commit b93cb1b65ab4a27b57c951b8c3e5af5ce8f80426 Author: Alam Ed Arias Date: Sat Mar 15 12:59:03 2014 -0400 SRB2 2.1 release diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..777bf189a --- /dev/null +++ b/.gitattributes @@ -0,0 +1,32 @@ +# Windows EOL +*.cs -crlf -whitespace +*.mk -crlf -whitespace +*.bat -crlf -whitespace +*.dev -crlf -whitespace +*.dsp -crlf -whitespace +*.dsw -crlf -whitespace +*.sln -crlf -whitespace +*.resx -crlf -whitespace +*.vcproj -crlf -whitespace +*.csproj* -crlf -whitespace +*.vcxproj* -crlf -whitespace +*.manifest -crlf -whitespace +# Patches +/tools/SDL-1.2.14-gc/SDL-1.2.14-gc.patch -whitespace +# LibPNG +/libs/libpng-src/CMakeLists.txt -whitespace +/libs/libpng-src/libpng-1.2.*.txt -whitespace +/libs/libpng-src/libpng.3 -whitespace +/libs/libpng-src/*.c -whitespace +# Zlib +/libs/zlib/contrib/amd64/amd64-match.S -whitespace +/libs/zlib/contrib/delphi/zlibd32.mak -crlf -whitespace +/libs/zlib/contrib/gcc_gvmat64/gvmat64.S -whitespace +/libs/zlib/contrib/minizip/MiniZip64_Changes.txt -whitespace +/libs/zlib/contrib/minizip/MiniZip64_info.txt -whitespace +/libs/zlib/contrib/pascal/zlibd32.mak -whitespace +/libs/zlib/nintendods/Makefile -whitespace +/libs/zlib/nintendods/README -whitespace +/libs/zlib/watcom/watcom_f.mak -crlf -whitespace +/libs/zlib/watcom/watcom_l.mak -crlf -whitespace +# Other diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..567fecd83 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +/data +*.ncb +*.opt +*.plg +*.suo +*.vcproj.*.*.user +Win32_LIB_ASM_Debug +Win32_LIB_ASM_Release +*.bsc +/SRB2.layout +/SRB2.depend +/src/comptime.h +*.dgb +*.debug +*.debug.txt diff --git a/Android.mk b/Android.mk new file mode 100644 index 000000000..240dfa843 --- /dev/null +++ b/Android.mk @@ -0,0 +1,6 @@ +# Build both the native piece of SRB2 for Android, and the Java frontend. +LOCAL_PATH:= $(call my-dir) + +include $(CLEAR_VARS) + +include $(call all-makefiles-under,$(LOCAL_PATH)) diff --git a/Doxyfile b/Doxyfile new file mode 100644 index 000000000..d11fa2bbc --- /dev/null +++ b/Doxyfile @@ -0,0 +1,272 @@ +# Doxyfile 1.4.3 + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- +PROJECT_NAME = SRB2 +PROJECT_NUMBER = 1.09 +OUTPUT_DIRECTORY = ./doc/SRB2 +CREATE_SUBDIRS = YES +OUTPUT_LANGUAGE = English +USE_WINDOWS_ENCODING = YES +BRIEF_MEMBER_DESC = YES +REPEAT_BRIEF = YES +ABBREVIATE_BRIEF = "The $name class" \ + "The $name widget" \ + "The $name file" \ + is \ + provides \ + specifies \ + contains \ + represents \ + a \ + an \ + the +ALWAYS_DETAILED_SEC = NO +INLINE_INHERITED_MEMB = NO +FULL_PATH_NAMES = YES +STRIP_FROM_PATH = +STRIP_FROM_INC_PATH = +SHORT_NAMES = NO +JAVADOC_AUTOBRIEF = NO +MULTILINE_CPP_IS_BRIEF = NO +DETAILS_AT_TOP = NO +INHERIT_DOCS = YES +DISTRIBUTE_GROUP_DOC = NO +SEPARATE_MEMBER_PAGES = NO +TAB_SIZE = 8 +ALIASES = +OPTIMIZE_OUTPUT_FOR_C = YES +OPTIMIZE_OUTPUT_JAVA = NO +SUBGROUPING = YES +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- +EXTRACT_ALL = YES +EXTRACT_PRIVATE = YES +EXTRACT_STATIC = YES +EXTRACT_LOCAL_CLASSES = YES +EXTRACT_LOCAL_METHODS = NO +HIDE_UNDOC_MEMBERS = NO +HIDE_UNDOC_CLASSES = NO +HIDE_FRIEND_COMPOUNDS = NO +HIDE_IN_BODY_DOCS = NO +INTERNAL_DOCS = NO +CASE_SENSE_NAMES = NO +HIDE_SCOPE_NAMES = NO +SHOW_INCLUDE_FILES = YES +INLINE_INFO = YES +SORT_MEMBER_DOCS = YES +SORT_BRIEF_DOCS = NO +SORT_BY_SCOPE_NAME = NO +GENERATE_TODOLIST = YES +GENERATE_TESTLIST = YES +GENERATE_BUGLIST = YES +GENERATE_DEPRECATEDLIST= YES +ENABLED_SECTIONS = +MAX_INITIALIZER_LINES = 30 +SHOW_USED_FILES = YES +SHOW_DIRECTORIES = YES +FILE_VERSION_FILTER = +#--------------------------------------------------------------------------- +# configuration options related to warning and progress messages +#--------------------------------------------------------------------------- +QUIET = NO +WARNINGS = YES +WARN_IF_UNDOCUMENTED = YES +WARN_IF_DOC_ERROR = YES +WARN_NO_PARAMDOC = NO +WARN_FORMAT = "$file:$line: $text" +WARN_LOGFILE = +#--------------------------------------------------------------------------- +# configuration options related to the input files +#--------------------------------------------------------------------------- +INPUT = ./src +FILE_PATTERNS = *.c \ + *.cc \ + *.cxx \ + *.cpp \ + *.c++ \ + *.d \ + *.java \ + *.ii \ + *.ixx \ + *.ipp \ + *.i++ \ + *.inl \ + *.h \ + *.hh \ + *.hxx \ + *.hpp \ + *.h++ \ + *.idl \ + *.odl \ + *.cs \ + *.php \ + *.php3 \ + *.inc \ + *.m \ + *.mm \ + *.dox +RECURSIVE = YES +EXCLUDE = ./src/djgppdos/internal.h \ + ./src/djgppdos/setup.c \ + ./src/sdl/IMG_xpm.c \ + ./src/sdl/SRB2DC/scramble.c +EXCLUDE_SYMLINKS = NO +EXCLUDE_PATTERNS = */src/hardware/*/* \ + */src/djgppdos/bcd.? \ + */src/sdl/SDL_main/* \ + */src/*/*_private.h \ + */src/sdl/*/*help.? \ + */src/md5.? \ + */src/sdl/filter/* +EXAMPLE_PATH = +EXAMPLE_PATTERNS = * +EXAMPLE_RECURSIVE = NO +IMAGE_PATH = +INPUT_FILTER = +FILTER_PATTERNS = +FILTER_SOURCE_FILES = YES +#--------------------------------------------------------------------------- +# configuration options related to source browsing +#--------------------------------------------------------------------------- +SOURCE_BROWSER = NO +INLINE_SOURCES = NO +STRIP_CODE_COMMENTS = YES +REFERENCED_BY_RELATION = NO +REFERENCES_RELATION = NO +#USE_HTAGS = NO +VERBATIM_HEADERS = YES +#--------------------------------------------------------------------------- +# configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- +ALPHABETICAL_INDEX = NO +COLS_IN_ALPHA_INDEX = 5 +IGNORE_PREFIX = +#--------------------------------------------------------------------------- +# configuration options related to the HTML output +#--------------------------------------------------------------------------- +GENERATE_HTML = YES +HTML_OUTPUT = html +HTML_FILE_EXTENSION = .html +HTML_HEADER = +HTML_FOOTER = +HTML_STYLESHEET = +HTML_ALIGN_MEMBERS = YES +GENERATE_HTMLHELP = NO +CHM_FILE = +HHC_LOCATION = +GENERATE_CHI = NO +BINARY_TOC = NO +TOC_EXPAND = NO +DISABLE_INDEX = NO +ENUM_VALUES_PER_LINE = 4 +GENERATE_TREEVIEW = YES +TREEVIEW_WIDTH = 250 +#--------------------------------------------------------------------------- +# configuration options related to the LaTeX output +#--------------------------------------------------------------------------- +GENERATE_LATEX = NO +LATEX_OUTPUT = latex +LATEX_CMD_NAME = latex +MAKEINDEX_CMD_NAME = makeindex +COMPACT_LATEX = NO +PAPER_TYPE = a4wide +EXTRA_PACKAGES = +LATEX_HEADER = +PDF_HYPERLINKS = NO +USE_PDFLATEX = NO +LATEX_BATCHMODE = NO +LATEX_HIDE_INDICES = NO +#--------------------------------------------------------------------------- +# configuration options related to the RTF output +#--------------------------------------------------------------------------- +GENERATE_RTF = NO +RTF_OUTPUT = rtf +COMPACT_RTF = NO +RTF_HYPERLINKS = NO +RTF_STYLESHEET_FILE = +RTF_EXTENSIONS_FILE = +#--------------------------------------------------------------------------- +# configuration options related to the man page output +#--------------------------------------------------------------------------- +GENERATE_MAN = NO +MAN_OUTPUT = man +MAN_EXTENSION = .3 +MAN_LINKS = YES +#--------------------------------------------------------------------------- +# configuration options related to the XML output +#--------------------------------------------------------------------------- +GENERATE_XML = NO +XML_OUTPUT = xml +XML_SCHEMA = +XML_DTD = +XML_PROGRAMLISTING = YES +#--------------------------------------------------------------------------- +# configuration options for the AutoGen Definitions output +#--------------------------------------------------------------------------- +GENERATE_AUTOGEN_DEF = NO +#--------------------------------------------------------------------------- +# configuration options related to the Perl module output +#--------------------------------------------------------------------------- +GENERATE_PERLMOD = NO +PERLMOD_LATEX = NO +PERLMOD_PRETTY = YES +PERLMOD_MAKEVAR_PREFIX = +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- +ENABLE_PREPROCESSING = YES +MACRO_EXPANSION = NO +EXPAND_ONLY_PREDEF = NO +SEARCH_INCLUDES = YES +INCLUDE_PATH = +INCLUDE_FILE_PATTERNS = +PREDEFINED = DOXYGEN \ + HWRENDER \ + DIRECTFULLSCREEN \ + HW3SOUND \ + LOGMESSAGES \ + WALLSPLATS \ + FLOORSPLATS +EXPAND_AS_DEFINED = +SKIP_FUNCTION_MACROS = YES +#--------------------------------------------------------------------------- +# Configuration::additions related to external references +#--------------------------------------------------------------------------- +TAGFILES = +GENERATE_TAGFILE = +ALLEXTERNALS = NO +EXTERNAL_GROUPS = YES +PERL_PATH = /usr/bin/perl +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- +CLASS_DIAGRAMS = YES +HIDE_UNDOC_RELATIONS = YES +HAVE_DOT = NO +CLASS_GRAPH = YES +COLLABORATION_GRAPH = YES +GROUP_GRAPHS = YES +UML_LOOK = NO +TEMPLATE_RELATIONS = NO +INCLUDE_GRAPH = YES +INCLUDED_BY_GRAPH = YES +CALL_GRAPH = NO +GRAPHICAL_HIERARCHY = YES +DIRECTORY_GRAPH = YES +DOT_IMAGE_FORMAT = png +DOT_PATH = +DOTFILE_DIRS = +MAX_DOT_GRAPH_WIDTH = 1024 +MAX_DOT_GRAPH_HEIGHT = 1024 +MAX_DOT_GRAPH_DEPTH = 1000 +DOT_TRANSPARENT = NO +DOT_MULTI_TARGETS = NO +GENERATE_LEGEND = YES +DOT_CLEANUP = YES +#--------------------------------------------------------------------------- +# Configuration::additions related to the search engine +#--------------------------------------------------------------------------- +SEARCHENGINE = NO diff --git a/LICENSE b/LICENSE new file mode 100644 index 000000000..d159169d1 --- /dev/null +++ b/LICENSE @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 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. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/SRB2.cbp b/SRB2.cbp new file mode 100644 index 000000000..a6be5757d --- /dev/null +++ b/SRB2.cbp @@ -0,0 +1,4841 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Srb2.dev b/Srb2.dev new file mode 100644 index 000000000..561703864 --- /dev/null +++ b/Srb2.dev @@ -0,0 +1,3093 @@ +[Project] +FileName=Srb2.dev +Name=Srb2 +Ver=3 +IsCpp=0 +Type=0 +UnitCount=279 +Folders=A_Asm,B_Bot,BLUA,D_Doom,F_Frame,G_Game,H_Hud,Hw_Hardware,Hw_Hardware/r_opengl,I_Interface,I_Interface/Dummy,I_Interface/SDL,I_Interface/Win32,LUA,M_Misc,P_Play,R_Rend,S_Sounds,W_Wad +CommandLine= +CompilerSettings=00000000000100000111e1 +PchHead=-1 +PchSource=-1 +ProfilesCount=10 +ProfileIndex=2 + +[Unit1] +FileName=src\hardware\hw3dsdrv.h +Folder=Hw_Hardware +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit2] +FileName=src\hardware\hw3sound.c +Folder=Hw_Hardware +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit3] +FileName=src\hardware\hw3sound.h +Folder=Hw_Hardware +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit4] +FileName=src\hardware\hw_bsp.c +Folder=Hw_Hardware +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit5] +FileName=src\hardware\hw_cache.c +Folder=Hw_Hardware +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit6] +FileName=src\hardware\hw_data.h +Folder=Hw_Hardware +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit7] +FileName=src\hardware\hw_defs.h +Folder=Hw_Hardware +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit8] +FileName=src\hardware\hw_draw.c +Folder=Hw_Hardware +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit9] +FileName=src\hardware\hw_drv.h +Folder=Hw_Hardware +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit10] +FileName=src\hardware\hw_glide.h +Folder=Hw_Hardware +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit11] +FileName=src\hardware\hw_glob.h +Folder=Hw_Hardware +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit12] +FileName=src\hardware\hw_light.c +Folder=Hw_Hardware +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit13] +FileName=src\hardware\hw_light.h +Folder=Hw_Hardware +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit14] +FileName=src\hardware\hw_main.c +Folder=Hw_Hardware +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit15] +FileName=src\hardware\hw_main.h +Folder=Hw_Hardware +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit16] +FileName=src\hardware\hw_md2.c +Folder=Hw_Hardware +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit17] +FileName=src\hardware\hw_md2.h +Folder=Hw_Hardware +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit18] +FileName=src\hardware\hw_trick.c +Folder=Hw_Hardware +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit19] +FileName=src\d_clisrv.c +Folder=D_Doom +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit20] +FileName=src\d_clisrv.h +Folder=D_Doom +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit21] +FileName=src\d_event.h +Folder=D_Doom +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit23] +FileName=src\d_main.h +Folder=D_Doom +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit24] +FileName=src\d_net.c +Folder=D_Doom +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit25] +FileName=src\d_net.h +Folder=D_Doom +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit26] +FileName=src\d_netcmd.c +Folder=D_Doom +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit27] +FileName=src\d_netcmd.h +Folder=D_Doom +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit28] +FileName=src\d_netfil.c +Folder=D_Doom +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit29] +FileName=src\d_netfil.h +Folder=D_Doom +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit30] +FileName=src\d_player.h +Folder=D_Doom +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit31] +FileName=src\d_think.h +Folder=D_Doom +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit32] +FileName=src\d_ticcmd.h +Folder=D_Doom +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit33] +FileName=src\m_argv.c +Folder=M_Misc +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit34] +FileName=src\m_argv.h +Folder=M_Misc +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit35] +FileName=src\m_bbox.c +Folder=M_Misc +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit36] +FileName=src\m_bbox.h +Folder=M_Misc +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit37] +FileName=src\m_cheat.c +Folder=M_Misc +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit38] +FileName=src\m_cheat.h +Folder=M_Misc +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit39] +FileName=src\m_fixed.c +Folder=M_Misc +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit40] +FileName=src\m_fixed.h +Folder=M_Misc +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit41] +FileName=src\m_menu.c +Folder=M_Misc +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit42] +FileName=src\m_menu.h +Folder=M_Misc +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit44] +FileName=src\m_misc.h +Folder=M_Misc +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit45] +FileName=src\m_random.c +Folder=M_Misc +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit46] +FileName=src\m_random.h +Folder=M_Misc +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit47] +FileName=src\m_swap.h +Folder=M_Misc +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit48] +FileName=src\p_ceilng.c +Folder=P_Play +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit49] +FileName=src\p_enemy.c +Folder=P_Play +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit50] +FileName=src\p_fab.c +Folder=P_Play +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit51] +FileName=src\p_floor.c +Folder=P_Play +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit52] +FileName=src\p_inter.c +Folder=P_Play +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit53] +FileName=src\p_lights.c +Folder=P_Play +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit54] +FileName=src\p_local.h +Folder=P_Play +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit55] +FileName=src\p_map.c +Folder=P_Play +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit56] +FileName=src\p_maputl.c +Folder=P_Play +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit57] +FileName=src\p_maputl.h +Folder=P_Play +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit58] +FileName=src\p_mobj.c +Folder=P_Play +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit59] +FileName=src\p_mobj.h +Folder=P_Play +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit60] +FileName=src\p_pspr.h +Folder=P_Play +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit61] +FileName=src\p_saveg.c +Folder=P_Play +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit62] +FileName=src\p_saveg.h +Folder=P_Play +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit63] +FileName=src\p_setup.c +Folder=P_Play +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit64] +FileName=src\p_setup.h +Folder=P_Play +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit65] +FileName=src\p_sight.c +Folder=P_Play +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit66] +FileName=src\p_spec.c +Folder=P_Play +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit67] +FileName=src\p_spec.h +Folder=P_Play +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit68] +FileName=src\p_telept.c +Folder=P_Play +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit69] +FileName=src\p_tick.c +Folder=P_Play +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit70] +FileName=src\p_tick.h +Folder=P_Play +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit71] +FileName=src\p_user.c +Folder=P_Play +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit72] +FileName=src\r_bsp.c +Folder=R_Rend +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit73] +FileName=src\r_bsp.h +Folder=R_Rend +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit74] +FileName=src\r_data.c +Folder=R_Rend +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit75] +FileName=src\r_data.h +Folder=R_Rend +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit76] +FileName=src\r_defs.h +Folder=R_Rend +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit77] +FileName=src\r_draw.c +Folder=R_Rend +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit78] +FileName=src\r_draw.h +Folder=R_Rend +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit79] +FileName=src\r_draw16.c +Folder=R_Rend +Compile=0 +CompileCpp=0 +Link=0 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit80] +FileName=src\r_draw8.c +Folder=R_Rend +Compile=0 +CompileCpp=0 +Link=0 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit81] +FileName=src\r_local.h +Folder=R_Rend +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit82] +FileName=src\r_main.c +Folder=R_Rend +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit83] +FileName=src\r_main.h +Folder=R_Rend +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit84] +FileName=src\r_plane.c +Folder=R_Rend +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit85] +FileName=src\r_plane.h +Folder=R_Rend +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit86] +FileName=src\r_segs.c +Folder=R_Rend +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit87] +FileName=src\r_segs.h +Folder=R_Rend +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit88] +FileName=src\r_sky.c +Folder=R_Rend +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit89] +FileName=src\r_sky.h +Folder=R_Rend +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit90] +FileName=src\r_splats.c +Folder=R_Rend +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit91] +FileName=src\r_splats.h +Folder=R_Rend +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit92] +FileName=src\r_state.h +Folder=R_Rend +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit93] +FileName=src\r_things.c +Folder=R_Rend +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit94] +FileName=src\r_things.h +Folder=R_Rend +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit95] +FileName=src\am_map.c +Folder=H_Hud +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit96] +FileName=src\am_map.h +Folder=H_Hud +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit97] +FileName=src\byteptr.h +Folder=I_Interface +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit98] +FileName=src\command.c +Folder=H_Hud +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit99] +FileName=src\command.h +Folder=H_Hud +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit100] +FileName=src\console.c +Folder=H_Hud +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit101] +FileName=src\console.h +Folder=H_Hud +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit102] +FileName=src\dehacked.c +Folder=D_Doom +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit103] +FileName=src\dehacked.h +Folder=D_Doom +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit104] +FileName=src\Doomdata.h +Folder=D_Doom +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit105] +FileName=src\Doomdef.h +Folder=D_Doom +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit106] +FileName=src\Doomstat.h +Folder=D_Doom +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit107] +FileName=src\Doomtype.h +Folder=D_Doom +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit108] +FileName=src\F_finale.c +Folder=F_Frame +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit109] +FileName=src\F_finale.h +Folder=F_Frame +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit110] +FileName=src\F_wipe.c +Folder=F_Frame +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit111] +FileName=src\filesrch.h +Folder=I_Interface +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit112] +FileName=src\g_game.c +Folder=G_Game +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit113] +FileName=src\g_game.h +Folder=G_Game +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit114] +FileName=src\g_input.c +Folder=G_Game +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit115] +FileName=src\g_input.h +Folder=G_Game +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit116] +FileName=src\g_state.h +Folder=G_Game +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit117] +FileName=src\hu_stuff.c +Folder=H_Hud +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit118] +FileName=src\hu_stuff.h +Folder=H_Hud +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit119] +FileName=src\i_joy.h +Folder=I_Interface +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit120] +FileName=src\i_net.h +Folder=I_Interface +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit121] +FileName=src\i_sound.h +Folder=I_Interface +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit122] +FileName=src\i_system.h +Folder=I_Interface +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit123] +FileName=src\i_tcp.c +Folder=I_Interface +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit124] +FileName=src\i_tcp.h +Folder=I_Interface +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit125] +FileName=src\i_video.h +Folder=I_Interface +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit126] +FileName=src\info.c +Folder=P_Play +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit127] +FileName=src\info.h +Folder=P_Play +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit128] +FileName=src\keys.h +Folder=I_Interface +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit129] +FileName=src\md5.c +Folder=W_Wad +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit130] +FileName=src\md5.h +Folder=W_Wad +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit131] +FileName=src\mserv.c +Folder=I_Interface +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit132] +FileName=src\mserv.h +Folder=I_Interface +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit133] +FileName=src\s_sound.c +Folder=S_Sounds +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit134] +FileName=src\s_sound.h +Folder=S_Sounds +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit135] +FileName=src\screen.c +Folder=R_Rend +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit136] +FileName=src\screen.h +Folder=R_Rend +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit137] +FileName=src\sounds.c +Folder=S_Sounds +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit138] +FileName=src\sounds.h +Folder=S_Sounds +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit139] +FileName=src\st_stuff.c +Folder=H_Hud +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit140] +FileName=src\st_stuff.h +Folder=H_Hud +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit141] +FileName=src\tables.c +Folder=P_Play +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit142] +FileName=src\tables.h +Folder=P_Play +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit143] +FileName=src\v_video.c +Folder=R_Rend +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit144] +FileName=src\v_video.h +Folder=R_Rend +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit145] +FileName=src\w_wad.c +Folder=W_Wad +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit146] +FileName=src\w_wad.h +Folder=W_Wad +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit147] +FileName=src\Z_zone.c +Folder=D_Doom +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit148] +FileName=src\Z_zone.h +Folder=D_Doom +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit149] +FileName=src\tmap.nas +Folder=A_Asm +Compile=0 +CompileCpp=0 +Link=0 +Priority=1000 +OverrideBuildCmd=1 +BuildCmd=nasm.exe -g -o $@ -f win32 src/tmap.nas + +[Unit150] +FileName=src\asm_defs.inc +Folder=A_Asm +Compile=0 +CompileCpp=0 +Link=0 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit151] +FileName=src\vid_copy.s +Folder=A_Asm +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=1 +BuildCmd=$(CC) -g $(CFLAGS) -x assembler-with-cpp -c src/vid_copy.s -o $@ + +[Unit152] +FileName=src\y_inter.h +Folder=H_Hud +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit153] +FileName=src\y_inter.c +Folder=H_Hud +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit154] +FileName=src\hardware\hw_dll.h +Folder=Hw_Hardware +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit155] +FileName=src\hardware\hws_data.h +Folder=Hw_Hardware +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit156] +FileName=src\p5prof.h +Folder=A_Asm +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit157] +FileName=src\tmap_mmx.nas +Folder=A_Asm +Compile=0 +CompileCpp=0 +Link=0 +Priority=1000 +OverrideBuildCmd=1 +BuildCmd=nasm.exe -g -o $@ -f win32 src/tmap_mmx.nas + +[Unit159] +FileName=src\lzf.h +Folder=W_Wad +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit160] +FileName=src\lzf.c +Folder=W_Wad +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit161] +FileName=src\p_polyobj.h +Folder=P_Play +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit162] +FileName=src\p_polyobj.c +Folder=P_Play +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit163] +FileName=src\m_queue.h +Folder=M_Misc +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit164] +FileName=src\m_dllist.h +Folder=M_Misc +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit165] +FileName=src\m_queue.c +Folder=M_Misc +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit166] +FileName=src\dummy\i_cdmus.c +Folder=I_Interface/Dummy +Compile=0 +CompileCpp=0 +Link=0 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit167] +FileName=src\dummy\i_main.c +Folder=I_Interface/Dummy +Compile=0 +CompileCpp=0 +Link=0 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit168] +FileName=src\dummy\i_net.c +Folder=I_Interface/Dummy +Compile=0 +CompileCpp=0 +Link=0 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit169] +FileName=src\dummy\i_sound.c +Folder=I_Interface/Dummy +Compile=0 +CompileCpp=0 +Link=0 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit170] +FileName=src\dummy\i_system.c +Folder=I_Interface/Dummy +Compile=0 +CompileCpp=0 +Link=0 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit171] +FileName=src\dummy\i_video.c +Folder=I_Interface/Dummy +Compile=0 +CompileCpp=0 +Link=0 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit172] +FileName=src\filesrch.c +Folder=I_Interface +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit173] +FileName=src\win32\afxres.h +Folder=I_Interface/Win32 +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit174] +FileName=src\win32\dx_error.c +Folder=I_Interface/Win32 +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit175] +FileName=src\win32\dx_error.h +Folder=I_Interface/Win32 +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit176] +FileName=src\win32\fabdxlib.c +Folder=I_Interface/Win32 +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit177] +FileName=src\win32\fabdxlib.h +Folder=I_Interface/Win32 +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[VersionInfo] +Major=1 +Minor=1 +Release=1 +Build=1 +LanguageID=1033 +CharsetID=1252 +CompanyName= +FileVersion=0.1 +FileDescription=Developed using the Dev-C++ IDE +InternalName= +LegalCopyright= +LegalTrademarks= +OriginalFilename=wLegacy.exe +ProductName=wLegacy +ProductVersion=0.1 +AutoIncBuildNrOnRebuild=0 +AutoIncBuildNrOnCompile=0 + +[Unit181] +FileName=src\win32\resource.h +CompileCpp=0 +Folder=I_Interface/Win32 +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit182] +FileName=src\win32\win_cd.c +CompileCpp=0 +Folder=I_Interface/Win32 +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit22] +FileName=src\d_main.c +Folder=D_Doom +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= +CompileCpp=0 + +[Unit158] +FileName=src\string.c +CompileCpp=0 +Folder=M_Misc +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit183] +FileName=src\win32\win_dbg.c +CompileCpp=0 +Folder=I_Interface/Win32 +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit184] +FileName=src\win32\win_dbg.h +CompileCpp=0 +Folder=I_Interface/Win32 +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit185] +FileName=src\win32\win_dll.c +CompileCpp=0 +Folder=I_Interface/Win32 +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit186] +FileName=src\win32\win_dll.h +CompileCpp=0 +Folder=I_Interface/Win32 +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit187] +FileName=src\win32\win_main.c +CompileCpp=0 +Folder=I_Interface/Win32 +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit188] +FileName=src\win32\win_main.h +CompileCpp=0 +Folder=I_Interface/Win32 +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit189] +FileName=src\win32\win_net.c +CompileCpp=0 +Folder=I_Interface/Win32 +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit190] +FileName=src\win32\win_snd.c +CompileCpp=0 +Folder=I_Interface/Win32 +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit191] +FileName=src\win32\win_sys.c +CompileCpp=0 +Folder=I_Interface/Win32 +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit43] +FileName=src\m_misc.c +CompileCpp=0 +Folder=M_Misc +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Profile1] +ProfileName=Dummy Release +Type=1 +ObjFiles= +Includes= +Libs= +ResourceIncludes= +MakeIncludes=comptime.mk;cpdebug.mk +Compiler=-DNDEBUG_@@_-fno-exceptions_@@_-DSTDC_HEADERS_@@_-Wall_@@_-Os_@@_-g_@@_-DNONET_@@_-DNOROPENGL_@@_-D__USE_MINGW_ANSI_STDIO=0_@@_-DHAVE_BLUA_@@_ +CppCompiler=-Os_@@_-g_@@_ +Linker= +PreprocDefines=NORMALSRB2_@@_ +CompilerSettings=0000000000100000011000 +Icon= +ExeOutput=bin\Dummy\Release +ObjectOutput=objs\Dummy\Release +OverrideOutput=1 +OverrideOutputName=srb2dummy.exe +HostApplication= +CommandLine= +UseCustomMakefile=0 +CustomMakefile= +IncludeVersionInfo=0 +SupportXPThemes=0 +CompilerSet=0 +CompilerType=0 + +[Profile2] +ProfileName=Dummy Debug +Type=1 +ObjFiles= +Includes= +Libs= +ResourceIncludes= +MakeIncludes=comptime.mk;cpdebug.mk +Compiler=-D_DEBUG_@@_-fno-exceptions_@@_-DSTDC_HEADERS_@@_-Wall_@@_-O0_@@_-g_@@_-DNONET_@@_-DNOROPENGL_@@_-D__USE_MINGW_ANSI_STDIO=0_@@_-DHAVE_BLUA_@@_ +CppCompiler=-O0_@@_-g_@@_ +Linker= +PreprocDefines=NORMALSRB2_@@_ +CompilerSettings=0000000000000010011000 +Icon= +ExeOutput=bin\Dummy\Debug +ObjectOutput=objs\Dummy\Debug +OverrideOutput=1 +OverrideOutputName=srb2dummy.exe +HostApplication= +CommandLine= +UseCustomMakefile=0 +CustomMakefile= +IncludeVersionInfo=0 +SupportXPThemes=0 +CompilerSet=0 +CompilerType=0 + +[Unit192] +FileName=src\win32\win_vid.c +CompileCpp=0 +Folder=I_Interface/Win32 +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit193] +FileName=src\win32\Srb2win.rc +CompileCpp=0 +Folder=I_Interface/Win32 +Compile=1 +Link=0 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit194] +FileName=src\sdl\dosstr.c +CompileCpp=0 +Folder=I_Interface/SDL +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit195] +FileName=src\sdl\endtxt.c +CompileCpp=0 +Folder=I_Interface/SDL +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit196] +FileName=src\sdl\endtxt.h +Folder=I_Interface/SDL +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= +CompileCpp=0 + +[Profile3] +ProfileName=Win32/DirectX Release +Type=0 +ObjFiles= +Includes=libs/libpng-src;libs/zlib;libs/gme/include;libs/fmodex/inc;libs +Libs=libs/libpng-src/projects;libs/zlib/win32;libs/miniupnpc/mingw32;libs/gme/win32;libs/gme/win32;libs/fmodex/lib +ResourceIncludes=src/win32 +MakeIncludes=comptime.mk;cpdebug.mk +Compiler=-DNDEBUG_@@_-fno-exceptions_@@_-DSTDC_HEADERS_@@_-Wall_@@_-Os_@@_-g_@@_-D_WINDOWS_@@_-DHAVE_PNG_@@_-DNOROPENGL_@@_-D__USE_MINGW_ANSI_STDIO=0_@@_-DHAVE_MINIUPNPC_@@_-DSTATIC_MINIUPNPC_@@_-DHAVE_BLUA_@@_-DHAVE_LIBGME_@@_ +CppCompiler=-Os_@@_-g_@@_ +Linker=-lgdi32_@@_-ldinput_@@_-ldxguid_@@_-lwinmm_@@_-lpng32_@@_-lz32_@@_-lminiupnpc_@@_-lws2_32_@@_-liphlpapi_@@_-mwindows_@@_-lgme.dll_@@_-lfmodex_@@_ +PreprocDefines=NORMALSRB2_@@_ +CompilerSettings=00000000001000000110e1 +Icon= +ExeOutput=bin\Mingw\Release +ObjectOutput=objs\Mingw\Release +OverrideOutput=1 +OverrideOutputName=srb2win.exe +HostApplication= +CommandLine= +UseCustomMakefile=0 +CustomMakefile= +IncludeVersionInfo=0 +SupportXPThemes=0 +CompilerSet=0 +CompilerType=0 + +[Profile4] +ProfileName=Win32/DirectX Debug +Type=0 +ObjFiles= +Includes=libs/libpng-src;libs/zlib;libs/gme/include;libs/fmodex/inc;libs +Libs=libs/libpng-src/projects;libs/zlib/win32;libs/miniupnpc/mingw32;libs/gme/win32;libs/fmodex/lib +ResourceIncludes=src/win32 +MakeIncludes=comptime.mk;cpdebug.mk +Compiler=-D_DEBUG_@@_-fno-exceptions_@@_-DSTDC_HEADERS_@@_-Wall_@@_-O0_@@_-g_@@_-D_WINDOWS_@@_-DHAVE_PNG_@@_-DNOROPENGL_@@_-D__USE_MINGW_ANSI_STDIO=0_@@_-DHAVE_MINIUPNPC_@@_-DSTATIC_MINIUPNPC_@@_-DHAVE_BLUA_@@_-DHAVE_LIBGME_@@_ +CppCompiler=-O0_@@_-g_@@_ +Linker=-lgdi32_@@_-ldinput_@@_-ldxguid_@@_-lwinmm_@@_-lpng32_@@_-lz32_@@_-lminiupnpc_@@_-lws2_32_@@_-liphlpapi_@@_-mconsole_@@_-lgme.dll_@@_-lfmodex_@@_ +PreprocDefines=NORMALSRB2_@@_ +CompilerSettings=00000000000000100110e1 +Icon= +ExeOutput=bin\Mingw\Debug +ObjectOutput=objs\Mingw\Debug +OverrideOutput=1 +OverrideOutputName=srb2win.exe +HostApplication= +CommandLine= +UseCustomMakefile=0 +CustomMakefile= +IncludeVersionInfo=0 +SupportXPThemes=0 +CompilerSet=0 +CompilerType=0 + +[Unit197] +FileName=src\sdl\hwsym_sdl.c +CompileCpp=0 +Folder=I_Interface/SDL +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit198] +FileName=src\sdl\hwsym_sdl.h +CompileCpp=0 +Folder=I_Interface/SDL +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit199] +FileName=src\sdl\i_cdmus.c +CompileCpp=0 +Folder=I_Interface/SDL +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit200] +FileName=src\sdl\i_main.c +CompileCpp=0 +Folder=I_Interface/SDL +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit201] +FileName=src\sdl\i_net.c +CompileCpp=0 +Folder=I_Interface/SDL +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit202] +FileName=src\sdl\sdl_sound.c +CompileCpp=0 +Folder=I_Interface/SDL +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit203] +FileName=src\sdl\i_system.c +CompileCpp=0 +Folder=I_Interface/SDL +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit204] +FileName=src\sdl\i_video.c +CompileCpp=0 +Folder=I_Interface/SDL +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit205] +FileName=src\sdl\IMG_xpm.c +CompileCpp=0 +Folder=I_Interface/SDL +Compile=0 +Link=0 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit206] +FileName=src\sdl\ogl_sdl.c +CompileCpp=0 +Folder=I_Interface/SDL +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit207] +FileName=src\sdl\ogl_sdl.h +CompileCpp=0 +Folder=I_Interface/SDL +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit208] +FileName=src\sdl\sdlmain.h +CompileCpp=0 +Folder=I_Interface/SDL +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit209] +FileName=src\hardware\r_opengl\ogl_win.c +CompileCpp=0 +Folder=Hw_Hardware/r_opengl +Compile=0 +Link=0 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit210] +FileName=src\hardware\r_opengl\r_opengl.c +CompileCpp=0 +Folder=Hw_Hardware/r_opengl +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit211] +FileName=src\hardware\r_opengl\r_opengl.h +CompileCpp=0 +Folder=Hw_Hardware/r_opengl +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Profile5] +ProfileName=Win32/SDL Release +Type=0 +ObjFiles= +Includes=libs/libpng-src;libs/zlib;libs +Libs=libs/libpng-src/projects;libs/zlib/win32;libs/miniupnpc/mingw32 +ResourceIncludes=src/win32 +MakeIncludes=comptime.mk;cpdebug.mk +Compiler=-DNDEBUG_@@_-fno-exceptions_@@_-DSTDC_HEADERS_@@_-Wall_@@_-Os_@@_-g_@@_-DUSE_WGL_SWAP_@@_-DDIRECTFULLSCREEN_@@_-DSDL_@@_-DHWRENDER_@@_-DHW3SOUND_@@_-DHAVE_MIXER_@@_-DHAVE_PNG_@@_-D__USE_MINGW_ANSI_STDIO=0_@@_-DHAVE_MINIUPNPC_@@_-DSTATIC_MINIUPNPC_@@_-DHAVE_BLUA_@@_ +CppCompiler=-Os_@@_-g_@@_ +Linker=-lSDL_@@_-lSDL_Mixer_@@_-lpng32_@@_-lz32_@@_-lminiupnpc_@@_-lws2_32_@@_-liphlpapi_@@_-mconsole_@@_ +PreprocDefines=NORMALSRB2_@@_ +CompilerSettings=00000000001000000110e1 +Icon= +ExeOutput=bin\Mingw\SDL\Release +ObjectOutput=objs\Mingw\SDL\Release +OverrideOutput=1 +OverrideOutputName=srb2sdl.exe +HostApplication= +CommandLine= +UseCustomMakefile=0 +CustomMakefile= +IncludeVersionInfo=0 +SupportXPThemes=0 +CompilerSet=0 +CompilerType=0 + +[Unit212] +FileName=src\lua_baselib.c +CompileCpp=0 +Folder=LUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit213] +FileName=src\lua_hooklib.c +CompileCpp=0 +Folder=LUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit214] +FileName=src\lua_infolib.c +CompileCpp=0 +Folder=LUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit215] +FileName=src\lua_libs.h +CompileCpp=0 +Folder=LUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit216] +FileName=src\lua_hook.h +CompileCpp=0 +Folder=LUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Profile6] +ProfileName=Win32/SDL Debug +Type=0 +ObjFiles= +Includes=libs/libpng-src;libs/zlib;libs +Libs=libs/libpng-src/projects;libs/zlib/win32;libs/miniupnpc/mingw32 +ResourceIncludes=src/win32 +MakeIncludes=comptime.mk;cpdebug.mk +Compiler=-D_DEBUG_@@_-fno-exceptions_@@_-DSTDC_HEADERS_@@_-Wall_@@_-O0_@@_-g_@@_-DUSE_WGL_SWAP_@@_-DDIRECTFULLSCREEN_@@_-DSDL_@@_-DHWRENDER_@@_-DHW3SOUND_@@_-DHAVE_MIXER_@@_-DHAVE_PNG_@@_-D__USE_MINGW_ANSI_STDIO=0_@@_-DHAVE_MINIUPNPC_@@_-DSTATIC_MINIUPNPC_@@_-DHAVE_BLUA_@@_ +CppCompiler=-O0_@@_-g_@@_ +Linker=-lSDL_@@_-lSDL_Mixer_@@_-lpng32_@@_-lz32_@@_-lminiupnpc_@@_-lws2_32_@@_-liphlpapi_@@_-mconsole_@@_ +PreprocDefines=NORMALSRB2_@@_ +CompilerSettings=00000000000000100110e1 +Icon= +ExeOutput=bin\Mingw\SDL\Debug +ObjectOutput=objs\Mingw\SDL\Debug +OverrideOutput=1 +OverrideOutputName=srb2sdl.exe +HostApplication= +CommandLine= +UseCustomMakefile=0 +CustomMakefile= +IncludeVersionInfo=0 +SupportXPThemes=0 +CompilerSet=0 +CompilerType=0 + +[Profile7] +ProfileName=Win64/DirectX Release +Type=0 +ObjFiles= +Includes=libs/libpng-src;libs/zlib;libs +Libs=libs/libpng-src/projects;libs/zlib/win32;libs/miniupnpc/mingw64 +ResourceIncludes=src/win32 +MakeIncludes=comptime.mk;cpdebug.mk +Compiler=-DNDEBUG_@@_-fno-exceptions_@@_-DSTDC_HEADERS_@@_-Wall_@@_-Os_@@_-g_@@_-D_WINDOWS_@@_-DHAVE_PNG_@@_-DNOROPENGL_@@_-D__USE_MINGW_ANSI_STDIO=0_@@_-DHAVE_MINIUPNPC_@@_-DSTATIC_MINIUPNPC_@@_-DHAVE_BLUA_@@_ +CppCompiler=-Os_@@_-g_@@_ +Linker=-lgdi32_@@_-ldinput_@@_-ldxguid_@@_-lwinmm_@@_-lpng64_@@_-lz64_@@_-lminiupnpc_@@_-lws2_32_@@_-liphlpapi_@@_-mwindows_@@_ +PreprocDefines=NORMALSRB2_@@_ +CompilerSettings=00000000001000000110tb +Icon= +ExeOutput=bin\Mingw64\Release +ObjectOutput=objs\Mingw64\Release +OverrideOutput=1 +OverrideOutputName=srb2win.exe +HostApplication= +CommandLine= +UseCustomMakefile=0 +CustomMakefile= +IncludeVersionInfo=0 +SupportXPThemes=0 +CompilerSet=9 +CompilerType=0 + +[Profile8] +ProfileName=Win64/DirectX Debug +Type=0 +ObjFiles= +Includes=libs/libpng-src;libs/zlib;libs +Libs=libs/libpng-src/projects;libs/zlib/win32;libs/miniupnpc/mingw64 +ResourceIncludes=src/win32 +MakeIncludes=comptime.mk;cpdebug.mk +Compiler=-D_DEBUG_@@_-fno-exceptions_@@_-DSTDC_HEADERS_@@_-Wall_@@_-O0_@@_-g_@@_-D_WINDOWS_@@_-DHAVE_PNG_@@_-DNOROPENGL_@@_-D__USE_MINGW_ANSI_STDIO=0_@@_-DHAVE_MINIUPNPC_@@_-DSTATIC_MINIUPNPC_@@_-DHAVE_BLUA_@@_ +CppCompiler=-O0_@@_-g_@@_ +Linker=-lgdi32_@@_-ldinput_@@_-ldxguid_@@_-lwinmm_@@_-lpng64_@@_-lz64_@@_-lminiupnpc_@@_-lws2_32_@@_-liphlpapi_@@_-mconsole_@@_ +PreprocDefines=NORMALSRB2_@@_ +CompilerSettings=00000000000000100110tb +Icon= +ExeOutput=bin\Mingw64\Debug +ObjectOutput=objs\Mingw64\Debug +OverrideOutput=1 +OverrideOutputName=srb2win.exe +HostApplication= +CommandLine= +UseCustomMakefile=0 +CustomMakefile= +IncludeVersionInfo=0 +SupportXPThemes=0 +CompilerSet=9 +CompilerType=0 + +[Profile9] +ProfileName=Win64/SDL Release +Type=0 +ObjFiles= +Includes=libs/libpng-src;libs/zlib;libs +Libs=libs/libpng-src/projects;libs/zlib/win32;libs/miniupnpc/mingw64 +ResourceIncludes=src/win32 +MakeIncludes=comptime.mk;cpdebug.mk +Compiler=-DNDEBUG_@@_-fno-exceptions_@@_-DSTDC_HEADERS_@@_-Wall_@@_-Os_@@_-g_@@_-DUSE_WGL_SWAP_@@_-DDIRECTFULLSCREEN_@@_-DSDL_@@_-DHWRENDER_@@_-DHW3SOUND_@@_-DHAVE_MIXER_@@_-DHAVE_PNG_@@_-D__USE_MINGW_ANSI_STDIO=0_@@_-DHAVE_MINIUPNPC_@@_-DSTATIC_MINIUPNPC_@@_-DHAVE_BLUA_@@_ +CppCompiler=-Os_@@_-g_@@_ +Linker=-lSDL_@@_-lSDL_Mixer_@@_-lpng64_@@_-lz64_@@_-lminiupnpc_@@_-lws2_32_@@_-liphlpapi_@@_-mconsole_@@_ +PreprocDefines=NORMALSRB2_@@_ +CompilerSettings=00000000001000000110tb +Icon= +ExeOutput=bin\Mingw64\SDL\Release +ObjectOutput=objs\Mingw64\SDL\Release +OverrideOutput=1 +OverrideOutputName=srb2sdl.exe +HostApplication= +CommandLine= +UseCustomMakefile=0 +CustomMakefile= +IncludeVersionInfo=0 +SupportXPThemes=0 +CompilerSet=9 +CompilerType=0 + +[Profile10] +ProfileName=Win64/SDL Debug +Type=0 +ObjFiles= +Includes=libs/libpng-src;libs/zlib;libs +Libs=libs/libpng-src/projects;libs/zlib/win32;libs/miniupnpc/mingw64 +ResourceIncludes=src/win32 +MakeIncludes=comptime.mk;cpdebug.mk +Compiler=-D_DEBUG_@@_-fno-exceptions_@@_-DSTDC_HEADERS_@@_-Wall_@@_-O0_@@_-g_@@_-DUSE_WGL_SWAP_@@_-DDIRECTFULLSCREEN_@@_-DSDL_@@_-DHWRENDER_@@_-DHW3SOUND_@@_-DHAVE_MIXER_@@_-DHAVE_PNG_@@_-D__USE_MINGW_ANSI_STDIO=0_@@_-DHAVE_MINIUPNPC_@@_-DSTATIC_MINIUPNPC_@@_-DHAVE_BLUA_@@_ +CppCompiler=-O0_@@_-g_@@_ +Linker=-lSDL_@@_-lSDL_Mixer_@@_-lpng64_@@_-lz64_@@_-lminiupnpc_@@_-lws2_32_@@_-liphlpapi_@@_-mconsole_@@_ +PreprocDefines=NORMALSRB2_@@_ +CompilerSettings=00000000000000100110tb +Icon= +ExeOutput=bin\Mingw64\SDL\Debug +ObjectOutput=objs\Mingw64\SDL\Debug +OverrideOutput=1 +OverrideOutputName=srb2sdl.exe +HostApplication= +CommandLine= +UseCustomMakefile=0 +CustomMakefile= +IncludeVersionInfo=0 +SupportXPThemes=0 +CompilerSet=9 +CompilerType=0 + +[Unit217] +FileName=src\lua_mathlib.c +CompileCpp=0 +Folder=LUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit218] +FileName=src\lua_mobjlib.c +CompileCpp=0 +Folder=LUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit219] +FileName=src\lua_script.c +CompileCpp=0 +Folder=LUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit220] +FileName=src\lua_script.h +CompileCpp=0 +Folder=LUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit221] +FileName=src\blua\lapi.h +CompileCpp=0 +Folder=BLUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit222] +FileName=src\blua\lauxlib.h +CompileCpp=0 +Folder=BLUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit223] +FileName=src\blua\lcode.h +CompileCpp=0 +Folder=BLUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit224] +FileName=src\blua\ldebug.h +CompileCpp=0 +Folder=BLUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit225] +FileName=src\blua\ldo.h +CompileCpp=0 +Folder=BLUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit226] +FileName=src\blua\lfunc.h +CompileCpp=0 +Folder=BLUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit227] +FileName=src\blua\lgc.h +CompileCpp=0 +Folder=BLUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit228] +FileName=src\blua\llex.h +CompileCpp=0 +Folder=BLUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit229] +FileName=src\blua\llimits.h +CompileCpp=0 +Folder=BLUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit230] +FileName=src\blua\lmem.h +CompileCpp=0 +Folder=BLUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit231] +FileName=src\blua\lobject.h +CompileCpp=0 +Folder=BLUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit232] +FileName=src\blua\lopcodes.h +CompileCpp=0 +Folder=BLUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit233] +FileName=src\blua\lparser.h +CompileCpp=0 +Folder=BLUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit234] +FileName=src\blua\lstate.h +CompileCpp=0 +Folder=BLUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit235] +FileName=src\blua\lstring.h +CompileCpp=0 +Folder=BLUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit236] +FileName=src\blua\ltable.h +CompileCpp=0 +Folder=BLUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit237] +FileName=src\blua\ltm.h +CompileCpp=0 +Folder=BLUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit238] +FileName=src\blua\lua.h +CompileCpp=0 +Folder=BLUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit239] +FileName=src\blua\luaconf.h +CompileCpp=0 +Folder=BLUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit240] +FileName=src\blua\lualib.h +CompileCpp=0 +Folder=BLUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit241] +FileName=src\blua\lundump.h +CompileCpp=0 +Folder=BLUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit242] +FileName=src\blua\lvm.h +CompileCpp=0 +Folder=BLUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit243] +FileName=src\blua\lzio.h +CompileCpp=0 +Folder=BLUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit244] +FileName=src\blua\lapi.c +CompileCpp=0 +Folder=BLUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit245] +FileName=src\blua\lauxlib.c +CompileCpp=0 +Folder=BLUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit246] +FileName=src\blua\lbaselib.c +CompileCpp=0 +Folder=BLUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit247] +FileName=src\blua\lcode.c +CompileCpp=0 +Folder=BLUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit248] +FileName=src\blua\ldebug.c +CompileCpp=0 +Folder=BLUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit249] +FileName=src\blua\ldo.c +CompileCpp=0 +Folder=BLUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit250] +FileName=src\blua\ldump.c +CompileCpp=0 +Folder=BLUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit251] +FileName=src\blua\lfunc.c +CompileCpp=0 +Folder=BLUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit252] +FileName=src\blua\lgc.c +CompileCpp=0 +Folder=BLUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit253] +FileName=src\blua\linit.c +CompileCpp=0 +Folder=BLUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit254] +FileName=src\blua\llex.c +CompileCpp=0 +Folder=BLUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit255] +FileName=src\blua\lmem.c +CompileCpp=0 +Folder=BLUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit256] +FileName=src\blua\lobject.c +CompileCpp=0 +Folder=BLUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit257] +FileName=src\blua\lopcodes.c +CompileCpp=0 +Folder=BLUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit258] +FileName=src\blua\lparser.c +CompileCpp=0 +Folder=BLUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit259] +FileName=src\blua\lstate.c +CompileCpp=0 +Folder=BLUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit260] +FileName=src\blua\lstring.c +CompileCpp=0 +Folder=BLUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit261] +FileName=src\blua\lstrlib.c +CompileCpp=0 +Folder=BLUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit262] +FileName=src\blua\ltable.c +CompileCpp=0 +Folder=BLUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit263] +FileName=src\blua\ltablib.c +CompileCpp=0 +Folder=BLUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit264] +FileName=src\blua\ltm.c +CompileCpp=0 +Folder=BLUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit265] +FileName=src\blua\lundump.c +CompileCpp=0 +Folder=BLUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit266] +FileName=src\blua\lvm.c +CompileCpp=0 +Folder=BLUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit267] +FileName=src\blua\lzio.c +CompileCpp=0 +Folder=BLUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit268] +FileName=src\lua_playerlib.c +CompileCpp=0 +Folder=LUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit269] +FileName=src\comptime.c +CompileCpp=0 +Folder=D_Doom +Compile=1 +Link=1 +Priority=1001 +OverrideBuildCmd=1 +BuildCmd=$(CC) -c src/comptime.c -o $@ $(CFLAGS) -DCOMPVERSION + +[Unit270] +FileName=src\b_bot.c +CompileCpp=0 +Folder=B_Bot +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit271] +FileName=src\b_bot.h +CompileCpp=0 +Folder=B_Bot +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit272] +FileName=src\m_cond.c +CompileCpp=0 +Folder=M_Misc +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit273] +FileName=src\m_cond.h +CompileCpp=0 +Folder=M_Misc +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit178] +FileName=src\lua_consolelib.c +CompileCpp=0 +Folder=LUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit179] +FileName=src\lua_thinkerlib.c +CompileCpp=0 +Folder=LUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit180] +FileName=src\lua_maplib.c +CompileCpp=0 +Folder=LUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit274] +FileName=src\sdl\mixer_sound.c +CompileCpp=0 +Folder=I_Interface/SDL +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit275] +FileName=src\m_anigif.c +CompileCpp=0 +Folder=M_Misc +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit276] +FileName=src\m_anigif.h +CompileCpp=0 +Folder=M_Misc +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit277] +FileName=src\lua_hudlib.c +CompileCpp=0 +Folder=LUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit278] +FileName=src\lua_skinlib.c +CompileCpp=0 +Folder=LUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit279] +FileName=src\lua_hud.h +CompileCpp=0 +Folder=LUA +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= diff --git a/android/.classpath b/android/.classpath new file mode 100644 index 000000000..609aa00eb --- /dev/null +++ b/android/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/android/.project b/android/.project new file mode 100644 index 000000000..2654493b0 --- /dev/null +++ b/android/.project @@ -0,0 +1,33 @@ + + + SRB2 + + + + + + com.android.ide.eclipse.adt.ResourceManagerBuilder + + + + + com.android.ide.eclipse.adt.PreCompilerBuilder + + + + + org.eclipse.jdt.core.javabuilder + + + + + com.android.ide.eclipse.adt.ApkBuilder + + + + + + com.android.ide.eclipse.adt.AndroidNature + org.eclipse.jdt.core.javanature + + diff --git a/android/.settings/org.eclipse.jdt.core.prefs b/android/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..eda3d91ae --- /dev/null +++ b/android/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,5 @@ +#Mon Nov 09 14:38:16 EST 2009 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.source=1.5 diff --git a/android/Android.mk b/android/Android.mk new file mode 100644 index 000000000..650337e5c --- /dev/null +++ b/android/Android.mk @@ -0,0 +1,17 @@ +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_MODULE_TAGS := user + +LOCAL_SRC_FILES := $(call all-java-files-under, src) + +LOCAL_PACKAGE_NAME := SRB2 +LOCAL_CERTIFICATE := media + +LOCAL_REQUIRED_MODULES := libsrb2 +LOCAL_JNI_SHARED_LIBRARIES := libsrb2 + +include $(BUILD_PACKAGE) + +# Use the following include to make our test apk. +include $(call all-makefiles-under,$(LOCAL_PATH)) diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml new file mode 100644 index 000000000..cc6a1db1c --- /dev/null +++ b/android/AndroidManifest.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + diff --git a/android/default.properties b/android/default.properties new file mode 100644 index 000000000..5dad0b51a --- /dev/null +++ b/android/default.properties @@ -0,0 +1,13 @@ +# This file is automatically generated by Android Tools. +# Do not modify this file -- YOUR CHANGES WILL BE ERASED! +# +# This file must be checked in Version Control Systems. +# +# To customize properties used by the Ant build system use, +# "build.properties", and override values to adapt the script to your +# project structure. + +# Project target. +target=android-4 +# Indicates whether an apk should be generated for each density. +split.density=false diff --git a/android/gen/org/srb2/R.java b/android/gen/org/srb2/R.java new file mode 100644 index 000000000..8db10bde5 --- /dev/null +++ b/android/gen/org/srb2/R.java @@ -0,0 +1,26 @@ +/* AUTO-GENERATED FILE. DO NOT MODIFY. + * + * This class was automatically generated by the + * aapt tool from the resource data it found. It + * should not be modified by hand. + */ + +package org.srb2; + +public final class R { + public static final class attr { + } + public static final class drawable { + public static final int icon=0x7f020000; + } + public static final class id { + public static final int SoftwareRendererDisplay=0x7f050000; + } + public static final class layout { + public static final int main=0x7f030000; + } + public static final class string { + public static final int app_name=0x7f040001; + public static final int hello=0x7f040000; + } +} diff --git a/android/res/drawable-hdpi/icon.png b/android/res/drawable-hdpi/icon.png new file mode 100644 index 000000000..8074c4c57 Binary files /dev/null and b/android/res/drawable-hdpi/icon.png differ diff --git a/android/res/drawable-ldpi/icon.png b/android/res/drawable-ldpi/icon.png new file mode 100644 index 000000000..1095584ec Binary files /dev/null and b/android/res/drawable-ldpi/icon.png differ diff --git a/android/res/drawable-mdpi/icon.png b/android/res/drawable-mdpi/icon.png new file mode 100644 index 000000000..a07c69fa5 Binary files /dev/null and b/android/res/drawable-mdpi/icon.png differ diff --git a/android/res/layout/main.xml b/android/res/layout/main.xml new file mode 100644 index 000000000..32f3b483e --- /dev/null +++ b/android/res/layout/main.xml @@ -0,0 +1,9 @@ + + + + + diff --git a/android/res/values/strings.xml b/android/res/values/strings.xml new file mode 100644 index 000000000..20f67d16f --- /dev/null +++ b/android/res/values/strings.xml @@ -0,0 +1,5 @@ + + + Hello World, SRB2Game! + SRB2 + diff --git a/android/src/org/srb2/GameThread.java b/android/src/org/srb2/GameThread.java new file mode 100644 index 000000000..6aecdac74 --- /dev/null +++ b/android/src/org/srb2/GameThread.java @@ -0,0 +1,25 @@ +package org.srb2; + +import org.srb2.nativecode.SRB2; + +import android.graphics.Canvas; +import android.util.Log; +import android.view.SurfaceHolder; + +public class GameThread extends Thread { + public static String TAG = "SRB2-GameThread"; + private SurfaceHolder sh; + private SRB2 srb2; + + public GameThread(SurfaceHolder h) { + super(); + this.srb2 = new SRB2(h); + this.sh = h; + } + + @Override + public void run() { + Log.d(TAG, "Starting thread!"); + this.srb2.run(); + } +} diff --git a/android/src/org/srb2/SRB2Game.java b/android/src/org/srb2/SRB2Game.java new file mode 100644 index 000000000..ae9f43b2a --- /dev/null +++ b/android/src/org/srb2/SRB2Game.java @@ -0,0 +1,39 @@ +package org.srb2; + +import android.util.Log; +import android.view.SurfaceHolder; +import android.view.SurfaceView; +import android.view.SurfaceHolder.Callback; +import android.app.Activity; +import android.os.Bundle; + +public class SRB2Game extends Activity implements Callback { + public static String TAG = "SRB2-Activity"; + private SurfaceView sv; + private GameThread thread; + + /** Called when the activity is first created. */ + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + setContentView(R.layout.main); + + sv = (SurfaceView) findViewById(R.id.SoftwareRendererDisplay); + sv.getHolder().addCallback(this); + } + + public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) { + Log.e(TAG, "Output surface changed? OHSHI-"); + } + + public void surfaceCreated(SurfaceHolder arg0) { + Log.d(TAG, "Output surface ready! Instantiating and starting game..."); + thread = new GameThread(sv.getHolder()); + thread.start(); + } + + public void surfaceDestroyed(SurfaceHolder arg0) { + // TODO shutdown SRB2 as cleanly as possible. + } +} diff --git a/android/src/org/srb2/nativecode/Main.java b/android/src/org/srb2/nativecode/Main.java new file mode 100644 index 000000000..1a2dc200a --- /dev/null +++ b/android/src/org/srb2/nativecode/Main.java @@ -0,0 +1,13 @@ +package org.srb2.nativecode; + +import java.nio.ByteBuffer; + +public class Main { + private SRB2 srb2; + + public Main(SRB2 srb2) { + this.srb2 = srb2; + } + + public native int main(Video v); +} diff --git a/android/src/org/srb2/nativecode/SRB2.java b/android/src/org/srb2/nativecode/SRB2.java new file mode 100644 index 000000000..0f18f1eaf --- /dev/null +++ b/android/src/org/srb2/nativecode/SRB2.java @@ -0,0 +1,35 @@ +package org.srb2.nativecode; + +import android.util.Log; +import android.view.SurfaceHolder; + +/// Wraps the entire native game. This object should be wholly owned +/// by the thread it's going to run in. +public class SRB2 { + public static String TAG = "SRB2-Wrapper"; + private Main main; + public Video video; + + public SRB2(SurfaceHolder videoOut) { + try { + Log.i(TAG, "Loading native SRB2 shared object from package..."); + System.load("/data/data/org.srb2/lib/libsrb2.so"); + + } catch (UnsatisfiedLinkError ule) { + Log.i(TAG, "... it doesn't appear to be installed in the package. Looking for native library in the global search path."); + try { + System.load("libsrb2.so"); + + } catch (UnsatisfiedLinkError ule2) { + Log.e("JNI", "... no luck. Could not load libsrb2.so!"); + return; + } + } + this.video = new Video(this, videoOut); + this.main = new Main(this); + } + + public void run() { + this.main.main(this.video); + } +} diff --git a/android/src/org/srb2/nativecode/Video.java b/android/src/org/srb2/nativecode/Video.java new file mode 100644 index 000000000..d7256ee1e --- /dev/null +++ b/android/src/org/srb2/nativecode/Video.java @@ -0,0 +1,39 @@ +package org.srb2.nativecode; + +import java.nio.ByteBuffer; + +import android.graphics.Bitmap; +import android.graphics.Canvas; +import android.view.SurfaceHolder; + +public class Video { + public static int width = 340; + public static int height = 240; + private SurfaceHolder sh; + public ByteBuffer fb; + public Bitmap bmp; + + public Video(SRB2 srb2, SurfaceHolder sh) { + this.sh = sh; + fb = ByteBuffer.allocateDirect(fbSize()); + bmp = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565); + } + + private int fbSize() { + // naively assuming RGBA8888 now, even though that is entirely wrong. + // ... well, at least, that's what the Canvas/Bitmap will expect. + return width * height * 4; + } + + public void gotFrame() { + + Canvas canvas = sh.lockCanvas(); + canvas.drawARGB(0xff, 0, 0, 0); + // ugh, an extra copy. the only way to avoid this, I suppose, + // is to use the surface in native code directly. + bmp.copyPixelsFromBuffer(fb); + canvas.drawBitmap(bmp, 0, 0, null); + sh.unlockCanvasAndPost(canvas); + + } +} diff --git a/bin/Linux/Debug/.gitignore b/bin/Linux/Debug/.gitignore new file mode 100644 index 000000000..56dee6f95 --- /dev/null +++ b/bin/Linux/Debug/.gitignore @@ -0,0 +1 @@ +/lsdlsrb2 diff --git a/bin/Linux/Release/.gitignore b/bin/Linux/Release/.gitignore new file mode 100644 index 000000000..5b5c54a54 --- /dev/null +++ b/bin/Linux/Release/.gitignore @@ -0,0 +1,3 @@ +/lsdlsrb2 +/pnd +/*.mo diff --git a/bin/Linux64/Debug/.gitignore b/bin/Linux64/Debug/.gitignore new file mode 100644 index 000000000..56dee6f95 --- /dev/null +++ b/bin/Linux64/Debug/.gitignore @@ -0,0 +1 @@ +/lsdlsrb2 diff --git a/bin/Linux64/Release/.gitignore b/bin/Linux64/Release/.gitignore new file mode 100644 index 000000000..56dee6f95 --- /dev/null +++ b/bin/Linux64/Release/.gitignore @@ -0,0 +1 @@ +/lsdlsrb2 diff --git a/bin/Mingw/Debug/.gitignore b/bin/Mingw/Debug/.gitignore new file mode 100644 index 000000000..e431dca5d --- /dev/null +++ b/bin/Mingw/Debug/.gitignore @@ -0,0 +1,3 @@ +/srb2sdl.exe +/srb2win.exe +/r_opengl.dll diff --git a/bin/Mingw/Release/.gitignore b/bin/Mingw/Release/.gitignore new file mode 100644 index 000000000..e431dca5d --- /dev/null +++ b/bin/Mingw/Release/.gitignore @@ -0,0 +1,3 @@ +/srb2sdl.exe +/srb2win.exe +/r_opengl.dll diff --git a/bin/Mingw64/Debug/.gitignore b/bin/Mingw64/Debug/.gitignore new file mode 100644 index 000000000..e431dca5d --- /dev/null +++ b/bin/Mingw64/Debug/.gitignore @@ -0,0 +1,3 @@ +/srb2sdl.exe +/srb2win.exe +/r_opengl.dll diff --git a/bin/Mingw64/Release/.gitignore b/bin/Mingw64/Release/.gitignore new file mode 100644 index 000000000..e431dca5d --- /dev/null +++ b/bin/Mingw64/Release/.gitignore @@ -0,0 +1,3 @@ +/srb2sdl.exe +/srb2win.exe +/r_opengl.dll diff --git a/bin/PS3/Debug/.gitignore b/bin/PS3/Debug/.gitignore new file mode 100644 index 000000000..c4dcd19e5 --- /dev/null +++ b/bin/PS3/Debug/.gitignore @@ -0,0 +1,5 @@ +/*.elf +/*.self +/*.pkg +/*.BIN +/pkg diff --git a/bin/PS3/Release/.gitignore b/bin/PS3/Release/.gitignore new file mode 100644 index 000000000..c4dcd19e5 --- /dev/null +++ b/bin/PS3/Release/.gitignore @@ -0,0 +1,5 @@ +/*.elf +/*.self +/*.pkg +/*.BIN +/pkg diff --git a/bin/PSP/Release/.gitignore b/bin/PSP/Release/.gitignore new file mode 100644 index 000000000..98d08e695 --- /dev/null +++ b/bin/PSP/Release/.gitignore @@ -0,0 +1,4 @@ +/EBOOT.PBP +/PARAM.SFO +/SRB2PSP.PBP +/SRB2PSP.elf diff --git a/bin/Resources/debian/README.Debian b/bin/Resources/debian/README.Debian new file mode 100644 index 000000000..4d9f067ac --- /dev/null +++ b/bin/Resources/debian/README.Debian @@ -0,0 +1,12 @@ +srb2 for Debian +--------------- + +SRB2 Debian package! +Hi there, to rebuild this package just use the SRB2 Makefile system, or, optionally, run +dpkg-buildpackage in the in /bin/Resources directory. You can build these with or without a key +if you want, but if you want to put these on a repo, generate your own GnuPG key as per the +https://help.ubuntu.com/community/GnuPrivacyGuardHowto instructions and pass the -k +command to debuild. Make sure you export the key footprint and give them to your users to install +with apt-key add. Thanks! + + -- Callum Dickinson Fri, 26 Nov 2010 18:25:31 +1300 diff --git a/bin/Resources/debian/README.source b/bin/Resources/debian/README.source new file mode 100644 index 000000000..d29aaf71b --- /dev/null +++ b/bin/Resources/debian/README.source @@ -0,0 +1,4 @@ +srb2-data for Debian +--------------- + +Look in main SRB2 README.source for more information. diff --git a/bin/Resources/debian/changelog b/bin/Resources/debian/changelog new file mode 100644 index 000000000..0c514d4d2 --- /dev/null +++ b/bin/Resources/debian/changelog @@ -0,0 +1,5 @@ +srb2-data (2.0.6-2) maverick; urgency=high + + * Initial proper release.. + + -- Callum Dickinson Sat, 29 Jan 2011 01:18:42 +1300 diff --git a/bin/Resources/debian/compat b/bin/Resources/debian/compat new file mode 100644 index 000000000..7f8f011eb --- /dev/null +++ b/bin/Resources/debian/compat @@ -0,0 +1 @@ +7 diff --git a/bin/Resources/debian/control b/bin/Resources/debian/control new file mode 100644 index 000000000..123b58429 --- /dev/null +++ b/bin/Resources/debian/control @@ -0,0 +1,22 @@ +# SRB2-data Debian package control file. + +Source: srb2-data +Section: games +Priority: extra +Maintainer: Callum Dickinson +Build-Depends: debhelper (>= 7.0.50~) +Standards-Version: 3.8.4 +Homepage: http://www.srb2.org + +Package: srb2-data +Architecture: all +Description: A cross-platform 3D Sonic fangame + Sonic Robo Blast 2 is a 3D open-source Sonic the Hedgehog + fangame built using a modified version of the Doom Legacy + port of Doom. SRB2 is closely inspired by the original + Sonic games from the Sega Genesis, and attempts to recreate + the design in 3D. While SRB2 isn't fully completed, it already + features tons of levels, enemies, speed, and quite a lot + of the fun that the original Sonic games provided. + This is the data package that provides the data files that + SRB2 requires to run, it will not work without it. diff --git a/bin/Resources/debian/copyright b/bin/Resources/debian/copyright new file mode 100644 index 000000000..8a8705190 --- /dev/null +++ b/bin/Resources/debian/copyright @@ -0,0 +1,26 @@ +This work was packaged for Debian by: + + Callum Dickinson on Fri, 26 Nov 2010 15:19:16 +1300 + +It was downloaded from: + + + +Upstream Author(s): + + Sonic Team Junior + +Copyright: + + Copyright (C) 1998-2010 Sonic Team Junior + +License: + + GNU General Public License, version 2 + +The Debian packaging is: + + Copyright (C) 2010 Callum Dickinson + +and is licensed under the GPL version 2, +see "/usr/share/common-licenses/GPL-2". diff --git a/bin/Resources/debian/rules b/bin/Resources/debian/rules new file mode 100755 index 000000000..514d8e07c --- /dev/null +++ b/bin/Resources/debian/rules @@ -0,0 +1,109 @@ +#!/usr/bin/make -f +# -*- makefile -*- + +############################################################################# +# +# GNU Make Debian package makefile for SRB2-data +# +# Copyright (C) 1998-2011 by Callum Dickinson +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# This file most likely will not need to be modified to make +# branches of SRB2 capable of making their own Debian packages, +# instead look at the /debian/control file for configuration. +# +############################################################################# + +# Uncomment this to turn on verbose mode. +#export DH_VERBOSE=1 + +# user/group of to-be-installed files +ROOT_USER := 0 +ROOT_GROUP := 0 + +MKDIR := mkdir -p +INSTALL := install -o $(ROOT_USER) -g $(ROOT_GROUP) -m 644 +MV := mv +RM := rm -rf +DIR := $(shell pwd) + +PACKAGE := $(shell cat $(DIR)/debian/control | grep 'Package:' | sed -e 's/Package: //g') +DATAFILES := drill.dta music.dta soar.dta zones.dta player.dta rings.wpn srb2.wad + +DATADIR := usr/games/SRB2 +RESOURCEDIR := . +WGET := wget -P $(RESOURCEDIR) -c -nc + +build: + $(MKDIR) $(DIR)/debian/tmp/$(DATADIR) + # This will need to be updated every time SRB2 official version is + # Copy data files to their install locations, and add data files to include-binaries + for file in $(DATAFILES); do \ + $(WGET) http://alam.srb2.org/SRB2/2.0.6-Final/Resources/$$file; \ + if test "$$file" = "srb2.wad"; then \ + $(INSTALL) $(RESOURCEDIR)/$$file $(DIR)/debian/tmp/$(DATADIR)/srb2.srb; \ + else \ + $(INSTALL) $(RESOURCEDIR)/$$file $(DIR)/debian/tmp/$(DATADIR)/$$file; \ + fi; \ + echo $(RESOURCEDIR)/$$file >> $(DIR)/debian/source/include-binaries; \ + done + +binary-indep: + # Generate install folder file + echo $(DATADIR) > $(DIR)/debian/$(PACKAGE).install + +binary-arch: + # only here to kill Lintian warning + echo "no need to do any arch-specific stuff" + +binary: binary-indep + dh_testdir + dh_testroot + dh_installchangelogs + # dh_installdocs + # dh_installexamples + dh_install --sourcedir=$(DIR)/debian/tmp + # dh_installmenu + # dh_installdebconf + # dh_installlogrotate + # dh_installemacsen + # dh_installpam + # dh_installmime + # dh_python + # dh_installinit + # dh_installcron + # dh_installinfo + # dh_installman + # dh_link + dh_compress + dh_fixperms + # dh_perl + # dh_makeshlibs + dh_installdeb + # -dh_shlibdeps + dh_gencontrol + dh_md5sums + dh_builddeb + +clean: + $(RM) $(RESOURCEDIR)/*.wad + $(RM) $(RESOURCEDIR)/*.dta + $(RM) $(RESOURCEDIR)/*.plr + $(RM) $(RESOURCEDIR)/*.wpn + $(RM) $(RESOURCEDIR)/*.srb + $(RM) $(RESOURCEDIR)/*.dll + $(RM) $(DIR)/debian/tmp/* + $(RM) $(DIR)/debian/$(PACKAGE).install + $(RM) $(DIR)/debian/files + $(RM) $(DIR)/debian/source/include-binaries + +.PHONY: all clean binary binary-arch binary-indep build diff --git a/bin/Resources/debian/source/format b/bin/Resources/debian/source/format new file mode 100644 index 000000000..163aaf8d8 --- /dev/null +++ b/bin/Resources/debian/source/format @@ -0,0 +1 @@ +3.0 (quilt) diff --git a/bin/Resources/exchndl.dll b/bin/Resources/exchndl.dll new file mode 100644 index 000000000..d836a6762 Binary files /dev/null and b/bin/Resources/exchndl.dll differ diff --git a/bin/Resources/fmod.dll b/bin/Resources/fmod.dll new file mode 100644 index 000000000..6b0e379d3 Binary files /dev/null and b/bin/Resources/fmod.dll differ diff --git a/bin/Resources/fmod64.dll b/bin/Resources/fmod64.dll new file mode 100644 index 000000000..2a8bab284 Binary files /dev/null and b/bin/Resources/fmod64.dll differ diff --git a/bin/Resources/fmodex.dll b/bin/Resources/fmodex.dll new file mode 100644 index 000000000..875f8a267 Binary files /dev/null and b/bin/Resources/fmodex.dll differ diff --git a/bin/Resources/fmodex64.dll b/bin/Resources/fmodex64.dll new file mode 100644 index 000000000..f08c0033b Binary files /dev/null and b/bin/Resources/fmodex64.dll differ diff --git a/bin/Resources/fmodexL.dll b/bin/Resources/fmodexL.dll new file mode 100644 index 000000000..1ac9e21c9 Binary files /dev/null and b/bin/Resources/fmodexL.dll differ diff --git a/bin/Resources/fmodexL64.dll b/bin/Resources/fmodexL64.dll new file mode 100644 index 000000000..463628c6e Binary files /dev/null and b/bin/Resources/fmodexL64.dll differ diff --git a/bin/Resources/libgcc_s_dw2-1.dll b/bin/Resources/libgcc_s_dw2-1.dll new file mode 100644 index 000000000..19b729559 Binary files /dev/null and b/bin/Resources/libgcc_s_dw2-1.dll differ diff --git a/bin/Resources/libgme.dll b/bin/Resources/libgme.dll new file mode 100644 index 000000000..ddf8b0d82 Binary files /dev/null and b/bin/Resources/libgme.dll differ diff --git a/bin/Resources/libintl-8.dll b/bin/Resources/libintl-8.dll new file mode 100644 index 000000000..9f10b6c55 Binary files /dev/null and b/bin/Resources/libintl-8.dll differ diff --git a/bin/VC/.gitignore b/bin/VC/.gitignore new file mode 100644 index 000000000..e52f825b2 --- /dev/null +++ b/bin/VC/.gitignore @@ -0,0 +1,2 @@ +/Release +/Debug diff --git a/bin/VC9/.gitignore b/bin/VC9/.gitignore new file mode 100644 index 000000000..205fe45de --- /dev/null +++ b/bin/VC9/.gitignore @@ -0,0 +1,2 @@ +/Win32 +/x64 diff --git a/bin/Wii/Debug/.gitignore b/bin/Wii/Debug/.gitignore new file mode 100644 index 000000000..200eea51f --- /dev/null +++ b/bin/Wii/Debug/.gitignore @@ -0,0 +1,3 @@ +/*.elf +/*.dol +/apps diff --git a/bin/Wii/Release/.gitignore b/bin/Wii/Release/.gitignore new file mode 100644 index 000000000..200eea51f --- /dev/null +++ b/bin/Wii/Release/.gitignore @@ -0,0 +1,3 @@ +/*.elf +/*.dol +/apps diff --git a/bin/nds/Debug/.gitignore b/bin/nds/Debug/.gitignore new file mode 100644 index 000000000..9bfc4a51d --- /dev/null +++ b/bin/nds/Debug/.gitignore @@ -0,0 +1,3 @@ +*.arm9 +*.elf* +*.nds diff --git a/bin/nds/Release/.gitignore b/bin/nds/Release/.gitignore new file mode 100644 index 000000000..9bfc4a51d --- /dev/null +++ b/bin/nds/Release/.gitignore @@ -0,0 +1,3 @@ +*.arm9 +*.elf* +*.nds diff --git a/comptime.bat b/comptime.bat new file mode 100644 index 000000000..23ee7ea55 --- /dev/null +++ b/comptime.bat @@ -0,0 +1,10 @@ +@ECHO OFF +set REV=Unknown +copy nul: /b +%1\comptime.c tmp.$$$ > nul +move tmp.$$$ %1\comptime.c > nul +SET REV=illegal +FOR /F "usebackq" %%s IN (`svnversion %1`) DO @SET REV=%%s +ECHO // Do not edit! This file was autogenerated > %1\comptime.h +ECHO // by the %0 batch file >> %1\comptime.h +ECHO // >> %1\comptime.h +ECHO const char* comprevision = "r%REV%"; >> %1\comptime.h diff --git a/comptime.mk b/comptime.mk new file mode 100644 index 000000000..b5e4f7a39 --- /dev/null +++ b/comptime.mk @@ -0,0 +1,21 @@ +#Add-on Makefile for wxDev-C++ project file +SRCDIR=src +ifdef ComSpec +COMSPEC=$(ComSpec) +endif + +all-before: +ifdef COMSPEC + ${RM} $(SRCDIR)\comptime.h + comptime.bat $(SRCDIR) +else + ${RM} $(SRCDIR)/comptime.h + ./comptime.sh $(SRCDIR) +endif + +clean-custom: +ifdef COMSPEC + ${RM} $(SRCDIR)\comptime.h +else + ${RM} $(SRCDIR)/comptime.h +endif diff --git a/comptime.sh b/comptime.sh new file mode 100755 index 000000000..1bd35b629 --- /dev/null +++ b/comptime.sh @@ -0,0 +1,50 @@ +#!/bin/sh -e +path="." +if [ x"$1" != x ]; then + path="$1" +fi + +versiongit() { + gitversion=`git svn log HEAD --limit=1 --oneline | cut -f 1 -d " "` + cat < $path/comptime.h + +// Do not edit! This file was autogenerated +// by the $0 script with git svn +// +const char* comprevision = "$gitversion"; +EOF +exit 0 +} + +versionsvn() { + svnrevision=`svnversion -n $1` + cat < $path/comptime.h + +// Do not edit! This file was autogenerated +// by the $0 script with subversion +// +const char* comprevision = "r$svnrevision"; +EOF +exit 0 +} + +versionfake() { + cat < $path/comptime.h + +// Do not edit! This file was autogenerated +// by the $0 script with an unknown or nonexist SCM +// +const char* comprevision = "illegal"; +EOF +} + +compversion() { +touch $path/comptime.c +versionfake +test -d $path/.svn && versionsvn +test -d $path/../.git && versiongit +exit 1 +} + +test -f $path/comptime.c && compversion +exit 2 diff --git a/cpdebug.mk b/cpdebug.mk new file mode 100644 index 000000000..440ffe384 --- /dev/null +++ b/cpdebug.mk @@ -0,0 +1,32 @@ +#Add-on Makefile for wxDev-C++ project file +ifdef ComSpec +COMSPEC=$(ComSpec) +endif +ifdef COMSPEC +OBJCOPY=objcopy.exe +OBJDUMP=objdump.exe +GZIP?=gzip.exe +else +OBJCOPY=objcopy +OBJDUMP=objdump +GZIP?=gzip +endif +DBGNAME=$(BIN).debug +OBJDUMP_OPTS?=--wide --source --line-numbers +GZIP_OPTS?=-9 -f -n +GZIP_OPT2=$(GZIP_OPTS) --rsyncable +UPX?=upx +UPX_OPTS?=--best --preserve-build-id +UPX_OPTS+=-q + +all-after: + $(OBJDUMP) $(OBJDUMP_OPTS) "$(BIN)" > "$(DBGNAME).txt" + $(OBJCOPY) $(BIN) $(DBGNAME) + $(OBJCOPY) --strip-debug $(BIN) + -$(OBJCOPY) --add-gnu-debuglink=$(DBGNAME) $(BIN) + -$(GZIP) $(GZIP_OPTS) $(DBGNAME).txt +ifndef COMSPEC + $(GZIP) $(GZIP_OPT2) $(DBGNAME).txt +endif + -$(UPX) $(UPX_OPTS) $(BIN) + diff --git a/debian/README.Debian b/debian/README.Debian new file mode 100644 index 000000000..bbc306b16 --- /dev/null +++ b/debian/README.Debian @@ -0,0 +1,11 @@ +srb2 for Debian +--------------- + +SRB2 Debian package! +Hi there, to rebuild these packages just use debuild in the root source directory (not /src!). +You can build these with or without a key if you want, but if you want to put these on a repo, +generate your own GnuPG key as per the https://help.ubuntu.com/community/GnuPrivacyGuardHowto +instructions and pass the -k command to debuild. Make sure you export the key footprint +and give them to your users to install with apt-key add. Thanks! + + -- Callum Dickinson Fri, 26 Nov 2010 18:25:31 +1300 diff --git a/debian/README.source b/debian/README.source new file mode 100644 index 000000000..3f532203d --- /dev/null +++ b/debian/README.source @@ -0,0 +1,42 @@ +srb2 for Debian +--------------- + +Here it is! SRB2 v2.0 source code! + +GNU/Linux +~~~ + +Dependencies: + SDL 1.2.7 or better (from libsdl.org) + SDL_Mixer 1.2.2(.7 for file-less music playback) (from libsdl.org) + Nasm (use NOASM=1 if you don't have it or have an non-i386 system, I think) + libPNG 1.2.7 + Zlib 1.2.3 + The Xiph.org libogg and libvorbis libraries + The OpenGL headers (from Mesa, usually shipped with your X.org or XFree + installation, so you needn't worry, most likely) + GCC 3.x toolchain and binutils + GNU Make + +Build instructions: + +make -C src LINUX=1 + +Build instructions to build for Wii Linux/SRB2Wii on a PowerPC system, +follow cross-compiling instructions for cross-compiling on a x86 system: + +make -C src LINUX=1 WIILINUX=1 + +Build instructions to build for Pandora (Linux) on a ARM system, +follow cross-compiling instructions for cross-compiling on a x86 system: + +make -C src PANDORA=1 + +------------------------------------------------------------------------------- + +binaries will turn in up in bin/ + +note: read the src/makefile for more options + +- Sonic Team Junior +http://www.srb2.org diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 000000000..b454b1abd --- /dev/null +++ b/debian/changelog @@ -0,0 +1,5 @@ +srb2 (2.0.6-5) maverick; urgency=high + + * Initial proper release.. + + -- Callum Dickinson Sat, 29 Jan 2011 01:18:42 +1300 diff --git a/debian/compat b/debian/compat new file mode 100644 index 000000000..7f8f011eb --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +7 diff --git a/debian/control b/debian/control new file mode 100644 index 000000000..c64a85c48 --- /dev/null +++ b/debian/control @@ -0,0 +1,36 @@ +# SRB2 Debian package control file. + +Source: srb2 +Section: games +Priority: extra +Maintainer: Callum Dickinson +Build-Depends: debhelper (>= 7.0.50~), libsdl1.2-dev (>= 1.2.7), libsdl-mixer1.2-dev (>= 1.2.7), libpng12-dev (>= 1.2.7), libglu1-dev | libglu-dev, libosmesa6-dev | libgl-dev, nasm [i386] +Standards-Version: 3.8.4 +Homepage: http://www.srb2.org + +Package: srb2 +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends}, srb2-data (= 2.0.6) +Description: A cross-platform 3D Sonic fangame + Sonic Robo Blast 2 is a 3D open-source Sonic the Hedgehog + fangame built using a modified version of the Doom Legacy + port of Doom. SRB2 is closely inspired by the original + Sonic games from the Sega Genesis, and attempts to recreate + the design in 3D. While SRB2 isn't fully completed, it already + features tons of levels, enemies, speed, and quite a lot + of the fun that the original Sonic games provided. + +Package: srb2-dbg +Architecture: any +# FIXME: should be Depends: ${shlibs:Depends}, ${misc:Depends}, srb2-data (= 2.0.6), srb2 but dh_shlibdeps is being an asshat +Depends: libc6, ${misc:Depends}, srb2-data (= 2.0.6), srb2 +Description: A cross-platform 3D Sonic fangame + Sonic Robo Blast 2 is a 3D open-source Sonic the Hedgehog + fangame built using a modified version of the Doom Legacy + port of Doom. SRB2 is closely inspired by the original + Sonic games from the Sega Genesis, and attempts to recreate + the design in 3D. While SRB2 isn't fully completed, it already + features tons of levels, enemies, speed, and quite a lot + of the fun that the original Sonic games provided. + This is a debug binary, its symbols will be loaded by gdb + when the user starts the game with gdb for debugging. diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 000000000..8a8705190 --- /dev/null +++ b/debian/copyright @@ -0,0 +1,26 @@ +This work was packaged for Debian by: + + Callum Dickinson on Fri, 26 Nov 2010 15:19:16 +1300 + +It was downloaded from: + + + +Upstream Author(s): + + Sonic Team Junior + +Copyright: + + Copyright (C) 1998-2010 Sonic Team Junior + +License: + + GNU General Public License, version 2 + +The Debian packaging is: + + Copyright (C) 2010 Callum Dickinson + +and is licensed under the GPL version 2, +see "/usr/share/common-licenses/GPL-2". diff --git a/debian/docs b/debian/docs new file mode 100644 index 000000000..f3d4ef20e --- /dev/null +++ b/debian/docs @@ -0,0 +1,2 @@ +readme.txt +readme.txt diff --git a/debian/rules b/debian/rules new file mode 100755 index 000000000..33ade54c8 --- /dev/null +++ b/debian/rules @@ -0,0 +1,137 @@ +#!/usr/bin/make -f +# -*- makefile -*- + +############################################################################# +# +# GNU Make Debian package makefile for SRB2 +# +# Copyright (C) 1998-2010 by Callum Dickinson +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# This file most likely will not need to be modified to make +# branches of SRB2 capable of making their own Debian packages, +# instead look at the /debian/control file for configuration. +# +############################################################################# + +# Uncomment this to turn on verbose mode. +#export DH_VERBOSE=1 + +# user/group of to-be-installed files +ROOT_USER := 0 +ROOT_GROUP := 0 + +# determine cross-compile (may need some work) +CROSS_COMPILE_BUILD := $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE) +CROSS_COMPILE_HOST := $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE) +CROSS_COMPILE := $(shell test "$(CROSS_COMPILE_BUILD)" != "$(CROSS_COMPILE_HOST)" && echo "$(CROSS_COMPILE_HOST)") + +MKDIR = mkdir -p +MAKE = make +INSTALL = install -o $(ROOT_USER) -g $(ROOT_GROUP) -m 644 +MV = mv +RM = rm -rf +STRIPARGS = --strip-unneeded +ifdef CROSS_COMPILE +STRIP = $(CROSS_COMPILE_HOST)-strip $(STRIPARGS) +else +STRIP = strip $(STRIPARGS) +endif +DIR := $(shell pwd) + +# FIXME: hate hate hate head/tail hack :( +CONTROLF = $(DIR)/debian/control +PACKAGE = srb2 +DBGPKG = $(PACKAGE)-dbg +TITLE = Sonic Robo Blast 2 +SECTION = Games/Action +EXENAME = srb2 +DBGNAME = debug/$(EXENAME) + +PKGDIR = usr/games +DBGDIR = usr/lib/debug/$(PKGDIR) +PREFIX = $(shell test "$(CROSS_COMPILE_BUILD)" != "$(CROSS_COMPILE_HOST)" && echo "PREFIX=$(CROSS_COMPILE_HOST)") +OS = LINUX=1 +NONX86 = $(shell test "`echo $(CROSS_COMPILE_HOST) | grep 'i[3-6]86'`" || echo "NONX86=1") +MAKEARGS = $(OS) $(NONX86) $(PREFIX) EXENAME=$(EXENAME) DBGNAME=$(DBGNAME) SDL_PKGCONFIG=sdl PNG_PKGCONFIG=libpng NOOBJDUMP=1 +MENUFILE1 = ?package($(PACKAGE)):needs="X11" section="$(SECTION)" +MENUFILE2 = title="$(TITLE)" command="/$(PKGDIR)/$(PACKAGE)" +# FIXME pkg-config dir hacks +export PKG_CONFIG_LIBDIR = /usr/$(CROSS_COMPILE_HOST)/lib/pkgconfig +BINDIR := $(DIR)/bin/Linux/Release +LDFLAGS += "-Wl,-rpath=/usr/$(CROSS_COMPILE_HOST)/lib/" + +build: + $(MKDIR) $(BINDIR)/debug + $(MAKE) -C $(DIR)/src $(MAKEARGS) + $(STRIP) $(BINDIR)/$(EXENAME) + +binary-indep: + # only here to kill Lintian warning + echo "no need to do any arch-independent stuff" + +binary-arch: + $(MKDIR) $(DIR)/debian/tmp/$(PKGDIR) $(DIR)/debian/tmp/$(DBGDIR) + $(INSTALL) $(BINDIR)/$(EXENAME) $(DIR)/debian/tmp/$(PKGDIR)/$(PACKAGE) + $(INSTALL) $(BINDIR)/$(DBGNAME) $(DIR)/debian/tmp/$(DBGDIR)/$(PACKAGE) + # add compiled binaries to include-binaries + echo $(BINDIR)/$(EXENAME) >> $(DIR)/debian/source/include-binaries + echo $(BINDIR)/$(EXENAME) >> $(DIR)/debian/source/include-binaries + # Generate install folder files + echo $(PKGDIR) > $(DIR)/debian/$(PACKAGE).install + echo $(DBGDIR) > $(DIR)/debian/$(DBGPKG).install + +binary: binary-arch + # Generate .desktop specifications + echo "`echo '$(MENUFILE1)\\'`" > $(DIR)/debian/menu + echo " `echo '$(MENUFILE2)'`" >> $(DIR)/debian/menu + dh_testdir + dh_testroot + dh_installchangelogs + dh_installdocs + # dh_installexamples + dh_install --sourcedir=$(DIR)/debian/tmp + dh_installmenu + # dh_installdebconf + # dh_installlogrotate + # dh_installemacsen + # dh_installpam + # dh_installmime + # dh_python + # dh_installinit + # dh_installcron + # dh_installinfo + # dh_installman + # dh_link + dh_compress + dh_fixperms + # dh_perl + # dh_makeshlibs + dh_installdeb + -dh_shlibdeps + dh_gencontrol + dh_md5sums + dh_builddeb + +clean: + $(MAKE) -C $(DIR)/src $(MAKEARGS) clean cleandep + $(RM) $(BINDIR)/* + $(RM) $(DIR)/debian/$(PACKAGE)/* + $(RM) $(DIR)/debian/$(DBGPKG)/* + $(RM) $(DIR)/debian/tmp/* + $(RM) $(DIR)/debian/$(PACKAGE).install + $(RM) $(DIR)/debian/$(DBGPKG).install + $(RM) $(DIR)/debian/menu + $(RM) $(DIR)/debian/files + $(RM) $(DIR)/debian/source/include-binaries + +.PHONY: all clean binary binary-arch binary-indep build diff --git a/debian/source/format b/debian/source/format new file mode 100644 index 000000000..89ae9db8f --- /dev/null +++ b/debian/source/format @@ -0,0 +1 @@ +3.0 (native) diff --git a/doc/.gitignore b/doc/.gitignore new file mode 100644 index 000000000..36a49a811 --- /dev/null +++ b/doc/.gitignore @@ -0,0 +1 @@ +/SRB2 diff --git a/doc/Doublescan.txt b/doc/Doublescan.txt new file mode 100644 index 000000000..5e492ec89 --- /dev/null +++ b/doc/Doublescan.txt @@ -0,0 +1,93 @@ + ================================================================ + How to add Low-res modes to your XF86Config under Linux MANUALLY + ================================================================ + + I TAKE NO RESPONSIBILITY FOR ANY DAMAGE DONE TO YOUR EQUIPMENT!!! + + This document explains how to add low-res modes like 320x200 to your + X-Server configuration, because some new setup tools for the X-Server + do not support this. ONLY RECOMMENDED FOR USERS WHO KNOW WHAT THEY DO! + + I do not take any responsibility for damage done to your monitor, your + videocard, your harddisk, your cat, your dog or anything else!!! + IMPORTANT IS, THAT YOUR "HorizSync" AND "VertRefresh" VALUES REALLY + MATCH YOUR MONITOR! OTHERWISE YOUR MONITOR CAN BLOW UP!!! + + OK, if you have read up to here, you either know what you do or really + die-hard want those low-res modes. Here is what to do: + Look up your XF86Config. Is is either in /etc or in /etc/X11. Here is + what you have to add to the definition of your modeslines: + +# Low-res Doublescan modes +# If your chipset does not support doublescan, you get a 'squashed' +# resolution like 320x400. + +# 320x200 @ 70 Hz, 31.5 kHz hsync, 8:5 aspect ratio +Modeline "320x200" 12.588 320 336 384 400 200 204 205 225 Doublescan +# 320x240 @ 60 Hz, 31.5 kHz hsync, 4:3 aspect ratio +Modeline "320x240" 12.588 320 336 384 400 240 245 246 262 Doublescan +# 320x240 @ 72 Hz, 36.5 kHz hsync +Modeline "320x240" 15.750 320 336 384 400 240 244 246 262 Doublescan +# 400x300 @ 56 Hz, 35.2 kHz hsync, 4:3 aspect ratio +ModeLine "400x300" 18 400 416 448 512 300 301 302 312 Doublescan +# 400x300 @ 60 Hz, 37.8 kHz hsync +Modeline "400x300" 20 400 416 480 528 300 301 303 314 Doublescan +# 400x300 @ 72 Hz, 48.0 kHz hsync +Modeline "400x300" 25 400 424 488 520 300 319 322 333 Doublescan + + If your video card only supports a specific set of discrete dotclocks + (RAMDAC) you may have to replace the dotclocks given here by one of the + specified (e.g in the first modeline the dotclock is 12.588 MHz). I believe + that nowadays all cards and monitors should work with these settings, but + if you have outdated hardware you better check the frequencies yourself. If + there is any uncertainty, please check the "XFree86 Video Timings HOWTO". + + + Then have a look at the section "Screen" with the appropriate driver + (usually either "svga" or "accel"). Under Subsection "Display" there + are modes for the given color depth. Add the desired modes. As an + example I give you my screens definition here with low-res modes in + 16 bit color depth: + +Section "Screen" + Driver "accel" + Device "3D Charger" + Monitor "Iiyama Pro 450" + DefaultColorDepth 16 + + Subsection "Display" + Depth 8 + Modes "1280x1024" "1024x768" "800x600" "640x480" + ViewPort 0 0 + Virtual 1280 1024 + EndSubsection + Subsection "Display" + Depth 16 + Modes "1152x864" "1024x768" "800x600" "640x480" "400x300" "320x200" <- THIS IS ACTUALLY WHAT YOU WANT!!! + ViewPort 0 0 ^^^^^^^^^^^^^^^^^^^ + Virtual 1152 864 + EndSubsection + Subsection "Display" + Depth 24 + Modes "800x600" "640x480" + ViewPort 0 0 + Virtual 800 600 + EndSubsection + Subsection "Display" + Depth 32 + Modes "800x600" "640x480" + ViewPort 0 0 + Virtual 800 600 + EndSubsection +EndSection + + Once again: important is, that you edit the correct Screen section. + If you use the SVGA Server and edit the ACCEL Server, you might + wonder where your new modes have gone. + + If everything went fine and you want to say thank you, just write + to "metzgermeister@users.sourceforge.net". If your monitor blew + up and you want to kill me, find me playing Legacy or Q3A on the net + and frag me (with your second monitor, hehe). + + - metzgermeister diff --git a/doc/Item Ranges.txt b/doc/Item Ranges.txt new file mode 100644 index 000000000..60251e547 --- /dev/null +++ b/doc/Item Ranges.txt @@ -0,0 +1,212 @@ +1-99 : Player Starts + 1 - Player 1 Start 1 + 2 - Player 2 Start 2 + 3 - Player 3 Start 3 + 4 - Player 4 Start 4 + 5 - Player 5 Start 4001 + 6 - Player 6 Start 4002 + 7 - Player 7 Start 4003 + 8 - Player 8 Start 4004 + 9 - Player 9 Start 4005 + 10 - Player 10 Start 4006 + 11 - Player 11 Start 4007 + 12 - Player 12 Start 4008 + 13 - Player 13 Start 4009 + 14 - Player 14 Start 4010 + 15 - Player 15 Start 4011 + 16 - Player 16 Start 4012 + 17 - Player 17 Start 4013 + 18 - Player 18 Start 4014 + 19 - Player 19 Start 4015 + 20 - Player 20 Start 4016 + 21 - Player 21 Start 4017 + 22 - Player 22 Start 4018 + 23 - Player 23 Start 4019 + 24 - Player 24 Start 4020 + 25 - Player 25 Start 4021 + 26 - Player 26 Start 4022 + 27 - Player 27 Start 4023 + 28 - Player 28 Start 4024 + 29 - Player 29 Start 4025 + 30 - Player 30 Start 4026 + 31 - Player 31 Start 4027 + 32 - Player 32 Start 4028 + 33 - Player Match Start 11 + 34 - Red Team Start 87 + 35 - Blue Team Start 89 + 36 - Tag start New + +100 - 199 : Enemies + 100 - Blue Crawla 3004 + 101 - Red Crawla 9 + 102 - GFZ Fish 58 + 103 - Gold Buzz 5005 + 104 - Red Buzz 5006 + 105 - Jetty-Syn Bomber 3005 + 106 - Jetty-Syn Gunner 22 + 107 - Crawla Commander 21 + 108 - Deton 71 + 109 - Skim 56 + 110 - THZ Turret 2004 + 111 - Pop-up Turret 42 + +200 - 299 : Bosses and their associated items (if any) + 200 - Boss 1 16 + 201 - Boss 2 2008 + 290 - Boss Fly Point 17 + 291 - EggTrap Center 2049 + +300 - 399 : Collectibles + 300 - Ring 2014 + 301 - Homing Ring 69 + 302 - Rail Ring 3003 + 303 - Infinity Ring 80 + 304 - Automatic Ring 26 + 305 - Explosion Ring 54 + 306 - Red CTF Flag 31 + 307 - Blue CTF Flag 34 + 308 - Special Stage Token 2013 + 309 - Emerald 1 420 + 310 - Emerald 2 421 + 311 - Emerald 3 422 + 312 - Emerald 4 423 + 313 - Emerald 5 424 + 314 - Emerald 6 425 + 315 - Emerald 7 426 + 316 - Hunting Emerald 1 64 + 317 - Hunting Emerald 2 3002 + 318 - Hunting Emerald 3 3001 + +400 - 499 : Boxes + 400 - Super Ring Box 2011 + 401 - Grey Ring Box 2012 + 402 - Ring Shield Box 48 + 403 - Fire Shield Box 2002 + 404 - Bomb Shield Box 2018 + 405 - Jump Shield Box 35 + 406 - Water Shield Box 2028 + 407 - Sneaker Box 25 + 408 - Invincibility Box 2022 + 409 - 1-Up Box 41 + 410 - Eggman Box 2005 + 411 - Mixup Box 78 + 412 - Question Box 3000 + +500 - 599 : Interactive Objects (friendly or otherwise - includes springs) + 500 - Bubble Patch 33 + 501 - Level End Sign 86 + 502 - Starpost 3006 + 520 - Spike Ball -1 + 521 - Special Stage Spike Ball 23 + 522 - Ceiling Spike 67 + 523 - Floor Spike 68 + 540 - Fan 32 + 541 - Steam Riser 30 + 550 - Yellow Spring 28 + 551 - Red Spring 79 + 552 - Blue Spring 5004 + 553 - Yellow Spring Down 65 + 554 - Red Spring Down 66 + 555 - Yellow Diagonal Spring 2015 + 556 - Red Diagonal Spring 38 + 557 - Yellow Diag Spring Down 20 + 558 - Red Diag Spring Down 39 + +600 - 699 : Special placement patterns + 600 - Vertical Rigns - Stack of 5 (suitable for Yellow Spring) 84 + 601 - Vertical Rings - Stack of 5 (suitable for Red Spring) 44 + 602 - Diagonal rings (5) 76 + 603 - Diagonal rings (10) 77 + 604 - A ring of rings 47 + 605 - A BIGGER ring of rings 2007 + 606 - A ring of wing items 2048 + 607 - A BIGGER ring of wing items 2010 + 608 - A ring of rings and wings (alternating) 2046 + 609 - A BIGGER ring of rings and wings (alternating) 2047 + +700 - 799 : Powerup indicators/environmental effects/miscellany + 700 - Ambient Water 1a (S) 2026 + 701 - Ambient Water 1b (S) 2024 + 702 - Ambient Water 2a (M) 2023 + 703 - Ambient Water 2b (M) 2045 + 704 - Ambient Water 3a (L) 83 + 705 - Ambient Water 3b (L) 2019 + 706 - Ambient Water 4a (XL) 2025 + 707 - Ambient Water 4b (XL) 27 + 708 - Random Ambient 1 14 + 709 - Random Ambient 2 43 + 750 - Chaos Spawner 8 + 751 - Teleport Point 5003 + 752 - Alternate View Point 5007 + 753 - Zoom Tube Waypoint 18 + 754 - Pusher 5001 + 755 - Puller 5002 + 756 - Street Light 2003 + +800 - 899 : Greenflower Scenery + 800 - Flower 1 36 + 801 - Flower 2 70 + 802 - Flower 3 73 + 804 - Berry Bush 74 + 805 - Bush 75 + +900 - 999 : Techno Hill Scenery + 900 - THZ Plant 2035 + 901 - Alarm 2006 + +1000 - 1099 : Deep Sea Scenery + 1000 - Gargoyle 81 + +1100 - 1199 : Castle Eggman Scenery + 1100 - Ceiling Chain 49 + 1101 - Torch Flame 24 + 1102 - Eggman Statue 52 + 1103 - CEZ Flower 2001 + +1200 - 1299 : Arid Canyon Scenery +1300 - 1399 : Red Volcano Scenery +1400 - 1499 : Dark City Scenery +1500 - 1599 : Doom Ship Scenery +1600 - 1699 : Egg Rock/Final Fight Scenery +1700 - 1799 : NiGHTS Items + 1700 - Axis 72 + 1701 - Axis Transfer (Normal) 61 + 1702 - Axis Transfer (Line) 46 + 1703 - Nights Drone 60 + 1704 - Nights Bumper 82 + 1705 - Hoop 57 + 1706 - Nights Wing 37 + 1707 - Super Loop Powerup 3007 + 1708 - Drill Refill Powerup 3008 + 1709 - Helper Powerup 3009 + 1710 - Egg Capsule 40 + +1800 - 1849 : Mario Items + 1800 - Coin 10005 + 1801 - Goomba 10000 + 1802 - Blue Goomba 10001 + 1803 - FireFlower 50 + 1804 - Shell 10 + 1805 - Puma 29 + 1806 - Koopa 19 + 1807 - Axe 12 + 1808 - Mario Bush 1 10002 + 1809 - Mario Bush 2 10003 + 1810 - Toad 10004 + +1850 - 1899 : Christmas Items + 1850 - Xmas Pole 5 + 1851 - Candy Cane 13 + 1852 - Snowman 6 + +1900 - 1999 : Misc Scenery + 1900 - Stalagmite 0 + 1901 - Stalagmite 1 + 1902 - Stalagmite 2 + 1903 - Stalagmite 3 + 1904 - Stalagmite 4 + 1905 - Stalagmite 5 + 1906 - Stalagmite 6 + 1907 - Stalagmite 7 + 1908 - Stalagmite 8 + 1909 - Stalagmite 9 diff --git a/doc/Linedef Ranges.txt b/doc/Linedef Ranges.txt new file mode 100644 index 000000000..81fa695a0 --- /dev/null +++ b/doc/Linedef Ranges.txt @@ -0,0 +1,223 @@ + Description OldNum NewNum Description + Old Water 14 Removed + + Level Parameters/Misc: + Per-Sector Gravity 64 1 + Custom Exit 71 2 + Zoom Tube Parameters 18 3 + Speed Pad 65 4 + Camera Scanner 63 5 + Disable Linedef 73 6 + Flat Alignment 66 7 + Sector Special Parameters New 8 + Mace Parameters New 9 + Sprite Cull Height New 10 + Rope Hang Parameters New 11 + Rock Spawner Parameters New 12 + + PolyObjects + Marks first line in PolyObject New 20 + Explicitly includes a PolyObject line New 21 + PolyObject: Parameters New 22 + PolyObject: Waving Flag New 31 + + Level-Load Effects: + Instant Floor Lower 26 50 + Instant Ceiling Raise 24 51 + Continuously Falling Sector 88 52 + Continuous Floor/Ceiling Mover 2 53 + Continuous Floor Mover 3 54 + Continuous Ceiling Mover 4 55 + Continuous Two-Speed Floor/Ceiling Mover 6 56 + Continuous Two-Speed Floor Mover 7 57 + Continuous Two-Speed Ceiling Mover 8 58 + Activate Floating Platform 232 59 + Activate Floating Platform (Adjustable Speed) 233 60 + Crusher 1 (Ceiling to Floor) 43 61 + Crusher 2 (Floor to Ceiling) 50 62 + Fake Floor/Ceiling 242 63 + Appearing/Disappearing FOF New 64 + Bridge Thinker New 65 + + Floor Over Floors: + "Floor Over Floor: Solid, Opaque, Shadowcasting " 25 100 + "Floor Over Floor: Solid, Opaque, Non-Shadowcasting " 33 101 + "Floor Over Floor: Solid, Translucent " 44 102 + "Floor Over Floor: Solid, Sides Only " 69 103 + "Floor Over Floor: Solid, No Sides " 51 104 + "Floor Over Floor: Solid, Invisible " 57 105 + + "Floor Over Floor: Water, Opaque " 48 120 + "Floor Over Floor: Water, Translucent " 45 121 + "Floor Over Floor: Water, Opaque, No Sides " 75 122 + "Floor Over Floor: Water, Translucent, No Sides " 74 123 + + "Floor Over Floor: Platform, Opaque " 59 140 + "Floor Over Floor: Platform, Translucent " 81 141 + "Floor Over Floor: Platform, Translucent, No Sides " 77 142 + + Floor Over Floor: Bobbing (Air) 38 150 + Floor Over Floor: Adjustable Bobbing (Air) 68 151 + Floor Over Floor: Reverse Adjustable Bobbing (Air) 72 152 + + "Floor Over Floor: Floating, Bobbing " 34 160 + + Floor Over Floor: Crumbling (Respawn) 36 170 + Floor Over Floor: Crumbling (No Respawn) 35 171 + "Floor Over Floor: Crumbling (Respawn), Platform " 79 172 + "Floor Over Floor: Crumbling (No Respawn), Platform " 80 173 + "Floor Over Floor: Crumbling (Respawn), Platform, Translucent " 82 174 + "Floor Over Floor: Crumbling (No Respawn), Platform, Translucent " 83 175 + "Floor Over Floor: Crumbling (Respawn), Floating, Bobbing " 39 176 + "Floor Over Floor: Crumbling (No Respawn), Floating, Bobbing " 1 177 + "Floor Over Floor: Crumbling (Respawn), Floating " 37 178 + "Floor Over Floor: Crumbling (No Respawn), Floating " 42 179 + "Floor Over Floor: Crumbling (Respawn), Bobbing (Air) " 40 180 + + "Floor Over Floor: Rising Platform, Solid, Opaque, Shadowcasting " 89 190 + "Floor Over Floor: Rising Platform, Solid, Opaque, Non-Shadowcasting " 90 191 + "Floor Over Floor: Rising Platform, Solid, Translucent " 91 192 + "Floor Over Floor: Rising Platform, Solid, Invisible " 94 193 + "Floor Over Floor: Rising Platform, Platform, Opaque " 92 194 + "Floor Over Floor: Rising Platform, Platform, Translucent " 93 195 + + Floor Over Floor: Light Block 49 200 + Floor Over Floor: Half Light Block 47 201 + Floor Over Floor: Fog Block 46 202 + + "Floor Over Floor: Intangible, Opaque " 62 220 + "Floor Over Floor: Intangible, Translucent " 52 221 + "Floor Over Floor: Intangible, Sides Only " 67 222 + "Floor Over Floor: Intangible, Invisible " 58 223 + + Floor Over Floor: Mario Block 41 250 + Floor Over Floor: Thwomp Block 54 251 + Floor Over Floor: Shatter Block 76 252 + "Floor Over Floor: Shatter Block, Translucent " 86 253 + Floor Over Floor: Bustable Block 55 254 + Floor Over Floor: Spin Bust Block 78 255 + "Floor Over Floor: Spin Bust Block, Translucent " 84 256 + Floor Over Floor: Quicksand Block 56 257 + Floor Over Floor: Laser Block 53 258 + Floor Over Floor: Custom 87 259 + + Linedef Executor Triggers: + Trigger Linedef Executor (Continuous) 96 300 + Trigger Linedef Executor (Each Time) 97 301 + Trigger Linedef Executor (Once) 98 302 + Trigger Linedef Executor (Ring Count - Continuous) 95 303 + Trigger Linedef Executor (Ring Count - Once) 99 304 + Trigger Linedef Executor (Character Ability - Continuous) 19 305 + Trigger Linedef Executor (Character Ability - Each Time) 20 306 + Trigger Linedef Executor (Character Ability - Once) 21 307 + "Trigger Linedef Executor (Race Only, Once) " 9 308 + Trigger Linedef Executor (CTF Red Team - Continuous) 10 309 + Trigger Linedef Executor (CTF Red Team - Each Time) 11 310 + Trigger Linedef Executor (CTF Blue Team - Continuous) 12 311 + Trigger Linedef Executor (CTF Blue Team - Each Time) 13 312 + Trigger Linedef Executor (No More Enemies - Once) 15 313 + Trigger Linedef Executor (# of Pushables - Continuous) New 314 + Trigger Linedef Executor (# of Pushables - Once) New 315 + Trigger Linedef Executors (PolyObject - Land On) New 316 + Trigger Linedef Executor (Level Load) New 399 + + Linedef Executor Options: + Linedef Executor: Set Tagged Sector's Floor Height/Pic 101 400 + Linedef Executor: Set Tagged Sector's Ceiling Height/Pic 102 401 + Linedef Executor: Set Tagged Sector's Light Level 103 402 + Linedef Executor: Move Tagged Sector's Floor 106 403 + Linedef Executor: Move Tagged Sector's Ceiling 107 404 + Linedef Executor: Lower Floor by Line 108 405 + Linedef Executor: Raise Floor by Line 109 406 + Linedef Executor: Lower Ceiling by Line 110 407 + Linedef Executor: Raise Ceiling by Line 111 408 + Linedef Executor: Change Calling Sector's Tag 112 409 + Linedef Executor: Change Front Sector's Tag 114 410 + Linedef Executor: Stop Plane Movement 116 411 + Linedef Executor: Teleport Player to Tagged Sector 104 412 + Linedef Executor: Change Music 105 413 + Linedef Executor: Play SFX 115 414 + Linedef Executor: Run Script 113 415 + Linedef Executor: Start Adjustable Fire Flicker 119 416 + Linedef Executor: Start Adjustable Glowing Light 120 417 + Linedef Executor: Start Adjustable Strobe Flash (unsynchronized) New 418 + Linedef Executor: Start Adjustable Strobe Flash (synchronized) New 419 + Linedef Executor: Fade Light Level 117 420 + Linedef Executor: Stop Lighting Effect 118 421 + Linedef Executor: Cut-Away View 121 422 + Linedef Executor: Change Sky 123 423 + Linedef Executor: Change Weather 124 424 + Linedef Executor: Change Object State 125 425 + Linedef Executor: Stop Object 122 426 + Linedef Executor: Award Score 126 427 + Linedef Executor: Start Platform Movement 127 428 + Linedef Executor: Crush Ceiling Once New 429 + Linedef Executor: Crush Floor Once New 430 + Linedef Executor: Crush Floor & Ceiling Once New 431 + Linedef Executor: Enable 2D Mode New 432 + Linedef Executor: Disable 2D Mode New 433 + Linedef Executor: Award Custom Power New 434 + Linedef Executor: Stop Conveyor New 435 + Linedef Executor: Start Conveyor New 436 + Linedef Executor: Disable Player Movement New 437 + + Linedef Executor: Execute Linedef Executor New 450 + + Linedef Executor: PolyObject: Door Slide New 480 + Linedef Executor: PolyObject: Door Swing New 481 + Linedef Executor: PolyObject: Move XY New 482 + Linedef Executor: PolyObject: Move XY w/ override New 483 + Linedef Executor: PolyObject: Rotate Right New 484 + Linedef Executor: PolyObject: Rotate Right w/ override New 485 + Linedef Executor: PolyObject: Rotate Left New 486 + Linedef Executor: PolyObject: Rotate Left w/ override New 487 + Linedef Executor: PolyObject: Start waypoint movement New 488 + Linedef Executor: PolyObject: Make Invisible New 489 + Linedef Executor: PolyObject: Make Visible New 490 + + Scrollers/Pushers: + Scroll Wall First Side Left 100 500 + Scroll Wall First Side Opposite Direction 85 501 + Scroll Wall According to Linedef 254 502 + Acc Scroll Wall According to Linedef 218 503 + Disp Scroll Wall According to Linedef 249 504 + Scroll Texture by Offsets 255 505 + + Scroll Floor Texture 251 510 + Acc Scroll Floor Texture 215 511 + Disp Scroll Floor Texture 246 512 + Scroll Ceiling Texture 250 513 + Acc Scroll Ceiling Texture 214 514 + Disp Scroll Ceiling Texture 245 515 + + Carry Objects on Floor (no scroll) 252 520 + Acc Carry Objects on Floor 216 521 + Disp Carry Objects on Floor 247 522 + Carry Objects on Ceiling 203 523 + Acc Carry Objects on Ceiling 205 524 + Disp Carry Objects on Ceiling 201 525 + + Scroll Floor Texture and Carry Objects 253 530 + Acc Scroll Floor Texture and Carry Objects 217 531 + Disp Scroll Floor Texture and Carry Objects 248 532 + Scroll Ceiling Texture and Carry Objects 202 533 + Acc Scroll Ceiling Texture and Carry Objects 204 534 + Disp Scroll Ceiling Texture and Carry Objects 200 535 + + Friction 223 540 + Horizontal Wind 224 541 + Upwards Wind 229 542 + Downwards Wind 230 543 + Horizontal Current 225 544 + Upwards Current 227 545 + Downwards Current 228 546 + Boom Push/Pull Thing 226 547 + + Lighting: + Floor Lighting 213 600 + Ceiling Lighting 5 601 + Adjustable Pulsating Light 60 602 + Adjustable Flickering Light 61 603 + Adjustable Blinking Light (unsynchronized) New 604 + Adjustable Blinking Light (synchronized) New 605 + Colormap 16 606 diff --git a/doc/SSN-Todo.xls b/doc/SSN-Todo.xls new file mode 100644 index 000000000..c468b3476 Binary files /dev/null and b/doc/SSN-Todo.xls differ diff --git a/doc/Sector Ranges.txt b/doc/Sector Ranges.txt new file mode 100644 index 000000000..42760e133 --- /dev/null +++ b/doc/Sector Ranges.txt @@ -0,0 +1,78 @@ +Removed: + - Buttons 1-20 690-709 + - Button 21 (THZ2 A/740 B/741 D/742 E/745 710 + - Close Door Blazing (Tag 743) 711 + - Raise Ceiling to Highest (Tag 744) 981 + - THZ2 Slime Raise (B/712 W713 P714 D715 S716) 986 + +Stuff to Remove/Change: + - Light Blinks On Every 0.5 Seconds 2 Add Linedef Combine + - Light Blinks On Every 1 Second 3 Add Linedef Combine + - Light Pulses Smoothly 8 Remove + - Light Blinks On Every 0.5 Seconds (Sync) 12 Add Linedef Combine + - Lights Blinks On Every 1 Second (Sync) 13 Add Linedef Combine + - Light Flickers Like Fire 17 Remove + ? - Damage (Fire) and Current 519 Remove (convert to combination) + ? - Damage (Water) and Current 984 Remove (convert to combination) + +Section 1: + 1 - Damage (Generic) 11 + 2 - Damage (Water) 983 + 3 - Damage (Fire) 7 + 4 - Damage (Electrical) 18 + 5 - Spikes 4 + 6 - Death Pit (Camera Mod) 16 + 7 - Death Pit (No Camera Mod) 5 + 8 - Instant Kill 10 + 9 - Ring Drainer (Floor Touch) 978 + 10 - Ring Drainer (No Floor Touch) 980 + 11 - Special Stage Damage 9 + 12 - Space Countdown 6 + 13 - Ramp Sector (Increase step-up) 992 + 14 - Non-Ramp Sector (Don't step-down) 996 + 15 - Bouncy Sector (FOF Control Only) 14 + +Section 2: << 4 + 1 - Trigger Linedef Exec (Pushable Objects) 971 + 2 - Trigger LD Exec (Anywhere in Sec/All Pls) 972 + 3 - Trigger Linedef Exec (Floor Touch/All Pls) 973 + 4 - Trigger Linedef Exec (Anywhere in Sec) 974 + 5 - Trigger Linedef Exec (Floor Touch) 975 + 6 - Trigger Linedef Exec (Emerald Check) 967 + 7 - Trigger Linedef Exec (NiGHTS Mare) 968 + 8 - Check for linedef executor on FOFs (ANY) 970 + 9 - Egg Trap Capsule 666 + 10 - Special Stage Time/Rings, Par 990 + 11 - Custom Global Gravity 991 + +Section 3: << 8 + 1 - Ice/Sludge (required?!) 256 + 2 - Wind/Current (required?!) 512 + 3 - Ice/Sludge and Wind/Current 768 + 4 - Conveyor Belt 985 + 5 - Speed Pad (No Spin) 976 + 6 - Speed Pad (Spin) 977 + 7 - Bustable Block Sprite Parameter 1500-1515 + 8 - " + 9 - " + 10 - " + 11 - " + 12 - " + 13 - " + 14 - " + 15 - " + +Section 4: << 12 + 1 - Starpost Activator 993 + 2 - Special Stage Goal Combine 33 + 2 - Exit Sector Combine 982 + 2 - No Tag Zone Combine 987 + 2 - CTF: Flag Return Combine 995 + 3 - CTF: Red Team Base 988 + 4 - CTF: Blue Team Base 989 + 5 - Fan Sector 997 + 6 - Super Sonic Transform 969 + 7 - Spinner 979 + 8 - Zoom Tube Start 998 + 9 - Zoom Tube End 999 + 10 - Finish Line 994 \ No newline at end of file diff --git a/doc/copying b/doc/copying new file mode 100644 index 000000000..a43ea2126 --- /dev/null +++ b/doc/copying @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 675 Mass Ave, Cambridge, MA 02139, USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + Appendix: How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) 19yy + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) 19yy name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/doc/faq.txt b/doc/faq.txt new file mode 100644 index 000000000..26c75bbad --- /dev/null +++ b/doc/faq.txt @@ -0,0 +1,307 @@ + SRB2 + Release v1.09, ? 2005. + + Last Updated: June 2005 + + Original game & sources by: Id Software. + Additions: (c)1998 by: Fabrice Denis & Boris Pereira + (c)1999 by: Fabrice Denis, Boris Pereira & Thierry Van Elsuwe + (c)2000 by: Boris Pereira & Thierry Van Elsuwe + (c)2004 By: AJ, Graue, Alam Arias, Logan Arias & Andrew Clunis + + Special thanks to Steven McGranahan, Lee Killough, Robert Bäuml and Bell Kin for + their large contribution and to other DooM LEGACY & SRB2 Team members. + + Web site: http://www.SRB2.org/ + e-mail: none@none.com + + OpenGL specific: + Web site: http://legacy.newdoom.com/gl + + + ----------------------------------------------------------------------- + F.A.Q. + ----------------------------------------------------------------------- + + + If you have any trouble with SRB2, you might find a solution + here. + + If you find a solution to a problem that was not listed here, + please tell us so that we can update the FAQ and help other people! + + Mail your hardware/software problems to: + + None@none.com subject: FAQ + + + -------- + CONTENTS + -------- + + [0] Miscellaneous + [1] Mouse/Joystick/Keyboard + [2] Video + [3] Sound + [4] Network + [5] Troubleshooting + + + ----------------- + [0] MISCELLANEOUS + ----------------- + + * under win95 or OS/2, I don't have enough memory. How can i handle with ? + + Tell win95 to put more dpmi memory for your dos box. + Or use the -mb option. + + + + --------------------------- + [1] MOUSE/JOYSTICK/KEYBOARD + --------------------------- + + * My mouse/joystick does not work in SRB2. + + First, check that the mouse/joystick is activated : go at the + console and type either 'use_mouse' (or use the respective + menuitem) or 'use_joystick'. + + If it tells '0' or off than the mouse/joystick is not used, + set the variable to 1. eg: 'use_mouse 1'. + + For the joystick, different values will support different + types of joystick, check the console documentation for the + command 'use_joystick' for more. + + Even if the mouse or joystick is activated, you have to + set up the contols into the Setup Controls menu. That is: + tell what use you will make of the mouse/joystick buttons. + + + --------- + [2] VIDEO + --------- + + + * Where are the other video modes ? I have only '320x200' in the + Video Modes menu. + + DOS + --- + + SRB2 adds new video modes only if a VESA2 (or better) driver + is present. The VESA2 driver is a standard of 'talking' between a + program and the huge amount of different graphics cards + available today. + + If you don't have a VESA2 driver, you can download UNIVBE, or + SMART DISPLAY DOCTOR from + + http://www.scitechsoft.com/products/ent/free_titles.html + + or if you have an S3 based card, you can download the free + software called 'S3VBE'. + + ftp://ftp.externet.hu/pub/mirror/sac/graph/s3vbe318.zip + ftp://ftp.digsys.bg/pub/simtelnet/msdos/graphics/s3vbe318.zip + http://www.filesearching.com/cgi-bin/s?q=s3vbe318.zip + http://www.google.com/search?q=s3vbe318.zip + + * The game doesn't restore the video mode I have chosen the last time + I played SRB2. + + The current video mode has to be made the 'default' so that it is + saved to the config : press the key 'D' on the Video Options menu + to set the current video mode the default. + + * I have some problems with OpenGL mode + + Have a look at the FAQ for OpenGL on the glLegacy web site: + + http://www.doomnation.com/gllegacy/faqe.htm + + # Linux: I only have a 1024x768 (or 800x600, 1280x1024, ...) resolution + in fullscreen mode under X and SRB2 is really really slow. Can I + have lower resolutions like 320x200 in fullscreen mode as well? + + Probably yes. SRB2 can only use the resolutions offered by the + X-Server. So if all fullscreen modes have a very high resolution you + have to modify /etc/XF86Config (or /etc/X11/XF86Config). Use XF86Setup + (or the appropriate tool coming with your distribution - sax, + xf86config, ...) to do this. + If you do not succeed there, you can enter them manually into your + XF86Config file. ONLY RECOMMENDED FOR USERS WHO KNOW WHAT THEY DO! + For a short guide on how to do this, have a look at the file + "Doublescan.txt". + In case of doubt consult the XFree86-HOWTO (or ask your system + administrator :). + + # Linux: I cannot have any fullscreen modes at all! + + You have only modes above 1024x768 in your XF86Config. Proceed as + described above. + + # Linux: After a certain idle time my screensaver jams the display of + SRB2. I can still operate SRB2, but I do not see what's happening + and the screensaver won't go away. + + You probably have KDE. The KDE screensaver does not obey the screensaver + rules (at least mine, version 1.1). The solution is to deactivate the + KDE screensaver and use another screensaver (like the xscreensaver, + e.g.). But the hell, when you started SRB2 you should have played it + as well and not left it alone!!! + + --------- + [3] SOUND + --------- + + + DOS:I can't have CD audio music, why ? + + Make sure that the MSCDEX driver version 2.0 or later is loaded. + If it says 'MSCDEX version xxx' at game startup, and you still + don't hear the cd music, then probably your card doesn't respond + when SRB2 tries to set the cd volume. If so, make sure your sound + card's mixer have the cd volume set up so that you can hear something. + + + When the CD plays, the game is very 'jerky'. It doesn't do that when + I type 'cd off' in the console. + + You have an old/bad cd driver, that can take up to a second to + respond to cd driver commands. Either get the latest version of + your driver, or turn cd update off. Check 'cd_udpate' in the + console documentation for more. + + * DOS:How can I *ALWAYS* disable the sounds or music of the game ? + + Edit the allegro.cfg file and set digicard/midicard to 0 (none) + + * DOS:My sterero sound is reversed, how can I set it the right way ? + + Change the console variable 'stereoreverse' to either 1 or 0. + Or, you can edit the allegro.cfg file, and set the 'flip_pan' variable. + + + * DOS:The sounds are too 'slow', or 'low-pitched' + + It seems to be a problem of the auto-detection of some 8bit sound + cards. You will have to set manually the 'sb_freq' value in the + allegro.cfg file to a lower value : 11906, 16129. + + * DOS:SRB2 doesn't play any sound/music, but I have a sound + blaster genuine/compatible card. + + If you have a genuine or compatible SoundBlaster card, it is very + important that you set the BLASTER environment variable. + + If you are playing under DOS, and never installed your sound card + under DOS, run the setup of your sound card for DOS. + + Check if the BLASTER variable was set: type 'SET' under dos + (or DOSbox) + + Do you see something like 'BLASTER=A220 I5 D1 ...' ? + + Yes? If you don't hear sounds/music, then tweak the settings in the + allegro.cfg file until you get something, first try changing the + type of the sound card, it is not always properly detected. + + No? You have to set this variable in order that your sound card is + detected. Run the setup that was shipped with your sound card, and + make sure you run the setup for DOS too, it will usually add a + line of the type 'SET BLASTER=... ...' in the autoexec.bat file. + + + * DOS:How can I have better midi music on my 8bit sound card ? + + Use the DIGMID driver, it is supported in SRB2. + + What the hell is this? Well, the Gravis Ultrasound uses digital + samples to play midi music. On a simple 8bit card, you can use digital + samples too, which will sound usually better than what is output + by the poor fm synthesis chip of 8bit cards. + + You will need to get a Gravis Ultrasound patch set, you can find + several ones for free on internet, it consists of a bunch of '.pat' + files which are the digital samples to play the midi instruments + (eg: piano, conga, guitar, ect.). + + Check the Allegro homepage for some links to GUS patches: + http://alleg.sourceforge.net/digmid.html + http://alleg.sourceforge.net/ + http://www.talula.demon.co.uk/allegro/digmid.html + http://www.talula.demon.co.uk/allegro/ + + Now to activate the DIGMID driver: + + Set the 'midi_card' value to 8 (DIGMID) in the allegro.cfg file. + Make sure you leave the 'digi_voices' blank, or set it to a low + value, because the midi music will use digital voices. + At the end of the allegro.cfg file, set the 'patches' value + to the path, where you have installed a Gravis Ultrasound midi + patch set. eg: patches = d:\music\midipat\ + + # Linux: CD music does not work or only works when run as root. + + We do not encourage you to run SRB2 as root (you never know + what SRB2 can do to your system - it's a mighty piece of code :). + There is a common problem with ATAPI CD-rom drives, which are + treated as harddisks. Usually there is a link /dev/cdrom pointing to + device hd[b,c,d]. As harddisks are not supposed to be read directly + via this device (especially not by a common user), there are no read + permissions for "all". For CD-roms you can savely set read permissions + unless you are very paranoid. Assuming your CD-rom drive is /dev/hdc, + set permissions with "chmod +r /dev/hdc" (as root). SCSI CD-rom drives + should not have this problem. But if they do, proceed as described + with ATAPI drives. + + # Linux: The CD music volume is not set properly. + + Go to the console and type "jigglecdvolume 1". + + ----------- + [4] NETWORK + ----------- + + * Where can I find Internet servers ? + + For the moment there is one public server. + http://srb2.servegame.org/ Master server web page + srb2.servegame.org:28910 current Master Server + + * When I start SRB2 with -server or -connect it say : + "BinToPort: Address already in use (EADDRINUSE)" + + It appears only when SRB2 crashes or when you leave with ctrl-break. + use -udpport 12345 (or any other free slot) on both sides (client and + server). + + This can also happens when there is already a SRB2 running on your + computer if you whant to try two SRB2 running on the same computer + use -clientport 12345 (or any other free slot). Then the second will + connect to the first one. + + * Do you use the tcp protocol ? + + No, we use the udp protocol which is faster, but don't worry udp is a + part of the internet protocol. + + + ------------------- + [5] Troubleshooting + ------------------- + + # Linux: SRB2 is hung in fullscreen mode and won´t let me leave. + What shall I do? + + Some people press the reset button, but hey, we are not in the + stoneage of operating systems! There are two "proper" ways to + get out: kill your X-Server. You can usually do this by pressing + "CTRL-ALT-BACKSPACE". But if you have other open applications with + important data (probably hacked away on your diploma thesis for 3 + weeks without saving once) you can also kill SRB2 directly. Press + "CTRL-ALT-F2" and you will get to a console. Log in, type + "killall llxSRB2" and switch back to the X-Server with "CTRL-ALT-F7". + Some X-Server crash on this procedure - blame the X-Server for the + loss of 3 weeks work on your diploma thesis :) diff --git a/doc/manual/1up.png b/doc/manual/1up.png new file mode 100644 index 000000000..d8617cb8b Binary files /dev/null and b/doc/manual/1up.png differ diff --git a/doc/manual/RNGA0000.png b/doc/manual/RNGA0000.png new file mode 100644 index 000000000..78f98625c Binary files /dev/null and b/doc/manual/RNGA0000.png differ diff --git a/doc/manual/RNGB0000.png b/doc/manual/RNGB0000.png new file mode 100644 index 000000000..71a9c51be Binary files /dev/null and b/doc/manual/RNGB0000.png differ diff --git a/doc/manual/RNGE0000.png b/doc/manual/RNGE0000.png new file mode 100644 index 000000000..960b9c3ba Binary files /dev/null and b/doc/manual/RNGE0000.png differ diff --git a/doc/manual/RNGG0000.png b/doc/manual/RNGG0000.png new file mode 100644 index 000000000..38c552fca Binary files /dev/null and b/doc/manual/RNGG0000.png differ diff --git a/doc/manual/RNGR0000.png b/doc/manual/RNGR0000.png new file mode 100644 index 000000000..ad9c5c073 Binary files /dev/null and b/doc/manual/RNGR0000.png differ diff --git a/doc/manual/RNGS0000.png b/doc/manual/RNGS0000.png new file mode 100644 index 000000000..bbcb6636a Binary files /dev/null and b/doc/manual/RNGS0000.png differ diff --git a/doc/manual/Ring0000.png b/doc/manual/Ring0000.png new file mode 100644 index 000000000..730f6f590 Binary files /dev/null and b/doc/manual/Ring0000.png differ diff --git a/doc/manual/acz.png b/doc/manual/acz.png new file mode 100644 index 000000000..f8d98a653 Binary files /dev/null and b/doc/manual/acz.png differ diff --git a/doc/manual/airspin.png b/doc/manual/airspin.png new file mode 100644 index 000000000..943ee546a Binary files /dev/null and b/doc/manual/airspin.png differ diff --git a/doc/manual/attack.png b/doc/manual/attack.png new file mode 100644 index 000000000..3f3e48fdd Binary files /dev/null and b/doc/manual/attack.png differ diff --git a/doc/manual/blue_monitor.png b/doc/manual/blue_monitor.png new file mode 100644 index 000000000..f6d01f802 Binary files /dev/null and b/doc/manual/blue_monitor.png differ diff --git a/doc/manual/blue_ring.png b/doc/manual/blue_ring.png new file mode 100644 index 000000000..8ffd4b38d Binary files /dev/null and b/doc/manual/blue_ring.png differ diff --git a/doc/manual/bshield.png b/doc/manual/bshield.png new file mode 100644 index 000000000..01f16a3af Binary files /dev/null and b/doc/manual/bshield.png differ diff --git a/doc/manual/cez.png b/doc/manual/cez.png new file mode 100644 index 000000000..34848023d Binary files /dev/null and b/doc/manual/cez.png differ diff --git a/doc/manual/controls.png b/doc/manual/controls.png new file mode 100644 index 000000000..8422625a1 Binary files /dev/null and b/doc/manual/controls.png differ diff --git a/doc/manual/conveyor.png b/doc/manual/conveyor.png new file mode 100644 index 000000000..871549aa9 Binary files /dev/null and b/doc/manual/conveyor.png differ diff --git a/doc/manual/coop.png b/doc/manual/coop.png new file mode 100644 index 000000000..b1ed48b05 Binary files /dev/null and b/doc/manual/coop.png differ diff --git a/doc/manual/crusher.png b/doc/manual/crusher.png new file mode 100644 index 000000000..42859e61d Binary files /dev/null and b/doc/manual/crusher.png differ diff --git a/doc/manual/ctf.png b/doc/manual/ctf.png new file mode 100644 index 000000000..24712f653 Binary files /dev/null and b/doc/manual/ctf.png differ diff --git a/doc/manual/dsz.png b/doc/manual/dsz.png new file mode 100644 index 000000000..cc062bf8e Binary files /dev/null and b/doc/manual/dsz.png differ diff --git a/doc/manual/eggbox.png b/doc/manual/eggbox.png new file mode 100644 index 000000000..a45ead1bf Binary files /dev/null and b/doc/manual/eggbox.png differ diff --git a/doc/manual/eggman.png b/doc/manual/eggman.png new file mode 100644 index 000000000..3ee0a0d20 Binary files /dev/null and b/doc/manual/eggman.png differ diff --git a/doc/manual/emblem.png b/doc/manual/emblem.png new file mode 100644 index 000000000..0aa63b651 Binary files /dev/null and b/doc/manual/emblem.png differ diff --git a/doc/manual/fan.png b/doc/manual/fan.png new file mode 100644 index 000000000..74e4a17d0 Binary files /dev/null and b/doc/manual/fan.png differ diff --git a/doc/manual/gfz.png b/doc/manual/gfz.png new file mode 100644 index 000000000..6530f1a99 Binary files /dev/null and b/doc/manual/gfz.png differ diff --git a/doc/manual/gshield.png b/doc/manual/gshield.png new file mode 100644 index 000000000..225f1a76d Binary files /dev/null and b/doc/manual/gshield.png differ diff --git a/doc/manual/invc.png b/doc/manual/invc.png new file mode 100644 index 000000000..f0e7a6340 Binary files /dev/null and b/doc/manual/invc.png differ diff --git a/doc/manual/knuckles.png b/doc/manual/knuckles.png new file mode 100644 index 000000000..4fef38b59 Binary files /dev/null and b/doc/manual/knuckles.png differ diff --git a/doc/manual/koneup.png b/doc/manual/koneup.png new file mode 100644 index 000000000..cda5b1b84 Binary files /dev/null and b/doc/manual/koneup.png differ diff --git a/doc/manual/manual.htm b/doc/manual/manual.htm new file mode 100644 index 000000000..57e9bb0c9 --- /dev/null +++ b/doc/manual/manual.htm @@ -0,0 +1,2393 @@ + + + + + Sonic Robo Blast 2 Manual + + + + + +

+ title.png (43991 bytes) +

+

+ Manual +

+

+ Design and content on SRB2 is copyright 1998-2009 by Sonic Team Junior. + All non-original material in this game is copyrighted by their respective + owners, and no copyright infringement is intended. This game's staff make + no profit whatsoever (in fact, we lose money). THIS GAME + SHOULD NOT BE SOLD FOR ANY COST WHATSOEVER! Sonic Team + Junior is in no way affiliated with Sega or Sonic Team. +

+
+ +
+

+ thanks.png (8396 bytes)Thank you for installing SRB2! This fan + created tribute game to one of the greatest video game series has + been over 11 years in the making. Before you begin play, please note the + system requirements below to make sure you have an enjoyable experience. +

+

+ + System Requirements +

+

+ Minimum Spec (320x200): +

+
    +
  • Intel Pentium II 400mhz or better* +
  • +
  • 64mb RAM +
  • +
  • 200mb free disk space (2mb free during play) +
  • +
  • DirectX 3 or better compliant video +
  • +
  • DirectX 3 compliant sound +
  • +
+

+ Recommended Spec (640x400): +

+
    +
  • Intel or AMD 700mhz or better* +
  • +
  • 64mb RAM +
  • +
  • 200mb free disk space (2mb free during play) +
  • +
  • DirectX 3 or better compliant video +
  • +
  • DirectSound compatible sound card +
  • +
+

+ SRB2 will run on lesser machines, but is generally not recommended. +

+

+

+
+

+ + Items +

+

+ There are many items you will encounter throughout the game that Sonic + and his friends can use to their advantage. Below is a short summary of + the most common ones you will find. +

+

+

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

+ Ring0000.png (1178 bytes) +

+
+ Ring +

+ The main lifeline for Sonic & Co. Your collection of rings + will scatter when hit, but as long as you have one, you cannot be + killed (except from a pit or crusher). +

+
+ ring.png (1109 bytes) + + 10 Ring Box +

+ Adds 10 rings to your cache +

+
+ wshield.png (1114 bytes) + + Whirlwind Shield +

+ Protects you from one hit. Press the spin button while jumping to + perform a second jump. Beware, though, as the second jump stops + you from spinning. +

+
+ yshield.png (1112 bytes) + + Attraction Shield +

+ Protects you from one hit. This will attract nearby rings. Don't + go too deep in the water, or you'll short it out! +

+
+ bshield.png (1113 bytes) + + Force Shield +

+ Protects you from two hits. It has a reflect ability that is automatically + activated when it gets hit. +

+
+ gshield.png (1113 bytes) + + Elemental Shield +

+ Protects you from one hit. This protects you from the elements, keeps + you from drowning, and creates a flaming trail when you spindash that + will damage your enemies! +

+
+ rshield.png (1110 bytes) + + Armaggeddon Shield +

+ Protects you from one hit. When you get hit, the shield will + explode, wiping out all enemies within its blast radius, + destroying the shield. The explosion can be triggered by pressing + the spin button while jumping as well. +

+
+ invc.png (1112 bytes) + + Invincibility +

+ Makes you invincible for 20 seconds. +

+
+ shoes.png (1118 bytes) + + Super Sneakers +

+ Increases your speed for 20 seconds. +

+
+ soneup.png (1118 bytes)
+ soneup.png (1118 bytes)
+ soneup.png (1118 bytes) +
+ One-Up +

+ Gives you an extra life. In match and CTF, it gives you 100 rings. +

+
+ mixup.png (1162 bytes) + + Teleporter Scramble +

+ In multiplayer, this will scramble the positions of all players + in the game. +

+
+ recycler.png (1230 bytes) + + Recycler +

+ In multiplayer, this will scramble all of the players' powerups. + This includes ammo, powerups, and weapons. +

+
+ eggbox.png (1157 bytes) + + Eggman +

+ Harms your player. Watch out! +

+
+ random.png (1105 bytes) + + Random Item +

+ What's in the box? Only way to find out is to open it! +

+
+ token.png (1122 bytes) + +

+ Warp Token +

+

+ At the end of the act, you will be taken to a special stage, + giving you the chance to snatch one of the Chaos Emeralds back + from Dr. Eggman's grasp! There are at least one of these in each + act. +

+
+ emblem.png (1368 bytes) + + Emblem +

+ These are hidden in every act, except ones where you have to + confront Eggman. Different ones appear depending on which + character you play as. Getting enough of these will unlock + special bonuses! You may obtain more by meeting special criteria, + such as completing the game with all of the chaos emeralds. When + you've picked up these emblems, they will disappear. If you find + them again in a new game, they will be faded, indicating that you + have already obtained that emblem. Check the statistics to see + which emblems are missing from your collection. +

+
+

+ In CTF, there are team based rings and monitors. +

+

+ red_ring.png (1219 bytes) + red_monitor.png (1199 bytes) + blue_ring.png (1218 bytes) + blue_monitor.png (1160 bytes) +

+
+
+
+

+ +

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

+ Special Multiplayer Items +

+

+ In certain multiplayer games, you can use the following match weapons + to change the kind of rings you throw. Make sure you grab the weapon, + the ammo, and have rings or else it won't fire. +

+
+

+ red_ring.png (1219 bytes) +

+
+

+ Red Ring (Default Weapon) +

+

+ This is your default weapon. It can't be dropped and it uses normal rings + for ammo. +

+
+

+ wpnpanel_auto.png (1399 bytes) + RNGA0000.png (1100 bytes) +

+
+

+ Automatic +

+

+ Hold down the THROW key for a constant stream of rings. +

+
+

+ wpnpanel_bounce.png (1533 bytes) + RNGB0000.png (1275 bytes) +

+
+

+ Bounce +

+

+ When fired, the bounce ring acts like a normal red ring, except that + it will bounce off walls, ceilings, and floors for a bit before disappearing. + Great for firing around corners and in small rooms. +

+
+

+ wpnpanel_explosion.png (1359 bytes) + RNGE0000.png (1326 bytes) +

+
+

+ Explosion +

+

+ When this ring hits a wall, it scatters rings everywhere in a + fireworks-like display. Players hit directly by the black ring + get knocked back farther than normal. +

+
+

+ wpnpanel_grenade.png (1455 bytes) + RNGG0000.png (1227 bytes) +

+
+

+ Grenade +

+

+ Fires a grenade that explodes by proximity. Great for guarding CTF + bases and for chucking in places where you expect the opponent will run. +

+
+

+ wpnpanel_rail.png (1489 bytes) + RNGR0000.png (1163 bytes) +

+
+

+ Rail +

+

+ Snipe at your enemies with this instant-hit weapon! Players hit + with this weapon get knocked back farther than normal. +

+
+

+ wpnpanel_scatter.png (1370 bytes) + RNGS0000.png (1127 bytes) +

+
+

+ Scatter +

+

+ Fires 5 rings that spread out as they go farther. The distance the + opponent flies when hit varies depending on how far the shot traveled + in the air. At point-blank range, scatter will send the opponent + flying across the stage, leaving their items easily taken. +

+
+

+ WARNING! +

+

+ metal.png (5951 bytes) +

+

+ If you are hit while carrying any of these special rings, they + will be dropped. Pick them up quickly to keep your opponents from + stealing them! +

+
+
+
+
+

+ + Special Moves +

+

+ Sonic and his friends each have abilities unique to themselves. Below is + a summary of each character's special moves. +

+

+

+
+ + + + + + + + + + +
+

+ Sonic +

+
+

+ airspin.png (4279 bytes) +

+
+ Air Spin Attack +

+ While jumping, press the jump button again to hurl Sonic forward + in a burst of speed. +

+
+
+
+
+ + + + + + + + + + + + + +
+

+ Tails +

+
+

+ tailsfly.png (18615 bytes) +

+
+ Fly +

+ While jumping, press the jump button repeatedly to fly for a + short time. If you are playing with a friend, fly over them to + pick them up for a ride! +

+
+ Swim +

+ While underwater, press the jump button repeatedly to swim for a + short time. Just like flying, you can pick up others to give them + a lift. +

+
+
+
+
+ + + + + + + + + + + + + +
+

+ Knuckles +

+
+

+ knuckles.png (16482 bytes) +

+
+ Glide +

+ While jumping, press and hold the jump button again to glide. Use + the directional keys to steer. +

+
+ Climb +

+ If you collide with a wall while gliding, Knuckles will latch + onto it. Use the directional keys to move along the wall. Press + the jump button to release and turn around, or press the spin + button to release while still facing the wall. +

+
+
+
+
+

+ + Basic Gameplay +

+
+ + + + + + + + + + + + + + + + + + + + + + + +
+

    Your main objective is to stop Eggman's plans for world + domination. The game is set over eight zones ranging from green + fields and ancient sunken cities to raging volcanoes and the Egg + Rock itself. Each zone is split up into three acts, the third one + being a battle against Dr. Eggman in one of his powerful machines.

+
+

+ eggman.png (12925 bytes) +

+
+

+ attack.png (3880 bytes) +

+
+

    When you encounter enemies, to defeat them, simply use your + spin attack by jumping. Enemies can also be destroyed by spinning + through them along the ground. Knuckles can even glide through his + enemies.

+
+

    However, beware! You are not invulnerable and, unless you have + at least one ring, an enemy will kill you on contact, or if you are + hit by one of their attacks. If you get hit by an enemy while you + have rings, you will survive, but your rings will be dropped and + scattered. You can pick them back up again, but only if you are + quick; rings will dissapear after a few seconds have elapsed! You + can find out how many rings you have in the top-left hand part of + the screen.

+
+

+ stats_rings.png (19450 bytes) +

+
+

+ wshield.png (1114 bytes) + yshield.png (1112 bytes) + bshield.png (1113 bytes) + gshield.png (1113 bytes) + rshield.png (1110 bytes) +

+
+

    You can also obtain shields, which will dissapate to protect + you if you are hit by a robot or an attack. Some shields have + additional powers, which were described above, along with other + power-ups you can obtain.

+
+

    Getting killed by a robot or by other hazards (described below) + will result in the loss of one life - keep an eye on your lives in + the bottom left hand side of the screen - losing all of your lives + will end your game (unless you have a continue)!

+
+

+ stats_lives.png (19359 bytes) +

+
+
+
+
+

+ + Surroundings +

+

+ The following is a description of several objects or environments you + will encounter. +

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

+ spring1.png (941 bytes) + spring2.png (941 bytes) + spring3.png (1071 bytes) + spring4.png (1046 bytes) +

+

+ spring5.png (1107 bytes) + spring6.png (1138 bytes) + spring7.png (940 bytes) + spring8.png (940 bytes) +

+
+

+ Springs +

+

+ These springs will bounce you in the direction they are pointing. + There are two varieties, yellow and red. The red spring is much + stronger than the yellow spring. Beware though, as some springs + may throw you headlong into trouble! +

+
+

+ platform.png (47948 bytes) +

+
+

+ Floating Platforms +

+

+ These platforms may move up and down, allowing you to hitch a + ride. Careful timing may be needed to leap from one platform to + the next. +

+
+

+ fan.png (1089 bytes) +

+
+

+ Fans +

+

+ Powerful fans swirl around at a high speed and produces a power + blast of wind. It is advised to be careful on these, as it is + easy to go flying off the fans and into danger! +

+
+

+ conveyor.png (59401 bytes) +

+
+

+ Conveyor Belts +

+

+ Found in most of Eggman's factories, these conveyor belts are + used to quickly transport robotic components and robots. While + you can also make use of them, be alert! Eggman has changed the + movements of them to lead an unwary player into a trap! +

+
+

+ water.png (33687 bytes) +

+
+

+ Water +

+

+ All three characters can go underwater, but movement is greatly + slowed down, and only Tails can swim. Bear in mind that you + cannot breathe while you are underwater and must make use of the + air pockets that are found bubbling out of cracks in the floor. A + countdown will appear if you are dangerously close to running out + of air. If time runs out, you will drown and lose a life. +

+
+

+ slime.png (67845 bytes) +

+
+

+ Slime +

+

+ This is largely predominant in zones where Eggman has been at + work, such as the Techno Hill Zone. You can wade in it, but don't + get in too deep! The only way to safely swim is with an elemental + shield. +

+
+

+ crusher.png (49485 bytes) +

+
+

+ Crushers +

+

+ These traps are lethal and will immediately kill anyone trapped + under one - even invincibility will not protect you here. +

+
+

+ pit.png (5508 bytes) +

+
+

+ Deep Pits +

+

+ Like crushers, these traps immediately take one life and + invincibility is useless. +

+
+
+
+
+

+ + Multiplayer +

+

+ Not only can you play SRB2 alone, but with a network connection, your + friends as well! +

+

+ +

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

+ coop.png (11051 bytes) +

+

+ Co-Op +

+
+ Similar to a single player game, you can play through the single + player levels together. Up to 32 players allowed, but a maximum of + 8 is suggested. +
+

+ match.png (7565 bytes) +

+

+ Match +

+
+ It's a free for all, and the one with the most points wins! Run + around picking up rings to hurl at your opponent. Points are given + depending on the status of your target:
+
    +
  • Rings or Shield - 50 pts. +
  • +
  • No Rings or Shield - 100 pts. +
  • +
+

+ The player with the most points at the end of the round wins the + round.
+
+ Press the "Rankings" key to view scores. Up to a maximum of 32 + players allowed. +

+
+

+ match.png (7565 bytes) +

+

+ Team Match +

+
+ It's a team based fight to the finish. Play match with teammates, + and the team with the biggest total score wins. Scoring is the same + as match mode.
+
+ Press the "Rankings" key to view scores. Up to a maximum of 32 + players allowed. +
+

+ race.png (5364 bytes) +

+

+ Classic Race +

+
+ Just like Sonic 2's split screen mode, each player must race to the + end of the level. At the end of the stage, players will be ranked + based on the following five categories:
+
    +
  • Score - The player with the most points wins this category. +
  • +
  • Time - The player who beat the stage the fastest wins this + category. +
  • +
  • Ring - The player who completed the stage with the most rings + wins this category. +
  • +
  • Total Ring - The player who picked up the most rings wins + this category. Rings lost to enemies and hazards still count + towards this score. +
  • +
  • Item Box - The player who broke the most powerup monitors + wins this category. +
  • +
+

+ When one player has completed the stage, the rest of the players + in the game have 60 seconds to complete the stage or they will + die and the round will end. The player who wins the most + categories wins the round. +

+
+

+ race.png (5364 bytes) +

+

+ Race +

+
+ Just like Sonic 3's split screen mode, each player must race to the + end of the level. When one player has completed the stage, the rest + of the players in the game have 60 seconds to complete the stage or + they will die and the round will end. Best time wins! +
+

+ tag.png (11057 bytes) +

+

+ Tag +

+
+ You're it! Up to 32 people can play in this touch-and-run frenzy! + One player is it, and can tag others either by throwing a ring, or + by touching them. You become it once you're hit. In some levels + there is a no-tag zone, but don't stay in there too long! You gain + points by avoiding a tag each time one occurs. +

+ Press the "Rankings" key to view scores. Up to a maximum of 32 + players allowed. +

+
+

+ ctf.png (8251 bytes) +

+

+ Capture the Flag +

+
+ Just like the popular FPS game, but with a platforming twist! + Choose a team - Red or Blue. Grab the opposing team's flag and + bring it back to your base while your own team's flag is in the + base to score a point. +

+ Press the "Rankings" key to view scores. Up to a maximum of 32 + players allowed. +

+
+
+
+

+ You'll notice that in the LEVEL NAME, after the level, are letters in + parenthesis. This tells you what kind of level it is. +

+

+ C = Cooperative/Single Player +

+

+ R = Race/Classic Race +

+

+ M = Match/Team Match +

+

+ T = Tag +

+

+ F = Capture the Flag +

+

+ + Special Multiplayer Console Commands +

+

+ Multiplayer can make heavy use of the console, and you may find several + commands to your advantage. Please refer to the Console Command + Summary below. +

+

+ SRB2 uses ports 5029 and 5030 for network communication using the UDP + protocol. +

+
+

+ + Zones
+

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

+ gfz.png (19494 bytes) +

+
+ GREENFLOWER ZONE -
+ Sonic and friends immediately set out for the Greenflower Zone. + Luckily, you've reached this green haven before Eggman has had a + chance to completely take control. Whilst exploring this level, + keep your eyes peeled for anything hidden among the foilage... + including robots! +
+

+ thz.png (23896 bytes) +

+
+ TECHNO HILL ZONE -
+ Once a beautiful landscape, Eggman has turned this into a + slime-ridden mess. You'll eventually reach the factory, and once + inside, you'll have to negotiate lasers and crushers that have been + installed to stop your progress. Finally, a battle will ensue on a + high speed rail cart... +
+

+ dsz.png (32144 bytes) +

+
+ DEEP SEA ZONE -
+ Sonic, Tails and Knuckles stumble upon some ruins, which have been flooded, + partly by nature and partly by Eggman digging for the Chaos Emeralds. Be + wary of water traps which can threaten to drown you! +
+

+ cez.png (36151 bytes) +

+
+ CASTLE EGGMAN ZONE -
+ Having retreated here, Sonic, Tails and Knuckles must launch a + full-scale assault on this castle and defeat Eggman, who is + residing in the lower levels. Not only is this castle guarded by a + huge wall, but Eggman has laid several traps inside that will catch + you off guard! +
+

+ acz.png (43670 bytes) +

+
+ ARID CANYON ZONE -
+ Having escaped Eggman's stronghold, you come across a huge canyon. + While Sonic must find a way to cross this, Tails and Knuckles can use + their abilites to the fullest. Be careful not to enjoy the scenery too + much, as there are plenty of falling platforms and obstacles. +
+

+ rvz.png (45020 bytes) +

+
+ RED VOLCANO ZONE -
+ Finding Eggman's robots entering the volcano, you follow them to + investigate what's happening. Rather than worrying about Eggman's + traps here, you should be more concerned with the deadly lava, that + threatens to rise without warning. +
+

+ unknown.png (546 bytes) +

+
+ EGG ROCK ZONE -
+ You've finally arrived at the Eggrock Zone. Who knows what's in here? + Except for a few surprises, maybe. +
+

+ unknown.png (546 bytes) +

+
+ ??? -
+ More hidden levels are waiting to be unlocked... can you find them? +
+
+
+

+ +

+
+

+ + Controls +

+

+ The following are the default controls and their definition. You can + change the controls by going to Options/Setup Controls in the menu. Player 2's controls + can be changed as well. +

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Forward +

+ Default Key: Up Or W +

+
+ Moves your player forward. +
+ Reverse +

+ Default Key: Down Or S +

+
+ Moves your player in reverse. +
+ Turn Left +

+ Default Key: Left +

+
+ Turns your player left. +
+ Turn Right +

+ Default Key: Right +

+
+ Turns your player right. +
+ Jump +

+ Default Key: Z Or Mouse2 +

+
+ Makes your player jump. +
+ Spin +

+ Default Key: X +

+
+ If standing still, this will rev a spindash. If you are moving and + on the ground, you will go into a spin. +
+ Ring Toss +

+ Default Key: RCTRL Or Mouse1 +

+
+ If in a multiplayer game that permits it, this button throws a + ring. +
+ Ring Toss Normal +

+ Default Key: C +

+
+ If in a multiplayer game that permits it, this button will throw a + normal ring, whether you have special weapons or not. +
+ Taunt +

+ Default Key: V +

+
+ If in a multiplayer game, this key throws one of four random taunts + at your opponents, providing they exist for your character. Sonic, + Tails, and Knuckles do not have taunts. +
+ Toss Flag +

+ Default Key: ' (Apostrophe) +

+
+ Press this key to throw a flag + you are carrying (Capture the Flag). +
+ Strafe On +

+ Default Key: RALT +

+
+ Hold this down to use the Left and Right keys to strafe. +
+ Strafe Left +

+ Default Key: A +

+
+ Makes your player sidestep to the left. +
+ Strafe Right +

+ Default Key: D +

+
+ Makes your player sidestep to the right. +
+ Look Up +

+ Default Key: PageUp +

+
+ Tilts the camera upward. +
+ Look Down +

+ Default Key: PageDown +

+
+ Tilts the camera downward. +
+ Center View +

+ Default Key: End +

+
+ Centers the camera view. +
+ Mouselook +

+ Default Key: --- (No default key assigned) +

+
+ When held down, use the mouse to move your view. +
+ Talk Key +

+ Default Key: T +

+
+ Talk to other players in the game. +
+ Team-Talk Key +

+ Default Key: Y +

+
+ Talk to team members in the game. +
+ Rankings/Scores +

+ Default Key: Tab +

+
+ View current scores/statistics. +
+ Console +

+ Default Key: ~ (Tilde) +

+
+ Brings down the console. For advanced users only. +
+ Next Weapon +

+ Default Key: E +

+
+ Changes your weapon to the next one. +
+ Previous Weapon +

+ Default Key: Q +

+
+ Changes your weapon to the previous one. +
+ Weapon Slot 1 +

+ Default Key: 1 +

+
+ Changes your weapon to slot 1. +
+ Weapon Slot 2 +

+ Default Key: 2 +

+
+ Changes your weapon to slot 2. +
+ Weapon Slot 3 +

+ Default Key: 3 +

+
+ Changes your weapon to slot 3. +
+ Weapon Slot 4 +

+ Default Key: 4 +

+
+ Changes your weapon to slot 4. +
+ Weapon Slot 5 +

+ Default Key: 5 +

+
+ Changes your weapon to slot 5. +
+ Weapon Slot 6 +

+ Default Key: 6 +

+
+ Changes your weapon to slot 6. +
+ Weapon Slot 7 +

+ Default Key: 7 +

+
+ Changes your weapon to slot 7. +
+ Rotate Camera L +

+ Default Key: ( +

+
+ Rotates the camera left. +
+ Rotate Camera R +

+ Default Key: ) +

+
+ Rotates the camera right. +
+ Reset Camera +

+ Default Key: R +

+
+ Resets the camera if it gets stuck. +
+ Pause +

+ Default Key: Pause/Break +

+
+ Pauses the game. +
+
+
+

+ + Joystick Setup +

+
+ + + + + + + + + + +
+

+ controls.png (22752 bytes) +

+
+ You can also use a joystick with SRB2! Look in the controls menu + for a joystick menu to set it up! +
+ If you have an analog joystick/gamepad, you are welcome to try the + "Analog Control" option in the Options menu. In collaboration with + the Rotate Camera L and R buttons, you may prefer this method of + control over the standard one. Available in single player and + split-screen, but not network games. +
+
+
+

+ +

+
+

+ + Console Command Summary +

+

+ This is a general summary of some of the console commands that are in SRB2. + More information can be found on the website. +

+

+ + Commands +

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ CONNECT <ip> + + Connects to the specified IP address. If no IP is specified, it + will search on the LAN for a game. +
+ KICK <name or node #> + + Kicks a player in the current game (server only). +
+ GETPLAYERNUM + + Lists all of the players in the game, their number in the array, + and their node #s. +
+ SAVE <slot> <description> + + Saves your game. +
+ LOAD <slot> + + Loads a saved game. +
+ TUNES <slot> + + Temporarily changes the game music. +
+ DISPLAYPLAYER + + Displays the number of the current player being displayed. +
+ LISTSERV + + Retrieves a list of games currently running if the master list is + active. +
+ NODES + + Lists all of the players in the game and their node #s. +
+ SCREENSHOT + + Takes a screenshot of the game. Useful to bind a key to. +
+ CHANGECONFIG <filename> + + Saves the current config and loads another. +
+ LOADCONFIG <filename> + + Loads a new config without saving. +
+ SAVECONFIG <filename> + + Saves the current configuration. +
+ SETCONTROL +

+ SETCONTROL2 +

+
+ Manually changes the controls of 1P and 2P. See config.cfg for an + example. +
+ CHATMACRO + + Type in HELP CHATMACRO for more information. +
+ QUIT + + Exits the game. +
+ PAUSE + + Pauses the game. +
+ ADDFILE <filename> + + Adds a file to the game. +
+ EXITLEVEL + + Exits the current level. +
+ EXITGAME + + Exits the current game. +
+ MAP MAPxx (01-99) + + Changes the level. +
+ STOPDEMO + + Stops the currently running demo. +
+ TIMEDEMO + + Plays back a demo at full speed. Useful for benchmarking. +
+ PLAYDEMO + + Plays back a recorded demo. +
+ CHANGETEAM x (RED or BLUE) + + Changes the current CTF team you are on. +
+ BIND <key> <command> + + Binds a command to a key. +
+ CLS + + Clears the console buffer. +
+ TOGGLE + + Type HELP TOGGLE for more information +
+ HELP + + Provides help. +
+ WAIT + + Waits a certain number of game tics before executing the next + command. +
+ EXEC <filename> + + Executes a console script. +
+ ECHO + + Echos whatever you type. +
+ ALIAS + + Creates an alias. Type HELP ALIAS for more information. +
+ SAYTEAM <message> + + Sends a message to your team. +
+ SAYTO <playername> <message> + + Sends a message to this player. +
+ SAY <message> + + Sends a message to everyone. +
+ MEMFREE + + Displays memory usage statistics. +
+
+
+

+ + Variables +

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ SV_MAXPLAYERS (on/off) + + Sets the maximum number of players allowed to be in this game. +
+ SV_ALLOWNEWPLAYERS (on/off) + + Allow new players to join instantly or not. Setting this to NO + forces them to wait until the next map change. +
+ SURROUND (on/off) + + Toggles DirectSound3D acceleration. +
+ PRECACHESOUND (on/off) + + Tells the game to precache sound or not before playing. +
+ STEREOREVERSE (on/off) + + Toggles reverse stereo mode. +
+ CAM_ROTSPEED <integer> +

+ CAM2_ROTSPEED <integer> +

+
+ Changes the rotation speed of the camera. +
+ CAM_ROTATE <integer> +

+ CAM2_ROTATE <integer> +

+
+ Changes the angle of the camera's rotation. +
+ CAM_SPEED <integer> +

+ CAM2_SPEED <integer> +

+
+ Changes the speed of the camera. +
+ CAM_HEIGHT <integer> +

+ CAM2_HEIGHT <integer> +

+
+ Changes the height of the camera. +
+ CAM_STILL (on/off) +

+ CAM2_STILL (on/off) +

+
+ Forces the camera angle to freeze in place. +
+ CAM_DIST <integer> +

+ CAM2_DIST <integer> +

+
+ Changes the distance of the camera. +
+ ALLOWMLOOK + + Allow players to mouselook in a netgame (server only) +
+ SONICCD (on/off) + + An alternate mode of death for enemies. +
+ CHASECAM (on/off) +

+ CHASECAM2 (on/off) +

+
+ Turns the camera on and off. +
+ GRAVITY <decimal value> + + Changes the gravity when allowed. +
+ TRANSLUCENCY (on/off) + + Turns sprite translucency on and off. +
+ SND_CHANNELS <integer> + + Sets the number of sound channels. +
+ MUSICVOLUME <integer> + + Changes the music volume. +
+ SOUNDVOLUME <integer> + + Changes the sound volume. +
+ ALLOWTEAMCHANGE (yes/no) + + Allows players to change teams in CTF. (server only) +
+ ALLOWAUTOAIM (yes/no) + + Allows players to use autoaim. (server only) +
+ ALLOWEXITLEVEL (yes/no) + + Allows players to exit the level. (server only) +
+ SHOWMESSAGES (on/off) + + Suppresses or enables some screen messages. +
+ GAMMA <integer> + + Changes the gamma level. +
+ COLOR <colorname> +

+ COLOR2 <colorname> +

+
+ Changes your player's color +
+ NAME <name> +

+ NAME2 <name> +

+
+ Changes your player's name. +
+ SKIN <name> +

+ SKIN2 <name> +

+
+ Changes your player's character. +
+ FORCESKIN (on/off) + + Forces all players in the game to use the character that the server + is using. (server only) +
+ PLAYDEMOSPEED <integer> + + Changes the speed at which a demo is played back. +
+ NETSTAT (on/off) + + Shows network statistics. +
+ TIMELIMIT <integer> + + Sets a time limit for multiplayer levels. (server only) +
+ INTTIME <integer> + + Changes the intermission time in multiplayer levels. (server only) +
+ AUTOCTF (yes/no) + + Auto-sorts people on teams as they join. (server only) +
+ TIMETIC (on/off) + + Displays the time in game tics. +
+ SERVERNAME <name> + + Changes the name of the server. +
+ INTERNETSERVER (yes/no) + + Enables or disables advertising of the game on the master list. +
+ VID_WAIT (on/off) + + Enables/Disables V-Sync. +
+ VID_TICRATE (on/off) + + Shows game speed stats on a graph. +
+
+
+
+

+ + Extras +

+

+ knuckles.png (16482 bytes) +

+

+ There are many add-ons and extra goodies for SRB2! Visit the Addons + section at www.srb2.org for a large + cache of downloads. +

+

+ +

+
+

+ + Troubleshooting +

+

+ Have a problem? Question? Can't get SRB2 to work? Stop by the Forum at + www.srb2.org and ask. Someone will be + glad to help you work through the problem. +

+

+ +

+ + diff --git a/doc/manual/match.png b/doc/manual/match.png new file mode 100644 index 000000000..a89bf8d5d Binary files /dev/null and b/doc/manual/match.png differ diff --git a/doc/manual/metal.png b/doc/manual/metal.png new file mode 100644 index 000000000..6fc385c42 Binary files /dev/null and b/doc/manual/metal.png differ diff --git a/doc/manual/mixup.png b/doc/manual/mixup.png new file mode 100644 index 000000000..fc26fed17 Binary files /dev/null and b/doc/manual/mixup.png differ diff --git a/doc/manual/pit.png b/doc/manual/pit.png new file mode 100644 index 000000000..5accda689 Binary files /dev/null and b/doc/manual/pit.png differ diff --git a/doc/manual/platform.png b/doc/manual/platform.png new file mode 100644 index 000000000..c0e4c4993 Binary files /dev/null and b/doc/manual/platform.png differ diff --git a/doc/manual/race.png b/doc/manual/race.png new file mode 100644 index 000000000..66ebf9c6e Binary files /dev/null and b/doc/manual/race.png differ diff --git a/doc/manual/random.png b/doc/manual/random.png new file mode 100644 index 000000000..303ad5b53 Binary files /dev/null and b/doc/manual/random.png differ diff --git a/doc/manual/recycler.png b/doc/manual/recycler.png new file mode 100644 index 000000000..12e0343f6 Binary files /dev/null and b/doc/manual/recycler.png differ diff --git a/doc/manual/red_monitor.png b/doc/manual/red_monitor.png new file mode 100644 index 000000000..8ceae6ef5 Binary files /dev/null and b/doc/manual/red_monitor.png differ diff --git a/doc/manual/red_ring.png b/doc/manual/red_ring.png new file mode 100644 index 000000000..c3dcdd4c3 Binary files /dev/null and b/doc/manual/red_ring.png differ diff --git a/doc/manual/ring.png b/doc/manual/ring.png new file mode 100644 index 000000000..6f7c54f0d Binary files /dev/null and b/doc/manual/ring.png differ diff --git a/doc/manual/rshield.png b/doc/manual/rshield.png new file mode 100644 index 000000000..7a346cab5 Binary files /dev/null and b/doc/manual/rshield.png differ diff --git a/doc/manual/rvz.png b/doc/manual/rvz.png new file mode 100644 index 000000000..e20c5dc1f Binary files /dev/null and b/doc/manual/rvz.png differ diff --git a/doc/manual/shoes.png b/doc/manual/shoes.png new file mode 100644 index 000000000..5667f5462 Binary files /dev/null and b/doc/manual/shoes.png differ diff --git a/doc/manual/slime.png b/doc/manual/slime.png new file mode 100644 index 000000000..857f98fd3 Binary files /dev/null and b/doc/manual/slime.png differ diff --git a/doc/manual/soneup.png b/doc/manual/soneup.png new file mode 100644 index 000000000..f9f869f0c Binary files /dev/null and b/doc/manual/soneup.png differ diff --git a/doc/manual/spring1.png b/doc/manual/spring1.png new file mode 100644 index 000000000..8a222f378 Binary files /dev/null and b/doc/manual/spring1.png differ diff --git a/doc/manual/spring2.png b/doc/manual/spring2.png new file mode 100644 index 000000000..4e7b1a05a Binary files /dev/null and b/doc/manual/spring2.png differ diff --git a/doc/manual/spring3.png b/doc/manual/spring3.png new file mode 100644 index 000000000..c7b88b88a Binary files /dev/null and b/doc/manual/spring3.png differ diff --git a/doc/manual/spring4.png b/doc/manual/spring4.png new file mode 100644 index 000000000..d16919266 Binary files /dev/null and b/doc/manual/spring4.png differ diff --git a/doc/manual/spring5.png b/doc/manual/spring5.png new file mode 100644 index 000000000..0eedf4a6f Binary files /dev/null and b/doc/manual/spring5.png differ diff --git a/doc/manual/spring6.png b/doc/manual/spring6.png new file mode 100644 index 000000000..012b7bc2a Binary files /dev/null and b/doc/manual/spring6.png differ diff --git a/doc/manual/spring7.png b/doc/manual/spring7.png new file mode 100644 index 000000000..98c88bcd6 Binary files /dev/null and b/doc/manual/spring7.png differ diff --git a/doc/manual/spring8.png b/doc/manual/spring8.png new file mode 100644 index 000000000..ec552eebf Binary files /dev/null and b/doc/manual/spring8.png differ diff --git a/doc/manual/stats_lives.png b/doc/manual/stats_lives.png new file mode 100644 index 000000000..ec1371398 Binary files /dev/null and b/doc/manual/stats_lives.png differ diff --git a/doc/manual/stats_rings.png b/doc/manual/stats_rings.png new file mode 100644 index 000000000..5b807403e Binary files /dev/null and b/doc/manual/stats_rings.png differ diff --git a/doc/manual/tag.png b/doc/manual/tag.png new file mode 100644 index 000000000..72954b2b7 Binary files /dev/null and b/doc/manual/tag.png differ diff --git a/doc/manual/tailsfly.png b/doc/manual/tailsfly.png new file mode 100644 index 000000000..7628128de Binary files /dev/null and b/doc/manual/tailsfly.png differ diff --git a/doc/manual/thanks.png b/doc/manual/thanks.png new file mode 100644 index 000000000..8cb0ad115 Binary files /dev/null and b/doc/manual/thanks.png differ diff --git a/doc/manual/thz.png b/doc/manual/thz.png new file mode 100644 index 000000000..f4db3c59c Binary files /dev/null and b/doc/manual/thz.png differ diff --git a/doc/manual/title.png b/doc/manual/title.png new file mode 100644 index 000000000..e4ea963a9 Binary files /dev/null and b/doc/manual/title.png differ diff --git a/doc/manual/token.png b/doc/manual/token.png new file mode 100644 index 000000000..0e821ce37 Binary files /dev/null and b/doc/manual/token.png differ diff --git a/doc/manual/toneup.png b/doc/manual/toneup.png new file mode 100644 index 000000000..425973294 Binary files /dev/null and b/doc/manual/toneup.png differ diff --git a/doc/manual/unknown.png b/doc/manual/unknown.png new file mode 100644 index 000000000..a59a6c764 Binary files /dev/null and b/doc/manual/unknown.png differ diff --git a/doc/manual/water.png b/doc/manual/water.png new file mode 100644 index 000000000..2d5d607e0 Binary files /dev/null and b/doc/manual/water.png differ diff --git a/doc/manual/wpnpanel_auto.png b/doc/manual/wpnpanel_auto.png new file mode 100644 index 000000000..af71f98bf Binary files /dev/null and b/doc/manual/wpnpanel_auto.png differ diff --git a/doc/manual/wpnpanel_bounce.png b/doc/manual/wpnpanel_bounce.png new file mode 100644 index 000000000..606b3598e Binary files /dev/null and b/doc/manual/wpnpanel_bounce.png differ diff --git a/doc/manual/wpnpanel_explosion.png b/doc/manual/wpnpanel_explosion.png new file mode 100644 index 000000000..f3bd45dec Binary files /dev/null and b/doc/manual/wpnpanel_explosion.png differ diff --git a/doc/manual/wpnpanel_grenade.png b/doc/manual/wpnpanel_grenade.png new file mode 100644 index 000000000..f0e18fa08 Binary files /dev/null and b/doc/manual/wpnpanel_grenade.png differ diff --git a/doc/manual/wpnpanel_rail.png b/doc/manual/wpnpanel_rail.png new file mode 100644 index 000000000..bf0822360 Binary files /dev/null and b/doc/manual/wpnpanel_rail.png differ diff --git a/doc/manual/wpnpanel_scatter.png b/doc/manual/wpnpanel_scatter.png new file mode 100644 index 000000000..497f1abe1 Binary files /dev/null and b/doc/manual/wpnpanel_scatter.png differ diff --git a/doc/manual/wshield.png b/doc/manual/wshield.png new file mode 100644 index 000000000..20e3cf344 Binary files /dev/null and b/doc/manual/wshield.png differ diff --git a/doc/manual/yshield.png b/doc/manual/yshield.png new file mode 100644 index 000000000..6271eab9a Binary files /dev/null and b/doc/manual/yshield.png differ diff --git a/doc/rules.txt b/doc/rules.txt new file mode 100644 index 000000000..4bbb8cdc1 --- /dev/null +++ b/doc/rules.txt @@ -0,0 +1,39 @@ +SVN-RULES + +- As you can see, there is sub-directory in the repository, one for eatch + platform (djgpp (dos),win32,SDL) the root directory is for all platform, + so take care of the order we have put in. +- do not commit/upload tests of bugged code, try to fix a maximum of know + bugs and update know bugs list in source.txt. If you must commit your source + make your code in #ifdef so we can disable it +- SRB2 is a modification of doom/Doom Legacy source. We allow additionnal feature + and visual addition. +- Maximize communications between members, do not impose your changes, if your + are not sure about a feature/change, talk about it in irc://irc.esper.net/srb2 chat room. + +CODE-RULES + +- We use no tab, 4 space indent, and tab size 8 (in case some tab have filtred + and for makefile) +- Self documented code, variable and function must have a name that help + understand the code, so do not call variable and function a,b, a2, ... +- the usage of extern in a c file is prohibited, except for declaration of a + function with body (so it is like public keyword in c++) + Also function protos haren't allowed for external function, put it un the + corresponding h file. +- Try to minimize #ifdef usage for : + - code readability + - the main code is for all port so if something is good for a platform all + platform can benefit by this feature +- Take care of platform dependent code, we would like to have code that work + on Dos, Win32, SDL, ... little and big endian, software/Glide/OpenGl. + +GOOD PRACTICE + +- Try to put as mush static variable and function on module so it help to + understand the role of the varaible/function in the module also this + help the compiler to optimize +- minimise global variable +- make a log of your work, so you don't need to put a lot of comment in + the code, this will also help us to update the what's new section of doc + when doing final release diff --git a/doc/source.txt b/doc/source.txt new file mode 100644 index 000000000..5926d95fb --- /dev/null +++ b/doc/source.txt @@ -0,0 +1,240 @@ + +1. Compile SRB2 +2. Explanation of the code + 2.1 The memory model + 2.2 Hardware Texture model + +1. Compile SRB2 +================= + +DOS +--- + +need: +- djgpp 2.03 (http://www.delorie.com/djgpp/) +- allegro 3.12 (http://alleg.sourceforge.net/index.html) +( +- libsocket 0.7.4 (beta 4) or better + for use with Winsock 1.1 (example Windows 3.1) + (http://www.phekda.freeserve.co.uk/richdawe/lsck/lsck.htm) + OR +- Wattcp-32 v2.2 dev.rel 6 or better + For use with a packet driver + (http://www.bgnett.no/~giva/) + (http://groups.yahoo.com/group/watt-32/) + (http://groups.yahoo.com/group/watt-32/files/v2.2/) +) +- bcd 1.03 (inlcude in this package) +- gcc 2.95.2 is recommended +- nasm 0.98 (or better) (http://nasm.sourceforge.net/) + +compile: +make +make WATTCP=1 (to make a Wattcp-32 version) + +debug: +when craching SRB2 will return eip +type make asm, then you will have a 8 megs srb2.s (a assembler file) +the you can find the faulting instruction and function + +------------------------------------------------------------------------ + +Linux/SDL +----- + +need: +- tested with gcc 2.95 and 3.X. +- SDL 1.2 +- SDL_mixer 1.2 +- ibogg and libvorbis (http://Xiph.org/) +- nasm 0.98 (or better)(http://nasm.sourceforge.net/) only with 2.95, else add CC30=1 + +compile +make LINUX=1 + +debug: +gdb ? + +------------------------------------------------------------------------ + +Win32 +----- + +need : +- glide 3.x sdk (optional) (http://www.3dfx.com) +- directx6 sdk (or higher) (http://www.micosoft.com/directx) +- nasm 0.98 (or better) (http://nasm.sourceforge.net/) +- use src\win32\wLegacy.dsp +- VC6 should also work with VC5, and VS.NET 200X + +debug: +press on "step over" with the release version (there is some debug info +on it). Then change the eip in the regster window when you will type +enter the edi will go to the faulting instruction. don't forget that +you can follow the stack for calls. +You can also use trace with the debug version but add -win and -nomouse. + +------------------------------------------------------------------------ + +Win32/minGW/SDL +----- + +need: +- tested with gcc 2.95 and 3.X. +- can also use Dev-C++ 5.0 beta 9 (4.9.9.0) from http://www.bloodshed.net/dev/devcpp.html +- SDL 1.2 +- SDL_mixer 1.2 + +compile +make minGW=1 SDL=1 +or use src\SDL\Win32SDL.dev with Dev-C++ 4.9.9.0 or later + +debug: +gdb ? + +------------------------------------------------------------------------ + +WinCE/SDL WIP +----- + +need: +- ActiveSync 3.8 + http://www.microsoft.com/windowsmobile/downloads/activesync38.mspx + +- ActiveSync 3.7.1, if 3.8 isn't available for your language + http://www.microsoft.com/windowsmobile/downloads/activesync37.mspx + +- eMbedded Visual Tools 3.0 - 2002 Edition + http://www.microsoft.com/downloads/details.aspx?FamilyID=f663bf48-31ee-4cbe-aac5-0affd5fb27dd + +- Pocket PC 2000 SDK + http://www.microsoft.com/downloads/details.aspx?FamilyID=bb3f4d7b-de2a-4e1a-a175-26a68c301ac4 + +- Pocket PC 2002 SDK (eMVT 3.0 2002 Ed. comes with this) + http://www.microsoft.com/downloads/details.aspx?FamilyID=2dbee84a-bd94-4167-b817-2b2e548b2e92 + +- Pocket PC 2002 SDK Emulator Images (eMVT 3.0 2002 Ed. comes with this) + http://www.microsoft.com/downloads/details.aspx?FamilyID=25f4de97-ae80-477a-9df1-496b85b3d3e3 + +- eMbedded Visual C++ 4.0 + http://www.microsoft.com/downloads/details.aspx?familyid=1DACDB3D-50D1-41B2-A107-FA75AE960856 + +- eMbedded Visual C++ 4.0 SP3 (Win CE 4.0-4.2) + http://www.microsoft.com/downloads/details.aspx?FamilyID=5bb36f3e-5b3d-419a-9610-2fe53815ae3b + + OR + +- eMbedded Visual C++ 4.0 SP4 (No SH3 support,Win CE 4.0-5.0 support) + http://www.microsoft.com/downloads/details.aspx?FamilyID=4a4ed1f4-91d3-4dbe-986e-a812984318e5 + +- eMbedded Visual C++ 4.0 Update 5625 (SP4 only) + http://www.microsoft.com/downloads/details.aspx?FamilyID=aa282a6d-6f57-436d-8c10-0ec02d94f5b1 + +- Windows CE: Standard Software Development Kit + http://www.microsoft.com/downloads/details.aspx?familyid=a08f6991-16b0-4019-a174-0c40e6d25fe7 + +- SDK for Windows Mobile 2003-based Pocket PCs + http://www.microsoft.com/downloads/details.aspx?FamilyId=9996B314-0364-4623-9EDE-0B5FBB133652 + +- Emulator Images for Windows Mobile 2003 Second Edition software for Pocket PC + http://www.microsoft.com/downloads/details.aspx?familyid=5C53E3B5-F2A2-47D7-A41D-825FD68EBB6C + +- Microsoft Device Emulator 1.0 Community Preview + http://beta.microsoft.com Use Guest ID "MSDEVICE" to access the Community Preview website + +- Windows CE Utilities for Visual Studio .NET 2003 Add-on Pack 1.1 + (if you also have VS 2003 installed, you need this to install Win CE 5.0 SDK, else no need) + http://www.microsoft.com/downloads/details.aspx?FamilyId=7EC99CA6-2095-4086-B0CC-7C6C39B28762 + +- Windows CE 5.0: Standard Software Development Kit (eMC++ 4 SP4 only) + http://www.microsoft.com/downloads/details.aspx?FamilyID=fa1a3d66-3f61-4ddc-9510-ae450e2318c3 + +- SDL 1.27 (use patch and zip in tools\SDL1.2.7_CE) + +compile +use src\SDL\WinCE\SRB2CE.vcw + +debug: +? + + +2. Explanation of the code +========================== + + 2.1 The memory model (original) (z_zone.c) (by BP) + -------------------- + + SRB2 allocate a heap of 6/32/48 megs at begining and provide a Z_Malloc function + to allocate in this heap. + + Z_Malloc( int size,int tag,void* user ) + + size is the size in byte + tag can be : PU_STATIC allocated static (like malloc do) + call Z_Free to free it + PU_LEVEL same as static but the zone is "tagged" with the + tag PU_LEVEL, when calling + Z_FreeTag (PU_LEVEL, PU_LEVEL) all zone tagged + with PU_LEVEL are freed (at the end of the level) + PU_CACHE this one _can_ be freed automatiquely by one other + call to Z_Malloc. the *user point to a pointer + to this zone so when freed automatiquely the + pointer is set to NULL so eatch time you use it + you must check if the pointer is not NULL and + reload it. + + (...) + + 2.2 Hardware Texture model (by BP) + -------------------------- + + Eatch texture/patch/flats/pic in SRB2 are converted to hardware texture at + runtime (the GlideMipmap_s structure (hw_data.h)). I will call hardware + texture a gr_texture so there is no confusion. + + To remind you : + - Texture are set of patch and are associate to linedefs (walls) can be + upper, lower or middle texture. It can have hole on it. + - patch are sprites (the doom patch are run of vertical lines) + - flats are used for floors and ceiling of sectors and have size of 64x64 + it can't have hole on it + - pic are new legacy format for picture, it can only handle plain texture + like flats it is now used for hud in full screen for the main picture + of legacy and for coronas (the format was extended to handle 32 bit color + or intensity + alpha, not all are implemented at this time) + + Since patch, flat and pic are basic structure represented by only one lump in + the wad, the wad loader allocate for eatch lump a GlideMipmap_s (cache3Dfx) + and init data field to NULL. Since the data structure is allocated in + PU_3DFXCACHE (like PU_CACHE) the data will be initilised when needed + (hw_cache.c). + + The GlideMipmap_s structures for textures are initialized on + HWR_PrepLevelCache (hw_cache.c) it is called in P_SetupLevel (load level) + the number of textures is computed with TEXTURE1, TEXTURE2 lumps since this + can be changed in runtime in SRB2 (load a wad while runing) it must be + reallocated. Well, at this time it is realloceted at eatch level start. We + can do better, since numtextures change only when a wad is loaded. + + The 3dfx driver use glide3, it load gr_texture in gr_texture memory of the + card in fifo order when there is no more place it remove the first gr_texture, + the downloaded field of GlideMipmap_s go to false and when needed it is + reloaded in gr_texture memory. In OpenGl, since OpenGl keep texture in there + own memory and handle gr_texture memory of the card we no more need to + redownload it but if we not free time to time gr_texture memory in opengl, + it will get alot of memory, so the gr_texture memory is cleared at eatch + new level (same time of texture reallocation). Opengl and 3dfx link the + loaded gr_texture with the nextmipmap field of GlideMipmap_s so before clear + textures of the heap we MUST free gr_texture memory of OpenGl or 3dfx ! + + SRB2 can also draw patch with a differant colormap (thanks to Hurdler). + When needed it create the same gr_texture but just with a differant colormap. + This one is linked with the original in the GlideMipmap_s with the + nextcolormap field. + + So when a polygone with a gr_texture must be drawn, first we check if the + gr_textures is not allready loaded in hadware memory (downloaded field) if + not then we check if gr_texture data is there (not grabbed by z_malloc + function) if not we must recompute it eatch type of gr_texture (texture, + patch, flat, pic have there own methode) the we can send the gr_texture + to 3dfx or OpenGl. diff --git a/doc/specials.html b/doc/specials.html new file mode 100644 index 000000000..2cc840632 --- /dev/null +++ b/doc/specials.html @@ -0,0 +1,1992 @@ + + + + +Sonic Robo Blast II - Specials Reference Document + + + + +

SRB2 Specials Reference Document

+ +

Last updated May 27, 2008

+ +

For v1.1 Private Beta

+ +

This is the SRB2 Specials Reference Document. It is designed to be the ultimate +reference for effects used in SRB2. As such, it is rather technical in areas and quite +concise, and is not something a beginner with level design should be dealing with.

+ +

Thing Types

+ +

In general, thing bitsets have 4 flags and 3 digits for their height. The bitset is +0xAAAB, where AAA is the object's height above ground, and B are the Easy, Normal, Hard, +and Deaf flags. To get the bitset on a normal object, multiply the height desired by 16, +and then add the existant B. Some objects use 32 as this number, and they will be noted. +Objects that multiply by 16 can be placed up to 4095 units in the air, while objects that +multiply by 32 can be placed up to 2047 units in the air. + +

    +
  • Player Starts
      +

      1 - Player 01 Start

      +

      This is the start for the first player in single player mode, cooperative mode, or race + mode. This start must be placed on every map, as it is what the game defaults to if the + start it is attempting to find isn't there. If there is no Player 1 Start on the map, and + the game is confused over where to spawn the player, the game will crash outright.

      +

      The Deaf tag will make the player spawn from the ceiling, and the object needs to be + multiplied by 32 to give height, not 16.

      +

      2 - Player 02 Start

      +

      This is the start for the second player in cooperative and race mode.

      +

      The Deaf tag will make the player spawn from the ceiling, and the object needs to be + multiplied by 32 to give height, not 16.

      +

      3 - Player 03 Start

      +

      See Thing 2 for more information.

      +

      4 - Player 04 Start

      +

      See Thing 2 for more information.

      +

      5 - Player 05 Start

      +

      See Thing 2 for more information.

      +

      6 - Player 06 Start

      +

      See Thing 2 for more information.

      +

      7 - Player 07 Start

      +

      See Thing 2 for more information.

      +

      8 - Player 08 Start

      +

      See Thing 2 for more information.

      +

      9 - Player 09 Start

      +

      See Thing 2 for more information.

      +

      10 - Player 10 Start

      +

      See Thing 2 for more information.

      +

      11 - Player 11 Start

      +

      See Thing 2 for more information.

      +

      12 - Player 12 Start

      +

      See Thing 2 for more information.

      +

      13 - Player 13 Start

      +

      See Thing 2 for more information.

      +

      14 - Player 14 Start

      +

      See Thing 2 for more information.

      +

      15 - Player 15 Start

      +

      See Thing 2 for more information.

      +

      16 - Player 16 Start

      +

      See Thing 2 for more information.

      +

      17 - Player 17 Start

      +

      See Thing 2 for more information.

      +

      18 - Player 18 Start

      +

      See Thing 2 for more information.

      +

      19 - Player 19 Start

      +

      See Thing 2 for more information.

      +

      20 - Player 20 Start

      +

      See Thing 2 for more information.

      +

      21 - Player 21 Start

      +

      See Thing 2 for more information.

      +

      22 - Player 22 Start

      +

      See Thing 2 for more information.

      +

      23 - Player 23 Start

      +

      See Thing 2 for more information.

      +

      24 - Player 24 Start

      +

      See Thing 2 for more information.

      +

      25 - Player 25 Start

      +

      See Thing 2 for more information.

      +

      26 - Player 26 Start

      +

      See Thing 2 for more information.

      +

      27 - Player 27 Start

      +

      See Thing 2 for more information.

      +

      28 - Player 28 Start

      +

      See Thing 2 for more information.

      +

      29 - Player 29 Start

      +

      See Thing 2 for more information.

      +

      30 - Player 30 Start

      +

      See Thing 2 for more information.

      +

      31 - Player 31 Start

      +

      See Thing 2 for more information.

      +

      32 - Player 32 Start

      +

      See Thing 2 for more information.

      +

      33 - Player Match Start

      +

      This is the start for players in Match and Chaos modes. They should also be placed in + Capture the Flag maps as well. There should be 32 of these in a map to assure proper + randomization. While it's unelegant, they can be stacked on top of each other without + negative effect.

      +

      The Deaf tag will make the player spawn from the ceiling, and the object needs to be + multiplied by 32 to give height, not 16.

      +

      34 - CTF Team Start (Red)

      +

      This is the start for players on the red team in Capture the Flag mode. There should be + 32 of these in a map to assure proper randomization. While it's unelegant, they can be + stacked on top of each other without negative effect.

      +

      The Deaf tag will make the player spawn from the ceiling, and the object needs to be + multiplied by 32 to give height, not 16.

      +

      35 - CTF Team Start (Blue)

      +

      This is the start for players on the blue team in Capture the Flag mode. There should + be 32 of these in a map to assure proper randomization. While it's unelegant, they can be + stacked on top of each other without negative effect.

      +

      The Deaf tag will make the player spawn from the ceiling, and the object needs to be + multiplied by 32 to give height, not 16.

      +

       

      +
    +
  • +
  • Enemies
      +

      100 - Crawla (Blue)

      +

      These are the blue ground enemies found in the one player stages. They can't move off + of cliffs and are exceedingly slow.

      +

      101 - Crawla (Red)

      +

      These are the red ground enemies found in the one player stages. They can't move off + cliffs and are relatively slow.

      +

      102 - Stupid Dumb Unnamed RoboFish (tm)

      +

      This is the little fish in Greenflower Zone. The angle determines the jump height, with + 0 being the old jump style. Note that the jump height is based on force, not units, so + experimentation will be necessary to get the correct height.

      +

      103 - Yellow Buzz

      +

      This enemy flies at a moderate speed directly at the player.

      +

      104 - Red Buzz

      +

      This enemy flies at a relatively high speed directly at the player.

      +

      105 - Jetty-Syn Bomber

      +

      This is a highly mobile flying enemy with a bomb that it drops on the player from + directly above. It is considered highly difficult to kill, and should only be used in + situations where the stage is supposed to be difficult.

      +

      106 - Jetty-Syn Gunner

      +

      This is a highly mobile flying enemy with a gun that it fires at the player with high + accuracy. It is considered highly difficult to kill, and should only be used in situations + where the stage is supposed to be difficult.

      +

      107 - Crawla Commander

      +

      This is the grey floating enemy in the opening room of Techno Hill Zone Act 2. It is + quite fast and will start bouncing after taking the first hit. It is significantly + challenging, although a spindash will kill it given time.

      +

      108 - Deton

      +

      This is the red spherical enemy in Techno Hill Zone Act 2. Upon seeing the player, it + makes a mad dash straight for them. With the exception of the Armageddon + Shield, Detons are invincible, and must be avoided by running behind a wall or another + enemy.

      +

      109 - Skim

      +

      This is an enemy that floats on the surface of the water, dropping bombs into the water + below. It is not currently used in any of the Single Player stages, but it is fully + operational. The designer does not have to put them on the surface of the water, they know + where it is.

      +

      110 - THZ Turret

      +

      This is the turret from Techno Hill Zone Act 2. It fires large bursts of laser fire at + the player with high accuracy. It is invincible unless it is somehow dipped into water.

      +

      111 - Popup Turret

      +

      This is a small turret that pops up now and then and shoots. The object's angle is a + value defining the delay between shooting.

      +

      112 - Sharp

      +

      This is a blue enemy with spikes on top if it. It starts off by slowly chasing the player, + then it fades to red and runs after the player, and is invincible until it fades back to red.

      +

      113 – Jet Jaw

      +

      This is an underwater enemy that tries to bite at the player, which can be found in + Deep Sea Zone.

      +

      114 – Snailer

      +

      This is an incomplete enemy.

      +

      115 – Bird Aircraft Strike Hazard (B.A.S.H.)

      +

      This is the red vulture-like enemy in Arid Canyon Zone. If it sees a player, it lifts off and + charges at him. Collision with a wall will send it plummeting.

      +

      116 – Pointy

      +

      This is the orbinaut enemy that has spikes circling around it. None of the single player stages + currently use him. You have to place him in a map by using a WAD editor, he can't be placed using + objectplace.

      +

      117 – Robo-Hood

      +

      This is the green enemy from Castle Eggman Zone, which shoots arrows at the player.

      +

      118 – CastleBot FaceStabber

      +

      This is the large grey enemy from Castle Eggman Zone. It slowly trudges towards the player, + and if the player in range, lunges at them with his sword.

      +

      119 – Egg Guard

      +

      This is the enemy from Castle Eggman Zone that wields a protective shield.

      +

      120 – Green Snapper

      +

      This is the green turtle enemy from Arid Canyon Zone. This enemy behaves exactly like a blue + crawla does. The circumference of its shell is covered with spikes, so the only way to destroy it + is by jumping on top of it.

      +

      121 – Minus

      +

      This is the digging enemy from Arid Canyon Zone. It burrows underground towards the player, and + once it's directly underneath, it bursts out from under the ground, jumping up and hurting the player.

      +

       

      +
    +
  • +
  • Bosses and their associated items (if any)
      +

      200 - Egg Mobile (Boss 1)

      +

      The boss of Greenflower Zone and Castle Eggman Zone. He moves around firing at the + player, and after taking six hits, he dashes at the player.

      +

      Giving the boss the Deaf flag will make him have spikeballs, like CEZ3, and giving him + the Multi flag will make the level end when he is dead. To place him above ground, + multiply by 32 to give height, not 16.

      +

      201 - Egg Slimer (Boss 2)

      +

      This is the boss of Techno Hill Zone. It requires an axis point at the center to + function, and it goes in a circle around the axis point dropping slime. After 6 hits, he + stops going in a circle, and bouncing at the player, spewing a lot more slime.

      +

      The Multi flag will make the level end when he is dead.

      +

      202 - Sea Egg (Boss 3)

      +

      This is the boss of Deep Sea Zone. More information will be supplied later.

      +

      The Multi flag will make the level end when he is dead.

      +

      203 - Eggscalibur (Boss 4)

      +

      This is the boss of Castle Eggman Zone. More information will be supplied later.

      +

      The Multi flag will make the level end when he is dead.

      +

      290 - Boss Flypoint

      +

      This is the location the boss will fly to after being killed.

      +

      291 - Egg Capsule Center

      +

       

      +
    +
  • +
  • Collectibles
      +

      300 - Ring

      +

      This is a normal ring. Pick this up to get one ring.

      +

      Giving the deaf tag to a ring will cause it to float 31 units above the ground. This + does stack with bitsets, allowing rings to be a total of 4127 units above the ground at + maximum.

      +

      301 - Bounce Ring

      +

      Picking this up gives you more ammo for this particular ring weapon. You cannot fire + the weapon, however, if you do not have the associated panel. +

      302 - Rail Ring

      +

      See thing #301.

      +

      304 - Automatic Ring

      +

      See thing #301.

      +

      305 - Explosion Ring

      +

      See thing #301.

      +

      306 - Scatter Ring

      +

      See thing #301.

      +

      307 - Grenade Ring

      +

      See thing #301.

      +

      310 - CTF Flag (Red)

      +

      This is the red team's flag in capture the flag mode. If the blue team takes this to + their team base (sector type 16384), they score a point.

      +

      311 - CTF Flag (Blue)

      +

      This is the blue team's flag in capture the flag mode. If the red team takes this to + their team base (sector type 12288), they score a point.

      +

      312 - Special Stage Token

      +

      This token gives the player a chance at the special stage after the current stage has + ended. If more than one token is collected, the player gets that many chances at the + special stages, continuing until they run out of tokens or have all the emeralds.

      +

      313 - Emerald 1 (Green)

      +

      This object gives the player the first emerald as a pickup object, instead of by + completing a special stage.

      +

      314 - Emerald 2 (Orange)

      +

      This object gives the player the second emerald as a pickup object, instead of by + completing a special stage.

      +

      315 - Emerald 3 (Pink)

      +

      This object gives the player the third emerald as a pickup object, instead of by + completing a special stage.

      +

      316 - Emerald 4 (Blue)

      +

      This object gives the player the fourth emerald as a pickup object, instead of by + completing a special stage.

      +

      317 - Emerald 5 (Red)

      +

      This object gives the player the fifth emerald as a pickup object, instead of by + completing a special stage.

      +

      318 - Emerald 6 (Light Blue)

      +

      This object gives the player the sixth emerald as a pickup object, instead of by + completing a special stage.

      +

      319 - Emerald 7 (Grey)

      +

      This object gives the player the seventh emerald as a pickup object, instead of by + completing a special stage.

      +

      320 - Emerald Hunt Location

      +

      This is one of the three emeralds to be used in Hunting mode.

      +

      323 - Emerald Spawn

      +

      Spawn location for emeralds in Match mode.

      +

      330 - Bounce Ring Panel

      +

      This is a match weapon panel. The Bounce Ring throws a slow ring that will bounce when + it hits walls.

      +

      Giving the deaf tag to a panel will cause it to float 31 units above the ground. This + does stack with bitsets, allowing panels to be a total of 4127 units above the ground at + maximum.

      +

      331 - Rail Ring Panel

      +

      This is a match weapon panel. The Rail Ring gives the player an instantaneous shot, that + strikes its target the instant its fired, however there is a long downtime between shots. + Being shot by a rail ring causes more kickback than normal.

      +

      Giving the deaf tag to a panel will cause it to float 31 units above the ground. This + does stack with bitsets, allowing panels to be a total of 4127 units above the ground at + maximum.

      +

      332 - Automatic Ring Panel

      +

      This is a match weapon panel. The Automatic Ring gives the player a fire rate of 17.5 + rings per second.

      +

      Giving the deaf tag to a panel will cause it to float 31 units above the ground. This + does stack with bitsets, allowing panels to be a total of 4127 units above the ground at + maximum.

      +

      333 - Explosion Ring Panel

      +

      This is a match weapon panel. The Explosion Ring throws a slow ring that explodes into + many fragments upon striking a wall or another player. Being struck directly by the + Explosion Ring causes more kickback than usual.

      +

      Giving the deaf tag to a panel will cause it to float 31 units above the ground. This + does stack with bitsets, allowing panels to be a total of 4127 units above the ground at + maximum.

      +

      334 - Scatter Ring Panel

      +

      This is a match weapon panel. The Scatter Ring throws 5 rings in a plus-shape.

      +

      Giving the deaf tag to a panel will cause it to float 31 units above the ground. This + does stack with bitsets, allowing panels to be a total of 4127 units above the ground at + maximum.

      +

      335 - Grenade Ring Panel

      +

      This is a match weapon panel. The Grenade Ring throws a grenade that will explode + if an opposing player gets too close to it. It will also explode automatically after a + while if left untouched.

      +

      Giving the deaf tag to a panel will cause it to float 31 units above the ground. This + does stack with bitsets, allowing panels to be a total of 4127 units above the ground at + maximum.

      +

       

      +
    +
  • +
  • Boxes
      +

      400 - Super Ring (10 Rings)

      +

      This monitor gives the player ten rings.

      +

      If monitors are given the Deaf tag, they will respawn as a random monitor type (not a ? + monitor) from the weighted table in modes that support respawn. Elsewise, they will + respawn as the same monitor.

      +

      402 - Attraction Shield

      +

      Also known as the yellow shield and god shield, this shield protects the player from a + single hit, then disappears. It also attracts all normal rings, spilled or on the map to + the player with the shield. It also protects the player from electric damage.

      +

      If monitors are given the Deaf tag, they will respawn as a random monitor type (not a ? + monitor) from the weighted table in modes that support respawn. Elsewise, they will + respawn as the same monitor.

      +

      403 - Force Shield

      +

      Also known as the blue shield, this shield protects the player from two hits, then + disappears. If the spin  button is pressed while jumping, it is also possible to + reflect many projectiles.

      +

      If monitors are given the Deaf tag, they will respawn as a random monitor type (not a ? + monitor) from the weighted table in modes that support respawn. Elsewise, they will + respawn as the same monitor.

      +

      404 - Armageddon Shield

      +

      Also known as the black shield, this shield protects the player from a single hit, + triggering upon a hit. The shield can also be triggered by jumping, and then hitting the + spin key in midair. When the shield is triggered, a flash of light damages everything + within a large radius, destroying the shield in the process.

      +

      If monitors are given the Deaf tag, they will respawn as a random monitor type (not a ? + monitor) from the weighted table in modes that support respawn. Elsewise, they will + respawn as the same monitor.

      +

      405 - Whirlwind Shield

      +

      This shield protects the player from a single hit, then disappears. If the player does + a jump-spin, they will do a second jump in midair, making the maximum height that the + player can jump with the shield 224.

      +

      Versions of SRB2 previous to 1.09 had the Basic Shield in this object number, so make + sure to note that if the player loads the map in an older version, that is what they will + see.

      +

      If monitors are given the Deaf tag, they will respawn as a random monitor type (not a ? + monitor) from the weighted table in modes that support respawn. Elsewise, they will + respawn as the same monitor.

      +

      406 - Elemental Shield

      +

      Also known as the green  shield, this shield protects the player from a single + hit, then disappears. While this shield is active, the player cannot drown. It also + protects the player from water, fire, and other damage. When the player with this shield + spin-dashes, it leaves a trail of fire, which deals fire damage to any enemy that touches + it.

      +

      If monitors are given the Deaf tag, they will respawn as a random monitor type (not a ? + monitor) from the weighted table in modes that support respawn. Elsewise, they will + respawn as the same monitor.

      +

      407 - Super Sneakers

      +

      This is a monitor powerup that gives the player about 2x running speed for 20 seconds.

      +

      408 - Invincibility

      +

      This is a monitor powerup that prevents all damage to the player for 20 seconds.

      +

      409 - Extra Life

      +

      This powerup monitor features the player's face, and provides an extra life when + struck.

      +

      If monitors are given the Deaf tag, they will respawn as a random monitor type (not a ? + monitor) from the weighted table in modes that support respawn. Elsewise, they will + respawn as the same monitor.

      +

      410 - Eggman

      +

      This monitor damages the player if they strike it.

      +

      If monitors are given the Deaf tag, they will respawn as a random monitor type (not a ? + monitor) from the weighted table in modes that support respawn. Elsewise, they will + respawn as the same monitor.

      +

      411 - Teleporter

      +

      This monitor mixes up all locations of players, teleporting them to the location of a + random other player. It has no effect in Single Player or in multiplayer modes while only + one player is in the game.

      +

      If monitors are given the Deaf tag, they will respawn as a random monitor type (not a ? + monitor) from the weighted table in modes that support respawn. Elsewise, they will + respawn as the same monitor.

      +

      412 - Random Box

      +

      Destroy this monitor and you will get a random powerup, like the boxes in Sonic 2 race + mode.

      +

      413 - Gravity Boots Box

      +

      Destroy this monitor and the gravity will be flipped for a short time.

      +

       

      +
    +
  • +
  • Interactive Objects (friendly or otherwise)
      +

      500 - Air Bubble Patch

      +

      This is the air bubble patch used underwater to give players air. It spawns big bubbles + randomly which replenish the player's air.

      +

      501 - End Level Sign

      +

      This is the sign at the end of the stage. When the player enters the Exit + Sector, this sign will start to spin, and end on the face of the player. This sign + does not make the stage end, it's just a visual effect for it.

      +

      502 - Star Post

      +

      Star Posts allow the player to respawn after dying at a point other than the beginning + of the stage. There can be up to 32 Star Posts in a map, and they work with the bitsets.

      +

      Instead of controlling the difficulty and deaf flags, the final digit of the bitset + determines the number of the Star Post. 0x0000 is the first one and 0x000f is the + sixteenth one. Note that since this overwrites all of the difficulty flags, they will + appear in all difficulties, even though 0x0000 would normally mean it wouldn't appear in + any difficulty level.

      +

      520 - Spikeball

      +

      Just like thing 521, except they do normal damage to the player on + contact.

      +

      521 - Spikeball (Special Stage)

      +

      These are the spikeballs used in the special stages. They harm the player for damage on + contact, but only if they are carrying rings.

      +

      522 - Ceiling Spike

      +

      This is a downward pointing spike for use on the ceiling. Touching the pointy end of + the spike deals damage to the player.

      +

      By default, it attaches itself to the ceiling, and the height part of the bitset + measures how far down from the ceiling, instead of up from the floor.

      +

      523 - Floor Spike

      +

      This is a upward pointing spike for use on the floor. Touching the pointy end of the + spike deals damage to the player.

      +

      524 - Big Floating Mine

      +

      When you get close, this mine will start to follow you. Touches you, and it explodes.

      +

      540 - THZ Fan

      +

      This is the fan used inside the secret passage in Techno Hill Zone Act 1. It pushes the + player slowly up until it reaches the maximum height it can. The maximum height is + determined by the angle, measured in normal fracunits (It can go above 360 just fine).

      +

      541 - THZ Gas Jet

      +

      This is the gas jet used at the end of Techno Hill Zone Act 1. It launches the player + straight up on regular intervals about the same height as a yellow spring pointing up.

      +

      550 - Yellow Spring (Up)

      +

      This is a yellow spring pointing straight up. It has a medium amount of force behind + it.

      +

      551 - Red Spring (Up)

      +

      This is a red spring pointing straight up. It has a large amount of force behind it.

      +

      552 - Blue Spring

      +

      This is a blue spring pointing straight up. It has a small amount of force behind it. + The intent is for this spring to be used underwater. It has about the same effect + underwater as a yellow spring does above water.

      +

      553 - Yellow Spring (Down)

      +

      This is a yellow spring pointing straight down. It has a medium amount of force behind + it.

      +

      554 - Red Spring (Down)

      +

      This is a red spring pointing straight down. It has a large amount of force behind it.

      +

      555 - Yellow Spring (Diagonal Up)

      +

      This is a yellow spring pointing upwards and in the direction the thing is facing. It + has a medium amount of force behind it. When the player touches this spring, he will + automatically turn to face the direction the spring is launching the player.

      +

      556 - Red Spring (Diagonal Up)

      +

      This is a red spring pointing upwards and in the direction the thing is facing. It has + a large amount of force behind it. When the player touches this spring, he will + automatically turn to face the direction the spring is launching the player.

      +

      557 - Yellow Spring (Diagonal Down)

      +

      This is a yellow spring pointing downwards and in the direction the thing is facing. It + has a medium amount of force behind it. When the player touches this spring, he will + automatically turn to face the direction the spring is launching the player.

      +

      558 - Red Spring (Diagonal Down)

      +

      This is a red spring pointing downward and in the direction the thing is facing. It has + a large amount of force behind it. When the player touches this spring, he will + automatically turn to face the direction the spring is launching the player.

      +

       

      +
    +
  • +
  • Special placement patterns
      +

      600 - 5 Vertical Rings (Yellow Spring)

      +

      This is a chain of five rings intended to be used with thing 550. + Do not use ring chain objects in any mode where items respawn, because ring chains do not + respawn. Use bitsets to create chains in any mode with item respawn.

      +

      601 - 5 Vertical Rings (Red Spring)

      +

      This is a chain of five rings intended to be used with thing 551. + Do not use ring chain objects in any mode where items respawn, because ring chains do not + respawn. Use bitsets to create chains in any mode with item respawn.

      +

      602 - 5 Diagonal Rings (Yellow Spring)

      +

      This is a chain of five rings intended to be used with thing 555. + Do not use ring chain objects in any mode where items respawn, because ring chains do not + respawn. Use bitsets to create chains in any mode with item respawn.

      +

      603 - 10 Diagonal Rings (Red Spring)

      +

      This is a chain of ten rings intended to be used with thing 556. Do + not use ring chain objects in any mode where items respawn, because ring chains do not + respawn. Use bitsets to create chains in any mode with item respawn.

      +

      604 - Nights: Circle of Rings

      +

      605 - Nights: Circle of Rings (Big)

      +

      606 - Nights: Circle of Wing Logos

      +

      607 - Nights: Circle of Wing Logos (Big)

      +

      608 - Nights: Circle of Rings and Wings

      +

      609 - Nights: Circle of Rings and Wings (Big)

      +

       

      +
    +
  • +
  • Powerup indicators/environmental effects/miscellany
      +

      700 - Ambient Water SFX 1A (Small)

      +

      701 - Ambient Water SFX 1B (Small)

      +

      702 - Ambient Water SFX 2A (Medium)

      +

      703 - Ambient Water SFX 2B (Medium)

      +

      704 - Ambient Water SFX 3A (Large)

      +

      705 - Ambient Water SFX 3B (Large)

      +

      706 - Ambient Water SFX 4A (Extra Large)

      +

      707 - Ambient Water SFX 4B (Extra Large)

      +

      708 - Random Ambience 1

      +

      709 - Random Ambience 2

      +

      750 - Chaos Mode Enemy Spawn

      +

      This is where the enemies spawn from in Chaos mode. There should be around 12 of these + points on a map with Chaos support.

      +

      751 - Teleport Destination

      +

      This is the thing to be used with linedef type 412, the linedef + executor that teleports a player. This thing is where the player will spawn in the tagged + sector.

      +

      752 - Alternate View Point

      +

      This is the thing to be used with linedef type 422, the linedef + executor that changes the camera view. This thing is where the camera will be moved to in + the tagged sector.

      +

      753 - Zoom Tube Waypoint

      +

      Waypoints for zoom tubes. Think of Sonic 2's Metropolis Zone, Sonic 3 & Knuckles's + Death Egg Zone, and Lava Reef Zone. The lower byte of the ANGLE field specifies the + waypoint's number in the sequence, and the upper byte specifies the sequence that the + waypoint belongs to. These are used in conjunction with sector type 32768 + and 36864.

      +

      754 - Push

      +

      755 - Pull

      +

      756 - Street Light Source

      +

      This produces a light in OpenGL. It is used in Starlit Warehouse Zone, one of the match + stages, as the street lights.

      +

      760 - PolyObject Anchor

      +

      This is the first of the two points used to set up 'how much to move' a polyobject by + when creating it. Angle is the PolyObject ID#.

      +

      761 - PolyObject SpawnPoint

      +

      This is the second of the two points used to set up 'how much to move' a polyobject by + when creating it. Angle is the PolyObject ID#.

      +

      762 - PolyObject SpawnPoint Crush

      +

      This is the second of the two points used to set up 'how much to move' a polyobject by + when creating it. Angle is the PolyObject ID#. This item tells the PolyObject that it + should hurt the player.

      +

       

      +
    +
  • +
  • Greenflower Scenery
      +

      800 - GFZ Flower (Normal)

      +

      This is a scenery object from Greenflower Zone. It is the orange flower seen all + throughout GFZ and most GFZ-themed custom maps.

      +

      801 - GFZ Sunflower

      +

      This is a scenery object from Greenflower Zone. It is the large blue sunflower seen all + throughout GFZ and most GFZ-themed custom maps.

      +

      802 - GFZ Budding Flower

      +

      This is a scenery object from Greenflower Zone. It is the small purple flower seen all + throughout GFZ and most GFZ-themed custom maps.

      +

      804 - Berry Bush

      +

      This is a scenery object from Greenflower Zone. It is the green bush with red berries + seen all throughout GFZ and most GFZ-themed custom maps.

      +

      805 - Bush

      +

      This is a scenery object from Greenflower Zone. It is the green bush without the + berries seen all throughout GFZ and most GFZ-themed custom maps.

      +

       

      +
    +
  • +
  • Techno Hill Scenery
      +

      900 - THZ Flower

      +

      This is a scenery object from Techno Hill Zone Act 1. It is the metallic white flower.

      +

      901 - THZ Alarm

      +

      This is a scenery object from Techno Hill Zone Act 2. It is the little alarm in the + passage with the first Star Post. It creates noise, but the red visual effect in THZ2 was + done with a colormap, not this object.

      +

       

      +
    +
  • +
  • Deep Sea Scenery
      +

      1000 - Gargoyle

      +

      Pushable gargoyle. Can be stood on top of as well.

      +

      Giving this the Deaf tag will prevent it from being pushable.

      +

      1001 - Seaweed

      +

      Animated seaweed. Intangible scenery.

      +

      1002 - Dripping Water

      +

      Water dripping from the ceiling. ANGLE value specifies start delay.

      +

       

      +
    +
  • +
  • Castle Eggman Scenery
      +

      1100 - Hanging Chain

      +

      This is a scenery object from Castle Eggman, a dungeon chain hanging from the ceiling.

      +

      By default, it attaches itself to the ceiling, and the height part of the bitset + measures how far down from the ceiling, instead of up from the floor.

      +

      1101 - CEZ Torch

      +

      This is the torch used in Castle Eggman Zone. It produces light in OpenGL, and it harms + the player for fire damage on contact.

      +

      1102 - Eggman Statue

      +

      This is the large Eggman statue in Castle Eggman Zone.

      +

      1103 - CEZ Flower

      +

      This is a scenery object from Castle Eggman Zone. It is the decaying flower.

      +

       

      +
    +
  • +
  • Arid Canyon Scenery
      +

      1200 – Big Tumbleweed

      +

      A large moveable tumbleweed that rolls along the floor.

      +

      1201 – Little Tumbleweed

      +

      A small movable tumbleweed that rolls along the floor.

      +

      1202 – Rock Spawner

      +

      An object which randomly spawns falling rocks, which damage the player on impact.
      + Description on how to use goes here.

      +
    +
  • +
  • Red Volcano Scenery
      +

      1300 – Horizontal Flame Jet

      +

      A stready stream of flames comes out horizontally.

      +

      1301 – Vertial Flame Jet

      +

      A stready stream of flames comes out vertially.

      +
    +
  • +
  • Dark City Scenery
      +
    +
  • +
  • Doom Ship Scenery
      +
    +
  • +
  • Egg Rock / Final Fight Scenery
      +
    +
  • +
  • NiGHTS Items
      +

      1700 - Nights: Axis

      +

      Lower 10 bits: Axis number in the mare (0-based) Upper 6 bits: Mare that axis belongs + to (0-based). ANGLE value determines the size of the axis to rotate around. If 16384 is + added to the ANGLE value, the axis will be inverted.

      +

      1701 - Nights: Axis Transfer (Normal)

      +

      1702 - Nights: Axis Transfer Line

      +

      1703 - Nights: Ideya Drone

      +

      Angle value sets the NiGHTS timer, in seconds.

      +

      1704 - Nights: Bumper

      +

      Lower 4 bits of the flags specify the angle of the bumper in 30 degree increments.

      +

      1705 - Nights: Hoop

      +

      1706 - Nights: Wing Logo

      +

      1707 - Nights: Super Loop

      +

      1708 - Nights: Drill Refill

      +

      1709 - Nights: Helper

      +

      1710 - Nights: Egg Capsule

      +

      The capsule you need to collect rings to break in NiGHTS. The value of its ANGLE field + determines how many rings you need to break it. Just like the axis points, the upper bits + (value >> 10) determine the mare it belongs to. For example, an angle value of 1024 + means it belongs to mare 1 (2nd mare, it's zero based), and requires 0 rings to break. + 1030 would be mare 1, and 6 rings to break. 2048 would be mare 2, no rings.

      +

       

      +
    +
  • +
  • Mario Items
      +

      1800 - Coin

      +

      This is a coin, which is essentially a ring with Mario graphics and sound effects.

      +

      1801 - Overworld Goomba

      +

      These are the enemies in Mario Koopa Blast 1, and are essentially Crawlas with a Mario + graphic.

      +

      1802 - Underworld Goomba

      +

      These are the enemies in Mario Koopa Blast 2, and are essentially Crawlas with a Mario + graphic.

      +

      1803 - Fire Flower

      +

      This is the powerup from the Mario Koopa Blast stages. It changes the player to a white + palette, and allows the player to throw fireballs with the fire button. The fireballs fly + in a Mario-style bounce trajectory until they hit an enemy or a wall.

      +

      1804 - Koopa Shell

      +

      This is the Koopa Shell in Mario Koopa Blast 1. It will bounce around, striking enemies + and players.

      +

      1805 - Puma (Mario Jumping Fireball)

      +

      This is the fireball used in Mario Koopa Blast 3. The angle determines the jump height, + with 0 being the old jump style. Note that the jump height is based on force, not units, + so experimentation will be necessary to get the correct height.

      +

      1806 - King Bowser

      +

      1807 - Axe

      +

      The axe used to defeat Bowser in the third Mario level.

      +

      1808 - Bush (Short)

      +

      This is a scenery object from Mario Koopa Blast

      +

      1809 - Bush (Tall)

      +

      This is a scenery object from Mario Koopa Blast

      +

      1810 - Toad

      +

      This is Toad at the end of Mario Koopa Blast 3.

      +

       

      +
    +
  • +
  • Xmas Items
      +

      1850 - Xmas Pole

      +

      X-Mas scenery object. Looks like a little barber shop pole.

      +

      1851 - Candy Cane

      +

      X-Mas scenery object. Looks like a candy cane.

      +

      Note that Mystic Realm 4 replaces this object with the Sonic 1 palm tree, so any maps + loaded while Mystic Realm 4 is loaded will overwrite the image, making any candy canes + look like palm trees, which can look kinda stupid.

      +

      1852 - Snowman

      +

      X-Mas scenery object. Pushable snowman with a happy face. Can be stood on top of as + well. Acts the same as thing 1000.

      +

      Giving this the Deaf tag will prevent it from being pushable.

      +

       

      +
    +
  • +

    Linedef Types

    +

    Lines may have flags applied to them. The following is a reference of their values. + Unless specified otherwise in a line type, the flags behave as follows:

    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NAMEVALUEDESCRIPTION
    EFFECT61Special use flag #6.
    BLOCKMONSTERS2Prevents an enemy from crossing the line. May not work for especially + speedy enemies.
    TWOSIDED4Flag used to indicate if a line is two sided. Do not modify.
    DONTPEGTOP8Unpeg upper texture. Good for moving floors.
    DONTPEGBOTTOM16Unpeg bottom texture. Good for moving ceilings.
    EFFECT132Special use flag #1.
    NOCLIMB64Don't allow Knuckles to climb on this wall.
    EFFECT2128Special use flag #2.
    EFFECT3256Special use flag #3.
    EFFECT4512Special use flag #4.
    EFFECT51024Special use flag #5.
    NOSONIC2048Disable line special if playing as Sonic (Single Player Only).
    NOTAILS4096Disable line special if playing as Tails (Single Player Only).
    NOKNUX8192Disable line special if playing as Knuckles (Single Player Only).
    BOUNCY16384Bounce the player off this line.
    TFERLINE32768Use this on a FOF line special to define the texture & offsets for + each side of the FOF. The control sector must have at LEAST the same # of sides as the + target sector(s).
    +

    +
  • Level Parameters / Miscellany
      +

      1 - Per-Sector Gravity

      +

      Sets the gravity of the tagged sector or sectors, as a percentage of global gravity + (which can be set separately using sector type 176). The floor height + of the control sector is used. If it is 1000, then the target sector will have 100% + gravity. If it is 500, the target sector will have 50% of the global gravity. Negative + values work as well, but players can't jump down; they'll get stuck to the ceiling, unless + the NOCLIMB flag is checked.

      +

      You can apply this special to the control sector of an intangible FOF to change the + gravity only inside that FOF.

      +

      2 - Custom Exit

      +

      Tag this to an Exit Sector (type 8192) to exit to a custom level, + overriding the one set in the map header. The map number you go to is indicated by the + front sector's floor. Additionally, if the control linedef's bitset is set to disallow + climbing (with the NOCLIMB attribute, whose value is 64), skip the + score tally screen when switching to the new map.

      +

      If the control linedef has the BLOCKMONSTERS flag set, + this effect does something super complicated and fun, going to a different level depending + on whether the player has all emeralds or not. If the player has seven emeralds, the + linedef's front sector's ceiling height will be used. Otherwise, go to the map number + indicated by the linedef's front sector's floor. That's only if you set the BLOCKMONSTERS flag.

      +

      If the EFFECT4 flag is set, the linedef's front side x offset + will be used as the new gametype after the map change, providing it is in range (from 0 to + 4, inclusive).

      +

      3 - Zoom Tube Parameters

      +

      X length = speed. Y length = waypoint sequence #. See sector type 32768 + for more information.

      +

      4 - Speed Pad

      +

      Creates a speed pad. The linedef direction and indicates the direction of the pad. The + target sector must have type 1280 or 1536 for + this to work.

      +

      If the EFFECT4 flag is set, you will not be teleported to the + center of the sector when the speed pad is activated.

      +

      5 - Camera Scanner

      +

      Modifies camera position while the player is in the target sector. The floor and + ceiling of the control sector and the angle of the control linedef are the values for + CAM_HEIGHT, CAM_DIST, and CAM_ROTATE, respectively. Camera position is reset when the + player steps outside the sector.

      +

      6 - Disable Linedef

      +

      Disables any linedef specials that share the same tag. Will be used in the future to + check if a particular level has been previously cleared or not.

      +

      7 - Flat Alignment

      +

      Aligns floor and/or ceiling flats. The x alignment is specified by the control + linedef's x distance (the difference between the x values of its two vertices), and the y + alignment is specified by the control linedef's y distance.

      +

      By default, works on both the floor and ceiling (however, note that skies cannot be + "aligned" ;). Adding the NOCLIMB flag to the linedef will + align the floor only, while the BLOCKMONSTERS flag will make + it align the ceiling only.

      +

      8 - Sector Special Parameters

      +

      Sets special behavior of a sector's type depending on the flag(s) checked:

      +

      NOCLIMB - Special only operates when touching ceiling

      +

      EFFECT4 - Special operates when touching either the floor or the + ceiling

      +

      EFFECT3 - Special operates by just touching the sector, rather + than having to be inside of it.

      +

      9 - Chain Parameters

      +

      Sets special behavior of a moving chain as such:

      +

      x length - # of links on the chain

      +

      y length - Overall speed (0-15)

      +

      X offset - Rotation speed on the X axis (0-15)

      +

      Y offset - Rotation speed on the Z axis (0-15)

      +

      floorheight - angle to start at (0-15)

      +

      ceilingheight - maximum rotation speed

      +

      10 - Culling Plane

      +

      Set like line 1, this creates an invisible plane in the sector. If + your view is above this plane, lots of things drawn below the height of this plane will be + discarded, and if your view is below the plane, a lot of things drawn above the height of + the plane will be discarded. This is to tell the game to not draw stuff that you aren't + going to see anyway. Do note that the view doesn't have to be in the current sector, you + can also be viewing from the side, which may be undesirable. To prevent this problem, you + can check the NOCLIMB flag, which will allow you to 'group' a set + of sectors to one control sector in which the culling will only take effect. For example, + you have a control sector set up for culling, and have two culling lines in the control + sector, tagged to sectors 'A' and 'B'. If the player is in sector 'A' or 'B', the culling + will occur, but if the player is in sector 'C', it will not.

      +

      11 - Rope Hang Parameters

      +

      X length = speed. Y length = waypoint sequence #.

      +

      EFFECT1 - Don't wrap movement

      +

      See sector type 45056 for more information.

      +

      12 - Rock Spawn Parameters

      +

      Sets special behavior of a rock spawner (#1202) as such:

      +

      length - momentum strength

      +

      line angle - momentum angle

      +

      X offset - # of tics to wait until another is spawned

      +

      Y offset - Rock crumble sprite to use (0-15)

      +

      NOCLIMB - add some randomization to the momentum

      +

       

      +

      13 - Heat Wave

      +

      Applies a heat effect to the screen. Tag this to a sector, or to the control sector of a FOF.

      +

       

      +
    +
  • +
  • Level Parameters / Miscellany
      +

      20 - Marks first line in PolyObject

      +

      Explain here.

      +

      21 - Explicitly include a PolyObject line

      +

      Explain here.

      +

      30 - PolyObject Parameters

      +

      Explain here.

      +

       

      +
    +
  • +
  • Level-Load Effects
      +

      50 - Instant Floor Lower

      +

      Makes the floor instantly lower on level load to be at the same height as the lowest + floor of any bordering sector.

      +

      51 - Instant Ceiling Raise

      +

      Makes the ceiling instantly rise on level load to be the same height as the highest + ceiling of any bordering sector.

      +

      52 - Continuously Falling Sector

      +

      Requires two control sectors. Sector continuously falls until its ceiling reaches the + floor of the line's back sector, then returns to its original position and keeps falling. + Linedef length determines speed. Good for things like intermittently falling lava. If the NOCLIMB flag is set, it falls upwards, instead of downwards.

      +

      53 - Continuous Floor/Ceiling Mover

      +

      Must be a two-sided linedef, tagged to another sector on the map. The tagged sector's + floor and ceiling will move, first so that they're equal to the floor and ceiling of the + linedef's front sector, then so they're equal to the floor and ceiling of the linedef's + back sector, then the front sector again, and so on.

      +

      The speed of the movement is determined by the linedef's length and uses the same units + as linetype 60.

      +

      54 - Continuous Floor Mover

      +

      Like linetype 53, but only moves the floor, not the ceiling. Can be + used to replace floating platforms in some cases, where only the floor was desired to + move.

      +

      55 - Continuous Ceiling Mover

      +

      Like linetype 53, but only moves the ceiling, not the floor.

      +

      56 - Continuous Two-Speed Floor/Ceiling Mover

      +

      Must be a two-sided linedef, tagged to another sector on the map. The tagged sector's + floor and ceiling will move, first so that they're equal to the floor and ceiling of the + linedef's front sector, then so they're equal to the floor and ceiling of the linedef's + back sector, then the front sector again, and so on.

      +

      The speed of the movement is determined by the linedef's x distance (the first way, + towards the front sector) and y distance (the second way, towards the back sector), using + the same units as linetype 60.

      +

      Unlike linetype 53, this effect does not slow down when it reaches + the end of its movement. Instead, it changes instantly from going in one direction to + going in the other. It's designed for making more sophisticated crushers than the crusher + type allows (i.e. crushers with varying rise/crush speeds, FOF crushers, crushers with + different start points).

      +

      57 - Continuous Two-Speed Floor Mover

      +

      Like linetype 56, but only moves the floor, not the ceiling.

      +

      58 - Continuous Two-Speed Ceiling Mover

      +

      Like linetype 56, but only moves the ceiling, not the floor.

      +

      59 - Activate Floating Platform

      +

      This is used to make floating platforms (that move up and down) as well as moving + water. In fact, you can use this to make any type of block move vertically. The way it + works is somewhat confusing - You use three control sectors, all connected by at least one + linedef. Easiest thing to do is make three square sectors together in a row. One of the + linedefs on the middle sector should contain the Floor Over Floor line special that you + want. This will be the Floor Over Floor control sector. The other two sectors represent + the bottommost position you want the Floor Over Floor to reach, and the topmost position + you want the Floor Over Floor to reach. The 59 line can be on any of these sectors, as + long as you tag it to the middle one. If you still don't understand, look at Greenflower + Zone Act 2. If the NOCLIMB flag is set, the platform will begin + moving upwards, rather than downwards.

      +

      60 - Activate Floating Platform (Adjustable Speed)

      +

      Speed is indicated by linedef length; one unit of speed here is 0.25 fracunits per tic. + (Floating platforms made with type 59 move at 2 fracunits per tic.) + Aside from the linedef length controlling speed, works exactly like linedef type 59.

      +

      61 - Crusher 1 (Ceiling to Floor)

      +

      The crush motion is from the ceiling to the floor. Linedef length indicates crusher + speed. See also linetype 62, Crusher 2.

      +

      62 - Crusher 2 (Floor to Ceiling)

      +

      Like linetype 61, Crusher 1, except that it starts in a different + place, not synchronised with any crushers that use the Crusher 1 type. The highest ceiling + this crusher reaches will be the highest ceiling height of any bordering sector.

      +

      63 - Fake Floor

      +

      Creates two fake planes, fake floor and fake ceiling. Main textures are not affected, + but as far as above/below textures and floor/ceiling flats are concerned, the floor and + ceiling height are those of the control sector. As far as collisions, walking, etc. are + concerned, the floor and ceiling flats are whatever they normally would be.

      +

      Fake floor is useful for railings (THZRAIL and WOODRAIL; see THZ2 for examples) and + snow effects (making a fake floor of snow just a few units above normal floor, so it looks + like the player's feet are buried in the snow).

      +

      64 - Appearing/Disappearing FOF

      +

      Tag this to any FOF line and this will cause it to appear and disappear + intermittently. The line's X length is the amount of time (in tics) that the FOF will + appear, and Y length is the amount of time (in tics) that the FOF will disappear. The + control sector's floor height allows you to specify an offset (in tics) of how much time + will pass before the appearing/disappearing kicks in.

      +

       

      +
    +
  • +
  • Floor-Over-Floors (FOFs)
      +

      100 - Floor Over Floor: Solid, Opaque, Shadowcasting

      +

      This is just a regular old FOF. As with any block, the ceiling of the control sector is + the top of the block, and the floor of the control sector is the bottom. + "Shadowcasting" means that the light value used in the control sector is used + for the area below where the actual FOF appears, as opposed to above it.

      + +

      101 - Floor Over Floor: Solid, Opaque, Non-Shadowcasting

      +

      See notes for 100. "Non-shadowcasting" means that the + light value you set in the control sector will be used for the area above the FOF, instead + of below it.

      + +

      102 - Floor Over Floor: Solid, Translucent

      +

      Useful for windows. The GLASSTEX texture is good for this purpose. You can change the + alpha value of the translucency by setting the control linedef's Above texture to a # + followed by a three-digit decimal number, 000 to 255. #000 is most transparent, #255 is + most opaque. Note that in software mode, there are actually only ten different values that + serve as a 'best guess'.

      + +

      103 - Floor Over Floor: Solid, Sides Only

      +

      A solid FOF that renders sides only, not planes (floor and ceiling). You were supposed + to be able to use it to place railings (THZRAIL, WOODRAIL, etc.) on FOFs. It doesn't work + for that, because the railings use a different kind of transparency and software mode + won't draw them on FOFs. So this one is going on the list of useless effects, right next + to linetype 104.

      + +

      104 - Floor Over Floor: Solid, No Sides

      +

      Like a 3D floor of type 101, except that sides are not drawn. + Supposedly a little bit faster than a normal 3D floor. You can use it when the sides + wouldn't be visible anyway.

      +

      This type of 3D floor will have shadows if and only if you set the control linedef's NOCLIMB flag.

      + +

      105 - Floor Over Floor: Solid, Invisible

      +

      For making invisible walls and other strange effects.

      + +
      +

      120 - Floor Over Floor: Water, Opaque

      +

      This one looks exactly like linetype 100 ingame, but is a block of + water instead of solid.

      +

      The block will have the attribute of linetype 200 if the NOCLIMB flag is set.

      +

      To use the light level of the target sector, utilize the EFFECT4 + flag.

      +

      If this is used as lava (Fire Damage), and you set the BLOCKMONSTERS + flag, you can still pass through the lava.

      + +

      121 - Floor Over Floor: Water, Translucent

      +

      This one looks exactly like linetype 102 ingame, but is a block of + water instead of solid.

      +

      The block will have the attribute of linetype 200 if the NOCLIMB flag is set.

      +

      To use the light level of the target sector, utilize the EFFECT4 + flag.

      +

      If this is used as lava (Fire Damage), and you set the BLOCKMONSTERS + flag, you can still pass through the lava.

      + +

      122 - Floor Over Floor: Water, Opaque, No Sides

      +

      Like linetype 120, but doesn't render sides.

      +

      The block will have the attribute of linetype 200 if the NOCLIMB flag is set.

      +

      To use the light level of the target sector, utilize the EFFECT4 + flag.

      +

      If this is used as lava (Fire Damage), and you set the BLOCKMONSTERS + flag, you can still pass through the lava.

      + +

      123 - Floor Over Floor: Water, Translucent, No Sides

      +

      Like linetype 121, but doesn't render sides. Most of the time this + won't make a difference. It can be useful, however, for windows that have water on one + side and not on the other.

      +

      The block will have the attribute of linetype 200 if the NOCLIMB flag is set.

      +

      To use the light level of the target sector, utilize the EFFECT4 + flag.

      +

      If this is used as lava (Fire Damage), and you set the BLOCKMONSTERS + flag, you can still pass through the lava.

      + +
      +

      140 - Floor Over Floor: Intangible from Bottom, Opaque

      +

      This sector type is solid from the top and walls, but is not solid from the bottom. + This allows the designer to create one-way passages as well as simulate 2D design by + having platforms that players can jump up to from below.

      +

      This type of 3D floor will have shadows unless you set the control linedef's NOCLIMB flag.

      + +

      141 - Floor Over Floor: Intangible from Bottom, Translucent

      +

      A copy of linetype 140 that is also translucent.

      + +

      142 - Floor Over Floor: Intangible from Bottom, Translucent, No + Sides

      +

      A platform you can jump up through, like linetype 140 (and decides + the same way whether to have shadows or not), with translucency and that doesn't render + sides. Alpha value supported the same way as linetype 102.

      + +
      +

      150 - Floor Over Floor: Bobbing (Air)

      +

      FOF that moves down 16 units when you step on, then returns to its former position when + you step off. The control sector must be connected to another sector with the same floor + and ceiling height. This seemingly redundant sector is used for resetting the heights. (If + you forget to put it in, the bobbing floor when stepped on will go down, keep going down, + and never stop or come back up.) See also linetypes 151 and 152. This linedef is obsolete. Please use linetype 190-195.

      + +

      151 - Floor Over Floor: Adjustable Bobbing (Air)

      +

      Like linetype 150, except that instead of the floor moving down 16 + units when you step on it, it moves down the number of units of the control linedef's + length. This linedef is obsolete. Please use linetype 190-195.

      + +

      152 - Floor Over Floor: Reverse Bobbing (Air)

      +

      Like linetype 151, except in reverse. The platform goes up + when you step on it and back down when you step off. This linedef is obsolete. + Please use linetype 190-195.

      + +
      +

      160 - Floor Over Floor: Floating, Bobbing

      +

      Bobs and floats in water. The floating part means that if the water moves or rises, + this platform will rise with it.

      + +
      +

      170 - Floor Over Floor: Crumbling (Respawn)

      +

      Crumbles and falls away, then reappears 15 seconds later.

      + +

      171 - Floor Over Floor: Crumbling (No Respawn)

      +

      Crumbles and falls away and never comes back.

      + +

      172 - Floor Over Floor: Crumbling (Respawn)

      +

      A copy of linetype 140 that also crumbles when stood on and + reappears after 15 seconds.

      + +

      173 - Floor Over Floor: Crumbling (No Respawn)

      +

      A copy of linetype 172 that stays gone forever after crumbling.

      + +

      174 - Floor Over Floor: Intangible from Bottom, Crumbling + (Respawn), Translucent

      +

      A copy of linetype 141 that also crumbles when stood on and + reappears after 15 seconds.

      + +

      175 - Floor Over Floor: Intangible from Bottom, Crumbling (No + Respawn), Translucent

      +

      A copy of linetype 174 that stays gone forever after crumbling.

      + +

      176 - Floor Over Floor: Crumbling (Respawn), Floating, Bobbing

      +

      Crumbles and falls, then floats on water, then bobs when you step on it.

      + +

      177 - Floor Over Floor: Crumbling (No Respawn), Floating, Bobbing

      +

      Crumbles and falls, then floats on water, then bobs when you step on it. Unlike + linetype 176, does not return to its former position.

      + +

      178 - Floor Over Floor: Crumbling (Respawn), Floating

      +

      Crumbles and falls, then floats on water, then reappears up in the air 15 seconds + later.

      + +

      179 - Floor Over Floor: Crumbling (No Respawn), Floating

      +

      Crumbles and falls, then spends the rest of its days floating on water, never to + reappear up in the air.

      + +

      180 - Floor Over Floor: Crumbling (Respawn), Bobbing (Air)

      +

      Bobs, crumbles, and falls when stepped on.

      + +
      +

      190 - Floor Over Floor: Rising Platform, Solid, Opaque, + Shadowcasting

      +

      Just like 100, except when a player steps on it, it will rise up to + the control sector's highest adjacent sector. You set the control sectors for this up like + special 59. Linedef length controls speed like 60. + If the NOCLIMB flag is set, it will require the player to spindash + to raise the platform.

      +

      191 - Floor Over Floor: Rising Platform, Solid, Opaque, + Non-Shadowcasting

      +

      Just like 101, except when a player steps on it, it will rise up to + the control sector's highest adjacent sector. You set the control sectors for this up like + special 59. Linedef length controls speed like 60. + If the NOCLIMB flag is set, it will require the player to spindash + to raise the platform.

      +

      192 - Floor Over Floor: Rising Platform, Solid, Translucent

      +

      Just like 102, except when a player steps on it, it will rise up to + the control sector's highest adjacent sector. You set the control sectors for this up like + special 59. Linedef length controls speed like 60. + If the NOCLIMB flag is set, it will require the player to spindash + to raise the platform.

      +

      193 - Floor Over Floor: Rising Platform, Solid, Invisible

      +

      Just like 105, except when a player steps on it, it will rise up to + the control sector's highest adjacent sector. You set the control sectors for this up like + special 59. Linedef length controls speed like 60. + If the NOCLIMB flag is set, it will require the player to spindash + to raise the platform.

      +

      194 - Floor Over Floor: Rising Platform, Intangible from Bottom, + Opaque

      +

      Just like 140, except when a player steps on it, it will rise up to + the control sector's highest adjacent sector. You set the control sectors for this up like + special 59. Linedef length controls speed like 60. + If the NOCLIMB flag is set, it will require the player to spindash + to raise the platform.

      +

      195 - Floor Over Floor: Rising Platform, Intangible from Bottom, + Translucent

      +

      Just like 141, except when a player steps on it, it will rise up to + the control sector's highest adjacent sector. You set the control sectors for this up like + special 59. Linedef length controls speed like 60. + If the NOCLIMB flag is set, it will require the player to spindash + to raise the platform.

      +
      +

      200 - Floor Over Floor: Light Block

      +

      Like a half light block, but it's really an actual block. That is, the light only comes + down to the control sector's floor, not to the bottom of the level (as with linetype 201.

      + +

      201 - Floor Over Floor: Half Light Block

      +

      Light blocks can be used to set color maps and light values. The light value of the + control sector will be used and any colormap attached to it will be used also. Note that + only the ceiling of the control sector is used; the light goes all the way down to the + bottom of the level. If this isn't what you want, consider using linedef type 200 instead.

      + +

      202 - Floor Over Floor: Fog Block

      +

      Creates a block of colored fog. Attach a colormap (linetype 606) to + the control sector for the fog block; otherwise you won't see anything out of the + ordinary.

      + +
      +

      220 - Floor Over Floor: Intangible, Opaque

      +

      Like opaque water, but not swimmable. Good for a snow effect on + FOFs. Can also be used to make hidden rooms, like you would normally do by setting a Main + texture.

      + +

      221 - Floor Over Floor: Intangible, Translucent

      +

      See linedef type 102 for how to adjust the translucency, making the + 3D floor more transparent or more opaque.

      +

      This type of 3D floor will have shadows if and only if you set the control linedef's NOCLIMB flag.

      + +

      222 - Floor Over Floor: Intangible, Sides Only

      +

      An intangible FOF that renders sides only, not planes (floor and ceiling). It renders + both inside sides and outside sides. You can use it to place sector borders (GFZGRASS, + etc.) on FOFs.

      + +

      223 - Floor Over Floor: Intangible, Invisible

      +

      Useful for setting effects, such as wind and gravity.

      + +
      +

      250 - Floor Over Floor: Mario Block

      +

      Like a normal FOF, except that the control linedef's Above texture is used after the + block has been hit (the Main texture is used before this). Any things in the control + sector will pop out the top of the block in the order in which they were placed. Rings + will be obtained and the effects of monitors will begin as soon as the block has been hit.

      + +

      251 - Floor Over Floor: Thwomp Block

      +

      The thwomps are the crazy platforms with faces in Mario Koopa Blast 3. They can crush + you, but you can also ride on them.

      +

      Control sector is set up like a normal FOF. When a player steps + underneath the thwomp, it will crush down to the floor. You don't need to tell it where + the floor is. It knows.

      + +

      252 - Floor Over Floor: Shatter Block

      +

      Like the bustable block, linetype 254, except that it shatters on + any sort of contact, whether it's a spindash or not (and whether you're Knuckles or not).

      +

      If the NOCLIMB flag is set, the block is only shatterable from + the bottom, like some things you spring up and break in Launch Base Zone from Sonic 3.

      + +

      253 - Floor Over Floor: Shatter Block, Translucent

      +

      Translucent version of 252 supporting alpha values.

      + +

      254 - Floor Over Floor: Bustable Block

      +

      Bustable blocks can be destroyed by spindashing. Additionally, Knuckles can destroy + them by walking or jumping into them, since he is very strong. If the NOCLIMB + flag is set, only Knuckles can break the block.

      + +

      255 - Floor Over Floor: Spin Bust Block

      +

      Like the bustable block, linetype 254, set off in a different way. + To break, jump onto it or fall down onto it while spinning. Similar to blocks found in + Marble Zone, as well as the ice cubes that would encase buttons and monitors in parts of + Ice Cap Zone.

      + +

      256 - Floor Over Floor: Spin Bust Block, Translucent

      +

      Translucent version of 255 supporting alpha values.

      +

      257 - Floor Over Floor: Quicksand Block

      +

      It's set up like any block. You can, of course, sink and die in it. X length of the + linedef determines sink speed, Y length determines how "sludgy" movement in the + quicksand is.

      + +

      258 - Floor Over Floor: Laser Block

      +

      Creates a blinking FOF that zaps you if you touch it. You can set the flats and texture + to whatever you want. For a red laser like in THZ2, use REDFLR for the flats and REDWALL + for the texture.

      +

      You can also make other colors using BLUEFLR/BLUWALL (blue laser), GREENFLR/GRNWALL + (green laser), and YELFLR/YELWALL (yellow laser). Of course, those colors of lasers are + very expensive, so Eggman doesn't have nearly as many of them. He usually goes with the + cheap red lasers.

      + +

      259 - Floor Over Floor: Custom

      +

      Place the appropriate flag values in hex (do not include the 0x in front of it) in the + line's UPPER TEXTURE field on the 2nd side of the linedef.

      +
    +
  • +
  • Linedef Executor Triggers
      +

      300 - Trigger Linedef Executor (Continuous)

      +

      Triggers linedef executor in the control sector when a player touches the tagged + sector's floor or steps in the sector (depending on the sector special used). The linedef + executor will keep being triggered over and over again as long as a player is there, hence + the word "continuous" in this linetype's name. Tagged sector must have one of + the Trigger Linedef Executor types for this to work.

      +

      301 - Trigger Linedef Executor (Each Time)

      +

      Like 300, except that it only gets triggered once for each time you + fall or jump onto the floor. Tagged sector must have one of the Trigger + Linedef Executor types for this to work.

      +

      302 - Trigger Linedef Executor (Once)

      +

      Like 300, except that after that linedef executor executes its + linedefs, it's done. It's over. The linedefs will never be executed again.

      +

      303 - Trigger Linedef Executor (Ring Count - Continuous)

      +

      Triggers linedef executor in the control sector when a player touches the tagged + sector's floor or steps in the sector (depending on the sector special used). The linedef + executor will keep being triggered over and over again as long as a player is there, hence + the word "continuous" in this linetype's name. Tagged sector must have one of + the Trigger Linedef Executor types for this to work. Executor will be + triggered depending on how many rings the player has:

      +

      No flags -> Runs if (rings = line length)

      +

      NOCLIMB -> Runs if (rings <= line length)

      +

      BLOCKMONSTERS -> Runs if (rings >= line length)

      +

      EFFECT4 -> Takes the rings of ALL players into account.

      +

      304 - Trigger Linedef Executor (Ring Count - Once)

      +

      Like 303, except that after that linedef executor executes its + linedefs, it's done. It's over. The linedefs will never be executed again.

      +

      305 - Trigger Linedef Executor (Character Ability - Once)

      +

      Like linetype 302, but is only activated when the character's + ability number matches the linedef length by multiples of 10. For example:

      +

      0-9 = Charability 0

      +

      10-19 = Charability 1

      +

      20-29 = Charability 2

      +

      etc...

      +

      306 - Trigger Linedef Executor (Character Ability - Continuous)

      +

      Like 300, but only triggers when the character's ability number + matches the linedef length by multiples of 10. See linetype 305 for a + futher description.

      +

      307 - Trigger Linedef Executor (Character Ability - Each Time)

      +

      Like 301, but only triggers when the character's ability number + matches the linedef length by multiples of 10. See linetype 305 for a + futher description.

      +

      308 - Trigger Linedef Executor (Race Only, Once)

      +

      Like linetype 302, but is only activated when the gametype is Race. + Useful for doing things like opening doors, pre-solving puzzles, etc. to make race + smoother.

      +

      309 - Trigger Linedef Executor (CTF Red Team - Continuous)

      +

      Like 300, but only triggers if you are in CTF and on the red team.

      +

      310 - Trigger Linedef Executor (CTF Red Team - Each Time)

      +

      Like 301, but only triggers if you are in CTF and on the red team.

      +

      311 - Trigger Linedef Executor (CTF Blue Team - Continuous)

      +

      Like 300, but only triggers if you are in CTF and on the blue team.

      +

      312 - Trigger Linedef Executor (CTF Blue Team - Each Time)

      +

      Like 301, but only triggers if you are in CTF and on the blue team.

      +

      313 - Trigger Linedef Executor (No More Enemies - Once)

      +

      Like linetype 302, but is only activated when no more objects of + type MF_ENEMY exist in its tagged area. Think "destroy all enemies in this room for + the door to open to go to the next room". Tag this to a control sector. It will go + through the lines of the control sector, checking for any lines of type 223 + and checking inside the area occupied by the invisible intangible FOF to see if any + enemies exist. If no alive enemies are in all of the type 223 FOFs, + the linedef executor is run once. The line length is the tag number of the linedef + executor trigger to run.

      +

      314 - Trigger Linedef Executor (# of Pushables - Continuous)

      +

      Like 300, but only triggers if the number of pushable objects in + the sector compared to the line length is:

      +

      No flags -> Runs if (# pushables = line length)

      +

      NOCLIMB -> Runs if (# pushables >= line length)

      +

      EFFECT4 -> Runs if (# pushables < line length)

      +

      315 - Trigger Linedef Executor (# of Pushables - Once)

      +

      Like 314, but only triggers once.

      +

      316 - Trigger Linedef Executor (PolyObject - Land On)

      +

      This will trigger every time you land on the polyobject. Line's tag # is 32000 + the + PolyObject ID #. You must also flag the PolyObject Start (#20) line with NOCLIMB to tell the game it has a linedef executor associated with it.

      +

      So if you had a PolyObject with an ID of 1, this line would have a tag of 32001.

      +

       

      +
    +
  • +
  • Linedef Executor Options
      +

      400 - Linedef Executor: Set Tagged Sector's Floor Height/Pic

      +

      When executed, instantly changes the tagged sector's floor height and flat to the floor + height and flat of the linedef's front sector.

      +

      401 - Linedef Executor: Set Tagged Sector's Ceiling Height/Pic

      +

      When executed, instantly changes the tagged sector's ceiling height and flat to the + ceiling height and flat of the linedef's front sector.

      +

      402 - Linedef Executor: Set Tagged Sector's Light Level

      +

      When executed, instantly changes the tagged sector's light level to that of the + linedef's front sector. Floor and ceiling light settings done with linetypes 601 and 600 are transferred as well; colormaps are + not.

      +

      If there is a lighting effect active in the target sector or sectors at the time (glow, + fade, strobe, flicker), it will be stopped.

      +

      403 - Linedef Executor: Move Tagged Sector's Floor

      +

      When executed, starts moving the tagged sector's floor until it is at the same height + as the linedef's front sector's floor. Speed is indicated in the same units used by + linetype 60.

      +

      If the line used has NOCLIMB flag, the floor flat will change + after the move, to that on the front sector's floor. This is like what linetype 400 does.

      +

      If the line used has BLOCKMONSTERS flag, another linedef + executor will be run when the floor movement is finished. (If multiple sectors finish at + different times, it goes by the lowest numbered sector, but you should probably try to + avoid this scenario.) The tag of the new linedef executor to run is specified by the X + alignment on the front side of the line. The tag number you use must be positive, and this + functionality cannot be combined with changing the floor flat using the NOCLIMB + flag. Running a linedef executor will take precedence over changing the floor flat.

      +

      404 - Linedef Executor: Move Tagged Sector's Ceiling

      +

      When executed, starts moving the tagged sector's ceiling until it is at the same height + as the linedef's front sector's ceiling. Speed is indicated in the same units used by + linetype 60.

      +

      If the line used has NOCLIMB flag, the ceiling flat will change + after the move, to that on the front sector's ceiling. This is like what linetype 401 does.

      +

      If the line used has BLOCKMONSTERS flag, another linedef + executor will be run when the ceiling movement is finished. (If multiple sectors finish at + different times, it goes by the lowest numbered sector, but you should probably try to + avoid this scenario.) The tag of the new linedef executor to run is specified by the X + alignment on the front side of the line. The tag number you use must be positive, and this + functionality cannot be combined with changing the ceiling flat using the NOCLIMB flag. Running a linedef executor will take precedence over + changing the ceiling flat.

      +

      405 - Linedef Executor: Lower Floor by Line

      +

      Speed is indicated by x distance; amount to lower is indicated by y distance.

      +

      406 - Linedef Executor: Raise Floor by Line

      +

      Speed is indicated by x distance; amount to raise is indicated by y distance.

      +

      407 - Linedef Executor: Lower Ceiling by Line

      +

      Speed is indicated by x distance; amount to lower is indicated by y distance.

      +

      408 - Linedef Executor: Raise Ceiling by Line

      +

      Speed is indicated by x distance; amount to raise is indicated by y distance.

      +

      409 - Linedef Executor: Change Calling Sector's Tag

      +

      Changes the tag of the calling sector; that is, the sector on the map that activated + this linedef executor. The new tag is the linedef's length.

      +

      410 - Linedef Executor: Change Front Sector's Tag

      +

      Changes the tag of the linedef's front sector. The new tag is the linedef's length.

      +

      411 - Linedef Executor: Stop Plane Movement

      +

      Stops any and all floor, ceiling, or elevator movement in the tagged sector or sectors.

      +

      412 - Linedef Executor: Teleport Player to Tagged Sector

      +

      The player who triggered the linedef executor will be teleported to the tagged sector. + The player's exact X, Y, Z, and angle are determined by a teleport destination thing, type + 751, somewhere in the tagged sector.

      +

      If the BLOCKMONSTERS flag is used, it won't flash and make + the teleport sound effects. If the NOCLIMB flag is used, it won't + reset the angle to the angle of the teleport destination thing, and if the EFFECT4 flag is used, it will not kill your acceleration/speed upon + teleport.

      +

      413 - Linedef Executor: Change Music

      +

      Linedef length indicates the music slot to use. If the linedef's NOCLIMB + flag is set, play the music once, otherwise loop it.

      +

      If the player dies and goes back to a starpost, the beginning of the level, or the + appropriate multiplayer start, the map music from before will be restored. The linedef + flag BLOCKMONSTERS can be set to change this behavior, and + retain the new music even after dying.

      +

      If the linedef length isn't a valid music slot, the music is stopped.

      +

      414 - Linedef Executor: Play SFX

      +

      Plays a sound effect. The line length is the sound number to use. The list of sound + effects can be found in sounds.h. The origin of the sound depends on which linedef flags + are set:

        +
      • NOCLIMB : The sound is played from nowhere, but only for the + player who triggered it.
      • +
      • EFFECT4: The sound is played from nowhere for everyone.
      • +
      • BLOCKMONSTERS: The sound is played from the center of the + sector that triggered the linedef executor.
      • +
      +

      Otherwise, the sound is played from the location of the player or thing who triggered + it.

      +

      415 - Linedef Executor: Run Script

      +

      Runs a script, the same kind of script you can run on level load with the level header + scriptname attribute. The script that will be run should have a lumpname of the form SCRxxyyy, + where xx is the two-digit map number and yyy is the linedef's sector's floor + height in decimal, with leading zeroes as necessary (or 000 if the floor height exceeds + 999 fracunits). For instance, if the linedef is in MAP31 and the floor of its sector is + 337 fracunits, the script named SCR31337 will be run.

      +

      416 - Linedef Executor: Start Adjustable Fire Flicker

      +

      Essentially a copy of linetype 603 that waits to activate until the + linedef executor is triggered. It does have an extra feature, though. If you use a + two-sided linedef with the NOCLIMB flag, the linedef's back sector + will be used as the maximum light level, allowing you to set the target sector (or + sectors) at a different starting light level entirely.

      +

      417 - Linedef Executor: Start Adjustable Glowing Light

      +

      Essentially a copy of linetype 602 that waits to activate until the + linedef executor is triggered. It does have an extra feature, though. If you use a + two-sided linedef with the NOCLIMB flag, the linedef's back sector + will be used as the maximum light level, allowing you to set the target sector (or + sectors) at a different starting light level entirely.

      +

      418 - Linedef Executor: Start Adjustable Blinking Light + (unsynchronized)

      +

      Essentially a copy of linetype 604 that waits to activate until the + linedef executor is triggered. It does have an extra feature, though. If you use a + two-sided linedef with the NOCLIMB flag, the linedef's back sector + will be used as the maximum light level, allowing you to set the target sector (or + sectors) at a different starting light level entirely.

      +

      419 - Linedef Executor: Start Adjustable Blinking Light + (synchronized)

      +

      Essentially a copy of linetype 605 that waits to activate until the + linedef executor is triggered. It does have an extra feature, though. If you use a + two-sided linedef with the NOCLIMB flag, the linedef's back sector + will be used as the maximum light level, allowing you to set the target sector (or + sectors) at a different starting light level entirely.

      +

      420 - Linedef Executor: Fade Light Level

      +

      When executed, gradually fades the tagged sector's light level to that of the linedef's + front sector. Floor and ceiling light settings done with linetypes 601 + and 600 are not affected or used.

      +

      If there is a lighting effect already active in the target sector or sectors at the + time (glow, other fade, strobe, flicker), it will be halted in favor of this one.

      +

      Linedef length in fracunits indicates speed. Fading from 224 to 64 with a linedef + length of 4 will take 40 fracunits (224 - 64 = 160, 160 / 4 = 40). There are 35 fracunits + in a second.

      +

      421 - Linedef Executor: Stop Lighting Effect

      +

      Stops any lighting effects active in the tagged sector or sectors: glow, fade, strobe, + flicker, etc. The light level, whatever it is at the moment this script line is run, will + be preserved until a new lighting effect or light level change is used.

      +

      Note that the lighting effects will all stop other lighting effects when activated. In + other words, you only need to use this when you really want the lighting effect to stop, + not when you want one effect to stop and another to start.

      +

      422 - Linedef Executor: Cut-Away View

      +

      Cuts away to a view from a different place for a moment. Only works for linedef + executors triggered by a player. Tag the line to a sector with an alt view thing (map + thing type 5007) in it at the proper location with the proper Z and angle. The line length + indicates how long to stay in this view, in tics.

      +

      By giving the linedef a NOCLIMB flag, you can adjust the + vertical viewing angle from the cut-away view. Set the x offset on the linedef's front + side to an integer -90 to 90. In software mode the range of viewing angles is actually + about -68 to 68. This is in degrees.

      +

      423 - Linedef Executor: Change Sky

      +

      Changes sky to the # of the control sector's floorheight. This only affects the player + who activates it. If you'd like it to affect all players, make sure you check the NOCLIMB flag.

      +

      424 - Linedef Executor: Change Weather

      +

      Changes weather to the control sector's floorheight in powers of 10.

      +

      Example:

      +
      + + + + + + + + + + + + + + + + + + + + +
      Linedef LengthWeather Type
      10None
      20Snow
      30Rain
      40Storm
      +

      (higher numbers reserved for future use)

      +

      This only affects the player who activates it. If you'd like it to affect all players, + make sure you check the NOCLIMB flag.

      +

      425 - Linedef Executor: Change Object State

      +

      Changes the animation frame of the activating object to the state # indicated by the + length of the control linedef. Be careful how you use this.

      +

      426 - Linedef Executor: Stop Object

      +

      Makes the object that triggered the linedef executor stop moving, after being sent to + the center of the sector it's in (only if NOCLIMB flag is set), on + the floor. Although it comes to a complete stop, the object can begin moving right away + again. If the object is a player, the player will stop jumping, spinning, or anything + else.

      +

      427 - Linedef Executor: Award Score

      +

      Adds to the score of the player who activated it. Control sector's floorheight = points + to award. This even works with negative values.

      +

      428 - Linedef Executor: Start Platform Movement

      +

      Starts a moving platform in the nature of linetype 59 or 60. If the NOCLIMB flag is set, the platform will + begin moving upwards. Otherwise, it will start moving downwards. Speed of movement is set + just like with linetype 60.

      +

      429 - Linedef Executor: Crush Ceiling Once

      +

      Ceiling moves down to the floor, then back up. Speed is determined by line length - + every 16 units equals 1 FRACUNIT/tic.

      +

      430 - Linedef Executor: Crush Floor Once

      +

      Floor moves up to the ceiling, then back down. Speed is determined by line length - + every 16 units equals 1 FRACUNIT/tic.

      +

      431 - Linedef Executor: Crush Floor And Ceiling Once

      +

      Floor and ceiling meet in the middle and then return, sandwiching anything that's + inbetween. Speed is determined by line length - every 16 units equals 1 FRACUNIT/tic.

      +

      432 - Linedef Executor: Enable 2D Mode

      +

      Turns on 2D mode within the level. You'll probably only want to use this with a zoom + tube or teleport to guarantee that the player is in the correct position when it switches.

      +

      433 - Linedef Executor: Disable 2D Mode

      +

      Turns off 2D mode within the level.

      +

      434 - Linedef Executor: Award Custom Power

      +

      Awards (or removes!) a power to the calling player.

      +

      X length: Power Index + 1

      +

      Y length: Power Duration (in 35ths of a second)

      +

      435 - Linedef Executor: Change Scroller Direction

      +

      Changes direction of a scroller (conveyor, texture). Also changes speed if this is not + an accelerative/displacement scroller.

      +

      436 - Linedef Executor: Shatter Block

      +

      Shatters a FOF - of any type. Parameters are as follows:

      +

      Texture X Offset: Tag # of FOF target sector

      +

      Texture Y Offset: Tag # of FOF control sector

      +

      Note that the FOF should only have one target sector.

      +

      437 - Linedef Executor: Disable Player Control

      +

      Disables the controls of the player that triggered the linedef executor. If the + NOCLIMB flag is set, they will be able to jump, however.

      +

      Giving the front texture of the linedef an X offset will make the effect last that amount + of time, in tics. Otherwise, it ends immediately, so you would need to use a continuous + trigger.

      +

      438 - Linedef Executor: Set Object's Scale

      +

      Length of this line determines the scale size of an object, in percentage. Note that there is a max of 400%.

      +

      450 - Linedef Executor: Execute Linedef Executor

      +

      Just what it says. Can be used for recursion. Be careful, because you CAN make a loop + out of this that will freeze the game.

      +

      Tag is the linedef executor trigger tag to run.

      +

      488 - Linedef Executor: PolyObject - Move by Waypoints

      +

      Moves a polyobject along a sequence of Zoom Tube waypoints.

      +

      Texture X offset: Speed (8 = 1 FRACUNIT).

      +

      Texture Y offset: Sequence # of Zoom Tube waypoints.

      +

      The movement also depends on which linedef flags are set:

        +
      • EFFECT1 : Moves from highest waypoint # to lowest waypoint #.
      • +
      • EFFECT2 : Comes back the way it came when the end is reached.
      • +
      • EFFECT3 : Wrap around the waypoints.
      • +
      • EFFECT4:  Continuously move (used with EFFECT2 or EFFECT3).
      • +
      +

       

      +
    +
  • +
  • Scrollers / Pushers
      +

      500 - Scroll Wall First Side Left

      +

      501 - Scroll Wall First Side Opposite Direction

      +

      502 - Scroll Wall According to Linedef

      +

      503 - Acc Scroll Wall According to Linedef

      +

      Accelerative scrolling version of 502.

      +

      504 - Disp Scroll Wall According to Linedef

      +

      Displacement scrolling version of 502.

      +

      505 - Scroll Texture by Offsets

      +
      +

      510 - Scroll Floor Texture

      +

      Linedef length and direction indicate speed and direction.

      +

      511 - Acc Scroll Floor Texture

      +

      Accelerative scrolling version of 510.

      +

      512 - Disp Scroll Floor Texture

      +

      Displacement scrolling version of 510.

      +

      513 - Scroll Ceiling Texture

      +

      Linedef length and direction indicate speed and direction.

      +

      514 - Acc Scroll Ceiling Texture

      +

      Accelerative scrolling version of 513.

      +

      515 - Disp Scroll Ceiling Texture

      +

      Displacement scrolling version of 513.

      +
      +

      520 - Carry Objects on Floor

      +

      Like linedef type 530, without scrolling the floor texture, so the + floor doesn't look like it's moving.

      +

      521 - Acc Carry Objects on Floor

      +

      Accelerative scrolling version of 520.

      +

      522 - Disp Carry Objects on Floor

      +

      Displacement scrolling version of 520.

      +

      523 - Carry Objects on Ceiling

      +

      For FOF conveyor belts. Like 533, except without the scrolling to + accompany it.

      +

      524 - Acc Carry Objects on Ceiling

      +

      Accelerative scrolling version of 523. Untested.

      +

      525 - Disp Carry Objects on Ceiling

      +

      Displacement scrolling version of 523. Untested.

      +
      +

      530 - Scroll Floor Texture and Carry Objects

      +

      Used for conveyor belts, in conjunction with sector type 1024 + (Conveyor Belt). Linedef length and direction indicate conveyor speed and direction, + respectively. This can also be used to convey items on the underneath of a FOF. See Egg + Rock Zone for an example.

      +

      531 - Acc Scroll Floor Texture and Carry Objects

      +

      Accelerative scrolling version of 530.

      +

      532 - Disp Scroll Floor Texture and Carry Objects

      +

      Displacement scrolling version of 530.

      +

      533 - Scroll Ceiling Texture and Carry Objects

      +

      For conveyor belts on the top of FOFs, or for conveying items on a ceiling. Tag this to + the FOF control sector and give the FOF control sector a type of 1024, + Conveyor Belt. For realism you might also want to scroll the control sector's floor + texture in the opposite direction (see linetype 510).

      +

      534 - Acc Scroll Ceiling Texture and Carry Objects

      +

      Accelerative scrolling version of 533. Untested.

      +

      535 - Disp Scroll Ceiling Texture and Carry Objects

      +

      Displacement scrolling version of 533. Untested.

      +
      +

      540 - Friction

      +

      Linedef lengths greater than 100 indicate slippery ice, while linedef lengths less than + 100 can be used for sludge, with extra friction.

      +

      If you want friction on a FOF, tag this line to the control sector of the FOF. + Otherwise, tag it to the sector of desired destination.

      +

      541 - Wind

      +

      Speed and direction are indicated by linedef length and direction. The target sector + should be of type 512, Wind/Current. If being used in a 3D Floor, put + the 512/768 sector type in the control sector, not the target sector. Also tag the line to + the control sector, and not the target sector.

      +

      Special flags:

      +

      NOCLIMB -> Only this pusher will affect the object - the + object can't have multiple 'pushings' due to being on the edge of a sector, etc.

      +

      EFFECT4 -> Player will go into slide with limited control + (similar to the water and oil slides in Labyrinth and Oil Ocean).

      +

      542 - Upwards Wind

      +

      The length of the linedef is the wind speed. The target sector will need type 512 or 768. If being used in a 3D Floor, put the + 512/768 sector type in the control sector, not the target sector. Also tag the line to the + control sector, and not the target sector.

      +

      NOCLIMB/EFFECT4 flags operate the same as for line 541.

      +

      543 - Downwards Wind

      +

      Wind speed is determined by the linedef's length. Type 512 or 768 must be applied to the target sector. If being used in a 3D Floor, + put the 512/768 sector type in the control sector, not the target sector. Also tag the + line to the control sector, and not the target sector.

      +

      NOCLIMB/EFFECT4 flags operate the same as for line 541.

      +

      544 - Current

      +

      Speed and direction are indicated by linedef length and direction. The target sector + should have type 512, Wind/Current. If being used in a 3D Floor, put + the 512/768 sector type in the control sector, not the target sector. Also tag the line to + the control sector, and not the target sector.

      +

      NOCLIMB/EFFECT4 flags operate the same as for line 541.

      +

      545 - Upwards Current

      +

      Linedef length indicates speed. Target sector needs sector type 512 + or 768. If being used in a 3D Floor, put the 512/768 sector type in + the control sector, not the target sector. Also tag the line to the control sector, and + not the target sector.

      +

      NOCLIMB/EFFECT4 flags operate the same as for line 541.

      +

      546 - Downwards Current

      +

      Speed is indicated by linedef length. Assign a type of 512 or 768 to the target sector. If being used in a 3D Floor, put the 512/768 + sector type in the control sector, not the target sector. Also tag the line to the control + sector, and not the target sector.

      +

      NOCLIMB/EFFECT4 flags operate the same as for line 541.

      +

      547 - Boom Push/Pull Thing

      +

      Creates a "point pusher," or a point that pushes you away or pulls you toward + it if you get close enough. Tag the linedef to a sector with type 512, + Wind/Current, and with a thing on it of type 5001 (push) or 5002 (pull). The control + linedef's length indicates pushing/pulling strength; if length is L, the effect fades away + to nothing when you are 2L away from the point.

      +

      If you want to create multiple point pushers/pullers, you'll need to have them in + different target sectors, but they can share the same tag.

      +

      NOCLIMB/EFFECT4 flags operate the same as for line 541.

      +

       

      +
    +
  • +
  • Lighting
      +

      600 - Floor Lighting

      +

      Sets the lighting for the floor only. The control sector's light value will be used for + the target sector's floor. Also see type 601.

      +

      601 - Ceiling Lighting

      +

      Sets the lighting of the ceiling only. The light value of the control sector will be + used for the target sector's ceiling. Also see type 600.

      +

      602 - Adjustable Pulsating Light

      +

      Linedef length indicates glow speed. The normal speed would be a linedef 32 units long.

      +

      The control sector (the linedef's front sector) is used to get what will be the minimum + light level for this effect, while the target sector's light level ends up being the + maximum.

      +

      603 - Adjustable Flickering Light

      +

      Linedef length indicates flicker speed. Normal speed would be a 16 fracunit long + linedef. A longer linedef means more time in between flickers.

      +

      The control sector (the linedef's front sector) is used to get what will be the minimum + light level for this effect, while the target sector's light level ends up being the + maximum.

      +

      604 - Adjustable Blinking Light (unsynchronized)

      +

      Line's X length is time for the light to be off, and Y length is the time for the light + to be on.

      +

      The control sector (the linedef's front sector) is used to get what will be the minimum + light level for this effect, while the target sector's light level ends up being the + maximum.

      +

      605 - Adjustable Blinking Light (synchronized)

      +

      Line's X length is time for the light to be off, and Y length is the time for the light + to be on.

      +

      The control sector (the linedef's front sector) is used to get what will be the minimum + light level for this effect, while the target sector's light level ends up being the + maximum.

      +

      606 - Colormap

      +

      Sets a colormap. Tag the linedef to the sector or sectors affected by the colormap. The + control linedef's front Above texture is used to determine the colormap. The format is + #rrggbba, where rr, gg, and bb are two hexadecimal digits for determining each color: red, + blue, and green. The a stands for alpha, and is a number or letter indicating the + translucency; from A-Z and 0-9, with A being most transparent and 9 being most opaque.

      +

      It does not generally matter what sector the colormap linedef belongs to. However, it + should not belong to the same sector as another colormap, as this can cause problems.

      +
    +
  • +

    Sector Types

    +

    You can apply up to four different types to one sector, provided that you only choose + ONE from EACH category. Add the numbers together to obtain the final value to use in level + editors.

    +
  • Section 1
      +

      1 - Damage (Generic)

      +

      This special hurts, period. It doesn't matter whether you have a liquid shield, fire + shield, attraction shield, or whatever else; step on one of these and suffer.

      +

      2 - Damage (Water)

      +

      Also known as Slime Hurt. Stepping here will be painful, as in shield/ring/life loss + (depending on how you are equipped), unless you happen to have the liquid shield.

      +

      3 - Damage (Fire)

      +

      Stepping here will hurt, unless you happen to have a fire shield.

      +

      4 - Damage (Electrical)

      +

      Hurts players whenever they're in the sector, unless they have the attraction shield.

      +

      Usage tip: Give the sector a floor flat that looks electrical and looks like it could + hurt you.

      +

      5 - Spikes

      +

      Making spikes using sectors is rather tedious and difficult. You can use things instead + (Floor Spike and Ceiling Spike). But the sector + version DOES look cooler. ;)

      +

      6 - Death Pit (Camera Modifications)

      +

      Used for bottomless pits. You'll probably want the sector's floor flat to be either + F_SKY1 (falling from the sky) or PIT (falling into a pit of complete blackness). The + camera modifications keep the camera from following you all the way down, for a Sonic + Adventure-style pit death. If you don't like the camera modifications, use sector type 5.

      +

      7 - Death Pit (No Camera Modifications)

      +

      For bottomless pits. Use if the camera modifications of sector type 6 + are not to your taste.

      +

      8 - Instant Kill

      +

      Die right away if you even step into this sector. No need to touch the floor as with + those sissy death pits.

      +

      9 - Ring Drainer (Floor Touch)

      +

      Lose one ring per 15 tics while touching the floor.

      +

      10 - Ring Drainer (No Floor Touch)

      +

      Like sector type 9, but doesn't require touching floor.

      +

      11 - Special Stage Damage

      +

      If you have rings and no shield, and you step on it, you only lose 10 rings, maximum. + It's just like the special stages!

      +

      12 - Space Countdown

      +

      In space, you have no chance to survive make your time, ha ha ha. Starts an immediate + five-second countdown, like when you drown.

      +

      13 - Ramp Sector

      +

      Doubles the step-up height of the player. Default step-up height is 24 fracunits, but + with this, it becomes 48. Useful for steps and other things if your players seem to be + getting 'stopped' by the stairs while moving quickly.

      +

      14 - Non-Ramp Sector (Don't step down)

      +

      Removes the 'step-down' that a player will normally do when moving to a nearby sector.

      +

      15 - Bouncy Sector (FOF Control Only)

      +

      Use this on a 3D floor's control sector to make it bouncy. Players will bounce off the + top of it. If the 3D floor's control line has the BOUNCY flag set, the linedef length sets + the minimum bounce force. Otherwise, you will slowly come to a stop.

      +

       

      +
    +
  • +
  • Section 2
      +

      16 - Trigger Linedef Executor (Pushable Objects)

      +

      Works like 80 but with a pushable object (gargoyle or snowman) + touching the floor rather than a player.

      +

      32 - Trigger Linedef Executor (Anywhere in Sector) (All Players)

      +

      Sector type 64 with the added requirement that all players who don't + have a game over need to be in the sector, not just one player. Currently does not work in + FOFs.

      +

      48 - Trigger Linedef Executor (Floor Touch) (All Players)

      +

      Sector type 80 with the added requirement that all players who don't + have a game over need to be in the sector, not just one player.

      +

      64 - Trigger Linedef Executor (Anywhere in Sector)

      +

      Like sector type 80, but you don't have to be touching the floor to + do the triggering. You could be flying high in the air. You should also use this one for + linedef executors triggered by FOFs.

      +

      80 - Trigger Linedef Executor (Floor Touch)

      +

      Required for any of the Linedef Executor Triggers to work in + the sector.

      +

      96 - Trigger Linedef Executor (Emerald Check)

      +

      Sector type 64 which will only execute if you have all 7 chaos + emeralds.

      +

      112 - Trigger Linedef Executor (NiGHTS Mare)

      +

      Like sector type 64, but this is only triggered if you are in a + NiGHTS map, and checks what mare you're on using the following format, depending on what + flags you have set for this line:

      +

      No flags -> Runs if (current mare = line length)

      +

      NOCLIMB -> Runs if (current mare <= line length)

      +

      BLOCKMONSTERS -> Runs if (current mare >= line + length)

      +

      128 - Check for linedef executor on 3D Floors (ANY object)

      +

      For any item to detect sector type 16 on a 3D floor, the target + sector on the map must have this type. This allows you to have any kind of object trigger + a linedef executor.

      +

      144 - Egg Trap Capsule

      +

      160 - Special Stage Time/Rings, Par

      +

      For special stages, floor height is time limit in seconds, and ceiling height is rings + required in seconds. If the ceiling height is 0, there is no ring requirement, only a time + limit to find an exit.

      +

      176 - Custom Global Gravity

      +

      Floor height sets global gravity. 500 is normal. 1000 is twice the normal gravity, 250 + is half. You can also set per-sector gravity with linetype 1. This can + also be adjusted in realtime, for some really cool effects.

      +

       

      +
    +
  • +
  • Section 3
      +

      256 - Ice/Sludge

      +

      See linedef type 540.

      +

      512 - Wind/Current

      +

      See linedef types 541 and 544.

      +

      768 - Ice/Sludge and Wind/Current

      +

      Combination of sector specials 256 and 512.

      +

      1024 - Conveyor Belt

      +

      See linedef type 520.

      +

      1280 - Speed Pad (No Spin)

      +

      See linedef type 4.

      +

      1536 - Speed Pad (Spin)

      +

      See linedef type 4. This type of speed pad forces you into a spin.

      +

      1792, 2048, 2304, 2560, 2816, 3072, 3328, 3584, 3840 - Bustable + Block Sprite Parameter

      +

      Used in a control sector of a bustable block. Chooses which debris sprite to spawn.

      +

      1792 = ROIA

      +

      2048 = ROIB

      +

      2304 = ROIC

      +

      2560 = ROID

      +

      2816 = ROIE

      +

      3072 = ROIF

      +

      3328 = ROIG

      +

      3584 = ROIH

      +

      3840 = ROII

      +

       

      +
    +
  • +
  • Section 4
      +

      4096 - Starpost Activator

      +

      Whenever a player steps in the sector, a starpost in that sector will be searched for + and, if found, activated.

      +

      8192 - Special Stage Goal

      +

      This is like the "GOAL" buttons in Sonic 1's special stages. Ends the special + stage when stepped on.

      +

      8192 - Exit Sector

      +

      In single-player, cooperative, or race mode, being in this sector ends the level. You + don't necessarily have to be touching the floor. (If you want the player to have to be + touching the floor, you can use linedef type 223, an invisible, + intangible FOF, to do the trick. Give the FOF control sector a type of 8192.)

      +

      See linedef type 2 for a way to exit to any map, not just the one + whose number is specified in the map header. Linedef 2 also allows you to skip the score + tally screen.

      +

      8192 - No Tag Zone

      +

      In games of tag, this sector is a safe spot. You cannot be tagged while in it.

      +

      8192 - CTF: Flag Return

      +

      In CTF, if the red or blue flag enters this sector, it will automatically return to + base, much like how it behaves when it falls in a pit. This can also be set as a special + on a 3D floor.

      +

      12288 - CTF: Red Team Base

      +

      The red team has to bring the blue flag onto this sector to score. + It's generally a good idea to have the red flag here and the red team player starts somewhere close by.

      +

      16384 - CTF: Blue Team Base

      +

      The blue team has to bring the red flag onto this sector to score. + It's generally a good idea to have the blue flag here and the blue team player starts somewhere close by.

      +

      20480 - Fan Sector

      +

      Acts like a fan, pushing the player up at constant speed and activating the proper + animation. Can be used on intangible FOFs.

      +

      24576 - Super Sonic Transform

      +

      Transforms you into Super Sonic and gives you 50 rings, providing you have all of the + chaos emeralds.

      +

      28672 - Spinner

      +

      Forces the player into a spin.

      +

      32768 - Zoom Tube Start

      +

      When the player touches this sector, a line type 3 with the same tag + as the sector is searched for, and if found, the line's X length determines the speed at + which the tube operates, while its Y length determines which zoom tube sequence to use. + Then the player is immediately put into a spin, loses control, and gravitates toward the + first Zoom Tube Waypoint (thing type 753), which does not have to be + in the same sector. Once they reach the first waypoint, they begin traveling to the 2nd, + 3rd, and so on, until the last waypoint is reached.

      +

      This can be used with Floor-Over-Floors, just use these specials in the control sector + instead.

      +

      36864 - Zoom Tube End

      +

      Just like sector type 32768, but starts from the last waypoint + and goes to the first.

      +

      40960 - Finish Line

      +

      The finish line for a race circuit. This increments a lap when you pass it, after + hitting all the star posts in the stage in sequential order. Once the number of laps + specified by the server is reached, the level is completed.

      +
    +
  • +
+ + diff --git a/extras/conf/Srb2-20db.cfg b/extras/conf/Srb2-20db.cfg new file mode 100644 index 000000000..8dc18b6e8 --- /dev/null +++ b/extras/conf/Srb2-20db.cfg @@ -0,0 +1,2276 @@ +/******************************************************************************\ + + SRB2 Doom Builder + Game Configuration for SRB2 version 2.0. + + Contributors: + - Kristos + - Shadow Hog + - ST218 + - Foxboy + - JJames19119 + - SRB2-Playah + - Oogaland + - SSNTails + - DarkWarrior + - Neo + +\******************************************************************************/ + +// This is required to prevent accedential use of a different configuration. +type = "SRB2 Doom Builder Game Configuration"; + +// This is the title to show for this game. +game = "Sonic Robo Blast 2 v2.0"; + +// Map format determines the way the map will be loaded. +mapformat = 1; + +// Flags for changes in 2.0. +seceffectnybble = 1; + +// Default flags for first new thing. +defaulthingflags = 0; + +// Default lump name for new map. +defaultlumpname = "MAP01"; + +// Load textures/flats by default from this file. +texturesfile = ""; + +// Thing number for start position in 3D Mode. +start3dmode = 32000; + +// Thing number for control sector position hint. +ctrlsechint = 32001; + +// Zoom tube waypoint, for the wizard. +zoomtubewaypoint = 753; + +// No generalized types. +generalizedlinedefs = 0; +generalizedsectors = 0; + +/* TEXTURES AND FLAT SOURCES --------------------------------------------------- + +This tells Doom Builder where to find the information for textures and flats in +the IWAD file, Addition WAD file and Map WAD file. + +Start and end lumps must be given in a structure (of which the key name doesn't +matter) and any textures or flats in between them are loaded in either the +textures category or flats category. + +For textures: PNAMES, TEXTURE1 and TEXTURE2 are loaded by default. + +*/ + +// Texture sources. +textures +{ +} + +// Flat sources. +flats +{ + standard1 + { + start = "F_START"; + end = "F_END"; + } + + standard2 + { + start = "FF_START"; + end = "FF_END"; + } + + standard3 + { + start = "FF_START"; + end = "F_END"; + } + + standard4 + { + start = "F_START"; + end = "FF_END"; + } +} + +/* TEXTURES AND FLATS FILTERING ------------------------------------------------ + +This allows you to filter textures and flats so that you only see the +textures/flats listed that you prefer to use. + +The key name doesn't matter here, only the values. + +Pattern-matching is performed on lump names. You can use the following wildcards +in values to specify ranges: + +? = Any character. +* = Zero or more characters. +# = Any numeric digit. +[abc...] = Any of these characters that are between brackets. +[!abc..] = Not any of these characters that are between brackets. + +*/ + +// List these textures... +texturesfilter +{ + all_textures = "*"; +} + +// But do not list these textures... +notexturesfilter +{ + none = ""; +} + +// List these flats... +flatsfilter +{ + all_flats = "*"; +} + +// But do not list these flats... +noflatsfilter +{ + none = ""; +} + +/* PSEUDO-FLATS AND TEXTURES --------------------------------------------------- + +Names of flats and textures that don't really exist, but shouldn't be identified +as invalid. + +Pattern-matching is performed on lump names. See above for syntax. + +*/ + +pseudoflats +{ + F_SKY1; +} + +pseudotextures +{ + [#]*; +} + +/* GAME DETECT PATTERN --------------------------------------------------------- + +Used to guess the game for which a WAD file is made. + +1 = One of these lumps must exist. +2 = None of these lumps must exist. +3 = All of these lumps must exist. + +Pattern-matching is performed on lump names. See above for syntax. + +*/ + +gamedetect +{ + EXTENDED = 2; + BEHAVIOR = 2; + E#M# = 2; + MAP?? = 1; +} + +/* MAP LUMP NAMES -------------------------------------------------------------- + +Map lumps are loaded with the map as long as they are right after each other. +When the editor meets a lump which is not defined in this list (or defined +as 0), it will stop loading right there. + +The order of items defines the order in which lumps will be written to WAD file +on save. The value (flags) of items determines what the editor should do with +it. You should never mess with value 4, because it may result in incorrect map +builds. + + 1 = Lump required. + 2 = Lump which must be respected. + 4 = Lump generated by node builder. + 8 = Lump allowed to be empty after nodebuilding. + 16 = Lump allowed to be missing after nodebuilding. + 4096 = Lump which can be edited as text. + 8192 = Lump which can be edited as DEHACKED. +12288 = Lump which can be edited as MAPINFO. +16384 = WAD-global. + +*/ + +maplumpnames +{ + THINGS = 13; + LINEDEFS = 5; + SIDEDEFS = 5; + VERTEXES = 5; + SEGS = 4; + SSECTORS = 4; + NODES = 4; + SECTORS = 5; + REJECT = 4; + BLOCKMAP = 20; + MAINCFG = 24576; +} + +// DEFAULT SECTOR BRIGHTNESS LEVELS -------------------------------------------- + +sectorbrightness +{ + 255; + 240; + 224; + 208; + 192; + 176; + 160; + 144; + 128; + 112; + 96; + 80; + 64; + 48; + 32; + 16; + 0; +} + +// SECTOR TYPES ---------------------------------------------------------------- + +sectortypes +{ + nybble0 + { + 0 = "(normal)"; + 1 = "Damage"; + 2 = "Damage (Water)"; + 3 = "Damage (Fire)"; + 4 = "Damage (Electrical)"; + 5 = "Spikes"; + 6 = "Death Pit (Camera Modifications)"; + 7 = "Death Pit (No Camera Modifications)"; + 8 = "Instant Kill"; + 9 = "Ring Drainer (Floor Touch)"; + 10 = "Ring Drainer (No Floor Touch)"; + 11 = "Special Stage Damage"; + 12 = "Space Countdown"; + 13 = "Ramp Sector (double step-up/down)"; + 14 = "Non-Ramp Sector (no step-down)"; + 15 = "Bouncy Sector (FOF Control Only)"; + } + + nybble1 + { + 0 = "(normal)"; + 1 = "Trigger Line Ex. (Pushable Objects)"; + 2 = "Trigger Line Ex. (Anywhere, All Players)"; + 3 = "Trigger Line Ex. (Floor Touch, All Players)"; + 4 = "Trigger Line Ex. (Anywhere in Sector)"; + 5 = "Trigger Line Ex. (Floor Touch)"; + 6 = "Trigger Line Ex. (Emerald Check)"; + 7 = "Trigger Line Ex. (Nights Mare)"; + 8 = " Check for Line Exec. on FOFs"; + 9 = "Egg Trap Capsule"; + 10 = "Special Stage Time/Rings Parameters"; + 11 = "Custom Global Gravity"; + } + + nybble2 + { + 0 = "(normal)"; + 1 = "Ice/Sludge"; + 2 = "Wind/Current"; + 3 = "Ice/Sludge and Wind/Current"; + 4 = "Conveyor Belt"; + 5 = "Speed Pad (No Spin)"; + 6 = "Speed Pad (Spin)"; + 7 = "Bustable Block Sprite Parameter (ROIA)"; + 8 = "Bustable Block Sprite Parameter (ROIB)"; + 9 = "Bustable Block Sprite Parameter (ROIC)"; + 10 = "Bustable Block Sprite Parameter (ROID)"; + 11 = "Bustable Block Sprite Parameter (ROIE)"; + 12 = "Bustable Block Sprite Parameter (ROIF)"; + 13 = "Bustable Block Sprite Parameter (ROIG)"; + 14 = "Bustable Block Sprite Parameter (ROIH)"; + 15 = "Bustable Block Sprite Parameter (ROII)"; + } + + nybble3 + { + 0 = "(normal)"; + 1 = "Star Post Activator"; + 2 = "Exit/Special Stage Goal/Return Flag"; + 3 = "CTF: Red Team Base"; + 4 = "CTF: Blue Team Base"; + 5 = "Fan Sector"; + 6 = "Super Sonic Transform"; + 7 = "Spinner"; + 8 = "Zoom Tube Start"; + 9 = "Zoom Tube End"; + 10 = "Finish Line"; + 11 = "Rope Hang"; + } +} + +// LINEDEF FLAGS --------------------------------------------------------------- + +linedefflags +{ + 1 = "[0] Effect 6"; + 2 = "[1] Block Enemies"; + 4 = "[2] Double-Sided"; + 8 = "[3] Upper Unpegged"; + 16 = "[4] Lower Unpegged"; + 32 = "[5] Effect 1"; + 64 = "[6] Not Climbable"; + 128 = "[7] Effect 2"; + 256 = "[8] Effect 3"; + 512 = "[9] Effect 4"; + 1024 = "[10] Effect 5"; + 2048 = "[11] No Sonic"; + 4096 = "[12] No Tails"; + 8192 = "[13] No Knuckles"; + 16384 = "[14] Bouncy Wall"; + 32768 = "[15] Transfer Line"; +} + +// LINEDEF ACTIVATIONS --------------------------------------------------------- + +linedefactivations +{ +} + +/* FOF FLAGS ------------------------------------------------------------------- + +This is a hack. The FOF flag values have changed in 2.0, but the old 1.09.4 +values are hardcoded in the source for SRB2 Doom Builder. Until Oogaland fixes +this, I'm sticking some fake values in here to make 3D mode draw FOFs like it's +supposed to. --Neo + +Flags I've found relevant: + + 4 = Renders the walls. + 8 = Renders the planes. +32 = Doesn't cast a shadow. + +*/ + +fofs +{ + 100 = 12; + 101 = 44; + 102 = 44; + 103 = 36; + 104 = 40; + 105 = 32; + 120 = 12; + 121 = 12; + 122 = 8; + 123 = 8; + 140 = 12; + 141 = 12; + 142 = 8; + 143 = 12; + 144 = 12; + 145 = 8; + 146 = 4; + 150 = 12; + 151 = 12; + 152 = 12; + 160 = 12; + 170 = 12; + 171 = 12; + 172 = 12; + 173 = 12; + 174 = 12; + 175 = 12; + 176 = 12; + 177 = 12; + 178 = 12; + 179 = 12; + 180 = 12; + 190 = 12; + 191 = 44; + 192 = 44; + 193 = 32; + 194 = 12; + 195 = 12; + 200 = 0; + 201 = 0; + 202 = 0; + 220 = 12; + 221 = 44; + 222 = 36; + 223 = 32; + 250 = 12; + 251 = 12; + 252 = 12; + 253 = 12; + 254 = 12; + 255 = 12; + 256 = 12; + 257 = 12; + 258 = 44; + 259 = 12; +} + +// LINEDEF TYPES --------------------------------------------------------------- + +linedeftypes +{ + 0 = "Miscellaneous: (normal)"; + 1 = "Miscellaneous: Per-Sector Gravity"; + 2 = "Parameters: Custom Exit"; + 3 = "Parameters: Zoom Tube Parameters"; + 4 = "Miscellaneous: Speed Pad"; + 5 = "Miscellaneous: Camera Scanner"; + 6 = "Miscellaneous: Disable Linedef Effect On Level Load"; + 7 = "Miscellaneous: Sector Flat Alignment"; + 8 = "Parameters: Sector Special Parameters"; + 9 = "Parameters: Chain Parameters"; + 10 = "Miscellaneous: Culling Plane"; + 11 = "Parameters: Rope Hang Parameters"; + 12 = "Parameters: Rock Spawn Parameters"; + 13 = "Miscellaneous: Heat Wave Effect"; + 20 = "PolyObject: First Line"; + 21 = "PolyObject: Explicity Include Line"; + 22 = "PolyObject: Parameters"; + 30 = "PolyObject: Waving Flag"; + 50 = "Miscellaneous: Instantly Lower Floor On Level Load"; + 51 = "Miscellaneous: Instantly Raise Ceiling On Level Load"; + 52 = "Plane Movement: Continuously Falling Sector"; + 53 = "Plane Movement: Continuous Floor/Ceiling Mover"; + 54 = "Plane Movement: Continuous Floor Mover"; + 55 = "Plane Movement: Continuous Ceiling Mover"; + 56 = "Plane Movement: Continuous Two-Speed Floor/Ceiling Mover"; + 57 = "Plane Movement: Continuous Two-Speed Floor Mover"; + 58 = "Plane Movement: Continuous Two-Speed Ceiling Mover"; + 59 = "Plane Movement: Activate Moving Platform"; + 60 = "Plane Movement: Activate Moving Platform (Adjustable Speed)"; + 61 = "Plane Movement: Crusher (Ceiling to Floor)"; + 62 = "Plane Movement: Crusher (Floor to Ceiling)"; + 63 = "Miscellaneous: Fake Floor/Ceiling Planes"; + 64 = "Parameters: Appearing/Disappearing FOF"; + 65 = "Parameters: Bridge Thinker"; + 100 = "FOF (solid): Solid, Opaque"; + 101 = "FOF (solid): Solid, Opaque, No Shadow"; + 102 = "FOF (solid): Solid, Translucent"; + 103 = "FOF (solid): Solid, Sides Only"; + 104 = "FOF (solid): Solid, No Sides"; + 105 = "FOF (solid): Solid, Invisible"; + 120 = "FOF (intangible): Water, Opaque"; + 121 = "FOF (intangible): Water, Translucent"; + 122 = "FOF (intangible): Water, Opaque, No Sides"; + 123 = "FOF (intangible): Water, Translucent, No Sides"; + 140 = "FOF (solid): Intangible from Bottom, Opaque"; + 141 = "FOF (solid): Intangible from Bottom, Translucent"; + 142 = "FOF (solid): Intangible from Bottom, Translucent, No Sides"; + 143 = "FOF (solid): Intangible from Top, Opaque"; + 144 = "FOF (solid): Intangible from Top, Translucent"; + 145 = "FOF (solid): Intangible from Top, Translucent, No Sides"; + 146 = "FOF (solid): Only Tangible From Sides"; + 150 = "FOF (bobbing): Air Bobbing"; + 151 = "FOF (bobbing): Air Bobbing (Adjustable)"; + 152 = "FOF (bobbing): Reverse Air Bobbing (Adjustable)"; + 160 = "FOF (bobbing): Floating, Bobbing"; + 170 = "FOF (crumbling): Crumbling (Respawn)"; + 171 = "FOF (crumbling): Crumbling (No Respawn)"; + 172 = "FOF (crumbling): Crumbling (Respawn), Intangible from Bottom"; + 173 = "FOF (crumbling): Crumbling (No Respawn), Intangible from Bottom"; + 174 = "FOF (crumbling): Crumbling (Respawn), Int. from Bottom, Translucent"; + 175 = "FOF (crumbling): Crumbling (No Respawn), Int. from Bottom, Translucent"; + 176 = "FOF (crumbling): Crumbling (Respawn), Floating, Bobbing"; + 177 = "FOF (crumbling): Crumbling (No Respawn), Floating, Bobbing"; + 178 = "FOF (crumbling): Crumbling (Respawn), Floating"; + 179 = "FOF (crumbling): Crumbling (No Respawn), Floating"; + 180 = "FOF (crumbling): Crumbling (Respawn), Air Bobbing"; + 190 = "FOF (bobbing): Rising Platform, Solid, Opaque"; + 191 = "FOF (bobbing): Rising Platform, Solid, Opaque, No Shadow"; + 192 = "FOF (bobbing): Rising Platform, Solid, Translucent"; + 193 = "FOF (bobbing): Rising Platform, Solid, Invisible"; + 194 = "FOF (bobbing): Rising Platform, Intangible from Bottom, Opaque"; + 195 = "FOF (bobbing): Rising Platform, Intangible from Bottom, Translucent"; + 200 = "FOF (special): Light Block"; + 201 = "FOF (special): Half Light Block"; + 202 = "FOF (special): Fog Block"; + 220 = "FOF (intangible): Intangible, Opaque"; + 221 = "FOF (intangible): Intangible, Translucent"; + 222 = "FOF (intangible): Intangible, Sides Only"; + 223 = "FOF (intangible): Intangible, Invisible"; + 250 = "FOF (special): Mario Block"; + 251 = "FOF (special): Thwomp Block"; + 252 = "FOF (special): Shatter Block"; + 253 = "FOF (special): Shatter Block, Translucent"; + 254 = "FOF (special): Bustable Block"; + 255 = "FOF (special): Spin Bust Block"; + 256 = "FOF (special): Spin Bust Block, Translucent"; + 257 = "FOF (special): Quicksand"; + 258 = "FOF (special): Laser"; + 259 = "FOF (special): Custom FOF"; + 300 = "Linedef Executor Trigger: Continuous"; + 301 = "Linedef Executor Trigger: Each Time"; + 302 = "Linedef Executor Trigger: Once"; + 303 = "Linedef Executor Trigger: Ring Count - Continuous"; + 304 = "Linedef Executor Trigger: Ring Count - Once"; + 305 = "Linedef Executor Trigger: Character Ability - Once"; + 306 = "Linedef Executor Trigger: Character Ability - Each Time"; + 307 = "Linedef Executor Trigger: Character Ability - Continuous"; + 308 = "Linedef Executor Trigger: Race Only - Once"; + 309 = "Linedef Executor Trigger: CTF Red Team - Continuous"; + 310 = "Linedef Executor Trigger: CTF Red Team - Each Time"; + 311 = "Linedef Executor Trigger: CTF Blue Team - Continuous"; + 312 = "Linedef Executor Trigger: CTF Blue Team - Each Time"; + 313 = "Linedef Executor Trigger: No More Enemies - Once"; + 314 = "Linedef Executor Trigger: Number of Pushables - Continuous"; + 315 = "Linedef Executor Trigger: Number of Pushables - Once"; + 316 = "Linedef Executor Trigger: Land On PolyObject"; + 399 = "Linedef Executor Trigger: Level Load"; + 400 = "Linedef Executor (sector): Set Tagged Sector's Floor Height/Texture"; + 401 = "Linedef Executor (sector): Set Tagged Sector's Ceiling Height/Texture"; + 402 = "Linedef Executor (sector): Set Tagged Sector's Light Level"; + 403 = "Linedef Executor (plane movement): Move Tagged Sector's Floor"; + 404 = "Linedef Executor (plane movement): Move Tagged Sector's Ceiling"; + 405 = "Linedef Executor (plane movement): Lower Floor According to Linedef"; + 406 = "Linedef Executor (plane movement): Raise Floor According to Linedef"; + 407 = "Linedef Executor (plane movement): Lower Ceiling According to Linedef"; + 408 = "Linedef Executor (plane movement): Raise Ceiling According to Linedef"; + 409 = "Linedef Executor (sector): Change Tagged Sectors' Tag"; + 410 = "Linedef Executor (sector): Change Front Sector's Tag"; + 411 = "Linedef Executor (plane movement): Stop Plane Movement"; + 412 = "Linedef Executor (player/object): Teleporter"; + 413 = "Linedef Executor (misc.): Change Music"; + 414 = "Linedef Executor (misc.): Play Sound Effect"; + 415 = "Linedef Executor (misc.): Run Script"; + 416 = "Linedef Executor (sector): Start Adjustable Fire Flicker"; + 417 = "Linedef Executor (sector): Start Adjustable Glowing Light"; + 418 = "Linedef Executor (sector): Start Adjustable Blinking Light (unsynchronized)"; + 419 = "Linedef Executor (sector): Start Adjustable Blinking Light (synchronized)"; + 420 = "Linedef Executor (sector): Fade Light Level"; + 421 = "Linedef Executor (sector): Stop Lighting Effect"; + 422 = "Linedef Executor (misc.): Switch To Cut-Away View"; + 423 = "Linedef Executor (misc.): Change Sky"; + 424 = "Linedef Executor (misc.): Change Weather"; + 425 = "Linedef Executor (player/object): Change Object State"; + 426 = "Linedef Executor (player/object): Stop Object"; + 427 = "Linedef Executor (player/object): Award Score"; + 428 = "Linedef Executor (plane movement): Start Platform Movement"; + 429 = "Linedef Executor (plane movement): Crush Ceiling Once"; + 430 = "Linedef Executor (plane movement): Crush Floor Once"; + 431 = "Linedef Executor (plane movement): Crush Floor And Ceiling Once"; + 432 = "Linedef Executor (player/object): Enable 2D Mode"; + 433 = "Linedef Executor (player/object): Disable 2D Mode"; + 434 = "Linedef Executor (player/object): Award Power-Up"; + 435 = "Linedef Executor (sector): Change Plane Scroller Direction"; + 436 = "Linedef Executor (misc.): Shatter FOF"; + 437 = "Linedef Executor (player/object): Disable Player Control"; + 438 = "Linedef Executor (player/object): Change Object Size"; + 450 = "Linedef Executor (misc.): Execute Linedef Executor"; + 480 = "Linedef Executor (polyobject): Door Slide"; + 481 = "Linedef Executor (polyobject): Door Swing"; + 482 = "Linedef Executor (polyobject): Move"; + 483 = "Linedef Executor (polyobject): Move, Override"; + 484 = "Linedef Executor (polyobject): Rotate Right"; + 485 = "Linedef Executor (polyobject): Rotate Right, Override"; + 486 = "Linedef Executor (polyobject): Rotate Left"; + 487 = "Linedef Executor (polyobject): Rotate Left, Override"; + 488 = "Linedef Executor (polyobject): Move by Waypoints"; + 489 = "Linedef Executor (polyobject): Turn Invisible, Intangible"; + 490 = "Linedef Executor (polyobject): Turn Visible, Tangible"; + 491 = "Linedef Executor (polyobject): Set Translucency"; + 500 = "Wall Scrolling: Scroll Wall Front Side Left"; + 501 = "Wall Scrolling: Scroll Wall Front Side Right"; + 502 = "Wall Scrolling: Scroll Wall According to Linedef"; + 503 = "Wall Scrolling: Scroll Wall According to Linedef (Accelerative)"; + 504 = "Wall Scrolling: Scroll Wall According to Linedef (Displacement)"; + 505 = "Wall Scrolling: Scroll Texture by Front Side Offsets"; + 506 = "Wall Scrolling: Scroll Texture by Back Side Offsets"; + 510 = "Plane Scrolling: Scroll Floor Texture"; + 511 = "Plane Scrolling: Scroll Floor Texture (Accelerative)"; + 512 = "Plane Scrolling: Scroll Floor Texture (Displacement)"; + 513 = "Plane Scrolling: Scroll Ceiling Texture"; + 514 = "Plane Scrolling: Scroll Ceiling Texture (Accelerative)"; + 515 = "Plane Scrolling: Scroll Ceiling Texture (Displacement)"; + 520 = "Plane Scrolling: Carry Objects on Floor"; + 521 = "Plane Scrolling: Carry Objects on Floor (Accelerative)"; + 522 = "Plane Scrolling: Carry Objects on Floor (Displacement)"; + 523 = "Plane Scrolling: Carry Objects on Ceiling"; + 524 = "Plane Scrolling: Carry Objects on Ceiling (Accelerative)"; + 525 = "Plane Scrolling: Carry Objects on Ceiling (Displacement)"; + 530 = "Plane Scrolling: Scroll Floor Texture and Carry Objects"; + 531 = "Plane Scrolling: Scroll Floor Texture and Carry Objects (Accelerative)"; + 532 = "Plane Scrolling: Scroll Floor Texture and Carry Objects (Displacement)"; + 533 = "Plane Scrolling: Scroll Ceiling Texture and Carry Objects"; + 534 = "Plane Scrolling: Scroll Ceiling Texture and Carry Objects (Accelerative)"; + 535 = "Plane Scrolling: Scroll Ceiling Texture and Carry Objects (Displacement)"; + 540 = "Miscellaneous: Floor Friction"; + 541 = "Pusher: Wind"; + 542 = "Pusher: Upwards Wind"; + 543 = "Pusher: Downwards Wind"; + 544 = "Pusher: Current"; + 545 = "Pusher: Upwards Current"; + 546 = "Pusher: Downwards Current"; + 547 = "Pusher: Push/Pull"; + 600 = "Lighting: Floor Lighting"; + 601 = "Lighting: Ceiling Lighting"; + 602 = "Lighting: Adjustable Pulsating Light"; + 603 = "Lighting: Adjustable Flickering Light"; + 604 = "Lighting: Adjustable Blinking Light (unsynchronized)"; + 605 = "Lighting: Adjustable Blinking Light (synchronized)"; + 606 = "Lighting: Colormap"; + 900 = "Translucent Wall: 90% Opaque"; + 901 = "Translucent Wall: 80% Opaque"; + 902 = "Translucent Wall: 70% Opaque"; + 903 = "Translucent Wall: 60% Opaque"; + 904 = "Translucent Wall: 50% Opaque"; + 905 = "Translucent Wall: 40% Opaque"; + 906 = "Translucent Wall: 30% Opaque"; + 907 = "Translucent Wall: 20% Opaque"; + 908 = "Translucent Wall: 10% Opaque"; + 909 = "Translucent Wall: Fog Wall"; +} + +// THING FLAGS ----------------------------------------------------------------- + +thingflags +{ + 1 = "[0] Unused Flag"; + 2 = "[1] Object Flip"; + 4 = "[2] Object Special"; + 8 = "[3] Ambush"; + 16 = "(Used for Z offsets)"; +} + +/* THING TYPES ----------------------------------------------------------------- + +Color values: 1 = Blue 9 = Light_Blue + 2 = Green 10 = Light_Green + 3 = Cyan 11 = Light_Cyan + 4 = Red 12 = Light_Red + 5 = Magenta 13 = Pink + 6 = Brown 14 = Yellow + 7 = Gray 15 = White + 8 = Dark_Gray + +*/ + +thingtypes +{ + editor + { + color = 15; // White + arrow = 1; + title = ""; + error = -1; + width = 8; + height = 16; + sort = 1; + + 32000 = "3D Mode Start"; + 32001 + { + arrow = 0; + title = "Control Sector Position Hint"; + } + } + + starts + { + color = 1; // Blue + arrow = 1; + title = "Player Starts"; + width = 16; + height = 56; + zfactor = 32; + deaftext = "[3] Spawn On Ceiling"; + + 1 + { + title = "Player 01 Start"; + sprite = "SUPTD0"; + } + 2 + { + title = "Player 02 Start"; + sprite = "SUPTD0"; + } + 3 + { + title = "Player 03 Start"; + sprite = "SUPTD0"; + } + 4 + { + title = "Player 04 Start"; + sprite = "SUPTD0"; + } + 5 + { + title = "Player 05 Start"; + sprite = "SUPTD0"; + } + 6 + { + title = "Player 06 Start"; + sprite = "SUPTD0"; + } + 7 + { + title = "Player 07 Start"; + sprite = "SUPTD0"; + } + 8 + { + title = "Player 08 Start"; + sprite = "SUPTD0"; + } + 9 + { + title = "Player 09 Start"; + sprite = "SUPTD0"; + } + 10 + { + title = "Player 10 Start"; + sprite = "SUPTD0"; + } + 11 + { + title = "Player 11 Start"; + sprite = "SUPTD0"; + } + 12 + { + title = "Player 12 Start"; + sprite = "SUPTD0"; + } + 13 + { + title = "Player 13 Start"; + sprite = "SUPTD0"; + } + 14 + { + title = "Player 14 Start"; + sprite = "SUPTD0"; + } + 15 + { + title = "Player 15 Start"; + sprite = "SUPTD0"; + } + 16 + { + title = "Player 16 Start"; + sprite = "SUPTD0"; + } + 17 + { + title = "Player 17 Start"; + sprite = "SUPTD0"; + } + 18 + { + title = "Player 18 Start"; + sprite = "SUPTD0"; + } + 19 + { + title = "Player 19 Start"; + sprite = "SUPTD0"; + } + 20 + { + title = "Player 20 Start"; + sprite = "SUPTD0"; + } + 21 + { + title = "Player 21 Start"; + sprite = "SUPTD0"; + } + 22 + { + title = "Player 22 Start"; + sprite = "SUPTD0"; + } + 23 + { + title = "Player 23 Start"; + sprite = "SUPTD0"; + } + 24 + { + title = "Player 24 Start"; + sprite = "SUPTD0"; + } + 25 + { + title = "Player 25 Start"; + sprite = "SUPTD0"; + } + 26 + { + title = "Player 26 Start"; + sprite = "SUPTD0"; + } + 27 + { + title = "Player 27 Start"; + sprite = "SUPTD0"; + } + 28 + { + title = "Player 28 Start"; + sprite = "SUPTD0"; + } + 29 + { + title = "Player 29 Start"; + sprite = "SUPTD0"; + } + 30 + { + title = "Player 30 Start"; + sprite = "SUPTD0"; + } + 31 + { + title = "Player 31 Start"; + sprite = "SUPTD0"; + } + 32 + { + title = "Player 32 Start"; + sprite = "SUPTD0"; + } + 33 + { + title = "Match Start"; + sprite = "SUPTI0"; + } + 34 + { + title = "CTF Red Team Start"; + sprite = "SIGNG0"; + } + 35 + { + title = "CTF Blue Team Start"; + sprite = "SIGNE0"; + } + } + + enemies + { + color = 9; // Light_Blue + arrow = 1; + title = "Enemies"; + width = 24; + height = 32; + sort = 1; + + 100 + { + title = "Crawla (Blue)"; + sprite = "POSSA1"; + } + 101 + { + title = "Crawla (Red)"; + sprite = "SPOSA1"; + } + 102 + { + title = "Stupid Dumb Unnamed RoboFish"; + sprite = "FISHA0"; + width = 8; + height = 28; + } + 103 + { + title = "Buzz (Gold)"; + sprite = "BUZZA1"; + width = 20; + height = 24; + } + 104 + { + title = "Buzz (Red)"; + sprite = "RBUZA1"; + width = 20; + height = 24; + } + 105 + { + title = "Jetty-Syn Bomber"; + sprite = "JETBB1"; + width = 20; + } + 106 + { + title = "Jetty-Syn Gunner"; + sprite = "JETGB1"; + width = 20; + } + 107 + { + title = "Crawla Commander"; + sprite = "CCOMA1"; + width = 16; + } + 108 + { + title = "Deton"; + sprite = "DETNA1"; + width = 20; + } + 109 + { + title = "Skim"; + sprite = "SKIMA1"; + width = 16; + height = 24; + } + 110 + { + title = "Turret"; + sprite = "TRETA1"; + width = 16; + } + 111 + { + title = "Popup Turret"; + sprite = "TURRI1"; + width = 12; + height = 64; + } + 112 + { + title = "Sharp"; + sprite = "SHRPA1"; + width = 16; + height = 24; + } + 113 + { + title = "Jet Jaw"; + sprite = "JJAWA3A7"; + width = 12; + height = 20; + } + 114 + { + title = "Snailer"; + sprite = "SNLRA3A7"; + height = 48; + } + 115 + { + title = "Bird Aircraft Strike Hazard"; + sprite = "VLTRF1"; + width = 12; + height = 24; + } + 116 + { + title = "Pointy"; + sprite = "PNTYA1"; + width = 8; + height = 16; + } + 117 + { + title = "Robo-Hood"; + sprite = "ARCHA1"; + deaftext = "[3] Unknown Effect"; + } + 118 + { + title = "CastleBot FaceStabber"; + sprite = "CBFSA1"; + width = 32; + height = 64; + } + 119 + { + title = "Egg Guard"; + sprite = "ESHIA1"; + width = 16; + height = 48; + } + 120 + { + title = "Green Snapper"; + sprite = "GSNPA1"; + height = 24; + } + 121 + { + title = "Minus"; + sprite = "MNUSA1"; + } + 750 + { + title = " Chaos Enemy Spawn"; + sprite = "TFOGG0"; + width = 32; + height = 64; + } + } + + bosses + { + color = 8; // Dark_Gray + arrow = 1; + title = "Bosses"; + width = 24; + height = 52; + sort = 1; + zfactor = 32; + + 200 + { + title = "Boss 1 - Egg Mobile"; + sprite = "EGGMA1"; + deaftext = "[3] Rotating Spikeballs"; + } + 201 + { + title = "Boss 2 - Egg Slimer"; + sprite = "EGGNA1"; + height = 48; + deaftext = "[3] Speed Up When Hit"; + } + 202 + { + title = "Boss 3 - Sea Egg"; + sprite = "EGGOA1"; + width = 32; + height = 80; + deaftext = "[3] Unknown Effect"; + } + 203 + { + title = " Boss 4 - Eggscalibur"; + sprite = "EGGPA1"; + } + 206 + { + title = "Boss 5 - Black Eggman"; + sprite = "BRAKB1"; + width = 48; + height = 160; + } + 290 + { + arrow = 0; + title = "Boss Escape Point"; + width = 8; + height = 16; + zfactor = 16; + } + 291 + { + arrow = 0; + title = "Egg Trap Center"; + width = 8; + height = 16; + zfactor = 16; + } + 292 + { + arrow = 0; + title = "Boss Waypoint"; + width = 8; + height = 16; + zfactor = 16; + } + } + + rings + { + color = 14; // Yellow + title = "Rings and Weapon Panels"; + width = 24; + height = 24; + deafheight = 32; + deaftext = "[3] Float"; + + 300 + { + title = "Ring"; + sprite = "RINGA0"; + width = 16; + } + 301 + { + title = "Bounce Ring"; + sprite = "CPRKB0"; + } + 302 + { + title = "Rail Ring"; + sprite = "SPRKA0"; + } + 304 + { + title = "Automatic Ring"; + sprite = "TAUTA3A7"; + } + 305 + { + title = "Explosion Ring"; + sprite = "BMSLA1"; + } + 306 + { + title = "Scatter Ring"; + sprite = "TSCRA1A5"; + } + 307 + { + title = "Grenade Ring"; + sprite = "TGREA0"; + } + 339 + { + title = "Turbo Ring"; + sprite = "BMSLA1"; + } + 340 + { + title = "Mine Ring"; + sprite = "TSCRA1A5"; + } + 341 + { + title = "Bright Fluorescent Ring"; + sprite = "TGREA0"; + } + 308 + { + title = "CTF Team Ring (Red)"; + sprite = "RRNGA0"; + width = 16; + } + 309 + { + title = "CTF Team Ring (Blue)"; + sprite = "TRNGA0"; + width = 16; + } + 330 + { + title = "Bounce Ring Panel"; + sprite = "PIKBA0"; + } + 331 + { + title = "Rail Ring Panel"; + sprite = "PIKRA0"; + } + 332 + { + title = "Automatic Ring Panel"; + sprite = "PIKAA0"; + } + 333 + { + title = "Explosion Ring Panel"; + sprite = "PIKEA0"; + } + 334 + { + title = "Scatter Ring Panel"; + sprite = "PIKSA0"; + } + 335 + { + title = "Grenade Ring Panel"; + sprite = "PIKGA0"; + } + 336 + { + title = "Turbo Ring Panel"; + sprite = "PIKEA0"; + } + 337 + { + title = "Mine Ring Panel"; + sprite = "PIKSA0"; + } + 338 + { + title = "Bright Fluorescent Ring Panel"; + sprite = "PIKGA0"; + } + } + + collectibles + { + color = 10; // Light_Green + title = "Other Collectibles"; + width = 16; + height = 32; + sort = 1; + + 310 + { + title = "CTF Red Flag"; + sprite = "RFLGA0"; + width = 24; + height = 64; + } + 311 + { + title = "CTF Blue Flag"; + sprite = "BFLGA0"; + width = 24; + height = 64; + } + 312 + { + title = "Special Stage Token"; + sprite = "TOKEA0"; + width = 8; + height = 16; + deafheight = 32; + deaftext = "[3] Float"; + } + 313 + { + title = "Chaos Emerald 1 (Green)"; + sprite = "EMMYA0"; + } + 314 + { + title = "Chaos Emerald 2 (Orange)"; + sprite = "EMMYB0"; + } + 315 + { + title = "Chaos Emerald 3 (Purple)"; + sprite = "EMMYC0"; + } + 316 + { + title = "Chaos Emerald 4 (Blue)"; + sprite = "EMMYD0"; + } + 317 + { + title = "Chaos Emerald 5 (Red)"; + sprite = "EMMYE0"; + } + 318 + { + title = "Chaos Emerald 6 (Light Blue)"; + sprite = "EMMYF0"; + } + 319 + { + title = "Chaos Emerald 7 (Gray)"; + sprite = "EMMYG0"; + } + 320 + { + title = "Emerald Hunt Location"; + sprite = "EMERA0"; + } + 323 + { + title = "Match Chaos Emerald Spawn"; + sprite = "CEMGA0"; + width = 8; + height = 48; + deafheight = 32; + deaftext = "[3] Float"; + } + } + + boxes + { + color = 7; // Gray + blocking = 2; + title = "Item Boxes"; + width = 16; + height = 32; + deaftext = "[3] Random (Weak)"; + sort = 1; + + 400 + { + title = "Super Ring (10 Rings)"; + sprite = "SRBXA0"; + } + 402 + { + title = "Attraction Shield"; + sprite = "YLTVA0"; + } + 403 + { + title = "Force Shield"; + sprite = "BLTVA0"; + } + 404 + { + title = "Armageddon Shield"; + sprite = "BKTVA0"; + } + 405 + { + title = "Whirlwind Shield"; + sprite = "WHTVA0"; + } + 406 + { + title = "Elemental Shield"; + sprite = "GRTVA0"; + } + 407 + { + title = "Super Sneakers"; + sprite = "SHTVA0"; + } + 408 + { + title = "Invincibility"; + sprite = "PINVA0"; + } + 409 + { + title = "Extra Life"; + sprite = "MTEXA0"; + } + 410 + { + title = "Eggman"; + sprite = "EGGBA0"; + } + 411 + { + title = "Teleporter"; + sprite = "MIXUA0"; + } + 412 + { + title = "Random"; + sprite = "QUESA0"; + } + 413 + { + title = "Gravity Boots"; + sprite = "GBTVA0"; + } + 414 + { + title = "CTF Team Ring Box (Red)"; + sprite = "RRBXA0"; + deaftext = "[3] Ambush"; + } + 415 + { + title = "CTF Team Ring Box (Blue)"; + sprite = "BRBXA0"; + deaftext = "[3] Ambush"; + } + 416 + { + title = "Recycler"; + sprite = "RECYA0"; + } + } + + miscellaneous + { + color = 11; // Light_Cyan + title = "Miscellaneous"; + width = 16; + height = 40; + sort = 1; + + 500 + { + title = "Air Bubble Patch"; + sprite = "BUBLA0"; + width = 8; + height = 16; + } + 501 + { + title = "End Level Sign"; + sprite = "SIGND0"; + width = 8; + height = 32; + } + 502 + { + arrow = 1; + title = "Star Post"; + sprite = "STPTA0"; + width = 64; + height = 80; + } + 526 + { + blocking = 2; + title = "Cannonball"; + sprite = "CBLLA0"; + width = 20; + deaftext = "[3] Not Pushable"; + } + 1000 + { + arrow = 1; + blocking = 2; + title = "Gargoyle"; + sprite = "GARGA1"; + deaftext = "[3] Not Pushable"; + } + 1102 + { + arrow = 1; + blocking = 2; + title = "Eggman Statue"; + sprite = "ESTAA1"; + width = 32; + height = 240; + deaftext = "[3] Not Pushable"; + } + 1106 + { + arrow = 1; + title = "Chain (Hang)"; + sprite = "SMCHA0"; + height = 32; + deaftext = "[3] Double Size"; + } + 1107 + { + arrow = 1; + title = "Chain (Spin)"; + sprite = "SMCHA0"; + height = 32; + } + 1200 + { + title = "Tumbleweed (Big)"; + sprite = "BTBLA0"; + width = 24; + height = 48; + deaftext = "[3] Moves Perpetually"; + } + 1201 + { + title = "Tumbleweed (Small)"; + sprite = "STBLA0"; + width = 12; + height = 24; + deaftext = "[3] Moves Perpetually"; + } + 1852 + { + blocking = 2; + title = "Snowman"; + sprite = "XMS3A0"; + deaftext = "[3] Not Pushable"; + } + 1876 + { + arrow = 1; + blocking = 2; + title = "Eggman Disco Statue"; + sprite = "ESTAB1"; + width = 20; + height = 96; + deaftext = "[3] Not Pushable"; + } + } + + springs + { + color = 12; // Light_Red + title = "Springs and Fans"; + width = 20; + height = 16; + + 540 + { + title = "Fan"; + sprite = "FANSA0"; + width = 16; + } + 541 + { + title = "Gas Jet"; + sprite = "STEMD0"; + width = 32; + } + 550 + { + title = "Yellow Spring"; + sprite = "SPRYA0"; + } + 551 + { + title = "Red Spring"; + sprite = "SPRRA0"; + } + 552 + { + title = "Blue Spring"; + sprite = "SPRBA0"; + } + 553 + { + title = "Yellow Spring (Ceiling)"; + sprite = "SUDYA0"; + } + 554 + { + title = "Red Spring (Ceiling)"; + sprite = "SUDRA0"; + } + 555 + { + arrow = 1; + title = "Diagonal Yellow Spring"; + sprite = "YSPRD2"; + width = 16; + deaftext = "[3] Rotate 22.5° CCW"; + } + 556 + { + arrow = 1; + title = "Diagonal Red Spring"; + sprite = "RSPRD2"; + width = 16; + deaftext = "[3] Rotate 22.5° CCW"; + } + 557 + { + arrow = 1; + title = "Diagonal Yellow Spring (Ceiling)"; + sprite = "YSUDE2"; + width = 16; + hangs = 1; + deaftext = "[3] Rotate 22.5° CCW"; + } + 558 + { + arrow = 1; + title = "Diagonal Red Spring (Ceiling)"; + sprite = "RSUDE2"; + width = 16; + hangs = 1; + deaftext = "[3] Rotate 22.5° CCW"; + } + } + + patterns + { + color = 5; // Magenta + arrow = 1; + title = "Special Placement Patterns"; + width = 16; + height = 384; + + 600 + { + arrow = 0; + title = "5 Vertical Rings (Yellow Spring)"; + sprite = "RINGA0"; + } + 601 + { + arrow = 0; + title = "5 Vertical Rings (Red Spring)"; + sprite = "RINGA0"; + height = 1024; + } + 602 + { + title = "5 Diagonal Rings (Yellow Spring)"; + sprite = "RINGA0"; + height = 32; + } + 603 + { + title = "10 Diagonal Rings (Red Spring)"; + sprite = "RINGA0"; + height = 32; + } + 604 + { + title = "Circle of Rings"; + sprite = "RINGA0"; + width = 96; + height = 192; + } + 605 + { + title = "Circle of Rings (Big)"; + sprite = "RINGA0"; + width = 192; + } + 606 + { + title = "Circle of Wing Logos"; + sprite = "NWNGA0"; + width = 96; + height = 192; + } + 607 + { + title = "Circle of Wing Logos (Big)"; + sprite = "NWNGA0"; + width = 192; + } + 608 + { + title = "Circle of Rings and Wings"; + sprite = "NWNGA0"; + width = 96; + height = 192; + } + 609 + { + title = "Circle of Rings and Wings (Big)"; + sprite = "NWNGA0"; + width = 192; + } + } + + invisible + { + color = 15; // White + title = "Misc. Invisible"; + width = 8; + height = 16; + + 700 = "Water Ambience A (Large)"; + 701 = "Water Ambience B (Large)"; + 702 = "Water Ambience C (Medium)"; + 703 = "Water Ambience D (Medium)"; + 704 = "Water Ambience E (Small)"; + 705 = "Water Ambience F (Small)"; + 706 = "Water Ambience G (Extra Large)"; + 707 = "Water Ambience H (Extra Large)"; + 708 = "Disco Ambience"; + 709 = "Volcano Ambience"; + 751 + { + arrow = 1; + title = "Teleport Destination"; + } + 752 + { + arrow = 1; + title = "Alternate View Point"; + } + 753 = "Zoom Tube Waypoint"; + 754 + { + title = "Push Point"; + deaftext = "[3] Push Using XYZ"; + } + 755 + { + title = "Pull Point"; + deaftext = "[3] Pull Using XYZ"; + } + 760 = "PolyObject Anchor"; + 761 = "PolyObject Spawn Point"; + 762 = "PolyObject Spawn Point (Crush)"; + } + + hazards + { + color = 4; // Red + title = "Hazards"; + width = 20; + height = 40; + sort = 1; + + 521 + { + title = "Spikeball"; + sprite = "SPIKA0"; + width = 12; + height = 24; + deafheight = 32; + deaftext = "[3] Float"; + } + 522 + { + blocking = 2; + title = "Spike (Ceiling)"; + sprite = "DSPKA0"; + width = 8; + height = 42; + hangs = 1; + } + 523 + { + title = "Spike (Floor)"; + sprite = "USPKA0"; + width = 8; + height = 42; + deaftext = "[3] Solid"; + } + 524 + { + arrow = 1; + title = "Big Floating Mine"; + width = 16; + height = 32; + sprite = "BMNEA1"; + } + 527 + { + arrow = 1; + title = "Big Floating Mine (Air)"; + width = 16; + height = 32; + sprite = "BMNEA1"; + } + 525 + { + title = "Cannonball Launcher"; + sprite = "CBLLA0"; + } + 1101 + { + title = "Torch"; + sprite = "FLAMA0"; + width = 8; + height = 32; + } + 1104 + { + title = "Mace (Spinning)"; + sprite = "SMCEA0"; + deaftext = "[3] Double Size"; + } + 1105 + { + title = "Mace (Swinging)"; + sprite = "SMCEA0"; + deaftext = "[3] Double Size"; + } + 1202 + { + arrow = 1; + title = "Rock Spawner"; + sprite = "ROIAA0"; + } + 1300 + { + arrow = 1; + title = "Flame Jet (Horizontal)"; + sprite = "FLMEB0"; + width = 16; + } + 1301 + { + title = "Flame Jet (Vertical)"; + sprite = "FLMEB0"; + width = 16; + deaftext = "[3] Shoot Downwards"; + } + } + + decoration + { + color = 2; // Green + title = "Decoration"; + width = 16; + height = 40; + + 757 + { + title = "Fan Particle Generator"; + sprite = "PRTLA0"; + width = 8; + height = 16; + } + 800 + { + title = "GFZ Flower"; + sprite = "FWR1A0"; + } + 801 + { + title = "Sunflower"; + sprite = "FWR2A0"; + height = 96; + } + 802 + { + title = "Budding Flower"; + sprite = "FWR3A0"; + width = 8; + height = 32; + } + 804 + { + title = "Berry Bush"; + sprite = "BUS1A0"; + height = 32; + } + 805 + { + title = "Bush"; + sprite = "BUS2A0"; + height = 32; + } + 900 + { + title = "THZ Flower"; + sprite = "THZPA0"; + width = 8; + height = 32; + } + 901 + { + title = "Alarm"; + sprite = "ALRMA0"; + width = 8; + height = 16; + hangs = 1; + } + 1001 + { + title = "Seaweed"; + sprite = "SEWEA0"; + width = 24; + height = 56; + } + 1002 + { + title = "Dripping Water"; + sprite = "DRIPD0"; + width = 8; + height = 16; + hangs = 1; + } + 1003 + { + title = "Coral (Green)"; + sprite = "CRL1A0"; + width = 8; + height = 16; + } + 1004 + { + title = "Coral (Red)"; + sprite = "CRL2A0"; + width = 8; + height = 16; + } + 1005 + { + title = "Coral (Orange)"; + sprite = "CRL3A0"; + width = 8; + height = 16; + } + 1006 + { + title = "Blue Crystal"; + sprite = "BCRYA1"; + width = 8; + height = 16; + } + 1100 + { + title = "Chain"; + sprite = "CHANA0"; + width = 8; + height = 128; + hangs = 1; + } + 1103 + { + title = "CEZ Flower"; + sprite = "FWR4A0"; + } + 1203 + { + title = "Cactus with Brown Flower"; + sprite = "CACTA0"; + height = 32; + } + 1204 + { + title = "Cactus with Brown Flower (Tall)"; + sprite = "CACTB0"; + height = 64; + } + 1205 + { + title = "Cactus with Blue Flower"; + sprite = "CACTC0"; + height = 32; + } + 1206 + { + title = "Cactus with Blue Flower (Tall)"; + sprite = "CACTD0"; + height = 80; + } + 1850 + { + title = "Xmas Pole"; + sprite = "XMS1A0"; + } + 1851 + { + title = "Candy Cane"; + sprite = "XMS2A0"; + width = 8; + height = 32; + } + 1875 + { + title = "Disco Ball"; + sprite = "DBALA0"; + height = 54; + hangs = 1; + } + 1900 + { + title = "Brown Stalagmite (Tall)"; + sprite = "STG0A0"; + } + 1901 + { + title = "Brown Stalagmite"; + sprite = "STG1A0"; + } + 1902 + { + title = "Orange Stalagmite (Tall)"; + sprite = "STG2A0"; + } + 1903 + { + title = "Orange Stalagmite"; + sprite = "STG3A0"; + } + 1904 + { + title = "Red Stalagmite (Tall)"; + sprite = "STG4A0"; + } + 1905 + { + title = "Red Stalagmite"; + sprite = "STG5A0"; + } + 1906 + { + title = "Gray Stalagmite (Tall)"; + sprite = "STG6A0"; + } + 1907 + { + title = "Gray Stalagmite"; + sprite = "STG7A0"; + } + 1908 + { + title = "Blue Stalagmite (Tall)"; + sprite = "STG8A0"; + } + 1909 + { + title = "Blue Stalagmite"; + sprite = "STG9A0"; + } + } + + nights + { + color = 13; // Pink + title = "Nights Items"; + width = 12; + height = 32; + + 1700 + { + title = "Axis"; + width = 8; + height = 4096; + circle = 1; + } + 1701 + { + title = "Axis Transfer"; + width = 8; + height = 4096; + } + 1702 + { + title = "Axis Transfer Line"; + width = 8; + height = 4096; + } + 1703 + { + title = "Ideya Drone"; + sprite = "NDRNA1"; + width = 16; + height = 56; + deaftext = "[3] Die Upon Time Up"; + } + 1704 + { + arrow = 1; + title = "Bumper"; + sprite = "NBMPG3G7"; + width = 32; + height = 64; + } + 1705 + { + arrow = 1; + title = "Hoop"; + sprite = "HOOPA0"; + width = 80; + height = 160; + } + 1706 + { + title = "Wing Logo"; + sprite = "NWNGA0"; + height = 24; + } + 1707 + { + title = "Super Loop"; + sprite = "NPRAA0"; + } + 1708 + { + title = "Drill Refill"; + sprite = "NPRBA0"; + } + 1709 + { + title = "Helper"; + sprite = "NPRCA0"; + } + 1710 + { + title = "Egg Capsule"; + sprite = "CAPSA0"; + width = 72; + height = 144; + } + } + + mario + { + color = 6; // Brown + title = "Mario Items"; + width = 16; + height = 32; + sort = 1; + + 1800 + { + title = "Coin"; + sprite = "COINA0"; + height = 24; + deafheight = 32; + deaftext = "[3] Float"; + } + 1801 + { + arrow = 1; + title = "Goomba"; + sprite = "GOOMA0"; + width = 24; + } + 1802 + { + arrow = 1; + title = "Goomba (Blue)"; + sprite = "BGOMA0"; + width = 24; + } + 1803 + { + title = "Fire Flower"; + sprite = "FFWRB0"; + } + 1804 + { + title = "Koopa Shell"; + sprite = "SHLLA0"; + width = 8; + height = 16; + } + 1805 + { + title = "Puma (Jumping Fireball)"; + sprite = "PUMAA0"; + width = 8; + height = 16; + } + 1806 + { + title = "King Bowser"; + sprite = "KOOPA0"; + height = 28; + } + 1807 + { + title = "Axe"; + sprite = "MAXEA0"; + width = 8; + height = 16; + } + 1808 + { + title = "Bush (Short)"; + sprite = "MUS1A0"; + } + 1809 + { + title = "Bush (Tall)"; + sprite = "MUS2A0"; + } + 1810 + { + title = "Toad"; + sprite = "TOADA0"; + width = 8; + } + } + + srb1 + { + color = 3; // Cyan + arrow = 1; + title = "SRB1 Remake Items"; + width = 20; + height = 32; + sort = 1; + + 4000 + { + title = "SRB1 Crawla"; + sprite = "SRBAA1"; + height = 40; + } + 4001 + { + title = "GuardRobo"; + sprite = "SRBBA1"; + width = 17; + height = 40; + } + 4002 + { + title = "Pyrin"; + sprite = "SRBCB1"; + width = 22; + } + 4003 + { + title = "HotRobo"; + sprite = "SRBDA0"; + height = 40; + } + 4004 + { + title = "Pogminz"; + sprite = "SRBEA1"; + } + 4005 + { + title = "Pogminz (Water)"; + sprite = "SRBEA1"; + } + 4006 + { + title = "Pog-GX2"; + sprite = "SRBFA0"; + width = 10; + height = 34; + } + 4007 + { + title = "Pyrex"; + sprite = "SRBGA1"; + width = 24; + } + 4008 + { + title = "UFO"; + sprite = "SRBHA0"; + width = 24; + hangs = 1; + } + 4009 + { + title = "SWAT Bot"; + sprite = "SRBIA1"; + width = 21; + height = 69; + } + 4010 + { + title = "SpyBot 2000"; + sprite = "SRBJA0"; + width = 36; + height = 62; + } + 4011 + { + title = "Buzz Bomber"; + sprite = "SRBKA0"; + width = 44; + height = 45; + } + 4012 + { + arrow = 0; + title = "RBZ Spike"; + sprite = "SRBLA0"; + width = 10; + height = 53; + } + 4013 + { + arrow = 0; + blocking = 2; + title = "Dumb Metal Sonic"; + sprite = "SRBMC0"; + width = 16; + height = 40; + deaftext = "[3] Not Pushable"; + } + 4014 + { + title = "Super SWAT Bot"; + sprite = "SRBNA1"; + width = 21; + height = 69; + } + 4015 + { + title = "Genrex"; + sprite = "SRBOA1"; + width = 17; + height = 40; + } + } +} diff --git a/extras/conf/Srb2-20wb.cfg b/extras/conf/Srb2-20wb.cfg new file mode 100644 index 000000000..d4ccd6971 --- /dev/null +++ b/extras/conf/Srb2-20wb.cfg @@ -0,0 +1,2364 @@ +/******************************************************************************\ + + SRB2 Workbench + Game Configuration for SRB2 version 2.0. + + Contributors: + - Kristos + - Shadow Hog + - ST218 + - Foxboy + - JJames19119 + - SRB2-Playah + - Oogaland + - SSNTails + - DarkWarrior + - Neo + +\******************************************************************************/ + +// This is required to prevent accedential use of a different configuration. +type = "SRB2 Workbench Game Configuration"; + +// This is the title to show for this game. +game = "Sonic Robo Blast 2 v2.0"; + +// This is used internally to refer to the game. +id = "srb2-20wb"; + +// Flags for changes in 2.0. +seceffectnybble = 1; +thingeffectnybble = 1; + +// Defaults for new thing. +defaultthingflags = 0; +defaultthing = 1; + +// Flags indicating which header features are supported. See +// ENUM_MAPHEADER_FLAGS in soc.h for values. +headerflags = 29360130; // Map Credits, Run SOC, Subtitle, Speed Music. + +// Thing numbers for Nights axes. +nights +{ + axistransfer = 1701; + axistransferline = 1702; +} + +// Wiki page names. +wiki +{ + seceffect = "Sector+Type+%d"; + ldeffect = "Linedef+Type+%d"; + thing = "Thing+Type+%d"; +} + +// Map-type flags for the TypeOfLevel header option. +leveltypes +{ + 1 = "Cooperative"; + 2 = "Race"; + 4 = "Match"; + 8 = "Tag"; + 16 = "Capture the Flag"; + 32 = " Chaos"; + 64 = "Nights"; + 128 = " Adventure"; + 256 = "Mario"; + 512 = "2D"; + 1024 = " Xmas"; + 2048 = "Egg Rock Zone 3"; + 4096 = "Single Player"; + 8192 = "SRB1 Remake"; +} + +// Weather types for use in the header-editor. +weather +{ + 0 = "None"; + 1 = "Storm"; + 2 = "Snow"; + 3 = "Rain"; + 4 = "Blank (precalculate)"; + 5 = "Storm (no rain)"; + 6 = "Storm (no strikes)"; + 7 = "Heat Wave"; +} + +/* PSEUDO-FLATS AND TEXTURES --------------------------------------------------- + +Names of flats and textures that don't really exist, but shouldn't be identified +as invalid. + +Pattern-matching is performed on lump names. You can use the following wildcards +in values to specify ranges: + +? = Any character. +* = Zero or more characters. +# = Any numeric digit. +[abc...] = Any of these characters that are between brackets. +[!abc..] = Not any of these characters that are between brackets. + +TODO: Not actually used yet! + +*/ + +pseudoflats +{ + F_SKY1; +} + +pseudotextures +{ + [#]*; +} + +// Sky flat, used to determine whether upper/lower textures are required. +sky = "F_SKY1"; + +/* MAP LUMP NAMES -------------------------------------------------------------- + +Map lumps are loaded with the map as long as they are right after each other. +When the editor meets a lump which is not defined in this list, it will stop +loading right there. + + 1 = Lump required. + 2 = Lump which must be respected. + 4 = Lump generated by node builder. + 8 = Lump allowed to be empty after nodebuilding. + 16 = Lump allowed to be missing after nodebuilding. + 4096 = Lump which can be edited as text. + 8192 = Lump which can be edited as DEHACKED. +12288 = Lump which can be edited as MAPINFO. +16384 = WAD-global. + +*/ + +maplumpnames +{ + THINGS = 13; + LINEDEFS = 5; + SIDEDEFS = 5; + VERTEXES = 5; + SEGS = 4; + SSECTORS = 4; + NODES = 4; + SECTORS = 5; + REJECT = 4; + BLOCKMAP = 20; +} + +// SECTOR TYPES ---------------------------------------------------------------- + +sectortypes +{ + nybble0 + { + 0 = "(normal)"; + 1 = "Damage"; + 2 = "Damage (Water)"; + 3 = "Damage (Fire)"; + 4 = "Damage (Electrical)"; + 5 = "Spikes"; + 6 = "Death Pit (Camera Modifications)"; + 7 = "Death Pit (No Camera Modifications)"; + 8 = "Instant Kill"; + 9 = "Ring Drainer (Floor Touch)"; + 10 = "Ring Drainer (No Floor Touch)"; + 11 = "Special Stage Damage"; + 12 = "Space Countdown"; + 13 = "Ramp Sector (double step-up/down)"; + 14 = "Non-Ramp Sector (no step-down)"; + 15 = "Bouncy Sector (FOF Control Only)"; + } + + nybble1 + { + 0 = "(normal)"; + 1 = "Trigger Linedef Executor (Pushable Objects)"; + 2 = "Trigger Linedef Executor (Anywhere, All Players)"; + 3 = "Trigger Linedef Executor (Floor Touch, All Players)"; + 4 = "Trigger Linedef Executor (Anywhere in Sector)"; + 5 = "Trigger Linedef Executor (Floor Touch)"; + 6 = "Trigger Linedef Executor (Emerald Check)"; + 7 = "Trigger Linedef Executor (Nights Mare)"; + 8 = " Check for Linedef Executor on FOFs"; + 9 = "Egg Trap Capsule"; + 10 = "Special Stage Time/Rings Parameters"; + 11 = "Custom Global Gravity"; + } + + nybble2 + { + 0 = "(normal)"; + 1 = "Ice/Sludge"; + 2 = "Wind/Current"; + 3 = "Ice/Sludge and Wind/Current"; + 4 = "Conveyor Belt"; + 5 = "Speed Pad (No Spin)"; + 6 = "Speed Pad (Spin)"; + 7 = "Bustable Block Sprite Parameter (ROIA)"; + 8 = "Bustable Block Sprite Parameter (ROIB)"; + 9 = "Bustable Block Sprite Parameter (ROIC)"; + 10 = "Bustable Block Sprite Parameter (ROID)"; + 11 = "Bustable Block Sprite Parameter (ROIE)"; + 12 = "Bustable Block Sprite Parameter (ROIF)"; + 13 = "Bustable Block Sprite Parameter (ROIG)"; + 14 = "Bustable Block Sprite Parameter (ROIH)"; + 15 = "Bustable Block Sprite Parameter (ROII)"; + } + + nybble3 + { + 0 = "(normal)"; + 1 = "Star Post Activator"; + 2 = "Exit/Special Stage Goal/Return Flag"; + 3 = "CTF: Red Team Base"; + 4 = "CTF: Blue Team Base"; + 5 = "Fan Sector"; + 6 = "Super Sonic Transform"; + 7 = "Spinner"; + 8 = "Zoom Tube Start"; + 9 = "Zoom Tube End"; + 10 = "Finish Line"; + 11 = "Rope Hang"; + } +} + +// LINEDEF FLAGS --------------------------------------------------------------- + +linedefflags +{ + 1 = "[00] Effect 6"; + 2 = "[01] Block Enemies"; + 4 = "[02] Double-Sided"; + 8 = "[03] Upper Unpegged"; + 16 = "[04] Lower Unpegged"; + 32 = "[05] Effect 1"; + 64 = "[06] Not Climbable"; + 128 = "[07] Effect 2"; + 256 = "[08] Effect 3"; + 512 = "[09] Effect 4"; + 1024 = "[10] Effect 5"; + 2048 = "[11] No Sonic"; + 4096 = "[12] No Tails"; + 8192 = "[13] No Knuckles"; + 16384 = "[14] Bouncy Wall"; + 32768 = "[15] Transfer Line"; +} + +// FOF INFORMATION ------------------------------------------------------------- + +fofs +{ + default = 100; + colourmap = 606; + defaultcustom = 259; + + // The FOF linedef specials, together with their FOF flags and a few + // other fields. + specials + { + 100 {flags = 415;} + 101 {flags = 479;} + 102 {flags = 6495;} + 103 {flags = 463;} + 104 {flags = 471;} + 105 {flags = 71;} + 120 {flags = 36665;} + 121 {flags = 40761;} + 122 {flags = 3889;} + 123 {flags = 7985;} + 140 {flags = 33588255;} + 141 {flags = 33560863;} + 142 {flags = 33560855;} + 143 {flags = 67142687;} + 144 {flags = 67115295;} + 145 {flags = 67115287;} + 146 {flags = 100696079;} + 150 {flags = 415; airbob = 1;} + 151 {flags = 415; airbob = 1;} + 152 {flags = 415; airbob = 1;} + 160 {flags = 262559; airbob = 1;} + 170 {flags = 1048991;} + 171 {flags = 1573279;} + 172 {flags = 34636831;} + 173 {flags = 35161119;} + 174 {flags = 34641311;} + 175 {flags = 35165599;} + 176 {flags = 1311135; airbob = 1;} + 177 {flags = 1835423; airbob = 1;} + 178 {flags = 1311135;} + 179 {flags = 1835423;} + 180 {flags = 1048991;} + 190 {flags = 415; rising = 1;} + 191 {flags = 479; rising = 1;} + 192 {flags = 6495; rising = 1;} + 193 {flags = 71; rising = 1;} + 194 {flags = 33588255; rising = 1;} + 195 {flags = 33594655; rising = 1;} + 200 {flags = 131585;} + 201 {flags = 513;} + 202 {flags = 257817;} + 220 {flags = 36633;} + 221 {flags = 6937;} + 222 {flags = 32777;} + 223 {flags = 65;} + 250 {flags = 4194719;} + 251 {flags = 415;} + 252 {flags = 142606367;} + 253 {flags = 142610463;} + 254 {flags = 8388639;} + 255 {flags = 276824095;} + 256 {flags = 276828191;} + 257 {flags = 16810521;} + 258 {flags = 2393;} + 259 {custom = 1;} + } + + // The significance of the FOF flags. Some of these have special + // meanings to the editor; for those which don't, the subsection name is + // ignored, but an entry will still be added to the list of flags for + // custom FOFs. + flags + { + FF_EXISTS {value = 1; text = "Exists.";} + FF_BLOCKPLAYER {value = 2; text = "Solid to players.";} + FF_BLOCKOTHERS {value = 4; text = "Solid to everything else.";} +// FF_SOLID {value = 6; text = "Solid to all objects."} + FF_RENDERSIDES {value = 8; text = "Renders the walls.";} + FF_RENDERPLANES {value = 16; text = "Renders the planes.";} +// FF_RENDERALL {value = 24; text = "Renders everything.} + FF_SWIMMABLE {value = 32; text = "Water block.";} + FF_NOSHADE {value = 64; text = "Doesn't cast a shadow.";} + FF_CUTSOLIDS {value = 128; text = "Skips rendering pixels hidden behind the block.";} + FF_CUTEXTRA {value = 256; text = "Skips rendering blocks marked with FF_EXTRA hidden behind the block.";} +// FF_CUTLEVEL {value = 384; text = "Skips rendering everything hidden behind the block."} + FF_CUTSPRITES {value = 512; text = "Splits sprites halfway inside the block.";} + FF_BOTHPLANES {value = 1024; text = "Renders both inside and outside planes.";} + FF_EXTRA {value = 2048; text = "Not rendered when seen through a block marked with FF_CUTEXTRA.";} + FF_TRANSLUCENT {value = 4096; text = "Translucent.";} + FF_FOG {value = 8192; text = "Fog block.";} + FF_INVERTPLANES {value = 16384; text = "Renders the planes only when within the block.";} + FF_ALLSIDES {value = 32768; text = "Renders both inside and outside walls.";} + FF_INVERTSIDES {value = 65536; text = "Renders the walls only when within the block.";} + FF_DOUBLESHADOW {value = 131072; text = "Light level and colormap affect only the inside of the block.";} + FF_FLOATBOB {value = 262144; text = "Floats on water and bobs when stepped on.";} + FF_NORETURN {value = 524288; text = "(Use with FF_CRUMBLE) Doesn't respawn after crumbling.";} + FF_CRUMBLE {value = 1048576; text = "Crumbles two seconds after being stepped on.";} + FF_SHATTERBOTTOM {value = 2097152; text = "(Use with FF_BUSTUP) Breaks only when hit from below.";} + FF_MARIO {value = 4194304; text = "Mario item block.";} + FF_BUSTUP {value = 8388608; text = "Can be broken by a spin or Knuckles.";} + FF_QUICKSAND {value = 16777216; text = "Quicksand block.";} + FF_PLATFORM {value = 33554432; text = "Intangible from bottom.";} + FF_REVERSEPLATFORM {value = 67108864; text = "Intangible from top.";} +// FF_INTANGABLEFLATS {value = 100663296; text = "Only tangible from sides.";} + FF_SHATTER {value = 134217728; text = "(Use with FF_BUSTUP) Breaks on any contact.";} + FF_SPINBUST {value = 268435456; text = "(Use with FF_BUSTUP) Breaks only with a spin from above.";} + FF_ONLYKNUX {value = 536870912; text = "(Use with FF_BUSTUP) Can only be broken by Knuckles.";} + FF_RIPPLE {value = 1073741824; text = "Employs a visual ripple effect.";} +// FF_COLORMAPONLY {value = 2147483648; text = "Ignores the control sector's light level.";} + } +} + +// LINEDEF TYPES --------------------------------------------------------------- + +linedeftypes +{ + misc + { + title = "Miscellaneous"; + values + { + 0 = "(normal)"; + 1 = "Per-Sector Gravity"; + 4 = "Speed Pad"; + 5 = "Camera Scanner"; + 6 = "Disable Linedef Effect On Level Load"; + 7 = "Sector Flat Alignment"; + 10 = "Culling Plane"; + 13 = "Heat Wave Effect"; + 50 = "Instantly Lower Floor On Level Load"; + 51 = "Instantly Raise Ceiling On Level Load"; + 63 = "Fake Floor/Ceiling Planes"; + 540 = "Floor Friction"; + } + } + + parameters + { + title = "Parameters"; + values + { + 2 = "Custom Exit"; + 3 = "Zoom Tube Parameters"; + 8 = "Sector Special Parameters"; + 9 = "Chain Parameters"; + 11 = "Rope Hang Parameters"; + 12 = "Rock Spawn Parameters"; + 64 = "Appearing/Disappearing FOF"; + 65 = " Bridge Thinker"; + } + } + + polyobject + { + title = "PolyObject"; + values + { + 20 = "First Line"; + 21 = "Explicity Include Line"; + 22 = "Parameters"; + 30 = "Waving Flag"; + } + } + + movement + { + title = "Plane Movement"; + values + { + 52 = "Continuously Falling Sector"; + 53 = "Continuous Floor/Ceiling Mover"; + 54 = "Continuous Floor Mover"; + 55 = "Continuous Ceiling Mover"; + 56 = "Continuous Two-Speed Floor/Ceiling Mover"; + 57 = "Continuous Two-Speed Floor Mover"; + 58 = "Continuous Two-Speed Ceiling Mover"; + 59 = "Activate Moving Platform"; + 60 = "Activate Moving Platform (Adjustable Speed)"; + 61 = "Crusher (Ceiling to Floor)"; + 62 = "Crusher (Floor to Ceiling)"; + } + } + + fofsolid + { + title = "FOF (solid)"; + values + { + 100 = "Solid, Opaque"; + 101 = "Solid, Opaque, No Shadow"; + 102 = "Solid, Translucent"; + 103 = "Solid, Sides Only"; + 104 = "Solid, No Sides"; + 105 = "Solid, Invisible"; + 140 = "Intangible from Bottom, Opaque"; + 141 = "Intangible from Bottom, Translucent"; + 142 = "Intangible from Bottom, Translucent, No Sides"; + 143 = "Intangible from Top, Opaque"; + 144 = "Intangible from Top, Translucent"; + 145 = "Intangible from Top, Translucent, No Sides"; + 146 = "Only Tangible From Sides"; + } + } + + fofintangible + { + title = "FOF (intangible)"; + values + { + 120 = "Water, Opaque"; + 121 = "Water, Translucent"; + 122 = "Water, Opaque, No Sides"; + 123 = "Water, Translucent, No Sides"; + 220 = "Intangible, Opaque"; + 221 = "Intangible, Translucent"; + 222 = "Intangible, Sides Only"; + 223 = "Intangible, Invisible"; + } + } + + fofbobbing + { + title = "FOF (bobbing)"; + values + { + 150 = " Air Bobbing"; + 151 = " Air Bobbing (Adjustable)"; + 152 = " Reverse Air Bobbing (Adjustable)"; + 160 = "Floating, Bobbing"; + 190 = "Rising Platform, Solid, Opaque"; + 191 = "Rising Platform, Solid, Opaque, No Shadow"; + 192 = "Rising Platform, Solid, Translucent"; + 193 = "Rising Platform, Solid, Invisible"; + 194 = "Rising Platform, Intangible from Bottom, Opaque"; + 195 = "Rising Platform, Intangible from Bottom, Translucent"; + } + } + + fofcrumbling + { + title = "FOF (crumbling)"; + values + { + 170 = "Crumbling (Respawn)"; + 171 = "Crumbling (No Respawn)"; + 172 = "Crumbling (Respawn), Intangible from Bottom"; + 173 = "Crumbling (No Respawn), Intangible from Bottom"; + 174 = "Crumbling (Respawn), Int. from Bottom, Translucent"; + 175 = "Crumbling (No Respawn), Int. from Bottom, Translucent"; + 176 = "Crumbling (Respawn), Floating, Bobbing"; + 177 = "Crumbling (No Respawn), Floating, Bobbing"; + 178 = "Crumbling (Respawn), Floating"; + 179 = "Crumbling (No Respawn), Floating"; + 180 = "Crumbling (Respawn), Air Bobbing"; + } + } + + fofspecial + { + title = "FOF (special)"; + values + { + 200 = "Light Block"; + 201 = "Half Light Block"; + 202 = "Fog Block"; + 250 = "Mario Block"; + 251 = "Thwomp Block"; + 252 = "Shatter Block"; + 253 = "Shatter Block, Translucent"; + 254 = "Bustable Block"; + 255 = "Spin Bust Block"; + 256 = "Spin Bust Block, Translucent"; + 257 = "Quicksand"; + 258 = "Laser"; + 259 = "Custom FOF"; + } + } + + trigger + { + title = "Linedef Executor Trigger"; + values + { + 300 = "Continuous"; + 301 = "Each Time"; + 302 = "Once"; + 303 = "Ring Count - Continuous"; + 304 = "Ring Count - Once"; + 305 = "Character Ability - Once"; + 306 = "Character Ability - Each Time"; + 307 = "Character Ability - Continuous"; + 308 = "Race Only - Once"; + 309 = "CTF Red Team - Continuous"; + 310 = "CTF Red Team - Each Time"; + 311 = "CTF Blue Team - Continuous"; + 312 = "CTF Blue Team - Each Time"; + 313 = "No More Enemies - Once"; + 314 = "Number of Pushables - Continuous"; + 315 = "Number of Pushables - Once"; + 316 = "Land On PolyObject"; + 399 = "Level Load"; + } + } + + execsector + { + title = "Linedef Executor (sector)"; + values + { + 400 = "Set Tagged Sector's Floor Height/Texture"; + 401 = "Set Tagged Sector's Ceiling Height/Texture"; + 402 = "Set Tagged Sector's Light Level"; + 409 = "Change Tagged Sectors' Tag"; + 410 = "Change Front Sector's Tag"; + 416 = "Start Adjustable Fire Flicker"; + 417 = "Start Adjustable Glowing Light"; + 418 = "Start Adjustable Blinking Light (unsynchronized)"; + 419 = "Start Adjustable Blinking Light (synchronized)"; + 420 = "Fade Light Level"; + 421 = "Stop Lighting Effect"; + 435 = "Change Plane Scroller Direction"; + } + } + + execplane + { + title = "Linedef Executor (plane movement)"; + values + { + 403 = "Move Tagged Sector's Floor"; + 404 = "Move Tagged Sector's Ceiling"; + 405 = "Lower Floor According to Linedef"; + 406 = "Raise Floor According to Linedef"; + 407 = "Lower Ceiling According to Linedef"; + 408 = "Raise Ceiling According to Linedef"; + 411 = "Stop Plane Movement"; + 428 = "Start Platform Movement"; + 429 = "Crush Ceiling Once"; + 430 = "Crush Floor Once"; + 431 = "Crush Floor And Ceiling Once"; + } + } + + execplayer + { + title = "Linedef Executor (player/object)"; + values + { + 412 = "Teleporter"; + 425 = "Change Object State"; + 426 = "Stop Object"; + 427 = "Award Score"; + 432 = "Enable 2D Mode"; + 433 = "Disable 2D Mode"; + 434 = "Award Power-Up"; + 437 = "Disable Player Control"; + 438 = "Change Object Size"; + } + } + + execmisc + { + title = "Linedef Executor (misc.)"; + values + { + 413 = "Change Music"; + 414 = "Play Sound Effect"; + 415 = "Run Script"; + 422 = "Switch To Cut-Away View"; + 423 = "Change Sky"; + 424 = "Change Weather"; + 436 = "Shatter FOF"; + 450 = "Execute Linedef Executor"; + } + } + + execpoly + { + title = "Linedef Executor (polyobject)"; + values + { + 480 = "Door Slide"; + 481 = "Door Swing"; + 482 = "Move"; + 483 = "Move, Override"; + 484 = "Rotate Right"; + 485 = "Rotate Right, Override"; + 486 = "Rotate Left"; + 487 = "Rotate Left, Override"; + 488 = "Move by Waypoints"; + 489 = "Turn Invisible, Intangible"; + 490 = "Turn Visible, Tangible"; + 491 = "Set Translucency"; + } + } + + wall + { + title = "Wall Scrolling"; + values + { + 500 = "Scroll Wall Front Side Left"; + 501 = "Scroll Wall Front Side Right"; + 502 = "Scroll Wall According to Linedef"; + 503 = "Scroll Wall According to Linedef (Accelerative)"; + 504 = "Scroll Wall According to Linedef (Displacement)"; + 505 = "Scroll Texture by Front Side Offsets"; + 506 = "Scroll Texture by Back Side Offsets"; + } + } + + plane + { + title = "Plane Scrolling"; + values + { + 510 = "Scroll Floor Texture"; + 511 = "Scroll Floor Texture (Accelerative)"; + 512 = "Scroll Floor Texture (Displacement)"; + 513 = "Scroll Ceiling Texture"; + 514 = "Scroll Ceiling Texture (Accelerative)"; + 515 = "Scroll Ceiling Texture (Displacement)"; + 520 = "Carry Objects on Floor"; + 521 = "Carry Objects on Floor (Accelerative)"; + 522 = "Carry Objects on Floor (Displacement)"; + 523 = "Carry Objects on Ceiling"; + 524 = "Carry Objects on Ceiling (Accelerative)"; + 525 = "Carry Objects on Ceiling (Displacement)"; + 530 = "Scroll Floor Texture and Carry Objects"; + 531 = "Scroll Floor Texture and Carry Objects (Accelerative)"; + 532 = "Scroll Floor Texture and Carry Objects (Displacement)"; + 533 = "Scroll Ceiling Texture and Carry Objects"; + 534 = "Scroll Ceiling Texture and Carry Objects (Accelerative)"; + 535 = "Scroll Ceiling Texture and Carry Objects (Displacement)"; + } + } + + pusher + { + title = "Pusher"; + values + { + 541 = "Wind"; + 542 = "Upwards Wind"; + 543 = "Downwards Wind"; + 544 = "Current"; + 545 = "Upwards Current"; + 546 = "Downwards Current"; + 547 = "Push/Pull"; + } + } + + lighting + { + title = "Lighting"; + values + { + 600 = "Floor Lighting"; + 601 = "Ceiling Lighting"; + 602 = "Adjustable Pulsating Light"; + 603 = "Adjustable Flickering Light"; + 604 = "Adjustable Blinking Light (unsynchronized)"; + 605 = "Adjustable Blinking Light (synchronized)"; + 606 = "Colormap"; + } + } + + transwall + { + title = "Translucent Wall"; + values + { + 900 = "90% Opaque"; + 901 = "80% Opaque"; + 902 = "70% Opaque"; + 903 = "60% Opaque"; + 904 = "50% Opaque"; + 905 = "40% Opaque"; + 906 = "30% Opaque"; + 907 = "20% Opaque"; + 908 = "10% Opaque"; + 909 = "Fog Wall"; + } + } +} + +// THING FLAGS ----------------------------------------------------------------- + +thingflags +{ + 1 = "[0] Unused Flag"; + 2 = "[1] Object Flip"; + 4 = "[2] Object Special"; + 8 = "[3] Ambush"; + 16 = "(Used for Z offsets)"; +} + +/* THING TYPES ----------------------------------------------------------------- + +Color values are 24-bit RGB colors in decimal. + +*/ + +thingtypes +{ + starts + { + color = 223; // Blue (0000DF) + arrow = 1; + title = "Player Starts"; + width = 16; + height = 56; + zfactor = 32; + deaftext = "[3] Spawn On Ceiling"; + values + { + 1 + { + title = "Player 01 Start"; + sprite = "SUPTD0"; + } + 2 + { + title = "Player 02 Start"; + sprite = "SUPTD0"; + } + 3 + { + title = "Player 03 Start"; + sprite = "SUPTD0"; + } + 4 + { + title = "Player 04 Start"; + sprite = "SUPTD0"; + } + 5 + { + title = "Player 05 Start"; + sprite = "SUPTD0"; + } + 6 + { + title = "Player 06 Start"; + sprite = "SUPTD0"; + } + 7 + { + title = "Player 07 Start"; + sprite = "SUPTD0"; + } + 8 + { + title = "Player 08 Start"; + sprite = "SUPTD0"; + } + 9 + { + title = "Player 09 Start"; + sprite = "SUPTD0"; + } + 10 + { + title = "Player 10 Start"; + sprite = "SUPTD0"; + } + 11 + { + title = "Player 11 Start"; + sprite = "SUPTD0"; + } + 12 + { + title = "Player 12 Start"; + sprite = "SUPTD0"; + } + 13 + { + title = "Player 13 Start"; + sprite = "SUPTD0"; + } + 14 + { + title = "Player 14 Start"; + sprite = "SUPTD0"; + } + 15 + { + title = "Player 15 Start"; + sprite = "SUPTD0"; + } + 16 + { + title = "Player 16 Start"; + sprite = "SUPTD0"; + } + 17 + { + title = "Player 17 Start"; + sprite = "SUPTD0"; + } + 18 + { + title = "Player 18 Start"; + sprite = "SUPTD0"; + } + 19 + { + title = "Player 19 Start"; + sprite = "SUPTD0"; + } + 20 + { + title = "Player 20 Start"; + sprite = "SUPTD0"; + } + 21 + { + title = "Player 21 Start"; + sprite = "SUPTD0"; + } + 22 + { + title = "Player 22 Start"; + sprite = "SUPTD0"; + } + 23 + { + title = "Player 23 Start"; + sprite = "SUPTD0"; + } + 24 + { + title = "Player 24 Start"; + sprite = "SUPTD0"; + } + 25 + { + title = "Player 25 Start"; + sprite = "SUPTD0"; + } + 26 + { + title = "Player 26 Start"; + sprite = "SUPTD0"; + } + 27 + { + title = "Player 27 Start"; + sprite = "SUPTD0"; + } + 28 + { + title = "Player 28 Start"; + sprite = "SUPTD0"; + } + 29 + { + title = "Player 29 Start"; + sprite = "SUPTD0"; + } + 30 + { + title = "Player 30 Start"; + sprite = "SUPTD0"; + } + 31 + { + title = "Player 31 Start"; + sprite = "SUPTD0"; + } + 32 + { + title = "Player 32 Start"; + sprite = "SUPTD0"; + } + 33 + { + title = "Match Start"; + sprite = "SUPTI0"; + } + 34 + { + title = "CTF Red Team Start"; + sprite = "SIGNG0"; + } + 35 + { + title = "CTF Blue Team Start"; + sprite = "SIGNE0"; + } + } + } + + enemies + { + color = 6250495; // Light blue (5F5FFF) + arrow = 1; + title = "Enemies"; + width = 24; + height = 32; + values + { + 100 + { + title = "Crawla (Blue)"; + sprite = "POSSA1"; + } + 101 + { + title = "Crawla (Red)"; + sprite = "SPOSA1"; + } + 102 + { + title = "Stupid Dumb Unnamed RoboFish"; + sprite = "FISHA0"; + width = 8; + height = 28; + } + 103 + { + title = "Buzz (Gold)"; + sprite = "BUZZA1"; + width = 20; + height = 24; + } + 104 + { + title = "Buzz (Red)"; + sprite = "RBUZA1"; + width = 20; + height = 24; + } + 105 + { + title = "Jetty-Syn Bomber"; + sprite = "JETBB1"; + width = 20; + } + 106 + { + title = "Jetty-Syn Gunner"; + sprite = "JETGB1"; + width = 20; + } + 107 + { + title = "Crawla Commander"; + sprite = "CCOMA1"; + width = 16; + } + 108 + { + title = "Deton"; + sprite = "DETNA1"; + width = 20; + } + 109 + { + title = "Skim"; + sprite = "SKIMA1"; + width = 16; + height = 24; + } + 110 + { + title = "Turret"; + sprite = "TRETA1"; + width = 16; + height = 32; + } + 111 + { + title = "Popup Turret"; + sprite = "TURRI1"; + width = 12; + height = 64; + } + 112 + { + title = "Sharp"; + sprite = "SHRPA1"; + width = 16; + height = 24; + } + 113 + { + title = "Jet Jaw"; + sprite = "JJAWA3A7"; + width = 12; + height = 20; + } + 114 + { + title = "Snailer"; + sprite = "SNLRA3A7"; + height = 48; + } + 115 + { + title = "Bird Aircraft Strike Hazard"; + sprite = "VLTRF1"; + width = 12; + height = 24; + } + 116 + { + title = "Pointy"; + sprite = "PNTYA1"; + width = 8; + height = 16; + } + 117 + { + title = "Robo-Hood"; + sprite = "ARCHA1"; + deaftext = "[3] Unknown Effect"; + } + 118 + { + title = "CastleBot FaceStabber"; + sprite = "CBFSA1"; + width = 32; + height = 64; + } + 119 + { + title = "Egg Guard"; + sprite = "ESHIA1"; + width = 16; + height = 48; + } + 120 + { + title = "Green Snapper"; + sprite = "GSNPA1"; + height = 24; + } + 121 + { + title = "Minus"; + sprite = "MNUSA1"; + } + 750 + { + title = " Chaos Enemy Spawn"; + sprite = "TFOGG0"; + width = 32; + height = 64; + } + } + } + + bosses + { + color = 6250335; // Grey (5F5F5F) + arrow = 1; + title = "Bosses"; + width = 24; + height = 52; + zfactor = 32; + values + { + 200 + { + title = "Boss 1 - Egg Mobile"; + sprite = "EGGMA1"; + spectext = "[2] End Level When Defeated"; + deaftext = "[3] Rotating Spikeballs"; + } + 201 + { + title = "Boss 2 - Egg Slimer"; + sprite = "EGGNA1"; + height = 48; + spectext = "[2] End Level When Defeated"; + deaftext = "[3] Speed Up When Hit"; + } + 202 + { + title = "Boss 3 - Sea Egg"; + sprite = "EGGOA1"; + width = 32; + height = 80; + spectext = "[2] End Level When Defeated"; + deaftext = "[3] Unknown Effect"; + } + 203 + { + title = " Boss 4 - Eggscalibur"; + sprite = "EGGPA1"; + } + 206 + { + title = "Boss 5 - Black Eggman"; + sprite = "BRAKB1"; + width = 48; + height = 160; + } + 290 + { + arrow = 0; + title = "Boss Escape Point"; + width = 8; + height = 16; + zfactor = 16; + } + 291 + { + arrow = 0; + title = "Egg Trap Center"; + width = 8; + height = 16; + zfactor = 16; + } + 292 + { + arrow = 0; + title = "Boss Waypoint"; + width = 8; + height = 16; + zfactor = 16; + } + } + } + + rings + { + color = 12566272; // Yellow (BFBF00) + title = "Rings and Weapon Panels"; + width = 24; + height = 24; + deafheight = 32; + deaftext = "[3] Float"; + values + { + 300 + { + title = "Ring"; + sprite = "RINGA0"; + width = 16; + } + 301 + { + title = "Bounce Ring"; + sprite = "CPRKB0"; + } + 302 + { + title = "Rail Ring"; + sprite = "SPRKA0"; + } + 304 + { + title = "Automatic Ring"; + sprite = "TAUTA3A7"; + } + 305 + { + title = "Explosion Ring"; + sprite = "BMSLA1"; + } + 306 + { + title = "Scatter Ring"; + sprite = "TSCRA1A5"; + } + 307 + { + title = "Grenade Ring"; + sprite = "TGREA0"; + } + 308 + { + title = "CTF Team Ring (Red)"; + sprite = "RRNGA0"; + width = 16; + } + 309 + { + title = "CTF Team Ring (Blue)"; + sprite = "TRNGA0"; + width = 16; + } + 330 + { + title = "Bounce Ring Panel"; + sprite = "PIKBA0"; + } + 331 + { + title = "Rail Ring Panel"; + sprite = "PIKRA0"; + } + 332 + { + title = "Automatic Ring Panel"; + sprite = "PIKAA0"; + } + 333 + { + title = "Explosion Ring Panel"; + sprite = "PIKEA0"; + } + 334 + { + title = "Scatter Ring Panel"; + sprite = "PIKSA0"; + } + 335 + { + title = "Grenade Ring Panel"; + sprite = "PIKGA0"; + } + } + } + + collectibles + { + color = 48896; // Green (00BF00) + title = "Other Collectibles"; + width = 16; + height = 32; + values + { + 310 + { + title = "CTF Red Flag"; + sprite = "RFLGA0"; + width = 24; + height = 64; + } + 311 + { + title = "CTF Blue Flag"; + sprite = "BFLGA0"; + width = 24; + height = 64; + } + 312 + { + title = "Special Stage Token"; + sprite = "TOKEA0"; + width = 8; + height = 16; + deafheight = 32; + deaftext = "[3] Float"; + } + 313 + { + title = "Chaos Emerald 1 (Green)"; + sprite = "EMMYA0"; + } + 314 + { + title = "Chaos Emerald 2 (Orange)"; + sprite = "EMMYB0"; + } + 315 + { + title = "Chaos Emerald 3 (Purple)"; + sprite = "EMMYC0"; + } + 316 + { + title = "Chaos Emerald 4 (Blue)"; + sprite = "EMMYD0"; + } + 317 + { + title = "Chaos Emerald 5 (Red)"; + sprite = "EMMYE0"; + } + 318 + { + title = "Chaos Emerald 6 (Light Blue)"; + sprite = "EMMYF0"; + } + 319 + { + title = "Chaos Emerald 7 (Gray)"; + sprite = "EMMYG0"; + } + 320 + { + title = "Emerald Hunt Location"; + sprite = "EMERA0"; + } + 323 + { + title = "Match Chaos Emerald Spawn"; + sprite = "CEMGA0"; + width = 8; + height = 48; + deafheight = 32; + deaftext = "[3] Float"; + } + } + } + + boxes + { + color = 12566463; // Silver (BFBFBF) + blocking = 2; + title = "Item Boxes"; + width = 16; + height = 32; + spectext = "[2] Random (Strong)"; + deaftext = "[3] Random (Weak)"; + values + { + 400 + { + title = "Super Ring (10 Rings)"; + sprite = "SRBXA0"; + } + 402 + { + title = "Attraction Shield"; + sprite = "YLTVA0"; + } + 403 + { + title = "Force Shield"; + sprite = "BLTVA0"; + } + 404 + { + title = "Armageddon Shield"; + sprite = "BKTVA0"; + } + 405 + { + title = "Whirlwind Shield"; + sprite = "WHTVA0"; + } + 406 + { + title = "Elemental Shield"; + sprite = "GRTVA0"; + } + 407 + { + title = "Super Sneakers"; + sprite = "SHTVA0"; + } + 408 + { + title = "Invincibility"; + sprite = "PINVA0"; + } + 409 + { + title = "Extra Life"; + sprite = "MTEXA0"; + } + 410 + { + title = "Eggman"; + sprite = "EGGBA0"; + } + 411 + { + title = "Teleporter"; + sprite = "MIXUA0"; + } + 412 + { + title = "Random"; + sprite = "QUESA0"; + } + 413 + { + title = "Gravity Boots"; + sprite = "GBTVA0"; + } + 414 + { + title = "CTF Team Ring Box (Red)"; + sprite = "RRBXA0"; + spectext = "[2] Object Special"; + deaftext = "[3] Ambush"; + } + 415 + { + title = "CTF Team Ring Box (Blue)"; + sprite = "BRBXA0"; + spectext = "[2] Object Special"; + deaftext = "[3] Ambush"; + } + 416 + { + title = "Recycler"; + sprite = "RECYA0"; + } + } + } + + miscellaneous + { + color = 49119; // Sky blue (00BFDF) + title = "Miscellaneous"; + width = 16; + height = 40; + values + { + 500 + { + title = "Air Bubble Patch"; + sprite = "BUBLA0"; + width = 8; + height = 16; + } + 501 + { + title = "End Level Sign"; + sprite = "SIGND0"; + width = 8; + height = 32; + } + 502 + { + arrow = 1; + title = "Star Post"; + sprite = "STPTA0"; + width = 64; + height = 80; + } + 526 + { + blocking = 2; + title = "Cannonball"; + sprite = "CBLLA0"; + width = 20; + spectext = "[2] Light And Bouncy"; + deaftext = "[3] Not Pushable"; + } + 1000 + { + arrow = 1; + blocking = 2; + title = "Gargoyle"; + sprite = "GARGA1"; + spectext = "[2] Light And Bouncy"; + deaftext = "[3] Not Pushable"; + } + 1102 + { + arrow = 1; + blocking = 2; + title = "Eggman Statue"; + sprite = "ESTAA1"; + width = 32; + height = 240; + spectext = "[2] Light And Bouncy"; + deaftext = "[3] Not Pushable"; + } + 1106 + { + arrow = 1; + title = "Chain (Hang)"; + sprite = "SMCHA0"; + height = 32; + deaftext = "[3] Double Size"; + } + 1107 + { + arrow = 1; + title = "Chain (Spin)"; + sprite = "SMCHA0"; + height = 32; + } + 1200 + { + title = "Tumbleweed (Big)"; + sprite = "BTBLA0"; + width = 24; + height = 28; + deaftext = "[3] Moves Perpetually"; + } + 1201 + { + title = "Tumbleweed (Small)"; + sprite = "STBLA0"; + width = 12; + height = 24; + deaftext = "[3] Moves Perpetually"; + } + 1852 + { + blocking = 2; + title = "Snowman"; + sprite = "XMS3A0"; + spectext = "[2] Light And Bouncy"; + deaftext = "[3] Not Pushable"; + } + 1876 + { + arrow = 1; + blocking = 2; + title = "Eggman Disco Statue"; + sprite = "ESTAB1"; + width = 20; + height = 96; + spectext = "[2] Light And Bouncy"; + deaftext = "[3] Not Pushable"; + } + } + } + + springs + { + color = 14614528; // Red (DF0000) + title = "Springs and Fans"; + width = 20; + height = 16; + values + { + 540 + { + title = "Fan"; + sprite = "FANSA0"; + width = 16; + } + 541 + { + title = "Gas Jet"; + sprite = "STEMD0"; + width = 32; + } + 550 + { + title = "Yellow Spring"; + sprite = "SPRYA0"; + } + 551 + { + title = "Red Spring"; + sprite = "SPRRA0"; + } + 552 + { + title = "Blue Spring"; + sprite = "SPRBA0"; + } + 553 + { + title = "Yellow Spring (Ceiling)"; + sprite = "SUDYA0"; + hangs = 1; + } + 554 + { + title = "Red Spring (Ceiling)"; + sprite = "SUDRA0"; + hangs = 1; + } + 555 + { + arrow = 1; + title = "Diagonal Yellow Spring"; + sprite = "YSPRD2"; + width = 16; + deaftext = "[3] Rotate 22.5° CCW"; + } + 556 + { + arrow = 1; + title = "Diagonal Red Spring"; + sprite = "RSPRD2"; + width = 16; + deaftext = "[3] Rotate 22.5° CCW"; + } + 557 + { + arrow = 1; + title = "Diagonal Yellow Spring (Ceiling)"; + sprite = "YSUDE2"; + width = 16; + hangs = 1; + deaftext = "[3] Rotate 22.5° CCW"; + } + 558 + { + arrow = 1; + title = "Diagonal Red Spring (Ceiling)"; + sprite = "RSUDE2"; + width = 16; + hangs = 1; + deaftext = "[3] Rotate 22.5° CCW"; + } + } + } + + patterns + { + color = 10420319; // Dark Rose (9F005F) + arrow = 1; + title = "Special Placement Patterns"; + width = 16; + height = 384; + values + { + 600 + { + arrow = 0; + title = "5 Vertical Rings (Yellow Spring)"; + sprite = "RINGA0"; + } + 601 + { + arrow = 0; + title = "5 Vertical Rings (Red Spring)"; + sprite = "RINGA0"; + height = 1024; + } + 602 + { + title = "5 Diagonal Rings (Yellow Spring)"; + sprite = "RINGA0"; + height = 32; + } + 603 + { + title = "10 Diagonal Rings (Red Spring)"; + sprite = "RINGA0"; + height = 32; + } + 604 + { + title = "Circle of Rings"; + sprite = "RINGA0"; + width = 96; + height = 192; + } + 605 + { + title = "Circle of Rings (Big)"; + sprite = "RINGA0"; + width = 192; + } + 606 + { + title = "Circle of Wing Logos"; + sprite = "NWNGA0"; + width = 96; + height = 192; + } + 607 + { + title = "Circle of Wing Logos (Big)"; + sprite = "NWNGA0"; + width = 192; + } + 608 + { + title = "Circle of Rings and Wings"; + sprite = "NWNGA0"; + width = 96; + height = 192; + } + 609 + { + title = "Circle of Rings and Wings (Big)"; + sprite = "NWNGA0"; + width = 192; + } + } + } + + invisible + { + color = 16777215; // White (FFFFFF) + title = "Misc. Invisible"; + width = 8; + height = 16; + values + { + 700 = "Water Ambience A (Large)"; + 701 = "Water Ambience B (Large)"; + 702 = "Water Ambience C (Medium)"; + 703 = "Water Ambience D (Medium)"; + 704 = "Water Ambience E (Small)"; + 705 = "Water Ambience F (Small)"; + 706 = "Water Ambience G (Extra Large)"; + 707 = "Water Ambience H (Extra Large)"; + 708 = "Disco Ambience"; + 709 = "Volcano Ambience"; + 751 + { + arrow = 1; + title = "Teleport Destination"; + } + 752 + { + arrow = 1; + title = "Alternate View Point"; + } + 753 = "Zoom Tube Waypoint"; + 754 + { + title = "Push Point"; + spectext = "[2] No Z Fade"; + deaftext = "[3] Push Using XYZ"; + } + 755 + { + title = "Pull Point"; + spectext = "[2] No Z Fade"; + deaftext = "[3] Pull Using XYZ"; + } + 760 = "PolyObject Anchor"; + 761 = "PolyObject Spawn Point"; + 762 = "PolyObject Spawn Point (Crush)"; + } + } + + hazards + { + color = 10420224; // Maroon (9F0000) + title = "Hazards"; + width = 20; + height = 40; + values + { + 521 + { + title = "Spikeball"; + sprite = "SPIKA0"; + width = 12; + height = 24; + deafheight = 32; + deaftext = "[3] Float"; + } + 522 + { + blocking = 2; + title = "Spike (Ceiling)"; + sprite = "DSPKA0"; + width = 8; + height = 42; + hangs = 1; + } + 523 + { + title = "Spike (Floor)"; + sprite = "USPKA0"; + width = 8; + height = 42; + deaftext = "[3] Solid"; + } + 524 + { + arrow = 1; + title = "Big Floating Mine"; + width = 16; + height = 32; + sprite = "BMNEA1"; + } + 527 + { + arrow = 1; + title = "Big Floating Mine (Air)"; + width = 16; + height = 32; + sprite = "BMNEA1"; + } + 525 + { + title = "Cannonball Launcher"; + sprite = "CBLLA0"; + } + 1101 + { + title = "Torch"; + sprite = "FLAMA0"; + width = 8; + height = 32; + } + 1104 + { + title = "Mace (Spinning)"; + sprite = "SMCEA0"; + deaftext = "[3] Double Size"; + } + 1105 + { + title = "Mace (Swinging)"; + sprite = "SMCEA0"; + deaftext = "[3] Double Size"; + } + 1202 + { + arrow = 1; + title = "Rock Spawner"; + sprite = "ROIAA0"; + } + 1300 + { + arrow = 1; + title = "Flame Jet (Horizontal)"; + sprite = "FLMEB0"; + width = 16; + } + 1301 + { + title = "Flame Jet (Vertical)"; + sprite = "FLMEB0"; + width = 16; + deaftext = "[3] Shoot Downwards"; + } + } + } + + decoration + { + color = 4153088; // Dark lime (3F5F00) + title = "Decoration"; + width = 16; + height = 40; + values + { + 757 + { + title = "Fan Particle Generator"; + sprite = "PRTLA0"; + width = 8; + height = 16; + } + 800 + { + title = "GFZ Flower"; + sprite = "FWR1A0"; + } + 801 + { + title = "Sunflower"; + sprite = "FWR2A0"; + height = 96; + } + 802 + { + title = "Budding Flower"; + sprite = "FWR3A0"; + width = 8; + height = 32; + } + 804 + { + title = "Berry Bush"; + sprite = "BUS1A0"; + height = 32; + } + 805 + { + title = "Bush"; + sprite = "BUS2A0"; + height = 32; + } + 900 + { + title = "THZ Flower"; + sprite = "THZPA0"; + width = 8; + height = 32; + } + 901 + { + title = "Alarm"; + sprite = "ALRMA0"; + width = 8; + height = 16; + hangs = 1; + } + 1001 + { + title = "Seaweed"; + sprite = "SEWEA0"; + width = 24; + height = 56; + } + 1002 + { + title = "Dripping Water"; + sprite = "DRIPD0"; + width = 8; + height = 16; + hangs = 1; + } + 1003 + { + title = "Coral (Green)"; + sprite = "CRL1A0"; + width = 8; + height = 16; + } + 1004 + { + title = "Coral (Red)"; + sprite = "CRL2A0"; + width = 8; + height = 16; + } + 1005 + { + title = "Coral (Orange)"; + sprite = "CRL3A0"; + width = 8; + height = 16; + } + 1006 + { + title = "Blue Crystal"; + sprite = "BCRYA1"; + width = 8; + height = 16; + } + 1100 + { + title = "Chain"; + sprite = "CHANA0"; + width = 8; + height = 128; + hangs = 1; + } + 1103 + { + title = "CEZ Flower"; + sprite = "FWR4A0"; + } + 1203 + { + title = "Cactus with Brown Flower"; + sprite = "CACTA0"; + height = 32; + } + 1204 + { + title = "Cactus with Brown Flower (Tall)"; + sprite = "CACTB0"; + height = 64; + } + 1205 + { + title = "Cactus with Blue Flower"; + sprite = "CACTC0"; + height = 32; + } + 1206 + { + title = "Cactus with Blue Flower (Tall)"; + sprite = "CACTD0"; + height = 80; + } + 1850 + { + title = "Xmas Pole"; + sprite = "XMS1A0"; + } + 1851 + { + title = "Candy Cane"; + sprite = "XMS2A0"; + width = 8; + height = 32; + } + 1875 + { + title = "Disco Ball"; + sprite = "DBALA0"; + height = 54; + hangs = 1; + } + 1900 + { + title = "Brown Stalagmite (Tall)"; + sprite = "STG0A0"; + } + 1901 + { + title = "Brown Stalagmite"; + sprite = "STG1A0"; + width = 16; + height = 40; + } + 1902 + { + title = "Orange Stalagmite (Tall)"; + sprite = "STG2A0"; + } + 1903 + { + title = "Orange Stalagmite"; + sprite = "STG3A0"; + } + 1904 + { + title = "Red Stalagmite (Tall)"; + sprite = "STG4A0"; + } + 1905 + { + title = "Red Stalagmite"; + sprite = "STG5A0"; + } + 1906 + { + title = "Gray Stalagmite (Tall)"; + sprite = "STG6A0"; + } + 1907 + { + title = "Gray Stalagmite"; + sprite = "STG7A0"; + } + 1908 + { + title = "Blue Stalagmite (Tall)"; + sprite = "STG8A0"; + } + 1909 + { + title = "Blue Stalagmite"; + sprite = "STG9A0"; + } + } + } + + nights + { + color = 12517599; // Violet (BF00DF) + title = "Nights Items"; + width = 12; + height = 32; + values + { + 1700 + { + title = "Axis"; + width = 8; + height = 2048; + circle = 1; + } + 1701 + { + title = "Axis Transfer"; + width = 8; + height = 2048; + } + 1702 + { + title = "Axis Transfer Line"; + width = 8; + height = 2048; + } + 1703 + { + title = "Ideya Drone"; + sprite = "NDRNA1"; + width = 16; + height = 56; + deaftext = "[3] Die Upon Time Up"; + } + 1704 + { + arrow = 1; + title = "Bumper"; + sprite = "NBMPG3G7"; + width = 32; + height = 64; + } + 1705 + { + arrow = 1; + title = "Hoop"; + sprite = "HOOPA0"; + width = 80; + height = 160; + } + 1706 + { + title = "Wing Logo"; + sprite = "NWNGA0"; + height = 24; + } + 1707 + { + title = "Super Loop"; + sprite = "NPRAA0"; + } + 1708 + { + title = "Drill Refill"; + sprite = "NPRBA0"; + } + 1709 + { + title = "Helper"; + sprite = "NPRCA0"; + } + 1710 + { + title = "Egg Capsule"; + sprite = "CAPSA0"; + width = 72; + height = 144; + } + } + } + + mario + { + color = 14647040; // Orange (DF7F00) + title = "Mario Items"; + width = 16; + height = 32; + values + { + 1800 + { + title = "Coin"; + sprite = "COINA0"; + height = 24; + deafheight = 32; + deaftext = "[3] Float"; + } + 1801 + { + arrow = 1; + title = "Goomba"; + sprite = "GOOMA0"; + width = 24; + } + 1802 + { + arrow = 1; + title = "Goomba (Blue)"; + sprite = "BGOMA0"; + width = 24; + } + 1803 + { + title = "Fire Flower"; + sprite = "FFWRB0"; + } + 1804 + { + title = "Koopa Shell"; + sprite = "SHLLA0"; + width = 8; + height = 16; + } + 1805 + { + title = "Puma (Jumping Fireball)"; + sprite = "PUMAA0"; + width = 8; + height = 16; + } + 1806 + { + title = "King Bowser"; + sprite = "KOOPA0"; + height = 48; + } + 1807 + { + title = "Axe"; + sprite = "MAXEA0"; + width = 8; + height = 16; + } + 1808 + { + title = "Bush (Short)"; + sprite = "MUS1A0"; + } + 1809 + { + title = "Bush (Tall)"; + sprite = "MUS2A0"; + } + 1810 + { + title = "Toad"; + sprite = "TOADA0"; + width = 8; + } + } + } + + srb1 + { + color = 32607; // Teal (007F5F) + arrow = 1; + title = "SRB1 Remake Items"; + width = 20; + height = 32; + values + { + 4000 + { + title = "SRB1 Crawla"; + sprite = "SRBAA1"; + height = 40; + } + 4001 + { + title = "GuardRobo"; + sprite = "SRBBA1"; + width = 17; + height = 40; + } + 4002 + { + title = "Pyrin"; + sprite = "SRBCB1"; + width = 22; + } + 4003 + { + title = "HotRobo"; + sprite = "SRBDA0"; + height = 40; + } + 4004 + { + title = "Pogminz"; + sprite = "SRBEA1"; + } + 4005 + { + title = "Pogminz (Water)"; + sprite = "SRBEA1"; + } + 4006 + { + title = "Pog-GX2"; + sprite = "SRBFA0"; + width = 10; + height = 34; + } + 4007 + { + title = "Pyrex"; + sprite = "SRBGA1"; + width = 24; + } + 4008 + { + title = "UFO"; + sprite = "SRBHA0"; + width = 24; + hangs = 1; + } + 4009 + { + title = "SWAT Bot"; + sprite = "SRBIA1"; + width = 21; + height = 69; + } + 4010 + { + title = "SpyBot 2000"; + sprite = "SRBJA0"; + width = 36; + height = 62; + } + 4011 + { + title = "Buzz Bomber"; + sprite = "SRBKA0"; + width = 44; + height = 45; + } + 4012 + { + arrow = 0; + title = "RBZ Spike"; + sprite = "SRBLA0"; + width = 10; + height = 53; + } + 4013 + { + arrow = 0; + blocking = 2; + title = "Dumb Metal Sonic"; + sprite = "SRBMC0"; + width = 16; + height = 40; + spectext = "[2] Light And Bouncy"; + deaftext = "[3] Not Pushable"; + } + 4014 + { + title = "Super SWAT Bot"; + sprite = "SRBNA1"; + width = 21; + height = 69; + } + 4015 + { + title = "Genrex"; + sprite = "SRBOA1"; + width = 17; + height = 40; + } + } + } +} diff --git a/extras/conf/Srb2-21db.cfg b/extras/conf/Srb2-21db.cfg new file mode 100644 index 000000000..a7c4dbf75 --- /dev/null +++ b/extras/conf/Srb2-21db.cfg @@ -0,0 +1,2832 @@ +/******************************************************************************\ + + SRB2 Doom Builder + Game Configuration for SRB2 version 2.1. + + Contributors: + - Kristos + - Shadow Hog + - ST218 + - Foxboy + - JJames19119 + - SRB2-Playah + - Oogaland + - SSNTails + - DarkWarrior + - Neo + - Morpheus + - Trinity + +\******************************************************************************/ + +// This is required to prevent accedential use of a different configuration. +type = "SRB2 Doom Builder Game Configuration"; + +// This is the title to show for this game. +game = "Sonic Robo Blast 2 v2.1"; + +// Map format determines the way the map will be loaded. +mapformat = 1; + +// Flags for changes in 2.0. +seceffectnybble = 1; + +// Default flags for first new thing. +defaulthingflags = 0; + +// Default lump name for new map. +defaultlumpname = "MAP01"; + +// Load textures/flats by default from this file. +texturesfile = ""; + +// Thing number for start position in 3D Mode. +start3dmode = 32000; + +// Thing number for control sector position hint. +ctrlsechint = 32001; + +// Zoom tube waypoint, for the wizard. +zoomtubewaypoint = 753; + +// No generalized types. +generalizedlinedefs = 0; +generalizedsectors = 0; + +/* TEXTURES AND FLAT SOURCES --------------------------------------------------- + +This tells Doom Builder where to find the information for textures and flats in +the IWAD file, Addition WAD file and Map WAD file. + +Start and end lumps must be given in a structure (of which the key name doesn't +matter) and any textures or flats in between them are loaded in either the +textures category or flats category. + +For textures: PNAMES, TEXTURE1 and TEXTURE2 are loaded by default. + +*/ + +// Texture sources. +textures +{ + zdoom1 + { + start = "TX_START"; + end = "TX_END"; + } +} + +// Flat sources. +flats +{ + standard1 + { + start = "F_START"; + end = "F_END"; + } + + standard2 + { + start = "FF_START"; + end = "FF_END"; + } + + standard3 + { + start = "FF_START"; + end = "F_END"; + } + + standard4 + { + start = "F_START"; + end = "FF_END"; + } +} + +/* TEXTURES AND FLATS FILTERING ------------------------------------------------ + +This allows you to filter textures and flats so that you only see the +textures/flats listed that you prefer to use. + +The key name doesn't matter here, only the values. + +Pattern-matching is performed on lump names. You can use the following wildcards +in values to specify ranges: + +? = Any character. +* = Zero or more characters. +# = Any numeric digit. +[abc...] = Any of these characters that are between brackets. +[!abc..] = Not any of these characters that are between brackets. + +*/ + +// List these textures... +texturesfilter +{ + all_textures = "*"; +} + +// But do not list these textures... +notexturesfilter +{ + none = ""; +} + +// List these flats... +flatsfilter +{ + all_flats = "*"; +} + +// But do not list these flats... +noflatsfilter +{ + none = ""; +} + +/* PSEUDO-FLATS AND TEXTURES --------------------------------------------------- + +Names of flats and textures that don't really exist, but shouldn't be identified +as invalid. + +Pattern-matching is performed on lump names. See above for syntax. + +*/ + +pseudoflats +{ + F_SKY1; +} + +pseudotextures +{ + [#]*; +} + +/* GAME DETECT PATTERN --------------------------------------------------------- + +Used to guess the game for which a WAD file is made. + +1 = One of these lumps must exist. +2 = None of these lumps must exist. +3 = All of these lumps must exist. + +Pattern-matching is performed on lump names. See above for syntax. + +*/ + +gamedetect +{ + EXTENDED = 2; + BEHAVIOR = 2; + E#M# = 2; + MAP?? = 1; +} + +/* MAP LUMP NAMES -------------------------------------------------------------- + +Map lumps are loaded with the map as long as they are right after each other. +When the editor meets a lump which is not defined in this list (or defined +as 0), it will stop loading right there. + +The order of items defines the order in which lumps will be written to WAD file +on save. The value (flags) of items determines what the editor should do with +it. You should never mess with value 4, because it may result in incorrect map +builds. + + 1 = Lump required. + 2 = Lump which must be respected. + 4 = Lump generated by node builder. + 8 = Lump allowed to be empty after nodebuilding. + 16 = Lump allowed to be missing after nodebuilding. + 4096 = Lump which can be edited as text. + 8192 = Lump which can be edited as DEHACKED. +12288 = Lump which can be edited as MAPINFO. +16384 = WAD-global. + +*/ + +maplumpnames +{ + THINGS = 13; + LINEDEFS = 5; + SIDEDEFS = 5; + VERTEXES = 5; + SEGS = 4; + SSECTORS = 4; + NODES = 4; + SECTORS = 5; + REJECT = 4; + BLOCKMAP = 20; + MAINCFG = 24576; +} + +// DEFAULT SECTOR BRIGHTNESS LEVELS -------------------------------------------- + +sectorbrightness +{ + 255; + 240; + 224; + 208; + 192; + 176; + 160; + 144; + 128; + 112; + 96; + 80; + 64; + 48; + 32; + 16; + 0; +} + +// SECTOR TYPES ---------------------------------------------------------------- + +sectortypes +{ + nybble0 + { + 0 = "(normal)"; + 1 = "Damage"; + 2 = "Damage (Water)"; + 3 = "Damage (Fire)"; + 4 = "Damage (Electrical)"; + 5 = "Spikes"; + 6 = "Death Pit (Camera Modifications)"; + 7 = "Death Pit (No Camera Modifications)"; + 8 = "Instant Kill"; + 9 = "Ring Drainer (Floor Touch)"; + 10 = "Ring Drainer (No Floor Touch)"; + 11 = "Special Stage Damage"; + 12 = "Space Countdown"; + 13 = "Ramp Sector (double step-up/down)"; + 14 = "Non-Ramp Sector (no step-down)"; + 15 = "Bouncy Sector (FOF Control Only)"; + } + + nybble1 + { + 0 = "(normal)"; + 1 = "Trigger Line Ex. (Pushable Objects)"; + 2 = "Trigger Line Ex. (Anywhere, All Players)"; + 3 = "Trigger Line Ex. (Floor Touch, All Players)"; + 4 = "Trigger Line Ex. (Anywhere in Sector)"; + 5 = "Trigger Line Ex. (Floor Touch)"; + 6 = "Trigger Line Ex. (Emerald Check)"; + 7 = "Trigger Line Ex. (Nights Mare)"; + 8 = " Check for Line Exec. on FOFs"; + 9 = "Egg Trap Capsule"; + 10 = "Special Stage Time/Rings Parameters"; + 11 = "Custom Global Gravity"; + } + + nybble2 + { + 0 = "(normal)"; + 1 = "Ice/Sludge"; + 2 = "Wind/Current"; + 3 = "Ice/Sludge and Wind/Current"; + 4 = "Conveyor Belt"; + 5 = "Speed Pad (No Spin)"; + 6 = "Speed Pad (Spin)"; + 7 = "Bustable Block Sprite Parameter (ROIA)"; + 8 = "Bustable Block Sprite Parameter (ROIB)"; + 9 = "Bustable Block Sprite Parameter (ROIC)"; + 10 = "Bustable Block Sprite Parameter (ROID)"; + 11 = "Bustable Block Sprite Parameter (ROIE)"; + 12 = "Bustable Block Sprite Parameter (ROIF)"; + 13 = "Bustable Block Sprite Parameter (ROIG)"; + 14 = "Bustable Block Sprite Parameter (ROIH)"; + 15 = "Bustable Block Sprite Parameter (ROII)"; + } + + nybble3 + { + 0 = "(normal)"; + 1 = "Star Post Activator"; + 2 = "Exit/Special Stage Goal/Return Flag"; + 3 = "CTF: Red Team Base"; + 4 = "CTF: Blue Team Base"; + 5 = "Fan Sector"; + 6 = "Super Sonic Transform"; + 7 = "Spinner"; + 8 = "Zoom Tube Start"; + 9 = "Zoom Tube End"; + 10 = "Finish Line"; + 11 = "Rope Hang"; + 12 = "Intangible to the Camera"; + } +} + +// LINEDEF FLAGS --------------------------------------------------------------- + +linedefflags +{ + 1 = "[0] Effect 6"; + 2 = "[1] Block Enemies"; + 4 = "[2] Double-Sided"; + 8 = "[3] Upper Unpegged"; + 16 = "[4] Lower Unpegged"; + 32 = "[5] Effect 1"; + 64 = "[6] Not Climbable"; + 128 = "[7] Effect 2"; + 256 = "[8] Effect 3"; + 512 = "[9] Effect 4"; + 1024 = "[10] Effect 5"; + 2048 = "[11] No Sonic"; + 4096 = "[12] No Tails"; + 8192 = "[13] No Knuckles"; + 16384 = "[14] Bouncy Wall"; + 32768 = "[15] Transfer Line"; +} + +// LINEDEF ACTIVATIONS --------------------------------------------------------- + +linedefactivations +{ +} + +/* FOF FLAGS ------------------------------------------------------------------- + +This is a hack. The FOF flag values have changed in 2.0, but the old 1.09.4 +values are hardcoded in the source for SRB2 Doom Builder. Until Oogaland fixes +this, I'm sticking some fake values in here to make 3D mode draw FOFs like it's +supposed to. --Neo + +Flags I've found relevant: + + 4 = Renders the walls. + 8 = Renders the planes. +32 = Doesn't cast a shadow. + +*/ + +fofs +{ + 100 = 12; + 101 = 44; + 102 = 44; + 103 = 36; + 104 = 40; + 105 = 32; + 120 = 12; + 121 = 12; + 122 = 8; + 123 = 8; + 124 = 12; + 125 = 8; + 140 = 12; + 141 = 12; + 142 = 8; + 143 = 12; + 144 = 12; + 145 = 8; + 146 = 4; + 150 = 12; + 151 = 12; + 152 = 12; + 160 = 12; + 170 = 12; + 171 = 12; + 172 = 12; + 173 = 12; + 174 = 12; + 175 = 12; + 176 = 12; + 177 = 12; + 178 = 12; + 179 = 12; + 180 = 12; + 190 = 12; + 191 = 44; + 192 = 44; + 193 = 32; + 194 = 12; + 195 = 12; + 200 = 0; + 201 = 0; + 202 = 0; + 220 = 12; + 221 = 44; + 222 = 36; + 223 = 32; + 250 = 12; + 251 = 12; + 252 = 12; + 253 = 12; + 254 = 12; + 255 = 12; + 256 = 12; + 257 = 12; + 258 = 44; + 259 = 12; +} + +// LINEDEF TYPES --------------------------------------------------------------- + +linedeftypes +{ + 0 = "Miscellaneous: (normal)"; + 1 = "Miscellaneous: Per-Sector Gravity"; + 2 = "Parameters: Custom Exit"; + 3 = "Parameters: Zoom Tube Parameters"; + 4 = "Miscellaneous: Speed Pad"; + 5 = "Miscellaneous: Camera Scanner"; + 6 = "Miscellaneous: Disable Linedef Effect On Level Load"; + 7 = "Miscellaneous: Sector Flat Alignment"; + 8 = "Parameters: Sector Special Parameters"; + 9 = "Parameters: Chain Parameters"; + 10 = "Miscellaneous: Culling Plane"; + 11 = "Parameters: Rope Hang Parameters"; + 12 = "Parameters: Rock Spawn Parameters"; + 13 = "Miscellaneous: Heat Wave Effect"; + 20 = "PolyObject: First Line"; + 21 = "PolyObject: Explicity Include Line"; + 22 = "PolyObject: Parameters"; + 30 = "PolyObject: Waving Flag"; + 50 = "Miscellaneous: Instantly Lower Floor On Level Load"; + 51 = "Miscellaneous: Instantly Raise Ceiling On Level Load"; + 52 = "Plane Movement: Continuously Falling Sector"; + 53 = "Plane Movement: Continuous Floor/Ceiling Mover"; + 54 = "Plane Movement: Continuous Floor Mover"; + 55 = "Plane Movement: Continuous Ceiling Mover"; + 56 = "Plane Movement: Continuous Two-Speed Floor/Ceiling Mover"; + 57 = "Plane Movement: Continuous Two-Speed Floor Mover"; + 58 = "Plane Movement: Continuous Two-Speed Ceiling Mover"; + 59 = "Plane Movement: Activate Moving Platform"; + 60 = "Plane Movement: Activate Moving Platform (Adjustable Speed)"; + 61 = "Plane Movement: Crusher (Ceiling to Floor)"; + 62 = "Plane Movement: Crusher (Floor to Ceiling)"; + 63 = "Miscellaneous: Fake Floor/Ceiling Planes"; + 64 = "Parameters: Appearing/Disappearing FOF"; + 65 = "Parameters: Bridge Thinker"; + 100 = "FOF (solid): Solid, Opaque"; + 101 = "FOF (solid): Solid, Opaque, No Shadow"; + 102 = "FOF (solid): Solid, Translucent"; + 103 = "FOF (solid): Solid, Sides Only"; + 104 = "FOF (solid): Solid, No Sides"; + 105 = "FOF (solid): Solid, Invisible"; + 120 = "FOF (intangible): Water, Opaque"; + 121 = "FOF (intangible): Water, Translucent"; + 122 = "FOF (intangible): Water, Opaque, No Sides"; + 123 = "FOF (intangible): Water, Translucent, No Sides"; + 124 = "FOF (intangible): Goo Water, Translucent"; + 125 = "FOF (intangible): Goo Water, Translucent, No Sides"; + 140 = "FOF (solid): Intangible from Bottom, Opaque"; + 141 = "FOF (solid): Intangible from Bottom, Translucent"; + 142 = "FOF (solid): Intangible from Bottom, Translucent, No Sides"; + 143 = "FOF (solid): Intangible from Top, Opaque"; + 144 = "FOF (solid): Intangible from Top, Translucent"; + 145 = "FOF (solid): Intangible from Top, Translucent, No Sides"; + 146 = "FOF (solid): Only Tangible From Sides"; + 150 = "FOF (bobbing): Air Bobbing"; + 151 = "FOF (bobbing): Air Bobbing (Adjustable)"; + 152 = "FOF (bobbing): Reverse Air Bobbing (Adjustable)"; + 160 = "FOF (bobbing): Floating, Bobbing"; + 170 = "FOF (crumbling): Crumbling (Respawn)"; + 171 = "FOF (crumbling): Crumbling (No Respawn)"; + 172 = "FOF (crumbling): Crumbling (Respawn), Intangible from Bottom"; + 173 = "FOF (crumbling): Crumbling (No Respawn), Intangible from Bottom"; + 174 = "FOF (crumbling): Crumbling (Respawn), Int. from Bottom, Translucent"; + 175 = "FOF (crumbling): Crumbling (No Respawn), Int. from Bottom, Translucent"; + 176 = "FOF (crumbling): Crumbling (Respawn), Floating, Bobbing"; + 177 = "FOF (crumbling): Crumbling (No Respawn), Floating, Bobbing"; + 178 = "FOF (crumbling): Crumbling (Respawn), Floating"; + 179 = "FOF (crumbling): Crumbling (No Respawn), Floating"; + 180 = "FOF (crumbling): Crumbling (Respawn), Air Bobbing"; + 190 = "FOF (bobbing): Rising Platform, Solid, Opaque"; + 191 = "FOF (bobbing): Rising Platform, Solid, Opaque, No Shadow"; + 192 = "FOF (bobbing): Rising Platform, Solid, Translucent"; + 193 = "FOF (bobbing): Rising Platform, Solid, Invisible"; + 194 = "FOF (bobbing): Rising Platform, Intangible from Bottom, Opaque"; + 195 = "FOF (bobbing): Rising Platform, Intangible from Bottom, Translucent"; + 200 = "FOF (special): Light Block"; + 201 = "FOF (special): Half Light Block"; + 202 = "FOF (special): Fog Block"; + 220 = "FOF (intangible): Intangible, Opaque"; + 221 = "FOF (intangible): Intangible, Translucent"; + 222 = "FOF (intangible): Intangible, Sides Only"; + 223 = "FOF (intangible): Intangible, Invisible"; + 250 = "FOF (special): Mario Block"; + 251 = "FOF (special): Thwomp Block"; + 252 = "FOF (special): Shatter Block"; + 253 = "FOF (special): Shatter Block, Translucent"; + 254 = "FOF (special): Bustable Block"; + 255 = "FOF (special): Spin Bust Block"; + 256 = "FOF (special): Spin Bust Block, Translucent"; + 257 = "FOF (special): Quicksand"; + 258 = "FOF (special): Laser"; + 259 = "FOF (special): Custom FOF"; + 300 = "Linedef Executor Trigger: Continuous"; + 301 = "Linedef Executor Trigger: Each Time"; + 302 = "Linedef Executor Trigger: Once"; + 303 = "Linedef Executor Trigger: Ring Count - Continuous"; + 304 = "Linedef Executor Trigger: Ring Count - Once"; + 305 = "Linedef Executor Trigger: Character Ability - Once"; + 306 = "Linedef Executor Trigger: Character Ability - Each Time"; + 307 = "Linedef Executor Trigger: Character Ability - Continuous"; + 308 = "Linedef Executor Trigger: Race Only - Once"; + 309 = "Linedef Executor Trigger: CTF Red Team - Continuous"; + 310 = "Linedef Executor Trigger: CTF Red Team - Each Time"; + 311 = "Linedef Executor Trigger: CTF Blue Team - Continuous"; + 312 = "Linedef Executor Trigger: CTF Blue Team - Each Time"; + 313 = "Linedef Executor Trigger: No More Enemies - Once"; + 314 = "Linedef Executor Trigger: Number of Pushables - Continuous"; + 315 = "Linedef Executor Trigger: Number of Pushables - Once"; + 316 = "Linedef Executor Trigger: Land On PolyObject"; + 317 = "Linedef Executor Trigger: Unlockable Trigger - Continuous"; + 318 = "Linedef Executor Trigger: Unlockable Trigger - Once"; + 399 = "Linedef Executor Trigger: Level Load"; + 400 = "Linedef Executor (sector): Set Tagged Sector's Floor Height/Texture"; + 401 = "Linedef Executor (sector): Set Tagged Sector's Ceiling Height/Texture"; + 402 = "Linedef Executor (sector): Set Tagged Sector's Light Level"; + 403 = "Linedef Executor (plane movement): Move Tagged Sector's Floor"; + 404 = "Linedef Executor (plane movement): Move Tagged Sector's Ceiling"; + 405 = "Linedef Executor (plane movement): Move Floor According to Front Texture Offsets"; + 407 = "Linedef Executor (plane movement): Move Ceiling According to Front Texture Offsets"; + 409 = "Linedef Executor (sector): Change Tagged Sectors' Tag"; + 410 = "Linedef Executor (sector): Change Front Sector's Tag"; + 411 = "Linedef Executor (plane movement): Stop Plane Movement"; + 412 = "Linedef Executor (player/object): Teleporter"; + 413 = "Linedef Executor (misc.): Change Music"; + 414 = "Linedef Executor (misc.): Play Sound Effect"; + 415 = "Linedef Executor (misc.): Run Script"; + 416 = "Linedef Executor (sector): Start Adjustable Fire Flicker"; + 417 = "Linedef Executor (sector): Start Adjustable Glowing Light"; + 418 = "Linedef Executor (sector): Start Adjustable Blinking Light (unsynchronized)"; + 419 = "Linedef Executor (sector): Start Adjustable Blinking Light (synchronized)"; + 420 = "Linedef Executor (sector): Fade Light Level"; + 421 = "Linedef Executor (sector): Stop Lighting Effect"; + 422 = "Linedef Executor (misc.): Switch To Cut-Away View"; + 423 = "Linedef Executor (misc.): Change Sky"; + 424 = "Linedef Executor (misc.): Change Weather"; + 425 = "Linedef Executor (player/object): Change Object State"; + 426 = "Linedef Executor (player/object): Stop Object"; + 427 = "Linedef Executor (player/object): Award Score"; + 428 = "Linedef Executor (plane movement): Start Platform Movement"; + 429 = "Linedef Executor (plane movement): Crush Ceiling Once"; + 430 = "Linedef Executor (plane movement): Crush Floor Once"; + 431 = "Linedef Executor (plane movement): Crush Floor And Ceiling Once"; + 432 = "Linedef Executor (player/object): Enable/Disable 2D Mode"; + 433 = "Linedef Executor (player/object): Enable/Disable Gravity Flip"; + 434 = "Linedef Executor (player/object): Award Power-Up"; + 435 = "Linedef Executor (sector): Change Plane Scroller Direction"; + 436 = "Linedef Executor (misc.): Shatter FOF"; + 437 = "Linedef Executor (player/object): Disable Player Control"; + 438 = "Linedef Executor (player/object): Change Object Size"; + 439 = "Linedef Executor (misc.): Change Tagged Linedef Textures"; + 440 = "Linedef Executor (misc.): Start Metal Sonic Race"; + 441 = "Linedef Executor (misc.): Unlockable Trigger"; + 442 = "Linedef Executor (player/object): Change Object Type State"; + 443 = "Linedef Executor (misc.): Call Lua Function"; + 444 = "Linedef Executor (misc.): Earthquake"; + 445 = "Linedef Executor (misc.): Force Block Disappear"; + 450 = "Linedef Executor (misc.): Execute Linedef Executor (from tag)"; + 451 = "Linedef Executor (misc.): Execute Linedef Executor (random range)"; + 480 = "Linedef Executor (polyobject): Door Slide"; + 481 = "Linedef Executor (polyobject): Door Swing"; + 482 = "Linedef Executor (polyobject): Move"; + 483 = "Linedef Executor (polyobject): Move, Override"; + 484 = "Linedef Executor (polyobject): Rotate Right"; + 485 = "Linedef Executor (polyobject): Rotate Right, Override"; + 486 = "Linedef Executor (polyobject): Rotate Left"; + 487 = "Linedef Executor (polyobject): Rotate Left, Override"; + 488 = "Linedef Executor (polyobject): Move by Waypoints"; + 489 = "Linedef Executor (polyobject): Turn Invisible, Intangible"; + 490 = "Linedef Executor (polyobject): Turn Visible, Tangible"; + 491 = "Linedef Executor (polyobject): Set Translucency"; + 500 = "Wall Scrolling: Scroll Wall Front Side Left"; + 501 = "Wall Scrolling: Scroll Wall Front Side Right"; + 502 = "Wall Scrolling: Scroll Wall According to Linedef"; + 503 = "Wall Scrolling: Scroll Wall According to Linedef (Accelerative)"; + 504 = "Wall Scrolling: Scroll Wall According to Linedef (Displacement)"; + 505 = "Wall Scrolling: Scroll Texture by Front Side Offsets"; + 506 = "Wall Scrolling: Scroll Texture by Back Side Offsets"; + 510 = "Plane Scrolling: Scroll Floor Texture"; + 511 = "Plane Scrolling: Scroll Floor Texture (Accelerative)"; + 512 = "Plane Scrolling: Scroll Floor Texture (Displacement)"; + 513 = "Plane Scrolling: Scroll Ceiling Texture"; + 514 = "Plane Scrolling: Scroll Ceiling Texture (Accelerative)"; + 515 = "Plane Scrolling: Scroll Ceiling Texture (Displacement)"; + 520 = "Plane Scrolling: Carry Objects on Floor"; + 521 = "Plane Scrolling: Carry Objects on Floor (Accelerative)"; + 522 = "Plane Scrolling: Carry Objects on Floor (Displacement)"; + 523 = "Plane Scrolling: Carry Objects on Ceiling"; + 524 = "Plane Scrolling: Carry Objects on Ceiling (Accelerative)"; + 525 = "Plane Scrolling: Carry Objects on Ceiling (Displacement)"; + 530 = "Plane Scrolling: Scroll Floor Texture and Carry Objects"; + 531 = "Plane Scrolling: Scroll Floor Texture and Carry Objects (Accelerative)"; + 532 = "Plane Scrolling: Scroll Floor Texture and Carry Objects (Displacement)"; + 533 = "Plane Scrolling: Scroll Ceiling Texture and Carry Objects"; + 534 = "Plane Scrolling: Scroll Ceiling Texture and Carry Objects (Accelerative)"; + 535 = "Plane Scrolling: Scroll Ceiling Texture and Carry Objects (Displacement)"; + 540 = "Miscellaneous: Floor Friction"; + 541 = "Pusher: Wind"; + 542 = "Pusher: Upwards Wind"; + 543 = "Pusher: Downwards Wind"; + 544 = "Pusher: Current"; + 545 = "Pusher: Upwards Current"; + 546 = "Pusher: Downwards Current"; + 547 = "Pusher: Push/Pull"; + 600 = "Lighting: Floor Lighting"; + 601 = "Lighting: Ceiling Lighting"; + 602 = "Lighting: Adjustable Pulsating Light"; + 603 = "Lighting: Adjustable Flickering Light"; + 604 = "Lighting: Adjustable Blinking Light (unsynchronized)"; + 605 = "Lighting: Adjustable Blinking Light (synchronized)"; + 606 = "Lighting: Colormap"; + 900 = "Translucent Wall: 90% Opaque"; + 901 = "Translucent Wall: 80% Opaque"; + 902 = "Translucent Wall: 70% Opaque"; + 903 = "Translucent Wall: 60% Opaque"; + 904 = "Translucent Wall: 50% Opaque"; + 905 = "Translucent Wall: 40% Opaque"; + 906 = "Translucent Wall: 30% Opaque"; + 907 = "Translucent Wall: 20% Opaque"; + 908 = "Translucent Wall: 10% Opaque"; + 909 = "Translucent Wall: Fog Wall"; +} + +// THING FLAGS ----------------------------------------------------------------- + +thingflags +{ + 1 = "[0] Unused Flag"; + 2 = "[1] Object Flip"; + 4 = "[2] Object Special"; + 8 = "[3] Ambush"; + 16 = "(Used for Z offsets)"; +} + +/* THING TYPES ----------------------------------------------------------------- + +Color values: 1 = Blue 9 = Light_Blue + 2 = Green 10 = Light_Green + 3 = Cyan 11 = Light_Cyan + 4 = Red 12 = Light_Red + 5 = Magenta 13 = Pink + 6 = Brown 14 = Yellow + 7 = Gray 15 = White + 8 = Dark_Gray + +*/ + +thingtypes +{ + editor + { + color = 15; // White + arrow = 1; + title = ""; + error = -1; + width = 8; + height = 16; + sort = 1; + + 32000 = "3D Mode Start"; + 32001 + { + arrow = 0; + title = "Control Sector Position Hint"; + } + } + + starts + { + color = 1; // Blue + arrow = 1; + title = "Player Starts"; + width = 16; + height = 56; + deaftext = "[3] Spawn On Ceiling"; + + 1 + { + title = "Player 01 Start"; + sprite = "SUPTD0"; + } + 2 + { + title = "Player 02 Start"; + sprite = "SUPTD0"; + } + 3 + { + title = "Player 03 Start"; + sprite = "SUPTD0"; + } + 4 + { + title = "Player 04 Start"; + sprite = "SUPTD0"; + } + 5 + { + title = "Player 05 Start"; + sprite = "SUPTD0"; + } + 6 + { + title = "Player 06 Start"; + sprite = "SUPTD0"; + } + 7 + { + title = "Player 07 Start"; + sprite = "SUPTD0"; + } + 8 + { + title = "Player 08 Start"; + sprite = "SUPTD0"; + } + 9 + { + title = "Player 09 Start"; + sprite = "SUPTD0"; + } + 10 + { + title = "Player 10 Start"; + sprite = "SUPTD0"; + } + 11 + { + title = "Player 11 Start"; + sprite = "SUPTD0"; + } + 12 + { + title = "Player 12 Start"; + sprite = "SUPTD0"; + } + 13 + { + title = "Player 13 Start"; + sprite = "SUPTD0"; + } + 14 + { + title = "Player 14 Start"; + sprite = "SUPTD0"; + } + 15 + { + title = "Player 15 Start"; + sprite = "SUPTD0"; + } + 16 + { + title = "Player 16 Start"; + sprite = "SUPTD0"; + } + 17 + { + title = "Player 17 Start"; + sprite = "SUPTD0"; + } + 18 + { + title = "Player 18 Start"; + sprite = "SUPTD0"; + } + 19 + { + title = "Player 19 Start"; + sprite = "SUPTD0"; + } + 20 + { + title = "Player 20 Start"; + sprite = "SUPTD0"; + } + 21 + { + title = "Player 21 Start"; + sprite = "SUPTD0"; + } + 22 + { + title = "Player 22 Start"; + sprite = "SUPTD0"; + } + 23 + { + title = "Player 23 Start"; + sprite = "SUPTD0"; + } + 24 + { + title = "Player 24 Start"; + sprite = "SUPTD0"; + } + 25 + { + title = "Player 25 Start"; + sprite = "SUPTD0"; + } + 26 + { + title = "Player 26 Start"; + sprite = "SUPTD0"; + } + 27 + { + title = "Player 27 Start"; + sprite = "SUPTD0"; + } + 28 + { + title = "Player 28 Start"; + sprite = "SUPTD0"; + } + 29 + { + title = "Player 29 Start"; + sprite = "SUPTD0"; + } + 30 + { + title = "Player 30 Start"; + sprite = "SUPTD0"; + } + 31 + { + title = "Player 31 Start"; + sprite = "SUPTD0"; + } + 32 + { + title = "Player 32 Start"; + sprite = "SUPTD0"; + } + 33 + { + title = "Match Start"; + sprite = "SUPTI0"; + } + 34 + { + title = "CTF Red Team Start"; + sprite = "SIGNG0"; + } + 35 + { + title = "CTF Blue Team Start"; + sprite = "SIGNE0"; + } + } + + enemies + { + color = 9; // Light_Blue + arrow = 1; + title = "Enemies"; + width = 24; + height = 32; + sort = 1; + + 100 + { + title = "Crawla (Blue)"; + sprite = "POSSA1"; + } + 101 + { + title = "Crawla (Red)"; + sprite = "SPOSA1"; + } + 102 + { + title = "Stupid Dumb Unnamed RoboFish"; + sprite = "FISHA0"; + width = 8; + height = 28; + } + 103 + { + title = "Buzz (Gold)"; + sprite = "BUZZA1"; + width = 20; + height = 24; + deaftext = "[3] Cannot Move"; + } + 104 + { + title = "Buzz (Red)"; + sprite = "RBUZA1"; + width = 20; + height = 24; + deaftext = "[3] Cannot Move"; + } + 105 + { + title = "Jetty-Syn Bomber"; + sprite = "JETBB1"; + width = 20; + height = 48; + deaftext = "[3] Cannot Move"; + } + 106 + { + title = "Jetty-Syn Gunner"; + sprite = "JETGB1"; + width = 20; + height = 48; + deaftext = "[3] Cannot Move"; + } + 107 + { + title = "Crawla Commander"; + sprite = "CCOMA1"; + width = 16; + } + 108 + { + title = "Deton"; + sprite = "DETNA1"; + width = 20; + } + 109 + { + title = "Skim"; + sprite = "SKIMA1"; + width = 16; + height = 24; + } + 110 + { + title = "Turret"; + sprite = "TRETA1"; + width = 16; + height = 32; + } + 111 + { + title = "Popup Turret"; + sprite = "TURRI1"; + width = 12; + height = 64; + } + 112 + { + title = "Sharp"; + sprite = "SHRPA1"; + width = 16; + height = 24; + } + 113 + { + title = "Jet Jaw"; + sprite = "JJAWA3A7"; + width = 12; + height = 20; + } + 114 + { + title = "Snailer"; + sprite = "SNLRA3A7"; + height = 48; + } + 115 + { + title = "Bird Aircraft Strike Hazard"; + sprite = "VLTRF1"; + width = 12; + height = 24; + } + 116 + { + title = "Pointy"; + sprite = "PNTYA1"; + width = 8; + height = 16; + } + 117 + { + title = "Robo-Hood"; + sprite = "ARCHA1"; + deaftext = "[3] Cannot Jump"; + } + 118 + { + title = "CastleBot FaceStabber"; + sprite = "CBFSA1"; + width = 32; + height = 64; + } + 119 + { + title = "Egg Guard"; + sprite = "ESHIA1"; + width = 16; + height = 48; + deaftext = "[3] Double Speed"; + } + 120 + { + title = "Green Snapper"; + sprite = "GSNPA1"; + height = 24; + } + 121 + { + title = "Minus"; + sprite = "MNUSA1"; + } + 122 + { + title = "Spring Shell (Green)"; + sprite = "SSHLA1"; + height = 40; + } + 123 + { + title = "Unidus"; + sprite = "UNIDA1"; + width = 18; + height = 36; + } + 124 + { + title = "AquaBuzz"; + sprite = "BBUZA1"; + width = 20; + height = 24; + } + 125 + { + title = "Spring Shell (Yellow)"; + sprite = "YSHLA1"; + height = 40; + } + 750 + { + title = " Chaos Enemy Spawn"; + sprite = "TFOGG0"; + width = 32; + height = 64; + } + } + + bosses + { + color = 8; // Dark_Gray + arrow = 1; + title = "Bosses"; + width = 24; + height = 52; + sort = 1; + + 200 + { + title = "Boss 1 - Egg Mobile"; + sprite = "EGGMA1"; + deaftext = "[3] Rotating Spikeballs"; + } + 201 + { + title = "Boss 2 - Egg Slimer"; + sprite = "EGGNA1"; + height = 48; + deaftext = "[3] Speed Up When Hit"; + } + 202 + { + title = "Boss 3 - Sea Egg"; + sprite = "EGGOA1"; + width = 32; + height = 80; + } + 203 + { + title = "Boss 4 - Eggscalibur"; + sprite = "EGGPA1"; + } + 206 + { + title = "Boss - Black Eggman (Old)"; + sprite = "BRAKB1"; + width = 48; + height = 160; + } + 207 + { + title = "Boss 5A - Metal Sonic Race Start"; + sprite = "METLI1"; + width = 16; + height = 48; + } + 208 + { + title = "Boss 5B - Metal Sonic Battle Start"; + sprite = "METLC1"; + width = 16; + height = 48; + } + 209 + { + title = "Boss 6 - Black Eggman (New)"; + sprite = "BRAK[1"; + width = 48; + height = 160; + deaftext = "[3] Electric Barrier"; + } + 290 + { + arrow = 0; + title = "Boss Escape Point"; + width = 8; + height = 16; + } + 291 + { + arrow = 0; + title = "Egg Trap Center"; + width = 8; + height = 16; + } + 292 + { + arrow = 0; + title = "Boss Waypoint"; + width = 8; + height = 16; + deaftext = "[3] Sea Egg Shooting Point"; + } + 293 = "Metal Sonic Waypoint"; + } + + rings + { + color = 14; // Yellow + title = "Rings and Weapon Panels"; + width = 24; + height = 24; + deafheight = 32; + deaftext = "[3] Float"; + + 300 + { + title = "Ring"; + sprite = "RINGA0"; + width = 16; + } + 301 + { + title = "Bounce Ring"; + sprite = "CPRKB0"; + } + 302 + { + title = "Rail Ring"; + sprite = "SPRKA0"; + } + 303 + { + title = "Infinity Ring"; + sprite = "RNGIA0"; + } + 304 + { + title = "Automatic Ring"; + sprite = "TAUTA3A7"; + } + 305 + { + title = "Explosion Ring"; + sprite = "BMSLA1"; + } + 306 + { + title = "Scatter Ring"; + sprite = "TSCRA1A5"; + } + 307 + { + title = "Grenade Ring"; + sprite = "TGREA0"; + } + 308 + { + title = "CTF Team Ring (Red)"; + sprite = "RRNGA0"; + width = 16; + } + 309 + { + title = "CTF Team Ring (Blue)"; + sprite = "TRNGA0"; + width = 16; + } + 330 + { + title = "Bounce Ring Panel"; + sprite = "PIKBA0"; + } + 331 + { + title = "Rail Ring Panel"; + sprite = "PIKRA0"; + } + 332 + { + title = "Automatic Ring Panel"; + sprite = "PIKAA0"; + } + 333 + { + title = "Explosion Ring Panel"; + sprite = "PIKEA0"; + } + 334 + { + title = "Scatter Ring Panel"; + sprite = "PIKSA0"; + } + 335 + { + title = "Grenade Ring Panel"; + sprite = "PIKGA0"; + } + } + + collectibles + { + color = 10; // Light_Green + title = "Other Collectibles"; + width = 16; + height = 32; + sort = 1; + + 310 + { + title = "CTF Red Flag"; + sprite = "RFLGA0"; + width = 24; + height = 64; + } + 311 + { + title = "CTF Blue Flag"; + sprite = "BFLGA0"; + width = 24; + height = 64; + } + 312 + { + title = "Special Stage Token"; + sprite = "TOKEA0"; + width = 8; + height = 16; + deafheight = 32; + deaftext = "[3] Float"; + } + 313 + { + title = "Chaos Emerald 1 (Green)"; + sprite = "EMMYA0"; + } + 314 + { + title = "Chaos Emerald 2 (Orange)"; + sprite = "EMMYB0"; + } + 315 + { + title = "Chaos Emerald 3 (Purple)"; + sprite = "EMMYC0"; + } + 316 + { + title = "Chaos Emerald 4 (Blue)"; + sprite = "EMMYD0"; + } + 317 + { + title = "Chaos Emerald 5 (Red)"; + sprite = "EMMYE0"; + } + 318 + { + title = "Chaos Emerald 6 (Light Blue)"; + sprite = "EMMYF0"; + } + 319 + { + title = "Chaos Emerald 7 (Gray)"; + sprite = "EMMYG0"; + } + 320 + { + title = "Emerald Hunt Location"; + sprite = "EMERA0"; + } + 323 + { + title = "Match Chaos Emerald Spawn"; + sprite = "CEMGA0"; + width = 8; + height = 16; + deafheight = 32; + deaftext = "[3] Float"; + } + } + + boxes + { + color = 7; // Gray + blocking = 2; + title = "Item Boxes"; + width = 16; + height = 32; + deaftext = "[3] Random (Weak)"; + sort = 1; + + 400 + { + title = "Super Ring (10 Rings)"; + sprite = "SRBXA0"; + } + 401 + { + title = "Pity / Basic Shield"; + sprite = "GRTVA0"; + } + 402 + { + title = "Attraction Shield"; + sprite = "YLTVA0"; + } + 403 + { + title = "Force Shield"; + sprite = "BLTVA0"; + } + 404 + { + title = "Armageddon Shield"; + sprite = "BKTVA0"; + } + 405 + { + title = "Whirlwind Shield"; + sprite = "WHTVA0"; + } + 406 + { + title = "Elemental Shield"; + sprite = "ELTVA0"; + } + 407 + { + title = "Super Sneakers"; + sprite = "SHTVA0"; + } + 408 + { + title = "Invincibility"; + sprite = "PINVA0"; + } + 409 + { + title = "Extra Life"; + sprite = "PRUPA0"; + deaftext = "[3] Random (Weak) / 10k points"; + } + 410 + { + title = "Eggman"; + sprite = "EGGBA0"; + } + 411 + { + title = "Teleporter"; + sprite = "MIXUA0"; + } + 412 + { + title = "Random"; + sprite = "QUESA0"; + } + 413 + { + title = "Gravity Boots"; + sprite = "GBTVA0"; + } + 414 + { + title = "CTF Team Ring Box (Red)"; + sprite = "RRBXA0"; + deaftext = "[3] Ambush"; + } + 415 + { + title = "CTF Team Ring Box (Blue)"; + sprite = "BRBXA0"; + deaftext = "[3] Ambush"; + } + 416 + { + title = "Recycler"; + sprite = "RECYA0"; + } + 418 + { + title = "1,000 Points"; + sprite = "PTTVA0"; + } + 419 + { + title = "10,000 Points"; + sprite = "PTTVF0"; + } + } + + miscellaneous + { + color = 11; // Light_Cyan + title = "Miscellaneous"; + width = 16; + height = 40; + sort = 1; + + 500 + { + title = "Air Bubble Patch"; + sprite = "BUBLA0"; + width = 8; + height = 16; + deaftext = "[3] No Distance Check"; + } + 501 + { + title = "End Level Sign"; + sprite = "SIGND0"; + width = 8; + height = 32; + } + 502 + { + arrow = 1; + title = "Star Post"; + sprite = "STPTA0"; + width = 64; + height = 80; + } + 526 + { + blocking = 2; + title = "Cannonball"; + sprite = "CBLLA0"; + width = 20; + deaftext = "[3] Not Pushable"; + } + 1000 + { + arrow = 1; + blocking = 2; + title = "Gargoyle"; + sprite = "GARGA1"; + deaftext = "[3] Not Pushable"; + } + 1102 + { + arrow = 1; + blocking = 2; + title = "Eggman Statue"; + sprite = "ESTAA1"; + width = 32; + height = 240; + deaftext = "[3] Not Pushable"; + } + 1106 + { + arrow = 1; + title = "Chain (Hang)"; + sprite = "SMCHA0"; + height = 32; + deaftext = "[3] Double Size"; + } + 1107 + { + arrow = 1; + title = "Chain (Spin)"; + sprite = "SMCHA0"; + height = 32; + } + 1200 + { + title = "Tumbleweed (Big)"; + sprite = "BTBLA0"; + width = 24; + height = 48; + deaftext = "[3] Tossed On Spawn"; + } + 1201 + { + title = "Tumbleweed (Small)"; + sprite = "STBLA0"; + width = 12; + height = 24; + deaftext = "[3] Tossed On Spawn"; + } + 1852 + { + blocking = 2; + title = "Snowman"; + sprite = "XMS3A0"; + deaftext = "[3] Not Pushable"; + } + 1876 + { + arrow = 1; + blocking = 2; + title = "Eggman Disco Statue"; + sprite = "ESTAB1"; + width = 20; + height = 96; + deaftext = "[3] Not Pushable"; + } + 1504 + { + title = "ATZ Target"; + sprite = "RCRYB0"; + width = 24; + height = 32; + } + } + + springs + { + color = 12; // Light_Red + title = "Springs and Fans"; + width = 20; + height = 16; + + 540 + { + title = "Fan"; + sprite = "FANSA0D0"; + width = 16; + deaftext = "[3] No Distance Check"; + } + 541 + { + title = "Gas Jet"; + sprite = "STEMD0"; + width = 32; + } + 550 + { + title = "Yellow Spring"; + sprite = "SPRYA0"; + } + 551 + { + title = "Red Spring"; + sprite = "SPRRA0"; + } + 552 + { + title = "Blue Spring"; + sprite = "SPRBA0"; + } + 555 + { + arrow = 1; + title = "Diagonal Yellow Spring"; + sprite = "YSPRD2"; + width = 16; + deaftext = "[3] Rotate 22.5° CCW"; + } + 556 + { + arrow = 1; + title = "Diagonal Red Spring"; + sprite = "RSPRD2"; + width = 16; + deaftext = "[3] Rotate 22.5° CCW"; + } + } + + patterns + { + color = 5; // Magenta + arrow = 1; + title = "Special Placement Patterns"; + width = 16; + height = 384; + + 600 + { + arrow = 0; + title = "5 Vertical Rings (Yellow Spring)"; + sprite = "RINGA0"; + } + 601 + { + arrow = 0; + title = "5 Vertical Rings (Red Spring)"; + sprite = "RINGA0"; + height = 1024; + } + 602 + { + title = "5 Diagonal Rings (Yellow Spring)"; + sprite = "RINGA0"; + height = 32; + } + 603 + { + title = "10 Diagonal Rings (Red Spring)"; + sprite = "RINGA0"; + height = 32; + } + 604 + { + title = "Circle of Rings"; + sprite = "RINGA0"; + width = 96; + height = 192; + } + 605 + { + title = "Circle of Rings (Big)"; + sprite = "RINGA0"; + width = 192; + } + 606 + { + title = "Circle of Wing Logos"; + sprite = "NWNGA0"; + width = 96; + height = 192; + } + 607 + { + title = "Circle of Wing Logos (Big)"; + sprite = "NWNGA0"; + width = 192; + } + 608 + { + title = "Circle of Rings and Wings"; + sprite = "NWNGA0"; + width = 96; + height = 192; + } + 609 + { + title = "Circle of Rings and Wings (Big)"; + sprite = "NWNGA0"; + width = 192; + } + } + + invisible + { + color = 15; // White + title = "Misc. Invisible"; + width = 8; + height = 16; + + 700 = "Water Ambience A (Large)"; + 701 = "Water Ambience B (Large)"; + 702 = "Water Ambience C (Medium)"; + 703 = "Water Ambience D (Medium)"; + 704 = "Water Ambience E (Small)"; + 705 = "Water Ambience F (Small)"; + 706 = "Water Ambience G (Extra Large)"; + 707 = "Water Ambience H (Extra Large)"; + 708 = "Disco Ambience"; + 709 = "Volcano Ambience"; + 751 + { + arrow = 1; + title = "Teleport Destination"; + } + 752 + { + arrow = 1; + title = "Alternate View Point"; + } + 753 = "Zoom Tube Waypoint"; + 754 + { + title = "Push Point"; + deaftext = "[3] Push Using XYZ"; + } + 755 + { + title = "Pull Point"; + deaftext = "[3] Pull Using XYZ"; + } + 760 = "PolyObject Anchor"; + 761 = "PolyObject Spawn Point"; + 762 = "PolyObject Spawn Point (Crush)"; + 780 = "Skybox View Point"; + } + + hazards + { + color = 4; // Red + title = "Hazards"; + width = 20; + height = 40; + sort = 1; + + 521 + { + title = "Spikeball"; + sprite = "SPIKA0"; + width = 12; + height = 24; + deafheight = 32; + deaftext = "[3] Float"; + } + 523 + { + title = "Spike (Floor)"; + sprite = "USPKA0"; + width = 8; + height = 42; + deaftext = "[3] Solid"; + } + 524 + { + arrow = 1; + title = "Big Floating Mine"; + width = 16; + height = 32; + sprite = "BMNEA1"; + } + 527 + { + arrow = 1; + title = "Big Floating Mine (Air)"; + width = 16; + height = 32; + sprite = "BMNEA1"; + } + 525 + { + title = "Cannonball Launcher"; + sprite = "CBLLA0"; + } + 1101 + { + title = "Torch"; + sprite = "FLAMA0"; + width = 8; + height = 32; + } + 1104 + { + title = "Mace (Spinning)"; + sprite = "SMCEA0"; + deaftext = "[3] Double Size"; + } + 1105 + { + title = "Mace (Swinging)"; + sprite = "SMCEA0"; + deaftext = "[3] Double Size"; + } + 1202 + { + arrow = 1; + title = "Rock Spawner"; + sprite = "ROIAA0"; + } + 1300 + { + arrow = 1; + title = "Flame Jet (Horizontal)"; + sprite = "FLMEB0"; + width = 16; + deaftext = "[3] Waves Vertically"; + } + 1301 + { + title = "Flame Jet (Vertical)"; + sprite = "FLMEB0"; + width = 16; + deaftext = "[3] Shoot Downwards"; + } + 1500 + { + arrow = 1; + blocking = 2; + title = "Trapgoyle"; + sprite = "GARGA1"; + width = 16; + height = 40; + deaftext = "[3] Not Pushable"; + } + 1501 + { + arrow = 1; + blocking = 2; + title = "Trapgoyle (Up)"; + sprite = "GARGA1"; + width = 16; + height = 40; + deaftext = "[3] Not Pushable"; + } + 1502 + { + arrow = 1; + blocking = 2; + title = "Trapgoyle (Down)"; + sprite = "GARGA1"; + width = 16; + height = 40; + deaftext = "[3] Not Pushable"; + } + 1503 + { + arrow = 1; + blocking = 2; + title = "Trapgoyle (Long)"; + sprite = "GARGA1"; + width = 16; + height = 40; + deaftext = "[3] Not Pushable"; + } + 3575 + { + title = "Spinning Flame Jet (Counter-Clockwise)"; + sprite = "FLMEB0"; + width = "16"; + } + 3576 + { + title = "Spinning Flame Jet (Clockwise)"; + sprite = "FLMEB0"; + width = "16"; + } + } + + decoration + { + color = 2; // Green + title = "Decoration"; + width = 16; + height = 40; + + 757 + { + title = "Fan Particle Generator"; + sprite = "PRTLA0"; + width = 8; + height = 16; + } + 800 + { + title = "GFZ Flower"; + sprite = "FWR1A0"; + } + 801 + { + title = "Sunflower"; + sprite = "FWR2A0"; + height = 96; + } + 802 + { + title = "Budding Flower"; + sprite = "FWR3A0"; + width = 8; + height = 32; + } + 804 + { + title = "Berry Bush"; + sprite = "BUS1A0"; + height = 32; + } + 805 + { + title = "Bush"; + sprite = "BUS2A0"; + height = 32; + } + 900 + { + title = "THZ Flower"; + sprite = "THZPA0"; + width = 8; + height = 32; + } + 901 + { + title = "Alarm"; + sprite = "ALRMA0"; + width = 8; + height = 16; + hangs = 1; + } + 1001 + { + title = "Seaweed"; + sprite = "SEWEA0"; + width = 24; + height = 56; + } + 1002 + { + title = "Dripping Water"; + sprite = "DRIPD0"; + width = 8; + height = 16; + hangs = 1; + } + 1003 + { + title = "Coral (Green)"; + sprite = "CRL1A0"; + width = 8; + height = 16; + } + 1004 + { + title = "Coral (Red)"; + sprite = "CRL2A0"; + width = 8; + height = 16; + } + 1005 + { + title = "Coral (Orange)"; + sprite = "CRL3A0"; + width = 8; + height = 16; + } + 1006 + { + title = "Blue Crystal"; + sprite = "BCRYA1"; + width = 8; + height = 16; + } + 1100 + { + title = "Chain"; + sprite = "CHANA0"; + width = 8; + height = 128; + hangs = 1; + } + 1103 + { + title = "CEZ Flower"; + sprite = "FWR4A0"; + } + 1203 + { + title = "Cactus with Brown Flower"; + sprite = "CACTA0"; + height = 32; + } + 1204 + { + title = "Cactus with Brown Flower (Tall)"; + sprite = "CACTB0"; + height = 64; + } + 1205 + { + title = "Cactus with Blue Flower"; + sprite = "CACTC0"; + height = 32; + } + 1206 + { + title = "Cactus with Blue Flower (Tall)"; + sprite = "CACTD0"; + height = 80; + } + 1850 + { + title = "Xmas Pole"; + sprite = "XMS1A0"; + } + 1851 + { + title = "Candy Cane"; + sprite = "XMS2A0"; + width = 8; + height = 32; + } + 1875 + { + title = "Disco Ball"; + sprite = "DBALA0"; + height = 54; + hangs = 1; + } + 1900 + { + title = "Brown Stalagmite (Tall)"; + sprite = "STLGA0"; + } + 1901 + { + title = "Brown Stalagmite"; + sprite = "STLGB0"; + } + 1902 + { + title = "Orange Stalagmite (Tall)"; + sprite = "STLGC0"; + } + 1903 + { + title = "Orange Stalagmite"; + sprite = "STLGD0"; + } + 1904 + { + title = "Red Stalagmite (Tall)"; + sprite = "STLGE0"; + } + 1905 + { + title = "Red Stalagmite"; + sprite = "STLGF0"; + } + 1906 + { + title = "Gray Stalagmite (Tall)"; + sprite = "STLGG0"; + } + 1907 + { + title = "Gray Stalagmite"; + sprite = "STLGH0"; + } + 1908 + { + title = "Blue Stalagmite (Tall)"; + sprite = "STLGI0"; + } + 1909 + { + title = "Blue Stalagmite"; + sprite = "STLGJ0"; + } + } + + nights + { + color = 13; // Pink + title = "Nights Items"; + width = 12; + height = 32; + + 1703 + { + title = "Ideya Drone"; + sprite = "NDRNA1"; + width = 16; + height = 56; + deaftext = "[3] Die Upon Time Up"; + } + 1704 + { + arrow = 1; + title = "Bumper"; + sprite = "NBMPG3G7"; + width = 32; + height = 64; + } + 1705 + { + arrow = 1; + title = "Hoop (Generic)"; + sprite = "HOOPA0"; + width = 80; + height = 160; + } + 1706 + { + title = "Wing Logo"; + sprite = "NWNGA0"; + height = 24; + } + 1707 + { + title = "Super Loop"; + sprite = "NPRUA0"; + deaftext = "[3] Spawn Immediately"; + } + 1708 + { + title = "Drill Refill"; + sprite = "NPRUB0"; + deaftext = "[3] Spawn Immediately"; + } + 1709 + { + title = "Helper"; + sprite = "NPRUC0"; + deaftext = "[3] Spawn Immediately"; + } + 1711 + { + title = "Extra Time"; + sprite = "NPRUD0"; + deaftext = "[3] Spawn Immediately"; + } + 1712 + { + title = "Link Freeze"; + sprite = "NPRUE0"; + deaftext = "[3] Spawn Immediately"; + } + 1713 + { + arrow = 1; + title = "Hoop (Customizable)"; + sprite = "HOOPA0"; + width = 80; + height = 160; + } + } + + nightstrk + { + color = 13; // Pink + title = "Nights Track"; + width = 8; + height = 4096; + + 1700 + { + title = "Axis"; + circle = 1; + } + 1701 + { + title = "Axis Transfer"; + } + 1702 + { + title = "Axis Transfer Line"; + } + 1710 + { + title = "Egg Capsule"; + sprite = "CAPSA0"; + width = 72; + height = 144; + } + } + + nightstrk1 + { + color = 13; // Pink + title = "Nights Track (2nd Mare)"; + width = 8; + height = 4096; + + 5796 + { + title = "(Mare 2) Axis"; + circle = 1; + } + 5797 + { + title = "(Mare 2) Axis Transfer"; + } + 5798 + { + title = "(Mare 2) Axis Transfer Line"; + } + 5806 + { + title = "(Mare 2) Egg Capsule"; + sprite = "CAPSA0"; + width = 72; + height = 144; + } + } + + nightstrk2 + { + color = 13; // Pink + title = "Nights Track (3rd Mare)"; + width = 8; + height = 4096; + + 9892 + { + title = "(Mare 3) Axis"; + circle = 1; + } + 9893 + { + title = "(Mare 3) Axis Transfer"; + } + 9894 + { + title = "(Mare 3) Axis Transfer Line"; + } + 9902 + { + title = "(Mare 3) Egg Capsule"; + sprite = "CAPSA0"; + width = 72; + height = 144; + } + } + + nightstrk3 + { + color = 13; // Pink + title = "Nights Track (4th Mare)"; + width = 8; + height = 4096; + + 13988 + { + title = "(Mare 4) Axis"; + circle = 1; + } + 13989 + { + title = "(Mare 4) Axis Transfer"; + } + 13990 + { + title = "(Mare 4) Axis Transfer Line"; + } + 13998 + { + title = "(Mare 4) Egg Capsule"; + sprite = "CAPSA0"; + width = 72; + height = 144; + } + } + + nightstrk4 + { + color = 13; // Pink + title = "Nights Track (5th Mare)"; + width = 8; + height = 4096; + + 18084 + { + title = "(Mare 5) Axis"; + circle = 1; + } + 18085 + { + title = "(Mare 5) Axis Transfer"; + } + 18086 + { + title = "(Mare 5) Axis Transfer Line"; + } + 18094 + { + title = "(Mare 5) Egg Capsule"; + sprite = "CAPSA0"; + width = 72; + height = 144; + } + } + + nightstrk5 + { + color = 13; // Pink + title = "Nights Track (6th Mare)"; + width = 8; + height = 4096; + + 22180 + { + title = "(Mare 6) Axis"; + circle = 1; + } + 22181 + { + title = "(Mare 6) Axis Transfer"; + } + 22182 + { + title = "(Mare 6) Axis Transfer Line"; + } + 22190 + { + title = "(Mare 6) Egg Capsule"; + sprite = "CAPSA0"; + width = 72; + height = 144; + } + } + + nightstrk6 + { + color = 13; // Pink + title = "Nights Track (7th Mare)"; + width = 8; + height = 4096; + + 26276 + { + title = "(Mare 7) Axis"; + circle = 1; + } + 26277 + { + title = "(Mare 7) Axis Transfer"; + } + 26278 + { + title = "(Mare 7) Axis Transfer Line"; + } + 26286 + { + title = "(Mare 7) Egg Capsule"; + sprite = "CAPSA0"; + width = 72; + height = 144; + } + } + + nightstrk7 + { + color = 13; // Pink + title = "Nights Track (8th Mare)"; + width = 8; + height = 4096; + + 30372 + { + title = "(Mare 8) Axis"; + circle = 1; + } + 30373 + { + title = "(Mare 8) Axis Transfer"; + } + 30374 + { + title = "(Mare 8) Axis Transfer Line"; + } + 30382 + { + title = "(Mare 8) Egg Capsule"; + sprite = "CAPSA0"; + width = 72; + height = 144; + } + } + + mario + { + color = 6; // Brown + title = "Mario Items"; + width = 16; + height = 32; + sort = 1; + + 1800 + { + title = "Coin"; + sprite = "COINA0"; + height = 24; + deafheight = 32; + deaftext = "[3] Float"; + } + 1801 + { + arrow = 1; + title = "Goomba"; + sprite = "GOOMA0"; + width = 24; + } + 1802 + { + arrow = 1; + title = "Goomba (Blue)"; + sprite = "BGOMA0"; + width = 24; + } + 1803 + { + title = "Fire Flower"; + sprite = "FFWRB0"; + } + 1804 + { + title = "Koopa Shell"; + sprite = "SHLLA0"; + width = 8; + height = 16; + } + 1805 + { + title = "Puma (Jumping Fireball)"; + sprite = "PUMAA0"; + width = 8; + height = 16; + } + 1806 + { + title = "King Bowser"; + sprite = "KOOPA0"; + height = 28; + } + 1807 + { + title = "Axe"; + sprite = "MAXEA0"; + width = 8; + height = 16; + } + 1808 + { + title = "Bush (Short)"; + sprite = "MUS1A0"; + } + 1809 + { + title = "Bush (Tall)"; + sprite = "MUS2A0"; + } + 1810 + { + title = "Toad"; + sprite = "TOADA0"; + width = 8; + } + } + + srb1 + { + color = 3; // Cyan + arrow = 1; + title = "SRB1 Remake Items"; + width = 20; + height = 32; + sort = 1; + + 4000 + { + title = "SRB1 Crawla"; + sprite = "SRBAA1"; + height = 40; + } + 4001 + { + title = "GuardRobo"; + sprite = "SRBBA1"; + width = 17; + height = 40; + } + 4002 + { + title = "Pyrin"; + sprite = "SRBCB1"; + width = 22; + } + 4003 + { + title = "HotRobo"; + sprite = "SRBDA0"; + height = 40; + } + 4004 + { + title = "Pogminz"; + sprite = "SRBEA1"; + } + 4005 + { + title = "Pogminz (Water)"; + sprite = "SRBEA1"; + } + 4006 + { + title = "Pog-GX2"; + sprite = "SRBFA0"; + width = 10; + height = 34; + } + 4007 + { + title = "Pyrex"; + sprite = "SRBGA1"; + width = 24; + } + 4008 + { + title = "UFO"; + sprite = "SRBHA0"; + width = 24; + hangs = 1; + } + 4009 + { + title = "SWAT Bot"; + sprite = "SRBIA1"; + width = 21; + height = 69; + } + 4010 + { + title = "SpyBot 2000"; + sprite = "SRBJA0"; + width = 36; + height = 62; + } + 4011 + { + title = "Buzz Bomber"; + sprite = "SRBKA0"; + width = 44; + height = 45; + } + 4012 + { + arrow = 0; + title = "RBZ Spike"; + sprite = "SRBLA0"; + width = 10; + height = 53; + } + 4013 + { + arrow = 0; + blocking = 2; + title = "Dumb Metal Sonic"; + sprite = "SRBMC0"; + width = 16; + height = 40; + deaftext = "[3] Not Pushable"; + } + 4014 + { + title = "Super SWAT Bot"; + sprite = "SRBNA1"; + width = 21; + height = 69; + } + 4015 + { + title = "Genrex"; + sprite = "SRBOA1"; + width = 17; + height = 40; + } + } + + bsz + { + color = 2; // Green + title = "Botanic Serenity Items"; + width = 16; + height = 32; + 1400 + { + title = "Tall Flower (Red)"; + sprite = "BSZ1A0"; + } + 1401 + { + title = "Tall Flower (Purple)"; + sprite = "BSZ1B0"; + } + 1402 + { + title = "Tall Flower (Blue)"; + sprite = "BSZ1C0"; + } + 1403 + { + title = "Tall Flower (Cyan)"; + sprite = "BSZ1D0"; + } + 1404 + { + title = "Tall Flower (Yellow)"; + sprite = "BSZ1E0"; + } + 1405 + { + title = "Tall Flower (Orange)"; + sprite = "BSZ1F0"; + } + 1410 + { + title = "Medium Flower (Red)"; + sprite = "BSZ2A0"; + } + 1411 + { + title = "Medium Flower (Purple)"; + sprite = "BSZ2B0"; + } + 1412 + { + title = "Medium Flower (Blue)"; + sprite = "BSZ2C0"; + } + 1413 + { + title = "Medium Flower (Cyan)"; + sprite = "BSZ2D0"; + } + 1414 + { + title = "Medium Flower (Yellow)"; + sprite = "BSZ2E0"; + } + 1415 + { + title = "Medium Flower (Orange)"; + sprite = "BSZ2F0"; + } + 1420 + { + title = "Short Flower (Red)"; + sprite = "BSZ3A0"; + } + 1421 + { + title = "Short Flower (Purple)"; + sprite = "BSZ3B0"; + } + 1422 + { + title = "Short Flower (Blue)"; + sprite = "BSZ3C0"; + } + 1423 + { + title = "Short Flower (Cyan)"; + sprite = "BSZ3D0"; + } + 1424 + { + title = "Short Flower (Yellow)"; + sprite = "BSZ3E0"; + } + 1425 + { + title = "Short Flower (Orange)"; + sprite = "BSZ3F0"; + } + 1430 + { + title = "Tulip (Red)"; + sprite = "BSZ4A0"; + } + 1431 + { + title = "Tulip (Purple)"; + sprite = "BSZ4B0"; + } + 1432 + { + title = "Tulip (Blue)"; + sprite = "BSZ4C0"; + } + 1433 + { + title = "Tulip (Cyan)"; + sprite = "BSZ4D0"; + } + 1434 + { + title = "Tulip (Yellow)"; + sprite = "BSZ4E0"; + } + 1435 + { + title = "Tulip (Orange)"; + sprite = "BSZ4F0"; + } + 1440 + { + title = "Cluster (Red)"; + sprite = "BSZ5A0"; + } + 1441 + { + title = "Cluster (Purple)"; + sprite = "BSZ5B0"; + } + 1442 + { + title = "Cluster (Blue)"; + sprite = "BSZ5C0"; + } + 1443 + { + title = "Cluster (Cyan)"; + sprite = "BSZ5D0"; + } + 1444 + { + title = "Cluster (Yellow)"; + sprite = "BSZ5E0"; + } + 1445 + { + title = "Cluster (Orange)"; + sprite = "BSZ5F0"; + } + 1450 + { + title = "Bush (Red)"; + sprite = "BSZ6A0"; + } + 1451 + { + title = "Bush (Purple)"; + sprite = "BSZ6B0"; + } + 1452 + { + title = "Bush (Blue)"; + sprite = "BSZ6C0"; + } + 1453 + { + title = "Bush (Cyan)"; + sprite = "BSZ6D0"; + } + 1454 + { + title = "Bush (Yellow)"; + sprite = "BSZ6E0"; + } + 1455 + { + title = "Bush (Orange)"; + sprite = "BSZ6F0"; + } + 1460 + { + title = "Vine (Red)"; + sprite = "BSZ7A0"; + } + 1461 + { + title = "Vine (Purple)"; + sprite = "BSZ7B0"; + } + 1462 + { + title = "Vine (Blue)"; + sprite = "BSZ7C0"; + } + 1463 + { + title = "Vine (Cyan)"; + sprite = "BSZ7D0"; + } + 1464 + { + title = "Vine (Yellow)"; + sprite = "BSZ7E0"; + } + 1465 + { + title = "Vine (Orange)"; + sprite = "BSZ7F0"; + } + 1470 + { + title = "BSZ Shrub"; + sprite = "BSZ8A0"; + } + 1471 + { + title = "BSZ Clover"; + sprite = "BSZ8B0"; + } + 1472 + { + title = "BSZ Fish"; + sprite = "BSZ8C0"; + } + 1473 + { + title = "BSZ Sunflower"; + sprite = "BSZ8D0"; + } + } +} diff --git a/extras/conf/Srb2-21wb.cfg b/extras/conf/Srb2-21wb.cfg new file mode 100644 index 000000000..01f8762ac --- /dev/null +++ b/extras/conf/Srb2-21wb.cfg @@ -0,0 +1,2970 @@ +/******************************************************************************\ + + SRB2 Workbench + Game Configuration for SRB2 version 2.0. + + Contributors: + - Kristos + - Shadow Hog + - ST218 + - Foxboy + - JJames19119 + - SRB2-Playah + - Oogaland + - SSNTails + - DarkWarrior + - Neo + +\******************************************************************************/ + +// This is required to prevent accedential use of a different configuration. +type = "SRB2 Workbench Game Configuration"; + +// This is the title to show for this game. +game = "Sonic Robo Blast 2 v2.1"; + +// This is used internally to refer to the game. +id = "srb2-21wb"; + +// Tells Workbench that 2.1 has 4 different sector type options +seceffectnybble = 1; +thingeffectnybble = 1; + +// Defaults for new thing. +defaultthingflags = 0; +defaultthing = 1; + +// Flags indicating which header features are supported. See +// ENUM_MAPHEADER_FLAGS in soc.h for values. +headerflags = 29360130; // Map Credits, Run SOC, Subtitle, Speed Music. + +// Thing numbers for Nights axes. +nights +{ + axistransfer = 1701; + axistransferline = 1702; +} + +// Wiki page names. +wiki +{ + seceffect = "Sector+Type+%d"; + ldeffect = "Linedef+Type+%d"; + thing = "Thing+Type+%d"; +} + +// Map-type flags for the TypeOfLevel header option. +leveltypes +{ + 1 = "Single Player"; + 2 = "Co-op"; + 4 = "Competition"; + 8 = "Race"; + 16 = "Match"; + 32 = "Tag/Hide and Seek"; + 64 = "Capture the Flag"; + 128 = "Chaos (disabled)"; + 256 = "2D"; + 512 = "Mario"; + 1024 = "NiGHTS"; + 2048 = "Egg Rock Zone 3"; +} + +// Weather types for use in the header-editor. +weather +{ + 0 = "None"; + 1 = "Storm"; + 2 = "Snow"; + 3 = "Rain"; + 4 = "Blank (precalculate)"; + 5 = "Storm (no rain)"; + 6 = "Storm (no strikes)"; + 7 = "Heat Wave"; +} + +/* PSEUDO-FLATS AND TEXTURES --------------------------------------------------- + +Names of flats and textures that don't really exist, but shouldn't be identified +as invalid. + +Pattern-matching is performed on lump names. You can use the following wildcards +in values to specify ranges: + +? = Any character. +* = Zero or more characters. +# = Any numeric digit. +[abc...] = Any of these characters that are between brackets. +[!abc..] = Not any of these characters that are between brackets. + +TODO: Not actually used yet! + +*/ + +pseudoflats +{ + F_SKY1; +} + +pseudotextures +{ + [#]*; +} + +// Sky flat, used to determine whether upper/lower textures are required. +sky = "F_SKY1"; + +/* MAP LUMP NAMES -------------------------------------------------------------- + +Map lumps are loaded with the map as long as they are right after each other. +When the editor meets a lump which is not defined in this list, it will stop +loading right there. + + 1 = Lump required. + 2 = Lump which must be respected. + 4 = Lump generated by node builder. + 8 = Lump allowed to be empty after nodebuilding. + 16 = Lump allowed to be missing after nodebuilding. + 4096 = Lump which can be edited as text. + 8192 = Lump which can be edited as DEHACKED. +12288 = Lump which can be edited as MAPINFO. +16384 = WAD-global. + +*/ + +maplumpnames +{ + THINGS = 13; + LINEDEFS = 5; + SIDEDEFS = 5; + VERTEXES = 5; + SEGS = 4; + SSECTORS = 4; + NODES = 4; + SECTORS = 5; + REJECT = 4; + BLOCKMAP = 20; +} + +// SECTOR TYPES ---------------------------------------------------------------- + +sectortypes +{ + nybble0 + { + 0 = "(normal)"; + 1 = "Damage"; + 2 = "Damage (Water)"; + 3 = "Damage (Fire)"; + 4 = "Damage (Electrical)"; + 5 = "Spikes"; + 6 = "Death Pit (Camera Modifications)"; + 7 = "Death Pit (No Camera Modifications)"; + 8 = "Instant Kill"; + 9 = "Ring Drainer (Floor Touch)"; + 10 = "Ring Drainer (No Floor Touch)"; + 11 = "Special Stage Damage"; + 12 = "Space Countdown"; + 13 = "Ramp Sector (double step-up/down)"; + 14 = "Non-Ramp Sector (no step-down)"; + 15 = "Bouncy Sector (FOF Control Only)"; + } + + nybble1 + { + 0 = "(normal)"; + 1 = "Trigger Linedef Executor (Pushable Objects)"; + 2 = "Trigger Linedef Executor (Anywhere, All Players)"; + 3 = "Trigger Linedef Executor (Floor Touch, All Players)"; + 4 = "Trigger Linedef Executor (Anywhere in Sector)"; + 5 = "Trigger Linedef Executor (Floor Touch)"; + 6 = "Trigger Linedef Executor (Emerald Check)"; + 7 = "Trigger Linedef Executor (Nights Mare)"; + 8 = " Check for Linedef Executor on FOFs"; + 9 = "Egg Trap Capsule"; + 10 = "Special Stage Time/Rings Parameters"; + 11 = "Custom Global Gravity"; + } + + nybble2 + { + 0 = "(normal)"; + 1 = "Ice/Sludge"; + 2 = "Wind/Current"; + 3 = "Ice/Sludge and Wind/Current"; + 4 = "Conveyor Belt"; + 5 = "Speed Pad (No Spin)"; + 6 = "Speed Pad (Spin)"; + 7 = "Bustable Block Sprite Parameter (ROIA)"; + 8 = "Bustable Block Sprite Parameter (ROIB)"; + 9 = "Bustable Block Sprite Parameter (ROIC)"; + 10 = "Bustable Block Sprite Parameter (ROID)"; + 11 = "Bustable Block Sprite Parameter (ROIE)"; + 12 = "Bustable Block Sprite Parameter (ROIF)"; + 13 = "Bustable Block Sprite Parameter (ROIG)"; + 14 = "Bustable Block Sprite Parameter (ROIH)"; + 15 = "Bustable Block Sprite Parameter (ROII)"; + } + + nybble3 + { + 0 = "(normal)"; + 1 = "Star Post Activator"; + 2 = "Exit/Special Stage Goal/Return Flag"; + 3 = "CTF: Red Team Base"; + 4 = "CTF: Blue Team Base"; + 5 = "Fan Sector"; + 6 = "Super Sonic Transform"; + 7 = "Spinner"; + 8 = "Zoom Tube Start"; + 9 = "Zoom Tube End"; + 10 = "Finish Line"; + 11 = "Rope Hang"; + 12 = "Intangible to the Camera"; + } +} + +// LINEDEF FLAGS --------------------------------------------------------------- + +linedefflags +{ + 1 = "[00] Effect 6"; + 2 = "[01] Block Enemies"; + 4 = "[02] Double-Sided"; + 8 = "[03] Upper Unpegged"; + 16 = "[04] Lower Unpegged"; + 32 = "[05] Effect 1"; + 64 = "[06] Not Climbable"; + 128 = "[07] Effect 2"; + 256 = "[08] Effect 3"; + 512 = "[09] Effect 4"; + 1024 = "[10] Effect 5"; + 2048 = "[11] No Sonic"; + 4096 = "[12] No Tails"; + 8192 = "[13] No Knuckles"; + 16384 = "[14] Bouncy Wall"; + 32768 = "[15] Transfer Line"; +} + +// FOF INFORMATION ------------------------------------------------------------- + +fofs +{ + default = 100; + colourmap = 606; + defaultcustom = 259; + + // The FOF linedef specials, together with their FOF flags and a few + // other fields. + specials + { + 100 {flags = 415;} + 101 {flags = 479;} + 102 {flags = 6495;} + 103 {flags = 463;} + 104 {flags = 471;} + 105 {flags = 71;} + 120 {flags = 36665;} + 121 {flags = 40761;} + 122 {flags = 3889;} + 123 {flags = 7985;} + 124 {flags = 2137913;} + 125 {flags = 2105137;} + 140 {flags = 33588255;} + 141 {flags = 33560863;} + 142 {flags = 33560855;} + 143 {flags = 67142687;} + 144 {flags = 67115295;} + 145 {flags = 67115287;} + 146 {flags = 100696079;} + 150 {flags = 415; airbob = 1;} + 151 {flags = 415; airbob = 1;} + 152 {flags = 415; airbob = 1;} + 160 {flags = 262559; airbob = 1;} + 170 {flags = 1048991;} + 171 {flags = 1573279;} + 172 {flags = 34636831;} + 173 {flags = 35161119;} + 174 {flags = 34641311;} + 175 {flags = 35165599;} + 176 {flags = 1311135; airbob = 1;} + 177 {flags = 1835423; airbob = 1;} + 178 {flags = 1311135;} + 179 {flags = 1835423;} + 180 {flags = 1048991;} + 190 {flags = 415; rising = 1;} + 191 {flags = 479; rising = 1;} + 192 {flags = 6495; rising = 1;} + 193 {flags = 71; rising = 1;} + 194 {flags = 33588255; rising = 1;} + 195 {flags = 33594655; rising = 1;} + 200 {flags = 131585;} + 201 {flags = 513;} + 202 {flags = 257817;} + 220 {flags = 36633;} + 221 {flags = 6937;} + 222 {flags = 32777;} + 223 {flags = 65;} + 250 {flags = 4194719;} + 251 {flags = 415;} + 252 {flags = 142606367;} + 253 {flags = 142610463;} + 254 {flags = 8388639;} + 255 {flags = 276824095;} + 256 {flags = 276828191;} + 257 {flags = 16810521;} + 258 {flags = 2393;} + 259 {custom = 1;} + } + + // The significance of the FOF flags. Some of these have special + // meanings to the editor; for those which don't, the subsection name is + // ignored, but an entry will still be added to the list of flags for + // custom FOFs. + flags + { + FF_EXISTS {value = 1; text = "Exists.";} + FF_BLOCKPLAYER {value = 2; text = "Solid to players.";} + FF_BLOCKOTHERS {value = 4; text = "Solid to everything else.";} +// FF_SOLID {value = 6; text = "Solid to all objects."} + FF_RENDERSIDES {value = 8; text = "Renders the walls.";} + FF_RENDERPLANES {value = 16; text = "Renders the planes.";} +// FF_RENDERALL {value = 24; text = "Renders everything.} + FF_SWIMMABLE {value = 32; text = "Water block.";} + FF_NOSHADE {value = 64; text = "Doesn't cast a shadow.";} + FF_CUTSOLIDS {value = 128; text = "Skips rendering pixels hidden behind the block.";} + FF_CUTEXTRA {value = 256; text = "Skips rendering blocks marked with FF_EXTRA hidden behind the block.";} +// FF_CUTLEVEL {value = 384; text = "Skips rendering everything hidden behind the block."} + FF_CUTSPRITES {value = 512; text = "Splits sprites halfway inside the block.";} + FF_BOTHPLANES {value = 1024; text = "Renders both inside and outside planes.";} + FF_EXTRA {value = 2048; text = "Not rendered when seen through a block marked with FF_CUTEXTRA.";} + FF_TRANSLUCENT {value = 4096; text = "Translucent.";} + FF_FOG {value = 8192; text = "Fog block.";} + FF_INVERTPLANES {value = 16384; text = "Renders the planes only when within the block.";} + FF_ALLSIDES {value = 32768; text = "Renders both inside and outside walls.";} + FF_INVERTSIDES {value = 65536; text = "Renders the walls only when within the block.";} + FF_DOUBLESHADOW {value = 131072; text = "Light level and colormap affect only the inside of the block.";} + FF_FLOATBOB {value = 262144; text = "Floats on water and bobs when stepped on.";} + FF_NORETURN {value = 524288; text = "(Use with FF_CRUMBLE) Doesn't respawn after crumbling.";} + FF_CRUMBLE {value = 1048576; text = "Crumbles two seconds after being stepped on.";} + FF_SHATTERBOTTOM {value = 2097152; text = "(Use with FF_BUSTUP) Breaks only when hit from below.";} + FF_MARIO {value = 4194304; text = "Mario item block.";} + FF_BUSTUP {value = 8388608; text = "Can be broken by a spin or Knuckles.";} + FF_QUICKSAND {value = 16777216; text = "Quicksand block.";} + FF_PLATFORM {value = 33554432; text = "Intangible from bottom.";} + FF_REVERSEPLATFORM {value = 67108864; text = "Intangible from top.";} +// FF_INTANGABLEFLATS {value = 100663296; text = "Only tangible from sides.";} + FF_SHATTER {value = 134217728; text = "(Use with FF_BUSTUP) Breaks on any contact.";} + FF_SPINBUST {value = 268435456; text = "(Use with FF_BUSTUP) Breaks only with a spin from above.";} + FF_ONLYKNUX {value = 536870912; text = "(Use with FF_BUSTUP) Can only be broken by Knuckles.";} + FF_RIPPLE {value = 1073741824; text = "Employs a visual ripple effect.";} +// FF_COLORMAPONLY {value = 2147483648; text = "Ignores the control sector's light level.";} + } +} + +// LINEDEF TYPES --------------------------------------------------------------- + +linedeftypes +{ + misc + { + title = "Miscellaneous"; + values + { + 0 = "(normal)"; + 1 = "Per-Sector Gravity"; + 4 = "Speed Pad"; + 5 = "Camera Scanner"; + 6 = "Disable Linedef Effect On Level Load"; + 7 = "Sector Flat Alignment"; + 10 = "Culling Plane"; + 13 = "Heat Wave Effect"; + 50 = "Instantly Lower Floor On Level Load"; + 51 = "Instantly Raise Ceiling On Level Load"; + 63 = "Fake Floor/Ceiling Planes"; + 540 = "Floor Friction"; + } + } + + parameters + { + title = "Parameters"; + values + { + 2 = "Custom Exit"; + 3 = "Zoom Tube Parameters"; + 8 = "Sector Special Parameters"; + 9 = "Chain Parameters"; + 11 = "Rope Hang Parameters"; + 12 = "Rock Spawn Parameters"; + 64 = "Appearing/Disappearing FOF"; + 65 = " Bridge Thinker"; + } + } + + polyobject + { + title = "PolyObject"; + values + { + 20 = "First Line"; + 21 = "Explicity Include Line"; + 22 = "Parameters"; + 30 = "Waving Flag"; + } + } + + movement + { + title = "Plane Movement"; + values + { + 52 = "Continuously Falling Sector"; + 53 = "Continuous Floor/Ceiling Mover"; + 54 = "Continuous Floor Mover"; + 55 = "Continuous Ceiling Mover"; + 56 = "Continuous Two-Speed Floor/Ceiling Mover"; + 57 = "Continuous Two-Speed Floor Mover"; + 58 = "Continuous Two-Speed Ceiling Mover"; + 59 = "Activate Moving Platform"; + 60 = "Activate Moving Platform (Adjustable Speed)"; + 61 = "Crusher (Ceiling to Floor)"; + 62 = "Crusher (Floor to Ceiling)"; + } + } + + fofsolid + { + title = "FOF (solid)"; + values + { + 100 = "Solid, Opaque"; + 101 = "Solid, Opaque, No Shadow"; + 102 = "Solid, Translucent"; + 103 = "Solid, Sides Only"; + 104 = "Solid, No Sides"; + 105 = "Solid, Invisible"; + 140 = "Intangible from Bottom, Opaque"; + 141 = "Intangible from Bottom, Translucent"; + 142 = "Intangible from Bottom, Translucent, No Sides"; + 143 = "Intangible from Top, Opaque"; + 144 = "Intangible from Top, Translucent"; + 145 = "Intangible from Top, Translucent, No Sides"; + 146 = "Only Tangible From Sides"; + } + } + + fofintangible + { + title = "FOF (intangible)"; + values + { + 120 = "Water, Opaque"; + 121 = "Water, Translucent"; + 122 = "Water, Opaque, No Sides"; + 123 = "Water, Translucent, No Sides"; + 124 = "Goo Water, Translucent"; + 125 = "Goo Water, Translucent, No Sides"; + 220 = "Intangible, Opaque"; + 221 = "Intangible, Translucent"; + 222 = "Intangible, Sides Only"; + 223 = "Intangible, Invisible"; + } + } + + fofbobbing + { + title = "FOF (bobbing)"; + values + { + 150 = " Air Bobbing"; + 151 = " Air Bobbing (Adjustable)"; + 152 = " Reverse Air Bobbing (Adjustable)"; + 160 = "Floating, Bobbing"; + 190 = "Rising Platform, Solid, Opaque"; + 191 = "Rising Platform, Solid, Opaque, No Shadow"; + 192 = "Rising Platform, Solid, Translucent"; + 193 = "Rising Platform, Solid, Invisible"; + 194 = "Rising Platform, Intangible from Bottom, Opaque"; + 195 = "Rising Platform, Intangible from Bottom, Translucent"; + } + } + + fofcrumbling + { + title = "FOF (crumbling)"; + values + { + 170 = "Crumbling (Respawn)"; + 171 = "Crumbling (No Respawn)"; + 172 = "Crumbling (Respawn), Intangible from Bottom"; + 173 = "Crumbling (No Respawn), Intangible from Bottom"; + 174 = "Crumbling (Respawn), Int. from Bottom, Translucent"; + 175 = "Crumbling (No Respawn), Int. from Bottom, Translucent"; + 176 = "Crumbling (Respawn), Floating, Bobbing"; + 177 = "Crumbling (No Respawn), Floating, Bobbing"; + 178 = "Crumbling (Respawn), Floating"; + 179 = "Crumbling (No Respawn), Floating"; + 180 = "Crumbling (Respawn), Air Bobbing"; + } + } + + fofspecial + { + title = "FOF (special)"; + values + { + 200 = "Light Block"; + 201 = "Half Light Block"; + 202 = "Fog Block"; + 250 = "Mario Block"; + 251 = "Thwomp Block"; + 252 = "Shatter Block"; + 253 = "Shatter Block, Translucent"; + 254 = "Bustable Block"; + 255 = "Spin Bust Block"; + 256 = "Spin Bust Block, Translucent"; + 257 = "Quicksand"; + 258 = "Laser"; + 259 = "Custom FOF"; + } + } + + trigger + { + title = "Linedef Executor Trigger"; + values + { + 300 = "Continuous"; + 301 = "Each Time"; + 302 = "Once"; + 303 = "Ring Count - Continuous"; + 304 = "Ring Count - Once"; + 305 = "Character Ability - Once"; + 306 = "Character Ability - Each Time"; + 307 = "Character Ability - Continuous"; + 308 = "Race Only - Once"; + 309 = "CTF Red Team - Continuous"; + 310 = "CTF Red Team - Each Time"; + 311 = "CTF Blue Team - Continuous"; + 312 = "CTF Blue Team - Each Time"; + 313 = "No More Enemies - Once"; + 314 = "Number of Pushables - Continuous"; + 315 = "Number of Pushables - Once"; + 316 = "Land On PolyObject"; + 317 = "Unlockable Trigger - Continuous"; + 318 = "Unlockable Trigger - Once"; + 399 = "Level Load"; + } + } + + execsector + { + title = "Linedef Executor (sector)"; + values + { + 400 = "Set Tagged Sector's Floor Height/Texture"; + 401 = "Set Tagged Sector's Ceiling Height/Texture"; + 402 = "Set Tagged Sector's Light Level"; + 409 = "Change Tagged Sectors' Tag"; + 410 = "Change Front Sector's Tag"; + 416 = "Start Adjustable Fire Flicker"; + 417 = "Start Adjustable Glowing Light"; + 418 = "Start Adjustable Blinking Light (unsynchronized)"; + 419 = "Start Adjustable Blinking Light (synchronized)"; + 420 = "Fade Light Level"; + 421 = "Stop Lighting Effect"; + 435 = "Change Plane Scroller Direction"; + } + } + + execplane + { + title = "Linedef Executor (plane movement)"; + values + { + 403 = "Move Tagged Sector's Floor"; + 404 = "Move Tagged Sector's Ceiling"; + 405 = "Move Floor According to Front Texture Offsets"; + 407 = "Move Ceiling According to Front Texture Offsets"; + 411 = "Stop Plane Movement"; + 428 = "Start Platform Movement"; + 429 = "Crush Ceiling Once"; + 430 = "Crush Floor Once"; + 431 = "Crush Floor And Ceiling Once"; + } + } + + execplayer + { + title = "Linedef Executor (player/object)"; + values + { + 412 = "Teleporter"; + 425 = "Change Object State"; + 426 = "Stop Object"; + 427 = "Award Score"; + 432 = "Enable/Disable 2D Mode"; + 433 = "Enable/Disable Gravity Flip"; + 434 = "Award Power-Up"; + 437 = "Disable Player Control"; + 438 = "Change Object Size"; + 442 = "Change Object Type State"; + } + } + + execmisc + { + title = "Linedef Executor (misc.)"; + values + { + 413 = "Change Music"; + 414 = "Play Sound Effect"; + 415 = "Run Script"; + 422 = "Switch to Cut-Away View"; + 423 = "Change Sky"; + 424 = "Change Weather"; + 436 = "Shatter FOF"; + 439 = "Set Texture"; + 440 = "Start Metal Sonic Race"; + 441 = "Unlockable Trigger"; + 443 = "Call Lua Function"; + 444 = "Earthquake"; + 445 = "Force Block Disappear"; + 450 = "Execute Linedef Executor (from tag)"; + 451 = "Execute Linedef Executor (random range)"; + } + } + + execpoly + { + title = "Linedef Executor (polyobject)"; + values + { + 480 = "Door Slide"; + 481 = "Door Swing"; + 482 = "Move"; + 483 = "Move, Override"; + 484 = "Rotate Right"; + 485 = "Rotate Right, Override"; + 486 = "Rotate Left"; + 487 = "Rotate Left, Override"; + 488 = "Move by Waypoints"; + 489 = "Turn Invisible, Intangible"; + 490 = "Turn Visible, Tangible"; + 491 = "Set Translucency"; + } + } + + wall + { + title = "Texture settings/Wall Scrolling"; + values + { + 500 = "Scroll Wall Front Side Left"; + 501 = "Scroll Wall Front Side Right"; + 502 = "Scroll Wall According to Linedef"; + 503 = "Scroll Wall According to Linedef (Accelerative)"; + 504 = "Scroll Wall According to Linedef (Displacement)"; + 505 = "Scroll Texture by Front Side Offsets"; + 506 = "Scroll Texture by Back Side Offsets"; + } + } + + plane + { + title = "Plane Scrolling"; + values + { + 510 = "Scroll Floor Texture"; + 511 = "Scroll Floor Texture (Accelerative)"; + 512 = "Scroll Floor Texture (Displacement)"; + 513 = "Scroll Ceiling Texture"; + 514 = "Scroll Ceiling Texture (Accelerative)"; + 515 = "Scroll Ceiling Texture (Displacement)"; + 520 = "Carry Objects on Floor"; + 521 = "Carry Objects on Floor (Accelerative)"; + 522 = "Carry Objects on Floor (Displacement)"; + 523 = "Carry Objects on Ceiling"; + 524 = "Carry Objects on Ceiling (Accelerative)"; + 525 = "Carry Objects on Ceiling (Displacement)"; + 530 = "Scroll Floor Texture and Carry Objects"; + 531 = "Scroll Floor Texture and Carry Objects (Accelerative)"; + 532 = "Scroll Floor Texture and Carry Objects (Displacement)"; + 533 = "Scroll Ceiling Texture and Carry Objects"; + 534 = "Scroll Ceiling Texture and Carry Objects (Accelerative)"; + 535 = "Scroll Ceiling Texture and Carry Objects (Displacement)"; + } + } + + pusher + { + title = "Pusher"; + values + { + 541 = "Wind"; + 542 = "Upwards Wind"; + 543 = "Downwards Wind"; + 544 = "Current"; + 545 = "Upwards Current"; + 546 = "Downwards Current"; + 547 = "Push/Pull"; + } + } + + lighting + { + title = "Lighting"; + values + { + 600 = "Floor Lighting"; + 601 = "Ceiling Lighting"; + 602 = "Adjustable Pulsating Light"; + 603 = "Adjustable Flickering Light"; + 604 = "Adjustable Blinking Light (unsynchronized)"; + 605 = "Adjustable Blinking Light (synchronized)"; + 606 = "Colormap"; + } + } + + transwall + { + title = "Translucent Wall"; + values + { + 900 = "90% Opaque"; + 901 = "80% Opaque"; + 902 = "70% Opaque"; + 903 = "60% Opaque"; + 904 = "50% Opaque"; + 905 = "40% Opaque"; + 906 = "30% Opaque"; + 907 = "20% Opaque"; + 908 = "10% Opaque"; + 909 = "Fog Wall"; + } + } +} + +// THING FLAGS ----------------------------------------------------------------- + +thingflags +{ + 1 = "[0] Unused Flag"; + 2 = "[1] Object Flip"; + 4 = "[2] Object Special"; + 8 = "[3] Ambush"; + 16 = "(Used for Z offsets)"; +} + +/* THING TYPES ----------------------------------------------------------------- + +Color values are 24-bit RGB colors in decimal. + +*/ + +thingtypes +{ + starts + { + color = 223; // Blue (0000DF) + arrow = 1; + title = "Player Starts"; + width = 16; + height = 56; + deaftext = "[3] Spawn On Ceiling"; + values + { + 1 + { + title = "Player 01 Start"; + sprite = "SUPTD0"; + } + 2 + { + title = "Player 02 Start"; + sprite = "SUPTD0"; + } + 3 + { + title = "Player 03 Start"; + sprite = "SUPTD0"; + } + 4 + { + title = "Player 04 Start"; + sprite = "SUPTD0"; + } + 5 + { + title = "Player 05 Start"; + sprite = "SUPTD0"; + } + 6 + { + title = "Player 06 Start"; + sprite = "SUPTD0"; + } + 7 + { + title = "Player 07 Start"; + sprite = "SUPTD0"; + } + 8 + { + title = "Player 08 Start"; + sprite = "SUPTD0"; + } + 9 + { + title = "Player 09 Start"; + sprite = "SUPTD0"; + } + 10 + { + title = "Player 10 Start"; + sprite = "SUPTD0"; + } + 11 + { + title = "Player 11 Start"; + sprite = "SUPTD0"; + } + 12 + { + title = "Player 12 Start"; + sprite = "SUPTD0"; + } + 13 + { + title = "Player 13 Start"; + sprite = "SUPTD0"; + } + 14 + { + title = "Player 14 Start"; + sprite = "SUPTD0"; + } + 15 + { + title = "Player 15 Start"; + sprite = "SUPTD0"; + } + 16 + { + title = "Player 16 Start"; + sprite = "SUPTD0"; + } + 17 + { + title = "Player 17 Start"; + sprite = "SUPTD0"; + } + 18 + { + title = "Player 18 Start"; + sprite = "SUPTD0"; + } + 19 + { + title = "Player 19 Start"; + sprite = "SUPTD0"; + } + 20 + { + title = "Player 20 Start"; + sprite = "SUPTD0"; + } + 21 + { + title = "Player 21 Start"; + sprite = "SUPTD0"; + } + 22 + { + title = "Player 22 Start"; + sprite = "SUPTD0"; + } + 23 + { + title = "Player 23 Start"; + sprite = "SUPTD0"; + } + 24 + { + title = "Player 24 Start"; + sprite = "SUPTD0"; + } + 25 + { + title = "Player 25 Start"; + sprite = "SUPTD0"; + } + 26 + { + title = "Player 26 Start"; + sprite = "SUPTD0"; + } + 27 + { + title = "Player 27 Start"; + sprite = "SUPTD0"; + } + 28 + { + title = "Player 28 Start"; + sprite = "SUPTD0"; + } + 29 + { + title = "Player 29 Start"; + sprite = "SUPTD0"; + } + 30 + { + title = "Player 30 Start"; + sprite = "SUPTD0"; + } + 31 + { + title = "Player 31 Start"; + sprite = "SUPTD0"; + } + 32 + { + title = "Player 32 Start"; + sprite = "SUPTD0"; + } + 33 + { + title = "Match Start"; + sprite = "SUPTI0"; + } + 34 + { + title = "CTF Red Team Start"; + sprite = "SIGNG0"; + } + 35 + { + title = "CTF Blue Team Start"; + sprite = "SIGNE0"; + } + } + } + + enemies + { + color = 6250495; // Light blue (5F5FFF) + arrow = 1; + title = "Enemies"; + width = 24; + height = 32; + values + { + 100 + { + title = "Crawla (Blue)"; + sprite = "POSSA1"; + } + 101 + { + title = "Crawla (Red)"; + sprite = "SPOSA1"; + } + 102 + { + title = "Stupid Dumb Unnamed RoboFish"; + sprite = "FISHA0"; + width = 8; + height = 28; + } + 103 + { + title = "Buzz (Gold)"; + sprite = "BUZZA1"; + width = 20; + height = 24; + deaftext = "[3] Cannot Move"; + } + 104 + { + title = "Buzz (Red)"; + sprite = "RBUZA1"; + width = 20; + height = 24; + deaftext = "[3] Cannot Move"; + + } + 105 + { + title = "Jetty-Syn Bomber"; + sprite = "JETBB1"; + width = 20; + height = 50; + deaftext = "[3] Cannot Move"; + } + 106 + { + title = "Jetty-Syn Gunner"; + sprite = "JETGB1"; + width = 20; + height = 48; + deaftext = "[3] Cannot Move"; + } + 107 + { + title = "Crawla Commander"; + sprite = "CCOMA1"; + width = 16; + } + 108 + { + title = "Deton"; + sprite = "DETNA1"; + width = 20; + } + 109 + { + title = "Skim"; + sprite = "SKIMA1"; + width = 16; + height = 24; + } + 110 + { + title = "Turret"; + sprite = "TRETA1"; + width = 16; + height = 32; + } + 111 + { + title = "Popup Turret"; + sprite = "TURRI1"; + width = 12; + height = 64; + } + 112 + { + title = "Sharp"; + sprite = "SHRPA1"; + width = 16; + height = 24; + } + 113 + { + title = "Jet Jaw"; + sprite = "JJAWA3A7"; + width = 12; + height = 20; + } + 114 + { + title = "Snailer"; + sprite = "SNLRA3A7"; + height = 48; + } + 115 + { + title = "Bird Aircraft Strike Hazard"; + sprite = "VLTRF1"; + width = 12; + height = 24; + } + 116 + { + title = "Pointy"; + sprite = "PNTYA1"; + width = 8; + height = 16; + } + 117 + { + title = "Robo-Hood"; + sprite = "ARCHA1"; + deaftext = "[3] Cannot Jump"; + } + 118 + { + title = "CastleBot FaceStabber"; + sprite = "CBFSA1"; + width = 32; + height = 64; + } + 119 + { + title = "Egg Guard"; + sprite = "ESHIA1"; + width = 16; + height = 48; + deaftext = "[3] Double Speed"; + } + 120 + { + title = "Green Snapper"; + sprite = "GSNPA1"; + height = 24; + } + 121 + { + title = "Minus"; + sprite = "MNUSA1"; + } + 122 + { + title = "Spring Shell (Green)"; + sprite = "SSHLA1"; + height = 40; + } + 123 + { + title = "Unidus"; + sprite = "UNIDA1"; + width = 18; + height = 36; + } + 124 + { + title = "AquaBuzz"; + sprite = "BBUZA1"; + width = 20; + height = 24; + } + 125 + { + title = "Spring Shell (Yellow)"; + sprite = "YSHLA1"; + height = 40; + } + 750 + { + title = " Chaos Enemy Spawn"; + sprite = "TFOGG0"; + width = 32; + height = 64; + } + } + } + + bosses + { + color = 6250335; // Grey (5F5F5F) + arrow = 1; + title = "Bosses"; + width = 24; + height = 76; + values + { + 200 + { + title = "Boss 1 - Egg Mobile"; + sprite = "EGGMA1"; + spectext = "[2] End Level On Death"; + deaftext = "[3] Rotating Spikeballs"; + } + 201 + { + title = "Boss 2 - Egg Slimer"; + sprite = "EGGNA1"; + height = 48; + spectext = "[2] End Level On Death"; + deaftext = "[3] Speed Up When Hit"; + } + 202 + { + title = "Boss 3 - Sea Egg"; + sprite = "EGGOA1"; + width = 32; + height = 116; + spectext = "[2] End Level On Death"; + } + 203 + { + title = "Boss 4 - Eggscalibur"; + sprite = "EGGPA1"; + spectext = "[2] End Level On Death"; + } + 206 + { + title = "Boss - Black Eggman (Old)"; + sprite = "BRAKB1"; + width = 48; + height = 160; + spectext = "[2] End Level On Death"; + } + 207 + { + title = "Boss 5A - Metal Sonic Race Start"; + sprite = "METLI1"; + width = 16; + height = 48; + } + 208 + { + title = "Boss 5B - Metal Sonic Battle Start"; + sprite = "METLC1"; + width = 16; + height = 48; + spectext = "[2] End Level On Death"; + } + 209 + { + title = "Boss 6 - Black Eggman (New)"; + sprite = "BRAK[1"; + width = 48; + height = 160; + spectext = "[2] End Level On Death"; + deaftext = "[3] Electric Barrier"; + } + 290 + { + arrow = 0; + title = "Boss Escape Point"; + width = 8; + height = 16; + } + 291 + { + arrow = 0; + title = "Egg Trap Center"; + width = 8; + height = 16; + } + 292 + { + arrow = 0; + title = "Boss Waypoint"; + width = 8; + height = 16; + deaftext = "[3] Sea Egg Shooting Point"; + } + 293 = "Metal Sonic Waypoint"; + } + } + + rings + { + color = 12566272; // Yellow (BFBF00) + title = "Rings and Weapon Panels"; + width = 24; + height = 24; + deafheight = 32; + deaftext = "[3] Float"; + values + { + 300 + { + title = "Ring"; + sprite = "RINGA0"; + width = 16; + } + 301 + { + title = "Bounce Ring"; + sprite = "CPRKB0"; + } + 302 + { + title = "Rail Ring"; + sprite = "SPRKA0"; + } + 304 + { + title = "Automatic Ring"; + sprite = "TAUTA3A7"; + } + 305 + { + title = "Explosion Ring"; + sprite = "BMSLA1"; + } + 306 + { + title = "Scatter Ring"; + sprite = "TSCRA1A5"; + } + 307 + { + title = "Grenade Ring"; + sprite = "TGREA0"; + } + 308 + { + title = "CTF Team Ring (Red)"; + sprite = "RRNGA0"; + width = 16; + } + 309 + { + title = "CTF Team Ring (Blue)"; + sprite = "TRNGA0"; + width = 16; + } + 330 + { + title = "Bounce Ring Panel"; + sprite = "PIKBA0"; + } + 331 + { + title = "Rail Ring Panel"; + sprite = "PIKRA0"; + } + 332 + { + title = "Automatic Ring Panel"; + sprite = "PIKAA0"; + } + 333 + { + title = "Explosion Ring Panel"; + sprite = "PIKEA0"; + } + 334 + { + title = "Scatter Ring Panel"; + sprite = "PIKSA0"; + } + 335 + { + title = "Grenade Ring Panel"; + sprite = "PIKGA0"; + } + } + } + + collectibles + { + color = 48896; // Green (00BF00) + title = "Other Collectibles"; + width = 16; + height = 32; + values + { + 310 + { + title = "CTF Red Flag"; + sprite = "RFLGA0"; + width = 24; + height = 64; + } + 311 + { + title = "CTF Blue Flag"; + sprite = "BFLGA0"; + width = 24; + height = 64; + } + 312 + { + title = "Special Stage Token"; + sprite = "TOKEA0"; + width = 8; + height = 16; + deafheight = 32; + spectext = "[2] Mario Block Version"; + deaftext = "[3] Float"; + } + 313 + { + title = "Chaos Emerald 1 (Green)"; + sprite = "EMMYA0"; + } + 314 + { + title = "Chaos Emerald 2 (Purple)"; + sprite = "EMMYB0"; + } + 315 + { + title = "Chaos Emerald 3 (Blue)"; + sprite = "EMMYC0"; + } + 316 + { + title = "Chaos Emerald 4 (Cyan)"; + sprite = "EMMYD0"; + } + 317 + { + title = "Chaos Emerald 5 (Orange)"; + sprite = "EMMYE0"; + } + 318 + { + title = "Chaos Emerald 6 (Red)"; + sprite = "EMMYF0"; + } + 319 + { + title = "Chaos Emerald 7 (Gray)"; + sprite = "EMMYG0"; + } + 320 + { + title = "Emerald Hunt Location"; + sprite = "EMERA0"; + } + 323 + { + title = "Match Chaos Emerald Spawn"; + sprite = "CEMGA0"; + width = 8; + height = 48; + deafheight = 32; + deaftext = "[3] Float"; + } + } + } + + boxes + { + color = 12566463; // Silver (BFBFBF) + blocking = 2; + title = "Item Boxes"; + width = 16; + height = 32; + spectext = "[2] Random (Strong)"; + deaftext = "[3] Random (Weak)"; + values + { + 400 + { + title = "Super Ring (10 Rings)"; + sprite = "SRBXA0"; + } + 401 + { + title = "Pity / Basic Shield"; + sprite = "GRTVA0"; + } + 402 + { + title = "Attraction Shield"; + sprite = "YLTVA0"; + } + 403 + { + title = "Force Shield"; + sprite = "BLTVA0"; + } + 404 + { + title = "Armageddon Shield"; + sprite = "BKTVA0"; + } + 405 + { + title = "Whirlwind Shield"; + sprite = "WHTVA0"; + } + 406 + { + title = "Elemental Shield"; + sprite = "ELTVA0"; + } + 407 + { + title = "Super Sneakers"; + sprite = "SHTVA0"; + } + 408 + { + title = "Invincibility"; + sprite = "PINVA0"; + } + 409 + { + title = "Extra Life"; + sprite = "PRUPA0"; + spectext = "[2] Random (Strong) / 10k points"; + deaftext = "[3] Random (Weak) / 10k points"; + } + 410 + { + title = "Eggman"; + sprite = "EGGBA0"; + } + 411 + { + title = "Teleporter"; + sprite = "MIXUA0"; + } + 412 + { + title = "Random"; + sprite = "QUESA0"; + } + 413 + { + title = "Gravity Boots"; + sprite = "GBTVA0"; + } + 414 + { + title = "CTF Team Ring Box (Red)"; + sprite = "RRBXA0"; + spectext = "[2] Object Special"; + deaftext = "[3] Ambush"; + } + 415 + { + title = "CTF Team Ring Box (Blue)"; + sprite = "BRBXA0"; + spectext = "[2] Object Special"; + deaftext = "[3] Ambush"; + } + 416 + { + title = "Recycler"; + sprite = "RECYA0"; + } + 418 + { + title = "1,000 Points"; + sprite = "PTTVA0"; + } + 419 + { + title = "10,000 Points"; + sprite = "PTTVF0"; + } + } + } + + miscellaneous + { + color = 49119; // Sky blue (00BFDF) + title = "Miscellaneous"; + width = 16; + height = 40; + values + { + 500 + { + title = "Air Bubble Patch"; + sprite = "BUBLA0"; + width = 8; + height = 16; + deaftext = "[3] No Distance Check"; + } + 501 + { + title = "End Level Sign"; + sprite = "SIGND0"; + width = 8; + height = 32; + } + 502 + { + arrow = 1; + title = "Star Post"; + sprite = "STPTA0"; + width = 64; + height = 80; + } + 526 + { + blocking = 2; + title = "Cannonball"; + sprite = "CBLLA0"; + width = 20; + spectext = "[2] Slides When Pushed"; + deaftext = "[3] Not Pushable"; + } + 1000 + { + arrow = 1; + blocking = 2; + title = "Gargoyle"; + sprite = "GARGA1"; + spectext = "[2] Slides When Pushed"; + deaftext = "[3] Not Pushable"; + } + 1102 + { + arrow = 1; + blocking = 2; + title = "Eggman Statue"; + sprite = "ESTAA1"; + width = 32; + height = 240; + spectext = "[2] Slides When Pushed"; + deaftext = "[3] Not Pushable"; + } + 1106 + { + arrow = 1; + title = "Chain (Hang)"; + sprite = "SMCHA0"; + height = 32; + deaftext = "[3] Double Size"; + } + 1107 + { + arrow = 1; + title = "Chain (Spin)"; + sprite = "SMCHA0"; + height = 32; + deaftext = "[3] Double Size"; + } + 1200 + { + title = "Tumbleweed (Big)"; + sprite = "BTBLA0"; + width = 24; + height = 28; + deaftext = "[3] Moves Perpetually"; + } + 1201 + { + title = "Tumbleweed (Small)"; + sprite = "STBLA0"; + width = 12; + height = 24; + deaftext = "[3] Moves Perpetually"; + } + 1504 + { + title = "ATZ Target"; + sprite = "RCRYB0"; + width = 24; + height = 32; + } + 1852 + { + blocking = 2; + title = "Snowman"; + sprite = "XMS3A0"; + spectext = "[2] Slides When Pushed"; + deaftext = "[3] Not Pushable"; + } + 1876 + { + arrow = 1; + blocking = 2; + title = "Eggman Disco Statue"; + sprite = "ESTAB1"; + width = 20; + height = 96; + spectext = "[2] Slides When Pushed"; + deaftext = "[3] Not Pushable"; + } + } + } + + springs + { + color = 14614528; // Red (DF0000) + title = "Springs and Fans"; + width = 20; + height = 16; + values + { + 540 + { + title = "Fan"; + sprite = "FANSA0D0"; + width = 16; + deaftext = "[3] No Distance Check"; + } + 541 + { + title = "Gas Jet"; + sprite = "STEMD0"; + width = 32; + } + 550 + { + title = "Yellow Spring"; + sprite = "SPRYA0"; + } + 551 + { + title = "Red Spring"; + sprite = "SPRRA0"; + } + 552 + { + title = "Blue Spring"; + sprite = "SPRBA0"; + } + 555 + { + arrow = 1; + title = "Diagonal Yellow Spring"; + sprite = "YSPRD2"; + width = 16; + deaftext = "[3] Rotate 22.5° CCW"; + } + 556 + { + arrow = 1; + title = "Diagonal Red Spring"; + sprite = "RSPRD2"; + width = 16; + deaftext = "[3] Rotate 22.5° CCW"; + } + } + } + + patterns + { + color = 10420319; // Dark Rose (9F005F) + arrow = 1; + title = "Special Placement Patterns"; + width = 16; + height = 384; + values + { + 600 + { + arrow = 0; + title = "5 Vertical Rings (Yellow Spring)"; + sprite = "RINGA0"; + } + 601 + { + arrow = 0; + title = "5 Vertical Rings (Red Spring)"; + sprite = "RINGA0"; + height = 1024; + } + 602 + { + title = "5 Diagonal Rings (Yellow Spring)"; + sprite = "RINGA0"; + height = 32; + } + 603 + { + title = "10 Diagonal Rings (Red Spring)"; + sprite = "RINGA0"; + height = 32; + } + 604 + { + title = "Circle of Rings"; + sprite = "RINGA0"; + width = 96; + height = 192; + } + 605 + { + title = "Circle of Rings (Big)"; + sprite = "RINGA0"; + width = 192; + } + 606 + { + title = "Circle of Wing Logos"; + sprite = "NWNGA0"; + width = 96; + height = 192; + } + 607 + { + title = "Circle of Wing Logos (Big)"; + sprite = "NWNGA0"; + width = 192; + } + 608 + { + title = "Circle of Rings and Wings"; + sprite = "NWNGA0"; + width = 96; + height = 192; + } + 609 + { + title = "Circle of Rings and Wings (Big)"; + sprite = "NWNGA0"; + width = 192; + } + } + } + + invisible + { + color = 16777215; // White (FFFFFF) + title = "Misc. Invisible"; + width = 8; + height = 16; + values + { + 700 = "Water Ambience A (Large)"; + 701 = "Water Ambience B (Large)"; + 702 = "Water Ambience C (Medium)"; + 703 = "Water Ambience D (Medium)"; + 704 = "Water Ambience E (Small)"; + 705 = "Water Ambience F (Small)"; + 706 = "Water Ambience G (Extra Large)"; + 707 = "Water Ambience H (Extra Large)"; + 708 = "Disco Ambience"; + 709 = "Volcano Ambience"; + 751 + { + arrow = 1; + title = "Teleport Destination"; + } + 752 + { + arrow = 1; + title = "Alternate View Point"; + } + 753 = "Zoom Tube Waypoint"; + 754 + { + title = "Push Point"; + spectext = "[2] Fades Using XY"; + deaftext = "[3] Push Using XYZ"; + } + 755 + { + title = "Pull Point"; + spectext = "[2] Fades Using XY"; + deaftext = "[3] Pull Using XYZ"; + } + 760 = "PolyObject Anchor"; + 761 = "PolyObject Spawn Point"; + 762 = "PolyObject Spawn Point (Crush)"; + 780 + { + title = "Skybox View Point"; + spectext = "[2] In-Map Reference Point"; + } + } + } + + hazards + { + color = 10420224; // Maroon (9F0000) + title = "Hazards"; + width = 20; + height = 40; + values + { + 521 + { + title = "Spikeball"; + sprite = "SPIKA0"; + width = 12; + height = 24; + deafheight = 32; + deaftext = "[3] Float"; + } + 523 + { + title = "Spike (Floor)"; + sprite = "USPKA0"; + width = 8; + height = 42; + spectext = "[2] Retractable"; + deaftext = "[3] Solid"; + } + 524 + { + arrow = 1; + title = "Big Floating Mine"; + width = 16; + height = 32; + sprite = "BMNEA1"; + } + 527 + { + arrow = 1; + title = "Big Floating Mine (Air)"; + width = 16; + height = 32; + sprite = "BMNEA1"; + } + 525 + { + title = "Cannonball Launcher"; + sprite = "CBLLA0"; + } + 1101 + { + title = "Torch"; + sprite = "FLAMA0"; + width = 8; + height = 32; + } + 1104 + { + title = "Mace (Spinning)"; + sprite = "SMCEA0"; + spectext = "[2] No Sounds"; + deaftext = "[3] Double Size"; + } + 1105 + { + title = "Mace (Swinging)"; + sprite = "SMCEA0"; + spectext = "[2] No Sounds"; + deaftext = "[3] Double Size"; + } + 1202 + { + arrow = 1; + title = "Rock Spawner"; + sprite = "ROIAA0"; + } + 1300 + { + arrow = 1; + title = "Flame Jet (Horizontal)"; + sprite = "FLMEB0"; + width = 16; + deaftext = "[3] Waves Vertically"; + } + 1301 + { + title = "Flame Jet (Vertical)"; + sprite = "FLMEB0"; + width = 16; + deaftext = "[3] Shoot Downwards"; + } + 1500 + { + arrow = 1; + blocking = 2; + title = "Trapgoyle"; + sprite = "GARGA1"; + width = 16; + height = 40; + spectext = "[2] Slides When Pushed"; + deaftext = "[3] Not Pushable"; + } + 1501 + { + arrow = 1; + blocking = 2; + title = "Trapgoyle (Up)"; + sprite = "GARGA1"; + width = 16; + height = 40; + spectext = "[2] Slides When Pushed"; + deaftext = "[3] Not Pushable"; + } + 1502 + { + arrow = 1; + blocking = 2; + title = "Trapgoyle (Down)"; + sprite = "GARGA1"; + width = 16; + height = 40; + spectext = "[2] Slides When Pushed"; + deaftext = "[3] Not Pushable"; + } + 1503 + { + arrow = 1; + blocking = 2; + title = "Trapgoyle (Long)"; + sprite = "GARGA1"; + width = 16; + height = 40; + spectext = "[2] Slides When Pushed"; + deaftext = "[3] Not Pushable"; + } + 3575 + { + title = "Spinning Flame Jet (Counter-Clockwise)"; + sprite = "FLMEB0"; + width = "16"; + } + 3576 + { + title = "Spinning Flame Jet (Clockwise)"; + sprite = "FLMEB0"; + width = "16"; + } + } + } + + decoration + { + color = 4153088; // Dark lime (3F5F00) + title = "Decoration"; + width = 16; + height = 40; + values + { + 757 + { + title = "Fan Particle Generator"; + sprite = "PRTLA0"; + width = 8; + height = 16; + } + 800 + { + title = "GFZ Flower"; + sprite = "FWR1A0"; + } + 801 + { + title = "Sunflower"; + sprite = "FWR2A0"; + height = 96; + } + 802 + { + title = "Budding Flower"; + sprite = "FWR3A0"; + width = 8; + height = 32; + } + 804 + { + title = "Berry Bush"; + sprite = "BUS1A0"; + height = 32; + } + 805 + { + title = "Bush"; + sprite = "BUS2A0"; + height = 32; + } + 900 + { + title = "THZ Flower"; + sprite = "THZPA0"; + width = 8; + height = 32; + } + 901 + { + title = "Alarm"; + sprite = "ALRMA0"; + width = 8; + height = 16; + hangs = 1; + } + 1001 + { + title = "Seaweed"; + sprite = "SEWEA0"; + width = 24; + height = 56; + } + 1002 + { + title = "Dripping Water"; + sprite = "DRIPD0"; + width = 8; + height = 16; + hangs = 1; + } + 1003 + { + title = "Coral (Green)"; + sprite = "CRL1A0"; + width = 8; + height = 16; + } + 1004 + { + title = "Coral (Red)"; + sprite = "CRL2A0"; + width = 8; + height = 16; + } + 1005 + { + title = "Coral (Orange)"; + sprite = "CRL3A0"; + width = 8; + height = 16; + } + 1006 + { + title = "Blue Crystal"; + sprite = "BCRYA1"; + width = 8; + height = 16; + } + 1100 + { + title = "Chain"; + sprite = "CHANA0"; + width = 8; + height = 128; + hangs = 1; + } + 1103 + { + title = "CEZ Flower"; + sprite = "FWR4A0"; + } + 1203 + { + title = "Cactus with Brown Flower"; + sprite = "CACTA0"; + height = 32; + } + 1204 + { + title = "Cactus with Brown Flower (Tall)"; + sprite = "CACTB0"; + height = 64; + } + 1205 + { + title = "Cactus with Blue Flower"; + sprite = "CACTC0"; + height = 32; + } + 1206 + { + title = "Cactus with Blue Flower (Tall)"; + sprite = "CACTD0"; + height = 80; + } + 1850 + { + title = "Xmas Pole"; + sprite = "XMS1A0"; + } + 1851 + { + title = "Candy Cane"; + sprite = "XMS2A0"; + width = 8; + height = 32; + } + 1875 + { + title = "Disco Ball"; + sprite = "DBALA0"; + height = 54; + hangs = 1; + } + 1900 + { + title = "Brown Stalagmite (Tall)"; + sprite = "STLGA0"; + } + 1901 + { + title = "Brown Stalagmite"; + sprite = "STLGB0"; + } + 1902 + { + title = "Orange Stalagmite (Tall)"; + sprite = "STLGC0"; + } + 1903 + { + title = "Orange Stalagmite"; + sprite = "STLGD0"; + } + 1904 + { + title = "Red Stalagmite (Tall)"; + sprite = "STLGE0"; + } + 1905 + { + title = "Red Stalagmite"; + sprite = "STLGF0"; + } + 1906 + { + title = "Gray Stalagmite (Tall)"; + sprite = "STLGG0"; + } + 1907 + { + title = "Gray Stalagmite"; + sprite = "STLGH0"; + } + 1908 + { + title = "Blue Stalagmite (Tall)"; + sprite = "STLGI0"; + } + 1909 + { + title = "Blue Stalagmite"; + sprite = "STLGJ0"; + } + } + } + + nights + { + color = 12517599; // Violet (BF00DF) + title = "Nights Items"; + width = 12; + height = 32; + values + { + 1703 + { + title = "Ideya Drone"; + sprite = "NDRNA1"; + width = 16; + height = 56; + deaftext = "[3] Die Upon Time Up"; + } + 1704 + { + arrow = 1; + title = "Bumper"; + sprite = "NBMPG3G7"; + width = 32; + height = 64; + } + 1705 + { + arrow = 1; + title = "Hoop"; + sprite = "HOOPA0"; + width = 80; + height = 160; + } + 1713 + { + arrow = 1; + title = "Custom Hoop"; + sprite = "HOOPA0"; + width = 80; + height = 160; + } + 1706 + { + title = "Wing Logo"; + sprite = "NWNGA0"; + height = 24; + } + 1707 + { + title = "Super Loop"; + sprite = "NPRUA0"; + deaftext = "[3] Spawn Immediately"; + } + 1708 + { + title = "Drill Refill"; + sprite = "NPRUB0"; + deaftext = "[3] Spawn Immediately"; + } + 1709 + { + title = "Helper"; + sprite = "NPRUC0"; + deaftext = "[3] Spawn Immediately"; + } + 1711 + { + title = "Extra Time"; + sprite = "NPRUD0"; + deaftext = "[3] Spawn Immediately"; + } + 1712 + { + title = "Link Freeze"; + sprite = "NPRUE0"; + deaftext = "[3] Spawn Immediately"; + } + } + } + + nightstrk + { + color = 12517599; // Violet (BF00DF) + title = "Nights Track"; + width = 8; + height = 4096; + values + { + 1700 + { + title = "Axis"; + circle = 1; + } + 1701 + { + title = "Axis Transfer"; + } + 1702 + { + title = "Axis Transfer Line"; + } + 1710 + { + title = "Egg Capsule"; + sprite = "CAPSA0"; + width = 72; + height = 144; + } + } + } + + nightstrk1 + { + color = 12517599; // Violet (BF00DF) + title = "Nights Track (2nd Mare)"; + width = 8; + height = 4096; + values + { + 5796 + { + title = "(Mare 2) Axis"; + circle = 1; + } + 5797 + { + title = "(Mare 2) Axis Transfer"; + } + 5798 + { + title = "(Mare 2) Axis Transfer Line"; + } + 5806 + { + title = "(Mare 2) Egg Capsule"; + sprite = "CAPSA0"; + width = 72; + height = 144; + } + } + } + + nightstrk2 + { + color = 12517599; // Violet (BF00DF) + title = "Nights Track (3rd Mare)"; + width = 8; + height = 4096; + values + { + 9892 + { + title = "(Mare 3) Axis"; + circle = 1; + } + 9893 + { + title = "(Mare 3) Axis Transfer"; + } + 9894 + { + title = "(Mare 3) Axis Transfer Line"; + } + 9902 + { + title = "(Mare 3) Egg Capsule"; + sprite = "CAPSA0"; + width = 72; + height = 144; + } + } + } + + nightstrk3 + { + color = 12517599; // Violet (BF00DF) + title = "Nights Track (4th Mare)"; + width = 8; + height = 4096; + values + { + 13988 + { + title = "(Mare 4) Axis"; + circle = 1; + } + 13989 + { + title = "(Mare 4) Axis Transfer"; + } + 13990 + { + title = "(Mare 4) Axis Transfer Line"; + } + 13998 + { + title = "(Mare 4) Egg Capsule"; + sprite = "CAPSA0"; + width = 72; + height = 144; + } + } + } + + nightstrk4 + { + color = 12517599; // Violet (BF00DF) + title = "Nights Track (5th Mare)"; + width = 8; + height = 4096; + values + { + 18084 + { + title = "(Mare 5) Axis"; + circle = 1; + } + 18085 + { + title = "(Mare 5) Axis Transfer"; + } + 18086 + { + title = "(Mare 5) Axis Transfer Line"; + } + 18094 + { + title = "(Mare 5) Egg Capsule"; + sprite = "CAPSA0"; + width = 72; + height = 144; + } + } + } + + nightstrk5 + { + color = 12517599; // Violet (BF00DF) + title = "Nights Track (6th Mare)"; + width = 8; + height = 4096; + values + { + 22180 + { + title = "(Mare 6) Axis"; + circle = 1; + } + 22181 + { + title = "(Mare 6) Axis Transfer"; + } + 22182 + { + title = "(Mare 6) Axis Transfer Line"; + } + 22190 + { + title = "(Mare 6) Egg Capsule"; + sprite = "CAPSA0"; + width = 72; + height = 144; + } + } + } + + nightstrk6 + { + color = 12517599; // Violet (BF00DF) + title = "Nights Track (7th Mare)"; + width = 8; + height = 4096; + values + { + 26276 + { + title = "(Mare 7) Axis"; + circle = 1; + } + 26277 + { + title = "(Mare 7) Axis Transfer"; + } + 26278 + { + title = "(Mare 7) Axis Transfer Line"; + } + 26286 + { + title = "(Mare 7) Egg Capsule"; + sprite = "CAPSA0"; + width = 72; + height = 144; + } + } + } + + nightstrk7 + { + color = 12517599; // Violet (BF00DF) + title = "Nights Track (8th Mare)"; + width = 8; + height = 4096; + values + { + 30372 + { + title = "(Mare 8) Axis"; + circle = 1; + } + 30373 + { + title = "(Mare 8) Axis Transfer"; + } + 30374 + { + title = "(Mare 8) Axis Transfer Line"; + } + 30382 + { + title = "(Mare 8) Egg Capsule"; + sprite = "CAPSA0"; + width = 72; + height = 144; + } + } + } + + + mario + { + color = 14647040; // Orange (DF7F00) + title = "Mario Items"; + width = 16; + height = 32; + values + { + 1800 + { + title = "Coin"; + sprite = "COINA0"; + height = 24; + deafheight = 32; + deaftext = "[3] Float"; + } + 1801 + { + arrow = 1; + title = "Goomba"; + sprite = "GOOMA0"; + width = 24; + } + 1802 + { + arrow = 1; + title = "Goomba (Blue)"; + sprite = "BGOMA0"; + width = 24; + } + 1803 + { + title = "Fire Flower"; + sprite = "FFWRB0"; + } + 1804 + { + title = "Koopa Shell"; + sprite = "SHLLA0"; + width = 8; + height = 16; + } + 1805 + { + title = "Puma (Jumping Fireball)"; + sprite = "PUMAA0"; + width = 8; + height = 16; + } + 1806 + { + title = "King Bowser"; + sprite = "KOOPA0"; + height = 48; + } + 1807 + { + title = "Axe"; + sprite = "MAXEA0"; + width = 8; + height = 16; + } + 1808 + { + title = "Bush (Short)"; + sprite = "MUS1A0"; + } + 1809 + { + title = "Bush (Tall)"; + sprite = "MUS2A0"; + } + 1810 + { + title = "Toad"; + sprite = "TOADA0"; + width = 8; + } + } + } + + srb1 + { + color = 32607; // Teal (007F5F) + arrow = 1; + title = "SRB1 Remake Items"; + width = 20; + height = 32; + values + { + 4000 + { + title = "SRB1 Crawla"; + sprite = "SRBAA1"; + height = 40; + } + 4001 + { + title = "GuardRobo"; + sprite = "SRBBA1"; + width = 17; + height = 40; + } + 4002 + { + title = "Pyrin"; + sprite = "SRBCB1"; + width = 22; + } + 4003 + { + title = "HotRobo"; + sprite = "SRBDA0"; + height = 40; + } + 4004 + { + title = "Pogminz"; + sprite = "SRBEA1"; + } + 4005 + { + title = "Pogminz (Water)"; + sprite = "SRBEA1"; + } + 4006 + { + title = "Pog-GX2"; + sprite = "SRBFA0"; + width = 10; + height = 34; + } + 4007 + { + title = "Pyrex"; + sprite = "SRBGA1"; + width = 24; + } + 4008 + { + title = "UFO"; + sprite = "SRBHA0"; + width = 24; + hangs = 1; + } + 4009 + { + title = "SWAT Bot"; + sprite = "SRBIA1"; + width = 21; + height = 69; + } + 4010 + { + title = "SpyBot 2000"; + sprite = "SRBJA0"; + width = 36; + height = 62; + } + 4011 + { + title = "Buzz Bomber"; + sprite = "SRBKA0"; + width = 44; + height = 45; + } + 4012 + { + arrow = 0; + title = "RBZ Spike"; + sprite = "SRBLA0"; + width = 10; + height = 53; + } + 4013 + { + arrow = 0; + blocking = 2; + title = "Dumb Metal Sonic"; + sprite = "SRBMC0"; + width = 16; + height = 40; + spectext = "[2] Slides When Pushed"; + deaftext = "[3] Not Pushable"; + } + 4014 + { + title = "Super SWAT Bot"; + sprite = "SRBNA1"; + width = 21; + height = 69; + } + 4015 + { + title = "Genrex"; + sprite = "SRBOA1"; + width = 17; + height = 40; + } + } + } + + bsz + { + color = 10469120; // Light Lime (9FDF00) + title = "Botanic Serenity Items"; + width = 16; + height = 32; + values + { + 1400 + { + title = "Tall Flower (Red)"; + sprite = "BSZ1A0"; + } + 1401 + { + title = "Tall Flower (Purple)"; + sprite = "BSZ1B0"; + } + 1402 + { + title = "Tall Flower (Blue)"; + sprite = "BSZ1C0"; + } + 1403 + { + title = "Tall Flower (Cyan)"; + sprite = "BSZ1D0"; + } + 1404 + { + title = "Tall Flower (Yellow)"; + sprite = "BSZ1E0"; + } + 1405 + { + title = "Tall Flower (Orange)"; + sprite = "BSZ1F0"; + } + 1410 + { + title = "Medium Flower (Red)"; + sprite = "BSZ2A0"; + } + 1411 + { + title = "Medium Flower (Purple)"; + sprite = "BSZ2B0"; + } + 1412 + { + title = "Medium Flower (Blue)"; + sprite = "BSZ2C0"; + } + 1413 + { + title = "Medium Flower (Cyan)"; + sprite = "BSZ2D0"; + } + 1414 + { + title = "Medium Flower (Yellow)"; + sprite = "BSZ2E0"; + } + 1415 + { + title = "Medium Flower (Orange)"; + sprite = "BSZ2F0"; + } + 1420 + { + title = "Short Flower (Red)"; + sprite = "BSZ3A0"; + } + 1421 + { + title = "Short Flower (Purple)"; + sprite = "BSZ3B0"; + } + 1422 + { + title = "Short Flower (Blue)"; + sprite = "BSZ3C0"; + } + 1423 + { + title = "Short Flower (Cyan)"; + sprite = "BSZ3D0"; + } + 1424 + { + title = "Short Flower (Yellow)"; + sprite = "BSZ3E0"; + } + 1425 + { + title = "Short Flower (Orange)"; + sprite = "BSZ3F0"; + } + 1430 + { + title = "Tulip (Red)"; + sprite = "BSZ4A0"; + } + 1431 + { + title = "Tulip (Purple)"; + sprite = "BSZ4B0"; + } + 1432 + { + title = "Tulip (Blue)"; + sprite = "BSZ4C0"; + } + 1433 + { + title = "Tulip (Cyan)"; + sprite = "BSZ4D0"; + } + 1434 + { + title = "Tulip (Yellow)"; + sprite = "BSZ4E0"; + } + 1435 + { + title = "Tulip (Orange)"; + sprite = "BSZ4F0"; + } + 1440 + { + title = "Cluster (Red)"; + sprite = "BSZ5A0"; + } + 1441 + { + title = "Cluster (Purple)"; + sprite = "BSZ5B0"; + } + 1442 + { + title = "Cluster (Blue)"; + sprite = "BSZ5C0"; + } + 1443 + { + title = "Cluster (Cyan)"; + sprite = "BSZ5D0"; + } + 1444 + { + title = "Cluster (Yellow)"; + sprite = "BSZ5E0"; + } + 1445 + { + title = "Cluster (Orange)"; + sprite = "BSZ5F0"; + } + 1450 + { + title = "Bush (Red)"; + sprite = "BSZ6A0"; + } + 1451 + { + title = "Bush (Purple)"; + sprite = "BSZ6B0"; + } + 1452 + { + title = "Bush (Blue)"; + sprite = "BSZ6C0"; + } + 1453 + { + title = "Bush (Cyan)"; + sprite = "BSZ6D0"; + } + 1454 + { + title = "Bush (Yellow)"; + sprite = "BSZ6E0"; + } + 1455 + { + title = "Bush (Orange)"; + sprite = "BSZ6F0"; + } + 1460 + { + title = "Vine (Red)"; + sprite = "BSZ7A0"; + } + 1461 + { + title = "Vine (Purple)"; + sprite = "BSZ7B0"; + } + 1462 + { + title = "Vine (Blue)"; + sprite = "BSZ7C0"; + } + 1463 + { + title = "Vine (Cyan)"; + sprite = "BSZ7D0"; + } + 1464 + { + title = "Vine (Yellow)"; + sprite = "BSZ7E0"; + } + 1465 + { + title = "Vine (Orange)"; + sprite = "BSZ7F0"; + } + 1470 + { + title = "BSZ Shrub"; + sprite = "BSZ8A0"; + } + 1471 + { + title = "BSZ Clover"; + sprite = "BSZ8B0"; + } + 1472 + { + title = "BSZ Fish"; + sprite = "BSZ8C0"; + } + 1473 + { + title = "BSZ Sunflower"; + sprite = "BSZ8D0"; + } + } + } +} diff --git a/extras/conf/srb2-21db2.cfg b/extras/conf/srb2-21db2.cfg new file mode 100644 index 000000000..075cbbf28 --- /dev/null +++ b/extras/conf/srb2-21db2.cfg @@ -0,0 +1,4881 @@ +/*********************************************************\ + SRB2Doom Builder 2 Game Configuration + For Sonic Robo Blast 2 Version 2.1 + Contributors (alphabetical): + * Foxboy + * JJames19119 + * Kalaron + * Kristos + * Morpheus + * Neo Chaotikal + * Oogaland + * Rob + * Shadow Hog + * ST218 + * SRB2-Playah + * SSNTails + * Viola +\*********************************************************/ + +// This is required to prevent accedential use of a different configuration +type = "Doom Builder 2 Game Configuration"; + +// This is the title to show for this game +game = "Sonic Robo Blast 2 2.1"; + +// This is the simplified game engine/sourceport name +engine = "eternity"; + +// The format interface handles the map data format +formatinterface = "DoomMapSetIO"; + +// Default lump name for new map +defaultlumpname = "MAP01"; + +// Default testing parameters +testparameters = "-iwad \"%WP\" -file \"%AP\" \"%F\" -warp %L"; +testshortpaths = true; + +// Default nodebuilder configurations +defaultsavecompiler = "zennode_normal"; +defaulttestcompiler = "zennode_fast"; + +// Skill levels +skills +{ + 1 = "Normal"; +} + +// When this is set to true, sectors with the same tag will light up when a line is highlighted +linetagindicatesectors = true; + +// Special linedefs +soundlinedefflag = 64; // See linedefflags +singlesidedflag = 1; // See linedefflags +doublesidedflag = 4; // See linedefflags +impassableflag = 1; +upperunpeggedflag = 8; +lowerunpeggedflag = 16; + +// Door making +makedoortrack = "DOORTRAK"; +makedooraction = 1; // See linedeftypes + +// Generalized actions +generalizedlinedefs = false; +generalizedsectors = true; + +// Texture loading options // Kalaron: Mix the resources! +mixtexturesflats = false; +defaulttexturescale = 1.0f; +defaultflatscale = 1.0f; + +// Thing number for start position in 3D Mode +start3dmode = 32000; + +// Default flags for first new thing +// Doom Builder is picky for some reason +// and will give a small warning of 'unknown flags' +// not an issue at all though, just strange +defaultthingflags +{ + 0; +} + + +/* +TEXTURES AND FLAT SOURCES +This tells Doom Builder where to find the information for textures +and flats in the IWAD file, Addition WAD file and Map WAD file. + +Start and end lumps must be given in a structure (of which the +key name doesnt matter) and any textures or flats in between them +are loaded in either the textures category or flats category. + +For textures: PNAMES, TEXTURE1 and TEXTURE2 are loaded by default. +Kalaron: and now TX_START +*/ + +// Texture sources +textures +{ + zdoom1 + { + start = "TX_START"; + end = "TX_END"; + } +} + +// Patch sources +patches +{ + standard1 + { + start = "P_START"; + end = "P_END"; + } + + standard2 + { + start = "PP_START"; + end = "PP_END"; + } +} + +// Sprite sources +sprites +{ + standard1 + { + start = "S_START"; + end = "S_END"; + } + + standard2 + { + start = "SS_START"; + end = "SS_END"; + } +} + +// Flat sources +flats +{ + standard1 + { + start = "F_START"; + end = "F_END"; + } + + standard2 + { + start = "FF_START"; + end = "FF_END"; + } + + standard3 + { + start = "FF_START"; + end = "F_END"; + } + + standard4 + { + start = "F_START"; + end = "FF_END"; + } +} + + +/* +GAME DETECT PATTERN +Used to guess the game for which a WAD file is made. + +1 = One of these lumps must exist +2 = None of these lumps must exist +3 = All of these lumps must exist +*/ + +gamedetect +{ + EXTENDED = 2; + + + BEHAVIOR = 2; + + E#M# = 2; + + MAP?? = 1; +} + + +/* +MAP LUMP NAMES +Map lumps are loaded with the map as long as they are right after each other. When the editor +meets a lump which is not defined in this list it will ignore the map if not satisfied. +The order of items defines the order in which lumps will be written to WAD file on save. +To indicate the map header lump, use ~MAP + +Legenda: +required = Lump is required to exist. +blindcopy = Lump will be copied along with the map blindly. (usefull for lumps Doom Builder doesn't use) +nodebuild = The nodebuilder generates this lump. +allowempty = The nodebuilder is allowed to leave this lump empty. +script = This lump is a text-based script. Specify the filename of the script configuration to use. +*/ + +maplumpnames +{ + ~MAP + { + required = true; + blindcopy = true; + nodebuild = false; + } + + THINGS + { + required = true; + nodebuild = true; + allowempty = true; + } + + LINEDEFS + { + required = true; + nodebuild = true; + allowempty = false; + } + + SIDEDEFS + { + required = true; + nodebuild = true; + allowempty = false; + } + + VERTEXES + { + required = true; + nodebuild = true; + allowempty = false; + } + + SEGS + { + required = false; + nodebuild = true; + allowempty = false; + } + + SSECTORS + { + required = false; + nodebuild = true; + allowempty = false; + } + + NODES + { + required = false; + nodebuild = true; + allowempty = false; + } + + SECTORS + { + required = true; + nodebuild = true; + allowempty = false; + } + + REJECT + { + required = false; + nodebuild = true; + allowempty = false; + } + + BLOCKMAP + { + required = false; + nodebuild = true; + allowempty = false; + } +} + + +// DEFAULT SECTOR BRIGHTNESS LEVELS +sectorbrightness +{ + 255; + 248; + 240; + 232; + 224; + 216; + 208; + 200; + 192; + 184; + 176; + 168; + 160; + 152; + 144; + 136; + 128; + 120; + 112; + 104; + 96; + 88; + 80; + 72; + 64; + 56; + 48; + 40; + 32; + 24; + 16; + 8; + 0; +} + +// SECTOR TYPES----------------------------------------------------------------- +sectortypes +{ + 0 = "Normal"; + 1 = "Damage"; + 2 = "Damage (Water)"; + 3 = "Damage (Fire)"; + 4 = "Damage (Electrical)"; + 5 = "Spikes"; + 6 = "Death Pit (Camera Modifications)"; + 7 = "Death Pit (No Camera Modifications)"; + 8 = "Instant Kill"; + 9 = "Ring Drainer (Floor Touch)"; + 10 = "Ring Drainer (No Floor Touch)"; + 11 = "Special Stage Damage"; + 12 = "Space Countdown"; + 13 = "Ramp Sector (double step-up/down)"; + 14 = "Non-Ramp Sector (no step-down)"; + 15 = "Bouncy Sector (FOF Control Only)"; + 16 = "Trigger Line Ex. (Pushable Objects)"; + 32 = "Trigger Line Ex. (Anywhere, All Players)"; + 48 = "Trigger Line Ex. (Floor Touch, All Players)"; + 64 = "Trigger Line Ex. (Anywhere in Sector)"; + 80 = "Trigger Line Ex. (Floor Touch)"; + 96 = "Trigger Line Ex. (Emerald Check)"; + 112 = "Trigger Line Ex. (Nights Mare)"; + 128 = " Check for Line Exec. on FOFs"; + 144 = "Egg Trap Capsule"; + 160 = "Special Stage Time/Rings Parameters"; + 176 = "Custom Global Gravity"; + 256 = "Ice/Sludge"; + 512 = "Wind/Current"; + 768 = "Ice/Sludge and Wind/Current"; + 1024 = "Conveyor Belt"; + 1280 = "Speed Pad (No Spin)"; + 1536 = "Speed Pad (Spin)"; + 1792 = "Bustable Block Sprite Parameter (ROIA)"; + 2048 = "Bustable Block Sprite Parameter (ROIB)"; + 2304 = "Bustable Block Sprite Parameter (ROIC)"; + 2560 = "Bustable Block Sprite Parameter (ROID)"; + 2816 = "Bustable Block Sprite Parameter (ROIE)"; + 3072 = "Bustable Block Sprite Parameter (ROIF)"; + 3328 = "Bustable Block Sprite Parameter (ROIG)"; + 3884 = "Bustable Block Sprite Parameter (ROIH)"; + 3840 = "Bustable Block Sprite Parameter (ROII)"; + 4096 = "Star Post Activator"; + 8192 = "Exit/Special Stage Goal/Return Flag"; + 12288 = "CTF: Red Team Base"; + 16384 = "CTF: Blue Team Base"; + 20480 = "Fan Sector"; + 24576 = "Super Sonic Transform"; + 28672 = "Spinner"; + 32768 = "Zoom Tube Start"; + 36864 = "Zoom Tube End"; + 40960 = "Finish Line"; + 45056 = "Rope Hang"; + 49152 = "Intangible to the Camera"; +} + + +// GENERALISED SECTOR TYPES----------------------------------------------------------------- +gen_sectortypes +{ + first + { + 0 = "Normal"; + 1 = "Damage"; + 2 = "Damage (Water)"; + 3 = "Damage (Fire)"; + 4 = "Damage (Electrical)"; + 5 = "Spikes"; + 6 = "Death Pit (Camera Modifications)"; + 7 = "Death Pit (No Camera Modifications)"; + 8 = "Instant Kill"; + 9 = "Ring Drainer (Floor Touch)"; + 10 = "Ring Drainer (No Floor Touch)"; + 11 = "Special Stage Damage"; + 12 = "Space Countdown"; + 13 = "Ramp Sector (double step-up/down)"; + 14 = "Non-Ramp Sector (no step-down)"; + 15 = "Bouncy Sector (FOF Control Only)"; + } + + second + { + 0 = "Normal"; + 16 = "Trigger Line Ex. (Pushable Objects)"; + 32 = "Trigger Line Ex. (Anywhere, All Players)"; + 48 = "Trigger Line Ex. (Floor Touch, All Players)"; + 64 = "Trigger Line Ex. (Anywhere in Sector)"; + 80 = "Trigger Line Ex. (Floor Touch)"; + 96 = "Trigger Line Ex. (Emerald Check)"; + 112 = "Trigger Line Ex. (Nights Mare)"; + 128 = " Check for Line Exec. on FOFs"; + 144 = "Egg Trap Capsule"; + 160 = "Special Stage Time/Rings Parameters"; + 176 = "Custom Global Gravity"; + } + + third + { + 0 = "Normal"; + 256 = "Ice/Sludge"; + 512 = "Wind/Current"; + 768 = "Ice/Sludge and Wind/Current"; + 1024 = "Conveyor Belt"; + 1280 = "Speed Pad (No Spin)"; + 1536 = "Speed Pad (Spin)"; + 1792 = "Bustable Block Sprite Parameter (ROIA)"; + 2048 = "Bustable Block Sprite Parameter (ROIB)"; + 2304 = "Bustable Block Sprite Parameter (ROIC)"; + 2560 = "Bustable Block Sprite Parameter (ROID)"; + 2816 = "Bustable Block Sprite Parameter (ROIE)"; + 3072 = "Bustable Block Sprite Parameter (ROIF)"; + 3328 = "Bustable Block Sprite Parameter (ROIG)"; + 3884 = "Bustable Block Sprite Parameter (ROIH)"; + 3840 = "Bustable Block Sprite Parameter (ROII)"; + } + + fourth + { + 0 = "Normal"; + 4096 = "Star Post Activator"; + 8192 = "Exit/Special Stage Goal/Return Flag"; + 12288 = "CTF: Red Team Base"; + 16384 = "CTF: Blue Team Base"; + 20480 = "Fan Sector"; + 24576 = "Super Sonic Transform"; + 28672 = "Spinner"; + 32768 = "Zoom Tube Start"; + 36864 = "Zoom Tube End"; + 40960 = "Finish Line"; + 45056 = "Rope Hang"; + 49152 = "Intangible to the Camera"; + } +} + +// LINEDEF FLAGS +linedefflags +{ + 1 = "[0] Effect 6"; + 2 = "[1] Block Enemies"; + 4 = "[2] Double-Sided"; + 8 = "[3] Upper Unpegged"; + 16 = "[4] Lower Unpegged"; + 32 = "[5] Effect 1"; + 64 = "[6] Not Climbable"; + 128 = "[7] Effect 2"; + 256 = "[8] Effect 3"; + 512 = "[9] Effect 4"; + 1024 = "[10] Effect 5"; + 2048 = "[11] No Sonic"; + 4096 = "[12] No Tails"; + 8192 = "[13] No Knuckles"; + 16384 = "[14] Bouncy Wall"; + 32768 = "[15] Transfer Line"; +} + +// Linedef flags UDMF translation table +// This is needed for copy/paste and prefabs to work properly +// When the UDMF field name is prefixed with ! it is inverted +linedefflagstranslation +{ + 1 = "blocking"; + 2 = "blockmonsters"; + 4 = "twosided"; + 8 = "dontpegtop"; + 16 = "dontpegbottom"; + 32 = "secret"; + 64 = "blocksound"; + 128 = "dontdraw"; + 256 = "mapped"; +} + +// LINEDEF ACTIVATIONS +linedefactivations +{ +} + +// LINEDEF TYPES +linedeftypes +{ + misc + { + title = "Miscellaneous"; + + 0 + { + title = "None"; + prefix = "(0)"; + } + + 1 + { + title = "Per-Sector Gravity"; + prefix = "(1)"; + } + + 4 + { + title = "Speed Pad"; + prefix = "(4)"; + } + + 5 + { + title = "Camera Scanner"; + prefix = "(5)"; + } + + 6 + { + title = "Disable Linedef Effect On Level Load"; + prefix = "(6)"; + } + + 7 + { + title = "Sector Flat Alignment"; + prefix = "(7)"; + } + + 10 + { + title = "Culling Plane"; + prefix = "(10)"; + } + + 13 + { + title = "Heat Wave Effect"; + prefix = "(13)"; + } + + 50 + { + title = "Instantly Lower Floor On Level Load"; + prefix = "(50)"; + } + + 51 + { + title = "Instantly Raise Ceiling On Level Load"; + prefix = "(51)"; + } + + 63 + { + title = "Fake Floor/Ceiling Planes"; + prefix = "(63)"; + } + + 540 + { + title = "Floor Friction"; + prefix = "(540)"; + } + } + + parameters + { + title = "Parameters"; + + 2 + { + title = "Custom Exit"; + prefix = "(2)"; + } + + 3 + { + title = "Zoom Tube Parameters"; + prefix = "(3)"; + } + + 8 + { + title = "Sector Special Parameters"; + prefix = "(8)"; + } + + 9 + { + title = "Chain Parameters"; + prefix = "(9)"; + } + + 11 + { + title = "Rope Hang Parameters"; + prefix = "(12)"; + } + + 12 + { + title = "Rock Spawn Parameters"; + prefix = "(12)"; + } + + 64 + { + title = "Appearing/Disappearing FOF"; + prefix = "(64)"; + } + + 65 + { + title = "Bridge Thinker "; + prefix = "(65)"; + } + } + + polyobject + { + title = "PolyObject"; + + 20 + { + title = "First Line"; + prefix = "(20)"; + } + + 21 + { + title = "Explicitly Include Line"; + prefix = "(21)"; + } + + 22 + { + title = "Parameters"; + prefix = "(22)"; + } + + 30 + { + title = "Waving Flag"; + prefix = "(30)"; + } + } + + planemove + { + title = "Plane Movement"; + + 52 + { + title = "Continuous Falling Sector"; + prefix = "(52)"; + } + + 53 + { + title = "Continuous Floor/Ceiling Mover"; + prefix = "(53)"; + } + + 54 + { + title = "Continuous Floor Mover"; + prefix = "(54)"; + } + + 55 + { + title = "Continuous Ceiling Mover"; + prefix = "(55)"; + } + + 56 + { + title = "Continuous Two-Speed Floor/Ceiling Mover"; + prefix = "(56)"; + } + + 57 + { + title = "Continuous Two-Speed Floor Mover"; + prefix = "(57)"; + } + + 58 + { + title = "Continuous Two-Speed Ceiling Mover"; + prefix = "(58)"; + } + + 59 + { + title = "Activate Moving Platform"; + prefix = "(59)"; + } + + 60 + { + title = "Activate Moving Platform (Adjustable Speed)"; + prefix = "(60)"; + } + + 61 + { + title = "Crusher (Ceiling to Floor)"; + prefix = "(61)"; + } + + 62 + { + title = "Crusher (Floor to Ceiling)"; + prefix = "(62)"; + } + } + + fofsolid + { + title = "FOF (solid)"; + + 100 + { + title = "Solid, Opaque"; + prefix = "(100)"; + } + + 101 + { + title = "Solid, Opaque, No Shadow"; + prefix = "(101)"; + } + + 102 + { + title = "Solid, Translucent"; + prefix = "(102)"; + } + + 103 + { + title = "Solid, Sides Only"; + prefix = "(103)"; + } + + 104 + { + title = "Solid, No Sides"; + prefix = "(104)"; + } + + 105 + { + title = "Solid, Invisible"; + prefix = "(105)"; + } + + 140 + { + title = "Intangible from Bottom, Opaque"; + prefix = "(140)"; + } + + 141 + { + title = "Intangible from Bottom, Translucent"; + prefix = "(141)"; + } + + 142 + { + title = "Intangible from Bottom, Translucent, No Sides"; + prefix = "(142)"; + } + + 143 + { + title = "Intangible from Top, Opaque"; + prefix = "(143)"; + } + + 144 + { + title = "Intangible from Top, Translucent"; + prefix = "(144)"; + } + + 145 + { + title = "Intangible from Top, Translucent, No Sides"; + prefix = "(145)"; + } + + 146 + { + title = "Only Tangible from Sides"; + prefix = "(146)"; + } + } + + fofintangible + { + title = "FOF (intangible)"; + + 120 + { + title = "Water, Opaque"; + prefix = "(120)"; + } + + 121 + { + title = "Water, Translucent"; + prefix = "(121)"; + } + + 122 + { + title = "Water, Opaque, No Sides"; + prefix = "(122)"; + } + + 123 + { + title = "Water, Translucent, No Sides"; + prefix = "(123)"; + } + + 124 + { + title = "Goo Water, Translucent"; + prefix = "(124)"; + } + + 125 + { + title = "Goo Water, Translucent, No Sides"; + prefix = "(125)"; + } + + 220 + { + title = "Intangible, Opaque"; + prefix = "(220)"; + } + + 221 + { + title = "Intangible, Translucent"; + prefix = "(221)"; + } + + 222 + { + title = "Intangible, Sides Only"; + prefix = "(222)"; + } + + 223 + { + title = "Intangible, Invisible"; + prefix = "(223)"; + } + } + + fofbobbing + { + title = "FOF (bobbing)"; + + 150 + { + title = " Air Bobbing"; + prefix = "(150)"; + } + + 151 + { + title = " Air Bobbing (Adjustable)"; + prefix = "(151)"; + } + + 152 + { + title = " Reverse Air Bobbing (Adjustable)"; + prefix = "(152)"; + } + + 160 + { + title = "Floating, Bobbing"; + prefix = "(160)"; + } + + 190 + { + title = "Rising Platform, Solid, Opaque"; + prefix = "(190)"; + } + + 191 + { + title = "Rising Platform, Solid, Opaque, No Shadow"; + prefix = "(191)"; + } + + 192 + { + title = "Rising Platform, Solid, Translucent"; + prefix = "(192)"; + } + + 193 + { + title = "Rising PLatform, Solid, Invisible"; + prefix = "(193)"; + } + + 194 + { + title = "Rising Platform, Intangible from Bottom, Opaque"; + prefix = "(194)"; + } + + 195 + { + title = "Rising Platform, Intangible from Bottom, Translucent"; + prefix = "(195)"; + } + } + + fofcrumbling + { + title = "FOF (crumbling)"; + + 170 + { + title = "Crumbling (Respawn)"; + prefix = "(170)"; + } + + 171 + { + title = "Crumbling (No Respawn)"; + prefix = "(171)"; + } + + 172 + { + title = "Crumbling (Respawn), Intangible from Bottom"; + prefix = "(172)"; + } + + 173 + { + title = "Crumbling (No Respawn), Intangible from Bottom"; + prefix = "(173)"; + } + + 174 + { + title = "Crumbling (Respawn), Int. from Bottom, Translucent"; + prefix = "(174)"; + } + + 175 + { + title = "Crumbling (No Respawn), Int. from Bottom, Translucent"; + prefix = "(175)"; + } + + 176 + { + title = "Crumbling (Respawn), Floating, Bobbing"; + prefix = "(176)"; + } + + 177 + { + title = "Crumbling (No Respawn), Floating, Bobbing"; + prefix = "(177)"; + } + + 178 + { + title = "Crumbling (Respawn), Floating"; + prefix = "(178)"; + } + + 179 + { + title = "Crumbling (No Respawn), Floating"; + prefix = "(179)"; + } + + 180 + { + title = "Crumbling (Respawn), Air Bobbing"; + prefix = "(180)"; + } + } + + fofspecial + { + title = "FOF (special)"; + + 200 + { + title = "Light Block"; + prefix = "(200)"; + } + + 201 + { + title = "Half Light Block"; + prefix = "(201)"; + } + + 202 + { + title = "Fog Block"; + prefix = "(202)"; + } + + 250 + { + title = "Mario Block"; + prefix = "(250)"; + } + + 251 + { + title = "Thwomp Block"; + prefix = "(251)"; + } + + 252 + { + title = "Shatter Block"; + prefix = "(252)"; + } + + 253 + { + title = "Shatter Block, Translucent"; + prefix = "(253)"; + } + + 254 + { + title = "Bustable Block"; + prefix = "(254)"; + } + + 255 + { + title = "Spin Bust Block"; + prefix = "(255)"; + } + + 256 + { + title = "Spin Bust Block, Translucent"; + prefix = "(256)"; + } + + 257 + { + title = "Quicksand"; + prefix = "(257)"; + } + + 258 + { + title = "Laser"; + prefix = "(258)"; + } + + 259 + { + title = "Custom FOF"; + prefix = "(259)"; + } + } + + linedeftrigger + { + title = "Lindef Executor Trigger"; + + 300 + { + title = "Continuous"; + prefix = "(300)"; + } + + 301 + { + title = "Each Time"; + prefix = "(301)"; + } + + 302 + { + title = "Once"; + prefix = "(302)"; + } + + 303 + { + title = "Ring Count - Continuous"; + prefix = "(303)"; + } + + 304 + { + title = "Ring Count - Once"; + prefix = "(304)"; + } + + 305 + { + title = "Character Ability - Once"; + prefix = "(305)"; + } + + 306 + { + title = "Character Ability - Each Time"; + prefix = "(306)"; + } + + 307 + { + title = "Character Ability - Continuous"; + prefix = "(307)"; + } + + 308 + { + title = "Race Only - Once"; + prefix = "(308)"; + } + + 309 + { + title = "CTF Red Team - Continuous"; + prefix = "(309)"; + } + + 310 + { + title = "CTF Red Team - Each Time"; + prefix = "(310)"; + } + + 311 + { + title = "CTF Blue Team - Continuous"; + prefix = "(311)"; + } + + 312 + { + title = "CTF Blue Team - Each Time"; + prefix = "(312)"; + } + + 313 + { + title = "No More Enemies - Once"; + prefix = "(313)"; + } + + 314 + { + title = "Number of Pushables - Continuous"; + prefix = "(314)"; + } + + 315 + { + title = "Number of Pushables - Once"; + prefix = "(315)"; + } + + 316 + { + title = "Land On PolyObject"; + prefix = "(316)"; + } + + 317 + { + title = "Unlockable Trigger - Continuous"; + prefix = "(317)"; + } + + 318 + { + title = "Unlockable Trigger - Once"; + prefix = "(316)"; + } + + 399 + { + title = "Level Load"; + prefix = "(399)"; + } + } + + linedefexecsector + { + title = "Linedef Executor (sector)"; + + 400 + { + title = "Set Tagged Sector's Floor Height/Texture"; + prefix = "(400)"; + } + + 401 + { + title = "Set Tagged Sector's Ceiling Height/Texture"; + prefix = "(401)"; + } + + 402 + { + title = "Set Tagged Sector's Light Level"; + prefix = "(402)"; + } + + 409 + { + title = "Change Tagged Sector's Tag"; + prefix = "(409)"; + } + + 410 + { + title = "Change Front Sector's Tag"; + prefix = "(410)"; + } + + 416 + { + title = "Start Adjustable Fire Flicker"; + prefix = "(416)"; + } + + 417 + { + title = "Start Adjustable Glowing Light"; + prefix = "(417)"; + } + + 418 + { + title = "Start Adjustable Blinking Light (unsynchronized)"; + prefix = "(418)"; + } + + 419 + { + title = "Start Adjustable Blinking Light (synchronized)"; + prefix = "(419)"; + } + + 420 + { + title = "Fade Light Level"; + prefix = "(420)"; + } + + 421 + { + title = "Stop Lighting Effect"; + prefix = "(421)"; + } + + 435 + { + title = "Change Plane Scroller Direction"; + prefix = "(435)"; + } + } + + linedefexecplane + { + title = "Linedef Executor (plane movement)"; + + 403 + { + title = "Move Tagged Sector's Floor"; + prefix = "(403)"; + } + + 404 + { + title = "Move Tagged Sector's Ceiling"; + prefix = "(404)"; + } + + 405 + { + title = "Move Floor According to Front Texture Offsets"; + prefix = "(405)"; + } + + 407 + { + title = "Move Ceiling According to Front Texture Offsets"; + prefix = "(407)"; + } + + 411 + { + title = "Stop Plane Movement"; + prefix = "(411)"; + } + + 428 + { + title = "Start Platform Movement"; + prefix = "(428)"; + } + + 429 + { + title = "Crush Ceiling Once"; + prefix = "(429)"; + } + + 430 + { + title = "Crush Floor Once"; + prefix = "(430)"; + } + + 431 + { + title = "Crush Floor and Ceiling Once"; + prefix = "(431)"; + } + } + + linedefexecplayer + { + title = "Linedef Executor (player/object)"; + + 412 + { + title = "Teleporter"; + prefix = "(412)"; + } + + 425 + { + title = "Change Object State"; + prefix = "(425)"; + } + + 426 + { + title = "Stop Object"; + prefix = "(426)"; + } + + 427 + { + title = "Award Score"; + prefix = "(427)"; + } + + 432 + { + title = "Enable/Disable 2D Mode"; + prefix = "(432)"; + } + + 433 + { + title = "Enable/Disable Gravity Flip"; + prefix = "(433)"; + } + + 434 + { + title = "Award Power-Up"; + prefix = "(434)"; + } + + 437 + { + title = "Disable Player Control"; + prefix = "(437)"; + } + + 438 + { + title = "Change Object Size"; + prefix = "(438)"; + } + + 442 + { + title = "Change Object Type State"; + prefix = "(442)"; + } + } + + linedefexecmisc + { + title = "Linedef Executor (misc.)"; + + 413 + { + title = "Change Music"; + prefix = "(413)"; + } + + 414 + { + title = "Play Sound Effect"; + prefix = "(414)"; + } + + 415 + { + title = "Run Script"; + prefix = "(415)"; + } + + 422 + { + title = "Switch to Cut-Away View"; + prefix = "(422)"; + } + + 423 + { + title = "Change Sky"; + prefix = "(423)"; + } + + 424 + { + title = "Change Weather"; + prefix = "(424)"; + } + + 436 + { + title = "Shatter FOF"; + prefix = "(436)"; + } + + 439 + { + title = "Set Texture"; + prefix = "(439)"; + } + + 440 + { + title = "Start Metal Sonic Race"; + prefix = "(440)"; + } + + 441 + { + title = "Unlockable Trigger"; + prefix = "(441)"; + } + + 443 + { + title = "Call Lua Function"; + prefix = "(443)"; + } + + 444 + { + title = "Earthquake"; + prefix = "(444)"; + } + + + 445 + { + title = "Force Block Disappear"; + prefix = "(445)"; + } + + 450 + { + title = "Execute Linedef Executor (from tag)"; + prefix = "(450)"; + } + + 451 + { + title = "Execute Linedef Executor (random range)"; + prefix = "(451)"; + } + } + + linedefexecpoly + { + title = "Linedef Executor (polyobject)"; + + 480 + { + title = "Door Slide"; + prefix = "(480)"; + } + + 481 + { + title = "Door Swing"; + prefix = "(481)"; + } + + 482 + { + title = "Move"; + prefix = "(482)"; + } + + 483 + { + title = "Move, Override"; + prefix = "(483)"; + } + + 484 + { + title = "Rotate Right"; + prefix = "(484)"; + } + + 485 + { + title = "Rotate Right, Override"; + prefix = "(485)"; + } + + 486 + { + title = "Rotate Left"; + prefix = "(486)"; + } + + 487 + { + title = "Rotate Left, Override"; + prefix = "(487)"; + } + + 488 + { + title = "Move by Waypoints"; + prefix = "(488)"; + } + + 489 + { + title = "Turn Inisible, Intangible"; + prefix = "(489)"; + } + + 490 + { + title = "Turn Visible, Tangible"; + prefix = "(490)"; + } + + 491 + { + title = "Set Translucency"; + prefix = "(491)"; + } + } + + wallscroll + { + title = "Wall Scrolling"; + + 500 + { + title = "Scroll Wall Front Side Left"; + prefix = "(500)"; + } + + 501 + { + title = "Scroll Wall Front Side Right"; + prefix = "(501)"; + } + + 502 + { + title = "Scroll Wall According to Linedef"; + prefix = "(502)"; + } + + 503 + { + title = "Scroll Wall According to Linedef (Accelerative)"; + prefix = "(503)"; + } + + 504 + { + title = "Scroll Wall According to Linedef (Displacement)"; + prefix = "(504)"; + } + + 505 + { + title = "Scroll Texture by Front Side Offsets"; + prefix = "(505)"; + } + + 506 + { + title = "Scroll Texture by Back Side Offsets"; + prefix = "(506)"; + } + } + + planescroll + { + title = "Plane Scrolling"; + + 510 + { + title = "Scroll Floor Texture"; + prefix = "(510)"; + } + + 511 + { + title = "Scroll Floor Texture (Accelerative)"; + prefix = "(511)"; + } + + 512 + { + title = "Scroll Floor Texture (Displacement)"; + prefix = "(512)"; + } + + 513 + { + title = "Scroll Ceiling Texture"; + prefix = "(513)"; + } + + 514 + { + title = "Scroll Ceiling Texture (Accelerative)"; + prefix = "(514)"; + } + + 515 + { + title = "Scroll Ceiling Texture (Displacement)"; + prefix = "(515)"; + } + + 520 + { + title = "Carry Objects on Floor"; + prefix = "(520)"; + } + + 521 + { + title = "Carry Objects on Floor (Accelerative)"; + prefix = "(521)"; + } + + 522 + { + title = "Carry Objects on Floor (Displacement)"; + prefix = "(522)"; + } + + 523 + { + title = "Carry Objects on Ceiling"; + prefix = "(523)"; + } + + 524 + { + title = "Carry Objects on Ceiling (Accelerative)"; + prefix = "(524)"; + } + + 525 + { + title = "Carry Objects on Ceiling (Displacement)"; + prefix = "(525)"; + } + + 530 + { + title = "Scroll Floor Texture and Carry Objects"; + prefix = "(530)"; + } + + 531 + { + title = "Scroll Floor Texture and Carry Objects (Accelerative)"; + prefix = "(531)"; + } + + 532 + { + title = "Scroll Floor Texture and Carry Objects (Displacement)"; + prefix = "(532)"; + } + + 533 + { + title = "Scroll Ceiling Texture and Carry Objects"; + prefix = "(533)"; + } + + 534 + { + title = "Scroll Ceiling Texture and Carry Objects (Accelerative)"; + prefix = "(534)"; + } + + 535 + { + title = "Scroll Ceiling Texture and Carry Objects (Displacement)"; + prefix = "(535)"; + } + } + + pusher + { + title = "Pusher"; + + 541 + { + title = "Wind"; + prefix = "(541)"; + } + + 542 + { + title = "Upwards Wind"; + prefix = "(542)"; + } + + 543 + { + title = "Downwards Wind"; + prefix = "(543)"; + } + + 544 + { + title = "Current"; + prefix = "(544)"; + } + + 545 + { + title = "Upwards Current"; + prefix = "(545)"; + } + + 546 + { + title = "Downwards Current"; + prefix = "(546)"; + } + + 547 + { + title = "Push/Pull"; + prefix = "(547)"; + } + } + + light + { + title = "Lighting"; + + 600 + { + title = "Floor Lighting"; + prefix = "(600)"; + } + + 601 + { + title = "Ceiling Lighting"; + prefix = "(601)"; + } + + 602 + { + title = "Adjustable Pulsating Light"; + prefix = "(602)"; + } + + 603 + { + title = "Adjustable Flickering Light"; + prefix = "(603)"; + } + + 604 + { + title = "Adjustable Blinking Light (unsynchronized)"; + prefix = "(604)"; + } + + 605 + { + title = "Adjustable Blinking Light (synchronized)"; + prefix = "(605)"; + } + + 606 + { + title = "Colormap"; + prefix = "(606)"; + } + } + + transwall + { + title = "Translucent Wall"; + + 900 + { + title = "90% Opaque"; + prefix = "(900)"; + } + + 901 + { + title = "80% Opaque"; + prefix = "(901)"; + } + + 902 + { + title = "70% Opaque"; + prefix = "(902)"; + } + + 903 + { + title = "60% Opaque"; + prefix = "(903)"; + } + + 904 + { + title = "50% Opaque"; + prefix = "(904)"; + } + + 905 + { + title = "40% Opaque"; + prefix = "(905)"; + } + + 906 + { + title = "30% Opaque"; + prefix = "(906)"; + } + + 907 + { + title = "20% Opaque"; + prefix = "(907)"; + } + + 908 + { + title = "10% Opaque"; + prefix = "(908)"; + } + + 909 + { + title = "Fog Wall"; + prefix = "(909)"; + } + } +} + + +// THING FLAGS +thingflags +{ + 1 = "[0] Unused Flag"; + 2 = "[1] Object Flip"; + 4 = "[2] Object Special"; + 8 = "[3] Ambush"; + 16 = "(Used for Z offsets)"; +} + +// Thing flags UDMF translation table +// This is needed for copy/paste and prefabs to work properly +// When the UDMF field name is prefixed with ! it is inverted +thingflagstranslation +{ + 1 = "skill1"; + 2 = "skill2"; + 4 = "skill3"; + 8 = "ambush"; + 16 = "!single"; +} + +// THING FLAGS ERROR MASK +// Mask for the thing flags which indicates the options +// that make the same thing appear in the same modes +thingflagsmask1 = 7; // 1 + 2 + 4 +thingflagsmask2 = 0; + + +// THING TYPES------------------------------------------------------------------ +// Color values: 1-Blue 2-Green 3-Cyan 4-Red 5-Magenta 6-Brown 7-Gray +// 8-Dark_Gray 9-Light_Blue 10-Light_Green 11-Light_Cyan 12-Light_Red 13-Pink +// 14-Yellow 15-White +thingtypes +{ + editor + { + color = 15; // White + arrow = 1; + title = ""; + error = -1; + width = 8; + height = 16; + sort = 1; + + 32000 = "3D Mode Start"; + 32001 + { + arrow = 0; + title = "Control Sector Position Hint"; + } + } + + starts + { + color = 1; // Blue + arrow = 1; + title = "Player Starts"; + width = 16; + height = 56; + deaftext = "[3] Spawn On Ceiling"; + + 1 + { + title = "Player 01 Start"; + sprite = "SUPTD0"; + } + 2 + { + title = "Player 02 Start"; + sprite = "SUPTD0"; + } + 3 + { + title = "Player 03 Start"; + sprite = "SUPTD0"; + } + 4 + { + title = "Player 04 Start"; + sprite = "SUPTD0"; + } + 5 + { + title = "Player 05 Start"; + sprite = "SUPTD0"; + } + 6 + { + title = "Player 06 Start"; + sprite = "SUPTD0"; + } + 7 + { + title = "Player 07 Start"; + sprite = "SUPTD0"; + } + 8 + { + title = "Player 08 Start"; + sprite = "SUPTD0"; + } + 9 + { + title = "Player 09 Start"; + sprite = "SUPTD0"; + } + 10 + { + title = "Player 10 Start"; + sprite = "SUPTD0"; + } + 11 + { + title = "Player 11 Start"; + sprite = "SUPTD0"; + } + 12 + { + title = "Player 12 Start"; + sprite = "SUPTD0"; + } + 13 + { + title = "Player 13 Start"; + sprite = "SUPTD0"; + } + 14 + { + title = "Player 14 Start"; + sprite = "SUPTD0"; + } + 15 + { + title = "Player 15 Start"; + sprite = "SUPTD0"; + } + 16 + { + title = "Player 16 Start"; + sprite = "SUPTD0"; + } + 17 + { + title = "Player 17 Start"; + sprite = "SUPTD0"; + } + 18 + { + title = "Player 18 Start"; + sprite = "SUPTD0"; + } + 19 + { + title = "Player 19 Start"; + sprite = "SUPTD0"; + } + 20 + { + title = "Player 20 Start"; + sprite = "SUPTD0"; + } + 21 + { + title = "Player 21 Start"; + sprite = "SUPTD0"; + } + 22 + { + title = "Player 22 Start"; + sprite = "SUPTD0"; + } + 23 + { + title = "Player 23 Start"; + sprite = "SUPTD0"; + } + 24 + { + title = "Player 24 Start"; + sprite = "SUPTD0"; + } + 25 + { + title = "Player 25 Start"; + sprite = "SUPTD0"; + } + 26 + { + title = "Player 26 Start"; + sprite = "SUPTD0"; + } + 27 + { + title = "Player 27 Start"; + sprite = "SUPTD0"; + } + 28 + { + title = "Player 28 Start"; + sprite = "SUPTD0"; + } + 29 + { + title = "Player 29 Start"; + sprite = "SUPTD0"; + } + 30 + { + title = "Player 30 Start"; + sprite = "SUPTD0"; + } + 31 + { + title = "Player 31 Start"; + sprite = "SUPTD0"; + } + 32 + { + title = "Player 32 Start"; + sprite = "SUPTD0"; + } + 33 + { + title = "Match Start"; + sprite = "SUPTI0"; + } + 34 + { + title = "CTF Red Team Start"; + sprite = "SIGNG0"; + } + 35 + { + title = "CTF Blue Team Start"; + sprite = "SIGNE0"; + } + } + + enemies + { + color = 9; // Light_Blue + arrow = 1; + title = "Enemies"; + width = 24; + height = 32; + sort = 1; + + 100 + { + title = "Crawla (Blue)"; + sprite = "POSSA1"; + } + 101 + { + title = "Crawla (Red)"; + sprite = "SPOSA1"; + } + 102 + { + title = "Stupid Dumb Unnamed RoboFish"; + sprite = "FISHA0"; + width = 8; + height = 28; + } + 103 + { + title = "Buzz (Gold)"; + sprite = "BUZZA1"; + width = 20; + height = 24; + deaftext = "[3] Cannot Move"; + } + 104 + { + title = "Buzz (Red)"; + sprite = "RBUZA1"; + width = 20; + height = 24; + deaftext = "[3] Cannot Move"; + } + 105 + { + title = "Jetty-Syn Bomber"; + sprite = "JETBB1"; + width = 20; + height = 48; + deaftext = "[3] Cannot Move"; + } + 106 + { + title = "Jetty-Syn Gunner"; + sprite = "JETGB1"; + width = 20; + height = 48; + deaftext = "[3] Cannot Move"; + } + 107 + { + title = "Crawla Commander"; + sprite = "CCOMA1"; + width = 16; + } + 108 + { + title = "Deton"; + sprite = "DETNA1"; + width = 20; + } + 109 + { + title = "Skim"; + sprite = "SKIMA1"; + width = 16; + height = 24; + } + 110 + { + title = "Turret"; + sprite = "TRETA1"; + width = 16; + height = 32; + } + 111 + { + title = "Popup Turret"; + sprite = "TURRI1"; + width = 12; + height = 64; + } + 112 + { + title = "Sharp"; + sprite = "SHRPA1"; + width = 16; + height = 24; + } + 113 + { + title = "Jet Jaw"; + sprite = "JJAWA3A7"; + width = 12; + height = 20; + } + 114 + { + title = "Snailer"; + sprite = "SNLRA3A7"; + height = 48; + } + 115 + { + title = "Bird Aircraft Strike Hazard"; + sprite = "VLTRF1"; + width = 12; + height = 24; + } + 116 + { + title = "Pointy"; + sprite = "PNTYA1"; + width = 8; + height = 16; + } + 117 + { + title = "Robo-Hood"; + sprite = "ARCHA1"; + deaftext = "[3] Cannot Jump"; + } + 118 + { + title = "CastleBot FaceStabber"; + sprite = "CBFSA1"; + width = 32; + height = 64; + } + 119 + { + title = "Egg Guard"; + sprite = "ESHIA1"; + width = 16; + height = 48; + deaftext = "[3] Double Speed"; + } + 120 + { + title = "Green Snapper"; + sprite = "GSNPA1"; + height = 24; + } + 121 + { + title = "Minus"; + sprite = "MNUSA1"; + } + 122 + { + title = "Spring Shell (Green)"; + sprite = "SSHLA1"; + height = 40; + } + 123 + { + title = "Unidus"; + sprite = "UNIDA1"; + width = 18; + height = 36; + } + 124 + { + title = "AquaBuzz"; + sprite = "BBUZA1"; + width = 20; + height = 24; + } + 125 + { + title = "Spring Shell (Yellow)"; + sprite = "YSHLA1"; + height = 40; + } + 750 + { + title = " Chaos Enemy Spawn"; + sprite = "TFOGG0"; + width = 32; + height = 64; + } + } + + bosses + { + color = 8; // Dark_Gray + arrow = 1; + title = "Bosses"; + width = 24; + height = 52; + sort = 1; + + 200 + { + title = "Boss 1 - Egg Mobile"; + sprite = "EGGMA1"; + deaftext = "[3] Rotating Spikeballs"; + } + 201 + { + title = "Boss 2 - Egg Slimer"; + sprite = "EGGNA1"; + height = 48; + deaftext = "[3] Speed Up When Hit"; + } + 202 + { + title = "Boss 3 - Sea Egg"; + sprite = "EGGOA1"; + width = 32; + height = 80; + } + 203 + { + title = "Boss 4 - Eggscalibur"; + sprite = "EGGPA1"; + } + 206 + { + title = "Boss - Black Eggman (Old)"; + sprite = "BRAKB1"; + width = 48; + height = 160; + } + 207 + { + title = "Boss 5A - Metal Sonic Race Start"; + sprite = "METLI1"; + width = 16; + height = 48; + } + 208 + { + title = "Boss 5B - Metal Sonic Battle Start"; + sprite = "METLC1"; + width = 16; + height = 48; + } + 209 + { + title = "Boss 6 - Black Eggman (New)"; + sprite = "BRAK[1"; + width = 48; + height = 160; + deaftext = "[3] Electric Barrier"; + } + 290 + { + arrow = 0; + title = "Boss Escape Point"; + width = 8; + height = 16; + } + 291 + { + arrow = 0; + title = "Egg Trap Center"; + width = 8; + height = 16; + } + 292 + { + arrow = 0; + title = "Boss Waypoint"; + width = 8; + height = 16; + deaftext = "[3] Sea Egg Shooting Point"; + } + 293 = "Metal Sonic Waypoint"; + } + + rings + { + color = 14; // Yellow + title = "Rings and Weapon Panels"; + width = 24; + height = 24; + deafheight = 32; + deaftext = "[3] Float"; + + 300 + { + title = "Ring"; + sprite = "RINGA0"; + width = 16; + } + 301 + { + title = "Bounce Ring"; + sprite = "CPRKB0"; + } + 302 + { + title = "Rail Ring"; + sprite = "SPRKA0"; + } + 304 + { + title = "Automatic Ring"; + sprite = "TAUTA3A7"; + } + 305 + { + title = "Explosion Ring"; + sprite = "BMSLA1"; + } + 306 + { + title = "Scatter Ring"; + sprite = "TSCRA1A5"; + } + 307 + { + title = "Grenade Ring"; + sprite = "TGREA0"; + } + 308 + { + title = "CTF Team Ring (Red)"; + sprite = "RRNGA0"; + width = 16; + } + 309 + { + title = "CTF Team Ring (Blue)"; + sprite = "TRNGA0"; + width = 16; + } + 330 + { + title = "Bounce Ring Panel"; + sprite = "PIKBA0"; + } + 331 + { + title = "Rail Ring Panel"; + sprite = "PIKRA0"; + } + 332 + { + title = "Automatic Ring Panel"; + sprite = "PIKAA0"; + } + 333 + { + title = "Explosion Ring Panel"; + sprite = "PIKEA0"; + } + 334 + { + title = "Scatter Ring Panel"; + sprite = "PIKSA0"; + } + 335 + { + title = "Grenade Ring Panel"; + sprite = "PIKGA0"; + } + } + + collectibles + { + color = 10; // Light_Green + title = "Other Collectibles"; + width = 16; + height = 32; + sort = 1; + + 310 + { + title = "CTF Red Flag"; + sprite = "RFLGA0"; + width = 24; + height = 64; + } + 311 + { + title = "CTF Blue Flag"; + sprite = "BFLGA0"; + width = 24; + height = 64; + } + 312 + { + title = "Special Stage Token"; + sprite = "TOKEA0"; + width = 8; + height = 16; + deafheight = 32; + deaftext = "[3] Float"; + } + 313 + { + title = "Chaos Emerald 1 (Green)"; + sprite = "EMMYA0"; + } + 314 + { + title = "Chaos Emerald 2 (Orange)"; + sprite = "EMMYB0"; + } + 315 + { + title = "Chaos Emerald 3 (Purple)"; + sprite = "EMMYC0"; + } + 316 + { + title = "Chaos Emerald 4 (Blue)"; + sprite = "EMMYD0"; + } + 317 + { + title = "Chaos Emerald 5 (Red)"; + sprite = "EMMYE0"; + } + 318 + { + title = "Chaos Emerald 6 (Light Blue)"; + sprite = "EMMYF0"; + } + 319 + { + title = "Chaos Emerald 7 (Gray)"; + sprite = "EMMYG0"; + } + 320 + { + title = "Emerald Hunt Location"; + sprite = "EMERA0"; + } + 323 + { + title = "Match Chaos Emerald Spawn"; + sprite = "CEMGA0"; + width = 8; + height = 16; + deafheight = 32; + deaftext = "[3] Float"; + } + } + + boxes + { + color = 7; // Gray + blocking = 2; + title = "Item Boxes"; + width = 16; + height = 32; + deaftext = "[3] Random (Weak)"; + sort = 1; + + 400 + { + title = "Super Ring (10 Rings)"; + sprite = "SRBXA0"; + } + 401 + { + title = "Pity / Basic Shield"; + sprite = "GRTVA0"; + } + 402 + { + title = "Attraction Shield"; + sprite = "YLTVA0"; + } + 403 + { + title = "Force Shield"; + sprite = "BLTVA0"; + } + 404 + { + title = "Armageddon Shield"; + sprite = "BKTVA0"; + } + 405 + { + title = "Whirlwind Shield"; + sprite = "WHTVA0"; + } + 406 + { + title = "Elemental Shield"; + sprite = "ELTVA0"; + } + 407 + { + title = "Super Sneakers"; + sprite = "SHTVA0"; + } + 408 + { + title = "Invincibility"; + sprite = "PINVA0"; + } + 409 + { + title = "Extra Life"; + sprite = "PRUPA0"; + deaftext = "[3] Random (Weak) / 10k points"; + } + 410 + { + title = "Eggman"; + sprite = "EGGBA0"; + } + 411 + { + title = "Teleporter"; + sprite = "MIXUA0"; + } + 412 + { + title = "Random"; + sprite = "QUESA0"; + } + 413 + { + title = "Gravity Boots"; + sprite = "GBTVA0"; + } + 414 + { + title = "CTF Team Ring Box (Red)"; + sprite = "RRBXA0"; + deaftext = "[3] Ambush"; + } + 415 + { + title = "CTF Team Ring Box (Blue)"; + sprite = "BRBXA0"; + deaftext = "[3] Ambush"; + } + 416 + { + title = "Recycler"; + sprite = "RECYA0"; + } + 418 + { + title = "1,000 Points"; + sprite = "PTTVA0"; + } + 419 + { + title = "10,000 Points"; + sprite = "PTTVF0"; + } + } + + miscellaneous + { + color = 11; // Light_Cyan + title = "Miscellaneous"; + width = 16; + height = 40; + sort = 1; + + 500 + { + title = "Air Bubble Patch"; + sprite = "BUBLA0"; + width = 8; + height = 16; + deaftext = "[3] No Distance Check"; + } + 501 + { + title = "End Level Sign"; + sprite = "SIGND0"; + width = 8; + height = 32; + } + 502 + { + arrow = 1; + title = "Star Post"; + sprite = "STPTA0"; + width = 64; + height = 80; + } + 526 + { + blocking = 2; + title = "Cannonball"; + sprite = "CBLLA0"; + width = 20; + deaftext = "[3] Not Pushable"; + } + 1000 + { + arrow = 1; + blocking = 2; + title = "Gargoyle"; + sprite = "GARGA1"; + deaftext = "[3] Not Pushable"; + } + 1102 + { + arrow = 1; + blocking = 2; + title = "Eggman Statue"; + sprite = "ESTAA1"; + width = 32; + height = 240; + deaftext = "[3] Not Pushable"; + } + 1106 + { + arrow = 1; + title = "Chain (Hang)"; + sprite = "SMCHA0"; + height = 32; + deaftext = "[3] Double Size"; + } + 1107 + { + arrow = 1; + title = "Chain (Spin)"; + sprite = "SMCHA0"; + height = 32; + } + 1200 + { + title = "Tumbleweed (Big)"; + sprite = "BTBLA0"; + width = 24; + height = 48; + deaftext = "[3] Moves Perpetually"; + } + 1201 + { + title = "Tumbleweed (Small)"; + sprite = "STBLA0"; + width = 12; + height = 24; + deaftext = "[3] Moves Perpetually"; + } + 1504 + { + title = "ATZ Target"; + sprite = "RCRYB0"; + width = 24; + height = 32; + } + 1852 + { + blocking = 2; + title = "Snowman"; + sprite = "XMS3A0"; + deaftext = "[3] Not Pushable"; + } + 1876 + { + arrow = 1; + blocking = 2; + title = "Eggman Disco Statue"; + sprite = "ESTAB1"; + width = 20; + height = 96; + deaftext = "[3] Not Pushable"; + } + } + + springs + { + color = 12; // Light_Red + title = "Springs and Fans"; + width = 20; + height = 16; + + 540 + { + title = "Fan"; + sprite = "FANSA0D0"; + width = 16; + deaftext = "[3] No Distance Check"; + } + 541 + { + title = "Gas Jet"; + sprite = "STEMD0"; + width = 32; + } + 550 + { + title = "Yellow Spring"; + sprite = "SPRYA0"; + } + 551 + { + title = "Red Spring"; + sprite = "SPRRA0"; + } + 552 + { + title = "Blue Spring"; + sprite = "SPRBA0"; + } + 555 + { + arrow = 1; + title = "Diagonal Yellow Spring"; + sprite = "YSPRD2"; + width = 16; + deaftext = "[3] Rotate 22.5° CCW"; + } + 556 + { + arrow = 1; + title = "Diagonal Red Spring"; + sprite = "RSPRD2"; + width = 16; + deaftext = "[3] Rotate 22.5° CCW"; + } + } + + patterns + { + color = 5; // Magenta + arrow = 1; + title = "Special Placement Patterns"; + width = 16; + height = 384; + + 600 + { + arrow = 0; + title = "5 Vertical Rings (Yellow Spring)"; + sprite = "RINGA0"; + } + 601 + { + arrow = 0; + title = "5 Vertical Rings (Red Spring)"; + sprite = "RINGA0"; + height = 1024; + } + 602 + { + title = "5 Diagonal Rings (Yellow Spring)"; + sprite = "RINGA0"; + height = 32; + } + 603 + { + title = "10 Diagonal Rings (Red Spring)"; + sprite = "RINGA0"; + height = 32; + } + 604 + { + title = "Circle of Rings"; + sprite = "RINGA0"; + width = 96; + height = 192; + } + 605 + { + title = "Circle of Rings (Big)"; + sprite = "RINGA0"; + width = 192; + } + 606 + { + title = "Circle of Wing Logos"; + sprite = "NWNGA0"; + width = 96; + height = 192; + } + 607 + { + title = "Circle of Wing Logos (Big)"; + sprite = "NWNGA0"; + width = 192; + } + 608 + { + title = "Circle of Rings and Wings"; + sprite = "NWNGA0"; + width = 96; + height = 192; + } + 609 + { + title = "Circle of Rings and Wings (Big)"; + sprite = "NWNGA0"; + width = 192; + } + } + + invisible + { + color = 15; // White + title = "Misc. Invisible"; + width = 8; + height = 16; + + 700 = "Water Ambience A (Large)"; + 701 = "Water Ambience B (Large)"; + 702 = "Water Ambience C (Medium)"; + 703 = "Water Ambience D (Medium)"; + 704 = "Water Ambience E (Small)"; + 705 = "Water Ambience F (Small)"; + 706 = "Water Ambience G (Extra Large)"; + 707 = "Water Ambience H (Extra Large)"; + 708 = "Disco Ambience"; + 709 = "Volcano Ambience"; + 751 + { + arrow = 1; + title = "Teleport Destination"; + } + 752 + { + arrow = 1; + title = "Alternate View Point"; + } + 753 = "Zoom Tube Waypoint"; + 754 + { + title = "Push Point"; + deaftext = "[3] Push Using XYZ"; + } + 755 + { + title = "Pull Point"; + deaftext = "[3] Pull Using XYZ"; + } + 760 = "PolyObject Anchor"; + 761 = "PolyObject Spawn Point"; + 762 = "PolyObject Spawn Point (Crush)"; + 780 = "Skybox View Point"; + + } + + hazards + { + color = 4; // Red + title = "Hazards"; + width = 20; + height = 40; + sort = 1; + + 521 + { + title = "Spikeball"; + sprite = "SPIKA0"; + width = 12; + height = 24; + deafheight = 32; + deaftext = "[3] Float"; + } + 523 + { + title = "Spike (Floor)"; + sprite = "USPKA0"; + width = 8; + height = 42; + deaftext = "[3] Solid"; + } + 524 + { + arrow = 1; + title = "Big Floating Mine"; + width = 16; + height = 32; + sprite = "BMNEA1"; + } + 527 + { + arrow = 1; + title = "Big Floating Mine (Air)"; + width = 16; + height = 32; + sprite = "BMNEA1"; + } + 525 + { + title = "Cannonball Launcher"; + sprite = "CBLLA0"; + } + 1101 + { + title = "Torch"; + sprite = "FLAMA0"; + width = 8; + height = 32; + } + 1104 + { + title = "Mace (Spinning)"; + sprite = "SMCEA0"; + deaftext = "[3] Double Size"; + } + 1105 + { + title = "Mace (Swinging)"; + sprite = "SMCEA0"; + deaftext = "[3] Double Size"; + } + 1202 + { + arrow = 1; + title = "Rock Spawner"; + sprite = "ROIAA0"; + } + 1300 + { + arrow = 1; + title = "Flame Jet (Horizontal)"; + sprite = "FLMEB0"; + width = 16; + } + 1301 + { + title = "Flame Jet (Vertical)"; + sprite = "FLMEB0"; + width = 16; + deaftext = "[3] Shoot Downwards"; + } + 1500 + { + arrow = 1; + blocking = 2; + title = "Trapgoyle"; + sprite = "GARGA1"; + width = 16; + height = 40; + deaftext = "[3] Not Pushable"; + } + 1501 + { + arrow = 1; + blocking = 2; + title = "Trapgoyle (Up)"; + sprite = "GARGA1"; + width = 16; + height = 40; + deaftext = "[3] Not Pushable"; + } + 1502 + { + arrow = 1; + blocking = 2; + title = "Trapgoyle (Down)"; + sprite = "GARGA1"; + width = 16; + height = 40; + deaftext = "[3] Not Pushable"; + } + 1503 + { + arrow = 1; + blocking = 2; + title = "Trapgoyle (Long)"; + sprite = "GARGA1"; + width = 16; + height = 40; + deaftext = "[3] Not Pushable"; + } + 3575 + { + title = "Spinning Flame Jet (Counter-Clockwise)"; + sprite = "FLMEB0"; + width = "16"; + } + 3576 + { + title = "Spinning Flame Jet (Clockwise)"; + sprite = "FLMEB0"; + width = "16"; + } + } + + decoration + { + color = 2; // Green + title = "Decoration"; + width = 16; + height = 40; + + 757 + { + title = "Fan Particle Generator"; + sprite = "PRTLA0"; + width = 8; + height = 16; + } + 800 + { + title = "GFZ Flower"; + sprite = "FWR1A0"; + } + 801 + { + title = "Sunflower"; + sprite = "FWR2A0"; + height = 96; + } + 802 + { + title = "Budding Flower"; + sprite = "FWR3A0"; + width = 8; + height = 32; + } + 804 + { + title = "Berry Bush"; + sprite = "BUS1A0"; + height = 32; + } + 805 + { + title = "Bush"; + sprite = "BUS2A0"; + height = 32; + } + 900 + { + title = "THZ Flower"; + sprite = "THZPA0"; + width = 8; + height = 32; + } + 901 + { + title = "Alarm"; + sprite = "ALRMA0"; + width = 8; + height = 16; + hangs = 1; + } + 1001 + { + title = "Seaweed"; + sprite = "SEWEA0"; + width = 24; + height = 56; + } + 1002 + { + title = "Dripping Water"; + sprite = "DRIPD0"; + width = 8; + height = 16; + hangs = 1; + } + 1003 + { + title = "Coral (Green)"; + sprite = "CRL1A0"; + width = 8; + height = 16; + } + 1004 + { + title = "Coral (Red)"; + sprite = "CRL2A0"; + width = 8; + height = 16; + } + 1005 + { + title = "Coral (Orange)"; + sprite = "CRL3A0"; + width = 8; + height = 16; + } + 1006 + { + title = "Blue Crystal"; + sprite = "BCRYA1"; + width = 8; + height = 16; + } + 1100 + { + title = "Chain"; + sprite = "CHANA0"; + width = 8; + height = 128; + hangs = 1; + } + 1103 + { + title = "CEZ Flower"; + sprite = "FWR4A0"; + } + 1203 + { + title = "Cactus with Brown Flower"; + sprite = "CACTA0"; + height = 32; + } + 1204 + { + title = "Cactus with Brown Flower (Tall)"; + sprite = "CACTB0"; + height = 64; + } + 1205 + { + title = "Cactus with Blue Flower"; + sprite = "CACTC0"; + height = 32; + } + 1206 + { + title = "Cactus with Blue Flower (Tall)"; + sprite = "CACTD0"; + height = 80; + } + 1850 + { + title = "Xmas Pole"; + sprite = "XMS1A0"; + } + 1851 + { + title = "Candy Cane"; + sprite = "XMS2A0"; + width = 8; + height = 32; + } + 1875 + { + title = "Disco Ball"; + sprite = "DBALA0"; + height = 54; + hangs = 1; + } + 1900 + { + title = "Brown Stalagmite (Tall)"; + sprite = "STLGA0"; + } + 1901 + { + title = "Brown Stalagmite"; + sprite = "STLGB0"; + } + 1902 + { + title = "Orange Stalagmite (Tall)"; + sprite = "STLGC0"; + } + 1903 + { + title = "Orange Stalagmite"; + sprite = "STLGD0"; + } + 1904 + { + title = "Red Stalagmite (Tall)"; + sprite = "STLGE0"; + } + 1905 + { + title = "Red Stalagmite"; + sprite = "STLGF0"; + } + 1906 + { + title = "Gray Stalagmite (Tall)"; + sprite = "STLGG0"; + } + 1907 + { + title = "Gray Stalagmite"; + sprite = "STLGH0"; + } + 1908 + { + title = "Blue Stalagmite (Tall)"; + sprite = "STLGI0"; + } + 1909 + { + title = "Blue Stalagmite"; + sprite = "STLGJ0"; + } + } + + nights + { + color = 13; // Pink + title = "Nights Items"; + width = 12; + height = 32; + + 1703 + { + title = "Ideya Drone"; + sprite = "NDRNA1"; + width = 16; + height = 56; + deaftext = "[3] Die Upon Time Up"; + } + 1704 + { + arrow = 1; + title = "Bumper"; + sprite = "NBMPG3G7"; + width = 32; + height = 64; + } + 1705 + { + arrow = 1; + title = "Hoop (Generic)"; + sprite = "HOOPA0"; + width = 80; + height = 160; + } + 1706 + { + title = "Wing Logo"; + sprite = "NWNGA0"; + height = 24; + } + 1707 + { + title = "Super Loop"; + sprite = "NPRUA0"; + deaftext = "[3] Spawn Immediately"; + } + 1708 + { + title = "Drill Refill"; + sprite = "NPRUB0"; + deaftext = "[3] Spawn Immediately"; + } + 1709 + { + title = "Helper"; + sprite = "NPRUC0"; + deaftext = "[3] Spawn Immediately"; + } + 1711 + { + title = "Extra Time"; + sprite = "NPRUD0"; + deaftext = "[3] Spawn Immediately"; + } + 1712 + { + title = "Link Freeze"; + sprite = "NPRUE0"; + deaftext = "[3] Spawn Immediately"; + } + 1713 + { + arrow = 1; + title = "Hoop (Customizable)"; + sprite = "HOOPA0"; + width = 80; + height = 160; + } + } + + nightstrk + { + color = 13; // Pink + title = "Nights Track"; + width = 8; + height = 4096; + + 1700 + { + title = "Axis"; + circle = 1; + } + 1701 + { + title = "Axis Transfer"; + } + 1702 + { + title = "Axis Transfer Line"; + } + 1710 + { + title = "Egg Capsule"; + sprite = "CAPSA0"; + width = 72; + height = 144; + } + } + + nightstrk1 + { + color = 13; // Pink + title = "Nights Track (2nd Mare)"; + width = 8; + height = 4096; + + 5796 + { + title = "(Mare 2) Axis"; + circle = 1; + } + 5797 + { + title = "(Mare 2) Axis Transfer"; + } + 5798 + { + title = "(Mare 2) Axis Transfer Line"; + } + 5806 + { + title = "(Mare 2) Egg Capsule"; + sprite = "CAPSA0"; + width = 72; + height = 144; + } + } + + nightstrk2 + { + color = 13; // Pink + title = "Nights Track (3rd Mare)"; + width = 8; + height = 4096; + + 9892 + { + title = "(Mare 3) Axis"; + circle = 1; + } + 9893 + { + title = "(Mare 3) Axis Transfer"; + } + 9894 + { + title = "(Mare 3) Axis Transfer Line"; + } + 9902 + { + title = "(Mare 3) Egg Capsule"; + sprite = "CAPSA0"; + width = 72; + height = 144; + } + } + + nightstrk3 + { + color = 13; // Pink + title = "Nights Track (4th Mare)"; + width = 8; + height = 4096; + + 13988 + { + title = "(Mare 4) Axis"; + circle = 1; + } + 13989 + { + title = "(Mare 4) Axis Transfer"; + } + 13990 + { + title = "(Mare 4) Axis Transfer Line"; + } + 13998 + { + title = "(Mare 4) Egg Capsule"; + sprite = "CAPSA0"; + width = 72; + height = 144; + } + } + + nightstrk4 + { + color = 13; // Pink + title = "Nights Track (5th Mare)"; + width = 8; + height = 4096; + + 18084 + { + title = "(Mare 5) Axis"; + circle = 1; + } + 18085 + { + title = "(Mare 5) Axis Transfer"; + } + 18086 + { + title = "(Mare 5) Axis Transfer Line"; + } + 18094 + { + title = "(Mare 5) Egg Capsule"; + sprite = "CAPSA0"; + width = 72; + height = 144; + } + } + + nightstrk5 + { + color = 13; // Pink + title = "Nights Track (6th Mare)"; + width = 8; + height = 4096; + + 22180 + { + title = "(Mare 6) Axis"; + circle = 1; + } + 22181 + { + title = "(Mare 6) Axis Transfer"; + } + 22182 + { + title = "(Mare 6) Axis Transfer Line"; + } + 22190 + { + title = "(Mare 6) Egg Capsule"; + sprite = "CAPSA0"; + width = 72; + height = 144; + } + } + + nightstrk6 + { + color = 13; // Pink + title = "Nights Track (7th Mare)"; + width = 8; + height = 4096; + + 26276 + { + title = "(Mare 7) Axis"; + circle = 1; + } + 26277 + { + title = "(Mare 7) Axis Transfer"; + } + 26278 + { + title = "(Mare 7) Axis Transfer Line"; + } + 26286 + { + title = "(Mare 7) Egg Capsule"; + sprite = "CAPSA0"; + width = 72; + height = 144; + } + } + + nightstrk7 + { + color = 13; // Pink + title = "Nights Track (8th Mare)"; + width = 8; + height = 4096; + + 30372 + { + title = "(Mare 8) Axis"; + circle = 1; + } + 30373 + { + title = "(Mare 8) Axis Transfer"; + } + 30374 + { + title = "(Mare 8) Axis Transfer Line"; + } + 30382 + { + title = "(Mare 8) Egg Capsule"; + sprite = "CAPSA0"; + width = 72; + height = 144; + } + } + + mario + { + color = 6; // Brown + title = "Mario Items"; + width = 16; + height = 32; + sort = 1; + + 1800 + { + title = "Coin"; + sprite = "COINA0"; + height = 24; + deafheight = 32; + deaftext = "[3] Float"; + } + 1801 + { + arrow = 1; + title = "Goomba"; + sprite = "GOOMA0"; + width = 24; + } + 1802 + { + arrow = 1; + title = "Goomba (Blue)"; + sprite = "BGOMA0"; + width = 24; + } + 1803 + { + title = "Fire Flower"; + sprite = "FFWRB0"; + } + 1804 + { + title = "Koopa Shell"; + sprite = "SHLLA0"; + width = 8; + height = 16; + } + 1805 + { + title = "Puma (Jumping Fireball)"; + sprite = "PUMAA0"; + width = 8; + height = 16; + } + 1806 + { + title = "King Bowser"; + sprite = "KOOPA0"; + height = 28; + } + 1807 + { + title = "Axe"; + sprite = "MAXEA0"; + width = 8; + height = 16; + } + 1808 + { + title = "Bush (Short)"; + sprite = "MUS1A0"; + } + 1809 + { + title = "Bush (Tall)"; + sprite = "MUS2A0"; + } + 1810 + { + title = "Toad"; + sprite = "TOADA0"; + width = 8; + } + } + + srb1 + { + color = 3; // Cyan + arrow = 1; + title = "SRB1 Remake"; + width = 20; + height = 32; + sort = 1; + + 4000 + { + title = "SRB1 Crawla"; + sprite = "SRBAA1"; + height = 40; + } + 4001 + { + title = "GuardRobo"; + sprite = "SRBBA1"; + width = 17; + height = 40; + } + 4002 + { + title = "Pyrin"; + sprite = "SRBCB1"; + width = 22; + } + 4003 + { + title = "HotRobo"; + sprite = "SRBDA0"; + height = 40; + } + 4004 + { + title = "Pogminz"; + sprite = "SRBEA1"; + } + 4005 + { + title = "Pogminz (Water)"; + sprite = "SRBEA1"; + } + 4006 + { + title = "Pog-GX2"; + sprite = "SRBFA0"; + width = 10; + height = 34; + } + 4007 + { + title = "Pyrex"; + sprite = "SRBGA1"; + width = 24; + } + 4008 + { + title = "UFO"; + sprite = "SRBHA0"; + width = 24; + hangs = 1; + } + 4009 + { + title = "SWAT Bot"; + sprite = "SRBIA1"; + width = 21; + height = 69; + } + 4010 + { + title = "SpyBot 2000"; + sprite = "SRBJA0"; + width = 36; + height = 62; + } + 4011 + { + title = "Buzz Bomber"; + sprite = "SRBKA0"; + width = 44; + height = 45; + } + 4012 + { + arrow = 0; + title = "RBZ Spike"; + sprite = "SRBLA0"; + width = 10; + height = 53; + } + 4013 + { + arrow = 0; + blocking = 2; + title = "Dumb Metal Sonic"; + sprite = "SRBMC0"; + width = 16; + height = 40; + deaftext = "[3] Not Pushable"; + } + 4014 + { + title = "Super SWAT Bot"; + sprite = "SRBNA1"; + width = 21; + height = 69; + } + 4015 + { + title = "Genrex"; + sprite = "SRBOA1"; + width = 17; + height = 40; + } + } + + bsz + { + color = 2; // Green + title = "Botanic Serenity Items"; + width = 16; + height = 32; + 1400 + { + title = "Tall Flower (Red)"; + sprite = "BSZ1A0"; + } + 1401 + { + title = "Tall Flower (Purple)"; + sprite = "BSZ1B0"; + } + 1402 + { + title = "Tall Flower (Blue)"; + sprite = "BSZ1C0"; + } + 1403 + { + title = "Tall Flower (Cyan)"; + sprite = "BSZ1D0"; + } + 1404 + { + title = "Tall Flower (Yellow)"; + sprite = "BSZ1E0"; + } + 1405 + { + title = "Tall Flower (Orange)"; + sprite = "BSZ1F0"; + } + 1410 + { + title = "Medium Flower (Red)"; + sprite = "BSZ2A0"; + } + 1411 + { + title = "Medium Flower (Purple)"; + sprite = "BSZ2B0"; + } + 1412 + { + title = "Medium Flower (Blue)"; + sprite = "BSZ2C0"; + } + 1413 + { + title = "Medium Flower (Cyan)"; + sprite = "BSZ2D0"; + } + 1414 + { + title = "Medium Flower (Yellow)"; + sprite = "BSZ2E0"; + } + 1415 + { + title = "Medium Flower (Orange)"; + sprite = "BSZ2F0"; + } + 1420 + { + title = "Short Flower (Red)"; + sprite = "BSZ3A0"; + } + 1421 + { + title = "Short Flower (Purple)"; + sprite = "BSZ3B0"; + } + 1422 + { + title = "Short Flower (Blue)"; + sprite = "BSZ3C0"; + } + 1423 + { + title = "Short Flower (Cyan)"; + sprite = "BSZ3D0"; + } + 1424 + { + title = "Short Flower (Yellow)"; + sprite = "BSZ3E0"; + } + 1425 + { + title = "Short Flower (Orange)"; + sprite = "BSZ3F0"; + } + 1430 + { + title = "Tulip (Red)"; + sprite = "BSZ4A0"; + } + 1431 + { + title = "Tulip (Purple)"; + sprite = "BSZ4B0"; + } + 1432 + { + title = "Tulip (Blue)"; + sprite = "BSZ4C0"; + } + 1433 + { + title = "Tulip (Cyan)"; + sprite = "BSZ4D0"; + } + 1434 + { + title = "Tulip (Yellow)"; + sprite = "BSZ4E0"; + } + 1435 + { + title = "Tulip (Orange)"; + sprite = "BSZ4F0"; + } + 1440 + { + title = "Cluster (Red)"; + sprite = "BSZ5A0"; + } + 1441 + { + title = "Cluster (Purple)"; + sprite = "BSZ5B0"; + } + 1442 + { + title = "Cluster (Blue)"; + sprite = "BSZ5C0"; + } + 1443 + { + title = "Cluster (Cyan)"; + sprite = "BSZ5D0"; + } + 1444 + { + title = "Cluster (Yellow)"; + sprite = "BSZ5E0"; + } + 1445 + { + title = "Cluster (Orange)"; + sprite = "BSZ5F0"; + } + 1450 + { + title = "Bush (Red)"; + sprite = "BSZ6A0"; + } + 1451 + { + title = "Bush (Purple)"; + sprite = "BSZ6B0"; + } + 1452 + { + title = "Bush (Blue)"; + sprite = "BSZ6C0"; + } + 1453 + { + title = "Bush (Cyan)"; + sprite = "BSZ6D0"; + } + 1454 + { + title = "Bush (Yellow)"; + sprite = "BSZ6E0"; + } + 1455 + { + title = "Bush (Orange)"; + sprite = "BSZ6F0"; + } + 1460 + { + title = "Vine (Red)"; + sprite = "BSZ7A0"; + } + 1461 + { + title = "Vine (Purple)"; + sprite = "BSZ7B0"; + } + 1462 + { + title = "Vine (Blue)"; + sprite = "BSZ7C0"; + } + 1463 + { + title = "Vine (Cyan)"; + sprite = "BSZ7D0"; + } + 1464 + { + title = "Vine (Yellow)"; + sprite = "BSZ7E0"; + } + 1465 + { + title = "Vine (Orange)"; + sprite = "BSZ7F0"; + } + 1470 + { + title = "BSZ Shrub"; + sprite = "BSZ8A0"; + } + 1471 + { + title = "BSZ Clover"; + sprite = "BSZ8B0"; + } + 1472 + { + title = "BSZ Fish"; + sprite = "BSZ8C0"; + } + 1473 + { + title = "BSZ Sunflower"; + sprite = "BSZ8D0"; + } + } +} + + + +// Default thing filters +// (these are not required, just usefull for new users) +thingsfilters +{ + + filter0 + { + name = "Easy skill"; + category = ""; + type = -1; + + fields + { + 1 = true; + } + + } + + + filter1 + { + name = "Hard skill"; + category = ""; + type = -1; + + fields + { + 4 = true; + } + + } + + + filter2 + { + name = "Keys only"; + category = "keys"; + type = -1; + } + + + filter3 + { + name = "Medium skill"; + category = ""; + type = -1; + + fields + { + 2 = true; + } + + } + + + filter4 + { + name = "Multiplayer"; + category = ""; + type = -1; + + fields + { + 16 = true; + } + + } +} + + +// Default texture sets +// (these are not required, but usefull for new users) +/* +texturesets +{ + + set0 + { + name = "GFZ Themed Textures"; + filter0 = "GFZROCK"; + filter1 = "GFZGRASS"; + filter2 = "CFALL1"; + filter3 = "GFALL1"; + filter4 = "GFZBLOCK"; + filter5 = "GFZCRACK"; + filter6 = "GFZINSID"; + filter7 = "GFZVINES"; + filter8 = "GFZVCRCK"; + filter9 = "GFZBRIDG"; + filter10 = "GFZBLOK2"; + filter11 = "GFZBRICK"; + filter12 = "GFZDOOR"; + filter13 = "GFZWINDW"; + filter14 = "GFZROOF"; + filter15 = "GFZFENC2"; + filter16 = "GFZGRSW"; + } + + + set1 + { + name = "GFZ Themed Flats"; + filter0 = "FLOOR0_6"; + filter1 = "FLOOR0_3"; + filter2 = "DEM1_4"; + filter3 = "FWATER1"; + filter4 = "SFLR5_0"; + filter5 = "SFLR6_1"; + filter6 = "SLR6_4"; + filter7 = "SFLR7_1"; + filter8 = "SFLR7_4"; + filter9 = "FLOOR0_4"; + filter10 = "FLOOR1_1"; + filter11 = "FLOOR1_7"; + filter12 = "CEIL3_3"; + filter13 = "CEIL3_4"; + filter14 = "GATE1"; + filter15 = "FLOOR0_2"; + } + + + set2 + { + name = "Liquids"; + filter0 = "BFALL*"; + filter1 = "BLOOD*"; + filter2 = "DBRAIN*"; + filter3 = "FWATER*"; + filter4 = "LAVA*"; + filter5 = "NUKAGE*"; + filter6 = "SFALL*"; + filter7 = "SLIME01"; + filter8 = "SLIME02"; + filter9 = "SLIME03"; + filter10 = "SLIME04"; + filter11 = "SLIME05"; + filter12 = "SLIME06"; + filter13 = "SLIME07"; + filter14 = "SLIME08"; + } + + + set3 + { + name = "Doors"; + filter0 = "BIGDOOR*"; + filter1 = "DOOR*"; + filter2 = "EXITDOOR"; + filter3 = "SPCDOOR*"; + filter4 = "TEKBRON1"; + filter5 = "TEKBRON2"; + } + + + set4 + { + name = "Steps"; + filter0 = "STEP*"; + } + + + set5 + { + name = "Wood"; + filter0 = "BIGDOOR5"; + filter1 = "BIGDOOR6"; + filter2 = "BIGDOOR7"; + filter3 = "CEIL1_1"; + filter4 = "CEIL1_3"; + filter5 = "FLAT5_1"; + filter6 = "FLAT5_2"; + filter7 = "PAN*"; + filter8 = "SW1PANEL"; + filter9 = "SW1WDMET"; + filter10 = "SW1WOOD"; + filter11 = "SW2PANEL"; + filter12 = "SW2WDMET"; + filter13 = "SW2WOOD"; + filter14 = "WOOD*"; + } + + + set6 + { + name = "Flesh"; + filter0 = "AASHITTY"; + filter1 = "FLAT5_6"; + filter2 = "SFLR6_1"; + filter3 = "SFLR6_4"; + filter4 = "SFLR7_1"; + filter5 = "SFLR7_4"; + filter6 = "SK_LEFT"; + filter7 = "SK_RIGHT"; + filter8 = "SKIN*"; + filter9 = "SKSNAKE1"; + filter10 = "SKSNAKE2"; + filter11 = "SKSPINE1"; + filter12 = "SKSPINE2"; + filter13 = "SLOPPY1"; + filter14 = "SLOPPY2"; + filter15 = "SP_DUDE1"; + filter16 = "SP_DUDE2"; + filter17 = "SP_DUDE4"; + filter18 = "SP_DUDE5"; + filter19 = "SP_DUDE7"; + filter20 = "SP_DUDE8"; + filter21 = "SP_FACE1"; + filter22 = "SP_FACE2"; + filter23 = "SW1SKIN"; + filter24 = "SW1SKULL"; + filter25 = "SW2SKIN"; + filter26 = "SW2SKULL"; + } + + + set7 + { + name = "Switches"; + filter0 = "SW1*"; + filter1 = "SW2*"; + } + + + set8 + { + name = "Marble"; + filter0 = "DEM1_*"; + filter1 = "FLOOR7_2"; + filter2 = "GST*"; + filter3 = "MARB*"; + filter4 = "SP_DUDE1"; + filter5 = "SP_DUDE2"; + filter6 = "SP_DUDE4"; + filter7 = "SP_DUDE5"; + filter8 = "SP_HOT1"; + filter9 = "SW1GSTON"; + filter10 = "SW1MARB"; + filter11 = "SW2GSTON"; + filter12 = "SW2MARB"; + } + + + set9 + { + name = "Lights"; + filter0 = "BRICKLIT"; + filter1 = "BSTONE3"; + filter2 = "CEIL1_2"; + filter3 = "CEIL1_3"; + filter4 = "CEIL3_4"; + filter5 = "CEIL3_6"; + filter6 = "CEIL4_3"; + filter7 = "FLAT17"; + filter8 = "FLAT2"; + filter9 = "FLAT22"; + filter10 = "FLOOR1_7"; + filter11 = "GRNLITE1"; + filter12 = "LITE3"; + filter13 = "LITE5"; + filter14 = "LITEBLU1"; + filter15 = "LITEBLU4"; + filter16 = "TLITE6_1"; + filter17 = "TLITE6_4"; + filter18 = "TLITE6_5"; + filter19 = "TLITE6_6"; + } + + + set10 + { + name = "Metal"; + filter0 = "CEIL1_2"; + filter1 = "METAL*"; + filter2 = "METAL"; + filter3 = "MIDBRN1"; + filter4 = "MIDGRATE"; + filter5 = "SW1GARG"; + filter6 = "SW1LION"; + filter7 = "SW1SATYR"; + filter8 = "SW2GARG"; + filter9 = "SW2LION"; + filter10 = "SW2MET2"; + filter11 = "SW2METAL"; + filter12 = "SW1METAL"; + filter13 = "SW1MET2"; + filter14 = "SW2SATYR"; + filter15 = "WOODMET1"; + filter16 = "WOODMET2"; + filter17 = "WOODMET3"; + filter18 = "WOODMET4"; + filter19 = "SW2WDMET"; + filter20 = "SW1WDMET"; + filter21 = "SUPPORT*"; + } + + + set11 + { + name = "Silver"; + filter0 = "BIGDOOR1"; + filter1 = "DOORSTOP"; + filter2 = "LITEBLU1"; + filter3 = "SHAWN*"; + filter4 = "SILVER*"; + filter5 = "SPCDOOR3"; + filter6 = "STEP4"; + filter7 = "SUPPORT2"; + filter8 = "SW1COMM"; + filter9 = "SW2COMM"; + } + + + set12 + { + name = "Base"; + filter0 = "BIGBRIK*"; + filter1 = "BIGDOOR1"; + filter2 = "BIGDOOR2"; + filter3 = "BIGDOOR3"; + filter4 = "BIGDOOR4"; + filter5 = "BLAKWAL*"; + filter6 = "BRN*"; + filter7 = "BRONZE*"; + filter8 = "BROWN*"; + filter9 = "BROVINE2"; + filter10 = "CEIL3_1"; + filter11 = "CEIL3_2"; + filter12 = "CEIL3_3"; + filter13 = "CEIL3_4"; + filter14 = "CEIL3_5"; + filter15 = "CEIL3_6"; + filter16 = "CEIL4_1"; + filter17 = "CEIL4_2"; + filter18 = "CEIL4_3"; + filter19 = "CEIL5_1"; + filter20 = "CEIL5_2"; + filter21 = "CEMENT*"; + filter22 = "COMP*"; + filter23 = "CONS*"; + filter24 = "CRAT*"; + filter25 = "DOOR1"; + filter26 = "DOOR3"; + filter27 = "DOORBLU"; + filter28 = "DOORRED"; + filter29 = "DOORSTOP"; + filter30 = "DOORTRAK"; + filter31 = "DOORYEL"; + filter32 = "EXITDOOR"; + filter33 = "EXITSIGN"; + filter34 = "EXITSTON"; + filter35 = "FLAT1"; + filter36 = "FLAT1_1"; + filter37 = "FLAT1_2"; + filter38 = "FLAT1_3"; + filter39 = "FLAT14"; + filter40 = "FLAT17"; + filter41 = "FLAT18"; + filter42 = "FLAT19"; + filter43 = "FLAT2"; + filter44 = "FLAT20"; + filter45 = "FLAT22"; + filter46 = "FLAT23"; + filter47 = "FLAT3"; + filter48 = "FLAT4"; + filter49 = "FLAT5"; + filter50 = "FLAT5_4"; + filter51 = "FLAT5_5"; + filter52 = "FLAT8"; + filter53 = "FLAT9"; + filter54 = "FLOOR0_1"; + filter55 = "FLOOR0_2"; + filter56 = "FLOOR0_3"; + filter57 = "FLOOR0_5"; + filter58 = "FLOOR0_6"; + filter59 = "FLOOR0_7"; + filter60 = "FLOOR1_1"; + filter61 = "FLOOR1_6"; + filter62 = "FLOOR1_7"; + filter63 = "FLOOR3_3"; + filter64 = "FLOOR4_1"; + filter65 = "FLOOR4_5"; + filter66 = "FLOOR4_6"; + filter67 = "FLOOR4_8"; + filter68 = "FLOOR5_1"; + filter69 = "FLOOR5_2"; + filter70 = "FLOOR5_3"; + filter71 = "FLOOR5_4"; + filter72 = "FLOOR7_1"; + filter73 = "GRAY*"; + filter74 = "ICKWALL*"; + filter75 = "LITE*"; + filter76 = "METAL"; + filter77 = "METAL1"; + filter78 = "METAL2"; + filter79 = "METAL3"; + filter80 = "METAL4"; + filter81 = "METAL5"; + filter82 = "METAL6"; + filter83 = "METAL7"; + filter84 = "MFLR8_1"; + filter85 = "MIDBARS1"; + filter86 = "MIDBARS3"; + filter87 = "MIDBRONZ"; + filter88 = "MIDSPACE"; + filter89 = "MODWALL*"; + filter90 = "NUKE*"; + filter91 = "PIPES"; + filter92 = "PIPEWAL1"; + filter93 = "PIPEWAL2"; + filter94 = "PLAT1"; + filter95 = "RROCK14"; + filter96 = "SHAWN*"; + filter97 = "SILVER*"; + filter98 = "SLAD*"; + filter99 = "SLIME13"; + filter100 = "SLIME14"; + filter101 = "SLIME15"; + filter102 = "SLIME16"; + filter103 = "SPACE*"; + filter104 = "SPCDOOR*"; + filter105 = "STAR*"; + filter106 = "STEP*"; + filter107 = "STONE"; + filter108 = "STONE2"; + filter109 = "STONE3"; + filter110 = "SUPPORT2"; + filter111 = "SUPPORT3"; + filter112 = "SW1BLUE"; + filter113 = "SW1BRCOM"; + filter114 = "SW1BRIK"; + filter115 = "SW1BRN1"; + filter116 = "SW1BRN2"; + filter117 = "SW1BRNGN"; + filter118 = "SW1BROWN"; + filter119 = "SW1CMT"; + filter120 = "SW1COMM"; + filter121 = "SW1COMP"; + filter122 = "SW1DIRT"; + filter123 = "SW1EXIT"; + filter124 = "SW1GRAY"; + filter125 = "SW1GRAY1"; + filter126 = "SW1MET2"; + filter127 = "SW1METAL"; + filter128 = "SW1MOD1"; + filter129 = "SW1SLAD"; + filter130 = "SW1STARG"; + filter131 = "SW1STON1"; + filter132 = "SW1STON2"; + filter133 = "SW1STONE"; + filter134 = "SW1STRTN"; + filter135 = "SW1TEK"; + filter136 = "SW1VINE"; + filter137 = "SW2BLUE"; + filter138 = "SW2BRCOM"; + filter139 = "SW2BRIK"; + filter140 = "SW2BRN1"; + filter141 = "SW2BRN2"; + filter142 = "SW2BRNGN"; + filter143 = "SW2BROWN"; + filter144 = "SW2CMT"; + filter145 = "SW2COMM"; + filter146 = "SW2COMP"; + filter147 = "SW2DIRT"; + filter148 = "SW2EXIT"; + filter149 = "SW2GRAY"; + filter150 = "SW2GRAY1"; + filter151 = "SW2MET2"; + filter152 = "SW2METAL"; + filter153 = "SW2MOD1"; + filter154 = "SW2SLAD"; + filter155 = "SW2STARG"; + filter156 = "SW2STON1"; + filter157 = "SW2STON2"; + filter158 = "SW2STONE"; + filter159 = "SW2STRTN"; + filter160 = "SW2TEK"; + filter161 = "SW2VINE"; + filter162 = "TEK*"; + filter163 = "TLITE*"; + filter164 = "PIPE1"; + filter165 = "PIPE2"; + filter166 = "PIPE4"; + filter167 = "PIPE6"; + filter168 = "STUCCO*"; + filter169 = "STUCCO"; + } + + + set13 + { + name = "Hell"; + filter0 = "BFALL*"; + filter1 = "BIGDOOR5"; + filter2 = "BIGDOOR6"; + filter3 = "BIGDOOR7"; + filter4 = "BLODRIP*"; + filter5 = "BLOOD1"; + filter6 = "BLOOD2"; + filter7 = "BLOOD3"; + filter8 = "CEIL1_2"; + filter9 = "CEIL1_3"; + filter10 = "CEIL1_1"; + filter11 = "BSTONE1"; + filter12 = "BSTONE2"; + filter13 = "BSTONE3"; + filter14 = "CRACKLE2"; + filter15 = "CRACKLE4"; + filter16 = "DOORBLU2"; + filter17 = "DOORRED2"; + filter18 = "DOORYEL2"; + filter19 = "FIRE*"; + filter20 = "FLAT1_1"; + filter21 = "FLAT1_2"; + filter22 = "FLAT1_3"; + filter23 = "FLAT5_1"; + filter24 = "FLAT5_2"; + filter25 = "FLAT5_3"; + filter26 = "FLAT5_6"; + filter27 = "FLAT5_7"; + filter28 = "FLAT5_8"; + filter29 = "FLOOR1_6"; + filter30 = "FLOOR1_7"; + filter31 = "FLOOR6_1"; + filter32 = "FLOOR6_2"; + filter33 = "GATE*"; + filter34 = "GST*"; + filter35 = "LAVA*"; + filter36 = "MARB*"; + filter37 = "METAL"; + filter38 = "MFLR8_2"; + filter39 = "MFLR8_3"; + filter40 = "MIDBRN1"; + filter41 = "MIDGRATE"; + filter42 = "REDWALL"; + filter43 = "ROCKRED1"; + filter44 = "ROCKRED2"; + filter45 = "ROCKRED3"; + filter46 = "RROCK01"; + filter47 = "RROCK02"; + filter48 = "RROCK03"; + filter49 = "RROCK04"; + filter50 = "RROCK05"; + filter51 = "RROCK06"; + filter52 = "RROCK07"; + filter53 = "RROCK08"; + filter54 = "RROCK09"; + filter55 = "RROCK10"; + filter56 = "RROCK11"; + filter57 = "RROCK12"; + filter58 = "RROCK15"; + filter59 = "SFLR6_1"; + filter60 = "SFLR6_4"; + filter61 = "SFLR7_1"; + filter62 = "SFLR7_4"; + filter63 = "SK_LEFT"; + filter64 = "SK_RIGHT"; + filter65 = "SKIN*"; + filter66 = "SKSNAKE1"; + filter67 = "SKSNAKE2"; + filter68 = "SKSPINE1"; + filter69 = "SKSPINE2"; + filter70 = "SLIME09"; + filter71 = "SLIME10"; + filter72 = "SLIME11"; + filter73 = "SLIME12"; + filter74 = "SLOPPY1"; + filter75 = "SLOPPY2"; + filter76 = "SP_*"; + filter77 = "SUPPORT3"; + filter78 = "SW1GARG"; + filter79 = "SW1GSTON"; + filter80 = "SW1HOT"; + filter81 = "SW1LION"; + filter82 = "SW1MARB"; + filter83 = "SW1SATYR"; + filter84 = "SW1SKIN"; + filter85 = "SW1SKULL"; + filter86 = "SW1WDMET"; + filter87 = "SW1WOOD"; + filter88 = "SW2GARG"; + filter89 = "SW2GSTON"; + filter90 = "SW2HOT"; + filter91 = "SW2LION"; + filter92 = "SW2MARB"; + filter93 = "SW2SATYR"; + filter94 = "SW2SKIN"; + filter95 = "SW2SKULL"; + filter96 = "SW2WDMET"; + filter97 = "SW2WOOD"; + filter98 = "WOOD*"; + } + + + set14 + { + name = "Outdoors"; + filter0 = "ASHWALL*"; + filter1 = "BFALL*"; + filter2 = "FLAT10"; + filter3 = "FLAT5_7"; + filter4 = "FLAT5_8"; + filter5 = "FLOOR6_1"; + filter6 = "FLOOR6_2"; + filter7 = "FWATER*"; + filter8 = "GRASS*"; + filter9 = "LAVA*"; + filter10 = "MFLR8_2"; + filter11 = "MFLR8_3"; + filter12 = "MFLR8_4"; + filter13 = "NUKAGE*"; + filter14 = "ROCK4"; + filter15 = "ROCK5"; + filter16 = "ROCKRED1"; + filter17 = "ROCKRED2"; + filter18 = "ROCKRED3"; + filter19 = "RROCK01"; + filter20 = "RROCK02"; + filter21 = "RROCK03"; + filter22 = "RROCK04"; + filter23 = "RROCK05"; + filter24 = "RROCK06"; + filter25 = "RROCK07"; + filter26 = "RROCK08"; + filter27 = "RROCK16"; + filter28 = "RROCK17"; + filter29 = "RROCK18"; + filter30 = "RROCK19"; + filter31 = "RROCK20"; + filter32 = "SFALL*"; + filter33 = "SLIME01"; + filter34 = "SLIME02"; + filter35 = "SLIME03"; + filter36 = "SLIME04"; + filter37 = "SLIME05"; + filter38 = "SLIME06"; + filter39 = "SLIME07"; + filter40 = "SLIME08"; + filter41 = "SLIME09"; + filter42 = "SLIME10"; + filter43 = "SLIME11"; + filter44 = "SLIME12"; + filter45 = "SP_ROCK1"; + filter46 = "STONE4"; + filter47 = "STONE5"; + filter48 = "STONE6"; + filter49 = "STONE7"; + filter50 = "TANROCK5"; + filter51 = "TANROCK8"; + filter52 = "ZIMMER*"; + } + + + set15 + { + name = "Computer"; + filter0 = "COMP*"; + filter1 = "CONS*"; + filter2 = "SILVER3"; + filter3 = "SPACEW3"; + filter4 = "SW1COMP"; + filter5 = "SW2COMP"; + } +} +*/ + +/* Better version +texturesets +{ + set0 + { + name = "Greenflower Zone Flats & Textures"; + filter0 = "GFZFLR02"; + filter1 = "GFZFLR10"; + filter2 = "GFZGRASS"; + filter3 = "GFZGRSw"; + filter4 = "FWATER1"; + filter5 = "CFALL1"; + filter6 = "GFALL1"; + filter7 = "GFZFLR01"; + filter8 = "GFZROCK"; + filter9 = "GFZCRACK"; + filter10 = "GFZINSID"; + filter11 = "GFZVINES"; + filter12 = "GFZVCRCK"; + filter13 = "GFZFLR05"; + filter14 = "GFZFLR06"; + filter15 = "GFZFLR09"; + filter16 = "GFZBRIDG"; + filter17 = "GFZBLOCK"; + filter18 = "GFZFLR03"; + filter19 = "GFZFLR04"; + filter20 = "GFZBRICK"; + filter21 = "GFZDOOR"; + filter22 = "GFZWINDW"; + filter23 = "GFZROOF"; + filter31 = "FLOOR0_2"; + filter32 = "GFZFLR07"; + filter33 = "DEM1_5"; + filter34 = "GFZFENC2"; + } + + set1 + { + name = "Techno Hill Zone Flats & Textures"; + filter0 = "THZFLR01"; + filter1 = "THZFLR02"; + filter2 = "THZFLR03"; + filter3 = "THZFLR04"; + filter4 = "THZFLR05"; + filter5 = "THZFLR08"; + filter6 = "THZFLR19"; + filter7 = "THZFLR24"; + filter8 = "THZFLR27"; + filter9 = "THZWAL01"; + filter10 = "THZWAL02"; + filter11 = "THZWAL03"; + filter12 = "THZWAL04"; + filter13 = "THZWAL05"; + filter14 = "THZWAL09"; + filter15 = "THZSTONE"; + filter16 = "THZTILE"; + filter17 = "THZBLOK1"; + filter18 = "THZREACT"; + filter19 = "THZVINES"; + filter20 = "THZFLR30"; + filter21 = "THZROCK"; + filter22 = "THZCRACK"; + filter23 = "THZMECH1"; + filter24 = "THZMECH2"; + filter25 = "THZMECH3"; + filter26 = "CHEMG01"; + filter27 = "TFALL1"; + filter28 = "ALTBOXF1"; + filter29 = "THZBOXF1"; + filter30 = "ALTBOX01"; + filter31 = "THZBOX01"; + filter32 = "BOXWARNG"; + filter33 = "BOXWARN2"; + filter34 = "THZFLR06"; + filter35 = "THZFLR09"; + filter36 = "THZFLR11"; + filter37 = "THZFLR13"; + filter38 = "THZFLR21"; + filter39 = "THZFLR07"; + filter40 = "THZFLR10"; + filter41 = "THZFLR12"; + filter42 = "THZFLR20"; + filter43 = "THZFLR28"; + filter44 = "PIPE2F"; + filter45 = "PIPE3F"; + filter46 = "THZFLR22"; + filter47 = "THZFLR23"; + filter48 = "PIPE2"; + filter49 = "PIPE3"; + filter50 = "THZPIPE1"; + filter51 = "THZPIPE2"; + filter52 = "PISTON"; + filter53 = "THZPIPE"; + filter54 = "THZFLR16"; + filter55 = "THZFLR17"; + filter56 = "THZFLR25"; + filter57 = "THZFLR26"; + filter58 = "THZCONV1"; + filter59 = "THZCONv2"; + filter60 = "WHZFLR16"; + filter61 = "WHZFLR17"; + filter62 = "THZFLR18"; + filter63 = "THZFLR29"; + filter64 = "BARLSIDE"; + filter65 = "BARREL2"; + filter66 = "BARREL3"; + } +}*/ diff --git a/extras/conf/srb2.wcf b/extras/conf/srb2.wcf new file mode 100644 index 000000000..b474633da --- /dev/null +++ b/extras/conf/srb2.wcf @@ -0,0 +1,576 @@ + +; Defines general parameters of the game for which wadfiles are intended. +; +; Name textual name for internal use +; IWAD standard 8.3 base name and extension of main wadfile +; NewMap default name for new map -- dictates format for all maps +; Directory directory in which main wadfile (and game files) reside +; Run command to execute (from the directory) for running a map + +[WadGame] +Name=Sonic Robo Blast 2 +IWAD=srb2.srb +NewMap=MAP01 +Directory=C:\Documents and Settings\Ben\My Documents\srb2 +Run=fd\srb2win.exe -file $_Wadfile -warp $_Wadmap + +; Defines parameters of the default sector motif created when no motif +; file can be located at startup. + +[Default.Sector] +Above=GFZROCK +Main=GFZROCK +Below=GFZROCK +Ceiling=F_SKY1 +Floor=FLOOR0_6 +CeilingHeight=4096 +FloorHeight=0 +Lighting=255 + +; Defines parameters of the default door motif created when no motif +; file can be located at startup. + +[Default.Door] +Base=FLAT1 +Door=BIGDOOR2 +Track=DOORTRAK +Type=1 + +; Defines parameters of the default stair motif created when no motif +; file can be located at startup. + +[Default.Stair] +FloorRunner=GFZROCK +CeilingRunner=GFZROCK +Stairwell=GFZROCK +FloorInc=8 +CeilingInc=0 +LightingInc=0 + +; ID used to classify things +; Flags supplies some additional information: +; 0x0001 - indicate thing facing angle +; Red red value for drawing things of said class +; Green green value for drawing things of said class +; Blue blue value for drawing things of said class +; Name textual description of class + +[Things.Classes] +0x001 0x0001 255 255 255 Starts +0x002 0x0000 192 0 224 Emeralds +0x003 0x0001 255 0 0 Enemies +0x004 0x0000 255 192 0 Nights Things +0x005 0x0000 0 192 192 Power-Up Monitors +0x006 0x0000 192 0 224 Misc. +0x007 0x0000 192 192 192 Scenery +0x008 0x0000 255 255 0 Mario +0x009 0x0000 255 192 224 Christmas +0x00b 0x0000 0 0 255 Rings +0x00c 0x0000 0 224 0 Springs and Such + +; ID used to uniquely identify things in a map +; Class classification (defined above section) +; Size approximate thing size (in map units) +; Sprite name of the sprite to use for display purposes +; Name textual description of thing + +[Things.Types] +0x001 1 32 suptd0 Player 01 Start +0x002 1 32 suptd0 Player 02 Start +0x003 1 32 suptd0 Player 03 Start +0x004 1 32 suptd0 Player 04 Start +0xfa1 1 32 suptd0 Player 05 Start +0xfa2 1 32 suptd0 Player 06 Start +0xfa3 1 32 suptd0 Player 07 Start +0xfa4 1 32 suptd0 Player 08 Start +0xfa5 1 32 suptd0 Player 09 Start +0xfa6 1 32 suptd0 Player 10 Start +0xfa7 1 32 suptd0 Player 11 Start +0xfa8 1 32 suptd0 Player 12 Start +0xfa9 1 32 suptd0 Player 13 Start +0xfaa 1 32 suptd0 Player 14 Start +0xfab 1 32 suptd0 Player 15 Start +0xfac 1 32 suptd0 Player 16 Start +0xfad 1 32 suptd0 Player 17 Start +0xfae 1 32 suptd0 Player 18 Start +0xfaf 1 32 suptd0 Player 19 Start +0xfb0 1 32 suptd0 Player 20 Start +0xfb1 1 32 suptd0 Player 21 Start +0xfb2 1 32 suptd0 Player 22 Start +0xfb3 1 32 suptd0 Player 23 Start +0xfb4 1 32 suptd0 Player 24 Start +0xfb5 1 32 suptd0 Player 25 Start +0xfb6 1 32 suptd0 Player 26 Start +0xfb7 1 32 suptd0 Player 27 Start +0xfb8 1 32 suptd0 Player 28 Start +0xfb9 1 32 suptd0 Player 29 Start +0xfba 1 32 suptd0 Player 30 Start +0xfbb 1 32 suptd0 Player 31 Start +0xfbc 1 32 suptd0 Player 32 Start +0x057 1 32 suptd0 CTF Team Start (Red) +0x059 1 32 suptd0 CTF Team Start (Blue) +0x00b 1 32 suptd0 Deathmatch Start +0x1a4 2 20 cemga0 Emerald 1 (Green) +0x1a5 2 20 cemoa0 Emerald 2 (Orange) +0x1a6 2 20 cempa0 Emerald 3 (Pink) +0x1a7 2 20 cemba0 Emerald 4 (Blue) +0x1a8 2 20 cemra0 Emerald 5 (Red) +0x1a9 2 20 cemla0 Emerald 6 (Light Blue) +0x1aa 2 20 cemga0 Emerald 7 (Grey) +0x1ab 2 20 cemka0 Emerald 8 (Master) +0x009 3 40 sposa1 Crawla (Red) +0xbbc 3 40 possa1 Crawla (Blue) +0x02a 3 40 tfogi0 Pop-up Turret +0xbbd 3 40 jetba1 Jetty-Syn Bomber +0x016 3 40 jetga1 Jetty-Syn Gunner +0x03a 3 40 fisha0 Stupid Dumb Unnamed Robofish (tm) +0x047 3 40 detna1 Deton +0x038 3 40 skima0 Skim +0x7d4 3 40 treta1 THZ Turret +0x010 3 80 eggma1 Egg Mobile (Boss 1) +0x7d8 3 80 eggna1 Egg Slimer (Boss 2) +0x015 3 40 ccoma1 Crawla Commander +0x008 3 40 tfogi0 Chaos Mode Enemy Spawn +0x138d 3 40 buzza0 Gold Buzz +0x138e 3 40 rbuza0 Red Buzz +0x034 4 20 dissa0 1024 Axis +0x035 4 20 dissa0 512 Axis +0x03b 4 20 dissa0 2048 Axis +0x03e 4 20 dissa0 1024 Axis (Inverted) +0x00f 4 20 dissa0 512 Axis (Inverted) +0x02d 4 20 dissa0 2048 Axis (Inverted) +0x03d 4 20 dissa0 Axis Transfer +0x02e 4 20 dissa0 Axis Transfer Closest +0x037 4 20 dissa0 Axis Transfer LastToFirst +0x03c 4 20 ndrna1 Ideya Drone +0x039 4 20 hoopa0 Hoop +0x02f 4 20 bon1a0 Circle of Rings +0x7d7 4 20 bon1a0 Circle of Rings (Big) +0x800 4 20 nwnga0 Circle of Wing Logos +0x7da 4 20 nwnga0 Circle of Wing Logos (Big) +0x7fe 4 20 nwnga0 Circle of Rings and Wings +0x7ff 4 20 nwnga0 Circle of Rings and Wings (Big) +0x025 4 20 nwnga0 Wing Logo +0x052 4 20 dissa0 Axis Transfer Condition +0x055 4 20 dissa0 Axis Transfer Condition 2 +0xbbf 4 20 npraa0 Super Loop +0xbc0 4 20 nprba0 Drill Refill +0xbc1 4 20 nprca0 Helper +0x019 5 20 shtva0 Super Sneakers +0x023 5 20 whtva0 Whirlwind Shield +0x029 5 20 prupa0 Extra Life +0x030 5 20 yltva0 Attraction Shield +0x7d2 5 20 rdtva0 Inferno Shield +0x7e2 5 20 bktva0 Armageddon Shield +0x7e6 5 20 pinva0 Invincibility +0x7ec 5 20 bltva0 Liquid Shield +0x7db 5 20 srbxa0 Super Ring (10 Rings) +0x7dc 5 20 grbxa0 Silver Ring (25 Rings) +0x04e 5 20 mixua0 Teleporter +0x7d5 5 20 eggba0 Eggman +0xbb8 5 20 quesa0 Random +0x01f 6 20 rflga0 CTF Flag (Red) +0x022 6 20 bflga0 CTF Flag (Blue) +0x7dd 6 20 tokea0 Special Stage Token +0x056 6 20 signd0 End Level Sign +0x021 6 20 bubla0 Air Bubble Patch +0x040 6 20 emera0 Emerald Hunt Location 1 +0xbba 6 20 emera0 Emerald Hunt Location 2 +0xbb9 6 20 emera0 Emerald Hunt Location 3 +0xbbe 6 20 stpta0 Star Post +0x1389 6 20 ppsha0 Push +0x138a 6 20 pplla0 Pull +0x138b 6 20 dissa0 Teleport Destination +0x138f 6 20 dissa0 Cut-Away View +0x043 6 20 dspka0 Ceiling Spike +0x044 6 20 uspka0 Floor Spike +0x017 6 20 spika0 Spikeball (Special Stage) +0x011 6 20 dissa0 Boss Flypoint +0x012 6 20 dissa0 Zoom Tube Waypoint +0x801 6 20 dissa0 Egg Capsule Center +0x033 6 20 lasra0 Laser +0x024 7 20 fwr1b0 GFZ Flower (Normal) +0x046 7 20 fwr2a0 GFZ Sunflower +0x049 7 20 fwr3a0 GFZ Budding Flower +0x04a 7 20 bus1a0 Berry Bush +0x04b 7 20 bus2a0 Bush +0x7f3 7 20 thzpa0 THZ Flower +0x00d 7 20 xms2a0 Palm Tree +0x051 7 20 garga1 Gargoyle +;wtraa0 through wtrha0 are empty sprites, formerly used for the below +0x7ea 7 20 dumba0 Ambient Water SFX 1A (Large) +0x7e8 7 20 dumba0 Ambient Water SFX 1B (Large) +0x7e7 7 20 dumba0 Ambient Water SFX 2A (Medium) +0x7fd 7 20 dumba0 Ambient Water SFX 2B (Medium) +0x053 7 20 dumba0 Ambient Water SFX 3A (Small) +0x7e3 7 20 dumba0 Ambient Water SFX 3B (Small) +0x7e9 7 20 dumba0 Ambient Water SFX 4A (Extra Large) +0x01b 7 20 dumba0 Ambient Water SFX 4B (Extra Large) +0x00e 7 20 dumba0 Random Ambience 1 +0x02b 7 20 dumba0 Random Ambience 2 +0x031 7 20 chana0 Hanging Chain +0x7d6 7 20 alrma0 THZ Alarm +0x7d1 7 20 fwr4a0 CEZ Flower +0x018 7 20 flama0 CEZ Torch +0x7d3 7 20 dissa0 Light Source (MAP92) +0x2710 8 20 gooma0 Overworld Goomba +0x2711 8 20 bgoma0 Underworld Goomba +0x2712 8 20 mus1a0 Bush (Short) +0x2713 8 20 mus2a0 Bush (Tall) +0x2714 8 20 toada0 Toad +0x2715 8 20 coina0 Coin +0x013 8 20 koopa0 King Bowser +0x00a 8 20 shlla0 Koopa Shell +0x00c 8 20 maxea0 Axe +0x032 8 20 ffwra0 Fire Flower +0x01d 8 20 pumaa0 Puma (Mario Fireball) +0x005 9 20 xms1a0 Pole +0x006 9 20 xms3a0 Snowman +0x00d 9 20 xms2a0 Candy Cane +0x054 11 20 bon1a0 5 Vertical Rings (Yellow Spring) +0x02c 11 20 bon1a0 5 Vertical Rings (Red Spring) +0x04c 11 20 bon1a0 5 Diagonal Rings (Yellow Spring) +0x04d 11 20 bon1a0 10 Diagonal Rings (Red Spring) +0x7de 11 20 bon1a0 Ring +0x045 11 20 homra0 Homing Ring +0xbbb 11 20 raila0 Rail Ring +0x01a 11 20 autra0 Automatic Ring +0x036 11 20 bomra0 Explosion Ring +0x050 11 20 infra0 Infinity Ring +0x138c 12 20 sprba0 Blue Spring +0x01c 12 20 sprya0 Yellow Spring (Up) +0x04f 12 20 sprra0 Red Spring (Up) +0x7df 12 20 yspra1 Yellow Spring (Diagonal Up) +0x026 12 20 rspra1 Red Spring (Diagonal Up) +0x014 12 20 ysuda1 Yellow Spring (Diagonal Down) +0x027 12 20 rsuda1 Red Spring (Diagonal Down) +0x041 12 20 sudya0 Yellow Spring (Down) +0x042 12 20 sudra0 Red Spring (Down) +0x01e 12 20 stemd0 THZ Gas Jet +0x020 12 20 fansa0 THZ Fan + +; ID used to classify linedefs +; Name textual description of class +; +; Note: When converting a sector to a door, the linedef types +; available are those in class number two. + +[LineDefs.Classes] +0x001 *Important +0x002 Floor Over Floor +0x003 Linedef Executor +0x004 Plane Movement +0x005 Lighting +0x006 Scroll Effects +0x007 Pushers +0x008 Miscellaneous + +; ID +; class +; codes +; n does NOT require a tag number +; W walk-over activation +; S switch (triggered by player use) +; G gunfire (pistol, shotgun, chaingun) cross or hit line +; 1 the line may be activated once only +; R potentially repeatable activation +; & affected sectors locked out from further changes +; m monster actions can activate the line's effect +; speed +; (slow=1, medium = 2, fast = 3, turbo = 4) +; time +; texture changes +; description + +[LineDefs.Types] +; Commonly used types +0x019 1 - - - - Floor Over Floor: Solid, Opaque, Shadowcasting +0x02d 1 - - - - Floor Over Floor: Water, Translucent +0x010 1 - - - - Colormap + +0x001 2 - - - - Crumbling (No Respawn), Floating, Bobbing +0x002 4 - - - - Continuous Floor/Ceiling Mover +0x003 4 - - - - Continuous Floor Mover +0x004 4 - - - - Continuous Ceiling Mover +0x005 5 - - - - Ceiling Lighting +0x006 4 - - - - Continuous Two-Speed Floor/Ceiling Mover +0x007 4 - - - - Continuous Two-Speed Floor Mover +0x008 4 - - - - Continuous Two-Speed Ceiling Mover +0x009 3 - - - - Trigger Linedef Executor (Race Only, Once) +0x00a 3 - - - - Trigger Linedef Executor (CTF Red Team, Continuous) +0x00b 3 - - - - Trigger Linedef Executor (CTF Red Team, Each Time) +0x00c 3 - - - - Trigger Linedef Executor (CTF Blue Team, Continuous) +0x00d 3 - - - - Trigger Linedef Executor (CTF Blue Team, Each Time) + +0x00f 3 - - - - Trigger Linedef Executor (No More Enemies, Once) +0x010 5 - - - - Colormap + +0x012 8 - - - - Zoom Tube Parameters +0x013 3 - - - - Trigger Linedef Executor (Character Ability, Continuous) +0x014 3 - - - - Trigger Linedef Executor (Character Ability, Each Time) +0x015 3 - - - - Trigger Linedef Executor (Character Ability, Once) + +0x018 4 - - - - Instant Ceiling Raise +0x019 2 - - - - Solid, Opaque, Shadowcasting +0x01a 4 - - - - Instant Floor Lower + +0x021 2 - - - - Solid, Opaque, Non-Shadowcasting +0x022 2 - - - - Floating, Bobbing +0x023 2 - - - - Crumbling (No Respawn) +0x024 2 - - - - Crumbling (Respawn) +0x025 2 - - - - Crumbling (Respawn), Floating +0x026 2 - - - - Bobbing (Air) +0x027 2 - - - - Crumbling (Respawn), Floating, Bobbing +0x028 2 - - - - Crumbling (Respawn), Bobbing (Air) +0x029 2 - - - - Mario Block +0x02a 2 - - - - Crumbling (No Respawn), Floating +0x02b 4 - - - - Crusher 1 (Ceiling to Floor) +0x02c 2 - - - - Solid, Translucent +0x02d 2 - - - - Water, Translucent +0x02e 2 - - - - Fog Block +0x02f 2 - - - - Half Light Block +0x030 2 - - - - Water, Opaque +0x031 2 - - - - Light Block +0x032 4 - - - - Crusher 2 (Floor to Ceiling) +0x033 2 - - - - Solid, No Sides +0x034 2 - - - - Intangible, Translucent +0x035 2 - - - - Laser Block +0x036 2 - - - - Thwomp Block +0x037 2 - - - - Bustable Block +0x038 2 - - - - Quicksand Block +0x039 2 - - - - Solid, Invisible +0x03a 2 - - - - Intangible, Invisible +0x03b 2 - - - - Intangible from Bottom, Opaque +0x03c 5 - - - - Adjustable Pulsating Light +0x03d 5 - - - - Adjustable Flickering Light +0x03e 2 - - - - Intangible, Opaque +0x03f 8 - - - - Camera Scanner +0x040 8 - - - - Per-Sector Gravity +0x041 8 - - - - Speed Pad +0x042 8 - - - - Flat Alignment +0x043 2 - - - - Intangible, Sides Only +0x044 2 - - - - Adjustable Bobbing (Air) +0x045 2 - - - - Solid, Sides Only +0x046 8 - - - - Ideya Time Modifier +0x047 8 - - - - Custom Exit +0x048 2 - - - - Reverse Adjustable Bobbing (Air) +0x049 8 - - - - Disable Linedef +0x04a 2 - - - - Water, Translucent, No Sides +0x04b 2 - - - - Water, Opaque, No Sides +0x04c 2 - - - - Shatter Block +0x04d 2 - - - - Intangible from Bottom, Translucent, No Sides +0x04e 2 - - - - Spin Bust Block +0x04f 2 - - - - Crumbling (Respawn) +0x050 2 - - - - Crumbling (No Respawn) +0x051 2 - - - - Intangible from Bottom, Translucent +0x052 2 - - - - Intangible from Bottom, Crumbling (Respawn), Translucent +0x053 2 - - - - Intangible from Bottom, Crumbling (No Respawn), Translucent +0x054 2 - - - - Spin Bust Block, Translucent +0x055 6 - - - - Scroll Wall First Side Opposite Direction +0x056 2 - - - - Shatter Block, Translucent +0x057 2 - - - - Custom +0x058 4 - - - - Continuously Falling Sector +0x059 2 - - - - Rising, Solid, Opaque, Shadowcasting +0x05a 2 - - - - Rising, Solid, Opaque, Non-shadowcasting +0x05b 2 - - - - Rising, Solid, Translucent +0x05c 2 - - - - Rising, Intangible from Bottom, Opaque +0x05d 2 - - - - Rising, Intangible from Bottom, Translucent +0x05e 2 - - - - Rising, Solid, Invisible +0x05f 3 - - - - Trigger Linedef Executor (Ring Count, Continuous) +0x060 3 - - - - Trigger Linedef Executor (Continuous) +0x061 3 - - - - Trigger Linedef Executor (Each Time) +0x062 3 - - - - Trigger Linedef Executor (Once) +0x063 3 - - - - Trigger Linedef Executor (Ring Count, Once) +0x064 6 - - - - Scroll Wall First Side Left +0x065 3 - - - - Set Tagged Sector's Floor Height/Pic +0x066 3 - - - - Set Tagged Sector's Ceiling Height/Pic +0x067 3 - - - - Set Tagged Sector's Light Level +0x068 3 - - - - Teleport Player to Tagged Sector +0x069 3 - - - - Change Music +0x06a 3 - - - - Move Tagged Sector's Floor +0x06b 3 - - - - Move Tagged Sector's Ceiling +0x06c 3 - - - - Lower Floor by Line +0x06d 3 - - - - Raise Floor by Line +0x06e 3 - - - - Lower Ceiling by Line +0x06f 3 - - - - Raise Ceiling by Line +0x070 3 - - - - Change Tagged Sector's Tag +0x071 3 - - - - Run Script +0x072 3 - - - - Change Front Sector's Tag +0x073 3 - - - - Play SFX +0x074 3 - - - - Stop Plane Movement +0x075 3 - - - - Fade Light Level +0x076 3 - - - - Stop Lighting Effect +0x077 3 - - - - Start Adjustable Fire Flicker +0x078 3 - - - - Start Adjustable Glowing Light +0x079 3 - - - - Cut-Away View +0x07a 3 - - - - Stop Object +0x07b 3 - - - - Change Sky +0x07c 3 - - - - Change Weather +0x07d 3 - - - - Change Object State +0x07e 3 - - - - Stop Object +0x07f 3 - - - - Award Score +0x080 3 - - - - Start Platform Movement +0x081 3 - - - - Crush Ceiling Once +0x082 3 - - - - Crush Floor Once +0x083 3 - - - - Crush Floor And Ceiling Once +0x084 3 - - - - Enable/Disable 2D Mode +0x085 3 - - - - Enable/Disable Gravity Flip +0x086 3 - - - - Award Power-Up +0x087 3 - - - - Change Plane Scroller Direction +0x088 3 - - - - Shatter FOF +0x089 3 - - - - Disable Player Control +0x08a 3 - - - - Change Object Size +0x08b 3 - - - - Change Tagged Linedef Textures +0x08c 3 - - - - Start Metal Sonic Race +0x08d 3 - - - - Unlockable Trigger +0x08e 3 - - - - Change Object Type State +0x08f 3 - - - - Call Lua Function +0x090 3 - - - - Earthquake +0x096 3 - - - - Execute Linedef Executor (from tag) +0x097 3 - - - - Execute Linedef Executor (random range) + +0x0c8 6 - - - - Disp Scroll Ceiling Texture and Carry Objects +0x0c9 6 - - - - Disp Carry Objects on Ceiling +0x0ca 6 - - - - Scroll Ceiling Texture and Carry Objects +0x0cb 6 - - - - Carry Objects on Ceiling +0x0cc 6 - - - - Acc Scroll Ceiling Texture and Carry Objects +0x0cd 6 - - - - Acc Carry Objects on Ceiling + +0x0d5 5 - - - - Floor Lighting +0x0d6 6 - - - - Acc Scroll Ceiling Texture +0x0d7 6 - - - - Acc Scroll Floor Texture +0x0d8 6 - - - - Acc Carry Objects on Floor +0x0d9 6 - - - - Acc Scroll Floor Texture and Carry Objects +0x0da 6 - - - - Acc Scroll Wall According to Linedef + +0x0df 8 - - - - Friction +0x0e0 7 - - - - Wind +0x0e1 7 - - - - Current +0x0e2 7 - - - - Boom Push/Pull Thing +0x0e3 7 - - - - Upwards Current +0x0e4 7 - - - - Downwards Current +0x0e5 7 - - - - Upwards Wind +0x0e6 7 - - - - Downwards Wind + +0x0e8 4 - - - - Activate Floating Platform +0x0e9 4 - - - - Activate Floating Platform (Adjustable Speed) + +0x0f2 8 - - - - Fake Floor + +0x0f5 6 - - - - Disp Scroll Ceiling Texture +0x0f6 6 - - - - Disp Scroll Floor Texture +0x0f7 6 - - - - Disp Carry Objects on Floor +0x0f8 6 - - - - Disp Scroll Floor Texture and Carry Objects +0x0f9 6 - - - - Disp Scroll Wall According to Linedef +0x0fa 6 - - - - Scroll Ceiling Texture +0x0fb 6 - - - - Scroll Floor Texture +0x0fc 6 - - - - Carry Objects on Floor +0x0fd 6 - - - - Scroll Floor Texture and Carry Objects +0x0fe 6 - - - - Scroll Wall According to Linedef +0x0ff 6 - - - - Scroll Texture by Offsets + +[Sectors.Types] +0x001 Blink (random) +0x002 Blink (1/2 second) +0x003 Blink (1 second) +0x004 Spikes +0x005 Death Pit (no camera modifications) +0x006 Space Countdown +0x007 Damage (Fire) +0x008 Light oscillates +0x009 Damage (Special Stage) +0x00a Instant Kill +0x00b Damage (Non-Elemental) +0x00c Blink (1 second synch) +0x00d Blink (1/2 second synch) +0x00e Bouncy Sector (FOF Control Only) + +0x010 Death Pit (camera modifications) +0x011 Light flickers like fire +0x012 Damage (Electrical) + +0x021 Special Stage Goal + +0x100 Ice/Sludge + +0x200 Wind/Current + +0x207 Damage (Fire) and Current + +0x29a Egg Trap Capsule + +0x2b2 Button 1 (Open Door A/700 B/701) +0x2b3 Button 2 (Open Door A/702 B/703) +0x2b4 Button 3 (Open Door A/704 B/705) +0x2b5 Button 4 (Open Door A/706 B/707) +0x2b6 Button 5 (Open Door A/708 B/709) +0x2b7 Button 6 (Open Door A/710 B/711) +0x2b8 Button 7 (Open Door A/712 B/713) +0x2b9 Button 8 (Open Door A/714 B/715) +0x2ba Button 9 (Open Door A/716 B/717) +0x2bb Button 10 (Open Door A/718 B/719) +0x2bc Button 11 (Open Door A/720 B/721) +0x2bd Button 12 (Open Door A/722 B/723) +0x2be Button 13 (Open Door A/724 B/725) +0x2bf Button 14 (Open Door A/726 B/727) +0x2c0 Button 15 (Open Door A/728 B/729) +0x2c1 Button 16 (Open Door A/730 B/731) +0x2c2 Button 17 (Open Door A/732 B/733) +0x2c3 Button 18 (Open Door A/734 B/735) +0x2c4 Button 19 (Open Door A/736 B/737) +0x2c5 Button 20 (Open Door A/738 B/739) +0x2c6 Button 21 (THZ2 A/740 B/741 D/742) +0x2c7 Close Door Blazing (Tag 743) + +0x300 Ice/Sludge and Wind/Current + +0x3c7 Linedef Executor (Emerald Check) +0x3c8 Linedef Executor (NiGHTS Mare) +0x3c9 Super Sonic Transform +0x3ca Check 3DFloors for Linedef Executor +0x3cb Linedef Executor (Pushable Objects) +0x3cc Linedef Executor (No Floor Touch, All Players) +0x3cd Linedef Executor (Floor Touch, All Players) +0x3ce Linedef Executor (No Floor Touch) +0x3cf Linedef Executor (Floor Touch) +0x3d0 Speed Pad (No Spin) +0x3d1 Speed Pad (Spin) +0x3d2 Ring Drainer (Floor Touch) +0x3d3 Spinner +0x3d4 Ring Drainer (No Floor Touch) +0x3d5 Raise Ceiling to Highest (Tag 744) +0x3d6 Exit Sector +0x3d7 Damage (Water) +0x3d8 Damage (Water) and Current +0x3d9 Conveyor Belt +0x3da THZ2 Slime Raise (B/712 S/713 P/714 D/715 S/716) +0x3db No Tag Zone +0x3dc CTF - Red Team Base +0x3dd CTF - Blue Team Base +0x3de Special Stage (Floor=Time) (Ceiling=Rings) +0x3df Custom Gravity +0x3e0 Ramp Sector +0x3e1 Starpost Activator +0x3e2 Finish Line + +0x3e4 Non-Ramp Sector +0x3e5 Fan Sector +0x3e6 Zoom Tube Start +0x3e7 Zoom Tube End + +0x5dc Bustable Block Sprite ROIA +0x5dd Bustable Block Sprite ROIB +0x5de Bustable Block Sprite ROIC +0x5df Bustable Block Sprite ROID +0x5e0 Bustable Block Sprite ROIE +0x5e1 Bustable Block Sprite ROIF +0x5e2 Bustable Block Sprite ROIG +0x5e3 Bustable Block Sprite ROIH +0x5e4 Bustable Block Sprite ROII +0x5e5 Bustable Block Sprite ROIJ +0x5e6 Bustable Block Sprite ROIK +0x5e7 Bustable Block Sprite ROIL +0x5e8 Bustable Block Sprite ROIM +0x5e9 Bustable Block Sprite ROIN +0x5ea Bustable Block Sprite ROIO +0x5eb Bustable Block Sprite ROIP diff --git a/extras/conf/srb2.ygd b/extras/conf/srb2.ygd new file mode 100644 index 000000000..4d93076b8 --- /dev/null +++ b/extras/conf/srb2.ygd @@ -0,0 +1,539 @@ +# Yadex game definition file version 4 +# +# srb2.ygd +# Yadex Game Definitions for Sonic Robo Blast 2 +# See Yadex's doc/ygd.html for the specs. +# + +# File made by Alam_GBC. +# Updated by Graue, 2006-06-19 + +# Yadex has only a few games like "doom2", etc. hardcoded into it. +# Rather than hack the code, since I don't expect to ever edit Doom 2, +# I went into /usr/local/share/games/yadex/1.7.0/ and renamed +# doom2.ygd to doom2_real.ygd, then installed this file as srb2.ygd, +# then made a hard link from doom2.ygd to srb2.ygd; that is: +# ln srb2.ygd /usr/local/share/games/yadex/1.7.0/doom2.ygd + +# If you do that, change "iwad2" in yadex.cfg to point to your copy of +# srb2.srb. + +# It's not the most beautiful thing to do, but it works. Also, Doom 2 +# is the default game, so this way you don't have to do anything +# special when starting Yadex. + +# I claim no copyright on this file. -- Graue + +level_format doom +level_name map01 +picture_format normal +sky_flat sky1 +texture_format normal +texture_lumps normal + +# +# Definition of linedef type groups +# Format is : ldtgroup +# + +ldtgroup e "Linedef Executor" +ldtgroup E "3D Floors" +ldtgroup A "Water" +ldtgroup t "Scroll Effects" +ldtgroup x "Misc." +ldtgroup L "Lighting" +ldtgroup l "Pushers" +ldtgroup P "Plane Movement" + +# +# Definition of linedef types +# Format is : ldt +# must not exceed 16 characters. +# + +# Linedef Executor +ldt 00009 e "Trigger(Race1)" "Trigger (Race, Once) (1.09)" +ldt 00010 e "Trigger(RedCont)" "Trigger (CTF Red Team, Continuous) (1.09)" +ldt 00011 e "Trigger(RedEach)" "Trigger (CTF Red Team, Once per Floor Touch) (1.09)" +ldt 00012 e "Trigger(BluCont)" "Trigger (CTF Blue Team, Continuous) (1.09)" +ldt 00013 e "Trigger(BluEach)" "Trigger (CTF Blue Team, Once per Floor Touch) (1.09)" +ldt 00015 e "Trigger(NoEnemy)" "Trigger (Once when no more enemies) (1.09)" +ldt 00019 e "Trigger(ChrCont)" "Trigger (Character Ability, Continuous) (1.09)" +ldt 00020 e "Trigger(ChrEach)" "Trigger (Character Ability, Once per Floor Touch) (1.09)" +ldt 00021 e "Trigger(Chr1)" "Trigger (Character Ability, Once) (1.09)" +ldt 00095 e "Trigger(RngCont)" "Trigger (Ring Count, Continuous) (1.09)" +ldt 00096 e "Trigger (Cont)" "Trigger (Continuous)" +ldt 00097 e "Trigger (Each)" "Trigger (Once per Floor Touch)" +ldt 00098 e "Trigger (1)" "Trigger (Once)" +ldt 00099 e "Trigger (Rng1)" "Trigger (Ring Count, Once) (1.09)" +ldt 00101 e "Set Floor" "Set Tagged Sector's Floor Height/Flat" +ldt 00102 e "Set Ceiling" "Set Tagged Sector's Ceiling Height/Flat" +ldt 00103 e "Set Light Level" "Set Tagged Sector's Light Level" +ldt 00104 e "Teleport to" "Teleport to Tagged Sector" +ldt 00105 e "Music Change" "Music Change" +ldt 00106 e "Move Floor by FS" "Move Floor by Front Sector (Length=Speed)" +ldt 00107 e "Move Ceil. by FS" "Move Ceiling by Front Sector (Length=Speed)" +ldt 00108 e "Lower Flr by Ld" "Lower Floor by Line (dx=speed, dy=amount)" +ldt 00109 e "Raise Flr by Ld" "Raise Floor by Line (dx=speed, dy=amount)" +ldt 00110 e "Lower Ceil by Ld" "Lower Ceiling by Line (dx=speed, dy=amount)" +ldt 00111 e "Raise Ceil by Ld" "Raise Ceiling by Line (dx=speed, dy=amount)" +ldt 00112 e "Change Clg/T Tag" "Change Calling Sector's Tag (Change Tagged Sector's Tag in 1.09)" +ldt 00113 e "Run Script" "Run Script" +ldt 00114 e "Change FS Tag" "Change Front Sector's Tag" +ldt 00115 e "Play SFX" "Play SFX" +ldt 00116 e "Stop Plane Move" "Stop Plane Movement" +ldt 00117 e "Fade Light to FS" "Fade Light Level to Front Sector (Length=Speed)" +ldt 00118 e "Stop Light FX" "Stop Lighting Effect" +ldt 00119 e "Start Fire Flckr" "Start Adjustable Fire Flicker" +ldt 00120 e "Start Pulsate" "Start Adjustable Pulsating Light" +ldt 00121 e "Cut-Away View" "Cut-Away View" +ldt 00122 e "Stop Object" "Stop Object" +ldt 00123 e "Change Sky" "Change Sky (1.09)" +ldt 00124 e "Change Weather" "Change Weather (1.09)" +ldt 00125 e "Change Obj State" "Change Object State (1.09)" +ldt 00126 e "Award Score" "Award Score (1.09)" +ldt 00127 e "Start Platf Mvmt" "Start Platform Movement" + +# 3D Floors/Blocks +ldt 00001 E "CrumBobFlt NoRet" "Crumbling Floating Bobbing FOF (Never Reappears)" +ldt 00025 E "FOFSoliOpaquShad" "FOF (Solid, Opaque, Shadows)" +ldt 00033 E "FOFSolOpaqNShado" "FOF (Solid, Opaque, No Shadows)" +ldt 00034 E "BobbingFOFWater" "Bobbing Platform (Water)" +ldt 00035 E "CrumblingFOFNRea" "Crumbling FOF (Never Reappears)" +ldt 00036 E "CrumblingFOFReap" "Crumbling FOF (Reappears)" +ldt 00037 E "CrumblingFOFRaps" "Crumbling Floating FOF (Reappears)" +ldt 00038 E "BobbingFOF(Air)" "Bobbing FOF (Air)" +ldt 00039 E "CrumBobbFOF(Rep)" "Crumbling Floating Bobbing FOF (Reappears)" +ldt 00040 E "CrumBobbFOF(Air)" "Crumbling Bobbing FOF (Air)" +ldt 00041 E "Mario Block" "Mario Block" +ldt 00042 E "CrumblingFOF(NR)" "Crumbling Floating FOF (Never Reappears)" +ldt 00044 E "FOFSolidTransluc" "FOF (Solid, Translucent)" +ldt 00046 E "Fog Block" "Fog Block" +ldt 00047 E "Light Block" "Light Block" +ldt 00049 E "2x Light Block" "Double Light Block" +ldt 00051 E "FOFSolid,NoSides" "FOF (Solid, No Sides)" +ldt 00052 E "FOFIntangTranslu" "FOF (Intangible, Translucent)" +ldt 00053 E "Laser Block" "Laser Block" +ldt 00054 E "Thwomp Block" "Thwomp Block" +ldt 00055 E "Bustable Block" "Bustable Block" +ldt 00056 E "Quicksand Block" "Quicksand Block" +ldt 00057 E "FOFSolidInv" "FOF (Solid, Invisible)" +ldt 00058 E "FOFIntangiInvisi" "FOF (Intangible, Invisible)" +ldt 00059 E "Platform" "Platform" +ldt 00062 E "FOFIntangibOpaqu" "FOF (Intangible, Opaque)" +ldt 00067 E "FOFIntaSidesOnly" "FOF (Intangible, Sides Only)" +#removed: ldt 00068 E "AdjBobbFOF(Air)" "Adjustable Bobbing FOF (Air)" +ldt 00069 E "FOFSoliSidesOnly" "FOF (Solid, Sides Only)" +#removed: ldt 00072 E "RevAdjBobFOFAir" "Reverse Adjustable Bobbing FOF (Air)" +ldt 00076 E "Shatter Block" "Shatter Block" +ldt 00077 E "Platf (Trnsl-NS)" "Platform (Translucent, No Sides)" +ldt 00078 E "Spin Bust Block" "Spin Bust Block" +ldt 00079 E "CrumblPlatf(Rep)" "Crumbling Platform (Reappears)" +ldt 00080 E "CrumblPlat(NRep)" "Crumbling Platform (Never Reappears)" +ldt 00081 E "Platform (Trnsl)" "Platform (Translucent)" +ldt 00082 E "CrmPlt(Trns,Rep)" "Crumbling Platform (Translucent, Reappears)" +ldt 00083 E "CrmPlt(Trs,NRep)" "Crumbling Platform (Translucent, Never Reappears)" +ldt 00084 E "SpinBust (Trnsl)" "Spin Bust Block (Translucent)" +ldt 00086 E "Shatter (Trnsl.)" "Shatter Block (Translucent)" +ldt 00087 E "Custom FOF" "Custom FOF (1.09)" +ldt 00089 E "Rising FOF Shado" "Rising FOF (Solid, Opaque, Shadows) (1.09)" +ldt 00090 E "Rising FOF NShad" "Rising FOF (Solid, Opaque, No Shadows) (1.09)" +ldt 00091 E "Rising FOF Trnsl" "Rising FOF (Translucent) (1.09)" +ldt 00092 E "Rising Plat Opaq" "Rising Platform (Opaque) (1.09)" +ldt 00093 E "Rising Plat Trsl" "Rising Platform (Translucent) (1.09)" +ldt 00094 E "Rising FOF SlInv" "Rising FOF (Solid, Invisible) (1.09)" + +# Water +ldt 00045 A "Water (Transl.)" "Water (Translucent)" +ldt 00048 A "Water (Opaque)" "Water (Opaque)" +ldt 00074 A "Water (Trnsl-NS)" "Water (Translucent, No Sides)" +ldt 00075 A "Water (Opaq-NS)" "Water (Opaque, No Sides)" + +# Scroll Effects +ldt 00085 t "Scr Wl Front Opp" "Scroll Wall First Side Opposite Direction" +ldt 00100 t "Scr Wl FrontLeft" "Scroll Wall First Side Left" +ldt 00202 t "Scr&Carry Ceil" "Scroll&Carry Things Sector Ceiling (FOF Conveyor)" +ldt 00203 t "Carry Ceiling" "Carry Things on Sector Ceiling (FOF Conveyor)" +ldt 00214 t "AccScr Ceiling" "Accel Scroll Sector's Ceiling" +ldt 00215 t "AccScr Floor" "Accel Scroll Sector's Floor" +ldt 00216 t "AccCarry Floor" "Accel Carry Things on Floor" +ldt 00217 t "AccScr&Carry Flr" "Accel Scroll Floor & Carry Things" +ldt 00218 t "AccScr Front" "Accel Scroll 1st Side Tagged Line" +ldt 00245 t "RemScr Ceiling" "Remote Scroll Sector's Ceiling" +ldt 00246 t "RemScr Floor" "Remote Scroll Sector's Floor" +ldt 00247 t "RemCarry Floor" "Remote Carry Things on Floor" +ldt 00248 t "RemScr&Carry Flr" "Remote Scroll Floor & Carry Things" +ldt 00249 t "RemScr Front" "Remote Scroll 1st Side Tagged Line" +ldt 00250 t "Scroll Ceiling" "Scroll Sector's Ceiling" +ldt 00251 t "Scroll Floor" "Scroll Sector's Floor" +ldt 00252 t "Carry on Floor" "Carry Things On Sector Floor" +ldt 00253 t "Scroll&Carry Flr" "Scroll&Carry Things Sector Floor" +ldt 00254 t "Scroll Front" "Scroll First Side of Tagged Line" +ldt 00255 t "Scroll by Offset" "Effect Scrolling From XY Offsets" + +# Misc. +ldt 00018 x "Zoom Tube Params" "Zoom Tube Parameters (1.09)" +ldt 00063 x "Camera Scanner" "Camera Scanner" +ldt 00064 x "Sector Gravity" "Per-Sector Gravity" +ldt 00065 x "Speed Pad" "Speed Pad" +ldt 00066 x "Flat Alignment" "Flat Alignment" +ldt 00070 x "IdeyaTimeModify " "Ideya Time Modifier" +ldt 00071 x "Custom Exit" "Custom Exit" +ldt 00073 x "Disable Linedef" "Disable Linedef (main game only)" +ldt 00223 x "Friction" "Friction (Ice>100, Sludge<100)" +ldt 00242 x "Fake Floor" "Fake Floor" + +# Lighting +ldt 00005 L "Ceiling Lighting" "Ceiling Lighting" +ldt 00016 L "Colormap" "Colormap" +ldt 00060 L "AdjPulsLight" "Adjustable Pulsating Light" +ldt 00061 L "AdjFlickLight" "Adjustable Flickering Light" +ldt 00213 L "Floor Lighting" "Floor Lighting" + +# Plane Movement +ldt 00002 P "ContMover F/C" "Continuous Floor/Ceiling Mover" +ldt 00003 P "ContMover Floor" "Continuous Floor Mover" +ldt 00004 P "ContMover Ceilng" "Continuous Ceiling Mover" +ldt 00006 P "Cont2Mover F/C" "Continuous 2-Speed Floor/Ceiling Mover" +ldt 00007 P "Cont2Mover Floor" "Continuous 2-Speed Floor Mover" +ldt 00008 P "Cont2Mover Ceilg" "Continuous 2-Speed Ceiling Mover" +ldt 00024 P "InstCeilingRaise" "Instant Ceiling Raise" +ldt 00026 P "InstFloorLower" "Instant Floor Lower" +ldt 00043 P "Crusher 1 (C2F)" "Crusher 1 (Ceiling to Floor)" +ldt 00050 P "Crusher 2 (F2C)" "Crusher 2 (Floor to Ceiling)" +ldt 00088 P "Continuous Fall" "Continuously Falling Sector (1.09)" +ldt 00232 P "FloatingPlatform" "Floating Platform" +ldt 00233 P "FloatPFAdjuSpeed" "Floating Platform Adjustable Speed" + +# Pushers +ldt 00224 l "Wind Force/Dir" "Wind Force/Direction" +ldt 00225 l "Water Force/Dir" "Water Current Force/Direction" +ldt 00226 l "Boom Push/Pull" "Boom Push/Pull Thing" +ldt 00227 l "Upwards Current" "Upwards Current" +ldt 00228 l "DownwardsCurrent" "Downwards Current" +ldt 00229 l "Upwards Wind" "Upwards Wind" +ldt 00230 l "Downwards Wind" "Downwards Wind" + +# +# Definition of sector types +# Format is : st +# must not exceed 14 characters. +# + +st 00000 "X Normal" "X Normal" +st 00001 "Blink random" "Blink (random)" +st 00002 "Blink halfsec" "Blink (1/2 second)" +st 00003 "Blink oneasec" "Blink (1 second)" +st 00004 "Spikes of Doom" "Spikes" +st 00005 "DeathPit (ncm)" "Death Pit (no camera modifications)" +st 00006 "SpaceCountdown" "Space Countdown" +st 00007 "Fire Damage" "Damage (Fire)" +st 00008 "Lightoscilates" "Light oscillates" +st 00009 "SS Damage" "Damage (Special Stage)" +st 00010 "Instant Kill" "Instant Kill" +st 00011 "Normal Damage" "Damage (Non-elemental)" +st 00012 "Blinks oneasec" "Blink (1 second synch)" +st 00013 "Blinks hafasec" "Blink (1/2 second synch)" +st 00014 "FOF Bouncy Con" "Bouncy Sector (FOF Control Only)" +st 00016 "DeathPit (wcm)" "Death Pit (camera modifications)" +st 00017 "Lightslikefire" "Light flickers like fire" + +st 00018 "Elec Damage" "Damage (Electrical)" + +st 00256 "Ice/Sludge" "Ice/Sludge" + +st 00512 "Wind/Current" "Wind/Current" + +st 00680 "EggCapsule But" "Egg Capsule (Button)" +st 00681 "EggCapsule Top" "Egg Capsule (Top)" +st 00682 "EggCapsule Bot" "Egg Capsule (Bottom)" +st 00683 "EggCapsule Cen" "Egg Capsule (Center)" + +st 00690 "Button 01" "Button 1 (Open Door A/700 B/701)" +st 00691 "Button 02" "Button 2 (Open Door A/702 B/703)" +st 00692 "Button 03" "Button 3 (Open Door A/704 B/705)" +st 00693 "Button 04" "Button 4 (Open Door A/706 B/707)" +st 00694 "Button 05" "Button 5 (Open Door A/708 B/709)" +st 00695 "Button 06" "Button 6 (Open Door A/710 B/711)" +st 00696 "Button 07" "Button 7 (Open Door A/712 B/713)" +st 00697 "Button 08" "Button 8 (Open Door A/714 B/715)" +st 00698 "Button 09" "Button 9 (Open Door A/716 B/717)" +st 00699 "Button 10" "Button 10 (Open Door A/718 B/719)" +st 00700 "Button 11" "Button 11 (Open Door A/720 B/721)" +st 00701 "Button 12" "Button 12 (Open Door A/722 B/723)" +st 00702 "Button 13" "Button 13 (Open Door A/724 B/725)" +st 00703 "Button 14" "Button 14 (Open Door A/726 B/727)" +st 00704 "Button 15" "Button 15 (Open Door A/728 B/729)" +st 00705 "Button 16" "Button 16 (Open Door A/730 B/731)" +st 00706 "Button 17" "Button 17 (Open Door A/732 B/733)" +st 00707 "Button 18" "Button 18 (Open Door A/734 B/735)" +st 00708 "Button 19" "Button 19 (Open Door A/736 B/737)" +st 00709 "Button 20" "Button 20 (Open Door A/738 B/739)" +st 00710 "Button 21" "Button 21 (THZ2 A/740 B/741 D/742)" + +st 00768 "IceSluWindCurr" "Ice/Sludge and Wind/Current" + +st 00974 "Linedefx (NFT)" "Linedef Executor (No Floor Touch)" +st 00975 "Linedefx (WFT)" "Linedef Executor (Floor Touch)" +st 00976 "Speed Pad (NS)" "Speed Pad (No Spin)" +st 00977 "Speed Pad (WS)" "Speed Pad (Spin)" +st 00978 "Ring Drainer" "Ring Drainer" +st 00979 "Spinner" "Spinner" +st 00980 "Ring Drain NFT" "Ring Drainer (No Floor Touch)" # 1.09? +st 00981 "RaiseCeilHghst" "Raise Ceiling to Highest (tag 744) (obsolete)" +st 00982 "Exit" "Exit Sector" +st 00983 "Water Damage" "Damage (Water)" +st 00984 "WaterDm&Curent" "Damage (Water) and Current" +st 00985 "ConveyorBelt" "Conveyor Belt" +st 00986 "Slime Raise" "THZ2 Slime Raise (B/712 W/713 P/714 D/715 S/716)" +st 00987 "No Tag Zone" "No Tag Zone" +st 00988 "CTF - Red" "CTF - Red Team Base" +st 00989 "CTF - Bule" "CTF - Blue Team Base" +st 00990 "SS Control" "Special Stage (Floor=Time) (Ceiling=Rings)" +st 00991 "Custom Gravity" "Custom Gravity" +st 00992 "Ramp" "Ramp Sector (Stairs)" +st 00993 "Starpost Actor" "Starpost Activator" +st 00994 "Hockey - Red" "Hockey - Red Team Goal (Finish Line in 1.09)" +st 00995 "Hockey - Blue" "Hockey - Blue Team Goal (not in 1.09)" +st 00996 "Non-Ramp" "Non-Ramp Sector" +st 00997 "Fan Sector" "Fan Sector" +st 00998 "Zoom Tube Strt" "Zoom Tube Start (1.09)" +st 00999 "Zoom Tube End" "Zoom Tube End (1.09)" +st 01500 "BustSprt ROIA" "Bustable Block Sprite ROIA (1.09)" +st 01501 "BustSprt ROIB" "Bustable Block Sprite ROIB (1.09)" +st 01502 "BustSprt ROIC" "Bustable Block Sprite ROIC (1.09)" +st 01503 "BustSprt ROID" "Bustable Block Sprite ROID (1.09)" +st 01504 "BustSprt ROIE" "Bustable Block Sprite ROIE (1.09)" +st 01505 "BustSprt ROIF" "Bustable Block Sprite ROIF (1.09)" +st 01506 "BustSprt ROIG" "Bustable Block Sprite ROIG (1.09)" +st 01507 "BustSprt ROIH" "Bustable Block Sprite ROIH (1.09)" +st 01508 "BustSprt ROII" "Bustable Block Sprite ROII (1.09)" +st 01509 "BustSprt ROIJ" "Bustable Block Sprite ROIJ (1.09)" +st 01510 "BustSprt ROIK" "Bustable Block Sprite ROIK (1.09)" +st 01511 "BustSprt ROIL" "Bustable Block Sprite ROIL (1.09)" +st 01512 "BustSprt ROIM" "Bustable Block Sprite ROIM (1.09)" +st 01513 "BustSprt ROIN" "Bustable Block Sprite ROIN (1.09)" +st 01514 "BustSprt ROIO" "Bustable Block Sprite ROIO (1.09)" +st 01515 "BustSprt ROIP" "Bustable Block Sprite ROIP (1.09)" + +# +# Definition of thing groups +# Format is : thinggroup +# + +thinggroup b rgb:f/f/f "Starts" +thinggroup e rgb:f/0/0 "Enemies" +thinggroup n rgb:f/b/0 "Nights Things" +thinggroup p rgb:0/b/b "Power-Up Monitors" +thinggroup o rgb:b/0/c "Misc." +thinggroup d rgb:b/b/b "Scenery" +thinggroup m rgb:f/f/0 "Mario" +thinggroup c rgb:f/b/c "Christmas" +thinggroup r rgb:0/0/f "Rings" +thinggroup s rgb:0/c/0 "Springs and Such" + +# +# Definition of things +# Format is : +# thing [] +# must not exceed 19 characters. s for see-thur +# + +# FIXME: replace dissa0 and dumba0 with sprites that are really there + +# FIXME: replace start images of ndrna1 with something better. +# ndrna1 is really the nights drone +#thig 00000 g s ## " " ?????# +thing 00001 b - 32 "Player 01 Start" ndrna1 +thing 00002 b - 32 "Player 02 Start" ndrna1 +thing 00003 b - 32 "Player 03 Start" ndrna1 +thing 00004 b - 32 "Player 04 Start" ndrna1 +thing 04001 b - 32 "Player 05 Start" ndrna1 +thing 04002 b - 32 "Player 06 Start" ndrna1 +thing 04003 b - 32 "Player 07 Start" ndrna1 +thing 04004 b - 32 "Player 08 Start" ndrna1 +thing 04005 b - 32 "Player 09 Start" ndrna1 +thing 04006 b - 32 "Player 10 Start" ndrna1 +thing 04007 b - 32 "Player 11 Start" ndrna1 +thing 04008 b - 32 "Player 12 Start" ndrna1 +thing 04009 b - 32 "Player 13 Start" ndrna1 +thing 04010 b - 32 "Player 14 Start" ndrna1 +thing 04011 b - 32 "Player 15 Start" ndrna1 +thing 04012 b - 32 "Player 16 Start" ndrna1 +thing 04013 b - 32 "Player 17 Start" ndrna1 +thing 04014 b - 32 "Player 18 Start" ndrna1 +thing 04015 b - 32 "Player 19 Start" ndrna1 +thing 04016 b - 32 "Player 20 Start" ndrna1 +thing 04017 b - 32 "Player 21 Start" ndrna1 +thing 04018 b - 32 "Player 22 Start" ndrna1 +thing 04019 b - 32 "Player 23 Start" ndrna1 +thing 04020 b - 32 "Player 24 Start" ndrna1 +thing 04021 b - 32 "Player 25 Start" ndrna1 +thing 04022 b - 32 "Player 26 Start" ndrna1 +thing 04023 b - 32 "Player 27 Start" ndrna1 +thing 04024 b - 32 "Player 28 Start" ndrna1 +thing 04025 b - 32 "Player 29 Start" ndrna1 +thing 04026 b - 32 "Player 30 Start" ndrna1 +thing 04027 b - 32 "Player 31 Start" ndrna1 +thing 04028 b - 32 "Player 32 Start" ndrna1 +thing 00087 b - 32 "CTF Red Team Start" ndrna1 +thing 00089 b - 32 "CTF Blue Team Start" ndrna1 +thing 00011 b - 32 "Deathmatch Start" ndrna1 +#thig 00000 g s ## " " ?????# + +#thig 00000 g s ## " " ?????# +thing 00009 e - 40 "Crawla (Red)" sposa1 +thing 03004 e - 40 "Crawla (Blue)" possa1 +thing 03005 e - 40 "Jetty-Syn Bomber" jetba1 +thing 00022 e - 40 "Jetty-Syn Gunner" jetga1 +thing 00058 e - 40 "Robofish (tm)" fisha0 +thing 00071 e - 40 "Deton" detna1 +thing 00056 e - 40 "Skim" skima0 +thing 05005 e - 40 "Buzz (Yellow)" buzza0 +thing 05006 e - 40 "Buzz (Red)" rbuza0 +thing 02004 e - 40 "THZ Turret" treta1 +thing 00042 e - 40 "Popup Turret" turre1 +thing 00016 e - 80 "Egg Mobile (Boss 1)" eggma1 +thing 01008 e - 80 "Egg Slimer (Boss 2)" eggna1 +thing 00021 e - 40 "Crawla Commander" ccoma1 +thing 00008 e s 20 "ChaosModeEnemySpawn" tfogi0 +#thig 00000 g s ## " " ?????# + +#thig 00000 g s ## " " ?????# +thing 00052 n s 20 "1024 Axis" dissa0 +thing 00053 n s 20 "512 Axis" dissa0 +thing 00059 n s 20 "2048 Axis" dissa0 +thing 00062 n s 20 "1024 Axis(Inverted)" dissa0 +thing 00015 n s 20 "512 Axis (Inverted)" dissa0 +thing 00045 n s 20 "2048 Axis(Inverted)" dissa0 +thing 00061 n s 20 "Axis Transfer" dissa0 +thing 00046 n s 20 "Axis Transfer Closest" dissa0 +thing 00055 n s 20 "Axis Transfer LastToFirst" dissa0 +thing 00060 n - 20 "Ideya Drone" ndrna1 +thing 00057 n - 20 "Hoop" hoopa0 +thing 00047 n - 20 "Circle of Rings" bon1a0 +thing 02007 n - 20 "Circle ofRings(Big)" bon1a0 +thing 02048 n - 20 "Circle ofWing Logos" nwnga0 +thing 02010 n - 20 "CircleofWingLogos-B" nwnga0 +thing 02046 n - 20 "CircleofRings&Wings" nwnga0 +thing 02047 n - 20 "CirleofRngs&Wings-B" nwnga0 +thing 00037 n - 20 "Wing Logo" nwnga0 +thing 00082 n s 20 "AxisTrnsferCodtion" dissa0 +thing 00085 n s 20 "AxisTrnsferCodtion2" dissa0 +thing 03007 n - 20 "Super Loop" npraa0 +thing 03008 n - 20 "Drill Refill" nprba0 +thing 03009 n - 20 "Helper" nprca0 +#thig 00000 g s ## " " ?????# + +#thig 00000 g s ## " " ?????# +thing 00025 p - 20 "Super Sneakers" shtva0 +thing 00035 p - 20 "Basic/WhirlShield" bltva0 +thing 00041 p - 20 "Extra Life" prupa0 +thing 00048 p - 20 "Attraction Shield" yltva0 +thing 02002 p - 20 "Inferno Shield" rdtva0 +thing 02018 p - 20 "Armageddon Shield" bktva0 +thing 02022 p - 20 "Invincibility" pinva0 +thing 02028 p - 20 "Liquid Shield" grtva0 +thing 02011 p - 20 "SuperRing(10 Rings)" srbxa0 +thing 02012 p - 20 "SilverRing(25Rings)" grbxa0 +thing 00078 p - 20 "Teleporter" mixua0 +thing 02005 p - 20 "Eggman" eggba0 +thing 03000 p - 20 "Random" quesa0 +#thig 00000 g s ## " " ?????# + +#thig 00000 g s ## " " ?????# +thing 00031 o - 20 "CTF Flag (Red)" rflga0 +thing 00034 o - 20 "CTF Flag (Blue)" bflga0 +thing 02013 o - 20 "Special Stage Token" tokea0 +thing 00086 o - 20 "End Level Sign" signd0 +thing 00033 o - 20 "Air Bubble Patch" bubla0 +thing 00064 o - 20 "Emerald Hunt Place1" emera0 +thing 03002 o - 20 "Emerald Hunt Place2" emera0 +thing 03001 o - 20 "Emerald Hunt Place3" emera0 +thing 03006 o - 20 "Star Post" stpta0 +thing 05001 o s 20 "Push" ppsha0 +thing 05002 o s 20 "Pull" pplla0 +thing 05003 o s 20 "TeleportDestination" dissa0 +thing 05007 o s 20 "Cut-Away View Thing" dissa0 +thing 00067 o - 20 "Ceiling Spike" dspka0 +thing 00068 o - 20 "Floor Spike" uspka0 +thing 00023 o - 20 "Spikeball" spika0 +thing 00017 o s 20 "Boss Flypoint" dissa0 +thing 02049 o s 20 "Egg Capsule Center" dissa0 +thing 00051 o - 20 "Laser" lasra0 +thing 00018 o - 20 "ZoomTubeWaypoint109" dissa0 +thing 00420 o - 20 "Emerald 1 (Green)" emmya0 +thing 00421 o - 20 "Emerald 2 (Orange)" emmyb0 +thing 00422 o - 20 "Emerald 3 (Pink)" emmyc0 +thing 00423 o - 20 "Emerald 4 (Blue)" emmyd0 +thing 00424 o - 20 "Emerald 5 (Red)" emmye0 +thing 00425 o - 20 "Emerald 6 (LtBlue)" emmyf0 +thing 00426 o - 20 "Emerald 7 (Gray)" emmyg0 +# FIXME: add correct sprite for this emerald +thing 00427 o - 20 "Emerald 8 (Master)" dissa0 + +#thig 00000 g s ## " " ?????# +thing 00036 d - 20 "GFZ Flower (Normal)" fwr1b0 +thing 00070 d - 20 "GFZ Sunflower" fwr2a0 +thing 00073 d - 20 "GFZ Budding Flower" fwr3a0 +thing 00074 d - 20 "Berry Bush" bus1a0 +thing 00075 d - 20 "Bush" bus2a0 +thing 02035 d - 20 "THZ Flower" thzpa0 +thing 00081 d - 20 "Gargoyle" garga1 +thing 02026 d s 20 "AmbientWaterSFX1A-L" dumba0 +thing 02024 d s 20 "AmbientWaterSFX1B-L" dumba0 +thing 02025 d s 20 "AmbientWaterSFX2A-M" dumba0 +thing 02045 d s 20 "AmbientWaterSFX2B-M" dumba0 +thing 00083 d s 20 "AmbientWaterSFX3A-S" dumba0 +thing 02019 d s 20 "AmbientWaterSFX3B-S" dumba0 +thing 02025 d s 20 "AmbientWaterSFX4A-E" dumba0 +thing 00027 d s 20 "AmbientWaterSFX4B-E" dumba0 +thing 00014 d s 20 "Random Ambience 1" dumba0 +thing 00043 d s 20 "Random Ambience 2" dumba0 +thing 00049 d - 20 "Hanging Chain" chana0 +thing 02006 d - 20 "THZ Alarm" alrma0 +thing 02001 d - 20 "CEZ Flower" fwr4a0 +thing 00024 d - 20 "CEZ Torch" flama0 +thing 02003 d s 20 "LightSource (MAP92)" dissa0 +#thig 00000 g s ## " " ?????# + +#thig 00000 g s ## " " ?????# +thing 100000 m - 20 "Overworld Goomba" gooma0 +thing 100001 m - 20 "Underworld Goomba" bgoma0 +thing 100002 m - 20 "Bush (Short)" mus1a0 +thing 100003 m - 20 "Bush (Tall)" mus2a0 +thing 100004 m - 20 "Toad" toada0 +thing 100005 m - 20 "Coin" coina0 +thing 00019 m - 20 "King Bowser" koopa0 +thing 00010 m - 20 "Koopa Shell" shlla0 +thing 00012 m - 20 "Axe" maxea0 +thing 00050 m - 20 "Fire Flower" ffwra0 +thing 00029 m - 20 "Puma(MarioFireball)" pumaa0 +#thig 00000 g s ## " " ?????# + +#thig 00000 g s ## " " ?????# +thing 00005 c - 20 "Pole" xms1a0 +thing 00006 c - 20 "Snowman" xms3a0 +thing 00013 c - 20 "Candy Cane" xms2a0 +thing 00084 r - 20 "5VerticalRings-YwSg" bon1a0 +thing 00044 r - 20 "5VerticalRings-RdSg" bon1a0 +thing 00076 r - 20 "5DiagonalRings-YwSg" bon1a0 +thing 00077 r - 20 "10DiagonalRings-RSg" bon1a0 +thing 02014 r - 20 "Ring" bon1a0 +thing 00069 r - 20 "Homing Ring" homra0 +thing 03003 r - 20 "Rail Ring" raila0 +thing 00026 r - 20 "Automatic Ring" autra0 +thing 00054 r - 20 "Explosion Ring" bomra0 +thing 00080 r - 20 "Infinity Ring" infra0 +thing 00028 s - 20 "Yellow Spring (Up)" sprya0 +thing 00079 s - 20 "Red Spring (Up)" sprra0 +thing 02015 s - 20 "Yellow Spring (DU)" yspra1 +thing 00038 s - 20 "Red Spring (DU)" rspra1 +thing 00020 s - 20 "Yellow Spring (DD)" ysuda1 +thing 00039 s - 20 "Red Spring (DD)" rsuda1 +thing 00065 s - 20 "Yellow Spring (Dn)" sudya0 +thing 00066 s - 20 "Red Spring (Dn)" sudra0 +thing 05004 s - 20 "Blue Spring" sprba0 +thing 00030 s - 20 "THZ Gas Jet" stemd0 +thing 00032 s - 20 "THZ Fan" fansa0 +#thig 00000 g s ## " " ?????# diff --git a/extras/conf/srb2_db.cfg b/extras/conf/srb2_db.cfg new file mode 100644 index 000000000..cad786472 --- /dev/null +++ b/extras/conf/srb2_db.cfg @@ -0,0 +1,1559 @@ +/*******************************************************\ + + XODE Multimedia Doom Builder + + Game Configuration for SRB2 version 2.0 + + Original CFG by Kristos + + Edited by Shadow Hog to eliminate one NASTY map header-eliminating bug + + Edited further by ST218 to make more organized + + Edited by Foxboy to show thing sprite previews and to update it for srb2 1.09.2 and to finally make the linedef and sector types to have the same name as the WA config. + + Edited by JJames19119 to fix parse errors, thing and linedef names, fix borked lindef categories, add the missing PASSUSE + linedef flag and put bitset flags for the lazy :P + + Edited by SRB2-Playah to make Things visable in 3D Mode, add Mario section because I think it'd be more organized, changed + a few names, put in a list of Color Values in the Things section of this CFG, and to put it large lines to make it easier + to find stuff in the CFG and thusly, easier to edit. + Dang, this was just edited to heck, wasn't it? :P + This CFG is best viewed with size 8 font, 1024x768 screen resolution, maximized. + +\*******************************************************/ + +// This is required to prevent accedential use of a different configuration +type = "Doom Builder Game Configuration"; + +// This is the title to show for this game +game = "Sonic Robo Blast 2"; + +// Map format determines the way the map will be loaded +mapformat = 1; + +// No generalized types +generalizedlinedefs = 0; +generalizedsectors = 0; + +// Thing number for start position in 3D Mode +start3dmode = 32000; + +// Load textures/flats by default from this file +texturesfile = ""; + +// Default lump name for new map +defaultlumpname = "MAP01"; + +// Default flags for first new thing +defaulthingflags = 1; + +/* +TEXTURES AND FLAT SOURCES---------------------------------------------------------------------------------------------------- +This tells Doom Builder where to find the information for textures +and flats in the IWAD file, Addition WAD file and Map WAD file. + +Start and end lumps must be given in a structure (of which the +key name doesnt matter) and any textures or flats in between them +are loaded in either the textures category or flats category. + +For textures: PNAMES, TEXTURE1 and TEXTURE2 are loaded by default. +*/ + +// Texture sources +textures +{ +} + +// Flat sources +flats +{ + standard1 + { + start = "F_START"; + end = "F_END"; + } + + standard2 + { + start = "FF_START"; + end = "FF_END"; + } + + standard3 + { + start = "FF_START"; + end = "F_END"; + } + + standard4 + { + start = "F_START"; + end = "FF_END"; + } +} + +/* +TEXTURES AND FLATS FILTERING------------------------------------------------------------------------------------------------- +This allows you to filter textures and flats so that you only see the +textures/flats listed that you prefer to use. + +The key name doesnt matter here, only the values. You can use +the following wildcards in values to specify ranges: + +? = Any character +* = Zero or more characters +# = Any numeric digit +[abc...] = Any of these characters that are between brackets +[!abc..] = Not any of these characters that are between brackets +*/ + +// List these textures... +texturesfilter +{ + all_textures = "*"; +} + +// But do not list these textures... +notexturesfilter +{ + none = ""; +} + +// List these flats... +flatsfilter +{ + all_flats = "*"; +} + +// But do not list these flats... +noflatsfilter +{ + none = ""; +} + +/* +GAME DETECT PATTERN---------------------------------------------------------------------------------------------------------- +Used to guess the game for which a WAD file is made. + +1 = One of these lumps must exist +2 = None of these lumps must exist +3 = All of these lumps must exist +*/ +gamedetect +{ + EXTENDED = 2; + BEHAVIOR = 2; + E1M1 = 2; E1M2 = 2; E1M3 = 2; E1M4 = 2; E1M5 = 2; E1M6 = 2; E1M7 = 2; E1M8 = 2; E1M9 = 2; + E2M1 = 2; E2M2 = 2; E2M3 = 2; E2M4 = 2; E2M5 = 2; E2M6 = 2; E2M7 = 2; E2M8 = 2; E2M9 = 2; + E3M1 = 2; E3M2 = 2; E3M3 = 2; E3M4 = 2; E3M5 = 2; E3M6 = 2; E3M7 = 2; E3M8 = 2; E3M9 = 2; + E4M1 = 2; E4M2 = 2; E4M3 = 2; E4M4 = 2; E4M5 = 2; E4M6 = 2; E4M7 = 2; E4M8 = 2; E4M9 = 2; + MAP01 = 1; MAP02 = 1; MAP03 = 1; MAP04 = 1; MAP05 = 1; MAP06 = 1; MAP07 = 1; MAP08 = 1; MAP09 = 1; MAP10 = 1; + MAP11 = 1; MAP12 = 1; MAP13 = 1; MAP14 = 1; MAP15 = 1; MAP16 = 1; MAP17 = 1; MAP18 = 1; MAP19 = 1; MAP20 = 1; + MAP21 = 1; MAP22 = 1; MAP23 = 1; MAP24 = 1; MAP25 = 1; MAP26 = 1; MAP27 = 1; MAP28 = 1; MAP29 = 1; MAP30 = 1; + MAP31 = 1; MAP32 = 1; MAP33 = 1; MAP34 = 1; MAP35 = 1; MAP36 = 1; MAP37 = 1; MAP38 = 1; MAP39 = 1; MAP40 = 1; + MAP41 = 1; MAP42 = 1; MAP43 = 1; MAP44 = 1; MAP45 = 1; MAP46 = 1; MAP47 = 1; MAP48 = 1; MAP49 = 1; MAP50 = 1; + MAP51 = 1; MAP52 = 1; MAP53 = 1; MAP54 = 1; MAP55 = 1; MAP56 = 1; MAP57 = 1; MAP58 = 1; MAP59 = 1; MAP60 = 1; + MAP61 = 1; MAP62 = 1; MAP63 = 1; MAP64 = 1; MAP65 = 1; MAP66 = 1; MAP67 = 1; MAP68 = 1; MAP69 = 1; MAP70 = 1; + MAP71 = 1; MAP72 = 1; MAP73 = 1; MAP74 = 1; MAP75 = 1; MAP76 = 1; MAP77 = 1; MAP78 = 1; MAP79 = 1; MAP80 = 1; + MAP81 = 1; MAP82 = 1; MAP83 = 1; MAP84 = 1; MAP85 = 1; MAP86 = 1; MAP87 = 1; MAP88 = 1; MAP89 = 1; MAP90 = 1; + MAP91 = 1; MAP92 = 1; MAP93 = 1; MAP94 = 1; MAP95 = 1; MAP96 = 1; MAP97 = 1; MAP98 = 1; MAP99 = 1; +} + +/* +MAP LUMP NAMES--------------------------------------------------------------------------------------------------------------- +Map lumps are loaded with the map as long as they are right after each other. When the editor +meets a lump which is not defined in this list (or defined as 0) it will stop loading right there. + +The order of items defines the order in which lumps will be written to WAD file on save. +The value (flags) of items determines what the editor should do with it. +You should never mess with value 4, because it may result in incorrect map builds. + +1 = Map lump required +2 = Map lump which must be respected +4 = Lump generated by node builder +8 = Lump allowed to be empty after nodebuilding +4096 = Map lump which can be edited as Text +8192 = Map lump which can be edited as ACS +12288 = Map lump which can be edited as MAPINFO +16384 = Map lump which can be edited as DEHACKED +*/ + +maplumpnames +{ + THINGS = 13; + LINEDEFS = 5; + SIDEDEFS = 5; + VERTEXES = 5; + SEGS = 4; + SSECTORS = 4; + NODES = 4; + SECTORS = 5; + REJECT = 4; + BLOCKMAP = 4; + MAINCFG = 2; + // Here it is... all 1035 map headers, all to be "respected" by DoomBuilder... + MAP01D = 4098; MAP02D = 4098; MAP03D = 4098; MAP04D = 4098; MAP05D = 4098; MAP06D = 4098; + MAP07D = 4098; MAP08D = 4098; MAP09D = 4098; MAP10D = 4098; MAP11D = 4098; MAP12D = 4098; + MAP13D = 4098; MAP14D = 4098; MAP15D = 4098; MAP16D = 4098; MAP17D = 4098; MAP18D = 4098; + MAP19D = 4098; MAP20D = 4098; MAP21D = 4098; MAP22D = 4098; MAP23D = 4098; MAP24D = 4098; + MAP25D = 4098; MAP26D = 4098; MAP27D = 4098; MAP28D = 4098; MAP29D = 4098; MAP30D = 4098; + MAP31D = 4098; MAP32D = 4098; MAP33D = 4098; MAP34D = 4098; MAP35D = 4098; MAP36D = 4098; + MAP37D = 4098; MAP38D = 4098; MAP39D = 4098; MAP40D = 4098; MAP41D = 4098; MAP42D = 4098; + MAP43D = 4098; MAP44D = 4098; MAP45D = 4098; MAP46D = 4098; MAP47D = 4098; MAP48D = 4098; + MAP49D = 4098; MAP50D = 4098; MAP51D = 4098; MAP52D = 4098; MAP53D = 4098; MAP54D = 4098; + MAP55D = 4098; MAP56D = 4098; MAP57D = 4098; MAP58D = 4098; MAP59D = 4098; MAP60D = 4098; + MAP61D = 4098; MAP62D = 4098; MAP63D = 4098; MAP64D = 4098; MAP65D = 4098; MAP66D = 4098; + MAP67D = 4098; MAP68D = 4098; MAP69D = 4098; MAP70D = 4098; MAP71D = 4098; MAP72D = 4098; + MAP73D = 4098; MAP74D = 4098; MAP75D = 4098; MAP76D = 4098; MAP77D = 4098; MAP78D = 4098; + MAP79D = 4098; MAP80D = 4098; MAP81D = 4098; MAP82D = 4098; MAP83D = 4098; MAP84D = 4098; + MAP85D = 4098; MAP86D = 4098; MAP87D = 4098; MAP88D = 4098; MAP89D = 4098; MAP90D = 4098; + MAP91D = 4098; MAP92D = 4098; MAP93D = 4098; MAP94D = 4098; MAP95D = 4098; MAP96D = 4098; + MAP97D = 4098; MAP98D = 4098; MAP99D = 4098; + + MAPA0D = 4098; MAPA1D = 4098; MAPA2D = 4098; MAPA3D = 4098; MAPA4D = 4098; MAPA5D = 4098; + MAPA6D = 4098; MAPA7D = 4098; MAPA8D = 4098; MAPA9D = 4098; MAPAAD = 4098; MAPABD = 4098; + MAPACD = 4098; MAPADD = 4098; MAPAED = 4098; MAPAFD = 4098; MAPAGD = 4098; MAPAHD = 4098; + MAPAID = 4098; MAPAJD = 4098; MAPAKD = 4098; MAPALD = 4098; MAPAMD = 4098; MAPAND = 4098; + MAPAOD = 4098; MAPAPD = 4098; MAPAQD = 4098; MAPARD = 4098; MAPASD = 4098; MAPATD = 4098; + MAPAUD = 4098; MAPAVD = 4098; MAPAWD = 4098; MAPAXD = 4098; MAPAYD = 4098; MAPAZD = 4098; + + MAPB0D = 4098; MAPB1D = 4098; MAPB2D = 4098; MAPB3D = 4098; MAPB4D = 4098; MAPB5D = 4098; + MAPB6D = 4098; MAPB7D = 4098; MAPB8D = 4098; MAPB9D = 4098; MAPBAD = 4098; MAPBBD = 4098; + MAPBCD = 4098; MAPBDD = 4098; MAPBED = 4098; MAPBFD = 4098; MAPBGD = 4098; MAPBHD = 4098; + MAPBID = 4098; MAPBJD = 4098; MAPBKD = 4098; MAPBLD = 4098; MAPBMD = 4098; MAPBND = 4098; + MAPBOD = 4098; MAPBPD = 4098; MAPBQD = 4098; MAPBRD = 4098; MAPBSD = 4098; MAPBTD = 4098; + MAPBUD = 4098; MAPBVD = 4098; MAPBWD = 4098; MAPBXD = 4098; MAPBYD = 4098; MAPBZD = 4098; + + MAPC0D = 4098; MAPC1D = 4098; MAPC2D = 4098; MAPC3D = 4098; MAPC4D = 4098; MAPC5D = 4098; + MAPC6D = 4098; MAPC7D = 4098; MAPC8D = 4098; MAPC9D = 4098; MAPCAD = 4098; MAPCBD = 4098; + MAPCCD = 4098; MAPCDD = 4098; MAPCED = 4098; MAPCFD = 4098; MAPCGD = 4098; MAPCHD = 4098; + MAPCID = 4098; MAPCJD = 4098; MAPCKD = 4098; MAPCLD = 4098; MAPCMD = 4098; MAPCND = 4098; + MAPCOD = 4098; MAPCPD = 4098; MAPCQD = 4098; MAPCRD = 4098; MAPCSD = 4098; MAPCTD = 4098; + MAPCUD = 4098; MAPCVD = 4098; MAPCWD = 4098; MAPCXD = 4098; MAPCYD = 4098; MAPCZD = 4098; + + MAPD0D = 4098; MAPD1D = 4098; MAPD2D = 4098; MAPD3D = 4098; MAPD4D = 4098; MAPD5D = 4098; + MAPD6D = 4098; MAPD7D = 4098; MAPD8D = 4098; MAPD9D = 4098; MAPDAD = 4098; MAPDBD = 4098; + MAPDCD = 4098; MAPDDD = 4098; MAPDED = 4098; MAPDFD = 4098; MAPDGD = 4098; MAPDHD = 4098; + MAPDID = 4098; MAPDJD = 4098; MAPDKD = 4098; MAPDLD = 4098; MAPDMD = 4098; MAPDND = 4098; + MAPDOD = 4098; MAPDPD = 4098; MAPDQD = 4098; MAPDRD = 4098; MAPDSD = 4098; MAPDTD = 4098; + MAPDUD = 4098; MAPDVD = 4098; MAPDWD = 4098; MAPDXD = 4098; MAPDYD = 4098; MAPDZD = 4098; + + MAPE0D = 4098; MAPE1D = 4098; MAPE2D = 4098; MAPE3D = 4098; MAPE4D = 4098; MAPE5D = 4098; + MAPE6D = 4098; MAPE7D = 4098; MAPE8D = 4098; MAPE9D = 4098; MAPEAD = 4098; MAPEBD = 4098; + MAPECD = 4098; MAPEDD = 4098; MAPEED = 4098; MAPEFD = 4098; MAPEGD = 4098; MAPEHD = 4098; + MAPEID = 4098; MAPEJD = 4098; MAPEKD = 4098; MAPELD = 4098; MAPEMD = 4098; MAPEND = 4098; + MAPEOD = 4098; MAPEPD = 4098; MAPEQD = 4098; MAPERD = 4098; MAPESD = 4098; MAPETD = 4098; + MAPEUD = 4098; MAPEVD = 4098; MAPEWD = 4098; MAPEXD = 4098; MAPEYD = 4098; MAPEZD = 4098; + + MAPF0D = 4098; MAPF1D = 4098; MAPF2D = 4098; MAPF3D = 4098; MAPF4D = 4098; MAPF5D = 4098; + MAPF6D = 4098; MAPF7D = 4098; MAPF8D = 4098; MAPF9D = 4098; MAPFAD = 4098; MAPFBD = 4098; + MAPFCD = 4098; MAPFDD = 4098; MAPFED = 4098; MAPFFD = 4098; MAPFGD = 4098; MAPFHD = 4098; + MAPFID = 4098; MAPFJD = 4098; MAPFKD = 4098; MAPFLD = 4098; MAPFMD = 4098; MAPFND = 4098; + MAPFOD = 4098; MAPFPD = 4098; MAPFQD = 4098; MAPFRD = 4098; MAPFSD = 4098; MAPFTD = 4098; + MAPFUD = 4098; MAPFVD = 4098; MAPFWD = 4098; MAPFXD = 4098; MAPFYD = 4098; MAPFZD = 4098; + + MAPG0D = 4098; MAPG1D = 4098; MAPG2D = 4098; MAPG3D = 4098; MAPG4D = 4098; MAPG5D = 4098; + MAPG6D = 4098; MAPG7D = 4098; MAPG8D = 4098; MAPG9D = 4098; MAPGAD = 4098; MAPGBD = 4098; + MAPGCD = 4098; MAPGDD = 4098; MAPGED = 4098; MAPGFD = 4098; MAPGGD = 4098; MAPGHD = 4098; + MAPGID = 4098; MAPGJD = 4098; MAPGKD = 4098; MAPGLD = 4098; MAPGMD = 4098; MAPGND = 4098; + MAPGOD = 4098; MAPGPD = 4098; MAPGQD = 4098; MAPGRD = 4098; MAPGSD = 4098; MAPGTD = 4098; + MAPGUD = 4098; MAPGVD = 4098; MAPGWD = 4098; MAPGXD = 4098; MAPGYD = 4098; MAPGZD = 4098; + + MAPH0D = 4098; MAPH1D = 4098; MAPH2D = 4098; MAPH3D = 4098; MAPH4D = 4098; MAPH5D = 4098; + MAPH6D = 4098; MAPH7D = 4098; MAPH8D = 4098; MAPH9D = 4098; MAPHAD = 4098; MAPHBD = 4098; + MAPHCD = 4098; MAPHDD = 4098; MAPHED = 4098; MAPHFD = 4098; MAPHGD = 4098; MAPHHD = 4098; + MAPHID = 4098; MAPHJD = 4098; MAPHKD = 4098; MAPHLD = 4098; MAPHMD = 4098; MAPHND = 4098; + MAPHOD = 4098; MAPHPD = 4098; MAPHQD = 4098; MAPHRD = 4098; MAPHSD = 4098; MAPHTD = 4098; + MAPHUD = 4098; MAPHVD = 4098; MAPHWD = 4098; MAPHXD = 4098; MAPHYD = 4098; MAPHZD = 4098; + + MAPI0D = 4098; MAPI1D = 4098; MAPI2D = 4098; MAPI3D = 4098; MAPI4D = 4098; MAPI5D = 4098; + MAPI6D = 4098; MAPI7D = 4098; MAPI8D = 4098; MAPI9D = 4098; MAPIAD = 4098; MAPIBD = 4098; + MAPICD = 4098; MAPIDD = 4098; MAPIED = 4098; MAPIFD = 4098; MAPIGD = 4098; MAPIHD = 4098; + MAPIID = 4098; MAPIJD = 4098; MAPIKD = 4098; MAPILD = 4098; MAPIMD = 4098; MAPIND = 4098; + MAPIOD = 4098; MAPIPD = 4098; MAPIQD = 4098; MAPIRD = 4098; MAPISD = 4098; MAPITD = 4098; + MAPIUD = 4098; MAPIVD = 4098; MAPIWD = 4098; MAPIXD = 4098; MAPIYD = 4098; MAPIZD = 4098; + + MAPJ0D = 4098; MAPJ1D = 4098; MAPJ2D = 4098; MAPJ3D = 4098; MAPJ4D = 4098; MAPJ5D = 4098; + MAPJ6D = 4098; MAPJ7D = 4098; MAPJ8D = 4098; MAPJ9D = 4098; MAPJAD = 4098; MAPJBD = 4098; + MAPJCD = 4098; MAPJDD = 4098; MAPJED = 4098; MAPJFD = 4098; MAPJGD = 4098; MAPJHD = 4098; + MAPJID = 4098; MAPJJD = 4098; MAPJKD = 4098; MAPJLD = 4098; MAPJMD = 4098; MAPJND = 4098; + MAPJOD = 4098; MAPJPD = 4098; MAPJQD = 4098; MAPJRD = 4098; MAPJSD = 4098; MAPJTD = 4098; + MAPJUD = 4098; MAPJVD = 4098; MAPJWD = 4098; MAPJXD = 4098; MAPJYD = 4098; MAPJZD = 4098; + + MAPK0D = 4098; MAPK1D = 4098; MAPK2D = 4098; MAPK3D = 4098; MAPK4D = 4098; MAPK5D = 4098; + MAPK6D = 4098; MAPK7D = 4098; MAPK8D = 4098; MAPK9D = 4098; MAPKAD = 4098; MAPKBD = 4098; + MAPKCD = 4098; MAPKDD = 4098; MAPKED = 4098; MAPKFD = 4098; MAPKGD = 4098; MAPKHD = 4098; + MAPKID = 4098; MAPKJD = 4098; MAPKKD = 4098; MAPKLD = 4098; MAPKMD = 4098; MAPKND = 4098; + MAPKOD = 4098; MAPKPD = 4098; MAPKQD = 4098; MAPKRD = 4098; MAPKSD = 4098; MAPKTD = 4098; + MAPKUD = 4098; MAPKVD = 4098; MAPKWD = 4098; MAPKXD = 4098; MAPKYD = 4098; MAPKZD = 4098; + + MAPL0D = 4098; MAPL1D = 4098; MAPL2D = 4098; MAPL3D = 4098; MAPL4D = 4098; MAPL5D = 4098; + MAPL6D = 4098; MAPL7D = 4098; MAPL8D = 4098; MAPL9D = 4098; MAPLAD = 4098; MAPLBD = 4098; + MAPLCD = 4098; MAPLDD = 4098; MAPLED = 4098; MAPLFD = 4098; MAPLGD = 4098; MAPLHD = 4098; + MAPLID = 4098; MAPLJD = 4098; MAPLKD = 4098; MAPLLD = 4098; MAPLMD = 4098; MAPLND = 4098; + MAPLOD = 4098; MAPLPD = 4098; MAPLQD = 4098; MAPLRD = 4098; MAPLSD = 4098; MAPLTD = 4098; + MAPLUD = 4098; MAPLVD = 4098; MAPLWD = 4098; MAPLXD = 4098; MAPLYD = 4098; MAPLZD = 4098; + + MAPM0D = 4098; MAPM1D = 4098; MAPM2D = 4098; MAPM3D = 4098; MAPM4D = 4098; MAPM5D = 4098; + MAPM6D = 4098; MAPM7D = 4098; MAPM8D = 4098; MAPM9D = 4098; MAPMAD = 4098; MAPMBD = 4098; + MAPMCD = 4098; MAPMDD = 4098; MAPMED = 4098; MAPMFD = 4098; MAPMGD = 4098; MAPMHD = 4098; + MAPMID = 4098; MAPMJD = 4098; MAPMKD = 4098; MAPMLD = 4098; MAPMMD = 4098; MAPMND = 4098; + MAPMOD = 4098; MAPMPD = 4098; MAPMQD = 4098; MAPMRD = 4098; MAPMSD = 4098; MAPMTD = 4098; + MAPMUD = 4098; MAPMVD = 4098; MAPMWD = 4098; MAPMXD = 4098; MAPMYD = 4098; MAPMZD = 4098; + + MAPN0D = 4098; MAPN1D = 4098; MAPN2D = 4098; MAPN3D = 4098; MAPN4D = 4098; MAPN5D = 4098; + MAPN6D = 4098; MAPN7D = 4098; MAPN8D = 4098; MAPN9D = 4098; MAPNAD = 4098; MAPNBD = 4098; + MAPNCD = 4098; MAPNDD = 4098; MAPNED = 4098; MAPNFD = 4098; MAPNGD = 4098; MAPNHD = 4098; + MAPNID = 4098; MAPNJD = 4098; MAPNKD = 4098; MAPNLD = 4098; MAPNMD = 4098; MAPNND = 4098; + MAPNOD = 4098; MAPNPD = 4098; MAPNQD = 4098; MAPNRD = 4098; MAPNSD = 4098; MAPNTD = 4098; + MAPNUD = 4098; MAPNVD = 4098; MAPNWD = 4098; MAPNXD = 4098; MAPNYD = 4098; MAPNZD = 4098; + + MAPO0D = 4098; MAPO1D = 4098; MAPO2D = 4098; MAPO3D = 4098; MAPO4D = 4098; MAPO5D = 4098; + MAPO6D = 4098; MAPO7D = 4098; MAPO8D = 4098; MAPO9D = 4098; MAPOAD = 4098; MAPOBD = 4098; + MAPOCD = 4098; MAPODD = 4098; MAPOED = 4098; MAPOFD = 4098; MAPOGD = 4098; MAPOHD = 4098; + MAPOID = 4098; MAPOJD = 4098; MAPOKD = 4098; MAPOLD = 4098; MAPOMD = 4098; MAPOND = 4098; + MAPOOD = 4098; MAPOPD = 4098; MAPOQD = 4098; MAPORD = 4098; MAPOSD = 4098; MAPOTD = 4098; + MAPOUD = 4098; MAPOVD = 4098; MAPOWD = 4098; MAPOXD = 4098; MAPOYD = 4098; MAPOZD = 4098; + + MAPP0D = 4098; MAPP1D = 4098; MAPP2D = 4098; MAPP3D = 4098; MAPP4D = 4098; MAPP5D = 4098; + MAPP6D = 4098; MAPP7D = 4098; MAPP8D = 4098; MAPP9D = 4098; MAPPAD = 4098; MAPPBD = 4098; + MAPPCD = 4098; MAPPDD = 4098; MAPPED = 4098; MAPPFD = 4098; MAPPGD = 4098; MAPPHD = 4098; + MAPPID = 4098; MAPPJD = 4098; MAPPKD = 4098; MAPPLD = 4098; MAPPMD = 4098; MAPPND = 4098; + MAPPOD = 4098; MAPPPD = 4098; MAPPQD = 4098; MAPPRD = 4098; MAPPSD = 4098; MAPPTD = 4098; + MAPPUD = 4098; MAPPVD = 4098; MAPPWD = 4098; MAPPXD = 4098; MAPPYD = 4098; MAPPZD = 4098; + + MAPQ0D = 4098; MAPQ1D = 4098; MAPQ2D = 4098; MAPQ3D = 4098; MAPQ4D = 4098; MAPQ5D = 4098; + MAPQ6D = 4098; MAPQ7D = 4098; MAPQ8D = 4098; MAPQ9D = 4098; MAPQAD = 4098; MAPQBD = 4098; + MAPQCD = 4098; MAPQDD = 4098; MAPQED = 4098; MAPQFD = 4098; MAPQGD = 4098; MAPQHD = 4098; + MAPQID = 4098; MAPQJD = 4098; MAPQKD = 4098; MAPQLD = 4098; MAPQMD = 4098; MAPQND = 4098; + MAPQOD = 4098; MAPQPD = 4098; MAPQQD = 4098; MAPQRD = 4098; MAPQSD = 4098; MAPQTD = 4098; + MAPQUD = 4098; MAPQVD = 4098; MAPQWD = 4098; MAPQXD = 4098; MAPQYD = 4098; MAPQZD = 4098; + + MAPR0D = 4098; MAPR1D = 4098; MAPR2D = 4098; MAPR3D = 4098; MAPR4D = 4098; MAPR5D = 4098; + MAPR6D = 4098; MAPR7D = 4098; MAPR8D = 4098; MAPR9D = 4098; MAPRAD = 4098; MAPRBD = 4098; + MAPRCD = 4098; MAPRDD = 4098; MAPRED = 4098; MAPRFD = 4098; MAPRGD = 4098; MAPRHD = 4098; + MAPRID = 4098; MAPRJD = 4098; MAPRKD = 4098; MAPRLD = 4098; MAPRMD = 4098; MAPRND = 4098; + MAPROD = 4098; MAPRPD = 4098; MAPRQD = 4098; MAPRRD = 4098; MAPRSD = 4098; MAPRTD = 4098; + MAPRUD = 4098; MAPRVD = 4098; MAPRWD = 4098; MAPRXD = 4098; MAPRYD = 4098; MAPRZD = 4098; + + MAPS0D = 4098; MAPS1D = 4098; MAPS2D = 4098; MAPS3D = 4098; MAPS4D = 4098; MAPS5D = 4098; + MAPS6D = 4098; MAPS7D = 4098; MAPS8D = 4098; MAPS9D = 4098; MAPSAD = 4098; MAPSBD = 4098; + MAPSCD = 4098; MAPSDD = 4098; MAPSED = 4098; MAPSFD = 4098; MAPSGD = 4098; MAPSHD = 4098; + MAPSID = 4098; MAPSJD = 4098; MAPSKD = 4098; MAPSLD = 4098; MAPSMD = 4098; MAPSND = 4098; + MAPSOD = 4098; MAPSPD = 4098; MAPSQD = 4098; MAPSRD = 4098; MAPSSD = 4098; MAPSTD = 4098; + MAPSUD = 4098; MAPSVD = 4098; MAPSWD = 4098; MAPSXD = 4098; MAPSYD = 4098; MAPSZD = 4098; + + MAPT0D = 4098; MAPT1D = 4098; MAPT2D = 4098; MAPT3D = 4098; MAPT4D = 4098; MAPT5D = 4098; + MAPT6D = 4098; MAPT7D = 4098; MAPT8D = 4098; MAPT9D = 4098; MAPTAD = 4098; MAPTBD = 4098; + MAPTCD = 4098; MAPTDD = 4098; MAPTED = 4098; MAPTFD = 4098; MAPTGD = 4098; MAPTHD = 4098; + MAPTID = 4098; MAPTJD = 4098; MAPTKD = 4098; MAPTLD = 4098; MAPTMD = 4098; MAPTND = 4098; + MAPTOD = 4098; MAPTPD = 4098; MAPTQD = 4098; MAPTRD = 4098; MAPTSD = 4098; MAPTTD = 4098; + MAPTUD = 4098; MAPTVD = 4098; MAPTWD = 4098; MAPTXD = 4098; MAPTYD = 4098; MAPTZD = 4098; + + MAPU0D = 4098; MAPU1D = 4098; MAPU2D = 4098; MAPU3D = 4098; MAPU4D = 4098; MAPU5D = 4098; + MAPU6D = 4098; MAPU7D = 4098; MAPU8D = 4098; MAPU9D = 4098; MAPUAD = 4098; MAPUBD = 4098; + MAPUCD = 4098; MAPUDD = 4098; MAPUED = 4098; MAPUFD = 4098; MAPUGD = 4098; MAPUHD = 4098; + MAPUID = 4098; MAPUJD = 4098; MAPUKD = 4098; MAPULD = 4098; MAPUMD = 4098; MAPUND = 4098; + MAPUOD = 4098; MAPUPD = 4098; MAPUQD = 4098; MAPURD = 4098; MAPUSD = 4098; MAPUTD = 4098; + MAPUUD = 4098; MAPUVD = 4098; MAPUWD = 4098; MAPUXD = 4098; MAPUYD = 4098; MAPUZD = 4098; + + MAPV0D = 4098; MAPV1D = 4098; MAPV2D = 4098; MAPV3D = 4098; MAPV4D = 4098; MAPV5D = 4098; + MAPV6D = 4098; MAPV7D = 4098; MAPV8D = 4098; MAPV9D = 4098; MAPVAD = 4098; MAPVBD = 4098; + MAPVCD = 4098; MAPVDD = 4098; MAPVED = 4098; MAPVFD = 4098; MAPVGD = 4098; MAPVHD = 4098; + MAPVID = 4098; MAPVJD = 4098; MAPVKD = 4098; MAPVLD = 4098; MAPVMD = 4098; MAPVND = 4098; + MAPVOD = 4098; MAPVPD = 4098; MAPVQD = 4098; MAPVRD = 4098; MAPVSD = 4098; MAPVTD = 4098; + MAPVUD = 4098; MAPVVD = 4098; MAPVWD = 4098; MAPVXD = 4098; MAPVYD = 4098; MAPVZD = 4098; + + MAPW0D = 4098; MAPW1D = 4098; MAPW2D = 4098; MAPW3D = 4098; MAPW4D = 4098; MAPW5D = 4098; + MAPW6D = 4098; MAPW7D = 4098; MAPW8D = 4098; MAPW9D = 4098; MAPWAD = 4098; MAPWBD = 4098; + MAPWCD = 4098; MAPWDD = 4098; MAPWED = 4098; MAPWFD = 4098; MAPWGD = 4098; MAPWHD = 4098; + MAPWID = 4098; MAPWJD = 4098; MAPWKD = 4098; MAPWLD = 4098; MAPWMD = 4098; MAPWND = 4098; + MAPWOD = 4098; MAPWPD = 4098; MAPWQD = 4098; MAPWRD = 4098; MAPWSD = 4098; MAPWTD = 4098; + MAPWUD = 4098; MAPWVD = 4098; MAPWWD = 4098; MAPWXD = 4098; MAPWYD = 4098; MAPWZD = 4098; + + MAPX0D = 4098; MAPX1D = 4098; MAPX2D = 4098; MAPX3D = 4098; MAPX4D = 4098; MAPX5D = 4098; + MAPX6D = 4098; MAPX7D = 4098; MAPX8D = 4098; MAPX9D = 4098; MAPXAD = 4098; MAPXBD = 4098; + MAPXCD = 4098; MAPXDD = 4098; MAPXED = 4098; MAPXFD = 4098; MAPXGD = 4098; MAPXHD = 4098; + MAPXID = 4098; MAPXJD = 4098; MAPXKD = 4098; MAPXLD = 4098; MAPXMD = 4098; MAPXND = 4098; + MAPXOD = 4098; MAPXPD = 4098; MAPXQD = 4098; MAPXRD = 4098; MAPXSD = 4098; MAPXTD = 4098; + MAPXUD = 4098; MAPXVD = 4098; MAPXWD = 4098; MAPXXD = 4098; MAPXYD = 4098; MAPXZD = 4098; + + MAPY0D = 4098; MAPY1D = 4098; MAPY2D = 4098; MAPY3D = 4098; MAPY4D = 4098; MAPY5D = 4098; + MAPY6D = 4098; MAPY7D = 4098; MAPY8D = 4098; MAPY9D = 4098; MAPYAD = 4098; MAPYBD = 4098; + MAPYCD = 4098; MAPYDD = 4098; MAPYED = 4098; MAPYFD = 4098; MAPYGD = 4098; MAPYHD = 4098; + MAPYID = 4098; MAPYJD = 4098; MAPYKD = 4098; MAPYLD = 4098; MAPYMD = 4098; MAPYND = 4098; + MAPYOD = 4098; MAPYPD = 4098; MAPYQD = 4098; MAPYRD = 4098; MAPYSD = 4098; MAPYTD = 4098; + MAPYUD = 4098; MAPYVD = 4098; MAPYWD = 4098; MAPYXD = 4098; MAPYYD = 4098; MAPYZD = 4098; + + MAPZ0D = 4098; MAPZ1D = 4098; MAPZ2D = 4098; MAPZ3D = 4098; MAPZ4D = 4098; MAPZ5D = 4098; + MAPZ6D = 4098; MAPZ7D = 4098; MAPZ8D = 4098; MAPZ9D = 4098; MAPZAD = 4098; MAPZBD = 4098; + MAPZCD = 4098; MAPZDD = 4098; MAPZED = 4098; MAPZFD = 4098; MAPZGD = 4098; MAPZHD = 4098; + MAPZID = 4098; MAPZJD = 4098; MAPZKD = 4098; MAPZLD = 4098; MAPZMD = 4098; MAPZND = 4098; + MAPZOD = 4098; MAPZPD = 4098; MAPZQD = 4098; MAPZRD = 4098; MAPZSD = 4098; MAPZTD = 4098; + MAPZUD = 4098; MAPZVD = 4098; MAPZWD = 4098; MAPZXD = 4098; MAPZYD = 4098; MAPZZD = 4098; +} + + +// DEFAULT SECTOR BRIGHTNESS LEVELS------------------------------------------------------------------------------------------ +sectorbrightness +{ + 255; + 240; + 224; + 208; + 192; + 176; + 160; + 144; + 128; + 112; + 96; + 80; + 64; + 48; + 32; + 16; + 0; +} + +// SECTOR TYPES-------------------------------------------------------------------------------------------------------------- +sectortypes +{ + 0 = "Normal"; + 1 = "Light Blink Randomly"; + 2 = "Light Blink On Every 0.5 Seconds"; + 3 = "Light Blink On Every 1 Second"; + 4 = "Spikes"; + 5 = "Death Pit (No Camera Modifications)"; + 6 = "Space Countdown"; + 7 = "Damage (Fire)"; + 8 = "Light Pulse Smoothly"; + 9 = "Special Stage Damage"; + 10 = "Instant Kill"; + 11 = "Damage (Non-Elemental)"; + 12 = "Light Blinks On Every Half 0.5 (Synch)"; + 13 = "Light Blink On Every 1 Second (Synch)"; + 14 = "BOuncy Sector (FOF Control Only)"; + 16 = "Death Pit (Camera Modifications)"; + 17 = "Light Flickers Like Fire"; + 18 = "Damage (Electric)"; + 33 = "Special Stage Goal"; + 256 = "Ice/Sludge"; + 512 = "Wind/Current"; + 519 = "Damage (Fire) and Current"; + 666 = "Egg Trap Capsule"; + 690 = "Button for Door 700"; + 691 = "Button for Door 702"; + 692 = "Button for Door 704"; + 693 = "Button for Door 706"; + 694 = "Button for Door 708"; + 695 = "Button for Door 710"; + 696 = "Button for Door 712"; + 697 = "Button for Door 714"; + 698 = "Button for Door 716"; + 699 = "Button for Door 718"; + 700 = "Button for Door 720"; + 701 = "Button for Door 722"; + 702 = "Button for Door 724"; + 703 = "Button for Door 726"; + 704 = "Button for Door 728"; + 705 = "Button for Door 730"; + 706 = "Button for Door 732"; + 707 = "Button for Door 734"; + 708 = "Button for Door 736"; + 709 = "Button for Door 738"; + 710 = "Button 21 (THZ2)"; + 711 = "Close Door Blazing (Tag 743)"; + 768 = "Ice/Sludge & Wind/Current"; + 967 = "Trigger Linedef Executor (Emerald Check)"; + 968 = "Trigger Linedef Executor (NiGHTS mare)"; + 969 = "Super Sonic Transform"; + 970 = "Check for Linedef Executor On 3D Floors (ANY Object)"; + 971 = "Trigger Linedef Executor (Pushable Objects)"; + 972 = "Trigger Linedef Executor (Anywhere in Sector)(All Players)"; + 973 = "Trigger Linedef Executor (Floor touch)(All players)"; + 974 = "Trigger Linedef Executor (Anywhere in Sector)"; + 975 = "Trigger Linedef Executor (Floor Touch)"; + 976 = "Speed Pad (No Spin)"; + 977 = "Speed Pad (Spin)"; + 978 = "Ring Drainer (Floor Touch)"; + 979 = "Spinner"; + 980 = "Ring Drainer (No Floor Touch)"; + 981 = "Raise Ceiling to Highest (Tag 744)"; + 982 = "Exit Sector"; + 983 = "Damage (Water)"; + 984 = "Damage (Water) & Current"; + 985 = "Conveyor Belt"; + 986 = "THZ2 Slime Raise"; + 987 = "No Tag Zone"; + 988 = "CTF Red Team Base"; + 989 = "CTF Blue Team Base"; + 990 = "Special Stage Time/Rings"; + 991 = "Custom Gravity"; + 992 = "Ramp Sector"; + 993 = "Starpost Activator"; + 994 = "Finish Line"; + 996 = "Non-Ramp Sector"; + 997 = "Fan Sector"; + 998 = "Zoom Tube Start"; + 999 = "Zoom Tube End"; + 1500 ="Bustable Block Sprite parameter(ROIA)"; + 1501 ="Bustable Block Sprite parameter(ROIB)"; + 1502 ="Bustable Block Sprite parameter(ROIC)"; + 1503 ="Bustable Block Sprite parameter(ROID)"; + 1504 ="Bustable Block Sprite parameter(ROIE)"; + 1505 ="Bustable Block Sprite parameter(ROIF)"; + 1506 ="Bustable Block Sprite parameter(ROIG)"; + 1507 ="Bustable Block Sprite parameter(ROIH)"; + 1508 ="Bustable Block Sprite parameter(ROII)"; + 1509 ="Bustable Block Sprite parameter(ROIJ)"; + 1510 ="Bustable Block Sprite parameter(ROIK)"; + 1511 ="Bustable Block Sprite parameter(ROIL)"; + 1512 ="Bustable Block Sprite parameter(ROIM)"; + 1513 ="Bustable Block Sprite parameter(ROIN)"; + 1514 ="Bustable Block Sprite parameter(ROIO)"; + 1515 ="Bustable Block Sprite parameter(ROIP)"; +} + +// LINEDEF FLAGS------------------------------------------------------------------------------------------------------------- +linedefflags +{ + 1 = "Impassible"; + 2 = "Block Monster"; + 4 = "Double Sided"; + 8 = "Upper Unpegged"; + 16 = "Lower Unpegged"; + 32 = "Don't Activate On Easy"; + 64 = "No Climb"; + 128 = "Don't Activate On Normal"; + 256 = "Don't Activate On Hard"; + 512 = "Passuse"; + 2048 = "Don't Activate When Sonic"; + 4096 = "Don't Activate When Tails"; + 8192 = "Don't Activate When Knux"; + 16384 = "Bouncy Wall"; +} + +// LINEDEF ACTIVATIONS +linedefactivations +{ +} + +// LINEDEF TYPES------------------------------------------------------------------------------------------------------------- +linedeftypes +{ + 0 = " Normal"; + 1 = " 3D - Floor Over Floor: Crumbling (No respawn), Floating, Bobbing"; + 2 = " Continuous Floor/Ceiling Mover"; + 3 = " Continuous Floor Mover"; + 4 = " Continuous Ceiling Mover"; + 5 = " Light - Ceiling Lighting"; + 6 = " Continuous Two-Speed Floor/Ceiling Mover"; + 7 = " Continuous Two-Speed Floor Mover"; + 8 = " Continuous Two-Speed Ceiling Mover"; + 9 = " Linedef Executor: Trigger Linedef (Race - Once)"; + 10 = " Linedef Executor: Trigger Linedef (CTF Red Team, Continuous)"; + 11 = " Linedef Executor: Trigger Linedef (CTF Red Team, Each Time)"; + 12 = " Linedef Executor: Trigger Linedef (CTF Blue Team, Continuous)"; + 13 = " Linedef Executor: Trigger Linedef (CTF Red Team, Each Time)"; + 15 = " Linedef Executor: Trigger Linedef (No More Enemies, Once)"; + 16 = " ColorMap"; + 18 = " Zoom Tube Parameters"; + 19 = " Linedef Executor: Trigger Linedef (Character Ability, Continuous)"; + 20 = " Linedef Executor: Trigger Linedef (Character Ability, Each Time)"; + 21 = " Linedef Executor: Trigger Linedef (Character Ability, Once)"; + 24 = " Instant - Instant Ceiling Raise"; + 25 = " 3D - Floor Over Floor: Solid, Opaque, Shadowcasting (CTL sector light level used below"; + 26 = " Instant - Instant Floor Lower"; + 33 = " 3D - Floor Over Floor: Solid, Opaque, Non-Shadowcasting (CTL sector light level used above)"; + 34 = " 3D - Floor Over Floor: Floating & Bobbing"; + 35 = " 3D - Floor Over Floor: Crumbling (No Respawn)"; + 36 = " 3D - Floor Over Floor: Crumbling (Respawns after 15 seconds)"; + 37 = " 3D - Floor Over Floor: Crumbling (Respawn), Floating"; + 38 = " 3D - Floor Over Floor: Bobbing (Air)"; + 39 = " 3D - Floor Over Floor: Crumbling (Respawn), Floating, & Bobbing (Air)"; + 40 = " 3D - Floor Over Floor: Crumbling (Respawn), Bobbing (Air)"; + 41 = " Mario - Mario [?] Block"; + 42 = " 3D - Floor Over Floor: Crumbling (No Respawn), Floating"; + 43 = " Crusher - Crusher 1 (Ceiling to Floor)"; + 44 = " 3D - Floor Over Floor: Solid, Translucent"; + 45 = " Water - Water, Translucent"; + 46 = " 3D - Floor Over Floor: Fog Block"; + 47 = " Light - Half Light Block (From ceiling to bottom of level)"; + 48 = " Water - Water, Opaque"; + 49 = " Light - Light Block (From ceiling to floor)"; + 50 = " Crusher - Crusher 2 (Floor To Ceiling)"; + 51 = " 3D - Floor Over Floor: Solid, No Sides"; + 52 = " 3D - Floor Over Floor: Intangible, Translucent"; + 53 = " 3D - Floor Over Floor: Laser Block"; + 54 = " Mario - Floor Over Floor: Thwomp Block"; + 55 = " 3D - Floor Over Floor: Bustable Block"; + 56 = " 3D - Floor Over Floor: QuickSand Block"; + 57 = " 3D - Floor Over Floor: Solid, Invisible"; + 58 = " 3D - Floor Over Floor: Intangible, invisible"; + 59 = " 3D - Floor Over Floor: Intangible from Bottom, Opaque"; + 60 = " Light - Adjustable Pulsating Light"; + 61 = " Light - Adjustable Flickering Light"; + 62 = " 3D - Floor Over Floor: Intangible, Opaque"; + 63 = " Other - Camera Scanner"; + 64 = " Other - Per-Sector Gravity"; + 65 = " Movement/Scrolling - Speed Pad"; + 66 = " Other - Flat Alignment"; + 67 = " 3D - Floor Over Floor: Intangible, Sides Only"; + 68 = " 3D - Floor Over Floor: Adjustable Bobbing (Air)"; + 69 = " 3D - Floor Over Floor: Solid, Sides Only"; + 70 = " Other - Ideya (Nights) Time Modifier"; + 71 = " Other - Custom Exit"; + 72 = " 3D - Floor Over Floor: Reverse Adjustable Bob (Air)"; + 73 = " Other - Disable Linedef (Does Nothing)"; + 74 = " Water - Water, Translucent, No Sides"; + 75 = " Water - Water, Opaque, No Sides"; + 76 = " 3D - Floor Over Floor: Shatter Block"; + 77 = " 3D - Floor Over Floor: Platform, Translucent, No Sides"; + 78 = " 3D - Floor Over Floor: Spin Bust Block"; + 79 = " 3D - Floor Over Floor: Crumbling (Respawn)"; + 80 = " 3D - Floor Over Floor: Crumbling (No Respawn)"; + 81 = " 3D - Floor Over Floor: Platform, Translucent"; + 82 = " 3D - Floor Over Floor: Platform, Crumbling (Respawn), Translucent"; + 83 = " 3D - Floor Over Floor: Platform, Crumbling (No Respawn), Translucent"; + 84 = " 3D - Floor Over Floor: Spin Bust Block, Translucent"; + 85 = " Movement/Scrolling - Scroll Wall First Side Opposite Direction"; + 86 = " 3D - Floor Over Floor: Shatter Block, translucent"; + 87 = " 3D - Floor Over Floor: Custom"; + 88 = " Continuous Falling Sector"; + 89 = " 3D - Floor Over Floor: Rising Platform, Solid, Opaque, Shadowcasting"; + 90 = " 3D - Floor Over Floor: Rising Platform, Solid, Opaque, Non-Shadowcasting"; + 91 = " 3D - Floor Over Floor: Rising Platform Solid, Translucent"; + 92 = " 3D - Floor Over Floor: Rising Platform, Opaque"; + 93 = " 3D - Floor Over Floor: Rising Platform, Intangible from Bottom, Translucent"; + 94 = " 3D - Floor Over Floor: Rising Platform, Solid, Invisible"; + 95 = " Linedef Executor: Trigger Linedef (Ring Count - Continuous)"; + 96 = " Linedef Executor: Trigger Linedef (Continuous)"; + 97 = " Linedef Executor: Trigger Linedef (Each Time)"; + 98 = " Linedef Executor: Trigger Linedef (Once)"; + 99 = " Linedef Executor: Trigger Linedef (Ring Count - Once)"; + 100 = " Movement/Scrolling - Scroll Wall First Side Left"; + 101 = " Linedef Executor: Set Tagged Sector's Floor Height and Pic"; + 102 = " Linedef Executor: Set Tagged Sector's Ceiling Height and Pic"; + 103 = " Linedef Executor: Set Tagged Sector's Light Level"; + 104 = " Linedef Executor: Teleport Player to Tagged Sector"; + 105 = " Linedef Executor: Change Music"; + 106 = " Linedef Executor: Move Tagged Sector's Floor"; + 107 = " Linedef Executor: Move Tagged Sector's Ceiling"; + 108 = " Linedef Executor: Lower Floor by Line"; + 109 = " Linedef Executor: Raise Floor by Line"; + 110 = " Linedef Executor: Lower Ceiling by Line"; + 111 = " Linedef Executor: Raise Ceiling by Line"; + 112 = " Linedef Executor: Change Calling Sector's Tag"; + 113 = " Linedef Executor: Run Script"; + 114 = " Linedef Executor: Change Front Sector's Tag"; + 115 = " Linedef Executor: Play SFX"; + 116 = " Linedef Executor: Stop Plane Movement"; + 117 = " Linedef Executor: Fade Light Level"; + 118 = " Linedef Executor: Stop Lighting Effect"; + 119 = " Linedef Executor: Start Adjustable Fire Flicker"; + 120 = " Linedef Executor: Start Adjustable Glowing Light"; + 121 = " Linedef Executor: Cut-Away View"; + 122 = " Linedef Executor: Stop Object"; + 123 = " Linedef Executor: Change Sky"; + 124 = " Linedef Executor: Change Weather"; + 125 = " Linedef Executor: Change Object State"; + 126 = " Linedef Executor: Award Points"; + 127 = " Linedef Executor: Start Platform Movement"; + 200 = " Movement/Scrolling - Disp Scroll Ceiling Texture & Carry Objects"; + 201 = " Movement/Scrolling - Disp Carry Objects on Ceiling"; + 202 = " Movement/Scrolling - Scroll Ceiling Texture & Carry Objects"; + 203 = " Movement/Scrolling - Carry Objects on Ceiling"; + 204 = " Movement/Scrolling - Acc Scroll Ceiling Texture & Carry Objects"; + 205 = " Movement/Scrolling - Acc Carry Objects on Ceiling"; + 213 = " Light - Set Floor Lighting"; + 214 = " Movement/Scrolling - Acc Scroll Ceiling Texture"; + 215 = " Movement/Scrolling - Acc Scroll Floor Texture"; + 216 = " Movement/Scrolling - Acc Scroll Objects on Floor"; + 217 = " Movement/Scrolling - Acc Scroll Floor Texture & Carry Objects"; + 218 = " Movement/Scrolling - Acc Scroll Wall According to Linedef"; + 223 = " Other - Friction"; + 224 = " Wind/Current - Wind"; + 225 = " Wind/Current - Current"; + 226 = " Other - Boom Push/Pull"; + 227 = " Wind/Current - Upward Current"; + 228 = " Wind/Current - Downward Current"; + 229 = " Wind/Current - Upward Wind"; + 230 = " Wind/Current - Downward Wind"; + 232 = " Activate Floating Platform"; + 233 = " Activate Floating Platform (Adjustable Speed)"; + 242 = " Other - Fake Floor"; + 245 = " Movement/Scrolling - Disp Scroll Ceiling Texture"; + 246 = " Movement/Scrolling - Disp Scroll Floor Texture"; + 247 = " Movement/Scrolling - Disp Scroll Objects on Floor"; + 248 = " Movement/Scrolling - Disp Scroll Floor Texture & Carry Objects"; + 249 = " Movement/Scrolling - Disp Scroll Wall According to Linedef"; + 250 = " Movement/Scrolling - Scroll Ceiling Texture"; + 251 = " Movement/Scrolling - Scroll Floor Texture"; + 252 = " Movement/Scrolling - Carry Objects on Floor"; + 253 = " Movement/Scrolling - Scroll Floor Texture & Carry Objects"; + 254 = " Movement/Scrolling - Scroll Wall According by Linedef"; + 255 = " Movement/Scrolling - Scroll Texture by Offsets"; +} + +// THING FLAGS--------------------------------------------------------------------------------------------------------------- +thingflags +{ + 1 = "Easy"; + 2 = "Medium"; + 4 = "Hard"; + 8 = "Deaf"; + 16 = "Multiplayer"; + 32 = "Bitset: 2 Units"; + 64 = "Bitset: 4 Units"; + 128 = "Bitset: 8 Units"; + 256 = "Bitset: 16 Units"; + 512 = "Bitset: 32 Units"; + 1024 = "Bitset: 64 Units"; + 2048 = "Bitset: 128 Units"; + 4096 = "Bitset: 256 Units"; + 8192 = "Bitset: 512 Units"; + 16384 = "Bitset: 1024 Units"; + 32768 = "Bitset: 2048 Units"; +} + +// THING TYPES--------------------------------------------------------------------------------------------------------------- +// Color values: 1-Blue 2-Green 3-Cyan 4-Red 5-Magenta 6-Brown 7-Gray 8-Dark_Gray 9-Light_Blue +// 10-Light_Green 11-Light_Cyan 12-Light_Red 13-Pink 14-Yellow 15-White +thingtypes +{ + editor + { + color = 15; // White + arrow = 1; + title = "Editor Things"; + width = 16; + + 32000 + { + title = "3D Mode start"; + } + } + + players //--------------------------------------------------------------------------------------- + { + color = 1; // Blue + arrow = 1; + title = "Player Starts"; + width = 32; + sort = 2; + + 1 + { + title = "Player 1 Start"; + sprite = "SUPTD0"; + height = 74; + } + 2 + { + title = "Player 2 Start"; + sprite = "SUPTD0"; + height = 74; + } + 3 + { + title = "Player 3 Start"; + sprite = "SUPTD0"; + height = 74; + } + 4 + { + title = "Player 4 Start"; + sprite = "SUPTD0"; + height = 74; + } + 4001 + { + title = "Player 5 Start"; + sprite = "SUPTD0"; + height = 74; + } + 4002 + { + title = "Player 6 Start"; + sprite = "SUPTD0"; + height = 74; + } + 4003 + { + title = "Player 7 Start"; + sprite = "SUPTD0"; + height = 74; + } + 4004 + { + title = "Player 8 Start"; + sprite = "SUPTD0"; + height = 74; + } + 87 + { + title = "Red Team Start(CTF)"; + sprite = "SUPTD0"; + height = 74; + } + 89 + { + title = "Blue Team Start(CTF)"; + sprite = "SUPTD0"; + height = 74; + } + 11 + { + title = "Deathmatch Start"; + sprite = "SUPTD0"; + height = 74; + } + } + + enemies //----------------------------------------------------------------------------------------------- + { + color = 4; // Red + arrow = 1; + title = "Enemies"; + width = 40; + sort = 2; + + 3004 + { + title = "Blue Crawla"; + sprite = "POSSA1"; + height = 48; + } + 9 + { + title = "Red Crawla"; + sprite = "SPOSA1"; + height = 48; + } + 21 + { + title = "Crawla Commander"; + sprite = "CCOMA1"; + height = 42; + } + 5005 + { + title = "Gold Buzz"; + sprite = "BUZZA1"; + height = 29; + } + 5006 + { + title = "Red Buzz"; + sprite = "RBUZA1"; + height = 29; + } + 3005 + { + title = "Jettysyn Bomber"; + sprite = "JETBB1"; + height = 64; + } + 22 + { + title = "Jettysyn Gunner"; + sprite = "JETGC1"; + height = 64; + } + 58 + { + title = "Stupid Dumb Unnamed Robo-fish"; + sprite = "FISHA0"; + height = 32; + } + 56 + { + title = "Skim"; + sprite = "SKIMA0"; + height = 48; + } + 71 + { + title = "Deton"; + sprite = "DETNA1"; + height = 46; + } + 2004 + { + title = "Turret"; + sprite = "TRETA1"; + height = 32; + } + 42 + { + title = "Pop Up Turret"; + sprite = "TURRD1"; + height = 53; + } + 16 + { + title = "Egg Mobile(Boss A)"; + width = 112; + sprite = "EGGMA1"; + height = 96; + } + 2008 + { + title = "Egg Slimer(Boss B)"; + width = 112; + sprite = "EGGNA1"; + height = 132; + } + 17 + { + title = "Boss Flypoint"; + width = 20; + sprite = "EGGNG1"; + height = 96; + } + } + + NiGHTs //------------------------------------------------------------------------------------------ + { + color = 11; // Light Cyan + arrow = 0; + title = "NiGHTs stuff"; + width = 20; + sort = 2; + + 52 = "1024 Axis"; + 53 = "512 Axis"; + 59 = "2048 Axis"; + 62 = "1024 Axis Inverted"; + 15 = "512 Axis Inverted"; + 45 = "2048 Axis Inverted"; + 61 = "Axis Transfer"; + 46 = "Axis Transfer Closest"; + 55 = "Axis Transfer Last to First"; + 60 + { + title = "NiGHTs Super Sonic"; + sprite = "NDRNA1"; + height = 70; + } + 57 = "Hoop"; + 47 = "Ring Circle"; + 2007 = "Big Ring Circle"; + 2048 = "Wing Logo Circle"; + 40 = "NiGHT's egg capsule"; + 2010 = "Big Wing Logo Circle"; + 2046 = "Ring N Wing Circle"; + 2047 = "Big Ring N Wing Circle"; + 3007 = "Super loop"; + 3008 = "Drill refill"; + 3009 = "Helper"; + 82 = "Axis Transfer Condition"; + } + + monitors //-------------------------------------------------------------------------------------------- + { + color = 7; // Gray + arrow = 0; + title = "Moniters"; + width = 20; + sort = 2; + + 41 + { + title = "Extra Life"; + sprite = "PRUPA0"; + height = 34; + } + 2022 + { + title = "Invincibility"; + sprite = "PINVA0"; + height = 34; + } + 25 + { + title = "Super Sneakers"; + sprite = "SHTVA0"; + height = 34; + } + 2028 + { + title = "Liquid Shield"; + sprite = "BLTVA0"; + height = 34; + } + 35 + { + title = "Whirlwind shield"; + sprite = "WHTVA0"; + height = 34; + } + 48 + { + title = "Lightning Shield"; + sprite = "YLTVA0"; + height = 34; + } + 2002 + { + title = "Fire Shield"; + sprite = "RDTVA0"; + height = 34; + } + 2018 + { + title = "Armageddon Shield"; + sprite = "BKTVA0"; + height = 34; + } + 2011 + { + title = "Super Rings"; + sprite = "SRBXA0"; + height = 34; + } + 2012 + { + title = "Silver Ring"; + sprite = "GRBXA0"; + height = 34; + } + 78 + { + title = "Teleporter"; + sprite = "MIXUA0"; + height = 34; + } + 2005 + { + title = "Robotnik"; + sprite = "EGGBA0"; + height = 34; + } + 3000 + { + title = "Random Monitor"; + sprite = "QUESA0"; + height = 34; + } + } + + weapons //--------------------------------------------------------------------------------------- + { + color = 14; // Yellow + arrow = 0; + title = "Rings and Weapons"; + width = 20; + sort = 2; + + 2014 + { + title= "Ring"; + sprite = "BON1A0"; + height = 32; + } + 84 + { + title = "5 Vertical Rings for Yellow Spring"; + sprite = "BON1A0"; + height = 32; + } + 44 + { + title = "5 Vertical Rings for Red Spring"; + sprite = "BON1A0"; + height = 32; + } + 76 + { + title = "5 Diagonal Rings for Yellow Spring"; + sprite = "BON1A0"; + height = 32; + } + 77 + { + title = "10 Diagonal Rings for Red Spring"; + sprite = "BON1A0"; + height = 32; + } + 69 + { + title= "Homing Ring"; + sprite = "HOMNIND"; + height = 16; + } + 3003 + { + title = "Rail Ring"; + sprite = "RAILIND"; + height = 16; + } + 26 + { + title = "Auto Ring"; + sprite = "AUTOIND"; + height = 16; + } + 54 + { + title= "Bomb Ring"; + sprite = "BOMBIND"; + height = 16; + } + 80 + { + title= "Infinity Ring"; + sprite = "INFNIND"; + height = 16; + } + } + + collectables //----------------------------------------------------------------------------------- + { + color = 10; // Light Green + arrow = 0; + title = "Other Collectables"; + width = 20; + sort = 2; + + 31 + { + title = "Red Flag (CTF)"; + sprite = "RFLGA0"; + height = 73; + } + 34 + { + title = "Blue Flag (CTF)"; + sprite = "BFLGA0"; + height = 73; + } + 37 + { + title = "Emblem"; + sprite = "NWNGA0"; + height = 32; + } + 2013 + { + title = "Special Stage Token"; + sprite = "TOKEA0"; + height = 32; + } + 64 + { title = "Emerald Hunt Location A"; + sprite = "EMERA0"; + height = 16; + } + 3002 + { title = "Emerald Hunt Location B"; + sprite = "EMERA0"; + height = 16; + } + 3001 + { + title = "Emerald Hunt Location C"; + sprite = "EMERA0"; + height = 16; + } + 420 + { + title = "Emerald 1 (Green)"; + sprite = "cemga0"; + height = 16; + } + 421 + { + title = "Emerald 2 (Orange)"; + sprite = "cemoa0"; + height = 16; + } + 422 + { + title = "Emerald 3 (Pink)"; + sprite = "cempa0"; + height = 16; + } + 423 + { + title = "Emerald 4 (Blue)"; + sprite = "cemba0"; + height = 16; + } + 424 + { + title = "Emerald 5 (Red)"; + sprite = "cemra0"; + height = 16; + } + 425 + { + title = "Emerald 6 (Light Blue)"; + sprite = "cemla0"; + height = 16; + } + 426 + { + title = "Emerald 7 (Grey)"; + sprite = "cemya0"; + height = 16; + } + 427 + { + title = "Emerald 8 (Master)"; + sprite = "cemka0"; + height = 16; + } + } + + springs //------------------------------------------------------------------------------------------ + { + color = 12; // Light Red + arrow = 1; + title = "Springs and Other Vertical Boosters"; + width = 20; + sort = 2; + + 28 + { + title = "Yellow Spring (384 units high)"; + sprite = "SPRYA0"; + height = 32; + } + 65 + { + title = "Yellow Spring Down"; + sprite = "SUDYA0"; + height = 32; + hangs = 1; + } + 2015 + { + title = "Yellow Spring Diagonal Up"; + sprite = "YSPRD2"; + height = 41; + } + 20 + { + title = "Yellow Spring Diagonal Down"; + sprite = "YSUDE2"; + height = 41; + hangs = 1; + } + 79 + { + title = "Red Spring (1024 units high)"; + sprite = "SPRRA0"; + height = 32; + } + 66 + { + title = "Red Spring Down"; + sprite = "SUDRA0"; + height = 32; + hangs = 1; + } + 38 + { + title = "Red Spring Diagonal Up"; + sprite = "RSPRD2"; + height = 41; + } + 39 + { + title = "Red Spring Diagonal Down"; + sprite = "RSUDE2"; + height = 41; + hangs = 1; + } + 30 + { + title = "Gas Jet"; + sprite = "STEMD0"; + height = 80; + } + 32 + { + title = "Fan"; + sprite = "FANSA0"; + height = 24; + } + 5004 + { + title = "Blue Spring"; + sprite = "SPRBA0"; + height = 32; + } + } + + hazards //----------------------------------------------------------------------------------------------- + { + color = 5; // Magenta + arrow = 0; + title = "Hazards"; + width = 20; + sort = 2; + + 68 + { + title = "Spike"; + sprite = "USPKA0"; + height = 42; + } + 67 + { + title = "Hanging Spike"; + sprite = "DSPKA0"; + height = 42; + hangs = 1; + } + 23 + { + title = "Spiked ball"; + sprite = "SPIKA0"; + height = 32; + } + 24 + { + title = "Torch"; + sprite = "FLAMA0"; + height = 96; + } + 51 + { + title = "Laser"; + sprite = "LASRA0"; + height = 32; + } + + } + + others //--------------------------------------------------------------------------------------------------- + { + color = 6; // Brown + arrow = 1; + title = "Other Useful Things"; + width = 20; + sort = 2; + + 33 + { + title = "Air Bubbles"; + sprite = "BUBMA0"; + height = 31; + } + 3006 + { + title = "Star Post"; + sprite = "STPTA0"; + height = 96; + } + 2049 + { + title = "Capsule Center"; + sprite = "SQRLA1"; + height = 32; + } + 86 + { + title = "End Sign"; + sprite = "SIGNF0"; + height = 64; + width = 64; + } + 5001 = "Push"; + 5002 = "Pull"; + 5003 = "Teleport Destination"; + 5007 = "Alt View (Cut-Away)"; + } + + scenery //--------------------------------------------------------------------------------------------- + { + color = 2; // Green + arrow = 0; + title = "Scenery"; + width = 20; + sort = 2; + + 36 + { + title = "Orange Flower"; + sprite = "FWR1A0"; + height = 56; + } + 70 + { + title = "Sun-Flower"; + sprite = "FWR2A0"; + height = 128; + } + 73 + { + title = "Purple Budding Flower"; + sprite = "FWR3A0"; + height = 32; + } + 75 + { + title = "Small Tree"; + sprite = "BUS2A0"; + height = 64; + } + 74 + { + title = "Small Tree w/ Fruit"; + sprite = "BUS1A0"; + height = 64; + } + 2035 + { + title = "Polluted Flower"; + sprite = "THZPA0"; + height = 64; + } + 2001 + { + title = "Dead Flower"; + sprite = "FWR4A0"; + height = 56; + } + 81 + { + title = "Gargoyle"; + sprite = "GARGA1"; + height = 64; + } + 49 + { + title = "Chain"; + sprite = "CHANA0"; + height = 128; + hangs = 1; + } + 5 + { + title = "Christmas Pole"; + sprite = "XMS1A0"; + height = 64; + } + 13 + { + title = "Candy Cane"; + sprite = "XMS2A0"; + height = 72; + } + 6 + { + title = "Snow Man"; + sprite = "XMS3A0"; + height = 72; + } + } + + sounds //--------------------------------------------------------------------------------------------------- + { + color = 3; // Cyan + arrow = 0; + title = "Sounds and Lights"; + width = 16; + sort = 2; + + 14 = "Random Ambience"; + 43 = "Random Ambience 2"; + 2019 = "Water sound 3B (Small)"; + 2025 = "Water Sound 4A (Extra Large)"; + 2026 = "Water Sound 1A (Large)"; + 2023 = "Water Sound 2A (Medium)"; + 83 = "Water Sound 3A (Small)"; + 27 = "Water Sound 2 (Huge)"; + 2024 = "Water Sound 1B (Large)"; + 2045 = "Water Sound 2B (Medium)"; + + 2006 + { + title = "Alarm"; + sprite = "ALRMA0"; + height = 32; + hangs = 1; + } + 2003 = "Light Source"; + } + + Mario //------------------------------------------------------------------------------------------------- + { + color = 9; // Light Blue + arrow = 1; + title = "Mario themed items"; + + 10005 + { + title = "Coin"; + sprite = "COINB0"; + height = 28; + } + 50 + { + title= "Fire Flower"; + sprite = "FFWRB0"; + height = 32; + } + 10002 + { + title = "Mario Tree"; + sprite = "MUS1A0"; + height = 60; + } + 10003 + { + title = "Mario Tree (Tall)"; + sprite = "MUS2A0"; + height = 92; + } + 10004 + { + title = "Toad"; + sprite = "TOADA0"; + height = 46; + } + 12 + { + title = "Mario Bridge Axe"; + sprite = "MAXEA0"; + height = 32; + } + 10 + { + title = "Koopa Shell"; + sprite = "SHLLA0"; + height = 30; + } + 29 + { + title = "Leaping Fireball (AKA Puma)"; + sprite = "PUMAA0"; + height = 32; + } + 10000 + { + title = "Goomba"; + sprite = "GOOMB0"; + height = 48; + } + 10001 + { + title = "Blue Underground Goomba"; + sprite = "BGOMA0"; + height = 48; + } + 18 + { + title = "Bowser"; + width = 80; + sprite = "KOOPA0"; + height = 70; + } + } + +} diff --git a/extras/wminput.conf b/extras/wminput.conf new file mode 100644 index 000000000..ea6f4e3ec --- /dev/null +++ b/extras/wminput.conf @@ -0,0 +1,58 @@ +# wminput configuration for SRB2Wii by Alam Arias +# based on Callum Dickinson's version + +#Wiimote.Up = KEY_RESERVED +#Wiimote.Down = KEY_RESERVED +#Wiimote.Left = KEY_RESERVED +#Wiimote.Right = KEY_RESERVED +Wiimote.A = BTN_THUMB +Wiimote.B = BTN_TRIGGER +Wiimote.Minus = BTN_THUMBL +Wiimote.Plus = BTN_THUMBR +Wiimote.Home = BTN_MODE +Wiimote.1 = BTN_1 +Wiimote.2 = BTN_2 + +Wiimote.Dpad.X = -ABS_HAT0Y +Wiimote.Dpad.Y = -ABS_HAT0X + +Nunchuk.C = BTN_C +Nunchuk.Z = BTN_Z + +Nunchuk.Stick.X = ABS_THROTTLE +Nunchuk.Stick.Y = -ABS_RUDDER + +#Classic.Up = KEY_RESERVED +#Classic.Down = KEY_RESERVED +#Classic.Left = KEY_RESERVED +#Classic.Right = KEY_RESERVED +Classic.Minus = BTN_SELECT +Classic.Plus = BTN_START +Classic.Home = BTN_MODE +Classic.A = BTN_A +Classic.B = BTN_B +Classic.X = BTN_X +Classic.Y = BTN_Y +Classic.ZL = BTN_TL2 +Classic.ZR = BTN_TR2 +Classic.L = BTN_TL +Classic.R = BTN_TR + +Classic.Dpad.X = ABS_HAT1X +Classic.Dpad.Y = -ABS_HAT1Y +Classic.LStick.X = ABS_X +Classic.LStick.Y = -ABS_Y +Classic.RStick.X = ABS_RX +Classic.RStick.Y = -ABS_RY +Classic.LAnalog = ABS_GAS +Classic.RAnalog = ABS_BRAKE + +# Nunchuk Stick buttons +Plugin.nunchuk_stick2btn.Up = BTN_BASE +Plugin.nunchuk_stick2btn.Down = BTN_BASE2 +Plugin.nunchuk_stick2btn.Left = BTN_BASE3 +Plugin.nunchuk_stick2btn.Right = BTN_BASE4 + +# Mouse Control +#Plugin.ir_ptr.X = REL_X +#Plugin.ir_ptr.Y = REL_Y diff --git a/libs/.gitignore b/libs/.gitignore new file mode 100644 index 000000000..7a65d55c1 --- /dev/null +++ b/libs/.gitignore @@ -0,0 +1,2 @@ +zlib.lib +libpng.lib diff --git a/libs/curl/CHANGES b/libs/curl/CHANGES new file mode 100644 index 000000000..de754c543 --- /dev/null +++ b/libs/curl/CHANGES @@ -0,0 +1,5424 @@ + _ _ ____ _ + ___| | | | _ \| | + / __| | | | |_) | | + | (__| |_| | _ <| |___ + \___|\___/|_| \_\_____| + + Changelog + +Version 7.21.6 (22 Apr 2011) + +Daniel Stenberg (22 Apr 2011) +- RELEASE-NOTES: two more contributors + +Dan Fandrich (21 Apr 2011) +- Fixed test 1023 when using daily snapshots + +- Include unistd.h to declare close() + +Julien Chaffraix (21 Apr 2011) +- [Fabian Keil brought this change] + + In lib/, change 'wanna' to 'want to'. + + Found with codespell. + +- [Fabian Keil brought this change] + + Fix spelling errors in buildconf + + Found with codespell. + +- [Fabian Keil brought this change] + + Fix spelling errors in src/ + + Found with codespell. + +- [Fabian Keil brought this change] + + Fix spelling errors in include/ + +- [Fabian Keil brought this change] + + Fix a couple of spelling errors in lib/ + + Found with codespell. + +- transfer.c: Fixed indentation in readwrite_data. + +Dan Fandrich (20 Apr 2011) +- Fixed closing test tag + +Daniel Stenberg (20 Apr 2011) +- RELEASE-NOTES: synced with 3242abd87a1262 + +- SFTP: close file before postquote + + Make sure that files are closed before the post quote commands run as if + they operate on the just transferred file they could otherwise easily + fail. + + Patch by: Rajesh Naganathan (edited) + +Dan Fandrich (20 Apr 2011) +- Fixed test 1022 when using daily snapshots + +Daniel Stenberg (20 Apr 2011) +- Curl_http_connect: detect HTTPS properly after CONNECT + + libcurl failed to check the correct struct for HTTPS after CONNECT was + issued to the proxy, so it didn't do the TLS handshake and subsequently + failed the connection. A regression released in 7.21.5 (introduced + around commit 8831000bc07de). + + Bug: http://curl.haxx.se/mail/lib-2011-04/0134.html + Reported by: Josue Andrade Gomes + +- curl_easy_setopt.3: CURLOPT_PROXYTYPE clarification + + When set to a HTTP 1.0 proxy, that only affects the CONNECT request and + not the regular HTTP request. + +- [Gisle Vanem brought this change] + + CURL_DOES_CONVERSIONS: fixes + + Made it compile and work again after the code move. + +- CURL_DOES_CONVERSIONS: cleanup + + Massively reduce #ifdefs all over (23 #ifdef lines less so far) + Moved conversion-specific code to non-ascii.c + +Guenter Knauf (19 Apr 2011) +- Improve MinGW static makefile builds. + + It is now possible to use any combination of features without + having to 1st add makefile targets to the main makefile. The + main makefile now passes the 'mingw32-feat1-feat2' as var CFG, + and the ./[lib|src]/Makefile.m32 parses the CFG var to determine + the features to be enabled. + +- Enabled MinGW native Windows IDN build. + +- Windows native IDN fixes. + + changed windows.h include to system header; + changed obsolete 2nd check for str_w to str_utf8 in order to catch + malloc() failure and avoid a free(NULL); + changed calls to GetLastError() to void to kill unsused var compiler + warnings; + moved one call to GetLastError() into else case so that its only + called when WideCharToMultiByte() really fails. + +- Windows native IDN fixes. + + Provide prototype for curl_win32_idn_to_ascii(); + remove wrong 3rd parameter from curl_win32_idn_to_ascii() call. + +Daniel Stenberg (19 Apr 2011) +- curl-config: fix version output + + do the s/VERSION/CURLVERSION replacement for the human redable output + for --checkfor + + Reported by: Ryan Schmidt + +- RELEASE-NOTES: synced with 5aae3c13e2 + +Guenter Knauf (19 Apr 2011) +- Updated default (recommended) dependency versions. + +- Updated default (recommended) dependency versions. + +Daniel Stenberg (18 Apr 2011) +- transfer-encoding: document the options + + The new libcurl and command line options are now described. + +- transfer-encoding: added new option and cmdline + + Added CURLOPT_TRANSFER_ENCODING as the option to set to request Transfer + Encoding in HTTP requests (if built zlib enabled). I also renamed + CURLOPT_ENCODING to CURLOPT_ACCEPT_ENCODING (while keeping the old name + around) to reduce the confusion when we have to encoding options for + HTTP. + + --tr-encoding is now the new command line option for curl to request + this, and thus I updated the test cases accordingly. + +- CURLE_BAD_CONTENT_ENCODING: now used for transfer encoding too + +- TE: do the Connection: header + + When TE: is inserted in the request, we must add a "Connection: TE" as + well to be HTTP 1.1 compliant. If a custom Connection: header is passed + in, we must use that and only append TE to it. Test case 1125 verifies + TE: + custom Connection:. + +- test1124: verify gzip AND chunked transfer-encoding + +- TE: rename struct field content_encoding + + Since this struct member is used in the code to determine what and how + to decode automatically and since it is now also used for compressed + Transfer-Encodings, I renamed it to the more suitable 'auto_decoding' + +- HTTP: add support for gzip and deflate Transfer-Encoding + + Transfer-Encoding differs from Content-Encoding in a few subtle ways, + but primarily it concerns the transfer only and not the content so when + discovered to be compressed we know we have to uncompress it. There will + only arrive compressed transfers in a response after we have requested + them with the appropriate TE: header. + + Test case 1122 and 1123 verify. + +Patrick Monnerat (18 Apr 2011) +- OS400 pragma comment: replace (date) by (user, __DATE__) to include year. + +- Augment RPG binding with "OLDIES" definitions. + Fix OS400 LDAP wrappers: strings were non null-terminated. + +Daniel Stenberg (18 Apr 2011) +- curl-config: fix --version + + curl-config --version didn't output the correct version string (bug + introduced in commit 0355e33b5f7b234cf3), and unfortunately the test + case 1022 that was supposed to check for this was broken. + + This change fixes the test to detect this problem and it fixes the + output. + + Bug: http://curl.haxx.se/bug/view.cgi?id=3288727 + +- RELEASE-NOTES: updated contributor amount + +- THANKS: 11 new contributors from 7.21.5 + +- 7.21.6: next planned release number + +Version 7.21.5 (17 Apr 2011) + +Daniel Stenberg (17 Apr 2011) +- base64.c: removed wrong comment + +- INTERNALS: clean up + + Clarified the release procedure + +- TODO-RELEASE: push the remaining ones to next release + + As we're closing in on the release, I give up on the remaining ones but + I leave them in here for now to try to fix for next release. + + I removed the 281 issue about warnings from the statical analyzer scans, + as they seem to be mostly false positives at this point. + +- RELEASE-NOTES: synced with c246f63a71 + +- Curl_ssl_shutdown: restore send/recv pointers + + When going back from SSL, put the send/recv function pointers back to + the plain versions. + + Bug: http://curl.haxx.se/mail/lib-2011-04/0070.html + Reported by: Mehmet Bozkurt + +Guenter Knauf (16 Apr 2011) +- Changed email per Gisle's request. + +Daniel Stenberg (14 Apr 2011) +- curl.1: error code update + + Error 4 has got a meaning + + Error 48 has got a slightly different meaning now + +- FAQ: c-ares does ipv6 pretty well now + +- [Andrei Benea brought this change] + + Fix a buffer overflow in pubkey_show(). + +Guenter Knauf (14 Apr 2011) +- Replaced var manipulations with perlish hacks. + +Dan Fandrich (12 Apr 2011) +- Updated minimum binary sizes + +Daniel Stenberg (12 Apr 2011) +- configure: libssh2 link fix without pkg-config + + The script didn't properly add the -lssh2 link option when it enabled + libssh2 linking where pkg-config isn't found. + + Reported by: Saqib Ali + Bug: http://curl.haxx.se/mail/lib-2011-04/0054.html + +- RELEASE-NOTES: synced with f01df197981 + +- checkconnection: don't call with NULL pointer + + When checking if an existing RTSP connection is alive or not, the + checkconnection function might be called with a SessionHandle pointer + being NULL and then referenced causing a crash. This happened only using + the multi interface. + + Reported by: Tinus van den Berg + + Bug: http://curl.haxx.se/bug/view.cgi?id=3280739 + +- curl.1: spell out the -O target directory + + When using -O the file will be saved in the current directory, and this + is now spelled out clearly. + +- OpenSSL: no-sslv2 aware + + Allow openSSL without SSL2 to be used. This fix is inspired by the fix + provided by Cristian Rodríguez. + + Reported by: Cristian Rodríguez + +- curl_easy_setopt.3: CURLOPT_RESOLVE typo version + + Reported by: Hongli Lai + +Kamil Dudka (8 Apr 2011) +- nss: allow to use multiple client certificates for a single host + + In case a client certificate is used, invalidate SSL session cache + at the end of a session. This forces NSS to ask for a new client + certificate when connecting second time to the same host. + + Bug: https://bugzilla.redhat.com/689031 + +Daniel Stenberg (7 Apr 2011) +- mk-ca-bundle.pl: show full URL in output + + When I decided to search for a potential error with the cacert bundle it + struck me I wanted to see the full source URL in the output... + +Dan Fandrich (7 Apr 2011) +- Added mention of FTP proxies + +Daniel Stenberg (7 Apr 2011) +- [Gisle Vanem brought this change] + + src/Makefile.b32: updates + + * Rename the object object directory from 'objs' to 'BCC_obj' to be in + sync with my previous patch for lib/Makefile.b32. + + * Turn off these warnings to keep the build totally silent (with CBuilder-6 + that is). + -w-inl 8026 Functions X are not expanded inline. + -w-pia 8060 Possibly incorrect assignment + -w-pin 8061 Initialization is only partially bracketed + (same added in src/Makefile.b32) + + * $(MKDIR) and $(RMDIR) have been replaced with the shell-commands 'md' + and 'rd'. When having MingW/Msys programs 'mkdir.exe' and 'rmdir.exe' in + $PATH, this confuses Borland's make and the result (the cleaning etc.) would + not be as expected. + + * Removed the preprocessing step; no need for PP_CMD and the .int files. + curl.exe builds fine w/o and the makefile gets simpler. + + * Added a target for creating a compressed hugehelp.c if WITH_ZLIB is defined. + It assumes groff, gzip and perl is available if such an "advanced" users + requests it. Okay? BTW. My groff and Perl needs unix-slashes ('/'). + Other perls should handle both forms ('/' and '\'). + +- [Gisle Vanem brought this change] + + lib/Makefile.b32: updates + + * Rename the object object directory from 'objs' to 'BCC_obj'. I feel + it should be named properly. Ref. Makefile.Watcom where it's called + 'WC_Win32.obj'. + + * Turn off these warnings to keep the build totally silent (with CBuilder-6 + that is). + -w-inl 8026 Functions X are not expanded inline. + -w-pia 8060 Possibly incorrect assignment + -w-pin 8061 Initialization is only partially bracketed + + I'm sure the warnings could be fixed the "proper" way or with some added + "#pragma" statements. But that just clutters the sources IMHO. + + * $(MKDIR) and $(RMDIR) have been replaced with the shell-commands 'md' + and 'rd'. When having MingW/Msys programs 'mkdir.exe' and 'rmdir.exe' in + $PATH, this confuses Borland's make and the result (the cleaning etc.) would + not be as expected. + + * Added a ".path.int = $(OBJDIR)" to tell make where the $(PREPROCESSED) + files are. Why we need the preprocess step in the fist place is beyond me + (Yang?). But I'll leave that for now. + +- [Gisle Vanem brought this change] + + examples/makefile.dj: update email + +- TODO-RELEASE: deleted 4 issues + + These problems have gotten no interest/feedback from users: + + -275 - Introduce a way to avoid sending USER for FTP connections + -288 - bug 3219997 curl rtmp request curl: (55) select/poll returned error + + This problem is rather an autoconf bug with little user interest and it + can be worked around with an older autoconf: + + -278 - "Configure $as_echo does not work" + + This problem is not fixed: + + -286 - bug 3214223 Pipelined HTTP requests with a zero-length body broken + +- [Chris Smowton brought this change] + + HTTP pipelining: Fix handling of zero-length responses + + Also add test case 584 for the same + + Bug: http://curl.haxx.se/bug/view.cgi?id=3214223 + +- libcurl.pc: version number fix + + This hasn't show the version number correctly since the $VERSION change + in the configure, and now it works again. + +Dan Fandrich (5 Apr 2011) +- Changed some nonportable types + +- Don't list NTLM in curl-config when HTTP is disabled + + Also, fixed Curl_proxyCONNECT() stub with HTTP disabled. + +- Fixed compatibility macro CURLE_URL_MALFORMAT_USER + +Daniel Stenberg (5 Apr 2011) +- return code cleanup: build, init and run-time errors + + Stop the abuse of CURLE_FAILED_INIT as return code for things not being + init related by introducing two new return codes: + + CURLE_NOT_BUILT_IN and CURLE_UNKNOWN_OPTION + + CURLE_NOT_BUILT_IN replaces return code 4 that has been obsoleted for + several years. It is used for returning error when something is + attempted to be used but the feature/option was not enabled or + explictitly disabled at build-time. Getting this error mostly means that + libcurl needs to be rebuilt. + + CURLE_FAILED_INIT is now saved and used strictly for init + failures. Getting this problem means something went seriously wrong, + like a resource shortage or similar. + + CURLE_UNKNOWN_OPTION is the option formerly known as + CURLE_UNKNOWN_TELNET_OPTION (and the old name is still present, + separately defined to be removed in a very distant future). This error + code is meant to be used to return when an option is given to libcurl + that isn't known. This problem would mostly indicate a problem in the + program that uses libcurl. + +- FTP+proxy: macrofied functions when proxy disabled + + In my attempts to reduce #ifdefs in code, the SOCKS functions are now + macros when libcurl is built without proxy support and therefore the FTP + code could avoid some #ifs. + +- RELEASE-NOTES: synced with db59b6202d8 + +- [Ben Noordhuis brought this change] + + [pop3 starttls] PASS command was not sent after upgrade to TLS. + +- [Ben Noordhuis brought this change] + + [pop3 starttls] the command to send is STLS, not STARTTLS. + +Dan Fandrich (4 Apr 2011) +- Added http_proxy.c to the Symbian build files + +Daniel Stenberg (4 Apr 2011) +- http-proxy: move proxy code to http_proxy.c + + The new http_proxy.* files now host HTTP proxy specific code (500+ lines + moved out from http.c), and as a consequence there is a macro introduced + for the Curl_proxyCONNECT() function so that code can use it without + actually supporting proxy (or HTTP) in builds. + +- disable cookies: remove ifdefs, move code + + 1 - make sure to #define macros for cookie functions in the cookie + header when cookies are disabled to avoid having to use #ifdefs in code + using those functions. + + 2 - move cookie-specific code to cookie.c and use the functio + conditionally as mentioned in (1). + + net result: 6 #if lines removed, and 9 lines of code less + +Kamil Dudka (4 Apr 2011) +- nss: fix a crash within SSL_AuthCertificate() + + The bug was introduced in 806dbb0 (a wrong value was passed in as the + first argument to the default callback in our wrapper). + +Daniel Stenberg (3 Apr 2011) +- multi: shorten lines + + We keep them less than 80 columns + +- multi: conn goes bad when data change + + Within multi_socket when conn is used as a shorthand, data could be + changed and multi_runsingle could modify the connectdata struct to deal + with. This bug has not been included in a public release. + + Using 'conn' like that turned out to be ugly. This change is a partial + revert of commit f1c6cd42f474df59. + + Reported by: Miroslav Spousta + Bug: http://curl.haxx.se/bug/view.cgi?id=3265485 + +Guenter Knauf (1 Apr 2011) +- Increased script version. + +- Make use of proxy vars if set. + + Posted to the list by Quanah Gibson-Mount [quanah zimbra.com]. + +- Use var again instead of hard-coded filename. + +Daniel Stenberg (29 Mar 2011) +- [Gisle Vanem brought this change] + + typo fix + +- curl_easy_setopt.3: mention TFTP read callback flaw + + The read callback must return the exact requested amount of data when it + is used for doing TFTP uploads. This is due to how it deals with data + internally. This could/should be fixed but for now we document the + existing behavior. + + Reported by: Colin Blair + Bug: http://curl.haxx.se/mail/lib-2011-03/0319.html + +Yang Tse (27 Mar 2011) +- configure: fix libtool warning + +Daniel Stenberg (25 Mar 2011) +- [Peter Sylvester brought this change] + + TSL-SRP: enabled with OpenSSL + + If a new enough OpenSSL version is used, configure detects the TLS-SRP + support and enables it. + +- RELEASE-NOTES: synced with 11c2db2aa2a + +- fix: re-use of bound connections + + When asked to bind the local end of a connection when doing a request, + the code will now disqualify other existing connections from re-use even + if they are connected to the correct remote host. + + This will also affect which connections that can be used for pipelining, + so that only connections that aren't bound or bound to the same + device/port you're asking for will be considered. + +- symbols-in-versions: make test 1119 happy + +- rtsp: move protocol code to dedicated file + + The RTSP-specific function for checking for "dead" connection is better + located in rtsp.c. The code using this is now written without #ifdefs as + the function call is instead turned into a macro (in rtsp.h) when RTSP + is disabled. + +- MAIL-ETIQUETTE: intro and spam + + Added a little generic info section about the lists and a section about + how to deal with trolls and spam on the lists. + +- TODO-RELEASE: 1 fixed, 1 notabug + + Fixed: + + 271 - fix the IPv6-working probing to only exist at one place in the code and + only get done once + + A problem not repeatable and no proper recipe given and therefore simply + removed for now until we hear something else: + + 282 - 100 Continue responses should return the "final" HTTP response code: + "Getting the HTTP response code following a 100 Continue" + +- ipv6: only probe once + + Move ipv6-functional-probe into a single function that is used from all + places that need to know. + + Make the probe function store the result in a static variable so that + subsequent invokes just returns the previous result and won't have to + probe again. + +- headers: more copyright headers added + +- MAIL-ETIQUETTE: how to behave + + This is a new documentation for the source tree. This information has + been present since a long time at + http://curl.haxx.se/mail/etiquette.html but now it is put into a plain + text version too for wider distribution. The web version will be + automatically generated from this source document. + +Julien Chaffraix (21 Mar 2011) +- progress: don't print the last update on a separate line. + + Curl_posttransfer is called too soon to add the final new line. + Moved the new line logic to pgrsDone as there is no more call to + update the progress status after this call. + + Reported by: Dmitri Shubin + http://curl.haxx.se/mail/lib-2010-12/0162.html + +Daniel Stenberg (21 Mar 2011) +- TODO-RELEASE: fixed 2, got 3 new! + +- [Dave Reisner brought this change] + + libcurl.m4: Add missing quotes in AC_LINK_IFELSE + + This avoids warnings generated by autoconf 2.68. + + Signed-off-by: Dave Reisner + +- retry-request: rewind if data was sent + + When libcurl sends a HTTP request on a re-used connection and detects it + being closed (ie no data at all was read from it), it is important to + rewind if any data in the request was sent using the read callback or + was read from file, as otherwise the retried request will be broken. + + Reported by: Chris Smowton + Bug: http://curl.haxx.se/bug/view.cgi?id=3195205 + +- configure: avoid $VERSION + + To reduce the risk of variable name conflicts, use CURLVERSION instead + of VERSION. + +- symbols-in-versions: many corrections + + Scanned with a tool that checked for mistakes and this is the subsequent + cleanup. + +Julien Chaffraix (20 Mar 2011) +- unit1305: Fixed the test to match our coding style. + +- url: 0 is PROTOPT_NONE. + + Tiny tweak after Daniel's refactoring of the protocol handlers. + +Daniel Stenberg (19 Mar 2011) +- pop3: add state name in debug array + + We have an array with the state names only built and used when built + debug enabled and this need to list all the states from the .h + +Dan Fandrich (18 Mar 2011) +- Added two more POP3 tests + +- pop3: use Curl_safefree() to allow torture tests to succeed + +Daniel Stenberg (18 Mar 2011) +- symbol-scan.pl: detect duplicates + + Test 1119 now also makes sure that symbols-in-versions doesn't contain + any duplicates + +- CONTRIBUTE: minor edits + + Slightly modified to become a nicer web page when converted for the site + +- RELEASE-NOTES: synced with 0c05ee3a33d4d7 + +- pop3: remove unused variable + +Dan Fandrich (17 Mar 2011) +- Added support for LISTing a single POP3 message + + Added tests for a number of POP3 LIST operations, including one + that shows a curl problem when listing no messages, so is + disabled. + +- pop3: fixed memory leak in an error retrieval case + +Daniel Stenberg (17 Mar 2011) +- symbols-in-versions: remove duplicates + +- symbols-in-versions: 2 corrections + + CURLE_CHUNK_FAILED and CURLE_FTP_BAD_FILE_LIST were introduced in + 7.21.0, not 7.20.1 + +- connection setup: if HTTP is disabled asking for HTTP proxy is bad + +- FAQ: better english + + Reported by: Andre Guibert de Bruet + +- scan-build warning + + Value stored to 'len' is never read + +- ldap_recv: check return code from ldap_get_dn_ber + +- compiler warnings fixed + + Use (void)[variable] to inhibit unused argument/variables warnings. + +- [Ben Noordhuis brought this change] + + SMTP-multi: non-blocking connect + + Use Curl_ssl_connect_nonblocking() when upgrading the connection to + TLS/SSL while using the multi interface. + +- [Ben Noordhuis brought this change] + + SMTP in multi mode: use Curl_ssl_connect_nonblocking() when connecting. + +- lib582: use curl_socket_t for portability + +- buildfix: spell define correctly + +Kamil Dudka (15 Mar 2011) +- nss: do not ignore value of CURLOPT_SSL_VERIFYPEER + + When NSS-powered libcurl connected to a SSL server with + CURLOPT_SSL_VERIFYPEER equal to zero, NSS remembered that the peer + certificate was accepted by libcurl and did not ask the second time when + connecting to the same server with CURLOPT_SSL_VERIFYPEER equal to one. + + This patch turns off the SSL session cache for the particular SSL socket + if peer verification is disabled. In order to avoid any performance + impact, the peer verification is completely skipped in that case, which + makes it even faster than before. + + Bug: https://bugzilla.redhat.com/678580 + +Guenter Knauf (15 Mar 2011) +- Removed unused var. + +Daniel Stenberg (15 Mar 2011) +- configure: stop using the deprecated AM_INIT_AUTOMAKE syntax + +- protocol handler cleanup: SSL awareness + + As a follow-up to commit 8831000bc0: don't assume that the SSL powered + protocol alternatives are available. + +- ldap: use the new protocol handler setup + + Use the new flags field and stop using the old protocol defines. + +- TODO-RELEASE: add and remove issues + + Removed a fixed issue, added five new existing ones and clarified one of + the previous ones. + +- protocols: use CURLPROTO_ internally + + The PROT_* set of internal defines for the protocols is no longer + used. We now use the same bits internally as we have defined in the + public header using the CURLPROTO_ prefix. This is for simplicity and + because the PROT_* prefix was already used duplicated internally for a + set of KRB4 values. + + The PROTOPT_* defines were moved up to just below the struct definition + within which they are used. + +- protocol handler: added flags field + + The protocol handler struct got a 'flags' field for special information + and characteristics of the given protocol. + + This now enables us to move away central protocol information such as + CLOSEACTION and DUALCHANNEL from single defines in a central place, out + to each protocol's definition. It also made us stop abusing the protocol + field for other info than the protocol, and we could start cleaning up + other protocol-specific things by adding flags bits to set in the + handler struct. + + The "protocol" field connectdata struct was removed as well and the code + now refers directly to the conn->handler->protocol field instead. To + make things work properly, the code now always store a conn->given + pointer that points out the original handler struct so that the code can + learn details from the original protocol even if conn->handler is + modified along the way - for example when switching to go over a HTTP + proxy. + +Patrick Monnerat (14 Mar 2011) +- - Take new char * options into account in OS400 curl_easy_setopt_ccsid(). + - Keep RPG binding, STRING_* table end check and OS400 README up to date. + +Daniel Stenberg (14 Mar 2011) +- FAQ: indent tables + + Lines that are indented with at least 5 spaces get special treatment by + the script that converts it to HTML on the site. + +- sslgen: define Curl_ssl_connect_nonblocking for non-SSL + + The non-blocking connect improvement for IMAP showed that we didn't + properly define the Curl_ssl_connect_nonblocking function for non-SSL + builds. + + Reported by: Tor Arntsen + +- configure: removed wrongly claimed default paths + + Several --with-XXX options claimed the wrong default path in their help + outputs. + + Reported by: Vincent Torri + +- [Ask Bjørn Hansen brought this change] + + mk-ca-bundle.pl: Only download if modified + + Only download and convert the certdata to the ca-bundle.crt if Mozilla + changed the data + + The Perl LWP module (which in a bit of a circular reference is used by + mk-ca-bundle.pl) is now indirectly using this script. I made this small + tweak to make it easier to automatically maintain the generated + ca-bundle.crt file in version control. + +- SSH: add protocol lock direction + + Some protocols have to call the underlying functions without regard to + what exact state the socket signals. For example even if the socket says + "readable", the send function might need to be called while uploading, + or vice versa. This is the case for libssh2 based protocols: SCP and + SFTP and we now introduce a define to set those protocols and we make + the multi interface code aware of this concept. + + This is another fix to make test 582 run properly. + +- state: add missing state to debug table + + As a new state recently was added to the IMAP state machine it has to be + in the array of names as well as otherwise libcurl crashes when a debug + version runs... + +- test 582: enabled again + + Commit ca37692bf43b5ef should now hopefully make it run + +- ssh_statemach_act: set cselect for sftp upload + + For uploads we want to use the _sending_ function even when the socket + turns out readable as the underlying libssh2 sftp send function will + deal with both accordingly. This is what the cselect_bits magic is for. + + Fixes test 582. + +- RELEASE-NOTES: synced with e649a7baae2 + +- Revert "test582: enabled" + + This reverts commit b8478187406cf625c9d0f10b45a082221130cc92. + +- Merge branch 'imap' of https://github.com/bnoordhuis/curl into bnoordhuis-imap + +- TODO-RELEASE: fixed four isues + + These issues are now addressed: + + 276 - Karl M's vc makefile patch + 277 - The "Stall when uploading to sftp using multi interface" bug + 279 - curl_multi_remove_handle() crashes + 280 - Marcus Sundberg's gss patch + +- [Karl M brought this change] + + VC: add missing file + + http_negotiate_sspi.c was added to the source tree recently + +- [Marcus Sundberg brought this change] + + GSS: handle reuse fix + + Make GSS authentication work when a curl handle is reused for multiple + authenticated requests, by always setting negdata->state in + output_auth_headers(). + + Signed-off-by: Marcus Sundberg + +- test583: verify early SSH multi remove handle + + This test case is meant to verify that the logic in commit + 60172a0446bbe3f8b actually works. This test failed for me before that + change and it works after it. + +- SFTP: gracefully handle shutdown early + + When using the multi interface and a handle using SFTP was removed very + early on, we would get a segfault due to the code assumed data was there + that hadn't yet been setup. + + Bug: http://curl.haxx.se/mail/lib-2011-03/0066.html + Reported by: Saqib Ali + +- [Manuel Massing brought this change] + + CURL_CHECK_FUNC_RECVFROM: android/bionic fix + + recvfrom in bionic (the android libc) deviates from POSIX and uses a + const in the 5th argument ("const struct sockaddr *") so the check now + tests for that as well. + +- test582: enabled + +- PROT_CLOSEACTION: added SFTP and SCP + + Both SFTP and SCP are protocols that need to shut down stuff properly + when the connection is about to get torned down. The primary effect of + not doing this shows up as memory leaks (when using SCP or SFTP with the + multi interface). + + This is one of the problems detected by test 582. + +- readwrite_upload: stop upload at file size + + As we know how much to send, we can and should stop once we've sent that + much data as it avoids having to rely on other mechanisms to detect the + end. + + This is one of the problems detected by test 582. + + Reported by: Henry Ludemann + +- sftp upload: expire to advance state machine + + When using the multi_socket API to do SFTP upload, it is important that + we set a quick expire when leaving the SSH_SFTP_UPLOAD_INIT state as + there's nothing happening on the socket so there's no read or write to + wait for, but the next libssh2 API function needs to be called to get + the ball rolling. + + This is one of the problems detected by test 582. + + Reported by: Henry Ludemann + +- test582: improved info messages + +- source header: added to more files + +- sources: update source headers + + All C and H files now (should) feature the proper project curl source + code header, which includes basic info, a copyright statement and some + basic disclaimers. + +- TODO-RELEASE: add 10 pending issues + +- TODO-RELEASE: fix the IPv6-working probing + +- tests: phase out haxx.se + + Instead of using haxx.se as a fixed magic host name in lots of tests, + this is a first step to move toward the generic example.com host + instead. + +- test523: avoid using haxx.se + + ... since search engines find what they think is a URL in this, they + hammer www.haxx.se on this port! + +- configure: update the copyright year in the output + +Dan Fandrich (9 Mar 2011) +- Force setopt constants written by --libcurl to be long + +Daniel Stenberg (8 Mar 2011) +- cyassl: fix compiler warnings + +- [Todd A Ouska brought this change] + + SSL: (part 2) Added CyaSSL to SSL abstraction layer + + This is the modified existing files commit. + +- [Todd A Ouska brought this change] + + SSL: Added CyaSSL to SSL abstraction layer + + CyaSSL (available from git@github.com:cyassl/cyassl.git) has been + added to the SSL abstraction layer. + + To test: + 1) git CyaSSL sources + 2) autoreconf -i + 3) ./configure --disable-static + 4) make + 5) sudo make install + 6) autoreconf -i + 7) git curl sources (and this patch) + 8) ./configure --disable-shared --with-cyassl --without-ssl --enable-debug + 9) make + 10) normal testing + + Please send questions or comments to todd@yassl.com . + +- curl.1: clarify -E + + Stress that it is for client certificates and then mention that it also + works for all other SSL-based protocols apart from HTTPS and + FTPS. Namely POP3S, IMAPS and SMTPS for now. + +- FAQ: Protocol xxx not supported or disabled in libcurl + +- lib582: used for test 582 + + Accidentally not included in commit 0e74e1d8d83 + +Dan Fandrich (7 Mar 2011) +- Fixed libcurl to honour the --disable-ldaps configure option + +Daniel Stenberg (8 Mar 2011) +- [Henry Ludemann brought this change] + + sftp-multi: test 582 added + + Add test 582 for uploading a file using sftp and the multi interface. + + (Patch and test slightly tweaked by Daniel Stenberg) + + Initially marked as disabled until it is fixed in the source. + +- FAQ: How to SFTP from my user's home directory? + +- cpp: correct #endif placement + + The end-of-file #endif in rawstr.h was not correcly positioned after all + prototypes. + + Reported by: Boris + Bug: http://curl.haxx.se/bug/view.cgi?id=3195205 + +Dan Fandrich (4 Mar 2011) +- Moved test 577 into the unit test framework as test 1307 + +- Added unit test 1306 so tests 558 & 559 are now fully replaced + +- The unit test argument is allowed to be used + +- Converted tests 558 & 559 to use the unit test framework as 1305 + + Test 558 was just a subset of 559 which is something that can be + easily added later. + +- Fixed test 1300 to pass the torture test + +- Added abort_* unit test macros + + These are for when a test failure makes it impossible to continue + running further tests. + +Kamil Dudka (4 Mar 2011) +- [Stefan Krause brought this change] + + transfer: avoid insane conversion of time_t + +Daniel Stenberg (26 Feb 2011) +- ssh_connect: treat libssh2 return code better + + libssh2_knownhost_readfile() returns a negative value on error or + otherwise number of parsed known hosts - this was previously not + documented correctly in the libssh2 man page for the function. + + Bug: http://curl.haxx.se/mail/lib-2011-02/0327.html + Reported by: murat + +Julien Chaffraix (25 Feb 2011) +- http: removed wrong unused comment. + + |premature| is used in Curl_http_done. + +- http: removed code duplication for stubbed https_getsock function. + +Daniel Stenberg (23 Feb 2011) +- RELEASE-NOTES: synced with 2345c1dd661c + +- runtests.pl/stopserver: space separate pids + + The stopserver function would append pids to kill and could append them + without separating them with space properly. The result would be a very + large number that by (some implementations of) kill would be interpreted + as a negative number and that process group would be wiped... + + Bug: http://curl.haxx.se/bug/view.cgi?id=3188836 + Reported by: Greg Pratt + +Kamil Dudka (22 Feb 2011) +- nss: do not ignore failure of SSL handshake + + Flaw introduced in fc77790 and present in curl-7.21.4. + Bug: https://bugzilla.redhat.com/669702#c16 + +Daniel Stenberg (21 Feb 2011) +- CURLOPT_SSH_KEYFUNCTION: requires *SSH_KNOWNHOSTS + + Extend the docs to clarify that CURLOPT_SSH_KEYFUNCTION is only called + if the known hosts option is also correctly set! + +Julien Chaffraix (20 Feb 2011) +- curl_easy_setopt.3: Removed wrong reference to CURLOPT_USERPASSWORD. + + CURLOPT_HTTPAUTH was mentioning CURLOPT_USERPASSWORD instead of + CURLOPT_PASSWORD. + + Reported by: Mike Henshaw + +- netrc: Removed _NETRC_DEBUG code. + + This is not needed anymore as we have unit testing running on it. + +- tests: Cleaned up netrc testing. + + Removed the "netrc_debug" keyword replaced with --netrc-file additions. + Removed the debug code from Curl_parsenetrc as it is superseeded by + --netrc-file. + +- curl: Added --netrc-file. + + This enables people to specify a path to the netrc file to use. + The new option override --netrc if both are present. However it + does follow --netrc-optional if specified. + +Ben Noordhuis (20 Feb 2011) +- IMAP in multi mode: use Curl_ssl_connect_nonblocking() when upgrading the connection to TLS/SSL. + +- IMAP in multi mode: use Curl_ssl_connect_nonblocking() when connecting. + +Daniel Stenberg (18 Feb 2011) +- [Mike Crowe brought this change] + + multi: close connection on timeout + + After a request times out, the connection wasn't properly closed and + prevented to get re-used, so subsequent transfers could still mistakenly + get to use the previously aborted connection. + +- multi: better failed connect treatment + + When failing to connect the protocol during the CURLM_STATE_PROTOCONNECT + state, Curl_done() has to be called with the premature flag set TRUE as + for the pingpong protocols this can be important. + + When Curl_done() is called with premature == TRUE, it needs to call + Curl_disconnect() with its 'dead_connection' argument set to TRUE as + well so that any protocol handler's disconnect function won't attempt to + use the (control) connection for anything. + + This problem caused the pingpong protocols to fail to disconnect when + STARTTLS failed. + + Reported by: Alona Rossen + Bug: http://curl.haxx.se/mail/lib-2011-02/0195.html + +- [Hoi-Ho Chan brought this change] + + PolarSSL: Return 0 on receiving TLS CLOSE_NOTIFY alert + + Signed-off-by: Hoi-Ho Chan + +- symbols-in-versions: sorted + + I forgot to sort it when I added the CURL_SOCKOPT_* symbols + +- TODO-RELEASE: refresh + +- SOCKOPTFUNCTION: documented new return codes + +- SOCKOPTFUNCTION: callback can say already-connected + + Introducing a few CURL_SOCKOPT* defines for conveniance. The new + CURL_SOCKOPT_ALREADY_CONNECTED signals to libcurl that the socket is to + be treated as already connected and thus it will skip the connect() + call. + +Kamil Dudka (17 Feb 2011) +- nss: avoid memory leak on SSL connection failure + +Daniel Stenberg (17 Feb 2011) +- RELEASE-NOTES: fresh start towards 7.21.5 + +- curlver.h: bump to 7.21.5 + +- THANKS: add contributors from 7.21.4 + +Version 7.21.4 (17 Feb 2011) + +Guenter Knauf (17 Feb 2011) +- Set -fpcc-struct-return only for gcc compiler. + +Daniel Stenberg (17 Feb 2011) +- RELEASE-NOTES: credits since 7.21.3 + + I went through all the names mentioned as authors and in commit messages + since 7.21.3, and this list inserted now is sorted on first name. + +- nss_load_key: fix unused variable warning + +- gmtime: remove define + + It turns out some systems rely on the gmtime or gmtime_r to be defined + already in the system headers and thus my "precaution" redefining of + them only caused trouble. They are now removed. + +Guenter Knauf (13 Feb 2011) +- Added -m32 to CFLAGS to compile with x86_64 gcc. + +- Updated OpenSSL version, added links to docu. + +Daniel Stenberg (10 Feb 2011) +- RELEASE-NOTES: synced with 3bb1291fbd4 + +- --keepalive-time: warn if not supported properly + + Since the feature requires support for TCP_KEEPIDLE and TCP_KEEPINTVL to + function as documented, it now warns if that support is missing when the + option is used. + +Dan Fandrich (10 Feb 2011) +- Call ERR_peek_error instead of ERR_peek_last_error + + The latter isn't available in older OpenSSL versions, and is + less useful since it returns the most recent error instead of + the first one encountered. + +Julien Chaffraix (10 Feb 2011) +- netrc: Enable setting up the filename in unit tests. + + Unset the environment variable so that we can specify different + filenames in the unit test. + +- test1304: Added some unit tests for Curl_parsenetrc. + + Moved some definitons into the header file so that we can reuse them. + +Daniel Stenberg (9 Feb 2011) +- [Quinn Slack brought this change] + + CURLE_TLSAUTH_FAILED: removed + + On second thought, I think CURLE_TLSAUTH_FAILED should be eliminated. It + was only being raised when an internal error occurred while allocating + or setting the GnuTLS SRP client credentials struct. For TLS + authentication failures, the general CURLE_SSL_CONNECT_ERROR seems + appropriate; its error string already includes "passwords" as a possible + cause. Having a separate TLS auth error code might also cause people to + think that a TLS auth failure means the wrong username or password was + entered, when it could also be a sign of a man-in-the-middle attack. + +- [Quinn Slack brought this change] + + TLS-SRP: new options documented + +- CURLOPT_SOCKOPTFUNCTION: return proper error code + + When the callback returns an error, this function must make sure to return + CURLE_ABORTED_BY_CALLBACK properly and not CURLE_OK as before to allow the + callback to properly abort the operation. + +- curl.1: typo in -v description + + Reported by: Ian D Allen + Bug: https://bugs.launchpad.net/ubuntu/+source/curl/+bug/714895 + + Forwarded to us by: + + Reported by: Andreas Olsson + Bug: http://curl.haxx.se/bug/view.cgi?id=3175422 + +Julien Chaffraix (7 Feb 2011) +- netrc: Removed dead code. + + The main has not been updated from some time and is out of sync with + the code. The code is now tested by several test cases so no need for + a seperate code path. + +- netrc: Tightened up the type checks. + + The state should not be anonymous so that we can check if the values + are fine. Added 2 unreachables states to the switch as a result of this + change. + +- imap: Fixed typo in a comment. + +Daniel Stenberg (7 Feb 2011) +- Curl_gmtime: avoid future mistakes + + Document Curl_gmtime() and define away the old functions so that they + won't be used internally again by mistake. + +- Curl_gmtime: added a portable gmtime + + Instead of polluting many places with #ifdefs, we create a single place + for this function, and also check return code properly so that a NULL + pointer returned won't cause problems. + +Guenter Knauf (3 Feb 2011) +- mk-ca-bundle.vbs: use new cacert url + + The official Mozilla page at http://www.mozilla.org/projects/security/certs/ + points out a new place as the "proper" place to get Mozilla's CA certs from + so this script is now updated to use that instead. + + Reported by: Daniel Mentz + +Daniel Stenberg (2 Feb 2011) +- mk-ca-bundle.pl: use new cacert url + + The official Mozilla page at + http://www.mozilla.org/projects/security/certs/ points out a new place + as the "proper" place to get Mozilla's CA certs from so this script is + now updated to use that instead. + + Reported by: Daniel Mentz + +- [Bjoern Sikora brought this change] + + ssluse: improved error message on SSL_CTX_new failures + + "SSL: couldn't create a context" really isn't that helpful, now it'll + also extract an explanation from OpenSSL and append to the right. + +- [Nicholas Maniscalco brought this change] + + multi: fix CURLM_STATE_TOOFAST for multi_socket + + The code in the toofast state needs to first recalculate the values + before it uses them again since it may have been a while since it last + did it when it reaches this point. + +- unit1300: code style cleanup + +- [Amr Shahin brought this change] + + adding unit tests for Curl_llist_remove + +Patrick Monnerat (31 Jan 2011) +- Include TLSAUTH options in ILE/RPG binding. + +Kamil Dudka (31 Jan 2011) +- [Dave Reisner brought this change] + + file: add support for CURLOPT_TIMECONDITION + +- [Dave Reisner brought this change] + + transfer: add Curl_meets_timecondition() + + This will be used by file_do() and Curl_readwrite() as a unified method + of checking to see if a remote document meets the supplied + CURLOPT_TIMEVAL and CURLOPT_TIMECONDITION. + + Signed-off-by: Dave Reisner + +Daniel Stenberg (29 Jan 2011) +- FAQ: clarified/expanded 6.7 a bit + + "6.7 What are my obligations when using libcurl in my commercial apps?" + got the piece about what exactly "in all copies" mean to a user of the + code. + + This interpretation is based on what other MIT-like licenses have made + more explicit. + +- COPYING: update the year to 2011 + + The generic copyright year range now includes 2011 + +- [Pierre Joye brought this change] + + Windows build: alternative makefile + + This is a separate makefile for MSVC builds. It is deliberately put in + another dir than src/ and lib/ to allow a different build experience + than the previous - at least during a period. Eventually we should + unify. + +- test: add test 580 to the dist + +Dan Fandrich (27 Jan 2011) +- Some minor edits including updates to function names + +Daniel Stenberg (27 Jan 2011) +- ares: memory leak fix + + The double name resolve trick used with c-ares could leave allocated + memory in 'temp_ai' if the operation was aborted in the middle. + +- ares_query_completed_cb: don't touch invalid data + + When this callback is called due to the destruction of the ares handle, + the connection pointer passed in as an argument may no longer pointing + to valid data and this function doesn't need to do anything with it + anyway so we make sure it doesn't. + + Bug: http://curl.haxx.se/mail/lib-2011-01/0333.html + Reported by: Vsevolod Novikov + +Kamil Dudka (27 Jan 2011) +- nss: avoid memory leaks and failure of NSS shutdown + + ... in case more than one CA is loaded. + + Bug: https://bugzilla.redhat.com/670802 + +Dan Fandrich (26 Jan 2011) +- Mention that sftp quote commands can be quoted + +Daniel Stenberg (25 Jan 2011) +- tests: more multiple headers checks + +- HTTP: memory leak on multiple Location: + + The HTTP parser allocated memory on each received Location: header + without properly freeing old data. Starting now, the code only considers + the first Location: header and will blissfully ignore subsequent ones. + + Bug: http://curl.haxx.se/bug/view.cgi?id=3165129 + Reported by: Martin Lemke + +- FAQ: clarify 5.13 how to stop a transfer + +Guenter Knauf (22 Jan 2011) +- Fixed C++ style comment not allowed in ISO C90. + +Dan Fandrich (21 Jan 2011) +- Mention axTLS in some more documentation + +Daniel Stenberg (20 Jan 2011) +- runtests.pl: make -s not show skipped tests + +- [Amr Shahin brought this change] + + unittest: add 3 tests to test1300 + + Testing Curl_llist_insert_next + +Dan Fandrich (20 Jan 2011) +- [Darshan Mody brought this change] + + Fixed compile using OpenSSL versions < 0.9.4a + +Daniel Stenberg (19 Jan 2011) +- main: make the tlsauth options always present + + ... to not make the connection between the tool and the libcurl used + tighter than necessary, the tlsauth options are now always present but + if the used libcurl doesn't have TLSAUTH support it will return failure. + + Also, replaced strncmp() with strequal to get case insensitive matching. + +- symbols-in-versions: add the new TLSAUTH-SRP symbols + +- configure: TLS-SRP wasn't added as a feature + + Test case 1014 failed since TLS-SRP was correctly set to the features + variable so curl-config --features didn't output it. + +- dist: add new certs to tarball + +- [Quinn Slack brought this change] + + TLS-SRP: support added when using GnuTLS + +- CURLOPT_SSL_VERIFYPEER: more clarifications + + The default value is 1. + + curl _uses_ a default CA bundle, it doesn't install one. + + Drop the references to 7.10 as that is now >8 years old! + +- TheArtOfHttpScripting: extended + + Extended the intial HTTP protcol part and added a mention of --trace and + --trace-ascii. + + Replaced most URLs in the text to use example.com instead of all the + made up strange names. + + Shortened a bunch of lines. + +- curl_easy_setopt.3: clarify VERIFYHOST/PEER + + Extended the descriptions somewhat and made the options get listed next + to each other. + +- RELEASE-NOTES: mention contributors + +- RELEASE-NOTES: synced with 7fcbdd68b9e + +Guenter Knauf (18 Jan 2011) +- Fixed configure define for Win32. + + Submitted by Vincent Torri. + +Kamil Dudka (18 Jan 2011) +- nss: fix a bug in handling of CURLOPT_CAPATH + + ... and update the curl.1 and curl_easy_setopt.3 man pages such that + they do not suggest to use an OpenSSL utility if curl is not built + against OpenSSL. + + Bug: https://bugzilla.redhat.com/669702 + +Guenter Knauf (17 Jan 2011) +- Avoid redefines. + +Daniel Stenberg (15 Jan 2011) +- curl.1: fix spelling + + Bug: http://curl.haxx.se/bug/view.cgi?id=3157232 + Reported by: John Bradshaw + +Guenter Knauf (14 Jan 2011) +- Added casts to silent gcc warnings. + +Yang Tse (13 Jan 2011) +- build: BCC - makefile.b32 tweak + + Get rid of stdout redirection to NUL and move stderr redirection + into RM and RMDIR macros. + +- build: BCC - makefile.b32 tweak + + Check for BCCDIR environment var done now as other checks. + +Guenter Knauf (13 Jan 2011) +- Use env var for PSDK instead of hardcoded path. + +- Enabled SSPI support by default. + +- Use MAKE macro with BCC targets. + +Yang Tse (12 Jan 2011) +- docs - update BCC INSTALL section + +- build: BCC - require Borlands's MAKE for Makefile.b32 processing. + +- build: BCC - recover lost functionality from commit 3d813204260b37289411 + + Borland's $(MAKEDIR) expands to the path where make.exe is located, + use this feature to define BCCDIR when user has not defined BCCDIR. + +- build: use external preprocessor cpp32 when building with Borland C + +- build: allow usage of Borland 5.5.1 external preprocessor cpp32 + +Guenter Knauf (11 Jan 2011) +- Disable LDAP support since BCC headers are insufficient. + +- Instead of exiting with error lets set BCCDIR self. + +- Some Borland C++ makefile tweaks. + +- Borland C++ doesnt have struct sockaddr_storage. + +Daniel Stenberg (11 Jan 2011) +- connect: use UDP correctly + + The idea that the protocol and socktype is part of name resolving in the + libc functions is nuts. We keep the name resolver functions assume + TCP/STREAM and we make sure that when we want to connect to a UDP + service we use the correct UDP/DGRAM set instead. This bug was because + the ->protocol field was not always set correctly. + + This bug was only affecting ipv6-disabled non-cares non-threaded builds. + + Bug: http://curl.haxx.se/bug/view.cgi?id=3154436 + Reported by: "dperham" + +- [Quinn Slack brought this change] + + SSL: fix memory leak + + In OOM situation. Follow-up fix to commit a9cd4f4ed49e1a0. + +- gtls: fix memory leak + + Bug: http://curl.haxx.se/mail/lib-2011-01/0079.html + Reported by: Quinn Slack + +- [Marcel Roelofs brought this change] + + HTTP: HTTP Negotiate authentication using SSPI + + Only under Windows + +- cmake: removed two files + + CMake/CheckTypeSize.c.in and CMake/CheckTypeSize.cmake were removed in + the previous cmake commit + +Dan Fandrich (5 Jan 2011) +- Made unit_setup() return an error code to abort the test early + + This makes it possible to skip the call to unit_stop() in such + cases. Also use Curl_safefree() in unit test 1302 so it will + pass the memory torture test. + +Daniel Stenberg (6 Jan 2011) +- SSH: speedcheck clobbered existing error + + The just added speedcheck must not ruin the error code if already set + due to a problem. + +- [Brad King brought this change] + + CMake: Use upstream CheckTypeSize module + + The CheckTypeSize module that comes with CMake 2.6.2 and above does + everything we need and also supports cross-compiling. Avoid duplicating + an older version of it here. This also fixes a cross-compiling error + because the old line + + include ("${CMAKE_MODULE_PATH}/CheckTypeSize.cmake") + + failed because CMAKE_MODULE_PATH is a search path and not a directory. + + Signed-off-by: Brad King + +- SSH: acknowledge speedcheck + + Check for speedcheck limits during the state machine traversals + +- tests: tag corrections + +- unittest: 1303 tests Curl_timeleft + + I came up with 33 different ways to call it and verify that it returns the + correct return code. + +- curlcheck.h: add fail() + + fail is a new function/macro that a test case can use to indicate a test + failure for cases when the standard macros are not sufficient. + +- Curl_timeleft: s/conn/data in first argument + + As the function doesn't really use the connectdata struct but only the + SessionHanadle struct I modified what argument it wants. + +Dan Fandrich (4 Jan 2011) +- Fixed path to allow out-of-tree builds + +Kamil Dudka (4 Jan 2011) +- nss: avoid CURLE_OUT_OF_MEMORY given a file name without any slash + + Bug: https://bugzilla.redhat.com/623663 + +Daniel Stenberg (4 Jan 2011) +- ignore: all executable unit test cases + +- tests: add 1302 to the package + +- unittest: test base64 encode/decode + +- curlcheck.h: avoid using NULL pointers + +- curlcheck.h: add verify_memory + + This check verifies that a pointer contains the correct data. + +- curlcheck.h: add newlines in error messages + +- unittest: verify curl_strequal + +- get_cert_chain: support larger data sets + + 512 bytes turned out too short for some data, so now we allocate a + larger buffer instead + + Bug: http://curl.haxx.se/mail/archive-2011-01/0002.html + +- RELEASE-NOTES: synced with 83e9fb21aabbec2 + +- curlcheck.h: add fail_if() fix code + + The UNITTEST_START and UNITTEST_STOP defines needed to do a new brace + level so that test cases can declare variables fine and still remain + fine C89 code. + +- unittests: basic docs + +- ignore: unit test files + +- unittests: a dedicated feature in tests + + The test runner script now knows if unittests can run and the unit test + setup file says it is one. I also made runtests.pl deal with no + tag set, so that the description file can get even simpler. + +- unittesting: build a separate static lib + + When configure --enable-debug has been used, all files in lib/ are now + built twice and a separate static library crafted for unit-testing will + be linked. The unit tests in the tests/unit subdir will use that + library. + +- unittest: framework for unit-testing + + This is the first approach at doing fairly clean and easy to write and + debug unit tests. + +- SSH: avoid PATH_MAX with alloc + + We cannot assume that PATH_MAX will be enough for the remote path name + so allocating room for it is the only sensible approach. + +- TODO: get rid of PATH_MAX + +- Curl_nss_connect: avoid PATH_MAX + + Since some systems don't have PATH_MAX and it isn't that clever to + assume a fixed maximum path length, the code now allocates buffer space + instead of using stack. + + Reported by: Samuel Thibault + Bug: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=608521 + +- SFTP: make pwd output result to header callback + + Sending "pwd" as a QUOTE command only sent the reply to the + DEBUGFUNCTION. Now it also sends an FTP-like header to the header + callback to allow similar operations as with FTP, and apps can re-use + the same parser. + +- pubkey_show: allocate buffer to fit any-size result + + The loop condition was wrong so keys larger than 340 bits would overflow + the local stack-based buffer. + +- CURLINFO_FTP_ENTRY_PATH: sftp support + +- [Luke Amery brought this change] + + ssh: honour the CURLINFO_FTP_ENTRY_PATH curl_getinfo option + +- [Pierre Joye brought this change] + + IDN: use win32 API if told to + + The functionality is provided in a new source file: lib/idn_win32.c + +Yang Tse (28 Dec 2010) +- test harness: take in account that Windows does not support LD_PRELOAD + + configure.ac: Test harness libhostname library will not be built for Windows. + + runtests.pl: LD_PRELOAD mechanism will not be used to load libhostname + library on operating systems which lack LD_PRELOAD support. + +Daniel Stenberg (27 Dec 2010) +- c-ares: fix cancelled resolves + + When built IPv6-enabled, we could do Curl_done() with one of the two + resolves having returned already, so when ares_cancel() is called the + resolve callback ends up doing funny things (sometimes resulting in a + segfault) since it would try to actually store the previous resolve even + though we're shutting down the resolve. + + This bug was introduced in commit 8ab137b2bc9630ce so it hasn't been + included in any public release. + + Bug: http://curl.haxx.se/bug/view.cgi?id=3145445 + Reported by: Pedro Larroy + +- [Brad Hards brought this change] + + Typo / spelling fixes. + +- [Brad Hards brought this change] + + Use angle address, as for the rest of the example. + + Also spelling fix for RECIPIENT #define. + +- [Brad Hards brought this change] + + Add angle brackets to addresses in easy SMTP examples, as for smtp-multi example. + +- cookies: tricked dotcounter fixed + + Providing multiple dots in a series in the domain field (domain=..com) could + trick the cookie engine to wrongly accept the cookie believing it to be + fine. Since the tailmatching would then match all .com sites, the cookie would + then be sent to all of them. + + The code now requires at least one letter between each dot for them to be + counted. Edited test case 61 to verify this. + +- multi: connect fail => use next IP address + + When using the multi interface and connecting to a host name that + resolves to multiple IP addresses, there was no logic that made it + continue to the next IP if connecting to the first address times + out. This is now corrected. + +- smtp-multi: put recipient within + + Even if libcurl might to do it for us, it is more correct. + +- ossl_seed: no more RAND_screen + + RAND_screen() is slow, not thread-safe and not needed anymore since OpenSSL + uses the thread-safe win32 CryptoAPI nowadays. + +- multi: inhibit some verbose outputs + + The info about pipe status and expire cleared are clearly debug-related + and not anything mere mortals will or should care about so they are now + ifdef'ed DEBUGBUILD + +- SMTP tests: updated MAIL FROM use + + They were all wrong previously since none used the they + should for MAIL FROM. Now libcurl adds them itself if the app doesn't so + they end up wrong less easy. + +- CURLOPT_MAIL_FROM: document the bracket situation + +- [Brad Hards brought this change] + + SMTP: add brackets for MAIL FROM + + Similar to what is done already for RCPT TO, the code now checks for and + adds angle brackets (<>) around the email address that is provided for + CURLOPT_MAIL_RCPT unless the app has done so itself. + +Guenter Knauf (22 Dec 2010) +- Added support for axTLS to NetWare build. + +- Fixed include: memory.h -> curl_memory.h. + +Kamil Dudka (22 Dec 2010) +- [Brad Hards brought this change] + + smtp-tls: add a missing newline + + Without this you won't get the next (Subject) line. + +Daniel Stenberg (21 Dec 2010) +- [Brad Hards brought this change] + + Typo fixes. + +Patrick Monnerat (21 Dec 2010) +- New curl/curl.h definitions added to ILE/RPG binding. + +Yang Tse (21 Dec 2010) +- build: sort configuration hunks in lib/Makefile.vc6 + + sorted to reflect same internal order as the one shown + in the usage message. + +Daniel Stenberg (20 Dec 2010) +- getparameter: add error check + + if add2list() returns an error, bail out! + +- loadhostpairs: return errorcode + + Make sure that Curl_cache_addr() errors are propagated to callers of + loadhostpairs(). + + (this loadhostpairs function caused a scan-build warning due to the + 'dns' variable getting assigned but never used) + +Yang Tse (20 Dec 2010) +- distrib: add new file to EXTRA_DIST + +- build: refactoring of msvc makefiles to allow overriding of library filenames. + + Default libcurl's file names are kept equal to those used since Y2K. + +Daniel Stenberg (19 Dec 2010) +- ftp_parselist: fix compiler warning + + Doing curlx_strtoofft() on the size just to figure out the end of it + causes a compiler warning since the result wasn't used, but is also a + bit of a waste. + +- [Pasha Kuznetsov brought this change] + + Curl_do: avoid using stale conn pointer + + Since the original `conn' pointer was used after the `connectdata' it + points to has been closed/cleaned up by Curl_reconnect_request it caused + a crash. We must make sure to use the newly created connection instead! + + URL: http://curl.haxx.se/mail/lib-2010-12/0202.html + +- [Tommie Gannert brought this change] + + ares: ask for both IPv4 and IPv6 addresses + + Make the c-ares resolver code ask for both IPv4 and IPv6 addresses when + IPv6 is enabled. + + This is a workaround for the missing ares_getaddrinfo() and is a lot + easier to implement. + + Note that as long as c-ares returns IPv4 addresses when IPv6 addresses + were requested but missing, this will cause a host's IPv4 addresses to + occur twice in the DNS cache. + + URL: http://curl.haxx.se/mail/lib-2010-12/0041.html + +- examples: socket type cleanup + +- [Brad Hards brought this change] + + Trival comment fix. + +- [Brad Hards brought this change] + + smtp-tls: add Message-ID: header + +- gitignore: ignore the new example execs + +- examples: fix compiler warnings + +- examples: build all examples easier + +- [Brad Hards brought this change] + + smtp-tls: new example + + This example shows how to send SMTP with TLS + +- [Brad Hards brought this change] + + Docs: add simple SMTP example + + Add a simple SMTP example program, patterned after some of the existing + examples, and the curl application. + + This version addresses issues raised by David Woodhouse on comments in + the simplesmtp.c example. + +Kamil Dudka (17 Dec 2010) +- [Paul Howarth brought this change] + + tftpd: avoid buffer overflow report from glibc + +Daniel Stenberg (17 Dec 2010) +- example: fix compiler warnings in fopen.c + +- [Brad Hards brought this change] + + chkspeed: bad strtol() call for -M option + + Bug: http://curl.haxx.se/mail/lib-2010-12/0192.html + +Yang Tse (16 Dec 2010) +- axTLS integration: silence runtests.pl perl warning + +Daniel Stenberg (15 Dec 2010) +- axTLS: mention it among the other SSL libs + +- 7.21.4: version bump + +- axtls_connect: allow connect without peer verification + + The SSL_SERVER_VERIFY_LATER bit in the ssl_ctx_new() call allows the + code to verify the peer certificate explicitly after the handshake and + then the "data->set.ssl.verifypeer" option works. + +- axTLS: allow "default" SSL version as well + + When no explicit version is selected we should try to use whatever is + best for us, and in the axTLS case that means TLSv1. + +- axtls.c: cleanup + + Removed trailing whitespace + Removed several compiler warnings + Removed odd backslashes at some line endings + +- urldate: undef hideous memory defines + + The public axTLS header (at least as of 1.2.7) redefines the memory + functions. We #undef those again immediately after the public header to + limit the damage. This should be fixed in axTLS. + +- configure: make --with-axtls set prefix + + In tradition with other options, have this point to the directory prefix + and not the lib directory. Otherwise we can't set the include path + reliably. + +- [Eric Hu brought this change] + + Minor fixes to pass tests 301 and 306 with a patched axTLS. + +- [Eric Hu brought this change] + + Initial axTLS integration. Connections can be made and some tests pass. + + Failed HTTPS tests: 301, 306, 311, 312, 313, 560 + 311, 312 need more detailed error reporting from axTLS. + 313 relates to CRL, which hasn't been implemented yet. + +- [Eric Hu brought this change] + + Simple update to configure script to notify user of --with-axtls switch. + +- [Eric Hu brought this change] + + Preparing for axTLS. Actual SSL API functions are only stubbed. + + Added axTLS to autotool files and glue code to misc other files. + axtls.h maps SSL API functions, but may change. + axtls.c is just a stub file and will definitely change. + +- THANKS: added contributors from 7.21.3 + +Version 7.21.3 (15 Dec 2010) + +Daniel Stenberg (15 Dec 2010) +- RELEASE-NOTES: synced with a865bd9fbaaa43e5c + +- IsPipeliningPossible: only for HTTP + + The function that checks if pipelining is possible now requires the HTTP + bit to be set so that it doesn't mistakenly tries to do it for other + protocols. + + Bug: http://curl.haxx.se/mail/lib-2010-12/0152.html + Reported by: Dmitri Shubin + +- multi_runsingle: don't timeout completed handles + + The generic timeout code must not check easy handles that are already + completed. Going to completed (again) within there risked decreasing the + number of alive handles again and thus it could go negative. + + This regression bug was added in 7.21.2 in commit ca10e28f06f1 + +- symbols-in-versions: CURLOPT_KEYPASSWD fixed + + It was added in 7.17.0 and is not deprecated + +- RELEASE-NOTES: synced with c28443c551825 + +Dan Fandrich (8 Dec 2010) +- Mention that using other libraries can affect app licensing + +Yang Tse (7 Dec 2010) +- easy: fix compiler warning: end-of-loop code not reached + +Daniel Stenberg (6 Dec 2010) +- disconnect: pass on the dead_connection argument + + Cleanup fix after Kamil's commit 5c7c9a768d0093 + +Yang Tse (6 Dec 2010) +- sws: fix compier warning: external definition with no prior declaration + +Daniel Stenberg (6 Dec 2010) +- [Heinrich Ko brought this change] + + ossl_connect_common: detect connection re-use + + ossl_connect_common() now checks whether or not 'struct + connectdata->state' is equal 'ssl_connection_complete' and if so, will + return CURLE_OK with 'done' set to 'TRUE'. This check prevents + ossl_connect_common() from creating a new ssl connection on an existing + ssl session which causes openssl to fail when it tries to parse an + encrypted TLS packet since the cipher data was effectively thrown away + when the new ssl connection was created. + + Bug: http://curl.haxx.se/mail/lib-2010-11/0169.html + +Kamil Dudka (6 Dec 2010) +- url: provide dead_connection flag in Curl_handler::disconnect + + It helps to prevent a hangup with some FTP servers in case idle session + timeout has exceeded. But it may be useful also for other protocols + that send any quit message on disconnect. Currently used by FTP, POP3, + IMAP and SMTP. + +Yang Tse (6 Dec 2010) +- ssh: fix a download resume point calculation + +Daniel Stenberg (5 Dec 2010) +- Curl_wait_for_resolv: correct timeout + + When looping in this function and checking for the timeout being + expired, it was not updating the reference time when calculating the + timediff since previous round which made it think each subsequent loop + to have taken longer than it actually did. + + I also modified the function to use the generic Curl_timeleft() function + instead of the custom logic. + + Bug: http://curl.haxx.se/bug/view.cgi?id=3112579 + +- Curl_send/recv_plain: return errno on failure + + When send() and recv() fail, we now store the errno value to allow the + app to access it. + + Bug: http://curl.haxx.se/bug/view.cgi?id=3128121 + Reported by: Yuri + +Guenter Knauf (5 Dec 2010) +- Updated OpenSSL version. + +Yang Tse (4 Dec 2010) +- fix compiler warning: conversion may lose significant bits + +- fix compiler warning: assignment within conditional expression + +- fix getinfo CURLINFO_LOCAL* for reused connections (take 2) follow-up + + - Show address string from proper buffer in case of connection failure. + + - Try next address when inet_ntop() fails. + +Daniel Stenberg (3 Dec 2010) +- version-check: added brief documentation + + and the traditional source header + +Yang Tse (3 Dec 2010) +- build: provide SIZEOF_SIZE_T DOS definition + +- build: lib/config.dos renamed to lib/config-dos.h + +- build: provide SIZEOF_SIZE_T VMS definition + +- build: move config-vms.h from subdir 'packages/vms' into 'lib' + +- build: provide SIZEOF_SIZE_T definition for non-configure builds + +- build: provide SIZEOF_SIZE_T netware definition + +- configure: undo using autobuilds to temporarily verify strict aliasing warnings. + +- fix compiler warning: rounding, sign extension, or loss of accuracy may result + +- fix compiler warning: statement is not reachable + +- fix compiler warning: conversion may lose significant bits + +- connect: fix compiler warning: unused variable + +- fix getinfo CURLINFO_LOCAL* for reused connections (take 2) + +- fix getinfo CURLINFO_LOCAL* for reused connections follow-up + + Reinstate IPV6 build variable that got removed. + +- fix getinfo CURLINFO_LOCAL* for reused connections + + Failed to commit this file changes along with the others. + +- fix getinfo CURLINFO_LOCAL* for reused connections + +- atoi: remove atoi usage + +- multi: fix compiler warning: conversion may lose significant bits follow-up + +- ftp: fix 'bool' data type implementation dependant usage + +- multi: fix compiler warning: conversion may lose significant bits + +- multi: fix compiler warning: enumerated type mixed with another type + +- hostip: edit comment + +- xattr: fix compiler warning: enumerated type mixed with another type + +- s/isspace/ISSPACE + +- symbol-scan: use configure script knowledge about how to run the C preprocessor + +- ignore file generated by configure + +- curl_multi_info_read: fix compiler warning: conversion may lose significant bits + +- inet_pton: fix compiler warning + + warning C4146: unary minus operator applied to unsigned type, result still unsigned + +- Curl_getaddrinfo_ex: sanitize function results follow-up. + +- Curl_getaddrinfo_ex: sanitize function results. + + Ensure that spurious results from system's getaddrinfo() ares not propagated + by Curl_getaddrinfo_ex() into the library. + + Also ensure that the ai_addrlen member of Curl_getaddrinfo_ex()'s output linked + list of Curl_addrinfo structures has appropriate family-specific address size. + +Kamil Dudka (22 Nov 2010) +- openldap: use remote port in URL passed to ldap_init_fd() + + ... not the proxy port. It makes no difference unless a proxy is used. + +Yang Tse (20 Nov 2010) +- gtls: define and use gtls_EAGAIN, gtls_EINTR and gtls_EIO. + + Winsock builds clobber some errno.h defines in setup_once. + +Dan Fandrich (19 Nov 2010) +- Added a couple examples that were missing from the tar ball + +- Check for errors while preprocessing curl.h in test 1119 + + This showed a problem when running the test out-of-tree, so + an include path is now being added to pick up the generated + curlbuild.h file. + +- Use the 3-argument open for compatibility with older perls + +- [Matthias Bolte brought this change] + + Detect socket errors in GnuTLS on Windows + + On Windows, translate WSAGetLastError() to errno values as GNU + TLS does it internally, too. This is necessary because send() and + recv() on Windows don't set errno when they fail but GNU TLS + expects a proper errno value. + + Bug: http://curl.haxx.se/bug/view.cgi?id=3110991 + +Yang Tse (19 Nov 2010) +- test servers: fix strict aliasing compiler warnings + +- configure: use autobuilds to temporarily verify strict aliasing warnings. + + Temporarily, When cross-compiling with gcc 3.0 or later, enable strict aliasing + rules and warnings. Given that cross-compiled targets autobuilds do not run the + +Julien Chaffraix (17 Nov 2010) +- configure: Prevent link errors with --librtmp. + + If --librtmp was specified but pkg-config could not find the librtmp + file, we would have undefined symbols when linking curl. + + We prevent this error by disabling this case as suggested on the mailing + list. + +Daniel Stenberg (15 Nov 2010) +- RELEASE-NOTES: synced with cbf4961bf3e4 + +- gnutls->handshake: improved timeout handling + + When no timeout is set, we call the socket_ready function with a timeout + value of 0 during handshake, which makes it loop too much/fast in this + function. It also made this function return CURLE_OPERATION_TIMEDOUT + wrongly on a slow handshake. + + However, the particular bug report that highlighted this problem is not + solved by this fix, as this fix only makes the more proper error get + reported instead. + + Bug: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=594150 + Reported by: Johannes Ernst + +Julien Chaffraix (13 Nov 2010) +- urldata: Capitalize enum protect_level values. + + This makes it easier to spot the enum values from the variables. + Removed some unneeded DEBUGASSERT added in the previous commit. + +- security: tighten enum protection_level usage. + + While changing Curl_sec_read_msg to accept an enum protection_level + instead of an int, I went ahead and fixed the usage of the associated + fields. + + Some code was assuming that prot_clear == 0. Fixed those to use the + proper value. Added assertions prior to any code that would set the + protection level. + +Yang Tse (13 Nov 2010) +- configure: fix autoconf 2.68 warning: no AC_LANG_SOURCE call detected in body + +Daniel Stenberg (12 Nov 2010) +- curl.1: "a file", not an + +- version-check.pl: display version number for symbols + + This script is the start of a helper tool that scans a source code and + outputs the most recent libcurl version it finds symbols for. Meaning + that if there's no conditions in the code, that's the earliest libcurl + version the scanned code requires. + + It is not added to the Makefile.am yet as it is still a bit crude, but + I'm committing it to keep it and allow us to work on it. + +- [Adam Light brought this change] + + Makefile.vc6: fixed the xattr.c compile + +Julien Chaffraix (12 Nov 2010) +- krb5: Use GSS_ERROR to check for error. + + This is the advised way of checking for errors in the GSS-API RFC. + Also added some '\n' to the error message so that they are not mixed + with other outputs. + +- security: Pass the right parameter to init. + + init is expecting app_data. Passing it the struct connecdata would make + us crash later. + +Daniel Stenberg (11 Nov 2010) +- HTTP Auth: Add CURLAUTH_ONLY + + This is a meta symbol. OR this value together with a single specific + auth value to force libcurl to probe for un-restricted auth and if not, + only that single auth algorithm is acceptable. + + For example you can use CURLAUTH_DIGEST|CURLAUTH_ONLY to make libcurl + first probe for what method to use, but yet only consider Digest to be + acceptable. + + Using _only_ CURLAUTH_DIGEST without the CURLAUTH_ONLY field, will make + libcurl explicitly use Digest right away and not do any probing. + +- ip_version: moved to connection struct + + The IP version choice was previously only in the UserDefined struct + within the SessionHandle, but since we sometimes alter that option + during a request we need to have it on a per-connection basis. + + I also moved more "init conn" code into the allocate_conn() function + which is designed for that purpose more or less. + +Yang Tse (11 Nov 2010) +- buildconf: MAC OS X requires libtool version 1.5.26 or newer + + MAC OS X requires libtool version 1.5.26 or newer, otherwise + configure will mishandle *.dSYM directories when it runs. + +- configure: remove temporary autobuilds exercising of xattr function tests + +- configure: use autobuilds to temporarily exercise xattr function tests + +- xattr: portability fix + +- curl-functions: provide xattr function tests that also check number of arguments + +Daniel Stenberg (10 Nov 2010) +- test1120: verify FTP response 421 + + curl mustn't try to use the control connection after the 421 is received + +- ftpserver.pl: spellfix comment + +- [Rutger Hofman brought this change] + + TFTP: resend the correct data + + I found a bug in tftp_tx() in tftp.c. If a data resend is done after + reception of an ACK/OACK, the call to sendto is wrong. + +- [Stefan Tomanek brought this change] + + write extended attributes by using fsetxattr + + Instead of reopening the downloaded file, fsetxattr uses the (already + open) file descriptor to attach extended attributes. This makes the + procedure more robust against errors caused by moved or deleted files. + +Dan Fandrich (9 Nov 2010) +- Check for getinfo errors before setting attributes + +Kamil Dudka (9 Nov 2010) +- ftp: treat server's response 421 as CURLE_OPERATION_TIMEDOUT + + Bug: https://bugzilla.redhat.com/650255 + Reported by: Simon H. + +Daniel Stenberg (9 Nov 2010) +- symbols-in-version: add CURL_SOCKET_BAD + + I also documented the filtering logic in the symbol-scan.pl function to + clarify why not all CURL_* symbols are included. + +Yang Tse (9 Nov 2010) +- serial number bump + +Kamil Dudka (8 Nov 2010) +- ftp: close connection as soon as ABOR has been sent + + ... and do not send ABOR unless really necessary. + + Bug: https://bugzilla.redhat.com/649347 + Reported by: Simon H. + +Daniel Stenberg (8 Nov 2010) +- RELEASE-NOTES: synced with fc6c4c10f9faab08 + + I also recounted and updated the command line and libcurl options. + +- help: indent the --xattr option like the others + +- curl.1: --resolve documented + +- CURLOPT_RESOLVE: documented + +- CURLOPT_USE_SSL: move from FTP options to connection options + +- xattr-check: correct the comment as well + +- xattr: use const char * for const strings + +- setxattr: fix the checks + + My copy and paste job was a little too much copy and I missed to adjust + it properly to sys/xattr.h all over and this is a fix to cure that. + +- CURLOPT_RESOLVE: added + + CURLOPT_RESOLVE is a new option that sends along a curl_slist with + name:port:address sets that will populate the DNS cache with entries so + that request can be "fooled" to use another host than what otherwise + would've been used. Previously we've encouraged the use of Host: for + that when dealing with HTTP, but this new feature has the added bonus + that it allows the name from the URL to be used for TLS SNI and server + certificate name checks as well. + + This is a first change. Surely more will follow to make it decent. + +Yang Tse (8 Nov 2010) +- fix compiler warning + +Dan Fandrich (7 Nov 2010) +- Added os-specific.c and xattr.c to the Symbian build files + +Yang Tse (7 Nov 2010) +- xattr: fix VisualStudio builds + +- fix snapshot generation + +Daniel Stenberg (5 Nov 2010) +- --libcurl: simplify output + + Removed the code that was needed for libcurl before 7.19.0 which now is + more than two years old. + + Simplified the top comment and corrected the URL. + +- [Alfred Gebert brought this change] + + LDAP: detect non-binary attributes properly + + If the query result has a binary attribute, the binary attribute is + base64 encoded. But all following non binary attributes are also base64 + encoded which is wrong. + + This is a test (LDAP server is public). + + curl + ldap://x500.bund.de:389/o=Bund,c=DE?userCertificate,certificateSerialNumber?sub + ?cn=*Woehleke* + +- xattr: add configure check and #ifdefs + + setxattr is a glibc call to set extended attributes, so configure now + checks for it and the code is adapted to only build when the + functionality is present. + +- [Stefan Tomanek brought this change] + + save metadata to extended file attributes + + It is often convinient to track back the source of a once downloaded + file; this patch makes curl store the source URL and other metadata + alongside the retrieved file by using the extended attributes (if + supported by the file system and enabled by --xattr). + +- test: remove test 580 + + Test 580 is removed again for two reasons: + + 1) Some compilers aren't satisfied by just a data variable called 'test' + when first.o wants a function called 'test'. The Solaris compiler says + "ld: warning: symbol `test' has differing types:" while the AIX compiler + downright rejects it. + + 2) Test case 1119 that was added after this test is way more complete + and cover everything test 580 does and more without introducing the same + problems. + +- Revert: use Host: name for SNI and cert name checks + + This reverts commit b0fd03f5b8d4520dd232a9d13567d16bd0ad8951, + 4b2fbe1e97891f, afecd1aa13b4f, 68cde058f66b3 + +- TODO-RELEASE: "TLS SNI use Host:" is done + + 262 - Manual setting of TLS Server Name Indication - use Host: + +- RELEASE-NOTES: synced with 7b823badbcab9d330 + +- curl.1: added a few missing exit codes + +- certcheck: use the custom Host: name for checks + + If you use a custom Host: name in a request to a SSL server, libcurl + will now use that given name when it verifies the server certificate to + be correct rather than using the host name used in the actual URL. + +- SNI: simplify the custom host name use + + The redirect check is already done at the position where the customhost + field is assigned so there's no point in doing that a second time. + +- host: get the custom Host: name more genericly + + When given a custom host name in a Host: header, we can use it for + several different purposes other than just cookies, so we rename it and + use it for SSL SNI etc. + +- [Hongli Lai (Phusion) brought this change] + + SNI: set name to custom Host header + + OpenSSL SNI host name should be set to the custom Host header, if the + user provided one. + +- fopen.c: re-indented, fixed previous mistake + + I've made the code intended using curl-style now to look more like other + examples. + + My previous "fix" was a bit too invasive but is now fixed again. + +- multi use: call multi_perform even on select() timeouts + +- example: add smtp-multi.c + + An example application source code sending SMTP mail with the multi + interface. It is based on the code Alona Rossen provided, which in turn + is based on existing example/test code, and I converted it even more + into a decent example with a fair multi API use, put the info required + to edit at the top and I added some comments. + +- CURLOPT_NOSIGNAL: add blurb about SIGPIPE + +Dan Fandrich (3 Nov 2010) +- Allow building test 580 out of tree + +Daniel Stenberg (3 Nov 2010) +- dist: add symbol-scan.pl to the tarball + +- test1119: verify symbols-in-versions + +- runtests: allow tests written as perl scripts + + If a command is set type="perl", it can now specify a perl program that will + be run instead of an ordinary curl or built tool. + + A perl test automatically disables memory and valgrind debugging. + +- symbol-scan: verifies symbols-in-versions + + This new script scans for all enums and #defines used by the curl/curl.h + and curl/multi.h headers. Then it reads all symbols mentioned in + symbols-in-vesions and make sure that there's no entries missing in + there. It then proceeds to verify that the entries that + symbols-in-vesions mentions but aren't found in the sources are truly + documented as removed. + + This script is used in the new test case 1119 + +- symbols-in-versions: added 119 missing symbols + + I've developed a script I call symbol-scan.pl that scans the curl.h and + multi.h header files and compare the symbols it finds in there with the + symbols symbols-in-versions documents and outputs a report on the + differences. Using this I've dug through the history to fill up + symbols-in-versions with all the symbols my script found mismatches for. + + I will commit symbol-scan.pl separatly and think of a way to put it to + use in the build/tests so that we from now on will get this in-sync + check automatically. + +Dan Fandrich (2 Nov 2010) +- Added mk580.pl to the tar ball + +Daniel Stenberg (2 Nov 2010) +- symbols-in-versions: added missing symbols + +- ignore: lib580.c is generated by mk580.pl + +- test: added test 580 - verifies symbols-in-versions + + The new perl script mk580.pl generates a C table in a fresh source file + named lib580.c and if that compiles fine we know that the file + docs/libcurl/symbols-in-versions at least doesn't include any symbols + that are misspelled. + + An additional feature would be to somehow scan curl/curl.h and compare + with symbols-in-versions to see if there are symbols missing. + +- spellfix: CURLOPT_TFTP_BLKSIZE it is + +Kamil Dudka (29 Oct 2010) +- ftp: prevent server from hanging on closed data connection + + Some FTP servers (e.g. Pure-ftpd) end up hanging if we close the data + connection before transferring all the requested data. If we send ABOR + in that case, it prevents the server from hanging. + + Bug: https://bugzilla.redhat.com/643656 + Reported by: Pasi Karkkainen, Patrick Monnerat + +Dan Fandrich (28 Oct 2010) +- Removed a leftover mention of FTP in an error message + +- Removed the native Makefile.riscos files + + These haven't worked in at least 8 years due to missing source + files, and most active RiscOS developers these days apparently + cross-compile anyway. + + Signed-off-by: James Bursa + +- Lightened the stack in wc_statemach to permit deeper recursion + + Also, added a few hints to help compilers to perform tail call + recursion optimization. + +Daniel Stenberg (20 Oct 2010) +- SSH: use libssh2_session_handshake() + + In libssh2 1.2.8, libssh2_session_handshake() replaces + libssh2_session_startup() to fix the previous portability problem with + the socket type that was too small for win64 and thus easily could cause + crashes and more. + +- SSH: avoid using the libssh2_ prefix + + It is a bad idea to use the public prefix used by another library and + now we realize that libssh2 introduces a symbol in the upcoming version + 1.2.8 that conflicts with our static function named libssh2_free. + +- formdata: provide error message + + When failing to build form post due to an error, the code now does a + proper failf(). Previously libcurl would report an error like "failed + creating formpost data" when a file wasn't possible to open which was + not easy for users to figure out. + + I also lower cased a function name to be named more curl-style and + removed some unnecessary code. + +- URL-parsing: consider ? a divider + + The URL parser got a little stricter as it now considers a ? to be a + host name divider so that the slightly sloppier URLs work too. The + problem that made me do this change was the reported problem with an URL + like: www.example.com?email=name@example.com This form of URL is not + really a legal URL (due to the missing slash after the host name) but is + widely accepted by all major browsers and libcurl also already accepted + it, it was just the '@' letter that triggered the problem now. + + The side-effect of this change is that now libcurl no longer accepts the + ? letter as part of user-name or password when given in the URL, which + it used to accept (and is tested in test 191). That letter is however + mentioned in RFC3986 to be required to be percent encoded since it is + used as a divider. + + Bug: http://curl.haxx.se/bug/view.cgi?id=3090268 + +- curl_easy_setopt.3: spellfix + +- curl_easy_setopt.3: CURLOPT_USE_SSL is not just for FTP + + It is for FTP, SMTP, POP3, IMAP at least. + +- krb4.h: removed unused prototypes + +- krb4: make a few functions static + +- TODO-RELEASE: cleanup for 7.21.3 works + + "SFTP resume with 4GB file does not work" is now removed as I'm sure + this is really a libssh2 bug and not a libcurl bug. + + 7.21.2 is released already + +- RELEASE-NOTES: sync with 09a2d93a0f17ca + +- http_chunks: remove debug output + + Accidentally left in there during my previous debugging of this + +- Curl_setopt: disallow CURLOPT_USE_SSL without SSL support + + In order to avoid for example the pingpong protocols to issue STARTTLS + (or equivalent) even though there's no SSL support built-in. + + Reported by: Sune Ahlgren + Bug: http://curl.haxx.se/mail/archive-2010-10/0045.html + +- options: check for features for some options + + Some options, such as the automatic decompression and some SSL related + ones now will bail out if the underlying libcurl doesn't have support + for the particular feature needed. + +Dan Fandrich (14 Oct 2010) +- Fixed the IPv6 host address in test1203 + + Reported by: Christian Weisgerber + Bug: http://curl.haxx.se/bug/view.cgi?id=3087479 + +Daniel Stenberg (14 Oct 2010) +- curl_easy_setopt.3: clarify CURLOPT_CRLF + + The option takes a parameter that should be 1 or 0 to enable or disable + the feature. + + URL: http://curl.haxx.se/bug/view.cgi?id=3086428 + +Guenter Knauf (14 Oct 2010) +- Some more small Watcom makefile fixes. + +- Added --noconfigure switch to testcurl.pl. + +- Modified Watcom makefiles to work on Linux too. + +- Added MingW32 rtmp target; changed Watcom targets. + + Modified Watcom targets to avoid backslashs so that they can + work on Linux too. + +Daniel Stenberg (13 Oct 2010) +- gitignore: ignore Makefile.vc10.dist made by maketgz + +- curlver.h: start over at 7.21.3 + +- RELEASE-NOTES: start over towards 7.21.3 + +- THANKS: added contributors from 7.21.2 + +Version 7.21.2 (12 Oct 2010) + +Daniel Stenberg (12 Oct 2010) +- RELEASE-NOTES: synced with ecd624b8e774a85 + +- [Julien Chaffraix brought this change] + + CMake: Build fix. + + Do not match the trailing '\n' in the regular expression as this would + make us dump a ) parenthesis on a new line. + + This fixes the following error: + + would get transformed into: + + ) + + Bug: http://curl.haxx.se/mail/lib-2010-10/0065.html + Reported by: Dimitre Dimitrov + +- header_callback: strip off file path separated with backslashes + + If the filename contains a backslash, only use filename portion. The + idea is that even systems that don't handle backslashes as path + separators probably want that path removed for convenience. + + This flaw is considered a security problem, see the curl security + vulnerability http://curl.haxx.se/docs/adv_20101013.html + +Dan Fandrich (12 Oct 2010) +- Get the curl source files for Amiga from Makefile.inc + + This is similar to how it's done in the lib directory. + The Amiga build appears to have been broken for a year because + of a missing homedir.c + +- Added section on server-supplied names to security considerations + +Guenter Knauf (12 Oct 2010) +- Fixed Watcom makefile. + +- Added build bits for librtmp / libssh2 to Watcom makefiles. + +- Added build bits for librtmp to NetWare makefiles. + +Daniel Stenberg (12 Oct 2010) +- SFTP: more ignoring negative file sizes + + As the change in 5f0ae7a0626cbe709 added a precaution against negative + file sizes that for some reason managed to get returned, this change now + introduces the same check at the second place in the code where the file + size from the libssh2 stat call is used. + + This check might not be suitable for a 32 bit curl_off_t, but libssh2.h + assumes long long to work and to be 64 bit so I believe such a small + curl_off_t will be very unlikely to occur in the wild. + +- SMTP: debug output for no known auth mechanisms supported + + ... and some minor source code whitespace edits + +- test: urlglob error messages have no extra newline anymore + +Guenter Knauf (11 Oct 2010) +- Added build bits for librtmp to MingW32 makefiles. + +Daniel Stenberg (8 Oct 2010) +- RELEASE-NOTES: synced with 61f4cdb73ae4 + +- globbing: fix crash on unballanced open brace + + Having an open brace without a closing brace caused a segfault. + + Having a closing brace too many caused a silent error to occur, which + caused curl to bail out and return an error code but no error message + was shown. It does now! + + All error message outputs no longer wrongly get _two_ newlines written + after the error message. + + Reported by: Vlad Ureche + Bug: http://curl.haxx.se/bug/view.cgi?id=3083942 + +- [Dan Locks brought this change] + + libcurl.m4: AC_PATH_PROG fixes + + The invocation of autoconf's AC_PATH_PROG( ) is not quite right for + finding curl-config. This fix corrects the negative case (where + curl-config is not found). + +- FAQ: added "How do I submit my patch?" + +- examples: use example.com in example URLs + +- TODO-RELEASE: libidn problem not repeatable + + "261 - configure and libidn" is removed from the list since Julien + Chaffraix tried to repeat it but failed and the reporter did not return + to provide further details. + + Reported by: Lyndon Hill + Bug: http://curl.haxx.se/mail/lib-2010-07/0029.html + +- libcurl.m4: mention argument is PREFIX + + The macro provides a --with-libcurl option that expects a PREFIX to be + specified and not actually a "directory" in which libcurl will be found. + This now spells that out more clearly. + + Reported by: Dan Locks + Bug: http://curl.haxx.se/bug/view.cgi?id=3079891 + +Guenter Knauf (3 Oct 2010) +- Some NetWare makefile tweaks. + + Renamed SDK_* to NDK_*; made NDK_* defines overwriteable from + environment; removed now obsolete YACC macro; + moved some curl_config.h defines to IPv6 section since they + are only needed when IPv6 is enabled - this makes libcurl compile + with older NDKs too which were not IPv6-aware. + +Daniel Stenberg (2 Oct 2010) +- TODO-RELEASE: 416 error fixed + + "3076808 Requests fail silently following a 416 error" done + +Julien Chaffraix (2 Oct 2010) +- krb5-gssapi: Removed a memory leak in krb5_auth. + + We forgot to release the buffer passed to gss_init_sec_context. + + The previous logic was difficult to read as we were reusing the same + variable (gssbuf) for both input buffer and output buffer. Splitted the + logic in 2 variables to better underline who needs to be released. + Also made the code break at 80 lines. + +- krb5-gssapi: Made the function always return a value. + + kr5_auth missed a final 'return' statement. This is not an error in + gcc but can lead to potential bugs. + +- krb5-gssapi: Delete the GSS-API context. + + This fixes a memory leak related to the GSS-API code. + + Added a krb5_init and krb5_end functions. Also removed a work-around + the lack of proper initialization of the GSS-API context. + +Daniel Stenberg (2 Oct 2010) +- HTTP: remove special case for 416 + + It was pointed out that the special case libcurl did for 416 was + incorrect and wrong. 416 is not really different to other errors so the + response body must be handled like for other errors/http responses. + + Reported by: Chris Smowton + Bug: http://curl.haxx.se/bug/view.cgi?id=3076808 + +- [Dan Fandrich brought this change] + + sws: Added writedelay HTTP server command + + This delays between write operations, hopefully making it easier + to spot problems where libcurl doesn't flush the socket properly + before waiting for the next response. + +- TODO-RELEASE: no bug in ftp_nextconnect + + The issue named "266 - Bug in ftp_nextconnect?" was deemed to not be a + bug and instead resulted in clarified docs. + +- curl_easy_setopt.3: CURLOPT_DIRLISTONLY implies dir list + + Make it explicit that setting CURLOPT_DIRLISTONLY to 1 will make libcurl + to list the directory. + +- RELEASE-NOTES: synced up to 588402585bae + +- TODO-RELEASE: move new features to next release + +- README.ares: we know require c-ares 1.6.0 + +- SFTP: avoid downloading negative sizes! + + It is still not clarified exactly why this happens, but libssh2 + sometimes report a negative file size for the remote SFTP file and that + deeply confuses libcurl (or crashes it) so this precaution is added to + avoid badness. + + Reported by: Ernest Beinrohr + Bug: http://curl.haxx.se/bug/view.cgi?id=3076430 + +- TODO-RELEASE: drop curl_easy_setoptv + + I haven't read any really convincing arguments for adding it + +- [Dirk Manske brought this change] + + multi & hiper examples: updates and cleanups + + all multi and hiper examples: + + * don't loop curl_multi_perform calls, that was <7.20.0 style, currently + the exported multi functions will not return CURLM_CALL_MULTI_PERFORM + + all hiper examples: + * renamed check_run_count to check_multi_info + * don't compare current running handle count with previous value, this + was the wrong way to check for finished requests, simply call + curl_multi_info_read + * it's also safe to call curl_multi_remove_handle inside the + curl_multi_info_read loop. + + ghiper.c: + * replaced curl_multi_socket (that function is marked as obsolete) calls + with curl_multi_socket_action calls (as in hiperfifo.c and + evhiperfifo.c) + + ghiper.c and evhiperfifo.c: + * be smart as hiperfifo.c, don't do uncessary curl_multi_* calls in + new_conn and main + +- TODO-RELEASE: one fixed, one postponed, one added + + As we're already in feature freeze, I pushed the feature onwards. + +Dan Fandrich (29 Sep 2010) +- Renamed test1204 to test1117 to move it into the normal range + +Patrick Monnerat (29 Sep 2010) +- Add gopher protocol definition to ILE/RPG binding. + OS400 compile script in test dir updated for chkhostname. + +Julien Chaffraix (28 Sep 2010) +- krb5-gssapi: Remove several memory leaks. + + Remove a leak seen on Kerberos/MIT (gss_OID is copied internally and + we were leaking it). Now we just pass NULL as advised in RFC2744. + + |tmp| was never set back to buf->data. + + Cleaned up Curl_sec_end to take into account failure in Curl_sec_login + (where conn->mech would be NULL but not conn->app_data or + conn->in_buffer->data). + +- security.c: Remove Curl_sec_fflush_fd. + + The current implementation would make us send wrong data on a closed + socket. We don't buffer our data so the method can be safely removed. + +- security.c: We should always register the socket handler. + + Following a change in the way socket handler are registered, the custom + recv and send method were conditionaly registered. + We need to register them everytime to handle the ftp security + extensions. + + Re-added the clear text handling in sec_recv. + +- security.c: Fix Curl_sec_login after rewrite. + + Curl_sec_login was returning the opposite result that the code in ftp.c + was expecting. Simplified the return code (using a CURLcode) so to see + more clearly what is going on. + +- security.c: Readd the '\n' to the infof() calls. + + They are not automatically added and make the output of the verbose + mode a lot more readable. + +- security.c: Fix typo (PSBZ -> PBSZ) + +- security.c: Fix ftp_send_command. + + My use of va_args was completely wrong. Fixed the usage so that + we send the right commands! + +Daniel Stenberg (28 Sep 2010) +- curl_easy_escape: don't escape "unreserved" characters + + According to RFC3986 section 2.3 the letters -, ., _ and ~ should not be + percent-encoded. + + Reported by: Miguel Diaz + Bug: http://curl.haxx.se/mail/lib-2010-09/0227.html + +- multi: don't expire timeouts at disonnect or done + + The functions Curl_disconnect() and Curl_done() are both used within the + scope of a single request so they cannot be allowed to use + Curl_expire(... 0) to kill all timeouts as there are some timeouts that + are set before a request that are supposed to remain until the request + is done. + + The timeouts are now instead cleared at curl_easy_cleanup() and when the + multi state machine changes a handle to the complete state. + +Dan Fandrich (27 Sep 2010) +- Changed the TPF make file to get source files from Makefile.inc + + Patch was fixed and validated by David McCreedy. + +- Added test case 1204 to test HTTP range failure + + This is an attempt to reproduce bug #3076808 + +Daniel Stenberg (27 Sep 2010) +- [Dirk Manske brought this change] + + multi_runsingle: set timeout error messages + + With the latest changes to fix the timeout handling with multi interface + we lost the timeout error messages. This patch brings them back. + +- TODO-RELEASE: updated list of issues to work on + +- parsedate: allow time specified without seconds + + The date format in RFC822 allows that the seconds part of HH:MM:SS is + left out, but this function didn't allow it. This change also includes a + modified test case that makes sure that this now works. + + Reported by: Matt Ford + Bug: http://curl.haxx.se/bug/view.cgi?id=3076529 + +- TFTP: re-indented the source code + + Just made sure that the good old curl indentation style is used all over + this file. + +- [Tim Newsome brought this change] + + TFTP: Work around tftpd-hpa upload bug + + tftpd-hpa has a bug where it will send an incorrect ack when the block + counter wraps and tftp options have been sent. Work around that by + accepting an ack for 65535 when we're expecting one for 0. + +- Revert "security.c: buffer_read various fixes." + + This reverts commit fbb38de415b7bb7d743e53a7b4b887ffb12b3e5b. + +- security.c: removed superfluous parentheses + + And also removed the FIXME where memory was zeroed just before freed, + and some other minor whitespace changes. + +- [Julien Chaffraix brought this change] + + security.c: Update the #include statements after the rewrite. + +- [Julien Chaffraix brought this change] + + security.c: sec_write tweaks + + - |fd| is now a curl_socket_t and |len| a size_t to avoid conversions. + - Added 2 FIXMEs about the 2 unsigned -> signed conversions. + - Included 2 minor changes to Curl_sec_end. + +- [Julien Chaffraix brought this change] + + security.c: _sec_send tweaks + + - Renamed the method to sec_send now that we + renamed sec_send to do_sec_send. + - Some more variable renaming. + +- [Julien Chaffraix brought this change] + + security.c: sec_read tweaks + + - Renamed the function to sec_recv. + - Renamed the parameters and variable to match the rest of the code. + +- [Julien Chaffraix brought this change] + + security.c: Curl_sec_fflush_fd tweaks + + - Use an early return as it makes the code more readable. + - Added a FIXME about a conversion. + +- [Julien Chaffraix brought this change] + + security.c: sec_send tweaks + + - Renamed it to do_sec_send as it is the function doing the actual + transfer. + - Do not return any values as no one was checking it and it never + reported a failure (added a FIXME about checking for errors). + - Renamed the variables to make their use more specific. + - Removed some casts (int -> curl_socket_t, ...) + - Avoid doing the htnl <-> nthl twice by caching the 2 results. + +- [Julien Chaffraix brought this change] + + security.c: Curl_sec_read_msg tweaks + + - Renamed the variables name to better match their intend. + - Unified the |decoded_len| checks. + - Added some FIXMEs to flag some improvement that did not go in this + change. + +- [Julien Chaffraix brought this change] + + security.c: Curl_sec_set_protection_level tweaking + + - Removed sec_prot_internal as it is now inlined in the function (this removed + a redundant check). + - Changed the prototype to return an error code. + - Updated the method to use the new ftp_send_command function. + - Added a level_to_char helper method to avoid relying on the compiler's + bound checks. This default to the maximum security we have in case of a + wrong input. + +- [Julien Chaffraix brought this change] + + security.c: factored the logic from Curl_sec_login into a dedicated method that better reflect its intent. + + Introduced a helper method ftp_send_command that synchronously send + an FTP query. + +- [Julien Chaffraix brought this change] + + security.c: Remove out_buffer as it was never written into. + +- [Julien Chaffraix brought this change] + + security.c: buffer_read various fixes. + + Tighten the type of the |data| parameter to avoid a cast. Also made + it const as we should not modify it. + + Added a DEBUGASSERT on the size to be written while changing it. + +- [Julien Chaffraix brought this change] + + security.c: Made block_write return a CURLcode. + + While doing so, renamed it to socket_write to better match its + function. + +- [Julien Chaffraix brought this change] + + security.c: Made block_read and sec_get_data return CURLcode. + + To do so, made block_read call Curl_read_plain instead of read. + + While changing them renamed block_read to socket_read and sec_get_data + to read_data to better match their function. + + Also fixed a potential memory leak in block_read. + +- [Julien Chaffraix brought this change] + + Security.c: Fix headers guard to match the rest of the code. + +- [Julien Chaffraix brought this change] + + configure: Fix the LDAPS disable message + + ... for example when LDAP is not compiled. + + Fixed the logic to match the rest of the options' message that is we + update the default message only if the option is not disabled after the + different checks. + + Reported by: Guenter Knauf + +- RELEASE-NOTES: sync with 8665d4e5 and c-ares >= 1.6.0 note + +- parse_remote_port: ignore colons without port number + + Obviously, browsers ignore a colon without a following port number. Both + Firefox and Chrome just removes the colon for such URLs. This change + does not remove the colon for URLs sent over a HTTP proxy, so we should + consider doing that change as well. + + Reported by: github user 'kreshano' + +- RELEASE-NOTES: in sync with 19f45eaa799 + +- duphandle: use ares_dup() + + curl_easy_duphandle() was not properly duping the ares channel. The + ares_dup() function was introduced in c-ares 1.6.0 so by starting to use + this function we also raise the bar and require c-ares >= 1.6.0 + (released Dec 9, 2008) for such builds. + + Reported by: Ning Dong + Bug: http://curl.haxx.se/mail/lib-2010-08/0318.html + +- [Hendrik Visage brought this change] + + MacOSX-Framework: updates for Snowleopard + + 1) PPC64 appears to be an 10.5 only supported architecture, so I + forced 10.5 for 64bit if there is a need for PPC64, else 64bit only + does x86_64 + + 2) proper "make clean" after every ./configure. fixes a bug where + subsequent runs the 32bit do not get compiled + + 3) Added a version numbering curl-$VERSION} rather than the "stock standard" A + +- RELEASE-NOTES: synced with 5fcc4332d62fe + + Removed the duplicate entry of Kamil in the credits. + +- configure: don't enable RTMP if the lib detect fails + + librtmp is often statically linked and using sub dependencies like + OpenSSL, so we need to make sure we can actually link with it properly + before enabling it. Otherwise we easily end up trying to link with a + RTMP lib that fails. + +- TODO: added 8.4 non-gcrypt under GnuTLS + + We must not assume gcrypt just because of GnuTLS + +- configure: check for gcrypt if using GnuTLS + + 1 - libcurl assumes that there are gcrypt functions available when + GnuTLS is. + + 2 - GnuTLS can be built to use libnettle instead as crypto library, + which breaks assumption (1) + + This change makes configure make sure that if GnuTLS is requested and + detected, it also makes sure that gcrypt is present or it errors + out. This is mostly a way to make the user more aware of this flaw, the + correct fix would be to detect which crypto layer that is in use and + adapt our code to use that instead of blindly assuming gcrypt. + + Reported by: Michal Gorny + Bug: http://curl.haxx.se/bug/view.cgi?id=3071038 + +- RELEASE-NOTES: sync from d2a7fd2fe65b to HEAD + +- FTP: fix bad check of Curl_timeleft() return code + + When it returns 0 it means no timeout. Only a negative value means that + we're out of time. + +- LDAP: moved variable declaration to avoid compiler warn + + If built without HTTP or proxy support it would cause a compiler warning + due to the unused variable. I moved the declaration of it into the only + scope it is used. + +Tor Arntsen (18 Sep 2010) +- LDAP: Use FALSE instead of bool_false when setting bits.close + + bool_false is the internal name used in the setup_once.h definition + we fall back to for non-C99 non-stdbool systems, it's not the actual + name to use in assignments (we use bool_false, bool_true there to + avoid global namespace problems, see comment in setup_once.h). + The correct C99 value to use is 'false', but let's use FALSE as + used elsewhere when assigning to bits.close. FALSE is set equal + to 'false' in setup_once.h when possible. + + This fixes a build problem on C99 targets. + +- LDAP: Add missing declaration for 'result' + +Daniel Stenberg (18 Sep 2010) +- [Mauro Iorio brought this change] + + LDAP: Support for tunnelling queries through HTTP proxy + + As of curl-7.21.1 tunnelling ldap queries through HTTP Proxies is not + supported. Actually if --proxytunnel command-line option (or equivalent + CURLOPT_HTTPPROXYTUNNEL) is used for ldap queries like + ldap://ldap.my.server.com/... You are unable to successfully execute the + query. In facts ldap_*_bind is executed directly against the ldap server + and proxy is totally ignored. This is true for both openLDAP and + Microsoft LDAP API. + + Step to reproduce the error: + Just launch "curl --proxytunnel --proxy 192.168.1.1:8080 + ldap://ldap.my.server.com/dc=... " + + This fix adds an invocation to Curl_proxyCONNECT against the provided + proxy address and on successful "CONNECT" it tunnels ldap query to the + final ldap server through the HTTP proxy. As far as I know Microsoft + LDAP APIs don't permit tunnelling in any way so the patch provided is + for OpenLDAP only. The patch has been developed against OpenLDAP 2.4.23 + and has been tested with Microsoft ISA Server 2006 and works properly + with basic, digest and NTLM authentication. + +- timeout: use the correct start value as offset + + Rodric provide an awesome recipe that proved libcurl didn't timeout at + the requested time - it instead often timed out at [connect time] + + [timeout time] instead of the documented and intended [timeout time] + only. This bug was due to the code using the wrong base offset when + comparing against "now". I could also take the oppurtinity to simplify + the code by properly using of the generic help function for this: + Curl_timeleft. + + Reported by: Rodric Glaser + Bug: http://curl.haxx.se/bug/view.cgi?id=3061535 + +- Curl_timeleft: avoid returning "no timeout" by mistake + + As this function uses return code 0 to mean that there is no timeout, it + needs to check that it doesn't return a time left value that is exactly + zero. It could lead to libcurl doing an extra 1000 ms select() call and + thus not timing out as accurately as it should. + + I fell over this bug when working on the bug 3061535 but this fix does + not correct that problem alone, although this is a problem that needs to + be fixed. + + Reported by: Rodric Glaser + Bug: http://curl.haxx.se/bug/view.cgi?id=3061535 + +- whitespace: unified source + + if ( => if( + while ( => while( + + and some other changes in the similar spirit, trying to make the + whole file use the same style + +- remote-header-name: don't output filename when NULL + +- [James Bursa brought this change] + + TheArtOfHttpScripting: use long options + +- [James Bursa brought this change] + + getinmemory: make the example easier to follow + + 1. Remove the comment warning that it's "not been verified to work". It + works with no problems in my testing. + + 2. Remove 2 unnecessary includes. + + 3. Remove the myrealloc(). Initialize chunk.memory with malloc() instead + of NULL. The comments for these two parts contradicted each other. + + 4. Handle out of memory from realloc() instead of continuing. + + 5. Print a brief status message at the end. + +- multi: don't do extra expire calls for the connection + + The timeout is set for the connect phase already at the start of the + request so we should not add a new one, and we MUST not set expire to 0 + as that will remove any other potentially existing timeouts. + +- [Peter Pentchev brought this change] + + Fix a bashism: test a = b is more portable than ==. + +- glob_word: remove a check that is always false + +- inflate_stream: remove redundant check that is always true + +- digest: make it clear the condition is always true + +- ssluse: removed redundant check that is always true + +Dan Fandrich (11 Sep 2010) +- Link curl and the test apps with -lrt explicitly when necessary + + When curl calls a function from that library then it needs to + explicitly link to the library instead of piggybacking on + libcurl's own dependency. Without this, GNU ld with the + --no-add-needed flag fails when linking (which Fedora now does + by default). + + Reported by: Quanah Gibson-Mount + Bug: http://curl.haxx.se/mail/lib-2010-09/0085.html + +- Mention the Debian Popularity Contest + +Tor Arntsen (9 Sep 2010) +- test565: Don't hardcode IP:PORT + + Use %HOSTIP:%HTTPPORT instead of 127.0.0.1:8990 so that + verification works if the baseport change option is used + when executing runtests.pl. + +Daniel Stenberg (9 Sep 2010) +- curl.1: updated protocols and polished language + +- FAQ: CURL_STATICLIB for visual studio users + + Clarified as it isn't used with a -D option for them. + + Reported by: Artfunkel + Bug: http://curl.haxx.se/bug/view.cgi?id=3060381 + +- FAQ: updated and added host with custom IP question + + Added "3.19 How do I get HTTP from a host using a specific IP address?" + and updated some stuff about certs etc. + +- chunky parser: only rewind if needed + + The code reading chunked encoding attempts to rewind the code if it had + read more data than the chunky parser consumes. The rewinding can fail + and it will then cause an error. This change now makes the rewinding + only happen if pipelining is in use - as that's the only time it really + needs to be done. + + Bug: http://curl.haxx.se/mail/lib-2010-08/0297.html + Reported by: Ron Parker + +Kamil Dudka (6 Sep 2010) +- rtsp: avoid SIGSEGV on malformed header + +- rtsp: avoid SIGSEGV on malformed header + +Daniel Stenberg (6 Sep 2010) +- warning: fix conversion to 'int' from 'size_t' + +- portabilty: use proper variable type to hold sockets + + Curl_getconnectinfo() is changed to return a proper curl_socket_t for + the last socket so that it'll work more portably (and cause less + compiler warnings). + +Guenter Knauf (3 Sep 2010) +- Trial to fix another compiler warning with braces. + +Dan Fandrich (2 Sep 2010) +- Use checkprefix() to compare protocol-specific strings + + Otherwise, there could be problems running in certain locales. + +Guenter Knauf (2 Sep 2010) +- Moved S_ISREG define to setup as suggested by Dan. + +- Use own typedef as workaround for broken sspi.h header (f.e. Watcom). + +- Added some hacks in order to build with VC from git. + + Adam Light posted this patch to the list which enables builds from + git with VC versions other than vc6; also he added a vc10 target. + +- Added S_ISREG define for Win32. + +Daniel Stenberg (1 Sep 2010) +- multi: fixes for timing out handles + + Add a timeout check for handles in the state machine so that they will + timeout in all states disregarding what actions that may or may not + happen. + + Fixed a bug in socket_action introduced recently when looping over timed + out handles: it wouldn't assign the 'data' variable and thus it wouldn't + properly take care of handles. + + In the update_timer function, the code now checks if the timeout has + been removed and then it tells the application. Previously it would + always let the remaining timeout(s) just linger to expire later on. + +- threaded resolver: no more expire 0 calls + + Curl_expire() set to 0 expires ALL timeouts so it should only be called + if we truly and really want to remove all timeouts for the handle. + +- resolve_server: simplify code + + Make use of the helper function Curl_timeleft() instead of duplicating + code. + +- multi: make sure the next timeout is used when one expires + + Each easy handle has a list of timeouts, so as soon as the main timeout + for a handle expires, we must make sure to get the next entry from the + list and re-add the handle to the splay tree. + + This was attempted previously but was done poorly in my commit + 232ad6549a68450. + +Dan Fandrich (30 Aug 2010) +- Added proxy keyword to allow skipping test in proxyless configs + +Daniel Stenberg (29 Aug 2010) +- multi: set timeouts when transfer begins + + When a new transfer is about to start we now set the proper timeouts to + expire for the multi interface if they are set for the handle. This is a + follow-up bugfix to make sure that easy handles timeout properly when + the times expire and the multi interface is used. This also improves + curl_multi_timeout(). + +- CURLOPT_DIRLISTONLY: don't use with CURLOPT_WILDCARDMATCH + +- FAQ: update list of supported protocols + +- [Fabian Keil brought this change] + + In the m4 detection line, factor out the 2>dev/null + +- [Fabian Keil brought this change] + + If m4 doesn't support --version, try if gm4 does. + +- [Fabian Keil brought this change] + + If the m4 version isn't recognized at all, just say so + + 'm4 version found. You need a GNU m4 installed!' is a bit confusing. + +- HISTORY: mention the gopher story + +Dan Fandrich (25 Aug 2010) +- Tweaked some test data files + + Fixed some issues that caused xmllint failures, added features + and keywords, fixed some quotes and removed some sections + that unnecessarily limited test checking. + +- Added new source files to Symbian and TPF makefiles + +Daniel Stenberg (25 Aug 2010) +- RELEASE-NOTES: sync from b980c9a02 to HEAD + +- Makefile: add gopher.c file to build + + As the VC and RISCOS makefiles don't use the .inc file + +- runtests: fix uninitialized variable warning + +- gopher tests: revert parts of gopher in the pingpong server + + Introduced in the initial gopher commits, there was added logic to do + GOPHER test serving in the pingpong server but as it resembles HTTP much + more than FTP or SMTP, the gopher testing has been moved over to instead + use the sws (HTTP) server. This change simply removes unused code. + +- gopher tests: use sws and adjusted to more standard style + +- sws: added basic gopher support + +- gopher: enable the header callback/verbosity + +- gopher: fix test case line endings + + Patches over email very easily lose CRLF line endings in files otherwise + LF-only so I had to put them back where needed. + +- gopher: fix memory leak and busyloop + + The fix for the busyloop really only is a temporary work-around. It + causes a BLOCKING behavior which is a NO-NO. This function should rather + be split up in a do and a doing piece where the pieces that aren't + possible to send now will be sent in the doing function repeatedly until + the entire request is sent. + +- [Cameron Kaiser brought this change] + + Gopher using Curl_write; test suite (4 tests) + +- [Cameron Kaiser brought this change] + + Remove url.c test + +- [Cameron Kaiser brought this change] + + Forgot gopher.h in Makefile.inc + +- [Cameron Kaiser brought this change] + + Gopher protocol support (initial release) + +- http: handle trailer headers in all chunked responses + + HTTP allows that a server sends trailing headers after all the chunks + have been sent WITHOUT signalling their presence in the first response + headers. The "Trailer:" header is only a SHOULD there and as we need to + handle the situation even without that header I made libcurl ignore + Trailer: completely. + + Test case 1116 was added to verify this and to make sure we handle more + than one trailer header properly. + + Reported by: Patrick McManus + Bug: http://curl.haxx.se/bug/view.cgi?id=3052450 + +- TODO: we now support RTMP + +- TODO: done "NTLM with other crypto functions" + + Since NTLM was made to work with the NSS API as well, the primary SSL + alternatives will be built with NTLM support in libcurl. + +- TODO: fixed "Make curl_multi_info_read faster" + + It is really fast now + +Dan Fandrich (24 Aug 2010) +- Fixed a NULL pointer dereference in form posting + + It was introduced in commit eeb2cb05 along with the -F type= + change. Also fixed a typo in the name of the magic filename= + parameter. Tweaked tests 39 and 173 to better test this path. + +Daniel Stenberg (24 Aug 2010) +- [Ben Greear brought this change] + + multi: Fix compile warning on 64-bit systems + +Dan Fandrich (23 Aug 2010) +- Mention PolarSSL in tutorial & add some URLs to INSTALL + +Daniel Stenberg (23 Aug 2010) +- RESUME_FROM: clarify what ftp uploads do + + The numerical value passed to CURLOPT_RESUME_FROM for FTP uploads is + interpreted and used as position where to resume the _reading_ of the + local file and it will "blindly" append that data on the remote + file. This was certainly not clear in the docs previously. + + Reported by: catalin + Bug: http://curl.haxx.se/bug/view.cgi?id=3048174 + +- [Dirk Manske brought this change] + + Curl_is_connected: use correct errno + + The correctly extracted errno contents were mistakenly overwritten by a newer + value that wasn't the correct error value. + + Bug: http://curl.haxx.se/mail/lib-2010-08/0242.html + +- cmdline: make -F type= accept ;charset= + + The -F option allows some custom parameters within the given string, and + those strings are separated with semicolons. You can for example specify + "name=daniel;type=text/plain" to set content-type for the + field. However, the use of semicolons like that made it not work fine if + you specified one within the content-type, like for: + "name=daniel;type=text/plain;charset=UTF-8" + ... as the second one would be seen as a separator and "charset" is no + parameter curl knows anything about so it was just silently discarded. + + The new logic now checks if the semicolon and following keyword looks + like a parameter it knows about and if it isn't it is assumed to be + meant to be used within the content-type string itself. + + I modified test case 186 to verify that this works as intended. + + Reported by: Larry Stone + Bug: http://curl.haxx.se/bug/view.cgi?id=3048988 + +Guenter Knauf (20 Aug 2010) +- Added mk-ca-bundle.vbs script. + + The script works exactly same as the Perl one except for one thing: + when the text descriptions generated with openssl are included then + the md5 fingerprints are missing; seems openssl has either a bug or + a feature which prints the md5 fingerprint output to stdout instead + of writing them to specified file; this script could here do the same + as what the Perl scripr does (redirect stdout into file) but this + makes the script take up double the time because it needs to launch + cmd.exe 140 times (fo each openssl call). So I think for now we just + ommit the md5 fingerprints, and see if openssl will be fixed. + +- Trial to fix win32 autobuilds. + + It seems that its time to look at some better ideas for the win32 + non-configure builds; probably a prebuild target which copies + config-win32.h to curl_config.h and appends also then feature + defines like USE_ARES. + +Dan Fandrich (19 Aug 2010) +- Use the S_ISREG macro to determine what is a regular file + +Kamil Dudka (19 Aug 2010) +- AC_INIT: avoid a warning with autoconf 2.66 + + It was complaining about the '=>' operator, introduced in e3fc0d5. + +Dan Fandrich (18 Aug 2010) +- Fixed a memory leak during OOM in the multi timeout code + +- Removed a C99ism & made an array const + +Daniel Stenberg (19 Aug 2010) +- [Julien Chaffraix brought this change] + + test: added test 579 to verify progress callback for chunked post + + The 66 bytes checked are those 38 bytes with the chunked encoding + headers added: 8+8+10+35+5 = 66 + + The three-letter words become 8 bytes on the wire because they are sent + like: "3\r\none\r\n" + + ... and there's the trailing 5 bytes write after the four lines since + the final chunk is sent (which is "0\r\n\r\n"). + +- multi: avoid sending multiple complete messages + + I fell over this bug report that mentioned that libcurl could wrongly + send more than one complete messages at the end of a transfer. Reading + the code confirmed this, so I've added a new multi state to make it not + happen. The mentioned bug report was made by Brad Jorsch but is (oddly + enough) filed in Debian's bug tracker for the "wmweather+" tool. + + Bug: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=593390 + +- FAQ: update the list of supported protocols + +- FAQ: added blurb about ECCN + + "1.13 curl's ECCN number" is a new section mostly made up from + Alessandro Vesely's very informative ML post on the subject: + http://curl.haxx.se/mail/lib-2008-03/0251.html + +Guenter Knauf (18 Aug 2010) +- It is sufficient to pipe stderr to NUL to get rid of the nasty messages. + +- Added SSPI build to Watcom makefile. + +Daniel Stenberg (16 Aug 2010) +- [Julien Chaffraix brought this change] + + progress: callback for POSTs less than MAX_INITIAL_POST_SIZE + + Add a call to Curl_pgrsSetUploadSize in this case valided by a test + case. + + Reported by: Ðикита Дорохин. + Bug: http://curl.haxx.se/mail/lib-2010-04/0173.html + +Dan Fandrich (16 Aug 2010) +- Make the LD_PRELOAD path absolute in the tests that use it + + In some situations, libtool will change directories and perform + a link step before executing the libtest test app. Since + LD_PRELOAD is in effect for this entire process, the path to the + binary must be absolute so it will be valid no matter in which + directory the app is running. + +Daniel Stenberg (16 Aug 2010) +- negotiation: Wrong proxy authorization + + There's an error in http_negotiation.c where a mistake is using only + userpwd even for proxy requests. Ludek provided a patch, but I decided + to write the fix slightly different using his patch as inspiration. + + Reported by: Ludek Finstrle + Bug: http://curl.haxx.se/bug/view.cgi?id=3046066 + +Dan Fandrich (16 Aug 2010) +- Clear stdout and stderr files on each test run + + This allows a test to be run several times in the same test + session even when the -k option is given. + +Guenter Knauf (15 Aug 2010) +- Syncroniszed vclean target; fixed some comments. + +Daniel Stenberg (15 Aug 2010) +- THANKS: added contributors from 7.21.1 + +- multi: two fixes done + +- multi: use timeouts properly for MAX_RECV/SEND_SPEED + + When detecting that the send or recv speed, the multi interface changes + state to TOOFAST and previously there was no timeout set that would + force a recheck but it would rely on the application to somehow call + libcurl anyway. This now sets a timeout for a suitable future time to + check again if the average transfer speed is then below the threshold + again. + +- multi: support timeouts + + Curl_expire() is now expanded to hold a list of timeouts for each easy + handle. Only the closest in time will be the one used as the primary + timeout for the handle and will be used for the splay tree (which sorts + and lists all handles within the multi handle). + + When the main timeout has triggered/expired, the next timeout in time + that is kept in the list will be moved to the main timeout position and + used as the key to splay with. This way, all timeouts that are set with + Curl_expire() internally will end up as a proper timeout. Previously any + Curl_expire() that set a _later_ timeout than what was already set was + just silently ignored and thus missed. + + Setting Curl_expire() with timeout 0 (zero) will cancel all previously + added timeouts. + + Corrects known bug #62. + +- Curl_llist_insert_next: allow insertion first in the list + + When we specify the "insert after" entry as NULL, this function now + inserts the new entry first in the list. + +- multi: make curl_multi_info_read perform O(1) + + Instead of looping over all attached easy handles, this now keeps a list + of messages in the multi handle. It allows curl_multi_info_read() to + perform O(1) no matter how many easy handles that are handled. This is + of importance since this function may be polled very frequently by apps + using the multi interface. + +Kamil Dudka (15 Aug 2010) +- curl -T: ignore file size of special files + + original bug report at https://bugzilla.redhat.com/622520 + +Dan Fandrich (13 Aug 2010) +- Reset environment variables before starting servers + + Otherwise, variables from tests could affect the servers + themselves. + +Kamil Dudka (12 Aug 2010) +- typecheck-gcc: work around gcc upstream bug #32061 + + original bug report at https://bugzilla.redhat.com/617757 + +Daniel Stenberg (11 Aug 2010) +- release cycle loop: start over toward 7.21.2 + +Version 7.21.1 (11 Aug 2010) + +Daniel Stenberg (11 Aug 2010) +- RELEASE-NOTES: mention the runtests fix as well + +- runtests: clear old setenv remainders before test + + Due to the layout of the singletest function there are situations where + it returns before it clears the environment variables that were + especially set for the single specific test case. That could lead to + subsequent tests getting executed with environment variables sticking + around from a previous test which could lead to badness. + + This change makes sure to clear all custom variables that may be laying + around from a previous round, before running a test case. + + Reported by: Kamil Dudka + Bug: http://curl.haxx.se/mail/lib-2010-08/0141.html + +Guenter Knauf (11 Aug 2010) +- Added OpenSSL builds to Watcom makefiles. + +Yang Tse (11 Aug 2010) +- configure: werror related adjustments + +Daniel Stenberg (11 Aug 2010) +- FAQ: s/libcurl.so.3/libcurl.so.X + +Dan Fandrich (10 Aug 2010) +- KNOWN_BUG #59 is fixed. Clarify support of IPv6 zone IDs. + +- Fixed typo in Android configure command + +Daniel Stenberg (11 Aug 2010) +- HISTORY: added stuff from recent years + +- warning: silence the compiler + + warning: conversion to 'long int' from 'time_t' may alter its value + + ... on win64 when time_t is 64bit and long is 32bit. + +- RELEASE-NOTES: synced, 3 additional bugfixes + +- multi_socket_action: clarify how to kickstart it + + The callbacks are called when curl_multi_socket_action() is called, not + when handles are added. This is now mentioned in the "TYPICAL USAGE" + section. + +- callbacks: acknowledge progress callback error returns + + When the progress callback is called during the TCP connection, an error + return would accidentally not abort the operation as intended but would + instead be counted as a failure to connect to that particular IP and + libcurl would just continue to try the next. I made singleipconnect() + and trynextip() return CURLcode properly. + + Added bonus: it corrected the error code for bad --interface usages, + like tested in test 1084 and test 1085. + + Reported by: Adam Light + Bug: http://curl.haxx.se/mail/lib-2010-08/0105.html + +Guenter Knauf (10 Aug 2010) +- More Watcom makefile fixes ... + + Final fix (hopefully!) for dll wlink loader; + prefer faster internal rm if available. + +- Fixed my wrong edit. + +- More Watcom makefile fixes. + + Added the -br switch to dynamic builds which fixes the issue I saw + with curl's --version output. Added debug info and symfile for debug + builds to linker opts. Added DLL loader for wlink back, but this time + dependend on wlink version. + Patch posted to the list by malak.jiri AT gmail.com. + +- Changed test for -u switch in order to enable other wmake switches. + + The var %MAKEFLAGS is only set in 3 cases: if set as environment + var or as macro definition from commandline, and either with the + -u or -ms switch. Since all these cases are unlikely for the average + user it should be safe to only test if %MAKEFLAGS is defined; this + has the benefit that now all other switches can be used again in + addition to the -u which was formerly not possible. + +Daniel Stenberg (10 Aug 2010) +- llist: hide Curl_llist_init + + Curl_llist_init is never used outside of llist.c and thus it should be + static. I also removed the protos for Curl_llist_insert_prev and + Curl_llist_remove_next which are functions we removed from llist.c ages + ago. + +Guenter Knauf (10 Aug 2010) +- Added msys Perl since git for Win32 comes with own Perl which identifies as msys. + +- Updated lib dependency versions. + +- Make testcurl.pl Watcom-aware. + +Daniel Stenberg (10 Aug 2010) +- parse_remote_port: fix ;type= URL suffix over HTTP proxy + + Test 563 is enabled now and verifies that the combo FTP type=A URL, + CURLOPT_PORT set and proxy work fine. As a bonus I managed to remove the + somewhat odd FTP check in parse_remote_port() and instead converted it + to a better and more generic 'slash_removed' struct field. Checking the + ->protocol field isn't right since when an FTP:// URL is sent over a + HTTP proxy, the protocol is HTTP but the URL was handled by the FTP code + and thus slash_removed is set TRUE for this case. + +- indent: white space fixes only + +Yang Tse (9 Aug 2010) +- build: fix previous push + +- build: don't build libhostname unless shared libcurl is built + +- build: libhostname and chkhostname linkage adjustments followup + +Daniel Stenberg (8 Aug 2010) +- typo: remove duplicate semicolon + +- multi: avoid a malloc() when a transfer is complete + + The struct used for storing the message for a completed transfer is now + no longer allocated separatly but is kept within the main struct kept + for each easy handle so that we avoid one malloc (and the subsequent + free). + +Yang Tse (8 Aug 2010) +- build: libhostname linkage adjustments followup + +Guenter Knauf (7 Aug 2010) +- Fix to overwrite libcurl name. + +Yang Tse (7 Aug 2010) +- build: chkhostname build adjustments followup + +U-D5B1PQ1J\Administrador (7 Aug 2010) +- build: allow NTLM tests to run on more build configurations + +Daniel Stenberg (7 Aug 2010) +- curl_easy_setopt.3: rename stream to userdata + + In some places where the name 'stream' has been used for naming a + function argument that is in fact settable with a setopt() option we now + call that argument 'userdata' to make it more obvious that it is in fact + possible to set by the application. + + Suggested by: Jeff Pohlmeyer + +Guenter Knauf (7 Aug 2010) +- Block created curlbuild.h for NetWare to avoid usage from other platforms. + +Daniel Stenberg (7 Aug 2010) +- RELEASE-NOTES: synced with recent changes + +Yang Tse (6 Aug 2010) +- build: ensure that libhostname doesn't get installed + +Daniel Stenberg (6 Aug 2010) +- multi_socket: set timeout for 100-continue + + When libcurl internally decided to wait for a 100-continue header, there + was no call to the timeout function so there was no timeout callback + called when the multi_socket API was used and thus applications became + either completely wrong or at least ineffecient depending on how they + handled the situation. We now set a timeout to get triggered. + + Reported by: Ben Darnell + Bug: http://curl.haxx.se/bug/view.cgi?id=3039744 + +Guenter Knauf (6 Aug 2010) +- Some more Watcom makefile massage ... + + For now removed the .autodepend directive until I've figured out + which of my changes broke it again. + +Yang Tse (5 Aug 2010) +- build: fix libssh2_scp_send64() availability + +- build: remove unneeded cast to (void *) + +- build: remove unused file + +Daniel Stenberg (4 Aug 2010) +- SCP: send large files properly with new enough libssh2 + + libssh2 1.2.6 and later handle >32bit file sizes properly even on 32bit + architectures and we make sure to use that ability. + + Reported by: Mikael Johansson + Bug: http://curl.haxx.se/mail/lib-2010-08/0052.html + +Yang Tse (3 Aug 2010) +- build: add missing new files to non-configure target build files + +- md4: replace bcopy usage with memcpy + +Daniel Stenberg (3 Aug 2010) +- RELEASE-NOTES: synced with recent changes + +- TODO-RELEASE: clear, file not really used ATM + +- typecheck-gcc: add checks for recently added options + + I added all OBJECTPOINT curl_easy_setopt() options from 178 to 202. Left + to add: the five FUNCTIONPOINT (callbacks) options added since: + + SSH_KEYFUNCTION + INTERLEAVEFUNCTION + CHUNK_BGN_FUNCTION + CHUNK_END_FUNCTION + FNMATCH_FUNCTION + +- .gitignore: ignore all built examples + +- example: fix code to build warning-free + +- Curl_connected_proxy: skip the bits.tcpconnect check + + Simply because the TCP might be connected already we cannot skip the + proxy connect procedure. We need to be careful to not overload more + meaning to the bits.tcpconnect field like this. + + With this fix, SOCKS proxies work again when the multi interface is + used. I believe this regression was added with commit 4b351d018e, + released as 7.20.1. + + Left todo: add a test case that verifies this functionality that + prevents us from breaking it again in the future! + + Reported by: Robin Cornelius + Bug: http://curl.haxx.se/bug/view.cgi?id=3033966 + +- sethostname: provide local prototype for gethostname + + This is only to avoid warnings on some systems. + +- build: add typecast to avoid warning + + There is an implicit conversion from "unsigned long" to "long"; + rounding, sign extension, or loss of accuracy may result. + +Guenter Knauf (2 Aug 2010) +- Rename CURL_SOURCES macro; revert previous rename of curl_SOURCES macro. + +- Removed ugly dependency lists since wmake knows the .autodepend directive. + +- Use suffix search path for sources in lib folder. + +- Changed src/Makefile.Watcom to use CURL_SOURCES from src/Makefile.inc. + +- Renamed curl_SOURCES to CURL_ALLFILES to overcome wmake's case-insensitivity. + +- Removed wlink from DLL loader list because it doesnt work with Watcom < 1.8. + +- Moved the LDAP API defines from Makefile.Watcom to config-win32.h. + + These defines are only needed for older Watcom versions (< 1280). + +Daniel Stenberg (2 Aug 2010) +- retry: consider retrying even if -f is used + + The --retry logic does retry HTTP when some specific response codes are + returned, but because the -f option sets the CURLOPT_FAILONERROR to + libcurl, the return codes are different for such situations and then the + curl tool failed to consider it for retrying. + + Reported by: Mike Power + Bug: http://curl.haxx.se/bug/view.cgi?id=3037362 + +- multi: fix FTPS connecting the data connection with OpenSSL + + Commit 496002ea1cd76af7f (released in 7.20.1) broke FTPS when using the + multi interface and OpenSSL was used. The condition for the non-blocking + connect was incorrect. + + Reported by: Georg Lippitsch + Bug: http://curl.haxx.se/mail/lib-2010-07/0270.html + +Guenter Knauf (1 Aug 2010) +- Fixed curlbuild.h rule. + +- Added rule to create curlbuild.h if not present (for builds from git). + +- Added dependend libs for curl static linking. + +- Fixed curl.exe static linking. + +Daniel Stenberg (30 Jul 2010) +- warning: silence a win64 compiler warning + + conversion from 'size_t' to 'curl_socklen_t', possible loss of data + + Reported by: Adam Light + +- KNOWN_BUG: The SOCKET type in Win64 is 64 bits + + The SOCKET type in Win64 is 64 bits large (and thus so is curl_socket_t + on that platform), and long is only 32 bits. It makes it impossible for + curl_easy_getinfo() to return a socket properly with the + CURLINFO_LASTSOCKET option as for all other operating systems. + +- smtp_connect: always provide host name buffer + + Previously the host name buffer was only used if gethostname() exists, + but since we converted that into a curl private function that function + always exists and will be used so the buffer needs to exist for all + cases/systems. + +- sethostname: avoid including unistd.h to duck for warnings + +- sethostname: ISO C does not allow extra `;' outside of a function + +- [Kamil Dudka brought this change] + + NTLM tests: boost coverage by forcing the hostname + + A shared library tests/libtest/.libs/lihostname.so is preloaded in NTLM + test-cases to override the system implementation of gethostname(). It + makes it possible to test the NTLM authentication for exact match, and + this way test the implementation of MD4 and DES. + + If LD_PRELOAD doesn't work, a debug build willl also workk as debug + builds are now made to prefer a specific environment variable and will + then return that content as host name instead of the actual one. + + Kamil wrote the bulk of this, Daniel Stenberg polished it. + +Guenter Knauf (29 Jul 2010) +- Added a comment with an alternate idea to avoid the backslash line contination character. + +- Changed comparison to match size_t var type. + +- Removed unused vars to avoid compiler warnings. + +- Make Watcom makefiles use Makefile.inc to reduce future maintainance. + + lib/Makefile.Watcom works fine already, for src/Makefile.Watcom we + need first to tweak src/Makefile.inc a bit - therefore the handtweaked + list still exists for now. + +- Watcom makefiles overhaul. + + - make both libcurl and curl makefiles use register calling convention + (previously libcurl had stack calling convention). + - added include paths to the Watcom headers so its no longer required + to set the environment vars for this. + - added -wcd=201 to supress compiler warning about unreachable code. + - use macros for all tools, and removed dependency on GNU tools like rm. + - make ipv6 and debug builds controlable via env vars and so make them + optional instead of default. + - commented WINLDAPAPI and WINBERAPI since they broke with OW 1.8, and + it seems they're not needed (anymore?). + - added rule for hugehelp.c.cvs so that it will be created when not + already exist - this is required for building from a release tarball + since there we have no hugehelp.c.cvs, thus compilation broke. + - removed C_ARG creation from lib/Makefile.Watcom and use CFLAGS + directly as done too in src/Makefile.Watcom - this has the benefit + that we will see all active cflags and defines during compile. + - added LINK-ARG to src/Makefile.Watcom in order to better control + linker input. + - a couple of other minor makefile tweaks here and there ... + - added largefile support for Watcom builds to config-win32.h. Not yet + tested if it really works, but should since Win32 supports it. + - added loaddll stuff to speed up builds if supported. + +- some cosmetic changes. + +Dan Fandrich (26 Jul 2010) +- Added md4.c to the Watcom makefile + +- Added PolarSSL to the docs + +Daniel Stenberg (25 Jul 2010) +- curl-config: --built-shared returns shared info + + The curl-config now features a --built-shared command line option that + will output 'yes' or 'no' depending if the build process was asked to + build shared library/libraries or not. + + It is primarily made to offer more details to the test suite to know + what kind of stunts it can expect to work. + +- add_buffer_send: fix compiler warning + + Win64's 32 bit long but 64 bit size_t caused a warning that we avoid + with a typecast. A small whitespace indent fix was also applied. + + Reported by: Adam Light + +Guenter Knauf (22 Jul 2010) +- Updated library versions. + +- Fixed script version which was still based on CVS Revision tag. + +Dan Fandrich (21 Jul 2010) +- FAQ: Why doesn't cURL error out when the cable is unplugged? + + This one was long overdue to be mentioned in the FAQ. Also, mention the + new ftp wildcard downloading feature. + +Daniel Stenberg (21 Jul 2010) +- [Ben Greear brought this change] + + ssh: Fix compile error on 64-bit systems. + + Signed-off-by: Ben Greear + +- [Ben Greear brought this change] + + build: Enable configure --enable-werror + + This passes -Werror to gcc when building curl and libcurl, + allowing easy dection of compile warnings. + + Signed-off-by: Ben Greear + +- [Ben Greear brought this change] + + pingpong: Fix indentation (whitespace change only) + + Signed-off-by: Ben Greear + +- [Jan Van Boghout brought this change] + + CUSTOMREQUEST: shouldn't be disabled when HTTP is disabled + + ... since FTP is using it as well, and potentially other protocols! + + Also, an #endif CURL_DISABLE_HTTP was incorrectly marked, as it seems to + end the proxy block instead. + +- [Jan Van Boghout brought this change] + + pingpong: response_time is milliseconds + + Fixed the comment/document for the response_time struct member. + +- [Jan Van Boghout brought this change] + + ftp: response timeout bug in "quote" sending + + The FTP implementation was missing a timestamp reset point, making the + waiting for responses after sending a post-transfer "QUOTE" command not + working as supposedly. This bug was introduced in 7.20.0 + +- [Jeff Pohlmeyer brought this change] + + remote-header-name: chop filename at next semicolon + + The --remote-header-name option for the command-line tool assumes that + everything beyond the filename= field is part of the filename, but that + might not always be the case, for example: + + Content-Disposition: attachment; filename=file.txt; modification-date=... + + This fix chops the filename off at the next semicolon, if there is one. + +- --retry: access violation with URL part sets continued + + When getting multiple URLs, curl didn't properly reset the byte counter + after a successful transfer so if the subsequent transfer failed it + would wrongly use the previous byte counter and behave badly (segfault) + because of that. The code assumes that the byte counter and the 'stream' + pointer is well in synch. + + Reported by: Jon Sargeant + Bug: http://curl.haxx.se/bug/view.cgi?id=3028241 + +- releasnote: synch up with commit f3b77e5611d + +- [Constantine Sapuntzakis brought this change] + + examples: add curl_multi_timeout + + Make the multi-interface using examples use curl_multi_timeout to + properly educate users how to do things. + +- configure: document the STATICLIB variable + +- [Constantine Sapuntzakis brought this change] + + multi: fix condition that remove timers before trigger + + curl_multi perform has two phases: run through every easy handle calling + multi_runsingle and remove expired timers (timer removal). + + If a small timer (e.g. 1-10ms) is set during multi_runsingle, then it's + possible that the timer has passed by when the timer removal runs. The + timer which was just added is then removed. This will potentially cause + the timer list to be empty and cause the next call to curl_multi_timeout + to return -1. Ideally, curl_multi_timeout should return 0 in this case. + + One way to fix this is to move the struct timeval now = Curl_tvnow(); to + the top of curl_multi_perform. The change does that. + +- [Constantine Sapuntzakis brought this change] + + threaded resolver: fix timeout issue + + Reset old timer first so we can set a new one further in the future. + +- configure: allow environments variable to override internals + + configure checks for grep, egrep, sed and ar and set the variables GREP, + EGREP, SED and AR accordingly. We now let already set variables override + the internal choices to let users make decisions when they know the + right choice already. This is a regression as our configure script used + to allow this back before commit 0b57c475 (up to 7.18.2). + + Reported by: "kdekker" + Bug: http://curl.haxx.se/bug/view.cgi?id=3028318 + +Dan Fandrich (9 Jul 2010) +- Improved the Android build instructions + +Daniel Stenberg (7 Jul 2010) +- [Tor Arntsen brought this change] + + upload: Avoid infinite loop when checking for auth bits + + The test would loop forever if authtype bit 0 wasn't set. + +- upload: warn users trying to upload from stdin with anyauth + + Since uploading from stdin is very likely to not work with anyauth and + its multi-phase probing for what authentication to actually use, alert + the user about it. Multi-phase negotiate almost certainly will involve + sending data and thus libcurl will need to rewind the stream to send + again, and it cannot do that with stdin. + +- http: don't enable chunked during authentication negotiations + + As mentioned in bug report #2956968, the HTTP code wouldn't send the + first empty chunk during the auth negotiation phase of the HTTP request + sending, so the server would wait for data to come and libcurl would + wait for data to arrive... I've made the code not enable chunked + encoding until the auth negotiation is done and thus this scenario + doesn't occur anymore. + + Reported by: Sidney San Martín + Bug: http://curl.haxx.se/bug/view.cgi?id=2956968 + +- --libcurl: list the tricky options instead of using [REMARK] + + I think the [REMARK] and commented function calls cluttered the code a + bit too much and made the generated code ugly to read. Now we instead + track the remarks one specially and just lists them at the end of the + generated code more as additional information. + +- curl: avoid setting libcurl options to its default + + it makes the --libcurl output easier to follow. + +- --libcurl: hide setopt() calls setting default options + + And additionally, don't show function or object pointers actual value + since they make no sense to anyone. Show 'functionpointer' and + 'objectpointer' instead. + +- --libcurl: use *_LARGE options with typecasted constants + + In the generated code --libcurl makes, all calls to curl_easy_setopt() + that use *_LARGE options now have the value typecasted to curl_off_t, so + that it works correctly for 32bit systems with 64bit curl_off_t type. + +- multi: CURLINFO_LASTSOCKET doesn't work after remove_handle + + When curl_multi_remove_handle() is called and an easy handle is returned + to the connection cache held in the multi handle, then we cannot allow + CURLINFO_LASTSOCKET to extract it since that will more or less encourage + that the user uses the socket while it can get used by libcurl again. + + Without this fix, we'd get a segfault in Curl_getconnectinfo() trying to + dereference the NULL pointer in 'data->state.connc'. + + Bug: http://curl.haxx.se/bug/view.cgi?id=3023840 + +- [Pierre Joye brought this change] + + build: add enable IPV6 option for the VC makefiles + +- FAQ: the threaded resolver works universally now + +Kamil Dudka (30 Jun 2010) +- http_ntlm: add support for NSS + + When configured with '--without-ssl --with-nss', NTLM authentication + now uses NSS crypto library for MD5 and DES. For MD4 we have a local + implementation in that case. More details are available at + https://bugzilla.redhat.com/603783 + + In order to get it working, curl_global_init() must be called with + CURL_GLOBAL_SSL or CURL_GLOBAL_ALL. That's necessary because NSS needs + to be initialized globally and we do so only when the NSS library is + actually required by protocol. The mentioned call of curl_global_init() + is responsible for creating of the initialization mutex. + + There was also slightly changed the NSS initialization scenario, in + particular, loading of the NSS PEM module. It used to be loaded always + right after the NSS library was initialized. Now the library is + initialized as soon as any SSL or NTLM is required, while the PEM module + is prevented from being loaded until the SSL is actually required. + +Daniel Stenberg (29 Jun 2010) +- glob: backslash escaping bug + + curl didn't properly handle escaping characters in a URL with the use of + backslash. It did an attempt, but that failed as reported in bug + 3022551. The described example was using the URL + "http://example.com?{AB,C\,D}". + + I've now removed the special-handling of letters following the backslash + and I also removed the bad extra check that triggered this particular + bug. + + Bug: http://curl.haxx.se/bug/view.cgi?id=3022551 + Reported by: Jon Sargeant + +- release-notes: sync up with recent commits + +- CONTRIBUTE: the git commit message line length is 72 columns + +- [Pavel Raiskup brought this change] + + ftp wildcard: FTP LIST parser FIX + + There was a problem when a UNIX-like server returned information + about directory size (total NNNNNN) at the first line of + response. + +- [Pavel Raiskup brought this change] + + examples: new FTP wildcard showcase + +- multi_socket: re-use of same socket without notifying app + + When a hostname resolves to multiple IP addresses and the first one + tried doesn't work, the socket for the second attempt may get dropped on + the floor, causing the request to eventually time out. The issue is that + when using kqueue (as on mac and bsd platforms) instead of select, the + kernel removes the first fd from kqueue when it is closed (in trynextip, + connect.c:503). Trynextip() then goes on to open a new socket, which + gets assigned the same number as the one it just closed. Later in + multi.c, socket_cb is not called because the fd is already in + multi->sockhash, so the new socket is never added to kqueue. + + The correct fix is to ensure that socket_cb is called to remove the fd + when trynextip() closes the socket, and again to re-add it after + singleipsocket(). I'm not sure how to cleanly do that, but the attached + patch works around the problem in an admittedly kludgy way by delaying + the close to ensure that the newly-opened socket gets a different fd. + + Daniel's added comment: I didn't spot a way to easily do a nicer fix so + I've proceeded with Ben's patch. + + Bug: http://curl.haxx.se/bug/view.cgi?id=3017819 + Patch by: Ben Darnell + +Kamil Dudka (24 Jun 2010) +- [Pavel Raiskup brought this change] + + ftp-wildcard: avoid tight loop when used without any pattern + + It was broken for URLs like "ftp://example.com/". + +Daniel Stenberg (21 Jun 2010) +- maketgz: produce CHANGES automatically with the 1000 most recent commits + + It passes the git log output through 'log2changes.pl' to produce + the lot. + +- ignore: CHANGES.dist gets generated by maketgz + +- CHANGES: move all contents from CHANGES to CHANGES.0 + + CHANGES is no longer used for manually edited content. It is to + be generated automatically by maketgz when we make release + tarballs. + +- log2changes: correct command line, fix tag usage, change Version output + + --decorate=full is needed with my git 1.7.1 to get the necessary + output so that the previous edit would work to extract the + Version stuff. + + ... but I had to edit how the refs/tags was extracted since it + had a little flaw that made it miss the 7.20.1 output. + + Finally, I changed so that Version is outputted even more similar + to how CHANGES does it. + +Dan Fandrich (21 Jun 2010) +- Make the output of log2changes.pl even more closely match CHANGES + + Add the ASCII art header, and list version commits by decoding + the ref tag names, when available (using the git log --decorate + option). + +Daniel Stenberg (19 Jun 2010) +- log2changes: first version of the git log to CHANGES conversion script + + $ git log --pretty=fuller --no-color --date=short | ./log2changes.pl + + Of course, limiting the log output with a range like with + "[tag]..HEAD" appended can be very useful too. + +- sendrecv: treat all negative values from send/recv as errors + + For example the libssh2 based functions return other negative + values than -1 to signal errors and it is important that we catch + them properly. Right before this, various failures from libssh2 + were treated as negative download amounts which caused havoc. + +- multi: prevent NULL pointer dereference + + My additional call to Curl_pgrsUpdate() would sometimes get + called even though there's no connection (left) so a NULL pointer + would get passed, causing a segfault. + +- smtp: fixed a few uses of size_t that seemed to believe it was signed + + Reported-by: Steven M. Schweda + +Dan Fandrich (17 Jun 2010) +- Fixed an OOM memory leak in the FTP wildcard code + +Kamil Dudka (17 Jun 2010) +- test575: do not fail with threaded DNS resolver + +Daniel Stenberg (17 Jun 2010) +- [Krister Johansen brought this change] + + multi: unmark handle as used when no longer head of pipeline + +- multi: call the progress function only once and allow abort + + 1) no need to call the progress function twice when in the + CURLM_STATE_TOOFAST state. + + 2) Make sure that the progress callback's return code is + acknowledged when used + +- multi: call the progress callback in all states + + As long as no error is reported, the progress function can get + called. This may be a little TOO often so we should keep an eye + on this and possibly make this conditional somehow. + +- configure: spell --disable-threaded-resolver correctly + + Previously we only accepted the option when named + --disable-threaded-resover, which wasn't quite intended. + + Reported by: Helwing Lutz + +- release: start on 7.21.1, bump contributor count + +- version: start working on the 7.21.1-dev version + +- THANKS: added contributors from the 7.21.0 release + +Version 7.21.0 (16 Jun 2010) + +Daniel Stenberg (16 Jun 2010) +- release: 7.21.0 + +Yang Tse (10 Jun 2010) +- remove unused 'tmpdata' and 'backup' ftp_parselist_data struct members + +- replace isprint() with ISPRINT() + +- ensure that Curl_wildcard_dtor() leaves WildcardData struct zero initialized + +Patrick Monnerat (9 Jun 2010) +- ILE/RPG binding updated to current curl.h definitions. + +Yang Tse (9 Jun 2010) +- code simplification + +- add Curl_ prefix to conform with cURL naming standards + +- Merge branch 'master' of git@github.com:bagder/curl + +- fix compiler warning using curl_socket_t to store socket descriptor + +Daniel Stenberg (8 Jun 2010) +- inet_pton: warnings: use size_t to store pointer deltas + +Yang Tse (8 Jun 2010) +- avoid redundant work when reusing same connection + +- fix function result checking + +Daniel Stenberg (8 Jun 2010) +- transfer: warning: implicit conversion + + There is an implicit conversion from "unsigned long" to "long"; + rounding, sign extension, or loss of accuracy may result. + + Fixed by an added typecast. + +- TFTP: fix compiler warning + + Curl_fillreadbuffer()'s second argument takes an int, so + typecasting to another is a bad idea. + +- TFTP: fix warning for sendto() usage on non-POSIX systems + + Older unixes want an 'int' instead of 'size_t' as the 3rd + argumment so before this change it would cause warnings such as: + + There is an implicit conversion from "unsigned long" to "int"; + rounding, sign extension, or loss of accuracy may result. + +Dan Fandrich (7 Jun 2010) +- Include Makefile.inc to get the list of source files for Amiga + + Signed-off-by: Diego Casorran + +Yang Tse (7 Jun 2010) +- Curl_updateconninfo() error handling fix + +Daniel Stenberg (5 Jun 2010) +- [Constantine Sapuntzakis brought this change] + + OpenSSL: fix spurious SSL connection aborts + + Was seeing spurious SSL connection aborts using libcurl and + OpenSSL. I tracked it down to uncleared error state on the + OpenSSL error stack - patch attached deals with that. + + Rough idea of problem: + + Code that uses libcurl calls some library that uses OpenSSL but + don't clear the OpenSSL error stack after an error. + + ssluse.c calls SSL_read which eventually gets an EWOULDBLOCK from + the OS. Returns -1 to indicate an error + + ssluse.c calls SSL_get_error. First thing, SSL_get_error calls + ERR_get_error to check the OpenSSL error stack, finds an old + error and returns SSL_ERROR_SSL instead of SSL_ERROR_WANT_READ or + SSL_ERROR_WANT_WRITE. + + ssluse.c returns an error and aborts the connection + + Solution: + + Clear the openssl error stack before calling SSL_* operation if + we're going to call SSL_get_error afterwards. + + Notes: + + This is much more likely to happen with multi because it's easier + to intersperse other calls to the OpenSSL library in the same + thread. + +Yang Tse (5 Jun 2010) +- replace socklen_t with curl_socklen_t + +Daniel Stenberg (5 Jun 2010) +- [Frank Meier brought this change] + + getinfo: added *_PRIMARY_PORT, *_LOCAL_IP and *_LOCAL_PORT + +- RELEASE-NOTES: add contributors not mentioned + +Yang Tse (4 Jun 2010) +- Enable OpenLDAP support for cygwin builds. + + Enable OpenLDAP support for cygwin builds. This support was disabled back + in 2008 due to incompatibilities between OpenSSL and OpenLDAP headers. + cygwin's OpenSSL 0.9.8l and OpenLDAP 2.3.43 versions on cygwin 1.5.25 + allow building an OpenLDAP enabled libcurl supporting back to Windows 95. + + Remove non-functional CURL_LDAP_HYBRID code and references. + +Kamil Dudka (2 Jun 2010) +- ftplistparser.c: oops, fix typo in the last commit + +- ftplistparser.c: avoid some invalid dereferences + +- lib: eliminate some dead code + +Daniel Stenberg (2 Jun 2010) +- SSH: corrected the inability to respect the timeout + + Jason McDonald posted bug report #3006786 when he found that the + SFTP code didn't timeout properly in several places in the code + even if a timeout was set properly. + + Based on his suggested patch, I wrote a different implementation + that I think addressed the issue better and also uses the connect + timeout for the initial part of the SSH/SFTP done during the + "protocol connect" phase. + + (http://curl.haxx.se/bug/view.cgi?id=3006786) + +Yang Tse (2 Jun 2010) +- mention last changes + +- add missing new files to non-configure target build files + +- include libcurl standard internal headers + +Daniel Stenberg (2 Jun 2010) +- TODO: add multi interface improvement remove ldap select + +Yang Tse (2 Jun 2010) +- make setup.h first included file + +- fix spnego memory leak + +- openldap header inclusions fix + +Daniel Stenberg (1 Jun 2010) +- multi_socket: handles timer inaccuracy better for timeouts + + Igor Novoseltsev reported a problem with the multi socket API and + using timeouts and timers. It boiled down to a problem with + libcurl's use of GetTickCount() interally to figure out the + current time, while Igor's own application code used another + function call. + + It made his app call the socket API timeout function a bit + _before_ libcurl would consider the timeout to trigger, and that + could easily lead to timeouts or stalls in the app. It seems + GetTickCount() in general often has no better resolution than + 16ms and switching to the alternative function + QueryPerformanceCounter has its share of problems: + http://www.virtualdub.org/blog/pivot/entry.php?id=106 + + We address this problem by simply having libcurl treat timers + that already has occured or will occur within 40ms subject for + treatment. I'm confident that there are other implementations and + operating systems with similarly in accurate timer functions so + it makes sense to have applied generically and I don't believe we + sacrifice much by adding a 40ms inaccuracy on these timeouts. + +Yang Tse (1 Jun 2010) +- fix ldaps option issue + +- fix ldap related compilation issues + +- fix compiler warning: enumerated type mixed with another type + +- fix compiler warning: enumerated type mixed with another type + +Patrick Monnerat (31 May 2010) +- smtp_authenticate: avoid compiler warnings + +Yang Tse (31 May 2010) +- fix compiler warning: enumerated type mixed with another type + +- fix compiler warning: enumerated type mixed with another type + +- fix compiler warning: enumerated type mixed with another type + +- fix compiler warning: external declaration in primary source file + +- fix compiler warning: variable was set but never used + +- fix compiler warning: enumerated type mixed with another type + +- fix compiler warning: external declaration in primary source file + +- update year in copyright notice + +Kamil Dudka (29 May 2010) +- strtoofft: rename CURL_LLONG_MIN -> CURL_OFF_T_MIN + + ... and CURL_LLONG_MAX -> CURL_OFF_T_MAX + +- CURL_LLONG_MAX: avoid constant overflow + + ... when (CURL_SIZEOF_CURL_OFF_T == 4) + +Daniel Stenberg (28 May 2010) +- [Howard Chu brought this change] + + LDAPS: list availability depending on SSL's presence + +- [Howard Chu brought this change] + + LDAP: make it build without SSL if no such support is available + + of course it also goes for the case where SSL is explicitly + disabled + +- TODO: removed fixed items + + These two items are now actually implemented: + + 11.1 Content-Disposition + 11.5 ftp wildcard download + +Kamil Dudka (28 May 2010) +- lib: eliminate 'statement not reached' warnings + +Daniel Stenberg (28 May 2010) +- test1115: verify that unexpected 1xx responses work fine + +Kamil Dudka (28 May 2010) +- lib577: avoid redefinition of ERROR + +- test313: a new test for CRL support + +- tests/certs: re-generated because of lost pass-phrase + +- tests/certs/scripts: generate also CRL + + ... and make it possible to do so without any user interaction + +Daniel Stenberg (27 May 2010) +- [Howard Chu brought this change] + + openldap: fix compiler warnings + +- indent: some whitespace edits + +Kamil Dudka (27 May 2010) +- wildcard.c: add missing include of "setup.h" + +- [Tor Arntsen brought this change] + + lib573: do not compare double for exact match + +- [Pavel Raiskup brought this change] + + wildcard.c: add missing include of "curl_memory.h" + +- [Tor Arntsen brought this change] + + setup_once: use enum type for 'bool' on non-C99 platforms + + An enum will catch non-bool assignments to bool on platforms with + a strict compiler, e.g MIPSPro. + + Signed-off-by: Kamil Dudka + +- url.c: avoid implied cast to bool + +- [Tor Arntsen brought this change] + + curl_fnmatch: remove use of register keyword + + Using the 'register' keyword rarely improves anything with modern + compilers and architectures. + +Daniel Stenberg (26 May 2010) +- [Julien Chaffraix brought this change] + + RTMP: Fix compiler warnings + +- [Julien Chaffraix brought this change] + + OOM fixes in http_negociate.c and lib/splay.c + + Fix 2 OOM errors: a missing NULL-check in lib/http_negociate.c + and a potential NULL dereferencing in lib/splay.c + +- [Howard Chu brought this change] + + LDAP: properly implemented as a curl_handler + + makes the LDAP code much cleaner, nicer and in general being a + better libcurl citizen. If a new enough OpenLDAP version is + detect, the new and shiny lib/openldap.c code is then used + instead of the old cruft + + Code by Howard, minor cleanups by Daniel. + +- [Tor Arntsen brought this change] + + curl_fnmatch: Use int not bool when function returns int + + bool in curl internals is unsigned char and should not be used + to receive return value from functions returning int - this fails + when using IBM VisualAge and Tru64 compilers. + +- TFTP: send legal timeout value + + Eric Mertens posted bug #3003705: when we made TFTP use the + correct timeout option when sent to the server (fixed May 18th + 2010) it became obvious that libcurl used invalid timeout values + (300 by default while the RFC allows nothing above 255). While of + course it is obvious that as TFTP has worked thus far without + being able to set timeout at all, just removing the setting + wouldn't make any difference in behavior. I decided to still keep + it (but fix the problem) as it now actually allows for easier + (future) customization of the timeout. + + (http://curl.haxx.se/bug/view.cgi?id=3003705) + +- TFTP: don't ack if wrong block num is received + + If an unexpected block number was received, break out of the + switch loop. + +- TFTP: block id wrap bug fix + + In a normal expression, doing [unsigned short] + 1 will not wrap + at 16 bits so the comparisons and outputs were done wrong. I + added a macro do make sure it gets done right. + + Douglas Kilpatrick filed bug report #3004787 about it: + http://curl.haxx.se/bug/view.cgi?id=3004787 + +- [Ben Greear brought this change] + + Fix build warnings. + + Signed-off-by: Ben Greear + +- [Ben Greear brought this change] + + setopt: Fix setting of set.is_fwrite_set + + Signed-off-by: Ben Greear + +- [Tanguy Fautre brought this change] + + build: allow curl to build with Microsoft VC10 + + By undefing a bunch of E* defines that VC10 has started to define + but that we redefine internally to their WSA* alternatives when + building for Windows. + +Kamil Dudka (20 May 2010) +- [Tor Arntsen brought this change] + + Test 573: Use correct type for CURLINFO_CONNECT_TIME + + curl_easy_getinfo() called with a pointer to long instead of double + would sigbus on RISC processors (e.g. MIPS) due to wrong alignment + of pointer address. + +- [Tor Arntsen brought this change] + + lib: Fix AIX build failure + +Dan Fandrich (19 May 2010) +- Fixed some memory leaks in the POP3 torture tests + +- Fixed a memory leak in the SMTP torture tests + +Daniel Stenberg (18 May 2010) +- TFTP: send timeout option correctly + + Eric Mertens posted bug report #3003005 pointing out that the + libcurl TFTP code was not sending the timeout option properly to + the server, and suggested a fix. + + (http://curl.haxx.se/bug/view.cgi?id=3003005) + +Kamil Dudka (16 May 2010) +- [Tor Arntsen brought this change] + + lib: Change some CRLF line endings to LF + + An update had added a couple of lines with DOS line endings, + and some compilers will choke on that (e.g. the Tru64 compiler). + +- ftp wildcard: a new option CURLOPT_FNMATCH_DATA + +Daniel Stenberg (15 May 2010) +- [Howard Chu brought this change] + + RMTP: the version code is now rtmp aware + +- [Howard Chu brought this change] + + RTMP: fix wrong #ifdef + +- [Pavel Raiskup brought this change] + + ftp wildcard: fix int32_t and size/group mixups + +Dan Fandrich (14 May 2010) +- Fixed test 577 to work when --enable-hidden-symbols is configured + +Daniel Stenberg (14 May 2010) +- OpenSSL: multi interface handshake could hang + + John-Mark Bell filed bug #3000052 that identified a problem (with + an associated patch) with the OpenSSL handshake state machine + when the multi interface is used: + + Performing an https request using a curl multi handle and using + select or epoll to wait for events results in a hang. It appears + that the cause is the fix for bug #2958179, which makes + ossl_connect_common unconditionally return from the step 2 loop + when fetching from a multi handle. + + When ossl_connect_step2 has completed, it updates + connssl->connecting_state to ssl_connect_3. ossl_connect_common + will then return to the caller, as a multi handle is in + use. Eventually, the client code will call curl_multi_fdset to + obtain an updated fdset to select or epoll on. For https + requests, curl_multi_fdset will cause https_getsock to be called. + https_getsock will only return a socket handle if the + connecting_state is ssl_connect_2_reading or + ssl_connect_2_writing. Therefore, the client will never obtain a + valid fdset, and thus not drive the multi handle, resulting in a + hang. + + (http://curl.haxx.se/bug/view.cgi?id=3000052) + +- changelog: add link to bug report + +Dan Fandrich (14 May 2010) +- Added directories.pm to the source tar ball + +Daniel Stenberg (14 May 2010) +- follow redirect: ignore response-body on redirect even if compressed + + Sebastian V reported bug #3000056 identifying a problem with + redirect following. It showed that when curl followed redirects + it didn't properly ignore the response body of the 30X response + if that response was using compressed Content-Encoding! + + (http://curl.haxx.se/bug/view.cgi?id=3000056) + +- version: we're now going for 7.21.0 + +- [Hoi-Ho Chan brought this change] + + Remove support for BSD version of PolarSSL + + "The BSD version of PolarSSL was made for migratory purposes only and is not + maintained. The GPL version of PolarSSL is actually the only actively + developed version, so I would be very reluctant to use the BSD version." / + Paul Bakker, PolarSSL hacker. + + Signed-off-by: Hoi-Ho Chan + +Dan Fandrich (12 May 2010) +- Added Polar SSL and RTMP files to the non-autoconf build files + + I didn't bother with a few that have little hope of running the required + dependent libraries. + +- Added the new ftp source files to the non-autoconf build files + +- Copy the license file so it's seen by the Android build system + +Daniel Stenberg (13 May 2010) +- updated with symbols added in recent commits for 7.21.0 + +- changelogs: mention RTMP and the FTP wildcard support + +- ftp wildcards: mention they're added in 7.21.0 + +- style: minor whitespace change + +- syntax: cleanups + +- [Pavel Raiskup brought this change] + + FTP: WILDCARDMATCH/CHUNKING/FNMATCH added + +- [Howard Chu brought this change] + + RTMP: initial support added, powered by librtmp + + librtmp is found at http://rtmpdump.mplayerhq.hu/ + +- [Howard Chu brought this change] + + sendrecv: make them two pairs of send/recv to properly deal with FTPS + + FTP(S) use two connections that can be set to different recv and + send functions independently, so by introducing recv+send pairs + in the same manner we already have sockets/connections we can + work with FTPS fine. + + This commit fixes the FTPS regression introduced in change d64bd82. + +Kamil Dudka (11 May 2010) +- changelog: fixed CRL support in libcurl-NSS + +- nss: make it possible to read ASCII and DER CRL + +- nss: add CRL to cache instead of read-only NSS db + +Daniel Stenberg (10 May 2010) +- git: how to write a fine commit message + +- findtool: file name as a full path requires a slash + + Kalle Vahlman's patch applied a while ago broke how the findtool + function searches for tools, as it would always check if "$file" + was present first, which thus made the bad assumption that a file + in the current directory would be a match. + + I noticed when it found 'libtool' in the current directory but + libtoolize is not there, which confused the script. + +Hacki (8 May 2010) +- moved vars into conditional since seems that winsock implementation doesnt use them. + +Daniel Stenberg (7 May 2010) +- multi interface: missed storing connection time + + Dirk Manske reported a regression. When connecting with the multi + interface, there were situations where libcurl wouldn't store + connect time correctly as it used to (and is documented to) do. + + Using his fine sample program we could repeat it, and I wrote up + test case 573 using that code. The problem does not easily show + itself using the local test suite though. + + The fix, also as suggested by Dirk, is a bit on the ugly side as + it adds yet another call to Curl_verboseconnect() and setting the + TIMER_CONNECT time. That situation is subject for some closer + inspection in the future. + +- verboseconnect: so the verbose checking within the function + + As the function is used more than once and libcurl can be built + without it, do the conditional check within the verboseconnect() + function itself. + +- changelogs: split the I/O handling + +- [Howard Chu brought this change] + + sendrecv: split the I/O handling into private handler + + Howard Chu brought the bulk work of this patch that properly + moves out the sending and recving of data to the parts of the + code that are properly responsible for the various ways of doing + so. + + Daniel Stenberg assisted with polishing a few bits and fixed some + minor flaws in the original patch. + + Another upside of this patch is that we now abuse CURLcodes less + with the "magic" -1 return codes and instead use CURLE_AGAIN more + consistently. + +- changelog: PolarSSL + +- [Hoi-Ho Chan brought this change] + + PolarSSL: initial support added + + This is Hoi-Ho Chan's patch with some minor fixes by me. There + are some potential issues in this, but none worse than we can + sort out on the list and over time. + +- TODO: we've done PRET already, consider HOST for the future + + ... and GnuTLS connects are non-blocking, TFTP is better + integrated as a "real" protocol and RTSP is supported. + +- TODO: GnuTLS connects are now non-blocking + + Since commit c288860 by Jerome Vouillon + +- INTERNALS: tftp is decent now, ldap is not + + It's not quite fair to list TFTP is a "crappy" member of the + libcurl family so I removed its mentioning. + +- changelog: mention Ben Greear's telnet work + +- [Ben Greear brought this change] + + telnet: Allow programatic use of telnet. + + The main change is to allow input from user-specified methods, + when they are specified with CURLOPT_READFUNCTION. + All calls to fflush(stdout) in telnet.c were removed, which makes + using 'curl telnet://foo.com' painful since prompts and other data + are not always returned to the user promptly. Use + 'curl --no-buffer telnet://foo.com' instead. In general, + the user should have their CURLOPT_WRITEFUNCTION do a fflush + for interactive use. + + Also fix assumption that reading from stdin never returns < 0. + Old code could crash in that case. + + Call progress functions in telnet main loop. + + Signed-off-by: Ben Greear + +- test: enable valgrind for 604, seems to work + +Kamil Dudka (28 Apr 2010) +- [Paul Howarth brought this change] + + add 1s post-command delay to tests 513 and 514 + + addressing http://curl.haxx.se/mail/lib-2009-12/0031.html + +Daniel Stenberg (26 Apr 2010) +- [Kalle Vahlman brought this change] + + Allow tools to be defined with full path in buildconf + + This is required in Scratchbox where + LIBTOOL=/targets/links/arch_tools/bin/libtool + is set in the environment. + +- progress callback: can be called more than once per sec + +- SSH: init and cleanup libssh2 in global_init/cleanup + + The necessary libssh2 functions require libssh2 1.2.5 or later. + +- new configure option --enable-threaded-resolver + +- configure: check for libssh2_init and libssh2_exit + +Kamil Dudka (24 Apr 2010) +- nss: fix SSL handshake timeout underflow + +Guenter Knauf (24 Apr 2010) +- encourage users to take latest lib dependencies. + +Daniel Stenberg (24 Apr 2010) +- socks5: please static code analyzer + + Make sure we don't call memcpy() if the argument is NULL even + though we also passed a zero length then, as the clang analyzer + whined and we want to limit warnings (even false positives) when + they're this easy to fix. + + The change of (char) to (unsigned char) will fix long user names + and passwords on systems that have the char type signed by + default. + +- gzip: Value stored to 'data' is never read + +- RELEASE-NOTES: update top numbers + +- changelog: added the --proto and -proto-redir options + +- [Alex Bligh brought this change] + + curl: added --proto and --proto-redir + + --proto tells curl to use the listed protocols for its initial + retrieval + + --proto-redir tells curl to use the listed protocols after a + redirect + +Kamil Dudka (24 Apr 2010) +- test536: do not fail with threaded DNS resolver + + Also tweaked comments in certain examples using curl_multi_fdset(). + +Daniel Stenberg (21 Apr 2010) +- curl: -O crash on windows + + The -O option caused curl to crash on windows and DOS due to the + tool writing out of boundary memory. + +Yang Tse (20 Apr 2010) +- hmac.c related compilation adjustment + +- hmac.c related compilation adjustment + +monnerat (20 Apr 2010) +- Add compilation directives for hmac in Watcom,riscos and vc6 platform-specific makefiles. + +Yang Tse (20 Apr 2010) +- [Ruslan Gazizov brought this change] + + replaced wsock32.lib usage with ws2_32.lib in MSVC makefiles + +monnerat (19 Apr 2010) +- Merge branch 'master' of github.com:bagder/curl + +- Remove null-effect leftover code. + +Daniel Stenberg (19 Apr 2010) +- changelog: -J/--remote-header-name strips CRLF + +- parse_filename: strip trailing CRs and LFs + + The feature that uses the file name given in a + Content-disposition: header didn't properly skip trailing + carriage returns and linefeed characters from the end of the file + name when it was given without quotes. + +- Curl_HMAC_MD5: fix the array init to not warn with picky compilers + +monnerat (19 Apr 2010) +- Fix GnuTLS compilation problem in md5.c + +- Fix compilation problem: declare Curl_HMAC_MD5 as extern in include file. + +- Merge branch 'master' of github.com:bagder/curl + +- Implement SMTP authentication + +Daniel Stenberg (17 Apr 2010) +- parseconfig: Value stored to 'line' is never read + + Make the function call with (void) as we don't care about the + return code. + +- parsedate: Value stored to 'found' is never read + +- check_gzip_header: Value stored to 'data' is never read + +- dprintf_formatf: Value stored to 'left' is never read + +- curl_version: remove superfluous assignments + +- FTP PORT: Value stored to 'rc' is never read + +- Curl_setup_transfer: no longer returns anything + + This function could only return CURLE_OK and by changing it to + a void instead, we can simplify code all over. + +- PASV response: Value stored to 'rc' is never read + +- Curl_perform: Value stored to 'res2' is never read + +- sftp range: remove unnecessary check for NULL pointer + +- ftp_range: remove unnecessary check for NULL pointer + +- file_range: remove unnecessary check for NULL pointer + +- SOCKS4: Value stored to 'rc' is never read + +- FTP PASV: Value stored to 'rc' is never read + +- ftp_range: Value stored to 'totalsize' is never read + + Simplified the code by removing a local variable completely. + +- SOCKS5: when name resolves fail return immediately + + This makes the code flow more obvious and reacts on the return + code properly, even if the code acted the same way before. + +- POP3: when USER command fails, don't even try PASS + +- tftp_rx: Value stored to 'sbytes' is never read + +- file_range: Value stored to 'totalsize' is never read + +- changelog: GnuTLS: SSL handshake phase is non-blocking + +- [Jerome Vouillon brought this change] + + GnuTLS: make the connection phase non-blocking + + When multi interface is used, the SSL handshake is no longer + blocking when GnuTLS is used. + +- krb5_auth: fix my previous change to compile diff --git a/libs/curl/include/curl/curl.h b/libs/curl/include/curl/curl.h new file mode 100644 index 000000000..ee9754da8 --- /dev/null +++ b/libs/curl/include/curl/curl.h @@ -0,0 +1,2166 @@ +#ifndef __CURL_CURL_H +#define __CURL_CURL_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2011, Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at http://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ + +/* + * If you have libcurl problems, all docs and details are found here: + * http://curl.haxx.se/libcurl/ + * + * curl-library mailing list subscription and unsubscription web interface: + * http://cool.haxx.se/mailman/listinfo/curl-library/ + */ + +#include "curlver.h" /* libcurl version defines */ +#include "curlbuild.h" /* libcurl build definitions */ +#include "curlrules.h" /* libcurl rules enforcement */ + +/* + * Define WIN32 when build target is Win32 API + */ + +#if (defined(_WIN32) || defined(__WIN32__)) && \ + !defined(WIN32) && !defined(__SYMBIAN32__) +#define WIN32 +#endif + +#include +#include + +#if defined(__FreeBSD__) && (__FreeBSD__ >= 2) +/* Needed for __FreeBSD_version symbol definition */ +#include +#endif + +/* The include stuff here below is mainly for time_t! */ +#include +#include + +#if defined(WIN32) && !defined(_WIN32_WCE) && !defined(__GNUC__) && \ + !defined(__CYGWIN__) || defined(__MINGW32__) +#if !(defined(_WINSOCKAPI_) || defined(_WINSOCK_H)) +/* The check above prevents the winsock2 inclusion if winsock.h already was + included, since they can't co-exist without problems */ +#include +#include +#endif +#else + +/* HP-UX systems version 9, 10 and 11 lack sys/select.h and so does oldish + libc5-based Linux systems. Only include it on system that are known to + require it! */ +#if defined(_AIX) || defined(__NOVELL_LIBC__) || defined(__NetBSD__) || \ + defined(__minix) || defined(__SYMBIAN32__) || defined(__INTEGRITY) || \ + defined(ANDROID) || \ + (defined(__FreeBSD_version) && (__FreeBSD_version < 800000)) +#include +#endif + +#ifndef _WIN32_WCE +#include +#endif +#if !defined(WIN32) && !defined(__WATCOMC__) && !defined(__VXWORKS__) +#include +#endif +#include +#endif + +#ifdef __BEOS__ +#include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void CURL; + +/* + * Decorate exportable functions for Win32 and Symbian OS DLL linking. + * This avoids using a .def file for building libcurl.dll. + */ +#if (defined(WIN32) || defined(_WIN32) || defined(__SYMBIAN32__)) && \ + !defined(CURL_STATICLIB) +#if defined(BUILDING_LIBCURL) +#define CURL_EXTERN __declspec(dllexport) +#else +#define CURL_EXTERN __declspec(dllimport) +#endif +#else + +#ifdef CURL_HIDDEN_SYMBOLS +/* + * This definition is used to make external definitions visible in the + * shared library when symbols are hidden by default. It makes no + * difference when compiling applications whether this is set or not, + * only when compiling the library. + */ +#define CURL_EXTERN CURL_EXTERN_SYMBOL +#else +#define CURL_EXTERN +#endif +#endif + +#ifndef curl_socket_typedef +/* socket typedef */ +#ifdef WIN32 +typedef SOCKET curl_socket_t; +#define CURL_SOCKET_BAD INVALID_SOCKET +#else +typedef int curl_socket_t; +#define CURL_SOCKET_BAD -1 +#endif +#define curl_socket_typedef +#endif /* curl_socket_typedef */ + +struct curl_httppost { + struct curl_httppost *next; /* next entry in the list */ + char *name; /* pointer to allocated name */ + long namelength; /* length of name length */ + char *contents; /* pointer to allocated data contents */ + long contentslength; /* length of contents field */ + char *buffer; /* pointer to allocated buffer contents */ + long bufferlength; /* length of buffer field */ + char *contenttype; /* Content-Type */ + struct curl_slist* contentheader; /* list of extra headers for this form */ + struct curl_httppost *more; /* if one field name has more than one + file, this link should link to following + files */ + long flags; /* as defined below */ +#define HTTPPOST_FILENAME (1<<0) /* specified content is a file name */ +#define HTTPPOST_READFILE (1<<1) /* specified content is a file name */ +#define HTTPPOST_PTRNAME (1<<2) /* name is only stored pointer + do not free in formfree */ +#define HTTPPOST_PTRCONTENTS (1<<3) /* contents is only stored pointer + do not free in formfree */ +#define HTTPPOST_BUFFER (1<<4) /* upload file from buffer */ +#define HTTPPOST_PTRBUFFER (1<<5) /* upload file from pointer contents */ +#define HTTPPOST_CALLBACK (1<<6) /* upload file contents by using the + regular read callback to get the data + and pass the given pointer as custom + pointer */ + + char *showfilename; /* The file name to show. If not set, the + actual file name will be used (if this + is a file part) */ + void *userp; /* custom pointer used for + HTTPPOST_CALLBACK posts */ +}; + +typedef int (*curl_progress_callback)(void *clientp, + double dltotal, + double dlnow, + double ultotal, + double ulnow); + +#ifndef CURL_MAX_WRITE_SIZE + /* Tests have proven that 20K is a very bad buffer size for uploads on + Windows, while 16K for some odd reason performed a lot better. + We do the ifndef check to allow this value to easier be changed at build + time for those who feel adventurous. The practical minimum is about + 400 bytes since libcurl uses a buffer of this size as a scratch area + (unrelated to network send operations). */ +#define CURL_MAX_WRITE_SIZE 16384 +#endif + +#ifndef CURL_MAX_HTTP_HEADER +/* The only reason to have a max limit for this is to avoid the risk of a bad + server feeding libcurl with a never-ending header that will cause reallocs + infinitely */ +#define CURL_MAX_HTTP_HEADER (100*1024) +#endif + + +/* This is a magic return code for the write callback that, when returned, + will signal libcurl to pause receiving on the current transfer. */ +#define CURL_WRITEFUNC_PAUSE 0x10000001 +typedef size_t (*curl_write_callback)(char *buffer, + size_t size, + size_t nitems, + void *outstream); + + + +/* enumeration of file types */ +typedef enum { + CURLFILETYPE_FILE = 0, + CURLFILETYPE_DIRECTORY, + CURLFILETYPE_SYMLINK, + CURLFILETYPE_DEVICE_BLOCK, + CURLFILETYPE_DEVICE_CHAR, + CURLFILETYPE_NAMEDPIPE, + CURLFILETYPE_SOCKET, + CURLFILETYPE_DOOR, /* is possible only on Sun Solaris now */ + + CURLFILETYPE_UNKNOWN /* should never occur */ +} curlfiletype; + +#define CURLFINFOFLAG_KNOWN_FILENAME (1<<0) +#define CURLFINFOFLAG_KNOWN_FILETYPE (1<<1) +#define CURLFINFOFLAG_KNOWN_TIME (1<<2) +#define CURLFINFOFLAG_KNOWN_PERM (1<<3) +#define CURLFINFOFLAG_KNOWN_UID (1<<4) +#define CURLFINFOFLAG_KNOWN_GID (1<<5) +#define CURLFINFOFLAG_KNOWN_SIZE (1<<6) +#define CURLFINFOFLAG_KNOWN_HLINKCOUNT (1<<7) + +/* Content of this structure depends on information which is known and is + achievable (e.g. by FTP LIST parsing). Please see the url_easy_setopt(3) man + page for callbacks returning this structure -- some fields are mandatory, + some others are optional. The FLAG field has special meaning. */ +struct curl_fileinfo { + char *filename; + curlfiletype filetype; + time_t time; + unsigned int perm; + int uid; + int gid; + curl_off_t size; + long int hardlinks; + + struct { + /* If some of these fields is not NULL, it is a pointer to b_data. */ + char *time; + char *perm; + char *user; + char *group; + char *target; /* pointer to the target filename of a symlink */ + } strings; + + unsigned int flags; + + /* used internally */ + char * b_data; + size_t b_size; + size_t b_used; +}; + +/* return codes for CURLOPT_CHUNK_BGN_FUNCTION */ +#define CURL_CHUNK_BGN_FUNC_OK 0 +#define CURL_CHUNK_BGN_FUNC_FAIL 1 /* tell the lib to end the task */ +#define CURL_CHUNK_BGN_FUNC_SKIP 2 /* skip this chunk over */ + +/* if splitting of data transfer is enabled, this callback is called before + download of an individual chunk started. Note that parameter "remains" works + only for FTP wildcard downloading (for now), otherwise is not used */ +typedef long (*curl_chunk_bgn_callback)(const void *transfer_info, + void *ptr, + int remains); + +/* return codes for CURLOPT_CHUNK_END_FUNCTION */ +#define CURL_CHUNK_END_FUNC_OK 0 +#define CURL_CHUNK_END_FUNC_FAIL 1 /* tell the lib to end the task */ + +/* If splitting of data transfer is enabled this callback is called after + download of an individual chunk finished. + Note! After this callback was set then it have to be called FOR ALL chunks. + Even if downloading of this chunk was skipped in CHUNK_BGN_FUNC. + This is the reason why we don't need "transfer_info" parameter in this + callback and we are not interested in "remains" parameter too. */ +typedef long (*curl_chunk_end_callback)(void *ptr); + +/* return codes for FNMATCHFUNCTION */ +#define CURL_FNMATCHFUNC_MATCH 0 /* string corresponds to the pattern */ +#define CURL_FNMATCHFUNC_NOMATCH 1 /* pattern doesn't match the string */ +#define CURL_FNMATCHFUNC_FAIL 2 /* an error occurred */ + +/* callback type for wildcard downloading pattern matching. If the + string matches the pattern, return CURL_FNMATCHFUNC_MATCH value, etc. */ +typedef int (*curl_fnmatch_callback)(void *ptr, + const char *pattern, + const char *string); + +/* These are the return codes for the seek callbacks */ +#define CURL_SEEKFUNC_OK 0 +#define CURL_SEEKFUNC_FAIL 1 /* fail the entire transfer */ +#define CURL_SEEKFUNC_CANTSEEK 2 /* tell libcurl seeking can't be done, so + libcurl might try other means instead */ +typedef int (*curl_seek_callback)(void *instream, + curl_off_t offset, + int origin); /* 'whence' */ + +/* This is a return code for the read callback that, when returned, will + signal libcurl to immediately abort the current transfer. */ +#define CURL_READFUNC_ABORT 0x10000000 +/* This is a return code for the read callback that, when returned, will + signal libcurl to pause sending data on the current transfer. */ +#define CURL_READFUNC_PAUSE 0x10000001 + +typedef size_t (*curl_read_callback)(char *buffer, + size_t size, + size_t nitems, + void *instream); + +typedef enum { + CURLSOCKTYPE_IPCXN, /* socket created for a specific IP connection */ + CURLSOCKTYPE_LAST /* never use */ +} curlsocktype; + +/* The return code from the sockopt_callback can signal information back + to libcurl: */ +#define CURL_SOCKOPT_OK 0 +#define CURL_SOCKOPT_ERROR 1 /* causes libcurl to abort and return + CURLE_ABORTED_BY_CALLBACK */ +#define CURL_SOCKOPT_ALREADY_CONNECTED 2 + +typedef int (*curl_sockopt_callback)(void *clientp, + curl_socket_t curlfd, + curlsocktype purpose); + +struct curl_sockaddr { + int family; + int socktype; + int protocol; + unsigned int addrlen; /* addrlen was a socklen_t type before 7.18.0 but it + turned really ugly and painful on the systems that + lack this type */ + struct sockaddr addr; +}; + +typedef curl_socket_t +(*curl_opensocket_callback)(void *clientp, + curlsocktype purpose, + struct curl_sockaddr *address); + +typedef enum { + CURLIOE_OK, /* I/O operation successful */ + CURLIOE_UNKNOWNCMD, /* command was unknown to callback */ + CURLIOE_FAILRESTART, /* failed to restart the read */ + CURLIOE_LAST /* never use */ +} curlioerr; + +typedef enum { + CURLIOCMD_NOP, /* no operation */ + CURLIOCMD_RESTARTREAD, /* restart the read stream from start */ + CURLIOCMD_LAST /* never use */ +} curliocmd; + +typedef curlioerr (*curl_ioctl_callback)(CURL *handle, + int cmd, + void *clientp); + +/* + * The following typedef's are signatures of malloc, free, realloc, strdup and + * calloc respectively. Function pointers of these types can be passed to the + * curl_global_init_mem() function to set user defined memory management + * callback routines. + */ +typedef void *(*curl_malloc_callback)(size_t size); +typedef void (*curl_free_callback)(void *ptr); +typedef void *(*curl_realloc_callback)(void *ptr, size_t size); +typedef char *(*curl_strdup_callback)(const char *str); +typedef void *(*curl_calloc_callback)(size_t nmemb, size_t size); + +/* the kind of data that is passed to information_callback*/ +typedef enum { + CURLINFO_TEXT = 0, + CURLINFO_HEADER_IN, /* 1 */ + CURLINFO_HEADER_OUT, /* 2 */ + CURLINFO_DATA_IN, /* 3 */ + CURLINFO_DATA_OUT, /* 4 */ + CURLINFO_SSL_DATA_IN, /* 5 */ + CURLINFO_SSL_DATA_OUT, /* 6 */ + CURLINFO_END +} curl_infotype; + +typedef int (*curl_debug_callback) + (CURL *handle, /* the handle/transfer this concerns */ + curl_infotype type, /* what kind of data */ + char *data, /* points to the data */ + size_t size, /* size of the data pointed to */ + void *userptr); /* whatever the user please */ + +/* All possible error codes from all sorts of curl functions. Future versions + may return other values, stay prepared. + + Always add new return codes last. Never *EVER* remove any. The return + codes must remain the same! + */ + +typedef enum { + CURLE_OK = 0, + CURLE_UNSUPPORTED_PROTOCOL, /* 1 */ + CURLE_FAILED_INIT, /* 2 */ + CURLE_URL_MALFORMAT, /* 3 */ + CURLE_NOT_BUILT_IN, /* 4 - [was obsoleted in August 2007 for + 7.17.0, reused in April 2011 for 7.21.5] */ + CURLE_COULDNT_RESOLVE_PROXY, /* 5 */ + CURLE_COULDNT_RESOLVE_HOST, /* 6 */ + CURLE_COULDNT_CONNECT, /* 7 */ + CURLE_FTP_WEIRD_SERVER_REPLY, /* 8 */ + CURLE_REMOTE_ACCESS_DENIED, /* 9 a service was denied by the server + due to lack of access - when login fails + this is not returned. */ + CURLE_OBSOLETE10, /* 10 - NOT USED */ + CURLE_FTP_WEIRD_PASS_REPLY, /* 11 */ + CURLE_OBSOLETE12, /* 12 - NOT USED */ + CURLE_FTP_WEIRD_PASV_REPLY, /* 13 */ + CURLE_FTP_WEIRD_227_FORMAT, /* 14 */ + CURLE_FTP_CANT_GET_HOST, /* 15 */ + CURLE_OBSOLETE16, /* 16 - NOT USED */ + CURLE_FTP_COULDNT_SET_TYPE, /* 17 */ + CURLE_PARTIAL_FILE, /* 18 */ + CURLE_FTP_COULDNT_RETR_FILE, /* 19 */ + CURLE_OBSOLETE20, /* 20 - NOT USED */ + CURLE_QUOTE_ERROR, /* 21 - quote command failure */ + CURLE_HTTP_RETURNED_ERROR, /* 22 */ + CURLE_WRITE_ERROR, /* 23 */ + CURLE_OBSOLETE24, /* 24 - NOT USED */ + CURLE_UPLOAD_FAILED, /* 25 - failed upload "command" */ + CURLE_READ_ERROR, /* 26 - couldn't open/read from file */ + CURLE_OUT_OF_MEMORY, /* 27 */ + /* Note: CURLE_OUT_OF_MEMORY may sometimes indicate a conversion error + instead of a memory allocation error if CURL_DOES_CONVERSIONS + is defined + */ + CURLE_OPERATION_TIMEDOUT, /* 28 - the timeout time was reached */ + CURLE_OBSOLETE29, /* 29 - NOT USED */ + CURLE_FTP_PORT_FAILED, /* 30 - FTP PORT operation failed */ + CURLE_FTP_COULDNT_USE_REST, /* 31 - the REST command failed */ + CURLE_OBSOLETE32, /* 32 - NOT USED */ + CURLE_RANGE_ERROR, /* 33 - RANGE "command" didn't work */ + CURLE_HTTP_POST_ERROR, /* 34 */ + CURLE_SSL_CONNECT_ERROR, /* 35 - wrong when connecting with SSL */ + CURLE_BAD_DOWNLOAD_RESUME, /* 36 - couldn't resume download */ + CURLE_FILE_COULDNT_READ_FILE, /* 37 */ + CURLE_LDAP_CANNOT_BIND, /* 38 */ + CURLE_LDAP_SEARCH_FAILED, /* 39 */ + CURLE_OBSOLETE40, /* 40 - NOT USED */ + CURLE_FUNCTION_NOT_FOUND, /* 41 */ + CURLE_ABORTED_BY_CALLBACK, /* 42 */ + CURLE_BAD_FUNCTION_ARGUMENT, /* 43 */ + CURLE_OBSOLETE44, /* 44 - NOT USED */ + CURLE_INTERFACE_FAILED, /* 45 - CURLOPT_INTERFACE failed */ + CURLE_OBSOLETE46, /* 46 - NOT USED */ + CURLE_TOO_MANY_REDIRECTS , /* 47 - catch endless re-direct loops */ + CURLE_UNKNOWN_OPTION, /* 48 - User specified an unknown option */ + CURLE_TELNET_OPTION_SYNTAX , /* 49 - Malformed telnet option */ + CURLE_OBSOLETE50, /* 50 - NOT USED */ + CURLE_PEER_FAILED_VERIFICATION, /* 51 - peer's certificate or fingerprint + wasn't verified fine */ + CURLE_GOT_NOTHING, /* 52 - when this is a specific error */ + CURLE_SSL_ENGINE_NOTFOUND, /* 53 - SSL crypto engine not found */ + CURLE_SSL_ENGINE_SETFAILED, /* 54 - can not set SSL crypto engine as + default */ + CURLE_SEND_ERROR, /* 55 - failed sending network data */ + CURLE_RECV_ERROR, /* 56 - failure in receiving network data */ + CURLE_OBSOLETE57, /* 57 - NOT IN USE */ + CURLE_SSL_CERTPROBLEM, /* 58 - problem with the local certificate */ + CURLE_SSL_CIPHER, /* 59 - couldn't use specified cipher */ + CURLE_SSL_CACERT, /* 60 - problem with the CA cert (path?) */ + CURLE_BAD_CONTENT_ENCODING, /* 61 - Unrecognized/bad encoding */ + CURLE_LDAP_INVALID_URL, /* 62 - Invalid LDAP URL */ + CURLE_FILESIZE_EXCEEDED, /* 63 - Maximum file size exceeded */ + CURLE_USE_SSL_FAILED, /* 64 - Requested FTP SSL level failed */ + CURLE_SEND_FAIL_REWIND, /* 65 - Sending the data requires a rewind + that failed */ + CURLE_SSL_ENGINE_INITFAILED, /* 66 - failed to initialise ENGINE */ + CURLE_LOGIN_DENIED, /* 67 - user, password or similar was not + accepted and we failed to login */ + CURLE_TFTP_NOTFOUND, /* 68 - file not found on server */ + CURLE_TFTP_PERM, /* 69 - permission problem on server */ + CURLE_REMOTE_DISK_FULL, /* 70 - out of disk space on server */ + CURLE_TFTP_ILLEGAL, /* 71 - Illegal TFTP operation */ + CURLE_TFTP_UNKNOWNID, /* 72 - Unknown transfer ID */ + CURLE_REMOTE_FILE_EXISTS, /* 73 - File already exists */ + CURLE_TFTP_NOSUCHUSER, /* 74 - No such user */ + CURLE_CONV_FAILED, /* 75 - conversion failed */ + CURLE_CONV_REQD, /* 76 - caller must register conversion + callbacks using curl_easy_setopt options + CURLOPT_CONV_FROM_NETWORK_FUNCTION, + CURLOPT_CONV_TO_NETWORK_FUNCTION, and + CURLOPT_CONV_FROM_UTF8_FUNCTION */ + CURLE_SSL_CACERT_BADFILE, /* 77 - could not load CACERT file, missing + or wrong format */ + CURLE_REMOTE_FILE_NOT_FOUND, /* 78 - remote file not found */ + CURLE_SSH, /* 79 - error from the SSH layer, somewhat + generic so the error message will be of + interest when this has happened */ + + CURLE_SSL_SHUTDOWN_FAILED, /* 80 - Failed to shut down the SSL + connection */ + CURLE_AGAIN, /* 81 - socket is not ready for send/recv, + wait till it's ready and try again (Added + in 7.18.2) */ + CURLE_SSL_CRL_BADFILE, /* 82 - could not load CRL file, missing or + wrong format (Added in 7.19.0) */ + CURLE_SSL_ISSUER_ERROR, /* 83 - Issuer check failed. (Added in + 7.19.0) */ + CURLE_FTP_PRET_FAILED, /* 84 - a PRET command failed */ + CURLE_RTSP_CSEQ_ERROR, /* 85 - mismatch of RTSP CSeq numbers */ + CURLE_RTSP_SESSION_ERROR, /* 86 - mismatch of RTSP Session Identifiers */ + CURLE_FTP_BAD_FILE_LIST, /* 87 - unable to parse FTP file list */ + CURLE_CHUNK_FAILED, /* 88 - chunk callback reported error */ + + CURL_LAST /* never use! */ +} CURLcode; + +#ifndef CURL_NO_OLDIES /* define this to test if your app builds with all + the obsolete stuff removed! */ + +/* compatibility with older names */ +#define CURLOPT_ENCODING CURLOPT_ACCEPT_ENCODING + +/* The following were added in 7.21.5, April 2011 */ +#define CURLE_UNKNOWN_TELNET_OPTION CURLE_UNKNOWN_OPTION + +/* The following were added in 7.17.1 */ +/* These are scheduled to disappear by 2009 */ +#define CURLE_SSL_PEER_CERTIFICATE CURLE_PEER_FAILED_VERIFICATION + +/* The following were added in 7.17.0 */ +/* These are scheduled to disappear by 2009 */ +#define CURLE_OBSOLETE CURLE_OBSOLETE50 /* no one should be using this! */ +#define CURLE_BAD_PASSWORD_ENTERED CURLE_OBSOLETE46 +#define CURLE_BAD_CALLING_ORDER CURLE_OBSOLETE44 +#define CURLE_FTP_USER_PASSWORD_INCORRECT CURLE_OBSOLETE10 +#define CURLE_FTP_CANT_RECONNECT CURLE_OBSOLETE16 +#define CURLE_FTP_COULDNT_GET_SIZE CURLE_OBSOLETE32 +#define CURLE_FTP_COULDNT_SET_ASCII CURLE_OBSOLETE29 +#define CURLE_FTP_WEIRD_USER_REPLY CURLE_OBSOLETE12 +#define CURLE_FTP_WRITE_ERROR CURLE_OBSOLETE20 +#define CURLE_LIBRARY_NOT_FOUND CURLE_OBSOLETE40 +#define CURLE_MALFORMAT_USER CURLE_OBSOLETE24 +#define CURLE_SHARE_IN_USE CURLE_OBSOLETE57 +#define CURLE_URL_MALFORMAT_USER CURLE_NOT_BUILT_IN + +#define CURLE_FTP_ACCESS_DENIED CURLE_REMOTE_ACCESS_DENIED +#define CURLE_FTP_COULDNT_SET_BINARY CURLE_FTP_COULDNT_SET_TYPE +#define CURLE_FTP_QUOTE_ERROR CURLE_QUOTE_ERROR +#define CURLE_TFTP_DISKFULL CURLE_REMOTE_DISK_FULL +#define CURLE_TFTP_EXISTS CURLE_REMOTE_FILE_EXISTS +#define CURLE_HTTP_RANGE_ERROR CURLE_RANGE_ERROR +#define CURLE_FTP_SSL_FAILED CURLE_USE_SSL_FAILED + +/* The following were added earlier */ + +#define CURLE_OPERATION_TIMEOUTED CURLE_OPERATION_TIMEDOUT + +#define CURLE_HTTP_NOT_FOUND CURLE_HTTP_RETURNED_ERROR +#define CURLE_HTTP_PORT_FAILED CURLE_INTERFACE_FAILED +#define CURLE_FTP_COULDNT_STOR_FILE CURLE_UPLOAD_FAILED + +#define CURLE_FTP_PARTIAL_FILE CURLE_PARTIAL_FILE +#define CURLE_FTP_BAD_DOWNLOAD_RESUME CURLE_BAD_DOWNLOAD_RESUME + +/* This was the error code 50 in 7.7.3 and a few earlier versions, this + is no longer used by libcurl but is instead #defined here only to not + make programs break */ +#define CURLE_ALREADY_COMPLETE 99999 + +#endif /*!CURL_NO_OLDIES*/ + +/* This prototype applies to all conversion callbacks */ +typedef CURLcode (*curl_conv_callback)(char *buffer, size_t length); + +typedef CURLcode (*curl_ssl_ctx_callback)(CURL *curl, /* easy handle */ + void *ssl_ctx, /* actually an + OpenSSL SSL_CTX */ + void *userptr); + +typedef enum { + CURLPROXY_HTTP = 0, /* added in 7.10, new in 7.19.4 default is to use + CONNECT HTTP/1.1 */ + CURLPROXY_HTTP_1_0 = 1, /* added in 7.19.4, force to use CONNECT + HTTP/1.0 */ + CURLPROXY_SOCKS4 = 4, /* support added in 7.15.2, enum existed already + in 7.10 */ + CURLPROXY_SOCKS5 = 5, /* added in 7.10 */ + CURLPROXY_SOCKS4A = 6, /* added in 7.18.0 */ + CURLPROXY_SOCKS5_HOSTNAME = 7 /* Use the SOCKS5 protocol but pass along the + host name rather than the IP address. added + in 7.18.0 */ +} curl_proxytype; /* this enum was added in 7.10 */ + +#define CURLAUTH_NONE 0 /* nothing */ +#define CURLAUTH_BASIC (1<<0) /* Basic (default) */ +#define CURLAUTH_DIGEST (1<<1) /* Digest */ +#define CURLAUTH_GSSNEGOTIATE (1<<2) /* GSS-Negotiate */ +#define CURLAUTH_NTLM (1<<3) /* NTLM */ +#define CURLAUTH_DIGEST_IE (1<<4) /* Digest with IE flavour */ +#define CURLAUTH_ONLY (1<<31) /* used together with a single other + type to force no auth or just that + single type */ +#define CURLAUTH_ANY (~CURLAUTH_DIGEST_IE) /* all fine types set */ +#define CURLAUTH_ANYSAFE (~(CURLAUTH_BASIC|CURLAUTH_DIGEST_IE)) + +#define CURLSSH_AUTH_ANY ~0 /* all types supported by the server */ +#define CURLSSH_AUTH_NONE 0 /* none allowed, silly but complete */ +#define CURLSSH_AUTH_PUBLICKEY (1<<0) /* public/private key files */ +#define CURLSSH_AUTH_PASSWORD (1<<1) /* password */ +#define CURLSSH_AUTH_HOST (1<<2) /* host key files */ +#define CURLSSH_AUTH_KEYBOARD (1<<3) /* keyboard interactive */ +#define CURLSSH_AUTH_DEFAULT CURLSSH_AUTH_ANY + +#define CURL_ERROR_SIZE 256 + +struct curl_khkey { + const char *key; /* points to a zero-terminated string encoded with base64 + if len is zero, otherwise to the "raw" data */ + size_t len; + enum type { + CURLKHTYPE_UNKNOWN, + CURLKHTYPE_RSA1, + CURLKHTYPE_RSA, + CURLKHTYPE_DSS + } keytype; +}; + +/* this is the set of return values expected from the curl_sshkeycallback + callback */ +enum curl_khstat { + CURLKHSTAT_FINE_ADD_TO_FILE, + CURLKHSTAT_FINE, + CURLKHSTAT_REJECT, /* reject the connection, return an error */ + CURLKHSTAT_DEFER, /* do not accept it, but we can't answer right now so + this causes a CURLE_DEFER error but otherwise the + connection will be left intact etc */ + CURLKHSTAT_LAST /* not for use, only a marker for last-in-list */ +}; + +/* this is the set of status codes pass in to the callback */ +enum curl_khmatch { + CURLKHMATCH_OK, /* match */ + CURLKHMATCH_MISMATCH, /* host found, key mismatch! */ + CURLKHMATCH_MISSING, /* no matching host/key found */ + CURLKHMATCH_LAST /* not for use, only a marker for last-in-list */ +}; + +typedef int + (*curl_sshkeycallback) (CURL *easy, /* easy handle */ + const struct curl_khkey *knownkey, /* known */ + const struct curl_khkey *foundkey, /* found */ + enum curl_khmatch, /* libcurl's view on the keys */ + void *clientp); /* custom pointer passed from app */ + +/* parameter for the CURLOPT_USE_SSL option */ +typedef enum { + CURLUSESSL_NONE, /* do not attempt to use SSL */ + CURLUSESSL_TRY, /* try using SSL, proceed anyway otherwise */ + CURLUSESSL_CONTROL, /* SSL for the control connection or fail */ + CURLUSESSL_ALL, /* SSL for all communication or fail */ + CURLUSESSL_LAST /* not an option, never use */ +} curl_usessl; + +#ifndef CURL_NO_OLDIES /* define this to test if your app builds with all + the obsolete stuff removed! */ + +/* Backwards compatibility with older names */ +/* These are scheduled to disappear by 2009 */ + +#define CURLFTPSSL_NONE CURLUSESSL_NONE +#define CURLFTPSSL_TRY CURLUSESSL_TRY +#define CURLFTPSSL_CONTROL CURLUSESSL_CONTROL +#define CURLFTPSSL_ALL CURLUSESSL_ALL +#define CURLFTPSSL_LAST CURLUSESSL_LAST +#define curl_ftpssl curl_usessl +#endif /*!CURL_NO_OLDIES*/ + +/* parameter for the CURLOPT_FTP_SSL_CCC option */ +typedef enum { + CURLFTPSSL_CCC_NONE, /* do not send CCC */ + CURLFTPSSL_CCC_PASSIVE, /* Let the server initiate the shutdown */ + CURLFTPSSL_CCC_ACTIVE, /* Initiate the shutdown */ + CURLFTPSSL_CCC_LAST /* not an option, never use */ +} curl_ftpccc; + +/* parameter for the CURLOPT_FTPSSLAUTH option */ +typedef enum { + CURLFTPAUTH_DEFAULT, /* let libcurl decide */ + CURLFTPAUTH_SSL, /* use "AUTH SSL" */ + CURLFTPAUTH_TLS, /* use "AUTH TLS" */ + CURLFTPAUTH_LAST /* not an option, never use */ +} curl_ftpauth; + +/* parameter for the CURLOPT_FTP_CREATE_MISSING_DIRS option */ +typedef enum { + CURLFTP_CREATE_DIR_NONE, /* do NOT create missing dirs! */ + CURLFTP_CREATE_DIR, /* (FTP/SFTP) if CWD fails, try MKD and then CWD + again if MKD succeeded, for SFTP this does + similar magic */ + CURLFTP_CREATE_DIR_RETRY, /* (FTP only) if CWD fails, try MKD and then CWD + again even if MKD failed! */ + CURLFTP_CREATE_DIR_LAST /* not an option, never use */ +} curl_ftpcreatedir; + +/* parameter for the CURLOPT_FTP_FILEMETHOD option */ +typedef enum { + CURLFTPMETHOD_DEFAULT, /* let libcurl pick */ + CURLFTPMETHOD_MULTICWD, /* single CWD operation for each path part */ + CURLFTPMETHOD_NOCWD, /* no CWD at all */ + CURLFTPMETHOD_SINGLECWD, /* one CWD to full dir, then work on file */ + CURLFTPMETHOD_LAST /* not an option, never use */ +} curl_ftpmethod; + +/* CURLPROTO_ defines are for the CURLOPT_*PROTOCOLS options */ +#define CURLPROTO_HTTP (1<<0) +#define CURLPROTO_HTTPS (1<<1) +#define CURLPROTO_FTP (1<<2) +#define CURLPROTO_FTPS (1<<3) +#define CURLPROTO_SCP (1<<4) +#define CURLPROTO_SFTP (1<<5) +#define CURLPROTO_TELNET (1<<6) +#define CURLPROTO_LDAP (1<<7) +#define CURLPROTO_LDAPS (1<<8) +#define CURLPROTO_DICT (1<<9) +#define CURLPROTO_FILE (1<<10) +#define CURLPROTO_TFTP (1<<11) +#define CURLPROTO_IMAP (1<<12) +#define CURLPROTO_IMAPS (1<<13) +#define CURLPROTO_POP3 (1<<14) +#define CURLPROTO_POP3S (1<<15) +#define CURLPROTO_SMTP (1<<16) +#define CURLPROTO_SMTPS (1<<17) +#define CURLPROTO_RTSP (1<<18) +#define CURLPROTO_RTMP (1<<19) +#define CURLPROTO_RTMPT (1<<20) +#define CURLPROTO_RTMPE (1<<21) +#define CURLPROTO_RTMPTE (1<<22) +#define CURLPROTO_RTMPS (1<<23) +#define CURLPROTO_RTMPTS (1<<24) +#define CURLPROTO_GOPHER (1<<25) +#define CURLPROTO_ALL (~0) /* enable everything */ + +/* long may be 32 or 64 bits, but we should never depend on anything else + but 32 */ +#define CURLOPTTYPE_LONG 0 +#define CURLOPTTYPE_OBJECTPOINT 10000 +#define CURLOPTTYPE_FUNCTIONPOINT 20000 +#define CURLOPTTYPE_OFF_T 30000 + +/* name is uppercase CURLOPT_, + type is one of the defined CURLOPTTYPE_ + number is unique identifier */ +#ifdef CINIT +#undef CINIT +#endif + +#ifdef CURL_ISOCPP +#define CINIT(name,type,number) CURLOPT_ ## name = CURLOPTTYPE_ ## type + number +#else +/* The macro "##" is ISO C, we assume pre-ISO C doesn't support it. */ +#define LONG CURLOPTTYPE_LONG +#define OBJECTPOINT CURLOPTTYPE_OBJECTPOINT +#define FUNCTIONPOINT CURLOPTTYPE_FUNCTIONPOINT +#define OFF_T CURLOPTTYPE_OFF_T +#define CINIT(name,type,number) CURLOPT_/**/name = type + number +#endif + +/* + * This macro-mania below setups the CURLOPT_[what] enum, to be used with + * curl_easy_setopt(). The first argument in the CINIT() macro is the [what] + * word. + */ + +typedef enum { + /* This is the FILE * or void * the regular output should be written to. */ + CINIT(FILE, OBJECTPOINT, 1), + + /* The full URL to get/put */ + CINIT(URL, OBJECTPOINT, 2), + + /* Port number to connect to, if other than default. */ + CINIT(PORT, LONG, 3), + + /* Name of proxy to use. */ + CINIT(PROXY, OBJECTPOINT, 4), + + /* "name:password" to use when fetching. */ + CINIT(USERPWD, OBJECTPOINT, 5), + + /* "name:password" to use with proxy. */ + CINIT(PROXYUSERPWD, OBJECTPOINT, 6), + + /* Range to get, specified as an ASCII string. */ + CINIT(RANGE, OBJECTPOINT, 7), + + /* not used */ + + /* Specified file stream to upload from (use as input): */ + CINIT(INFILE, OBJECTPOINT, 9), + + /* Buffer to receive error messages in, must be at least CURL_ERROR_SIZE + * bytes big. If this is not used, error messages go to stderr instead: */ + CINIT(ERRORBUFFER, OBJECTPOINT, 10), + + /* Function that will be called to store the output (instead of fwrite). The + * parameters will use fwrite() syntax, make sure to follow them. */ + CINIT(WRITEFUNCTION, FUNCTIONPOINT, 11), + + /* Function that will be called to read the input (instead of fread). The + * parameters will use fread() syntax, make sure to follow them. */ + CINIT(READFUNCTION, FUNCTIONPOINT, 12), + + /* Time-out the read operation after this amount of seconds */ + CINIT(TIMEOUT, LONG, 13), + + /* If the CURLOPT_INFILE is used, this can be used to inform libcurl about + * how large the file being sent really is. That allows better error + * checking and better verifies that the upload was successful. -1 means + * unknown size. + * + * For large file support, there is also a _LARGE version of the key + * which takes an off_t type, allowing platforms with larger off_t + * sizes to handle larger files. See below for INFILESIZE_LARGE. + */ + CINIT(INFILESIZE, LONG, 14), + + /* POST static input fields. */ + CINIT(POSTFIELDS, OBJECTPOINT, 15), + + /* Set the referrer page (needed by some CGIs) */ + CINIT(REFERER, OBJECTPOINT, 16), + + /* Set the FTP PORT string (interface name, named or numerical IP address) + Use i.e '-' to use default address. */ + CINIT(FTPPORT, OBJECTPOINT, 17), + + /* Set the User-Agent string (examined by some CGIs) */ + CINIT(USERAGENT, OBJECTPOINT, 18), + + /* If the download receives less than "low speed limit" bytes/second + * during "low speed time" seconds, the operations is aborted. + * You could i.e if you have a pretty high speed connection, abort if + * it is less than 2000 bytes/sec during 20 seconds. + */ + + /* Set the "low speed limit" */ + CINIT(LOW_SPEED_LIMIT, LONG, 19), + + /* Set the "low speed time" */ + CINIT(LOW_SPEED_TIME, LONG, 20), + + /* Set the continuation offset. + * + * Note there is also a _LARGE version of this key which uses + * off_t types, allowing for large file offsets on platforms which + * use larger-than-32-bit off_t's. Look below for RESUME_FROM_LARGE. + */ + CINIT(RESUME_FROM, LONG, 21), + + /* Set cookie in request: */ + CINIT(COOKIE, OBJECTPOINT, 22), + + /* This points to a linked list of headers, struct curl_slist kind */ + CINIT(HTTPHEADER, OBJECTPOINT, 23), + + /* This points to a linked list of post entries, struct curl_httppost */ + CINIT(HTTPPOST, OBJECTPOINT, 24), + + /* name of the file keeping your private SSL-certificate */ + CINIT(SSLCERT, OBJECTPOINT, 25), + + /* password for the SSL or SSH private key */ + CINIT(KEYPASSWD, OBJECTPOINT, 26), + + /* send TYPE parameter? */ + CINIT(CRLF, LONG, 27), + + /* send linked-list of QUOTE commands */ + CINIT(QUOTE, OBJECTPOINT, 28), + + /* send FILE * or void * to store headers to, if you use a callback it + is simply passed to the callback unmodified */ + CINIT(WRITEHEADER, OBJECTPOINT, 29), + + /* point to a file to read the initial cookies from, also enables + "cookie awareness" */ + CINIT(COOKIEFILE, OBJECTPOINT, 31), + + /* What version to specifically try to use. + See CURL_SSLVERSION defines below. */ + CINIT(SSLVERSION, LONG, 32), + + /* What kind of HTTP time condition to use, see defines */ + CINIT(TIMECONDITION, LONG, 33), + + /* Time to use with the above condition. Specified in number of seconds + since 1 Jan 1970 */ + CINIT(TIMEVALUE, LONG, 34), + + /* 35 = OBSOLETE */ + + /* Custom request, for customizing the get command like + HTTP: DELETE, TRACE and others + FTP: to use a different list command + */ + CINIT(CUSTOMREQUEST, OBJECTPOINT, 36), + + /* HTTP request, for odd commands like DELETE, TRACE and others */ + CINIT(STDERR, OBJECTPOINT, 37), + + /* 38 is not used */ + + /* send linked-list of post-transfer QUOTE commands */ + CINIT(POSTQUOTE, OBJECTPOINT, 39), + + /* Pass a pointer to string of the output using full variable-replacement + as described elsewhere. */ + CINIT(WRITEINFO, OBJECTPOINT, 40), + + CINIT(VERBOSE, LONG, 41), /* talk a lot */ + CINIT(HEADER, LONG, 42), /* throw the header out too */ + CINIT(NOPROGRESS, LONG, 43), /* shut off the progress meter */ + CINIT(NOBODY, LONG, 44), /* use HEAD to get http document */ + CINIT(FAILONERROR, LONG, 45), /* no output on http error codes >= 300 */ + CINIT(UPLOAD, LONG, 46), /* this is an upload */ + CINIT(POST, LONG, 47), /* HTTP POST method */ + CINIT(DIRLISTONLY, LONG, 48), /* return bare names when listing directories */ + + CINIT(APPEND, LONG, 50), /* Append instead of overwrite on upload! */ + + /* Specify whether to read the user+password from the .netrc or the URL. + * This must be one of the CURL_NETRC_* enums below. */ + CINIT(NETRC, LONG, 51), + + CINIT(FOLLOWLOCATION, LONG, 52), /* use Location: Luke! */ + + CINIT(TRANSFERTEXT, LONG, 53), /* transfer data in text/ASCII format */ + CINIT(PUT, LONG, 54), /* HTTP PUT */ + + /* 55 = OBSOLETE */ + + /* Function that will be called instead of the internal progress display + * function. This function should be defined as the curl_progress_callback + * prototype defines. */ + CINIT(PROGRESSFUNCTION, FUNCTIONPOINT, 56), + + /* Data passed to the progress callback */ + CINIT(PROGRESSDATA, OBJECTPOINT, 57), + + /* We want the referrer field set automatically when following locations */ + CINIT(AUTOREFERER, LONG, 58), + + /* Port of the proxy, can be set in the proxy string as well with: + "[host]:[port]" */ + CINIT(PROXYPORT, LONG, 59), + + /* size of the POST input data, if strlen() is not good to use */ + CINIT(POSTFIELDSIZE, LONG, 60), + + /* tunnel non-http operations through a HTTP proxy */ + CINIT(HTTPPROXYTUNNEL, LONG, 61), + + /* Set the interface string to use as outgoing network interface */ + CINIT(INTERFACE, OBJECTPOINT, 62), + + /* Set the krb4/5 security level, this also enables krb4/5 awareness. This + * is a string, 'clear', 'safe', 'confidential' or 'private'. If the string + * is set but doesn't match one of these, 'private' will be used. */ + CINIT(KRBLEVEL, OBJECTPOINT, 63), + + /* Set if we should verify the peer in ssl handshake, set 1 to verify. */ + CINIT(SSL_VERIFYPEER, LONG, 64), + + /* The CApath or CAfile used to validate the peer certificate + this option is used only if SSL_VERIFYPEER is true */ + CINIT(CAINFO, OBJECTPOINT, 65), + + /* 66 = OBSOLETE */ + /* 67 = OBSOLETE */ + + /* Maximum number of http redirects to follow */ + CINIT(MAXREDIRS, LONG, 68), + + /* Pass a long set to 1 to get the date of the requested document (if + possible)! Pass a zero to shut it off. */ + CINIT(FILETIME, LONG, 69), + + /* This points to a linked list of telnet options */ + CINIT(TELNETOPTIONS, OBJECTPOINT, 70), + + /* Max amount of cached alive connections */ + CINIT(MAXCONNECTS, LONG, 71), + + /* What policy to use when closing connections when the cache is filled + up */ + CINIT(CLOSEPOLICY, LONG, 72), + + /* 73 = OBSOLETE */ + + /* Set to explicitly use a new connection for the upcoming transfer. + Do not use this unless you're absolutely sure of this, as it makes the + operation slower and is less friendly for the network. */ + CINIT(FRESH_CONNECT, LONG, 74), + + /* Set to explicitly forbid the upcoming transfer's connection to be re-used + when done. Do not use this unless you're absolutely sure of this, as it + makes the operation slower and is less friendly for the network. */ + CINIT(FORBID_REUSE, LONG, 75), + + /* Set to a file name that contains random data for libcurl to use to + seed the random engine when doing SSL connects. */ + CINIT(RANDOM_FILE, OBJECTPOINT, 76), + + /* Set to the Entropy Gathering Daemon socket pathname */ + CINIT(EGDSOCKET, OBJECTPOINT, 77), + + /* Time-out connect operations after this amount of seconds, if connects + are OK within this time, then fine... This only aborts the connect + phase. [Only works on unix-style/SIGALRM operating systems] */ + CINIT(CONNECTTIMEOUT, LONG, 78), + + /* Function that will be called to store headers (instead of fwrite). The + * parameters will use fwrite() syntax, make sure to follow them. */ + CINIT(HEADERFUNCTION, FUNCTIONPOINT, 79), + + /* Set this to force the HTTP request to get back to GET. Only really usable + if POST, PUT or a custom request have been used first. + */ + CINIT(HTTPGET, LONG, 80), + + /* Set if we should verify the Common name from the peer certificate in ssl + * handshake, set 1 to check existence, 2 to ensure that it matches the + * provided hostname. */ + CINIT(SSL_VERIFYHOST, LONG, 81), + + /* Specify which file name to write all known cookies in after completed + operation. Set file name to "-" (dash) to make it go to stdout. */ + CINIT(COOKIEJAR, OBJECTPOINT, 82), + + /* Specify which SSL ciphers to use */ + CINIT(SSL_CIPHER_LIST, OBJECTPOINT, 83), + + /* Specify which HTTP version to use! This must be set to one of the + CURL_HTTP_VERSION* enums set below. */ + CINIT(HTTP_VERSION, LONG, 84), + + /* Specifically switch on or off the FTP engine's use of the EPSV command. By + default, that one will always be attempted before the more traditional + PASV command. */ + CINIT(FTP_USE_EPSV, LONG, 85), + + /* type of the file keeping your SSL-certificate ("DER", "PEM", "ENG") */ + CINIT(SSLCERTTYPE, OBJECTPOINT, 86), + + /* name of the file keeping your private SSL-key */ + CINIT(SSLKEY, OBJECTPOINT, 87), + + /* type of the file keeping your private SSL-key ("DER", "PEM", "ENG") */ + CINIT(SSLKEYTYPE, OBJECTPOINT, 88), + + /* crypto engine for the SSL-sub system */ + CINIT(SSLENGINE, OBJECTPOINT, 89), + + /* set the crypto engine for the SSL-sub system as default + the param has no meaning... + */ + CINIT(SSLENGINE_DEFAULT, LONG, 90), + + /* Non-zero value means to use the global dns cache */ + CINIT(DNS_USE_GLOBAL_CACHE, LONG, 91), /* To become OBSOLETE soon */ + + /* DNS cache timeout */ + CINIT(DNS_CACHE_TIMEOUT, LONG, 92), + + /* send linked-list of pre-transfer QUOTE commands */ + CINIT(PREQUOTE, OBJECTPOINT, 93), + + /* set the debug function */ + CINIT(DEBUGFUNCTION, FUNCTIONPOINT, 94), + + /* set the data for the debug function */ + CINIT(DEBUGDATA, OBJECTPOINT, 95), + + /* mark this as start of a cookie session */ + CINIT(COOKIESESSION, LONG, 96), + + /* The CApath directory used to validate the peer certificate + this option is used only if SSL_VERIFYPEER is true */ + CINIT(CAPATH, OBJECTPOINT, 97), + + /* Instruct libcurl to use a smaller receive buffer */ + CINIT(BUFFERSIZE, LONG, 98), + + /* Instruct libcurl to not use any signal/alarm handlers, even when using + timeouts. This option is useful for multi-threaded applications. + See libcurl-the-guide for more background information. */ + CINIT(NOSIGNAL, LONG, 99), + + /* Provide a CURLShare for mutexing non-ts data */ + CINIT(SHARE, OBJECTPOINT, 100), + + /* indicates type of proxy. accepted values are CURLPROXY_HTTP (default), + CURLPROXY_SOCKS4, CURLPROXY_SOCKS4A and CURLPROXY_SOCKS5. */ + CINIT(PROXYTYPE, LONG, 101), + + /* Set the Accept-Encoding string. Use this to tell a server you would like + the response to be compressed. Before 7.21.6, this was known as + CURLOPT_ENCODING */ + CINIT(ACCEPT_ENCODING, OBJECTPOINT, 102), + + /* Set pointer to private data */ + CINIT(PRIVATE, OBJECTPOINT, 103), + + /* Set aliases for HTTP 200 in the HTTP Response header */ + CINIT(HTTP200ALIASES, OBJECTPOINT, 104), + + /* Continue to send authentication (user+password) when following locations, + even when hostname changed. This can potentially send off the name + and password to whatever host the server decides. */ + CINIT(UNRESTRICTED_AUTH, LONG, 105), + + /* Specifically switch on or off the FTP engine's use of the EPRT command ( it + also disables the LPRT attempt). By default, those ones will always be + attempted before the good old traditional PORT command. */ + CINIT(FTP_USE_EPRT, LONG, 106), + + /* Set this to a bitmask value to enable the particular authentications + methods you like. Use this in combination with CURLOPT_USERPWD. + Note that setting multiple bits may cause extra network round-trips. */ + CINIT(HTTPAUTH, LONG, 107), + + /* Set the ssl context callback function, currently only for OpenSSL ssl_ctx + in second argument. The function must be matching the + curl_ssl_ctx_callback proto. */ + CINIT(SSL_CTX_FUNCTION, FUNCTIONPOINT, 108), + + /* Set the userdata for the ssl context callback function's third + argument */ + CINIT(SSL_CTX_DATA, OBJECTPOINT, 109), + + /* FTP Option that causes missing dirs to be created on the remote server. + In 7.19.4 we introduced the convenience enums for this option using the + CURLFTP_CREATE_DIR prefix. + */ + CINIT(FTP_CREATE_MISSING_DIRS, LONG, 110), + + /* Set this to a bitmask value to enable the particular authentications + methods you like. Use this in combination with CURLOPT_PROXYUSERPWD. + Note that setting multiple bits may cause extra network round-trips. */ + CINIT(PROXYAUTH, LONG, 111), + + /* FTP option that changes the timeout, in seconds, associated with + getting a response. This is different from transfer timeout time and + essentially places a demand on the FTP server to acknowledge commands + in a timely manner. */ + CINIT(FTP_RESPONSE_TIMEOUT, LONG, 112), +#define CURLOPT_SERVER_RESPONSE_TIMEOUT CURLOPT_FTP_RESPONSE_TIMEOUT + + /* Set this option to one of the CURL_IPRESOLVE_* defines (see below) to + tell libcurl to resolve names to those IP versions only. This only has + affect on systems with support for more than one, i.e IPv4 _and_ IPv6. */ + CINIT(IPRESOLVE, LONG, 113), + + /* Set this option to limit the size of a file that will be downloaded from + an HTTP or FTP server. + + Note there is also _LARGE version which adds large file support for + platforms which have larger off_t sizes. See MAXFILESIZE_LARGE below. */ + CINIT(MAXFILESIZE, LONG, 114), + + /* See the comment for INFILESIZE above, but in short, specifies + * the size of the file being uploaded. -1 means unknown. + */ + CINIT(INFILESIZE_LARGE, OFF_T, 115), + + /* Sets the continuation offset. There is also a LONG version of this; + * look above for RESUME_FROM. + */ + CINIT(RESUME_FROM_LARGE, OFF_T, 116), + + /* Sets the maximum size of data that will be downloaded from + * an HTTP or FTP server. See MAXFILESIZE above for the LONG version. + */ + CINIT(MAXFILESIZE_LARGE, OFF_T, 117), + + /* Set this option to the file name of your .netrc file you want libcurl + to parse (using the CURLOPT_NETRC option). If not set, libcurl will do + a poor attempt to find the user's home directory and check for a .netrc + file in there. */ + CINIT(NETRC_FILE, OBJECTPOINT, 118), + + /* Enable SSL/TLS for FTP, pick one of: + CURLFTPSSL_TRY - try using SSL, proceed anyway otherwise + CURLFTPSSL_CONTROL - SSL for the control connection or fail + CURLFTPSSL_ALL - SSL for all communication or fail + */ + CINIT(USE_SSL, LONG, 119), + + /* The _LARGE version of the standard POSTFIELDSIZE option */ + CINIT(POSTFIELDSIZE_LARGE, OFF_T, 120), + + /* Enable/disable the TCP Nagle algorithm */ + CINIT(TCP_NODELAY, LONG, 121), + + /* 122 OBSOLETE, used in 7.12.3. Gone in 7.13.0 */ + /* 123 OBSOLETE. Gone in 7.16.0 */ + /* 124 OBSOLETE, used in 7.12.3. Gone in 7.13.0 */ + /* 125 OBSOLETE, used in 7.12.3. Gone in 7.13.0 */ + /* 126 OBSOLETE, used in 7.12.3. Gone in 7.13.0 */ + /* 127 OBSOLETE. Gone in 7.16.0 */ + /* 128 OBSOLETE. Gone in 7.16.0 */ + + /* When FTP over SSL/TLS is selected (with CURLOPT_USE_SSL), this option + can be used to change libcurl's default action which is to first try + "AUTH SSL" and then "AUTH TLS" in this order, and proceed when a OK + response has been received. + + Available parameters are: + CURLFTPAUTH_DEFAULT - let libcurl decide + CURLFTPAUTH_SSL - try "AUTH SSL" first, then TLS + CURLFTPAUTH_TLS - try "AUTH TLS" first, then SSL + */ + CINIT(FTPSSLAUTH, LONG, 129), + + CINIT(IOCTLFUNCTION, FUNCTIONPOINT, 130), + CINIT(IOCTLDATA, OBJECTPOINT, 131), + + /* 132 OBSOLETE. Gone in 7.16.0 */ + /* 133 OBSOLETE. Gone in 7.16.0 */ + + /* zero terminated string for pass on to the FTP server when asked for + "account" info */ + CINIT(FTP_ACCOUNT, OBJECTPOINT, 134), + + /* feed cookies into cookie engine */ + CINIT(COOKIELIST, OBJECTPOINT, 135), + + /* ignore Content-Length */ + CINIT(IGNORE_CONTENT_LENGTH, LONG, 136), + + /* Set to non-zero to skip the IP address received in a 227 PASV FTP server + response. Typically used for FTP-SSL purposes but is not restricted to + that. libcurl will then instead use the same IP address it used for the + control connection. */ + CINIT(FTP_SKIP_PASV_IP, LONG, 137), + + /* Select "file method" to use when doing FTP, see the curl_ftpmethod + above. */ + CINIT(FTP_FILEMETHOD, LONG, 138), + + /* Local port number to bind the socket to */ + CINIT(LOCALPORT, LONG, 139), + + /* Number of ports to try, including the first one set with LOCALPORT. + Thus, setting it to 1 will make no additional attempts but the first. + */ + CINIT(LOCALPORTRANGE, LONG, 140), + + /* no transfer, set up connection and let application use the socket by + extracting it with CURLINFO_LASTSOCKET */ + CINIT(CONNECT_ONLY, LONG, 141), + + /* Function that will be called to convert from the + network encoding (instead of using the iconv calls in libcurl) */ + CINIT(CONV_FROM_NETWORK_FUNCTION, FUNCTIONPOINT, 142), + + /* Function that will be called to convert to the + network encoding (instead of using the iconv calls in libcurl) */ + CINIT(CONV_TO_NETWORK_FUNCTION, FUNCTIONPOINT, 143), + + /* Function that will be called to convert from UTF8 + (instead of using the iconv calls in libcurl) + Note that this is used only for SSL certificate processing */ + CINIT(CONV_FROM_UTF8_FUNCTION, FUNCTIONPOINT, 144), + + /* if the connection proceeds too quickly then need to slow it down */ + /* limit-rate: maximum number of bytes per second to send or receive */ + CINIT(MAX_SEND_SPEED_LARGE, OFF_T, 145), + CINIT(MAX_RECV_SPEED_LARGE, OFF_T, 146), + + /* Pointer to command string to send if USER/PASS fails. */ + CINIT(FTP_ALTERNATIVE_TO_USER, OBJECTPOINT, 147), + + /* callback function for setting socket options */ + CINIT(SOCKOPTFUNCTION, FUNCTIONPOINT, 148), + CINIT(SOCKOPTDATA, OBJECTPOINT, 149), + + /* set to 0 to disable session ID re-use for this transfer, default is + enabled (== 1) */ + CINIT(SSL_SESSIONID_CACHE, LONG, 150), + + /* allowed SSH authentication methods */ + CINIT(SSH_AUTH_TYPES, LONG, 151), + + /* Used by scp/sftp to do public/private key authentication */ + CINIT(SSH_PUBLIC_KEYFILE, OBJECTPOINT, 152), + CINIT(SSH_PRIVATE_KEYFILE, OBJECTPOINT, 153), + + /* Send CCC (Clear Command Channel) after authentication */ + CINIT(FTP_SSL_CCC, LONG, 154), + + /* Same as TIMEOUT and CONNECTTIMEOUT, but with ms resolution */ + CINIT(TIMEOUT_MS, LONG, 155), + CINIT(CONNECTTIMEOUT_MS, LONG, 156), + + /* set to zero to disable the libcurl's decoding and thus pass the raw body + data to the application even when it is encoded/compressed */ + CINIT(HTTP_TRANSFER_DECODING, LONG, 157), + CINIT(HTTP_CONTENT_DECODING, LONG, 158), + + /* Permission used when creating new files and directories on the remote + server for protocols that support it, SFTP/SCP/FILE */ + CINIT(NEW_FILE_PERMS, LONG, 159), + CINIT(NEW_DIRECTORY_PERMS, LONG, 160), + + /* Set the behaviour of POST when redirecting. Values must be set to one + of CURL_REDIR* defines below. This used to be called CURLOPT_POST301 */ + CINIT(POSTREDIR, LONG, 161), + + /* used by scp/sftp to verify the host's public key */ + CINIT(SSH_HOST_PUBLIC_KEY_MD5, OBJECTPOINT, 162), + + /* Callback function for opening socket (instead of socket(2)). Optionally, + callback is able change the address or refuse to connect returning + CURL_SOCKET_BAD. The callback should have type + curl_opensocket_callback */ + CINIT(OPENSOCKETFUNCTION, FUNCTIONPOINT, 163), + CINIT(OPENSOCKETDATA, OBJECTPOINT, 164), + + /* POST volatile input fields. */ + CINIT(COPYPOSTFIELDS, OBJECTPOINT, 165), + + /* set transfer mode (;type=) when doing FTP via an HTTP proxy */ + CINIT(PROXY_TRANSFER_MODE, LONG, 166), + + /* Callback function for seeking in the input stream */ + CINIT(SEEKFUNCTION, FUNCTIONPOINT, 167), + CINIT(SEEKDATA, OBJECTPOINT, 168), + + /* CRL file */ + CINIT(CRLFILE, OBJECTPOINT, 169), + + /* Issuer certificate */ + CINIT(ISSUERCERT, OBJECTPOINT, 170), + + /* (IPv6) Address scope */ + CINIT(ADDRESS_SCOPE, LONG, 171), + + /* Collect certificate chain info and allow it to get retrievable with + CURLINFO_CERTINFO after the transfer is complete. (Unfortunately) only + working with OpenSSL-powered builds. */ + CINIT(CERTINFO, LONG, 172), + + /* "name" and "pwd" to use when fetching. */ + CINIT(USERNAME, OBJECTPOINT, 173), + CINIT(PASSWORD, OBJECTPOINT, 174), + + /* "name" and "pwd" to use with Proxy when fetching. */ + CINIT(PROXYUSERNAME, OBJECTPOINT, 175), + CINIT(PROXYPASSWORD, OBJECTPOINT, 176), + + /* Comma separated list of hostnames defining no-proxy zones. These should + match both hostnames directly, and hostnames within a domain. For + example, local.com will match local.com and www.local.com, but NOT + notlocal.com or www.notlocal.com. For compatibility with other + implementations of this, .local.com will be considered to be the same as + local.com. A single * is the only valid wildcard, and effectively + disables the use of proxy. */ + CINIT(NOPROXY, OBJECTPOINT, 177), + + /* block size for TFTP transfers */ + CINIT(TFTP_BLKSIZE, LONG, 178), + + /* Socks Service */ + CINIT(SOCKS5_GSSAPI_SERVICE, OBJECTPOINT, 179), + + /* Socks Service */ + CINIT(SOCKS5_GSSAPI_NEC, LONG, 180), + + /* set the bitmask for the protocols that are allowed to be used for the + transfer, which thus helps the app which takes URLs from users or other + external inputs and want to restrict what protocol(s) to deal + with. Defaults to CURLPROTO_ALL. */ + CINIT(PROTOCOLS, LONG, 181), + + /* set the bitmask for the protocols that libcurl is allowed to follow to, + as a subset of the CURLOPT_PROTOCOLS ones. That means the protocol needs + to be set in both bitmasks to be allowed to get redirected to. Defaults + to all protocols except FILE and SCP. */ + CINIT(REDIR_PROTOCOLS, LONG, 182), + + /* set the SSH knownhost file name to use */ + CINIT(SSH_KNOWNHOSTS, OBJECTPOINT, 183), + + /* set the SSH host key callback, must point to a curl_sshkeycallback + function */ + CINIT(SSH_KEYFUNCTION, FUNCTIONPOINT, 184), + + /* set the SSH host key callback custom pointer */ + CINIT(SSH_KEYDATA, OBJECTPOINT, 185), + + /* set the SMTP mail originator */ + CINIT(MAIL_FROM, OBJECTPOINT, 186), + + /* set the SMTP mail receiver(s) */ + CINIT(MAIL_RCPT, OBJECTPOINT, 187), + + /* FTP: send PRET before PASV */ + CINIT(FTP_USE_PRET, LONG, 188), + + /* RTSP request method (OPTIONS, SETUP, PLAY, etc...) */ + CINIT(RTSP_REQUEST, LONG, 189), + + /* The RTSP session identifier */ + CINIT(RTSP_SESSION_ID, OBJECTPOINT, 190), + + /* The RTSP stream URI */ + CINIT(RTSP_STREAM_URI, OBJECTPOINT, 191), + + /* The Transport: header to use in RTSP requests */ + CINIT(RTSP_TRANSPORT, OBJECTPOINT, 192), + + /* Manually initialize the client RTSP CSeq for this handle */ + CINIT(RTSP_CLIENT_CSEQ, LONG, 193), + + /* Manually initialize the server RTSP CSeq for this handle */ + CINIT(RTSP_SERVER_CSEQ, LONG, 194), + + /* The stream to pass to INTERLEAVEFUNCTION. */ + CINIT(INTERLEAVEDATA, OBJECTPOINT, 195), + + /* Let the application define a custom write method for RTP data */ + CINIT(INTERLEAVEFUNCTION, FUNCTIONPOINT, 196), + + /* Turn on wildcard matching */ + CINIT(WILDCARDMATCH, LONG, 197), + + /* Directory matching callback called before downloading of an + individual file (chunk) started */ + CINIT(CHUNK_BGN_FUNCTION, FUNCTIONPOINT, 198), + + /* Directory matching callback called after the file (chunk) + was downloaded, or skipped */ + CINIT(CHUNK_END_FUNCTION, FUNCTIONPOINT, 199), + + /* Change match (fnmatch-like) callback for wildcard matching */ + CINIT(FNMATCH_FUNCTION, FUNCTIONPOINT, 200), + + /* Let the application define custom chunk data pointer */ + CINIT(CHUNK_DATA, OBJECTPOINT, 201), + + /* FNMATCH_FUNCTION user pointer */ + CINIT(FNMATCH_DATA, OBJECTPOINT, 202), + + /* send linked-list of name:port:address sets */ + CINIT(RESOLVE, OBJECTPOINT, 203), + + /* Set a username for authenticated TLS */ + CINIT(TLSAUTH_USERNAME, OBJECTPOINT, 204), + + /* Set a password for authenticated TLS */ + CINIT(TLSAUTH_PASSWORD, OBJECTPOINT, 205), + + /* Set authentication type for authenticated TLS */ + CINIT(TLSAUTH_TYPE, OBJECTPOINT, 206), + + /* Set to 1 to enable the "TE:" header in HTTP requests to ask for + compressed transfer-encoded responses. Set to 0 to disable the use of TE: + in outgoing requests. The current default is 0, but it might change in a + future libcurl release. + + libcurl will ask for the compressed methods it knows of, and if that + isn't any, it will not ask for transfer-encoding at all even if this + option is set to 1. + + */ + CINIT(TRANSFER_ENCODING, LONG, 207), + + CURLOPT_LASTENTRY /* the last unused */ +} CURLoption; + +#ifndef CURL_NO_OLDIES /* define this to test if your app builds with all + the obsolete stuff removed! */ + +/* Backwards compatibility with older names */ +/* These are scheduled to disappear by 2011 */ + +/* This was added in version 7.19.1 */ +#define CURLOPT_POST301 CURLOPT_POSTREDIR + +/* These are scheduled to disappear by 2009 */ + +/* The following were added in 7.17.0 */ +#define CURLOPT_SSLKEYPASSWD CURLOPT_KEYPASSWD +#define CURLOPT_FTPAPPEND CURLOPT_APPEND +#define CURLOPT_FTPLISTONLY CURLOPT_DIRLISTONLY +#define CURLOPT_FTP_SSL CURLOPT_USE_SSL + +/* The following were added earlier */ + +#define CURLOPT_SSLCERTPASSWD CURLOPT_KEYPASSWD +#define CURLOPT_KRB4LEVEL CURLOPT_KRBLEVEL + +#else +/* This is set if CURL_NO_OLDIES is defined at compile-time */ +#undef CURLOPT_DNS_USE_GLOBAL_CACHE /* soon obsolete */ +#endif + + + /* Below here follows defines for the CURLOPT_IPRESOLVE option. If a host + name resolves addresses using more than one IP protocol version, this + option might be handy to force libcurl to use a specific IP version. */ +#define CURL_IPRESOLVE_WHATEVER 0 /* default, resolves addresses to all IP + versions that your system allows */ +#define CURL_IPRESOLVE_V4 1 /* resolve to ipv4 addresses */ +#define CURL_IPRESOLVE_V6 2 /* resolve to ipv6 addresses */ + + /* three convenient "aliases" that follow the name scheme better */ +#define CURLOPT_WRITEDATA CURLOPT_FILE +#define CURLOPT_READDATA CURLOPT_INFILE +#define CURLOPT_HEADERDATA CURLOPT_WRITEHEADER +#define CURLOPT_RTSPHEADER CURLOPT_HTTPHEADER + + /* These enums are for use with the CURLOPT_HTTP_VERSION option. */ +enum { + CURL_HTTP_VERSION_NONE, /* setting this means we don't care, and that we'd + like the library to choose the best possible + for us! */ + CURL_HTTP_VERSION_1_0, /* please use HTTP 1.0 in the request */ + CURL_HTTP_VERSION_1_1, /* please use HTTP 1.1 in the request */ + + CURL_HTTP_VERSION_LAST /* *ILLEGAL* http version */ +}; + +/* + * Public API enums for RTSP requests + */ +enum { + CURL_RTSPREQ_NONE, /* first in list */ + CURL_RTSPREQ_OPTIONS, + CURL_RTSPREQ_DESCRIBE, + CURL_RTSPREQ_ANNOUNCE, + CURL_RTSPREQ_SETUP, + CURL_RTSPREQ_PLAY, + CURL_RTSPREQ_PAUSE, + CURL_RTSPREQ_TEARDOWN, + CURL_RTSPREQ_GET_PARAMETER, + CURL_RTSPREQ_SET_PARAMETER, + CURL_RTSPREQ_RECORD, + CURL_RTSPREQ_RECEIVE, + CURL_RTSPREQ_LAST /* last in list */ +}; + + /* These enums are for use with the CURLOPT_NETRC option. */ +enum CURL_NETRC_OPTION { + CURL_NETRC_IGNORED, /* The .netrc will never be read. + * This is the default. */ + CURL_NETRC_OPTIONAL, /* A user:password in the URL will be preferred + * to one in the .netrc. */ + CURL_NETRC_REQUIRED, /* A user:password in the URL will be ignored. + * Unless one is set programmatically, the .netrc + * will be queried. */ + CURL_NETRC_LAST +}; + +enum { + CURL_SSLVERSION_DEFAULT, + CURL_SSLVERSION_TLSv1, + CURL_SSLVERSION_SSLv2, + CURL_SSLVERSION_SSLv3, + + CURL_SSLVERSION_LAST /* never use, keep last */ +}; + +enum CURL_TLSAUTH { + CURL_TLSAUTH_NONE, + CURL_TLSAUTH_SRP, + CURL_TLSAUTH_LAST /* never use, keep last */ +}; + +/* symbols to use with CURLOPT_POSTREDIR. + CURL_REDIR_POST_301 and CURL_REDIR_POST_302 can be bitwise ORed so that + CURL_REDIR_POST_301 | CURL_REDIR_POST_302 == CURL_REDIR_POST_ALL */ + +#define CURL_REDIR_GET_ALL 0 +#define CURL_REDIR_POST_301 1 +#define CURL_REDIR_POST_302 2 +#define CURL_REDIR_POST_ALL (CURL_REDIR_POST_301|CURL_REDIR_POST_302) + +typedef enum { + CURL_TIMECOND_NONE, + + CURL_TIMECOND_IFMODSINCE, + CURL_TIMECOND_IFUNMODSINCE, + CURL_TIMECOND_LASTMOD, + + CURL_TIMECOND_LAST +} curl_TimeCond; + + +/* curl_strequal() and curl_strnequal() are subject for removal in a future + libcurl, see lib/README.curlx for details */ +CURL_EXTERN int (curl_strequal)(const char *s1, const char *s2); +CURL_EXTERN int (curl_strnequal)(const char *s1, const char *s2, size_t n); + +/* name is uppercase CURLFORM_ */ +#ifdef CFINIT +#undef CFINIT +#endif + +#ifdef CURL_ISOCPP +#define CFINIT(name) CURLFORM_ ## name +#else +/* The macro "##" is ISO C, we assume pre-ISO C doesn't support it. */ +#define CFINIT(name) CURLFORM_/**/name +#endif + +typedef enum { + CFINIT(NOTHING), /********* the first one is unused ************/ + + /* */ + CFINIT(COPYNAME), + CFINIT(PTRNAME), + CFINIT(NAMELENGTH), + CFINIT(COPYCONTENTS), + CFINIT(PTRCONTENTS), + CFINIT(CONTENTSLENGTH), + CFINIT(FILECONTENT), + CFINIT(ARRAY), + CFINIT(OBSOLETE), + CFINIT(FILE), + + CFINIT(BUFFER), + CFINIT(BUFFERPTR), + CFINIT(BUFFERLENGTH), + + CFINIT(CONTENTTYPE), + CFINIT(CONTENTHEADER), + CFINIT(FILENAME), + CFINIT(END), + CFINIT(OBSOLETE2), + + CFINIT(STREAM), + + CURLFORM_LASTENTRY /* the last unused */ +} CURLformoption; + +#undef CFINIT /* done */ + +/* structure to be used as parameter for CURLFORM_ARRAY */ +struct curl_forms { + CURLformoption option; + const char *value; +}; + +/* use this for multipart formpost building */ +/* Returns code for curl_formadd() + * + * Returns: + * CURL_FORMADD_OK on success + * CURL_FORMADD_MEMORY if the FormInfo allocation fails + * CURL_FORMADD_OPTION_TWICE if one option is given twice for one Form + * CURL_FORMADD_NULL if a null pointer was given for a char + * CURL_FORMADD_MEMORY if the allocation of a FormInfo struct failed + * CURL_FORMADD_UNKNOWN_OPTION if an unknown option was used + * CURL_FORMADD_INCOMPLETE if the some FormInfo is not complete (or error) + * CURL_FORMADD_MEMORY if a curl_httppost struct cannot be allocated + * CURL_FORMADD_MEMORY if some allocation for string copying failed. + * CURL_FORMADD_ILLEGAL_ARRAY if an illegal option is used in an array + * + ***************************************************************************/ +typedef enum { + CURL_FORMADD_OK, /* first, no error */ + + CURL_FORMADD_MEMORY, + CURL_FORMADD_OPTION_TWICE, + CURL_FORMADD_NULL, + CURL_FORMADD_UNKNOWN_OPTION, + CURL_FORMADD_INCOMPLETE, + CURL_FORMADD_ILLEGAL_ARRAY, + CURL_FORMADD_DISABLED, /* libcurl was built with this disabled */ + + CURL_FORMADD_LAST /* last */ +} CURLFORMcode; + +/* + * NAME curl_formadd() + * + * DESCRIPTION + * + * Pretty advanced function for building multi-part formposts. Each invoke + * adds one part that together construct a full post. Then use + * CURLOPT_HTTPPOST to send it off to libcurl. + */ +CURL_EXTERN CURLFORMcode curl_formadd(struct curl_httppost **httppost, + struct curl_httppost **last_post, + ...); + +/* + * callback function for curl_formget() + * The void *arg pointer will be the one passed as second argument to + * curl_formget(). + * The character buffer passed to it must not be freed. + * Should return the buffer length passed to it as the argument "len" on + * success. + */ +typedef size_t (*curl_formget_callback)(void *arg, const char *buf, size_t len); + +/* + * NAME curl_formget() + * + * DESCRIPTION + * + * Serialize a curl_httppost struct built with curl_formadd(). + * Accepts a void pointer as second argument which will be passed to + * the curl_formget_callback function. + * Returns 0 on success. + */ +CURL_EXTERN int curl_formget(struct curl_httppost *form, void *arg, + curl_formget_callback append); +/* + * NAME curl_formfree() + * + * DESCRIPTION + * + * Free a multipart formpost previously built with curl_formadd(). + */ +CURL_EXTERN void curl_formfree(struct curl_httppost *form); + +/* + * NAME curl_getenv() + * + * DESCRIPTION + * + * Returns a malloc()'ed string that MUST be curl_free()ed after usage is + * complete. DEPRECATED - see lib/README.curlx + */ +CURL_EXTERN char *curl_getenv(const char *variable); + +/* + * NAME curl_version() + * + * DESCRIPTION + * + * Returns a static ascii string of the libcurl version. + */ +CURL_EXTERN char *curl_version(void); + +/* + * NAME curl_easy_escape() + * + * DESCRIPTION + * + * Escapes URL strings (converts all letters consider illegal in URLs to their + * %XX versions). This function returns a new allocated string or NULL if an + * error occurred. + */ +CURL_EXTERN char *curl_easy_escape(CURL *handle, + const char *string, + int length); + +/* the previous version: */ +CURL_EXTERN char *curl_escape(const char *string, + int length); + + +/* + * NAME curl_easy_unescape() + * + * DESCRIPTION + * + * Unescapes URL encoding in strings (converts all %XX codes to their 8bit + * versions). This function returns a new allocated string or NULL if an error + * occurred. + * Conversion Note: On non-ASCII platforms the ASCII %XX codes are + * converted into the host encoding. + */ +CURL_EXTERN char *curl_easy_unescape(CURL *handle, + const char *string, + int length, + int *outlength); + +/* the previous version */ +CURL_EXTERN char *curl_unescape(const char *string, + int length); + +/* + * NAME curl_free() + * + * DESCRIPTION + * + * Provided for de-allocation in the same translation unit that did the + * allocation. Added in libcurl 7.10 + */ +CURL_EXTERN void curl_free(void *p); + +/* + * NAME curl_global_init() + * + * DESCRIPTION + * + * curl_global_init() should be invoked exactly once for each application that + * uses libcurl and before any call of other libcurl functions. + * + * This function is not thread-safe! + */ +CURL_EXTERN CURLcode curl_global_init(long flags); + +/* + * NAME curl_global_init_mem() + * + * DESCRIPTION + * + * curl_global_init() or curl_global_init_mem() should be invoked exactly once + * for each application that uses libcurl. This function can be used to + * initialize libcurl and set user defined memory management callback + * functions. Users can implement memory management routines to check for + * memory leaks, check for mis-use of the curl library etc. User registered + * callback routines with be invoked by this library instead of the system + * memory management routines like malloc, free etc. + */ +CURL_EXTERN CURLcode curl_global_init_mem(long flags, + curl_malloc_callback m, + curl_free_callback f, + curl_realloc_callback r, + curl_strdup_callback s, + curl_calloc_callback c); + +/* + * NAME curl_global_cleanup() + * + * DESCRIPTION + * + * curl_global_cleanup() should be invoked exactly once for each application + * that uses libcurl + */ +CURL_EXTERN void curl_global_cleanup(void); + +/* linked-list structure for the CURLOPT_QUOTE option (and other) */ +struct curl_slist { + char *data; + struct curl_slist *next; +}; + +/* + * NAME curl_slist_append() + * + * DESCRIPTION + * + * Appends a string to a linked list. If no list exists, it will be created + * first. Returns the new list, after appending. + */ +CURL_EXTERN struct curl_slist *curl_slist_append(struct curl_slist *, + const char *); + +/* + * NAME curl_slist_free_all() + * + * DESCRIPTION + * + * free a previously built curl_slist. + */ +CURL_EXTERN void curl_slist_free_all(struct curl_slist *); + +/* + * NAME curl_getdate() + * + * DESCRIPTION + * + * Returns the time, in seconds since 1 Jan 1970 of the time string given in + * the first argument. The time argument in the second parameter is unused + * and should be set to NULL. + */ +CURL_EXTERN time_t curl_getdate(const char *p, const time_t *unused); + +/* info about the certificate chain, only for OpenSSL builds. Asked + for with CURLOPT_CERTINFO / CURLINFO_CERTINFO */ +struct curl_certinfo { + int num_of_certs; /* number of certificates with information */ + struct curl_slist **certinfo; /* for each index in this array, there's a + linked list with textual information in the + format "name: value" */ +}; + +#define CURLINFO_STRING 0x100000 +#define CURLINFO_LONG 0x200000 +#define CURLINFO_DOUBLE 0x300000 +#define CURLINFO_SLIST 0x400000 +#define CURLINFO_MASK 0x0fffff +#define CURLINFO_TYPEMASK 0xf00000 + +typedef enum { + CURLINFO_NONE, /* first, never use this */ + CURLINFO_EFFECTIVE_URL = CURLINFO_STRING + 1, + CURLINFO_RESPONSE_CODE = CURLINFO_LONG + 2, + CURLINFO_TOTAL_TIME = CURLINFO_DOUBLE + 3, + CURLINFO_NAMELOOKUP_TIME = CURLINFO_DOUBLE + 4, + CURLINFO_CONNECT_TIME = CURLINFO_DOUBLE + 5, + CURLINFO_PRETRANSFER_TIME = CURLINFO_DOUBLE + 6, + CURLINFO_SIZE_UPLOAD = CURLINFO_DOUBLE + 7, + CURLINFO_SIZE_DOWNLOAD = CURLINFO_DOUBLE + 8, + CURLINFO_SPEED_DOWNLOAD = CURLINFO_DOUBLE + 9, + CURLINFO_SPEED_UPLOAD = CURLINFO_DOUBLE + 10, + CURLINFO_HEADER_SIZE = CURLINFO_LONG + 11, + CURLINFO_REQUEST_SIZE = CURLINFO_LONG + 12, + CURLINFO_SSL_VERIFYRESULT = CURLINFO_LONG + 13, + CURLINFO_FILETIME = CURLINFO_LONG + 14, + CURLINFO_CONTENT_LENGTH_DOWNLOAD = CURLINFO_DOUBLE + 15, + CURLINFO_CONTENT_LENGTH_UPLOAD = CURLINFO_DOUBLE + 16, + CURLINFO_STARTTRANSFER_TIME = CURLINFO_DOUBLE + 17, + CURLINFO_CONTENT_TYPE = CURLINFO_STRING + 18, + CURLINFO_REDIRECT_TIME = CURLINFO_DOUBLE + 19, + CURLINFO_REDIRECT_COUNT = CURLINFO_LONG + 20, + CURLINFO_PRIVATE = CURLINFO_STRING + 21, + CURLINFO_HTTP_CONNECTCODE = CURLINFO_LONG + 22, + CURLINFO_HTTPAUTH_AVAIL = CURLINFO_LONG + 23, + CURLINFO_PROXYAUTH_AVAIL = CURLINFO_LONG + 24, + CURLINFO_OS_ERRNO = CURLINFO_LONG + 25, + CURLINFO_NUM_CONNECTS = CURLINFO_LONG + 26, + CURLINFO_SSL_ENGINES = CURLINFO_SLIST + 27, + CURLINFO_COOKIELIST = CURLINFO_SLIST + 28, + CURLINFO_LASTSOCKET = CURLINFO_LONG + 29, + CURLINFO_FTP_ENTRY_PATH = CURLINFO_STRING + 30, + CURLINFO_REDIRECT_URL = CURLINFO_STRING + 31, + CURLINFO_PRIMARY_IP = CURLINFO_STRING + 32, + CURLINFO_APPCONNECT_TIME = CURLINFO_DOUBLE + 33, + CURLINFO_CERTINFO = CURLINFO_SLIST + 34, + CURLINFO_CONDITION_UNMET = CURLINFO_LONG + 35, + CURLINFO_RTSP_SESSION_ID = CURLINFO_STRING + 36, + CURLINFO_RTSP_CLIENT_CSEQ = CURLINFO_LONG + 37, + CURLINFO_RTSP_SERVER_CSEQ = CURLINFO_LONG + 38, + CURLINFO_RTSP_CSEQ_RECV = CURLINFO_LONG + 39, + CURLINFO_PRIMARY_PORT = CURLINFO_LONG + 40, + CURLINFO_LOCAL_IP = CURLINFO_STRING + 41, + CURLINFO_LOCAL_PORT = CURLINFO_LONG + 42, + /* Fill in new entries below here! */ + + CURLINFO_LASTONE = 42 +} CURLINFO; + +/* CURLINFO_RESPONSE_CODE is the new name for the option previously known as + CURLINFO_HTTP_CODE */ +#define CURLINFO_HTTP_CODE CURLINFO_RESPONSE_CODE + +typedef enum { + CURLCLOSEPOLICY_NONE, /* first, never use this */ + + CURLCLOSEPOLICY_OLDEST, + CURLCLOSEPOLICY_LEAST_RECENTLY_USED, + CURLCLOSEPOLICY_LEAST_TRAFFIC, + CURLCLOSEPOLICY_SLOWEST, + CURLCLOSEPOLICY_CALLBACK, + + CURLCLOSEPOLICY_LAST /* last, never use this */ +} curl_closepolicy; + +#define CURL_GLOBAL_SSL (1<<0) +#define CURL_GLOBAL_WIN32 (1<<1) +#define CURL_GLOBAL_ALL (CURL_GLOBAL_SSL|CURL_GLOBAL_WIN32) +#define CURL_GLOBAL_NOTHING 0 +#define CURL_GLOBAL_DEFAULT CURL_GLOBAL_ALL + + +/***************************************************************************** + * Setup defines, protos etc for the sharing stuff. + */ + +/* Different data locks for a single share */ +typedef enum { + CURL_LOCK_DATA_NONE = 0, + /* CURL_LOCK_DATA_SHARE is used internally to say that + * the locking is just made to change the internal state of the share + * itself. + */ + CURL_LOCK_DATA_SHARE, + CURL_LOCK_DATA_COOKIE, + CURL_LOCK_DATA_DNS, + CURL_LOCK_DATA_SSL_SESSION, + CURL_LOCK_DATA_CONNECT, + CURL_LOCK_DATA_LAST +} curl_lock_data; + +/* Different lock access types */ +typedef enum { + CURL_LOCK_ACCESS_NONE = 0, /* unspecified action */ + CURL_LOCK_ACCESS_SHARED = 1, /* for read perhaps */ + CURL_LOCK_ACCESS_SINGLE = 2, /* for write perhaps */ + CURL_LOCK_ACCESS_LAST /* never use */ +} curl_lock_access; + +typedef void (*curl_lock_function)(CURL *handle, + curl_lock_data data, + curl_lock_access locktype, + void *userptr); +typedef void (*curl_unlock_function)(CURL *handle, + curl_lock_data data, + void *userptr); + +typedef void CURLSH; + +typedef enum { + CURLSHE_OK, /* all is fine */ + CURLSHE_BAD_OPTION, /* 1 */ + CURLSHE_IN_USE, /* 2 */ + CURLSHE_INVALID, /* 3 */ + CURLSHE_NOMEM, /* out of memory */ + CURLSHE_LAST /* never use */ +} CURLSHcode; + +typedef enum { + CURLSHOPT_NONE, /* don't use */ + CURLSHOPT_SHARE, /* specify a data type to share */ + CURLSHOPT_UNSHARE, /* specify which data type to stop sharing */ + CURLSHOPT_LOCKFUNC, /* pass in a 'curl_lock_function' pointer */ + CURLSHOPT_UNLOCKFUNC, /* pass in a 'curl_unlock_function' pointer */ + CURLSHOPT_USERDATA, /* pass in a user data pointer used in the lock/unlock + callback functions */ + CURLSHOPT_LAST /* never use */ +} CURLSHoption; + +CURL_EXTERN CURLSH *curl_share_init(void); +CURL_EXTERN CURLSHcode curl_share_setopt(CURLSH *, CURLSHoption option, ...); +CURL_EXTERN CURLSHcode curl_share_cleanup(CURLSH *); + +/**************************************************************************** + * Structures for querying information about the curl library at runtime. + */ + +typedef enum { + CURLVERSION_FIRST, + CURLVERSION_SECOND, + CURLVERSION_THIRD, + CURLVERSION_FOURTH, + CURLVERSION_LAST /* never actually use this */ +} CURLversion; + +/* The 'CURLVERSION_NOW' is the symbolic name meant to be used by + basically all programs ever that want to get version information. It is + meant to be a built-in version number for what kind of struct the caller + expects. If the struct ever changes, we redefine the NOW to another enum + from above. */ +#define CURLVERSION_NOW CURLVERSION_FOURTH + +typedef struct { + CURLversion age; /* age of the returned struct */ + const char *version; /* LIBCURL_VERSION */ + unsigned int version_num; /* LIBCURL_VERSION_NUM */ + const char *host; /* OS/host/cpu/machine when configured */ + int features; /* bitmask, see defines below */ + const char *ssl_version; /* human readable string */ + long ssl_version_num; /* not used anymore, always 0 */ + const char *libz_version; /* human readable string */ + /* protocols is terminated by an entry with a NULL protoname */ + const char * const *protocols; + + /* The fields below this were added in CURLVERSION_SECOND */ + const char *ares; + int ares_num; + + /* This field was added in CURLVERSION_THIRD */ + const char *libidn; + + /* These field were added in CURLVERSION_FOURTH */ + + /* Same as '_libiconv_version' if built with HAVE_ICONV */ + int iconv_ver_num; + + const char *libssh_version; /* human readable string */ + +} curl_version_info_data; + +#define CURL_VERSION_IPV6 (1<<0) /* IPv6-enabled */ +#define CURL_VERSION_KERBEROS4 (1<<1) /* kerberos auth is supported */ +#define CURL_VERSION_SSL (1<<2) /* SSL options are present */ +#define CURL_VERSION_LIBZ (1<<3) /* libz features are present */ +#define CURL_VERSION_NTLM (1<<4) /* NTLM auth is supported */ +#define CURL_VERSION_GSSNEGOTIATE (1<<5) /* Negotiate auth support */ +#define CURL_VERSION_DEBUG (1<<6) /* built with debug capabilities */ +#define CURL_VERSION_ASYNCHDNS (1<<7) /* asynchronous dns resolves */ +#define CURL_VERSION_SPNEGO (1<<8) /* SPNEGO auth */ +#define CURL_VERSION_LARGEFILE (1<<9) /* supports files bigger than 2GB */ +#define CURL_VERSION_IDN (1<<10) /* International Domain Names support */ +#define CURL_VERSION_SSPI (1<<11) /* SSPI is supported */ +#define CURL_VERSION_CONV (1<<12) /* character conversions supported */ +#define CURL_VERSION_CURLDEBUG (1<<13) /* debug memory tracking supported */ +#define CURL_VERSION_TLSAUTH_SRP (1<<14) /* TLS-SRP auth is supported */ + +/* + * NAME curl_version_info() + * + * DESCRIPTION + * + * This function returns a pointer to a static copy of the version info + * struct. See above. + */ +CURL_EXTERN curl_version_info_data *curl_version_info(CURLversion); + +/* + * NAME curl_easy_strerror() + * + * DESCRIPTION + * + * The curl_easy_strerror function may be used to turn a CURLcode value + * into the equivalent human readable error string. This is useful + * for printing meaningful error messages. + */ +CURL_EXTERN const char *curl_easy_strerror(CURLcode); + +/* + * NAME curl_share_strerror() + * + * DESCRIPTION + * + * The curl_share_strerror function may be used to turn a CURLSHcode value + * into the equivalent human readable error string. This is useful + * for printing meaningful error messages. + */ +CURL_EXTERN const char *curl_share_strerror(CURLSHcode); + +/* + * NAME curl_easy_pause() + * + * DESCRIPTION + * + * The curl_easy_pause function pauses or unpauses transfers. Select the new + * state by setting the bitmask, use the convenience defines below. + * + */ +CURL_EXTERN CURLcode curl_easy_pause(CURL *handle, int bitmask); + +#define CURLPAUSE_RECV (1<<0) +#define CURLPAUSE_RECV_CONT (0) + +#define CURLPAUSE_SEND (1<<2) +#define CURLPAUSE_SEND_CONT (0) + +#define CURLPAUSE_ALL (CURLPAUSE_RECV|CURLPAUSE_SEND) +#define CURLPAUSE_CONT (CURLPAUSE_RECV_CONT|CURLPAUSE_SEND_CONT) + +#ifdef __cplusplus +} +#endif + +/* unfortunately, the easy.h and multi.h include files need options and info + stuff before they can be included! */ +#include "easy.h" /* nothing in curl is fun without the easy stuff */ +#include "multi.h" + +/* the typechecker doesn't work in C++ (yet) */ +#if defined(__GNUC__) && defined(__GNUC_MINOR__) && \ + ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) && \ + !defined(__cplusplus) && !defined(CURL_DISABLE_TYPECHECK) +#include "typecheck-gcc.h" +#else +#if defined(__STDC__) && (__STDC__ >= 1) +/* This preprocessor magic that replaces a call with the exact same call is + only done to make sure application authors pass exactly three arguments + to these functions. */ +#define curl_easy_setopt(handle,opt,param) curl_easy_setopt(handle,opt,param) +#define curl_easy_getinfo(handle,info,arg) curl_easy_getinfo(handle,info,arg) +#define curl_share_setopt(share,opt,param) curl_share_setopt(share,opt,param) +#define curl_multi_setopt(handle,opt,param) curl_multi_setopt(handle,opt,param) +#endif /* __STDC__ >= 1 */ +#endif /* gcc >= 4.3 && !__cplusplus */ + +#endif /* __CURL_CURL_H */ diff --git a/libs/curl/include/curl/curlbuild.h b/libs/curl/include/curl/curlbuild.h new file mode 100644 index 000000000..0f5311fba --- /dev/null +++ b/libs/curl/include/curl/curlbuild.h @@ -0,0 +1,191 @@ +/* include/curl/curlbuild.h. Generated from curlbuild.h.in by configure. */ +#ifndef __CURL_CURLBUILD_H +#define __CURL_CURLBUILD_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2009, Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at http://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ + +/* ================================================================ */ +/* NOTES FOR CONFIGURE CAPABLE SYSTEMS */ +/* ================================================================ */ + +/* + * NOTE 1: + * ------- + * + * Nothing in this file is intended to be modified or adjusted by the + * curl library user nor by the curl library builder. + * + * If you think that something actually needs to be changed, adjusted + * or fixed in this file, then, report it on the libcurl development + * mailing list: http://cool.haxx.se/mailman/listinfo/curl-library/ + * + * This header file shall only export symbols which are 'curl' or 'CURL' + * prefixed, otherwise public name space would be polluted. + * + * NOTE 2: + * ------- + * + * Right now you might be staring at file include/curl/curlbuild.h.in or + * at file include/curl/curlbuild.h, this is due to the following reason: + * + * On systems capable of running the configure script, the configure process + * will overwrite the distributed include/curl/curlbuild.h file with one that + * is suitable and specific to the library being configured and built, which + * is generated from the include/curl/curlbuild.h.in template file. + * + */ + +/* ================================================================ */ +/* DEFINITION OF THESE SYMBOLS SHALL NOT TAKE PLACE ANYWHERE ELSE */ +/* ================================================================ */ + +#ifdef CURL_SIZEOF_LONG +# error "CURL_SIZEOF_LONG shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_SIZEOF_LONG_already_defined +#endif + +#ifdef CURL_TYPEOF_CURL_SOCKLEN_T +# error "CURL_TYPEOF_CURL_SOCKLEN_T shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_TYPEOF_CURL_SOCKLEN_T_already_defined +#endif + +#ifdef CURL_SIZEOF_CURL_SOCKLEN_T +# error "CURL_SIZEOF_CURL_SOCKLEN_T shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_SIZEOF_CURL_SOCKLEN_T_already_defined +#endif + +#ifdef CURL_TYPEOF_CURL_OFF_T +# error "CURL_TYPEOF_CURL_OFF_T shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_TYPEOF_CURL_OFF_T_already_defined +#endif + +#ifdef CURL_FORMAT_CURL_OFF_T +# error "CURL_FORMAT_CURL_OFF_T shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_FORMAT_CURL_OFF_T_already_defined +#endif + +#ifdef CURL_FORMAT_CURL_OFF_TU +# error "CURL_FORMAT_CURL_OFF_TU shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_FORMAT_CURL_OFF_TU_already_defined +#endif + +#ifdef CURL_FORMAT_OFF_T +# error "CURL_FORMAT_OFF_T shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_FORMAT_OFF_T_already_defined +#endif + +#ifdef CURL_SIZEOF_CURL_OFF_T +# error "CURL_SIZEOF_CURL_OFF_T shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_SIZEOF_CURL_OFF_T_already_defined +#endif + +#ifdef CURL_SUFFIX_CURL_OFF_T +# error "CURL_SUFFIX_CURL_OFF_T shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_SUFFIX_CURL_OFF_T_already_defined +#endif + +#ifdef CURL_SUFFIX_CURL_OFF_TU +# error "CURL_SUFFIX_CURL_OFF_TU shall not be defined except in curlbuild.h" + Error Compilation_aborted_CURL_SUFFIX_CURL_OFF_TU_already_defined +#endif + +/* ================================================================ */ +/* EXTERNAL INTERFACE SETTINGS FOR CONFIGURE CAPABLE SYSTEMS ONLY */ +/* ================================================================ */ + +/* Configure process defines this to 1 when it finds out that system */ +/* header file ws2tcpip.h must be included by the external interface. */ +#define CURL_PULL_WS2TCPIP_H 1 +#ifdef CURL_PULL_WS2TCPIP_H +# ifndef WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN 1 +# endif +# include +# include +# include +#endif + +/* Configure process defines this to 1 when it finds out that system */ +/* header file sys/types.h must be included by the external interface. */ +#define CURL_PULL_SYS_TYPES_H 1 +#ifdef CURL_PULL_SYS_TYPES_H +# include +#endif + +/* Configure process defines this to 1 when it finds out that system */ +/* header file stdint.h must be included by the external interface. */ +#define CURL_PULL_STDINT_H 1 +#ifdef CURL_PULL_STDINT_H +# include +#endif + +/* Configure process defines this to 1 when it finds out that system */ +/* header file inttypes.h must be included by the external interface. */ +#define CURL_PULL_INTTYPES_H 1 +#ifdef CURL_PULL_INTTYPES_H +# include +#endif + +/* Configure process defines this to 1 when it finds out that system */ +/* header file sys/socket.h must be included by the external interface. */ +/* #undef CURL_PULL_SYS_SOCKET_H */ +#ifdef CURL_PULL_SYS_SOCKET_H +# include +#endif + +/* The size of `long', as computed by sizeof. */ +#define CURL_SIZEOF_LONG 4 + +/* Integral data type used for curl_socklen_t. */ +#define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t + +/* The size of `curl_socklen_t', as computed by sizeof. */ +#define CURL_SIZEOF_CURL_SOCKLEN_T 4 + +/* Data type definition of curl_socklen_t. */ +typedef CURL_TYPEOF_CURL_SOCKLEN_T curl_socklen_t; + +/* Signed integral data type used for curl_off_t. */ +#define CURL_TYPEOF_CURL_OFF_T int64_t + +/* Data type definition of curl_off_t. */ +typedef CURL_TYPEOF_CURL_OFF_T curl_off_t; + +/* curl_off_t formatting string directive without "%" conversion specifier. */ +#define CURL_FORMAT_CURL_OFF_T "I64d" + +/* unsigned curl_off_t formatting string without "%" conversion specifier. */ +#define CURL_FORMAT_CURL_OFF_TU "I64u" + +/* curl_off_t formatting string directive with "%" conversion specifier. */ +#define CURL_FORMAT_OFF_T "%I64d" + +/* The size of `curl_off_t', as computed by sizeof. */ +#define CURL_SIZEOF_CURL_OFF_T 8 + +/* curl_off_t constant suffix. */ +#define CURL_SUFFIX_CURL_OFF_T LL + +/* unsigned curl_off_t constant suffix. */ +#define CURL_SUFFIX_CURL_OFF_TU ULL + +#endif /* __CURL_CURLBUILD_H */ diff --git a/libs/curl/include/curl/curlrules.h b/libs/curl/include/curl/curlrules.h new file mode 100644 index 000000000..cbc12fdd2 --- /dev/null +++ b/libs/curl/include/curl/curlrules.h @@ -0,0 +1,261 @@ +#ifndef __CURL_CURLRULES_H +#define __CURL_CURLRULES_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2011, Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at http://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ + +/* ================================================================ */ +/* COMPILE TIME SANITY CHECKS */ +/* ================================================================ */ + +/* + * NOTE 1: + * ------- + * + * All checks done in this file are intentionally placed in a public + * header file which is pulled by curl/curl.h when an application is + * being built using an already built libcurl library. Additionally + * this file is also included and used when building the library. + * + * If compilation fails on this file it is certainly sure that the + * problem is elsewhere. It could be a problem in the curlbuild.h + * header file, or simply that you are using different compilation + * settings than those used to build the library. + * + * Nothing in this file is intended to be modified or adjusted by the + * curl library user nor by the curl library builder. + * + * Do not deactivate any check, these are done to make sure that the + * library is properly built and used. + * + * You can find further help on the libcurl development mailing list: + * http://cool.haxx.se/mailman/listinfo/curl-library/ + * + * NOTE 2 + * ------ + * + * Some of the following compile time checks are based on the fact + * that the dimension of a constant array can not be a negative one. + * In this way if the compile time verification fails, the compilation + * will fail issuing an error. The error description wording is compiler + * dependent but it will be quite similar to one of the following: + * + * "negative subscript or subscript is too large" + * "array must have at least one element" + * "-1 is an illegal array size" + * "size of array is negative" + * + * If you are building an application which tries to use an already + * built libcurl library and you are getting this kind of errors on + * this file, it is a clear indication that there is a mismatch between + * how the library was built and how you are trying to use it for your + * application. Your already compiled or binary library provider is the + * only one who can give you the details you need to properly use it. + */ + +/* + * Verify that some macros are actually defined. + */ + +#ifndef CURL_SIZEOF_LONG +# error "CURL_SIZEOF_LONG definition is missing!" + Error Compilation_aborted_CURL_SIZEOF_LONG_is_missing +#endif + +#ifndef CURL_TYPEOF_CURL_SOCKLEN_T +# error "CURL_TYPEOF_CURL_SOCKLEN_T definition is missing!" + Error Compilation_aborted_CURL_TYPEOF_CURL_SOCKLEN_T_is_missing +#endif + +#ifndef CURL_SIZEOF_CURL_SOCKLEN_T +# error "CURL_SIZEOF_CURL_SOCKLEN_T definition is missing!" + Error Compilation_aborted_CURL_SIZEOF_CURL_SOCKLEN_T_is_missing +#endif + +#ifndef CURL_TYPEOF_CURL_OFF_T +# error "CURL_TYPEOF_CURL_OFF_T definition is missing!" + Error Compilation_aborted_CURL_TYPEOF_CURL_OFF_T_is_missing +#endif + +#ifndef CURL_FORMAT_CURL_OFF_T +# error "CURL_FORMAT_CURL_OFF_T definition is missing!" + Error Compilation_aborted_CURL_FORMAT_CURL_OFF_T_is_missing +#endif + +#ifndef CURL_FORMAT_CURL_OFF_TU +# error "CURL_FORMAT_CURL_OFF_TU definition is missing!" + Error Compilation_aborted_CURL_FORMAT_CURL_OFF_TU_is_missing +#endif + +#ifndef CURL_FORMAT_OFF_T +# error "CURL_FORMAT_OFF_T definition is missing!" + Error Compilation_aborted_CURL_FORMAT_OFF_T_is_missing +#endif + +#ifndef CURL_SIZEOF_CURL_OFF_T +# error "CURL_SIZEOF_CURL_OFF_T definition is missing!" + Error Compilation_aborted_CURL_SIZEOF_CURL_OFF_T_is_missing +#endif + +#ifndef CURL_SUFFIX_CURL_OFF_T +# error "CURL_SUFFIX_CURL_OFF_T definition is missing!" + Error Compilation_aborted_CURL_SUFFIX_CURL_OFF_T_is_missing +#endif + +#ifndef CURL_SUFFIX_CURL_OFF_TU +# error "CURL_SUFFIX_CURL_OFF_TU definition is missing!" + Error Compilation_aborted_CURL_SUFFIX_CURL_OFF_TU_is_missing +#endif + +/* + * Macros private to this header file. + */ + +#define CurlchkszEQ(t, s) sizeof(t) == s ? 1 : -1 + +#define CurlchkszGE(t1, t2) sizeof(t1) >= sizeof(t2) ? 1 : -1 + +/* + * Verify that the size previously defined and expected for long + * is the same as the one reported by sizeof() at compile time. + */ + +typedef char + __curl_rule_01__ + [CurlchkszEQ(long, CURL_SIZEOF_LONG)]; + +/* + * Verify that the size previously defined and expected for + * curl_off_t is actually the the same as the one reported + * by sizeof() at compile time. + */ + +typedef char + __curl_rule_02__ + [CurlchkszEQ(curl_off_t, CURL_SIZEOF_CURL_OFF_T)]; + +/* + * Verify at compile time that the size of curl_off_t as reported + * by sizeof() is greater or equal than the one reported for long + * for the current compilation. + */ + +typedef char + __curl_rule_03__ + [CurlchkszGE(curl_off_t, long)]; + +/* + * Verify that the size previously defined and expected for + * curl_socklen_t is actually the the same as the one reported + * by sizeof() at compile time. + */ + +typedef char + __curl_rule_04__ + [CurlchkszEQ(curl_socklen_t, CURL_SIZEOF_CURL_SOCKLEN_T)]; + +/* + * Verify at compile time that the size of curl_socklen_t as reported + * by sizeof() is greater or equal than the one reported for int for + * the current compilation. + */ + +typedef char + __curl_rule_05__ + [CurlchkszGE(curl_socklen_t, int)]; + +/* ================================================================ */ +/* EXTERNALLY AND INTERNALLY VISIBLE DEFINITIONS */ +/* ================================================================ */ + +/* + * CURL_ISOCPP and CURL_OFF_T_C definitions are done here in order to allow + * these to be visible and exported by the external libcurl interface API, + * while also making them visible to the library internals, simply including + * setup.h, without actually needing to include curl.h internally. + * If some day this section would grow big enough, all this should be moved + * to its own header file. + */ + +/* + * Figure out if we can use the ## preprocessor operator, which is supported + * by ISO/ANSI C and C++. Some compilers support it without setting __STDC__ + * or __cplusplus so we need to carefully check for them too. + */ + +#if defined(__STDC__) || defined(_MSC_VER) || defined(__cplusplus) || \ + defined(__HP_aCC) || defined(__BORLANDC__) || defined(__LCC__) || \ + defined(__POCC__) || defined(__SALFORDC__) || defined(__HIGHC__) || \ + defined(__ILEC400__) + /* This compiler is believed to have an ISO compatible preprocessor */ +#define CURL_ISOCPP +#else + /* This compiler is believed NOT to have an ISO compatible preprocessor */ +#undef CURL_ISOCPP +#endif + +/* + * Macros for minimum-width signed and unsigned curl_off_t integer constants. + */ + +#if defined(__BORLANDC__) && (__BORLANDC__ == 0x0551) +# define __CURL_OFF_T_C_HLPR2(x) x +# define __CURL_OFF_T_C_HLPR1(x) __CURL_OFF_T_C_HLPR2(x) +# define CURL_OFF_T_C(Val) __CURL_OFF_T_C_HLPR1(Val) ## \ + __CURL_OFF_T_C_HLPR1(CURL_SUFFIX_CURL_OFF_T) +# define CURL_OFF_TU_C(Val) __CURL_OFF_T_C_HLPR1(Val) ## \ + __CURL_OFF_T_C_HLPR1(CURL_SUFFIX_CURL_OFF_TU) +#else +# ifdef CURL_ISOCPP +# define __CURL_OFF_T_C_HLPR2(Val,Suffix) Val ## Suffix +# else +# define __CURL_OFF_T_C_HLPR2(Val,Suffix) Val/**/Suffix +# endif +# define __CURL_OFF_T_C_HLPR1(Val,Suffix) __CURL_OFF_T_C_HLPR2(Val,Suffix) +# define CURL_OFF_T_C(Val) __CURL_OFF_T_C_HLPR1(Val,CURL_SUFFIX_CURL_OFF_T) +# define CURL_OFF_TU_C(Val) __CURL_OFF_T_C_HLPR1(Val,CURL_SUFFIX_CURL_OFF_TU) +#endif + +/* + * Get rid of macros private to this header file. + */ + +#undef CurlchkszEQ +#undef CurlchkszGE + +/* + * Get rid of macros not intended to exist beyond this point. + */ + +#undef CURL_PULL_WS2TCPIP_H +#undef CURL_PULL_SYS_TYPES_H +#undef CURL_PULL_SYS_SOCKET_H +#undef CURL_PULL_STDINT_H +#undef CURL_PULL_INTTYPES_H + +#undef CURL_TYPEOF_CURL_SOCKLEN_T +#undef CURL_TYPEOF_CURL_OFF_T + +#ifdef CURL_NO_OLDIES +#undef CURL_FORMAT_OFF_T /* not required since 7.19.0 - obsoleted in 7.20.0 */ +#endif + +#endif /* __CURL_CURLRULES_H */ diff --git a/libs/curl/include/curl/curlver.h b/libs/curl/include/curl/curlver.h new file mode 100644 index 000000000..4db21857d --- /dev/null +++ b/libs/curl/include/curl/curlver.h @@ -0,0 +1,69 @@ +#ifndef __CURL_CURLVER_H +#define __CURL_CURLVER_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2011, Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at http://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ + +/* This header file contains nothing but libcurl version info, generated by + a script at release-time. This was made its own header file in 7.11.2 */ + +/* This is the global package copyright */ +#define LIBCURL_COPYRIGHT "1996 - 2011 Daniel Stenberg, ." + +/* This is the version number of the libcurl package from which this header + file origins: */ +#define LIBCURL_VERSION "7.21.6" + +/* The numeric version number is also available "in parts" by using these + defines: */ +#define LIBCURL_VERSION_MAJOR 7 +#define LIBCURL_VERSION_MINOR 21 +#define LIBCURL_VERSION_PATCH 6 + +/* This is the numeric version of the libcurl version number, meant for easier + parsing and comparions by programs. The LIBCURL_VERSION_NUM define will + always follow this syntax: + + 0xXXYYZZ + + Where XX, YY and ZZ are the main version, release and patch numbers in + hexadecimal (using 8 bits each). All three numbers are always represented + using two digits. 1.2 would appear as "0x010200" while version 9.11.7 + appears as "0x090b07". + + This 6-digit (24 bits) hexadecimal number does not show pre-release number, + and it is always a greater number in a more recent release. It makes + comparisons with greater than and less than work. +*/ +#define LIBCURL_VERSION_NUM 0x071506 + +/* + * This is the date and time when the full source package was created. The + * timestamp is not stored in git, as the timestamp is properly set in the + * tarballs by the maketgz script. + * + * The format of the date should follow this template: + * + * "Mon Feb 12 11:35:33 UTC 2007" + */ +#define LIBCURL_TIMESTAMP "Fri Apr 22 17:18:50 UTC 2011" + +#endif /* __CURL_CURLVER_H */ diff --git a/libs/curl/include/curl/easy.h b/libs/curl/include/curl/easy.h new file mode 100644 index 000000000..c1e3e7609 --- /dev/null +++ b/libs/curl/include/curl/easy.h @@ -0,0 +1,102 @@ +#ifndef __CURL_EASY_H +#define __CURL_EASY_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2008, Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at http://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ +#ifdef __cplusplus +extern "C" { +#endif + +CURL_EXTERN CURL *curl_easy_init(void); +CURL_EXTERN CURLcode curl_easy_setopt(CURL *curl, CURLoption option, ...); +CURL_EXTERN CURLcode curl_easy_perform(CURL *curl); +CURL_EXTERN void curl_easy_cleanup(CURL *curl); + +/* + * NAME curl_easy_getinfo() + * + * DESCRIPTION + * + * Request internal information from the curl session with this function. The + * third argument MUST be a pointer to a long, a pointer to a char * or a + * pointer to a double (as the documentation describes elsewhere). The data + * pointed to will be filled in accordingly and can be relied upon only if the + * function returns CURLE_OK. This function is intended to get used *AFTER* a + * performed transfer, all results from this function are undefined until the + * transfer is completed. + */ +CURL_EXTERN CURLcode curl_easy_getinfo(CURL *curl, CURLINFO info, ...); + + +/* + * NAME curl_easy_duphandle() + * + * DESCRIPTION + * + * Creates a new curl session handle with the same options set for the handle + * passed in. Duplicating a handle could only be a matter of cloning data and + * options, internal state info and things like persistent connections cannot + * be transferred. It is useful in multithreaded applications when you can run + * curl_easy_duphandle() for each new thread to avoid a series of identical + * curl_easy_setopt() invokes in every thread. + */ +CURL_EXTERN CURL* curl_easy_duphandle(CURL *curl); + +/* + * NAME curl_easy_reset() + * + * DESCRIPTION + * + * Re-initializes a CURL handle to the default values. This puts back the + * handle to the same state as it was in when it was just created. + * + * It does keep: live connections, the Session ID cache, the DNS cache and the + * cookies. + */ +CURL_EXTERN void curl_easy_reset(CURL *curl); + +/* + * NAME curl_easy_recv() + * + * DESCRIPTION + * + * Receives data from the connected socket. Use after successful + * curl_easy_perform() with CURLOPT_CONNECT_ONLY option. + */ +CURL_EXTERN CURLcode curl_easy_recv(CURL *curl, void *buffer, size_t buflen, + size_t *n); + +/* + * NAME curl_easy_send() + * + * DESCRIPTION + * + * Sends data over the connected socket. Use after successful + * curl_easy_perform() with CURLOPT_CONNECT_ONLY option. + */ +CURL_EXTERN CURLcode curl_easy_send(CURL *curl, const void *buffer, + size_t buflen, size_t *n); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libs/curl/include/curl/mprintf.h b/libs/curl/include/curl/mprintf.h new file mode 100644 index 000000000..de7dd2f3c --- /dev/null +++ b/libs/curl/include/curl/mprintf.h @@ -0,0 +1,81 @@ +#ifndef __CURL_MPRINTF_H +#define __CURL_MPRINTF_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2006, Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at http://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ + +#include +#include /* needed for FILE */ + +#include "curl.h" + +#ifdef __cplusplus +extern "C" { +#endif + +CURL_EXTERN int curl_mprintf(const char *format, ...); +CURL_EXTERN int curl_mfprintf(FILE *fd, const char *format, ...); +CURL_EXTERN int curl_msprintf(char *buffer, const char *format, ...); +CURL_EXTERN int curl_msnprintf(char *buffer, size_t maxlength, + const char *format, ...); +CURL_EXTERN int curl_mvprintf(const char *format, va_list args); +CURL_EXTERN int curl_mvfprintf(FILE *fd, const char *format, va_list args); +CURL_EXTERN int curl_mvsprintf(char *buffer, const char *format, va_list args); +CURL_EXTERN int curl_mvsnprintf(char *buffer, size_t maxlength, + const char *format, va_list args); +CURL_EXTERN char *curl_maprintf(const char *format, ...); +CURL_EXTERN char *curl_mvaprintf(const char *format, va_list args); + +#ifdef _MPRINTF_REPLACE +# undef printf +# undef fprintf +# undef sprintf +# undef vsprintf +# undef snprintf +# undef vprintf +# undef vfprintf +# undef vsnprintf +# undef aprintf +# undef vaprintf +# define printf curl_mprintf +# define fprintf curl_mfprintf +#ifdef CURLDEBUG +/* When built with CURLDEBUG we define away the sprintf() functions since we + don't want internal code to be using them */ +# define sprintf sprintf_was_used +# define vsprintf vsprintf_was_used +#else +# define sprintf curl_msprintf +# define vsprintf curl_mvsprintf +#endif +# define snprintf curl_msnprintf +# define vprintf curl_mvprintf +# define vfprintf curl_mvfprintf +# define vsnprintf curl_mvsnprintf +# define aprintf curl_maprintf +# define vaprintf curl_mvaprintf +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* __CURL_MPRINTF_H */ diff --git a/libs/curl/include/curl/multi.h b/libs/curl/include/curl/multi.h new file mode 100644 index 000000000..f96566669 --- /dev/null +++ b/libs/curl/include/curl/multi.h @@ -0,0 +1,345 @@ +#ifndef __CURL_MULTI_H +#define __CURL_MULTI_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2007, Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at http://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ +/* + This is an "external" header file. Don't give away any internals here! + + GOALS + + o Enable a "pull" interface. The application that uses libcurl decides where + and when to ask libcurl to get/send data. + + o Enable multiple simultaneous transfers in the same thread without making it + complicated for the application. + + o Enable the application to select() on its own file descriptors and curl's + file descriptors simultaneous easily. + +*/ + +/* + * This header file should not really need to include "curl.h" since curl.h + * itself includes this file and we expect user applications to do #include + * without the need for especially including multi.h. + * + * For some reason we added this include here at one point, and rather than to + * break existing (wrongly written) libcurl applications, we leave it as-is + * but with this warning attached. + */ +#include "curl.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void CURLM; + +typedef enum { + CURLM_CALL_MULTI_PERFORM = -1, /* please call curl_multi_perform() or + curl_multi_socket*() soon */ + CURLM_OK, + CURLM_BAD_HANDLE, /* the passed-in handle is not a valid CURLM handle */ + CURLM_BAD_EASY_HANDLE, /* an easy handle was not good/valid */ + CURLM_OUT_OF_MEMORY, /* if you ever get this, you're in deep sh*t */ + CURLM_INTERNAL_ERROR, /* this is a libcurl bug */ + CURLM_BAD_SOCKET, /* the passed in socket argument did not match */ + CURLM_UNKNOWN_OPTION, /* curl_multi_setopt() with unsupported option */ + CURLM_LAST +} CURLMcode; + +/* just to make code nicer when using curl_multi_socket() you can now check + for CURLM_CALL_MULTI_SOCKET too in the same style it works for + curl_multi_perform() and CURLM_CALL_MULTI_PERFORM */ +#define CURLM_CALL_MULTI_SOCKET CURLM_CALL_MULTI_PERFORM + +typedef enum { + CURLMSG_NONE, /* first, not used */ + CURLMSG_DONE, /* This easy handle has completed. 'result' contains + the CURLcode of the transfer */ + CURLMSG_LAST /* last, not used */ +} CURLMSG; + +struct CURLMsg { + CURLMSG msg; /* what this message means */ + CURL *easy_handle; /* the handle it concerns */ + union { + void *whatever; /* message-specific data */ + CURLcode result; /* return code for transfer */ + } data; +}; +typedef struct CURLMsg CURLMsg; + +/* + * Name: curl_multi_init() + * + * Desc: inititalize multi-style curl usage + * + * Returns: a new CURLM handle to use in all 'curl_multi' functions. + */ +CURL_EXTERN CURLM *curl_multi_init(void); + +/* + * Name: curl_multi_add_handle() + * + * Desc: add a standard curl handle to the multi stack + * + * Returns: CURLMcode type, general multi error code. + */ +CURL_EXTERN CURLMcode curl_multi_add_handle(CURLM *multi_handle, + CURL *curl_handle); + + /* + * Name: curl_multi_remove_handle() + * + * Desc: removes a curl handle from the multi stack again + * + * Returns: CURLMcode type, general multi error code. + */ +CURL_EXTERN CURLMcode curl_multi_remove_handle(CURLM *multi_handle, + CURL *curl_handle); + + /* + * Name: curl_multi_fdset() + * + * Desc: Ask curl for its fd_set sets. The app can use these to select() or + * poll() on. We want curl_multi_perform() called as soon as one of + * them are ready. + * + * Returns: CURLMcode type, general multi error code. + */ +CURL_EXTERN CURLMcode curl_multi_fdset(CURLM *multi_handle, + fd_set *read_fd_set, + fd_set *write_fd_set, + fd_set *exc_fd_set, + int *max_fd); + + /* + * Name: curl_multi_perform() + * + * Desc: When the app thinks there's data available for curl it calls this + * function to read/write whatever there is right now. This returns + * as soon as the reads and writes are done. This function does not + * require that there actually is data available for reading or that + * data can be written, it can be called just in case. It returns + * the number of handles that still transfer data in the second + * argument's integer-pointer. + * + * Returns: CURLMcode type, general multi error code. *NOTE* that this only + * returns errors etc regarding the whole multi stack. There might + * still have occurred problems on invidual transfers even when this + * returns OK. + */ +CURL_EXTERN CURLMcode curl_multi_perform(CURLM *multi_handle, + int *running_handles); + + /* + * Name: curl_multi_cleanup() + * + * Desc: Cleans up and removes a whole multi stack. It does not free or + * touch any individual easy handles in any way. We need to define + * in what state those handles will be if this function is called + * in the middle of a transfer. + * + * Returns: CURLMcode type, general multi error code. + */ +CURL_EXTERN CURLMcode curl_multi_cleanup(CURLM *multi_handle); + +/* + * Name: curl_multi_info_read() + * + * Desc: Ask the multi handle if there's any messages/informationals from + * the individual transfers. Messages include informationals such as + * error code from the transfer or just the fact that a transfer is + * completed. More details on these should be written down as well. + * + * Repeated calls to this function will return a new struct each + * time, until a special "end of msgs" struct is returned as a signal + * that there is no more to get at this point. + * + * The data the returned pointer points to will not survive calling + * curl_multi_cleanup(). + * + * The 'CURLMsg' struct is meant to be very simple and only contain + * very basic informations. If more involved information is wanted, + * we will provide the particular "transfer handle" in that struct + * and that should/could/would be used in subsequent + * curl_easy_getinfo() calls (or similar). The point being that we + * must never expose complex structs to applications, as then we'll + * undoubtably get backwards compatibility problems in the future. + * + * Returns: A pointer to a filled-in struct, or NULL if it failed or ran out + * of structs. It also writes the number of messages left in the + * queue (after this read) in the integer the second argument points + * to. + */ +CURL_EXTERN CURLMsg *curl_multi_info_read(CURLM *multi_handle, + int *msgs_in_queue); + +/* + * Name: curl_multi_strerror() + * + * Desc: The curl_multi_strerror function may be used to turn a CURLMcode + * value into the equivalent human readable error string. This is + * useful for printing meaningful error messages. + * + * Returns: A pointer to a zero-terminated error message. + */ +CURL_EXTERN const char *curl_multi_strerror(CURLMcode); + +/* + * Name: curl_multi_socket() and + * curl_multi_socket_all() + * + * Desc: An alternative version of curl_multi_perform() that allows the + * application to pass in one of the file descriptors that have been + * detected to have "action" on them and let libcurl perform. + * See man page for details. + */ +#define CURL_POLL_NONE 0 +#define CURL_POLL_IN 1 +#define CURL_POLL_OUT 2 +#define CURL_POLL_INOUT 3 +#define CURL_POLL_REMOVE 4 + +#define CURL_SOCKET_TIMEOUT CURL_SOCKET_BAD + +#define CURL_CSELECT_IN 0x01 +#define CURL_CSELECT_OUT 0x02 +#define CURL_CSELECT_ERR 0x04 + +typedef int (*curl_socket_callback)(CURL *easy, /* easy handle */ + curl_socket_t s, /* socket */ + int what, /* see above */ + void *userp, /* private callback + pointer */ + void *socketp); /* private socket + pointer */ +/* + * Name: curl_multi_timer_callback + * + * Desc: Called by libcurl whenever the library detects a change in the + * maximum number of milliseconds the app is allowed to wait before + * curl_multi_socket() or curl_multi_perform() must be called + * (to allow libcurl's timed events to take place). + * + * Returns: The callback should return zero. + */ +typedef int (*curl_multi_timer_callback)(CURLM *multi, /* multi handle */ + long timeout_ms, /* see above */ + void *userp); /* private callback + pointer */ + +CURL_EXTERN CURLMcode curl_multi_socket(CURLM *multi_handle, curl_socket_t s, + int *running_handles); + +CURL_EXTERN CURLMcode curl_multi_socket_action(CURLM *multi_handle, + curl_socket_t s, + int ev_bitmask, + int *running_handles); + +CURL_EXTERN CURLMcode curl_multi_socket_all(CURLM *multi_handle, + int *running_handles); + +#ifndef CURL_ALLOW_OLD_MULTI_SOCKET +/* This macro below was added in 7.16.3 to push users who recompile to use + the new curl_multi_socket_action() instead of the old curl_multi_socket() +*/ +#define curl_multi_socket(x,y,z) curl_multi_socket_action(x,y,0,z) +#endif + +/* + * Name: curl_multi_timeout() + * + * Desc: Returns the maximum number of milliseconds the app is allowed to + * wait before curl_multi_socket() or curl_multi_perform() must be + * called (to allow libcurl's timed events to take place). + * + * Returns: CURLM error code. + */ +CURL_EXTERN CURLMcode curl_multi_timeout(CURLM *multi_handle, + long *milliseconds); + +#undef CINIT /* re-using the same name as in curl.h */ + +#ifdef CURL_ISOCPP +#define CINIT(name,type,num) CURLMOPT_ ## name = CURLOPTTYPE_ ## type + num +#else +/* The macro "##" is ISO C, we assume pre-ISO C doesn't support it. */ +#define LONG CURLOPTTYPE_LONG +#define OBJECTPOINT CURLOPTTYPE_OBJECTPOINT +#define FUNCTIONPOINT CURLOPTTYPE_FUNCTIONPOINT +#define OFF_T CURLOPTTYPE_OFF_T +#define CINIT(name,type,number) CURLMOPT_/**/name = type + number +#endif + +typedef enum { + /* This is the socket callback function pointer */ + CINIT(SOCKETFUNCTION, FUNCTIONPOINT, 1), + + /* This is the argument passed to the socket callback */ + CINIT(SOCKETDATA, OBJECTPOINT, 2), + + /* set to 1 to enable pipelining for this multi handle */ + CINIT(PIPELINING, LONG, 3), + + /* This is the timer callback function pointer */ + CINIT(TIMERFUNCTION, FUNCTIONPOINT, 4), + + /* This is the argument passed to the timer callback */ + CINIT(TIMERDATA, OBJECTPOINT, 5), + + /* maximum number of entries in the connection cache */ + CINIT(MAXCONNECTS, LONG, 6), + + CURLMOPT_LASTENTRY /* the last unused */ +} CURLMoption; + + +/* + * Name: curl_multi_setopt() + * + * Desc: Sets options for the multi handle. + * + * Returns: CURLM error code. + */ +CURL_EXTERN CURLMcode curl_multi_setopt(CURLM *multi_handle, + CURLMoption option, ...); + + +/* + * Name: curl_multi_assign() + * + * Desc: This function sets an association in the multi handle between the + * given socket and a private pointer of the application. This is + * (only) useful for curl_multi_socket uses. + * + * Returns: CURLM error code. + */ +CURL_EXTERN CURLMcode curl_multi_assign(CURLM *multi_handle, + curl_socket_t sockfd, void *sockp); + +#ifdef __cplusplus +} /* end of extern "C" */ +#endif + +#endif diff --git a/libs/curl/include/curl/stdcheaders.h b/libs/curl/include/curl/stdcheaders.h new file mode 100644 index 000000000..ad82ef633 --- /dev/null +++ b/libs/curl/include/curl/stdcheaders.h @@ -0,0 +1,33 @@ +#ifndef __STDC_HEADERS_H +#define __STDC_HEADERS_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2010, Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at http://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ + +#include + +size_t fread (void *, size_t, size_t, FILE *); +size_t fwrite (const void *, size_t, size_t, FILE *); + +int strcasecmp(const char *, const char *); +int strncasecmp(const char *, const char *, size_t); + +#endif /* __STDC_HEADERS_H */ diff --git a/libs/curl/include/curl/typecheck-gcc.h b/libs/curl/include/curl/typecheck-gcc.h new file mode 100644 index 000000000..46f92d728 --- /dev/null +++ b/libs/curl/include/curl/typecheck-gcc.h @@ -0,0 +1,584 @@ +#ifndef __CURL_TYPECHECK_GCC_H +#define __CURL_TYPECHECK_GCC_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2011, Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at http://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ + +/* wraps curl_easy_setopt() with typechecking */ + +/* To add a new kind of warning, add an + * if(_curl_is_sometype_option(_curl_opt)) + * if(!_curl_is_sometype(value)) + * _curl_easy_setopt_err_sometype(); + * block and define _curl_is_sometype_option, _curl_is_sometype and + * _curl_easy_setopt_err_sometype below + * + * NOTE: We use two nested 'if' statements here instead of the && operator, in + * order to work around gcc bug #32061. It affects only gcc 4.3.x/4.4.x + * when compiling with -Wlogical-op. + * + * To add an option that uses the same type as an existing option, you'll just + * need to extend the appropriate _curl_*_option macro + */ +#define curl_easy_setopt(handle, option, value) \ +__extension__ ({ \ + __typeof__ (option) _curl_opt = option; \ + if (__builtin_constant_p(_curl_opt)) { \ + if (_curl_is_long_option(_curl_opt)) \ + if (!_curl_is_long(value)) \ + _curl_easy_setopt_err_long(); \ + if (_curl_is_off_t_option(_curl_opt)) \ + if (!_curl_is_off_t(value)) \ + _curl_easy_setopt_err_curl_off_t(); \ + if (_curl_is_string_option(_curl_opt)) \ + if (!_curl_is_string(value)) \ + _curl_easy_setopt_err_string(); \ + if (_curl_is_write_cb_option(_curl_opt)) \ + if (!_curl_is_write_cb(value)) \ + _curl_easy_setopt_err_write_callback(); \ + if ((_curl_opt) == CURLOPT_READFUNCTION) \ + if (!_curl_is_read_cb(value)) \ + _curl_easy_setopt_err_read_cb(); \ + if ((_curl_opt) == CURLOPT_IOCTLFUNCTION) \ + if (!_curl_is_ioctl_cb(value)) \ + _curl_easy_setopt_err_ioctl_cb(); \ + if ((_curl_opt) == CURLOPT_SOCKOPTFUNCTION) \ + if (!_curl_is_sockopt_cb(value)) \ + _curl_easy_setopt_err_sockopt_cb(); \ + if ((_curl_opt) == CURLOPT_OPENSOCKETFUNCTION) \ + if (!_curl_is_opensocket_cb(value)) \ + _curl_easy_setopt_err_opensocket_cb(); \ + if ((_curl_opt) == CURLOPT_PROGRESSFUNCTION) \ + if (!_curl_is_progress_cb(value)) \ + _curl_easy_setopt_err_progress_cb(); \ + if ((_curl_opt) == CURLOPT_DEBUGFUNCTION) \ + if (!_curl_is_debug_cb(value)) \ + _curl_easy_setopt_err_debug_cb(); \ + if ((_curl_opt) == CURLOPT_SSL_CTX_FUNCTION) \ + if (!_curl_is_ssl_ctx_cb(value)) \ + _curl_easy_setopt_err_ssl_ctx_cb(); \ + if (_curl_is_conv_cb_option(_curl_opt)) \ + if (!_curl_is_conv_cb(value)) \ + _curl_easy_setopt_err_conv_cb(); \ + if ((_curl_opt) == CURLOPT_SEEKFUNCTION) \ + if (!_curl_is_seek_cb(value)) \ + _curl_easy_setopt_err_seek_cb(); \ + if (_curl_is_cb_data_option(_curl_opt)) \ + if (!_curl_is_cb_data(value)) \ + _curl_easy_setopt_err_cb_data(); \ + if ((_curl_opt) == CURLOPT_ERRORBUFFER) \ + if (!_curl_is_error_buffer(value)) \ + _curl_easy_setopt_err_error_buffer(); \ + if ((_curl_opt) == CURLOPT_STDERR) \ + if (!_curl_is_FILE(value)) \ + _curl_easy_setopt_err_FILE(); \ + if (_curl_is_postfields_option(_curl_opt)) \ + if (!_curl_is_postfields(value)) \ + _curl_easy_setopt_err_postfields(); \ + if ((_curl_opt) == CURLOPT_HTTPPOST) \ + if (!_curl_is_arr((value), struct curl_httppost)) \ + _curl_easy_setopt_err_curl_httpost(); \ + if (_curl_is_slist_option(_curl_opt)) \ + if (!_curl_is_arr((value), struct curl_slist)) \ + _curl_easy_setopt_err_curl_slist(); \ + if ((_curl_opt) == CURLOPT_SHARE) \ + if (!_curl_is_ptr((value), CURLSH)) \ + _curl_easy_setopt_err_CURLSH(); \ + } \ + curl_easy_setopt(handle, _curl_opt, value); \ +}) + +/* wraps curl_easy_getinfo() with typechecking */ +/* FIXME: don't allow const pointers */ +#define curl_easy_getinfo(handle, info, arg) \ +__extension__ ({ \ + __typeof__ (info) _curl_info = info; \ + if (__builtin_constant_p(_curl_info)) { \ + if (_curl_is_string_info(_curl_info)) \ + if (!_curl_is_arr((arg), char *)) \ + _curl_easy_getinfo_err_string(); \ + if (_curl_is_long_info(_curl_info)) \ + if (!_curl_is_arr((arg), long)) \ + _curl_easy_getinfo_err_long(); \ + if (_curl_is_double_info(_curl_info)) \ + if (!_curl_is_arr((arg), double)) \ + _curl_easy_getinfo_err_double(); \ + if (_curl_is_slist_info(_curl_info)) \ + if (!_curl_is_arr((arg), struct curl_slist *)) \ + _curl_easy_getinfo_err_curl_slist(); \ + } \ + curl_easy_getinfo(handle, _curl_info, arg); \ +}) + +/* TODO: typechecking for curl_share_setopt() and curl_multi_setopt(), + * for now just make sure that the functions are called with three + * arguments + */ +#define curl_share_setopt(share,opt,param) curl_share_setopt(share,opt,param) +#define curl_multi_setopt(handle,opt,param) curl_multi_setopt(handle,opt,param) + + +/* the actual warnings, triggered by calling the _curl_easy_setopt_err* + * functions */ + +/* To define a new warning, use _CURL_WARNING(identifier, "message") */ +#define _CURL_WARNING(id, message) \ + static void __attribute__((warning(message))) __attribute__((unused)) \ + __attribute__((noinline)) id(void) { __asm__(""); } + +_CURL_WARNING(_curl_easy_setopt_err_long, + "curl_easy_setopt expects a long argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_curl_off_t, + "curl_easy_setopt expects a curl_off_t argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_string, + "curl_easy_setopt expects a string (char* or char[]) argument for this option" + ) +_CURL_WARNING(_curl_easy_setopt_err_write_callback, + "curl_easy_setopt expects a curl_write_callback argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_read_cb, + "curl_easy_setopt expects a curl_read_callback argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_ioctl_cb, + "curl_easy_setopt expects a curl_ioctl_callback argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_sockopt_cb, + "curl_easy_setopt expects a curl_sockopt_callback argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_opensocket_cb, + "curl_easy_setopt expects a curl_opensocket_callback argument for this option" + ) +_CURL_WARNING(_curl_easy_setopt_err_progress_cb, + "curl_easy_setopt expects a curl_progress_callback argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_debug_cb, + "curl_easy_setopt expects a curl_debug_callback argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_ssl_ctx_cb, + "curl_easy_setopt expects a curl_ssl_ctx_callback argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_conv_cb, + "curl_easy_setopt expects a curl_conv_callback argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_seek_cb, + "curl_easy_setopt expects a curl_seek_callback argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_cb_data, + "curl_easy_setopt expects a private data pointer as argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_error_buffer, + "curl_easy_setopt expects a char buffer of CURL_ERROR_SIZE as argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_FILE, + "curl_easy_setopt expects a FILE* argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_postfields, + "curl_easy_setopt expects a void* or char* argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_curl_httpost, + "curl_easy_setopt expects a struct curl_httppost* argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_curl_slist, + "curl_easy_setopt expects a struct curl_slist* argument for this option") +_CURL_WARNING(_curl_easy_setopt_err_CURLSH, + "curl_easy_setopt expects a CURLSH* argument for this option") + +_CURL_WARNING(_curl_easy_getinfo_err_string, + "curl_easy_getinfo expects a pointer to char * for this info") +_CURL_WARNING(_curl_easy_getinfo_err_long, + "curl_easy_getinfo expects a pointer to long for this info") +_CURL_WARNING(_curl_easy_getinfo_err_double, + "curl_easy_getinfo expects a pointer to double for this info") +_CURL_WARNING(_curl_easy_getinfo_err_curl_slist, + "curl_easy_getinfo expects a pointer to struct curl_slist * for this info") + +/* groups of curl_easy_setops options that take the same type of argument */ + +/* To add a new option to one of the groups, just add + * (option) == CURLOPT_SOMETHING + * to the or-expression. If the option takes a long or curl_off_t, you don't + * have to do anything + */ + +/* evaluates to true if option takes a long argument */ +#define _curl_is_long_option(option) \ + (0 < (option) && (option) < CURLOPTTYPE_OBJECTPOINT) + +#define _curl_is_off_t_option(option) \ + ((option) > CURLOPTTYPE_OFF_T) + +/* evaluates to true if option takes a char* argument */ +#define _curl_is_string_option(option) \ + ((option) == CURLOPT_URL || \ + (option) == CURLOPT_PROXY || \ + (option) == CURLOPT_INTERFACE || \ + (option) == CURLOPT_NETRC_FILE || \ + (option) == CURLOPT_USERPWD || \ + (option) == CURLOPT_USERNAME || \ + (option) == CURLOPT_PASSWORD || \ + (option) == CURLOPT_PROXYUSERPWD || \ + (option) == CURLOPT_PROXYUSERNAME || \ + (option) == CURLOPT_PROXYPASSWORD || \ + (option) == CURLOPT_NOPROXY || \ + (option) == CURLOPT_ACCEPT_ENCODING || \ + (option) == CURLOPT_REFERER || \ + (option) == CURLOPT_USERAGENT || \ + (option) == CURLOPT_COOKIE || \ + (option) == CURLOPT_COOKIEFILE || \ + (option) == CURLOPT_COOKIEJAR || \ + (option) == CURLOPT_COOKIELIST || \ + (option) == CURLOPT_FTPPORT || \ + (option) == CURLOPT_FTP_ALTERNATIVE_TO_USER || \ + (option) == CURLOPT_FTP_ACCOUNT || \ + (option) == CURLOPT_RANGE || \ + (option) == CURLOPT_CUSTOMREQUEST || \ + (option) == CURLOPT_SSLCERT || \ + (option) == CURLOPT_SSLCERTTYPE || \ + (option) == CURLOPT_SSLKEY || \ + (option) == CURLOPT_SSLKEYTYPE || \ + (option) == CURLOPT_KEYPASSWD || \ + (option) == CURLOPT_SSLENGINE || \ + (option) == CURLOPT_CAINFO || \ + (option) == CURLOPT_CAPATH || \ + (option) == CURLOPT_RANDOM_FILE || \ + (option) == CURLOPT_EGDSOCKET || \ + (option) == CURLOPT_SSL_CIPHER_LIST || \ + (option) == CURLOPT_KRBLEVEL || \ + (option) == CURLOPT_SSH_HOST_PUBLIC_KEY_MD5 || \ + (option) == CURLOPT_SSH_PUBLIC_KEYFILE || \ + (option) == CURLOPT_SSH_PRIVATE_KEYFILE || \ + (option) == CURLOPT_CRLFILE || \ + (option) == CURLOPT_ISSUERCERT || \ + (option) == CURLOPT_SOCKS5_GSSAPI_SERVICE || \ + (option) == CURLOPT_SSH_KNOWNHOSTS || \ + (option) == CURLOPT_MAIL_FROM || \ + (option) == CURLOPT_RTSP_SESSION_ID || \ + (option) == CURLOPT_RTSP_STREAM_URI || \ + (option) == CURLOPT_RTSP_TRANSPORT || \ + 0) + +/* evaluates to true if option takes a curl_write_callback argument */ +#define _curl_is_write_cb_option(option) \ + ((option) == CURLOPT_HEADERFUNCTION || \ + (option) == CURLOPT_WRITEFUNCTION) + +/* evaluates to true if option takes a curl_conv_callback argument */ +#define _curl_is_conv_cb_option(option) \ + ((option) == CURLOPT_CONV_TO_NETWORK_FUNCTION || \ + (option) == CURLOPT_CONV_FROM_NETWORK_FUNCTION || \ + (option) == CURLOPT_CONV_FROM_UTF8_FUNCTION) + +/* evaluates to true if option takes a data argument to pass to a callback */ +#define _curl_is_cb_data_option(option) \ + ((option) == CURLOPT_WRITEDATA || \ + (option) == CURLOPT_READDATA || \ + (option) == CURLOPT_IOCTLDATA || \ + (option) == CURLOPT_SOCKOPTDATA || \ + (option) == CURLOPT_OPENSOCKETDATA || \ + (option) == CURLOPT_PROGRESSDATA || \ + (option) == CURLOPT_WRITEHEADER || \ + (option) == CURLOPT_DEBUGDATA || \ + (option) == CURLOPT_SSL_CTX_DATA || \ + (option) == CURLOPT_SEEKDATA || \ + (option) == CURLOPT_PRIVATE || \ + (option) == CURLOPT_SSH_KEYDATA || \ + (option) == CURLOPT_INTERLEAVEDATA || \ + (option) == CURLOPT_CHUNK_DATA || \ + (option) == CURLOPT_FNMATCH_DATA || \ + 0) + +/* evaluates to true if option takes a POST data argument (void* or char*) */ +#define _curl_is_postfields_option(option) \ + ((option) == CURLOPT_POSTFIELDS || \ + (option) == CURLOPT_COPYPOSTFIELDS || \ + 0) + +/* evaluates to true if option takes a struct curl_slist * argument */ +#define _curl_is_slist_option(option) \ + ((option) == CURLOPT_HTTPHEADER || \ + (option) == CURLOPT_HTTP200ALIASES || \ + (option) == CURLOPT_QUOTE || \ + (option) == CURLOPT_POSTQUOTE || \ + (option) == CURLOPT_PREQUOTE || \ + (option) == CURLOPT_TELNETOPTIONS || \ + (option) == CURLOPT_MAIL_RCPT || \ + 0) + +/* groups of curl_easy_getinfo infos that take the same type of argument */ + +/* evaluates to true if info expects a pointer to char * argument */ +#define _curl_is_string_info(info) \ + (CURLINFO_STRING < (info) && (info) < CURLINFO_LONG) + +/* evaluates to true if info expects a pointer to long argument */ +#define _curl_is_long_info(info) \ + (CURLINFO_LONG < (info) && (info) < CURLINFO_DOUBLE) + +/* evaluates to true if info expects a pointer to double argument */ +#define _curl_is_double_info(info) \ + (CURLINFO_DOUBLE < (info) && (info) < CURLINFO_SLIST) + +/* true if info expects a pointer to struct curl_slist * argument */ +#define _curl_is_slist_info(info) \ + (CURLINFO_SLIST < (info)) + + +/* typecheck helpers -- check whether given expression has requested type*/ + +/* For pointers, you can use the _curl_is_ptr/_curl_is_arr macros, + * otherwise define a new macro. Search for __builtin_types_compatible_p + * in the GCC manual. + * NOTE: these macros MUST NOT EVALUATE their arguments! The argument is + * the actual expression passed to the curl_easy_setopt macro. This + * means that you can only apply the sizeof and __typeof__ operators, no + * == or whatsoever. + */ + +/* XXX: should evaluate to true iff expr is a pointer */ +#define _curl_is_any_ptr(expr) \ + (sizeof(expr) == sizeof(void*)) + +/* evaluates to true if expr is NULL */ +/* XXX: must not evaluate expr, so this check is not accurate */ +#define _curl_is_NULL(expr) \ + (__builtin_types_compatible_p(__typeof__(expr), __typeof__(NULL))) + +/* evaluates to true if expr is type*, const type* or NULL */ +#define _curl_is_ptr(expr, type) \ + (_curl_is_NULL(expr) || \ + __builtin_types_compatible_p(__typeof__(expr), type *) || \ + __builtin_types_compatible_p(__typeof__(expr), const type *)) + +/* evaluates to true if expr is one of type[], type*, NULL or const type* */ +#define _curl_is_arr(expr, type) \ + (_curl_is_ptr((expr), type) || \ + __builtin_types_compatible_p(__typeof__(expr), type [])) + +/* evaluates to true if expr is a string */ +#define _curl_is_string(expr) \ + (_curl_is_arr((expr), char) || \ + _curl_is_arr((expr), signed char) || \ + _curl_is_arr((expr), unsigned char)) + +/* evaluates to true if expr is a long (no matter the signedness) + * XXX: for now, int is also accepted (and therefore short and char, which + * are promoted to int when passed to a variadic function) */ +#define _curl_is_long(expr) \ + (__builtin_types_compatible_p(__typeof__(expr), long) || \ + __builtin_types_compatible_p(__typeof__(expr), signed long) || \ + __builtin_types_compatible_p(__typeof__(expr), unsigned long) || \ + __builtin_types_compatible_p(__typeof__(expr), int) || \ + __builtin_types_compatible_p(__typeof__(expr), signed int) || \ + __builtin_types_compatible_p(__typeof__(expr), unsigned int) || \ + __builtin_types_compatible_p(__typeof__(expr), short) || \ + __builtin_types_compatible_p(__typeof__(expr), signed short) || \ + __builtin_types_compatible_p(__typeof__(expr), unsigned short) || \ + __builtin_types_compatible_p(__typeof__(expr), char) || \ + __builtin_types_compatible_p(__typeof__(expr), signed char) || \ + __builtin_types_compatible_p(__typeof__(expr), unsigned char)) + +/* evaluates to true if expr is of type curl_off_t */ +#define _curl_is_off_t(expr) \ + (__builtin_types_compatible_p(__typeof__(expr), curl_off_t)) + +/* evaluates to true if expr is abuffer suitable for CURLOPT_ERRORBUFFER */ +/* XXX: also check size of an char[] array? */ +#define _curl_is_error_buffer(expr) \ + (__builtin_types_compatible_p(__typeof__(expr), char *) || \ + __builtin_types_compatible_p(__typeof__(expr), char[])) + +/* evaluates to true if expr is of type (const) void* or (const) FILE* */ +#if 0 +#define _curl_is_cb_data(expr) \ + (_curl_is_ptr((expr), void) || \ + _curl_is_ptr((expr), FILE)) +#else /* be less strict */ +#define _curl_is_cb_data(expr) \ + _curl_is_any_ptr(expr) +#endif + +/* evaluates to true if expr is of type FILE* */ +#define _curl_is_FILE(expr) \ + (__builtin_types_compatible_p(__typeof__(expr), FILE *)) + +/* evaluates to true if expr can be passed as POST data (void* or char*) */ +#define _curl_is_postfields(expr) \ + (_curl_is_ptr((expr), void) || \ + _curl_is_arr((expr), char)) + +/* FIXME: the whole callback checking is messy... + * The idea is to tolerate char vs. void and const vs. not const + * pointers in arguments at least + */ +/* helper: __builtin_types_compatible_p distinguishes between functions and + * function pointers, hide it */ +#define _curl_callback_compatible(func, type) \ + (__builtin_types_compatible_p(__typeof__(func), type) || \ + __builtin_types_compatible_p(__typeof__(func), type*)) + +/* evaluates to true if expr is of type curl_read_callback or "similar" */ +#define _curl_is_read_cb(expr) \ + (_curl_is_NULL(expr) || \ + __builtin_types_compatible_p(__typeof__(expr), __typeof__(fread)) || \ + __builtin_types_compatible_p(__typeof__(expr), curl_read_callback) || \ + _curl_callback_compatible((expr), _curl_read_callback1) || \ + _curl_callback_compatible((expr), _curl_read_callback2) || \ + _curl_callback_compatible((expr), _curl_read_callback3) || \ + _curl_callback_compatible((expr), _curl_read_callback4) || \ + _curl_callback_compatible((expr), _curl_read_callback5) || \ + _curl_callback_compatible((expr), _curl_read_callback6)) +typedef size_t (_curl_read_callback1)(char *, size_t, size_t, void*); +typedef size_t (_curl_read_callback2)(char *, size_t, size_t, const void*); +typedef size_t (_curl_read_callback3)(char *, size_t, size_t, FILE*); +typedef size_t (_curl_read_callback4)(void *, size_t, size_t, void*); +typedef size_t (_curl_read_callback5)(void *, size_t, size_t, const void*); +typedef size_t (_curl_read_callback6)(void *, size_t, size_t, FILE*); + +/* evaluates to true if expr is of type curl_write_callback or "similar" */ +#define _curl_is_write_cb(expr) \ + (_curl_is_read_cb(expr) || \ + __builtin_types_compatible_p(__typeof__(expr), __typeof__(fwrite)) || \ + __builtin_types_compatible_p(__typeof__(expr), curl_write_callback) || \ + _curl_callback_compatible((expr), _curl_write_callback1) || \ + _curl_callback_compatible((expr), _curl_write_callback2) || \ + _curl_callback_compatible((expr), _curl_write_callback3) || \ + _curl_callback_compatible((expr), _curl_write_callback4) || \ + _curl_callback_compatible((expr), _curl_write_callback5) || \ + _curl_callback_compatible((expr), _curl_write_callback6)) +typedef size_t (_curl_write_callback1)(const char *, size_t, size_t, void*); +typedef size_t (_curl_write_callback2)(const char *, size_t, size_t, + const void*); +typedef size_t (_curl_write_callback3)(const char *, size_t, size_t, FILE*); +typedef size_t (_curl_write_callback4)(const void *, size_t, size_t, void*); +typedef size_t (_curl_write_callback5)(const void *, size_t, size_t, + const void*); +typedef size_t (_curl_write_callback6)(const void *, size_t, size_t, FILE*); + +/* evaluates to true if expr is of type curl_ioctl_callback or "similar" */ +#define _curl_is_ioctl_cb(expr) \ + (_curl_is_NULL(expr) || \ + __builtin_types_compatible_p(__typeof__(expr), curl_ioctl_callback) || \ + _curl_callback_compatible((expr), _curl_ioctl_callback1) || \ + _curl_callback_compatible((expr), _curl_ioctl_callback2) || \ + _curl_callback_compatible((expr), _curl_ioctl_callback3) || \ + _curl_callback_compatible((expr), _curl_ioctl_callback4)) +typedef curlioerr (_curl_ioctl_callback1)(CURL *, int, void*); +typedef curlioerr (_curl_ioctl_callback2)(CURL *, int, const void*); +typedef curlioerr (_curl_ioctl_callback3)(CURL *, curliocmd, void*); +typedef curlioerr (_curl_ioctl_callback4)(CURL *, curliocmd, const void*); + +/* evaluates to true if expr is of type curl_sockopt_callback or "similar" */ +#define _curl_is_sockopt_cb(expr) \ + (_curl_is_NULL(expr) || \ + __builtin_types_compatible_p(__typeof__(expr), curl_sockopt_callback) || \ + _curl_callback_compatible((expr), _curl_sockopt_callback1) || \ + _curl_callback_compatible((expr), _curl_sockopt_callback2)) +typedef int (_curl_sockopt_callback1)(void *, curl_socket_t, curlsocktype); +typedef int (_curl_sockopt_callback2)(const void *, curl_socket_t, + curlsocktype); + +/* evaluates to true if expr is of type curl_opensocket_callback or "similar" */ +#define _curl_is_opensocket_cb(expr) \ + (_curl_is_NULL(expr) || \ + __builtin_types_compatible_p(__typeof__(expr), curl_opensocket_callback) ||\ + _curl_callback_compatible((expr), _curl_opensocket_callback1) || \ + _curl_callback_compatible((expr), _curl_opensocket_callback2) || \ + _curl_callback_compatible((expr), _curl_opensocket_callback3) || \ + _curl_callback_compatible((expr), _curl_opensocket_callback4)) +typedef curl_socket_t (_curl_opensocket_callback1) + (void *, curlsocktype, struct curl_sockaddr *); +typedef curl_socket_t (_curl_opensocket_callback2) + (void *, curlsocktype, const struct curl_sockaddr *); +typedef curl_socket_t (_curl_opensocket_callback3) + (const void *, curlsocktype, struct curl_sockaddr *); +typedef curl_socket_t (_curl_opensocket_callback4) + (const void *, curlsocktype, const struct curl_sockaddr *); + +/* evaluates to true if expr is of type curl_progress_callback or "similar" */ +#define _curl_is_progress_cb(expr) \ + (_curl_is_NULL(expr) || \ + __builtin_types_compatible_p(__typeof__(expr), curl_progress_callback) || \ + _curl_callback_compatible((expr), _curl_progress_callback1) || \ + _curl_callback_compatible((expr), _curl_progress_callback2)) +typedef int (_curl_progress_callback1)(void *, + double, double, double, double); +typedef int (_curl_progress_callback2)(const void *, + double, double, double, double); + +/* evaluates to true if expr is of type curl_debug_callback or "similar" */ +#define _curl_is_debug_cb(expr) \ + (_curl_is_NULL(expr) || \ + __builtin_types_compatible_p(__typeof__(expr), curl_debug_callback) || \ + _curl_callback_compatible((expr), _curl_debug_callback1) || \ + _curl_callback_compatible((expr), _curl_debug_callback2) || \ + _curl_callback_compatible((expr), _curl_debug_callback3) || \ + _curl_callback_compatible((expr), _curl_debug_callback4)) +typedef int (_curl_debug_callback1) (CURL *, + curl_infotype, char *, size_t, void *); +typedef int (_curl_debug_callback2) (CURL *, + curl_infotype, char *, size_t, const void *); +typedef int (_curl_debug_callback3) (CURL *, + curl_infotype, const char *, size_t, void *); +typedef int (_curl_debug_callback4) (CURL *, + curl_infotype, const char *, size_t, const void *); + +/* evaluates to true if expr is of type curl_ssl_ctx_callback or "similar" */ +/* this is getting even messier... */ +#define _curl_is_ssl_ctx_cb(expr) \ + (_curl_is_NULL(expr) || \ + __builtin_types_compatible_p(__typeof__(expr), curl_ssl_ctx_callback) || \ + _curl_callback_compatible((expr), _curl_ssl_ctx_callback1) || \ + _curl_callback_compatible((expr), _curl_ssl_ctx_callback2) || \ + _curl_callback_compatible((expr), _curl_ssl_ctx_callback3) || \ + _curl_callback_compatible((expr), _curl_ssl_ctx_callback4) || \ + _curl_callback_compatible((expr), _curl_ssl_ctx_callback5) || \ + _curl_callback_compatible((expr), _curl_ssl_ctx_callback6) || \ + _curl_callback_compatible((expr), _curl_ssl_ctx_callback7) || \ + _curl_callback_compatible((expr), _curl_ssl_ctx_callback8)) +typedef CURLcode (_curl_ssl_ctx_callback1)(CURL *, void *, void *); +typedef CURLcode (_curl_ssl_ctx_callback2)(CURL *, void *, const void *); +typedef CURLcode (_curl_ssl_ctx_callback3)(CURL *, const void *, void *); +typedef CURLcode (_curl_ssl_ctx_callback4)(CURL *, const void *, const void *); +#ifdef HEADER_SSL_H +/* hack: if we included OpenSSL's ssl.h, we know about SSL_CTX + * this will of course break if we're included before OpenSSL headers... + */ +typedef CURLcode (_curl_ssl_ctx_callback5)(CURL *, SSL_CTX, void *); +typedef CURLcode (_curl_ssl_ctx_callback6)(CURL *, SSL_CTX, const void *); +typedef CURLcode (_curl_ssl_ctx_callback7)(CURL *, const SSL_CTX, void *); +typedef CURLcode (_curl_ssl_ctx_callback8)(CURL *, const SSL_CTX, const void *); +#else +typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback5; +typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback6; +typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback7; +typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback8; +#endif + +/* evaluates to true if expr is of type curl_conv_callback or "similar" */ +#define _curl_is_conv_cb(expr) \ + (_curl_is_NULL(expr) || \ + __builtin_types_compatible_p(__typeof__(expr), curl_conv_callback) || \ + _curl_callback_compatible((expr), _curl_conv_callback1) || \ + _curl_callback_compatible((expr), _curl_conv_callback2) || \ + _curl_callback_compatible((expr), _curl_conv_callback3) || \ + _curl_callback_compatible((expr), _curl_conv_callback4)) +typedef CURLcode (*_curl_conv_callback1)(char *, size_t length); +typedef CURLcode (*_curl_conv_callback2)(const char *, size_t length); +typedef CURLcode (*_curl_conv_callback3)(void *, size_t length); +typedef CURLcode (*_curl_conv_callback4)(const void *, size_t length); + +/* evaluates to true if expr is of type curl_seek_callback or "similar" */ +#define _curl_is_seek_cb(expr) \ + (_curl_is_NULL(expr) || \ + __builtin_types_compatible_p(__typeof__(expr), curl_seek_callback) || \ + _curl_callback_compatible((expr), _curl_seek_callback1) || \ + _curl_callback_compatible((expr), _curl_seek_callback2)) +typedef CURLcode (*_curl_seek_callback1)(void *, curl_off_t, int); +typedef CURLcode (*_curl_seek_callback2)(const void *, curl_off_t, int); + + +#endif /* __CURL_TYPECHECK_GCC_H */ diff --git a/libs/curl/include/curl/types.h b/libs/curl/include/curl/types.h new file mode 100644 index 000000000..d37d6ae9e --- /dev/null +++ b/libs/curl/include/curl/types.h @@ -0,0 +1 @@ +/* not used */ diff --git a/libs/curl/lib32/libcurl.a b/libs/curl/lib32/libcurl.a new file mode 100644 index 000000000..2f5a29f62 Binary files /dev/null and b/libs/curl/lib32/libcurl.a differ diff --git a/libs/curl/lib64/libcurl.a b/libs/curl/lib64/libcurl.a new file mode 100644 index 000000000..2112cd8f0 Binary files /dev/null and b/libs/curl/lib64/libcurl.a differ diff --git a/libs/fmodex/inc/fmod.h b/libs/fmodex/inc/fmod.h new file mode 100644 index 000000000..f3fbd853e --- /dev/null +++ b/libs/fmodex/inc/fmod.h @@ -0,0 +1,2462 @@ + +/* ============================================================================================ */ +/* FMOD Ex - Main C/C++ header file. Copyright (c), Firelight Technologies Pty, Ltd. 2004-2011. */ +/* */ +/* This header is the base header for all other FMOD headers. If you are programming in C */ +/* use this exclusively, or if you are programming C++ use this in conjunction with FMOD.HPP */ +/* */ +/* ============================================================================================ */ + +#ifndef _FMOD_H +#define _FMOD_H + +/* + FMOD version number. Check this against FMOD::System::getVersion. + 0xaaaabbcc -> aaaa = major version number. bb = minor version number. cc = development version number. +*/ + +#define FMOD_VERSION 0x00044412 + +/* + Compiler specific settings. +*/ + +#if defined(__CYGWIN32__) + #define F_CDECL __cdecl + #define F_STDCALL __stdcall + #define F_DECLSPEC __declspec + #define F_DLLEXPORT ( dllexport ) +#elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(_WIN64) + #define F_CDECL _cdecl + #define F_STDCALL _stdcall + #define F_DECLSPEC __declspec + #define F_DLLEXPORT ( dllexport ) +#elif defined(__MACH__) || defined(__ANDROID__) || defined(__linux__) || defined(__QNX__) + #define F_CDECL + #define F_STDCALL + #define F_DECLSPEC + #define F_DLLEXPORT __attribute__ ((visibility("default"))) +#else + #define F_CDECL + #define F_STDCALL + #define F_DECLSPEC + #define F_DLLEXPORT +#endif + +#ifdef DLL_EXPORTS + #if defined(__MACH__) || defined(__ANDROID__) || defined(__linux__) || defined(__QNX__) + #define F_API __attribute__ ((visibility("default"))) + #else + #define F_API __declspec(dllexport) F_STDCALL + #endif +#else + #define F_API F_STDCALL +#endif + +#define F_CALLBACK F_STDCALL + +/* + FMOD types. +*/ + +typedef int FMOD_BOOL; +typedef struct FMOD_SYSTEM FMOD_SYSTEM; +typedef struct FMOD_SOUND FMOD_SOUND; +typedef struct FMOD_CHANNEL FMOD_CHANNEL; +typedef struct FMOD_CHANNELGROUP FMOD_CHANNELGROUP; +typedef struct FMOD_SOUNDGROUP FMOD_SOUNDGROUP; +typedef struct FMOD_REVERB FMOD_REVERB; +typedef struct FMOD_DSP FMOD_DSP; +typedef struct FMOD_DSPCONNECTION FMOD_DSPCONNECTION; +typedef struct FMOD_POLYGON FMOD_POLYGON; +typedef struct FMOD_GEOMETRY FMOD_GEOMETRY; +typedef struct FMOD_SYNCPOINT FMOD_SYNCPOINT; +typedef unsigned int FMOD_MODE; +typedef unsigned int FMOD_TIMEUNIT; +typedef unsigned int FMOD_INITFLAGS; +typedef unsigned int FMOD_CAPS; +typedef unsigned int FMOD_DEBUGLEVEL; +typedef unsigned int FMOD_MEMORY_TYPE; + +/* +[ENUM] +[ + [DESCRIPTION] + error codes. Returned from every function. + + [REMARKS] + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] +] +*/ +typedef enum +{ + FMOD_OK, /* No errors. */ + FMOD_ERR_ALREADYLOCKED, /* Tried to call lock a second time before unlock was called. */ + FMOD_ERR_BADCOMMAND, /* Tried to call a function on a data type that does not allow this type of functionality (ie calling Sound::lock on a streaming sound). */ + FMOD_ERR_CDDA_DRIVERS, /* Neither NTSCSI nor ASPI could be initialised. */ + FMOD_ERR_CDDA_INIT, /* An error occurred while initialising the CDDA subsystem. */ + FMOD_ERR_CDDA_INVALID_DEVICE, /* Couldn't find the specified device. */ + FMOD_ERR_CDDA_NOAUDIO, /* No audio tracks on the specified disc. */ + FMOD_ERR_CDDA_NODEVICES, /* No CD/DVD devices were found. */ + FMOD_ERR_CDDA_NODISC, /* No disc present in the specified drive. */ + FMOD_ERR_CDDA_READ, /* A CDDA read error occurred. */ + FMOD_ERR_CHANNEL_ALLOC, /* Error trying to allocate a channel. */ + FMOD_ERR_CHANNEL_STOLEN, /* The specified channel has been reused to play another sound. */ + FMOD_ERR_COM, /* A Win32 COM related error occured. COM failed to initialize or a QueryInterface failed meaning a Windows codec or driver was not installed properly. */ + FMOD_ERR_DMA, /* DMA Failure. See debug output for more information. */ + FMOD_ERR_DSP_CONNECTION, /* DSP connection error. Connection possibly caused a cyclic dependancy. Or tried to connect a tree too many units deep (more than 128). */ + FMOD_ERR_DSP_FORMAT, /* DSP Format error. A DSP unit may have attempted to connect to this network with the wrong format. */ + FMOD_ERR_DSP_NOTFOUND, /* DSP connection error. Couldn't find the DSP unit specified. */ + FMOD_ERR_DSP_RUNNING, /* DSP error. Cannot perform this operation while the network is in the middle of running. This will most likely happen if a connection or disconnection is attempted in a DSP callback. */ + FMOD_ERR_DSP_TOOMANYCONNECTIONS,/* DSP connection error. The unit being connected to or disconnected should only have 1 input or output. */ + FMOD_ERR_FILE_BAD, /* Error loading file. */ + FMOD_ERR_FILE_COULDNOTSEEK, /* Couldn't perform seek operation. This is a limitation of the medium (ie netstreams) or the file format. */ + FMOD_ERR_FILE_DISKEJECTED, /* Media was ejected while reading. */ + FMOD_ERR_FILE_EOF, /* End of file unexpectedly reached while trying to read essential data (truncated data?). */ + FMOD_ERR_FILE_NOTFOUND, /* File not found. */ + FMOD_ERR_FILE_UNWANTED, /* Unwanted file access occured. */ + FMOD_ERR_FORMAT, /* Unsupported file or audio format. */ + FMOD_ERR_HTTP, /* A HTTP error occurred. This is a catch-all for HTTP errors not listed elsewhere. */ + FMOD_ERR_HTTP_ACCESS, /* The specified resource requires authentication or is forbidden. */ + FMOD_ERR_HTTP_PROXY_AUTH, /* Proxy authentication is required to access the specified resource. */ + FMOD_ERR_HTTP_SERVER_ERROR, /* A HTTP server error occurred. */ + FMOD_ERR_HTTP_TIMEOUT, /* The HTTP request timed out. */ + FMOD_ERR_INITIALIZATION, /* FMOD was not initialized correctly to support this function. */ + FMOD_ERR_INITIALIZED, /* Cannot call this command after System::init. */ + FMOD_ERR_INTERNAL, /* An error occured that wasn't supposed to. Contact support. */ + FMOD_ERR_INVALID_ADDRESS, /* On Xbox 360, this memory address passed to FMOD must be physical, (ie allocated with XPhysicalAlloc.) */ + FMOD_ERR_INVALID_FLOAT, /* Value passed in was a NaN, Inf or denormalized float. */ + FMOD_ERR_INVALID_HANDLE, /* An invalid object handle was used. */ + FMOD_ERR_INVALID_PARAM, /* An invalid parameter was passed to this function. */ + FMOD_ERR_INVALID_POSITION, /* An invalid seek position was passed to this function. */ + FMOD_ERR_INVALID_SPEAKER, /* An invalid speaker was passed to this function based on the current speaker mode. */ + FMOD_ERR_INVALID_SYNCPOINT, /* The syncpoint did not come from this sound handle. */ + FMOD_ERR_INVALID_VECTOR, /* The vectors passed in are not unit length, or perpendicular. */ + FMOD_ERR_MAXAUDIBLE, /* Reached maximum audible playback count for this sound's soundgroup. */ + FMOD_ERR_MEMORY, /* Not enough memory or resources. */ + FMOD_ERR_MEMORY_CANTPOINT, /* Can't use FMOD_OPENMEMORY_POINT on non PCM source data, or non mp3/xma/adpcm data if FMOD_CREATECOMPRESSEDSAMPLE was used. */ + FMOD_ERR_MEMORY_SRAM, /* Not enough memory or resources on console sound ram. */ + FMOD_ERR_NEEDS2D, /* Tried to call a command on a 3d sound when the command was meant for 2d sound. */ + FMOD_ERR_NEEDS3D, /* Tried to call a command on a 2d sound when the command was meant for 3d sound. */ + FMOD_ERR_NEEDSHARDWARE, /* Tried to use a feature that requires hardware support. (ie trying to play a GCADPCM compressed sound in software on Wii). */ + FMOD_ERR_NEEDSSOFTWARE, /* Tried to use a feature that requires the software engine. Software engine has either been turned off, or command was executed on a hardware channel which does not support this feature. */ + FMOD_ERR_NET_CONNECT, /* Couldn't connect to the specified host. */ + FMOD_ERR_NET_SOCKET_ERROR, /* A socket error occurred. This is a catch-all for socket-related errors not listed elsewhere. */ + FMOD_ERR_NET_URL, /* The specified URL couldn't be resolved. */ + FMOD_ERR_NET_WOULD_BLOCK, /* Operation on a non-blocking socket could not complete immediately. */ + FMOD_ERR_NOTREADY, /* Operation could not be performed because specified sound/DSP connection is not ready. */ + FMOD_ERR_OUTPUT_ALLOCATED, /* Error initializing output device, but more specifically, the output device is already in use and cannot be reused. */ + FMOD_ERR_OUTPUT_CREATEBUFFER, /* Error creating hardware sound buffer. */ + FMOD_ERR_OUTPUT_DRIVERCALL, /* A call to a standard soundcard driver failed, which could possibly mean a bug in the driver or resources were missing or exhausted. */ + FMOD_ERR_OUTPUT_ENUMERATION, /* Error enumerating the available driver list. List may be inconsistent due to a recent device addition or removal. */ + FMOD_ERR_OUTPUT_FORMAT, /* Soundcard does not support the minimum features needed for this soundsystem (16bit stereo output). */ + FMOD_ERR_OUTPUT_INIT, /* Error initializing output device. */ + FMOD_ERR_OUTPUT_NOHARDWARE, /* FMOD_HARDWARE was specified but the sound card does not have the resources necessary to play it. */ + FMOD_ERR_OUTPUT_NOSOFTWARE, /* Attempted to create a software sound but no software channels were specified in System::init. */ + FMOD_ERR_PAN, /* Panning only works with mono or stereo sound sources. */ + FMOD_ERR_PLUGIN, /* An unspecified error has been returned from a 3rd party plugin. */ + FMOD_ERR_PLUGIN_INSTANCES, /* The number of allowed instances of a plugin has been exceeded. */ + FMOD_ERR_PLUGIN_MISSING, /* A requested output, dsp unit type or codec was not available. */ + FMOD_ERR_PLUGIN_RESOURCE, /* A resource that the plugin requires cannot be found. (ie the DLS file for MIDI playback or other DLLs that it needs to load) */ + FMOD_ERR_PRELOADED, /* The specified sound is still in use by the event system, call EventSystem::unloadFSB before trying to release it. */ + FMOD_ERR_PROGRAMMERSOUND, /* The specified sound is still in use by the event system, wait for the event which is using it finish with it. */ + FMOD_ERR_RECORD, /* An error occured trying to initialize the recording device. */ + FMOD_ERR_REVERB_INSTANCE, /* Specified instance in FMOD_REVERB_PROPERTIES couldn't be set. Most likely because it is an invalid instance number or the reverb doesnt exist. */ + FMOD_ERR_SUBSOUND_ALLOCATED, /* This subsound is already being used by another sound, you cannot have more than one parent to a sound. Null out the other parent's entry first. */ + FMOD_ERR_SUBSOUND_CANTMOVE, /* Shared subsounds cannot be replaced or moved from their parent stream, such as when the parent stream is an FSB file. */ + FMOD_ERR_SUBSOUND_MODE, /* The subsound's mode bits do not match with the parent sound's mode bits. See documentation for function that it was called with. */ + FMOD_ERR_SUBSOUNDS, /* The error occured because the sound referenced contains subsounds when it shouldn't have, or it doesn't contain subsounds when it should have. The operation may also not be able to be performed on a parent sound, or a parent sound was played without setting up a sentence first. */ + FMOD_ERR_TAGNOTFOUND, /* The specified tag could not be found or there are no tags. */ + FMOD_ERR_TOOMANYCHANNELS, /* The sound created exceeds the allowable input channel count. This can be increased using the maxinputchannels parameter in System::setSoftwareFormat. */ + FMOD_ERR_UNIMPLEMENTED, /* Something in FMOD hasn't been implemented when it should be! contact support! */ + FMOD_ERR_UNINITIALIZED, /* This command failed because System::init or System::setDriver was not called. */ + FMOD_ERR_UNSUPPORTED, /* A command issued was not supported by this object. Possibly a plugin without certain callbacks specified. */ + FMOD_ERR_UPDATE, /* An error caused by System::update occured. */ + FMOD_ERR_VERSION, /* The version number of this file format is not supported. */ + + FMOD_ERR_EVENT_FAILED, /* An Event failed to be retrieved, most likely due to 'just fail' being specified as the max playbacks behavior. */ + FMOD_ERR_EVENT_INFOONLY, /* Can't execute this command on an EVENT_INFOONLY event. */ + FMOD_ERR_EVENT_INTERNAL, /* An error occured that wasn't supposed to. See debug log for reason. */ + FMOD_ERR_EVENT_MAXSTREAMS, /* Event failed because 'Max streams' was hit when FMOD_EVENT_INIT_FAIL_ON_MAXSTREAMS was specified. */ + FMOD_ERR_EVENT_MISMATCH, /* FSB mismatches the FEV it was compiled with, the stream/sample mode it was meant to be created with was different, or the FEV was built for a different platform. */ + FMOD_ERR_EVENT_NAMECONFLICT, /* A category with the same name already exists. */ + FMOD_ERR_EVENT_NOTFOUND, /* The requested event, event group, event category or event property could not be found. */ + FMOD_ERR_EVENT_NEEDSSIMPLE, /* Tried to call a function on a complex event that's only supported by simple events. */ + FMOD_ERR_EVENT_GUIDCONFLICT, /* An event with the same GUID already exists. */ + FMOD_ERR_EVENT_ALREADY_LOADED, /* The specified project or bank has already been loaded. Having multiple copies of the same project loaded simultaneously is forbidden. */ + + FMOD_ERR_MUSIC_UNINITIALIZED, /* Music system is not initialized probably because no music data is loaded. */ + FMOD_ERR_MUSIC_NOTFOUND, /* The requested music entity could not be found. */ + FMOD_ERR_MUSIC_NOCALLBACK, /* The music callback is required, but it has not been set. */ + + FMOD_RESULT_FORCEINT = 65536 /* Makes sure this enum is signed 32bit. */ +} FMOD_RESULT; + + +/* +[STRUCTURE] +[ + [DESCRIPTION] + Structure describing a point in 3D space. + + [REMARKS] + FMOD uses a left handed co-ordinate system by default. + To use a right handed co-ordinate system specify FMOD_INIT_3D_RIGHTHANDED from FMOD_INITFLAGS in System::init. + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + System::set3DListenerAttributes + System::get3DListenerAttributes + Channel::set3DAttributes + Channel::get3DAttributes + Channel::set3DCustomRolloff + Channel::get3DCustomRolloff + Sound::set3DCustomRolloff + Sound::get3DCustomRolloff + Geometry::addPolygon + Geometry::setPolygonVertex + Geometry::getPolygonVertex + Geometry::setRotation + Geometry::getRotation + Geometry::setPosition + Geometry::getPosition + Geometry::setScale + Geometry::getScale + FMOD_INITFLAGS +] +*/ +typedef struct +{ + float x; /* X co-ordinate in 3D space. */ + float y; /* Y co-ordinate in 3D space. */ + float z; /* Z co-ordinate in 3D space. */ +} FMOD_VECTOR; + +/* +[STRUCTURE] +[ + [DESCRIPTION] + Structure describing a globally unique identifier. + + [REMARKS] + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + System::getDriverInfo +] +*/ +typedef struct +{ + unsigned int Data1; /* Specifies the first 8 hexadecimal digits of the GUID */ + unsigned short Data2; /* Specifies the first group of 4 hexadecimal digits. */ + unsigned short Data3; /* Specifies the second group of 4 hexadecimal digits. */ + unsigned char Data4[8]; /* Array of 8 bytes. The first 2 bytes contain the third group of 4 hexadecimal digits. The remaining 6 bytes contain the final 12 hexadecimal digits. */ +} FMOD_GUID; + +/* +[STRUCTURE] +[ + [DESCRIPTION] + Structure that is passed into FMOD_FILE_ASYNCREADCALLBACK. Use the information in this structure to perform + + [REMARKS] + Members marked with [r] mean the variable is modified by FMOD and is for reading purposes only. Do not change this value. + Members marked with [w] mean the variable can be written to. The user can set the value. + + Instructions: write to 'buffer', and 'bytesread' BEFORE setting 'result'. + As soon as result is set, FMOD will asynchronously continue internally using the data provided in this structure. + + Set 'result' to the result expected from a normal file read callback. + If the read was successful, set it to FMOD_OK. + If it read some data but hit the end of the file, set it to FMOD_ERR_FILE_EOF. + If a bad error occurred, return FMOD_ERR_FILE_BAD + If a disk was ejected, return FMOD_ERR_FILE_DISKEJECTED. + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + FMOD_FILE_ASYNCREADCALLBACK + FMOD_FILE_ASYNCCANCELCALLBACK +] +*/ +typedef struct +{ + void *handle; /* [r] The file handle that was filled out in the open callback. */ + unsigned int offset; /* [r] Seek position, make sure you read from this file offset. */ + unsigned int sizebytes; /* [r] how many bytes requested for read. */ + int priority; /* [r] 0 = low importance. 100 = extremely important (ie 'must read now or stuttering may occur') */ + + void *buffer; /* [w] Buffer to read file data into. */ + unsigned int bytesread; /* [w] Fill this in before setting result code to tell FMOD how many bytes were read. */ + FMOD_RESULT result; /* [r/w] Result code, FMOD_OK tells the system it is ready to consume the data. Set this last! Default value = FMOD_ERR_NOTREADY. */ + + void *userdata; /* [r] User data pointer. */ +} FMOD_ASYNCREADINFO; + + +/* +[ENUM] +[ + [DESCRIPTION] + These output types are used with System::setOutput / System::getOutput, to choose which output method to use. + + [REMARKS] + To pass information to the driver when initializing fmod use the extradriverdata parameter in System::init for the following reasons. + - FMOD_OUTPUTTYPE_WAVWRITER - extradriverdata is a pointer to a char * filename that the wav writer will output to. + - FMOD_OUTPUTTYPE_WAVWRITER_NRT - extradriverdata is a pointer to a char * filename that the wav writer will output to. + - FMOD_OUTPUTTYPE_DSOUND - extradriverdata is a pointer to a HWND so that FMOD can set the focus on the audio for a particular window. + - FMOD_OUTPUTTYPE_PS3 - extradriverdata is a pointer to a FMOD_PS3_EXTRADRIVERDATA struct. This can be found in fmodps3.h. + - FMOD_OUTPUTTYPE_GC - extradriverdata is a pointer to a FMOD_GC_INFO struct. This can be found in fmodgc.h. + - FMOD_OUTPUTTYPE_WII - extradriverdata is a pointer to a FMOD_WII_INFO struct. This can be found in fmodwii.h. + - FMOD_OUTPUTTYPE_ALSA - extradriverdata is a pointer to a FMOD_LINUX_EXTRADRIVERDATA struct. This can be found in fmodlinux.h. + + Currently these are the only FMOD drivers that take extra information. Other unknown plugins may have different requirements. + + Note! If FMOD_OUTPUTTYPE_WAVWRITER_NRT or FMOD_OUTPUTTYPE_NOSOUND_NRT are used, and if the System::update function is being called + very quickly (ie for a non realtime decode) it may be being called too quickly for the FMOD streamer thread to respond to. + The result will be a skipping/stuttering output in the captured audio. + + To remedy this, disable the FMOD Ex streamer thread, and use FMOD_INIT_STREAM_FROM_UPDATE to avoid skipping in the output stream, + as it will lock the mixer and the streamer together in the same thread. + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + System::setOutput + System::getOutput + System::setSoftwareFormat + System::getSoftwareFormat + System::init + System::update + FMOD_INITFLAGS +] +*/ +typedef enum +{ + FMOD_OUTPUTTYPE_AUTODETECT, /* Picks the best output mode for the platform. This is the default. */ + + FMOD_OUTPUTTYPE_UNKNOWN, /* All - 3rd party plugin, unknown. This is for use with System::getOutput only. */ + FMOD_OUTPUTTYPE_NOSOUND, /* All - All calls in this mode succeed but make no sound. */ + FMOD_OUTPUTTYPE_WAVWRITER, /* All - Writes output to fmodoutput.wav by default. Use the 'extradriverdata' parameter in System::init, by simply passing the filename as a string, to set the wav filename. */ + FMOD_OUTPUTTYPE_NOSOUND_NRT, /* All - Non-realtime version of FMOD_OUTPUTTYPE_NOSOUND. User can drive mixer with System::update at whatever rate they want. */ + FMOD_OUTPUTTYPE_WAVWRITER_NRT, /* All - Non-realtime version of FMOD_OUTPUTTYPE_WAVWRITER. User can drive mixer with System::update at whatever rate they want. */ + + FMOD_OUTPUTTYPE_DSOUND, /* Win32/Win64 - DirectSound output. (Default on Windows XP and below) */ + FMOD_OUTPUTTYPE_WINMM, /* Win32/Win64 - Windows Multimedia output. */ + FMOD_OUTPUTTYPE_WASAPI, /* Win32 - Windows Audio Session API. (Default on Windows Vista and above) */ + FMOD_OUTPUTTYPE_ASIO, /* Win32 - Low latency ASIO 2.0 driver. */ + FMOD_OUTPUTTYPE_OSS, /* Linux/Linux64 - Open Sound System output. (Default on Linux, third preference) */ + FMOD_OUTPUTTYPE_ALSA, /* Linux/Linux64 - Advanced Linux Sound Architecture output. (Default on Linux, second preference if available) */ + FMOD_OUTPUTTYPE_ESD, /* Linux/Linux64 - Enlightment Sound Daemon output. */ + FMOD_OUTPUTTYPE_PULSEAUDIO, /* Linux/Linux64 - PulseAudio output. (Default on Linux, first preference if available) */ + FMOD_OUTPUTTYPE_COREAUDIO, /* Mac - Macintosh CoreAudio output. (Default on Mac) */ + FMOD_OUTPUTTYPE_XBOX360, /* Xbox 360 - Native Xbox360 output. (Default on Xbox 360) */ + FMOD_OUTPUTTYPE_PSP, /* PSP - Native PSP output. (Default on PSP) */ + FMOD_OUTPUTTYPE_PS3, /* PS3 - Native PS3 output. (Default on PS3) */ + FMOD_OUTPUTTYPE_NGP, /* NGP - Native NGP output. (Default on NGP) */ + FMOD_OUTPUTTYPE_WII, /* Wii - Native Wii output. (Default on Wii) */ + FMOD_OUTPUTTYPE_3DS, /* 3DS - Native 3DS output (Default on 3DS) */ + FMOD_OUTPUTTYPE_AUDIOTRACK, /* Android - Java Audio Track output. (Default on Android 2.2 and below) */ + FMOD_OUTPUTTYPE_OPENSL, /* Android - OpenSL ES output. (Default on Android 2.3 and above) */ + FMOD_OUTPUTTYPE_NACL, /* Native Client - Native Client output. (Default on Native Client) */ + FMOD_OUTPUTTYPE_WIIU, /* Wii U - Native Wii U output. (Default on Wii U) */ + FMOD_OUTPUTTYPE_ASOUND, /* BlackBerry - Native BlackBerry asound output. (Default on BlackBerry) */ + + FMOD_OUTPUTTYPE_MAX, /* Maximum number of output types supported. */ + FMOD_OUTPUTTYPE_FORCEINT = 65536 /* Makes sure this enum is signed 32bit. */ +} FMOD_OUTPUTTYPE; + + +/* +[DEFINE] +[ + [NAME] + FMOD_CAPS + + [DESCRIPTION] + Bit fields to use with System::getDriverCaps to determine the capabilities of a card / output device. + + [REMARKS] + It is important to check FMOD_CAPS_HARDWARE_EMULATED on windows machines, to then adjust System::setDSPBufferSize to (1024, 10) to compensate for the higher latency. + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + System::getDriverCaps + System::setDSPBufferSize +] +*/ +#define FMOD_CAPS_NONE 0x00000000 /* Device has no special capabilities. */ +#define FMOD_CAPS_HARDWARE 0x00000001 /* Device supports hardware mixing. */ +#define FMOD_CAPS_HARDWARE_EMULATED 0x00000002 /* User has device set to 'Hardware acceleration = off' in control panel, and now extra 200ms latency is incurred. */ +#define FMOD_CAPS_OUTPUT_MULTICHANNEL 0x00000004 /* Device can do multichannel output, ie greater than 2 channels. */ +#define FMOD_CAPS_OUTPUT_FORMAT_PCM8 0x00000008 /* Device can output to 8bit integer PCM. */ +#define FMOD_CAPS_OUTPUT_FORMAT_PCM16 0x00000010 /* Device can output to 16bit integer PCM. */ +#define FMOD_CAPS_OUTPUT_FORMAT_PCM24 0x00000020 /* Device can output to 24bit integer PCM. */ +#define FMOD_CAPS_OUTPUT_FORMAT_PCM32 0x00000040 /* Device can output to 32bit integer PCM. */ +#define FMOD_CAPS_OUTPUT_FORMAT_PCMFLOAT 0x00000080 /* Device can output to 32bit floating point PCM. */ +#define FMOD_CAPS_REVERB_LIMITED 0x00002000 /* Device supports some form of limited hardware reverb, maybe parameterless and only selectable by environment. */ +#define FMOD_CAPS_LOOPBACK 0x00004000 /* Device is a loopback recording device */ +/* [DEFINE_END] */ + +/* +[DEFINE] +[ + [NAME] + FMOD_DEBUGLEVEL + + [DESCRIPTION] + Bit fields to use with FMOD::Debug_SetLevel / FMOD::Debug_GetLevel to control the level of tty debug output with logging versions of FMOD (fmodL). + + [REMARKS] + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + Debug_SetLevel + Debug_GetLevel +] +*/ +#define FMOD_DEBUG_LEVEL_NONE 0x00000000 +#define FMOD_DEBUG_LEVEL_LOG 0x00000001 /* Will display generic logging messages. */ +#define FMOD_DEBUG_LEVEL_ERROR 0x00000002 /* Will display errors. */ +#define FMOD_DEBUG_LEVEL_WARNING 0x00000004 /* Will display warnings that are not fatal. */ +#define FMOD_DEBUG_LEVEL_HINT 0x00000008 /* Will hint to you if there is something possibly better you could be doing. */ +#define FMOD_DEBUG_LEVEL_ALL 0x000000FF +#define FMOD_DEBUG_TYPE_MEMORY 0x00000100 /* Show FMOD memory related logging messages. */ +#define FMOD_DEBUG_TYPE_THREAD 0x00000200 /* Show FMOD thread related logging messages. */ +#define FMOD_DEBUG_TYPE_FILE 0x00000400 /* Show FMOD file system related logging messages. */ +#define FMOD_DEBUG_TYPE_NET 0x00000800 /* Show FMOD network related logging messages. */ +#define FMOD_DEBUG_TYPE_EVENT 0x00001000 /* Show FMOD Event related logging messages. */ +#define FMOD_DEBUG_TYPE_ALL 0x0000FFFF +#define FMOD_DEBUG_DISPLAY_TIMESTAMPS 0x01000000 /* Display the timestamp of the log entry in milliseconds. */ +#define FMOD_DEBUG_DISPLAY_LINENUMBERS 0x02000000 /* Display the FMOD Ex source code line numbers, for debugging purposes. */ +#define FMOD_DEBUG_DISPLAY_COMPRESS 0x04000000 /* If a message is repeated more than 5 times it will stop displaying it and instead display the number of times the message was logged. */ +#define FMOD_DEBUG_DISPLAY_THREAD 0x08000000 /* Display the thread ID of the calling function that caused this log entry to appear. */ +#define FMOD_DEBUG_DISPLAY_ALL 0x0F000000 +#define FMOD_DEBUG_ALL 0xFFFFFFFF +/* [DEFINE_END] */ + + +/* +[DEFINE] +[ + [NAME] + FMOD_MEMORY_TYPE + + [DESCRIPTION] + Bit fields for memory allocation type being passed into FMOD memory callbacks. + + [REMARKS] + Remember this is a bitfield. You may get more than 1 bit set (ie physical + persistent) so do not simply switch on the types! You must check each bit individually or clear out the bits that you do not want within the callback. + Bits can be excluded if you want during Memory_Initialize so that you never get them. + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + FMOD_MEMORY_ALLOCCALLBACK + FMOD_MEMORY_REALLOCCALLBACK + FMOD_MEMORY_FREECALLBACK + Memory_Initialize + +] +*/ +#define FMOD_MEMORY_NORMAL 0x00000000 /* Standard memory. */ +#define FMOD_MEMORY_STREAM_FILE 0x00000001 /* Stream file buffer, size controllable with System::setStreamBufferSize. */ +#define FMOD_MEMORY_STREAM_DECODE 0x00000002 /* Stream decode buffer, size controllable with FMOD_CREATESOUNDEXINFO::decodebuffersize. */ +#define FMOD_MEMORY_SAMPLEDATA 0x00000004 /* Sample data buffer. Raw audio data, usually PCM/MPEG/ADPCM/XMA data. */ +#define FMOD_MEMORY_DSP_OUTPUTBUFFER 0x00000008 /* DSP memory block allocated when more than 1 output exists on a DSP node. */ +#define FMOD_MEMORY_XBOX360_PHYSICAL 0x00100000 /* Requires XPhysicalAlloc / XPhysicalFree. */ +#define FMOD_MEMORY_PERSISTENT 0x00200000 /* Persistent memory. Memory will be freed when System::release is called. */ +#define FMOD_MEMORY_SECONDARY 0x00400000 /* Secondary memory. Allocation should be in secondary memory. For example RSX on the PS3. */ +#define FMOD_MEMORY_ALL 0xFFFFFFFF +/* [DEFINE_END] */ + + +/* +[ENUM] +[ + [DESCRIPTION] + These are speaker types defined for use with the System::setSpeakerMode or System::getSpeakerMode command. + + [REMARKS] + These are important notes on speaker modes in regards to sounds created with FMOD_SOFTWARE. + Note below the phrase 'sound channels' is used. These are the subchannels inside a sound, they are not related and + have nothing to do with the FMOD class "Channel". + For example a mono sound has 1 sound channel, a stereo sound has 2 sound channels, and an AC3 or 6 channel wav file have 6 "sound channels". + + FMOD_SPEAKERMODE_RAW + --------------------- + This mode is for output devices that are not specifically mono/stereo/quad/surround/5.1 or 7.1, but are multichannel. + Use System::setSoftwareFormat to specify the number of speakers you want to address, otherwise it will default to 2 (stereo). + Sound channels map to speakers sequentially, so a mono sound maps to output speaker 0, stereo sound maps to output speaker 0 & 1. + The user assumes knowledge of the speaker order. FMOD_SPEAKER enumerations may not apply, so raw channel indices should be used. + Multichannel sounds map input channels to output channels 1:1. + Channel::setPan and Channel::setSpeakerMix do not work. + Speaker levels must be manually set with Channel::setSpeakerLevels. + + FMOD_SPEAKERMODE_MONO + --------------------- + This mode is for a 1 speaker arrangement. + Panning does not work in this speaker mode. + Mono, stereo and multichannel sounds have each sound channel played on the one speaker unity. + Mix behavior for multichannel sounds can be set with Channel::setSpeakerLevels. + Channel::setSpeakerMix does not work. + + FMOD_SPEAKERMODE_STEREO + ----------------------- + This mode is for 2 speaker arrangements that have a left and right speaker. + - Mono sounds default to an even distribution between left and right. They can be panned with Channel::setPan. + - Stereo sounds default to the middle, or full left in the left speaker and full right in the right speaker. + - They can be cross faded with Channel::setPan. + - Multichannel sounds have each sound channel played on each speaker at unity. + - Mix behavior for multichannel sounds can be set with Channel::setSpeakerLevels. + - Channel::setSpeakerMix works but only front left and right parameters are used, the rest are ignored. + + FMOD_SPEAKERMODE_QUAD + ------------------------ + This mode is for 4 speaker arrangements that have a front left, front right, rear left and a rear right speaker. + - Mono sounds default to an even distribution between front left and front right. They can be panned with Channel::setPan. + - Stereo sounds default to the left sound channel played on the front left, and the right sound channel played on the front right. + - They can be cross faded with Channel::setPan. + - Multichannel sounds default to all of their sound channels being played on each speaker in order of input. + - Mix behavior for multichannel sounds can be set with Channel::setSpeakerLevels. + - Channel::setSpeakerMix works but side left, side right, center and lfe are ignored. + + FMOD_SPEAKERMODE_SURROUND + ------------------------ + This mode is for 5 speaker arrangements that have a left/right/center/rear left/rear right. + - Mono sounds default to the center speaker. They can be panned with Channel::setPan. + - Stereo sounds default to the left sound channel played on the front left, and the right sound channel played on the front right. + - They can be cross faded with Channel::setPan. + - Multichannel sounds default to all of their sound channels being played on each speaker in order of input. + - Mix behavior for multichannel sounds can be set with Channel::setSpeakerLevels. + - Channel::setSpeakerMix works but side left / side right are ignored. + + FMOD_SPEAKERMODE_5POINT1 + ------------------------ + This mode is for 5.1 speaker arrangements that have a left/right/center/rear left/rear right and a subwoofer speaker. + - Mono sounds default to the center speaker. They can be panned with Channel::setPan. + - Stereo sounds default to the left sound channel played on the front left, and the right sound channel played on the front right. + - They can be cross faded with Channel::setPan. + - Multichannel sounds default to all of their sound channels being played on each speaker in order of input. + - Mix behavior for multichannel sounds can be set with Channel::setSpeakerLevels. + - Channel::setSpeakerMix works but side left / side right are ignored. + + FMOD_SPEAKERMODE_7POINT1 + ------------------------ + This mode is for 7.1 speaker arrangements that have a left/right/center/rear left/rear right/side left/side right + and a subwoofer speaker. + - Mono sounds default to the center speaker. They can be panned with Channel::setPan. + - Stereo sounds default to the left sound channel played on the front left, and the right sound channel played on the front right. + - They can be cross faded with Channel::setPan. + - Multichannel sounds default to all of their sound channels being played on each speaker in order of input. + - Mix behavior for multichannel sounds can be set with Channel::setSpeakerLevels. + - Channel::setSpeakerMix works and every parameter is used to set the balance of a sound in any speaker. + + FMOD_SPEAKERMODE_SRS5_1_MATRIX + ------------------------------------------------------ + This mode is for mono, stereo, 5.1 and 6.1 speaker arrangements, as it is backwards and forwards compatible with + stereo, but to get a surround effect a SRS 5.1, Prologic or Prologic 2 hardware decoder / amplifier is needed or + a compatible SRS equipped device (e.g., laptop, TV, etc.) or accessory (e.g., headphone). + Pan behavior is the same as FMOD_SPEAKERMODE_5POINT1. + + If this function is called the numoutputchannels setting in System::setSoftwareFormat is overwritten. + + Output rate must be 44100, 48000 or 96000 for this to work otherwise FMOD_ERR_OUTPUT_INIT will be returned. + + FMOD_SPEAKERMODE_DOLBY5_1_MATRIX + ------------------------------------------------------ + This mode is for 5.1 speaker arrangements using a stereo signal, to get a surround effect a Dolby Pro Logic II + hardware decoder / amplifier is needed. + Pan behavior is the same as FMOD_SPEAKERMODE_5POINT1. + + If this function is called the numoutputchannels setting in System::setSoftwareFormat is overwritten. + + Output rate must be 32000, 44100 or 48000 for this to work otherwise FMOD_ERR_OUTPUT_INIT will be returned. + + FMOD_SPEAKERMODE_MYEARS + ------------------------------------------------------ + This mode is for headphones. This will attempt to load a MyEars profile (see myears.net.au) and use it to generate + surround sound on headphones using a personalized HRTF algorithm, for realistic 3d sound. + Pan behavior is the same as FMOD_SPEAKERMODE_7POINT1. + MyEars speaker mode will automatically be set if the speakermode is FMOD_SPEAKERMODE_STEREO and the MyEars profile exists. + If this mode is set explicitly, FMOD_INIT_DISABLE_MYEARS_AUTODETECT has no effect. + If this mode is set explicitly and the MyEars profile does not exist, FMOD_ERR_OUTPUT_DRIVERCALL will be returned. + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + System::setSpeakerMode + System::getSpeakerMode + System::getDriverCaps + System::setSoftwareFormat + Channel::setSpeakerLevels +] +*/ +typedef enum +{ + FMOD_SPEAKERMODE_RAW, /* There is no specific speakermode. Sound channels are mapped in order of input to output. Use System::setSoftwareFormat to specify speaker count. See remarks for more information. */ + FMOD_SPEAKERMODE_MONO, /* The speakers are monaural. */ + FMOD_SPEAKERMODE_STEREO, /* The speakers are stereo (DEFAULT). */ + FMOD_SPEAKERMODE_QUAD, /* 4 speaker setup. This includes front left, front right, rear left, rear right. */ + FMOD_SPEAKERMODE_SURROUND, /* 5 speaker setup. This includes front left, front right, center, rear left, rear right. */ + FMOD_SPEAKERMODE_5POINT1, /* 5.1 speaker setup. This includes front left, front right, center, rear left, rear right and a subwoofer. */ + FMOD_SPEAKERMODE_7POINT1, /* 7.1 speaker setup. This includes front left, front right, center, rear left, rear right, side left, side right and a subwoofer. */ + + FMOD_SPEAKERMODE_SRS5_1_MATRIX, /* Stereo compatible output, embedded with surround information. SRS 5.1/Prologic/Prologic2 decoders will split the signal into a 5.1 speaker set-up or SRS virtual surround will decode into a 2-speaker/headphone setup. See remarks about limitations.*/ + FMOD_SPEAKERMODE_DOLBY5_1_MATRIX, /* Stereo compatible output, embedded with surround information. Dolby Pro Logic II decoders will split the signal into a 5.1 speaker set-up. */ + FMOD_SPEAKERMODE_MYEARS, /* Stereo output, but data is encoded using personalized HRTF algorithms. See myears.net.au */ + + FMOD_SPEAKERMODE_MAX, /* Maximum number of speaker modes supported. */ + FMOD_SPEAKERMODE_FORCEINT = 65536 /* Makes sure this enum is signed 32bit. */ +} FMOD_SPEAKERMODE; + + +/* +[ENUM] +[ + [DESCRIPTION] + These are speaker types defined for use with the Channel::setSpeakerLevels command. + It can also be used for speaker placement in the System::set3DSpeakerPosition command. + + [REMARKS] + If you are using FMOD_SPEAKERMODE_RAW and speaker assignments are meaningless, just cast a raw integer value to this type. + For example (FMOD_SPEAKER)7 would use the 7th speaker (also the same as FMOD_SPEAKER_SIDE_RIGHT). + Values higher than this can be used if an output system has more than 8 speaker types / output channels. 15 is the current maximum. + + NOTE: On Playstation 3 in 7.1, the extra 2 speakers are not side left/side right, they are 'surround back left'/'surround back right' which + locate the speakers behind the listener instead of to the sides like on PC. FMOD_SPEAKER_SBL/FMOD_SPEAKER_SBR are provided to make it + clearer what speaker is being addressed on that platform. + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + FMOD_SPEAKERMODE + Channel::setSpeakerLevels + Channel::getSpeakerLevels + System::set3DSpeakerPosition + System::get3DSpeakerPosition +] +*/ +typedef enum +{ + FMOD_SPEAKER_FRONT_LEFT, + FMOD_SPEAKER_FRONT_RIGHT, + FMOD_SPEAKER_FRONT_CENTER, + FMOD_SPEAKER_LOW_FREQUENCY, + FMOD_SPEAKER_BACK_LEFT, + FMOD_SPEAKER_BACK_RIGHT, + FMOD_SPEAKER_SIDE_LEFT, + FMOD_SPEAKER_SIDE_RIGHT, + + FMOD_SPEAKER_MAX, /* Maximum number of speaker types supported. */ + FMOD_SPEAKER_MONO = FMOD_SPEAKER_FRONT_LEFT, /* For use with FMOD_SPEAKERMODE_MONO and Channel::SetSpeakerLevels. Mapped to same value as FMOD_SPEAKER_FRONT_LEFT. */ + FMOD_SPEAKER_NULL = 65535, /* A non speaker. Use this with ASIO mapping to ignore a speaker. */ + FMOD_SPEAKER_SBL = FMOD_SPEAKER_SIDE_LEFT, /* For use with FMOD_SPEAKERMODE_7POINT1 on PS3 where the extra speakers are surround back inside of side speakers. */ + FMOD_SPEAKER_SBR = FMOD_SPEAKER_SIDE_RIGHT, /* For use with FMOD_SPEAKERMODE_7POINT1 on PS3 where the extra speakers are surround back inside of side speakers. */ + FMOD_SPEAKER_FORCEINT = 65536 /* Makes sure this enum is signed 32bit. */ +} FMOD_SPEAKER; + + +/* +[ENUM] +[ + [DESCRIPTION] + These are plugin types defined for use with the System::getNumPlugins, + System::getPluginInfo and System::unloadPlugin functions. + + [REMARKS] + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + System::getNumPlugins + System::getPluginInfo + System::unloadPlugin +] +*/ +typedef enum +{ + FMOD_PLUGINTYPE_OUTPUT, /* The plugin type is an output module. FMOD mixed audio will play through one of these devices */ + FMOD_PLUGINTYPE_CODEC, /* The plugin type is a file format codec. FMOD will use these codecs to load file formats for playback. */ + FMOD_PLUGINTYPE_DSP, /* The plugin type is a DSP unit. FMOD will use these plugins as part of its DSP network to apply effects to output or generate sound in realtime. */ + + FMOD_PLUGINTYPE_MAX, /* Maximum number of plugin types supported. */ + FMOD_PLUGINTYPE_FORCEINT = 65536 /* Makes sure this enum is signed 32bit. */ +} FMOD_PLUGINTYPE; + + +/* +[DEFINE] +[ + [NAME] + FMOD_INITFLAGS + + [DESCRIPTION] + Initialization flags. Use them with System::init in the flags parameter to change various behavior. + + [REMARKS] + Use System::setAdvancedSettings to adjust settings for some of the features that are enabled by these flags. + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + System::init + System::update + System::setAdvancedSettings + Channel::set3DOcclusion +] +*/ +#define FMOD_INIT_NORMAL 0x00000000 /* All platforms - Initialize normally */ +#define FMOD_INIT_STREAM_FROM_UPDATE 0x00000001 /* All platforms - No stream thread is created internally. Streams are driven from System::update. Mainly used with non-realtime outputs. */ +#define FMOD_INIT_3D_RIGHTHANDED 0x00000002 /* All platforms - FMOD will treat +X as right, +Y as up and +Z as backwards (towards you). */ +#define FMOD_INIT_SOFTWARE_DISABLE 0x00000004 /* All platforms - Disable software mixer to save memory. Anything created with FMOD_SOFTWARE will fail and DSP will not work. */ +#define FMOD_INIT_OCCLUSION_LOWPASS 0x00000008 /* All platforms - All FMOD_SOFTWARE (and FMOD_HARDWARE on 3DS and NGP) with FMOD_3D based voices will add a software lowpass filter effect into the DSP chain which is automatically used when Channel::set3DOcclusion is used or the geometry API. */ +#define FMOD_INIT_HRTF_LOWPASS 0x00000010 /* All platforms - All FMOD_SOFTWARE (and FMOD_HARDWARE on 3DS and NGP) with FMOD_3D based voices will add a software lowpass filter effect into the DSP chain which causes sounds to sound duller when the sound goes behind the listener. Use System::setAdvancedSettings to adjust cutoff frequency. */ +#define FMOD_INIT_DISTANCE_FILTERING 0x00000200 /* All platforms - All FMOD_SOFTWARE with FMOD_3D based voices will add a software lowpass and highpass filter effect into the DSP chain which will act as a distance-automated bandpass filter. Use System::setAdvancedSettings to adjust the center frequency. */ +#define FMOD_INIT_REVERB_PREALLOCBUFFERS 0x00000040 /* All platforms - FMOD Software reverb will preallocate enough buffers for reverb per channel, rather than allocating them and freeing them at runtime. */ +#define FMOD_INIT_ENABLE_PROFILE 0x00000020 /* All platforms - Enable TCP/IP based host which allows FMOD Designer or FMOD Profiler to connect to it, and view memory, CPU and the DSP network graph in real-time. */ +#define FMOD_INIT_VOL0_BECOMES_VIRTUAL 0x00000080 /* All platforms - Any sounds that are 0 volume will go virtual and not be processed except for having their positions updated virtually. Use System::setAdvancedSettings to adjust what volume besides zero to switch to virtual at. */ +#define FMOD_INIT_WASAPI_EXCLUSIVE 0x00000100 /* Win32 Vista only - for WASAPI output - Enable exclusive access to hardware, lower latency at the expense of excluding other applications from accessing the audio hardware. */ +#define FMOD_INIT_PS3_PREFERDTS 0x00800000 /* PS3 only - Prefer DTS over Dolby Digital if both are supported. Note: 8 and 6 channel LPCM is always preferred over both DTS and Dolby Digital. */ +#define FMOD_INIT_PS3_FORCE2CHLPCM 0x01000000 /* PS3 only - Force PS3 system output mode to 2 channel LPCM. */ +#define FMOD_INIT_DISABLEDOLBY 0x00100000 /* Wii / 3DS - Disable Dolby Pro Logic surround. Speakermode will be set to STEREO even if user has selected surround in the system settings. */ +#define FMOD_INIT_SYSTEM_MUSICMUTENOTPAUSE 0x00200000 /* Xbox 360 / PS3 - The "music" channelgroup which by default pauses when custom 360 dashboard / PS3 BGM music is played, can be changed to mute (therefore continues playing) instead of pausing, by using this flag. */ +#define FMOD_INIT_SYNCMIXERWITHUPDATE 0x00400000 /* Win32/Wii/PS3/Xbox/Xbox 360 - FMOD Mixer thread is woken up to do a mix when System::update is called rather than waking periodically on its own timer. */ +#define FMOD_INIT_GEOMETRY_USECLOSEST 0x04000000 /* All platforms - With the geometry engine, only process the closest polygon rather than accumulating all polygons the sound to listener line intersects. */ +#define FMOD_INIT_DISABLE_MYEARS_AUTODETECT 0x08000000 /* Win32 - Disables automatic setting of FMOD_SPEAKERMODE_STEREO to FMOD_SPEAKERMODE_MYEARS if the MyEars profile exists on the PC. MyEars is HRTF 7.1 downmixing through headphones. */ +#define FMOD_INIT_PS3_DISABLEDTS 0x10000000 /* PS3 only - Disable DTS output mode selection */ +#define FMOD_INIT_PS3_DISABLEDOLBYDIGITAL 0x20000000 /* PS3 only - Disable Dolby Digital output mode selection */ +/* [DEFINE_END] */ + + +/* +[ENUM] +[ + [DESCRIPTION] + These definitions describe the type of song being played. + + [REMARKS] + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + Sound::getFormat +] +*/ +typedef enum +{ + FMOD_SOUND_TYPE_UNKNOWN, /* 3rd party / unknown plugin format. */ + FMOD_SOUND_TYPE_AIFF, /* AIFF. */ + FMOD_SOUND_TYPE_ASF, /* Microsoft Advanced Systems Format (ie WMA/ASF/WMV). */ + FMOD_SOUND_TYPE_AT3, /* Sony ATRAC 3 format */ + FMOD_SOUND_TYPE_CDDA, /* Digital CD audio. */ + FMOD_SOUND_TYPE_DLS, /* Sound font / downloadable sound bank. */ + FMOD_SOUND_TYPE_FLAC, /* FLAC lossless codec. */ + FMOD_SOUND_TYPE_FSB, /* FMOD Sample Bank. */ + FMOD_SOUND_TYPE_GCADPCM, /* Nintendo GameCube/Wii ADPCM */ + FMOD_SOUND_TYPE_IT, /* Impulse Tracker. */ + FMOD_SOUND_TYPE_MIDI, /* MIDI. extracodecdata is a pointer to an FMOD_MIDI_EXTRACODECDATA structure. */ + FMOD_SOUND_TYPE_MOD, /* Protracker / Fasttracker MOD. */ + FMOD_SOUND_TYPE_MPEG, /* MP2/MP3 MPEG. */ + FMOD_SOUND_TYPE_OGGVORBIS, /* Ogg vorbis. */ + FMOD_SOUND_TYPE_PLAYLIST, /* Information only from ASX/PLS/M3U/WAX playlists */ + FMOD_SOUND_TYPE_RAW, /* Raw PCM data. */ + FMOD_SOUND_TYPE_S3M, /* ScreamTracker 3. */ + FMOD_SOUND_TYPE_SF2, /* Sound font 2 format. */ + FMOD_SOUND_TYPE_USER, /* User created sound. */ + FMOD_SOUND_TYPE_WAV, /* Microsoft WAV. */ + FMOD_SOUND_TYPE_XM, /* FastTracker 2 XM. */ + FMOD_SOUND_TYPE_XMA, /* Xbox360 XMA */ + FMOD_SOUND_TYPE_VAG, /* PlayStation Portable ADPCM VAG format. */ + FMOD_SOUND_TYPE_AUDIOQUEUE, /* iPhone hardware decoder, supports AAC, ALAC and MP3. extracodecdata is a pointer to an FMOD_AUDIOQUEUE_EXTRACODECDATA structure. */ + FMOD_SOUND_TYPE_XWMA, /* Xbox360 XWMA */ + FMOD_SOUND_TYPE_BCWAV, /* 3DS BCWAV container format for DSP ADPCM and PCM */ + FMOD_SOUND_TYPE_AT9, /* NGP ATRAC 9 format */ + FMOD_SOUND_TYPE_VORBIS, /* Raw vorbis */ + FMOD_SOUND_TYPE_MEDIA_FOUNDATION,/* Microsoft Media Foundation wrappers, supports ASF/WMA */ + + FMOD_SOUND_TYPE_MAX, /* Maximum number of sound types supported. */ + FMOD_SOUND_TYPE_FORCEINT = 65536 /* Makes sure this enum is signed 32bit. */ +} FMOD_SOUND_TYPE; + + +/* +[ENUM] +[ + [DESCRIPTION] + These definitions describe the native format of the hardware or software buffer that will be used. + + [REMARKS] + This is the format the native hardware or software buffer will be or is created in. + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + System::createSound + Sound::getFormat +] +*/ +typedef enum +{ + FMOD_SOUND_FORMAT_NONE, /* Unitialized / unknown. */ + FMOD_SOUND_FORMAT_PCM8, /* 8bit integer PCM data. */ + FMOD_SOUND_FORMAT_PCM16, /* 16bit integer PCM data. */ + FMOD_SOUND_FORMAT_PCM24, /* 24bit integer PCM data. */ + FMOD_SOUND_FORMAT_PCM32, /* 32bit integer PCM data. */ + FMOD_SOUND_FORMAT_PCMFLOAT, /* 32bit floating point PCM data. */ + FMOD_SOUND_FORMAT_GCADPCM, /* Compressed Nintendo 3DS/Wii DSP data. */ + FMOD_SOUND_FORMAT_IMAADPCM, /* Compressed IMA ADPCM data. */ + FMOD_SOUND_FORMAT_VAG, /* Compressed PlayStation Portable ADPCM data. */ + FMOD_SOUND_FORMAT_HEVAG, /* Compressed PSVita ADPCM data. */ + FMOD_SOUND_FORMAT_XMA, /* Compressed Xbox360 XMA data. */ + FMOD_SOUND_FORMAT_MPEG, /* Compressed MPEG layer 2 or 3 data. */ + FMOD_SOUND_FORMAT_CELT, /* Compressed CELT data. */ + FMOD_SOUND_FORMAT_AT9, /* Compressed PSVita ATRAC9 data. */ + FMOD_SOUND_FORMAT_XWMA, /* Compressed Xbox360 xWMA data. */ + FMOD_SOUND_FORMAT_VORBIS, /* Compressed Vorbis data. */ + + FMOD_SOUND_FORMAT_MAX, /* Maximum number of sound formats supported. */ + FMOD_SOUND_FORMAT_FORCEINT = 65536 /* Makes sure this enum is signed 32bit. */ +} FMOD_SOUND_FORMAT; + + +/* +[DEFINE] +[ + [NAME] + FMOD_MODE + + [DESCRIPTION] + Sound description bitfields, bitwise OR them together for loading and describing sounds. + + [REMARKS] + By default a sound will open as a static sound that is decompressed fully into memory to PCM. (ie equivalent of FMOD_CREATESAMPLE) + To have a sound stream instead, use FMOD_CREATESTREAM, or use the wrapper function System::createStream. + Some opening modes (ie FMOD_OPENUSER, FMOD_OPENMEMORY, FMOD_OPENMEMORY_POINT, FMOD_OPENRAW) will need extra information. + This can be provided using the FMOD_CREATESOUNDEXINFO structure. + + Specifying FMOD_OPENMEMORY_POINT will POINT to your memory rather allocating its own sound buffers and duplicating it internally. + This means you cannot free the memory while FMOD is using it, until after Sound::release is called. + With FMOD_OPENMEMORY_POINT, for PCM formats, only WAV, FSB, and RAW are supported. For compressed formats, only those formats supported by FMOD_CREATECOMPRESSEDSAMPLE are supported. + With FMOD_OPENMEMORY_POINT and FMOD_OPENRAW or PCM, if using them together, note that you must pad the data on each side by 16 bytes. This is so fmod can modify the ends of the data for looping/interpolation/mixing purposes. If a wav file, you will need to insert silence, and then reset loop points to stop the playback from playing that silence. + With FMOD_OPENMEMORY_POINT, For Wii/PSP FMOD_HARDWARE supports this flag for the GCADPCM/VAG formats. On other platforms FMOD_SOFTWARE must be used. + + Xbox 360 memory On Xbox 360 Specifying FMOD_OPENMEMORY_POINT to a virtual memory address will cause FMOD_ERR_INVALID_ADDRESS + to be returned. Use physical memory only for this functionality. + + FMOD_LOWMEM is used on a sound if you want to minimize the memory overhead, by having FMOD not allocate memory for certain + features that are not likely to be used in a game environment. These are : + 1. Sound::getName functionality is removed. 256 bytes per sound is saved. + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + System::createSound + System::createStream + Sound::setMode + Sound::getMode + Channel::setMode + Channel::getMode + Sound::set3DCustomRolloff + Channel::set3DCustomRolloff + Sound::getOpenState +] +*/ +#define FMOD_DEFAULT 0x00000000 /* Default for all modes listed below. FMOD_LOOP_OFF, FMOD_2D, FMOD_HARDWARE */ +#define FMOD_LOOP_OFF 0x00000001 /* For non looping sounds. (DEFAULT). Overrides FMOD_LOOP_NORMAL / FMOD_LOOP_BIDI. */ +#define FMOD_LOOP_NORMAL 0x00000002 /* For forward looping sounds. */ +#define FMOD_LOOP_BIDI 0x00000004 /* For bidirectional looping sounds. (only works on software mixed static sounds). */ +#define FMOD_2D 0x00000008 /* Ignores any 3d processing. (DEFAULT). */ +#define FMOD_3D 0x00000010 /* Makes the sound positionable in 3D. Overrides FMOD_2D. */ +#define FMOD_HARDWARE 0x00000020 /* Attempts to make sounds use hardware acceleration. (DEFAULT). Note on platforms that don't support FMOD_HARDWARE (only 3DS, PS Vita, PSP, Wii and Wii U support FMOD_HARDWARE), this will be internally treated as FMOD_SOFTWARE. */ +#define FMOD_SOFTWARE 0x00000040 /* Makes the sound be mixed by the FMOD CPU based software mixer. Overrides FMOD_HARDWARE. Use this for FFT, DSP, compressed sample support, 2D multi-speaker support and other software related features. */ +#define FMOD_CREATESTREAM 0x00000080 /* Decompress at runtime, streaming from the source provided (ie from disk). Overrides FMOD_CREATESAMPLE and FMOD_CREATECOMPRESSEDSAMPLE. Note a stream can only be played once at a time due to a stream only having 1 stream buffer and file handle. Open multiple streams to have them play concurrently. */ +#define FMOD_CREATESAMPLE 0x00000100 /* Decompress at loadtime, decompressing or decoding whole file into memory as the target sample format (ie PCM). Fastest for FMOD_SOFTWARE based playback and most flexible. */ +#define FMOD_CREATECOMPRESSEDSAMPLE 0x00000200 /* Load MP2, MP3, IMAADPCM or XMA into memory and leave it compressed. During playback the FMOD software mixer will decode it in realtime as a 'compressed sample'. Can only be used in combination with FMOD_SOFTWARE. Overrides FMOD_CREATESAMPLE. If the sound data is not ADPCM, MPEG or XMA it will behave as if it was created with FMOD_CREATESAMPLE and decode the sound into PCM. */ +#define FMOD_OPENUSER 0x00000400 /* Opens a user created static sample or stream. Use FMOD_CREATESOUNDEXINFO to specify format and/or read callbacks. If a user created 'sample' is created with no read callback, the sample will be empty. Use Sound::lock and Sound::unlock to place sound data into the sound if this is the case. */ +#define FMOD_OPENMEMORY 0x00000800 /* "name_or_data" will be interpreted as a pointer to memory instead of filename for creating sounds. Use FMOD_CREATESOUNDEXINFO to specify length. If used with FMOD_CREATESAMPLE or FMOD_CREATECOMPRESSEDSAMPLE, FMOD duplicates the memory into its own buffers. Your own buffer can be freed after open. If used with FMOD_CREATESTREAM, FMOD will stream out of the buffer whose pointer you passed in. In this case, your own buffer should not be freed until you have finished with and released the stream.*/ +#define FMOD_OPENMEMORY_POINT 0x10000000 /* "name_or_data" will be interpreted as a pointer to memory instead of filename for creating sounds. Use FMOD_CREATESOUNDEXINFO to specify length. This differs to FMOD_OPENMEMORY in that it uses the memory as is, without duplicating the memory into its own buffers. For Wii/PSP FMOD_HARDWARE supports this flag for the GCADPCM/VAG formats. On other platforms FMOD_SOFTWARE must be used, as sound hardware on the other platforms (ie PC) cannot access main ram. Cannot be freed after open, only after Sound::release. Will not work if the data is compressed and FMOD_CREATECOMPRESSEDSAMPLE is not used. */ +#define FMOD_OPENRAW 0x00001000 /* Will ignore file format and treat as raw pcm. Use FMOD_CREATESOUNDEXINFO to specify format. Requires at least defaultfrequency, numchannels and format to be specified before it will open. Must be little endian data. */ +#define FMOD_OPENONLY 0x00002000 /* Just open the file, dont prebuffer or read. Good for fast opens for info, or when sound::readData is to be used. */ +#define FMOD_ACCURATETIME 0x00004000 /* For System::createSound - for accurate Sound::getLength/Channel::setPosition on VBR MP3, and MOD/S3M/XM/IT/MIDI files. Scans file first, so takes longer to open. FMOD_OPENONLY does not affect this. */ +#define FMOD_MPEGSEARCH 0x00008000 /* For corrupted / bad MP3 files. This will search all the way through the file until it hits a valid MPEG header. Normally only searches for 4k. */ +#define FMOD_NONBLOCKING 0x00010000 /* For opening sounds and getting streamed subsounds (seeking) asyncronously. Use Sound::getOpenState to poll the state of the sound as it opens or retrieves the subsound in the background. */ +#define FMOD_UNIQUE 0x00020000 /* Unique sound, can only be played one at a time */ +#define FMOD_3D_HEADRELATIVE 0x00040000 /* Make the sound's position, velocity and orientation relative to the listener. */ +#define FMOD_3D_WORLDRELATIVE 0x00080000 /* Make the sound's position, velocity and orientation absolute (relative to the world). (DEFAULT) */ +#define FMOD_3D_INVERSEROLLOFF 0x00100000 /* This sound will follow the inverse rolloff model where mindistance = full volume, maxdistance = where sound stops attenuating, and rolloff is fixed according to the global rolloff factor. (DEFAULT) */ +#define FMOD_3D_LINEARROLLOFF 0x00200000 /* This sound will follow a linear rolloff model where mindistance = full volume, maxdistance = silence. Rolloffscale is ignored. */ +#define FMOD_3D_LINEARSQUAREROLLOFF 0x00400000 /* This sound will follow a linear-square rolloff model where mindistance = full volume, maxdistance = silence. Rolloffscale is ignored. */ +#define FMOD_3D_CUSTOMROLLOFF 0x04000000 /* This sound will follow a rolloff model defined by Sound::set3DCustomRolloff / Channel::set3DCustomRolloff. */ +#define FMOD_3D_IGNOREGEOMETRY 0x40000000 /* Is not affect by geometry occlusion. If not specified in Sound::setMode, or Channel::setMode, the flag is cleared and it is affected by geometry again. */ +#define FMOD_UNICODE 0x01000000 /* Filename is double-byte unicode. */ +#define FMOD_IGNORETAGS 0x02000000 /* Skips id3v2/asf/etc tag checks when opening a sound, to reduce seek/read overhead when opening files (helps with CD performance). */ +#define FMOD_LOWMEM 0x08000000 /* Removes some features from samples to give a lower memory overhead, like Sound::getName. See remarks. */ +#define FMOD_LOADSECONDARYRAM 0x20000000 /* Load sound into the secondary RAM of supported platform. On PS3, sounds will be loaded into RSX/VRAM. */ +#define FMOD_VIRTUAL_PLAYFROMSTART 0x80000000 /* For sounds that start virtual (due to being quiet or low importance), instead of swapping back to audible, and playing at the correct offset according to time, this flag makes the sound play from the start. */ + +/* [DEFINE_END] */ + + +/* +[ENUM] +[ + [DESCRIPTION] + These values describe what state a sound is in after FMOD_NONBLOCKING has been used to open it. + + [REMARKS] + With streams, if you are using FMOD_NONBLOCKING, note that if the user calls Sound::getSubSound, a stream will go into FMOD_OPENSTATE_SEEKING state and sound related commands will return FMOD_ERR_NOTREADY. + With streams, if you are using FMOD_NONBLOCKING, note that if the user calls Channel::getPosition, a stream will go into FMOD_OPENSTATE_SETPOSITION state and sound related commands will return FMOD_ERR_NOTREADY. + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + Sound::getOpenState + FMOD_MODE +] +*/ +typedef enum +{ + FMOD_OPENSTATE_READY = 0, /* Opened and ready to play. */ + FMOD_OPENSTATE_LOADING, /* Initial load in progress. */ + FMOD_OPENSTATE_ERROR, /* Failed to open - file not found, out of memory etc. See return value of Sound::getOpenState for what happened. */ + FMOD_OPENSTATE_CONNECTING, /* Connecting to remote host (internet sounds only). */ + FMOD_OPENSTATE_BUFFERING, /* Buffering data. */ + FMOD_OPENSTATE_SEEKING, /* Seeking to subsound and re-flushing stream buffer. */ + FMOD_OPENSTATE_PLAYING, /* Ready and playing, but not possible to release at this time without stalling the main thread. */ + FMOD_OPENSTATE_SETPOSITION, /* Seeking within a stream to a different position. */ + + FMOD_OPENSTATE_MAX, /* Maximum number of open state types. */ + FMOD_OPENSTATE_FORCEINT = 65536 /* Makes sure this enum is signed 32bit. */ +} FMOD_OPENSTATE; + + +/* +[ENUM] +[ + [DESCRIPTION] + These flags are used with SoundGroup::setMaxAudibleBehavior to determine what happens when more sounds + are played than are specified with SoundGroup::setMaxAudible. + + [REMARKS] + When using FMOD_SOUNDGROUP_BEHAVIOR_MUTE, SoundGroup::setMuteFadeSpeed can be used to stop a sudden transition. + Instead, the time specified will be used to cross fade between the sounds that go silent and the ones that become audible. + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + SoundGroup::setMaxAudibleBehavior + SoundGroup::getMaxAudibleBehavior + SoundGroup::setMaxAudible + SoundGroup::getMaxAudible + SoundGroup::setMuteFadeSpeed + SoundGroup::getMuteFadeSpeed +] +*/ +typedef enum +{ + FMOD_SOUNDGROUP_BEHAVIOR_FAIL, /* Any sound played that puts the sound count over the SoundGroup::setMaxAudible setting, will simply fail during System::playSound. */ + FMOD_SOUNDGROUP_BEHAVIOR_MUTE, /* Any sound played that puts the sound count over the SoundGroup::setMaxAudible setting, will be silent, then if another sound in the group stops the sound that was silent before becomes audible again. */ + FMOD_SOUNDGROUP_BEHAVIOR_STEALLOWEST, /* Any sound played that puts the sound count over the SoundGroup::setMaxAudible setting, will steal the quietest / least important sound playing in the group. */ + + FMOD_SOUNDGROUP_BEHAVIOR_MAX, /* Maximum number of open state types. */ + FMOD_SOUNDGROUP_BEHAVIOR_FORCEINT = 65536 /* Makes sure this enum is signed 32bit. */ +} FMOD_SOUNDGROUP_BEHAVIOR; + + +/* +[ENUM] +[ + [DESCRIPTION] + These callback types are used with Channel::setCallback. + + [REMARKS] + Each callback has commanddata parameters passed as int unique to the type of callback. + See reference to FMOD_CHANNEL_CALLBACK to determine what they might mean for each type of callback. + + Note! Currently the user must call System::update for these callbacks to trigger! + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + Channel::setCallback + FMOD_CHANNEL_CALLBACK + System::update +] +*/ +typedef enum +{ + FMOD_CHANNEL_CALLBACKTYPE_END, /* Called when a sound ends. */ + FMOD_CHANNEL_CALLBACKTYPE_VIRTUALVOICE, /* Called when a voice is swapped out or swapped in. */ + FMOD_CHANNEL_CALLBACKTYPE_SYNCPOINT, /* Called when a syncpoint is encountered. Can be from wav file markers. */ + FMOD_CHANNEL_CALLBACKTYPE_OCCLUSION, /* Called when the channel has its geometry occlusion value calculated. Can be used to clamp or change the value. */ + + FMOD_CHANNEL_CALLBACKTYPE_MAX, /* Maximum number of callback types supported. */ + FMOD_CHANNEL_CALLBACKTYPE_FORCEINT = 65536 /* Makes sure this enum is signed 32bit. */ +} FMOD_CHANNEL_CALLBACKTYPE; + + +/* +[ENUM] +[ + [DESCRIPTION] + These callback types are used with System::setCallback. + + [REMARKS] + Each callback has commanddata parameters passed as void* unique to the type of callback. + See reference to FMOD_SYSTEM_CALLBACK to determine what they might mean for each type of callback. + + Note! Using FMOD_SYSTEM_CALLBACKTYPE_DEVICELISTCHANGED (on Mac only) requires the application to be running an event loop which will allow external changes to device list to be detected by FMOD. + + Note! The 'system' object pointer will be null for FMOD_SYSTEM_CALLBACKTYPE_THREADCREATED and FMOD_SYSTEM_CALLBACKTYPE_MEMORYALLOCATIONFAILED callbacks. + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + System::setCallback + FMOD_SYSTEM_CALLBACK + System::update + DSP::addInput +] +*/ +typedef enum +{ + FMOD_SYSTEM_CALLBACKTYPE_DEVICELISTCHANGED, /* Called from System::update when the enumerated list of devices has changed. */ + FMOD_SYSTEM_CALLBACKTYPE_DEVICELOST, /* Called from System::update when an output device has been lost due to control panel parameter changes and FMOD cannot automatically recover. */ + FMOD_SYSTEM_CALLBACKTYPE_MEMORYALLOCATIONFAILED, /* Called directly when a memory allocation fails somewhere in FMOD. (NOTE - 'system' will be NULL in this callback type.)*/ + FMOD_SYSTEM_CALLBACKTYPE_THREADCREATED, /* Called directly when a thread is created. (NOTE - 'system' will be NULL in this callback type.) */ + FMOD_SYSTEM_CALLBACKTYPE_BADDSPCONNECTION, /* Called when a bad connection was made with DSP::addInput. Usually called from mixer thread because that is where the connections are made. */ + FMOD_SYSTEM_CALLBACKTYPE_BADDSPLEVEL, /* Called when too many effects were added exceeding the maximum tree depth of 128. This is most likely caused by accidentally adding too many DSP effects. Usually called from mixer thread because that is where the connections are made. */ + + FMOD_SYSTEM_CALLBACKTYPE_MAX, /* Maximum number of callback types supported. */ + FMOD_SYSTEM_CALLBACKTYPE_FORCEINT = 65536 /* Makes sure this enum is signed 32bit. */ +} FMOD_SYSTEM_CALLBACKTYPE; + + +/* + FMOD Callbacks +*/ +typedef FMOD_RESULT (F_CALLBACK *FMOD_SYSTEM_CALLBACK) (FMOD_SYSTEM *system, FMOD_SYSTEM_CALLBACKTYPE type, void *commanddata1, void *commanddata2); + +typedef FMOD_RESULT (F_CALLBACK *FMOD_CHANNEL_CALLBACK) (FMOD_CHANNEL *channel, FMOD_CHANNEL_CALLBACKTYPE type, void *commanddata1, void *commanddata2); + +typedef FMOD_RESULT (F_CALLBACK *FMOD_SOUND_NONBLOCKCALLBACK)(FMOD_SOUND *sound, FMOD_RESULT result); +typedef FMOD_RESULT (F_CALLBACK *FMOD_SOUND_PCMREADCALLBACK)(FMOD_SOUND *sound, void *data, unsigned int datalen); +typedef FMOD_RESULT (F_CALLBACK *FMOD_SOUND_PCMSETPOSCALLBACK)(FMOD_SOUND *sound, int subsound, unsigned int position, FMOD_TIMEUNIT postype); + +typedef FMOD_RESULT (F_CALLBACK *FMOD_FILE_OPENCALLBACK) (const char *name, int unicode, unsigned int *filesize, void **handle, void **userdata); +typedef FMOD_RESULT (F_CALLBACK *FMOD_FILE_CLOSECALLBACK) (void *handle, void *userdata); +typedef FMOD_RESULT (F_CALLBACK *FMOD_FILE_READCALLBACK) (void *handle, void *buffer, unsigned int sizebytes, unsigned int *bytesread, void *userdata); +typedef FMOD_RESULT (F_CALLBACK *FMOD_FILE_SEEKCALLBACK) (void *handle, unsigned int pos, void *userdata); +typedef FMOD_RESULT (F_CALLBACK *FMOD_FILE_ASYNCREADCALLBACK)(FMOD_ASYNCREADINFO *info, void *userdata); +typedef FMOD_RESULT (F_CALLBACK *FMOD_FILE_ASYNCCANCELCALLBACK)(void *handle, void *userdata); + +typedef void * (F_CALLBACK *FMOD_MEMORY_ALLOCCALLBACK) (unsigned int size, FMOD_MEMORY_TYPE type, const char *sourcestr); +typedef void * (F_CALLBACK *FMOD_MEMORY_REALLOCCALLBACK)(void *ptr, unsigned int size, FMOD_MEMORY_TYPE type, const char *sourcestr); +typedef void (F_CALLBACK *FMOD_MEMORY_FREECALLBACK) (void *ptr, FMOD_MEMORY_TYPE type, const char *sourcestr); + +typedef float (F_CALLBACK *FMOD_3D_ROLLOFFCALLBACK) (FMOD_CHANNEL *channel, float distance); + + +/* +[ENUM] +[ + [DESCRIPTION] + List of windowing methods used in spectrum analysis to reduce leakage / transient signals intefering with the analysis. + This is a problem with analysis of continuous signals that only have a small portion of the signal sample (the fft window size). + Windowing the signal with a curve or triangle tapers the sides of the fft window to help alleviate this problem. + + [REMARKS] + Cyclic signals such as a sine wave that repeat their cycle in a multiple of the window size do not need windowing. + I.e. If the sine wave repeats every 1024, 512, 256 etc samples and the FMOD fft window is 1024, then the signal would not need windowing. + Not windowing is the same as FMOD_DSP_FFT_WINDOW_RECT, which is the default. + If the cycle of the signal (ie the sine wave) is not a multiple of the window size, it will cause frequency abnormalities, so a different windowing method is needed. + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + System::getSpectrum + Channel::getSpectrum +] +*/ +typedef enum +{ + FMOD_DSP_FFT_WINDOW_RECT, /* w[n] = 1.0 */ + FMOD_DSP_FFT_WINDOW_TRIANGLE, /* w[n] = TRI(2n/N) */ + FMOD_DSP_FFT_WINDOW_HAMMING, /* w[n] = 0.54 - (0.46 * COS(n/N) ) */ + FMOD_DSP_FFT_WINDOW_HANNING, /* w[n] = 0.5 * (1.0 - COS(n/N) ) */ + FMOD_DSP_FFT_WINDOW_BLACKMAN, /* w[n] = 0.42 - (0.5 * COS(n/N) ) + (0.08 * COS(2.0 * n/N) ) */ + FMOD_DSP_FFT_WINDOW_BLACKMANHARRIS, /* w[n] = 0.35875 - (0.48829 * COS(1.0 * n/N)) + (0.14128 * COS(2.0 * n/N)) - (0.01168 * COS(3.0 * n/N)) */ + + FMOD_DSP_FFT_WINDOW_MAX, /* Maximum number of FFT window types supported. */ + FMOD_DSP_FFT_WINDOW_FORCEINT = 65536 /* Makes sure this enum is signed 32bit. */ +} FMOD_DSP_FFT_WINDOW; + + +/* +[ENUM] +[ + [DESCRIPTION] + List of interpolation types that the FMOD Ex software mixer supports. + + [REMARKS] + The default resampler type is FMOD_DSP_RESAMPLER_LINEAR. + Use System::setSoftwareFormat to tell FMOD the resampling quality you require for FMOD_SOFTWARE based sounds. + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + System::setSoftwareFormat + System::getSoftwareFormat +] +*/ +typedef enum +{ + FMOD_DSP_RESAMPLER_NOINTERP, /* No interpolation. High frequency aliasing hiss will be audible depending on the sample rate of the sound. */ + FMOD_DSP_RESAMPLER_LINEAR, /* Linear interpolation (default method). Fast and good quality, causes very slight lowpass effect on low frequency sounds. */ + FMOD_DSP_RESAMPLER_CUBIC, /* Cubic interpolation. Slower than linear interpolation but better quality. */ + FMOD_DSP_RESAMPLER_SPLINE, /* 5 point spline interpolation. Slowest resampling method but best quality. */ + + FMOD_DSP_RESAMPLER_MAX, /* Maximum number of resample methods supported. */ + FMOD_DSP_RESAMPLER_FORCEINT = 65536 /* Makes sure this enum is signed 32bit. */ +} FMOD_DSP_RESAMPLER; + + +/* +[ENUM] +[ + [DESCRIPTION] + List of tag types that could be stored within a sound. These include id3 tags, metadata from netstreams and vorbis/asf data. + + [REMARKS] + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + Sound::getTag +] +*/ +typedef enum +{ + FMOD_TAGTYPE_UNKNOWN = 0, + FMOD_TAGTYPE_ID3V1, + FMOD_TAGTYPE_ID3V2, + FMOD_TAGTYPE_VORBISCOMMENT, + FMOD_TAGTYPE_SHOUTCAST, + FMOD_TAGTYPE_ICECAST, + FMOD_TAGTYPE_ASF, + FMOD_TAGTYPE_MIDI, + FMOD_TAGTYPE_PLAYLIST, + FMOD_TAGTYPE_FMOD, + FMOD_TAGTYPE_USER, + + FMOD_TAGTYPE_MAX, /* Maximum number of tag types supported. */ + FMOD_TAGTYPE_FORCEINT = 65536 /* Makes sure this enum is signed 32bit. */ +} FMOD_TAGTYPE; + + +/* +[ENUM] +[ + [DESCRIPTION] + List of data types that can be returned by Sound::getTag + + [REMARKS] + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + Sound::getTag +] +*/ +typedef enum +{ + FMOD_TAGDATATYPE_BINARY = 0, + FMOD_TAGDATATYPE_INT, + FMOD_TAGDATATYPE_FLOAT, + FMOD_TAGDATATYPE_STRING, + FMOD_TAGDATATYPE_STRING_UTF16, + FMOD_TAGDATATYPE_STRING_UTF16BE, + FMOD_TAGDATATYPE_STRING_UTF8, + FMOD_TAGDATATYPE_CDTOC, + + FMOD_TAGDATATYPE_MAX, /* Maximum number of tag datatypes supported. */ + FMOD_TAGDATATYPE_FORCEINT = 65536 /* Makes sure this enum is signed 32bit. */ +} FMOD_TAGDATATYPE; + + +/* +[ENUM] +[ + [DESCRIPTION] + Types of delay that can be used with Channel::setDelay / Channel::getDelay. + + [REMARKS] + If you haven't called Channel::setDelay yet, if you call Channel::getDelay with FMOD_DELAYTYPE_DSPCLOCK_START it will return the + equivalent global DSP clock value to determine when a channel started, so that you can use it for other channels to sync against. + + Use System::getDSPClock to also get the current dspclock time, a base for future calls to Channel::setDelay. + + Use FMOD_64BIT_ADD or FMOD_64BIT_SUB to add a hi/lo combination together and cope with wraparound. + + If FMOD_DELAYTYPE_END_MS is specified, the value is not treated as a 64 bit number, just the delayhi value is used and it is treated as milliseconds. + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + Channel::setDelay + Channel::getDelay + System::getDSPClock +] +*/ +typedef enum +{ + FMOD_DELAYTYPE_END_MS, /* Delay at the end of the sound in milliseconds. Use delayhi only. Channel::isPlaying will remain true until this delay has passed even though the sound itself has stopped playing.*/ + FMOD_DELAYTYPE_DSPCLOCK_START, /* Time the sound started if Channel::getDelay is used, or if Channel::setDelay is used, the sound will delay playing until this exact tick. */ + FMOD_DELAYTYPE_DSPCLOCK_END, /* Time the sound should end. If this is non-zero, the channel will go silent at this exact tick. */ + FMOD_DELAYTYPE_DSPCLOCK_PAUSE, /* Time the sound should pause. If this is non-zero, the channel will pause at this exact tick. */ + + FMOD_DELAYTYPE_MAX, /* Maximum number of tag datatypes supported. */ + FMOD_DELAYTYPE_FORCEINT = 65536 /* Makes sure this enum is signed 32bit. */ +} FMOD_DELAYTYPE; + + +#define FMOD_64BIT_ADD(_hi1, _lo1, _hi2, _lo2) _hi1 += ((_hi2) + ((((_lo1) + (_lo2)) < (_lo1)) ? 1 : 0)); (_lo1) += (_lo2); +#define FMOD_64BIT_SUB(_hi1, _lo1, _hi2, _lo2) _hi1 -= ((_hi2) + ((((_lo1) - (_lo2)) > (_lo1)) ? 1 : 0)); (_lo1) -= (_lo2); + + +/* +[STRUCTURE] +[ + [DESCRIPTION] + Structure describing a piece of tag data. + + [REMARKS] + Members marked with [r] mean the variable is modified by FMOD and is for reading purposes only. Do not change this value. + Members marked with [w] mean the variable can be written to. The user can set the value. + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + Sound::getTag + FMOD_TAGTYPE + FMOD_TAGDATATYPE +] +*/ +typedef struct FMOD_TAG +{ + FMOD_TAGTYPE type; /* [r] The type of this tag. */ + FMOD_TAGDATATYPE datatype; /* [r] The type of data that this tag contains */ + char *name; /* [r] The name of this tag i.e. "TITLE", "ARTIST" etc. */ + void *data; /* [r] Pointer to the tag data - its format is determined by the datatype member */ + unsigned int datalen; /* [r] Length of the data contained in this tag */ + FMOD_BOOL updated; /* [r] True if this tag has been updated since last being accessed with Sound::getTag */ +} FMOD_TAG; + + +/* +[STRUCTURE] +[ + [DESCRIPTION] + Structure describing a CD/DVD table of contents + + [REMARKS] + Members marked with [r] mean the variable is modified by FMOD and is for reading purposes only. Do not change this value. + Members marked with [w] mean the variable can be written to. The user can set the value. + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + Sound::getTag +] +*/ +typedef struct FMOD_CDTOC +{ + int numtracks; /* [r] The number of tracks on the CD */ + int min[100]; /* [r] The start offset of each track in minutes */ + int sec[100]; /* [r] The start offset of each track in seconds */ + int frame[100]; /* [r] The start offset of each track in frames */ +} FMOD_CDTOC; + + +/* +[DEFINE] +[ + [NAME] + FMOD_TIMEUNIT + + [DESCRIPTION] + List of time types that can be returned by Sound::getLength and used with Channel::setPosition or Channel::getPosition. + + [REMARKS] + FMOD_TIMEUNIT_SENTENCE_MS, FMOD_TIMEUNIT_SENTENCE_PCM, FMOD_TIMEUNIT_SENTENCE_PCMBYTES, FMOD_TIMEUNIT_SENTENCE and FMOD_TIMEUNIT_SENTENCE_SUBSOUND are only supported by Channel functions. + Do not combine flags except FMOD_TIMEUNIT_BUFFERED. + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + Sound::getLength + Channel::setPosition + Channel::getPosition +] +*/ +#define FMOD_TIMEUNIT_MS 0x00000001 /* Milliseconds. */ +#define FMOD_TIMEUNIT_PCM 0x00000002 /* PCM samples, related to milliseconds * samplerate / 1000. */ +#define FMOD_TIMEUNIT_PCMBYTES 0x00000004 /* Bytes, related to PCM samples * channels * datawidth (ie 16bit = 2 bytes). */ +#define FMOD_TIMEUNIT_RAWBYTES 0x00000008 /* Raw file bytes of (compressed) sound data (does not include headers). Only used by Sound::getLength and Channel::getPosition. */ +#define FMOD_TIMEUNIT_PCMFRACTION 0x00000010 /* Fractions of 1 PCM sample. Unsigned int range 0 to 0xFFFFFFFF. Used for sub-sample granularity for DSP purposes. */ +#define FMOD_TIMEUNIT_MODORDER 0x00000100 /* MOD/S3M/XM/IT. Order in a sequenced module format. Use Sound::getFormat to determine the PCM format being decoded to. */ +#define FMOD_TIMEUNIT_MODROW 0x00000200 /* MOD/S3M/XM/IT. Current row in a sequenced module format. Sound::getLength will return the number of rows in the currently playing or seeked to pattern. */ +#define FMOD_TIMEUNIT_MODPATTERN 0x00000400 /* MOD/S3M/XM/IT. Current pattern in a sequenced module format. Sound::getLength will return the number of patterns in the song and Channel::getPosition will return the currently playing pattern. */ +#define FMOD_TIMEUNIT_SENTENCE_MS 0x00010000 /* Currently playing subsound in a sentence time in milliseconds. */ +#define FMOD_TIMEUNIT_SENTENCE_PCM 0x00020000 /* Currently playing subsound in a sentence time in PCM Samples, related to milliseconds * samplerate / 1000. */ +#define FMOD_TIMEUNIT_SENTENCE_PCMBYTES 0x00040000 /* Currently playing subsound in a sentence time in bytes, related to PCM samples * channels * datawidth (ie 16bit = 2 bytes). */ +#define FMOD_TIMEUNIT_SENTENCE 0x00080000 /* Currently playing sentence index according to the channel. */ +#define FMOD_TIMEUNIT_SENTENCE_SUBSOUND 0x00100000 /* Currently playing subsound index in a sentence. */ +#define FMOD_TIMEUNIT_BUFFERED 0x10000000 /* Time value as seen by buffered stream. This is always ahead of audible time, and is only used for processing. */ +/* [DEFINE_END] */ + + +/* +[ENUM] +[ + [DESCRIPTION] + When creating a multichannel sound, FMOD will pan them to their default speaker locations, for example a 6 channel sound will default to one channel per 5.1 output speaker. + Another example is a stereo sound. It will default to left = front left, right = front right. + + This is for sounds that are not 'default'. For example you might have a sound that is 6 channels but actually made up of 3 stereo pairs, that should all be located in front left, front right only. + + [REMARKS] + For full flexibility of speaker assignments, use Channel::setSpeakerLevels. + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + FMOD_CREATESOUNDEXINFO + Channel::setSpeakerLevels +] +*/ +typedef enum +{ + FMOD_SPEAKERMAPTYPE_DEFAULT, /* This is the default, and just means FMOD decides which speakers it puts the source channels. */ + FMOD_SPEAKERMAPTYPE_ALLMONO, /* This means the sound is made up of all mono sounds. All voices will be panned to the front center by default in this case. */ + FMOD_SPEAKERMAPTYPE_ALLSTEREO, /* This means the sound is made up of all stereo sounds. All voices will be panned to front left and front right alternating every second channel. */ + FMOD_SPEAKERMAPTYPE_51_PROTOOLS /* Map a 5.1 sound to use protools L C R Ls Rs LFE mapping. Will return an error if not a 6 channel sound. */ +} FMOD_SPEAKERMAPTYPE; + + +/* +[STRUCTURE] +[ + [DESCRIPTION] + Use this structure with System::createSound when more control is needed over loading. + The possible reasons to use this with System::createSound are: + - Loading a file from memory. + - Loading a file from within another larger (possibly wad/pak) file, by giving the loader an offset and length. + - To create a user created / non file based sound. + - To specify a starting subsound to seek to within a multi-sample sounds (ie FSB/DLS/SF2) when created as a stream. + - To specify which subsounds to load for multi-sample sounds (ie FSB/DLS/SF2) so that memory is saved and only a subset is actually loaded/read from disk. + - To specify 'piggyback' read and seek callbacks for capture of sound data as fmod reads and decodes it. Useful for ripping decoded PCM data from sounds as they are loaded / played. + - To specify a MIDI DLS/SF2 sample set file to load when opening a MIDI file. + See below on what members to fill for each of the above types of sound you want to create. + + [REMARKS] + This structure is optional! Specify 0 or NULL in System::createSound if you don't need it! + + Loading a file from memory. + - Create the sound using the FMOD_OPENMEMORY flag. + - Mandatory. Specify 'length' for the size of the memory block in bytes. + - Other flags are optional. + + + Loading a file from within another larger (possibly wad/pak) file, by giving the loader an offset and length. + - Mandatory. Specify 'fileoffset' and 'length'. + - Other flags are optional. + + + To create a user created / non file based sound. + - Create the sound using the FMOD_OPENUSER flag. + - Mandatory. Specify 'defaultfrequency, 'numchannels' and 'format'. + - Other flags are optional. + + + To specify a starting subsound to seek to and flush with, within a multi-sample stream (ie FSB/DLS/SF2). + + - Mandatory. Specify 'initialsubsound'. + + + To specify which subsounds to load for multi-sample sounds (ie FSB/DLS/SF2) so that memory is saved and only a subset is actually loaded/read from disk. + + - Mandatory. Specify 'inclusionlist' and 'inclusionlistnum'. + + + To specify 'piggyback' read and seek callbacks for capture of sound data as fmod reads and decodes it. Useful for ripping decoded PCM data from sounds as they are loaded / played. + + - Mandatory. Specify 'pcmreadcallback' and 'pcmseekcallback'. + + + To specify a MIDI DLS/SF2 sample set file to load when opening a MIDI file. + + - Mandatory. Specify 'dlsname'. + + + Setting the 'decodebuffersize' is for cpu intensive codecs that may be causing stuttering, not file intensive codecs (ie those from CD or netstreams) which are normally + altered with System::setStreamBufferSize. As an example of cpu intensive codecs, an mp3 file will take more cpu to decode than a PCM wav file. + If you have a stuttering effect, then it is using more cpu than the decode buffer playback rate can keep up with. Increasing the decode buffersize will most likely solve this problem. + + + FSB codec. If inclusionlist and numsubsounds are used together, this will trigger a special mode where subsounds are shuffled down to save memory. (useful for large FSB + files where you only want to load 1 sound). There will be no gaps, ie no null subsounds. As an example, if there are 10,000 subsounds and there is an inclusionlist with only 1 entry, + and numsubsounds = 1, then subsound 0 will be that entry, and there will only be the memory allocated for 1 subsound. Previously there would still be 10,000 subsound pointers and other + associated codec entries allocated along with it multiplied by 10,000. + + Members marked with [r] mean the variable is modified by FMOD and is for reading purposes only. Do not change this value. + Members marked with [w] mean the variable can be written to. The user can set the value. + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + System::createSound + System::setStreamBufferSize + FMOD_MODE + FMOD_SOUND_FORMAT + FMOD_SOUND_TYPE + FMOD_SPEAKERMAPTYPE +] +*/ +typedef struct FMOD_CREATESOUNDEXINFO +{ + int cbsize; /* [w] Size of this structure. This is used so the structure can be expanded in the future and still work on older versions of FMOD Ex. */ + unsigned int length; /* [w] Optional. Specify 0 to ignore. Size in bytes of file to load, or sound to create (in this case only if FMOD_OPENUSER is used). Required if loading from memory. If 0 is specified, then it will use the size of the file (unless loading from memory then an error will be returned). */ + unsigned int fileoffset; /* [w] Optional. Specify 0 to ignore. Offset from start of the file to start loading from. This is useful for loading files from inside big data files. */ + int numchannels; /* [w] Optional. Specify 0 to ignore. Number of channels in a sound mandatory if FMOD_OPENUSER or FMOD_OPENRAW is used. */ + int defaultfrequency; /* [w] Optional. Specify 0 to ignore. Default frequency of sound in a sound mandatory if FMOD_OPENUSER or FMOD_OPENRAW is used. Other formats use the frequency determined by the file format. */ + FMOD_SOUND_FORMAT format; /* [w] Optional. Specify 0 or FMOD_SOUND_FORMAT_NONE to ignore. Format of the sound mandatory if FMOD_OPENUSER or FMOD_OPENRAW is used. Other formats use the format determined by the file format. */ + unsigned int decodebuffersize; /* [w] Optional. Specify 0 to ignore. For streams. This determines the size of the double buffer (in PCM samples) that a stream uses. Use this for user created streams if you want to determine the size of the callback buffer passed to you. Specify 0 to use FMOD's default size which is currently equivalent to 400ms of the sound format created/loaded. */ + int initialsubsound; /* [w] Optional. Specify 0 to ignore. In a multi-sample file format such as .FSB/.DLS/.SF2, specify the initial subsound to seek to, only if FMOD_CREATESTREAM is used. */ + int numsubsounds; /* [w] Optional. Specify 0 to ignore or have no subsounds. In a sound created with FMOD_OPENUSER, specify the number of subsounds that are accessable with Sound::getSubSound. If not created with FMOD_OPENUSER, this will limit the number of subsounds loaded within a multi-subsound file. If using FSB, then if FMOD_CREATESOUNDEXINFO::inclusionlist is used, this will shuffle subsounds down so that there are not any gaps. It will mean that the indices of the sounds will be different. */ + int *inclusionlist; /* [w] Optional. Specify 0 to ignore. In a multi-sample format such as .FSB/.DLS/.SF2 it may be desirable to specify only a subset of sounds to be loaded out of the whole file. This is an array of subsound indices to load into memory when created. */ + int inclusionlistnum; /* [w] Optional. Specify 0 to ignore. This is the number of integers contained within the inclusionlist array. */ + FMOD_SOUND_PCMREADCALLBACK pcmreadcallback; /* [w] Optional. Specify 0 to ignore. Callback to 'piggyback' on FMOD's read functions and accept or even write PCM data while FMOD is opening the sound. Used for user sounds created with FMOD_OPENUSER or for capturing decoded data as FMOD reads it. */ + FMOD_SOUND_PCMSETPOSCALLBACK pcmsetposcallback; /* [w] Optional. Specify 0 to ignore. Callback for when the user calls a seeking function such as Channel::setTime or Channel::setPosition within a multi-sample sound, and for when it is opened.*/ + FMOD_SOUND_NONBLOCKCALLBACK nonblockcallback; /* [w] Optional. Specify 0 to ignore. Callback for successful completion, or error while loading a sound that used the FMOD_NONBLOCKING flag.*/ + const char *dlsname; /* [w] Optional. Specify 0 to ignore. Filename for a DLS or SF2 sample set when loading a MIDI file. If not specified, on Windows it will attempt to open /windows/system32/drivers/gm.dls or /windows/system32/drivers/etc/gm.dls, on Mac it will attempt to load /System/Library/Components/CoreAudio.component/Contents/Resources/gs_instruments.dls, otherwise the MIDI will fail to open. Current DLS support is for level 1 of the specification. */ + const char *encryptionkey; /* [w] Optional. Specify 0 to ignore. Key for encrypted FSB file. Without this key an encrypted FSB file will not load. */ + int maxpolyphony; /* [w] Optional. Specify 0 to ignore. For sequenced formats with dynamic channel allocation such as .MID and .IT, this specifies the maximum voice count allowed while playing. .IT defaults to 64. .MID defaults to 32. */ + void *userdata; /* [w] Optional. Specify 0 to ignore. This is user data to be attached to the sound during creation. Access via Sound::getUserData. Note: This is not passed to FMOD_FILE_OPENCALLBACK, that is a different userdata that is file specific. */ + FMOD_SOUND_TYPE suggestedsoundtype; /* [w] Optional. Specify 0 or FMOD_SOUND_TYPE_UNKNOWN to ignore. Instead of scanning all codec types, use this to speed up loading by making it jump straight to this codec. */ + FMOD_FILE_OPENCALLBACK useropen; /* [w] Optional. Specify 0 to ignore. Callback for opening this file. */ + FMOD_FILE_CLOSECALLBACK userclose; /* [w] Optional. Specify 0 to ignore. Callback for closing this file. */ + FMOD_FILE_READCALLBACK userread; /* [w] Optional. Specify 0 to ignore. Callback for reading from this file. */ + FMOD_FILE_SEEKCALLBACK userseek; /* [w] Optional. Specify 0 to ignore. Callback for seeking within this file. */ + FMOD_FILE_ASYNCREADCALLBACK userasyncread; /* [w] Optional. Specify 0 to ignore. Callback for seeking within this file. */ + FMOD_FILE_ASYNCCANCELCALLBACK userasynccancel; /* [w] Optional. Specify 0 to ignore. Callback for seeking within this file. */ + FMOD_SPEAKERMAPTYPE speakermap; /* [w] Optional. Specify 0 to ignore. Use this to differ the way fmod maps multichannel sounds to speakers. See FMOD_SPEAKERMAPTYPE for more. */ + FMOD_SOUNDGROUP *initialsoundgroup; /* [w] Optional. Specify 0 to ignore. Specify a sound group if required, to put sound in as it is created. */ + unsigned int initialseekposition;/* [w] Optional. Specify 0 to ignore. For streams. Specify an initial position to seek the stream to. */ + FMOD_TIMEUNIT initialseekpostype; /* [w] Optional. Specify 0 to ignore. For streams. Specify the time unit for the position set in initialseekposition. */ + int ignoresetfilesystem;/* [w] Optional. Specify 0 to ignore. Set to 1 to use fmod's built in file system. Ignores setFileSystem callbacks and also FMOD_CREATESOUNEXINFO file callbacks. Useful for specific cases where you don't want to use your own file system but want to use fmod's file system (ie net streaming). */ + int cddaforceaspi; /* [w] Optional. Specify 0 to ignore. For CDDA sounds only - if non-zero use ASPI instead of NTSCSI to access the specified CD/DVD device. */ + unsigned int audioqueuepolicy; /* [w] Optional. Specify 0 or FMOD_AUDIOQUEUE_CODECPOLICY_DEFAULT to ignore. Policy used to determine whether hardware or software is used for decoding, see FMOD_AUDIOQUEUE_CODECPOLICY for options (iOS >= 3.0 required, otherwise only hardware is available) */ + unsigned int minmidigranularity; /* [w] Optional. Specify 0 to ignore. Allows you to set a minimum desired MIDI mixer granularity. Values smaller than 512 give greater than default accuracy at the cost of more CPU and vice versa. Specify 0 for default (512 samples). */ + int nonblockthreadid; /* [w] Optional. Specify 0 to ignore. Specifies a thread index to execute non blocking load on. Allows for up to 5 threads to be used for loading at once. This is to avoid one load blocking another. Maximum value = 4. */ +} FMOD_CREATESOUNDEXINFO; + + +/* +[STRUCTURE] +[ + [DESCRIPTION] + Structure defining a reverb environment. + + [REMARKS] + Note the default reverb properties are the same as the FMOD_PRESET_GENERIC preset. + Note that integer values that typically range from -10,000 to 1000 are represented in + decibels, and are of a logarithmic scale, not linear, wheras float values are always linear. + + The numerical values listed below are the maximum, minimum and default values for each variable respectively. + + SUPPORTED next to each parameter means the platform the parameter can be set on. Some platforms support all parameters and some don't. + WII means Nintendo Wii hardware reverb (must use FMOD_HARDWARE). + PSP means Playstation Portable hardware reverb (must use FMOD_HARDWARE). + SFX means FMOD SFX software reverb. This works on any platform that uses FMOD_SOFTWARE for loading sounds. + --- means unsupported/deprecated. Will either be removed or supported by SFX in the future. + + Nintendo Wii Notes: + This structure supports only limited parameters, and maps them to the Wii hardware reverb as follows. + DecayTime = 'time' + ReverbDelay = 'predelay' + ModulationDepth = 'damping' + Reflections = 'coloration' + EnvDiffusion = 'crosstalk' + Room = 'mix' + + Members marked with [r] mean the variable is modified by FMOD and is for reading purposes only. Do not change this value. + Members marked with [w] mean the variable can be written to. The user can set the value. + Members marked with [r/w] are either read or write depending on if you are using System::setReverbProperties (w) or System::getReverbProperties (r). + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + System::setReverbProperties + System::getReverbProperties + FMOD_REVERB_PRESETS + FMOD_REVERB_FLAGS +] +*/ +typedef struct FMOD_REVERB_PROPERTIES +{ /* MIN MAX DEFAULT DESCRIPTION */ + int Instance; /* [w] 0 3 0 Environment Instance. (SUPPORTED:SFX(4 instances) and Wii (3 instances)) */ + int Environment; /* [r/w] -1 25 -1 Sets all listener properties. -1 = OFF. (SUPPORTED:SFX(-1 only)/PSP) */ + float EnvDiffusion; /* [r/w] 0.0 1.0 1.0 Environment diffusion (SUPPORTED:WII) */ + int Room; /* [r/w] -10000 0 -1000 Room effect level (at mid frequencies) (SUPPORTED:SFX/WII/PSP) */ + int RoomHF; /* [r/w] -10000 0 -100 Relative room effect level at high frequencies (SUPPORTED:SFX) */ + int RoomLF; /* [r/w] -10000 0 0 Relative room effect level at low frequencies (SUPPORTED:SFX) */ + float DecayTime; /* [r/w] 0.1 20.0 1.49 Reverberation decay time at mid frequencies (SUPPORTED:SFX/WII) */ + float DecayHFRatio; /* [r/w] 0.1 2.0 0.83 High-frequency to mid-frequency decay time ratio (SUPPORTED:SFX) */ + float DecayLFRatio; /* [r/w] 0.1 2.0 1.0 Low-frequency to mid-frequency decay time ratio (SUPPORTED:---) */ + int Reflections; /* [r/w] -10000 1000 -2602 Early reflections level relative to room effect (SUPPORTED:SFX/WII) */ + float ReflectionsDelay; /* [r/w] 0.0 0.3 0.007 Initial reflection delay time (SUPPORTED:SFX) */ + int Reverb; /* [r/w] -10000 2000 200 Late reverberation level relative to room effect (SUPPORTED:SFX) */ + float ReverbDelay; /* [r/w] 0.0 0.1 0.011 Late reverberation delay time relative to initial reflection (SUPPORTED:SFX/WII) */ + float ModulationTime; /* [r/w] 0.04 4.0 0.25 Modulation time (SUPPORTED:---) */ + float ModulationDepth; /* [r/w] 0.0 1.0 0.0 Modulation depth (SUPPORTED:WII) */ + float HFReference; /* [r/w] 20.0 20000.0 5000.0 Reference high frequency (hz) (SUPPORTED:SFX) */ + float LFReference; /* [r/w] 20.0 1000.0 250.0 Reference low frequency (hz) (SUPPORTED:SFX) */ + float Diffusion; /* [r/w] 0.0 100.0 100.0 Value that controls the echo density in the late reverberation decay. (SUPPORTED:SFX) */ + float Density; /* [r/w] 0.0 100.0 100.0 Value that controls the modal density in the late reverberation decay (SUPPORTED:SFX) */ + unsigned int Flags; /* [r/w] FMOD_REVERB_FLAGS - modifies the behavior of above properties (SUPPORTED:WII) */ +} FMOD_REVERB_PROPERTIES; + + +/* +[DEFINE] +[ + [NAME] + FMOD_REVERB_FLAGS + + [DESCRIPTION] + Values for the Flags member of the FMOD_REVERB_PROPERTIES structure. + + [REMARKS] + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + FMOD_REVERB_PROPERTIES +] +*/ +#define FMOD_REVERB_FLAGS_HIGHQUALITYREVERB 0x00000400 /* Wii. Use high quality reverb */ +#define FMOD_REVERB_FLAGS_HIGHQUALITYDPL2REVERB 0x00000800 /* Wii. Use high quality DPL2 reverb */ +#define FMOD_REVERB_FLAGS_HARDWAREONLY 0x00001000 /* Don't create an SFX reverb for FMOD_SOFTWARE channels, hardware reverb only */ +#define FMOD_REVERB_FLAGS_DEFAULT 0x00000000 +/* [DEFINE_END] */ + + +/* +[DEFINE] +[ + [NAME] + FMOD_REVERB_PRESETS + + [DESCRIPTION] + A set of predefined environment PARAMETERS. + These are used to initialize an FMOD_REVERB_PROPERTIES structure statically. + i.e. + FMOD_REVERB_PROPERTIES prop = FMOD_PRESET_GENERIC; + + [REMARKS] + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + System::setReverbProperties +] +*/ +/* Inst Env Diffus Room RoomHF RmLF DecTm DecHF DecLF Refl RefDel Revb RevDel ModTm ModDp HFRef LFRef Diffus Densty FLAGS */ +#define FMOD_PRESET_OFF { 0, -1, 1.00f, -10000, -10000, 0, 1.00f, 1.00f, 1.0f, -2602, 0.007f, 200, 0.011f, 0.25f, 0.000f, 5000.0f, 250.0f, 0.0f, 0.0f, 0x33f } +#define FMOD_PRESET_GENERIC { 0, 0, 1.00f, -1000, -100, 0, 1.49f, 0.83f, 1.0f, -2602, 0.007f, 200, 0.011f, 0.25f, 0.000f, 5000.0f, 250.0f, 100.0f, 100.0f, 0x3f } +#define FMOD_PRESET_PADDEDCELL { 0, 1, 1.00f, -1000, -6000, 0, 0.17f, 0.10f, 1.0f, -1204, 0.001f, 207, 0.002f, 0.25f, 0.000f, 5000.0f, 250.0f, 100.0f, 100.0f, 0x3f } +#define FMOD_PRESET_ROOM { 0, 2, 1.00f, -1000, -454, 0, 0.40f, 0.83f, 1.0f, -1646, 0.002f, 53, 0.003f, 0.25f, 0.000f, 5000.0f, 250.0f, 100.0f, 100.0f, 0x3f } +#define FMOD_PRESET_BATHROOM { 0, 3, 1.00f, -1000, -1200, 0, 1.49f, 0.54f, 1.0f, -370, 0.007f, 1030, 0.011f, 0.25f, 0.000f, 5000.0f, 250.0f, 100.0f, 60.0f, 0x3f } +#define FMOD_PRESET_LIVINGROOM { 0, 4, 1.00f, -1000, -6000, 0, 0.50f, 0.10f, 1.0f, -1376, 0.003f, -1104, 0.004f, 0.25f, 0.000f, 5000.0f, 250.0f, 100.0f, 100.0f, 0x3f } +#define FMOD_PRESET_STONEROOM { 0, 5, 1.00f, -1000, -300, 0, 2.31f, 0.64f, 1.0f, -711, 0.012f, 83, 0.017f, 0.25f, 0.000f, 5000.0f, 250.0f, 100.0f, 100.0f, 0x3f } +#define FMOD_PRESET_AUDITORIUM { 0, 6, 1.00f, -1000, -476, 0, 4.32f, 0.59f, 1.0f, -789, 0.020f, -289, 0.030f, 0.25f, 0.000f, 5000.0f, 250.0f, 100.0f, 100.0f, 0x3f } +#define FMOD_PRESET_CONCERTHALL { 0, 7, 1.00f, -1000, -500, 0, 3.92f, 0.70f, 1.0f, -1230, 0.020f, -2, 0.029f, 0.25f, 0.000f, 5000.0f, 250.0f, 100.0f, 100.0f, 0x3f } +#define FMOD_PRESET_CAVE { 0, 8, 1.00f, -1000, 0, 0, 2.91f, 1.30f, 1.0f, -602, 0.015f, -302, 0.022f, 0.25f, 0.000f, 5000.0f, 250.0f, 100.0f, 100.0f, 0x1f } +#define FMOD_PRESET_ARENA { 0, 9, 1.00f, -1000, -698, 0, 7.24f, 0.33f, 1.0f, -1166, 0.020f, 16, 0.030f, 0.25f, 0.000f, 5000.0f, 250.0f, 100.0f, 100.0f, 0x3f } +#define FMOD_PRESET_HANGAR { 0, 10, 1.00f, -1000, -1000, 0, 10.05f, 0.23f, 1.0f, -602, 0.020f, 198, 0.030f, 0.25f, 0.000f, 5000.0f, 250.0f, 100.0f, 100.0f, 0x3f } +#define FMOD_PRESET_CARPETTEDHALLWAY { 0, 11, 1.00f, -1000, -4000, 0, 0.30f, 0.10f, 1.0f, -1831, 0.002f, -1630, 0.030f, 0.25f, 0.000f, 5000.0f, 250.0f, 100.0f, 100.0f, 0x3f } +#define FMOD_PRESET_HALLWAY { 0, 12, 1.00f, -1000, -300, 0, 1.49f, 0.59f, 1.0f, -1219, 0.007f, 441, 0.011f, 0.25f, 0.000f, 5000.0f, 250.0f, 100.0f, 100.0f, 0x3f } +#define FMOD_PRESET_STONECORRIDOR { 0, 13, 1.00f, -1000, -237, 0, 2.70f, 0.79f, 1.0f, -1214, 0.013f, 395, 0.020f, 0.25f, 0.000f, 5000.0f, 250.0f, 100.0f, 100.0f, 0x3f } +#define FMOD_PRESET_ALLEY { 0, 14, 0.30f, -1000, -270, 0, 1.49f, 0.86f, 1.0f, -1204, 0.007f, -4, 0.011f, 0.25f, 0.000f, 5000.0f, 250.0f, 100.0f, 100.0f, 0x3f } +#define FMOD_PRESET_FOREST { 0, 15, 0.30f, -1000, -3300, 0, 1.49f, 0.54f, 1.0f, -2560, 0.162f, -229, 0.088f, 0.25f, 0.000f, 5000.0f, 250.0f, 79.0f, 100.0f, 0x3f } +#define FMOD_PRESET_CITY { 0, 16, 0.50f, -1000, -800, 0, 1.49f, 0.67f, 1.0f, -2273, 0.007f, -1691, 0.011f, 0.25f, 0.000f, 5000.0f, 250.0f, 50.0f, 100.0f, 0x3f } +#define FMOD_PRESET_MOUNTAINS { 0, 17, 0.27f, -1000, -2500, 0, 1.49f, 0.21f, 1.0f, -2780, 0.300f, -1434, 0.100f, 0.25f, 0.000f, 5000.0f, 250.0f, 27.0f, 100.0f, 0x1f } +#define FMOD_PRESET_QUARRY { 0, 18, 1.00f, -1000, -1000, 0, 1.49f, 0.83f, 1.0f, -10000, 0.061f, 500, 0.025f, 0.25f, 0.000f, 5000.0f, 250.0f, 100.0f, 100.0f, 0x3f } +#define FMOD_PRESET_PLAIN { 0, 19, 0.21f, -1000, -2000, 0, 1.49f, 0.50f, 1.0f, -2466, 0.179f, -1926, 0.100f, 0.25f, 0.000f, 5000.0f, 250.0f, 21.0f, 100.0f, 0x3f } +#define FMOD_PRESET_PARKINGLOT { 0, 20, 1.00f, -1000, 0, 0, 1.65f, 1.50f, 1.0f, -1363, 0.008f, -1153, 0.012f, 0.25f, 0.000f, 5000.0f, 250.0f, 100.0f, 100.0f, 0x1f } +#define FMOD_PRESET_SEWERPIPE { 0, 21, 0.80f, -1000, -1000, 0, 2.81f, 0.14f, 1.0f, 429, 0.014f, 1023, 0.021f, 0.25f, 0.000f, 5000.0f, 250.0f, 80.0f, 60.0f, 0x3f } +#define FMOD_PRESET_UNDERWATER { 0, 22, 1.00f, -1000, -4000, 0, 1.49f, 0.10f, 1.0f, -449, 0.007f, 1700, 0.011f, 1.18f, 0.348f, 5000.0f, 250.0f, 100.0f, 100.0f, 0x3f } + +/* PlayStation Portable Only presets */ +#define FMOD_PRESET_PSP_ROOM { 0, 1, 0, 0, 0, 0, 0.0f, 0.0f, 0.0f, 0, 0.000f, 0, 0.000f, 0.00f, 0.000f, 0000.0f, 0.0f, 0.0f, 0.0f, 0x31f } +#define FMOD_PRESET_PSP_STUDIO_A { 0, 2, 0, 0, 0, 0, 0.0f, 0.0f, 0.0f, 0, 0.000f, 0, 0.000f, 0.00f, 0.000f, 0000.0f, 0.0f, 0.0f, 0.0f, 0x31f } +#define FMOD_PRESET_PSP_STUDIO_B { 0, 3, 0, 0, 0, 0, 0.0f, 0.0f, 0.0f, 0, 0.000f, 0, 0.000f, 0.00f, 0.000f, 0000.0f, 0.0f, 0.0f, 0.0f, 0x31f } +#define FMOD_PRESET_PSP_STUDIO_C { 0, 4, 0, 0, 0, 0, 0.0f, 0.0f, 0.0f, 0, 0.000f, 0, 0.000f, 0.00f, 0.000f, 0000.0f, 0.0f, 0.0f, 0.0f, 0x31f } +#define FMOD_PRESET_PSP_HALL { 0, 5, 0, 0, 0, 0, 0.0f, 0.0f, 0.0f, 0, 0.000f, 0, 0.000f, 0.00f, 0.000f, 0000.0f, 0.0f, 0.0f, 0.0f, 0x31f } +#define FMOD_PRESET_PSP_SPACE { 0, 6, 0, 0, 0, 0, 0.0f, 0.0f, 0.0f, 0, 0.000f, 0, 0.000f, 0.00f, 0.000f, 0000.0f, 0.0f, 0.0f, 0.0f, 0x31f } +#define FMOD_PRESET_PSP_ECHO { 0, 7, 0, 0, 0, 0, 0.0f, 0.0f, 0.0f, 0, 0.000f, 0, 0.000f, 0.00f, 0.000f, 0000.0f, 0.0f, 0.0f, 0.0f, 0x31f } +#define FMOD_PRESET_PSP_DELAY { 0, 8, 0, 0, 0, 0, 0.0f, 0.0f, 0.0f, 0, 0.000f, 0, 0.000f, 0.00f, 0.000f, 0000.0f, 0.0f, 0.0f, 0.0f, 0x31f } +#define FMOD_PRESET_PSP_PIPE { 0, 9, 0, 0, 0, 0, 0.0f, 0.0f, 0.0f, 0, 0.000f, 0, 0.000f, 0.00f, 0.000f, 0000.0f, 0.0f, 0.0f, 0.0f, 0x31f } +/* [DEFINE_END] */ + + +/* +[STRUCTURE] +[ + [DESCRIPTION] + Structure defining the properties for a reverb source, related to a FMOD channel. + + Note the default reverb properties are the same as the FMOD_PRESET_GENERIC preset. + Note that integer values that typically range from -10,000 to 1000 are represented in + decibels, and are of a logarithmic scale, not linear, wheras float values are typically linear. + PORTABILITY: Each member has the platform it supports in braces ie (win32/wii). + + The numerical values listed below are the maximum, minimum and default values for each variable respectively. + + [REMARKS] + SUPPORTED next to each parameter means the platform the parameter can be set on. Some platforms support all parameters and some don't. + WII means Nintendo Wii hardware reverb (must use FMOD_HARDWARE). + PSP means Playstation Portable hardware reverb (must use FMOD_HARDWARE). + SFX means FMOD SFX software reverb. This works on any platform that uses FMOD_SOFTWARE for loading sounds. + --- means unsupported/deprecated. Will either be removed or supported by SFX in the future. + + + 'ConnectionPoint' Parameter. This parameter is for the FMOD software reverb only (known as SFX in the list above). + By default the dsp network connection for a channel and its reverb is between the 'SFX Reverb' unit, and the channel's wavetable/resampler/dspcodec/oscillator unit (the unit below the channel DSP head). NULL can be used for this parameter to make it use this default behaviour. + This parameter allows the user to connect the SFX reverb to somewhere else internally, for example the channel DSP head, or a related channelgroup. The event system uses this so that it can have the output of an event going to the reverb, instead of just the output of the event's channels (thereby ignoring event effects/submixes etc). + Do not use if you are unaware of DSP network connection issues. Leave it at the default of NULL instead. + + Members marked with [r] mean the variable is modified by FMOD and is for reading purposes only. Do not change this value. + Members marked with [w] mean the variable can be written to. The user can set the value. + Members marked with [r/w] are either read or write depending on if you are using Channel::setReverbProperties (w) or Channel::getReverbProperties (r). + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + Channel::setReverbProperties + Channel::getReverbProperties + FMOD_REVERB_CHANNELFLAGS +] +*/ +typedef struct FMOD_REVERB_CHANNELPROPERTIES +{ /* MIN MAX DEFAULT DESCRIPTION */ + int Direct; /* [r/w] -10000 1000 0 Direct path level (SUPPORTED:SFX) */ + int Room; /* [r/w] -10000 1000 0 Room effect level (SUPPORTED:SFX) */ + unsigned int Flags; /* [r/w] FMOD_REVERB_CHANNELFLAGS - modifies the behavior of properties (SUPPORTED:SFX) */ + FMOD_DSP *ConnectionPoint; /* [r/w] See remarks. DSP network location to connect reverb for this channel. (SUPPORTED:SFX).*/ +} FMOD_REVERB_CHANNELPROPERTIES; + + +/* +[DEFINE] +[ + [NAME] + FMOD_REVERB_CHANNELFLAGS + + [DESCRIPTION] + Values for the Flags member of the FMOD_REVERB_CHANNELPROPERTIES structure. + + [REMARKS] + For SFX Reverb, there is support for multiple reverb environments. + Use FMOD_REVERB_CHANNELFLAGS_ENVIRONMENT0 to FMOD_REVERB_CHANNELFLAGS_ENVIRONMENT3 in the flags member + of FMOD_REVERB_CHANNELPROPERTIES to specify which environment instance(s) to target. + - If you do not specify any instance the first reverb instance will be used. + - If you specify more than one instance with getReverbProperties, the first instance will be used. + - If you specify more than one instance with setReverbProperties, it will set more than 1 instance at once. + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + FMOD_REVERB_CHANNELPROPERTIES +] +*/ +#define FMOD_REVERB_CHANNELFLAGS_INSTANCE0 0x00000010 /* SFX/Wii. Specify channel to target reverb instance 0. Default target. */ +#define FMOD_REVERB_CHANNELFLAGS_INSTANCE1 0x00000020 /* SFX/Wii. Specify channel to target reverb instance 1. */ +#define FMOD_REVERB_CHANNELFLAGS_INSTANCE2 0x00000040 /* SFX/Wii. Specify channel to target reverb instance 2. */ +#define FMOD_REVERB_CHANNELFLAGS_INSTANCE3 0x00000080 /* SFX. Specify channel to target reverb instance 3. */ + +#define FMOD_REVERB_CHANNELFLAGS_DEFAULT FMOD_REVERB_CHANNELFLAGS_INSTANCE0 +/* [DEFINE_END] */ + + +/* +[STRUCTURE] +[ + [DESCRIPTION] + Settings for advanced features like configuring memory and cpu usage for the FMOD_CREATECOMPRESSEDSAMPLE feature. + + [REMARKS] + maxMPEGcodecs / maxADPCMcodecs / maxXMAcodecs will determine the maximum cpu usage of playing realtime samples. Use this to lower potential excess cpu usage and also control memory usage. + + maxPCMcodecs is for use with PS3 only. It will determine the maximum number of PCM voices that can be played at once. This includes streams of any format and all sounds created + *without* the FMOD_CREATECOMPRESSEDSAMPLE flag. + + Memory will be allocated for codecs 'up front' (during System::init) if these values are specified as non zero. If any are zero, it allocates memory for the codec whenever a file of the type in question is loaded. So if maxMPEGcodecs is 0 for example, it will allocate memory for the mpeg codecs the first time an mp3 is loaded or an mp3 based .FSB file is loaded. + + Due to inefficient encoding techniques on certain .wav based ADPCM files, FMOD can can need an extra 29720 bytes per codec. This means for lowest memory consumption. Use FSB as it uses an optimal/small ADPCM block size. + + Members marked with [r] mean the variable is modified by FMOD and is for reading purposes only. Do not change this value. + Members marked with [w] mean the variable can be written to. The user can set the value. + Members marked with [r/w] are either read or write depending on if you are using System::setAdvancedSettings (w) or System::getAdvancedSettings (r). + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + System::setAdvancedSettings + System::getAdvancedSettings + System::init + FMOD_MODE +] +*/ +typedef struct FMOD_ADVANCEDSETTINGS +{ + int cbsize; /* [w] Size of this structure. Use sizeof(FMOD_ADVANCEDSETTINGS) NOTE: This must be set before calling System::getAdvancedSettings! */ + int maxMPEGcodecs; /* [r/w] Optional. Specify 0 to ignore. For use with FMOD_CREATECOMPRESSEDSAMPLE only. Mpeg codecs consume 21,684 bytes per instance and this number will determine how many mpeg channels can be played simultaneously. Default = 32. */ + int maxADPCMcodecs; /* [r/w] Optional. Specify 0 to ignore. For use with FMOD_CREATECOMPRESSEDSAMPLE only. ADPCM codecs consume 2,136 bytes per instance and this number will determine how many ADPCM channels can be played simultaneously. Default = 32. */ + int maxXMAcodecs; /* [r/w] Optional. Specify 0 to ignore. For use with FMOD_CREATECOMPRESSEDSAMPLE only. XMA codecs consume 14,836 bytes per instance and this number will determine how many XMA channels can be played simultaneously. Default = 32. */ + int maxCELTcodecs; /* [r/w] Optional. Specify 0 to ignore. For use with FMOD_CREATECOMPRESSEDSAMPLE only. CELT codecs consume 11,500 bytes per instance and this number will determine how many CELT channels can be played simultaneously. Default = 32. */ + int maxVORBIScodecs; /* [r/w] Optional. Specify 0 to ignore. For use with FMOD_CREATECOMPRESSEDSAMPLE only. Vorbis codecs consume 12,000 bytes per instance and this number will determine how many Vorbis channels can be played simultaneously. Default = 32. */ + int maxPCMcodecs; /* [r/w] Optional. Specify 0 to ignore. For use with PS3 only. PCM codecs consume 12,672 bytes per instance and this number will determine how many streams and PCM voices can be played simultaneously. Default = 16. */ + int ASIONumChannels; /* [r/w] Optional. Specify 0 to ignore. Number of channels available on the ASIO device. */ + char **ASIOChannelList; /* [r/w] Optional. Specify 0 to ignore. Pointer to an array of strings (number of entries defined by ASIONumChannels) with ASIO channel names. */ + FMOD_SPEAKER *ASIOSpeakerList; /* [r/w] Optional. Specify 0 to ignore. Pointer to a list of speakers that the ASIO channels map to. This can be called after System::init to remap ASIO output. */ + int max3DReverbDSPs; /* [r/w] Optional. Specify 0 to ignore. The max number of 3d reverb DSP's in the system. (NOTE: CURRENTLY DISABLED / UNUSED) */ + float HRTFMinAngle; /* [r/w] Optional. For use with FMOD_INIT_HRTF_LOWPASS. The angle range (0-360) of a 3D sound in relation to the listener, at which the HRTF function begins to have an effect. 0 = in front of the listener. 180 = from 90 degrees to the left of the listener to 90 degrees to the right. 360 = behind the listener. Default = 180.0. */ + float HRTFMaxAngle; /* [r/w] Optional. For use with FMOD_INIT_HRTF_LOWPASS. The angle range (0-360) of a 3D sound in relation to the listener, at which the HRTF function has maximum effect. 0 = front of the listener. 180 = from 90 degrees to the left of the listener to 90 degrees to the right. 360 = behind the listener. Default = 360.0. */ + float HRTFFreq; /* [r/w] Optional. Specify 0 to ignore. For use with FMOD_INIT_HRTF_LOWPASS. The cutoff frequency of the HRTF's lowpass filter function when at maximum effect. (i.e. at HRTFMaxAngle). Default = 4000.0. */ + float vol0virtualvol; /* [r/w] Optional. Specify 0 to ignore. For use with FMOD_INIT_VOL0_BECOMES_VIRTUAL. If this flag is used, and the volume is 0.0, then the sound will become virtual. Use this value to raise the threshold to a different point where a sound goes virtual. */ + int eventqueuesize; /* [r/w] Optional. Specify 0 to ignore. For use with FMOD Event system only. Specifies the number of slots available for simultaneous non blocking loads, across all threads. Default = 32. */ + unsigned int defaultDecodeBufferSize; /* [r/w] Optional. Specify 0 to ignore. For streams. This determines the default size of the double buffer (in milliseconds) that a stream uses. Default = 400ms */ + char *debugLogFilename; /* [r/w] Optional. Specify 0 to ignore. Gives fmod's logging system a path/filename. Normally the log is placed in the same directory as the executable and called fmod.log. When using System::getAdvancedSettings, provide at least 256 bytes of memory to copy into. */ + unsigned short profileport; /* [r/w] Optional. Specify 0 to ignore. For use with FMOD_INIT_ENABLE_PROFILE. Specify the port to listen on for connections by the profiler application. */ + unsigned int geometryMaxFadeTime; /* [r/w] Optional. Specify 0 to ignore. The maximum time in miliseconds it takes for a channel to fade to the new level when its occlusion changes. */ + unsigned int maxSpectrumWaveDataBuffers; /* [r/w] Optional. Specify 0 to ignore. Tells System::init to allocate a pool of wavedata/spectrum buffers to prevent memory fragmentation, any additional buffers will be allocated normally. */ + unsigned int musicSystemCacheDelay; /* [r/w] Optional. Specify 0 to ignore. The delay the music system should allow for loading a sample from disk (in milliseconds). Default = 400 ms. */ + float distanceFilterCenterFreq; /* [r/w] Optional. Specify 0 to ignore. For use with FMOD_INIT_DISTANCE_FILTERING. The default center frequency in Hz for the distance filtering effect. Default = 1500.0. */ + unsigned int stackSizeStream; /* [r/w] Optional. Specify 0 to ignore. Specify the stack size for the FMOD Stream thread in bytes. Useful for custom codecs that use excess stack. Default 49,152 (48kb) */ + unsigned int stackSizeNonBlocking; /* [r/w] Optional. Specify 0 to ignore. Specify the stack size for the FMOD_NONBLOCKING loading thread. Useful for custom codecs that use excess stack. Default 65,536 (64kb) */ + unsigned int stackSizeMixer; /* [r/w] Optional. Specify 0 to ignore. Specify the stack size for the FMOD mixer thread. Useful for custom dsps that use excess stack. Default 49,152 (48kb) */ +} FMOD_ADVANCEDSETTINGS; + + +/* +[ENUM] +[ + [DESCRIPTION] + Special channel index values for FMOD functions. + + [REMARKS] + To get 'all' of the channels, use System::getMasterChannelGroup. + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + System::playSound + System::playDSP + System::getChannel + System::getMasterChannelGroup +] +*/ +typedef enum +{ + FMOD_CHANNEL_FREE = -1, /* For a channel index, FMOD chooses a free voice using the priority system. */ + FMOD_CHANNEL_REUSE = -2 /* For a channel index, re-use the channel handle that was passed in. */ +} FMOD_CHANNELINDEX; + +#include "fmod_codec.h" +#include "fmod_dsp.h" +#include "fmod_memoryinfo.h" + +/* ========================================================================================== */ +/* FUNCTION PROTOTYPES */ +/* ========================================================================================== */ + +#ifdef __cplusplus +extern "C" +{ +#endif + +/* + FMOD global system functions (optional). +*/ + +FMOD_RESULT F_API FMOD_Memory_Initialize (void *poolmem, int poollen, FMOD_MEMORY_ALLOCCALLBACK useralloc, FMOD_MEMORY_REALLOCCALLBACK userrealloc, FMOD_MEMORY_FREECALLBACK userfree, FMOD_MEMORY_TYPE memtypeflags); +FMOD_RESULT F_API FMOD_Memory_GetStats (int *currentalloced, int *maxalloced, FMOD_BOOL blocking); +FMOD_RESULT F_API FMOD_Debug_SetLevel (FMOD_DEBUGLEVEL level); +FMOD_RESULT F_API FMOD_Debug_GetLevel (FMOD_DEBUGLEVEL *level); +FMOD_RESULT F_API FMOD_File_SetDiskBusy (int busy); +FMOD_RESULT F_API FMOD_File_GetDiskBusy (int *busy); + +/* + FMOD System factory functions. Use this to create an FMOD System Instance. below you will see FMOD_System_Init/Close to get started. +*/ + +FMOD_RESULT F_API FMOD_System_Create (FMOD_SYSTEM **system); +FMOD_RESULT F_API FMOD_System_Release (FMOD_SYSTEM *system); + + +/* + 'System' API +*/ + +/* + Pre-init functions. +*/ + +FMOD_RESULT F_API FMOD_System_SetOutput (FMOD_SYSTEM *system, FMOD_OUTPUTTYPE output); +FMOD_RESULT F_API FMOD_System_GetOutput (FMOD_SYSTEM *system, FMOD_OUTPUTTYPE *output); +FMOD_RESULT F_API FMOD_System_GetNumDrivers (FMOD_SYSTEM *system, int *numdrivers); +FMOD_RESULT F_API FMOD_System_GetDriverInfo (FMOD_SYSTEM *system, int id, char *name, int namelen, FMOD_GUID *guid); +FMOD_RESULT F_API FMOD_System_GetDriverInfoW (FMOD_SYSTEM *system, int id, short *name, int namelen, FMOD_GUID *guid); +FMOD_RESULT F_API FMOD_System_GetDriverCaps (FMOD_SYSTEM *system, int id, FMOD_CAPS *caps, int *controlpaneloutputrate, FMOD_SPEAKERMODE *controlpanelspeakermode); +FMOD_RESULT F_API FMOD_System_SetDriver (FMOD_SYSTEM *system, int driver); +FMOD_RESULT F_API FMOD_System_GetDriver (FMOD_SYSTEM *system, int *driver); +FMOD_RESULT F_API FMOD_System_SetHardwareChannels (FMOD_SYSTEM *system, int numhardwarechannels); +FMOD_RESULT F_API FMOD_System_SetSoftwareChannels (FMOD_SYSTEM *system, int numsoftwarechannels); +FMOD_RESULT F_API FMOD_System_GetSoftwareChannels (FMOD_SYSTEM *system, int *numsoftwarechannels); +FMOD_RESULT F_API FMOD_System_SetSoftwareFormat (FMOD_SYSTEM *system, int samplerate, FMOD_SOUND_FORMAT format, int numoutputchannels, int maxinputchannels, FMOD_DSP_RESAMPLER resamplemethod); +FMOD_RESULT F_API FMOD_System_GetSoftwareFormat (FMOD_SYSTEM *system, int *samplerate, FMOD_SOUND_FORMAT *format, int *numoutputchannels, int *maxinputchannels, FMOD_DSP_RESAMPLER *resamplemethod, int *bits); +FMOD_RESULT F_API FMOD_System_SetDSPBufferSize (FMOD_SYSTEM *system, unsigned int bufferlength, int numbuffers); +FMOD_RESULT F_API FMOD_System_GetDSPBufferSize (FMOD_SYSTEM *system, unsigned int *bufferlength, int *numbuffers); +FMOD_RESULT F_API FMOD_System_SetFileSystem (FMOD_SYSTEM *system, FMOD_FILE_OPENCALLBACK useropen, FMOD_FILE_CLOSECALLBACK userclose, FMOD_FILE_READCALLBACK userread, FMOD_FILE_SEEKCALLBACK userseek, FMOD_FILE_ASYNCREADCALLBACK userasyncread, FMOD_FILE_ASYNCCANCELCALLBACK userasynccancel, int blockalign); +FMOD_RESULT F_API FMOD_System_AttachFileSystem (FMOD_SYSTEM *system, FMOD_FILE_OPENCALLBACK useropen, FMOD_FILE_CLOSECALLBACK userclose, FMOD_FILE_READCALLBACK userread, FMOD_FILE_SEEKCALLBACK userseek); +FMOD_RESULT F_API FMOD_System_SetAdvancedSettings (FMOD_SYSTEM *system, FMOD_ADVANCEDSETTINGS *settings); +FMOD_RESULT F_API FMOD_System_GetAdvancedSettings (FMOD_SYSTEM *system, FMOD_ADVANCEDSETTINGS *settings); +FMOD_RESULT F_API FMOD_System_SetSpeakerMode (FMOD_SYSTEM *system, FMOD_SPEAKERMODE speakermode); +FMOD_RESULT F_API FMOD_System_GetSpeakerMode (FMOD_SYSTEM *system, FMOD_SPEAKERMODE *speakermode); +FMOD_RESULT F_API FMOD_System_SetCallback (FMOD_SYSTEM *system, FMOD_SYSTEM_CALLBACK callback); + +/* + Plug-in support +*/ + +FMOD_RESULT F_API FMOD_System_SetPluginPath (FMOD_SYSTEM *system, const char *path); +FMOD_RESULT F_API FMOD_System_LoadPlugin (FMOD_SYSTEM *system, const char *filename, unsigned int *handle, unsigned int priority); +FMOD_RESULT F_API FMOD_System_UnloadPlugin (FMOD_SYSTEM *system, unsigned int handle); +FMOD_RESULT F_API FMOD_System_GetNumPlugins (FMOD_SYSTEM *system, FMOD_PLUGINTYPE plugintype, int *numplugins); +FMOD_RESULT F_API FMOD_System_GetPluginHandle (FMOD_SYSTEM *system, FMOD_PLUGINTYPE plugintype, int index, unsigned int *handle); +FMOD_RESULT F_API FMOD_System_GetPluginInfo (FMOD_SYSTEM *system, unsigned int handle, FMOD_PLUGINTYPE *plugintype, char *name, int namelen, unsigned int *version); +FMOD_RESULT F_API FMOD_System_SetOutputByPlugin (FMOD_SYSTEM *system, unsigned int handle); +FMOD_RESULT F_API FMOD_System_GetOutputByPlugin (FMOD_SYSTEM *system, unsigned int *handle); +FMOD_RESULT F_API FMOD_System_CreateDSPByPlugin (FMOD_SYSTEM *system, unsigned int handle, FMOD_DSP **dsp); +FMOD_RESULT F_API FMOD_System_RegisterCodec (FMOD_SYSTEM *system, FMOD_CODEC_DESCRIPTION *description, unsigned int *handle, unsigned int priority); +FMOD_RESULT F_API FMOD_System_RegisterDSP (FMOD_SYSTEM *system, FMOD_DSP_DESCRIPTION *description, unsigned int *handle); + +/* + Init/Close +*/ + +FMOD_RESULT F_API FMOD_System_Init (FMOD_SYSTEM *system, int maxchannels, FMOD_INITFLAGS flags, void *extradriverdata); +FMOD_RESULT F_API FMOD_System_Close (FMOD_SYSTEM *system); + +/* + General post-init system functions +*/ + +FMOD_RESULT F_API FMOD_System_Update (FMOD_SYSTEM *system); + +FMOD_RESULT F_API FMOD_System_Set3DSettings (FMOD_SYSTEM *system, float dopplerscale, float distancefactor, float rolloffscale); +FMOD_RESULT F_API FMOD_System_Get3DSettings (FMOD_SYSTEM *system, float *dopplerscale, float *distancefactor, float *rolloffscale); +FMOD_RESULT F_API FMOD_System_Set3DNumListeners (FMOD_SYSTEM *system, int numlisteners); +FMOD_RESULT F_API FMOD_System_Get3DNumListeners (FMOD_SYSTEM *system, int *numlisteners); +FMOD_RESULT F_API FMOD_System_Set3DListenerAttributes(FMOD_SYSTEM *system, int listener, const FMOD_VECTOR *pos, const FMOD_VECTOR *vel, const FMOD_VECTOR *forward, const FMOD_VECTOR *up); +FMOD_RESULT F_API FMOD_System_Get3DListenerAttributes(FMOD_SYSTEM *system, int listener, FMOD_VECTOR *pos, FMOD_VECTOR *vel, FMOD_VECTOR *forward, FMOD_VECTOR *up); +FMOD_RESULT F_API FMOD_System_Set3DRolloffCallback (FMOD_SYSTEM *system, FMOD_3D_ROLLOFFCALLBACK callback); +FMOD_RESULT F_API FMOD_System_Set3DSpeakerPosition (FMOD_SYSTEM *system, FMOD_SPEAKER speaker, float x, float y, FMOD_BOOL active); +FMOD_RESULT F_API FMOD_System_Get3DSpeakerPosition (FMOD_SYSTEM *system, FMOD_SPEAKER speaker, float *x, float *y, FMOD_BOOL *active); + +FMOD_RESULT F_API FMOD_System_SetStreamBufferSize (FMOD_SYSTEM *system, unsigned int filebuffersize, FMOD_TIMEUNIT filebuffersizetype); +FMOD_RESULT F_API FMOD_System_GetStreamBufferSize (FMOD_SYSTEM *system, unsigned int *filebuffersize, FMOD_TIMEUNIT *filebuffersizetype); + +/* + System information functions. +*/ + +FMOD_RESULT F_API FMOD_System_GetVersion (FMOD_SYSTEM *system, unsigned int *version); +FMOD_RESULT F_API FMOD_System_GetOutputHandle (FMOD_SYSTEM *system, void **handle); +FMOD_RESULT F_API FMOD_System_GetChannelsPlaying (FMOD_SYSTEM *system, int *channels); +FMOD_RESULT F_API FMOD_System_GetHardwareChannels (FMOD_SYSTEM *system, int *numhardwarechannels); +FMOD_RESULT F_API FMOD_System_GetCPUUsage (FMOD_SYSTEM *system, float *dsp, float *stream, float *geometry, float *update, float *total); +FMOD_RESULT F_API FMOD_System_GetSoundRAM (FMOD_SYSTEM *system, int *currentalloced, int *maxalloced, int *total); +FMOD_RESULT F_API FMOD_System_GetNumCDROMDrives (FMOD_SYSTEM *system, int *numdrives); +FMOD_RESULT F_API FMOD_System_GetCDROMDriveName (FMOD_SYSTEM *system, int drive, char *drivename, int drivenamelen, char *scsiname, int scsinamelen, char *devicename, int devicenamelen); +FMOD_RESULT F_API FMOD_System_GetSpectrum (FMOD_SYSTEM *system, float *spectrumarray, int numvalues, int channeloffset, FMOD_DSP_FFT_WINDOW windowtype); +FMOD_RESULT F_API FMOD_System_GetWaveData (FMOD_SYSTEM *system, float *wavearray, int numvalues, int channeloffset); + +/* + Sound/DSP/Channel/FX creation and retrieval. +*/ + +FMOD_RESULT F_API FMOD_System_CreateSound (FMOD_SYSTEM *system, const char *name_or_data, FMOD_MODE mode, FMOD_CREATESOUNDEXINFO *exinfo, FMOD_SOUND **sound); +FMOD_RESULT F_API FMOD_System_CreateStream (FMOD_SYSTEM *system, const char *name_or_data, FMOD_MODE mode, FMOD_CREATESOUNDEXINFO *exinfo, FMOD_SOUND **sound); +FMOD_RESULT F_API FMOD_System_CreateDSP (FMOD_SYSTEM *system, FMOD_DSP_DESCRIPTION *description, FMOD_DSP **dsp); +FMOD_RESULT F_API FMOD_System_CreateDSPByType (FMOD_SYSTEM *system, FMOD_DSP_TYPE type, FMOD_DSP **dsp); +FMOD_RESULT F_API FMOD_System_CreateChannelGroup (FMOD_SYSTEM *system, const char *name, FMOD_CHANNELGROUP **channelgroup); +FMOD_RESULT F_API FMOD_System_CreateSoundGroup (FMOD_SYSTEM *system, const char *name, FMOD_SOUNDGROUP **soundgroup); +FMOD_RESULT F_API FMOD_System_CreateReverb (FMOD_SYSTEM *system, FMOD_REVERB **reverb); + +FMOD_RESULT F_API FMOD_System_PlaySound (FMOD_SYSTEM *system, FMOD_CHANNELINDEX channelid, FMOD_SOUND *sound, FMOD_BOOL paused, FMOD_CHANNEL **channel); +FMOD_RESULT F_API FMOD_System_PlayDSP (FMOD_SYSTEM *system, FMOD_CHANNELINDEX channelid, FMOD_DSP *dsp, FMOD_BOOL paused, FMOD_CHANNEL **channel); +FMOD_RESULT F_API FMOD_System_GetChannel (FMOD_SYSTEM *system, int channelid, FMOD_CHANNEL **channel); +FMOD_RESULT F_API FMOD_System_GetMasterChannelGroup (FMOD_SYSTEM *system, FMOD_CHANNELGROUP **channelgroup); +FMOD_RESULT F_API FMOD_System_GetMasterSoundGroup (FMOD_SYSTEM *system, FMOD_SOUNDGROUP **soundgroup); + +/* + Reverb API +*/ + +FMOD_RESULT F_API FMOD_System_SetReverbProperties (FMOD_SYSTEM *system, const FMOD_REVERB_PROPERTIES *prop); +FMOD_RESULT F_API FMOD_System_GetReverbProperties (FMOD_SYSTEM *system, FMOD_REVERB_PROPERTIES *prop); +FMOD_RESULT F_API FMOD_System_SetReverbAmbientProperties(FMOD_SYSTEM *system, FMOD_REVERB_PROPERTIES *prop); +FMOD_RESULT F_API FMOD_System_GetReverbAmbientProperties(FMOD_SYSTEM *system, FMOD_REVERB_PROPERTIES *prop); + +/* + System level DSP access. +*/ + +FMOD_RESULT F_API FMOD_System_GetDSPHead (FMOD_SYSTEM *system, FMOD_DSP **dsp); +FMOD_RESULT F_API FMOD_System_AddDSP (FMOD_SYSTEM *system, FMOD_DSP *dsp, FMOD_DSPCONNECTION **connection); +FMOD_RESULT F_API FMOD_System_LockDSP (FMOD_SYSTEM *system); +FMOD_RESULT F_API FMOD_System_UnlockDSP (FMOD_SYSTEM *system); +FMOD_RESULT F_API FMOD_System_GetDSPClock (FMOD_SYSTEM *system, unsigned int *hi, unsigned int *lo); + +/* + Recording API. +*/ + +FMOD_RESULT F_API FMOD_System_GetRecordNumDrivers (FMOD_SYSTEM *system, int *numdrivers); +FMOD_RESULT F_API FMOD_System_GetRecordDriverInfo (FMOD_SYSTEM *system, int id, char *name, int namelen, FMOD_GUID *guid); +FMOD_RESULT F_API FMOD_System_GetRecordDriverInfoW (FMOD_SYSTEM *system, int id, short *name, int namelen, FMOD_GUID *guid); +FMOD_RESULT F_API FMOD_System_GetRecordDriverCaps (FMOD_SYSTEM *system, int id, FMOD_CAPS *caps, int *minfrequency, int *maxfrequency); +FMOD_RESULT F_API FMOD_System_GetRecordPosition (FMOD_SYSTEM *system, int id, unsigned int *position); + +FMOD_RESULT F_API FMOD_System_RecordStart (FMOD_SYSTEM *system, int id, FMOD_SOUND *sound, FMOD_BOOL loop); +FMOD_RESULT F_API FMOD_System_RecordStop (FMOD_SYSTEM *system, int id); +FMOD_RESULT F_API FMOD_System_IsRecording (FMOD_SYSTEM *system, int id, FMOD_BOOL *recording); + +/* + Geometry API. +*/ + +FMOD_RESULT F_API FMOD_System_CreateGeometry (FMOD_SYSTEM *system, int maxpolygons, int maxvertices, FMOD_GEOMETRY **geometry); +FMOD_RESULT F_API FMOD_System_SetGeometrySettings (FMOD_SYSTEM *system, float maxworldsize); +FMOD_RESULT F_API FMOD_System_GetGeometrySettings (FMOD_SYSTEM *system, float *maxworldsize); +FMOD_RESULT F_API FMOD_System_LoadGeometry (FMOD_SYSTEM *system, const void *data, int datasize, FMOD_GEOMETRY **geometry); +FMOD_RESULT F_API FMOD_System_GetGeometryOcclusion (FMOD_SYSTEM *system, const FMOD_VECTOR *listener, const FMOD_VECTOR *source, float *direct, float *reverb); + +/* + Network functions. +*/ + +FMOD_RESULT F_API FMOD_System_SetNetworkProxy (FMOD_SYSTEM *system, const char *proxy); +FMOD_RESULT F_API FMOD_System_GetNetworkProxy (FMOD_SYSTEM *system, char *proxy, int proxylen); +FMOD_RESULT F_API FMOD_System_SetNetworkTimeout (FMOD_SYSTEM *system, int timeout); +FMOD_RESULT F_API FMOD_System_GetNetworkTimeout (FMOD_SYSTEM *system, int *timeout); + +/* + Userdata set/get. +*/ + +FMOD_RESULT F_API FMOD_System_SetUserData (FMOD_SYSTEM *system, void *userdata); +FMOD_RESULT F_API FMOD_System_GetUserData (FMOD_SYSTEM *system, void **userdata); + +FMOD_RESULT F_API FMOD_System_GetMemoryInfo (FMOD_SYSTEM *system, unsigned int memorybits, unsigned int event_memorybits, unsigned int *memoryused, FMOD_MEMORY_USAGE_DETAILS *memoryused_details); + +/* + 'Sound' API +*/ + +FMOD_RESULT F_API FMOD_Sound_Release (FMOD_SOUND *sound); +FMOD_RESULT F_API FMOD_Sound_GetSystemObject (FMOD_SOUND *sound, FMOD_SYSTEM **system); + +/* + Standard sound manipulation functions. +*/ + +FMOD_RESULT F_API FMOD_Sound_Lock (FMOD_SOUND *sound, unsigned int offset, unsigned int length, void **ptr1, void **ptr2, unsigned int *len1, unsigned int *len2); +FMOD_RESULT F_API FMOD_Sound_Unlock (FMOD_SOUND *sound, void *ptr1, void *ptr2, unsigned int len1, unsigned int len2); +FMOD_RESULT F_API FMOD_Sound_SetDefaults (FMOD_SOUND *sound, float frequency, float volume, float pan, int priority); +FMOD_RESULT F_API FMOD_Sound_GetDefaults (FMOD_SOUND *sound, float *frequency, float *volume, float *pan, int *priority); +FMOD_RESULT F_API FMOD_Sound_SetVariations (FMOD_SOUND *sound, float frequencyvar, float volumevar, float panvar); +FMOD_RESULT F_API FMOD_Sound_GetVariations (FMOD_SOUND *sound, float *frequencyvar, float *volumevar, float *panvar); +FMOD_RESULT F_API FMOD_Sound_Set3DMinMaxDistance (FMOD_SOUND *sound, float min, float max); +FMOD_RESULT F_API FMOD_Sound_Get3DMinMaxDistance (FMOD_SOUND *sound, float *min, float *max); +FMOD_RESULT F_API FMOD_Sound_Set3DConeSettings (FMOD_SOUND *sound, float insideconeangle, float outsideconeangle, float outsidevolume); +FMOD_RESULT F_API FMOD_Sound_Get3DConeSettings (FMOD_SOUND *sound, float *insideconeangle, float *outsideconeangle, float *outsidevolume); +FMOD_RESULT F_API FMOD_Sound_Set3DCustomRolloff (FMOD_SOUND *sound, FMOD_VECTOR *points, int numpoints); +FMOD_RESULT F_API FMOD_Sound_Get3DCustomRolloff (FMOD_SOUND *sound, FMOD_VECTOR **points, int *numpoints); +FMOD_RESULT F_API FMOD_Sound_SetSubSound (FMOD_SOUND *sound, int index, FMOD_SOUND *subsound); +FMOD_RESULT F_API FMOD_Sound_GetSubSound (FMOD_SOUND *sound, int index, FMOD_SOUND **subsound); +FMOD_RESULT F_API FMOD_Sound_SetSubSoundSentence (FMOD_SOUND *sound, int *subsoundlist, int numsubsounds); +FMOD_RESULT F_API FMOD_Sound_GetName (FMOD_SOUND *sound, char *name, int namelen); +FMOD_RESULT F_API FMOD_Sound_GetLength (FMOD_SOUND *sound, unsigned int *length, FMOD_TIMEUNIT lengthtype); +FMOD_RESULT F_API FMOD_Sound_GetFormat (FMOD_SOUND *sound, FMOD_SOUND_TYPE *type, FMOD_SOUND_FORMAT *format, int *channels, int *bits); +FMOD_RESULT F_API FMOD_Sound_GetNumSubSounds (FMOD_SOUND *sound, int *numsubsounds); +FMOD_RESULT F_API FMOD_Sound_GetNumTags (FMOD_SOUND *sound, int *numtags, int *numtagsupdated); +FMOD_RESULT F_API FMOD_Sound_GetTag (FMOD_SOUND *sound, const char *name, int index, FMOD_TAG *tag); +FMOD_RESULT F_API FMOD_Sound_GetOpenState (FMOD_SOUND *sound, FMOD_OPENSTATE *openstate, unsigned int *percentbuffered, FMOD_BOOL *starving, FMOD_BOOL *diskbusy); +FMOD_RESULT F_API FMOD_Sound_ReadData (FMOD_SOUND *sound, void *buffer, unsigned int lenbytes, unsigned int *read); +FMOD_RESULT F_API FMOD_Sound_SeekData (FMOD_SOUND *sound, unsigned int pcm); + +FMOD_RESULT F_API FMOD_Sound_SetSoundGroup (FMOD_SOUND *sound, FMOD_SOUNDGROUP *soundgroup); +FMOD_RESULT F_API FMOD_Sound_GetSoundGroup (FMOD_SOUND *sound, FMOD_SOUNDGROUP **soundgroup); + +/* + Synchronization point API. These points can come from markers embedded in wav files, and can also generate channel callbacks. +*/ + +FMOD_RESULT F_API FMOD_Sound_GetNumSyncPoints (FMOD_SOUND *sound, int *numsyncpoints); +FMOD_RESULT F_API FMOD_Sound_GetSyncPoint (FMOD_SOUND *sound, int index, FMOD_SYNCPOINT **point); +FMOD_RESULT F_API FMOD_Sound_GetSyncPointInfo (FMOD_SOUND *sound, FMOD_SYNCPOINT *point, char *name, int namelen, unsigned int *offset, FMOD_TIMEUNIT offsettype); +FMOD_RESULT F_API FMOD_Sound_AddSyncPoint (FMOD_SOUND *sound, unsigned int offset, FMOD_TIMEUNIT offsettype, const char *name, FMOD_SYNCPOINT **point); +FMOD_RESULT F_API FMOD_Sound_DeleteSyncPoint (FMOD_SOUND *sound, FMOD_SYNCPOINT *point); + +/* + Functions also in Channel class but here they are the 'default' to save having to change it in Channel all the time. +*/ + +FMOD_RESULT F_API FMOD_Sound_SetMode (FMOD_SOUND *sound, FMOD_MODE mode); +FMOD_RESULT F_API FMOD_Sound_GetMode (FMOD_SOUND *sound, FMOD_MODE *mode); +FMOD_RESULT F_API FMOD_Sound_SetLoopCount (FMOD_SOUND *sound, int loopcount); +FMOD_RESULT F_API FMOD_Sound_GetLoopCount (FMOD_SOUND *sound, int *loopcount); +FMOD_RESULT F_API FMOD_Sound_SetLoopPoints (FMOD_SOUND *sound, unsigned int loopstart, FMOD_TIMEUNIT loopstarttype, unsigned int loopend, FMOD_TIMEUNIT loopendtype); +FMOD_RESULT F_API FMOD_Sound_GetLoopPoints (FMOD_SOUND *sound, unsigned int *loopstart, FMOD_TIMEUNIT loopstarttype, unsigned int *loopend, FMOD_TIMEUNIT loopendtype); + +/* + For MOD/S3M/XM/IT/MID sequenced formats only. +*/ + +FMOD_RESULT F_API FMOD_Sound_GetMusicNumChannels (FMOD_SOUND *sound, int *numchannels); +FMOD_RESULT F_API FMOD_Sound_SetMusicChannelVolume (FMOD_SOUND *sound, int channel, float volume); +FMOD_RESULT F_API FMOD_Sound_GetMusicChannelVolume (FMOD_SOUND *sound, int channel, float *volume); +FMOD_RESULT F_API FMOD_Sound_SetMusicSpeed (FMOD_SOUND *sound, float speed); +FMOD_RESULT F_API FMOD_Sound_GetMusicSpeed (FMOD_SOUND *sound, float *speed); + +/* + Userdata set/get. +*/ + +FMOD_RESULT F_API FMOD_Sound_SetUserData (FMOD_SOUND *sound, void *userdata); +FMOD_RESULT F_API FMOD_Sound_GetUserData (FMOD_SOUND *sound, void **userdata); + +FMOD_RESULT F_API FMOD_Sound_GetMemoryInfo (FMOD_SOUND *sound, unsigned int memorybits, unsigned int event_memorybits, unsigned int *memoryused, FMOD_MEMORY_USAGE_DETAILS *memoryused_details); + +/* + 'Channel' API +*/ + +FMOD_RESULT F_API FMOD_Channel_GetSystemObject (FMOD_CHANNEL *channel, FMOD_SYSTEM **system); + +FMOD_RESULT F_API FMOD_Channel_Stop (FMOD_CHANNEL *channel); +FMOD_RESULT F_API FMOD_Channel_SetPaused (FMOD_CHANNEL *channel, FMOD_BOOL paused); +FMOD_RESULT F_API FMOD_Channel_GetPaused (FMOD_CHANNEL *channel, FMOD_BOOL *paused); +FMOD_RESULT F_API FMOD_Channel_SetVolume (FMOD_CHANNEL *channel, float volume); +FMOD_RESULT F_API FMOD_Channel_GetVolume (FMOD_CHANNEL *channel, float *volume); +FMOD_RESULT F_API FMOD_Channel_SetFrequency (FMOD_CHANNEL *channel, float frequency); +FMOD_RESULT F_API FMOD_Channel_GetFrequency (FMOD_CHANNEL *channel, float *frequency); +FMOD_RESULT F_API FMOD_Channel_SetPan (FMOD_CHANNEL *channel, float pan); +FMOD_RESULT F_API FMOD_Channel_GetPan (FMOD_CHANNEL *channel, float *pan); +FMOD_RESULT F_API FMOD_Channel_SetDelay (FMOD_CHANNEL *channel, FMOD_DELAYTYPE delaytype, unsigned int delayhi, unsigned int delaylo); +FMOD_RESULT F_API FMOD_Channel_GetDelay (FMOD_CHANNEL *channel, FMOD_DELAYTYPE delaytype, unsigned int *delayhi, unsigned int *delaylo); +FMOD_RESULT F_API FMOD_Channel_SetSpeakerMix (FMOD_CHANNEL *channel, float frontleft, float frontright, float center, float lfe, float backleft, float backright, float sideleft, float sideright); +FMOD_RESULT F_API FMOD_Channel_GetSpeakerMix (FMOD_CHANNEL *channel, float *frontleft, float *frontright, float *center, float *lfe, float *backleft, float *backright, float *sideleft, float *sideright); +FMOD_RESULT F_API FMOD_Channel_SetSpeakerLevels (FMOD_CHANNEL *channel, FMOD_SPEAKER speaker, float *levels, int numlevels); +FMOD_RESULT F_API FMOD_Channel_GetSpeakerLevels (FMOD_CHANNEL *channel, FMOD_SPEAKER speaker, float *levels, int numlevels); +FMOD_RESULT F_API FMOD_Channel_SetInputChannelMix (FMOD_CHANNEL *channel, float *levels, int numlevels); +FMOD_RESULT F_API FMOD_Channel_GetInputChannelMix (FMOD_CHANNEL *channel, float *levels, int numlevels); +FMOD_RESULT F_API FMOD_Channel_SetMute (FMOD_CHANNEL *channel, FMOD_BOOL mute); +FMOD_RESULT F_API FMOD_Channel_GetMute (FMOD_CHANNEL *channel, FMOD_BOOL *mute); +FMOD_RESULT F_API FMOD_Channel_SetPriority (FMOD_CHANNEL *channel, int priority); +FMOD_RESULT F_API FMOD_Channel_GetPriority (FMOD_CHANNEL *channel, int *priority); +FMOD_RESULT F_API FMOD_Channel_SetPosition (FMOD_CHANNEL *channel, unsigned int position, FMOD_TIMEUNIT postype); +FMOD_RESULT F_API FMOD_Channel_GetPosition (FMOD_CHANNEL *channel, unsigned int *position, FMOD_TIMEUNIT postype); +FMOD_RESULT F_API FMOD_Channel_SetReverbProperties (FMOD_CHANNEL *channel, const FMOD_REVERB_CHANNELPROPERTIES *prop); +FMOD_RESULT F_API FMOD_Channel_GetReverbProperties (FMOD_CHANNEL *channel, FMOD_REVERB_CHANNELPROPERTIES *prop); +FMOD_RESULT F_API FMOD_Channel_SetLowPassGain (FMOD_CHANNEL *channel, float gain); +FMOD_RESULT F_API FMOD_Channel_GetLowPassGain (FMOD_CHANNEL *channel, float *gain); + +FMOD_RESULT F_API FMOD_Channel_SetChannelGroup (FMOD_CHANNEL *channel, FMOD_CHANNELGROUP *channelgroup); +FMOD_RESULT F_API FMOD_Channel_GetChannelGroup (FMOD_CHANNEL *channel, FMOD_CHANNELGROUP **channelgroup); +FMOD_RESULT F_API FMOD_Channel_SetCallback (FMOD_CHANNEL *channel, FMOD_CHANNEL_CALLBACK callback); + +/* + 3D functionality. +*/ + +FMOD_RESULT F_API FMOD_Channel_Set3DAttributes (FMOD_CHANNEL *channel, const FMOD_VECTOR *pos, const FMOD_VECTOR *vel); +FMOD_RESULT F_API FMOD_Channel_Get3DAttributes (FMOD_CHANNEL *channel, FMOD_VECTOR *pos, FMOD_VECTOR *vel); +FMOD_RESULT F_API FMOD_Channel_Set3DMinMaxDistance (FMOD_CHANNEL *channel, float mindistance, float maxdistance); +FMOD_RESULT F_API FMOD_Channel_Get3DMinMaxDistance (FMOD_CHANNEL *channel, float *mindistance, float *maxdistance); +FMOD_RESULT F_API FMOD_Channel_Set3DConeSettings (FMOD_CHANNEL *channel, float insideconeangle, float outsideconeangle, float outsidevolume); +FMOD_RESULT F_API FMOD_Channel_Get3DConeSettings (FMOD_CHANNEL *channel, float *insideconeangle, float *outsideconeangle, float *outsidevolume); +FMOD_RESULT F_API FMOD_Channel_Set3DConeOrientation (FMOD_CHANNEL *channel, FMOD_VECTOR *orientation); +FMOD_RESULT F_API FMOD_Channel_Get3DConeOrientation (FMOD_CHANNEL *channel, FMOD_VECTOR *orientation); +FMOD_RESULT F_API FMOD_Channel_Set3DCustomRolloff (FMOD_CHANNEL *channel, FMOD_VECTOR *points, int numpoints); +FMOD_RESULT F_API FMOD_Channel_Get3DCustomRolloff (FMOD_CHANNEL *channel, FMOD_VECTOR **points, int *numpoints); +FMOD_RESULT F_API FMOD_Channel_Set3DOcclusion (FMOD_CHANNEL *channel, float directocclusion, float reverbocclusion); +FMOD_RESULT F_API FMOD_Channel_Get3DOcclusion (FMOD_CHANNEL *channel, float *directocclusion, float *reverbocclusion); +FMOD_RESULT F_API FMOD_Channel_Set3DSpread (FMOD_CHANNEL *channel, float angle); +FMOD_RESULT F_API FMOD_Channel_Get3DSpread (FMOD_CHANNEL *channel, float *angle); +FMOD_RESULT F_API FMOD_Channel_Set3DPanLevel (FMOD_CHANNEL *channel, float level); +FMOD_RESULT F_API FMOD_Channel_Get3DPanLevel (FMOD_CHANNEL *channel, float *level); +FMOD_RESULT F_API FMOD_Channel_Set3DDopplerLevel (FMOD_CHANNEL *channel, float level); +FMOD_RESULT F_API FMOD_Channel_Get3DDopplerLevel (FMOD_CHANNEL *channel, float *level); +FMOD_RESULT F_API FMOD_Channel_Set3DDistanceFilter (FMOD_CHANNEL *channel, FMOD_BOOL custom, float customLevel, float centerFreq); +FMOD_RESULT F_API FMOD_Channel_Get3DDistanceFilter (FMOD_CHANNEL *channel, FMOD_BOOL *custom, float *customLevel, float *centerFreq); + +/* + DSP functionality only for channels playing sounds created with FMOD_SOFTWARE. +*/ + +FMOD_RESULT F_API FMOD_Channel_GetDSPHead (FMOD_CHANNEL *channel, FMOD_DSP **dsp); +FMOD_RESULT F_API FMOD_Channel_AddDSP (FMOD_CHANNEL *channel, FMOD_DSP *dsp, FMOD_DSPCONNECTION **connection); + +/* + Information only functions. +*/ + +FMOD_RESULT F_API FMOD_Channel_IsPlaying (FMOD_CHANNEL *channel, FMOD_BOOL *isplaying); +FMOD_RESULT F_API FMOD_Channel_IsVirtual (FMOD_CHANNEL *channel, FMOD_BOOL *isvirtual); +FMOD_RESULT F_API FMOD_Channel_GetAudibility (FMOD_CHANNEL *channel, float *audibility); +FMOD_RESULT F_API FMOD_Channel_GetCurrentSound (FMOD_CHANNEL *channel, FMOD_SOUND **sound); +FMOD_RESULT F_API FMOD_Channel_GetSpectrum (FMOD_CHANNEL *channel, float *spectrumarray, int numvalues, int channeloffset, FMOD_DSP_FFT_WINDOW windowtype); +FMOD_RESULT F_API FMOD_Channel_GetWaveData (FMOD_CHANNEL *channel, float *wavearray, int numvalues, int channeloffset); +FMOD_RESULT F_API FMOD_Channel_GetIndex (FMOD_CHANNEL *channel, int *index); + +/* + Functions also found in Sound class but here they can be set per channel. +*/ + +FMOD_RESULT F_API FMOD_Channel_SetMode (FMOD_CHANNEL *channel, FMOD_MODE mode); +FMOD_RESULT F_API FMOD_Channel_GetMode (FMOD_CHANNEL *channel, FMOD_MODE *mode); +FMOD_RESULT F_API FMOD_Channel_SetLoopCount (FMOD_CHANNEL *channel, int loopcount); +FMOD_RESULT F_API FMOD_Channel_GetLoopCount (FMOD_CHANNEL *channel, int *loopcount); +FMOD_RESULT F_API FMOD_Channel_SetLoopPoints (FMOD_CHANNEL *channel, unsigned int loopstart, FMOD_TIMEUNIT loopstarttype, unsigned int loopend, FMOD_TIMEUNIT loopendtype); +FMOD_RESULT F_API FMOD_Channel_GetLoopPoints (FMOD_CHANNEL *channel, unsigned int *loopstart, FMOD_TIMEUNIT loopstarttype, unsigned int *loopend, FMOD_TIMEUNIT loopendtype); + +/* + Userdata set/get. +*/ + +FMOD_RESULT F_API FMOD_Channel_SetUserData (FMOD_CHANNEL *channel, void *userdata); +FMOD_RESULT F_API FMOD_Channel_GetUserData (FMOD_CHANNEL *channel, void **userdata); + +FMOD_RESULT F_API FMOD_Channel_GetMemoryInfo (FMOD_CHANNEL *channel, unsigned int memorybits, unsigned int event_memorybits, unsigned int *memoryused, FMOD_MEMORY_USAGE_DETAILS *memoryused_details); + +/* + 'ChannelGroup' API +*/ + +FMOD_RESULT F_API FMOD_ChannelGroup_Release (FMOD_CHANNELGROUP *channelgroup); +FMOD_RESULT F_API FMOD_ChannelGroup_GetSystemObject (FMOD_CHANNELGROUP *channelgroup, FMOD_SYSTEM **system); + +/* + Channelgroup scale values. (changes attributes relative to the channels, doesn't overwrite them) +*/ + +FMOD_RESULT F_API FMOD_ChannelGroup_SetVolume (FMOD_CHANNELGROUP *channelgroup, float volume); +FMOD_RESULT F_API FMOD_ChannelGroup_GetVolume (FMOD_CHANNELGROUP *channelgroup, float *volume); +FMOD_RESULT F_API FMOD_ChannelGroup_SetPitch (FMOD_CHANNELGROUP *channelgroup, float pitch); +FMOD_RESULT F_API FMOD_ChannelGroup_GetPitch (FMOD_CHANNELGROUP *channelgroup, float *pitch); +FMOD_RESULT F_API FMOD_ChannelGroup_Set3DOcclusion (FMOD_CHANNELGROUP *channelgroup, float directocclusion, float reverbocclusion); +FMOD_RESULT F_API FMOD_ChannelGroup_Get3DOcclusion (FMOD_CHANNELGROUP *channelgroup, float *directocclusion, float *reverbocclusion); +FMOD_RESULT F_API FMOD_ChannelGroup_SetPaused (FMOD_CHANNELGROUP *channelgroup, FMOD_BOOL paused); +FMOD_RESULT F_API FMOD_ChannelGroup_GetPaused (FMOD_CHANNELGROUP *channelgroup, FMOD_BOOL *paused); +FMOD_RESULT F_API FMOD_ChannelGroup_SetMute (FMOD_CHANNELGROUP *channelgroup, FMOD_BOOL mute); +FMOD_RESULT F_API FMOD_ChannelGroup_GetMute (FMOD_CHANNELGROUP *channelgroup, FMOD_BOOL *mute); + +/* + Channelgroup override values. (recursively overwrites whatever settings the channels had) +*/ + +FMOD_RESULT F_API FMOD_ChannelGroup_Stop (FMOD_CHANNELGROUP *channelgroup); +FMOD_RESULT F_API FMOD_ChannelGroup_OverrideVolume (FMOD_CHANNELGROUP *channelgroup, float volume); +FMOD_RESULT F_API FMOD_ChannelGroup_OverrideFrequency(FMOD_CHANNELGROUP *channelgroup, float frequency); +FMOD_RESULT F_API FMOD_ChannelGroup_OverridePan (FMOD_CHANNELGROUP *channelgroup, float pan); +FMOD_RESULT F_API FMOD_ChannelGroup_OverrideReverbProperties(FMOD_CHANNELGROUP *channelgroup, const FMOD_REVERB_CHANNELPROPERTIES *prop); +FMOD_RESULT F_API FMOD_ChannelGroup_Override3DAttributes(FMOD_CHANNELGROUP *channelgroup, const FMOD_VECTOR *pos, const FMOD_VECTOR *vel); +FMOD_RESULT F_API FMOD_ChannelGroup_OverrideSpeakerMix(FMOD_CHANNELGROUP *channelgroup, float frontleft, float frontright, float center, float lfe, float backleft, float backright, float sideleft, float sideright); + +/* + Nested channel groups. +*/ + +FMOD_RESULT F_API FMOD_ChannelGroup_AddGroup (FMOD_CHANNELGROUP *channelgroup, FMOD_CHANNELGROUP *group); +FMOD_RESULT F_API FMOD_ChannelGroup_GetNumGroups (FMOD_CHANNELGROUP *channelgroup, int *numgroups); +FMOD_RESULT F_API FMOD_ChannelGroup_GetGroup (FMOD_CHANNELGROUP *channelgroup, int index, FMOD_CHANNELGROUP **group); +FMOD_RESULT F_API FMOD_ChannelGroup_GetParentGroup (FMOD_CHANNELGROUP *channelgroup, FMOD_CHANNELGROUP **group); + +/* + DSP functionality only for channel groups playing sounds created with FMOD_SOFTWARE. +*/ + +FMOD_RESULT F_API FMOD_ChannelGroup_GetDSPHead (FMOD_CHANNELGROUP *channelgroup, FMOD_DSP **dsp); +FMOD_RESULT F_API FMOD_ChannelGroup_AddDSP (FMOD_CHANNELGROUP *channelgroup, FMOD_DSP *dsp, FMOD_DSPCONNECTION **connection); + +/* + Information only functions. +*/ + +FMOD_RESULT F_API FMOD_ChannelGroup_GetName (FMOD_CHANNELGROUP *channelgroup, char *name, int namelen); +FMOD_RESULT F_API FMOD_ChannelGroup_GetNumChannels (FMOD_CHANNELGROUP *channelgroup, int *numchannels); +FMOD_RESULT F_API FMOD_ChannelGroup_GetChannel (FMOD_CHANNELGROUP *channelgroup, int index, FMOD_CHANNEL **channel); +FMOD_RESULT F_API FMOD_ChannelGroup_GetSpectrum (FMOD_CHANNELGROUP *channelgroup, float *spectrumarray, int numvalues, int channeloffset, FMOD_DSP_FFT_WINDOW windowtype); +FMOD_RESULT F_API FMOD_ChannelGroup_GetWaveData (FMOD_CHANNELGROUP *channelgroup, float *wavearray, int numvalues, int channeloffset); + +/* + Userdata set/get. +*/ + +FMOD_RESULT F_API FMOD_ChannelGroup_SetUserData (FMOD_CHANNELGROUP *channelgroup, void *userdata); +FMOD_RESULT F_API FMOD_ChannelGroup_GetUserData (FMOD_CHANNELGROUP *channelgroup, void **userdata); + +FMOD_RESULT F_API FMOD_ChannelGroup_GetMemoryInfo (FMOD_CHANNELGROUP *channelgroup, unsigned int memorybits, unsigned int event_memorybits, unsigned int *memoryused, FMOD_MEMORY_USAGE_DETAILS *memoryused_details); + +/* + 'SoundGroup' API +*/ + +FMOD_RESULT F_API FMOD_SoundGroup_Release (FMOD_SOUNDGROUP *soundgroup); +FMOD_RESULT F_API FMOD_SoundGroup_GetSystemObject (FMOD_SOUNDGROUP *soundgroup, FMOD_SYSTEM **system); + +/* + SoundGroup control functions. +*/ + +FMOD_RESULT F_API FMOD_SoundGroup_SetMaxAudible (FMOD_SOUNDGROUP *soundgroup, int maxaudible); +FMOD_RESULT F_API FMOD_SoundGroup_GetMaxAudible (FMOD_SOUNDGROUP *soundgroup, int *maxaudible); +FMOD_RESULT F_API FMOD_SoundGroup_SetMaxAudibleBehavior(FMOD_SOUNDGROUP *soundgroup, FMOD_SOUNDGROUP_BEHAVIOR behavior); +FMOD_RESULT F_API FMOD_SoundGroup_GetMaxAudibleBehavior(FMOD_SOUNDGROUP *soundgroup, FMOD_SOUNDGROUP_BEHAVIOR *behavior); +FMOD_RESULT F_API FMOD_SoundGroup_SetMuteFadeSpeed (FMOD_SOUNDGROUP *soundgroup, float speed); +FMOD_RESULT F_API FMOD_SoundGroup_GetMuteFadeSpeed (FMOD_SOUNDGROUP *soundgroup, float *speed); +FMOD_RESULT F_API FMOD_SoundGroup_SetVolume (FMOD_SOUNDGROUP *soundgroup, float volume); +FMOD_RESULT F_API FMOD_SoundGroup_GetVolume (FMOD_SOUNDGROUP *soundgroup, float *volume); +FMOD_RESULT F_API FMOD_SoundGroup_Stop (FMOD_SOUNDGROUP *soundgroup); + +/* + Information only functions. +*/ + +FMOD_RESULT F_API FMOD_SoundGroup_GetName (FMOD_SOUNDGROUP *soundgroup, char *name, int namelen); +FMOD_RESULT F_API FMOD_SoundGroup_GetNumSounds (FMOD_SOUNDGROUP *soundgroup, int *numsounds); +FMOD_RESULT F_API FMOD_SoundGroup_GetSound (FMOD_SOUNDGROUP *soundgroup, int index, FMOD_SOUND **sound); +FMOD_RESULT F_API FMOD_SoundGroup_GetNumPlaying (FMOD_SOUNDGROUP *soundgroup, int *numplaying); + +/* + Userdata set/get. +*/ + +FMOD_RESULT F_API FMOD_SoundGroup_SetUserData (FMOD_SOUNDGROUP *soundgroup, void *userdata); +FMOD_RESULT F_API FMOD_SoundGroup_GetUserData (FMOD_SOUNDGROUP *soundgroup, void **userdata); + +FMOD_RESULT F_API FMOD_SoundGroup_GetMemoryInfo (FMOD_SOUNDGROUP *soundgroup, unsigned int memorybits, unsigned int event_memorybits, unsigned int *memoryused, FMOD_MEMORY_USAGE_DETAILS *memoryused_details); + +/* + 'DSP' API +*/ + +FMOD_RESULT F_API FMOD_DSP_Release (FMOD_DSP *dsp); +FMOD_RESULT F_API FMOD_DSP_GetSystemObject (FMOD_DSP *dsp, FMOD_SYSTEM **system); + +/* + Connection / disconnection / input and output enumeration. +*/ + +FMOD_RESULT F_API FMOD_DSP_AddInput (FMOD_DSP *dsp, FMOD_DSP *target, FMOD_DSPCONNECTION **connection); +FMOD_RESULT F_API FMOD_DSP_DisconnectFrom (FMOD_DSP *dsp, FMOD_DSP *target); +FMOD_RESULT F_API FMOD_DSP_DisconnectAll (FMOD_DSP *dsp, FMOD_BOOL inputs, FMOD_BOOL outputs); +FMOD_RESULT F_API FMOD_DSP_Remove (FMOD_DSP *dsp); +FMOD_RESULT F_API FMOD_DSP_GetNumInputs (FMOD_DSP *dsp, int *numinputs); +FMOD_RESULT F_API FMOD_DSP_GetNumOutputs (FMOD_DSP *dsp, int *numoutputs); +FMOD_RESULT F_API FMOD_DSP_GetInput (FMOD_DSP *dsp, int index, FMOD_DSP **input, FMOD_DSPCONNECTION **inputconnection); +FMOD_RESULT F_API FMOD_DSP_GetOutput (FMOD_DSP *dsp, int index, FMOD_DSP **output, FMOD_DSPCONNECTION **outputconnection); + +/* + DSP unit control. +*/ + +FMOD_RESULT F_API FMOD_DSP_SetActive (FMOD_DSP *dsp, FMOD_BOOL active); +FMOD_RESULT F_API FMOD_DSP_GetActive (FMOD_DSP *dsp, FMOD_BOOL *active); +FMOD_RESULT F_API FMOD_DSP_SetBypass (FMOD_DSP *dsp, FMOD_BOOL bypass); +FMOD_RESULT F_API FMOD_DSP_GetBypass (FMOD_DSP *dsp, FMOD_BOOL *bypass); +FMOD_RESULT F_API FMOD_DSP_SetSpeakerActive (FMOD_DSP *dsp, FMOD_SPEAKER speaker, FMOD_BOOL active); +FMOD_RESULT F_API FMOD_DSP_GetSpeakerActive (FMOD_DSP *dsp, FMOD_SPEAKER speaker, FMOD_BOOL *active); +FMOD_RESULT F_API FMOD_DSP_Reset (FMOD_DSP *dsp); + +/* + DSP parameter control. +*/ + +FMOD_RESULT F_API FMOD_DSP_SetParameter (FMOD_DSP *dsp, int index, float value); +FMOD_RESULT F_API FMOD_DSP_GetParameter (FMOD_DSP *dsp, int index, float *value, char *valuestr, int valuestrlen); +FMOD_RESULT F_API FMOD_DSP_GetNumParameters (FMOD_DSP *dsp, int *numparams); +FMOD_RESULT F_API FMOD_DSP_GetParameterInfo (FMOD_DSP *dsp, int index, char *name, char *label, char *description, int descriptionlen, float *min, float *max); +FMOD_RESULT F_API FMOD_DSP_ShowConfigDialog (FMOD_DSP *dsp, void *hwnd, FMOD_BOOL show); + +/* + DSP attributes. +*/ + +FMOD_RESULT F_API FMOD_DSP_GetInfo (FMOD_DSP *dsp, char *name, unsigned int *version, int *channels, int *configwidth, int *configheight); +FMOD_RESULT F_API FMOD_DSP_GetType (FMOD_DSP *dsp, FMOD_DSP_TYPE *type); +FMOD_RESULT F_API FMOD_DSP_SetDefaults (FMOD_DSP *dsp, float frequency, float volume, float pan, int priority); +FMOD_RESULT F_API FMOD_DSP_GetDefaults (FMOD_DSP *dsp, float *frequency, float *volume, float *pan, int *priority); + +/* + Userdata set/get. +*/ + +FMOD_RESULT F_API FMOD_DSP_SetUserData (FMOD_DSP *dsp, void *userdata); +FMOD_RESULT F_API FMOD_DSP_GetUserData (FMOD_DSP *dsp, void **userdata); + +FMOD_RESULT F_API FMOD_DSP_GetMemoryInfo (FMOD_DSP *dsp, unsigned int memorybits, unsigned int event_memorybits, unsigned int *memoryused, FMOD_MEMORY_USAGE_DETAILS *memoryused_details); + +/* + 'DSPConnection' API +*/ + +FMOD_RESULT F_API FMOD_DSPConnection_GetInput (FMOD_DSPCONNECTION *dspconnection, FMOD_DSP **input); +FMOD_RESULT F_API FMOD_DSPConnection_GetOutput (FMOD_DSPCONNECTION *dspconnection, FMOD_DSP **output); +FMOD_RESULT F_API FMOD_DSPConnection_SetMix (FMOD_DSPCONNECTION *dspconnection, float volume); +FMOD_RESULT F_API FMOD_DSPConnection_GetMix (FMOD_DSPCONNECTION *dspconnection, float *volume); +FMOD_RESULT F_API FMOD_DSPConnection_SetLevels (FMOD_DSPCONNECTION *dspconnection, FMOD_SPEAKER speaker, float *levels, int numlevels); +FMOD_RESULT F_API FMOD_DSPConnection_GetLevels (FMOD_DSPCONNECTION *dspconnection, FMOD_SPEAKER speaker, float *levels, int numlevels); + +/* + Userdata set/get. +*/ + +FMOD_RESULT F_API FMOD_DSPConnection_SetUserData (FMOD_DSPCONNECTION *dspconnection, void *userdata); +FMOD_RESULT F_API FMOD_DSPConnection_GetUserData (FMOD_DSPCONNECTION *dspconnection, void **userdata); + +FMOD_RESULT F_API FMOD_DSPConnection_GetMemoryInfo (FMOD_DSPCONNECTION *dspconnection, unsigned int memorybits, unsigned int event_memorybits, unsigned int *memoryused, FMOD_MEMORY_USAGE_DETAILS *memoryused_details); + +/* + 'Geometry' API +*/ + +FMOD_RESULT F_API FMOD_Geometry_Release (FMOD_GEOMETRY *geometry); + +/* + Polygon manipulation. +*/ + +FMOD_RESULT F_API FMOD_Geometry_AddPolygon (FMOD_GEOMETRY *geometry, float directocclusion, float reverbocclusion, FMOD_BOOL doublesided, int numvertices, const FMOD_VECTOR *vertices, int *polygonindex); +FMOD_RESULT F_API FMOD_Geometry_GetNumPolygons (FMOD_GEOMETRY *geometry, int *numpolygons); +FMOD_RESULT F_API FMOD_Geometry_GetMaxPolygons (FMOD_GEOMETRY *geometry, int *maxpolygons, int *maxvertices); +FMOD_RESULT F_API FMOD_Geometry_GetPolygonNumVertices(FMOD_GEOMETRY *geometry, int index, int *numvertices); +FMOD_RESULT F_API FMOD_Geometry_SetPolygonVertex (FMOD_GEOMETRY *geometry, int index, int vertexindex, const FMOD_VECTOR *vertex); +FMOD_RESULT F_API FMOD_Geometry_GetPolygonVertex (FMOD_GEOMETRY *geometry, int index, int vertexindex, FMOD_VECTOR *vertex); +FMOD_RESULT F_API FMOD_Geometry_SetPolygonAttributes (FMOD_GEOMETRY *geometry, int index, float directocclusion, float reverbocclusion, FMOD_BOOL doublesided); +FMOD_RESULT F_API FMOD_Geometry_GetPolygonAttributes (FMOD_GEOMETRY *geometry, int index, float *directocclusion, float *reverbocclusion, FMOD_BOOL *doublesided); + +/* + Object manipulation. +*/ + +FMOD_RESULT F_API FMOD_Geometry_SetActive (FMOD_GEOMETRY *geometry, FMOD_BOOL active); +FMOD_RESULT F_API FMOD_Geometry_GetActive (FMOD_GEOMETRY *geometry, FMOD_BOOL *active); +FMOD_RESULT F_API FMOD_Geometry_SetRotation (FMOD_GEOMETRY *geometry, const FMOD_VECTOR *forward, const FMOD_VECTOR *up); +FMOD_RESULT F_API FMOD_Geometry_GetRotation (FMOD_GEOMETRY *geometry, FMOD_VECTOR *forward, FMOD_VECTOR *up); +FMOD_RESULT F_API FMOD_Geometry_SetPosition (FMOD_GEOMETRY *geometry, const FMOD_VECTOR *position); +FMOD_RESULT F_API FMOD_Geometry_GetPosition (FMOD_GEOMETRY *geometry, FMOD_VECTOR *position); +FMOD_RESULT F_API FMOD_Geometry_SetScale (FMOD_GEOMETRY *geometry, const FMOD_VECTOR *scale); +FMOD_RESULT F_API FMOD_Geometry_GetScale (FMOD_GEOMETRY *geometry, FMOD_VECTOR *scale); +FMOD_RESULT F_API FMOD_Geometry_Save (FMOD_GEOMETRY *geometry, void *data, int *datasize); + +/* + Userdata set/get. +*/ + +FMOD_RESULT F_API FMOD_Geometry_SetUserData (FMOD_GEOMETRY *geometry, void *userdata); +FMOD_RESULT F_API FMOD_Geometry_GetUserData (FMOD_GEOMETRY *geometry, void **userdata); + +FMOD_RESULT F_API FMOD_Geometry_GetMemoryInfo (FMOD_GEOMETRY *geometry, unsigned int memorybits, unsigned int event_memorybits, unsigned int *memoryused, FMOD_MEMORY_USAGE_DETAILS *memoryused_details); + +/* + 'Reverb' API +*/ + +FMOD_RESULT F_API FMOD_Reverb_Release (FMOD_REVERB *reverb); + +/* + Reverb manipulation. +*/ + +FMOD_RESULT F_API FMOD_Reverb_Set3DAttributes (FMOD_REVERB *reverb, const FMOD_VECTOR *position, float mindistance, float maxdistance); +FMOD_RESULT F_API FMOD_Reverb_Get3DAttributes (FMOD_REVERB *reverb, FMOD_VECTOR *position, float *mindistance, float *maxdistance); +FMOD_RESULT F_API FMOD_Reverb_SetProperties (FMOD_REVERB *reverb, const FMOD_REVERB_PROPERTIES *properties); +FMOD_RESULT F_API FMOD_Reverb_GetProperties (FMOD_REVERB *reverb, FMOD_REVERB_PROPERTIES *properties); +FMOD_RESULT F_API FMOD_Reverb_SetActive (FMOD_REVERB *reverb, FMOD_BOOL active); +FMOD_RESULT F_API FMOD_Reverb_GetActive (FMOD_REVERB *reverb, FMOD_BOOL *active); + +/* + Userdata set/get. +*/ + +FMOD_RESULT F_API FMOD_Reverb_SetUserData (FMOD_REVERB *reverb, void *userdata); +FMOD_RESULT F_API FMOD_Reverb_GetUserData (FMOD_REVERB *reverb, void **userdata); + +FMOD_RESULT F_API FMOD_Reverb_GetMemoryInfo (FMOD_REVERB *reverb, unsigned int memorybits, unsigned int event_memorybits, unsigned int *memoryused, FMOD_MEMORY_USAGE_DETAILS *memoryused_details); + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/libs/fmodex/inc/fmod_codec.h b/libs/fmodex/inc/fmod_codec.h new file mode 100644 index 000000000..2e13eb69d --- /dev/null +++ b/libs/fmodex/inc/fmod_codec.h @@ -0,0 +1,159 @@ +/* ==================================================================================================== */ +/* FMOD Ex - codec development header file. Copyright (c), Firelight Technologies Pty, Ltd. 2004-2011. */ +/* */ +/* Use this header if you are wanting to develop your own file format plugin to use with */ +/* FMOD's codec system. With this header you can make your own fileformat plugin that FMOD */ +/* can register and use. See the documentation and examples on how to make a working plugin. */ +/* */ +/* ==================================================================================================== */ + +#ifndef _FMOD_CODEC_H +#define _FMOD_CODEC_H + +typedef struct FMOD_CODEC_STATE FMOD_CODEC_STATE; +typedef struct FMOD_CODEC_WAVEFORMAT FMOD_CODEC_WAVEFORMAT; + +/* + Codec callbacks +*/ +typedef FMOD_RESULT (F_CALLBACK *FMOD_CODEC_OPENCALLBACK) (FMOD_CODEC_STATE *codec_state, FMOD_MODE usermode, FMOD_CREATESOUNDEXINFO *userexinfo); +typedef FMOD_RESULT (F_CALLBACK *FMOD_CODEC_CLOSECALLBACK) (FMOD_CODEC_STATE *codec_state); +typedef FMOD_RESULT (F_CALLBACK *FMOD_CODEC_READCALLBACK) (FMOD_CODEC_STATE *codec_state, void *buffer, unsigned int sizebytes, unsigned int *bytesread); +typedef FMOD_RESULT (F_CALLBACK *FMOD_CODEC_GETLENGTHCALLBACK) (FMOD_CODEC_STATE *codec_state, unsigned int *length, FMOD_TIMEUNIT lengthtype); +typedef FMOD_RESULT (F_CALLBACK *FMOD_CODEC_SETPOSITIONCALLBACK) (FMOD_CODEC_STATE *codec_state, int subsound, unsigned int position, FMOD_TIMEUNIT postype); +typedef FMOD_RESULT (F_CALLBACK *FMOD_CODEC_GETPOSITIONCALLBACK) (FMOD_CODEC_STATE *codec_state, unsigned int *position, FMOD_TIMEUNIT postype); +typedef FMOD_RESULT (F_CALLBACK *FMOD_CODEC_SOUNDCREATECALLBACK) (FMOD_CODEC_STATE *codec_state, int subsound, FMOD_SOUND *sound); +typedef FMOD_RESULT (F_CALLBACK *FMOD_CODEC_METADATACALLBACK) (FMOD_CODEC_STATE *codec_state, FMOD_TAGTYPE tagtype, char *name, void *data, unsigned int datalen, FMOD_TAGDATATYPE datatype, int unique); +typedef FMOD_RESULT (F_CALLBACK *FMOD_CODEC_GETWAVEFORMAT) (FMOD_CODEC_STATE *codec_state, int index, FMOD_CODEC_WAVEFORMAT *waveformat); + + +/* +[STRUCTURE] +[ + [DESCRIPTION] + When creating a codec, declare one of these and provide the relevant callbacks and name for FMOD to use when it opens and reads a file. + + [REMARKS] + Members marked with [in] mean the variable can be written to. The user can set the value. + Members marked with [out] mean the variable is modified by FMOD and is for reading purposes only. Do not change this value. + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + FMOD_CODEC_STATE +] +*/ +typedef struct FMOD_CODEC_DESCRIPTION +{ + const char *name; /* [in] Name of the codec. */ + unsigned int version; /* [in] Plugin writer's version number. */ + int defaultasstream; /* [in] Tells FMOD to open the file as a stream when calling System::createSound, and not a static sample. Should normally be 0 (FALSE), because generally the user wants to decode the file into memory when using System::createSound. Mainly used for formats that decode for a very long time, or could use large amounts of memory when decoded. Usually sequenced formats such as mod/s3m/xm/it/midi fall into this category. It is mainly to stop users that don't know what they're doing from getting FMOD_ERR_MEMORY returned from createSound when they should have in fact called System::createStream or used FMOD_CREATESTREAM in System::createSound. */ + FMOD_TIMEUNIT timeunits; /* [in] When setposition codec is called, only these time formats will be passed to the codec. Use bitwise OR to accumulate different types. */ + FMOD_CODEC_OPENCALLBACK open; /* [in] Open callback for the codec for when FMOD tries to open a sound using this codec. */ + FMOD_CODEC_CLOSECALLBACK close; /* [in] Close callback for the codec for when FMOD tries to close a sound using this codec. */ + FMOD_CODEC_READCALLBACK read; /* [in] Read callback for the codec for when FMOD tries to read some data from the file to the destination format (specified in the open callback). */ + FMOD_CODEC_GETLENGTHCALLBACK getlength; /* [in] Callback to return the length of the song in whatever format required when Sound::getLength is called. */ + FMOD_CODEC_SETPOSITIONCALLBACK setposition; /* [in] Seek callback for the codec for when FMOD tries to seek within the file with Channel::setPosition. */ + FMOD_CODEC_GETPOSITIONCALLBACK getposition; /* [in] Tell callback for the codec for when FMOD tries to get the current position within the with Channel::getPosition. */ + FMOD_CODEC_SOUNDCREATECALLBACK soundcreate; /* [in] Sound creation callback for the codec when FMOD finishes creating the sound. (So the codec can set more parameters for the related created sound, ie loop points/mode or 3D attributes etc). */ + FMOD_CODEC_GETWAVEFORMAT getwaveformat; /* [in] Callback to tell FMOD about the waveformat of a particular subsound. This is to save memory, rather than saving 1000 FMOD_CODEC_WAVEFORMAT structures in the codec, the codec might have a more optimal way of storing this information. */ +} FMOD_CODEC_DESCRIPTION; + + +/* +[STRUCTURE] +[ + [DESCRIPTION] + Set these values marked 'in' to tell fmod what sort of sound to create. + The format, channels and frequency tell FMOD what sort of hardware buffer to create when you initialize your code. So if you wrote an MP3 codec that decoded to stereo 16bit integer PCM, you would specify FMOD_SOUND_FORMAT_PCM16, and channels would be equal to 2. + Members marked as 'out' are set by fmod. Do not modify these. Simply specify 0 for these values when declaring the structure, FMOD will fill in the values for you after creation with the correct function pointers. + + [REMARKS] + Members marked with [in] mean the variable can be written to. The user can set the value. + Members marked with [out] mean the variable is modified by FMOD and is for reading purposes only. Do not change this value. + + An FMOD file might be from disk, memory or network, however the file may be opened by the user. + + 'numsubsounds' should be 0 if the file is a normal single sound stream or sound. Examples of this would be .WAV, .WMA, .MP3, .AIFF. + 'numsubsounds' should be 1+ if the file is a container format, and does not contain wav data itself. Examples of these types would be CDDA (multiple CD tracks), FSB (contains multiple sounds), MIDI/MOD/S3M/XM/IT (contain instruments). + The arrays of format, channel, frequency, length and blockalign should point to arrays of information based on how many subsounds are in the format. If the number of subsounds is 0 then it should point to 1 of each attribute, the same as if the number of subsounds was 1. If subsounds was 100 for example, each pointer should point to an array of 100 of each attribute. + When a sound has 1 or more subsounds, you must play the individual sounds specified by first obtaining the subsound with Sound::getSubSound. + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + FMOD_SOUND_FORMAT + FMOD_FILE_READCALLBACK + FMOD_FILE_SEEKCALLBACK + FMOD_CODEC_METADATACALLBACK + Sound::getSubSound + Sound::getNumSubSounds +] +*/ +struct FMOD_CODEC_WAVEFORMAT +{ + char name[256]; /* [in] Name of sound.*/ + FMOD_SOUND_FORMAT format; /* [in] Format for (decompressed) codec output, ie FMOD_SOUND_FORMAT_PCM8, FMOD_SOUND_FORMAT_PCM16.*/ + int channels; /* [in] Number of channels used by codec, ie mono = 1, stereo = 2. */ + int frequency; /* [in] Default frequency in hz of the codec, ie 44100. */ + unsigned int lengthbytes; /* [in] Length in bytes of the source data. */ + unsigned int lengthpcm; /* [in] Length in decompressed, PCM samples of the file, ie length in seconds * frequency. Used for Sound::getLength and for memory allocation of static decompressed sample data. */ + int blockalign; /* [in] Blockalign in decompressed, PCM samples of the optimal decode chunk size for this format. The codec read callback will be called in multiples of this value. */ + int loopstart; /* [in] Loopstart in decompressed, PCM samples of file. */ + int loopend; /* [in] Loopend in decompressed, PCM samples of file. */ + FMOD_MODE mode; /* [in] Mode to determine whether the sound should by default load as looping, non looping, 2d or 3d. */ + unsigned int channelmask; /* [in] Microsoft speaker channel mask, as defined for WAVEFORMATEXTENSIBLE and is found in ksmedia.h. Leave at 0 to play in natural speaker order. */ +}; + + +/* +[STRUCTURE] +[ + [DESCRIPTION] + Codec plugin structure that is passed into each callback. + + Set these numsubsounds and waveformat members when called in FMOD_CODEC_OPENCALLBACK to tell fmod what sort of sound to create. + + The format, channels and frequency tell FMOD what sort of hardware buffer to create when you initialize your code. So if you wrote an MP3 codec that decoded to stereo 16bit integer PCM, you would specify FMOD_SOUND_FORMAT_PCM16, and channels would be equal to 2. + + [REMARKS] + Members marked with [in] mean the variable can be written to. The user can set the value. + Members marked with [out] mean the variable is modified by FMOD and is for reading purposes only. Do not change this value. + + An FMOD file might be from disk, memory or internet, however the file may be opened by the user. + + 'numsubsounds' should be 0 if the file is a normal single sound stream or sound. Examples of this would be .WAV, .WMA, .MP3, .AIFF. + 'numsubsounds' should be 1+ if the file is a container format, and does not contain wav data itself. Examples of these types would be CDDA (multiple CD tracks), FSB (contains multiple sounds), DLS (contain instruments). + The arrays of format, channel, frequency, length and blockalign should point to arrays of information based on how many subsounds are in the format. If the number of subsounds is 0 then it should point to 1 of each attribute, the same as if the number of subsounds was 1. If subsounds was 100 for example, each pointer should point to an array of 100 of each attribute. + When a sound has 1 or more subsounds, you must play the individual sounds specified by first obtaining the subsound with Sound::getSubSound. + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + FMOD_SOUND_FORMAT + FMOD_FILE_READCALLBACK + FMOD_FILE_SEEKCALLBACK + FMOD_CODEC_METADATACALLBACK + Sound::getSubSound + Sound::getNumSubSounds +] +*/ +struct FMOD_CODEC_STATE +{ + int numsubsounds; /* [in] Number of 'subsounds' in this sound. Anything other than 0 makes it a 'container' format (ie CDDA/DLS/FSB etc which contain 1 or more su bsounds). For most normal, single sound codec such as WAV/AIFF/MP3, this should be 0 as they are not a container for subsounds, they are the sound by itself. */ + FMOD_CODEC_WAVEFORMAT *waveformat; /* [in] Pointer to an array of format structures containing information about each sample. Can be 0 or NULL if FMOD_CODEC_GETWAVEFORMAT callback is preferred. The number of entries here must equal the number of subsounds defined in the subsound parameter. If numsubsounds = 0 then there should be 1 instance of this structure. */ + void *plugindata; /* [in] Plugin writer created data the codec author wants to attach to this object. */ + + void *filehandle; /* [out] This will return an internal FMOD file handle to use with the callbacks provided. */ + unsigned int filesize; /* [out] This will contain the size of the file in bytes. */ + FMOD_FILE_READCALLBACK fileread; /* [out] This will return a callable FMOD file function to use from codec. */ + FMOD_FILE_SEEKCALLBACK fileseek; /* [out] This will return a callable FMOD file function to use from codec. */ + FMOD_CODEC_METADATACALLBACK metadata; /* [out] This will return a callable FMOD metadata function to use from codec. */ +}; + +#endif + + diff --git a/libs/fmodex/inc/fmod_dsp.h b/libs/fmodex/inc/fmod_dsp.h new file mode 100644 index 000000000..1c5e2a62b --- /dev/null +++ b/libs/fmodex/inc/fmod_dsp.h @@ -0,0 +1,743 @@ +/* ========================================================================================== */ +/* FMOD Ex - DSP header file. Copyright (c), Firelight Technologies Pty, Ltd. 2004-2011. */ +/* */ +/* Use this header if you are interested in delving deeper into the FMOD software mixing / */ +/* DSP engine. In this header you can find parameter structures for FMOD system reigstered */ +/* DSP effects and generators. */ +/* Also use this header if you are wanting to develop your own DSP plugin to use with FMOD's */ +/* dsp system. With this header you can make your own DSP plugin that FMOD can */ +/* register and use. See the documentation and examples on how to make a working plugin. */ +/* */ +/* ========================================================================================== */ + +#ifndef _FMOD_DSP_H +#define _FMOD_DSP_H + +typedef struct FMOD_DSP_STATE FMOD_DSP_STATE; + +/* + DSP callbacks +*/ +typedef FMOD_RESULT (F_CALLBACK *FMOD_DSP_CREATECALLBACK) (FMOD_DSP_STATE *dsp_state); +typedef FMOD_RESULT (F_CALLBACK *FMOD_DSP_RELEASECALLBACK) (FMOD_DSP_STATE *dsp_state); +typedef FMOD_RESULT (F_CALLBACK *FMOD_DSP_RESETCALLBACK) (FMOD_DSP_STATE *dsp_state); +typedef FMOD_RESULT (F_CALLBACK *FMOD_DSP_READCALLBACK) (FMOD_DSP_STATE *dsp_state, float *inbuffer, float *outbuffer, unsigned int length, int inchannels, int outchannels); +typedef FMOD_RESULT (F_CALLBACK *FMOD_DSP_SETPOSITIONCALLBACK)(FMOD_DSP_STATE *dsp_state, unsigned int pos); +typedef FMOD_RESULT (F_CALLBACK *FMOD_DSP_SETPARAMCALLBACK) (FMOD_DSP_STATE *dsp_state, int index, float value); +typedef FMOD_RESULT (F_CALLBACK *FMOD_DSP_GETPARAMCALLBACK) (FMOD_DSP_STATE *dsp_state, int index, float *value, char *valuestr); +typedef FMOD_RESULT (F_CALLBACK *FMOD_DSP_DIALOGCALLBACK) (FMOD_DSP_STATE *dsp_state, void *hwnd, int show); + +/* +[ENUM] +[ + [DESCRIPTION] + These definitions can be used for creating FMOD defined special effects or DSP units. + + [REMARKS] + To get them to be active, first create the unit, then add it somewhere into the DSP network, either at the front of the network near the soundcard unit to affect the global output (by using System::getDSPHead), or on a single channel (using Channel::getDSPHead). + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + System::createDSPByType +] +*/ +typedef enum +{ + FMOD_DSP_TYPE_UNKNOWN, /* This unit was created via a non FMOD plugin so has an unknown purpose. */ + FMOD_DSP_TYPE_MIXER, /* This unit does nothing but take inputs and mix them together then feed the result to the soundcard unit. */ + FMOD_DSP_TYPE_OSCILLATOR, /* This unit generates sine/square/saw/triangle or noise tones. */ + FMOD_DSP_TYPE_LOWPASS, /* This unit filters sound using a high quality, resonant lowpass filter algorithm but consumes more CPU time. */ + FMOD_DSP_TYPE_ITLOWPASS, /* This unit filters sound using a resonant lowpass filter algorithm that is used in Impulse Tracker, but with limited cutoff range (0 to 8060hz). */ + FMOD_DSP_TYPE_HIGHPASS, /* This unit filters sound using a resonant highpass filter algorithm. */ + FMOD_DSP_TYPE_ECHO, /* This unit produces an echo on the sound and fades out at the desired rate. */ + FMOD_DSP_TYPE_FLANGE, /* This unit produces a flange effect on the sound. */ + FMOD_DSP_TYPE_DISTORTION, /* This unit distorts the sound. */ + FMOD_DSP_TYPE_NORMALIZE, /* This unit normalizes or amplifies the sound to a certain level. */ + FMOD_DSP_TYPE_PARAMEQ, /* This unit attenuates or amplifies a selected frequency range. */ + FMOD_DSP_TYPE_PITCHSHIFT, /* This unit bends the pitch of a sound without changing the speed of playback. */ + FMOD_DSP_TYPE_CHORUS, /* This unit produces a chorus effect on the sound. */ + FMOD_DSP_TYPE_VSTPLUGIN, /* This unit allows the use of Steinberg VST plugins */ + FMOD_DSP_TYPE_WINAMPPLUGIN, /* This unit allows the use of Nullsoft Winamp plugins */ + FMOD_DSP_TYPE_ITECHO, /* This unit produces an echo on the sound and fades out at the desired rate as is used in Impulse Tracker. */ + FMOD_DSP_TYPE_COMPRESSOR, /* This unit implements dynamic compression (linked multichannel, wideband) */ + FMOD_DSP_TYPE_SFXREVERB, /* This unit implements SFX reverb */ + FMOD_DSP_TYPE_LOWPASS_SIMPLE, /* This unit filters sound using a simple lowpass with no resonance, but has flexible cutoff and is fast. */ + FMOD_DSP_TYPE_DELAY, /* This unit produces different delays on individual channels of the sound. */ + FMOD_DSP_TYPE_TREMOLO, /* This unit produces a tremolo / chopper effect on the sound. */ + FMOD_DSP_TYPE_LADSPAPLUGIN, /* This unit allows the use of LADSPA standard plugins. */ + FMOD_DSP_TYPE_HIGHPASS_SIMPLE, /* This unit filters sound using a simple highpass with no resonance, but has flexible cutoff and is fast. */ + FMOD_DSP_TYPE_HARDWARE = 1000, /* Offset that platform specific FMOD_HARDWARE DSPs will start at. */ + FMOD_DSP_TYPE_FORCEINT = 65536 /* Makes sure this enum is signed 32bit. */ +} FMOD_DSP_TYPE; + + +/* +[STRUCTURE] +[ + [DESCRIPTION] + Structure to define a parameter for a DSP unit. + + [REMARKS] + Members marked with [r] mean the variable is modified by FMOD and is for reading purposes only. Do not change this value. + Members marked with [w] mean the variable can be written to. The user can set the value. + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + System::createDSP + DSP::setParameter +] +*/ +typedef struct FMOD_DSP_PARAMETERDESC +{ + float min; /* [w] Minimum value of the parameter (ie 100.0). */ + float max; /* [w] Maximum value of the parameter (ie 22050.0). */ + float defaultval; /* [w] Default value of parameter. */ + char name[16]; /* [w] Name of the parameter to be displayed (ie "Cutoff frequency"). */ + char label[16]; /* [w] Short string to be put next to value to denote the unit type (ie "hz"). */ + const char *description; /* [w] Description of the parameter to be displayed as a help item / tooltip for this parameter. */ +} FMOD_DSP_PARAMETERDESC; + + +/* +[STRUCTURE] +[ + [DESCRIPTION] + When creating a DSP unit, declare one of these and provide the relevant callbacks and name for FMOD to use when it creates and uses a DSP unit of this type. + + [REMARKS] + Members marked with [r] mean the variable is modified by FMOD and is for reading purposes only. Do not change this value. + Members marked with [w] mean the variable can be written to. The user can set the value. + + There are 2 different ways to change a parameter in this architecture. + One is to use DSP::setParameter / DSP::getParameter. This is platform independant and is dynamic, so new unknown plugins can have their parameters enumerated and used. + The other is to use DSP::showConfigDialog. This is platform specific and requires a GUI, and will display a dialog box to configure the plugin. + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + System::createDSP + FMOD_DSP_STATE +] +*/ +typedef struct FMOD_DSP_DESCRIPTION +{ + char name[32]; /* [w] Name of the unit to be displayed in the network. */ + unsigned int version; /* [w] Plugin writer's version number. */ + int channels; /* [w] Number of channels. Use 0 to process whatever number of channels is currently in the network. >0 would be mostly used if the unit is a unit that only generates sound. */ + FMOD_DSP_CREATECALLBACK create; /* [w] Create callback. This is called when DSP unit is created. Can be null. */ + FMOD_DSP_RELEASECALLBACK release; /* [w] Release callback. This is called just before the unit is freed so the user can do any cleanup needed for the unit. Can be null. */ + FMOD_DSP_RESETCALLBACK reset; /* [w] Reset callback. This is called by the user to reset any history buffers that may need resetting for a filter, when it is to be used or re-used for the first time to its initial clean state. Use to avoid clicks or artifacts. */ + FMOD_DSP_READCALLBACK read; /* [w] Read callback. Processing is done here. Can be null. */ + FMOD_DSP_SETPOSITIONCALLBACK setposition; /* [w] Set position callback. This is called if the unit wants to update its position info but not process data, or reset a cursor position internally if it is reading data from a certain source. Can be null. */ + + int numparameters; /* [w] Number of parameters used in this filter. The user finds this with DSP::getNumParameters */ + FMOD_DSP_PARAMETERDESC *paramdesc; /* [w] Variable number of parameter structures. */ + FMOD_DSP_SETPARAMCALLBACK setparameter; /* [w] This is called when the user calls DSP::setParameter. Can be null. */ + FMOD_DSP_GETPARAMCALLBACK getparameter; /* [w] This is called when the user calls DSP::getParameter. Can be null. */ + FMOD_DSP_DIALOGCALLBACK config; /* [w] This is called when the user calls DSP::showConfigDialog. Can be used to display a dialog to configure the filter. Can be null. */ + int configwidth; /* [w] Width of config dialog graphic if there is one. 0 otherwise.*/ + int configheight; /* [w] Height of config dialog graphic if there is one. 0 otherwise.*/ + void *userdata; /* [w] Optional. Specify 0 to ignore. This is user data to be attached to the DSP unit during creation. Access via DSP::getUserData. */ +} FMOD_DSP_DESCRIPTION; + + +/* +[STRUCTURE] +[ + [DESCRIPTION] + DSP plugin structure that is passed into each callback. + + [REMARKS] + Members marked with [r] mean the variable is modified by FMOD and is for reading purposes only. Do not change this value. + Members marked with [w] mean the variable can be written to. The user can set the value. + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + FMOD_DSP_DESCRIPTION +] +*/ +struct FMOD_DSP_STATE +{ + FMOD_DSP *instance; /* [r] Handle to the DSP hand the user created. Not to be modified. C++ users cast to FMOD::DSP to use. */ + void *plugindata; /* [w] Plugin writer created data the output author wants to attach to this object. */ + unsigned short speakermask; /* [w] Specifies which speakers the DSP effect is active on */ +}; + + +/* + =================================================================================================== + + FMOD built in effect parameters. + Use DSP::setParameter with these enums for the 'index' parameter. + + =================================================================================================== +*/ + +/* +[ENUM] +[ + [DESCRIPTION] + Parameter types for the FMOD_DSP_TYPE_OSCILLATOR filter. + + [REMARKS] + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + DSP::setParameter + DSP::getParameter + FMOD_DSP_TYPE +] +*/ +typedef enum +{ + FMOD_DSP_OSCILLATOR_TYPE, /* Waveform type. 0 = sine. 1 = square. 2 = sawup. 3 = sawdown. 4 = triangle. 5 = noise. */ + FMOD_DSP_OSCILLATOR_RATE /* Frequency of the sinewave in hz. 1.0 to 22000.0. Default = 220.0. */ +} FMOD_DSP_OSCILLATOR; + + +/* +[ENUM] +[ + [DESCRIPTION] + Parameter types for the FMOD_DSP_TYPE_LOWPASS filter. + + [REMARKS] + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + DSP::setParameter + DSP::getParameter + FMOD_DSP_TYPE +] +*/ +typedef enum +{ + FMOD_DSP_LOWPASS_CUTOFF, /* Lowpass cutoff frequency in hz. 10.0 to 22000.0. Default = 5000.0. */ + FMOD_DSP_LOWPASS_RESONANCE /* Lowpass resonance Q value. 1.0 to 10.0. Default = 1.0. */ +} FMOD_DSP_LOWPASS; + + +/* +[ENUM] +[ + [DESCRIPTION] + Parameter types for the FMOD_DSP_TYPE_ITLOWPASS filter. + This is different to the default FMOD_DSP_TYPE_ITLOWPASS filter in that it uses a different quality algorithm and is + the filter used to produce the correct sounding playback in .IT files. + FMOD Ex's .IT playback uses this filter. + + [REMARKS] + Note! This filter actually has a limited cutoff frequency below the specified maximum, due to its limited design, + so for a more open range filter use FMOD_DSP_LOWPASS or if you don't mind not having resonance, + FMOD_DSP_LOWPASS_SIMPLE. + The effective maximum cutoff is about 8060hz. + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + DSP::setParameter + DSP::getParameter + FMOD_DSP_TYPE +] +*/ +typedef enum +{ + FMOD_DSP_ITLOWPASS_CUTOFF, /* Lowpass cutoff frequency in hz. 1.0 to 22000.0. Default = 5000.0/ */ + FMOD_DSP_ITLOWPASS_RESONANCE /* Lowpass resonance Q value. 0.0 to 127.0. Default = 1.0. */ +} FMOD_DSP_ITLOWPASS; + + +/* +[ENUM] +[ + [DESCRIPTION] + Parameter types for the FMOD_DSP_TYPE_HIGHPASS filter. + + [REMARKS] + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + DSP::setParameter + DSP::getParameter + FMOD_DSP_TYPE +] +*/ +typedef enum +{ + FMOD_DSP_HIGHPASS_CUTOFF, /* Highpass cutoff frequency in hz. 1.0 to output 22000.0. Default = 5000.0. */ + FMOD_DSP_HIGHPASS_RESONANCE /* Highpass resonance Q value. 1.0 to 10.0. Default = 1.0. */ +} FMOD_DSP_HIGHPASS; + + +/* +[ENUM] +[ + [DESCRIPTION] + Parameter types for the FMOD_DSP_TYPE_ECHO filter. + + [REMARKS] + Note. Every time the delay is changed, the plugin re-allocates the echo buffer. This means the echo will dissapear at that time while it refills its new buffer. + Larger echo delays result in larger amounts of memory allocated. + + 'maxchannels' also dictates the amount of memory allocated. By default, the maxchannels value is 0. If FMOD is set to stereo, the echo unit will allocate enough memory for 2 channels. If it is 5.1, it will allocate enough memory for a 6 channel echo, etc. + If the echo effect is only ever applied to the global mix (ie it was added with System::addDSP), then 0 is the value to set as it will be enough to handle all speaker modes. + When the echo is added to a channel (ie Channel::addDSP) then the channel count that comes in could be anything from 1 to 8 possibly. It is only in this case where you might want to increase the channel count above the output's channel count. + If a channel echo is set to a lower number than the sound's channel count that is coming in, it will not echo the sound. + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + DSP::setParameter + DSP::getParameter + FMOD_DSP_TYPE +] +*/ +typedef enum +{ + FMOD_DSP_ECHO_DELAY, /* Echo delay in ms. 10 to 5000. Default = 500. */ + FMOD_DSP_ECHO_DECAYRATIO, /* Echo decay per delay. 0 to 1. 1.0 = No decay, 0.0 = total decay (ie simple 1 line delay). Default = 0.5. */ + FMOD_DSP_ECHO_MAXCHANNELS, /* Maximum channels supported. 0 to 16. 0 = same as fmod's default output polyphony, 1 = mono, 2 = stereo etc. See remarks for more. Default = 0. It is suggested to leave at 0! */ + FMOD_DSP_ECHO_DRYMIX, /* Volume of original signal to pass to output. 0.0 to 1.0. Default = 1.0. */ + FMOD_DSP_ECHO_WETMIX /* Volume of echo signal to pass to output. 0.0 to 1.0. Default = 1.0. */ +} FMOD_DSP_ECHO; + + +/* +[ENUM] +[ + [DESCRIPTION] + Parameter types for the FMOD_DSP_TYPE_DELAY filter. + + [REMARKS] + Note. Every time MaxDelay is changed, the plugin re-allocates the delay buffer. This means the delay will dissapear at that time while it refills its new buffer. + A larger MaxDelay results in larger amounts of memory allocated. + Channel delays above MaxDelay will be clipped to MaxDelay and the delay buffer will not be resized. + + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + DSP::setParameter + DSP::getParameter + FMOD_DSP_TYPE +] +*/ +typedef enum +{ + FMOD_DSP_DELAY_CH0, /* Channel #0 Delay in ms. 0 to 10000. Default = 0. */ + FMOD_DSP_DELAY_CH1, /* Channel #1 Delay in ms. 0 to 10000. Default = 0. */ + FMOD_DSP_DELAY_CH2, /* Channel #2 Delay in ms. 0 to 10000. Default = 0. */ + FMOD_DSP_DELAY_CH3, /* Channel #3 Delay in ms. 0 to 10000. Default = 0. */ + FMOD_DSP_DELAY_CH4, /* Channel #4 Delay in ms. 0 to 10000. Default = 0. */ + FMOD_DSP_DELAY_CH5, /* Channel #5 Delay in ms. 0 to 10000. Default = 0. */ + FMOD_DSP_DELAY_CH6, /* Channel #6 Delay in ms. 0 to 10000. Default = 0. */ + FMOD_DSP_DELAY_CH7, /* Channel #7 Delay in ms. 0 to 10000. Default = 0. */ + FMOD_DSP_DELAY_CH8, /* Channel #8 Delay in ms. 0 to 10000. Default = 0. */ + FMOD_DSP_DELAY_CH9, /* Channel #9 Delay in ms. 0 to 10000. Default = 0. */ + FMOD_DSP_DELAY_CH10, /* Channel #10 Delay in ms. 0 to 10000. Default = 0. */ + FMOD_DSP_DELAY_CH11, /* Channel #11 Delay in ms. 0 to 10000. Default = 0. */ + FMOD_DSP_DELAY_CH12, /* Channel #12 Delay in ms. 0 to 10000. Default = 0. */ + FMOD_DSP_DELAY_CH13, /* Channel #13 Delay in ms. 0 to 10000. Default = 0. */ + FMOD_DSP_DELAY_CH14, /* Channel #14 Delay in ms. 0 to 10000. Default = 0. */ + FMOD_DSP_DELAY_CH15, /* Channel #15 Delay in ms. 0 to 10000. Default = 0. */ + FMOD_DSP_DELAY_MAXDELAY /* Maximum delay in ms. 0 to 10000. Default = 10. */ +} FMOD_DSP_DELAY; + + +/* +[ENUM] +[ + [DESCRIPTION] + Parameter types for the FMOD_DSP_TYPE_FLANGE filter. + + [REMARKS] + Flange is an effect where the signal is played twice at the same time, and one copy slides back and forth creating a whooshing or flanging effect. + As there are 2 copies of the same signal, by default each signal is given 50% mix, so that the total is not louder than the original unaffected signal. + + Flange depth is a percentage of a 10ms shift from the original signal. Anything above 10ms is not considered flange because to the ear it begins to 'echo' so 10ms is the highest value possible. + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + DSP::setParameter + DSP::getParameter + FMOD_DSP_TYPE +] +*/ +typedef enum +{ + FMOD_DSP_FLANGE_DRYMIX, /* Volume of original signal to pass to output. 0.0 to 1.0. Default = 0.45. */ + FMOD_DSP_FLANGE_WETMIX, /* Volume of flange signal to pass to output. 0.0 to 1.0. Default = 0.55. */ + FMOD_DSP_FLANGE_DEPTH, /* Flange depth (percentage of 40ms delay). 0.01 to 1.0. Default = 1.0. */ + FMOD_DSP_FLANGE_RATE /* Flange speed in hz. 0.0 to 20.0. Default = 0.1. */ +} FMOD_DSP_FLANGE; + + +/* +[ENUM] +[ + [DESCRIPTION] + Parameter types for the FMOD_DSP_TYPE_TREMOLO filter. + + [REMARKS] + The tremolo effect varies the amplitude of a sound. Depending on the settings, this unit can produce a tremolo, chopper or auto-pan effect. + + The shape of the LFO (low freq. oscillator) can morphed between sine, triangle and sawtooth waves using the FMOD_DSP_TREMOLO_SHAPE and FMOD_DSP_TREMOLO_SKEW parameters. + FMOD_DSP_TREMOLO_DUTY and FMOD_DSP_TREMOLO_SQUARE are useful for a chopper-type effect where the first controls the on-time duration and second controls the flatness of the envelope. + FMOD_DSP_TREMOLO_SPREAD varies the LFO phase between channels to get an auto-pan effect. This works best with a sine shape LFO. + The LFO can be synchronized using the FMOD_DSP_TREMOLO_PHASE parameter which sets its instantaneous phase. + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + DSP::setParameter + DSP::getParameter + FMOD_DSP_TYPE +] +*/ +typedef enum +{ + FMOD_DSP_TREMOLO_FREQUENCY, /* LFO frequency in Hz. 0.1 to 20. Default = 4. */ + FMOD_DSP_TREMOLO_DEPTH, /* Tremolo depth. 0 to 1. Default = 0. */ + FMOD_DSP_TREMOLO_SHAPE, /* LFO shape morph between triangle and sine. 0 to 1. Default = 0. */ + FMOD_DSP_TREMOLO_SKEW, /* Time-skewing of LFO cycle. -1 to 1. Default = 0. */ + FMOD_DSP_TREMOLO_DUTY, /* LFO on-time. 0 to 1. Default = 0.5. */ + FMOD_DSP_TREMOLO_SQUARE, /* Flatness of the LFO shape. 0 to 1. Default = 0. */ + FMOD_DSP_TREMOLO_PHASE, /* Instantaneous LFO phase. 0 to 1. Default = 0. */ + FMOD_DSP_TREMOLO_SPREAD /* Rotation / auto-pan effect. -1 to 1. Default = 0. */ +} FMOD_DSP_TREMOLO; + + +/* +[ENUM] +[ + [DESCRIPTION] + Parameter types for the FMOD_DSP_TYPE_DISTORTION filter. + + [REMARKS] + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + DSP::setParameter + DSP::getParameter + FMOD_DSP_TYPE +] +*/ +typedef enum +{ + FMOD_DSP_DISTORTION_LEVEL /* Distortion value. 0.0 to 1.0. Default = 0.5. */ +} FMOD_DSP_DISTORTION; + + +/* +[ENUM] +[ + [DESCRIPTION] + Parameter types for the FMOD_DSP_TYPE_NORMALIZE filter. + + [REMARKS] + Normalize amplifies the sound based on the maximum peaks within the signal. + For example if the maximum peaks in the signal were 50% of the bandwidth, it would scale the whole sound by 2. + The lower threshold value makes the normalizer ignores peaks below a certain point, to avoid over-amplification if a loud signal suddenly came in, and also to avoid amplifying to maximum things like background hiss. + + Because FMOD is a realtime audio processor, it doesn't have the luxury of knowing the peak for the whole sound (ie it can't see into the future), so it has to process data as it comes in. + To avoid very sudden changes in volume level based on small samples of new data, fmod fades towards the desired amplification which makes for smooth gain control. The fadetime parameter can control this. + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + DSP::setParameter + DSP::getParameter + FMOD_DSP_TYPE +] +*/ +typedef enum +{ + FMOD_DSP_NORMALIZE_FADETIME, /* Time to ramp the silence to full in ms. 0.0 to 20000.0. Default = 5000.0. */ + FMOD_DSP_NORMALIZE_THRESHHOLD, /* Lower volume range threshold to ignore. 0.0 to 1.0. Default = 0.1. Raise higher to stop amplification of very quiet signals. */ + FMOD_DSP_NORMALIZE_MAXAMP /* Maximum amplification allowed. 1.0 to 100000.0. Default = 20.0. 1.0 = no amplifaction, higher values allow more boost. */ +} FMOD_DSP_NORMALIZE; + + +/* +[ENUM] +[ + [DESCRIPTION] + Parameter types for the FMOD_DSP_TYPE_PARAMEQ filter. + + [REMARKS] + Parametric EQ is a bandpass filter that attenuates or amplifies a selected frequency and its neighbouring frequencies. + + To create a multi-band EQ create multiple FMOD_DSP_TYPE_PARAMEQ units and set each unit to different frequencies, for example 1000hz, 2000hz, 4000hz, 8000hz, 16000hz with a range of 1 octave each. + + When a frequency has its gain set to 1.0, the sound will be unaffected and represents the original signal exactly. + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + DSP::setParameter + DSP::getParameter + FMOD_DSP_TYPE +] +*/ +typedef enum +{ + FMOD_DSP_PARAMEQ_CENTER, /* Frequency center. 20.0 to 22000.0. Default = 8000.0. */ + FMOD_DSP_PARAMEQ_BANDWIDTH, /* Octave range around the center frequency to filter. 0.2 to 5.0. Default = 1.0. */ + FMOD_DSP_PARAMEQ_GAIN /* Frequency Gain. 0.05 to 3.0. Default = 1.0. */ +} FMOD_DSP_PARAMEQ; + + + +/* +[ENUM] +[ + [DESCRIPTION] + Parameter types for the FMOD_DSP_TYPE_PITCHSHIFT filter. + + [REMARKS] + This pitch shifting unit can be used to change the pitch of a sound without speeding it up or slowing it down. + It can also be used for time stretching or scaling, for example if the pitch was doubled, and the frequency of the sound was halved, the pitch of the sound would sound correct but it would be twice as slow. + + Warning! This filter is very computationally expensive! Similar to a vocoder, it requires several overlapping FFT and IFFT's to produce smooth output, and can require around 440mhz for 1 stereo 48khz signal using the default settings. + Reducing the signal to mono will half the cpu usage. + Reducing this will lower audio quality, but what settings to use are largely dependant on the sound being played. A noisy polyphonic signal will need higher fft size compared to a speaking voice for example. + + This pitch shifter is based on the pitch shifter code at http://www.dspdimension.com, written by Stephan M. Bernsee. + The original code is COPYRIGHT 1999-2003 Stephan M. Bernsee . + + 'maxchannels' dictates the amount of memory allocated. By default, the maxchannels value is 0. If FMOD is set to stereo, the pitch shift unit will allocate enough memory for 2 channels. If it is 5.1, it will allocate enough memory for a 6 channel pitch shift, etc. + If the pitch shift effect is only ever applied to the global mix (ie it was added with System::addDSP), then 0 is the value to set as it will be enough to handle all speaker modes. + When the pitch shift is added to a channel (ie Channel::addDSP) then the channel count that comes in could be anything from 1 to 8 possibly. It is only in this case where you might want to increase the channel count above the output's channel count. + If a channel pitch shift is set to a lower number than the sound's channel count that is coming in, it will not pitch shift the sound. + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + DSP::setParameter + DSP::getParameter + FMOD_DSP_TYPE +] +*/ +typedef enum +{ + FMOD_DSP_PITCHSHIFT_PITCH, /* Pitch value. 0.5 to 2.0. Default = 1.0. 0.5 = one octave down, 2.0 = one octave up. 1.0 does not change the pitch. */ + FMOD_DSP_PITCHSHIFT_FFTSIZE, /* FFT window size. 256, 512, 1024, 2048, 4096. Default = 1024. Increase this to reduce 'smearing'. This effect is a warbling sound similar to when an mp3 is encoded at very low bitrates. */ + FMOD_DSP_PITCHSHIFT_OVERLAP, /* Removed. Do not use. FMOD now uses 4 overlaps and cannot be changed. */ + FMOD_DSP_PITCHSHIFT_MAXCHANNELS /* Maximum channels supported. 0 to 16. 0 = same as fmod's default output polyphony, 1 = mono, 2 = stereo etc. See remarks for more. Default = 0. It is suggested to leave at 0! */ +} FMOD_DSP_PITCHSHIFT; + + + +/* +[ENUM] +[ + [DESCRIPTION] + Parameter types for the FMOD_DSP_TYPE_CHORUS filter. + + [REMARKS] + Chrous is an effect where the sound is more 'spacious' due to 1 to 3 versions of the sound being played along side the original signal but with the pitch of each copy modulating on a sine wave. + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + DSP::setParameter + DSP::getParameter + FMOD_DSP_TYPE +] +*/ +typedef enum +{ + FMOD_DSP_CHORUS_DRYMIX, /* Volume of original signal to pass to output. 0.0 to 1.0. Default = 0.5. */ + FMOD_DSP_CHORUS_WETMIX1, /* Volume of 1st chorus tap. 0.0 to 1.0. Default = 0.5. */ + FMOD_DSP_CHORUS_WETMIX2, /* Volume of 2nd chorus tap. This tap is 90 degrees out of phase of the first tap. 0.0 to 1.0. Default = 0.5. */ + FMOD_DSP_CHORUS_WETMIX3, /* Volume of 3rd chorus tap. This tap is 90 degrees out of phase of the second tap. 0.0 to 1.0. Default = 0.5. */ + FMOD_DSP_CHORUS_DELAY, /* Chorus delay in ms. 0.1 to 100.0. Default = 40.0 ms. */ + FMOD_DSP_CHORUS_RATE, /* Chorus modulation rate in hz. 0.0 to 20.0. Default = 0.8 hz. */ + FMOD_DSP_CHORUS_DEPTH /* Chorus modulation depth. 0.0 to 1.0. Default = 0.03. */ +} FMOD_DSP_CHORUS; + + +/* +[ENUM] +[ + [DESCRIPTION] + Parameter types for the FMOD_DSP_TYPE_ITECHO filter. + This is effectively a software based echo filter that emulates the DirectX DMO echo effect. Impulse tracker files can support this, and FMOD will produce the effect on ANY platform, not just those that support DirectX effects! + + [REMARKS] + Note. Every time the delay is changed, the plugin re-allocates the echo buffer. This means the echo will dissapear at that time while it refills its new buffer. + Larger echo delays result in larger amounts of memory allocated. + + As this is a stereo filter made mainly for IT playback, it is targeted for stereo signals. + With mono signals only the FMOD_DSP_ITECHO_LEFTDELAY is used. + For multichannel signals (>2) there will be no echo on those channels. + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + DSP::SetParameter + DSP::GetParameter + FMOD_DSP_TYPE + System::addDSP +] +*/ +typedef enum +{ + FMOD_DSP_ITECHO_WETDRYMIX, /* Ratio of wet (processed) signal to dry (unprocessed) signal. Must be in the range from 0.0 through 100.0 (all wet). The default value is 50. */ + FMOD_DSP_ITECHO_FEEDBACK, /* Percentage of output fed back into input, in the range from 0.0 through 100.0. The default value is 50. */ + FMOD_DSP_ITECHO_LEFTDELAY, /* Delay for left channel, in milliseconds, in the range from 1.0 through 2000.0. The default value is 500 ms. */ + FMOD_DSP_ITECHO_RIGHTDELAY, /* Delay for right channel, in milliseconds, in the range from 1.0 through 2000.0. The default value is 500 ms. */ + FMOD_DSP_ITECHO_PANDELAY /* Value that specifies whether to swap left and right delays with each successive echo. The default value is zero, meaning no swap. Possible values are defined as 0.0 (equivalent to FALSE) and 1.0 (equivalent to TRUE). CURRENTLY NOT SUPPORTED. */ +} FMOD_DSP_ITECHO; + +/* +[ENUM] +[ + [DESCRIPTION] + Parameter types for the FMOD_DSP_TYPE_COMPRESSOR unit. + This is a simple linked multichannel software limiter that is uniform across the whole spectrum. + + [REMARKS] + The limiter is not guaranteed to catch every peak above the threshold level, + because it cannot apply gain reduction instantaneously - the time delay is + determined by the attack time. However setting the attack time too short will + distort the sound, so it is a compromise. High level peaks can be avoided by + using a short attack time - but not too short, and setting the threshold a few + decibels below the critical level. + + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + DSP::SetParameter + DSP::GetParameter + FMOD_DSP_TYPE + System::addDSP +] +*/ +typedef enum +{ + FMOD_DSP_COMPRESSOR_THRESHOLD, /* Threshold level (dB) in the range from -60 through 0. The default value is 0. */ + FMOD_DSP_COMPRESSOR_ATTACK, /* Gain reduction attack time (milliseconds), in the range from 10 through 200. The default value is 50. */ + FMOD_DSP_COMPRESSOR_RELEASE, /* Gain reduction release time (milliseconds), in the range from 20 through 1000. The default value is 50. */ + FMOD_DSP_COMPRESSOR_GAINMAKEUP /* Make-up gain (dB) applied after limiting, in the range from 0 through 30. The default value is 0. */ +} FMOD_DSP_COMPRESSOR; + +/* +[ENUM] +[ + [DESCRIPTION] + Parameter types for the FMOD_DSP_TYPE_SFXREVERB unit. + + [REMARKS] + This is a high quality I3DL2 based reverb. + On top of the I3DL2 property set, "Dry Level" is also included to allow the dry mix to be changed. + + These properties can be set with presets in FMOD_REVERB_PRESETS. + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + DSP::SetParameter + DSP::GetParameter + FMOD_DSP_TYPE + System::addDSP + FMOD_REVERB_PRESETS +] +*/ +typedef enum +{ + FMOD_DSP_SFXREVERB_DRYLEVEL, /* Dry Level : Mix level of dry signal in output in mB. Ranges from -10000.0 to 0.0. Default is 0. */ + FMOD_DSP_SFXREVERB_ROOM, /* Room : Room effect level at low frequencies in mB. Ranges from -10000.0 to 0.0. Default is -10000.0. */ + FMOD_DSP_SFXREVERB_ROOMHF, /* Room HF : Room effect high-frequency level re. low frequency level in mB. Ranges from -10000.0 to 0.0. Default is 0.0. */ + FMOD_DSP_SFXREVERB_DECAYTIME, /* Decay Time : Reverberation decay time at low-frequencies in seconds. Ranges from 0.1 to 20.0. Default is 1.0. */ + FMOD_DSP_SFXREVERB_DECAYHFRATIO, /* Decay HF Ratio : High-frequency to low-frequency decay time ratio. Ranges from 0.1 to 2.0. Default is 0.5. */ + FMOD_DSP_SFXREVERB_REFLECTIONSLEVEL, /* Reflections : Early reflections level relative to room effect in mB. Ranges from -10000.0 to 1000.0. Default is -10000.0. */ + FMOD_DSP_SFXREVERB_REFLECTIONSDELAY, /* Reflect Delay : Delay time of first reflection in seconds. Ranges from 0.0 to 0.3. Default is 0.02. */ + FMOD_DSP_SFXREVERB_REVERBLEVEL, /* Reverb : Late reverberation level relative to room effect in mB. Ranges from -10000.0 to 2000.0. Default is 0.0. */ + FMOD_DSP_SFXREVERB_REVERBDELAY, /* Reverb Delay : Late reverberation delay time relative to first reflection in seconds. Ranges from 0.0 to 0.1. Default is 0.04. */ + FMOD_DSP_SFXREVERB_DIFFUSION, /* Diffusion : Reverberation diffusion (echo density) in percent. Ranges from 0.0 to 100.0. Default is 100.0. */ + FMOD_DSP_SFXREVERB_DENSITY, /* Density : Reverberation density (modal density) in percent. Ranges from 0.0 to 100.0. Default is 100.0. */ + FMOD_DSP_SFXREVERB_HFREFERENCE, /* HF Reference : Reference high frequency in Hz. Ranges from 20.0 to 20000.0. Default is 5000.0. */ + FMOD_DSP_SFXREVERB_ROOMLF, /* Room LF : Room effect low-frequency level in mB. Ranges from -10000.0 to 0.0. Default is 0.0. */ + FMOD_DSP_SFXREVERB_LFREFERENCE /* LF Reference : Reference low-frequency in Hz. Ranges from 20.0 to 1000.0. Default is 250.0. */ +} FMOD_DSP_SFXREVERB; + +/* +[ENUM] +[ + [DESCRIPTION] + Parameter types for the FMOD_DSP_TYPE_LOWPASS_SIMPLE filter. + This is a very simple low pass filter, based on two single-pole RC time-constant modules. + The emphasis is on speed rather than accuracy, so this should not be used for task requiring critical filtering. + + [REMARKS] + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + DSP::setParameter + DSP::getParameter + FMOD_DSP_TYPE +] +*/ +typedef enum +{ + FMOD_DSP_LOWPASS_SIMPLE_CUTOFF /* Lowpass cutoff frequency in hz. 10.0 to 22000.0. Default = 5000.0 */ +} FMOD_DSP_LOWPASS_SIMPLE; + +/* +[ENUM] +[ + [DESCRIPTION] + Parameter types for the FMOD_DSP_TYPE_HIGHPASS_SIMPLE filter. + This is a very simple single-order high pass filter. + The emphasis is on speed rather than accuracy, so this should not be used for task requiring critical filtering. + + [REMARKS] + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + DSP::setParameter + DSP::getParameter + FMOD_DSP_TYPE +] +*/ +typedef enum +{ + FMOD_DSP_HIGHPASS_SIMPLE_CUTOFF /* Highpass cutoff frequency in hz. 10.0 to 22000.0. Default = 1000.0 */ +} FMOD_DSP_HIGHPASS_SIMPLE; + +#endif + diff --git a/libs/fmodex/inc/fmod_errors.h b/libs/fmodex/inc/fmod_errors.h new file mode 100644 index 000000000..fdb85984b --- /dev/null +++ b/libs/fmodex/inc/fmod_errors.h @@ -0,0 +1,123 @@ + +/* ============================================================================================== */ +/* FMOD Ex - Error string header file. Copyright (c), Firelight Technologies Pty, Ltd. 2004-2011. */ +/* */ +/* Use this header if you want to store or display a string version / english explanation of */ +/* the FMOD error codes. */ +/* */ +/* ============================================================================================== */ + +#ifndef _FMOD_ERRORS_H +#define _FMOD_ERRORS_H + +#include "fmod.h" + +#ifdef __GNUC__ +static const char *FMOD_ErrorString(FMOD_RESULT errcode) __attribute__((unused)); +#endif + +static const char *FMOD_ErrorString(FMOD_RESULT errcode) +{ + switch (errcode) + { + case FMOD_ERR_ALREADYLOCKED: return "Tried to call lock a second time before unlock was called. "; + case FMOD_ERR_BADCOMMAND: return "Tried to call a function on a data type that does not allow this type of functionality (ie calling Sound::lock on a streaming sound). "; + case FMOD_ERR_CDDA_DRIVERS: return "Neither NTSCSI nor ASPI could be initialised. "; + case FMOD_ERR_CDDA_INIT: return "An error occurred while initialising the CDDA subsystem. "; + case FMOD_ERR_CDDA_INVALID_DEVICE: return "Couldn't find the specified device. "; + case FMOD_ERR_CDDA_NOAUDIO: return "No audio tracks on the specified disc. "; + case FMOD_ERR_CDDA_NODEVICES: return "No CD/DVD devices were found. "; + case FMOD_ERR_CDDA_NODISC: return "No disc present in the specified drive. "; + case FMOD_ERR_CDDA_READ: return "A CDDA read error occurred. "; + case FMOD_ERR_CHANNEL_ALLOC: return "Error trying to allocate a channel. "; + case FMOD_ERR_CHANNEL_STOLEN: return "The specified channel has been reused to play another sound. "; + case FMOD_ERR_COM: return "A Win32 COM related error occured. COM failed to initialize or a QueryInterface failed meaning a Windows codec or driver was not installed properly. "; + case FMOD_ERR_DMA: return "DMA Failure. See debug output for more information. "; + case FMOD_ERR_DSP_CONNECTION: return "DSP connection error. Connection possibly caused a cyclic dependancy. Or tried to connect a tree too many units deep (more than 128). "; + case FMOD_ERR_DSP_FORMAT: return "DSP Format error. A DSP unit may have attempted to connect to this network with the wrong format. "; + case FMOD_ERR_DSP_NOTFOUND: return "DSP connection error. Couldn't find the DSP unit specified. "; + case FMOD_ERR_DSP_RUNNING: return "DSP error. Cannot perform this operation while the network is in the middle of running. This will most likely happen if a connection or disconnection is attempted in a DSP callback. "; + case FMOD_ERR_DSP_TOOMANYCONNECTIONS: return "DSP connection error. The unit being connected to or disconnected should only have 1 input or output. "; + case FMOD_ERR_EVENT_ALREADY_LOADED: return "The specified project or bank has already been loaded. Having multiple copies of the same project loaded simultaneously is forbidden. "; + case FMOD_ERR_EVENT_FAILED: return "An Event failed to be retrieved, most likely due to 'just fail' being specified as the max playbacks behavior. "; + case FMOD_ERR_EVENT_GUIDCONFLICT: return "An event with the same GUID already exists. "; + case FMOD_ERR_EVENT_INFOONLY: return "Can't execute this command on an EVENT_INFOONLY event. "; + case FMOD_ERR_EVENT_INTERNAL: return "An error occured that wasn't supposed to. See debug log for reason. "; + case FMOD_ERR_EVENT_MAXSTREAMS: return "Event failed because 'Max streams' was hit when FMOD_EVENT_INIT_FAIL_ON_MAXSTREAMS was specified. "; + case FMOD_ERR_EVENT_MISMATCH: return "FSB mismatches the FEV it was compiled with, the stream/sample mode it was meant to be created with was different, or the FEV was built for a different platform. "; + case FMOD_ERR_EVENT_NAMECONFLICT: return "A category with the same name already exists. "; + case FMOD_ERR_EVENT_NEEDSSIMPLE: return "Tried to call a function on a complex event that's only supported by simple events. "; + case FMOD_ERR_EVENT_NOTFOUND: return "The requested event, event group, event category or event property could not be found. "; + case FMOD_ERR_FILE_BAD: return "Error loading file. "; + case FMOD_ERR_FILE_COULDNOTSEEK: return "Couldn't perform seek operation. This is a limitation of the medium (ie netstreams) or the file format. "; + case FMOD_ERR_FILE_DISKEJECTED: return "Media was ejected while reading. "; + case FMOD_ERR_FILE_EOF: return "End of file unexpectedly reached while trying to read essential data (truncated data?). "; + case FMOD_ERR_FILE_NOTFOUND: return "File not found. "; + case FMOD_ERR_FILE_UNWANTED: return "Unwanted file access occured. "; + case FMOD_ERR_FORMAT: return "Unsupported file or audio format. "; + case FMOD_ERR_HTTP: return "A HTTP error occurred. This is a catch-all for HTTP errors not listed elsewhere. "; + case FMOD_ERR_HTTP_ACCESS: return "The specified resource requires authentication or is forbidden. "; + case FMOD_ERR_HTTP_PROXY_AUTH: return "Proxy authentication is required to access the specified resource. "; + case FMOD_ERR_HTTP_SERVER_ERROR: return "A HTTP server error occurred. "; + case FMOD_ERR_HTTP_TIMEOUT: return "The HTTP request timed out. "; + case FMOD_ERR_INITIALIZATION: return "FMOD was not initialized correctly to support this function. "; + case FMOD_ERR_INITIALIZED: return "Cannot call this command after System::init. "; + case FMOD_ERR_INTERNAL: return "An error occured that wasn't supposed to. Contact support. "; + case FMOD_ERR_INVALID_ADDRESS: return "On Xbox 360, this memory address passed to FMOD must be physical, (ie allocated with XPhysicalAlloc.) "; + case FMOD_ERR_INVALID_FLOAT: return "Value passed in was a NaN, Inf or denormalized float. "; + case FMOD_ERR_INVALID_HANDLE: return "An invalid object handle was used. "; + case FMOD_ERR_INVALID_PARAM: return "An invalid parameter was passed to this function. "; + case FMOD_ERR_INVALID_POSITION: return "An invalid seek position was passed to this function. "; + case FMOD_ERR_INVALID_SPEAKER: return "An invalid speaker was passed to this function based on the current speaker mode. "; + case FMOD_ERR_INVALID_SYNCPOINT: return "The syncpoint did not come from this sound handle. "; + case FMOD_ERR_INVALID_VECTOR: return "The vectors passed in are not unit length, or perpendicular. "; + case FMOD_ERR_MAXAUDIBLE: return "Reached maximum audible playback count for this sound's soundgroup. "; + case FMOD_ERR_MEMORY: return "Not enough memory or resources. "; + case FMOD_ERR_MEMORY_CANTPOINT: return "Can't use FMOD_OPENMEMORY_POINT on non PCM source data, or non mp3/xma/adpcm data if FMOD_CREATECOMPRESSEDSAMPLE was used. "; + case FMOD_ERR_MEMORY_SRAM: return "Not enough memory or resources on console sound ram. "; + case FMOD_ERR_MUSIC_NOCALLBACK: return "The music callback is required, but it has not been set. "; + case FMOD_ERR_MUSIC_NOTFOUND: return "The requested music entity could not be found. "; + case FMOD_ERR_MUSIC_UNINITIALIZED: return "Music system is not initialized probably because no music data is loaded. "; + case FMOD_ERR_NEEDS2D: return "Tried to call a command on a 3d sound when the command was meant for 2d sound. "; + case FMOD_ERR_NEEDS3D: return "Tried to call a command on a 2d sound when the command was meant for 3d sound. "; + case FMOD_ERR_NEEDSHARDWARE: return "Tried to use a feature that requires hardware support. (ie trying to play a GCADPCM compressed sound in software on Wii). "; + case FMOD_ERR_NEEDSSOFTWARE: return "Tried to use a feature that requires the software engine. Software engine has either been turned off, or command was executed on a hardware channel which does not support this feature. "; + case FMOD_ERR_NET_CONNECT: return "Couldn't connect to the specified host. "; + case FMOD_ERR_NET_SOCKET_ERROR: return "A socket error occurred. This is a catch-all for socket-related errors not listed elsewhere. "; + case FMOD_ERR_NET_URL: return "The specified URL couldn't be resolved. "; + case FMOD_ERR_NET_WOULD_BLOCK: return "Operation on a non-blocking socket could not complete immediately. "; + case FMOD_ERR_NOTREADY: return "Operation could not be performed because specified sound/DSP connection is not ready. "; + case FMOD_ERR_OUTPUT_ALLOCATED: return "Error initializing output device, but more specifically, the output device is already in use and cannot be reused. "; + case FMOD_ERR_OUTPUT_CREATEBUFFER: return "Error creating hardware sound buffer. "; + case FMOD_ERR_OUTPUT_DRIVERCALL: return "A call to a standard soundcard driver failed, which could possibly mean a bug in the driver or resources were missing or exhausted. "; + case FMOD_ERR_OUTPUT_ENUMERATION: return "Error enumerating the available driver list. List may be inconsistent due to a recent device addition or removal. "; + case FMOD_ERR_OUTPUT_FORMAT: return "Soundcard does not support the minimum features needed for this soundsystem (16bit stereo output). "; + case FMOD_ERR_OUTPUT_INIT: return "Error initializing output device. "; + case FMOD_ERR_OUTPUT_NOHARDWARE: return "FMOD_HARDWARE was specified but the sound card does not have the resources necessary to play it. "; + case FMOD_ERR_OUTPUT_NOSOFTWARE: return "Attempted to create a software sound but no software channels were specified in System::init. "; + case FMOD_ERR_PAN: return "Panning only works with mono or stereo sound sources. "; + case FMOD_ERR_PLUGIN: return "An unspecified error has been returned from a 3rd party plugin. "; + case FMOD_ERR_PLUGIN_INSTANCES: return "The number of allowed instances of a plugin has been exceeded. "; + case FMOD_ERR_PLUGIN_MISSING: return "A requested output, dsp unit type or codec was not available. "; + case FMOD_ERR_PLUGIN_RESOURCE: return "A resource that the plugin requires cannot be found. (ie the DLS file for MIDI playback or other DLLs that it needs to load) "; + case FMOD_ERR_PRELOADED: return "The specified sound is still in use by the event system, call EventSystem::unloadFSB before trying to release it. "; + case FMOD_ERR_PROGRAMMERSOUND: return "The specified sound is still in use by the event system, wait for the event which is using it finish with it. "; + case FMOD_ERR_RECORD: return "An error occured trying to initialize the recording device. "; + case FMOD_ERR_REVERB_INSTANCE: return "Specified instance in FMOD_REVERB_PROPERTIES couldn't be set. Most likely because it is an invalid instance number or the reverb doesnt exist. "; + case FMOD_ERR_SUBSOUNDS: return "The error occured because the sound referenced contains subsounds when it shouldn't have, or it doesn't contain subsounds when it should have. The operation may also not be able to be performed on a parent sound, or a parent sound was played without setting up a sentence first. "; + case FMOD_ERR_SUBSOUND_ALLOCATED: return "This subsound is already being used by another sound, you cannot have more than one parent to a sound. Null out the other parent's entry first. "; + case FMOD_ERR_SUBSOUND_CANTMOVE: return "Shared subsounds cannot be replaced or moved from their parent stream, such as when the parent stream is an FSB file. "; + case FMOD_ERR_SUBSOUND_MODE: return "The subsound's mode bits do not match with the parent sound's mode bits. See documentation for function that it was called with. "; + case FMOD_ERR_TAGNOTFOUND: return "The specified tag could not be found or there are no tags. "; + case FMOD_ERR_TOOMANYCHANNELS: return "The sound created exceeds the allowable input channel count. This can be increased using the maxinputchannels parameter in System::setSoftwareFormat. "; + case FMOD_ERR_UNIMPLEMENTED: return "Something in FMOD hasn't been implemented when it should be! contact support! "; + case FMOD_ERR_UNINITIALIZED: return "This command failed because System::init or System::setDriver was not called. "; + case FMOD_ERR_UNSUPPORTED: return "A command issued was not supported by this object. Possibly a plugin without certain callbacks specified. "; + case FMOD_ERR_UPDATE: return "An error caused by System::update occured. "; + case FMOD_ERR_VERSION: return "The version number of this file format is not supported. "; + case FMOD_OK: return "No errors."; + default : return "Unknown error."; + }; +} + +#endif diff --git a/libs/fmodex/inc/fmod_memoryinfo.h b/libs/fmodex/inc/fmod_memoryinfo.h new file mode 100644 index 000000000..6db9de3b8 --- /dev/null +++ b/libs/fmodex/inc/fmod_memoryinfo.h @@ -0,0 +1,201 @@ +/* ============================================================================================= */ +/* FMOD Ex - Memory info header file. Copyright (c), Firelight Technologies Pty, Ltd. 2008-2011. */ +/* */ +/* Use this header if you are interested in getting detailed information on FMOD's memory */ +/* usage. See the documentation for more details. */ +/* */ +/* ============================================================================================= */ + +#ifndef _FMOD_MEMORYINFO_H +#define _FMOD_MEMORYINFO_H + +/* +[STRUCTURE] +[ + [DESCRIPTION] + Structure to be filled with detailed memory usage information of an FMOD object + + [REMARKS] + Every public FMOD class has a getMemoryInfo function which can be used to get detailed information on what memory resources are associated with the object in question. + On return from getMemoryInfo, each member of this structure will hold the amount of memory used for its type in bytes. + + Members marked with [in] mean the user sets the value before passing it to the function. + Members marked with [out] mean FMOD sets the value to be used after the function exits. + + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + System::getMemoryInfo + EventSystem::getMemoryInfo + FMOD_MEMBITS + FMOD_EVENT_MEMBITS +] +*/ +typedef struct FMOD_MEMORY_USAGE_DETAILS +{ + unsigned int other; /* [out] Memory not accounted for by other types */ + unsigned int string; /* [out] String data */ + unsigned int system; /* [out] System object and various internals */ + unsigned int plugins; /* [out] Plugin objects and internals */ + unsigned int output; /* [out] Output module object and internals */ + unsigned int channel; /* [out] Channel related memory */ + unsigned int channelgroup; /* [out] ChannelGroup objects and internals */ + unsigned int codec; /* [out] Codecs allocated for streaming */ + unsigned int file; /* [out] File buffers and structures */ + unsigned int sound; /* [out] Sound objects and internals */ + unsigned int secondaryram; /* [out] Sound data stored in secondary RAM */ + unsigned int soundgroup; /* [out] SoundGroup objects and internals */ + unsigned int streambuffer; /* [out] Stream buffer memory */ + unsigned int dspconnection; /* [out] DSPConnection objects and internals */ + unsigned int dsp; /* [out] DSP implementation objects */ + unsigned int dspcodec; /* [out] Realtime file format decoding DSP objects */ + unsigned int profile; /* [out] Profiler memory footprint. */ + unsigned int recordbuffer; /* [out] Buffer used to store recorded data from microphone */ + unsigned int reverb; /* [out] Reverb implementation objects */ + unsigned int reverbchannelprops; /* [out] Reverb channel properties structs */ + unsigned int geometry; /* [out] Geometry objects and internals */ + unsigned int syncpoint; /* [out] Sync point memory. */ + unsigned int eventsystem; /* [out] EventSystem and various internals */ + unsigned int musicsystem; /* [out] MusicSystem and various internals */ + unsigned int fev; /* [out] Definition of objects contained in all loaded projects e.g. events, groups, categories */ + unsigned int memoryfsb; /* [out] Data loaded with preloadFSB */ + unsigned int eventproject; /* [out] EventProject objects and internals */ + unsigned int eventgroupi; /* [out] EventGroup objects and internals */ + unsigned int soundbankclass; /* [out] Objects used to manage wave banks */ + unsigned int soundbanklist; /* [out] Data used to manage lists of wave bank usage */ + unsigned int streaminstance; /* [out] Stream objects and internals */ + unsigned int sounddefclass; /* [out] Sound definition objects */ + unsigned int sounddefdefclass; /* [out] Sound definition static data objects */ + unsigned int sounddefpool; /* [out] Sound definition pool data */ + unsigned int reverbdef; /* [out] Reverb definition objects */ + unsigned int eventreverb; /* [out] Reverb objects */ + unsigned int userproperty; /* [out] User property objects */ + unsigned int eventinstance; /* [out] Event instance base objects */ + unsigned int eventinstance_complex; /* [out] Complex event instance objects */ + unsigned int eventinstance_simple; /* [out] Simple event instance objects */ + unsigned int eventinstance_layer; /* [out] Event layer instance objects */ + unsigned int eventinstance_sound; /* [out] Event sound instance objects */ + unsigned int eventenvelope; /* [out] Event envelope objects */ + unsigned int eventenvelopedef; /* [out] Event envelope definition objects */ + unsigned int eventparameter; /* [out] Event parameter objects */ + unsigned int eventcategory; /* [out] Event category objects */ + unsigned int eventenvelopepoint; /* [out] Event envelope point objects */ + unsigned int eventinstancepool; /* [out] Event instance pool memory */ +} FMOD_MEMORY_USAGE_DETAILS; + + +/* +[DEFINE] +[ + [NAME] + FMOD_MEMBITS + + [DESCRIPTION] + Bitfield used to request specific memory usage information from the getMemoryInfo function of every public FMOD Ex class. + Use with the "memorybits" parameter of getMemoryInfo to get information on FMOD Ex memory usage. + + [REMARKS] + Every public FMOD class has a getMemoryInfo function which can be used to get detailed information on what memory resources are associated with the object in question. + The FMOD_MEMBITS defines can be OR'd together to specify precisely what memory usage you'd like to get information on. See System::getMemoryInfo for an example. + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + FMOD_EVENT_MEMBITS + System::getMemoryInfo +] +*/ +#define FMOD_MEMBITS_OTHER 0x00000001 /* Memory not accounted for by other types */ +#define FMOD_MEMBITS_STRING 0x00000002 /* String data */ + +#define FMOD_MEMBITS_SYSTEM 0x00000004 /* System object and various internals */ +#define FMOD_MEMBITS_PLUGINS 0x00000008 /* Plugin objects and internals */ +#define FMOD_MEMBITS_OUTPUT 0x00000010 /* Output module object and internals */ +#define FMOD_MEMBITS_CHANNEL 0x00000020 /* Channel related memory */ +#define FMOD_MEMBITS_CHANNELGROUP 0x00000040 /* ChannelGroup objects and internals */ +#define FMOD_MEMBITS_CODEC 0x00000080 /* Codecs allocated for streaming */ +#define FMOD_MEMBITS_FILE 0x00000100 /* Codecs allocated for streaming */ +#define FMOD_MEMBITS_SOUND 0x00000200 /* Sound objects and internals */ +#define FMOD_MEMBITS_SOUND_SECONDARYRAM 0x00000400 /* Sound data stored in secondary RAM */ +#define FMOD_MEMBITS_SOUNDGROUP 0x00000800 /* SoundGroup objects and internals */ +#define FMOD_MEMBITS_STREAMBUFFER 0x00001000 /* Stream buffer memory */ +#define FMOD_MEMBITS_DSPCONNECTION 0x00002000 /* DSPConnection objects and internals */ +#define FMOD_MEMBITS_DSP 0x00004000 /* DSP implementation objects */ +#define FMOD_MEMBITS_DSPCODEC 0x00008000 /* Realtime file format decoding DSP objects */ +#define FMOD_MEMBITS_PROFILE 0x00010000 /* Profiler memory footprint. */ +#define FMOD_MEMBITS_RECORDBUFFER 0x00020000 /* Buffer used to store recorded data from microphone */ +#define FMOD_MEMBITS_REVERB 0x00040000 /* Reverb implementation objects */ +#define FMOD_MEMBITS_REVERBCHANNELPROPS 0x00080000 /* Reverb channel properties structs */ +#define FMOD_MEMBITS_GEOMETRY 0x00100000 /* Geometry objects and internals */ +#define FMOD_MEMBITS_SYNCPOINT 0x00200000 /* Sync point memory. */ +#define FMOD_MEMBITS_ALL 0xffffffff /* All memory used by FMOD Ex */ +/* [DEFINE_END] */ + + +/* +[DEFINE] +[ + [NAME] + FMOD_EVENT_MEMBITS + + [DESCRIPTION] + Bitfield used to request specific memory usage information from the getMemoryInfo function of every public FMOD Event System class. + Use with the "event_memorybits" parameter of getMemoryInfo to get information on FMOD Event System memory usage. + + [REMARKS] + Every public FMOD Event System class has a getMemoryInfo function which can be used to get detailed information on what memory resources are associated with the object in question. + The FMOD_EVENT_MEMBITS defines can be OR'd together to specify precisely what memory usage you'd like to get information on. See EventSystem::getMemoryInfo for an example. + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + FMOD_MEMBITS + System::getMemoryInfo +] +*/ +#define FMOD_EVENT_MEMBITS_EVENTSYSTEM 0x00000001 /* EventSystem and various internals */ +#define FMOD_EVENT_MEMBITS_MUSICSYSTEM 0x00000002 /* MusicSystem and various internals */ +#define FMOD_EVENT_MEMBITS_FEV 0x00000004 /* Definition of objects contained in all loaded projects e.g. events, groups, categories */ +#define FMOD_EVENT_MEMBITS_MEMORYFSB 0x00000008 /* Data loaded with preloadFSB */ +#define FMOD_EVENT_MEMBITS_EVENTPROJECT 0x00000010 /* EventProject objects and internals */ +#define FMOD_EVENT_MEMBITS_EVENTGROUPI 0x00000020 /* EventGroup objects and internals */ +#define FMOD_EVENT_MEMBITS_SOUNDBANKCLASS 0x00000040 /* Objects used to manage wave banks */ +#define FMOD_EVENT_MEMBITS_SOUNDBANKLIST 0x00000080 /* Data used to manage lists of wave bank usage */ +#define FMOD_EVENT_MEMBITS_STREAMINSTANCE 0x00000100 /* Stream objects and internals */ +#define FMOD_EVENT_MEMBITS_SOUNDDEFCLASS 0x00000200 /* Sound definition objects */ +#define FMOD_EVENT_MEMBITS_SOUNDDEFDEFCLASS 0x00000400 /* Sound definition static data objects */ +#define FMOD_EVENT_MEMBITS_SOUNDDEFPOOL 0x00000800 /* Sound definition pool data */ +#define FMOD_EVENT_MEMBITS_REVERBDEF 0x00001000 /* Reverb definition objects */ +#define FMOD_EVENT_MEMBITS_EVENTREVERB 0x00002000 /* Reverb objects */ +#define FMOD_EVENT_MEMBITS_USERPROPERTY 0x00004000 /* User property objects */ +#define FMOD_EVENT_MEMBITS_EVENTINSTANCE 0x00008000 /* Event instance base objects */ +#define FMOD_EVENT_MEMBITS_EVENTINSTANCE_COMPLEX 0x00010000 /* Complex event instance objects */ +#define FMOD_EVENT_MEMBITS_EVENTINSTANCE_SIMPLE 0x00020000 /* Simple event instance objects */ +#define FMOD_EVENT_MEMBITS_EVENTINSTANCE_LAYER 0x00040000 /* Event layer instance objects */ +#define FMOD_EVENT_MEMBITS_EVENTINSTANCE_SOUND 0x00080000 /* Event sound instance objects */ +#define FMOD_EVENT_MEMBITS_EVENTENVELOPE 0x00100000 /* Event envelope objects */ +#define FMOD_EVENT_MEMBITS_EVENTENVELOPEDEF 0x00200000 /* Event envelope definition objects */ +#define FMOD_EVENT_MEMBITS_EVENTPARAMETER 0x00400000 /* Event parameter objects */ +#define FMOD_EVENT_MEMBITS_EVENTCATEGORY 0x00800000 /* Event category objects */ +#define FMOD_EVENT_MEMBITS_EVENTENVELOPEPOINT 0x01000000 /* Event envelope point object+s */ +#define FMOD_EVENT_MEMBITS_EVENTINSTANCEPOOL 0x02000000 /* Event instance pool data */ +#define FMOD_EVENT_MEMBITS_ALL 0xffffffff /* All memory used by FMOD Event System */ + +/* All event instance memory */ +#define FMOD_EVENT_MEMBITS_EVENTINSTANCE_GROUP (FMOD_EVENT_MEMBITS_EVENTINSTANCE | \ + FMOD_EVENT_MEMBITS_EVENTINSTANCE_COMPLEX | \ + FMOD_EVENT_MEMBITS_EVENTINSTANCE_SIMPLE | \ + FMOD_EVENT_MEMBITS_EVENTINSTANCE_LAYER | \ + FMOD_EVENT_MEMBITS_EVENTINSTANCE_SOUND) + +/* All sound definition memory */ +#define FMOD_EVENT_MEMBITS_SOUNDDEF_GROUP (FMOD_EVENT_MEMBITS_SOUNDDEFCLASS | \ + FMOD_EVENT_MEMBITS_SOUNDDEFDEFCLASS | \ + FMOD_EVENT_MEMBITS_SOUNDDEFPOOL) +/* [DEFINE_END] */ + +#endif diff --git a/libs/fmodex/inc/fmod_output.h b/libs/fmodex/inc/fmod_output.h new file mode 100644 index 000000000..2ffb867bd --- /dev/null +++ b/libs/fmodex/inc/fmod_output.h @@ -0,0 +1,93 @@ +/* ==================================================================================================== */ +/* FMOD Ex - output development header file. Copyright (c), Firelight Technologies Pty, Ltd. 2004-2011. */ +/* */ +/* Use this header if you are wanting to develop your own output plugin to use with */ +/* FMOD's output system. With this header you can make your own output plugin that FMOD */ +/* can register and use. See the documentation and examples on how to make a working plugin. */ +/* */ +/* ==================================================================================================== */ + +#ifndef _FMOD_OUTPUT_H +#define _FMOD_OUTPUT_H + +#include "fmod.h" + +typedef struct FMOD_OUTPUT_STATE FMOD_OUTPUT_STATE; + +/* + Output callbacks +*/ +typedef FMOD_RESULT (F_CALLBACK *FMOD_OUTPUT_GETNUMDRIVERSCALLBACK)(FMOD_OUTPUT_STATE *output_state, int *numdrivers); +typedef FMOD_RESULT (F_CALLBACK *FMOD_OUTPUT_GETDRIVERNAMECALLBACK)(FMOD_OUTPUT_STATE *output_state, int id, char *name, int namelen); +typedef FMOD_RESULT (F_CALLBACK *FMOD_OUTPUT_GETDRIVERCAPSCALLBACK)(FMOD_OUTPUT_STATE *output_state, int id, FMOD_CAPS *caps); +typedef FMOD_RESULT (F_CALLBACK *FMOD_OUTPUT_INITCALLBACK) (FMOD_OUTPUT_STATE *output_state, int selecteddriver, FMOD_INITFLAGS flags, int *outputrate, int outputchannels, FMOD_SOUND_FORMAT *outputformat, int dspbufferlength, int dspnumbuffers, void *extradriverdata); +typedef FMOD_RESULT (F_CALLBACK *FMOD_OUTPUT_CLOSECALLBACK) (FMOD_OUTPUT_STATE *output_state); +typedef FMOD_RESULT (F_CALLBACK *FMOD_OUTPUT_UPDATECALLBACK) (FMOD_OUTPUT_STATE *output_state); +typedef FMOD_RESULT (F_CALLBACK *FMOD_OUTPUT_GETHANDLECALLBACK) (FMOD_OUTPUT_STATE *output_state, void **handle); +typedef FMOD_RESULT (F_CALLBACK *FMOD_OUTPUT_GETPOSITIONCALLBACK) (FMOD_OUTPUT_STATE *output_state, unsigned int *pcm); +typedef FMOD_RESULT (F_CALLBACK *FMOD_OUTPUT_LOCKCALLBACK) (FMOD_OUTPUT_STATE *output_state, unsigned int offset, unsigned int length, void **ptr1, void **ptr2, unsigned int *len1, unsigned int *len2); +typedef FMOD_RESULT (F_CALLBACK *FMOD_OUTPUT_UNLOCKCALLBACK) (FMOD_OUTPUT_STATE *output_state, void *ptr1, void *ptr2, unsigned int len1, unsigned int len2); +typedef FMOD_RESULT (F_CALLBACK *FMOD_OUTPUT_READFROMMIXER) (FMOD_OUTPUT_STATE *output_state, void *buffer, unsigned int length); + + +/* +[STRUCTURE] +[ + [DESCRIPTION] + When creating an output, declare one of these and provide the relevant callbacks and name for FMOD to use when it opens and reads a file of this type. + + [REMARKS] + Members marked with [in] mean the variable can be written to. The user can set the value. + Members marked with [out] mean the variable is modified by FMOD and is for reading purposes only. Do not change this value. + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + FMOD_OUTPUT_STATE +] +*/ +typedef struct FMOD_OUTPUT_DESCRIPTION +{ + const char *name; /* [in] Name of the output. */ + unsigned int version; /* [in] Plugin writer's version number. */ + int polling; /* [in] If TRUE (non zero), this tells FMOD to start a thread and call getposition / lock / unlock for feeding data. If 0, the output is probably callback based, so all the plugin needs to do is call readfrommixer to the appropriate pointer. */ + FMOD_OUTPUT_GETNUMDRIVERSCALLBACK getnumdrivers; /* [in] For sound device enumeration. This callback is to give System::getNumDrivers somthing to return. */ + FMOD_OUTPUT_GETDRIVERNAMECALLBACK getdrivername; /* [in] For sound device enumeration. This callback is to give System::getDriverName somthing to return. */ + FMOD_OUTPUT_GETDRIVERCAPSCALLBACK getdrivercaps; /* [in] For sound device enumeration. This callback is to give System::getDriverCaps somthing to return. */ + FMOD_OUTPUT_INITCALLBACK init; /* [in] Initialization function for the output device. This is called from System::init. */ + FMOD_OUTPUT_CLOSECALLBACK close; /* [in] Cleanup / close down function for the output device. This is called from System::close. */ + FMOD_OUTPUT_UPDATECALLBACK update; /* [in] Update function that is called once a frame by the user. This is called from System::update. */ + FMOD_OUTPUT_GETHANDLECALLBACK gethandle; /* [in] This is called from System::getOutputHandle. This is just to return a pointer to the internal system device object that the system may be using.*/ + FMOD_OUTPUT_GETPOSITIONCALLBACK getposition; /* [in] This is called from the FMOD software mixer thread if 'polling' = true. This returns a position value in samples so that FMOD knows where and when to fill its buffer. */ + FMOD_OUTPUT_LOCKCALLBACK lock; /* [in] This is called from the FMOD software mixer thread if 'polling' = true. This function provides a pointer to data that FMOD can write to when software mixing. */ + FMOD_OUTPUT_UNLOCKCALLBACK unlock; /* [in] This is called from the FMOD software mixer thread if 'polling' = true. This optional function accepts the data that has been mixed and copies it or does whatever it needs to before sending it to the hardware. */ +} FMOD_OUTPUT_DESCRIPTION; + + +/* +[STRUCTURE] +[ + [DESCRIPTION] + Output plugin structure that is passed into each callback. + + [REMARKS] + Members marked with [in] mean the variable can be written to. The user can set the value. + Members marked with [out] mean the variable is modified by FMOD and is for reading purposes only. Do not change this value. + + [PLATFORMS] + Win32, Win64, Linux, Linux64, Macintosh, Xbox360, PlayStation Portable, PlayStation 3, Wii, iPhone, 3GS, NGP, Android + + [SEE_ALSO] + FMOD_OUTPUT_DESCRIPTION +] +*/ +struct FMOD_OUTPUT_STATE +{ + void *plugindata; /* [in] Plugin writer created data the output author wants to attach to this object. */ + FMOD_OUTPUT_READFROMMIXER readfrommixer; /* [out] Function to update mixer and write the result to the provided pointer. Used from callback based output only. Polling based output uses lock/unlock/getposition. */ +}; + +#endif + + diff --git a/libs/fmodex/lib/fmodex64_vc.lib b/libs/fmodex/lib/fmodex64_vc.lib new file mode 100644 index 000000000..77a761d34 Binary files /dev/null and b/libs/fmodex/lib/fmodex64_vc.lib differ diff --git a/libs/fmodex/lib/fmodexL64_vc.lib b/libs/fmodex/lib/fmodexL64_vc.lib new file mode 100644 index 000000000..6c008895c Binary files /dev/null and b/libs/fmodex/lib/fmodexL64_vc.lib differ diff --git a/libs/fmodex/lib/fmodexL_bc.lib b/libs/fmodex/lib/fmodexL_bc.lib new file mode 100644 index 000000000..0ae81171b Binary files /dev/null and b/libs/fmodex/lib/fmodexL_bc.lib differ diff --git a/libs/fmodex/lib/fmodexL_lcc.lib b/libs/fmodex/lib/fmodexL_lcc.lib new file mode 100644 index 000000000..0c0e22918 Binary files /dev/null and b/libs/fmodex/lib/fmodexL_lcc.lib differ diff --git a/libs/fmodex/lib/fmodexL_vc.lib b/libs/fmodex/lib/fmodexL_vc.lib new file mode 100644 index 000000000..63b6ee4fa Binary files /dev/null and b/libs/fmodex/lib/fmodexL_vc.lib differ diff --git a/libs/fmodex/lib/fmodex_bc.lib b/libs/fmodex/lib/fmodex_bc.lib new file mode 100644 index 000000000..1f5c98ca3 Binary files /dev/null and b/libs/fmodex/lib/fmodex_bc.lib differ diff --git a/libs/fmodex/lib/fmodex_lcc.lib b/libs/fmodex/lib/fmodex_lcc.lib new file mode 100644 index 000000000..235fe165c Binary files /dev/null and b/libs/fmodex/lib/fmodex_lcc.lib differ diff --git a/libs/fmodex/lib/fmodex_vc.lib b/libs/fmodex/lib/fmodex_vc.lib new file mode 100644 index 000000000..ec169885f Binary files /dev/null and b/libs/fmodex/lib/fmodex_vc.lib differ diff --git a/libs/fmodex/lib/libfmodex.a b/libs/fmodex/lib/libfmodex.a new file mode 100644 index 000000000..6c49195aa Binary files /dev/null and b/libs/fmodex/lib/libfmodex.a differ diff --git a/libs/fmodex/lib/libfmodex64_vc.a b/libs/fmodex/lib/libfmodex64_vc.a new file mode 120000 index 000000000..20ca620dc --- /dev/null +++ b/libs/fmodex/lib/libfmodex64_vc.a @@ -0,0 +1 @@ +fmodex64_vc.lib \ No newline at end of file diff --git a/libs/fmodex/lib/libfmodexL.a b/libs/fmodex/lib/libfmodexL.a new file mode 100644 index 000000000..fe253aaf6 Binary files /dev/null and b/libs/fmodex/lib/libfmodexL.a differ diff --git a/libs/fmodex/lib/libfmodexL64_vc.a b/libs/fmodex/lib/libfmodexL64_vc.a new file mode 120000 index 000000000..082105d95 --- /dev/null +++ b/libs/fmodex/lib/libfmodexL64_vc.a @@ -0,0 +1 @@ +fmodexL64_vc.lib \ No newline at end of file diff --git a/libs/fmodex/lib/libfmodexL_vc.a b/libs/fmodex/lib/libfmodexL_vc.a new file mode 120000 index 000000000..fe8fb4df3 --- /dev/null +++ b/libs/fmodex/lib/libfmodexL_vc.a @@ -0,0 +1 @@ +fmodexL_vc.lib \ No newline at end of file diff --git a/libs/fmodex/lib/libfmodex_vc.a b/libs/fmodex/lib/libfmodex_vc.a new file mode 120000 index 000000000..290610c08 --- /dev/null +++ b/libs/fmodex/lib/libfmodex_vc.a @@ -0,0 +1 @@ +fmodex_vc.lib \ No newline at end of file diff --git a/libs/fmodex/lib/which library do I use.txt b/libs/fmodex/lib/which library do I use.txt new file mode 100644 index 000000000..12738bed0 --- /dev/null +++ b/libs/fmodex/lib/which library do I use.txt @@ -0,0 +1,28 @@ +Which library do I link? +------------------------ + +If you want to use fmodex.dll: + +Visual Studio users - fmodex_vc.lib. +Metrowerks Codewarrior users - fmodex_vc.lib. +Borland users - fmodex_bc.lib. +LCC-Win32 users - fmodex_lcc.lib. +Dev-C++, MinGW and CygWin users - libfmodex.a. + +If you want to use fmodexL.dll: (same as fmodex.dll but with debug logging enabled) + +Visual Studio users - fmodexL_vc.lib. +Metrowerks Codewarrior users - fmodexL_vc.lib. +Borland users - fmodexL_bc.lib. +LCC-Win32 users - fmodexL_lcc.lib. +Dev-C++, MinGW and CygWin users - libfmodexL.a. + +If you want to use fmodex64.dll: (same as fmodex.dll but for 64bit machines) + +Visual Studio users - fmodex64_vc.lib. + +If you want to use fmodexL64.dll: (same as fmodex64.dll but with debug logging enabled) + +Visual Studio users - fmodexL64_vc.lib. + +No other compilers are supported for 64bit libraries. \ No newline at end of file diff --git a/libs/gettext/bin32/autopoint b/libs/gettext/bin32/autopoint new file mode 100755 index 000000000..0d3f47f84 --- /dev/null +++ b/libs/gettext/bin32/autopoint @@ -0,0 +1,717 @@ +#! /bin/sh +# +# Copyright (C) 2002-2010 Free Software Foundation, Inc. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +# This file is meant for authors, maintainers, co-maintainers or installers +# of packages which are internationalized with the help of GNU gettext. For +# further information how to use it consult the GNU gettext manual. + +progname=$0 +package=gettext-tools +version=0.18.1 + +# Set variables +# - gettext_dir directory where the sources are stored. +prefix="/usr/local/i686-w64-mingw32/stow/gettext-0.18.1.1" +datarootdir="${prefix}/share" +gettext_dir="${datarootdir}/gettext" + +# func_tmpdir +# creates a temporary directory. +# Sets variable +# - tmp pathname of freshly created temporary directory +func_tmpdir () +{ + # Use the environment variable TMPDIR, falling back to /tmp. This allows + # users to specify a different temporary directory, for example, if their + # /tmp is filled up or too small. + : ${TMPDIR=/tmp} + { + # Use the mktemp program if available. If not available, hide the error + # message. + tmp=`(umask 077 && mktemp -d "$TMPDIR/gtXXXXXX") 2>/dev/null` && + test -n "$tmp" && test -d "$tmp" + } || + { + # Use a simple mkdir command. It is guaranteed to fail if the directory + # already exists. $RANDOM is bash specific and expands to empty in shells + # other than bash, ksh and zsh. Its use does not increase security; + # rather, it minimizes the probability of failure in a very cluttered /tmp + # directory. + tmp=$TMPDIR/gt$$-$RANDOM + (umask 077 && mkdir "$tmp") + } || + { + echo "$0: cannot create a temporary directory in $TMPDIR" >&2 + { (exit 1); exit 1; } + } +} + +# Support for relocatability. +func_find_curr_installdir () +{ + # Determine curr_installdir, even taking into account symlinks. + curr_executable="$0" + case "$curr_executable" in + */* | *\\*) ;; + *) # Need to look in the PATH. + if test "${PATH_SEPARATOR+set}" != set; then + func_tmpdir + { echo "#! /bin/sh"; echo "exit 0"; } > "$tmp"/conf.sh + chmod +x "$tmp"/conf.sh + if (PATH="/nonexistent;$tmp"; conf.sh) >/dev/null 2>&1; then + PATH_SEPARATOR=';' + else + PATH_SEPARATOR=: + fi + rm -rf "$tmp" + fi + save_IFS="$IFS"; IFS="$PATH_SEPARATOR" + for dir in $PATH; do + IFS="$save_IFS" + test -z "$dir" && dir=. + for exec_ext in ''; do + if test -f "$dir/$curr_executable$exec_ext"; then + curr_executable="$dir/$curr_executable$exec_ext" + break 2 + fi + done + done + IFS="$save_IFS" + ;; + esac + # Make absolute. + case "$curr_executable" in + /* | ?:/* | ?:\\*) ;; + *) curr_executable=`pwd`/"$curr_executable" ;; + esac + # Resolve symlinks. + sed_dirname='s,/[^/]*$,,' + sed_linkdest='s,^.* -> \(.*\),\1,p' + while : ; do + lsline=`LC_ALL=C ls -l "$curr_executable"` + case "$lsline" in + *" -> "*) + linkdest=`echo "$lsline" | sed -n -e "$sed_linkdest"` + case "$linkdest" in + /* | ?:/* | ?:\\*) curr_executable="$linkdest" ;; + *) curr_executable=`echo "$curr_executable" | sed -e "$sed_dirname"`/"$linkdest" ;; + esac ;; + *) break ;; + esac + done + curr_installdir=`echo "$curr_executable" | sed -e 's,/[^/]*$,,'` + # Canonicalize. + curr_installdir=`cd "$curr_installdir" && pwd` +} +func_find_prefixes () +{ + # Compute the original/current installation prefixes by stripping the + # trailing directories off the original/current installation directories. + orig_installprefix="$orig_installdir" + curr_installprefix="$curr_installdir" + while true; do + orig_last=`echo "$orig_installprefix" | sed -n -e 's,^.*/\([^/]*\)$,\1,p'` + curr_last=`echo "$curr_installprefix" | sed -n -e 's,^.*/\([^/]*\)$,\1,p'` + if test -z "$orig_last" || test -z "$curr_last"; then + break + fi + if test "$orig_last" != "$curr_last"; then + break + fi + orig_installprefix=`echo "$orig_installprefix" | sed -e 's,/[^/]*$,,'` + curr_installprefix=`echo "$curr_installprefix" | sed -e 's,/[^/]*$,,'` + done +} +if test "no" = yes; then + exec_prefix="${prefix}" + bindir="${exec_prefix}/bin" + orig_installdir="$bindir" # see Makefile.am's *_SCRIPTS variables + func_find_curr_installdir # determine curr_installdir + func_find_prefixes + # Relocate the directory variables that we use. + gettext_dir=`echo "$gettext_dir/" | sed -e "s%^${orig_installprefix}/%${curr_installprefix}/%" | sed -e 's,/$,,'` +fi + +# func_usage +# outputs to stdout the --help usage message. +func_usage () +{ + echo "\ +Usage: autopoint [OPTION]... + +Copies standard gettext infrastructure files into a source package. + +Options: + --help print this help and exit + --version print version information and exit + -f, --force force overwriting of files that already exist + -n, --dry-run print modifications but don't perform them" +# echo "\ +# -V version copy the infrastructure of the specified gettext version +# (dangerous)" + echo " +Report bugs to ." +} + +# func_version +# outputs to stdout the --version message. +func_version () +{ + echo "$progname (GNU $package) $version" + echo "Uses a versions archive in git format." + echo "Copyright (C) 2002-2010 Free Software Foundation, Inc. +License GPLv3+: GNU GPL version 3 or later +This is free software: you are free to change and redistribute it. +There is NO WARRANTY, to the extent permitted by law." + echo "Written by" "Bruno Haible" +} + +# func_fatal_error message +# outputs to stderr a fatal error message, and terminates the program. +func_fatal_error () +{ + echo "autopoint: *** $1" 1>&2 + echo "autopoint: *** Stop." 1>&2 + exit 1 +} + +# Command-line option processing. +# Removes the OPTIONS from the arguments. Sets the variables: +# - force yes if --force was given, empty otherwise +# - ver gettext version if -V was given, empty otherwise +# - doit false if --dry-run was given, : otherwise +{ + force= + ver= + doit=: + + while test $# -gt 0; do + case "$1" in + -n | --dry-run | --dry-ru | --dry-r | --dry- | --dry | --dr | --d ) + shift + doit=false ;; + -f | --force | --forc | --for | --fo | --f ) + shift + force=yes ;; + --help | --hel | --he | --h ) + func_usage; exit 0 ;; +# -V ) # Some people put a space between -V and the version number. +# shift +# if test $# = 0; then +# func_usage 1>&2 +# exit 1 +# fi +# ver=$1; +# shift ;; +# -V*) # Some people omit the space between -V and the version number. +# ver=`echo "X$1" | sed -e 's/^X-V//'` +# shift ;; + --version | --versio | --versi | --vers | --ver | --ve | --v ) + func_version + exit 0 ;; + -- ) # Stop option prcessing + shift; break ;; + -* ) + echo "autopoint: unknown option $1" 1>&2 + echo "Try 'autopoint --help' for more information." 1>&2 + exit 1 ;; + * ) + break ;; + esac + done +} + +# Command-line argument processing. +# Analyzes the remaining arguments. +{ + if test $# -gt 0; then + func_usage 1>&2 + exit 1 + fi +} + +srcdir=`pwd` +# The current directory is now $srcdir. + +# Check integrity of package: A configure.in/ac must be present. Sets variable +# - configure_in name of configure.in/ac file. +if test -f configure.in; then + configure_in=configure.in +else + if test -f configure.ac; then + configure_in=configure.ac + else + # KDE specific convention: configure.in.in + if test -f configure.in.in; then + configure_in=configure.in.in + else + func_fatal_error "Missing configure.in or configure.ac, please cd to your package first." + fi + fi +fi + +# Check whether the -V option and the version number in configure.in match. +# At least one of the two must be given. If both are given, they must agree. +sed_extract_AM_GNU_GETTEXT_VERSION_argument='s/^AM_GNU_GETTEXT_VERSION(\([^()]*\)).*$/\1/' +sed_remove_outer_brackets='s/^\[\(.*\)\]$/\1/' +xver=`cat "$configure_in" | grep '^AM_GNU_GETTEXT_VERSION(' | sed -n -e "$sed_extract_AM_GNU_GETTEXT_VERSION_argument"p | sed -e "$sed_remove_outer_brackets" | sed -e 1q` +if test -z "$xver" && test -f intl/VERSION; then + xver=`cat intl/VERSION | LC_ALL=C sed -n -e 's/^.*gettext-\([-+_.0-9A-Za-z]*\).*$/\1/p'` +fi +if test -n "$xver"; then + if test -n "$ver"; then + if test "X$ver" != "X$xver"; then + func_fatal_error "Version mismatch: specified -V $ver but the package uses gettext version $xver" + fi + else + ver="$xver" + fi +else + if test -z "$ver"; then + func_fatal_error "Missing version: please specify in $configure_in through a line 'AM_GNU_GETTEXT_VERSION(x.yy.zz)' the gettext version the package is using" + fi +fi + +# Check whether the version number is supported. +case "$ver" in + 0.10.35 | 0.10.36 | 0.10.37 | 0.10.38 | 0.10.39 | 0.10.40 | \ + 0.11 | 0.11.1 | 0.11.2 | 0.11.3 | 0.11.4 | 0.11.5 | \ + 0.12 | 0.12.1 | \ + 0.13 | 0.13.1 | \ + 0.14 | 0.14.1 | 0.14.2 | 0.14.3 | 0.14.4 | 0.14.5 | 0.14.6 | \ + 0.15 | \ + 0.16 | 0.16.1 | \ + 0.17 | \ + 0.18 | 0.18.1 ) + ;; + *) + func_fatal_error "The AM_GNU_GETTEXT_VERSION declaration in your $configure_in + file requires the infrastructure from gettext-$ver but this version + is older. Please upgrade to gettext-$ver or newer." + ;; +esac + +# Check in which directory config.rpath, mkinstalldirs etc. belong. +auxdir=`cat "$configure_in" | grep '^AC_CONFIG_AUX_DIR' | sed -n -e 's/AC_CONFIG_AUX_DIR(\([^()]*\))/\1/p' | sed -e 's/^\[\(.*\)\]$/\1/' | sed -e 1q` +if test -n "$auxdir"; then + auxdir="$auxdir/" +fi + +# Check in which directory the *.m4 macros belong. +m4dir=m4 +if test -f Makefile.am; then + # A package using automake. + # Extract the macro directory name from Makefile.am. + aclocal_amflags=`grep '^ACLOCAL_AMFLAGS[ ]*=' Makefile.am | sed -e 's/^ACLOCAL_AMFLAGS[ ]*=\(.*\)$/\1/'` + m4dir_is_next= + for arg in $aclocal_amflags; do + if test -n "$m4dir_is_next"; then + m4dir="$arg" + break + else + if test "X$arg" = "X-I"; then + m4dir_is_next=yes + else + m4dir_is_next= + fi + fi + done +fi + +# Check whether to omit the intl/ directory. +omitintl=`cat "$configure_in" | grep '^AM_GNU_GETTEXT' | sed -n -e 's/^AM_GNU_GETTEXT(\([^(),]*\).*$/\1/p' | sed -e 's/^\[\(.*\)\]$/\1/' | sed -e 1q` +omitintl=`if test 'external' = "$omitintl"; then echo yes; fi` + +# Check in which directory or directories the po/* infrastructure belongs. +sed_extract_config_files='s,#.*$,, +s,^dnl .*$,, +s, dnl .*$,, +/AC_CONFIG_FILES(/ { + ta + :a + s/)/)/ + tb + s/\\$// + N + ba + :b + s,^.*AC_CONFIG_FILES([[ ]*\([^]"$`\\)]*\).*$,\1,p +}' +configfiles=`cat "$configure_in" | sed -n -e "$sed_extract_config_files"` +# PO directories have a Makefile.in generated from Makefile.in.in. +# Treat a directory as a PO directory if and only if it has a +# POTFILES.in file. This allows packages to have multiple PO +# directories under different names or in different locations. +sed_remove_Makefile_in='s,/Makefile\.in$,,' +podirs=`for f in $configfiles; do case "$f" in */Makefile.in) echo $f;; esac; done | sed -e "$sed_remove_Makefile_in"` +if test -z "$podirs"; then + # If we cannot get the list of PO directories from configure.ac, assume the + # common default. + podirs="po" +fi + +# Set up a temporary checkout directory. +# Set variables +# - work_dir directory containing the temporary checkout +work_dir=tmpwrk$$ +mkdir "$work_dir" || { + if test -d "$work_dir"; then + func_fatal_error "directory $work_dir already exists" + else + func_fatal_error "cannot create directory $work_dir" + fi +} + +# We support three archive formats. +# +# Format | Size (KiB) for gettext-0.17 | Extra tools needed | +# -------+-----------------------------+--------------------+ +# dir | 3000 | -- | +# cvs | 356 | cvs | +# git | 484 | git | +# -------+-----------------------------+--------------------+ + +case "git" in + dir) + # The archive of different versions is very large, but using it does not + # require special tools. + gzip -d -c < "$gettext_dir/archive.dir.tar.gz" | (cd "$work_dir" && tar xf - "gettext-$ver") + if test `find "$work_dir" -type f -print | wc -l` = 0; then + rm -rf "$work_dir" + func_fatal_error "infrastructure files for version $ver not found; this is autopoint from GNU $package $version" + fi + mv "$work_dir/gettext-$ver" "$work_dir/archive" + ;; + + cvs) + # We distributed the many different versions of the files in a CVS + # repository. This guaranteed a good compression rate: + # + # Including version size in KB of + # "du autopoint-files/archive" + # 0.10.35 240 + # 0.10.36 428 + # 0.10.37 436 + # 0.10.38 488 + # 0.10.39 500 + # 0.10.40 528 + # 0.11 720 + # 0.11.1 740 + # 0.11.2 748 + # 0.11.3 804 + # 0.11.4 864 + # 0.11.5 880 + # 0.12 1032 + # 0.12.1 1032 + # 0.13 1220 + # 0.13.1 1236 + # 0.14 1296 + # 0.14.1 1300 + # 0.14.2 1420 + # 0.14.3 1428 + # 0.14.4 1464 + # 0.14.5 1508 + # 0.14.6 1580 + # 0.15 1760 + # 0.16 1808 + # 0.16.1 1812 + # 0.17 2128 + # 0.18 2656 + # + # The requirement that the user must have the CVS program available is not + # a severe restrictions, because most of the people who use autopoint are + # users of CVS. + # + # But the CVS format is now deprecated, because "cvs init" does not work in + # all circumstances + # (see ) + # and we are not allowed to distribute the cvs infrastructure files + # ourselves + # (see ). + # + # Check availability of the CVS program. + (cvs -v) >/dev/null 2>/dev/null || func_fatal_error "cvs program not found" + + # Set up a temporary CVS repository. + # We need the temporary CVS repository because any checkout needs write + # access to the CVSROOT/history file, so it cannot be under $gettext_dir. + # We need the temporary checkout directory because when --force was not + # given, we need to compare the existing files with the checked out ones. + # Set variables + # - cvs_dir directory containing the temporary repository + cvs_dir=tmpcvs$$ + # Use an umask of 077, to avoid attacks that work by overwriting files in + # the "$CVSROOT"/CVSROOT directory. + (umask 077 && mkdir "$cvs_dir") || { + if test -d "$cvs_dir"; then + func_fatal_error "directory $cvs_dir already exists" + else + func_fatal_error "cannot create directory $cvs_dir" + fi + } + CVSROOT="$srcdir/$cvs_dir" + unset CVS_CLIENT_LOG + unset CVS_CLIENT_PORT + unset CVS_IGNORE_REMOTE_ROOT + unset CVS_LOCAL_BRANCH_NUM + unset CVS_NOBASES + unset CVS_PASSFILE + unset CVS_PASSWORD + unset CVS_PROXY_PORT + unset CVS_RCMD_PORT + unset CVS_RSH + unset CVS_SERVER + unset CVS_SERVER_SLEEP + CVS_SIGN_COMMITS= + export CVS_SIGN_COMMITS + unset CVS_SSH + unset CVS_VERIFY_CHECKOUTS + unset CVS_VERIFY_TEMPLATE + unset CVSIGNORE + unset CVSREAD + unset CVSREADONLYFS + unset CVSUMASK + unset CVSWRAPPERS + + # Need to pass -d "$CVSROOT", because there may be a CVS directory in the + # current directory. + cvs -d "$CVSROOT" init + gzip -d -c < "$gettext_dir/archive.cvs.tar.gz" | (cd "$cvs_dir" && tar xf -) + + cd "$work_dir" + cvsver=gettext-`echo "$ver" | sed -e 's/\./_/g'` + (cvs -d "$CVSROOT" checkout -r"$cvsver" archive > /dev/null) 2>&1 | grep -v '^cvs checkout: Updating' + find archive -name CVS -type d -print | xargs rm -rf + cd .. + rm -rf "$cvs_dir" + # Check that really all CVS directories are gone, otherwise we would overwrite + # the contents of the user's CVS directories. + if test `find $work_dir/archive -name CVS -type d -print | wc -l` != 0; then + rm -rf "$work_dir" + func_fatal_error "failed to remove all CVS subdirectories" + fi + if test `find $work_dir/archive -type f -print | wc -l` = 0; then + rm -rf "$work_dir" + func_fatal_error "infrastructure files for version $ver not found; this is autopoint from GNU $package $version" + fi + ;; + + git) + # Check availability of the git program. + (git --version) >/dev/null 2>/dev/null || func_fatal_error "git program not found" + mkdir "$work_dir/archive" + gzip -d -c < "$gettext_dir/archive.git.tar.gz" | (cd "$work_dir/archive" && tar xf -) + (cd "$work_dir/archive" && git checkout -q "gettext-$ver") || { + rm -rf "$work_dir" + func_fatal_error "infrastructure files for version $ver not found; this is autopoint from GNU $package $version" + } + (cd "$work_dir/archive" && rm -rf .git .gitignore) + ;; +esac + +# func_destfile file +# determines the destination file, relative to the package's top level +# directory, for a given file name, relative to archive. +# Sets variables +# - destfile relative destination file name, or +# empty if the file shall be omitted +# - sharedowner yes if the file is not only owned by GNU gettext but may +# be installed by automake or other tools, otherwise empty +# - allpodirs yes if the file is to be installed in every dir in $podirs +func_destfile () +{ + # There are five categories of files: + # ABOUT_NLS -> top level directory + # config.rpath mkinstalldirs -> $auxdir + # m4/* -> $m4dir/ + # intl/* -> intl/ + # po/* -> + sharedowner= + allpodirs= + case `echo "$1" | sed -e 's,[^/]*$,,'` in + "" ) + case "$1" in + config.rpath ) destfile="$auxdir$1" ;; + mkinstalldirs ) destfile="$auxdir$1" sharedowner=yes ;; + * ) destfile="$1" ;; + esac + ;; + m4/ ) destfile=`echo "$1" | sed -e "s,^m4/,$m4dir/,"` ;; + intl/ ) if test -n "$omitintl"; then destfile=""; else destfile="$1"; fi ;; + po/ ) destfile=`echo "$1" | sed -e "s,^po/,,"` allpodirs=yes ;; + * ) destfile="$1" ;; + esac +} + +# func_compare existingfile gettextfile +# compares the existing file and the file from gettext, and decides whether the +# existing file should be overwritten with the file from gettext. Returns 0 if +# it should be overwritten, or 1 if it should be skipped. +sed_extract_serial='s/^#.* serial \([^ ]*\).*/\1/p +1q' +func_compare () +{ + if cmp -s "$1" "$2"; then + false + else + case "$2" in + *.m4) + # For interoperability with gnulib. gnulib often has newer versions of + # the *.m4 files than the latest gettext release. Don't overwrite a + # newer version from gnulib with an older version from the gettext + # release. The version can be retrieved from the first line, which + # looks like this: # file.m4 serial NN ... + existing_serial=`sed -n -e "$sed_extract_serial" < "$1"` + gettext_serial=`sed -n -e "$sed_extract_serial" < "$2"` + if test -n "$existing_serial" && test -n "$gettext_serial" \ + && test "$existing_serial" -ge "$gettext_serial" 2> /dev/null; then + false + else + true + fi + ;; + *) + true + ;; + esac + fi +} + +# If some files have been locally modified and we have not been requested +# to overwrite them, then bail out. This is better than leaving a source +# package around where half of the files are locally modified and half are +# original - too great risk of version mismatch. +if test -z "$force"; then + mismatch= + func_tmpdir + mismatchfile="$tmp"/autopoint.diff + for file in `find "$work_dir/archive" -type f -print | sed -e "s,^$work_dir/archive/,," | LC_ALL=C sort`; do + func_destfile "$file" + if test -n "$destfile"; then + func_compare_to_destfile () + { + finaldestfile="$1" + if test -f "$finaldestfile"; then + if func_compare "$finaldestfile" "$work_dir/archive/$file"; then + if test -n "$sharedowner"; then + echo "autopoint: warning: File $finaldestfile has been locally modified." 1>&2 + else + echo "autopoint: File $finaldestfile has been locally modified." 1>&2 + mismatch=yes + diff -c "$work_dir/archive/$file" "$finaldestfile" | sed -e "1s,$work_dir/archive/,," >> "$mismatchfile" + fi + fi + fi + } + if test -n "$allpodirs"; then + for dir in $podirs; do + func_compare_to_destfile "$dir/$destfile" + done + else + func_compare_to_destfile "$destfile" + fi + fi + done + if test -n "$mismatch"; then + rm -rf "$work_dir" + func_fatal_error "Some files have been locally modified. Not overwriting them because --force has not been specified. For your convenience, you find the local modifications in the file '$mismatchfile'." + fi + rm -rf "$tmp" +fi + +# func_mkdir_for to +# ensures the directory that would the given file exists. +# 'to' is a relative pathname, relative to the current directory. +func_mkdir_for () +{ + base=`echo "$1" | sed -e 's,/[^/]*$,,'` + if test "X$base" != "X$1" && test -n "$base"; then + func_mkdir_for "$base" + # Recompute base. It was clobbered by the recursive call. + base=`echo "$1" | sed -e 's,/[^/]*$,,'` + test -d "$base" || { echo "Creating directory $base"; mkdir "$base"; } + fi +} + +# func_copy from to +# copies a file. +# 'from' is a relative pathname, relative to the current directory. +# 'to' is a relative pathname, relative to the current directory. +func_copy () +{ + if $doit; then + func_mkdir_for "$2" + rm -f "$2" + echo "Copying file $2" + cp "$1" "$2" + else + echo "Copy file $2" + fi +} + +# func_backup to +# makes a backup of a file that is about to be overwritten or replaced. +# 'to' is a relative pathname, relative to the current directory. +func_backup () +{ + if $doit; then + if test -f "$1"; then + rm -f "$1~" + cp -p "$1" "$1~" + fi + fi +} + +# Now copy the files. +for file in `find "$work_dir/archive" -type f -print | sed -e "s,^$work_dir/archive/,," | LC_ALL=C sort`; do + func_destfile "$file" + if test -n "$destfile"; then + func_copy_to_destfile () + { + finaldestfile="$1" + mustcopy= + if test -f "$finaldestfile"; then + if func_compare "$finaldestfile" "$work_dir/archive/$file"; then + if test -n "$force"; then + # Overwrite locally modified file. + mustcopy=yes + fi + # If --force is not specified, don't overwrite locally modified files + # for which GNU gettext is a shared owner. + fi + else + mustcopy=yes + fi + if test -n "$mustcopy"; then + func_backup "$finaldestfile" + func_copy "$work_dir/archive/$file" "$finaldestfile" + fi + } + if test -n "$allpodirs"; then + for dir in $podirs; do + func_copy_to_destfile "$dir/$destfile" + done + else + func_copy_to_destfile "$destfile" + fi + fi +done + +# That's it. +rm -rf "$work_dir" +exit 0 diff --git a/libs/gettext/bin32/envsubst.exe b/libs/gettext/bin32/envsubst.exe new file mode 100644 index 000000000..3c326aa0d Binary files /dev/null and b/libs/gettext/bin32/envsubst.exe differ diff --git a/libs/gettext/bin32/gettext.exe b/libs/gettext/bin32/gettext.exe new file mode 100644 index 000000000..eb1048ebc Binary files /dev/null and b/libs/gettext/bin32/gettext.exe differ diff --git a/libs/gettext/bin32/gettext.sh b/libs/gettext/bin32/gettext.sh new file mode 100755 index 000000000..2369ab501 --- /dev/null +++ b/libs/gettext/bin32/gettext.sh @@ -0,0 +1,123 @@ +#! /bin/sh +# +# Copyright (C) 2003, 2005-2007 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU Library General Public License as published +# by the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU Library General Public +# License along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +# USA. +# + +# Find a way to echo strings without interpreting backslash. +if test "X`(echo '\t') 2>/dev/null`" = 'X\t'; then + echo='echo' +else + if test "X`(printf '%s\n' '\t') 2>/dev/null`" = 'X\t'; then + echo='printf %s\n' + else + echo_func () { + cat < +This is free software: you are free to change and redistribute it. +There is NO WARRANTY, to the extent permitted by law." + echo "Written by" "Bruno Haible" + } + if test $# = 1; then + case "$1" in + --help | --hel | --he | --h ) + func_usage; exit 0 ;; + --version | --versio | --versi | --vers | --ver | --ve | --v ) + func_version; exit 0 ;; + esac + fi + func_usage 1>&2 + exit 1 + ;; + esac +fi + +# eval_gettext MSGID +# looks up the translation of MSGID and substitutes shell variables in the +# result. +eval_gettext () { + gettext "$1" | (export PATH `envsubst --variables "$1"`; envsubst "$1") +} + +# eval_ngettext MSGID MSGID-PLURAL COUNT +# looks up the translation of MSGID / MSGID-PLURAL for COUNT and substitutes +# shell variables in the result. +eval_ngettext () { + ngettext "$1" "$2" "$3" | (export PATH `envsubst --variables "$1 $2"`; envsubst "$1 $2") +} + +# Note: This use of envsubst is much safer than using the shell built-in 'eval' +# would be. +# 1) The security problem with Chinese translations that happen to use a +# character such as \xe0\x60 is avoided. +# 2) The security problem with malevolent translators who put in command lists +# like "$(...)" or "`...`" is avoided. +# 3) The translations can only refer to shell variables that are already +# mentioned in MSGID or MSGID-PLURAL. +# +# Note: "export PATH" above is a dummy; this is for the case when +# `envsubst --variables ...` returns nothing. +# +# Note: In eval_ngettext above, "$1 $2" means a string whose variables set is +# the union of the variables set of "$1" and "$2". +# +# Note: The minimal use of backquote above ensures that trailing newlines are +# not dropped, not from the gettext invocation and not from the value of any +# shell variable. +# +# Note: Field splitting on the `envsubst --variables ...` result is desired, +# since envsubst outputs the variables, separated by newlines. Pathname +# wildcard expansion or tilde expansion has no effect here, since the words +# output by "envsubst --variables ..." consist solely of alphanumeric +# characters and underscore. diff --git a/libs/gettext/bin32/gettextize b/libs/gettext/bin32/gettextize new file mode 100755 index 000000000..27a23b732 --- /dev/null +++ b/libs/gettext/bin32/gettextize @@ -0,0 +1,1281 @@ +#! /bin/sh +# +# Copyright (C) 1995-1998, 2000-2010 Free Software Foundation, Inc. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +# This file is meant for authors or maintainers which want to +# internationalize their package with the help of GNU gettext. For +# further information how to use it consult the GNU gettext manual. + +progname=$0 +package=gettext-tools +version=0.18.1 + +# Set variables +# - gettext_dir directory where the sources are stored. +prefix="/usr/local/i686-w64-mingw32/stow/gettext-0.18.1.1" +datarootdir="${prefix}/share" +gettext_dir="${datarootdir}/gettext" + +# func_tmpdir +# creates a temporary directory. +# Sets variable +# - tmp pathname of freshly created temporary directory +func_tmpdir () +{ + # Use the environment variable TMPDIR, falling back to /tmp. This allows + # users to specify a different temporary directory, for example, if their + # /tmp is filled up or too small. + : ${TMPDIR=/tmp} + { + # Use the mktemp program if available. If not available, hide the error + # message. + tmp=`(umask 077 && mktemp -d "$TMPDIR/gtXXXXXX") 2>/dev/null` && + test -n "$tmp" && test -d "$tmp" + } || + { + # Use a simple mkdir command. It is guaranteed to fail if the directory + # already exists. $RANDOM is bash specific and expands to empty in shells + # other than bash, ksh and zsh. Its use does not increase security; + # rather, it minimizes the probability of failure in a very cluttered /tmp + # directory. + tmp=$TMPDIR/gt$$-$RANDOM + (umask 077 && mkdir "$tmp") + } || + { + echo "$0: cannot create a temporary directory in $TMPDIR" >&2 + { (exit 1); exit 1; } + } +} + +# Support for relocatability. +func_find_curr_installdir () +{ + # Determine curr_installdir, even taking into account symlinks. + curr_executable="$0" + case "$curr_executable" in + */* | *\\*) ;; + *) # Need to look in the PATH. + if test "${PATH_SEPARATOR+set}" != set; then + func_tmpdir + { echo "#! /bin/sh"; echo "exit 0"; } > "$tmp"/conf.sh + chmod +x "$tmp"/conf.sh + if (PATH="/nonexistent;$tmp"; conf.sh) >/dev/null 2>&1; then + PATH_SEPARATOR=';' + else + PATH_SEPARATOR=: + fi + rm -rf "$tmp" + fi + save_IFS="$IFS"; IFS="$PATH_SEPARATOR" + for dir in $PATH; do + IFS="$save_IFS" + test -z "$dir" && dir=. + for exec_ext in ''; do + if test -f "$dir/$curr_executable$exec_ext"; then + curr_executable="$dir/$curr_executable$exec_ext" + break 2 + fi + done + done + IFS="$save_IFS" + ;; + esac + # Make absolute. + case "$curr_executable" in + /* | ?:/* | ?:\\*) ;; + *) curr_executable=`pwd`/"$curr_executable" ;; + esac + # Resolve symlinks. + sed_dirname='s,/[^/]*$,,' + sed_linkdest='s,^.* -> \(.*\),\1,p' + while : ; do + lsline=`LC_ALL=C ls -l "$curr_executable"` + case "$lsline" in + *" -> "*) + linkdest=`echo "$lsline" | sed -n -e "$sed_linkdest"` + case "$linkdest" in + /* | ?:/* | ?:\\*) curr_executable="$linkdest" ;; + *) curr_executable=`echo "$curr_executable" | sed -e "$sed_dirname"`/"$linkdest" ;; + esac ;; + *) break ;; + esac + done + curr_installdir=`echo "$curr_executable" | sed -e 's,/[^/]*$,,'` + # Canonicalize. + curr_installdir=`cd "$curr_installdir" && pwd` +} +func_find_prefixes () +{ + # Compute the original/current installation prefixes by stripping the + # trailing directories off the original/current installation directories. + orig_installprefix="$orig_installdir" + curr_installprefix="$curr_installdir" + while true; do + orig_last=`echo "$orig_installprefix" | sed -n -e 's,^.*/\([^/]*\)$,\1,p'` + curr_last=`echo "$curr_installprefix" | sed -n -e 's,^.*/\([^/]*\)$,\1,p'` + if test -z "$orig_last" || test -z "$curr_last"; then + break + fi + if test "$orig_last" != "$curr_last"; then + break + fi + orig_installprefix=`echo "$orig_installprefix" | sed -e 's,/[^/]*$,,'` + curr_installprefix=`echo "$curr_installprefix" | sed -e 's,/[^/]*$,,'` + done +} +if test "no" = yes; then + exec_prefix="${prefix}" + bindir="${exec_prefix}/bin" + orig_installdir="$bindir" # see Makefile.am's *_SCRIPTS variables + func_find_curr_installdir # determine curr_installdir + func_find_prefixes + # Relocate the directory variables that we use. + gettext_dir=`echo "$gettext_dir/" | sed -e "s%^${orig_installprefix}/%${curr_installprefix}/%" | sed -e 's,/$,,'` +fi + +# func_usage +# outputs to stdout the --help usage message. +func_usage () +{ + echo "\ +Usage: gettextize [OPTION]... [package-dir] + +Prepares a source package to use gettext. + +Options: + --help print this help and exit + --version print version information and exit + -f, --force force writing of new files even if old exist + --intl install libintl in a subdirectory (deprecated) + --po-dir=DIR specify directory with PO files + --no-changelog don't update or create ChangeLog files + --symlink make symbolic links instead of copying files + -n, --dry-run print modifications but don't perform them + +Report bugs to ." +} + +# func_version +# outputs to stdout the --version message. +func_version () +{ + echo "$progname (GNU $package) $version" + echo "Copyright (C) 1995-1998, 2000-2010 Free Software Foundation, Inc. +License GPLv3+: GNU GPL version 3 or later +This is free software: you are free to change and redistribute it. +There is NO WARRANTY, to the extent permitted by law." + echo "Written by" "Ulrich Drepper" +} + +# func_fatal_error message +# outputs to stderr a fatal error message, and terminates the program. +func_fatal_error () +{ + echo "gettextize: *** $1" 1>&2 + echo "gettextize: *** Stop." 1>&2 + exit 1 +} + +# Nuisances. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + +# Command-line option processing. +# Removes the OPTIONS from the arguments. Sets the variables: +# - force 1 if --force was given, 0 otherwise +# - intldir yes if --intl was given, empty otherwise +# - podirs list of directories specified with --po-dir +# - try_ln_s : if --symlink was given, false otherwise +# - do_changelog false if --no-changelog was given, : otherwise +# - doit false if --dry-run was given, : otherwise +{ + force=0 + intldir= + podirs= + try_ln_s=false + do_changelog=: + doit=: + + while test $# -gt 0; do + case "$1" in + -c | --copy | --cop | --co | --c ) # accepted for backward compatibility + shift ;; + -n | --dry-run | --dry-ru | --dry-r | --dry- | --dry | --dr | --d ) + shift + doit=false ;; + -f | --force | --forc | --for | --fo | --f ) + shift + force=1 ;; + --help | --hel | --he | --h ) + func_usage; exit 0 ;; + --intl | --int | --in | --i ) + shift + intldir=yes ;; + --po-dir | --po-di | --po-d | --po- | --po | --p ) + shift + if test $# = 0; then + func_fatal_error "missing argument for --po-dir" + fi + case "$1" in + -*) func_fatal_error "missing argument for --po-dir" ;; + esac + podirs="$podirs $1" + shift ;; + --po-dir=* ) + arg=`echo "X$1" | sed -e 's/^X--po-dir=//'` + podirs="$podirs $arg" + shift ;; + --no-changelog | --no-changelo | --no-changel | --no-change | --no-chang | --no-chan | --no-cha | --no-ch | --no-c ) + shift + do_changelog=false ;; + --symlink | --symlin | --symli | --syml | --sym | --sy | --s ) + shift + try_ln_s=: ;; + --version | --versio | --versi | --vers | --ver | --ve | --v ) + func_version + exit 0 ;; + -- ) # Stop option prcessing + shift; break ;; + -* ) + echo "gettextize: unknown option $1" 1>&2 + echo "Try 'gettextize --help' for more information." 1>&2 + exit 1 ;; + * ) + break ;; + esac + done + # podirs defaults to "po". + test -n "$podirs" || podirs="po" +} + +# Warn about deprecated options. +if test -n "$intldir"; then + echo "gettextize: warning: the option '--intl' is deprecated and will be removed" 1>&2 +fi + +# Command-line argument processing. +# Analyzes the remaining arguments. +# Sets the variables +# - origdir to the original directory, +# - srcdir to the package directory, and cd-s into it. +{ + if test $# -gt 1; then + func_usage 1>&2 + exit 1 + fi + origdir=`pwd` + if test $# -eq 1; then + srcdir=$1 + if cd "$srcdir"; then + srcdir=`pwd` + else + func_fatal_error "Cannot change directory to '$srcdir'." + fi + else + srcdir=$origdir + fi +} + +# The current directory is now $srcdir. + +# Check integrity of package: A configure.in/ac must be present. Sets variable +# - configure_in name of configure.in/ac file. +test -f configure.in || test -f configure.ac || + func_fatal_error "Missing configure.in or configure.ac, please cd to your package first." +configure_in=NONE +if test -f configure.in; then + configure_in=configure.in +else + if test -f configure.ac; then + configure_in=configure.ac + fi +fi + +# Check whether the --force option is needed but has not been specified. +if test $force -eq 0; then + if test -d intl; then + func_fatal_error "intl/ subdirectory exists: use option -f if you really want to delete it." + fi + for podir in $podirs; do + if test -f "$podir/Makefile.in.in"; then + func_fatal_error "$podir/Makefile.in.in exists: use option -f if you really want to delete it." + fi + done + if test -f ABOUT-NLS; then + func_fatal_error "ABOUT-NLS exists: use option -f if you really want to delete it." + fi +fi + +# Check in which directory config.rpath etc. belong. +auxdir=`cat "$configure_in" | grep '^AC_CONFIG_AUX_DIR' | sed -n -e 's/AC_CONFIG_AUX_DIR(\([^()]*\))/\1/p' | sed -e 's/^\[\(.*\)\]$/\1/' | sed -e 1q` +if test -n "$auxdir"; then + auxdir="$auxdir/" +fi + +# For simplicity we change to the gettext source directory. +cd "$gettext_dir" || + func_fatal_error "gettext source directory '${gettext_dir}' doesn't exist" + +# Variables which keep track what has been modified. +added_directories= +removed_directory= +added_extradist= +added_acoutput= +removed_acoutput=" intl/intlh.inst" + +# Variable: +# - please accumulates instructions for the user. +please= + +# Variable: +# - date current date, for use in ChangeLog entries. +date=`date +%Y-%m-%d` + +# func_copy from to +# copies a file. +# 'from' is a relative pathname, relative to the current directory. +# 'to' is a relative pathname, relative to $srcdir. +func_copy () +{ + if $doit; then + rm -f "$srcdir/$2" + echo "Copying file $2" + cp "$1" "$srcdir/$2" + else + echo "Copy file $2" + fi +} + +# func_linkorcopy from absfrom to +# links or copies a file. +# 'from' is a relative pathname, relative to the current directory. +# 'absfrom' is the corresponding absolute pathname. +# 'to' is a relative pathname, relative to $srcdir. +func_linkorcopy () +{ + if $doit; then + rm -f "$srcdir/$3" + ($try_ln_s && ln -s "$2" "$srcdir/$3" && echo "Symlinking file $3") 2>/dev/null || + { echo "Copying file $3"; cp "$1" "$srcdir/$3"; } + else + if $try_ln_s; then + echo "Symlink file $3" + else + echo "Copy file $3" + fi + fi +} + +# func_backup to +# makes a backup of a file that is about to be overwritten or replaced. +# 'to' is a relative pathname, relative to $srcdir. +func_backup () +{ + if $doit; then + if test -f "$srcdir/$1"; then + rm -f "$srcdir/$1~" + cp -p "$srcdir/$1" "$srcdir/$1~" + fi + fi +} + +# func_remove to +# removes a file. +# 'to' is a relative pathname, relative to $srcdir. +func_remove () +{ + if $doit; then + echo "Removing $1" + rm -f "$srcdir/$1" + else + echo "Remove $1" + fi +} + +# func_ChangeLog_init +# func_ChangeLog_add_entry line +# func_ChangeLog_finish +# manage the ChangeLog file, relative to $srcdir. +func_ChangeLog_init () +{ + modified_ChangeLog= +} +func_ChangeLog_add_entry () +{ + if $doit; then + if test -z "$modified_ChangeLog"; then + echo "$date gettextize " > "$srcdir/ChangeLog.tmp" + echo >> "$srcdir/ChangeLog.tmp" + modified_ChangeLog=yes + fi + echo "$1" >> "$srcdir/ChangeLog.tmp" + else + modified_ChangeLog=yes + fi +} +func_ChangeLog_finish () +{ + if test -n "$modified_ChangeLog"; then + if $doit; then + echo >> "$srcdir/ChangeLog.tmp" + if test -f "$srcdir/ChangeLog"; then + echo "Adding an entry to ChangeLog (backup is in ChangeLog~)" + cat "$srcdir/ChangeLog" >> "$srcdir/ChangeLog.tmp" + rm -f "$srcdir/ChangeLog~" + cp -p "$srcdir/ChangeLog" "$srcdir/ChangeLog~" + else + echo "Creating ChangeLog" + fi + cp "$srcdir/ChangeLog.tmp" "$srcdir/ChangeLog" + rm -f "$srcdir/ChangeLog.tmp" + else + if test -f "$srcdir/ChangeLog"; then + echo "Add an entry to ChangeLog" + else + echo "Create ChangeLog" + fi + fi + fi +} + +# func_poChangeLog_init +# func_poChangeLog_add_entry line +# func_poChangeLog_finish +# manage the $podir/ChangeLog file, relative to $srcdir. +func_poChangeLog_init () +{ + modified_poChangeLog= +} +func_poChangeLog_add_entry () +{ + if $doit; then + if test -z "$modified_poChangeLog"; then + echo "$date gettextize " > "$srcdir/$podir/ChangeLog.tmp" + echo >> "$srcdir/$podir/ChangeLog.tmp" + modified_poChangeLog=yes + fi + echo "$1" >> "$srcdir/$podir/ChangeLog.tmp" + else + modified_poChangeLog=yes + fi +} +func_poChangeLog_finish () +{ + if test -n "$modified_poChangeLog"; then + if $doit; then + echo >> "$srcdir/$podir/ChangeLog.tmp" + if test -f "$srcdir/$podir/ChangeLog"; then + echo "Adding an entry to $podir/ChangeLog (backup is in $podir/ChangeLog~)" + cat "$srcdir/$podir/ChangeLog" >> "$srcdir/$podir/ChangeLog.tmp" + rm -f "$srcdir/$podir/ChangeLog~" + cp -p "$srcdir/$podir/ChangeLog" "$srcdir/$podir/ChangeLog~" + else + echo "Creating $podir/ChangeLog" + fi + cp "$srcdir/$podir/ChangeLog.tmp" "$srcdir/$podir/ChangeLog" + rm -f "$srcdir/$podir/ChangeLog.tmp" + else + if test -f "$srcdir/$podir/ChangeLog"; then + echo "Add an entry to $podir/ChangeLog" + else + echo "Create $podir/ChangeLog" + fi + fi + fi +} + +# func_m4ChangeLog_init +# func_m4ChangeLog_add_entry line +# func_m4ChangeLog_finish +# manage the $m4dir/ChangeLog file, relative to $srcdir. +func_m4ChangeLog_init () +{ + if test -n "$using_m4ChangeLog"; then + modified_m4ChangeLog= + created_m4ChangeLog= + fi +} +func_m4ChangeLog_add_entry () +{ + if test -n "$using_m4ChangeLog"; then + if $doit; then + if test -z "$modified_m4ChangeLog"; then + echo "$date gettextize " > "$srcdir/$m4dir/ChangeLog.tmp" + echo >> "$srcdir/$m4dir/ChangeLog.tmp" + modified_m4ChangeLog=yes + fi + echo "$1" >> "$srcdir/$m4dir/ChangeLog.tmp" + else + modified_m4ChangeLog=yes + fi + else + line="$1" + line=`echo "$line" | sed -e "s%^ \\* % * $m4dir/%"` + func_ChangeLog_add_entry "$line" + fi +} +func_m4ChangeLog_finish () +{ + if test -n "$using_m4ChangeLog"; then + if test -n "$modified_m4ChangeLog"; then + if $doit; then + echo >> "$srcdir/$m4dir/ChangeLog.tmp" + if test -f "$srcdir/$m4dir/ChangeLog"; then + echo "Adding an entry to $m4dir/ChangeLog (backup is in $m4dir/ChangeLog~)" + cat "$srcdir/$m4dir/ChangeLog" >> "$srcdir/$m4dir/ChangeLog.tmp" + rm -f "$srcdir/$m4dir/ChangeLog~" + cp -p "$srcdir/$m4dir/ChangeLog" "$srcdir/$m4dir/ChangeLog~" + else + echo "Creating $m4dir/ChangeLog" + created_m4ChangeLog=yes + fi + cp "$srcdir/$m4dir/ChangeLog.tmp" "$srcdir/$m4dir/ChangeLog" + rm -f "$srcdir/$m4dir/ChangeLog.tmp" + else + if test -f "$srcdir/$m4dir/ChangeLog"; then + echo "Add an entry to $m4dir/ChangeLog" + else + echo "Create $m4dir/ChangeLog" + created_m4ChangeLog=yes + fi + fi + fi + fi +} +using_m4ChangeLog=yes + +if test ! -f "$srcdir/intl/Makefile.in" && test -n "$intldir"; then + added_acoutput="$added_acoutput intl/Makefile" +fi +if test -f "$srcdir/intl/Makefile.in" && test -z "$intldir"; then + removed_acoutput="$removed_acoutput intl/Makefile" +fi +if test -d "$srcdir/intl"; then + # Remove everything inside intl except for RCS and CVS subdirs and invisible + # files. + if $doit; then + echo "Wiping out intl/ subdirectory" + (cd "$srcdir/intl" && + for f in *; do + if test CVS != "$f" && test RCS != "$f"; then + rm -rf "$f" + fi + done) + else + echo "Wipe out intl/ subdirectory" + fi + if test -z "$intldir"; then + removed_directory=intl + fi +else + if test -n "$intldir"; then + if $doit; then + echo "Creating intl/ subdirectory" + mkdir "$srcdir/intl" || func_fatal_error "failed to create intl/ subdirectory" + else + echo "Create intl/ subdirectory" + fi + added_directories="$added_directories intl" + fi +fi + +$do_changelog && func_ChangeLog_init + +for podir in $podirs; do + test -d "$srcdir/$podir" || { + if $doit; then + echo "Creating $podir/ subdirectory" + mkdir "$srcdir/$podir" || func_fatal_error "failed to create $podir/ subdirectory" + else + echo "Create $podir/ subdirectory" + fi + added_directories="$added_directories $podir" + } +done + +# Create the directory for config.rpath, if needed. +# This is for consistency with autoreconf and automake. +# Note that $auxdir is either empty or ends in a slash. +test -d "$srcdir/$auxdir" || { + if $doit; then + echo "Creating $auxdir subdirectory" + mkdir "$srcdir/$auxdir" || func_fatal_error "failed to create $auxdir subdirectory" + else + echo "Create $auxdir subdirectory" + fi +} + +# Now copy all files. Take care for the destination directories. +for file in *; do + case $file in + ABOUT-NLS) + func_linkorcopy $file "$gettext_dir/$file" $file + ;; + config.rpath) + if test -f "$srcdir/$auxdir$file"; then + : + else + added_extradist="$added_extradist $auxdir$file" + fi + func_linkorcopy $file "$gettext_dir/$file" "$auxdir$file" + ;; + esac +done + +# Copy files to intl/ subdirectory. +if test -n "$intldir"; then + cd intl + for file in *; do + if test $file != COPYING.LIB-2.0 && test $file != COPYING.LIB-2.1; then + if test $file != plural.c; then + func_linkorcopy $file "$gettext_dir/intl/$file" intl/$file + else + # plural.c is a generated file; it must be copied and touched. + func_copy $file intl/$file + if $doit; then + (sleep 2; touch "$srcdir/intl/$file") & + fi + fi + fi + done + cd .. +else + echo "Not copying intl/ directory." + # Tell the user what to put into configure.ac, if it is not already there. + if grep '^AM_GNU_GETTEXT([[]\?external[]]\?[ ]*[,)]' "$srcdir/$configure_in" > /dev/null; then + : + else + please="$please +Please use AM_GNU_GETTEXT([external]) in order to cause autoconfiguration +to look for an external libintl. +" + fi +fi + +# Copy files to po/ subdirectory. +cd po +for podir in $podirs; do + $do_changelog && func_poChangeLog_init + for file in Makefile.in.in; do + same=no + if test -f "$srcdir/$podir/$file"; then + if cmp -s $file "$srcdir/$podir/$file"; then + same=yes + fi + else + added_acoutput="$added_acoutput $podir/Makefile.in" + fi + if $do_changelog && test $same = no; then + if test -f "$srcdir/$podir/$file"; then + func_poChangeLog_add_entry " * $file: Upgrade to gettext-${version}." + else + func_poChangeLog_add_entry " * $file: New file, from gettext-${version}." + fi + fi + func_backup "$podir/$file" + func_linkorcopy $file "$gettext_dir/po/$file" "$podir/$file" + done + for file in *; do + case $file in + Makefile.in.in) + # Already handled above. + ;; + Makevars.template) + func_linkorcopy Makevars.template "$gettext_dir/po/Makevars.template" "$podir/Makevars.template" + if test -f "$srcdir/po/Makevars"; then + LC_ALL=C sed -n -e 's/[ ]*\([A-Za-z0-9_]*\)[ ]*=.*/\1/p' < "$srcdir/$podir/Makevars" | LC_ALL=C sort > "$srcdir/$podir/Makevars.tmp1" + LC_ALL=C sed -n -e 's/[ ]*\([A-Za-z0-9_]*\)[ ]*=.*/\1/p' < "$srcdir/$podir/Makevars.template" | LC_ALL=C sort > "$srcdir/$podir/Makevars.tmp2" + missingvars=`LC_ALL=C comm -13 "$srcdir/$podir/Makevars.tmp1" "$srcdir/$podir/Makevars.tmp2"` + rm -f "$srcdir/$podir/Makevars.tmp1" "$srcdir/$podir/Makevars.tmp2" + if test -n "$missingvars"; then + please="$please +Please update $podir/Makevars so that it defines all the variables mentioned +in $podir/Makevars.template. +You can then remove $podir/Makevars.template. +" + fi + else + please="$please +Please create $podir/Makevars from the template in $podir/Makevars.template. +You can then remove $podir/Makevars.template. +" + fi + ;; + *) + same=no + if test -f "$srcdir/$podir/$file"; then + if cmp -s $file "$srcdir/$podir/$file"; then + same=yes + fi + fi + if $do_changelog && test $same = no; then + if test -f "$srcdir/$podir/$file"; then + func_poChangeLog_add_entry " * $file: Upgrade to gettext-${version}." + else + func_poChangeLog_add_entry " * $file: New file, from gettext-${version}." + fi + fi + func_backup "$podir/$file" + func_linkorcopy $file "$gettext_dir/po/$file" "$podir/$file" + ;; + esac + done + if test -f "$srcdir/$podir/cat-id-tbl.c"; then + func_remove "$podir/cat-id-tbl.c" + $do_changelog && func_poChangeLog_add_entry " * cat-id-tbl.c: Remove file." + fi + if test -f "$srcdir/$podir/stamp-cat-id"; then + func_remove "$podir/stamp-cat-id" + $do_changelog && func_poChangeLog_add_entry " * stamp-cat-id: Remove file." + fi + if test ! -f "$srcdir/$podir/POTFILES.in"; then + if $doit; then + echo "Creating initial $podir/POTFILES.in" + echo '# List of source files which contain translatable strings.' > "$srcdir/$podir/POTFILES.in" + else + echo "Create initial $podir/POTFILES.in" + fi + $do_changelog && func_poChangeLog_add_entry " * POTFILES.in: New file." + please="$please +Please fill $podir/POTFILES.in as described in the documentation. +" + fi + $do_changelog && func_poChangeLog_finish +done + +# Determine whether we can assume automake 1.9 or newer. +have_automake19= +if (aclocal --version) >/dev/null 2>/dev/null; then + aclocal_version=`aclocal --version | sed -n -e 1p | sed -e 's/^[^0-9]*//'` + case $aclocal_version in + 1.9* | 1.[1-9][0-9]* | [2-9]*) have_automake19=yes ;; + esac +fi + +m4filelist='gettext.m4 iconv.m4 lib-ld.m4 lib-link.m4 lib-prefix.m4 nls.m4 + po.m4 progtest.m4' +# With aclocal versions < 1.9 we need all m4 files, otherwise "aclocal -I m4" +# might give an error. (aclocal < 1.9 didn't know which macros are really +# needed, it looked which macros are potentially needed.) +min_automake_version=1.9 +if test -n "$intldir" || test -z "$have_automake19"; then + # Add intldir.m4, intl.m4 and its dependencies. + m4filelist=$m4filelist' codeset.m4 fcntl-o.m4 glibc2.m4 glibc21.m4 intdiv0.m4 + intl.m4 intldir.m4 intlmacosx.m4 intmax.m4 inttypes_h.m4 inttypes-pri.m4 + lcmessage.m4 lock.m4 longlong.m4 printf-posix.m4 size_max.m4 stdint_h.m4 + threadlib.m4 uintmax_t.m4 visibility.m4 wchar_t.m4 wint_t.m4 xsize.m4' + min_automake_version=1.8 +fi + +# All sorts of bugs could occur if the configure file was remade with the wrong +# version of gettext.m4 et al. (because then the configure and the po/Makefile.in.in +# don't fit together). It is therefore important that the package carries the +# right versions of gettext.m4 et al. with it. +if test -f "$srcdir/Makefile.am"; then + # A package using automake. + + # Determine whether it's using automake 1.8 or newer. + have_automake18= + if (aclocal --version) >/dev/null 2>/dev/null; then + aclocal_version=`aclocal --version | sed -n -e 1p | sed -e 's/^[^0-9]*//'` + case $aclocal_version in + 1.[8-9]* | 1.[1-9][0-9]* | [2-9]*) have_automake18=yes ;; + esac + fi + + # Extract the macro directory name from Makefile.am. + aclocal_amflags=`grep '^ACLOCAL_AMFLAGS[ ]*=' "$srcdir/Makefile.am" | sed -e 's/^ACLOCAL_AMFLAGS[ ]*=\(.*\)$/\1/'` + m4dir=m4 + m4dir_defaulted=yes + m4dir_is_next= + for arg in $aclocal_amflags; do + if test -n "$m4dir_is_next"; then + # Ignore absolute directory pathnames, like /usr/local/share/aclocal. + case "$arg" in + /*) ;; + *) + m4dir="$arg" + m4dir_defaulted= + break + ;; + esac + m4dir_is_next= + else + if test "X$arg" = "X-I"; then + m4dir_is_next=yes + else + m4dir_is_next= + fi + fi + done + + # Decide whether to use $m4dir/ChangeLog, or to use ChangeLog instead. + if test -d "$srcdir/$m4dir" && test -f "$srcdir/ChangeLog" && test ! -f "$srcdir/$m4dir/ChangeLog"; then + # The programmer has no $m4dir/ChangeLog so far. Don't introduce one. + using_m4ChangeLog= + fi + + # Update the *.m4 files and the corresponding Makefile.am. + $do_changelog && func_m4ChangeLog_init + added_m4dir= + added_m4files= + if test -d "$srcdir/$m4dir"; then + : + else + if $doit; then + echo "Creating directory $m4dir" + mkdir "$srcdir/$m4dir" + else + echo "Create directory $m4dir" + fi + added_m4dir=yes + fi + for file in $m4filelist; do + same=no + if test -f "$srcdir/$m4dir/$file"; then + if cmp -s "${datarootdir}/aclocal/$file" "$srcdir/$m4dir/$file"; then + same=yes + fi + else + added_m4files="$added_m4files $file" + fi + if $do_changelog && test $same = no; then + if test -f "$srcdir/$m4dir/$file"; then + func_m4ChangeLog_add_entry " * $file: Upgrade to gettext-${version}." + else + func_m4ChangeLog_add_entry " * $file: New file, from gettext-${version}." + fi + fi + func_backup "$m4dir/$file" + func_linkorcopy "${datarootdir}/aclocal/$file" "${datarootdir}/aclocal/$file" "$m4dir/$file" + done + missing_m4Makefileam= + if test -n "$added_m4files"; then + if test -f "$srcdir/$m4dir/Makefile.am"; then + if $doit; then + echo "Updating EXTRA_DIST in $m4dir/Makefile.am (backup is in $m4dir/Makefile.am~)" + func_backup "$m4dir/Makefile.am" + rm -f "$srcdir/$m4dir/Makefile.am" + if grep '^EXTRA_DIST[ ]*=' "$srcdir/$m4dir/Makefile.am~" > /dev/null; then + sed -e "s%^\(EXTRA_DIST[ ]*=\) \\?%\\1$added_m4files %" < "$srcdir/$m4dir/Makefile.am~" > "$srcdir/$m4dir/Makefile.am" + $do_changelog && func_m4ChangeLog_add_entry " * Makefile.am (EXTRA_DIST): Add the new files." + else + (cat "$srcdir/$m4dir/Makefile.am~"; echo; echo "EXTRA_DIST =$added_m4files") > "$srcdir/$m4dir/Makefile.am" + $do_changelog && func_m4ChangeLog_add_entry " * Makefile.am (EXTRA_DIST): New variable." + fi + else + echo "Update EXTRA_DIST in $m4dir/Makefile.am" + $do_changelog && func_m4ChangeLog_add_entry " * Makefile.am (EXTRA_DIST)." + fi + else + # $m4dir/Makefile.am is not needed any more when aclocal 1.8 or newer + # is used. + if test -z "$have_automake18"; then + if $doit; then + echo "Creating $m4dir/Makefile.am" + echo "EXTRA_DIST =$added_m4files" > "$srcdir/$m4dir/Makefile.am" + else + echo "Create $m4dir/Makefile.am" + fi + $do_changelog && func_m4ChangeLog_add_entry " * Makefile.am: New file." + added_acoutput="$added_acoutput $m4dir/Makefile" + else + missing_m4Makefileam=yes + fi + fi + fi + if test -n "$added_m4dir" && test -z "$missing_m4Makefileam"; then + added_directories="$added_directories $m4dir" + fi + $do_changelog && func_m4ChangeLog_finish + # automake will arrange for $m4dir/ChangeLog to be distributed if a + # $m4dir/Makefile.am exists. If not, we need to add it to Makefile.am's + # EXTRA_DIST explicitly. + if test -n "$created_m4ChangeLog" && test -n "$missing_m4Makefileam"; then + added_extradist="$added_extradist $m4dir/ChangeLog" + fi + + # Update the top-level Makefile.am. + modified_Makefile_am= + # func_modify_Makefile_am changelog_comment + # assumes a modified copy of $srcdir/Makefile.am in $srcdir/Makefile.am.tmp + # and replaces the original Makefile.am file with the modified one if + # the two files differ. Then it removes the modified copy. + func_modify_Makefile_am () + { + if cmp -s "$srcdir/Makefile.am" "$srcdir/Makefile.am.tmp"; then + : + else + if test -z "$modified_Makefile_am"; then + if $doit; then + echo "Updating Makefile.am (backup is in Makefile.am~)" + func_backup Makefile.am + else + echo "Update Makefile.am" + fi + fi + if $doit; then + rm -f "$srcdir/Makefile.am" + cp "$srcdir/Makefile.am.tmp" "$srcdir/Makefile.am" + fi + if $do_changelog; then + if test -z "$modified_Makefile_am"; then + func_ChangeLog_add_entry " * Makefile.am $1" + else + func_ChangeLog_add_entry " $1" + fi + fi + modified_Makefile_am=yes + fi + rm -f "$srcdir/Makefile.am.tmp" + } + + if test -n "$added_directories"; then + if grep '^SUBDIRS[ ]*=' "$srcdir/Makefile.am" > /dev/null; then + sed -e "s%^\(SUBDIRS[ ]*=\) \\?%\\1$added_directories %" < "$srcdir/Makefile.am" > "$srcdir/Makefile.am.tmp" + added_directories_pretty=`echo $added_directories | sed -e 's/ /, /g'` + func_modify_Makefile_am "(SUBDIRS): Add $added_directories_pretty." + else + (cat "$srcdir/Makefile.am"; echo; echo "SUBDIRS =$added_directories") > "$srcdir/Makefile.am.tmp" + func_modify_Makefile_am "(SUBDIRS): New variable." + fi + fi + if test -n "$removed_directory"; then + sed -e '/^SUBDIRS[ ]*=/ { + :a + s%\([ ]\)'"$removed_directory"'[ ]%\1% + s%[ ]'"$removed_directory"'$%% + tb + :b + s%\\$%\\% + tc + bd + :c + n + ba + :d + }' < "$srcdir/Makefile.am" > "$srcdir/Makefile.am.tmp" + func_modify_Makefile_am "(SUBDIRS): Remove $removed_directory." + fi + if test -n "$added_directories"; then + if grep '^DIST_SUBDIRS[ ]*=' "$srcdir/Makefile.am" > /dev/null; then + sed -e "s%^\(DIST_SUBDIRS[ ]*=\) \\?%\\1$added_directories %" < "$srcdir/Makefile.am" > "$srcdir/Makefile.am.tmp" + added_directories_pretty=`echo $added_directories | sed -e 's/ /, /g'` + func_modify_Makefile_am "(DIST_SUBDIRS): Add $added_directories_pretty." + fi + fi + if test -n "$removed_directory"; then + sed -e '/^DIST_SUBDIRS[ ]*=/ { + :a + s%\([ ]\)'"$removed_directory"'[ ]%\1% + s%[ ]'"$removed_directory"'$%% + tb + :b + s%\\$%\\% + tc + bd + :c + n + ba + :d + }' < "$srcdir/Makefile.am" > "$srcdir/Makefile.am.tmp" + func_modify_Makefile_am "(DIST_SUBDIRS): Remove $removed_directory." + fi + if test -n "$m4dir_defaulted"; then + if grep '^ACLOCAL_AMFLAGS[ ]*=' "$srcdir/Makefile.am" > /dev/null; then + sed -e "s%^\(ACLOCAL_AMFLAGS[ ]*=\) \\?%\\1 -I $m4dir %" < "$srcdir/Makefile.am" > "$srcdir/Makefile.am.tmp" + func_modify_Makefile_am "(ACLOCAL_AMFLAGS): Add -I $m4dir." + else + (cat "$srcdir/Makefile.am"; echo; echo "ACLOCAL_AMFLAGS = -I $m4dir") > "$srcdir/Makefile.am.tmp" + func_modify_Makefile_am "(ACLOCAL_AMFLAGS): New variable." + fi + # Also update Makefile.in and, if existent, Makefile. Otherwise they + # would take into account the new flags only after a few rounds of + # "./configure", "make", "touch configure.in", "make distclean". + if $doit; then + for file in Makefile.in Makefile; do + if test -f "$srcdir/$file"; then + func_backup $file + rm -f "$srcdir/$file" + sed -e "s%(ACLOCAL)%(ACLOCAL) -I $m4dir%" < "$srcdir/$file~" > "$srcdir/$file" + fi + done + fi + fi + if test -n "$added_extradist"; then + if grep '^EXTRA_DIST[ ]*=' "$srcdir/Makefile.am" > /dev/null; then + sed -e "s%^\(EXTRA_DIST[ ]*=\)%\\1$added_extradist %" < "$srcdir/Makefile.am" > "$srcdir/Makefile.am.tmp" + added_extradist_pretty=`echo $added_extradist | sed -e 's/ /, /g'` + func_modify_Makefile_am "(EXTRA_DIST): Add $added_extradist_pretty." + else + (cat "$srcdir/Makefile.am"; echo; echo "EXTRA_DIST =$added_extradist") > "$srcdir/Makefile.am.tmp" + func_modify_Makefile_am "(EXTRA_DIST): New variable." + fi + fi + # Extract the aclocal options name from Makefile.am. + aclocal_amflags=`grep '^ACLOCAL_AMFLAGS[ ]*=' "$srcdir/Makefile.am" | sed -e 's/^ACLOCAL_AMFLAGS[ ]*=\(.*\)$/\1/'` + aclocal_options= + m4dir_is_next= + for arg in $aclocal_amflags; do + if test -n "$m4dir_is_next"; then + aclocal_options="$aclocal_options -I $arg" + m4dir_is_next= + else + if test "X$arg" = "X-I"; then + m4dir_is_next=yes + else + m4dir_is_next= + fi + fi + done + please="$please +Please run 'aclocal$aclocal_options' to regenerate the aclocal.m4 file. +You need aclocal from GNU automake $min_automake_version (or newer) to do this. +Then run 'autoconf' to regenerate the configure file. +" + + # Also create $m4dir/Makefile.in from $m4dir/Makefile.am, because automake + # doesn't do it by itself. + if $doit; then + case "$added_acoutput" in + *" $m4dir/Makefile") + (cd "$srcdir" && automake "$m4dir/Makefile") 2>/dev/null || + please="$please +Please run 'automake $m4dir/Makefile' to create $m4dir/Makefile.in +" + ;; + esac + fi +else + please="$please +Please add the files +$m4filelist +from the ${datarootdir}/aclocal directory to your aclocal.m4 file. +" +fi + +modified_configure_in= +# func_modify_configure_in changelog_comment +# assumes a modified copy of $srcdir/$configure_in in $srcdir/$configure_in.tmp +# and replaces the original configure.in/ac file with the modified one if +# the two files differ. Then it removes the modified copy. +func_modify_configure_in () +{ + if cmp -s "$srcdir/$configure_in" "$srcdir/$configure_in.tmp"; then + : + else + if test -z "$modified_configure_in"; then + if $doit; then + echo "Updating $configure_in (backup is in $configure_in~)" + func_backup $configure_in + else + echo "Update $configure_in" + fi + fi + if $doit; then + rm -f "$srcdir/$configure_in" + cp "$srcdir/$configure_in.tmp" "$srcdir/$configure_in" + fi + if $do_changelog; then + if test -z "$modified_configure_in"; then + func_ChangeLog_add_entry " * $configure_in $1" + else + func_ChangeLog_add_entry " $1" + fi + fi + modified_configure_in=yes + fi + rm -f "$srcdir/$configure_in.tmp" +} + +if test -n "$added_acoutput"; then + if grep '^AC_CONFIG_FILES(' "$srcdir/$configure_in" > /dev/null; then + sedprog=' +ta +b +:a +n +ba' + sed -e "s%^\\(AC_CONFIG_FILES([^])\\,]*\\)%\\1$added_acoutput%$sedprog" < "$srcdir/$configure_in" > "$srcdir/$configure_in.tmp" + added_acoutput_pretty=`echo $added_acoutput | sed -e 's/ /, /g'` + func_modify_configure_in "(AC_CONFIG_FILES): Add $added_acoutput_pretty." + else + if grep '^AC_OUTPUT(' "$srcdir/$configure_in" > /dev/null; then + sed -e "s%^\\(AC_OUTPUT([^])\\,]*\\)%\\1$added_acoutput%" < "$srcdir/$configure_in" > "$srcdir/$configure_in.tmp" + added_acoutput_pretty=`echo $added_acoutput | sed -e 's/ /, /g'` + func_modify_configure_in "(AC_OUTPUT): Add $added_acoutput_pretty." + else + please="$please +Please add$added_acoutput to the AC_OUTPUT or AC_CONFIG_FILES invocation in the $configure_in file. +" + fi + fi +fi +if test -n "$removed_acoutput"; then + for file in $removed_acoutput; do + tag= + sedprog='{ + s%\([[ ]\)'"$file"'[ ]%\1% + s%\([[ ]\)'"$file"'\([]),]\)%\1\2% + s%[[ ]'"$file"'$%% + :a + tb + :b + s%\\$%\\% + tc + bd + :c + n + s%\([ ]\)'"$file"'[ ]%\1% + s%\([ ]\)'"$file"'\([]),]\)%\1\2% + s%[ ]'"$file"'$%% + ba + :d + }' + sed -e '/^AC_CONFIG_FILES(/'"$sedprog" < "$srcdir/$configure_in" > "$srcdir/$configure_in.tmp" + if cmp -s "$srcdir/$configure_in" "$srcdir/$configure_in.tmp"; then + sed -e '/^AC_OUTPUT(/'"$sedprog" < "$srcdir/$configure_in" > "$srcdir/$configure_in.tmp" + if cmp -s "$srcdir/$configure_in" "$srcdir/$configure_in.tmp"; then + : + else + tag=AC_OUTPUT + fi + else + tag=AC_CONFIG_FILES + fi + if test -n "$tag"; then + func_modify_configure_in "($tag): Remove $file." + else + rm -f "$srcdir/$configure_in.tmp" + if test "$file" != intl/intlh.inst; then + please="$please +Please remove $file from the AC_OUTPUT or AC_CONFIG_FILES invocation +in the $configure_in file. +" + fi + fi + done +fi +sed -e 's%sed -e "/POTFILES =/r po/POTFILES" po/Makefile\.in > po/Makefile *;* *%%' < "$srcdir/$configure_in" > "$srcdir/$configure_in.tmp" +func_modify_configure_in "(AC_OUTPUT): Remove command that created po/Makefile." +sed -e '/^\(dnl \|\)AC_LINK_FILES(\$nls_cv_header_libgt, \$nls_cv_header_intl)$/d' < "$srcdir/$configure_in" > "$srcdir/$configure_in.tmp" +func_modify_configure_in "(AC_LINK_FILES): Remove invocation." +sed -e 's/^AM_GNU_GETTEXT_VERSION([^()]*)/AM_GNU_GETTEXT_VERSION(['"$version"'])/' < "$srcdir/$configure_in" > "$srcdir/$configure_in.tmp" +func_modify_configure_in "(AM_GNU_GETTEXT_VERSION): Bump to $version." +$do_changelog && func_ChangeLog_finish + +# Recommend replacement for deprecated Makefile variables. +use_libtool=`cat "$srcdir/$configure_in" | grep '^A[CM]_PROG_LIBTOOL'` +for file in `(cd "$srcdir"; find . -name Makefile.am -print; find . -name Makefile.in -print) | sed -e 's,^\./,,'`; do + if test -f "$srcdir/$file"; then + if test `echo "$file" | sed -e 's,^.*/,,'` = Makefile.in && grep automake "$srcdir/$file" >/dev/null 2>&1; then + continue; + fi + # INTLLIBS is deprecated because it doesn't distinguish the two + # cases: with libtool, without libtool. + if grep '@''INTLLIBS''@' "$srcdir/$file" >/dev/null 2>&1; then + if test -n "$use_libtool"; then + please="$please +Please change $file to use @""LTLIBINTL""@ or @""LIBINTL""@ instead of +@""INTLLIBS""@. Which one, depends whether it is used with libtool or not. +@""INTLLIBS""@ will go away. +" + else + please="$please +Please change $file to use @""LIBINTL""@ instead of @""INTLLIBS""@. +@""INTLLIBS""@ will go away. +" + fi + fi + # DATADIRNAME is deprecated because we install only .gmo files nowadays, + # which can be stored in the platform independent $prefix/share hierarchy. + if grep '@''DATADIRNAME''@' "$srcdir/$file" >/dev/null 2>&1; then + please="$please +Please change $file to use the constant string \"share\" instead of +@""DATADIRNAME""@. @""DATADIRNAME""@ will go away. +" + fi + # INSTOBJEXT is deprecated because we install only .gmo files nowadays, + # no catgets .cat catalogs. + if grep '@''INSTOBJEXT''@' "$srcdir/$file" >/dev/null 2>&1; then + please="$please +Please change $file to use the constant string \".mo\" instead of +@""INSTOBJEXT""@. @""INSTOBJEXT""@ will go away. +" + fi + # GENCAT is deprecated because we install no catgets catalogs anymore. + if grep '@''GENCAT''@' "$srcdir/$file" >/dev/null 2>&1; then + please="$please +Please change $file to use the constant string \"gencat\" instead of +@""GENCAT""@. @""GENCAT""@ will go away. Maybe you don't even need it any more? +" + fi + # POSUB is deprecated because it causes "./configure --disable-nls", "make", + # "make dist" to create a buggy tarfile. + if grep '@''POSUB''@' "$srcdir/$file" >/dev/null 2>&1; then + please="$please +Please change $file to use the constant string \"po\" instead of +@""POSUB""@. @""POSUB""@ will go away. +" + fi + fi +done + +# Recommend replacement for deprecated configure variables. +if grep '\$nls_cv_header_' "$srcdir/$configure_in" >/dev/null 2>&1; then + please="$please +Please stop using \$nls_cv_header_intl or \$nls_cv_header_libgt in the +$configure_in file. Both will go away. Use or \"gettext.h\" instead. +" +fi + +# Recommend fetching config.guess and config.sub. +if test -f "$srcdir/$auxdir"config.guess && test -f "$srcdir/$auxdir"config.sub; then + : +else + please="$please +You will also need config.guess and config.sub, which you can get from the CVS +of the 'config' project at http://savannah.gnu.org/. The commands to fetch them +are +\$ wget 'http://savannah.gnu.org/cgi-bin/viewcvs/*checkout*/config/config/config.guess' +\$ wget 'http://savannah.gnu.org/cgi-bin/viewcvs/*checkout*/config/config/config.sub' +" +fi + +if $doit; then + echo "$please" + echo "You might also want to copy the convenience header file gettext.h" + echo "from the $gettext_dir directory into your package." + echo "It is a wrapper around that implements the configure --disable-nls" + echo "option." + echo + count=`echo "$please" | grep '^$' | wc -l` + count=`echo "$count" | sed -e 's/[ ]//g'` + case "$count" in + 1) count="paragraph";; + 2) count="two paragraphs";; + 3) count="three paragraphs";; + 4) count="four paragraphs";; + 5) count="five paragraphs";; + *) count="$count paragraphs";; + esac + echo "Press Return to acknowledge the previous $count." + # Read from /dev/tty, not stdin, so that gettextize cannot be abused by + # non-interactive tools. + read dummy < /dev/tty +fi + +exit 0 diff --git a/libs/gettext/bin32/libasprintf-0.dll b/libs/gettext/bin32/libasprintf-0.dll new file mode 100644 index 000000000..dcd8f8593 Binary files /dev/null and b/libs/gettext/bin32/libasprintf-0.dll differ diff --git a/libs/gettext/bin32/libgcc_s_sjlj-1.dll b/libs/gettext/bin32/libgcc_s_sjlj-1.dll new file mode 100644 index 000000000..b7c5910fd Binary files /dev/null and b/libs/gettext/bin32/libgcc_s_sjlj-1.dll differ diff --git a/libs/gettext/bin32/libgettextlib-0-18-1.dll b/libs/gettext/bin32/libgettextlib-0-18-1.dll new file mode 100644 index 000000000..b1bfb9462 Binary files /dev/null and b/libs/gettext/bin32/libgettextlib-0-18-1.dll differ diff --git a/libs/gettext/bin32/libgettextpo-0.dll b/libs/gettext/bin32/libgettextpo-0.dll new file mode 100644 index 000000000..cea1c97be Binary files /dev/null and b/libs/gettext/bin32/libgettextpo-0.dll differ diff --git a/libs/gettext/bin32/libgettextsrc-0-18-1.dll b/libs/gettext/bin32/libgettextsrc-0-18-1.dll new file mode 100644 index 000000000..95f904658 Binary files /dev/null and b/libs/gettext/bin32/libgettextsrc-0-18-1.dll differ diff --git a/libs/gettext/bin32/libintl-8.dll b/libs/gettext/bin32/libintl-8.dll new file mode 100644 index 000000000..9f10b6c55 Binary files /dev/null and b/libs/gettext/bin32/libintl-8.dll differ diff --git a/libs/gettext/bin32/msgattrib.exe b/libs/gettext/bin32/msgattrib.exe new file mode 100644 index 000000000..4f64eda79 Binary files /dev/null and b/libs/gettext/bin32/msgattrib.exe differ diff --git a/libs/gettext/bin32/msgcat.exe b/libs/gettext/bin32/msgcat.exe new file mode 100644 index 000000000..b41e9141f Binary files /dev/null and b/libs/gettext/bin32/msgcat.exe differ diff --git a/libs/gettext/bin32/msgcmp.exe b/libs/gettext/bin32/msgcmp.exe new file mode 100644 index 000000000..7743c9ed6 Binary files /dev/null and b/libs/gettext/bin32/msgcmp.exe differ diff --git a/libs/gettext/bin32/msgcomm.exe b/libs/gettext/bin32/msgcomm.exe new file mode 100644 index 000000000..de4c6699f Binary files /dev/null and b/libs/gettext/bin32/msgcomm.exe differ diff --git a/libs/gettext/bin32/msgconv.exe b/libs/gettext/bin32/msgconv.exe new file mode 100644 index 000000000..7be1c362f Binary files /dev/null and b/libs/gettext/bin32/msgconv.exe differ diff --git a/libs/gettext/bin32/msgen.exe b/libs/gettext/bin32/msgen.exe new file mode 100644 index 000000000..ee42349bf Binary files /dev/null and b/libs/gettext/bin32/msgen.exe differ diff --git a/libs/gettext/bin32/msgexec.exe b/libs/gettext/bin32/msgexec.exe new file mode 100644 index 000000000..99e56dc02 Binary files /dev/null and b/libs/gettext/bin32/msgexec.exe differ diff --git a/libs/gettext/bin32/msgfilter.exe b/libs/gettext/bin32/msgfilter.exe new file mode 100644 index 000000000..b99f25d57 Binary files /dev/null and b/libs/gettext/bin32/msgfilter.exe differ diff --git a/libs/gettext/bin32/msgfmt.exe b/libs/gettext/bin32/msgfmt.exe new file mode 100644 index 000000000..1badcca98 Binary files /dev/null and b/libs/gettext/bin32/msgfmt.exe differ diff --git a/libs/gettext/bin32/msggrep.exe b/libs/gettext/bin32/msggrep.exe new file mode 100644 index 000000000..2f27989b4 Binary files /dev/null and b/libs/gettext/bin32/msggrep.exe differ diff --git a/libs/gettext/bin32/msginit.exe b/libs/gettext/bin32/msginit.exe new file mode 100644 index 000000000..2f8fbef5e Binary files /dev/null and b/libs/gettext/bin32/msginit.exe differ diff --git a/libs/gettext/bin32/msgmerge.exe b/libs/gettext/bin32/msgmerge.exe new file mode 100644 index 000000000..09dcad0c5 Binary files /dev/null and b/libs/gettext/bin32/msgmerge.exe differ diff --git a/libs/gettext/bin32/msgunfmt.exe b/libs/gettext/bin32/msgunfmt.exe new file mode 100644 index 000000000..eada3edfd Binary files /dev/null and b/libs/gettext/bin32/msgunfmt.exe differ diff --git a/libs/gettext/bin32/msguniq.exe b/libs/gettext/bin32/msguniq.exe new file mode 100644 index 000000000..6cb12abfb Binary files /dev/null and b/libs/gettext/bin32/msguniq.exe differ diff --git a/libs/gettext/bin32/ngettext.exe b/libs/gettext/bin32/ngettext.exe new file mode 100644 index 000000000..c1faea08e Binary files /dev/null and b/libs/gettext/bin32/ngettext.exe differ diff --git a/libs/gettext/bin32/recode-sr-latin.exe b/libs/gettext/bin32/recode-sr-latin.exe new file mode 100644 index 000000000..366202d0b Binary files /dev/null and b/libs/gettext/bin32/recode-sr-latin.exe differ diff --git a/libs/gettext/bin32/xgettext.exe b/libs/gettext/bin32/xgettext.exe new file mode 100644 index 000000000..4c3e02b7d Binary files /dev/null and b/libs/gettext/bin32/xgettext.exe differ diff --git a/libs/gettext/bin64/autopoint b/libs/gettext/bin64/autopoint new file mode 100755 index 000000000..73d909638 --- /dev/null +++ b/libs/gettext/bin64/autopoint @@ -0,0 +1,717 @@ +#! /bin/sh +# +# Copyright (C) 2002-2010 Free Software Foundation, Inc. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +# This file is meant for authors, maintainers, co-maintainers or installers +# of packages which are internationalized with the help of GNU gettext. For +# further information how to use it consult the GNU gettext manual. + +progname=$0 +package=gettext-tools +version=0.18.1 + +# Set variables +# - gettext_dir directory where the sources are stored. +prefix="/usr/local/x86_64-w64-mingw32/stow/gettext-0.18.1.1" +datarootdir="${prefix}/share" +gettext_dir="${datarootdir}/gettext" + +# func_tmpdir +# creates a temporary directory. +# Sets variable +# - tmp pathname of freshly created temporary directory +func_tmpdir () +{ + # Use the environment variable TMPDIR, falling back to /tmp. This allows + # users to specify a different temporary directory, for example, if their + # /tmp is filled up or too small. + : ${TMPDIR=/tmp} + { + # Use the mktemp program if available. If not available, hide the error + # message. + tmp=`(umask 077 && mktemp -d "$TMPDIR/gtXXXXXX") 2>/dev/null` && + test -n "$tmp" && test -d "$tmp" + } || + { + # Use a simple mkdir command. It is guaranteed to fail if the directory + # already exists. $RANDOM is bash specific and expands to empty in shells + # other than bash, ksh and zsh. Its use does not increase security; + # rather, it minimizes the probability of failure in a very cluttered /tmp + # directory. + tmp=$TMPDIR/gt$$-$RANDOM + (umask 077 && mkdir "$tmp") + } || + { + echo "$0: cannot create a temporary directory in $TMPDIR" >&2 + { (exit 1); exit 1; } + } +} + +# Support for relocatability. +func_find_curr_installdir () +{ + # Determine curr_installdir, even taking into account symlinks. + curr_executable="$0" + case "$curr_executable" in + */* | *\\*) ;; + *) # Need to look in the PATH. + if test "${PATH_SEPARATOR+set}" != set; then + func_tmpdir + { echo "#! /bin/sh"; echo "exit 0"; } > "$tmp"/conf.sh + chmod +x "$tmp"/conf.sh + if (PATH="/nonexistent;$tmp"; conf.sh) >/dev/null 2>&1; then + PATH_SEPARATOR=';' + else + PATH_SEPARATOR=: + fi + rm -rf "$tmp" + fi + save_IFS="$IFS"; IFS="$PATH_SEPARATOR" + for dir in $PATH; do + IFS="$save_IFS" + test -z "$dir" && dir=. + for exec_ext in ''; do + if test -f "$dir/$curr_executable$exec_ext"; then + curr_executable="$dir/$curr_executable$exec_ext" + break 2 + fi + done + done + IFS="$save_IFS" + ;; + esac + # Make absolute. + case "$curr_executable" in + /* | ?:/* | ?:\\*) ;; + *) curr_executable=`pwd`/"$curr_executable" ;; + esac + # Resolve symlinks. + sed_dirname='s,/[^/]*$,,' + sed_linkdest='s,^.* -> \(.*\),\1,p' + while : ; do + lsline=`LC_ALL=C ls -l "$curr_executable"` + case "$lsline" in + *" -> "*) + linkdest=`echo "$lsline" | sed -n -e "$sed_linkdest"` + case "$linkdest" in + /* | ?:/* | ?:\\*) curr_executable="$linkdest" ;; + *) curr_executable=`echo "$curr_executable" | sed -e "$sed_dirname"`/"$linkdest" ;; + esac ;; + *) break ;; + esac + done + curr_installdir=`echo "$curr_executable" | sed -e 's,/[^/]*$,,'` + # Canonicalize. + curr_installdir=`cd "$curr_installdir" && pwd` +} +func_find_prefixes () +{ + # Compute the original/current installation prefixes by stripping the + # trailing directories off the original/current installation directories. + orig_installprefix="$orig_installdir" + curr_installprefix="$curr_installdir" + while true; do + orig_last=`echo "$orig_installprefix" | sed -n -e 's,^.*/\([^/]*\)$,\1,p'` + curr_last=`echo "$curr_installprefix" | sed -n -e 's,^.*/\([^/]*\)$,\1,p'` + if test -z "$orig_last" || test -z "$curr_last"; then + break + fi + if test "$orig_last" != "$curr_last"; then + break + fi + orig_installprefix=`echo "$orig_installprefix" | sed -e 's,/[^/]*$,,'` + curr_installprefix=`echo "$curr_installprefix" | sed -e 's,/[^/]*$,,'` + done +} +if test "no" = yes; then + exec_prefix="${prefix}" + bindir="${exec_prefix}/bin" + orig_installdir="$bindir" # see Makefile.am's *_SCRIPTS variables + func_find_curr_installdir # determine curr_installdir + func_find_prefixes + # Relocate the directory variables that we use. + gettext_dir=`echo "$gettext_dir/" | sed -e "s%^${orig_installprefix}/%${curr_installprefix}/%" | sed -e 's,/$,,'` +fi + +# func_usage +# outputs to stdout the --help usage message. +func_usage () +{ + echo "\ +Usage: autopoint [OPTION]... + +Copies standard gettext infrastructure files into a source package. + +Options: + --help print this help and exit + --version print version information and exit + -f, --force force overwriting of files that already exist + -n, --dry-run print modifications but don't perform them" +# echo "\ +# -V version copy the infrastructure of the specified gettext version +# (dangerous)" + echo " +Report bugs to ." +} + +# func_version +# outputs to stdout the --version message. +func_version () +{ + echo "$progname (GNU $package) $version" + echo "Uses a versions archive in git format." + echo "Copyright (C) 2002-2010 Free Software Foundation, Inc. +License GPLv3+: GNU GPL version 3 or later +This is free software: you are free to change and redistribute it. +There is NO WARRANTY, to the extent permitted by law." + echo "Written by" "Bruno Haible" +} + +# func_fatal_error message +# outputs to stderr a fatal error message, and terminates the program. +func_fatal_error () +{ + echo "autopoint: *** $1" 1>&2 + echo "autopoint: *** Stop." 1>&2 + exit 1 +} + +# Command-line option processing. +# Removes the OPTIONS from the arguments. Sets the variables: +# - force yes if --force was given, empty otherwise +# - ver gettext version if -V was given, empty otherwise +# - doit false if --dry-run was given, : otherwise +{ + force= + ver= + doit=: + + while test $# -gt 0; do + case "$1" in + -n | --dry-run | --dry-ru | --dry-r | --dry- | --dry | --dr | --d ) + shift + doit=false ;; + -f | --force | --forc | --for | --fo | --f ) + shift + force=yes ;; + --help | --hel | --he | --h ) + func_usage; exit 0 ;; +# -V ) # Some people put a space between -V and the version number. +# shift +# if test $# = 0; then +# func_usage 1>&2 +# exit 1 +# fi +# ver=$1; +# shift ;; +# -V*) # Some people omit the space between -V and the version number. +# ver=`echo "X$1" | sed -e 's/^X-V//'` +# shift ;; + --version | --versio | --versi | --vers | --ver | --ve | --v ) + func_version + exit 0 ;; + -- ) # Stop option prcessing + shift; break ;; + -* ) + echo "autopoint: unknown option $1" 1>&2 + echo "Try 'autopoint --help' for more information." 1>&2 + exit 1 ;; + * ) + break ;; + esac + done +} + +# Command-line argument processing. +# Analyzes the remaining arguments. +{ + if test $# -gt 0; then + func_usage 1>&2 + exit 1 + fi +} + +srcdir=`pwd` +# The current directory is now $srcdir. + +# Check integrity of package: A configure.in/ac must be present. Sets variable +# - configure_in name of configure.in/ac file. +if test -f configure.in; then + configure_in=configure.in +else + if test -f configure.ac; then + configure_in=configure.ac + else + # KDE specific convention: configure.in.in + if test -f configure.in.in; then + configure_in=configure.in.in + else + func_fatal_error "Missing configure.in or configure.ac, please cd to your package first." + fi + fi +fi + +# Check whether the -V option and the version number in configure.in match. +# At least one of the two must be given. If both are given, they must agree. +sed_extract_AM_GNU_GETTEXT_VERSION_argument='s/^AM_GNU_GETTEXT_VERSION(\([^()]*\)).*$/\1/' +sed_remove_outer_brackets='s/^\[\(.*\)\]$/\1/' +xver=`cat "$configure_in" | grep '^AM_GNU_GETTEXT_VERSION(' | sed -n -e "$sed_extract_AM_GNU_GETTEXT_VERSION_argument"p | sed -e "$sed_remove_outer_brackets" | sed -e 1q` +if test -z "$xver" && test -f intl/VERSION; then + xver=`cat intl/VERSION | LC_ALL=C sed -n -e 's/^.*gettext-\([-+_.0-9A-Za-z]*\).*$/\1/p'` +fi +if test -n "$xver"; then + if test -n "$ver"; then + if test "X$ver" != "X$xver"; then + func_fatal_error "Version mismatch: specified -V $ver but the package uses gettext version $xver" + fi + else + ver="$xver" + fi +else + if test -z "$ver"; then + func_fatal_error "Missing version: please specify in $configure_in through a line 'AM_GNU_GETTEXT_VERSION(x.yy.zz)' the gettext version the package is using" + fi +fi + +# Check whether the version number is supported. +case "$ver" in + 0.10.35 | 0.10.36 | 0.10.37 | 0.10.38 | 0.10.39 | 0.10.40 | \ + 0.11 | 0.11.1 | 0.11.2 | 0.11.3 | 0.11.4 | 0.11.5 | \ + 0.12 | 0.12.1 | \ + 0.13 | 0.13.1 | \ + 0.14 | 0.14.1 | 0.14.2 | 0.14.3 | 0.14.4 | 0.14.5 | 0.14.6 | \ + 0.15 | \ + 0.16 | 0.16.1 | \ + 0.17 | \ + 0.18 | 0.18.1 ) + ;; + *) + func_fatal_error "The AM_GNU_GETTEXT_VERSION declaration in your $configure_in + file requires the infrastructure from gettext-$ver but this version + is older. Please upgrade to gettext-$ver or newer." + ;; +esac + +# Check in which directory config.rpath, mkinstalldirs etc. belong. +auxdir=`cat "$configure_in" | grep '^AC_CONFIG_AUX_DIR' | sed -n -e 's/AC_CONFIG_AUX_DIR(\([^()]*\))/\1/p' | sed -e 's/^\[\(.*\)\]$/\1/' | sed -e 1q` +if test -n "$auxdir"; then + auxdir="$auxdir/" +fi + +# Check in which directory the *.m4 macros belong. +m4dir=m4 +if test -f Makefile.am; then + # A package using automake. + # Extract the macro directory name from Makefile.am. + aclocal_amflags=`grep '^ACLOCAL_AMFLAGS[ ]*=' Makefile.am | sed -e 's/^ACLOCAL_AMFLAGS[ ]*=\(.*\)$/\1/'` + m4dir_is_next= + for arg in $aclocal_amflags; do + if test -n "$m4dir_is_next"; then + m4dir="$arg" + break + else + if test "X$arg" = "X-I"; then + m4dir_is_next=yes + else + m4dir_is_next= + fi + fi + done +fi + +# Check whether to omit the intl/ directory. +omitintl=`cat "$configure_in" | grep '^AM_GNU_GETTEXT' | sed -n -e 's/^AM_GNU_GETTEXT(\([^(),]*\).*$/\1/p' | sed -e 's/^\[\(.*\)\]$/\1/' | sed -e 1q` +omitintl=`if test 'external' = "$omitintl"; then echo yes; fi` + +# Check in which directory or directories the po/* infrastructure belongs. +sed_extract_config_files='s,#.*$,, +s,^dnl .*$,, +s, dnl .*$,, +/AC_CONFIG_FILES(/ { + ta + :a + s/)/)/ + tb + s/\\$// + N + ba + :b + s,^.*AC_CONFIG_FILES([[ ]*\([^]"$`\\)]*\).*$,\1,p +}' +configfiles=`cat "$configure_in" | sed -n -e "$sed_extract_config_files"` +# PO directories have a Makefile.in generated from Makefile.in.in. +# Treat a directory as a PO directory if and only if it has a +# POTFILES.in file. This allows packages to have multiple PO +# directories under different names or in different locations. +sed_remove_Makefile_in='s,/Makefile\.in$,,' +podirs=`for f in $configfiles; do case "$f" in */Makefile.in) echo $f;; esac; done | sed -e "$sed_remove_Makefile_in"` +if test -z "$podirs"; then + # If we cannot get the list of PO directories from configure.ac, assume the + # common default. + podirs="po" +fi + +# Set up a temporary checkout directory. +# Set variables +# - work_dir directory containing the temporary checkout +work_dir=tmpwrk$$ +mkdir "$work_dir" || { + if test -d "$work_dir"; then + func_fatal_error "directory $work_dir already exists" + else + func_fatal_error "cannot create directory $work_dir" + fi +} + +# We support three archive formats. +# +# Format | Size (KiB) for gettext-0.17 | Extra tools needed | +# -------+-----------------------------+--------------------+ +# dir | 3000 | -- | +# cvs | 356 | cvs | +# git | 484 | git | +# -------+-----------------------------+--------------------+ + +case "git" in + dir) + # The archive of different versions is very large, but using it does not + # require special tools. + gzip -d -c < "$gettext_dir/archive.dir.tar.gz" | (cd "$work_dir" && tar xf - "gettext-$ver") + if test `find "$work_dir" -type f -print | wc -l` = 0; then + rm -rf "$work_dir" + func_fatal_error "infrastructure files for version $ver not found; this is autopoint from GNU $package $version" + fi + mv "$work_dir/gettext-$ver" "$work_dir/archive" + ;; + + cvs) + # We distributed the many different versions of the files in a CVS + # repository. This guaranteed a good compression rate: + # + # Including version size in KB of + # "du autopoint-files/archive" + # 0.10.35 240 + # 0.10.36 428 + # 0.10.37 436 + # 0.10.38 488 + # 0.10.39 500 + # 0.10.40 528 + # 0.11 720 + # 0.11.1 740 + # 0.11.2 748 + # 0.11.3 804 + # 0.11.4 864 + # 0.11.5 880 + # 0.12 1032 + # 0.12.1 1032 + # 0.13 1220 + # 0.13.1 1236 + # 0.14 1296 + # 0.14.1 1300 + # 0.14.2 1420 + # 0.14.3 1428 + # 0.14.4 1464 + # 0.14.5 1508 + # 0.14.6 1580 + # 0.15 1760 + # 0.16 1808 + # 0.16.1 1812 + # 0.17 2128 + # 0.18 2656 + # + # The requirement that the user must have the CVS program available is not + # a severe restrictions, because most of the people who use autopoint are + # users of CVS. + # + # But the CVS format is now deprecated, because "cvs init" does not work in + # all circumstances + # (see ) + # and we are not allowed to distribute the cvs infrastructure files + # ourselves + # (see ). + # + # Check availability of the CVS program. + (cvs -v) >/dev/null 2>/dev/null || func_fatal_error "cvs program not found" + + # Set up a temporary CVS repository. + # We need the temporary CVS repository because any checkout needs write + # access to the CVSROOT/history file, so it cannot be under $gettext_dir. + # We need the temporary checkout directory because when --force was not + # given, we need to compare the existing files with the checked out ones. + # Set variables + # - cvs_dir directory containing the temporary repository + cvs_dir=tmpcvs$$ + # Use an umask of 077, to avoid attacks that work by overwriting files in + # the "$CVSROOT"/CVSROOT directory. + (umask 077 && mkdir "$cvs_dir") || { + if test -d "$cvs_dir"; then + func_fatal_error "directory $cvs_dir already exists" + else + func_fatal_error "cannot create directory $cvs_dir" + fi + } + CVSROOT="$srcdir/$cvs_dir" + unset CVS_CLIENT_LOG + unset CVS_CLIENT_PORT + unset CVS_IGNORE_REMOTE_ROOT + unset CVS_LOCAL_BRANCH_NUM + unset CVS_NOBASES + unset CVS_PASSFILE + unset CVS_PASSWORD + unset CVS_PROXY_PORT + unset CVS_RCMD_PORT + unset CVS_RSH + unset CVS_SERVER + unset CVS_SERVER_SLEEP + CVS_SIGN_COMMITS= + export CVS_SIGN_COMMITS + unset CVS_SSH + unset CVS_VERIFY_CHECKOUTS + unset CVS_VERIFY_TEMPLATE + unset CVSIGNORE + unset CVSREAD + unset CVSREADONLYFS + unset CVSUMASK + unset CVSWRAPPERS + + # Need to pass -d "$CVSROOT", because there may be a CVS directory in the + # current directory. + cvs -d "$CVSROOT" init + gzip -d -c < "$gettext_dir/archive.cvs.tar.gz" | (cd "$cvs_dir" && tar xf -) + + cd "$work_dir" + cvsver=gettext-`echo "$ver" | sed -e 's/\./_/g'` + (cvs -d "$CVSROOT" checkout -r"$cvsver" archive > /dev/null) 2>&1 | grep -v '^cvs checkout: Updating' + find archive -name CVS -type d -print | xargs rm -rf + cd .. + rm -rf "$cvs_dir" + # Check that really all CVS directories are gone, otherwise we would overwrite + # the contents of the user's CVS directories. + if test `find $work_dir/archive -name CVS -type d -print | wc -l` != 0; then + rm -rf "$work_dir" + func_fatal_error "failed to remove all CVS subdirectories" + fi + if test `find $work_dir/archive -type f -print | wc -l` = 0; then + rm -rf "$work_dir" + func_fatal_error "infrastructure files for version $ver not found; this is autopoint from GNU $package $version" + fi + ;; + + git) + # Check availability of the git program. + (git --version) >/dev/null 2>/dev/null || func_fatal_error "git program not found" + mkdir "$work_dir/archive" + gzip -d -c < "$gettext_dir/archive.git.tar.gz" | (cd "$work_dir/archive" && tar xf -) + (cd "$work_dir/archive" && git checkout -q "gettext-$ver") || { + rm -rf "$work_dir" + func_fatal_error "infrastructure files for version $ver not found; this is autopoint from GNU $package $version" + } + (cd "$work_dir/archive" && rm -rf .git .gitignore) + ;; +esac + +# func_destfile file +# determines the destination file, relative to the package's top level +# directory, for a given file name, relative to archive. +# Sets variables +# - destfile relative destination file name, or +# empty if the file shall be omitted +# - sharedowner yes if the file is not only owned by GNU gettext but may +# be installed by automake or other tools, otherwise empty +# - allpodirs yes if the file is to be installed in every dir in $podirs +func_destfile () +{ + # There are five categories of files: + # ABOUT_NLS -> top level directory + # config.rpath mkinstalldirs -> $auxdir + # m4/* -> $m4dir/ + # intl/* -> intl/ + # po/* -> + sharedowner= + allpodirs= + case `echo "$1" | sed -e 's,[^/]*$,,'` in + "" ) + case "$1" in + config.rpath ) destfile="$auxdir$1" ;; + mkinstalldirs ) destfile="$auxdir$1" sharedowner=yes ;; + * ) destfile="$1" ;; + esac + ;; + m4/ ) destfile=`echo "$1" | sed -e "s,^m4/,$m4dir/,"` ;; + intl/ ) if test -n "$omitintl"; then destfile=""; else destfile="$1"; fi ;; + po/ ) destfile=`echo "$1" | sed -e "s,^po/,,"` allpodirs=yes ;; + * ) destfile="$1" ;; + esac +} + +# func_compare existingfile gettextfile +# compares the existing file and the file from gettext, and decides whether the +# existing file should be overwritten with the file from gettext. Returns 0 if +# it should be overwritten, or 1 if it should be skipped. +sed_extract_serial='s/^#.* serial \([^ ]*\).*/\1/p +1q' +func_compare () +{ + if cmp -s "$1" "$2"; then + false + else + case "$2" in + *.m4) + # For interoperability with gnulib. gnulib often has newer versions of + # the *.m4 files than the latest gettext release. Don't overwrite a + # newer version from gnulib with an older version from the gettext + # release. The version can be retrieved from the first line, which + # looks like this: # file.m4 serial NN ... + existing_serial=`sed -n -e "$sed_extract_serial" < "$1"` + gettext_serial=`sed -n -e "$sed_extract_serial" < "$2"` + if test -n "$existing_serial" && test -n "$gettext_serial" \ + && test "$existing_serial" -ge "$gettext_serial" 2> /dev/null; then + false + else + true + fi + ;; + *) + true + ;; + esac + fi +} + +# If some files have been locally modified and we have not been requested +# to overwrite them, then bail out. This is better than leaving a source +# package around where half of the files are locally modified and half are +# original - too great risk of version mismatch. +if test -z "$force"; then + mismatch= + func_tmpdir + mismatchfile="$tmp"/autopoint.diff + for file in `find "$work_dir/archive" -type f -print | sed -e "s,^$work_dir/archive/,," | LC_ALL=C sort`; do + func_destfile "$file" + if test -n "$destfile"; then + func_compare_to_destfile () + { + finaldestfile="$1" + if test -f "$finaldestfile"; then + if func_compare "$finaldestfile" "$work_dir/archive/$file"; then + if test -n "$sharedowner"; then + echo "autopoint: warning: File $finaldestfile has been locally modified." 1>&2 + else + echo "autopoint: File $finaldestfile has been locally modified." 1>&2 + mismatch=yes + diff -c "$work_dir/archive/$file" "$finaldestfile" | sed -e "1s,$work_dir/archive/,," >> "$mismatchfile" + fi + fi + fi + } + if test -n "$allpodirs"; then + for dir in $podirs; do + func_compare_to_destfile "$dir/$destfile" + done + else + func_compare_to_destfile "$destfile" + fi + fi + done + if test -n "$mismatch"; then + rm -rf "$work_dir" + func_fatal_error "Some files have been locally modified. Not overwriting them because --force has not been specified. For your convenience, you find the local modifications in the file '$mismatchfile'." + fi + rm -rf "$tmp" +fi + +# func_mkdir_for to +# ensures the directory that would the given file exists. +# 'to' is a relative pathname, relative to the current directory. +func_mkdir_for () +{ + base=`echo "$1" | sed -e 's,/[^/]*$,,'` + if test "X$base" != "X$1" && test -n "$base"; then + func_mkdir_for "$base" + # Recompute base. It was clobbered by the recursive call. + base=`echo "$1" | sed -e 's,/[^/]*$,,'` + test -d "$base" || { echo "Creating directory $base"; mkdir "$base"; } + fi +} + +# func_copy from to +# copies a file. +# 'from' is a relative pathname, relative to the current directory. +# 'to' is a relative pathname, relative to the current directory. +func_copy () +{ + if $doit; then + func_mkdir_for "$2" + rm -f "$2" + echo "Copying file $2" + cp "$1" "$2" + else + echo "Copy file $2" + fi +} + +# func_backup to +# makes a backup of a file that is about to be overwritten or replaced. +# 'to' is a relative pathname, relative to the current directory. +func_backup () +{ + if $doit; then + if test -f "$1"; then + rm -f "$1~" + cp -p "$1" "$1~" + fi + fi +} + +# Now copy the files. +for file in `find "$work_dir/archive" -type f -print | sed -e "s,^$work_dir/archive/,," | LC_ALL=C sort`; do + func_destfile "$file" + if test -n "$destfile"; then + func_copy_to_destfile () + { + finaldestfile="$1" + mustcopy= + if test -f "$finaldestfile"; then + if func_compare "$finaldestfile" "$work_dir/archive/$file"; then + if test -n "$force"; then + # Overwrite locally modified file. + mustcopy=yes + fi + # If --force is not specified, don't overwrite locally modified files + # for which GNU gettext is a shared owner. + fi + else + mustcopy=yes + fi + if test -n "$mustcopy"; then + func_backup "$finaldestfile" + func_copy "$work_dir/archive/$file" "$finaldestfile" + fi + } + if test -n "$allpodirs"; then + for dir in $podirs; do + func_copy_to_destfile "$dir/$destfile" + done + else + func_copy_to_destfile "$destfile" + fi + fi +done + +# That's it. +rm -rf "$work_dir" +exit 0 diff --git a/libs/gettext/bin64/envsubst.exe b/libs/gettext/bin64/envsubst.exe new file mode 100644 index 000000000..8e09a3397 Binary files /dev/null and b/libs/gettext/bin64/envsubst.exe differ diff --git a/libs/gettext/bin64/gettext.exe b/libs/gettext/bin64/gettext.exe new file mode 100644 index 000000000..c9f48a0eb Binary files /dev/null and b/libs/gettext/bin64/gettext.exe differ diff --git a/libs/gettext/bin64/gettext.sh b/libs/gettext/bin64/gettext.sh new file mode 100755 index 000000000..2369ab501 --- /dev/null +++ b/libs/gettext/bin64/gettext.sh @@ -0,0 +1,123 @@ +#! /bin/sh +# +# Copyright (C) 2003, 2005-2007 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU Library General Public License as published +# by the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU Library General Public +# License along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +# USA. +# + +# Find a way to echo strings without interpreting backslash. +if test "X`(echo '\t') 2>/dev/null`" = 'X\t'; then + echo='echo' +else + if test "X`(printf '%s\n' '\t') 2>/dev/null`" = 'X\t'; then + echo='printf %s\n' + else + echo_func () { + cat < +This is free software: you are free to change and redistribute it. +There is NO WARRANTY, to the extent permitted by law." + echo "Written by" "Bruno Haible" + } + if test $# = 1; then + case "$1" in + --help | --hel | --he | --h ) + func_usage; exit 0 ;; + --version | --versio | --versi | --vers | --ver | --ve | --v ) + func_version; exit 0 ;; + esac + fi + func_usage 1>&2 + exit 1 + ;; + esac +fi + +# eval_gettext MSGID +# looks up the translation of MSGID and substitutes shell variables in the +# result. +eval_gettext () { + gettext "$1" | (export PATH `envsubst --variables "$1"`; envsubst "$1") +} + +# eval_ngettext MSGID MSGID-PLURAL COUNT +# looks up the translation of MSGID / MSGID-PLURAL for COUNT and substitutes +# shell variables in the result. +eval_ngettext () { + ngettext "$1" "$2" "$3" | (export PATH `envsubst --variables "$1 $2"`; envsubst "$1 $2") +} + +# Note: This use of envsubst is much safer than using the shell built-in 'eval' +# would be. +# 1) The security problem with Chinese translations that happen to use a +# character such as \xe0\x60 is avoided. +# 2) The security problem with malevolent translators who put in command lists +# like "$(...)" or "`...`" is avoided. +# 3) The translations can only refer to shell variables that are already +# mentioned in MSGID or MSGID-PLURAL. +# +# Note: "export PATH" above is a dummy; this is for the case when +# `envsubst --variables ...` returns nothing. +# +# Note: In eval_ngettext above, "$1 $2" means a string whose variables set is +# the union of the variables set of "$1" and "$2". +# +# Note: The minimal use of backquote above ensures that trailing newlines are +# not dropped, not from the gettext invocation and not from the value of any +# shell variable. +# +# Note: Field splitting on the `envsubst --variables ...` result is desired, +# since envsubst outputs the variables, separated by newlines. Pathname +# wildcard expansion or tilde expansion has no effect here, since the words +# output by "envsubst --variables ..." consist solely of alphanumeric +# characters and underscore. diff --git a/libs/gettext/bin64/gettextize b/libs/gettext/bin64/gettextize new file mode 100755 index 000000000..8261a1cb7 --- /dev/null +++ b/libs/gettext/bin64/gettextize @@ -0,0 +1,1281 @@ +#! /bin/sh +# +# Copyright (C) 1995-1998, 2000-2010 Free Software Foundation, Inc. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +# This file is meant for authors or maintainers which want to +# internationalize their package with the help of GNU gettext. For +# further information how to use it consult the GNU gettext manual. + +progname=$0 +package=gettext-tools +version=0.18.1 + +# Set variables +# - gettext_dir directory where the sources are stored. +prefix="/usr/local/x86_64-w64-mingw32/stow/gettext-0.18.1.1" +datarootdir="${prefix}/share" +gettext_dir="${datarootdir}/gettext" + +# func_tmpdir +# creates a temporary directory. +# Sets variable +# - tmp pathname of freshly created temporary directory +func_tmpdir () +{ + # Use the environment variable TMPDIR, falling back to /tmp. This allows + # users to specify a different temporary directory, for example, if their + # /tmp is filled up or too small. + : ${TMPDIR=/tmp} + { + # Use the mktemp program if available. If not available, hide the error + # message. + tmp=`(umask 077 && mktemp -d "$TMPDIR/gtXXXXXX") 2>/dev/null` && + test -n "$tmp" && test -d "$tmp" + } || + { + # Use a simple mkdir command. It is guaranteed to fail if the directory + # already exists. $RANDOM is bash specific and expands to empty in shells + # other than bash, ksh and zsh. Its use does not increase security; + # rather, it minimizes the probability of failure in a very cluttered /tmp + # directory. + tmp=$TMPDIR/gt$$-$RANDOM + (umask 077 && mkdir "$tmp") + } || + { + echo "$0: cannot create a temporary directory in $TMPDIR" >&2 + { (exit 1); exit 1; } + } +} + +# Support for relocatability. +func_find_curr_installdir () +{ + # Determine curr_installdir, even taking into account symlinks. + curr_executable="$0" + case "$curr_executable" in + */* | *\\*) ;; + *) # Need to look in the PATH. + if test "${PATH_SEPARATOR+set}" != set; then + func_tmpdir + { echo "#! /bin/sh"; echo "exit 0"; } > "$tmp"/conf.sh + chmod +x "$tmp"/conf.sh + if (PATH="/nonexistent;$tmp"; conf.sh) >/dev/null 2>&1; then + PATH_SEPARATOR=';' + else + PATH_SEPARATOR=: + fi + rm -rf "$tmp" + fi + save_IFS="$IFS"; IFS="$PATH_SEPARATOR" + for dir in $PATH; do + IFS="$save_IFS" + test -z "$dir" && dir=. + for exec_ext in ''; do + if test -f "$dir/$curr_executable$exec_ext"; then + curr_executable="$dir/$curr_executable$exec_ext" + break 2 + fi + done + done + IFS="$save_IFS" + ;; + esac + # Make absolute. + case "$curr_executable" in + /* | ?:/* | ?:\\*) ;; + *) curr_executable=`pwd`/"$curr_executable" ;; + esac + # Resolve symlinks. + sed_dirname='s,/[^/]*$,,' + sed_linkdest='s,^.* -> \(.*\),\1,p' + while : ; do + lsline=`LC_ALL=C ls -l "$curr_executable"` + case "$lsline" in + *" -> "*) + linkdest=`echo "$lsline" | sed -n -e "$sed_linkdest"` + case "$linkdest" in + /* | ?:/* | ?:\\*) curr_executable="$linkdest" ;; + *) curr_executable=`echo "$curr_executable" | sed -e "$sed_dirname"`/"$linkdest" ;; + esac ;; + *) break ;; + esac + done + curr_installdir=`echo "$curr_executable" | sed -e 's,/[^/]*$,,'` + # Canonicalize. + curr_installdir=`cd "$curr_installdir" && pwd` +} +func_find_prefixes () +{ + # Compute the original/current installation prefixes by stripping the + # trailing directories off the original/current installation directories. + orig_installprefix="$orig_installdir" + curr_installprefix="$curr_installdir" + while true; do + orig_last=`echo "$orig_installprefix" | sed -n -e 's,^.*/\([^/]*\)$,\1,p'` + curr_last=`echo "$curr_installprefix" | sed -n -e 's,^.*/\([^/]*\)$,\1,p'` + if test -z "$orig_last" || test -z "$curr_last"; then + break + fi + if test "$orig_last" != "$curr_last"; then + break + fi + orig_installprefix=`echo "$orig_installprefix" | sed -e 's,/[^/]*$,,'` + curr_installprefix=`echo "$curr_installprefix" | sed -e 's,/[^/]*$,,'` + done +} +if test "no" = yes; then + exec_prefix="${prefix}" + bindir="${exec_prefix}/bin" + orig_installdir="$bindir" # see Makefile.am's *_SCRIPTS variables + func_find_curr_installdir # determine curr_installdir + func_find_prefixes + # Relocate the directory variables that we use. + gettext_dir=`echo "$gettext_dir/" | sed -e "s%^${orig_installprefix}/%${curr_installprefix}/%" | sed -e 's,/$,,'` +fi + +# func_usage +# outputs to stdout the --help usage message. +func_usage () +{ + echo "\ +Usage: gettextize [OPTION]... [package-dir] + +Prepares a source package to use gettext. + +Options: + --help print this help and exit + --version print version information and exit + -f, --force force writing of new files even if old exist + --intl install libintl in a subdirectory (deprecated) + --po-dir=DIR specify directory with PO files + --no-changelog don't update or create ChangeLog files + --symlink make symbolic links instead of copying files + -n, --dry-run print modifications but don't perform them + +Report bugs to ." +} + +# func_version +# outputs to stdout the --version message. +func_version () +{ + echo "$progname (GNU $package) $version" + echo "Copyright (C) 1995-1998, 2000-2010 Free Software Foundation, Inc. +License GPLv3+: GNU GPL version 3 or later +This is free software: you are free to change and redistribute it. +There is NO WARRANTY, to the extent permitted by law." + echo "Written by" "Ulrich Drepper" +} + +# func_fatal_error message +# outputs to stderr a fatal error message, and terminates the program. +func_fatal_error () +{ + echo "gettextize: *** $1" 1>&2 + echo "gettextize: *** Stop." 1>&2 + exit 1 +} + +# Nuisances. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + +# Command-line option processing. +# Removes the OPTIONS from the arguments. Sets the variables: +# - force 1 if --force was given, 0 otherwise +# - intldir yes if --intl was given, empty otherwise +# - podirs list of directories specified with --po-dir +# - try_ln_s : if --symlink was given, false otherwise +# - do_changelog false if --no-changelog was given, : otherwise +# - doit false if --dry-run was given, : otherwise +{ + force=0 + intldir= + podirs= + try_ln_s=false + do_changelog=: + doit=: + + while test $# -gt 0; do + case "$1" in + -c | --copy | --cop | --co | --c ) # accepted for backward compatibility + shift ;; + -n | --dry-run | --dry-ru | --dry-r | --dry- | --dry | --dr | --d ) + shift + doit=false ;; + -f | --force | --forc | --for | --fo | --f ) + shift + force=1 ;; + --help | --hel | --he | --h ) + func_usage; exit 0 ;; + --intl | --int | --in | --i ) + shift + intldir=yes ;; + --po-dir | --po-di | --po-d | --po- | --po | --p ) + shift + if test $# = 0; then + func_fatal_error "missing argument for --po-dir" + fi + case "$1" in + -*) func_fatal_error "missing argument for --po-dir" ;; + esac + podirs="$podirs $1" + shift ;; + --po-dir=* ) + arg=`echo "X$1" | sed -e 's/^X--po-dir=//'` + podirs="$podirs $arg" + shift ;; + --no-changelog | --no-changelo | --no-changel | --no-change | --no-chang | --no-chan | --no-cha | --no-ch | --no-c ) + shift + do_changelog=false ;; + --symlink | --symlin | --symli | --syml | --sym | --sy | --s ) + shift + try_ln_s=: ;; + --version | --versio | --versi | --vers | --ver | --ve | --v ) + func_version + exit 0 ;; + -- ) # Stop option prcessing + shift; break ;; + -* ) + echo "gettextize: unknown option $1" 1>&2 + echo "Try 'gettextize --help' for more information." 1>&2 + exit 1 ;; + * ) + break ;; + esac + done + # podirs defaults to "po". + test -n "$podirs" || podirs="po" +} + +# Warn about deprecated options. +if test -n "$intldir"; then + echo "gettextize: warning: the option '--intl' is deprecated and will be removed" 1>&2 +fi + +# Command-line argument processing. +# Analyzes the remaining arguments. +# Sets the variables +# - origdir to the original directory, +# - srcdir to the package directory, and cd-s into it. +{ + if test $# -gt 1; then + func_usage 1>&2 + exit 1 + fi + origdir=`pwd` + if test $# -eq 1; then + srcdir=$1 + if cd "$srcdir"; then + srcdir=`pwd` + else + func_fatal_error "Cannot change directory to '$srcdir'." + fi + else + srcdir=$origdir + fi +} + +# The current directory is now $srcdir. + +# Check integrity of package: A configure.in/ac must be present. Sets variable +# - configure_in name of configure.in/ac file. +test -f configure.in || test -f configure.ac || + func_fatal_error "Missing configure.in or configure.ac, please cd to your package first." +configure_in=NONE +if test -f configure.in; then + configure_in=configure.in +else + if test -f configure.ac; then + configure_in=configure.ac + fi +fi + +# Check whether the --force option is needed but has not been specified. +if test $force -eq 0; then + if test -d intl; then + func_fatal_error "intl/ subdirectory exists: use option -f if you really want to delete it." + fi + for podir in $podirs; do + if test -f "$podir/Makefile.in.in"; then + func_fatal_error "$podir/Makefile.in.in exists: use option -f if you really want to delete it." + fi + done + if test -f ABOUT-NLS; then + func_fatal_error "ABOUT-NLS exists: use option -f if you really want to delete it." + fi +fi + +# Check in which directory config.rpath etc. belong. +auxdir=`cat "$configure_in" | grep '^AC_CONFIG_AUX_DIR' | sed -n -e 's/AC_CONFIG_AUX_DIR(\([^()]*\))/\1/p' | sed -e 's/^\[\(.*\)\]$/\1/' | sed -e 1q` +if test -n "$auxdir"; then + auxdir="$auxdir/" +fi + +# For simplicity we change to the gettext source directory. +cd "$gettext_dir" || + func_fatal_error "gettext source directory '${gettext_dir}' doesn't exist" + +# Variables which keep track what has been modified. +added_directories= +removed_directory= +added_extradist= +added_acoutput= +removed_acoutput=" intl/intlh.inst" + +# Variable: +# - please accumulates instructions for the user. +please= + +# Variable: +# - date current date, for use in ChangeLog entries. +date=`date +%Y-%m-%d` + +# func_copy from to +# copies a file. +# 'from' is a relative pathname, relative to the current directory. +# 'to' is a relative pathname, relative to $srcdir. +func_copy () +{ + if $doit; then + rm -f "$srcdir/$2" + echo "Copying file $2" + cp "$1" "$srcdir/$2" + else + echo "Copy file $2" + fi +} + +# func_linkorcopy from absfrom to +# links or copies a file. +# 'from' is a relative pathname, relative to the current directory. +# 'absfrom' is the corresponding absolute pathname. +# 'to' is a relative pathname, relative to $srcdir. +func_linkorcopy () +{ + if $doit; then + rm -f "$srcdir/$3" + ($try_ln_s && ln -s "$2" "$srcdir/$3" && echo "Symlinking file $3") 2>/dev/null || + { echo "Copying file $3"; cp "$1" "$srcdir/$3"; } + else + if $try_ln_s; then + echo "Symlink file $3" + else + echo "Copy file $3" + fi + fi +} + +# func_backup to +# makes a backup of a file that is about to be overwritten or replaced. +# 'to' is a relative pathname, relative to $srcdir. +func_backup () +{ + if $doit; then + if test -f "$srcdir/$1"; then + rm -f "$srcdir/$1~" + cp -p "$srcdir/$1" "$srcdir/$1~" + fi + fi +} + +# func_remove to +# removes a file. +# 'to' is a relative pathname, relative to $srcdir. +func_remove () +{ + if $doit; then + echo "Removing $1" + rm -f "$srcdir/$1" + else + echo "Remove $1" + fi +} + +# func_ChangeLog_init +# func_ChangeLog_add_entry line +# func_ChangeLog_finish +# manage the ChangeLog file, relative to $srcdir. +func_ChangeLog_init () +{ + modified_ChangeLog= +} +func_ChangeLog_add_entry () +{ + if $doit; then + if test -z "$modified_ChangeLog"; then + echo "$date gettextize " > "$srcdir/ChangeLog.tmp" + echo >> "$srcdir/ChangeLog.tmp" + modified_ChangeLog=yes + fi + echo "$1" >> "$srcdir/ChangeLog.tmp" + else + modified_ChangeLog=yes + fi +} +func_ChangeLog_finish () +{ + if test -n "$modified_ChangeLog"; then + if $doit; then + echo >> "$srcdir/ChangeLog.tmp" + if test -f "$srcdir/ChangeLog"; then + echo "Adding an entry to ChangeLog (backup is in ChangeLog~)" + cat "$srcdir/ChangeLog" >> "$srcdir/ChangeLog.tmp" + rm -f "$srcdir/ChangeLog~" + cp -p "$srcdir/ChangeLog" "$srcdir/ChangeLog~" + else + echo "Creating ChangeLog" + fi + cp "$srcdir/ChangeLog.tmp" "$srcdir/ChangeLog" + rm -f "$srcdir/ChangeLog.tmp" + else + if test -f "$srcdir/ChangeLog"; then + echo "Add an entry to ChangeLog" + else + echo "Create ChangeLog" + fi + fi + fi +} + +# func_poChangeLog_init +# func_poChangeLog_add_entry line +# func_poChangeLog_finish +# manage the $podir/ChangeLog file, relative to $srcdir. +func_poChangeLog_init () +{ + modified_poChangeLog= +} +func_poChangeLog_add_entry () +{ + if $doit; then + if test -z "$modified_poChangeLog"; then + echo "$date gettextize " > "$srcdir/$podir/ChangeLog.tmp" + echo >> "$srcdir/$podir/ChangeLog.tmp" + modified_poChangeLog=yes + fi + echo "$1" >> "$srcdir/$podir/ChangeLog.tmp" + else + modified_poChangeLog=yes + fi +} +func_poChangeLog_finish () +{ + if test -n "$modified_poChangeLog"; then + if $doit; then + echo >> "$srcdir/$podir/ChangeLog.tmp" + if test -f "$srcdir/$podir/ChangeLog"; then + echo "Adding an entry to $podir/ChangeLog (backup is in $podir/ChangeLog~)" + cat "$srcdir/$podir/ChangeLog" >> "$srcdir/$podir/ChangeLog.tmp" + rm -f "$srcdir/$podir/ChangeLog~" + cp -p "$srcdir/$podir/ChangeLog" "$srcdir/$podir/ChangeLog~" + else + echo "Creating $podir/ChangeLog" + fi + cp "$srcdir/$podir/ChangeLog.tmp" "$srcdir/$podir/ChangeLog" + rm -f "$srcdir/$podir/ChangeLog.tmp" + else + if test -f "$srcdir/$podir/ChangeLog"; then + echo "Add an entry to $podir/ChangeLog" + else + echo "Create $podir/ChangeLog" + fi + fi + fi +} + +# func_m4ChangeLog_init +# func_m4ChangeLog_add_entry line +# func_m4ChangeLog_finish +# manage the $m4dir/ChangeLog file, relative to $srcdir. +func_m4ChangeLog_init () +{ + if test -n "$using_m4ChangeLog"; then + modified_m4ChangeLog= + created_m4ChangeLog= + fi +} +func_m4ChangeLog_add_entry () +{ + if test -n "$using_m4ChangeLog"; then + if $doit; then + if test -z "$modified_m4ChangeLog"; then + echo "$date gettextize " > "$srcdir/$m4dir/ChangeLog.tmp" + echo >> "$srcdir/$m4dir/ChangeLog.tmp" + modified_m4ChangeLog=yes + fi + echo "$1" >> "$srcdir/$m4dir/ChangeLog.tmp" + else + modified_m4ChangeLog=yes + fi + else + line="$1" + line=`echo "$line" | sed -e "s%^ \\* % * $m4dir/%"` + func_ChangeLog_add_entry "$line" + fi +} +func_m4ChangeLog_finish () +{ + if test -n "$using_m4ChangeLog"; then + if test -n "$modified_m4ChangeLog"; then + if $doit; then + echo >> "$srcdir/$m4dir/ChangeLog.tmp" + if test -f "$srcdir/$m4dir/ChangeLog"; then + echo "Adding an entry to $m4dir/ChangeLog (backup is in $m4dir/ChangeLog~)" + cat "$srcdir/$m4dir/ChangeLog" >> "$srcdir/$m4dir/ChangeLog.tmp" + rm -f "$srcdir/$m4dir/ChangeLog~" + cp -p "$srcdir/$m4dir/ChangeLog" "$srcdir/$m4dir/ChangeLog~" + else + echo "Creating $m4dir/ChangeLog" + created_m4ChangeLog=yes + fi + cp "$srcdir/$m4dir/ChangeLog.tmp" "$srcdir/$m4dir/ChangeLog" + rm -f "$srcdir/$m4dir/ChangeLog.tmp" + else + if test -f "$srcdir/$m4dir/ChangeLog"; then + echo "Add an entry to $m4dir/ChangeLog" + else + echo "Create $m4dir/ChangeLog" + created_m4ChangeLog=yes + fi + fi + fi + fi +} +using_m4ChangeLog=yes + +if test ! -f "$srcdir/intl/Makefile.in" && test -n "$intldir"; then + added_acoutput="$added_acoutput intl/Makefile" +fi +if test -f "$srcdir/intl/Makefile.in" && test -z "$intldir"; then + removed_acoutput="$removed_acoutput intl/Makefile" +fi +if test -d "$srcdir/intl"; then + # Remove everything inside intl except for RCS and CVS subdirs and invisible + # files. + if $doit; then + echo "Wiping out intl/ subdirectory" + (cd "$srcdir/intl" && + for f in *; do + if test CVS != "$f" && test RCS != "$f"; then + rm -rf "$f" + fi + done) + else + echo "Wipe out intl/ subdirectory" + fi + if test -z "$intldir"; then + removed_directory=intl + fi +else + if test -n "$intldir"; then + if $doit; then + echo "Creating intl/ subdirectory" + mkdir "$srcdir/intl" || func_fatal_error "failed to create intl/ subdirectory" + else + echo "Create intl/ subdirectory" + fi + added_directories="$added_directories intl" + fi +fi + +$do_changelog && func_ChangeLog_init + +for podir in $podirs; do + test -d "$srcdir/$podir" || { + if $doit; then + echo "Creating $podir/ subdirectory" + mkdir "$srcdir/$podir" || func_fatal_error "failed to create $podir/ subdirectory" + else + echo "Create $podir/ subdirectory" + fi + added_directories="$added_directories $podir" + } +done + +# Create the directory for config.rpath, if needed. +# This is for consistency with autoreconf and automake. +# Note that $auxdir is either empty or ends in a slash. +test -d "$srcdir/$auxdir" || { + if $doit; then + echo "Creating $auxdir subdirectory" + mkdir "$srcdir/$auxdir" || func_fatal_error "failed to create $auxdir subdirectory" + else + echo "Create $auxdir subdirectory" + fi +} + +# Now copy all files. Take care for the destination directories. +for file in *; do + case $file in + ABOUT-NLS) + func_linkorcopy $file "$gettext_dir/$file" $file + ;; + config.rpath) + if test -f "$srcdir/$auxdir$file"; then + : + else + added_extradist="$added_extradist $auxdir$file" + fi + func_linkorcopy $file "$gettext_dir/$file" "$auxdir$file" + ;; + esac +done + +# Copy files to intl/ subdirectory. +if test -n "$intldir"; then + cd intl + for file in *; do + if test $file != COPYING.LIB-2.0 && test $file != COPYING.LIB-2.1; then + if test $file != plural.c; then + func_linkorcopy $file "$gettext_dir/intl/$file" intl/$file + else + # plural.c is a generated file; it must be copied and touched. + func_copy $file intl/$file + if $doit; then + (sleep 2; touch "$srcdir/intl/$file") & + fi + fi + fi + done + cd .. +else + echo "Not copying intl/ directory." + # Tell the user what to put into configure.ac, if it is not already there. + if grep '^AM_GNU_GETTEXT([[]\?external[]]\?[ ]*[,)]' "$srcdir/$configure_in" > /dev/null; then + : + else + please="$please +Please use AM_GNU_GETTEXT([external]) in order to cause autoconfiguration +to look for an external libintl. +" + fi +fi + +# Copy files to po/ subdirectory. +cd po +for podir in $podirs; do + $do_changelog && func_poChangeLog_init + for file in Makefile.in.in; do + same=no + if test -f "$srcdir/$podir/$file"; then + if cmp -s $file "$srcdir/$podir/$file"; then + same=yes + fi + else + added_acoutput="$added_acoutput $podir/Makefile.in" + fi + if $do_changelog && test $same = no; then + if test -f "$srcdir/$podir/$file"; then + func_poChangeLog_add_entry " * $file: Upgrade to gettext-${version}." + else + func_poChangeLog_add_entry " * $file: New file, from gettext-${version}." + fi + fi + func_backup "$podir/$file" + func_linkorcopy $file "$gettext_dir/po/$file" "$podir/$file" + done + for file in *; do + case $file in + Makefile.in.in) + # Already handled above. + ;; + Makevars.template) + func_linkorcopy Makevars.template "$gettext_dir/po/Makevars.template" "$podir/Makevars.template" + if test -f "$srcdir/po/Makevars"; then + LC_ALL=C sed -n -e 's/[ ]*\([A-Za-z0-9_]*\)[ ]*=.*/\1/p' < "$srcdir/$podir/Makevars" | LC_ALL=C sort > "$srcdir/$podir/Makevars.tmp1" + LC_ALL=C sed -n -e 's/[ ]*\([A-Za-z0-9_]*\)[ ]*=.*/\1/p' < "$srcdir/$podir/Makevars.template" | LC_ALL=C sort > "$srcdir/$podir/Makevars.tmp2" + missingvars=`LC_ALL=C comm -13 "$srcdir/$podir/Makevars.tmp1" "$srcdir/$podir/Makevars.tmp2"` + rm -f "$srcdir/$podir/Makevars.tmp1" "$srcdir/$podir/Makevars.tmp2" + if test -n "$missingvars"; then + please="$please +Please update $podir/Makevars so that it defines all the variables mentioned +in $podir/Makevars.template. +You can then remove $podir/Makevars.template. +" + fi + else + please="$please +Please create $podir/Makevars from the template in $podir/Makevars.template. +You can then remove $podir/Makevars.template. +" + fi + ;; + *) + same=no + if test -f "$srcdir/$podir/$file"; then + if cmp -s $file "$srcdir/$podir/$file"; then + same=yes + fi + fi + if $do_changelog && test $same = no; then + if test -f "$srcdir/$podir/$file"; then + func_poChangeLog_add_entry " * $file: Upgrade to gettext-${version}." + else + func_poChangeLog_add_entry " * $file: New file, from gettext-${version}." + fi + fi + func_backup "$podir/$file" + func_linkorcopy $file "$gettext_dir/po/$file" "$podir/$file" + ;; + esac + done + if test -f "$srcdir/$podir/cat-id-tbl.c"; then + func_remove "$podir/cat-id-tbl.c" + $do_changelog && func_poChangeLog_add_entry " * cat-id-tbl.c: Remove file." + fi + if test -f "$srcdir/$podir/stamp-cat-id"; then + func_remove "$podir/stamp-cat-id" + $do_changelog && func_poChangeLog_add_entry " * stamp-cat-id: Remove file." + fi + if test ! -f "$srcdir/$podir/POTFILES.in"; then + if $doit; then + echo "Creating initial $podir/POTFILES.in" + echo '# List of source files which contain translatable strings.' > "$srcdir/$podir/POTFILES.in" + else + echo "Create initial $podir/POTFILES.in" + fi + $do_changelog && func_poChangeLog_add_entry " * POTFILES.in: New file." + please="$please +Please fill $podir/POTFILES.in as described in the documentation. +" + fi + $do_changelog && func_poChangeLog_finish +done + +# Determine whether we can assume automake 1.9 or newer. +have_automake19= +if (aclocal --version) >/dev/null 2>/dev/null; then + aclocal_version=`aclocal --version | sed -n -e 1p | sed -e 's/^[^0-9]*//'` + case $aclocal_version in + 1.9* | 1.[1-9][0-9]* | [2-9]*) have_automake19=yes ;; + esac +fi + +m4filelist='gettext.m4 iconv.m4 lib-ld.m4 lib-link.m4 lib-prefix.m4 nls.m4 + po.m4 progtest.m4' +# With aclocal versions < 1.9 we need all m4 files, otherwise "aclocal -I m4" +# might give an error. (aclocal < 1.9 didn't know which macros are really +# needed, it looked which macros are potentially needed.) +min_automake_version=1.9 +if test -n "$intldir" || test -z "$have_automake19"; then + # Add intldir.m4, intl.m4 and its dependencies. + m4filelist=$m4filelist' codeset.m4 fcntl-o.m4 glibc2.m4 glibc21.m4 intdiv0.m4 + intl.m4 intldir.m4 intlmacosx.m4 intmax.m4 inttypes_h.m4 inttypes-pri.m4 + lcmessage.m4 lock.m4 longlong.m4 printf-posix.m4 size_max.m4 stdint_h.m4 + threadlib.m4 uintmax_t.m4 visibility.m4 wchar_t.m4 wint_t.m4 xsize.m4' + min_automake_version=1.8 +fi + +# All sorts of bugs could occur if the configure file was remade with the wrong +# version of gettext.m4 et al. (because then the configure and the po/Makefile.in.in +# don't fit together). It is therefore important that the package carries the +# right versions of gettext.m4 et al. with it. +if test -f "$srcdir/Makefile.am"; then + # A package using automake. + + # Determine whether it's using automake 1.8 or newer. + have_automake18= + if (aclocal --version) >/dev/null 2>/dev/null; then + aclocal_version=`aclocal --version | sed -n -e 1p | sed -e 's/^[^0-9]*//'` + case $aclocal_version in + 1.[8-9]* | 1.[1-9][0-9]* | [2-9]*) have_automake18=yes ;; + esac + fi + + # Extract the macro directory name from Makefile.am. + aclocal_amflags=`grep '^ACLOCAL_AMFLAGS[ ]*=' "$srcdir/Makefile.am" | sed -e 's/^ACLOCAL_AMFLAGS[ ]*=\(.*\)$/\1/'` + m4dir=m4 + m4dir_defaulted=yes + m4dir_is_next= + for arg in $aclocal_amflags; do + if test -n "$m4dir_is_next"; then + # Ignore absolute directory pathnames, like /usr/local/share/aclocal. + case "$arg" in + /*) ;; + *) + m4dir="$arg" + m4dir_defaulted= + break + ;; + esac + m4dir_is_next= + else + if test "X$arg" = "X-I"; then + m4dir_is_next=yes + else + m4dir_is_next= + fi + fi + done + + # Decide whether to use $m4dir/ChangeLog, or to use ChangeLog instead. + if test -d "$srcdir/$m4dir" && test -f "$srcdir/ChangeLog" && test ! -f "$srcdir/$m4dir/ChangeLog"; then + # The programmer has no $m4dir/ChangeLog so far. Don't introduce one. + using_m4ChangeLog= + fi + + # Update the *.m4 files and the corresponding Makefile.am. + $do_changelog && func_m4ChangeLog_init + added_m4dir= + added_m4files= + if test -d "$srcdir/$m4dir"; then + : + else + if $doit; then + echo "Creating directory $m4dir" + mkdir "$srcdir/$m4dir" + else + echo "Create directory $m4dir" + fi + added_m4dir=yes + fi + for file in $m4filelist; do + same=no + if test -f "$srcdir/$m4dir/$file"; then + if cmp -s "${datarootdir}/aclocal/$file" "$srcdir/$m4dir/$file"; then + same=yes + fi + else + added_m4files="$added_m4files $file" + fi + if $do_changelog && test $same = no; then + if test -f "$srcdir/$m4dir/$file"; then + func_m4ChangeLog_add_entry " * $file: Upgrade to gettext-${version}." + else + func_m4ChangeLog_add_entry " * $file: New file, from gettext-${version}." + fi + fi + func_backup "$m4dir/$file" + func_linkorcopy "${datarootdir}/aclocal/$file" "${datarootdir}/aclocal/$file" "$m4dir/$file" + done + missing_m4Makefileam= + if test -n "$added_m4files"; then + if test -f "$srcdir/$m4dir/Makefile.am"; then + if $doit; then + echo "Updating EXTRA_DIST in $m4dir/Makefile.am (backup is in $m4dir/Makefile.am~)" + func_backup "$m4dir/Makefile.am" + rm -f "$srcdir/$m4dir/Makefile.am" + if grep '^EXTRA_DIST[ ]*=' "$srcdir/$m4dir/Makefile.am~" > /dev/null; then + sed -e "s%^\(EXTRA_DIST[ ]*=\) \\?%\\1$added_m4files %" < "$srcdir/$m4dir/Makefile.am~" > "$srcdir/$m4dir/Makefile.am" + $do_changelog && func_m4ChangeLog_add_entry " * Makefile.am (EXTRA_DIST): Add the new files." + else + (cat "$srcdir/$m4dir/Makefile.am~"; echo; echo "EXTRA_DIST =$added_m4files") > "$srcdir/$m4dir/Makefile.am" + $do_changelog && func_m4ChangeLog_add_entry " * Makefile.am (EXTRA_DIST): New variable." + fi + else + echo "Update EXTRA_DIST in $m4dir/Makefile.am" + $do_changelog && func_m4ChangeLog_add_entry " * Makefile.am (EXTRA_DIST)." + fi + else + # $m4dir/Makefile.am is not needed any more when aclocal 1.8 or newer + # is used. + if test -z "$have_automake18"; then + if $doit; then + echo "Creating $m4dir/Makefile.am" + echo "EXTRA_DIST =$added_m4files" > "$srcdir/$m4dir/Makefile.am" + else + echo "Create $m4dir/Makefile.am" + fi + $do_changelog && func_m4ChangeLog_add_entry " * Makefile.am: New file." + added_acoutput="$added_acoutput $m4dir/Makefile" + else + missing_m4Makefileam=yes + fi + fi + fi + if test -n "$added_m4dir" && test -z "$missing_m4Makefileam"; then + added_directories="$added_directories $m4dir" + fi + $do_changelog && func_m4ChangeLog_finish + # automake will arrange for $m4dir/ChangeLog to be distributed if a + # $m4dir/Makefile.am exists. If not, we need to add it to Makefile.am's + # EXTRA_DIST explicitly. + if test -n "$created_m4ChangeLog" && test -n "$missing_m4Makefileam"; then + added_extradist="$added_extradist $m4dir/ChangeLog" + fi + + # Update the top-level Makefile.am. + modified_Makefile_am= + # func_modify_Makefile_am changelog_comment + # assumes a modified copy of $srcdir/Makefile.am in $srcdir/Makefile.am.tmp + # and replaces the original Makefile.am file with the modified one if + # the two files differ. Then it removes the modified copy. + func_modify_Makefile_am () + { + if cmp -s "$srcdir/Makefile.am" "$srcdir/Makefile.am.tmp"; then + : + else + if test -z "$modified_Makefile_am"; then + if $doit; then + echo "Updating Makefile.am (backup is in Makefile.am~)" + func_backup Makefile.am + else + echo "Update Makefile.am" + fi + fi + if $doit; then + rm -f "$srcdir/Makefile.am" + cp "$srcdir/Makefile.am.tmp" "$srcdir/Makefile.am" + fi + if $do_changelog; then + if test -z "$modified_Makefile_am"; then + func_ChangeLog_add_entry " * Makefile.am $1" + else + func_ChangeLog_add_entry " $1" + fi + fi + modified_Makefile_am=yes + fi + rm -f "$srcdir/Makefile.am.tmp" + } + + if test -n "$added_directories"; then + if grep '^SUBDIRS[ ]*=' "$srcdir/Makefile.am" > /dev/null; then + sed -e "s%^\(SUBDIRS[ ]*=\) \\?%\\1$added_directories %" < "$srcdir/Makefile.am" > "$srcdir/Makefile.am.tmp" + added_directories_pretty=`echo $added_directories | sed -e 's/ /, /g'` + func_modify_Makefile_am "(SUBDIRS): Add $added_directories_pretty." + else + (cat "$srcdir/Makefile.am"; echo; echo "SUBDIRS =$added_directories") > "$srcdir/Makefile.am.tmp" + func_modify_Makefile_am "(SUBDIRS): New variable." + fi + fi + if test -n "$removed_directory"; then + sed -e '/^SUBDIRS[ ]*=/ { + :a + s%\([ ]\)'"$removed_directory"'[ ]%\1% + s%[ ]'"$removed_directory"'$%% + tb + :b + s%\\$%\\% + tc + bd + :c + n + ba + :d + }' < "$srcdir/Makefile.am" > "$srcdir/Makefile.am.tmp" + func_modify_Makefile_am "(SUBDIRS): Remove $removed_directory." + fi + if test -n "$added_directories"; then + if grep '^DIST_SUBDIRS[ ]*=' "$srcdir/Makefile.am" > /dev/null; then + sed -e "s%^\(DIST_SUBDIRS[ ]*=\) \\?%\\1$added_directories %" < "$srcdir/Makefile.am" > "$srcdir/Makefile.am.tmp" + added_directories_pretty=`echo $added_directories | sed -e 's/ /, /g'` + func_modify_Makefile_am "(DIST_SUBDIRS): Add $added_directories_pretty." + fi + fi + if test -n "$removed_directory"; then + sed -e '/^DIST_SUBDIRS[ ]*=/ { + :a + s%\([ ]\)'"$removed_directory"'[ ]%\1% + s%[ ]'"$removed_directory"'$%% + tb + :b + s%\\$%\\% + tc + bd + :c + n + ba + :d + }' < "$srcdir/Makefile.am" > "$srcdir/Makefile.am.tmp" + func_modify_Makefile_am "(DIST_SUBDIRS): Remove $removed_directory." + fi + if test -n "$m4dir_defaulted"; then + if grep '^ACLOCAL_AMFLAGS[ ]*=' "$srcdir/Makefile.am" > /dev/null; then + sed -e "s%^\(ACLOCAL_AMFLAGS[ ]*=\) \\?%\\1 -I $m4dir %" < "$srcdir/Makefile.am" > "$srcdir/Makefile.am.tmp" + func_modify_Makefile_am "(ACLOCAL_AMFLAGS): Add -I $m4dir." + else + (cat "$srcdir/Makefile.am"; echo; echo "ACLOCAL_AMFLAGS = -I $m4dir") > "$srcdir/Makefile.am.tmp" + func_modify_Makefile_am "(ACLOCAL_AMFLAGS): New variable." + fi + # Also update Makefile.in and, if existent, Makefile. Otherwise they + # would take into account the new flags only after a few rounds of + # "./configure", "make", "touch configure.in", "make distclean". + if $doit; then + for file in Makefile.in Makefile; do + if test -f "$srcdir/$file"; then + func_backup $file + rm -f "$srcdir/$file" + sed -e "s%(ACLOCAL)%(ACLOCAL) -I $m4dir%" < "$srcdir/$file~" > "$srcdir/$file" + fi + done + fi + fi + if test -n "$added_extradist"; then + if grep '^EXTRA_DIST[ ]*=' "$srcdir/Makefile.am" > /dev/null; then + sed -e "s%^\(EXTRA_DIST[ ]*=\)%\\1$added_extradist %" < "$srcdir/Makefile.am" > "$srcdir/Makefile.am.tmp" + added_extradist_pretty=`echo $added_extradist | sed -e 's/ /, /g'` + func_modify_Makefile_am "(EXTRA_DIST): Add $added_extradist_pretty." + else + (cat "$srcdir/Makefile.am"; echo; echo "EXTRA_DIST =$added_extradist") > "$srcdir/Makefile.am.tmp" + func_modify_Makefile_am "(EXTRA_DIST): New variable." + fi + fi + # Extract the aclocal options name from Makefile.am. + aclocal_amflags=`grep '^ACLOCAL_AMFLAGS[ ]*=' "$srcdir/Makefile.am" | sed -e 's/^ACLOCAL_AMFLAGS[ ]*=\(.*\)$/\1/'` + aclocal_options= + m4dir_is_next= + for arg in $aclocal_amflags; do + if test -n "$m4dir_is_next"; then + aclocal_options="$aclocal_options -I $arg" + m4dir_is_next= + else + if test "X$arg" = "X-I"; then + m4dir_is_next=yes + else + m4dir_is_next= + fi + fi + done + please="$please +Please run 'aclocal$aclocal_options' to regenerate the aclocal.m4 file. +You need aclocal from GNU automake $min_automake_version (or newer) to do this. +Then run 'autoconf' to regenerate the configure file. +" + + # Also create $m4dir/Makefile.in from $m4dir/Makefile.am, because automake + # doesn't do it by itself. + if $doit; then + case "$added_acoutput" in + *" $m4dir/Makefile") + (cd "$srcdir" && automake "$m4dir/Makefile") 2>/dev/null || + please="$please +Please run 'automake $m4dir/Makefile' to create $m4dir/Makefile.in +" + ;; + esac + fi +else + please="$please +Please add the files +$m4filelist +from the ${datarootdir}/aclocal directory to your aclocal.m4 file. +" +fi + +modified_configure_in= +# func_modify_configure_in changelog_comment +# assumes a modified copy of $srcdir/$configure_in in $srcdir/$configure_in.tmp +# and replaces the original configure.in/ac file with the modified one if +# the two files differ. Then it removes the modified copy. +func_modify_configure_in () +{ + if cmp -s "$srcdir/$configure_in" "$srcdir/$configure_in.tmp"; then + : + else + if test -z "$modified_configure_in"; then + if $doit; then + echo "Updating $configure_in (backup is in $configure_in~)" + func_backup $configure_in + else + echo "Update $configure_in" + fi + fi + if $doit; then + rm -f "$srcdir/$configure_in" + cp "$srcdir/$configure_in.tmp" "$srcdir/$configure_in" + fi + if $do_changelog; then + if test -z "$modified_configure_in"; then + func_ChangeLog_add_entry " * $configure_in $1" + else + func_ChangeLog_add_entry " $1" + fi + fi + modified_configure_in=yes + fi + rm -f "$srcdir/$configure_in.tmp" +} + +if test -n "$added_acoutput"; then + if grep '^AC_CONFIG_FILES(' "$srcdir/$configure_in" > /dev/null; then + sedprog=' +ta +b +:a +n +ba' + sed -e "s%^\\(AC_CONFIG_FILES([^])\\,]*\\)%\\1$added_acoutput%$sedprog" < "$srcdir/$configure_in" > "$srcdir/$configure_in.tmp" + added_acoutput_pretty=`echo $added_acoutput | sed -e 's/ /, /g'` + func_modify_configure_in "(AC_CONFIG_FILES): Add $added_acoutput_pretty." + else + if grep '^AC_OUTPUT(' "$srcdir/$configure_in" > /dev/null; then + sed -e "s%^\\(AC_OUTPUT([^])\\,]*\\)%\\1$added_acoutput%" < "$srcdir/$configure_in" > "$srcdir/$configure_in.tmp" + added_acoutput_pretty=`echo $added_acoutput | sed -e 's/ /, /g'` + func_modify_configure_in "(AC_OUTPUT): Add $added_acoutput_pretty." + else + please="$please +Please add$added_acoutput to the AC_OUTPUT or AC_CONFIG_FILES invocation in the $configure_in file. +" + fi + fi +fi +if test -n "$removed_acoutput"; then + for file in $removed_acoutput; do + tag= + sedprog='{ + s%\([[ ]\)'"$file"'[ ]%\1% + s%\([[ ]\)'"$file"'\([]),]\)%\1\2% + s%[[ ]'"$file"'$%% + :a + tb + :b + s%\\$%\\% + tc + bd + :c + n + s%\([ ]\)'"$file"'[ ]%\1% + s%\([ ]\)'"$file"'\([]),]\)%\1\2% + s%[ ]'"$file"'$%% + ba + :d + }' + sed -e '/^AC_CONFIG_FILES(/'"$sedprog" < "$srcdir/$configure_in" > "$srcdir/$configure_in.tmp" + if cmp -s "$srcdir/$configure_in" "$srcdir/$configure_in.tmp"; then + sed -e '/^AC_OUTPUT(/'"$sedprog" < "$srcdir/$configure_in" > "$srcdir/$configure_in.tmp" + if cmp -s "$srcdir/$configure_in" "$srcdir/$configure_in.tmp"; then + : + else + tag=AC_OUTPUT + fi + else + tag=AC_CONFIG_FILES + fi + if test -n "$tag"; then + func_modify_configure_in "($tag): Remove $file." + else + rm -f "$srcdir/$configure_in.tmp" + if test "$file" != intl/intlh.inst; then + please="$please +Please remove $file from the AC_OUTPUT or AC_CONFIG_FILES invocation +in the $configure_in file. +" + fi + fi + done +fi +sed -e 's%sed -e "/POTFILES =/r po/POTFILES" po/Makefile\.in > po/Makefile *;* *%%' < "$srcdir/$configure_in" > "$srcdir/$configure_in.tmp" +func_modify_configure_in "(AC_OUTPUT): Remove command that created po/Makefile." +sed -e '/^\(dnl \|\)AC_LINK_FILES(\$nls_cv_header_libgt, \$nls_cv_header_intl)$/d' < "$srcdir/$configure_in" > "$srcdir/$configure_in.tmp" +func_modify_configure_in "(AC_LINK_FILES): Remove invocation." +sed -e 's/^AM_GNU_GETTEXT_VERSION([^()]*)/AM_GNU_GETTEXT_VERSION(['"$version"'])/' < "$srcdir/$configure_in" > "$srcdir/$configure_in.tmp" +func_modify_configure_in "(AM_GNU_GETTEXT_VERSION): Bump to $version." +$do_changelog && func_ChangeLog_finish + +# Recommend replacement for deprecated Makefile variables. +use_libtool=`cat "$srcdir/$configure_in" | grep '^A[CM]_PROG_LIBTOOL'` +for file in `(cd "$srcdir"; find . -name Makefile.am -print; find . -name Makefile.in -print) | sed -e 's,^\./,,'`; do + if test -f "$srcdir/$file"; then + if test `echo "$file" | sed -e 's,^.*/,,'` = Makefile.in && grep automake "$srcdir/$file" >/dev/null 2>&1; then + continue; + fi + # INTLLIBS is deprecated because it doesn't distinguish the two + # cases: with libtool, without libtool. + if grep '@''INTLLIBS''@' "$srcdir/$file" >/dev/null 2>&1; then + if test -n "$use_libtool"; then + please="$please +Please change $file to use @""LTLIBINTL""@ or @""LIBINTL""@ instead of +@""INTLLIBS""@. Which one, depends whether it is used with libtool or not. +@""INTLLIBS""@ will go away. +" + else + please="$please +Please change $file to use @""LIBINTL""@ instead of @""INTLLIBS""@. +@""INTLLIBS""@ will go away. +" + fi + fi + # DATADIRNAME is deprecated because we install only .gmo files nowadays, + # which can be stored in the platform independent $prefix/share hierarchy. + if grep '@''DATADIRNAME''@' "$srcdir/$file" >/dev/null 2>&1; then + please="$please +Please change $file to use the constant string \"share\" instead of +@""DATADIRNAME""@. @""DATADIRNAME""@ will go away. +" + fi + # INSTOBJEXT is deprecated because we install only .gmo files nowadays, + # no catgets .cat catalogs. + if grep '@''INSTOBJEXT''@' "$srcdir/$file" >/dev/null 2>&1; then + please="$please +Please change $file to use the constant string \".mo\" instead of +@""INSTOBJEXT""@. @""INSTOBJEXT""@ will go away. +" + fi + # GENCAT is deprecated because we install no catgets catalogs anymore. + if grep '@''GENCAT''@' "$srcdir/$file" >/dev/null 2>&1; then + please="$please +Please change $file to use the constant string \"gencat\" instead of +@""GENCAT""@. @""GENCAT""@ will go away. Maybe you don't even need it any more? +" + fi + # POSUB is deprecated because it causes "./configure --disable-nls", "make", + # "make dist" to create a buggy tarfile. + if grep '@''POSUB''@' "$srcdir/$file" >/dev/null 2>&1; then + please="$please +Please change $file to use the constant string \"po\" instead of +@""POSUB""@. @""POSUB""@ will go away. +" + fi + fi +done + +# Recommend replacement for deprecated configure variables. +if grep '\$nls_cv_header_' "$srcdir/$configure_in" >/dev/null 2>&1; then + please="$please +Please stop using \$nls_cv_header_intl or \$nls_cv_header_libgt in the +$configure_in file. Both will go away. Use or \"gettext.h\" instead. +" +fi + +# Recommend fetching config.guess and config.sub. +if test -f "$srcdir/$auxdir"config.guess && test -f "$srcdir/$auxdir"config.sub; then + : +else + please="$please +You will also need config.guess and config.sub, which you can get from the CVS +of the 'config' project at http://savannah.gnu.org/. The commands to fetch them +are +\$ wget 'http://savannah.gnu.org/cgi-bin/viewcvs/*checkout*/config/config/config.guess' +\$ wget 'http://savannah.gnu.org/cgi-bin/viewcvs/*checkout*/config/config/config.sub' +" +fi + +if $doit; then + echo "$please" + echo "You might also want to copy the convenience header file gettext.h" + echo "from the $gettext_dir directory into your package." + echo "It is a wrapper around that implements the configure --disable-nls" + echo "option." + echo + count=`echo "$please" | grep '^$' | wc -l` + count=`echo "$count" | sed -e 's/[ ]//g'` + case "$count" in + 1) count="paragraph";; + 2) count="two paragraphs";; + 3) count="three paragraphs";; + 4) count="four paragraphs";; + 5) count="five paragraphs";; + *) count="$count paragraphs";; + esac + echo "Press Return to acknowledge the previous $count." + # Read from /dev/tty, not stdin, so that gettextize cannot be abused by + # non-interactive tools. + read dummy < /dev/tty +fi + +exit 0 diff --git a/libs/gettext/bin64/msgattrib.exe b/libs/gettext/bin64/msgattrib.exe new file mode 100644 index 000000000..cc904e272 Binary files /dev/null and b/libs/gettext/bin64/msgattrib.exe differ diff --git a/libs/gettext/bin64/msgcat.exe b/libs/gettext/bin64/msgcat.exe new file mode 100644 index 000000000..3af8a496d Binary files /dev/null and b/libs/gettext/bin64/msgcat.exe differ diff --git a/libs/gettext/bin64/msgcmp.exe b/libs/gettext/bin64/msgcmp.exe new file mode 100644 index 000000000..27e6c6f62 Binary files /dev/null and b/libs/gettext/bin64/msgcmp.exe differ diff --git a/libs/gettext/bin64/msgcomm.exe b/libs/gettext/bin64/msgcomm.exe new file mode 100644 index 000000000..5d39de446 Binary files /dev/null and b/libs/gettext/bin64/msgcomm.exe differ diff --git a/libs/gettext/bin64/msgconv.exe b/libs/gettext/bin64/msgconv.exe new file mode 100644 index 000000000..d454ac15f Binary files /dev/null and b/libs/gettext/bin64/msgconv.exe differ diff --git a/libs/gettext/bin64/msgen.exe b/libs/gettext/bin64/msgen.exe new file mode 100644 index 000000000..bd9438b36 Binary files /dev/null and b/libs/gettext/bin64/msgen.exe differ diff --git a/libs/gettext/bin64/msgexec.exe b/libs/gettext/bin64/msgexec.exe new file mode 100644 index 000000000..dd988641e Binary files /dev/null and b/libs/gettext/bin64/msgexec.exe differ diff --git a/libs/gettext/bin64/msgfilter.exe b/libs/gettext/bin64/msgfilter.exe new file mode 100644 index 000000000..1c07caf3c Binary files /dev/null and b/libs/gettext/bin64/msgfilter.exe differ diff --git a/libs/gettext/bin64/msgfmt.exe b/libs/gettext/bin64/msgfmt.exe new file mode 100644 index 000000000..1907713a5 Binary files /dev/null and b/libs/gettext/bin64/msgfmt.exe differ diff --git a/libs/gettext/bin64/msggrep.exe b/libs/gettext/bin64/msggrep.exe new file mode 100644 index 000000000..4cc3cbf0f Binary files /dev/null and b/libs/gettext/bin64/msggrep.exe differ diff --git a/libs/gettext/bin64/msginit.exe b/libs/gettext/bin64/msginit.exe new file mode 100644 index 000000000..67ac3e2d3 Binary files /dev/null and b/libs/gettext/bin64/msginit.exe differ diff --git a/libs/gettext/bin64/msgmerge.exe b/libs/gettext/bin64/msgmerge.exe new file mode 100644 index 000000000..1104a71f9 Binary files /dev/null and b/libs/gettext/bin64/msgmerge.exe differ diff --git a/libs/gettext/bin64/msgunfmt.exe b/libs/gettext/bin64/msgunfmt.exe new file mode 100644 index 000000000..a0b6f5c3f Binary files /dev/null and b/libs/gettext/bin64/msgunfmt.exe differ diff --git a/libs/gettext/bin64/msguniq.exe b/libs/gettext/bin64/msguniq.exe new file mode 100644 index 000000000..875d1362d Binary files /dev/null and b/libs/gettext/bin64/msguniq.exe differ diff --git a/libs/gettext/bin64/ngettext.exe b/libs/gettext/bin64/ngettext.exe new file mode 100644 index 000000000..674204be3 Binary files /dev/null and b/libs/gettext/bin64/ngettext.exe differ diff --git a/libs/gettext/bin64/recode-sr-latin.exe b/libs/gettext/bin64/recode-sr-latin.exe new file mode 100644 index 000000000..bdc3f8bbd Binary files /dev/null and b/libs/gettext/bin64/recode-sr-latin.exe differ diff --git a/libs/gettext/bin64/xgettext.exe b/libs/gettext/bin64/xgettext.exe new file mode 100644 index 000000000..f43f64239 Binary files /dev/null and b/libs/gettext/bin64/xgettext.exe differ diff --git a/libs/gettext/gettext-0.18.1.1-tml.patch b/libs/gettext/gettext-0.18.1.1-tml.patch new file mode 100644 index 000000000..55e295fe0 --- /dev/null +++ b/libs/gettext/gettext-0.18.1.1-tml.patch @@ -0,0 +1,177 @@ +--- gettext-runtime/intl/printf.c ++++ gettext-runtime/intl/printf.c +@@ -69,7 +69,7 @@ + #define STATIC static + + /* This needs to be consistent with libgnuintl.h.in. */ +-#if defined __NetBSD__ || defined __BEOS__ || defined __CYGWIN__ || defined __MINGW32__ ++#if defined __NetBSD__ || defined __BEOS__ || defined __CYGWIN__ + /* Don't break __attribute__((format(printf,M,N))). + This redefinition is only possible because the libc in NetBSD, Cygwin, + mingw does not have a function __printf__. */ +--- gettext-runtime/intl/libgnuintl.h.in ++++ gettext-runtime/intl/libgnuintl.h.in +@@ -330,7 +330,7 @@ + + #if !(defined printf && defined _GL_STDIO_H) /* don't override gnulib */ + #undef printf +-#if defined __NetBSD__ || defined __BEOS__ || defined __CYGWIN__ || defined __MINGW32__ ++#if defined __NetBSD__ || defined __BEOS__ || defined __CYGWIN__ + /* Don't break __attribute__((format(printf,M,N))). + This redefinition is only possible because the libc in NetBSD, Cygwin, + mingw does not have a function __printf__. +---- gettext-tools/gnulib-lib/clean-temp.c ++++ gettext-tools/gnulib-lib/clean-temp.c +@@ -66,9 +66,11 @@ + # endif + #endif + ++#ifndef _WIN64 + #ifndef uintptr_t + # define uintptr_t unsigned long + #endif ++#endif + + #if !GNULIB_FCNTL_SAFER + /* The results of open() in this file are not used with fchdir, +--- gettext-tools/gnulib-lib/fstrcmp.c ++++ gettext-tools/gnulib-lib/fstrcmp.c +@@ -55,9 +55,11 @@ + #include "minmax.h" + #include "xalloc.h" + ++#ifndef _WIN64 + #ifndef uintptr_t + # define uintptr_t unsigned long + #endif ++#endif + + + #define ELEMENT char +--- gettext-tools/gnulib-lib/gl_array_list.c ++++ gettext-tools/gnulib-lib/gl_array_list.c +@@ -55,9 +55,11 @@ + /* Checked size_t computations. */ + #include "xsize.h" + ++#ifndef _WIN64 + #ifndef uintptr_t + # define uintptr_t unsigned long + #endif ++#endif + + /* -------------------------- gl_list_t Data Type -------------------------- */ + +--- gettext-tools/gnulib-lib/gl_linkedhash_list.c ++++ gettext-tools/gnulib-lib/gl_linkedhash_list.c +@@ -55,9 +55,11 @@ + + #include "xsize.h" + ++#ifndef _WIN64 + #ifndef uintptr_t + # define uintptr_t unsigned long + #endif ++#endif + + #define WITH_HASHTABLE 1 + +--- gettext-tools/gnulib-lib/stdio.in.h ++++ gettext-tools/gnulib-lib/stdio.in.h +@@ -642,10 +642,6 @@ + # if (@GNULIB_PRINTF_POSIX@ && @REPLACE_PRINTF@) \ + || (@GNULIB_PRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@) + # if defined __GNUC__ +-# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +-/* Don't break __attribute__((format(printf,M,N))). */ +-# define printf __printf__ +-# endif + _GL_FUNCDECL_RPL_1 (__printf__, int, + (const char *format, ...) + __asm__ (@ASM_SYMBOL_PREFIX@ +--- gettext-tools/gnulib-lib/tempname.c ++++ gettext-tools/gnulib-lib/tempname.c +@@ -54,6 +54,10 @@ + #include + #include + ++#ifdef _WIN32 ++# include ++#endif ++ + #include + + #if _LIBC +@@ -73,6 +73,10 @@ + # define __xstat64(version, file, buf) stat (file, buf) + #endif + ++#ifdef _WIN32 ++# define mkdir(path,mode) _mkdir(path) ++#endif ++ + #if ! (HAVE___SECURE_GETENV || _LIBC) + # define __secure_getenv getenv + #endif +--- gettext-tools/src/write-java.c ++++ gettext-tools/src/write-java.c +@@ -30,6 +30,10 @@ + #include + #include + ++#ifdef _WIN32 ++# include ++#endif ++ + #include + #if !defined S_ISDIR && defined S_IFDIR + # define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) +@@ -53,6 +53,10 @@ + # define S_IXUSR 00100 + #endif + ++#ifdef _WIN32 ++# define mkdir(path,mode) _mkdir(path) ++#endif ++ + #include "c-ctype.h" + #include "error.h" + #include "xerror.h" +--- gettext-tools/src/write-csharp.c ++++ gettext-tools/src/write-csharp.c +@@ -29,6 +29,10 @@ + #include + #include + ++#ifdef _WIN32 ++# include ++#endif ++ + #include + #if !defined S_ISDIR && defined S_IFDIR + # define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) +@@ -70,6 +70,10 @@ + # define S_IXOTH (S_IXUSR >> 6) + #endif + ++#ifdef _WIN32 ++# define mkdir(path,mode) _mkdir(path) ++#endif ++ + #include "c-ctype.h" + #include "relocatable.h" + #include "error.h" +--- gettext-tools/woe32dll/export.h ++++ gettext-tools/woe32dll/export.h +@@ -90,7 +90,11 @@ + --export-all-symbols is used. */ + + /* IMP(x) is a symbol that contains the address of x. */ ++#ifdef _WIN64 ++#define IMP(x) __imp_##x ++#else + #define IMP(x) _imp__##x ++#endif + + /* Ensure that the variable x is exported from the library, and that a + pseudo-variable IMP(x) is available. */ diff --git a/libs/gettext/include32/autosprintf.h b/libs/gettext/include32/autosprintf.h new file mode 100644 index 000000000..f447391b0 --- /dev/null +++ b/libs/gettext/include32/autosprintf.h @@ -0,0 +1,66 @@ +/* Class autosprintf - formatted output to an ostream. + Copyright (C) 2002 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#ifndef _AUTOSPRINTF_H +#define _AUTOSPRINTF_H + +#ifndef __attribute__ +/* This feature is available in gcc versions 2.5 and later. */ +# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__ +# define __attribute__(Spec) /* empty */ +# endif +/* The __-protected variants of `format' and `printf' attributes + are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */ +# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) +# define __format__ format +# define __printf__ printf +# endif +#endif + +#include +#include + +namespace gnu +{ + /* A temporary object, usually allocated on the stack, representing + the result of an asprintf() call. */ + class autosprintf + { + public: + /* Constructor: takes a format string and the printf arguments. */ + autosprintf (const char *format, ...) + __attribute__ ((__format__ (__printf__, 2, 3))); + /* Copy constructor. */ + autosprintf (const autosprintf& src); + /* Destructor: frees the temporarily allocated string. */ + ~autosprintf (); + /* Conversion to string. */ + operator char * () const; + operator std::string () const; + /* Output to an ostream. */ + friend inline std::ostream& operator<< (std::ostream& stream, const autosprintf& tmp) + { + stream << (tmp.str ? tmp.str : "(error in autosprintf)"); + return stream; + } + private: + char *str; + }; +} + +#endif /* _AUTOSPRINTF_H */ diff --git a/libs/gettext/include32/gettext-po.h b/libs/gettext/include32/gettext-po.h new file mode 100644 index 000000000..091ad86fa --- /dev/null +++ b/libs/gettext/include32/gettext-po.h @@ -0,0 +1,357 @@ +/* Public API for GNU gettext PO files - contained in libgettextpo. + Copyright (C) 2003-2008, 2010 Free Software Foundation, Inc. + Written by Bruno Haible , 2003. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#ifndef _GETTEXT_PO_H +#define _GETTEXT_PO_H 1 + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +/* =========================== Meta Information ============================ */ + +/* Version number: (major<<16) + (minor<<8) + subminor */ +#define LIBGETTEXTPO_VERSION 0x001201 +extern __declspec (dllimport) int libgettextpo_version; + +/* ================================= Types ================================= */ + +/* A po_file_t represents the contents of a PO file. */ +typedef struct po_file *po_file_t; + +/* A po_message_iterator_t represents an iterator through a domain of a + PO file. */ +typedef struct po_message_iterator *po_message_iterator_t; + +/* A po_message_t represents a message in a PO file. */ +typedef struct po_message *po_message_t; + +/* A po_filepos_t represents a string's position within a source file. */ +typedef struct po_filepos *po_filepos_t; + +/* A po_error_handler handles error situations. */ +struct po_error_handler +{ + /* Signal an error. The error message is built from FORMAT and the following + arguments. ERRNUM, if nonzero, is an errno value. + Must increment the error_message_count variable declared in error.h. + Must not return if STATUS is nonzero. */ + void (*error) (int status, int errnum, + const char *format, ...) +#if ((__GNUC__ == 3 && __GNUC_MINOR__ >= 1) || __GNUC__ > 3) && !__STRICT_ANSI__ + __attribute__ ((__format__ (__printf__, 3, 4))) +#endif + ; + + /* Signal an error. The error message is built from FORMAT and the following + arguments. The error location is at FILENAME line LINENO. ERRNUM, if + nonzero, is an errno value. + Must increment the error_message_count variable declared in error.h. + Must not return if STATUS is nonzero. */ + void (*error_at_line) (int status, int errnum, + const char *filename, unsigned int lineno, + const char *format, ...) +#if ((__GNUC__ == 3 && __GNUC_MINOR__ >= 1) || __GNUC__ > 3) && !__STRICT_ANSI__ + __attribute__ ((__format__ (__printf__, 5, 6))) +#endif + ; + + /* Signal a multiline warning. The PREFIX applies to all lines of the + MESSAGE. Free the PREFIX and MESSAGE when done. */ + void (*multiline_warning) (char *prefix, char *message); + + /* Signal a multiline error. The PREFIX applies to all lines of the + MESSAGE. Free the PREFIX and MESSAGE when done. + Must increment the error_message_count variable declared in error.h if + PREFIX is non-NULL. */ + void (*multiline_error) (char *prefix, char *message); +}; +typedef const struct po_error_handler *po_error_handler_t; + +/* A po_xerror_handler handles warnings, error and fatal error situations. */ +#define PO_SEVERITY_WARNING 0 /* just a warning, tell the user */ +#define PO_SEVERITY_ERROR 1 /* an error, the operation cannot complete */ +#define PO_SEVERITY_FATAL_ERROR 2 /* an error, the operation must be aborted */ +struct po_xerror_handler +{ + /* Signal a problem of the given severity. + MESSAGE and/or FILENAME + LINENO indicate where the problem occurred. + If FILENAME is NULL, FILENAME and LINENO and COLUMN should be ignored. + If LINENO is (size_t)(-1), LINENO and COLUMN should be ignored. + If COLUMN is (size_t)(-1), it should be ignored. + MESSAGE_TEXT is the problem description (if MULTILINE_P is true, + multiple lines of text, each terminated with a newline, otherwise + usually a single line). + Must not return if SEVERITY is PO_SEVERITY_FATAL_ERROR. */ + void (*xerror) (int severity, + po_message_t message, + const char *filename, size_t lineno, size_t column, + int multiline_p, const char *message_text); + /* Signal a problem that refers to two messages. + Similar to two calls to xerror. + If possible, a "..." can be appended to MESSAGE_TEXT1 and prepended to + MESSAGE_TEXT2. */ + void (*xerror2) (int severity, + po_message_t message1, + const char *filename1, size_t lineno1, size_t column1, + int multiline_p1, const char *message_text1, + po_message_t message2, + const char *filename2, size_t lineno2, size_t column2, + int multiline_p2, const char *message_text2); +}; +typedef const struct po_xerror_handler *po_xerror_handler_t; + +/* Memory allocation: + The memory allocations performed by these functions use xmalloc(), + therefore will cause a program exit if memory is exhausted. + The memory allocated by po_file_read, and implicitly returned through + the po_message_* functions, lasts until freed with po_file_free. */ + + +/* ============================= po_file_t API ============================= */ + +/* Create an empty PO file representation in memory. */ +extern po_file_t po_file_create (void); + +/* Read a PO file into memory. + Return its contents. Upon failure, return NULL and set errno. */ +#define po_file_read po_file_read_v3 +extern po_file_t po_file_read (const char *filename, + po_xerror_handler_t handler); + +/* Write an in-memory PO file to a file. + Upon failure, return NULL and set errno. */ +#define po_file_write po_file_write_v2 +extern po_file_t po_file_write (po_file_t file, const char *filename, + po_xerror_handler_t handler); + +/* Free a PO file from memory. */ +extern void po_file_free (po_file_t file); + +/* Return the names of the domains covered by a PO file in memory. */ +extern const char * const * po_file_domains (po_file_t file); + + +/* =========================== Header entry API ============================ */ + +/* Return the header entry of a domain of a PO file in memory. + The domain NULL denotes the default domain. + Return NULL if there is no header entry. */ +extern const char * po_file_domain_header (po_file_t file, const char *domain); + +/* Return the value of a field in a header entry. + The return value is either a freshly allocated string, to be freed by the + caller, or NULL. */ +extern char * po_header_field (const char *header, const char *field); + +/* Return the header entry with a given field set to a given value. The field + is added if necessary. + The return value is a freshly allocated string. */ +extern char * po_header_set_field (const char *header, const char *field, const char *value); + + +/* ======================= po_message_iterator_t API ======================= */ + +/* Create an iterator for traversing a domain of a PO file in memory. + The domain NULL denotes the default domain. */ +extern po_message_iterator_t po_message_iterator (po_file_t file, const char *domain); + +/* Free an iterator. */ +extern void po_message_iterator_free (po_message_iterator_t iterator); + +/* Return the next message, and advance the iterator. + Return NULL at the end of the message list. */ +extern po_message_t po_next_message (po_message_iterator_t iterator); + +/* Insert a message in a PO file in memory, in the domain and at the position + indicated by the iterator. The iterator thereby advances past the freshly + inserted message. */ +extern void po_message_insert (po_message_iterator_t iterator, po_message_t message); + + +/* =========================== po_message_t API ============================ */ + +/* Return a freshly constructed message. + To finish initializing the message, you must set the msgid and msgstr. */ +extern po_message_t po_message_create (void); + +/* Return the context of a message, or NULL for a message not restricted to a + context. */ +extern const char * po_message_msgctxt (po_message_t message); + +/* Change the context of a message. NULL means a message not restricted to a + context. */ +extern void po_message_set_msgctxt (po_message_t message, const char *msgctxt); + +/* Return the msgid (untranslated English string) of a message. */ +extern const char * po_message_msgid (po_message_t message); + +/* Change the msgid (untranslated English string) of a message. */ +extern void po_message_set_msgid (po_message_t message, const char *msgid); + +/* Return the msgid_plural (untranslated English plural string) of a message, + or NULL for a message without plural. */ +extern const char * po_message_msgid_plural (po_message_t message); + +/* Change the msgid_plural (untranslated English plural string) of a message. + NULL means a message without plural. */ +extern void po_message_set_msgid_plural (po_message_t message, const char *msgid_plural); + +/* Return the msgstr (translation) of a message. + Return the empty string for an untranslated message. */ +extern const char * po_message_msgstr (po_message_t message); + +/* Change the msgstr (translation) of a message. + Use an empty string to denote an untranslated message. */ +extern void po_message_set_msgstr (po_message_t message, const char *msgstr); + +/* Return the msgstr[index] for a message with plural handling, or + NULL when the index is out of range or for a message without plural. */ +extern const char * po_message_msgstr_plural (po_message_t message, int index); + +/* Change the msgstr[index] for a message with plural handling. + Use a NULL value at the end to reduce the number of plural forms. */ +extern void po_message_set_msgstr_plural (po_message_t message, int index, const char *msgstr); + +/* Return the comments for a message. */ +extern const char * po_message_comments (po_message_t message); + +/* Change the comments for a message. + comments should be a multiline string, ending in a newline, or empty. */ +extern void po_message_set_comments (po_message_t message, const char *comments); + +/* Return the extracted comments for a message. */ +extern const char * po_message_extracted_comments (po_message_t message); + +/* Change the extracted comments for a message. + comments should be a multiline string, ending in a newline, or empty. */ +extern void po_message_set_extracted_comments (po_message_t message, const char *comments); + +/* Return the i-th file position for a message, or NULL if i is out of + range. */ +extern po_filepos_t po_message_filepos (po_message_t message, int i); + +/* Remove the i-th file position from a message. + The indices of all following file positions for the message are decremented + by one. */ +extern void po_message_remove_filepos (po_message_t message, int i); + +/* Add a file position to a message, if it is not already present for the + message. + file is the file name. + start_line is the line number where the string starts, or (size_t)(-1) if no + line number is available. */ +extern void po_message_add_filepos (po_message_t message, const char *file, size_t start_line); + +/* Return the previous context of a message, or NULL for none. */ +extern const char * po_message_prev_msgctxt (po_message_t message); + +/* Change the previous context of a message. NULL is allowed. */ +extern void po_message_set_prev_msgctxt (po_message_t message, const char *prev_msgctxt); + +/* Return the previous msgid (untranslated English string) of a message, or + NULL for none. */ +extern const char * po_message_prev_msgid (po_message_t message); + +/* Change the previous msgid (untranslated English string) of a message. + NULL is allowed. */ +extern void po_message_set_prev_msgid (po_message_t message, const char *prev_msgid); + +/* Return the previous msgid_plural (untranslated English plural string) of a + message, or NULL for none. */ +extern const char * po_message_prev_msgid_plural (po_message_t message); + +/* Change the previous msgid_plural (untranslated English plural string) of a + message. NULL is allowed. */ +extern void po_message_set_prev_msgid_plural (po_message_t message, const char *prev_msgid_plural); + +/* Return true if the message is marked obsolete. */ +extern int po_message_is_obsolete (po_message_t message); + +/* Change the obsolete mark of a message. */ +extern void po_message_set_obsolete (po_message_t message, int obsolete); + +/* Return true if the message is marked fuzzy. */ +extern int po_message_is_fuzzy (po_message_t message); + +/* Change the fuzzy mark of a message. */ +extern void po_message_set_fuzzy (po_message_t message, int fuzzy); + +/* Return true if the message is marked as being a format string of the given + type (e.g. "c-format"). */ +extern int po_message_is_format (po_message_t message, const char *format_type); + +/* Change the format string mark for a given type of a message. */ +extern void po_message_set_format (po_message_t message, const char *format_type, /*bool*/int value); + +/* If a numeric range of a message is set, return true and store the minimum + and maximum value in *MINP and *MAXP. */ +extern int po_message_is_range (po_message_t message, int *minp, int *maxp); + +/* Change the numeric range of a message. MIN and MAX must be non-negative, + with MIN < MAX. Use MIN = MAX = -1 to remove the numeric range of a + message. */ +extern void po_message_set_range (po_message_t message, int min, int max); + + +/* =========================== po_filepos_t API ============================ */ + +/* Return the file name. */ +extern const char * po_filepos_file (po_filepos_t filepos); + +/* Return the line number where the string starts, or (size_t)(-1) if no line + number is available. */ +extern size_t po_filepos_start_line (po_filepos_t filepos); + + +/* ============================ Format type API ============================= */ + +/* Return a NULL terminated array of the supported format types. */ +extern const char * const * po_format_list (void); + +/* Return the pretty name associated with a format type. + For example, for "csharp-format", return "C#". + Return NULL if the argument is not a supported format type. */ +extern const char * po_format_pretty_name (const char *format_type); + + +/* ============================= Checking API ============================== */ + +/* Test whether an entire file PO file is valid, like msgfmt does it. + If it is invalid, pass the reasons to the handler. */ +extern void po_file_check_all (po_file_t file, po_xerror_handler_t handler); + +/* Test a single message, to be inserted in a PO file in memory, like msgfmt + does it. If it is invalid, pass the reasons to the handler. The iterator + is not modified by this call; it only specifies the file and the domain. */ +extern void po_message_check_all (po_message_t message, po_message_iterator_t iterator, po_xerror_handler_t handler); + +/* Test whether the message translation is a valid format string if the message + is marked as being a format string. If it is invalid, pass the reasons to + the handler. */ +#define po_message_check_format po_message_check_format_v2 +extern void po_message_check_format (po_message_t message, po_xerror_handler_t handler); + + +#ifdef __cplusplus +} +#endif + +#endif /* _GETTEXT_PO_H */ diff --git a/libs/gettext/include32/libintl.h b/libs/gettext/include32/libintl.h new file mode 100644 index 000000000..a8e2d414b --- /dev/null +++ b/libs/gettext/include32/libintl.h @@ -0,0 +1,464 @@ +/* Message catalogs for internationalization. + Copyright (C) 1995-1997, 2000-2010 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#ifndef _LIBINTL_H +#define _LIBINTL_H 1 + +#include +#if (defined __APPLE__ && defined __MACH__) && 0 +# include +#endif + +/* The LC_MESSAGES locale category is the category used by the functions + gettext() and dgettext(). It is specified in POSIX, but not in ANSI C. + On systems that don't define it, use an arbitrary value instead. + On Solaris, defines __LOCALE_H (or _LOCALE_H in Solaris 2.5) + then includes (i.e. this file!) and then only defines + LC_MESSAGES. To avoid a redefinition warning, don't define LC_MESSAGES + in this case. */ +#if !defined LC_MESSAGES && !(defined __LOCALE_H || (defined _LOCALE_H && defined __sun)) +# define LC_MESSAGES 1729 +#endif + +/* We define an additional symbol to signal that we use the GNU + implementation of gettext. */ +#define __USE_GNU_GETTEXT 1 + +/* Provide information about the supported file formats. Returns the + maximum minor revision number supported for a given major revision. */ +#define __GNU_GETTEXT_SUPPORTED_REVISION(major) \ + ((major) == 0 || (major) == 1 ? 1 : -1) + +/* Resolve a platform specific conflict on DJGPP. GNU gettext takes + precedence over _conio_gettext. */ +#ifdef __DJGPP__ +# undef gettext +#endif + +#ifdef __cplusplus +extern "C" { +#endif + + +/* Version number: (major<<16) + (minor<<8) + subminor */ +#define LIBINTL_VERSION 0x001201 +extern int libintl_version; + + +/* We redirect the functions to those prefixed with "libintl_". This is + necessary, because some systems define gettext/textdomain/... in the C + library (namely, Solaris 2.4 and newer, and GNU libc 2.0 and newer). + If we used the unprefixed names, there would be cases where the + definition in the C library would override the one in the libintl.so + shared library. Recall that on ELF systems, the symbols are looked + up in the following order: + 1. in the executable, + 2. in the shared libraries specified on the link command line, in order, + 3. in the dependencies of the shared libraries specified on the link + command line, + 4. in the dlopen()ed shared libraries, in the order in which they were + dlopen()ed. + The definition in the C library would override the one in libintl.so if + either + * -lc is given on the link command line and -lintl isn't, or + * -lc is given on the link command line before -lintl, or + * libintl.so is a dependency of a dlopen()ed shared library but not + linked to the executable at link time. + Since Solaris gettext() behaves differently than GNU gettext(), this + would be unacceptable. + + The redirection happens by default through macros in C, so that &gettext + is independent of the compilation unit, but through inline functions in + C++, in order not to interfere with the name mangling of class fields or + class methods called 'gettext'. */ + +/* The user can define _INTL_REDIRECT_INLINE or _INTL_REDIRECT_MACROS. + If he doesn't, we choose the method. A third possible method is + _INTL_REDIRECT_ASM, supported only by GCC. */ +#if !(defined _INTL_REDIRECT_INLINE || defined _INTL_REDIRECT_MACROS) +# if defined __GNUC__ && __GNUC__ >= 2 && !(defined __APPLE_CC__ && __APPLE_CC__ > 1) && !defined __MINGW32__ && !(__GNUC__ == 2 && defined _AIX) && (defined __STDC__ || defined __cplusplus) +# define _INTL_REDIRECT_ASM +# else +# ifdef __cplusplus +# define _INTL_REDIRECT_INLINE +# else +# define _INTL_REDIRECT_MACROS +# endif +# endif +#endif +/* Auxiliary macros. */ +#ifdef _INTL_REDIRECT_ASM +# define _INTL_ASM(cname) __asm__ (_INTL_ASMNAME (__USER_LABEL_PREFIX__, #cname)) +# define _INTL_ASMNAME(prefix,cnamestring) _INTL_STRINGIFY (prefix) cnamestring +# define _INTL_STRINGIFY(prefix) #prefix +#else +# define _INTL_ASM(cname) +#endif + +/* _INTL_MAY_RETURN_STRING_ARG(n) declares that the given function may return + its n-th argument literally. This enables GCC to warn for example about + printf (gettext ("foo %y")). */ +#if defined __GNUC__ && __GNUC__ >= 3 && !(defined __APPLE_CC__ && __APPLE_CC__ > 1 && defined __cplusplus) +# define _INTL_MAY_RETURN_STRING_ARG(n) __attribute__ ((__format_arg__ (n))) +#else +# define _INTL_MAY_RETURN_STRING_ARG(n) +#endif + +/* Look up MSGID in the current default message catalog for the current + LC_MESSAGES locale. If not found, returns MSGID itself (the default + text). */ +#ifdef _INTL_REDIRECT_INLINE +extern char *libintl_gettext (const char *__msgid) + _INTL_MAY_RETURN_STRING_ARG (1); +static inline char *gettext (const char *__msgid) +{ + return libintl_gettext (__msgid); +} +#else +#ifdef _INTL_REDIRECT_MACROS +# define gettext libintl_gettext +#endif +extern char *gettext (const char *__msgid) + _INTL_ASM (libintl_gettext) + _INTL_MAY_RETURN_STRING_ARG (1); +#endif + +/* Look up MSGID in the DOMAINNAME message catalog for the current + LC_MESSAGES locale. */ +#ifdef _INTL_REDIRECT_INLINE +extern char *libintl_dgettext (const char *__domainname, const char *__msgid) + _INTL_MAY_RETURN_STRING_ARG (2); +static inline char *dgettext (const char *__domainname, const char *__msgid) +{ + return libintl_dgettext (__domainname, __msgid); +} +#else +#ifdef _INTL_REDIRECT_MACROS +# define dgettext libintl_dgettext +#endif +extern char *dgettext (const char *__domainname, const char *__msgid) + _INTL_ASM (libintl_dgettext) + _INTL_MAY_RETURN_STRING_ARG (2); +#endif + +/* Look up MSGID in the DOMAINNAME message catalog for the current CATEGORY + locale. */ +#ifdef _INTL_REDIRECT_INLINE +extern char *libintl_dcgettext (const char *__domainname, const char *__msgid, + int __category) + _INTL_MAY_RETURN_STRING_ARG (2); +static inline char *dcgettext (const char *__domainname, const char *__msgid, + int __category) +{ + return libintl_dcgettext (__domainname, __msgid, __category); +} +#else +#ifdef _INTL_REDIRECT_MACROS +# define dcgettext libintl_dcgettext +#endif +extern char *dcgettext (const char *__domainname, const char *__msgid, + int __category) + _INTL_ASM (libintl_dcgettext) + _INTL_MAY_RETURN_STRING_ARG (2); +#endif + + +/* Similar to `gettext' but select the plural form corresponding to the + number N. */ +#ifdef _INTL_REDIRECT_INLINE +extern char *libintl_ngettext (const char *__msgid1, const char *__msgid2, + unsigned long int __n) + _INTL_MAY_RETURN_STRING_ARG (1) _INTL_MAY_RETURN_STRING_ARG (2); +static inline char *ngettext (const char *__msgid1, const char *__msgid2, + unsigned long int __n) +{ + return libintl_ngettext (__msgid1, __msgid2, __n); +} +#else +#ifdef _INTL_REDIRECT_MACROS +# define ngettext libintl_ngettext +#endif +extern char *ngettext (const char *__msgid1, const char *__msgid2, + unsigned long int __n) + _INTL_ASM (libintl_ngettext) + _INTL_MAY_RETURN_STRING_ARG (1) _INTL_MAY_RETURN_STRING_ARG (2); +#endif + +/* Similar to `dgettext' but select the plural form corresponding to the + number N. */ +#ifdef _INTL_REDIRECT_INLINE +extern char *libintl_dngettext (const char *__domainname, const char *__msgid1, + const char *__msgid2, unsigned long int __n) + _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3); +static inline char *dngettext (const char *__domainname, const char *__msgid1, + const char *__msgid2, unsigned long int __n) +{ + return libintl_dngettext (__domainname, __msgid1, __msgid2, __n); +} +#else +#ifdef _INTL_REDIRECT_MACROS +# define dngettext libintl_dngettext +#endif +extern char *dngettext (const char *__domainname, + const char *__msgid1, const char *__msgid2, + unsigned long int __n) + _INTL_ASM (libintl_dngettext) + _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3); +#endif + +/* Similar to `dcgettext' but select the plural form corresponding to the + number N. */ +#ifdef _INTL_REDIRECT_INLINE +extern char *libintl_dcngettext (const char *__domainname, + const char *__msgid1, const char *__msgid2, + unsigned long int __n, int __category) + _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3); +static inline char *dcngettext (const char *__domainname, + const char *__msgid1, const char *__msgid2, + unsigned long int __n, int __category) +{ + return libintl_dcngettext (__domainname, __msgid1, __msgid2, __n, __category); +} +#else +#ifdef _INTL_REDIRECT_MACROS +# define dcngettext libintl_dcngettext +#endif +extern char *dcngettext (const char *__domainname, + const char *__msgid1, const char *__msgid2, + unsigned long int __n, int __category) + _INTL_ASM (libintl_dcngettext) + _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3); +#endif + + + +/* Set the current default message catalog to DOMAINNAME. + If DOMAINNAME is null, return the current default. + If DOMAINNAME is "", reset to the default of "messages". */ +#ifdef _INTL_REDIRECT_INLINE +extern char *libintl_textdomain (const char *__domainname); +static inline char *textdomain (const char *__domainname) +{ + return libintl_textdomain (__domainname); +} +#else +#ifdef _INTL_REDIRECT_MACROS +# define textdomain libintl_textdomain +#endif +extern char *textdomain (const char *__domainname) + _INTL_ASM (libintl_textdomain); +#endif + +/* Specify that the DOMAINNAME message catalog will be found + in DIRNAME rather than in the system locale data base. */ +#ifdef _INTL_REDIRECT_INLINE +extern char *libintl_bindtextdomain (const char *__domainname, + const char *__dirname); +static inline char *bindtextdomain (const char *__domainname, + const char *__dirname) +{ + return libintl_bindtextdomain (__domainname, __dirname); +} +#else +#ifdef _INTL_REDIRECT_MACROS +# define bindtextdomain libintl_bindtextdomain +#endif +extern char *bindtextdomain (const char *__domainname, const char *__dirname) + _INTL_ASM (libintl_bindtextdomain); +#endif + +/* Specify the character encoding in which the messages from the + DOMAINNAME message catalog will be returned. */ +#ifdef _INTL_REDIRECT_INLINE +extern char *libintl_bind_textdomain_codeset (const char *__domainname, + const char *__codeset); +static inline char *bind_textdomain_codeset (const char *__domainname, + const char *__codeset) +{ + return libintl_bind_textdomain_codeset (__domainname, __codeset); +} +#else +#ifdef _INTL_REDIRECT_MACROS +# define bind_textdomain_codeset libintl_bind_textdomain_codeset +#endif +extern char *bind_textdomain_codeset (const char *__domainname, + const char *__codeset) + _INTL_ASM (libintl_bind_textdomain_codeset); +#endif + + + +/* Support for format strings with positions in *printf(), following the + POSIX/XSI specification. + Note: These replacements for the *printf() functions are visible only + in source files that #include or #include "gettext.h". + Packages that use *printf() in source files that don't refer to _() + or gettext() but for which the format string could be the return value + of _() or gettext() need to add this #include. Oh well. */ + +#if !0 + +#include +#include + +/* Get va_list. */ +#if (defined __STDC__ && __STDC__) || defined __cplusplus || defined _MSC_VER +# include +#else +# include +#endif + +#if !(defined fprintf && defined _GL_STDIO_H) /* don't override gnulib */ +#undef fprintf +#define fprintf libintl_fprintf +extern int fprintf (FILE *, const char *, ...); +#endif +#if !(defined vfprintf && defined _GL_STDIO_H) /* don't override gnulib */ +#undef vfprintf +#define vfprintf libintl_vfprintf +extern int vfprintf (FILE *, const char *, va_list); +#endif + +#if !(defined printf && defined _GL_STDIO_H) /* don't override gnulib */ +#undef printf +#if defined __NetBSD__ || defined __BEOS__ || defined __CYGWIN__ || defined __MINGW32__ +/* Don't break __attribute__((format(printf,M,N))). + This redefinition is only possible because the libc in NetBSD, Cygwin, + mingw does not have a function __printf__. + Alternatively, we could have done this redirection only when compiling with + __GNUC__, together with a symbol redirection: + extern int printf (const char *, ...) + __asm__ (#__USER_LABEL_PREFIX__ "libintl_printf"); + But doing it now would introduce a binary incompatibility with already + distributed versions of libintl on these systems. */ +# define libintl_printf __printf__ +#endif +#define printf libintl_printf +extern int printf (const char *, ...); +#endif +#if !(defined vprintf && defined _GL_STDIO_H) /* don't override gnulib */ +#undef vprintf +#define vprintf libintl_vprintf +extern int vprintf (const char *, va_list); +#endif + +#if !(defined sprintf && defined _GL_STDIO_H) /* don't override gnulib */ +#undef sprintf +#define sprintf libintl_sprintf +extern int sprintf (char *, const char *, ...); +#endif +#if !(defined vsprintf && defined _GL_STDIO_H) /* don't override gnulib */ +#undef vsprintf +#define vsprintf libintl_vsprintf +extern int vsprintf (char *, const char *, va_list); +#endif + +#if 1 + +#if !(defined snprintf && defined _GL_STDIO_H) /* don't override gnulib */ +#undef snprintf +#define snprintf libintl_snprintf +extern int snprintf (char *, size_t, const char *, ...); +#endif +#if !(defined vsnprintf && defined _GL_STDIO_H) /* don't override gnulib */ +#undef vsnprintf +#define vsnprintf libintl_vsnprintf +extern int vsnprintf (char *, size_t, const char *, va_list); +#endif + +#endif + +#if 0 + +#if !(defined asprintf && defined _GL_STDIO_H) /* don't override gnulib */ +#undef asprintf +#define asprintf libintl_asprintf +extern int asprintf (char **, const char *, ...); +#endif +#if !(defined vasprintf && defined _GL_STDIO_H) /* don't override gnulib */ +#undef vasprintf +#define vasprintf libintl_vasprintf +extern int vasprintf (char **, const char *, va_list); +#endif + +#endif + +#if 0 + +#undef fwprintf +#define fwprintf libintl_fwprintf +extern int fwprintf (FILE *, const wchar_t *, ...); +#undef vfwprintf +#define vfwprintf libintl_vfwprintf +extern int vfwprintf (FILE *, const wchar_t *, va_list); + +#undef wprintf +#define wprintf libintl_wprintf +extern int wprintf (const wchar_t *, ...); +#undef vwprintf +#define vwprintf libintl_vwprintf +extern int vwprintf (const wchar_t *, va_list); + +#undef swprintf +#define swprintf libintl_swprintf +extern int swprintf (wchar_t *, size_t, const wchar_t *, ...); +#undef vswprintf +#define vswprintf libintl_vswprintf +extern int vswprintf (wchar_t *, size_t, const wchar_t *, va_list); + +#endif + +#endif + + +/* Support for the locale chosen by the user. */ +#if (defined __APPLE__ && defined __MACH__) || defined _WIN32 || defined __WIN32__ || defined __CYGWIN__ + +#undef setlocale +#define setlocale libintl_setlocale +extern char *setlocale (int, const char *); + +#if 0 + +#undef newlocale +#define newlocale libintl_newlocale +extern locale_t newlocale (int, const char *, locale_t); + +#endif + +#endif + + +/* Support for relocatable packages. */ + +/* Sets the original and the current installation prefix of the package. + Relocation simply replaces a pathname starting with the original prefix + by the corresponding pathname with the current prefix instead. Both + prefixes should be directory names without trailing slash (i.e. use "" + instead of "/"). */ +#define libintl_set_relocation_prefix libintl_set_relocation_prefix +extern void + libintl_set_relocation_prefix (const char *orig_prefix, + const char *curr_prefix); + + +#ifdef __cplusplus +} +#endif + +#endif /* libintl.h */ diff --git a/libs/gettext/include64/autosprintf.h b/libs/gettext/include64/autosprintf.h new file mode 100644 index 000000000..f447391b0 --- /dev/null +++ b/libs/gettext/include64/autosprintf.h @@ -0,0 +1,66 @@ +/* Class autosprintf - formatted output to an ostream. + Copyright (C) 2002 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#ifndef _AUTOSPRINTF_H +#define _AUTOSPRINTF_H + +#ifndef __attribute__ +/* This feature is available in gcc versions 2.5 and later. */ +# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__ +# define __attribute__(Spec) /* empty */ +# endif +/* The __-protected variants of `format' and `printf' attributes + are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */ +# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) +# define __format__ format +# define __printf__ printf +# endif +#endif + +#include +#include + +namespace gnu +{ + /* A temporary object, usually allocated on the stack, representing + the result of an asprintf() call. */ + class autosprintf + { + public: + /* Constructor: takes a format string and the printf arguments. */ + autosprintf (const char *format, ...) + __attribute__ ((__format__ (__printf__, 2, 3))); + /* Copy constructor. */ + autosprintf (const autosprintf& src); + /* Destructor: frees the temporarily allocated string. */ + ~autosprintf (); + /* Conversion to string. */ + operator char * () const; + operator std::string () const; + /* Output to an ostream. */ + friend inline std::ostream& operator<< (std::ostream& stream, const autosprintf& tmp) + { + stream << (tmp.str ? tmp.str : "(error in autosprintf)"); + return stream; + } + private: + char *str; + }; +} + +#endif /* _AUTOSPRINTF_H */ diff --git a/libs/gettext/include64/gettext-po.h b/libs/gettext/include64/gettext-po.h new file mode 100644 index 000000000..24fd8e90e --- /dev/null +++ b/libs/gettext/include64/gettext-po.h @@ -0,0 +1,357 @@ +/* Public API for GNU gettext PO files - contained in libgettextpo. + Copyright (C) 2003-2008, 2010 Free Software Foundation, Inc. + Written by Bruno Haible , 2003. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#ifndef _GETTEXT_PO_H +#define _GETTEXT_PO_H 1 + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +/* =========================== Meta Information ============================ */ + +/* Version number: (major<<16) + (minor<<8) + subminor */ +#define LIBGETTEXTPO_VERSION 0x001201 +extern int libgettextpo_version; + +/* ================================= Types ================================= */ + +/* A po_file_t represents the contents of a PO file. */ +typedef struct po_file *po_file_t; + +/* A po_message_iterator_t represents an iterator through a domain of a + PO file. */ +typedef struct po_message_iterator *po_message_iterator_t; + +/* A po_message_t represents a message in a PO file. */ +typedef struct po_message *po_message_t; + +/* A po_filepos_t represents a string's position within a source file. */ +typedef struct po_filepos *po_filepos_t; + +/* A po_error_handler handles error situations. */ +struct po_error_handler +{ + /* Signal an error. The error message is built from FORMAT and the following + arguments. ERRNUM, if nonzero, is an errno value. + Must increment the error_message_count variable declared in error.h. + Must not return if STATUS is nonzero. */ + void (*error) (int status, int errnum, + const char *format, ...) +#if ((__GNUC__ == 3 && __GNUC_MINOR__ >= 1) || __GNUC__ > 3) && !__STRICT_ANSI__ + __attribute__ ((__format__ (__printf__, 3, 4))) +#endif + ; + + /* Signal an error. The error message is built from FORMAT and the following + arguments. The error location is at FILENAME line LINENO. ERRNUM, if + nonzero, is an errno value. + Must increment the error_message_count variable declared in error.h. + Must not return if STATUS is nonzero. */ + void (*error_at_line) (int status, int errnum, + const char *filename, unsigned int lineno, + const char *format, ...) +#if ((__GNUC__ == 3 && __GNUC_MINOR__ >= 1) || __GNUC__ > 3) && !__STRICT_ANSI__ + __attribute__ ((__format__ (__printf__, 5, 6))) +#endif + ; + + /* Signal a multiline warning. The PREFIX applies to all lines of the + MESSAGE. Free the PREFIX and MESSAGE when done. */ + void (*multiline_warning) (char *prefix, char *message); + + /* Signal a multiline error. The PREFIX applies to all lines of the + MESSAGE. Free the PREFIX and MESSAGE when done. + Must increment the error_message_count variable declared in error.h if + PREFIX is non-NULL. */ + void (*multiline_error) (char *prefix, char *message); +}; +typedef const struct po_error_handler *po_error_handler_t; + +/* A po_xerror_handler handles warnings, error and fatal error situations. */ +#define PO_SEVERITY_WARNING 0 /* just a warning, tell the user */ +#define PO_SEVERITY_ERROR 1 /* an error, the operation cannot complete */ +#define PO_SEVERITY_FATAL_ERROR 2 /* an error, the operation must be aborted */ +struct po_xerror_handler +{ + /* Signal a problem of the given severity. + MESSAGE and/or FILENAME + LINENO indicate where the problem occurred. + If FILENAME is NULL, FILENAME and LINENO and COLUMN should be ignored. + If LINENO is (size_t)(-1), LINENO and COLUMN should be ignored. + If COLUMN is (size_t)(-1), it should be ignored. + MESSAGE_TEXT is the problem description (if MULTILINE_P is true, + multiple lines of text, each terminated with a newline, otherwise + usually a single line). + Must not return if SEVERITY is PO_SEVERITY_FATAL_ERROR. */ + void (*xerror) (int severity, + po_message_t message, + const char *filename, size_t lineno, size_t column, + int multiline_p, const char *message_text); + /* Signal a problem that refers to two messages. + Similar to two calls to xerror. + If possible, a "..." can be appended to MESSAGE_TEXT1 and prepended to + MESSAGE_TEXT2. */ + void (*xerror2) (int severity, + po_message_t message1, + const char *filename1, size_t lineno1, size_t column1, + int multiline_p1, const char *message_text1, + po_message_t message2, + const char *filename2, size_t lineno2, size_t column2, + int multiline_p2, const char *message_text2); +}; +typedef const struct po_xerror_handler *po_xerror_handler_t; + +/* Memory allocation: + The memory allocations performed by these functions use xmalloc(), + therefore will cause a program exit if memory is exhausted. + The memory allocated by po_file_read, and implicitly returned through + the po_message_* functions, lasts until freed with po_file_free. */ + + +/* ============================= po_file_t API ============================= */ + +/* Create an empty PO file representation in memory. */ +extern po_file_t po_file_create (void); + +/* Read a PO file into memory. + Return its contents. Upon failure, return NULL and set errno. */ +#define po_file_read po_file_read_v3 +extern po_file_t po_file_read (const char *filename, + po_xerror_handler_t handler); + +/* Write an in-memory PO file to a file. + Upon failure, return NULL and set errno. */ +#define po_file_write po_file_write_v2 +extern po_file_t po_file_write (po_file_t file, const char *filename, + po_xerror_handler_t handler); + +/* Free a PO file from memory. */ +extern void po_file_free (po_file_t file); + +/* Return the names of the domains covered by a PO file in memory. */ +extern const char * const * po_file_domains (po_file_t file); + + +/* =========================== Header entry API ============================ */ + +/* Return the header entry of a domain of a PO file in memory. + The domain NULL denotes the default domain. + Return NULL if there is no header entry. */ +extern const char * po_file_domain_header (po_file_t file, const char *domain); + +/* Return the value of a field in a header entry. + The return value is either a freshly allocated string, to be freed by the + caller, or NULL. */ +extern char * po_header_field (const char *header, const char *field); + +/* Return the header entry with a given field set to a given value. The field + is added if necessary. + The return value is a freshly allocated string. */ +extern char * po_header_set_field (const char *header, const char *field, const char *value); + + +/* ======================= po_message_iterator_t API ======================= */ + +/* Create an iterator for traversing a domain of a PO file in memory. + The domain NULL denotes the default domain. */ +extern po_message_iterator_t po_message_iterator (po_file_t file, const char *domain); + +/* Free an iterator. */ +extern void po_message_iterator_free (po_message_iterator_t iterator); + +/* Return the next message, and advance the iterator. + Return NULL at the end of the message list. */ +extern po_message_t po_next_message (po_message_iterator_t iterator); + +/* Insert a message in a PO file in memory, in the domain and at the position + indicated by the iterator. The iterator thereby advances past the freshly + inserted message. */ +extern void po_message_insert (po_message_iterator_t iterator, po_message_t message); + + +/* =========================== po_message_t API ============================ */ + +/* Return a freshly constructed message. + To finish initializing the message, you must set the msgid and msgstr. */ +extern po_message_t po_message_create (void); + +/* Return the context of a message, or NULL for a message not restricted to a + context. */ +extern const char * po_message_msgctxt (po_message_t message); + +/* Change the context of a message. NULL means a message not restricted to a + context. */ +extern void po_message_set_msgctxt (po_message_t message, const char *msgctxt); + +/* Return the msgid (untranslated English string) of a message. */ +extern const char * po_message_msgid (po_message_t message); + +/* Change the msgid (untranslated English string) of a message. */ +extern void po_message_set_msgid (po_message_t message, const char *msgid); + +/* Return the msgid_plural (untranslated English plural string) of a message, + or NULL for a message without plural. */ +extern const char * po_message_msgid_plural (po_message_t message); + +/* Change the msgid_plural (untranslated English plural string) of a message. + NULL means a message without plural. */ +extern void po_message_set_msgid_plural (po_message_t message, const char *msgid_plural); + +/* Return the msgstr (translation) of a message. + Return the empty string for an untranslated message. */ +extern const char * po_message_msgstr (po_message_t message); + +/* Change the msgstr (translation) of a message. + Use an empty string to denote an untranslated message. */ +extern void po_message_set_msgstr (po_message_t message, const char *msgstr); + +/* Return the msgstr[index] for a message with plural handling, or + NULL when the index is out of range or for a message without plural. */ +extern const char * po_message_msgstr_plural (po_message_t message, int index); + +/* Change the msgstr[index] for a message with plural handling. + Use a NULL value at the end to reduce the number of plural forms. */ +extern void po_message_set_msgstr_plural (po_message_t message, int index, const char *msgstr); + +/* Return the comments for a message. */ +extern const char * po_message_comments (po_message_t message); + +/* Change the comments for a message. + comments should be a multiline string, ending in a newline, or empty. */ +extern void po_message_set_comments (po_message_t message, const char *comments); + +/* Return the extracted comments for a message. */ +extern const char * po_message_extracted_comments (po_message_t message); + +/* Change the extracted comments for a message. + comments should be a multiline string, ending in a newline, or empty. */ +extern void po_message_set_extracted_comments (po_message_t message, const char *comments); + +/* Return the i-th file position for a message, or NULL if i is out of + range. */ +extern po_filepos_t po_message_filepos (po_message_t message, int i); + +/* Remove the i-th file position from a message. + The indices of all following file positions for the message are decremented + by one. */ +extern void po_message_remove_filepos (po_message_t message, int i); + +/* Add a file position to a message, if it is not already present for the + message. + file is the file name. + start_line is the line number where the string starts, or (size_t)(-1) if no + line number is available. */ +extern void po_message_add_filepos (po_message_t message, const char *file, size_t start_line); + +/* Return the previous context of a message, or NULL for none. */ +extern const char * po_message_prev_msgctxt (po_message_t message); + +/* Change the previous context of a message. NULL is allowed. */ +extern void po_message_set_prev_msgctxt (po_message_t message, const char *prev_msgctxt); + +/* Return the previous msgid (untranslated English string) of a message, or + NULL for none. */ +extern const char * po_message_prev_msgid (po_message_t message); + +/* Change the previous msgid (untranslated English string) of a message. + NULL is allowed. */ +extern void po_message_set_prev_msgid (po_message_t message, const char *prev_msgid); + +/* Return the previous msgid_plural (untranslated English plural string) of a + message, or NULL for none. */ +extern const char * po_message_prev_msgid_plural (po_message_t message); + +/* Change the previous msgid_plural (untranslated English plural string) of a + message. NULL is allowed. */ +extern void po_message_set_prev_msgid_plural (po_message_t message, const char *prev_msgid_plural); + +/* Return true if the message is marked obsolete. */ +extern int po_message_is_obsolete (po_message_t message); + +/* Change the obsolete mark of a message. */ +extern void po_message_set_obsolete (po_message_t message, int obsolete); + +/* Return true if the message is marked fuzzy. */ +extern int po_message_is_fuzzy (po_message_t message); + +/* Change the fuzzy mark of a message. */ +extern void po_message_set_fuzzy (po_message_t message, int fuzzy); + +/* Return true if the message is marked as being a format string of the given + type (e.g. "c-format"). */ +extern int po_message_is_format (po_message_t message, const char *format_type); + +/* Change the format string mark for a given type of a message. */ +extern void po_message_set_format (po_message_t message, const char *format_type, /*bool*/int value); + +/* If a numeric range of a message is set, return true and store the minimum + and maximum value in *MINP and *MAXP. */ +extern int po_message_is_range (po_message_t message, int *minp, int *maxp); + +/* Change the numeric range of a message. MIN and MAX must be non-negative, + with MIN < MAX. Use MIN = MAX = -1 to remove the numeric range of a + message. */ +extern void po_message_set_range (po_message_t message, int min, int max); + + +/* =========================== po_filepos_t API ============================ */ + +/* Return the file name. */ +extern const char * po_filepos_file (po_filepos_t filepos); + +/* Return the line number where the string starts, or (size_t)(-1) if no line + number is available. */ +extern size_t po_filepos_start_line (po_filepos_t filepos); + + +/* ============================ Format type API ============================= */ + +/* Return a NULL terminated array of the supported format types. */ +extern const char * const * po_format_list (void); + +/* Return the pretty name associated with a format type. + For example, for "csharp-format", return "C#". + Return NULL if the argument is not a supported format type. */ +extern const char * po_format_pretty_name (const char *format_type); + + +/* ============================= Checking API ============================== */ + +/* Test whether an entire file PO file is valid, like msgfmt does it. + If it is invalid, pass the reasons to the handler. */ +extern void po_file_check_all (po_file_t file, po_xerror_handler_t handler); + +/* Test a single message, to be inserted in a PO file in memory, like msgfmt + does it. If it is invalid, pass the reasons to the handler. The iterator + is not modified by this call; it only specifies the file and the domain. */ +extern void po_message_check_all (po_message_t message, po_message_iterator_t iterator, po_xerror_handler_t handler); + +/* Test whether the message translation is a valid format string if the message + is marked as being a format string. If it is invalid, pass the reasons to + the handler. */ +#define po_message_check_format po_message_check_format_v2 +extern void po_message_check_format (po_message_t message, po_xerror_handler_t handler); + + +#ifdef __cplusplus +} +#endif + +#endif /* _GETTEXT_PO_H */ diff --git a/libs/gettext/include64/libintl.h b/libs/gettext/include64/libintl.h new file mode 100644 index 000000000..a8e2d414b --- /dev/null +++ b/libs/gettext/include64/libintl.h @@ -0,0 +1,464 @@ +/* Message catalogs for internationalization. + Copyright (C) 1995-1997, 2000-2010 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#ifndef _LIBINTL_H +#define _LIBINTL_H 1 + +#include +#if (defined __APPLE__ && defined __MACH__) && 0 +# include +#endif + +/* The LC_MESSAGES locale category is the category used by the functions + gettext() and dgettext(). It is specified in POSIX, but not in ANSI C. + On systems that don't define it, use an arbitrary value instead. + On Solaris, defines __LOCALE_H (or _LOCALE_H in Solaris 2.5) + then includes (i.e. this file!) and then only defines + LC_MESSAGES. To avoid a redefinition warning, don't define LC_MESSAGES + in this case. */ +#if !defined LC_MESSAGES && !(defined __LOCALE_H || (defined _LOCALE_H && defined __sun)) +# define LC_MESSAGES 1729 +#endif + +/* We define an additional symbol to signal that we use the GNU + implementation of gettext. */ +#define __USE_GNU_GETTEXT 1 + +/* Provide information about the supported file formats. Returns the + maximum minor revision number supported for a given major revision. */ +#define __GNU_GETTEXT_SUPPORTED_REVISION(major) \ + ((major) == 0 || (major) == 1 ? 1 : -1) + +/* Resolve a platform specific conflict on DJGPP. GNU gettext takes + precedence over _conio_gettext. */ +#ifdef __DJGPP__ +# undef gettext +#endif + +#ifdef __cplusplus +extern "C" { +#endif + + +/* Version number: (major<<16) + (minor<<8) + subminor */ +#define LIBINTL_VERSION 0x001201 +extern int libintl_version; + + +/* We redirect the functions to those prefixed with "libintl_". This is + necessary, because some systems define gettext/textdomain/... in the C + library (namely, Solaris 2.4 and newer, and GNU libc 2.0 and newer). + If we used the unprefixed names, there would be cases where the + definition in the C library would override the one in the libintl.so + shared library. Recall that on ELF systems, the symbols are looked + up in the following order: + 1. in the executable, + 2. in the shared libraries specified on the link command line, in order, + 3. in the dependencies of the shared libraries specified on the link + command line, + 4. in the dlopen()ed shared libraries, in the order in which they were + dlopen()ed. + The definition in the C library would override the one in libintl.so if + either + * -lc is given on the link command line and -lintl isn't, or + * -lc is given on the link command line before -lintl, or + * libintl.so is a dependency of a dlopen()ed shared library but not + linked to the executable at link time. + Since Solaris gettext() behaves differently than GNU gettext(), this + would be unacceptable. + + The redirection happens by default through macros in C, so that &gettext + is independent of the compilation unit, but through inline functions in + C++, in order not to interfere with the name mangling of class fields or + class methods called 'gettext'. */ + +/* The user can define _INTL_REDIRECT_INLINE or _INTL_REDIRECT_MACROS. + If he doesn't, we choose the method. A third possible method is + _INTL_REDIRECT_ASM, supported only by GCC. */ +#if !(defined _INTL_REDIRECT_INLINE || defined _INTL_REDIRECT_MACROS) +# if defined __GNUC__ && __GNUC__ >= 2 && !(defined __APPLE_CC__ && __APPLE_CC__ > 1) && !defined __MINGW32__ && !(__GNUC__ == 2 && defined _AIX) && (defined __STDC__ || defined __cplusplus) +# define _INTL_REDIRECT_ASM +# else +# ifdef __cplusplus +# define _INTL_REDIRECT_INLINE +# else +# define _INTL_REDIRECT_MACROS +# endif +# endif +#endif +/* Auxiliary macros. */ +#ifdef _INTL_REDIRECT_ASM +# define _INTL_ASM(cname) __asm__ (_INTL_ASMNAME (__USER_LABEL_PREFIX__, #cname)) +# define _INTL_ASMNAME(prefix,cnamestring) _INTL_STRINGIFY (prefix) cnamestring +# define _INTL_STRINGIFY(prefix) #prefix +#else +# define _INTL_ASM(cname) +#endif + +/* _INTL_MAY_RETURN_STRING_ARG(n) declares that the given function may return + its n-th argument literally. This enables GCC to warn for example about + printf (gettext ("foo %y")). */ +#if defined __GNUC__ && __GNUC__ >= 3 && !(defined __APPLE_CC__ && __APPLE_CC__ > 1 && defined __cplusplus) +# define _INTL_MAY_RETURN_STRING_ARG(n) __attribute__ ((__format_arg__ (n))) +#else +# define _INTL_MAY_RETURN_STRING_ARG(n) +#endif + +/* Look up MSGID in the current default message catalog for the current + LC_MESSAGES locale. If not found, returns MSGID itself (the default + text). */ +#ifdef _INTL_REDIRECT_INLINE +extern char *libintl_gettext (const char *__msgid) + _INTL_MAY_RETURN_STRING_ARG (1); +static inline char *gettext (const char *__msgid) +{ + return libintl_gettext (__msgid); +} +#else +#ifdef _INTL_REDIRECT_MACROS +# define gettext libintl_gettext +#endif +extern char *gettext (const char *__msgid) + _INTL_ASM (libintl_gettext) + _INTL_MAY_RETURN_STRING_ARG (1); +#endif + +/* Look up MSGID in the DOMAINNAME message catalog for the current + LC_MESSAGES locale. */ +#ifdef _INTL_REDIRECT_INLINE +extern char *libintl_dgettext (const char *__domainname, const char *__msgid) + _INTL_MAY_RETURN_STRING_ARG (2); +static inline char *dgettext (const char *__domainname, const char *__msgid) +{ + return libintl_dgettext (__domainname, __msgid); +} +#else +#ifdef _INTL_REDIRECT_MACROS +# define dgettext libintl_dgettext +#endif +extern char *dgettext (const char *__domainname, const char *__msgid) + _INTL_ASM (libintl_dgettext) + _INTL_MAY_RETURN_STRING_ARG (2); +#endif + +/* Look up MSGID in the DOMAINNAME message catalog for the current CATEGORY + locale. */ +#ifdef _INTL_REDIRECT_INLINE +extern char *libintl_dcgettext (const char *__domainname, const char *__msgid, + int __category) + _INTL_MAY_RETURN_STRING_ARG (2); +static inline char *dcgettext (const char *__domainname, const char *__msgid, + int __category) +{ + return libintl_dcgettext (__domainname, __msgid, __category); +} +#else +#ifdef _INTL_REDIRECT_MACROS +# define dcgettext libintl_dcgettext +#endif +extern char *dcgettext (const char *__domainname, const char *__msgid, + int __category) + _INTL_ASM (libintl_dcgettext) + _INTL_MAY_RETURN_STRING_ARG (2); +#endif + + +/* Similar to `gettext' but select the plural form corresponding to the + number N. */ +#ifdef _INTL_REDIRECT_INLINE +extern char *libintl_ngettext (const char *__msgid1, const char *__msgid2, + unsigned long int __n) + _INTL_MAY_RETURN_STRING_ARG (1) _INTL_MAY_RETURN_STRING_ARG (2); +static inline char *ngettext (const char *__msgid1, const char *__msgid2, + unsigned long int __n) +{ + return libintl_ngettext (__msgid1, __msgid2, __n); +} +#else +#ifdef _INTL_REDIRECT_MACROS +# define ngettext libintl_ngettext +#endif +extern char *ngettext (const char *__msgid1, const char *__msgid2, + unsigned long int __n) + _INTL_ASM (libintl_ngettext) + _INTL_MAY_RETURN_STRING_ARG (1) _INTL_MAY_RETURN_STRING_ARG (2); +#endif + +/* Similar to `dgettext' but select the plural form corresponding to the + number N. */ +#ifdef _INTL_REDIRECT_INLINE +extern char *libintl_dngettext (const char *__domainname, const char *__msgid1, + const char *__msgid2, unsigned long int __n) + _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3); +static inline char *dngettext (const char *__domainname, const char *__msgid1, + const char *__msgid2, unsigned long int __n) +{ + return libintl_dngettext (__domainname, __msgid1, __msgid2, __n); +} +#else +#ifdef _INTL_REDIRECT_MACROS +# define dngettext libintl_dngettext +#endif +extern char *dngettext (const char *__domainname, + const char *__msgid1, const char *__msgid2, + unsigned long int __n) + _INTL_ASM (libintl_dngettext) + _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3); +#endif + +/* Similar to `dcgettext' but select the plural form corresponding to the + number N. */ +#ifdef _INTL_REDIRECT_INLINE +extern char *libintl_dcngettext (const char *__domainname, + const char *__msgid1, const char *__msgid2, + unsigned long int __n, int __category) + _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3); +static inline char *dcngettext (const char *__domainname, + const char *__msgid1, const char *__msgid2, + unsigned long int __n, int __category) +{ + return libintl_dcngettext (__domainname, __msgid1, __msgid2, __n, __category); +} +#else +#ifdef _INTL_REDIRECT_MACROS +# define dcngettext libintl_dcngettext +#endif +extern char *dcngettext (const char *__domainname, + const char *__msgid1, const char *__msgid2, + unsigned long int __n, int __category) + _INTL_ASM (libintl_dcngettext) + _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3); +#endif + + + +/* Set the current default message catalog to DOMAINNAME. + If DOMAINNAME is null, return the current default. + If DOMAINNAME is "", reset to the default of "messages". */ +#ifdef _INTL_REDIRECT_INLINE +extern char *libintl_textdomain (const char *__domainname); +static inline char *textdomain (const char *__domainname) +{ + return libintl_textdomain (__domainname); +} +#else +#ifdef _INTL_REDIRECT_MACROS +# define textdomain libintl_textdomain +#endif +extern char *textdomain (const char *__domainname) + _INTL_ASM (libintl_textdomain); +#endif + +/* Specify that the DOMAINNAME message catalog will be found + in DIRNAME rather than in the system locale data base. */ +#ifdef _INTL_REDIRECT_INLINE +extern char *libintl_bindtextdomain (const char *__domainname, + const char *__dirname); +static inline char *bindtextdomain (const char *__domainname, + const char *__dirname) +{ + return libintl_bindtextdomain (__domainname, __dirname); +} +#else +#ifdef _INTL_REDIRECT_MACROS +# define bindtextdomain libintl_bindtextdomain +#endif +extern char *bindtextdomain (const char *__domainname, const char *__dirname) + _INTL_ASM (libintl_bindtextdomain); +#endif + +/* Specify the character encoding in which the messages from the + DOMAINNAME message catalog will be returned. */ +#ifdef _INTL_REDIRECT_INLINE +extern char *libintl_bind_textdomain_codeset (const char *__domainname, + const char *__codeset); +static inline char *bind_textdomain_codeset (const char *__domainname, + const char *__codeset) +{ + return libintl_bind_textdomain_codeset (__domainname, __codeset); +} +#else +#ifdef _INTL_REDIRECT_MACROS +# define bind_textdomain_codeset libintl_bind_textdomain_codeset +#endif +extern char *bind_textdomain_codeset (const char *__domainname, + const char *__codeset) + _INTL_ASM (libintl_bind_textdomain_codeset); +#endif + + + +/* Support for format strings with positions in *printf(), following the + POSIX/XSI specification. + Note: These replacements for the *printf() functions are visible only + in source files that #include or #include "gettext.h". + Packages that use *printf() in source files that don't refer to _() + or gettext() but for which the format string could be the return value + of _() or gettext() need to add this #include. Oh well. */ + +#if !0 + +#include +#include + +/* Get va_list. */ +#if (defined __STDC__ && __STDC__) || defined __cplusplus || defined _MSC_VER +# include +#else +# include +#endif + +#if !(defined fprintf && defined _GL_STDIO_H) /* don't override gnulib */ +#undef fprintf +#define fprintf libintl_fprintf +extern int fprintf (FILE *, const char *, ...); +#endif +#if !(defined vfprintf && defined _GL_STDIO_H) /* don't override gnulib */ +#undef vfprintf +#define vfprintf libintl_vfprintf +extern int vfprintf (FILE *, const char *, va_list); +#endif + +#if !(defined printf && defined _GL_STDIO_H) /* don't override gnulib */ +#undef printf +#if defined __NetBSD__ || defined __BEOS__ || defined __CYGWIN__ || defined __MINGW32__ +/* Don't break __attribute__((format(printf,M,N))). + This redefinition is only possible because the libc in NetBSD, Cygwin, + mingw does not have a function __printf__. + Alternatively, we could have done this redirection only when compiling with + __GNUC__, together with a symbol redirection: + extern int printf (const char *, ...) + __asm__ (#__USER_LABEL_PREFIX__ "libintl_printf"); + But doing it now would introduce a binary incompatibility with already + distributed versions of libintl on these systems. */ +# define libintl_printf __printf__ +#endif +#define printf libintl_printf +extern int printf (const char *, ...); +#endif +#if !(defined vprintf && defined _GL_STDIO_H) /* don't override gnulib */ +#undef vprintf +#define vprintf libintl_vprintf +extern int vprintf (const char *, va_list); +#endif + +#if !(defined sprintf && defined _GL_STDIO_H) /* don't override gnulib */ +#undef sprintf +#define sprintf libintl_sprintf +extern int sprintf (char *, const char *, ...); +#endif +#if !(defined vsprintf && defined _GL_STDIO_H) /* don't override gnulib */ +#undef vsprintf +#define vsprintf libintl_vsprintf +extern int vsprintf (char *, const char *, va_list); +#endif + +#if 1 + +#if !(defined snprintf && defined _GL_STDIO_H) /* don't override gnulib */ +#undef snprintf +#define snprintf libintl_snprintf +extern int snprintf (char *, size_t, const char *, ...); +#endif +#if !(defined vsnprintf && defined _GL_STDIO_H) /* don't override gnulib */ +#undef vsnprintf +#define vsnprintf libintl_vsnprintf +extern int vsnprintf (char *, size_t, const char *, va_list); +#endif + +#endif + +#if 0 + +#if !(defined asprintf && defined _GL_STDIO_H) /* don't override gnulib */ +#undef asprintf +#define asprintf libintl_asprintf +extern int asprintf (char **, const char *, ...); +#endif +#if !(defined vasprintf && defined _GL_STDIO_H) /* don't override gnulib */ +#undef vasprintf +#define vasprintf libintl_vasprintf +extern int vasprintf (char **, const char *, va_list); +#endif + +#endif + +#if 0 + +#undef fwprintf +#define fwprintf libintl_fwprintf +extern int fwprintf (FILE *, const wchar_t *, ...); +#undef vfwprintf +#define vfwprintf libintl_vfwprintf +extern int vfwprintf (FILE *, const wchar_t *, va_list); + +#undef wprintf +#define wprintf libintl_wprintf +extern int wprintf (const wchar_t *, ...); +#undef vwprintf +#define vwprintf libintl_vwprintf +extern int vwprintf (const wchar_t *, va_list); + +#undef swprintf +#define swprintf libintl_swprintf +extern int swprintf (wchar_t *, size_t, const wchar_t *, ...); +#undef vswprintf +#define vswprintf libintl_vswprintf +extern int vswprintf (wchar_t *, size_t, const wchar_t *, va_list); + +#endif + +#endif + + +/* Support for the locale chosen by the user. */ +#if (defined __APPLE__ && defined __MACH__) || defined _WIN32 || defined __WIN32__ || defined __CYGWIN__ + +#undef setlocale +#define setlocale libintl_setlocale +extern char *setlocale (int, const char *); + +#if 0 + +#undef newlocale +#define newlocale libintl_newlocale +extern locale_t newlocale (int, const char *, locale_t); + +#endif + +#endif + + +/* Support for relocatable packages. */ + +/* Sets the original and the current installation prefix of the package. + Relocation simply replaces a pathname starting with the original prefix + by the corresponding pathname with the current prefix instead. Both + prefixes should be directory names without trailing slash (i.e. use "" + instead of "/"). */ +#define libintl_set_relocation_prefix libintl_set_relocation_prefix +extern void + libintl_set_relocation_prefix (const char *orig_prefix, + const char *curr_prefix); + + +#ifdef __cplusplus +} +#endif + +#endif /* libintl.h */ diff --git a/libs/gettext/lib32/gettext/hostname.exe b/libs/gettext/lib32/gettext/hostname.exe new file mode 100644 index 000000000..ec691522b Binary files /dev/null and b/libs/gettext/lib32/gettext/hostname.exe differ diff --git a/libs/gettext/lib32/gettext/project-id b/libs/gettext/lib32/gettext/project-id new file mode 100755 index 000000000..496f466c9 --- /dev/null +++ b/libs/gettext/lib32/gettext/project-id @@ -0,0 +1,86 @@ +#!/bin/sh +# Prints a package's identification PACKAGE VERSION or PACKAGE. +# +# Copyright (C) 2001-2003, 2005 Free Software Foundation, Inc. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +want_version="$1" + +# NLS nuisances: Letter ranges are different in the Estonian locale. +LC_ALL=C + +while true; do + if test -f configure; then + package=`(grep '^PACKAGE_NAME=' configure; grep '^ *PACKAGE=' configure) | grep -v '=[ ]*$' | sed -e '1q' | sed -e 's/^[^=]*=//' | sed -e "s/^'//" -e "s/'$//"` + case "$package" in + *[\"\$\`\{\}]*) + # Some packages (gcal) retrieve the package name dynamically. + package= + ;; + esac + if test -n "$package"; then + is_gnu=`LC_ALL=C grep "GNU $package" * 2>/dev/null | grep -v '^libtool:'` + if test -n "$is_gnu"; then + package="GNU $package" + fi + if test -n "$want_version"; then + version=`(grep '^PACKAGE_VERSION=' configure; grep '^ *VERSION=' configure) | grep -v '=[ ]*$' | sed -e '1q' | sed -e 's/^[^=]*=//' | sed -e "s/^'//" -e "s/'$//"` + case "$version" in + *[\"\$\`\{\}]*) + # Some packages (gcal, gcc, clisp) retrieve the version dynamically. + version= + ;; + esac + if test -n "$version"; then + echo "$package $version" + else + echo "$package" + fi + else + echo "$package" + fi + exit 0 + fi + fi + dir=`basename \`pwd\`` + case "$dir" in + i18n) + # This directory name, used in GNU make, is not the top level directory. + ;; + *[A-Za-z]*[0-9]*) + package=`echo "$dir" | sed -e 's/^\([^0-9]*\)[0-9].*$/\1/' -e 's/[-_]$//'` + if test -n "$want_version"; then + version=`echo "$dir" | sed -e 's/^[^0-9]*\([0-9].*\)$/\1/'` + echo "$package $version" + else + echo "$package" + fi + exit 0 + ;; + esac + # Go to parent directory + last=`/bin/pwd` + cd .. + curr=`/bin/pwd` + if test "$last" = "$curr"; then + # Oops, didn't find the package name. + if test -n "$want_version"; then + echo "PACKAGE VERSION" + else + echo "PACKAGE" + fi + exit 0 + fi +done diff --git a/libs/gettext/lib32/gettext/urlget.exe b/libs/gettext/lib32/gettext/urlget.exe new file mode 100644 index 000000000..8f4234b54 Binary files /dev/null and b/libs/gettext/lib32/gettext/urlget.exe differ diff --git a/libs/gettext/lib32/gettext/user-email b/libs/gettext/lib32/gettext/user-email new file mode 100755 index 000000000..ebcee4d11 --- /dev/null +++ b/libs/gettext/lib32/gettext/user-email @@ -0,0 +1,436 @@ +#!/bin/sh +# Prints the user's email address, with confirmation from the user. +# +# Copyright (C) 2001-2003, 2005 Free Software Foundation, Inc. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Prerequisites for using ${exec_prefix}/lib and ${datarootdir}/locale. +prefix="/usr/local/i686-w64-mingw32/stow/gettext-0.18.1.1" +exec_prefix="${prefix}" +datarootdir="${prefix}/share" +datadir="${datarootdir}" +# Set variables libdir, localedir. +libdir="${exec_prefix}/lib" +localedir="${datarootdir}/locale" + +# Support for relocatability. +if test "no" = yes; then + orig_installdir="$libdir"/gettext # see Makefile.am's install rule + # Determine curr_installdir without caring for symlinked callers. + curr_installdir=`echo "$0" | sed -e 's,/[^/]*$,,'` + curr_installdir=`cd "$curr_installdir" && pwd` + # Compute the original/current installation prefixes by stripping the + # trailing directories off the original/current installation directories. + while true; do + orig_last=`echo "$orig_installdir" | sed -n -e 's,^.*/\([^/]*\)$,\1,p'` + curr_last=`echo "$curr_installdir" | sed -n -e 's,^.*/\([^/]*\)$,\1,p'` + if test -z "$orig_last" || test -z "$curr_last"; then + break + fi + if test "$orig_last" != "$curr_last"; then + break + fi + orig_installdir=`echo "$orig_installdir" | sed -e 's,/[^/]*$,,'` + curr_installdir=`echo "$curr_installdir" | sed -e 's,/[^/]*$,,'` + done + # Now relocate the directory variables that we use. + libdir=`echo "$libdir/" | sed -e "s%^${orig_installdir}/%${curr_installdir}/%" | sed -e 's,/$,,'` + localedir=`echo "$localedir/" | sed -e "s%^${orig_installdir}/%${curr_installdir}/%" | sed -e 's,/$,,'` +fi + +# Internationalization. +. gettext.sh +TEXTDOMAIN=gettext-tools +export TEXTDOMAIN +TEXTDOMAINDIR="$localedir" +export TEXTDOMAINDIR + +# Redirect fileno 3 to interactive I/O. +exec 3>/dev/tty + +# Output a prompt. +if test $# != 0; then + echo "$1" 1>&3 +fi + +# Find the user name on the local machine. +user=`id -u -n 2>/dev/null` +if test -z "$user"; then + user="$USER" + if test -z "$user"; then + user="$LOGNAME" + if test -z "$user"; then + user=unknown + fi + fi +fi + +# Find the hostname. +# hostname on some systems (SVR3.2, old Linux) returns a bogus exit status, +# so uname gets run too, so we keep only the first line of output. +#host=`(hostname || uname -n) 2>/dev/null | sed 1q` +host=`"$libdir"/gettext/hostname --short 2>/dev/null | sed 1q` + +# Find the hostname. +hostfqdn=`"$libdir"/gettext/hostname --fqdn 2>/dev/null | sed 1q` + +# Find a list of email addresses from various mailer configuration files. +# All mailers use configuration files under $HOME. We handle them in a +# last-modified - first-priority order. +cd $HOME +files="" + +# ----------------------- BEGIN MAILER SPECIFIC CODE ----------------------- + +# Mozilla Thunderbird addresses +files="$files .thunderbird/*/prefs.js" + +# Mozilla addresses +files="$files .mozilla/*/prefs.js" + +# Netscape 4 addresses +files="$files .netscape/liprefs.js .netscape/preferences.js" + +# Netscape 3 addresses +files="$files .netscape/preferences" + +# Emacs/XEmacs rmail, Emacs/XEmacs gnus, XEmacs vm addresses +# XEmacs mew addresses +files="$files .emacs .emacs.el" + +# KDE2 addresses +files="$files .kde2/share/config/emaildefaults" + +# KDE kmail addresses +files="$files .kde2/share/config/kmailrc" + +# GNOME evolution 2 addresses +files="$files .gconf/apps/evolution/mail/%gconf.xml" + +# GNOME evolution 1 addresses +files="$files evolution/config.xmldb" + +# GNOME balsa addresses +files="$files .gnome/balsa" + +# StarOffice and OpenOffice addresses +sed_dos2unix='s/\r$//' +sed_soffice51='s,StarOffice 5\.1=\(.*\)$,\1/sofficerc,p' +sed_soffice52='s,StarOffice 5\.2=\(.*\)$,\1/user/sofficerc,p' +sed_ooffice='s,^OpenOffice[^=]*=\(.*\)$,\1/user/config/registry/instance/org/openoffice/UserProfile.xml,p' +files="$files Office51/sofficerc Office52/user/sofficerc "`sed -n -e "$sed_dos2unix" -e "$sed_soffice51" -e "$sed_soffice52" -e "$sed_ooffice" .sversionrc 2>/dev/null | sed -e 's,^file://*,/,'` + +# mutt addresses +files="$files .muttrc" + +# pine addresses +files="$files .pinerc" + +# xfmail addresses +files="$files .xfmail/.xfmailrc" + +# tkrat addresses +files="$files .ratatosk/ratatoskrc" + +# ----------------------- END MAILER SPECIFIC CODE ----------------------- + +# Expand wildcards and remove nonexistent files from the list. +nfiles="" +for file in $files; do + if test -r "$file" && test ! -d "$file"; then + nfiles="$nfiles $file" + fi +done +files="$nfiles" + +addresses="" + +if test -n "$files"; then + + for file in `ls -t $files`; do + + case "$file" in + +# ----------------------- BEGIN MAILER SPECIFIC CODE ----------------------- + + # Mozilla and Mozilla Thunderbird addresses + .mozilla/*/prefs.js | .thunderbird/*/prefs.js) + addresses="$addresses "`grep -h '^user_pref("mail\.identity\..*\.useremail", ".*");$' $file 2>/dev/null | sed -e 's/^user_pref("mail\.identity\..*\.useremail", "\(.*\)");$/\1/'` + ;; + + # Netscape 4 addresses + .netscape/liprefs.js | .netscape/preferences.js) + addresses="$addresses "`grep -h '^user_pref("mail\.identity\.useremail", ".*");$' $file 2>/dev/null | sed -e 's/^user_pref("mail\.identity\.useremail", "\(.*\)");$/\1/'` + ;; + + # Netscape 3 addresses + .netscape/preferences) + addresses="$addresses "`grep -h '^EMAIL_ADDRESS:' $file 2>/dev/null | sed -e 's/^EMAIL_ADDRESS:[ ]*//'` + ;; + + .emacs | .emacs.el) + # Emacs/XEmacs rmail, Emacs/XEmacs gnus, XEmacs vm addresses + addresses="$addresses "`grep -h '[ (]user-mail-address "[^"]*"' $file 2>/dev/null | sed -e 's/^.*[ (]user-mail-address "\([^"]*\)".*$/\1/'` + # XEmacs mew addresses + domains=`grep -h '[ (]mew-mail-domain "[^"]*"' $file 2>/dev/null | sed -e 's/^.*[ (]mew-mail-domain "\([^"]*\)".*$/\1/'` + if test -n "$domains"; then + for domain in $domains; do + addresses="$addresses ${user}@$domain" + done + fi + ;; + + # KDE2 addresses + .kde2/share/config/emaildefaults) + addresses="$addresses "`grep -h '^EmailAddress=' $file 2>/dev/null | sed -e 's/^EmailAddress=//'` + ;; + + # KDE kmail addresses + .kde2/share/config/kmailrc) + addresses="$addresses "`grep -h '^Email Address=' $file 2>/dev/null | sed -e 's/^Email Address=//'` + ;; + + # GNOME evolution 2 addresses + .gconf/apps/evolution/mail/%gconf.xml) + sedexpr0='s,^.*<addr-spec>\(.*\)</addr-spec>.*$,\1,p' + addresses="$addresses "`sed -n -e "$sedexpr0" < $file` + ;; + + # GNOME evolution 1 addresses + evolution/config.xmldb) + sedexpr0='s/^.*\(.*\).*$,\1,p' $file 2>/dev/null` + ;; + + # StarOffice addresses + # Not a typo. They really write "Adress" with a single d. + # German orthography... + */sofficerc) + addresses="$addresses "`grep -h '^User-Adress=' $file 2>/dev/null | sed -e 's/#[^#]*$//' -e 's/^.*#//'` + ;; + + # mutt addresses + .muttrc) + mutt_addresses=`grep -h '^set from="[^"]*"[ ]*$' $file 2>/dev/null | sed -e 's/^set from="\([^"]*\)"[ ]*$/\1/'` + if test -n "$mutt_addresses"; then + addresses="$addresses $mutt_addresses" + else + # mutt uses $EMAIL as fallback. + if test -n "$EMAIL"; then + addresses="$addresses $EMAIL" + fi + fi + ;; + + # pine addresses + .pinerc) + domains=`grep -h '^user-domain=' $file 2>/dev/null | sed -e 's/^user-domain=//'` + if test -n "$domains"; then + for domain in $domains; do + addresses="$addresses ${user}@$domain" + done + else + # The use-only-domain-name option is only used if the user-domain option is not present. + domains=`grep -h '^use-only-domain-name=' $file 2>/dev/null | sed -e 's/^use-only-domain-name=//'` + if test "Yes" = "$domains"; then + addresses="$addresses ${user}@"`echo "$hostfqdn" | sed -e 's/^[^.]*\.//'` + fi + fi + ;; + + # xfmail addresses + .xfmail/.xfmailrc) + addresses="$addresses "`grep -h '^from=.*<.*>' $file 2>/dev/null | sed -e 's/^.*<\([^<>]*\)>.*$/\1/'` + ;; + + # tkrat addresses + .ratatosk/ratatoskrc) + domains=`grep -h '^set option(masquerade_as) ' $file 2>/dev/null | sed -e 's/^set option(masquerade_as) //'` + if test -n "$domains"; then + for domain in $domains; do + addresses="$addresses ${user}@$domain" + done + else + # The domain option is used only if the masquerade_as option is not present. + domains=`grep -h '^set option(domain) ' $file 2>/dev/null | sed -e 's/^set option(domain) //'` + if test -n "$domains"; then + for domain in $domains; do + addresses="$addresses ${user}@${host}.$domain" + done + fi + fi + ;; + +# ----------------------- END MAILER SPECIFIC CODE ----------------------- + + esac + + done + +fi + +# Some Debian systems have a file /etc/mailname. +if test -r /etc/mailname; then + hostmailname=`cat /etc/mailname` + if test -n "$hostmailname"; then + addresses="$addresses ${user}@$hostmailname" + fi +fi + +# SuSE Linux >= 8.0 systems have a file /etc/sysconfig/mail. +if test -r /etc/sysconfig/mail; then + hostmailname=`. /etc/sysconfig/mail && echo "$FROM_HEADER"` + if test -n "$hostmailname"; then + addresses="$addresses ${user}@$hostmailname" + fi +fi + +# elm has no user-defined addresses. +# mailx has no user-defined addresses. +# mh has no user-defined addresses. +# They use the system default. +addresses="$addresses ${user}@$hostfqdn" + +# Normalize addresses: remove addresses without @, lowercase the part after @, +# and remove duplicates. +lowercase_sed='{ +h +s/^[^@]*@\(.*\)$/\1/ +y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ +x +s/^\([^@]*\)@.*/\1@/ +G +s/\ +// +p +}' +naddresses="" +for addr in $addresses; do + case "$addr" in + "<"*">") addr=`echo "$addr" | sed -e 's/^$//'` ;; + esac + case "$addr" in + *@*) + addr=`echo "$addr" | sed -n -e "$lowercase_sed"` + case " $naddresses " in + *" $addr "*) ;; + *) naddresses="$naddresses $addr" ;; + esac + ;; + esac +done +addresses="$naddresses" + +# Now it's time to ask the user. +case "$addresses" in + " "*" "*) + # At least two addresses. + lines="" + i=0 + for addr in $addresses; do + i=`expr $i + 1` + lines="${lines}${i} ${addr} +" + done + while true; do + { gettext "Which is your email address?"; echo; } 1>&3 + echo "$lines" 1>&3 + { gettext "Please choose the number, or enter your email address."; echo; } 1>&3 + read answer < /dev/tty + case "$answer" in + *@*) ;; + [0-9]*) + i=0 + for addr in $addresses; do + i=`expr $i + 1` + if test "$i" = "$answer"; then + break 2 + fi + done + ;; + esac + case "$answer" in + "<"*">") answer=`echo "$answer" | sed -e 's/^$//'` ;; + esac + case "$answer" in + *" "*) { gettext "Invalid email address: invalid character."; echo; echo; } 1>&3 ; continue ;; + *@*.*) ;; + *@*) { gettext "Invalid email address: need a fully qualified host name or domain name."; echo; echo; } 1>&3 ; continue ;; + *) { gettext "Invalid email address: missing @"; echo; echo; } 1>&3 ; continue ;; + esac + addr=`echo "$answer" | sed -n -e "$lowercase_sed"` + break + done + ;; + " "*) + # One address. + while true; do + { gettext "Is the following your email address?"; echo; } 1>&3 + echo " $addresses" 1>&3 + { gettext "Please confirm by pressing Return, or enter your email address."; echo; } 1>&3 + read answer < /dev/tty + if test -z "$answer"; then + addr=`echo "$addresses" | sed -e 's/^ //'` + break + fi + case "$answer" in + "<"*">") answer=`echo "$answer" | sed -e 's/^$//'` ;; + esac + case "$answer" in + *" "*) { gettext "Invalid email address: invalid character."; echo; echo; } 1>&3 ; continue ;; + *@*.*) ;; + *@*) { gettext "Invalid email address: need a fully qualified host name or domain name."; echo; echo; } 1>&3 ; continue ;; + *) { gettext "Invalid email address: missing @"; echo; echo; } 1>&3 ; continue ;; + esac + addr=`echo "$answer" | sed -n -e "$lowercase_sed"` + break + done + ;; + "") + # No address. + { gettext "Couldn't find out about your email address."; echo; } 1>&3 + while true; do + { gettext "Please enter your email address."; echo; } 1>&3 + read answer < /dev/tty + case "$answer" in + "<"*">") answer=`echo "$answer" | sed -e 's/^$//'` ;; + esac + case "$answer" in + *" "*) { gettext "Invalid email address: invalid character."; echo; echo; } 1>&3 ; continue ;; + *@*.*) ;; + *@*) { gettext "Invalid email address: need a fully qualified host name or domain name."; echo; echo; } 1>&3 ; continue ;; + *) { gettext "Invalid email address: missing @"; echo; echo; } 1>&3 ; continue ;; + esac + addr=`echo "$answer" | sed -n -e "$lowercase_sed"` + break + done + ;; + *) echo "internal error" 1>&3 ; exit 1 ;; +esac + +# Print to standard output. +echo "$addr" diff --git a/libs/gettext/lib32/libasprintf.dll.a b/libs/gettext/lib32/libasprintf.dll.a new file mode 100644 index 000000000..d83727061 Binary files /dev/null and b/libs/gettext/lib32/libasprintf.dll.a differ diff --git a/libs/gettext/lib32/libgettextlib.dll.a b/libs/gettext/lib32/libgettextlib.dll.a new file mode 100644 index 000000000..5b1c93d8a Binary files /dev/null and b/libs/gettext/lib32/libgettextlib.dll.a differ diff --git a/libs/gettext/lib32/libgettextpo.dll.a b/libs/gettext/lib32/libgettextpo.dll.a new file mode 100644 index 000000000..b4e858aab Binary files /dev/null and b/libs/gettext/lib32/libgettextpo.dll.a differ diff --git a/libs/gettext/lib32/libgettextsrc.dll.a b/libs/gettext/lib32/libgettextsrc.dll.a new file mode 100644 index 000000000..83425c51f Binary files /dev/null and b/libs/gettext/lib32/libgettextsrc.dll.a differ diff --git a/libs/gettext/lib32/libintl.dll.a b/libs/gettext/lib32/libintl.dll.a new file mode 100644 index 000000000..9e595475f Binary files /dev/null and b/libs/gettext/lib32/libintl.dll.a differ diff --git a/libs/gettext/lib64/gettext/hostname.exe b/libs/gettext/lib64/gettext/hostname.exe new file mode 100644 index 000000000..afc31abd8 Binary files /dev/null and b/libs/gettext/lib64/gettext/hostname.exe differ diff --git a/libs/gettext/lib64/gettext/project-id b/libs/gettext/lib64/gettext/project-id new file mode 100755 index 000000000..496f466c9 --- /dev/null +++ b/libs/gettext/lib64/gettext/project-id @@ -0,0 +1,86 @@ +#!/bin/sh +# Prints a package's identification PACKAGE VERSION or PACKAGE. +# +# Copyright (C) 2001-2003, 2005 Free Software Foundation, Inc. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +want_version="$1" + +# NLS nuisances: Letter ranges are different in the Estonian locale. +LC_ALL=C + +while true; do + if test -f configure; then + package=`(grep '^PACKAGE_NAME=' configure; grep '^ *PACKAGE=' configure) | grep -v '=[ ]*$' | sed -e '1q' | sed -e 's/^[^=]*=//' | sed -e "s/^'//" -e "s/'$//"` + case "$package" in + *[\"\$\`\{\}]*) + # Some packages (gcal) retrieve the package name dynamically. + package= + ;; + esac + if test -n "$package"; then + is_gnu=`LC_ALL=C grep "GNU $package" * 2>/dev/null | grep -v '^libtool:'` + if test -n "$is_gnu"; then + package="GNU $package" + fi + if test -n "$want_version"; then + version=`(grep '^PACKAGE_VERSION=' configure; grep '^ *VERSION=' configure) | grep -v '=[ ]*$' | sed -e '1q' | sed -e 's/^[^=]*=//' | sed -e "s/^'//" -e "s/'$//"` + case "$version" in + *[\"\$\`\{\}]*) + # Some packages (gcal, gcc, clisp) retrieve the version dynamically. + version= + ;; + esac + if test -n "$version"; then + echo "$package $version" + else + echo "$package" + fi + else + echo "$package" + fi + exit 0 + fi + fi + dir=`basename \`pwd\`` + case "$dir" in + i18n) + # This directory name, used in GNU make, is not the top level directory. + ;; + *[A-Za-z]*[0-9]*) + package=`echo "$dir" | sed -e 's/^\([^0-9]*\)[0-9].*$/\1/' -e 's/[-_]$//'` + if test -n "$want_version"; then + version=`echo "$dir" | sed -e 's/^[^0-9]*\([0-9].*\)$/\1/'` + echo "$package $version" + else + echo "$package" + fi + exit 0 + ;; + esac + # Go to parent directory + last=`/bin/pwd` + cd .. + curr=`/bin/pwd` + if test "$last" = "$curr"; then + # Oops, didn't find the package name. + if test -n "$want_version"; then + echo "PACKAGE VERSION" + else + echo "PACKAGE" + fi + exit 0 + fi +done diff --git a/libs/gettext/lib64/gettext/urlget.exe b/libs/gettext/lib64/gettext/urlget.exe new file mode 100644 index 000000000..8f1d6b405 Binary files /dev/null and b/libs/gettext/lib64/gettext/urlget.exe differ diff --git a/libs/gettext/lib64/gettext/user-email b/libs/gettext/lib64/gettext/user-email new file mode 100755 index 000000000..7d2d679bc --- /dev/null +++ b/libs/gettext/lib64/gettext/user-email @@ -0,0 +1,436 @@ +#!/bin/sh +# Prints the user's email address, with confirmation from the user. +# +# Copyright (C) 2001-2003, 2005 Free Software Foundation, Inc. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Prerequisites for using ${exec_prefix}/lib and ${datarootdir}/locale. +prefix="/usr/local/x86_64-w64-mingw32/stow/gettext-0.18.1.1" +exec_prefix="${prefix}" +datarootdir="${prefix}/share" +datadir="${datarootdir}" +# Set variables libdir, localedir. +libdir="${exec_prefix}/lib" +localedir="${datarootdir}/locale" + +# Support for relocatability. +if test "no" = yes; then + orig_installdir="$libdir"/gettext # see Makefile.am's install rule + # Determine curr_installdir without caring for symlinked callers. + curr_installdir=`echo "$0" | sed -e 's,/[^/]*$,,'` + curr_installdir=`cd "$curr_installdir" && pwd` + # Compute the original/current installation prefixes by stripping the + # trailing directories off the original/current installation directories. + while true; do + orig_last=`echo "$orig_installdir" | sed -n -e 's,^.*/\([^/]*\)$,\1,p'` + curr_last=`echo "$curr_installdir" | sed -n -e 's,^.*/\([^/]*\)$,\1,p'` + if test -z "$orig_last" || test -z "$curr_last"; then + break + fi + if test "$orig_last" != "$curr_last"; then + break + fi + orig_installdir=`echo "$orig_installdir" | sed -e 's,/[^/]*$,,'` + curr_installdir=`echo "$curr_installdir" | sed -e 's,/[^/]*$,,'` + done + # Now relocate the directory variables that we use. + libdir=`echo "$libdir/" | sed -e "s%^${orig_installdir}/%${curr_installdir}/%" | sed -e 's,/$,,'` + localedir=`echo "$localedir/" | sed -e "s%^${orig_installdir}/%${curr_installdir}/%" | sed -e 's,/$,,'` +fi + +# Internationalization. +. gettext.sh +TEXTDOMAIN=gettext-tools +export TEXTDOMAIN +TEXTDOMAINDIR="$localedir" +export TEXTDOMAINDIR + +# Redirect fileno 3 to interactive I/O. +exec 3>/dev/tty + +# Output a prompt. +if test $# != 0; then + echo "$1" 1>&3 +fi + +# Find the user name on the local machine. +user=`id -u -n 2>/dev/null` +if test -z "$user"; then + user="$USER" + if test -z "$user"; then + user="$LOGNAME" + if test -z "$user"; then + user=unknown + fi + fi +fi + +# Find the hostname. +# hostname on some systems (SVR3.2, old Linux) returns a bogus exit status, +# so uname gets run too, so we keep only the first line of output. +#host=`(hostname || uname -n) 2>/dev/null | sed 1q` +host=`"$libdir"/gettext/hostname --short 2>/dev/null | sed 1q` + +# Find the hostname. +hostfqdn=`"$libdir"/gettext/hostname --fqdn 2>/dev/null | sed 1q` + +# Find a list of email addresses from various mailer configuration files. +# All mailers use configuration files under $HOME. We handle them in a +# last-modified - first-priority order. +cd $HOME +files="" + +# ----------------------- BEGIN MAILER SPECIFIC CODE ----------------------- + +# Mozilla Thunderbird addresses +files="$files .thunderbird/*/prefs.js" + +# Mozilla addresses +files="$files .mozilla/*/prefs.js" + +# Netscape 4 addresses +files="$files .netscape/liprefs.js .netscape/preferences.js" + +# Netscape 3 addresses +files="$files .netscape/preferences" + +# Emacs/XEmacs rmail, Emacs/XEmacs gnus, XEmacs vm addresses +# XEmacs mew addresses +files="$files .emacs .emacs.el" + +# KDE2 addresses +files="$files .kde2/share/config/emaildefaults" + +# KDE kmail addresses +files="$files .kde2/share/config/kmailrc" + +# GNOME evolution 2 addresses +files="$files .gconf/apps/evolution/mail/%gconf.xml" + +# GNOME evolution 1 addresses +files="$files evolution/config.xmldb" + +# GNOME balsa addresses +files="$files .gnome/balsa" + +# StarOffice and OpenOffice addresses +sed_dos2unix='s/\r$//' +sed_soffice51='s,StarOffice 5\.1=\(.*\)$,\1/sofficerc,p' +sed_soffice52='s,StarOffice 5\.2=\(.*\)$,\1/user/sofficerc,p' +sed_ooffice='s,^OpenOffice[^=]*=\(.*\)$,\1/user/config/registry/instance/org/openoffice/UserProfile.xml,p' +files="$files Office51/sofficerc Office52/user/sofficerc "`sed -n -e "$sed_dos2unix" -e "$sed_soffice51" -e "$sed_soffice52" -e "$sed_ooffice" .sversionrc 2>/dev/null | sed -e 's,^file://*,/,'` + +# mutt addresses +files="$files .muttrc" + +# pine addresses +files="$files .pinerc" + +# xfmail addresses +files="$files .xfmail/.xfmailrc" + +# tkrat addresses +files="$files .ratatosk/ratatoskrc" + +# ----------------------- END MAILER SPECIFIC CODE ----------------------- + +# Expand wildcards and remove nonexistent files from the list. +nfiles="" +for file in $files; do + if test -r "$file" && test ! -d "$file"; then + nfiles="$nfiles $file" + fi +done +files="$nfiles" + +addresses="" + +if test -n "$files"; then + + for file in `ls -t $files`; do + + case "$file" in + +# ----------------------- BEGIN MAILER SPECIFIC CODE ----------------------- + + # Mozilla and Mozilla Thunderbird addresses + .mozilla/*/prefs.js | .thunderbird/*/prefs.js) + addresses="$addresses "`grep -h '^user_pref("mail\.identity\..*\.useremail", ".*");$' $file 2>/dev/null | sed -e 's/^user_pref("mail\.identity\..*\.useremail", "\(.*\)");$/\1/'` + ;; + + # Netscape 4 addresses + .netscape/liprefs.js | .netscape/preferences.js) + addresses="$addresses "`grep -h '^user_pref("mail\.identity\.useremail", ".*");$' $file 2>/dev/null | sed -e 's/^user_pref("mail\.identity\.useremail", "\(.*\)");$/\1/'` + ;; + + # Netscape 3 addresses + .netscape/preferences) + addresses="$addresses "`grep -h '^EMAIL_ADDRESS:' $file 2>/dev/null | sed -e 's/^EMAIL_ADDRESS:[ ]*//'` + ;; + + .emacs | .emacs.el) + # Emacs/XEmacs rmail, Emacs/XEmacs gnus, XEmacs vm addresses + addresses="$addresses "`grep -h '[ (]user-mail-address "[^"]*"' $file 2>/dev/null | sed -e 's/^.*[ (]user-mail-address "\([^"]*\)".*$/\1/'` + # XEmacs mew addresses + domains=`grep -h '[ (]mew-mail-domain "[^"]*"' $file 2>/dev/null | sed -e 's/^.*[ (]mew-mail-domain "\([^"]*\)".*$/\1/'` + if test -n "$domains"; then + for domain in $domains; do + addresses="$addresses ${user}@$domain" + done + fi + ;; + + # KDE2 addresses + .kde2/share/config/emaildefaults) + addresses="$addresses "`grep -h '^EmailAddress=' $file 2>/dev/null | sed -e 's/^EmailAddress=//'` + ;; + + # KDE kmail addresses + .kde2/share/config/kmailrc) + addresses="$addresses "`grep -h '^Email Address=' $file 2>/dev/null | sed -e 's/^Email Address=//'` + ;; + + # GNOME evolution 2 addresses + .gconf/apps/evolution/mail/%gconf.xml) + sedexpr0='s,^.*<addr-spec>\(.*\)</addr-spec>.*$,\1,p' + addresses="$addresses "`sed -n -e "$sedexpr0" < $file` + ;; + + # GNOME evolution 1 addresses + evolution/config.xmldb) + sedexpr0='s/^.*\(.*\).*$,\1,p' $file 2>/dev/null` + ;; + + # StarOffice addresses + # Not a typo. They really write "Adress" with a single d. + # German orthography... + */sofficerc) + addresses="$addresses "`grep -h '^User-Adress=' $file 2>/dev/null | sed -e 's/#[^#]*$//' -e 's/^.*#//'` + ;; + + # mutt addresses + .muttrc) + mutt_addresses=`grep -h '^set from="[^"]*"[ ]*$' $file 2>/dev/null | sed -e 's/^set from="\([^"]*\)"[ ]*$/\1/'` + if test -n "$mutt_addresses"; then + addresses="$addresses $mutt_addresses" + else + # mutt uses $EMAIL as fallback. + if test -n "$EMAIL"; then + addresses="$addresses $EMAIL" + fi + fi + ;; + + # pine addresses + .pinerc) + domains=`grep -h '^user-domain=' $file 2>/dev/null | sed -e 's/^user-domain=//'` + if test -n "$domains"; then + for domain in $domains; do + addresses="$addresses ${user}@$domain" + done + else + # The use-only-domain-name option is only used if the user-domain option is not present. + domains=`grep -h '^use-only-domain-name=' $file 2>/dev/null | sed -e 's/^use-only-domain-name=//'` + if test "Yes" = "$domains"; then + addresses="$addresses ${user}@"`echo "$hostfqdn" | sed -e 's/^[^.]*\.//'` + fi + fi + ;; + + # xfmail addresses + .xfmail/.xfmailrc) + addresses="$addresses "`grep -h '^from=.*<.*>' $file 2>/dev/null | sed -e 's/^.*<\([^<>]*\)>.*$/\1/'` + ;; + + # tkrat addresses + .ratatosk/ratatoskrc) + domains=`grep -h '^set option(masquerade_as) ' $file 2>/dev/null | sed -e 's/^set option(masquerade_as) //'` + if test -n "$domains"; then + for domain in $domains; do + addresses="$addresses ${user}@$domain" + done + else + # The domain option is used only if the masquerade_as option is not present. + domains=`grep -h '^set option(domain) ' $file 2>/dev/null | sed -e 's/^set option(domain) //'` + if test -n "$domains"; then + for domain in $domains; do + addresses="$addresses ${user}@${host}.$domain" + done + fi + fi + ;; + +# ----------------------- END MAILER SPECIFIC CODE ----------------------- + + esac + + done + +fi + +# Some Debian systems have a file /etc/mailname. +if test -r /etc/mailname; then + hostmailname=`cat /etc/mailname` + if test -n "$hostmailname"; then + addresses="$addresses ${user}@$hostmailname" + fi +fi + +# SuSE Linux >= 8.0 systems have a file /etc/sysconfig/mail. +if test -r /etc/sysconfig/mail; then + hostmailname=`. /etc/sysconfig/mail && echo "$FROM_HEADER"` + if test -n "$hostmailname"; then + addresses="$addresses ${user}@$hostmailname" + fi +fi + +# elm has no user-defined addresses. +# mailx has no user-defined addresses. +# mh has no user-defined addresses. +# They use the system default. +addresses="$addresses ${user}@$hostfqdn" + +# Normalize addresses: remove addresses without @, lowercase the part after @, +# and remove duplicates. +lowercase_sed='{ +h +s/^[^@]*@\(.*\)$/\1/ +y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ +x +s/^\([^@]*\)@.*/\1@/ +G +s/\ +// +p +}' +naddresses="" +for addr in $addresses; do + case "$addr" in + "<"*">") addr=`echo "$addr" | sed -e 's/^$//'` ;; + esac + case "$addr" in + *@*) + addr=`echo "$addr" | sed -n -e "$lowercase_sed"` + case " $naddresses " in + *" $addr "*) ;; + *) naddresses="$naddresses $addr" ;; + esac + ;; + esac +done +addresses="$naddresses" + +# Now it's time to ask the user. +case "$addresses" in + " "*" "*) + # At least two addresses. + lines="" + i=0 + for addr in $addresses; do + i=`expr $i + 1` + lines="${lines}${i} ${addr} +" + done + while true; do + { gettext "Which is your email address?"; echo; } 1>&3 + echo "$lines" 1>&3 + { gettext "Please choose the number, or enter your email address."; echo; } 1>&3 + read answer < /dev/tty + case "$answer" in + *@*) ;; + [0-9]*) + i=0 + for addr in $addresses; do + i=`expr $i + 1` + if test "$i" = "$answer"; then + break 2 + fi + done + ;; + esac + case "$answer" in + "<"*">") answer=`echo "$answer" | sed -e 's/^$//'` ;; + esac + case "$answer" in + *" "*) { gettext "Invalid email address: invalid character."; echo; echo; } 1>&3 ; continue ;; + *@*.*) ;; + *@*) { gettext "Invalid email address: need a fully qualified host name or domain name."; echo; echo; } 1>&3 ; continue ;; + *) { gettext "Invalid email address: missing @"; echo; echo; } 1>&3 ; continue ;; + esac + addr=`echo "$answer" | sed -n -e "$lowercase_sed"` + break + done + ;; + " "*) + # One address. + while true; do + { gettext "Is the following your email address?"; echo; } 1>&3 + echo " $addresses" 1>&3 + { gettext "Please confirm by pressing Return, or enter your email address."; echo; } 1>&3 + read answer < /dev/tty + if test -z "$answer"; then + addr=`echo "$addresses" | sed -e 's/^ //'` + break + fi + case "$answer" in + "<"*">") answer=`echo "$answer" | sed -e 's/^$//'` ;; + esac + case "$answer" in + *" "*) { gettext "Invalid email address: invalid character."; echo; echo; } 1>&3 ; continue ;; + *@*.*) ;; + *@*) { gettext "Invalid email address: need a fully qualified host name or domain name."; echo; echo; } 1>&3 ; continue ;; + *) { gettext "Invalid email address: missing @"; echo; echo; } 1>&3 ; continue ;; + esac + addr=`echo "$answer" | sed -n -e "$lowercase_sed"` + break + done + ;; + "") + # No address. + { gettext "Couldn't find out about your email address."; echo; } 1>&3 + while true; do + { gettext "Please enter your email address."; echo; } 1>&3 + read answer < /dev/tty + case "$answer" in + "<"*">") answer=`echo "$answer" | sed -e 's/^$//'` ;; + esac + case "$answer" in + *" "*) { gettext "Invalid email address: invalid character."; echo; echo; } 1>&3 ; continue ;; + *@*.*) ;; + *@*) { gettext "Invalid email address: need a fully qualified host name or domain name."; echo; echo; } 1>&3 ; continue ;; + *) { gettext "Invalid email address: missing @"; echo; echo; } 1>&3 ; continue ;; + esac + addr=`echo "$answer" | sed -n -e "$lowercase_sed"` + break + done + ;; + *) echo "internal error" 1>&3 ; exit 1 ;; +esac + +# Print to standard output. +echo "$addr" diff --git a/libs/gettext/lib64/libasprintf.a b/libs/gettext/lib64/libasprintf.a new file mode 100644 index 000000000..7988c40bf Binary files /dev/null and b/libs/gettext/lib64/libasprintf.a differ diff --git a/libs/gettext/lib64/libgettextpo.a b/libs/gettext/lib64/libgettextpo.a new file mode 100644 index 000000000..bf824d464 Binary files /dev/null and b/libs/gettext/lib64/libgettextpo.a differ diff --git a/libs/gettext/lib64/libintl.a b/libs/gettext/lib64/libintl.a new file mode 100644 index 000000000..42794ae61 Binary files /dev/null and b/libs/gettext/lib64/libintl.a differ diff --git a/libs/gme/CMakeLists.txt b/libs/gme/CMakeLists.txt new file mode 100644 index 000000000..8beee872f --- /dev/null +++ b/libs/gme/CMakeLists.txt @@ -0,0 +1,92 @@ +# CMake project definition file. +project(libgme) + +include (CheckCXXCompilerFlag) + +# When version is changed, also change the one in gme/gme.h to match +set(GME_VERSION 0.6.0 CACHE INTERNAL "libgme Version") + +# 2.6+ always assumes FATAL_ERROR, but 2.4 and below don't. +# Of course, 2.4 might work, in which case you're welcome to drop +# down the requirement, but I can't test that. +cmake_minimum_required(VERSION 2.6 FATAL_ERROR) + +# Default emulators to build (all of them! ;) +if (NOT DEFINED USE_GME_AY) + SET(USE_GME_AY 1 CACHE BOOL "Enable support for Spectrum ZX music emulation") +endif() + +if (NOT DEFINED USE_GME_GBS) + SET(USE_GME_GBS 1 CACHE BOOL "Enable support for Game Boy music emulation") +endif() + +if (NOT DEFINED USE_GME_GYM) + SET(USE_GME_GYM 1 CACHE BOOL "Enable Sega MegaDrive/Genesis music emulation") +endif() + +if (NOT DEFINED USE_GME_HES) + SET(USE_GME_HES 1 CACHE BOOL "Enable PC Engine/TurboGrafx-16 music emulation") +endif() + +if (NOT DEFINED USE_GME_KSS) + SET(USE_GME_KSS 1 CACHE BOOL "Enable MSX or other Z80 systems music emulation") +endif() + +if (NOT DEFINED USE_GME_NSF) + SET(USE_GME_NSF 1 CACHE BOOL "Enable NES NSF music emulation") +endif() + +if (NOT DEFINED USE_GME_NSFE) + SET(USE_GME_NSFE 1 CACHE BOOL "Enable NES NSFE and NSF music emulation") +endif() + +if (NOT DEFINED USE_GME_SAP) + SET(USE_GME_SAP 1 CACHE BOOL "Enable Atari SAP music emulation") +endif() + +if (NOT DEFINED USE_GME_SPC) + SET(USE_GME_SPC 1 CACHE BOOL "Enable SNES SPC music emulation") +endif() + +if (NOT DEFINED USE_GME_VGM) + SET(USE_GME_VGM 1 CACHE BOOL "Enable Sega VGM/VGZ music emulation") +endif() + +if (USE_GME_NSFE AND NOT USE_GME_NSF) + MESSAGE(" -- NSFE support requires NSF, enabling NSF support. --") + SET(USE_GME_NSF 1 CACHE BOOL "Enable NES NSF music emulation" FORCE) +endif() + +# Check for GCC "visibility" support. +if (CMAKE_COMPILER_IS_GNUCXX) + check_cxx_compiler_flag (-fvisibility=hidden __LIBGME_TEST_VISIBILITY) + set (ENABLE_VISIBILITY OFF) + if (__LIBGME_TEST_VISIBILITY) + # get the gcc version + exec_program(${CMAKE_CXX_COMPILER} ARGS --version OUTPUT_VARIABLE _gcc_version_info) + string (REGEX MATCH "[3-9]\\.[0-9]\\.[0-9]" _gcc_version "${_gcc_version_info}") + + # gcc <4.1 had poor support for symbol visibility + if ((${_gcc_version} VERSION_GREATER "4.1") OR (${_gcc_version} VERSION_EQUAL "4.1")) + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden") + set (ENABLE_VISIBILITY ON) + add_definitions (-DLIBGME_VISIBILITY) + + # GCC >= 4.2 also correctly supports making inline members have hidden + # visibility by default. + if ((${_gcc_version} VERSION_GREATER "4.2") OR (${_gcc_version} VERSION_EQUAL "4.2")) + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility-inlines-hidden") + endif() + endif() + endif() # test visibility +endif (CMAKE_COMPILER_IS_GNUCXX) + +# Cache this result +set( LIBGME_HAVE_GCC_VISIBILITY ${ENABLE_VISIBILITY} CACHE BOOL "GCC support for hidden visibility") + +# Shared library defined here +add_subdirectory(gme) + +# EXCLUDE_FROM_ALL adds build rules but keeps it out of default build +add_subdirectory(player EXCLUDE_FROM_ALL) +add_subdirectory(demo EXCLUDE_FROM_ALL) diff --git a/libs/gme/changes.txt b/libs/gme/changes.txt new file mode 100644 index 000000000..62391ebb5 --- /dev/null +++ b/libs/gme/changes.txt @@ -0,0 +1,262 @@ +Game_Music_Emu Change Log +------------------------- + +Game_Music_Emu 0.6.0 +-------------------- + +- Note: A 0.5.6 release was referenced but never tagged or packaged. + +- SPC improvements: + - Switched to newer snes_spc 0.9.0 for SPC emulation. Uses fast DSP. + - Fixed Spc_Emu::gain(). + - Fixed support for files <0x10200 bytes. + +- Other bugfixes: + - Fixed a couple of GBS bugs, one involving access of memory after + realloc. + - Blip_Buffer works on systems where 'double' is a single-precision + floating-point type. + - Fix uninitialized buffer size in dual_resampler. + - Compilation warnings squashed out as of clang 3.3-pre and gcc 4.7.2. + +- API changes/additions: + - Removed documentation of C++ interface, as the C interface in gme.h is + the only supported one. + - Added gme_enable_accuracy() for enabling more accurate sound emulation + options (currently affects SPC only). + +- Build system improvements: + - Add pkg_config support. + - Fix build on case-insensitive systems. + - Allow for install on Cygwin. + - Fix install on multilib systems, such as many 64-bit distros (CMake must + be able to figure out your system's libsuffix, if any). + - C++ implementation symbols are not leaked into the resultant library + file (requires symbol visibility support). + +- Sample player improvements: + - Can toggle fast/accurate emulation (with the 'A' key). + +Game_Music_Emu 0.5.5 +-------------------- +- CMake build support has been added. You can build Game_Music_Emu as +a shared library and install it so that you do not have to include your +own copy if you know libgme will be present on your target system. +Requires CMake 2.6 or higher. + + +Game_Music_Emu 0.5.2 +-------------------- +- *TONS* of changes and improvements. You should re-read the new header +files and documentation as the changes will allow you to simplify your +code a lot (it might even be simpler to just rewrite it). Existing code +should continue to work without changes in most cases (see Deprecated +features in gme.txt). + +- New file formats: AY, HES, KSS, SAP, NSFE + +- All-new comprehensive C interface (also usable from C++). Simplifies +many things, especially file loading, and brings everything together in +one header file (gme.h). + +- Information tags and track names and times can be accessed for all +game music formats + +- New features supported by all emulators: end of track fading, +automatic silence detection, adjustable song tempo, seek to new time in +track + +- Updated mini player example to support track names and times, echo, +tempo, and channel muting, and added visual waveform display + +- Improved configuration to use blargg_config.h, which you can modify +and keep when you update to a newer libary version. Includes flag for +library to automatically handle gzipped files using zlib (so you don't +need to use Gzip_File_Reader anymore). + +- GBS: Fixed wave channel to not reset waveform when APU is powered off +(affected Garfield). Also improved invalid bank selection (affected Game +& Watch and others). + +- VGM: Added support for alternate noise shifter register +configurations, used by other systems like the BBC Micro. + +- SPC: Removed IPL ROM dump from emulator, as none of the SPC files I +scanned needed it, and an SPC file can include a copy if necessary. Also +re-enabled supposed clamping in gaussian interpolation between the third +and fourth lookups, though I don't know whether it matters + +- Added Music_Emu::load_mem() to use music data already in memory +(without copying it) + +- Added Music_Emu::warning(), which reports minor problems when loading +and playing a music file + +- Added Music_Emu::set_gain() for uniform adjustment of gain. Can only +be set during initialization, so not useful as a general volume control. + +- Added custom operator new to ensure that no exceptions are thrown in +the library (I'd use std::nothrow if it were part of pre-ISO (ARM) C++) + +- Added BLIP_BUFFER_FAST flag to blargg_config.h to use a lower quality +bandlimited synthesis in "classic" emulators, which might help +performance on ancient processors (measure first!). Don't use this +unless absolutely necessary, as quality suffers. + +- Improved performance a bit for x86 platforms + +- Text files now in DOS newline format so they will open in Notepad +properly + +- Removed requirement that file header structures not have any padding +added to the end + +- Fixed common bug in all CPU emulators where negative program counter +could crash emulator (occurred during a negative branch from the +beginning of memory). Also fixed related bug in Z80 emulator for +IX/IY+displacement mode. + +- Eliminated all warnings when compiling on gcc 4.0. The following +generates no diagnostics: + + gcc -S gme/*.cpp -o /dev/null -ansi -fno-gnu-keywords + -fno-nonansi-builtins -pedantic -W -Wabi -Wall -Wcast-align + -Wcast-qual -Wchar-subscripts -Wdisabled-optimization -Werror + -Winline -Wlong-long -Wmultichar -Winvalid-offsetof + -Wnon-virtual-dtor -Woverloaded-virtual -Wparentheses + -Wpointer-arith -Wredundant-decls -Wreorder -Wsign-compare + -Wsign-promo -Wunknown-pragmas -Wwrite-strings + + +Game_Music_Emu 0.3.0 +-------------------- +- Added more demos, including music player using the SDL multimedia +library for sound, and improved documentation + +- All: Improved interface to emulators to allow simpler setup and +loading. Instead of various init() functions, all now support +set_sample_rate( long rate ) and load( const char* file_path ). + +- All: Removed error return from start_track() and play(), and added +error_count() to get the total number of emulation errors since the +track was last started. See demos for examples of new usage. + +- All: Fixed mute_voices() muting to be preserved after loading files +and starting tracks, instead of being cleared as it was whenever a track +was started + +- VGM: Rewrote Vgm_Emu to support Sega Genesis/Mega Drive FM sound at +any sample rate with optional FM oversampling, support for alternate +YM2612 sound cores, and support for optional YM2413 + +- VGM: Added tempo control, useful for slowing 60Hz NTSC Sega Genesis +music to 50Hz PAL + +- VGM: Removed Vgm_Emu::track_data(), since I realized that this +information is already present in the VGM header (oops!) + +- GYM: Changed Gym_Emu::track_length() operation (see Gym_Emu.h) + +- NSF: Added support for Sunsoft FME-7 sound chip used by Gimmick +soundtrack + +- NSF: Fixed Namco 106 problems with Final Lap and others + +- Moved library sources to gme/ directory to reduce clutter, and merged +boost/ functionality into blargg_common.h + +- Added Gzip_File_Reader for transparently using gzipped files + + +Game_Music_Emu 0.2.4 +-------------------- +- Created a discussion forum for problems and feedback: +http://groups-beta.google.com/group/blargg-sound-libs + +- Changed error return value of Blip_Buffer::sample_rate() (also for +Stereo_Buffer, Effects_Buffer, etc.) to blargg_err_t (defined in +blargg_common.h), to make error reporting consistent with other +functions. This means the "no error" return value is the opposite of +what it was before, which will break current code which checks the error +return value: + + // current code (broken) + if ( !buf.sample_rate( samples_per_sec ) ) + out_of_memory(); + + // quick-and-dirty fix (just remove the ! operation) + if ( buf.sample_rate( samples_per_sec ) ) + out_of_memory(); + + // proper fix + blargg_err_t error = buf.sample_rate( samples_per_sec ); + if ( error ) + report_error( error ); + +- Implemented workaround for MSVC++ 6 compiler limitations, allowing it +to work on that compiler again + +- Added sample clamping to avoid wrap-around at high volumes, allowing +higher volume with little distortion + +- Added to-do list and design notes + +- Added Music_Emu::skip( long sample_count ) to skip ahead in current +track + +- Added Gym_Emu::track_length() and Vgm_Emu::track_length() for +determining the length of non-looped GYM and VGM files + +- Partially implemented DMC non-linearity when its value is directly set +using $4011, which reduces previously over-emphasized "popping" of +percussion on some games (TMNT II in particular) + +- Fixed Fir_Resampler, used for SPC and GYM playback (was incorrectly +using abs() instead of fabs()...argh) + +- Fixed SPC emulation bugs: eliminated clicks in Plok! soundtrack and +now stops sample slightly earlier than the end, as the SNES does. Fixed +a totally broken CPU addressing mode. + +- Fixed Konami VRC6 saw wave (was very broken before). Now VRC6 music +sounds decent + +- Fixed a minor GBS emulation bug + +- Fixed GYM loop point bug when track was restarted before loop point +had been reached + +- Made default GBS frequency equalization less muffled + +- Added pseudo-surround effect removal for SPC files + +- Added Music_Emu::voice_names() which returns names for each voice. + +- Added BLARGG_SOURCE_BEGIN which allows custom compiler options to be +easily set for library sources + +- Changed assignment of expansion sound chips in Nsf_Emu to be spread +more evenly when using Effects_Buffer + +- Changed 'size_t' values in Blip_Buffer interface to 'long' + +- Changed demo to generate a WAVE sound file rather than an AIFF file + + +Game_Music_Emu 0.2.0 +-------------------- +- Redid framework and rewrote/cleaned up emulators + +- Changed licensing to GNU Lesser General Public License (LGPL) + +- Added Sega Genesis GYM and Super Nintendo SPC emulators + +- Added Namco-106 and Konami VRC6 sound chip support to NSF emulator + +- Eliminated use of static mutable data in emulators, allowing +multi-instance safety + + +Game_Music_Emu 0.1.0 +-------------------- +- First release diff --git a/libs/gme/demo/CMakeLists.txt b/libs/gme/demo/CMakeLists.txt new file mode 100644 index 000000000..024e9e973 --- /dev/null +++ b/libs/gme/demo/CMakeLists.txt @@ -0,0 +1,17 @@ +# Rules for building the demo. Doesn't use an installed gme if you've already +# installed the project so if you're copying these rules you probably don't +# even need these next two lines if you're building against system-installed +# gme. +include_directories(${CMAKE_SOURCE_DIR}/gme ${CMAKE_SOURCE_DIR}) +link_directories(${CMAKE_BINARY_DIR}/gme) + +add_executable(demo Wave_Writer.cpp basics.c) + +# Add command to copy build file over. +add_custom_command(TARGET demo + POST_BUILD + COMMAND cmake -E copy "${CMAKE_SOURCE_DIR}/test.nsf" ${CMAKE_CURRENT_BINARY_DIR} + COMMENT "Add convenience copy of test.nsf file for demo application" + VERBATIM) # VERBATIM is essentially required, "please use correct command line kthx" + +target_link_libraries(demo gme) diff --git a/libs/gme/demo/Wave_Writer.cpp b/libs/gme/demo/Wave_Writer.cpp new file mode 100644 index 000000000..1acaebc01 --- /dev/null +++ b/libs/gme/demo/Wave_Writer.cpp @@ -0,0 +1,182 @@ +// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/ + +#include "Wave_Writer.h" + +#include +#include + +/* Copyright (C) 2003-2006 by Shay Green. Permission is hereby granted, free +of charge, to any person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, copy, modify, +merge, publish, distribute, sublicense, and/or sell copies of the Software, and +to permit persons to whom the Software is furnished to do so, subject to the +following conditions: The above copyright notice and this permission notice +shall be included in all copies or substantial portions of the Software. THE +SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + +const int header_size = 0x2C; + +static void exit_with_error( const char* str ) +{ + printf( "Error: %s\n", str ); getchar(); + exit( EXIT_FAILURE ); +} + +Wave_Writer::Wave_Writer( long sample_rate, const char* filename ) +{ + sample_count_ = 0; + rate = sample_rate; + buf_pos = header_size; + chan_count = 1; + + buf = (unsigned char*) malloc( buf_size * sizeof *buf ); + if ( !buf ) + exit_with_error( "Out of memory" ); + + file = fopen( filename, "wb" ); + if ( !file ) + exit_with_error( "Couldn't open WAVE file for writing" ); + + setvbuf( file, 0, _IOFBF, 32 * 1024L ); +} + +void Wave_Writer::flush() +{ + if ( buf_pos && !fwrite( buf, buf_pos, 1, file ) ) + exit_with_error( "Couldn't write WAVE data" ); + buf_pos = 0; +} + +void Wave_Writer::write( const sample_t* in, long remain, int skip ) +{ + sample_count_ += remain; + while ( remain ) + { + if ( buf_pos >= buf_size ) + flush(); + + long n = (buf_size - buf_pos) / sizeof (sample_t); + if ( n > remain ) + n = remain; + remain -= n; + + // convert to lsb first format + unsigned char* p = &buf [buf_pos]; + while ( n-- ) + { + int s = *in; + in += skip; + *p++ = (unsigned char) s; + *p++ = (unsigned char) (s >> 8); + } + + buf_pos = p - buf; + assert( buf_pos <= buf_size ); + } +} + + +void Wave_Writer::write( const float* in, long remain, int skip ) +{ + sample_count_ += remain; + while ( remain ) + { + if ( buf_pos >= buf_size ) + flush(); + + long n = (buf_size - buf_pos) / sizeof (sample_t); + if ( n > remain ) + n = remain; + remain -= n; + + // convert to lsb first format + unsigned char* p = &buf [buf_pos]; + while ( n-- ) + { + long s = (long) (*in * 0x7FFF); + in += skip; + if ( (short) s != s ) + s = 0x7FFF - (s >> 24); // clamp to 16 bits + *p++ = (unsigned char) s; + *p++ = (unsigned char) (s >> 8); + } + + buf_pos = p - buf; + assert( buf_pos <= buf_size ); + } +} + +void Wave_Writer::close() +{ + if ( file ) + { + flush(); + + // generate header + long ds = sample_count_ * sizeof (sample_t); + long rs = header_size - 8 + ds; + int frame_size = chan_count * sizeof (sample_t); + long bps = rate * frame_size; + unsigned char header [header_size] = + { + 'R','I','F','F', + rs,rs>>8, // length of rest of file + rs>>16,rs>>24, + 'W','A','V','E', + 'f','m','t',' ', + 0x10,0,0,0, // size of fmt chunk + 1,0, // uncompressed format + chan_count,0, // channel count + rate,rate >> 8, // sample rate + rate>>16,rate>>24, + bps,bps>>8, // bytes per second + bps>>16,bps>>24, + frame_size,0, // bytes per sample frame + 16,0, // bits per sample + 'd','a','t','a', + ds,ds>>8,ds>>16,ds>>24// size of sample data + // ... // sample data + }; + + // write header + fseek( file, 0, SEEK_SET ); + fwrite( header, sizeof header, 1, file ); + + fclose( file ); + file = 0; + free( buf ); + } +} + +Wave_Writer::~Wave_Writer() +{ + close(); +} + +// C interface + +static Wave_Writer* ww; + +void wave_open( long sample_rate, const char* filename ) +{ + ww = new Wave_Writer( sample_rate, filename ); + assert( ww ); +} + +void wave_enable_stereo() { ww->enable_stereo(); } + +long wave_sample_count() { return ww->sample_count(); } + +void wave_write( const short* buf, long count ) { ww->write( buf, count ); } + +void wave_close() +{ + delete ww; + ww = 0; +} diff --git a/libs/gme/demo/Wave_Writer.h b/libs/gme/demo/Wave_Writer.h new file mode 100644 index 000000000..da08cc2a7 --- /dev/null +++ b/libs/gme/demo/Wave_Writer.h @@ -0,0 +1,73 @@ +/* WAVE sound file writer for recording 16-bit output during program development */ + +#ifndef WAVE_WRITER_H +#define WAVE_WRITER_H + +#ifdef __cplusplus + extern "C" { +#endif + +/* C interface */ +void wave_open( long sample_rate, const char* filename ); +void wave_enable_stereo( void ); +void wave_write( const short* buf, long count ); +long wave_sample_count( void ); +void wave_close( void ); + +#ifdef __cplusplus + } +#endif + +#ifdef __cplusplus +#include +#include + +/* C++ interface */ +class Wave_Writer { +public: + typedef short sample_t; + + // Create sound file with given sample rate (in Hz) and filename. + // Exits program if there's an error. + Wave_Writer( long sample_rate, char const* filename = "out.wav" ); + + // Enable stereo output + void enable_stereo(); + + // Append 'count' samples to file. Use every 'skip'th source sample; allows + // one channel of stereo sample pairs to be written by specifying a skip of 2. + void write( const sample_t*, long count, int skip = 1 ); + + // Append 'count' floating-point samples to file. Use every 'skip'th source sample; + // allows one channel of stereo sample pairs to be written by specifying a skip of 2. + void write( const float*, long count, int skip = 1 ); + + // Number of samples written so far + long sample_count() const; + + // Finish writing sound file and close it + void close(); + + ~Wave_Writer(); +public: + // Deprecated + void stereo( bool b ) { chan_count = b ? 2 : 1; } +private: + enum { buf_size = 32768 * 2 }; + unsigned char* buf; + FILE* file; + long sample_count_; + long rate; + long buf_pos; + int chan_count; + + void flush(); +}; + +inline void Wave_Writer::enable_stereo() { chan_count = 2; } + +inline long Wave_Writer::sample_count() const { return sample_count_; } + +#endif + +#endif diff --git a/libs/gme/demo/basics.c b/libs/gme/demo/basics.c new file mode 100644 index 000000000..551782518 --- /dev/null +++ b/libs/gme/demo/basics.c @@ -0,0 +1,57 @@ +/* C example that opens a game music file and records 10 seconds to "out.wav" */ + +static char filename [] = "test.nsf"; /* opens this file (can be any music type) */ + +#include "gme/gme.h" + +#include "Wave_Writer.h" /* wave_ functions for writing sound file */ +#include +#include + +void handle_error( const char* str ); + +int main() +{ + long sample_rate = 44100; /* number of samples per second */ + int track = 0; /* index of track to play (0 = first) */ + + /* Open music file in new emulator */ + Music_Emu* emu; + handle_error( gme_open_file( filename, &emu, sample_rate ) ); + + /* Start track */ + handle_error( gme_start_track( emu, track ) ); + + /* Begin writing to wave file */ + wave_open( sample_rate, "out.wav" ); + wave_enable_stereo(); + + /* Record 10 seconds of track */ + while ( gme_tell( emu ) < 10 * 1000L ) + { + /* Sample buffer */ + #define buf_size 1024 /* can be any multiple of 2 */ + short buf [buf_size]; + + /* Fill sample buffer */ + handle_error( gme_play( emu, buf_size, buf ) ); + + /* Write samples to wave file */ + wave_write( buf, buf_size ); + } + + /* Cleanup */ + gme_delete( emu ); + wave_close(); + + return 0; +} + +void handle_error( const char* str ) +{ + if ( str ) + { + printf( "Error: %s\n", str ); getchar(); + exit( EXIT_FAILURE ); + } +} diff --git a/libs/gme/demo/cpp_basics.cpp b/libs/gme/demo/cpp_basics.cpp new file mode 100644 index 000000000..53fab4186 --- /dev/null +++ b/libs/gme/demo/cpp_basics.cpp @@ -0,0 +1,67 @@ +// C++ example that opens a game music file and records 10 seconds to "out.wav" + +static char filename [] = "test.nsf"; /* opens this file (can be any music type) */ + +#include "gme/Music_Emu.h" + +#include "Wave_Writer.h" +#include +#include + +void handle_error( const char* str ); + +int main() +{ + long sample_rate = 44100; // number of samples per second + int track = 0; // index of track to play (0 = first) + + // Determine file type + gme_type_t file_type; + handle_error( gme_identify_file( filename, &file_type ) ); + if ( !file_type ) + handle_error( "Unsupported music type" ); + + // Create emulator and set sample rate + Music_Emu* emu = file_type->new_emu(); + if ( !emu ) + handle_error( "Out of memory" ); + handle_error( emu->set_sample_rate( sample_rate ) ); + + // Load music file into emulator + handle_error( emu->load_file( filename ) ); + + // Start track + handle_error( emu->start_track( track ) ); + + // Begin writing to wave file + Wave_Writer wave( sample_rate, "out.wav" ); + wave.enable_stereo(); + + // Record 10 seconds of track + while ( emu->tell() < 10 * 1000L ) + { + // Sample buffer + const long size = 1024; // can be any multiple of 2 + short buf [size]; + + // Fill buffer + handle_error( emu->play( size, buf ) ); + + // Write samples to wave file + wave.write( buf, size ); + } + + // Cleanup + delete emu; + + return 0; +} + +void handle_error( const char* str ) +{ + if ( str ) + { + printf( "Error: %s\n", str ); getchar(); + exit( EXIT_FAILURE ); + } +} diff --git a/libs/gme/demo/features.c b/libs/gme/demo/features.c new file mode 100644 index 000000000..38c8a1a6e --- /dev/null +++ b/libs/gme/demo/features.c @@ -0,0 +1,156 @@ +/* C example that opens any music file type, opens an m3u playlist if present, +prints its info and voice names, customizes the sound, and fades a track out. +Records to "out.wav". */ + +static char filename [] = "test.nsf"; /* opens this file (can be any music type) */ +static char playlist [] = "test.m3u"; /* uses this playlist, if present*/ + +#include "gme/gme.h" + +#include "Wave_Writer.h" /* wave_ functions for writing sound file */ +#include +#include + +void handle_error( const char* ); + +/* Example of loading from memory, which would be useful if using a zip file or +other custom format. In this example it's silly because we could just use +gme_load( &emu, sample_rate, path, 0 ). */ +Music_Emu* load_file( const char* path, long sample_rate ) +{ + Music_Emu* emu; + char* data; + long size; + + /* Read file data into memory. You might read the data from a zip file or + other compressed format. */ + FILE* in = fopen( path, "rb" ); + if ( !in ) + handle_error( "Couldn't open file" ); + fseek( in, 0, SEEK_END ); + size = ftell( in ); + rewind( in ); + + data = malloc( size ); + if ( !data ) + handle_error( "Out of memory" ); + if ( fread( data, size, 1, in ) <= 0 ) + handle_error( "Read error" ); + fclose( in ); + + handle_error( gme_open_data( data, size, &emu, sample_rate ) ); + free( data ); /* a copy is made of the data */ + return emu; +} + +/* Print any warning for most recent emulator action (load, start_track, play) */ +void print_warning( Music_Emu* emu ) +{ + const char* warning = gme_warning( emu ); + if ( warning ) + printf( "**** Warning: %s\n\n", warning ); +} + +static char my_data [] = "Our cleanup function was called"; + +/* Example cleanup function automatically called when emulator is deleted. */ +static void my_cleanup( void* my_data ) +{ + printf( "\n%s\n", (char*) my_data ); +} + +int main() +{ + long sample_rate = 44100; + int track = 0; /* index of track to play (0 = first) */ + int i; + + /* Load file into emulator */ + Music_Emu* emu = load_file( filename, sample_rate ); + print_warning( emu ); + + /* Register cleanup function and confirmation string as data */ + gme_set_user_data( emu, my_data ); + gme_set_user_cleanup( emu, my_cleanup ); + + /* Load .m3u playlist file. All tracks are assumed to use current file. + We ignore error here in case there is no m3u file present. */ + gme_load_m3u( emu, playlist ); + print_warning( emu ); + + /* Get and print main info for track */ + { + gme_info_t* info; + handle_error( gme_track_info( emu, &info, track ) ); + + printf( "System : %s\n", info->system ); + printf( "Game : %s\n", info->game ); + printf( "Author : %s\n", info->author ); + printf( "Copyright: %s\n", info->copyright ); + printf( "Comment : %s\n", info->comment ); + printf( "Dumper : %s\n", info->dumper ); + printf( "Tracks : %d\n", (int) gme_track_count( emu ) ); + printf( "\n" ); + printf( "Track : %d\n", (int) track + 1 ); + printf( "Name : %s\n", info->song ); + printf( "Length : %ld:%02ld", + (long) info->length / 1000 / 60, (long) info->length / 1000 % 60 ); + if ( info->loop_length != 0 ) + printf( " (endless)" ); + printf( "\n\n" ); + + gme_free_info( info ); + } + + /* Print voice names */ + for ( i = 0; i < gme_voice_count( emu ); i++ ) + printf( "Voice %d: %s\n", i, gme_voice_name( emu, i ) ); + + /* Enable most accurate sound emulation */ + gme_enable_accuracy( emu, 1 ); + + /* Add some stereo enhancement */ + gme_set_stereo_depth( emu, 0.20 ); + + /* Adjust equalizer for crisp, bassy sound */ + { + gme_equalizer_t eq; + gme_equalizer( emu, &eq ); + eq.treble = 0.0; + eq.bass = 20; + gme_set_equalizer( emu, &eq ); + } + + /* Start track and begin fade at 10 seconds */ + handle_error( gme_start_track( emu, track ) ); + print_warning( emu ); + gme_set_fade( emu, 10 * 1000L ); + + /* Record track until it ends */ + wave_open( sample_rate, "out.wav" ); + wave_enable_stereo(); + while ( !gme_track_ended( emu ) ) + { + #define buf_size 1024 + short buf [buf_size]; + handle_error( gme_play( emu, buf_size, buf ) ); + print_warning( emu ); + wave_write( buf, buf_size ); + } + + /* Cleanup */ + gme_delete( emu ); + wave_close(); + + getchar(); + return 0; +} + +void handle_error( const char* str ) +{ + if ( str ) + { + printf( "Error: %s\n", str ); getchar(); + exit( EXIT_FAILURE ); + } +} diff --git a/libs/gme/design.txt b/libs/gme/design.txt new file mode 100644 index 000000000..d79c860f7 --- /dev/null +++ b/libs/gme/design.txt @@ -0,0 +1,194 @@ +Game_Music_Emu 0.6.0 Design +--------------------------- +This might be slightly out-of-date at times, but will be a big help in +understanding the library implementation. + + +Architecture +------------ +The library is essentially a bunch of independent game music file +emulators unified with a common interface. + +Gme_File and Music_Emu provide a common interface to the emulators. The +virtual functions are protected rather than public to allow pre- and +post-processing of arguments and data in one place. This allows the +emulator classes to assume that everything is set up properly when +starting a track and playing samples. + +All file input is done with the Data_Reader interface. Many derived +classes are present, for the usual disk-based file and block of memory, +to specialized adaptors for things like reading a subset of data or +combining a block of memory with a Data_Reader to the remaining data. +This makes the library much more flexible with regard to the source of +game music file data. I still added a specialized load_mem() function to +have the emulator keep a pointer to data already read in memory, for +those formats whose files can be absolutely huge (GYM, some VGMs). This +is important if for some reason the caller must load the data ahead of +time, but doesn't want the emulator needlessly making a copy. + +Since silence checking and fading are relatively complex, they are kept +separate from basic file loading and track information, which are +handled in the base class Gme_File. My original intent was to use +Gme_File as the common base class for full emulators and track +information-only readers, but implementing the C interface was much +simpler if both derived from Music_Emu. User C++ code can still benefit +from static checking by using Gme_File where only track information will +be accessed. + +Each emulator generally has three components: main emulator, CPU +emulator, and sound chip emulator(s). Each component has minimal +coupling, so use in a full emulator or stand alone is fairly easy. This +modularity really helps reduce complexity. Blip_Buffer helps a lot with +simplifying the APU interfaces and implementation. + +The "classic" emulators derive from Classic_Emu, which handles +Blip_Buffer filling and multiple channels. It uses Multi_Buffer for +output, allowing you to derive a custom buffer that could output each +voice to a separate sound channel and do different processing on each. +At some point I'm going to implement a better Effects_Buffer that allows +individual control of every channel. + +In implementing the C interface, I wanted a way to specify an emulator +type that didn't require linking in all the emulators. For each emulator +type there is a global object with pointers to functions to create the +emulator or a track information reader. The emulator type is thus a +pointer to this, which conveniently allows for a NULL value. The user +referencing this emulator type object is what ultimately links the +emulator in (unless new Foo_Emu is used in C++, of course). This type +also serves as a useful substitute for RTTI on older C++ compilers. + +Addendum: I have since added gme_type_list(), which causes all listed +emulators to be linked in. To avoid this, I make the list itself +editable in blargg_config.h. Having a built-in list allows +gme_load_file() to take a path and give back an emulator with the file +loaded, which is extremely useful for new users. + + +Interface conventions +---------------------- +If a function retains a pointer to or replaces the value of an object +passed, it takes a pointer so that it will be clear in the caller's +source code that care is required. + +Multi-word names have an underscore '_' separator between individual +words. + +Functions are named with lowercase words. Functions which perform an +action with side-effects are named with a verb phrase (i.e. load, move, +run). Functions which return the value of a piece of state are named +using a noun phrase (i.e. loaded, moved, running). + +Classes are named with capitalized words. Only the first letter of an +acronym is capitalized. Class names are nouns, sometimes suggestive of +what they do (i.e. File_Scanner). + +Structure, enumeration, and typedefs to these and built-in types are +named using lowercase words with a _t suffix. + +Macros are named with all-uppercase words. + +Internal names which can't be hidden due to technical reasons have an +underscore '_' suffix. + + +Managing Complexity +------------------- +Complexity has been a factor in most library decisions. Many features +have been passed by due to the complexity they would add. Once +complexity goes past a certain level, it mentally grasping the library +in its entirety, at which point more defects will occur and be hard to +find. + +I chose 16-bit signed samples because it seems to be the most common +format. Supporting multiple formats would add too much complexity to be +worth it. Other formats can be obtained via conversion. + +I've kept interfaces fairly lean, leaving many possible features +untapped but easy to add if necessary. For example the classic emulators +could have volume and frequency equalization adjusted separately for +each channel, since they each have an associated Blip_Synth. + +Source files of 400 lines or less seem to be the best size to limit +complexity. In a few cases there is no reasonable way to split longer +files, or there is benefit from having the source together in one file. + + +Preventing Bugs +--------------- +I've done many things to reduce the opportunity for defects. A general +principle is to write code so that defects will be as visible as +possible. I've used several techniques to achieve this. + +I put assertions at key points where defects seem likely or where +corruption due to a defect is likely to be visible. I've also put +assertions where violations of the interface are likely. In emulators +where I am unsure of exact hardware operation in a particular case, I +output a debug-only message noting that this has occurred; many times I +haven't implemented a hardware feature because nothing uses it. I've +made code brittle where there is no clear reason flexibility; code +written to handle every possibility sacrifices quality and reliability +to handle vaguely defined situations. + + +Flexibility through indirection +------------------------------- +I've tried to allow the most flexibility of modules by using indirection +to allow extension by the user. This keeps each module simpler and more +focused on its unique task. + +The classic emulators use Multi_Buffer, which potentially allows a +separate Blip_Buffer for each channel. This keeps emulators free of +typical code to allow output in mono, stereo, panning, etc. + +All emulators use a reader object to access file data, allowing it to be +stored in a regular file, compressed archive, memory, or generated +on-the-fly. Again, the library can be kept free of the particulars of +file access and changes required to support new formats. + + +Emulators in general +-------------------- +When I wrote the first NES sound emulator, I stored most of the state in +an emulator-specific format, with significant redundancy. In the +register write function I decoded everything into named variables. I +became tired of the verbosity and wanted to more closely model the +hardware, so I moved to a style of storing the last written value to +each register, along with as little other state as possible, mostly the +internal hardware registers. While this involves slightly more +recalculation, in most cases the emulation code is of comparable size. +It also makes state save/restore (for use in a full emulator) much +simpler. Finally, it makes debugging easier since the hardware registers +used in emulation are obvious. + + +CPU Cores +--------- +I've spent lots of time coming up with techniques to optimize the CPU +cores. Some of the most important: execute multiple instructions during +an emulation call, keep state in local variables to allow register +assignment, optimize state representation for most common instructions, +defer status flag calculation until actually needed, read program code +directly without a call to the memory read function, always pre-fetch +the operand byte before decoding instruction, and emulate instructions +using common blocks of code. + +I've successfully used Nes_Cpu in a fairly complete NES emulator, and +I'd like to make all the CPU emulators suitable for use in emulators. It +seems a waste for them to be used only for the small amount of emulation +necessary for game music files. + +I debugged the CPU cores by writing a test shell that ran them in +parallel with other CPU cores and compared all memory accesses and +processor states at each step. This provided good value at little cost. + +The CPU mapping page size is adjustable to allow the best tradeoff +between memory/cache usage and handler granularity. The interface allows +code to be somewhat independent of the page size. + +I optimize program memory accesses to direct reads rather than calls to +the memory read function. My assumption is that it would be difficult to +get useful code out of hardware I/O addresses, so no software will +intentionally execute out of I/O space. Since the page size can be +changed easily, most program memory mapping schemes can be accommodated. +This greatly reduces memory access function calls. + diff --git a/libs/gme/gme.txt b/libs/gme/gme.txt new file mode 100644 index 000000000..d9a2452c7 --- /dev/null +++ b/libs/gme/gme.txt @@ -0,0 +1,376 @@ +Game_Music_Emu 0.6.0 +-------------------- +Author : Shay Green +Website: http://www.slack.net/~ant/libs/ +Forum : http://groups.google.com/group/blargg-sound-libs +Source : https://code.google.com/p/game-music-emu/ +License: GNU Lesser General Public License (LGPL) + +Contents +-------- +* Overview +* Error handling +* Emulator types +* M3U playlist support +* Information fields +* Track length +* Loading file data +* Sound parameters +* VGM/GYM YM2413 & YM2612 FM sound +* Modular construction +* Obscure features +* Solving problems +* Thanks + + +Overview +-------- +This library can open game music files, play tracks, and read game and +track information tags. To play a game music file, do the following: + +* Open the file with gme_open_file() +* Start a track with gme_start_track(); +* Generate samples as needed with gme_play() +* Play samples through speaker using your operating system +* Delete emulator when done with gme_delete() + +Your code must arrange for the generated samples to be played through +the computer's speaker using whatever method your operating system +requires. + +There are many additional features available; you can: + +* Determine of the type of a music file without opening it with +gme_identify_*() +* Load just the file's information tags with gme_info_only +* Load from a block of memory rather than a file with gme_load_data() +* Arrange for a fade-out at a particular time with gme_set_fade +* Find when a track has ended with gme_track_ended() +* Seek to a new time in the track with gme_seek() +* Load an extended m3u playlist with gme_load_m3u() +* Get a list of the voices (channels) and mute them individually with +gme_voice_names() and gme_mute_voice() +* Change the playback tempo without affecting pitch with gme_set_tempo() +* Adjust treble/bass equalization with gme_set_equalizer() +* Associate your own data with an emulator and later get it back with +gme_set_user_data() +* Register a function of yours to be called back when the emulator is +deleted with gme_set_user_cleanup() + +Refer to gme.h for a comprehensive summary of features. + + +Error handling +-------------- +Functions which can fail have a return type of gme_err_t, which is a +pointer to an error string (const char*). If a function is successful it +returns NULL. Errors that you can easily avoid are checked with debug +assertions; gme_err_t return values are only used for genuine run-time +errors that can't be easily predicted in advance (out of memory, I/O +errors, incompatible file data). Your code should check all error +values. + +When loading a music file in the wrong emulator or trying to load a +non-music file, gme_wrong_file_type is returned. You can check for this +error in C++ like this: + + gme_err_t err = gme_open_file( path, &emu ); + if ( err == gme_wrong_file_type ) + ... + +To check for minor problems, call gme_warning() to get a string +describing the last warning. Your player should allow the user some way +of knowing when this is the case, since these minor errors could affect +playback. Without this information the user can't solve problems as +well. When playing a track, gme_warning() returns minor playback-related +problems (major playback problems end the track immediately and set the +warning string). + + +Emulator types +-------------- +The library includes several game music emulators that each support a +different file type. Each is identified by a gme_type_t constant defined +in gme.h, for example gme_nsf_emu is for the NSF emulator. If you use +gme_open_file() or gme_open_data(), the library does the work of +determining the file type and creating an appropriate emulator. If you +want more control over this process, read on. + +There are two basic ways to identify a game music file's type: look at +its file extension, or read the header data. The library includes +functions to help with both methods. The first is preferable because it +is fast and the most common way to identify files. Sometimes the +extension is lost or wrong, so the header must be read. + +Use gme_identify_extension() to find the correct game music type based +on a filename. To identify a file based on its extension and header +contents, use gme_identify_file(). If you read the header data yourself, +use gme_identify_header(). + +If you want to remove support for some music types to reduce your +executable size, edit GME_TYPE_LIST in blargg_config.h. For example, to +support just NSF and GBS, use this: + + #define GME_TYPE_LIST \ + gme_nsf_type,\ + gme_gbs_type + + +M3U playlist support +-------------------- +The library supports playlists in an extended m3u format with +gme_load_m3u() to give track names and times to multi-song formats: AY, +GBS, HES, KSS, NSF, NSFE, and SAP. Some aspects of the file format +itself is not well-defined so some m3u files won't work properly +(particularly those provided with KSS files). Only m3u files referencing +a single file are supported; your code must handle m3u files covering +more than one game music file, though it can use the built-in m3u +parsing provided by the library. + + +Information fields +------------------ +Support is provided for the various text fields and length information +in a file with gme_track_info(). If you just need track information for +a file (for example, building a playlist), use gme_new_info() in place +of gme_new_emu(), load the file normally, then you can access the track +count and info, but nothing else. + + M3U VGM GYM SPC SAP NSFE NSF AY GBS HES KSS + ------------------------------------------------------- +Track Count | * * * * * * * * * + | +System | * * * * * * * * * * + | +Game | * * * * * * * + | +Song | * * * * * * * + | +Author | * * * * * * * * + | +Copyright | * * * * * * * * + | +Comment | * * * * + | +Dumper | * * * * + | +Length | * * * * * * + | +Intro Length| * * * + | +Loop Length | * * * + +As listed above, the HES and KSS file formats don't include a track +count, and tracks are often scattered over the 0-255 range, so an m3u +playlist for these is a must. + +Unavailable text fields are set to an empty string and times to -1. Your +code should be prepared for any combination of available and unavailable +fields, as a particular music file might not use all of the supported +fields listed above. + +Currently text fields are truncated to 255 characters. Obscure fields of +some formats are not currently decoded; contact me if you want one +added. + + +Track length +------------ +The library leaves it up to you as to when to stop playing a track. You +can ask for available length information and then tell the library what +time it should start fading the track with gme_set_fade(). By default it +also continually checks for 6 or more seconds of silence to mark the end +of a track. Here is a reasonable algorithm you can use to decide how +long to play a track: + +* If the track length is > 0, use it +* If the loop length > 0, play for intro + loop * 2 +* Otherwise, default to 2.5 minutes (150000 msec) + +If you want to play a track longer than normal, be sure the loop length +isn't zero. See Music_Player.cpp around line 145 for example code. + +By default, the library skips silence at the beginning of a track. It +also continually checks for the end of a non-looping track by watching +for 6 seconds of unbroken silence. When doing this is scans *ahead* by +several seconds so it can report the end of the track after only one +second of silence has actually played. This feature can be disabled with +gme_ignore_silence(). + + +Loading file data +----------------- +The library allows file data to be loaded in many different ways. All +load functions return an error which you should check. The following +examples assume these variables: + + Music_Emu* emu; + gme_err_t error; + +If you're letting the library determine a file's type, you can use +either gme_open_file() or gme_open_data(): + + error = gme_open_file( pathname, &emu ); + error = gme_open_data( pointer, size, &emu ); + +If you're manually determining file type and using used gme_new_emu() to +create an emulator, you can use the following methods of loading: + +* From a block of memory: + + error = gme_load_data( emu, pointer, size ); + +* Have library call your function to read data: + + gme_err_t my_read( void* my_data, void* out, long count ) + { + // code that reads 'count' bytes into 'out' buffer + // and return 0 if no error + } + + error = gme_load_custom( emu, my_read, file_size, my_data ); + + +Sound parameters +---------------- +All emulators support an arbitrary output sampling rate. A rate of 44100 +Hz should work well on most systems. Since band-limited synthesis is +used, a sampling rate above 48000 Hz is not necessary and will actually +reduce sound quality and performance. + +All emulators also support adjustable gain, mainly for the purpose of +getting consistent volume between different music formats and avoiding +excessive modulation. The gain can only be set *before* setting the +emulator's sampling rate, so it's not useful as a general volume +control. The default gains of emulators are set so that they give +generally similar volumes, though some soundtracks are significantly +louder or quieter than normal. + +Some emulators support adjustable treble and bass frequency equalization +(AY, GBS, HES, KSS, NSF, NSFE, SAP, VGM) using set_equalizer(). +Parameters are specified using gme_equalizer_t eq = { treble_dB, +bass_freq }. Treble_dB sets the treble level (in dB), where 0.0 dB gives +normal treble; -200.0 dB is quite muffled, and 5.0 dB emphasizes treble +for an extra crisp sound. Bass_freq sets the frequency where bass +response starts to diminish; 15 Hz is normal, 0 Hz gives maximum bass, +and 15000 Hz removes all bass. For example, the following makes the +sound extra-crisp but lacking bass: + + gme_equalizer_t eq = { 5.0, 1000 }; + gme_set_equalizer( music_emu, &eq ); + +Each emulator's equalization defaults to approximate the particular +console's sound quality; this default can be determined by calling +equalizer() just after creating the emulator. The Music_Emu::tv_eq +profile gives sound as if coming from a TV speaker, and some emulators +include other profiles for different versions of the system. For +example, to use Famicom sound equalization with the NSF emulator, do the +following: + + music_emu->set_equalizer( Nsf_Emu::famicom_eq ); + + +VGM/GYM YM2413 & YM2612 FM sound +-------------------------------- +The library plays Sega Genesis/Mega Drive music using a YM2612 FM sound +chip emulator based on the Gens project. Because this has some +inaccuracies, other YM2612 emulators can be used in its place by +re-implementing the interface in YM2612_Emu.h. Available on my website +is a modified version of MAME's YM2612 emulator, which sounds better in +some ways and whose author is still making improvements. + +VGM music files using the YM2413 FM sound chip are also supported, but a +YM2413 emulator isn't included with the library due to technical +reasons. I have put one of the available YM2413 emulators on my website +that can be used directly. + + +Modular construction +-------------------- +The library is made of many fairly independent modules. If you're using +only one music file emulator, you can eliminate many of the library +sources from your program. Refer to the files list in readme.txt to get +a general idea of what can be removed, and be sure to edit GME_TYPE_LIST +(see "Emulator types" above). Post to the forum if you'd like me to put +together a smaller version for a particular use, as this only takes me a +few minutes to do. + +If you want to use one of the individual sound chip emulators (or CPU +cores) in your own console emulator, first check the libraries page on +my website since I have released several of them as stand alone +libraries with included documentation and examples on their use. If you +don't find it as a standalone library, contact me and I'll consider +separating it. + +The "classic" sound chips use my Blip_Buffer library, which greatly +simplifies their implementation and efficiently handles band-limited +synthesis. It is also available as a stand alone library with +documentation and many examples. + + +Obscure features +---------------- +The library's flexibility allows many possibilities. Contact me if you +want help implementing ideas or removing limitations. + +* Uses no global/static variables, allowing multiple instances of any +emulator. This is useful in a music player if you want to allow +simultaneous recording or scanning of other tracks while one is already +playing. This will also be useful if your platform disallows global +data. + +* Emulators that support a custom sound buffer can have *every* voice +routed to a different Blip_Buffer, allowing custom processing on each +voice. For example you could record a Game Boy track as a 4-channel +sound file. + +* Defining BLIP_BUFFER_FAST uses lower quality, less-multiply-intensive +synthesis on "classic" emulators, which might help on some really old +processors. This significantly lowers sound quality and prevents treble +equalization. Try this if your platform's processor isn't fast enough +for normal quality. Even on my ten-year-old 400 MHz Mac, this reduces +processor usage at most by about 0.6% (from 4% to 3.4%), hardly worth +the quality loss. + + +Solving problems +---------------- +If you're having problems, try the following: + +* If you're getting garbled sound, try this simple siren generator in +place of your call to play(). This will quickly tell whether the problem +is in the library or in your code. + + static void play_siren( long count, short* out ) + { + static double a, a2; + while ( count-- ) + *out++ = 0x2000 * sin( a += .1 + .05*sin( a2+=.00005 ) ); + } + +* Enable debugging support in your environment. This enables assertions +and other run-time checks. + +* Turn the compiler's optimizer is off. Sometimes an optimizer generates +bad code. + +* If multiple threads are being used, ensure that only one at a time is +accessing a given set of objects from the library. This library is not +in general thread-safe, though independent objects can be used in +separate threads. + +* If all else fails, see if the demos work. + + +Thanks +------ +Big thanks to Chris Moeller (kode54) for help with library testing and +feedback, for maintaining the Foobar2000 plugin foo_gep based on it, and +for original work on openspc++ that was used when developing Spc_Emu. +Brad Martin's excellent OpenSPC SNES DSP emulator worked well from the +start. Also thanks to Richard Bannister, Mahendra Tallur, Shazz, +nenolod, theHobbit, Johan Samuelsson, and nes6502 for testing, using, +and giving feedback for the library in their respective game music +players. More recently, Lucas Paul and Michael Pyne have helped nudge the +library into a public repository and get its interface more stable for use +in shared libraries. diff --git a/libs/gme/gme/Ay_Apu.cpp b/libs/gme/gme/Ay_Apu.cpp new file mode 100644 index 000000000..c1405231d --- /dev/null +++ b/libs/gme/gme/Ay_Apu.cpp @@ -0,0 +1,395 @@ +// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/ + +#include "Ay_Apu.h" + +/* Copyright (C) 2006 Shay Green. This module 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 +module 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 module; if not, write to the Free Software Foundation, +Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + +#include "blargg_source.h" + +// Emulation inaccuracies: +// * Noise isn't run when not in use +// * Changes to envelope and noise periods are delayed until next reload +// * Super-sonic tone should attenuate output to about 60%, not 50% + +// Tones above this frequency are treated as disabled tone at half volume. +// Power of two is more efficient (avoids division). +unsigned const inaudible_freq = 16384; + +int const period_factor = 16; + +static byte const amp_table [16] = +{ +#define ENTRY( n ) byte (n * Ay_Apu::amp_range + 0.5) + // With channels tied together and 1K resistor to ground (as datasheet recommends), + // output nearly matches logarithmic curve as claimed. Approx. 1.5 dB per step. + ENTRY(0.000000),ENTRY(0.007813),ENTRY(0.011049),ENTRY(0.015625), + ENTRY(0.022097),ENTRY(0.031250),ENTRY(0.044194),ENTRY(0.062500), + ENTRY(0.088388),ENTRY(0.125000),ENTRY(0.176777),ENTRY(0.250000), + ENTRY(0.353553),ENTRY(0.500000),ENTRY(0.707107),ENTRY(1.000000), + + /* + // Measured from an AY-3-8910A chip with date code 8611. + + // Direct voltages without any load (very linear) + ENTRY(0.000000),ENTRY(0.046237),ENTRY(0.064516),ENTRY(0.089785), + ENTRY(0.124731),ENTRY(0.173118),ENTRY(0.225806),ENTRY(0.329032), + ENTRY(0.360215),ENTRY(0.494624),ENTRY(0.594624),ENTRY(0.672043), + ENTRY(0.766129),ENTRY(0.841935),ENTRY(0.926882),ENTRY(1.000000), + // With only some load + ENTRY(0.000000),ENTRY(0.011940),ENTRY(0.017413),ENTRY(0.024876), + ENTRY(0.036318),ENTRY(0.054229),ENTRY(0.072637),ENTRY(0.122388), + ENTRY(0.174129),ENTRY(0.239303),ENTRY(0.323881),ENTRY(0.410945), + ENTRY(0.527363),ENTRY(0.651741),ENTRY(0.832338),ENTRY(1.000000), + */ +#undef ENTRY +}; + +static byte const modes [8] = +{ +#define MODE( a0,a1, b0,b1, c0,c1 ) \ + (a0 | a1<<1 | b0<<2 | b1<<3 | c0<<4 | c1<<5) + MODE( 1,0, 1,0, 1,0 ), + MODE( 1,0, 0,0, 0,0 ), + MODE( 1,0, 0,1, 1,0 ), + MODE( 1,0, 1,1, 1,1 ), + MODE( 0,1, 0,1, 0,1 ), + MODE( 0,1, 1,1, 1,1 ), + MODE( 0,1, 1,0, 0,1 ), + MODE( 0,1, 0,0, 0,0 ), +}; + +Ay_Apu::Ay_Apu() +{ + // build full table of the upper 8 envelope waveforms + for ( int m = 8; m--; ) + { + byte* out = env.modes [m]; + int flags = modes [m]; + for ( int x = 3; --x >= 0; ) + { + int amp = flags & 1; + int end = flags >> 1 & 1; + int step = end - amp; + amp *= 15; + for ( int y = 16; --y >= 0; ) + { + *out++ = amp_table [amp]; + amp += step; + } + flags >>= 2; + } + } + + output( 0 ); + volume( 1.0 ); + reset(); +} + +void Ay_Apu::reset() +{ + last_time = 0; + noise.delay = 0; + noise.lfsr = 1; + + osc_t* osc = &oscs [osc_count]; + do + { + osc--; + osc->period = period_factor; + osc->delay = 0; + osc->last_amp = 0; + osc->phase = 0; + } + while ( osc != oscs ); + + for ( int i = sizeof regs; --i >= 0; ) + regs [i] = 0; + regs [7] = 0xFF; + write_data_( 13, 0 ); +} + +void Ay_Apu::write_data_( int addr, int data ) +{ + assert( (unsigned) addr < reg_count ); + + if ( (unsigned) addr >= 14 ) + { + #ifdef debug_printf + debug_printf( "Wrote to I/O port %02X\n", (int) addr ); + #endif + } + + // envelope mode + if ( addr == 13 ) + { + if ( !(data & 8) ) // convert modes 0-7 to proper equivalents + data = (data & 4) ? 15 : 9; + env.wave = env.modes [data - 7]; + env.pos = -48; + env.delay = 0; // will get set to envelope period in run_until() + } + regs [addr] = data; + + // handle period changes accurately + int i = addr >> 1; + if ( i < osc_count ) + { + blip_time_t period = (regs [i * 2 + 1] & 0x0F) * (0x100L * period_factor) + + regs [i * 2] * period_factor; + if ( !period ) + period = period_factor; + + // adjust time of next timer expiration based on change in period + osc_t& osc = oscs [i]; + if ( (osc.delay += period - osc.period) < 0 ) + osc.delay = 0; + osc.period = period; + } + + // TODO: same as above for envelope timer, and it also has a divide by two after it +} + +int const noise_off = 0x08; +int const tone_off = 0x01; + +void Ay_Apu::run_until( blip_time_t final_end_time ) +{ + require( final_end_time >= last_time ); + + // noise period and initial values + blip_time_t const noise_period_factor = period_factor * 2; // verified + blip_time_t noise_period = (regs [6] & 0x1F) * noise_period_factor; + if ( !noise_period ) + noise_period = noise_period_factor; + blip_time_t const old_noise_delay = noise.delay; + blargg_ulong const old_noise_lfsr = noise.lfsr; + + // envelope period + blip_time_t const env_period_factor = period_factor * 2; // verified + blip_time_t env_period = (regs [12] * 0x100L + regs [11]) * env_period_factor; + if ( !env_period ) + env_period = env_period_factor; // same as period 1 on my AY chip + if ( !env.delay ) + env.delay = env_period; + + // run each osc separately + for ( int index = 0; index < osc_count; index++ ) + { + osc_t* const osc = &oscs [index]; + int osc_mode = regs [7] >> index; + + // output + Blip_Buffer* const osc_output = osc->output; + if ( !osc_output ) + continue; + osc_output->set_modified(); + + // period + int half_vol = 0; + blip_time_t inaudible_period = (blargg_ulong) (osc_output->clock_rate() + + inaudible_freq) / (inaudible_freq * 2); + if ( osc->period <= inaudible_period && !(osc_mode & tone_off) ) + { + half_vol = 1; // Actually around 60%, but 50% is close enough + osc_mode |= tone_off; + } + + // envelope + blip_time_t start_time = last_time; + blip_time_t end_time = final_end_time; + int const vol_mode = regs [0x08 + index]; + int volume = amp_table [vol_mode & 0x0F] >> half_vol; + int osc_env_pos = env.pos; + if ( vol_mode & 0x10 ) + { + volume = env.wave [osc_env_pos] >> half_vol; + // use envelope only if it's a repeating wave or a ramp that hasn't finished + if ( !(regs [13] & 1) || osc_env_pos < -32 ) + { + end_time = start_time + env.delay; + if ( end_time >= final_end_time ) + end_time = final_end_time; + + //if ( !(regs [12] | regs [11]) ) + // debug_printf( "Used envelope period 0\n" ); + } + else if ( !volume ) + { + osc_mode = noise_off | tone_off; + } + } + else if ( !volume ) + { + osc_mode = noise_off | tone_off; + } + + // tone time + blip_time_t const period = osc->period; + blip_time_t time = start_time + osc->delay; + if ( osc_mode & tone_off ) // maintain tone's phase when off + { + blargg_long count = (final_end_time - time + period - 1) / period; + time += count * period; + osc->phase ^= count & 1; + } + + // noise time + blip_time_t ntime = final_end_time; + blargg_ulong noise_lfsr = 1; + if ( !(osc_mode & noise_off) ) + { + ntime = start_time + old_noise_delay; + noise_lfsr = old_noise_lfsr; + //if ( (regs [6] & 0x1F) == 0 ) + // debug_printf( "Used noise period 0\n" ); + } + + // The following efficiently handles several cases (least demanding first): + // * Tone, noise, and envelope disabled, where channel acts as 4-bit DAC + // * Just tone or just noise, envelope disabled + // * Envelope controlling tone and/or noise + // * Tone and noise disabled, envelope enabled with high frequency + // * Tone and noise together + // * Tone and noise together with envelope + + // This loop only runs one iteration if envelope is disabled. If envelope + // is being used as a waveform (tone and noise disabled), this loop will + // still be reasonably efficient since the bulk of it will be skipped. + while ( 1 ) + { + // current amplitude + int amp = 0; + if ( (osc_mode | osc->phase) & 1 & (osc_mode >> 3 | noise_lfsr) ) + amp = volume; + { + int delta = amp - osc->last_amp; + if ( delta ) + { + osc->last_amp = amp; + synth_.offset( start_time, delta, osc_output ); + } + } + + // Run wave and noise interleved with each catching up to the other. + // If one or both are disabled, their "current time" will be past end time, + // so there will be no significant performance hit. + if ( ntime < end_time || time < end_time ) + { + // Since amplitude was updated above, delta will always be +/- volume, + // so we can avoid using last_amp every time to calculate the delta. + int delta = amp * 2 - volume; + int delta_non_zero = delta != 0; + int phase = osc->phase | (osc_mode & tone_off); assert( tone_off == 0x01 ); + do + { + // run noise + blip_time_t end = end_time; + if ( end_time > time ) end = time; + if ( phase & delta_non_zero ) + { + while ( ntime <= end ) // must advance *past* time to avoid hang + { + int changed = noise_lfsr + 1; + noise_lfsr = (-(noise_lfsr & 1) & 0x12000) ^ (noise_lfsr >> 1); + if ( changed & 2 ) + { + delta = -delta; + synth_.offset( ntime, delta, osc_output ); + } + ntime += noise_period; + } + } + else + { + // 20 or more noise periods on average for some music + blargg_long remain = end - ntime; + blargg_long count = remain / noise_period; + if ( remain >= 0 ) + ntime += noise_period + count * noise_period; + } + + // run tone + end = end_time; + if ( end_time > ntime ) end = ntime; + if ( noise_lfsr & delta_non_zero ) + { + while ( time < end ) + { + delta = -delta; + synth_.offset( time, delta, osc_output ); + time += period; + //phase ^= 1; + } + //assert( phase == (delta > 0) ); + phase = unsigned (-delta) >> (CHAR_BIT * sizeof (unsigned) - 1); + // (delta > 0) + } + else + { + // loop usually runs less than once + //SUB_CASE_COUNTER( (time < end) * (end - time + period - 1) / period ); + + while ( time < end ) + { + time += period; + phase ^= 1; + } + } + } + while ( time < end_time || ntime < end_time ); + + osc->last_amp = (delta + volume) >> 1; + if ( !(osc_mode & tone_off) ) + osc->phase = phase; + } + + if ( end_time >= final_end_time ) + break; // breaks first time when envelope is disabled + + // next envelope step + if ( ++osc_env_pos >= 0 ) + osc_env_pos -= 32; + volume = env.wave [osc_env_pos] >> half_vol; + + start_time = end_time; + end_time += env_period; + if ( end_time > final_end_time ) + end_time = final_end_time; + } + osc->delay = time - final_end_time; + + if ( !(osc_mode & noise_off) ) + { + noise.delay = ntime - final_end_time; + noise.lfsr = noise_lfsr; + } + } + + // TODO: optimized saw wave envelope? + + // maintain envelope phase + blip_time_t remain = final_end_time - last_time - env.delay; + if ( remain >= 0 ) + { + blargg_long count = (remain + env_period) / env_period; + env.pos += count; + if ( env.pos >= 0 ) + env.pos = (env.pos & 31) - 32; + remain -= count * env_period; + assert( -remain <= env_period ); + } + env.delay = -remain; + assert( env.delay > 0 ); + assert( env.pos < 0 ); + + last_time = final_end_time; +} diff --git a/libs/gme/gme/Ay_Apu.h b/libs/gme/gme/Ay_Apu.h new file mode 100644 index 000000000..b031f0473 --- /dev/null +++ b/libs/gme/gme/Ay_Apu.h @@ -0,0 +1,106 @@ +// AY-3-8910 sound chip emulator + +// Game_Music_Emu 0.6.0 +#ifndef AY_APU_H +#define AY_APU_H + +#include "blargg_common.h" +#include "Blip_Buffer.h" + +class Ay_Apu { +public: + // Set buffer to generate all sound into, or disable sound if NULL + void output( Blip_Buffer* ); + + // Reset sound chip + void reset(); + + // Write to register at specified time + enum { reg_count = 16 }; + void write( blip_time_t time, int addr, int data ); + + // Run sound to specified time, end current time frame, then start a new + // time frame at time 0. Time frames have no effect on emulation and each + // can be whatever length is convenient. + void end_frame( blip_time_t length ); + +// Additional features + + // Set sound output of specific oscillator to buffer, where index is + // 0, 1, or 2. If buffer is NULL, the specified oscillator is muted. + enum { osc_count = 3 }; + void osc_output( int index, Blip_Buffer* ); + + // Set overall volume (default is 1.0) + void volume( double ); + + // Set treble equalization (see documentation) + void treble_eq( blip_eq_t const& ); + +public: + Ay_Apu(); + typedef unsigned char byte; +private: + struct osc_t + { + blip_time_t period; + blip_time_t delay; + short last_amp; + short phase; + Blip_Buffer* output; + } oscs [osc_count]; + blip_time_t last_time; + byte regs [reg_count]; + + struct { + blip_time_t delay; + blargg_ulong lfsr; + } noise; + + struct { + blip_time_t delay; + byte const* wave; + int pos; + byte modes [8] [48]; // values already passed through volume table + } env; + + void run_until( blip_time_t ); + void write_data_( int addr, int data ); +public: + enum { amp_range = 255 }; + Blip_Synth synth_; +}; + +inline void Ay_Apu::volume( double v ) { synth_.volume( 0.7 / osc_count / amp_range * v ); } + +inline void Ay_Apu::treble_eq( blip_eq_t const& eq ) { synth_.treble_eq( eq ); } + +inline void Ay_Apu::write( blip_time_t time, int addr, int data ) +{ + run_until( time ); + write_data_( addr, data ); +} + +inline void Ay_Apu::osc_output( int i, Blip_Buffer* buf ) +{ + assert( (unsigned) i < osc_count ); + oscs [i].output = buf; +} + +inline void Ay_Apu::output( Blip_Buffer* buf ) +{ + osc_output( 0, buf ); + osc_output( 1, buf ); + osc_output( 2, buf ); +} + +inline void Ay_Apu::end_frame( blip_time_t time ) +{ + if ( time > last_time ) + run_until( time ); + + assert( last_time >= time ); + last_time -= time; +} + +#endif diff --git a/libs/gme/gme/Ay_Cpu.cpp b/libs/gme/gme/Ay_Cpu.cpp new file mode 100644 index 000000000..825320d08 --- /dev/null +++ b/libs/gme/gme/Ay_Cpu.cpp @@ -0,0 +1,1666 @@ +// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/ + +/* +Last validated with zexall 2006.11.21 5:26 PM +* Doesn't implement the R register or immediate interrupt after EI. +* Address wrap-around isn't completely correct, but is prevented from crashing emulator. +*/ + +#include "Ay_Cpu.h" + +#include "blargg_endian.h" +#include + +//#include "z80_cpu_log.h" + +/* Copyright (C) 2006 Shay Green. This module 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 +module 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 module; if not, write to the Free Software Foundation, +Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + +#define SYNC_TIME() (void) (s.time = s_time) +#define RELOAD_TIME() (void) (s_time = s.time) + +// Callbacks to emulator + +#define CPU_OUT( cpu, addr, data, TIME )\ + ay_cpu_out( cpu, TIME, addr, data ) + +#define CPU_IN( cpu, addr, TIME )\ + ay_cpu_in( cpu, addr ) + +#include "blargg_source.h" + +// flags, named with hex value for clarity +int const S80 = 0x80; +int const Z40 = 0x40; +int const F20 = 0x20; +int const H10 = 0x10; +int const F08 = 0x08; +int const V04 = 0x04; +int const P04 = 0x04; +int const N02 = 0x02; +int const C01 = 0x01; + +#define SZ28P( n ) szpc [n] +#define SZ28PC( n ) szpc [n] +#define SZ28C( n ) (szpc [n] & ~P04) +#define SZ28( n ) SZ28C( n ) + +#define SET_R( n ) (void) (r.r = n) +#define GET_R() (r.r) + +Ay_Cpu::Ay_Cpu() +{ + state = &state_; + for ( int i = 0x100; --i >= 0; ) + { + int even = 1; + for ( int p = i; p; p >>= 1 ) + even ^= p; + int n = (i & (S80 | F20 | F08)) | ((even & 1) * P04); + szpc [i] = n; + szpc [i + 0x100] = n | C01; + } + szpc [0x000] |= Z40; + szpc [0x100] |= Z40; +} + +void Ay_Cpu::reset( void* m ) +{ + mem = (uint8_t*) m; + + check( state == &state_ ); + state = &state_; + state_.time = 0; + state_.base = 0; + end_time_ = 0; + + memset( &r, 0, sizeof r ); +} + +#define TIME (s_time + s.base) +#define READ_PROG( addr ) (mem [addr]) +#define INSTR( offset ) READ_PROG( pc + (offset) ) +#define GET_ADDR() GET_LE16( &READ_PROG( pc ) ) +#define READ( addr ) READ_PROG( addr ) +#define WRITE( addr, data ) (void) (READ_PROG( addr ) = data) +#define READ_WORD( addr ) GET_LE16( &READ_PROG( addr ) ) +#define WRITE_WORD( addr, data ) SET_LE16( &READ_PROG( addr ), data ) +#define IN( addr ) CPU_IN( this, addr, TIME ) +#define OUT( addr, data ) CPU_OUT( this, addr, data, TIME ) + +#if BLARGG_BIG_ENDIAN + #define R8( n, offset ) ((r8_ - offset) [n]) +#elif BLARGG_LITTLE_ENDIAN + #define R8( n, offset ) ((r8_ - offset) [(n) ^ 1]) +#else + #error "Byte order of CPU must be known" +#endif + +//#define R16( n, shift, offset ) (r16_ [((n) >> shift) - (offset >> shift)]) + +// help compiler see that it can just adjust stack offset, saving an extra instruction +#define R16( n, shift, offset )\ + (*(uint16_t*) ((char*) r16_ - (offset >> (shift - 1)) + ((n) >> (shift - 1)))) + +#define CASE5( a, b, c, d, e ) case 0x##a:case 0x##b:case 0x##c:case 0x##d:case 0x##e +#define CASE6( a, b, c, d, e, f ) CASE5( a, b, c, d, e ): case 0x##f +#define CASE7( a, b, c, d, e, f, g ) CASE6( a, b, c, d, e, f ): case 0x##g +#define CASE8( a, b, c, d, e, f, g, h ) CASE7( a, b, c, d, e, f, g ): case 0x##h + +// high four bits are $ED time - 8, low four bits are $DD/$FD time - 8 +static byte const ed_dd_timing [0x100] = { +//0 1 2 3 4 5 6 7 8 9 A B C D E F +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x06,0x0C,0x02,0x00,0x00,0x03,0x00,0x00,0x07,0x0C,0x02,0x00,0x00,0x03,0x00, +0x00,0x00,0x00,0x00,0x0F,0x0F,0x0B,0x00,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00, +0x40,0x40,0x70,0xC0,0x00,0x60,0x0B,0x10,0x40,0x40,0x70,0xC0,0x00,0x60,0x0B,0x10, +0x40,0x40,0x70,0xC0,0x00,0x60,0x0B,0x10,0x40,0x40,0x70,0xC0,0x00,0x60,0x0B,0x10, +0x40,0x40,0x70,0xC0,0x00,0x60,0x0B,0xA0,0x40,0x40,0x70,0xC0,0x00,0x60,0x0B,0xA0, +0x4B,0x4B,0x7B,0xCB,0x0B,0x6B,0x00,0x0B,0x40,0x40,0x70,0xC0,0x00,0x60,0x0B,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x0B,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0B,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x0B,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0B,0x00, +0x80,0x80,0x80,0x80,0x00,0x00,0x0B,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x0B,0x00, +0xD0,0xD0,0xD0,0xD0,0x00,0x00,0x0B,0x00,0xD0,0xD0,0xD0,0xD0,0x00,0x00,0x0B,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x06,0x00,0x0F,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00, +}; + +// even on x86, using short and unsigned char was slower +typedef int fint16; +typedef unsigned fuint16; +typedef unsigned fuint8; + +bool Ay_Cpu::run( cpu_time_t end_time ) +{ + set_end_time( end_time ); + state_t s = this->state_; + this->state = &s; + bool warning = false; + + typedef BOOST::int8_t int8_t; + + union { + regs_t rg; + pairs_t rp; + uint8_t r8_ [8]; // indexed + uint16_t r16_ [4]; + }; + rg = this->r.b; + + cpu_time_t s_time = s.time; + uint8_t* const mem = this->mem; // cache + fuint16 pc = r.pc; + fuint16 sp = r.sp; + fuint16 ix = r.ix; // TODO: keep in memory for direct access? + fuint16 iy = r.iy; + int flags = r.b.flags; + + goto loop; +jr_not_taken: + s_time -= 5; + goto loop; +call_not_taken: + s_time -= 7; +jp_not_taken: + pc += 2; +loop: + + check( (unsigned long) pc < 0x10000 ); + check( (unsigned long) sp < 0x10000 ); + check( (unsigned) flags < 0x100 ); + check( (unsigned) ix < 0x10000 ); + check( (unsigned) iy < 0x10000 ); + + fuint8 opcode; + opcode = READ_PROG( pc ); + pc++; + + static byte const base_timing [0x100] = { + // 0 1 2 3 4 5 6 7 8 9 A B C D E F + 4,10, 7, 6, 4, 4, 7, 4, 4,11, 7, 6, 4, 4, 7, 4, // 0 + 13,10, 7, 6, 4, 4, 7, 4,12,11, 7, 6, 4, 4, 7, 4, // 1 + 12,10,16, 6, 4, 4, 7, 4,12,11,16, 6, 4, 4, 7, 4, // 2 + 12,10,13, 6,11,11,10, 4,12,11,13, 6, 4, 4, 7, 4, // 3 + 4, 4, 4, 4, 4, 4, 7, 4, 4, 4, 4, 4, 4, 4, 7, 4, // 4 + 4, 4, 4, 4, 4, 4, 7, 4, 4, 4, 4, 4, 4, 4, 7, 4, // 5 + 4, 4, 4, 4, 4, 4, 7, 4, 4, 4, 4, 4, 4, 4, 7, 4, // 6 + 7, 7, 7, 7, 7, 7, 4, 7, 4, 4, 4, 4, 4, 4, 7, 4, // 7 + 4, 4, 4, 4, 4, 4, 7, 4, 4, 4, 4, 4, 4, 4, 7, 4, // 8 + 4, 4, 4, 4, 4, 4, 7, 4, 4, 4, 4, 4, 4, 4, 7, 4, // 9 + 4, 4, 4, 4, 4, 4, 7, 4, 4, 4, 4, 4, 4, 4, 7, 4, // A + 4, 4, 4, 4, 4, 4, 7, 4, 4, 4, 4, 4, 4, 4, 7, 4, // B + 11,10,10,10,17,11, 7,11,11,10,10, 8,17,17, 7,11, // C + 11,10,10,11,17,11, 7,11,11, 4,10,11,17, 8, 7,11, // D + 11,10,10,19,17,11, 7,11,11, 4,10, 4,17, 8, 7,11, // E + 11,10,10, 4,17,11, 7,11,11, 6,10, 4,17, 8, 7,11, // F + }; + + fuint16 data; + data = base_timing [opcode]; + if ( (s_time += data) >= 0 ) + goto possibly_out_of_time; +almost_out_of_time: + + data = READ_PROG( pc ); + + #ifdef Z80_CPU_LOG_H + //log_opcode( opcode, READ_PROG( pc ) ); + z80_log_regs( rg.a, rp.bc, rp.de, rp.hl, sp, ix, iy ); + z80_cpu_log( "new", pc - 1, opcode, READ_PROG( pc ), + READ_PROG( pc + 1 ), READ_PROG( pc + 2 ) ); + #endif + + switch ( opcode ) + { +possibly_out_of_time: + if ( s_time < (int) data ) + goto almost_out_of_time; + s_time -= data; + goto out_of_time; + +// Common + + case 0x00: // NOP + CASE7( 40, 49, 52, 5B, 64, 6D, 7F ): // LD B,B etc. + goto loop; + + case 0x08:{// EX AF,AF' + int temp = r.alt.b.a; + r.alt.b.a = rg.a; + rg.a = temp; + + temp = r.alt.b.flags; + r.alt.b.flags = flags; + flags = temp; + goto loop; + } + + case 0xD3: // OUT (imm),A + pc++; + OUT( data + rg.a * 0x100, rg.a ); + goto loop; + + case 0x2E: // LD L,imm + pc++; + rg.l = data; + goto loop; + + case 0x3E: // LD A,imm + pc++; + rg.a = data; + goto loop; + + case 0x3A:{// LD A,(addr) + fuint16 addr = GET_ADDR(); + pc += 2; + rg.a = READ( addr ); + goto loop; + } + +// Conditional + +#define ZERO (flags & Z40) +#define CARRY (flags & C01) +#define EVEN (flags & P04) +#define MINUS (flags & S80) + +// JR +#define JR( cond ) {\ + int disp = (BOOST::int8_t) data;\ + pc++;\ + if ( !(cond) )\ + goto jr_not_taken;\ + pc += disp;\ + goto loop;\ +} + + case 0x20: JR( !ZERO ) // JR NZ,disp + case 0x28: JR( ZERO ) // JR Z,disp + case 0x30: JR( !CARRY ) // JR NC,disp + case 0x38: JR( CARRY ) // JR C,disp + case 0x18: JR( true ) // JR disp + + case 0x10:{// DJNZ disp + int temp = rg.b - 1; + rg.b = temp; + JR( temp ) + } + +// JP +#define JP( cond ) if ( !(cond) ) goto jp_not_taken; pc = GET_ADDR(); goto loop; + + case 0xC2: JP( !ZERO ) // JP NZ,addr + case 0xCA: JP( ZERO ) // JP Z,addr + case 0xD2: JP( !CARRY ) // JP NC,addr + case 0xDA: JP( CARRY ) // JP C,addr + case 0xE2: JP( !EVEN ) // JP PO,addr + case 0xEA: JP( EVEN ) // JP PE,addr + case 0xF2: JP( !MINUS ) // JP P,addr + case 0xFA: JP( MINUS ) // JP M,addr + + case 0xC3: // JP addr + pc = GET_ADDR(); + goto loop; + + case 0xE9: // JP HL + pc = rp.hl; + goto loop; + +// RET +#define RET( cond ) if ( cond ) goto ret_taken; s_time -= 6; goto loop; + + case 0xC0: RET( !ZERO ) // RET NZ + case 0xC8: RET( ZERO ) // RET Z + case 0xD0: RET( !CARRY ) // RET NC + case 0xD8: RET( CARRY ) // RET C + case 0xE0: RET( !EVEN ) // RET PO + case 0xE8: RET( EVEN ) // RET PE + case 0xF0: RET( !MINUS ) // RET P + case 0xF8: RET( MINUS ) // RET M + + case 0xC9: // RET + ret_taken: + pc = READ_WORD( sp ); + sp = uint16_t (sp + 2); + goto loop; + +// CALL +#define CALL( cond ) if ( cond ) goto call_taken; goto call_not_taken; + + case 0xC4: CALL( !ZERO ) // CALL NZ,addr + case 0xCC: CALL( ZERO ) // CALL Z,addr + case 0xD4: CALL( !CARRY ) // CALL NC,addr + case 0xDC: CALL( CARRY ) // CALL C,addr + case 0xE4: CALL( !EVEN ) // CALL PO,addr + case 0xEC: CALL( EVEN ) // CALL PE,addr + case 0xF4: CALL( !MINUS ) // CALL P,addr + case 0xFC: CALL( MINUS ) // CALL M,addr + + case 0xCD:{// CALL addr + call_taken: + fuint16 addr = pc + 2; + pc = GET_ADDR(); + sp = uint16_t (sp - 2); + WRITE_WORD( sp, addr ); + goto loop; + } + + case 0xFF: // RST + if ( (pc - 1) > 0xFFFF ) + { + pc = uint16_t (pc - 1); + s_time -= 11; + goto loop; + } + CASE7( C7, CF, D7, DF, E7, EF, F7 ): + data = pc; + pc = opcode & 0x38; + goto push_data; + +// PUSH/POP + case 0xF5: // PUSH AF + data = rg.a * 0x100u + flags; + goto push_data; + + case 0xC5: // PUSH BC + case 0xD5: // PUSH DE + case 0xE5: // PUSH HL + data = R16( opcode, 4, 0xC5 ); + push_data: + sp = uint16_t (sp - 2); + WRITE_WORD( sp, data ); + goto loop; + + case 0xF1: // POP AF + flags = READ( sp ); + rg.a = READ( sp + 1 ); + sp = uint16_t (sp + 2); + goto loop; + + case 0xC1: // POP BC + case 0xD1: // POP DE + case 0xE1: // POP HL + R16( opcode, 4, 0xC1 ) = READ_WORD( sp ); + sp = uint16_t (sp + 2); + goto loop; + +// ADC/ADD/SBC/SUB + case 0x96: // SUB (HL) + case 0x86: // ADD (HL) + flags &= ~C01; + case 0x9E: // SBC (HL) + case 0x8E: // ADC (HL) + data = READ( rp.hl ); + goto adc_data; + + case 0xD6: // SUB A,imm + case 0xC6: // ADD imm + flags &= ~C01; + case 0xDE: // SBC A,imm + case 0xCE: // ADC imm + pc++; + goto adc_data; + + CASE7( 90, 91, 92, 93, 94, 95, 97 ): // SUB r + CASE7( 80, 81, 82, 83, 84, 85, 87 ): // ADD r + flags &= ~C01; + CASE7( 98, 99, 9A, 9B, 9C, 9D, 9F ): // SBC r + CASE7( 88, 89, 8A, 8B, 8C, 8D, 8F ): // ADC r + data = R8( opcode & 7, 0 ); + adc_data: { + int result = data + (flags & C01); + data ^= rg.a; + flags = opcode >> 3 & N02; // bit 4 is set in subtract opcodes + if ( flags ) + result = -result; + result += rg.a; + data ^= result; + flags |=(data & H10) | + ((data - -0x80) >> 6 & V04) | + SZ28C( result & 0x1FF ); + rg.a = result; + goto loop; + } + +// CP + case 0xBE: // CP (HL) + data = READ( rp.hl ); + goto cp_data; + + case 0xFE: // CP imm + pc++; + goto cp_data; + + CASE7( B8, B9, BA, BB, BC, BD, BF ): // CP r + data = R8( opcode, 0xB8 ); + cp_data: { + int result = rg.a - data; + flags = N02 | (data & (F20 | F08)) | (result >> 8 & C01); + data ^= rg.a; + flags |=(((result ^ rg.a) & data) >> 5 & V04) | + (((data & H10) ^ result) & (S80 | H10)); + if ( (uint8_t) result ) + goto loop; + flags |= Z40; + goto loop; + } + +// ADD HL,rp + + case 0x39: // ADD HL,SP + data = sp; + goto add_hl_data; + + case 0x09: // ADD HL,BC + case 0x19: // ADD HL,DE + case 0x29: // ADD HL,HL + data = R16( opcode, 4, 0x09 ); + add_hl_data: { + blargg_ulong sum = rp.hl + data; + data ^= rp.hl; + rp.hl = sum; + flags = (flags & (S80 | Z40 | V04)) | + (sum >> 16) | + (sum >> 8 & (F20 | F08)) | + ((data ^ sum) >> 8 & H10); + goto loop; + } + + case 0x27:{// DAA + int a = rg.a; + if ( a > 0x99 ) + flags |= C01; + + int adjust = 0x60 & -(flags & C01); + + if ( flags & H10 || (a & 0x0F) > 9 ) + adjust |= 0x06; + + if ( flags & N02 ) + adjust = -adjust; + a += adjust; + + flags = (flags & (C01 | N02)) | + ((rg.a ^ a) & H10) | + SZ28P( (uint8_t) a ); + rg.a = a; + goto loop; + } + /* + case 0x27:{// DAA + // more optimized, but probably not worth the obscurity + int f = (rg.a + (0xFF - 0x99)) >> 8 | flags; // (a > 0x99 ? C01 : 0) | flags + int adjust = 0x60 & -(f & C01); // f & C01 ? 0x60 : 0 + + if ( (((rg.a + (0x0F - 9)) ^ rg.a) | f) & H10 ) // flags & H10 || (rg.a & 0x0F) > 9 + adjust |= 0x06; + + if ( f & N02 ) + adjust = -adjust; + int a = rg.a + adjust; + + flags = (f & (N02 | C01)) | ((rg.a ^ a) & H10) | SZ28P( (uint8_t) a ); + rg.a = a; + goto loop; + } + */ + +// INC/DEC + case 0x34: // INC (HL) + data = READ( rp.hl ) + 1; + WRITE( rp.hl, data ); + goto inc_set_flags; + + CASE7( 04, 0C, 14, 1C, 24, 2C, 3C ): // INC r + data = ++R8( opcode >> 3, 0 ); + inc_set_flags: + flags = (flags & C01) | + (((data & 0x0F) - 1) & H10) | + SZ28( (uint8_t) data ); + if ( data != 0x80 ) + goto loop; + flags |= V04; + goto loop; + + case 0x35: // DEC (HL) + data = READ( rp.hl ) - 1; + WRITE( rp.hl, data ); + goto dec_set_flags; + + CASE7( 05, 0D, 15, 1D, 25, 2D, 3D ): // DEC r + data = --R8( opcode >> 3, 0 ); + dec_set_flags: + flags = (flags & C01) | N02 | + (((data & 0x0F) + 1) & H10) | + SZ28( (uint8_t) data ); + if ( data != 0x7F ) + goto loop; + flags |= V04; + goto loop; + + case 0x03: // INC BC + case 0x13: // INC DE + case 0x23: // INC HL + R16( opcode, 4, 0x03 )++; + goto loop; + + case 0x33: // INC SP + sp = uint16_t (sp + 1); + goto loop; + + case 0x0B: // DEC BC + case 0x1B: // DEC DE + case 0x2B: // DEC HL + R16( opcode, 4, 0x0B )--; + goto loop; + + case 0x3B: // DEC SP + sp = uint16_t (sp - 1); + goto loop; + +// AND + case 0xA6: // AND (HL) + data = READ( rp.hl ); + goto and_data; + + case 0xE6: // AND imm + pc++; + goto and_data; + + CASE7( A0, A1, A2, A3, A4, A5, A7 ): // AND r + data = R8( opcode, 0xA0 ); + and_data: + rg.a &= data; + flags = SZ28P( rg.a ) | H10; + goto loop; + +// OR + case 0xB6: // OR (HL) + data = READ( rp.hl ); + goto or_data; + + case 0xF6: // OR imm + pc++; + goto or_data; + + CASE7( B0, B1, B2, B3, B4, B5, B7 ): // OR r + data = R8( opcode, 0xB0 ); + or_data: + rg.a |= data; + flags = SZ28P( rg.a ); + goto loop; + +// XOR + case 0xAE: // XOR (HL) + data = READ( rp.hl ); + goto xor_data; + + case 0xEE: // XOR imm + pc++; + goto xor_data; + + CASE7( A8, A9, AA, AB, AC, AD, AF ): // XOR r + data = R8( opcode, 0xA8 ); + xor_data: + rg.a ^= data; + flags = SZ28P( rg.a ); + goto loop; + +// LD + CASE7( 70, 71, 72, 73, 74, 75, 77 ): // LD (HL),r + WRITE( rp.hl, R8( opcode, 0x70 ) ); + goto loop; + + CASE6( 41, 42, 43, 44, 45, 47 ): // LD B,r + CASE6( 48, 4A, 4B, 4C, 4D, 4F ): // LD C,r + CASE6( 50, 51, 53, 54, 55, 57 ): // LD D,r + CASE6( 58, 59, 5A, 5C, 5D, 5F ): // LD E,r + CASE6( 60, 61, 62, 63, 65, 67 ): // LD H,r + CASE6( 68, 69, 6A, 6B, 6C, 6F ): // LD L,r + CASE6( 78, 79, 7A, 7B, 7C, 7D ): // LD A,r + R8( opcode >> 3 & 7, 0 ) = R8( opcode & 7, 0 ); + goto loop; + + CASE5( 06, 0E, 16, 1E, 26 ): // LD r,imm + R8( opcode >> 3, 0 ) = data; + pc++; + goto loop; + + case 0x36: // LD (HL),imm + pc++; + WRITE( rp.hl, data ); + goto loop; + + CASE7( 46, 4E, 56, 5E, 66, 6E, 7E ): // LD r,(HL) + R8( opcode >> 3, 8 ) = READ( rp.hl ); + goto loop; + + case 0x01: // LD rp,imm + case 0x11: + case 0x21: + R16( opcode, 4, 0x01 ) = GET_ADDR(); + pc += 2; + goto loop; + + case 0x31: // LD sp,imm + sp = GET_ADDR(); + pc += 2; + goto loop; + + case 0x2A:{// LD HL,(addr) + fuint16 addr = GET_ADDR(); + pc += 2; + rp.hl = READ_WORD( addr ); + goto loop; + } + + case 0x32:{// LD (addr),A + fuint16 addr = GET_ADDR(); + pc += 2; + WRITE( addr, rg.a ); + goto loop; + } + + case 0x22:{// LD (addr),HL + fuint16 addr = GET_ADDR(); + pc += 2; + WRITE_WORD( addr, rp.hl ); + goto loop; + } + + case 0x02: // LD (BC),A + case 0x12: // LD (DE),A + WRITE( R16( opcode, 4, 0x02 ), rg.a ); + goto loop; + + case 0x0A: // LD A,(BC) + case 0x1A: // LD A,(DE) + rg.a = READ( R16( opcode, 4, 0x0A ) ); + goto loop; + + case 0xF9: // LD SP,HL + sp = rp.hl; + goto loop; + +// Rotate + + case 0x07:{// RLCA + fuint16 temp = rg.a; + temp = (temp << 1) | (temp >> 7); + flags = (flags & (S80 | Z40 | P04)) | + (temp & (F20 | F08 | C01)); + rg.a = temp; + goto loop; + } + + case 0x0F:{// RRCA + fuint16 temp = rg.a; + flags = (flags & (S80 | Z40 | P04)) | + (temp & C01); + temp = (temp << 7) | (temp >> 1); + flags |= temp & (F20 | F08); + rg.a = temp; + goto loop; + } + + case 0x17:{// RLA + blargg_ulong temp = (rg.a << 1) | (flags & C01); + flags = (flags & (S80 | Z40 | P04)) | + (temp & (F20 | F08)) | + (temp >> 8); + rg.a = temp; + goto loop; + } + + case 0x1F:{// RRA + fuint16 temp = (flags << 7) | (rg.a >> 1); + flags = (flags & (S80 | Z40 | P04)) | + (temp & (F20 | F08)) | + (rg.a & C01); + rg.a = temp; + goto loop; + } + +// Misc + case 0x2F:{// CPL + fuint16 temp = ~rg.a; + flags = (flags & (S80 | Z40 | P04 | C01)) | + (temp & (F20 | F08)) | + (H10 | N02); + rg.a = temp; + goto loop; + } + + case 0x3F:{// CCF + flags = ((flags & (S80 | Z40 | P04 | C01)) ^ C01) | + (flags << 4 & H10) | + (rg.a & (F20 | F08)); + goto loop; + } + + case 0x37: // SCF + flags = (flags & (S80 | Z40 | P04)) | C01 | + (rg.a & (F20 | F08)); + goto loop; + + case 0xDB: // IN A,(imm) + pc++; + rg.a = IN( data + rg.a * 0x100 ); + goto loop; + + case 0xE3:{// EX (SP),HL + fuint16 temp = READ_WORD( sp ); + WRITE_WORD( sp, rp.hl ); + rp.hl = temp; + goto loop; + } + + case 0xEB:{// EX DE,HL + fuint16 temp = rp.hl; + rp.hl = rp.de; + rp.de = temp; + goto loop; + } + + case 0xD9:{// EXX DE,HL + fuint16 temp = r.alt.w.bc; + r.alt.w.bc = rp.bc; + rp.bc = temp; + + temp = r.alt.w.de; + r.alt.w.de = rp.de; + rp.de = temp; + + temp = r.alt.w.hl; + r.alt.w.hl = rp.hl; + rp.hl = temp; + goto loop; + } + + case 0xF3: // DI + r.iff1 = 0; + r.iff2 = 0; + goto loop; + + case 0xFB: // EI + r.iff1 = 1; + r.iff2 = 1; + // TODO: delayed effect + goto loop; + + case 0x76: // HALT + goto halt; + +//////////////////////////////////////// CB prefix + { + case 0xCB: + unsigned data2; + data2 = INSTR( 1 ); + (void) data2; // TODO is this the same as data in all cases? + pc++; + switch ( data ) + { + + // Rotate left + + #define RLC( read, write ) {\ + fuint8 result = read;\ + result = uint8_t (result << 1) | (result >> 7);\ + flags = SZ28P( result ) | (result & C01);\ + write;\ + goto loop;\ + } + + case 0x06: // RLC (HL) + s_time += 7; + data = rp.hl; + rlc_data_addr: + RLC( READ( data ), WRITE( data, result ) ) + + CASE7( 00, 01, 02, 03, 04, 05, 07 ):{// RLC r + uint8_t& reg = R8( data, 0 ); + RLC( reg, reg = result ) + } + + #define RL( read, write ) {\ + fuint16 result = (read << 1) | (flags & C01);\ + flags = SZ28PC( result );\ + write;\ + goto loop;\ + } + + case 0x16: // RL (HL) + s_time += 7; + data = rp.hl; + rl_data_addr: + RL( READ( data ), WRITE( data, result ) ) + + CASE7( 10, 11, 12, 13, 14, 15, 17 ):{// RL r + uint8_t& reg = R8( data, 0x10 ); + RL( reg, reg = result ) + } + + #define SLA( read, add, write ) {\ + fuint16 result = (read << 1) | add;\ + flags = SZ28PC( result );\ + write;\ + goto loop;\ + } + + case 0x26: // SLA (HL) + s_time += 7; + data = rp.hl; + sla_data_addr: + SLA( READ( data ), 0, WRITE( data, result ) ) + + CASE7( 20, 21, 22, 23, 24, 25, 27 ):{// SLA r + uint8_t& reg = R8( data, 0x20 ); + SLA( reg, 0, reg = result ) + } + + case 0x36: // SLL (HL) + s_time += 7; + data = rp.hl; + sll_data_addr: + SLA( READ( data ), 1, WRITE( data, result ) ) + + CASE7( 30, 31, 32, 33, 34, 35, 37 ):{// SLL r + uint8_t& reg = R8( data, 0x30 ); + SLA( reg, 1, reg = result ) + } + + // Rotate right + + #define RRC( read, write ) {\ + fuint8 result = read;\ + flags = result & C01;\ + result = uint8_t (result << 7) | (result >> 1);\ + flags |= SZ28P( result );\ + write;\ + goto loop;\ + } + + case 0x0E: // RRC (HL) + s_time += 7; + data = rp.hl; + rrc_data_addr: + RRC( READ( data ), WRITE( data, result ) ) + + CASE7( 08, 09, 0A, 0B, 0C, 0D, 0F ):{// RRC r + uint8_t& reg = R8( data, 0x08 ); + RRC( reg, reg = result ) + } + + #define RR( read, write ) {\ + fuint8 result = read;\ + fuint8 temp = result & C01;\ + result = uint8_t (flags << 7) | (result >> 1);\ + flags = SZ28P( result ) | temp;\ + write;\ + goto loop;\ + } + + case 0x1E: // RR (HL) + s_time += 7; + data = rp.hl; + rr_data_addr: + RR( READ( data ), WRITE( data, result ) ) + + CASE7( 18, 19, 1A, 1B, 1C, 1D, 1F ):{// RR r + uint8_t& reg = R8( data, 0x18 ); + RR( reg, reg = result ) + } + + #define SRA( read, write ) {\ + fuint8 result = read;\ + flags = result & C01;\ + result = (result & 0x80) | (result >> 1);\ + flags |= SZ28P( result );\ + write;\ + goto loop;\ + } + + case 0x2E: // SRA (HL) + data = rp.hl; + s_time += 7; + sra_data_addr: + SRA( READ( data ), WRITE( data, result ) ) + + CASE7( 28, 29, 2A, 2B, 2C, 2D, 2F ):{// SRA r + uint8_t& reg = R8( data, 0x28 ); + SRA( reg, reg = result ) + } + + #define SRL( read, write ) {\ + fuint8 result = read;\ + flags = result & C01;\ + result >>= 1;\ + flags |= SZ28P( result );\ + write;\ + goto loop;\ + } + + case 0x3E: // SRL (HL) + s_time += 7; + data = rp.hl; + srl_data_addr: + SRL( READ( data ), WRITE( data, result ) ) + + CASE7( 38, 39, 3A, 3B, 3C, 3D, 3F ):{// SRL r + uint8_t& reg = R8( data, 0x38 ); + SRL( reg, reg = result ) + } + + // BIT + { + unsigned temp; + CASE8( 46, 4E, 56, 5E, 66, 6E, 76, 7E ): // BIT b,(HL) + s_time += 4; + temp = READ( rp.hl ); + flags &= C01; + goto bit_temp; + CASE7( 40, 41, 42, 43, 44, 45, 47 ): // BIT 0,r + CASE7( 48, 49, 4A, 4B, 4C, 4D, 4F ): // BIT 1,r + CASE7( 50, 51, 52, 53, 54, 55, 57 ): // BIT 2,r + CASE7( 58, 59, 5A, 5B, 5C, 5D, 5F ): // BIT 3,r + CASE7( 60, 61, 62, 63, 64, 65, 67 ): // BIT 4,r + CASE7( 68, 69, 6A, 6B, 6C, 6D, 6F ): // BIT 5,r + CASE7( 70, 71, 72, 73, 74, 75, 77 ): // BIT 6,r + CASE7( 78, 79, 7A, 7B, 7C, 7D, 7F ): // BIT 7,r + temp = R8( data & 7, 0 ); + flags = (flags & C01) | (temp & (F20 | F08)); + bit_temp: + int masked = temp & 1 << (data >> 3 & 7); + flags |=(masked & S80) | H10 | + ((masked - 1) >> 8 & (Z40 | P04)); + goto loop; + } + + // SET/RES + CASE8( 86, 8E, 96, 9E, A6, AE, B6, BE ): // RES b,(HL) + CASE8( C6, CE, D6, DE, E6, EE, F6, FE ):{// SET b,(HL) + s_time += 7; + int temp = READ( rp.hl ); + int bit = 1 << (data >> 3 & 7); + temp |= bit; // SET + if ( !(data & 0x40) ) + temp ^= bit; // RES + WRITE( rp.hl, temp ); + goto loop; + } + + CASE7( C0, C1, C2, C3, C4, C5, C7 ): // SET 0,r + CASE7( C8, C9, CA, CB, CC, CD, CF ): // SET 1,r + CASE7( D0, D1, D2, D3, D4, D5, D7 ): // SET 2,r + CASE7( D8, D9, DA, DB, DC, DD, DF ): // SET 3,r + CASE7( E0, E1, E2, E3, E4, E5, E7 ): // SET 4,r + CASE7( E8, E9, EA, EB, EC, ED, EF ): // SET 5,r + CASE7( F0, F1, F2, F3, F4, F5, F7 ): // SET 6,r + CASE7( F8, F9, FA, FB, FC, FD, FF ): // SET 7,r + R8( data & 7, 0 ) |= 1 << (data >> 3 & 7); + goto loop; + + CASE7( 80, 81, 82, 83, 84, 85, 87 ): // RES 0,r + CASE7( 88, 89, 8A, 8B, 8C, 8D, 8F ): // RES 1,r + CASE7( 90, 91, 92, 93, 94, 95, 97 ): // RES 2,r + CASE7( 98, 99, 9A, 9B, 9C, 9D, 9F ): // RES 3,r + CASE7( A0, A1, A2, A3, A4, A5, A7 ): // RES 4,r + CASE7( A8, A9, AA, AB, AC, AD, AF ): // RES 5,r + CASE7( B0, B1, B2, B3, B4, B5, B7 ): // RES 6,r + CASE7( B8, B9, BA, BB, BC, BD, BF ): // RES 7,r + R8( data & 7, 0 ) &= ~(1 << (data >> 3 & 7)); + goto loop; + } + assert( false ); + } + +//////////////////////////////////////// ED prefix + { + case 0xED: + pc++; + s_time += ed_dd_timing [data] >> 4; + switch ( data ) + { + { + blargg_ulong temp; + case 0x72: // SBC HL,SP + case 0x7A: // ADC HL,SP + temp = sp; + if ( 0 ) + case 0x42: // SBC HL,BC + case 0x52: // SBC HL,DE + case 0x62: // SBC HL,HL + case 0x4A: // ADC HL,BC + case 0x5A: // ADC HL,DE + case 0x6A: // ADC HL,HL + temp = R16( data >> 3 & 6, 1, 0 ); + blargg_ulong sum = temp + (flags & C01); + flags = ~data >> 2 & N02; + if ( flags ) + sum = -sum; + sum += rp.hl; + temp ^= rp.hl; + temp ^= sum; + flags |=(sum >> 16 & C01) | + (temp >> 8 & H10) | + (sum >> 8 & (S80 | F20 | F08)) | + ((temp - -0x8000) >> 14 & V04); + rp.hl = sum; + if ( (uint16_t) sum ) + goto loop; + flags |= Z40; + goto loop; + } + + CASE8( 40, 48, 50, 58, 60, 68, 70, 78 ):{// IN r,(C) + int temp = IN( rp.bc ); + R8( data >> 3, 8 ) = temp; + flags = (flags & C01) | SZ28P( temp ); + goto loop; + } + + case 0x71: // OUT (C),0 + rg.flags = 0; + CASE7( 41, 49, 51, 59, 61, 69, 79 ): // OUT (C),r + OUT( rp.bc, R8( data >> 3, 8 ) ); + goto loop; + + { + unsigned temp; + case 0x73: // LD (ADDR),SP + temp = sp; + if ( 0 ) + case 0x43: // LD (ADDR),BC + case 0x53: // LD (ADDR),DE + temp = R16( data, 4, 0x43 ); + fuint16 addr = GET_ADDR(); + pc += 2; + WRITE_WORD( addr, temp ); + goto loop; + } + + case 0x4B: // LD BC,(ADDR) + case 0x5B:{// LD DE,(ADDR) + fuint16 addr = GET_ADDR(); + pc += 2; + R16( data, 4, 0x4B ) = READ_WORD( addr ); + goto loop; + } + + case 0x7B:{// LD SP,(ADDR) + fuint16 addr = GET_ADDR(); + pc += 2; + sp = READ_WORD( addr ); + goto loop; + } + + case 0x67:{// RRD + fuint8 temp = READ( rp.hl ); + WRITE( rp.hl, (rg.a << 4) | (temp >> 4) ); + temp = (rg.a & 0xF0) | (temp & 0x0F); + flags = (flags & C01) | SZ28P( temp ); + rg.a = temp; + goto loop; + } + + case 0x6F:{// RLD + fuint8 temp = READ( rp.hl ); + WRITE( rp.hl, (temp << 4) | (rg.a & 0x0F) ); + temp = (rg.a & 0xF0) | (temp >> 4); + flags = (flags & C01) | SZ28P( temp ); + rg.a = temp; + goto loop; + } + + CASE8( 44, 4C, 54, 5C, 64, 6C, 74, 7C ): // NEG + opcode = 0x10; // flag to do SBC instead of ADC + flags &= ~C01; + data = rg.a; + rg.a = 0; + goto adc_data; + + { + int inc; + case 0xA9: // CPD + case 0xB9: // CPDR + inc = -1; + if ( 0 ) + case 0xA1: // CPI + case 0xB1: // CPIR + inc = +1; + fuint16 addr = rp.hl; + rp.hl = addr + inc; + int temp = READ( addr ); + + int result = rg.a - temp; + flags = (flags & C01) | N02 | + ((((temp ^ rg.a) & H10) ^ result) & (S80 | H10)); + + if ( !(uint8_t) result ) flags |= Z40; + result -= (flags & H10) >> 4; + flags |= result & F08; + flags |= result << 4 & F20; + if ( !--rp.bc ) + goto loop; + + flags |= V04; + if ( flags & Z40 || data < 0xB0 ) + goto loop; + + pc -= 2; + s_time += 5; + goto loop; + } + + { + int inc; + case 0xA8: // LDD + case 0xB8: // LDDR + inc = -1; + if ( 0 ) + case 0xA0: // LDI + case 0xB0: // LDIR + inc = +1; + fuint16 addr = rp.hl; + rp.hl = addr + inc; + int temp = READ( addr ); + + addr = rp.de; + rp.de = addr + inc; + WRITE( addr, temp ); + + temp += rg.a; + flags = (flags & (S80 | Z40 | C01)) | + (temp & F08) | (temp << 4 & F20); + if ( !--rp.bc ) + goto loop; + + flags |= V04; + if ( data < 0xB0 ) + goto loop; + + pc -= 2; + s_time += 5; + goto loop; + } + + { + int inc; + case 0xAB: // OUTD + case 0xBB: // OTDR + inc = -1; + if ( 0 ) + case 0xA3: // OUTI + case 0xB3: // OTIR + inc = +1; + fuint16 addr = rp.hl; + rp.hl = addr + inc; + int temp = READ( addr ); + + int b = --rg.b; + flags = (temp >> 6 & N02) | SZ28( b ); + if ( b && data >= 0xB0 ) + { + pc -= 2; + s_time += 5; + } + + OUT( rp.bc, temp ); + goto loop; + } + + { + int inc; + case 0xAA: // IND + case 0xBA: // INDR + inc = -1; + if ( 0 ) + case 0xA2: // INI + case 0xB2: // INIR + inc = +1; + + fuint16 addr = rp.hl; + rp.hl = addr + inc; + + int temp = IN( rp.bc ); + + int b = --rg.b; + flags = (temp >> 6 & N02) | SZ28( b ); + if ( b && data >= 0xB0 ) + { + pc -= 2; + s_time += 5; + } + + WRITE( addr, temp ); + goto loop; + } + + case 0x47: // LD I,A + r.i = rg.a; + goto loop; + + case 0x4F: // LD R,A + SET_R( rg.a ); + debug_printf( "LD R,A not supported\n" ); + warning = true; + goto loop; + + case 0x57: // LD A,I + rg.a = r.i; + goto ld_ai_common; + + case 0x5F: // LD A,R + rg.a = GET_R(); + debug_printf( "LD A,R not supported\n" ); + warning = true; + ld_ai_common: + flags = (flags & C01) | SZ28( rg.a ) | (r.iff2 << 2 & V04); + goto loop; + + CASE8( 45, 4D, 55, 5D, 65, 6D, 75, 7D ): // RETI/RETN + r.iff1 = r.iff2; + goto ret_taken; + + case 0x46: case 0x4E: case 0x66: case 0x6E: // IM 0 + r.im = 0; + goto loop; + + case 0x56: case 0x76: // IM 1 + r.im = 1; + goto loop; + + case 0x5E: case 0x7E: // IM 2 + r.im = 2; + goto loop; + + default: + debug_printf( "Opcode $ED $%02X not supported\n", data ); + warning = true; + goto loop; + } + assert( false ); + } + +//////////////////////////////////////// DD/FD prefix + { + fuint16 ixy; + case 0xDD: + ixy = ix; + goto ix_prefix; + case 0xFD: + ixy = iy; + ix_prefix: + pc++; + unsigned data2 = READ_PROG( pc ); + s_time += ed_dd_timing [data] & 0x0F; + switch ( data ) + { + // TODO: more efficient way of avoid negative address + #define IXY_DISP( ixy, disp ) uint16_t ((ixy) + (disp)) + + #define SET_IXY( in ) if ( opcode == 0xDD ) ix = in; else iy = in; + + // ADD/ADC/SUB/SBC + + case 0x96: // SUB (IXY+disp) + case 0x86: // ADD (IXY+disp) + flags &= ~C01; + case 0x9E: // SBC (IXY+disp) + case 0x8E: // ADC (IXY+disp) + pc++; + opcode = data; + data = READ( IXY_DISP( ixy, (int8_t) data2 ) ); + goto adc_data; + + case 0x94: // SUB HXY + case 0x84: // ADD HXY + flags &= ~C01; + case 0x9C: // SBC HXY + case 0x8C: // ADC HXY + opcode = data; + data = ixy >> 8; + goto adc_data; + + case 0x95: // SUB LXY + case 0x85: // ADD LXY + flags &= ~C01; + case 0x9D: // SBC LXY + case 0x8D: // ADC LXY + opcode = data; + data = (uint8_t) ixy; + goto adc_data; + + { + unsigned temp; + case 0x39: // ADD IXY,SP + temp = sp; + goto add_ixy_data; + + case 0x29: // ADD IXY,HL + temp = ixy; + goto add_ixy_data; + + case 0x09: // ADD IXY,BC + case 0x19: // ADD IXY,DE + temp = R16( data, 4, 0x09 ); + add_ixy_data: { + blargg_ulong sum = ixy + temp; + temp ^= ixy; + ixy = (uint16_t) sum; + flags = (flags & (S80 | Z40 | V04)) | + (sum >> 16) | + (sum >> 8 & (F20 | F08)) | + ((temp ^ sum) >> 8 & H10); + goto set_ixy; + } + } + + // AND + case 0xA6: // AND (IXY+disp) + pc++; + data = READ( IXY_DISP( ixy, (int8_t) data2 ) ); + goto and_data; + + case 0xA4: // AND HXY + data = ixy >> 8; + goto and_data; + + case 0xA5: // AND LXY + data = (uint8_t) ixy; + goto and_data; + + // OR + case 0xB6: // OR (IXY+disp) + pc++; + data = READ( IXY_DISP( ixy, (int8_t) data2 ) ); + goto or_data; + + case 0xB4: // OR HXY + data = ixy >> 8; + goto or_data; + + case 0xB5: // OR LXY + data = (uint8_t) ixy; + goto or_data; + + // XOR + case 0xAE: // XOR (IXY+disp) + pc++; + data = READ( IXY_DISP( ixy, (int8_t) data2 ) ); + goto xor_data; + + case 0xAC: // XOR HXY + data = ixy >> 8; + goto xor_data; + + case 0xAD: // XOR LXY + data = (uint8_t) ixy; + goto xor_data; + + // CP + case 0xBE: // CP (IXY+disp) + pc++; + data = READ( IXY_DISP( ixy, (int8_t) data2 ) ); + goto cp_data; + + case 0xBC: // CP HXY + data = ixy >> 8; + goto cp_data; + + case 0xBD: // CP LXY + data = (uint8_t) ixy; + goto cp_data; + + // LD + CASE7( 70, 71, 72, 73, 74, 75, 77 ): // LD (IXY+disp),r + data = R8( data, 0x70 ); + if ( 0 ) + case 0x36: // LD (IXY+disp),imm + pc++, data = READ_PROG( pc ); + pc++; + WRITE( IXY_DISP( ixy, (int8_t) data2 ), data ); + goto loop; + + CASE5( 44, 4C, 54, 5C, 7C ): // LD r,HXY + R8( data >> 3, 8 ) = ixy >> 8; + goto loop; + + case 0x64: // LD HXY,HXY + case 0x6D: // LD LXY,LXY + goto loop; + + CASE5( 45, 4D, 55, 5D, 7D ): // LD r,LXY + R8( data >> 3, 8 ) = ixy; + goto loop; + + CASE7( 46, 4E, 56, 5E, 66, 6E, 7E ): // LD r,(IXY+disp) + pc++; + R8( data >> 3, 8 ) = READ( IXY_DISP( ixy, (int8_t) data2 ) ); + goto loop; + + case 0x26: // LD HXY,imm + pc++; + goto ld_hxy_data; + + case 0x65: // LD HXY,LXY + data2 = (uint8_t) ixy; + goto ld_hxy_data; + + CASE5( 60, 61, 62, 63, 67 ): // LD HXY,r + data2 = R8( data, 0x60 ); + ld_hxy_data: + ixy = (uint8_t) ixy | (data2 << 8); + goto set_ixy; + + case 0x2E: // LD LXY,imm + pc++; + goto ld_lxy_data; + + case 0x6C: // LD LXY,HXY + data2 = ixy >> 8; + goto ld_lxy_data; + + CASE5( 68, 69, 6A, 6B, 6F ): // LD LXY,r + data2 = R8( data, 0x68 ); + ld_lxy_data: + ixy = (ixy & 0xFF00) | data2; + set_ixy: + if ( opcode == 0xDD ) + { + ix = ixy; + goto loop; + } + iy = ixy; + goto loop; + + case 0xF9: // LD SP,IXY + sp = ixy; + goto loop; + + case 0x22:{// LD (ADDR),IXY + fuint16 addr = GET_ADDR(); + pc += 2; + WRITE_WORD( addr, ixy ); + goto loop; + } + + case 0x21: // LD IXY,imm + ixy = GET_ADDR(); + pc += 2; + goto set_ixy; + + case 0x2A:{// LD IXY,(addr) + fuint16 addr = GET_ADDR(); + ixy = READ_WORD( addr ); + pc += 2; + goto set_ixy; + } + + // DD/FD CB prefix + case 0xCB: { + data = IXY_DISP( ixy, (int8_t) data2 ); + pc++; + data2 = READ_PROG( pc ); + pc++; + switch ( data2 ) + { + case 0x06: goto rlc_data_addr; // RLC (IXY) + case 0x16: goto rl_data_addr; // RL (IXY) + case 0x26: goto sla_data_addr; // SLA (IXY) + case 0x36: goto sll_data_addr; // SLL (IXY) + case 0x0E: goto rrc_data_addr; // RRC (IXY) + case 0x1E: goto rr_data_addr; // RR (IXY) + case 0x2E: goto sra_data_addr; // SRA (IXY) + case 0x3E: goto srl_data_addr; // SRL (IXY) + + CASE8( 46, 4E, 56, 5E, 66, 6E, 76, 7E ):{// BIT b,(IXY+disp) + fuint8 temp = READ( data ); + int masked = temp & 1 << (data2 >> 3 & 7); + flags = (flags & C01) | H10 | + (masked & S80) | + ((masked - 1) >> 8 & (Z40 | P04)); + goto loop; + } + + CASE8( 86, 8E, 96, 9E, A6, AE, B6, BE ): // RES b,(IXY+disp) + CASE8( C6, CE, D6, DE, E6, EE, F6, FE ):{// SET b,(IXY+disp) + int temp = READ( data ); + int bit = 1 << (data2 >> 3 & 7); + temp |= bit; // SET + if ( !(data2 & 0x40) ) + temp ^= bit; // RES + WRITE( data, temp ); + goto loop; + } + + default: + debug_printf( "Opcode $%02X $CB $%02X not supported\n", opcode, data2 ); + warning = true; + goto loop; + } + assert( false ); + } + + // INC/DEC + case 0x23: // INC IXY + ixy = uint16_t (ixy + 1); + goto set_ixy; + + case 0x2B: // DEC IXY + ixy = uint16_t (ixy - 1); + goto set_ixy; + + case 0x34: // INC (IXY+disp) + ixy = IXY_DISP( ixy, (int8_t) data2 ); + pc++; + data = READ( ixy ) + 1; + WRITE( ixy, data ); + goto inc_set_flags; + + case 0x35: // DEC (IXY+disp) + ixy = IXY_DISP( ixy, (int8_t) data2 ); + pc++; + data = READ( ixy ) - 1; + WRITE( ixy, data ); + goto dec_set_flags; + + case 0x24: // INC HXY + ixy = uint16_t (ixy + 0x100); + data = ixy >> 8; + goto inc_xy_common; + + case 0x2C: // INC LXY + data = uint8_t (ixy + 1); + ixy = (ixy & 0xFF00) | data; + inc_xy_common: + if ( opcode == 0xDD ) + { + ix = ixy; + goto inc_set_flags; + } + iy = ixy; + goto inc_set_flags; + + case 0x25: // DEC HXY + ixy = uint16_t (ixy - 0x100); + data = ixy >> 8; + goto dec_xy_common; + + case 0x2D: // DEC LXY + data = uint8_t (ixy - 1); + ixy = (ixy & 0xFF00) | data; + dec_xy_common: + if ( opcode == 0xDD ) + { + ix = ixy; + goto dec_set_flags; + } + iy = ixy; + goto dec_set_flags; + + // PUSH/POP + case 0xE5: // PUSH IXY + data = ixy; + goto push_data; + + case 0xE1:{// POP IXY + ixy = READ_WORD( sp ); + sp = uint16_t (sp + 2); + goto set_ixy; + } + + // Misc + + case 0xE9: // JP (IXY) + pc = ixy; + goto loop; + + case 0xE3:{// EX (SP),IXY + fuint16 temp = READ_WORD( sp ); + WRITE_WORD( sp, ixy ); + ixy = temp; + goto set_ixy; + } + + default: + debug_printf( "Unnecessary DD/FD prefix encountered\n" ); + warning = true; + pc--; + goto loop; + } + assert( false ); + } + + } + debug_printf( "Unhandled main opcode: $%02X\n", opcode ); + assert( false ); + +halt: + s_time &= 3; // increment by multiple of 4 +out_of_time: + pc--; + + s.time = s_time; + rg.flags = flags; + r.ix = ix; + r.iy = iy; + r.sp = sp; + r.pc = pc; + this->r.b = rg; + this->state_ = s; + this->state = &this->state_; + + return warning; +} diff --git a/libs/gme/gme/Ay_Cpu.h b/libs/gme/gme/Ay_Cpu.h new file mode 100644 index 000000000..cd3d66747 --- /dev/null +++ b/libs/gme/gme/Ay_Cpu.h @@ -0,0 +1,92 @@ +// Z80 CPU emulator + +// Game_Music_Emu 0.6.0 +#ifndef AY_CPU_H +#define AY_CPU_H + +#include "blargg_endian.h" + +typedef blargg_long cpu_time_t; + +// must be defined by caller +void ay_cpu_out( class Ay_Cpu*, cpu_time_t, unsigned addr, int data ); +int ay_cpu_in( class Ay_Cpu*, unsigned addr ); + +class Ay_Cpu { +public: + // Clear all registers and keep pointer to 64K memory passed in + void reset( void* mem_64k ); + + // Run until specified time is reached. Returns true if suspicious/unsupported + // instruction was encountered at any point during run. + bool run( cpu_time_t end_time ); + + // Time of beginning of next instruction + cpu_time_t time() const { return state->time + state->base; } + + // Alter current time. Not supported during run() call. + void set_time( cpu_time_t t ) { state->time = t - state->base; } + void adjust_time( int delta ) { state->time += delta; } + + typedef BOOST::uint8_t uint8_t; + typedef BOOST::uint16_t uint16_t; + + #if BLARGG_BIG_ENDIAN + struct regs_t { uint8_t b, c, d, e, h, l, flags, a; }; + #else + struct regs_t { uint8_t c, b, e, d, l, h, a, flags; }; + #endif + BOOST_STATIC_ASSERT( sizeof (regs_t) == 8 ); + + struct pairs_t { uint16_t bc, de, hl, fa; }; + + // Registers are not updated until run() returns + struct registers_t { + uint16_t pc; + uint16_t sp; + uint16_t ix; + uint16_t iy; + union { + regs_t b; // b.b, b.c, b.d, b.e, b.h, b.l, b.flags, b.a + pairs_t w; // w.bc, w.de, w.hl. w.fa + }; + union { + regs_t b; + pairs_t w; + } alt; + uint8_t iff1; + uint8_t iff2; + uint8_t r; + uint8_t i; + uint8_t im; + }; + //registers_t r; (below for efficiency) + + // can read this far past end of memory + enum { cpu_padding = 0x100 }; + +public: + Ay_Cpu(); +private: + uint8_t szpc [0x200]; + uint8_t* mem; + cpu_time_t end_time_; + struct state_t { + cpu_time_t base; + cpu_time_t time; + }; + state_t* state; // points to state_ or a local copy within run() + state_t state_; + void set_end_time( cpu_time_t t ); +public: + registers_t r; +}; + +inline void Ay_Cpu::set_end_time( cpu_time_t t ) +{ + cpu_time_t delta = state->base - t; + state->base = t; + state->time += delta; +} + +#endif diff --git a/libs/gme/gme/Ay_Emu.cpp b/libs/gme/gme/Ay_Emu.cpp new file mode 100644 index 000000000..43670d1bd --- /dev/null +++ b/libs/gme/gme/Ay_Emu.cpp @@ -0,0 +1,405 @@ +// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/ + +#include "Ay_Emu.h" + +#include "blargg_endian.h" +#include + +/* Copyright (C) 2006 Shay Green. This module 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 +module 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 module; if not, write to the Free Software Foundation, +Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + +#include "blargg_source.h" + +long const spectrum_clock = 3546900; +long const cpc_clock = 2000000; + +unsigned const ram_start = 0x4000; +int const osc_count = Ay_Apu::osc_count + 1; + +Ay_Emu::Ay_Emu() +{ + beeper_output = 0; + set_type( gme_ay_type ); + + static const char* const names [osc_count] = { + "Wave 1", "Wave 2", "Wave 3", "Beeper" + }; + set_voice_names( names ); + + static int const types [osc_count] = { + wave_type | 0, wave_type | 1, wave_type | 2, mixed_type | 0 + }; + set_voice_types( types ); + set_silence_lookahead( 6 ); +} + +Ay_Emu::~Ay_Emu() { } + +// Track info + +static byte const* get_data( Ay_Emu::file_t const& file, byte const* ptr, int min_size ) +{ + long pos = ptr - (byte const*) file.header; + long file_size = file.end - (byte const*) file.header; + assert( (unsigned long) pos <= (unsigned long) file_size - 2 ); + int offset = (BOOST::int16_t) get_be16( ptr ); + if ( !offset || blargg_ulong (pos + offset) > blargg_ulong (file_size - min_size) ) + return 0; + return ptr + offset; +} + +static blargg_err_t parse_header( byte const* in, long size, Ay_Emu::file_t* out ) +{ + typedef Ay_Emu::header_t header_t; + out->header = (header_t const*) in; + out->end = in + size; + + if ( size < Ay_Emu::header_size ) + return gme_wrong_file_type; + + header_t const& h = *(header_t const*) in; + if ( memcmp( h.tag, "ZXAYEMUL", 8 ) ) + return gme_wrong_file_type; + + out->tracks = get_data( *out, h.track_info, (h.max_track + 1) * 4 ); + if ( !out->tracks ) + return "Missing track data"; + + return 0; +} + +static void copy_ay_fields( Ay_Emu::file_t const& file, track_info_t* out, int track ) +{ + Gme_File::copy_field_( out->song, (char const*) get_data( file, file.tracks + track * 4, 1 ) ); + byte const* track_info = get_data( file, file.tracks + track * 4 + 2, 6 ); + if ( track_info ) + out->length = get_be16( track_info + 4 ) * (1000L / 50); // frames to msec + + Gme_File::copy_field_( out->author, (char const*) get_data( file, file.header->author, 1 ) ); + Gme_File::copy_field_( out->comment, (char const*) get_data( file, file.header->comment, 1 ) ); +} + +blargg_err_t Ay_Emu::track_info_( track_info_t* out, int track ) const +{ + copy_ay_fields( file, out, track ); + return 0; +} + +struct Ay_File : Gme_Info_ +{ + Ay_Emu::file_t file; + + Ay_File() { set_type( gme_ay_type ); } + + blargg_err_t load_mem_( byte const* begin, long size ) + { + RETURN_ERR( parse_header( begin, size, &file ) ); + set_track_count( file.header->max_track + 1 ); + return 0; + } + + blargg_err_t track_info_( track_info_t* out, int track ) const + { + copy_ay_fields( file, out, track ); + return 0; + } +}; + +static Music_Emu* new_ay_emu () { return BLARGG_NEW Ay_Emu ; } +static Music_Emu* new_ay_file() { return BLARGG_NEW Ay_File; } + +static gme_type_t_ const gme_ay_type_ = { "ZX Spectrum", 0, &new_ay_emu, &new_ay_file, "AY", 1 }; +gme_type_t const gme_ay_type = &gme_ay_type_; + +// Setup + +blargg_err_t Ay_Emu::load_mem_( byte const* in, long size ) +{ + assert( offsetof (header_t,track_info [2]) == header_size ); + + RETURN_ERR( parse_header( in, size, &file ) ); + set_track_count( file.header->max_track + 1 ); + + if ( file.header->vers > 2 ) + set_warning( "Unknown file version" ); + + set_voice_count( osc_count ); + apu.volume( gain() ); + + return setup_buffer( spectrum_clock ); +} + +void Ay_Emu::update_eq( blip_eq_t const& eq ) +{ + apu.treble_eq( eq ); +} + +void Ay_Emu::set_voice( int i, Blip_Buffer* center, Blip_Buffer*, Blip_Buffer* ) +{ + if ( i >= Ay_Apu::osc_count ) + beeper_output = center; + else + apu.osc_output( i, center ); +} + +// Emulation + +void Ay_Emu::set_tempo_( double t ) +{ + play_period = blip_time_t (clock_rate() / 50 / t); +} + +blargg_err_t Ay_Emu::start_track_( int track ) +{ + RETURN_ERR( Classic_Emu::start_track_( track ) ); + + memset( mem.ram + 0x0000, 0xC9, 0x100 ); // fill RST vectors with RET + memset( mem.ram + 0x0100, 0xFF, 0x4000 - 0x100 ); + memset( mem.ram + ram_start, 0x00, sizeof mem.ram - ram_start ); + memset( mem.padding1, 0xFF, sizeof mem.padding1 ); + memset( mem.ram + 0x10000, 0xFF, sizeof mem.ram - 0x10000 ); + + // locate data blocks + byte const* const data = get_data( file, file.tracks + track * 4 + 2, 14 ); + if ( !data ) return "File data missing"; + + byte const* const more_data = get_data( file, data + 10, 6 ); + if ( !more_data ) return "File data missing"; + + byte const* blocks = get_data( file, data + 12, 8 ); + if ( !blocks ) return "File data missing"; + + // initial addresses + cpu::reset( mem.ram ); + r.sp = get_be16( more_data ); + r.b.a = r.b.b = r.b.d = r.b.h = data [8]; + r.b.flags = r.b.c = r.b.e = r.b.l = data [9]; + r.alt.w = r.w; + r.ix = r.iy = r.w.hl; + + unsigned addr = get_be16( blocks ); + if ( !addr ) return "File data missing"; + + unsigned init = get_be16( more_data + 2 ); + if ( !init ) + init = addr; + + // copy blocks into memory + do + { + blocks += 2; + unsigned len = get_be16( blocks ); blocks += 2; + if ( addr + len > 0x10000 ) + { + set_warning( "Bad data block size" ); + len = 0x10000 - addr; + } + check( len ); + byte const* in = get_data( file, blocks, 0 ); blocks += 2; + if ( len > blargg_ulong (file.end - in) ) + { + set_warning( "Missing file data" ); + len = file.end - in; + } + //debug_printf( "addr: $%04X, len: $%04X\n", addr, len ); + if ( addr < ram_start && addr >= 0x400 ) // several tracks use low data + debug_printf( "Block addr in ROM\n" ); + memcpy( mem.ram + addr, in, len ); + + if ( file.end - blocks < 8 ) + { + set_warning( "Missing file data" ); + break; + } + } + while ( (addr = get_be16( blocks )) != 0 ); + + // copy and configure driver + static byte const passive [] = { + 0xF3, // DI + 0xCD, 0, 0, // CALL init + 0xED, 0x5E, // LOOP: IM 2 + 0xFB, // EI + 0x76, // HALT + 0x18, 0xFA // JR LOOP + }; + static byte const active [] = { + 0xF3, // DI + 0xCD, 0, 0, // CALL init + 0xED, 0x56, // LOOP: IM 1 + 0xFB, // EI + 0x76, // HALT + 0xCD, 0, 0, // CALL play + 0x18, 0xF7 // JR LOOP + }; + memcpy( mem.ram, passive, sizeof passive ); + unsigned play_addr = get_be16( more_data + 4 ); + //debug_printf( "Play: $%04X\n", play_addr ); + if ( play_addr ) + { + memcpy( mem.ram, active, sizeof active ); + mem.ram [ 9] = play_addr; + mem.ram [10] = play_addr >> 8; + } + mem.ram [2] = init; + mem.ram [3] = init >> 8; + + mem.ram [0x38] = 0xFB; // Put EI at interrupt vector (followed by RET) + + memcpy( mem.ram + 0x10000, mem.ram, 0x80 ); // some code wraps around (ugh) + + beeper_delta = int (apu.amp_range * 0.65); + last_beeper = 0; + apu.reset(); + next_play = play_period; + + // start at spectrum speed + change_clock_rate( spectrum_clock ); + set_tempo( tempo() ); + + spectrum_mode = false; + cpc_mode = false; + cpc_latch = 0; + + return 0; +} + +// Emulation + +void Ay_Emu::cpu_out_misc( cpu_time_t time, unsigned addr, int data ) +{ + if ( !cpc_mode ) + { + switch ( addr & 0xFEFF ) + { + case 0xFEFD: + spectrum_mode = true; + apu_addr = data & 0x0F; + return; + + case 0xBEFD: + spectrum_mode = true; + apu.write( time, apu_addr, data ); + return; + } + } + + if ( !spectrum_mode ) + { + switch ( addr >> 8 ) + { + case 0xF6: + switch ( data & 0xC0 ) + { + case 0xC0: + apu_addr = cpc_latch & 0x0F; + goto enable_cpc; + + case 0x80: + apu.write( time, apu_addr, cpc_latch ); + goto enable_cpc; + } + break; + + case 0xF4: + cpc_latch = data; + goto enable_cpc; + } + } + + debug_printf( "Unmapped OUT: $%04X <- $%02X\n", addr, data ); + return; + +enable_cpc: + if ( !cpc_mode ) + { + cpc_mode = true; + change_clock_rate( cpc_clock ); + set_tempo( tempo() ); + } +} + +void ay_cpu_out( Ay_Cpu* cpu, cpu_time_t time, unsigned addr, int data ) +{ + Ay_Emu& emu = STATIC_CAST(Ay_Emu&,*cpu); + + if ( (addr & 0xFF) == 0xFE && !emu.cpc_mode ) + { + int delta = emu.beeper_delta; + data &= 0x10; + if ( emu.last_beeper != data ) + { + emu.last_beeper = data; + emu.beeper_delta = -delta; + emu.spectrum_mode = true; + if ( emu.beeper_output ) + emu.apu.synth_.offset( time, delta, emu.beeper_output ); + } + } + else + { + emu.cpu_out_misc( time, addr, data ); + } +} + +int ay_cpu_in( Ay_Cpu*, unsigned addr ) +{ + // keyboard read and other things + if ( (addr & 0xFF) == 0xFE ) + return 0xFF; // other values break some beeper tunes + + debug_printf( "Unmapped IN : $%04X\n", addr ); + return 0xFF; +} + +blargg_err_t Ay_Emu::run_clocks( blip_time_t& duration, int ) +{ + set_time( 0 ); + if ( !(spectrum_mode | cpc_mode) ) + duration /= 2; // until mode is set, leave room for halved clock rate + + while ( time() < duration ) + { + cpu::run( min( duration, (blip_time_t) next_play ) ); + + if ( time() >= next_play ) + { + next_play += play_period; + + if ( r.iff1 ) + { + if ( mem.ram [r.pc] == 0x76 ) + r.pc++; + + r.iff1 = r.iff2 = 0; + + mem.ram [--r.sp] = uint8_t (r.pc >> 8); + mem.ram [--r.sp] = uint8_t (r.pc); + r.pc = 0x38; + cpu::adjust_time( 12 ); + if ( r.im == 2 ) + { + cpu::adjust_time( 6 ); + unsigned addr = r.i * 0x100u + 0xFF; + r.pc = mem.ram [(addr + 1) & 0xFFFF] * 0x100u + mem.ram [addr]; + } + } + } + } + duration = time(); + next_play -= duration; + check( next_play >= 0 ); + adjust_time( -duration ); + + apu.end_frame( duration ); + + return 0; +} diff --git a/libs/gme/gme/Ay_Emu.h b/libs/gme/gme/Ay_Emu.h new file mode 100644 index 000000000..86b020487 --- /dev/null +++ b/libs/gme/gme/Ay_Emu.h @@ -0,0 +1,69 @@ +// Sinclair Spectrum AY music file emulator + +// Game_Music_Emu 0.6.0 +#ifndef AY_EMU_H +#define AY_EMU_H + +#include "Classic_Emu.h" +#include "Ay_Apu.h" +#include "Ay_Cpu.h" + +class Ay_Emu : private Ay_Cpu, public Classic_Emu { + typedef Ay_Cpu cpu; +public: + // AY file header + enum { header_size = 0x14 }; + struct header_t + { + byte tag [8]; + byte vers; + byte player; + byte unused [2]; + byte author [2]; + byte comment [2]; + byte max_track; + byte first_track; + byte track_info [2]; + }; + + static gme_type_t static_type() { return gme_ay_type; } +public: + Ay_Emu(); + ~Ay_Emu(); + struct file_t { + header_t const* header; + byte const* end; + byte const* tracks; + }; +protected: + blargg_err_t track_info_( track_info_t*, int track ) const; + blargg_err_t load_mem_( byte const*, long ); + blargg_err_t start_track_( int ); + blargg_err_t run_clocks( blip_time_t&, int ); + void set_tempo_( double ); + void set_voice( int, Blip_Buffer*, Blip_Buffer*, Blip_Buffer* ); + void update_eq( blip_eq_t const& ); +private: + file_t file; + + cpu_time_t play_period; + cpu_time_t next_play; + Blip_Buffer* beeper_output; + int beeper_delta; + int last_beeper; + int apu_addr; + int cpc_latch; + bool spectrum_mode; + bool cpc_mode; + + // large items + struct { + byte padding1 [0x100]; + byte ram [0x10000 + 0x100]; + } mem; + Ay_Apu apu; + friend void ay_cpu_out( Ay_Cpu*, cpu_time_t, unsigned addr, int data ); + void cpu_out_misc( cpu_time_t, unsigned addr, int data ); +}; + +#endif diff --git a/libs/gme/gme/Blip_Buffer.cpp b/libs/gme/gme/Blip_Buffer.cpp new file mode 100644 index 000000000..2b88cd4f8 --- /dev/null +++ b/libs/gme/gme/Blip_Buffer.cpp @@ -0,0 +1,460 @@ +// Blip_Buffer 0.4.1. http://www.slack.net/~ant/ + +#include "Blip_Buffer.h" + +#include +#include +#include +#include +#include + +/* Copyright (C) 2003-2006 Shay Green. This module 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 +module 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 module; if not, write to the Free Software Foundation, +Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + +#ifdef BLARGG_ENABLE_OPTIMIZER + #include BLARGG_ENABLE_OPTIMIZER +#endif + +int const silent_buf_size = 1; // size used for Silent_Blip_Buffer + +Blip_Buffer::Blip_Buffer() +{ + factor_ = (blip_ulong)-1 / 2; + offset_ = 0; + buffer_ = 0; + buffer_size_ = 0; + sample_rate_ = 0; + reader_accum_ = 0; + bass_shift_ = 0; + clock_rate_ = 0; + bass_freq_ = 16; + length_ = 0; + + // assumptions code makes about implementation-defined features + #ifndef NDEBUG + // right shift of negative value preserves sign + buf_t_ i = -0x7FFFFFFE; + assert( (i >> 1) == -0x3FFFFFFF ); + + // casting to short truncates to 16 bits and sign-extends + i = 0x18000; + assert( (short) i == -0x8000 ); + #endif +} + +Blip_Buffer::~Blip_Buffer() +{ + if ( buffer_size_ != silent_buf_size ) + free( buffer_ ); +} + +Silent_Blip_Buffer::Silent_Blip_Buffer() +{ + factor_ = 0; + buffer_ = buf; + buffer_size_ = silent_buf_size; + memset( buf, 0, sizeof buf ); // in case machine takes exception for signed overflow +} + +void Blip_Buffer::clear( int entire_buffer ) +{ + offset_ = 0; + reader_accum_ = 0; + modified_ = 0; + if ( buffer_ ) + { + long count = (entire_buffer ? buffer_size_ : samples_avail()); + memset( buffer_, 0, (count + blip_buffer_extra_) * sizeof (buf_t_) ); + } +} + +Blip_Buffer::blargg_err_t Blip_Buffer::set_sample_rate( long new_rate, int msec ) +{ + if ( buffer_size_ == silent_buf_size ) + { + assert( 0 ); + return "Internal (tried to resize Silent_Blip_Buffer)"; + } + + // start with maximum length that resampled time can represent + long new_size = (UINT_MAX >> BLIP_BUFFER_ACCURACY) - blip_buffer_extra_ - 64; + if ( msec != blip_max_length ) + { + long s = (new_rate * (msec + 1) + 999) / 1000; + if ( s < new_size ) + new_size = s; + else + assert( 0 ); // fails if requested buffer length exceeds limit + } + + if ( buffer_size_ != new_size ) + { + void* p = realloc( buffer_, (new_size + blip_buffer_extra_) * sizeof *buffer_ ); + if ( !p ) + return "Out of memory"; + buffer_ = (buf_t_*) p; + } + + buffer_size_ = new_size; + assert( buffer_size_ != silent_buf_size ); + + // update things based on the sample rate + sample_rate_ = new_rate; + length_ = new_size * 1000 / new_rate - 1; + if ( msec ) + assert( length_ == msec ); // ensure length is same as that passed in + if ( clock_rate_ ) + clock_rate( clock_rate_ ); + bass_freq( bass_freq_ ); + + clear(); + + return 0; // success +} + +blip_resampled_time_t Blip_Buffer::clock_rate_factor( long rate ) const +{ + double ratio = (double) sample_rate_ / rate; + blip_long factor = (blip_long) floor( ratio * (1L << BLIP_BUFFER_ACCURACY) + 0.5 ); + assert( factor > 0 || !sample_rate_ ); // fails if clock/output ratio is too large + return (blip_resampled_time_t) factor; +} + +void Blip_Buffer::bass_freq( int freq ) +{ + bass_freq_ = freq; + int shift = 31; + if ( freq > 0 ) + { + shift = 13; + long f = (freq << 16) / sample_rate_; + while ( (f >>= 1) && --shift ) { } + } + bass_shift_ = shift; +} + +void Blip_Buffer::end_frame( blip_time_t t ) +{ + offset_ += t * factor_; + assert( samples_avail() <= (long) buffer_size_ ); // time outside buffer length +} + +void Blip_Buffer::remove_silence( long count ) +{ + assert( count <= samples_avail() ); // tried to remove more samples than available + offset_ -= (blip_resampled_time_t) count << BLIP_BUFFER_ACCURACY; +} + +long Blip_Buffer::count_samples( blip_time_t t ) const +{ + unsigned long last_sample = resampled_time( t ) >> BLIP_BUFFER_ACCURACY; + unsigned long first_sample = offset_ >> BLIP_BUFFER_ACCURACY; + return (long) (last_sample - first_sample); +} + +blip_time_t Blip_Buffer::count_clocks( long count ) const +{ + if ( !factor_ ) + { + assert( 0 ); // sample rate and clock rates must be set first + return 0; + } + + if ( count > buffer_size_ ) + count = buffer_size_; + blip_resampled_time_t time = (blip_resampled_time_t) count << BLIP_BUFFER_ACCURACY; + return (blip_time_t) ((time - offset_ + factor_ - 1) / factor_); +} + +void Blip_Buffer::remove_samples( long count ) +{ + if ( count ) + { + remove_silence( count ); + + // copy remaining samples to beginning and clear old samples + long remain = samples_avail() + blip_buffer_extra_; + memmove( buffer_, buffer_ + count, remain * sizeof *buffer_ ); + memset( buffer_ + remain, 0, count * sizeof *buffer_ ); + } +} + +// Blip_Synth_ + +Blip_Synth_Fast_::Blip_Synth_Fast_() +{ + buf = 0; + last_amp = 0; + delta_factor = 0; +} + +void Blip_Synth_Fast_::volume_unit( double new_unit ) +{ + delta_factor = int (new_unit * (1L << blip_sample_bits) + 0.5); +} + +#if !BLIP_BUFFER_FAST + +Blip_Synth_::Blip_Synth_( short* p, int w ) : + impulses( p ), + width( w ) +{ + volume_unit_ = 0.0; + kernel_unit = 0; + buf = 0; + last_amp = 0; + delta_factor = 0; +} + +#undef PI +#define PI 3.1415926535897932384626433832795029 + +static void gen_sinc( float* out, int count, double oversample, double treble, double cutoff ) +{ + if ( cutoff >= 0.999 ) + cutoff = 0.999; + + if ( treble < -300.0 ) + treble = -300.0; + if ( treble > 5.0 ) + treble = 5.0; + + double const maxh = 4096.0; + double const rolloff = pow( 10.0, 1.0 / (maxh * 20.0) * treble / (1.0 - cutoff) ); + double const pow_a_n = pow( rolloff, maxh - maxh * cutoff ); + double const to_angle = PI / 2 / maxh / oversample; + for ( int i = 0; i < count; i++ ) + { + double angle = ((i - count) * 2 + 1) * to_angle; + double angle_maxh = angle * maxh; + double angle_maxh_mid = angle_maxh * cutoff; + + double y = maxh; + + // 0 to Fs/2*cutoff, flat + if ( angle_maxh_mid ) // unstable at t=0 + y *= sin( angle_maxh_mid ) / angle_maxh_mid; + + // Fs/2*cutoff to Fs/2, logarithmic rolloff + double cosa = cos( angle ); + double den = 1 + rolloff * (rolloff - cosa - cosa); + + // Becomes unstable when rolloff is near 1.0 and t is near 0, + // which is the only time den becomes small + if ( den > 1e-13 ) + { + double num = + (cos( angle_maxh - angle ) * rolloff - cos( angle_maxh )) * pow_a_n - + cos( angle_maxh_mid - angle ) * rolloff + cos( angle_maxh_mid ); + + y = y * cutoff + num / den; + } + + out [i] = (float) y; + } +} + +void blip_eq_t::generate( float* out, int count ) const +{ + // lower cutoff freq for narrow kernels with their wider transition band + // (8 points->1.49, 16 points->1.15) + double oversample = blip_res * 2.25 / count + 0.85; + double half_rate = sample_rate * 0.5; + if ( cutoff_freq ) + oversample = half_rate / cutoff_freq; + double cutoff = rolloff_freq * oversample / half_rate; + + gen_sinc( out, count, blip_res * oversample, treble, cutoff ); + + // apply (half of) hamming window + double to_fraction = PI / (count - 1); + for ( int i = count; i--; ) + out [i] *= 0.54f - 0.46f * (float) cos( i * to_fraction ); +} + +void Blip_Synth_::adjust_impulse() +{ + // sum pairs for each phase and add error correction to end of first half + int const size = impulses_size(); + for ( int p = blip_res; p-- >= blip_res / 2; ) + { + int p2 = blip_res - 2 - p; + long error = kernel_unit; + for ( int i = 1; i < size; i += blip_res ) + { + error -= impulses [i + p ]; + error -= impulses [i + p2]; + } + if ( p == p2 ) + error /= 2; // phase = 0.5 impulse uses same half for both sides + impulses [size - blip_res + p] += (short) error; + //printf( "error: %ld\n", error ); + } + + //for ( int i = blip_res; i--; printf( "\n" ) ) + // for ( int j = 0; j < width / 2; j++ ) + // printf( "%5ld,", impulses [j * blip_res + i + 1] ); +} + +void Blip_Synth_::treble_eq( blip_eq_t const& eq ) +{ + float fimpulse [blip_res / 2 * (blip_widest_impulse_ - 1) + blip_res * 2]; + + int const half_size = blip_res / 2 * (width - 1); + eq.generate( &fimpulse [blip_res], half_size ); + + int i; + + // need mirror slightly past center for calculation + for ( i = blip_res; i--; ) + fimpulse [blip_res + half_size + i] = fimpulse [blip_res + half_size - 1 - i]; + + // starts at 0 + for ( i = 0; i < blip_res; i++ ) + fimpulse [i] = 0.0f; + + // find rescale factor + double total = 0.0; + for ( i = 0; i < half_size; i++ ) + total += fimpulse [blip_res + i]; + + //double const base_unit = 44800.0 - 128 * 18; // allows treble up to +0 dB + //double const base_unit = 37888.0; // allows treble to +5 dB + double const base_unit = 32768.0; // necessary for blip_unscaled to work + double rescale = base_unit / 2 / total; + kernel_unit = (long) base_unit; + + // integrate, first difference, rescale, convert to int + double sum = 0.0; + double next = 0.0; + int const impulses_size = this->impulses_size(); + for ( i = 0; i < impulses_size; i++ ) + { + impulses [i] = (short) floor( (next - sum) * rescale + 0.5 ); + sum += fimpulse [i]; + next += fimpulse [i + blip_res]; + } + adjust_impulse(); + + // volume might require rescaling + double vol = volume_unit_; + if ( vol ) + { + volume_unit_ = 0.0; + volume_unit( vol ); + } +} + +void Blip_Synth_::volume_unit( double new_unit ) +{ + if ( new_unit != volume_unit_ ) + { + // use default eq if it hasn't been set yet + if ( !kernel_unit ) + treble_eq( -8.0 ); + + volume_unit_ = new_unit; + double factor = new_unit * (1L << blip_sample_bits) / kernel_unit; + + if ( factor > 0.0 ) + { + int shift = 0; + + // if unit is really small, might need to attenuate kernel + while ( factor < 2.0 ) + { + shift++; + factor *= 2.0; + } + + if ( shift ) + { + kernel_unit >>= shift; + assert( kernel_unit > 0 ); // fails if volume unit is too low + + // keep values positive to avoid round-towards-zero of sign-preserving + // right shift for negative values + long offset = 0x8000 + (1 << (shift - 1)); + long offset2 = 0x8000 >> shift; + for ( int i = impulses_size(); i--; ) + impulses [i] = (short) (((impulses [i] + offset) >> shift) - offset2); + adjust_impulse(); + } + } + delta_factor = (int) floor( factor + 0.5 ); + //printf( "delta_factor: %d, kernel_unit: %d\n", delta_factor, kernel_unit ); + } +} +#endif + +long Blip_Buffer::read_samples( blip_sample_t* BLIP_RESTRICT out, long max_samples, int stereo ) +{ + long count = samples_avail(); + if ( count > max_samples ) + count = max_samples; + + if ( count ) + { + int const bass = BLIP_READER_BASS( *this ); + BLIP_READER_BEGIN( reader, *this ); + + if ( !stereo ) + { + for ( blip_long n = count; n; --n ) + { + blip_long s = BLIP_READER_READ( reader ); + if ( (blip_sample_t) s != s ) + s = 0x7FFF - (s >> 24); + *out++ = (blip_sample_t) s; + BLIP_READER_NEXT( reader, bass ); + } + } + else + { + for ( blip_long n = count; n; --n ) + { + blip_long s = BLIP_READER_READ( reader ); + if ( (blip_sample_t) s != s ) + s = 0x7FFF - (s >> 24); + *out = (blip_sample_t) s; + out += 2; + BLIP_READER_NEXT( reader, bass ); + } + } + BLIP_READER_END( reader, *this ); + + remove_samples( count ); + } + return count; +} + +void Blip_Buffer::mix_samples( blip_sample_t const* in, long count ) +{ + if ( buffer_size_ == silent_buf_size ) + { + assert( 0 ); + return; + } + + buf_t_* out = buffer_ + (offset_ >> BLIP_BUFFER_ACCURACY) + blip_widest_impulse_ / 2; + + int const sample_shift = blip_sample_bits - 16; + int prev = 0; + while ( count-- ) + { + blip_long s = (blip_long) *in++ << sample_shift; + *out += s - prev; + prev = s; + ++out; + } + *out -= prev; +} + diff --git a/libs/gme/gme/Blip_Buffer.h b/libs/gme/gme/Blip_Buffer.h new file mode 100644 index 000000000..4cc526d2f --- /dev/null +++ b/libs/gme/gme/Blip_Buffer.h @@ -0,0 +1,488 @@ +// Band-limited sound synthesis buffer + +// Blip_Buffer 0.4.1 +#ifndef BLIP_BUFFER_H +#define BLIP_BUFFER_H + + // internal + #include + #if INT_MAX < 0x7FFFFFFF + #error "int must be at least 32 bits" + #endif + + typedef int blip_long; + typedef unsigned blip_ulong; + +// Time unit at source clock rate +typedef blip_long blip_time_t; + +// Output samples are 16-bit signed, with a range of -32768 to 32767 +typedef short blip_sample_t; +enum { blip_sample_max = 32767 }; + +class Blip_Buffer { +public: + typedef const char* blargg_err_t; + + // Set output sample rate and buffer length in milliseconds (1/1000 sec, defaults + // to 1/4 second), then clear buffer. Returns NULL on success, otherwise if there + // isn't enough memory, returns error without affecting current buffer setup. + blargg_err_t set_sample_rate( long samples_per_sec, int msec_length = 1000 / 4 ); + + // Set number of source time units per second + void clock_rate( long ); + + // End current time frame of specified duration and make its samples available + // (along with any still-unread samples) for reading with read_samples(). Begins + // a new time frame at the end of the current frame. + void end_frame( blip_time_t time ); + + // Read at most 'max_samples' out of buffer into 'dest', removing them from from + // the buffer. Returns number of samples actually read and removed. If stereo is + // true, increments 'dest' one extra time after writing each sample, to allow + // easy interleving of two channels into a stereo output buffer. + long read_samples( blip_sample_t* dest, long max_samples, int stereo = 0 ); + +// Additional optional features + + // Current output sample rate + long sample_rate() const; + + // Length of buffer, in milliseconds + int length() const; + + // Number of source time units per second + long clock_rate() const; + + // Set frequency high-pass filter frequency, where higher values reduce bass more + void bass_freq( int frequency ); + + // Number of samples delay from synthesis to samples read out + int output_latency() const; + + // Remove all available samples and clear buffer to silence. If 'entire_buffer' is + // false, just clears out any samples waiting rather than the entire buffer. + void clear( int entire_buffer = 1 ); + + // Number of samples available for reading with read_samples() + long samples_avail() const; + + // Remove 'count' samples from those waiting to be read + void remove_samples( long count ); + +// Experimental features + + // Count number of clocks needed until 'count' samples will be available. + // If buffer can't even hold 'count' samples, returns number of clocks until + // buffer becomes full. + blip_time_t count_clocks( long count ) const; + + // Number of raw samples that can be mixed within frame of specified duration. + long count_samples( blip_time_t duration ) const; + + // Mix 'count' samples from 'buf' into buffer. + void mix_samples( blip_sample_t const* buf, long count ); + + // not documented yet + void set_modified() { modified_ = 1; } + int clear_modified() { int b = modified_; modified_ = 0; return b; } + typedef blip_ulong blip_resampled_time_t; + void remove_silence( long count ); + blip_resampled_time_t resampled_duration( int t ) const { return t * factor_; } + blip_resampled_time_t resampled_time( blip_time_t t ) const { return t * factor_ + offset_; } + blip_resampled_time_t clock_rate_factor( long clock_rate ) const; +public: + Blip_Buffer(); + ~Blip_Buffer(); + + // Deprecated + typedef blip_resampled_time_t resampled_time_t; + blargg_err_t sample_rate( long r ) { return set_sample_rate( r ); } + blargg_err_t sample_rate( long r, int msec ) { return set_sample_rate( r, msec ); } +private: + // noncopyable + Blip_Buffer( const Blip_Buffer& ); + Blip_Buffer& operator = ( const Blip_Buffer& ); +public: + typedef blip_time_t buf_t_; + blip_ulong factor_; + blip_resampled_time_t offset_; + buf_t_* buffer_; + blip_long buffer_size_; + blip_long reader_accum_; + int bass_shift_; +private: + long sample_rate_; + long clock_rate_; + int bass_freq_; + int length_; + int modified_; + friend class Blip_Reader; +}; + +#ifdef HAVE_CONFIG_H + #include "config.h" +#endif + +// Number of bits in resample ratio fraction. Higher values give a more accurate ratio +// but reduce maximum buffer size. +#ifndef BLIP_BUFFER_ACCURACY + #define BLIP_BUFFER_ACCURACY 16 +#endif + +// Number bits in phase offset. Fewer than 6 bits (64 phase offsets) results in +// noticeable broadband noise when synthesizing high frequency square waves. +// Affects size of Blip_Synth objects since they store the waveform directly. +#ifndef BLIP_PHASE_BITS + #if BLIP_BUFFER_FAST + #define BLIP_PHASE_BITS 8 + #else + #define BLIP_PHASE_BITS 6 + #endif +#endif + + // Internal + typedef blip_ulong blip_resampled_time_t; + int const blip_widest_impulse_ = 16; + int const blip_buffer_extra_ = blip_widest_impulse_ + 2; + int const blip_res = 1 << BLIP_PHASE_BITS; + class blip_eq_t; + + class Blip_Synth_Fast_ { + public: + Blip_Buffer* buf; + int last_amp; + int delta_factor; + + void volume_unit( double ); + Blip_Synth_Fast_(); + void treble_eq( blip_eq_t const& ) { } + }; + + class Blip_Synth_ { + public: + Blip_Buffer* buf; + int last_amp; + int delta_factor; + + void volume_unit( double ); + Blip_Synth_( short* impulses, int width ); + void treble_eq( blip_eq_t const& ); + private: + double volume_unit_; + short* const impulses; + int const width; + blip_long kernel_unit; + int impulses_size() const { return blip_res / 2 * width + 1; } + void adjust_impulse(); + }; + +// Quality level. Start with blip_good_quality. +const int blip_med_quality = 8; +const int blip_good_quality = 12; +const int blip_high_quality = 16; + +// Range specifies the greatest expected change in amplitude. Calculate it +// by finding the difference between the maximum and minimum expected +// amplitudes (max - min). +template +class Blip_Synth { +public: + // Set overall volume of waveform + void volume( double v ) { impl.volume_unit( v * (1.0 / (range < 0 ? -range : range)) ); } + + // Configure low-pass filter (see blip_buffer.txt) + void treble_eq( blip_eq_t const& eq ) { impl.treble_eq( eq ); } + + // Get/set Blip_Buffer used for output + Blip_Buffer* output() const { return impl.buf; } + void output( Blip_Buffer* b ) { impl.buf = b; impl.last_amp = 0; } + + // Update amplitude of waveform at given time. Using this requires a separate + // Blip_Synth for each waveform. + void update( blip_time_t time, int amplitude ); + +// Low-level interface + + // Add an amplitude transition of specified delta, optionally into specified buffer + // rather than the one set with output(). Delta can be positive or negative. + // The actual change in amplitude is delta * (volume / range) + void offset( blip_time_t, int delta, Blip_Buffer* ) const; + void offset( blip_time_t t, int delta ) const { offset( t, delta, impl.buf ); } + + // Works directly in terms of fractional output samples. Contact author for more info. + void offset_resampled( blip_resampled_time_t, int delta, Blip_Buffer* ) const; + + // Same as offset(), except code is inlined for higher performance + void offset_inline( blip_time_t t, int delta, Blip_Buffer* buf ) const { + offset_resampled( t * buf->factor_ + buf->offset_, delta, buf ); + } + void offset_inline( blip_time_t t, int delta ) const { + offset_resampled( t * impl.buf->factor_ + impl.buf->offset_, delta, impl.buf ); + } + +private: +#if BLIP_BUFFER_FAST + Blip_Synth_Fast_ impl; +#else + Blip_Synth_ impl; + typedef short imp_t; + imp_t impulses [blip_res * (quality / 2) + 1]; +public: + Blip_Synth() : impl( impulses, quality ) { } +#endif +}; + +// Low-pass equalization parameters +class blip_eq_t { +public: + // Logarithmic rolloff to treble dB at half sampling rate. Negative values reduce + // treble, small positive values (0 to 5.0) increase treble. + blip_eq_t( double treble_db = 0 ); + + // See blip_buffer.txt + blip_eq_t( double treble, long rolloff_freq, long sample_rate, long cutoff_freq = 0 ); + +private: + double treble; + long rolloff_freq; + long sample_rate; + long cutoff_freq; + void generate( float* out, int count ) const; + friend class Blip_Synth_; +}; + +int const blip_sample_bits = 30; + +// Dummy Blip_Buffer to direct sound output to, for easy muting without +// having to stop sound code. +class Silent_Blip_Buffer : public Blip_Buffer { + buf_t_ buf [blip_buffer_extra_ + 1]; +public: + // The following cannot be used (an assertion will fail if attempted): + blargg_err_t set_sample_rate( long samples_per_sec, int msec_length ); + blip_time_t count_clocks( long count ) const; + void mix_samples( blip_sample_t const* buf, long count ); + + Silent_Blip_Buffer(); +}; + + #if defined (__GNUC__) || _MSC_VER >= 1100 + #define BLIP_RESTRICT __restrict + #else + #define BLIP_RESTRICT + #endif + +// Optimized reading from Blip_Buffer, for use in custom sample output + +// Begin reading from buffer. Name should be unique to the current block. +#define BLIP_READER_BEGIN( name, blip_buffer ) \ + const Blip_Buffer::buf_t_* BLIP_RESTRICT name##_reader_buf = (blip_buffer).buffer_;\ + blip_long name##_reader_accum = (blip_buffer).reader_accum_ + +// Get value to pass to BLIP_READER_NEXT() +#define BLIP_READER_BASS( blip_buffer ) ((blip_buffer).bass_shift_) + +// Constant value to use instead of BLIP_READER_BASS(), for slightly more optimal +// code at the cost of having no bass control +int const blip_reader_default_bass = 9; + +// Current sample +#define BLIP_READER_READ( name ) (name##_reader_accum >> (blip_sample_bits - 16)) + +// Current raw sample in full internal resolution +#define BLIP_READER_READ_RAW( name ) (name##_reader_accum) + +// Advance to next sample +#define BLIP_READER_NEXT( name, bass ) \ + (void) (name##_reader_accum += *name##_reader_buf++ - (name##_reader_accum >> (bass))) + +// End reading samples from buffer. The number of samples read must now be removed +// using Blip_Buffer::remove_samples(). +#define BLIP_READER_END( name, blip_buffer ) \ + (void) ((blip_buffer).reader_accum_ = name##_reader_accum) + + +// Compatibility with older version +const long blip_unscaled = 65535; +const int blip_low_quality = blip_med_quality; +const int blip_best_quality = blip_high_quality; + +// Deprecated; use BLIP_READER macros as follows: +// Blip_Reader r; r.begin( buf ); -> BLIP_READER_BEGIN( r, buf ); +// int bass = r.begin( buf ) -> BLIP_READER_BEGIN( r, buf ); int bass = BLIP_READER_BASS( buf ); +// r.read() -> BLIP_READER_READ( r ) +// r.read_raw() -> BLIP_READER_READ_RAW( r ) +// r.next( bass ) -> BLIP_READER_NEXT( r, bass ) +// r.next() -> BLIP_READER_NEXT( r, blip_reader_default_bass ) +// r.end( buf ) -> BLIP_READER_END( r, buf ) +class Blip_Reader { +public: + int begin( Blip_Buffer& ); + blip_long read() const { return accum >> (blip_sample_bits - 16); } + blip_long read_raw() const { return accum; } + void next( int bass_shift = 9 ) { accum += *buf++ - (accum >> bass_shift); } + void end( Blip_Buffer& b ) { b.reader_accum_ = accum; } + +private: + const Blip_Buffer::buf_t_* buf; + blip_long accum; +}; + +// End of public interface + +#include + +template +inline void Blip_Synth::offset_resampled( blip_resampled_time_t time, + int delta, Blip_Buffer* blip_buf ) const +{ + // Fails if time is beyond end of Blip_Buffer, due to a bug in caller code or the + // need for a longer buffer as set by set_sample_rate(). + assert( (blip_long) (time >> BLIP_BUFFER_ACCURACY) < blip_buf->buffer_size_ ); + delta *= impl.delta_factor; + blip_long* BLIP_RESTRICT buf = blip_buf->buffer_ + (time >> BLIP_BUFFER_ACCURACY); + int phase = (int) (time >> (BLIP_BUFFER_ACCURACY - BLIP_PHASE_BITS) & (blip_res - 1)); + +#if BLIP_BUFFER_FAST + blip_long left = buf [0] + delta; + + // Kind of crappy, but doing shift after multiply results in overflow. + // Alternate way of delaying multiply by delta_factor results in worse + // sub-sample resolution. + blip_long right = (delta >> BLIP_PHASE_BITS) * phase; + left -= right; + right += buf [1]; + + buf [0] = left; + buf [1] = right; +#else + + int const fwd = (blip_widest_impulse_ - quality) / 2; + int const rev = fwd + quality - 2; + int const mid = quality / 2 - 1; + + imp_t const* BLIP_RESTRICT imp = impulses + blip_res - phase; + + #if defined (_M_IX86) || defined (_M_IA64) || defined (__i486__) || \ + defined (__x86_64__) || defined (__ia64__) || defined (__i386__) + + // straight forward implementation resulted in better code on GCC for x86 + + #define ADD_IMP( out, in ) \ + buf [out] += (blip_long) imp [blip_res * (in)] * delta + + #define BLIP_FWD( i ) {\ + ADD_IMP( fwd + i, i );\ + ADD_IMP( fwd + 1 + i, i + 1 );\ + } + #define BLIP_REV( r ) {\ + ADD_IMP( rev - r, r + 1 );\ + ADD_IMP( rev + 1 - r, r );\ + } + + BLIP_FWD( 0 ) + if ( quality > 8 ) BLIP_FWD( 2 ) + if ( quality > 12 ) BLIP_FWD( 4 ) + { + ADD_IMP( fwd + mid - 1, mid - 1 ); + ADD_IMP( fwd + mid , mid ); + imp = impulses + phase; + } + if ( quality > 12 ) BLIP_REV( 6 ) + if ( quality > 8 ) BLIP_REV( 4 ) + BLIP_REV( 2 ) + + ADD_IMP( rev , 1 ); + ADD_IMP( rev + 1, 0 ); + + #else + + // for RISC processors, help compiler by reading ahead of writes + + #define BLIP_FWD( i ) {\ + blip_long t0 = i0 * delta + buf [fwd + i];\ + blip_long t1 = imp [blip_res * (i + 1)] * delta + buf [fwd + 1 + i];\ + i0 = imp [blip_res * (i + 2)];\ + buf [fwd + i] = t0;\ + buf [fwd + 1 + i] = t1;\ + } + #define BLIP_REV( r ) {\ + blip_long t0 = i0 * delta + buf [rev - r];\ + blip_long t1 = imp [blip_res * r] * delta + buf [rev + 1 - r];\ + i0 = imp [blip_res * (r - 1)];\ + buf [rev - r] = t0;\ + buf [rev + 1 - r] = t1;\ + } + + blip_long i0 = *imp; + BLIP_FWD( 0 ) + if ( quality > 8 ) BLIP_FWD( 2 ) + if ( quality > 12 ) BLIP_FWD( 4 ) + { + blip_long t0 = i0 * delta + buf [fwd + mid - 1]; + blip_long t1 = imp [blip_res * mid] * delta + buf [fwd + mid ]; + imp = impulses + phase; + i0 = imp [blip_res * mid]; + buf [fwd + mid - 1] = t0; + buf [fwd + mid ] = t1; + } + if ( quality > 12 ) BLIP_REV( 6 ) + if ( quality > 8 ) BLIP_REV( 4 ) + BLIP_REV( 2 ) + + blip_long t0 = i0 * delta + buf [rev ]; + blip_long t1 = *imp * delta + buf [rev + 1]; + buf [rev ] = t0; + buf [rev + 1] = t1; + #endif + +#endif +} + +#undef BLIP_FWD +#undef BLIP_REV + +template +#if BLIP_BUFFER_FAST + inline +#endif +void Blip_Synth::offset( blip_time_t t, int delta, Blip_Buffer* buf ) const +{ + offset_resampled( t * buf->factor_ + buf->offset_, delta, buf ); +} + +template +#if BLIP_BUFFER_FAST + inline +#endif +void Blip_Synth::update( blip_time_t t, int amp ) +{ + int delta = amp - impl.last_amp; + impl.last_amp = amp; + offset_resampled( t * impl.buf->factor_ + impl.buf->offset_, delta, impl.buf ); +} + +inline blip_eq_t::blip_eq_t( double t ) : + treble( t ), rolloff_freq( 0 ), sample_rate( 44100 ), cutoff_freq( 0 ) { } +inline blip_eq_t::blip_eq_t( double t, long rf, long sr, long cf ) : + treble( t ), rolloff_freq( rf ), sample_rate( sr ), cutoff_freq( cf ) { } + +inline int Blip_Buffer::length() const { return length_; } +inline long Blip_Buffer::samples_avail() const { return (long) (offset_ >> BLIP_BUFFER_ACCURACY); } +inline long Blip_Buffer::sample_rate() const { return sample_rate_; } +inline int Blip_Buffer::output_latency() const { return blip_widest_impulse_ / 2; } +inline long Blip_Buffer::clock_rate() const { return clock_rate_; } +inline void Blip_Buffer::clock_rate( long cps ) { factor_ = clock_rate_factor( clock_rate_ = cps ); } + +inline int Blip_Reader::begin( Blip_Buffer& blip_buf ) +{ + buf = blip_buf.buffer_; + accum = blip_buf.reader_accum_; + return blip_buf.bass_shift_; +} + +int const blip_max_length = 0; +int const blip_default_length = 250; + +#endif diff --git a/libs/gme/gme/CMakeLists.txt b/libs/gme/gme/CMakeLists.txt new file mode 100644 index 000000000..3c6464fc7 --- /dev/null +++ b/libs/gme/gme/CMakeLists.txt @@ -0,0 +1,162 @@ +# List of source files required by libgme and any emulators +# This is not 100% accurate (Fir_Resampler for instance) but +# you'll be OK. +set(libgme_SRCS Blip_Buffer.cpp + Classic_Emu.cpp + Data_Reader.cpp + Dual_Resampler.cpp + Effects_Buffer.cpp + Fir_Resampler.cpp + gme.cpp + Gme_File.cpp + M3u_Playlist.cpp + Multi_Buffer.cpp + Music_Emu.cpp + ) + +# Ay_Apu is very popular around here +if (USE_GME_AY OR USE_GME_KSS) + set(libgme_SRCS ${libgme_SRCS} + Ay_Apu.cpp + ) +endif() + +# so is Ym2612_Emu +if (USE_GME_VGM OR USE_GME_GYM) + set(libgme_SRCS ${libgme_SRCS} + Ym2612_Emu.cpp + ) +endif() + +# But none are as popular as Sms_Apu +if (USE_GME_VGM OR USE_GME_GYM OR USE_GME_KSS) + set(libgme_SRCS ${libgme_SRCS} + Sms_Apu.cpp + ) +endif() + +if (USE_GME_AY) + set(libgme_SRCS ${libgme_SRCS} + # Ay_Apu.cpp included earlier + Ay_Cpu.cpp + Ay_Emu.cpp + ) +endif() + +if (USE_GME_GBS) + set(libgme_SRCS ${libgme_SRCS} + Gb_Apu.cpp + Gb_Cpu.cpp + Gb_Oscs.cpp + Gbs_Emu.cpp + ) +endif() + +if (USE_GME_GYM) + set(libgme_SRCS ${libgme_SRCS} + # Sms_Apu.cpp included earlier + # Ym2612_Emu.cpp included earlier + Gym_Emu.cpp + ) +endif() + +if (USE_GME_HES) + set(libgme_SRCS ${libgme_SRCS} + Hes_Apu.cpp + Hes_Cpu.cpp + Hes_Emu.cpp + ) +endif() + +if (USE_GME_KSS) + set(libgme_SRCS ${libgme_SRCS} + # Ay_Apu.cpp included earlier + # Sms_Apu.cpp included earlier + Kss_Cpu.cpp + Kss_Emu.cpp + Kss_Scc_Apu.cpp + ) +endif() + +if (USE_GME_NSF OR USE_GME_NSFE) + set(libgme_SRCS ${libgme_SRCS} + Nes_Apu.cpp + Nes_Cpu.cpp + Nes_Fme7_Apu.cpp + Nes_Namco_Apu.cpp + Nes_Oscs.cpp + Nes_Vrc6_Apu.cpp + Nsf_Emu.cpp + ) +endif() + +if (USE_GME_NSFE) + set(libgme_SRCS ${libgme_SRCS} + Nsfe_Emu.cpp + ) +endif() + +if (USE_GME_SAP) + set(libgme_SRCS ${libgme_SRCS} + Sap_Apu.cpp + Sap_Cpu.cpp + Sap_Emu.cpp + ) +endif() + +if (USE_GME_SPC) + set(libgme_SRCS ${libgme_SRCS} + Snes_Spc.cpp + Spc_Cpu.cpp + Spc_Dsp.cpp + Spc_Emu.cpp + Spc_Filter.cpp + ) +endif() + +if (USE_GME_VGM) + set(libgme_SRCS ${libgme_SRCS} + # Sms_Apu.cpp included earlier + # Ym2612_Emu.cpp included earlier + Vgm_Emu.cpp + Vgm_Emu_Impl.cpp + Ym2413_Emu.cpp + ) +endif() + +# These headers are part of the generic gme interface. +set (EXPORTED_HEADERS gme.h) + +# Run during cmake phase, so this is available during make +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/gme_types.h.in + ${CMAKE_CURRENT_BINARY_DIR}/gme_types.h) + +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libgme.pc.in + ${CMAKE_CURRENT_BINARY_DIR}/libgme.pc @ONLY) + +# On some platforms we may need to change headers or whatnot based on whether +# we're building the library or merely using the library. The following is +# only defined when building the library to allow us to tell which is which. +add_definitions(-DBLARGG_BUILD_DLL) + +# For the gme_types.h +include_directories(${CMAKE_CURRENT_BINARY_DIR}) + +# Add library to be compiled. +add_library(gme SHARED ${libgme_SRCS}) + +# The version is the release. The "soversion" is the API version. As long +# as only build fixes are performed (i.e. no backwards-incompatible changes +# to the API), the SOVERSION should be the same even when bumping up VERSION. +# The way gme.h is designed, SOVERSION should very rarely be bumped, if ever. +# Hopefully the API can stay compatible with old versions. +set_target_properties(gme + PROPERTIES VERSION ${GME_VERSION} + SOVERSION 0) + +install(TARGETS gme LIBRARY DESTINATION lib${LIB_SUFFIX} + RUNTIME DESTINATION bin # DLL platforms + ARCHIVE DESTINATION lib) # DLL platforms + +install(FILES ${EXPORTED_HEADERS} DESTINATION include/gme) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libgme.pc DESTINATION lib/pkgconfig) diff --git a/libs/gme/gme/Classic_Emu.cpp b/libs/gme/gme/Classic_Emu.cpp new file mode 100644 index 000000000..42bb2fbe2 --- /dev/null +++ b/libs/gme/gme/Classic_Emu.cpp @@ -0,0 +1,184 @@ +// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/ + +#include "Classic_Emu.h" + +#include "Multi_Buffer.h" +#include + +/* Copyright (C) 2003-2006 Shay Green. This module 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 +module 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 module; if not, write to the Free Software Foundation, +Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + +#include "blargg_source.h" + +Classic_Emu::Classic_Emu() +{ + buf = 0; + stereo_buffer = 0; + voice_types = 0; + + // avoid inconsistency in our duplicated constants + assert( (int) wave_type == (int) Multi_Buffer::wave_type ); + assert( (int) noise_type == (int) Multi_Buffer::noise_type ); + assert( (int) mixed_type == (int) Multi_Buffer::mixed_type ); +} + +Classic_Emu::~Classic_Emu() +{ + delete stereo_buffer; +} + +void Classic_Emu::set_equalizer_( equalizer_t const& eq ) +{ + Music_Emu::set_equalizer_( eq ); + update_eq( eq.treble ); + if ( buf ) + buf->bass_freq( (int) equalizer().bass ); +} + +blargg_err_t Classic_Emu::set_sample_rate_( long rate ) +{ + if ( !buf ) + { + if ( !stereo_buffer ) + CHECK_ALLOC( stereo_buffer = BLARGG_NEW Stereo_Buffer ); + buf = stereo_buffer; + } + return buf->set_sample_rate( rate, 1000 / 20 ); +} + +void Classic_Emu::mute_voices_( int mask ) +{ + Music_Emu::mute_voices_( mask ); + for ( int i = voice_count(); i--; ) + { + if ( mask & (1 << i) ) + { + set_voice( i, 0, 0, 0 ); + } + else + { + Multi_Buffer::channel_t ch = buf->channel( i, (voice_types ? voice_types [i] : 0) ); + assert( (ch.center && ch.left && ch.right) || + (!ch.center && !ch.left && !ch.right) ); // all or nothing + set_voice( i, ch.center, ch.left, ch.right ); + } + } +} + +void Classic_Emu::change_clock_rate( long rate ) +{ + clock_rate_ = rate; + buf->clock_rate( rate ); +} + +blargg_err_t Classic_Emu::setup_buffer( long rate ) +{ + change_clock_rate( rate ); + RETURN_ERR( buf->set_channel_count( voice_count() ) ); + set_equalizer( equalizer() ); + buf_changed_count = buf->channels_changed_count(); + return 0; +} + +blargg_err_t Classic_Emu::start_track_( int track ) +{ + RETURN_ERR( Music_Emu::start_track_( track ) ); + buf->clear(); + return 0; +} + +blargg_err_t Classic_Emu::play_( long count, sample_t* out ) +{ + long remain = count; + while ( remain ) + { + remain -= buf->read_samples( &out [count - remain], remain ); + if ( remain ) + { + if ( buf_changed_count != buf->channels_changed_count() ) + { + buf_changed_count = buf->channels_changed_count(); + remute_voices(); + } + int msec = buf->length(); + blip_time_t clocks_emulated = (blargg_long) msec * clock_rate_ / 1000; + RETURN_ERR( run_clocks( clocks_emulated, msec ) ); + assert( clocks_emulated ); + buf->end_frame( clocks_emulated ); + } + } + return 0; +} + +// Rom_Data + +blargg_err_t Rom_Data_::load_rom_data_( Data_Reader& in, + int header_size, void* header_out, int fill, long pad_size ) +{ + long file_offset = pad_size - header_size; + + rom_addr = 0; + mask = 0; + size_ = 0; + rom.clear(); + + file_size_ = in.remain(); + if ( file_size_ <= header_size ) // <= because there must be data after header + return gme_wrong_file_type; + blargg_err_t err = rom.resize( file_offset + file_size_ + pad_size ); + if ( !err ) + err = in.read( rom.begin() + file_offset, file_size_ ); + if ( err ) + { + rom.clear(); + return err; + } + + file_size_ -= header_size; + memcpy( header_out, &rom [file_offset], header_size ); + + memset( rom.begin() , fill, pad_size ); + memset( rom.end() - pad_size, fill, pad_size ); + + return 0; +} + +void Rom_Data_::set_addr_( long addr, int unit ) +{ + rom_addr = addr - unit - pad_extra; + + long rounded = (addr + file_size_ + unit - 1) / unit * unit; + if ( rounded <= 0 ) + { + rounded = 0; + } + else + { + int shift = 0; + unsigned long max_addr = (unsigned long) (rounded - 1); + while ( max_addr >> shift ) + shift++; + mask = (1L << shift) - 1; + } + + if ( addr < 0 ) + addr = 0; + size_ = rounded; + if ( rom.resize( rounded - rom_addr + pad_extra ) ) { } // OK if shrink fails + + if ( 0 ) + { + debug_printf( "addr: %X\n", addr ); + debug_printf( "file_size: %d\n", file_size_ ); + debug_printf( "rounded: %d\n", rounded ); + debug_printf( "mask: $%X\n", mask ); + } +} diff --git a/libs/gme/gme/Classic_Emu.h b/libs/gme/gme/Classic_Emu.h new file mode 100644 index 000000000..99e99afbe --- /dev/null +++ b/libs/gme/gme/Classic_Emu.h @@ -0,0 +1,127 @@ +// Common aspects of emulators which use Blip_Buffer for sound output + +// Game_Music_Emu 0.6.0 +#ifndef CLASSIC_EMU_H +#define CLASSIC_EMU_H + +#include "blargg_common.h" +#include "Blip_Buffer.h" +#include "Music_Emu.h" + +class Classic_Emu : public Music_Emu { +public: + Classic_Emu(); + ~Classic_Emu(); + void set_buffer( Multi_Buffer* ); +protected: + // Services + enum { wave_type = 0x100, noise_type = 0x200, mixed_type = wave_type | noise_type }; + void set_voice_types( int const* t ) { voice_types = t; } + blargg_err_t setup_buffer( long clock_rate ); + long clock_rate() const { return clock_rate_; } + void change_clock_rate( long ); // experimental + + // Overridable + virtual void set_voice( int index, Blip_Buffer* center, + Blip_Buffer* left, Blip_Buffer* right ) = 0; + virtual void update_eq( blip_eq_t const& ) = 0; + virtual blargg_err_t start_track_( int track ) = 0; + virtual blargg_err_t run_clocks( blip_time_t& time_io, int msec ) = 0; +protected: + blargg_err_t set_sample_rate_( long sample_rate ); + void mute_voices_( int ); + void set_equalizer_( equalizer_t const& ); + blargg_err_t play_( long, sample_t* ); +private: + Multi_Buffer* buf; + Multi_Buffer* stereo_buffer; // NULL if using custom buffer + long clock_rate_; + unsigned buf_changed_count; + int const* voice_types; +}; + +inline void Classic_Emu::set_buffer( Multi_Buffer* new_buf ) +{ + assert( !buf && new_buf ); + buf = new_buf; +} + +// ROM data handler, used by several Classic_Emu derivitives. Loads file data +// with padding on both sides, allowing direct use in bank mapping. The main purpose +// is to allow all file data to be loaded with only one read() call (for efficiency). + +class Rom_Data_ { +public: + typedef unsigned char byte; +protected: + enum { pad_extra = 8 }; + blargg_vector rom; + long file_size_; + blargg_long rom_addr; + blargg_long mask; + blargg_long size_; // TODO: eliminate + + blargg_err_t load_rom_data_( Data_Reader& in, int header_size, void* header_out, + int fill, long pad_size ); + void set_addr_( long addr, int unit ); +}; + +template +class Rom_Data : public Rom_Data_ { + enum { pad_size = unit + pad_extra }; +public: + // Load file data, using already-loaded header 'h' if not NULL. Copy header + // from loaded file data into *out and fill unmapped bytes with 'fill'. + blargg_err_t load( Data_Reader& in, int header_size, void* header_out, int fill ) + { + return load_rom_data_( in, header_size, header_out, fill, pad_size ); + } + + // Size of file data read in (excluding header) + long file_size() const { return file_size_; } + + // Pointer to beginning of file data + byte* begin() const { return rom.begin() + pad_size; } + + // Set address that file data should start at + void set_addr( long addr ) { set_addr_( addr, unit ); } + + // Free data + void clear() { rom.clear(); } + + // Size of data + start addr, rounded to a multiple of unit + long size() const { return size_; } + + // Pointer to unmapped page filled with same value + byte* unmapped() { return rom.begin(); } + + // Mask address to nearest power of two greater than size() + blargg_long mask_addr( blargg_long addr ) const + { + #ifdef check + check( addr <= mask ); + #endif + return addr & mask; + } + + // Pointer to page starting at addr. Returns unmapped() if outside data. + byte* at_addr( blargg_long addr ) + { + blargg_ulong offset = mask_addr( addr ) - rom_addr; + if ( offset > blargg_ulong (rom.size() - pad_size) ) + offset = 0; // unmapped + return &rom [offset]; + } +}; + +#ifndef GME_APU_HOOK + #define GME_APU_HOOK( emu, addr, data ) ((void) 0) +#endif + +#ifndef GME_FRAME_HOOK + #define GME_FRAME_HOOK( emu ) ((void) 0) +#else + #define GME_FRAME_HOOK_DEFINED 1 +#endif + +#endif diff --git a/libs/gme/gme/Data_Reader.cpp b/libs/gme/gme/Data_Reader.cpp new file mode 100644 index 000000000..5bbfbf551 --- /dev/null +++ b/libs/gme/gme/Data_Reader.cpp @@ -0,0 +1,315 @@ +// File_Extractor 0.4.0. http://www.slack.net/~ant/ + +#include "Data_Reader.h" + +#include "blargg_endian.h" +#include +#include +#include + +/* Copyright (C) 2005-2006 Shay Green. This module 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 +module 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 module; if not, write to the Free Software Foundation, +Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + +#include "blargg_source.h" + +const char Data_Reader::eof_error [] = "Unexpected end of file"; + +blargg_err_t Data_Reader::read( void* p, long s ) +{ + long result = read_avail( p, s ); + if ( result != s ) + { + if ( result >= 0 && result < s ) + return eof_error; + + return "Read error"; + } + + return 0; +} + +blargg_err_t Data_Reader::skip( long count ) +{ + char buf [512]; + while ( count ) + { + long n = sizeof buf; + if ( n > count ) + n = count; + count -= n; + RETURN_ERR( read( buf, n ) ); + } + return 0; +} + +long File_Reader::remain() const { return size() - tell(); } + +blargg_err_t File_Reader::skip( long n ) +{ + assert( n >= 0 ); + if ( !n ) + return 0; + return seek( tell() + n ); +} + +// Subset_Reader + +Subset_Reader::Subset_Reader( Data_Reader* dr, long size ) +{ + in = dr; + remain_ = dr->remain(); + if ( remain_ > size ) + remain_ = size; +} + +long Subset_Reader::remain() const { return remain_; } + +long Subset_Reader::read_avail( void* p, long s ) +{ + if ( s > remain_ ) + s = remain_; + remain_ -= s; + return in->read_avail( p, s ); +} + +// Remaining_Reader + +Remaining_Reader::Remaining_Reader( void const* h, long size, Data_Reader* r ) +{ + header = (char const*) h; + header_end = header + size; + in = r; +} + +long Remaining_Reader::remain() const { return header_end - header + in->remain(); } + +long Remaining_Reader::read_first( void* out, long count ) +{ + long first = header_end - header; + if ( first ) + { + if ( first > count ) + first = count; + void const* old = header; + header += first; + memcpy( out, old, first ); + } + return first; +} + +long Remaining_Reader::read_avail( void* out, long count ) +{ + long first = read_first( out, count ); + long second = count - first; + if ( second ) + { + second = in->read_avail( (char*) out + first, second ); + if ( second <= 0 ) + return second; + } + return first + second; +} + +blargg_err_t Remaining_Reader::read( void* out, long count ) +{ + long first = read_first( out, count ); + long second = count - first; + if ( !second ) + return 0; + return in->read( (char*) out + first, second ); +} + +// Mem_File_Reader + +Mem_File_Reader::Mem_File_Reader( const void* p, long s ) : + begin( (const char*) p ), + size_( s ) +{ + pos = 0; +} + +long Mem_File_Reader::size() const { return size_; } + +long Mem_File_Reader::read_avail( void* p, long s ) +{ + long r = remain(); + if ( s > r ) + s = r; + memcpy( p, begin + pos, s ); + pos += s; + return s; +} + +long Mem_File_Reader::tell() const { return pos; } + +blargg_err_t Mem_File_Reader::seek( long n ) +{ + if ( n > size_ ) + return eof_error; + pos = n; + return 0; +} + +// Callback_Reader + +Callback_Reader::Callback_Reader( callback_t c, long size, void* d ) : + callback( c ), + data( d ) +{ + remain_ = size; +} + +long Callback_Reader::remain() const { return remain_; } + +long Callback_Reader::read_avail( void* out, long count ) +{ + if ( count > remain_ ) + count = remain_; + if ( Callback_Reader::read( out, count ) ) + count = -1; + return count; +} + +blargg_err_t Callback_Reader::read( void* out, long count ) +{ + if ( count > remain_ ) + return eof_error; + return callback( data, out, count ); +} + +// Std_File_Reader + +Std_File_Reader::Std_File_Reader() : file_( 0 ) { } + +Std_File_Reader::~Std_File_Reader() { close(); } + +blargg_err_t Std_File_Reader::open( const char* path ) +{ + file_ = fopen( path, "rb" ); + if ( !file_ ) + return "Couldn't open file"; + return 0; +} + +long Std_File_Reader::size() const +{ + long pos = tell(); + fseek( (FILE*) file_, 0, SEEK_END ); + long result = tell(); + fseek( (FILE*) file_, pos, SEEK_SET ); + return result; +} + +long Std_File_Reader::read_avail( void* p, long s ) +{ + return fread( p, 1, s, (FILE*) file_ ); +} + +blargg_err_t Std_File_Reader::read( void* p, long s ) +{ + if ( s == (long) fread( p, 1, s, (FILE*) file_ ) ) + return 0; + if ( feof( (FILE*) file_ ) ) + return eof_error; + return "Couldn't read from file"; +} + +long Std_File_Reader::tell() const { return ftell( (FILE*) file_ ); } + +blargg_err_t Std_File_Reader::seek( long n ) +{ + if ( !fseek( (FILE*) file_, n, SEEK_SET ) ) + return 0; + if ( n > size() ) + return eof_error; + return "Error seeking in file"; +} + +void Std_File_Reader::close() +{ + if ( file_ ) + { + fclose( (FILE*) file_ ); + file_ = 0; + } +} + +// Gzip_File_Reader + +#ifdef HAVE_ZLIB_H + +#include "zlib.h" + +static const char* get_gzip_eof( const char* path, long* eof ) +{ + FILE* file = fopen( path, "rb" ); + if ( !file ) + return "Couldn't open file"; + + unsigned char buf [4]; + if ( fread( buf, 2, 1, file ) > 0 && buf [0] == 0x1F && buf [1] == 0x8B ) + { + fseek( file, -4, SEEK_END ); + fread( buf, 4, 1, file ); + *eof = get_le32( buf ); + } + else + { + fseek( file, 0, SEEK_END ); + *eof = ftell( file ); + } + const char* err = (ferror( file ) || feof( file )) ? "Couldn't get file size" : 0; + fclose( file ); + return err; +} + +Gzip_File_Reader::Gzip_File_Reader() : file_( 0 ) { } + +Gzip_File_Reader::~Gzip_File_Reader() { close(); } + +blargg_err_t Gzip_File_Reader::open( const char* path ) +{ + close(); + + RETURN_ERR( get_gzip_eof( path, &size_ ) ); + + file_ = gzopen( path, "rb" ); + if ( !file_ ) + return "Couldn't open file"; + + return 0; +} + +long Gzip_File_Reader::size() const { return size_; } + +long Gzip_File_Reader::read_avail( void* p, long s ) { return gzread( file_, p, s ); } + +long Gzip_File_Reader::tell() const { return gztell( file_ ); } + +blargg_err_t Gzip_File_Reader::seek( long n ) +{ + if ( gzseek( file_, n, SEEK_SET ) >= 0 ) + return 0; + if ( n > size_ ) + return eof_error; + return "Error seeking in file"; +} + +void Gzip_File_Reader::close() +{ + if ( file_ ) + { + gzclose( file_ ); + file_ = 0; + } +} + +#endif diff --git a/libs/gme/gme/Data_Reader.h b/libs/gme/gme/Data_Reader.h new file mode 100644 index 000000000..acf571f67 --- /dev/null +++ b/libs/gme/gme/Data_Reader.h @@ -0,0 +1,151 @@ +// Data reader interface for uniform access + +// File_Extractor 0.4.0 +#ifndef DATA_READER_H +#define DATA_READER_H + +#include "blargg_common.h" + +// Supports reading and finding out how many bytes are remaining +class Data_Reader { +public: + virtual ~Data_Reader() { } + + static const char eof_error []; // returned by read() when request goes beyond end + + // Read at most count bytes and return number actually read, or <= 0 if error + virtual long read_avail( void*, long n ) = 0; + + // Read exactly count bytes and return error if they couldn't be read + virtual blargg_err_t read( void*, long count ); + + // Number of bytes remaining until end of file + virtual long remain() const = 0; + + // Read and discard count bytes + virtual blargg_err_t skip( long count ); + +public: + Data_Reader() { } + typedef blargg_err_t error_t; // deprecated +private: + // noncopyable + Data_Reader( const Data_Reader& ); + Data_Reader& operator = ( const Data_Reader& ); +}; + +// Supports seeking in addition to Data_Reader operations +class File_Reader : public Data_Reader { +public: + // Size of file + virtual long size() const = 0; + + // Current position in file + virtual long tell() const = 0; + + // Go to new position + virtual blargg_err_t seek( long ) = 0; + + long remain() const; + blargg_err_t skip( long n ); +}; + +// Disk file reader +class Std_File_Reader : public File_Reader { +public: + blargg_err_t open( const char* path ); + void close(); + +public: + Std_File_Reader(); + ~Std_File_Reader(); + long size() const; + blargg_err_t read( void*, long ); + long read_avail( void*, long ); + long tell() const; + blargg_err_t seek( long ); +private: + void* file_; +}; + +// Treats range of memory as a file +class Mem_File_Reader : public File_Reader { +public: + Mem_File_Reader( const void*, long size ); + +public: + long size() const; + long read_avail( void*, long ); + long tell() const; + blargg_err_t seek( long ); +private: + const char* const begin; + const long size_; + long pos; +}; + +// Makes it look like there are only count bytes remaining +class Subset_Reader : public Data_Reader { +public: + Subset_Reader( Data_Reader*, long count ); + +public: + long remain() const; + long read_avail( void*, long ); +private: + Data_Reader* in; + long remain_; +}; + +// Joins already-read header and remaining data into original file (to avoid seeking) +class Remaining_Reader : public Data_Reader { +public: + Remaining_Reader( void const* header, long size, Data_Reader* ); + +public: + long remain() const; + long read_avail( void*, long ); + blargg_err_t read( void*, long ); +private: + char const* header; + char const* header_end; + Data_Reader* in; + long read_first( void* out, long count ); +}; + +// Invokes callback function to read data. Size of data must be specified in advance. +class Callback_Reader : public Data_Reader { +public: + typedef const char* (*callback_t)( void* data, void* out, int count ); + Callback_Reader( callback_t, long size, void* data = 0 ); +public: + long read_avail( void*, long ); + blargg_err_t read( void*, long ); + long remain() const; +private: + callback_t const callback; + void* const data; + long remain_; +}; + +#ifdef HAVE_ZLIB_H +// Gzip compressed file reader +class Gzip_File_Reader : public File_Reader { +public: + blargg_err_t open( const char* path ); + void close(); + +public: + Gzip_File_Reader(); + ~Gzip_File_Reader(); + long size() const; + long read_avail( void*, long ); + long tell() const; + blargg_err_t seek( long ); +private: + void* file_; + long size_; +}; +#endif + +#endif diff --git a/libs/gme/gme/Dual_Resampler.cpp b/libs/gme/gme/Dual_Resampler.cpp new file mode 100644 index 000000000..1c2cc36e2 --- /dev/null +++ b/libs/gme/gme/Dual_Resampler.cpp @@ -0,0 +1,137 @@ +// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/ + +#include "Dual_Resampler.h" + +#include +#include + +/* Copyright (C) 2003-2006 Shay Green. This module 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 +module 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 module; if not, write to the Free Software Foundation, +Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + +#include "blargg_source.h" + +unsigned const resampler_extra = 256; + +Dual_Resampler::Dual_Resampler() : + sample_buf_size(0), + oversamples_per_frame(-1), + buf_pos(-1), + resampler_size(0) +{ +} + +Dual_Resampler::~Dual_Resampler() { } + +blargg_err_t Dual_Resampler::reset( int pairs ) +{ + // expand allocations a bit + RETURN_ERR( sample_buf.resize( (pairs + (pairs >> 2)) * 2 ) ); + resize( pairs ); + resampler_size = oversamples_per_frame + (oversamples_per_frame >> 2); + return resampler.buffer_size( resampler_size ); +} + +void Dual_Resampler::resize( int pairs ) +{ + int new_sample_buf_size = pairs * 2; + if ( sample_buf_size != new_sample_buf_size ) + { + if ( (unsigned) new_sample_buf_size > sample_buf.size() ) + { + check( false ); + return; + } + sample_buf_size = new_sample_buf_size; + oversamples_per_frame = int (pairs * resampler.ratio()) * 2 + 2; + clear(); + } +} + +void Dual_Resampler::play_frame_( Blip_Buffer& blip_buf, dsample_t* out ) +{ + long pair_count = sample_buf_size >> 1; + blip_time_t blip_time = blip_buf.count_clocks( pair_count ); + int sample_count = oversamples_per_frame - resampler.written(); + + int new_count = play_frame( blip_time, sample_count, resampler.buffer() ); + assert( new_count < resampler_size ); + + blip_buf.end_frame( blip_time ); + assert( blip_buf.samples_avail() == pair_count ); + + resampler.write( new_count ); + + long count = resampler.read( sample_buf.begin(), sample_buf_size ); + assert( count == (long) sample_buf_size ); + + mix_samples( blip_buf, out ); + blip_buf.remove_samples( pair_count ); +} + +void Dual_Resampler::dual_play( long count, dsample_t* out, Blip_Buffer& blip_buf ) +{ + // empty extra buffer + long remain = sample_buf_size - buf_pos; + if ( remain ) + { + if ( remain > count ) + remain = count; + count -= remain; + memcpy( out, &sample_buf [buf_pos], remain * sizeof *out ); + out += remain; + buf_pos += remain; + } + + // entire frames + while ( count >= (long) sample_buf_size ) + { + play_frame_( blip_buf, out ); + out += sample_buf_size; + count -= sample_buf_size; + } + + // extra + if ( count ) + { + play_frame_( blip_buf, sample_buf.begin() ); + buf_pos = count; + memcpy( out, sample_buf.begin(), count * sizeof *out ); + out += count; + } +} + +void Dual_Resampler::mix_samples( Blip_Buffer& blip_buf, dsample_t* out ) +{ + Blip_Reader sn; + int bass = sn.begin( blip_buf ); + const dsample_t* in = sample_buf.begin(); + + for ( int n = sample_buf_size >> 1; n--; ) + { + int s = sn.read(); + blargg_long l = (blargg_long) in [0] * 2 + s; + if ( (BOOST::int16_t) l != l ) + l = 0x7FFF - (l >> 24); + + sn.next( bass ); + blargg_long r = (blargg_long) in [1] * 2 + s; + if ( (BOOST::int16_t) r != r ) + r = 0x7FFF - (r >> 24); + + in += 2; + out [0] = l; + out [1] = r; + out += 2; + } + + sn.end( blip_buf ); +} + diff --git a/libs/gme/gme/Dual_Resampler.h b/libs/gme/gme/Dual_Resampler.h new file mode 100644 index 000000000..6dc8dcfc2 --- /dev/null +++ b/libs/gme/gme/Dual_Resampler.h @@ -0,0 +1,50 @@ +// Combination of Fir_Resampler and Blip_Buffer mixing. Used by Sega FM emulators. + +// Game_Music_Emu 0.6.0 +#ifndef DUAL_RESAMPLER_H +#define DUAL_RESAMPLER_H + +#include "Fir_Resampler.h" +#include "Blip_Buffer.h" + +class Dual_Resampler { +public: + Dual_Resampler(); + virtual ~Dual_Resampler(); + + typedef short dsample_t; + + double setup( double oversample, double rolloff, double gain ); + blargg_err_t reset( int max_pairs ); + void resize( int pairs_per_frame ); + void clear(); + + void dual_play( long count, dsample_t* out, Blip_Buffer& ); + +protected: + virtual int play_frame( blip_time_t, int pcm_count, dsample_t* pcm_out ) = 0; +private: + + blargg_vector sample_buf; + int sample_buf_size; + int oversamples_per_frame; + int buf_pos; + int resampler_size; + + Fir_Resampler<12> resampler; + void mix_samples( Blip_Buffer&, dsample_t* ); + void play_frame_( Blip_Buffer&, dsample_t* ); +}; + +inline double Dual_Resampler::setup( double oversample, double rolloff, double gain ) +{ + return resampler.time_ratio( oversample, rolloff, gain * 0.5 ); +} + +inline void Dual_Resampler::clear() +{ + buf_pos = sample_buf_size; + resampler.clear(); +} + +#endif diff --git a/libs/gme/gme/Effects_Buffer.cpp b/libs/gme/gme/Effects_Buffer.cpp new file mode 100644 index 000000000..6af9c14be --- /dev/null +++ b/libs/gme/gme/Effects_Buffer.cpp @@ -0,0 +1,529 @@ +// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/ + +#include "Effects_Buffer.h" + +#include + +/* Copyright (C) 2003-2006 Shay Green. This module 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 +module 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 module; if not, write to the Free Software Foundation, +Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + +#include "blargg_source.h" + +#ifdef BLARGG_ENABLE_OPTIMIZER + #include BLARGG_ENABLE_OPTIMIZER +#endif + +typedef blargg_long fixed_t; + +#define TO_FIXED( f ) fixed_t ((f) * (1L << 15) + 0.5) +#define FMUL( x, y ) (((x) * (y)) >> 15) + +const unsigned echo_size = 4096; +const unsigned echo_mask = echo_size - 1; +BOOST_STATIC_ASSERT( (echo_size & echo_mask) == 0 ); // must be power of 2 + +const unsigned reverb_size = 8192 * 2; +const unsigned reverb_mask = reverb_size - 1; +BOOST_STATIC_ASSERT( (reverb_size & reverb_mask) == 0 ); // must be power of 2 + +Effects_Buffer::config_t::config_t() +{ + pan_1 = -0.15f; + pan_2 = 0.15f; + reverb_delay = 88.0f; + reverb_level = 0.12f; + echo_delay = 61.0f; + echo_level = 0.10f; + delay_variance = 18.0f; + effects_enabled = false; +} + +void Effects_Buffer::set_depth( double d ) +{ + float f = (float) d; + config_t c; + c.pan_1 = -0.6f * f; + c.pan_2 = 0.6f * f; + c.reverb_delay = 880 * 0.1f; + c.echo_delay = 610 * 0.1f; + if ( f > 0.5 ) + f = 0.5; // TODO: more linear reduction of extreme reverb/echo + c.reverb_level = 0.5f * f; + c.echo_level = 0.30f * f; + c.delay_variance = 180 * 0.1f; + c.effects_enabled = (d > 0.0f); + config( c ); +} + +Effects_Buffer::Effects_Buffer( bool center_only ) : Multi_Buffer( 2 ) +{ + buf_count = center_only ? max_buf_count - 4 : max_buf_count; + + echo_pos = 0; + reverb_pos = 0; + + stereo_remain = 0; + effect_remain = 0; + effects_enabled = false; + set_depth( 0 ); +} + +Effects_Buffer::~Effects_Buffer() { } + +blargg_err_t Effects_Buffer::set_sample_rate( long rate, int msec ) +{ + if ( !echo_buf.size() ) + RETURN_ERR( echo_buf.resize( echo_size ) ); + + if ( !reverb_buf.size() ) + RETURN_ERR( reverb_buf.resize( reverb_size ) ); + + for ( int i = 0; i < buf_count; i++ ) + RETURN_ERR( bufs [i].set_sample_rate( rate, msec ) ); + + config( config_ ); + clear(); + + return Multi_Buffer::set_sample_rate( bufs [0].sample_rate(), bufs [0].length() ); +} + +void Effects_Buffer::clock_rate( long rate ) +{ + for ( int i = 0; i < buf_count; i++ ) + bufs [i].clock_rate( rate ); +} + +void Effects_Buffer::bass_freq( int freq ) +{ + for ( int i = 0; i < buf_count; i++ ) + bufs [i].bass_freq( freq ); +} + +void Effects_Buffer::clear() +{ + stereo_remain = 0; + effect_remain = 0; + if ( echo_buf.size() ) + memset( &echo_buf [0], 0, echo_size * sizeof echo_buf [0] ); + + if ( reverb_buf.size() ) + memset( &reverb_buf [0], 0, reverb_size * sizeof reverb_buf [0] ); + + for ( int i = 0; i < buf_count; i++ ) + bufs [i].clear(); +} + +inline int pin_range( int n, int max, int min = 0 ) +{ + if ( n < min ) + return min; + if ( n > max ) + return max; + return n; +} + +void Effects_Buffer::config( const config_t& cfg ) +{ + channels_changed(); + + // clear echo and reverb buffers + if ( !config_.effects_enabled && cfg.effects_enabled && echo_buf.size() ) + { + memset( &echo_buf [0], 0, echo_size * sizeof echo_buf [0] ); + memset( &reverb_buf [0], 0, reverb_size * sizeof reverb_buf [0] ); + } + + config_ = cfg; + + if ( config_.effects_enabled ) + { + // convert to internal format + + chans.pan_1_levels [0] = TO_FIXED( 1 ) - TO_FIXED( config_.pan_1 ); + chans.pan_1_levels [1] = TO_FIXED( 2 ) - chans.pan_1_levels [0]; + + chans.pan_2_levels [0] = TO_FIXED( 1 ) - TO_FIXED( config_.pan_2 ); + chans.pan_2_levels [1] = TO_FIXED( 2 ) - chans.pan_2_levels [0]; + + chans.reverb_level = TO_FIXED( config_.reverb_level ); + chans.echo_level = TO_FIXED( config_.echo_level ); + + int delay_offset = int (1.0 / 2000 * config_.delay_variance * sample_rate()); + + int reverb_sample_delay = int (1.0 / 1000 * config_.reverb_delay * sample_rate()); + chans.reverb_delay_l = pin_range( reverb_size - + (reverb_sample_delay - delay_offset) * 2, reverb_size - 2, 0 ); + chans.reverb_delay_r = pin_range( reverb_size + 1 - + (reverb_sample_delay + delay_offset) * 2, reverb_size - 1, 1 ); + + int echo_sample_delay = int (1.0 / 1000 * config_.echo_delay * sample_rate()); + chans.echo_delay_l = pin_range( echo_size - 1 - (echo_sample_delay - delay_offset), + echo_size - 1 ); + chans.echo_delay_r = pin_range( echo_size - 1 - (echo_sample_delay + delay_offset), + echo_size - 1 ); + + chan_types [0].center = &bufs [0]; + chan_types [0].left = &bufs [3]; + chan_types [0].right = &bufs [4]; + + chan_types [1].center = &bufs [1]; + chan_types [1].left = &bufs [3]; + chan_types [1].right = &bufs [4]; + + chan_types [2].center = &bufs [2]; + chan_types [2].left = &bufs [5]; + chan_types [2].right = &bufs [6]; + assert( 2 < chan_types_count ); + } + else + { + // set up outputs + for ( unsigned i = 0; i < chan_types_count; i++ ) + { + channel_t& c = chan_types [i]; + c.center = &bufs [0]; + c.left = &bufs [1]; + c.right = &bufs [2]; + } + } + + if ( buf_count < max_buf_count ) + { + for ( int i = 0; i < chan_types_count; i++ ) + { + channel_t& c = chan_types [i]; + c.left = c.center; + c.right = c.center; + } + } +} + +Effects_Buffer::channel_t Effects_Buffer::channel( int i, int type ) +{ + int out = 2; + if ( !type ) + { + out = i % 5; + if ( out > 2 ) + out = 2; + } + else if ( !(type & noise_type) && (type & type_index_mask) % 3 != 0 ) + { + out = type & 1; + } + return chan_types [out]; +} + +void Effects_Buffer::end_frame( blip_time_t clock_count ) +{ + int bufs_used = 0; + for ( int i = 0; i < buf_count; i++ ) + { + bufs_used |= bufs [i].clear_modified() << i; + bufs [i].end_frame( clock_count ); + } + + int stereo_mask = (config_.effects_enabled ? 0x78 : 0x06); + if ( (bufs_used & stereo_mask) && buf_count == max_buf_count ) + stereo_remain = bufs [0].samples_avail() + bufs [0].output_latency(); + + if ( effects_enabled || config_.effects_enabled ) + effect_remain = bufs [0].samples_avail() + bufs [0].output_latency(); + + effects_enabled = config_.effects_enabled; +} + +long Effects_Buffer::samples_avail() const +{ + return bufs [0].samples_avail() * 2; +} + +long Effects_Buffer::read_samples( blip_sample_t* out, long total_samples ) +{ + require( total_samples % 2 == 0 ); // count must be even + + long remain = bufs [0].samples_avail(); + if ( remain > (total_samples >> 1) ) + remain = (total_samples >> 1); + total_samples = remain; + while ( remain ) + { + int active_bufs = buf_count; + long count = remain; + + // optimizing mixing to skip any channels which had nothing added + if ( effect_remain ) + { + if ( count > effect_remain ) + count = effect_remain; + + if ( stereo_remain ) + { + mix_enhanced( out, count ); + } + else + { + mix_mono_enhanced( out, count ); + active_bufs = 3; + } + } + else if ( stereo_remain ) + { + mix_stereo( out, count ); + active_bufs = 3; + } + else + { + mix_mono( out, count ); + active_bufs = 1; + } + + out += count * 2; + remain -= count; + + stereo_remain -= count; + if ( stereo_remain < 0 ) + stereo_remain = 0; + + effect_remain -= count; + if ( effect_remain < 0 ) + effect_remain = 0; + + for ( int i = 0; i < buf_count; i++ ) + { + if ( i < active_bufs ) + bufs [i].remove_samples( count ); + else + bufs [i].remove_silence( count ); // keep time synchronized + } + } + + return total_samples * 2; +} + +void Effects_Buffer::mix_mono( blip_sample_t* out_, blargg_long count ) +{ + blip_sample_t* BLIP_RESTRICT out = out_; + int const bass = BLIP_READER_BASS( bufs [0] ); + BLIP_READER_BEGIN( c, bufs [0] ); + + // unrolled loop + for ( blargg_long n = count >> 1; n; --n ) + { + blargg_long cs0 = BLIP_READER_READ( c ); + BLIP_READER_NEXT( c, bass ); + + blargg_long cs1 = BLIP_READER_READ( c ); + BLIP_READER_NEXT( c, bass ); + + if ( (BOOST::int16_t) cs0 != cs0 ) + cs0 = 0x7FFF - (cs0 >> 24); + ((BOOST::uint32_t*) out) [0] = ((BOOST::uint16_t) cs0) | (cs0 << 16); + + if ( (BOOST::int16_t) cs1 != cs1 ) + cs1 = 0x7FFF - (cs1 >> 24); + ((BOOST::uint32_t*) out) [1] = ((BOOST::uint16_t) cs1) | (cs1 << 16); + out += 4; + } + + if ( count & 1 ) + { + int s = BLIP_READER_READ( c ); + BLIP_READER_NEXT( c, bass ); + out [0] = s; + out [1] = s; + if ( (BOOST::int16_t) s != s ) + { + s = 0x7FFF - (s >> 24); + out [0] = s; + out [1] = s; + } + } + + BLIP_READER_END( c, bufs [0] ); +} + +void Effects_Buffer::mix_stereo( blip_sample_t* out_, blargg_long count ) +{ + blip_sample_t* BLIP_RESTRICT out = out_; + int const bass = BLIP_READER_BASS( bufs [0] ); + BLIP_READER_BEGIN( c, bufs [0] ); + BLIP_READER_BEGIN( l, bufs [1] ); + BLIP_READER_BEGIN( r, bufs [2] ); + + while ( count-- ) + { + int cs = BLIP_READER_READ( c ); + BLIP_READER_NEXT( c, bass ); + int left = cs + BLIP_READER_READ( l ); + int right = cs + BLIP_READER_READ( r ); + BLIP_READER_NEXT( l, bass ); + BLIP_READER_NEXT( r, bass ); + + if ( (BOOST::int16_t) left != left ) + left = 0x7FFF - (left >> 24); + + out [0] = left; + out [1] = right; + + out += 2; + + if ( (BOOST::int16_t) right != right ) + out [-1] = 0x7FFF - (right >> 24); + } + + BLIP_READER_END( r, bufs [2] ); + BLIP_READER_END( l, bufs [1] ); + BLIP_READER_END( c, bufs [0] ); +} + +void Effects_Buffer::mix_mono_enhanced( blip_sample_t* out_, blargg_long count ) +{ + blip_sample_t* BLIP_RESTRICT out = out_; + int const bass = BLIP_READER_BASS( bufs [2] ); + BLIP_READER_BEGIN( center, bufs [2] ); + BLIP_READER_BEGIN( sq1, bufs [0] ); + BLIP_READER_BEGIN( sq2, bufs [1] ); + + blip_sample_t* const reverb_buf = this->reverb_buf.begin(); + blip_sample_t* const echo_buf = this->echo_buf.begin(); + int echo_pos = this->echo_pos; + int reverb_pos = this->reverb_pos; + + while ( count-- ) + { + int sum1_s = BLIP_READER_READ( sq1 ); + int sum2_s = BLIP_READER_READ( sq2 ); + + BLIP_READER_NEXT( sq1, bass ); + BLIP_READER_NEXT( sq2, bass ); + + int new_reverb_l = FMUL( sum1_s, chans.pan_1_levels [0] ) + + FMUL( sum2_s, chans.pan_2_levels [0] ) + + reverb_buf [(reverb_pos + chans.reverb_delay_l) & reverb_mask]; + + int new_reverb_r = FMUL( sum1_s, chans.pan_1_levels [1] ) + + FMUL( sum2_s, chans.pan_2_levels [1] ) + + reverb_buf [(reverb_pos + chans.reverb_delay_r) & reverb_mask]; + + fixed_t reverb_level = chans.reverb_level; + reverb_buf [reverb_pos] = (blip_sample_t) FMUL( new_reverb_l, reverb_level ); + reverb_buf [reverb_pos + 1] = (blip_sample_t) FMUL( new_reverb_r, reverb_level ); + reverb_pos = (reverb_pos + 2) & reverb_mask; + + int sum3_s = BLIP_READER_READ( center ); + BLIP_READER_NEXT( center, bass ); + + int left = new_reverb_l + sum3_s + FMUL( chans.echo_level, + echo_buf [(echo_pos + chans.echo_delay_l) & echo_mask] ); + int right = new_reverb_r + sum3_s + FMUL( chans.echo_level, + echo_buf [(echo_pos + chans.echo_delay_r) & echo_mask] ); + + echo_buf [echo_pos] = sum3_s; + echo_pos = (echo_pos + 1) & echo_mask; + + if ( (BOOST::int16_t) left != left ) + left = 0x7FFF - (left >> 24); + + out [0] = left; + out [1] = right; + + out += 2; + + if ( (BOOST::int16_t) right != right ) + out [-1] = 0x7FFF - (right >> 24); + } + this->reverb_pos = reverb_pos; + this->echo_pos = echo_pos; + + BLIP_READER_END( sq1, bufs [0] ); + BLIP_READER_END( sq2, bufs [1] ); + BLIP_READER_END( center, bufs [2] ); +} + +void Effects_Buffer::mix_enhanced( blip_sample_t* out_, blargg_long count ) +{ + blip_sample_t* BLIP_RESTRICT out = out_; + int const bass = BLIP_READER_BASS( bufs [2] ); + BLIP_READER_BEGIN( center, bufs [2] ); + BLIP_READER_BEGIN( l1, bufs [3] ); + BLIP_READER_BEGIN( r1, bufs [4] ); + BLIP_READER_BEGIN( l2, bufs [5] ); + BLIP_READER_BEGIN( r2, bufs [6] ); + BLIP_READER_BEGIN( sq1, bufs [0] ); + BLIP_READER_BEGIN( sq2, bufs [1] ); + + blip_sample_t* const reverb_buf = this->reverb_buf.begin(); + blip_sample_t* const echo_buf = this->echo_buf.begin(); + int echo_pos = this->echo_pos; + int reverb_pos = this->reverb_pos; + + while ( count-- ) + { + int sum1_s = BLIP_READER_READ( sq1 ); + int sum2_s = BLIP_READER_READ( sq2 ); + + BLIP_READER_NEXT( sq1, bass ); + BLIP_READER_NEXT( sq2, bass ); + + int new_reverb_l = FMUL( sum1_s, chans.pan_1_levels [0] ) + + FMUL( sum2_s, chans.pan_2_levels [0] ) + BLIP_READER_READ( l1 ) + + reverb_buf [(reverb_pos + chans.reverb_delay_l) & reverb_mask]; + + int new_reverb_r = FMUL( sum1_s, chans.pan_1_levels [1] ) + + FMUL( sum2_s, chans.pan_2_levels [1] ) + BLIP_READER_READ( r1 ) + + reverb_buf [(reverb_pos + chans.reverb_delay_r) & reverb_mask]; + + BLIP_READER_NEXT( l1, bass ); + BLIP_READER_NEXT( r1, bass ); + + fixed_t reverb_level = chans.reverb_level; + reverb_buf [reverb_pos] = (blip_sample_t) FMUL( new_reverb_l, reverb_level ); + reverb_buf [reverb_pos + 1] = (blip_sample_t) FMUL( new_reverb_r, reverb_level ); + reverb_pos = (reverb_pos + 2) & reverb_mask; + + int sum3_s = BLIP_READER_READ( center ); + BLIP_READER_NEXT( center, bass ); + + int left = new_reverb_l + sum3_s + BLIP_READER_READ( l2 ) + FMUL( chans.echo_level, + echo_buf [(echo_pos + chans.echo_delay_l) & echo_mask] ); + int right = new_reverb_r + sum3_s + BLIP_READER_READ( r2 ) + FMUL( chans.echo_level, + echo_buf [(echo_pos + chans.echo_delay_r) & echo_mask] ); + + BLIP_READER_NEXT( l2, bass ); + BLIP_READER_NEXT( r2, bass ); + + echo_buf [echo_pos] = sum3_s; + echo_pos = (echo_pos + 1) & echo_mask; + + if ( (BOOST::int16_t) left != left ) + left = 0x7FFF - (left >> 24); + + out [0] = left; + out [1] = right; + + out += 2; + + if ( (BOOST::int16_t) right != right ) + out [-1] = 0x7FFF - (right >> 24); + } + this->reverb_pos = reverb_pos; + this->echo_pos = echo_pos; + + BLIP_READER_END( l1, bufs [3] ); + BLIP_READER_END( r1, bufs [4] ); + BLIP_READER_END( l2, bufs [5] ); + BLIP_READER_END( r2, bufs [6] ); + BLIP_READER_END( sq1, bufs [0] ); + BLIP_READER_END( sq2, bufs [1] ); + BLIP_READER_END( center, bufs [2] ); +} + diff --git a/libs/gme/gme/Effects_Buffer.h b/libs/gme/gme/Effects_Buffer.h new file mode 100644 index 000000000..832c44b06 --- /dev/null +++ b/libs/gme/gme/Effects_Buffer.h @@ -0,0 +1,86 @@ +// Multi-channel effects buffer with panning, echo and reverb + +// Game_Music_Emu 0.6.0 +#ifndef EFFECTS_BUFFER_H +#define EFFECTS_BUFFER_H + +#include "Multi_Buffer.h" + +// Effects_Buffer uses several buffers and outputs stereo sample pairs. +class Effects_Buffer : public Multi_Buffer { +public: + // If center_only is true, only center buffers are created and + // less memory is used. + Effects_Buffer( bool center_only = false ); + + // Channel Effect Center Pan + // --------------------------------- + // 0,5 reverb pan_1 + // 1,6 reverb pan_2 + // 2,7 echo - + // 3 echo - + // 4 echo - + + // Channel configuration + struct config_t { + double pan_1; // -1.0 = left, 0.0 = center, 1.0 = right + double pan_2; + double echo_delay; // msec + double echo_level; // 0.0 to 1.0 + double reverb_delay; // msec + double delay_variance; // difference between left/right delays (msec) + double reverb_level; // 0.0 to 1.0 + bool effects_enabled; // if false, use optimized simple mixer + config_t(); + }; + + // Set configuration of buffer + virtual void config( const config_t& ); + void set_depth( double ); + +public: + ~Effects_Buffer(); + blargg_err_t set_sample_rate( long samples_per_sec, int msec = blip_default_length ); + void clock_rate( long ); + void bass_freq( int ); + void clear(); + channel_t channel( int, int ); + void end_frame( blip_time_t ); + long read_samples( blip_sample_t*, long ); + long samples_avail() const; +private: + typedef long fixed_t; + + enum { max_buf_count = 7 }; + Blip_Buffer bufs [max_buf_count]; + enum { chan_types_count = 3 }; + channel_t chan_types [3]; + config_t config_; + long stereo_remain; + long effect_remain; + int buf_count; + bool effects_enabled; + + blargg_vector reverb_buf; + blargg_vector echo_buf; + int reverb_pos; + int echo_pos; + + struct { + fixed_t pan_1_levels [2]; + fixed_t pan_2_levels [2]; + int echo_delay_l; + int echo_delay_r; + fixed_t echo_level; + int reverb_delay_l; + int reverb_delay_r; + fixed_t reverb_level; + } chans; + + void mix_mono( blip_sample_t*, blargg_long ); + void mix_stereo( blip_sample_t*, blargg_long ); + void mix_enhanced( blip_sample_t*, blargg_long ); + void mix_mono_enhanced( blip_sample_t*, blargg_long ); +}; + +#endif diff --git a/libs/gme/gme/Fir_Resampler.cpp b/libs/gme/gme/Fir_Resampler.cpp new file mode 100644 index 000000000..7a6600be8 --- /dev/null +++ b/libs/gme/gme/Fir_Resampler.cpp @@ -0,0 +1,199 @@ +// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/ + +#include "Fir_Resampler.h" + +#include +#include +#include +#include + +/* Copyright (C) 2004-2006 Shay Green. This module 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 +module 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 module; if not, write to the Free Software Foundation, +Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + +#include "blargg_source.h" + +#undef PI +#define PI 3.1415926535897932384626433832795029 + +static void gen_sinc( double rolloff, int width, double offset, double spacing, double scale, + int count, short* out ) +{ + double const maxh = 256; + double const step = PI / maxh * spacing; + double const to_w = maxh * 2 / width; + double const pow_a_n = pow( rolloff, maxh ); + scale /= maxh * 2; + + double angle = (count / 2 - 1 + offset) * -step; + while ( count-- ) + { + *out++ = 0; + double w = angle * to_w; + if ( fabs( w ) < PI ) + { + double rolloff_cos_a = rolloff * cos( angle ); + double num = 1 - rolloff_cos_a - + pow_a_n * cos( maxh * angle ) + + pow_a_n * rolloff * cos( (maxh - 1) * angle ); + double den = 1 - rolloff_cos_a - rolloff_cos_a + rolloff * rolloff; + double sinc = scale * num / den - scale; + + out [-1] = (short) (cos( w ) * sinc + sinc); + } + angle += step; + } +} + +Fir_Resampler_::Fir_Resampler_( int width, sample_t* impulses_ ) : + width_( width ), + write_offset( width * stereo - stereo ), + impulses( impulses_ ) +{ + write_pos = 0; + res = 1; + imp_phase = 0; + skip_bits = 0; + step = stereo; + ratio_ = 1.0; +} + +Fir_Resampler_::~Fir_Resampler_() { } + +void Fir_Resampler_::clear() +{ + imp_phase = 0; + if ( buf.size() ) + { + write_pos = &buf [write_offset]; + memset( buf.begin(), 0, write_offset * sizeof buf [0] ); + } +} + +blargg_err_t Fir_Resampler_::buffer_size( int new_size ) +{ + RETURN_ERR( buf.resize( new_size + write_offset ) ); + clear(); + return 0; +} + +double Fir_Resampler_::time_ratio( double new_factor, double rolloff, double gain ) +{ + ratio_ = new_factor; + + double fstep = 0.0; + { + double least_error = 2; + double pos = 0; + res = -1; + for ( int r = 1; r <= max_res; r++ ) + { + pos += ratio_; + double nearest = floor( pos + 0.5 ); + double error = fabs( pos - nearest ); + if ( error < least_error ) + { + res = r; + fstep = nearest / res; + least_error = error; + } + } + } + + skip_bits = 0; + + step = stereo * (int) floor( fstep ); + + ratio_ = fstep; + fstep = fmod( fstep, 1.0 ); + + double filter = (ratio_ < 1.0) ? 1.0 : 1.0 / ratio_; + double pos = 0.0; + input_per_cycle = 0; + for ( int i = 0; i < res; i++ ) + { + gen_sinc( rolloff, int (width_ * filter + 1) & ~1, pos, filter, + double (0x7FFF * gain * filter), + (int) width_, impulses + i * width_ ); + + pos += fstep; + input_per_cycle += step; + if ( pos >= 0.9999999 ) + { + pos -= 1.0; + skip_bits |= 1 << i; + input_per_cycle++; + } + } + + clear(); + + return ratio_; +} + +int Fir_Resampler_::input_needed( blargg_long output_count ) const +{ + blargg_long input_count = 0; + + unsigned long skip = skip_bits >> imp_phase; + int remain = res - imp_phase; + while ( (output_count -= 2) > 0 ) + { + input_count += step + (skip & 1) * stereo; + skip >>= 1; + if ( !--remain ) + { + skip = skip_bits; + remain = res; + } + output_count -= 2; + } + + long input_extra = input_count - (write_pos - &buf [(width_ - 1) * stereo]); + if ( input_extra < 0 ) + input_extra = 0; + return input_extra; +} + +int Fir_Resampler_::avail_( blargg_long input_count ) const +{ + int cycle_count = input_count / input_per_cycle; + int output_count = cycle_count * res * stereo; + input_count -= cycle_count * input_per_cycle; + + blargg_ulong skip = skip_bits >> imp_phase; + int remain = res - imp_phase; + while ( input_count >= 0 ) + { + input_count -= step + (skip & 1) * stereo; + skip >>= 1; + if ( !--remain ) + { + skip = skip_bits; + remain = res; + } + output_count += 2; + } + return output_count; +} + +int Fir_Resampler_::skip_input( long count ) +{ + int remain = write_pos - buf.begin(); + int max_count = remain - width_ * stereo; + if ( count > max_count ) + count = max_count; + + remain -= count; + write_pos = &buf [remain]; + memmove( buf.begin(), &buf [count], remain * sizeof buf [0] ); + + return count; +} diff --git a/libs/gme/gme/Fir_Resampler.h b/libs/gme/gme/Fir_Resampler.h new file mode 100644 index 000000000..a1bb67781 --- /dev/null +++ b/libs/gme/gme/Fir_Resampler.h @@ -0,0 +1,171 @@ +// Finite impulse response (FIR) resampler with adjustable FIR size + +// Game_Music_Emu 0.6.0 +#ifndef FIR_RESAMPLER_H +#define FIR_RESAMPLER_H + +#include "blargg_common.h" +#include + +class Fir_Resampler_ { +public: + + // Use Fir_Resampler (below) + + // Set input/output resampling ratio and optionally low-pass rolloff and gain. + // Returns actual ratio used (rounded to internal precision). + double time_ratio( double factor, double rolloff = 0.999, double gain = 1.0 ); + + // Current input/output ratio + double ratio() const { return ratio_; } + +// Input + + typedef short sample_t; + + // Resize and clear input buffer + blargg_err_t buffer_size( int ); + + // Clear input buffer. At least two output samples will be available after + // two input samples are written. + void clear(); + + // Number of input samples that can be written + int max_write() const { return buf.end() - write_pos; } + + // Pointer to place to write input samples + sample_t* buffer() { return write_pos; } + + // Notify resampler that 'count' input samples have been written + void write( long count ); + + // Number of input samples in buffer + int written() const { return write_pos - &buf [write_offset]; } + + // Skip 'count' input samples. Returns number of samples actually skipped. + int skip_input( long count ); + +// Output + + // Number of extra input samples needed until 'count' output samples are available + int input_needed( blargg_long count ) const; + + // Number of output samples available + int avail() const { return avail_( write_pos - &buf [width_ * stereo] ); } + +public: + ~Fir_Resampler_(); +protected: + enum { stereo = 2 }; + enum { max_res = 32 }; + blargg_vector buf; + sample_t* write_pos; + int res; + int imp_phase; + int const width_; + int const write_offset; + blargg_ulong skip_bits; + int step; + int input_per_cycle; + double ratio_; + sample_t* impulses; + + Fir_Resampler_( int width, sample_t* ); + int avail_( blargg_long input_count ) const; +}; + +// Width is number of points in FIR. Must be even and 4 or more. More points give +// better quality and rolloff effectiveness, and take longer to calculate. +template +class Fir_Resampler : public Fir_Resampler_ { + BOOST_STATIC_ASSERT( width >= 4 && width % 2 == 0 ); + short impulses [max_res] [width]; +public: + Fir_Resampler() : Fir_Resampler_( width, impulses [0] ) { } + + // Read at most 'count' samples. Returns number of samples actually read. + typedef short sample_t; + int read( sample_t* out, blargg_long count ); +}; + +// End of public interface + +inline void Fir_Resampler_::write( long count ) +{ + write_pos += count; + assert( write_pos <= buf.end() ); +} + +template +int Fir_Resampler::read( sample_t* out_begin, blargg_long count ) +{ + sample_t* out = out_begin; + const sample_t* in = buf.begin(); + sample_t* end_pos = write_pos; + blargg_ulong skip = skip_bits >> imp_phase; + sample_t const* imp = impulses [imp_phase]; + int remain = res - imp_phase; + int const step = this->step; + + count >>= 1; + + if ( end_pos - in >= width * stereo ) + { + end_pos -= width * stereo; + do + { + count--; + + // accumulate in extended precision + blargg_long l = 0; + blargg_long r = 0; + + const sample_t* i = in; + if ( count < 0 ) + break; + + for ( int n = width / 2; n; --n ) + { + int pt0 = imp [0]; + l += pt0 * i [0]; + r += pt0 * i [1]; + int pt1 = imp [1]; + imp += 2; + l += pt1 * i [2]; + r += pt1 * i [3]; + i += 4; + } + + remain--; + + l >>= 15; + r >>= 15; + + in += (skip * stereo) & stereo; + skip >>= 1; + in += step; + + if ( !remain ) + { + imp = impulses [0]; + skip = skip_bits; + remain = res; + } + + out [0] = (sample_t) l; + out [1] = (sample_t) r; + out += 2; + } + while ( in <= end_pos ); + } + + imp_phase = res - remain; + + int left = write_pos - in; + write_pos = &buf [left]; + memmove( buf.begin(), in, left * sizeof *in ); + + return out - out_begin; +} + +#endif diff --git a/libs/gme/gme/Gb_Apu.cpp b/libs/gme/gme/Gb_Apu.cpp new file mode 100644 index 000000000..866594ddf --- /dev/null +++ b/libs/gme/gme/Gb_Apu.cpp @@ -0,0 +1,306 @@ +// Gb_Snd_Emu 0.1.5. http://www.slack.net/~ant/ + +#include "Gb_Apu.h" + +#include + +/* Copyright (C) 2003-2006 Shay Green. This module 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 +module 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 module; if not, write to the Free Software Foundation, +Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + +#include "blargg_source.h" + +unsigned const vol_reg = 0xFF24; +unsigned const status_reg = 0xFF26; + +Gb_Apu::Gb_Apu() +{ + square1.synth = &square_synth; + square2.synth = &square_synth; + wave.synth = &other_synth; + noise.synth = &other_synth; + + oscs [0] = &square1; + oscs [1] = &square2; + oscs [2] = &wave; + oscs [3] = &noise; + + for ( int i = 0; i < osc_count; i++ ) + { + Gb_Osc& osc = *oscs [i]; + osc.regs = ®s [i * 5]; + osc.output = 0; + osc.outputs [0] = 0; + osc.outputs [1] = 0; + osc.outputs [2] = 0; + osc.outputs [3] = 0; + } + + set_tempo( 1.0 ); + volume( 1.0 ); + reset(); +} + +void Gb_Apu::treble_eq( const blip_eq_t& eq ) +{ + square_synth.treble_eq( eq ); + other_synth.treble_eq( eq ); +} + +void Gb_Apu::osc_output( int index, Blip_Buffer* center, Blip_Buffer* left, Blip_Buffer* right ) +{ + require( (unsigned) index < osc_count ); + require( (center && left && right) || (!center && !left && !right) ); + Gb_Osc& osc = *oscs [index]; + osc.outputs [1] = right; + osc.outputs [2] = left; + osc.outputs [3] = center; + osc.output = osc.outputs [osc.output_select]; +} + +void Gb_Apu::output( Blip_Buffer* center, Blip_Buffer* left, Blip_Buffer* right ) +{ + for ( int i = 0; i < osc_count; i++ ) + osc_output( i, center, left, right ); +} + +void Gb_Apu::update_volume() +{ + // TODO: doesn't handle differing left/right global volume (support would + // require modification to all oscillator code) + int data = regs [vol_reg - start_addr]; + double vol = (max( data & 7, data >> 4 & 7 ) + 1) * volume_unit; + square_synth.volume( vol ); + other_synth.volume( vol ); +} + +static unsigned char const powerup_regs [0x20] = { + 0x80,0x3F,0x00,0xFF,0xBF, // square 1 + 0xFF,0x3F,0x00,0xFF,0xBF, // square 2 + 0x7F,0xFF,0x9F,0xFF,0xBF, // wave + 0xFF,0xFF,0x00,0x00,0xBF, // noise + 0x00, // left/right enables + 0x77, // master volume + 0x80, // power + 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF +}; + +void Gb_Apu::set_tempo( double t ) +{ + frame_period = 4194304 / 256; // 256 Hz + if ( t != 1.0 ) + frame_period = blip_time_t (frame_period / t); +} + +void Gb_Apu::reset() +{ + next_frame_time = 0; + last_time = 0; + frame_count = 0; + + square1.reset(); + square2.reset(); + wave.reset(); + noise.reset(); + noise.bits = 1; + wave.wave_pos = 0; + + // avoid click at beginning + regs [vol_reg - start_addr] = 0x77; + update_volume(); + + regs [status_reg - start_addr] = 0x01; // force power + write_register( 0, status_reg, 0x00 ); + + static unsigned char const initial_wave [] = { + 0x84,0x40,0x43,0xAA,0x2D,0x78,0x92,0x3C, // wave table + 0x60,0x59,0x59,0xB0,0x34,0xB8,0x2E,0xDA + }; + memcpy( wave.wave, initial_wave, sizeof wave.wave ); +} + +void Gb_Apu::run_until( blip_time_t end_time ) +{ + require( end_time >= last_time ); // end_time must not be before previous time + if ( end_time == last_time ) + return; + + while ( true ) + { + blip_time_t time = next_frame_time; + if ( time > end_time ) + time = end_time; + + // run oscillators + for ( int i = 0; i < osc_count; ++i ) + { + Gb_Osc& osc = *oscs [i]; + if ( osc.output ) + { + osc.output->set_modified(); // TODO: misses optimization opportunities? + int playing = false; + if ( osc.enabled && osc.volume && + (!(osc.regs [4] & osc.len_enabled_mask) || osc.length) ) + playing = -1; + switch ( i ) + { + case 0: square1.run( last_time, time, playing ); break; + case 1: square2.run( last_time, time, playing ); break; + case 2: wave .run( last_time, time, playing ); break; + case 3: noise .run( last_time, time, playing ); break; + } + } + } + last_time = time; + + if ( time == end_time ) + break; + + next_frame_time += frame_period; + + // 256 Hz actions + square1.clock_length(); + square2.clock_length(); + wave.clock_length(); + noise.clock_length(); + + frame_count = (frame_count + 1) & 3; + if ( frame_count == 0 ) + { + // 64 Hz actions + square1.clock_envelope(); + square2.clock_envelope(); + noise.clock_envelope(); + } + + if ( frame_count & 1 ) + square1.clock_sweep(); // 128 Hz action + } +} + +void Gb_Apu::end_frame( blip_time_t end_time ) +{ + if ( end_time > last_time ) + run_until( end_time ); + + assert( next_frame_time >= end_time ); + next_frame_time -= end_time; + + assert( last_time >= end_time ); + last_time -= end_time; +} + +void Gb_Apu::write_register( blip_time_t time, unsigned addr, int data ) +{ + require( (unsigned) data < 0x100 ); + + int reg = addr - start_addr; + if ( (unsigned) reg >= register_count ) + return; + + run_until( time ); + + int old_reg = regs [reg]; + regs [reg] = data; + + if ( addr < vol_reg ) + { + write_osc( reg / 5, reg, data ); + } + else if ( addr == vol_reg && data != old_reg ) // global volume + { + // return all oscs to 0 + for ( int i = 0; i < osc_count; i++ ) + { + Gb_Osc& osc = *oscs [i]; + int amp = osc.last_amp; + osc.last_amp = 0; + if ( amp && osc.enabled && osc.output ) + other_synth.offset( time, -amp, osc.output ); + } + + if ( wave.outputs [3] ) + other_synth.offset( time, 30, wave.outputs [3] ); + + update_volume(); + + if ( wave.outputs [3] ) + other_synth.offset( time, -30, wave.outputs [3] ); + + // oscs will update with new amplitude when next run + } + else if ( addr == 0xFF25 || addr == status_reg ) + { + int mask = (regs [status_reg - start_addr] & 0x80) ? ~0 : 0; + int flags = regs [0xFF25 - start_addr] & mask; + + // left/right assignments + for ( int i = 0; i < osc_count; i++ ) + { + Gb_Osc& osc = *oscs [i]; + osc.enabled &= mask; + int bits = flags >> i; + Blip_Buffer* old_output = osc.output; + osc.output_select = (bits >> 3 & 2) | (bits & 1); + osc.output = osc.outputs [osc.output_select]; + if ( osc.output != old_output ) + { + int amp = osc.last_amp; + osc.last_amp = 0; + if ( amp && old_output ) + other_synth.offset( time, -amp, old_output ); + } + } + + if ( addr == status_reg && data != old_reg ) + { + if ( !(data & 0x80) ) + { + for ( unsigned i = 0; i < sizeof powerup_regs; i++ ) + { + if ( i != status_reg - start_addr ) + write_register( time, i + start_addr, powerup_regs [i] ); + } + } + else + { + //debug_printf( "APU powered on\n" ); + } + } + } + else if ( addr >= 0xFF30 ) + { + int index = (addr & 0x0F) * 2; + wave.wave [index] = data >> 4; + wave.wave [index + 1] = data & 0x0F; + } +} + +int Gb_Apu::read_register( blip_time_t time, unsigned addr ) +{ + run_until( time ); + + int index = addr - start_addr; + require( (unsigned) index < register_count ); + int data = regs [index]; + + if ( addr == status_reg ) + { + data = (data & 0x80) | 0x70; + for ( int i = 0; i < osc_count; i++ ) + { + const Gb_Osc& osc = *oscs [i]; + if ( osc.enabled && (osc.length || !(osc.regs [4] & osc.len_enabled_mask)) ) + data |= 1 << i; + } + } + + return data; +} diff --git a/libs/gme/gme/Gb_Apu.h b/libs/gme/gme/Gb_Apu.h new file mode 100644 index 000000000..e74ebc55b --- /dev/null +++ b/libs/gme/gme/Gb_Apu.h @@ -0,0 +1,90 @@ +// Nintendo Game Boy PAPU sound chip emulator + +// Gb_Snd_Emu 0.1.5 +#ifndef GB_APU_H +#define GB_APU_H + +#include "Gb_Oscs.h" + +class Gb_Apu { +public: + + // Set overall volume of all oscillators, where 1.0 is full volume + void volume( double ); + + // Set treble equalization + void treble_eq( const blip_eq_t& ); + + // Outputs can be assigned to a single buffer for mono output, or to three + // buffers for stereo output (using Stereo_Buffer to do the mixing). + + // Assign all oscillator outputs to specified buffer(s). If buffer + // is NULL, silences all oscillators. + void output( Blip_Buffer* mono ); + void output( Blip_Buffer* center, Blip_Buffer* left, Blip_Buffer* right ); + + // Assign single oscillator output to buffer(s). Valid indicies are 0 to 3, + // which refer to Square 1, Square 2, Wave, and Noise. If buffer is NULL, + // silences oscillator. + enum { osc_count = 4 }; + void osc_output( int index, Blip_Buffer* mono ); + void osc_output( int index, Blip_Buffer* center, Blip_Buffer* left, Blip_Buffer* right ); + + // Reset oscillators and internal state + void reset(); + + // Reads and writes at addr must satisfy start_addr <= addr <= end_addr + enum { start_addr = 0xFF10 }; + enum { end_addr = 0xFF3F }; + enum { register_count = end_addr - start_addr + 1 }; + + // Write 'data' to address at specified time + void write_register( blip_time_t, unsigned addr, int data ); + + // Read from address at specified time + int read_register( blip_time_t, unsigned addr ); + + // Run all oscillators up to specified time, end current time frame, then + // start a new frame at time 0. + void end_frame( blip_time_t ); + + void set_tempo( double ); + +public: + Gb_Apu(); +private: + // noncopyable + Gb_Apu( const Gb_Apu& ); + Gb_Apu& operator = ( const Gb_Apu& ); + + Gb_Osc* oscs [osc_count]; + blip_time_t next_frame_time; + blip_time_t last_time; + blip_time_t frame_period; + double volume_unit; + int frame_count; + + Gb_Square square1; + Gb_Square square2; + Gb_Wave wave; + Gb_Noise noise; + BOOST::uint8_t regs [register_count]; + Gb_Square::Synth square_synth; // used by squares + Gb_Wave::Synth other_synth; // used by wave and noise + + void update_volume(); + void run_until( blip_time_t ); + void write_osc( int index, int reg, int data ); +}; + +inline void Gb_Apu::output( Blip_Buffer* b ) { output( b, b, b ); } + +inline void Gb_Apu::osc_output( int i, Blip_Buffer* b ) { osc_output( i, b, b, b ); } + +inline void Gb_Apu::volume( double vol ) +{ + volume_unit = 0.60 / osc_count / 15 /*steps*/ / 2 /*?*/ / 8 /*master vol range*/ * vol; + update_volume(); +} + +#endif diff --git a/libs/gme/gme/Gb_Cpu.cpp b/libs/gme/gme/Gb_Cpu.cpp new file mode 100644 index 000000000..b0128ea4c --- /dev/null +++ b/libs/gme/gme/Gb_Cpu.cpp @@ -0,0 +1,1056 @@ +// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/ + +#include "Gb_Cpu.h" + +#include + +//#include "gb_cpu_log.h" + +/* Copyright (C) 2003-2006 Shay Green. This module 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 +module 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 module; if not, write to the Free Software Foundation, +Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + +#include "gb_cpu_io.h" + +#include "blargg_source.h" + +// Common instructions: +// +// 365880 FA LD A,IND16 +// 355863 20 JR NZ +// 313655 21 LD HL,IMM +// 274580 28 JR Z +// 252878 FE CMP IMM +// 230541 7E LD A,(HL) +// 226209 2A LD A,(HL+) +// 217467 CD CALL +// 212034 C9 RET +// 208376 CB CB prefix +// +// 27486 CB 7E BIT 7,(HL) +// 15925 CB 76 BIT 6,(HL) +// 13035 CB 19 RR C +// 11557 CB 7F BIT 7,A +// 10898 CB 37 SWAP A +// 10208 CB 66 BIT 4,(HL) + +#if BLARGG_NONPORTABLE + #define PAGE_OFFSET( addr ) (addr) +#else + #define PAGE_OFFSET( addr ) ((addr) & (page_size - 1)) +#endif + +inline void Gb_Cpu::set_code_page( int i, uint8_t* p ) +{ + state->code_map [i] = p - PAGE_OFFSET( i * (blargg_long) page_size ); +} + +void Gb_Cpu::reset( void* unmapped ) +{ + check( state == &state_ ); + state = &state_; + + state_.remain = 0; + + for ( int i = 0; i < page_count + 1; i++ ) + set_code_page( i, (uint8_t*) unmapped ); + + memset( &r, 0, sizeof r ); + //interrupts_enabled = false; + + blargg_verify_byte_order(); +} + +void Gb_Cpu::map_code( gb_addr_t start, unsigned size, void* data ) +{ + // address range must begin and end on page boundaries + require( start % page_size == 0 ); + require( size % page_size == 0 ); + + unsigned first_page = start / page_size; + for ( unsigned i = size / page_size; i--; ) + set_code_page( first_page + i, (uint8_t*) data + i * page_size ); +} + +#define READ( addr ) CPU_READ( this, (addr), s.remain ) +#define WRITE( addr, data ) {CPU_WRITE( this, (addr), (data), s.remain );} +#define READ_FAST( addr, out ) CPU_READ_FAST( this, (addr), s.remain, out ) +#define READ_PROG( addr ) (s.code_map [(addr) >> page_shift] [PAGE_OFFSET( addr )]) + +unsigned const z_flag = 0x80; +unsigned const n_flag = 0x40; +unsigned const h_flag = 0x20; +unsigned const c_flag = 0x10; + +bool Gb_Cpu::run( blargg_long cycle_count ) +{ + state_.remain = blargg_ulong (cycle_count + clocks_per_instr) / clocks_per_instr; + state_t s; + this->state = &s; + memcpy( &s, &this->state_, sizeof s ); + + typedef BOOST::uint16_t uint16_t; + +#if BLARGG_BIG_ENDIAN + #define R8( n ) (r8_ [n]) +#elif BLARGG_LITTLE_ENDIAN + #define R8( n ) (r8_ [(n) ^ 1]) +#else + #error "Byte order of CPU must be known" +#endif + + union { + core_regs_t rg; // individual registers + + struct { + BOOST::uint16_t bc, de, hl, unused; // pairs + } rp; + + uint8_t r8_ [8]; // indexed registers (use R8 macro due to endian dependence) + BOOST::uint16_t r16 [4]; // indexed pairs + }; + BOOST_STATIC_ASSERT( sizeof rg == 8 && sizeof rp == 8 ); + + rg = r; + unsigned pc = r.pc; + unsigned sp = r.sp; + unsigned flags = r.flags; + +loop: + + check( (unsigned long) pc < 0x10000 ); + check( (unsigned long) sp < 0x10000 ); + check( (flags & ~0xF0) == 0 ); + + uint8_t const* instr = s.code_map [pc >> page_shift]; + unsigned op; + + // TODO: eliminate this special case + #if BLARGG_NONPORTABLE + op = instr [pc]; + pc++; + instr += pc; + #else + instr += PAGE_OFFSET( pc ); + op = *instr++; + pc++; + #endif + +#define GET_ADDR() GET_LE16( instr ) + + if ( !--s.remain ) + goto stop; + + unsigned data; + data = *instr; + + #ifdef GB_CPU_LOG_H + gb_cpu_log( "new", pc - 1, op, data, instr [1] ); + #endif + + switch ( op ) + { + +// TODO: more efficient way to handle negative branch that wraps PC around +#define BRANCH( cond )\ +{\ + pc++;\ + int offset = (BOOST::int8_t) data;\ + if ( !(cond) ) goto loop;\ + pc = uint16_t (pc + offset);\ + goto loop;\ +} + +// Most Common + + case 0x20: // JR NZ + BRANCH( !(flags & z_flag) ) + + case 0x21: // LD HL,IMM (common) + rp.hl = GET_ADDR(); + pc += 2; + goto loop; + + case 0x28: // JR Z + BRANCH( flags & z_flag ) + + { + unsigned temp; + case 0xF0: // LD A,(0xFF00+imm) + temp = data | 0xFF00; + pc++; + goto ld_a_ind_comm; + + case 0xF2: // LD A,(0xFF00+C) + temp = rg.c | 0xFF00; + goto ld_a_ind_comm; + + case 0x0A: // LD A,(BC) + temp = rp.bc; + goto ld_a_ind_comm; + + case 0x3A: // LD A,(HL-) + temp = rp.hl; + rp.hl = temp - 1; + goto ld_a_ind_comm; + + case 0x1A: // LD A,(DE) + temp = rp.de; + goto ld_a_ind_comm; + + case 0x2A: // LD A,(HL+) (common) + temp = rp.hl; + rp.hl = temp + 1; + goto ld_a_ind_comm; + + case 0xFA: // LD A,IND16 (common) + temp = GET_ADDR(); + pc += 2; + ld_a_ind_comm: + READ_FAST( temp, rg.a ); + goto loop; + } + + case 0xBE: // CMP (HL) + data = READ( rp.hl ); + goto cmp_comm; + + case 0xB8: // CMP B + case 0xB9: // CMP C + case 0xBA: // CMP D + case 0xBB: // CMP E + case 0xBC: // CMP H + case 0xBD: // CMP L + data = R8( op & 7 ); + goto cmp_comm; + + case 0xFE: // CMP IMM + pc++; + cmp_comm: + op = rg.a; + data = op - data; + sub_set_flags: + flags = ((op & 15) - (data & 15)) & h_flag; + flags |= (data >> 4) & c_flag; + flags |= n_flag; + if ( data & 0xFF ) + goto loop; + flags |= z_flag; + goto loop; + + case 0x46: // LD B,(HL) + case 0x4E: // LD C,(HL) + case 0x56: // LD D,(HL) + case 0x5E: // LD E,(HL) + case 0x66: // LD H,(HL) + case 0x6E: // LD L,(HL) + case 0x7E:{// LD A,(HL) + unsigned addr = rp.hl; + READ_FAST( addr, R8( (op >> 3) & 7 ) ); + goto loop; + } + + case 0xC4: // CNZ (next-most-common) + pc += 2; + if ( flags & z_flag ) + goto loop; + call: + pc -= 2; + case 0xCD: // CALL (most-common) + data = pc + 2; + pc = GET_ADDR(); + push: + sp = (sp - 1) & 0xFFFF; + WRITE( sp, data >> 8 ); + sp = (sp - 1) & 0xFFFF; + WRITE( sp, data & 0xFF ); + goto loop; + + case 0xC8: // RNZ (next-most-common) + if ( !(flags & z_flag) ) + goto loop; + case 0xC9: // RET (most common) + ret: + pc = READ( sp ); + pc += 0x100 * READ( sp + 1 ); + sp = (sp + 2) & 0xFFFF; + goto loop; + + case 0x00: // NOP + case 0x40: // LD B,B + case 0x49: // LD C,C + case 0x52: // LD D,D + case 0x5B: // LD E,E + case 0x64: // LD H,H + case 0x6D: // LD L,L + case 0x7F: // LD A,A + goto loop; + +// CB Instructions + + case 0xCB: + pc++; + // now data is the opcode + switch ( data ) { + + { + int temp; + case 0x46: // BIT b,(HL) + case 0x4E: + case 0x56: + case 0x5E: + case 0x66: + case 0x6E: + case 0x76: + case 0x7E: + { + unsigned addr = rp.hl; + READ_FAST( addr, temp ); + goto bit_comm; + } + + case 0x40: case 0x41: case 0x42: case 0x43: // BIT b,r + case 0x44: case 0x45: case 0x47: case 0x48: + case 0x49: case 0x4A: case 0x4B: case 0x4C: + case 0x4D: case 0x4F: case 0x50: case 0x51: + case 0x52: case 0x53: case 0x54: case 0x55: + case 0x57: case 0x58: case 0x59: case 0x5A: + case 0x5B: case 0x5C: case 0x5D: case 0x5F: + case 0x60: case 0x61: case 0x62: case 0x63: + case 0x64: case 0x65: case 0x67: case 0x68: + case 0x69: case 0x6A: case 0x6B: case 0x6C: + case 0x6D: case 0x6F: case 0x70: case 0x71: + case 0x72: case 0x73: case 0x74: case 0x75: + case 0x77: case 0x78: case 0x79: case 0x7A: + case 0x7B: case 0x7C: case 0x7D: case 0x7F: + temp = R8( data & 7 ); + bit_comm: + int bit = (~data >> 3) & 7; + flags &= ~n_flag; + flags |= h_flag | z_flag; + flags ^= (temp << bit) & z_flag; + goto loop; + } + + case 0x86: // RES b,(HL) + case 0x8E: + case 0x96: + case 0x9E: + case 0xA6: + case 0xAE: + case 0xB6: + case 0xBE: + case 0xC6: // SET b,(HL) + case 0xCE: + case 0xD6: + case 0xDE: + case 0xE6: + case 0xEE: + case 0xF6: + case 0xFE: { + int temp = READ( rp.hl ); + int bit = 1 << ((data >> 3) & 7); + temp &= ~bit; + if ( !(data & 0x40) ) + bit = 0; + WRITE( rp.hl, temp | bit ); + goto loop; + } + + case 0xC0: case 0xC1: case 0xC2: case 0xC3: // SET b,r + case 0xC4: case 0xC5: case 0xC7: case 0xC8: + case 0xC9: case 0xCA: case 0xCB: case 0xCC: + case 0xCD: case 0xCF: case 0xD0: case 0xD1: + case 0xD2: case 0xD3: case 0xD4: case 0xD5: + case 0xD7: case 0xD8: case 0xD9: case 0xDA: + case 0xDB: case 0xDC: case 0xDD: case 0xDF: + case 0xE0: case 0xE1: case 0xE2: case 0xE3: + case 0xE4: case 0xE5: case 0xE7: case 0xE8: + case 0xE9: case 0xEA: case 0xEB: case 0xEC: + case 0xED: case 0xEF: case 0xF0: case 0xF1: + case 0xF2: case 0xF3: case 0xF4: case 0xF5: + case 0xF7: case 0xF8: case 0xF9: case 0xFA: + case 0xFB: case 0xFC: case 0xFD: case 0xFF: + R8( data & 7 ) |= 1 << ((data >> 3) & 7); + goto loop; + + case 0x80: case 0x81: case 0x82: case 0x83: // RES b,r + case 0x84: case 0x85: case 0x87: case 0x88: + case 0x89: case 0x8A: case 0x8B: case 0x8C: + case 0x8D: case 0x8F: case 0x90: case 0x91: + case 0x92: case 0x93: case 0x94: case 0x95: + case 0x97: case 0x98: case 0x99: case 0x9A: + case 0x9B: case 0x9C: case 0x9D: case 0x9F: + case 0xA0: case 0xA1: case 0xA2: case 0xA3: + case 0xA4: case 0xA5: case 0xA7: case 0xA8: + case 0xA9: case 0xAA: case 0xAB: case 0xAC: + case 0xAD: case 0xAF: case 0xB0: case 0xB1: + case 0xB2: case 0xB3: case 0xB4: case 0xB5: + case 0xB7: case 0xB8: case 0xB9: case 0xBA: + case 0xBB: case 0xBC: case 0xBD: case 0xBF: + R8( data & 7 ) &= ~(1 << ((data >> 3) & 7)); + goto loop; + + { + int temp; + case 0x36: // SWAP (HL) + temp = READ( rp.hl ); + goto swap_comm; + + case 0x30: // SWAP B + case 0x31: // SWAP C + case 0x32: // SWAP D + case 0x33: // SWAP E + case 0x34: // SWAP H + case 0x35: // SWAP L + case 0x37: // SWAP A + temp = R8( data & 7 ); + swap_comm: + op = (temp >> 4) | (temp << 4); + flags = 0; + goto shift_comm; + } + +// Shift/Rotate + + case 0x06: // RLC (HL) + case 0x16: // RL (HL) + case 0x26: // SLA (HL) + op = READ( rp.hl ); + goto rl_comm; + + case 0x20: case 0x21: case 0x22: case 0x23: case 0x24: case 0x25: case 0x27: // SLA A + case 0x00: case 0x01: case 0x02: case 0x03: case 0x04: case 0x05: case 0x07: // RLC A + case 0x10: case 0x11: case 0x12: case 0x13: case 0x14: case 0x15: case 0x17: // RL A + op = R8( data & 7 ); + goto rl_comm; + + case 0x3E: // SRL (HL) + data += 0x10; // bump up to 0x4n to avoid preserving sign bit + case 0x1E: // RR (HL) + case 0x0E: // RRC (HL) + case 0x2E: // SRA (HL) + op = READ( rp.hl ); + goto rr_comm; + + case 0x38: case 0x39: case 0x3A: case 0x3B: case 0x3C: case 0x3D: case 0x3F: // SRL A + data += 0x10; // bump up to 0x4n + case 0x18: case 0x19: case 0x1A: case 0x1B: case 0x1C: case 0x1D: case 0x1F: // RR A + case 0x08: case 0x09: case 0x0A: case 0x0B: case 0x0C: case 0x0D: case 0x0F: // RRC A + case 0x28: case 0x29: case 0x2A: case 0x2B: case 0x2C: case 0x2D: case 0x2F: // SRA A + op = R8( data & 7 ); + goto rr_comm; + + } // CB op + assert( false ); // unhandled CB op + + case 0x07: // RLCA + case 0x17: // RLA + data = op; + op = rg.a; + rl_comm: + op <<= 1; + op |= ((data & flags) >> 4) & 1; // RL and carry is set + flags = (op >> 4) & c_flag; // C = bit shifted out + if ( data < 0x10 ) // RLC + op |= op >> 8; + // SLA doesn't fill lower bit + goto shift_comm; + + case 0x0F: // RRCA + case 0x1F: // RRA + data = op; + op = rg.a; + rr_comm: + op |= (data & flags) << 4; // RR and carry is set + flags = (op << 4) & c_flag; // C = bit shifted out + if ( data < 0x10 ) // RRC + op |= op << 8; + op >>= 1; + if ( data & 0x20 ) // SRA propagates sign bit + op |= (op << 1) & 0x80; + shift_comm: + data &= 7; + if ( !(op & 0xFF) ) + flags |= z_flag; + if ( data == 6 ) + goto write_hl_op_ff; + R8( data ) = op; + goto loop; + +// Load + + case 0x70: // LD (HL),B + case 0x71: // LD (HL),C + case 0x72: // LD (HL),D + case 0x73: // LD (HL),E + case 0x74: // LD (HL),H + case 0x75: // LD (HL),L + case 0x77: // LD (HL),A + op = R8( op & 7 ); + write_hl_op_ff: + WRITE( rp.hl, op & 0xFF ); + goto loop; + + case 0x41: case 0x42: case 0x43: case 0x44: case 0x45: case 0x47: // LD r,r + case 0x48: case 0x4A: case 0x4B: case 0x4C: case 0x4D: case 0x4F: + case 0x50: case 0x51: case 0x53: case 0x54: case 0x55: case 0x57: + case 0x58: case 0x59: case 0x5A: case 0x5C: case 0x5D: case 0x5F: + case 0x60: case 0x61: case 0x62: case 0x63: case 0x65: case 0x67: + case 0x68: case 0x69: case 0x6A: case 0x6B: case 0x6C: case 0x6F: + case 0x78: case 0x79: case 0x7A: case 0x7B: case 0x7C: case 0x7D: + R8( (op >> 3) & 7 ) = R8( op & 7 ); + goto loop; + + case 0x08: // LD IND16,SP + data = GET_ADDR(); + pc += 2; + WRITE( data, sp&0xFF ); + data++; + WRITE( data, sp >> 8 ); + goto loop; + + case 0xF9: // LD SP,HL + sp = rp.hl; + goto loop; + + case 0x31: // LD SP,IMM + sp = GET_ADDR(); + pc += 2; + goto loop; + + case 0x01: // LD BC,IMM + case 0x11: // LD DE,IMM + r16 [op >> 4] = GET_ADDR(); + pc += 2; + goto loop; + + { + unsigned temp; + case 0xE0: // LD (0xFF00+imm),A + temp = data | 0xFF00; + pc++; + goto write_data_rg_a; + + case 0xE2: // LD (0xFF00+C),A + temp = rg.c | 0xFF00; + goto write_data_rg_a; + + case 0x32: // LD (HL-),A + temp = rp.hl; + rp.hl = temp - 1; + goto write_data_rg_a; + + case 0x02: // LD (BC),A + temp = rp.bc; + goto write_data_rg_a; + + case 0x12: // LD (DE),A + temp = rp.de; + goto write_data_rg_a; + + case 0x22: // LD (HL+),A + temp = rp.hl; + rp.hl = temp + 1; + goto write_data_rg_a; + + case 0xEA: // LD IND16,A (common) + temp = GET_ADDR(); + pc += 2; + write_data_rg_a: + WRITE( temp, rg.a ); + goto loop; + } + + case 0x06: // LD B,IMM + rg.b = data; + pc++; + goto loop; + + case 0x0E: // LD C,IMM + rg.c = data; + pc++; + goto loop; + + case 0x16: // LD D,IMM + rg.d = data; + pc++; + goto loop; + + case 0x1E: // LD E,IMM + rg.e = data; + pc++; + goto loop; + + case 0x26: // LD H,IMM + rg.h = data; + pc++; + goto loop; + + case 0x2E: // LD L,IMM + rg.l = data; + pc++; + goto loop; + + case 0x36: // LD (HL),IMM + WRITE( rp.hl, data ); + pc++; + goto loop; + + case 0x3E: // LD A,IMM + rg.a = data; + pc++; + goto loop; + +// Increment/Decrement + + case 0x03: // INC BC + case 0x13: // INC DE + case 0x23: // INC HL + r16 [op >> 4]++; + goto loop; + + case 0x33: // INC SP + sp = (sp + 1) & 0xFFFF; + goto loop; + + case 0x0B: // DEC BC + case 0x1B: // DEC DE + case 0x2B: // DEC HL + r16 [op >> 4]--; + goto loop; + + case 0x3B: // DEC SP + sp = (sp - 1) & 0xFFFF; + goto loop; + + case 0x34: // INC (HL) + op = rp.hl; + data = READ( op ); + data++; + WRITE( op, data & 0xFF ); + goto inc_comm; + + case 0x04: // INC B + case 0x0C: // INC C (common) + case 0x14: // INC D + case 0x1C: // INC E + case 0x24: // INC H + case 0x2C: // INC L + case 0x3C: // INC A + op = (op >> 3) & 7; + R8( op ) = data = R8( op ) + 1; + inc_comm: + flags = (flags & c_flag) | (((data & 15) - 1) & h_flag) | ((data >> 1) & z_flag); + goto loop; + + case 0x35: // DEC (HL) + op = rp.hl; + data = READ( op ); + data--; + WRITE( op, data & 0xFF ); + goto dec_comm; + + case 0x05: // DEC B + case 0x0D: // DEC C + case 0x15: // DEC D + case 0x1D: // DEC E + case 0x25: // DEC H + case 0x2D: // DEC L + case 0x3D: // DEC A + op = (op >> 3) & 7; + data = R8( op ) - 1; + R8( op ) = data; + dec_comm: + flags = (flags & c_flag) | n_flag | (((data & 15) + 0x31) & h_flag); + if ( data & 0xFF ) + goto loop; + flags |= z_flag; + goto loop; + +// Add 16-bit + + { + blargg_ulong temp; // need more than 16 bits for carry + unsigned prev; + + case 0xF8: // LD HL,SP+imm + temp = BOOST::int8_t (data); // sign-extend to 16 bits + pc++; + flags = 0; + temp += sp; + prev = sp; + goto add_16_hl; + + case 0xE8: // ADD SP,IMM + temp = BOOST::int8_t (data); // sign-extend to 16 bits + pc++; + flags = 0; + temp += sp; + prev = sp; + sp = temp & 0xFFFF; + goto add_16_comm; + + case 0x39: // ADD HL,SP + temp = sp; + goto add_hl_comm; + + case 0x09: // ADD HL,BC + case 0x19: // ADD HL,DE + case 0x29: // ADD HL,HL + temp = r16 [op >> 4]; + add_hl_comm: + prev = rp.hl; + temp += prev; + flags &= z_flag; + add_16_hl: + rp.hl = temp; + add_16_comm: + flags |= (temp >> 12) & c_flag; + flags |= (((temp & 0x0FFF) - (prev & 0x0FFF)) >> 7) & h_flag; + goto loop; + } + + case 0x86: // ADD (HL) + data = READ( rp.hl ); + goto add_comm; + + case 0x80: // ADD B + case 0x81: // ADD C + case 0x82: // ADD D + case 0x83: // ADD E + case 0x84: // ADD H + case 0x85: // ADD L + case 0x87: // ADD A + data = R8( op & 7 ); + goto add_comm; + + case 0xC6: // ADD IMM + pc++; + add_comm: + flags = rg.a; + data += flags; + flags = ((data & 15) - (flags & 15)) & h_flag; + flags |= (data >> 4) & c_flag; + rg.a = data; + if ( data & 0xFF ) + goto loop; + flags |= z_flag; + goto loop; + +// Add/Subtract + + case 0x8E: // ADC (HL) + data = READ( rp.hl ); + goto adc_comm; + + case 0x88: // ADC B + case 0x89: // ADC C + case 0x8A: // ADC D + case 0x8B: // ADC E + case 0x8C: // ADC H + case 0x8D: // ADC L + case 0x8F: // ADC A + data = R8( op & 7 ); + goto adc_comm; + + case 0xCE: // ADC IMM + pc++; + adc_comm: + data += (flags >> 4) & 1; + data &= 0xFF; // to do: does carry get set when sum + carry = 0x100? + goto add_comm; + + case 0x96: // SUB (HL) + data = READ( rp.hl ); + goto sub_comm; + + case 0x90: // SUB B + case 0x91: // SUB C + case 0x92: // SUB D + case 0x93: // SUB E + case 0x94: // SUB H + case 0x95: // SUB L + case 0x97: // SUB A + data = R8( op & 7 ); + goto sub_comm; + + case 0xD6: // SUB IMM + pc++; + sub_comm: + op = rg.a; + data = op - data; + rg.a = data; + goto sub_set_flags; + + case 0x9E: // SBC (HL) + data = READ( rp.hl ); + goto sbc_comm; + + case 0x98: // SBC B + case 0x99: // SBC C + case 0x9A: // SBC D + case 0x9B: // SBC E + case 0x9C: // SBC H + case 0x9D: // SBC L + case 0x9F: // SBC A + data = R8( op & 7 ); + goto sbc_comm; + + case 0xDE: // SBC IMM + pc++; + sbc_comm: + data += (flags >> 4) & 1; + data &= 0xFF; // to do: does carry get set when sum + carry = 0x100? + goto sub_comm; + +// Logical + + case 0xA0: // AND B + case 0xA1: // AND C + case 0xA2: // AND D + case 0xA3: // AND E + case 0xA4: // AND H + case 0xA5: // AND L + data = R8( op & 7 ); + goto and_comm; + + case 0xA6: // AND (HL) + data = READ( rp.hl ); + pc--; + case 0xE6: // AND IMM + pc++; + and_comm: + rg.a &= data; + case 0xA7: // AND A + flags = h_flag | (((rg.a - 1) >> 1) & z_flag); + goto loop; + + case 0xB0: // OR B + case 0xB1: // OR C + case 0xB2: // OR D + case 0xB3: // OR E + case 0xB4: // OR H + case 0xB5: // OR L + data = R8( op & 7 ); + goto or_comm; + + case 0xB6: // OR (HL) + data = READ( rp.hl ); + pc--; + case 0xF6: // OR IMM + pc++; + or_comm: + rg.a |= data; + case 0xB7: // OR A + flags = ((rg.a - 1) >> 1) & z_flag; + goto loop; + + case 0xA8: // XOR B + case 0xA9: // XOR C + case 0xAA: // XOR D + case 0xAB: // XOR E + case 0xAC: // XOR H + case 0xAD: // XOR L + data = R8( op & 7 ); + goto xor_comm; + + case 0xAE: // XOR (HL) + data = READ( rp.hl ); + pc--; + case 0xEE: // XOR IMM + pc++; + xor_comm: + data ^= rg.a; + rg.a = data; + data--; + flags = (data >> 1) & z_flag; + goto loop; + + case 0xAF: // XOR A + rg.a = 0; + flags = z_flag; + goto loop; + +// Stack + + case 0xF1: // POP FA + case 0xC1: // POP BC + case 0xD1: // POP DE + case 0xE1: // POP HL (common) + data = READ( sp ); + r16 [(op >> 4) & 3] = data + 0x100 * READ( sp + 1 ); + sp = (sp + 2) & 0xFFFF; + if ( op != 0xF1 ) + goto loop; + flags = rg.flags & 0xF0; + goto loop; + + case 0xC5: // PUSH BC + data = rp.bc; + goto push; + + case 0xD5: // PUSH DE + data = rp.de; + goto push; + + case 0xE5: // PUSH HL + data = rp.hl; + goto push; + + case 0xF5: // PUSH FA + data = (flags << 8) | rg.a; + goto push; + +// Flow control + + case 0xFF: + if ( pc == idle_addr + 1 ) + goto stop; + case 0xC7: case 0xCF: case 0xD7: case 0xDF: // RST + case 0xE7: case 0xEF: case 0xF7: + data = pc; + pc = (op & 0x38) + rst_base; + goto push; + + case 0xCC: // CZ + pc += 2; + if ( flags & z_flag ) + goto call; + goto loop; + + case 0xD4: // CNC + pc += 2; + if ( !(flags & c_flag) ) + goto call; + goto loop; + + case 0xDC: // CC + pc += 2; + if ( flags & c_flag ) + goto call; + goto loop; + + case 0xD9: // RETI + //interrupts_enabled = 1; + goto ret; + + case 0xC0: // RZ + if ( !(flags & z_flag) ) + goto ret; + goto loop; + + case 0xD0: // RNC + if ( !(flags & c_flag) ) + goto ret; + goto loop; + + case 0xD8: // RC + if ( flags & c_flag ) + goto ret; + goto loop; + + case 0x18: // JR + BRANCH( true ) + + case 0x30: // JR NC + BRANCH( !(flags & c_flag) ) + + case 0x38: // JR C + BRANCH( flags & c_flag ) + + case 0xE9: // JP_HL + pc = rp.hl; + goto loop; + + case 0xC3: // JP (next-most-common) + pc = GET_ADDR(); + goto loop; + + case 0xC2: // JP NZ + pc += 2; + if ( !(flags & z_flag) ) + goto jp_taken; + goto loop; + + case 0xCA: // JP Z (most common) + pc += 2; + if ( !(flags & z_flag) ) + goto loop; + jp_taken: + pc -= 2; + pc = GET_ADDR(); + goto loop; + + case 0xD2: // JP NC + pc += 2; + if ( !(flags & c_flag) ) + goto jp_taken; + goto loop; + + case 0xDA: // JP C + pc += 2; + if ( flags & c_flag ) + goto jp_taken; + goto loop; + +// Flags + + case 0x2F: // CPL + rg.a = ~rg.a; + flags |= n_flag | h_flag; + goto loop; + + case 0x3F: // CCF + flags = (flags ^ c_flag) & ~(n_flag | h_flag); + goto loop; + + case 0x37: // SCF + flags = (flags | c_flag) & ~(n_flag | h_flag); + goto loop; + + case 0xF3: // DI + //interrupts_enabled = 0; + goto loop; + + case 0xFB: // EI + //interrupts_enabled = 1; + goto loop; + +// Special + + case 0xDD: case 0xD3: case 0xDB: case 0xE3: case 0xE4: // ? + case 0xEB: case 0xEC: case 0xF4: case 0xFD: case 0xFC: + case 0x10: // STOP + case 0x27: // DAA (I'll have to implement this eventually...) + case 0xBF: + case 0xED: // Z80 prefix + case 0x76: // HALT + s.remain++; + goto stop; + } + + // If this fails then the case above is missing an opcode + assert( false ); + +stop: + pc--; + + // copy state back + STATIC_CAST(core_regs_t&,r) = rg; + r.pc = pc; + r.sp = sp; + r.flags = flags; + + this->state = &state_; + memcpy( &this->state_, &s, sizeof this->state_ ); + + return s.remain > 0; +} diff --git a/libs/gme/gme/Gb_Cpu.h b/libs/gme/gme/Gb_Cpu.h new file mode 100644 index 000000000..0994cec29 --- /dev/null +++ b/libs/gme/gme/Gb_Cpu.h @@ -0,0 +1,93 @@ +// Nintendo Game Boy CPU emulator +// Treats every instruction as taking 4 cycles + +// Game_Music_Emu 0.6.0 +#ifndef GB_CPU_H +#define GB_CPU_H + +#include "blargg_common.h" +#include "blargg_endian.h" + +typedef unsigned gb_addr_t; // 16-bit CPU address + +class Gb_Cpu { + enum { clocks_per_instr = 4 }; +public: + typedef BOOST::uint8_t uint8_t; + + // Clear registers and map all pages to unmapped + void reset( void* unmapped = 0 ); + + // Map code memory (memory accessed via the program counter). Start and size + // must be multiple of page_size. + enum { page_size = 0x2000 }; + void map_code( gb_addr_t start, unsigned size, void* code ); + + uint8_t* get_code( gb_addr_t ); + + // Push a byte on the stack + void push_byte( int ); + + // Game Boy Z80 registers. *Not* kept updated during a call to run(). + struct core_regs_t { + #if BLARGG_BIG_ENDIAN + uint8_t b, c, d, e, h, l, flags, a; + #else + uint8_t c, b, e, d, l, h, a, flags; + #endif + }; + + struct registers_t : core_regs_t { + long pc; // more than 16 bits to allow overflow detection + BOOST::uint16_t sp; + }; + registers_t r; + + // Interrupt enable flag set by EI and cleared by DI + //bool interrupts_enabled; // unused + + // Base address for RST vectors (normally 0) + gb_addr_t rst_base; + + // If CPU executes opcode 0xFF at this address, it treats as illegal instruction + enum { idle_addr = 0xF00D }; + + // Run CPU for at least 'count' cycles and return false, or return true if + // illegal instruction is encountered. + bool run( blargg_long count ); + + // Number of clock cycles remaining for most recent run() call + blargg_long remain() const { return state->remain * clocks_per_instr; } + + // Can read this many bytes past end of a page + enum { cpu_padding = 8 }; + +public: + Gb_Cpu() : rst_base( 0 ) { state = &state_; } + enum { page_shift = 13 }; + enum { page_count = 0x10000 >> page_shift }; +private: + // noncopyable + Gb_Cpu( const Gb_Cpu& ); + Gb_Cpu& operator = ( const Gb_Cpu& ); + + struct state_t { + uint8_t* code_map [page_count + 1]; + blargg_long remain; + }; + state_t* state; // points to state_ or a local copy within run() + state_t state_; + + void set_code_page( int, uint8_t* ); +}; + +inline BOOST::uint8_t* Gb_Cpu::get_code( gb_addr_t addr ) +{ + return state->code_map [addr >> page_shift] + addr + #if !BLARGG_NONPORTABLE + % (unsigned) page_size + #endif + ; +} + +#endif diff --git a/libs/gme/gme/Gb_Oscs.cpp b/libs/gme/gme/Gb_Oscs.cpp new file mode 100644 index 000000000..735653fa9 --- /dev/null +++ b/libs/gme/gme/Gb_Oscs.cpp @@ -0,0 +1,336 @@ +// Gb_Snd_Emu 0.1.5. http://www.slack.net/~ant/ + +#include "Gb_Apu.h" + +#include + +/* Copyright (C) 2003-2006 Shay Green. This module 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 +module 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 module; if not, write to the Free Software Foundation, +Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + +#include "blargg_source.h" + +// Gb_Osc + +void Gb_Osc::reset() +{ + delay = 0; + last_amp = 0; + length = 0; + output_select = 3; + output = outputs [output_select]; +} + +void Gb_Osc::clock_length() +{ + if ( (regs [4] & len_enabled_mask) && length ) + length--; +} + +// Gb_Env + +void Gb_Env::clock_envelope() +{ + if ( env_delay && !--env_delay ) + { + env_delay = regs [2] & 7; + int v = volume - 1 + (regs [2] >> 2 & 2); + if ( (unsigned) v < 15 ) + volume = v; + } +} + +bool Gb_Env::write_register( int reg, int data ) +{ + switch ( reg ) + { + case 1: + length = 64 - (regs [1] & 0x3F); + break; + + case 2: + if ( !(data >> 4) ) + enabled = false; + break; + + case 4: + if ( data & trigger ) + { + env_delay = regs [2] & 7; + volume = regs [2] >> 4; + enabled = true; + if ( length == 0 ) + length = 64; + return true; + } + } + return false; +} + +// Gb_Square + +void Gb_Square::reset() +{ + phase = 0; + sweep_freq = 0; + sweep_delay = 0; + Gb_Env::reset(); +} + +void Gb_Square::clock_sweep() +{ + int sweep_period = (regs [0] & period_mask) >> 4; + if ( sweep_period && sweep_delay && !--sweep_delay ) + { + sweep_delay = sweep_period; + regs [3] = sweep_freq & 0xFF; + regs [4] = (regs [4] & ~0x07) | (sweep_freq >> 8 & 0x07); + + int offset = sweep_freq >> (regs [0] & shift_mask); + if ( regs [0] & 0x08 ) + offset = -offset; + sweep_freq += offset; + + if ( sweep_freq < 0 ) + { + sweep_freq = 0; + } + else if ( sweep_freq >= 2048 ) + { + sweep_delay = 0; // don't modify channel frequency any further + sweep_freq = 2048; // silence sound immediately + } + } +} + +void Gb_Square::run( blip_time_t time, blip_time_t end_time, int playing ) +{ + if ( sweep_freq == 2048 ) + playing = false; + + static unsigned char const table [4] = { 1, 2, 4, 6 }; + int const duty = table [regs [1] >> 6]; + int amp = volume & playing; + if ( phase >= duty ) + amp = -amp; + + int frequency = this->frequency(); + if ( unsigned (frequency - 1) > 2040 ) // frequency < 1 || frequency > 2041 + { + // really high frequency results in DC at half volume + amp = volume >> 1; + playing = false; + } + + { + int delta = amp - last_amp; + if ( delta ) + { + last_amp = amp; + synth->offset( time, delta, output ); + } + } + + time += delay; + if ( !playing ) + time = end_time; + + if ( time < end_time ) + { + int const period = (2048 - frequency) * 4; + Blip_Buffer* const output = this->output; + int phase = this->phase; + int delta = amp * 2; + do + { + phase = (phase + 1) & 7; + if ( phase == 0 || phase == duty ) + { + delta = -delta; + synth->offset_inline( time, delta, output ); + } + time += period; + } + while ( time < end_time ); + + this->phase = phase; + last_amp = delta >> 1; + } + delay = time - end_time; +} + +// Gb_Noise + +void Gb_Noise::run( blip_time_t time, blip_time_t end_time, int playing ) +{ + int amp = volume & playing; + int tap = 13 - (regs [3] & 8); + if ( bits >> tap & 2 ) + amp = -amp; + + { + int delta = amp - last_amp; + if ( delta ) + { + last_amp = amp; + synth->offset( time, delta, output ); + } + } + + time += delay; + if ( !playing ) + time = end_time; + + if ( time < end_time ) + { + static unsigned char const table [8] = { 8, 16, 32, 48, 64, 80, 96, 112 }; + int period = table [regs [3] & 7] << (regs [3] >> 4); + + // keep parallel resampled time to eliminate time conversion in the loop + Blip_Buffer* const output = this->output; + const blip_resampled_time_t resampled_period = + output->resampled_duration( period ); + blip_resampled_time_t resampled_time = output->resampled_time( time ); + unsigned bits = this->bits; + int delta = amp * 2; + + do + { + unsigned changed = (bits >> tap) + 1; + time += period; + bits <<= 1; + if ( changed & 2 ) + { + delta = -delta; + bits |= 1; + synth->offset_resampled( resampled_time, delta, output ); + } + resampled_time += resampled_period; + } + while ( time < end_time ); + + this->bits = bits; + last_amp = delta >> 1; + } + delay = time - end_time; +} + +// Gb_Wave + +inline void Gb_Wave::write_register( int reg, int data ) +{ + switch ( reg ) + { + case 0: + if ( !(data & 0x80) ) + enabled = false; + break; + + case 1: + length = 256 - regs [1]; + break; + + case 2: + volume = data >> 5 & 3; + break; + + case 4: + if ( data & trigger & regs [0] ) + { + wave_pos = 0; + enabled = true; + if ( length == 0 ) + length = 256; + } + } +} + +void Gb_Wave::run( blip_time_t time, blip_time_t end_time, int playing ) +{ + int volume_shift = (volume - 1) & 7; // volume = 0 causes shift = 7 + int frequency; + { + int amp = (wave [wave_pos] >> volume_shift & playing) * 2; + + frequency = this->frequency(); + if ( unsigned (frequency - 1) > 2044 ) // frequency < 1 || frequency > 2045 + { + amp = 30 >> volume_shift & playing; + playing = false; + } + + int delta = amp - last_amp; + if ( delta ) + { + last_amp = amp; + synth->offset( time, delta, output ); + } + } + + time += delay; + if ( !playing ) + time = end_time; + + if ( time < end_time ) + { + Blip_Buffer* const output = this->output; + int const period = (2048 - frequency) * 2; + int wave_pos = (this->wave_pos + 1) & (wave_size - 1); + + do + { + int amp = (wave [wave_pos] >> volume_shift) * 2; + wave_pos = (wave_pos + 1) & (wave_size - 1); + int delta = amp - last_amp; + if ( delta ) + { + last_amp = amp; + synth->offset_inline( time, delta, output ); + } + time += period; + } + while ( time < end_time ); + + this->wave_pos = (wave_pos - 1) & (wave_size - 1); + } + delay = time - end_time; +} + +// Gb_Apu::write_osc + +void Gb_Apu::write_osc( int index, int reg, int data ) +{ + reg -= index * 5; + Gb_Square* sq = &square2; + switch ( index ) + { + case 0: + sq = &square1; + case 1: + if ( sq->write_register( reg, data ) && index == 0 ) + { + square1.sweep_freq = square1.frequency(); + if ( (regs [0] & sq->period_mask) && (regs [0] & sq->shift_mask) ) + { + square1.sweep_delay = 1; // cause sweep to recalculate now + square1.clock_sweep(); + } + } + break; + + case 2: + wave.write_register( reg, data ); + break; + + case 3: + if ( noise.write_register( reg, data ) ) + noise.bits = 0x7FFF; + } +} diff --git a/libs/gme/gme/Gb_Oscs.h b/libs/gme/gme/Gb_Oscs.h new file mode 100644 index 000000000..d7f88ea14 --- /dev/null +++ b/libs/gme/gme/Gb_Oscs.h @@ -0,0 +1,83 @@ +// Private oscillators used by Gb_Apu + +// Gb_Snd_Emu 0.1.5 +#ifndef GB_OSCS_H +#define GB_OSCS_H + +#include "blargg_common.h" +#include "Blip_Buffer.h" + +struct Gb_Osc +{ + enum { trigger = 0x80 }; + enum { len_enabled_mask = 0x40 }; + + Blip_Buffer* outputs [4]; // NULL, right, left, center + Blip_Buffer* output; + int output_select; + BOOST::uint8_t* regs; // osc's 5 registers + + int delay; + int last_amp; + int volume; + int length; + int enabled; + + void reset(); + void clock_length(); + int frequency() const { return (regs [4] & 7) * 0x100 + regs [3]; } +}; + +struct Gb_Env : Gb_Osc +{ + int env_delay; + + void reset(); + void clock_envelope(); + bool write_register( int, int ); +}; + +struct Gb_Square : Gb_Env +{ + enum { period_mask = 0x70 }; + enum { shift_mask = 0x07 }; + + typedef Blip_Synth Synth; + Synth const* synth; + int sweep_delay; + int sweep_freq; + int phase; + + void reset(); + void clock_sweep(); + void run( blip_time_t, blip_time_t, int playing ); +}; + +struct Gb_Noise : Gb_Env +{ + typedef Blip_Synth Synth; + Synth const* synth; + unsigned bits; + + void run( blip_time_t, blip_time_t, int playing ); +}; + +struct Gb_Wave : Gb_Osc +{ + typedef Blip_Synth Synth; + Synth const* synth; + int wave_pos; + enum { wave_size = 32 }; + BOOST::uint8_t wave [wave_size]; + + void write_register( int, int ); + void run( blip_time_t, blip_time_t, int playing ); +}; + +inline void Gb_Env::reset() +{ + env_delay = 0; + Gb_Osc::reset(); +} + +#endif diff --git a/libs/gme/gme/Gbs_Emu.cpp b/libs/gme/gme/Gbs_Emu.cpp new file mode 100644 index 000000000..05a0b9935 --- /dev/null +++ b/libs/gme/gme/Gbs_Emu.cpp @@ -0,0 +1,290 @@ +// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/ + +#include "Gbs_Emu.h" + +#include "blargg_endian.h" +#include + +/* Copyright (C) 2003-2006 Shay Green. This module 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 +module 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 module; if not, write to the Free Software Foundation, +Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + +#include "blargg_source.h" + +Gbs_Emu::equalizer_t const Gbs_Emu::handheld_eq = + Music_Emu::make_equalizer( -47.0, 2000 ); +Gbs_Emu::equalizer_t const Gbs_Emu::headphones_eq = + Music_Emu::make_equalizer( 0.0, 300 ); + +Gbs_Emu::Gbs_Emu() +{ + set_type( gme_gbs_type ); + + static const char* const names [Gb_Apu::osc_count] = { + "Square 1", "Square 2", "Wave", "Noise" + }; + set_voice_names( names ); + + static int const types [Gb_Apu::osc_count] = { + wave_type | 1, wave_type | 2, wave_type | 0, mixed_type | 0 + }; + set_voice_types( types ); + + set_silence_lookahead( 6 ); + set_max_initial_silence( 21 ); + set_gain( 1.2 ); + + set_equalizer( make_equalizer( -1.0, 120 ) ); +} + +Gbs_Emu::~Gbs_Emu() { } + +void Gbs_Emu::unload() +{ + rom.clear(); + Music_Emu::unload(); +} + +// Track info + +static void copy_gbs_fields( Gbs_Emu::header_t const& h, track_info_t* out ) +{ + GME_COPY_FIELD( h, out, game ); + GME_COPY_FIELD( h, out, author ); + GME_COPY_FIELD( h, out, copyright ); +} + +blargg_err_t Gbs_Emu::track_info_( track_info_t* out, int ) const +{ + copy_gbs_fields( header_, out ); + return 0; +} + +static blargg_err_t check_gbs_header( void const* header ) +{ + if ( memcmp( header, "GBS", 3 ) ) + return gme_wrong_file_type; + return 0; +} + +struct Gbs_File : Gme_Info_ +{ + Gbs_Emu::header_t h; + + Gbs_File() { set_type( gme_gbs_type ); } + + blargg_err_t load_( Data_Reader& in ) + { + blargg_err_t err = in.read( &h, Gbs_Emu::header_size ); + if ( err ) + return (err == in.eof_error ? gme_wrong_file_type : err); + + set_track_count( h.track_count ); + return check_gbs_header( &h ); + } + + blargg_err_t track_info_( track_info_t* out, int ) const + { + copy_gbs_fields( h, out ); + return 0; + } +}; + +static Music_Emu* new_gbs_emu () { return BLARGG_NEW Gbs_Emu ; } +static Music_Emu* new_gbs_file() { return BLARGG_NEW Gbs_File; } + +static gme_type_t_ const gme_gbs_type_ = { "Game Boy", 0, &new_gbs_emu, &new_gbs_file, "GBS", 1 }; +gme_type_t const gme_gbs_type = &gme_gbs_type_; + +// Setup + +blargg_err_t Gbs_Emu::load_( Data_Reader& in ) +{ + assert( offsetof (header_t,copyright [32]) == header_size ); + RETURN_ERR( rom.load( in, header_size, &header_, 0 ) ); + + set_track_count( header_.track_count ); + RETURN_ERR( check_gbs_header( &header_ ) ); + + if ( header_.vers != 1 ) + set_warning( "Unknown file version" ); + + if ( header_.timer_mode & 0x78 ) + set_warning( "Invalid timer mode" ); + + unsigned load_addr = get_le16( header_.load_addr ); + if ( (header_.load_addr [1] | header_.init_addr [1] | header_.play_addr [1]) > 0x7F || + load_addr < 0x400 ) + set_warning( "Invalid load/init/play address" ); + + set_voice_count( Gb_Apu::osc_count ); + + apu.volume( gain() ); + + return setup_buffer( 4194304 ); +} + +void Gbs_Emu::update_eq( blip_eq_t const& eq ) +{ + apu.treble_eq( eq ); +} + +void Gbs_Emu::set_voice( int i, Blip_Buffer* c, Blip_Buffer* l, Blip_Buffer* r ) +{ + apu.osc_output( i, c, l, r ); +} + +// Emulation + +// see gb_cpu_io.h for read/write functions + +void Gbs_Emu::set_bank( int n ) +{ + blargg_long addr = rom.mask_addr( n * (blargg_long) bank_size ); + if ( addr == 0 && rom.size() > bank_size ) + { + // TODO: what is the correct behavior? Current Game & Watch Gallery + // rip requires that this have no effect or set to bank 1. + //debug_printf( "Selected ROM bank 0\n" ); + return; + //n = 1; + } + cpu::map_code( bank_size, bank_size, rom.at_addr( addr ) ); +} + +void Gbs_Emu::update_timer() +{ + if ( header_.timer_mode & 0x04 ) + { + static byte const rates [4] = { 10, 4, 6, 8 }; + int shift = rates [ram [hi_page + 7] & 3] - (header_.timer_mode >> 7); + play_period = (256L - ram [hi_page + 6]) << shift; + } + else + { + play_period = 70224; // 59.73 Hz + } + if ( tempo() != 1.0 ) + play_period = blip_time_t (play_period / tempo()); +} + +static BOOST::uint8_t const sound_data [Gb_Apu::register_count] = { + 0x80, 0xBF, 0x00, 0x00, 0xBF, // square 1 + 0x00, 0x3F, 0x00, 0x00, 0xBF, // square 2 + 0x7F, 0xFF, 0x9F, 0x00, 0xBF, // wave + 0x00, 0xFF, 0x00, 0x00, 0xBF, // noise + 0x77, 0xF3, 0xF1, // vin/volume, status, power mode + 0, 0, 0, 0, 0, 0, 0, 0, 0, // unused + 0xAC, 0xDD, 0xDA, 0x48, 0x36, 0x02, 0xCF, 0x16, // waveform data + 0x2C, 0x04, 0xE5, 0x2C, 0xAC, 0xDD, 0xDA, 0x48 +}; + +void Gbs_Emu::cpu_jsr( gb_addr_t addr ) +{ + check( cpu::r.sp == get_le16( header_.stack_ptr ) ); + cpu::r.pc = addr; + cpu_write( --cpu::r.sp, idle_addr >> 8 ); + cpu_write( --cpu::r.sp, idle_addr&0xFF ); +} + +void Gbs_Emu::set_tempo_( double t ) +{ + apu.set_tempo( t ); + update_timer(); +} + +blargg_err_t Gbs_Emu::start_track_( int track ) +{ + RETURN_ERR( Classic_Emu::start_track_( track ) ); + + memset( ram, 0, 0x4000 ); + memset( ram + 0x4000, 0xFF, 0x1F80 ); + memset( ram + 0x5F80, 0, sizeof ram - 0x5F80 ); + ram [hi_page] = 0; // joypad reads back as 0 + + apu.reset(); + for ( int i = 0; i < (int) sizeof sound_data; i++ ) + apu.write_register( 0, i + apu.start_addr, sound_data [i] ); + + unsigned load_addr = get_le16( header_.load_addr ); + rom.set_addr( load_addr ); + cpu::rst_base = load_addr; + + cpu::reset( rom.unmapped() ); + + cpu::map_code( ram_addr, 0x10000 - ram_addr, ram ); + cpu::map_code( 0, bank_size, rom.at_addr( 0 ) ); + set_bank( rom.size() > bank_size ); + + ram [hi_page + 6] = header_.timer_modulo; + ram [hi_page + 7] = header_.timer_mode; + update_timer(); + next_play = play_period; + + cpu::r.a = track; + cpu::r.pc = idle_addr; + cpu::r.sp = get_le16( header_.stack_ptr ); + cpu_time = 0; + cpu_jsr( get_le16( header_.init_addr ) ); + + return 0; +} + +blargg_err_t Gbs_Emu::run_clocks( blip_time_t& duration, int ) +{ + cpu_time = 0; + while ( cpu_time < duration ) + { + long count = duration - cpu_time; + cpu_time = duration; + bool result = cpu::run( count ); + cpu_time -= cpu::remain(); + + if ( result ) + { + if ( cpu::r.pc == idle_addr ) + { + if ( next_play > duration ) + { + cpu_time = duration; + break; + } + + if ( cpu_time < next_play ) + cpu_time = next_play; + next_play += play_period; + cpu_jsr( get_le16( header_.play_addr ) ); + GME_FRAME_HOOK( this ); + // TODO: handle timer rates different than 60 Hz + } + else if ( cpu::r.pc > 0xFFFF ) + { + debug_printf( "PC wrapped around\n" ); + cpu::r.pc &= 0xFFFF; + } + else + { + set_warning( "Emulation error (illegal/unsupported instruction)" ); + debug_printf( "Bad opcode $%.2x at $%.4x\n", + (int) *cpu::get_code( cpu::r.pc ), (int) cpu::r.pc ); + cpu::r.pc = (cpu::r.pc + 1) & 0xFFFF; + cpu_time += 6; + } + } + } + + duration = cpu_time; + next_play -= cpu_time; + if ( next_play < 0 ) // could go negative if routine is taking too long to return + next_play = 0; + apu.end_frame( cpu_time ); + + return 0; +} diff --git a/libs/gme/gme/Gbs_Emu.h b/libs/gme/gme/Gbs_Emu.h new file mode 100644 index 000000000..b233a2b4f --- /dev/null +++ b/libs/gme/gme/Gbs_Emu.h @@ -0,0 +1,88 @@ +// Nintendo Game Boy GBS music file emulator + +// Game_Music_Emu 0.6.0 +#ifndef GBS_EMU_H +#define GBS_EMU_H + +#include "Classic_Emu.h" +#include "Gb_Apu.h" +#include "Gb_Cpu.h" + +class Gbs_Emu : private Gb_Cpu, public Classic_Emu { + typedef Gb_Cpu cpu; +public: + // Equalizer profiles for Game Boy Color speaker and headphones + static equalizer_t const handheld_eq; + static equalizer_t const headphones_eq; + + // GBS file header + enum { header_size = 112 }; + struct header_t + { + char tag [3]; + byte vers; + byte track_count; + byte first_track; + byte load_addr [2]; + byte init_addr [2]; + byte play_addr [2]; + byte stack_ptr [2]; + byte timer_modulo; + byte timer_mode; + char game [32]; + char author [32]; + char copyright [32]; + }; + + // Header for currently loaded file + header_t const& header() const { return header_; } + + static gme_type_t static_type() { return gme_gbs_type; } + +public: + // deprecated + using Music_Emu::load; + blargg_err_t load( header_t const& h, Data_Reader& in ) // use Remaining_Reader + { return load_remaining_( &h, sizeof h, in ); } + +public: + Gbs_Emu(); + ~Gbs_Emu(); +protected: + blargg_err_t track_info_( track_info_t*, int track ) const; + blargg_err_t load_( Data_Reader& ); + blargg_err_t start_track_( int ); + blargg_err_t run_clocks( blip_time_t&, int ); + void set_tempo_( double ); + void set_voice( int, Blip_Buffer*, Blip_Buffer*, Blip_Buffer* ); + void update_eq( blip_eq_t const& ); + void unload(); +private: + // rom + enum { bank_size = 0x4000 }; + Rom_Data rom; + void set_bank( int ); + + // timer + blip_time_t cpu_time; + blip_time_t play_period; + blip_time_t next_play; + void update_timer(); + + header_t header_; + void cpu_jsr( gb_addr_t ); + +public: private: friend class Gb_Cpu; + blip_time_t clock() const { return cpu_time - cpu::remain(); } + + enum { joypad_addr = 0xFF00 }; + enum { ram_addr = 0xA000 }; + enum { hi_page = 0xFF00 - ram_addr }; + byte ram [0x4000 + 0x2000 + Gb_Cpu::cpu_padding]; + Gb_Apu apu; + + int cpu_read( gb_addr_t ); + void cpu_write( gb_addr_t, int ); +}; + +#endif diff --git a/libs/gme/gme/Gme_File.cpp b/libs/gme/gme/Gme_File.cpp new file mode 100644 index 000000000..995f56b1c --- /dev/null +++ b/libs/gme/gme/Gme_File.cpp @@ -0,0 +1,216 @@ +// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/ + +#include "Gme_File.h" + +#include "blargg_endian.h" +#include + +/* Copyright (C) 2003-2006 Shay Green. This module 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 +module 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 module; if not, write to the Free Software Foundation, +Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + +#include "blargg_source.h" + +const char* const gme_wrong_file_type = "Wrong file type for this emulator"; + +void Gme_File::clear_playlist() +{ + playlist.clear(); + clear_playlist_(); + track_count_ = raw_track_count_; +} + +void Gme_File::unload() +{ + clear_playlist(); // *before* clearing track count + track_count_ = 0; + raw_track_count_ = 0; + file_data.clear(); +} + +Gme_File::Gme_File() +{ + type_ = 0; + user_data_ = 0; + user_cleanup_ = 0; + unload(); // clears fields + blargg_verify_byte_order(); // used by most emulator types, so save them the trouble +} + +Gme_File::~Gme_File() +{ + if ( user_cleanup_ ) + user_cleanup_( user_data_ ); +} + +blargg_err_t Gme_File::load_mem_( byte const* data, long size ) +{ + require( data != file_data.begin() ); // load_mem_() or load_() must be overridden + Mem_File_Reader in( data, size ); + return load_( in ); +} + +blargg_err_t Gme_File::load_( Data_Reader& in ) +{ + RETURN_ERR( file_data.resize( in.remain() ) ); + RETURN_ERR( in.read( file_data.begin(), file_data.size() ) ); + return load_mem_( file_data.begin(), file_data.size() ); +} + +// public load functions call this at beginning +void Gme_File::pre_load() { unload(); } + +void Gme_File::post_load_() { } + +// public load functions call this at end +blargg_err_t Gme_File::post_load( blargg_err_t err ) +{ + if ( !track_count() ) + set_track_count( type()->track_count ); + if ( !err ) + post_load_(); + else + unload(); + + return err; +} + +// Public load functions + +blargg_err_t Gme_File::load_mem( void const* in, long size ) +{ + pre_load(); + return post_load( load_mem_( (byte const*) in, size ) ); +} + +blargg_err_t Gme_File::load( Data_Reader& in ) +{ + pre_load(); + return post_load( load_( in ) ); +} + +blargg_err_t Gme_File::load_file( const char* path ) +{ + pre_load(); + GME_FILE_READER in; + RETURN_ERR( in.open( path ) ); + return post_load( load_( in ) ); +} + +blargg_err_t Gme_File::load_remaining_( void const* h, long s, Data_Reader& in ) +{ + Remaining_Reader rem( h, s, &in ); + return load( rem ); +} + +// Track info + +void Gme_File::copy_field_( char* out, const char* in, int in_size ) +{ + if ( !in || !*in ) + return; + + // remove spaces/junk from beginning + while ( in_size && unsigned (*in - 1) <= ' ' - 1 ) + { + in++; + in_size--; + } + + // truncate + if ( in_size > max_field_ ) + in_size = max_field_; + + // find terminator + int len = 0; + while ( len < in_size && in [len] ) + len++; + + // remove spaces/junk from end + while ( len && unsigned (in [len - 1]) <= ' ' ) + len--; + + // copy + out [len] = 0; + memcpy( out, in, len ); + + // strip out stupid fields that should have been left blank + if ( !strcmp( out, "?" ) || !strcmp( out, "" ) || !strcmp( out, "< ? >" ) ) + out [0] = 0; +} + +void Gme_File::copy_field_( char* out, const char* in ) +{ + copy_field_( out, in, max_field_ ); +} + +blargg_err_t Gme_File::remap_track_( int* track_io ) const +{ + if ( (unsigned) *track_io >= (unsigned) track_count() ) + return "Invalid track"; + + if ( (unsigned) *track_io < (unsigned) playlist.size() ) + { + M3u_Playlist::entry_t const& e = playlist [*track_io]; + *track_io = 0; + if ( e.track >= 0 ) + { + *track_io = e.track; + if ( !(type_->flags_ & 0x02) ) + *track_io -= e.decimal_track; + } + if ( *track_io >= raw_track_count_ ) + return "Invalid track in m3u playlist"; + } + else + { + check( !playlist.size() ); + } + return 0; +} + +blargg_err_t Gme_File::track_info( track_info_t* out, int track ) const +{ + out->track_count = track_count(); + out->length = -1; + out->loop_length = -1; + out->intro_length = -1; + out->song [0] = 0; + + out->game [0] = 0; + out->author [0] = 0; + out->copyright [0] = 0; + out->comment [0] = 0; + out->dumper [0] = 0; + out->system [0] = 0; + + copy_field_( out->system, type()->system ); + + int remapped = track; + RETURN_ERR( remap_track_( &remapped ) ); + RETURN_ERR( track_info_( out, remapped ) ); + + // override with m3u info + if ( playlist.size() ) + { + M3u_Playlist::info_t const& i = playlist.info(); + copy_field_( out->game , i.title ); + copy_field_( out->author, i.engineer ); + copy_field_( out->author, i.composer ); + copy_field_( out->dumper, i.ripping ); + + M3u_Playlist::entry_t const& e = playlist [track]; + copy_field_( out->song, e.name ); + if ( e.length >= 0 ) out->length = e.length * 1000L; + if ( e.intro >= 0 ) out->intro_length = e.intro * 1000L; + if ( e.loop >= 0 ) out->loop_length = e.loop * 1000L; + } + return 0; +} diff --git a/libs/gme/gme/Gme_File.h b/libs/gme/gme/Gme_File.h new file mode 100644 index 000000000..2d0a57344 --- /dev/null +++ b/libs/gme/gme/Gme_File.h @@ -0,0 +1,177 @@ +// Common interface to game music file loading and information + +// Game_Music_Emu 0.6.0 +#ifndef GME_FILE_H +#define GME_FILE_H + +#include "gme.h" +#include "blargg_common.h" +#include "Data_Reader.h" +#include "M3u_Playlist.h" + +// Error returned if file is wrong type +//extern const char gme_wrong_file_type []; // declared in gme.h + +struct gme_type_t_ +{ + const char* system; /* name of system this music file type is generally for */ + int track_count; /* non-zero for formats with a fixed number of tracks */ + Music_Emu* (*new_emu)(); /* Create new emulator for this type (useful in C++ only) */ + Music_Emu* (*new_info)(); /* Create new info reader for this type */ + + /* internal */ + const char* extension_; + int flags_; +}; + +struct track_info_t +{ + long track_count; + + /* times in milliseconds; -1 if unknown */ + long length; + long intro_length; + long loop_length; + + /* empty string if not available */ + char system [256]; + char game [256]; + char song [256]; + char author [256]; + char copyright [256]; + char comment [256]; + char dumper [256]; +}; +enum { gme_max_field = 255 }; + +struct Gme_File { +public: +// File loading + + // Each loads game music data from a file and returns an error if + // file is wrong type or is seriously corrupt. They also set warning + // string for minor problems. + + // Load from file on disk + blargg_err_t load_file( const char* path ); + + // Load from custom data source (see Data_Reader.h) + blargg_err_t load( Data_Reader& ); + + // Load from file already read into memory. Keeps pointer to data, so you + // must not free it until you're done with the file. + blargg_err_t load_mem( void const* data, long size ); + + // Load an m3u playlist. Must be done after loading main music file. + blargg_err_t load_m3u( const char* path ); + blargg_err_t load_m3u( Data_Reader& in ); + + // Clears any loaded m3u playlist and any internal playlist that the music + // format supports (NSFE for example). + void clear_playlist(); + +// Informational + + // Type of emulator. For example if this returns gme_nsfe_type, this object + // is an NSFE emulator, and you can cast to an Nsfe_Emu* if necessary. + gme_type_t type() const; + + // Most recent warning string, or NULL if none. Clears current warning after + // returning. + const char* warning(); + + // Number of tracks or 0 if no file has been loaded + int track_count() const; + + // Get information for a track (length, name, author, etc.) + // See gme.h for definition of struct track_info_t. + blargg_err_t track_info( track_info_t* out, int track ) const; + +// User data/cleanup + + // Set/get pointer to data you want to associate with this emulator. + // You can use this for whatever you want. + void set_user_data( void* p ) { user_data_ = p; } + void* user_data() const { return user_data_; } + + // Register cleanup function to be called when deleting emulator, or NULL to + // clear it. Passes user_data to cleanup function. + void set_user_cleanup( gme_user_cleanup_t func ) { user_cleanup_ = func; } + +public: + // deprecated + int error_count() const; // use warning() +public: + Gme_File(); + virtual ~Gme_File(); + BLARGG_DISABLE_NOTHROW + typedef BOOST::uint8_t byte; +protected: + // Services + void set_track_count( int n ) { track_count_ = raw_track_count_ = n; } + void set_warning( const char* s ) { warning_ = s; } + void set_type( gme_type_t t ) { type_ = t; } + blargg_err_t load_remaining_( void const* header, long header_size, Data_Reader& remaining ); + + // Overridable + virtual void unload(); // called before loading file and if loading fails + virtual blargg_err_t load_( Data_Reader& ); // default loads then calls load_mem_() + virtual blargg_err_t load_mem_( byte const* data, long size ); // use data in memory + virtual blargg_err_t track_info_( track_info_t* out, int track ) const = 0; + virtual void pre_load(); + virtual void post_load_(); + virtual void clear_playlist_() { } + +public: + blargg_err_t remap_track_( int* track_io ) const; // need by Music_Emu +private: + // noncopyable + Gme_File( const Gme_File& ); + Gme_File& operator = ( const Gme_File& ); + + gme_type_t type_; + int track_count_; + int raw_track_count_; + const char* warning_; + void* user_data_; + gme_user_cleanup_t user_cleanup_; + M3u_Playlist playlist; + char playlist_warning [64]; + blargg_vector file_data; // only if loaded into memory using default load + + blargg_err_t load_m3u_( blargg_err_t ); + blargg_err_t post_load( blargg_err_t err ); +public: + // track_info field copying + enum { max_field_ = 255 }; + static void copy_field_( char* out, const char* in ); + static void copy_field_( char* out, const char* in, int len ); +}; + +Music_Emu* gme_new_( Music_Emu*, long sample_rate ); + +#define GME_COPY_FIELD( in, out, name ) \ + { Gme_File::copy_field_( out->name, in.name, sizeof in.name ); } + +#ifndef GME_FILE_READER + #ifdef HAVE_ZLIB_H + #define GME_FILE_READER Gzip_File_Reader + #else + #define GME_FILE_READER Std_File_Reader + #endif +#elif defined (GME_FILE_READER_INCLUDE) + #include GME_FILE_READER_INCLUDE +#endif + +inline gme_type_t Gme_File::type() const { return type_; } +inline int Gme_File::error_count() const { return warning_ != 0; } +inline int Gme_File::track_count() const { return track_count_; } + +inline const char* Gme_File::warning() +{ + const char* s = warning_; + warning_ = 0; + return s; +} + +#endif diff --git a/libs/gme/gme/Gym_Emu.cpp b/libs/gme/gme/Gym_Emu.cpp new file mode 100644 index 000000000..f149aebb5 --- /dev/null +++ b/libs/gme/gme/Gym_Emu.cpp @@ -0,0 +1,380 @@ +// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/ + +#include "Gym_Emu.h" + +#include "blargg_endian.h" +#include + +/* Copyright (C) 2003-2006 Shay Green. This module 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 +module 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 module; if not, write to the Free Software Foundation, +Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + +#include "blargg_source.h" + +double const min_tempo = 0.25; +double const oversample_factor = 5 / 3.0; +double const fm_gain = 3.0; + +const long base_clock = 53700300; +const long clock_rate = base_clock / 15; + +Gym_Emu::Gym_Emu() +{ + data = 0; + pos = 0; + set_type( gme_gym_type ); + + static const char* const names [] = { + "FM 1", "FM 2", "FM 3", "FM 4", "FM 5", "FM 6", "PCM", "PSG" + }; + set_voice_names( names ); + set_silence_lookahead( 1 ); // tracks should already be trimmed +} + +Gym_Emu::~Gym_Emu() { } + +// Track info + +static void get_gym_info( Gym_Emu::header_t const& h, long length, track_info_t* out ) +{ + if ( !memcmp( h.tag, "GYMX", 4 ) ) + { + length = length * 50 / 3; // 1000 / 60 + long loop = get_le32( h.loop_start ); + if ( loop ) + { + out->intro_length = loop * 50 / 3; + out->loop_length = length - out->intro_length; + } + else + { + out->length = length; + out->intro_length = length; // make it clear that track is no longer than length + out->loop_length = 0; + } + + // more stupidity where the field should have been left + if ( strcmp( h.song, "Unknown Song" ) ) + GME_COPY_FIELD( h, out, song ); + + if ( strcmp( h.game, "Unknown Game" ) ) + GME_COPY_FIELD( h, out, game ); + + if ( strcmp( h.copyright, "Unknown Publisher" ) ) + GME_COPY_FIELD( h, out, copyright ); + + if ( strcmp( h.dumper, "Unknown Person" ) ) + GME_COPY_FIELD( h, out, dumper ); + + if ( strcmp( h.comment, "Header added by YMAMP" ) ) + GME_COPY_FIELD( h, out, comment ); + } +} + +blargg_err_t Gym_Emu::track_info_( track_info_t* out, int ) const +{ + get_gym_info( header_, track_length(), out ); + return 0; +} + +static long gym_track_length( byte const* p, byte const* end ) +{ + long time = 0; + while ( p < end ) + { + switch ( *p++ ) + { + case 0: + time++; + break; + + case 1: + case 2: + p += 2; + break; + + case 3: + p += 1; + break; + } + } + return time; +} + +long Gym_Emu::track_length() const { return gym_track_length( data, data_end ); } + +static blargg_err_t check_header( byte const* in, long size, int* data_offset = 0 ) +{ + if ( size < 4 ) + return gme_wrong_file_type; + + if ( memcmp( in, "GYMX", 4 ) == 0 ) + { + if ( size < Gym_Emu::header_size + 1 ) + return gme_wrong_file_type; + + if ( memcmp( ((Gym_Emu::header_t const*) in)->packed, "\0\0\0\0", 4 ) != 0 ) + return "Packed GYM file not supported"; + + if ( data_offset ) + *data_offset = Gym_Emu::header_size; + } + else if ( *in > 3 ) + { + return gme_wrong_file_type; + } + + return 0; +} + +struct Gym_File : Gme_Info_ +{ + byte const* file_begin; + byte const* file_end; + int data_offset; + + Gym_File() { set_type( gme_gym_type ); } + + blargg_err_t load_mem_( byte const* in, long size ) + { + file_begin = in; + file_end = in + size; + data_offset = 0; + return check_header( in, size, &data_offset ); + } + + blargg_err_t track_info_( track_info_t* out, int ) const + { + long length = gym_track_length( &file_begin [data_offset], file_end ); + get_gym_info( *(Gym_Emu::header_t const*) file_begin, length, out ); + return 0; + } +}; + +static Music_Emu* new_gym_emu () { return BLARGG_NEW Gym_Emu ; } +static Music_Emu* new_gym_file() { return BLARGG_NEW Gym_File; } + +static gme_type_t_ const gme_gym_type_ = { "Sega Genesis", 1, &new_gym_emu, &new_gym_file, "GYM", 0 }; +gme_type_t const gme_gym_type = &gme_gym_type_; + +// Setup + +blargg_err_t Gym_Emu::set_sample_rate_( long sample_rate ) +{ + blip_eq_t eq( -32, 8000, sample_rate ); + apu.treble_eq( eq ); + dac_synth.treble_eq( eq ); + apu.volume( 0.135 * fm_gain * gain() ); + dac_synth.volume( 0.125 / 256 * fm_gain * gain() ); + double factor = Dual_Resampler::setup( oversample_factor, 0.990, fm_gain * gain() ); + fm_sample_rate = sample_rate * factor; + + RETURN_ERR( blip_buf.set_sample_rate( sample_rate, int (1000 / 60.0 / min_tempo) ) ); + blip_buf.clock_rate( clock_rate ); + + RETURN_ERR( fm.set_rate( fm_sample_rate, base_clock / 7.0 ) ); + RETURN_ERR( Dual_Resampler::reset( long (1.0 / 60 / min_tempo * sample_rate) ) ); + + return 0; +} + +void Gym_Emu::set_tempo_( double t ) +{ + if ( t < min_tempo ) + { + set_tempo( min_tempo ); + return; + } + + if ( blip_buf.sample_rate() ) + { + clocks_per_frame = long (clock_rate / 60 / tempo()); + Dual_Resampler::resize( long (sample_rate() / (60.0 * tempo())) ); + } +} + +void Gym_Emu::mute_voices_( int mask ) +{ + Music_Emu::mute_voices_( mask ); + fm.mute_voices( mask ); + dac_muted = (mask & 0x40) != 0; + apu.output( (mask & 0x80) ? 0 : &blip_buf ); +} + +blargg_err_t Gym_Emu::load_mem_( byte const* in, long size ) +{ + assert( offsetof (header_t,packed [4]) == header_size ); + int offset = 0; + RETURN_ERR( check_header( in, size, &offset ) ); + set_voice_count( 8 ); + + data = in + offset; + data_end = in + size; + loop_begin = 0; + + if ( offset ) + header_ = *(header_t const*) in; + else + memset( &header_, 0, sizeof header_ ); + + return 0; +} + +// Emulation + +blargg_err_t Gym_Emu::start_track_( int track ) +{ + RETURN_ERR( Music_Emu::start_track_( track ) ); + + pos = data; + loop_remain = get_le32( header_.loop_start ); + + prev_dac_count = 0; + dac_enabled = false; + dac_amp = -1; + + fm.reset(); + apu.reset(); + blip_buf.clear(); + Dual_Resampler::clear(); + return 0; +} + +void Gym_Emu::run_dac( int dac_count ) +{ + // Guess beginning and end of sample and adjust rate and buffer position accordingly. + + // count dac samples in next frame + int next_dac_count = 0; + const byte* p = this->pos; + int cmd; + while ( (cmd = *p++) != 0 ) + { + int data = *p++; + if ( cmd <= 2 ) + ++p; + if ( cmd == 1 && data == 0x2A ) + next_dac_count++; + } + + // detect beginning and end of sample + int rate_count = dac_count; + int start = 0; + if ( !prev_dac_count && next_dac_count && dac_count < next_dac_count ) + { + rate_count = next_dac_count; + start = next_dac_count - dac_count; + } + else if ( prev_dac_count && !next_dac_count && dac_count < prev_dac_count ) + { + rate_count = prev_dac_count; + } + + // Evenly space samples within buffer section being used + blip_resampled_time_t period = blip_buf.resampled_duration( clocks_per_frame ) / rate_count; + + blip_resampled_time_t time = blip_buf.resampled_time( 0 ) + + period * start + (period >> 1); + + int dac_amp = this->dac_amp; + if ( dac_amp < 0 ) + dac_amp = dac_buf [0]; + + for ( int i = 0; i < dac_count; i++ ) + { + int delta = dac_buf [i] - dac_amp; + dac_amp += delta; + dac_synth.offset_resampled( time, delta, &blip_buf ); + time += period; + } + this->dac_amp = dac_amp; +} + +void Gym_Emu::parse_frame() +{ + int dac_count = 0; + const byte* pos = this->pos; + + if ( loop_remain && !--loop_remain ) + loop_begin = pos; // find loop on first time through sequence + + int cmd; + while ( (cmd = *pos++) != 0 ) + { + int data = *pos++; + if ( cmd == 1 ) + { + int data2 = *pos++; + if ( data != 0x2A ) + { + if ( data == 0x2B ) + dac_enabled = (data2 & 0x80) != 0; + + fm.write0( data, data2 ); + } + else if ( dac_count < (int) sizeof dac_buf ) + { + dac_buf [dac_count] = data2; + dac_count += dac_enabled; + } + } + else if ( cmd == 2 ) + { + fm.write1( data, *pos++ ); + } + else if ( cmd == 3 ) + { + apu.write_data( 0, data ); + } + else + { + // to do: many GYM streams are full of errors, and error count should + // reflect cases where music is really having problems + //log_error(); + --pos; // put data back + } + } + + // loop + if ( pos >= data_end ) + { + check( pos == data_end ); + + if ( loop_begin ) + pos = loop_begin; + else + set_track_ended(); + } + this->pos = pos; + + // dac + if ( dac_count && !dac_muted ) + run_dac( dac_count ); + prev_dac_count = dac_count; +} + +int Gym_Emu::play_frame( blip_time_t blip_time, int sample_count, sample_t* buf ) +{ + if ( !track_ended() ) + parse_frame(); + + apu.end_frame( blip_time ); + + memset( buf, 0, sample_count * sizeof *buf ); + fm.run( sample_count >> 1, buf ); + + return sample_count; +} + +blargg_err_t Gym_Emu::play_( long count, sample_t* out ) +{ + Dual_Resampler::dual_play( count, out, blip_buf ); + return 0; +} diff --git a/libs/gme/gme/Gym_Emu.h b/libs/gme/gme/Gym_Emu.h new file mode 100644 index 000000000..1e4ed8b3e --- /dev/null +++ b/libs/gme/gme/Gym_Emu.h @@ -0,0 +1,82 @@ +// Sega Genesis/Mega Drive GYM music file emulator +// Includes with PCM timing recovery to improve sample quality. + +// Game_Music_Emu 0.6.0 +#ifndef GYM_EMU_H +#define GYM_EMU_H + +#include "Dual_Resampler.h" +#include "Ym2612_Emu.h" +#include "Music_Emu.h" +#include "Sms_Apu.h" + +class Gym_Emu : public Music_Emu, private Dual_Resampler { +public: + // GYM file header + enum { header_size = 428 }; + struct header_t + { + char tag [4]; + char song [32]; + char game [32]; + char copyright [32]; + char emulator [32]; + char dumper [32]; + char comment [256]; + byte loop_start [4]; // in 1/60 seconds, 0 if not looped + byte packed [4]; + }; + + // Header for currently loaded file + header_t const& header() const { return header_; } + + static gme_type_t static_type() { return gme_gym_type; } + +public: + // deprecated + using Music_Emu::load; + blargg_err_t load( header_t const& h, Data_Reader& in ) // use Remaining_Reader + { return load_remaining_( &h, sizeof h, in ); } + enum { gym_rate = 60 }; + long track_length() const; // use track_info() + +public: + Gym_Emu(); + ~Gym_Emu(); +protected: + blargg_err_t load_mem_( byte const*, long ); + blargg_err_t track_info_( track_info_t*, int track ) const; + blargg_err_t set_sample_rate_( long sample_rate ); + blargg_err_t start_track_( int ); + blargg_err_t play_( long count, sample_t* ); + void mute_voices_( int ); + void set_tempo_( double ); + int play_frame( blip_time_t blip_time, int sample_count, sample_t* buf ); +private: + // sequence data begin, loop begin, current position, end + const byte* data; + const byte* loop_begin; + const byte* pos; + const byte* data_end; + blargg_long loop_remain; // frames remaining until loop beginning has been located + header_t header_; + double fm_sample_rate; + blargg_long clocks_per_frame; + void parse_frame(); + + // dac (pcm) + int dac_amp; + int prev_dac_count; + bool dac_enabled; + bool dac_muted; + void run_dac( int ); + + // sound + Blip_Buffer blip_buf; + Ym2612_Emu fm; + Blip_Synth dac_synth; + Sms_Apu apu; + byte dac_buf [1024]; +}; + +#endif diff --git a/libs/gme/gme/Hes_Apu.cpp b/libs/gme/gme/Hes_Apu.cpp new file mode 100644 index 000000000..9c7f515d6 --- /dev/null +++ b/libs/gme/gme/Hes_Apu.cpp @@ -0,0 +1,315 @@ +// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/ + +#include "Hes_Apu.h" + +#include + +/* Copyright (C) 2006 Shay Green. This module 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 +module 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 module; if not, write to the Free Software Foundation, +Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + +#include "blargg_source.h" + +bool const center_waves = true; // reduces asymmetry and clamping when starting notes + +Hes_Apu::Hes_Apu() +{ + Hes_Osc* osc = &oscs [osc_count]; + do + { + osc--; + osc->outputs [0] = 0; + osc->outputs [1] = 0; + osc->chans [0] = 0; + osc->chans [1] = 0; + osc->chans [2] = 0; + } + while ( osc != oscs ); + + reset(); +} + +void Hes_Apu::reset() +{ + latch = 0; + balance = 0xFF; + + Hes_Osc* osc = &oscs [osc_count]; + do + { + osc--; + memset( osc, 0, offsetof (Hes_Osc,outputs) ); + osc->noise_lfsr = 1; + osc->control = 0x40; + osc->balance = 0xFF; + } + while ( osc != oscs ); +} + +void Hes_Apu::osc_output( int index, Blip_Buffer* center, Blip_Buffer* left, Blip_Buffer* right ) +{ + require( (unsigned) index < osc_count ); + oscs [index].chans [0] = center; + oscs [index].chans [1] = left; + oscs [index].chans [2] = right; + + Hes_Osc* osc = &oscs [osc_count]; + do + { + osc--; + balance_changed( *osc ); + } + while ( osc != oscs ); +} + +void Hes_Osc::run_until( synth_t& synth_, blip_time_t end_time ) +{ + Blip_Buffer* const osc_outputs_0 = outputs [0]; // cache often-used values + if ( osc_outputs_0 && control & 0x80 ) + { + int dac = this->dac; + + int const volume_0 = volume [0]; + { + int delta = dac * volume_0 - last_amp [0]; + if ( delta ) + synth_.offset( last_time, delta, osc_outputs_0 ); + osc_outputs_0->set_modified(); + } + + Blip_Buffer* const osc_outputs_1 = outputs [1]; + int const volume_1 = volume [1]; + if ( osc_outputs_1 ) + { + int delta = dac * volume_1 - last_amp [1]; + if ( delta ) + synth_.offset( last_time, delta, osc_outputs_1 ); + osc_outputs_1->set_modified(); + } + + blip_time_t time = last_time + delay; + if ( time < end_time ) + { + if ( noise & 0x80 ) + { + if ( volume_0 | volume_1 ) + { + // noise + int const period = (32 - (noise & 0x1F)) * 64; // TODO: correct? + unsigned noise_lfsr = this->noise_lfsr; + do + { + int new_dac = 0x1F & -(noise_lfsr >> 1 & 1); + // Implemented using "Galios configuration" + // TODO: find correct LFSR algorithm + noise_lfsr = (noise_lfsr >> 1) ^ (0xE008 & -(noise_lfsr & 1)); + //noise_lfsr = (noise_lfsr >> 1) ^ (0x6000 & -(noise_lfsr & 1)); + int delta = new_dac - dac; + if ( delta ) + { + dac = new_dac; + synth_.offset( time, delta * volume_0, osc_outputs_0 ); + if ( osc_outputs_1 ) + synth_.offset( time, delta * volume_1, osc_outputs_1 ); + } + time += period; + } + while ( time < end_time ); + + this->noise_lfsr = noise_lfsr; + assert( noise_lfsr ); + } + } + else if ( !(control & 0x40) ) + { + // wave + int phase = (this->phase + 1) & 0x1F; // pre-advance for optimal inner loop + int period = this->period * 2; + if ( period >= 14 && (volume_0 | volume_1) ) + { + do + { + int new_dac = wave [phase]; + phase = (phase + 1) & 0x1F; + int delta = new_dac - dac; + if ( delta ) + { + dac = new_dac; + synth_.offset( time, delta * volume_0, osc_outputs_0 ); + if ( osc_outputs_1 ) + synth_.offset( time, delta * volume_1, osc_outputs_1 ); + } + time += period; + } + while ( time < end_time ); + } + else + { + if ( !period ) + { + // TODO: Gekisha Boy assumes that period = 0 silences wave + //period = 0x1000 * 2; + period = 1; + //if ( !(volume_0 | volume_1) ) + // debug_printf( "Used period 0\n" ); + } + + // maintain phase when silent + blargg_long count = (end_time - time + period - 1) / period; + phase += count; // phase will be masked below + time += count * period; + } + this->phase = (phase - 1) & 0x1F; // undo pre-advance + } + } + time -= end_time; + if ( time < 0 ) + time = 0; + delay = time; + + this->dac = dac; + last_amp [0] = dac * volume_0; + last_amp [1] = dac * volume_1; + } + last_time = end_time; +} + +void Hes_Apu::balance_changed( Hes_Osc& osc ) +{ + static short const log_table [32] = { // ~1.5 db per step + #define ENTRY( factor ) short (factor * Hes_Osc::amp_range / 31.0 + 0.5) + ENTRY( 0.000000 ),ENTRY( 0.005524 ),ENTRY( 0.006570 ),ENTRY( 0.007813 ), + ENTRY( 0.009291 ),ENTRY( 0.011049 ),ENTRY( 0.013139 ),ENTRY( 0.015625 ), + ENTRY( 0.018581 ),ENTRY( 0.022097 ),ENTRY( 0.026278 ),ENTRY( 0.031250 ), + ENTRY( 0.037163 ),ENTRY( 0.044194 ),ENTRY( 0.052556 ),ENTRY( 0.062500 ), + ENTRY( 0.074325 ),ENTRY( 0.088388 ),ENTRY( 0.105112 ),ENTRY( 0.125000 ), + ENTRY( 0.148651 ),ENTRY( 0.176777 ),ENTRY( 0.210224 ),ENTRY( 0.250000 ), + ENTRY( 0.297302 ),ENTRY( 0.353553 ),ENTRY( 0.420448 ),ENTRY( 0.500000 ), + ENTRY( 0.594604 ),ENTRY( 0.707107 ),ENTRY( 0.840896 ),ENTRY( 1.000000 ), + #undef ENTRY + }; + + int vol = (osc.control & 0x1F) - 0x1E * 2; + + int left = vol + (osc.balance >> 3 & 0x1E) + (balance >> 3 & 0x1E); + if ( left < 0 ) left = 0; + + int right = vol + (osc.balance << 1 & 0x1E) + (balance << 1 & 0x1E); + if ( right < 0 ) right = 0; + + left = log_table [left ]; + right = log_table [right]; + + // optimizing for the common case of being centered also allows easy + // panning using Effects_Buffer + osc.outputs [0] = osc.chans [0]; // center + osc.outputs [1] = 0; + if ( left != right ) + { + osc.outputs [0] = osc.chans [1]; // left + osc.outputs [1] = osc.chans [2]; // right + } + + if ( center_waves ) + { + osc.last_amp [0] += (left - osc.volume [0]) * 16; + osc.last_amp [1] += (right - osc.volume [1]) * 16; + } + + osc.volume [0] = left; + osc.volume [1] = right; +} + +void Hes_Apu::write_data( blip_time_t time, int addr, int data ) +{ + if ( addr == 0x800 ) + { + latch = data & 7; + } + else if ( addr == 0x801 ) + { + if ( balance != data ) + { + balance = data; + + Hes_Osc* osc = &oscs [osc_count]; + do + { + osc--; + osc->run_until( synth, time ); + balance_changed( *oscs ); + } + while ( osc != oscs ); + } + } + else if ( latch < osc_count ) + { + Hes_Osc& osc = oscs [latch]; + osc.run_until( synth, time ); + switch ( addr ) + { + case 0x802: + osc.period = (osc.period & 0xF00) | data; + break; + + case 0x803: + osc.period = (osc.period & 0x0FF) | ((data & 0x0F) << 8); + break; + + case 0x804: + if ( osc.control & 0x40 & ~data ) + osc.phase = 0; + osc.control = data; + balance_changed( osc ); + break; + + case 0x805: + osc.balance = data; + balance_changed( osc ); + break; + + case 0x806: + data &= 0x1F; + if ( !(osc.control & 0x40) ) + { + osc.wave [osc.phase] = data; + osc.phase = (osc.phase + 1) & 0x1F; + } + else if ( osc.control & 0x80 ) + { + osc.dac = data; + } + break; + + case 0x807: + if ( &osc >= &oscs [4] ) + osc.noise = data; + break; + + case 0x809: + if ( !(data & 0x80) && (data & 0x03) != 0 ) + debug_printf( "HES LFO not supported\n" ); + } + } +} + +void Hes_Apu::end_frame( blip_time_t end_time ) +{ + Hes_Osc* osc = &oscs [osc_count]; + do + { + osc--; + if ( end_time > osc->last_time ) + osc->run_until( synth, end_time ); + assert( osc->last_time >= end_time ); + osc->last_time -= end_time; + } + while ( osc != oscs ); +} diff --git a/libs/gme/gme/Hes_Apu.h b/libs/gme/gme/Hes_Apu.h new file mode 100644 index 000000000..89dde02cd --- /dev/null +++ b/libs/gme/gme/Hes_Apu.h @@ -0,0 +1,66 @@ +// Turbo Grafx 16 (PC Engine) PSG sound chip emulator + +// Game_Music_Emu 0.6.0 +#ifndef HES_APU_H +#define HES_APU_H + +#include "blargg_common.h" +#include "Blip_Buffer.h" + +struct Hes_Osc +{ + unsigned char wave [32]; + short volume [2]; + int last_amp [2]; + int delay; + int period; + unsigned char noise; + unsigned char phase; + unsigned char balance; + unsigned char dac; + blip_time_t last_time; + + Blip_Buffer* outputs [2]; + Blip_Buffer* chans [3]; + unsigned noise_lfsr; + unsigned char control; + + enum { amp_range = 0x8000 }; + typedef Blip_Synth synth_t; + + void run_until( synth_t& synth, blip_time_t ); +}; + +class Hes_Apu { +public: + void treble_eq( blip_eq_t const& ); + void volume( double ); + + enum { osc_count = 6 }; + void osc_output( int index, Blip_Buffer* center, Blip_Buffer* left, Blip_Buffer* right ); + + void reset(); + + enum { start_addr = 0x0800 }; + enum { end_addr = 0x0809 }; + void write_data( blip_time_t, int addr, int data ); + + void end_frame( blip_time_t ); + +public: + Hes_Apu(); +private: + Hes_Osc oscs [osc_count]; + int latch; + int balance; + Hes_Osc::synth_t synth; + + void balance_changed( Hes_Osc& ); + void recalc_chans(); +}; + +inline void Hes_Apu::volume( double v ) { synth.volume( 1.8 / osc_count / Hes_Osc::amp_range * v ); } + +inline void Hes_Apu::treble_eq( blip_eq_t const& eq ) { synth.treble_eq( eq ); } + +#endif diff --git a/libs/gme/gme/Hes_Cpu.cpp b/libs/gme/gme/Hes_Cpu.cpp new file mode 100644 index 000000000..4bfe8faff --- /dev/null +++ b/libs/gme/gme/Hes_Cpu.cpp @@ -0,0 +1,1303 @@ +// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/ + +#include "Hes_Cpu.h" + +#include "blargg_endian.h" + +//#include "hes_cpu_log.h" + +/* Copyright (C) 2003-2006 Shay Green. This module 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 +module 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 module; if not, write to the Free Software Foundation, +Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + +// TODO: support T flag, including clearing it at appropriate times? + +// all zero-page should really use whatever is at page 1, but that would +// reduce efficiency quite a bit +int const ram_addr = 0x2000; + +#define FLUSH_TIME() (void) (s.time = s_time) +#define CACHE_TIME() (void) (s_time = s.time) + +#include "hes_cpu_io.h" + +#include "blargg_source.h" + +#if BLARGG_NONPORTABLE + #define PAGE_OFFSET( addr ) (addr) +#else + #define PAGE_OFFSET( addr ) ((addr) & (page_size - 1)) +#endif + +// status flags +int const st_n = 0x80; +int const st_v = 0x40; +int const st_t = 0x20; +int const st_b = 0x10; +int const st_d = 0x08; +int const st_i = 0x04; +int const st_z = 0x02; +int const st_c = 0x01; + +void Hes_Cpu::reset() +{ + check( state == &state_ ); + state = &state_; + + state_.time = 0; + state_.base = 0; + irq_time_ = future_hes_time; + end_time_ = future_hes_time; + + r.status = st_i; + r.sp = 0; + r.pc = 0; + r.a = 0; + r.x = 0; + r.y = 0; + + blargg_verify_byte_order(); +} + +void Hes_Cpu::set_mmr( int reg, int bank ) +{ + assert( (unsigned) reg <= page_count ); // allow page past end to be set + assert( (unsigned) bank < 0x100 ); + mmr [reg] = bank; + uint8_t const* code = CPU_SET_MMR( this, reg, bank ); + state->code_map [reg] = code - PAGE_OFFSET( reg << page_shift ); +} + +#define TIME (s_time + s.base) + +#define READ( addr ) CPU_READ( this, (addr), TIME ) +#define WRITE( addr, data ) {CPU_WRITE( this, (addr), (data), TIME );} +#define READ_LOW( addr ) (ram [int (addr)]) +#define WRITE_LOW( addr, data ) (void) (READ_LOW( addr ) = (data)) +#define READ_PROG( addr ) (s.code_map [(addr) >> page_shift] [PAGE_OFFSET( addr )]) + +#define SET_SP( v ) (sp = ((v) + 1) | 0x100) +#define GET_SP() ((sp - 1) & 0xFF) +#define PUSH( v ) ((sp = (sp - 1) | 0x100), WRITE_LOW( sp, v )) + +// even on x86, using short and unsigned char was slower +typedef int fint16; +typedef unsigned fuint16; +typedef unsigned fuint8; +typedef blargg_long fint32; + +bool Hes_Cpu::run( hes_time_t end_time ) +{ + bool illegal_encountered = false; + set_end_time( end_time ); + state_t s = this->state_; + this->state = &s; + // even on x86, using s.time in place of s_time was slower + fint16 s_time = s.time; + + // registers + fuint16 pc = r.pc; + fuint8 a = r.a; + fuint8 x = r.x; + fuint8 y = r.y; + fuint16 sp; + SET_SP( r.sp ); + + #define IS_NEG (nz & 0x8080) + + #define CALC_STATUS( out ) do {\ + out = status & (st_v | st_d | st_i);\ + out |= ((nz >> 8) | nz) & st_n;\ + out |= c >> 8 & st_c;\ + if ( !(nz & 0xFF) ) out |= st_z;\ + } while ( 0 ) + + #define SET_STATUS( in ) do {\ + status = in & (st_v | st_d | st_i);\ + nz = in << 8;\ + c = nz;\ + nz |= ~in & st_z;\ + } while ( 0 ) + + fuint8 status; + fuint16 c; // carry set if (c & 0x100) != 0 + fuint16 nz; // Z set if (nz & 0xFF) == 0, N set if (nz & 0x8080) != 0 + { + fuint8 temp = r.status; + SET_STATUS( temp ); + } + + goto loop; +branch_not_taken: + s_time -= 2; +loop: + + #ifndef NDEBUG + { + hes_time_t correct = end_time_; + if ( !(status & st_i) && correct > irq_time_ ) + correct = irq_time_; + check( s.base == correct ); + /* + static long count; + if ( count == 1844 ) Debugger(); + if ( s.base != correct ) debug_printf( "%ld\n", count ); + count++; + */ + } + #endif + + check( (unsigned) GET_SP() < 0x100 ); + check( (unsigned) a < 0x100 ); + check( (unsigned) x < 0x100 ); + + uint8_t const* instr = s.code_map [pc >> page_shift]; + fuint8 opcode; + + // TODO: eliminate this special case + #if BLARGG_NONPORTABLE + opcode = instr [pc]; + pc++; + instr += pc; + #else + instr += PAGE_OFFSET( pc ); + opcode = *instr++; + pc++; + #endif + + // TODO: each reference lists slightly different timing values, ugh + static uint8_t const clock_table [256] = + {// 0 1 2 3 4 5 6 7 8 9 A B C D E F + 1,7,3, 4,6,4,6,7,3,2,2,2,7,5,7,6,// 0 + 4,7,7, 4,6,4,6,7,2,5,2,2,7,5,7,6,// 1 + 7,7,3, 4,4,4,6,7,4,2,2,2,5,5,7,6,// 2 + 4,7,7, 2,4,4,6,7,2,5,2,2,5,5,7,6,// 3 + 7,7,3, 4,8,4,6,7,3,2,2,2,4,5,7,6,// 4 + 4,7,7, 5,2,4,6,7,2,5,3,2,2,5,7,6,// 5 + 7,7,2, 2,4,4,6,7,4,2,2,2,7,5,7,6,// 6 + 4,7,7,17,4,4,6,7,2,5,4,2,7,5,7,6,// 7 + 4,7,2, 7,4,4,4,7,2,2,2,2,5,5,5,6,// 8 + 4,7,7, 8,4,4,4,7,2,5,2,2,5,5,5,6,// 9 + 2,7,2, 7,4,4,4,7,2,2,2,2,5,5,5,6,// A + 4,7,7, 8,4,4,4,7,2,5,2,2,5,5,5,6,// B + 2,7,2,17,4,4,6,7,2,2,2,2,5,5,7,6,// C + 4,7,7,17,2,4,6,7,2,5,3,2,2,5,7,6,// D + 2,7,2,17,4,4,6,7,2,2,2,2,5,5,7,6,// E + 4,7,7,17,2,4,6,7,2,5,4,2,2,5,7,6 // F + }; // 0x00 was 8 + + fuint16 data; + data = clock_table [opcode]; + if ( (s_time += data) >= 0 ) + goto possibly_out_of_time; +almost_out_of_time: + + data = *instr; + + #ifdef HES_CPU_LOG_H + log_cpu( "new", pc - 1, opcode, instr [0], instr [1], instr [2], + instr [3], instr [4], instr [5] ); + //log_opcode( opcode ); + #endif + + switch ( opcode ) + { +possibly_out_of_time: + if ( s_time < (int) data ) + goto almost_out_of_time; + s_time -= data; + goto out_of_time; + +// Macros + +#define GET_MSB() (instr [1]) +#define ADD_PAGE( out ) (pc++, out = data + 0x100 * GET_MSB()); +#define GET_ADDR() GET_LE16( instr ) + +// TODO: is the penalty really always added? the original 6502 was much better +//#define PAGE_CROSS_PENALTY( lsb ) (void) (s_time += (lsb) >> 8) +#define PAGE_CROSS_PENALTY( lsb ) + +// Branch + +// TODO: more efficient way to handle negative branch that wraps PC around +#define BRANCH( cond )\ +{\ + fint16 offset = (BOOST::int8_t) data;\ + pc++;\ + if ( !(cond) ) goto branch_not_taken;\ + pc = BOOST::uint16_t (pc + offset);\ + goto loop;\ +} + + case 0xF0: // BEQ + BRANCH( !((uint8_t) nz) ); + + case 0xD0: // BNE + BRANCH( (uint8_t) nz ); + + case 0x10: // BPL + BRANCH( !IS_NEG ); + + case 0x90: // BCC + BRANCH( !(c & 0x100) ) + + case 0x30: // BMI + BRANCH( IS_NEG ) + + case 0x50: // BVC + BRANCH( !(status & st_v) ) + + case 0x70: // BVS + BRANCH( status & st_v ) + + case 0xB0: // BCS + BRANCH( c & 0x100 ) + + case 0x80: // BRA + branch_taken: + BRANCH( true ); + + case 0xFF: + if ( pc == idle_addr + 1 ) + goto idle_done; + case 0x0F: // BBRn + case 0x1F: + case 0x2F: + case 0x3F: + case 0x4F: + case 0x5F: + case 0x6F: + case 0x7F: + case 0x8F: // BBSn + case 0x9F: + case 0xAF: + case 0xBF: + case 0xCF: + case 0xDF: + case 0xEF: { + fuint16 t = 0x101 * READ_LOW( data ); + t ^= 0xFF; + pc++; + data = GET_MSB(); + BRANCH( t & (1 << (opcode >> 4)) ) + } + + case 0x4C: // JMP abs + pc = GET_ADDR(); + goto loop; + + case 0x7C: // JMP (ind+X) + data += x; + case 0x6C:{// JMP (ind) + data += 0x100 * GET_MSB(); + pc = GET_LE16( &READ_PROG( data ) ); + goto loop; + } + +// Subroutine + + case 0x44: // BSR + WRITE_LOW( 0x100 | (sp - 1), pc >> 8 ); + sp = (sp - 2) | 0x100; + WRITE_LOW( sp, pc ); + goto branch_taken; + + case 0x20: { // JSR + fuint16 temp = pc + 1; + pc = GET_ADDR(); + WRITE_LOW( 0x100 | (sp - 1), temp >> 8 ); + sp = (sp - 2) | 0x100; + WRITE_LOW( sp, temp ); + goto loop; + } + + case 0x60: // RTS + pc = 0x100 * READ_LOW( 0x100 | (sp - 0xFF) ); + pc += 1 + READ_LOW( sp ); + sp = (sp - 0xFE) | 0x100; + goto loop; + + case 0x00: // BRK + goto handle_brk; + +// Common + + case 0xBD:{// LDA abs,X + PAGE_CROSS_PENALTY( data + x ); + fuint16 addr = GET_ADDR() + x; + pc += 2; + CPU_READ_FAST( this, addr, TIME, nz ); + a = nz; + goto loop; + } + + case 0x9D:{// STA abs,X + fuint16 addr = GET_ADDR() + x; + pc += 2; + CPU_WRITE_FAST( this, addr, a, TIME ); + goto loop; + } + + case 0x95: // STA zp,x + data = uint8_t (data + x); + case 0x85: // STA zp + pc++; + WRITE_LOW( data, a ); + goto loop; + + case 0xAE:{// LDX abs + fuint16 addr = GET_ADDR(); + pc += 2; + CPU_READ_FAST( this, addr, TIME, nz ); + x = nz; + goto loop; + } + + case 0xA5: // LDA zp + a = nz = READ_LOW( data ); + pc++; + goto loop; + +// Load/store + + { + fuint16 addr; + case 0x91: // STA (ind),Y + addr = 0x100 * READ_LOW( uint8_t (data + 1) ); + addr += READ_LOW( data ) + y; + pc++; + goto sta_ptr; + + case 0x81: // STA (ind,X) + data = uint8_t (data + x); + case 0x92: // STA (ind) + addr = 0x100 * READ_LOW( uint8_t (data + 1) ); + addr += READ_LOW( data ); + pc++; + goto sta_ptr; + + case 0x99: // STA abs,Y + data += y; + case 0x8D: // STA abs + addr = data + 0x100 * GET_MSB(); + pc += 2; + sta_ptr: + CPU_WRITE_FAST( this, addr, a, TIME ); + goto loop; + } + + { + fuint16 addr; + case 0xA1: // LDA (ind,X) + data = uint8_t (data + x); + case 0xB2: // LDA (ind) + addr = 0x100 * READ_LOW( uint8_t (data + 1) ); + addr += READ_LOW( data ); + pc++; + goto a_nz_read_addr; + + case 0xB1:// LDA (ind),Y + addr = READ_LOW( data ) + y; + PAGE_CROSS_PENALTY( addr ); + addr += 0x100 * READ_LOW( (uint8_t) (data + 1) ); + pc++; + goto a_nz_read_addr; + + case 0xB9: // LDA abs,Y + data += y; + PAGE_CROSS_PENALTY( data ); + case 0xAD: // LDA abs + addr = data + 0x100 * GET_MSB(); + pc += 2; + a_nz_read_addr: + CPU_READ_FAST( this, addr, TIME, nz ); + a = nz; + goto loop; + } + + case 0xBE:{// LDX abs,y + PAGE_CROSS_PENALTY( data + y ); + fuint16 addr = GET_ADDR() + y; + pc += 2; + FLUSH_TIME(); + x = nz = READ( addr ); + CACHE_TIME(); + goto loop; + } + + case 0xB5: // LDA zp,x + a = nz = READ_LOW( uint8_t (data + x) ); + pc++; + goto loop; + + case 0xA9: // LDA #imm + pc++; + a = data; + nz = data; + goto loop; + +// Bit operations + + case 0x3C: // BIT abs,x + data += x; + case 0x2C:{// BIT abs + fuint16 addr; + ADD_PAGE( addr ); + FLUSH_TIME(); + nz = READ( addr ); + CACHE_TIME(); + goto bit_common; + } + case 0x34: // BIT zp,x + data = uint8_t (data + x); + case 0x24: // BIT zp + data = READ_LOW( data ); + case 0x89: // BIT imm + nz = data; + bit_common: + pc++; + status &= ~st_v; + status |= nz & st_v; + if ( nz & a ) + goto loop; // Z should be clear, and nz must be non-zero if nz & a is + nz <<= 8; // set Z flag without affecting N flag + goto loop; + + { + fuint16 addr; + + case 0xB3: // TST abs,x + addr = GET_MSB() + x; + goto tst_abs; + + case 0x93: // TST abs + addr = GET_MSB(); + tst_abs: + addr += 0x100 * instr [2]; + pc++; + FLUSH_TIME(); + nz = READ( addr ); + CACHE_TIME(); + goto tst_common; + } + + case 0xA3: // TST zp,x + nz = READ_LOW( uint8_t (GET_MSB() + x) ); + goto tst_common; + + case 0x83: // TST zp + nz = READ_LOW( GET_MSB() ); + tst_common: + pc += 2; + status &= ~st_v; + status |= nz & st_v; + if ( nz & data ) + goto loop; // Z should be clear, and nz must be non-zero if nz & data is + nz <<= 8; // set Z flag without affecting N flag + goto loop; + + { + fuint16 addr; + case 0x0C: // TSB abs + case 0x1C: // TRB abs + addr = GET_ADDR(); + pc++; + goto txb_addr; + + // TODO: everyone lists different behaviors for the status flags, ugh + case 0x04: // TSB zp + case 0x14: // TRB zp + addr = data + ram_addr; + txb_addr: + FLUSH_TIME(); + nz = a | READ( addr ); + if ( opcode & 0x10 ) + nz ^= a; // bits from a will already be set, so this clears them + status &= ~st_v; + status |= nz & st_v; + pc++; + WRITE( addr, nz ); + CACHE_TIME(); + goto loop; + } + + case 0x07: // RMBn + case 0x17: + case 0x27: + case 0x37: + case 0x47: + case 0x57: + case 0x67: + case 0x77: + pc++; + READ_LOW( data ) &= ~(1 << (opcode >> 4)); + goto loop; + + case 0x87: // SMBn + case 0x97: + case 0xA7: + case 0xB7: + case 0xC7: + case 0xD7: + case 0xE7: + case 0xF7: + pc++; + READ_LOW( data ) |= 1 << ((opcode >> 4) - 8); + goto loop; + +// Load/store + + case 0x9E: // STZ abs,x + data += x; + case 0x9C: // STZ abs + ADD_PAGE( data ); + pc++; + FLUSH_TIME(); + WRITE( data, 0 ); + CACHE_TIME(); + goto loop; + + case 0x74: // STZ zp,x + data = uint8_t (data + x); + case 0x64: // STZ zp + pc++; + WRITE_LOW( data, 0 ); + goto loop; + + case 0x94: // STY zp,x + data = uint8_t (data + x); + case 0x84: // STY zp + pc++; + WRITE_LOW( data, y ); + goto loop; + + case 0x96: // STX zp,y + data = uint8_t (data + y); + case 0x86: // STX zp + pc++; + WRITE_LOW( data, x ); + goto loop; + + case 0xB6: // LDX zp,y + data = uint8_t (data + y); + case 0xA6: // LDX zp + data = READ_LOW( data ); + case 0xA2: // LDX #imm + pc++; + x = data; + nz = data; + goto loop; + + case 0xB4: // LDY zp,x + data = uint8_t (data + x); + case 0xA4: // LDY zp + data = READ_LOW( data ); + case 0xA0: // LDY #imm + pc++; + y = data; + nz = data; + goto loop; + + case 0xBC: // LDY abs,X + data += x; + PAGE_CROSS_PENALTY( data ); + case 0xAC:{// LDY abs + fuint16 addr = data + 0x100 * GET_MSB(); + pc += 2; + FLUSH_TIME(); + y = nz = READ( addr ); + CACHE_TIME(); + goto loop; + } + + { + fuint8 temp; + case 0x8C: // STY abs + temp = y; + goto store_abs; + + case 0x8E: // STX abs + temp = x; + store_abs: + fuint16 addr = GET_ADDR(); + pc += 2; + FLUSH_TIME(); + WRITE( addr, temp ); + CACHE_TIME(); + goto loop; + } + +// Compare + + case 0xEC:{// CPX abs + fuint16 addr = GET_ADDR(); + pc++; + FLUSH_TIME(); + data = READ( addr ); + CACHE_TIME(); + goto cpx_data; + } + + case 0xE4: // CPX zp + data = READ_LOW( data ); + case 0xE0: // CPX #imm + cpx_data: + nz = x - data; + pc++; + c = ~nz; + nz &= 0xFF; + goto loop; + + case 0xCC:{// CPY abs + fuint16 addr = GET_ADDR(); + pc++; + FLUSH_TIME(); + data = READ( addr ); + CACHE_TIME(); + goto cpy_data; + } + + case 0xC4: // CPY zp + data = READ_LOW( data ); + case 0xC0: // CPY #imm + cpy_data: + nz = y - data; + pc++; + c = ~nz; + nz &= 0xFF; + goto loop; + +// Logical + +#define ARITH_ADDR_MODES( op )\ + case op - 0x04: /* (ind,x) */\ + data = uint8_t (data + x);\ + case op + 0x0D: /* (ind) */\ + data = 0x100 * READ_LOW( uint8_t (data + 1) ) + READ_LOW( data );\ + goto ptr##op;\ + case op + 0x0C:{/* (ind),y */\ + fuint16 temp = READ_LOW( data ) + y;\ + PAGE_CROSS_PENALTY( temp );\ + data = temp + 0x100 * READ_LOW( uint8_t (data + 1) );\ + goto ptr##op;\ + }\ + case op + 0x10: /* zp,X */\ + data = uint8_t (data + x);\ + case op + 0x00: /* zp */\ + data = READ_LOW( data );\ + goto imm##op;\ + case op + 0x14: /* abs,Y */\ + data += y;\ + goto ind##op;\ + case op + 0x18: /* abs,X */\ + data += x;\ + ind##op:\ + PAGE_CROSS_PENALTY( data );\ + case op + 0x08: /* abs */\ + ADD_PAGE( data );\ + ptr##op:\ + FLUSH_TIME();\ + data = READ( data );\ + CACHE_TIME();\ + case op + 0x04: /* imm */\ + imm##op: + + ARITH_ADDR_MODES( 0xC5 ) // CMP + nz = a - data; + pc++; + c = ~nz; + nz &= 0xFF; + goto loop; + + ARITH_ADDR_MODES( 0x25 ) // AND + nz = (a &= data); + pc++; + goto loop; + + ARITH_ADDR_MODES( 0x45 ) // EOR + nz = (a ^= data); + pc++; + goto loop; + + ARITH_ADDR_MODES( 0x05 ) // ORA + nz = (a |= data); + pc++; + goto loop; + +// Add/subtract + + ARITH_ADDR_MODES( 0xE5 ) // SBC + data ^= 0xFF; + goto adc_imm; + + ARITH_ADDR_MODES( 0x65 ) // ADC + adc_imm: { + if ( status & st_d ) + debug_printf( "Decimal mode not supported\n" ); + fint16 carry = c >> 8 & 1; + fint16 ov = (a ^ 0x80) + carry + (BOOST::int8_t) data; // sign-extend + status &= ~st_v; + status |= ov >> 2 & 0x40; + c = nz = a + data + carry; + pc++; + a = (uint8_t) nz; + goto loop; + } + +// Shift/rotate + + case 0x4A: // LSR A + c = 0; + case 0x6A: // ROR A + nz = c >> 1 & 0x80; + c = a << 8; + nz |= a >> 1; + a = nz; + goto loop; + + case 0x0A: // ASL A + nz = a << 1; + c = nz; + a = (uint8_t) nz; + goto loop; + + case 0x2A: { // ROL A + nz = a << 1; + fint16 temp = c >> 8 & 1; + c = nz; + nz |= temp; + a = (uint8_t) nz; + goto loop; + } + + case 0x5E: // LSR abs,X + data += x; + case 0x4E: // LSR abs + c = 0; + case 0x6E: // ROR abs + ror_abs: { + ADD_PAGE( data ); + FLUSH_TIME(); + int temp = READ( data ); + nz = (c >> 1 & 0x80) | (temp >> 1); + c = temp << 8; + goto rotate_common; + } + + case 0x3E: // ROL abs,X + data += x; + goto rol_abs; + + case 0x1E: // ASL abs,X + data += x; + case 0x0E: // ASL abs + c = 0; + case 0x2E: // ROL abs + rol_abs: + ADD_PAGE( data ); + nz = c >> 8 & 1; + FLUSH_TIME(); + nz |= (c = READ( data ) << 1); + rotate_common: + pc++; + WRITE( data, (uint8_t) nz ); + CACHE_TIME(); + goto loop; + + case 0x7E: // ROR abs,X + data += x; + goto ror_abs; + + case 0x76: // ROR zp,x + data = uint8_t (data + x); + goto ror_zp; + + case 0x56: // LSR zp,x + data = uint8_t (data + x); + case 0x46: // LSR zp + c = 0; + case 0x66: // ROR zp + ror_zp: { + int temp = READ_LOW( data ); + nz = (c >> 1 & 0x80) | (temp >> 1); + c = temp << 8; + goto write_nz_zp; + } + + case 0x36: // ROL zp,x + data = uint8_t (data + x); + goto rol_zp; + + case 0x16: // ASL zp,x + data = uint8_t (data + x); + case 0x06: // ASL zp + c = 0; + case 0x26: // ROL zp + rol_zp: + nz = c >> 8 & 1; + nz |= (c = READ_LOW( data ) << 1); + goto write_nz_zp; + +// Increment/decrement + +#define INC_DEC_AXY( reg, n ) reg = uint8_t (nz = reg + n); goto loop; + + case 0x1A: // INA + INC_DEC_AXY( a, +1 ) + + case 0xE8: // INX + INC_DEC_AXY( x, +1 ) + + case 0xC8: // INY + INC_DEC_AXY( y, +1 ) + + case 0x3A: // DEA + INC_DEC_AXY( a, -1 ) + + case 0xCA: // DEX + INC_DEC_AXY( x, -1 ) + + case 0x88: // DEY + INC_DEC_AXY( y, -1 ) + + case 0xF6: // INC zp,x + data = uint8_t (data + x); + case 0xE6: // INC zp + nz = 1; + goto add_nz_zp; + + case 0xD6: // DEC zp,x + data = uint8_t (data + x); + case 0xC6: // DEC zp + nz = (unsigned) -1; + add_nz_zp: + nz += READ_LOW( data ); + write_nz_zp: + pc++; + WRITE_LOW( data, nz ); + goto loop; + + case 0xFE: // INC abs,x + data = x + GET_ADDR(); + goto inc_ptr; + + case 0xEE: // INC abs + data = GET_ADDR(); + inc_ptr: + nz = 1; + goto inc_common; + + case 0xDE: // DEC abs,x + data = x + GET_ADDR(); + goto dec_ptr; + + case 0xCE: // DEC abs + data = GET_ADDR(); + dec_ptr: + nz = (unsigned) -1; + inc_common: + FLUSH_TIME(); + nz += READ( data ); + pc += 2; + WRITE( data, (uint8_t) nz ); + CACHE_TIME(); + goto loop; + +// Transfer + + case 0xA8: // TAY + y = a; + nz = a; + goto loop; + + case 0x98: // TYA + a = y; + nz = y; + goto loop; + + case 0xAA: // TAX + x = a; + nz = a; + goto loop; + + case 0x8A: // TXA + a = x; + nz = x; + goto loop; + + case 0x9A: // TXS + SET_SP( x ); // verified (no flag change) + goto loop; + + case 0xBA: // TSX + x = nz = GET_SP(); + goto loop; + + #define SWAP_REGS( r1, r2 ) {\ + fuint8 t = r1;\ + r1 = r2;\ + r2 = t;\ + goto loop;\ + } + + case 0x02: // SXY + SWAP_REGS( x, y ); + + case 0x22: // SAX + SWAP_REGS( a, x ); + + case 0x42: // SAY + SWAP_REGS( a, y ); + + case 0x62: // CLA + a = 0; + goto loop; + + case 0x82: // CLX + x = 0; + goto loop; + + case 0xC2: // CLY + y = 0; + goto loop; + +// Stack + + case 0x48: // PHA + PUSH( a ); + goto loop; + + case 0xDA: // PHX + PUSH( x ); + goto loop; + + case 0x5A: // PHY + PUSH( y ); + goto loop; + + case 0x40:{// RTI + fuint8 temp = READ_LOW( sp ); + pc = READ_LOW( 0x100 | (sp - 0xFF) ); + pc |= READ_LOW( 0x100 | (sp - 0xFE) ) * 0x100; + sp = (sp - 0xFD) | 0x100; + data = status; + SET_STATUS( temp ); + this->r.status = status; // update externally-visible I flag + if ( (data ^ status) & st_i ) + { + hes_time_t new_time = end_time_; + if ( !(status & st_i) && new_time > irq_time_ ) + new_time = irq_time_; + blargg_long delta = s.base - new_time; + s.base = new_time; + s_time += delta; + } + goto loop; + } + + #define POP() READ_LOW( sp ); sp = (sp - 0xFF) | 0x100 + + case 0x68: // PLA + a = nz = POP(); + goto loop; + + case 0xFA: // PLX + x = nz = POP(); + goto loop; + + case 0x7A: // PLY + y = nz = POP(); + goto loop; + + case 0x28:{// PLP + fuint8 temp = POP(); + fuint8 changed = status ^ temp; + SET_STATUS( temp ); + if ( !(changed & st_i) ) + goto loop; // I flag didn't change + if ( status & st_i ) + goto handle_sei; + goto handle_cli; + } + #undef POP + + case 0x08: { // PHP + fuint8 temp; + CALC_STATUS( temp ); + PUSH( temp | st_b ); + goto loop; + } + +// Flags + + case 0x38: // SEC + c = (unsigned) ~0; + goto loop; + + case 0x18: // CLC + c = 0; + goto loop; + + case 0xB8: // CLV + status &= ~st_v; + goto loop; + + case 0xD8: // CLD + status &= ~st_d; + goto loop; + + case 0xF8: // SED + status |= st_d; + goto loop; + + case 0x58: // CLI + if ( !(status & st_i) ) + goto loop; + status &= ~st_i; + handle_cli: { + this->r.status = status; // update externally-visible I flag + blargg_long delta = s.base - irq_time_; + if ( delta <= 0 ) + { + if ( TIME < irq_time_ ) + goto loop; + goto delayed_cli; + } + s.base = irq_time_; + s_time += delta; + if ( s_time < 0 ) + goto loop; + + if ( delta >= s_time + 1 ) + { + // delayed irq until after next instruction + s.base += s_time + 1; + s_time = -1; + irq_time_ = s.base; // TODO: remove, as only to satisfy debug check in loop + goto loop; + } + delayed_cli: + debug_printf( "Delayed CLI not supported\n" ); // TODO: implement + goto loop; + } + + case 0x78: // SEI + if ( status & st_i ) + goto loop; + status |= st_i; + handle_sei: { + this->r.status = status; // update externally-visible I flag + blargg_long delta = s.base - end_time_; + s.base = end_time_; + s_time += delta; + if ( s_time < 0 ) + goto loop; + debug_printf( "Delayed SEI not supported\n" ); // TODO: implement + goto loop; + } + +// Special + + case 0x53:{// TAM + fuint8 const bits = data; // avoid using data across function call + pc++; + for ( int i = 0; i < 8; i++ ) + if ( bits & (1 << i) ) + set_mmr( i, a ); + goto loop; + } + + case 0x43:{// TMA + pc++; + byte const* in = mmr; + do + { + if ( data & 1 ) + a = *in; + in++; + } + while ( (data >>= 1) != 0 ); + goto loop; + } + + case 0x03: // ST0 + case 0x13: // ST1 + case 0x23:{// ST2 + fuint16 addr = opcode >> 4; + if ( addr ) + addr++; + pc++; + FLUSH_TIME(); + CPU_WRITE_VDP( this, addr, data, TIME ); + CACHE_TIME(); + goto loop; + } + + case 0xEA: // NOP + goto loop; + + case 0x54: // CSL + debug_printf( "CSL not supported\n" ); + illegal_encountered = true; + goto loop; + + case 0xD4: // CSH + goto loop; + + case 0xF4: { // SET + //fuint16 operand = GET_MSB(); + debug_printf( "SET not handled\n" ); + //switch ( data ) + //{ + //} + illegal_encountered = true; + goto loop; + } + +// Block transfer + + { + fuint16 in_alt; + fint16 in_inc; + fuint16 out_alt; + fint16 out_inc; + + case 0xE3: // TIA + in_alt = 0; + goto bxfer_alt; + + case 0xF3: // TAI + in_alt = 1; + bxfer_alt: + in_inc = in_alt ^ 1; + out_alt = in_inc; + out_inc = in_alt; + goto bxfer; + + case 0xD3: // TIN + in_inc = 1; + out_inc = 0; + goto bxfer_no_alt; + + case 0xC3: // TDD + in_inc = -1; + out_inc = -1; + goto bxfer_no_alt; + + case 0x73: // TII + in_inc = 1; + out_inc = 1; + bxfer_no_alt: + in_alt = 0; + out_alt = 0; + bxfer: + fuint16 in = GET_LE16( instr + 0 ); + fuint16 out = GET_LE16( instr + 2 ); + int count = GET_LE16( instr + 4 ); + if ( !count ) + count = 0x10000; + pc += 6; + WRITE_LOW( 0x100 | (sp - 1), y ); + WRITE_LOW( 0x100 | (sp - 2), a ); + WRITE_LOW( 0x100 | (sp - 3), x ); + FLUSH_TIME(); + do + { + // TODO: reads from $0800-$1400 in I/O page return 0 and don't access I/O + fuint8 t = READ( in ); + in += in_inc; + in &= 0xFFFF; + s.time += 6; + if ( in_alt ) + in_inc = -in_inc; + WRITE( out, t ); + out += out_inc; + out &= 0xFFFF; + if ( out_alt ) + out_inc = -out_inc; + } + while ( --count ); + CACHE_TIME(); + goto loop; + } + +// Illegal + + default: + assert( (unsigned) opcode <= 0xFF ); + debug_printf( "Illegal opcode $%02X at $%04X\n", (int) opcode, (int) pc - 1 ); + illegal_encountered = true; + goto loop; + } + assert( false ); + + int result_; +handle_brk: + pc++; + result_ = 6; + +interrupt: + { + s_time += 7; + + WRITE_LOW( 0x100 | (sp - 1), pc >> 8 ); + WRITE_LOW( 0x100 | (sp - 2), pc ); + pc = GET_LE16( &READ_PROG( 0xFFF0 ) + result_ ); + + sp = (sp - 3) | 0x100; + fuint8 temp; + CALC_STATUS( temp ); + if ( result_ == 6 ) + temp |= st_b; + WRITE_LOW( sp, temp ); + + status &= ~st_d; + status |= st_i; + this->r.status = status; // update externally-visible I flag + + blargg_long delta = s.base - end_time_; + s.base = end_time_; + s_time += delta; + goto loop; + } + +idle_done: + s_time = 0; +out_of_time: + pc--; + FLUSH_TIME(); + CPU_DONE( this, TIME, result_ ); + CACHE_TIME(); + if ( result_ > 0 ) + goto interrupt; + if ( s_time < 0 ) + goto loop; + + s.time = s_time; + + r.pc = pc; + r.sp = GET_SP(); + r.a = a; + r.x = x; + r.y = y; + + { + fuint8 temp; + CALC_STATUS( temp ); + r.status = temp; + } + + this->state_ = s; + this->state = &this->state_; + + return illegal_encountered; +} + diff --git a/libs/gme/gme/Hes_Cpu.h b/libs/gme/gme/Hes_Cpu.h new file mode 100644 index 000000000..d46a0b8a8 --- /dev/null +++ b/libs/gme/gme/Hes_Cpu.h @@ -0,0 +1,124 @@ +// PC Engine CPU emulator for use with HES music files + +// Game_Music_Emu 0.6.0 +#ifndef HES_CPU_H +#define HES_CPU_H + +#include "blargg_common.h" + +typedef blargg_long hes_time_t; // clock cycle count +typedef unsigned hes_addr_t; // 16-bit address +enum { future_hes_time = INT_MAX / 2 + 1 }; + +class Hes_Cpu { +public: + typedef BOOST::uint8_t uint8_t; + + void reset(); + + enum { page_size = 0x2000 }; + enum { page_shift = 13 }; + enum { page_count = 8 }; + void set_mmr( int reg, int bank ); + + uint8_t const* get_code( hes_addr_t ); + + uint8_t ram [page_size]; + + // not kept updated during a call to run() + struct registers_t { + BOOST::uint16_t pc; + uint8_t a; + uint8_t x; + uint8_t y; + uint8_t status; + uint8_t sp; + }; + registers_t r; + + // page mapping registers + uint8_t mmr [page_count + 1]; + + // Set end_time and run CPU from current time. Returns true if any illegal + // instructions were encountered. + bool run( hes_time_t end_time ); + + // Time of beginning of next instruction to be executed + hes_time_t time() const { return state->time + state->base; } + void set_time( hes_time_t t ) { state->time = t - state->base; } + void adjust_time( int delta ) { state->time += delta; } + + hes_time_t irq_time() const { return irq_time_; } + void set_irq_time( hes_time_t ); + + hes_time_t end_time() const { return end_time_; } + void set_end_time( hes_time_t ); + + void end_frame( hes_time_t ); + + // Attempt to execute instruction here results in CPU advancing time to + // lesser of irq_time() and end_time() (or end_time() if IRQs are + // disabled) + enum { idle_addr = 0x1FFF }; + + // Can read this many bytes past end of a page + enum { cpu_padding = 8 }; + +public: + Hes_Cpu() { state = &state_; } + enum { irq_inhibit = 0x04 }; +private: + // noncopyable + Hes_Cpu( const Hes_Cpu& ); + Hes_Cpu& operator = ( const Hes_Cpu& ); + + struct state_t { + uint8_t const* code_map [page_count + 1]; + hes_time_t base; + blargg_long time; + }; + state_t* state; // points to state_ or a local copy within run() + state_t state_; + hes_time_t irq_time_; + hes_time_t end_time_; + + void set_code_page( int, void const* ); + inline int update_end_time( hes_time_t end, hes_time_t irq ); +}; + +inline BOOST::uint8_t const* Hes_Cpu::get_code( hes_addr_t addr ) +{ + return state->code_map [addr >> page_shift] + addr + #if !BLARGG_NONPORTABLE + % (unsigned) page_size + #endif + ; +} + +inline int Hes_Cpu::update_end_time( hes_time_t t, hes_time_t irq ) +{ + if ( irq < t && !(r.status & irq_inhibit) ) t = irq; + int delta = state->base - t; + state->base = t; + return delta; +} + +inline void Hes_Cpu::set_irq_time( hes_time_t t ) +{ + state->time += update_end_time( end_time_, (irq_time_ = t) ); +} + +inline void Hes_Cpu::set_end_time( hes_time_t t ) +{ + state->time += update_end_time( (end_time_ = t), irq_time_ ); +} + +inline void Hes_Cpu::end_frame( hes_time_t t ) +{ + assert( state == &state_ ); + state_.base -= t; + if ( irq_time_ < future_hes_time ) irq_time_ -= t; + if ( end_time_ < future_hes_time ) end_time_ -= t; +} + +#endif diff --git a/libs/gme/gme/Hes_Emu.cpp b/libs/gme/gme/Hes_Emu.cpp new file mode 100644 index 000000000..e3c700dbc --- /dev/null +++ b/libs/gme/gme/Hes_Emu.cpp @@ -0,0 +1,531 @@ +// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/ + +#include "Hes_Emu.h" + +#include "blargg_endian.h" +#include + +/* Copyright (C) 2006 Shay Green. This module 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 +module 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 module; if not, write to the Free Software Foundation, +Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + +#include "blargg_source.h" + +int const timer_mask = 0x04; +int const vdp_mask = 0x02; +int const i_flag_mask = 0x04; +int const unmapped = 0xFF; + +long const period_60hz = 262 * 455L; // scanlines * clocks per scanline + +Hes_Emu::Hes_Emu() +{ + timer.raw_load = 0; + set_type( gme_hes_type ); + + static const char* const names [Hes_Apu::osc_count] = { + "Wave 1", "Wave 2", "Wave 3", "Wave 4", "Multi 1", "Multi 2" + }; + set_voice_names( names ); + + static int const types [Hes_Apu::osc_count] = { + wave_type | 0, wave_type | 1, wave_type | 2, wave_type | 3, + mixed_type | 0, mixed_type | 1 + }; + set_voice_types( types ); + set_silence_lookahead( 6 ); + set_gain( 1.11 ); +} + +Hes_Emu::~Hes_Emu() { } + +void Hes_Emu::unload() +{ + rom.clear(); + Music_Emu::unload(); +} + +// Track info + +static byte const* copy_field( byte const* in, char* out ) +{ + if ( in ) + { + int len = 0x20; + if ( in [0x1F] && !in [0x2F] ) + len = 0x30; // fields are sometimes 16 bytes longer (ugh) + + // since text fields are where any data could be, detect non-text + // and fields with data after zero byte terminator + + int i = 0; + for ( i = 0; i < len && in [i]; i++ ) + if ( ((in [i] + 1) & 0xFF) < ' ' + 1 ) // also treat 0xFF as non-text + return 0; // non-ASCII found + + for ( ; i < len; i++ ) + if ( in [i] ) + return 0; // data after terminator + + Gme_File::copy_field_( out, (char const*) in, len ); + in += len; + } + return in; +} + +static void copy_hes_fields( byte const* in, track_info_t* out ) +{ + if ( *in >= ' ' ) + { + in = copy_field( in, out->game ); + in = copy_field( in, out->author ); + in = copy_field( in, out->copyright ); + } +} + +blargg_err_t Hes_Emu::track_info_( track_info_t* out, int ) const +{ + copy_hes_fields( rom.begin() + 0x20, out ); + return 0; +} + +static blargg_err_t check_hes_header( void const* header ) +{ + if ( memcmp( header, "HESM", 4 ) ) + return gme_wrong_file_type; + return 0; +} + +struct Hes_File : Gme_Info_ +{ + struct header_t { + char header [Hes_Emu::header_size]; + char unused [0x20]; + byte fields [0x30 * 3]; + } h; + + Hes_File() { set_type( gme_hes_type ); } + + blargg_err_t load_( Data_Reader& in ) + { + assert( offsetof (header_t,fields) == Hes_Emu::header_size + 0x20 ); + blargg_err_t err = in.read( &h, sizeof h ); + if ( err ) + return (err == in.eof_error ? gme_wrong_file_type : err); + return check_hes_header( &h ); + } + + blargg_err_t track_info_( track_info_t* out, int ) const + { + copy_hes_fields( h.fields, out ); + return 0; + } +}; + +static Music_Emu* new_hes_emu () { return BLARGG_NEW Hes_Emu ; } +static Music_Emu* new_hes_file() { return BLARGG_NEW Hes_File; } + +static gme_type_t_ const gme_hes_type_ = { "PC Engine", 256, &new_hes_emu, &new_hes_file, "HES", 1 }; +gme_type_t const gme_hes_type = &gme_hes_type_; + + +// Setup + +blargg_err_t Hes_Emu::load_( Data_Reader& in ) +{ + assert( offsetof (header_t,unused [4]) == header_size ); + RETURN_ERR( rom.load( in, header_size, &header_, unmapped ) ); + + RETURN_ERR( check_hes_header( header_.tag ) ); + + if ( header_.vers != 0 ) + set_warning( "Unknown file version" ); + + if ( memcmp( header_.data_tag, "DATA", 4 ) ) + set_warning( "Data header missing" ); + + if ( memcmp( header_.unused, "\0\0\0\0", 4 ) ) + set_warning( "Unknown header data" ); + + // File spec supports multiple blocks, but I haven't found any, and + // many files have bad sizes in the only block, so it's simpler to + // just try to load the damn data as best as possible. + + long addr = get_le32( header_.addr ); + long size = get_le32( header_.size ); + long const rom_max = 0x100000; + if ( addr & ~(rom_max - 1) ) + { + set_warning( "Invalid address" ); + addr &= rom_max - 1; + } + if ( (unsigned long) (addr + size) > (unsigned long) rom_max ) + set_warning( "Invalid size" ); + + if ( size != rom.file_size() ) + { + if ( size <= rom.file_size() - 4 && !memcmp( rom.begin() + size, "DATA", 4 ) ) + set_warning( "Multiple DATA not supported" ); + else if ( size < rom.file_size() ) + set_warning( "Extra file data" ); + else + set_warning( "Missing file data" ); + } + + rom.set_addr( addr ); + + set_voice_count( apu.osc_count ); + + apu.volume( gain() ); + + return setup_buffer( 7159091 ); +} + +void Hes_Emu::update_eq( blip_eq_t const& eq ) +{ + apu.treble_eq( eq ); +} + +void Hes_Emu::set_voice( int i, Blip_Buffer* center, Blip_Buffer* left, Blip_Buffer* right ) +{ + apu.osc_output( i, center, left, right ); +} + +// Emulation + +void Hes_Emu::recalc_timer_load() +{ + timer.load = timer.raw_load * timer_base + 1; +} + +void Hes_Emu::set_tempo_( double t ) +{ + play_period = hes_time_t (period_60hz / t); + timer_base = int (1024 / t); + recalc_timer_load(); +} + +blargg_err_t Hes_Emu::start_track_( int track ) +{ + RETURN_ERR( Classic_Emu::start_track_( track ) ); + + memset( ram, 0, sizeof ram ); // some HES music relies on zero fill + memset( sgx, 0, sizeof sgx ); + + apu.reset(); + cpu::reset(); + + for ( unsigned i = 0; i < sizeof header_.banks; i++ ) + set_mmr( i, header_.banks [i] ); + set_mmr( page_count, 0xFF ); // unmapped beyond end of address space + + irq.disables = timer_mask | vdp_mask; + irq.timer = future_hes_time; + irq.vdp = future_hes_time; + + timer.enabled = false; + timer.raw_load= 0x80; + timer.count = timer.load; + timer.fired = false; + timer.last_time = 0; + + vdp.latch = 0; + vdp.control = 0; + vdp.next_vbl = 0; + + ram [0x1FF] = (idle_addr - 1) >> 8; + ram [0x1FE] = (idle_addr - 1) & 0xFF; + r.sp = 0xFD; + r.pc = get_le16( header_.init_addr ); + r.a = track; + + recalc_timer_load(); + last_frame_hook = 0; + + return 0; +} + +// Hardware + +void Hes_Emu::cpu_write_vdp( int addr, int data ) +{ + switch ( addr ) + { + case 0: + vdp.latch = data & 0x1F; + break; + + case 2: + if ( vdp.latch == 5 ) + { + if ( data & 0x04 ) + set_warning( "Scanline interrupt unsupported" ); + run_until( time() ); + vdp.control = data; + irq_changed(); + } + else + { + debug_printf( "VDP not supported: $%02X <- $%02X\n", vdp.latch, data ); + } + break; + + case 3: + debug_printf( "VDP MSB not supported: $%02X <- $%02X\n", vdp.latch, data ); + break; + } +} + +void Hes_Emu::cpu_write_( hes_addr_t addr, int data ) +{ + if ( unsigned (addr - apu.start_addr) <= apu.end_addr - apu.start_addr ) + { + GME_APU_HOOK( this, addr - apu.start_addr, data ); + // avoid going way past end when a long block xfer is writing to I/O space + hes_time_t t = min( time(), end_time() + 8 ); + apu.write_data( t, addr, data ); + return; + } + + hes_time_t time = this->time(); + switch ( addr ) + { + case 0x0000: + case 0x0002: + case 0x0003: + cpu_write_vdp( addr, data ); + return; + + case 0x0C00: { + run_until( time ); + timer.raw_load = (data & 0x7F) + 1; + recalc_timer_load(); + timer.count = timer.load; + break; + } + + case 0x0C01: + data &= 1; + if ( timer.enabled == data ) + return; + run_until( time ); + timer.enabled = data; + if ( data ) + timer.count = timer.load; + break; + + case 0x1402: + run_until( time ); + irq.disables = data; + if ( (data & 0xF8) && (data & 0xF8) != 0xF8 ) // flag questionable values + debug_printf( "Int mask: $%02X\n", data ); + break; + + case 0x1403: + run_until( time ); + if ( timer.enabled ) + timer.count = timer.load; + timer.fired = false; + break; + +#ifndef NDEBUG + case 0x1000: // I/O port + case 0x0402: // palette + case 0x0403: + case 0x0404: + case 0x0405: + return; + + default: + debug_printf( "unmapped write $%04X <- $%02X\n", addr, data ); + return; +#endif + } + + irq_changed(); +} + +int Hes_Emu::cpu_read_( hes_addr_t addr ) +{ + hes_time_t time = this->time(); + addr &= page_size - 1; + switch ( addr ) + { + case 0x0000: + if ( irq.vdp > time ) + return 0; + irq.vdp = future_hes_time; + run_until( time ); + irq_changed(); + return 0x20; + + case 0x0002: + case 0x0003: + debug_printf( "VDP read not supported: %d\n", addr ); + return 0; + + case 0x0C01: + //return timer.enabled; // TODO: remove? + case 0x0C00: + run_until( time ); + debug_printf( "Timer count read\n" ); + return (unsigned) (timer.count - 1) / timer_base; + + case 0x1402: + return irq.disables; + + case 0x1403: + { + int status = 0; + if ( irq.timer <= time ) status |= timer_mask; + if ( irq.vdp <= time ) status |= vdp_mask; + return status; + } + + #ifndef NDEBUG + case 0x1000: // I/O port + case 0x180C: // CD-ROM + case 0x180D: + break; + + default: + debug_printf( "unmapped read $%04X\n", addr ); + #endif + } + + return unmapped; +} + +// see hes_cpu_io.h for core read/write functions + +// Emulation + +void Hes_Emu::run_until( hes_time_t present ) +{ + while ( vdp.next_vbl < present ) + vdp.next_vbl += play_period; + + hes_time_t elapsed = present - timer.last_time; + if ( elapsed > 0 ) + { + if ( timer.enabled ) + { + timer.count -= elapsed; + if ( timer.count <= 0 ) + timer.count += timer.load; + } + timer.last_time = present; + } +} + +void Hes_Emu::irq_changed() +{ + hes_time_t present = time(); + + if ( irq.timer > present ) + { + irq.timer = future_hes_time; + if ( timer.enabled && !timer.fired ) + irq.timer = present + timer.count; + } + + if ( irq.vdp > present ) + { + irq.vdp = future_hes_time; + if ( vdp.control & 0x08 ) + irq.vdp = vdp.next_vbl; + } + + hes_time_t time = future_hes_time; + if ( !(irq.disables & timer_mask) ) time = irq.timer; + if ( !(irq.disables & vdp_mask) ) time = min( time, irq.vdp ); + + set_irq_time( time ); +} + +int Hes_Emu::cpu_done() +{ + check( time() >= end_time() || + (!(r.status & i_flag_mask) && time() >= irq_time()) ); + + if ( !(r.status & i_flag_mask) ) + { + hes_time_t present = time(); + + if ( irq.timer <= present && !(irq.disables & timer_mask) ) + { + timer.fired = true; + irq.timer = future_hes_time; + irq_changed(); // overkill, but not worth writing custom code + #if GME_FRAME_HOOK_DEFINED + { + unsigned const threshold = period_60hz / 30; + unsigned long elapsed = present - last_frame_hook; + if ( elapsed - period_60hz + threshold / 2 < threshold ) + { + last_frame_hook = present; + GME_FRAME_HOOK( this ); + } + } + #endif + return 0x0A; + } + + if ( irq.vdp <= present && !(irq.disables & vdp_mask) ) + { + // work around for bugs with music not acknowledging VDP + //run_until( present ); + //irq.vdp = future_hes_time; + //irq_changed(); + #if GME_FRAME_HOOK_DEFINED + last_frame_hook = present; + GME_FRAME_HOOK( this ); + #endif + return 0x08; + } + } + return 0; +} + +static void adjust_time( blargg_long& time, hes_time_t delta ) +{ + if ( time < future_hes_time ) + { + time -= delta; + if ( time < 0 ) + time = 0; + } +} + +blargg_err_t Hes_Emu::run_clocks( blip_time_t& duration_, int ) +{ + blip_time_t const duration = duration_; // cache + + if ( cpu::run( duration ) ) + set_warning( "Emulation error (illegal instruction)" ); + + check( time() >= duration ); + //check( time() - duration < 20 ); // Txx instruction could cause going way over + + run_until( duration ); + + // end time frame + timer.last_time -= duration; + vdp.next_vbl -= duration; + #if GME_FRAME_HOOK_DEFINED + last_frame_hook -= duration; + #endif + cpu::end_frame( duration ); + ::adjust_time( irq.timer, duration ); + ::adjust_time( irq.vdp, duration ); + apu.end_frame( duration ); + + return 0; +} diff --git a/libs/gme/gme/Hes_Emu.h b/libs/gme/gme/Hes_Emu.h new file mode 100644 index 000000000..b4e20fd67 --- /dev/null +++ b/libs/gme/gme/Hes_Emu.h @@ -0,0 +1,94 @@ +// TurboGrafx-16/PC Engine HES music file emulator + +// Game_Music_Emu 0.6.0 +#ifndef HES_EMU_H +#define HES_EMU_H + +#include "Classic_Emu.h" +#include "Hes_Apu.h" +#include "Hes_Cpu.h" + +class Hes_Emu : private Hes_Cpu, public Classic_Emu { + typedef Hes_Cpu cpu; +public: + // HES file header + enum { header_size = 0x20 }; + struct header_t + { + byte tag [4]; + byte vers; + byte first_track; + byte init_addr [2]; + byte banks [8]; + byte data_tag [4]; + byte size [4]; + byte addr [4]; + byte unused [4]; + }; + + // Header for currently loaded file + header_t const& header() const { return header_; } + + static gme_type_t static_type() { return gme_hes_type; } + +public: + Hes_Emu(); + ~Hes_Emu(); +protected: + blargg_err_t track_info_( track_info_t*, int track ) const; + blargg_err_t load_( Data_Reader& ); + blargg_err_t start_track_( int ); + blargg_err_t run_clocks( blip_time_t&, int ); + void set_tempo_( double ); + void set_voice( int, Blip_Buffer*, Blip_Buffer*, Blip_Buffer* ); + void update_eq( blip_eq_t const& ); + void unload(); +public: private: friend class Hes_Cpu; + byte* write_pages [page_count + 1]; // 0 if unmapped or I/O space + + int cpu_read_( hes_addr_t ); + int cpu_read( hes_addr_t ); + void cpu_write_( hes_addr_t, int data ); + void cpu_write( hes_addr_t, int ); + void cpu_write_vdp( int addr, int data ); + byte const* cpu_set_mmr( int page, int bank ); + int cpu_done(); +private: + Rom_Data rom; + header_t header_; + hes_time_t play_period; + hes_time_t last_frame_hook; + int timer_base; + + struct { + hes_time_t last_time; + blargg_long count; + blargg_long load; + int raw_load; + byte enabled; + byte fired; + } timer; + + struct { + hes_time_t next_vbl; + byte latch; + byte control; + } vdp; + + struct { + hes_time_t timer; + hes_time_t vdp; + byte disables; + } irq; + + void recalc_timer_load(); + + // large items + Hes_Apu apu; + byte sgx [3 * page_size + cpu_padding]; + + void irq_changed(); + void run_until( hes_time_t ); +}; + +#endif diff --git a/libs/gme/gme/Kss_Cpu.cpp b/libs/gme/gme/Kss_Cpu.cpp new file mode 100644 index 000000000..a2068efc4 --- /dev/null +++ b/libs/gme/gme/Kss_Cpu.cpp @@ -0,0 +1,1707 @@ +// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/ + +/* +Last validated with zexall 2006.11.14 2:19 PM +* Doesn't implement the R register or immediate interrupt after EI. +* Address wrap-around isn't completely correct, but is prevented from crashing emulator. +*/ + +#include "Kss_Cpu.h" + +#include "blargg_endian.h" +#include + +//#include "z80_cpu_log.h" + +/* Copyright (C) 2006 Shay Green. This module 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 +module 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 module; if not, write to the Free Software Foundation, +Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + +#define SYNC_TIME() (void) (s.time = s_time) +#define RELOAD_TIME() (void) (s_time = s.time) + +// Callbacks to emulator + +#define CPU_OUT( cpu, addr, data, time )\ + kss_cpu_out( this, time, addr, data ) + +#define CPU_IN( cpu, addr, time )\ + kss_cpu_in( this, time, addr ) + +#define CPU_WRITE( cpu, addr, data, time )\ + (SYNC_TIME(), kss_cpu_write( this, addr, data )) + +#include "blargg_source.h" + +// flags, named with hex value for clarity +int const S80 = 0x80; +int const Z40 = 0x40; +int const F20 = 0x20; +int const H10 = 0x10; +int const F08 = 0x08; +int const V04 = 0x04; +int const P04 = 0x04; +int const N02 = 0x02; +int const C01 = 0x01; + +#define SZ28P( n ) szpc [n] +#define SZ28PC( n ) szpc [n] +#define SZ28C( n ) (szpc [n] & ~P04) +#define SZ28( n ) SZ28C( n ) + +#define SET_R( n ) (void) (r.r = n) +#define GET_R() (r.r) + +Kss_Cpu::Kss_Cpu() +{ + state = &state_; + + for ( int i = 0x100; --i >= 0; ) + { + int even = 1; + for ( int p = i; p; p >>= 1 ) + even ^= p; + int n = (i & (S80 | F20 | F08)) | ((even & 1) * P04); + szpc [i] = n; + szpc [i + 0x100] = n | C01; + } + szpc [0x000] |= Z40; + szpc [0x100] |= Z40; +} + +inline void Kss_Cpu::set_page( int i, void* write, void const* read ) +{ + blargg_long offset = KSS_CPU_PAGE_OFFSET( i * (blargg_long) page_size ); + state->write [i] = (byte *) write - offset; + state->read [i] = (byte const*) read - offset; +} + +void Kss_Cpu::reset( void* unmapped_write, void const* unmapped_read ) +{ + check( state == &state_ ); + state = &state_; + state_.time = 0; + state_.base = 0; + end_time_ = 0; + + for ( int i = 0; i < page_count + 1; i++ ) + set_page( i, unmapped_write, unmapped_read ); + + memset( &r, 0, sizeof r ); +} + +void Kss_Cpu::map_mem( unsigned addr, blargg_ulong size, void* write, void const* read ) +{ + // address range must begin and end on page boundaries + require( addr % page_size == 0 ); + require( size % page_size == 0 ); + + unsigned first_page = addr / page_size; + for ( unsigned i = size / page_size; i--; ) + { + blargg_long offset = i * (blargg_long) page_size; + set_page( first_page + i, (byte*) write + offset, (byte const*) read + offset ); + } +} + +#define TIME (s_time + s.base) +#define RW_MEM( addr, rw ) (s.rw [(addr) >> page_shift] [KSS_CPU_PAGE_OFFSET( addr )]) +#define READ_PROG( addr ) RW_MEM( addr, read ) +#define READ( addr ) READ_PROG( addr ) +//#define WRITE( addr, data ) (void) (RW_MEM( addr, write ) = data) +#define WRITE( addr, data ) CPU_WRITE( this, addr, data, TIME ) +#define READ_WORD( addr ) GET_LE16( &READ( addr ) ) +#define WRITE_WORD( addr, data ) SET_LE16( &RW_MEM( addr, write ), data ) +#define IN( addr ) CPU_IN( this, addr, TIME ) +#define OUT( addr, data ) CPU_OUT( this, addr, data, TIME ) + +#if BLARGG_BIG_ENDIAN + #define R8( n, offset ) ((r8_ - offset) [n]) +#elif BLARGG_LITTLE_ENDIAN + #define R8( n, offset ) ((r8_ - offset) [(n) ^ 1]) +#else + #error "Byte order of CPU must be known" +#endif + +//#define R16( n, shift, offset ) (r16_ [((n) >> shift) - (offset >> shift)]) + +// help compiler see that it can just adjust stack offset, saving an extra instruction +#define R16( n, shift, offset )\ + (*(uint16_t*) ((char*) r16_ - (offset >> (shift - 1)) + ((n) >> (shift - 1)))) + +#define CASE5( a, b, c, d, e ) case 0x##a:case 0x##b:case 0x##c:case 0x##d:case 0x##e +#define CASE6( a, b, c, d, e, f ) CASE5( a, b, c, d, e ): case 0x##f +#define CASE7( a, b, c, d, e, f, g ) CASE6( a, b, c, d, e, f ): case 0x##g +#define CASE8( a, b, c, d, e, f, g, h ) CASE7( a, b, c, d, e, f, g ): case 0x##h + +// high four bits are $ED time - 8, low four bits are $DD/$FD time - 8 +static byte const ed_dd_timing [0x100] = { +//0 1 2 3 4 5 6 7 8 9 A B C D E F +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x06,0x0C,0x02,0x00,0x00,0x03,0x00,0x00,0x07,0x0C,0x02,0x00,0x00,0x03,0x00, +0x00,0x00,0x00,0x00,0x0F,0x0F,0x0B,0x00,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00, +0x40,0x40,0x70,0xC0,0x00,0x60,0x0B,0x10,0x40,0x40,0x70,0xC0,0x00,0x60,0x0B,0x10, +0x40,0x40,0x70,0xC0,0x00,0x60,0x0B,0x10,0x40,0x40,0x70,0xC0,0x00,0x60,0x0B,0x10, +0x40,0x40,0x70,0xC0,0x00,0x60,0x0B,0xA0,0x40,0x40,0x70,0xC0,0x00,0x60,0x0B,0xA0, +0x4B,0x4B,0x7B,0xCB,0x0B,0x6B,0x00,0x0B,0x40,0x40,0x70,0xC0,0x00,0x60,0x0B,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x0B,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0B,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x0B,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0B,0x00, +0x80,0x80,0x80,0x80,0x00,0x00,0x0B,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x0B,0x00, +0xD0,0xD0,0xD0,0xD0,0x00,0x00,0x0B,0x00,0xD0,0xD0,0xD0,0xD0,0x00,0x00,0x0B,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x06,0x00,0x0F,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00, +}; + +// even on x86, using short and unsigned char was slower +typedef int fint16; +typedef unsigned fuint16; +typedef unsigned fuint8; + +bool Kss_Cpu::run( cpu_time_t end_time ) +{ + set_end_time( end_time ); + state_t s = this->state_; + this->state = &s; + bool warning = false; + + typedef BOOST::int8_t int8_t; + + union { + regs_t rg; + pairs_t rp; + uint8_t r8_ [8]; // indexed + uint16_t r16_ [4]; + }; + rg = this->r.b; + + cpu_time_t s_time = s.time; + fuint16 pc = r.pc; + fuint16 sp = r.sp; + fuint16 ix = r.ix; // TODO: keep in memory for direct access? + fuint16 iy = r.iy; + int flags = r.b.flags; + + goto loop; +jr_not_taken: + s_time -= 5; + goto loop; +call_not_taken: + s_time -= 7; +jp_not_taken: + pc += 2; +loop: + + check( (unsigned long) pc < 0x10000 ); + check( (unsigned long) sp < 0x10000 ); + check( (unsigned) flags < 0x100 ); + check( (unsigned) ix < 0x10000 ); + check( (unsigned) iy < 0x10000 ); + + uint8_t const* instr = s.read [pc >> page_shift]; +#define GET_ADDR() GET_LE16( instr ) + + fuint8 opcode; + + // TODO: eliminate this special case + #if BLARGG_NONPORTABLE + opcode = instr [pc]; + pc++; + instr += pc; + #else + instr += KSS_CPU_PAGE_OFFSET( pc ); + opcode = *instr++; + pc++; + #endif + + static byte const base_timing [0x100] = { + // 0 1 2 3 4 5 6 7 8 9 A B C D E F + 4,10, 7, 6, 4, 4, 7, 4, 4,11, 7, 6, 4, 4, 7, 4, // 0 + 13,10, 7, 6, 4, 4, 7, 4,12,11, 7, 6, 4, 4, 7, 4, // 1 + 12,10,16, 6, 4, 4, 7, 4,12,11,16, 6, 4, 4, 7, 4, // 2 + 12,10,13, 6,11,11,10, 4,12,11,13, 6, 4, 4, 7, 4, // 3 + 4, 4, 4, 4, 4, 4, 7, 4, 4, 4, 4, 4, 4, 4, 7, 4, // 4 + 4, 4, 4, 4, 4, 4, 7, 4, 4, 4, 4, 4, 4, 4, 7, 4, // 5 + 4, 4, 4, 4, 4, 4, 7, 4, 4, 4, 4, 4, 4, 4, 7, 4, // 6 + 7, 7, 7, 7, 7, 7, 4, 7, 4, 4, 4, 4, 4, 4, 7, 4, // 7 + 4, 4, 4, 4, 4, 4, 7, 4, 4, 4, 4, 4, 4, 4, 7, 4, // 8 + 4, 4, 4, 4, 4, 4, 7, 4, 4, 4, 4, 4, 4, 4, 7, 4, // 9 + 4, 4, 4, 4, 4, 4, 7, 4, 4, 4, 4, 4, 4, 4, 7, 4, // A + 4, 4, 4, 4, 4, 4, 7, 4, 4, 4, 4, 4, 4, 4, 7, 4, // B + 11,10,10,10,17,11, 7,11,11,10,10, 8,17,17, 7,11, // C + 11,10,10,11,17,11, 7,11,11, 4,10,11,17, 8, 7,11, // D + 11,10,10,19,17,11, 7,11,11, 4,10, 4,17, 8, 7,11, // E + 11,10,10, 4,17,11, 7,11,11, 6,10, 4,17, 8, 7,11, // F + }; + + fuint16 data; + data = base_timing [opcode]; + if ( (s_time += data) >= 0 ) + goto possibly_out_of_time; +almost_out_of_time: + + data = READ_PROG( pc ); + + #ifdef Z80_CPU_LOG_H + //log_opcode( opcode, READ_PROG( pc ) ); + z80_log_regs( rg.a, rp.bc, rp.de, rp.hl, sp, ix, iy ); + z80_cpu_log( "new", pc - 1, opcode, READ_PROG( pc ), + READ_PROG( pc + 1 ), READ_PROG( pc + 2 ) ); + #endif + + switch ( opcode ) + { +possibly_out_of_time: + if ( s_time < (int) data ) + goto almost_out_of_time; + s_time -= data; + goto out_of_time; + +// Common + + case 0x00: // NOP + CASE7( 40, 49, 52, 5B, 64, 6D, 7F ): // LD B,B etc. + goto loop; + + case 0x08:{// EX AF,AF' + int temp = r.alt.b.a; + r.alt.b.a = rg.a; + rg.a = temp; + + temp = r.alt.b.flags; + r.alt.b.flags = flags; + flags = temp; + goto loop; + } + + case 0xD3: // OUT (imm),A + pc++; + OUT( data + rg.a * 0x100, rg.a ); + goto loop; + + case 0x2E: // LD L,imm + pc++; + rg.l = data; + goto loop; + + case 0x3E: // LD A,imm + pc++; + rg.a = data; + goto loop; + + case 0x3A:{// LD A,(addr) + fuint16 addr = GET_ADDR(); + pc += 2; + rg.a = READ( addr ); + goto loop; + } + +// Conditional + +#define ZERO (flags & Z40) +#define CARRY (flags & C01) +#define EVEN (flags & P04) +#define MINUS (flags & S80) + +// JR +// TODO: more efficient way to handle negative branch that wraps PC around +#define JR( cond ) {\ + int offset = (BOOST::int8_t) data;\ + pc++;\ + if ( !(cond) )\ + goto jr_not_taken;\ + pc = uint16_t (pc + offset);\ + goto loop;\ +} + + case 0x20: JR( !ZERO ) // JR NZ,disp + case 0x28: JR( ZERO ) // JR Z,disp + case 0x30: JR( !CARRY ) // JR NC,disp + case 0x38: JR( CARRY ) // JR C,disp + case 0x18: JR( true ) // JR disp + + case 0x10:{// DJNZ disp + int temp = rg.b - 1; + rg.b = temp; + JR( temp ) + } + +// JP +#define JP( cond ) if ( !(cond) ) goto jp_not_taken; pc = GET_ADDR(); goto loop; + + case 0xC2: JP( !ZERO ) // JP NZ,addr + case 0xCA: JP( ZERO ) // JP Z,addr + case 0xD2: JP( !CARRY ) // JP NC,addr + case 0xDA: JP( CARRY ) // JP C,addr + case 0xE2: JP( !EVEN ) // JP PO,addr + case 0xEA: JP( EVEN ) // JP PE,addr + case 0xF2: JP( !MINUS ) // JP P,addr + case 0xFA: JP( MINUS ) // JP M,addr + + case 0xC3: // JP addr + pc = GET_ADDR(); + goto loop; + + case 0xE9: // JP HL + pc = rp.hl; + goto loop; + +// RET +#define RET( cond ) if ( cond ) goto ret_taken; s_time -= 6; goto loop; + + case 0xC0: RET( !ZERO ) // RET NZ + case 0xC8: RET( ZERO ) // RET Z + case 0xD0: RET( !CARRY ) // RET NC + case 0xD8: RET( CARRY ) // RET C + case 0xE0: RET( !EVEN ) // RET PO + case 0xE8: RET( EVEN ) // RET PE + case 0xF0: RET( !MINUS ) // RET P + case 0xF8: RET( MINUS ) // RET M + + case 0xC9: // RET + ret_taken: + pc = READ_WORD( sp ); + sp = uint16_t (sp + 2); + goto loop; + +// CALL +#define CALL( cond ) if ( cond ) goto call_taken; goto call_not_taken; + + case 0xC4: CALL( !ZERO ) // CALL NZ,addr + case 0xCC: CALL( ZERO ) // CALL Z,addr + case 0xD4: CALL( !CARRY ) // CALL NC,addr + case 0xDC: CALL( CARRY ) // CALL C,addr + case 0xE4: CALL( !EVEN ) // CALL PO,addr + case 0xEC: CALL( EVEN ) // CALL PE,addr + case 0xF4: CALL( !MINUS ) // CALL P,addr + case 0xFC: CALL( MINUS ) // CALL M,addr + + case 0xCD:{// CALL addr + call_taken: + fuint16 addr = pc + 2; + pc = GET_ADDR(); + sp = uint16_t (sp - 2); + WRITE_WORD( sp, addr ); + goto loop; + } + + case 0xFF: // RST + if ( pc > idle_addr ) + goto hit_idle_addr; + CASE7( C7, CF, D7, DF, E7, EF, F7 ): + data = pc; + pc = opcode & 0x38; + goto push_data; + +// PUSH/POP + case 0xF5: // PUSH AF + data = rg.a * 0x100u + flags; + goto push_data; + + case 0xC5: // PUSH BC + case 0xD5: // PUSH DE + case 0xE5: // PUSH HL + data = R16( opcode, 4, 0xC5 ); + push_data: + sp = uint16_t (sp - 2); + WRITE_WORD( sp, data ); + goto loop; + + case 0xF1: // POP AF + flags = READ( sp ); + rg.a = READ( sp + 1 ); + sp = uint16_t (sp + 2); + goto loop; + + case 0xC1: // POP BC + case 0xD1: // POP DE + case 0xE1: // POP HL + R16( opcode, 4, 0xC1 ) = READ_WORD( sp ); + sp = uint16_t (sp + 2); + goto loop; + +// ADC/ADD/SBC/SUB + case 0x96: // SUB (HL) + case 0x86: // ADD (HL) + flags &= ~C01; + case 0x9E: // SBC (HL) + case 0x8E: // ADC (HL) + data = READ( rp.hl ); + goto adc_data; + + case 0xD6: // SUB A,imm + case 0xC6: // ADD imm + flags &= ~C01; + case 0xDE: // SBC A,imm + case 0xCE: // ADC imm + pc++; + goto adc_data; + + CASE7( 90, 91, 92, 93, 94, 95, 97 ): // SUB r + CASE7( 80, 81, 82, 83, 84, 85, 87 ): // ADD r + flags &= ~C01; + CASE7( 98, 99, 9A, 9B, 9C, 9D, 9F ): // SBC r + CASE7( 88, 89, 8A, 8B, 8C, 8D, 8F ): // ADC r + data = R8( opcode & 7, 0 ); + adc_data: { + int result = data + (flags & C01); + data ^= rg.a; + flags = opcode >> 3 & N02; // bit 4 is set in subtract opcodes + if ( flags ) + result = -result; + result += rg.a; + data ^= result; + flags |=(data & H10) | + ((data - -0x80) >> 6 & V04) | + SZ28C( result & 0x1FF ); + rg.a = result; + goto loop; + } + +// CP + case 0xBE: // CP (HL) + data = READ( rp.hl ); + goto cp_data; + + case 0xFE: // CP imm + pc++; + goto cp_data; + + CASE7( B8, B9, BA, BB, BC, BD, BF ): // CP r + data = R8( opcode, 0xB8 ); + cp_data: { + int result = rg.a - data; + flags = N02 | (data & (F20 | F08)) | (result >> 8 & C01); + data ^= rg.a; + flags |=(((result ^ rg.a) & data) >> 5 & V04) | + (((data & H10) ^ result) & (S80 | H10)); + if ( (uint8_t) result ) + goto loop; + flags |= Z40; + goto loop; + } + +// ADD HL,rp + + case 0x39: // ADD HL,SP + data = sp; + goto add_hl_data; + + case 0x09: // ADD HL,BC + case 0x19: // ADD HL,DE + case 0x29: // ADD HL,HL + data = R16( opcode, 4, 0x09 ); + add_hl_data: { + blargg_ulong sum = rp.hl + data; + data ^= rp.hl; + rp.hl = sum; + flags = (flags & (S80 | Z40 | V04)) | + (sum >> 16) | + (sum >> 8 & (F20 | F08)) | + ((data ^ sum) >> 8 & H10); + goto loop; + } + + case 0x27:{// DAA + int a = rg.a; + if ( a > 0x99 ) + flags |= C01; + + int adjust = 0x60 & -(flags & C01); + + if ( flags & H10 || (a & 0x0F) > 9 ) + adjust |= 0x06; + + if ( flags & N02 ) + adjust = -adjust; + a += adjust; + + flags = (flags & (C01 | N02)) | + ((rg.a ^ a) & H10) | + SZ28P( (uint8_t) a ); + rg.a = a; + goto loop; + } + /* + case 0x27:{// DAA + // more optimized, but probably not worth the obscurity + int f = (rg.a + (0xFF - 0x99)) >> 8 | flags; // (a > 0x99 ? C01 : 0) | flags + int adjust = 0x60 & -(f & C01); // f & C01 ? 0x60 : 0 + + if ( (((rg.a + (0x0F - 9)) ^ rg.a) | f) & H10 ) // flags & H10 || (rg.a & 0x0F) > 9 + adjust |= 0x06; + + if ( f & N02 ) + adjust = -adjust; + int a = rg.a + adjust; + + flags = (f & (N02 | C01)) | ((rg.a ^ a) & H10) | SZ28P( (uint8_t) a ); + rg.a = a; + goto loop; + } + */ + +// INC/DEC + case 0x34: // INC (HL) + data = READ( rp.hl ) + 1; + WRITE( rp.hl, data ); + goto inc_set_flags; + + CASE7( 04, 0C, 14, 1C, 24, 2C, 3C ): // INC r + data = ++R8( opcode >> 3, 0 ); + inc_set_flags: + flags = (flags & C01) | + (((data & 0x0F) - 1) & H10) | + SZ28( (uint8_t) data ); + if ( data != 0x80 ) + goto loop; + flags |= V04; + goto loop; + + case 0x35: // DEC (HL) + data = READ( rp.hl ) - 1; + WRITE( rp.hl, data ); + goto dec_set_flags; + + CASE7( 05, 0D, 15, 1D, 25, 2D, 3D ): // DEC r + data = --R8( opcode >> 3, 0 ); + dec_set_flags: + flags = (flags & C01) | N02 | + (((data & 0x0F) + 1) & H10) | + SZ28( (uint8_t) data ); + if ( data != 0x7F ) + goto loop; + flags |= V04; + goto loop; + + case 0x03: // INC BC + case 0x13: // INC DE + case 0x23: // INC HL + R16( opcode, 4, 0x03 )++; + goto loop; + + case 0x33: // INC SP + sp = uint16_t (sp + 1); + goto loop; + + case 0x0B: // DEC BC + case 0x1B: // DEC DE + case 0x2B: // DEC HL + R16( opcode, 4, 0x0B )--; + goto loop; + + case 0x3B: // DEC SP + sp = uint16_t (sp - 1); + goto loop; + +// AND + case 0xA6: // AND (HL) + data = READ( rp.hl ); + goto and_data; + + case 0xE6: // AND imm + pc++; + goto and_data; + + CASE7( A0, A1, A2, A3, A4, A5, A7 ): // AND r + data = R8( opcode, 0xA0 ); + and_data: + rg.a &= data; + flags = SZ28P( rg.a ) | H10; + goto loop; + +// OR + case 0xB6: // OR (HL) + data = READ( rp.hl ); + goto or_data; + + case 0xF6: // OR imm + pc++; + goto or_data; + + CASE7( B0, B1, B2, B3, B4, B5, B7 ): // OR r + data = R8( opcode, 0xB0 ); + or_data: + rg.a |= data; + flags = SZ28P( rg.a ); + goto loop; + +// XOR + case 0xAE: // XOR (HL) + data = READ( rp.hl ); + goto xor_data; + + case 0xEE: // XOR imm + pc++; + goto xor_data; + + CASE7( A8, A9, AA, AB, AC, AD, AF ): // XOR r + data = R8( opcode, 0xA8 ); + xor_data: + rg.a ^= data; + flags = SZ28P( rg.a ); + goto loop; + +// LD + CASE7( 70, 71, 72, 73, 74, 75, 77 ): // LD (HL),r + WRITE( rp.hl, R8( opcode, 0x70 ) ); + goto loop; + + CASE6( 41, 42, 43, 44, 45, 47 ): // LD B,r + CASE6( 48, 4A, 4B, 4C, 4D, 4F ): // LD C,r + CASE6( 50, 51, 53, 54, 55, 57 ): // LD D,r + CASE6( 58, 59, 5A, 5C, 5D, 5F ): // LD E,r + CASE6( 60, 61, 62, 63, 65, 67 ): // LD H,r + CASE6( 68, 69, 6A, 6B, 6C, 6F ): // LD L,r + CASE6( 78, 79, 7A, 7B, 7C, 7D ): // LD A,r + R8( opcode >> 3 & 7, 0 ) = R8( opcode & 7, 0 ); + goto loop; + + CASE5( 06, 0E, 16, 1E, 26 ): // LD r,imm + R8( opcode >> 3, 0 ) = data; + pc++; + goto loop; + + case 0x36: // LD (HL),imm + pc++; + WRITE( rp.hl, data ); + goto loop; + + CASE7( 46, 4E, 56, 5E, 66, 6E, 7E ): // LD r,(HL) + R8( opcode >> 3, 8 ) = READ( rp.hl ); + goto loop; + + case 0x01: // LD rp,imm + case 0x11: + case 0x21: + R16( opcode, 4, 0x01 ) = GET_ADDR(); + pc += 2; + goto loop; + + case 0x31: // LD sp,imm + sp = GET_ADDR(); + pc += 2; + goto loop; + + case 0x2A:{// LD HL,(addr) + fuint16 addr = GET_ADDR(); + pc += 2; + rp.hl = READ_WORD( addr ); + goto loop; + } + + case 0x32:{// LD (addr),A + fuint16 addr = GET_ADDR(); + pc += 2; + WRITE( addr, rg.a ); + goto loop; + } + + case 0x22:{// LD (addr),HL + fuint16 addr = GET_ADDR(); + pc += 2; + WRITE_WORD( addr, rp.hl ); + goto loop; + } + + case 0x02: // LD (BC),A + case 0x12: // LD (DE),A + WRITE( R16( opcode, 4, 0x02 ), rg.a ); + goto loop; + + case 0x0A: // LD A,(BC) + case 0x1A: // LD A,(DE) + rg.a = READ( R16( opcode, 4, 0x0A ) ); + goto loop; + + case 0xF9: // LD SP,HL + sp = rp.hl; + goto loop; + +// Rotate + + case 0x07:{// RLCA + fuint16 temp = rg.a; + temp = (temp << 1) | (temp >> 7); + flags = (flags & (S80 | Z40 | P04)) | + (temp & (F20 | F08 | C01)); + rg.a = temp; + goto loop; + } + + case 0x0F:{// RRCA + fuint16 temp = rg.a; + flags = (flags & (S80 | Z40 | P04)) | + (temp & C01); + temp = (temp << 7) | (temp >> 1); + flags |= temp & (F20 | F08); + rg.a = temp; + goto loop; + } + + case 0x17:{// RLA + blargg_ulong temp = (rg.a << 1) | (flags & C01); + flags = (flags & (S80 | Z40 | P04)) | + (temp & (F20 | F08)) | + (temp >> 8); + rg.a = temp; + goto loop; + } + + case 0x1F:{// RRA + fuint16 temp = (flags << 7) | (rg.a >> 1); + flags = (flags & (S80 | Z40 | P04)) | + (temp & (F20 | F08)) | + (rg.a & C01); + rg.a = temp; + goto loop; + } + +// Misc + case 0x2F:{// CPL + fuint16 temp = ~rg.a; + flags = (flags & (S80 | Z40 | P04 | C01)) | + (temp & (F20 | F08)) | + (H10 | N02); + rg.a = temp; + goto loop; + } + + case 0x3F:{// CCF + flags = ((flags & (S80 | Z40 | P04 | C01)) ^ C01) | + (flags << 4 & H10) | + (rg.a & (F20 | F08)); + goto loop; + } + + case 0x37: // SCF + flags = (flags & (S80 | Z40 | P04)) | C01 | + (rg.a & (F20 | F08)); + goto loop; + + case 0xDB: // IN A,(imm) + pc++; + rg.a = IN( data + rg.a * 0x100 ); + goto loop; + + case 0xE3:{// EX (SP),HL + fuint16 temp = READ_WORD( sp ); + WRITE_WORD( sp, rp.hl ); + rp.hl = temp; + goto loop; + } + + case 0xEB:{// EX DE,HL + fuint16 temp = rp.hl; + rp.hl = rp.de; + rp.de = temp; + goto loop; + } + + case 0xD9:{// EXX DE,HL + fuint16 temp = r.alt.w.bc; + r.alt.w.bc = rp.bc; + rp.bc = temp; + + temp = r.alt.w.de; + r.alt.w.de = rp.de; + rp.de = temp; + + temp = r.alt.w.hl; + r.alt.w.hl = rp.hl; + rp.hl = temp; + goto loop; + } + + case 0xF3: // DI + r.iff1 = 0; + r.iff2 = 0; + goto loop; + + case 0xFB: // EI + r.iff1 = 1; + r.iff2 = 1; + // TODO: delayed effect + goto loop; + + case 0x76: // HALT + goto halt; + +//////////////////////////////////////// CB prefix + { + case 0xCB: + unsigned data2; + data2 = instr [1]; + (void) data2; // TODO is this the same as data in all cases? + pc++; + switch ( data ) + { + + // Rotate left + + #define RLC( read, write ) {\ + fuint8 result = read;\ + result = uint8_t (result << 1) | (result >> 7);\ + flags = SZ28P( result ) | (result & C01);\ + write;\ + goto loop;\ + } + + case 0x06: // RLC (HL) + s_time += 7; + data = rp.hl; + rlc_data_addr: + RLC( READ( data ), WRITE( data, result ) ) + + CASE7( 00, 01, 02, 03, 04, 05, 07 ):{// RLC r + uint8_t& reg = R8( data, 0 ); + RLC( reg, reg = result ) + } + + #define RL( read, write ) {\ + fuint16 result = (read << 1) | (flags & C01);\ + flags = SZ28PC( result );\ + write;\ + goto loop;\ + } + + case 0x16: // RL (HL) + s_time += 7; + data = rp.hl; + rl_data_addr: + RL( READ( data ), WRITE( data, result ) ) + + CASE7( 10, 11, 12, 13, 14, 15, 17 ):{// RL r + uint8_t& reg = R8( data, 0x10 ); + RL( reg, reg = result ) + } + + #define SLA( read, add, write ) {\ + fuint16 result = (read << 1) | add;\ + flags = SZ28PC( result );\ + write;\ + goto loop;\ + } + + case 0x26: // SLA (HL) + s_time += 7; + data = rp.hl; + sla_data_addr: + SLA( READ( data ), 0, WRITE( data, result ) ) + + CASE7( 20, 21, 22, 23, 24, 25, 27 ):{// SLA r + uint8_t& reg = R8( data, 0x20 ); + SLA( reg, 0, reg = result ) + } + + case 0x36: // SLL (HL) + s_time += 7; + data = rp.hl; + sll_data_addr: + SLA( READ( data ), 1, WRITE( data, result ) ) + + CASE7( 30, 31, 32, 33, 34, 35, 37 ):{// SLL r + uint8_t& reg = R8( data, 0x30 ); + SLA( reg, 1, reg = result ) + } + + // Rotate right + + #define RRC( read, write ) {\ + fuint8 result = read;\ + flags = result & C01;\ + result = uint8_t (result << 7) | (result >> 1);\ + flags |= SZ28P( result );\ + write;\ + goto loop;\ + } + + case 0x0E: // RRC (HL) + s_time += 7; + data = rp.hl; + rrc_data_addr: + RRC( READ( data ), WRITE( data, result ) ) + + CASE7( 08, 09, 0A, 0B, 0C, 0D, 0F ):{// RRC r + uint8_t& reg = R8( data, 0x08 ); + RRC( reg, reg = result ) + } + + #define RR( read, write ) {\ + fuint8 result = read;\ + fuint8 temp = result & C01;\ + result = uint8_t (flags << 7) | (result >> 1);\ + flags = SZ28P( result ) | temp;\ + write;\ + goto loop;\ + } + + case 0x1E: // RR (HL) + s_time += 7; + data = rp.hl; + rr_data_addr: + RR( READ( data ), WRITE( data, result ) ) + + CASE7( 18, 19, 1A, 1B, 1C, 1D, 1F ):{// RR r + uint8_t& reg = R8( data, 0x18 ); + RR( reg, reg = result ) + } + + #define SRA( read, write ) {\ + fuint8 result = read;\ + flags = result & C01;\ + result = (result & 0x80) | (result >> 1);\ + flags |= SZ28P( result );\ + write;\ + goto loop;\ + } + + case 0x2E: // SRA (HL) + data = rp.hl; + s_time += 7; + sra_data_addr: + SRA( READ( data ), WRITE( data, result ) ) + + CASE7( 28, 29, 2A, 2B, 2C, 2D, 2F ):{// SRA r + uint8_t& reg = R8( data, 0x28 ); + SRA( reg, reg = result ) + } + + #define SRL( read, write ) {\ + fuint8 result = read;\ + flags = result & C01;\ + result >>= 1;\ + flags |= SZ28P( result );\ + write;\ + goto loop;\ + } + + case 0x3E: // SRL (HL) + s_time += 7; + data = rp.hl; + srl_data_addr: + SRL( READ( data ), WRITE( data, result ) ) + + CASE7( 38, 39, 3A, 3B, 3C, 3D, 3F ):{// SRL r + uint8_t& reg = R8( data, 0x38 ); + SRL( reg, reg = result ) + } + + // BIT + { + unsigned temp; + CASE8( 46, 4E, 56, 5E, 66, 6E, 76, 7E ): // BIT b,(HL) + s_time += 4; + temp = READ( rp.hl ); + flags &= C01; + goto bit_temp; + CASE7( 40, 41, 42, 43, 44, 45, 47 ): // BIT 0,r + CASE7( 48, 49, 4A, 4B, 4C, 4D, 4F ): // BIT 1,r + CASE7( 50, 51, 52, 53, 54, 55, 57 ): // BIT 2,r + CASE7( 58, 59, 5A, 5B, 5C, 5D, 5F ): // BIT 3,r + CASE7( 60, 61, 62, 63, 64, 65, 67 ): // BIT 4,r + CASE7( 68, 69, 6A, 6B, 6C, 6D, 6F ): // BIT 5,r + CASE7( 70, 71, 72, 73, 74, 75, 77 ): // BIT 6,r + CASE7( 78, 79, 7A, 7B, 7C, 7D, 7F ): // BIT 7,r + temp = R8( data & 7, 0 ); + flags = (flags & C01) | (temp & (F20 | F08)); + bit_temp: + int masked = temp & 1 << (data >> 3 & 7); + flags |=(masked & S80) | H10 | + ((masked - 1) >> 8 & (Z40 | P04)); + goto loop; + } + + // SET/RES + CASE8( 86, 8E, 96, 9E, A6, AE, B6, BE ): // RES b,(HL) + CASE8( C6, CE, D6, DE, E6, EE, F6, FE ):{// SET b,(HL) + s_time += 7; + int temp = READ( rp.hl ); + int bit = 1 << (data >> 3 & 7); + temp |= bit; // SET + if ( !(data & 0x40) ) + temp ^= bit; // RES + WRITE( rp.hl, temp ); + goto loop; + } + + CASE7( C0, C1, C2, C3, C4, C5, C7 ): // SET 0,r + CASE7( C8, C9, CA, CB, CC, CD, CF ): // SET 1,r + CASE7( D0, D1, D2, D3, D4, D5, D7 ): // SET 2,r + CASE7( D8, D9, DA, DB, DC, DD, DF ): // SET 3,r + CASE7( E0, E1, E2, E3, E4, E5, E7 ): // SET 4,r + CASE7( E8, E9, EA, EB, EC, ED, EF ): // SET 5,r + CASE7( F0, F1, F2, F3, F4, F5, F7 ): // SET 6,r + CASE7( F8, F9, FA, FB, FC, FD, FF ): // SET 7,r + R8( data & 7, 0 ) |= 1 << (data >> 3 & 7); + goto loop; + + CASE7( 80, 81, 82, 83, 84, 85, 87 ): // RES 0,r + CASE7( 88, 89, 8A, 8B, 8C, 8D, 8F ): // RES 1,r + CASE7( 90, 91, 92, 93, 94, 95, 97 ): // RES 2,r + CASE7( 98, 99, 9A, 9B, 9C, 9D, 9F ): // RES 3,r + CASE7( A0, A1, A2, A3, A4, A5, A7 ): // RES 4,r + CASE7( A8, A9, AA, AB, AC, AD, AF ): // RES 5,r + CASE7( B0, B1, B2, B3, B4, B5, B7 ): // RES 6,r + CASE7( B8, B9, BA, BB, BC, BD, BF ): // RES 7,r + R8( data & 7, 0 ) &= ~(1 << (data >> 3 & 7)); + goto loop; + } + assert( false ); + } + +#undef GET_ADDR +#define GET_ADDR() GET_LE16( instr + 1 ) + +//////////////////////////////////////// ED prefix + { + case 0xED: + pc++; + s_time += ed_dd_timing [data] >> 4; + switch ( data ) + { + { + blargg_ulong temp; + case 0x72: // SBC HL,SP + case 0x7A: // ADC HL,SP + temp = sp; + if ( 0 ) + case 0x42: // SBC HL,BC + case 0x52: // SBC HL,DE + case 0x62: // SBC HL,HL + case 0x4A: // ADC HL,BC + case 0x5A: // ADC HL,DE + case 0x6A: // ADC HL,HL + temp = R16( data >> 3 & 6, 1, 0 ); + blargg_ulong sum = temp + (flags & C01); + flags = ~data >> 2 & N02; + if ( flags ) + sum = -sum; + sum += rp.hl; + temp ^= rp.hl; + temp ^= sum; + flags |=(sum >> 16 & C01) | + (temp >> 8 & H10) | + (sum >> 8 & (S80 | F20 | F08)) | + ((temp - -0x8000) >> 14 & V04); + rp.hl = sum; + if ( (uint16_t) sum ) + goto loop; + flags |= Z40; + goto loop; + } + + CASE8( 40, 48, 50, 58, 60, 68, 70, 78 ):{// IN r,(C) + int temp = IN( rp.bc ); + R8( data >> 3, 8 ) = temp; + flags = (flags & C01) | SZ28P( temp ); + goto loop; + } + + case 0x71: // OUT (C),0 + rg.flags = 0; + CASE7( 41, 49, 51, 59, 61, 69, 79 ): // OUT (C),r + OUT( rp.bc, R8( data >> 3, 8 ) ); + goto loop; + + { + unsigned temp; + case 0x73: // LD (ADDR),SP + temp = sp; + if ( 0 ) + case 0x43: // LD (ADDR),BC + case 0x53: // LD (ADDR),DE + temp = R16( data, 4, 0x43 ); + fuint16 addr = GET_ADDR(); + pc += 2; + WRITE_WORD( addr, temp ); + goto loop; + } + + case 0x4B: // LD BC,(ADDR) + case 0x5B:{// LD DE,(ADDR) + fuint16 addr = GET_ADDR(); + pc += 2; + R16( data, 4, 0x4B ) = READ_WORD( addr ); + goto loop; + } + + case 0x7B:{// LD SP,(ADDR) + fuint16 addr = GET_ADDR(); + pc += 2; + sp = READ_WORD( addr ); + goto loop; + } + + case 0x67:{// RRD + fuint8 temp = READ( rp.hl ); + WRITE( rp.hl, (rg.a << 4) | (temp >> 4) ); + temp = (rg.a & 0xF0) | (temp & 0x0F); + flags = (flags & C01) | SZ28P( temp ); + rg.a = temp; + goto loop; + } + + case 0x6F:{// RLD + fuint8 temp = READ( rp.hl ); + WRITE( rp.hl, (temp << 4) | (rg.a & 0x0F) ); + temp = (rg.a & 0xF0) | (temp >> 4); + flags = (flags & C01) | SZ28P( temp ); + rg.a = temp; + goto loop; + } + + CASE8( 44, 4C, 54, 5C, 64, 6C, 74, 7C ): // NEG + opcode = 0x10; // flag to do SBC instead of ADC + flags &= ~C01; + data = rg.a; + rg.a = 0; + goto adc_data; + + { + int inc; + case 0xA9: // CPD + case 0xB9: // CPDR + inc = -1; + if ( 0 ) + case 0xA1: // CPI + case 0xB1: // CPIR + inc = +1; + fuint16 addr = rp.hl; + rp.hl = addr + inc; + int temp = READ( addr ); + + int result = rg.a - temp; + flags = (flags & C01) | N02 | + ((((temp ^ rg.a) & H10) ^ result) & (S80 | H10)); + + if ( !(uint8_t) result ) flags |= Z40; + result -= (flags & H10) >> 4; + flags |= result & F08; + flags |= result << 4 & F20; + if ( !--rp.bc ) + goto loop; + + flags |= V04; + if ( flags & Z40 || data < 0xB0 ) + goto loop; + + pc -= 2; + s_time += 5; + goto loop; + } + + { + int inc; + case 0xA8: // LDD + case 0xB8: // LDDR + inc = -1; + if ( 0 ) + case 0xA0: // LDI + case 0xB0: // LDIR + inc = +1; + fuint16 addr = rp.hl; + rp.hl = addr + inc; + int temp = READ( addr ); + + addr = rp.de; + rp.de = addr + inc; + WRITE( addr, temp ); + + temp += rg.a; + flags = (flags & (S80 | Z40 | C01)) | + (temp & F08) | (temp << 4 & F20); + if ( !--rp.bc ) + goto loop; + + flags |= V04; + if ( data < 0xB0 ) + goto loop; + + pc -= 2; + s_time += 5; + goto loop; + } + + { + int inc; + case 0xAB: // OUTD + case 0xBB: // OTDR + inc = -1; + if ( 0 ) + case 0xA3: // OUTI + case 0xB3: // OTIR + inc = +1; + fuint16 addr = rp.hl; + rp.hl = addr + inc; + int temp = READ( addr ); + + int b = --rg.b; + flags = (temp >> 6 & N02) | SZ28( b ); + if ( b && data >= 0xB0 ) + { + pc -= 2; + s_time += 5; + } + + OUT( rp.bc, temp ); + goto loop; + } + + { + int inc; + case 0xAA: // IND + case 0xBA: // INDR + inc = -1; + if ( 0 ) + case 0xA2: // INI + case 0xB2: // INIR + inc = +1; + + fuint16 addr = rp.hl; + rp.hl = addr + inc; + + int temp = IN( rp.bc ); + + int b = --rg.b; + flags = (temp >> 6 & N02) | SZ28( b ); + if ( b && data >= 0xB0 ) + { + pc -= 2; + s_time += 5; + } + + WRITE( addr, temp ); + goto loop; + } + + case 0x47: // LD I,A + r.i = rg.a; + goto loop; + + case 0x4F: // LD R,A + SET_R( rg.a ); + debug_printf( "LD R,A not supported\n" ); + warning = true; + goto loop; + + case 0x57: // LD A,I + rg.a = r.i; + goto ld_ai_common; + + case 0x5F: // LD A,R + rg.a = GET_R(); + debug_printf( "LD A,R not supported\n" ); + warning = true; + ld_ai_common: + flags = (flags & C01) | SZ28( rg.a ) | (r.iff2 << 2 & V04); + goto loop; + + CASE8( 45, 4D, 55, 5D, 65, 6D, 75, 7D ): // RETI/RETN + r.iff1 = r.iff2; + goto ret_taken; + + case 0x46: case 0x4E: case 0x66: case 0x6E: // IM 0 + r.im = 0; + goto loop; + + case 0x56: case 0x76: // IM 1 + r.im = 1; + goto loop; + + case 0x5E: case 0x7E: // IM 2 + r.im = 2; + goto loop; + + default: + debug_printf( "Opcode $ED $%02X not supported\n", data ); + warning = true; + goto loop; + } + assert( false ); + } + +//////////////////////////////////////// DD/FD prefix + { + fuint16 ixy; + case 0xDD: + ixy = ix; + goto ix_prefix; + case 0xFD: + ixy = iy; + ix_prefix: + pc++; + unsigned data2 = READ_PROG( pc ); + s_time += ed_dd_timing [data] & 0x0F; + switch ( data ) + { + // TODO: more efficient way of avoid negative address + // TODO: avoid using this as argument to READ() since it is evaluated twice + #define IXY_DISP( ixy, disp ) uint16_t ((ixy) + (disp)) + + #define SET_IXY( in ) if ( opcode == 0xDD ) ix = in; else iy = in; + + // ADD/ADC/SUB/SBC + + case 0x96: // SUB (IXY+disp) + case 0x86: // ADD (IXY+disp) + flags &= ~C01; + case 0x9E: // SBC (IXY+disp) + case 0x8E: // ADC (IXY+disp) + pc++; + opcode = data; + data = READ( IXY_DISP( ixy, (int8_t) data2 ) ); + goto adc_data; + + case 0x94: // SUB HXY + case 0x84: // ADD HXY + flags &= ~C01; + case 0x9C: // SBC HXY + case 0x8C: // ADC HXY + opcode = data; + data = ixy >> 8; + goto adc_data; + + case 0x95: // SUB LXY + case 0x85: // ADD LXY + flags &= ~C01; + case 0x9D: // SBC LXY + case 0x8D: // ADC LXY + opcode = data; + data = (uint8_t) ixy; + goto adc_data; + + { + unsigned temp; + case 0x39: // ADD IXY,SP + temp = sp; + goto add_ixy_data; + + case 0x29: // ADD IXY,HL + temp = ixy; + goto add_ixy_data; + + case 0x09: // ADD IXY,BC + case 0x19: // ADD IXY,DE + temp = R16( data, 4, 0x09 ); + add_ixy_data: { + blargg_ulong sum = ixy + temp; + temp ^= ixy; + ixy = (uint16_t) sum; + flags = (flags & (S80 | Z40 | V04)) | + (sum >> 16) | + (sum >> 8 & (F20 | F08)) | + ((temp ^ sum) >> 8 & H10); + goto set_ixy; + } + } + + // AND + case 0xA6: // AND (IXY+disp) + pc++; + data = READ( IXY_DISP( ixy, (int8_t) data2 ) ); + goto and_data; + + case 0xA4: // AND HXY + data = ixy >> 8; + goto and_data; + + case 0xA5: // AND LXY + data = (uint8_t) ixy; + goto and_data; + + // OR + case 0xB6: // OR (IXY+disp) + pc++; + data = READ( IXY_DISP( ixy, (int8_t) data2 ) ); + goto or_data; + + case 0xB4: // OR HXY + data = ixy >> 8; + goto or_data; + + case 0xB5: // OR LXY + data = (uint8_t) ixy; + goto or_data; + + // XOR + case 0xAE: // XOR (IXY+disp) + pc++; + data = READ( IXY_DISP( ixy, (int8_t) data2 ) ); + goto xor_data; + + case 0xAC: // XOR HXY + data = ixy >> 8; + goto xor_data; + + case 0xAD: // XOR LXY + data = (uint8_t) ixy; + goto xor_data; + + // CP + case 0xBE: // CP (IXY+disp) + pc++; + data = READ( IXY_DISP( ixy, (int8_t) data2 ) ); + goto cp_data; + + case 0xBC: // CP HXY + data = ixy >> 8; + goto cp_data; + + case 0xBD: // CP LXY + data = (uint8_t) ixy; + goto cp_data; + + // LD + CASE7( 70, 71, 72, 73, 74, 75, 77 ): // LD (IXY+disp),r + data = R8( data, 0x70 ); + if ( 0 ) + case 0x36: // LD (IXY+disp),imm + pc++, data = READ_PROG( pc ); + pc++; + WRITE( IXY_DISP( ixy, (int8_t) data2 ), data ); + goto loop; + + CASE5( 44, 4C, 54, 5C, 7C ): // LD r,HXY + R8( data >> 3, 8 ) = ixy >> 8; + goto loop; + + case 0x64: // LD HXY,HXY + case 0x6D: // LD LXY,LXY + goto loop; + + CASE5( 45, 4D, 55, 5D, 7D ): // LD r,LXY + R8( data >> 3, 8 ) = ixy; + goto loop; + + CASE7( 46, 4E, 56, 5E, 66, 6E, 7E ): // LD r,(IXY+disp) + pc++; + R8( data >> 3, 8 ) = READ( IXY_DISP( ixy, (int8_t) data2 ) ); + goto loop; + + case 0x26: // LD HXY,imm + pc++; + goto ld_hxy_data; + + case 0x65: // LD HXY,LXY + data2 = (uint8_t) ixy; + goto ld_hxy_data; + + CASE5( 60, 61, 62, 63, 67 ): // LD HXY,r + data2 = R8( data, 0x60 ); + ld_hxy_data: + ixy = (uint8_t) ixy | (data2 << 8); + goto set_ixy; + + case 0x2E: // LD LXY,imm + pc++; + goto ld_lxy_data; + + case 0x6C: // LD LXY,HXY + data2 = ixy >> 8; + goto ld_lxy_data; + + CASE5( 68, 69, 6A, 6B, 6F ): // LD LXY,r + data2 = R8( data, 0x68 ); + ld_lxy_data: + ixy = (ixy & 0xFF00) | data2; + set_ixy: + if ( opcode == 0xDD ) + { + ix = ixy; + goto loop; + } + iy = ixy; + goto loop; + + case 0xF9: // LD SP,IXY + sp = ixy; + goto loop; + + case 0x22:{// LD (ADDR),IXY + fuint16 addr = GET_ADDR(); + pc += 2; + WRITE_WORD( addr, ixy ); + goto loop; + } + + case 0x21: // LD IXY,imm + ixy = GET_ADDR(); + pc += 2; + goto set_ixy; + + case 0x2A:{// LD IXY,(addr) + fuint16 addr = GET_ADDR(); + ixy = READ_WORD( addr ); + pc += 2; + goto set_ixy; + } + + // DD/FD CB prefix + case 0xCB: { + data = IXY_DISP( ixy, (int8_t) data2 ); + pc++; + data2 = READ_PROG( pc ); + pc++; + switch ( data2 ) + { + case 0x06: goto rlc_data_addr; // RLC (IXY) + case 0x16: goto rl_data_addr; // RL (IXY) + case 0x26: goto sla_data_addr; // SLA (IXY) + case 0x36: goto sll_data_addr; // SLL (IXY) + case 0x0E: goto rrc_data_addr; // RRC (IXY) + case 0x1E: goto rr_data_addr; // RR (IXY) + case 0x2E: goto sra_data_addr; // SRA (IXY) + case 0x3E: goto srl_data_addr; // SRL (IXY) + + CASE8( 46, 4E, 56, 5E, 66, 6E, 76, 7E ):{// BIT b,(IXY+disp) + fuint8 temp = READ( data ); + int masked = temp & 1 << (data2 >> 3 & 7); + flags = (flags & C01) | H10 | + (masked & S80) | + ((masked - 1) >> 8 & (Z40 | P04)); + goto loop; + } + + CASE8( 86, 8E, 96, 9E, A6, AE, B6, BE ): // RES b,(IXY+disp) + CASE8( C6, CE, D6, DE, E6, EE, F6, FE ):{// SET b,(IXY+disp) + int temp = READ( data ); + int bit = 1 << (data2 >> 3 & 7); + temp |= bit; // SET + if ( !(data2 & 0x40) ) + temp ^= bit; // RES + WRITE( data, temp ); + goto loop; + } + + default: + debug_printf( "Opcode $%02X $CB $%02X not supported\n", opcode, data2 ); + warning = true; + goto loop; + } + assert( false ); + } + + // INC/DEC + case 0x23: // INC IXY + ixy = uint16_t (ixy + 1); + goto set_ixy; + + case 0x2B: // DEC IXY + ixy = uint16_t (ixy - 1); + goto set_ixy; + + case 0x34: // INC (IXY+disp) + ixy = IXY_DISP( ixy, (int8_t) data2 ); + pc++; + data = READ( ixy ) + 1; + WRITE( ixy, data ); + goto inc_set_flags; + + case 0x35: // DEC (IXY+disp) + ixy = IXY_DISP( ixy, (int8_t) data2 ); + pc++; + data = READ( ixy ) - 1; + WRITE( ixy, data ); + goto dec_set_flags; + + case 0x24: // INC HXY + ixy = uint16_t (ixy + 0x100); + data = ixy >> 8; + goto inc_xy_common; + + case 0x2C: // INC LXY + data = uint8_t (ixy + 1); + ixy = (ixy & 0xFF00) | data; + inc_xy_common: + if ( opcode == 0xDD ) + { + ix = ixy; + goto inc_set_flags; + } + iy = ixy; + goto inc_set_flags; + + case 0x25: // DEC HXY + ixy = uint16_t (ixy - 0x100); + data = ixy >> 8; + goto dec_xy_common; + + case 0x2D: // DEC LXY + data = uint8_t (ixy - 1); + ixy = (ixy & 0xFF00) | data; + dec_xy_common: + if ( opcode == 0xDD ) + { + ix = ixy; + goto dec_set_flags; + } + iy = ixy; + goto dec_set_flags; + + // PUSH/POP + case 0xE5: // PUSH IXY + data = ixy; + goto push_data; + + case 0xE1:{// POP IXY + ixy = READ_WORD( sp ); + sp = uint16_t (sp + 2); + goto set_ixy; + } + + // Misc + + case 0xE9: // JP (IXY) + pc = ixy; + goto loop; + + case 0xE3:{// EX (SP),IXY + fuint16 temp = READ_WORD( sp ); + WRITE_WORD( sp, ixy ); + ixy = temp; + goto set_ixy; + } + + default: + debug_printf( "Unnecessary DD/FD prefix encountered\n" ); + warning = true; + pc--; + goto loop; + } + assert( false ); + } + + } + debug_printf( "Unhandled main opcode: $%02X\n", opcode ); + assert( false ); + +hit_idle_addr: + s_time -= 11; + goto out_of_time; +halt: + s_time &= 3; // increment by multiple of 4 +out_of_time: + pc--; + + s.time = s_time; + rg.flags = flags; + r.ix = ix; + r.iy = iy; + r.sp = sp; + r.pc = pc; + this->r.b = rg; + this->state_ = s; + this->state = &this->state_; + + return warning; +} diff --git a/libs/gme/gme/Kss_Cpu.h b/libs/gme/gme/Kss_Cpu.h new file mode 100644 index 000000000..aec24e9d5 --- /dev/null +++ b/libs/gme/gme/Kss_Cpu.h @@ -0,0 +1,124 @@ +// Z80 CPU emulator + +// Game_Music_Emu 0.6.0 +#ifndef KSS_CPU_H +#define KSS_CPU_H + +#include "blargg_endian.h" + +typedef blargg_long cpu_time_t; + +// must be defined by caller +void kss_cpu_out( class Kss_Cpu*, cpu_time_t, unsigned addr, int data ); +int kss_cpu_in( class Kss_Cpu*, cpu_time_t, unsigned addr ); +void kss_cpu_write( class Kss_Cpu*, unsigned addr, int data ); + +class Kss_Cpu { +public: + typedef BOOST::uint8_t uint8_t; + + // Clear registers and map all pages to unmapped + void reset( void* unmapped_write, void const* unmapped_read ); + + // Map memory. Start and size must be multiple of page_size. + enum { page_size = 0x2000 }; + void map_mem( unsigned addr, blargg_ulong size, void* write, void const* read ); + + // Map address to page + uint8_t* write( unsigned addr ); + uint8_t const* read( unsigned addr ); + + // Run until specified time is reached. Returns true if suspicious/unsupported + // instruction was encountered at any point during run. + bool run( cpu_time_t end_time ); + + // Time of beginning of next instruction + cpu_time_t time() const { return state->time + state->base; } + + // Alter current time. Not supported during run() call. + void set_time( cpu_time_t t ) { state->time = t - state->base; } + void adjust_time( int delta ) { state->time += delta; } + + typedef BOOST::uint16_t uint16_t; + + #if BLARGG_BIG_ENDIAN + struct regs_t { uint8_t b, c, d, e, h, l, flags, a; }; + #else + struct regs_t { uint8_t c, b, e, d, l, h, a, flags; }; + #endif + BOOST_STATIC_ASSERT( sizeof (regs_t) == 8 ); + + struct pairs_t { uint16_t bc, de, hl, fa; }; + + // Registers are not updated until run() returns + struct registers_t { + uint16_t pc; + uint16_t sp; + uint16_t ix; + uint16_t iy; + union { + regs_t b; // b.b, b.c, b.d, b.e, b.h, b.l, b.flags, b.a + pairs_t w; // w.bc, w.de, w.hl. w.fa + }; + union { + regs_t b; + pairs_t w; + } alt; + uint8_t iff1; + uint8_t iff2; + uint8_t r; + uint8_t i; + uint8_t im; + }; + //registers_t r; (below for efficiency) + + enum { idle_addr = 0xFFFF }; + + // can read this far past end of a page + enum { cpu_padding = 0x100 }; + +public: + Kss_Cpu(); + enum { page_shift = 13 }; + enum { page_count = 0x10000 >> page_shift }; +private: + uint8_t szpc [0x200]; + cpu_time_t end_time_; + struct state_t { + uint8_t const* read [page_count + 1]; + uint8_t * write [page_count + 1]; + cpu_time_t base; + cpu_time_t time; + }; + state_t* state; // points to state_ or a local copy within run() + state_t state_; + void set_end_time( cpu_time_t t ); + void set_page( int i, void* write, void const* read ); +public: + registers_t r; +}; + +#if BLARGG_NONPORTABLE + #define KSS_CPU_PAGE_OFFSET( addr ) (addr) +#else + #define KSS_CPU_PAGE_OFFSET( addr ) ((addr) & (page_size - 1)) +#endif + +inline BOOST::uint8_t* Kss_Cpu::write( unsigned addr ) +{ + return state->write [addr >> page_shift] + KSS_CPU_PAGE_OFFSET( addr ); +} + +inline BOOST::uint8_t const* Kss_Cpu::read( unsigned addr ) +{ + return state->read [addr >> page_shift] + KSS_CPU_PAGE_OFFSET( addr ); +} + +inline void Kss_Cpu::set_end_time( cpu_time_t t ) +{ + cpu_time_t delta = state->base - t; + state->base = t; + state->time += delta; +} + +#endif diff --git a/libs/gme/gme/Kss_Emu.cpp b/libs/gme/gme/Kss_Emu.cpp new file mode 100644 index 000000000..def6ee199 --- /dev/null +++ b/libs/gme/gme/Kss_Emu.cpp @@ -0,0 +1,416 @@ +// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/ + +#include "Kss_Emu.h" + +#include "blargg_endian.h" +#include + +/* Copyright (C) 2006 Shay Green. This module 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 +module 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 module; if not, write to the Free Software Foundation, +Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + +#include "blargg_source.h" + +long const clock_rate = 3579545; +int const osc_count = Ay_Apu::osc_count + Scc_Apu::osc_count; + +Kss_Emu::Kss_Emu() +{ + sn = 0; + set_type( gme_kss_type ); + set_silence_lookahead( 6 ); + static const char* const names [osc_count] = { + "Square 1", "Square 2", "Square 3", + "Wave 1", "Wave 2", "Wave 3", "Wave 4", "Wave 5" + }; + set_voice_names( names ); + + static int const types [osc_count] = { + wave_type | 0, wave_type | 1, wave_type | 2, + wave_type | 3, wave_type | 4, wave_type | 5, wave_type | 6, wave_type | 7 + }; + set_voice_types( types ); + + memset( unmapped_read, 0xFF, sizeof unmapped_read ); +} + +Kss_Emu::~Kss_Emu() { unload(); } + +void Kss_Emu::unload() +{ + delete sn; + sn = 0; + Classic_Emu::unload(); +} + +// Track info + +static void copy_kss_fields( Kss_Emu::header_t const& h, track_info_t* out ) +{ + const char* system = "MSX"; + if ( h.device_flags & 0x02 ) + { + system = "Sega Master System"; + if ( h.device_flags & 0x04 ) + system = "Game Gear"; + } + Gme_File::copy_field_( out->system, system ); +} + +blargg_err_t Kss_Emu::track_info_( track_info_t* out, int ) const +{ + copy_kss_fields( header_, out ); + return 0; +} + +static blargg_err_t check_kss_header( void const* header ) +{ + if ( memcmp( header, "KSCC", 4 ) && memcmp( header, "KSSX", 4 ) ) + return gme_wrong_file_type; + return 0; +} + +struct Kss_File : Gme_Info_ +{ + Kss_Emu::header_t header_; + + Kss_File() { set_type( gme_kss_type ); } + + blargg_err_t load_( Data_Reader& in ) + { + blargg_err_t err = in.read( &header_, Kss_Emu::header_size ); + if ( err ) + return (err == in.eof_error ? gme_wrong_file_type : err); + return check_kss_header( &header_ ); + } + + blargg_err_t track_info_( track_info_t* out, int ) const + { + copy_kss_fields( header_, out ); + return 0; + } +}; + +static Music_Emu* new_kss_emu () { return BLARGG_NEW Kss_Emu ; } +static Music_Emu* new_kss_file() { return BLARGG_NEW Kss_File; } + +static gme_type_t_ const gme_kss_type_ = { "MSX", 256, &new_kss_emu, &new_kss_file, "KSS", 0x03 }; +gme_type_t const gme_kss_type = &gme_kss_type_; + + +// Setup + +void Kss_Emu::update_gain() +{ + double g = gain() * 1.4; + if ( scc_accessed ) + g *= 1.5; + ay.volume( g ); + scc.volume( g ); + if ( sn ) + sn->volume( g ); +} + +blargg_err_t Kss_Emu::load_( Data_Reader& in ) +{ + memset( &header_, 0, sizeof header_ ); + assert( offsetof (header_t,device_flags) == header_size - 1 ); + assert( offsetof (ext_header_t,msx_audio_vol) == ext_header_size - 1 ); + RETURN_ERR( rom.load( in, header_size, STATIC_CAST(header_t*,&header_), 0 ) ); + + RETURN_ERR( check_kss_header( header_.tag ) ); + + if ( header_.tag [3] == 'C' ) + { + if ( header_.extra_header ) + { + header_.extra_header = 0; + set_warning( "Unknown data in header" ); + } + if ( header_.device_flags & ~0x0F ) + { + header_.device_flags &= 0x0F; + set_warning( "Unknown data in header" ); + } + } + else + { + ext_header_t& ext = header_; + memcpy( &ext, rom.begin(), min( (int) ext_header_size, (int) header_.extra_header ) ); + if ( header_.extra_header > 0x10 ) + set_warning( "Unknown data in header" ); + } + + if ( header_.device_flags & 0x09 ) + set_warning( "FM sound not supported" ); + + scc_enabled = 0xC000; + if ( header_.device_flags & 0x04 ) + scc_enabled = 0; + + if ( header_.device_flags & 0x02 && !sn ) + CHECK_ALLOC( sn = BLARGG_NEW( Sms_Apu ) ); + + set_voice_count( osc_count ); + + return setup_buffer( ::clock_rate ); +} + +void Kss_Emu::update_eq( blip_eq_t const& eq ) +{ + ay.treble_eq( eq ); + scc.treble_eq( eq ); + if ( sn ) + sn->treble_eq( eq ); +} + +void Kss_Emu::set_voice( int i, Blip_Buffer* center, Blip_Buffer* left, Blip_Buffer* right ) +{ + int i2 = i - ay.osc_count; + if ( i2 >= 0 ) + scc.osc_output( i2, center ); + else + ay.osc_output( i, center ); + if ( sn && i < sn->osc_count ) + sn->osc_output( i, center, left, right ); +} + +// Emulation + +void Kss_Emu::set_tempo_( double t ) +{ + blip_time_t period = + (header_.device_flags & 0x40 ? ::clock_rate / 50 : ::clock_rate / 60); + play_period = blip_time_t (period / t); +} + +blargg_err_t Kss_Emu::start_track_( int track ) +{ + RETURN_ERR( Classic_Emu::start_track_( track ) ); + + memset( ram, 0xC9, 0x4000 ); + memset( ram + 0x4000, 0, sizeof ram - 0x4000 ); + + // copy driver code to lo RAM + static byte const bios [] = { + 0xD3, 0xA0, 0xF5, 0x7B, 0xD3, 0xA1, 0xF1, 0xC9, // $0001: WRTPSG + 0xD3, 0xA0, 0xDB, 0xA2, 0xC9 // $0009: RDPSG + }; + static byte const vectors [] = { + 0xC3, 0x01, 0x00, // $0093: WRTPSG vector + 0xC3, 0x09, 0x00, // $0096: RDPSG vector + }; + memcpy( ram + 0x01, bios, sizeof bios ); + memcpy( ram + 0x93, vectors, sizeof vectors ); + + // copy non-banked data into RAM + unsigned load_addr = get_le16( header_.load_addr ); + long orig_load_size = get_le16( header_.load_size ); + long load_size = min( orig_load_size, rom.file_size() ); + load_size = min( load_size, long (mem_size - load_addr) ); + if ( load_size != orig_load_size ) + set_warning( "Excessive data size" ); + memcpy( ram + load_addr, rom.begin() + header_.extra_header, load_size ); + + rom.set_addr( -load_size - header_.extra_header ); + + // check available bank data + blargg_long const bank_size = this->bank_size(); + int max_banks = (rom.file_size() - load_size + bank_size - 1) / bank_size; + bank_count = header_.bank_mode & 0x7F; + if ( bank_count > max_banks ) + { + bank_count = max_banks; + set_warning( "Bank data missing" ); + } + //debug_printf( "load_size : $%X\n", load_size ); + //debug_printf( "bank_size : $%X\n", bank_size ); + //debug_printf( "bank_count: %d (%d claimed)\n", bank_count, header_.bank_mode & 0x7F ); + + ram [idle_addr] = 0xFF; + cpu::reset( unmapped_write, unmapped_read ); + cpu::map_mem( 0, mem_size, ram, ram ); + + ay.reset(); + scc.reset(); + if ( sn ) + sn->reset(); + r.sp = 0xF380; + ram [--r.sp] = idle_addr >> 8; + ram [--r.sp] = idle_addr & 0xFF; + r.b.a = track; + r.pc = get_le16( header_.init_addr ); + next_play = play_period; + scc_accessed = false; + gain_updated = false; + update_gain(); + ay_latch = 0; + + return 0; +} + +void Kss_Emu::set_bank( int logical, int physical ) +{ + unsigned const bank_size = this->bank_size(); + + unsigned addr = 0x8000; + if ( logical && bank_size == 8 * 1024 ) + addr = 0xA000; + + physical -= header_.first_bank; + if ( (unsigned) physical >= (unsigned) bank_count ) + { + byte* data = ram + addr; + cpu::map_mem( addr, bank_size, data, data ); + } + else + { + long phys = physical * (blargg_long) bank_size; + for ( unsigned offset = 0; offset < bank_size; offset += page_size ) + cpu::map_mem( addr + offset, page_size, + unmapped_write, rom.at_addr( phys + offset ) ); + } +} + +void Kss_Emu::cpu_write( unsigned addr, int data ) +{ + data &= 0xFF; + switch ( addr ) + { + case 0x9000: + set_bank( 0, data ); + return; + + case 0xB000: + set_bank( 1, data ); + return; + } + + int scc_addr = (addr & 0xDFFF) ^ 0x9800; + if ( scc_addr < scc.reg_count ) + { + scc_accessed = true; + scc.write( time(), scc_addr, data ); + return; + } + + debug_printf( "LD ($%04X),$%02X\n", addr, data ); +} + +void kss_cpu_write( Kss_Cpu* cpu, unsigned addr, int data ) +{ + *cpu->write( addr ) = data; + if ( (addr & STATIC_CAST(Kss_Emu&,*cpu).scc_enabled) == 0x8000 ) + STATIC_CAST(Kss_Emu&,*cpu).cpu_write( addr, data ); +} + +void kss_cpu_out( Kss_Cpu* cpu, cpu_time_t time, unsigned addr, int data ) +{ + data &= 0xFF; + Kss_Emu& emu = STATIC_CAST(Kss_Emu&,*cpu); + switch ( addr & 0xFF ) + { + case 0xA0: + emu.ay_latch = data & 0x0F; + return; + + case 0xA1: + GME_APU_HOOK( &emu, emu.ay_latch, data ); + emu.ay.write( time, emu.ay_latch, data ); + return; + + case 0x06: + if ( emu.sn && (emu.header_.device_flags & 0x04) ) + { + emu.sn->write_ggstereo( time, data ); + return; + } + break; + + case 0x7E: + case 0x7F: + if ( emu.sn ) + { + GME_APU_HOOK( &emu, 16, data ); + emu.sn->write_data( time, data ); + return; + } + break; + + case 0xFE: + emu.set_bank( 0, data ); + return; + + #ifndef NDEBUG + case 0xF1: // FM data + if ( data ) + break; // trap non-zero data + case 0xF0: // FM addr + case 0xA8: // PPI + return; + #endif + } + + debug_printf( "OUT $%04X,$%02X\n", addr, data ); +} + +int kss_cpu_in( Kss_Cpu*, cpu_time_t, unsigned addr ) +{ + //Kss_Emu& emu = STATIC_CAST(Kss_Emu&,*cpu); + //switch ( addr & 0xFF ) + //{ + //} + + debug_printf( "IN $%04X\n", addr ); + return 0; +} + +// Emulation + +blargg_err_t Kss_Emu::run_clocks( blip_time_t& duration, int ) +{ + while ( time() < duration ) + { + blip_time_t end = min( duration, next_play ); + cpu::run( min( duration, next_play ) ); + if ( r.pc == idle_addr ) + set_time( end ); + + if ( time() >= next_play ) + { + next_play += play_period; + if ( r.pc == idle_addr ) + { + if ( !gain_updated ) + { + gain_updated = true; + if ( scc_accessed ) + update_gain(); + } + + ram [--r.sp] = idle_addr >> 8; + ram [--r.sp] = idle_addr & 0xFF; + r.pc = get_le16( header_.play_addr ); + GME_FRAME_HOOK( this ); + } + } + } + + duration = time(); + next_play -= duration; + check( next_play >= 0 ); + adjust_time( -duration ); + ay.end_frame( duration ); + scc.end_frame( duration ); + if ( sn ) + sn->end_frame( duration ); + + return 0; +} diff --git a/libs/gme/gme/Kss_Emu.h b/libs/gme/gme/Kss_Emu.h new file mode 100644 index 000000000..e457f7311 --- /dev/null +++ b/libs/gme/gme/Kss_Emu.h @@ -0,0 +1,95 @@ +// MSX computer KSS music file emulator + +// Game_Music_Emu 0.6.0 +#ifndef KSS_EMU_H +#define KSS_EMU_H + +#include "Classic_Emu.h" +#include "Kss_Scc_Apu.h" +#include "Kss_Cpu.h" +#include "Sms_Apu.h" +#include "Ay_Apu.h" + +class Kss_Emu : private Kss_Cpu, public Classic_Emu { + typedef Kss_Cpu cpu; +public: + // KSS file header + enum { header_size = 0x10 }; + struct header_t + { + byte tag [4]; + byte load_addr [2]; + byte load_size [2]; + byte init_addr [2]; + byte play_addr [2]; + byte first_bank; + byte bank_mode; + byte extra_header; + byte device_flags; + }; + + enum { ext_header_size = 0x10 }; + struct ext_header_t + { + byte data_size [4]; + byte unused [4]; + byte first_track [2]; + byte last_tack [2]; + byte psg_vol; + byte scc_vol; + byte msx_music_vol; + byte msx_audio_vol; + }; + + struct composite_header_t : header_t, ext_header_t { }; + + // Header for currently loaded file + composite_header_t const& header() const { return header_; } + + static gme_type_t static_type() { return gme_kss_type; } +public: + Kss_Emu(); + ~Kss_Emu(); +protected: + blargg_err_t track_info_( track_info_t*, int track ) const; + blargg_err_t load_( Data_Reader& ); + blargg_err_t start_track_( int ); + blargg_err_t run_clocks( blip_time_t&, int ); + void set_tempo_( double ); + void set_voice( int, Blip_Buffer*, Blip_Buffer*, Blip_Buffer* ); + void update_eq( blip_eq_t const& ); + void unload(); +private: + Rom_Data rom; + composite_header_t header_; + + bool scc_accessed; + bool gain_updated; + void update_gain(); + + unsigned scc_enabled; // 0 or 0xC000 + int bank_count; + void set_bank( int logical, int physical ); + blargg_long bank_size() const { return (16 * 1024L) >> (header_.bank_mode >> 7 & 1); } + + blip_time_t play_period; + blip_time_t next_play; + int ay_latch; + + friend void kss_cpu_out( class Kss_Cpu*, cpu_time_t, unsigned addr, int data ); + friend int kss_cpu_in( class Kss_Cpu*, cpu_time_t, unsigned addr ); + void cpu_write( unsigned addr, int data ); + friend void kss_cpu_write( class Kss_Cpu*, unsigned addr, int data ); + + // large items + enum { mem_size = 0x10000 }; + byte ram [mem_size + cpu_padding]; + + Ay_Apu ay; + Scc_Apu scc; + Sms_Apu* sn; + byte unmapped_read [0x100]; + byte unmapped_write [page_size]; +}; + +#endif diff --git a/libs/gme/gme/Kss_Scc_Apu.cpp b/libs/gme/gme/Kss_Scc_Apu.cpp new file mode 100644 index 000000000..1ab14bd00 --- /dev/null +++ b/libs/gme/gme/Kss_Scc_Apu.cpp @@ -0,0 +1,97 @@ +// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/ + +#include "Kss_Scc_Apu.h" + +/* Copyright (C) 2006 Shay Green. This module 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 +module 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 module; if not, write to the Free Software Foundation, +Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + +#include "blargg_source.h" + +// Tones above this frequency are treated as disabled tone at half volume. +// Power of two is more efficient (avoids division). +unsigned const inaudible_freq = 16384; + +int const wave_size = 0x20; + +void Scc_Apu::run_until( blip_time_t end_time ) +{ + for ( int index = 0; index < osc_count; index++ ) + { + osc_t& osc = oscs [index]; + + Blip_Buffer* const output = osc.output; + if ( !output ) + continue; + output->set_modified(); + + blip_time_t period = (regs [0x80 + index * 2 + 1] & 0x0F) * 0x100 + + regs [0x80 + index * 2] + 1; + int volume = 0; + if ( regs [0x8F] & (1 << index) ) + { + blip_time_t inaudible_period = (blargg_ulong) (output->clock_rate() + + inaudible_freq * 32) / (inaudible_freq * 16); + if ( period > inaudible_period ) + volume = (regs [0x8A + index] & 0x0F) * (amp_range / 256 / 15); + } + + BOOST::int8_t const* wave = (BOOST::int8_t*) regs + index * wave_size; + if ( index == osc_count - 1 ) + wave -= wave_size; // last two oscs share wave + { + int amp = wave [osc.phase] * volume; + int delta = amp - osc.last_amp; + if ( delta ) + { + osc.last_amp = amp; + synth.offset( last_time, delta, output ); + } + } + + blip_time_t time = last_time + osc.delay; + if ( time < end_time ) + { + if ( !volume ) + { + // maintain phase + blargg_long count = (end_time - time + period - 1) / period; + osc.phase = (osc.phase + count) & (wave_size - 1); + time += count * period; + } + else + { + + int phase = osc.phase; + int last_wave = wave [phase]; + phase = (phase + 1) & (wave_size - 1); // pre-advance for optimal inner loop + + do + { + int amp = wave [phase]; + phase = (phase + 1) & (wave_size - 1); + int delta = amp - last_wave; + if ( delta ) + { + last_wave = amp; + synth.offset( time, delta * volume, output ); + } + time += period; + } + while ( time < end_time ); + + osc.phase = phase = (phase - 1) & (wave_size - 1); // undo pre-advance + osc.last_amp = wave [phase] * volume; + } + } + osc.delay = time - end_time; + } + last_time = end_time; +} diff --git a/libs/gme/gme/Kss_Scc_Apu.h b/libs/gme/gme/Kss_Scc_Apu.h new file mode 100644 index 000000000..c8c69f118 --- /dev/null +++ b/libs/gme/gme/Kss_Scc_Apu.h @@ -0,0 +1,106 @@ +// Konami SCC sound chip emulator + +// Game_Music_Emu 0.6.0 +#ifndef KSS_SCC_APU_H +#define KSS_SCC_APU_H + +#include "blargg_common.h" +#include "Blip_Buffer.h" +#include + +class Scc_Apu { +public: + // Set buffer to generate all sound into, or disable sound if NULL + void output( Blip_Buffer* ); + + // Reset sound chip + void reset(); + + // Write to register at specified time + enum { reg_count = 0x90 }; + void write( blip_time_t time, int reg, int data ); + + // Run sound to specified time, end current time frame, then start a new + // time frame at time 0. Time frames have no effect on emulation and each + // can be whatever length is convenient. + void end_frame( blip_time_t length ); + +// Additional features + + // Set sound output of specific oscillator to buffer, where index is + // 0 to 4. If buffer is NULL, the specified oscillator is muted. + enum { osc_count = 5 }; + void osc_output( int index, Blip_Buffer* ); + + // Set overall volume (default is 1.0) + void volume( double ); + + // Set treble equalization (see documentation) + void treble_eq( blip_eq_t const& ); + +public: + Scc_Apu(); +private: + enum { amp_range = 0x8000 }; + struct osc_t + { + int delay; + int phase; + int last_amp; + Blip_Buffer* output; + }; + osc_t oscs [osc_count]; + blip_time_t last_time; + unsigned char regs [reg_count]; + Blip_Synth synth; + + void run_until( blip_time_t ); +}; + +inline void Scc_Apu::volume( double v ) { synth.volume( 0.43 / osc_count / amp_range * v ); } + +inline void Scc_Apu::treble_eq( blip_eq_t const& eq ) { synth.treble_eq( eq ); } + +inline void Scc_Apu::osc_output( int index, Blip_Buffer* b ) +{ + assert( (unsigned) index < osc_count ); + oscs [index].output = b; +} + +inline void Scc_Apu::write( blip_time_t time, int addr, int data ) +{ + assert( (unsigned) addr < reg_count ); + run_until( time ); + regs [addr] = data; +} + +inline void Scc_Apu::end_frame( blip_time_t end_time ) +{ + if ( end_time > last_time ) + run_until( end_time ); + last_time -= end_time; + assert( last_time >= 0 ); +} + +inline void Scc_Apu::output( Blip_Buffer* buf ) +{ + for ( int i = 0; i < osc_count; i++ ) + oscs [i].output = buf; +} + +inline Scc_Apu::Scc_Apu() +{ + output( 0 ); +} + +inline void Scc_Apu::reset() +{ + last_time = 0; + + for ( int i = 0; i < osc_count; i++ ) + memset( &oscs [i], 0, offsetof (osc_t,output) ); + + memset( regs, 0, sizeof regs ); +} + +#endif diff --git a/libs/gme/gme/M3u_Playlist.cpp b/libs/gme/gme/M3u_Playlist.cpp new file mode 100644 index 000000000..bbe52b1a7 --- /dev/null +++ b/libs/gme/gme/M3u_Playlist.cpp @@ -0,0 +1,426 @@ +// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/ + +#include "M3u_Playlist.h" +#include "Music_Emu.h" + +#include + +/* Copyright (C) 2006 Shay Green. This module 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 +module 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 module; if not, write to the Free Software Foundation, +Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + +#include "blargg_source.h" + +// gme functions defined here to avoid linking in m3u code unless it's used + +blargg_err_t Gme_File::load_m3u_( blargg_err_t err ) +{ + require( raw_track_count_ ); // file must be loaded first + + if ( !err ) + { + if ( playlist.size() ) + track_count_ = playlist.size(); + + int line = playlist.first_error(); + if ( line ) + { + // avoid using bloated printf() + char* out = &playlist_warning [sizeof playlist_warning]; + *--out = 0; + do { + *--out = line % 10 + '0'; + } while ( (line /= 10) > 0 ); + + static const char str [] = "Problem in m3u at line "; + out -= sizeof str - 1; + memcpy( out, str, sizeof str - 1 ); + set_warning( out ); + } + } + return err; +} + +blargg_err_t Gme_File::load_m3u( const char* path ) { return load_m3u_( playlist.load( path ) ); } + +blargg_err_t Gme_File::load_m3u( Data_Reader& in ) { return load_m3u_( playlist.load( in ) ); } + +BLARGG_EXPORT gme_err_t gme_load_m3u( Music_Emu* me, const char* path ) { return me->load_m3u( path ); } + +BLARGG_EXPORT gme_err_t gme_load_m3u_data( Music_Emu* me, const void* data, long size ) +{ + Mem_File_Reader in( data, size ); + return me->load_m3u( in ); +} + + + +static char* skip_white( char* in ) +{ + while ( *in == ' ' ) + in++; + return in; +} + +inline unsigned from_dec( unsigned n ) { return n - '0'; } + +static char* parse_filename( char* in, M3u_Playlist::entry_t& entry ) +{ + entry.file = in; + entry.type = ""; + char* out = in; + while ( 1 ) + { + int c = *in; + if ( !c ) break; + in++; + + if ( c == ',' ) // commas in filename + { + char* p = skip_white( in ); + if ( *p == '$' || from_dec( *p ) <= 9 ) + { + in = p; + break; + } + } + + if ( c == ':' && in [0] == ':' && in [1] && in [2] != ',' ) // ::type suffix + { + entry.type = ++in; + while ( (c = *in) != 0 && c != ',' ) + in++; + if ( c == ',' ) + { + *in++ = 0; // terminate type + in = skip_white( in ); + } + break; + } + + if ( c == '\\' ) // \ prefix for special characters + { + c = *in; + if ( !c ) break; + in++; + } + *out++ = (char) c; + } + *out = 0; // terminate string + return in; +} + +static char* next_field( char* in, int* result ) +{ + while ( 1 ) + { + in = skip_white( in ); + + if ( !*in ) + break; + + if ( *in == ',' ) + { + in++; + break; + } + + *result = 1; + in++; + } + return skip_white( in ); +} + +static char* parse_int_( char* in, int* out ) +{ + int n = 0; + while ( 1 ) + { + unsigned d = from_dec( *in ); + if ( d > 9 ) + break; + in++; + n = n * 10 + d; + *out = n; + } + return in; +} + +static char* parse_int( char* in, int* out, int* result ) +{ + return next_field( parse_int_( in, out ), result ); +} + +// Returns 16 or greater if not hex +inline int from_hex_char( int h ) +{ + h -= 0x30; + if ( (unsigned) h > 9 ) + h = ((h - 0x11) & 0xDF) + 10; + return h; +} + +static char* parse_track( char* in, M3u_Playlist::entry_t& entry, int* result ) +{ + if ( *in == '$' ) + { + in++; + int n = 0; + while ( 1 ) + { + int h = from_hex_char( *in ); + if ( h > 15 ) + break; + in++; + n = n * 16 + h; + entry.track = n; + } + } + else + { + in = parse_int_( in, &entry.track ); + if ( entry.track >= 0 ) + entry.decimal_track = 1; + } + return next_field( in, result ); +} + +static char* parse_time_( char* in, int* out ) +{ + *out = -1; + int n = -1; + in = parse_int_( in, &n ); + if ( n >= 0 ) + { + *out = n; + if ( *in == ':' ) + { + n = -1; + in = parse_int_( in + 1, &n ); + if ( n >= 0 ) + *out = *out * 60 + n; + } + } + return in; +} + +static char* parse_time( char* in, int* out, int* result ) +{ + return next_field( parse_time_( in, out ), result ); +} + +static char* parse_name( char* in ) +{ + char* out = in; + while ( 1 ) + { + int c = *in; + if ( !c ) break; + in++; + + if ( c == ',' ) // commas in string + { + char* p = skip_white( in ); + if ( *p == ',' || *p == '-' || from_dec( *p ) <= 9 ) + { + in = p; + break; + } + } + + if ( c == '\\' ) // \ prefix for special characters + { + c = *in; + if ( !c ) break; + in++; + } + *out++ = (char) c; + } + *out = 0; // terminate string + return in; +} + +static int parse_line( char* in, M3u_Playlist::entry_t& entry ) +{ + int result = 0; + + // file + entry.file = in; + entry.type = ""; + in = parse_filename( in, entry ); + + // track + entry.track = -1; + entry.decimal_track = 0; + in = parse_track( in, entry, &result ); + + // name + entry.name = in; + in = parse_name( in ); + + // time + entry.length = -1; + in = parse_time( in, &entry.length, &result ); + + // loop + entry.intro = -1; + entry.loop = -1; + if ( *in == '-' ) + { + entry.loop = entry.length; + in++; + } + else + { + in = parse_time_( in, &entry.loop ); + if ( entry.loop >= 0 ) + { + entry.intro = 0; + if ( *in == '-' ) // trailing '-' means that intro length was specified + { + in++; + entry.intro = entry.loop; + entry.loop = entry.length - entry.intro; + } + } + } + in = next_field( in, &result ); + + // fade + entry.fade = -1; + in = parse_time( in, &entry.fade, &result ); + + // repeat + entry.repeat = -1; + in = parse_int( in, &entry.repeat, &result ); + + return result; +} + +static void parse_comment( char* in, M3u_Playlist::info_t& info, bool first ) +{ + in = skip_white( in + 1 ); + const char* field = in; + while ( *in && *in != ':' ) + in++; + + if ( *in == ':' ) + { + const char* text = skip_white( in + 1 ); + if ( *text ) + { + *in = 0; + if ( !strcmp( "Composer", field ) ) info.composer = text; + else if ( !strcmp( "Engineer", field ) ) info.engineer = text; + else if ( !strcmp( "Ripping" , field ) ) info.ripping = text; + else if ( !strcmp( "Tagging" , field ) ) info.tagging = text; + else + text = 0; + if ( text ) + return; + *in = ':'; + } + } + + if ( first ) + info.title = field; +} + +blargg_err_t M3u_Playlist::parse_() +{ + info_.title = ""; + info_.composer = ""; + info_.engineer = ""; + info_.ripping = ""; + info_.tagging = ""; + + int const CR = 13; + int const LF = 10; + + data.end() [-1] = LF; // terminate input + + first_error_ = 0; + bool first_comment = true; + int line = 0; + int count = 0; + char* in = data.begin(); + while ( in < data.end() ) + { + // find end of line and terminate it + line++; + char* begin = in; + while ( *in != CR && *in != LF ) + { + if ( !*in ) + return "Not an m3u playlist"; + in++; + } + if ( in [0] == CR && in [1] == LF ) // treat CR,LF as a single line + *in++ = 0; + *in++ = 0; + + // parse line + if ( *begin == '#' ) + { + parse_comment( begin, info_, first_comment ); + first_comment = false; + } + else if ( *begin ) + { + if ( (int) entries.size() <= count ) + RETURN_ERR( entries.resize( count * 2 + 64 ) ); + + if ( !parse_line( begin, entries [count] ) ) + count++; + else if ( !first_error_ ) + first_error_ = line; + first_comment = false; + } + } + if ( count <= 0 ) + return "Not an m3u playlist"; + + if ( !(info_.composer [0] | info_.engineer [0] | info_.ripping [0] | info_.tagging [0]) ) + info_.title = ""; + + return entries.resize( count ); +} + +blargg_err_t M3u_Playlist::parse() +{ + blargg_err_t err = parse_(); + if ( err ) + { + entries.clear(); + data.clear(); + } + return err; +} + +blargg_err_t M3u_Playlist::load( Data_Reader& in ) +{ + RETURN_ERR( data.resize( in.remain() + 1 ) ); + RETURN_ERR( in.read( data.begin(), data.size() - 1 ) ); + return parse(); +} + +blargg_err_t M3u_Playlist::load( const char* path ) +{ + GME_FILE_READER in; + RETURN_ERR( in.open( path ) ); + return load( in ); +} + +blargg_err_t M3u_Playlist::load( void const* in, long size ) +{ + RETURN_ERR( data.resize( size + 1 ) ); + memcpy( data.begin(), in, size ); + return parse(); +} diff --git a/libs/gme/gme/M3u_Playlist.h b/libs/gme/gme/M3u_Playlist.h new file mode 100644 index 000000000..e764cb936 --- /dev/null +++ b/libs/gme/gme/M3u_Playlist.h @@ -0,0 +1,67 @@ +// M3U playlist file parser, with support for subtrack information + +// Game_Music_Emu 0.6.0 +#ifndef M3U_PLAYLIST_H +#define M3U_PLAYLIST_H + +#include "blargg_common.h" +#include "Data_Reader.h" + +class M3u_Playlist { +public: + // Load playlist data + blargg_err_t load( const char* path ); + blargg_err_t load( Data_Reader& in ); + blargg_err_t load( void const* data, long size ); + + // Line number of first parse error, 0 if no error. Any lines with parse + // errors are ignored. + int first_error() const { return first_error_; } + + struct info_t + { + const char* title; + const char* composer; + const char* engineer; + const char* ripping; + const char* tagging; + }; + info_t const& info() const { return info_; } + + struct entry_t + { + const char* file; // filename without stupid ::TYPE suffix + const char* type; // if filename has ::TYPE suffix, this will be "TYPE". "" if none. + const char* name; + bool decimal_track; // true if track was specified in hex + // integers are -1 if not present + int track; // 1-based + int length; // seconds + int intro; + int loop; + int fade; + int repeat; // count + }; + entry_t const& operator [] ( int i ) const { return entries [i]; } + int size() const { return entries.size(); } + + void clear(); + +private: + blargg_vector entries; + blargg_vector data; + int first_error_; + info_t info_; + + blargg_err_t parse(); + blargg_err_t parse_(); +}; + +inline void M3u_Playlist::clear() +{ + first_error_ = 0; + entries.clear(); + data.clear(); +} + +#endif diff --git a/libs/gme/gme/Multi_Buffer.cpp b/libs/gme/gme/Multi_Buffer.cpp new file mode 100644 index 000000000..57f93b317 --- /dev/null +++ b/libs/gme/gme/Multi_Buffer.cpp @@ -0,0 +1,232 @@ +// Blip_Buffer 0.4.1. http://www.slack.net/~ant/ + +#include "Multi_Buffer.h" + +/* Copyright (C) 2003-2006 Shay Green. This module 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 +module 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 module; if not, write to the Free Software Foundation, +Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + +#include "blargg_source.h" + +#ifdef BLARGG_ENABLE_OPTIMIZER + #include BLARGG_ENABLE_OPTIMIZER +#endif + +Multi_Buffer::Multi_Buffer( int spf ) : samples_per_frame_( spf ) +{ + length_ = 0; + sample_rate_ = 0; + channels_changed_count_ = 1; +} + +blargg_err_t Multi_Buffer::set_channel_count( int ) { return 0; } + +// Silent_Buffer + +Silent_Buffer::Silent_Buffer() : Multi_Buffer( 1 ) // 0 channels would probably confuse +{ + // TODO: better to use empty Blip_Buffer so caller never has to check for NULL? + chan.left = 0; + chan.center = 0; + chan.right = 0; +} + +// Mono_Buffer + +Mono_Buffer::Mono_Buffer() : Multi_Buffer( 1 ) +{ + chan.center = &buf; + chan.left = &buf; + chan.right = &buf; +} + +Mono_Buffer::~Mono_Buffer() { } + +blargg_err_t Mono_Buffer::set_sample_rate( long rate, int msec ) +{ + RETURN_ERR( buf.set_sample_rate( rate, msec ) ); + return Multi_Buffer::set_sample_rate( buf.sample_rate(), buf.length() ); +} + +// Stereo_Buffer + +Stereo_Buffer::Stereo_Buffer() : Multi_Buffer( 2 ) +{ + chan.center = &bufs [0]; + chan.left = &bufs [1]; + chan.right = &bufs [2]; +} + +Stereo_Buffer::~Stereo_Buffer() { } + +blargg_err_t Stereo_Buffer::set_sample_rate( long rate, int msec ) +{ + for ( int i = 0; i < buf_count; i++ ) + RETURN_ERR( bufs [i].set_sample_rate( rate, msec ) ); + return Multi_Buffer::set_sample_rate( bufs [0].sample_rate(), bufs [0].length() ); +} + +void Stereo_Buffer::clock_rate( long rate ) +{ + for ( int i = 0; i < buf_count; i++ ) + bufs [i].clock_rate( rate ); +} + +void Stereo_Buffer::bass_freq( int bass ) +{ + for ( unsigned i = 0; i < buf_count; i++ ) + bufs [i].bass_freq( bass ); +} + +void Stereo_Buffer::clear() +{ + stereo_added = 0; + was_stereo = false; + for ( int i = 0; i < buf_count; i++ ) + bufs [i].clear(); +} + +void Stereo_Buffer::end_frame( blip_time_t clock_count ) +{ + stereo_added = 0; + for ( unsigned i = 0; i < buf_count; i++ ) + { + stereo_added |= bufs [i].clear_modified() << i; + bufs [i].end_frame( clock_count ); + } +} + +long Stereo_Buffer::read_samples( blip_sample_t* out, long count ) +{ + require( !(count & 1) ); // count must be even + count = (unsigned) count / 2; + + long avail = bufs [0].samples_avail(); + if ( count > avail ) + count = avail; + if ( count ) + { + int bufs_used = stereo_added | was_stereo; + //debug_printf( "%X\n", bufs_used ); + if ( bufs_used <= 1 ) + { + mix_mono( out, count ); + bufs [0].remove_samples( count ); + bufs [1].remove_silence( count ); + bufs [2].remove_silence( count ); + } + else if ( bufs_used & 1 ) + { + mix_stereo( out, count ); + bufs [0].remove_samples( count ); + bufs [1].remove_samples( count ); + bufs [2].remove_samples( count ); + } + else + { + mix_stereo_no_center( out, count ); + bufs [0].remove_silence( count ); + bufs [1].remove_samples( count ); + bufs [2].remove_samples( count ); + } + + // to do: this might miss opportunities for optimization + if ( !bufs [0].samples_avail() ) + { + was_stereo = stereo_added; + stereo_added = 0; + } + } + + return count * 2; +} + +void Stereo_Buffer::mix_stereo( blip_sample_t* out_, blargg_long count ) +{ + blip_sample_t* BLIP_RESTRICT out = out_; + int const bass = BLIP_READER_BASS( bufs [1] ); + BLIP_READER_BEGIN( left, bufs [1] ); + BLIP_READER_BEGIN( right, bufs [2] ); + BLIP_READER_BEGIN( center, bufs [0] ); + + for ( ; count; --count ) + { + int c = BLIP_READER_READ( center ); + blargg_long l = c + BLIP_READER_READ( left ); + blargg_long r = c + BLIP_READER_READ( right ); + if ( (BOOST::int16_t) l != l ) + l = 0x7FFF - (l >> 24); + + BLIP_READER_NEXT( center, bass ); + if ( (BOOST::int16_t) r != r ) + r = 0x7FFF - (r >> 24); + + BLIP_READER_NEXT( left, bass ); + BLIP_READER_NEXT( right, bass ); + + out [0] = l; + out [1] = r; + out += 2; + } + + BLIP_READER_END( center, bufs [0] ); + BLIP_READER_END( right, bufs [2] ); + BLIP_READER_END( left, bufs [1] ); +} + +void Stereo_Buffer::mix_stereo_no_center( blip_sample_t* out_, blargg_long count ) +{ + blip_sample_t* BLIP_RESTRICT out = out_; + int const bass = BLIP_READER_BASS( bufs [1] ); + BLIP_READER_BEGIN( left, bufs [1] ); + BLIP_READER_BEGIN( right, bufs [2] ); + + for ( ; count; --count ) + { + blargg_long l = BLIP_READER_READ( left ); + if ( (BOOST::int16_t) l != l ) + l = 0x7FFF - (l >> 24); + + blargg_long r = BLIP_READER_READ( right ); + if ( (BOOST::int16_t) r != r ) + r = 0x7FFF - (r >> 24); + + BLIP_READER_NEXT( left, bass ); + BLIP_READER_NEXT( right, bass ); + + out [0] = l; + out [1] = r; + out += 2; + } + + BLIP_READER_END( right, bufs [2] ); + BLIP_READER_END( left, bufs [1] ); +} + +void Stereo_Buffer::mix_mono( blip_sample_t* out_, blargg_long count ) +{ + blip_sample_t* BLIP_RESTRICT out = out_; + int const bass = BLIP_READER_BASS( bufs [0] ); + BLIP_READER_BEGIN( center, bufs [0] ); + + for ( ; count; --count ) + { + blargg_long s = BLIP_READER_READ( center ); + if ( (BOOST::int16_t) s != s ) + s = 0x7FFF - (s >> 24); + + BLIP_READER_NEXT( center, bass ); + out [0] = s; + out [1] = s; + out += 2; + } + + BLIP_READER_END( center, bufs [0] ); +} diff --git a/libs/gme/gme/Multi_Buffer.h b/libs/gme/gme/Multi_Buffer.h new file mode 100644 index 000000000..82c8b3ab5 --- /dev/null +++ b/libs/gme/gme/Multi_Buffer.h @@ -0,0 +1,158 @@ +// Multi-channel sound buffer interface, and basic mono and stereo buffers + +// Blip_Buffer 0.4.1 +#ifndef MULTI_BUFFER_H +#define MULTI_BUFFER_H + +#include "blargg_common.h" +#include "Blip_Buffer.h" + +// Interface to one or more Blip_Buffers mapped to one or more channels +// consisting of left, center, and right buffers. +class Multi_Buffer { +public: + Multi_Buffer( int samples_per_frame ); + virtual ~Multi_Buffer() { } + + // Set the number of channels available + virtual blargg_err_t set_channel_count( int ); + + // Get indexed channel, from 0 to channel count - 1 + struct channel_t { + Blip_Buffer* center; + Blip_Buffer* left; + Blip_Buffer* right; + }; + enum { type_index_mask = 0xFF }; + enum { wave_type = 0x100, noise_type = 0x200, mixed_type = wave_type | noise_type }; + virtual channel_t channel( int index, int type ) = 0; + + // See Blip_Buffer.h + virtual blargg_err_t set_sample_rate( long rate, int msec = blip_default_length ) = 0; + virtual void clock_rate( long ) = 0; + virtual void bass_freq( int ) = 0; + virtual void clear() = 0; + long sample_rate() const; + + // Length of buffer, in milliseconds + int length() const; + + // See Blip_Buffer.h + virtual void end_frame( blip_time_t ) = 0; + + // Number of samples per output frame (1 = mono, 2 = stereo) + int samples_per_frame() const; + + // Count of changes to channel configuration. Incremented whenever + // a change is made to any of the Blip_Buffers for any channel. + unsigned channels_changed_count() { return channels_changed_count_; } + + // See Blip_Buffer.h + virtual long read_samples( blip_sample_t*, long ) = 0; + virtual long samples_avail() const = 0; + +public: + BLARGG_DISABLE_NOTHROW +protected: + void channels_changed() { channels_changed_count_++; } +private: + // noncopyable + Multi_Buffer( const Multi_Buffer& ); + Multi_Buffer& operator = ( const Multi_Buffer& ); + + unsigned channels_changed_count_; + long sample_rate_; + int length_; + int const samples_per_frame_; +}; + +// Uses a single buffer and outputs mono samples. +class Mono_Buffer : public Multi_Buffer { + Blip_Buffer buf; + channel_t chan; +public: + // Buffer used for all channels + Blip_Buffer* center() { return &buf; } + +public: + Mono_Buffer(); + ~Mono_Buffer(); + blargg_err_t set_sample_rate( long rate, int msec = blip_default_length ); + void clock_rate( long rate ) { buf.clock_rate( rate ); } + void bass_freq( int freq ) { buf.bass_freq( freq ); } + void clear() { buf.clear(); } + long samples_avail() const { return buf.samples_avail(); } + long read_samples( blip_sample_t* p, long s ) { return buf.read_samples( p, s ); } + channel_t channel( int, int ) { return chan; } + void end_frame( blip_time_t t ) { buf.end_frame( t ); } +}; + +// Uses three buffers (one for center) and outputs stereo sample pairs. +class Stereo_Buffer : public Multi_Buffer { +public: + + // Buffers used for all channels + Blip_Buffer* center() { return &bufs [0]; } + Blip_Buffer* left() { return &bufs [1]; } + Blip_Buffer* right() { return &bufs [2]; } + +public: + Stereo_Buffer(); + ~Stereo_Buffer(); + blargg_err_t set_sample_rate( long, int msec = blip_default_length ); + void clock_rate( long ); + void bass_freq( int ); + void clear(); + channel_t channel( int, int ) { return chan; } + void end_frame( blip_time_t ); + + long samples_avail() const { return bufs [0].samples_avail() * 2; } + long read_samples( blip_sample_t*, long ); + +private: + enum { buf_count = 3 }; + Blip_Buffer bufs [buf_count]; + channel_t chan; + int stereo_added; + int was_stereo; + + void mix_stereo_no_center( blip_sample_t*, blargg_long ); + void mix_stereo( blip_sample_t*, blargg_long ); + void mix_mono( blip_sample_t*, blargg_long ); +}; + +// Silent_Buffer generates no samples, useful where no sound is wanted +class Silent_Buffer : public Multi_Buffer { + channel_t chan; +public: + Silent_Buffer(); + blargg_err_t set_sample_rate( long rate, int msec = blip_default_length ); + void clock_rate( long ) { } + void bass_freq( int ) { } + void clear() { } + channel_t channel( int, int ) { return chan; } + void end_frame( blip_time_t ) { } + long samples_avail() const { return 0; } + long read_samples( blip_sample_t*, long ) { return 0; } +}; + + +inline blargg_err_t Multi_Buffer::set_sample_rate( long rate, int msec ) +{ + sample_rate_ = rate; + length_ = msec; + return 0; +} + +inline blargg_err_t Silent_Buffer::set_sample_rate( long rate, int msec ) +{ + return Multi_Buffer::set_sample_rate( rate, msec ); +} + +inline int Multi_Buffer::samples_per_frame() const { return samples_per_frame_; } + +inline long Multi_Buffer::sample_rate() const { return sample_rate_; } + +inline int Multi_Buffer::length() const { return length_; } + +#endif diff --git a/libs/gme/gme/Music_Emu.cpp b/libs/gme/gme/Music_Emu.cpp new file mode 100644 index 000000000..30b25dcfc --- /dev/null +++ b/libs/gme/gme/Music_Emu.cpp @@ -0,0 +1,412 @@ +// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/ + +#include "Music_Emu.h" + +#include "Multi_Buffer.h" +#include + +/* Copyright (C) 2003-2006 Shay Green. This module 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 +module 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 module; if not, write to the Free Software Foundation, +Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + +#include "blargg_source.h" + +int const stereo = 2; // number of channels for stereo +int const silence_max = 6; // seconds +int const silence_threshold = 0x10; +long const fade_block_size = 512; +int const fade_shift = 8; // fade ends with gain at 1.0 / (1 << fade_shift) + +Music_Emu::equalizer_t const Music_Emu::tv_eq = + Music_Emu::make_equalizer( -8.0, 180 ); + +void Music_Emu::clear_track_vars() +{ + current_track_ = -1; + out_time = 0; + emu_time = 0; + emu_track_ended_ = true; + track_ended_ = true; + fade_start = INT_MAX / 2 + 1; + fade_step = 1; + silence_time = 0; + silence_count = 0; + buf_remain = 0; + warning(); // clear warning +} + +void Music_Emu::unload() +{ + voice_count_ = 0; + clear_track_vars(); + Gme_File::unload(); +} + +Music_Emu::Music_Emu() +{ + effects_buffer = 0; + + sample_rate_ = 0; + mute_mask_ = 0; + tempo_ = 1.0; + gain_ = 1.0; + + // defaults + max_initial_silence = 2; + silence_lookahead = 3; + ignore_silence_ = false; + equalizer_.treble = -1.0; + equalizer_.bass = 60; + + static const char* const names [] = { + "Voice 1", "Voice 2", "Voice 3", "Voice 4", + "Voice 5", "Voice 6", "Voice 7", "Voice 8" + }; + set_voice_names( names ); + Music_Emu::unload(); // non-virtual +} + +Music_Emu::~Music_Emu() { delete effects_buffer; } + +blargg_err_t Music_Emu::set_sample_rate( long rate ) +{ + require( !sample_rate() ); // sample rate can't be changed once set + RETURN_ERR( set_sample_rate_( rate ) ); + RETURN_ERR( buf.resize( buf_size ) ); + sample_rate_ = rate; + return 0; +} + +void Music_Emu::pre_load() +{ + require( sample_rate() ); // set_sample_rate() must be called before loading a file + Gme_File::pre_load(); +} + +void Music_Emu::set_equalizer( equalizer_t const& eq ) +{ + equalizer_ = eq; + set_equalizer_( eq ); +} + +void Music_Emu::mute_voice( int index, bool mute ) +{ + require( (unsigned) index < (unsigned) voice_count() ); + int bit = 1 << index; + int mask = mute_mask_ | bit; + if ( !mute ) + mask ^= bit; + mute_voices( mask ); +} + +void Music_Emu::mute_voices( int mask ) +{ + require( sample_rate() ); // sample rate must be set first + mute_mask_ = mask; + mute_voices_( mask ); +} + +void Music_Emu::set_tempo( double t ) +{ + require( sample_rate() ); // sample rate must be set first + double const min = 0.02; + double const max = 4.00; + if ( t < min ) t = min; + if ( t > max ) t = max; + tempo_ = t; + set_tempo_( t ); +} + +void Music_Emu::post_load_() +{ + set_tempo( tempo_ ); + remute_voices(); +} + +blargg_err_t Music_Emu::start_track( int track ) +{ + clear_track_vars(); + + int remapped = track; + RETURN_ERR( remap_track_( &remapped ) ); + current_track_ = track; + RETURN_ERR( start_track_( remapped ) ); + + emu_track_ended_ = false; + track_ended_ = false; + + if ( !ignore_silence_ ) + { + // play until non-silence or end of track + for ( long end = max_initial_silence * stereo * sample_rate(); emu_time < end; ) + { + fill_buf(); + if ( buf_remain | (int) emu_track_ended_ ) + break; + } + + emu_time = buf_remain; + out_time = 0; + silence_time = 0; + silence_count = 0; + } + return track_ended() ? warning() : 0; +} + +void Music_Emu::end_track_if_error( blargg_err_t err ) +{ + if ( err ) + { + emu_track_ended_ = true; + set_warning( err ); + } +} + +// Tell/Seek + +blargg_long Music_Emu::msec_to_samples( blargg_long msec ) const +{ + blargg_long sec = msec / 1000; + msec -= sec * 1000; + return (sec * sample_rate() + msec * sample_rate() / 1000) * stereo; +} + +long Music_Emu::tell() const +{ + blargg_long rate = sample_rate() * stereo; + blargg_long sec = out_time / rate; + return sec * 1000 + (out_time - sec * rate) * 1000 / rate; +} + +blargg_err_t Music_Emu::seek( long msec ) +{ + blargg_long time = msec_to_samples( msec ); + if ( time < out_time ) + RETURN_ERR( start_track( current_track_ ) ); + return skip( time - out_time ); +} + +blargg_err_t Music_Emu::skip( long count ) +{ + require( current_track() >= 0 ); // start_track() must have been called already + out_time += count; + + // remove from silence and buf first + { + long n = min( count, silence_count ); + silence_count -= n; + count -= n; + + n = min( count, buf_remain ); + buf_remain -= n; + count -= n; + } + + if ( count && !emu_track_ended_ ) + { + emu_time += count; + end_track_if_error( skip_( count ) ); + } + + if ( !(silence_count | buf_remain) ) // caught up to emulator, so update track ended + track_ended_ |= emu_track_ended_; + + return 0; +} + +blargg_err_t Music_Emu::skip_( long count ) +{ + // for long skip, mute sound + const long threshold = 30000; + if ( count > threshold ) + { + int saved_mute = mute_mask_; + mute_voices( ~0 ); + + while ( count > threshold / 2 && !emu_track_ended_ ) + { + RETURN_ERR( play_( buf_size, buf.begin() ) ); + count -= buf_size; + } + + mute_voices( saved_mute ); + } + + while ( count && !emu_track_ended_ ) + { + long n = buf_size; + if ( n > count ) + n = count; + count -= n; + RETURN_ERR( play_( n, buf.begin() ) ); + } + return 0; +} + +// Fading + +void Music_Emu::set_fade( long start_msec, long length_msec ) +{ + fade_step = sample_rate() * length_msec / (fade_block_size * fade_shift * 1000 / stereo); + fade_start = msec_to_samples( start_msec ); +} + +// unit / pow( 2.0, (double) x / step ) +static int int_log( blargg_long x, int step, int unit ) +{ + int shift = x / step; + int fraction = (x - shift * step) * unit / step; + return ((unit - fraction) + (fraction >> 1)) >> shift; +} + +void Music_Emu::handle_fade( long out_count, sample_t* out ) +{ + for ( int i = 0; i < out_count; i += fade_block_size ) + { + int const shift = 14; + int const unit = 1 << shift; + int gain = int_log( (out_time + i - fade_start) / fade_block_size, + fade_step, unit ); + if ( gain < (unit >> fade_shift) ) + track_ended_ = emu_track_ended_ = true; + + sample_t* io = &out [i]; + for ( int count = min( fade_block_size, out_count - i ); count; --count ) + { + *io = sample_t ((*io * gain) >> shift); + ++io; + } + } +} + +// Silence detection + +void Music_Emu::emu_play( long count, sample_t* out ) +{ + check( current_track_ >= 0 ); + emu_time += count; + if ( current_track_ >= 0 && !emu_track_ended_ ) + end_track_if_error( play_( count, out ) ); + else + memset( out, 0, count * sizeof *out ); +} + +// number of consecutive silent samples at end +static long count_silence( Music_Emu::sample_t* begin, long size ) +{ + Music_Emu::sample_t first = *begin; + *begin = silence_threshold; // sentinel + Music_Emu::sample_t* p = begin + size; + while ( (unsigned) (*--p + silence_threshold / 2) <= (unsigned) silence_threshold ) { } + *begin = first; + return size - (p - begin); +} + +// fill internal buffer and check it for silence +void Music_Emu::fill_buf() +{ + assert( !buf_remain ); + if ( !emu_track_ended_ ) + { + emu_play( buf_size, buf.begin() ); + long silence = count_silence( buf.begin(), buf_size ); + if ( silence < buf_size ) + { + silence_time = emu_time - silence; + buf_remain = buf_size; + return; + } + } + silence_count += buf_size; +} + +blargg_err_t Music_Emu::play( long out_count, sample_t* out ) +{ + if ( track_ended_ ) + { + memset( out, 0, out_count * sizeof *out ); + } + else + { + require( current_track() >= 0 ); + require( out_count % stereo == 0 ); + + assert( emu_time >= out_time ); + + // prints nifty graph of how far ahead we are when searching for silence + //debug_printf( "%*s \n", int ((emu_time - out_time) * 7 / sample_rate()), "*" ); + + long pos = 0; + if ( silence_count ) + { + // during a run of silence, run emulator at >=2x speed so it gets ahead + long ahead_time = silence_lookahead * (out_time + out_count - silence_time) + silence_time; + while ( emu_time < ahead_time && !(buf_remain | emu_track_ended_) ) + fill_buf(); + + // fill with silence + pos = min( silence_count, out_count ); + memset( out, 0, pos * sizeof *out ); + silence_count -= pos; + + if ( emu_time - silence_time > silence_max * stereo * sample_rate() ) + { + track_ended_ = emu_track_ended_ = true; + silence_count = 0; + buf_remain = 0; + } + } + + if ( buf_remain ) + { + // empty silence buf + long n = min( buf_remain, out_count - pos ); + memcpy( &out [pos], buf.begin() + (buf_size - buf_remain), n * sizeof *out ); + buf_remain -= n; + pos += n; + } + + // generate remaining samples normally + long remain = out_count - pos; + if ( remain ) + { + emu_play( remain, out + pos ); + track_ended_ |= emu_track_ended_; + + if ( !ignore_silence_ || out_time > fade_start ) + { + // check end for a new run of silence + long silence = count_silence( out + pos, remain ); + if ( silence < remain ) + silence_time = emu_time - silence; + + if ( emu_time - silence_time >= buf_size ) + fill_buf(); // cause silence detection on next play() + } + } + + if ( out_time > fade_start ) + handle_fade( out_count, out ); + } + out_time += out_count; + return 0; +} + +// Gme_Info_ + +blargg_err_t Gme_Info_::set_sample_rate_( long ) { return 0; } +void Gme_Info_::pre_load() { Gme_File::pre_load(); } // skip Music_Emu +void Gme_Info_::post_load_() { Gme_File::post_load_(); } // skip Music_Emu +void Gme_Info_::set_equalizer_( equalizer_t const& ){ check( false ); } +void Gme_Info_::enable_accuracy_( bool ) { check( false ); } +void Gme_Info_::mute_voices_( int ) { check( false ); } +void Gme_Info_::set_tempo_( double ) { } +blargg_err_t Gme_Info_::start_track_( int ) { return "Use full emulator for playback"; } +blargg_err_t Gme_Info_::play_( long, sample_t* ) { return "Use full emulator for playback"; } diff --git a/libs/gme/gme/Music_Emu.h b/libs/gme/gme/Music_Emu.h new file mode 100644 index 000000000..b96f4b611 --- /dev/null +++ b/libs/gme/gme/Music_Emu.h @@ -0,0 +1,226 @@ +// Common interface to game music file emulators + +// Game_Music_Emu 0.6.0 +#ifndef MUSIC_EMU_H +#define MUSIC_EMU_H + +#include "Gme_File.h" +class Multi_Buffer; + +struct Music_Emu : public Gme_File { +public: +// Basic functionality (see Gme_File.h for file loading/track info functions) + + // Set output sample rate. Must be called only once before loading file. + blargg_err_t set_sample_rate( long sample_rate ); + + // Start a track, where 0 is the first track. Also clears warning string. + blargg_err_t start_track( int ); + + // Generate 'count' samples info 'buf'. Output is in stereo. Any emulation + // errors set warning string, and major errors also end track. + typedef short sample_t; + blargg_err_t play( long count, sample_t* buf ); + +// Informational + + // Sample rate sound is generated at + long sample_rate() const; + + // Index of current track or -1 if one hasn't been started + int current_track() const; + + // Number of voices used by currently loaded file + int voice_count() const; + + // Names of voices + const char** voice_names() const; + +// Track status/control + + // Number of milliseconds (1000 msec = 1 second) played since beginning of track + long tell() const; + + // Seek to new time in track. Seeking backwards or far forward can take a while. + blargg_err_t seek( long msec ); + + // Skip n samples + blargg_err_t skip( long n ); + + // True if a track has reached its end + bool track_ended() const; + + // Set start time and length of track fade out. Once fade ends track_ended() returns + // true. Fade time can be changed while track is playing. + void set_fade( long start_msec, long length_msec = 8000 ); + + // Disable automatic end-of-track detection and skipping of silence at beginning + void ignore_silence( bool disable = true ); + + // Info for current track + using Gme_File::track_info; + blargg_err_t track_info( track_info_t* out ) const; + +// Sound customization + + // Adjust song tempo, where 1.0 = normal, 0.5 = half speed, 2.0 = double speed. + // Track length as returned by track_info() assumes a tempo of 1.0. + void set_tempo( double ); + + // Mute/unmute voice i, where voice 0 is first voice + void mute_voice( int index, bool mute = true ); + + // Set muting state of all voices at once using a bit mask, where -1 mutes them all, + // 0 unmutes them all, 0x01 mutes just the first voice, etc. + void mute_voices( int mask ); + + // Change overall output amplitude, where 1.0 results in minimal clamping. + // Must be called before set_sample_rate(). + void set_gain( double ); + + // Request use of custom multichannel buffer. Only supported by "classic" emulators; + // on others this has no effect. Should be called only once *before* set_sample_rate(). + virtual void set_buffer( Multi_Buffer* ) { } + + // Enables/disables accurate emulation options, if any are supported. Might change + // equalizer settings. + void enable_accuracy( bool enable = true ); + +// Sound equalization (treble/bass) + + // Frequency equalizer parameters (see gme.txt) + // See gme.h for definition of struct gme_equalizer_t. + typedef gme_equalizer_t equalizer_t; + + // Current frequency equalizater parameters + equalizer_t const& equalizer() const; + + // Set frequency equalizer parameters + void set_equalizer( equalizer_t const& ); + + // Construct equalizer of given treble/bass settings + static const equalizer_t make_equalizer( double treble, double bass ) + { + const Music_Emu::equalizer_t e = { treble, bass, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; + return e; + } + + // Equalizer settings for TV speaker + static equalizer_t const tv_eq; + +public: + Music_Emu(); + ~Music_Emu(); +protected: + void set_max_initial_silence( int n ) { max_initial_silence = n; } + void set_silence_lookahead( int n ) { silence_lookahead = n; } + void set_voice_count( int n ) { voice_count_ = n; } + void set_voice_names( const char* const* names ); + void set_track_ended() { emu_track_ended_ = true; } + double gain() const { return gain_; } + double tempo() const { return tempo_; } + void remute_voices(); + + virtual blargg_err_t set_sample_rate_( long sample_rate ) = 0; + virtual void set_equalizer_( equalizer_t const& ) { } + virtual void enable_accuracy_( bool /* enable */ ) { } + virtual void mute_voices_( int mask ) = 0; + virtual void set_tempo_( double ) = 0; + virtual blargg_err_t start_track_( int ) = 0; // tempo is set before this + virtual blargg_err_t play_( long count, sample_t* out ) = 0; + virtual blargg_err_t skip_( long count ); +protected: + virtual void unload(); + virtual void pre_load(); + virtual void post_load_(); +private: + // general + equalizer_t equalizer_; + int max_initial_silence; + const char** voice_names_; + int voice_count_; + int mute_mask_; + double tempo_; + double gain_; + + long sample_rate_; + blargg_long msec_to_samples( blargg_long msec ) const; + + // track-specific + int current_track_; + blargg_long out_time; // number of samples played since start of track + blargg_long emu_time; // number of samples emulator has generated since start of track + bool emu_track_ended_; // emulator has reached end of track + volatile bool track_ended_; + void clear_track_vars(); + void end_track_if_error( blargg_err_t ); + + // fading + blargg_long fade_start; + int fade_step; + void handle_fade( long count, sample_t* out ); + + // silence detection + int silence_lookahead; // speed to run emulator when looking ahead for silence + bool ignore_silence_; + long silence_time; // number of samples where most recent silence began + long silence_count; // number of samples of silence to play before using buf + long buf_remain; // number of samples left in silence buffer + enum { buf_size = 2048 }; + blargg_vector buf; + void fill_buf(); + void emu_play( long count, sample_t* out ); + + Multi_Buffer* effects_buffer; + friend Music_Emu* gme_new_emu( gme_type_t, int ); + friend void gme_set_stereo_depth( Music_Emu*, double ); +}; + +// base class for info-only derivations +struct Gme_Info_ : Music_Emu +{ + virtual blargg_err_t set_sample_rate_( long sample_rate ); + virtual void set_equalizer_( equalizer_t const& ); + virtual void enable_accuracy_( bool ); + virtual void mute_voices_( int mask ); + virtual void set_tempo_( double ); + virtual blargg_err_t start_track_( int ); + virtual blargg_err_t play_( long count, sample_t* out ); + virtual void pre_load(); + virtual void post_load_(); +}; + +inline blargg_err_t Music_Emu::track_info( track_info_t* out ) const +{ + return track_info( out, current_track_ ); +} + +inline long Music_Emu::sample_rate() const { return sample_rate_; } +inline const char** Music_Emu::voice_names() const { return voice_names_; } +inline int Music_Emu::voice_count() const { return voice_count_; } +inline int Music_Emu::current_track() const { return current_track_; } +inline bool Music_Emu::track_ended() const { return track_ended_; } +inline const Music_Emu::equalizer_t& Music_Emu::equalizer() const { return equalizer_; } + +inline void Music_Emu::enable_accuracy( bool b ) { enable_accuracy_( b ); } +inline void Music_Emu::set_tempo_( double t ) { tempo_ = t; } +inline void Music_Emu::remute_voices() { mute_voices( mute_mask_ ); } +inline void Music_Emu::ignore_silence( bool b ) { ignore_silence_ = b; } +inline blargg_err_t Music_Emu::start_track_( int ) { return 0; } + +inline void Music_Emu::set_voice_names( const char* const* names ) +{ + // Intentional removal of const, so users don't have to remember obscure const in middle + voice_names_ = const_cast (names); +} + +inline void Music_Emu::mute_voices_( int ) { } + +inline void Music_Emu::set_gain( double g ) +{ + assert( !sample_rate() ); // you must set gain before setting sample rate + gain_ = g; +} + +#endif diff --git a/libs/gme/gme/Nes_Apu.cpp b/libs/gme/gme/Nes_Apu.cpp new file mode 100644 index 000000000..68edb446d --- /dev/null +++ b/libs/gme/gme/Nes_Apu.cpp @@ -0,0 +1,391 @@ +// Nes_Snd_Emu 0.1.8. http://www.slack.net/~ant/ + +#include "Nes_Apu.h" + +/* Copyright (C) 2003-2006 Shay Green. This module 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 +module 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 module; if not, write to the Free Software Foundation, +Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + +#include "blargg_source.h" + +int const amp_range = 15; + +Nes_Apu::Nes_Apu() : + square1( &square_synth ), + square2( &square_synth ) +{ + tempo_ = 1.0; + dmc.apu = this; + dmc.prg_reader = NULL; + irq_notifier_ = NULL; + + oscs [0] = &square1; + oscs [1] = &square2; + oscs [2] = ▵ + oscs [3] = &noise; + oscs [4] = &dmc; + + output( NULL ); + volume( 1.0 ); + reset( false ); +} + +void Nes_Apu::treble_eq( const blip_eq_t& eq ) +{ + square_synth.treble_eq( eq ); + triangle.synth.treble_eq( eq ); + noise.synth.treble_eq( eq ); + dmc.synth.treble_eq( eq ); +} + +void Nes_Apu::enable_nonlinear( double v ) +{ + dmc.nonlinear = true; + square_synth.volume( 1.3 * 0.25751258 / 0.742467605 * 0.25 / amp_range * v ); + + const double tnd = 0.48 / 202 * nonlinear_tnd_gain(); + triangle.synth.volume( 3.0 * tnd ); + noise.synth.volume( 2.0 * tnd ); + dmc.synth.volume( tnd ); + + square1 .last_amp = 0; + square2 .last_amp = 0; + triangle.last_amp = 0; + noise .last_amp = 0; + dmc .last_amp = 0; +} + +void Nes_Apu::volume( double v ) +{ + dmc.nonlinear = false; + square_synth.volume( 0.1128 / amp_range * v ); + triangle.synth.volume( 0.12765 / amp_range * v ); + noise.synth.volume( 0.0741 / amp_range * v ); + dmc.synth.volume( 0.42545 / 127 * v ); +} + +void Nes_Apu::output( Blip_Buffer* buffer ) +{ + for ( int i = 0; i < osc_count; i++ ) + osc_output( i, buffer ); +} + +void Nes_Apu::set_tempo( double t ) +{ + tempo_ = t; + frame_period = (dmc.pal_mode ? 8314 : 7458); + if ( t != 1.0 ) + frame_period = (int) (frame_period / t) & ~1; // must be even +} + +void Nes_Apu::reset( bool pal_mode, int initial_dmc_dac ) +{ + dmc.pal_mode = pal_mode; + set_tempo( tempo_ ); + + square1.reset(); + square2.reset(); + triangle.reset(); + noise.reset(); + dmc.reset(); + + last_time = 0; + last_dmc_time = 0; + osc_enables = 0; + irq_flag = false; + earliest_irq_ = no_irq; + frame_delay = 1; + write_register( 0, 0x4017, 0x00 ); + write_register( 0, 0x4015, 0x00 ); + + for ( nes_addr_t addr = start_addr; addr <= 0x4013; addr++ ) + write_register( 0, addr, (addr & 3) ? 0x00 : 0x10 ); + + dmc.dac = initial_dmc_dac; + if ( !dmc.nonlinear ) + triangle.last_amp = 15; + if ( !dmc.nonlinear ) // TODO: remove? + dmc.last_amp = initial_dmc_dac; // prevent output transition +} + +void Nes_Apu::irq_changed() +{ + nes_time_t new_irq = dmc.next_irq; + if ( dmc.irq_flag | irq_flag ) { + new_irq = 0; + } + else if ( new_irq > next_irq ) { + new_irq = next_irq; + } + + if ( new_irq != earliest_irq_ ) { + earliest_irq_ = new_irq; + if ( irq_notifier_ ) + irq_notifier_( irq_data ); + } +} + +// frames + +void Nes_Apu::run_until( nes_time_t end_time ) +{ + require( end_time >= last_dmc_time ); + if ( end_time > next_dmc_read_time() ) + { + nes_time_t start = last_dmc_time; + last_dmc_time = end_time; + dmc.run( start, end_time ); + } +} + +void Nes_Apu::run_until_( nes_time_t end_time ) +{ + require( end_time >= last_time ); + + if ( end_time == last_time ) + return; + + if ( last_dmc_time < end_time ) + { + nes_time_t start = last_dmc_time; + last_dmc_time = end_time; + dmc.run( start, end_time ); + } + + while ( true ) + { + // earlier of next frame time or end time + nes_time_t time = last_time + frame_delay; + if ( time > end_time ) + time = end_time; + frame_delay -= time - last_time; + + // run oscs to present + square1.run( last_time, time ); + square2.run( last_time, time ); + triangle.run( last_time, time ); + noise.run( last_time, time ); + last_time = time; + + if ( time == end_time ) + break; // no more frames to run + + // take frame-specific actions + frame_delay = frame_period; + switch ( frame++ ) + { + case 0: + if ( !(frame_mode & 0xC0) ) { + next_irq = time + frame_period * 4 + 2; + irq_flag = true; + } + // fall through + case 2: + // clock length and sweep on frames 0 and 2 + square1.clock_length( 0x20 ); + square2.clock_length( 0x20 ); + noise.clock_length( 0x20 ); + triangle.clock_length( 0x80 ); // different bit for halt flag on triangle + + square1.clock_sweep( -1 ); + square2.clock_sweep( 0 ); + + // frame 2 is slightly shorter in mode 1 + if ( dmc.pal_mode && frame == 3 ) + frame_delay -= 2; + break; + + case 1: + // frame 1 is slightly shorter in mode 0 + if ( !dmc.pal_mode ) + frame_delay -= 2; + break; + + case 3: + frame = 0; + + // frame 3 is almost twice as long in mode 1 + if ( frame_mode & 0x80 ) + frame_delay += frame_period - (dmc.pal_mode ? 2 : 6); + break; + } + + // clock envelopes and linear counter every frame + triangle.clock_linear_counter(); + square1.clock_envelope(); + square2.clock_envelope(); + noise.clock_envelope(); + } +} + +template +inline void zero_apu_osc( T* osc, nes_time_t time ) +{ + Blip_Buffer* output = osc->output; + int last_amp = osc->last_amp; + osc->last_amp = 0; + if ( output && last_amp ) + osc->synth.offset( time, -last_amp, output ); +} + +void Nes_Apu::end_frame( nes_time_t end_time ) +{ + if ( end_time > last_time ) + run_until_( end_time ); + + if ( dmc.nonlinear ) + { + zero_apu_osc( &square1, last_time ); + zero_apu_osc( &square2, last_time ); + zero_apu_osc( &triangle, last_time ); + zero_apu_osc( &noise, last_time ); + zero_apu_osc( &dmc, last_time ); + } + + // make times relative to new frame + last_time -= end_time; + require( last_time >= 0 ); + + last_dmc_time -= end_time; + require( last_dmc_time >= 0 ); + + if ( next_irq != no_irq ) { + next_irq -= end_time; + check( next_irq >= 0 ); + } + if ( dmc.next_irq != no_irq ) { + dmc.next_irq -= end_time; + check( dmc.next_irq >= 0 ); + } + if ( earliest_irq_ != no_irq ) { + earliest_irq_ -= end_time; + if ( earliest_irq_ < 0 ) + earliest_irq_ = 0; + } +} + +// registers + +static const unsigned char length_table [0x20] = { + 0x0A, 0xFE, 0x14, 0x02, 0x28, 0x04, 0x50, 0x06, + 0xA0, 0x08, 0x3C, 0x0A, 0x0E, 0x0C, 0x1A, 0x0E, + 0x0C, 0x10, 0x18, 0x12, 0x30, 0x14, 0x60, 0x16, + 0xC0, 0x18, 0x48, 0x1A, 0x10, 0x1C, 0x20, 0x1E +}; + +void Nes_Apu::write_register( nes_time_t time, nes_addr_t addr, int data ) +{ + require( addr > 0x20 ); // addr must be actual address (i.e. 0x40xx) + require( (unsigned) data <= 0xFF ); + + // Ignore addresses outside range + if ( unsigned (addr - start_addr) > end_addr - start_addr ) + return; + + run_until_( time ); + + if ( addr < 0x4014 ) + { + // Write to channel + int osc_index = (addr - start_addr) >> 2; + Nes_Osc* osc = oscs [osc_index]; + + int reg = addr & 3; + osc->regs [reg] = data; + osc->reg_written [reg] = true; + + if ( osc_index == 4 ) + { + // handle DMC specially + dmc.write_register( reg, data ); + } + else if ( reg == 3 ) + { + // load length counter + if ( (osc_enables >> osc_index) & 1 ) + osc->length_counter = length_table [(data >> 3) & 0x1F]; + + // reset square phase + if ( osc_index < 2 ) + ((Nes_Square*) osc)->phase = Nes_Square::phase_range - 1; + } + } + else if ( addr == 0x4015 ) + { + // Channel enables + for ( int i = osc_count; i--; ) + if ( !((data >> i) & 1) ) + oscs [i]->length_counter = 0; + + bool recalc_irq = dmc.irq_flag; + dmc.irq_flag = false; + + int old_enables = osc_enables; + osc_enables = data; + if ( !(data & 0x10) ) { + dmc.next_irq = no_irq; + recalc_irq = true; + } + else if ( !(old_enables & 0x10) ) { + dmc.start(); // dmc just enabled + } + + if ( recalc_irq ) + irq_changed(); + } + else if ( addr == 0x4017 ) + { + // Frame mode + frame_mode = data; + + bool irq_enabled = !(data & 0x40); + irq_flag &= irq_enabled; + next_irq = no_irq; + + // mode 1 + frame_delay = (frame_delay & 1); + frame = 0; + + if ( !(data & 0x80) ) + { + // mode 0 + frame = 1; + frame_delay += frame_period; + if ( irq_enabled ) + next_irq = time + frame_delay + frame_period * 3 + 1; + } + + irq_changed(); + } +} + +int Nes_Apu::read_status( nes_time_t time ) +{ + run_until_( time - 1 ); + + int result = (dmc.irq_flag << 7) | (irq_flag << 6); + + for ( int i = 0; i < osc_count; i++ ) + if ( oscs [i]->length_counter ) + result |= 1 << i; + + run_until_( time ); + + if ( irq_flag ) + { + result |= 0x40; + irq_flag = false; + irq_changed(); + } + + //debug_printf( "%6d/%d Read $4015->$%02X\n", frame_delay, frame, result ); + + return result; +} diff --git a/libs/gme/gme/Nes_Apu.h b/libs/gme/gme/Nes_Apu.h new file mode 100644 index 000000000..5e722248f --- /dev/null +++ b/libs/gme/gme/Nes_Apu.h @@ -0,0 +1,179 @@ +// NES 2A03 APU sound chip emulator + +// Nes_Snd_Emu 0.1.8 +#ifndef NES_APU_H +#define NES_APU_H + +#include "blargg_common.h" + +typedef blargg_long nes_time_t; // CPU clock cycle count +typedef unsigned nes_addr_t; // 16-bit memory address + +#include "Nes_Oscs.h" + +struct apu_state_t; +class Nes_Buffer; + +class Nes_Apu { +public: + // Set buffer to generate all sound into, or disable sound if NULL + void output( Blip_Buffer* ); + + // Set memory reader callback used by DMC oscillator to fetch samples. + // When callback is invoked, 'user_data' is passed unchanged as the + // first parameter. + void dmc_reader( int (*callback)( void* user_data, nes_addr_t ), void* user_data = NULL ); + + // All time values are the number of CPU clock cycles relative to the + // beginning of the current time frame. Before resetting the CPU clock + // count, call end_frame( last_cpu_time ). + + // Write to register (0x4000-0x4017, except 0x4014 and 0x4016) + enum { start_addr = 0x4000 }; + enum { end_addr = 0x4017 }; + void write_register( nes_time_t, nes_addr_t, int data ); + + // Read from status register at 0x4015 + enum { status_addr = 0x4015 }; + int read_status( nes_time_t ); + + // Run all oscillators up to specified time, end current time frame, then + // start a new time frame at time 0. Time frames have no effect on emulation + // and each can be whatever length is convenient. + void end_frame( nes_time_t ); + +// Additional optional features (can be ignored without any problem) + + // Reset internal frame counter, registers, and all oscillators. + // Use PAL timing if pal_timing is true, otherwise use NTSC timing. + // Set the DMC oscillator's initial DAC value to initial_dmc_dac without + // any audible click. + void reset( bool pal_mode = false, int initial_dmc_dac = 0 ); + + // Adjust frame period + void set_tempo( double ); + + // Save/load exact emulation state + void save_state( apu_state_t* out ) const; + void load_state( apu_state_t const& ); + + // Set overall volume (default is 1.0) + void volume( double ); + + // Set treble equalization (see notes.txt) + void treble_eq( const blip_eq_t& ); + + // Set sound output of specific oscillator to buffer. If buffer is NULL, + // the specified oscillator is muted and emulation accuracy is reduced. + // The oscillators are indexed as follows: 0) Square 1, 1) Square 2, + // 2) Triangle, 3) Noise, 4) DMC. + enum { osc_count = 5 }; + void osc_output( int index, Blip_Buffer* buffer ); + + // Set IRQ time callback that is invoked when the time of earliest IRQ + // may have changed, or NULL to disable. When callback is invoked, + // 'user_data' is passed unchanged as the first parameter. + void irq_notifier( void (*callback)( void* user_data ), void* user_data = NULL ); + + // Get time that APU-generated IRQ will occur if no further register reads + // or writes occur. If IRQ is already pending, returns irq_waiting. If no + // IRQ will occur, returns no_irq. + enum { no_irq = INT_MAX / 2 + 1 }; + enum { irq_waiting = 0 }; + nes_time_t earliest_irq( nes_time_t ) const; + + // Count number of DMC reads that would occur if 'run_until( t )' were executed. + // If last_read is not NULL, set *last_read to the earliest time that + // 'count_dmc_reads( time )' would result in the same result. + int count_dmc_reads( nes_time_t t, nes_time_t* last_read = NULL ) const; + + // Time when next DMC memory read will occur + nes_time_t next_dmc_read_time() const; + + // Run DMC until specified time, so that any DMC memory reads can be + // accounted for (i.e. inserting CPU wait states). + void run_until( nes_time_t ); + +public: + Nes_Apu(); + BLARGG_DISABLE_NOTHROW +private: + friend class Nes_Nonlinearizer; + void enable_nonlinear( double volume ); + static double nonlinear_tnd_gain() { return 0.75; } +private: + friend struct Nes_Dmc; + + // noncopyable + Nes_Apu( const Nes_Apu& ); + Nes_Apu& operator = ( const Nes_Apu& ); + + Nes_Osc* oscs [osc_count]; + Nes_Square square1; + Nes_Square square2; + Nes_Noise noise; + Nes_Triangle triangle; + Nes_Dmc dmc; + + double tempo_; + nes_time_t last_time; // has been run until this time in current frame + nes_time_t last_dmc_time; + nes_time_t earliest_irq_; + nes_time_t next_irq; + int frame_period; + int frame_delay; // cycles until frame counter runs next + int frame; // current frame (0-3) + int osc_enables; + int frame_mode; + bool irq_flag; + void (*irq_notifier_)( void* user_data ); + void* irq_data; + Nes_Square::Synth square_synth; // shared by squares + + void irq_changed(); + void state_restored(); + void run_until_( nes_time_t ); + + // TODO: remove + friend class Nes_Core; +}; + +inline void Nes_Apu::osc_output( int osc, Blip_Buffer* buf ) +{ + assert( (unsigned) osc < osc_count ); + oscs [osc]->output = buf; +} + +inline nes_time_t Nes_Apu::earliest_irq( nes_time_t ) const +{ + return earliest_irq_; +} + +inline void Nes_Apu::dmc_reader( int (*func)( void*, nes_addr_t ), void* user_data ) +{ + dmc.prg_reader_data = user_data; + dmc.prg_reader = func; +} + +inline void Nes_Apu::irq_notifier( void (*func)( void* user_data ), void* user_data ) +{ + irq_notifier_ = func; + irq_data = user_data; +} + +inline int Nes_Apu::count_dmc_reads( nes_time_t time, nes_time_t* last_read ) const +{ + return dmc.count_reads( time, last_read ); +} + +inline nes_time_t Nes_Dmc::next_read_time() const +{ + if ( length_counter == 0 ) + return Nes_Apu::no_irq; // not reading + + return apu->last_dmc_time + delay + long (bits_remain - 1) * period; +} + +inline nes_time_t Nes_Apu::next_dmc_read_time() const { return dmc.next_read_time(); } + +#endif diff --git a/libs/gme/gme/Nes_Cpu.cpp b/libs/gme/gme/Nes_Cpu.cpp new file mode 100644 index 000000000..ac548d0ff --- /dev/null +++ b/libs/gme/gme/Nes_Cpu.cpp @@ -0,0 +1,1084 @@ +// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/ + +#include "Nes_Cpu.h" + +#include "blargg_endian.h" +#include + +#define BLARGG_CPU_X86 1 + +/* Copyright (C) 2003-2006 Shay Green. This module 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 +module 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 module; if not, write to the Free Software Foundation, +Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + +#ifdef BLARGG_ENABLE_OPTIMIZER + #include BLARGG_ENABLE_OPTIMIZER +#endif + +#define FLUSH_TIME() (void) (s.time = s_time) +#define CACHE_TIME() (void) (s_time = s.time) + +#include "nes_cpu_io.h" + +#include "blargg_source.h" + +#ifndef CPU_DONE + #define CPU_DONE( cpu, time, result_out ) { result_out = -1; } +#endif + +#ifndef CPU_READ_PPU + #define CPU_READ_PPU( cpu, addr, out, time )\ + {\ + FLUSH_TIME();\ + out = CPU_READ( cpu, addr, time );\ + CACHE_TIME();\ + } +#endif + +#if BLARGG_NONPORTABLE + #define PAGE_OFFSET( addr ) (addr) +#else + #define PAGE_OFFSET( addr ) ((addr) & (page_size - 1)) +#endif + +inline void Nes_Cpu::set_code_page( int i, void const* p ) +{ + state->code_map [i] = (uint8_t const*) p - PAGE_OFFSET( i * page_size ); +} + +int const st_n = 0x80; +int const st_v = 0x40; +int const st_r = 0x20; +int const st_b = 0x10; +int const st_d = 0x08; +int const st_i = 0x04; +int const st_z = 0x02; +int const st_c = 0x01; + +void Nes_Cpu::reset( void const* unmapped_page ) +{ + check( state == &state_ ); + state = &state_; + r.status = st_i; + r.sp = 0xFF; + r.pc = 0; + r.a = 0; + r.x = 0; + r.y = 0; + state_.time = 0; + state_.base = 0; + irq_time_ = future_nes_time; + end_time_ = future_nes_time; + error_count_ = 0; + + assert( page_size == 0x800 ); // assumes this + set_code_page( page_count, unmapped_page ); + map_code( 0x2000, 0xE000, unmapped_page, true ); + map_code( 0x0000, 0x2000, low_mem, true ); + + blargg_verify_byte_order(); +} + +void Nes_Cpu::map_code( nes_addr_t start, unsigned size, void const* data, bool mirror ) +{ + // address range must begin and end on page boundaries + require( start % page_size == 0 ); + require( size % page_size == 0 ); + require( start + size <= 0x10000 ); + + unsigned page = start / page_size; + for ( unsigned n = size / page_size; n; --n ) + { + set_code_page( page++, data ); + if ( !mirror ) + data = (char const*) data + page_size; + } +} + +#define TIME (s_time + s.base) +#define READ_LIKELY_PPU( addr, out ) {CPU_READ_PPU( this, (addr), out, TIME );} +#define READ( addr ) CPU_READ( this, (addr), TIME ) +#define WRITE( addr, data ) {CPU_WRITE( this, (addr), (data), TIME );} +#define READ_LOW( addr ) (low_mem [int (addr)]) +#define WRITE_LOW( addr, data ) (void) (READ_LOW( addr ) = (data)) +#define READ_PROG( addr ) (s.code_map [(addr) >> page_bits] [PAGE_OFFSET( addr )]) + +#define SET_SP( v ) (sp = ((v) + 1) | 0x100) +#define GET_SP() ((sp - 1) & 0xFF) +#define PUSH( v ) ((sp = (sp - 1) | 0x100), WRITE_LOW( sp, v )) + +// even on x86, using short and unsigned char was slower +typedef int fint16; +typedef unsigned fuint16; +typedef unsigned fuint8; + +bool Nes_Cpu::run( nes_time_t end_time ) +{ + set_end_time( end_time ); + state_t s = this->state_; + this->state = &s; + // even on x86, using s.time in place of s_time was slower + fint16 s_time = s.time; + + // registers + fuint16 pc = r.pc; + fuint8 a = r.a; + fuint8 x = r.x; + fuint8 y = r.y; + fuint16 sp; + SET_SP( r.sp ); + + // status flags + #define IS_NEG (nz & 0x8080) + + #define CALC_STATUS( out ) do {\ + out = status & (st_v | st_d | st_i);\ + out |= ((nz >> 8) | nz) & st_n;\ + out |= c >> 8 & st_c;\ + if ( !(nz & 0xFF) ) out |= st_z;\ + } while ( 0 ) + + #define SET_STATUS( in ) do {\ + status = in & (st_v | st_d | st_i);\ + nz = in << 8;\ + c = nz;\ + nz |= ~in & st_z;\ + } while ( 0 ) + + fuint8 status; + fuint16 c; // carry set if (c & 0x100) != 0 + fuint16 nz; // Z set if (nz & 0xFF) == 0, N set if (nz & 0x8080) != 0 + { + fuint8 temp = r.status; + SET_STATUS( temp ); + } + + goto loop; +dec_clock_loop: + s_time--; +loop: + + check( (unsigned) GET_SP() < 0x100 ); + check( (unsigned) pc < 0x10000 ); + check( (unsigned) a < 0x100 ); + check( (unsigned) x < 0x100 ); + check( (unsigned) y < 0x100 ); + check( -32768 <= s_time && s_time < 32767 ); + + uint8_t const* instr = s.code_map [pc >> page_bits]; + fuint8 opcode; + + // TODO: eliminate this special case + #if BLARGG_NONPORTABLE + opcode = instr [pc]; + pc++; + instr += pc; + #else + instr += PAGE_OFFSET( pc ); + opcode = *instr++; + pc++; + #endif + + static uint8_t const clock_table [256] = + {// 0 1 2 3 4 5 6 7 8 9 A B C D E F + 0,6,2,8,3,3,5,5,3,2,2,2,4,4,6,6,// 0 + 3,5,2,8,4,4,6,6,2,4,2,7,4,4,7,7,// 1 + 6,6,2,8,3,3,5,5,4,2,2,2,4,4,6,6,// 2 + 3,5,2,8,4,4,6,6,2,4,2,7,4,4,7,7,// 3 + 6,6,2,8,3,3,5,5,3,2,2,2,3,4,6,6,// 4 + 3,5,2,8,4,4,6,6,2,4,2,7,4,4,7,7,// 5 + 6,6,2,8,3,3,5,5,4,2,2,2,5,4,6,6,// 6 + 3,5,2,8,4,4,6,6,2,4,2,7,4,4,7,7,// 7 + 2,6,2,6,3,3,3,3,2,2,2,2,4,4,4,4,// 8 + 3,6,2,6,4,4,4,4,2,5,2,5,5,5,5,5,// 9 + 2,6,2,6,3,3,3,3,2,2,2,2,4,4,4,4,// A + 3,5,2,5,4,4,4,4,2,4,2,4,4,4,4,4,// B + 2,6,2,8,3,3,5,5,2,2,2,2,4,4,6,6,// C + 3,5,2,8,4,4,6,6,2,4,2,7,4,4,7,7,// D + 2,6,2,8,3,3,5,5,2,2,2,2,4,4,6,6,// E + 3,5,0,8,4,4,6,6,2,4,2,7,4,4,7,7 // F + }; // 0x00 was 7 and 0xF2 was 2 + + fuint16 data; + +#if !BLARGG_CPU_X86 + if ( s_time >= 0 ) + goto out_of_time; + s_time += clock_table [opcode]; + + data = *instr; + + switch ( opcode ) + { +#else + + data = clock_table [opcode]; + if ( (s_time += data) >= 0 ) + goto possibly_out_of_time; +almost_out_of_time: + + data = *instr; + + switch ( opcode ) + { +possibly_out_of_time: + if ( s_time < (int) data ) + goto almost_out_of_time; + s_time -= data; + goto out_of_time; +#endif + +// Macros + +#define GET_MSB() (instr [1]) +#define ADD_PAGE() (pc++, data += 0x100 * GET_MSB()) +#define GET_ADDR() GET_LE16( instr ) + +#define NO_PAGE_CROSSING( lsb ) +#define HANDLE_PAGE_CROSSING( lsb ) s_time += (lsb) >> 8; + +#define INC_DEC_XY( reg, n ) reg = uint8_t (nz = reg + n); goto loop; + +#define IND_Y( cross, out ) {\ + fuint16 temp = READ_LOW( data ) + y;\ + out = temp + 0x100 * READ_LOW( uint8_t (data + 1) );\ + cross( temp );\ + } + +#define IND_X( out ) {\ + fuint16 temp = data + x;\ + out = 0x100 * READ_LOW( uint8_t (temp + 1) ) + READ_LOW( uint8_t (temp) );\ + } + +#define ARITH_ADDR_MODES( op )\ +case op - 0x04: /* (ind,x) */\ + IND_X( data )\ + goto ptr##op;\ +case op + 0x0C: /* (ind),y */\ + IND_Y( HANDLE_PAGE_CROSSING, data )\ + goto ptr##op;\ +case op + 0x10: /* zp,X */\ + data = uint8_t (data + x);\ +case op + 0x00: /* zp */\ + data = READ_LOW( data );\ + goto imm##op;\ +case op + 0x14: /* abs,Y */\ + data += y;\ + goto ind##op;\ +case op + 0x18: /* abs,X */\ + data += x;\ +ind##op:\ + HANDLE_PAGE_CROSSING( data );\ +case op + 0x08: /* abs */\ + ADD_PAGE();\ +ptr##op:\ + FLUSH_TIME();\ + data = READ( data );\ + CACHE_TIME();\ +case op + 0x04: /* imm */\ +imm##op: + +// TODO: more efficient way to handle negative branch that wraps PC around +#define BRANCH( cond )\ +{\ + fint16 offset = (BOOST::int8_t) data;\ + fuint16 extra_clock = (++pc & 0xFF) + offset;\ + if ( !(cond) ) goto dec_clock_loop;\ + pc = BOOST::uint16_t (pc + offset);\ + s_time += extra_clock >> 8 & 1;\ + goto loop;\ +} + +// Often-Used + + case 0xB5: // LDA zp,x + a = nz = READ_LOW( uint8_t (data + x) ); + pc++; + goto loop; + + case 0xA5: // LDA zp + a = nz = READ_LOW( data ); + pc++; + goto loop; + + case 0xD0: // BNE + BRANCH( (uint8_t) nz ); + + case 0x20: { // JSR + fuint16 temp = pc + 1; + pc = GET_ADDR(); + WRITE_LOW( 0x100 | (sp - 1), temp >> 8 ); + sp = (sp - 2) | 0x100; + WRITE_LOW( sp, temp ); + goto loop; + } + + case 0x4C: // JMP abs + pc = GET_ADDR(); + goto loop; + + case 0xE8: // INX + INC_DEC_XY( x, 1 ) + + case 0x10: // BPL + BRANCH( !IS_NEG ) + + ARITH_ADDR_MODES( 0xC5 ) // CMP + nz = a - data; + pc++; + c = ~nz; + nz &= 0xFF; + goto loop; + + case 0x30: // BMI + BRANCH( IS_NEG ) + + case 0xF0: // BEQ + BRANCH( !(uint8_t) nz ); + + case 0x95: // STA zp,x + data = uint8_t (data + x); + case 0x85: // STA zp + pc++; + WRITE_LOW( data, a ); + goto loop; + + case 0xC8: // INY + INC_DEC_XY( y, 1 ) + + case 0xA8: // TAY + y = a; + nz = a; + goto loop; + + case 0x98: // TYA + a = y; + nz = y; + goto loop; + + case 0xAD:{// LDA abs + unsigned addr = GET_ADDR(); + pc += 2; + READ_LIKELY_PPU( addr, nz ); + a = nz; + goto loop; + } + + case 0x60: // RTS + pc = 1 + READ_LOW( sp ); + pc += 0x100 * READ_LOW( 0x100 | (sp - 0xFF) ); + sp = (sp - 0xFE) | 0x100; + goto loop; + + { + fuint16 addr; + + case 0x99: // STA abs,Y + addr = y + GET_ADDR(); + pc += 2; + if ( addr <= 0x7FF ) + { + WRITE_LOW( addr, a ); + goto loop; + } + goto sta_ptr; + + case 0x8D: // STA abs + addr = GET_ADDR(); + pc += 2; + if ( addr <= 0x7FF ) + { + WRITE_LOW( addr, a ); + goto loop; + } + goto sta_ptr; + + case 0x9D: // STA abs,X (slightly more common than STA abs) + addr = x + GET_ADDR(); + pc += 2; + if ( addr <= 0x7FF ) + { + WRITE_LOW( addr, a ); + goto loop; + } + sta_ptr: + FLUSH_TIME(); + WRITE( addr, a ); + CACHE_TIME(); + goto loop; + + case 0x91: // STA (ind),Y + IND_Y( NO_PAGE_CROSSING, addr ) + pc++; + goto sta_ptr; + + case 0x81: // STA (ind,X) + IND_X( addr ) + pc++; + goto sta_ptr; + + } + + case 0xA9: // LDA #imm + pc++; + a = data; + nz = data; + goto loop; + + // common read instructions + { + fuint16 addr; + + case 0xA1: // LDA (ind,X) + IND_X( addr ) + pc++; + goto a_nz_read_addr; + + case 0xB1:// LDA (ind),Y + addr = READ_LOW( data ) + y; + HANDLE_PAGE_CROSSING( addr ); + addr += 0x100 * READ_LOW( (uint8_t) (data + 1) ); + pc++; + a = nz = READ_PROG( addr ); + if ( (addr ^ 0x8000) <= 0x9FFF ) + goto loop; + goto a_nz_read_addr; + + case 0xB9: // LDA abs,Y + HANDLE_PAGE_CROSSING( data + y ); + addr = GET_ADDR() + y; + pc += 2; + a = nz = READ_PROG( addr ); + if ( (addr ^ 0x8000) <= 0x9FFF ) + goto loop; + goto a_nz_read_addr; + + case 0xBD: // LDA abs,X + HANDLE_PAGE_CROSSING( data + x ); + addr = GET_ADDR() + x; + pc += 2; + a = nz = READ_PROG( addr ); + if ( (addr ^ 0x8000) <= 0x9FFF ) + goto loop; + a_nz_read_addr: + FLUSH_TIME(); + a = nz = READ( addr ); + CACHE_TIME(); + goto loop; + + } + +// Branch + + case 0x50: // BVC + BRANCH( !(status & st_v) ) + + case 0x70: // BVS + BRANCH( status & st_v ) + + case 0xB0: // BCS + BRANCH( c & 0x100 ) + + case 0x90: // BCC + BRANCH( !(c & 0x100) ) + +// Load/store + + case 0x94: // STY zp,x + data = uint8_t (data + x); + case 0x84: // STY zp + pc++; + WRITE_LOW( data, y ); + goto loop; + + case 0x96: // STX zp,y + data = uint8_t (data + y); + case 0x86: // STX zp + pc++; + WRITE_LOW( data, x ); + goto loop; + + case 0xB6: // LDX zp,y + data = uint8_t (data + y); + case 0xA6: // LDX zp + data = READ_LOW( data ); + case 0xA2: // LDX #imm + pc++; + x = data; + nz = data; + goto loop; + + case 0xB4: // LDY zp,x + data = uint8_t (data + x); + case 0xA4: // LDY zp + data = READ_LOW( data ); + case 0xA0: // LDY #imm + pc++; + y = data; + nz = data; + goto loop; + + case 0xBC: // LDY abs,X + data += x; + HANDLE_PAGE_CROSSING( data ); + case 0xAC:{// LDY abs + unsigned addr = data + 0x100 * GET_MSB(); + pc += 2; + FLUSH_TIME(); + y = nz = READ( addr ); + CACHE_TIME(); + goto loop; + } + + case 0xBE: // LDX abs,y + data += y; + HANDLE_PAGE_CROSSING( data ); + case 0xAE:{// LDX abs + unsigned addr = data + 0x100 * GET_MSB(); + pc += 2; + FLUSH_TIME(); + x = nz = READ( addr ); + CACHE_TIME(); + goto loop; + } + + { + fuint8 temp; + case 0x8C: // STY abs + temp = y; + goto store_abs; + + case 0x8E: // STX abs + temp = x; + store_abs: + unsigned addr = GET_ADDR(); + pc += 2; + if ( addr <= 0x7FF ) + { + WRITE_LOW( addr, temp ); + goto loop; + } + FLUSH_TIME(); + WRITE( addr, temp ); + CACHE_TIME(); + goto loop; + } + +// Compare + + case 0xEC:{// CPX abs + unsigned addr = GET_ADDR(); + pc++; + FLUSH_TIME(); + data = READ( addr ); + CACHE_TIME(); + goto cpx_data; + } + + case 0xE4: // CPX zp + data = READ_LOW( data ); + case 0xE0: // CPX #imm + cpx_data: + nz = x - data; + pc++; + c = ~nz; + nz &= 0xFF; + goto loop; + + case 0xCC:{// CPY abs + unsigned addr = GET_ADDR(); + pc++; + FLUSH_TIME(); + data = READ( addr ); + CACHE_TIME(); + goto cpy_data; + } + + case 0xC4: // CPY zp + data = READ_LOW( data ); + case 0xC0: // CPY #imm + cpy_data: + nz = y - data; + pc++; + c = ~nz; + nz &= 0xFF; + goto loop; + +// Logical + + ARITH_ADDR_MODES( 0x25 ) // AND + nz = (a &= data); + pc++; + goto loop; + + ARITH_ADDR_MODES( 0x45 ) // EOR + nz = (a ^= data); + pc++; + goto loop; + + ARITH_ADDR_MODES( 0x05 ) // ORA + nz = (a |= data); + pc++; + goto loop; + + case 0x2C:{// BIT abs + unsigned addr = GET_ADDR(); + pc += 2; + status &= ~st_v; + READ_LIKELY_PPU( addr, nz ); + status |= nz & st_v; + if ( a & nz ) + goto loop; + nz <<= 8; // result must be zero, even if N bit is set + goto loop; + } + + case 0x24: // BIT zp + nz = READ_LOW( data ); + pc++; + status &= ~st_v; + status |= nz & st_v; + if ( a & nz ) + goto loop; + nz <<= 8; // result must be zero, even if N bit is set + goto loop; + +// Add/subtract + + ARITH_ADDR_MODES( 0xE5 ) // SBC + case 0xEB: // unofficial equivalent + data ^= 0xFF; + goto adc_imm; + + ARITH_ADDR_MODES( 0x65 ) // ADC + adc_imm: { + fint16 carry = c >> 8 & 1; + fint16 ov = (a ^ 0x80) + carry + (BOOST::int8_t) data; // sign-extend + status &= ~st_v; + status |= ov >> 2 & 0x40; + c = nz = a + data + carry; + pc++; + a = (uint8_t) nz; + goto loop; + } + +// Shift/rotate + + case 0x4A: // LSR A + c = 0; + case 0x6A: // ROR A + nz = c >> 1 & 0x80; + c = a << 8; + nz |= a >> 1; + a = nz; + goto loop; + + case 0x0A: // ASL A + nz = a << 1; + c = nz; + a = (uint8_t) nz; + goto loop; + + case 0x2A: { // ROL A + nz = a << 1; + fint16 temp = c >> 8 & 1; + c = nz; + nz |= temp; + a = (uint8_t) nz; + goto loop; + } + + case 0x5E: // LSR abs,X + data += x; + case 0x4E: // LSR abs + c = 0; + case 0x6E: // ROR abs + ror_abs: { + ADD_PAGE(); + FLUSH_TIME(); + int temp = READ( data ); + nz = (c >> 1 & 0x80) | (temp >> 1); + c = temp << 8; + goto rotate_common; + } + + case 0x3E: // ROL abs,X + data += x; + goto rol_abs; + + case 0x1E: // ASL abs,X + data += x; + case 0x0E: // ASL abs + c = 0; + case 0x2E: // ROL abs + rol_abs: + ADD_PAGE(); + nz = c >> 8 & 1; + FLUSH_TIME(); + nz |= (c = READ( data ) << 1); + rotate_common: + pc++; + WRITE( data, (uint8_t) nz ); + CACHE_TIME(); + goto loop; + + case 0x7E: // ROR abs,X + data += x; + goto ror_abs; + + case 0x76: // ROR zp,x + data = uint8_t (data + x); + goto ror_zp; + + case 0x56: // LSR zp,x + data = uint8_t (data + x); + case 0x46: // LSR zp + c = 0; + case 0x66: // ROR zp + ror_zp: { + int temp = READ_LOW( data ); + nz = (c >> 1 & 0x80) | (temp >> 1); + c = temp << 8; + goto write_nz_zp; + } + + case 0x36: // ROL zp,x + data = uint8_t (data + x); + goto rol_zp; + + case 0x16: // ASL zp,x + data = uint8_t (data + x); + case 0x06: // ASL zp + c = 0; + case 0x26: // ROL zp + rol_zp: + nz = c >> 8 & 1; + nz |= (c = READ_LOW( data ) << 1); + goto write_nz_zp; + +// Increment/decrement + + case 0xCA: // DEX + INC_DEC_XY( x, -1 ) + + case 0x88: // DEY + INC_DEC_XY( y, -1 ) + + case 0xF6: // INC zp,x + data = uint8_t (data + x); + case 0xE6: // INC zp + nz = 1; + goto add_nz_zp; + + case 0xD6: // DEC zp,x + data = uint8_t (data + x); + case 0xC6: // DEC zp + nz = (unsigned) -1; + add_nz_zp: + nz += READ_LOW( data ); + write_nz_zp: + pc++; + WRITE_LOW( data, nz ); + goto loop; + + case 0xFE: // INC abs,x + data = x + GET_ADDR(); + goto inc_ptr; + + case 0xEE: // INC abs + data = GET_ADDR(); + inc_ptr: + nz = 1; + goto inc_common; + + case 0xDE: // DEC abs,x + data = x + GET_ADDR(); + goto dec_ptr; + + case 0xCE: // DEC abs + data = GET_ADDR(); + dec_ptr: + nz = (unsigned) -1; + inc_common: + FLUSH_TIME(); + nz += READ( data ); + pc += 2; + WRITE( data, (uint8_t) nz ); + CACHE_TIME(); + goto loop; + +// Transfer + + case 0xAA: // TAX + x = a; + nz = a; + goto loop; + + case 0x8A: // TXA + a = x; + nz = x; + goto loop; + + case 0x9A: // TXS + SET_SP( x ); // verified (no flag change) + goto loop; + + case 0xBA: // TSX + x = nz = GET_SP(); + goto loop; + +// Stack + + case 0x48: // PHA + PUSH( a ); // verified + goto loop; + + case 0x68: // PLA + a = nz = READ_LOW( sp ); + sp = (sp - 0xFF) | 0x100; + goto loop; + + case 0x40:{// RTI + fuint8 temp = READ_LOW( sp ); + pc = READ_LOW( 0x100 | (sp - 0xFF) ); + pc |= READ_LOW( 0x100 | (sp - 0xFE) ) * 0x100; + sp = (sp - 0xFD) | 0x100; + data = status; + SET_STATUS( temp ); + if ( !((data ^ status) & st_i) ) goto loop; // I flag didn't change + this->r.status = status; // update externally-visible I flag + blargg_long delta = s.base - irq_time_; + if ( delta <= 0 ) goto loop; + if ( status & st_i ) goto loop; + s_time += delta; + s.base = irq_time_; + goto loop; + } + + case 0x28:{// PLP + fuint8 temp = READ_LOW( sp ); + sp = (sp - 0xFF) | 0x100; + fuint8 changed = status ^ temp; + SET_STATUS( temp ); + if ( !(changed & st_i) ) + goto loop; // I flag didn't change + if ( status & st_i ) + goto handle_sei; + goto handle_cli; + } + + case 0x08: { // PHP + fuint8 temp; + CALC_STATUS( temp ); + PUSH( temp | (st_b | st_r) ); + goto loop; + } + + case 0x6C:{// JMP (ind) + data = GET_ADDR(); + check( unsigned (data - 0x2000) >= 0x4000 ); // ensure it's outside I/O space + uint8_t const* page = s.code_map [data >> page_bits]; + pc = page [PAGE_OFFSET( data )]; + data = (data & 0xFF00) | ((data + 1) & 0xFF); + pc |= page [PAGE_OFFSET( data )] << 8; + goto loop; + } + + case 0x00: // BRK + goto handle_brk; + +// Flags + + case 0x38: // SEC + c = (unsigned) ~0; + goto loop; + + case 0x18: // CLC + c = 0; + goto loop; + + case 0xB8: // CLV + status &= ~st_v; + goto loop; + + case 0xD8: // CLD + status &= ~st_d; + goto loop; + + case 0xF8: // SED + status |= st_d; + goto loop; + + case 0x58: // CLI + if ( !(status & st_i) ) + goto loop; + status &= ~st_i; + handle_cli: { + //debug_printf( "CLI at %d\n", TIME ); + this->r.status = status; // update externally-visible I flag + blargg_long delta = s.base - irq_time_; + if ( delta <= 0 ) + { + if ( TIME < irq_time_ ) + goto loop; + goto delayed_cli; + } + s.base = irq_time_; + s_time += delta; + if ( s_time < 0 ) + goto loop; + + if ( delta >= s_time + 1 ) + { + s.base += s_time + 1; + s_time = -1; + goto loop; + } + + // TODO: implement + delayed_cli: + debug_printf( "Delayed CLI not emulated\n" ); + goto loop; + } + + case 0x78: // SEI + if ( status & st_i ) + goto loop; + status |= st_i; + handle_sei: { + this->r.status = status; // update externally-visible I flag + blargg_long delta = s.base - end_time_; + s.base = end_time_; + s_time += delta; + if ( s_time < 0 ) + goto loop; + + debug_printf( "Delayed SEI not emulated\n" ); + goto loop; + } + +// Unofficial + + // SKW - Skip word + case 0x1C: case 0x3C: case 0x5C: case 0x7C: case 0xDC: case 0xFC: + HANDLE_PAGE_CROSSING( data + x ); + case 0x0C: + pc++; + // SKB - Skip byte + case 0x74: case 0x04: case 0x14: case 0x34: case 0x44: case 0x54: case 0x64: + case 0x80: case 0x82: case 0x89: case 0xC2: case 0xD4: case 0xE2: case 0xF4: + pc++; + goto loop; + + // NOP + case 0xEA: case 0x1A: case 0x3A: case 0x5A: case 0x7A: case 0xDA: case 0xFA: + goto loop; + + case bad_opcode: // HLT + pc--; + if ( pc > 0xFFFF ) + { + // handle wrap-around (assumes caller has put page of HLT at 0x10000) + pc &= 0xFFFF; + goto loop; + } + case 0x02: case 0x12: case 0x22: case 0x32: case 0x42: case 0x52: + case 0x62: case 0x72: case 0x92: case 0xB2: case 0xD2: + goto stop; + +// Unimplemented + + case 0xFF: // force 256-entry jump table for optimization purposes + c |= 1; + default: + check( (unsigned) opcode <= 0xFF ); + // skip over proper number of bytes + static unsigned char const illop_lens [8] = { + 0x40, 0x40, 0x40, 0x80, 0x40, 0x40, 0x80, 0xA0 + }; + fuint8 opcode = instr [-1]; + fint16 len = illop_lens [opcode >> 2 & 7] >> (opcode << 1 & 6) & 3; + if ( opcode == 0x9C ) + len = 2; + pc += len; + error_count_++; + + if ( (opcode >> 4) == 0x0B ) + { + if ( opcode == 0xB3 ) + data = READ_LOW( data ); + if ( opcode != 0xB7 ) + HANDLE_PAGE_CROSSING( data + y ); + } + goto loop; + } + assert( false ); + + int result_; +handle_brk: + pc++; + result_ = 4; + +interrupt: + { + s_time += 7; + + WRITE_LOW( 0x100 | (sp - 1), pc >> 8 ); + WRITE_LOW( 0x100 | (sp - 2), pc ); + pc = GET_LE16( &READ_PROG( 0xFFFA ) + result_ ); + + sp = (sp - 3) | 0x100; + fuint8 temp; + CALC_STATUS( temp ); + temp |= st_r; + if ( result_ ) + temp |= st_b; // TODO: incorrectly sets B flag for IRQ + WRITE_LOW( sp, temp ); + + this->r.status = status |= st_i; + blargg_long delta = s.base - end_time_; + if ( delta >= 0 ) goto loop; + s_time += delta; + s.base = end_time_; + goto loop; + } + +out_of_time: + pc--; + FLUSH_TIME(); + CPU_DONE( this, TIME, result_ ); + CACHE_TIME(); + if ( result_ >= 0 ) + goto interrupt; + if ( s_time < 0 ) + goto loop; + +stop: + + s.time = s_time; + + r.pc = pc; + r.sp = GET_SP(); + r.a = a; + r.x = x; + r.y = y; + + { + fuint8 temp; + CALC_STATUS( temp ); + r.status = temp; + } + + this->state_ = s; + this->state = &this->state_; + + return s_time < 0; +} + diff --git a/libs/gme/gme/Nes_Cpu.h b/libs/gme/gme/Nes_Cpu.h new file mode 100644 index 000000000..c139e069f --- /dev/null +++ b/libs/gme/gme/Nes_Cpu.h @@ -0,0 +1,114 @@ +// NES 6502 CPU emulator + +// Game_Music_Emu 0.6.0 +#ifndef NES_CPU_H +#define NES_CPU_H + +#include "blargg_common.h" + +typedef blargg_long nes_time_t; // clock cycle count +typedef unsigned nes_addr_t; // 16-bit address +enum { future_nes_time = INT_MAX / 2 + 1 }; + +class Nes_Cpu { +public: + typedef BOOST::uint8_t uint8_t; + + // Clear registers, map low memory and its three mirrors to address 0, + // and mirror unmapped_page in remaining memory + void reset( void const* unmapped_page = 0 ); + + // Map code memory (memory accessed via the program counter). Start and size + // must be multiple of page_size. If mirror is true, repeats code page + // throughout address range. + enum { page_size = 0x800 }; + void map_code( nes_addr_t start, unsigned size, void const* code, bool mirror = false ); + + // Access emulated memory as CPU does + uint8_t const* get_code( nes_addr_t ); + + // 2KB of RAM at address 0 + uint8_t low_mem [0x800]; + + // NES 6502 registers. Not kept updated during a call to run(). + struct registers_t { + BOOST::uint16_t pc; + BOOST::uint8_t a; + BOOST::uint8_t x; + BOOST::uint8_t y; + BOOST::uint8_t status; + BOOST::uint8_t sp; + }; + registers_t r; + + // Set end_time and run CPU from current time. Returns true if execution + // stopped due to encountering bad_opcode. + bool run( nes_time_t end_time ); + + // Time of beginning of next instruction to be executed + nes_time_t time() const { return state->time + state->base; } + void set_time( nes_time_t t ) { state->time = t - state->base; } + void adjust_time( int delta ) { state->time += delta; } + + nes_time_t irq_time() const { return irq_time_; } + void set_irq_time( nes_time_t ); + + nes_time_t end_time() const { return end_time_; } + void set_end_time( nes_time_t ); + + // Number of undefined instructions encountered and skipped + void clear_error_count() { error_count_ = 0; } + unsigned long error_count() const { return error_count_; } + + // CPU invokes bad opcode handler if it encounters this + enum { bad_opcode = 0xF2 }; + +public: + Nes_Cpu() { state = &state_; } + enum { page_bits = 11 }; + enum { page_count = 0x10000 >> page_bits }; + enum { irq_inhibit = 0x04 }; +private: + struct state_t { + uint8_t const* code_map [page_count + 1]; + nes_time_t base; + int time; + }; + state_t* state; // points to state_ or a local copy within run() + state_t state_; + nes_time_t irq_time_; + nes_time_t end_time_; + unsigned long error_count_; + + void set_code_page( int, void const* ); + inline int update_end_time( nes_time_t end, nes_time_t irq ); +}; + +inline BOOST::uint8_t const* Nes_Cpu::get_code( nes_addr_t addr ) +{ + return state->code_map [addr >> page_bits] + addr + #if !BLARGG_NONPORTABLE + % (unsigned) page_size + #endif + ; +} + +inline int Nes_Cpu::update_end_time( nes_time_t t, nes_time_t irq ) +{ + if ( irq < t && !(r.status & irq_inhibit) ) t = irq; + int delta = state->base - t; + state->base = t; + return delta; +} + +inline void Nes_Cpu::set_irq_time( nes_time_t t ) +{ + state->time += update_end_time( end_time_, (irq_time_ = t) ); +} + +inline void Nes_Cpu::set_end_time( nes_time_t t ) +{ + state->time += update_end_time( (end_time_ = t), irq_time_ ); +} + +#endif diff --git a/libs/gme/gme/Nes_Fme7_Apu.cpp b/libs/gme/gme/Nes_Fme7_Apu.cpp new file mode 100644 index 000000000..bc8ca7f48 --- /dev/null +++ b/libs/gme/gme/Nes_Fme7_Apu.cpp @@ -0,0 +1,121 @@ +// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/ + +#include "Nes_Fme7_Apu.h" + +#include + +/* Copyright (C) 2003-2006 Shay Green. This module 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 +module 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 module; if not, write to the Free Software Foundation, +Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + +#include "blargg_source.h" + +void Nes_Fme7_Apu::reset() +{ + last_time = 0; + + for ( int i = 0; i < osc_count; i++ ) + oscs [i].last_amp = 0; + + fme7_apu_state_t* state = this; + memset( state, 0, sizeof *state ); +} + +unsigned char const Nes_Fme7_Apu::amp_table [16] = +{ + #define ENTRY( n ) (unsigned char) (n * amp_range + 0.5) + ENTRY(0.0000), ENTRY(0.0078), ENTRY(0.0110), ENTRY(0.0156), + ENTRY(0.0221), ENTRY(0.0312), ENTRY(0.0441), ENTRY(0.0624), + ENTRY(0.0883), ENTRY(0.1249), ENTRY(0.1766), ENTRY(0.2498), + ENTRY(0.3534), ENTRY(0.4998), ENTRY(0.7070), ENTRY(1.0000) + #undef ENTRY +}; + +void Nes_Fme7_Apu::run_until( blip_time_t end_time ) +{ + require( end_time >= last_time ); + + for ( int index = 0; index < osc_count; index++ ) + { + int mode = regs [7] >> index; + int vol_mode = regs [010 + index]; + int volume = amp_table [vol_mode & 0x0F]; + + Blip_Buffer* const osc_output = oscs [index].output; + if ( !osc_output ) + continue; + osc_output->set_modified(); + + // check for unsupported mode + #ifndef NDEBUG + if ( (mode & 011) <= 001 && vol_mode & 0x1F ) + debug_printf( "FME7 used unimplemented sound mode: %02X, vol_mode: %02X\n", + mode, vol_mode & 0x1F ); + #endif + + if ( (mode & 001) | (vol_mode & 0x10) ) + volume = 0; // noise and envelope aren't supported + + // period + int const period_factor = 16; + unsigned period = (regs [index * 2 + 1] & 0x0F) * 0x100 * period_factor + + regs [index * 2] * period_factor; + if ( period < 50 ) // around 22 kHz + { + volume = 0; + if ( !period ) // on my AY-3-8910A, period doesn't have extra one added + period = period_factor; + } + + // current amplitude + int amp = volume; + if ( !phases [index] ) + amp = 0; + { + int delta = amp - oscs [index].last_amp; + if ( delta ) + { + oscs [index].last_amp = amp; + synth.offset( last_time, delta, osc_output ); + } + } + + blip_time_t time = last_time + delays [index]; + if ( time < end_time ) + { + int delta = amp * 2 - volume; + if ( volume ) + { + do + { + delta = -delta; + synth.offset_inline( time, delta, osc_output ); + time += period; + } + while ( time < end_time ); + + oscs [index].last_amp = (delta + volume) >> 1; + phases [index] = (delta > 0); + } + else + { + // maintain phase when silent + int count = (end_time - time + period - 1) / period; + phases [index] ^= count & 1; + time += (blargg_long) count * period; + } + } + + delays [index] = time - end_time; + } + + last_time = end_time; +} + diff --git a/libs/gme/gme/Nes_Fme7_Apu.h b/libs/gme/gme/Nes_Fme7_Apu.h new file mode 100644 index 000000000..9069bd06a --- /dev/null +++ b/libs/gme/gme/Nes_Fme7_Apu.h @@ -0,0 +1,131 @@ +// Sunsoft FME-7 sound emulator + +// Game_Music_Emu 0.6.0 +#ifndef NES_FME7_APU_H +#define NES_FME7_APU_H + +#include "blargg_common.h" +#include "Blip_Buffer.h" + +struct fme7_apu_state_t +{ + enum { reg_count = 14 }; + BOOST::uint8_t regs [reg_count]; + BOOST::uint8_t phases [3]; // 0 or 1 + BOOST::uint8_t latch; + BOOST::uint16_t delays [3]; // a, b, c +}; + +class Nes_Fme7_Apu : private fme7_apu_state_t { +public: + // See Nes_Apu.h for reference + void reset(); + void volume( double ); + void treble_eq( blip_eq_t const& ); + void output( Blip_Buffer* ); + enum { osc_count = 3 }; + void osc_output( int index, Blip_Buffer* ); + void end_frame( blip_time_t ); + void save_state( fme7_apu_state_t* ) const; + void load_state( fme7_apu_state_t const& ); + + // Mask and addresses of registers + enum { addr_mask = 0xE000 }; + enum { data_addr = 0xE000 }; + enum { latch_addr = 0xC000 }; + + // (addr & addr_mask) == latch_addr + void write_latch( int ); + + // (addr & addr_mask) == data_addr + void write_data( blip_time_t, int data ); + +public: + Nes_Fme7_Apu(); + BLARGG_DISABLE_NOTHROW +private: + // noncopyable + Nes_Fme7_Apu( const Nes_Fme7_Apu& ); + Nes_Fme7_Apu& operator = ( const Nes_Fme7_Apu& ); + + static unsigned char const amp_table [16]; + + struct { + Blip_Buffer* output; + int last_amp; + } oscs [osc_count]; + blip_time_t last_time; + + enum { amp_range = 192 }; // can be any value; this gives best error/quality tradeoff + Blip_Synth synth; + + void run_until( blip_time_t ); +}; + +inline void Nes_Fme7_Apu::volume( double v ) +{ + synth.volume( 0.38 / amp_range * v ); // to do: fine-tune +} + +inline void Nes_Fme7_Apu::treble_eq( blip_eq_t const& eq ) +{ + synth.treble_eq( eq ); +} + +inline void Nes_Fme7_Apu::osc_output( int i, Blip_Buffer* buf ) +{ + assert( (unsigned) i < osc_count ); + oscs [i].output = buf; +} + +inline void Nes_Fme7_Apu::output( Blip_Buffer* buf ) +{ + for ( int i = 0; i < osc_count; i++ ) + osc_output( i, buf ); +} + +inline Nes_Fme7_Apu::Nes_Fme7_Apu() +{ + output( NULL ); + volume( 1.0 ); + reset(); +} + +inline void Nes_Fme7_Apu::write_latch( int data ) { latch = data; } + +inline void Nes_Fme7_Apu::write_data( blip_time_t time, int data ) +{ + if ( (unsigned) latch >= reg_count ) + { + #ifdef debug_printf + debug_printf( "FME7 write to %02X (past end of sound registers)\n", (int) latch ); + #endif + return; + } + + run_until( time ); + regs [latch] = data; +} + +inline void Nes_Fme7_Apu::end_frame( blip_time_t time ) +{ + if ( time > last_time ) + run_until( time ); + + assert( last_time >= time ); + last_time -= time; +} + +inline void Nes_Fme7_Apu::save_state( fme7_apu_state_t* out ) const +{ + *out = *this; +} + +inline void Nes_Fme7_Apu::load_state( fme7_apu_state_t const& in ) +{ + reset(); + fme7_apu_state_t* state = this; + *state = in; +} + +#endif diff --git a/libs/gme/gme/Nes_Namco_Apu.cpp b/libs/gme/gme/Nes_Namco_Apu.cpp new file mode 100644 index 000000000..f3235b383 --- /dev/null +++ b/libs/gme/gme/Nes_Namco_Apu.cpp @@ -0,0 +1,145 @@ +// Nes_Snd_Emu 0.1.8. http://www.slack.net/~ant/ + +#include "Nes_Namco_Apu.h" + +/* Copyright (C) 2003-2006 Shay Green. This module 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 +module 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 module; if not, write to the Free Software Foundation, +Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + +#include "blargg_source.h" + +Nes_Namco_Apu::Nes_Namco_Apu() +{ + output( NULL ); + volume( 1.0 ); + reset(); +} + +void Nes_Namco_Apu::reset() +{ + last_time = 0; + addr_reg = 0; + + int i; + for ( i = 0; i < reg_count; i++ ) + reg [i] = 0; + + for ( i = 0; i < osc_count; i++ ) + { + Namco_Osc& osc = oscs [i]; + osc.delay = 0; + osc.last_amp = 0; + osc.wave_pos = 0; + } +} + +void Nes_Namco_Apu::output( Blip_Buffer* buf ) +{ + for ( int i = 0; i < osc_count; i++ ) + osc_output( i, buf ); +} + +/* +void Nes_Namco_Apu::reflect_state( Tagged_Data& data ) +{ + reflect_int16( data, BLARGG_4CHAR('A','D','D','R'), &addr_reg ); + + static const char hex [17] = "0123456789ABCDEF"; + int i; + for ( i = 0; i < reg_count; i++ ) + reflect_int16( data, 'RG\0\0' + hex [i >> 4] * 0x100 + hex [i & 15], ® [i] ); + + for ( i = 0; i < osc_count; i++ ) + { + reflect_int32( data, BLARGG_4CHAR('D','L','Y','0') + i, &oscs [i].delay ); + reflect_int16( data, BLARGG_4CHAR('P','O','S','0') + i, &oscs [i].wave_pos ); + } +} +*/ + +void Nes_Namco_Apu::end_frame( blip_time_t time ) +{ + if ( time > last_time ) + run_until( time ); + + assert( last_time >= time ); + last_time -= time; +} + +void Nes_Namco_Apu::run_until( blip_time_t nes_end_time ) +{ + int active_oscs = (reg [0x7F] >> 4 & 7) + 1; + for ( int i = osc_count - active_oscs; i < osc_count; i++ ) + { + Namco_Osc& osc = oscs [i]; + Blip_Buffer* output = osc.output; + if ( !output ) + continue; + output->set_modified(); + + blip_resampled_time_t time = + output->resampled_time( last_time ) + osc.delay; + blip_resampled_time_t end_time = output->resampled_time( nes_end_time ); + osc.delay = 0; + if ( time < end_time ) + { + const BOOST::uint8_t* osc_reg = ® [i * 8 + 0x40]; + if ( !(osc_reg [4] & 0xE0) ) + continue; + + int volume = osc_reg [7] & 15; + if ( !volume ) + continue; + + blargg_long freq = (osc_reg [4] & 3) * 0x10000 + osc_reg [2] * 0x100L + osc_reg [0]; + if ( freq < 64 * active_oscs ) + continue; // prevent low frequencies from excessively delaying freq changes + blip_resampled_time_t period = + output->resampled_duration( 983040 ) / freq * active_oscs; + + int wave_size = 32 - (osc_reg [4] >> 2 & 7) * 4; + if ( !wave_size ) + continue; + + int last_amp = osc.last_amp; + int wave_pos = osc.wave_pos; + + do + { + // read wave sample + int addr = wave_pos + osc_reg [6]; + int sample = reg [addr >> 1] >> (addr << 2 & 4); + wave_pos++; + sample = (sample & 15) * volume; + + // output impulse if amplitude changed + int delta = sample - last_amp; + if ( delta ) + { + last_amp = sample; + synth.offset_resampled( time, delta, output ); + } + + // next sample + time += period; + if ( wave_pos >= wave_size ) + wave_pos = 0; + } + while ( time < end_time ); + + osc.wave_pos = wave_pos; + osc.last_amp = last_amp; + } + osc.delay = time - end_time; + } + + last_time = nes_end_time; +} + diff --git a/libs/gme/gme/Nes_Namco_Apu.h b/libs/gme/gme/Nes_Namco_Apu.h new file mode 100644 index 000000000..db5fea4bf --- /dev/null +++ b/libs/gme/gme/Nes_Namco_Apu.h @@ -0,0 +1,102 @@ +// Namco 106 sound chip emulator + +// Nes_Snd_Emu 0.1.8 +#ifndef NES_NAMCO_APU_H +#define NES_NAMCO_APU_H + +#include "blargg_common.h" +#include "Blip_Buffer.h" + +struct namco_state_t; + +class Nes_Namco_Apu { +public: + // See Nes_Apu.h for reference. + void volume( double ); + void treble_eq( const blip_eq_t& ); + void output( Blip_Buffer* ); + enum { osc_count = 8 }; + void osc_output( int index, Blip_Buffer* ); + void reset(); + void end_frame( blip_time_t ); + + // Read/write data register is at 0x4800 + enum { data_reg_addr = 0x4800 }; + void write_data( blip_time_t, int ); + int read_data(); + + // Write-only address register is at 0xF800 + enum { addr_reg_addr = 0xF800 }; + void write_addr( int ); + + // to do: implement save/restore + void save_state( namco_state_t* out ) const; + void load_state( namco_state_t const& ); + +public: + Nes_Namco_Apu(); + BLARGG_DISABLE_NOTHROW +private: + // noncopyable + Nes_Namco_Apu( const Nes_Namco_Apu& ); + Nes_Namco_Apu& operator = ( const Nes_Namco_Apu& ); + + struct Namco_Osc { + blargg_long delay; + Blip_Buffer* output; + short last_amp; + short wave_pos; + }; + + Namco_Osc oscs [osc_count]; + + blip_time_t last_time; + int addr_reg; + + enum { reg_count = 0x80 }; + BOOST::uint8_t reg [reg_count]; + Blip_Synth synth; + + BOOST::uint8_t& access(); + void run_until( blip_time_t ); +}; +/* +struct namco_state_t +{ + BOOST::uint8_t regs [0x80]; + BOOST::uint8_t addr; + BOOST::uint8_t unused; + BOOST::uint8_t positions [8]; + BOOST::uint32_t delays [8]; +}; +*/ + +inline BOOST::uint8_t& Nes_Namco_Apu::access() +{ + int addr = addr_reg & 0x7F; + if ( addr_reg & 0x80 ) + addr_reg = (addr + 1) | 0x80; + return reg [addr]; +} + +inline void Nes_Namco_Apu::volume( double v ) { synth.volume( 0.10 / osc_count * v ); } + +inline void Nes_Namco_Apu::treble_eq( const blip_eq_t& eq ) { synth.treble_eq( eq ); } + +inline void Nes_Namco_Apu::write_addr( int v ) { addr_reg = v; } + +inline int Nes_Namco_Apu::read_data() { return access(); } + +inline void Nes_Namco_Apu::osc_output( int i, Blip_Buffer* buf ) +{ + assert( (unsigned) i < osc_count ); + oscs [i].output = buf; +} + +inline void Nes_Namco_Apu::write_data( blip_time_t time, int data ) +{ + run_until( time ); + access() = data; +} + +#endif diff --git a/libs/gme/gme/Nes_Oscs.cpp b/libs/gme/gme/Nes_Oscs.cpp new file mode 100644 index 000000000..1ad3f59c0 --- /dev/null +++ b/libs/gme/gme/Nes_Oscs.cpp @@ -0,0 +1,551 @@ +// Nes_Snd_Emu 0.1.8. http://www.slack.net/~ant/ + +#include "Nes_Apu.h" + +/* Copyright (C) 2003-2006 Shay Green. This module 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 +module 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 module; if not, write to the Free Software Foundation, +Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + +#include "blargg_source.h" + +// Nes_Osc + +void Nes_Osc::clock_length( int halt_mask ) +{ + if ( length_counter && !(regs [0] & halt_mask) ) + length_counter--; +} + +void Nes_Envelope::clock_envelope() +{ + int period = regs [0] & 15; + if ( reg_written [3] ) { + reg_written [3] = false; + env_delay = period; + envelope = 15; + } + else if ( --env_delay < 0 ) { + env_delay = period; + if ( envelope | (regs [0] & 0x20) ) + envelope = (envelope - 1) & 15; + } +} + +int Nes_Envelope::volume() const +{ + return length_counter == 0 ? 0 : (regs [0] & 0x10) ? (regs [0] & 15) : envelope; +} + +// Nes_Square + +void Nes_Square::clock_sweep( int negative_adjust ) +{ + int sweep = regs [1]; + + if ( --sweep_delay < 0 ) + { + reg_written [1] = true; + + int period = this->period(); + int shift = sweep & shift_mask; + if ( shift && (sweep & 0x80) && period >= 8 ) + { + int offset = period >> shift; + + if ( sweep & negate_flag ) + offset = negative_adjust - offset; + + if ( period + offset < 0x800 ) + { + period += offset; + // rewrite period + regs [2] = period & 0xFF; + regs [3] = (regs [3] & ~7) | ((period >> 8) & 7); + } + } + } + + if ( reg_written [1] ) { + reg_written [1] = false; + sweep_delay = (sweep >> 4) & 7; + } +} + +// TODO: clean up +inline nes_time_t Nes_Square::maintain_phase( nes_time_t time, nes_time_t end_time, + nes_time_t timer_period ) +{ + nes_time_t remain = end_time - time; + if ( remain > 0 ) + { + int count = (remain + timer_period - 1) / timer_period; + phase = (phase + count) & (phase_range - 1); + time += (blargg_long) count * timer_period; + } + return time; +} + +void Nes_Square::run( nes_time_t time, nes_time_t end_time ) +{ + const int period = this->period(); + const int timer_period = (period + 1) * 2; + + if ( !output ) + { + delay = maintain_phase( time + delay, end_time, timer_period ) - end_time; + return; + } + + output->set_modified(); + + int offset = period >> (regs [1] & shift_mask); + if ( regs [1] & negate_flag ) + offset = 0; + + const int volume = this->volume(); + if ( volume == 0 || period < 8 || (period + offset) >= 0x800 ) + { + if ( last_amp ) { + synth.offset( time, -last_amp, output ); + last_amp = 0; + } + + time += delay; + time = maintain_phase( time, end_time, timer_period ); + } + else + { + // handle duty select + int duty_select = (regs [0] >> 6) & 3; + int duty = 1 << duty_select; // 1, 2, 4, 2 + int amp = 0; + if ( duty_select == 3 ) { + duty = 2; // negated 25% + amp = volume; + } + if ( phase < duty ) + amp ^= volume; + + { + int delta = update_amp( amp ); + if ( delta ) + synth.offset( time, delta, output ); + } + + time += delay; + if ( time < end_time ) + { + Blip_Buffer* const output = this->output; + const Synth& synth = this->synth; + int delta = amp * 2 - volume; + int phase = this->phase; + + do { + phase = (phase + 1) & (phase_range - 1); + if ( phase == 0 || phase == duty ) { + delta = -delta; + synth.offset_inline( time, delta, output ); + } + time += timer_period; + } + while ( time < end_time ); + + last_amp = (delta + volume) >> 1; + this->phase = phase; + } + } + + delay = time - end_time; +} + +// Nes_Triangle + +void Nes_Triangle::clock_linear_counter() +{ + if ( reg_written [3] ) + linear_counter = regs [0] & 0x7F; + else if ( linear_counter ) + linear_counter--; + + if ( !(regs [0] & 0x80) ) + reg_written [3] = false; +} + +inline int Nes_Triangle::calc_amp() const +{ + int amp = phase_range - phase; + if ( amp < 0 ) + amp = phase - (phase_range + 1); + return amp; +} + +// TODO: clean up +inline nes_time_t Nes_Triangle::maintain_phase( nes_time_t time, nes_time_t end_time, + nes_time_t timer_period ) +{ + nes_time_t remain = end_time - time; + if ( remain > 0 ) + { + int count = (remain + timer_period - 1) / timer_period; + phase = ((unsigned) phase + 1 - count) & (phase_range * 2 - 1); + phase++; + time += (blargg_long) count * timer_period; + } + return time; +} + +void Nes_Triangle::run( nes_time_t time, nes_time_t end_time ) +{ + const int timer_period = period() + 1; + if ( !output ) + { + time += delay; + delay = 0; + if ( length_counter && linear_counter && timer_period >= 3 ) + delay = maintain_phase( time, end_time, timer_period ) - end_time; + return; + } + + output->set_modified(); + + // to do: track phase when period < 3 + // to do: Output 7.5 on dac when period < 2? More accurate, but results in more clicks. + + int delta = update_amp( calc_amp() ); + if ( delta ) + synth.offset( time, delta, output ); + + time += delay; + if ( length_counter == 0 || linear_counter == 0 || timer_period < 3 ) + { + time = end_time; + } + else if ( time < end_time ) + { + Blip_Buffer* const output = this->output; + + int phase = this->phase; + int volume = 1; + if ( phase > phase_range ) { + phase -= phase_range; + volume = -volume; + } + + do { + if ( --phase == 0 ) { + phase = phase_range; + volume = -volume; + } + else { + synth.offset_inline( time, volume, output ); + } + + time += timer_period; + } + while ( time < end_time ); + + if ( volume < 0 ) + phase += phase_range; + this->phase = phase; + last_amp = calc_amp(); + } + delay = time - end_time; +} + +// Nes_Dmc + +void Nes_Dmc::reset() +{ + address = 0; + dac = 0; + buf = 0; + bits_remain = 1; + bits = 0; + buf_full = false; + silence = true; + next_irq = Nes_Apu::no_irq; + irq_flag = false; + irq_enabled = false; + + Nes_Osc::reset(); + period = 0x1AC; +} + +void Nes_Dmc::recalc_irq() +{ + nes_time_t irq = Nes_Apu::no_irq; + if ( irq_enabled && length_counter ) + irq = apu->last_dmc_time + delay + + ((length_counter - 1) * 8 + bits_remain - 1) * nes_time_t (period) + 1; + if ( irq != next_irq ) { + next_irq = irq; + apu->irq_changed(); + } +} + +int Nes_Dmc::count_reads( nes_time_t time, nes_time_t* last_read ) const +{ + if ( last_read ) + *last_read = time; + + if ( length_counter == 0 ) + return 0; // not reading + + nes_time_t first_read = next_read_time(); + nes_time_t avail = time - first_read; + if ( avail <= 0 ) + return 0; + + int count = (avail - 1) / (period * 8) + 1; + if ( !(regs [0] & loop_flag) && count > length_counter ) + count = length_counter; + + if ( last_read ) + { + *last_read = first_read + (count - 1) * (period * 8) + 1; + check( *last_read <= time ); + check( count == count_reads( *last_read, NULL ) ); + check( count - 1 == count_reads( *last_read - 1, NULL ) ); + } + + return count; +} + +static short const dmc_period_table [2] [16] = { + {428, 380, 340, 320, 286, 254, 226, 214, // NTSC + 190, 160, 142, 128, 106, 84, 72, 54}, + + {398, 354, 316, 298, 276, 236, 210, 198, // PAL + 176, 148, 132, 118, 98, 78, 66, 50} +}; + +inline void Nes_Dmc::reload_sample() +{ + address = 0x4000 + regs [2] * 0x40; + length_counter = regs [3] * 0x10 + 1; +} + +static byte const dac_table [128] = +{ + 0, 1, 2, 3, 4, 5, 6, 7, 7, 8, 9,10,11,12,13,14, + 15,15,16,17,18,19,20,20,21,22,23,24,24,25,26,27, + 27,28,29,30,31,31,32,33,33,34,35,36,36,37,38,38, + 39,40,41,41,42,43,43,44,45,45,46,47,47,48,48,49, + 50,50,51,52,52,53,53,54,55,55,56,56,57,58,58,59, + 59,60,60,61,61,62,63,63,64,64,65,65,66,66,67,67, + 68,68,69,70,70,71,71,72,72,73,73,74,74,75,75,75, + 76,76,77,77,78,78,79,79,80,80,81,81,82,82,82,83, +}; + +void Nes_Dmc::write_register( int addr, int data ) +{ + if ( addr == 0 ) + { + period = dmc_period_table [pal_mode] [data & 15]; + irq_enabled = (data & 0xC0) == 0x80; // enabled only if loop disabled + irq_flag &= irq_enabled; + recalc_irq(); + } + else if ( addr == 1 ) + { + int old_dac = dac; + dac = data & 0x7F; + + // adjust last_amp so that "pop" amplitude will be properly non-linear + // with respect to change in dac + int faked_nonlinear = dac - (dac_table [dac] - dac_table [old_dac]); + if ( !nonlinear ) + last_amp = faked_nonlinear; + } +} + +void Nes_Dmc::start() +{ + reload_sample(); + fill_buffer(); + recalc_irq(); +} + +void Nes_Dmc::fill_buffer() +{ + if ( !buf_full && length_counter ) + { + require( prg_reader ); // prg_reader must be set + buf = prg_reader( prg_reader_data, 0x8000u + address ); + address = (address + 1) & 0x7FFF; + buf_full = true; + if ( --length_counter == 0 ) + { + if ( regs [0] & loop_flag ) { + reload_sample(); + } + else { + apu->osc_enables &= ~0x10; + irq_flag = irq_enabled; + next_irq = Nes_Apu::no_irq; + apu->irq_changed(); + } + } + } +} + +void Nes_Dmc::run( nes_time_t time, nes_time_t end_time ) +{ + int delta = update_amp( dac ); + if ( !output ) + { + silence = true; + } + else + { + output->set_modified(); + if ( delta ) + synth.offset( time, delta, output ); + } + + time += delay; + if ( time < end_time ) + { + int bits_remain = this->bits_remain; + if ( silence && !buf_full ) + { + int count = (end_time - time + period - 1) / period; + bits_remain = (bits_remain - 1 + 8 - (count % 8)) % 8 + 1; + time += count * period; + } + else + { + Blip_Buffer* const output = this->output; + const int period = this->period; + int bits = this->bits; + int dac = this->dac; + + do + { + if ( !silence ) + { + int step = (bits & 1) * 4 - 2; + bits >>= 1; + if ( unsigned (dac + step) <= 0x7F ) { + dac += step; + synth.offset_inline( time, step, output ); + } + } + + time += period; + + if ( --bits_remain == 0 ) + { + bits_remain = 8; + if ( !buf_full ) { + silence = true; + } + else { + silence = false; + bits = buf; + buf_full = false; + if ( !output ) + silence = true; + fill_buffer(); + } + } + } + while ( time < end_time ); + + this->dac = dac; + this->last_amp = dac; + this->bits = bits; + } + this->bits_remain = bits_remain; + } + delay = time - end_time; +} + +// Nes_Noise + +static short const noise_period_table [16] = { + 0x004, 0x008, 0x010, 0x020, 0x040, 0x060, 0x080, 0x0A0, + 0x0CA, 0x0FE, 0x17C, 0x1FC, 0x2FA, 0x3F8, 0x7F2, 0xFE4 +}; + +void Nes_Noise::run( nes_time_t time, nes_time_t end_time ) +{ + int period = noise_period_table [regs [2] & 15]; + + if ( !output ) + { + // TODO: clean up + time += delay; + delay = time + (end_time - time + period - 1) / period * period - end_time; + return; + } + + output->set_modified(); + + const int volume = this->volume(); + int amp = (noise & 1) ? volume : 0; + { + int delta = update_amp( amp ); + if ( delta ) + synth.offset( time, delta, output ); + } + + time += delay; + if ( time < end_time ) + { + const int mode_flag = 0x80; + + if ( !volume ) + { + // round to next multiple of period + time += (end_time - time + period - 1) / period * period; + + // approximate noise cycling while muted, by shuffling up noise register + // to do: precise muted noise cycling? + if ( !(regs [2] & mode_flag) ) { + int feedback = (noise << 13) ^ (noise << 14); + noise = (feedback & 0x4000) | (noise >> 1); + } + } + else + { + Blip_Buffer* const output = this->output; + + // using resampled time avoids conversion in synth.offset() + blip_resampled_time_t rperiod = output->resampled_duration( period ); + blip_resampled_time_t rtime = output->resampled_time( time ); + + int noise = this->noise; + int delta = amp * 2 - volume; + const int tap = (regs [2] & mode_flag ? 8 : 13); + + do { + int feedback = (noise << tap) ^ (noise << 14); + time += period; + + if ( (noise + 1) & 2 ) { + // bits 0 and 1 of noise differ + delta = -delta; + synth.offset_resampled( rtime, delta, output ); + } + + rtime += rperiod; + noise = (feedback & 0x4000) | (noise >> 1); + } + while ( time < end_time ); + + last_amp = (delta + volume) >> 1; + this->noise = noise; + } + } + + delay = time - end_time; +} + diff --git a/libs/gme/gme/Nes_Oscs.h b/libs/gme/gme/Nes_Oscs.h new file mode 100644 index 000000000..b675bfb47 --- /dev/null +++ b/libs/gme/gme/Nes_Oscs.h @@ -0,0 +1,147 @@ +// Private oscillators used by Nes_Apu + +// Nes_Snd_Emu 0.1.8 +#ifndef NES_OSCS_H +#define NES_OSCS_H + +#include "blargg_common.h" +#include "Blip_Buffer.h" + +class Nes_Apu; + +struct Nes_Osc +{ + unsigned char regs [4]; + bool reg_written [4]; + Blip_Buffer* output; + int length_counter;// length counter (0 if unused by oscillator) + int delay; // delay until next (potential) transition + int last_amp; // last amplitude oscillator was outputting + + void clock_length( int halt_mask ); + int period() const { + return (regs [3] & 7) * 0x100 + (regs [2] & 0xFF); + } + void reset() { + delay = 0; + last_amp = 0; + } + int update_amp( int amp ) { + int delta = amp - last_amp; + last_amp = amp; + return delta; + } +}; + +struct Nes_Envelope : Nes_Osc +{ + int envelope; + int env_delay; + + void clock_envelope(); + int volume() const; + void reset() { + envelope = 0; + env_delay = 0; + Nes_Osc::reset(); + } +}; + +// Nes_Square +struct Nes_Square : Nes_Envelope +{ + enum { negate_flag = 0x08 }; + enum { shift_mask = 0x07 }; + enum { phase_range = 8 }; + int phase; + int sweep_delay; + + typedef Blip_Synth Synth; + Synth const& synth; // shared between squares + + Nes_Square( Synth const* s ) : synth( *s ) { } + + void clock_sweep( int adjust ); + void run( nes_time_t, nes_time_t ); + void reset() { + sweep_delay = 0; + Nes_Envelope::reset(); + } + nes_time_t maintain_phase( nes_time_t time, nes_time_t end_time, + nes_time_t timer_period ); +}; + +// Nes_Triangle +struct Nes_Triangle : Nes_Osc +{ + enum { phase_range = 16 }; + int phase; + int linear_counter; + Blip_Synth synth; + + int calc_amp() const; + void run( nes_time_t, nes_time_t ); + void clock_linear_counter(); + void reset() { + linear_counter = 0; + phase = 1; + Nes_Osc::reset(); + } + nes_time_t maintain_phase( nes_time_t time, nes_time_t end_time, + nes_time_t timer_period ); +}; + +// Nes_Noise +struct Nes_Noise : Nes_Envelope +{ + int noise; + Blip_Synth synth; + + void run( nes_time_t, nes_time_t ); + void reset() { + noise = 1 << 14; + Nes_Envelope::reset(); + } +}; + +// Nes_Dmc +struct Nes_Dmc : Nes_Osc +{ + int address; // address of next byte to read + int period; + //int length_counter; // bytes remaining to play (already defined in Nes_Osc) + int buf; + int bits_remain; + int bits; + bool buf_full; + bool silence; + + enum { loop_flag = 0x40 }; + + int dac; + + nes_time_t next_irq; + bool irq_enabled; + bool irq_flag; + bool pal_mode; + bool nonlinear; + + int (*prg_reader)( void*, nes_addr_t ); // needs to be initialized to prg read function + void* prg_reader_data; + + Nes_Apu* apu; + + Blip_Synth synth; + + void start(); + void write_register( int, int ); + void run( nes_time_t, nes_time_t ); + void recalc_irq(); + void fill_buffer(); + void reload_sample(); + void reset(); + int count_reads( nes_time_t, nes_time_t* ) const; + nes_time_t next_read_time() const; +}; + +#endif diff --git a/libs/gme/gme/Nes_Vrc6_Apu.cpp b/libs/gme/gme/Nes_Vrc6_Apu.cpp new file mode 100644 index 000000000..d178407c3 --- /dev/null +++ b/libs/gme/gme/Nes_Vrc6_Apu.cpp @@ -0,0 +1,215 @@ +// Nes_Snd_Emu 0.1.8. http://www.slack.net/~ant/ + +#include "Nes_Vrc6_Apu.h" + +/* Copyright (C) 2003-2006 Shay Green. This module 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 +module 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 module; if not, write to the Free Software Foundation, +Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + +#include "blargg_source.h" + +Nes_Vrc6_Apu::Nes_Vrc6_Apu() +{ + output( NULL ); + volume( 1.0 ); + reset(); +} + +void Nes_Vrc6_Apu::reset() +{ + last_time = 0; + for ( int i = 0; i < osc_count; i++ ) + { + Vrc6_Osc& osc = oscs [i]; + for ( int j = 0; j < reg_count; j++ ) + osc.regs [j] = 0; + osc.delay = 0; + osc.last_amp = 0; + osc.phase = 1; + osc.amp = 0; + } +} + +void Nes_Vrc6_Apu::output( Blip_Buffer* buf ) +{ + for ( int i = 0; i < osc_count; i++ ) + osc_output( i, buf ); +} + +void Nes_Vrc6_Apu::run_until( blip_time_t time ) +{ + require( time >= last_time ); + run_square( oscs [0], time ); + run_square( oscs [1], time ); + run_saw( time ); + last_time = time; +} + +void Nes_Vrc6_Apu::write_osc( blip_time_t time, int osc_index, int reg, int data ) +{ + require( (unsigned) osc_index < osc_count ); + require( (unsigned) reg < reg_count ); + + run_until( time ); + oscs [osc_index].regs [reg] = data; +} + +void Nes_Vrc6_Apu::end_frame( blip_time_t time ) +{ + if ( time > last_time ) + run_until( time ); + + assert( last_time >= time ); + last_time -= time; +} + +void Nes_Vrc6_Apu::save_state( vrc6_apu_state_t* out ) const +{ + assert( sizeof (vrc6_apu_state_t) == 20 ); + out->saw_amp = oscs [2].amp; + for ( int i = 0; i < osc_count; i++ ) + { + Vrc6_Osc const& osc = oscs [i]; + for ( int r = 0; r < reg_count; r++ ) + out->regs [i] [r] = osc.regs [r]; + + out->delays [i] = osc.delay; + out->phases [i] = osc.phase; + } +} + +void Nes_Vrc6_Apu::load_state( vrc6_apu_state_t const& in ) +{ + reset(); + oscs [2].amp = in.saw_amp; + for ( int i = 0; i < osc_count; i++ ) + { + Vrc6_Osc& osc = oscs [i]; + for ( int r = 0; r < reg_count; r++ ) + osc.regs [r] = in.regs [i] [r]; + + osc.delay = in.delays [i]; + osc.phase = in.phases [i]; + } + if ( !oscs [2].phase ) + oscs [2].phase = 1; +} + +void Nes_Vrc6_Apu::run_square( Vrc6_Osc& osc, blip_time_t end_time ) +{ + Blip_Buffer* output = osc.output; + if ( !output ) + return; + output->set_modified(); + + int volume = osc.regs [0] & 15; + if ( !(osc.regs [2] & 0x80) ) + volume = 0; + + int gate = osc.regs [0] & 0x80; + int duty = ((osc.regs [0] >> 4) & 7) + 1; + int delta = ((gate || osc.phase < duty) ? volume : 0) - osc.last_amp; + blip_time_t time = last_time; + if ( delta ) + { + osc.last_amp += delta; + square_synth.offset( time, delta, output ); + } + + time += osc.delay; + osc.delay = 0; + int period = osc.period(); + if ( volume && !gate && period > 4 ) + { + if ( time < end_time ) + { + int phase = osc.phase; + + do + { + phase++; + if ( phase == 16 ) + { + phase = 0; + osc.last_amp = volume; + square_synth.offset( time, volume, output ); + } + if ( phase == duty ) + { + osc.last_amp = 0; + square_synth.offset( time, -volume, output ); + } + time += period; + } + while ( time < end_time ); + + osc.phase = phase; + } + osc.delay = time - end_time; + } +} + +void Nes_Vrc6_Apu::run_saw( blip_time_t end_time ) +{ + Vrc6_Osc& osc = oscs [2]; + Blip_Buffer* output = osc.output; + if ( !output ) + return; + output->set_modified(); + + int amp = osc.amp; + int amp_step = osc.regs [0] & 0x3F; + blip_time_t time = last_time; + int last_amp = osc.last_amp; + if ( !(osc.regs [2] & 0x80) || !(amp_step | amp) ) + { + osc.delay = 0; + int delta = (amp >> 3) - last_amp; + last_amp = amp >> 3; + saw_synth.offset( time, delta, output ); + } + else + { + time += osc.delay; + if ( time < end_time ) + { + int period = osc.period() * 2; + int phase = osc.phase; + + do + { + if ( --phase == 0 ) + { + phase = 7; + amp = 0; + } + + int delta = (amp >> 3) - last_amp; + if ( delta ) + { + last_amp = amp >> 3; + saw_synth.offset( time, delta, output ); + } + + time += period; + amp = (amp + amp_step) & 0xFF; + } + while ( time < end_time ); + + osc.phase = phase; + osc.amp = amp; + } + + osc.delay = time - end_time; + } + + osc.last_amp = last_amp; +} + diff --git a/libs/gme/gme/Nes_Vrc6_Apu.h b/libs/gme/gme/Nes_Vrc6_Apu.h new file mode 100644 index 000000000..18722233f --- /dev/null +++ b/libs/gme/gme/Nes_Vrc6_Apu.h @@ -0,0 +1,95 @@ +// Konami VRC6 sound chip emulator + +// Nes_Snd_Emu 0.1.8 +#ifndef NES_VRC6_APU_H +#define NES_VRC6_APU_H + +#include "blargg_common.h" +#include "Blip_Buffer.h" + +struct vrc6_apu_state_t; + +class Nes_Vrc6_Apu { +public: + // See Nes_Apu.h for reference + void reset(); + void volume( double ); + void treble_eq( blip_eq_t const& ); + void output( Blip_Buffer* ); + enum { osc_count = 3 }; + void osc_output( int index, Blip_Buffer* ); + void end_frame( blip_time_t ); + void save_state( vrc6_apu_state_t* ) const; + void load_state( vrc6_apu_state_t const& ); + + // Oscillator 0 write-only registers are at $9000-$9002 + // Oscillator 1 write-only registers are at $A000-$A002 + // Oscillator 2 write-only registers are at $B000-$B002 + enum { reg_count = 3 }; + enum { base_addr = 0x9000 }; + enum { addr_step = 0x1000 }; + void write_osc( blip_time_t, int osc, int reg, int data ); + +public: + Nes_Vrc6_Apu(); + BLARGG_DISABLE_NOTHROW +private: + // noncopyable + Nes_Vrc6_Apu( const Nes_Vrc6_Apu& ); + Nes_Vrc6_Apu& operator = ( const Nes_Vrc6_Apu& ); + + struct Vrc6_Osc + { + BOOST::uint8_t regs [3]; + Blip_Buffer* output; + int delay; + int last_amp; + int phase; + int amp; // only used by saw + + int period() const + { + return (regs [2] & 0x0F) * 0x100L + regs [1] + 1; + } + }; + + Vrc6_Osc oscs [osc_count]; + blip_time_t last_time; + + Blip_Synth saw_synth; + Blip_Synth square_synth; + + void run_until( blip_time_t ); + void run_square( Vrc6_Osc& osc, blip_time_t ); + void run_saw( blip_time_t ); +}; + +struct vrc6_apu_state_t +{ + BOOST::uint8_t regs [3] [3]; + BOOST::uint8_t saw_amp; + BOOST::uint16_t delays [3]; + BOOST::uint8_t phases [3]; + BOOST::uint8_t unused; +}; + +inline void Nes_Vrc6_Apu::osc_output( int i, Blip_Buffer* buf ) +{ + assert( (unsigned) i < osc_count ); + oscs [i].output = buf; +} + +inline void Nes_Vrc6_Apu::volume( double v ) +{ + double const factor = 0.0967 * 2; + saw_synth.volume( factor / 31 * v ); + square_synth.volume( factor * 0.5 / 15 * v ); +} + +inline void Nes_Vrc6_Apu::treble_eq( blip_eq_t const& eq ) +{ + saw_synth.treble_eq( eq ); + square_synth.treble_eq( eq ); +} + +#endif diff --git a/libs/gme/gme/Nsf_Emu.cpp b/libs/gme/gme/Nsf_Emu.cpp new file mode 100644 index 000000000..eab4bfbfd --- /dev/null +++ b/libs/gme/gme/Nsf_Emu.cpp @@ -0,0 +1,561 @@ +// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/ + +#include "Nsf_Emu.h" + +#include "blargg_endian.h" +#include +#include + +#if !NSF_EMU_APU_ONLY + #include "Nes_Namco_Apu.h" + #include "Nes_Vrc6_Apu.h" + #include "Nes_Fme7_Apu.h" +#endif + +/* Copyright (C) 2003-2006 Shay Green. This module 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 +module 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 module; if not, write to the Free Software Foundation, +Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + +#include "blargg_source.h" + +int const vrc6_flag = 0x01; +int const namco_flag = 0x10; +int const fme7_flag = 0x20; + +long const clock_divisor = 12; + +Nsf_Emu::equalizer_t const Nsf_Emu::nes_eq = + Music_Emu::make_equalizer( -1.0, 80 ); +Nsf_Emu::equalizer_t const Nsf_Emu::famicom_eq = + Music_Emu::make_equalizer( -15.0, 80 ); + +int Nsf_Emu::pcm_read( void* emu, nes_addr_t addr ) +{ + return *((Nsf_Emu*) emu)->cpu::get_code( addr ); +} + +Nsf_Emu::Nsf_Emu() +{ + vrc6 = 0; + namco = 0; + fme7 = 0; + + set_type( gme_nsf_type ); + set_silence_lookahead( 6 ); + apu.dmc_reader( pcm_read, this ); + Music_Emu::set_equalizer( nes_eq ); + set_gain( 1.4 ); + memset( unmapped_code, Nes_Cpu::bad_opcode, sizeof unmapped_code ); +} + +Nsf_Emu::~Nsf_Emu() { unload(); } + +void Nsf_Emu::unload() +{ + #if !NSF_EMU_APU_ONLY + { + delete vrc6; + vrc6 = 0; + + delete namco; + namco = 0; + + delete fme7; + fme7 = 0; + } + #endif + + rom.clear(); + Music_Emu::unload(); +} + +// Track info + +static void copy_nsf_fields( Nsf_Emu::header_t const& h, track_info_t* out ) +{ + GME_COPY_FIELD( h, out, game ); + GME_COPY_FIELD( h, out, author ); + GME_COPY_FIELD( h, out, copyright ); + if ( h.chip_flags ) + Gme_File::copy_field_( out->system, "Famicom" ); +} + +blargg_err_t Nsf_Emu::track_info_( track_info_t* out, int ) const +{ + copy_nsf_fields( header_, out ); + return 0; +} + +static blargg_err_t check_nsf_header( void const* header ) +{ + if ( memcmp( header, "NESM\x1A", 5 ) ) + return gme_wrong_file_type; + return 0; +} + +struct Nsf_File : Gme_Info_ +{ + Nsf_Emu::header_t h; + + Nsf_File() { set_type( gme_nsf_type ); } + + blargg_err_t load_( Data_Reader& in ) + { + blargg_err_t err = in.read( &h, Nsf_Emu::header_size ); + if ( err ) + return (err == in.eof_error ? gme_wrong_file_type : err); + + if ( h.chip_flags & ~(namco_flag | vrc6_flag | fme7_flag) ) + set_warning( "Uses unsupported audio expansion hardware" ); + + set_track_count( h.track_count ); + return check_nsf_header( &h ); + } + + blargg_err_t track_info_( track_info_t* out, int ) const + { + copy_nsf_fields( h, out ); + return 0; + } +}; + +static Music_Emu* new_nsf_emu () { return BLARGG_NEW Nsf_Emu ; } +static Music_Emu* new_nsf_file() { return BLARGG_NEW Nsf_File; } + +static gme_type_t_ const gme_nsf_type_ = { "Nintendo NES", 0, &new_nsf_emu, &new_nsf_file, "NSF", 1 }; +gme_type_t const gme_nsf_type = &gme_nsf_type_; + + +// Setup + +void Nsf_Emu::set_tempo_( double t ) +{ + unsigned playback_rate = get_le16( header_.ntsc_speed ); + unsigned standard_rate = 0x411A; + clock_rate_ = 1789772.72727; + play_period = 262 * 341L * 4 - 2; // two fewer PPU clocks every four frames + + if ( pal_only ) + { + play_period = 33247 * clock_divisor; + clock_rate_ = 1662607.125; + standard_rate = 0x4E20; + playback_rate = get_le16( header_.pal_speed ); + } + + if ( !playback_rate ) + playback_rate = standard_rate; + + if ( playback_rate != standard_rate || t != 1.0 ) + play_period = long (playback_rate * clock_rate_ / (1000000.0 / clock_divisor * t)); + + apu.set_tempo( t ); +} + +blargg_err_t Nsf_Emu::init_sound() +{ + if ( header_.chip_flags & ~(namco_flag | vrc6_flag | fme7_flag) ) + set_warning( "Uses unsupported audio expansion hardware" ); + + { + #define APU_NAMES "Square 1", "Square 2", "Triangle", "Noise", "DMC" + + int const count = Nes_Apu::osc_count; + static const char* const apu_names [count] = { APU_NAMES }; + set_voice_count( count ); + set_voice_names( apu_names ); + + } + + static int const types [] = { + wave_type | 1, wave_type | 2, wave_type | 0, + noise_type | 0, mixed_type | 1, + wave_type | 3, wave_type | 4, wave_type | 5, + wave_type | 6, wave_type | 7, wave_type | 8, wave_type | 9, + wave_type |10, wave_type |11, wave_type |12, wave_type |13 + }; + set_voice_types( types ); // common to all sound chip configurations + + double adjusted_gain = gain(); + + #if NSF_EMU_APU_ONLY + { + if ( header_.chip_flags ) + set_warning( "Uses unsupported audio expansion hardware" ); + } + #else + { + if ( header_.chip_flags & (namco_flag | vrc6_flag | fme7_flag) ) + set_voice_count( Nes_Apu::osc_count + 3 ); + + if ( header_.chip_flags & namco_flag ) + { + namco = BLARGG_NEW Nes_Namco_Apu; + CHECK_ALLOC( namco ); + adjusted_gain *= 0.75; + + int const count = Nes_Apu::osc_count + Nes_Namco_Apu::osc_count; + static const char* const names [count] = { + APU_NAMES, + "Wave 1", "Wave 2", "Wave 3", "Wave 4", + "Wave 5", "Wave 6", "Wave 7", "Wave 8" + }; + set_voice_count( count ); + set_voice_names( names ); + } + + if ( header_.chip_flags & vrc6_flag ) + { + vrc6 = BLARGG_NEW Nes_Vrc6_Apu; + CHECK_ALLOC( vrc6 ); + adjusted_gain *= 0.75; + + { + int const count = Nes_Apu::osc_count + Nes_Vrc6_Apu::osc_count; + static const char* const names [count] = { + APU_NAMES, + "Saw Wave", "Square 3", "Square 4" + }; + set_voice_count( count ); + set_voice_names( names ); + } + + if ( header_.chip_flags & namco_flag ) + { + int const count = Nes_Apu::osc_count + Nes_Vrc6_Apu::osc_count + + Nes_Namco_Apu::osc_count; + static const char* const names [count] = { + APU_NAMES, + "Saw Wave", "Square 3", "Square 4", + "Wave 1", "Wave 2", "Wave 3", "Wave 4", + "Wave 5", "Wave 6", "Wave 7", "Wave 8" + }; + set_voice_count( count ); + set_voice_names( names ); + } + } + + if ( header_.chip_flags & fme7_flag ) + { + fme7 = BLARGG_NEW Nes_Fme7_Apu; + CHECK_ALLOC( fme7 ); + adjusted_gain *= 0.75; + + int const count = Nes_Apu::osc_count + Nes_Fme7_Apu::osc_count; + static const char* const names [count] = { + APU_NAMES, + "Square 3", "Square 4", "Square 5" + }; + set_voice_count( count ); + set_voice_names( names ); + } + + if ( namco ) namco->volume( adjusted_gain ); + if ( vrc6 ) vrc6 ->volume( adjusted_gain ); + if ( fme7 ) fme7 ->volume( adjusted_gain ); + } + #endif + + apu.volume( adjusted_gain ); + + return 0; +} + +blargg_err_t Nsf_Emu::load_( Data_Reader& in ) +{ + assert( offsetof (header_t,unused [4]) == header_size ); + RETURN_ERR( rom.load( in, header_size, &header_, 0 ) ); + + set_track_count( header_.track_count ); + RETURN_ERR( check_nsf_header( &header_ ) ); + + if ( header_.vers != 1 ) + set_warning( "Unknown file version" ); + + // sound and memory + blargg_err_t err = init_sound(); + if ( err ) + return err; + + // set up data + nes_addr_t load_addr = get_le16( header_.load_addr ); + init_addr = get_le16( header_.init_addr ); + play_addr = get_le16( header_.play_addr ); + if ( !load_addr ) load_addr = rom_begin; + if ( !init_addr ) init_addr = rom_begin; + if ( !play_addr ) play_addr = rom_begin; + if ( load_addr < rom_begin || init_addr < rom_begin ) + { + const char* w = warning(); + if ( !w ) + w = "Corrupt file (invalid load/init/play address)"; + return w; + } + + rom.set_addr( load_addr % bank_size ); + int total_banks = rom.size() / bank_size; + + // bank switching + int first_bank = (load_addr - rom_begin) / bank_size; + for ( int i = 0; i < bank_count; i++ ) + { + unsigned bank = i - first_bank; + if ( bank >= (unsigned) total_banks ) + bank = 0; + initial_banks [i] = bank; + + if ( header_.banks [i] ) + { + // bank-switched + memcpy( initial_banks, header_.banks, sizeof initial_banks ); + break; + } + } + + pal_only = (header_.speed_flags & 3) == 1; + + #if !NSF_EMU_EXTRA_FLAGS + header_.speed_flags = 0; + #endif + + set_tempo( tempo() ); + + return setup_buffer( (long) (clock_rate_ + 0.5) ); +} + +void Nsf_Emu::update_eq( blip_eq_t const& eq ) +{ + apu.treble_eq( eq ); + + #if !NSF_EMU_APU_ONLY + { + if ( namco ) namco->treble_eq( eq ); + if ( vrc6 ) vrc6 ->treble_eq( eq ); + if ( fme7 ) fme7 ->treble_eq( eq ); + } + #endif +} + +void Nsf_Emu::set_voice( int i, Blip_Buffer* buf, Blip_Buffer*, Blip_Buffer* ) +{ + if ( i < Nes_Apu::osc_count ) + { + apu.osc_output( i, buf ); + return; + } + i -= Nes_Apu::osc_count; + + #if !NSF_EMU_APU_ONLY + { + if ( fme7 && i < Nes_Fme7_Apu::osc_count ) + { + fme7->osc_output( i, buf ); + return; + } + + if ( vrc6 ) + { + if ( i < Nes_Vrc6_Apu::osc_count ) + { + // put saw first + if ( --i < 0 ) + i = 2; + vrc6->osc_output( i, buf ); + return; + } + i -= Nes_Vrc6_Apu::osc_count; + } + + if ( namco && i < Nes_Namco_Apu::osc_count ) + { + namco->osc_output( i, buf ); + return; + } + } + #endif +} + +// Emulation + +// see nes_cpu_io.h for read/write functions + +void Nsf_Emu::cpu_write_misc( nes_addr_t addr, int data ) +{ + #if !NSF_EMU_APU_ONLY + { + if ( namco ) + { + switch ( addr ) + { + case Nes_Namco_Apu::data_reg_addr: + namco->write_data( time(), data ); + return; + + case Nes_Namco_Apu::addr_reg_addr: + namco->write_addr( data ); + return; + } + } + + if ( addr >= Nes_Fme7_Apu::latch_addr && fme7 ) + { + switch ( addr & Nes_Fme7_Apu::addr_mask ) + { + case Nes_Fme7_Apu::latch_addr: + fme7->write_latch( data ); + return; + + case Nes_Fme7_Apu::data_addr: + fme7->write_data( time(), data ); + return; + } + } + + if ( vrc6 ) + { + unsigned reg = addr & (Nes_Vrc6_Apu::addr_step - 1); + unsigned osc = unsigned (addr - Nes_Vrc6_Apu::base_addr) / Nes_Vrc6_Apu::addr_step; + if ( osc < Nes_Vrc6_Apu::osc_count && reg < Nes_Vrc6_Apu::reg_count ) + { + vrc6->write_osc( time(), osc, reg, data ); + return; + } + } + } + #endif + + // unmapped write + + #ifndef NDEBUG + { + // some games write to $8000 and $8001 repeatedly + if ( addr == 0x8000 || addr == 0x8001 ) return; + + // probably namco sound mistakenly turned on in mck + if ( addr == 0x4800 || addr == 0xF800 ) return; + + // memory mapper? + if ( addr == 0xFFF8 ) return; + + debug_printf( "write_unmapped( 0x%04X, 0x%02X )\n", (unsigned) addr, (unsigned) data ); + } + #endif +} + +blargg_err_t Nsf_Emu::start_track_( int track ) +{ + RETURN_ERR( Classic_Emu::start_track_( track ) ); + + memset( low_mem, 0, sizeof low_mem ); + memset( sram, 0, sizeof sram ); + + cpu::reset( unmapped_code ); // also maps low_mem + cpu::map_code( sram_addr, sizeof sram, sram ); + for ( int i = 0; i < bank_count; ++i ) + cpu_write( bank_select_addr + i, initial_banks [i] ); + + apu.reset( pal_only, (header_.speed_flags & 0x20) ? 0x3F : 0 ); + apu.write_register( 0, 0x4015, 0x0F ); + apu.write_register( 0, 0x4017, (header_.speed_flags & 0x10) ? 0x80 : 0 ); + #if !NSF_EMU_APU_ONLY + { + if ( namco ) namco->reset(); + if ( vrc6 ) vrc6 ->reset(); + if ( fme7 ) fme7 ->reset(); + } + #endif + + play_ready = 4; + play_extra = 0; + next_play = play_period / clock_divisor; + + saved_state.pc = badop_addr; + low_mem [0x1FF] = (badop_addr - 1) >> 8; + low_mem [0x1FE] = (badop_addr - 1) & 0xFF; + r.sp = 0xFD; + r.pc = init_addr; + r.a = track; + r.x = pal_only; + + return 0; +} + +blargg_err_t Nsf_Emu::run_clocks( blip_time_t& duration, int ) +{ + set_time( 0 ); + while ( time() < duration ) + { + nes_time_t end = min( (blip_time_t) next_play, duration ); + end = min( end, time() + 32767 ); // allows CPU to use 16-bit time delta + if ( cpu::run( end ) ) + { + if ( r.pc != badop_addr ) + { + set_warning( "Emulation error (illegal instruction)" ); + r.pc++; + } + else + { + play_ready = 1; + if ( saved_state.pc != badop_addr ) + { + cpu::r = saved_state; + saved_state.pc = badop_addr; + } + else + { + set_time( end ); + } + } + } + + if ( time() >= next_play ) + { + nes_time_t period = (play_period + play_extra) / clock_divisor; + play_extra = play_period - period * clock_divisor; + next_play += period; + if ( play_ready && !--play_ready ) + { + check( saved_state.pc == badop_addr ); + if ( r.pc != badop_addr ) + saved_state = cpu::r; + + r.pc = play_addr; + low_mem [0x100 + r.sp--] = (badop_addr - 1) >> 8; + low_mem [0x100 + r.sp--] = (badop_addr - 1) & 0xFF; + GME_FRAME_HOOK( this ); + } + } + } + + if ( cpu::error_count() ) + { + cpu::clear_error_count(); + set_warning( "Emulation error (illegal instruction)" ); + } + + duration = time(); + next_play -= duration; + check( next_play >= 0 ); + if ( next_play < 0 ) + next_play = 0; + + apu.end_frame( duration ); + + #if !NSF_EMU_APU_ONLY + { + if ( namco ) namco->end_frame( duration ); + if ( vrc6 ) vrc6 ->end_frame( duration ); + if ( fme7 ) fme7 ->end_frame( duration ); + } + #endif + + return 0; +} diff --git a/libs/gme/gme/Nsf_Emu.h b/libs/gme/gme/Nsf_Emu.h new file mode 100644 index 000000000..0b001686c --- /dev/null +++ b/libs/gme/gme/Nsf_Emu.h @@ -0,0 +1,106 @@ +// Nintendo NES/Famicom NSF music file emulator + +// Game_Music_Emu 0.6.0 +#ifndef NSF_EMU_H +#define NSF_EMU_H + +#include "Classic_Emu.h" +#include "Nes_Apu.h" +#include "Nes_Cpu.h" + +class Nsf_Emu : private Nes_Cpu, public Classic_Emu { + typedef Nes_Cpu cpu; +public: + // Equalizer profiles for US NES and Japanese Famicom + static equalizer_t const nes_eq; + static equalizer_t const famicom_eq; + + // NSF file header + enum { header_size = 0x80 }; + struct header_t + { + char tag [5]; + byte vers; + byte track_count; + byte first_track; + byte load_addr [2]; + byte init_addr [2]; + byte play_addr [2]; + char game [32]; + char author [32]; + char copyright [32]; + byte ntsc_speed [2]; + byte banks [8]; + byte pal_speed [2]; + byte speed_flags; + byte chip_flags; + byte unused [4]; + }; + + // Header for currently loaded file + header_t const& header() const { return header_; } + + static gme_type_t static_type() { return gme_nsf_type; } + +public: + // deprecated + using Music_Emu::load; + blargg_err_t load( header_t const& h, Data_Reader& in ) // use Remaining_Reader + { return load_remaining_( &h, sizeof h, in ); } + +public: + Nsf_Emu(); + ~Nsf_Emu(); + Nes_Apu* apu_() { return &apu; } +protected: + blargg_err_t track_info_( track_info_t*, int track ) const; + blargg_err_t load_( Data_Reader& ); + blargg_err_t start_track_( int ); + blargg_err_t run_clocks( blip_time_t&, int ); + void set_tempo_( double ); + void set_voice( int, Blip_Buffer*, Blip_Buffer*, Blip_Buffer* ); + void update_eq( blip_eq_t const& ); + void unload(); +protected: + enum { bank_count = 8 }; + byte initial_banks [bank_count]; + nes_addr_t init_addr; + nes_addr_t play_addr; + double clock_rate_; + bool pal_only; + + // timing + Nes_Cpu::registers_t saved_state; + nes_time_t next_play; + nes_time_t play_period; + int play_extra; + int play_ready; + + enum { rom_begin = 0x8000 }; + enum { bank_select_addr = 0x5FF8 }; + enum { bank_size = 0x1000 }; + Rom_Data rom; + +public: private: friend class Nes_Cpu; + void cpu_jsr( nes_addr_t ); + int cpu_read( nes_addr_t ); + void cpu_write( nes_addr_t, int ); + void cpu_write_misc( nes_addr_t, int ); + enum { badop_addr = bank_select_addr }; + +private: + class Nes_Namco_Apu* namco; + class Nes_Vrc6_Apu* vrc6; + class Nes_Fme7_Apu* fme7; + Nes_Apu apu; + static int pcm_read( void*, nes_addr_t ); + blargg_err_t init_sound(); + + header_t header_; + + enum { sram_addr = 0x6000 }; + byte sram [0x2000]; + byte unmapped_code [Nes_Cpu::page_size + 8]; +}; + +#endif diff --git a/libs/gme/gme/Nsfe_Emu.cpp b/libs/gme/gme/Nsfe_Emu.cpp new file mode 100644 index 000000000..824a1a240 --- /dev/null +++ b/libs/gme/gme/Nsfe_Emu.cpp @@ -0,0 +1,332 @@ +// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/ + +#include "Nsfe_Emu.h" + +#include "blargg_endian.h" +#include +#include + +/* Copyright (C) 2005-2006 Shay Green. This module 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 +module 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 module; if not, write to the Free Software Foundation, +Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + +#include "blargg_source.h" + +Nsfe_Info::Nsfe_Info() { playlist_disabled = false; } + +Nsfe_Info::~Nsfe_Info() { } + +inline void Nsfe_Info::unload() +{ + track_name_data.clear(); + track_names.clear(); + playlist.clear(); + track_times.clear(); +} + +// TODO: if no playlist, treat as if there is a playlist that is just 1,2,3,4,5... ? +void Nsfe_Info::disable_playlist( bool b ) +{ + playlist_disabled = b; + info.track_count = playlist.size(); + if ( !info.track_count || playlist_disabled ) + info.track_count = actual_track_count_; +} + +int Nsfe_Info::remap_track( int track ) const +{ + if ( !playlist_disabled && (unsigned) track < playlist.size() ) + track = playlist [track]; + return track; +} + +// Read multiple strings and separate into individual strings +static blargg_err_t read_strs( Data_Reader& in, long size, blargg_vector& chars, + blargg_vector& strs ) +{ + RETURN_ERR( chars.resize( size + 1 ) ); + chars [size] = 0; // in case last string doesn't have terminator + RETURN_ERR( in.read( &chars [0], size ) ); + + RETURN_ERR( strs.resize( 128 ) ); + int count = 0; + for ( int i = 0; i < size; i++ ) + { + if ( (int) strs.size() <= count ) + RETURN_ERR( strs.resize( count * 2 ) ); + strs [count++] = &chars [i]; + while ( i < size && chars [i] ) + i++; + } + + return strs.resize( count ); +} + +// Copy in to out, where out has out_max characters allocated. Truncate to +// out_max - 1 characters. +static void copy_str( const char* in, char* out, int out_max ) +{ + out [out_max - 1] = 0; + strncpy( out, in, out_max - 1 ); +} + +struct nsfe_info_t +{ + byte load_addr [2]; + byte init_addr [2]; + byte play_addr [2]; + byte speed_flags; + byte chip_flags; + byte track_count; + byte first_track; + byte unused [6]; +}; + +blargg_err_t Nsfe_Info::load( Data_Reader& in, Nsf_Emu* nsf_emu ) +{ + int const nsfe_info_size = 16; + assert( offsetof (nsfe_info_t,unused [6]) == nsfe_info_size ); + + // check header + byte signature [4]; + blargg_err_t err = in.read( signature, sizeof signature ); + if ( err ) + return (err == in.eof_error ? gme_wrong_file_type : err); + if ( memcmp( signature, "NSFE", 4 ) ) + return gme_wrong_file_type; + + // free previous info + track_name_data.clear(); + track_names.clear(); + playlist.clear(); + track_times.clear(); + + // default nsf header + static const Nsf_Emu::header_t base_header = + { + {'N','E','S','M','\x1A'},// tag + 1, // version + 1, 1, // track count, first track + {0,0},{0,0},{0,0}, // addresses + "","","", // strings + {0x1A, 0x41}, // NTSC rate + {0,0,0,0,0,0,0,0}, // banks + {0x20, 0x4E}, // PAL rate + 0, 0, // flags + {0,0,0,0} // unused + }; + Nsf_Emu::header_t& header = info; + header = base_header; + + // parse tags + int phase = 0; + while ( phase != 3 ) + { + // read size and tag + byte block_header [2] [4]; + RETURN_ERR( in.read( block_header, sizeof block_header ) ); + blargg_long size = get_le32( block_header [0] ); + blargg_long tag = get_le32( block_header [1] ); + + //debug_printf( "tag: %c%c%c%c\n", char(tag), char(tag>>8), char(tag>>16), char(tag>>24) ); + + switch ( tag ) + { + case BLARGG_4CHAR('O','F','N','I'): { + check( phase == 0 ); + if ( size < 8 ) + return "Corrupt file"; + + nsfe_info_t finfo; + finfo.track_count = 1; + finfo.first_track = 0; + + RETURN_ERR( in.read( &finfo, min( size, (blargg_long) nsfe_info_size ) ) ); + if ( size > nsfe_info_size ) + RETURN_ERR( in.skip( size - nsfe_info_size ) ); + phase = 1; + info.speed_flags = finfo.speed_flags; + info.chip_flags = finfo.chip_flags; + info.track_count = finfo.track_count; + this->actual_track_count_ = finfo.track_count; + info.first_track = finfo.first_track; + memcpy( info.load_addr, finfo.load_addr, 2 * 3 ); + break; + } + + case BLARGG_4CHAR('K','N','A','B'): + if ( size > (int) sizeof info.banks ) + return "Corrupt file"; + RETURN_ERR( in.read( info.banks, size ) ); + break; + + case BLARGG_4CHAR('h','t','u','a'): { + blargg_vector chars; + blargg_vector strs; + RETURN_ERR( read_strs( in, size, chars, strs ) ); + int n = strs.size(); + + if ( n > 3 ) + copy_str( strs [3], info.dumper, sizeof info.dumper ); + + if ( n > 2 ) + copy_str( strs [2], info.copyright, sizeof info.copyright ); + + if ( n > 1 ) + copy_str( strs [1], info.author, sizeof info.author ); + + if ( n > 0 ) + copy_str( strs [0], info.game, sizeof info.game ); + + break; + } + + case BLARGG_4CHAR('e','m','i','t'): + RETURN_ERR( track_times.resize( size / 4 ) ); + RETURN_ERR( in.read( track_times.begin(), track_times.size() * 4 ) ); + break; + + case BLARGG_4CHAR('l','b','l','t'): + RETURN_ERR( read_strs( in, size, track_name_data, track_names ) ); + break; + + case BLARGG_4CHAR('t','s','l','p'): + RETURN_ERR( playlist.resize( size ) ); + RETURN_ERR( in.read( &playlist [0], size ) ); + break; + + case BLARGG_4CHAR('A','T','A','D'): { + check( phase == 1 ); + phase = 2; + if ( !nsf_emu ) + { + RETURN_ERR( in.skip( size ) ); + } + else + { + Subset_Reader sub( &in, size ); // limit emu to nsf data + Remaining_Reader rem( &header, Nsf_Emu::header_size, &sub ); + RETURN_ERR( nsf_emu->load( rem ) ); + check( rem.remain() == 0 ); + } + break; + } + + case BLARGG_4CHAR('D','N','E','N'): + check( phase == 2 ); + phase = 3; + break; + + default: + // tags that can be skipped start with a lowercase character + check( islower( (tag >> 24) & 0xFF ) ); + RETURN_ERR( in.skip( size ) ); + break; + } + } + + return 0; +} + +blargg_err_t Nsfe_Info::track_info_( track_info_t* out, int track ) const +{ + int remapped = remap_track( track ); + if ( (unsigned) remapped < track_times.size() ) + { + long length = (BOOST::int32_t) get_le32( track_times [remapped] ); + if ( length > 0 ) + out->length = length; + } + if ( (unsigned) remapped < track_names.size() ) + Gme_File::copy_field_( out->song, track_names [remapped] ); + + GME_COPY_FIELD( info, out, game ); + GME_COPY_FIELD( info, out, author ); + GME_COPY_FIELD( info, out, copyright ); + GME_COPY_FIELD( info, out, dumper ); + return 0; +} + +Nsfe_Emu::Nsfe_Emu() +{ + loading = false; + set_type( gme_nsfe_type ); +} + +Nsfe_Emu::~Nsfe_Emu() { } + +void Nsfe_Emu::unload() +{ + if ( !loading ) + info.unload(); // TODO: extremely hacky! + Nsf_Emu::unload(); +} + +blargg_err_t Nsfe_Emu::track_info_( track_info_t* out, int track ) const +{ + return info.track_info_( out, track ); +} + +struct Nsfe_File : Gme_Info_ +{ + Nsfe_Info info; + + Nsfe_File() { set_type( gme_nsfe_type ); } + + blargg_err_t load_( Data_Reader& in ) + { + RETURN_ERR( info.load( in, 0 ) ); + info.disable_playlist( false ); + set_track_count( info.info.track_count ); + return 0; + } + + blargg_err_t track_info_( track_info_t* out, int track ) const + { + return info.track_info_( out, track ); + } +}; + +static Music_Emu* new_nsfe_emu () { return BLARGG_NEW Nsfe_Emu ; } +static Music_Emu* new_nsfe_file() { return BLARGG_NEW Nsfe_File; } + +static gme_type_t_ const gme_nsfe_type_ = { "Nintendo NES", 0, &new_nsfe_emu, &new_nsfe_file, "NSFE", 1 }; +gme_type_t const gme_nsfe_type = &gme_nsfe_type_; + + +blargg_err_t Nsfe_Emu::load_( Data_Reader& in ) +{ + if ( loading ) + return Nsf_Emu::load_( in ); + + // TODO: this hacky recursion-avoidance could have subtle problems + loading = true; + blargg_err_t err = info.load( in, this ); + loading = false; + disable_playlist( false ); + return err; +} + +void Nsfe_Emu::disable_playlist( bool b ) +{ + info.disable_playlist( b ); + set_track_count( info.info.track_count ); +} + +void Nsfe_Emu::clear_playlist_() +{ + disable_playlist(); + Nsf_Emu::clear_playlist_(); +} + +blargg_err_t Nsfe_Emu::start_track_( int track ) +{ + return Nsf_Emu::start_track_( info.remap_track( track ) ); +} diff --git a/libs/gme/gme/Nsfe_Emu.h b/libs/gme/gme/Nsfe_Emu.h new file mode 100644 index 000000000..32b05d55e --- /dev/null +++ b/libs/gme/gme/Nsfe_Emu.h @@ -0,0 +1,68 @@ +// Nintendo NES/Famicom NSFE music file emulator + +// Game_Music_Emu 0.6.0 +#ifndef NSFE_EMU_H +#define NSFE_EMU_H + +#include "blargg_common.h" +#include "Nsf_Emu.h" + +// Allows reading info from NSFE file without creating emulator +class Nsfe_Info { +public: + blargg_err_t load( Data_Reader&, Nsf_Emu* ); + + struct info_t : Nsf_Emu::header_t + { + char game [256]; + char author [256]; + char copyright [256]; + char dumper [256]; + } info; + + void disable_playlist( bool = true ); + + blargg_err_t track_info_( track_info_t* out, int track ) const; + + int remap_track( int i ) const; + + void unload(); + + Nsfe_Info(); + ~Nsfe_Info(); +private: + blargg_vector track_name_data; + blargg_vector track_names; + blargg_vector playlist; + blargg_vector track_times; + int actual_track_count_; + bool playlist_disabled; +}; + +class Nsfe_Emu : public Nsf_Emu { +public: + static gme_type_t static_type() { return gme_nsfe_type; } + +public: + // deprecated + struct header_t { char tag [4]; }; + using Music_Emu::load; + blargg_err_t load( header_t const& h, Data_Reader& in ) // use Remaining_Reader + { return load_remaining_( &h, sizeof h, in ); } + void disable_playlist( bool = true ); // use clear_playlist() + +public: + Nsfe_Emu(); + ~Nsfe_Emu(); +protected: + blargg_err_t load_( Data_Reader& ); + blargg_err_t track_info_( track_info_t*, int track ) const; + blargg_err_t start_track_( int ); + void unload(); + void clear_playlist_(); +private: + Nsfe_Info info; + bool loading; +}; + +#endif diff --git a/libs/gme/gme/Sap_Apu.cpp b/libs/gme/gme/Sap_Apu.cpp new file mode 100644 index 000000000..ecac3dafd --- /dev/null +++ b/libs/gme/gme/Sap_Apu.cpp @@ -0,0 +1,334 @@ +// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/ + +#include "Sap_Apu.h" + +#include + +/* Copyright (C) 2006 Shay Green. This module 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 +module 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 module; if not, write to the Free Software Foundation, +Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + +#include "blargg_source.h" + +int const max_frequency = 12000; // pure waves above this frequency are silenced + +static void gen_poly( blargg_ulong mask, int count, byte* out ) +{ + blargg_ulong n = 1; + do + { + int bits = 0; + int b = 0; + do + { + // implemented using "Galios configuration" + bits |= (n & 1) << b; + n = (n >> 1) ^ (mask & -(n & 1)); + } + while ( b++ < 7 ); + *out++ = bits; + } + while ( --count ); +} + +// poly5 +int const poly5_len = (1 << 5) - 1; +blargg_ulong const poly5_mask = (1UL << poly5_len) - 1; +blargg_ulong const poly5 = 0x167C6EA1; + +inline blargg_ulong run_poly5( blargg_ulong in, int shift ) +{ + return (in << shift & poly5_mask) | (in >> (poly5_len - shift)); +} + +#define POLY_MASK( width, tap1, tap2 ) \ + ((1UL << (width - 1 - tap1)) | (1UL << (width - 1 - tap2))) + +Sap_Apu_Impl::Sap_Apu_Impl() +{ + gen_poly( POLY_MASK( 4, 1, 0 ), sizeof poly4, poly4 ); + gen_poly( POLY_MASK( 9, 5, 0 ), sizeof poly9, poly9 ); + gen_poly( POLY_MASK( 17, 5, 0 ), sizeof poly17, poly17 ); + + if ( 0 ) // comment out to recauculate poly5 constant + { + byte poly5 [4]; + gen_poly( POLY_MASK( 5, 2, 0 ), sizeof poly5, poly5 ); + blargg_ulong n = poly5 [3] * 0x1000000L + poly5 [2] * 0x10000L + + poly5 [1] * 0x100L + poly5 [0]; + blargg_ulong rev = n & 1; + for ( int i = 1; i < poly5_len; i++ ) + rev |= (n >> i & 1) << (poly5_len - i); + debug_printf( "poly5: 0x%08lX\n", rev ); + } +} + +Sap_Apu::Sap_Apu() +{ + impl = 0; + for ( int i = 0; i < osc_count; i++ ) + osc_output( i, 0 ); +} + +void Sap_Apu::reset( Sap_Apu_Impl* new_impl ) +{ + impl = new_impl; + last_time = 0; + poly5_pos = 0; + poly4_pos = 0; + polym_pos = 0; + control = 0; + + for ( int i = 0; i < osc_count; i++ ) + memset( &oscs [i], 0, offsetof (osc_t,output) ); +} + +inline void Sap_Apu::calc_periods() +{ + // 15/64 kHz clock + int divider = 28; + if ( this->control & 1 ) + divider = 114; + + for ( int i = 0; i < osc_count; i++ ) + { + osc_t* const osc = &oscs [i]; + + int const osc_reload = osc->regs [0]; // cache + blargg_long period = (osc_reload + 1) * divider; + static byte const fast_bits [osc_count] = { 1 << 6, 1 << 4, 1 << 5, 1 << 3 }; + if ( this->control & fast_bits [i] ) + { + period = osc_reload + 4; + if ( i & 1 ) + { + period = osc_reload * 0x100L + osc [-1].regs [0] + 7; + if ( !(this->control & fast_bits [i - 1]) ) + period = (period - 6) * divider; + + if ( (osc [-1].regs [1] & 0x1F) > 0x10 ) + debug_printf( "Use of slave channel in 16-bit mode not supported\n" ); + } + } + osc->period = period; + } +} + +void Sap_Apu::run_until( blip_time_t end_time ) +{ + calc_periods(); + Sap_Apu_Impl* const impl = this->impl; // cache + + // 17/9-bit poly selection + byte const* polym = impl->poly17; + int polym_len = poly17_len; + if ( this->control & 0x80 ) + { + polym_len = poly9_len; + polym = impl->poly9; + } + polym_pos %= polym_len; + + for ( int i = 0; i < osc_count; i++ ) + { + osc_t* const osc = &oscs [i]; + blip_time_t time = last_time + osc->delay; + blip_time_t const period = osc->period; + + // output + Blip_Buffer* output = osc->output; + if ( output ) + { + output->set_modified(); + + int const osc_control = osc->regs [1]; // cache + int volume = (osc_control & 0x0F) * 2; + if ( !volume || osc_control & 0x10 || // silent, DAC mode, or inaudible frequency + ((osc_control & 0xA0) == 0xA0 && period < 1789773 / 2 / max_frequency) ) + { + if ( !(osc_control & 0x10) ) + volume >>= 1; // inaudible frequency = half volume + + int delta = volume - osc->last_amp; + if ( delta ) + { + osc->last_amp = volume; + impl->synth.offset( last_time, delta, output ); + } + + // TODO: doesn't maintain high pass flip-flop (very minor issue) + } + else + { + // high pass + static byte const hipass_bits [osc_count] = { 1 << 2, 1 << 1, 0, 0 }; + blip_time_t period2 = 0; // unused if no high pass + blip_time_t time2 = end_time; + if ( this->control & hipass_bits [i] ) + { + period2 = osc [2].period; + time2 = last_time + osc [2].delay; + if ( osc->invert ) + { + // trick inner wave loop into inverting output + osc->last_amp -= volume; + volume = -volume; + } + } + + if ( time < end_time || time2 < end_time ) + { + // poly source + static byte const poly1 [] = { 0x55, 0x55 }; // square wave + byte const* poly = poly1; + int poly_len = 8 * sizeof poly1; // can be just 2 bits, but this is faster + int poly_pos = osc->phase & 1; + int poly_inc = 1; + if ( !(osc_control & 0x20) ) + { + poly = polym; + poly_len = polym_len; + poly_pos = polym_pos; + if ( osc_control & 0x40 ) + { + poly = impl->poly4; + poly_len = poly4_len; + poly_pos = poly4_pos; + } + poly_inc = period % poly_len; + poly_pos = (poly_pos + osc->delay) % poly_len; + } + poly_inc -= poly_len; // allows more optimized inner loop below + + // square/poly5 wave + blargg_ulong wave = poly5; + check( poly5 & 1 ); // low bit is set for pure wave + int poly5_inc = 0; + if ( !(osc_control & 0x80) ) + { + wave = run_poly5( wave, (osc->delay + poly5_pos) % poly5_len ); + poly5_inc = period % poly5_len; + } + + // Run wave and high pass interleved with each catching up to the other. + // Disabled high pass has no performance effect since inner wave loop + // makes no compromise for high pass, and only runs once in that case. + int osc_last_amp = osc->last_amp; + do + { + // run high pass + if ( time2 < time ) + { + int delta = -osc_last_amp; + if ( volume < 0 ) + delta += volume; + if ( delta ) + { + osc_last_amp += delta - volume; + volume = -volume; + impl->synth.offset( time2, delta, output ); + } + } + while ( time2 <= time ) // must advance *past* time to avoid hang + time2 += period2; + + // run wave + blip_time_t end = end_time; + if ( end > time2 ) + end = time2; + while ( time < end ) + { + if ( wave & 1 ) + { + int amp = volume & -(poly [poly_pos >> 3] >> (poly_pos & 7) & 1); + if ( (poly_pos += poly_inc) < 0 ) + poly_pos += poly_len; + int delta = amp - osc_last_amp; + if ( delta ) + { + osc_last_amp = amp; + impl->synth.offset( time, delta, output ); + } + } + wave = run_poly5( wave, poly5_inc ); + time += period; + } + } + while ( time < end_time || time2 < end_time ); + + osc->phase = poly_pos; + osc->last_amp = osc_last_amp; + } + + osc->invert = 0; + if ( volume < 0 ) + { + // undo inversion trickery + osc->last_amp -= volume; + osc->invert = 1; + } + } + } + + // maintain divider + blip_time_t remain = end_time - time; + if ( remain > 0 ) + { + blargg_long count = (remain + period - 1) / period; + osc->phase ^= count; + time += count * period; + } + osc->delay = time - end_time; + } + + // advance polies + blip_time_t duration = end_time - last_time; + last_time = end_time; + poly4_pos = (poly4_pos + duration) % poly4_len; + poly5_pos = (poly5_pos + duration) % poly5_len; + polym_pos += duration; // will get %'d on next call +} + +void Sap_Apu::write_data( blip_time_t time, unsigned addr, int data ) +{ + run_until( time ); + int i = (addr ^ 0xD200) >> 1; + if ( i < osc_count ) + { + oscs [i].regs [addr & 1] = data; + } + else if ( addr == 0xD208 ) + { + control = data; + } + else if ( addr == 0xD209 ) + { + oscs [0].delay = 0; + oscs [1].delay = 0; + oscs [2].delay = 0; + oscs [3].delay = 0; + } + /* + // TODO: are polynomials reset in this case? + else if ( addr == 0xD20F ) + { + if ( (data & 3) == 0 ) + polym_pos = 0; + } + */ +} + +void Sap_Apu::end_frame( blip_time_t end_time ) +{ + if ( end_time > last_time ) + run_until( end_time ); + + last_time -= end_time; +} diff --git a/libs/gme/gme/Sap_Apu.h b/libs/gme/gme/Sap_Apu.h new file mode 100644 index 000000000..8cdd7e50c --- /dev/null +++ b/libs/gme/gme/Sap_Apu.h @@ -0,0 +1,77 @@ +// Atari POKEY sound chip emulator + +// Game_Music_Emu 0.6.0 +#ifndef SAP_APU_H +#define SAP_APU_H + +#include "blargg_common.h" +#include "Blip_Buffer.h" + +class Sap_Apu_Impl; + +class Sap_Apu { +public: + enum { osc_count = 4 }; + void osc_output( int index, Blip_Buffer* ); + + void reset( Sap_Apu_Impl* ); + + enum { start_addr = 0xD200 }; + enum { end_addr = 0xD209 }; + void write_data( blip_time_t, unsigned addr, int data ); + + void end_frame( blip_time_t ); + +public: + Sap_Apu(); +private: + struct osc_t + { + unsigned char regs [2]; + unsigned char phase; + unsigned char invert; + int last_amp; + blip_time_t delay; + blip_time_t period; // always recalculated before use; here for convenience + Blip_Buffer* output; + }; + osc_t oscs [osc_count]; + Sap_Apu_Impl* impl; + blip_time_t last_time; + int poly5_pos; + int poly4_pos; + int polym_pos; + int control; + + void calc_periods(); + void run_until( blip_time_t ); + + enum { poly4_len = (1L << 4) - 1 }; + enum { poly9_len = (1L << 9) - 1 }; + enum { poly17_len = (1L << 17) - 1 }; + friend class Sap_Apu_Impl; +}; + +// Common tables and Blip_Synth that can be shared among multiple Sap_Apu objects +class Sap_Apu_Impl { +public: + Blip_Synth synth; + + Sap_Apu_Impl(); + void volume( double d ) { synth.volume( 1.0 / Sap_Apu::osc_count / 30 * d ); } + +private: + typedef unsigned char byte; + byte poly4 [Sap_Apu::poly4_len / 8 + 1]; + byte poly9 [Sap_Apu::poly9_len / 8 + 1]; + byte poly17 [Sap_Apu::poly17_len / 8 + 1]; + friend class Sap_Apu; +}; + +inline void Sap_Apu::osc_output( int i, Blip_Buffer* b ) +{ + assert( (unsigned) i < osc_count ); + oscs [i].output = b; +} + +#endif diff --git a/libs/gme/gme/Sap_Cpu.cpp b/libs/gme/gme/Sap_Cpu.cpp new file mode 100644 index 000000000..fd9112769 --- /dev/null +++ b/libs/gme/gme/Sap_Cpu.cpp @@ -0,0 +1,1011 @@ +// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/ + +#include "Sap_Cpu.h" + +#include +#include "blargg_endian.h" + +//#include "nes_cpu_log.h" + +/* Copyright (C) 2003-2006 Shay Green. This module 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 +module 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 module; if not, write to the Free Software Foundation, +Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + +#define FLUSH_TIME() (void) (s.time = s_time) +#define CACHE_TIME() (void) (s_time = s.time) + +#include "sap_cpu_io.h" + +#ifndef CPU_DONE + #define CPU_DONE( cpu, time, result_out ) { result_out = -1; } +#endif + +#include "blargg_source.h" + +int const st_n = 0x80; +int const st_v = 0x40; +int const st_r = 0x20; +int const st_b = 0x10; +int const st_d = 0x08; +int const st_i = 0x04; +int const st_z = 0x02; +int const st_c = 0x01; + +void Sap_Cpu::reset( void* new_mem ) +{ + check( state == &state_ ); + state = &state_; + mem = (uint8_t*) new_mem; + r.status = st_i; + r.sp = 0xFF; + r.pc = 0; + r.a = 0; + r.x = 0; + r.y = 0; + state_.time = 0; + state_.base = 0; + irq_time_ = future_sap_time; + end_time_ = future_sap_time; + + blargg_verify_byte_order(); +} + +#define TIME (s_time + s.base) +#define READ( addr ) CPU_READ( this, (addr), TIME ) +#define WRITE( addr, data ) {CPU_WRITE( this, (addr), (data), TIME );} +#define READ_LOW( addr ) (mem [int (addr)]) +#define WRITE_LOW( addr, data ) (void) (READ_LOW( addr ) = (data)) +#define READ_PROG( addr ) (READ_LOW( addr )) + +#define SET_SP( v ) (sp = ((v) + 1) | 0x100) +#define GET_SP() ((sp - 1) & 0xFF) +#define PUSH( v ) ((sp = (sp - 1) | 0x100), WRITE_LOW( sp, v )) + +// even on x86, using short and unsigned char was slower +typedef int fint16; +typedef unsigned fuint16; +typedef unsigned fuint8; +typedef blargg_long fint32; + +bool Sap_Cpu::run( sap_time_t end_time ) +{ + bool illegal_encountered = false; + set_end_time( end_time ); + state_t s = this->state_; + this->state = &s; + fint32 s_time = s.time; + uint8_t* const mem = this->mem; // cache + + // registers + fuint16 pc = r.pc; + fuint8 a = r.a; + fuint8 x = r.x; + fuint8 y = r.y; + fuint16 sp; + SET_SP( r.sp ); + + // status flags + #define IS_NEG (nz & 0x8080) + + #define CALC_STATUS( out ) do {\ + out = status & (st_v | st_d | st_i);\ + out |= ((nz >> 8) | nz) & st_n;\ + out |= c >> 8 & st_c;\ + if ( !(nz & 0xFF) ) out |= st_z;\ + } while ( 0 ) + + #define SET_STATUS( in ) do {\ + status = in & (st_v | st_d | st_i);\ + nz = in << 8;\ + c = nz;\ + nz |= ~in & st_z;\ + } while ( 0 ) + + fuint8 status; + fuint16 c; // carry set if (c & 0x100) != 0 + fuint16 nz; // Z set if (nz & 0xFF) == 0, N set if (nz & 0x8080) != 0 + { + fuint8 temp = r.status; + SET_STATUS( temp ); + } + + goto loop; +dec_clock_loop: + s_time--; +loop: + + #ifndef NDEBUG + { + sap_time_t correct = end_time_; + if ( !(status & st_i) && correct > irq_time_ ) + correct = irq_time_; + check( s.base == correct ); + } + #endif + + check( (unsigned) GET_SP() < 0x100 ); + check( (unsigned) a < 0x100 ); + check( (unsigned) x < 0x100 ); + check( (unsigned) y < 0x100 ); + + fuint8 opcode = mem [pc]; + pc++; + uint8_t const* instr = mem + pc; + + static uint8_t const clock_table [256] = + {// 0 1 2 3 4 5 6 7 8 9 A B C D E F + 0,6,2,8,3,3,5,5,3,2,2,2,4,4,6,6,// 0 + 3,5,2,8,4,4,6,6,2,4,2,7,4,4,7,7,// 1 + 6,6,2,8,3,3,5,5,4,2,2,2,4,4,6,6,// 2 + 3,5,2,8,4,4,6,6,2,4,2,7,4,4,7,7,// 3 + 6,6,2,8,3,3,5,5,3,2,2,2,3,4,6,6,// 4 + 3,5,2,8,4,4,6,6,2,4,2,7,4,4,7,7,// 5 + 6,6,2,8,3,3,5,5,4,2,2,2,5,4,6,6,// 6 + 3,5,2,8,4,4,6,6,2,4,2,7,4,4,7,7,// 7 + 2,6,2,6,3,3,3,3,2,2,2,2,4,4,4,4,// 8 + 3,6,2,6,4,4,4,4,2,5,2,5,5,5,5,5,// 9 + 2,6,2,6,3,3,3,3,2,2,2,2,4,4,4,4,// A + 3,5,2,5,4,4,4,4,2,4,2,4,4,4,4,4,// B + 2,6,2,8,3,3,5,5,2,2,2,2,4,4,6,6,// C + 3,5,2,8,4,4,6,6,2,4,2,7,4,4,7,7,// D + 2,6,2,8,3,3,5,5,2,2,2,2,4,4,6,6,// E + 3,5,2,8,4,4,6,6,2,4,2,7,4,4,7,7 // F + }; // 0x00 was 7 + + fuint16 data; + data = clock_table [opcode]; + if ( (s_time += data) >= 0 ) + goto possibly_out_of_time; +almost_out_of_time: + + data = *instr; + + #ifdef NES_CPU_LOG_H + nes_cpu_log( "cpu_log", pc - 1, opcode, instr [0], instr [1] ); + #endif + + switch ( opcode ) + { +possibly_out_of_time: + if ( s_time < (int) data ) + goto almost_out_of_time; + s_time -= data; + goto out_of_time; + +// Macros + +#define GET_MSB() (instr [1]) +#define ADD_PAGE() (pc++, data += 0x100 * GET_MSB()) +#define GET_ADDR() GET_LE16( instr ) + +#define NO_PAGE_CROSSING( lsb ) +#define HANDLE_PAGE_CROSSING( lsb ) s_time += (lsb) >> 8; + +#define INC_DEC_XY( reg, n ) reg = uint8_t (nz = reg + n); goto loop; + +#define IND_Y( cross, out ) {\ + fuint16 temp = READ_LOW( data ) + y;\ + out = temp + 0x100 * READ_LOW( uint8_t (data + 1) );\ + cross( temp );\ + } + +#define IND_X( out ) {\ + fuint16 temp = data + x;\ + out = 0x100 * READ_LOW( uint8_t (temp + 1) ) + READ_LOW( uint8_t (temp) );\ + } + +#define ARITH_ADDR_MODES( op )\ +case op - 0x04: /* (ind,x) */\ + IND_X( data )\ + goto ptr##op;\ +case op + 0x0C: /* (ind),y */\ + IND_Y( HANDLE_PAGE_CROSSING, data )\ + goto ptr##op;\ +case op + 0x10: /* zp,X */\ + data = uint8_t (data + x);\ +case op + 0x00: /* zp */\ + data = READ_LOW( data );\ + goto imm##op;\ +case op + 0x14: /* abs,Y */\ + data += y;\ + goto ind##op;\ +case op + 0x18: /* abs,X */\ + data += x;\ +ind##op:\ + HANDLE_PAGE_CROSSING( data );\ +case op + 0x08: /* abs */\ + ADD_PAGE();\ +ptr##op:\ + FLUSH_TIME();\ + data = READ( data );\ + CACHE_TIME();\ +case op + 0x04: /* imm */\ +imm##op: + +// TODO: more efficient way to handle negative branch that wraps PC around +#define BRANCH( cond )\ +{\ + fint16 offset = (BOOST::int8_t) data;\ + fuint16 extra_clock = (++pc & 0xFF) + offset;\ + if ( !(cond) ) goto dec_clock_loop;\ + pc += offset;\ + s_time += extra_clock >> 8 & 1;\ + goto loop;\ +} + +// Often-Used + + case 0xB5: // LDA zp,x + a = nz = READ_LOW( uint8_t (data + x) ); + pc++; + goto loop; + + case 0xA5: // LDA zp + a = nz = READ_LOW( data ); + pc++; + goto loop; + + case 0xD0: // BNE + BRANCH( (uint8_t) nz ); + + case 0x20: { // JSR + fuint16 temp = pc + 1; + pc = GET_ADDR(); + WRITE_LOW( 0x100 | (sp - 1), temp >> 8 ); + sp = (sp - 2) | 0x100; + WRITE_LOW( sp, temp ); + goto loop; + } + + case 0x4C: // JMP abs + pc = GET_ADDR(); + goto loop; + + case 0xE8: // INX + INC_DEC_XY( x, 1 ) + + case 0x10: // BPL + BRANCH( !IS_NEG ) + + ARITH_ADDR_MODES( 0xC5 ) // CMP + nz = a - data; + pc++; + c = ~nz; + nz &= 0xFF; + goto loop; + + case 0x30: // BMI + BRANCH( IS_NEG ) + + case 0xF0: // BEQ + BRANCH( !(uint8_t) nz ); + + case 0x95: // STA zp,x + data = uint8_t (data + x); + case 0x85: // STA zp + pc++; + WRITE_LOW( data, a ); + goto loop; + + case 0xC8: // INY + INC_DEC_XY( y, 1 ) + + case 0xA8: // TAY + y = a; + nz = a; + goto loop; + + case 0x98: // TYA + a = y; + nz = y; + goto loop; + + case 0xAD:{// LDA abs + unsigned addr = GET_ADDR(); + pc += 2; + nz = READ( addr ); + a = nz; + goto loop; + } + + case 0x60: // RTS + pc = 1 + READ_LOW( sp ); + pc += 0x100 * READ_LOW( 0x100 | (sp - 0xFF) ); + sp = (sp - 0xFE) | 0x100; + goto loop; + + { + fuint16 addr; + + case 0x99: // STA abs,Y + addr = y + GET_ADDR(); + pc += 2; + if ( addr <= 0x7FF ) + { + WRITE_LOW( addr, a ); + goto loop; + } + goto sta_ptr; + + case 0x8D: // STA abs + addr = GET_ADDR(); + pc += 2; + if ( addr <= 0x7FF ) + { + WRITE_LOW( addr, a ); + goto loop; + } + goto sta_ptr; + + case 0x9D: // STA abs,X (slightly more common than STA abs) + addr = x + GET_ADDR(); + pc += 2; + if ( addr <= 0x7FF ) + { + WRITE_LOW( addr, a ); + goto loop; + } + sta_ptr: + FLUSH_TIME(); + WRITE( addr, a ); + CACHE_TIME(); + goto loop; + + case 0x91: // STA (ind),Y + IND_Y( NO_PAGE_CROSSING, addr ) + pc++; + goto sta_ptr; + + case 0x81: // STA (ind,X) + IND_X( addr ) + pc++; + goto sta_ptr; + + } + + case 0xA9: // LDA #imm + pc++; + a = data; + nz = data; + goto loop; + + // common read instructions + { + fuint16 addr; + + case 0xA1: // LDA (ind,X) + IND_X( addr ) + pc++; + goto a_nz_read_addr; + + case 0xB1:// LDA (ind),Y + addr = READ_LOW( data ) + y; + HANDLE_PAGE_CROSSING( addr ); + addr += 0x100 * READ_LOW( (uint8_t) (data + 1) ); + pc++; + a = nz = READ_PROG( addr ); + if ( (addr ^ 0x8000) <= 0x9FFF ) + goto loop; + goto a_nz_read_addr; + + case 0xB9: // LDA abs,Y + HANDLE_PAGE_CROSSING( data + y ); + addr = GET_ADDR() + y; + pc += 2; + a = nz = READ_PROG( addr ); + if ( (addr ^ 0x8000) <= 0x9FFF ) + goto loop; + goto a_nz_read_addr; + + case 0xBD: // LDA abs,X + HANDLE_PAGE_CROSSING( data + x ); + addr = GET_ADDR() + x; + pc += 2; + a = nz = READ_PROG( addr ); + if ( (addr ^ 0x8000) <= 0x9FFF ) + goto loop; + a_nz_read_addr: + FLUSH_TIME(); + a = nz = READ( addr ); + CACHE_TIME(); + goto loop; + + } + +// Branch + + case 0x50: // BVC + BRANCH( !(status & st_v) ) + + case 0x70: // BVS + BRANCH( status & st_v ) + + case 0xB0: // BCS + BRANCH( c & 0x100 ) + + case 0x90: // BCC + BRANCH( !(c & 0x100) ) + +// Load/store + + case 0x94: // STY zp,x + data = uint8_t (data + x); + case 0x84: // STY zp + pc++; + WRITE_LOW( data, y ); + goto loop; + + case 0x96: // STX zp,y + data = uint8_t (data + y); + case 0x86: // STX zp + pc++; + WRITE_LOW( data, x ); + goto loop; + + case 0xB6: // LDX zp,y + data = uint8_t (data + y); + case 0xA6: // LDX zp + data = READ_LOW( data ); + case 0xA2: // LDX #imm + pc++; + x = data; + nz = data; + goto loop; + + case 0xB4: // LDY zp,x + data = uint8_t (data + x); + case 0xA4: // LDY zp + data = READ_LOW( data ); + case 0xA0: // LDY #imm + pc++; + y = data; + nz = data; + goto loop; + + case 0xBC: // LDY abs,X + data += x; + HANDLE_PAGE_CROSSING( data ); + case 0xAC:{// LDY abs + unsigned addr = data + 0x100 * GET_MSB(); + pc += 2; + FLUSH_TIME(); + y = nz = READ( addr ); + CACHE_TIME(); + goto loop; + } + + case 0xBE: // LDX abs,y + data += y; + HANDLE_PAGE_CROSSING( data ); + case 0xAE:{// LDX abs + unsigned addr = data + 0x100 * GET_MSB(); + pc += 2; + FLUSH_TIME(); + x = nz = READ( addr ); + CACHE_TIME(); + goto loop; + } + + { + fuint8 temp; + case 0x8C: // STY abs + temp = y; + goto store_abs; + + case 0x8E: // STX abs + temp = x; + store_abs: + unsigned addr = GET_ADDR(); + pc += 2; + if ( addr <= 0x7FF ) + { + WRITE_LOW( addr, temp ); + goto loop; + } + FLUSH_TIME(); + WRITE( addr, temp ); + CACHE_TIME(); + goto loop; + } + +// Compare + + case 0xEC:{// CPX abs + unsigned addr = GET_ADDR(); + pc++; + FLUSH_TIME(); + data = READ( addr ); + CACHE_TIME(); + goto cpx_data; + } + + case 0xE4: // CPX zp + data = READ_LOW( data ); + case 0xE0: // CPX #imm + cpx_data: + nz = x - data; + pc++; + c = ~nz; + nz &= 0xFF; + goto loop; + + case 0xCC:{// CPY abs + unsigned addr = GET_ADDR(); + pc++; + FLUSH_TIME(); + data = READ( addr ); + CACHE_TIME(); + goto cpy_data; + } + + case 0xC4: // CPY zp + data = READ_LOW( data ); + case 0xC0: // CPY #imm + cpy_data: + nz = y - data; + pc++; + c = ~nz; + nz &= 0xFF; + goto loop; + +// Logical + + ARITH_ADDR_MODES( 0x25 ) // AND + nz = (a &= data); + pc++; + goto loop; + + ARITH_ADDR_MODES( 0x45 ) // EOR + nz = (a ^= data); + pc++; + goto loop; + + ARITH_ADDR_MODES( 0x05 ) // ORA + nz = (a |= data); + pc++; + goto loop; + + case 0x2C:{// BIT abs + unsigned addr = GET_ADDR(); + pc += 2; + status &= ~st_v; + nz = READ( addr ); + status |= nz & st_v; + if ( a & nz ) + goto loop; + nz <<= 8; // result must be zero, even if N bit is set + goto loop; + } + + case 0x24: // BIT zp + nz = READ_LOW( data ); + pc++; + status &= ~st_v; + status |= nz & st_v; + if ( a & nz ) + goto loop; + nz <<= 8; // result must be zero, even if N bit is set + goto loop; + +// Add/subtract + + ARITH_ADDR_MODES( 0xE5 ) // SBC + case 0xEB: // unofficial equivalent + data ^= 0xFF; + goto adc_imm; + + ARITH_ADDR_MODES( 0x65 ) // ADC + adc_imm: { + check( !(status & st_d) ); + fint16 carry = c >> 8 & 1; + fint16 ov = (a ^ 0x80) + carry + (BOOST::int8_t) data; // sign-extend + status &= ~st_v; + status |= ov >> 2 & 0x40; + c = nz = a + data + carry; + pc++; + a = (uint8_t) nz; + goto loop; + } + +// Shift/rotate + + case 0x4A: // LSR A + c = 0; + case 0x6A: // ROR A + nz = c >> 1 & 0x80; + c = a << 8; + nz |= a >> 1; + a = nz; + goto loop; + + case 0x0A: // ASL A + nz = a << 1; + c = nz; + a = (uint8_t) nz; + goto loop; + + case 0x2A: { // ROL A + nz = a << 1; + fint16 temp = c >> 8 & 1; + c = nz; + nz |= temp; + a = (uint8_t) nz; + goto loop; + } + + case 0x5E: // LSR abs,X + data += x; + case 0x4E: // LSR abs + c = 0; + case 0x6E: // ROR abs + ror_abs: { + ADD_PAGE(); + FLUSH_TIME(); + int temp = READ( data ); + nz = (c >> 1 & 0x80) | (temp >> 1); + c = temp << 8; + goto rotate_common; + } + + case 0x3E: // ROL abs,X + data += x; + goto rol_abs; + + case 0x1E: // ASL abs,X + data += x; + case 0x0E: // ASL abs + c = 0; + case 0x2E: // ROL abs + rol_abs: + ADD_PAGE(); + nz = c >> 8 & 1; + FLUSH_TIME(); + nz |= (c = READ( data ) << 1); + rotate_common: + pc++; + WRITE( data, (uint8_t) nz ); + CACHE_TIME(); + goto loop; + + case 0x7E: // ROR abs,X + data += x; + goto ror_abs; + + case 0x76: // ROR zp,x + data = uint8_t (data + x); + goto ror_zp; + + case 0x56: // LSR zp,x + data = uint8_t (data + x); + case 0x46: // LSR zp + c = 0; + case 0x66: // ROR zp + ror_zp: { + int temp = READ_LOW( data ); + nz = (c >> 1 & 0x80) | (temp >> 1); + c = temp << 8; + goto write_nz_zp; + } + + case 0x36: // ROL zp,x + data = uint8_t (data + x); + goto rol_zp; + + case 0x16: // ASL zp,x + data = uint8_t (data + x); + case 0x06: // ASL zp + c = 0; + case 0x26: // ROL zp + rol_zp: + nz = c >> 8 & 1; + nz |= (c = READ_LOW( data ) << 1); + goto write_nz_zp; + +// Increment/decrement + + case 0xCA: // DEX + INC_DEC_XY( x, -1 ) + + case 0x88: // DEY + INC_DEC_XY( y, -1 ) + + case 0xF6: // INC zp,x + data = uint8_t (data + x); + case 0xE6: // INC zp + nz = 1; + goto add_nz_zp; + + case 0xD6: // DEC zp,x + data = uint8_t (data + x); + case 0xC6: // DEC zp + nz = (unsigned) -1; + add_nz_zp: + nz += READ_LOW( data ); + write_nz_zp: + pc++; + WRITE_LOW( data, nz ); + goto loop; + + case 0xFE: // INC abs,x + data = x + GET_ADDR(); + goto inc_ptr; + + case 0xEE: // INC abs + data = GET_ADDR(); + inc_ptr: + nz = 1; + goto inc_common; + + case 0xDE: // DEC abs,x + data = x + GET_ADDR(); + goto dec_ptr; + + case 0xCE: // DEC abs + data = GET_ADDR(); + dec_ptr: + nz = (unsigned) -1; + inc_common: + FLUSH_TIME(); + nz += READ( data ); + pc += 2; + WRITE( data, (uint8_t) nz ); + CACHE_TIME(); + goto loop; + +// Transfer + + case 0xAA: // TAX + x = a; + nz = a; + goto loop; + + case 0x8A: // TXA + a = x; + nz = x; + goto loop; + + case 0x9A: // TXS + SET_SP( x ); // verified (no flag change) + goto loop; + + case 0xBA: // TSX + x = nz = GET_SP(); + goto loop; + +// Stack + + case 0x48: // PHA + PUSH( a ); // verified + goto loop; + + case 0x68: // PLA + a = nz = READ_LOW( sp ); + sp = (sp - 0xFF) | 0x100; + goto loop; + + case 0x40:{// RTI + fuint8 temp = READ_LOW( sp ); + pc = READ_LOW( 0x100 | (sp - 0xFF) ); + pc |= READ_LOW( 0x100 | (sp - 0xFE) ) * 0x100; + sp = (sp - 0xFD) | 0x100; + data = status; + SET_STATUS( temp ); + this->r.status = status; // update externally-visible I flag + if ( (data ^ status) & st_i ) + { + sap_time_t new_time = end_time_; + if ( !(status & st_i) && new_time > irq_time_ ) + new_time = irq_time_; + blargg_long delta = s.base - new_time; + s.base = new_time; + s_time += delta; + } + goto loop; + } + + case 0x28:{// PLP + fuint8 temp = READ_LOW( sp ); + sp = (sp - 0xFF) | 0x100; + fuint8 changed = status ^ temp; + SET_STATUS( temp ); + if ( !(changed & st_i) ) + goto loop; // I flag didn't change + if ( status & st_i ) + goto handle_sei; + goto handle_cli; + } + + case 0x08: { // PHP + fuint8 temp; + CALC_STATUS( temp ); + PUSH( temp | (st_b | st_r) ); + goto loop; + } + + case 0x6C:{// JMP (ind) + data = GET_ADDR(); + pc = READ_PROG( data ); + data = (data & 0xFF00) | ((data + 1) & 0xFF); + pc |= 0x100 * READ_PROG( data ); + goto loop; + } + + case 0x00: // BRK + goto handle_brk; + +// Flags + + case 0x38: // SEC + c = (unsigned) ~0; + goto loop; + + case 0x18: // CLC + c = 0; + goto loop; + + case 0xB8: // CLV + status &= ~st_v; + goto loop; + + case 0xD8: // CLD + status &= ~st_d; + goto loop; + + case 0xF8: // SED + status |= st_d; + goto loop; + + case 0x58: // CLI + if ( !(status & st_i) ) + goto loop; + status &= ~st_i; + handle_cli: { + this->r.status = status; // update externally-visible I flag + blargg_long delta = s.base - irq_time_; + if ( delta <= 0 ) + { + if ( TIME < irq_time_ ) + goto loop; + goto delayed_cli; + } + s.base = irq_time_; + s_time += delta; + if ( s_time < 0 ) + goto loop; + + if ( delta >= s_time + 1 ) + { + // delayed irq until after next instruction + s.base += s_time + 1; + s_time = -1; + irq_time_ = s.base; // TODO: remove, as only to satisfy debug check in loop + goto loop; + } + delayed_cli: + debug_printf( "Delayed CLI not emulated\n" ); + goto loop; + } + + case 0x78: // SEI + if ( status & st_i ) + goto loop; + status |= st_i; + handle_sei: { + this->r.status = status; // update externally-visible I flag + blargg_long delta = s.base - end_time_; + s.base = end_time_; + s_time += delta; + if ( s_time < 0 ) + goto loop; + debug_printf( "Delayed SEI not emulated\n" ); + goto loop; + } + +// Unofficial + + // SKW - Skip word + case 0x1C: case 0x3C: case 0x5C: case 0x7C: case 0xDC: case 0xFC: + HANDLE_PAGE_CROSSING( data + x ); + case 0x0C: + pc++; + // SKB - Skip byte + case 0x74: case 0x04: case 0x14: case 0x34: case 0x44: case 0x54: case 0x64: + case 0x80: case 0x82: case 0x89: case 0xC2: case 0xD4: case 0xE2: case 0xF4: + pc++; + goto loop; + + // NOP + case 0xEA: case 0x1A: case 0x3A: case 0x5A: case 0x7A: case 0xDA: case 0xFA: + goto loop; + +// Unimplemented + + // halt + //case 0x02: case 0x12: case 0x22: case 0x32: case 0x42: case 0x52: + //case 0x62: case 0x72: case 0x92: case 0xB2: case 0xD2: case 0xF2: + + default: + assert( (unsigned) opcode <= 0xFF ); + illegal_encountered = true; + pc--; + goto stop; + } + assert( false ); + + int result_; +handle_brk: + if ( (pc - 1) >= idle_addr ) + goto idle_done; + pc++; + result_ = 4; + debug_printf( "BRK executed\n" ); + +interrupt: + { + s_time += 7; + + WRITE_LOW( 0x100 | (sp - 1), pc >> 8 ); + WRITE_LOW( 0x100 | (sp - 2), pc ); + pc = GET_LE16( &READ_PROG( 0xFFFA ) + result_ ); + + sp = (sp - 3) | 0x100; + fuint8 temp; + CALC_STATUS( temp ); + temp |= st_r; + if ( result_ ) + temp |= st_b; // TODO: incorrectly sets B flag for IRQ + WRITE_LOW( sp, temp ); + + status &= ~st_d; + status |= st_i; + this->r.status = status; // update externally-visible I flag + + blargg_long delta = s.base - end_time_; + s.base = end_time_; + s_time += delta; + goto loop; + } + +idle_done: + //s_time = 0; + pc--; + goto stop; +out_of_time: + pc--; + FLUSH_TIME(); + CPU_DONE( this, TIME, result_ ); + CACHE_TIME(); + if ( result_ >= 0 ) + goto interrupt; + if ( s_time < 0 ) + goto loop; + +stop: + + s.time = s_time; + + r.pc = pc; + r.sp = GET_SP(); + r.a = a; + r.x = x; + r.y = y; + + { + fuint8 temp; + CALC_STATUS( temp ); + r.status = temp; + } + + this->state_ = s; + this->state = &this->state_; + + return illegal_encountered; +} + diff --git a/libs/gme/gme/Sap_Cpu.h b/libs/gme/gme/Sap_Cpu.h new file mode 100644 index 000000000..ea42c7a80 --- /dev/null +++ b/libs/gme/gme/Sap_Cpu.h @@ -0,0 +1,83 @@ +// Atari 6502 CPU emulator + +// Game_Music_Emu 0.6.0 +#ifndef SAP_CPU_H +#define SAP_CPU_H + +#include "blargg_common.h" + +typedef blargg_long sap_time_t; // clock cycle count +typedef unsigned sap_addr_t; // 16-bit address +enum { future_sap_time = INT_MAX / 2 + 1 }; + +class Sap_Cpu { +public: + typedef BOOST::uint8_t uint8_t; + + // Clear all registers and keep pointer to 64K memory passed in + void reset( void* mem_64k ); + + // Run until specified time is reached. Returns true if suspicious/unsupported + // instruction was encountered at any point during run. + bool run( sap_time_t end_time ); + + // Registers are not updated until run() returns (except I flag in status) + struct registers_t { + BOOST::uint16_t pc; + BOOST::uint8_t a; + BOOST::uint8_t x; + BOOST::uint8_t y; + BOOST::uint8_t status; + BOOST::uint8_t sp; + }; + registers_t r; + + enum { idle_addr = 0xFEFF }; + + // Time of beginning of next instruction to be executed + sap_time_t time() const { return state->time + state->base; } + void set_time( sap_time_t t ) { state->time = t - state->base; } + void adjust_time( int delta ) { state->time += delta; } + + sap_time_t irq_time() const { return irq_time_; } + void set_irq_time( sap_time_t ); + + sap_time_t end_time() const { return end_time_; } + void set_end_time( sap_time_t ); + +public: + Sap_Cpu() { state = &state_; } + enum { irq_inhibit = 0x04 }; +private: + struct state_t { + sap_time_t base; + sap_time_t time; + }; + state_t* state; // points to state_ or a local copy within run() + state_t state_; + sap_time_t irq_time_; + sap_time_t end_time_; + uint8_t* mem; + + inline sap_time_t update_end_time( sap_time_t end, sap_time_t irq ); +}; + +inline sap_time_t Sap_Cpu::update_end_time( sap_time_t t, sap_time_t irq ) +{ + if ( irq < t && !(r.status & irq_inhibit) ) t = irq; + sap_time_t delta = state->base - t; + state->base = t; + return delta; +} + +inline void Sap_Cpu::set_irq_time( sap_time_t t ) +{ + state->time += update_end_time( end_time_, (irq_time_ = t) ); +} + +inline void Sap_Cpu::set_end_time( sap_time_t t ) +{ + state->time += update_end_time( (end_time_ = t), irq_time_ ); +} + +#endif diff --git a/libs/gme/gme/Sap_Emu.cpp b/libs/gme/gme/Sap_Emu.cpp new file mode 100644 index 000000000..cb52714f9 --- /dev/null +++ b/libs/gme/gme/Sap_Emu.cpp @@ -0,0 +1,444 @@ +// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/ + +#include "Sap_Emu.h" + +#include "blargg_endian.h" +#include + +/* Copyright (C) 2006 Shay Green. This module 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 +module 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 module; if not, write to the Free Software Foundation, +Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + +#include "blargg_source.h" + +long const base_scanline_period = 114; + +Sap_Emu::Sap_Emu() +{ + set_type( gme_sap_type ); + + static const char* const names [Sap_Apu::osc_count * 2] = { + "Wave 1", "Wave 2", "Wave 3", "Wave 4", + "Wave 5", "Wave 6", "Wave 7", "Wave 8", + }; + set_voice_names( names ); + + static int const types [Sap_Apu::osc_count * 2] = { + wave_type | 1, wave_type | 2, wave_type | 3, wave_type | 0, + wave_type | 5, wave_type | 6, wave_type | 7, wave_type | 4, + }; + set_voice_types( types ); + set_silence_lookahead( 6 ); +} + +Sap_Emu::~Sap_Emu() { } + +// Track info + +// Returns 16 or greater if not hex +inline int from_hex_char( int h ) +{ + h -= 0x30; + if ( (unsigned) h > 9 ) + h = ((h - 0x11) & 0xDF) + 10; + return h; +} + +static long from_hex( byte const* in ) +{ + unsigned result = 0; + for ( int n = 4; n--; ) + { + int h = from_hex_char( *in++ ); + if ( h > 15 ) + return -1; + result = result * 0x10 + h; + } + return result; +} + +static int from_dec( byte const* in, byte const* end ) +{ + if ( in >= end ) + return -1; + + int n = 0; + while ( in < end ) + { + int dig = *in++ - '0'; + if ( (unsigned) dig > 9 ) + return -1; + n = n * 10 + dig; + } + return n; +} + +static void parse_string( byte const* in, byte const* end, int len, char* out ) +{ + byte const* start = in; + if ( *in++ == '\"' ) + { + start++; + while ( in < end && *in != '\"' ) + in++; + } + else + { + in = end; + } + len = min( len - 1, int (in - start) ); + out [len] = 0; + memcpy( out, start, len ); +} + +static blargg_err_t parse_info( byte const* in, long size, Sap_Emu::info_t* out ) +{ + out->track_count = 1; + out->author [0] = 0; + out->name [0] = 0; + out->copyright [0] = 0; + + if ( size < 16 || memcmp( in, "SAP\x0D\x0A", 5 ) ) + return gme_wrong_file_type; + + byte const* file_end = in + size - 5; + in += 5; + while ( in < file_end && (in [0] != 0xFF || in [1] != 0xFF) ) + { + byte const* line_end = in; + while ( line_end < file_end && *line_end != 0x0D ) + line_end++; + + char const* tag = (char const*) in; + while ( in < line_end && *in > ' ' ) + in++; + int tag_len = (char const*) in - tag; + + while ( in < line_end && *in <= ' ' ) in++; + + if ( tag_len <= 0 ) + { + // skip line + } + else if ( !strncmp( "INIT", tag, tag_len ) ) + { + out->init_addr = from_hex( in ); + if ( (unsigned long) out->init_addr > 0xFFFF ) + return "Invalid init address"; + } + else if ( !strncmp( "PLAYER", tag, tag_len ) ) + { + out->play_addr = from_hex( in ); + if ( (unsigned long) out->play_addr > 0xFFFF ) + return "Invalid play address"; + } + else if ( !strncmp( "MUSIC", tag, tag_len ) ) + { + out->music_addr = from_hex( in ); + if ( (unsigned long) out->music_addr > 0xFFFF ) + return "Invalid music address"; + } + else if ( !strncmp( "SONGS", tag, tag_len ) ) + { + out->track_count = from_dec( in, line_end ); + if ( out->track_count <= 0 ) + return "Invalid track count"; + } + else if ( !strncmp( "TYPE", tag, tag_len ) ) + { + switch ( out->type = *in ) + { + case 'C': + case 'B': + break; + + case 'D': + return "Digimusic not supported"; + + default: + return "Unsupported player type"; + } + } + else if ( !strncmp( "STEREO", tag, tag_len ) ) + { + out->stereo = true; + } + else if ( !strncmp( "FASTPLAY", tag, tag_len ) ) + { + out->fastplay = from_dec( in, line_end ); + if ( out->fastplay <= 0 ) + return "Invalid fastplay value"; + } + else if ( !strncmp( "AUTHOR", tag, tag_len ) ) + { + parse_string( in, line_end, sizeof out->author, out->author ); + } + else if ( !strncmp( "NAME", tag, tag_len ) ) + { + parse_string( in, line_end, sizeof out->name, out->name ); + } + else if ( !strncmp( "DATE", tag, tag_len ) ) + { + parse_string( in, line_end, sizeof out->copyright, out->copyright ); + } + + in = line_end + 2; + } + + if ( in [0] != 0xFF || in [1] != 0xFF ) + return "ROM data missing"; + out->rom_data = in + 2; + + return 0; +} + +static void copy_sap_fields( Sap_Emu::info_t const& in, track_info_t* out ) +{ + Gme_File::copy_field_( out->game, in.name ); + Gme_File::copy_field_( out->author, in.author ); + Gme_File::copy_field_( out->copyright, in.copyright ); +} + +blargg_err_t Sap_Emu::track_info_( track_info_t* out, int ) const +{ + copy_sap_fields( info, out ); + return 0; +} + +struct Sap_File : Gme_Info_ +{ + Sap_Emu::info_t info; + + Sap_File() { set_type( gme_sap_type ); } + + blargg_err_t load_mem_( byte const* begin, long size ) + { + RETURN_ERR( parse_info( begin, size, &info ) ); + set_track_count( info.track_count ); + return 0; + } + + blargg_err_t track_info_( track_info_t* out, int ) const + { + copy_sap_fields( info, out ); + return 0; + } +}; + +static Music_Emu* new_sap_emu () { return BLARGG_NEW Sap_Emu ; } +static Music_Emu* new_sap_file() { return BLARGG_NEW Sap_File; } + +static gme_type_t_ const gme_sap_type_ = { "Atari XL", 0, &new_sap_emu, &new_sap_file, "SAP", 1 }; +gme_type_t const gme_sap_type = &gme_sap_type_; + + +// Setup + +blargg_err_t Sap_Emu::load_mem_( byte const* in, long size ) +{ + file_end = in + size; + + info.warning = 0; + info.type = 'B'; + info.stereo = false; + info.init_addr = -1; + info.play_addr = -1; + info.music_addr = -1; + info.fastplay = 312; + RETURN_ERR( parse_info( in, size, &info ) ); + + set_warning( info.warning ); + set_track_count( info.track_count ); + set_voice_count( Sap_Apu::osc_count << info.stereo ); + apu_impl.volume( gain() ); + + return setup_buffer( 1773447 ); +} + +void Sap_Emu::update_eq( blip_eq_t const& eq ) +{ + apu_impl.synth.treble_eq( eq ); +} + +void Sap_Emu::set_voice( int i, Blip_Buffer* center, Blip_Buffer* left, Blip_Buffer* right ) +{ + int i2 = i - Sap_Apu::osc_count; + if ( i2 >= 0 ) + apu2.osc_output( i2, right ); + else + apu.osc_output( i, (info.stereo ? left : center) ); +} + +// Emulation + +void Sap_Emu::set_tempo_( double t ) +{ + scanline_period = sap_time_t (base_scanline_period / t); +} + +inline sap_time_t Sap_Emu::play_period() const { return info.fastplay * scanline_period; } + +void Sap_Emu::cpu_jsr( sap_addr_t addr ) +{ + check( r.sp >= 0xFE ); // catch anything trying to leave data on stack + r.pc = addr; + int high_byte = (idle_addr - 1) >> 8; + if ( r.sp == 0xFE && mem.ram [0x1FF] == high_byte ) + r.sp = 0xFF; // pop extra byte off + mem.ram [0x100 + r.sp--] = high_byte; // some routines use RTI to return + mem.ram [0x100 + r.sp--] = high_byte; + mem.ram [0x100 + r.sp--] = (idle_addr - 1) & 0xFF; +} + +void Sap_Emu::run_routine( sap_addr_t addr ) +{ + cpu_jsr( addr ); + cpu::run( 312 * base_scanline_period * 60 ); + check( r.pc == idle_addr ); +} + +inline void Sap_Emu::call_init( int track ) +{ + switch ( info.type ) + { + case 'B': + r.a = track; + run_routine( info.init_addr ); + break; + + case 'C': + r.a = 0x70; + r.x = info.music_addr&0xFF; + r.y = info.music_addr >> 8; + run_routine( info.play_addr + 3 ); + r.a = 0; + r.x = track; + run_routine( info.play_addr + 3 ); + break; + } +} + +blargg_err_t Sap_Emu::start_track_( int track ) +{ + RETURN_ERR( Classic_Emu::start_track_( track ) ); + + memset( &mem, 0, sizeof mem ); + + byte const* in = info.rom_data; + while ( file_end - in >= 5 ) + { + unsigned start = get_le16( in ); + unsigned end = get_le16( in + 2 ); + //debug_printf( "Block $%04X-$%04X\n", start, end ); + in += 4; + if ( end < start ) + { + set_warning( "Invalid file data block" ); + break; + } + long len = end - start + 1; + if ( len > file_end - in ) + { + set_warning( "Invalid file data block" ); + break; + } + + memcpy( mem.ram + start, in, len ); + in += len; + if ( file_end - in >= 2 && in [0] == 0xFF && in [1] == 0xFF ) + in += 2; + } + + apu.reset( &apu_impl ); + apu2.reset( &apu_impl ); + cpu::reset( mem.ram ); + time_mask = 0; // disables sound during init + call_init( track ); + time_mask = -1; + + next_play = play_period(); + + return 0; +} + +// Emulation + +// see sap_cpu_io.h for read/write functions + +void Sap_Emu::cpu_write_( sap_addr_t addr, int data ) +{ + if ( (addr ^ Sap_Apu::start_addr) <= (Sap_Apu::end_addr - Sap_Apu::start_addr) ) + { + GME_APU_HOOK( this, addr - Sap_Apu::start_addr, data ); + apu.write_data( time() & time_mask, addr, data ); + return; + } + + if ( (addr ^ (Sap_Apu::start_addr + 0x10)) <= (Sap_Apu::end_addr - Sap_Apu::start_addr) && + info.stereo ) + { + GME_APU_HOOK( this, addr - 0x10 - Sap_Apu::start_addr + 10, data ); + apu2.write_data( time() & time_mask, addr ^ 0x10, data ); + return; + } + + if ( (addr & ~0x0010) != 0xD20F || data != 0x03 ) + debug_printf( "Unmapped write $%04X <- $%02X\n", addr, data ); +} + +inline void Sap_Emu::call_play() +{ + switch ( info.type ) + { + case 'B': + cpu_jsr( info.play_addr ); + break; + + case 'C': + cpu_jsr( info.play_addr + 6 ); + break; + } +} + +blargg_err_t Sap_Emu::run_clocks( blip_time_t& duration, int ) +{ + set_time( 0 ); + while ( time() < duration ) + { + if ( cpu::run( duration ) || r.pc > idle_addr ) + return "Emulation error (illegal instruction)"; + + if ( r.pc == idle_addr ) + { + if ( next_play <= duration ) + { + set_time( next_play ); + next_play += play_period(); + call_play(); + GME_FRAME_HOOK( this ); + } + else + { + set_time( duration ); + } + } + } + + duration = time(); + next_play -= duration; + check( next_play >= 0 ); + if ( next_play < 0 ) + next_play = 0; + apu.end_frame( duration ); + if ( info.stereo ) + apu2.end_frame( duration ); + + return 0; +} diff --git a/libs/gme/gme/Sap_Emu.h b/libs/gme/gme/Sap_Emu.h new file mode 100644 index 000000000..5b0dc47df --- /dev/null +++ b/libs/gme/gme/Sap_Emu.h @@ -0,0 +1,69 @@ +// Atari XL/XE SAP music file emulator + +// Game_Music_Emu 0.6.0 +#ifndef SAP_EMU_H +#define SAP_EMU_H + +#include "Classic_Emu.h" +#include "Sap_Apu.h" +#include "Sap_Cpu.h" + +class Sap_Emu : private Sap_Cpu, public Classic_Emu { + typedef Sap_Cpu cpu; +public: + static gme_type_t static_type() { return gme_sap_type; } +public: + Sap_Emu(); + ~Sap_Emu(); + struct info_t { + byte const* rom_data; + const char* warning; + long init_addr; + long play_addr; + long music_addr; + int type; + int track_count; + int fastplay; + bool stereo; + char author [256]; + char name [256]; + char copyright [ 32]; + }; +protected: + blargg_err_t track_info_( track_info_t*, int track ) const; + blargg_err_t load_mem_( byte const*, long ); + blargg_err_t start_track_( int ); + blargg_err_t run_clocks( blip_time_t&, int ); + void set_tempo_( double ); + void set_voice( int, Blip_Buffer*, Blip_Buffer*, Blip_Buffer* ); + void update_eq( blip_eq_t const& ); +public: private: friend class Sap_Cpu; + int cpu_read( sap_addr_t ); + void cpu_write( sap_addr_t, int ); + void cpu_write_( sap_addr_t, int ); +private: + info_t info; + + byte const* file_end; + sap_time_t scanline_period; + sap_time_t next_play; + sap_time_t time_mask; + Sap_Apu apu; + Sap_Apu apu2; + + // large items + struct { + byte padding1 [0x100]; + byte ram [0x10000]; + byte padding2 [0x100]; + } mem; + Sap_Apu_Impl apu_impl; + + sap_time_t play_period() const; + void call_play(); + void cpu_jsr( sap_addr_t ); + void call_init( int track ); + void run_routine( sap_addr_t ); +}; + +#endif diff --git a/libs/gme/gme/Sms_Apu.cpp b/libs/gme/gme/Sms_Apu.cpp new file mode 100644 index 000000000..b41fdec41 --- /dev/null +++ b/libs/gme/gme/Sms_Apu.cpp @@ -0,0 +1,330 @@ +// Sms_Snd_Emu 0.1.4. http://www.slack.net/~ant/ + +#include "Sms_Apu.h" + +/* Copyright (C) 2003-2006 Shay Green. This module 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 +module 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 module; if not, write to the Free Software Foundation, +Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + +#include "blargg_source.h" + +// Sms_Osc + +Sms_Osc::Sms_Osc() +{ + output = 0; + outputs [0] = 0; // always stays NULL + outputs [1] = 0; + outputs [2] = 0; + outputs [3] = 0; +} + +void Sms_Osc::reset() +{ + delay = 0; + last_amp = 0; + volume = 0; + output_select = 3; + output = outputs [3]; +} + +// Sms_Square + +inline void Sms_Square::reset() +{ + period = 0; + phase = 0; + Sms_Osc::reset(); +} + +void Sms_Square::run( blip_time_t time, blip_time_t end_time ) +{ + if ( !volume || period <= 128 ) + { + // ignore 16kHz and higher + if ( last_amp ) + { + synth->offset( time, -last_amp, output ); + last_amp = 0; + } + time += delay; + if ( !period ) + { + time = end_time; + } + else if ( time < end_time ) + { + // keep calculating phase + int count = (end_time - time + period - 1) / period; + phase = (phase + count) & 1; + time += count * period; + } + } + else + { + int amp = phase ? volume : -volume; + { + int delta = amp - last_amp; + if ( delta ) + { + last_amp = amp; + synth->offset( time, delta, output ); + } + } + + time += delay; + if ( time < end_time ) + { + Blip_Buffer* const output = this->output; + int delta = amp * 2; + do + { + delta = -delta; + synth->offset_inline( time, delta, output ); + time += period; + phase ^= 1; + } + while ( time < end_time ); + this->last_amp = phase ? volume : -volume; + } + } + delay = time - end_time; +} + +// Sms_Noise + +static int const noise_periods [3] = { 0x100, 0x200, 0x400 }; + +inline void Sms_Noise::reset() +{ + period = &noise_periods [0]; + shifter = 0x8000; + feedback = 0x9000; + Sms_Osc::reset(); +} + +void Sms_Noise::run( blip_time_t time, blip_time_t end_time ) +{ + int amp = volume; + if ( shifter & 1 ) + amp = -amp; + + { + int delta = amp - last_amp; + if ( delta ) + { + last_amp = amp; + synth.offset( time, delta, output ); + } + } + + time += delay; + if ( !volume ) + time = end_time; + + if ( time < end_time ) + { + Blip_Buffer* const output = this->output; + unsigned shifter = this->shifter; + int delta = amp * 2; + int period = *this->period * 2; + if ( !period ) + period = 16; + + do + { + int changed = shifter + 1; + shifter = (feedback & -(shifter & 1)) ^ (shifter >> 1); + if ( changed & 2 ) // true if bits 0 and 1 differ + { + delta = -delta; + synth.offset_inline( time, delta, output ); + } + time += period; + } + while ( time < end_time ); + + this->shifter = shifter; + this->last_amp = delta >> 1; + } + delay = time - end_time; +} + +// Sms_Apu + +Sms_Apu::Sms_Apu() +{ + for ( int i = 0; i < 3; i++ ) + { + squares [i].synth = &square_synth; + oscs [i] = &squares [i]; + } + oscs [3] = &noise; + + volume( 1.0 ); + reset(); +} + +Sms_Apu::~Sms_Apu() +{ +} + +void Sms_Apu::volume( double vol ) +{ + vol *= 0.85 / (osc_count * 64 * 2); + square_synth.volume( vol ); + noise.synth.volume( vol ); +} + +void Sms_Apu::treble_eq( const blip_eq_t& eq ) +{ + square_synth.treble_eq( eq ); + noise.synth.treble_eq( eq ); +} + +void Sms_Apu::osc_output( int index, Blip_Buffer* center, Blip_Buffer* left, Blip_Buffer* right ) +{ + require( (unsigned) index < osc_count ); + require( (center && left && right) || (!center && !left && !right) ); + Sms_Osc& osc = *oscs [index]; + osc.outputs [1] = right; + osc.outputs [2] = left; + osc.outputs [3] = center; + osc.output = osc.outputs [osc.output_select]; +} + +void Sms_Apu::output( Blip_Buffer* center, Blip_Buffer* left, Blip_Buffer* right ) +{ + for ( int i = 0; i < osc_count; i++ ) + osc_output( i, center, left, right ); +} + +void Sms_Apu::reset( unsigned feedback, int noise_width ) +{ + last_time = 0; + latch = 0; + + if ( !feedback || !noise_width ) + { + feedback = 0x0009; + noise_width = 16; + } + // convert to "Galios configuration" + looped_feedback = 1 << (noise_width - 1); + noise_feedback = 0; + while ( noise_width-- ) + { + noise_feedback = (noise_feedback << 1) | (feedback & 1); + feedback >>= 1; + } + + squares [0].reset(); + squares [1].reset(); + squares [2].reset(); + noise.reset(); +} + +void Sms_Apu::run_until( blip_time_t end_time ) +{ + require( end_time >= last_time ); // end_time must not be before previous time + + if ( end_time > last_time ) + { + // run oscillators + for ( int i = 0; i < osc_count; ++i ) + { + Sms_Osc& osc = *oscs [i]; + if ( osc.output ) + { + osc.output->set_modified(); + if ( i < 3 ) + squares [i].run( last_time, end_time ); + else + noise.run( last_time, end_time ); + } + } + + last_time = end_time; + } +} + +void Sms_Apu::end_frame( blip_time_t end_time ) +{ + if ( end_time > last_time ) + run_until( end_time ); + + assert( last_time >= end_time ); + last_time -= end_time; +} + +void Sms_Apu::write_ggstereo( blip_time_t time, int data ) +{ + require( (unsigned) data <= 0xFF ); + + run_until( time ); + + for ( int i = 0; i < osc_count; i++ ) + { + Sms_Osc& osc = *oscs [i]; + int flags = data >> i; + Blip_Buffer* old_output = osc.output; + osc.output_select = (flags >> 3 & 2) | (flags & 1); + osc.output = osc.outputs [osc.output_select]; + if ( osc.output != old_output && osc.last_amp ) + { + if ( old_output ) + { + old_output->set_modified(); + square_synth.offset( time, -osc.last_amp, old_output ); + } + osc.last_amp = 0; + } + } +} + +// volumes [i] = 64 * pow( 1.26, 15 - i ) / pow( 1.26, 15 ) +static unsigned char const volumes [16] = { + 64, 50, 39, 31, 24, 19, 15, 12, 9, 7, 5, 4, 3, 2, 1, 0 +}; + +void Sms_Apu::write_data( blip_time_t time, int data ) +{ + require( (unsigned) data <= 0xFF ); + + run_until( time ); + + if ( data & 0x80 ) + latch = data; + + int index = (latch >> 5) & 3; + if ( latch & 0x10 ) + { + oscs [index]->volume = volumes [data & 15]; + } + else if ( index < 3 ) + { + Sms_Square& sq = squares [index]; + if ( data & 0x80 ) + sq.period = (sq.period & 0xFF00) | (data << 4 & 0x00FF); + else + sq.period = (sq.period & 0x00FF) | (data << 8 & 0x3F00); + } + else + { + int select = data & 3; + if ( select < 3 ) + noise.period = &noise_periods [select]; + else + noise.period = &squares [2].period; + + noise.feedback = (data & 0x04) ? noise_feedback : looped_feedback; + noise.shifter = 0x8000; + } +} diff --git a/libs/gme/gme/Sms_Apu.h b/libs/gme/gme/Sms_Apu.h new file mode 100644 index 000000000..3c11a9c3c --- /dev/null +++ b/libs/gme/gme/Sms_Apu.h @@ -0,0 +1,75 @@ +// Sega Master System SN76489 PSG sound chip emulator + +// Sms_Snd_Emu 0.1.4 +#ifndef SMS_APU_H +#define SMS_APU_H + +#include "Sms_Oscs.h" + +class Sms_Apu { +public: + // Set overall volume of all oscillators, where 1.0 is full volume + void volume( double ); + + // Set treble equalization + void treble_eq( const blip_eq_t& ); + + // Outputs can be assigned to a single buffer for mono output, or to three + // buffers for stereo output (using Stereo_Buffer to do the mixing). + + // Assign all oscillator outputs to specified buffer(s). If buffer + // is NULL, silences all oscillators. + void output( Blip_Buffer* mono ); + void output( Blip_Buffer* center, Blip_Buffer* left, Blip_Buffer* right ); + + // Assign single oscillator output to buffer(s). Valid indicies are 0 to 3, + // which refer to Square 1, Square 2, Square 3, and Noise. If buffer is NULL, + // silences oscillator. + enum { osc_count = 4 }; + void osc_output( int index, Blip_Buffer* mono ); + void osc_output( int index, Blip_Buffer* center, Blip_Buffer* left, Blip_Buffer* right ); + + // Reset oscillators and internal state + void reset( unsigned noise_feedback = 0, int noise_width = 0 ); + + // Write GameGear left/right assignment byte + void write_ggstereo( blip_time_t, int ); + + // Write to data port + void write_data( blip_time_t, int ); + + // Run all oscillators up to specified time, end current frame, then + // start a new frame at time 0. + void end_frame( blip_time_t ); + +public: + Sms_Apu(); + ~Sms_Apu(); +private: + // noncopyable + Sms_Apu( const Sms_Apu& ); + Sms_Apu& operator = ( const Sms_Apu& ); + + Sms_Osc* oscs [osc_count]; + Sms_Square squares [3]; + Sms_Square::Synth square_synth; // used by squares + blip_time_t last_time; + int latch; + Sms_Noise noise; + unsigned noise_feedback; + unsigned looped_feedback; + + void run_until( blip_time_t ); +}; + +struct sms_apu_state_t +{ + unsigned char regs [8] [2]; + unsigned char latch; +}; + +inline void Sms_Apu::output( Blip_Buffer* b ) { output( b, b, b ); } + +inline void Sms_Apu::osc_output( int i, Blip_Buffer* b ) { osc_output( i, b, b, b ); } + +#endif diff --git a/libs/gme/gme/Sms_Oscs.h b/libs/gme/gme/Sms_Oscs.h new file mode 100644 index 000000000..2a896fef3 --- /dev/null +++ b/libs/gme/gme/Sms_Oscs.h @@ -0,0 +1,49 @@ +// Private oscillators used by Sms_Apu + +// Sms_Snd_Emu 0.1.4 +#ifndef SMS_OSCS_H +#define SMS_OSCS_H + +#include "blargg_common.h" +#include "Blip_Buffer.h" + +struct Sms_Osc +{ + Blip_Buffer* outputs [4]; // NULL, right, left, center + Blip_Buffer* output; + int output_select; + + int delay; + int last_amp; + int volume; + + Sms_Osc(); + void reset(); +}; + +struct Sms_Square : Sms_Osc +{ + int period; + int phase; + + typedef Blip_Synth Synth; + const Synth* synth; + + void reset(); + void run( blip_time_t, blip_time_t ); +}; + +struct Sms_Noise : Sms_Osc +{ + const int* period; + unsigned shifter; + unsigned feedback; + + typedef Blip_Synth Synth; + Synth synth; + + void reset(); + void run( blip_time_t, blip_time_t ); +}; + +#endif diff --git a/libs/gme/gme/Snes_Spc.cpp b/libs/gme/gme/Snes_Spc.cpp new file mode 100644 index 000000000..de5585ffc --- /dev/null +++ b/libs/gme/gme/Snes_Spc.cpp @@ -0,0 +1,380 @@ +// SPC emulation support: init, sample buffering, reset, SPC loading + +// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/ + +#include "Snes_Spc.h" + +#include + +/* Copyright (C) 2004-2007 Shay Green. This module 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 +module 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 module; if not, write to the Free Software Foundation, +Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + +#include "blargg_source.h" + +#define RAM (m.ram.ram) +#define REGS (m.smp_regs [0]) +#define REGS_IN (m.smp_regs [1]) + +// (n ? n : 256) +#define IF_0_THEN_256( n ) ((uint8_t) ((n) - 1) + 1) + + +//// Init + +blargg_err_t Snes_Spc::init() +{ + memset( &m, 0, sizeof m ); + dsp.init( RAM ); + + m.tempo = tempo_unit; + + // Most SPC music doesn't need ROM, and almost all the rest only rely + // on these two bytes + m.rom [0x3E] = 0xFF; + m.rom [0x3F] = 0xC0; + + static unsigned char const cycle_table [128] = + {// 01 23 45 67 89 AB CD EF + 0x28,0x47,0x34,0x36,0x26,0x54,0x54,0x68, // 0 + 0x48,0x47,0x45,0x56,0x55,0x65,0x22,0x46, // 1 + 0x28,0x47,0x34,0x36,0x26,0x54,0x54,0x74, // 2 + 0x48,0x47,0x45,0x56,0x55,0x65,0x22,0x38, // 3 + 0x28,0x47,0x34,0x36,0x26,0x44,0x54,0x66, // 4 + 0x48,0x47,0x45,0x56,0x55,0x45,0x22,0x43, // 5 + 0x28,0x47,0x34,0x36,0x26,0x44,0x54,0x75, // 6 + 0x48,0x47,0x45,0x56,0x55,0x55,0x22,0x36, // 7 + 0x28,0x47,0x34,0x36,0x26,0x54,0x52,0x45, // 8 + 0x48,0x47,0x45,0x56,0x55,0x55,0x22,0xC5, // 9 + 0x38,0x47,0x34,0x36,0x26,0x44,0x52,0x44, // A + 0x48,0x47,0x45,0x56,0x55,0x55,0x22,0x34, // B + 0x38,0x47,0x45,0x47,0x25,0x64,0x52,0x49, // C + 0x48,0x47,0x56,0x67,0x45,0x55,0x22,0x83, // D + 0x28,0x47,0x34,0x36,0x24,0x53,0x43,0x40, // E + 0x48,0x47,0x45,0x56,0x34,0x54,0x22,0x60, // F + }; + + // unpack cycle table + for ( int i = 0; i < 128; i++ ) + { + int n = cycle_table [i]; + m.cycle_table [i * 2 + 0] = n >> 4; + m.cycle_table [i * 2 + 1] = n & 0x0F; + } + + #if SPC_LESS_ACCURATE + memcpy( reg_times, reg_times_, sizeof reg_times ); + #endif + + reset(); + return 0; +} + +void Snes_Spc::init_rom( uint8_t const in [rom_size] ) +{ + memcpy( m.rom, in, sizeof m.rom ); +} + +void Snes_Spc::set_tempo( int t ) +{ + m.tempo = t; + int const timer2_shift = 4; // 64 kHz + int const other_shift = 3; // 8 kHz + + #if SPC_DISABLE_TEMPO + m.timers [2].prescaler = timer2_shift; + m.timers [1].prescaler = timer2_shift + other_shift; + m.timers [0].prescaler = timer2_shift + other_shift; + #else + if ( !t ) + t = 1; + int const timer2_rate = 1 << timer2_shift; + int rate = (timer2_rate * tempo_unit + (t >> 1)) / t; + if ( rate < timer2_rate / 4 ) + rate = timer2_rate / 4; // max 4x tempo + m.timers [2].prescaler = rate; + m.timers [1].prescaler = rate << other_shift; + m.timers [0].prescaler = rate << other_shift; + #endif +} + +// Timer registers have been loaded. Applies these to the timers. Does not +// reset timer prescalers or dividers. +void Snes_Spc::timers_loaded() +{ + int i; + for ( i = 0; i < timer_count; i++ ) + { + Timer* t = &m.timers [i]; + t->period = IF_0_THEN_256( REGS [r_t0target + i] ); + t->enabled = REGS [r_control] >> i & 1; + t->counter = REGS_IN [r_t0out + i] & 0x0F; + } + + set_tempo( m.tempo ); +} + +// Loads registers from unified 16-byte format +void Snes_Spc::load_regs( uint8_t const in [reg_count] ) +{ + memcpy( REGS, in, reg_count ); + memcpy( REGS_IN, REGS, reg_count ); + + // These always read back as 0 + REGS_IN [r_test ] = 0; + REGS_IN [r_control ] = 0; + REGS_IN [r_t0target] = 0; + REGS_IN [r_t1target] = 0; + REGS_IN [r_t2target] = 0; +} + +// RAM was just loaded from SPC, with $F0-$FF containing SMP registers +// and timer counts. Copies these to proper registers. +void Snes_Spc::ram_loaded() +{ + m.rom_enabled = 0; + load_regs( &RAM [0xF0] ); + + // Put STOP instruction around memory to catch PC underflow/overflow + memset( m.ram.padding1, cpu_pad_fill, sizeof m.ram.padding1 ); + memset( m.ram.padding2, cpu_pad_fill, sizeof m.ram.padding2 ); +} + +// Registers were just loaded. Applies these new values. +void Snes_Spc::regs_loaded() +{ + enable_rom( REGS [r_control] & 0x80 ); + timers_loaded(); +} + +void Snes_Spc::reset_time_regs() +{ + m.cpu_error = 0; + m.echo_accessed = 0; + m.spc_time = 0; + m.dsp_time = 0; + #if SPC_LESS_ACCURATE + m.dsp_time = clocks_per_sample + 1; + #endif + + for ( int i = 0; i < timer_count; i++ ) + { + Timer* t = &m.timers [i]; + t->next_time = 1; + t->divider = 0; + } + + regs_loaded(); + + m.extra_clocks = 0; + reset_buf(); +} + +void Snes_Spc::reset_common( int timer_counter_init ) +{ + int i; + for ( i = 0; i < timer_count; i++ ) + REGS_IN [r_t0out + i] = timer_counter_init; + + // Run IPL ROM + memset( &m.cpu_regs, 0, sizeof m.cpu_regs ); + m.cpu_regs.pc = rom_addr; + + REGS [r_test ] = 0x0A; + REGS [r_control] = 0xB0; // ROM enabled, clear ports + for ( i = 0; i < port_count; i++ ) + REGS_IN [r_cpuio0 + i] = 0; + + reset_time_regs(); +} + +void Snes_Spc::soft_reset() +{ + reset_common( 0 ); + dsp.soft_reset(); +} + +void Snes_Spc::reset() +{ + memset( RAM, 0xFF, 0x10000 ); + ram_loaded(); + reset_common( 0x0F ); + dsp.reset(); +} + +char const Snes_Spc::signature [signature_size + 1] = + "SNES-SPC700 Sound File Data v0.30\x1A\x1A"; + +blargg_err_t Snes_Spc::load_spc( void const* data, long size ) +{ + spc_file_t const* const spc = (spc_file_t const*) data; + + // be sure compiler didn't insert any padding into fle_t + assert( sizeof (spc_file_t) == spc_min_file_size + 0x80 ); + + // Check signature and file size + if ( size < signature_size || memcmp( spc, signature, 27 ) ) + return "Not an SPC file"; + + if ( size < spc_min_file_size ) + return "Corrupt SPC file"; + + // CPU registers + m.cpu_regs.pc = spc->pch * 0x100 + spc->pcl; + m.cpu_regs.a = spc->a; + m.cpu_regs.x = spc->x; + m.cpu_regs.y = spc->y; + m.cpu_regs.psw = spc->psw; + m.cpu_regs.sp = spc->sp; + + // RAM and registers + memcpy( RAM, spc->ram, 0x10000 ); + ram_loaded(); + + // DSP registers + dsp.load( spc->dsp ); + + reset_time_regs(); + + return 0; +} + +void Snes_Spc::clear_echo() +{ + if ( !(dsp.read( Spc_Dsp::r_flg ) & 0x20) ) + { + int addr = 0x100 * dsp.read( Spc_Dsp::r_esa ); + int end = addr + 0x800 * (dsp.read( Spc_Dsp::r_edl ) & 0x0F); + if ( end > 0x10000 ) + end = 0x10000; + memset( &RAM [addr], 0xFF, end - addr ); + } +} + + +//// Sample output + +void Snes_Spc::reset_buf() +{ + // Start with half extra buffer of silence + sample_t* out = m.extra_buf; + while ( out < &m.extra_buf [extra_size / 2] ) + *out++ = 0; + + m.extra_pos = out; + m.buf_begin = 0; + + dsp.set_output( 0, 0 ); +} + +void Snes_Spc::set_output( sample_t* out, int size ) +{ + require( (size & 1) == 0 ); // size must be even + + m.extra_clocks &= clocks_per_sample - 1; + if ( out ) + { + sample_t const* out_end = out + size; + m.buf_begin = out; + m.buf_end = out_end; + + // Copy extra to output + sample_t const* in = m.extra_buf; + while ( in < m.extra_pos && out < out_end ) + *out++ = *in++; + + // Handle output being full already + if ( out >= out_end ) + { + // Have DSP write to remaining extra space + out = dsp.extra(); + out_end = &dsp.extra() [extra_size]; + + // Copy any remaining extra samples as if DSP wrote them + while ( in < m.extra_pos ) + *out++ = *in++; + assert( out <= out_end ); + } + + dsp.set_output( out, out_end - out ); + } + else + { + reset_buf(); + } +} + +void Snes_Spc::save_extra() +{ + // Get end pointers + sample_t const* main_end = m.buf_end; // end of data written to buf + sample_t const* dsp_end = dsp.out_pos(); // end of data written to dsp.extra() + if ( m.buf_begin <= dsp_end && dsp_end <= main_end ) + { + main_end = dsp_end; + dsp_end = dsp.extra(); // nothing in DSP's extra + } + + // Copy any extra samples at these ends into extra_buf + sample_t* out = m.extra_buf; + sample_t const* in; + for ( in = m.buf_begin + sample_count(); in < main_end; in++ ) + *out++ = *in; + for ( in = dsp.extra(); in < dsp_end ; in++ ) + *out++ = *in; + + m.extra_pos = out; + assert( out <= &m.extra_buf [extra_size] ); +} + +blargg_err_t Snes_Spc::play( int count, sample_t* out ) +{ + require( (count & 1) == 0 ); // must be even + if ( count ) + { + set_output( out, count ); + end_frame( count * (clocks_per_sample / 2) ); + } + + const char* err = m.cpu_error; + m.cpu_error = 0; + return err; +} + +blargg_err_t Snes_Spc::skip( int count ) +{ + #if SPC_LESS_ACCURATE + if ( count > 2 * sample_rate * 2 ) + { + set_output( 0, 0 ); + + // Skip a multiple of 4 samples + time_t end = count; + count = (count & 3) + 1 * sample_rate * 2; + end = (end - count) * (clocks_per_sample / 2); + + m.skipped_kon = 0; + m.skipped_koff = 0; + + // Preserve DSP and timer synchronization + // TODO: verify that this really preserves it + int old_dsp_time = m.dsp_time + m.spc_time; + m.dsp_time = end - m.spc_time + skipping_time; + end_frame( end ); + m.dsp_time = m.dsp_time - skipping_time + old_dsp_time; + + dsp.write( Spc_Dsp::r_koff, m.skipped_koff & ~m.skipped_kon ); + dsp.write( Spc_Dsp::r_kon , m.skipped_kon ); + clear_echo(); + } + #endif + + return play( count, 0 ); +} diff --git a/libs/gme/gme/Snes_Spc.h b/libs/gme/gme/Snes_Spc.h new file mode 100644 index 000000000..d6c4e8135 --- /dev/null +++ b/libs/gme/gme/Snes_Spc.h @@ -0,0 +1,287 @@ +// SNES SPC-700 APU emulator + +// Game_Music_Emu 0.6.0 +#ifndef SNES_SPC_H +#define SNES_SPC_H + +#include "Spc_Dsp.h" +#include "blargg_endian.h" + +struct Snes_Spc { +public: + typedef BOOST::uint8_t uint8_t; + + // Must be called once before using + blargg_err_t init(); + + // Sample pairs generated per second + enum { sample_rate = 32000 }; + +// Emulator use + + // Sets IPL ROM data. Library does not include ROM data. Most SPC music files + // don't need ROM, but a full emulator must provide this. + enum { rom_size = 0x40 }; + void init_rom( uint8_t const rom [rom_size] ); + + // Sets destination for output samples + typedef short sample_t; + void set_output( sample_t* out, int out_size ); + + // Number of samples written to output since last set + int sample_count() const; + + // Resets SPC to power-on state. This resets your output buffer, so you must + // call set_output() after this. + void reset(); + + // Emulates pressing reset switch on SNES. This resets your output buffer, so + // you must call set_output() after this. + void soft_reset(); + + // 1024000 SPC clocks per second, sample pair every 32 clocks + typedef int time_t; + enum { clock_rate = 1024000 }; + enum { clocks_per_sample = 32 }; + + // Emulated port read/write at specified time + enum { port_count = 4 }; + int read_port ( time_t, int port ); + void write_port( time_t, int port, int data ); + + // Runs SPC to end_time and starts a new time frame at 0 + void end_frame( time_t end_time ); + +// Sound control + + // Mutes voices corresponding to non-zero bits in mask (issues repeated KOFF events). + // Reduces emulation accuracy. + enum { voice_count = 8 }; + void mute_voices( int mask ); + + // If true, prevents channels and global volumes from being phase-negated. + // Only supported by fast DSP. + void disable_surround( bool disable = true ); + + // Sets tempo, where tempo_unit = normal, tempo_unit / 2 = half speed, etc. + enum { tempo_unit = 0x100 }; + void set_tempo( int ); + +// SPC music files + + // Loads SPC data into emulator + enum { spc_min_file_size = 0x10180 }; + enum { spc_file_size = 0x10200 }; + blargg_err_t load_spc( void const* in, long size ); + + // Clears echo region. Useful after loading an SPC as many have garbage in echo. + void clear_echo(); + + // Plays for count samples and write samples to out. Discards samples if out + // is NULL. Count must be a multiple of 2 since output is stereo. + blargg_err_t play( int count, sample_t* out ); + + // Skips count samples. Several times faster than play() when using fast DSP. + blargg_err_t skip( int count ); + +// State save/load (only available with accurate DSP) + +#if !SPC_NO_COPY_STATE_FUNCS + // Saves/loads state + enum { state_size = 67 * 1024L }; // maximum space needed when saving + typedef Spc_Dsp::copy_func_t copy_func_t; + void copy_state( unsigned char** io, copy_func_t ); + + // Writes minimal header to spc_out + static void init_header( void* spc_out ); + + // Saves emulator state as SPC file data. Writes spc_file_size bytes to spc_out. + // Does not set up SPC header; use init_header() for that. + void save_spc( void* spc_out ); + + // Returns true if new key-on events occurred since last check. Useful for + // trimming silence while saving an SPC. + bool check_kon(); +#endif + +public: + // TODO: document + struct regs_t + { + int pc; + int a; + int x; + int y; + int psw; + int sp; + }; + regs_t& smp_regs() { return m.cpu_regs; } + + uint8_t* smp_ram() { return m.ram.ram; } + + void run_until( time_t t ) { run_until_( t ); } +public: + BLARGG_DISABLE_NOTHROW + + typedef BOOST::uint16_t uint16_t; + + // Time relative to m_spc_time. Speeds up code a bit by eliminating need to + // constantly add m_spc_time to time from CPU. CPU uses time that ends at + // 0 to eliminate reloading end time every instruction. It pays off. + typedef int rel_time_t; + + struct Timer + { + rel_time_t next_time; // time of next event + int prescaler; + int period; + int divider; + int enabled; + int counter; + }; + enum { reg_count = 0x10 }; + enum { timer_count = 3 }; + enum { extra_size = Spc_Dsp::extra_size }; + + enum { signature_size = 35 }; + +private: + Spc_Dsp dsp; + + #if SPC_LESS_ACCURATE + static signed char const reg_times_ [256]; + signed char reg_times [256]; + #endif + + struct state_t + { + Timer timers [timer_count]; + + uint8_t smp_regs [2] [reg_count]; + + regs_t cpu_regs; + + rel_time_t dsp_time; + time_t spc_time; + bool echo_accessed; + + int tempo; + int skipped_kon; + int skipped_koff; + const char* cpu_error; + + int extra_clocks; + sample_t* buf_begin; + sample_t const* buf_end; + sample_t* extra_pos; + sample_t extra_buf [extra_size]; + + int rom_enabled; + uint8_t rom [rom_size]; + uint8_t hi_ram [rom_size]; + + unsigned char cycle_table [256]; + + struct + { + // padding to neutralize address overflow + union { + uint8_t padding1 [0x100]; + uint16_t align; // makes compiler align data for 16-bit access + } padding1 [1]; + uint8_t ram [0x10000]; + uint8_t padding2 [0x100]; + } ram; + }; + state_t m; + + enum { rom_addr = 0xFFC0 }; + + enum { skipping_time = 127 }; + + // Value that padding should be filled with + enum { cpu_pad_fill = 0xFF }; + + enum { + r_test = 0x0, r_control = 0x1, + r_dspaddr = 0x2, r_dspdata = 0x3, + r_cpuio0 = 0x4, r_cpuio1 = 0x5, + r_cpuio2 = 0x6, r_cpuio3 = 0x7, + r_f8 = 0x8, r_f9 = 0x9, + r_t0target = 0xA, r_t1target = 0xB, r_t2target = 0xC, + r_t0out = 0xD, r_t1out = 0xE, r_t2out = 0xF + }; + + void timers_loaded(); + void enable_rom( int enable ); + void reset_buf(); + void save_extra(); + void load_regs( uint8_t const in [reg_count] ); + void ram_loaded(); + void regs_loaded(); + void reset_time_regs(); + void reset_common( int timer_counter_init ); + + Timer* run_timer_ ( Timer* t, rel_time_t ); + Timer* run_timer ( Timer* t, rel_time_t ); + int dsp_read ( rel_time_t ); + void dsp_write ( int data, rel_time_t ); + void cpu_write_smp_reg_( int data, rel_time_t, int addr ); + void cpu_write_smp_reg ( int data, rel_time_t, int addr ); + void cpu_write_high ( int data, int i, rel_time_t ); + void cpu_write ( int data, int addr, rel_time_t ); + int cpu_read_smp_reg ( int i, rel_time_t ); + int cpu_read ( int addr, rel_time_t ); + unsigned CPU_mem_bit ( uint8_t const* pc, rel_time_t ); + + bool check_echo_access ( int addr ); + uint8_t* run_until_( time_t end_time ); + + struct spc_file_t + { + char signature [signature_size]; + uint8_t has_id666; + uint8_t version; + uint8_t pcl, pch; + uint8_t a; + uint8_t x; + uint8_t y; + uint8_t psw; + uint8_t sp; + char text [212]; + uint8_t ram [0x10000]; + uint8_t dsp [128]; + uint8_t unused [0x40]; + uint8_t ipl_rom [0x40]; + }; + + static char const signature [signature_size + 1]; + + void save_regs( uint8_t out [reg_count] ); +}; + +#include + +inline int Snes_Spc::sample_count() const { return (m.extra_clocks >> 5) * 2; } + +inline int Snes_Spc::read_port( time_t t, int port ) +{ + assert( (unsigned) port < port_count ); + return run_until_( t ) [port]; +} + +inline void Snes_Spc::write_port( time_t t, int port, int data ) +{ + assert( (unsigned) port < port_count ); + run_until_( t ) [0x10 + port] = data; +} + +inline void Snes_Spc::mute_voices( int mask ) { dsp.mute_voices( mask ); } + +inline void Snes_Spc::disable_surround( bool disable ) { dsp.disable_surround( disable ); } + +#if !SPC_NO_COPY_STATE_FUNCS +inline bool Snes_Spc::check_kon() { return dsp.check_kon(); } +#endif + +#endif diff --git a/libs/gme/gme/Spc_Cpu.cpp b/libs/gme/gme/Spc_Cpu.cpp new file mode 100644 index 000000000..90f60ed29 --- /dev/null +++ b/libs/gme/gme/Spc_Cpu.cpp @@ -0,0 +1,565 @@ +// Core SPC emulation: CPU, timers, SMP registers, memory + +// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/ + +#include "Snes_Spc.h" + +#include + +/* Copyright (C) 2004-2007 Shay Green. This module 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 +module 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 module; if not, write to the Free Software Foundation, +Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + +#include "blargg_source.h" + +#define RAM (m.ram.ram) +#define REGS (m.smp_regs [0]) +#define REGS_IN (m.smp_regs [1]) + +// (n ? n : 256) +#define IF_0_THEN_256( n ) ((uint8_t) ((n) - 1) + 1) + +// Note: SPC_MORE_ACCURACY exists mainly so I can run my validation tests, which +// do crazy echo buffer accesses. +#ifndef SPC_MORE_ACCURACY + #define SPC_MORE_ACCURACY 0 +#endif + +#ifdef BLARGG_ENABLE_OPTIMIZER + #include BLARGG_ENABLE_OPTIMIZER +#endif + + +//// Timers + +#if SPC_DISABLE_TEMPO + #define TIMER_DIV( t, n ) ((n) >> t->prescaler) + #define TIMER_MUL( t, n ) ((n) << t->prescaler) +#else + #define TIMER_DIV( t, n ) ((n) / t->prescaler) + #define TIMER_MUL( t, n ) ((n) * t->prescaler) +#endif + +Snes_Spc::Timer* Snes_Spc::run_timer_( Timer* t, rel_time_t time ) +{ + int elapsed = TIMER_DIV( t, time - t->next_time ) + 1; + t->next_time += TIMER_MUL( t, elapsed ); + + if ( t->enabled ) + { + int remain = IF_0_THEN_256( t->period - t->divider ); + int divider = t->divider + elapsed; + int over = elapsed - remain; + if ( over >= 0 ) + { + int n = over / t->period; + t->counter = (t->counter + 1 + n) & 0x0F; + divider = over - n * t->period; + } + t->divider = (uint8_t) divider; + } + return t; +} + +inline Snes_Spc::Timer* Snes_Spc::run_timer( Timer* t, rel_time_t time ) +{ + if ( time >= t->next_time ) + t = run_timer_( t, time ); + return t; +} + + +//// ROM + +void Snes_Spc::enable_rom( int enable ) +{ + if ( m.rom_enabled != enable ) + { + m.rom_enabled = enable; + if ( enable ) + memcpy( m.hi_ram, &RAM [rom_addr], sizeof m.hi_ram ); + memcpy( &RAM [rom_addr], (enable ? m.rom : m.hi_ram), rom_size ); + // TODO: ROM can still get overwritten when DSP writes to echo buffer + } +} + + +//// DSP + +#if SPC_LESS_ACCURATE + int const max_reg_time = 29; + + signed char const Snes_Spc::reg_times_ [256] = + { + -1, 0,-11,-10,-15,-11, -2, -2, 4, 3, 14, 14, 26, 26, 14, 22, + 2, 3, 0, 1,-12, 0, 1, 1, 7, 6, 14, 14, 27, 14, 14, 23, + 5, 6, 3, 4, -1, 3, 4, 4, 10, 9, 14, 14, 26, -5, 14, 23, + 8, 9, 6, 7, 2, 6, 7, 7, 13, 12, 14, 14, 27, -4, 14, 24, + 11, 12, 9, 10, 5, 9, 10, 10, 16, 15, 14, 14, -2, -4, 14, 24, + 14, 15, 12, 13, 8, 12, 13, 13, 19, 18, 14, 14, -2,-36, 14, 24, + 17, 18, 15, 16, 11, 15, 16, 16, 22, 21, 14, 14, 28, -3, 14, 25, + 20, 21, 18, 19, 14, 18, 19, 19, 25, 24, 14, 14, 14, 29, 14, 25, + + 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, + 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, + 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, + 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, + 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, + 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, + 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, + 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, + }; + + #define RUN_DSP( time, offset ) \ + int count = (time) - (offset) - m.dsp_time;\ + if ( count >= 0 )\ + {\ + int clock_count = (count & ~(clocks_per_sample - 1)) + clocks_per_sample;\ + m.dsp_time += clock_count;\ + dsp.run( clock_count );\ + } +#else + #define RUN_DSP( time, offset ) \ + {\ + int count = (time) - m.dsp_time;\ + if ( !SPC_MORE_ACCURACY || count )\ + {\ + assert( count > 0 );\ + m.dsp_time = (time);\ + dsp.run( count );\ + }\ + } +#endif + +int Snes_Spc::dsp_read( rel_time_t time ) +{ + RUN_DSP( time, reg_times [REGS [r_dspaddr] & 0x7F] ); + + int result = dsp.read( REGS [r_dspaddr] & 0x7F ); + + #ifdef SPC_DSP_READ_HOOK + SPC_DSP_READ_HOOK( spc_time + time, (REGS [r_dspaddr] & 0x7F), result ); + #endif + + return result; +} + +inline void Snes_Spc::dsp_write( int data, rel_time_t time ) +{ + RUN_DSP( time, reg_times [REGS [r_dspaddr]] ) + #if SPC_LESS_ACCURATE + else if ( m.dsp_time == skipping_time ) + { + int r = REGS [r_dspaddr]; + if ( r == Spc_Dsp::r_kon ) + m.skipped_kon |= data & ~dsp.read( Spc_Dsp::r_koff ); + + if ( r == Spc_Dsp::r_koff ) + { + m.skipped_koff |= data; + m.skipped_kon &= ~data; + } + } + #endif + + #ifdef SPC_DSP_WRITE_HOOK + SPC_DSP_WRITE_HOOK( m.spc_time + time, REGS [r_dspaddr], (uint8_t) data ); + #endif + + if ( REGS [r_dspaddr] <= 0x7F ) + dsp.write( REGS [r_dspaddr], data ); + else if ( !SPC_MORE_ACCURACY ) + debug_printf( "SPC wrote to DSP register > $7F\n" ); +} + + +//// Memory access extras + +#if SPC_MORE_ACCURACY + #define MEM_ACCESS( time, addr ) \ + {\ + if ( time >= m.dsp_time )\ + {\ + RUN_DSP( time, max_reg_time );\ + }\ + } +#elif !defined (NDEBUG) + // Debug-only check for read/write within echo buffer, since this might result in + // inaccurate emulation due to the DSP not being caught up to the present. + + bool Snes_Spc::check_echo_access( int addr ) + { + if ( !(dsp.read( Spc_Dsp::r_flg ) & 0x20) ) + { + int start = 0x100 * dsp.read( Spc_Dsp::r_esa ); + int size = 0x800 * (dsp.read( Spc_Dsp::r_edl ) & 0x0F); + int end = start + (size ? size : 4); + if ( start <= addr && addr < end ) + { + if ( !m.echo_accessed ) + { + m.echo_accessed = 1; + return true; + } + } + } + return false; + } + + #define MEM_ACCESS( time, addr ) check( !check_echo_access( (uint16_t) addr ) ); +#else + #define MEM_ACCESS( time, addr ) +#endif + + +//// CPU write + +#if SPC_MORE_ACCURACY +static unsigned char const glitch_probs [3] [256] = +{ + 0xC3,0x92,0x5B,0x1C,0xD1,0x92,0x5B,0x1C,0xDB,0x9C,0x72,0x18,0xCD,0x5C,0x38,0x0B, + 0xE1,0x9C,0x74,0x17,0xCF,0x75,0x45,0x0C,0xCF,0x6E,0x4A,0x0D,0xA3,0x3A,0x1D,0x08, + 0xDB,0xA0,0x82,0x19,0xD9,0x73,0x3C,0x0E,0xCB,0x76,0x52,0x0B,0xA5,0x46,0x1D,0x09, + 0xDA,0x74,0x55,0x0F,0xA2,0x3F,0x21,0x05,0x9A,0x40,0x20,0x07,0x63,0x1E,0x10,0x01, + 0xDF,0xA9,0x85,0x1D,0xD3,0x84,0x4B,0x0E,0xCF,0x6F,0x49,0x0F,0xB3,0x48,0x1E,0x05, + 0xD8,0x77,0x52,0x12,0xB7,0x49,0x23,0x06,0xAA,0x45,0x28,0x07,0x7D,0x28,0x0F,0x07, + 0xCC,0x7B,0x4A,0x0E,0xB2,0x4F,0x24,0x07,0xAD,0x43,0x2C,0x06,0x86,0x29,0x11,0x07, + 0xAE,0x48,0x1F,0x0A,0x76,0x21,0x19,0x05,0x76,0x21,0x14,0x05,0x44,0x11,0x0B,0x01, + 0xE7,0xAD,0x96,0x23,0xDC,0x86,0x59,0x0E,0xDC,0x7C,0x5F,0x15,0xBB,0x53,0x2E,0x09, + 0xD6,0x7C,0x4A,0x16,0xBB,0x4A,0x25,0x08,0xB3,0x4F,0x28,0x0B,0x8E,0x23,0x15,0x08, + 0xCF,0x7F,0x57,0x11,0xB5,0x4A,0x23,0x0A,0xAA,0x42,0x28,0x05,0x7D,0x22,0x12,0x03, + 0xA6,0x49,0x28,0x09,0x82,0x2B,0x0D,0x04,0x7A,0x20,0x0F,0x04,0x3D,0x0F,0x09,0x03, + 0xD1,0x7C,0x4C,0x0F,0xAF,0x4E,0x21,0x09,0xA8,0x46,0x2A,0x07,0x85,0x1F,0x0E,0x07, + 0xA6,0x3F,0x26,0x07,0x7C,0x24,0x14,0x07,0x78,0x22,0x16,0x04,0x46,0x12,0x0A,0x02, + 0xA6,0x41,0x2C,0x0A,0x7E,0x28,0x11,0x05,0x73,0x1B,0x14,0x05,0x3D,0x11,0x0A,0x02, + 0x70,0x22,0x17,0x05,0x48,0x13,0x08,0x03,0x3C,0x07,0x0D,0x07,0x26,0x07,0x06,0x01, + + 0xE0,0x9F,0xDA,0x7C,0x4F,0x18,0x28,0x0D,0xE9,0x9F,0xDA,0x7C,0x4F,0x18,0x1F,0x07, + 0xE6,0x97,0xD8,0x72,0x64,0x13,0x26,0x09,0xDC,0x67,0xA9,0x38,0x21,0x07,0x15,0x06, + 0xE9,0x91,0xD2,0x6B,0x63,0x14,0x2B,0x0E,0xD6,0x61,0xB7,0x41,0x2B,0x0E,0x10,0x09, + 0xCF,0x59,0xB0,0x2F,0x35,0x08,0x0F,0x07,0xB6,0x30,0x7A,0x21,0x17,0x07,0x09,0x03, + 0xE7,0xA3,0xE5,0x6B,0x65,0x1F,0x34,0x09,0xD8,0x6B,0xBE,0x45,0x27,0x07,0x10,0x07, + 0xDA,0x54,0xB1,0x39,0x2E,0x0E,0x17,0x08,0xA9,0x3C,0x86,0x22,0x16,0x06,0x07,0x03, + 0xD4,0x51,0xBC,0x3D,0x38,0x0A,0x13,0x06,0xB2,0x37,0x79,0x1C,0x17,0x05,0x0E,0x06, + 0xA7,0x31,0x74,0x1C,0x11,0x06,0x0C,0x02,0x6D,0x1A,0x38,0x10,0x0B,0x05,0x06,0x03, + 0xEB,0x9A,0xE1,0x7A,0x6F,0x13,0x34,0x0E,0xE6,0x75,0xC5,0x45,0x3E,0x0B,0x1A,0x05, + 0xD8,0x63,0xC1,0x40,0x3C,0x1B,0x19,0x06,0xB3,0x42,0x83,0x29,0x18,0x0A,0x08,0x04, + 0xD4,0x58,0xBA,0x43,0x3F,0x0A,0x1F,0x09,0xB1,0x33,0x8A,0x1F,0x1F,0x06,0x0D,0x05, + 0xAF,0x3C,0x7A,0x1F,0x16,0x08,0x0A,0x01,0x72,0x1B,0x52,0x0D,0x0B,0x09,0x06,0x01, + 0xCF,0x63,0xB7,0x47,0x40,0x10,0x14,0x06,0xC0,0x41,0x96,0x20,0x1C,0x09,0x10,0x05, + 0xA6,0x35,0x82,0x1A,0x20,0x0C,0x0E,0x04,0x80,0x1F,0x53,0x0F,0x0B,0x02,0x06,0x01, + 0xA6,0x31,0x81,0x1B,0x1D,0x01,0x08,0x08,0x7B,0x20,0x4D,0x19,0x0E,0x05,0x07,0x03, + 0x6B,0x17,0x49,0x07,0x0E,0x03,0x0A,0x05,0x37,0x0B,0x1F,0x06,0x04,0x02,0x07,0x01, + + 0xF0,0xD6,0xED,0xAD,0xEC,0xB1,0xEB,0x79,0xAC,0x22,0x47,0x1E,0x6E,0x1B,0x32,0x0A, + 0xF0,0xD6,0xEA,0xA4,0xED,0xC4,0xDE,0x82,0x98,0x1F,0x50,0x13,0x52,0x15,0x2A,0x0A, + 0xF1,0xD1,0xEB,0xA2,0xEB,0xB7,0xD8,0x69,0xA2,0x1F,0x5B,0x18,0x55,0x18,0x2C,0x0A, + 0xED,0xB5,0xDE,0x7E,0xE6,0x85,0xD3,0x59,0x59,0x0F,0x2C,0x09,0x24,0x07,0x15,0x09, + 0xF1,0xD6,0xEA,0xA0,0xEC,0xBB,0xDA,0x77,0xA9,0x23,0x58,0x14,0x5D,0x12,0x2F,0x09, + 0xF1,0xC1,0xE3,0x86,0xE4,0x87,0xD2,0x4E,0x68,0x15,0x26,0x0B,0x27,0x09,0x15,0x02, + 0xEE,0xA6,0xE0,0x5C,0xE0,0x77,0xC3,0x41,0x67,0x1B,0x3C,0x07,0x2A,0x06,0x19,0x07, + 0xE4,0x75,0xC6,0x43,0xCC,0x50,0x95,0x23,0x35,0x09,0x14,0x04,0x15,0x05,0x0B,0x04, + 0xEE,0xD6,0xED,0xAD,0xEC,0xB1,0xEB,0x79,0xAC,0x22,0x56,0x14,0x5A,0x12,0x26,0x0A, + 0xEE,0xBB,0xE7,0x7E,0xE9,0x8D,0xCB,0x49,0x67,0x11,0x34,0x07,0x2B,0x0B,0x14,0x07, + 0xED,0xA7,0xE5,0x76,0xE3,0x7E,0xC4,0x4B,0x77,0x14,0x34,0x08,0x27,0x07,0x14,0x04, + 0xE7,0x8B,0xD2,0x4C,0xCA,0x56,0x9E,0x31,0x36,0x0C,0x11,0x07,0x14,0x04,0x0A,0x02, + 0xF0,0x9B,0xEA,0x6F,0xE5,0x81,0xC4,0x43,0x74,0x10,0x30,0x0B,0x2D,0x08,0x1B,0x06, + 0xE6,0x83,0xCA,0x48,0xD9,0x56,0xA7,0x23,0x3B,0x09,0x12,0x09,0x15,0x07,0x0A,0x03, + 0xE5,0x5F,0xCB,0x3C,0xCF,0x48,0x91,0x22,0x31,0x0A,0x17,0x08,0x15,0x04,0x0D,0x02, + 0xD1,0x43,0x91,0x20,0xA9,0x2D,0x54,0x12,0x17,0x07,0x09,0x02,0x0C,0x04,0x05,0x03, +}; +#endif + +// Read/write handlers are divided into multiple functions to keep rarely-used +// functionality separate so often-used functionality can be optimized better +// by compiler. + +// If write isn't preceded by read, data has this added to it +int const no_read_before_write = 0x2000; + +void Snes_Spc::cpu_write_smp_reg_( int data, rel_time_t time, int addr ) +{ + switch ( addr ) + { + case r_t0target: + case r_t1target: + case r_t2target: { + Timer* t = &m.timers [addr - r_t0target]; + int period = IF_0_THEN_256( data ); + if ( t->period != period ) + { + t = run_timer( t, time ); + #if SPC_MORE_ACCURACY + // Insane behavior when target is written just after counter is + // clocked and counter matches new period and new period isn't 1, 2, 4, or 8 + if ( t->divider == (period & 0xFF) && + t->next_time == time + TIMER_MUL( t, 1 ) && + ((period - 1) | ~0x0F) & period ) + { + //debug_printf( "SPC pathological timer target write\n" ); + + // If the period is 3, 5, or 9, there's a probability this behavior won't occur, + // based on the previous period + int prob = 0xFF; + int old_period = t->period & 0xFF; + if ( period == 3 ) prob = glitch_probs [0] [old_period]; + if ( period == 5 ) prob = glitch_probs [1] [old_period]; + if ( period == 9 ) prob = glitch_probs [2] [old_period]; + + // The glitch suppresses incrementing of one of the counter bits, based on + // the lowest set bit in the new period + int b = 1; + while ( !(period & b) ) + b <<= 1; + + if ( (rand() >> 4 & 0xFF) <= prob ) + t->divider = (t->divider - b) & 0xFF; + } + #endif + t->period = period; + } + break; + } + + case r_t0out: + case r_t1out: + case r_t2out: + if ( !SPC_MORE_ACCURACY ) + debug_printf( "SPC wrote to counter %d\n", (int) addr - r_t0out ); + + if ( data < no_read_before_write / 2 ) + run_timer( &m.timers [addr - r_t0out], time - 1 )->counter = 0; + break; + + // Registers that act like RAM + case 0x8: + case 0x9: + REGS_IN [addr] = (uint8_t) data; + break; + + case r_test: + if ( (uint8_t) data != 0x0A ) + debug_printf( "SPC wrote to test register\n" ); + break; + + case r_control: + // port clears + if ( data & 0x10 ) + { + REGS_IN [r_cpuio0] = 0; + REGS_IN [r_cpuio1] = 0; + } + if ( data & 0x20 ) + { + REGS_IN [r_cpuio2] = 0; + REGS_IN [r_cpuio3] = 0; + } + + // timers + { + for ( int i = 0; i < timer_count; i++ ) + { + Timer* t = &m.timers [i]; + int enabled = data >> i & 1; + if ( t->enabled != enabled ) + { + t = run_timer( t, time ); + t->enabled = enabled; + if ( enabled ) + { + t->divider = 0; + t->counter = 0; + } + } + } + } + enable_rom( data & 0x80 ); + break; + } +} + +void Snes_Spc::cpu_write_smp_reg( int data, rel_time_t time, int addr ) +{ + if ( addr == r_dspdata ) // 99% + dsp_write( data, time ); + else + cpu_write_smp_reg_( data, time, addr ); +} + +void Snes_Spc::cpu_write_high( int data, int i, rel_time_t time ) +{ + if ( i < rom_size ) + { + m.hi_ram [i] = (uint8_t) data; + if ( m.rom_enabled ) + RAM [i + rom_addr] = m.rom [i]; // restore overwritten ROM + } + else + { + assert( RAM [i + rom_addr] == (uint8_t) data ); + RAM [i + rom_addr] = cpu_pad_fill; // restore overwritten padding + cpu_write( data, i + rom_addr - 0x10000, time ); + } +} + +int const bits_in_int = CHAR_BIT * sizeof (int); + +void Snes_Spc::cpu_write( int data, int addr, rel_time_t time ) +{ + MEM_ACCESS( time, addr ) + + // RAM + RAM [addr] = (uint8_t) data; + int reg = addr - 0xF0; + if ( reg >= 0 ) // 64% + { + // $F0-$FF + if ( reg < reg_count ) // 87% + { + REGS [reg] = (uint8_t) data; + + // Ports + #ifdef SPC_PORT_WRITE_HOOK + if ( (unsigned) (reg - r_cpuio0) < port_count ) + SPC_PORT_WRITE_HOOK( m.spc_time + time, (reg - r_cpuio0), + (uint8_t) data, ®S [r_cpuio0] ); + #endif + + // Registers other than $F2 and $F4-$F7 + //if ( reg != 2 && reg != 4 && reg != 5 && reg != 6 && reg != 7 ) + // TODO: this is a bit on the fragile side + if ( ((~0x2F00 << (bits_in_int - 16)) << reg) < 0 ) // 36% + cpu_write_smp_reg( data, time, reg ); + } + // High mem/address wrap-around + else + { + reg -= rom_addr - 0xF0; + if ( reg >= 0 ) // 1% in IPL ROM area or address wrapped around + cpu_write_high( data, reg, time ); + } + } +} + + +//// CPU read + +inline int Snes_Spc::cpu_read_smp_reg( int reg, rel_time_t time ) +{ + int result = REGS_IN [reg]; + reg -= r_dspaddr; + // DSP addr and data + if ( (unsigned) reg <= 1 ) // 4% 0xF2 and 0xF3 + { + result = REGS [r_dspaddr]; + if ( (unsigned) reg == 1 ) + result = dsp_read( time ); // 0xF3 + } + return result; +} + +int Snes_Spc::cpu_read( int addr, rel_time_t time ) +{ + MEM_ACCESS( time, addr ) + + // RAM + int result = RAM [addr]; + int reg = addr - 0xF0; + if ( reg >= 0 ) // 40% + { + reg -= 0x10; + if ( (unsigned) reg >= 0xFF00 ) // 21% + { + reg += 0x10 - r_t0out; + + // Timers + if ( (unsigned) reg < timer_count ) // 90% + { + Timer* t = &m.timers [reg]; + if ( time >= t->next_time ) + t = run_timer_( t, time ); + result = t->counter; + t->counter = 0; + } + // Other registers + else if ( reg < 0 ) // 10% + { + result = cpu_read_smp_reg( reg + r_t0out, time ); + } + else // 1% + { + assert( reg + (r_t0out + 0xF0 - 0x10000) < 0x100 ); + result = cpu_read( reg + (r_t0out + 0xF0 - 0x10000), time ); + } + } + } + + return result; +} + + +//// Run + +// Prefix and suffix for CPU emulator function +#define SPC_CPU_RUN_FUNC \ +BOOST::uint8_t* Snes_Spc::run_until_( time_t end_time )\ +{\ + rel_time_t rel_time = m.spc_time - end_time;\ + assert( rel_time <= 0 );\ + m.spc_time = end_time;\ + m.dsp_time += rel_time;\ + m.timers [0].next_time += rel_time;\ + m.timers [1].next_time += rel_time;\ + m.timers [2].next_time += rel_time; + +#define SPC_CPU_RUN_FUNC_END \ + m.spc_time += rel_time;\ + m.dsp_time -= rel_time;\ + m.timers [0].next_time -= rel_time;\ + m.timers [1].next_time -= rel_time;\ + m.timers [2].next_time -= rel_time;\ + assert( m.spc_time <= end_time );\ + return ®S [r_cpuio0];\ +} + +int const cpu_lag_max = 12 - 1; // DIV YA,X takes 12 clocks + +void Snes_Spc::end_frame( time_t end_time ) +{ + // Catch CPU up to as close to end as possible. If final instruction + // would exceed end, does NOT execute it and leaves m.spc_time < end. + if ( end_time > m.spc_time ) + run_until_( end_time ); + + m.spc_time -= end_time; + m.extra_clocks += end_time; + + // Greatest number of clocks early that emulation can stop early due to + // not being able to execute current instruction without going over + // allowed time. + assert( -cpu_lag_max <= m.spc_time && m.spc_time <= 0 ); + + // Catch timers up to CPU + for ( int i = 0; i < timer_count; i++ ) + run_timer( &m.timers [i], 0 ); + + // Catch DSP up to CPU + if ( m.dsp_time < 0 ) + { + RUN_DSP( 0, max_reg_time ); + } + + // Save any extra samples beyond what should be generated + if ( m.buf_begin ) + save_extra(); +} + +// Inclusion here allows static memory access functions and better optimization +#include "Spc_Cpu.h" diff --git a/libs/gme/gme/Spc_Cpu.h b/libs/gme/gme/Spc_Cpu.h new file mode 100644 index 000000000..4742e0990 --- /dev/null +++ b/libs/gme/gme/Spc_Cpu.h @@ -0,0 +1,1220 @@ +// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/ + +/* Copyright (C) 2004-2007 Shay Green. This module 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 +module 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 module; if not, write to the Free Software Foundation, +Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + +//// Memory access + +#if SPC_MORE_ACCURACY + #define SUSPICIOUS_OPCODE( name ) ((void) 0) +#else + #define SUSPICIOUS_OPCODE( name ) debug_printf( "SPC: suspicious opcode: " name "\n" ) +#endif + +#define CPU_READ( time, offset, addr )\ + cpu_read( addr, time + offset ) + +#define CPU_WRITE( time, offset, addr, data )\ + cpu_write( data, addr, time + offset ) + +#if SPC_MORE_ACCURACY + #define CPU_READ_TIMER( time, offset, addr, out )\ + { out = CPU_READ( time, offset, addr ); } + +#else + // timers are by far the most common thing read from dp + #define CPU_READ_TIMER( time, offset, addr_, out )\ + {\ + rel_time_t adj_time = time + offset;\ + int dp_addr = addr_;\ + int ti = dp_addr - (r_t0out + 0xF0);\ + if ( (unsigned) ti < timer_count )\ + {\ + Timer* t = &m.timers [ti];\ + if ( adj_time >= t->next_time )\ + t = run_timer_( t, adj_time );\ + out = t->counter;\ + t->counter = 0;\ + }\ + else\ + {\ + out = ram [dp_addr];\ + int i = dp_addr - 0xF0;\ + if ( (unsigned) i < 0x10 )\ + out = cpu_read_smp_reg( i, adj_time );\ + }\ + } +#endif + +#define TIME_ADJ( n ) (n) + +#define READ_TIMER( time, addr, out ) CPU_READ_TIMER( rel_time, TIME_ADJ(time), (addr), out ) +#define READ( time, addr ) CPU_READ ( rel_time, TIME_ADJ(time), (addr) ) +#define WRITE( time, addr, data ) CPU_WRITE( rel_time, TIME_ADJ(time), (addr), (data) ) + +#define DP_ADDR( addr ) (dp + (addr)) + +#define READ_DP_TIMER( time, addr, out ) CPU_READ_TIMER( rel_time, TIME_ADJ(time), DP_ADDR( addr ), out ) +#define READ_DP( time, addr ) READ ( time, DP_ADDR( addr ) ) +#define WRITE_DP( time, addr, data ) WRITE( time, DP_ADDR( addr ), data ) + +#define READ_PROG16( addr ) GET_LE16( ram + (addr) ) + +#define SET_PC( n ) (pc = ram + (n)) +#define GET_PC() (pc - ram) +#define READ_PC( pc ) (*(pc)) +#define READ_PC16( pc ) GET_LE16( pc ) + +// TODO: remove non-wrapping versions? +#define SPC_NO_SP_WRAPAROUND 0 + +#define SET_SP( v ) (sp = ram + 0x101 + (v)) +#define GET_SP() (sp - 0x101 - ram) + +#if SPC_NO_SP_WRAPAROUND +#define PUSH16( v ) (sp -= 2, SET_LE16( sp, v )) +#define PUSH( v ) (void) (*--sp = (uint8_t) (v)) +#define POP( out ) (void) ((out) = *sp++) + +#else +#define PUSH16( data )\ +{\ + int addr = (sp -= 2) - ram;\ + if ( addr > 0x100 )\ + {\ + SET_LE16( sp, data );\ + }\ + else\ + {\ + ram [(uint8_t) addr + 0x100] = (uint8_t) data;\ + sp [1] = (uint8_t) (data >> 8);\ + sp += 0x100;\ + }\ +} + +#define PUSH( data )\ +{\ + *--sp = (uint8_t) (data);\ + if ( sp - ram == 0x100 )\ + sp += 0x100;\ +} + +#define POP( out )\ +{\ + out = *sp++;\ + if ( sp - ram == 0x201 )\ + {\ + out = sp [-0x101];\ + sp -= 0x100;\ + }\ +} + +#endif + +#define MEM_BIT( rel ) CPU_mem_bit( pc, rel_time + rel ) + +unsigned Snes_Spc::CPU_mem_bit( uint8_t const* pc, rel_time_t rel_time ) +{ + unsigned addr = READ_PC16( pc ); + unsigned t = READ( 0, addr & 0x1FFF ) >> (addr >> 13); + return t << 8 & 0x100; +} + +//// Status flag handling + +// Hex value in name to clarify code and bit shifting. +// Flag stored in indicated variable during emulation +int const n80 = 0x80; // nz +int const v40 = 0x40; // psw +int const p20 = 0x20; // dp +int const b10 = 0x10; // psw +int const h08 = 0x08; // psw +int const i04 = 0x04; // psw +int const z02 = 0x02; // nz +int const c01 = 0x01; // c + +int const nz_neg_mask = 0x880; // either bit set indicates N flag set + +#define GET_PSW( out )\ +{\ + out = psw & ~(n80 | p20 | z02 | c01);\ + out |= c >> 8 & c01;\ + out |= dp >> 3 & p20;\ + out |= ((nz >> 4) | nz) & n80;\ + if ( !(uint8_t) nz ) out |= z02;\ +} + +#define SET_PSW( in )\ +{\ + psw = in;\ + c = in << 8;\ + dp = in << 3 & 0x100;\ + nz = (in << 4 & 0x800) | (~in & z02);\ +} + +SPC_CPU_RUN_FUNC +{ + uint8_t* const ram = RAM; + int a = m.cpu_regs.a; + int x = m.cpu_regs.x; + int y = m.cpu_regs.y; + uint8_t const* pc; + uint8_t* sp; + int psw; + int c; + int nz; + int dp; + + SET_PC( m.cpu_regs.pc ); + SET_SP( m.cpu_regs.sp ); + SET_PSW( m.cpu_regs.psw ); + + goto loop; + + + // Main loop + +cbranch_taken_loop: + pc += *(BOOST::int8_t const*) pc; +inc_pc_loop: + pc++; +loop: +{ + unsigned opcode; + unsigned data; + + check( (unsigned) a < 0x100 ); + check( (unsigned) x < 0x100 ); + check( (unsigned) y < 0x100 ); + + opcode = *pc; + if ( (rel_time += m.cycle_table [opcode]) > 0 ) + goto out_of_time; + + #ifdef SPC_CPU_OPCODE_HOOK + SPC_CPU_OPCODE_HOOK( GET_PC(), opcode ); + #endif + /* + //SUB_CASE_COUNTER( 1 ); + #define PROFILE_TIMER_LOOP( op, addr, len )\ + if ( opcode == op )\ + {\ + int cond = (unsigned) ((addr) - 0xFD) < 3 &&\ + pc [len] == 0xF0 && pc [len+1] == 0xFE - len;\ + SUB_CASE_COUNTER( op && cond );\ + } + + PROFILE_TIMER_LOOP( 0xEC, GET_LE16( pc + 1 ), 3 ); + PROFILE_TIMER_LOOP( 0xEB, pc [1], 2 ); + PROFILE_TIMER_LOOP( 0xE4, pc [1], 2 ); + */ + + // TODO: if PC is at end of memory, this will get wrong operand (very obscure) + data = *++pc; + switch ( opcode ) + { + +// Common instructions + +#define BRANCH( cond )\ +{\ + pc++;\ + pc += (BOOST::int8_t) data;\ + if ( cond )\ + goto loop;\ + pc -= (BOOST::int8_t) data;\ + rel_time -= 2;\ + goto loop;\ +} + + case 0xF0: // BEQ + BRANCH( !(uint8_t) nz ) // 89% taken + + case 0xD0: // BNE + BRANCH( (uint8_t) nz ) + + case 0x3F:{// CALL + int old_addr = GET_PC() + 2; + SET_PC( READ_PC16( pc ) ); + PUSH16( old_addr ); + goto loop; + } + + case 0x6F:// RET + #if SPC_NO_SP_WRAPAROUND + { + SET_PC( GET_LE16( sp ) ); + sp += 2; + } + #else + { + int addr = sp - ram; + SET_PC( GET_LE16( sp ) ); + sp += 2; + if ( addr < 0x1FF ) + goto loop; + + SET_PC( sp [-0x101] * 0x100 + ram [(uint8_t) addr + 0x100] ); + sp -= 0x100; + } + #endif + goto loop; + + case 0xE4: // MOV a,dp + ++pc; + // 80% from timer + READ_DP_TIMER( 0, data, a = nz ); + goto loop; + + case 0xFA:{// MOV dp,dp + int temp; + READ_DP_TIMER( -2, data, temp ); + data = temp + no_read_before_write ; + } + // fall through + case 0x8F:{// MOV dp,#imm + int temp = READ_PC( pc + 1 ); + pc += 2; + + #if !SPC_MORE_ACCURACY + { + int i = dp + temp; + ram [i] = (uint8_t) data; + i -= 0xF0; + if ( (unsigned) i < 0x10 ) // 76% + { + REGS [i] = (uint8_t) data; + + // Registers other than $F2 and $F4-$F7 + //if ( i != 2 && i != 4 && i != 5 && i != 6 && i != 7 ) + if ( ((~0x2F00 << (bits_in_int - 16)) << i) < 0 ) // 12% + cpu_write_smp_reg( data, rel_time, i ); + } + } + #else + WRITE_DP( 0, temp, data ); + #endif + goto loop; + } + + case 0xC4: // MOV dp,a + ++pc; + #if !SPC_MORE_ACCURACY + { + int i = dp + data; + ram [i] = (uint8_t) a; + i -= 0xF0; + if ( (unsigned) i < 0x10 ) // 39% + { + unsigned sel = i - 2; + REGS [i] = (uint8_t) a; + + if ( sel == 1 ) // 51% $F3 + dsp_write( a, rel_time ); + else if ( sel > 1 ) // 1% not $F2 or $F3 + cpu_write_smp_reg_( a, rel_time, i ); + } + } + #else + WRITE_DP( 0, data, a ); + #endif + goto loop; + +#define CASE( n ) case n: + +// Define common address modes based on opcode for immediate mode. Execution +// ends with data set to the address of the operand. +#define ADDR_MODES_( op )\ + CASE( op - 0x02 ) /* (X) */\ + data = x + dp;\ + pc--;\ + goto end_##op;\ + CASE( op + 0x0F ) /* (dp)+Y */\ + data = READ_PROG16( data + dp ) + y;\ + goto end_##op;\ + CASE( op - 0x01 ) /* (dp+X) */\ + data = READ_PROG16( ((uint8_t) (data + x)) + dp );\ + goto end_##op;\ + CASE( op + 0x0E ) /* abs+Y */\ + data += y;\ + goto abs_##op;\ + CASE( op + 0x0D ) /* abs+X */\ + data += x;\ + CASE( op - 0x03 ) /* abs */\ + abs_##op:\ + data += 0x100 * READ_PC( ++pc );\ + goto end_##op;\ + CASE( op + 0x0C ) /* dp+X */\ + data = (uint8_t) (data + x); + +#define ADDR_MODES_NO_DP( op )\ + ADDR_MODES_( op )\ + data += dp;\ + end_##op: + +#define ADDR_MODES( op )\ + ADDR_MODES_( op )\ + CASE( op - 0x04 ) /* dp */\ + data += dp;\ + end_##op: + +// 1. 8-bit Data Transmission Commands. Group I + + ADDR_MODES_NO_DP( 0xE8 ) // MOV A,addr + a = nz = READ( 0, data ); + goto inc_pc_loop; + + case 0xBF:{// MOV A,(X)+ + int temp = x + dp; + x = (uint8_t) (x + 1); + a = nz = READ( -1, temp ); + goto loop; + } + + case 0xE8: // MOV A,imm + a = data; + nz = data; + goto inc_pc_loop; + + case 0xF9: // MOV X,dp+Y + data = (uint8_t) (data + y); + case 0xF8: // MOV X,dp + READ_DP_TIMER( 0, data, x = nz ); + goto inc_pc_loop; + + case 0xE9: // MOV X,abs + data = READ_PC16( pc ); + ++pc; + data = READ( 0, data ); + case 0xCD: // MOV X,imm + x = data; + nz = data; + goto inc_pc_loop; + + case 0xFB: // MOV Y,dp+X + data = (uint8_t) (data + x); + case 0xEB: // MOV Y,dp + // 70% from timer + pc++; + READ_DP_TIMER( 0, data, y = nz ); + goto loop; + + case 0xEC:{// MOV Y,abs + int temp = READ_PC16( pc ); + pc += 2; + READ_TIMER( 0, temp, y = nz ); + //y = nz = READ( 0, temp ); + goto loop; + } + + case 0x8D: // MOV Y,imm + y = data; + nz = data; + goto inc_pc_loop; + +// 2. 8-BIT DATA TRANSMISSION COMMANDS, GROUP 2 + + ADDR_MODES_NO_DP( 0xC8 ) // MOV addr,A + WRITE( 0, data, a ); + goto inc_pc_loop; + + { + int temp; + case 0xCC: // MOV abs,Y + temp = y; + goto mov_abs_temp; + case 0xC9: // MOV abs,X + temp = x; + mov_abs_temp: + WRITE( 0, READ_PC16( pc ), temp ); + pc += 2; + goto loop; + } + + case 0xD9: // MOV dp+Y,X + data = (uint8_t) (data + y); + case 0xD8: // MOV dp,X + WRITE( 0, data + dp, x ); + goto inc_pc_loop; + + case 0xDB: // MOV dp+X,Y + data = (uint8_t) (data + x); + case 0xCB: // MOV dp,Y + WRITE( 0, data + dp, y ); + goto inc_pc_loop; + +// 3. 8-BIT DATA TRANSMISSIN COMMANDS, GROUP 3. + + case 0x7D: // MOV A,X + a = x; + nz = x; + goto loop; + + case 0xDD: // MOV A,Y + a = y; + nz = y; + goto loop; + + case 0x5D: // MOV X,A + x = a; + nz = a; + goto loop; + + case 0xFD: // MOV Y,A + y = a; + nz = a; + goto loop; + + case 0x9D: // MOV X,SP + x = nz = GET_SP(); + goto loop; + + case 0xBD: // MOV SP,X + SET_SP( x ); + goto loop; + + //case 0xC6: // MOV (X),A (handled by MOV addr,A in group 2) + + case 0xAF: // MOV (X)+,A + WRITE_DP( 0, x, a + no_read_before_write ); + x++; + goto loop; + +// 5. 8-BIT LOGIC OPERATION COMMANDS + +#define LOGICAL_OP( op, func )\ + ADDR_MODES( op ) /* addr */\ + data = READ( 0, data );\ + case op: /* imm */\ + nz = a func##= data;\ + goto inc_pc_loop;\ + { unsigned addr;\ + case op + 0x11: /* X,Y */\ + data = READ_DP( -2, y );\ + addr = x + dp;\ + goto addr_##op;\ + case op + 0x01: /* dp,dp */\ + data = READ_DP( -3, data );\ + case op + 0x10:{/*dp,imm*/\ + uint8_t const* addr2 = pc + 1;\ + pc += 2;\ + addr = READ_PC( addr2 ) + dp;\ + }\ + addr_##op:\ + nz = data func READ( -1, addr );\ + WRITE( 0, addr, nz );\ + goto loop;\ + } + + LOGICAL_OP( 0x28, & ); // AND + + LOGICAL_OP( 0x08, | ); // OR + + LOGICAL_OP( 0x48, ^ ); // EOR + +// 4. 8-BIT ARITHMETIC OPERATION COMMANDS + + ADDR_MODES( 0x68 ) // CMP addr + data = READ( 0, data ); + case 0x68: // CMP imm + nz = a - data; + c = ~nz; + nz &= 0xFF; + goto inc_pc_loop; + + case 0x79: // CMP (X),(Y) + data = READ_DP( -2, y ); + nz = READ_DP( -1, x ) - data; + c = ~nz; + nz &= 0xFF; + goto loop; + + case 0x69: // CMP dp,dp + data = READ_DP( -3, data ); + case 0x78: // CMP dp,imm + nz = READ_DP( -1, READ_PC( ++pc ) ) - data; + c = ~nz; + nz &= 0xFF; + goto inc_pc_loop; + + case 0x3E: // CMP X,dp + data += dp; + goto cmp_x_addr; + case 0x1E: // CMP X,abs + data = READ_PC16( pc ); + pc++; + cmp_x_addr: + data = READ( 0, data ); + case 0xC8: // CMP X,imm + nz = x - data; + c = ~nz; + nz &= 0xFF; + goto inc_pc_loop; + + case 0x7E: // CMP Y,dp + data += dp; + goto cmp_y_addr; + case 0x5E: // CMP Y,abs + data = READ_PC16( pc ); + pc++; + cmp_y_addr: + data = READ( 0, data ); + case 0xAD: // CMP Y,imm + nz = y - data; + c = ~nz; + nz &= 0xFF; + goto inc_pc_loop; + + { + int addr; + case 0xB9: // SBC (x),(y) + case 0x99: // ADC (x),(y) + pc--; // compensate for inc later + data = READ_DP( -2, y ); + addr = x + dp; + goto adc_addr; + case 0xA9: // SBC dp,dp + case 0x89: // ADC dp,dp + data = READ_DP( -3, data ); + case 0xB8: // SBC dp,imm + case 0x98: // ADC dp,imm + addr = READ_PC( ++pc ) + dp; + adc_addr: + nz = READ( -1, addr ); + goto adc_data; + +// catch ADC and SBC together, then decode later based on operand +#undef CASE +#define CASE( n ) case n: case (n) + 0x20: + ADDR_MODES( 0x88 ) // ADC/SBC addr + data = READ( 0, data ); + case 0xA8: // SBC imm + case 0x88: // ADC imm + addr = -1; // A + nz = a; + adc_data: { + int flags; + if ( opcode >= 0xA0 ) // SBC + data ^= 0xFF; + + flags = data ^ nz; + nz += data + (c >> 8 & 1); + flags ^= nz; + + psw = (psw & ~(v40 | h08)) | + (flags >> 1 & h08) | + ((flags + 0x80) >> 2 & v40); + c = nz; + if ( addr < 0 ) + { + a = (uint8_t) nz; + goto inc_pc_loop; + } + WRITE( 0, addr, /*(uint8_t)*/ nz ); + goto inc_pc_loop; + } + + } + +// 6. ADDITION & SUBTRACTION COMMANDS + +#define INC_DEC_REG( reg, op )\ + nz = reg op;\ + reg = (uint8_t) nz;\ + goto loop; + + case 0xBC: INC_DEC_REG( a, + 1 ) // INC A + case 0x3D: INC_DEC_REG( x, + 1 ) // INC X + case 0xFC: INC_DEC_REG( y, + 1 ) // INC Y + + case 0x9C: INC_DEC_REG( a, - 1 ) // DEC A + case 0x1D: INC_DEC_REG( x, - 1 ) // DEC X + case 0xDC: INC_DEC_REG( y, - 1 ) // DEC Y + + case 0x9B: // DEC dp+X + case 0xBB: // INC dp+X + data = (uint8_t) (data + x); + case 0x8B: // DEC dp + case 0xAB: // INC dp + data += dp; + goto inc_abs; + case 0x8C: // DEC abs + case 0xAC: // INC abs + data = READ_PC16( pc ); + pc++; + inc_abs: + nz = (opcode >> 4 & 2) - 1; + nz += READ( -1, data ); + WRITE( 0, data, /*(uint8_t)*/ nz ); + goto inc_pc_loop; + +// 7. SHIFT, ROTATION COMMANDS + + case 0x5C: // LSR A + c = 0; + case 0x7C:{// ROR A + nz = (c >> 1 & 0x80) | (a >> 1); + c = a << 8; + a = nz; + goto loop; + } + + case 0x1C: // ASL A + c = 0; + case 0x3C:{// ROL A + int temp = c >> 8 & 1; + c = a << 1; + nz = c | temp; + a = (uint8_t) nz; + goto loop; + } + + case 0x0B: // ASL dp + c = 0; + data += dp; + goto rol_mem; + case 0x1B: // ASL dp+X + c = 0; + case 0x3B: // ROL dp+X + data = (uint8_t) (data + x); + case 0x2B: // ROL dp + data += dp; + goto rol_mem; + case 0x0C: // ASL abs + c = 0; + case 0x2C: // ROL abs + data = READ_PC16( pc ); + pc++; + rol_mem: + nz = c >> 8 & 1; + nz |= (c = READ( -1, data ) << 1); + WRITE( 0, data, /*(uint8_t)*/ nz ); + goto inc_pc_loop; + + case 0x4B: // LSR dp + c = 0; + data += dp; + goto ror_mem; + case 0x5B: // LSR dp+X + c = 0; + case 0x7B: // ROR dp+X + data = (uint8_t) (data + x); + case 0x6B: // ROR dp + data += dp; + goto ror_mem; + case 0x4C: // LSR abs + c = 0; + case 0x6C: // ROR abs + data = READ_PC16( pc ); + pc++; + ror_mem: { + int temp = READ( -1, data ); + nz = (c >> 1 & 0x80) | (temp >> 1); + c = temp << 8; + WRITE( 0, data, nz ); + goto inc_pc_loop; + } + + case 0x9F: // XCN + nz = a = (a >> 4) | (uint8_t) (a << 4); + goto loop; + +// 8. 16-BIT TRANSMISION COMMANDS + + case 0xBA: // MOVW YA,dp + a = READ_DP( -2, data ); + nz = (a & 0x7F) | (a >> 1); + y = READ_DP( 0, (uint8_t) (data + 1) ); + nz |= y; + goto inc_pc_loop; + + case 0xDA: // MOVW dp,YA + WRITE_DP( -1, data, a ); + WRITE_DP( 0, (uint8_t) (data + 1), y + no_read_before_write ); + goto inc_pc_loop; + +// 9. 16-BIT OPERATION COMMANDS + + case 0x3A: // INCW dp + case 0x1A:{// DECW dp + int temp; + // low byte + data += dp; + temp = READ( -3, data ); + temp += (opcode >> 4 & 2) - 1; // +1 for INCW, -1 for DECW + nz = ((temp >> 1) | temp) & 0x7F; + WRITE( -2, data, /*(uint8_t)*/ temp ); + + // high byte + data = (uint8_t) (data + 1) + dp; + temp = (uint8_t) ((temp >> 8) + READ( -1, data )); + nz |= temp; + WRITE( 0, data, temp ); + + goto inc_pc_loop; + } + + case 0x7A: // ADDW YA,dp + case 0x9A:{// SUBW YA,dp + int lo = READ_DP( -2, data ); + int hi = READ_DP( 0, (uint8_t) (data + 1) ); + int result; + int flags; + + if ( opcode == 0x9A ) // SUBW + { + lo = (lo ^ 0xFF) + 1; + hi ^= 0xFF; + } + + lo += a; + result = y + hi + (lo >> 8); + flags = hi ^ y ^ result; + + psw = (psw & ~(v40 | h08)) | + (flags >> 1 & h08) | + ((flags + 0x80) >> 2 & v40); + c = result; + a = (uint8_t) lo; + result = (uint8_t) result; + y = result; + nz = (((lo >> 1) | lo) & 0x7F) | result; + + goto inc_pc_loop; + } + + case 0x5A: { // CMPW YA,dp + int temp = a - READ_DP( -1, data ); + nz = ((temp >> 1) | temp) & 0x7F; + temp = y + (temp >> 8); + temp -= READ_DP( 0, (uint8_t) (data + 1) ); + nz |= temp; + c = ~temp; + nz &= 0xFF; + goto inc_pc_loop; + } + +// 10. MULTIPLICATION & DIVISON COMMANDS + + case 0xCF: { // MUL YA + unsigned temp = y * a; + a = (uint8_t) temp; + nz = ((temp >> 1) | temp) & 0x7F; + y = temp >> 8; + nz |= y; + goto loop; + } + + case 0x9E: // DIV YA,X + { + unsigned ya = y * 0x100 + a; + + psw &= ~(h08 | v40); + + if ( y >= x ) + psw |= v40; + + if ( (y & 15) >= (x & 15) ) + psw |= h08; + + if ( y < x * 2 ) + { + a = ya / x; + y = ya - a * x; + } + else + { + a = 255 - (ya - x * 0x200) / (256 - x); + y = x + (ya - x * 0x200) % (256 - x); + } + + nz = (uint8_t) a; + a = (uint8_t) a; + + goto loop; + } + +// 11. DECIMAL COMPENSATION COMMANDS + + case 0xDF: // DAA + SUSPICIOUS_OPCODE( "DAA" ); + if ( a > 0x99 || c & 0x100 ) + { + a += 0x60; + c = 0x100; + } + + if ( (a & 0x0F) > 9 || psw & h08 ) + a += 0x06; + + nz = a; + a = (uint8_t) a; + goto loop; + + case 0xBE: // DAS + SUSPICIOUS_OPCODE( "DAS" ); + if ( a > 0x99 || !(c & 0x100) ) + { + a -= 0x60; + c = 0; + } + + if ( (a & 0x0F) > 9 || !(psw & h08) ) + a -= 0x06; + + nz = a; + a = (uint8_t) a; + goto loop; + +// 12. BRANCHING COMMANDS + + case 0x2F: // BRA rel + pc += (BOOST::int8_t) data; + goto inc_pc_loop; + + case 0x30: // BMI + BRANCH( (nz & nz_neg_mask) ) + + case 0x10: // BPL + BRANCH( !(nz & nz_neg_mask) ) + + case 0xB0: // BCS + BRANCH( c & 0x100 ) + + case 0x90: // BCC + BRANCH( !(c & 0x100) ) + + case 0x70: // BVS + BRANCH( psw & v40 ) + + case 0x50: // BVC + BRANCH( !(psw & v40) ) + + #define CBRANCH( cond )\ + {\ + pc++;\ + if ( cond )\ + goto cbranch_taken_loop;\ + rel_time -= 2;\ + goto inc_pc_loop;\ + } + + case 0x03: // BBS dp.bit,rel + case 0x23: + case 0x43: + case 0x63: + case 0x83: + case 0xA3: + case 0xC3: + case 0xE3: + CBRANCH( READ_DP( -4, data ) >> (opcode >> 5) & 1 ) + + case 0x13: // BBC dp.bit,rel + case 0x33: + case 0x53: + case 0x73: + case 0x93: + case 0xB3: + case 0xD3: + case 0xF3: + CBRANCH( !(READ_DP( -4, data ) >> (opcode >> 5) & 1) ) + + case 0xDE: // CBNE dp+X,rel + data = (uint8_t) (data + x); + // fall through + case 0x2E:{// CBNE dp,rel + int temp; + // 61% from timer + READ_DP_TIMER( -4, data, temp ); + CBRANCH( temp != a ) + } + + case 0x6E: { // DBNZ dp,rel + unsigned temp = READ_DP( -4, data ) - 1; + WRITE_DP( -3, (uint8_t) data, /*(uint8_t)*/ temp + no_read_before_write ); + CBRANCH( temp ) + } + + case 0xFE: // DBNZ Y,rel + y = (uint8_t) (y - 1); + BRANCH( y ) + + case 0x1F: // JMP [abs+X] + SET_PC( READ_PC16( pc ) + x ); + // fall through + case 0x5F: // JMP abs + SET_PC( READ_PC16( pc ) ); + goto loop; + +// 13. SUB-ROUTINE CALL RETURN COMMANDS + + case 0x0F:{// BRK + int temp; + int ret_addr = GET_PC(); + SUSPICIOUS_OPCODE( "BRK" ); + SET_PC( READ_PROG16( 0xFFDE ) ); // vector address verified + PUSH16( ret_addr ); + GET_PSW( temp ); + psw = (psw | b10) & ~i04; + PUSH( temp ); + goto loop; + } + + case 0x4F:{// PCALL offset + int ret_addr = GET_PC() + 1; + SET_PC( 0xFF00 | data ); + PUSH16( ret_addr ); + goto loop; + } + + case 0x01: // TCALL n + case 0x11: + case 0x21: + case 0x31: + case 0x41: + case 0x51: + case 0x61: + case 0x71: + case 0x81: + case 0x91: + case 0xA1: + case 0xB1: + case 0xC1: + case 0xD1: + case 0xE1: + case 0xF1: { + int ret_addr = GET_PC(); + SET_PC( READ_PROG16( 0xFFDE - (opcode >> 3) ) ); + PUSH16( ret_addr ); + goto loop; + } + +// 14. STACK OPERATION COMMANDS + + { + int temp; + case 0x7F: // RET1 + temp = *sp; + SET_PC( GET_LE16( sp + 1 ) ); + sp += 3; + goto set_psw; + case 0x8E: // POP PSW + POP( temp ); + set_psw: + SET_PSW( temp ); + goto loop; + } + + case 0x0D: { // PUSH PSW + int temp; + GET_PSW( temp ); + PUSH( temp ); + goto loop; + } + + case 0x2D: // PUSH A + PUSH( a ); + goto loop; + + case 0x4D: // PUSH X + PUSH( x ); + goto loop; + + case 0x6D: // PUSH Y + PUSH( y ); + goto loop; + + case 0xAE: // POP A + POP( a ); + goto loop; + + case 0xCE: // POP X + POP( x ); + goto loop; + + case 0xEE: // POP Y + POP( y ); + goto loop; + +// 15. BIT OPERATION COMMANDS + + case 0x02: // SET1 + case 0x22: + case 0x42: + case 0x62: + case 0x82: + case 0xA2: + case 0xC2: + case 0xE2: + case 0x12: // CLR1 + case 0x32: + case 0x52: + case 0x72: + case 0x92: + case 0xB2: + case 0xD2: + case 0xF2: { + int bit = 1 << (opcode >> 5); + int mask = ~bit; + if ( opcode & 0x10 ) + bit = 0; + data += dp; + WRITE( 0, data, (READ( -1, data ) & mask) | bit ); + goto inc_pc_loop; + } + + case 0x0E: // TSET1 abs + case 0x4E: // TCLR1 abs + data = READ_PC16( pc ); + pc += 2; + { + unsigned temp = READ( -2, data ); + nz = (uint8_t) (a - temp); + temp &= ~a; + if ( opcode == 0x0E ) + temp |= a; + WRITE( 0, data, temp ); + } + goto loop; + + case 0x4A: // AND1 C,mem.bit + c &= MEM_BIT( 0 ); + pc += 2; + goto loop; + + case 0x6A: // AND1 C,/mem.bit + c &= ~MEM_BIT( 0 ); + pc += 2; + goto loop; + + case 0x0A: // OR1 C,mem.bit + c |= MEM_BIT( -1 ); + pc += 2; + goto loop; + + case 0x2A: // OR1 C,/mem.bit + c |= ~MEM_BIT( -1 ); + pc += 2; + goto loop; + + case 0x8A: // EOR1 C,mem.bit + c ^= MEM_BIT( -1 ); + pc += 2; + goto loop; + + case 0xEA: // NOT1 mem.bit + data = READ_PC16( pc ); + pc += 2; + { + unsigned temp = READ( -1, data & 0x1FFF ); + temp ^= 1 << (data >> 13); + WRITE( 0, data & 0x1FFF, temp ); + } + goto loop; + + case 0xCA: // MOV1 mem.bit,C + data = READ_PC16( pc ); + pc += 2; + { + unsigned temp = READ( -2, data & 0x1FFF ); + unsigned bit = data >> 13; + temp = (temp & ~(1 << bit)) | ((c >> 8 & 1) << bit); + WRITE( 0, data & 0x1FFF, temp + no_read_before_write ); + } + goto loop; + + case 0xAA: // MOV1 C,mem.bit + c = MEM_BIT( 0 ); + pc += 2; + goto loop; + +// 16. PROGRAM PSW FLAG OPERATION COMMANDS + + case 0x60: // CLRC + c = 0; + goto loop; + + case 0x80: // SETC + c = ~0; + goto loop; + + case 0xED: // NOTC + c ^= 0x100; + goto loop; + + case 0xE0: // CLRV + psw &= ~(v40 | h08); + goto loop; + + case 0x20: // CLRP + dp = 0; + goto loop; + + case 0x40: // SETP + dp = 0x100; + goto loop; + + case 0xA0: // EI + SUSPICIOUS_OPCODE( "EI" ); + psw |= i04; + goto loop; + + case 0xC0: // DI + SUSPICIOUS_OPCODE( "DI" ); + psw &= ~i04; + goto loop; + +// 17. OTHER COMMANDS + + case 0x00: // NOP + goto loop; + + case 0xFF:{// STOP + // handle PC wrap-around + unsigned addr = GET_PC() - 1; + if ( addr >= 0x10000 ) + { + addr &= 0xFFFF; + SET_PC( addr ); + debug_printf( "SPC: PC wrapped around\n" ); + goto loop; + } + } + // fall through + case 0xEF: // SLEEP + SUSPICIOUS_OPCODE( "STOP/SLEEP" ); + --pc; + rel_time = 0; + m.cpu_error = "SPC emulation error"; + goto stop; + } // switch + + assert( 0 ); // catch any unhandled instructions +} +out_of_time: + rel_time -= m.cycle_table [*pc]; // undo partial execution of opcode +stop: + + // Uncache registers + if ( GET_PC() >= 0x10000 ) + debug_printf( "SPC: PC wrapped around\n" ); + m.cpu_regs.pc = (uint16_t) GET_PC(); + m.cpu_regs.sp = ( uint8_t) GET_SP(); + m.cpu_regs.a = ( uint8_t) a; + m.cpu_regs.x = ( uint8_t) x; + m.cpu_regs.y = ( uint8_t) y; + { + int temp; + GET_PSW( temp ); + m.cpu_regs.psw = (uint8_t) temp; + } +} +SPC_CPU_RUN_FUNC_END diff --git a/libs/gme/gme/Spc_Dsp.cpp b/libs/gme/gme/Spc_Dsp.cpp new file mode 100644 index 000000000..0a84bfe16 --- /dev/null +++ b/libs/gme/gme/Spc_Dsp.cpp @@ -0,0 +1,703 @@ +// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/ + +#include "Spc_Dsp.h" + +#include "blargg_endian.h" +#include + +/* Copyright (C) 2007 Shay Green. This module 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 +module 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 module; if not, write to the Free Software Foundation, +Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + +#include "blargg_source.h" + +#ifdef BLARGG_ENABLE_OPTIMIZER + #include BLARGG_ENABLE_OPTIMIZER +#endif + +#if INT_MAX < 0x7FFFFFFF + #error "Requires that int type have at least 32 bits" +#endif + + +// TODO: add to blargg_endian.h +#define GET_LE16SA( addr ) ((BOOST::int16_t) GET_LE16( addr )) +#define GET_LE16A( addr ) GET_LE16( addr ) +#define SET_LE16A( addr, data ) SET_LE16( addr, data ) + +static BOOST::uint8_t const initial_regs [Spc_Dsp::register_count] = +{ + 0x45,0x8B,0x5A,0x9A,0xE4,0x82,0x1B,0x78,0x00,0x00,0xAA,0x96,0x89,0x0E,0xE0,0x80, + 0x2A,0x49,0x3D,0xBA,0x14,0xA0,0xAC,0xC5,0x00,0x00,0x51,0xBB,0x9C,0x4E,0x7B,0xFF, + 0xF4,0xFD,0x57,0x32,0x37,0xD9,0x42,0x22,0x00,0x00,0x5B,0x3C,0x9F,0x1B,0x87,0x9A, + 0x6F,0x27,0xAF,0x7B,0xE5,0x68,0x0A,0xD9,0x00,0x00,0x9A,0xC5,0x9C,0x4E,0x7B,0xFF, + 0xEA,0x21,0x78,0x4F,0xDD,0xED,0x24,0x14,0x00,0x00,0x77,0xB1,0xD1,0x36,0xC1,0x67, + 0x52,0x57,0x46,0x3D,0x59,0xF4,0x87,0xA4,0x00,0x00,0x7E,0x44,0x9C,0x4E,0x7B,0xFF, + 0x75,0xF5,0x06,0x97,0x10,0xC3,0x24,0xBB,0x00,0x00,0x7B,0x7A,0xE0,0x60,0x12,0x0F, + 0xF7,0x74,0x1C,0xE5,0x39,0x3D,0x73,0xC1,0x00,0x00,0x7A,0xB3,0xFF,0x4E,0x7B,0xFF +}; + +// if ( io < -32768 ) io = -32768; +// if ( io > 32767 ) io = 32767; +#define CLAMP16( io )\ +{\ + if ( (int16_t) io != io )\ + io = (io >> 31) ^ 0x7FFF;\ +} + +// Access global DSP register +#define REG(n) m.regs [r_##n] + +// Access voice DSP register +#define VREG(r,n) r [v_##n] + +#define WRITE_SAMPLES( l, r, out ) \ +{\ + out [0] = l;\ + out [1] = r;\ + out += 2;\ + if ( out >= m.out_end )\ + {\ + check( out == m.out_end );\ + check( m.out_end != &m.extra [extra_size] || \ + (m.extra <= m.out_begin && m.extra < &m.extra [extra_size]) );\ + out = m.extra;\ + m.out_end = &m.extra [extra_size];\ + }\ +}\ + +void Spc_Dsp::set_output( sample_t* out, int size ) +{ + require( (size & 1) == 0 ); // must be even + if ( !out ) + { + out = m.extra; + size = extra_size; + } + m.out_begin = out; + m.out = out; + m.out_end = out + size; +} + +// Volume registers and efb are signed! Easy to forget int8_t cast. +// Prefixes are to avoid accidental use of locals with same names. + +// Interleved gauss table (to improve cache coherency) +// interleved_gauss [i] = gauss [(i & 1) * 256 + 255 - (i >> 1 & 0xFF)] +static short const interleved_gauss [512] = +{ + 370,1305, 366,1305, 362,1304, 358,1304, 354,1304, 351,1304, 347,1304, 343,1303, + 339,1303, 336,1303, 332,1302, 328,1302, 325,1301, 321,1300, 318,1300, 314,1299, + 311,1298, 307,1297, 304,1297, 300,1296, 297,1295, 293,1294, 290,1293, 286,1292, + 283,1291, 280,1290, 276,1288, 273,1287, 270,1286, 267,1284, 263,1283, 260,1282, + 257,1280, 254,1279, 251,1277, 248,1275, 245,1274, 242,1272, 239,1270, 236,1269, + 233,1267, 230,1265, 227,1263, 224,1261, 221,1259, 218,1257, 215,1255, 212,1253, + 210,1251, 207,1248, 204,1246, 201,1244, 199,1241, 196,1239, 193,1237, 191,1234, + 188,1232, 186,1229, 183,1227, 180,1224, 178,1221, 175,1219, 173,1216, 171,1213, + 168,1210, 166,1207, 163,1205, 161,1202, 159,1199, 156,1196, 154,1193, 152,1190, + 150,1186, 147,1183, 145,1180, 143,1177, 141,1174, 139,1170, 137,1167, 134,1164, + 132,1160, 130,1157, 128,1153, 126,1150, 124,1146, 122,1143, 120,1139, 118,1136, + 117,1132, 115,1128, 113,1125, 111,1121, 109,1117, 107,1113, 106,1109, 104,1106, + 102,1102, 100,1098, 99,1094, 97,1090, 95,1086, 94,1082, 92,1078, 90,1074, + 89,1070, 87,1066, 86,1061, 84,1057, 83,1053, 81,1049, 80,1045, 78,1040, + 77,1036, 76,1032, 74,1027, 73,1023, 71,1019, 70,1014, 69,1010, 67,1005, + 66,1001, 65, 997, 64, 992, 62, 988, 61, 983, 60, 978, 59, 974, 58, 969, + 56, 965, 55, 960, 54, 955, 53, 951, 52, 946, 51, 941, 50, 937, 49, 932, + 48, 927, 47, 923, 46, 918, 45, 913, 44, 908, 43, 904, 42, 899, 41, 894, + 40, 889, 39, 884, 38, 880, 37, 875, 36, 870, 36, 865, 35, 860, 34, 855, + 33, 851, 32, 846, 32, 841, 31, 836, 30, 831, 29, 826, 29, 821, 28, 816, + 27, 811, 27, 806, 26, 802, 25, 797, 24, 792, 24, 787, 23, 782, 23, 777, + 22, 772, 21, 767, 21, 762, 20, 757, 20, 752, 19, 747, 19, 742, 18, 737, + 17, 732, 17, 728, 16, 723, 16, 718, 15, 713, 15, 708, 15, 703, 14, 698, + 14, 693, 13, 688, 13, 683, 12, 678, 12, 674, 11, 669, 11, 664, 11, 659, + 10, 654, 10, 649, 10, 644, 9, 640, 9, 635, 9, 630, 8, 625, 8, 620, + 8, 615, 7, 611, 7, 606, 7, 601, 6, 596, 6, 592, 6, 587, 6, 582, + 5, 577, 5, 573, 5, 568, 5, 563, 4, 559, 4, 554, 4, 550, 4, 545, + 4, 540, 3, 536, 3, 531, 3, 527, 3, 522, 3, 517, 2, 513, 2, 508, + 2, 504, 2, 499, 2, 495, 2, 491, 2, 486, 1, 482, 1, 477, 1, 473, + 1, 469, 1, 464, 1, 460, 1, 456, 1, 451, 1, 447, 1, 443, 1, 439, + 0, 434, 0, 430, 0, 426, 0, 422, 0, 418, 0, 414, 0, 410, 0, 405, + 0, 401, 0, 397, 0, 393, 0, 389, 0, 385, 0, 381, 0, 378, 0, 374, +}; + + +//// Counters + +#define RATE( rate, div )\ + (rate >= div ? rate / div * 8 - 1 : rate - 1) + +static unsigned const counter_mask [32] = +{ + RATE( 2,2), RATE(2048,4), RATE(1536,3), + RATE(1280,5), RATE(1024,4), RATE( 768,3), + RATE( 640,5), RATE( 512,4), RATE( 384,3), + RATE( 320,5), RATE( 256,4), RATE( 192,3), + RATE( 160,5), RATE( 128,4), RATE( 96,3), + RATE( 80,5), RATE( 64,4), RATE( 48,3), + RATE( 40,5), RATE( 32,4), RATE( 24,3), + RATE( 20,5), RATE( 16,4), RATE( 12,3), + RATE( 10,5), RATE( 8,4), RATE( 6,3), + RATE( 5,5), RATE( 4,4), RATE( 3,3), + RATE( 2,4), + RATE( 1,4) +}; +#undef RATE + +inline void Spc_Dsp::init_counter() +{ + // counters start out with this synchronization + m.counters [0] = 1; + m.counters [1] = 0; + m.counters [2] = -0x20u; + m.counters [3] = 0x0B; + + int n = 2; + for ( int i = 1; i < 32; i++ ) + { + m.counter_select [i] = &m.counters [n]; + if ( !--n ) + n = 3; + } + m.counter_select [ 0] = &m.counters [0]; + m.counter_select [30] = &m.counters [2]; +} + +inline void Spc_Dsp::run_counter( int i ) +{ + int n = m.counters [i]; + if ( !(n-- & 7) ) + n -= 6 - i; + m.counters [i] = n; +} + +#define READ_COUNTER( rate )\ + (*m.counter_select [rate] & counter_mask [rate]) + + +//// Emulation + +void Spc_Dsp::run( int clock_count ) +{ + int new_phase = m.phase + clock_count; + int count = new_phase >> 5; + m.phase = new_phase & 31; + if ( !count ) + return; + + uint8_t* const ram = m.ram; + uint8_t const* const dir = &ram [REG(dir) * 0x100]; + int const slow_gaussian = (REG(pmon) >> 1) | REG(non); + int const noise_rate = REG(flg) & 0x1F; + + // Global volume + int mvoll = (int8_t) REG(mvoll); + int mvolr = (int8_t) REG(mvolr); + if ( mvoll * mvolr < m.surround_threshold ) + mvoll = -mvoll; // eliminate surround + + do + { + // KON/KOFF reading + if ( (m.every_other_sample ^= 1) != 0 ) + { + m.new_kon &= ~m.kon; + m.kon = m.new_kon; + m.t_koff = REG(koff); + } + + run_counter( 1 ); + run_counter( 2 ); + run_counter( 3 ); + + // Noise + if ( !READ_COUNTER( noise_rate ) ) + { + int feedback = (m.noise << 13) ^ (m.noise << 14); + m.noise = (feedback & 0x4000) ^ (m.noise >> 1); + } + + // Voices + int pmon_input = 0; + int main_out_l = 0; + int main_out_r = 0; + int echo_out_l = 0; + int echo_out_r = 0; + voice_t* v = m.voices; + uint8_t* v_regs = m.regs; + int vbit = 1; + do + { + #define SAMPLE_PTR(i) GET_LE16A( &dir [VREG(v_regs,srcn) * 4 + i * 2] ) + + int brr_header = ram [v->brr_addr]; + int kon_delay = v->kon_delay; + + // Pitch + int pitch = GET_LE16A( &VREG(v_regs,pitchl) ) & 0x3FFF; + if ( REG(pmon) & vbit ) + pitch += ((pmon_input >> 5) * pitch) >> 10; + + // KON phases + if ( --kon_delay >= 0 ) + { + v->kon_delay = kon_delay; + + // Get ready to start BRR decoding on next sample + if ( kon_delay == 4 ) + { + v->brr_addr = SAMPLE_PTR( 0 ); + v->brr_offset = 1; + v->buf_pos = v->buf; + brr_header = 0; // header is ignored on this sample + } + + // Envelope is never run during KON + v->env = 0; + v->hidden_env = 0; + + // Disable BRR decoding until last three samples + v->interp_pos = (kon_delay & 3 ? 0x4000 : 0); + + // Pitch is never added during KON + pitch = 0; + } + + int env = v->env; + + // Gaussian interpolation + { + int output = 0; + VREG(v_regs,envx) = (uint8_t) (env >> 4); + if ( env ) + { + // Make pointers into gaussian based on fractional position between samples + int offset = (unsigned) v->interp_pos >> 3 & 0x1FE; + short const* fwd = interleved_gauss + offset; + short const* rev = interleved_gauss + 510 - offset; // mirror left half of gaussian + + int const* in = &v->buf_pos [(unsigned) v->interp_pos >> 12]; + + if ( !(slow_gaussian & vbit) ) // 99% + { + // Faster approximation when exact sample value isn't necessary for pitch mod + output = (fwd [0] * in [0] + + fwd [1] * in [1] + + rev [1] * in [2] + + rev [0] * in [3]) >> 11; + output = (output * env) >> 11; + } + else + { + output = (int16_t) (m.noise * 2); + if ( !(REG(non) & vbit) ) + { + output = (fwd [0] * in [0]) >> 11; + output += (fwd [1] * in [1]) >> 11; + output += (rev [1] * in [2]) >> 11; + output = (int16_t) output; + output += (rev [0] * in [3]) >> 11; + + CLAMP16( output ); + output &= ~1; + } + output = (output * env) >> 11 & ~1; + } + + // Output + int l = output * v->volume [0]; + int r = output * v->volume [1]; + + main_out_l += l; + main_out_r += r; + + if ( REG(eon) & vbit ) + { + echo_out_l += l; + echo_out_r += r; + } + } + + pmon_input = output; + VREG(v_regs,outx) = (uint8_t) (output >> 8); + } + + // Soft reset or end of sample + if ( REG(flg) & 0x80 || (brr_header & 3) == 1 ) + { + v->env_mode = env_release; + env = 0; + } + + if ( m.every_other_sample ) + { + // KOFF + if ( m.t_koff & vbit ) + v->env_mode = env_release; + + // KON + if ( m.kon & vbit ) + { + v->kon_delay = 5; + v->env_mode = env_attack; + REG(endx) &= ~vbit; + } + } + + // Envelope + if ( !v->kon_delay ) + { + if ( v->env_mode == env_release ) // 97% + { + env -= 0x8; + v->env = env; + if ( env <= 0 ) + { + v->env = 0; + goto skip_brr; // no BRR decoding for you! + } + } + else // 3% + { + int rate; + int const adsr0 = VREG(v_regs,adsr0); + int env_data = VREG(v_regs,adsr1); + if ( adsr0 >= 0x80 ) // 97% ADSR + { + if ( v->env_mode > env_decay ) // 89% + { + env--; + env -= env >> 8; + rate = env_data & 0x1F; + + // optimized handling + v->hidden_env = env; + if ( READ_COUNTER( rate ) ) + goto exit_env; + v->env = env; + goto exit_env; + } + else if ( v->env_mode == env_decay ) + { + env--; + env -= env >> 8; + rate = (adsr0 >> 3 & 0x0E) + 0x10; + } + else // env_attack + { + rate = (adsr0 & 0x0F) * 2 + 1; + env += rate < 31 ? 0x20 : 0x400; + } + } + else // GAIN + { + int mode; + env_data = VREG(v_regs,gain); + mode = env_data >> 5; + if ( mode < 4 ) // direct + { + env = env_data * 0x10; + rate = 31; + } + else + { + rate = env_data & 0x1F; + if ( mode == 4 ) // 4: linear decrease + { + env -= 0x20; + } + else if ( mode < 6 ) // 5: exponential decrease + { + env--; + env -= env >> 8; + } + else // 6,7: linear increase + { + env += 0x20; + if ( mode > 6 && (unsigned) v->hidden_env >= 0x600 ) + env += 0x8 - 0x20; // 7: two-slope linear increase + } + } + } + + // Sustain level + if ( (env >> 8) == (env_data >> 5) && v->env_mode == env_decay ) + v->env_mode = env_sustain; + + v->hidden_env = env; + + // unsigned cast because linear decrease going negative also triggers this + if ( (unsigned) env > 0x7FF ) + { + env = (env < 0 ? 0 : 0x7FF); + if ( v->env_mode == env_attack ) + v->env_mode = env_decay; + } + + if ( !READ_COUNTER( rate ) ) + v->env = env; // nothing else is controlled by the counter + } + } + exit_env: + + { + // Apply pitch + int old_pos = v->interp_pos; + int interp_pos = (old_pos & 0x3FFF) + pitch; + if ( interp_pos > 0x7FFF ) + interp_pos = 0x7FFF; + v->interp_pos = interp_pos; + + // BRR decode if necessary + if ( old_pos >= 0x4000 ) + { + // Arrange the four input nybbles in 0xABCD order for easy decoding + int nybbles = ram [(v->brr_addr + v->brr_offset) & 0xFFFF] * 0x100 + + ram [(v->brr_addr + v->brr_offset + 1) & 0xFFFF]; + + // Advance read position + int const brr_block_size = 9; + int brr_offset = v->brr_offset; + if ( (brr_offset += 2) >= brr_block_size ) + { + // Next BRR block + int brr_addr = (v->brr_addr + brr_block_size) & 0xFFFF; + assert( brr_offset == brr_block_size ); + if ( brr_header & 1 ) + { + brr_addr = SAMPLE_PTR( 1 ); + if ( !v->kon_delay ) + REG(endx) |= vbit; + } + v->brr_addr = brr_addr; + brr_offset = 1; + } + v->brr_offset = brr_offset; + + // Decode + + // 0: >>1 1: <<0 2: <<1 ... 12: <<11 13-15: >>4 <<11 + static unsigned char const shifts [16 * 2] = { + 13,12,12,12,12,12,12,12,12,12,12, 12, 12, 16, 16, 16, + 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 11, 11, 11 + }; + int const scale = brr_header >> 4; + int const right_shift = shifts [scale]; + int const left_shift = shifts [scale + 16]; + + // Write to next four samples in circular buffer + int* pos = v->buf_pos; + int* end; + + // Decode four samples + for ( end = pos + 4; pos < end; pos++, nybbles <<= 4 ) + { + // Extract upper nybble and scale appropriately + int s = ((int16_t) nybbles >> right_shift) << left_shift; + + // Apply IIR filter (8 is the most commonly used) + int const filter = brr_header & 0x0C; + int const p1 = pos [brr_buf_size - 1]; + int const p2 = pos [brr_buf_size - 2] >> 1; + if ( filter >= 8 ) + { + s += p1; + s -= p2; + if ( filter == 8 ) // s += p1 * 0.953125 - p2 * 0.46875 + { + s += p2 >> 4; + s += (p1 * -3) >> 6; + } + else // s += p1 * 0.8984375 - p2 * 0.40625 + { + s += (p1 * -13) >> 7; + s += (p2 * 3) >> 4; + } + } + else if ( filter ) // s += p1 * 0.46875 + { + s += p1 >> 1; + s += (-p1) >> 5; + } + + // Adjust and write sample + CLAMP16( s ); + s = (int16_t) (s * 2); + pos [brr_buf_size] = pos [0] = s; // second copy simplifies wrap-around + } + + if ( pos >= &v->buf [brr_buf_size] ) + pos = v->buf; + v->buf_pos = pos; + } + } +skip_brr: + // Next voice + vbit <<= 1; + v_regs += 0x10; + v++; + } + while ( vbit < 0x100 ); + + // Echo position + int echo_offset = m.echo_offset; + uint8_t* const echo_ptr = &ram [(REG(esa) * 0x100 + echo_offset) & 0xFFFF]; + if ( !echo_offset ) + m.echo_length = (REG(edl) & 0x0F) * 0x800; + echo_offset += 4; + if ( echo_offset >= m.echo_length ) + echo_offset = 0; + m.echo_offset = echo_offset; + + // FIR + int echo_in_l = GET_LE16SA( echo_ptr + 0 ); + int echo_in_r = GET_LE16SA( echo_ptr + 2 ); + + int (*echo_hist_pos) [2] = m.echo_hist_pos; + if ( ++echo_hist_pos >= &m.echo_hist [echo_hist_size] ) + echo_hist_pos = m.echo_hist; + m.echo_hist_pos = echo_hist_pos; + + echo_hist_pos [0] [0] = echo_hist_pos [8] [0] = echo_in_l; + echo_hist_pos [0] [1] = echo_hist_pos [8] [1] = echo_in_r; + + #define CALC_FIR_( i, in ) ((in) * (int8_t) REG(fir + i * 0x10)) + echo_in_l = CALC_FIR_( 7, echo_in_l ); + echo_in_r = CALC_FIR_( 7, echo_in_r ); + + #define CALC_FIR( i, ch ) CALC_FIR_( i, echo_hist_pos [i + 1] [ch] ) + #define DO_FIR( i )\ + echo_in_l += CALC_FIR( i, 0 );\ + echo_in_r += CALC_FIR( i, 1 ); + DO_FIR( 0 ); + DO_FIR( 1 ); + DO_FIR( 2 ); + #if defined (__MWERKS__) && __MWERKS__ < 0x3200 + __eieio(); // keeps compiler from stupidly "caching" things in memory + #endif + DO_FIR( 3 ); + DO_FIR( 4 ); + DO_FIR( 5 ); + DO_FIR( 6 ); + + // Echo out + if ( !(REG(flg) & 0x20) ) + { + int l = (echo_out_l >> 7) + ((echo_in_l * (int8_t) REG(efb)) >> 14); + int r = (echo_out_r >> 7) + ((echo_in_r * (int8_t) REG(efb)) >> 14); + + // just to help pass more validation tests + #if SPC_MORE_ACCURACY + l &= ~1; + r &= ~1; + #endif + + CLAMP16( l ); + CLAMP16( r ); + + SET_LE16A( echo_ptr + 0, l ); + SET_LE16A( echo_ptr + 2, r ); + } + + // Sound out + int l = (main_out_l * mvoll + echo_in_l * (int8_t) REG(evoll)) >> 14; + int r = (main_out_r * mvolr + echo_in_r * (int8_t) REG(evolr)) >> 14; + + CLAMP16( l ); + CLAMP16( r ); + + if ( (REG(flg) & 0x40) ) + { + l = 0; + r = 0; + } + + sample_t* out = m.out; + WRITE_SAMPLES( l, r, out ); + m.out = out; + } + while ( --count ); +} + + +//// Setup + +void Spc_Dsp::mute_voices( int mask ) +{ + m.mute_mask = mask; + for ( int i = 0; i < voice_count; i++ ) + { + m.voices [i].enabled = (mask >> i & 1) - 1; + update_voice_vol( i * 0x10 ); + } +} + +void Spc_Dsp::init( void* ram_64k ) +{ + m.ram = (uint8_t*) ram_64k; + mute_voices( 0 ); + disable_surround( false ); + set_output( 0, 0 ); + reset(); + + #ifndef NDEBUG + // be sure this sign-extends + assert( (int16_t) 0x8000 == -0x8000 ); + + // be sure right shift preserves sign + assert( (-1 >> 1) == -1 ); + + // check clamp macro + int i; + i = +0x8000; CLAMP16( i ); assert( i == +0x7FFF ); + i = -0x8001; CLAMP16( i ); assert( i == -0x8000 ); + + blargg_verify_byte_order(); + #endif +} + +void Spc_Dsp::soft_reset_common() +{ + require( m.ram ); // init() must have been called already + + m.noise = 0x4000; + m.echo_hist_pos = m.echo_hist; + m.every_other_sample = 1; + m.echo_offset = 0; + m.phase = 0; + + init_counter(); +} + +void Spc_Dsp::soft_reset() +{ + REG(flg) = 0xE0; + soft_reset_common(); +} + +void Spc_Dsp::load( uint8_t const regs [register_count] ) +{ + memcpy( m.regs, regs, sizeof m.regs ); + memset( &m.regs [register_count], 0, offsetof (state_t,ram) - register_count ); + + // Internal state + int i; + for ( i = voice_count; --i >= 0; ) + { + voice_t& v = m.voices [i]; + v.brr_offset = 1; + v.buf_pos = v.buf; + } + m.new_kon = REG(kon); + + mute_voices( m.mute_mask ); + soft_reset_common(); +} + +void Spc_Dsp::reset() { load( initial_regs ); } diff --git a/libs/gme/gme/Spc_Dsp.h b/libs/gme/gme/Spc_Dsp.h new file mode 100644 index 000000000..401af020a --- /dev/null +++ b/libs/gme/gme/Spc_Dsp.h @@ -0,0 +1,212 @@ +// Fast SNES SPC-700 DSP emulator (about 3x speed of accurate one) + +// Game_Music_Emu 0.6.0 +#ifndef SPC_DSP_H +#define SPC_DSP_H + +#include "blargg_common.h" + +struct Spc_Dsp { +public: + typedef BOOST::uint8_t uint8_t; + +// Setup + + // Initializes DSP and has it use the 64K RAM provided + void init( void* ram_64k ); + + // Sets destination for output samples. If out is NULL or out_size is 0, + // doesn't generate any. + typedef short sample_t; + void set_output( sample_t* out, int out_size ); + + // Number of samples written to output since it was last set, always + // a multiple of 2. Undefined if more samples were generated than + // output buffer could hold. + int sample_count() const; + +// Emulation + + // Resets DSP to power-on state + void reset(); + + // Emulates pressing reset switch on SNES + void soft_reset(); + + // Reads/writes DSP registers. For accuracy, you must first call spc_run_dsp() + // to catch the DSP up to present. + int read ( int addr ) const; + void write( int addr, int data ); + + // Runs DSP for specified number of clocks (~1024000 per second). Every 32 clocks + // a pair of samples is be generated. + void run( int clock_count ); + +// Sound control + + // Mutes voices corresponding to non-zero bits in mask (overrides VxVOL with 0). + // Reduces emulation accuracy. + enum { voice_count = 8 }; + void mute_voices( int mask ); + + // If true, prevents channels and global volumes from being phase-negated + void disable_surround( bool disable = true ); + +// State + + // Resets DSP and uses supplied values to initialize registers + enum { register_count = 128 }; + void load( uint8_t const regs [register_count] ); + +// DSP register addresses + + // Global registers + enum { + r_mvoll = 0x0C, r_mvolr = 0x1C, + r_evoll = 0x2C, r_evolr = 0x3C, + r_kon = 0x4C, r_koff = 0x5C, + r_flg = 0x6C, r_endx = 0x7C, + r_efb = 0x0D, r_pmon = 0x2D, + r_non = 0x3D, r_eon = 0x4D, + r_dir = 0x5D, r_esa = 0x6D, + r_edl = 0x7D, + r_fir = 0x0F // 8 coefficients at 0x0F, 0x1F ... 0x7F + }; + + // Voice registers + enum { + v_voll = 0x00, v_volr = 0x01, + v_pitchl = 0x02, v_pitchh = 0x03, + v_srcn = 0x04, v_adsr0 = 0x05, + v_adsr1 = 0x06, v_gain = 0x07, + v_envx = 0x08, v_outx = 0x09 + }; + +public: + enum { extra_size = 16 }; + sample_t* extra() { return m.extra; } + sample_t const* out_pos() const { return m.out; } +public: + BLARGG_DISABLE_NOTHROW + + typedef BOOST::int8_t int8_t; + typedef BOOST::int16_t int16_t; + + enum { echo_hist_size = 8 }; + + enum env_mode_t { env_release, env_attack, env_decay, env_sustain }; + enum { brr_buf_size = 12 }; + struct voice_t + { + int buf [brr_buf_size*2];// decoded samples (twice the size to simplify wrap handling) + int* buf_pos; // place in buffer where next samples will be decoded + int interp_pos; // relative fractional position in sample (0x1000 = 1.0) + int brr_addr; // address of current BRR block + int brr_offset; // current decoding offset in BRR block + int kon_delay; // KON delay/current setup phase + env_mode_t env_mode; + int env; // current envelope level + int hidden_env; // used by GAIN mode 7, very obscure quirk + int volume [2]; // copy of volume from DSP registers, with surround disabled + int enabled; // -1 if enabled, 0 if muted + }; +private: + struct state_t + { + uint8_t regs [register_count]; + + // Echo history keeps most recent 8 samples (twice the size to simplify wrap handling) + int echo_hist [echo_hist_size * 2] [2]; + int (*echo_hist_pos) [2]; // &echo_hist [0 to 7] + + int every_other_sample; // toggles every sample + int kon; // KON value when last checked + int noise; + int echo_offset; // offset from ESA in echo buffer + int echo_length; // number of bytes that echo_offset will stop at + int phase; // next clock cycle to run (0-31) + unsigned counters [4]; + + int new_kon; + int t_koff; + + voice_t voices [voice_count]; + + unsigned* counter_select [32]; + + // non-emulation state + uint8_t* ram; // 64K shared RAM between DSP and SMP + int mute_mask; + int surround_threshold; + sample_t* out; + sample_t* out_end; + sample_t* out_begin; + sample_t extra [extra_size]; + }; + state_t m; + + void init_counter(); + void run_counter( int ); + void soft_reset_common(); + void write_outline( int addr, int data ); + void update_voice_vol( int addr ); +}; + +#include + +inline int Spc_Dsp::sample_count() const { return m.out - m.out_begin; } + +inline int Spc_Dsp::read( int addr ) const +{ + assert( (unsigned) addr < register_count ); + return m.regs [addr]; +} + +inline void Spc_Dsp::update_voice_vol( int addr ) +{ + int l = (int8_t) m.regs [addr + v_voll]; + int r = (int8_t) m.regs [addr + v_volr]; + + if ( l * r < m.surround_threshold ) + { + // signs differ, so negate those that are negative + l ^= l >> 7; + r ^= r >> 7; + } + + voice_t& v = m.voices [addr >> 4]; + int enabled = v.enabled; + v.volume [0] = l & enabled; + v.volume [1] = r & enabled; +} + +inline void Spc_Dsp::write( int addr, int data ) +{ + assert( (unsigned) addr < register_count ); + + m.regs [addr] = (uint8_t) data; + int low = addr & 0x0F; + if ( low < 0x2 ) // voice volumes + { + update_voice_vol( low ^ addr ); + } + else if ( low == 0xC ) + { + if ( addr == r_kon ) + m.new_kon = (uint8_t) data; + + if ( addr == r_endx ) // always cleared, regardless of data written + m.regs [r_endx] = 0; + } +} + +inline void Spc_Dsp::disable_surround( bool disable ) +{ + m.surround_threshold = disable ? 0 : -0x4000; +} + +#define SPC_NO_COPY_STATE_FUNCS 1 + +#define SPC_LESS_ACCURATE 1 + +#endif diff --git a/libs/gme/gme/Spc_Emu.cpp b/libs/gme/gme/Spc_Emu.cpp new file mode 100644 index 000000000..b3c20f317 --- /dev/null +++ b/libs/gme/gme/Spc_Emu.cpp @@ -0,0 +1,352 @@ +// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/ + +#include "Spc_Emu.h" + +#include "blargg_endian.h" +#include +#include + +/* Copyright (C) 2004-2006 Shay Green. This module 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 +module 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 module; if not, write to the Free Software Foundation, +Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + +#include "blargg_source.h" + +// TODO: support Spc_Filter's bass + +Spc_Emu::Spc_Emu() +{ + set_type( gme_spc_type ); + + static const char* const names [Snes_Spc::voice_count] = { + "DSP 1", "DSP 2", "DSP 3", "DSP 4", "DSP 5", "DSP 6", "DSP 7", "DSP 8" + }; + set_voice_names( names ); + + set_gain( 1.4 ); +} + +Spc_Emu::~Spc_Emu() { } + +// Track info + +long const trailer_offset = 0x10200; + +byte const* Spc_Emu::trailer() const { return &file_data [min( file_size, trailer_offset )]; } + +long Spc_Emu::trailer_size() const { return max( 0L, file_size - trailer_offset ); } + +static void get_spc_xid6( byte const* begin, long size, track_info_t* out ) +{ + // header + byte const* end = begin + size; + if ( size < 8 || memcmp( begin, "xid6", 4 ) ) + { + check( false ); + return; + } + long info_size = get_le32( begin + 4 ); + byte const* in = begin + 8; + if ( end - in > info_size ) + { + debug_printf( "Extra data after SPC xid6 info\n" ); + end = in + info_size; + } + + int year = 0; + char copyright [256 + 5]; + int copyright_len = 0; + int const year_len = 5; + + while ( end - in >= 4 ) + { + // header + int id = in [0]; + int data = in [3] * 0x100 + in [2]; + int type = in [1]; + int len = type ? data : 0; + in += 4; + if ( len > end - in ) + { + check( false ); + break; // block goes past end of data + } + + // handle specific block types + char* field = 0; + switch ( id ) + { + case 0x01: field = out->song; break; + case 0x02: field = out->game; break; + case 0x03: field = out->author; break; + case 0x04: field = out->dumper; break; + case 0x07: field = out->comment; break; + case 0x14: year = data; break; + + //case 0x30: // intro length + // Many SPCs have intro length set wrong for looped tracks, making it useless + /* + case 0x30: + check( len == 4 ); + if ( len >= 4 ) + { + out->intro_length = get_le32( in ) / 64; + if ( out->length > 0 ) + { + long loop = out->length - out->intro_length; + if ( loop >= 2000 ) + out->loop_length = loop; + } + } + break; + */ + + case 0x13: + copyright_len = min( len, (int) sizeof copyright - year_len ); + memcpy( ©right [year_len], in, copyright_len ); + break; + + default: + if ( id < 0x01 || (id > 0x07 && id < 0x10) || + (id > 0x14 && id < 0x30) || id > 0x36 ) + debug_printf( "Unknown SPC xid6 block: %X\n", (int) id ); + break; + } + if ( field ) + { + check( type == 1 ); + Gme_File::copy_field_( field, (char const*) in, len ); + } + + // skip to next block + in += len; + + // blocks are supposed to be 4-byte aligned with zero-padding... + byte const* unaligned = in; + while ( (in - begin) & 3 && in < end ) + { + if ( *in++ != 0 ) + { + // ...but some files have no padding + in = unaligned; + debug_printf( "SPC info tag wasn't properly padded to align\n" ); + break; + } + } + } + + char* p = ©right [year_len]; + if ( year ) + { + *--p = ' '; + for ( int n = 4; n--; ) + { + *--p = char (year % 10 + '0'); + year /= 10; + } + copyright_len += year_len; + } + if ( copyright_len ) + Gme_File::copy_field_( out->copyright, p, copyright_len ); + + check( in == end ); +} + +static void get_spc_info( Spc_Emu::header_t const& h, byte const* xid6, long xid6_size, + track_info_t* out ) +{ + // decode length (can be in text or binary format, sometimes ambiguous ugh) + long len_secs = 0; + for ( int i = 0; i < 3; i++ ) + { + unsigned n = h.len_secs [i] - '0'; + if ( n > 9 ) + { + // ignore single-digit text lengths + // (except if author field is present and begins at offset 1, ugh) + if ( i == 1 && (h.author [0] || !h.author [1]) ) + len_secs = 0; + break; + } + len_secs *= 10; + len_secs += n; + } + if ( !len_secs || len_secs > 0x1FFF ) + len_secs = get_le16( h.len_secs ); + if ( len_secs < 0x1FFF ) + out->length = len_secs * 1000; + + int offset = (h.author [0] < ' ' || unsigned (h.author [0] - '0') <= 9); + Gme_File::copy_field_( out->author, &h.author [offset], sizeof h.author - offset ); + + GME_COPY_FIELD( h, out, song ); + GME_COPY_FIELD( h, out, game ); + GME_COPY_FIELD( h, out, dumper ); + GME_COPY_FIELD( h, out, comment ); + + if ( xid6_size ) + get_spc_xid6( xid6, xid6_size, out ); +} + +blargg_err_t Spc_Emu::track_info_( track_info_t* out, int ) const +{ + get_spc_info( header(), trailer(), trailer_size(), out ); + return 0; +} + +static blargg_err_t check_spc_header( void const* header ) +{ + if ( memcmp( header, "SNES-SPC700 Sound File Data", 27 ) ) + return gme_wrong_file_type; + return 0; +} + +struct Spc_File : Gme_Info_ +{ + Spc_Emu::header_t header; + blargg_vector xid6; + + Spc_File() { set_type( gme_spc_type ); } + + blargg_err_t load_( Data_Reader& in ) + { + long file_size = in.remain(); + if ( file_size < Snes_Spc::spc_min_file_size ) + return gme_wrong_file_type; + RETURN_ERR( in.read( &header, Spc_Emu::header_size ) ); + RETURN_ERR( check_spc_header( header.tag ) ); + long const xid6_offset = 0x10200; + long xid6_size = file_size - xid6_offset; + if ( xid6_size > 0 ) + { + RETURN_ERR( xid6.resize( xid6_size ) ); + RETURN_ERR( in.skip( xid6_offset - Spc_Emu::header_size ) ); + RETURN_ERR( in.read( xid6.begin(), xid6.size() ) ); + } + return 0; + } + + blargg_err_t track_info_( track_info_t* out, int ) const + { + get_spc_info( header, xid6.begin(), xid6.size(), out ); + return 0; + } +}; + +static Music_Emu* new_spc_emu () { return BLARGG_NEW Spc_Emu ; } +static Music_Emu* new_spc_file() { return BLARGG_NEW Spc_File; } + +static gme_type_t_ const gme_spc_type_ = { "Super Nintendo", 1, &new_spc_emu, &new_spc_file, "SPC", 0 }; +gme_type_t const gme_spc_type = &gme_spc_type_; + + +// Setup + +blargg_err_t Spc_Emu::set_sample_rate_( long sample_rate ) +{ + RETURN_ERR( apu.init() ); + enable_accuracy( false ); + if ( sample_rate != native_sample_rate ) + { + RETURN_ERR( resampler.buffer_size( native_sample_rate / 20 * 2 ) ); + resampler.time_ratio( (double) native_sample_rate / sample_rate, 0.9965 ); + } + return 0; +} + +void Spc_Emu::enable_accuracy_( bool b ) +{ + Music_Emu::enable_accuracy_( b ); + filter.enable( b ); +} + +void Spc_Emu::mute_voices_( int m ) +{ + Music_Emu::mute_voices_( m ); + apu.mute_voices( m ); +} + +blargg_err_t Spc_Emu::load_mem_( byte const* in, long size ) +{ + assert( offsetof (header_t,unused2 [46]) == header_size ); + file_data = in; + file_size = size; + set_voice_count( Snes_Spc::voice_count ); + if ( size < Snes_Spc::spc_min_file_size ) + return gme_wrong_file_type; + return check_spc_header( in ); +} + +// Emulation + +void Spc_Emu::set_tempo_( double t ) +{ + apu.set_tempo( (int) (t * apu.tempo_unit) ); +} + +blargg_err_t Spc_Emu::start_track_( int track ) +{ + RETURN_ERR( Music_Emu::start_track_( track ) ); + resampler.clear(); + filter.clear(); + RETURN_ERR( apu.load_spc( file_data, file_size ) ); + filter.set_gain( (int) (gain() * SPC_Filter::gain_unit) ); + apu.clear_echo(); + return 0; +} + +blargg_err_t Spc_Emu::play_and_filter( long count, sample_t out [] ) +{ + RETURN_ERR( apu.play( count, out ) ); + filter.run( out, count ); + return 0; +} + +blargg_err_t Spc_Emu::skip_( long count ) +{ + if ( sample_rate() != native_sample_rate ) + { + count = long (count * resampler.ratio()) & ~1; + count -= resampler.skip_input( count ); + } + + // TODO: shouldn't skip be adjusted for the 64 samples read afterwards? + + if ( count > 0 ) + { + RETURN_ERR( apu.skip( count ) ); + filter.clear(); + } + + // eliminate pop due to resampler + const int resampler_latency = 64; + sample_t buf [resampler_latency]; + return play_( resampler_latency, buf ); +} + +blargg_err_t Spc_Emu::play_( long count, sample_t* out ) +{ + if ( sample_rate() == native_sample_rate ) + return play_and_filter( count, out ); + + long remain = count; + while ( remain > 0 ) + { + remain -= resampler.read( &out [count - remain], remain ); + if ( remain > 0 ) + { + long n = resampler.max_write(); + RETURN_ERR( play_and_filter( n, resampler.buffer() ) ); + resampler.write( n ); + } + } + check( remain == 0 ); + return 0; +} diff --git a/libs/gme/gme/Spc_Emu.h b/libs/gme/gme/Spc_Emu.h new file mode 100644 index 000000000..09063f123 --- /dev/null +++ b/libs/gme/gme/Spc_Emu.h @@ -0,0 +1,82 @@ +// Super Nintendo SPC music file emulator + +// Game_Music_Emu 0.6.0 +#ifndef SPC_EMU_H +#define SPC_EMU_H + +#include "Fir_Resampler.h" +#include "Music_Emu.h" +#include "Snes_Spc.h" +#include "Spc_Filter.h" + +class Spc_Emu : public Music_Emu { +public: + // The Super Nintendo hardware samples at 32kHz. Other sample rates are + // handled by resampling the 32kHz output; emulation accuracy is not affected. + enum { native_sample_rate = 32000 }; + + // SPC file header + enum { header_size = 0x100 }; + struct header_t + { + char tag [35]; + byte format; + byte version; + byte pc [2]; + byte a, x, y, psw, sp; + byte unused [2]; + char song [32]; + char game [32]; + char dumper [16]; + char comment [32]; + byte date [11]; + byte len_secs [3]; + byte fade_msec [4]; + char author [32]; // sometimes first char should be skipped (see official SPC spec) + byte mute_mask; + byte emulator; + byte unused2 [46]; + }; + + // Header for currently loaded file + header_t const& header() const { return *(header_t const*) file_data; } + + // Prevents channels and global volumes from being phase-negated + void disable_surround( bool disable = true ); + + static gme_type_t static_type() { return gme_spc_type; } + +public: + // deprecated + using Music_Emu::load; + blargg_err_t load( header_t const& h, Data_Reader& in ) // use Remaining_Reader + { return load_remaining_( &h, sizeof h, in ); } + byte const* trailer() const; // use track_info() + long trailer_size() const; + +public: + Spc_Emu(); + ~Spc_Emu(); +protected: + blargg_err_t load_mem_( byte const*, long ); + blargg_err_t track_info_( track_info_t*, int track ) const; + blargg_err_t set_sample_rate_( long ); + blargg_err_t start_track_( int ); + blargg_err_t play_( long, sample_t* ); + blargg_err_t skip_( long ); + void mute_voices_( int ); + void set_tempo_( double ); + void enable_accuracy_( bool ); +private: + byte const* file_data; + long file_size; + Fir_Resampler<24> resampler; + SPC_Filter filter; + Snes_Spc apu; + + blargg_err_t play_and_filter( long count, sample_t out [] ); +}; + +inline void Spc_Emu::disable_surround( bool b ) { apu.disable_surround( b ); } + +#endif diff --git a/libs/gme/gme/Spc_Filter.cpp b/libs/gme/gme/Spc_Filter.cpp new file mode 100644 index 000000000..0f2d18a83 --- /dev/null +++ b/libs/gme/gme/Spc_Filter.cpp @@ -0,0 +1,83 @@ +// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/ + +#include "Spc_Filter.h" + +#include + +/* Copyright (C) 2007 Shay Green. This module 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 +module 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 module; if not, write to the Free Software Foundation, +Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + +#include "blargg_source.h" + +void SPC_Filter::clear() { memset( ch, 0, sizeof ch ); } + +SPC_Filter::SPC_Filter() +{ + enabled = true; + gain = gain_unit; + bass = bass_norm; + clear(); +} + +void SPC_Filter::run( short* io, int count ) +{ + require( (count & 1) == 0 ); // must be even + + int const gain = this->gain; + if ( enabled ) + { + int const bass = this->bass; + chan_t* c = &ch [2]; + do + { + // cache in registers + int sum = (--c)->sum; + int pp1 = c->pp1; + int p1 = c->p1; + + for ( int i = 0; i < count; i += 2 ) + { + // Low-pass filter (two point FIR with coeffs 0.25, 0.75) + int f = io [i] + p1; + p1 = io [i] * 3; + + // High-pass filter ("leaky integrator") + int delta = f - pp1; + pp1 = f; + int s = sum >> (gain_bits + 2); + sum += (delta * gain) - (sum >> bass); + + // Clamp to 16 bits + if ( (short) s != s ) + s = (s >> 31) ^ 0x7FFF; + + io [i] = (short) s; + } + + c->p1 = p1; + c->pp1 = pp1; + c->sum = sum; + ++io; + } + while ( c != ch ); + } + else if ( gain != gain_unit ) + { + short* const end = io + count; + while ( io < end ) + { + int s = (*io * gain) >> gain_bits; + if ( (short) s != s ) + s = (s >> 31) ^ 0x7FFF; + *io++ = (short) s; + } + } +} diff --git a/libs/gme/gme/Spc_Filter.h b/libs/gme/gme/Spc_Filter.h new file mode 100644 index 000000000..5cdcc3606 --- /dev/null +++ b/libs/gme/gme/Spc_Filter.h @@ -0,0 +1,53 @@ +// Simple low-pass and high-pass filter to better match sound output of a SNES + +// Game_Music_Emu 0.6.0 +#ifndef SPC_FILTER_H +#define SPC_FILTER_H + +#include "blargg_common.h" + +struct SPC_Filter { +public: + + // Filters count samples of stereo sound in place. Count must be a multiple of 2. + typedef short sample_t; + void run( sample_t* io, int count ); + +// Optional features + + // Clears filter to silence + void clear(); + + // Sets gain (volume), where gain_unit is normal. Gains greater than gain_unit + // are fine, since output is clamped to 16-bit sample range. + enum { gain_unit = 0x100 }; + void set_gain( int gain ); + + // Enables/disables filtering (when disabled, gain is still applied) + void enable( bool b ); + + // Sets amount of bass (logarithmic scale) + enum { bass_none = 0 }; + enum { bass_norm = 8 }; // normal amount + enum { bass_max = 31 }; + void set_bass( int bass ); + +public: + SPC_Filter(); + BLARGG_DISABLE_NOTHROW +private: + enum { gain_bits = 8 }; + int gain; + int bass; + bool enabled; + struct chan_t { int p1, pp1, sum; }; + chan_t ch [2]; +}; + +inline void SPC_Filter::enable( bool b ) { enabled = b; } + +inline void SPC_Filter::set_gain( int g ) { gain = g; } + +inline void SPC_Filter::set_bass( int b ) { bass = b; } + +#endif diff --git a/libs/gme/gme/Vgm_Emu.cpp b/libs/gme/gme/Vgm_Emu.cpp new file mode 100644 index 000000000..5c6bc7cda --- /dev/null +++ b/libs/gme/gme/Vgm_Emu.cpp @@ -0,0 +1,415 @@ +// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/ + +#include "Vgm_Emu.h" + +#include "blargg_endian.h" +#include +#include + +/* Copyright (C) 2003-2006 Shay Green. This module 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 +module 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 module; if not, write to the Free Software Foundation, +Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + +#include "blargg_source.h" + +double const fm_gain = 3.0; // FM emulators are internally quieter to avoid 16-bit overflow +double const rolloff = 0.990; +double const oversample_factor = 1.5; + +Vgm_Emu::Vgm_Emu() +{ + disable_oversampling_ = false; + psg_rate = 0; + set_type( gme_vgm_type ); + + static int const types [8] = { + wave_type | 1, wave_type | 0, wave_type | 2, noise_type | 0 + }; + set_voice_types( types ); + + set_silence_lookahead( 1 ); // tracks should already be trimmed + + set_equalizer( make_equalizer( -14.0, 80 ) ); +} + +Vgm_Emu::~Vgm_Emu() { } + +// Track info + +static byte const* skip_gd3_str( byte const* in, byte const* end ) +{ + while ( end - in >= 2 ) + { + in += 2; + if ( !(in [-2] | in [-1]) ) + break; + } + return in; +} + +static byte const* get_gd3_str( byte const* in, byte const* end, char* field ) +{ + byte const* mid = skip_gd3_str( in, end ); + int len = (mid - in) / 2 - 1; + if ( len > 0 ) + { + len = min( len, (int) Gme_File::max_field_ ); + field [len] = 0; + for ( int i = 0; i < len; i++ ) + field [i] = (in [i * 2 + 1] ? '?' : in [i * 2]); // TODO: convert to utf-8 + } + return mid; +} + +static byte const* get_gd3_pair( byte const* in, byte const* end, char* field ) +{ + return skip_gd3_str( get_gd3_str( in, end, field ), end ); +} + +static void parse_gd3( byte const* in, byte const* end, track_info_t* out ) +{ + in = get_gd3_pair( in, end, out->song ); + in = get_gd3_pair( in, end, out->game ); + in = get_gd3_pair( in, end, out->system ); + in = get_gd3_pair( in, end, out->author ); + in = get_gd3_str ( in, end, out->copyright ); + in = get_gd3_pair( in, end, out->dumper ); + in = get_gd3_str ( in, end, out->comment ); +} + +int const gd3_header_size = 12; + +static long check_gd3_header( byte const* h, long remain ) +{ + if ( remain < gd3_header_size ) return 0; + if ( memcmp( h, "Gd3 ", 4 ) ) return 0; + if ( get_le32( h + 4 ) >= 0x200 ) return 0; + + long gd3_size = get_le32( h + 8 ); + if ( gd3_size > remain - gd3_header_size ) return 0; + + return gd3_size; +} + +byte const* Vgm_Emu::gd3_data( int* size ) const +{ + if ( size ) + *size = 0; + + long gd3_offset = get_le32( header().gd3_offset ) - 0x2C; + if ( gd3_offset < 0 ) + return 0; + + byte const* gd3 = data + header_size + gd3_offset; + long gd3_size = check_gd3_header( gd3, data_end - gd3 ); + if ( !gd3_size ) + return 0; + + if ( size ) + *size = gd3_size + gd3_header_size; + + return gd3; +} + +static void get_vgm_length( Vgm_Emu::header_t const& h, track_info_t* out ) +{ + long length = get_le32( h.track_duration ) * 10 / 441; + if ( length > 0 ) + { + long loop = get_le32( h.loop_duration ); + if ( loop > 0 && get_le32( h.loop_offset ) ) + { + out->loop_length = loop * 10 / 441; + out->intro_length = length - out->loop_length; + } + else + { + out->length = length; // 1000 / 44100 (VGM files used 44100 as timebase) + out->intro_length = length; // make it clear that track is no longer than length + out->loop_length = 0; + } + } +} + +blargg_err_t Vgm_Emu::track_info_( track_info_t* out, int ) const +{ + get_vgm_length( header(), out ); + + int size; + byte const* gd3 = gd3_data( &size ); + if ( gd3 ) + parse_gd3( gd3 + gd3_header_size, gd3 + size, out ); + + return 0; +} + +static blargg_err_t check_vgm_header( Vgm_Emu::header_t const& h ) +{ + if ( memcmp( h.tag, "Vgm ", 4 ) ) + return gme_wrong_file_type; + return 0; +} + +struct Vgm_File : Gme_Info_ +{ + Vgm_Emu::header_t h; + blargg_vector gd3; + + Vgm_File() { set_type( gme_vgm_type ); } + + blargg_err_t load_( Data_Reader& in ) + { + long file_size = in.remain(); + if ( file_size <= Vgm_Emu::header_size ) + return gme_wrong_file_type; + + RETURN_ERR( in.read( &h, Vgm_Emu::header_size ) ); + RETURN_ERR( check_vgm_header( h ) ); + + long gd3_offset = get_le32( h.gd3_offset ) - 0x2C; + long remain = file_size - Vgm_Emu::header_size - gd3_offset; + byte gd3_h [gd3_header_size]; + if ( gd3_offset > 0 && remain >= gd3_header_size ) + { + RETURN_ERR( in.skip( gd3_offset ) ); + RETURN_ERR( in.read( gd3_h, sizeof gd3_h ) ); + long gd3_size = check_gd3_header( gd3_h, remain ); + if ( gd3_size ) + { + RETURN_ERR( gd3.resize( gd3_size ) ); + RETURN_ERR( in.read( gd3.begin(), gd3.size() ) ); + } + } + return 0; + } + + blargg_err_t track_info_( track_info_t* out, int ) const + { + get_vgm_length( h, out ); + if ( gd3.size() ) + parse_gd3( gd3.begin(), gd3.end(), out ); + return 0; + } +}; + +static Music_Emu* new_vgm_emu () { return BLARGG_NEW Vgm_Emu ; } +static Music_Emu* new_vgm_file() { return BLARGG_NEW Vgm_File; } + +static gme_type_t_ const gme_vgm_type_ = { "Sega SMS/Genesis", 1, &new_vgm_emu, &new_vgm_file, "VGM", 1 }; +gme_type_t const gme_vgm_type = &gme_vgm_type_; + +static gme_type_t_ const gme_vgz_type_ = { "Sega SMS/Genesis", 1, &new_vgm_emu, &new_vgm_file, "VGZ", 1 }; +gme_type_t const gme_vgz_type = &gme_vgz_type_; + + +// Setup + +void Vgm_Emu::set_tempo_( double t ) +{ + if ( psg_rate ) + { + vgm_rate = (long) (44100 * t + 0.5); + blip_time_factor = (long) floor( double (1L << blip_time_bits) / vgm_rate * psg_rate + 0.5 ); + //debug_printf( "blip_time_factor: %ld\n", blip_time_factor ); + //debug_printf( "vgm_rate: %ld\n", vgm_rate ); + // TODO: remove? calculates vgm_rate more accurately (above differs at most by one Hz only) + //blip_time_factor = (long) floor( double (1L << blip_time_bits) * psg_rate / 44100 / t + 0.5 ); + //vgm_rate = (long) floor( double (1L << blip_time_bits) * psg_rate / blip_time_factor + 0.5 ); + + fm_time_factor = 2 + (long) floor( fm_rate * (1L << fm_time_bits) / vgm_rate + 0.5 ); + } +} + +blargg_err_t Vgm_Emu::set_sample_rate_( long sample_rate ) +{ + RETURN_ERR( blip_buf.set_sample_rate( sample_rate, 1000 / 30 ) ); + return Classic_Emu::set_sample_rate_( sample_rate ); +} + +void Vgm_Emu::update_eq( blip_eq_t const& eq ) +{ + psg.treble_eq( eq ); + dac_synth.treble_eq( eq ); +} + +void Vgm_Emu::set_voice( int i, Blip_Buffer* c, Blip_Buffer* l, Blip_Buffer* r ) +{ + if ( i < psg.osc_count ) + psg.osc_output( i, c, l, r ); +} + +void Vgm_Emu::mute_voices_( int mask ) +{ + Classic_Emu::mute_voices_( mask ); + dac_synth.output( &blip_buf ); + if ( uses_fm ) + { + psg.output( (mask & 0x80) ? 0 : &blip_buf ); + if ( ym2612.enabled() ) + { + dac_synth.volume( (mask & 0x40) ? 0.0 : 0.1115 / 256 * fm_gain * gain() ); + ym2612.mute_voices( mask ); + } + + if ( ym2413.enabled() ) + { + int m = mask & 0x3F; + if ( mask & 0x20 ) + m |= 0x01E0; // channels 5-8 + if ( mask & 0x40 ) + m |= 0x3E00; + ym2413.mute_voices( m ); + } + } +} + +blargg_err_t Vgm_Emu::load_mem_( byte const* new_data, long new_size ) +{ + assert( offsetof (header_t,unused2 [8]) == header_size ); + + if ( new_size <= header_size ) + return gme_wrong_file_type; + + header_t const& h = *(header_t const*) new_data; + + RETURN_ERR( check_vgm_header( h ) ); + + check( get_le32( h.version ) <= 0x150 ); + + // psg rate + psg_rate = get_le32( h.psg_rate ); + if ( !psg_rate ) + psg_rate = 3579545; + blip_buf.clock_rate( psg_rate ); + + data = new_data; + data_end = new_data + new_size; + + // get loop + loop_begin = data_end; + if ( get_le32( h.loop_offset ) ) + loop_begin = &data [get_le32( h.loop_offset ) + offsetof (header_t,loop_offset)]; + + set_voice_count( psg.osc_count ); + + RETURN_ERR( setup_fm() ); + + static const char* const fm_names [] = { + "FM 1", "FM 2", "FM 3", "FM 4", "FM 5", "FM 6", "PCM", "PSG" + }; + static const char* const psg_names [] = { "Square 1", "Square 2", "Square 3", "Noise" }; + set_voice_names( uses_fm ? fm_names : psg_names ); + + // do after FM in case output buffer is changed + return Classic_Emu::setup_buffer( psg_rate ); +} + +blargg_err_t Vgm_Emu::setup_fm() +{ + long ym2612_rate = get_le32( header().ym2612_rate ); + long ym2413_rate = get_le32( header().ym2413_rate ); + if ( ym2413_rate && get_le32( header().version ) < 0x110 ) + update_fm_rates( &ym2413_rate, &ym2612_rate ); + + uses_fm = false; + + fm_rate = blip_buf.sample_rate() * oversample_factor; + + if ( ym2612_rate ) + { + uses_fm = true; + if ( disable_oversampling_ ) + fm_rate = ym2612_rate / 144.0; + Dual_Resampler::setup( fm_rate / blip_buf.sample_rate(), rolloff, fm_gain * gain() ); + RETURN_ERR( ym2612.set_rate( fm_rate, ym2612_rate ) ); + ym2612.enable( true ); + set_voice_count( 8 ); + } + + if ( !uses_fm && ym2413_rate ) + { + uses_fm = true; + if ( disable_oversampling_ ) + fm_rate = ym2413_rate / 72.0; + Dual_Resampler::setup( fm_rate / blip_buf.sample_rate(), rolloff, fm_gain * gain() ); + int result = ym2413.set_rate( fm_rate, ym2413_rate ); + if ( result == 2 ) + return "YM2413 FM sound isn't supported"; + CHECK_ALLOC( !result ); + ym2413.enable( true ); + set_voice_count( 8 ); + } + + if ( uses_fm ) + { + RETURN_ERR( Dual_Resampler::reset( blip_buf.length() * blip_buf.sample_rate() / 1000 ) ); + psg.volume( 0.135 * fm_gain * gain() ); + } + else + { + ym2612.enable( false ); + ym2413.enable( false ); + psg.volume( gain() ); + } + + return 0; +} + +// Emulation + +blargg_err_t Vgm_Emu::start_track_( int track ) +{ + RETURN_ERR( Classic_Emu::start_track_( track ) ); + psg.reset( get_le16( header().noise_feedback ), header().noise_width ); + + dac_disabled = -1; + pos = data + header_size; + pcm_data = pos; + pcm_pos = pos; + dac_amp = -1; + vgm_time = 0; + if ( get_le32( header().version ) >= 0x150 ) + { + long data_offset = get_le32( header().data_offset ); + check( data_offset ); + if ( data_offset ) + pos += data_offset + offsetof (header_t,data_offset) - 0x40; + } + + if ( uses_fm ) + { + if ( ym2413.enabled() ) + ym2413.reset(); + + if ( ym2612.enabled() ) + ym2612.reset(); + + fm_time_offset = 0; + blip_buf.clear(); + Dual_Resampler::clear(); + } + return 0; +} + +blargg_err_t Vgm_Emu::run_clocks( blip_time_t& time_io, int msec ) +{ + time_io = run_commands( msec * vgm_rate / 1000 ); + psg.end_frame( time_io ); + return 0; +} + +blargg_err_t Vgm_Emu::play_( long count, sample_t* out ) +{ + if ( !uses_fm ) + return Classic_Emu::play_( count, out ); + + Dual_Resampler::dual_play( count, out, blip_buf ); + return 0; +} diff --git a/libs/gme/gme/Vgm_Emu.h b/libs/gme/gme/Vgm_Emu.h new file mode 100644 index 000000000..65895afaa --- /dev/null +++ b/libs/gme/gme/Vgm_Emu.h @@ -0,0 +1,84 @@ +// Sega Master System/Mark III, Sega Genesis/Mega Drive, BBC Micro VGM music file emulator + +// Game_Music_Emu 0.6.0 +#ifndef VGM_EMU_H +#define VGM_EMU_H + +#include "Vgm_Emu_Impl.h" + +// Emulates VGM music using SN76489/SN76496 PSG, YM2612, and YM2413 FM sound chips. +// Supports custom sound buffer and frequency equalization when VGM uses just the PSG. +// FM sound chips can be run at their proper rates, or slightly higher to reduce +// aliasing on high notes. Currently YM2413 support requires that you supply a +// YM2413 sound chip emulator. I can provide one I've modified to work with the library. +class Vgm_Emu : public Vgm_Emu_Impl { +public: + // True if custom buffer and custom equalization are supported + // TODO: move into Music_Emu and rename to something like supports_custom_buffer() + bool is_classic_emu() const { return !uses_fm; } + + // Disable running FM chips at higher than normal rate. Will result in slightly + // more aliasing of high notes. + void disable_oversampling( bool disable = true ) { disable_oversampling_ = disable; } + + // VGM header format + enum { header_size = 0x40 }; + struct header_t + { + char tag [4]; + byte data_size [4]; + byte version [4]; + byte psg_rate [4]; + byte ym2413_rate [4]; + byte gd3_offset [4]; + byte track_duration [4]; + byte loop_offset [4]; + byte loop_duration [4]; + byte frame_rate [4]; + byte noise_feedback [2]; + byte noise_width; + byte unused1; + byte ym2612_rate [4]; + byte ym2151_rate [4]; + byte data_offset [4]; + byte unused2 [8]; + }; + + // Header for currently loaded file + header_t const& header() const { return *(header_t const*) data; } + + static gme_type_t static_type() { return gme_vgm_type; } + +public: + // deprecated + using Music_Emu::load; + blargg_err_t load( header_t const& h, Data_Reader& in ) // use Remaining_Reader + { return load_remaining_( &h, sizeof h, in ); } + byte const* gd3_data( int* size_out = 0 ) const; // use track_info() + +public: + Vgm_Emu(); + ~Vgm_Emu(); +protected: + blargg_err_t track_info_( track_info_t*, int track ) const; + blargg_err_t load_mem_( byte const*, long ); + blargg_err_t set_sample_rate_( long sample_rate ); + blargg_err_t start_track_( int ); + blargg_err_t play_( long count, sample_t* ); + blargg_err_t run_clocks( blip_time_t&, int ); + void set_tempo_( double ); + void mute_voices_( int mask ); + void set_voice( int, Blip_Buffer*, Blip_Buffer*, Blip_Buffer* ); + void update_eq( blip_eq_t const& ); +private: + // removed; use disable_oversampling() and set_tempo() instead + Vgm_Emu( bool oversample, double tempo = 1.0 ); + double fm_rate; + long psg_rate; + long vgm_rate; + bool disable_oversampling_; + bool uses_fm; + blargg_err_t setup_fm(); +}; + +#endif diff --git a/libs/gme/gme/Vgm_Emu_Impl.cpp b/libs/gme/gme/Vgm_Emu_Impl.cpp new file mode 100644 index 000000000..60dc099fe --- /dev/null +++ b/libs/gme/gme/Vgm_Emu_Impl.cpp @@ -0,0 +1,314 @@ +// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/ + +#include "Vgm_Emu.h" + +#include +#include +#include "blargg_endian.h" + +/* Copyright (C) 2003-2006 Shay Green. This module 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 +module 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 module; if not, write to the Free Software Foundation, +Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + +#include "blargg_source.h" + +enum { + cmd_gg_stereo = 0x4F, + cmd_psg = 0x50, + cmd_ym2413 = 0x51, + cmd_ym2612_port0 = 0x52, + cmd_ym2612_port1 = 0x53, + cmd_ym2151 = 0x54, + cmd_delay = 0x61, + cmd_delay_735 = 0x62, + cmd_delay_882 = 0x63, + cmd_byte_delay = 0x64, + cmd_end = 0x66, + cmd_data_block = 0x67, + cmd_short_delay = 0x70, + cmd_pcm_delay = 0x80, + cmd_pcm_seek = 0xE0, + + pcm_block_type = 0x00, + ym2612_dac_port = 0x2A +}; + +inline int command_len( int command ) +{ + switch ( command >> 4 ) + { + case 0x03: + case 0x04: + return 2; + + case 0x05: + case 0x0A: + case 0x0B: + return 3; + + case 0x0C: + case 0x0D: + return 4; + + case 0x0E: + case 0x0F: + return 5; + } + + check( false ); + return 1; +} + +template +inline void Ym_Emu::begin_frame( short* p ) +{ + require( enabled() ); + out = p; + last_time = 0; +} + +template +inline int Ym_Emu::run_until( int time ) +{ + int count = time - last_time; + if ( count > 0 ) + { + if ( last_time < 0 ) + return false; + last_time = time; + short* p = out; + out += count * Emu::out_chan_count; + Emu::run( count, p ); + } + return true; +} + +inline Vgm_Emu_Impl::fm_time_t Vgm_Emu_Impl::to_fm_time( vgm_time_t t ) const +{ + return (t * fm_time_factor + fm_time_offset) >> fm_time_bits; +} + +inline blip_time_t Vgm_Emu_Impl::to_blip_time( vgm_time_t t ) const +{ + return (t * blip_time_factor) >> blip_time_bits; +} + +void Vgm_Emu_Impl::write_pcm( vgm_time_t vgm_time, int amp ) +{ + blip_time_t blip_time = to_blip_time( vgm_time ); + int old = dac_amp; + int delta = amp - old; + dac_amp = amp; + if ( old >= 0 ) + dac_synth.offset_inline( blip_time, delta, &blip_buf ); + else + dac_amp |= dac_disabled; +} + +blip_time_t Vgm_Emu_Impl::run_commands( vgm_time_t end_time ) +{ + vgm_time_t vgm_time = this->vgm_time; + byte const* pos = this->pos; + if ( pos >= data_end ) + { + set_track_ended(); + if ( pos > data_end ) + set_warning( "Stream lacked end event" ); + } + + while ( vgm_time < end_time && pos < data_end ) + { + // TODO: be sure there are enough bytes left in stream for particular command + // so we don't read past end + switch ( *pos++ ) + { + case cmd_end: + pos = loop_begin; // if not looped, loop_begin == data_end + break; + + case cmd_delay_735: + vgm_time += 735; + break; + + case cmd_delay_882: + vgm_time += 882; + break; + + case cmd_gg_stereo: + psg.write_ggstereo( to_blip_time( vgm_time ), *pos++ ); + break; + + case cmd_psg: + psg.write_data( to_blip_time( vgm_time ), *pos++ ); + break; + + case cmd_delay: + vgm_time += pos [1] * 0x100L + pos [0]; + pos += 2; + break; + + case cmd_byte_delay: + vgm_time += *pos++; + break; + + case cmd_ym2413: + if ( ym2413.run_until( to_fm_time( vgm_time ) ) ) + ym2413.write( pos [0], pos [1] ); + pos += 2; + break; + + case cmd_ym2612_port0: + if ( pos [0] == ym2612_dac_port ) + { + write_pcm( vgm_time, pos [1] ); + } + else if ( ym2612.run_until( to_fm_time( vgm_time ) ) ) + { + if ( pos [0] == 0x2B ) + { + dac_disabled = (pos [1] >> 7 & 1) - 1; + dac_amp |= dac_disabled; + } + ym2612.write0( pos [0], pos [1] ); + } + pos += 2; + break; + + case cmd_ym2612_port1: + if ( ym2612.run_until( to_fm_time( vgm_time ) ) ) + ym2612.write1( pos [0], pos [1] ); + pos += 2; + break; + + case cmd_data_block: { + check( *pos == cmd_end ); + int type = pos [1]; + long size = get_le32( pos + 2 ); + pos += 6; + if ( type == pcm_block_type ) + pcm_data = pos; + pos += size; + break; + } + + case cmd_pcm_seek: + pcm_pos = pcm_data + pos [3] * 0x1000000L + pos [2] * 0x10000L + + pos [1] * 0x100L + pos [0]; + pos += 4; + break; + + default: + int cmd = pos [-1]; + switch ( cmd & 0xF0 ) + { + case cmd_pcm_delay: + write_pcm( vgm_time, *pcm_pos++ ); + vgm_time += cmd & 0x0F; + break; + + case cmd_short_delay: + vgm_time += (cmd & 0x0F) + 1; + break; + + case 0x50: + pos += 2; + break; + + default: + pos += command_len( cmd ) - 1; + set_warning( "Unknown stream event" ); + } + } + } + vgm_time -= end_time; + this->pos = pos; + this->vgm_time = vgm_time; + + return to_blip_time( end_time ); +} + +int Vgm_Emu_Impl::play_frame( blip_time_t blip_time, int sample_count, sample_t* buf ) +{ + // to do: timing is working mostly by luck + + int min_pairs = sample_count >> 1; + int vgm_time = ((long) min_pairs << fm_time_bits) / fm_time_factor - 1; + assert( to_fm_time( vgm_time ) <= min_pairs ); + int pairs = min_pairs; + while ( (pairs = to_fm_time( vgm_time )) < min_pairs ) + vgm_time++; + //debug_printf( "pairs: %d, min_pairs: %d\n", pairs, min_pairs ); + + if ( ym2612.enabled() ) + { + ym2612.begin_frame( buf ); + memset( buf, 0, pairs * stereo * sizeof *buf ); + } + else if ( ym2413.enabled() ) + { + ym2413.begin_frame( buf ); + } + + run_commands( vgm_time ); + ym2612.run_until( pairs ); + ym2413.run_until( pairs ); + + fm_time_offset = (vgm_time * fm_time_factor + fm_time_offset) - + ((long) pairs << fm_time_bits); + + psg.end_frame( blip_time ); + + return pairs * stereo; +} + +// Update pre-1.10 header FM rates by scanning commands +void Vgm_Emu_Impl::update_fm_rates( long* ym2413_rate, long* ym2612_rate ) const +{ + byte const* p = data + 0x40; + while ( p < data_end ) + { + switch ( *p ) + { + case cmd_end: + return; + + case cmd_psg: + case cmd_byte_delay: + p += 2; + break; + + case cmd_delay: + p += 3; + break; + + case cmd_data_block: + p += 7 + get_le32( p + 3 ); + break; + + case cmd_ym2413: + *ym2612_rate = 0; + return; + + case cmd_ym2612_port0: + case cmd_ym2612_port1: + *ym2612_rate = *ym2413_rate; + *ym2413_rate = 0; + return; + + case cmd_ym2151: + *ym2413_rate = 0; + *ym2612_rate = 0; + return; + + default: + p += command_len( *p ); + } + } +} diff --git a/libs/gme/gme/Vgm_Emu_Impl.h b/libs/gme/gme/Vgm_Emu_Impl.h new file mode 100644 index 000000000..b50094a01 --- /dev/null +++ b/libs/gme/gme/Vgm_Emu_Impl.h @@ -0,0 +1,71 @@ +// Low-level parts of Vgm_Emu + +// Game_Music_Emu 0.6.0 +#ifndef VGM_EMU_IMPL_H +#define VGM_EMU_IMPL_H + +#include "Dual_Resampler.h" +#include "Classic_Emu.h" +#include "Ym2413_Emu.h" +#include "Ym2612_Emu.h" +#include "Sms_Apu.h" + +template +class Ym_Emu : public Emu { +protected: + int last_time; + short* out; + enum { disabled_time = -1 }; +public: + Ym_Emu() : last_time( disabled_time ), out( NULL ) { } + void enable( bool b ) { last_time = b ? 0 : disabled_time; } + bool enabled() const { return last_time != disabled_time; } + void begin_frame( short* p ); + int run_until( int time ); +}; + +class Vgm_Emu_Impl : public Classic_Emu, private Dual_Resampler { +public: + typedef Classic_Emu::sample_t sample_t; +protected: + enum { stereo = 2 }; + + typedef int vgm_time_t; + + enum { fm_time_bits = 12 }; + typedef int fm_time_t; + long fm_time_offset; + int fm_time_factor; + fm_time_t to_fm_time( vgm_time_t ) const; + + enum { blip_time_bits = 12 }; + int blip_time_factor; + blip_time_t to_blip_time( vgm_time_t ) const; + + byte const* data; + byte const* loop_begin; + byte const* data_end; + void update_fm_rates( long* ym2413_rate, long* ym2612_rate ) const; + + vgm_time_t vgm_time; + byte const* pos; + blip_time_t run_commands( vgm_time_t ); + int play_frame( blip_time_t blip_time, int sample_count, sample_t* buf ); + + byte const* pcm_data; + byte const* pcm_pos; + int dac_amp; + int dac_disabled; // -1 if disabled + void write_pcm( vgm_time_t, int amp ); + + Ym_Emu ym2612; + Ym_Emu ym2413; + + Blip_Buffer blip_buf; + Sms_Apu psg; + Blip_Synth dac_synth; + + friend class Vgm_Emu; +}; + +#endif diff --git a/libs/gme/gme/Ym2413_Emu.cpp b/libs/gme/gme/Ym2413_Emu.cpp new file mode 100644 index 000000000..d1c7a71b1 --- /dev/null +++ b/libs/gme/gme/Ym2413_Emu.cpp @@ -0,0 +1,21 @@ + +// Use in place of Ym2413_Emu.cpp and ym2413.c to disable support for this chip + +// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/ + +#include "Ym2413_Emu.h" + +Ym2413_Emu::Ym2413_Emu() { } + +Ym2413_Emu::~Ym2413_Emu() { } + +int Ym2413_Emu::set_rate( double, double ) { return 2; } + +void Ym2413_Emu::reset() { } + +void Ym2413_Emu::write( int, int ) { } + +void Ym2413_Emu::mute_voices( int ) { } + +void Ym2413_Emu::run( int, sample_t* ) { } + diff --git a/libs/gme/gme/Ym2413_Emu.h b/libs/gme/gme/Ym2413_Emu.h new file mode 100644 index 000000000..53ce38a96 --- /dev/null +++ b/libs/gme/gme/Ym2413_Emu.h @@ -0,0 +1,33 @@ +// YM2413 FM sound chip emulator interface + +// Game_Music_Emu 0.6.0 +#ifndef YM2413_EMU_H +#define YM2413_EMU_H + +class Ym2413_Emu { + struct OPLL* opll; +public: + Ym2413_Emu(); + ~Ym2413_Emu(); + + // Set output sample rate and chip clock rates, in Hz. Returns non-zero + // if error. + int set_rate( double sample_rate, double clock_rate ); + + // Reset to power-up state + void reset(); + + // Mute voice n if bit n (1 << n) of mask is set + enum { channel_count = 14 }; + void mute_voices( int mask ); + + // Write 'data' to 'addr' + void write( int addr, int data ); + + // Run and write pair_count samples to output + typedef short sample_t; + enum { out_chan_count = 2 }; // stereo + void run( int pair_count, sample_t* out ); +}; + +#endif diff --git a/libs/gme/gme/Ym2612_Emu.cpp b/libs/gme/gme/Ym2612_Emu.cpp new file mode 100644 index 000000000..5ea5c9a24 --- /dev/null +++ b/libs/gme/gme/Ym2612_Emu.cpp @@ -0,0 +1,1319 @@ +// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/ + +// Based on Gens 2.10 ym2612.c + +#include "Ym2612_Emu.h" + +#include +#include +#include +#include +#include +#include + +/* Copyright (C) 2002 Stéphane Dallongeville (gens AT consolemul.com) */ +/* Copyright (C) 2004-2006 Shay Green. This module 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 +module 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 module; if not, write to the Free Software Foundation, +Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + +// This is mostly the original source in its C style and all. +// +// Somewhat optimized and simplified. Uses a template to generate the many +// variants of Update_Chan. Rewrote header file. In need of full rewrite by +// someone more familiar with FM sound and the YM2612. Has some inaccuracies +// compared to the Sega Genesis sound, particularly being mixed at such a +// high sample accuracy (the Genesis sounds like it has only 8 bit samples). +// - Shay + +#ifdef BLARGG_ENABLE_OPTIMIZER + #include BLARGG_ENABLE_OPTIMIZER +#endif + +const int output_bits = 14; + +struct slot_t +{ + const int *DT; // parametre detune + int MUL; // parametre "multiple de frequence" + int TL; // Total Level = volume lorsque l'enveloppe est au plus haut + int TLL; // Total Level ajusted + int SLL; // Sustin Level (ajusted) = volume où l'enveloppe termine sa premiere phase de regression + int KSR_S; // Key Scale Rate Shift = facteur de prise en compte du KSL dans la variations de l'enveloppe + int KSR; // Key Scale Rate = cette valeur est calculee par rapport à la frequence actuelle, elle va influer + // sur les differents parametres de l'enveloppe comme l'attaque, le decay ... comme dans la realite ! + int SEG; // Type enveloppe SSG + int env_xor; + int env_max; + + const int *AR; // Attack Rate (table pointeur) = Taux d'attaque (AR[KSR]) + const int *DR; // Decay Rate (table pointeur) = Taux pour la regression (DR[KSR]) + const int *SR; // Sustin Rate (table pointeur) = Taux pour le maintien (SR[KSR]) + const int *RR; // Release Rate (table pointeur) = Taux pour le rel'chement (RR[KSR]) + int Fcnt; // Frequency Count = compteur-frequence pour determiner l'amplitude actuelle (SIN[Finc >> 16]) + int Finc; // frequency step = pas d'incrementation du compteur-frequence + // plus le pas est grand, plus la frequence est aïgu (ou haute) + int Ecurp; // Envelope current phase = cette variable permet de savoir dans quelle phase + // de l'enveloppe on se trouve, par exemple phase d'attaque ou phase de maintenue ... + // en fonction de la valeur de cette variable, on va appeler une fonction permettant + // de mettre à jour l'enveloppe courante. + int Ecnt; // Envelope counter = le compteur-enveloppe permet de savoir où l'on se trouve dans l'enveloppe + int Einc; // Envelope step courant + int Ecmp; // Envelope counter limite pour la prochaine phase + int EincA; // Envelope step for Attack = pas d'incrementation du compteur durant la phase d'attaque + // cette valeur est egal à AR[KSR] + int EincD; // Envelope step for Decay = pas d'incrementation du compteur durant la phase de regression + // cette valeur est egal à DR[KSR] + int EincS; // Envelope step for Sustain = pas d'incrementation du compteur durant la phase de maintenue + // cette valeur est egal à SR[KSR] + int EincR; // Envelope step for Release = pas d'incrementation du compteur durant la phase de rel'chement + // cette valeur est egal à RR[KSR] + int *OUTp; // pointeur of SLOT output = pointeur permettant de connecter la sortie de ce slot à l'entree + // d'un autre ou carrement à la sortie de la voie + int INd; // input data of the slot = donnees en entree du slot + int ChgEnM; // Change envelop mask. + int AMS; // AMS depth level of this SLOT = degre de modulation de l'amplitude par le LFO + int AMSon; // AMS enable flag = drapeau d'activation de l'AMS +}; + +struct channel_t +{ + int S0_OUT[4]; // anciennes sorties slot 0 (pour le feed back) + int LEFT; // LEFT enable flag + int RIGHT; // RIGHT enable flag + int ALGO; // Algorythm = determine les connections entre les operateurs + int FB; // shift count of self feed back = degre de "Feed-Back" du SLOT 1 (il est son unique entree) + int FMS; // Frequency Modulation Sensitivity of channel = degre de modulation de la frequence sur la voie par le LFO + int AMS; // Amplitude Modulation Sensitivity of channel = degre de modulation de l'amplitude sur la voie par le LFO + int FNUM[4]; // hauteur frequence de la voie (+ 3 pour le mode special) + int FOCT[4]; // octave de la voie (+ 3 pour le mode special) + int KC[4]; // Key Code = valeur fonction de la frequence (voir KSR pour les slots, KSR = KC >> KSR_S) + slot_t SLOT[4]; // four slot.operators = les 4 slots de la voie + int FFlag; // Frequency step recalculation flag +}; + +struct state_t +{ + int TimerBase; // TimerBase calculation + int Status; // YM2612 Status (timer overflow) + int TimerA; // timerA limit = valeur jusqu'à laquelle le timer A doit compter + int TimerAL; + int TimerAcnt; // timerA counter = valeur courante du Timer A + int TimerB; // timerB limit = valeur jusqu'à laquelle le timer B doit compter + int TimerBL; + int TimerBcnt; // timerB counter = valeur courante du Timer B + int Mode; // Mode actuel des voie 3 et 6 (normal / special) + int DAC; // DAC enabled flag + channel_t CHANNEL[Ym2612_Emu::channel_count]; // Les 6 voies du YM2612 + int REG[2][0x100]; // Sauvegardes des valeurs de tout les registres, c'est facultatif + // cela nous rend le debuggage plus facile +}; + +#ifndef PI +#define PI 3.14159265358979323846 +#endif + +#define ATTACK 0 +#define DECAY 1 +#define SUBSTAIN 2 +#define RELEASE 3 + +// SIN_LBITS <= 16 +// LFO_HBITS <= 16 +// (SIN_LBITS + SIN_HBITS) <= 26 +// (ENV_LBITS + ENV_HBITS) <= 28 +// (LFO_LBITS + LFO_HBITS) <= 28 + +#define SIN_HBITS 12 // Sinus phase counter int part +#define SIN_LBITS (26 - SIN_HBITS) // Sinus phase counter float part (best setting) + +#if (SIN_LBITS > 16) +#define SIN_LBITS 16 // Can't be greater than 16 bits +#endif + +#define ENV_HBITS 12 // Env phase counter int part +#define ENV_LBITS (28 - ENV_HBITS) // Env phase counter float part (best setting) + +#define LFO_HBITS 10 // LFO phase counter int part +#define LFO_LBITS (28 - LFO_HBITS) // LFO phase counter float part (best setting) + +#define SIN_LENGHT (1 << SIN_HBITS) +#define ENV_LENGHT (1 << ENV_HBITS) +#define LFO_LENGHT (1 << LFO_HBITS) + +#define TL_LENGHT (ENV_LENGHT * 3) // Env + TL scaling + LFO + +#define SIN_MASK (SIN_LENGHT - 1) +#define ENV_MASK (ENV_LENGHT - 1) +#define LFO_MASK (LFO_LENGHT - 1) + +#define ENV_STEP (96.0 / ENV_LENGHT) // ENV_MAX = 96 dB + +#define ENV_ATTACK ((ENV_LENGHT * 0) << ENV_LBITS) +#define ENV_DECAY ((ENV_LENGHT * 1) << ENV_LBITS) +#define ENV_END ((ENV_LENGHT * 2) << ENV_LBITS) + +#define MAX_OUT_BITS (SIN_HBITS + SIN_LBITS + 2) // Modulation = -4 <--> +4 +#define MAX_OUT ((1 << MAX_OUT_BITS) - 1) + +#define PG_CUT_OFF ((int) (78.0 / ENV_STEP)) +#define ENV_CUT_OFF ((int) (68.0 / ENV_STEP)) + +#define AR_RATE 399128 +#define DR_RATE 5514396 + +//#define AR_RATE 426136 +//#define DR_RATE (AR_RATE * 12) + +#define LFO_FMS_LBITS 9 // FIXED (LFO_FMS_BASE gives somethink as 1) +#define LFO_FMS_BASE ((int) (0.05946309436 * 0.0338 * (double) (1 << LFO_FMS_LBITS))) + +#define S0 0 // Stupid typo of the YM2612 +#define S1 2 +#define S2 1 +#define S3 3 + +inline void set_seg( slot_t& s, int seg ) +{ + s.env_xor = 0; + s.env_max = INT_MAX; + s.SEG = seg; + if ( seg & 4 ) + { + s.env_xor = ENV_MASK; + s.env_max = ENV_MASK; + } +} + +struct tables_t +{ + short SIN_TAB [SIN_LENGHT]; // SINUS TABLE (offset into TL TABLE) + int LFOcnt; // LFO counter = compteur-frequence pour le LFO + int LFOinc; // LFO step counter = pas d'incrementation du compteur-frequence du LFO + // plus le pas est grand, plus la frequence est grande + unsigned int AR_TAB [128]; // Attack rate table + unsigned int DR_TAB [96]; // Decay rate table + unsigned int DT_TAB [8] [32]; // Detune table + unsigned int SL_TAB [16]; // Substain level table + unsigned int NULL_RATE [32]; // Table for NULL rate + int LFO_INC_TAB [8]; // LFO step table + + short ENV_TAB [2 * ENV_LENGHT + 8]; // ENV CURVE TABLE (attack & decay) + + short LFO_ENV_TAB [LFO_LENGHT]; // LFO AMS TABLE (adjusted for 11.8 dB) + short LFO_FREQ_TAB [LFO_LENGHT]; // LFO FMS TABLE + int TL_TAB [TL_LENGHT * 2]; // TOTAL LEVEL TABLE (positif and minus) + unsigned int DECAY_TO_ATTACK [ENV_LENGHT]; // Conversion from decay to attack phase + unsigned int FINC_TAB [2048]; // Frequency step table +}; + +static const unsigned char DT_DEF_TAB [4 * 32] = +{ +// FD = 0 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + +// FD = 1 + 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, + 2, 3, 3, 3, 4, 4, 4, 5, 5, 6, 6, 7, 8, 8, 8, 8, + +// FD = 2 + 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, + 5, 6, 6, 7, 8, 8, 9, 10, 11, 12, 13, 14, 16, 16, 16, 16, + +// FD = 3 + 2, 2, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 6, 6, 7, + 8 , 8, 9, 10, 11, 12, 13, 14, 16, 17, 19, 20, 22, 22, 22, 22 +}; + +static const unsigned char FKEY_TAB [16] = +{ + 0, 0, 0, 0, + 0, 0, 0, 1, + 2, 3, 3, 3, + 3, 3, 3, 3 +}; + +static const unsigned char LFO_AMS_TAB [4] = +{ + 31, 4, 1, 0 +}; + +static const unsigned char LFO_FMS_TAB [8] = +{ + LFO_FMS_BASE * 0, LFO_FMS_BASE * 1, + LFO_FMS_BASE * 2, LFO_FMS_BASE * 3, + LFO_FMS_BASE * 4, LFO_FMS_BASE * 6, + LFO_FMS_BASE * 12, LFO_FMS_BASE * 24 +}; + +inline void YM2612_Special_Update() { } + +struct Ym2612_Impl +{ + enum { channel_count = Ym2612_Emu::channel_count }; + + state_t YM2612; + int mute_mask; + tables_t g; + + void KEY_ON( channel_t&, int ); + void KEY_OFF( channel_t&, int ); + int SLOT_SET( int, int ); + int CHANNEL_SET( int, int ); + int YM_SET( int, int ); + + void set_rate( double sample_rate, double clock_factor ); + void reset(); + void write0( int addr, int data ); + void write1( int addr, int data ); + void run_timer( int ); + void run( int pair_count, Ym2612_Emu::sample_t* ); +}; + +void Ym2612_Impl::KEY_ON( channel_t& ch, int nsl) +{ + slot_t *SL = &(ch.SLOT [nsl]); // on recupere le bon pointeur de slot + + if (SL->Ecurp == RELEASE) // la touche est-elle rel'chee ? + { + SL->Fcnt = 0; + + // Fix Ecco 2 splash sound + + SL->Ecnt = (g.DECAY_TO_ATTACK [g.ENV_TAB [SL->Ecnt >> ENV_LBITS]] + ENV_ATTACK) & SL->ChgEnM; + SL->ChgEnM = ~0; + +// SL->Ecnt = g.DECAY_TO_ATTACK [g.ENV_TAB [SL->Ecnt >> ENV_LBITS]] + ENV_ATTACK; +// SL->Ecnt = 0; + + SL->Einc = SL->EincA; + SL->Ecmp = ENV_DECAY; + SL->Ecurp = ATTACK; + } +} + + +void Ym2612_Impl::KEY_OFF(channel_t& ch, int nsl) +{ + slot_t *SL = &(ch.SLOT [nsl]); // on recupere le bon pointeur de slot + + if (SL->Ecurp != RELEASE) // la touche est-elle appuyee ? + { + if (SL->Ecnt < ENV_DECAY) // attack phase ? + { + SL->Ecnt = (g.ENV_TAB [SL->Ecnt >> ENV_LBITS] << ENV_LBITS) + ENV_DECAY; + } + + SL->Einc = SL->EincR; + SL->Ecmp = ENV_END; + SL->Ecurp = RELEASE; + } +} + + +int Ym2612_Impl::SLOT_SET( int Adr, int data ) +{ + int nch = Adr & 3; + if ( nch == 3 ) + return 1; + + channel_t& ch = YM2612.CHANNEL [nch + (Adr & 0x100 ? 3 : 0)]; + slot_t& sl = ch.SLOT [(Adr >> 2) & 3]; + + switch ( Adr & 0xF0 ) + { + case 0x30: + if ( (sl.MUL = (data & 0x0F)) != 0 ) sl.MUL <<= 1; + else sl.MUL = 1; + + sl.DT = (int*) g.DT_TAB [(data >> 4) & 7]; + + ch.SLOT [0].Finc = -1; + + break; + + case 0x40: + sl.TL = data & 0x7F; + + // SOR2 do a lot of TL adjustement and this fix R.Shinobi jump sound... + YM2612_Special_Update(); + +#if ((ENV_HBITS - 7) < 0) + sl.TLL = sl.TL >> (7 - ENV_HBITS); +#else + sl.TLL = sl.TL << (ENV_HBITS - 7); +#endif + + break; + + case 0x50: + sl.KSR_S = 3 - (data >> 6); + + ch.SLOT [0].Finc = -1; + + if (data &= 0x1F) sl.AR = (int*) &g.AR_TAB [data << 1]; + else sl.AR = (int*) &g.NULL_RATE [0]; + + sl.EincA = sl.AR [sl.KSR]; + if (sl.Ecurp == ATTACK) sl.Einc = sl.EincA; + break; + + case 0x60: + if ( (sl.AMSon = (data & 0x80)) != 0 ) sl.AMS = ch.AMS; + else sl.AMS = 31; + + if (data &= 0x1F) sl.DR = (int*) &g.DR_TAB [data << 1]; + else sl.DR = (int*) &g.NULL_RATE [0]; + + sl.EincD = sl.DR [sl.KSR]; + if (sl.Ecurp == DECAY) sl.Einc = sl.EincD; + break; + + case 0x70: + if (data &= 0x1F) sl.SR = (int*) &g.DR_TAB [data << 1]; + else sl.SR = (int*) &g.NULL_RATE [0]; + + sl.EincS = sl.SR [sl.KSR]; + if ((sl.Ecurp == SUBSTAIN) && (sl.Ecnt < ENV_END)) sl.Einc = sl.EincS; + break; + + case 0x80: + sl.SLL = g.SL_TAB [data >> 4]; + + sl.RR = (int*) &g.DR_TAB [((data & 0xF) << 2) + 2]; + + sl.EincR = sl.RR [sl.KSR]; + if ((sl.Ecurp == RELEASE) && (sl.Ecnt < ENV_END)) sl.Einc = sl.EincR; + break; + + case 0x90: + // SSG-EG envelope shapes : + /* + E At Al H + + 1 0 0 0 \\\\ + 1 0 0 1 \___ + 1 0 1 0 \/\/ + 1 0 1 1 \ + 1 1 0 0 //// + 1 1 0 1 / + 1 1 1 0 /\/\ + 1 1 1 1 /___ + + E = SSG-EG enable + At = Start negate + Al = Altern + H = Hold */ + + set_seg( sl, (data & 8) ? (data & 0x0F) : 0 ); + break; + } + + return 0; +} + + +int Ym2612_Impl::CHANNEL_SET( int Adr, int data ) +{ + int num = Adr & 3; + if ( num == 3 ) + return 1; + + channel_t& ch = YM2612.CHANNEL [num + (Adr & 0x100 ? 3 : 0)]; + + switch ( Adr & 0xFC ) + { + case 0xA0: + YM2612_Special_Update(); + + ch.FNUM [0] = (ch.FNUM [0] & 0x700) + data; + ch.KC [0] = (ch.FOCT [0] << 2) | FKEY_TAB [ch.FNUM [0] >> 7]; + + ch.SLOT [0].Finc = -1; + break; + + case 0xA4: + YM2612_Special_Update(); + + ch.FNUM [0] = (ch.FNUM [0] & 0x0FF) + ((data & 0x07) << 8); + ch.FOCT [0] = (data & 0x38) >> 3; + ch.KC [0] = (ch.FOCT [0] << 2) | FKEY_TAB [ch.FNUM [0] >> 7]; + + ch.SLOT [0].Finc = -1; + break; + + case 0xA8: + if ( Adr < 0x100 ) + { + num++; + + YM2612_Special_Update(); + + YM2612.CHANNEL [2].FNUM [num] = (YM2612.CHANNEL [2].FNUM [num] & 0x700) + data; + YM2612.CHANNEL [2].KC [num] = (YM2612.CHANNEL [2].FOCT [num] << 2) | + FKEY_TAB [YM2612.CHANNEL [2].FNUM [num] >> 7]; + + YM2612.CHANNEL [2].SLOT [0].Finc = -1; + } + break; + + case 0xAC: + if ( Adr < 0x100 ) + { + num++; + + YM2612_Special_Update(); + + YM2612.CHANNEL [2].FNUM [num] = (YM2612.CHANNEL [2].FNUM [num] & 0x0FF) + ((data & 0x07) << 8); + YM2612.CHANNEL [2].FOCT [num] = (data & 0x38) >> 3; + YM2612.CHANNEL [2].KC [num] = (YM2612.CHANNEL [2].FOCT [num] << 2) | + FKEY_TAB [YM2612.CHANNEL [2].FNUM [num] >> 7]; + + YM2612.CHANNEL [2].SLOT [0].Finc = -1; + } + break; + + case 0xB0: + if ( ch.ALGO != (data & 7) ) + { + // Fix VectorMan 2 heli sound (level 1) + YM2612_Special_Update(); + + ch.ALGO = data & 7; + + ch.SLOT [0].ChgEnM = 0; + ch.SLOT [1].ChgEnM = 0; + ch.SLOT [2].ChgEnM = 0; + ch.SLOT [3].ChgEnM = 0; + } + + ch.FB = 9 - ((data >> 3) & 7); // Real thing ? + +// if (ch.FB = ((data >> 3) & 7)) ch.FB = 9 - ch.FB; // Thunder force 4 (music stage 8), Gynoug, Aladdin bug sound... +// else ch.FB = 31; + break; + + case 0xB4: { + YM2612_Special_Update(); + + ch.LEFT = 0 - ((data >> 7) & 1); + ch.RIGHT = 0 - ((data >> 6) & 1); + + ch.AMS = LFO_AMS_TAB [(data >> 4) & 3]; + ch.FMS = LFO_FMS_TAB [data & 7]; + + for ( int i = 0; i < 4; i++ ) + { + slot_t& sl = ch.SLOT [i]; + sl.AMS = (sl.AMSon ? ch.AMS : 31); + } + break; + } + } + + return 0; +} + + +int Ym2612_Impl::YM_SET(int Adr, int data) +{ + switch ( Adr ) + { + case 0x22: + if (data & 8) // LFO enable + { + // Cool Spot music 1, LFO modified severals time which + // distord the sound, have to check that on a real genesis... + + g.LFOinc = g.LFO_INC_TAB [data & 7]; + } + else + { + g.LFOinc = g.LFOcnt = 0; + } + break; + + case 0x24: + YM2612.TimerA = (YM2612.TimerA & 0x003) | (((int) data) << 2); + + if (YM2612.TimerAL != (1024 - YM2612.TimerA) << 12) + { + YM2612.TimerAcnt = YM2612.TimerAL = (1024 - YM2612.TimerA) << 12; + } + break; + + case 0x25: + YM2612.TimerA = (YM2612.TimerA & 0x3FC) | (data & 3); + + if (YM2612.TimerAL != (1024 - YM2612.TimerA) << 12) + { + YM2612.TimerAcnt = YM2612.TimerAL = (1024 - YM2612.TimerA) << 12; + } + break; + + case 0x26: + YM2612.TimerB = data; + + if (YM2612.TimerBL != (256 - YM2612.TimerB) << (4 + 12)) + { + YM2612.TimerBcnt = YM2612.TimerBL = (256 - YM2612.TimerB) << (4 + 12); + } + break; + + case 0x27: + // Parametre divers + // b7 = CSM MODE + // b6 = 3 slot mode + // b5 = reset b + // b4 = reset a + // b3 = timer enable b + // b2 = timer enable a + // b1 = load b + // b0 = load a + + if ((data ^ YM2612.Mode) & 0x40) + { + // We changed the channel 2 mode, so recalculate phase step + // This fix the punch sound in Street of Rage 2 + + YM2612_Special_Update(); + + YM2612.CHANNEL [2].SLOT [0].Finc = -1; // recalculate phase step + } + +// if ((data & 2) && (YM2612.Status & 2)) YM2612.TimerBcnt = YM2612.TimerBL; +// if ((data & 1) && (YM2612.Status & 1)) YM2612.TimerAcnt = YM2612.TimerAL; + +// YM2612.Status &= (~data >> 4); // Reset du Status au cas ou c'est demande + YM2612.Status &= (~data >> 4) & (data >> 2); // Reset Status + + YM2612.Mode = data; + break; + + case 0x28: { + int nch = data & 3; + if ( nch == 3 ) + return 1; + if ( data & 4 ) + nch += 3; + channel_t& ch = YM2612.CHANNEL [nch]; + + YM2612_Special_Update(); + + if (data & 0x10) KEY_ON(ch, S0); // On appuie sur la touche pour le slot 1 + else KEY_OFF(ch, S0); // On rel'che la touche pour le slot 1 + if (data & 0x20) KEY_ON(ch, S1); // On appuie sur la touche pour le slot 3 + else KEY_OFF(ch, S1); // On rel'che la touche pour le slot 3 + if (data & 0x40) KEY_ON(ch, S2); // On appuie sur la touche pour le slot 2 + else KEY_OFF(ch, S2); // On rel'che la touche pour le slot 2 + if (data & 0x80) KEY_ON(ch, S3); // On appuie sur la touche pour le slot 4 + else KEY_OFF(ch, S3); // On rel'che la touche pour le slot 4 + break; + } + + case 0x2B: + if (YM2612.DAC ^ (data & 0x80)) YM2612_Special_Update(); + + YM2612.DAC = data & 0x80; // activation/desactivation du DAC + break; + } + + return 0; +} + +void Ym2612_Impl::set_rate( double sample_rate, double clock_rate ) +{ + assert( sample_rate ); + assert( clock_rate > sample_rate ); + + int i; + + // 144 = 12 * (prescale * 2) = 12 * 6 * 2 + // prescale set to 6 by default + + double Frequence = clock_rate / sample_rate / 144.0; + if ( fabs( Frequence - 1.0 ) < 0.0000001 ) + Frequence = 1.0; + YM2612.TimerBase = int (Frequence * 4096.0); + + // Tableau TL : + // [0 - 4095] = +output [4095 - ...] = +output overflow (fill with 0) + // [12288 - 16383] = -output [16384 - ...] = -output overflow (fill with 0) + + for(i = 0; i < TL_LENGHT; i++) + { + if (i >= PG_CUT_OFF) // YM2612 cut off sound after 78 dB (14 bits output ?) + { + g.TL_TAB [TL_LENGHT + i] = g.TL_TAB [i] = 0; + } + else + { + double x = MAX_OUT; // Max output + x /= pow( 10.0, (ENV_STEP * i) / 20.0 ); // Decibel -> Voltage + + g.TL_TAB [i] = (int) x; + g.TL_TAB [TL_LENGHT + i] = -g.TL_TAB [i]; + } + } + + // Tableau SIN : + // g.SIN_TAB [x] [y] = sin(x) * y; + // x = phase and y = volume + + g.SIN_TAB [0] = g.SIN_TAB [SIN_LENGHT / 2] = PG_CUT_OFF; + + for(i = 1; i <= SIN_LENGHT / 4; i++) + { + double x = sin(2.0 * PI * (double) (i) / (double) (SIN_LENGHT)); // Sinus + x = 20 * log10(1 / x); // convert to dB + + int j = (int) (x / ENV_STEP); // Get TL range + + if (j > PG_CUT_OFF) j = (int) PG_CUT_OFF; + + g.SIN_TAB [i] = g.SIN_TAB [(SIN_LENGHT / 2) - i] = j; + g.SIN_TAB [(SIN_LENGHT / 2) + i] = g.SIN_TAB [SIN_LENGHT - i] = TL_LENGHT + j; + } + + // Tableau LFO (LFO wav) : + + for(i = 0; i < LFO_LENGHT; i++) + { + double x = sin(2.0 * PI * (double) (i) / (double) (LFO_LENGHT)); // Sinus + x += 1.0; + x /= 2.0; // positive only + x *= 11.8 / ENV_STEP; // ajusted to MAX enveloppe modulation + + g.LFO_ENV_TAB [i] = (int) x; + + x = sin(2.0 * PI * (double) (i) / (double) (LFO_LENGHT)); // Sinus + x *= (double) ((1 << (LFO_HBITS - 1)) - 1); + + g.LFO_FREQ_TAB [i] = (int) x; + + } + + // Tableau Enveloppe : + // g.ENV_TAB [0] -> g.ENV_TAB [ENV_LENGHT - 1] = attack curve + // g.ENV_TAB [ENV_LENGHT] -> g.ENV_TAB [2 * ENV_LENGHT - 1] = decay curve + + for(i = 0; i < ENV_LENGHT; i++) + { + // Attack curve (x^8 - music level 2 Vectorman 2) + double x = pow(((double) ((ENV_LENGHT - 1) - i) / (double) (ENV_LENGHT)), 8); + x *= ENV_LENGHT; + + g.ENV_TAB [i] = (int) x; + + // Decay curve (just linear) + x = pow(((double) (i) / (double) (ENV_LENGHT)), 1); + x *= ENV_LENGHT; + + g.ENV_TAB [ENV_LENGHT + i] = (int) x; + } + for ( i = 0; i < 8; i++ ) + g.ENV_TAB [i + ENV_LENGHT * 2] = 0; + + g.ENV_TAB [ENV_END >> ENV_LBITS] = ENV_LENGHT - 1; // for the stopped state + + // Tableau pour la conversion Attack -> Decay and Decay -> Attack + + int j = ENV_LENGHT - 1; + for ( i = 0; i < ENV_LENGHT; i++ ) + { + while ( j && g.ENV_TAB [j] < i ) + j--; + + g.DECAY_TO_ATTACK [i] = j << ENV_LBITS; + } + + // Tableau pour le Substain Level + + for(i = 0; i < 15; i++) + { + double x = i * 3; // 3 and not 6 (Mickey Mania first music for test) + x /= ENV_STEP; + + g.SL_TAB [i] = ((int) x << ENV_LBITS) + ENV_DECAY; + } + + g.SL_TAB [15] = ((ENV_LENGHT - 1) << ENV_LBITS) + ENV_DECAY; // special case : volume off + + // Tableau Frequency Step + + for(i = 0; i < 2048; i++) + { + double x = (double) (i) * Frequence; + +#if ((SIN_LBITS + SIN_HBITS - (21 - 7)) < 0) + x /= (double) (1 << ((21 - 7) - SIN_LBITS - SIN_HBITS)); +#else + x *= (double) (1 << (SIN_LBITS + SIN_HBITS - (21 - 7))); +#endif + + x /= 2.0; // because MUL = value * 2 + + g.FINC_TAB [i] = (unsigned int) x; + } + + // Tableaux Attack & Decay Rate + + for(i = 0; i < 4; i++) + { + g.AR_TAB [i] = 0; + g.DR_TAB [i] = 0; + } + + for(i = 0; i < 60; i++) + { + double x = Frequence; + + x *= 1.0 + ((i & 3) * 0.25); // bits 0-1 : x1.00, x1.25, x1.50, x1.75 + x *= (double) (1 << ((i >> 2))); // bits 2-5 : shift bits (x2^0 - x2^15) + x *= (double) (ENV_LENGHT << ENV_LBITS); // on ajuste pour le tableau g.ENV_TAB + + g.AR_TAB [i + 4] = (unsigned int) (x / AR_RATE); + g.DR_TAB [i + 4] = (unsigned int) (x / DR_RATE); + } + + for(i = 64; i < 96; i++) + { + g.AR_TAB [i] = g.AR_TAB [63]; + g.DR_TAB [i] = g.DR_TAB [63]; + + g.NULL_RATE [i - 64] = 0; + } + + for ( i = 96; i < 128; i++ ) + g.AR_TAB [i] = 0; + + // Tableau Detune + + for(i = 0; i < 4; i++) + { + for (int j = 0; j < 32; j++) + { +#if ((SIN_LBITS + SIN_HBITS - 21) < 0) + double y = (double) DT_DEF_TAB [(i << 5) + j] * Frequence / (double) (1 << (21 - SIN_LBITS - SIN_HBITS)); +#else + double y = (double) DT_DEF_TAB [(i << 5) + j] * Frequence * (double) (1 << (SIN_LBITS + SIN_HBITS - 21)); +#endif + + g.DT_TAB [i + 0] [j] = (int) y; + g.DT_TAB [i + 4] [j] = (int) -y; + } + } + + // Tableau LFO + g.LFO_INC_TAB [0] = (unsigned int) (3.98 * (double) (1 << (LFO_HBITS + LFO_LBITS)) / sample_rate); + g.LFO_INC_TAB [1] = (unsigned int) (5.56 * (double) (1 << (LFO_HBITS + LFO_LBITS)) / sample_rate); + g.LFO_INC_TAB [2] = (unsigned int) (6.02 * (double) (1 << (LFO_HBITS + LFO_LBITS)) / sample_rate); + g.LFO_INC_TAB [3] = (unsigned int) (6.37 * (double) (1 << (LFO_HBITS + LFO_LBITS)) / sample_rate); + g.LFO_INC_TAB [4] = (unsigned int) (6.88 * (double) (1 << (LFO_HBITS + LFO_LBITS)) / sample_rate); + g.LFO_INC_TAB [5] = (unsigned int) (9.63 * (double) (1 << (LFO_HBITS + LFO_LBITS)) / sample_rate); + g.LFO_INC_TAB [6] = (unsigned int) (48.1 * (double) (1 << (LFO_HBITS + LFO_LBITS)) / sample_rate); + g.LFO_INC_TAB [7] = (unsigned int) (72.2 * (double) (1 << (LFO_HBITS + LFO_LBITS)) / sample_rate); + + reset(); +} + +const char* Ym2612_Emu::set_rate( double sample_rate, double clock_rate ) +{ + if ( !impl ) + { + impl = (Ym2612_Impl*) malloc( sizeof *impl ); + if ( !impl ) + return "Out of memory"; + impl->mute_mask = 0; + } + memset( &impl->YM2612, 0, sizeof impl->YM2612 ); + + impl->set_rate( sample_rate, clock_rate ); + + return 0; +} + +Ym2612_Emu::~Ym2612_Emu() +{ + free( impl ); +} + +inline void Ym2612_Impl::write0( int opn_addr, int data ) +{ + assert( (unsigned) data <= 0xFF ); + + if ( opn_addr < 0x30 ) + { + YM2612.REG [0] [opn_addr] = data; + YM_SET( opn_addr, data ); + } + else if ( YM2612.REG [0] [opn_addr] != data ) + { + YM2612.REG [0] [opn_addr] = data; + + if ( opn_addr < 0xA0 ) + SLOT_SET( opn_addr, data ); + else + CHANNEL_SET( opn_addr, data ); + } +} + +inline void Ym2612_Impl::write1( int opn_addr, int data ) +{ + assert( (unsigned) data <= 0xFF ); + + if ( opn_addr >= 0x30 && YM2612.REG [1] [opn_addr] != data ) + { + YM2612.REG [1] [opn_addr] = data; + + if ( opn_addr < 0xA0 ) + SLOT_SET( opn_addr + 0x100, data ); + else + CHANNEL_SET( opn_addr + 0x100, data ); + } +} + +void Ym2612_Emu::reset() +{ + impl->reset(); +} + +void Ym2612_Impl::reset() +{ + g.LFOcnt = 0; + YM2612.TimerA = 0; + YM2612.TimerAL = 0; + YM2612.TimerAcnt = 0; + YM2612.TimerB = 0; + YM2612.TimerBL = 0; + YM2612.TimerBcnt = 0; + YM2612.DAC = 0; + + YM2612.Status = 0; + + int i; + for ( i = 0; i < channel_count; i++ ) + { + channel_t& ch = YM2612.CHANNEL [i]; + + ch.LEFT = ~0; + ch.RIGHT = ~0; + ch.ALGO = 0; + ch.FB = 31; + ch.FMS = 0; + ch.AMS = 0; + + for ( int j = 0 ;j < 4 ; j++ ) + { + ch.S0_OUT [j] = 0; + ch.FNUM [j] = 0; + ch.FOCT [j] = 0; + ch.KC [j] = 0; + + ch.SLOT [j].Fcnt = 0; + ch.SLOT [j].Finc = 0; + ch.SLOT [j].Ecnt = ENV_END; // Put it at the end of Decay phase... + ch.SLOT [j].Einc = 0; + ch.SLOT [j].Ecmp = 0; + ch.SLOT [j].Ecurp = RELEASE; + + ch.SLOT [j].ChgEnM = 0; + } + } + + for ( i = 0; i < 0x100; i++ ) + { + YM2612.REG [0] [i] = -1; + YM2612.REG [1] [i] = -1; + } + + for ( i = 0xB6; i >= 0xB4; i-- ) + { + write0( i, 0xC0 ); + write1( i, 0xC0 ); + } + + for ( i = 0xB2; i >= 0x22; i-- ) + { + write0( i, 0 ); + write1( i, 0 ); + } + + write0( 0x2A, 0x80 ); +} + +void Ym2612_Emu::write0( int addr, int data ) +{ + impl->write0( addr, data ); +} + +void Ym2612_Emu::write1( int addr, int data ) +{ + impl->write1( addr, data ); +} + +void Ym2612_Emu::mute_voices( int mask ) { impl->mute_mask = mask; } + +static void update_envelope_( slot_t* sl ) +{ + switch ( sl->Ecurp ) + { + case 0: + // Env_Attack_Next + + // Verified with Gynoug even in HQ (explode SFX) + sl->Ecnt = ENV_DECAY; + + sl->Einc = sl->EincD; + sl->Ecmp = sl->SLL; + sl->Ecurp = DECAY; + break; + + case 1: + // Env_Decay_Next + + // Verified with Gynoug even in HQ (explode SFX) + sl->Ecnt = sl->SLL; + + sl->Einc = sl->EincS; + sl->Ecmp = ENV_END; + sl->Ecurp = SUBSTAIN; + break; + + case 2: + // Env_Substain_Next(slot_t *SL) + if (sl->SEG & 8) // SSG envelope type + { + int release = sl->SEG & 1; + + if ( !release ) + { + // re KEY ON + + // sl->Fcnt = 0; + // sl->ChgEnM = ~0; + + sl->Ecnt = 0; + sl->Einc = sl->EincA; + sl->Ecmp = ENV_DECAY; + sl->Ecurp = ATTACK; + } + + set_seg( *sl, (sl->SEG << 1) & 4 ); + + if ( !release ) + break; + } + // fall through + + case 3: + // Env_Release_Next + sl->Ecnt = ENV_END; + sl->Einc = 0; + sl->Ecmp = ENV_END + 1; + break; + + // default: no op + } +} + +inline void update_envelope( slot_t& sl ) +{ + int ecmp = sl.Ecmp; + if ( (sl.Ecnt += sl.Einc) >= ecmp ) + update_envelope_( &sl ); +} + +template +struct ym2612_update_chan { + static void func( tables_t&, channel_t&, Ym2612_Emu::sample_t*, int ); +}; + +typedef void (*ym2612_update_chan_t)( tables_t&, channel_t&, Ym2612_Emu::sample_t*, int ); + +template +void ym2612_update_chan::func( tables_t& g, channel_t& ch, + Ym2612_Emu::sample_t* buf, int length ) +{ + int not_end = ch.SLOT [S3].Ecnt - ENV_END; + + // algo is a compile-time constant, so all conditions based on it are resolved + // during compilation + + // special cases + if ( algo == 7 ) + not_end |= ch.SLOT [S0].Ecnt - ENV_END; + + if ( algo >= 5 ) + not_end |= ch.SLOT [S2].Ecnt - ENV_END; + + if ( algo >= 4 ) + not_end |= ch.SLOT [S1].Ecnt - ENV_END; + + int CH_S0_OUT_1 = ch.S0_OUT [1]; + + int in0 = ch.SLOT [S0].Fcnt; + int in1 = ch.SLOT [S1].Fcnt; + int in2 = ch.SLOT [S2].Fcnt; + int in3 = ch.SLOT [S3].Fcnt; + + int YM2612_LFOinc = g.LFOinc; + int YM2612_LFOcnt = g.LFOcnt + YM2612_LFOinc; + + if ( !not_end ) + return; + + do + { + // envelope + int const env_LFO = g.LFO_ENV_TAB [YM2612_LFOcnt >> LFO_LBITS & LFO_MASK]; + + short const* const ENV_TAB = g.ENV_TAB; + + #define CALC_EN( x ) \ + int temp##x = ENV_TAB [ch.SLOT [S##x].Ecnt >> ENV_LBITS] + ch.SLOT [S##x].TLL; \ + int en##x = ((temp##x ^ ch.SLOT [S##x].env_xor) + (env_LFO >> ch.SLOT [S##x].AMS)) & \ + ((temp##x - ch.SLOT [S##x].env_max) >> 31); + + CALC_EN( 0 ) + CALC_EN( 1 ) + CALC_EN( 2 ) + CALC_EN( 3 ) + + int const* const TL_TAB = g.TL_TAB; + + #define SINT( i, o ) (TL_TAB [g.SIN_TAB [(i)] + (o)]) + + // feedback + int CH_S0_OUT_0 = ch.S0_OUT [0]; + { + int temp = in0 + ((CH_S0_OUT_0 + CH_S0_OUT_1) >> ch.FB); + CH_S0_OUT_1 = CH_S0_OUT_0; + CH_S0_OUT_0 = SINT( (temp >> SIN_LBITS) & SIN_MASK, en0 ); + } + + int CH_OUTd; + if ( algo == 0 ) + { + int temp = in1 + CH_S0_OUT_1; + temp = in2 + SINT( (temp >> SIN_LBITS) & SIN_MASK, en1 ); + temp = in3 + SINT( (temp >> SIN_LBITS) & SIN_MASK, en2 ); + CH_OUTd = SINT( (temp >> SIN_LBITS) & SIN_MASK, en3 ); + } + else if ( algo == 1 ) + { + int temp = in2 + CH_S0_OUT_1 + SINT( (in1 >> SIN_LBITS) & SIN_MASK, en1 ); + temp = in3 + SINT( (temp >> SIN_LBITS) & SIN_MASK, en2 ); + CH_OUTd = SINT( (temp >> SIN_LBITS) & SIN_MASK, en3 ); + } + else if ( algo == 2 ) + { + int temp = in2 + SINT( (in1 >> SIN_LBITS) & SIN_MASK, en1 ); + temp = in3 + CH_S0_OUT_1 + SINT( (temp >> SIN_LBITS) & SIN_MASK, en2 ); + CH_OUTd = SINT( (temp >> SIN_LBITS) & SIN_MASK, en3 ); + } + else if ( algo == 3 ) + { + int temp = in1 + CH_S0_OUT_1; + temp = in3 + SINT( (temp >> SIN_LBITS) & SIN_MASK, en1 ) + + SINT( (in2 >> SIN_LBITS) & SIN_MASK, en2 ); + CH_OUTd = SINT( (temp >> SIN_LBITS) & SIN_MASK, en3 ); + } + else if ( algo == 4 ) + { + int temp = in3 + SINT( (in2 >> SIN_LBITS) & SIN_MASK, en2 ); + CH_OUTd = SINT( (temp >> SIN_LBITS) & SIN_MASK, en3 ) + + SINT( ((in1 + CH_S0_OUT_1) >> SIN_LBITS) & SIN_MASK, en1 ); + //DO_LIMIT + } + else if ( algo == 5 ) + { + int temp = CH_S0_OUT_1; + CH_OUTd = SINT( ((in3 + temp) >> SIN_LBITS) & SIN_MASK, en3 ) + + SINT( ((in1 + temp) >> SIN_LBITS) & SIN_MASK, en1 ) + + SINT( ((in2 + temp) >> SIN_LBITS) & SIN_MASK, en2 ); + //DO_LIMIT + } + else if ( algo == 6 ) + { + CH_OUTd = SINT( (in3 >> SIN_LBITS) & SIN_MASK, en3 ) + + SINT( ((in1 + CH_S0_OUT_1) >> SIN_LBITS) & SIN_MASK, en1 ) + + SINT( (in2 >> SIN_LBITS) & SIN_MASK, en2 ); + //DO_LIMIT + } + else if ( algo == 7 ) + { + CH_OUTd = SINT( (in3 >> SIN_LBITS) & SIN_MASK, en3 ) + + SINT( (in1 >> SIN_LBITS) & SIN_MASK, en1 ) + + SINT( (in2 >> SIN_LBITS) & SIN_MASK, en2 ) + CH_S0_OUT_1; + //DO_LIMIT + } + + CH_OUTd >>= MAX_OUT_BITS - output_bits + 2; + + // update phase + unsigned freq_LFO = ((g.LFO_FREQ_TAB [YM2612_LFOcnt >> LFO_LBITS & LFO_MASK] * + ch.FMS) >> (LFO_HBITS - 1 + 1)) + (1L << (LFO_FMS_LBITS - 1)); + YM2612_LFOcnt += YM2612_LFOinc; + in0 += (ch.SLOT [S0].Finc * freq_LFO) >> (LFO_FMS_LBITS - 1); + in1 += (ch.SLOT [S1].Finc * freq_LFO) >> (LFO_FMS_LBITS - 1); + in2 += (ch.SLOT [S2].Finc * freq_LFO) >> (LFO_FMS_LBITS - 1); + in3 += (ch.SLOT [S3].Finc * freq_LFO) >> (LFO_FMS_LBITS - 1); + + int t0 = buf [0] + (CH_OUTd & ch.LEFT); + int t1 = buf [1] + (CH_OUTd & ch.RIGHT); + + update_envelope( ch.SLOT [0] ); + update_envelope( ch.SLOT [1] ); + update_envelope( ch.SLOT [2] ); + update_envelope( ch.SLOT [3] ); + + ch.S0_OUT [0] = CH_S0_OUT_0; + buf [0] = t0; + buf [1] = t1; + buf += 2; + } + while ( --length ); + + ch.S0_OUT [1] = CH_S0_OUT_1; + + ch.SLOT [S0].Fcnt = in0; + ch.SLOT [S1].Fcnt = in1; + ch.SLOT [S2].Fcnt = in2; + ch.SLOT [S3].Fcnt = in3; +} + +static const ym2612_update_chan_t UPDATE_CHAN [8] = { + &ym2612_update_chan<0>::func, + &ym2612_update_chan<1>::func, + &ym2612_update_chan<2>::func, + &ym2612_update_chan<3>::func, + &ym2612_update_chan<4>::func, + &ym2612_update_chan<5>::func, + &ym2612_update_chan<6>::func, + &ym2612_update_chan<7>::func +}; + +void Ym2612_Impl::run_timer( int length ) +{ + int const step = 6; + int remain = length; + do + { + int n = step; + if ( n > remain ) + n = remain; + remain -= n; + + long i = n * YM2612.TimerBase; + if (YM2612.Mode & 1) // Timer A ON ? + { + // if ((YM2612.TimerAcnt -= 14073) <= 0) // 13879=NTSC (old: 14475=NTSC 14586=PAL) + if ((YM2612.TimerAcnt -= i) <= 0) + { + // timer a overflow + + YM2612.Status |= (YM2612.Mode & 0x04) >> 2; + YM2612.TimerAcnt += YM2612.TimerAL; + + if (YM2612.Mode & 0x80) + { + KEY_ON( YM2612.CHANNEL [2], 0 ); + KEY_ON( YM2612.CHANNEL [2], 1 ); + KEY_ON( YM2612.CHANNEL [2], 2 ); + KEY_ON( YM2612.CHANNEL [2], 3 ); + } + } + } + + if (YM2612.Mode & 2) // Timer B ON ? + { + // if ((YM2612.TimerBcnt -= 14073) <= 0) // 13879=NTSC (old: 14475=NTSC 14586=PAL) + if ((YM2612.TimerBcnt -= i) <= 0) + { + // timer b overflow + YM2612.Status |= (YM2612.Mode & 0x08) >> 2; + YM2612.TimerBcnt += YM2612.TimerBL; + } + } + } + while ( remain > 0 ); +} + +void Ym2612_Impl::run( int pair_count, Ym2612_Emu::sample_t* out ) +{ + if ( pair_count <= 0 ) + return; + + if ( YM2612.Mode & 3 ) + run_timer( pair_count ); + + // Mise à jour des pas des compteurs-frequences s'ils ont ete modifies + + for ( int chi = 0; chi < channel_count; chi++ ) + { + channel_t& ch = YM2612.CHANNEL [chi]; + if ( ch.SLOT [0].Finc != -1 ) + continue; + + int i2 = 0; + if ( chi == 2 && (YM2612.Mode & 0x40) ) + i2 = 2; + + for ( int i = 0; i < 4; i++ ) + { + // static int seq [4] = { 2, 1, 3, 0 }; + // if ( i2 ) i2 = seq [i]; + + slot_t& sl = ch.SLOT [i]; + int finc = g.FINC_TAB [ch.FNUM [i2]] >> (7 - ch.FOCT [i2]); + int ksr = ch.KC [i2] >> sl.KSR_S; // keycode attenuation + sl.Finc = (finc + sl.DT [ch.KC [i2]]) * sl.MUL; + if (sl.KSR != ksr) // si le KSR a change alors + { // les differents taux pour l'enveloppe sont mis à jour + sl.KSR = ksr; + + sl.EincA = sl.AR [ksr]; + sl.EincD = sl.DR [ksr]; + sl.EincS = sl.SR [ksr]; + sl.EincR = sl.RR [ksr]; + + if (sl.Ecurp == ATTACK) + { + sl.Einc = sl.EincA; + } + else if (sl.Ecurp == DECAY) + { + sl.Einc = sl.EincD; + } + else if (sl.Ecnt < ENV_END) + { + if (sl.Ecurp == SUBSTAIN) + sl.Einc = sl.EincS; + else if (sl.Ecurp == RELEASE) + sl.Einc = sl.EincR; + } + } + + if ( i2 ) + i2 = (i2 ^ 2) ^ (i2 >> 1); + } + } + + for ( int i = 0; i < channel_count; i++ ) + { + if ( !(mute_mask & (1 << i)) && (i != 5 || !YM2612.DAC) ) + UPDATE_CHAN [YM2612.CHANNEL [i].ALGO]( g, YM2612.CHANNEL [i], out, pair_count ); + } + + g.LFOcnt += g.LFOinc * pair_count; +} + +void Ym2612_Emu::run( int pair_count, sample_t* out ) { impl->run( pair_count, out ); } diff --git a/libs/gme/gme/Ym2612_Emu.h b/libs/gme/gme/Ym2612_Emu.h new file mode 100644 index 000000000..51cff6586 --- /dev/null +++ b/libs/gme/gme/Ym2612_Emu.h @@ -0,0 +1,38 @@ +// YM2612 FM sound chip emulator interface + +// Game_Music_Emu 0.6.0 +#ifndef YM2612_EMU_H +#define YM2612_EMU_H + +struct Ym2612_Impl; + +class Ym2612_Emu { + Ym2612_Impl* impl; +public: + Ym2612_Emu() { impl = 0; } + ~Ym2612_Emu(); + + // Set output sample rate and chip clock rates, in Hz. Returns non-zero + // if error. + const char* set_rate( double sample_rate, double clock_rate ); + + // Reset to power-up state + void reset(); + + // Mute voice n if bit n (1 << n) of mask is set + enum { channel_count = 6 }; + void mute_voices( int mask ); + + // Write addr to register 0 then data to register 1 + void write0( int addr, int data ); + + // Write addr to register 2 then data to register 3 + void write1( int addr, int data ); + + // Run and add pair_count samples into current output buffer contents + typedef short sample_t; + enum { out_chan_count = 2 }; // stereo + void run( int pair_count, sample_t* out ); +}; + +#endif diff --git a/libs/gme/gme/blargg_common.h b/libs/gme/gme/blargg_common.h new file mode 100644 index 000000000..ed218a8da --- /dev/null +++ b/libs/gme/gme/blargg_common.h @@ -0,0 +1,196 @@ +// Sets up common environment for Shay Green's libraries. +// To change configuration options, modify blargg_config.h, not this file. + +#ifndef BLARGG_COMMON_H +#define BLARGG_COMMON_H + +#include +#include +#include +#include + +#undef BLARGG_COMMON_H +// allow blargg_config.h to #include blargg_common.h +#include "blargg_config.h" +#ifndef BLARGG_COMMON_H +#define BLARGG_COMMON_H + +// BLARGG_RESTRICT: equivalent to restrict, where supported +#if __GNUC__ >= 3 || _MSC_VER >= 1100 + #define BLARGG_RESTRICT __restrict +#else + #define BLARGG_RESTRICT +#endif + +// STATIC_CAST(T,expr): Used in place of static_cast (expr) +#ifndef STATIC_CAST + #define STATIC_CAST(T,expr) ((T) (expr)) +#endif + +// blargg_err_t (0 on success, otherwise error string) +#ifndef blargg_err_t + typedef const char* blargg_err_t; +#endif + +// blargg_vector - very lightweight vector of POD types (no constructor/destructor) +template +class blargg_vector { + T* begin_; + size_t size_; +public: + blargg_vector() : begin_( 0 ), size_( 0 ) { } + ~blargg_vector() { free( begin_ ); } + size_t size() const { return size_; } + T* begin() const { return begin_; } + T* end() const { return begin_ + size_; } + blargg_err_t resize( size_t n ) + { + void* p = realloc( begin_, n * sizeof (T) ); + if ( !p && n ) + return "Out of memory"; + begin_ = (T*) p; + size_ = n; + return 0; + } + void clear() { void* p = begin_; begin_ = 0; size_ = 0; free( p ); } + T& operator [] ( size_t n ) const + { + assert( n <= size_ ); // <= to allow past-the-end value + return begin_ [n]; + } +}; + +#ifndef BLARGG_DISABLE_NOTHROW + // throw spec mandatory in ISO C++ if operator new can return NULL + #if __cplusplus >= 199711 || __GNUC__ >= 3 + #define BLARGG_THROWS( spec ) throw spec + #else + #define BLARGG_THROWS( spec ) + #endif + #define BLARGG_DISABLE_NOTHROW \ + void* operator new ( size_t s ) BLARGG_THROWS(()) { return malloc( s ); }\ + void operator delete ( void* p ) { free( p ); } + #define BLARGG_NEW new +#else + #include + #define BLARGG_NEW new (std::nothrow) +#endif + +// BLARGG_4CHAR('a','b','c','d') = 'abcd' (four character integer constant) +#define BLARGG_4CHAR( a, b, c, d ) \ + ((a&0xFF)*0x1000000L + (b&0xFF)*0x10000L + (c&0xFF)*0x100L + (d&0xFF)) + +// BOOST_STATIC_ASSERT( expr ): Generates compile error if expr is 0. +#ifndef BOOST_STATIC_ASSERT + #ifdef _MSC_VER + // MSVC6 (_MSC_VER < 1300) fails for use of __LINE__ when /Zl is specified + #define BOOST_STATIC_ASSERT( expr ) \ + void blargg_failed_( int (*arg) [2 / (int) !!(expr) - 1] ) + #else + // Some other compilers fail when declaring same function multiple times in class, + // so differentiate them by line + #define BOOST_STATIC_ASSERT( expr ) \ + void blargg_failed_( int (*arg) [2 / !!(expr) - 1] [__LINE__] ) + #endif +#endif + +// BLARGG_COMPILER_HAS_BOOL: If 0, provides bool support for old compiler. If 1, +// compiler is assumed to support bool. If undefined, availability is determined. +#ifndef BLARGG_COMPILER_HAS_BOOL + #if defined (__MWERKS__) + #if !__option(bool) + #define BLARGG_COMPILER_HAS_BOOL 0 + #endif + #elif defined (_MSC_VER) + #if _MSC_VER < 1100 + #define BLARGG_COMPILER_HAS_BOOL 0 + #endif + #elif defined (__GNUC__) + // supports bool + #elif __cplusplus < 199711 + #define BLARGG_COMPILER_HAS_BOOL 0 + #endif +#endif +#if defined (BLARGG_COMPILER_HAS_BOOL) && !BLARGG_COMPILER_HAS_BOOL + // If you get errors here, modify your blargg_config.h file + typedef int bool; + const bool true = 1; + const bool false = 0; +#endif + +// blargg_long/blargg_ulong = at least 32 bits, int if it's big enough + +#if INT_MAX < 0x7FFFFFFF || LONG_MAX == 0x7FFFFFFF + typedef long blargg_long; +#else + typedef int blargg_long; +#endif + +#if UINT_MAX < 0xFFFFFFFF || ULONG_MAX == 0xFFFFFFFF + typedef unsigned long blargg_ulong; +#else + typedef unsigned blargg_ulong; +#endif + +// BOOST::int8_t etc. + +// HAVE_STDINT_H: If defined, use for int8_t etc. +#if defined (HAVE_STDINT_H) + #include + #define BOOST + +// HAVE_INTTYPES_H: If defined, use for int8_t etc. +#elif defined (HAVE_INTTYPES_H) + #include + #define BOOST + +#else + struct BOOST + { + #if UCHAR_MAX == 0xFF && SCHAR_MAX == 0x7F + typedef signed char int8_t; + typedef unsigned char uint8_t; + #else + // No suitable 8-bit type available + typedef struct see_blargg_common_h int8_t; + typedef struct see_blargg_common_h uint8_t; + #endif + + #if USHRT_MAX == 0xFFFF + typedef short int16_t; + typedef unsigned short uint16_t; + #else + // No suitable 16-bit type available + typedef struct see_blargg_common_h int16_t; + typedef struct see_blargg_common_h uint16_t; + #endif + + #if ULONG_MAX == 0xFFFFFFFF + typedef long int32_t; + typedef unsigned long uint32_t; + #elif UINT_MAX == 0xFFFFFFFF + typedef int int32_t; + typedef unsigned int uint32_t; + #else + // No suitable 32-bit type available + typedef struct see_blargg_common_h int32_t; + typedef struct see_blargg_common_h uint32_t; + #endif + }; +#endif + +#if __GNUC__ >= 3 + #define BLARGG_DEPRECATED __attribute__ ((deprecated)) +#else + #define BLARGG_DEPRECATED +#endif + +// Use in place of "= 0;" for a pure virtual, since these cause calls to std C++ lib. +// During development, BLARGG_PURE( x ) expands to = 0; +// virtual int func() BLARGG_PURE( { return 0; } ) +#ifndef BLARGG_PURE + #define BLARGG_PURE( def ) def +#endif + +#endif +#endif diff --git a/libs/gme/gme/blargg_config.h b/libs/gme/gme/blargg_config.h new file mode 100644 index 000000000..377dd2d8c --- /dev/null +++ b/libs/gme/gme/blargg_config.h @@ -0,0 +1,43 @@ +// Library configuration. Modify this file as necessary. + +#ifndef BLARGG_CONFIG_H +#define BLARGG_CONFIG_H + +// Uncomment to use zlib for transparent decompression of gzipped files +//#define HAVE_ZLIB_H + +// Uncomment and edit list to support only the listed game music types, +// so that the others don't get linked in at all. +/* +#define GME_TYPE_LIST \ + gme_ay_type,\ + gme_gbs_type,\ + gme_gym_type,\ + gme_hes_type,\ + gme_kss_type,\ + gme_nsf_type,\ + gme_nsfe_type,\ + gme_sap_type,\ + gme_spc_type,\ + gme_vgm_type,\ + gme_vgz_type +*/ + +// Uncomment to enable platform-specific optimizations +//#define BLARGG_NONPORTABLE 1 + +// Uncomment to use faster, lower quality sound synthesis +//#define BLIP_BUFFER_FAST 1 + +// Uncomment if automatic byte-order determination doesn't work +//#define BLARGG_BIG_ENDIAN 1 + +// Uncomment if you get errors in the bool section of blargg_common.h +//#define BLARGG_COMPILER_HAS_BOOL 1 + +// Use standard config.h if present +#ifdef HAVE_CONFIG_H + #include "config.h" +#endif + +#endif diff --git a/libs/gme/gme/blargg_endian.h b/libs/gme/gme/blargg_endian.h new file mode 100644 index 000000000..ba09e067e --- /dev/null +++ b/libs/gme/gme/blargg_endian.h @@ -0,0 +1,184 @@ +// CPU Byte Order Utilities + +#ifndef BLARGG_ENDIAN +#define BLARGG_ENDIAN + +#include "blargg_common.h" + +// BLARGG_CPU_CISC: Defined if CPU has very few general-purpose registers (< 16) +#if defined (__i386__) || defined (__x86_64__) || defined (_M_IX86) || defined (_M_X64) + #define BLARGG_CPU_X86 1 + #define BLARGG_CPU_CISC 1 +#endif + +#if defined (__powerpc__) || defined (__ppc__) || defined (__ppc64__) || \ + defined (__POWERPC__) || defined (__powerc) + #define BLARGG_CPU_POWERPC 1 + #define BLARGG_CPU_RISC 1 +#endif + +// BLARGG_BIG_ENDIAN, BLARGG_LITTLE_ENDIAN: Determined automatically, otherwise only +// one may be #defined to 1. Only needed if something actually depends on byte order. +#if !defined (BLARGG_BIG_ENDIAN) && !defined (BLARGG_LITTLE_ENDIAN) +#ifdef __GLIBC__ + // GCC handles this for us + #include + #if __BYTE_ORDER == __LITTLE_ENDIAN + #define BLARGG_LITTLE_ENDIAN 1 + #elif __BYTE_ORDER == __BIG_ENDIAN + #define BLARGG_BIG_ENDIAN 1 + #endif +#else + +#if defined (LSB_FIRST) || defined (__LITTLE_ENDIAN__) || BLARGG_CPU_X86 || \ + (defined (LITTLE_ENDIAN) && LITTLE_ENDIAN+0 != 1234) + #define BLARGG_LITTLE_ENDIAN 1 +#endif + +#if defined (MSB_FIRST) || defined (__BIG_ENDIAN__) || defined (WORDS_BIGENDIAN) || \ + defined (__sparc__) || BLARGG_CPU_POWERPC || \ + (defined (BIG_ENDIAN) && BIG_ENDIAN+0 != 4321) + #define BLARGG_BIG_ENDIAN 1 +#elif !defined (__mips__) + // No endian specified; assume little-endian, since it's most common + #define BLARGG_LITTLE_ENDIAN 1 +#endif +#endif +#endif + +#if BLARGG_LITTLE_ENDIAN && BLARGG_BIG_ENDIAN + #undef BLARGG_LITTLE_ENDIAN + #undef BLARGG_BIG_ENDIAN +#endif + +inline void blargg_verify_byte_order() +{ + #ifndef NDEBUG + #if BLARGG_BIG_ENDIAN + volatile int i = 1; + assert( *(volatile char*) &i == 0 ); + #elif BLARGG_LITTLE_ENDIAN + volatile int i = 1; + assert( *(volatile char*) &i != 0 ); + #endif + #endif +} + +inline unsigned get_le16( void const* p ) +{ + return (unsigned) ((unsigned char const*) p) [1] << 8 | + (unsigned) ((unsigned char const*) p) [0]; +} + +inline unsigned get_be16( void const* p ) +{ + return (unsigned) ((unsigned char const*) p) [0] << 8 | + (unsigned) ((unsigned char const*) p) [1]; +} + +inline blargg_ulong get_le32( void const* p ) +{ + return (blargg_ulong) ((unsigned char const*) p) [3] << 24 | + (blargg_ulong) ((unsigned char const*) p) [2] << 16 | + (blargg_ulong) ((unsigned char const*) p) [1] << 8 | + (blargg_ulong) ((unsigned char const*) p) [0]; +} + +inline blargg_ulong get_be32( void const* p ) +{ + return (blargg_ulong) ((unsigned char const*) p) [0] << 24 | + (blargg_ulong) ((unsigned char const*) p) [1] << 16 | + (blargg_ulong) ((unsigned char const*) p) [2] << 8 | + (blargg_ulong) ((unsigned char const*) p) [3]; +} + +inline void set_le16( void* p, unsigned n ) +{ + ((unsigned char*) p) [1] = (unsigned char) (n >> 8); + ((unsigned char*) p) [0] = (unsigned char) n; +} + +inline void set_be16( void* p, unsigned n ) +{ + ((unsigned char*) p) [0] = (unsigned char) (n >> 8); + ((unsigned char*) p) [1] = (unsigned char) n; +} + +inline void set_le32( void* p, blargg_ulong n ) +{ + ((unsigned char*) p) [0] = (unsigned char) n; + ((unsigned char*) p) [1] = (unsigned char) (n >> 8); + ((unsigned char*) p) [2] = (unsigned char) (n >> 16); + ((unsigned char*) p) [3] = (unsigned char) (n >> 24); +} + +inline void set_be32( void* p, blargg_ulong n ) +{ + ((unsigned char*) p) [3] = (unsigned char) n; + ((unsigned char*) p) [2] = (unsigned char) (n >> 8); + ((unsigned char*) p) [1] = (unsigned char) (n >> 16); + ((unsigned char*) p) [0] = (unsigned char) (n >> 24); +} + +#if BLARGG_NONPORTABLE + // Optimized implementation if byte order is known + #if BLARGG_LITTLE_ENDIAN + #define GET_LE16( addr ) (*(BOOST::uint16_t*) (addr)) + #define GET_LE32( addr ) (*(BOOST::uint32_t*) (addr)) + #define SET_LE16( addr, data ) (void) (*(BOOST::uint16_t*) (addr) = (data)) + #define SET_LE32( addr, data ) (void) (*(BOOST::uint32_t*) (addr) = (data)) + #elif BLARGG_BIG_ENDIAN + #define GET_BE16( addr ) (*(BOOST::uint16_t*) (addr)) + #define GET_BE32( addr ) (*(BOOST::uint32_t*) (addr)) + #define SET_BE16( addr, data ) (void) (*(BOOST::uint16_t*) (addr) = (data)) + #define SET_BE32( addr, data ) (void) (*(BOOST::uint32_t*) (addr) = (data)) + + #if BLARGG_CPU_POWERPC + // PowerPC has special byte-reversed instructions + #if defined (__MWERKS__) + #define GET_LE16( addr ) (__lhbrx( addr, 0 )) + #define GET_LE32( addr ) (__lwbrx( addr, 0 )) + #define SET_LE16( addr, in ) (__sthbrx( in, addr, 0 )) + #define SET_LE32( addr, in ) (__stwbrx( in, addr, 0 )) + #elif defined (__GNUC__) + #define GET_LE16( addr ) ({unsigned short ppc_lhbrx_; __asm__ volatile( "lhbrx %0,0,%1" : "=r" (ppc_lhbrx_) : "r" (addr) : "memory" ); ppc_lhbrx_;}) + #define GET_LE32( addr ) ({unsigned short ppc_lwbrx_; __asm__ volatile( "lwbrx %0,0,%1" : "=r" (ppc_lwbrx_) : "r" (addr) : "memory" ); ppc_lwbrx_;}) + #define SET_LE16( addr, in ) ({__asm__ volatile( "sthbrx %0,0,%1" : : "r" (in), "r" (addr) : "memory" );}) + #define SET_LE32( addr, in ) ({__asm__ volatile( "stwbrx %0,0,%1" : : "r" (in), "r" (addr) : "memory" );}) + #endif + #endif + #endif +#endif + +#ifndef GET_LE16 + #define GET_LE16( addr ) get_le16( addr ) + #define SET_LE16( addr, data ) set_le16( addr, data ) +#endif + +#ifndef GET_LE32 + #define GET_LE32( addr ) get_le32( addr ) + #define SET_LE32( addr, data ) set_le32( addr, data ) +#endif + +#ifndef GET_BE16 + #define GET_BE16( addr ) get_be16( addr ) + #define SET_BE16( addr, data ) set_be16( addr, data ) +#endif + +#ifndef GET_BE32 + #define GET_BE32( addr ) get_be32( addr ) + #define SET_BE32( addr, data ) set_be32( addr, data ) +#endif + +// auto-selecting versions + +inline void set_le( BOOST::uint16_t* p, unsigned n ) { SET_LE16( p, n ); } +inline void set_le( BOOST::uint32_t* p, blargg_ulong n ) { SET_LE32( p, n ); } +inline void set_be( BOOST::uint16_t* p, unsigned n ) { SET_BE16( p, n ); } +inline void set_be( BOOST::uint32_t* p, blargg_ulong n ) { SET_BE32( p, n ); } +inline unsigned get_le( BOOST::uint16_t* p ) { return GET_LE16( p ); } +inline blargg_ulong get_le( BOOST::uint32_t* p ) { return GET_LE32( p ); } +inline unsigned get_be( BOOST::uint16_t* p ) { return GET_BE16( p ); } +inline blargg_ulong get_be( BOOST::uint32_t* p ) { return GET_BE32( p ); } + +#endif diff --git a/libs/gme/gme/blargg_source.h b/libs/gme/gme/blargg_source.h new file mode 100644 index 000000000..b011777ad --- /dev/null +++ b/libs/gme/gme/blargg_source.h @@ -0,0 +1,110 @@ +/* Included at the beginning of library source files, after all other #include lines. +Sets up helpful macros and services used in my source code. They don't need +module an annoying module prefix on their names since they are defined after +all other #include lines. */ + +#ifndef BLARGG_SOURCE_H +#define BLARGG_SOURCE_H + +// If debugging is enabled, abort program if expr is false. Meant for checking +// internal state and consistency. A failed assertion indicates a bug in the module. +// void assert( bool expr ); +#include + +// If debugging is enabled and expr is false, abort program. Meant for checking +// caller-supplied parameters and operations that are outside the control of the +// module. A failed requirement indicates a bug outside the module. +// void require( bool expr ); +#undef require +#define require( expr ) assert( expr ) + +// Like printf() except output goes to debug log file. Might be defined to do +// nothing (not even evaluate its arguments). +// void debug_printf( const char* format, ... ); +static inline void blargg_dprintf_( const char*, ... ) { } +#undef debug_printf +#define debug_printf (1) ? (void) 0 : blargg_dprintf_ + +// If enabled, evaluate expr and if false, make debug log entry with source file +// and line. Meant for finding situations that should be examined further, but that +// don't indicate a problem. In all cases, execution continues normally. +#undef check +#define check( expr ) ((void) 0) + +// If expr yields error string, return it from current function, otherwise continue. +#undef RETURN_ERR +#define RETURN_ERR( expr ) do { \ + blargg_err_t blargg_return_err_ = (expr); \ + if ( blargg_return_err_ ) return blargg_return_err_; \ + } while ( 0 ) + +// If ptr is 0, return out of memory error string. +#undef CHECK_ALLOC +#define CHECK_ALLOC( ptr ) do { if ( (ptr) == 0 ) return "Out of memory"; } while ( 0 ) + +// Avoid any macros which evaluate their arguments multiple times +#undef min +#undef max + +#define DEF_MIN_MAX( type ) \ + static inline type min( type x, type y ) { if ( x < y ) return x; return y; }\ + static inline type max( type x, type y ) { if ( y < x ) return x; return y; } + +DEF_MIN_MAX( int ) +DEF_MIN_MAX( unsigned ) +DEF_MIN_MAX( long ) +DEF_MIN_MAX( unsigned long ) +DEF_MIN_MAX( float ) +DEF_MIN_MAX( double ) + +#undef DEF_MIN_MAX + +/* +// using const references generates crappy code, and I am currenly only using these +// for built-in types, so they take arguments by value + +// TODO: remove +inline int min( int x, int y ) +template +inline T min( T x, T y ) +{ + if ( x < y ) + return x; + return y; +} + +template +inline T max( T x, T y ) +{ + if ( x < y ) + return y; + return x; +} +*/ + +// TODO: good idea? bad idea? +#undef byte +#define byte byte_ +typedef unsigned char byte; + +// Setup compiler defines useful for exporting required public API symbols in gme.cpp +#ifndef BLARGG_EXPORT + #if defined (_WIN32) && defined(BLARGG_BUILD_DLL) + #define BLARGG_EXPORT __declspec(dllexport) + #elif defined (LIBGME_VISIBILITY) + #define BLARGG_EXPORT __attribute__((visibility ("default"))) + #else + #define BLARGG_EXPORT + #endif +#endif + +// deprecated +#define BLARGG_CHECK_ALLOC CHECK_ALLOC +#define BLARGG_RETURN_ERR RETURN_ERR + +// BLARGG_SOURCE_BEGIN: If defined, #included, allowing redefition of debug_printf and check +#ifdef BLARGG_SOURCE_BEGIN + #include BLARGG_SOURCE_BEGIN +#endif + +#endif diff --git a/libs/gme/gme/gb_cpu_io.h b/libs/gme/gme/gb_cpu_io.h new file mode 100644 index 000000000..8bd69aa2d --- /dev/null +++ b/libs/gme/gme/gb_cpu_io.h @@ -0,0 +1,72 @@ + +#include "Gbs_Emu.h" + +#include "blargg_source.h" + +int Gbs_Emu::cpu_read( gb_addr_t addr ) +{ + int result = *cpu::get_code( addr ); + if ( unsigned (addr - Gb_Apu::start_addr) < Gb_Apu::register_count ) + result = apu.read_register( clock(), addr ); +#ifndef NDEBUG + else if ( unsigned (addr - 0x8000) < 0x2000 || unsigned (addr - 0xE000) < 0x1F00 ) + debug_printf( "Read from unmapped memory $%.4x\n", (unsigned) addr ); + else if ( unsigned (addr - 0xFF01) < 0xFF80 - 0xFF01 ) + debug_printf( "Unhandled I/O read 0x%4X\n", (unsigned) addr ); +#endif + return result; +} + +void Gbs_Emu::cpu_write( gb_addr_t addr, int data ) +{ + unsigned offset = addr - ram_addr; + if ( offset <= 0xFFFF - ram_addr ) + { + ram [offset] = data; + if ( (addr ^ 0xE000) <= 0x1F80 - 1 ) + { + if ( unsigned (addr - Gb_Apu::start_addr) < Gb_Apu::register_count ) + { + GME_APU_HOOK( this, addr - Gb_Apu::start_addr, data ); + apu.write_register( clock(), addr, data ); + } + else if ( (addr ^ 0xFF06) < 2 ) + update_timer(); + else if ( addr == joypad_addr ) + ram [offset] = 0; // keep joypad return value 0 + else + ram [offset] = 0xFF; + + //if ( addr == 0xFFFF ) + // debug_printf( "Wrote interrupt mask\n" ); + } + } + else if ( (addr ^ 0x2000) <= 0x2000 - 1 ) + { + set_bank( data ); + } +#ifndef NDEBUG + else if ( unsigned (addr - 0x8000) < 0x2000 || unsigned (addr - 0xE000) < 0x1F00 ) + { + debug_printf( "Wrote to unmapped memory $%.4x\n", (unsigned) addr ); + } +#endif +} + +#define CPU_READ_FAST( cpu, addr, time, out ) \ + CPU_READ_FAST_( STATIC_CAST(Gbs_Emu*,cpu), addr, time, out ) + +#define CPU_READ_FAST_( emu, addr, time, out ) \ +{\ + out = READ_PROG( addr );\ + if ( unsigned (addr - Gb_Apu::start_addr) < Gb_Apu::register_count )\ + out = emu->apu.read_register( emu->cpu_time - time * clocks_per_instr, addr );\ + else\ + check( out == emu->cpu_read( addr ) );\ +} + +#define CPU_READ( cpu, addr, time ) \ + STATIC_CAST(Gbs_Emu*,cpu)->cpu_read( addr ) + +#define CPU_WRITE( cpu, addr, data, time ) \ + STATIC_CAST(Gbs_Emu*,cpu)->cpu_write( addr, data ) diff --git a/libs/gme/gme/gme.cpp b/libs/gme/gme/gme.cpp new file mode 100644 index 000000000..c05f25eb4 --- /dev/null +++ b/libs/gme/gme/gme.cpp @@ -0,0 +1,376 @@ +// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/ + +#include "Music_Emu.h" + +#include "gme_types.h" +#if !GME_DISABLE_STEREO_DEPTH +#include "Effects_Buffer.h" +#endif +#include "blargg_endian.h" +#include +#include + +/* Copyright (C) 2003-2006 Shay Green. This module 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 +module 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 module; if not, write to the Free Software Foundation, +Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + +#include "blargg_source.h" + +BLARGG_EXPORT gme_type_t const* gme_type_list() +{ + static gme_type_t const gme_type_list_ [] = { +#ifdef GME_TYPE_LIST + GME_TYPE_LIST, +#else + #ifdef USE_GME_AY + gme_ay_type, + #endif + #ifdef USE_GME_GBS + gme_gbs_type, + #endif + #ifdef USE_GME_GYM + gme_gym_type, + #endif + #ifdef USE_GME_HES + gme_hes_type, + #endif + #ifdef USE_GME_KSS + gme_kss_type, + #endif + #ifdef USE_GME_NSF + gme_nsf_type, + #endif + #ifdef USE_GME_NSFE + gme_nsfe_type, + #endif + #ifdef USE_GME_SAP + gme_sap_type, + #endif + #ifdef USE_GME_SPC + gme_spc_type, + #endif + #ifdef USE_GME_VGM + gme_vgm_type, + gme_vgz_type, + #endif +#endif + 0 + }; + + return gme_type_list_; +} + +BLARGG_EXPORT const char* gme_identify_header( void const* header ) +{ + switch ( get_be32( header ) ) + { + case BLARGG_4CHAR('Z','X','A','Y'): return "AY"; + case BLARGG_4CHAR('G','B','S',0x01): return "GBS"; + case BLARGG_4CHAR('G','Y','M','X'): return "GYM"; + case BLARGG_4CHAR('H','E','S','M'): return "HES"; + case BLARGG_4CHAR('K','S','C','C'): + case BLARGG_4CHAR('K','S','S','X'): return "KSS"; + case BLARGG_4CHAR('N','E','S','M'): return "NSF"; + case BLARGG_4CHAR('N','S','F','E'): return "NSFE"; + case BLARGG_4CHAR('S','A','P',0x0D): return "SAP"; + case BLARGG_4CHAR('S','N','E','S'): return "SPC"; + case BLARGG_4CHAR('V','g','m',' '): return "VGM"; + } + return ""; +} + +static void to_uppercase( const char* in, int len, char* out ) +{ + for ( int i = 0; i < len; i++ ) + { + if ( !(out [i] = toupper( in [i] )) ) + return; + } + *out = 0; // extension too long +} + +BLARGG_EXPORT gme_type_t gme_identify_extension( const char* extension_ ) +{ + char const* end = strrchr( extension_, '.' ); + if ( end ) + extension_ = end + 1; + + char extension [6]; + to_uppercase( extension_, sizeof extension, extension ); + + for ( gme_type_t const* types = gme_type_list(); *types; types++ ) + if ( !strcmp( extension, (*types)->extension_ ) ) + return *types; + return 0; +} + +BLARGG_EXPORT gme_err_t gme_identify_file( const char* path, gme_type_t* type_out ) +{ + *type_out = gme_identify_extension( path ); + // TODO: don't examine header if file has extension? + if ( !*type_out ) + { + char header [4]; + GME_FILE_READER in; + RETURN_ERR( in.open( path ) ); + RETURN_ERR( in.read( header, sizeof header ) ); + *type_out = gme_identify_extension( gme_identify_header( header ) ); + } + return 0; +} + +BLARGG_EXPORT gme_err_t gme_open_data( void const* data, long size, Music_Emu** out, int sample_rate ) +{ + require( (data || !size) && out ); + *out = 0; + + gme_type_t file_type = 0; + if ( size >= 4 ) + file_type = gme_identify_extension( gme_identify_header( data ) ); + if ( !file_type ) + return gme_wrong_file_type; + + Music_Emu* emu = gme_new_emu( file_type, sample_rate ); + CHECK_ALLOC( emu ); + + gme_err_t err = gme_load_data( emu, data, size ); + + if ( err ) + delete emu; + else + *out = emu; + + return err; +} + +BLARGG_EXPORT gme_err_t gme_open_file( const char* path, Music_Emu** out, int sample_rate ) +{ + require( path && out ); + *out = 0; + + GME_FILE_READER in; + RETURN_ERR( in.open( path ) ); + + char header [4]; + int header_size = 0; + + gme_type_t file_type = gme_identify_extension( path ); + if ( !file_type ) + { + header_size = sizeof header; + RETURN_ERR( in.read( header, sizeof header ) ); + file_type = gme_identify_extension( gme_identify_header( header ) ); + } + if ( !file_type ) + return gme_wrong_file_type; + + Music_Emu* emu = gme_new_emu( file_type, sample_rate ); + CHECK_ALLOC( emu ); + + // optimization: avoids seeking/re-reading header + Remaining_Reader rem( header, header_size, &in ); + gme_err_t err = emu->load( rem ); + in.close(); + + if ( err ) + delete emu; + else + *out = emu; + + return err; +} + +BLARGG_EXPORT Music_Emu* gme_new_emu( gme_type_t type, int rate ) +{ + if ( type ) + { + if ( rate == gme_info_only ) + return type->new_info(); + + Music_Emu* me = type->new_emu(); + if ( me ) + { + #if !GME_DISABLE_STEREO_DEPTH + if ( type->flags_ & 1 ) + { + me->effects_buffer = BLARGG_NEW Effects_Buffer; + if ( me->effects_buffer ) + me->set_buffer( me->effects_buffer ); + } + + if ( !(type->flags_ & 1) || me->effects_buffer ) + #endif + { + if ( !me->set_sample_rate( rate ) ) + { + check( me->type() == type ); + return me; + } + } + delete me; + } + } + return 0; +} + +BLARGG_EXPORT gme_err_t gme_load_file( Music_Emu* me, const char* path ) { return me->load_file( path ); } + +BLARGG_EXPORT gme_err_t gme_load_data( Music_Emu* me, void const* data, long size ) +{ + Mem_File_Reader in( data, size ); + return me->load( in ); +} + +BLARGG_EXPORT gme_err_t gme_load_custom( Music_Emu* me, gme_reader_t func, long size, void* data ) +{ + Callback_Reader in( func, size, data ); + return me->load( in ); +} + +BLARGG_EXPORT void gme_delete( Music_Emu* me ) { delete me; } + +BLARGG_EXPORT gme_type_t gme_type( Music_Emu const* me ) { return me->type(); } + +BLARGG_EXPORT const char* gme_warning( Music_Emu* me ) { return me->warning(); } + +BLARGG_EXPORT int gme_track_count( Music_Emu const* me ) { return me->track_count(); } + +struct gme_info_t_ : gme_info_t +{ + track_info_t info; + + BLARGG_DISABLE_NOTHROW +}; + +BLARGG_EXPORT gme_err_t gme_track_info( Music_Emu const* me, gme_info_t** out, int track ) +{ + *out = NULL; + + gme_info_t_* info = BLARGG_NEW gme_info_t_; + CHECK_ALLOC( info ); + + gme_err_t err = me->track_info( &info->info, track ); + if ( err ) + { + gme_free_info( info ); + return err; + } + + #define COPY(name) info->name = info->info.name; + + COPY( length ); + COPY( intro_length ); + COPY( loop_length ); + + info->i4 = -1; + info->i5 = -1; + info->i6 = -1; + info->i7 = -1; + info->i8 = -1; + info->i9 = -1; + info->i10 = -1; + info->i11 = -1; + info->i12 = -1; + info->i13 = -1; + info->i14 = -1; + info->i15 = -1; + + info->s7 = ""; + info->s8 = ""; + info->s9 = ""; + info->s10 = ""; + info->s11 = ""; + info->s12 = ""; + info->s13 = ""; + info->s14 = ""; + info->s15 = ""; + + COPY( system ); + COPY( game ); + COPY( song ); + COPY( author ); + COPY( copyright ); + COPY( comment ); + COPY( dumper ); + + #undef COPY + + info->play_length = info->length; + if ( info->play_length <= 0 ) + { + info->play_length = info->intro_length + 2 * info->loop_length; // intro + 2 loops + if ( info->play_length <= 0 ) + info->play_length = 150 * 1000; // 2.5 minutes + } + + *out = info; + + return 0; +} + +BLARGG_EXPORT void gme_free_info( gme_info_t* info ) +{ + delete STATIC_CAST(gme_info_t_*,info); +} + +BLARGG_EXPORT void gme_set_stereo_depth( Music_Emu* me, double depth ) +{ +#if !GME_DISABLE_STEREO_DEPTH + if ( me->effects_buffer ) + STATIC_CAST(Effects_Buffer*,me->effects_buffer)->set_depth( depth ); +#endif +} + +BLARGG_EXPORT void* gme_user_data ( Music_Emu const* me ) { return me->user_data(); } +BLARGG_EXPORT void gme_set_user_data ( Music_Emu* me, void* new_user_data ) { me->set_user_data( new_user_data ); } +BLARGG_EXPORT void gme_set_user_cleanup(Music_Emu* me, gme_user_cleanup_t func ) { me->set_user_cleanup( func ); } + +BLARGG_EXPORT gme_err_t gme_start_track ( Music_Emu* me, int index ) { return me->start_track( index ); } +BLARGG_EXPORT gme_err_t gme_play ( Music_Emu* me, int n, short* p ) { return me->play( n, p ); } +BLARGG_EXPORT void gme_set_fade ( Music_Emu* me, int start_msec ) { me->set_fade( start_msec ); } +BLARGG_EXPORT int gme_track_ended ( Music_Emu const* me ) { return me->track_ended(); } +BLARGG_EXPORT int gme_tell ( Music_Emu const* me ) { return me->tell(); } +BLARGG_EXPORT gme_err_t gme_seek ( Music_Emu* me, int msec ) { return me->seek( msec ); } +BLARGG_EXPORT int gme_voice_count ( Music_Emu const* me ) { return me->voice_count(); } +BLARGG_EXPORT void gme_ignore_silence ( Music_Emu* me, int disable ) { me->ignore_silence( disable != 0 ); } +BLARGG_EXPORT void gme_set_tempo ( Music_Emu* me, double t ) { me->set_tempo( t ); } +BLARGG_EXPORT void gme_mute_voice ( Music_Emu* me, int index, int mute ) { me->mute_voice( index, mute != 0 ); } +BLARGG_EXPORT void gme_mute_voices ( Music_Emu* me, int mask ) { me->mute_voices( mask ); } +BLARGG_EXPORT void gme_enable_accuracy( Music_Emu* me, int enabled ) { me->enable_accuracy( enabled ); } +BLARGG_EXPORT void gme_clear_playlist ( Music_Emu* me ) { me->clear_playlist(); } +BLARGG_EXPORT int gme_type_multitrack( gme_type_t t ) { return t->track_count != 1; } + +BLARGG_EXPORT void gme_set_equalizer ( Music_Emu* me, gme_equalizer_t const* eq ) +{ + Music_Emu::equalizer_t e = me->equalizer(); + e.treble = eq->treble; + e.bass = eq->bass; + me->set_equalizer( e ); +} + +BLARGG_EXPORT void gme_equalizer( Music_Emu const* me, gme_equalizer_t* out ) +{ + gme_equalizer_t e = gme_equalizer_t(); // Default-init all fields to 0.0f + e.treble = me->equalizer().treble; + e.bass = me->equalizer().bass; + *out = e; +} + +BLARGG_EXPORT const char* gme_voice_name( Music_Emu const* me, int i ) +{ + assert( (unsigned) i < (unsigned) me->voice_count() ); + return me->voice_names() [i]; +} + +BLARGG_EXPORT const char* gme_type_system( gme_type_t type ) +{ + assert( type ); + return type->system; +} diff --git a/libs/gme/gme/gme.h b/libs/gme/gme/gme.h new file mode 100644 index 000000000..1f2a2d150 --- /dev/null +++ b/libs/gme/gme/gme.h @@ -0,0 +1,241 @@ +/* Game music emulator library C interface (also usable from C++) */ + +/* Game_Music_Emu 0.6.0 */ +#ifndef GME_H +#define GME_H + +#ifdef __cplusplus + extern "C" { +#endif + +#define GME_VERSION 0x000600 /* 1 byte major, 1 byte minor, 1 byte patch-level */ + +/* Error string returned by library functions, or NULL if no error (success) */ +typedef const char* gme_err_t; + +/* First parameter of most gme_ functions is a pointer to the Music_Emu */ +typedef struct Music_Emu Music_Emu; + + +/******** Basic operations ********/ + +/* Create emulator and load game music file/data into it. Sets *out to new emulator. */ +gme_err_t gme_open_file( const char path [], Music_Emu** out, int sample_rate ); + +/* Number of tracks available */ +int gme_track_count( Music_Emu const* ); + +/* Start a track, where 0 is the first track */ +gme_err_t gme_start_track( Music_Emu*, int index ); + +/* Generate 'count' 16-bit signed samples info 'out'. Output is in stereo. */ +gme_err_t gme_play( Music_Emu*, int count, short out [] ); + +/* Finish using emulator and free memory */ +void gme_delete( Music_Emu* ); + + +/******** Track position/length ********/ + +/* Set time to start fading track out. Once fade ends track_ended() returns true. +Fade time can be changed while track is playing. */ +void gme_set_fade( Music_Emu*, int start_msec ); + +/* True if a track has reached its end */ +int gme_track_ended( Music_Emu const* ); + +/* Number of milliseconds (1000 = one second) played since beginning of track */ +int gme_tell( Music_Emu const* ); + +/* Seek to new time in track. Seeking backwards or far forward can take a while. */ +gme_err_t gme_seek( Music_Emu*, int msec ); + + +/******** Informational ********/ + +/* If you only need track information from a music file, pass gme_info_only for +sample_rate to open/load. */ +enum { gme_info_only = -1 }; + +/* Most recent warning string, or NULL if none. Clears current warning after returning. +Warning is also cleared when loading a file and starting a track. */ +const char* gme_warning( Music_Emu* ); + +/* Load m3u playlist file (must be done after loading music) */ +gme_err_t gme_load_m3u( Music_Emu*, const char path [] ); + +/* Clear any loaded m3u playlist and any internal playlist that the music format +supports (NSFE for example). */ +void gme_clear_playlist( Music_Emu* ); + +/* Gets information for a particular track (length, name, author, etc.). +Must be freed after use. */ +typedef struct gme_info_t gme_info_t; +gme_err_t gme_track_info( Music_Emu const*, gme_info_t** out, int track ); + +/* Frees track information */ +void gme_free_info( gme_info_t* ); + +struct gme_info_t +{ + /* times in milliseconds; -1 if unknown */ + int length; /* total length, if file specifies it */ + int intro_length; /* length of song up to looping section */ + int loop_length; /* length of looping section */ + + /* Length if available, otherwise intro_length+loop_length*2 if available, + otherwise a default of 150000 (2.5 minutes). */ + int play_length; + + int i4,i5,i6,i7,i8,i9,i10,i11,i12,i13,i14,i15; /* reserved */ + + /* empty string ("") if not available */ + const char* system; + const char* game; + const char* song; + const char* author; + const char* copyright; + const char* comment; + const char* dumper; + + const char *s7,*s8,*s9,*s10,*s11,*s12,*s13,*s14,*s15; /* reserved */ +}; + + +/******** Advanced playback ********/ + +/* Adjust stereo echo depth, where 0.0 = off and 1.0 = maximum. Has no effect for +GYM, SPC, and Sega Genesis VGM music */ +void gme_set_stereo_depth( Music_Emu*, double depth ); + +/* Disable automatic end-of-track detection and skipping of silence at beginning +if ignore is true */ +void gme_ignore_silence( Music_Emu*, int ignore ); + +/* Adjust song tempo, where 1.0 = normal, 0.5 = half speed, 2.0 = double speed. +Track length as returned by track_info() assumes a tempo of 1.0. */ +void gme_set_tempo( Music_Emu*, double tempo ); + +/* Number of voices used by currently loaded file */ +int gme_voice_count( Music_Emu const* ); + +/* Name of voice i, from 0 to gme_voice_count() - 1 */ +const char* gme_voice_name( Music_Emu const*, int i ); + +/* Mute/unmute voice i, where voice 0 is first voice */ +void gme_mute_voice( Music_Emu*, int index, int mute ); + +/* Set muting state of all voices at once using a bit mask, where -1 mutes all +voices, 0 unmutes them all, 0x01 mutes just the first voice, etc. */ +void gme_mute_voices( Music_Emu*, int muting_mask ); + +/* Frequency equalizer parameters (see gme.txt) */ +/* Implementers: If modified, also adjust Music_Emu::make_equalizer as needed */ +typedef struct gme_equalizer_t +{ + double treble; /* -50.0 = muffled, 0 = flat, +5.0 = extra-crisp */ + double bass; /* 1 = full bass, 90 = average, 16000 = almost no bass */ + + double d2,d3,d4,d5,d6,d7,d8,d9; /* reserved */ +} gme_equalizer_t; + +/* Get current frequency equalizater parameters */ +void gme_equalizer( Music_Emu const*, gme_equalizer_t* out ); + +/* Change frequency equalizer parameters */ +void gme_set_equalizer( Music_Emu*, gme_equalizer_t const* eq ); + +/* Enables/disables most accurate sound emulation options */ +void gme_enable_accuracy( Music_Emu*, int enabled ); + + +/******** Game music types ********/ + +/* Music file type identifier. Can also hold NULL. */ +typedef const struct gme_type_t_* gme_type_t; + +/* Emulator type constants for each supported file type */ +extern const gme_type_t + gme_ay_type, + gme_gbs_type, + gme_gym_type, + gme_hes_type, + gme_kss_type, + gme_nsf_type, + gme_nsfe_type, + gme_sap_type, + gme_spc_type, + gme_vgm_type, + gme_vgz_type; + +/* Type of this emulator */ +gme_type_t gme_type( Music_Emu const* ); + +/* Pointer to array of all music types, with NULL entry at end. Allows a player linked +to this library to support new music types without having to be updated. */ +gme_type_t const* gme_type_list(); + +/* Name of game system for this music file type */ +const char* gme_type_system( gme_type_t ); + +/* True if this music file type supports multiple tracks */ +int gme_type_multitrack( gme_type_t ); + + +/******** Advanced file loading ********/ + +/* Error returned if file type is not supported */ +extern const char* const gme_wrong_file_type; + +/* Same as gme_open_file(), but uses file data already in memory. Makes copy of data. */ +gme_err_t gme_open_data( void const* data, long size, Music_Emu** out, int sample_rate ); + +/* Determine likely game music type based on first four bytes of file. Returns +string containing proper file suffix (i.e. "NSF", "SPC", etc.) or "" if +file header is not recognized. */ +const char* gme_identify_header( void const* header ); + +/* Get corresponding music type for file path or extension passed in. */ +gme_type_t gme_identify_extension( const char path_or_extension [] ); + +/* Determine file type based on file's extension or header (if extension isn't recognized). +Sets *type_out to type, or 0 if unrecognized or error. */ +gme_err_t gme_identify_file( const char path [], gme_type_t* type_out ); + +/* Create new emulator and set sample rate. Returns NULL if out of memory. If you only need +track information, pass gme_info_only for sample_rate. */ +Music_Emu* gme_new_emu( gme_type_t, int sample_rate ); + +/* Load music file into emulator */ +gme_err_t gme_load_file( Music_Emu*, const char path [] ); + +/* Load music file from memory into emulator. Makes a copy of data passed. */ +gme_err_t gme_load_data( Music_Emu*, void const* data, long size ); + +/* Load music file using custom data reader function that will be called to +read file data. Most emulators load the entire file in one read call. */ +typedef gme_err_t (*gme_reader_t)( void* your_data, void* out, int count ); +gme_err_t gme_load_custom( Music_Emu*, gme_reader_t, long file_size, void* your_data ); + +/* Load m3u playlist file from memory (must be done after loading music) */ +gme_err_t gme_load_m3u_data( Music_Emu*, void const* data, long size ); + + +/******** User data ********/ + +/* Set/get pointer to data you want to associate with this emulator. +You can use this for whatever you want. */ +void gme_set_user_data( Music_Emu*, void* new_user_data ); +void* gme_user_data( Music_Emu const* ); + +/* Register cleanup function to be called when deleting emulator, or NULL to +clear it. Passes user_data to cleanup function. */ +typedef void (*gme_user_cleanup_t)( void* user_data ); +void gme_set_user_cleanup( Music_Emu*, gme_user_cleanup_t func ); + + +#ifdef __cplusplus + } +#endif + +#endif diff --git a/libs/gme/gme/gme_types.h b/libs/gme/gme/gme_types.h new file mode 100644 index 000000000..06226f4aa --- /dev/null +++ b/libs/gme/gme/gme_types.h @@ -0,0 +1,21 @@ +#ifndef GME_TYPES_H +#define GME_TYPES_H + +/* + * This is a default gme_types.h for use when *not* using + * CMake. If CMake is in use gme_types.h.in will be + * processed instead. + */ +#define USE_GME_AY +#define USE_GME_GBS +#define USE_GME_GYM +#define USE_GME_HES +#define USE_GME_KSS +#define USE_GME_NSF +#define USE_GME_NSFE +#define USE_GME_SAP +#define USE_GME_SPC +/* VGM and VGZ are a package deal */ +#define USE_GME_VGM + +#endif /* GME_TYPES_H */ diff --git a/libs/gme/gme/gme_types.h.in b/libs/gme/gme/gme_types.h.in new file mode 100644 index 000000000..4829b3e16 --- /dev/null +++ b/libs/gme/gme/gme_types.h.in @@ -0,0 +1,23 @@ +#ifndef GME_TYPES_H +#define GME_TYPES_H + +/* CMake will either define the following to 1, or #undef it, + * depending on the options passed to CMake. This is used to + * conditionally compile in the various emulator types. + * + * See gme_type_list() in gme.cpp + */ + +#cmakedefine USE_GME_AY +#cmakedefine USE_GME_GBS +#cmakedefine USE_GME_GYM +#cmakedefine USE_GME_HES +#cmakedefine USE_GME_KSS +#cmakedefine USE_GME_NSF +#cmakedefine USE_GME_NSFE +#cmakedefine USE_GME_SAP +#cmakedefine USE_GME_SPC +/* VGM and VGZ are a package deal */ +#cmakedefine USE_GME_VGM + +#endif /* GME_TYPES_H */ diff --git a/libs/gme/gme/hes_cpu_io.h b/libs/gme/gme/hes_cpu_io.h new file mode 100644 index 000000000..ce60ce8ef --- /dev/null +++ b/libs/gme/gme/hes_cpu_io.h @@ -0,0 +1,101 @@ + +#include "Hes_Emu.h" + +#include "blargg_source.h" + +int Hes_Emu::cpu_read( hes_addr_t addr ) +{ + check( addr <= 0xFFFF ); + int result = *cpu::get_code( addr ); + if ( mmr [addr >> page_shift] == 0xFF ) + result = cpu_read_( addr ); + return result; +} + +void Hes_Emu::cpu_write( hes_addr_t addr, int data ) +{ + check( addr <= 0xFFFF ); + byte* out = write_pages [addr >> page_shift]; + addr &= page_size - 1; + if ( out ) + out [addr] = data; + else if ( mmr [addr >> page_shift] == 0xFF ) + cpu_write_( addr, data ); +} + +inline byte const* Hes_Emu::cpu_set_mmr( int page, int bank ) +{ + write_pages [page] = 0; + if ( bank < 0x80 ) + return rom.at_addr( bank * (blargg_long) page_size ); + + byte* data = 0; + switch ( bank ) + { + case 0xF8: + data = cpu::ram; + break; + + case 0xF9: + case 0xFA: + case 0xFB: + data = &sgx [(bank - 0xF9) * page_size]; + break; + + default: + if ( bank != 0xFF ) + debug_printf( "Unmapped bank $%02X\n", bank ); + return rom.unmapped(); + } + + write_pages [page] = data; + return data; +} + +#define CPU_READ_FAST( cpu, addr, time, out ) \ + CPU_READ_FAST_( STATIC_CAST(Hes_Emu*,cpu), addr, time, out ) + +#define CPU_READ_FAST_( cpu, addr, time, out ) \ +{\ + out = READ_PROG( addr );\ + if ( mmr [addr >> page_shift] == 0xFF )\ + {\ + FLUSH_TIME();\ + out = cpu->cpu_read_( addr );\ + CACHE_TIME();\ + }\ +} + +#define CPU_WRITE_FAST( cpu, addr, data, time ) \ + CPU_WRITE_FAST_( STATIC_CAST(Hes_Emu*,cpu), addr, data, time ) + +#define CPU_WRITE_FAST_( cpu, addr, data, time ) \ +{\ + byte* out = cpu->write_pages [addr >> page_shift];\ + addr &= page_size - 1;\ + if ( out )\ + {\ + out [addr] = data;\ + }\ + else if ( mmr [addr >> page_shift] == 0xFF )\ + {\ + FLUSH_TIME();\ + cpu->cpu_write_( addr, data );\ + CACHE_TIME();\ + }\ +} + +#define CPU_READ( cpu, addr, time ) \ + STATIC_CAST(Hes_Emu*,cpu)->cpu_read( addr ) + +#define CPU_WRITE( cpu, addr, data, time ) \ + STATIC_CAST(Hes_Emu*,cpu)->cpu_write( addr, data ) + +#define CPU_WRITE_VDP( cpu, addr, data, time ) \ + STATIC_CAST(Hes_Emu*,cpu)->cpu_write_vdp( addr, data ) + +#define CPU_SET_MMR( cpu, page, bank ) \ + STATIC_CAST(Hes_Emu*,cpu)->cpu_set_mmr( page, bank ) + +#define CPU_DONE( cpu, time, result_out ) \ + result_out = STATIC_CAST(Hes_Emu*,cpu)->cpu_done() diff --git a/libs/gme/gme/libgme.pc.in b/libs/gme/gme/libgme.pc.in new file mode 100644 index 000000000..4f420d9ed --- /dev/null +++ b/libs/gme/gme/libgme.pc.in @@ -0,0 +1,15 @@ +# entries grouped with CMake are expanded by CMake +# ${foo} entries are left alone by CMake and much +# later are used by pkg-config. +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=${prefix} +lib_suffix= +libdir=${exec_prefix}/lib${lib_suffix} +includedir=${prefix}/include + +Name: Game_Music_Emu +Description: A video game emulation library for music. +URL: http://code.google.com/p/game-music-emu/ +Version: @GME_VERSION@ +Cflags: -I${includedir} +Libs: -L${libdir} -lgme diff --git a/libs/gme/gme/nes_cpu_io.h b/libs/gme/gme/nes_cpu_io.h new file mode 100644 index 000000000..68ce9b6ff --- /dev/null +++ b/libs/gme/gme/nes_cpu_io.h @@ -0,0 +1,83 @@ + +#include "Nsf_Emu.h" + +#if !NSF_EMU_APU_ONLY + #include "Nes_Namco_Apu.h" +#endif + +#include "blargg_source.h" + +int Nsf_Emu::cpu_read( nes_addr_t addr ) +{ + int result; + + result = cpu::low_mem [addr & 0x7FF]; + if ( !(addr & 0xE000) ) + goto exit; + + result = *cpu::get_code( addr ); + if ( addr > 0x7FFF ) + goto exit; + + result = sram [addr & (sizeof sram - 1)]; + if ( addr > 0x5FFF ) + goto exit; + + if ( addr == Nes_Apu::status_addr ) + return apu.read_status( cpu::time() ); + + #if !NSF_EMU_APU_ONLY + if ( addr == Nes_Namco_Apu::data_reg_addr && namco ) + return namco->read_data(); + #endif + + result = addr >> 8; // simulate open bus + + if ( addr != 0x2002 ) + debug_printf( "Read unmapped $%.4X\n", (unsigned) addr ); + +exit: + return result; +} + +void Nsf_Emu::cpu_write( nes_addr_t addr, int data ) +{ + { + nes_addr_t offset = addr ^ sram_addr; + if ( offset < sizeof sram ) + { + sram [offset] = data; + return; + } + } + { + int temp = addr & 0x7FF; + if ( !(addr & 0xE000) ) + { + cpu::low_mem [temp] = data; + return; + } + } + + if ( unsigned (addr - Nes_Apu::start_addr) <= Nes_Apu::end_addr - Nes_Apu::start_addr ) + { + GME_APU_HOOK( this, addr - Nes_Apu::start_addr, data ); + apu.write_register( cpu::time(), addr, data ); + return; + } + + unsigned bank = addr - bank_select_addr; + if ( bank < bank_count ) + { + blargg_long offset = rom.mask_addr( data * (blargg_long) bank_size ); + if ( offset >= rom.size() ) + set_warning( "Invalid bank" ); + cpu::map_code( (bank + 8) * bank_size, bank_size, rom.at_addr( offset ) ); + return; + } + + cpu_write_misc( addr, data ); +} + +#define CPU_READ( cpu, addr, time ) STATIC_CAST(Nsf_Emu&,*cpu).cpu_read( addr ) +#define CPU_WRITE( cpu, addr, data, time ) STATIC_CAST(Nsf_Emu&,*cpu).cpu_write( addr, data ) diff --git a/libs/gme/gme/sap_cpu_io.h b/libs/gme/gme/sap_cpu_io.h new file mode 100644 index 000000000..d009d0d9b --- /dev/null +++ b/libs/gme/gme/sap_cpu_io.h @@ -0,0 +1,26 @@ + +#include "Sap_Emu.h" + +#include "blargg_source.h" + +#define CPU_WRITE( cpu, addr, data, time ) STATIC_CAST(Sap_Emu&,*cpu).cpu_write( addr, data ) + +void Sap_Emu::cpu_write( sap_addr_t addr, int data ) +{ + mem.ram [addr] = data; + if ( (addr >> 8) == 0xD2 ) + cpu_write_( addr, data ); +} + +#ifdef NDEBUG + #define CPU_READ( cpu, addr, time ) READ_LOW( addr ) +#else + #define CPU_READ( cpu, addr, time ) STATIC_CAST(Sap_Emu&,*cpu).cpu_read( addr ) + + int Sap_Emu::cpu_read( sap_addr_t addr ) + { + if ( (addr & 0xF900) == 0xD000 ) + debug_printf( "Unmapped read $%04X\n", addr ); + return mem.ram [addr]; + } +#endif diff --git a/libs/gme/include/gme/gme.h b/libs/gme/include/gme/gme.h new file mode 100644 index 000000000..1f2a2d150 --- /dev/null +++ b/libs/gme/include/gme/gme.h @@ -0,0 +1,241 @@ +/* Game music emulator library C interface (also usable from C++) */ + +/* Game_Music_Emu 0.6.0 */ +#ifndef GME_H +#define GME_H + +#ifdef __cplusplus + extern "C" { +#endif + +#define GME_VERSION 0x000600 /* 1 byte major, 1 byte minor, 1 byte patch-level */ + +/* Error string returned by library functions, or NULL if no error (success) */ +typedef const char* gme_err_t; + +/* First parameter of most gme_ functions is a pointer to the Music_Emu */ +typedef struct Music_Emu Music_Emu; + + +/******** Basic operations ********/ + +/* Create emulator and load game music file/data into it. Sets *out to new emulator. */ +gme_err_t gme_open_file( const char path [], Music_Emu** out, int sample_rate ); + +/* Number of tracks available */ +int gme_track_count( Music_Emu const* ); + +/* Start a track, where 0 is the first track */ +gme_err_t gme_start_track( Music_Emu*, int index ); + +/* Generate 'count' 16-bit signed samples info 'out'. Output is in stereo. */ +gme_err_t gme_play( Music_Emu*, int count, short out [] ); + +/* Finish using emulator and free memory */ +void gme_delete( Music_Emu* ); + + +/******** Track position/length ********/ + +/* Set time to start fading track out. Once fade ends track_ended() returns true. +Fade time can be changed while track is playing. */ +void gme_set_fade( Music_Emu*, int start_msec ); + +/* True if a track has reached its end */ +int gme_track_ended( Music_Emu const* ); + +/* Number of milliseconds (1000 = one second) played since beginning of track */ +int gme_tell( Music_Emu const* ); + +/* Seek to new time in track. Seeking backwards or far forward can take a while. */ +gme_err_t gme_seek( Music_Emu*, int msec ); + + +/******** Informational ********/ + +/* If you only need track information from a music file, pass gme_info_only for +sample_rate to open/load. */ +enum { gme_info_only = -1 }; + +/* Most recent warning string, or NULL if none. Clears current warning after returning. +Warning is also cleared when loading a file and starting a track. */ +const char* gme_warning( Music_Emu* ); + +/* Load m3u playlist file (must be done after loading music) */ +gme_err_t gme_load_m3u( Music_Emu*, const char path [] ); + +/* Clear any loaded m3u playlist and any internal playlist that the music format +supports (NSFE for example). */ +void gme_clear_playlist( Music_Emu* ); + +/* Gets information for a particular track (length, name, author, etc.). +Must be freed after use. */ +typedef struct gme_info_t gme_info_t; +gme_err_t gme_track_info( Music_Emu const*, gme_info_t** out, int track ); + +/* Frees track information */ +void gme_free_info( gme_info_t* ); + +struct gme_info_t +{ + /* times in milliseconds; -1 if unknown */ + int length; /* total length, if file specifies it */ + int intro_length; /* length of song up to looping section */ + int loop_length; /* length of looping section */ + + /* Length if available, otherwise intro_length+loop_length*2 if available, + otherwise a default of 150000 (2.5 minutes). */ + int play_length; + + int i4,i5,i6,i7,i8,i9,i10,i11,i12,i13,i14,i15; /* reserved */ + + /* empty string ("") if not available */ + const char* system; + const char* game; + const char* song; + const char* author; + const char* copyright; + const char* comment; + const char* dumper; + + const char *s7,*s8,*s9,*s10,*s11,*s12,*s13,*s14,*s15; /* reserved */ +}; + + +/******** Advanced playback ********/ + +/* Adjust stereo echo depth, where 0.0 = off and 1.0 = maximum. Has no effect for +GYM, SPC, and Sega Genesis VGM music */ +void gme_set_stereo_depth( Music_Emu*, double depth ); + +/* Disable automatic end-of-track detection and skipping of silence at beginning +if ignore is true */ +void gme_ignore_silence( Music_Emu*, int ignore ); + +/* Adjust song tempo, where 1.0 = normal, 0.5 = half speed, 2.0 = double speed. +Track length as returned by track_info() assumes a tempo of 1.0. */ +void gme_set_tempo( Music_Emu*, double tempo ); + +/* Number of voices used by currently loaded file */ +int gme_voice_count( Music_Emu const* ); + +/* Name of voice i, from 0 to gme_voice_count() - 1 */ +const char* gme_voice_name( Music_Emu const*, int i ); + +/* Mute/unmute voice i, where voice 0 is first voice */ +void gme_mute_voice( Music_Emu*, int index, int mute ); + +/* Set muting state of all voices at once using a bit mask, where -1 mutes all +voices, 0 unmutes them all, 0x01 mutes just the first voice, etc. */ +void gme_mute_voices( Music_Emu*, int muting_mask ); + +/* Frequency equalizer parameters (see gme.txt) */ +/* Implementers: If modified, also adjust Music_Emu::make_equalizer as needed */ +typedef struct gme_equalizer_t +{ + double treble; /* -50.0 = muffled, 0 = flat, +5.0 = extra-crisp */ + double bass; /* 1 = full bass, 90 = average, 16000 = almost no bass */ + + double d2,d3,d4,d5,d6,d7,d8,d9; /* reserved */ +} gme_equalizer_t; + +/* Get current frequency equalizater parameters */ +void gme_equalizer( Music_Emu const*, gme_equalizer_t* out ); + +/* Change frequency equalizer parameters */ +void gme_set_equalizer( Music_Emu*, gme_equalizer_t const* eq ); + +/* Enables/disables most accurate sound emulation options */ +void gme_enable_accuracy( Music_Emu*, int enabled ); + + +/******** Game music types ********/ + +/* Music file type identifier. Can also hold NULL. */ +typedef const struct gme_type_t_* gme_type_t; + +/* Emulator type constants for each supported file type */ +extern const gme_type_t + gme_ay_type, + gme_gbs_type, + gme_gym_type, + gme_hes_type, + gme_kss_type, + gme_nsf_type, + gme_nsfe_type, + gme_sap_type, + gme_spc_type, + gme_vgm_type, + gme_vgz_type; + +/* Type of this emulator */ +gme_type_t gme_type( Music_Emu const* ); + +/* Pointer to array of all music types, with NULL entry at end. Allows a player linked +to this library to support new music types without having to be updated. */ +gme_type_t const* gme_type_list(); + +/* Name of game system for this music file type */ +const char* gme_type_system( gme_type_t ); + +/* True if this music file type supports multiple tracks */ +int gme_type_multitrack( gme_type_t ); + + +/******** Advanced file loading ********/ + +/* Error returned if file type is not supported */ +extern const char* const gme_wrong_file_type; + +/* Same as gme_open_file(), but uses file data already in memory. Makes copy of data. */ +gme_err_t gme_open_data( void const* data, long size, Music_Emu** out, int sample_rate ); + +/* Determine likely game music type based on first four bytes of file. Returns +string containing proper file suffix (i.e. "NSF", "SPC", etc.) or "" if +file header is not recognized. */ +const char* gme_identify_header( void const* header ); + +/* Get corresponding music type for file path or extension passed in. */ +gme_type_t gme_identify_extension( const char path_or_extension [] ); + +/* Determine file type based on file's extension or header (if extension isn't recognized). +Sets *type_out to type, or 0 if unrecognized or error. */ +gme_err_t gme_identify_file( const char path [], gme_type_t* type_out ); + +/* Create new emulator and set sample rate. Returns NULL if out of memory. If you only need +track information, pass gme_info_only for sample_rate. */ +Music_Emu* gme_new_emu( gme_type_t, int sample_rate ); + +/* Load music file into emulator */ +gme_err_t gme_load_file( Music_Emu*, const char path [] ); + +/* Load music file from memory into emulator. Makes a copy of data passed. */ +gme_err_t gme_load_data( Music_Emu*, void const* data, long size ); + +/* Load music file using custom data reader function that will be called to +read file data. Most emulators load the entire file in one read call. */ +typedef gme_err_t (*gme_reader_t)( void* your_data, void* out, int count ); +gme_err_t gme_load_custom( Music_Emu*, gme_reader_t, long file_size, void* your_data ); + +/* Load m3u playlist file from memory (must be done after loading music) */ +gme_err_t gme_load_m3u_data( Music_Emu*, void const* data, long size ); + + +/******** User data ********/ + +/* Set/get pointer to data you want to associate with this emulator. +You can use this for whatever you want. */ +void gme_set_user_data( Music_Emu*, void* new_user_data ); +void* gme_user_data( Music_Emu const* ); + +/* Register cleanup function to be called when deleting emulator, or NULL to +clear it. Passes user_data to cleanup function. */ +typedef void (*gme_user_cleanup_t)( void* user_data ); +void gme_set_user_cleanup( Music_Emu*, gme_user_cleanup_t func ); + + +#ifdef __cplusplus + } +#endif + +#endif diff --git a/libs/gme/license.txt b/libs/gme/license.txt new file mode 100644 index 000000000..5ab7695ab --- /dev/null +++ b/libs/gme/license.txt @@ -0,0 +1,504 @@ + 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. + + 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. + + 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. + + 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. + + 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. + + 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. + + 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. + + 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. + + 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 + + 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. + + + Copyright (C) + + 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. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! + + diff --git a/libs/gme/player/Audio_Scope.cpp b/libs/gme/player/Audio_Scope.cpp new file mode 100644 index 000000000..ac73cc722 --- /dev/null +++ b/libs/gme/player/Audio_Scope.cpp @@ -0,0 +1,198 @@ +// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/ + +#include "Audio_Scope.h" + +#include +#include + +/* Copyright (C) 2005-2006 by Shay Green. Permission is hereby granted, free of +charge, to any person obtaining a copy of this software module and associated +documentation files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, copy, modify, +merge, publish, distribute, sublicense, and/or sell copies of the Software, and +to permit persons to whom the Software is furnished to do so, subject to the +following conditions: The above copyright notice and this permission notice +shall be included in all copies or substantial portions of the Software. THE +SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + +int const step_bits = 8; +int const step_unit = 1 << step_bits; +int const erase_color = 1; +int const draw_color = 2; + +Audio_Scope::Audio_Scope() +{ + surface = 0; + buf = 0; +} + +Audio_Scope::~Audio_Scope() +{ + free( buf ); + + if ( surface ) + SDL_FreeSurface( surface ); +} + +const char* Audio_Scope::init( int width, int height ) +{ + assert( height <= 256 ); + assert( !buf ); // can only call init() once + + buf = (byte*) calloc( width * sizeof *buf, 1 ); + if ( !buf ) + return "Out of memory"; + + low_y = 0; + high_y = height; + buf_size = width; + + for ( sample_shift = 6; sample_shift < 14; ) + if ( ((0x7FFFL * 2) >> sample_shift++) < height ) + break; + + v_offset = height / 2 - (0x10000 >> sample_shift); + + screen = SDL_SetVideoMode( width, height, 0, 0 ); + if ( !screen ) + return "Couldn't set video mode"; + + surface = SDL_CreateRGBSurface( SDL_SWSURFACE, width, height, 8, 0, 0, 0, 0 ); + if ( !screen ) + return "Couldn't create surface"; + + static SDL_Color palette [2] = { {0, 0, 0}, {0, 255, 0} }; + SDL_SetColors( surface, palette, 1, 2 ); + + return 0; // success +} + +const char* Audio_Scope::draw( const short* in, long count, double step ) +{ + int low = low_y; + int high = high_y; + + if ( count >= buf_size ) + { + count = buf_size; + low_y = 0x7FFF; + high_y = 0; + } + + if ( SDL_LockSurface( surface ) < 0 ) + return "Couldn't lock surface"; + render( in, count, (long) (step * step_unit) ); + SDL_UnlockSurface( surface ); + + if ( low > low_y ) + low = low_y; + + if ( high < high_y ) + high = high_y; + + SDL_Rect r; + r.x = 0; + r.w = buf_size; + r.y = low + v_offset; + r.h = high - low + 1; + + if ( SDL_BlitSurface( surface, &r, screen, &r ) < 0 ) + return "Blit to screen failed"; + + if ( SDL_Flip( screen ) < 0 ) + return "Couldn't flip screen"; + + return 0; // success +} + +void Audio_Scope::render( short const* in, long count, long step ) +{ + byte* old_pos = buf; + long surface_pitch = surface->pitch; + byte* out = (byte*) surface->pixels + v_offset * surface_pitch; + int old_erase = *old_pos; + int old_draw = 0; + long in_pos = 0; + + int low_y = this->low_y; + int high_y = this->high_y; + int half_step = (step + step_unit / 2) >> (step_bits + 1); + + while ( count-- ) + { + // Line drawing/erasing starts at previous sample and ends one short of + // current sample, except when previous and current are the same. + + // Extra read on the last iteration of line loops will always be at the + // height of the next sample, and thus within the gworld bounds. + + // Erase old line + { + int delta = *old_pos - old_erase; + int offset = old_erase * surface_pitch; + old_erase += delta; + + int next_line = surface_pitch; + if ( delta < 0 ) + { + delta = -delta; + next_line = -surface_pitch; + } + + do + { + out [offset] = erase_color; + offset += next_line; + } + while ( delta-- > 1 ); + } + + // Draw new line and put in old_buf + { + + int in_whole = in_pos >> step_bits; + int sample = (0x7FFF * 2 - in [in_whole] - in [in_whole + half_step]) >> sample_shift; + if ( !in_pos ) + old_draw = sample; + in_pos += step; + + int delta = sample - old_draw; + int offset = old_draw * surface_pitch; + old_draw += delta; + + int next_line = surface_pitch; + if ( delta < 0 ) + { + delta = -delta; + next_line = -surface_pitch; + } + + *old_pos++ = sample; + + // min/max updating can be interleved anywhere + + if ( low_y > sample ) + low_y = sample; + + do + { + out [offset] = draw_color; + offset += next_line; + } + while ( delta-- > 1 ); + + if ( high_y < sample ) + high_y = sample; + } + + out++; + } + + this->low_y = low_y; + this->high_y = high_y; +} diff --git a/libs/gme/player/Audio_Scope.h b/libs/gme/player/Audio_Scope.h new file mode 100644 index 000000000..753346769 --- /dev/null +++ b/libs/gme/player/Audio_Scope.h @@ -0,0 +1,36 @@ +// Simple audio waveform scope in a window, using SDL multimedia library + +#ifndef AUDIO_SCOPE_H +#define AUDIO_SCOPE_H + +#include "SDL.h" + +class Audio_Scope { +public: + typedef const char* error_t; + + // Initialize scope window of specified size. Height must be 256 or less. + error_t init( int width, int height ); + + // Draw at most 'count' samples from 'in', skipping 'step' samples after + // each sample drawn. Step can be less than 1.0. + error_t draw( const short* in, long count, double step = 1.0 ); + + Audio_Scope(); + ~Audio_Scope(); + +private: + typedef unsigned char byte; + SDL_Surface* screen; + SDL_Surface* surface; + byte* buf; + int buf_size; + int sample_shift; + int low_y; + int high_y; + int v_offset; + + void render( short const* in, long count, long step ); +}; + +#endif diff --git a/libs/gme/player/CMakeLists.txt b/libs/gme/player/CMakeLists.txt new file mode 100644 index 000000000..c37e27719 --- /dev/null +++ b/libs/gme/player/CMakeLists.txt @@ -0,0 +1,22 @@ +find_package(SDL QUIET) + +set(player_SRCS Audio_Scope.cpp + Audio_Scope.h + Music_Player.cpp + Music_Player.h + player.cpp) + +if(SDL_FOUND) + message(" ** SDL library located, player demo is available to be built in the /player directory") + + include_directories(${SDL_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR} + "${CMAKE_HOME_DIRECTORY}" "${CMAKE_HOME_DIRECTORY}/gme" + "${CMAKE_BINARY_DIR}/gme") + + add_executable(gme_player ${player_SRCS}) + target_link_libraries(gme_player ${SDL_LIBRARY} gme) + + # Is not to be installed though +else() + message("SDL library not found, disabling player demo build") +endif() diff --git a/libs/gme/player/Music_Player.cpp b/libs/gme/player/Music_Player.cpp new file mode 100644 index 000000000..908f14f0f --- /dev/null +++ b/libs/gme/player/Music_Player.cpp @@ -0,0 +1,245 @@ +// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/ + +#include "Music_Player.h" + +#include +#include + +/* Copyright (C) 2005-2010 by Shay Green. Permission is hereby granted, free of +charge, to any person obtaining a copy of this software module and associated +documentation files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, copy, modify, +merge, publish, distribute, sublicense, and/or sell copies of the Software, and +to permit persons to whom the Software is furnished to do so, subject to the +following conditions: The above copyright notice and this permission notice +shall be included in all copies or substantial portions of the Software. THE +SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + +#define RETURN_ERR( expr ) \ + do {\ + gme_err_t err_ = (expr);\ + if ( err_ )\ + return err_;\ + } while ( 0 ) + +// Number of audio buffers per second. Adjust if you encounter audio skipping. +const int fill_rate = 45; + +// Simple sound driver using SDL +typedef void (*sound_callback_t)( void* data, short* out, int count ); +static const char* sound_init( long sample_rate, int buf_size, sound_callback_t, void* data ); +static void sound_start(); +static void sound_stop(); +static void sound_cleanup(); + +Music_Player::Music_Player() +{ + emu_ = 0; + scope_buf = 0; + paused = false; + track_info_ = NULL; +} + +gme_err_t Music_Player::init( long rate ) +{ + sample_rate = rate; + + int min_size = sample_rate * 2 / fill_rate; + int buf_size = 512; + while ( buf_size < min_size ) + buf_size *= 2; + + return sound_init( sample_rate, buf_size, fill_buffer, this ); +} + +void Music_Player::stop() +{ + sound_stop(); + gme_delete( emu_ ); + emu_ = NULL; +} + +Music_Player::~Music_Player() +{ + stop(); + sound_cleanup(); + gme_free_info( track_info_ ); +} + +gme_err_t Music_Player::load_file( const char* path ) +{ + stop(); + + RETURN_ERR( gme_open_file( path, &emu_, sample_rate ) ); + + char m3u_path [256 + 5]; + strncpy( m3u_path, path, 256 ); + m3u_path [256] = 0; + char* p = strrchr( m3u_path, '.' ); + if ( !p ) + p = m3u_path + strlen( m3u_path ); + strcpy( p, ".m3u" ); + if ( gme_load_m3u( emu_, m3u_path ) ) { } // ignore error + + return 0; +} + +int Music_Player::track_count() const +{ + return emu_ ? gme_track_count( emu_ ) : false; +} + +gme_err_t Music_Player::start_track( int track ) +{ + if ( emu_ ) + { + gme_free_info( track_info_ ); + track_info_ = NULL; + RETURN_ERR( gme_track_info( emu_, &track_info_, track ) ); + + // Sound must not be running when operating on emulator + sound_stop(); + RETURN_ERR( gme_start_track( emu_, track ) ); + + // Calculate track length + if ( track_info_->length <= 0 ) + track_info_->length = track_info_->intro_length + + track_info_->loop_length * 2; + + if ( track_info_->length <= 0 ) + track_info_->length = (long) (2.5 * 60 * 1000); + gme_set_fade( emu_, track_info_->length ); + + paused = false; + sound_start(); + } + return 0; +} + +void Music_Player::pause( int b ) +{ + paused = b; + if ( b ) + sound_stop(); + else + sound_start(); +} + +void Music_Player::suspend() +{ + if ( !paused ) + sound_stop(); +} + +void Music_Player::resume() +{ + if ( !paused ) + sound_start(); +} + +bool Music_Player::track_ended() const +{ + return emu_ ? gme_track_ended( emu_ ) : false; +} + +void Music_Player::set_stereo_depth( double tempo ) +{ + suspend(); + gme_set_stereo_depth( emu_, tempo ); + resume(); +} + +void Music_Player::enable_accuracy( bool b ) +{ + suspend(); + gme_enable_accuracy( emu_, b ); + resume(); +} + +void Music_Player::set_tempo( double tempo ) +{ + suspend(); + gme_set_tempo( emu_, tempo ); + resume(); +} + +void Music_Player::mute_voices( int mask ) +{ + suspend(); + gme_mute_voices( emu_, mask ); + gme_ignore_silence( emu_, mask != 0 ); + resume(); +} + +void Music_Player::fill_buffer( void* data, sample_t* out, int count ) +{ + Music_Player* self = (Music_Player*) data; + if ( self->emu_ ) + { + if ( gme_play( self->emu_, count, out ) ) { } // ignore error + + if ( self->scope_buf ) + memcpy( self->scope_buf, out, self->scope_buf_size * sizeof *self->scope_buf ); + } +} + +// Sound output driver using SDL + +#include "SDL.h" + +static sound_callback_t sound_callback; +static void* sound_callback_data; + +static void sdl_callback( void* data, Uint8* out, int count ) +{ + if ( sound_callback ) + sound_callback( sound_callback_data, (short*) out, count / 2 ); +} + +static const char* sound_init( long sample_rate, int buf_size, + sound_callback_t cb, void* data ) +{ + sound_callback = cb; + sound_callback_data = data; + + static SDL_AudioSpec as; // making static clears all fields to 0 + as.freq = sample_rate; + as.format = AUDIO_S16SYS; + as.channels = 2; + as.callback = sdl_callback; + as.samples = buf_size; + if ( SDL_OpenAudio( &as, 0 ) < 0 ) + { + const char* err = SDL_GetError(); + if ( !err ) + err = "Couldn't open SDL audio"; + return err; + } + + return 0; +} + +static void sound_start() +{ + SDL_PauseAudio( false ); +} + +static void sound_stop() +{ + SDL_PauseAudio( true ); + + // be sure audio thread is not active + SDL_LockAudio(); + SDL_UnlockAudio(); +} + +static void sound_cleanup() +{ + sound_stop(); + SDL_CloseAudio(); +} diff --git a/libs/gme/player/Music_Player.h b/libs/gme/player/Music_Player.h new file mode 100644 index 000000000..f9b7bda49 --- /dev/null +++ b/libs/gme/player/Music_Player.h @@ -0,0 +1,72 @@ +// Simple game music file player + +// Game_Music_Emu 0.6.0 +#ifndef MUSIC_PLAYER_H +#define MUSIC_PLAYER_H + +#include "gme.h" + +class Music_Player { +public: + // Initialize player and set sample rate + gme_err_t init( long sample_rate = 44100 ); + + // Load game music file. NULL on success, otherwise error string. + gme_err_t load_file( const char* path ); + + // (Re)start playing track. Tracks are numbered from 0 to track_count() - 1. + gme_err_t start_track( int track ); + + // Stop playing current file + void stop(); + +// Optional functions + + // Number of tracks in current file, or 0 if no file loaded. + int track_count() const; + + // Info for current track + gme_info_t const& track_info() const { return *track_info_; } + + // Pause/resume playing current track. + void pause( int ); + + // True if track ended + bool track_ended() const; + + // Pointer to emulator + Music_Emu* emu() const { return emu_; } + + // Set stereo depth, where 0.0 = none and 1.0 = maximum + void set_stereo_depth( double ); + + // Enable accurate sound emulation + void enable_accuracy( bool ); + + // Set tempo, where 0.5 = half speed, 1.0 = normal, 2.0 = double speed + void set_tempo( double ); + + // Set voice muting bitmask + void mute_voices( int ); + + // Set buffer to copy samples from each buffer into, or NULL to disable + typedef short sample_t; + void set_scope_buffer( sample_t* buf, int size ) { scope_buf = buf; scope_buf_size = size; } + +public: + Music_Player(); + ~Music_Player(); +private: + Music_Emu* emu_; + sample_t* scope_buf; + long sample_rate; + int scope_buf_size; + bool paused; + gme_info_t* track_info_; + + void suspend(); + void resume(); + static void fill_buffer( void*, sample_t*, int ); +}; + +#endif diff --git a/libs/gme/player/player.cpp b/libs/gme/player/player.cpp new file mode 100644 index 000000000..368062dc2 --- /dev/null +++ b/libs/gme/player/player.cpp @@ -0,0 +1,220 @@ +/* How to play game music files with Music_Player (requires SDL library) + +Run program with path to a game music file. + +Left/Right Change track +Space Pause/unpause +E Normal/slight stereo echo/more stereo echo +A Enable/disable accurate emulation +-/= Adjust tempo +1-9 Toggle channel on/off +0 Reset tempo and turn channels back on */ + +int const scope_width = 512; + +#include "Music_Player.h" +#include "Audio_Scope.h" + +#include +#include +#include +#include "SDL.h" + +void handle_error( const char* ); + +static bool paused; +static Audio_Scope* scope; +static Music_Player* player; +static short scope_buf [scope_width * 2]; + +static void init() +{ + // Start SDL + if ( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_AUDIO ) < 0 ) + exit( EXIT_FAILURE ); + atexit( SDL_Quit ); + SDL_EnableKeyRepeat( 500, 80 ); + + // Init scope + scope = new Audio_Scope; + if ( !scope ) + handle_error( "Out of memory" ); + if ( scope->init( scope_width, 256 ) ) + handle_error( "Couldn't initialize scope" ); + memset( scope_buf, 0, sizeof scope_buf ); + + // Create player + player = new Music_Player; + if ( !player ) + handle_error( "Out of memory" ); + handle_error( player->init() ); + player->set_scope_buffer( scope_buf, scope_width * 2 ); +} + +static void start_track( int track, const char* path ) +{ + paused = false; + handle_error( player->start_track( track - 1 ) ); + + // update window title with track info + + long seconds = player->track_info().length / 1000; + const char* game = player->track_info().game; + if ( !*game ) + { + // extract filename + game = strrchr( path, '\\' ); // DOS + if ( !game ) + game = strrchr( path, '/' ); // UNIX + if ( !game ) + game = path; + else + game++; // skip path separator + } + + char title [512]; + sprintf( title, "%s: %d/%d %s (%ld:%02ld)", + game, track, player->track_count(), player->track_info().song, + seconds / 60, seconds % 60 ); + SDL_WM_SetCaption( title, title ); +} + +int main( int argc, char** argv ) +{ + init(); + + // Load file + const char* path = (argc > 1 ? argv [argc - 1] : "test.nsf"); + handle_error( player->load_file( path ) ); + start_track( 1, path ); + + // Main loop + int track = 1; + double tempo = 1.0; + bool running = true; + double stereo_depth = 0.0; + bool accurate = false; + int muting_mask = 0; + while ( running ) + { + SDL_Delay( 1000 / 100 ); + + // Update scope + scope->draw( scope_buf, scope_width, 2 ); + + // Automatically go to next track when current one ends + if ( player->track_ended() ) + { + if ( track < player->track_count() ) + start_track( ++track, path ); + else + player->pause( paused = true ); + } + + // Handle keyboard input + SDL_Event e; + while ( SDL_PollEvent( &e ) ) + { + switch ( e.type ) + { + case SDL_QUIT: + running = false; + break; + + case SDL_KEYDOWN: + int key = e.key.keysym.sym; + switch ( key ) + { + case SDLK_q: + case SDLK_ESCAPE: // quit + running = false; + break; + + case SDLK_LEFT: // prev track + if ( !paused && !--track ) + track = 1; + start_track( track, path ); + break; + + case SDLK_RIGHT: // next track + if ( track < player->track_count() ) + start_track( ++track, path ); + break; + + case SDLK_MINUS: // reduce tempo + tempo -= 0.1; + if ( tempo < 0.1 ) + tempo = 0.1; + player->set_tempo( tempo ); + break; + + case SDLK_EQUALS: // increase tempo + tempo += 0.1; + if ( tempo > 2.0 ) + tempo = 2.0; + player->set_tempo( tempo ); + break; + + case SDLK_SPACE: // toggle pause + paused = !paused; + player->pause( paused ); + break; + + case SDLK_a: // toggle accurate emulation + accurate = !accurate; + player->enable_accuracy( accurate ); + break; + + case SDLK_e: // toggle echo + stereo_depth += 0.2; + if ( stereo_depth > 0.5 ) + stereo_depth = 0; + player->set_stereo_depth( stereo_depth ); + break; + + case SDLK_0: // reset tempo and muting + tempo = 1.0; + muting_mask = 0; + player->set_tempo( tempo ); + player->mute_voices( muting_mask ); + break; + + default: + if ( SDLK_1 <= key && key <= SDLK_9 ) // toggle muting + { + muting_mask ^= 1 << (key - SDLK_1); + player->mute_voices( muting_mask ); + } + } + } + } + } + + // Cleanup + delete player; + delete scope; + + return 0; +} + +void handle_error( const char* error ) +{ + if ( error ) + { + // put error in window title + char str [256]; + sprintf( str, "Error: %s", error ); + fprintf( stderr, "%s\n", str ); + SDL_WM_SetCaption( str, str ); + + // wait for keyboard or mouse activity + SDL_Event e; + do + { + while ( !SDL_PollEvent( &e ) ) { } + } + while ( e.type != SDL_QUIT && e.type != SDL_KEYDOWN && e.type != SDL_MOUSEBUTTONDOWN ); + + exit( EXIT_FAILURE ); + } +} diff --git a/libs/gme/readme.txt b/libs/gme/readme.txt new file mode 100644 index 000000000..82a501dbd --- /dev/null +++ b/libs/gme/readme.txt @@ -0,0 +1,216 @@ +Game_Music_Emu 0.6.0: Game Music Emulators +------------------------------------------ +Game_Music_Emu is a collection of video game music file emulators that +support the following formats and systems: + +AY ZX Spectrum/Amstrad CPC +GBS Nintendo Game Boy +GYM Sega Genesis/Mega Drive +HES NEC TurboGrafx-16/PC Engine +KSS MSX Home Computer/other Z80 systems (doesn't support FM sound) +NSF/NSFE Nintendo NES/Famicom (with VRC 6, Namco 106, and FME-7 sound) +SAP Atari systems using POKEY sound chip +SPC Super Nintendo/Super Famicom +VGM/VGZ Sega Master System/Mark III, Sega Genesis/Mega Drive,BBC Micro + +Features: +* C interface for use in C, C++, and other compatible languages +* High emphasis has been placed on making the library very easy to use +* One set of common functions work with all emulators the same way +* Several code examples, including music player using SDL +* Portable code for use on any system with modern or older C++ compilers +* Adjustable output sample rate using quality band-limited resampling +* Uniform access to text information fields and track timing information +* End-of-track fading and automatic look ahead silence detection +* Treble/bass and stereo echo for AY/GBS/HES/KSS/NSF/NSFE/SAP/VGM +* Tempo can be adjusted and individual voices can be muted while playing +* Can read music data from file, memory, or custom reader function/class +* Can access track information without having to load into full emulator +* M3U track listing support for multi-track formats +* Modular design allows elimination of unneeded emulators/features + +This library has been used in game music players for Windows, Linux on +several architectures, Mac OS, MorphOS, Xbox, PlayStation Portable, +GP2X, and Nintendo DS. + +Author : Shay Green +Website: http://www.slack.net/~ant/ +Forum : http://groups.google.com/group/blargg-sound-libs +License: GNU Lesser General Public License (LGPL) + + +Getting Started +--------------- +Build a program consisting of demo/basics.c, demo/Wave_Writer.cpp, and +all source files in gme/. If you have CMake 2.6 or later, execute + + run cmake + cd demo + run make + +Be sure "test.nsf" is in the same directory as the program. Running it +should generate the recording "out.wav". + +A slightly more extensive demo application is available in the player/ +directory. It requires SDL to build. + +Read gme.txt for more information. Post to the discussion forum for +assistance. + + +Files +----- +gme.txt General notes about the library +changes.txt Changes made since previous releases +design.txt Library design notes +license.txt GNU Lesser General Public License +CMakeLists.txt CMake build rules + +test.nsf Test file for NSF emulator +test.m3u Test m3u playlist for features.c demo + +demo/ + basics.c Records NSF file to wave sound file + features.c Demonstrates many additional features + Wave_Writer.h WAVE sound file writer used for demo output + Wave_Writer.cpp + CMakeLists.txt CMake build rules + +player/ Player using the SDL multimedia library + player.cpp Simple music player with waveform display + Music_Player.cpp Stand alone player for background music + Music_Player.h + Audio_Scope.cpp Audio waveform scope + Audio_Scope.h + CMakeLists.txt CMake build rules + +gme/ + blargg_config.h Library configuration (modify this file as needed) + + gme.h Library interface header file + gme.cpp + + Ay_Emu.h ZX Spectrum AY emulator + Ay_Emu.cpp + Ay_Apu.cpp + Ay_Apu.h + Ay_Cpu.cpp + Ay_Cpu.h + + Gbs_Emu.h Nintendo Game Boy GBS emulator + Gbs_Emu.cpp + Gb_Apu.cpp + Gb_Apu.h + Gb_Cpu.cpp + Gb_Cpu.h + gb_cpu_io.h + Gb_Oscs.cpp + Gb_Oscs.h + + Hes_Emu.h TurboGrafx-16/PC Engine HES emulator + Hes_Apu.cpp + Hes_Apu.h + Hes_Cpu.cpp + Hes_Cpu.h + hes_cpu_io.h + Hes_Emu.cpp + + Kss_Emu.h MSX Home Computer/other Z80 systems KSS emulator + Kss_Emu.cpp + Kss_Cpu.cpp + Kss_Cpu.h + Kss_Scc_Apu.cpp + Kss_Scc_Apu.h + Ay_Apu.h + Ay_Apu.cpp + Sms_Apu.h + Sms_Apu.cpp + Sms_Oscs.h + + Nsf_Emu.h Nintendo NES NSF/NSFE emulator + Nsf_Emu.cpp + Nes_Apu.cpp + Nes_Apu.h + Nes_Cpu.cpp + Nes_Cpu.h + nes_cpu_io.h + Nes_Oscs.cpp + Nes_Oscs.h + Nes_Fme7_Apu.cpp + Nes_Fme7_Apu.h + Nes_Namco_Apu.cpp + Nes_Namco_Apu.h + Nes_Vrc6_Apu.cpp + Nes_Vrc6_Apu.h + Nsfe_Emu.h NSFE support + Nsfe_Emu.cpp + + Spc_Emu.h Super Nintendo SPC emulator + Spc_Emu.cpp + Snes_Spc.cpp + Snes_Spc.h + Spc_Cpu.cpp + Spc_Cpu.h + Spc_Dsp.cpp + Spc_Dsp.h + Fir_Resampler.cpp + Fir_Resampler.h + + Sap_Emu.h Atari SAP emulator + Sap_Emu.cpp + Sap_Apu.cpp + Sap_Apu.h + Sap_Cpu.cpp + Sap_Cpu.h + sap_cpu_io.h + + Vgm_Emu.h Sega VGM emulator + Vgm_Emu_Impl.cpp + Vgm_Emu_Impl.h + Vgm_Emu.cpp + Ym2413_Emu.cpp + Ym2413_Emu.h + Gym_Emu.h Sega Genesis GYM emulator + Gym_Emu.cpp + Sms_Apu.cpp Common Sega emulator files + Sms_Apu.h + Sms_Oscs.h + Ym2612_Emu.cpp + Ym2612_Emu.h + Dual_Resampler.cpp + Dual_Resampler.h + Fir_Resampler.cpp + Fir_Resampler.h + + M3u_Playlist.h M3U playlist support + M3u_Playlist.cpp + + Effects_Buffer.h Sound buffer with stereo echo and panning + Effects_Buffer.cpp + + blargg_common.h Common files needed by all emulators + blargg_endian.h + blargg_source.h + Blip_Buffer.cpp + Blip_Buffer.h + Gme_File.h + Gme_File.cpp + Music_Emu.h + Music_Emu.cpp + Classic_Emu.h + Classic_Emu.cpp + Multi_Buffer.h + Multi_Buffer.cpp + Data_Reader.h + Data_Reader.cpp + + CMakeLists.txt CMake build rules + + +Legal +----- +Game_Music_Emu library copyright (C) 2003-2009 Shay Green. +Sega Genesis YM2612 emulator copyright (C) 2002 Stephane Dallongeville. + +-- +Shay Green diff --git a/libs/gme/test.m3u b/libs/gme/test.m3u new file mode 100644 index 000000000..c4e91f517 --- /dev/null +++ b/libs/gme/test.m3u @@ -0,0 +1,2 @@ +# filename,track number,track name,track time +test.nsf,$00,BGM C,1:16 diff --git a/libs/gme/test.nsf b/libs/gme/test.nsf new file mode 100644 index 000000000..da5fcedd2 Binary files /dev/null and b/libs/gme/test.nsf differ diff --git a/libs/gme/win32/libgme.dll.a b/libs/gme/win32/libgme.dll.a new file mode 100644 index 000000000..d56d87396 Binary files /dev/null and b/libs/gme/win32/libgme.dll.a differ diff --git a/libs/libpng-src/ANNOUNCE b/libs/libpng-src/ANNOUNCE new file mode 100644 index 000000000..02a24bd6b --- /dev/null +++ b/libs/libpng-src/ANNOUNCE @@ -0,0 +1,65 @@ + +Libpng 1.2.46 - July 9, 2011 + +This is a public release of libpng, intended for use in production codes. + +Files available for download: + +Source files with LF line endings (for Unix/Linux) and with a +"configure" script + + libpng-1.2.46.tar.xz (LZMA-compressed, recommended) + libpng-1.2.46.tar.gz + libpng-1.2.46.tar.bz2 + +Source files with LF line endings (for Unix/Linux) without the +"configure" script + + libpng-1.2.46-no-config.tar.xz (LZMA-compressed, recommended) + libpng-1.2.46-no-config.tar.gz + libpng-1.2.46-no-config.tar.bz2 + +Source files with CRLF line endings (for Windows), without the +"configure" script + + lpng1246.zip + lpng1246.7z + lpng1246.tar.bz2 + +Project files + + libpng-1.2.46-project-netware.zip + libpng-1.2.46-project-wince.zip + +Other information: + + libpng-1.2.46-README.txt + libpng-1.2.46-KNOWNBUGS.txt + libpng-1.2.46-LICENSE.txt + libpng-1.2.46-Y2K-compliance.txt + libpng-1.2.46-[previous version]-diff.txt + +Changes since the last public release (1.2.43): + +version 1.2.45 [July 9, 2011] + + Fixed uninitialized memory read in png_format_buffer() (Bug + report by Frank Busse, related to CVE-2004-0421). + Pass "" instead of '\0' to png_default_error() in png_err(). This mistake + was introduced in libpng-1.2.20beta01. + Check for up->location !PNG_AFTER_IDAT when writing unknown chunks + before IDAT. + Ported bugfix in pngrtran.c from 1.5.3: when expanding a paletted image, + always expand to RGBA if transparency is present. + Check for integer overflow in png_set_rgb_to_gray(). + Check for sCAL chunk too short. + Added CMakeLists.txt, projects/xcode, and pnggccrd.c to EXTRA_DIST in + Makefile.am and Makefile.in + Udated copyright year to 2011. + +Send comments/corrections/commendations to png-mng-implement at lists.sf.net +(subscription required; visit +https://lists.sourceforge.net/lists/listinfo/png-mng-implement +to subscribe) or to glennrp at users.sourceforge.net + +Glenn R-P diff --git a/libs/libpng-src/CHANGES b/libs/libpng-src/CHANGES new file mode 100644 index 000000000..1b7a30ee4 --- /dev/null +++ b/libs/libpng-src/CHANGES @@ -0,0 +1,2746 @@ +/* +CHANGES - changes for libpng + +version 0.2 + added reader into png.h + fixed small problems in stub file + +version 0.3 + added pull reader + split up pngwrite.c to several files + added pnglib.txt + added example.c + cleaned up writer, adding a few new transformations + fixed some bugs in writer + interfaced with zlib 0.5 + added K&R support + added check for 64 KB blocks for 16 bit machines + +version 0.4 + cleaned up code and commented code + simplified time handling into png_time + created png_color_16 and png_color_8 to handle color needs + cleaned up color type defines + fixed various bugs + made various names more consistent + interfaced with zlib 0.71 + cleaned up zTXt reader and writer (using zlib's Reset functions) + split transformations into pngrtran.c and pngwtran.c + +version 0.5 + interfaced with zlib 0.8 + fixed many reading and writing bugs + saved using 3 spaces instead of tabs + +version 0.6 + added png_large_malloc() and png_large_free() + added png_size_t + cleaned up some compiler warnings + added png_start_read_image() + +version 0.7 + cleaned up lots of bugs + finished dithering and other stuff + added test program + changed name from pnglib to libpng + +version 0.71 [June, 1995] + changed pngtest.png for zlib 0.93 + fixed error in libpng.txt and example.c + +version 0.8 + cleaned up some bugs + added png_set_filler() + split up pngstub.c into pngmem.c, pngio.c, and pngerror.c + added #define's to remove unwanted code + moved png_info_init() to png.c + added old_size into png_realloc() + added functions to manually set filtering and compression info + changed compression parameters based on image type + optimized filter selection code + added version info + changed external functions passing floats to doubles (k&r problems?) + put all the configurable stuff in pngconf.h + enabled png_set_shift to work with paletted images on read + added png_read_update_info() - updates info structure with + transformations + +version 0.81 [August, 1995] + incorporated Tim Wegner's medium model code (thanks, Tim) + +version 0.82 [September, 1995] + [unspecified changes] + +version 0.85 [December, 1995] + added more medium model code (almost everything's a far) + added i/o, error, and memory callback functions + fixed some bugs (16 bit, 4 bit interlaced, etc.) + added first run progressive reader (barely tested) + +version 0.86 [January, 1996] + fixed bugs + improved documentation + +version 0.87 [January, 1996] + fixed medium model bugs + fixed other bugs introduced in 0.85 and 0.86 + added some minor documentation + +version 0.88 [January, 1996] + fixed progressive bugs + replaced tabs with spaces + cleaned up documentation + added callbacks for read/write and warning/error functions + +version 0.89 [July, 1996] + added new initialization API to make libpng work better with shared libs + we now have png_create_read_struct(), png_create_write_struct(), + png_create_info_struct(), png_destroy_read_struct(), and + png_destroy_write_struct() instead of the separate calls to + malloc and png_read_init(), png_info_init(), and png_write_init() + changed warning/error callback functions to fix bug - this means you + should use the new initialization API if you were using the old + png_set_message_fn() calls, and that the old API no longer exists + so that people are aware that they need to change their code + changed filter selection API to allow selection of multiple filters + since it didn't work in previous versions of libpng anyways + optimized filter selection code + fixed png_set_background() to allow using an arbitrary RGB color for + paletted images + fixed gamma and background correction for paletted images, so + png_correct_palette is not needed unless you are correcting an + external palette (you will need to #define PNG_CORRECT_PALETTE_SUPPORTED + in pngconf.h) - if nobody uses this, it may disappear in the future. + fixed bug with Borland 64K memory allocation (Alexander Lehmann) + fixed bug in interlace handling (Smarasderagd, I think) + added more error checking for writing and image to reduce invalid files + separated read and write functions so that they won't both be linked + into a binary when only reading or writing functionality is used + new pngtest image also has interlacing and zTXt + updated documentation to reflect new API + +version 0.90 [January, 1997] + made CRC errors/warnings on critical and ancillary chunks configurable + libpng will use the zlib CRC routines by (compile-time) default + changed DOS small/medium model memory support - needs zlib 1.04 (Tim Wegner) + added external C++ wrapper statements to png.h (Gilles Dauphin) + allow PNG file to be read when some or all of file signature has already + been read from the beginning of the stream. ****This affects the size + of info_struct and invalidates all programs that use a shared libpng**** + fixed png_filler() declarations + fixed? background color conversions + fixed order of error function pointers to match documentation + current chunk name is now available in png_struct to reduce the number + of nearly identical error messages (will simplify multi-lingual + support when available) + try to get ready for unknown-chunk callback functions: + - previously read critical chunks are flagged, so the chunk handling + routines can determine if the chunk is in the right place + - all chunk handling routines have the same prototypes, so we will + be able to handle all chunks via a callback mechanism + try to fix Linux "setjmp" buffer size problems + removed png_large_malloc, png_large_free, and png_realloc functions. + +version 0.95 [March, 1997] + fixed bug in pngwutil.c allocating "up_row" twice and "avg_row" never + fixed bug in PNG file signature compares when start != 0 + changed parameter type of png_set_filler(...filler...) from png_byte + to png_uint_32 + added test for MACOS to ensure that both math.h and fp.h are not #included + added macros for libpng to be compiled as a Windows DLL (Andreas Kupries) + added "packswap" transformation, which changes the endianness of + packed-pixel bytes (Kevin Bracey) + added "strip_alpha" transformation, which removes the alpha channel of + input images without using it (not necessarily a good idea) + added "swap_alpha" transformation, which puts the alpha channel in front + of the color bytes instead of after + removed all implicit variable tests which assume NULL == 0 (I think) + changed several variables to "png_size_t" to show 16/32-bit limitations + added new pCAL chunk read/write support + added experimental filter selection weighting (Greg Roelofs) + removed old png_set_rgbx() and png_set_xrgb() functions that have been + obsolete for about 2 years now (use png_set_filler() instead) + added macros to read 16- and 32-bit ints directly from buffer, to be + used only on those systems that support it (namely PowerPC and 680x0) + With some testing, this may become the default for MACOS/PPC systems. + only calculate CRC on data if we are going to use it + added macros for zTXt compression type PNG_zTXt_COMPRESSION_??? + added macros for simple libpng debugging output selectable at compile time + removed PNG_READ_END_MODE in progressive reader (Smarasderagd) + more description of info_struct in libpng.txt and png.h + more instructions in example.c + more chunk types tested in pngtest.c + renamed pngrcb.c to pngset.c, and all png_read_ functions to be + png_set_. We now have corresponding png_get_ + functions in pngget.c to get information in info_ptr. This isolates + the application from the internal organization of png_info_struct + (good for shared library implementations). + +version 0.96 [May, 1997] + fixed serious bug with < 8bpp images introduced in 0.95 + fixed 256-color transparency bug (Greg Roelofs) + fixed up documentation (Greg Roelofs, Laszlo Nyul) + fixed "error" in pngconf.h for Linux setjmp() behaviour + fixed DOS medium model support (Tim Wegner) + fixed png_check_keyword() for case with error in static string text + added read of CRC after IEND chunk for embedded PNGs (Laszlo Nyul) + added typecasts to quiet compiler errors + added more debugging info + +version 0.97 [January, 1998] + removed PNG_USE_OWN_CRC capability + relocated png_set_crc_action from pngrutil.c to pngrtran.c + fixed typecasts of "new_key", etc. (Andreas Dilger) + added RFC 1152 [sic] date support + fixed bug in gamma handling of 4-bit grayscale + added 2-bit grayscale gamma handling (Glenn R-P) + added more typecasts. 65536L becomes (png_uint_32)65536L, etc. (Glenn R-P) + minor corrections in libpng.txt + added simple sRGB support (Glenn R-P) + easier conditional compiling, e.g. define PNG_READ/WRITE_NOT_FULLY_SUPPORTED; + all configurable options can be selected from command-line instead + of having to edit pngconf.h (Glenn R-P) + fixed memory leak in pngwrite.c (free info_ptr->text) (Glenn R-P) + added more conditions for png_do_background, to avoid changing + black pixels to background when a background is supplied and + no pixels are transparent + repaired PNG_NO_STDIO behaviour + tested NODIV support and made it default behaviour (Greg Roelofs) + added "-m" option and PNGTEST_DEBUG_MEMORY to pngtest (John Bowler) + regularized version numbering scheme and bumped shared-library major + version number to 2 to avoid problems with libpng 0.89 apps (Greg Roelofs) + +version 0.98 [January, 1998] + cleaned up some typos in libpng.txt and in code documentation + fixed memory leaks in pCAL chunk processing (Glenn R-P and John Bowler) + cosmetic change "display_gamma" to "screen_gamma" in pngrtran.c + changed recommendation about file_gamma for PC images to .51 from .45, + in example.c and libpng.txt, added comments to distinguish between + screen_gamma, viewing_gamma, and display_gamma. + changed all references to RFC1152 to read RFC1123 and changed the + PNG_TIME_RFC1152_SUPPORTED macro to PNG_TIME_RFC1123_SUPPORTED + added png_invert_alpha capability (Glenn R-P -- suggestion by Jon Vincent) + changed srgb_intent from png_byte to int to avoid compiler bugs + +version 0.99 [January 30, 1998] + free info_ptr->text instead of end_info_ptr->text in pngread.c (John Bowler) + fixed a longstanding "packswap" bug in pngtrans.c + fixed some inconsistencies in pngconf.h that prevented compiling with + PNG_READ_GAMMA_SUPPORTED and PNG_READ_hIST_SUPPORTED undefined + fixed some typos and made other minor rearrangement of libpng.txt (Andreas) + changed recommendation about file_gamma for PC images to .50 from .51 in + example.c and libpng.txt, and changed file_gamma for sRGB images to .45 + added a number of functions to access information from the png structure + png_get_image_height(), etc. (Glenn R-P, suggestion by Brad Pettit) + added TARGET_MACOS similar to zlib-1.0.8 + define PNG_ALWAYS_EXTERN when __MWERKS__ && WIN32 are defined + added type casting to all png_malloc() function calls +version 0.99a [January 31, 1998] + Added type casts and parentheses to all returns that return a value.(Tim W.) +version 0.99b [February 4, 1998] + Added type cast png_uint_32 on malloc function calls where needed. + Changed type of num_hist from png_uint_32 to int (same as num_palette). + Added checks for rowbytes overflow, in case png_size_t is less than 32 bits. + Renamed makefile.elf to makefile.lnx. +version 0.99c [February 7, 1998] + More type casting. Removed erroneous overflow test in pngmem.c. + Added png_buffered_memcpy() and png_buffered_memset(), apply them to rowbytes. + Added UNIX manual pages libpng.3 (incorporating libpng.txt) and png.5. +version 0.99d [February 11, 1998] + Renamed "far_to_near()" "png_far_to_near()" + Revised libpng.3 + Version 99c "buffered" operations didn't work as intended. Replaced them + with png_memcpy_check() and png_memset_check(). + Added many "if (png_ptr == NULL) return" to quell compiler warnings about + unused png_ptr, mostly in pngget.c and pngset.c. + Check for overlength tRNS chunk present when indexed-color PLTE is read. + Cleaned up spelling errors in libpng.3/libpng.txt + Corrected a problem with png_get_tRNS() which returned undefined trans array +version 0.99e [February 28, 1998] + Corrected png_get_tRNS() again. + Add parentheses for easier reading of pngget.c, fixed "||" should be "&&". + Touched up example.c to make more of it compileable, although the entire + file still can't be compiled (Willem van Schaik) + Fixed a bug in png_do_shift() (Bryan Tsai) + Added a space in png.h prototype for png_write_chunk_start() + Replaced pngtest.png with one created with zlib 1.1.1 + Changed pngtest to report PASS even when file size is different (Jean-loup G.) + Corrected some logic errors in png_do_invert_alpha() (Chris Patterson) +version 0.99f [March 5, 1998] + Corrected a bug in pngpread() introduced in version 99c (Kevin Bracey) + Moved makefiles into a "scripts" directory, and added INSTALL instruction file + Added makefile.os2 and pngos2.def (A. Zabolotny) and makefile.s2x (W. Sebok) + Added pointers to "note on libpng versions" in makefile.lnx and README + Added row callback feature when reading and writing nonprogressive rows + and added a test of this feature in pngtest.c + Added user transform callbacks, with test of the feature in pngtest.c +version 0.99g [March 6, 1998, morning] + Minor changes to pngtest.c to suppress compiler warnings. + Removed "beta" language from documentation. +version 0.99h [March 6, 1998, evening] + Minor changes to previous minor changes to pngtest.c + Changed PNG_READ_NOT_FULLY_SUPPORTED to PNG_READ_TRANSFORMS_NOT_SUPPORTED + and added PNG_PROGRESSIVE_READ_NOT_SUPPORTED macro + Added user transform capability + +version 1.00 [March 7, 1998] + Changed several typedefs in pngrutil.c + Added makefile.wat (Pawel Mrochen), updated makefile.tc3 (Willem van Schaik) + replaced "while(1)" with "for(;;)" + added PNGARG() to prototypes in pngtest.c and removed some prototypes + updated some of the makefiles (Tom Lane) + changed some typedefs (s_start, etc.) in pngrutil.c + fixed dimensions of "short_months" array in pngwrite.c + Replaced ansi2knr.c with the one from jpeg-v6 + +version 1.0.0 [March 8, 1998] + Changed name from 1.00 to 1.0.0 (Adam Costello) + Added smakefile.ppc (with SCOPTIONS.ppc) for Amiga PPC (Andreas Kleinert) +version 1.0.0a [March 9, 1998] + Fixed three bugs in pngrtran.c to make gamma+background handling consistent + (Greg Roelofs) + Changed format of the PNG_LIBPNG_VER integer to xyyzz instead of xyz + for major, minor, and bugfix releases. This is 10001. (Adam Costello, + Tom Lane) + Make months range from 1-12 in png_convert_to_rfc1123 +version 1.0.0b [March 13, 1998] + Quieted compiler complaints about two empty "for" loops in pngrutil.c + Minor changes to makefile.s2x + Removed #ifdef/#endif around a png_free() in pngread.c + +version 1.0.1 [March 14, 1998] + Changed makefile.s2x to reduce security risk of using a relative pathname + Fixed some typos in the documentation (Greg). + Fixed a problem with value of "channels" returned by png_read_update_info() +version 1.0.1a [April 21, 1998] + Optimized Paeth calculations by replacing abs() function calls with intrinsics + plus other loop optimizations. Improves avg decoding speed by about 20%. + Commented out i386istic "align" compiler flags in makefile.lnx. + Reduced the default warning level in some makefiles, to make them consistent. + Removed references to IJG and JPEG in the ansi2knr.c copyright statement. + Fixed a bug in png_do_strip_filler with XXRRGGBB => RRGGBB transformation. + Added grayscale and 16-bit capability to png_do_read_filler(). + Fixed a bug in pngset.c, introduced in version 0.99c, that sets rowbytes + too large when writing an image with bit_depth < 8 (Bob Dellaca). + Corrected some bugs in the experimental weighted filtering heuristics. + Moved a misplaced pngrutil code block that truncates tRNS if it has more + than num_palette entries -- test was done before num_palette was defined. + Fixed a png_convert_to_rfc1123() bug that converts day 31 to 0 (Steve Eddins). + Changed compiler flags in makefile.wat for better optimization (Pawel Mrochen). +version 1.0.1b [May 2, 1998] + Relocated png_do_gray_to_rgb() within png_do_read_transformations() (Greg). + Relocated the png_composite macros from pngrtran.c to png.h (Greg). + Added makefile.sco (contributed by Mike Hopkirk). + Fixed two bugs (missing definitions of "istop") introduced in libpng-1.0.1a. + Fixed a bug in pngrtran.c that would set channels=5 under some circumstances. + More work on the Paeth-filtering, achieving imperceptible speedup (A Kleinert). + More work on loop optimization which may help when compiled with C++ compilers. + Added warnings when people try to use transforms they've defined out. + Collapsed 4 "i" and "c" loops into single "i" loops in pngrtran and pngwtran. + Revised paragraph about png_set_expand() in libpng.txt and libpng.3 (Greg) +version 1.0.1c [May 11, 1998] + Fixed a bug in pngrtran.c (introduced in libpng-1.0.1a) where the masks for + filler bytes should have been 0xff instead of 0xf. + Added max_pixel_depth=32 in pngrutil.c when using FILLER with palette images. + Moved PNG_WRITE_WEIGHTED_FILTER_SUPPORTED and PNG_WRITE_FLUSH_SUPPORTED + out of the PNG_WRITE_TRANSFORMS_NOT_SUPPORTED block of pngconf.h + Added "PNG_NO_WRITE_TRANSFORMS" etc., as alternatives for *_NOT_SUPPORTED, + for consistency, in pngconf.h + Added individual "ifndef PNG_NO_[CAPABILITY]" in pngconf.h to make it easier + to remove unwanted capabilities via the compile line + Made some corrections to grammar (which, it's) in documentation (Greg). + Corrected example.c, use of row_pointers in png_write_image(). +version 1.0.1d [May 24, 1998] + Corrected several statements that used side effects illegally in pngrutil.c + and pngtrans.c, that were introduced in version 1.0.1b + Revised png_read_rows() to avoid repeated if-testing for NULL (A Kleinert) + More corrections to example.c, use of row_pointers in png_write_image() + and png_read_rows(). + Added pngdll.mak and pngdef.pas to scripts directory, contributed by + Bob Dellaca, to make a png32bd.dll with Borland C++ 4.5 + Fixed error in example.c with png_set_text: num_text is 3, not 2 (Guido V.) + Changed several loops from count-down to count-up, for consistency. +version 1.0.1e [June 6, 1998] + Revised libpng.txt and libpng.3 description of png_set_read|write_fn(), and + added warnings when people try to set png_read_fn and png_write_fn in + the same structure. + Added a test such that png_do_gamma will be done when num_trans==0 + for truecolor images that have defined a background. This corrects an + error that was introduced in libpng-0.90 that can cause gamma processing + to be skipped. + Added tests in png.h to include "trans" and "trans_values" in structures + when PNG_READ_BACKGROUND_SUPPORTED or PNG_READ_EXPAND_SUPPORTED is defined. + Add png_free(png_ptr->time_buffer) in png_destroy_read_struct() + Moved png_convert_to_rfc_1123() from pngwrite.c to png.c + Added capability for user-provided malloc_fn() and free_fn() functions, + and revised pngtest.c to demonstrate their use, replacing the + PNGTEST_DEBUG_MEM feature. + Added makefile.w32, for Microsoft C++ 4.0 and later (Tim Wegner). + +version 1.0.2 [June 14, 1998] + Fixed two bugs in makefile.bor . +version 1.0.2a [December 30, 1998] + Replaced and extended code that was removed from png_set_filler() in 1.0.1a. + Fixed a bug in png_do_filler() that made it fail to write filler bytes in + the left-most pixel of each row (Kevin Bracey). + Changed "static pngcharp tIME_string" to "static char tIME_string[30]" + in pngtest.c (Duncan Simpson). + Fixed a bug in pngtest.c that caused pngtest to try to write a tIME chunk + even when no tIME chunk was present in the source file. + Fixed a problem in pngrutil.c: gray_to_rgb didn't always work with 16-bit. + Fixed a problem in png_read_push_finish_row(), which would not skip some + passes that it should skip, for images that are less than 3 pixels high. + Interchanged the order of calls to png_do_swap() and png_do_shift() + in pngwtran.c (John Cromer). + Added #ifdef PNG_DEBUG/#endif surrounding use of PNG_DEBUG in png.h . + Changed "bad adaptive filter type" from error to warning in pngrutil.c . + Fixed a documentation error about default filtering with 8-bit indexed-color. + Separated the PNG_NO_STDIO macro into PNG_NO_STDIO and PNG_NO_CONSOLE_IO + (L. Peter Deutsch). + Added png_set_rgb_to_gray() and png_get_rgb_to_gray_status() functions. + Added png_get_copyright() and png_get_header_version() functions. + Revised comments on png_set_progressive_read_fn() in libpng.txt and example.c + Added information about debugging in libpng.txt and libpng.3 . + Changed "ln -sf" to "ln -s -f" in makefile.s2x, makefile.lnx, and makefile.sco. + Removed lines after Dynamic Dependencies" in makefile.aco . + Revised makefile.dec to make a shared library (Jeremie Petit). + Removed trailing blanks from all files. +version 1.0.2a [January 6, 1999] + Removed misplaced #endif and #ifdef PNG_NO_EXTERN near the end of png.h + Added "if" tests to silence complaints about unused png_ptr in png.h and png.c + Changed "check_if_png" function in example.c to return true (nonzero) if PNG. + Changed libpng.txt to demonstrate png_sig_cmp() instead of png_check_sig() + which is obsolete. + +version 1.0.3 [January 14, 1999] + Added makefile.hux, for Hewlett Packard HPUX 10.20 and 11.00 (Jim Rice) + Added a statement of Y2K compliance in png.h, libpng.3, and Y2KINFO. +version 1.0.3a [August 12, 1999] + Added check for PNG_READ_INTERLACE_SUPPORTED in pngread.c; issue a warning + if an attempt is made to read an interlaced image when it's not supported. + Added check if png_ptr->trans is defined before freeing it in pngread.c + Modified the Y2K statement to include versions back to version 0.71 + Fixed a bug in the check for valid IHDR bit_depth/color_types in pngrutil.c + Modified makefile.wat (added -zp8 flag, ".symbolic", changed some comments) + Replaced leading blanks with tab characters in makefile.hux + Changed "dworkin.wustl.edu" to "ccrc.wustl.edu" in various documents. + Changed (float)red and (float)green to (double)red, (double)green + in png_set_rgb_to_gray() to avoid "promotion" problems in AIX. + Fixed a bug in pngconf.h that omitted when PNG_DEBUG==0 (K Bracey). + Reformatted libpng.3 and libpngpf.3 with proper fonts (script by J. vanZandt). + Updated documentation to refer to the PNG-1.2 specification. + Removed ansi2knr.c and left pointers to the latest source for ansi2knr.c + in makefile.knr, INSTALL, and README (L. Peter Deutsch) + Fixed bugs in calculation of the length of rowbytes when adding alpha + channels to 16-bit images, in pngrtran.c (Chris Nokleberg) + Added function png_set_user_transform_info() to store user_transform_ptr, + user_depth, and user_channels into the png_struct, and a function + png_get_user_transform_ptr() to retrieve the pointer (Chris Nokleberg) + Added function png_set_empty_plte_permitted() to make libpng useable + in MNG applications. + Corrected the typedef for png_free_ptr in png.h (Jesse Jones). + Correct gamma with srgb is 45455 instead of 45000 in pngrutil.c, to be + consistent with PNG-1.2, and allow variance of 500 before complaining. + Added assembler code contributed by Intel in file pngvcrd.c and modified + makefile.w32 to use it (Nirav Chhatrapati, INTEL Corporation, Gilles Vollant) + Changed "ln -s -f" to "ln -f -s" in the makefiles to make Solaris happy. + Added some aliases for png_set_expand() in pngrtran.c, namely + png_set_expand_PLTE(), png_set_expand_depth(), and png_set_expand_tRNS() + (Greg Roelofs, in "PNG: The Definitive Guide"). + Added makefile.beo for BEOS on X86, contributed by Sander Stok. +version 1.0.3b [August 26, 1999] + Replaced 2147483647L several places with PNG_MAX_UINT macro, defined in png.h + Changed leading blanks to tabs in all makefiles. + Define PNG_USE_PNGVCRD in makefile.w32, to get MMX assembler code. + Made alternate versions of png_set_expand() in pngrtran.c, namely + png_set_gray_1_2_4_to_8, png_set_palette_to_rgb, and png_set_tRNS_to_alpha + (Greg Roelofs, in "PNG: The Definitive Guide"). Deleted the 1.0.3a aliases. + Relocated start of 'extern "C"' block in png.h so it doesn't include pngconf.h + Revised calculation of num_blocks in pngmem.c to avoid a potentially + negative shift distance, whose results are undefined in the C language. + Added a check in pngset.c to prevent writing multiple tIME chunks. + Added a check in pngwrite.c to detect invalid small window_bits sizes. +version 1.0.3d [September 4, 1999] + Fixed type casting of igamma in pngrutil.c + Added new png_expand functions to scripts/pngdef.pas and pngos2.def + Added a demo read_user_transform_fn that examines the row filters in pngtest.c + +version 1.0.4 [September 24, 1999] + Define PNG_ALWAYS_EXTERN in pngconf.h if __STDC__ is defined + Delete #define PNG_INTERNAL and include "png.h" from pngasmrd.h + Made several minor corrections to pngtest.c + Renamed the makefiles with longer but more user friendly extensions. + Copied the PNG copyright and license to a separate LICENSE file. + Revised documentation, png.h, and example.c to remove reference to + "viewing_gamma" which no longer appears in the PNG specification. + Revised pngvcrd.c to use MMX code for interlacing only on the final pass. + Updated pngvcrd.c to use the faster C filter algorithms from libpng-1.0.1a + Split makefile.win32vc into two versions, makefile.vcawin32 (uses MMX + assembler code) and makefile.vcwin32 (doesn't). + Added a CPU timing report to pngtest.c (enabled by defining PNGTEST_TIMING) + Added a copy of pngnow.png to the distribution. +version 1.0.4a [September 25, 1999] + Increase max_pixel_depth in pngrutil.c if a user transform needs it. + Changed several division operations to right-shifts in pngvcrd.c +version 1.0.4b [September 30, 1999] + Added parentheses in line 3732 of pngvcrd.c + Added a comment in makefile.linux warning about buggy -O3 in pgcc 2.95.1 +version 1.0.4c [October 1, 1999] + Added a "png_check_version" function in png.c and pngtest.c that will generate + a helpful compiler error if an old png.h is found in the search path. + Changed type of png_user_transform_depth|channels from int to png_byte. +version 1.0.4d [October 6, 1999] + Changed 0.45 to 0.45455 in png_set_sRGB() + Removed unused PLTE entries from pngnow.png + Re-enabled some parts of pngvcrd.c (png_combine_row) that work properly. +version 1.0.4e [October 10, 1999] + Fixed sign error in pngvcrd.c (Greg Roelofs) + Replaced some instances of memcpy with simple assignments in pngvcrd (GR-P) +version 1.0.4f [October 15, 1999] + Surrounded example.c code with #if 0 .. #endif to prevent people from + inadvertently trying to compile it. + Changed png_get_header_version() from a function to a macro in png.h + Added type casting mostly in pngrtran.c and pngwtran.c + Removed some pointless "ptr = NULL" in pngmem.c + Added a "contrib" directory containing the source code from Greg's book. + +version 1.0.5 [October 15, 1999] + Minor editing of the INSTALL and README files. +version 1.0.5a [October 23, 1999] + Added contrib/pngsuite and contrib/pngminus (Willem van Schaik) + Fixed a typo in the png_set_sRGB() function call in example.c (Jan Nijtmans) + Further optimization and bugfix of pngvcrd.c + Revised pngset.c so that it does not allocate or free memory in the user's + text_ptr structure. Instead, it makes its own copy. + Created separate write_end_info_struct in pngtest.c for a more severe test. + Added code in pngwrite.c to free info_ptr->text[i].key to stop a memory leak. +version 1.0.5b [November 23, 1999] + Moved PNG_FLAG_HAVE_CHUNK_HEADER, PNG_FLAG_BACKGROUND_IS_GRAY and + PNG_FLAG_WROTE_tIME from flags to mode. + Added png_write_info_before_PLTE() function. + Fixed some typecasting in contrib/gregbook/*.c + Updated scripts/makevms.com and added makevms.com to contrib/gregbook + and contrib/pngminus (Martin Zinser) +version 1.0.5c [November 26, 1999] + Moved png_get_header_version from png.h to png.c, to accommodate ansi2knr. + Removed all global arrays (according to PNG_NO_GLOBAL_ARRAYS macro), to + accommodate making DLL's: Moved usr_png_ver from global variable to function + png_get_header_ver() in png.c. Moved png_sig to png_sig_bytes in png.c and + eliminated use of png_sig in pngwutil.c. Moved the various png_CHNK arrays + into pngtypes.h. Eliminated use of global png_pass arrays. Declared the + png_CHNK and png_pass arrays to be "const". Made the global arrays + available to applications (although none are used in libpng itself) when + PNG_NO_GLOBAL_ARRAYS is not defined or when PNG_GLOBAL_ARRAYS is defined. + Removed some extraneous "-I" from contrib/pngminus/makefile.std + Changed the PNG_sRGB_INTENT macros in png.h to be consistent with PNG-1.2. + Change PNG_SRGB_INTENT to PNG_sRGB_INTENT in libpng.txt and libpng.3 +version 1.0.5d [November 29, 1999] + Add type cast (png_const_charp) two places in png.c + Eliminated pngtypes.h; use macros instead to declare PNG_CHNK arrays. + Renamed "PNG_GLOBAL_ARRAYS" to "PNG_USE_GLOBAL_ARRAYS" and made available + to applications a macro "PNG_USE_LOCAL_ARRAYS". + Remove all the new declarations with #ifdef/#endif when + PNG_USE_GLOBAL_ARRAYS is defined. + Added PNG_EXPORT_VAR macro to accommodate making DLL's. +version 1.0.5e [November 30, 1999] + Added iCCP, iTXt, and sPLT support; added "lang" member to the png_text + structure; refactored the inflate/deflate support to make adding new chunks + with trailing compressed parts easier in the future, and added new functions + png_free_iCCP, png_free_pCAL, png_free_sPLT, png_free_text, png_get_iCCP, + png_get_spalettes, png_set_iCCP, png_set_spalettes (Eric S. Raymond). + NOTE: Applications that write text chunks MUST define png_text->lang + before calling png_set_text(). It must be set to NULL if you want to + write tEXt or zTXt chunks. If you want your application to be able to + run with older versions of libpng, use + + #ifdef PNG_iTXt_SUPPORTED + png_text[i].lang = NULL; + #endif + + Changed png_get_oFFs() and png_set_oFFs() to use signed rather than unsigned + offsets (Eric S. Raymond). + Combined PNG_READ_cHNK_SUPPORTED and PNG_WRITE_cHNK_SUPPORTED macros into + PNG_cHNK_SUPPORTED and combined the three types of PNG_text_SUPPORTED + macros, leaving the separate macros also available. + Removed comments on #endifs at the end of many short, non-nested #if-blocks. +version 1.0.5f [December 6, 1999] + Changed makefile.solaris to issue a warning about potential problems when + the ucb "ld" is in the path ahead of the ccs "ld". + Removed "- [date]" from the "synopsis" line in libpng.3 and libpngpf.3. + Added sCAL chunk support (Eric S. Raymond). +version 1.0.5g [December 7, 1999] + Fixed "png_free_spallettes" typo in png.h + Added code to handle new chunks in pngpread.c + Moved PNG_CHNK string macro definitions outside of PNG_NO_EXTERN block + Added "translated_key" to png_text structure and png_write_iTXt(). + Added code in pngwrite.c to work around a newly discovered zlib bug. +version 1.0.5h [December 10, 1999] + NOTE: regarding the note for version 1.0.5e, the following must also + be included in your code: + png_text[i].translated_key = NULL; + Unknown chunk handling is now supported. + Option to eliminate all floating point support was added. Some new + fixed-point functions such as png_set_gAMA_fixed() were added. + Expanded tabs and removed trailing blanks in source files. +version 1.0.5i [December 13, 1999] + Added some type casts to silence compiler warnings. + Renamed "png_free_spalette" to "png_free_spalettes" for consistency. + Removed leading blanks from a #define in pngvcrd.c + Added some parameters to the new png_set_keep_unknown_chunks() function. + Added a test for up->location != 0 in the first instance of writing + unknown chunks in pngwrite.c + Changed "num" to "i" in png_free_spalettes() and png_free_unknowns() to + prevent recursion. + Added png_free_hIST() function. + Various patches to fix bugs in the sCAL and integer cHRM processing, + and to add some convenience macros for use with sCAL. +version 1.0.5j [December 21, 1999] + Changed "unit" parameter of png_write_sCAL from png_byte to int, to work + around buggy compilers. + Added new type "png_fixed_point" for integers that hold float*100000 values + Restored backward compatibility of tEXt/zTXt chunk processing: + Restored the first four members of png_text to the same order as v.1.0.5d. + Added members "lang_key" and "itxt_length" to png_text struct. Set + text_length=0 when "text" contains iTXt data. Use the "compression" + member to distinguish among tEXt/zTXt/iTXt types. Added + PNG_ITXT_COMPRESSION_NONE (1) and PNG_ITXT_COMPRESSION_zTXt(2) macros. + The "Note" above, about backward incompatibility of libpng-1.0.5e, no + longer applies. + Fixed png_read|write_iTXt() to read|write parameters in the right order, + and to write the iTXt chunk after IDAT if it appears in the end_ptr. + Added pnggccrd.c, version of pngvcrd.c Intel assembler for gcc (Greg Roelofs) + Reversed the order of trying to write floating-point and fixed-point gAMA. +version 1.0.5k [December 27, 1999] + Added many parentheses, e.g., "if (a && b & c)" becomes "if (a && (b & c))" + Added png_handle_as_unknown() function (Glenn) + Added png_free_chunk_list() function and chunk_list and num_chunk_list members + of png_ptr. + Eliminated erroneous warnings about multiple sPLT chunks and sPLT-after-PLTE. + Fixed a libpng-1.0.5h bug in pngrutil.c that was issuing erroneous warnings + about ignoring incorrect gAMA with sRGB (gAMA was in fact not ignored) + Added png_free_tRNS(); png_set_tRNS() now malloc's its own trans array (ESR). + Define png_get_int_32 when oFFs chunk is supported as well as when pCAL is. + Changed type of proflen from png_int_32 to png_uint_32 in png_get_iCCP(). +version 1.0.5l [January 1, 2000] + Added functions png_set_read_user_chunk_fn() and png_get_user_chunk_ptr() + for setting a callback function to handle unknown chunks and for + retrieving the associated user pointer (Glenn). +version 1.0.5m [January 7, 2000] + Added high-level functions png_read_png(), png_write_png(), png_free_pixels(). +version 1.0.5n [January 9, 2000] + Added png_free_PLTE() function, and modified png_set_PLTE() to malloc its + own memory for info_ptr->palette. This makes it safe for the calling + application to free its copy of the palette any time after it calls + png_set_PLTE(). +version 1.0.5o [January 20, 2000] + Cosmetic changes only (removed some trailing blanks and TABs) +version 1.0.5p [January 31, 2000] + Renamed pngdll.mak to makefile.bd32 + Cosmetic changes in pngtest.c +version 1.0.5q [February 5, 2000] + Relocated the makefile.solaris warning about PATH problems. + Fixed pngvcrd.c bug by pushing/popping registers in mmxsupport (Bruce Oberg) + Revised makefile.gcmmx + Added PNG_SETJMP_SUPPORTED, PNG_SETJMP_NOT_SUPPORTED, and PNG_ABORT() macros +version 1.0.5r [February 7, 2000] + Removed superfluous prototype for png_get_itxt from png.h + Fixed a bug in pngrtran.c that improperly expanded the background color. + Return *num_text=0 from png_get_text() when appropriate, and fix documentation + of png_get_text() in libpng.txt/libpng.3. +version 1.0.5s [February 18, 2000] + Added "png_jmp_env()" macro to pngconf.h, to help people migrate to the + new error handler that's planned for the next libpng release, and changed + example.c, pngtest.c, and contrib programs to use this macro. + Revised some of the DLL-export macros in pngconf.h (Greg Roelofs) + Fixed a bug in png_read_png() that caused it to fail to expand some images + that it should have expanded. + Fixed some mistakes in the unused and undocumented INCH_CONVERSIONS functions + in pngget.c + Changed the allocation of palette, history, and trans arrays back to + the version 1.0.5 method (linking instead of copying) which restores + backward compatibility with version 1.0.5. Added some remarks about + that in example.c. Added "free_me" member to info_ptr and png_ptr + and added png_free_data() function. + Updated makefile.linux and makefile.gccmmx to make directories conditionally. + Made cosmetic changes to pngasmrd.h + Added png_set_rows() and png_get_rows(), for use with png_read|write_png(). + Modified png_read_png() to allocate info_ptr->row_pointers only if it + hasn't already been allocated. +version 1.0.5t [March 4, 2000] + Changed png_jmp_env() migration aiding macro to png_jmpbuf(). + Fixed "interlace" typo (should be "interlaced") in contrib/gregbook/read2-x.c + Fixed bug with use of PNG_BEFORE_IHDR bit in png_ptr->mode, introduced when + PNG_FLAG_HAVE_CHUNK_HEADER was moved into png_ptr->mode in version 1.0.5b + Files in contrib/gregbook were revised to use png_jmpbuf() and to select + a 24-bit visual if one is available, and to allow abbreviated options. + Files in contrib/pngminus were revised to use the png_jmpbuf() macro. + Removed spaces in makefile.linux and makefile.gcmmx, introduced in 1.0.5s +version 1.0.5u [March 5, 2000] + Simplified the code that detects old png.h in png.c and pngtest.c + Renamed png_spalette (_p, _pp) to png_sPLT_t (_tp, _tpp) + Increased precision of rgb_to_gray calculations from 8 to 15 bits and + added png_set_rgb_to_gray_fixed() function. + Added makefile.bc32 (32-bit Borland C++, C mode) +version 1.0.5v [March 11, 2000] + Added some parentheses to the png_jmpbuf macro definition. + Updated references to the zlib home page, which has moved to freesoftware.com. + Corrected bugs in documentation regarding png_read_row() and png_write_row(). + Updated documentation of png_rgb_to_gray calculations in libpng.3/libpng.txt. + Renamed makefile.borland,turboc3 back to makefile.bor,tc3 as in version 1.0.3, + revised borland makefiles; added makefile.ibmvac3 and makefile.gcc (Cosmin) + +version 1.0.6 [March 20, 2000] + Minor revisions of makefile.bor, libpng.txt, and gregbook/rpng2-win.c + Added makefile.sggcc (SGI IRIX with gcc) +version 1.0.6d [April 7, 2000] + Changed sprintf() to strcpy() in png_write_sCAL_s() to work without STDIO + Added data_length parameter to png_decompress_chunk() function + Revised documentation to remove reference to abandoned png_free_chnk functions + Fixed an error in png_rgb_to_gray_fixed() + Revised example.c, usage of png_destroy_write_struct(). + Renamed makefile.ibmvac3 to makefile.ibmc, added libpng.icc IBM project file + Added a check for info_ptr->free_me&PNG_FREE_TEXT when freeing text in png.c + Simplify png_sig_bytes() function to remove use of non-ISO-C strdup(). +version 1.0.6e [April 9, 2000] + Added png_data_freer() function. + In the code that checks for over-length tRNS chunks, added check of + info_ptr->num_trans as well as png_ptr->num_trans (Matthias Benckmann) + Minor revisions of libpng.txt/libpng.3. + Check for existing data and free it if the free_me flag is set, in png_set_*() + and png_handle_*(). + Only define PNG_WEIGHTED_FILTERS_SUPPORTED when PNG_FLOATING_POINT_SUPPORTED + is defined. + Changed several instances of PNG_NO_CONSOLE_ID to PNG_NO_STDIO in pngrutil.c + and mentioned the purposes of the two macros in libpng.txt/libpng.3. +version 1.0.6f [April 14, 2000] + Revised png_set_iCCP() and png_set_rows() to avoid prematurely freeing data. + Add checks in png_set_text() for NULL members of the input text structure. + Revised libpng.txt/libpng.3. + Removed superfluous prototype for png_set_itxt from png.h + Removed "else" from pngread.c, after png_error(), and changed "0" to "length". + Changed several png_errors about malformed ancillary chunks to png_warnings. +version 1.0.6g [April 24, 2000] + Added png_pass-* arrays to pnggccrd.c when PNG_USE_LOCAL_ARRAYS is defined. + Relocated paragraph about png_set_background() in libpng.3/libpng.txt + and other revisions (Matthias Benckmann) + Relocated info_ptr->free_me, png_ptr->free_me, and other info_ptr and + png_ptr members to restore binary compatibility with libpng-1.0.5 + (breaks compatibility with libpng-1.0.6). +version 1.0.6h [April 24, 2000] + Changed shared library so-number pattern from 2.x.y.z to xy.z (this builds + libpng.so.10 & libpng.so.10.6h instead of libpng.so.2 & libpng.so.2.1.0.6h) + This is a temporary change for test purposes. +version 1.0.6i [May 2, 2000] + Rearranged some members at the end of png_info and png_struct, to put + unknown_chunks_num and free_me within the original size of the png_structs + and free_me, png_read_user_fn, and png_free_fn within the original png_info, + because some old applications allocate the structs directly instead of + using png_create_*(). + Added documentation of user memory functions in libpng.txt/libpng.3 + Modified png_read_png so that it will use user_allocated row_pointers + if present, unless free_me directs that it be freed, and added description + of the use of png_set_rows() and png_get_rows() in libpng.txt/libpng.3. + Added PNG_LEGACY_SUPPORTED macro, and #ifdef out all new (since version + 1.00) members of png_struct and png_info, to regain binary compatibility + when you define this macro. Capabilities lost in this event + are user transforms (new in version 1.0.0),the user transform pointer + (new in version 1.0.2), rgb_to_gray (new in 1.0.5), iCCP, sCAL, sPLT, + the high-level interface, and unknown chunks support (all new in 1.0.6). + This was necessary because of old applications that allocate the structs + directly as authors were instructed to do in libpng-0.88 and earlier, + instead of using png_create_*(). + Added modes PNG_CREATED_READ_STRUCT and PNG_CREATED_WRITE_STRUCT which + can be used to detect codes that directly allocate the structs, and + code to check these modes in png_read_init() and png_write_init() and + generate a libpng error if the modes aren't set and PNG_LEGACY_SUPPORTED + was not defined. + Added makefile.intel and updated makefile.watcom (Pawel Mrochen) +version 1.0.6j [May 3, 2000] + Overloaded png_read_init() and png_write_init() with macros that convert + calls to png_read_init_2() or png_write_init_2() that check the version + and structure sizes. +version 1.0.7beta11 [May 7, 2000] + Removed the new PNG_CREATED_READ_STRUCT and PNG_CREATED_WRITE_STRUCT modes + which are no longer used. + Eliminated the three new members of png_text when PNG_LEGACY_SUPPORTED is + defined or when neither PNG_READ_iTXt_SUPPORTED nor PNG_WRITE_iTXT_SUPPORTED + is defined. + Made PNG_NO_READ|WRITE_iTXt the default setting, to avoid memory + overrun when old applications fill the info_ptr->text structure directly. + Added PNGAPI macro, and added it to the definitions of all exported functions. + Relocated version macro definitions ahead of the includes of zlib.h and + pngconf.h in png.h. +version 1.0.7beta12 [May 12, 2000] + Revised pngset.c to avoid a problem with expanding the png_debug macro. + Deleted some extraneous defines from pngconf.h + Made PNG_NO_CONSOLE_IO the default condition when PNG_BUILD_DLL is defined. + Use MSC _RPTn debugging instead of fprintf if _MSC_VER is defined. + Added png_access_version_number() function. + Check for mask&PNG_FREE_CHNK (for TEXT, SCAL, PCAL) in png_free_data(). + Expanded libpng.3/libpng.txt information about png_data_freer(). +version 1.0.7beta14 [May 17, 2000] (beta13 was not published) + Changed pnggccrd.c and pngvcrd.c to handle bad adaptive filter types as + warnings instead of errors, as pngrutil.c does. + Set the PNG_INFO_IDAT valid flag in png_set_rows() so png_write_png() + will actually write IDATs. + Made the default PNG_USE_LOCAL_ARRAYS depend on PNG_DLL instead of WIN32. + Make png_free_data() ignore its final parameter except when freeing data + that can have multiple instances (text, sPLT, unknowns). + Fixed a new bug in png_set_rows(). + Removed info_ptr->valid tests from png_free_data(), as in version 1.0.5. + Added png_set_invalid() function. + Fixed incorrect illustrations of png_destroy_write_struct() in example.c. +version 1.0.7beta15 [May 30, 2000] + Revised the deliberately erroneous Linux setjmp code in pngconf.h to produce + fewer error messages. + Rearranged checks for Z_OK to check the most likely path first in pngpread.c + and pngwutil.c. + Added checks in pngtest.c for png_create_*() returning NULL, and mentioned + in libpng.txt/libpng.3 the need for applications to check this. + Changed names of png_default_*() functions in pngtest to pngtest_*(). + Changed return type of png_get_x|y_offset_*() from png_uint_32 to png_int_32. + Fixed some bugs in the unused PNG_INCH_CONVERSIONS functions in pngget.c + Set each pointer to NULL after freeing it in png_free_data(). + Worked around a problem in pngconf.h; AIX's strings.h defines an "index" + macro that conflicts with libpng's png_color_16.index. (Dimitri Papadapoulos) + Added "msvc" directory with MSVC++ project files (Simon-Pierre Cadieux). +version 1.0.7beta16 [June 4, 2000] + Revised the workaround of AIX string.h "index" bug. + Added a check for overlength PLTE chunk in pngrutil.c. + Added PNG_NO_POINTER_INDEXING macro to use array-indexing instead of pointer + indexing in pngrutil.c and pngwutil.c to accommodate a buggy compiler. + Added a warning in png_decompress_chunk() when it runs out of data, e.g. + when it tries to read an erroneous PhotoShop iCCP chunk. + Added PNG_USE_DLL macro. + Revised the copyright/disclaimer/license notice. + Added contrib/msvctest directory +version 1.0.7rc1 [June 9, 2000] + Corrected the definition of PNG_TRANSFORM_INVERT_ALPHA (0x0400 not 0x0200) + Added contrib/visupng directory (Willem van Schaik) +version 1.0.7beta18 [June 23, 2000] + Revised PNGAPI definition, and pngvcrd.c to work with __GCC__ + and do not redefine PNGAPI if it is passed in via a compiler directive. + Revised visupng/PngFile.c to remove returns from within the Try block. + Removed leading underscores from "_PNG_H" and "_PNG_SAVE_BSD_SOURCE" macros. + Updated contrib/visupng/cexcept.h to version 1.0.0. + Fixed bugs in pngwrite.c and pngwutil.c that prevented writing iCCP chunks. +version 1.0.7rc2 [June 28, 2000] + Updated license to include disclaimers required by UCITA. + Fixed "DJBPP" typo in pnggccrd.c introduced in beta18. + +version 1.0.7 [July 1, 2000] + Revised the definition of "trans_values" in libpng.3/libpng.txt +version 1.0.8beta1 [July 8, 2000] + Added png_free(png_ptr, key) two places in pngpread.c to stop memory leaks. + Changed PNG_NO_STDIO to PNG_NO_CONSOLE_IO, several places in pngrutil.c and + pngwutil.c. + Changed PNG_EXPORT_VAR to use PNG_IMPEXP, in pngconf.h. + Removed unused "#include " from png.c + Added WindowsCE support. + Revised pnggccrd.c to work with gcc-2.95.2 and in the Cygwin environment. +version 1.0.8beta2 [July 10, 2000] + Added project files to the wince directory and made further revisions + of pngtest.c, pngrio.c, and pngwio.c in support of WindowsCE. +version 1.0.8beta3 [July 11, 2000] + Only set the PNG_FLAG_FREE_TRNS or PNG_FREE_TRNS flag in png_handle_tRNS() + for indexed-color input files to avoid potential double-freeing trans array + under some unusual conditions; problem was introduced in version 1.0.6f. + Further revisions to pngtest.c and files in the wince subdirectory. +version 1.0.8beta4 [July 14, 2000] + Added the files pngbar.png and pngbar.jpg to the distribution. + Added makefile.cygwin, and cygwin support in pngconf.h + Added PNG_NO_ZALLOC_ZERO macro (makes png_zalloc skip zeroing memory) +version 1.0.8rc1 [July 16, 2000] + Revised png_debug() macros and statements to eliminate compiler warnings. + +version 1.0.8 [July 24, 2000] + Added png_flush() in pngwrite.c, after png_write_IEND(). + Updated makefile.hpux to build a shared library. +version 1.0.9beta1 [November 10, 2000] + Fixed typo in scripts/makefile.hpux + Updated makevms.com in scripts and contrib/* and contrib/* (Martin Zinser) + Fixed seqence-point bug in contrib/pngminus/png2pnm (Martin Zinser) + Changed "cdrom.com" in documentation to "libpng.org" + Revised pnggccrd.c to get it all working, and updated makefile.gcmmx (Greg). + Changed type of "params" from voidp to png_voidp in png_read|write_png(). + Make sure PNGAPI and PNG_IMPEXP are defined in pngconf.h. + Revised the 3 instances of WRITEFILE in pngtest.c. + Relocated "msvc" and "wince" project subdirectories into "dll" subdirectory. + Updated png.rc in dll/msvc project + Revised makefile.dec to define and use LIBPATH and INCPATH + Increased size of global png_libpng_ver[] array from 12 to 18 chars. + Made global png_libpng_ver[], png_sig[] and png_pass_*[] arrays const. + Removed duplicate png_crc_finish() from png_handle_bKGD() function. + Added a warning when application calls png_read_update_info() multiple times. + Revised makefile.cygwin + Fixed bugs in iCCP support in pngrutil.c and pngwutil.c. + Replaced png_set_empty_plte_permitted() with png_permit_mng_features(). +version 1.0.9beta2 [November 19, 2000] + Renamed the "dll" subdirectory "projects". + Added borland project files to "projects" subdirectory. + Set VS_FF_PRERELEASE and VS_FF_PATCHED flags in msvc/png.rc when appropriate. + Add error message in png_set_compression_buffer_size() when malloc fails. +version 1.0.9beta3 [November 23, 2000] + Revised PNG_LIBPNG_BUILD_TYPE macro in png.h, used in the msvc project. + Removed the png_flush() in pngwrite.c that crashes some applications + that don't set png_output_flush_fn. + Added makefile.macosx and makefile.aix to scripts directory. +version 1.0.9beta4 [December 1, 2000] + Change png_chunk_warning to png_warning in png_check_keyword(). + Increased the first part of msg buffer from 16 to 18 in png_chunk_error(). +version 1.0.9beta5 [December 15, 2000] + Added support for filter method 64 (for PNG datastreams embedded in MNG). +version 1.0.9beta6 [December 18, 2000] + Revised png_set_filter() to accept filter method 64 when appropriate. + Added new PNG_HAVE_PNG_SIGNATURE bit to png_ptr->mode and use it to + help prevent applications from using MNG features in PNG datastreams. + Added png_permit_mng_features() function. + Revised libpng.3/libpng.txt. Changed "filter type" to "filter method". +version 1.0.9rc1 [December 23, 2000] + Revised test for PNG_HAVE_PNG_SIGNATURE in pngrutil.c + Fixed error handling of unknown compression type in png_decompress_chunk(). + In pngconf.h, define __cdecl when _MSC_VER is defined. +version 1.0.9beta7 [December 28, 2000] + Changed PNG_TEXT_COMPRESSION_zTXt to PNG_COMPRESSION_TYPE_BASE several places. + Revised memory management in png_set_hIST and png_handle_hIST in a backward + compatible manner. PLTE and tRNS were revised similarly. + Revised the iCCP chunk reader to ignore trailing garbage. +version 1.0.9beta8 [January 12, 2001] + Moved pngasmrd.h into pngconf.h. + Improved handling of out-of-spec garbage iCCP chunks generated by PhotoShop. +version 1.0.9beta9 [January 15, 2001] + Added png_set_invalid, png_permit_mng_features, and png_mmx_supported to + wince and msvc project module definition files. + Minor revision of makefile.cygwin. + Fixed bug with progressive reading of narrow interlaced images in pngpread.c +version 1.0.9beta10 [January 16, 2001] + Do not typedef png_FILE_p in pngconf.h when PNG_NO_STDIO is defined. + Fixed "png_mmx_supported" typo in project definition files. +version 1.0.9beta11 [January 19, 2001] + Updated makefile.sgi to make shared library. + Removed png_mmx_support() function and disabled PNG_MNG_FEATURES_SUPPORTED + by default, for the benefit of DLL forward compatibility. These will + be re-enabled in version 1.2.0. +version 1.0.9rc2 [January 22, 2001] + Revised cygwin support. + +version 1.0.9 [January 31, 2001] + Added check of cygwin's ALL_STATIC in pngconf.h + Added "-nommx" parameter to contrib/gregbook/rpng2-win and rpng2-x demos. +version 1.0.10beta1 [March 14, 2001] + Revised makefile.dec, makefile.sgi, and makefile.sggcc; added makefile.hpgcc. + Reformatted libpng.3 to eliminate bad line breaks. + Added checks for _mmx_supported in the read_filter_row function of pnggccrd.c + Added prototype for png_mmx_support() near the top of pnggccrd.c + Moved some error checking from png_handle_IHDR to png_set_IHDR. + Added PNG_NO_READ_SUPPORTED and PNG_NO_WRITE_SUPPORTED macros. + Revised png_mmx_support() function in pnggccrd.c + Restored version 1.0.8 PNG_WRITE_EMPTY_PLTE_SUPPORTED behavior in pngwutil.c + Fixed memory leak in contrib/visupng/PngFile.c + Fixed bugs in png_combine_row() in pnggccrd.c and pngvcrd.c (C version) + Added warnings when retrieving or setting gamma=0. + Increased the first part of msg buffer from 16 to 18 in png_chunk_warning(). +version 1.0.10rc1 [March 23, 2001] + Changed all instances of memcpy, strcpy, and strlen to png_memcpy, png_strcpy, + and png_strlen. + Revised png_mmx_supported() function in pnggccrd.c to return proper value. + Fixed bug in progressive reading (pngpread.c) with small images (height < 8). + +version 1.0.10 [March 30, 2001] + Deleted extraneous space (introduced in 1.0.9) from line 42 of makefile.cygwin + Added beos project files (Chris Herborth) +version 1.0.11beta1 [April 3, 2001] + Added type casts on several png_malloc() calls (Dimitri Papadapoulos). + Removed a no-longer needed AIX work-around from pngconf.h + Changed several "//" single-line comments to C-style in pnggccrd.c +version 1.0.11beta2 [April 11, 2001] + Removed PNGAPI from several functions whose prototypes did not have PNGAPI. + Updated scripts/pngos2.def +version 1.0.11beta3 [April 14, 2001] + Added checking the results of many instances of png_malloc() for NULL +version 1.0.11beta4 [April 20, 2001] + Undid the changes from version 1.0.11beta3. Added a check for NULL return + from user's malloc_fn(). + Removed some useless type casts of the NULL pointer. + Added makefile.netbsd + +version 1.0.11 [April 27, 2001] + Revised makefile.netbsd +version 1.0.12beta1 [May 14, 2001] + Test for Windows platform in pngconf.h when including malloc.h (Emmanuel Blot) + Updated makefile.cygwin and handling of Cygwin's ALL_STATIC in pngconf.h + Added some never-to-be-executed code in pnggccrd.c to quiet compiler warnings. + Eliminated the png_error about apps using png_read|write_init(). Instead, + libpng will reallocate the png_struct and info_struct if they are too small. + This retains future binary compatibility for old applications written for + libpng-0.88 and earlier. +version 1.2.0beta1 [May 6, 2001] + Bumped DLLNUM to 2. + Re-enabled PNG_MNG_FEATURES_SUPPORTED and enabled PNG_ASSEMBLER_CODE_SUPPORTED + by default. + Added runtime selection of MMX features. + Added png_set_strip_error_numbers function and related macros. +version 1.2.0beta2 [May 7, 2001] + Finished merging 1.2.0beta1 with version 1.0.11 + Added a check for attempts to read or write PLTE in grayscale PNG datastreams. +version 1.2.0beta3 [May 17, 2001] + Enabled user memory function by default. + Modified png_create_struct so it passes user mem_ptr to user memory allocator. + Increased png_mng_features flag from png_byte to png_uint_32. + Bumped shared-library (so-number) and dll-number to 3. +version 1.2.0beta4 [June 23, 2001] + Check for missing profile length field in iCCP chunk and free chunk_data + in case of truncated iCCP chunk. + Bumped shared-library number to 3 in makefile.sgi and makefile.sggcc + Bumped dll-number from 2 to 3 in makefile.cygwin + Revised contrib/gregbook/rpng*-x.c to avoid a memory leak and to exit cleanly + if user attempts to run it on an 8-bit display. + Updated contrib/gregbook + Use png_malloc instead of png_zalloc to allocate palette in pngset.c + Updated makefile.ibmc + Added some typecasts to eliminate gcc 3.0 warnings. Changed prototypes + of png_write_oFFS width and height from png_uint_32 to png_int_32. + Updated example.c + Revised prototypes for png_debug_malloc and png_debug_free in pngtest.c +version 1.2.0beta5 [August 8, 2001] + Revised contrib/gregbook + Revised makefile.gcmmx + Revised pnggccrd.c to conditionally compile some thread-unsafe code only + when PNG_THREAD_UNSAFE_OK is defined. + Added tests to prevent pngwutil.c from writing a bKGD or tRNS chunk with + value exceeding 2^bit_depth-1 + Revised makefile.sgi and makefile.sggcc + Replaced calls to fprintf(stderr,...) with png_warning() in pnggccrd.c + Removed restriction that do_invert_mono only operate on 1-bit opaque files + +version 1.2.0 [September 1, 2001] + Changed a png_warning() to png_debug() in pnggccrd.c + Fixed contrib/gregbook/rpng-x.c, rpng2-x.c to avoid crash with XFreeGC(). +version 1.2.1beta1 [October 19, 2001] + Revised makefile.std in contrib/pngminus + Include background_1 in png_struct regardless of gamma support. + Revised makefile.netbsd and makefile.macosx, added makefile.darwin. + Revised example.c to provide more details about using row_callback(). +version 1.2.1beta2 [October 25, 2001] + Added type cast to each NULL appearing in a function call, except for + WINCE functions. + Added makefile.so9. +version 1.2.1beta3 [October 27, 2001] + Removed type casts from all NULLs. + Simplified png_create_struct_2(). +version 1.2.1beta4 [November 7, 2001] + Revised png_create_info_struct() and png_creat_struct_2(). + Added error message if png_write_info() was omitted. + Type cast NULLs appearing in function calls when _NO_PROTO or + PNG_TYPECAST_NULL is defined. +version 1.2.1rc1 [November 24, 2001] + Type cast NULLs appearing in function calls except when PNG_NO_TYPECAST_NULL + is defined. + Changed typecast of "size" argument to png_size_t in pngmem.c calls to + the user malloc_fn, to agree with the prototype in png.h + Added a pop/push operation to pnggccrd.c, to preserve Eflag (Maxim Sobolev) + Updated makefile.sgi to recognize LIBPATH and INCPATH. + Updated various makefiles so "make clean" does not remove previous major + version of the shared library. +version 1.2.1rc2 [December 4, 2001] + Always allocate 256-entry internal palette, hist, and trans arrays, to + avoid out-of-bounds memory reference caused by invalid PNG datastreams. + Added a check for prefix_length > data_length in iCCP chunk handler. + +version 1.2.1 [December 7, 2001] + None. +version 1.2.2beta1 [February 22, 2002] + Fixed a bug with reading the length of iCCP profiles (Larry Reeves). + Revised makefile.linux, makefile.gcmmx, and makefile.sgi to generate + libpng.a, libpng12.so (not libpng.so.3), and libpng12/png.h + Revised makefile.darwin to remove "-undefined suppress" option. + Added checks for gamma and chromaticity values over 21474.83, which exceed + the limit for PNG unsigned 32-bit integers when encoded. + Revised calls to png_create_read_struct() and png_create_write_struct() + for simpler debugging. + Revised png_zalloc() so zlib handles errors (uses PNG_FLAG_MALLOC_NULL_MEM_OK) +version 1.2.2beta2 [February 23, 2002] + Check chunk_length and idat_size for invalid (over PNG_MAX_UINT) lengths. + Check for invalid image dimensions in png_get_IHDR. + Added missing "fi;" in the install target of the SGI makefiles. + Added install-static to all makefiles that make shared libraries. + Always do gamma compensation when image is partially transparent. +version 1.2.2beta3 [March 7, 2002] + Compute background.gray and background_1.gray even when color_type is RGB + in case image gets reduced to gray later. + Modified shared-library makefiles to install pkgconfig/libpngNN.pc. + Export (with PNGAPI) png_zalloc, png_zfree, and png_handle_as_unknown + Removed unused png_write_destroy_info prototype from png.h + Eliminated incorrect use of width_mmx from pnggccrd.c in pixel_bytes == 8 case + Added install-shared target to all makefiles that make shared libraries. + Stopped a double free of palette, hist, and trans when not using free_me. + Added makefile.32sunu for Sun Ultra 32 and makefile.64sunu for Sun Ultra 64. +version 1.2.2beta4 [March 8, 2002] + Compute background.gray and background_1.gray even when color_type is RGB + in case image gets reduced to gray later (Jason Summers). + Relocated a misplaced /bin/rm in the "install-shared" makefile targets + Added PNG_1_0_X macro which can be used to build a 1.0.x-compatible library. +version 1.2.2beta5 [March 26, 2002] + Added missing PNGAPI to several function definitions. + Check for invalid bit_depth or color_type in png_get_IHDR(), and + check for missing PLTE or IHDR in png_push_read_chunk() (Matthias Clasen). + Revised iTXt support to accept NULL for lang and lang_key. + Compute gamma for color components of background even when color_type is gray. + Changed "()" to "{}" in scripts/libpng.pc.in. + Revised makefiles to put png.h and pngconf.h only in $prefix/include/libpngNN + Revised makefiles to make symlink to libpng.so.NN in addition to libpngNN.so +version 1.2.2beta6 [March 31, 2002] +version 1.0.13beta1 [March 31, 2002] + Prevent png_zalloc() from trying to memset memory that it failed to acquire. + Add typecasts of PNG_MAX_UINT in pngset_cHRM_fixed() (Matt Holgate). + Ensure that the right function (user or default) is used to free the + png_struct after an error in png_create_read_struct_2(). +version 1.2.2rc1 [April 7, 2002] +version 1.0.13rc1 [April 7, 2002] + Save the ebx register in pnggccrd.c (Sami Farin) + Add "mem_ptr = png_ptr->mem_ptr" in png_destroy_write_struct() (Paul Gardner). + Updated makefiles to put headers in include/libpng and remove old include/*.h. + +version 1.2.2 [April 15, 2002] +version 1.0.13 [April 15, 2002] + Revised description of png_set_filter() in libpng.3/libpng.txt. + Revised makefile.netbsd and added makefile.neNNbsd and makefile.freebsd +version 1.0.13patch01 [April 17, 2002] +version 1.2.2patch01 [April 17, 2002] + Changed ${PNGMAJ}.${PNGVER} bug to ${PNGVER} in makefile.sgi and makefile.sggcc + Fixed VER -> PNGVER typo in makefile.macosx and added install-static to install + Added install: target to makefile.32sunu and makefile.64sunu +version 1.0.13patch03 [April 18, 2002] +version 1.2.2patch03 [April 18, 2002] + Revised 15 makefiles to link libpng.a to libpngNN.a and the include libpng + subdirectory to libpngNN subdirectory without the full pathname. + Moved generation of libpng.pc from "install" to "all" in 15 makefiles. +version 1.2.3rc1 [April 28, 2002] + Added install-man target to 15 makefiles (Dimitri Papadopolous-Orfanos). + Added $(DESTDIR) feature to 24 makefiles (Tim Mooney) + Fixed bug with $prefix, should be $(prefix) in makefile.hpux. + Updated cygwin-specific portion of pngconf.h and revised makefile.cygwin + Added a link from libpngNN.pc to libpng.pc in 15 makefiles. + Added links from include/libpngNN/*.h to include/*.h in 24 makefiles. + Revised makefile.darwin to make relative links without full pathname. + Added setjmp() at the end of png_create_*_struct_2() in case user forgets + to put one in their application. + Restored png_zalloc() and png_zfree() prototypes to version 1.2.1 and + removed them from module definition files. +version 1.2.3rc2 [May 1, 2002] + Fixed bug in reporting number of channels in pngget.c and pngset.c, + that was introduced in version 1.2.2beta5. + Exported png_zalloc(), png_zfree(), png_default_read(), png_default_write(), + png_default_flush(), and png_push_fill_buffer() and included them in + module definition files. + Added "libpng.pc" dependency to the "install-shared" target in 15 makefiles. +version 1.2.3rc3 [May 1, 2002] + Revised prototype for png_default_flush() + Remove old libpng.pc and libpngNN.pc before installing new ones. +version 1.2.3rc4 [May 2, 2002] + Typos in *.def files (png_default_read|write -> png_default_read|write_data) + In makefiles, changed rm libpng.NN.pc to rm libpngNN.pc + Added libpng-config and libpngNN-config and modified makefiles to install them. + Changed $(MANPATH) to $(DESTDIR)$(MANPATH) in makefiles + Added "Win32 DLL VB" configuration to projects/msvc/libpng.dsp +version 1.2.3rc5 [May 11, 2002] + Changed "error" and "message" in prototypes to "error_message" and + "warning_message" to avoid namespace conflict. + Revised 15 makefiles to build libpng-config from libpng-config-*.in + Once more restored png_zalloc and png_zfree to regular nonexported form. + Restored png_default_read|write_data, png_default_flush, png_read_fill_buffer + to nonexported form, but with PNGAPI, and removed them from module def files. +version 1.2.3rc6 [May 14, 2002] + Removed "PNGAPI" from png_zalloc() and png_zfree() in png.c + Changed "Gz" to "Gd" in projects/msvc/libpng.dsp and zlib.dsp. + Removed leftover libpng-config "sed" script from four makefiles. + Revised libpng-config creating script in 16 makefiles. + +version 1.2.3 [May 22, 2002] + Revised libpng-config target in makefile.cygwin. + Removed description of png_set_mem_fn() from documentation. + Revised makefile.freebsd. + Minor cosmetic changes to 15 makefiles, e.g., $(DI) = $(DESTDIR)/$(INCDIR). + Revised projects/msvc/README.txt + Changed -lpng to -lpngNN in LDFLAGS in several makefiles. +version 1.2.4beta1 [May 24, 2002] + Added libpng.pc and libpng-config to "all:" target in 16 makefiles. + Fixed bug in 16 makefiles: $(DESTDIR)/$(LIBPATH) to $(DESTDIR)$(LIBPATH) + Added missing "\" before closing double quote in makefile.gcmmx. + Plugged various memory leaks; added png_malloc_warn() and png_set_text_2() + functions. +version 1.2.4beta2 [June 25, 2002] + Plugged memory leak of png_ptr->current_text (Matt Holgate). + Check for buffer overflow before reading CRC in pngpread.c (Warwick Allison) + Added -soname to the loader flags in makefile.dec, makefile.sgi, and + makefile.sggcc. + Added "test-installed" target to makefile.linux, makefile.gcmmx, + makefile.sgi, and makefile.sggcc. +version 1.2.4beta3 [June 28, 2002] + Plugged memory leak of row_buf in pngtest.c when there is a png_error(). + Detect buffer overflow in pngpread.c when IDAT is corrupted with extra data. + Added "test-installed" target to makefile.32sunu, makefile.64sunu, + makefile.beos, makefile.darwin, makefile.dec, makefile.macosx, + makefile.solaris, makefile.hpux, makefile.hpgcc, and makefile.so9. +version 1.2.4rc1 and 1.0.14rc1 [July 2, 2002] + Added "test-installed" target to makefile.cygwin and makefile.sco. + Revised pnggccrd.c to be able to back out version 1.0.x via PNG_1_0_X macro. + +version 1.2.4 and 1.0.14 [July 8, 2002] + Changed png_warning() to png_error() when width is too large to process. +version 1.2.4patch01 [July 20, 2002] + Revised makefile.cygwin to use DLL number 12 instead of 13. +version 1.2.5beta1 [August 6, 2002] + Added code to contrib/gregbook/readpng2.c to ignore unused chunks. + Replaced toucan.png in contrib/gregbook (it has been corrupt since 1.0.11) + Removed some stray *.o files from contrib/gregbook. + Changed png_error() to png_warning() about "Too much data" in pngpread.c + and about "Extra compressed data" in pngrutil.c. + Prevent png_ptr->pass from exceeding 7 in png_push_finish_row(). + Updated makefile.hpgcc + Updated png.c and pnggccrd.c handling of return from png_mmx_support() +version 1.2.5beta2 [August 15, 2002] + Only issue png_warning() about "Too much data" in pngpread.c when avail_in + is nonzero. + Updated makefiles to install a separate libpng.so.3 with its own rpath. +version 1.2.5rc1 and 1.0.15rc1 [August 24, 2002] + Revised makefiles to not remove previous minor versions of shared libraries. +version 1.2.5rc2 and 1.0.15rc2 [September 16, 2002] + Revised 13 makefiles to remove "-lz" and "-L$(ZLIBLIB)", etc., from shared + library loader directive. + Added missing "$OBJSDLL" line to makefile.gcmmx. + Added missing "; fi" to makefile.32sunu. +version 1.2.5rc3 and 1.0.15rc3 [September 18, 2002] + Revised libpng-config script. + +version 1.2.5 and 1.0.15 [October 3, 2002] + Revised makefile.macosx, makefile.darwin, makefile.hpgcc, and makefile.hpux, + and makefile.aix. + Relocated two misplaced PNGAPI lines in pngtest.c +version 1.2.6beta1 [October 22, 2002] + Commented out warning about uninitialized mmx_support in pnggccrd.c. + Changed "IBMCPP__" flag to "__IBMCPP__" in pngconf.h. + Relocated two more misplaced PNGAPI lines in pngtest.c + Fixed memory overrun bug in png_do_read_filler() with 16-bit datastreams, + introduced in version 1.0.2. + Revised makefile.macosx, makefile.dec, makefile.aix, and makefile.32sunu. +version 1.2.6beta2 [November 1, 2002] + Added libpng-config "--ldopts" output. + Added "AR=ar" and "ARFLAGS=rc" and changed "ar rc" to "$(AR) $(ARFLAGS)" + in makefiles. +version 1.2.6beta3 [July 18, 2004] + Reverted makefile changes from version 1.2.6beta2 and some of the changes + from version 1.2.6beta1; these will be postponed until version 1.2.7. + Version 1.2.6 is going to be a simple bugfix release. + Changed the one instance of "ln -sf" to "ln -f -s" in each Sun makefile. + Fixed potential overrun in pngerror.c by using strncpy instead of memcpy. + Added "#!/bin/sh" at the top of configure, for recognition of the + 'x' flag under Cygwin (Cosmin). + Optimized vacuous tests that silence compiler warnings, in png.c (Cosmin). + Added support for PNG_USER_CONFIG, in pngconf.h (Cosmin). + Fixed the special memory handler for Borland C under DOS, in pngmem.c + (Cosmin). + Removed some spurious assignments in pngrutil.c (Cosmin). + Replaced 65536 with 65536L, and 0xffff with 0xffffL, to silence warnings + on 16-bit platforms (Cosmin). + Enclosed shift op expressions in parentheses, to silence warnings (Cosmin). + Used proper type png_fixed_point, to avoid problems on 16-bit platforms, + in png_handle_sRGB() (Cosmin). + Added compression_type to png_struct, and optimized the window size + inside the deflate stream (Cosmin). + Fixed definition of isnonalpha(), in pngerror.c and pngrutil.c (Cosmin). + Fixed handling of unknown chunks that come after IDAT (Cosmin). + Allowed png_error() and png_warning() to work even if png_ptr == NULL + (Cosmin). + Replaced row_info->rowbytes with row_bytes in png_write_find_filter() + (Cosmin). + Fixed definition of PNG_LIBPNG_VER_DLLNUM (Simon-Pierre). + Used PNG_LIBPNG_VER and PNG_LIBPNG_VER_STRING instead of the hardcoded + values in png.c (Simon-Pierre, Cosmin). + Initialized png_libpng_ver[] with PNG_LIBPNG_VER_STRING (Simon-Pierre). + Replaced PNG_LIBPNG_VER_MAJOR with PNG_LIBPNG_VER_DLLNUM in png.rc + (Simon-Pierre). + Moved the definition of PNG_HEADER_VERSION_STRING near the definitions + of the other PNG_LIBPNG_VER_... symbols in png.h (Cosmin). + Relocated #ifndef PNGAPI guards in pngconf.h (Simon-Pierre, Cosmin). + Updated scripts/makefile.vc(a)win32 (Cosmin). + Updated the MSVC project (Simon-Pierre, Cosmin). + Updated the Borland C++ Builder project (Cosmin). + Avoided access to asm_flags in pngvcrd.c, if PNG_1_0_X is defined (Cosmin). + Commented out warning about uninitialized mmx_support in pngvcrd.c (Cosmin). + Removed scripts/makefile.bd32 and scripts/pngdef.pas (Cosmin). + Added extra guard around inclusion of Turbo C memory headers, in pngconf.h + (Cosmin). + Renamed projects/msvc/ to projects/visualc6/, and projects/borland/ to + projects/cbuilder5/ (Cosmin). + Moved projects/visualc6/png32ms.def to scripts/pngw32.def, + and projects/visualc6/png.rc to scripts/pngw32.rc (Cosmin). + Added projects/visualc6/pngtest.dsp; removed contrib/msvctest/ (Cosmin). + Changed line endings to DOS style in cbuilder5 and visualc6 files, even + in the tar.* distributions (Cosmin). + Updated contrib/visupng/VisualPng.dsp (Cosmin). + Updated contrib/visupng/cexcept.h to version 2.0.0 (Cosmin). + Added a separate distribution with "configure" and supporting files (Junichi). +version 1.2.6beta4 [July 28, 2004] + Added user ability to change png_size_t via a PNG_SIZE_T macro. + Added png_sizeof() and png_convert_size() functions. + Added PNG_SIZE_MAX (maximum value of a png_size_t variable. + Added check in png_malloc_default() for (size_t)size != (png_uint_32)size + which would indicate an overflow. + Changed sPLT failure action from png_error to png_warning and abandon chunk. + Changed sCAL and iCCP failures from png_error to png_warning and abandon. + Added png_get_uint_31(png_ptr, buf) function. + Added PNG_UINT_32_MAX macro. + Renamed PNG_MAX_UINT to PNG_UINT_31_MAX. + Made png_zalloc() issue a png_warning and return NULL on potential + overflow. + Turn on PNG_NO_ZALLOC_ZERO by default in version 1.2.x + Revised "clobber list" in pnggccrd.c so it will compile under gcc-3.4. + Revised Borland portion of png_malloc() to return NULL or issue + png_error() according to setting of PNG_FLAG_MALLOC_NULL_MEM_OK. + Added PNG_NO_SEQUENTIAL_READ_SUPPORTED macro to conditionally remove + sequential read support. + Added some "#if PNG_WRITE_SUPPORTED" blocks. + Removed some redundancy with #ifdef/#endif in png_malloc_default(). + Use png_malloc instead of png_zalloc to allocate the pallete. +version 1.0.16rc1 and 1.2.6rc1 [August 4, 2004] + Fixed buffer overflow vulnerability in png_handle_tRNS() + Fixed integer arithmetic overflow vulnerability in png_read_png(). + Fixed some harmless bugs in png_handle_sBIT, etc, that would cause + duplicate chunk types to go undetected. + Fixed some timestamps in the -config version + Rearranged order of processing of color types in png_handle_tRNS(). + Added ROWBYTES macro to calculate rowbytes without integer overflow. + Updated makefile.darwin and removed makefile.macosx from scripts directory. + Imposed default one million column, one-million row limits on the image + dimensions, and added png_set_user_limits() function to override them. + Revised use of PNG_SET_USER_LIMITS_SUPPORTED macro. + Fixed wrong cast of returns from png_get_user_width|height_max(). + Changed some "keep the compiler happy" from empty statements to returns, + Revised libpng.txt to remove 1.2.x stuff from the 1.0.x distribution +version 1.0.16rc2 and 1.2.6rc2 [August 7, 2004] + Revised makefile.darwin and makefile.solaris. Removed makefile.macosx. + Revised pngtest's png_debug_malloc() to use png_malloc() instead of + png_malloc_default() which is not supposed to be exported. + Fixed off-by-one error in one of the conversions to PNG_ROWBYTES() in + pngpread.c. Bug was introduced in 1.2.6rc1. + Fixed bug in RGB to RGBX transformation introduced in 1.2.6rc1. + Fixed old bug in RGB to Gray transformation. + Fixed problem with 64-bit compilers by casting arguments to abs() + to png_int_32. + Changed "ln -sf" to "ln -f -s" in three makefiles (solaris, sco, so9). + Changed "HANDLE_CHUNK_*" to "PNG_HANDLE_CHUNK_*" (Cosmin) + Added "-@/bin/rm -f $(DL)/$(LIBNAME).so.$(PNGMAJ)" to 15 *NIX makefiles. + Added code to update the row_info->colortype in png_do_read_filler() (MSB). +version 1.0.16rc3 and 1.2.6rc3 [August 9, 2004] + Eliminated use of "abs()" in testing cHRM and gAMA values, to avoid + trouble with some 64-bit compilers. Created PNG_OUT_OF_RANGE() macro. + Revised documentation of png_set_keep_unknown_chunks(). + Check handle_as_unknown status in pngpread.c, as in pngread.c previously. + Moved "PNG_HANDLE_CHUNK_*" macros out of PNG_INTERNAL section of png.h + Added "rim" definitions for CONST4 and CONST6 in pnggccrd.c +version 1.0.16rc4 and 1.2.6rc4 [August 10, 2004] + Fixed mistake in pngtest.c introduced in 1.2.6rc2 (declaration of + "pinfo" was out of place). +version 1.0.16rc5 and 1.2.6rc5 [August 10, 2004] + Moved "PNG_HANDLE_CHUNK_*" macros out of PNG_ASSEMBLER_CODE_SUPPORTED + section of png.h where they were inadvertently placed in version rc3. + +version 1.2.6 and 1.0.16 [August 15, 2004] + Revised pngtest so memory allocation testing is only done when PNG_DEBUG==1. +version 1.2.7beta1 [August 26, 2004] + Removed unused pngasmrd.h file. + Removed references to uu.net for archived files. Added references to + PNG Spec (second edition) and the PNG ISO/IEC Standard. + Added "test-dd" target in 15 makefiles, to run pngtest in DESTDIR. + Fixed bug with "optimized window size" in the IDAT datastream, that + causes libpng to write PNG files with incorrect zlib header bytes. +version 1.2.7beta2 [August 28, 2004] + Fixed bug with sCAL chunk and big-endian machines (David Munro). + Undid new code added in 1.2.6rc2 to update the color_type in + png_set_filler(). + Added png_set_add_alpha() that updates color type. +version 1.0.17rc1 and 1.2.7rc1 [September 4, 2004] + Revised png_set_strip_filler() to not remove alpha if color_type has alpha. + +version 1.2.7 and 1.0.17 [September 12, 2004] + Added makefile.hp64 + Changed projects/msvc/png32ms.def to scripts/png32ms.def in makefile.cygwin +version 1.2.8beta1 [November 1, 2004] + Fixed bug in png_text_compress() that would fail to complete a large block. + Fixed bug, introduced in libpng-1.2.7, that overruns a buffer during + strip alpha operation in png_do_strip_filler(). + Added PNG_1_2_X definition in pngconf.h + Comment out with #ifdef/#endif png_info_init in png.c and png_read_init + in pngread.c (as of 1.3.0) +version 1.2.8beta2 [November 2, 2004] + Reduce color_type to a nonalpha type after strip alpha operation in + png_do_strip_filler(). +version 1.2.8beta3 [November 3, 2004] + Revised definitions of PNG_MAX_UINT_32, PNG_MAX_SIZE, and PNG_MAXSUM +version 1.2.8beta4 [November 12, 2004] + Fixed (again) definition of PNG_LIBPNG_VER_DLLNUM in png.h (Cosmin). + Added PNG_LIBPNG_BUILD_PRIVATE in png.h (Cosmin). + Set png_ptr->zstream.data_type to Z_BINARY, to avoid unnecessary detection + of data type in deflate (Cosmin). + Deprecated but continue to support SPECIALBUILD and PRIVATEBUILD in favor of + PNG_LIBPNG_BUILD_SPECIAL_STRING and PNG_LIBPNG_BUILD_PRIVATE_STRING. +version 1.2.8beta5 [November 20, 2004] + Use png_ptr->flags instead of png_ptr->transformations to pass + PNG_STRIP_ALPHA info to png_do_strip_filler(), to preserve ABI + compatibility. + Revised handling of SPECIALBUILD, PRIVATEBUILD, + PNG_LIBPNG_BUILD_SPECIAL_STRING and PNG_LIBPNG_BUILD_PRIVATE_STRING. +version 1.2.8rc1 [November 24, 2004] + Moved handling of BUILD macros from pngconf.h to png.h + Added definition of PNG_LIBPNG_BASE_TYPE in png.h, inadvertently + omitted from beta5. + Revised scripts/pngw32.rc + Despammed mailing addresses by masking "@" with "at". + Inadvertently installed a supposedly faster test version of pngrutil.c +version 1.2.8rc2 [November 26, 2004] + Added two missing "\" in png.h + Change tests in pngread.c and pngpread.c to + if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA)) + png_do_read_transformations(png_ptr); +version 1.2.8rc3 [November 28, 2004] + Reverted pngrutil.c to version libpng-1.2.8beta5. + Added scripts/makefile.elf with supporting code in pngconf.h for symbol + versioning (John Bowler). +version 1.2.8rc4 [November 29, 2004] + Added projects/visualc7 (Simon-pierre). +version 1.2.8rc5 [November 29, 2004] + Fixed new typo in scripts/pngw32.rc + +version 1.2.8 [December 3, 2004] + Removed projects/visualc7, added projects/visualc71. + +version 1.2.9beta1 [February 21, 2006] + + Initialized some structure members in pngwutil.c to avoid gcc-4.0.0 complaints + Revised man page and libpng.txt to make it clear that one should not call + png_read_end or png_write_end after png_read_png or png_write_png. + Updated references to png-mng-implement mailing list. + Fixed an incorrect typecast in pngrutil.c + Added PNG_NO_READ_SUPPORTED conditional for making a write-only library. + Added PNG_NO_WRITE_INTERLACING_SUPPORTED conditional. + Optimized alpha-inversion loops in pngwtran.c + Moved test for nonzero gamma outside of png_build_gamma_table() in pngrtran.c + Make sure num_trans is <= 256 before copying data in png_set_tRNS(). + Make sure num_palette is <= 256 before copying data in png_set_PLTE(). + Interchanged order of write_swap_alpha and write_invert_alpha transforms. + Added parentheses in the definition of PNG_LIBPNG_BUILD_TYPE (Cosmin). + Optimized zlib window flag (CINFO) in contrib/pngsuite/*.png (Cosmin). + Updated scripts/makefile.bc32 for Borland C++ 5.6 (Cosmin). + Exported png_get_uint_32, png_save_uint_32, png_get_uint_16, png_save_uint_16, + png_get_int_32, png_save_int_32, png_get_uint_31 (Cosmin). + Added type cast (png_byte) in png_write_sCAL() (Cosmin). + Fixed scripts/makefile.cygwin (Christian Biesinger, Cosmin). + Default iTXt support was inadvertently enabled. + +version 1.2.9beta2 [February 21, 2006] + + Check for png_rgb_to_gray and png_gray_to_rgb read transformations before + checking for png_read_dither in pngrtran.c + Revised checking of chromaticity limits to accommodate extended RGB + colorspace (John Denker). + Changed line endings in some of the project files to CRLF, even in the + "Unix" tar distributions (Cosmin). + Made png_get_int_32 and png_save_int_32 always available (Cosmin). + Updated scripts/pngos2.def, scripts/pngw32.def and projects/wince/png32ce.def + with the newly exported functions. + Eliminated distributions without the "configure" script. + Updated INSTALL instructions. + +version 1.2.9beta3 [February 24, 2006] + + Fixed CRCRLF line endings in contrib/visupng/VisualPng.dsp + Made libpng.pc respect EXEC_PREFIX (D. P. Kreil, J. Bowler) + Removed reference to pngasmrd.h from Makefile.am + Renamed CHANGES to ChangeLog. + Renamed LICENSE to COPYING. + Renamed ANNOUNCE to NEWS. + Created AUTHORS file. + +version 1.2.9beta4 [March 3, 2006] + + Changed definition of PKGCONFIG from $prefix/lib to $libdir in configure.ac + Reverted to filenames LICENSE and ANNOUNCE; removed AUTHORS and COPYING. + Removed newline from the end of some error and warning messages. + Removed test for sqrt() from configure.ac and configure. + Made swap tables in pngtrans.c PNG_CONST (Carlo Bramix). + Disabled default iTXt support that was inadvertently enabled in + libpng-1.2.9beta1. + Added "OS2" to list of systems that don't need underscores, in pnggccrd.c + Removed libpng version and date from *.c files. + +version 1.2.9beta5 [March 4, 2006] + Removed trailing blanks from source files. + Put version and date of latest change in each source file, and changed + copyright year accordingly. + More cleanup of configure.ac, Makefile.am, and associated scripts. + Restored scripts/makefile.elf which was inadvertently deleted. + +version 1.2.9beta6 [March 6, 2006] + Fixed typo (RELEASE) in configuration files. + +version 1.2.9beta7 [March 7, 2006] + Removed libpng.vers and libpng.sym from libpng12_la_SOURCES in Makefile.am + Fixed inconsistent #ifdef's around png_sig_bytes() and png_set_sCAL_s() + in png.h. + Updated makefile.elf as suggested by debian. + Made cosmetic changes to some makefiles, adding LN_SF and other macros. + Made some makefiles accept "exec_prefix". + +version 1.2.9beta8 [March 9, 2006] + Fixed some "#if defined (..." which should be "#if defined(..." + Bug introduced in libpng-1.2.8. + Fixed inconsistency in definition of png_default_read_data() + Restored blank that was lost from makefile.sggcc "clean" target in beta7. + Revised calculation of "current" and "major" for irix in ltmain.sh + Changed "mkdir" to "MKDIR_P" in some makefiles. + Separated PNG_EXPAND and PNG_EXPAND_tRNS. + Added png_set_expand_gray_1_2_4_to_8() and deprecated + png_set_gray_1_2_4_to_8() which also expands tRNS to alpha. + +version 1.2.9beta9 [March 10, 2006] + Include "config.h" in pngconf.h when available. + Added some checks for NULL png_ptr or NULL info_ptr (timeless) + +version 1.2.9beta10 [March 20, 2006] + Removed extra CR from contrib/visualpng/VisualPng.dsw (Cosmin) + Made pnggccrd.c PIC-compliant (Christian Aichinger). + Added makefile.mingw (Wolfgang Glas). + Revised pngconf.h MMX checking. + +version 1.2.9beta11 [March 22, 2006] + Fixed out-of-order declaration in pngwrite.c that was introduced in beta9 + Simplified some makefiles by using LIBSO, LIBSOMAJ, and LIBSOVER macros. + +version 1.2.9rc1 [March 31, 2006] + Defined PNG_USER_PRIVATEBUILD when including "pngusr.h" (Cosmin). + Removed nonsensical assertion check from pngtest.c (Cosmin). + +version 1.2.9 [April 14, 2006] + Revised makefile.beos and added "none" selector in ltmain.sh + +version 1.2.10beta1 [April 15, 2006] + Renamed "config.h" to "png_conf.h" and revised Makefile.am to add + -DPNG_BUILDING_LIBPNG to compile directive, and modified pngconf.h + to include png_conf.h only when PNG_BUILDING_LIBPNG is defined. + +version 1.2.10beta2 [April 15, 2006] + Manually updated Makefile.in and configure. Changed png_conf.h.in + back to config.h. + +version 1.2.10beta3 [April 15, 2006] + Change png_conf.h back to config.h in pngconf.h. + +version 1.2.10beta4 [April 16, 2006] + Change PNG_BUILDING_LIBPNG to PNG_CONFIGURE_LIBPNG in config/Makefile*. + +version 1.2.10beta5 [April 16, 2006] + Added a configure check for compiling assembler code in pnggccrd.c + +version 1.2.10beta6 [April 17, 2006] + Revised the configure check for pnggccrd.c + Moved -DPNG_CONFIGURE_LIBPNG into @LIBPNG_DEFINES@ + Added @LIBPNG_DEFINES@ to arguments when building libpng.sym + +version 1.2.10beta7 [April 18, 2006] + Change "exec_prefix=$prefix" to "exec_prefix=$(prefix)" in makefiles. + +version 1.2.10rc1 [April 19, 2006] + Ensure pngconf.h doesn't define both PNG_USE_PNGGCCRD and PNG_USE_PNGVCRD + Fixed "LN_FS" typo in makefile.sco and makefile.solaris. + +version 1.2.10rc2 [April 20, 2006] + Added a backslash between -DPNG_CONFIGURE_LIBPNG and -DPNG_NO_ASSEMBLER_CODE + in configure.ac and configure + Made the configure warning about versioned symbols less arrogant. + +version 1.2.10rc3 [April 21, 2006] + Added a note in libpng.txt that png_set_sig_bytes(8) can be used when + writing an embedded PNG without the 8-byte signature. + Revised makefiles and configure to avoid making links to libpng.so.* + +version 1.2.10 [April 23, 2006] + Reverted configure to "rc2" state. + +version 1.2.11beta1 [May 31, 2006] + scripts/libpng.pc.in contained "configure" style version info and would + not work with makefiles. + The shared-library makefiles were linking to libpng.so.0 instead of + libpng.so.3 compatibility as the library. + +version 1.2.11beta2 [June 2, 2006] + Increased sprintf buffer from 50 to 52 chars in pngrutil.c to avoid + buffer overflow. + Fixed bug in example.c (png_set_palette_rgb -> png_set_palette_to_rgb) + +version 1.2.11beta3 [June 5, 2006] + Prepended "#! /bin/sh" to ltmail.sh and contrib/pngminus/*.sh (Cosmin). + Removed the accidental leftover Makefile.in~ (Cosmin). + Avoided potential buffer overflow and optimized buffer in + png_write_sCAL(), png_write_sCAL_s() (Cosmin). + Removed the include directories and libraries from CFLAGS and LDFLAGS + in scripts/makefile.gcc (Nelson A. de Oliveira, Cosmin). + +version 1.2.11beta4 [June 6, 2006] + Allow zero-length IDAT chunks after the entire zlib datastream, but not + after another intervening chunk type. + +version 1.0.19rc1, 1.2.11rc1 [June 13, 2006] + Deleted extraneous square brackets from [config.h] in configure.ac + +version 1.0.19rc2, 1.2.11rc2 [June 14, 2006] + Added prototypes for PNG_INCH_CONVERSIONS functions to png.h + Revised INSTALL and autogen.sh + Fixed typo in several makefiles (-W1 should be -Wl) + Added typedef for png_int_32 and png_uint_32 on 64-bit systems. + +version 1.0.19rc3, 1.2.11rc3 [June 15, 2006] + Removed the new typedefs for 64-bit systems (delay until version 1.4.0) + Added one zero element to png_gamma_shift[] array in pngrtran.c to avoid + reading out of bounds. + +version 1.0.19rc4, 1.2.11rc4 [June 15, 2006] + Really removed the new typedefs for 64-bit systems. + +version 1.0.19rc5, 1.2.11rc5 [June 22, 2006] + Removed png_sig_bytes entry from scripts/pngw32.def + +version 1.0.19, 1.2.11 [June 26, 2006] + None. + +version 1.0.20, 1.2.12 [June 27, 2006] + Really increased sprintf buffer from 50 to 52 chars in pngrutil.c to avoid + buffer overflow. + +version 1.2.13beta1 [October 2, 2006] + Removed AC_FUNC_MALLOC from configure.ac + Work around Intel-Mac compiler bug by setting PNG_NO_MMX_CODE in pngconf.h + Change "logical" to "bitwise" throughout documentation. + Detect and fix attempt to write wrong iCCP profile length. + +version 1.0.21, 1.2.13 [November 14, 2006] + Fix potential buffer overflow in sPLT chunk handler. + Fix Makefile.am to not try to link to noexistent files. + Check all exported functions for NULL png_ptr. + +version 1.2.14beta1 [November 17, 2006] + Relocated three misplaced tests for NULL png_ptr. + Built Makefile.in with automake-1.9.6 instead of 1.9.2. + Build configure with autoconf-2.60 instead of 2.59 + +version 1.2.14beta2 [November 17, 2006] + Added some typecasts in png_zalloc(). + +version 1.2.14rc1 [November 20, 2006] + Changed "strtod" to "png_strtod" in pngrutil.c + +version 1.0.22, 1.2.14 [November 27, 2006] + Added missing "$(srcdir)" in Makefile.am and Makefile.in + +version 1.2.15beta1 [December 3, 2006] + Generated configure with autoconf-2.61 instead of 2.60 + Revised configure.ac to update libpng.pc and libpng-config. + +version 1.2.15beta2 [December 3, 2006] + Always export MMX asm functions, just stubs if not building pnggccrd.c + +version 1.2.15beta3 [December 4, 2006] + Add "png_bytep" typecast to profile while calculating length in pngwutil.c + +version 1.2.15beta4 [December 7, 2006] + Added scripts/CMakeLists.txt + Changed PNG_NO_ASSEMBLER_CODE to PNG_NO_MMX_CODE in scripts, like 1.4.0beta + +version 1.2.15beta5 [December 7, 2006] + Changed some instances of PNG_ASSEMBLER_* to PNG_MMX_* in pnggccrd.c + Revised scripts/CMakeLists.txt + +version 1.2.15beta6 [December 13, 2006] + Revised scripts/CMakeLists.txt and configure.ac + +version 1.2.15rc1 [December 18, 2006] + Revised scripts/CMakeLists.txt + +version 1.2.15rc2 [December 21, 2006] + Added conditional #undef jmpbuf in pngtest.c to undo #define in AIX headers. + Added scripts/makefile.nommx + +version 1.2.15rc3 [December 25, 2006] + Fixed shared library numbering error that was introduced in 1.2.15beta6. + +version 1.2.15rc4 [December 27, 2006] + Fixed handling of rgb_to_gray when png_ptr->color.gray isn't set. + +version 1.2.15rc5 [December 31, 2006] + Revised handling of rgb_to_gray. + +version 1.0.23, 1.2.15 [January 5, 2007] + Added some (unsigned long) typecasts in pngtest.c to avoid printing errors. + +version 1.2.16beta1 [January 6, 2007] + Fix bugs in makefile.nommx + +version 1.2.16beta2 [January 16, 2007] + Revised scripts/CMakeLists.txt + +version 1.0.24, 1.2.16 [January 31, 2007] + No changes. + +version 1.2.17beta1 [March 6, 2007] + Revised scripts/CMakeLists.txt to install both shared and static libraries. + Deleted a redundant line from pngset.c. + +version 1.2.17beta2 [April 26, 2007] + Relocated misplaced test for png_ptr == NULL in pngpread.c + Change "==" to "&" for testing PNG_RGB_TO_GRAY_ERR & PNG_RGB_TO_GRAY_WARN + flags. + Changed remaining instances of PNG_ASSEMBLER_* to PNG_MMX_* + Added pngerror() when write_IHDR fails in deflateInit2(). + Added "const" to some array declarations. + Mention examples of libpng usage in the libpng*.txt and libpng.3 documents. + +version 1.2.17rc1 [May 4, 2007] + No changes. + +version 1.2.17rc2 [May 8, 2007] + Moved several PNG_HAVE_* macros out of PNG_INTERNAL because applications + calling set_unknown_chunk_location() need them. + Changed transformation flag from PNG_EXPAND_tRNS to PNG_EXPAND in + png_set_expand_gray_1_2_4_to_8(). + Added png_ptr->unknown_chunk to hold working unknown chunk data, so it + can be free'ed in case of error. Revised unknown chunk handling in + pngrutil.c and pngpread.c to use this structure. + +version 1.2.17rc3 [May 8, 2007] + Revised symbol-handling in configure script. + +version 1.2.17rc4 [May 10, 2007] + Revised unknown chunk handling to avoid storing unknown critical chunks. + +version 1.0.25 [May 15, 2007] +version 1.2.17 [May 15, 2007] + Added "png_ptr->num_trans=0" before error return in png_handle_tRNS, + to eliminate a vulnerability (CVE-2007-2445, CERT VU#684664) + +version 1.0.26 [May 15, 2007] +version 1.2.18 [May 15, 2007] + Reverted the libpng-1.2.17rc3 change to symbol-handling in configure script + +version 1.2.19beta1 [May 18, 2007] + Changed "const static" to "static PNG_CONST" everywhere, mostly undoing + change of libpng-1.2.17beta2. Changed other "const" to "PNG_CONST" + Changed some handling of unused parameters, to avoid compiler warnings. + "if (unused == NULL) return;" becomes "unused = unused". + +version 1.2.19beta2 [May 18, 2007] + Only use the valid bits of tRNS value in png_do_expand() (Brian Cartier) + +version 1.2.19beta3 [May 19, 2007] + Add some "png_byte" typecasts in png_check_keyword() and write new_key + instead of key in zTXt chunk (Kevin Ryde). + +version 1.2.19beta4 [May 21, 2007] + Add png_snprintf() function and use it in place of sprint() for improved + defense against buffer overflows. + +version 1.2.19beta5 [May 21, 2007] + Fixed png_handle_tRNS() to only use the valid bits of tRNS value. + Changed handling of more unused parameters, to avoid compiler warnings. + Removed some PNG_CONST in pngwutil.c to avoid compiler warnings. + +version 1.2.19beta6 [May 22, 2007] + Added some #ifdef PNG_MMX_CODE_SUPPORTED where needed in pngvcrd.c + Added a special "_MSC_VER" case that defines png_snprintf to _snprintf + +version 1.2.19beta7 [May 22, 2007] + Squelched png_squelch_warnings() in pnggccrd.c and added + an #ifdef PNG_MMX_CODE_SUPPORTED/#endif block around the declarations + that caused the warnings that png_squelch_warnings was squelching. + +version 1.2.19beta8 [May 22, 2007] + Removed __MMX__ from test in pngconf.h. + +version 1.2.19beta9 [May 23, 2007] + Made png_squelch_warnings() available via PNG_SQUELCH_WARNINGS macro. + Revised png_squelch_warnings() so it might work. + Updated makefile.sgcc and makefile.solaris; added makefile.solaris-x86. + +version 1.2.19beta10 [May 24, 2007] + Resquelched png_squelch_warnings(), use "__attribute__((used))" instead. + +version 1.2.19beta11 [May 28, 2007] + Return 0 from png_get_sPLT() and png_get_unknown_chunks() if png_ptr is NULL; + changed three remaining instances of png_strcpy() to png_strncpy() (David + Hill). + Make test for NULL row_buf at the beginning of png_do_read_transformations + unconditional. + +version 1.2.19beta12 [May 28, 2007] + Revised pnggccrd.c. + +version 1.2.19beta13 [June 14, 2007] + Prefer PNG_USE_PNGVCRD when _MSC_VER is defined in pngconf.h + +version 1.2.19beta14 [June 16, 2007] + Fix bug with handling of 16-bit transparency, introduced in 1.2.19beta2 + +version 1.2.19beta15 [June 17, 2007] + Revised pnggccrd.c. + +version 1.2.19beta16 [June 18, 2007] + Revised pnggccrd.c again. + Updated contrib/gregbook. + Changed '#include "pnggccrd.c"' to 'include "$srcdir/pnggccrd.c"' + in configure.ac + +version 1.2.19beta17 [June 19, 2007] + Revised many of the makefiles, to set -DPNG_NO_MMX_CODE where needed + and to not use -O3 unless -DPNG_NO_MMX_CODE is also set. + +version 1.2.19beta18 [June 23, 2007] + Replaced some C++ style comments with C style comments in pnggccrd.c. + Copied optimized C code from pnggccrd.c to pngrutil.c, removed dependency + on pnggccrd.o from many makefiles. + Added sl and dylib to list of extensions be installed by Makefile.am + +version 1.2.19beta19 [June 28, 2007] + Fixed testing PNG_RGB_TO_GRAY_ERR & PNG_RGB_TO_GRAY_WARN in pngrtran.c + More cleanup of pnggccrd.c and pngvcrd.c + +version 1.2.19beta20 [June 29, 2007] + Rebuilt Makefile.in and configure using libtool-1.5.24. + Fixed typo in pnggccrd.c + +version 1.2.19beta21 [June 30, 2007] + More revision of pnggccrd.c + Added "test" target to Makefile.in and Makefile.am + +version 1.2.19beta22 [July 3, 2007] + Added info about pngrutil/pnggccrd/pngvcrd to png_get_header_version() + Fix type definition of dummy_value_a, b in pnggccrd.c + +version 1.2.19beta23 [July 10, 2007] + Revert change to type definition of dummy_value_a, b in pnggccrd.c + Make sure __PIC__ is defined in pnggccrd.c when PIC is defined. + Require gcc-4.1 or better to use PNG_HAVE_MMX_FILTER_ROW on x86_64 platforms + +version 1.2.19beta24 [July 14, 2007] + Added PNG_NO_READ_FILTER, PNG_NO_WRITE_FILTER, PNG_NO_WARNING macros. + Added contrib/pngminim to demonstrate building minimal encoder and decoder + +version 1.2.19beta25 [July 15, 2007] + Removed the new PNG_NO_READ_FILTER macro since it would make the library + unable to read valid PNG files, and filtering is at the heart of the + PNG format. + +version 1.2.19beta26 [July 16, 2007] + Changed "png_free(str)" to "png_free(png_ptr,str)" in pngrutil.c WinCE + code (Yves Piguet). This bug was introduced in libpng-1.2.14. + Updated scripts/CMakeLists.txt + Relocated a misplaced #endif in pnggccrd.c + +version 1.2.19beta27 [July 17, 2007] + Fixed incorrect stride and number of bytes copied (was 4 instead of + 6 bytes) in the cleanup loop of pnggccrd.c and pngvcrd.c for handling + the end of 48-bit interlaced rows (Glenn R-P). + +version 1.2.19beta28 [July 19, 2007] + Removed requirement for gcc-4.1 or better to use PNG_HAVE_MMX_FILTER_ROW + on x86_64 platforms + Added png_warning() in pngrutil.c for short iCCP, iTXt, sPLT, or zTXT chunks. + Revised pngtest.c so warnings are displayed regardless of PNG_NO_STDIO. + +version 1.2.19beta29 [July 20, 2007] + Fix typo in pnggccrd.c (%%eax should be %%ax in secondloop48) + +version 1.2.19beta30 [July 26, 2007] + Revised pnggccrd.c + +version 1.2.19beta31 [July 27, 2007] + Fix typos in pnggccrd.c + +version 1.0.27rc1 and 1.2.19rc1 [July 31, 2007] + Disable PNG_MMX_CODE_SUPPORTED when PNG_ASSEMBLER_CODE_SUPPORTED is off. + Enable PNG_MMX_READ_FILTER_* by default, except when gcc-3.x is being + used (they were inadvertently disabled in libpng-1.2.19beta23). + Fix some debugging statements in pnggccrd.c and pngrutil.c + Added information about disabling the MMX code in libpng documentation. + +version 1.0.27rc2 and 1.2.19rc2 [August 4, 2007] + Removed some "#if 0" blocks. + Made a global struct local in pngvcrd.c to make it thread safe. + Issue a png_error() if application attempts to transform a row tht + has not been initialized. + +version 1.0.27rc3 and 1.2.19rc3 [August 9, 2007] + Slightly revised pngvcrd.c + +version 1.0.27rc4 and 1.2.19rc4 [August 9, 2007] + Revised pnggccrd.c debugging change of rc1, which was broken. + Revised scripts/CMakeLists.txt + Change default to PNG_NO_GLOBAL_ARRAYS for MSVC. + Turn off PNG_FLAG_ROW_INIT flag when setting transforms that expand pixels. + +version 1.0.27rc5 and 1.2.19rc5 [August 10, 2007] + Fix typo (missing '"') in pnggccrd.c + Revise handling of png_strtod in recent versions of WINCE + +version 1.0.27rc6 and 1.2.19rc6 [August 15, 2007] + Fix typo (missing ',') in contrib/gregbook/readpng2.c + Undid row initialization error exit added to rc2 and rc4. + +version 1.0.27 and 1.2.19 [August 18, 2007] + Conditionally restored row initialization error exit. + +version 1.2.20beta01 [August 19, 2007] + Fixed problem with compiling pnggccrd.c on Intel-Apple platforms. + Changed png_malloc() to png_malloc_warn() in png_set_sPLT(). + Added PNG_NO_ERROR_TEXT feature, with demo in contrib/pngminim + Removed define PNG_WARN_UNINITIALIZED_ROW 1 /* 0: warning; 1: error */ + because it caused some trouble. + +version 1.2.20beta02 [August 20, 2007] + Avoid compiling pnggccrd.c on Intel-Apple platforms. + +version 1.2.20beta03 [August 20, 2007] + Added "/D PNG_NO_MMX_CODE" to the non-mmx builds of projects/visualc6 + and visualc71. + +version 1.2.20beta04 [August 21, 2007] + Revised pngvcrd.c for improved efficiency (Steve Snyder). + +version 1.2.20rc1 [August 23, 2007] + Revised pngconf.h to set PNG_NO_MMX_CODE for gcc-3.x compilers. + +version 1.2.20rc2 [August 27, 2007] + Revised scripts/CMakeLists.txt + Revised #ifdefs to ensure one and only one of pnggccrd.c, pngvcrd.c, + or part of pngrutil.c is selected. + +version 1.2.20rc3 [August 30, 2007] + Remove a little more code in pngwutil.c when PNG_NO_WRITE_FILTER is selected. + Added /D _CRT_SECURE_NO_WARNINGS to visual6c and visualc71 projects. + Compile png_mmx_support() in png.c even when PNG_NO_MMX_CODE is defined. + Restored a "superfluous" #ifdef that was removed from 1.2.20rc2 pnggccrd.c, + breaking the png_mmx_support() function. + +version 1.2.20rc4 [September 1, 2007] + Removed Intel contributions (MMX, Optimized C). + +version 1.2.20rc5 [September 2, 2007] + Restored configure and Makefile.in to rc3 and put a snippet of code in + pnggccrd.c, to ensure configure makes the same PNG_NO_MMX_CODE selection + +version 1.2.20rc6 [September 2, 2007] + Fixed bugs in scripts/CMakeLists.txt + Removed pngvcrd.c references from msvc projects. + +version 1.0.28 and 1.2.20 [September 8, 2007] + Removed "(NO READ SUPPORT)" from png_get_header_version() string. + +version 1.2.21beta1 [September 14, 2007] + Fixed various mistakes reported by George Cook and Jeff Phillips: + logical vs bitwise NOT in pngrtran.c, bug introduced in 1.2.19rc2 + 16-bit cheap transparency expansion, bug introduced in 1.2.19beta2 + errors with sizeof(unknown_chunk.name), bugs introduced in 1.2.19beta11 + <= compare with unsigned var in pngset.c, should be ==. + +version 1.2.21beta2 [September 18, 2007] + Removed some extraneous typecasts. + +version 1.2.21rc1 [September 25, 2007] + Fixed potential out-of-bounds reads in png_handle_pCAL() and + png_handle_ztXt() ("flayer" results reported by Tavis Ormandy). + +version 1.2.21rc2 [September 26, 2007] + Fixed potential out-of-bounds reads in png_handle_sCAL(), + png_handle_iTXt(), and png_push_read_tEXt(). + Remove some PNG_CONST declarations from pngwutil.c to avoid compiler warnings + Revised makefiles to update paths in libpng.pc properly. + +version 1.2.21rc3 [September 27, 2007] + Revised makefiles to update "Libs" in libpng.pc properly. + +version 1.0.29 and 1.2.21rc3 [October 4, 2007] + No changes. + +version 1.2.22beta1 [October 4, 2007] + Again, fixed logical vs bitwise NOT in pngrtran.c, bug introduced + in 1.2.19rc2 + +version 1.2.22beta2 [October 5, 2007] + Fixed string length error in pngset.c (caused crashes while decoding iCCP) + Add terminating NULL after each instance of png_strncpy(). + +version 1.2.22beta3 [October 6, 2007] + Fix two off-by-one terminating NULL after png_strncpy(). + +version 1.2.22beta4 [October 7, 2007] + Changed some 0 to '\0'. + +version 1.0.30rc1 and 1.2.22rc1 [October 8, 2007] + No changes. + +version 1.0.30 and 1.2.22 [October 13, 2007] + No changes. + +version 1.2.23beta01 [October 15, 2007] + Reduced number of invocations of png_strlen() in pngset.c. + Changed [azAZ09_] to [_abcde...89] in Makefile.am for better localization. + +version 1.2.23beta02 [October 16, 2007] + Eliminated png_strncpy() and png_strcpy() (Pierre Poissinger) + Changed $AN to $(AN) in Makefile.am. + +version 1.2.23beta03 [October 16, 2007] + Fixed off-by-one error in pngset.c + Restore statement to set last character of buffer to \0 in pngerror.c + +version 1.2.23beta04 [October 23, 2007] + Reject attempt to set all-zero cHRM values. + +version 1.2.23beta05 [October 26, 2007] + Add missing quotes in projects/visualc6, lost in version 1.2.20rc3 + +version 1.2.23rc01 [November 2, 2007] + No changes. + +version 1.2.23 [November 6, 2007] + No changes. + +version 1.2.24beta01 [November 19, 2007] + Moved misplaced test for malloc failure in png_set_sPLT(). This bug was + introduced in libpng-1.2.20beta01. + Ifdef out avg_row etc from png.h and pngwrite.c when PNG_NO_WRITE_FILTER + Do not use png_ptr->free_fn and png_ptr->mem_fn in png_destroy_read_struct() + when png_ptr is NULL (Marshall Clow). + Updated handling of symbol prefixes in Makefile.am and configure.ac (Mike + Frysinger). + +version 1.2.24beta02 [November 30, 2007] + Removed a useless test and fixed incorrect test in png_set_cHRM_fixed() + (David Hill). + +version 1.2.24rc01 [December 7, 2007] + No changes. + +version 1.2.24 [December 14, 2007] + Make sure not to redefine _BSD_SOURCE in pngconf.h + Revised gather.sh and makefile.std in contrib/pngminim to avoid compiling + unused files. + +version 1.2.25beta01 [January 7, 2008] + Fixed bug with unknown chunk handling, introduced in version 1.2.17rc2 + +version 1.2.25beta02 [January 10, 2008] + Prevent gamma from being applied twice. + +version 1.2.25rc01 [January 17, 2008] + No changes. + +version 1.2.25beta03 [January 22, 2008] + Fixed some continue-after-malloc-failure errors in pngset.c (David Hill) + Check for info_ptr == NULL in png_read_info() and png_process_data(). + Check for possible use of NULL user_png_ver[] in png_create_read_struct(). + Change "if (swidth == NULL)" to "if (sheight == NULL)" in png_handle_sCAL + (bug introduced in libpng-1.2.4/1.0.13). + Return from png_destroy_read_struct() if png_ptr_ptr is NULL. + Fix overflow of "msg" in png_decompress_chunk(). + +version 1.2.25beta04 [January 26, 2008] + Work around Coverity bug report by slightly refactoring + png_read_push_finish_row() + +version 1.2.25beta05 [January 31, 2008] + Added libpng-1.2.25beta05.tar.lzma to distribution. Get the lzma codec + from . + Added lp1225b05.7z to distribution. Get the 7-zip decoder from + from . + Fixed some broken links in the README file. + +version 1.2.25beta06 [February 6, 2008] + Refactored png_read_push_finish_row() again, trying to satisfy Coverity. + Fixed potential NULL dereference of png_ptr in png_destroy_write_struct(); + clarified potential NULL dereference of png_ptr in png_destroy_read_struct(); + fixed potential NULL dereference of info_ptr in png_handle_bKGD(); + fixed potential NULL dereference of user_png_ver[] in + png_create_write_struct_2(). (Coverity) + +version 1.2.25rc02 [February 10, 2008] + Reset png_ptr->pass in png_read_push_finish_row() before break. + Changed "pass" from png_byte to int. + +version 1.2.25 and 1.0.31 [February 18, 2008] + No changes. + +version 1.2.26beta01 [February 21, 2008] + Added missing "(" in pngmem.c. Bug introduced in libpng-1.2.2/1.0.13 + +version 1.2.26beta02 [March 12, 2008] + Refined error message returned from deflateInit2 in pngwutil.c + Check IHDR length in png_push_read_chunk() before saving it. + +version 1.2.26beta03 [March 16, 2008] + Revised contrib/gregbook to handle premature end-of-file and file + read errors correctly. + +version 1.2.26beta04 [March 18, 2008] + Free png_ptr->big_row_buf and png_ptr->prev_row before allocating + new copies in png_read_start_row(). Bug introduced in libpng-1.2.22. + +version 1.2.26beta05 [March 19, 2008] + Removed extra png_free() added in libpng-1.2.26beta04. + +version 1.2.26beta06 [March 19, 2008] + Avoid reallocating big_row_buf and prev_row when the size does not increase. + +version 1.2.26rc01 [March 26, 2008] + Ifdef out some code that is unused when interlacing is not supported. + +versions 1.0.32 and 1.2.26 [April 2, 2008] + No changes. + +version 1.2.27beta01 [April 12, 2008] + Fixed bug (introduced in libpng-1.0.5h) with handling zero-length + unknown chunks. + Added more information about png_set_keep_unknown_chunks() to the + documentation. + Reject tRNS chunk with out-of-range samples instead of masking off + the invalid high bits as done in since libpng-1.2.19beta5. + +version 1.2.27beta02 [April 13, 2008] + Revised documentation about unknown chunk and user chunk handling. + Keep tRNS chunk with out-of-range samples and issue a png_warning(). + +version 1.2.27beta03 [April 14, 2008] + Added check for NULL ptr in TURBOC version of png_free_default(). + Removed several unnecessary checks for NULL before calling png_free(). + Revised png_set_tRNS() so that calling it twice removes and invalidates + the previous call. + Revised pngtest to check for out-of-range tRNS samples. + +version 1.2.27beta04 [April 18, 2008] + Added AC_LIBTOOL_WIN32_DLL to configure.ac + Rebuilt Makefile.in, aclocal.m4, and configure with autoconf-2.62 + +version 1.2.27beta05 [April 19, 2008] + Added MAINTAINERCLEANFILES variable to Makefile.am + +version 1.2.27beta06 [April 21, 2008] + Avoid changing color_type from GRAY to RGB by + png_set_expand_gray_1_2_4_to_8(). + +version 1.2.27rc01 [April 23, 2008] + Fix broken URL for rfc2083 in png.5 and libpng-*.txt + +version 1.0.33 and 1.2.27 [April 30, 2008] + No changes. + +version 1.0.34 and 1.2.28 [April 30, 2008] + Rebuilt Makefile.in, aclocal.m4, and configure with autoconf-2.61 + due to backward incompatibilities. + Removed a stray object file from contrib/gregbook + +version 1.2.29beta01 [May 1, 2008] + Removed some stray *.diff and *.orig files + +version 1.2.29beta02 [May 1, 2008] + Reverted Makefile.in, aclocal.m4, and configure to the libpng-1.2.26 + versions. + +version 1.2.29beta03 [May 2, 2008] + Added --force to autogen libtoolize options and --force-missing to + automake options. + Changed $(ECHO) to echo in Makefile.am and Makefile.in + Updated all configure files to autoconf-2.62 + Comment out pnggcrd.c code with #ifdef/#endif if using MSC_VER + +version 1.2.29rc01 [May 4, 2008] + No changes. + +version 1.0.35 and 1.2.29 [May 8, 2008] + No changes. + +version 1.0.37 [May 9, 2008] + Updated Makefile.in and configure (omitted version 1.0.36). + +version 1.2.30beta01 [May 29, 2008] + Updated libpng.pc-configure.in and libpng-config.in per debian bug reports. + +version 1.2.30beta02 [June 25, 2008] + Restored png_flush(png_ptr) at the end of png_write_end(), that was + removed from libpng-1.0.9beta03. + +version 1.2.30beta03 [July 6, 2008] + Merged some cosmetic whitespace changes from libpng-1.4.0beta19. + Inline call of png_get_uint_32() in png_get_uint_31(), as in 1.4.0beta19. + Added demo of decoding vpAg and sTER chunks to pngtest.c, from 1.4.0beta19. + Changed PNGMAJ from 0 to 12 in makefile.darwin, which does not like 0. + Added new private function png_read_chunk_header() from 1.4.0beta19. + Merge reading of chunk length and chunk type into a single 8-byte read. + Merge writing of chunk length and chunk type into a single 8-byte write. + +version 1.2.30beta04 [July 10, 2008] + Merged more cosmetic whitespace changes from libpng-1.4.0beta19. + +version 1.0.38rc01, 1.2.30rc01 [July 18, 2008] + No changes. + +version 1.0.38rc02, 1.2.30rc02 [July 21, 2008] + Moved local array "chunkdata" from pngrutil.c to the png_struct, so + it will be freed by png_read_destroy() in case of a read error (Kurt + Christensen). + +version 1.0.38rc03, 1.2.30rc03 [July 21, 2008] + Changed "purpose" and "buffer" to png_ptr->chunkdata to avoid memory leaking. + +version 1.0.38rc04, 1.2.30rc04 [July 22, 2008] + Changed "chunkdata = NULL" to "png_ptr->chunkdata = NULL" several places in + png_decompress_chunk(). + +version 1.0.38rc05, 1.2.30rc05 [July 25, 2008] + Changed all remaining "chunkdata" to "png_ptr->chunkdata" in + png_decompress_chunk() and remove chunkdata from parameter list. + Put a call to png_check_chunk_name() in png_read_chunk_header(). + Revised png_check_chunk_name() to reject a name with a lowercase 3rd byte. + Removed two calls to png_check_chunk_name() occuring later in the process. + +version 1.0.38rc06, 1.2.30rc06 [July 29, 2008] + Added a call to png_check_chunk_name() in pngpread.c + Reverted png_check_chunk_name() to accept a name with a lowercase 3rd byte. + +version 1.0.38r07, 1.2.30r07 [August 2, 2008] + Changed "-Wall" to "-W -Wall" in the CFLAGS in all makefiles (Cosmin Truta) + Declared png_ptr "volatile" in pngread.c and pngwrite.c to avoid warnings. + Added code in pngset.c to quiet compiler warnings. + Updated contrib/visupng/cexcept.h to version 2.0.1 + Relocated a misplaced "#endif /* PNG_NO_WRITE_FILTER */" in pngwutil.c + +version 1.0.38r08, 1.2.30r08 [August 2, 2008] + Enclose "volatile" declarations in #ifdef PNG_SETJMP_SUPPORTED (Cosmin). + +version 1.0.38, 1.2.30 [August 14, 2008] + No changes. + +version 1.2.31rc01 [August 19, 2008] + Removed extra crc check at the end of png_handle_cHRM(). Bug introduced + in libpng-1.2.30beta03 (Heiko Nitzsche). + +version 1.2.31rc02 [August 19, 2008] + Added PNG_WRITE_FLUSH_SUPPORTED block around new png_flush() call. + +version 1.2.31rc03 [August 19, 2008] + Added PNG_WRITE_FLUSH_AFTER_IEND_SUPPORTED block, off by default, around + new png_flush(). + +version 1.0.39, 1.2.31 [August 21, 2008] + No changes. + +version 1.2.32beta01 [September 6, 2008] + Shortened tIME_string to 29 bytes in pngtest.c (bug introduced in + libpng-1.2.22). + Fixed off-by-one error introduced in png_push_read_zTXt() function in + libpng-1.2.30beta04/pngpread.c (Harald van Dijk) + These bugs have been given the vulnerability id CVE-2008-3964. + +version 1.0.40, 1.2.32 [September 18, 2008] + No changes. + +version 1.2.33beta01 [October 6, 2008] + Revised makefile.darwin to fix shared library numbering. + Change png_set_gray_1_2_4_to_8() to png_set_expand_gray_1_2_4_to_8() + in example.c (debian bug report) + +version 1.2.33rc01 [October 15, 2008] + No changes. + +version 1.0.41rc01, version 1.2.33rc02 [October 23, 2008] + Changed remaining "key" to "png_ptr->chunkdata" in png_handle_tEXt() + to avoid memory leak after memory failure while reading tEXt chunk.` + +version 1.2.33 [October 31, 2008] + No changes. + +version 1.2.34beta01 [November 27, 2008] + Revised png_warning() to write its message on standard output by default + when warning_fn is NULL. This was the behavior prior to libpng-1.2.9beta9. + Fixed string vs pointer-to-string error in png_check_keyword(). + Added png_check_cHRM_fixed() in png.c and moved checking from pngget.c, + pngrutil.c, and pngwrite.c, and eliminated floating point cHRM checking. + Added check for zero-area RGB cHRM triangle in png_check_cHRM_fixed(). + In png_check_cHRM_fixed(), ensure white_y is > 0, and removed redundant + check for all-zero coordinates that is detected by the triangle check. + Revised png_warning() to write its message on standard output by default + when warning_fn is NULL. + +version 1.2.34beta02 [November 28, 2008] + Corrected off-by-one error in bKGD validity check in png_write_bKGD() + and in png_handle_bKGD(). + +version 1.2.34beta03 [December 1, 2008] + Revised bKGD validity check to use >= x instead of > x + 1 + Merged with png_debug from libpng-1.4.0 to remove newlines. + +version 1.2.34beta04 [December 2, 2008] + More merging with png_debug from libpng-1.4.0 to remove newlines. + +version 1.2.34beta05 [December 5, 2008] + Removed redundant check for key==NULL before calling png_check_keyword() + to ensure that new_key gets initialized and removed extra warning + (Arvan Pritchard). + +version 1.2.34beta06 [December 9, 2008] + In png_write_png(), respect the placement of the filler bytes in an earlier + call to png_set_filler() (Jim Barry). + +version 1.2.34beta07 [December 9, 2008] + Undid previous change and added PNG_TRANSFORM_STRIP_FILLER_BEFORE and + PNG_TRANSFORM_STRIP_FILLER_AFTER conditionals and deprecated + PNG_TRANSFORM_STRIP_FILLER (Jim Barry). + +version 1.0.42rc01, 1.2.34rc01 [December 11, 2008] + No changes. + +version 1.0.42, 1.2.34 [December 18, 2008] + No changes. + +version 1.2.35beta01 [February 4, 2009] + Zero out some arrays of pointers after png_malloc(). (Tavis Ormandy) + +version 1.2.35beta02 [February 4, 2009] + Zero out more arrays of pointers after png_malloc(). + +version 1.2.35beta03 [February 5, 2009] + Use png_memset() instead of a loop to intialize pointers. We realize + this will not work on platforms where the NULL pointer is not all zeroes. + +version 1.2.35rc01 [February 11, 2009] + No changes. + +version 1.2.35rc02 [February 12, 2009] + Fix typo in new png_memset call in pngset.c (png_color should be png_charp) + +version 1.0.43 and 1.2.35 [February 14, 2009] + No changes. + +version 1.2.36beta01 [February 28, 2009] + Revised comments in png_set_read_fn() and png_set_write_fn(). + Revised order of #ifdef's and indentation in png_debug definitions of png.h + bug introduced in libpng-1.2.34. + +version 1.2.36beta02 [March 21, 2009] + Use png_memset() after png_malloc() of big_row_buf when reading an + interlaced file, to avoid a possible UMR. + Undid recent revision of PNG_NO_STDIO version of png_write_flush(). Users + having trouble with fflush() can build with PNG_NO_WRITE_FLUSH defined. + Revised libpng*.txt documentation about use of png_write_flush(). + Removed fflush() from pngtest.c. + Added "#define PNG_NO_WRITE_FLUSH" to contrib/pngminim/encoder/pngusr.h + +version 1.2.36beta03 [March 27, 2009] + Relocated misplaced PNG_1_0_X define in png.h that caused the prototype + for png_set_strip_error_numbers() to be omitted from PNG_NO_ASSEMBLER_CODE + builds. This bug was introduced in libpng-1.2.15beta4. + Added a section on differences between 1.0.x and 1.2.x to libpng.3/libpng.txt + +version 1.2.36beta04 [April 5, 2009] + Fixed potential memory leak of "new_name" in png_write_iCCP() (Ralph Giles) + +version 1.2.36beta05 [April 24, 2009] + Added "ifndef PNG_SKIP_SETJMP_CHECK" block in pngconf.h to allow + application code writers to bypass the check for multiple inclusion + of setjmp.h when they know that it is safe to ignore the situation. + Made some cosmetic changes to whitespace in pngtest output. + Renamed "user_chunk_data" to "my_user_chunk_data" in pngtest.c to suppress + "shadowed declaration" warning from gcc-4.3.3. + Renamed "gamma" to "png_gamma" in pngset.c to avoid "shadowed declaration" + warning about a global "gamma" variable in math.h on some platforms. + +version 1.2.36rc01 [April 30, 2009] + No changes. + +version 1.0.44 and 1.2.36 [May 7, 2009] + No changes. + +version 1.2.37beta01 [May 14, 2009] + Fixed inconsistency in pngrutil.c, introduced in libpng-1.2.36. The + memset() was using "png_ptr->rowbytes" instead of "row_bytes", which + the corresponding png_malloc() uses (Joe Drew). + Clarified usage of sig_bit versus sig_bit_p in example.c (Vincent Torri) + Updated some of the makefiles in the scripts directory (merged with + those in libpng-1.4.0beta57). + +version 1.2.37beta02 [May 19, 2009] + Fixed typo in libpng documentation (FILTER_AVE should be FILTER_AVG) + Relocated misplaced #endif in pngwrite.c, sCAL chunk handler. + Conditionally compile png_read_finish_row() which is not used by + progressive readers. + Added contrib/pngminim/preader to demonstrate building minimal progressive + decoder, based on contrib/gregbook with embedded libpng and zlib. + +version 1.2.37beta03 [May 20, 2009] + In contrib/pngminim/*, renamed "makefile.std" to "makefile", since there + is only one makefile in those directories, and revised the README files + accordingly. + Reformated sources in libpng style (3-space indentation, comment format) + +version 1.2.37rc01 [May 27, 2009] + No changes. + +versions 1.2.37 and 1.0.45 [June 4, 2009] + Reformatted several remaining "else statement;" and "if () statement;" into + two lines. + Added "#define PNG_NO_WRITE_SWAP" to contrib/pngminim/encoder/pngusr.h + and "define PNG_NO_READ_SWAP" to decoder/pngusr.h and preader/pngusr.h + Added sections about the git repository and our coding style to the + documentation (merged from libpng-1.4.0beta62) + Added a section to the libpng documentation about using png_get_io_ptr() + in configure scripts to detect the presence of libpng. + +version 1.2.38beta01 [June 17, 2009] + Revised libpng*.txt and libpng.3 to mention calling png_set_IHDR() + multiple times and to specify the sample order in the tRNS chunk, + because the ISO PNG specification has a typo in the tRNS table. + Changed several PNG_UNKNOWN_CHUNK_SUPPORTED to + PNG_HANDLE_AS_UNKNOWN_SUPPORTED, to make the png_set_keep mechanism + available for ignoring known chunks even when not saving unknown chunks. + Adopted preference for consistent use of "#ifdef" and "#ifndef" versus + "#if defined()" and "if !defined()" where possible. + Added PNG_NO_HANDLE_AS_UNKNOWN in the PNG_LEGACY_SUPPORTED block of + pngconf.h, and moved the various unknown chunk macro definitions + outside of the PNG_READ|WRITE_ANCILLARY_CHUNK_SUPPORTED blocks. + +version 1.0.46 [June 18, 2009] + Removed some editing cruft from scripts/libpng.pc.in and some makefiles. + +version 1.2.38rc01 [June 24, 2009] + No changes. + +version 1.2.38rc02 [June 29, 2009] + Added a reference to the libpng license in each source file. + +version 1.2.38rc03 [July 11, 2009] + Revised references to the libpng license in pngconf.h and contrib/visupng + source files. + Rebuilt configure scripts with autoconf-2.63. + +version 1.0.47 and 1.2.38 [July 16, 2009] + No changes. + +version 1.2.39beta01 [July 25, 2009] + Added a prototype for png_64bit_product() in png.c + +version 1.2.39beta02 [July 27, 2009] + Avoid a possible NULL dereference in debug build, in png_set_text_2(). + (bug introduced in libpng-0.95, discovered by Evan Rouault) + +version 1.2.39beta03 [July 29, 2009] + Relocated new png_64_bit_product() prototype into png.h + Expanded the information about prototypes in the libpng style section of + the documentation. + Rebuilt configure scripts with autoconf-2.64. + +version 1.2.39beta04 [August 1, 2009] + Replaced *.tar.lzma with *.txz in distribution. Get the xz codec + from . + +version 1.2.39beta05 [August 1, 2009] + Reject attempt to write iCCP chunk with negative embedded profile length + (JD Chen) + +version 1.2.39c01 [August 6, 2009] + No changes. + +version 1.2.39 and 1.0.48 [August 13, 2009] + No changes. + +version 1.2.40beta01 [August 20, 2009] + Removed an extra png_debug() recently added to png_write_find_filter(). + Fixed incorrect #ifdef in pngset.c regarding unknown chunk support. + +version 1.2.40rc01 [September 2, 2009] + Various bugfixes and improvements to CMakeLists.txt (Philip Lowman) + +version 1.2.40 and 1.0.49 [September 2, 2009] + No changes. + +version 1.0.50 [September 10, 2009] + Removed some editing cruft from pngset.c and pngwutil.c. + +version 1.2.41beta01 [September 25, 2009] + Moved redundant IHDR checking into new png_check_IHDR() in png.c + and report all errors found in the IHDR data. + Eliminated useless call to png_check_cHRM() from pngset.c + Expanded TAB characters in pngrtran.c + +version 1.2.41beta02 [September 30, 2009] + Revised png_check_IHDR(). + +version 1.2.41beta03 [October 1, 2009] + Revised png_check_IHDR() again, to check info_ptr members instead of + the contents of the returned parameters. + +version 1.2.41beta04 [October 7, 2009] + Added "xcode" project similar one already in libpng-1.4.0beta (Alam Arias). + Ported some cosmetic changes from libpng-1.4.0beta86. + Eliminated a shadowed declaration of "pp" in png_handle_sPLT(). + +version 1.2.41beta05 [October 17, 2009] + Revised pngconf.h to make it easier to enable iTXt support. From libpng + version 1.2.9 through 1.2.40, defining PNG_iTXt_SUPPORTED did not work + as expected. + Ported some cosmetic changes from libpng-1.4.0beta87, changing + many "#if defined(x)" to "#ifdef x". + +version 1.2.41beta06 [October 18, 2009] + Restored PNG_USE_LOCAL_ARRAYS code in pngread.c that was inadvertently + deleted in libpng-1.2.41beta05. + Converted all PNG_NO_* tests to PNG_*_SUPPORTED everywhere except pngconf.h + as in libpng-1.4.0beta78 and later. + +version 1.2.41beta07 [October 21, 2009] + Ported some cosmetic changes from libpng-1.4.0rc01, changing + many "#if defined(x)" to "#ifdef x" in png.h and pngconf.h. + +version 1.2.41beta08 [October 30, 2009] + Ported from libpng-1.4.0rc01: png_calloc(), png_get_io_chunk_name(), + png_get_io_state(), png_set_user_cache_max(), png_get_user_cache_max(), + png_set_premultiply_alpha, and png_do_read_premultiply_alpha(). + Relocated png_do_chop() ahead of building gamma tables in pngrtran.c + This avoids building 16-bit gamma tables unnecessarily. + +version 1.2.41beta09 [November 1, 2009] + Removed a harmless extra png_set_invert_alpha() from pngwrite.c + More bugfixes and improvements to CMakeLists.txt (Philip Lowman) + Moved CMakeLists.txt from scripts into the main libpng directory. + Apply png_user_chunk_cache_max within png_decompress_chunk(). + Merged libpng-1.2.41.txt with libpng-1.4.0.txt where appropriate. + +version 1.2.41beta10 [November 1, 2009] + Enabled iTXt support by default. To ensure binary compatibility with + previous versions, the "lang" and "lang_key" members will be assumed + to be omitted from previous versions unless the current libpng + version was built with PNG_iTXt_SUPPORTED (which is otherwise no + longer necessary to gain iTXt support), as a signal that the user has + been building previous versions with PNG_iTXt_SUPPORTED as well. + +version 1.2.41beta11 [November 2, 2009] + Store user's user_png_ver in new png_ptr->user_png_ver element. + Revised iTXt support. To ensure binary compatibility with + previous versions, the "lang" and "lang_key" members will be assumed + to be omitted from versions prior to 1.2.41beta11 whenever there is a + library mismatch. + +version 1.2.41beta12 [November 2, 2009] + Free png_ptr->user_png_ver when destroying png_ptr. + +version 1.2.41beta13 [November 3, 2009] + Updated scripts/pngw32.def and projects/wince/png32ce.def + Copied projects/wince/png32ce.def to the scripts directory. + Added scripts/makefile.wce + Patched ltmain.sh for wince support. + Added PNG_CONVERT_tIME_SUPPORTED macro. + +version 1.2.41beta14 [November 8, 2009] + versions 1.2.41beta05 through 1.2.41beta13 were abandoned. + The 1.0.x/1.2.x series will only receive security updates from now on. + Make inclusion of time.h in pngconf.h depend on PNG_CONVERT_tIME_SUPPORTED + Make #define PNG_CONVERT_tIME_SUPPORTED depend on PNG_WRITE_tIME_SUPPORTED + Reverted iTXt compatibility stuff from 1.2.41beta05, 1.2.41beta11, and + 1.2.41beta12. + Reverted IOSTATE feature, user_cache_max, and premultiply_alpha features + from 1.2.41beta08. + Retained png_calloc() from 1.2.41beta08 but as a non-exported function, + and removed reference to png_calloc from scripts/*.def + +version 1.2.41beta15 [November 8, 2009] + Added PNG_DEPSTRUCT, PNG_DEPRECATED, PNG_USE_RESULT, PNG_NORETURN, and + PNG_ALLOCATED macros to detect deprecated direct access to the + png_struct or info_struct members and other deprecated usage in + applications (John Bowler). + Updated scripts/makefile* to add "-DPNG_CONFIGURE_LIBPNG" to CFLAGS, + to prevent warnings about direct access to png structs by libpng + functions while building libpng. They need to be tested, especially + those using compilers other than gcc. + Updated projects/visualc6 and visualc71 with "/d PNG_CONFIGURE_LIBPNG". + +version 1.2.41beta16 [November 9, 2009] + Removed three direct references to read_info_ptr members in pngtest.c + that were detected by the new PNG_DEPSTRUCT macro. + Only #define PNG_DEPSTRUCT, etc. in pngconf.h if not already defined. + +version 1.2.41beta17 [November 10, 2009] + Updated CMakeLists.txt to add "-DPNG_CONFIGURE_LIBPNG" to the definitions. + Marked deprecated function prototypes with PNG_DEPRECATED. + Marked memory allocation function prototypes with PNG_ALLOCATED. + Changed png_check_sig() to !png_sig_cmp() in contrib programs. + Corrected the png_get_IHDR() call in contrib/gregbook/readpng2.c + Added "-DPNG_CONFIGURE_LIBPNG" to the contrib/pngminum makefiles. + +version 1.2.41beta18 [November 11, 2009] + Renamed scripts/makefile.wce to scripts/makefile.cegcc + Marked nonexported functions with PNG_PRIVATE macro. + +version 1.2.41rc01 and 1.0.51rc01 [November 18, 2009] + Revised scripts/*.def to reflect functions actually exported by libpng. + Updated the copyright year in scripts/pngw32.rc from 2004 to 2009. + Moved descriptions of makefiles and other scripts out of INSTALL into + scripts/README.txt + +version 1.2.41rc02 [November 22, 2009] + Rebuilt the configure scripts with autoconf-2.65 + +version 1.2.41rc03 [November 25, 2009] + Disabled the new pedantic warnings about deprecated function use + and deprecated structure access unless the user defines + PNG_PEDANTIC_WARNINGS. + Added "#define PNG_NO_PEDANTIC_WARNINGS" in the libpng source files. + Removed "-DPNG_CONFIGURE_LIBPNG" from the makefiles and projects. + +version 1.2.41 and 1.0.51 [December 3, 2009] + Updated the list of files and made some cosmetic changes in README. + +version 1.2.42beta01 [December 4, 2009] + Removed "#define PNG_NO_ERROR_NUMBERS" that was inadvertently added + to pngconf.h in version 1.2.41. + Revised scripts/makefile.netbsd, makefile.openbsd, and makefile.sco + to put png.h and pngconf.h in $prefix/include, like the other scripts, + instead of in $prefix/include/libpng. Also revised makefile.sco + to put them in $prefix/include/libpng12 instead of in + $prefix/include/libpng/libpng12. + Removed leftover "-DPNG_CONFIGURE_LIBPNG" from scripts/makefile.darwin + +version 1.2.42beta02 [December 11, 2009] + Removed leftover "-DPNG_CONFIGURE_LIBPNG" from contrib/pngminim/*/makefile + Relocated png_do_chop() to its original position in pngrtran.c. The + change in version 1.2.41beta08 caused transparency to be handled wrong + in some 16-bit datastreams (Yusaku Sugai). + +version 1.2.42rc01 [December 17, 2009] + No changes. + +version 1.2.42rc02 [December 22, 2009] + Renamed libpng-pc.in back to libpng.pc.in and revised CMakeLists.txt + (revising changes made in 1.2.41beta17 and 1.2.41rc01) + +version 1.2.42rc03 [December 25, 2009] + Swapped PNG_UNKNOWN_CHUNKS_SUPPORTED and PNG_HANDLE_AS_UNKNOWN_SUPPORTED + in pngset.c to be consistent with other changes in version 1.2.38. + +version 1.2.42rc04 [January 1, 2010] + Marked png_memcpy_check() and png_memset_check() PNG_DEPRECATED. + Updated copyright year. + +version 1.2.42rc05 [January 2, 2010] + Avoid deprecated references to png_ptr-io_ptr and png_ptr->error_ptr + in pngtest.c + +version 1.2.42 and 1.0.52 [January 3, 2010] + No changes. + +version 1.2.43beta01 [January 27, 2010] + Updated CMakeLists.txt for consistent indentation and to avoid an + unclosed if-statement warning (Philip Lowman). + Removed "#ifdef PNG_1_0_X / #endif" surrounding + PNG_READ_16_TO_8_SUPPORTED and PNG_READ_GRAY_TO_RGB_SUPPORTED + in pngconf.h. These were added in libpng-1.2.41beta08 and libpng-1.0.51, + which introduced a binary incompatibility with libpng-1.0.50. + Backported new png_decompress_chunk() algorithm from libpng-1.4.1. + +version 1.2.43beta02 [February 1, 2010] + Backported two-pass png_decompress_chunk() algorithm from libpng-1.4.1. + +version 1.2.43beta03 [February 6, 2010] + Backported fast png_push_save_buffer() algorithm from libpng-1.4.1. + Backported some cosmetic changes from libpng-1.4.1. + +version 1.2.43beta04 [February 8, 2010] + Reverted recent changes to png_push_save-buffer(). + Removed PNGAPI declaration of png_calloc() and png_write_sig() in + 1ibpng-1.2.X, introduced by mistake in libpng-1.2.41. + Return allocated "old_buffer" in png_push_save_buffer() before png_error() + to avoid a potential memory leak. + +version 1.2.43beta05 [February 8, 2010] + Ported rewritten png_decompress_chunk() by John Bowler from libpng-1.4.1. + +version 1.0.53rc01 and 1.2.43rc01 [February 18, 2010] + No changes. + +version 1.0.53rc02 and 1.2.43rc02 [February 19, 2010] + Define _ALL_SOURCE in configure.ac, makefile.aix, and CMakeLists.txt + when using AIX compiler. + +version 1.0.53 and 1.2.43 [February 25, 2010] + Removed unused gzio.c from contrib/pngminim gather and makefile scripts + +version 1.2.44beta01 [June 18, 2010] + In pngpread.c: png_push_have_row() add check for new_row > height + Removed the now-redundant check for out-of-bounds new_row from example.c + +version 1.2.44beta02 [June 19, 2010] + In pngpread.c: png_push_process_row() add check for too many rows. + Removed the now-redundant check for new_row > height in png_push_have_row(). + +version 1.2.44beta03 [June 20, 2010] + Rewrote png_process_IDAT_data() to consistently treat extra data as warnings + and handle end conditions more cleanly. + Removed the new (beta02) check in png_push_process_row(). + +version 1.2.44rc01 [June 21, 2010] + Revised some comments in png_process_IDAT_data(). + +version 1.2.44rc02 [June 22, 2010] + Stop memory leak when reading a malformed sCAL chunk. + +version 1.2.44rc03 [June 23, 2010] + Revised pngpread.c patch of beta05 to avoid an endless loop. + +version 1.2.44 [June 26, 2010] + Updated some of the "last changed" dates. + +version 1.2.45beta01 [June 7, 2011] + Fixed uninitialized memory read in png_format_buffer() (Bug + report by Frank Busse, related to CVE-2004-0421). + Pass "" instead of '\0' to png_default_error() in png_err(). This mistake + was introduced in libpng-1.2.20beta01. + Check for up->location !PNG_AFTER_IDAT when writing unknown chunks + before IDAT. + Ported bugfix in pngrtran.c from 1.5.3: when expanding a paletted image, + always expand to RGBA if transparency is present. + +version 1.2.45beta02 [June 8, 2011] + Check for integer overflow in png_set_rgb_to_gray(). + +version 1.2.45beta03 [June 19, 2011] + Check for sCAL chunk too short. + +version 1.2.45rc01 and 1.0.55rc01 [June 30, 2011] + Updated "last changed" dates and copyright year. + +version 1.2.45 and 1.0.55 [July 7, 2011] + No changes. + +version 1.2.46rc01 and 1.0.56rc01 [July 8, 2011] + Reverted changes to Makefile.am and Makefile.in to libpng-1.2.44 versions. + +version 1.2.46rc02 and 1.0.56rc02 [July 8, 2011] + Added CMakeLists.txt, projects/xcode, and pnggccrd.c to EXTRA_DIST in + Makefile.am and Makefile.in + +version 1.2.46 and 1.0.56 [July 9, 2011] + Udated copyright year to 2011. + +Send comments/corrections/commendations to png-mng-implement at lists.sf.net +(subscription required; visit +https://lists.sourceforge.net/lists/listinfo/png-mng-implement +to subscribe) +or to glennrp at users.sourceforge.net + +Glenn R-P +*/ diff --git a/libs/libpng-src/CMakeLists.txt b/libs/libpng-src/CMakeLists.txt new file mode 100644 index 000000000..a3ab4649b --- /dev/null +++ b/libs/libpng-src/CMakeLists.txt @@ -0,0 +1,284 @@ +cmake_minimum_required(VERSION 2.4.3) +set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true) + +if(UNIX AND NOT DEFINED CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING + "Choose the type of build, options are: + None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) + Debug + Release + RelWithDebInfo + MinSizeRel.") +endif() + +project(libpng C) +enable_testing() + +# Copyright (C) 2007-2010 Glenn Randers-Pehrson + +# This code is released under the libpng license. +# For conditions of distribution and use, see the disclaimer +# and license in png.h + +set(PNGLIB_MAJOR 1) +set(PNGLIB_MINOR 2) +set(PNGLIB_RELEASE 46) +set(PNGLIB_NAME libpng${PNGLIB_MAJOR}${PNGLIB_MINOR}) +set(PNGLIB_VERSION ${PNGLIB_MAJOR}.${PNGLIB_MINOR}.${PNGLIB_RELEASE}) + +# needed packages +find_package(ZLIB REQUIRED) +include_directories(${ZLIB_INCLUDE_DIR}) + +if(NOT WIN32) + find_library(M_LIBRARY + NAMES m + PATHS /usr/lib /usr/local/lib + ) + if(NOT M_LIBRARY) + message(STATUS + "math library 'libm' not found - floating point support disabled") + endif() +else() + # not needed on windows + set(M_LIBRARY "") +endif() + +# COMMAND LINE OPTIONS +if(DEFINED PNG_SHARED) + option(PNG_SHARED "Build shared lib" ${PNG_SHARED}) +else() + option(PNG_SHARED "Build shared lib" ON) +endif() +if(DEFINED PNG_STATIC) + option(PNG_STATIC "Build static lib" ${PNG_STATIC}) +else() + option(PNG_STATIC "Build static lib" ON) +endif() + +if(MINGW) + option(PNG_TESTS "Build pngtest" NO) +else() + option(PNG_TESTS "Build pngtest" YES) +endif() + +option(PNG_NO_CONSOLE_IO "FIXME" YES) +option(PNG_NO_STDIO "FIXME" YES) +option(PNG_DEBUG "Build with debug output" NO) +option(PNGARG "FIXME" YES) +#TODO: +# PNG_CONSOLE_IO_SUPPORTED + +# maybe needs improving, but currently I don't know when we can enable what :) +set(png_asm_tmp "OFF") +if(NOT WIN32) + find_program(uname_executable NAMES uname PATHS /bin /usr/bin /usr/local/bin) + if(uname_executable) + exec_program(${uname_executable} + ARGS --machine OUTPUT_VARIABLE uname_output) + if("uname_output" MATCHES "^.*i[1-9]86.*$") + set(png_asm_tmp "ON") + else("uname_output" MATCHES "^.*i[1-9]86.*$") + set(png_asm_tmp "OFF") + endif("uname_output" MATCHES "^.*i[1-9]86.*$") + endif(uname_executable) +else() + # this env var is normally only set on win64 + set(TEXT "ProgramFiles(x86)") + if("$ENV{${TEXT}}" STREQUAL "") + set(png_asm_tmp "ON") + endif("$ENV{${TEXT}}" STREQUAL "") +endif() + +# SET LIBNAME +set(PNG_LIB_NAME png${PNGLIB_MAJOR}${PNGLIB_MINOR}) + +# to distinguish between debug and release lib +set(CMAKE_DEBUG_POSTFIX "d") + + +# OUR SOURCES +set(libpng_sources + png.h + pngconf.h + png.c + pngerror.c + pngget.c + pngmem.c + pngpread.c + pngread.c + pngrio.c + pngrtran.c + pngrutil.c + pngset.c + pngtrans.c + pngwio.c + pngwrite.c + pngwtran.c + pngwutil.c +) +set(pngtest_sources + pngtest.c +) +# SOME NEEDED DEFINITIONS + +add_definitions(-DPNG_CONFIGURE_LIBPNG) + +if(_AIX) + add_definitions(-D_ALL_SOURCE) +endif(_AIX) + +if(MSVC) + add_definitions(-DPNG_NO_MODULEDEF -D_CRT_SECURE_NO_DEPRECATE) +endif(MSVC) + +if(PNG_SHARED OR NOT MSVC) + #if building msvc static this has NOT to be defined + add_definitions(-DZLIB_DLL) +endif() + +add_definitions(-DLIBPNG_NO_MMX) +add_definitions(-DPNG_NO_MMX_CODE) + + +if(PNG_CONSOLE_IO_SUPPORTED) + add_definitions(-DPNG_CONSOLE_IO_SUPPORTED) +endif() + +if(PNG_NO_CONSOLE_IO) + add_definitions(-DPNG_NO_CONSOLE_IO) +endif() + +if(PNG_NO_STDIO) + add_definitions(-DPNG_NO_STDIO) +endif() + +if(PNG_DEBUG) + add_definitions(-DPNG_DEBUG) +endif() + +if(NOT M_LIBRARY AND NOT WIN32) + add_definitions(-DPNG_NO_FLOATING_POINT_SUPPORTED) +endif() + +# NOW BUILD OUR TARGET +include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${ZLIB_INCLUDE_DIR}) + +if(PNG_SHARED) + add_library(${PNG_LIB_NAME} SHARED ${libpng_sources}) + if(MSVC) + # msvc does not append 'lib' - do it here to have consistent name + set_target_properties(${PNG_LIB_NAME} PROPERTIES PREFIX "lib") + endif() + target_link_libraries(${PNG_LIB_NAME} ${ZLIB_LIBRARY} ${M_LIBRARY}) +endif() + +if(PNG_STATIC) +# does not work without changing name + set(PNG_LIB_NAME_STATIC ${PNG_LIB_NAME}_static) + add_library(${PNG_LIB_NAME_STATIC} STATIC ${libpng_sources}) + if(MSVC) + # msvc does not append 'lib' - do it here to have consistent name + set_target_properties(${PNG_LIB_NAME_STATIC} PROPERTIES PREFIX "lib") + endif() +endif() + + +if(PNG_SHARED AND WIN32) + set_target_properties(${PNG_LIB_NAME} PROPERTIES DEFINE_SYMBOL PNG_BUILD_DLL) +endif() + +if(PNG_TESTS AND PNG_SHARED) + # does not work with msvc due to png_lib_ver issue + add_executable(pngtest ${pngtest_sources}) + target_link_libraries(pngtest ${PNG_LIB_NAME}) + add_test(pngtest pngtest ${CMAKE_CURRENT_SOURCE_DIR}/pngtest.png) +endif() + + +# CREATE PKGCONFIG FILES +# we use the same files like ./configure, so we have to set its vars +set(prefix ${CMAKE_INSTALL_PREFIX}) +set(exec_prefix ${CMAKE_INSTALL_PREFIX}) +set(libdir ${CMAKE_INSTALL_PREFIX}/lib) +set(includedir ${CMAKE_INSTALL_PREFIX}/include) + +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/libpng.pc.in + ${CMAKE_CURRENT_BINARY_DIR}/libpng.pc) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/libpng-config.in + ${CMAKE_CURRENT_BINARY_DIR}/libpng-config) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/libpng.pc.in + ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/libpng-config.in + ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config) + +# SET UP LINKS +if(PNG_SHARED) + set_target_properties(${PNG_LIB_NAME} PROPERTIES +# VERSION 0.${PNGLIB_RELEASE}.1.2.46 + VERSION 0.${PNGLIB_RELEASE}.0 + SOVERSION 0 + CLEAN_DIRECT_OUTPUT 1) +endif() +if(PNG_STATIC) + if(NOT WIN32) + # that's uncool on win32 - it overwrites our static import lib... + set_target_properties(${PNG_LIB_NAME_STATIC} PROPERTIES + OUTPUT_NAME ${PNG_LIB_NAME} + CLEAN_DIRECT_OUTPUT 1) + endif() +endif() + +# INSTALL +if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL ) + if(PNG_SHARED) + install(TARGETS ${PNG_LIB_NAME} + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib) + endif() + if(PNG_STATIC) + install(TARGETS ${PNG_LIB_NAME_STATIC} + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib) + endif() +endif() + +if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL ) + install(FILES png.h pngconf.h DESTINATION include) + install(FILES png.h pngconf.h DESTINATION include/${PNGLIB_NAME}) +endif() +if(NOT SKIP_INSTALL_EXECUTABLES AND NOT SKIP_INSTALL_ALL ) + install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/libpng-config DESTINATION bin) + install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config + DESTINATION bin) +endif() +if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL ) + # Install man pages + install(FILES libpng.3 libpngpf.3 DESTINATION man/man3) + install(FILES png.5 DESTINATION man/man5) + # Install pkg-config files + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng.pc + DESTINATION lib/pkgconfig) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng-config + DESTINATION bin) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc + DESTINATION lib/pkgconfig) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config + DESTINATION bin) +endif() + +# what's with libpng.txt and all the extra files? + + +# UNINSTALL +# do we need this? + + +# DIST +# do we need this? + +# to create msvc import lib for mingw compiled shared lib +# pexports libpng.dll > libpng.def +# lib /def:libpng.def /machine:x86 + diff --git a/libs/libpng-src/INSTALL b/libs/libpng-src/INSTALL new file mode 100644 index 000000000..99e5ccc2a --- /dev/null +++ b/libs/libpng-src/INSTALL @@ -0,0 +1,163 @@ + +Installing libpng version 1.2.46 - July 9, 2011 + +On Unix/Linux and similar systems, you can simply type + + ./configure [--prefix=/path] + make check + make install + +and ignore the rest of this document. + +If configure does not work on your system and you have a reasonably +up-to-date set of tools, running ./autogen.sh before running ./configure +may fix the problem. You can also run the individual commands in +autogen.sh with the --force option, if supported by your version of +the tools. If you run 'libtoolize --force', though, this will replace +the distributed, patched, version of ltmain.sh with an unpatched version +and your shared library builds may fail to produce libraries with the +correct version numbers. + +Instead, you can use one of the custom-built makefiles in the +"scripts" directory + + cp scripts/makefile.system makefile + make test + make install + +The files that are presently available in the scripts directory +are listed and described in scripts/README.txt. + +Or you can use one of the "projects" in the "projects" directory. + +Before installing libpng, you must first install zlib, if it +is not already on your system. zlib can usually be found +wherever you got libpng. zlib can be placed in another directory, +at the same level as libpng. + +If you want to use "cmake" (see www.cmake.org), type + + cmake . -DCMAKE_INSTALL_PREFIX=/path + make + make install + +If your system already has a preinstalled zlib you will still need +to have access to the zlib.h and zconf.h include files that +correspond to the version of zlib that's installed. + +You can rename the directories that you downloaded (they +might be called "libpng-1.2.46" or "libpng12" and "zlib-1.2.3" +or "zlib123") so that you have directories called "zlib" and "libpng". + +Your directory structure should look like this: + + .. (the parent directory) + libpng (this directory) + INSTALL (this file) + README + *.h + *.c + CMakeLists.txt => "cmake" script + configuration files: + configure.ac, configure, Makefile.am, Makefile.in, + autogen.sh, config.guess, ltmain.sh, missing, + aclocal.m4, config.h.in, config.sub, + depcomp, install-sh, mkinstalldirs, test-pngtest.sh + contrib + gregbook + pngminim + pngminus + pngsuite + visupng + projects + cbuilder5 (Borland) + visualc6 (msvc) + visualc71 + xcode + scripts + makefile.* + *.def (module definition files) + pngtest.png + etc. + zlib + README + *.h + *.c + contrib + etc. + +If the line endings in the files look funny, you may wish to get the other +distribution of libpng. It is available in both tar.gz (UNIX style line +endings) and zip (DOS style line endings) formats. + +If you are building libpng with MSVC, you can enter the +libpng projects\visualc6 or visualc71 directory and follow the instructions +in README.txt. + +Otherwise enter the zlib directory and follow the instructions in zlib/README, +then come back here and run "configure" or choose the appropriate +makefile.sys in the scripts directory. + +Copy the file (or files) that you need from the +scripts directory into this directory, for example + + MSDOS example: copy scripts\makefile.msc makefile + UNIX example: cp scripts/makefile.std makefile + +Read the makefile to see if you need to change any source or +target directories to match your preferences. + +Then read pngconf.h to see if you want to make any configuration +changes. + +Then just run "make" which will create the libpng library in +this directory and "make test" which will run a quick test that reads +the "pngtest.png" file and writes a "pngout.png" file that should be +identical to it. Look for "9782 zero samples" in the output of the +test. For more confidence, you can run another test by typing +"pngtest pngnow.png" and looking for "289 zero samples" in the output. +Also, you can run "pngtest -m contrib/pngsuite/*.png" and compare +your output with the result shown in contrib/pngsuite/README. + +Most of the makefiles will allow you to run "make install" to +put the library in its final resting place (if you want to +do that, run "make install" in the zlib directory first if necessary). +Some also allow you to run "make test-installed" after you have +run "make install". + +If you encounter a compiler error message complaining about the +lines + + __png.h__ already includes setjmp.h; + __dont__ include it again.; + +this means you have compiled another module that includes setjmp.h, +which is hazardous because the two modules might not include exactly +the same setjmp.h. If you are sure that you know what you are doing +and that they are exactly the same, then you can comment out or +delete the two lines. Better yet, use the cexcept interface +instead, as demonstrated in contrib/visupng of the libpng distribution. + +Further information can be found in the README and libpng.txt +files, in the individual makefiles, in png.h, and the manual pages +libpng.3 and png.5. + + +Using the ./configure script -- 16 December 2002. +================================================= + + +The ./configure script should work compatibly with what scripts/makefile.* +did, however there are some options you need to add to configure explicitly, +which previously was done semi-automatically (if you didn't edit +scripts/makefile.* yourself, that is) + + +CFLAGS="-Wall -O -funroll-loops \ +-malign-loops=2 -malign-functions=2" ./configure --prefix=/usr/include \ +--with-pkgconfigdir=/usr/lib/pkgconfig --includedir=/usr/include + +You can alternatively specify --includedir=/usr/include, /usr/local/include, +/usr/include/png12, or whatever. + + diff --git a/libs/libpng-src/KNOWNBUG b/libs/libpng-src/KNOWNBUG new file mode 100644 index 000000000..28e83dfb0 --- /dev/null +++ b/libs/libpng-src/KNOWNBUG @@ -0,0 +1,22 @@ + +Known bugs in libpng version 1.2.46 + +1. February 23, 2006: The custom makefiles don't build libpng with -lz. + + STATUS: This is a subject of debate. The change will probably be made + as a part of a major overhaul of the makefiles in libpng version 1.4.0. + +2. February 24, 2006: The Makefile generated by the "configure" script + fails to install symbolic links + libpng12.so => libpng12.so.0.1.2.9betaN + that are generated by the custom makefiles. + +3. September 4, 2007: There is a report that pngtest crashes on MacOS 10. + + STATUS: workarounds are + 1) Compile without optimization (crashes are observed with + -arch i386 and -O2 or -O3, using gcc-4.0.1). + 2) Compile pngtest.c with PNG_DEBUG defined (the bug goes away if + you try to look at it). + 3) Ignore the crash. The library itself seems to be OK. + diff --git a/libs/libpng-src/LICENSE b/libs/libpng-src/LICENSE new file mode 100644 index 000000000..0fa9cb703 --- /dev/null +++ b/libs/libpng-src/LICENSE @@ -0,0 +1,111 @@ + +This copy of the libpng notices is provided for your convenience. In case of +any discrepancy between this copy and the notices in the file png.h that is +included in the libpng distribution, the latter shall prevail. + +COPYRIGHT NOTICE, DISCLAIMER, and LICENSE: + +If you modify libpng you may insert additional notices immediately following +this sentence. + +This code is released under the libpng license. + +libpng versions 1.2.6, August 15, 2004, through 1.2.46, July 9, 2011, are +Copyright (c) 2004, 2006-2009 Glenn Randers-Pehrson, and are +distributed according to the same disclaimer and license as libpng-1.2.5 +with the following individual added to the list of Contributing Authors + + Cosmin Truta + +libpng versions 1.0.7, July 1, 2000, through 1.2.5 - October 3, 2002, are +Copyright (c) 2000-2002 Glenn Randers-Pehrson, and are +distributed according to the same disclaimer and license as libpng-1.0.6 +with the following individuals added to the list of Contributing Authors + + Simon-Pierre Cadieux + Eric S. Raymond + Gilles Vollant + +and with the following additions to the disclaimer: + + There is no warranty against interference with your enjoyment of the + library or against infringement. There is no warranty that our + efforts or the library will fulfill any of your particular purposes + or needs. This library is provided with all faults, and the entire + risk of satisfactory quality, performance, accuracy, and effort is with + the user. + +libpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are +Copyright (c) 1998, 1999 Glenn Randers-Pehrson, and are +distributed according to the same disclaimer and license as libpng-0.96, +with the following individuals added to the list of Contributing Authors: + + Tom Lane + Glenn Randers-Pehrson + Willem van Schaik + +libpng versions 0.89, June 1996, through 0.96, May 1997, are +Copyright (c) 1996, 1997 Andreas Dilger +Distributed according to the same disclaimer and license as libpng-0.88, +with the following individuals added to the list of Contributing Authors: + + John Bowler + Kevin Bracey + Sam Bushell + Magnus Holmgren + Greg Roelofs + Tom Tanner + +libpng versions 0.5, May 1995, through 0.88, January 1996, are +Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. + +For the purposes of this copyright and license, "Contributing Authors" +is defined as the following set of individuals: + + Andreas Dilger + Dave Martindale + Guy Eric Schalnat + Paul Schmidt + Tim Wegner + +The PNG Reference Library is supplied "AS IS". The Contributing Authors +and Group 42, Inc. disclaim all warranties, expressed or implied, +including, without limitation, the warranties of merchantability and of +fitness for any purpose. The Contributing Authors and Group 42, Inc. +assume no liability for direct, indirect, incidental, special, exemplary, +or consequential damages, which may result from the use of the PNG +Reference Library, even if advised of the possibility of such damage. + +Permission is hereby granted to use, copy, modify, and distribute this +source code, or portions hereof, for any purpose, without fee, subject +to the following restrictions: + +1. The origin of this source code must not be misrepresented. + +2. Altered versions must be plainly marked as such and must not + be misrepresented as being the original source. + +3. This Copyright notice may not be removed or altered from any + source or altered source distribution. + +The Contributing Authors and Group 42, Inc. specifically permit, without +fee, and encourage the use of this source code as a component to +supporting the PNG file format in commercial products. If you use this +source code in a product, acknowledgment is not required but would be +appreciated. + + +A "png_get_copyright" function is available, for convenient use in "about" +boxes and the like: + + printf("%s",png_get_copyright(NULL)); + +Also, the PNG logo (in PNG format, of course) is supplied in the +files "pngbar.png" and "pngbar.jpg (88x31) and "pngnow.png" (98x31). + +Libpng is OSI Certified Open Source Software. OSI Certified Open Source is a +certification mark of the Open Source Initiative. + +Glenn Randers-Pehrson +glennrp at users.sourceforge.net +July 9, 2011 diff --git a/libs/libpng-src/Makefile.am b/libs/libpng-src/Makefile.am new file mode 100644 index 000000000..d3289ca95 --- /dev/null +++ b/libs/libpng-src/Makefile.am @@ -0,0 +1,155 @@ +# Makefile.am: +# Source file for Makefile.in (and hence Makefile) +# +# Makefile.am need only be changed on a major version number +# change (e.g. libpng12 --> libpng14). In that case seach +# this file for every instance of the old base name (libpng12) +# and change to the new one (libpng14), then change the +# -version-number settings below so that the new values have +# the correct major part (first field). + +PNGLIB_BASENAME= libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@ + +# libpng does not follow GNU file name conventions +AUTOMAKE_OPTIONS = foreign + +# test programs - run on make check, make distcheck +check_PROGRAMS= pngtest +pngtest_SOURCES = pngtest.c +pngtest_LDADD = libpng12.la +TESTS = test-pngtest.sh +TESTS_ENVIRONMENT= srcdir=$(srcdir) + +# man pages +dist_man_MANS= libpng.3 libpngpf.3 png.5 + +# generate the -config scripts if required +binconfigs= libpng12-config +EXTRA_SCRIPTS= libpng-config libpng12-config +bin_SCRIPTS= @binconfigs@ + +# rules to build libpng, only build the old library on request +lib_LTLIBRARIES=libpng12.la @compatlib@ +EXTRA_LTLIBRARIES= libpng.la +libpng12_la_SOURCES = png.c pngset.c pngget.c pngrutil.c pngtrans.c pngwutil.c \ + pngread.c pngrio.c pngwio.c pngwrite.c pngrtran.c \ + pngwtran.c pngmem.c pngerror.c pngpread.c \ + png.h pngconf.h +libpng_la_SOURCES = $(libpng12_la_SOURCES) + +libpng_la_CPPFLAGS = @LIBPNG_DEFINES@ +libpng12_la_CPPFLAGS = @LIBPNG_DEFINES@ + +# MAJOR UPGRADE: the version-number settings below must be changed. +libpng12_la_LDFLAGS = -no-undefined -export-dynamic \ + -version-number 0:@PNGLIB_RELEASE@:0 +# -rpath is needed as automake doesn't know the directory +libpng_la_LDFLAGS = -rpath '$(libdir)' -no-undefined -export-dynamic \ + -version-number 3:@PNGLIB_RELEASE@:0 + +if HAVE_LD_VERSION_SCRIPT + # Versioned symbols and restricted exports + libpng12_la_LDFLAGS += -Wl,--version-script=libpng.vers + libpng12_la_DEPENDENCIES = libpng.vers +else + # Only restricted exports when possible + libpng12_la_LDFLAGS += -export-symbols libpng.sym + libpng12_la_DEPENDENCIES = libpng.sym +endif +libpng_la_DEPENDENCIES = $(libpng12_la_DEPENDENCIES) + +# Avoid depending upon Character Ranges. +AN = '_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' + +#distribute headers in /usr/include/libpng/* +pkgincludedir= $(includedir)/$(PNGLIB_BASENAME) +pkginclude_HEADERS= png.h pngconf.h + +# pkg-config stuff, note that libpng.pc is always required in order +# to get the correct library +pkgconfigdir = @pkgconfigdir@ +pkgconfig_DATA = libpng12.pc + +#extra source distribution files. +EXTRA_DIST= \ + ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO \ + pngtest.png pngbar.png pngnow.png pngbar.jpg autogen.sh \ + CMakeLists.txt \ + ${srcdir}/projects/cbuilder5/* \ + ${srcdir}/projects/beos/* \ + ${srcdir}/projects/visualc6/* \ + ${srcdir}/projects/visualc71/* \ + ${srcdir}/projects/wince.txt \ + ${srcdir}/projects/netware.txt \ + ${srcdir}/projects/xcode/* \ + ${srcdir}/scripts/* \ + ${srcdir}/contrib/gregbook/* \ + ${srcdir}/contrib/pngminim/* \ + ${srcdir}/contrib/pngminus/* \ + ${srcdir}/contrib/pngsuite/* \ + ${srcdir}/contrib/visupng/* \ + $(TESTS) \ + example.c libpng-1.2.46.txt pnggccrd.c pngvcrd.c + +CLEANFILES= pngout.png libpng12.pc libpng12-config libpng.vers \ +libpng.sym + +MAINTAINERCLEANFILES = Makefile.in aclocal.m4 config.guess config.h.in \ +config.sub configure depcomp install-sh ltmain.sh missing + +$(PNGLIB_BASENAME).pc: libpng.pc + cp libpng.pc $@ + +$(PNGLIB_BASENAME)-config: libpng-config + cp libpng-config $@ + +libpng.sym: png.h pngconf.h + rm -f $@ $@.new + $(CPP) @LIBPNG_DEFINES@ $(CPPFLAGS) -DPNG_BUILDSYMS $(srcdir)/png.h | \ + $(SED) -n -e \ + 's|^.*PNG_FUNCTION_EXPORT[ ]*\([$(AN)]*\).*$$|$(SYMBOL_PREFIX)\1|p' \ + -e 's|^.*PNG_DATA_EXPORT[ ]*\([$(AN)]*\).*$$|$(SYMBOL_PREFIX)\1|p' \ + >$@.new + mv $@.new $@ + +libpng.vers: libpng.sym + rm -f $@ $@.new + echo PNG@PNGLIB_MAJOR@@PNGLIB_MINOR@_0 '{global:' > $@.new + $(SED) s/$$/\;/ libpng.sym >> $@.new + echo 'local: *; };' >> $@.new + mv $@.new $@ + +test: check + +# install the .../include headers as links to the new ones +install-data-hook: + cd $(DESTDIR)$(includedir); rm -f png.h pngconf.h + cd $(DESTDIR)$(includedir); $(LN_S) $(PNGLIB_BASENAME)/png.h png.h + cd $(DESTDIR)$(includedir); $(LN_S) $(PNGLIB_BASENAME)/pngconf.h pngconf.h + cd $(DESTDIR)$(pkgconfigdir); rm -f libpng.pc + cd $(DESTDIR)$(pkgconfigdir); $(LN_S) $(PNGLIB_BASENAME).pc libpng.pc + +# do evil things to libpng to cause libpng12 to be used +install-exec-hook: + cd $(DESTDIR)$(bindir); rm -f libpng-config + cd $(DESTDIR)$(bindir); $(LN_S) $(PNGLIB_BASENAME)-config libpng-config + @set -x;\ + cd $(DESTDIR)$(libdir);\ + for ext in a la so sl dylib; do\ + rm -f libpng.$$ext;\ + if test -f $(PNGLIB_BASENAME).$$ext; then\ + $(LN_S) $(PNGLIB_BASENAME).$$ext libpng.$$ext;\ + fi;\ + done + +uninstall-hook: + cd $(DESTDIR)$(includedir); rm -f png.h pngconf.h + rm -f $(DESTDIR)$(pkgconfigdir)/libpng.pc + rm -f $(DESTDIR)$(bindir)/libpng-config + @if test -n "@compatlib@"; then\ + set -x;\ + cd $(DESTDIR)$(libdir);\ + for ext in a la so sl dylib; do\ + rm -f libpng.$$ext;\ + done;\ + fi diff --git a/libs/libpng-src/Makefile.in b/libs/libpng-src/Makefile.in new file mode 100644 index 000000000..d07cb3d7b --- /dev/null +++ b/libs/libpng-src/Makefile.in @@ -0,0 +1,1411 @@ +# Makefile.in generated by automake 1.11 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, +# Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +# Makefile.am: +# Source file for Makefile.in (and hence Makefile) +# +# Makefile.am need only be changed on a major version number +# change (e.g. libpng12 --> libpng14). In that case seach +# this file for every instance of the old base name (libpng12) +# and change to the new one (libpng14), then change the +# -version-number settings below so that the new values have +# the correct major part (first field). + + + + +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +check_PROGRAMS = pngtest$(EXEEXT) +@HAVE_LD_VERSION_SCRIPT_TRUE@am__append_1 = -Wl,--version-script=libpng.vers +@HAVE_LD_VERSION_SCRIPT_FALSE@am__append_2 = -export-symbols libpng.sym +subdir = . +DIST_COMMON = README $(am__configure_deps) $(dist_man_MANS) \ + $(pkginclude_HEADERS) $(srcdir)/Makefile.am \ + $(srcdir)/Makefile.in $(srcdir)/config.h.in \ + $(top_srcdir)/configure $(top_srcdir)/scripts/libpng-config.in \ + $(top_srcdir)/scripts/libpng.pc-configure.in INSTALL TODO \ + config.guess config.sub depcomp install-sh ltmain.sh missing \ + mkinstalldirs +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \ + configure.lineno config.status.lineno +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +CONFIG_HEADER = config.h +CONFIG_CLEAN_FILES = libpng.pc libpng-config +CONFIG_CLEAN_VPATH_FILES = +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; +am__install_max = 40 +am__nobase_strip_setup = \ + srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` +am__nobase_strip = \ + for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" +am__nobase_list = $(am__nobase_strip_setup); \ + for p in $$list; do echo "$$p $$p"; done | \ + sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ + $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ + if (++n[$$2] == $(am__install_max)) \ + { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ + END { for (dir in files) print dir, files[dir] }' +am__base_list = \ + sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ + sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' +am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(bindir)" \ + "$(DESTDIR)$(man3dir)" "$(DESTDIR)$(man5dir)" \ + "$(DESTDIR)$(pkgconfigdir)" "$(DESTDIR)$(pkgincludedir)" +LTLIBRARIES = $(lib_LTLIBRARIES) +libpng_la_LIBADD = +am__objects_1 = libpng_la-png.lo libpng_la-pngset.lo \ + libpng_la-pngget.lo libpng_la-pngrutil.lo \ + libpng_la-pngtrans.lo libpng_la-pngwutil.lo \ + libpng_la-pngread.lo libpng_la-pngrio.lo libpng_la-pngwio.lo \ + libpng_la-pngwrite.lo libpng_la-pngrtran.lo \ + libpng_la-pngwtran.lo libpng_la-pngmem.lo \ + libpng_la-pngerror.lo libpng_la-pngpread.lo +am_libpng_la_OBJECTS = $(am__objects_1) +libpng_la_OBJECTS = $(am_libpng_la_OBJECTS) +libpng_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(libpng_la_LDFLAGS) $(LDFLAGS) -o $@ +libpng12_la_LIBADD = +am_libpng12_la_OBJECTS = libpng12_la-png.lo libpng12_la-pngset.lo \ + libpng12_la-pngget.lo libpng12_la-pngrutil.lo \ + libpng12_la-pngtrans.lo libpng12_la-pngwutil.lo \ + libpng12_la-pngread.lo libpng12_la-pngrio.lo \ + libpng12_la-pngwio.lo libpng12_la-pngwrite.lo \ + libpng12_la-pngrtran.lo libpng12_la-pngwtran.lo \ + libpng12_la-pngmem.lo libpng12_la-pngerror.lo \ + libpng12_la-pngpread.lo +libpng12_la_OBJECTS = $(am_libpng12_la_OBJECTS) +libpng12_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(libpng12_la_LDFLAGS) $(LDFLAGS) -o $@ +am_pngtest_OBJECTS = pngtest.$(OBJEXT) +pngtest_OBJECTS = $(am_pngtest_OBJECTS) +pngtest_DEPENDENCIES = libpng12.la +SCRIPTS = $(bin_SCRIPTS) +DEFAULT_INCLUDES = -I.@am__isrc@ +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ + $(LDFLAGS) -o $@ +SOURCES = $(libpng_la_SOURCES) $(libpng12_la_SOURCES) \ + $(pngtest_SOURCES) +DIST_SOURCES = $(libpng_la_SOURCES) $(libpng12_la_SOURCES) \ + $(pngtest_SOURCES) +man3dir = $(mandir)/man3 +man5dir = $(mandir)/man5 +NROFF = nroff +MANS = $(dist_man_MANS) +DATA = $(pkgconfig_DATA) +HEADERS = $(pkginclude_HEADERS) +ETAGS = etags +CTAGS = ctags +am__tty_colors = \ +red=; grn=; lgn=; blu=; std= +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +distdir = $(PACKAGE)-$(VERSION) +top_distdir = $(distdir) +am__remove_distdir = \ + { test ! -d "$(distdir)" \ + || { find "$(distdir)" -type d ! -perm -200 -exec chmod u+w {} ';' \ + && rm -fr "$(distdir)"; }; } +DIST_ARCHIVES = $(distdir).tar.gz +GZIP_ENV = --best +distuninstallcheck_listfiles = find . -type f -print +distcleancheck_listfiles = find . -type f -print + +#distribute headers in /usr/include/libpng/* +pkgincludedir = $(includedir)/$(PNGLIB_BASENAME) +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AR = @AR@ +AS = @AS@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DLLTOOL = @DLLTOOL@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +FGREP = @FGREP@ +GREP = @GREP@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LIBOBJS = @LIBOBJS@ +LIBPNG_DEFINES = @LIBPNG_DEFINES@ +LIBPNG_NO_MMX = @LIBPNG_NO_MMX@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +MKDIR_P = @MKDIR_P@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PNGLIB_MAJOR = @PNGLIB_MAJOR@ +PNGLIB_MINOR = @PNGLIB_MINOR@ +PNGLIB_RELEASE = @PNGLIB_RELEASE@ +PNGLIB_VERSION = @PNGLIB_VERSION@ +POW_LIB = @POW_LIB@ +RANLIB = @RANLIB@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +SYMBOL_PREFIX = @SYMBOL_PREFIX@ +VERSION = @VERSION@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ + +# generate the -config scripts if required +binconfigs = libpng12-config +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +compatlib = @compatlib@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +lt_ECHO = @lt_ECHO@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ + +# pkg-config stuff, note that libpng.pc is always required in order +# to get the correct library +pkgconfigdir = @pkgconfigdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +PNGLIB_BASENAME = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@ + +# libpng does not follow GNU file name conventions +AUTOMAKE_OPTIONS = foreign +pngtest_SOURCES = pngtest.c +pngtest_LDADD = libpng12.la +TESTS = test-pngtest.sh +TESTS_ENVIRONMENT = srcdir=$(srcdir) + +# man pages +dist_man_MANS = libpng.3 libpngpf.3 png.5 +EXTRA_SCRIPTS = libpng-config libpng12-config +bin_SCRIPTS = @binconfigs@ + +# rules to build libpng, only build the old library on request +lib_LTLIBRARIES = libpng12.la @compatlib@ +EXTRA_LTLIBRARIES = libpng.la +libpng12_la_SOURCES = png.c pngset.c pngget.c pngrutil.c pngtrans.c pngwutil.c \ + pngread.c pngrio.c pngwio.c pngwrite.c pngrtran.c \ + pngwtran.c pngmem.c pngerror.c pngpread.c \ + png.h pngconf.h + +libpng_la_SOURCES = $(libpng12_la_SOURCES) +libpng_la_CPPFLAGS = @LIBPNG_DEFINES@ +libpng12_la_CPPFLAGS = @LIBPNG_DEFINES@ + +# MAJOR UPGRADE: the version-number settings below must be changed. +libpng12_la_LDFLAGS = -no-undefined -export-dynamic -version-number \ + 0:@PNGLIB_RELEASE@:0 $(am__append_1) $(am__append_2) +# -rpath is needed as automake doesn't know the directory +libpng_la_LDFLAGS = -rpath '$(libdir)' -no-undefined -export-dynamic \ + -version-number 3:@PNGLIB_RELEASE@:0 + +@HAVE_LD_VERSION_SCRIPT_FALSE@libpng12_la_DEPENDENCIES = libpng.sym +@HAVE_LD_VERSION_SCRIPT_TRUE@libpng12_la_DEPENDENCIES = libpng.vers +libpng_la_DEPENDENCIES = $(libpng12_la_DEPENDENCIES) + +# Avoid depending upon Character Ranges. +AN = '_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' +pkginclude_HEADERS = png.h pngconf.h +pkgconfig_DATA = libpng12.pc + +#extra source distribution files. +EXTRA_DIST = \ + ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO \ + CMakeLists.txt \ + pngtest.png pngbar.png pngnow.png pngbar.jpg autogen.sh \ + ${srcdir}/projects/cbuilder5/* \ + ${srcdir}/projects/beos/* \ + ${srcdir}/projects/visualc6/* \ + ${srcdir}/projects/visualc71/* \ + ${srcdir}/projects/wince.txt \ + ${srcdir}/projects/xcode/* \ + ${srcdir}/projects/netware.txt \ + ${srcdir}/scripts/* \ + ${srcdir}/contrib/gregbook/* \ + ${srcdir}/contrib/pngminim/* \ + ${srcdir}/contrib/pngminus/* \ + ${srcdir}/contrib/pngsuite/* \ + ${srcdir}/contrib/visupng/* \ + $(TESTS) \ + example.c libpng-1.2.46.txt pnggccrd.c pngvcrd.c + +CLEANFILES = pngout.png libpng12.pc libpng12-config libpng.vers \ +libpng.sym + +MAINTAINERCLEANFILES = Makefile.in aclocal.m4 config.guess config.h.in \ +config.sub configure depcomp install-sh ltmain.sh missing + +all: config.h + $(MAKE) $(AM_MAKEFLAGS) all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +am--refresh: + @: +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + echo ' cd $(srcdir) && $(AUTOMAKE) --foreign'; \ + $(am__cd) $(srcdir) && $(AUTOMAKE) --foreign \ + && exit 0; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --foreign Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + echo ' $(SHELL) ./config.status'; \ + $(SHELL) ./config.status;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + $(SHELL) ./config.status --recheck + +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + $(am__cd) $(srcdir) && $(AUTOCONF) +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + $(am__cd) $(srcdir) && $(ACLOCAL) $(ACLOCAL_AMFLAGS) +$(am__aclocal_m4_deps): + +config.h: stamp-h1 + @if test ! -f $@; then \ + rm -f stamp-h1; \ + $(MAKE) $(AM_MAKEFLAGS) stamp-h1; \ + else :; fi + +stamp-h1: $(srcdir)/config.h.in $(top_builddir)/config.status + @rm -f stamp-h1 + cd $(top_builddir) && $(SHELL) ./config.status config.h +$(srcdir)/config.h.in: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + ($(am__cd) $(top_srcdir) && $(AUTOHEADER)) + rm -f stamp-h1 + touch $@ + +distclean-hdr: + -rm -f config.h stamp-h1 +libpng.pc: $(top_builddir)/config.status $(top_srcdir)/scripts/libpng.pc-configure.in + cd $(top_builddir) && $(SHELL) ./config.status $@ +libpng-config: $(top_builddir)/config.status $(top_srcdir)/scripts/libpng-config.in + cd $(top_builddir) && $(SHELL) ./config.status $@ +install-libLTLIBRARIES: $(lib_LTLIBRARIES) + @$(NORMAL_INSTALL) + test -z "$(libdir)" || $(MKDIR_P) "$(DESTDIR)$(libdir)" + @list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \ + list2=; for p in $$list; do \ + if test -f $$p; then \ + list2="$$list2 $$p"; \ + else :; fi; \ + done; \ + test -z "$$list2" || { \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(libdir)'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(libdir)"; \ + } + +uninstall-libLTLIBRARIES: + @$(NORMAL_UNINSTALL) + @list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \ + for p in $$list; do \ + $(am__strip_dir) \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$f'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$f"; \ + done + +clean-libLTLIBRARIES: + -test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES) + @list='$(lib_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" != "$$p" || dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +libpng.la: $(libpng_la_OBJECTS) $(libpng_la_DEPENDENCIES) + $(libpng_la_LINK) $(libpng_la_OBJECTS) $(libpng_la_LIBADD) $(LIBS) +libpng12.la: $(libpng12_la_OBJECTS) $(libpng12_la_DEPENDENCIES) + $(libpng12_la_LINK) -rpath $(libdir) $(libpng12_la_OBJECTS) $(libpng12_la_LIBADD) $(LIBS) + +clean-checkPROGRAMS: + @list='$(check_PROGRAMS)'; test -n "$$list" || exit 0; \ + echo " rm -f" $$list; \ + rm -f $$list || exit $$?; \ + test -n "$(EXEEXT)" || exit 0; \ + list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \ + echo " rm -f" $$list; \ + rm -f $$list +pngtest$(EXEEXT): $(pngtest_OBJECTS) $(pngtest_DEPENDENCIES) + @rm -f pngtest$(EXEEXT) + $(LINK) $(pngtest_OBJECTS) $(pngtest_LDADD) $(LIBS) +install-binSCRIPTS: $(bin_SCRIPTS) + @$(NORMAL_INSTALL) + test -z "$(bindir)" || $(MKDIR_P) "$(DESTDIR)$(bindir)" + @list='$(bin_SCRIPTS)'; test -n "$(bindir)" || list=; \ + for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + if test -f "$$d$$p"; then echo "$$d$$p"; echo "$$p"; else :; fi; \ + done | \ + sed -e 'p;s,.*/,,;n' \ + -e 'h;s|.*|.|' \ + -e 'p;x;s,.*/,,;$(transform)' | sed 'N;N;N;s,\n, ,g' | \ + $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1; } \ + { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \ + if ($$2 == $$4) { files[d] = files[d] " " $$1; \ + if (++n[d] == $(am__install_max)) { \ + print "f", d, files[d]; n[d] = 0; files[d] = "" } } \ + else { print "f", d "/" $$4, $$1 } } \ + END { for (d in files) print "f", d, files[d] }' | \ + while read type dir files; do \ + if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \ + test -z "$$files" || { \ + echo " $(INSTALL_SCRIPT) $$files '$(DESTDIR)$(bindir)$$dir'"; \ + $(INSTALL_SCRIPT) $$files "$(DESTDIR)$(bindir)$$dir" || exit $$?; \ + } \ + ; done + +uninstall-binSCRIPTS: + @$(NORMAL_UNINSTALL) + @list='$(bin_SCRIPTS)'; test -n "$(bindir)" || exit 0; \ + files=`for p in $$list; do echo "$$p"; done | \ + sed -e 's,.*/,,;$(transform)'`; \ + test -n "$$list" || exit 0; \ + echo " ( cd '$(DESTDIR)$(bindir)' && rm -f" $$files ")"; \ + cd "$(DESTDIR)$(bindir)" && rm -f $$files + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpng12_la-png.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpng12_la-pngerror.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpng12_la-pngget.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpng12_la-pngmem.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpng12_la-pngpread.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpng12_la-pngread.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpng12_la-pngrio.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpng12_la-pngrtran.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpng12_la-pngrutil.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpng12_la-pngset.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpng12_la-pngtrans.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpng12_la-pngwio.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpng12_la-pngwrite.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpng12_la-pngwtran.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpng12_la-pngwutil.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpng_la-png.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpng_la-pngerror.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpng_la-pngget.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpng_la-pngmem.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpng_la-pngpread.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpng_la-pngread.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpng_la-pngrio.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpng_la-pngrtran.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpng_la-pngrutil.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpng_la-pngset.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpng_la-pngtrans.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpng_la-pngwio.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpng_la-pngwrite.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpng_la-pngwtran.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpng_la-pngwutil.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pngtest.Po@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c $< + +.c.obj: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< + +libpng_la-png.lo: png.c +@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libpng_la-png.lo -MD -MP -MF $(DEPDIR)/libpng_la-png.Tpo -c -o libpng_la-png.lo `test -f 'png.c' || echo '$(srcdir)/'`png.c +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libpng_la-png.Tpo $(DEPDIR)/libpng_la-png.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='png.c' object='libpng_la-png.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libpng_la-png.lo `test -f 'png.c' || echo '$(srcdir)/'`png.c + +libpng_la-pngset.lo: pngset.c +@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libpng_la-pngset.lo -MD -MP -MF $(DEPDIR)/libpng_la-pngset.Tpo -c -o libpng_la-pngset.lo `test -f 'pngset.c' || echo '$(srcdir)/'`pngset.c +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libpng_la-pngset.Tpo $(DEPDIR)/libpng_la-pngset.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pngset.c' object='libpng_la-pngset.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libpng_la-pngset.lo `test -f 'pngset.c' || echo '$(srcdir)/'`pngset.c + +libpng_la-pngget.lo: pngget.c +@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libpng_la-pngget.lo -MD -MP -MF $(DEPDIR)/libpng_la-pngget.Tpo -c -o libpng_la-pngget.lo `test -f 'pngget.c' || echo '$(srcdir)/'`pngget.c +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libpng_la-pngget.Tpo $(DEPDIR)/libpng_la-pngget.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pngget.c' object='libpng_la-pngget.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libpng_la-pngget.lo `test -f 'pngget.c' || echo '$(srcdir)/'`pngget.c + +libpng_la-pngrutil.lo: pngrutil.c +@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libpng_la-pngrutil.lo -MD -MP -MF $(DEPDIR)/libpng_la-pngrutil.Tpo -c -o libpng_la-pngrutil.lo `test -f 'pngrutil.c' || echo '$(srcdir)/'`pngrutil.c +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libpng_la-pngrutil.Tpo $(DEPDIR)/libpng_la-pngrutil.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pngrutil.c' object='libpng_la-pngrutil.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libpng_la-pngrutil.lo `test -f 'pngrutil.c' || echo '$(srcdir)/'`pngrutil.c + +libpng_la-pngtrans.lo: pngtrans.c +@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libpng_la-pngtrans.lo -MD -MP -MF $(DEPDIR)/libpng_la-pngtrans.Tpo -c -o libpng_la-pngtrans.lo `test -f 'pngtrans.c' || echo '$(srcdir)/'`pngtrans.c +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libpng_la-pngtrans.Tpo $(DEPDIR)/libpng_la-pngtrans.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pngtrans.c' object='libpng_la-pngtrans.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libpng_la-pngtrans.lo `test -f 'pngtrans.c' || echo '$(srcdir)/'`pngtrans.c + +libpng_la-pngwutil.lo: pngwutil.c +@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libpng_la-pngwutil.lo -MD -MP -MF $(DEPDIR)/libpng_la-pngwutil.Tpo -c -o libpng_la-pngwutil.lo `test -f 'pngwutil.c' || echo '$(srcdir)/'`pngwutil.c +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libpng_la-pngwutil.Tpo $(DEPDIR)/libpng_la-pngwutil.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pngwutil.c' object='libpng_la-pngwutil.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libpng_la-pngwutil.lo `test -f 'pngwutil.c' || echo '$(srcdir)/'`pngwutil.c + +libpng_la-pngread.lo: pngread.c +@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libpng_la-pngread.lo -MD -MP -MF $(DEPDIR)/libpng_la-pngread.Tpo -c -o libpng_la-pngread.lo `test -f 'pngread.c' || echo '$(srcdir)/'`pngread.c +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libpng_la-pngread.Tpo $(DEPDIR)/libpng_la-pngread.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pngread.c' object='libpng_la-pngread.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libpng_la-pngread.lo `test -f 'pngread.c' || echo '$(srcdir)/'`pngread.c + +libpng_la-pngrio.lo: pngrio.c +@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libpng_la-pngrio.lo -MD -MP -MF $(DEPDIR)/libpng_la-pngrio.Tpo -c -o libpng_la-pngrio.lo `test -f 'pngrio.c' || echo '$(srcdir)/'`pngrio.c +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libpng_la-pngrio.Tpo $(DEPDIR)/libpng_la-pngrio.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pngrio.c' object='libpng_la-pngrio.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libpng_la-pngrio.lo `test -f 'pngrio.c' || echo '$(srcdir)/'`pngrio.c + +libpng_la-pngwio.lo: pngwio.c +@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libpng_la-pngwio.lo -MD -MP -MF $(DEPDIR)/libpng_la-pngwio.Tpo -c -o libpng_la-pngwio.lo `test -f 'pngwio.c' || echo '$(srcdir)/'`pngwio.c +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libpng_la-pngwio.Tpo $(DEPDIR)/libpng_la-pngwio.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pngwio.c' object='libpng_la-pngwio.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libpng_la-pngwio.lo `test -f 'pngwio.c' || echo '$(srcdir)/'`pngwio.c + +libpng_la-pngwrite.lo: pngwrite.c +@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libpng_la-pngwrite.lo -MD -MP -MF $(DEPDIR)/libpng_la-pngwrite.Tpo -c -o libpng_la-pngwrite.lo `test -f 'pngwrite.c' || echo '$(srcdir)/'`pngwrite.c +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libpng_la-pngwrite.Tpo $(DEPDIR)/libpng_la-pngwrite.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pngwrite.c' object='libpng_la-pngwrite.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libpng_la-pngwrite.lo `test -f 'pngwrite.c' || echo '$(srcdir)/'`pngwrite.c + +libpng_la-pngrtran.lo: pngrtran.c +@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libpng_la-pngrtran.lo -MD -MP -MF $(DEPDIR)/libpng_la-pngrtran.Tpo -c -o libpng_la-pngrtran.lo `test -f 'pngrtran.c' || echo '$(srcdir)/'`pngrtran.c +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libpng_la-pngrtran.Tpo $(DEPDIR)/libpng_la-pngrtran.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pngrtran.c' object='libpng_la-pngrtran.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libpng_la-pngrtran.lo `test -f 'pngrtran.c' || echo '$(srcdir)/'`pngrtran.c + +libpng_la-pngwtran.lo: pngwtran.c +@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libpng_la-pngwtran.lo -MD -MP -MF $(DEPDIR)/libpng_la-pngwtran.Tpo -c -o libpng_la-pngwtran.lo `test -f 'pngwtran.c' || echo '$(srcdir)/'`pngwtran.c +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libpng_la-pngwtran.Tpo $(DEPDIR)/libpng_la-pngwtran.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pngwtran.c' object='libpng_la-pngwtran.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libpng_la-pngwtran.lo `test -f 'pngwtran.c' || echo '$(srcdir)/'`pngwtran.c + +libpng_la-pngmem.lo: pngmem.c +@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libpng_la-pngmem.lo -MD -MP -MF $(DEPDIR)/libpng_la-pngmem.Tpo -c -o libpng_la-pngmem.lo `test -f 'pngmem.c' || echo '$(srcdir)/'`pngmem.c +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libpng_la-pngmem.Tpo $(DEPDIR)/libpng_la-pngmem.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pngmem.c' object='libpng_la-pngmem.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libpng_la-pngmem.lo `test -f 'pngmem.c' || echo '$(srcdir)/'`pngmem.c + +libpng_la-pngerror.lo: pngerror.c +@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libpng_la-pngerror.lo -MD -MP -MF $(DEPDIR)/libpng_la-pngerror.Tpo -c -o libpng_la-pngerror.lo `test -f 'pngerror.c' || echo '$(srcdir)/'`pngerror.c +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libpng_la-pngerror.Tpo $(DEPDIR)/libpng_la-pngerror.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pngerror.c' object='libpng_la-pngerror.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libpng_la-pngerror.lo `test -f 'pngerror.c' || echo '$(srcdir)/'`pngerror.c + +libpng_la-pngpread.lo: pngpread.c +@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libpng_la-pngpread.lo -MD -MP -MF $(DEPDIR)/libpng_la-pngpread.Tpo -c -o libpng_la-pngpread.lo `test -f 'pngpread.c' || echo '$(srcdir)/'`pngpread.c +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libpng_la-pngpread.Tpo $(DEPDIR)/libpng_la-pngpread.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pngpread.c' object='libpng_la-pngpread.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libpng_la-pngpread.lo `test -f 'pngpread.c' || echo '$(srcdir)/'`pngpread.c + +libpng12_la-png.lo: png.c +@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng12_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libpng12_la-png.lo -MD -MP -MF $(DEPDIR)/libpng12_la-png.Tpo -c -o libpng12_la-png.lo `test -f 'png.c' || echo '$(srcdir)/'`png.c +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libpng12_la-png.Tpo $(DEPDIR)/libpng12_la-png.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='png.c' object='libpng12_la-png.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng12_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libpng12_la-png.lo `test -f 'png.c' || echo '$(srcdir)/'`png.c + +libpng12_la-pngset.lo: pngset.c +@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng12_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libpng12_la-pngset.lo -MD -MP -MF $(DEPDIR)/libpng12_la-pngset.Tpo -c -o libpng12_la-pngset.lo `test -f 'pngset.c' || echo '$(srcdir)/'`pngset.c +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libpng12_la-pngset.Tpo $(DEPDIR)/libpng12_la-pngset.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pngset.c' object='libpng12_la-pngset.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng12_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libpng12_la-pngset.lo `test -f 'pngset.c' || echo '$(srcdir)/'`pngset.c + +libpng12_la-pngget.lo: pngget.c +@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng12_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libpng12_la-pngget.lo -MD -MP -MF $(DEPDIR)/libpng12_la-pngget.Tpo -c -o libpng12_la-pngget.lo `test -f 'pngget.c' || echo '$(srcdir)/'`pngget.c +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libpng12_la-pngget.Tpo $(DEPDIR)/libpng12_la-pngget.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pngget.c' object='libpng12_la-pngget.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng12_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libpng12_la-pngget.lo `test -f 'pngget.c' || echo '$(srcdir)/'`pngget.c + +libpng12_la-pngrutil.lo: pngrutil.c +@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng12_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libpng12_la-pngrutil.lo -MD -MP -MF $(DEPDIR)/libpng12_la-pngrutil.Tpo -c -o libpng12_la-pngrutil.lo `test -f 'pngrutil.c' || echo '$(srcdir)/'`pngrutil.c +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libpng12_la-pngrutil.Tpo $(DEPDIR)/libpng12_la-pngrutil.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pngrutil.c' object='libpng12_la-pngrutil.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng12_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libpng12_la-pngrutil.lo `test -f 'pngrutil.c' || echo '$(srcdir)/'`pngrutil.c + +libpng12_la-pngtrans.lo: pngtrans.c +@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng12_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libpng12_la-pngtrans.lo -MD -MP -MF $(DEPDIR)/libpng12_la-pngtrans.Tpo -c -o libpng12_la-pngtrans.lo `test -f 'pngtrans.c' || echo '$(srcdir)/'`pngtrans.c +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libpng12_la-pngtrans.Tpo $(DEPDIR)/libpng12_la-pngtrans.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pngtrans.c' object='libpng12_la-pngtrans.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng12_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libpng12_la-pngtrans.lo `test -f 'pngtrans.c' || echo '$(srcdir)/'`pngtrans.c + +libpng12_la-pngwutil.lo: pngwutil.c +@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng12_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libpng12_la-pngwutil.lo -MD -MP -MF $(DEPDIR)/libpng12_la-pngwutil.Tpo -c -o libpng12_la-pngwutil.lo `test -f 'pngwutil.c' || echo '$(srcdir)/'`pngwutil.c +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libpng12_la-pngwutil.Tpo $(DEPDIR)/libpng12_la-pngwutil.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pngwutil.c' object='libpng12_la-pngwutil.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng12_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libpng12_la-pngwutil.lo `test -f 'pngwutil.c' || echo '$(srcdir)/'`pngwutil.c + +libpng12_la-pngread.lo: pngread.c +@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng12_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libpng12_la-pngread.lo -MD -MP -MF $(DEPDIR)/libpng12_la-pngread.Tpo -c -o libpng12_la-pngread.lo `test -f 'pngread.c' || echo '$(srcdir)/'`pngread.c +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libpng12_la-pngread.Tpo $(DEPDIR)/libpng12_la-pngread.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pngread.c' object='libpng12_la-pngread.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng12_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libpng12_la-pngread.lo `test -f 'pngread.c' || echo '$(srcdir)/'`pngread.c + +libpng12_la-pngrio.lo: pngrio.c +@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng12_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libpng12_la-pngrio.lo -MD -MP -MF $(DEPDIR)/libpng12_la-pngrio.Tpo -c -o libpng12_la-pngrio.lo `test -f 'pngrio.c' || echo '$(srcdir)/'`pngrio.c +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libpng12_la-pngrio.Tpo $(DEPDIR)/libpng12_la-pngrio.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pngrio.c' object='libpng12_la-pngrio.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng12_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libpng12_la-pngrio.lo `test -f 'pngrio.c' || echo '$(srcdir)/'`pngrio.c + +libpng12_la-pngwio.lo: pngwio.c +@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng12_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libpng12_la-pngwio.lo -MD -MP -MF $(DEPDIR)/libpng12_la-pngwio.Tpo -c -o libpng12_la-pngwio.lo `test -f 'pngwio.c' || echo '$(srcdir)/'`pngwio.c +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libpng12_la-pngwio.Tpo $(DEPDIR)/libpng12_la-pngwio.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pngwio.c' object='libpng12_la-pngwio.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng12_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libpng12_la-pngwio.lo `test -f 'pngwio.c' || echo '$(srcdir)/'`pngwio.c + +libpng12_la-pngwrite.lo: pngwrite.c +@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng12_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libpng12_la-pngwrite.lo -MD -MP -MF $(DEPDIR)/libpng12_la-pngwrite.Tpo -c -o libpng12_la-pngwrite.lo `test -f 'pngwrite.c' || echo '$(srcdir)/'`pngwrite.c +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libpng12_la-pngwrite.Tpo $(DEPDIR)/libpng12_la-pngwrite.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pngwrite.c' object='libpng12_la-pngwrite.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng12_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libpng12_la-pngwrite.lo `test -f 'pngwrite.c' || echo '$(srcdir)/'`pngwrite.c + +libpng12_la-pngrtran.lo: pngrtran.c +@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng12_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libpng12_la-pngrtran.lo -MD -MP -MF $(DEPDIR)/libpng12_la-pngrtran.Tpo -c -o libpng12_la-pngrtran.lo `test -f 'pngrtran.c' || echo '$(srcdir)/'`pngrtran.c +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libpng12_la-pngrtran.Tpo $(DEPDIR)/libpng12_la-pngrtran.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pngrtran.c' object='libpng12_la-pngrtran.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng12_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libpng12_la-pngrtran.lo `test -f 'pngrtran.c' || echo '$(srcdir)/'`pngrtran.c + +libpng12_la-pngwtran.lo: pngwtran.c +@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng12_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libpng12_la-pngwtran.lo -MD -MP -MF $(DEPDIR)/libpng12_la-pngwtran.Tpo -c -o libpng12_la-pngwtran.lo `test -f 'pngwtran.c' || echo '$(srcdir)/'`pngwtran.c +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libpng12_la-pngwtran.Tpo $(DEPDIR)/libpng12_la-pngwtran.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pngwtran.c' object='libpng12_la-pngwtran.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng12_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libpng12_la-pngwtran.lo `test -f 'pngwtran.c' || echo '$(srcdir)/'`pngwtran.c + +libpng12_la-pngmem.lo: pngmem.c +@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng12_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libpng12_la-pngmem.lo -MD -MP -MF $(DEPDIR)/libpng12_la-pngmem.Tpo -c -o libpng12_la-pngmem.lo `test -f 'pngmem.c' || echo '$(srcdir)/'`pngmem.c +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libpng12_la-pngmem.Tpo $(DEPDIR)/libpng12_la-pngmem.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pngmem.c' object='libpng12_la-pngmem.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng12_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libpng12_la-pngmem.lo `test -f 'pngmem.c' || echo '$(srcdir)/'`pngmem.c + +libpng12_la-pngerror.lo: pngerror.c +@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng12_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libpng12_la-pngerror.lo -MD -MP -MF $(DEPDIR)/libpng12_la-pngerror.Tpo -c -o libpng12_la-pngerror.lo `test -f 'pngerror.c' || echo '$(srcdir)/'`pngerror.c +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libpng12_la-pngerror.Tpo $(DEPDIR)/libpng12_la-pngerror.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pngerror.c' object='libpng12_la-pngerror.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng12_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libpng12_la-pngerror.lo `test -f 'pngerror.c' || echo '$(srcdir)/'`pngerror.c + +libpng12_la-pngpread.lo: pngpread.c +@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng12_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libpng12_la-pngpread.lo -MD -MP -MF $(DEPDIR)/libpng12_la-pngpread.Tpo -c -o libpng12_la-pngpread.lo `test -f 'pngpread.c' || echo '$(srcdir)/'`pngpread.c +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libpng12_la-pngpread.Tpo $(DEPDIR)/libpng12_la-pngpread.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pngpread.c' object='libpng12_la-pngpread.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libpng12_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libpng12_la-pngpread.lo `test -f 'pngpread.c' || echo '$(srcdir)/'`pngpread.c + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +distclean-libtool: + -rm -f libtool config.lt +install-man3: $(dist_man_MANS) + @$(NORMAL_INSTALL) + test -z "$(man3dir)" || $(MKDIR_P) "$(DESTDIR)$(man3dir)" + @list=''; test -n "$(man3dir)" || exit 0; \ + { for i in $$list; do echo "$$i"; done; \ + l2='$(dist_man_MANS)'; for i in $$l2; do echo "$$i"; done | \ + sed -n '/\.3[a-z]*$$/p'; \ + } | while read p; do \ + if test -f $$p; then d=; else d="$(srcdir)/"; fi; \ + echo "$$d$$p"; echo "$$p"; \ + done | \ + sed -e 'n;s,.*/,,;p;h;s,.*\.,,;s,^[^3][0-9a-z]*$$,3,;x' \ + -e 's,\.[0-9a-z]*$$,,;$(transform);G;s,\n,.,' | \ + sed 'N;N;s,\n, ,g' | { \ + list=; while read file base inst; do \ + if test "$$base" = "$$inst"; then list="$$list $$file"; else \ + echo " $(INSTALL_DATA) '$$file' '$(DESTDIR)$(man3dir)/$$inst'"; \ + $(INSTALL_DATA) "$$file" "$(DESTDIR)$(man3dir)/$$inst" || exit $$?; \ + fi; \ + done; \ + for i in $$list; do echo "$$i"; done | $(am__base_list) | \ + while read files; do \ + test -z "$$files" || { \ + echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(man3dir)'"; \ + $(INSTALL_DATA) $$files "$(DESTDIR)$(man3dir)" || exit $$?; }; \ + done; } + +uninstall-man3: + @$(NORMAL_UNINSTALL) + @list=''; test -n "$(man3dir)" || exit 0; \ + files=`{ for i in $$list; do echo "$$i"; done; \ + l2='$(dist_man_MANS)'; for i in $$l2; do echo "$$i"; done | \ + sed -n '/\.3[a-z]*$$/p'; \ + } | sed -e 's,.*/,,;h;s,.*\.,,;s,^[^3][0-9a-z]*$$,3,;x' \ + -e 's,\.[0-9a-z]*$$,,;$(transform);G;s,\n,.,'`; \ + test -z "$$files" || { \ + echo " ( cd '$(DESTDIR)$(man3dir)' && rm -f" $$files ")"; \ + cd "$(DESTDIR)$(man3dir)" && rm -f $$files; } +install-man5: $(dist_man_MANS) + @$(NORMAL_INSTALL) + test -z "$(man5dir)" || $(MKDIR_P) "$(DESTDIR)$(man5dir)" + @list=''; test -n "$(man5dir)" || exit 0; \ + { for i in $$list; do echo "$$i"; done; \ + l2='$(dist_man_MANS)'; for i in $$l2; do echo "$$i"; done | \ + sed -n '/\.5[a-z]*$$/p'; \ + } | while read p; do \ + if test -f $$p; then d=; else d="$(srcdir)/"; fi; \ + echo "$$d$$p"; echo "$$p"; \ + done | \ + sed -e 'n;s,.*/,,;p;h;s,.*\.,,;s,^[^5][0-9a-z]*$$,5,;x' \ + -e 's,\.[0-9a-z]*$$,,;$(transform);G;s,\n,.,' | \ + sed 'N;N;s,\n, ,g' | { \ + list=; while read file base inst; do \ + if test "$$base" = "$$inst"; then list="$$list $$file"; else \ + echo " $(INSTALL_DATA) '$$file' '$(DESTDIR)$(man5dir)/$$inst'"; \ + $(INSTALL_DATA) "$$file" "$(DESTDIR)$(man5dir)/$$inst" || exit $$?; \ + fi; \ + done; \ + for i in $$list; do echo "$$i"; done | $(am__base_list) | \ + while read files; do \ + test -z "$$files" || { \ + echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(man5dir)'"; \ + $(INSTALL_DATA) $$files "$(DESTDIR)$(man5dir)" || exit $$?; }; \ + done; } + +uninstall-man5: + @$(NORMAL_UNINSTALL) + @list=''; test -n "$(man5dir)" || exit 0; \ + files=`{ for i in $$list; do echo "$$i"; done; \ + l2='$(dist_man_MANS)'; for i in $$l2; do echo "$$i"; done | \ + sed -n '/\.5[a-z]*$$/p'; \ + } | sed -e 's,.*/,,;h;s,.*\.,,;s,^[^5][0-9a-z]*$$,5,;x' \ + -e 's,\.[0-9a-z]*$$,,;$(transform);G;s,\n,.,'`; \ + test -z "$$files" || { \ + echo " ( cd '$(DESTDIR)$(man5dir)' && rm -f" $$files ")"; \ + cd "$(DESTDIR)$(man5dir)" && rm -f $$files; } +install-pkgconfigDATA: $(pkgconfig_DATA) + @$(NORMAL_INSTALL) + test -z "$(pkgconfigdir)" || $(MKDIR_P) "$(DESTDIR)$(pkgconfigdir)" + @list='$(pkgconfig_DATA)'; test -n "$(pkgconfigdir)" || list=; \ + for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + echo "$$d$$p"; \ + done | $(am__base_list) | \ + while read files; do \ + echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(pkgconfigdir)'"; \ + $(INSTALL_DATA) $$files "$(DESTDIR)$(pkgconfigdir)" || exit $$?; \ + done + +uninstall-pkgconfigDATA: + @$(NORMAL_UNINSTALL) + @list='$(pkgconfig_DATA)'; test -n "$(pkgconfigdir)" || list=; \ + files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ + test -n "$$files" || exit 0; \ + echo " ( cd '$(DESTDIR)$(pkgconfigdir)' && rm -f" $$files ")"; \ + cd "$(DESTDIR)$(pkgconfigdir)" && rm -f $$files +install-pkgincludeHEADERS: $(pkginclude_HEADERS) + @$(NORMAL_INSTALL) + test -z "$(pkgincludedir)" || $(MKDIR_P) "$(DESTDIR)$(pkgincludedir)" + @list='$(pkginclude_HEADERS)'; test -n "$(pkgincludedir)" || list=; \ + for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + echo "$$d$$p"; \ + done | $(am__base_list) | \ + while read files; do \ + echo " $(INSTALL_HEADER) $$files '$(DESTDIR)$(pkgincludedir)'"; \ + $(INSTALL_HEADER) $$files "$(DESTDIR)$(pkgincludedir)" || exit $$?; \ + done + +uninstall-pkgincludeHEADERS: + @$(NORMAL_UNINSTALL) + @list='$(pkginclude_HEADERS)'; test -n "$(pkgincludedir)" || list=; \ + files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ + test -n "$$files" || exit 0; \ + echo " ( cd '$(DESTDIR)$(pkgincludedir)' && rm -f" $$files ")"; \ + cd "$(DESTDIR)$(pkgincludedir)" && rm -f $$files + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) config.h.in $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + set x; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) config.h.in $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) config.h.in $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + list='$(SOURCES) $(HEADERS) config.h.in $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +check-TESTS: $(TESTS) + @failed=0; all=0; xfail=0; xpass=0; skip=0; \ + srcdir=$(srcdir); export srcdir; \ + list=' $(TESTS) '; \ + $(am__tty_colors); \ + if test -n "$$list"; then \ + for tst in $$list; do \ + if test -f ./$$tst; then dir=./; \ + elif test -f $$tst; then dir=; \ + else dir="$(srcdir)/"; fi; \ + if $(TESTS_ENVIRONMENT) $${dir}$$tst; then \ + all=`expr $$all + 1`; \ + case " $(XFAIL_TESTS) " in \ + *[\ \ ]$$tst[\ \ ]*) \ + xpass=`expr $$xpass + 1`; \ + failed=`expr $$failed + 1`; \ + col=$$red; res=XPASS; \ + ;; \ + *) \ + col=$$grn; res=PASS; \ + ;; \ + esac; \ + elif test $$? -ne 77; then \ + all=`expr $$all + 1`; \ + case " $(XFAIL_TESTS) " in \ + *[\ \ ]$$tst[\ \ ]*) \ + xfail=`expr $$xfail + 1`; \ + col=$$lgn; res=XFAIL; \ + ;; \ + *) \ + failed=`expr $$failed + 1`; \ + col=$$red; res=FAIL; \ + ;; \ + esac; \ + else \ + skip=`expr $$skip + 1`; \ + col=$$blu; res=SKIP; \ + fi; \ + echo "$${col}$$res$${std}: $$tst"; \ + done; \ + if test "$$all" -eq 1; then \ + tests="test"; \ + All=""; \ + else \ + tests="tests"; \ + All="All "; \ + fi; \ + if test "$$failed" -eq 0; then \ + if test "$$xfail" -eq 0; then \ + banner="$$All$$all $$tests passed"; \ + else \ + if test "$$xfail" -eq 1; then failures=failure; else failures=failures; fi; \ + banner="$$All$$all $$tests behaved as expected ($$xfail expected $$failures)"; \ + fi; \ + else \ + if test "$$xpass" -eq 0; then \ + banner="$$failed of $$all $$tests failed"; \ + else \ + if test "$$xpass" -eq 1; then passes=pass; else passes=passes; fi; \ + banner="$$failed of $$all $$tests did not behave as expected ($$xpass unexpected $$passes)"; \ + fi; \ + fi; \ + dashes="$$banner"; \ + skipped=""; \ + if test "$$skip" -ne 0; then \ + if test "$$skip" -eq 1; then \ + skipped="($$skip test was not run)"; \ + else \ + skipped="($$skip tests were not run)"; \ + fi; \ + test `echo "$$skipped" | wc -c` -le `echo "$$banner" | wc -c` || \ + dashes="$$skipped"; \ + fi; \ + report=""; \ + if test "$$failed" -ne 0 && test -n "$(PACKAGE_BUGREPORT)"; then \ + report="Please report to $(PACKAGE_BUGREPORT)"; \ + test `echo "$$report" | wc -c` -le `echo "$$banner" | wc -c` || \ + dashes="$$report"; \ + fi; \ + dashes=`echo "$$dashes" | sed s/./=/g`; \ + if test "$$failed" -eq 0; then \ + echo "$$grn$$dashes"; \ + else \ + echo "$$red$$dashes"; \ + fi; \ + echo "$$banner"; \ + test -z "$$skipped" || echo "$$skipped"; \ + test -z "$$report" || echo "$$report"; \ + echo "$$dashes$$std"; \ + test "$$failed" -eq 0; \ + else :; fi + +distdir: $(DISTFILES) + @list='$(MANS)'; if test -n "$$list"; then \ + list=`for p in $$list; do \ + if test -f $$p; then d=; else d="$(srcdir)/"; fi; \ + if test -f "$$d$$p"; then echo "$$d$$p"; else :; fi; done`; \ + if test -n "$$list" && \ + grep 'ab help2man is required to generate this page' $$list >/dev/null; then \ + echo "error: found man pages containing the \`missing help2man' replacement text:" >&2; \ + grep -l 'ab help2man is required to generate this page' $$list | sed 's/^/ /' >&2; \ + echo " to fix them, install help2man, remove and regenerate the man pages;" >&2; \ + echo " typically \`make maintainer-clean' will remove them" >&2; \ + exit 1; \ + else :; fi; \ + else :; fi + $(am__remove_distdir) + test -d "$(distdir)" || mkdir "$(distdir)" + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done + -test -n "$(am__skip_mode_fix)" \ + || find "$(distdir)" -type d ! -perm -777 -exec chmod a+rwx {} \; -o \ + ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; -o \ + ! -type d ! -perm -400 -exec chmod a+r {} \; -o \ + ! -type d ! -perm -444 -exec $(install_sh) -c -m a+r {} {} \; \ + || chmod -R a+r "$(distdir)" +dist-gzip: distdir + tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz + $(am__remove_distdir) + +dist-bzip2: distdir + tardir=$(distdir) && $(am__tar) | bzip2 -9 -c >$(distdir).tar.bz2 + $(am__remove_distdir) + +dist-lzma: distdir + tardir=$(distdir) && $(am__tar) | lzma -9 -c >$(distdir).tar.lzma + $(am__remove_distdir) + +dist-xz: distdir + tardir=$(distdir) && $(am__tar) | xz -c >$(distdir).tar.xz + $(am__remove_distdir) + +dist-tarZ: distdir + tardir=$(distdir) && $(am__tar) | compress -c >$(distdir).tar.Z + $(am__remove_distdir) + +dist-shar: distdir + shar $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).shar.gz + $(am__remove_distdir) + +dist-zip: distdir + -rm -f $(distdir).zip + zip -rq $(distdir).zip $(distdir) + $(am__remove_distdir) + +dist dist-all: distdir + tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz + $(am__remove_distdir) + +# This target untars the dist file and tries a VPATH configuration. Then +# it guarantees that the distribution is self-contained by making another +# tarfile. +distcheck: dist + case '$(DIST_ARCHIVES)' in \ + *.tar.gz*) \ + GZIP=$(GZIP_ENV) gunzip -c $(distdir).tar.gz | $(am__untar) ;;\ + *.tar.bz2*) \ + bunzip2 -c $(distdir).tar.bz2 | $(am__untar) ;;\ + *.tar.lzma*) \ + unlzma -c $(distdir).tar.lzma | $(am__untar) ;;\ + *.tar.xz*) \ + xz -dc $(distdir).tar.xz | $(am__untar) ;;\ + *.tar.Z*) \ + uncompress -c $(distdir).tar.Z | $(am__untar) ;;\ + *.shar.gz*) \ + GZIP=$(GZIP_ENV) gunzip -c $(distdir).shar.gz | unshar ;;\ + *.zip*) \ + unzip $(distdir).zip ;;\ + esac + chmod -R a-w $(distdir); chmod a+w $(distdir) + mkdir $(distdir)/_build + mkdir $(distdir)/_inst + chmod a-w $(distdir) + test -d $(distdir)/_build || exit 0; \ + dc_install_base=`$(am__cd) $(distdir)/_inst && pwd | sed -e 's,^[^:\\/]:[\\/],/,'` \ + && dc_destdir="$${TMPDIR-/tmp}/am-dc-$$$$/" \ + && am__cwd=`pwd` \ + && $(am__cd) $(distdir)/_build \ + && ../configure --srcdir=.. --prefix="$$dc_install_base" \ + $(DISTCHECK_CONFIGURE_FLAGS) \ + && $(MAKE) $(AM_MAKEFLAGS) \ + && $(MAKE) $(AM_MAKEFLAGS) dvi \ + && $(MAKE) $(AM_MAKEFLAGS) check \ + && $(MAKE) $(AM_MAKEFLAGS) install \ + && $(MAKE) $(AM_MAKEFLAGS) installcheck \ + && $(MAKE) $(AM_MAKEFLAGS) uninstall \ + && $(MAKE) $(AM_MAKEFLAGS) distuninstallcheck_dir="$$dc_install_base" \ + distuninstallcheck \ + && chmod -R a-w "$$dc_install_base" \ + && ({ \ + (cd ../.. && umask 077 && mkdir "$$dc_destdir") \ + && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" install \ + && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" uninstall \ + && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" \ + distuninstallcheck_dir="$$dc_destdir" distuninstallcheck; \ + } || { rm -rf "$$dc_destdir"; exit 1; }) \ + && rm -rf "$$dc_destdir" \ + && $(MAKE) $(AM_MAKEFLAGS) dist \ + && rm -rf $(DIST_ARCHIVES) \ + && $(MAKE) $(AM_MAKEFLAGS) distcleancheck \ + && cd "$$am__cwd" \ + || exit 1 + $(am__remove_distdir) + @(echo "$(distdir) archives ready for distribution: "; \ + list='$(DIST_ARCHIVES)'; for i in $$list; do echo $$i; done) | \ + sed -e 1h -e 1s/./=/g -e 1p -e 1x -e '$$p' -e '$$x' +distuninstallcheck: + @$(am__cd) '$(distuninstallcheck_dir)' \ + && test `$(distuninstallcheck_listfiles) | wc -l` -le 1 \ + || { echo "ERROR: files left after uninstall:" ; \ + if test -n "$(DESTDIR)"; then \ + echo " (check DESTDIR support)"; \ + fi ; \ + $(distuninstallcheck_listfiles) ; \ + exit 1; } >&2 +distcleancheck: distclean + @if test '$(srcdir)' = . ; then \ + echo "ERROR: distcleancheck can only run from a VPATH build" ; \ + exit 1 ; \ + fi + @test `$(distcleancheck_listfiles) | wc -l` -eq 0 \ + || { echo "ERROR: files left in build directory after distclean:" ; \ + $(distcleancheck_listfiles) ; \ + exit 1; } >&2 +check-am: all-am + $(MAKE) $(AM_MAKEFLAGS) $(check_PROGRAMS) + $(MAKE) $(AM_MAKEFLAGS) check-TESTS +check: check-am +all-am: Makefile $(LTLIBRARIES) $(SCRIPTS) $(MANS) $(DATA) $(HEADERS) \ + config.h +installdirs: + for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(bindir)" "$(DESTDIR)$(man3dir)" "$(DESTDIR)$(man5dir)" "$(DESTDIR)$(pkgconfigdir)" "$(DESTDIR)$(pkgincludedir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES) + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." + -test -z "$(MAINTAINERCLEANFILES)" || rm -f $(MAINTAINERCLEANFILES) +clean: clean-am + +clean-am: clean-checkPROGRAMS clean-generic clean-libLTLIBRARIES \ + clean-libtool mostlyclean-am + +distclean: distclean-am + -rm -f $(am__CONFIG_DISTCLEAN_FILES) + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-hdr distclean-libtool distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: install-man install-pkgconfigDATA \ + install-pkgincludeHEADERS + @$(NORMAL_INSTALL) + $(MAKE) $(AM_MAKEFLAGS) install-data-hook +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: install-binSCRIPTS install-libLTLIBRARIES + @$(NORMAL_INSTALL) + $(MAKE) $(AM_MAKEFLAGS) install-exec-hook +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: install-man3 install-man5 + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -f $(am__CONFIG_DISTCLEAN_FILES) + -rm -rf $(top_srcdir)/autom4te.cache + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-binSCRIPTS uninstall-libLTLIBRARIES \ + uninstall-man uninstall-pkgconfigDATA \ + uninstall-pkgincludeHEADERS + @$(NORMAL_INSTALL) + $(MAKE) $(AM_MAKEFLAGS) uninstall-hook +uninstall-man: uninstall-man3 uninstall-man5 + +.MAKE: all check-am install-am install-data-am install-exec-am \ + install-strip uninstall-am + +.PHONY: CTAGS GTAGS all all-am am--refresh check check-TESTS check-am \ + clean clean-checkPROGRAMS clean-generic clean-libLTLIBRARIES \ + clean-libtool ctags dist dist-all dist-bzip2 dist-gzip \ + dist-lzma dist-shar dist-tarZ dist-xz dist-zip distcheck \ + distclean distclean-compile distclean-generic distclean-hdr \ + distclean-libtool distclean-tags distcleancheck distdir \ + distuninstallcheck dvi dvi-am html html-am info info-am \ + install install-am install-binSCRIPTS install-data \ + install-data-am install-data-hook install-dvi install-dvi-am \ + install-exec install-exec-am install-exec-hook install-html \ + install-html-am install-info install-info-am \ + install-libLTLIBRARIES install-man install-man3 install-man5 \ + install-pdf install-pdf-am install-pkgconfigDATA \ + install-pkgincludeHEADERS install-ps install-ps-am \ + install-strip installcheck installcheck-am installdirs \ + maintainer-clean maintainer-clean-generic mostlyclean \ + mostlyclean-compile mostlyclean-generic mostlyclean-libtool \ + pdf pdf-am ps ps-am tags uninstall uninstall-am \ + uninstall-binSCRIPTS uninstall-hook uninstall-libLTLIBRARIES \ + uninstall-man uninstall-man3 uninstall-man5 \ + uninstall-pkgconfigDATA uninstall-pkgincludeHEADERS + + +@HAVE_LD_VERSION_SCRIPT_TRUE@ # Versioned symbols and restricted exports +@HAVE_LD_VERSION_SCRIPT_FALSE@ # Only restricted exports when possible + +$(PNGLIB_BASENAME).pc: libpng.pc + cp libpng.pc $@ + +$(PNGLIB_BASENAME)-config: libpng-config + cp libpng-config $@ + +libpng.sym: png.h pngconf.h + rm -f $@ $@.new + $(CPP) @LIBPNG_DEFINES@ $(CPPFLAGS) -DPNG_BUILDSYMS $(srcdir)/png.h | \ + $(SED) -n -e \ + 's|^.*PNG_FUNCTION_EXPORT[ ]*\([$(AN)]*\).*$$|$(SYMBOL_PREFIX)\1|p' \ + -e 's|^.*PNG_DATA_EXPORT[ ]*\([$(AN)]*\).*$$|$(SYMBOL_PREFIX)\1|p' \ + >$@.new + mv $@.new $@ + +libpng.vers: libpng.sym + rm -f $@ $@.new + echo PNG@PNGLIB_MAJOR@@PNGLIB_MINOR@_0 '{global:' > $@.new + $(SED) s/$$/\;/ libpng.sym >> $@.new + echo 'local: *; };' >> $@.new + mv $@.new $@ + +test: check + +# install the .../include headers as links to the new ones +install-data-hook: + cd $(DESTDIR)$(includedir); rm -f png.h pngconf.h + cd $(DESTDIR)$(includedir); $(LN_S) $(PNGLIB_BASENAME)/png.h png.h + cd $(DESTDIR)$(includedir); $(LN_S) $(PNGLIB_BASENAME)/pngconf.h pngconf.h + cd $(DESTDIR)$(pkgconfigdir); rm -f libpng.pc + cd $(DESTDIR)$(pkgconfigdir); $(LN_S) $(PNGLIB_BASENAME).pc libpng.pc + +# do evil things to libpng to cause libpng12 to be used +install-exec-hook: + cd $(DESTDIR)$(bindir); rm -f libpng-config + cd $(DESTDIR)$(bindir); $(LN_S) $(PNGLIB_BASENAME)-config libpng-config + @set -x;\ + cd $(DESTDIR)$(libdir);\ + for ext in a la so sl dylib; do\ + rm -f libpng.$$ext;\ + if test -f $(PNGLIB_BASENAME).$$ext; then\ + $(LN_S) $(PNGLIB_BASENAME).$$ext libpng.$$ext;\ + fi;\ + done + +uninstall-hook: + cd $(DESTDIR)$(includedir); rm -f png.h pngconf.h + rm -f $(DESTDIR)$(pkgconfigdir)/libpng.pc + rm -f $(DESTDIR)$(bindir)/libpng-config + @if test -n "@compatlib@"; then\ + set -x;\ + cd $(DESTDIR)$(libdir);\ + for ext in a la so sl dylib; do\ + rm -f libpng.$$ext;\ + done;\ + fi + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/libs/libpng-src/README b/libs/libpng-src/README new file mode 100644 index 000000000..cbff54441 --- /dev/null +++ b/libs/libpng-src/README @@ -0,0 +1,275 @@ +README for libpng version 1.2.46 - July 9, 2011 (shared library 12.0) +See the note about version numbers near the top of png.h + +See INSTALL for instructions on how to install libpng. + +Libpng comes in several distribution formats. Get libpng-*.tar.gz, +libpng-*.tar.xz, or libpng-*.tar.bz2 if you want UNIX-style line +endings in the text files, or lpng*.7z or lpng*.zip if you want DOS-style +line endings. You can get UNIX-style line endings from the *.zip file +by using "unzip -a" but there seems to be no simple way to recover +UNIX-style line endings from the *.7z file. The *.tar.xz file is +recommended for *NIX users instead. + +Version 0.89 was the first official release of libpng. Don't let the +fact that it's the first release fool you. The libpng library has been in +extensive use and testing since mid-1995. By late 1997 it had +finally gotten to the stage where there hadn't been significant +changes to the API in some time, and people have a bad feeling about +libraries with versions < 1.0. Version 1.0.0 was released in +March 1998. + +**** +Note that some of the changes to the png_info structure render this +version of the library binary incompatible with libpng-0.89 or +earlier versions if you are using a shared library. The type of the +"filler" parameter for png_set_filler() has changed from png_byte to +png_uint_32, which will affect shared-library applications that use +this function. + +To avoid problems with changes to the internals of png_info_struct, +new APIs have been made available in 0.95 to avoid direct application +access to info_ptr. These functions are the png_set_ and +png_get_ functions. These functions should be used when +accessing/storing the info_struct data, rather than manipulating it +directly, to avoid such problems in the future. + +It is important to note that the APIs do not make current programs +that access the info struct directly incompatible with the new +library. However, it is strongly suggested that new programs use +the new APIs (as shown in example.c and pngtest.c), and older programs +be converted to the new format, to facilitate upgrades in the future. +**** + +Additions since 0.90 include the ability to compile libpng as a +Windows DLL, and new APIs for accessing data in the info struct. +Experimental functions include the ability to set weighting and cost +factors for row filter selection, direct reads of integers from buffers +on big-endian processors that support misaligned data access, faster +methods of doing alpha composition, and more accurate 16->8 bit color +conversion. + +The additions since 0.89 include the ability to read from a PNG stream +which has had some (or all) of the signature bytes read by the calling +application. This also allows the reading of embedded PNG streams that +do not have the PNG file signature. As well, it is now possible to set +the library action on the detection of chunk CRC errors. It is possible +to set different actions based on whether the CRC error occurred in a +critical or an ancillary chunk. + +The changes made to the library, and bugs fixed are based on discussions +on the png-mng-implement mailing list and not on material submitted +privately to Guy, Andreas, or Glenn. They will forward any good +suggestions to the list. + +For a detailed description on using libpng, read libpng.txt. For +examples of libpng in a program, see example.c and pngtest.c. For usage +information and restrictions (what little they are) on libpng, see +png.h. For a description on using zlib (the compression library used by +libpng) and zlib's restrictions, see zlib.h + +I have included a general makefile, as well as several machine and +compiler specific ones, but you may have to modify one for your own needs. + +You should use zlib 1.0.4 or later to run this, but it MAY work with +versions as old as zlib 0.95. Even so, there are bugs in older zlib +versions which can cause the output of invalid compression streams for +some images. You will definitely need zlib 1.0.4 or later if you are +taking advantage of the MS-DOS "far" structure allocation for the small +and medium memory models. You should also note that zlib is a +compression library that is useful for more things than just PNG files. +You can use zlib as a drop-in replacement for fread() and fwrite() if +you are so inclined. + +zlib should be available at the same place that libpng is, or at +ftp://ftp.simplesystems.org/pub/png/src/ + +You may also want a copy of the PNG specification. It is available +as an RFC, a W3C Recommendation, and an ISO/IEC Standard. You can find +these at http://www.libpng.org/pub/png/pngdocs.html + +This code is currently being archived at libpng.sf.net in the +[DOWNLOAD] area, and on CompuServe, Lib 20 (PNG SUPPORT) +at GO GRAPHSUP. If you can't find it in any of those places, +e-mail me, and I'll help you find it. + +If you have any code changes, requests, problems, etc., please e-mail +them to me. Also, I'd appreciate any make files or project files, +and any modifications you needed to make to get libpng to compile, +along with a #define variable to tell what compiler/system you are on. +If you needed to add transformations to libpng, or wish libpng would +provide the image in a different way, drop me a note (and code, if +possible), so I can consider supporting the transformation. +Finally, if you get any warning messages when compiling libpng +(note: not zlib), and they are easy to fix, I'd appreciate the +fix. Please mention "libpng" somewhere in the subject line. Thanks. + +This release was created and will be supported by myself (of course +based in a large way on Guy's and Andreas' earlier work), and the PNG +development group. + +Send comments/corrections/commendations to png-mng-implement at lists.sf.net +(subscription required; visit +https://lists.sourceforge.net/lists/listinfo/png-mng-implement +to subscribe) or to glennrp at users.sourceforge.net + +You can't reach Guy, the original libpng author, at the addresses +given in previous versions of this document. He and Andreas will +read mail addressed to the png-mng-implement list, however. + +Please do not send general questions about PNG. Send them to +the (png-mng-misc at lists.sourceforge.net, subscription required, visit +https://lists.sourceforge.net/lists/listinfo/png-mng-misc to +subscribe). On the other hand, please do not send libpng questions to +that address, send them to me or to the png-mng-implement list. I'll +get them in the end anyway. If you have a question about something +in the PNG specification that is related to using libpng, send it +to me. Send me any questions that start with "I was using libpng, +and ...". If in doubt, send questions to me. I'll bounce them +to others, if necessary. + +Please do not send suggestions on how to change PNG. We have +been discussing PNG for twelve years now, and it is official and +finished. If you have suggestions for libpng, however, I'll +gladly listen. Even if your suggestion is not used immediately, +it may be used later. + +Files in this distribution: + + ANNOUNCE => Announcement of this version, with recent changes + CHANGES => Description of changes between libpng versions + KNOWNBUG => List of known bugs and deficiencies + LICENSE => License to use and redistribute libpng + README => This file + TODO => Things not implemented in the current library + Y2KINFO => Statement of Y2K compliance + example.c => Example code for using libpng functions + libpng-*-*-diff.txt => Diff from previous release + libpng.3 => manual page for libpng (includes libpng.txt) + libpng.txt => Description of libpng and its functions + libpngpf.3 => manual page for libpng's private functions + png.5 => manual page for the PNG format + png.c => Basic interface functions common to library + png.h => Library function and interface declarations + pngconf.h => System specific library configuration + pngerror.c => Error/warning message I/O functions + pngget.c => Functions for retrieving info from struct + pngmem.c => Memory handling functions + pngbar.png => PNG logo, 88x31 + pngnow.png => PNG logo, 98x31 + pngpread.c => Progressive reading functions + pngread.c => Read data/helper high-level functions + pngrio.c => Lowest-level data read I/O functions + pngrtran.c => Read data transformation functions + pngrutil.c => Read data utility functions + pngset.c => Functions for storing data into the info_struct + pngtest.c => Library test program + pngtest.png => Library test sample image + pngtrans.c => Common data transformation functions + pngwio.c => Lowest-level write I/O functions + pngwrite.c => High-level write functions + pngwtran.c => Write data transformations + pngwutil.c => Write utility functions + contrib => Contributions + gregbook => source code for PNG reading and writing, from + Greg Roelofs' "PNG: The Definitive Guide", + O'Reilly, 1999 + msvctest => Builds and runs pngtest using a MSVC workspace + pngminim => Simple pnm2pngm and png2pnmm programs + pngminus => Simple pnm2png and png2pnm programs + pngsuite => Test images + visupng => Contains a MSVC workspace for VisualPng + projects => Contains project files and workspaces for + building a DLL + beos => Contains a Beos workspace for building libpng + c5builder => Contains a Borland workspace for building + libpng and zlib + netware.txt => Contains instructions for downloading a set + of project files for building libpng and + zlib on Netware. + visualc6 => Contains a Microsoft Visual C++ (MSVC) + workspace for building libpng and zlib + wince.txt => Contains instructions for downloading a + Microsoft Visual C++ (Windows CD Toolkit) + workspace for building libpng and zlib on + WindowsCE + xcode => Contains xcode project files + scripts => Directory containing scripts for building libpng: + descrip.mms => VMS makefile for MMS or MMK + makefile.std => Generic UNIX makefile (cc, creates static + libpng.a) + makefile.elf => Linux/ELF gcc makefile symbol versioning, + creates libpng12.so.0.1.2.46) + makefile.linux => Linux/ELF makefile (gcc, creates + libpng12.so.0.1.2.46) + makefile.gcmmx => Linux/ELF makefile (gcc, creates + libpng12.so.0.1.2.46, previously + used assembler code tuned for Intel MMX + platform) + makefile.gcc => Generic makefile (gcc, creates static + libpng.a) + makefile.knr => Archaic UNIX Makefile that converts files + with ansi2knr (Requires ansi2knr.c from + ftp://ftp.cs.wisc.edu/ghost) + makefile.aix => AIX makefile + makefile.cygwin => Cygwin/gcc makefile + makefile.darwin => Darwin makefile + makefile.dec => DEC Alpha UNIX makefile + makefile.freebsd => FreeBSD makefile + makefile.hpgcc => HPUX makefile using gcc + makefile.hpux => HPUX (10.20 and 11.00) makefile + makefile.hp64 => HPUX (10.20 and 11.00) makefile, 64 bit + makefile.ibmc => IBM C/C++ version 3.x for Win32 and OS/2 + (static) + makefile.intel => Intel C/C++ version 4.0 and later + libpng.icc => Project file, IBM VisualAge/C++ 4.0 or later + makefile.netbsd => NetBSD/cc makefile, makes libpng.so. + makefile.ne12bsd => NetBSD/cc makefile, makes libpng12.so + makefile.openbsd => OpenBSD makefile + makefile.sgi => Silicon Graphics IRIX (cc, creates static lib) + makefile.sggcc => Silicon Graphics + (gcc, creates libpng12.so.0.1.2.46) + makefile.sunos => Sun makefile + makefile.solaris => Solaris 2.X makefile + (gcc, creates libpng12.so.0.1.2.46) + makefile.so9 => Solaris 9 makefile + (gcc, creates libpng12.so.0.1.2.46) + makefile.32sunu => Sun Ultra 32-bit makefile + makefile.64sunu => Sun Ultra 64-bit makefile + makefile.sco => For SCO OSr5 ELF and Unixware 7 with Native cc + makefile.mips => MIPS makefile + makefile.acorn => Acorn makefile + makefile.amiga => Amiga makefile + smakefile.ppc => AMIGA smakefile for SAS C V6.58/7.00 PPC + compiler (Requires SCOPTIONS, copied from + scripts/SCOPTIONS.ppc) + makefile.atari => Atari makefile + makefile.beos => BEOS makefile for X86 + makefile.bor => Borland makefile (uses bcc) + makefile.bc32 => 32-bit Borland C++ (all modules compiled in C mode) + makefile.tc3 => Turbo C 3.0 makefile + makefile.dj2 => DJGPP 2 makefile + makefile.msc => Microsoft C makefile + makefile.vcawin32=> makefile for Microsoft Visual C++ 5.0 and + later (previously used assembler code tuned + for Intel MMX platform) + makefile.vcwin32 => makefile for Microsoft Visual C++ 4.0 and + later (does not use assembler code) + makefile.os2 => OS/2 Makefile (gcc and emx, requires pngos2.def) + pngos2.def => OS/2 module definition file used by makefile.os2 + makefile.watcom => Watcom 10a+ Makefile, 32-bit flat memory model + makevms.com => VMS build script + SCOPTIONS.ppc => Used with smakefile.ppc + +Good luck, and happy coding. + +-Glenn Randers-Pehrson (current maintainer, since 1998) + Internet: glennrp at users.sourceforge.net + +-Andreas Eric Dilger (former maintainer, 1996-1997) + Internet: adilger at enel.ucalgary.ca + Web: http://members.shaw.ca/adilger/ + +-Guy Eric Schalnat (original author and former maintainer, 1995-1996) + (formerly of Group 42, Inc) + Internet: gschal at infinet.com diff --git a/libs/libpng-src/TODO b/libs/libpng-src/TODO new file mode 100644 index 000000000..face7658c --- /dev/null +++ b/libs/libpng-src/TODO @@ -0,0 +1,25 @@ +TODO - list of things to do for libpng: + +Final bug fixes. +Improve API by hiding the png_struct and png_info structs. +Finish work on the no-floating-point version (including gamma compensation) +Better C++ wrapper/full C++ implementation? +Fix problem with C++ and EXTERN "C". +cHRM transformation. +Improve setjmp/longjmp usage or remove it in favor of returning error codes. +Add "grayscale->palette" transformation and "palette->grayscale" detection. +Improved dithering. +Multi-lingual error and warning message support. +Complete sRGB transformation (presently it simply uses gamma=0.45455). +Man pages for function calls. +Better documentation. +Better filter selection + (counting huffman bits/precompression? filter inertia? filter costs?). +Histogram creation. +Text conversion between different code pages (Latin-1 -> Mac and DOS). +Should we always malloc 2^bit_depth PLTE/tRNS/hIST entries for safety? +Build gamma tables using fixed point (and do away with floating point entirely). +Use greater precision when changing to linear gamma for compositing against + background and doing rgb-to-gray transformation. +Investigate pre-incremented loop counters and other loop constructions. +Add interpolated method of handling interlacing. diff --git a/libs/libpng-src/Y2KINFO b/libs/libpng-src/Y2KINFO new file mode 100644 index 000000000..0e2a92050 --- /dev/null +++ b/libs/libpng-src/Y2KINFO @@ -0,0 +1,55 @@ + Y2K compliance in libpng: + ========================= + + July 9, 2011 + + Since the PNG Development group is an ad-hoc body, we can't make + an official declaration. + + This is your unofficial assurance that libpng from version 0.71 and + upward through 1.2.46 are Y2K compliant. It is my belief that earlier + versions were also Y2K compliant. + + Libpng only has three year fields. One is a 2-byte unsigned integer + that will hold years up to 65535. The other two hold the date in text + format, and will hold years up to 9999. + + The integer is + "png_uint_16 year" in png_time_struct. + + The strings are + "png_charp time_buffer" in png_struct and + "near_time_buffer", which is a local character string in png.c. + + There are seven time-related functions: + + png_convert_to_rfc_1123() in png.c + (formerly png_convert_to_rfc_1152() in error) + png_convert_from_struct_tm() in pngwrite.c, called in pngwrite.c + png_convert_from_time_t() in pngwrite.c + png_get_tIME() in pngget.c + png_handle_tIME() in pngrutil.c, called in pngread.c + png_set_tIME() in pngset.c + png_write_tIME() in pngwutil.c, called in pngwrite.c + + All appear to handle dates properly in a Y2K environment. The + png_convert_from_time_t() function calls gmtime() to convert from system + clock time, which returns (year - 1900), which we properly convert to + the full 4-digit year. There is a possibility that applications using + libpng are not passing 4-digit years into the png_convert_to_rfc_1123() + function, or that they are incorrectly passing only a 2-digit year + instead of "year - 1900" into the png_convert_from_struct_tm() function, + but this is not under our control. The libpng documentation has always + stated that it works with 4-digit years, and the APIs have been + documented as such. + + The tIME chunk itself is also Y2K compliant. It uses a 2-byte unsigned + integer to hold the year, and can hold years as large as 65535. + + zlib, upon which libpng depends, is also Y2K compliant. It contains + no date-related code. + + + Glenn Randers-Pehrson + libpng maintainer + PNG Development Group diff --git a/libs/libpng-src/aclocal.m4 b/libs/libpng-src/aclocal.m4 new file mode 100644 index 000000000..27bc57cf4 --- /dev/null +++ b/libs/libpng-src/aclocal.m4 @@ -0,0 +1,8949 @@ +# generated automatically by aclocal 1.11 -*- Autoconf -*- + +# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, +# 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +m4_ifndef([AC_AUTOCONF_VERSION], + [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl +m4_if(m4_defn([AC_AUTOCONF_VERSION]), [2.65],, +[m4_warning([this file was generated for autoconf 2.65. +You have another version of autoconf. It may work, but is not guaranteed to. +If you have problems, you may need to regenerate the build system entirely. +To do so, use the procedure documented by the package, typically `autoreconf'.])]) + +# libtool.m4 - Configure libtool for the host system. -*-Autoconf-*- +# +# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, +# 2006, 2007, 2008 Free Software Foundation, Inc. +# Written by Gordon Matzigkeit, 1996 +# +# This file is free software; the Free Software Foundation gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. + +m4_define([_LT_COPYING], [dnl +# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, +# 2006, 2007, 2008 Free Software Foundation, Inc. +# Written by Gordon Matzigkeit, 1996 +# +# This file is part of GNU Libtool. +# +# GNU Libtool is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of +# the License, or (at your option) any later version. +# +# As a special exception to the GNU General Public License, +# if you distribute this file as part of a program or library that +# is built using GNU Libtool, you may include this file under the +# same distribution terms that you use for the rest of that program. +# +# GNU Libtool is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Libtool; see the file COPYING. If not, a copy +# can be downloaded from http://www.gnu.org/licenses/gpl.html, or +# obtained by writing to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +]) + +# serial 56 LT_INIT + + +# LT_PREREQ(VERSION) +# ------------------ +# Complain and exit if this libtool version is less that VERSION. +m4_defun([LT_PREREQ], +[m4_if(m4_version_compare(m4_defn([LT_PACKAGE_VERSION]), [$1]), -1, + [m4_default([$3], + [m4_fatal([Libtool version $1 or higher is required], + 63)])], + [$2])]) + + +# _LT_CHECK_BUILDDIR +# ------------------ +# Complain if the absolute build directory name contains unusual characters +m4_defun([_LT_CHECK_BUILDDIR], +[case `pwd` in + *\ * | *\ *) + AC_MSG_WARN([Libtool does not cope well with whitespace in `pwd`]) ;; +esac +]) + + +# LT_INIT([OPTIONS]) +# ------------------ +AC_DEFUN([LT_INIT], +[AC_PREREQ([2.58])dnl We use AC_INCLUDES_DEFAULT +AC_BEFORE([$0], [LT_LANG])dnl +AC_BEFORE([$0], [LT_OUTPUT])dnl +AC_BEFORE([$0], [LTDL_INIT])dnl +m4_require([_LT_CHECK_BUILDDIR])dnl + +dnl Autoconf doesn't catch unexpanded LT_ macros by default: +m4_pattern_forbid([^_?LT_[A-Z_]+$])dnl +m4_pattern_allow([^(_LT_EOF|LT_DLGLOBAL|LT_DLLAZY_OR_NOW|LT_MULTI_MODULE)$])dnl +dnl aclocal doesn't pull ltoptions.m4, ltsugar.m4, or ltversion.m4 +dnl unless we require an AC_DEFUNed macro: +AC_REQUIRE([LTOPTIONS_VERSION])dnl +AC_REQUIRE([LTSUGAR_VERSION])dnl +AC_REQUIRE([LTVERSION_VERSION])dnl +AC_REQUIRE([LTOBSOLETE_VERSION])dnl +m4_require([_LT_PROG_LTMAIN])dnl + +dnl Parse OPTIONS +_LT_SET_OPTIONS([$0], [$1]) + +# This can be used to rebuild libtool when needed +LIBTOOL_DEPS="$ltmain" + +# Always use our own libtool. +LIBTOOL='$(SHELL) $(top_builddir)/libtool' +AC_SUBST(LIBTOOL)dnl + +_LT_SETUP + +# Only expand once: +m4_define([LT_INIT]) +])# LT_INIT + +# Old names: +AU_ALIAS([AC_PROG_LIBTOOL], [LT_INIT]) +AU_ALIAS([AM_PROG_LIBTOOL], [LT_INIT]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_PROG_LIBTOOL], []) +dnl AC_DEFUN([AM_PROG_LIBTOOL], []) + + +# _LT_CC_BASENAME(CC) +# ------------------- +# Calculate cc_basename. Skip known compiler wrappers and cross-prefix. +m4_defun([_LT_CC_BASENAME], +[for cc_temp in $1""; do + case $cc_temp in + compile | *[[\\/]]compile | ccache | *[[\\/]]ccache ) ;; + distcc | *[[\\/]]distcc | purify | *[[\\/]]purify ) ;; + \-*) ;; + *) break;; + esac +done +cc_basename=`$ECHO "X$cc_temp" | $Xsed -e 's%.*/%%' -e "s%^$host_alias-%%"` +]) + + +# _LT_FILEUTILS_DEFAULTS +# ---------------------- +# It is okay to use these file commands and assume they have been set +# sensibly after `m4_require([_LT_FILEUTILS_DEFAULTS])'. +m4_defun([_LT_FILEUTILS_DEFAULTS], +[: ${CP="cp -f"} +: ${MV="mv -f"} +: ${RM="rm -f"} +])# _LT_FILEUTILS_DEFAULTS + + +# _LT_SETUP +# --------- +m4_defun([_LT_SETUP], +[AC_REQUIRE([AC_CANONICAL_HOST])dnl +AC_REQUIRE([AC_CANONICAL_BUILD])dnl +_LT_DECL([], [host_alias], [0], [The host system])dnl +_LT_DECL([], [host], [0])dnl +_LT_DECL([], [host_os], [0])dnl +dnl +_LT_DECL([], [build_alias], [0], [The build system])dnl +_LT_DECL([], [build], [0])dnl +_LT_DECL([], [build_os], [0])dnl +dnl +AC_REQUIRE([AC_PROG_CC])dnl +AC_REQUIRE([LT_PATH_LD])dnl +AC_REQUIRE([LT_PATH_NM])dnl +dnl +AC_REQUIRE([AC_PROG_LN_S])dnl +test -z "$LN_S" && LN_S="ln -s" +_LT_DECL([], [LN_S], [1], [Whether we need soft or hard links])dnl +dnl +AC_REQUIRE([LT_CMD_MAX_LEN])dnl +_LT_DECL([objext], [ac_objext], [0], [Object file suffix (normally "o")])dnl +_LT_DECL([], [exeext], [0], [Executable file suffix (normally "")])dnl +dnl +m4_require([_LT_FILEUTILS_DEFAULTS])dnl +m4_require([_LT_CHECK_SHELL_FEATURES])dnl +m4_require([_LT_CMD_RELOAD])dnl +m4_require([_LT_CHECK_MAGIC_METHOD])dnl +m4_require([_LT_CMD_OLD_ARCHIVE])dnl +m4_require([_LT_CMD_GLOBAL_SYMBOLS])dnl + +_LT_CONFIG_LIBTOOL_INIT([ +# See if we are running on zsh, and set the options which allow our +# commands through without removal of \ escapes INIT. +if test -n "\${ZSH_VERSION+set}" ; then + setopt NO_GLOB_SUBST +fi +]) +if test -n "${ZSH_VERSION+set}" ; then + setopt NO_GLOB_SUBST +fi + +_LT_CHECK_OBJDIR + +m4_require([_LT_TAG_COMPILER])dnl +_LT_PROG_ECHO_BACKSLASH + +case $host_os in +aix3*) + # AIX sometimes has problems with the GCC collect2 program. For some + # reason, if we set the COLLECT_NAMES environment variable, the problems + # vanish in a puff of smoke. + if test "X${COLLECT_NAMES+set}" != Xset; then + COLLECT_NAMES= + export COLLECT_NAMES + fi + ;; +esac + +# Sed substitution that helps us do robust quoting. It backslashifies +# metacharacters that are still active within double-quoted strings. +sed_quote_subst='s/\([["`$\\]]\)/\\\1/g' + +# Same as above, but do not quote variable references. +double_quote_subst='s/\([["`\\]]\)/\\\1/g' + +# Sed substitution to delay expansion of an escaped shell variable in a +# double_quote_subst'ed string. +delay_variable_subst='s/\\\\\\\\\\\$/\\\\\\$/g' + +# Sed substitution to delay expansion of an escaped single quote. +delay_single_quote_subst='s/'\''/'\'\\\\\\\'\''/g' + +# Sed substitution to avoid accidental globbing in evaled expressions +no_glob_subst='s/\*/\\\*/g' + +# Global variables: +ofile=libtool +can_build_shared=yes + +# All known linkers require a `.a' archive for static linking (except MSVC, +# which needs '.lib'). +libext=a + +with_gnu_ld="$lt_cv_prog_gnu_ld" + +old_CC="$CC" +old_CFLAGS="$CFLAGS" + +# Set sane defaults for various variables +test -z "$CC" && CC=cc +test -z "$LTCC" && LTCC=$CC +test -z "$LTCFLAGS" && LTCFLAGS=$CFLAGS +test -z "$LD" && LD=ld +test -z "$ac_objext" && ac_objext=o + +_LT_CC_BASENAME([$compiler]) + +# Only perform the check for file, if the check method requires it +test -z "$MAGIC_CMD" && MAGIC_CMD=file +case $deplibs_check_method in +file_magic*) + if test "$file_magic_cmd" = '$MAGIC_CMD'; then + _LT_PATH_MAGIC + fi + ;; +esac + +# Use C for the default configuration in the libtool script +LT_SUPPORTED_TAG([CC]) +_LT_LANG_C_CONFIG +_LT_LANG_DEFAULT_CONFIG +_LT_CONFIG_COMMANDS +])# _LT_SETUP + + +# _LT_PROG_LTMAIN +# --------------- +# Note that this code is called both from `configure', and `config.status' +# now that we use AC_CONFIG_COMMANDS to generate libtool. Notably, +# `config.status' has no value for ac_aux_dir unless we are using Automake, +# so we pass a copy along to make sure it has a sensible value anyway. +m4_defun([_LT_PROG_LTMAIN], +[m4_ifdef([AC_REQUIRE_AUX_FILE], [AC_REQUIRE_AUX_FILE([ltmain.sh])])dnl +_LT_CONFIG_LIBTOOL_INIT([ac_aux_dir='$ac_aux_dir']) +ltmain="$ac_aux_dir/ltmain.sh" +])# _LT_PROG_LTMAIN + + + +# So that we can recreate a full libtool script including additional +# tags, we accumulate the chunks of code to send to AC_CONFIG_COMMANDS +# in macros and then make a single call at the end using the `libtool' +# label. + + +# _LT_CONFIG_LIBTOOL_INIT([INIT-COMMANDS]) +# ---------------------------------------- +# Register INIT-COMMANDS to be passed to AC_CONFIG_COMMANDS later. +m4_define([_LT_CONFIG_LIBTOOL_INIT], +[m4_ifval([$1], + [m4_append([_LT_OUTPUT_LIBTOOL_INIT], + [$1 +])])]) + +# Initialize. +m4_define([_LT_OUTPUT_LIBTOOL_INIT]) + + +# _LT_CONFIG_LIBTOOL([COMMANDS]) +# ------------------------------ +# Register COMMANDS to be passed to AC_CONFIG_COMMANDS later. +m4_define([_LT_CONFIG_LIBTOOL], +[m4_ifval([$1], + [m4_append([_LT_OUTPUT_LIBTOOL_COMMANDS], + [$1 +])])]) + +# Initialize. +m4_define([_LT_OUTPUT_LIBTOOL_COMMANDS]) + + +# _LT_CONFIG_SAVE_COMMANDS([COMMANDS], [INIT_COMMANDS]) +# ----------------------------------------------------- +m4_defun([_LT_CONFIG_SAVE_COMMANDS], +[_LT_CONFIG_LIBTOOL([$1]) +_LT_CONFIG_LIBTOOL_INIT([$2]) +]) + + +# _LT_FORMAT_COMMENT([COMMENT]) +# ----------------------------- +# Add leading comment marks to the start of each line, and a trailing +# full-stop to the whole comment if one is not present already. +m4_define([_LT_FORMAT_COMMENT], +[m4_ifval([$1], [ +m4_bpatsubst([m4_bpatsubst([$1], [^ *], [# ])], + [['`$\]], [\\\&])]m4_bmatch([$1], [[!?.]$], [], [.]) +)]) + + + + + +# _LT_DECL([CONFIGNAME], VARNAME, VALUE, [DESCRIPTION], [IS-TAGGED?]) +# ------------------------------------------------------------------- +# CONFIGNAME is the name given to the value in the libtool script. +# VARNAME is the (base) name used in the configure script. +# VALUE may be 0, 1 or 2 for a computed quote escaped value based on +# VARNAME. Any other value will be used directly. +m4_define([_LT_DECL], +[lt_if_append_uniq([lt_decl_varnames], [$2], [, ], + [lt_dict_add_subkey([lt_decl_dict], [$2], [libtool_name], + [m4_ifval([$1], [$1], [$2])]) + lt_dict_add_subkey([lt_decl_dict], [$2], [value], [$3]) + m4_ifval([$4], + [lt_dict_add_subkey([lt_decl_dict], [$2], [description], [$4])]) + lt_dict_add_subkey([lt_decl_dict], [$2], + [tagged?], [m4_ifval([$5], [yes], [no])])]) +]) + + +# _LT_TAGDECL([CONFIGNAME], VARNAME, VALUE, [DESCRIPTION]) +# -------------------------------------------------------- +m4_define([_LT_TAGDECL], [_LT_DECL([$1], [$2], [$3], [$4], [yes])]) + + +# lt_decl_tag_varnames([SEPARATOR], [VARNAME1...]) +# ------------------------------------------------ +m4_define([lt_decl_tag_varnames], +[_lt_decl_filter([tagged?], [yes], $@)]) + + +# _lt_decl_filter(SUBKEY, VALUE, [SEPARATOR], [VARNAME1..]) +# --------------------------------------------------------- +m4_define([_lt_decl_filter], +[m4_case([$#], + [0], [m4_fatal([$0: too few arguments: $#])], + [1], [m4_fatal([$0: too few arguments: $#: $1])], + [2], [lt_dict_filter([lt_decl_dict], [$1], [$2], [], lt_decl_varnames)], + [3], [lt_dict_filter([lt_decl_dict], [$1], [$2], [$3], lt_decl_varnames)], + [lt_dict_filter([lt_decl_dict], $@)])[]dnl +]) + + +# lt_decl_quote_varnames([SEPARATOR], [VARNAME1...]) +# -------------------------------------------------- +m4_define([lt_decl_quote_varnames], +[_lt_decl_filter([value], [1], $@)]) + + +# lt_decl_dquote_varnames([SEPARATOR], [VARNAME1...]) +# --------------------------------------------------- +m4_define([lt_decl_dquote_varnames], +[_lt_decl_filter([value], [2], $@)]) + + +# lt_decl_varnames_tagged([SEPARATOR], [VARNAME1...]) +# --------------------------------------------------- +m4_define([lt_decl_varnames_tagged], +[m4_assert([$# <= 2])dnl +_$0(m4_quote(m4_default([$1], [[, ]])), + m4_ifval([$2], [[$2]], [m4_dquote(lt_decl_tag_varnames)]), + m4_split(m4_normalize(m4_quote(_LT_TAGS)), [ ]))]) +m4_define([_lt_decl_varnames_tagged], +[m4_ifval([$3], [lt_combine([$1], [$2], [_], $3)])]) + + +# lt_decl_all_varnames([SEPARATOR], [VARNAME1...]) +# ------------------------------------------------ +m4_define([lt_decl_all_varnames], +[_$0(m4_quote(m4_default([$1], [[, ]])), + m4_if([$2], [], + m4_quote(lt_decl_varnames), + m4_quote(m4_shift($@))))[]dnl +]) +m4_define([_lt_decl_all_varnames], +[lt_join($@, lt_decl_varnames_tagged([$1], + lt_decl_tag_varnames([[, ]], m4_shift($@))))dnl +]) + + +# _LT_CONFIG_STATUS_DECLARE([VARNAME]) +# ------------------------------------ +# Quote a variable value, and forward it to `config.status' so that its +# declaration there will have the same value as in `configure'. VARNAME +# must have a single quote delimited value for this to work. +m4_define([_LT_CONFIG_STATUS_DECLARE], +[$1='`$ECHO "X$][$1" | $Xsed -e "$delay_single_quote_subst"`']) + + +# _LT_CONFIG_STATUS_DECLARATIONS +# ------------------------------ +# We delimit libtool config variables with single quotes, so when +# we write them to config.status, we have to be sure to quote all +# embedded single quotes properly. In configure, this macro expands +# each variable declared with _LT_DECL (and _LT_TAGDECL) into: +# +# ='`$ECHO "X$" | $Xsed -e "$delay_single_quote_subst"`' +m4_defun([_LT_CONFIG_STATUS_DECLARATIONS], +[m4_foreach([_lt_var], m4_quote(lt_decl_all_varnames), + [m4_n([_LT_CONFIG_STATUS_DECLARE(_lt_var)])])]) + + +# _LT_LIBTOOL_TAGS +# ---------------- +# Output comment and list of tags supported by the script +m4_defun([_LT_LIBTOOL_TAGS], +[_LT_FORMAT_COMMENT([The names of the tagged configurations supported by this script])dnl +available_tags="_LT_TAGS"dnl +]) + + +# _LT_LIBTOOL_DECLARE(VARNAME, [TAG]) +# ----------------------------------- +# Extract the dictionary values for VARNAME (optionally with TAG) and +# expand to a commented shell variable setting: +# +# # Some comment about what VAR is for. +# visible_name=$lt_internal_name +m4_define([_LT_LIBTOOL_DECLARE], +[_LT_FORMAT_COMMENT(m4_quote(lt_dict_fetch([lt_decl_dict], [$1], + [description])))[]dnl +m4_pushdef([_libtool_name], + m4_quote(lt_dict_fetch([lt_decl_dict], [$1], [libtool_name])))[]dnl +m4_case(m4_quote(lt_dict_fetch([lt_decl_dict], [$1], [value])), + [0], [_libtool_name=[$]$1], + [1], [_libtool_name=$lt_[]$1], + [2], [_libtool_name=$lt_[]$1], + [_libtool_name=lt_dict_fetch([lt_decl_dict], [$1], [value])])[]dnl +m4_ifval([$2], [_$2])[]m4_popdef([_libtool_name])[]dnl +]) + + +# _LT_LIBTOOL_CONFIG_VARS +# ----------------------- +# Produce commented declarations of non-tagged libtool config variables +# suitable for insertion in the LIBTOOL CONFIG section of the `libtool' +# script. Tagged libtool config variables (even for the LIBTOOL CONFIG +# section) are produced by _LT_LIBTOOL_TAG_VARS. +m4_defun([_LT_LIBTOOL_CONFIG_VARS], +[m4_foreach([_lt_var], + m4_quote(_lt_decl_filter([tagged?], [no], [], lt_decl_varnames)), + [m4_n([_LT_LIBTOOL_DECLARE(_lt_var)])])]) + + +# _LT_LIBTOOL_TAG_VARS(TAG) +# ------------------------- +m4_define([_LT_LIBTOOL_TAG_VARS], +[m4_foreach([_lt_var], m4_quote(lt_decl_tag_varnames), + [m4_n([_LT_LIBTOOL_DECLARE(_lt_var, [$1])])])]) + + +# _LT_TAGVAR(VARNAME, [TAGNAME]) +# ------------------------------ +m4_define([_LT_TAGVAR], [m4_ifval([$2], [$1_$2], [$1])]) + + +# _LT_CONFIG_COMMANDS +# ------------------- +# Send accumulated output to $CONFIG_STATUS. Thanks to the lists of +# variables for single and double quote escaping we saved from calls +# to _LT_DECL, we can put quote escaped variables declarations +# into `config.status', and then the shell code to quote escape them in +# for loops in `config.status'. Finally, any additional code accumulated +# from calls to _LT_CONFIG_LIBTOOL_INIT is expanded. +m4_defun([_LT_CONFIG_COMMANDS], +[AC_PROVIDE_IFELSE([LT_OUTPUT], + dnl If the libtool generation code has been placed in $CONFIG_LT, + dnl instead of duplicating it all over again into config.status, + dnl then we will have config.status run $CONFIG_LT later, so it + dnl needs to know what name is stored there: + [AC_CONFIG_COMMANDS([libtool], + [$SHELL $CONFIG_LT || AS_EXIT(1)], [CONFIG_LT='$CONFIG_LT'])], + dnl If the libtool generation code is destined for config.status, + dnl expand the accumulated commands and init code now: + [AC_CONFIG_COMMANDS([libtool], + [_LT_OUTPUT_LIBTOOL_COMMANDS], [_LT_OUTPUT_LIBTOOL_COMMANDS_INIT])]) +])#_LT_CONFIG_COMMANDS + + +# Initialize. +m4_define([_LT_OUTPUT_LIBTOOL_COMMANDS_INIT], +[ + +# The HP-UX ksh and POSIX shell print the target directory to stdout +# if CDPATH is set. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + +sed_quote_subst='$sed_quote_subst' +double_quote_subst='$double_quote_subst' +delay_variable_subst='$delay_variable_subst' +_LT_CONFIG_STATUS_DECLARATIONS +LTCC='$LTCC' +LTCFLAGS='$LTCFLAGS' +compiler='$compiler_DEFAULT' + +# Quote evaled strings. +for var in lt_decl_all_varnames([[ \ +]], lt_decl_quote_varnames); do + case \`eval \\\\\$ECHO "X\\\\\$\$var"\` in + *[[\\\\\\\`\\"\\\$]]*) + eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"X\\\$\$var\\" | \\\$Xsed -e \\"\\\$sed_quote_subst\\"\\\`\\\\\\"" + ;; + *) + eval "lt_\$var=\\\\\\"\\\$\$var\\\\\\"" + ;; + esac +done + +# Double-quote double-evaled strings. +for var in lt_decl_all_varnames([[ \ +]], lt_decl_dquote_varnames); do + case \`eval \\\\\$ECHO "X\\\\\$\$var"\` in + *[[\\\\\\\`\\"\\\$]]*) + eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"X\\\$\$var\\" | \\\$Xsed -e \\"\\\$double_quote_subst\\" -e \\"\\\$sed_quote_subst\\" -e \\"\\\$delay_variable_subst\\"\\\`\\\\\\"" + ;; + *) + eval "lt_\$var=\\\\\\"\\\$\$var\\\\\\"" + ;; + esac +done + +# Fix-up fallback echo if it was mangled by the above quoting rules. +case \$lt_ECHO in +*'\\\[$]0 --fallback-echo"')dnl " + lt_ECHO=\`\$ECHO "X\$lt_ECHO" | \$Xsed -e 's/\\\\\\\\\\\\\\\[$]0 --fallback-echo"\[$]/\[$]0 --fallback-echo"/'\` + ;; +esac + +_LT_OUTPUT_LIBTOOL_INIT +]) + + +# LT_OUTPUT +# --------- +# This macro allows early generation of the libtool script (before +# AC_OUTPUT is called), incase it is used in configure for compilation +# tests. +AC_DEFUN([LT_OUTPUT], +[: ${CONFIG_LT=./config.lt} +AC_MSG_NOTICE([creating $CONFIG_LT]) +cat >"$CONFIG_LT" <<_LTEOF +#! $SHELL +# Generated by $as_me. +# Run this file to recreate a libtool stub with the current configuration. + +lt_cl_silent=false +SHELL=\${CONFIG_SHELL-$SHELL} +_LTEOF + +cat >>"$CONFIG_LT" <<\_LTEOF +AS_SHELL_SANITIZE +_AS_PREPARE + +exec AS_MESSAGE_FD>&1 +exec AS_MESSAGE_LOG_FD>>config.log +{ + echo + AS_BOX([Running $as_me.]) +} >&AS_MESSAGE_LOG_FD + +lt_cl_help="\ +\`$as_me' creates a local libtool stub from the current configuration, +for use in further configure time tests before the real libtool is +generated. + +Usage: $[0] [[OPTIONS]] + + -h, --help print this help, then exit + -V, --version print version number, then exit + -q, --quiet do not print progress messages + -d, --debug don't remove temporary files + +Report bugs to ." + +lt_cl_version="\ +m4_ifset([AC_PACKAGE_NAME], [AC_PACKAGE_NAME ])config.lt[]dnl +m4_ifset([AC_PACKAGE_VERSION], [ AC_PACKAGE_VERSION]) +configured by $[0], generated by m4_PACKAGE_STRING. + +Copyright (C) 2008 Free Software Foundation, Inc. +This config.lt script is free software; the Free Software Foundation +gives unlimited permision to copy, distribute and modify it." + +while test $[#] != 0 +do + case $[1] in + --version | --v* | -V ) + echo "$lt_cl_version"; exit 0 ;; + --help | --h* | -h ) + echo "$lt_cl_help"; exit 0 ;; + --debug | --d* | -d ) + debug=: ;; + --quiet | --q* | --silent | --s* | -q ) + lt_cl_silent=: ;; + + -*) AC_MSG_ERROR([unrecognized option: $[1] +Try \`$[0] --help' for more information.]) ;; + + *) AC_MSG_ERROR([unrecognized argument: $[1] +Try \`$[0] --help' for more information.]) ;; + esac + shift +done + +if $lt_cl_silent; then + exec AS_MESSAGE_FD>/dev/null +fi +_LTEOF + +cat >>"$CONFIG_LT" <<_LTEOF +_LT_OUTPUT_LIBTOOL_COMMANDS_INIT +_LTEOF + +cat >>"$CONFIG_LT" <<\_LTEOF +AC_MSG_NOTICE([creating $ofile]) +_LT_OUTPUT_LIBTOOL_COMMANDS +AS_EXIT(0) +_LTEOF +chmod +x "$CONFIG_LT" + +# configure is writing to config.log, but config.lt does its own redirection, +# appending to config.log, which fails on DOS, as config.log is still kept +# open by configure. Here we exec the FD to /dev/null, effectively closing +# config.log, so it can be properly (re)opened and appended to by config.lt. +if test "$no_create" != yes; then + lt_cl_success=: + test "$silent" = yes && + lt_config_lt_args="$lt_config_lt_args --quiet" + exec AS_MESSAGE_LOG_FD>/dev/null + $SHELL "$CONFIG_LT" $lt_config_lt_args || lt_cl_success=false + exec AS_MESSAGE_LOG_FD>>config.log + $lt_cl_success || AS_EXIT(1) +fi +])# LT_OUTPUT + + +# _LT_CONFIG(TAG) +# --------------- +# If TAG is the built-in tag, create an initial libtool script with a +# default configuration from the untagged config vars. Otherwise add code +# to config.status for appending the configuration named by TAG from the +# matching tagged config vars. +m4_defun([_LT_CONFIG], +[m4_require([_LT_FILEUTILS_DEFAULTS])dnl +_LT_CONFIG_SAVE_COMMANDS([ + m4_define([_LT_TAG], m4_if([$1], [], [C], [$1]))dnl + m4_if(_LT_TAG, [C], [ + # See if we are running on zsh, and set the options which allow our + # commands through without removal of \ escapes. + if test -n "${ZSH_VERSION+set}" ; then + setopt NO_GLOB_SUBST + fi + + cfgfile="${ofile}T" + trap "$RM \"$cfgfile\"; exit 1" 1 2 15 + $RM "$cfgfile" + + cat <<_LT_EOF >> "$cfgfile" +#! $SHELL + +# `$ECHO "$ofile" | sed 's%^.*/%%'` - Provide generalized library-building support services. +# Generated automatically by $as_me ($PACKAGE$TIMESTAMP) $VERSION +# Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`: +# NOTE: Changes made to this file will be lost: look at ltmain.sh. +# +_LT_COPYING +_LT_LIBTOOL_TAGS + +# ### BEGIN LIBTOOL CONFIG +_LT_LIBTOOL_CONFIG_VARS +_LT_LIBTOOL_TAG_VARS +# ### END LIBTOOL CONFIG + +_LT_EOF + + case $host_os in + aix3*) + cat <<\_LT_EOF >> "$cfgfile" +# AIX sometimes has problems with the GCC collect2 program. For some +# reason, if we set the COLLECT_NAMES environment variable, the problems +# vanish in a puff of smoke. +if test "X${COLLECT_NAMES+set}" != Xset; then + COLLECT_NAMES= + export COLLECT_NAMES +fi +_LT_EOF + ;; + esac + + _LT_PROG_LTMAIN + + # We use sed instead of cat because bash on DJGPP gets confused if + # if finds mixed CR/LF and LF-only lines. Since sed operates in + # text mode, it properly converts lines to CR/LF. This bash problem + # is reportedly fixed, but why not run on old versions too? + sed '/^# Generated shell functions inserted here/q' "$ltmain" >> "$cfgfile" \ + || (rm -f "$cfgfile"; exit 1) + + _LT_PROG_XSI_SHELLFNS + + sed -n '/^# Generated shell functions inserted here/,$p' "$ltmain" >> "$cfgfile" \ + || (rm -f "$cfgfile"; exit 1) + + mv -f "$cfgfile" "$ofile" || + (rm -f "$ofile" && cp "$cfgfile" "$ofile" && rm -f "$cfgfile") + chmod +x "$ofile" +], +[cat <<_LT_EOF >> "$ofile" + +dnl Unfortunately we have to use $1 here, since _LT_TAG is not expanded +dnl in a comment (ie after a #). +# ### BEGIN LIBTOOL TAG CONFIG: $1 +_LT_LIBTOOL_TAG_VARS(_LT_TAG) +# ### END LIBTOOL TAG CONFIG: $1 +_LT_EOF +])dnl /m4_if +], +[m4_if([$1], [], [ + PACKAGE='$PACKAGE' + VERSION='$VERSION' + TIMESTAMP='$TIMESTAMP' + RM='$RM' + ofile='$ofile'], []) +])dnl /_LT_CONFIG_SAVE_COMMANDS +])# _LT_CONFIG + + +# LT_SUPPORTED_TAG(TAG) +# --------------------- +# Trace this macro to discover what tags are supported by the libtool +# --tag option, using: +# autoconf --trace 'LT_SUPPORTED_TAG:$1' +AC_DEFUN([LT_SUPPORTED_TAG], []) + + +# C support is built-in for now +m4_define([_LT_LANG_C_enabled], []) +m4_define([_LT_TAGS], []) + + +# LT_LANG(LANG) +# ------------- +# Enable libtool support for the given language if not already enabled. +AC_DEFUN([LT_LANG], +[AC_BEFORE([$0], [LT_OUTPUT])dnl +m4_case([$1], + [C], [_LT_LANG(C)], + [C++], [_LT_LANG(CXX)], + [Java], [_LT_LANG(GCJ)], + [Fortran 77], [_LT_LANG(F77)], + [Fortran], [_LT_LANG(FC)], + [Windows Resource], [_LT_LANG(RC)], + [m4_ifdef([_LT_LANG_]$1[_CONFIG], + [_LT_LANG($1)], + [m4_fatal([$0: unsupported language: "$1"])])])dnl +])# LT_LANG + + +# _LT_LANG(LANGNAME) +# ------------------ +m4_defun([_LT_LANG], +[m4_ifdef([_LT_LANG_]$1[_enabled], [], + [LT_SUPPORTED_TAG([$1])dnl + m4_append([_LT_TAGS], [$1 ])dnl + m4_define([_LT_LANG_]$1[_enabled], [])dnl + _LT_LANG_$1_CONFIG($1)])dnl +])# _LT_LANG + + +# _LT_LANG_DEFAULT_CONFIG +# ----------------------- +m4_defun([_LT_LANG_DEFAULT_CONFIG], +[AC_PROVIDE_IFELSE([AC_PROG_CXX], + [LT_LANG(CXX)], + [m4_define([AC_PROG_CXX], defn([AC_PROG_CXX])[LT_LANG(CXX)])]) + +AC_PROVIDE_IFELSE([AC_PROG_F77], + [LT_LANG(F77)], + [m4_define([AC_PROG_F77], defn([AC_PROG_F77])[LT_LANG(F77)])]) + +AC_PROVIDE_IFELSE([AC_PROG_FC], + [LT_LANG(FC)], + [m4_define([AC_PROG_FC], defn([AC_PROG_FC])[LT_LANG(FC)])]) + +dnl The call to [A][M_PROG_GCJ] is quoted like that to stop aclocal +dnl pulling things in needlessly. +AC_PROVIDE_IFELSE([AC_PROG_GCJ], + [LT_LANG(GCJ)], + [AC_PROVIDE_IFELSE([A][M_PROG_GCJ], + [LT_LANG(GCJ)], + [AC_PROVIDE_IFELSE([LT_PROG_GCJ], + [LT_LANG(GCJ)], + [m4_ifdef([AC_PROG_GCJ], + [m4_define([AC_PROG_GCJ], defn([AC_PROG_GCJ])[LT_LANG(GCJ)])]) + m4_ifdef([A][M_PROG_GCJ], + [m4_define([A][M_PROG_GCJ], defn([A][M_PROG_GCJ])[LT_LANG(GCJ)])]) + m4_ifdef([LT_PROG_GCJ], + [m4_define([LT_PROG_GCJ], defn([LT_PROG_GCJ])[LT_LANG(GCJ)])])])])]) + +AC_PROVIDE_IFELSE([LT_PROG_RC], + [LT_LANG(RC)], + [m4_define([LT_PROG_RC], defn([LT_PROG_RC])[LT_LANG(RC)])]) +])# _LT_LANG_DEFAULT_CONFIG + +# Obsolete macros: +AU_DEFUN([AC_LIBTOOL_CXX], [LT_LANG(C++)]) +AU_DEFUN([AC_LIBTOOL_F77], [LT_LANG(Fortran 77)]) +AU_DEFUN([AC_LIBTOOL_FC], [LT_LANG(Fortran)]) +AU_DEFUN([AC_LIBTOOL_GCJ], [LT_LANG(Java)]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_CXX], []) +dnl AC_DEFUN([AC_LIBTOOL_F77], []) +dnl AC_DEFUN([AC_LIBTOOL_FC], []) +dnl AC_DEFUN([AC_LIBTOOL_GCJ], []) + + +# _LT_TAG_COMPILER +# ---------------- +m4_defun([_LT_TAG_COMPILER], +[AC_REQUIRE([AC_PROG_CC])dnl + +_LT_DECL([LTCC], [CC], [1], [A C compiler])dnl +_LT_DECL([LTCFLAGS], [CFLAGS], [1], [LTCC compiler flags])dnl +_LT_TAGDECL([CC], [compiler], [1], [A language specific compiler])dnl +_LT_TAGDECL([with_gcc], [GCC], [0], [Is the compiler the GNU compiler?])dnl + +# If no C compiler was specified, use CC. +LTCC=${LTCC-"$CC"} + +# If no C compiler flags were specified, use CFLAGS. +LTCFLAGS=${LTCFLAGS-"$CFLAGS"} + +# Allow CC to be a program name with arguments. +compiler=$CC +])# _LT_TAG_COMPILER + + +# _LT_COMPILER_BOILERPLATE +# ------------------------ +# Check for compiler boilerplate output or warnings with +# the simple compiler test code. +m4_defun([_LT_COMPILER_BOILERPLATE], +[m4_require([_LT_DECL_SED])dnl +ac_outfile=conftest.$ac_objext +echo "$lt_simple_compile_test_code" >conftest.$ac_ext +eval "$ac_compile" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err +_lt_compiler_boilerplate=`cat conftest.err` +$RM conftest* +])# _LT_COMPILER_BOILERPLATE + + +# _LT_LINKER_BOILERPLATE +# ---------------------- +# Check for linker boilerplate output or warnings with +# the simple link test code. +m4_defun([_LT_LINKER_BOILERPLATE], +[m4_require([_LT_DECL_SED])dnl +ac_outfile=conftest.$ac_objext +echo "$lt_simple_link_test_code" >conftest.$ac_ext +eval "$ac_link" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err +_lt_linker_boilerplate=`cat conftest.err` +$RM -r conftest* +])# _LT_LINKER_BOILERPLATE + +# _LT_REQUIRED_DARWIN_CHECKS +# ------------------------- +m4_defun_once([_LT_REQUIRED_DARWIN_CHECKS],[ + case $host_os in + rhapsody* | darwin*) + AC_CHECK_TOOL([DSYMUTIL], [dsymutil], [:]) + AC_CHECK_TOOL([NMEDIT], [nmedit], [:]) + AC_CHECK_TOOL([LIPO], [lipo], [:]) + AC_CHECK_TOOL([OTOOL], [otool], [:]) + AC_CHECK_TOOL([OTOOL64], [otool64], [:]) + _LT_DECL([], [DSYMUTIL], [1], + [Tool to manipulate archived DWARF debug symbol files on Mac OS X]) + _LT_DECL([], [NMEDIT], [1], + [Tool to change global to local symbols on Mac OS X]) + _LT_DECL([], [LIPO], [1], + [Tool to manipulate fat objects and archives on Mac OS X]) + _LT_DECL([], [OTOOL], [1], + [ldd/readelf like tool for Mach-O binaries on Mac OS X]) + _LT_DECL([], [OTOOL64], [1], + [ldd/readelf like tool for 64 bit Mach-O binaries on Mac OS X 10.4]) + + AC_CACHE_CHECK([for -single_module linker flag],[lt_cv_apple_cc_single_mod], + [lt_cv_apple_cc_single_mod=no + if test -z "${LT_MULTI_MODULE}"; then + # By default we will add the -single_module flag. You can override + # by either setting the environment variable LT_MULTI_MODULE + # non-empty at configure time, or by adding -multi_module to the + # link flags. + rm -rf libconftest.dylib* + echo "int foo(void){return 1;}" > conftest.c + echo "$LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \ +-dynamiclib -Wl,-single_module conftest.c" >&AS_MESSAGE_LOG_FD + $LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \ + -dynamiclib -Wl,-single_module conftest.c 2>conftest.err + _lt_result=$? + if test -f libconftest.dylib && test ! -s conftest.err && test $_lt_result = 0; then + lt_cv_apple_cc_single_mod=yes + else + cat conftest.err >&AS_MESSAGE_LOG_FD + fi + rm -rf libconftest.dylib* + rm -f conftest.* + fi]) + AC_CACHE_CHECK([for -exported_symbols_list linker flag], + [lt_cv_ld_exported_symbols_list], + [lt_cv_ld_exported_symbols_list=no + save_LDFLAGS=$LDFLAGS + echo "_main" > conftest.sym + LDFLAGS="$LDFLAGS -Wl,-exported_symbols_list,conftest.sym" + AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], + [lt_cv_ld_exported_symbols_list=yes], + [lt_cv_ld_exported_symbols_list=no]) + LDFLAGS="$save_LDFLAGS" + ]) + case $host_os in + rhapsody* | darwin1.[[012]]) + _lt_dar_allow_undefined='${wl}-undefined ${wl}suppress' ;; + darwin1.*) + _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' ;; + darwin*) # darwin 5.x on + # if running on 10.5 or later, the deployment target defaults + # to the OS version, if on x86, and 10.4, the deployment + # target defaults to 10.4. Don't you love it? + case ${MACOSX_DEPLOYMENT_TARGET-10.0},$host in + 10.0,*86*-darwin8*|10.0,*-darwin[[91]]*) + _lt_dar_allow_undefined='${wl}-undefined ${wl}dynamic_lookup' ;; + 10.[[012]]*) + _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' ;; + 10.*) + _lt_dar_allow_undefined='${wl}-undefined ${wl}dynamic_lookup' ;; + esac + ;; + esac + if test "$lt_cv_apple_cc_single_mod" = "yes"; then + _lt_dar_single_mod='$single_module' + fi + if test "$lt_cv_ld_exported_symbols_list" = "yes"; then + _lt_dar_export_syms=' ${wl}-exported_symbols_list,$output_objdir/${libname}-symbols.expsym' + else + _lt_dar_export_syms='~$NMEDIT -s $output_objdir/${libname}-symbols.expsym ${lib}' + fi + if test "$DSYMUTIL" != ":"; then + _lt_dsymutil='~$DSYMUTIL $lib || :' + else + _lt_dsymutil= + fi + ;; + esac +]) + + +# _LT_DARWIN_LINKER_FEATURES +# -------------------------- +# Checks for linker and compiler features on darwin +m4_defun([_LT_DARWIN_LINKER_FEATURES], +[ + m4_require([_LT_REQUIRED_DARWIN_CHECKS]) + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + _LT_TAGVAR(hardcode_direct, $1)=no + _LT_TAGVAR(hardcode_automatic, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=unsupported + _LT_TAGVAR(whole_archive_flag_spec, $1)='' + _LT_TAGVAR(link_all_deplibs, $1)=yes + _LT_TAGVAR(allow_undefined_flag, $1)="$_lt_dar_allow_undefined" + case $cc_basename in + ifort*) _lt_dar_can_shared=yes ;; + *) _lt_dar_can_shared=$GCC ;; + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=echo + _LT_TAGVAR(archive_cmds, $1)="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" + _LT_TAGVAR(module_cmds, $1)="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" + _LT_TAGVAR(archive_expsym_cmds, $1)="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" + _LT_TAGVAR(module_expsym_cmds, $1)="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + m4_if([$1], [CXX], +[ if test "$lt_cv_apple_cc_single_mod" != "yes"; then + _LT_TAGVAR(archive_cmds, $1)="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dsymutil}" + _LT_TAGVAR(archive_expsym_cmds, $1)="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dar_export_syms}${_lt_dsymutil}" + fi +],[]) + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi +]) + +# _LT_SYS_MODULE_PATH_AIX +# ----------------------- +# Links a minimal program and checks the executable +# for the system default hardcoded library path. In most cases, +# this is /usr/lib:/lib, but when the MPI compilers are used +# the location of the communication and MPI libs are included too. +# If we don't find anything, use the default library path according +# to the aix ld manual. +m4_defun([_LT_SYS_MODULE_PATH_AIX], +[m4_require([_LT_DECL_SED])dnl +AC_LINK_IFELSE(AC_LANG_PROGRAM,[ +lt_aix_libpath_sed=' + /Import File Strings/,/^$/ { + /^0/ { + s/^0 *\(.*\)$/\1/ + p + } + }' +aix_libpath=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` +# Check for a 64-bit object if we didn't find anything. +if test -z "$aix_libpath"; then + aix_libpath=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` +fi],[]) +if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi +])# _LT_SYS_MODULE_PATH_AIX + + +# _LT_SHELL_INIT(ARG) +# ------------------- +m4_define([_LT_SHELL_INIT], +[ifdef([AC_DIVERSION_NOTICE], + [AC_DIVERT_PUSH(AC_DIVERSION_NOTICE)], + [AC_DIVERT_PUSH(NOTICE)]) +$1 +AC_DIVERT_POP +])# _LT_SHELL_INIT + + +# _LT_PROG_ECHO_BACKSLASH +# ----------------------- +# Add some code to the start of the generated configure script which +# will find an echo command which doesn't interpret backslashes. +m4_defun([_LT_PROG_ECHO_BACKSLASH], +[_LT_SHELL_INIT([ +# Check that we are running under the correct shell. +SHELL=${CONFIG_SHELL-/bin/sh} + +case X$lt_ECHO in +X*--fallback-echo) + # Remove one level of quotation (which was required for Make). + ECHO=`echo "$lt_ECHO" | sed 's,\\\\\[$]\\[$]0,'[$]0','` + ;; +esac + +ECHO=${lt_ECHO-echo} +if test "X[$]1" = X--no-reexec; then + # Discard the --no-reexec flag, and continue. + shift +elif test "X[$]1" = X--fallback-echo; then + # Avoid inline document here, it may be left over + : +elif test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t' ; then + # Yippee, $ECHO works! + : +else + # Restart under the correct shell. + exec $SHELL "[$]0" --no-reexec ${1+"[$]@"} +fi + +if test "X[$]1" = X--fallback-echo; then + # used as fallback echo + shift + cat <<_LT_EOF +[$]* +_LT_EOF + exit 0 +fi + +# The HP-UX ksh and POSIX shell print the target directory to stdout +# if CDPATH is set. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + +if test -z "$lt_ECHO"; then + if test "X${echo_test_string+set}" != Xset; then + # find a string as large as possible, as long as the shell can cope with it + for cmd in 'sed 50q "[$]0"' 'sed 20q "[$]0"' 'sed 10q "[$]0"' 'sed 2q "[$]0"' 'echo test'; do + # expected sizes: less than 2Kb, 1Kb, 512 bytes, 16 bytes, ... + if { echo_test_string=`eval $cmd`; } 2>/dev/null && + { test "X$echo_test_string" = "X$echo_test_string"; } 2>/dev/null + then + break + fi + done + fi + + if test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t' && + echo_testing_string=`{ $ECHO "$echo_test_string"; } 2>/dev/null` && + test "X$echo_testing_string" = "X$echo_test_string"; then + : + else + # The Solaris, AIX, and Digital Unix default echo programs unquote + # backslashes. This makes it impossible to quote backslashes using + # echo "$something" | sed 's/\\/\\\\/g' + # + # So, first we look for a working echo in the user's PATH. + + lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR + for dir in $PATH /usr/ucb; do + IFS="$lt_save_ifs" + if (test -f $dir/echo || test -f $dir/echo$ac_exeext) && + test "X`($dir/echo '\t') 2>/dev/null`" = 'X\t' && + echo_testing_string=`($dir/echo "$echo_test_string") 2>/dev/null` && + test "X$echo_testing_string" = "X$echo_test_string"; then + ECHO="$dir/echo" + break + fi + done + IFS="$lt_save_ifs" + + if test "X$ECHO" = Xecho; then + # We didn't find a better echo, so look for alternatives. + if test "X`{ print -r '\t'; } 2>/dev/null`" = 'X\t' && + echo_testing_string=`{ print -r "$echo_test_string"; } 2>/dev/null` && + test "X$echo_testing_string" = "X$echo_test_string"; then + # This shell has a builtin print -r that does the trick. + ECHO='print -r' + elif { test -f /bin/ksh || test -f /bin/ksh$ac_exeext; } && + test "X$CONFIG_SHELL" != X/bin/ksh; then + # If we have ksh, try running configure again with it. + ORIGINAL_CONFIG_SHELL=${CONFIG_SHELL-/bin/sh} + export ORIGINAL_CONFIG_SHELL + CONFIG_SHELL=/bin/ksh + export CONFIG_SHELL + exec $CONFIG_SHELL "[$]0" --no-reexec ${1+"[$]@"} + else + # Try using printf. + ECHO='printf %s\n' + if test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t' && + echo_testing_string=`{ $ECHO "$echo_test_string"; } 2>/dev/null` && + test "X$echo_testing_string" = "X$echo_test_string"; then + # Cool, printf works + : + elif echo_testing_string=`($ORIGINAL_CONFIG_SHELL "[$]0" --fallback-echo '\t') 2>/dev/null` && + test "X$echo_testing_string" = 'X\t' && + echo_testing_string=`($ORIGINAL_CONFIG_SHELL "[$]0" --fallback-echo "$echo_test_string") 2>/dev/null` && + test "X$echo_testing_string" = "X$echo_test_string"; then + CONFIG_SHELL=$ORIGINAL_CONFIG_SHELL + export CONFIG_SHELL + SHELL="$CONFIG_SHELL" + export SHELL + ECHO="$CONFIG_SHELL [$]0 --fallback-echo" + elif echo_testing_string=`($CONFIG_SHELL "[$]0" --fallback-echo '\t') 2>/dev/null` && + test "X$echo_testing_string" = 'X\t' && + echo_testing_string=`($CONFIG_SHELL "[$]0" --fallback-echo "$echo_test_string") 2>/dev/null` && + test "X$echo_testing_string" = "X$echo_test_string"; then + ECHO="$CONFIG_SHELL [$]0 --fallback-echo" + else + # maybe with a smaller string... + prev=: + + for cmd in 'echo test' 'sed 2q "[$]0"' 'sed 10q "[$]0"' 'sed 20q "[$]0"' 'sed 50q "[$]0"'; do + if { test "X$echo_test_string" = "X`eval $cmd`"; } 2>/dev/null + then + break + fi + prev="$cmd" + done + + if test "$prev" != 'sed 50q "[$]0"'; then + echo_test_string=`eval $prev` + export echo_test_string + exec ${ORIGINAL_CONFIG_SHELL-${CONFIG_SHELL-/bin/sh}} "[$]0" ${1+"[$]@"} + else + # Oops. We lost completely, so just stick with echo. + ECHO=echo + fi + fi + fi + fi + fi +fi + +# Copy echo and quote the copy suitably for passing to libtool from +# the Makefile, instead of quoting the original, which is used later. +lt_ECHO=$ECHO +if test "X$lt_ECHO" = "X$CONFIG_SHELL [$]0 --fallback-echo"; then + lt_ECHO="$CONFIG_SHELL \\\$\[$]0 --fallback-echo" +fi + +AC_SUBST(lt_ECHO) +]) +_LT_DECL([], [SHELL], [1], [Shell to use when invoking shell scripts]) +_LT_DECL([], [ECHO], [1], + [An echo program that does not interpret backslashes]) +])# _LT_PROG_ECHO_BACKSLASH + + +# _LT_ENABLE_LOCK +# --------------- +m4_defun([_LT_ENABLE_LOCK], +[AC_ARG_ENABLE([libtool-lock], + [AS_HELP_STRING([--disable-libtool-lock], + [avoid locking (might break parallel builds)])]) +test "x$enable_libtool_lock" != xno && enable_libtool_lock=yes + +# Some flags need to be propagated to the compiler or linker for good +# libtool support. +case $host in +ia64-*-hpux*) + # Find out which ABI we are using. + echo 'int i;' > conftest.$ac_ext + if AC_TRY_EVAL(ac_compile); then + case `/usr/bin/file conftest.$ac_objext` in + *ELF-32*) + HPUX_IA64_MODE="32" + ;; + *ELF-64*) + HPUX_IA64_MODE="64" + ;; + esac + fi + rm -rf conftest* + ;; +*-*-irix6*) + # Find out which ABI we are using. + echo '[#]line __oline__ "configure"' > conftest.$ac_ext + if AC_TRY_EVAL(ac_compile); then + if test "$lt_cv_prog_gnu_ld" = yes; then + case `/usr/bin/file conftest.$ac_objext` in + *32-bit*) + LD="${LD-ld} -melf32bsmip" + ;; + *N32*) + LD="${LD-ld} -melf32bmipn32" + ;; + *64-bit*) + LD="${LD-ld} -melf64bmip" + ;; + esac + else + case `/usr/bin/file conftest.$ac_objext` in + *32-bit*) + LD="${LD-ld} -32" + ;; + *N32*) + LD="${LD-ld} -n32" + ;; + *64-bit*) + LD="${LD-ld} -64" + ;; + esac + fi + fi + rm -rf conftest* + ;; + +x86_64-*kfreebsd*-gnu|x86_64-*linux*|ppc*-*linux*|powerpc*-*linux*| \ +s390*-*linux*|s390*-*tpf*|sparc*-*linux*) + # Find out which ABI we are using. + echo 'int i;' > conftest.$ac_ext + if AC_TRY_EVAL(ac_compile); then + case `/usr/bin/file conftest.o` in + *32-bit*) + case $host in + x86_64-*kfreebsd*-gnu) + LD="${LD-ld} -m elf_i386_fbsd" + ;; + x86_64-*linux*) + LD="${LD-ld} -m elf_i386" + ;; + ppc64-*linux*|powerpc64-*linux*) + LD="${LD-ld} -m elf32ppclinux" + ;; + s390x-*linux*) + LD="${LD-ld} -m elf_s390" + ;; + sparc64-*linux*) + LD="${LD-ld} -m elf32_sparc" + ;; + esac + ;; + *64-bit*) + case $host in + x86_64-*kfreebsd*-gnu) + LD="${LD-ld} -m elf_x86_64_fbsd" + ;; + x86_64-*linux*) + LD="${LD-ld} -m elf_x86_64" + ;; + ppc*-*linux*|powerpc*-*linux*) + LD="${LD-ld} -m elf64ppc" + ;; + s390*-*linux*|s390*-*tpf*) + LD="${LD-ld} -m elf64_s390" + ;; + sparc*-*linux*) + LD="${LD-ld} -m elf64_sparc" + ;; + esac + ;; + esac + fi + rm -rf conftest* + ;; + +*-*-sco3.2v5*) + # On SCO OpenServer 5, we need -belf to get full-featured binaries. + SAVE_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS -belf" + AC_CACHE_CHECK([whether the C compiler needs -belf], lt_cv_cc_needs_belf, + [AC_LANG_PUSH(C) + AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],[[]])],[lt_cv_cc_needs_belf=yes],[lt_cv_cc_needs_belf=no]) + AC_LANG_POP]) + if test x"$lt_cv_cc_needs_belf" != x"yes"; then + # this is probably gcc 2.8.0, egcs 1.0 or newer; no need for -belf + CFLAGS="$SAVE_CFLAGS" + fi + ;; +sparc*-*solaris*) + # Find out which ABI we are using. + echo 'int i;' > conftest.$ac_ext + if AC_TRY_EVAL(ac_compile); then + case `/usr/bin/file conftest.o` in + *64-bit*) + case $lt_cv_prog_gnu_ld in + yes*) LD="${LD-ld} -m elf64_sparc" ;; + *) + if ${LD-ld} -64 -r -o conftest2.o conftest.o >/dev/null 2>&1; then + LD="${LD-ld} -64" + fi + ;; + esac + ;; + esac + fi + rm -rf conftest* + ;; +esac + +need_locks="$enable_libtool_lock" +])# _LT_ENABLE_LOCK + + +# _LT_CMD_OLD_ARCHIVE +# ------------------- +m4_defun([_LT_CMD_OLD_ARCHIVE], +[AC_CHECK_TOOL(AR, ar, false) +test -z "$AR" && AR=ar +test -z "$AR_FLAGS" && AR_FLAGS=cru +_LT_DECL([], [AR], [1], [The archiver]) +_LT_DECL([], [AR_FLAGS], [1]) + +AC_CHECK_TOOL(STRIP, strip, :) +test -z "$STRIP" && STRIP=: +_LT_DECL([], [STRIP], [1], [A symbol stripping program]) + +AC_CHECK_TOOL(RANLIB, ranlib, :) +test -z "$RANLIB" && RANLIB=: +_LT_DECL([], [RANLIB], [1], + [Commands used to install an old-style archive]) + +# Determine commands to create old-style static archives. +old_archive_cmds='$AR $AR_FLAGS $oldlib$oldobjs' +old_postinstall_cmds='chmod 644 $oldlib' +old_postuninstall_cmds= + +if test -n "$RANLIB"; then + case $host_os in + openbsd*) + old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB -t \$oldlib" + ;; + *) + old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB \$oldlib" + ;; + esac + old_archive_cmds="$old_archive_cmds~\$RANLIB \$oldlib" +fi +_LT_DECL([], [old_postinstall_cmds], [2]) +_LT_DECL([], [old_postuninstall_cmds], [2]) +_LT_TAGDECL([], [old_archive_cmds], [2], + [Commands used to build an old-style archive]) +])# _LT_CMD_OLD_ARCHIVE + + +# _LT_COMPILER_OPTION(MESSAGE, VARIABLE-NAME, FLAGS, +# [OUTPUT-FILE], [ACTION-SUCCESS], [ACTION-FAILURE]) +# ---------------------------------------------------------------- +# Check whether the given compiler option works +AC_DEFUN([_LT_COMPILER_OPTION], +[m4_require([_LT_FILEUTILS_DEFAULTS])dnl +m4_require([_LT_DECL_SED])dnl +AC_CACHE_CHECK([$1], [$2], + [$2=no + m4_if([$4], , [ac_outfile=conftest.$ac_objext], [ac_outfile=$4]) + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + lt_compiler_flag="$3" + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + # The option is referenced via a variable to avoid confusing sed. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [[^ ]]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:__oline__: $lt_compile\"" >&AS_MESSAGE_LOG_FD) + (eval "$lt_compile" 2>conftest.err) + ac_status=$? + cat conftest.err >&AS_MESSAGE_LOG_FD + echo "$as_me:__oline__: \$? = $ac_status" >&AS_MESSAGE_LOG_FD + if (exit $ac_status) && test -s "$ac_outfile"; then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings other than the usual output. + $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' >conftest.exp + $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 + if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then + $2=yes + fi + fi + $RM conftest* +]) + +if test x"[$]$2" = xyes; then + m4_if([$5], , :, [$5]) +else + m4_if([$6], , :, [$6]) +fi +])# _LT_COMPILER_OPTION + +# Old name: +AU_ALIAS([AC_LIBTOOL_COMPILER_OPTION], [_LT_COMPILER_OPTION]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_COMPILER_OPTION], []) + + +# _LT_LINKER_OPTION(MESSAGE, VARIABLE-NAME, FLAGS, +# [ACTION-SUCCESS], [ACTION-FAILURE]) +# ---------------------------------------------------- +# Check whether the given linker option works +AC_DEFUN([_LT_LINKER_OPTION], +[m4_require([_LT_FILEUTILS_DEFAULTS])dnl +m4_require([_LT_DECL_SED])dnl +AC_CACHE_CHECK([$1], [$2], + [$2=no + save_LDFLAGS="$LDFLAGS" + LDFLAGS="$LDFLAGS $3" + echo "$lt_simple_link_test_code" > conftest.$ac_ext + if (eval $ac_link 2>conftest.err) && test -s conftest$ac_exeext; then + # The linker can only warn and ignore the option if not recognized + # So say no if there are warnings + if test -s conftest.err; then + # Append any errors to the config.log. + cat conftest.err 1>&AS_MESSAGE_LOG_FD + $ECHO "X$_lt_linker_boilerplate" | $Xsed -e '/^$/d' > conftest.exp + $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 + if diff conftest.exp conftest.er2 >/dev/null; then + $2=yes + fi + else + $2=yes + fi + fi + $RM -r conftest* + LDFLAGS="$save_LDFLAGS" +]) + +if test x"[$]$2" = xyes; then + m4_if([$4], , :, [$4]) +else + m4_if([$5], , :, [$5]) +fi +])# _LT_LINKER_OPTION + +# Old name: +AU_ALIAS([AC_LIBTOOL_LINKER_OPTION], [_LT_LINKER_OPTION]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_LINKER_OPTION], []) + + +# LT_CMD_MAX_LEN +#--------------- +AC_DEFUN([LT_CMD_MAX_LEN], +[AC_REQUIRE([AC_CANONICAL_HOST])dnl +# find the maximum length of command line arguments +AC_MSG_CHECKING([the maximum length of command line arguments]) +AC_CACHE_VAL([lt_cv_sys_max_cmd_len], [dnl + i=0 + teststring="ABCD" + + case $build_os in + msdosdjgpp*) + # On DJGPP, this test can blow up pretty badly due to problems in libc + # (any single argument exceeding 2000 bytes causes a buffer overrun + # during glob expansion). Even if it were fixed, the result of this + # check would be larger than it should be. + lt_cv_sys_max_cmd_len=12288; # 12K is about right + ;; + + gnu*) + # Under GNU Hurd, this test is not required because there is + # no limit to the length of command line arguments. + # Libtool will interpret -1 as no limit whatsoever + lt_cv_sys_max_cmd_len=-1; + ;; + + cygwin* | mingw* | cegcc*) + # On Win9x/ME, this test blows up -- it succeeds, but takes + # about 5 minutes as the teststring grows exponentially. + # Worse, since 9x/ME are not pre-emptively multitasking, + # you end up with a "frozen" computer, even though with patience + # the test eventually succeeds (with a max line length of 256k). + # Instead, let's just punt: use the minimum linelength reported by + # all of the supported platforms: 8192 (on NT/2K/XP). + lt_cv_sys_max_cmd_len=8192; + ;; + + amigaos*) + # On AmigaOS with pdksh, this test takes hours, literally. + # So we just punt and use a minimum line length of 8192. + lt_cv_sys_max_cmd_len=8192; + ;; + + netbsd* | freebsd* | openbsd* | darwin* | dragonfly*) + # This has been around since 386BSD, at least. Likely further. + if test -x /sbin/sysctl; then + lt_cv_sys_max_cmd_len=`/sbin/sysctl -n kern.argmax` + elif test -x /usr/sbin/sysctl; then + lt_cv_sys_max_cmd_len=`/usr/sbin/sysctl -n kern.argmax` + else + lt_cv_sys_max_cmd_len=65536 # usable default for all BSDs + fi + # And add a safety zone + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4` + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3` + ;; + + interix*) + # We know the value 262144 and hardcode it with a safety zone (like BSD) + lt_cv_sys_max_cmd_len=196608 + ;; + + osf*) + # Dr. Hans Ekkehard Plesser reports seeing a kernel panic running configure + # due to this test when exec_disable_arg_limit is 1 on Tru64. It is not + # nice to cause kernel panics so lets avoid the loop below. + # First set a reasonable default. + lt_cv_sys_max_cmd_len=16384 + # + if test -x /sbin/sysconfig; then + case `/sbin/sysconfig -q proc exec_disable_arg_limit` in + *1*) lt_cv_sys_max_cmd_len=-1 ;; + esac + fi + ;; + sco3.2v5*) + lt_cv_sys_max_cmd_len=102400 + ;; + sysv5* | sco5v6* | sysv4.2uw2*) + kargmax=`grep ARG_MAX /etc/conf/cf.d/stune 2>/dev/null` + if test -n "$kargmax"; then + lt_cv_sys_max_cmd_len=`echo $kargmax | sed 's/.*[[ ]]//'` + else + lt_cv_sys_max_cmd_len=32768 + fi + ;; + *) + lt_cv_sys_max_cmd_len=`(getconf ARG_MAX) 2> /dev/null` + if test -n "$lt_cv_sys_max_cmd_len"; then + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4` + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3` + else + # Make teststring a little bigger before we do anything with it. + # a 1K string should be a reasonable start. + for i in 1 2 3 4 5 6 7 8 ; do + teststring=$teststring$teststring + done + SHELL=${SHELL-${CONFIG_SHELL-/bin/sh}} + # If test is not a shell built-in, we'll probably end up computing a + # maximum length that is only half of the actual maximum length, but + # we can't tell. + while { test "X"`$SHELL [$]0 --fallback-echo "X$teststring$teststring" 2>/dev/null` \ + = "XX$teststring$teststring"; } >/dev/null 2>&1 && + test $i != 17 # 1/2 MB should be enough + do + i=`expr $i + 1` + teststring=$teststring$teststring + done + # Only check the string length outside the loop. + lt_cv_sys_max_cmd_len=`expr "X$teststring" : ".*" 2>&1` + teststring= + # Add a significant safety factor because C++ compilers can tack on + # massive amounts of additional arguments before passing them to the + # linker. It appears as though 1/2 is a usable value. + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 2` + fi + ;; + esac +]) +if test -n $lt_cv_sys_max_cmd_len ; then + AC_MSG_RESULT($lt_cv_sys_max_cmd_len) +else + AC_MSG_RESULT(none) +fi +max_cmd_len=$lt_cv_sys_max_cmd_len +_LT_DECL([], [max_cmd_len], [0], + [What is the maximum length of a command?]) +])# LT_CMD_MAX_LEN + +# Old name: +AU_ALIAS([AC_LIBTOOL_SYS_MAX_CMD_LEN], [LT_CMD_MAX_LEN]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_SYS_MAX_CMD_LEN], []) + + +# _LT_HEADER_DLFCN +# ---------------- +m4_defun([_LT_HEADER_DLFCN], +[AC_CHECK_HEADERS([dlfcn.h], [], [], [AC_INCLUDES_DEFAULT])dnl +])# _LT_HEADER_DLFCN + + +# _LT_TRY_DLOPEN_SELF (ACTION-IF-TRUE, ACTION-IF-TRUE-W-USCORE, +# ACTION-IF-FALSE, ACTION-IF-CROSS-COMPILING) +# ---------------------------------------------------------------- +m4_defun([_LT_TRY_DLOPEN_SELF], +[m4_require([_LT_HEADER_DLFCN])dnl +if test "$cross_compiling" = yes; then : + [$4] +else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +[#line __oline__ "configure" +#include "confdefs.h" + +#if HAVE_DLFCN_H +#include +#endif + +#include + +#ifdef RTLD_GLOBAL +# define LT_DLGLOBAL RTLD_GLOBAL +#else +# ifdef DL_GLOBAL +# define LT_DLGLOBAL DL_GLOBAL +# else +# define LT_DLGLOBAL 0 +# endif +#endif + +/* We may have to define LT_DLLAZY_OR_NOW in the command line if we + find out it does not work in some platform. */ +#ifndef LT_DLLAZY_OR_NOW +# ifdef RTLD_LAZY +# define LT_DLLAZY_OR_NOW RTLD_LAZY +# else +# ifdef DL_LAZY +# define LT_DLLAZY_OR_NOW DL_LAZY +# else +# ifdef RTLD_NOW +# define LT_DLLAZY_OR_NOW RTLD_NOW +# else +# ifdef DL_NOW +# define LT_DLLAZY_OR_NOW DL_NOW +# else +# define LT_DLLAZY_OR_NOW 0 +# endif +# endif +# endif +# endif +#endif + +void fnord() { int i=42;} +int main () +{ + void *self = dlopen (0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW); + int status = $lt_dlunknown; + + if (self) + { + if (dlsym (self,"fnord")) status = $lt_dlno_uscore; + else if (dlsym( self,"_fnord")) status = $lt_dlneed_uscore; + /* dlclose (self); */ + } + else + puts (dlerror ()); + + return status; +}] +_LT_EOF + if AC_TRY_EVAL(ac_link) && test -s conftest${ac_exeext} 2>/dev/null; then + (./conftest; exit; ) >&AS_MESSAGE_LOG_FD 2>/dev/null + lt_status=$? + case x$lt_status in + x$lt_dlno_uscore) $1 ;; + x$lt_dlneed_uscore) $2 ;; + x$lt_dlunknown|x*) $3 ;; + esac + else : + # compilation failed + $3 + fi +fi +rm -fr conftest* +])# _LT_TRY_DLOPEN_SELF + + +# LT_SYS_DLOPEN_SELF +# ------------------ +AC_DEFUN([LT_SYS_DLOPEN_SELF], +[m4_require([_LT_HEADER_DLFCN])dnl +if test "x$enable_dlopen" != xyes; then + enable_dlopen=unknown + enable_dlopen_self=unknown + enable_dlopen_self_static=unknown +else + lt_cv_dlopen=no + lt_cv_dlopen_libs= + + case $host_os in + beos*) + lt_cv_dlopen="load_add_on" + lt_cv_dlopen_libs= + lt_cv_dlopen_self=yes + ;; + + mingw* | pw32* | cegcc*) + lt_cv_dlopen="LoadLibrary" + lt_cv_dlopen_libs= + ;; + + cygwin*) + lt_cv_dlopen="dlopen" + lt_cv_dlopen_libs= + ;; + + darwin*) + # if libdl is installed we need to link against it + AC_CHECK_LIB([dl], [dlopen], + [lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl"],[ + lt_cv_dlopen="dyld" + lt_cv_dlopen_libs= + lt_cv_dlopen_self=yes + ]) + ;; + + *) + AC_CHECK_FUNC([shl_load], + [lt_cv_dlopen="shl_load"], + [AC_CHECK_LIB([dld], [shl_load], + [lt_cv_dlopen="shl_load" lt_cv_dlopen_libs="-ldld"], + [AC_CHECK_FUNC([dlopen], + [lt_cv_dlopen="dlopen"], + [AC_CHECK_LIB([dl], [dlopen], + [lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl"], + [AC_CHECK_LIB([svld], [dlopen], + [lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-lsvld"], + [AC_CHECK_LIB([dld], [dld_link], + [lt_cv_dlopen="dld_link" lt_cv_dlopen_libs="-ldld"]) + ]) + ]) + ]) + ]) + ]) + ;; + esac + + if test "x$lt_cv_dlopen" != xno; then + enable_dlopen=yes + else + enable_dlopen=no + fi + + case $lt_cv_dlopen in + dlopen) + save_CPPFLAGS="$CPPFLAGS" + test "x$ac_cv_header_dlfcn_h" = xyes && CPPFLAGS="$CPPFLAGS -DHAVE_DLFCN_H" + + save_LDFLAGS="$LDFLAGS" + wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $export_dynamic_flag_spec\" + + save_LIBS="$LIBS" + LIBS="$lt_cv_dlopen_libs $LIBS" + + AC_CACHE_CHECK([whether a program can dlopen itself], + lt_cv_dlopen_self, [dnl + _LT_TRY_DLOPEN_SELF( + lt_cv_dlopen_self=yes, lt_cv_dlopen_self=yes, + lt_cv_dlopen_self=no, lt_cv_dlopen_self=cross) + ]) + + if test "x$lt_cv_dlopen_self" = xyes; then + wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $lt_prog_compiler_static\" + AC_CACHE_CHECK([whether a statically linked program can dlopen itself], + lt_cv_dlopen_self_static, [dnl + _LT_TRY_DLOPEN_SELF( + lt_cv_dlopen_self_static=yes, lt_cv_dlopen_self_static=yes, + lt_cv_dlopen_self_static=no, lt_cv_dlopen_self_static=cross) + ]) + fi + + CPPFLAGS="$save_CPPFLAGS" + LDFLAGS="$save_LDFLAGS" + LIBS="$save_LIBS" + ;; + esac + + case $lt_cv_dlopen_self in + yes|no) enable_dlopen_self=$lt_cv_dlopen_self ;; + *) enable_dlopen_self=unknown ;; + esac + + case $lt_cv_dlopen_self_static in + yes|no) enable_dlopen_self_static=$lt_cv_dlopen_self_static ;; + *) enable_dlopen_self_static=unknown ;; + esac +fi +_LT_DECL([dlopen_support], [enable_dlopen], [0], + [Whether dlopen is supported]) +_LT_DECL([dlopen_self], [enable_dlopen_self], [0], + [Whether dlopen of programs is supported]) +_LT_DECL([dlopen_self_static], [enable_dlopen_self_static], [0], + [Whether dlopen of statically linked programs is supported]) +])# LT_SYS_DLOPEN_SELF + +# Old name: +AU_ALIAS([AC_LIBTOOL_DLOPEN_SELF], [LT_SYS_DLOPEN_SELF]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_DLOPEN_SELF], []) + + +# _LT_COMPILER_C_O([TAGNAME]) +# --------------------------- +# Check to see if options -c and -o are simultaneously supported by compiler. +# This macro does not hard code the compiler like AC_PROG_CC_C_O. +m4_defun([_LT_COMPILER_C_O], +[m4_require([_LT_DECL_SED])dnl +m4_require([_LT_FILEUTILS_DEFAULTS])dnl +m4_require([_LT_TAG_COMPILER])dnl +AC_CACHE_CHECK([if $compiler supports -c -o file.$ac_objext], + [_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)], + [_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)=no + $RM -r conftest 2>/dev/null + mkdir conftest + cd conftest + mkdir out + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + + lt_compiler_flag="-o out/conftest2.$ac_objext" + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [[^ ]]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:__oline__: $lt_compile\"" >&AS_MESSAGE_LOG_FD) + (eval "$lt_compile" 2>out/conftest.err) + ac_status=$? + cat out/conftest.err >&AS_MESSAGE_LOG_FD + echo "$as_me:__oline__: \$? = $ac_status" >&AS_MESSAGE_LOG_FD + if (exit $ac_status) && test -s out/conftest2.$ac_objext + then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings + $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' > out/conftest.exp + $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2 + if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then + _LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)=yes + fi + fi + chmod u+w . 2>&AS_MESSAGE_LOG_FD + $RM conftest* + # SGI C++ compiler will create directory out/ii_files/ for + # template instantiation + test -d out/ii_files && $RM out/ii_files/* && rmdir out/ii_files + $RM out/* && rmdir out + cd .. + $RM -r conftest + $RM conftest* +]) +_LT_TAGDECL([compiler_c_o], [lt_cv_prog_compiler_c_o], [1], + [Does compiler simultaneously support -c and -o options?]) +])# _LT_COMPILER_C_O + + +# _LT_COMPILER_FILE_LOCKS([TAGNAME]) +# ---------------------------------- +# Check to see if we can do hard links to lock some files if needed +m4_defun([_LT_COMPILER_FILE_LOCKS], +[m4_require([_LT_ENABLE_LOCK])dnl +m4_require([_LT_FILEUTILS_DEFAULTS])dnl +_LT_COMPILER_C_O([$1]) + +hard_links="nottested" +if test "$_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)" = no && test "$need_locks" != no; then + # do not overwrite the value of need_locks provided by the user + AC_MSG_CHECKING([if we can lock with hard links]) + hard_links=yes + $RM conftest* + ln conftest.a conftest.b 2>/dev/null && hard_links=no + touch conftest.a + ln conftest.a conftest.b 2>&5 || hard_links=no + ln conftest.a conftest.b 2>/dev/null && hard_links=no + AC_MSG_RESULT([$hard_links]) + if test "$hard_links" = no; then + AC_MSG_WARN([`$CC' does not support `-c -o', so `make -j' may be unsafe]) + need_locks=warn + fi +else + need_locks=no +fi +_LT_DECL([], [need_locks], [1], [Must we lock files when doing compilation?]) +])# _LT_COMPILER_FILE_LOCKS + + +# _LT_CHECK_OBJDIR +# ---------------- +m4_defun([_LT_CHECK_OBJDIR], +[AC_CACHE_CHECK([for objdir], [lt_cv_objdir], +[rm -f .libs 2>/dev/null +mkdir .libs 2>/dev/null +if test -d .libs; then + lt_cv_objdir=.libs +else + # MS-DOS does not allow filenames that begin with a dot. + lt_cv_objdir=_libs +fi +rmdir .libs 2>/dev/null]) +objdir=$lt_cv_objdir +_LT_DECL([], [objdir], [0], + [The name of the directory that contains temporary libtool files])dnl +m4_pattern_allow([LT_OBJDIR])dnl +AC_DEFINE_UNQUOTED(LT_OBJDIR, "$lt_cv_objdir/", + [Define to the sub-directory in which libtool stores uninstalled libraries.]) +])# _LT_CHECK_OBJDIR + + +# _LT_LINKER_HARDCODE_LIBPATH([TAGNAME]) +# -------------------------------------- +# Check hardcoding attributes. +m4_defun([_LT_LINKER_HARDCODE_LIBPATH], +[AC_MSG_CHECKING([how to hardcode library paths into programs]) +_LT_TAGVAR(hardcode_action, $1)= +if test -n "$_LT_TAGVAR(hardcode_libdir_flag_spec, $1)" || + test -n "$_LT_TAGVAR(runpath_var, $1)" || + test "X$_LT_TAGVAR(hardcode_automatic, $1)" = "Xyes" ; then + + # We can hardcode non-existent directories. + if test "$_LT_TAGVAR(hardcode_direct, $1)" != no && + # If the only mechanism to avoid hardcoding is shlibpath_var, we + # have to relink, otherwise we might link with an installed library + # when we should be linking with a yet-to-be-installed one + ## test "$_LT_TAGVAR(hardcode_shlibpath_var, $1)" != no && + test "$_LT_TAGVAR(hardcode_minus_L, $1)" != no; then + # Linking always hardcodes the temporary library directory. + _LT_TAGVAR(hardcode_action, $1)=relink + else + # We can link without hardcoding, and we can hardcode nonexisting dirs. + _LT_TAGVAR(hardcode_action, $1)=immediate + fi +else + # We cannot hardcode anything, or else we can only hardcode existing + # directories. + _LT_TAGVAR(hardcode_action, $1)=unsupported +fi +AC_MSG_RESULT([$_LT_TAGVAR(hardcode_action, $1)]) + +if test "$_LT_TAGVAR(hardcode_action, $1)" = relink || + test "$_LT_TAGVAR(inherit_rpath, $1)" = yes; then + # Fast installation is not supported + enable_fast_install=no +elif test "$shlibpath_overrides_runpath" = yes || + test "$enable_shared" = no; then + # Fast installation is not necessary + enable_fast_install=needless +fi +_LT_TAGDECL([], [hardcode_action], [0], + [How to hardcode a shared library path into an executable]) +])# _LT_LINKER_HARDCODE_LIBPATH + + +# _LT_CMD_STRIPLIB +# ---------------- +m4_defun([_LT_CMD_STRIPLIB], +[m4_require([_LT_DECL_EGREP]) +striplib= +old_striplib= +AC_MSG_CHECKING([whether stripping libraries is possible]) +if test -n "$STRIP" && $STRIP -V 2>&1 | $GREP "GNU strip" >/dev/null; then + test -z "$old_striplib" && old_striplib="$STRIP --strip-debug" + test -z "$striplib" && striplib="$STRIP --strip-unneeded" + AC_MSG_RESULT([yes]) +else +# FIXME - insert some real tests, host_os isn't really good enough + case $host_os in + darwin*) + if test -n "$STRIP" ; then + striplib="$STRIP -x" + old_striplib="$STRIP -S" + AC_MSG_RESULT([yes]) + else + AC_MSG_RESULT([no]) + fi + ;; + *) + AC_MSG_RESULT([no]) + ;; + esac +fi +_LT_DECL([], [old_striplib], [1], [Commands to strip libraries]) +_LT_DECL([], [striplib], [1]) +])# _LT_CMD_STRIPLIB + + +# _LT_SYS_DYNAMIC_LINKER([TAG]) +# ----------------------------- +# PORTME Fill in your ld.so characteristics +m4_defun([_LT_SYS_DYNAMIC_LINKER], +[AC_REQUIRE([AC_CANONICAL_HOST])dnl +m4_require([_LT_DECL_EGREP])dnl +m4_require([_LT_FILEUTILS_DEFAULTS])dnl +m4_require([_LT_DECL_OBJDUMP])dnl +m4_require([_LT_DECL_SED])dnl +AC_MSG_CHECKING([dynamic linker characteristics]) +m4_if([$1], + [], [ +if test "$GCC" = yes; then + case $host_os in + darwin*) lt_awk_arg="/^libraries:/,/LR/" ;; + *) lt_awk_arg="/^libraries:/" ;; + esac + lt_search_path_spec=`$CC -print-search-dirs | awk $lt_awk_arg | $SED -e "s/^libraries://" -e "s,=/,/,g"` + if $ECHO "$lt_search_path_spec" | $GREP ';' >/dev/null ; then + # if the path contains ";" then we assume it to be the separator + # otherwise default to the standard path separator (i.e. ":") - it is + # assumed that no part of a normal pathname contains ";" but that should + # okay in the real world where ";" in dirpaths is itself problematic. + lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED -e 's/;/ /g'` + else + lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"` + fi + # Ok, now we have the path, separated by spaces, we can step through it + # and add multilib dir if necessary. + lt_tmp_lt_search_path_spec= + lt_multi_os_dir=`$CC $CPPFLAGS $CFLAGS $LDFLAGS -print-multi-os-directory 2>/dev/null` + for lt_sys_path in $lt_search_path_spec; do + if test -d "$lt_sys_path/$lt_multi_os_dir"; then + lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path/$lt_multi_os_dir" + else + test -d "$lt_sys_path" && \ + lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path" + fi + done + lt_search_path_spec=`$ECHO $lt_tmp_lt_search_path_spec | awk ' +BEGIN {RS=" "; FS="/|\n";} { + lt_foo=""; + lt_count=0; + for (lt_i = NF; lt_i > 0; lt_i--) { + if ($lt_i != "" && $lt_i != ".") { + if ($lt_i == "..") { + lt_count++; + } else { + if (lt_count == 0) { + lt_foo="/" $lt_i lt_foo; + } else { + lt_count--; + } + } + } + } + if (lt_foo != "") { lt_freq[[lt_foo]]++; } + if (lt_freq[[lt_foo]] == 1) { print lt_foo; } +}'` + sys_lib_search_path_spec=`$ECHO $lt_search_path_spec` +else + sys_lib_search_path_spec="/lib /usr/lib /usr/local/lib" +fi]) +library_names_spec= +libname_spec='lib$name' +soname_spec= +shrext_cmds=".so" +postinstall_cmds= +postuninstall_cmds= +finish_cmds= +finish_eval= +shlibpath_var= +shlibpath_overrides_runpath=unknown +version_type=none +dynamic_linker="$host_os ld.so" +sys_lib_dlsearch_path_spec="/lib /usr/lib" +need_lib_prefix=unknown +hardcode_into_libs=no + +# when you set need_version to no, make sure it does not cause -set_version +# flags to be left without arguments +need_version=unknown + +case $host_os in +aix3*) + version_type=linux + library_names_spec='${libname}${release}${shared_ext}$versuffix $libname.a' + shlibpath_var=LIBPATH + + # AIX 3 has no versioning support, so we append a major version to the name. + soname_spec='${libname}${release}${shared_ext}$major' + ;; + +aix[[4-9]]*) + version_type=linux + need_lib_prefix=no + need_version=no + hardcode_into_libs=yes + if test "$host_cpu" = ia64; then + # AIX 5 supports IA64 + library_names_spec='${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext}$versuffix $libname${shared_ext}' + shlibpath_var=LD_LIBRARY_PATH + else + # With GCC up to 2.95.x, collect2 would create an import file + # for dependence libraries. The import file would start with + # the line `#! .'. This would cause the generated library to + # depend on `.', always an invalid library. This was fixed in + # development snapshots of GCC prior to 3.0. + case $host_os in + aix4 | aix4.[[01]] | aix4.[[01]].*) + if { echo '#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97)' + echo ' yes ' + echo '#endif'; } | ${CC} -E - | $GREP yes > /dev/null; then + : + else + can_build_shared=no + fi + ;; + esac + # AIX (on Power*) has no versioning support, so currently we can not hardcode correct + # soname into executable. Probably we can add versioning support to + # collect2, so additional links can be useful in future. + if test "$aix_use_runtimelinking" = yes; then + # If using run time linking (on AIX 4.2 or later) use lib.so + # instead of lib.a to let people know that these are not + # typical AIX shared libraries. + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + else + # We preserve .a as extension for shared libraries through AIX4.2 + # and later when we are not doing run time linking. + library_names_spec='${libname}${release}.a $libname.a' + soname_spec='${libname}${release}${shared_ext}$major' + fi + shlibpath_var=LIBPATH + fi + ;; + +amigaos*) + case $host_cpu in + powerpc) + # Since July 2007 AmigaOS4 officially supports .so libraries. + # When compiling the executable, add -use-dynld -Lsobjs: to the compileline. + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + ;; + m68k) + library_names_spec='$libname.ixlibrary $libname.a' + # Create ${libname}_ixlibrary.a entries in /sys/libs. + finish_eval='for lib in `ls $libdir/*.ixlibrary 2>/dev/null`; do libname=`$ECHO "X$lib" | $Xsed -e '\''s%^.*/\([[^/]]*\)\.ixlibrary$%\1%'\''`; test $RM /sys/libs/${libname}_ixlibrary.a; $show "cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a"; cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a || exit 1; done' + ;; + esac + ;; + +beos*) + library_names_spec='${libname}${shared_ext}' + dynamic_linker="$host_os ld.so" + shlibpath_var=LIBRARY_PATH + ;; + +bsdi[[45]]*) + version_type=linux + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + finish_cmds='PATH="\$PATH:/sbin" ldconfig $libdir' + shlibpath_var=LD_LIBRARY_PATH + sys_lib_search_path_spec="/shlib /usr/lib /usr/X11/lib /usr/contrib/lib /lib /usr/local/lib" + sys_lib_dlsearch_path_spec="/shlib /usr/lib /usr/local/lib" + # the default ld.so.conf also contains /usr/contrib/lib and + # /usr/X11R6/lib (/usr/X11 is a link to /usr/X11R6), but let us allow + # libtool to hard-code these into programs + ;; + +cygwin* | mingw* | pw32* | cegcc*) + version_type=windows + shrext_cmds=".dll" + need_version=no + need_lib_prefix=no + + case $GCC,$host_os in + yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*) + library_names_spec='$libname.dll.a' + # DLL is installed to $(libdir)/../bin by postinstall_cmds + postinstall_cmds='base_file=`basename \${file}`~ + dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~ + dldir=$destdir/`dirname \$dlpath`~ + test -d \$dldir || mkdir -p \$dldir~ + $install_prog $dir/$dlname \$dldir/$dlname~ + chmod a+x \$dldir/$dlname~ + if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then + eval '\''$striplib \$dldir/$dlname'\'' || exit \$?; + fi' + postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~ + dlpath=$dir/\$dldll~ + $RM \$dlpath' + shlibpath_overrides_runpath=yes + + case $host_os in + cygwin*) + # Cygwin DLLs use 'cyg' prefix rather than 'lib' + soname_spec='`echo ${libname} | sed -e 's/^lib/cyg/'``echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}' + sys_lib_search_path_spec="/usr/lib /lib/w32api /lib /usr/local/lib" + ;; + mingw* | cegcc*) + # MinGW DLLs use traditional 'lib' prefix + soname_spec='${libname}`echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}' + sys_lib_search_path_spec=`$CC -print-search-dirs | $GREP "^libraries:" | $SED -e "s/^libraries://" -e "s,=/,/,g"` + if $ECHO "$sys_lib_search_path_spec" | [$GREP ';[c-zC-Z]:/' >/dev/null]; then + # It is most probably a Windows format PATH printed by + # mingw gcc, but we are running on Cygwin. Gcc prints its search + # path with ; separators, and with drive letters. We can handle the + # drive letters (cygwin fileutils understands them), so leave them, + # especially as we might pass files found there to a mingw objdump, + # which wouldn't understand a cygwinified path. Ahh. + sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e 's/;/ /g'` + else + sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"` + fi + ;; + pw32*) + # pw32 DLLs use 'pw' prefix rather than 'lib' + library_names_spec='`echo ${libname} | sed -e 's/^lib/pw/'``echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}' + ;; + esac + ;; + + *) + library_names_spec='${libname}`echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext} $libname.lib' + ;; + esac + dynamic_linker='Win32 ld.exe' + # FIXME: first we should search . and the directory the executable is in + shlibpath_var=PATH + ;; + +darwin* | rhapsody*) + dynamic_linker="$host_os dyld" + version_type=darwin + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${major}$shared_ext ${libname}$shared_ext' + soname_spec='${libname}${release}${major}$shared_ext' + shlibpath_overrides_runpath=yes + shlibpath_var=DYLD_LIBRARY_PATH + shrext_cmds='`test .$module = .yes && echo .so || echo .dylib`' +m4_if([$1], [],[ + sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/local/lib"]) + sys_lib_dlsearch_path_spec='/usr/local/lib /lib /usr/lib' + ;; + +dgux*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname$shared_ext' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + ;; + +freebsd1*) + dynamic_linker=no + ;; + +freebsd* | dragonfly*) + # DragonFly does not have aout. When/if they implement a new + # versioning mechanism, adjust this. + if test -x /usr/bin/objformat; then + objformat=`/usr/bin/objformat` + else + case $host_os in + freebsd[[123]]*) objformat=aout ;; + *) objformat=elf ;; + esac + fi + version_type=freebsd-$objformat + case $version_type in + freebsd-elf*) + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}' + need_version=no + need_lib_prefix=no + ;; + freebsd-*) + library_names_spec='${libname}${release}${shared_ext}$versuffix $libname${shared_ext}$versuffix' + need_version=yes + ;; + esac + shlibpath_var=LD_LIBRARY_PATH + case $host_os in + freebsd2*) + shlibpath_overrides_runpath=yes + ;; + freebsd3.[[01]]* | freebsdelf3.[[01]]*) + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + freebsd3.[[2-9]]* | freebsdelf3.[[2-9]]* | \ + freebsd4.[[0-5]] | freebsdelf4.[[0-5]] | freebsd4.1.1 | freebsdelf4.1.1) + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + *) # from 4.6 on, and DragonFly + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + esac + ;; + +gnu*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}${major} ${libname}${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + hardcode_into_libs=yes + ;; + +hpux9* | hpux10* | hpux11*) + # Give a soname corresponding to the major version so that dld.sl refuses to + # link against other versions. + version_type=sunos + need_lib_prefix=no + need_version=no + case $host_cpu in + ia64*) + shrext_cmds='.so' + hardcode_into_libs=yes + dynamic_linker="$host_os dld.so" + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes # Unless +noenvvar is specified. + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + if test "X$HPUX_IA64_MODE" = X32; then + sys_lib_search_path_spec="/usr/lib/hpux32 /usr/local/lib/hpux32 /usr/local/lib" + else + sys_lib_search_path_spec="/usr/lib/hpux64 /usr/local/lib/hpux64" + fi + sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec + ;; + hppa*64*) + shrext_cmds='.sl' + hardcode_into_libs=yes + dynamic_linker="$host_os dld.sl" + shlibpath_var=LD_LIBRARY_PATH # How should we handle SHLIB_PATH + shlibpath_overrides_runpath=yes # Unless +noenvvar is specified. + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + sys_lib_search_path_spec="/usr/lib/pa20_64 /usr/ccs/lib/pa20_64" + sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec + ;; + *) + shrext_cmds='.sl' + dynamic_linker="$host_os dld.sl" + shlibpath_var=SHLIB_PATH + shlibpath_overrides_runpath=no # +s is required to enable SHLIB_PATH + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + ;; + esac + # HP-UX runs *really* slowly unless shared libraries are mode 555. + postinstall_cmds='chmod 555 $lib' + ;; + +interix[[3-9]]*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + dynamic_linker='Interix 3.x ld.so.1 (PE, like ELF)' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + +irix5* | irix6* | nonstopux*) + case $host_os in + nonstopux*) version_type=nonstopux ;; + *) + if test "$lt_cv_prog_gnu_ld" = yes; then + version_type=linux + else + version_type=irix + fi ;; + esac + need_lib_prefix=no + need_version=no + soname_spec='${libname}${release}${shared_ext}$major' + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext} $libname${shared_ext}' + case $host_os in + irix5* | nonstopux*) + libsuff= shlibsuff= + ;; + *) + case $LD in # libtool.m4 will add one of these switches to LD + *-32|*"-32 "|*-melf32bsmip|*"-melf32bsmip ") + libsuff= shlibsuff= libmagic=32-bit;; + *-n32|*"-n32 "|*-melf32bmipn32|*"-melf32bmipn32 ") + libsuff=32 shlibsuff=N32 libmagic=N32;; + *-64|*"-64 "|*-melf64bmip|*"-melf64bmip ") + libsuff=64 shlibsuff=64 libmagic=64-bit;; + *) libsuff= shlibsuff= libmagic=never-match;; + esac + ;; + esac + shlibpath_var=LD_LIBRARY${shlibsuff}_PATH + shlibpath_overrides_runpath=no + sys_lib_search_path_spec="/usr/lib${libsuff} /lib${libsuff} /usr/local/lib${libsuff}" + sys_lib_dlsearch_path_spec="/usr/lib${libsuff} /lib${libsuff}" + hardcode_into_libs=yes + ;; + +# No shared lib support for Linux oldld, aout, or coff. +linux*oldld* | linux*aout* | linux*coff*) + dynamic_linker=no + ;; + +# This must be Linux ELF. +linux* | k*bsd*-gnu) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -n $libdir' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + # Some binutils ld are patched to set DT_RUNPATH + save_LDFLAGS=$LDFLAGS + save_libdir=$libdir + eval "libdir=/foo; wl=\"$_LT_TAGVAR(lt_prog_compiler_wl, $1)\"; \ + LDFLAGS=\"\$LDFLAGS $_LT_TAGVAR(hardcode_libdir_flag_spec, $1)\"" + AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], + [AS_IF([ ($OBJDUMP -p conftest$ac_exeext) 2>/dev/null | grep "RUNPATH.*$libdir" >/dev/null], + [shlibpath_overrides_runpath=yes])]) + LDFLAGS=$save_LDFLAGS + libdir=$save_libdir + + # This implies no fast_install, which is unacceptable. + # Some rework will be needed to allow for fast_install + # before this can be enabled. + hardcode_into_libs=yes + + # Append ld.so.conf contents to the search path + if test -f /etc/ld.so.conf; then + lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \[$]2)); skip = 1; } { if (!skip) print \[$]0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;/^[ ]*hwcap[ ]/d;s/[:, ]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;/^$/d' | tr '\n' ' '` + sys_lib_dlsearch_path_spec="/lib /usr/lib $lt_ld_extra" + fi + + # We used to test for /lib/ld.so.1 and disable shared libraries on + # powerpc, because MkLinux only supported shared libraries with the + # GNU dynamic linker. Since this was broken with cross compilers, + # most powerpc-linux boxes support dynamic linking these days and + # people can always --disable-shared, the test was removed, and we + # assume the GNU/Linux dynamic linker is in use. + dynamic_linker='GNU/Linux ld.so' + ;; + +netbsd*) + version_type=sunos + need_lib_prefix=no + need_version=no + if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir' + dynamic_linker='NetBSD (a.out) ld.so' + else + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + dynamic_linker='NetBSD ld.elf_so' + fi + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + +newsos6) + version_type=linux + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + ;; + +*nto* | *qnx*) + version_type=qnx + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + dynamic_linker='ldqnx.so' + ;; + +openbsd*) + version_type=sunos + sys_lib_dlsearch_path_spec="/usr/lib" + need_lib_prefix=no + # Some older versions of OpenBSD (3.3 at least) *do* need versioned libs. + case $host_os in + openbsd3.3 | openbsd3.3.*) need_version=yes ;; + *) need_version=no ;; + esac + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir' + shlibpath_var=LD_LIBRARY_PATH + if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then + case $host_os in + openbsd2.[[89]] | openbsd2.[[89]].*) + shlibpath_overrides_runpath=no + ;; + *) + shlibpath_overrides_runpath=yes + ;; + esac + else + shlibpath_overrides_runpath=yes + fi + ;; + +os2*) + libname_spec='$name' + shrext_cmds=".dll" + need_lib_prefix=no + library_names_spec='$libname${shared_ext} $libname.a' + dynamic_linker='OS/2 ld.exe' + shlibpath_var=LIBPATH + ;; + +osf3* | osf4* | osf5*) + version_type=osf + need_lib_prefix=no + need_version=no + soname_spec='${libname}${release}${shared_ext}$major' + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + shlibpath_var=LD_LIBRARY_PATH + sys_lib_search_path_spec="/usr/shlib /usr/ccs/lib /usr/lib/cmplrs/cc /usr/lib /usr/local/lib /var/shlib" + sys_lib_dlsearch_path_spec="$sys_lib_search_path_spec" + ;; + +rdos*) + dynamic_linker=no + ;; + +solaris*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + # ldd complains unless libraries are executable + postinstall_cmds='chmod +x $lib' + ;; + +sunos4*) + version_type=sunos + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix' + finish_cmds='PATH="\$PATH:/usr/etc" ldconfig $libdir' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + if test "$with_gnu_ld" = yes; then + need_lib_prefix=no + fi + need_version=yes + ;; + +sysv4 | sysv4.3*) + version_type=linux + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + case $host_vendor in + sni) + shlibpath_overrides_runpath=no + need_lib_prefix=no + runpath_var=LD_RUN_PATH + ;; + siemens) + need_lib_prefix=no + ;; + motorola) + need_lib_prefix=no + need_version=no + shlibpath_overrides_runpath=no + sys_lib_search_path_spec='/lib /usr/lib /usr/ccs/lib' + ;; + esac + ;; + +sysv4*MP*) + if test -d /usr/nec ;then + version_type=linux + library_names_spec='$libname${shared_ext}.$versuffix $libname${shared_ext}.$major $libname${shared_ext}' + soname_spec='$libname${shared_ext}.$major' + shlibpath_var=LD_LIBRARY_PATH + fi + ;; + +sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*) + version_type=freebsd-elf + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + if test "$with_gnu_ld" = yes; then + sys_lib_search_path_spec='/usr/local/lib /usr/gnu/lib /usr/ccs/lib /usr/lib /lib' + else + sys_lib_search_path_spec='/usr/ccs/lib /usr/lib' + case $host_os in + sco3.2v5*) + sys_lib_search_path_spec="$sys_lib_search_path_spec /lib" + ;; + esac + fi + sys_lib_dlsearch_path_spec='/usr/lib' + ;; + +tpf*) + # TPF is a cross-target only. Preferred cross-host = GNU/Linux. + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + +uts4*) + version_type=linux + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + ;; + +*) + dynamic_linker=no + ;; +esac +AC_MSG_RESULT([$dynamic_linker]) +test "$dynamic_linker" = no && can_build_shared=no + +variables_saved_for_relink="PATH $shlibpath_var $runpath_var" +if test "$GCC" = yes; then + variables_saved_for_relink="$variables_saved_for_relink GCC_EXEC_PREFIX COMPILER_PATH LIBRARY_PATH" +fi + +if test "${lt_cv_sys_lib_search_path_spec+set}" = set; then + sys_lib_search_path_spec="$lt_cv_sys_lib_search_path_spec" +fi +if test "${lt_cv_sys_lib_dlsearch_path_spec+set}" = set; then + sys_lib_dlsearch_path_spec="$lt_cv_sys_lib_dlsearch_path_spec" +fi + +_LT_DECL([], [variables_saved_for_relink], [1], + [Variables whose values should be saved in libtool wrapper scripts and + restored at link time]) +_LT_DECL([], [need_lib_prefix], [0], + [Do we need the "lib" prefix for modules?]) +_LT_DECL([], [need_version], [0], [Do we need a version for libraries?]) +_LT_DECL([], [version_type], [0], [Library versioning type]) +_LT_DECL([], [runpath_var], [0], [Shared library runtime path variable]) +_LT_DECL([], [shlibpath_var], [0],[Shared library path variable]) +_LT_DECL([], [shlibpath_overrides_runpath], [0], + [Is shlibpath searched before the hard-coded library search path?]) +_LT_DECL([], [libname_spec], [1], [Format of library name prefix]) +_LT_DECL([], [library_names_spec], [1], + [[List of archive names. First name is the real one, the rest are links. + The last name is the one that the linker finds with -lNAME]]) +_LT_DECL([], [soname_spec], [1], + [[The coded name of the library, if different from the real name]]) +_LT_DECL([], [postinstall_cmds], [2], + [Command to use after installation of a shared archive]) +_LT_DECL([], [postuninstall_cmds], [2], + [Command to use after uninstallation of a shared archive]) +_LT_DECL([], [finish_cmds], [2], + [Commands used to finish a libtool library installation in a directory]) +_LT_DECL([], [finish_eval], [1], + [[As "finish_cmds", except a single script fragment to be evaled but + not shown]]) +_LT_DECL([], [hardcode_into_libs], [0], + [Whether we should hardcode library paths into libraries]) +_LT_DECL([], [sys_lib_search_path_spec], [2], + [Compile-time system search path for libraries]) +_LT_DECL([], [sys_lib_dlsearch_path_spec], [2], + [Run-time system search path for libraries]) +])# _LT_SYS_DYNAMIC_LINKER + + +# _LT_PATH_TOOL_PREFIX(TOOL) +# -------------------------- +# find a file program which can recognize shared library +AC_DEFUN([_LT_PATH_TOOL_PREFIX], +[m4_require([_LT_DECL_EGREP])dnl +AC_MSG_CHECKING([for $1]) +AC_CACHE_VAL(lt_cv_path_MAGIC_CMD, +[case $MAGIC_CMD in +[[\\/*] | ?:[\\/]*]) + lt_cv_path_MAGIC_CMD="$MAGIC_CMD" # Let the user override the test with a path. + ;; +*) + lt_save_MAGIC_CMD="$MAGIC_CMD" + lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR +dnl $ac_dummy forces splitting on constant user-supplied paths. +dnl POSIX.2 word splitting is done only on the output of word expansions, +dnl not every word. This closes a longstanding sh security hole. + ac_dummy="m4_if([$2], , $PATH, [$2])" + for ac_dir in $ac_dummy; do + IFS="$lt_save_ifs" + test -z "$ac_dir" && ac_dir=. + if test -f $ac_dir/$1; then + lt_cv_path_MAGIC_CMD="$ac_dir/$1" + if test -n "$file_magic_test_file"; then + case $deplibs_check_method in + "file_magic "*) + file_magic_regex=`expr "$deplibs_check_method" : "file_magic \(.*\)"` + MAGIC_CMD="$lt_cv_path_MAGIC_CMD" + if eval $file_magic_cmd \$file_magic_test_file 2> /dev/null | + $EGREP "$file_magic_regex" > /dev/null; then + : + else + cat <<_LT_EOF 1>&2 + +*** Warning: the command libtool uses to detect shared libraries, +*** $file_magic_cmd, produces output that libtool cannot recognize. +*** The result is that libtool may fail to recognize shared libraries +*** as such. This will affect the creation of libtool libraries that +*** depend on shared libraries, but programs linked with such libtool +*** libraries will work regardless of this problem. Nevertheless, you +*** may want to report the problem to your system manager and/or to +*** bug-libtool@gnu.org + +_LT_EOF + fi ;; + esac + fi + break + fi + done + IFS="$lt_save_ifs" + MAGIC_CMD="$lt_save_MAGIC_CMD" + ;; +esac]) +MAGIC_CMD="$lt_cv_path_MAGIC_CMD" +if test -n "$MAGIC_CMD"; then + AC_MSG_RESULT($MAGIC_CMD) +else + AC_MSG_RESULT(no) +fi +_LT_DECL([], [MAGIC_CMD], [0], + [Used to examine libraries when file_magic_cmd begins with "file"])dnl +])# _LT_PATH_TOOL_PREFIX + +# Old name: +AU_ALIAS([AC_PATH_TOOL_PREFIX], [_LT_PATH_TOOL_PREFIX]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_PATH_TOOL_PREFIX], []) + + +# _LT_PATH_MAGIC +# -------------- +# find a file program which can recognize a shared library +m4_defun([_LT_PATH_MAGIC], +[_LT_PATH_TOOL_PREFIX(${ac_tool_prefix}file, /usr/bin$PATH_SEPARATOR$PATH) +if test -z "$lt_cv_path_MAGIC_CMD"; then + if test -n "$ac_tool_prefix"; then + _LT_PATH_TOOL_PREFIX(file, /usr/bin$PATH_SEPARATOR$PATH) + else + MAGIC_CMD=: + fi +fi +])# _LT_PATH_MAGIC + + +# LT_PATH_LD +# ---------- +# find the pathname to the GNU or non-GNU linker +AC_DEFUN([LT_PATH_LD], +[AC_REQUIRE([AC_PROG_CC])dnl +AC_REQUIRE([AC_CANONICAL_HOST])dnl +AC_REQUIRE([AC_CANONICAL_BUILD])dnl +m4_require([_LT_DECL_SED])dnl +m4_require([_LT_DECL_EGREP])dnl + +AC_ARG_WITH([gnu-ld], + [AS_HELP_STRING([--with-gnu-ld], + [assume the C compiler uses GNU ld @<:@default=no@:>@])], + [test "$withval" = no || with_gnu_ld=yes], + [with_gnu_ld=no])dnl + +ac_prog=ld +if test "$GCC" = yes; then + # Check if gcc -print-prog-name=ld gives a path. + AC_MSG_CHECKING([for ld used by $CC]) + case $host in + *-*-mingw*) + # gcc leaves a trailing carriage return which upsets mingw + ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;; + *) + ac_prog=`($CC -print-prog-name=ld) 2>&5` ;; + esac + case $ac_prog in + # Accept absolute paths. + [[\\/]]* | ?:[[\\/]]*) + re_direlt='/[[^/]][[^/]]*/\.\./' + # Canonicalize the pathname of ld + ac_prog=`$ECHO "$ac_prog"| $SED 's%\\\\%/%g'` + while $ECHO "$ac_prog" | $GREP "$re_direlt" > /dev/null 2>&1; do + ac_prog=`$ECHO $ac_prog| $SED "s%$re_direlt%/%"` + done + test -z "$LD" && LD="$ac_prog" + ;; + "") + # If it fails, then pretend we aren't using GCC. + ac_prog=ld + ;; + *) + # If it is relative, then search for the first ld in PATH. + with_gnu_ld=unknown + ;; + esac +elif test "$with_gnu_ld" = yes; then + AC_MSG_CHECKING([for GNU ld]) +else + AC_MSG_CHECKING([for non-GNU ld]) +fi +AC_CACHE_VAL(lt_cv_path_LD, +[if test -z "$LD"; then + lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR + for ac_dir in $PATH; do + IFS="$lt_save_ifs" + test -z "$ac_dir" && ac_dir=. + if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then + lt_cv_path_LD="$ac_dir/$ac_prog" + # Check to see if the program is GNU ld. I'd rather use --version, + # but apparently some variants of GNU ld only accept -v. + # Break only if it was the GNU/non-GNU ld that we prefer. + case `"$lt_cv_path_LD" -v 2>&1 &1 /dev/null 2>&1; then + lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL' + lt_cv_file_magic_cmd='func_win32_libid' + else + lt_cv_deplibs_check_method='file_magic file format pei*-i386(.*architecture: i386)?' + lt_cv_file_magic_cmd='$OBJDUMP -f' + fi + ;; + +cegcc) + # use the weaker test based on 'objdump'. See mingw*. + lt_cv_deplibs_check_method='file_magic file format pe-arm-.*little(.*architecture: arm)?' + lt_cv_file_magic_cmd='$OBJDUMP -f' + ;; + +darwin* | rhapsody*) + lt_cv_deplibs_check_method=pass_all + ;; + +freebsd* | dragonfly*) + if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then + case $host_cpu in + i*86 ) + # Not sure whether the presence of OpenBSD here was a mistake. + # Let's accept both of them until this is cleared up. + lt_cv_deplibs_check_method='file_magic (FreeBSD|OpenBSD|DragonFly)/i[[3-9]]86 (compact )?demand paged shared library' + lt_cv_file_magic_cmd=/usr/bin/file + lt_cv_file_magic_test_file=`echo /usr/lib/libc.so.*` + ;; + esac + else + lt_cv_deplibs_check_method=pass_all + fi + ;; + +gnu*) + lt_cv_deplibs_check_method=pass_all + ;; + +hpux10.20* | hpux11*) + lt_cv_file_magic_cmd=/usr/bin/file + case $host_cpu in + ia64*) + lt_cv_deplibs_check_method='file_magic (s[[0-9]][[0-9]][[0-9]]|ELF-[[0-9]][[0-9]]) shared object file - IA64' + lt_cv_file_magic_test_file=/usr/lib/hpux32/libc.so + ;; + hppa*64*) + [lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|ELF-[0-9][0-9]) shared object file - PA-RISC [0-9].[0-9]'] + lt_cv_file_magic_test_file=/usr/lib/pa20_64/libc.sl + ;; + *) + lt_cv_deplibs_check_method='file_magic (s[[0-9]][[0-9]][[0-9]]|PA-RISC[[0-9]].[[0-9]]) shared library' + lt_cv_file_magic_test_file=/usr/lib/libc.sl + ;; + esac + ;; + +interix[[3-9]]*) + # PIC code is broken on Interix 3.x, that's why |\.a not |_pic\.a here + lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so|\.a)$' + ;; + +irix5* | irix6* | nonstopux*) + case $LD in + *-32|*"-32 ") libmagic=32-bit;; + *-n32|*"-n32 ") libmagic=N32;; + *-64|*"-64 ") libmagic=64-bit;; + *) libmagic=never-match;; + esac + lt_cv_deplibs_check_method=pass_all + ;; + +# This must be Linux ELF. +linux* | k*bsd*-gnu) + lt_cv_deplibs_check_method=pass_all + ;; + +netbsd*) + if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then + lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|_pic\.a)$' + else + lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so|_pic\.a)$' + fi + ;; + +newos6*) + lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (executable|dynamic lib)' + lt_cv_file_magic_cmd=/usr/bin/file + lt_cv_file_magic_test_file=/usr/lib/libnls.so + ;; + +*nto* | *qnx*) + lt_cv_deplibs_check_method=pass_all + ;; + +openbsd*) + if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then + lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|\.so|_pic\.a)$' + else + lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|_pic\.a)$' + fi + ;; + +osf3* | osf4* | osf5*) + lt_cv_deplibs_check_method=pass_all + ;; + +rdos*) + lt_cv_deplibs_check_method=pass_all + ;; + +solaris*) + lt_cv_deplibs_check_method=pass_all + ;; + +sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*) + lt_cv_deplibs_check_method=pass_all + ;; + +sysv4 | sysv4.3*) + case $host_vendor in + motorola) + lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (shared object|dynamic lib) M[[0-9]][[0-9]]* Version [[0-9]]' + lt_cv_file_magic_test_file=`echo /usr/lib/libc.so*` + ;; + ncr) + lt_cv_deplibs_check_method=pass_all + ;; + sequent) + lt_cv_file_magic_cmd='/bin/file' + lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[LM]]SB (shared object|dynamic lib )' + ;; + sni) + lt_cv_file_magic_cmd='/bin/file' + lt_cv_deplibs_check_method="file_magic ELF [[0-9]][[0-9]]*-bit [[LM]]SB dynamic lib" + lt_cv_file_magic_test_file=/lib/libc.so + ;; + siemens) + lt_cv_deplibs_check_method=pass_all + ;; + pc) + lt_cv_deplibs_check_method=pass_all + ;; + esac + ;; + +tpf*) + lt_cv_deplibs_check_method=pass_all + ;; +esac +]) +file_magic_cmd=$lt_cv_file_magic_cmd +deplibs_check_method=$lt_cv_deplibs_check_method +test -z "$deplibs_check_method" && deplibs_check_method=unknown + +_LT_DECL([], [deplibs_check_method], [1], + [Method to check whether dependent libraries are shared objects]) +_LT_DECL([], [file_magic_cmd], [1], + [Command to use when deplibs_check_method == "file_magic"]) +])# _LT_CHECK_MAGIC_METHOD + + +# LT_PATH_NM +# ---------- +# find the pathname to a BSD- or MS-compatible name lister +AC_DEFUN([LT_PATH_NM], +[AC_REQUIRE([AC_PROG_CC])dnl +AC_CACHE_CHECK([for BSD- or MS-compatible name lister (nm)], lt_cv_path_NM, +[if test -n "$NM"; then + # Let the user override the test. + lt_cv_path_NM="$NM" +else + lt_nm_to_check="${ac_tool_prefix}nm" + if test -n "$ac_tool_prefix" && test "$build" = "$host"; then + lt_nm_to_check="$lt_nm_to_check nm" + fi + for lt_tmp_nm in $lt_nm_to_check; do + lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR + for ac_dir in $PATH /usr/ccs/bin/elf /usr/ccs/bin /usr/ucb /bin; do + IFS="$lt_save_ifs" + test -z "$ac_dir" && ac_dir=. + tmp_nm="$ac_dir/$lt_tmp_nm" + if test -f "$tmp_nm" || test -f "$tmp_nm$ac_exeext" ; then + # Check to see if the nm accepts a BSD-compat flag. + # Adding the `sed 1q' prevents false positives on HP-UX, which says: + # nm: unknown option "B" ignored + # Tru64's nm complains that /dev/null is an invalid object file + case `"$tmp_nm" -B /dev/null 2>&1 | sed '1q'` in + */dev/null* | *'Invalid file or object type'*) + lt_cv_path_NM="$tmp_nm -B" + break + ;; + *) + case `"$tmp_nm" -p /dev/null 2>&1 | sed '1q'` in + */dev/null*) + lt_cv_path_NM="$tmp_nm -p" + break + ;; + *) + lt_cv_path_NM=${lt_cv_path_NM="$tmp_nm"} # keep the first match, but + continue # so that we can try to find one that supports BSD flags + ;; + esac + ;; + esac + fi + done + IFS="$lt_save_ifs" + done + : ${lt_cv_path_NM=no} +fi]) +if test "$lt_cv_path_NM" != "no"; then + NM="$lt_cv_path_NM" +else + # Didn't find any BSD compatible name lister, look for dumpbin. + AC_CHECK_TOOLS(DUMPBIN, ["dumpbin -symbols" "link -dump -symbols"], :) + AC_SUBST([DUMPBIN]) + if test "$DUMPBIN" != ":"; then + NM="$DUMPBIN" + fi +fi +test -z "$NM" && NM=nm +AC_SUBST([NM]) +_LT_DECL([], [NM], [1], [A BSD- or MS-compatible name lister])dnl + +AC_CACHE_CHECK([the name lister ($NM) interface], [lt_cv_nm_interface], + [lt_cv_nm_interface="BSD nm" + echo "int some_variable = 0;" > conftest.$ac_ext + (eval echo "\"\$as_me:__oline__: $ac_compile\"" >&AS_MESSAGE_LOG_FD) + (eval "$ac_compile" 2>conftest.err) + cat conftest.err >&AS_MESSAGE_LOG_FD + (eval echo "\"\$as_me:__oline__: $NM \\\"conftest.$ac_objext\\\"\"" >&AS_MESSAGE_LOG_FD) + (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out) + cat conftest.err >&AS_MESSAGE_LOG_FD + (eval echo "\"\$as_me:__oline__: output\"" >&AS_MESSAGE_LOG_FD) + cat conftest.out >&AS_MESSAGE_LOG_FD + if $GREP 'External.*some_variable' conftest.out > /dev/null; then + lt_cv_nm_interface="MS dumpbin" + fi + rm -f conftest*]) +])# LT_PATH_NM + +# Old names: +AU_ALIAS([AM_PROG_NM], [LT_PATH_NM]) +AU_ALIAS([AC_PROG_NM], [LT_PATH_NM]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AM_PROG_NM], []) +dnl AC_DEFUN([AC_PROG_NM], []) + + +# LT_LIB_M +# -------- +# check for math library +AC_DEFUN([LT_LIB_M], +[AC_REQUIRE([AC_CANONICAL_HOST])dnl +LIBM= +case $host in +*-*-beos* | *-*-cygwin* | *-*-pw32* | *-*-darwin*) + # These system don't have libm, or don't need it + ;; +*-ncr-sysv4.3*) + AC_CHECK_LIB(mw, _mwvalidcheckl, LIBM="-lmw") + AC_CHECK_LIB(m, cos, LIBM="$LIBM -lm") + ;; +*) + AC_CHECK_LIB(m, cos, LIBM="-lm") + ;; +esac +AC_SUBST([LIBM]) +])# LT_LIB_M + +# Old name: +AU_ALIAS([AC_CHECK_LIBM], [LT_LIB_M]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_CHECK_LIBM], []) + + +# _LT_COMPILER_NO_RTTI([TAGNAME]) +# ------------------------------- +m4_defun([_LT_COMPILER_NO_RTTI], +[m4_require([_LT_TAG_COMPILER])dnl + +_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)= + +if test "$GCC" = yes; then + _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=' -fno-builtin' + + _LT_COMPILER_OPTION([if $compiler supports -fno-rtti -fno-exceptions], + lt_cv_prog_compiler_rtti_exceptions, + [-fno-rtti -fno-exceptions], [], + [_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)="$_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1) -fno-rtti -fno-exceptions"]) +fi +_LT_TAGDECL([no_builtin_flag], [lt_prog_compiler_no_builtin_flag], [1], + [Compiler flag to turn off builtin functions]) +])# _LT_COMPILER_NO_RTTI + + +# _LT_CMD_GLOBAL_SYMBOLS +# ---------------------- +m4_defun([_LT_CMD_GLOBAL_SYMBOLS], +[AC_REQUIRE([AC_CANONICAL_HOST])dnl +AC_REQUIRE([AC_PROG_CC])dnl +AC_REQUIRE([LT_PATH_NM])dnl +AC_REQUIRE([LT_PATH_LD])dnl +m4_require([_LT_DECL_SED])dnl +m4_require([_LT_DECL_EGREP])dnl +m4_require([_LT_TAG_COMPILER])dnl + +# Check for command to grab the raw symbol name followed by C symbol from nm. +AC_MSG_CHECKING([command to parse $NM output from $compiler object]) +AC_CACHE_VAL([lt_cv_sys_global_symbol_pipe], +[ +# These are sane defaults that work on at least a few old systems. +# [They come from Ultrix. What could be older than Ultrix?!! ;)] + +# Character class describing NM global symbol codes. +symcode='[[BCDEGRST]]' + +# Regexp to match symbols that can be accessed directly from C. +sympat='\([[_A-Za-z]][[_A-Za-z0-9]]*\)' + +# Define system-specific variables. +case $host_os in +aix*) + symcode='[[BCDT]]' + ;; +cygwin* | mingw* | pw32* | cegcc*) + symcode='[[ABCDGISTW]]' + ;; +hpux*) + if test "$host_cpu" = ia64; then + symcode='[[ABCDEGRST]]' + fi + ;; +irix* | nonstopux*) + symcode='[[BCDEGRST]]' + ;; +osf*) + symcode='[[BCDEGQRST]]' + ;; +solaris*) + symcode='[[BDRT]]' + ;; +sco3.2v5*) + symcode='[[DT]]' + ;; +sysv4.2uw2*) + symcode='[[DT]]' + ;; +sysv5* | sco5v6* | unixware* | OpenUNIX*) + symcode='[[ABDT]]' + ;; +sysv4) + symcode='[[DFNSTU]]' + ;; +esac + +# If we're using GNU nm, then use its standard symbol codes. +case `$NM -V 2>&1` in +*GNU* | *'with BFD'*) + symcode='[[ABCDGIRSTW]]' ;; +esac + +# Transform an extracted symbol line into a proper C declaration. +# Some systems (esp. on ia64) link data and code symbols differently, +# so use this general approach. +lt_cv_sys_global_symbol_to_cdecl="sed -n -e 's/^T .* \(.*\)$/extern int \1();/p' -e 's/^$symcode* .* \(.*\)$/extern char \1;/p'" + +# Transform an extracted symbol line into symbol name and symbol address +lt_cv_sys_global_symbol_to_c_name_address="sed -n -e 's/^: \([[^ ]]*\) $/ {\\\"\1\\\", (void *) 0},/p' -e 's/^$symcode* \([[^ ]]*\) \([[^ ]]*\)$/ {\"\2\", (void *) \&\2},/p'" +lt_cv_sys_global_symbol_to_c_name_address_lib_prefix="sed -n -e 's/^: \([[^ ]]*\) $/ {\\\"\1\\\", (void *) 0},/p' -e 's/^$symcode* \([[^ ]]*\) \(lib[[^ ]]*\)$/ {\"\2\", (void *) \&\2},/p' -e 's/^$symcode* \([[^ ]]*\) \([[^ ]]*\)$/ {\"lib\2\", (void *) \&\2},/p'" + +# Handle CRLF in mingw tool chain +opt_cr= +case $build_os in +mingw*) + opt_cr=`$ECHO 'x\{0,1\}' | tr x '\015'` # option cr in regexp + ;; +esac + +# Try without a prefix underscore, then with it. +for ac_symprfx in "" "_"; do + + # Transform symcode, sympat, and symprfx into a raw symbol and a C symbol. + symxfrm="\\1 $ac_symprfx\\2 \\2" + + # Write the raw and C identifiers. + if test "$lt_cv_nm_interface" = "MS dumpbin"; then + # Fake it for dumpbin and say T for any non-static function + # and D for any global variable. + # Also find C++ and __fastcall symbols from MSVC++, + # which start with @ or ?. + lt_cv_sys_global_symbol_pipe="$AWK ['"\ +" {last_section=section; section=\$ 3};"\ +" /Section length .*#relocs.*(pick any)/{hide[last_section]=1};"\ +" \$ 0!~/External *\|/{next};"\ +" / 0+ UNDEF /{next}; / UNDEF \([^|]\)*()/{next};"\ +" {if(hide[section]) next};"\ +" {f=0}; \$ 0~/\(\).*\|/{f=1}; {printf f ? \"T \" : \"D \"};"\ +" {split(\$ 0, a, /\||\r/); split(a[2], s)};"\ +" s[1]~/^[@?]/{print s[1], s[1]; next};"\ +" s[1]~prfx {split(s[1],t,\"@\"); print t[1], substr(t[1],length(prfx))}"\ +" ' prfx=^$ac_symprfx]" + else + lt_cv_sys_global_symbol_pipe="sed -n -e 's/^.*[[ ]]\($symcode$symcode*\)[[ ]][[ ]]*$ac_symprfx$sympat$opt_cr$/$symxfrm/p'" + fi + + # Check to see that the pipe works correctly. + pipe_works=no + + rm -f conftest* + cat > conftest.$ac_ext <<_LT_EOF +#ifdef __cplusplus +extern "C" { +#endif +char nm_test_var; +void nm_test_func(void); +void nm_test_func(void){} +#ifdef __cplusplus +} +#endif +int main(){nm_test_var='a';nm_test_func();return(0);} +_LT_EOF + + if AC_TRY_EVAL(ac_compile); then + # Now try to grab the symbols. + nlist=conftest.nm + if AC_TRY_EVAL(NM conftest.$ac_objext \| $lt_cv_sys_global_symbol_pipe \> $nlist) && test -s "$nlist"; then + # Try sorting and uniquifying the output. + if sort "$nlist" | uniq > "$nlist"T; then + mv -f "$nlist"T "$nlist" + else + rm -f "$nlist"T + fi + + # Make sure that we snagged all the symbols we need. + if $GREP ' nm_test_var$' "$nlist" >/dev/null; then + if $GREP ' nm_test_func$' "$nlist" >/dev/null; then + cat <<_LT_EOF > conftest.$ac_ext +#ifdef __cplusplus +extern "C" { +#endif + +_LT_EOF + # Now generate the symbol file. + eval "$lt_cv_sys_global_symbol_to_cdecl"' < "$nlist" | $GREP -v main >> conftest.$ac_ext' + + cat <<_LT_EOF >> conftest.$ac_ext + +/* The mapping between symbol names and symbols. */ +const struct { + const char *name; + void *address; +} +lt__PROGRAM__LTX_preloaded_symbols[[]] = +{ + { "@PROGRAM@", (void *) 0 }, +_LT_EOF + $SED "s/^$symcode$symcode* \(.*\) \(.*\)$/ {\"\2\", (void *) \&\2},/" < "$nlist" | $GREP -v main >> conftest.$ac_ext + cat <<\_LT_EOF >> conftest.$ac_ext + {0, (void *) 0} +}; + +/* This works around a problem in FreeBSD linker */ +#ifdef FREEBSD_WORKAROUND +static const void *lt_preloaded_setup() { + return lt__PROGRAM__LTX_preloaded_symbols; +} +#endif + +#ifdef __cplusplus +} +#endif +_LT_EOF + # Now try linking the two files. + mv conftest.$ac_objext conftstm.$ac_objext + lt_save_LIBS="$LIBS" + lt_save_CFLAGS="$CFLAGS" + LIBS="conftstm.$ac_objext" + CFLAGS="$CFLAGS$_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)" + if AC_TRY_EVAL(ac_link) && test -s conftest${ac_exeext}; then + pipe_works=yes + fi + LIBS="$lt_save_LIBS" + CFLAGS="$lt_save_CFLAGS" + else + echo "cannot find nm_test_func in $nlist" >&AS_MESSAGE_LOG_FD + fi + else + echo "cannot find nm_test_var in $nlist" >&AS_MESSAGE_LOG_FD + fi + else + echo "cannot run $lt_cv_sys_global_symbol_pipe" >&AS_MESSAGE_LOG_FD + fi + else + echo "$progname: failed program was:" >&AS_MESSAGE_LOG_FD + cat conftest.$ac_ext >&5 + fi + rm -rf conftest* conftst* + + # Do not use the global_symbol_pipe unless it works. + if test "$pipe_works" = yes; then + break + else + lt_cv_sys_global_symbol_pipe= + fi +done +]) +if test -z "$lt_cv_sys_global_symbol_pipe"; then + lt_cv_sys_global_symbol_to_cdecl= +fi +if test -z "$lt_cv_sys_global_symbol_pipe$lt_cv_sys_global_symbol_to_cdecl"; then + AC_MSG_RESULT(failed) +else + AC_MSG_RESULT(ok) +fi + +_LT_DECL([global_symbol_pipe], [lt_cv_sys_global_symbol_pipe], [1], + [Take the output of nm and produce a listing of raw symbols and C names]) +_LT_DECL([global_symbol_to_cdecl], [lt_cv_sys_global_symbol_to_cdecl], [1], + [Transform the output of nm in a proper C declaration]) +_LT_DECL([global_symbol_to_c_name_address], + [lt_cv_sys_global_symbol_to_c_name_address], [1], + [Transform the output of nm in a C name address pair]) +_LT_DECL([global_symbol_to_c_name_address_lib_prefix], + [lt_cv_sys_global_symbol_to_c_name_address_lib_prefix], [1], + [Transform the output of nm in a C name address pair when lib prefix is needed]) +]) # _LT_CMD_GLOBAL_SYMBOLS + + +# _LT_COMPILER_PIC([TAGNAME]) +# --------------------------- +m4_defun([_LT_COMPILER_PIC], +[m4_require([_LT_TAG_COMPILER])dnl +_LT_TAGVAR(lt_prog_compiler_wl, $1)= +_LT_TAGVAR(lt_prog_compiler_pic, $1)= +_LT_TAGVAR(lt_prog_compiler_static, $1)= + +AC_MSG_CHECKING([for $compiler option to produce PIC]) +m4_if([$1], [CXX], [ + # C++ specific cases for pic, static, wl, etc. + if test "$GXX" = yes; then + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' + + case $host_os in + aix*) + # All AIX code is PIC. + if test "$host_cpu" = ia64; then + # AIX 5 now supports IA64 processor + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + fi + ;; + + amigaos*) + case $host_cpu in + powerpc) + # see comment about AmigaOS4 .so support + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + m68k) + # FIXME: we need at least 68020 code to build shared libraries, but + # adding the `-m68020' flag to GCC prevents building anything better, + # like `-m68040'. + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-m68020 -resident32 -malways-restore-a4' + ;; + esac + ;; + + beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*) + # PIC is the default for these OSes. + ;; + mingw* | cygwin* | os2* | pw32* | cegcc*) + # This hack is so that the source file can tell whether it is being + # built for inclusion in a dll (and should export symbols for example). + # Although the cygwin gcc ignores -fPIC, still need this for old-style + # (--disable-auto-import) libraries + m4_if([$1], [GCJ], [], + [_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT']) + ;; + darwin* | rhapsody*) + # PIC is the default on this platform + # Common symbols not allowed in MH_DYLIB files + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fno-common' + ;; + *djgpp*) + # DJGPP does not support shared libraries at all + _LT_TAGVAR(lt_prog_compiler_pic, $1)= + ;; + interix[[3-9]]*) + # Interix 3.x gcc -fpic/-fPIC options generate broken code. + # Instead, we relocate shared libraries at runtime. + ;; + sysv4*MP*) + if test -d /usr/nec; then + _LT_TAGVAR(lt_prog_compiler_pic, $1)=-Kconform_pic + fi + ;; + hpux*) + # PIC is the default for 64-bit PA HP-UX, but not for 32-bit + # PA HP-UX. On IA64 HP-UX, PIC is the default but the pic flag + # sets the default TLS model and affects inlining. + case $host_cpu in + hppa*64*) + ;; + *) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + esac + ;; + *qnx* | *nto*) + # QNX uses GNU C++, but need to define -shared option too, otherwise + # it will coredump. + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared' + ;; + *) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + esac + else + case $host_os in + aix[[4-9]]*) + # All AIX code is PIC. + if test "$host_cpu" = ia64; then + # AIX 5 now supports IA64 processor + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + else + _LT_TAGVAR(lt_prog_compiler_static, $1)='-bnso -bI:/lib/syscalls.exp' + fi + ;; + chorus*) + case $cc_basename in + cxch68*) + # Green Hills C++ Compiler + # _LT_TAGVAR(lt_prog_compiler_static, $1)="--no_auto_instantiation -u __main -u __premain -u _abort -r $COOL_DIR/lib/libOrb.a $MVME_DIR/lib/CC/libC.a $MVME_DIR/lib/classix/libcx.s.a" + ;; + esac + ;; + dgux*) + case $cc_basename in + ec++*) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + ;; + ghcx*) + # Green Hills C++ Compiler + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic' + ;; + *) + ;; + esac + ;; + freebsd* | dragonfly*) + # FreeBSD uses GNU C++ + ;; + hpux9* | hpux10* | hpux11*) + case $cc_basename in + CC*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_static, $1)='${wl}-a ${wl}archive' + if test "$host_cpu" != ia64; then + _LT_TAGVAR(lt_prog_compiler_pic, $1)='+Z' + fi + ;; + aCC*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_static, $1)='${wl}-a ${wl}archive' + case $host_cpu in + hppa*64*|ia64*) + # +Z the default + ;; + *) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='+Z' + ;; + esac + ;; + *) + ;; + esac + ;; + interix*) + # This is c89, which is MS Visual C++ (no shared libs) + # Anyone wants to do a port? + ;; + irix5* | irix6* | nonstopux*) + case $cc_basename in + CC*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + # CC pic flag -KPIC is the default. + ;; + *) + ;; + esac + ;; + linux* | k*bsd*-gnu) + case $cc_basename in + KCC*) + # KAI C++ Compiler + _LT_TAGVAR(lt_prog_compiler_wl, $1)='--backend -Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + ecpc* ) + # old Intel C++ for x86_64 which still supported -KPIC. + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' + ;; + icpc* ) + # Intel C++, used to be incompatible with GCC. + # ICC 10 doesn't accept -KPIC any more. + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' + ;; + pgCC* | pgcpp*) + # Portland Group C++ compiler + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fpic' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + cxx*) + # Compaq C++ + # Make sure the PIC flag is empty. It appears that all Alpha + # Linux and Compaq Tru64 Unix objects are PIC. + _LT_TAGVAR(lt_prog_compiler_pic, $1)= + _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + ;; + xlc* | xlC*) + # IBM XL 8.0 on PPC + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-qpic' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-qstaticlink' + ;; + *) + case `$CC -V 2>&1 | sed 5q` in + *Sun\ C*) + # Sun C++ 5.9 + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ' + ;; + esac + ;; + esac + ;; + lynxos*) + ;; + m88k*) + ;; + mvs*) + case $cc_basename in + cxx*) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-W c,exportall' + ;; + *) + ;; + esac + ;; + netbsd*) + ;; + *qnx* | *nto*) + # QNX uses GNU C++, but need to define -shared option too, otherwise + # it will coredump. + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared' + ;; + osf3* | osf4* | osf5*) + case $cc_basename in + KCC*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='--backend -Wl,' + ;; + RCC*) + # Rational C++ 2.4.1 + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic' + ;; + cxx*) + # Digital/Compaq C++ + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + # Make sure the PIC flag is empty. It appears that all Alpha + # Linux and Compaq Tru64 Unix objects are PIC. + _LT_TAGVAR(lt_prog_compiler_pic, $1)= + _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + ;; + *) + ;; + esac + ;; + psos*) + ;; + solaris*) + case $cc_basename in + CC*) + # Sun C++ 4.2, 5.x and Centerline C++ + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ' + ;; + gcx*) + # Green Hills C++ Compiler + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-PIC' + ;; + *) + ;; + esac + ;; + sunos4*) + case $cc_basename in + CC*) + # Sun C++ 4.x + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + lcc*) + # Lucid + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic' + ;; + *) + ;; + esac + ;; + sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*) + case $cc_basename in + CC*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + esac + ;; + tandem*) + case $cc_basename in + NCC*) + # NonStop-UX NCC 3.20 + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + ;; + *) + ;; + esac + ;; + vxworks*) + ;; + *) + _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no + ;; + esac + fi +], +[ + if test "$GCC" = yes; then + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' + + case $host_os in + aix*) + # All AIX code is PIC. + if test "$host_cpu" = ia64; then + # AIX 5 now supports IA64 processor + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + fi + ;; + + amigaos*) + case $host_cpu in + powerpc) + # see comment about AmigaOS4 .so support + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + m68k) + # FIXME: we need at least 68020 code to build shared libraries, but + # adding the `-m68020' flag to GCC prevents building anything better, + # like `-m68040'. + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-m68020 -resident32 -malways-restore-a4' + ;; + esac + ;; + + beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*) + # PIC is the default for these OSes. + ;; + + mingw* | cygwin* | pw32* | os2* | cegcc*) + # This hack is so that the source file can tell whether it is being + # built for inclusion in a dll (and should export symbols for example). + # Although the cygwin gcc ignores -fPIC, still need this for old-style + # (--disable-auto-import) libraries + m4_if([$1], [GCJ], [], + [_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT']) + ;; + + darwin* | rhapsody*) + # PIC is the default on this platform + # Common symbols not allowed in MH_DYLIB files + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fno-common' + ;; + + hpux*) + # PIC is the default for 64-bit PA HP-UX, but not for 32-bit + # PA HP-UX. On IA64 HP-UX, PIC is the default but the pic flag + # sets the default TLS model and affects inlining. + case $host_cpu in + hppa*64*) + # +Z the default + ;; + *) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + esac + ;; + + interix[[3-9]]*) + # Interix 3.x gcc -fpic/-fPIC options generate broken code. + # Instead, we relocate shared libraries at runtime. + ;; + + msdosdjgpp*) + # Just because we use GCC doesn't mean we suddenly get shared libraries + # on systems that don't support them. + _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no + enable_shared=no + ;; + + *nto* | *qnx*) + # QNX uses GNU C++, but need to define -shared option too, otherwise + # it will coredump. + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared' + ;; + + sysv4*MP*) + if test -d /usr/nec; then + _LT_TAGVAR(lt_prog_compiler_pic, $1)=-Kconform_pic + fi + ;; + + *) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + esac + else + # PORTME Check for flag to pass linker flags through the system compiler. + case $host_os in + aix*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + if test "$host_cpu" = ia64; then + # AIX 5 now supports IA64 processor + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + else + _LT_TAGVAR(lt_prog_compiler_static, $1)='-bnso -bI:/lib/syscalls.exp' + fi + ;; + + mingw* | cygwin* | pw32* | os2* | cegcc*) + # This hack is so that the source file can tell whether it is being + # built for inclusion in a dll (and should export symbols for example). + m4_if([$1], [GCJ], [], + [_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT']) + ;; + + hpux9* | hpux10* | hpux11*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but + # not for PA HP-UX. + case $host_cpu in + hppa*64*|ia64*) + # +Z the default + ;; + *) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='+Z' + ;; + esac + # Is there a better lt_prog_compiler_static that works with the bundled CC? + _LT_TAGVAR(lt_prog_compiler_static, $1)='${wl}-a ${wl}archive' + ;; + + irix5* | irix6* | nonstopux*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + # PIC (with -KPIC) is the default. + _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + ;; + + linux* | k*bsd*-gnu) + case $cc_basename in + # old Intel for x86_64 which still supported -KPIC. + ecc*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' + ;; + # icc used to be incompatible with GCC. + # ICC 10 doesn't accept -KPIC any more. + icc* | ifort*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' + ;; + # Lahey Fortran 8.1. + lf95*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='--shared' + _LT_TAGVAR(lt_prog_compiler_static, $1)='--static' + ;; + pgcc* | pgf77* | pgf90* | pgf95*) + # Portland Group compilers (*not* the Pentium gcc compiler, + # which looks to be a dead project) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fpic' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + ccc*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + # All Alpha code is PIC. + _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + ;; + xl*) + # IBM XL C 8.0/Fortran 10.1 on PPC + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-qpic' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-qstaticlink' + ;; + *) + case `$CC -V 2>&1 | sed 5q` in + *Sun\ C*) + # Sun C 5.9 + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + ;; + *Sun\ F*) + # Sun Fortran 8.3 passes all unrecognized flags to the linker + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + _LT_TAGVAR(lt_prog_compiler_wl, $1)='' + ;; + esac + ;; + esac + ;; + + newsos6) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + + *nto* | *qnx*) + # QNX uses GNU C++, but need to define -shared option too, otherwise + # it will coredump. + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared' + ;; + + osf3* | osf4* | osf5*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + # All OSF/1 code is PIC. + _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + ;; + + rdos*) + _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + ;; + + solaris*) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + case $cc_basename in + f77* | f90* | f95*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ';; + *) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,';; + esac + ;; + + sunos4*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-PIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + + sysv4 | sysv4.2uw2* | sysv4.3*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + + sysv4*MP*) + if test -d /usr/nec ;then + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-Kconform_pic' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + fi + ;; + + sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + + unicos*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no + ;; + + uts4*) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + + *) + _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no + ;; + esac + fi +]) +case $host_os in + # For platforms which do not support PIC, -DPIC is meaningless: + *djgpp*) + _LT_TAGVAR(lt_prog_compiler_pic, $1)= + ;; + *) + _LT_TAGVAR(lt_prog_compiler_pic, $1)="$_LT_TAGVAR(lt_prog_compiler_pic, $1)@&t@m4_if([$1],[],[ -DPIC],[m4_if([$1],[CXX],[ -DPIC],[])])" + ;; +esac +AC_MSG_RESULT([$_LT_TAGVAR(lt_prog_compiler_pic, $1)]) +_LT_TAGDECL([wl], [lt_prog_compiler_wl], [1], + [How to pass a linker flag through the compiler]) + +# +# Check to make sure the PIC flag actually works. +# +if test -n "$_LT_TAGVAR(lt_prog_compiler_pic, $1)"; then + _LT_COMPILER_OPTION([if $compiler PIC flag $_LT_TAGVAR(lt_prog_compiler_pic, $1) works], + [_LT_TAGVAR(lt_cv_prog_compiler_pic_works, $1)], + [$_LT_TAGVAR(lt_prog_compiler_pic, $1)@&t@m4_if([$1],[],[ -DPIC],[m4_if([$1],[CXX],[ -DPIC],[])])], [], + [case $_LT_TAGVAR(lt_prog_compiler_pic, $1) in + "" | " "*) ;; + *) _LT_TAGVAR(lt_prog_compiler_pic, $1)=" $_LT_TAGVAR(lt_prog_compiler_pic, $1)" ;; + esac], + [_LT_TAGVAR(lt_prog_compiler_pic, $1)= + _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no]) +fi +_LT_TAGDECL([pic_flag], [lt_prog_compiler_pic], [1], + [Additional compiler flags for building library objects]) + +# +# Check to make sure the static flag actually works. +# +wl=$_LT_TAGVAR(lt_prog_compiler_wl, $1) eval lt_tmp_static_flag=\"$_LT_TAGVAR(lt_prog_compiler_static, $1)\" +_LT_LINKER_OPTION([if $compiler static flag $lt_tmp_static_flag works], + _LT_TAGVAR(lt_cv_prog_compiler_static_works, $1), + $lt_tmp_static_flag, + [], + [_LT_TAGVAR(lt_prog_compiler_static, $1)=]) +_LT_TAGDECL([link_static_flag], [lt_prog_compiler_static], [1], + [Compiler flag to prevent dynamic linking]) +])# _LT_COMPILER_PIC + + +# _LT_LINKER_SHLIBS([TAGNAME]) +# ---------------------------- +# See if the linker supports building shared libraries. +m4_defun([_LT_LINKER_SHLIBS], +[AC_REQUIRE([LT_PATH_LD])dnl +AC_REQUIRE([LT_PATH_NM])dnl +m4_require([_LT_FILEUTILS_DEFAULTS])dnl +m4_require([_LT_DECL_EGREP])dnl +m4_require([_LT_DECL_SED])dnl +m4_require([_LT_CMD_GLOBAL_SYMBOLS])dnl +m4_require([_LT_TAG_COMPILER])dnl +AC_MSG_CHECKING([whether the $compiler linker ($LD) supports shared libraries]) +m4_if([$1], [CXX], [ + _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' + case $host_os in + aix[[4-9]]*) + # If we're using GNU nm, then we don't want the "-C" option. + # -C means demangle to AIX nm, but means don't demangle with GNU nm + if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then + _LT_TAGVAR(export_symbols_cmds, $1)='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && ([substr](\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols' + else + _LT_TAGVAR(export_symbols_cmds, $1)='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && ([substr](\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols' + fi + ;; + pw32*) + _LT_TAGVAR(export_symbols_cmds, $1)="$ltdll_cmds" + ;; + cygwin* | mingw* | cegcc*) + _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]][[ ]]/s/.*[[ ]]\([[^ ]]*\)/\1 DATA/;/^.*[[ ]]__nm__/s/^.*[[ ]]__nm__\([[^ ]]*\)[[ ]][[^ ]]*/\1 DATA/;/^I[[ ]]/d;/^[[AITW]][[ ]]/s/.* //'\'' | sort | uniq > $export_symbols' + ;; + *) + _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' + ;; + esac + _LT_TAGVAR(exclude_expsyms, $1)=['_GLOBAL_OFFSET_TABLE_|_GLOBAL__F[ID]_.*'] +], [ + runpath_var= + _LT_TAGVAR(allow_undefined_flag, $1)= + _LT_TAGVAR(always_export_symbols, $1)=no + _LT_TAGVAR(archive_cmds, $1)= + _LT_TAGVAR(archive_expsym_cmds, $1)= + _LT_TAGVAR(compiler_needs_object, $1)=no + _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no + _LT_TAGVAR(export_dynamic_flag_spec, $1)= + _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' + _LT_TAGVAR(hardcode_automatic, $1)=no + _LT_TAGVAR(hardcode_direct, $1)=no + _LT_TAGVAR(hardcode_direct_absolute, $1)=no + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)= + _LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)= + _LT_TAGVAR(hardcode_libdir_separator, $1)= + _LT_TAGVAR(hardcode_minus_L, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=unsupported + _LT_TAGVAR(inherit_rpath, $1)=no + _LT_TAGVAR(link_all_deplibs, $1)=unknown + _LT_TAGVAR(module_cmds, $1)= + _LT_TAGVAR(module_expsym_cmds, $1)= + _LT_TAGVAR(old_archive_from_new_cmds, $1)= + _LT_TAGVAR(old_archive_from_expsyms_cmds, $1)= + _LT_TAGVAR(thread_safe_flag_spec, $1)= + _LT_TAGVAR(whole_archive_flag_spec, $1)= + # include_expsyms should be a list of space-separated symbols to be *always* + # included in the symbol list + _LT_TAGVAR(include_expsyms, $1)= + # exclude_expsyms can be an extended regexp of symbols to exclude + # it will be wrapped by ` (' and `)$', so one must not match beginning or + # end of line. Example: `a|bc|.*d.*' will exclude the symbols `a' and `bc', + # as well as any symbol that contains `d'. + _LT_TAGVAR(exclude_expsyms, $1)=['_GLOBAL_OFFSET_TABLE_|_GLOBAL__F[ID]_.*'] + # Although _GLOBAL_OFFSET_TABLE_ is a valid symbol C name, most a.out + # platforms (ab)use it in PIC code, but their linkers get confused if + # the symbol is explicitly referenced. Since portable code cannot + # rely on this symbol name, it's probably fine to never include it in + # preloaded symbol tables. + # Exclude shared library initialization/finalization symbols. +dnl Note also adjust exclude_expsyms for C++ above. + extract_expsyms_cmds= + + case $host_os in + cygwin* | mingw* | pw32* | cegcc*) + # FIXME: the MSVC++ port hasn't been tested in a loooong time + # When not using gcc, we currently assume that we are using + # Microsoft Visual C++. + if test "$GCC" != yes; then + with_gnu_ld=no + fi + ;; + interix*) + # we just hope/assume this is gcc and not c89 (= MSVC++) + with_gnu_ld=yes + ;; + openbsd*) + with_gnu_ld=no + ;; + esac + + _LT_TAGVAR(ld_shlibs, $1)=yes + if test "$with_gnu_ld" = yes; then + # If archive_cmds runs LD, not CC, wlarc should be empty + wlarc='${wl}' + + # Set some defaults for GNU ld with shared library support. These + # are reset later if shared libraries are not supported. Putting them + # here allows them to be overridden if necessary. + runpath_var=LD_RUN_PATH + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic' + # ancient GNU ld didn't support --whole-archive et. al. + if $LD --help 2>&1 | $GREP 'no-whole-archive' > /dev/null; then + _LT_TAGVAR(whole_archive_flag_spec, $1)="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive' + else + _LT_TAGVAR(whole_archive_flag_spec, $1)= + fi + supports_anon_versioning=no + case `$LD -v 2>&1` in + *\ [[01]].* | *\ 2.[[0-9]].* | *\ 2.10.*) ;; # catch versions < 2.11 + *\ 2.11.93.0.2\ *) supports_anon_versioning=yes ;; # RH7.3 ... + *\ 2.11.92.0.12\ *) supports_anon_versioning=yes ;; # Mandrake 8.2 ... + *\ 2.11.*) ;; # other 2.11 versions + *) supports_anon_versioning=yes ;; + esac + + # See if GNU ld supports shared libraries. + case $host_os in + aix[[3-9]]*) + # On AIX/PPC, the GNU linker is very broken + if test "$host_cpu" != ia64; then + _LT_TAGVAR(ld_shlibs, $1)=no + cat <<_LT_EOF 1>&2 + +*** Warning: the GNU linker, at least up to release 2.9.1, is reported +*** to be unable to reliably create shared libraries on AIX. +*** Therefore, libtool is disabling shared libraries support. If you +*** really care for shared libraries, you may want to modify your PATH +*** so that a non-GNU linker is found, and then restart. + +_LT_EOF + fi + ;; + + amigaos*) + case $host_cpu in + powerpc) + # see comment about AmigaOS4 .so support + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='' + ;; + m68k) + _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_minus_L, $1)=yes + ;; + esac + ;; + + beos*) + if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + # Joseph Beckenbach says some releases of gcc + # support --undefined. This deserves some investigation. FIXME + _LT_TAGVAR(archive_cmds, $1)='$CC -nostart $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + cygwin* | mingw* | pw32* | cegcc*) + # _LT_TAGVAR(hardcode_libdir_flag_spec, $1) is actually meaningless, + # as there is no search path for DLLs. + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + _LT_TAGVAR(always_export_symbols, $1)=no + _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes + _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]][[ ]]/s/.*[[ ]]\([[^ ]]*\)/\1 DATA/'\'' | $SED -e '\''/^[[AITW]][[ ]]/s/.*[[ ]]//'\'' | sort | uniq > $export_symbols' + + if $LD --help 2>&1 | $GREP 'auto-import' > /dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + # If the export-symbols file already is a .def file (1st line + # is EXPORTS), use it as is; otherwise, prepend... + _LT_TAGVAR(archive_expsym_cmds, $1)='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then + cp $export_symbols $output_objdir/$soname.def; + else + echo EXPORTS > $output_objdir/$soname.def; + cat $export_symbols >> $output_objdir/$soname.def; + fi~ + $CC -shared $output_objdir/$soname.def $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + interix[[3-9]]*) + _LT_TAGVAR(hardcode_direct, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' + # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc. + # Instead, shared libraries are loaded at an image base (0x10000000 by + # default) and relocated if they conflict, which is a slow very memory + # consuming and fragmenting process. To avoid this, we pick a random, + # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link + # time. Moving up from 0x10000000 also allows more sbrk(2) space. + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='sed "s,^,_," $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--retain-symbols-file,$output_objdir/$soname.expsym ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + ;; + + gnu* | linux* | tpf* | k*bsd*-gnu) + tmp_diet=no + if test "$host_os" = linux-dietlibc; then + case $cc_basename in + diet\ *) tmp_diet=yes;; # linux-dietlibc with static linking (!diet-dyn) + esac + fi + if $LD --help 2>&1 | $EGREP ': supported targets:.* elf' > /dev/null \ + && test "$tmp_diet" = no + then + tmp_addflag= + tmp_sharedflag='-shared' + case $cc_basename,$host_cpu in + pgcc*) # Portland Group C compiler + _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive' + tmp_addflag=' $pic_flag' + ;; + pgf77* | pgf90* | pgf95*) # Portland Group f77 and f90 compilers + _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive' + tmp_addflag=' $pic_flag -Mnomain' ;; + ecc*,ia64* | icc*,ia64*) # Intel C compiler on ia64 + tmp_addflag=' -i_dynamic' ;; + efc*,ia64* | ifort*,ia64*) # Intel Fortran compiler on ia64 + tmp_addflag=' -i_dynamic -nofor_main' ;; + ifc* | ifort*) # Intel Fortran compiler + tmp_addflag=' -nofor_main' ;; + lf95*) # Lahey Fortran 8.1 + _LT_TAGVAR(whole_archive_flag_spec, $1)= + tmp_sharedflag='--shared' ;; + xl[[cC]]*) # IBM XL C 8.0 on PPC (deal with xlf below) + tmp_sharedflag='-qmkshrobj' + tmp_addflag= ;; + esac + case `$CC -V 2>&1 | sed 5q` in + *Sun\ C*) # Sun C 5.9 + _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive' + _LT_TAGVAR(compiler_needs_object, $1)=yes + tmp_sharedflag='-G' ;; + *Sun\ F*) # Sun Fortran 8.3 + tmp_sharedflag='-G' ;; + esac + _LT_TAGVAR(archive_cmds, $1)='$CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + + if test "x$supports_anon_versioning" = xyes; then + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~ + cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ + echo "local: *; };" >> $output_objdir/$libname.ver~ + $CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-version-script ${wl}$output_objdir/$libname.ver -o $lib' + fi + + case $cc_basename in + xlf*) + # IBM XL Fortran 10.1 on PPC cannot create shared libs itself + _LT_TAGVAR(whole_archive_flag_spec, $1)='--whole-archive$convenience --no-whole-archive' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)= + _LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)='-rpath $libdir' + _LT_TAGVAR(archive_cmds, $1)='$LD -shared $libobjs $deplibs $compiler_flags -soname $soname -o $lib' + if test "x$supports_anon_versioning" = xyes; then + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~ + cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ + echo "local: *; };" >> $output_objdir/$libname.ver~ + $LD -shared $libobjs $deplibs $compiler_flags -soname $soname -version-script $output_objdir/$libname.ver -o $lib' + fi + ;; + esac + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + netbsd*) + if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib' + wlarc= + else + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + fi + ;; + + solaris*) + if $LD -v 2>&1 | $GREP 'BFD 2\.8' > /dev/null; then + _LT_TAGVAR(ld_shlibs, $1)=no + cat <<_LT_EOF 1>&2 + +*** Warning: The releases 2.8.* of the GNU linker cannot reliably +*** create shared libraries on Solaris systems. Therefore, libtool +*** is disabling shared libraries support. We urge you to upgrade GNU +*** binutils to release 2.9.1 or newer. Another option is to modify +*** your PATH or compiler configuration so that the native linker is +*** used, and then restart. + +_LT_EOF + elif $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX*) + case `$LD -v 2>&1` in + *\ [[01]].* | *\ 2.[[0-9]].* | *\ 2.1[[0-5]].*) + _LT_TAGVAR(ld_shlibs, $1)=no + cat <<_LT_EOF 1>&2 + +*** Warning: Releases of the GNU linker prior to 2.16.91.0.3 can not +*** reliably create shared libraries on SCO systems. Therefore, libtool +*** is disabling shared libraries support. We urge you to upgrade GNU +*** binutils to release 2.16.91.0.3 or newer. Another option is to modify +*** your PATH or compiler configuration so that the native linker is +*** used, and then restart. + +_LT_EOF + ;; + *) + # For security reasons, it is highly recommended that you always + # use absolute paths for naming shared libraries, and exclude the + # DT_RUNPATH tag from executables and libraries. But doing so + # requires that you compile everything twice, which is a pain. + if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + esac + ;; + + sunos4*) + _LT_TAGVAR(archive_cmds, $1)='$LD -assert pure-text -Bshareable -o $lib $libobjs $deplibs $linker_flags' + wlarc= + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + *) + if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + esac + + if test "$_LT_TAGVAR(ld_shlibs, $1)" = no; then + runpath_var= + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)= + _LT_TAGVAR(export_dynamic_flag_spec, $1)= + _LT_TAGVAR(whole_archive_flag_spec, $1)= + fi + else + # PORTME fill in a description of your system's linker (not GNU ld) + case $host_os in + aix3*) + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + _LT_TAGVAR(always_export_symbols, $1)=yes + _LT_TAGVAR(archive_expsym_cmds, $1)='$LD -o $output_objdir/$soname $libobjs $deplibs $linker_flags -bE:$export_symbols -T512 -H512 -bM:SRE~$AR $AR_FLAGS $lib $output_objdir/$soname' + # Note: this linker hardcodes the directories in LIBPATH if there + # are no directories specified by -L. + _LT_TAGVAR(hardcode_minus_L, $1)=yes + if test "$GCC" = yes && test -z "$lt_prog_compiler_static"; then + # Neither direct hardcoding nor static linking is supported with a + # broken collect2. + _LT_TAGVAR(hardcode_direct, $1)=unsupported + fi + ;; + + aix[[4-9]]*) + if test "$host_cpu" = ia64; then + # On IA64, the linker does run time linking by default, so we don't + # have to do anything special. + aix_use_runtimelinking=no + exp_sym_flag='-Bexport' + no_entry_flag="" + else + # If we're using GNU nm, then we don't want the "-C" option. + # -C means demangle to AIX nm, but means don't demangle with GNU nm + if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then + _LT_TAGVAR(export_symbols_cmds, $1)='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && ([substr](\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols' + else + _LT_TAGVAR(export_symbols_cmds, $1)='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && ([substr](\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols' + fi + aix_use_runtimelinking=no + + # Test if we are trying to use run time linking or normal + # AIX style linking. If -brtl is somewhere in LDFLAGS, we + # need to do runtime linking. + case $host_os in aix4.[[23]]|aix4.[[23]].*|aix[[5-9]]*) + for ld_flag in $LDFLAGS; do + if (test $ld_flag = "-brtl" || test $ld_flag = "-Wl,-brtl"); then + aix_use_runtimelinking=yes + break + fi + done + ;; + esac + + exp_sym_flag='-bexport' + no_entry_flag='-bnoentry' + fi + + # When large executables or shared objects are built, AIX ld can + # have problems creating the table of contents. If linking a library + # or program results in "error TOC overflow" add -mminimal-toc to + # CXXFLAGS/CFLAGS for g++/gcc. In the cases where that is not + # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS. + + _LT_TAGVAR(archive_cmds, $1)='' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_direct_absolute, $1)=yes + _LT_TAGVAR(hardcode_libdir_separator, $1)=':' + _LT_TAGVAR(link_all_deplibs, $1)=yes + _LT_TAGVAR(file_list_spec, $1)='${wl}-f,' + + if test "$GCC" = yes; then + case $host_os in aix4.[[012]]|aix4.[[012]].*) + # We only want to do this on AIX 4.2 and lower, the check + # below for broken collect2 doesn't work under 4.3+ + collect2name=`${CC} -print-prog-name=collect2` + if test -f "$collect2name" && + strings "$collect2name" | $GREP resolve_lib_name >/dev/null + then + # We have reworked collect2 + : + else + # We have old collect2 + _LT_TAGVAR(hardcode_direct, $1)=unsupported + # It fails to find uninstalled libraries when the uninstalled + # path is not listed in the libpath. Setting hardcode_minus_L + # to unsupported forces relinking + _LT_TAGVAR(hardcode_minus_L, $1)=yes + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)= + fi + ;; + esac + shared_flag='-shared' + if test "$aix_use_runtimelinking" = yes; then + shared_flag="$shared_flag "'${wl}-G' + fi + else + # not using gcc + if test "$host_cpu" = ia64; then + # VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release + # chokes on -Wl,-G. The following line is correct: + shared_flag='-G' + else + if test "$aix_use_runtimelinking" = yes; then + shared_flag='${wl}-G' + else + shared_flag='${wl}-bM:SRE' + fi + fi + fi + + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-bexpall' + # It seems that -bexpall does not export symbols beginning with + # underscore (_), so it is better to generate a list of symbols to export. + _LT_TAGVAR(always_export_symbols, $1)=yes + if test "$aix_use_runtimelinking" = yes; then + # Warning - without using the other runtime loading flags (-brtl), + # -berok will link without error, but may produce a broken library. + _LT_TAGVAR(allow_undefined_flag, $1)='-berok' + # Determine the default libpath from the value encoded in an + # empty executable. + _LT_SYS_MODULE_PATH_AIX + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath" + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags `if test "x${allow_undefined_flag}" != "x"; then $ECHO "X${wl}${allow_undefined_flag}" | $Xsed; else :; fi` '"\${wl}$exp_sym_flag:\$export_symbols $shared_flag" + else + if test "$host_cpu" = ia64; then + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R $libdir:/usr/lib:/lib' + _LT_TAGVAR(allow_undefined_flag, $1)="-z nodefs" + _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags ${wl}${allow_undefined_flag} '"\${wl}$exp_sym_flag:\$export_symbols" + else + # Determine the default libpath from the value encoded in an + # empty executable. + _LT_SYS_MODULE_PATH_AIX + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath" + # Warning - without using the other run time loading flags, + # -berok will link without error, but may produce a broken library. + _LT_TAGVAR(no_undefined_flag, $1)=' ${wl}-bernotok' + _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-berok' + # Exported symbols can be pulled into shared objects from archives + _LT_TAGVAR(whole_archive_flag_spec, $1)='$convenience' + _LT_TAGVAR(archive_cmds_need_lc, $1)=yes + # This is similar to how AIX traditionally builds its shared libraries. + _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs ${wl}-bnoentry $compiler_flags ${wl}-bE:$export_symbols${allow_undefined_flag}~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$soname' + fi + fi + ;; + + amigaos*) + case $host_cpu in + powerpc) + # see comment about AmigaOS4 .so support + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='' + ;; + m68k) + _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_minus_L, $1)=yes + ;; + esac + ;; + + bsdi[[45]]*) + _LT_TAGVAR(export_dynamic_flag_spec, $1)=-rdynamic + ;; + + cygwin* | mingw* | pw32* | cegcc*) + # When not using gcc, we currently assume that we are using + # Microsoft Visual C++. + # hardcode_libdir_flag_spec is actually meaningless, as there is + # no search path for DLLs. + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)=' ' + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + # Tell ltmain to make .lib files, not .a files. + libext=lib + # Tell ltmain to make .dll files, not .so files. + shrext_cmds=".dll" + # FIXME: Setting linknames here is a bad hack. + _LT_TAGVAR(archive_cmds, $1)='$CC -o $lib $libobjs $compiler_flags `$ECHO "X$deplibs" | $Xsed -e '\''s/ -lc$//'\''` -link -dll~linknames=' + # The linker will automatically build a .lib file if we build a DLL. + _LT_TAGVAR(old_archive_from_new_cmds, $1)='true' + # FIXME: Should let the user specify the lib program. + _LT_TAGVAR(old_archive_cmds, $1)='lib -OUT:$oldlib$oldobjs$old_deplibs' + _LT_TAGVAR(fix_srcfile_path, $1)='`cygpath -w "$srcfile"`' + _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes + ;; + + darwin* | rhapsody*) + _LT_DARWIN_LINKER_FEATURES($1) + ;; + + dgux*) + _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + freebsd1*) + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + + # FreeBSD 2.2.[012] allows us to include c++rt0.o to get C++ constructor + # support. Future versions do this automatically, but an explicit c++rt0.o + # does not break anything, and helps significantly (at the cost of a little + # extra space). + freebsd2.2*) + _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags /usr/lib/c++rt0.o' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + # Unfortunately, older versions of FreeBSD 2 do not have this feature. + freebsd2*) + _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_minus_L, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + # FreeBSD 3 and greater uses gcc -shared to do shared libraries. + freebsd* | dragonfly*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + hpux9*) + if test "$GCC" = yes; then + _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$CC -shared -fPIC ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $libobjs $deplibs $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib' + else + _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$LD -b +b $install_libdir -o $output_objdir/$soname $libobjs $deplibs $linker_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib' + fi + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + _LT_TAGVAR(hardcode_direct, $1)=yes + + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + _LT_TAGVAR(hardcode_minus_L, $1)=yes + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' + ;; + + hpux10*) + if test "$GCC" = yes -a "$with_gnu_ld" = no; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags' + else + _LT_TAGVAR(archive_cmds, $1)='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags' + fi + if test "$with_gnu_ld" = no; then + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir' + _LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)='+b $libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_direct_absolute, $1)=yes + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + _LT_TAGVAR(hardcode_minus_L, $1)=yes + fi + ;; + + hpux11*) + if test "$GCC" = yes -a "$with_gnu_ld" = no; then + case $host_cpu in + hppa*64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + ia64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags' + ;; + *) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + else + case $host_cpu in + hppa*64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + ia64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags' + ;; + *) + _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + fi + if test "$with_gnu_ld" = no; then + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + + case $host_cpu in + hppa*64*|ia64*) + _LT_TAGVAR(hardcode_direct, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + *) + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_direct_absolute, $1)=yes + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' + + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + _LT_TAGVAR(hardcode_minus_L, $1)=yes + ;; + esac + fi + ;; + + irix5* | irix6* | nonstopux*) + if test "$GCC" = yes; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' + # Try to use the -exported_symbol ld option, if it does not + # work, assume that -exports_file does not work either and + # implicitly export all symbols. + save_LDFLAGS="$LDFLAGS" + LDFLAGS="$LDFLAGS -shared ${wl}-exported_symbol ${wl}foo ${wl}-update_registry ${wl}/dev/null" + AC_LINK_IFELSE(int foo(void) {}, + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations ${wl}-exports_file ${wl}$export_symbols -o $lib' + ) + LDFLAGS="$save_LDFLAGS" + else + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -exports_file $export_symbols -o $lib' + fi + _LT_TAGVAR(archive_cmds_need_lc, $1)='no' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + _LT_TAGVAR(inherit_rpath, $1)=yes + _LT_TAGVAR(link_all_deplibs, $1)=yes + ;; + + netbsd*) + if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' # a.out + else + _LT_TAGVAR(archive_cmds, $1)='$LD -shared -o $lib $libobjs $deplibs $linker_flags' # ELF + fi + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + newsos6) + _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + *nto* | *qnx*) + ;; + + openbsd*) + if test -f /usr/libexec/ld.so; then + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_TAGVAR(hardcode_direct_absolute, $1)=yes + if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-retain-symbols-file,$export_symbols' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' + else + case $host_os in + openbsd[[01]].* | openbsd2.[[0-7]] | openbsd2.[[0-7]].*) + _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + ;; + *) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' + ;; + esac + fi + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + os2*) + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_minus_L, $1)=yes + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + _LT_TAGVAR(archive_cmds, $1)='$ECHO "LIBRARY $libname INITINSTANCE" > $output_objdir/$libname.def~$ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~$ECHO DATA >> $output_objdir/$libname.def~$ECHO " SINGLE NONSHARED" >> $output_objdir/$libname.def~$ECHO EXPORTS >> $output_objdir/$libname.def~emxexp $libobjs >> $output_objdir/$libname.def~$CC -Zdll -Zcrtdll -o $lib $libobjs $deplibs $compiler_flags $output_objdir/$libname.def' + _LT_TAGVAR(old_archive_from_new_cmds, $1)='emximp -o $output_objdir/$libname.a $output_objdir/$libname.def' + ;; + + osf3*) + if test "$GCC" = yes; then + _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' + else + _LT_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib' + fi + _LT_TAGVAR(archive_cmds_need_lc, $1)='no' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + ;; + + osf4* | osf5*) # as osf3* with the addition of -msym flag + if test "$GCC" = yes; then + _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-msym ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + else + _LT_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags -msym -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done; printf "%s\\n" "-hidden">> $lib.exp~ + $CC -shared${allow_undefined_flag} ${wl}-input ${wl}$lib.exp $compiler_flags $libobjs $deplibs -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib~$RM $lib.exp' + + # Both c and cxx compiler support -rpath directly + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir' + fi + _LT_TAGVAR(archive_cmds_need_lc, $1)='no' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + ;; + + solaris*) + _LT_TAGVAR(no_undefined_flag, $1)=' -z defs' + if test "$GCC" = yes; then + wlarc='${wl}' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-z ${wl}text ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $CC -shared ${wl}-z ${wl}text ${wl}-M ${wl}$lib.exp ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp' + else + case `$CC -V 2>&1` in + *"Compilers 5.0"*) + wlarc='' + _LT_TAGVAR(archive_cmds, $1)='$LD -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $LD -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $linker_flags~$RM $lib.exp' + ;; + *) + wlarc='${wl}' + _LT_TAGVAR(archive_cmds, $1)='$CC -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $CC -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp' + ;; + esac + fi + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + case $host_os in + solaris2.[[0-5]] | solaris2.[[0-5]].*) ;; + *) + # The compiler driver will combine and reorder linker options, + # but understands `-z linker_flag'. GCC discards it without `$wl', + # but is careful enough not to reorder. + # Supported since Solaris 2.6 (maybe 2.5.1?) + if test "$GCC" = yes; then + _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}-z ${wl}allextract$convenience ${wl}-z ${wl}defaultextract' + else + _LT_TAGVAR(whole_archive_flag_spec, $1)='-z allextract$convenience -z defaultextract' + fi + ;; + esac + _LT_TAGVAR(link_all_deplibs, $1)=yes + ;; + + sunos4*) + if test "x$host_vendor" = xsequent; then + # Use $CC to link under sequent, because it throws in some extra .o + # files that make .init and .fini sections work. + _LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h $soname -o $lib $libobjs $deplibs $compiler_flags' + else + _LT_TAGVAR(archive_cmds, $1)='$LD -assert pure-text -Bstatic -o $lib $libobjs $deplibs $linker_flags' + fi + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_minus_L, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + sysv4) + case $host_vendor in + sni) + _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_direct, $1)=yes # is this really true??? + ;; + siemens) + ## LD is ld it makes a PLAMLIB + ## CC just makes a GrossModule. + _LT_TAGVAR(archive_cmds, $1)='$LD -G -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(reload_cmds, $1)='$CC -r -o $output$reload_objs' + _LT_TAGVAR(hardcode_direct, $1)=no + ;; + motorola) + _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_direct, $1)=no #Motorola manual says yes, but my tests say they lie + ;; + esac + runpath_var='LD_RUN_PATH' + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + sysv4.3*) + _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_TAGVAR(export_dynamic_flag_spec, $1)='-Bexport' + ;; + + sysv4*MP*) + if test -d /usr/nec; then + _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + runpath_var=LD_RUN_PATH + hardcode_runpath_var=yes + _LT_TAGVAR(ld_shlibs, $1)=yes + fi + ;; + + sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[[01]].[[10]]* | unixware7* | sco3.2v5.0.[[024]]*) + _LT_TAGVAR(no_undefined_flag, $1)='${wl}-z,text' + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + runpath_var='LD_RUN_PATH' + + if test "$GCC" = yes; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + else + _LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + fi + ;; + + sysv5* | sco3.2v5* | sco5v6*) + # Note: We can NOT use -z defs as we might desire, because we do not + # link with -lc, and that would cause any symbols used from libc to + # always be unresolved, which means just about no library would + # ever link correctly. If we're not using GNU ld we use -z text + # though, which does catch some bad symbols but isn't as heavy-handed + # as -z defs. + _LT_TAGVAR(no_undefined_flag, $1)='${wl}-z,text' + _LT_TAGVAR(allow_undefined_flag, $1)='${wl}-z,nodefs' + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R,$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=':' + _LT_TAGVAR(link_all_deplibs, $1)=yes + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-Bexport' + runpath_var='LD_RUN_PATH' + + if test "$GCC" = yes; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + else + _LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + fi + ;; + + uts4*) + _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + *) + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + esac + + if test x$host_vendor = xsni; then + case $host in + sysv4 | sysv4.2uw2* | sysv4.3* | sysv5*) + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-Blargedynsym' + ;; + esac + fi + fi +]) +AC_MSG_RESULT([$_LT_TAGVAR(ld_shlibs, $1)]) +test "$_LT_TAGVAR(ld_shlibs, $1)" = no && can_build_shared=no + +_LT_TAGVAR(with_gnu_ld, $1)=$with_gnu_ld + +_LT_DECL([], [libext], [0], [Old archive suffix (normally "a")])dnl +_LT_DECL([], [shrext_cmds], [1], [Shared library suffix (normally ".so")])dnl +_LT_DECL([], [extract_expsyms_cmds], [2], + [The commands to extract the exported symbol list from a shared archive]) + +# +# Do we need to explicitly link libc? +# +case "x$_LT_TAGVAR(archive_cmds_need_lc, $1)" in +x|xyes) + # Assume -lc should be added + _LT_TAGVAR(archive_cmds_need_lc, $1)=yes + + if test "$enable_shared" = yes && test "$GCC" = yes; then + case $_LT_TAGVAR(archive_cmds, $1) in + *'~'*) + # FIXME: we may have to deal with multi-command sequences. + ;; + '$CC '*) + # Test whether the compiler implicitly links with -lc since on some + # systems, -lgcc has to come before -lc. If gcc already passes -lc + # to ld, don't add -lc before -lgcc. + AC_MSG_CHECKING([whether -lc should be explicitly linked in]) + $RM conftest* + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + + if AC_TRY_EVAL(ac_compile) 2>conftest.err; then + soname=conftest + lib=conftest + libobjs=conftest.$ac_objext + deplibs= + wl=$_LT_TAGVAR(lt_prog_compiler_wl, $1) + pic_flag=$_LT_TAGVAR(lt_prog_compiler_pic, $1) + compiler_flags=-v + linker_flags=-v + verstring= + output_objdir=. + libname=conftest + lt_save_allow_undefined_flag=$_LT_TAGVAR(allow_undefined_flag, $1) + _LT_TAGVAR(allow_undefined_flag, $1)= + if AC_TRY_EVAL(_LT_TAGVAR(archive_cmds, $1) 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1) + then + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + else + _LT_TAGVAR(archive_cmds_need_lc, $1)=yes + fi + _LT_TAGVAR(allow_undefined_flag, $1)=$lt_save_allow_undefined_flag + else + cat conftest.err 1>&5 + fi + $RM conftest* + AC_MSG_RESULT([$_LT_TAGVAR(archive_cmds_need_lc, $1)]) + ;; + esac + fi + ;; +esac + +_LT_TAGDECL([build_libtool_need_lc], [archive_cmds_need_lc], [0], + [Whether or not to add -lc for building shared libraries]) +_LT_TAGDECL([allow_libtool_libs_with_static_runtimes], + [enable_shared_with_static_runtimes], [0], + [Whether or not to disallow shared libs when runtime libs are static]) +_LT_TAGDECL([], [export_dynamic_flag_spec], [1], + [Compiler flag to allow reflexive dlopens]) +_LT_TAGDECL([], [whole_archive_flag_spec], [1], + [Compiler flag to generate shared objects directly from archives]) +_LT_TAGDECL([], [compiler_needs_object], [1], + [Whether the compiler copes with passing no objects directly]) +_LT_TAGDECL([], [old_archive_from_new_cmds], [2], + [Create an old-style archive from a shared archive]) +_LT_TAGDECL([], [old_archive_from_expsyms_cmds], [2], + [Create a temporary old-style archive to link instead of a shared archive]) +_LT_TAGDECL([], [archive_cmds], [2], [Commands used to build a shared archive]) +_LT_TAGDECL([], [archive_expsym_cmds], [2]) +_LT_TAGDECL([], [module_cmds], [2], + [Commands used to build a loadable module if different from building + a shared archive.]) +_LT_TAGDECL([], [module_expsym_cmds], [2]) +_LT_TAGDECL([], [with_gnu_ld], [1], + [Whether we are building with GNU ld or not]) +_LT_TAGDECL([], [allow_undefined_flag], [1], + [Flag that allows shared libraries with undefined symbols to be built]) +_LT_TAGDECL([], [no_undefined_flag], [1], + [Flag that enforces no undefined symbols]) +_LT_TAGDECL([], [hardcode_libdir_flag_spec], [1], + [Flag to hardcode $libdir into a binary during linking. + This must work even if $libdir does not exist]) +_LT_TAGDECL([], [hardcode_libdir_flag_spec_ld], [1], + [[If ld is used when linking, flag to hardcode $libdir into a binary + during linking. This must work even if $libdir does not exist]]) +_LT_TAGDECL([], [hardcode_libdir_separator], [1], + [Whether we need a single "-rpath" flag with a separated argument]) +_LT_TAGDECL([], [hardcode_direct], [0], + [Set to "yes" if using DIR/libNAME${shared_ext} during linking hardcodes + DIR into the resulting binary]) +_LT_TAGDECL([], [hardcode_direct_absolute], [0], + [Set to "yes" if using DIR/libNAME${shared_ext} during linking hardcodes + DIR into the resulting binary and the resulting library dependency is + "absolute", i.e impossible to change by setting ${shlibpath_var} if the + library is relocated]) +_LT_TAGDECL([], [hardcode_minus_L], [0], + [Set to "yes" if using the -LDIR flag during linking hardcodes DIR + into the resulting binary]) +_LT_TAGDECL([], [hardcode_shlibpath_var], [0], + [Set to "yes" if using SHLIBPATH_VAR=DIR during linking hardcodes DIR + into the resulting binary]) +_LT_TAGDECL([], [hardcode_automatic], [0], + [Set to "yes" if building a shared library automatically hardcodes DIR + into the library and all subsequent libraries and executables linked + against it]) +_LT_TAGDECL([], [inherit_rpath], [0], + [Set to yes if linker adds runtime paths of dependent libraries + to runtime path list]) +_LT_TAGDECL([], [link_all_deplibs], [0], + [Whether libtool must link a program against all its dependency libraries]) +_LT_TAGDECL([], [fix_srcfile_path], [1], + [Fix the shell variable $srcfile for the compiler]) +_LT_TAGDECL([], [always_export_symbols], [0], + [Set to "yes" if exported symbols are required]) +_LT_TAGDECL([], [export_symbols_cmds], [2], + [The commands to list exported symbols]) +_LT_TAGDECL([], [exclude_expsyms], [1], + [Symbols that should not be listed in the preloaded symbols]) +_LT_TAGDECL([], [include_expsyms], [1], + [Symbols that must always be exported]) +_LT_TAGDECL([], [prelink_cmds], [2], + [Commands necessary for linking programs (against libraries) with templates]) +_LT_TAGDECL([], [file_list_spec], [1], + [Specify filename containing input files]) +dnl FIXME: Not yet implemented +dnl _LT_TAGDECL([], [thread_safe_flag_spec], [1], +dnl [Compiler flag to generate thread safe objects]) +])# _LT_LINKER_SHLIBS + + +# _LT_LANG_C_CONFIG([TAG]) +# ------------------------ +# Ensure that the configuration variables for a C compiler are suitably +# defined. These variables are subsequently used by _LT_CONFIG to write +# the compiler configuration to `libtool'. +m4_defun([_LT_LANG_C_CONFIG], +[m4_require([_LT_DECL_EGREP])dnl +lt_save_CC="$CC" +AC_LANG_PUSH(C) + +# Source file extension for C test sources. +ac_ext=c + +# Object file extension for compiled C test sources. +objext=o +_LT_TAGVAR(objext, $1)=$objext + +# Code to be used in simple compile tests +lt_simple_compile_test_code="int some_variable = 0;" + +# Code to be used in simple link tests +lt_simple_link_test_code='int main(){return(0);}' + +_LT_TAG_COMPILER +# Save the default compiler, since it gets overwritten when the other +# tags are being tested, and _LT_TAGVAR(compiler, []) is a NOP. +compiler_DEFAULT=$CC + +# save warnings/boilerplate of simple test code +_LT_COMPILER_BOILERPLATE +_LT_LINKER_BOILERPLATE + +if test -n "$compiler"; then + _LT_COMPILER_NO_RTTI($1) + _LT_COMPILER_PIC($1) + _LT_COMPILER_C_O($1) + _LT_COMPILER_FILE_LOCKS($1) + _LT_LINKER_SHLIBS($1) + _LT_SYS_DYNAMIC_LINKER($1) + _LT_LINKER_HARDCODE_LIBPATH($1) + LT_SYS_DLOPEN_SELF + _LT_CMD_STRIPLIB + + # Report which library types will actually be built + AC_MSG_CHECKING([if libtool supports shared libraries]) + AC_MSG_RESULT([$can_build_shared]) + + AC_MSG_CHECKING([whether to build shared libraries]) + test "$can_build_shared" = "no" && enable_shared=no + + # On AIX, shared libraries and static libraries use the same namespace, and + # are all built from PIC. + case $host_os in + aix3*) + test "$enable_shared" = yes && enable_static=no + if test -n "$RANLIB"; then + archive_cmds="$archive_cmds~\$RANLIB \$lib" + postinstall_cmds='$RANLIB $lib' + fi + ;; + + aix[[4-9]]*) + if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then + test "$enable_shared" = yes && enable_static=no + fi + ;; + esac + AC_MSG_RESULT([$enable_shared]) + + AC_MSG_CHECKING([whether to build static libraries]) + # Make sure either enable_shared or enable_static is yes. + test "$enable_shared" = yes || enable_static=yes + AC_MSG_RESULT([$enable_static]) + + _LT_CONFIG($1) +fi +AC_LANG_POP +CC="$lt_save_CC" +])# _LT_LANG_C_CONFIG + + +# _LT_PROG_CXX +# ------------ +# Since AC_PROG_CXX is broken, in that it returns g++ if there is no c++ +# compiler, we have our own version here. +m4_defun([_LT_PROG_CXX], +[ +pushdef([AC_MSG_ERROR], [_lt_caught_CXX_error=yes]) +AC_PROG_CXX +if test -n "$CXX" && ( test "X$CXX" != "Xno" && + ( (test "X$CXX" = "Xg++" && `g++ -v >/dev/null 2>&1` ) || + (test "X$CXX" != "Xg++"))) ; then + AC_PROG_CXXCPP +else + _lt_caught_CXX_error=yes +fi +popdef([AC_MSG_ERROR]) +])# _LT_PROG_CXX + +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([_LT_PROG_CXX], []) + + +# _LT_LANG_CXX_CONFIG([TAG]) +# -------------------------- +# Ensure that the configuration variables for a C++ compiler are suitably +# defined. These variables are subsequently used by _LT_CONFIG to write +# the compiler configuration to `libtool'. +m4_defun([_LT_LANG_CXX_CONFIG], +[AC_REQUIRE([_LT_PROG_CXX])dnl +m4_require([_LT_FILEUTILS_DEFAULTS])dnl +m4_require([_LT_DECL_EGREP])dnl + +AC_LANG_PUSH(C++) +_LT_TAGVAR(archive_cmds_need_lc, $1)=no +_LT_TAGVAR(allow_undefined_flag, $1)= +_LT_TAGVAR(always_export_symbols, $1)=no +_LT_TAGVAR(archive_expsym_cmds, $1)= +_LT_TAGVAR(compiler_needs_object, $1)=no +_LT_TAGVAR(export_dynamic_flag_spec, $1)= +_LT_TAGVAR(hardcode_direct, $1)=no +_LT_TAGVAR(hardcode_direct_absolute, $1)=no +_LT_TAGVAR(hardcode_libdir_flag_spec, $1)= +_LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)= +_LT_TAGVAR(hardcode_libdir_separator, $1)= +_LT_TAGVAR(hardcode_minus_L, $1)=no +_LT_TAGVAR(hardcode_shlibpath_var, $1)=unsupported +_LT_TAGVAR(hardcode_automatic, $1)=no +_LT_TAGVAR(inherit_rpath, $1)=no +_LT_TAGVAR(module_cmds, $1)= +_LT_TAGVAR(module_expsym_cmds, $1)= +_LT_TAGVAR(link_all_deplibs, $1)=unknown +_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds +_LT_TAGVAR(no_undefined_flag, $1)= +_LT_TAGVAR(whole_archive_flag_spec, $1)= +_LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no + +# Source file extension for C++ test sources. +ac_ext=cpp + +# Object file extension for compiled C++ test sources. +objext=o +_LT_TAGVAR(objext, $1)=$objext + +# No sense in running all these tests if we already determined that +# the CXX compiler isn't working. Some variables (like enable_shared) +# are currently assumed to apply to all compilers on this platform, +# and will be corrupted by setting them based on a non-working compiler. +if test "$_lt_caught_CXX_error" != yes; then + # Code to be used in simple compile tests + lt_simple_compile_test_code="int some_variable = 0;" + + # Code to be used in simple link tests + lt_simple_link_test_code='int main(int, char *[[]]) { return(0); }' + + # ltmain only uses $CC for tagged configurations so make sure $CC is set. + _LT_TAG_COMPILER + + # save warnings/boilerplate of simple test code + _LT_COMPILER_BOILERPLATE + _LT_LINKER_BOILERPLATE + + # Allow CC to be a program name with arguments. + lt_save_CC=$CC + lt_save_LD=$LD + lt_save_GCC=$GCC + GCC=$GXX + lt_save_with_gnu_ld=$with_gnu_ld + lt_save_path_LD=$lt_cv_path_LD + if test -n "${lt_cv_prog_gnu_ldcxx+set}"; then + lt_cv_prog_gnu_ld=$lt_cv_prog_gnu_ldcxx + else + $as_unset lt_cv_prog_gnu_ld + fi + if test -n "${lt_cv_path_LDCXX+set}"; then + lt_cv_path_LD=$lt_cv_path_LDCXX + else + $as_unset lt_cv_path_LD + fi + test -z "${LDCXX+set}" || LD=$LDCXX + CC=${CXX-"c++"} + compiler=$CC + _LT_TAGVAR(compiler, $1)=$CC + _LT_CC_BASENAME([$compiler]) + + if test -n "$compiler"; then + # We don't want -fno-exception when compiling C++ code, so set the + # no_builtin_flag separately + if test "$GXX" = yes; then + _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=' -fno-builtin' + else + _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)= + fi + + if test "$GXX" = yes; then + # Set up default GNU C++ configuration + + LT_PATH_LD + + # Check if GNU C++ uses GNU ld as the underlying linker, since the + # archiving commands below assume that GNU ld is being used. + if test "$with_gnu_ld" = yes; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic' + + # If archive_cmds runs LD, not CC, wlarc should be empty + # XXX I think wlarc can be eliminated in ltcf-cxx, but I need to + # investigate it a little bit more. (MM) + wlarc='${wl}' + + # ancient GNU ld didn't support --whole-archive et. al. + if eval "`$CC -print-prog-name=ld` --help 2>&1" | + $GREP 'no-whole-archive' > /dev/null; then + _LT_TAGVAR(whole_archive_flag_spec, $1)="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive' + else + _LT_TAGVAR(whole_archive_flag_spec, $1)= + fi + else + with_gnu_ld=no + wlarc= + + # A generic and very simple default shared library creation + # command for GNU C++ for the case where it uses the native + # linker, instead of GNU ld. If possible, this setting should + # overridden to take advantage of the native linker features on + # the platform it is being used on. + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $lib' + fi + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "\-L"' + + else + GXX=no + with_gnu_ld=no + wlarc= + fi + + # PORTME: fill in a description of your system's C++ link characteristics + AC_MSG_CHECKING([whether the $compiler linker ($LD) supports shared libraries]) + _LT_TAGVAR(ld_shlibs, $1)=yes + case $host_os in + aix3*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + aix[[4-9]]*) + if test "$host_cpu" = ia64; then + # On IA64, the linker does run time linking by default, so we don't + # have to do anything special. + aix_use_runtimelinking=no + exp_sym_flag='-Bexport' + no_entry_flag="" + else + aix_use_runtimelinking=no + + # Test if we are trying to use run time linking or normal + # AIX style linking. If -brtl is somewhere in LDFLAGS, we + # need to do runtime linking. + case $host_os in aix4.[[23]]|aix4.[[23]].*|aix[[5-9]]*) + for ld_flag in $LDFLAGS; do + case $ld_flag in + *-brtl*) + aix_use_runtimelinking=yes + break + ;; + esac + done + ;; + esac + + exp_sym_flag='-bexport' + no_entry_flag='-bnoentry' + fi + + # When large executables or shared objects are built, AIX ld can + # have problems creating the table of contents. If linking a library + # or program results in "error TOC overflow" add -mminimal-toc to + # CXXFLAGS/CFLAGS for g++/gcc. In the cases where that is not + # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS. + + _LT_TAGVAR(archive_cmds, $1)='' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_direct_absolute, $1)=yes + _LT_TAGVAR(hardcode_libdir_separator, $1)=':' + _LT_TAGVAR(link_all_deplibs, $1)=yes + _LT_TAGVAR(file_list_spec, $1)='${wl}-f,' + + if test "$GXX" = yes; then + case $host_os in aix4.[[012]]|aix4.[[012]].*) + # We only want to do this on AIX 4.2 and lower, the check + # below for broken collect2 doesn't work under 4.3+ + collect2name=`${CC} -print-prog-name=collect2` + if test -f "$collect2name" && + strings "$collect2name" | $GREP resolve_lib_name >/dev/null + then + # We have reworked collect2 + : + else + # We have old collect2 + _LT_TAGVAR(hardcode_direct, $1)=unsupported + # It fails to find uninstalled libraries when the uninstalled + # path is not listed in the libpath. Setting hardcode_minus_L + # to unsupported forces relinking + _LT_TAGVAR(hardcode_minus_L, $1)=yes + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)= + fi + esac + shared_flag='-shared' + if test "$aix_use_runtimelinking" = yes; then + shared_flag="$shared_flag "'${wl}-G' + fi + else + # not using gcc + if test "$host_cpu" = ia64; then + # VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release + # chokes on -Wl,-G. The following line is correct: + shared_flag='-G' + else + if test "$aix_use_runtimelinking" = yes; then + shared_flag='${wl}-G' + else + shared_flag='${wl}-bM:SRE' + fi + fi + fi + + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-bexpall' + # It seems that -bexpall does not export symbols beginning with + # underscore (_), so it is better to generate a list of symbols to + # export. + _LT_TAGVAR(always_export_symbols, $1)=yes + if test "$aix_use_runtimelinking" = yes; then + # Warning - without using the other runtime loading flags (-brtl), + # -berok will link without error, but may produce a broken library. + _LT_TAGVAR(allow_undefined_flag, $1)='-berok' + # Determine the default libpath from the value encoded in an empty + # executable. + _LT_SYS_MODULE_PATH_AIX + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath" + + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags `if test "x${allow_undefined_flag}" != "x"; then $ECHO "X${wl}${allow_undefined_flag}" | $Xsed; else :; fi` '"\${wl}$exp_sym_flag:\$export_symbols $shared_flag" + else + if test "$host_cpu" = ia64; then + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R $libdir:/usr/lib:/lib' + _LT_TAGVAR(allow_undefined_flag, $1)="-z nodefs" + _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags ${wl}${allow_undefined_flag} '"\${wl}$exp_sym_flag:\$export_symbols" + else + # Determine the default libpath from the value encoded in an + # empty executable. + _LT_SYS_MODULE_PATH_AIX + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath" + # Warning - without using the other run time loading flags, + # -berok will link without error, but may produce a broken library. + _LT_TAGVAR(no_undefined_flag, $1)=' ${wl}-bernotok' + _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-berok' + # Exported symbols can be pulled into shared objects from archives + _LT_TAGVAR(whole_archive_flag_spec, $1)='$convenience' + _LT_TAGVAR(archive_cmds_need_lc, $1)=yes + # This is similar to how AIX traditionally builds its shared + # libraries. + _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs ${wl}-bnoentry $compiler_flags ${wl}-bE:$export_symbols${allow_undefined_flag}~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$soname' + fi + fi + ;; + + beos*) + if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + # Joseph Beckenbach says some releases of gcc + # support --undefined. This deserves some investigation. FIXME + _LT_TAGVAR(archive_cmds, $1)='$CC -nostart $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + chorus*) + case $cc_basename in + *) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + esac + ;; + + cygwin* | mingw* | pw32* | cegcc*) + # _LT_TAGVAR(hardcode_libdir_flag_spec, $1) is actually meaningless, + # as there is no search path for DLLs. + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + _LT_TAGVAR(always_export_symbols, $1)=no + _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes + + if $LD --help 2>&1 | $GREP 'auto-import' > /dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + # If the export-symbols file already is a .def file (1st line + # is EXPORTS), use it as is; otherwise, prepend... + _LT_TAGVAR(archive_expsym_cmds, $1)='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then + cp $export_symbols $output_objdir/$soname.def; + else + echo EXPORTS > $output_objdir/$soname.def; + cat $export_symbols >> $output_objdir/$soname.def; + fi~ + $CC -shared -nostdlib $output_objdir/$soname.def $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + darwin* | rhapsody*) + _LT_DARWIN_LINKER_FEATURES($1) + ;; + + dgux*) + case $cc_basename in + ec++*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + ghcx*) + # Green Hills C++ Compiler + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + *) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + esac + ;; + + freebsd[[12]]*) + # C++ shared libraries reported to be fairly broken before + # switch to ELF + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + + freebsd-elf*) + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + ;; + + freebsd* | dragonfly*) + # FreeBSD 3 and later use GNU C++ and GNU ld with standard ELF + # conventions + _LT_TAGVAR(ld_shlibs, $1)=yes + ;; + + gnu*) + ;; + + hpux9*) + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_minus_L, $1)=yes # Not in the search PATH, + # but as the default + # location of the library. + + case $cc_basename in + CC*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + aCC*) + _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$CC -b ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib' + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $EGREP "\-L"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; $ECHO "X$list" | $Xsed' + ;; + *) + if test "$GXX" = yes; then + _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$CC -shared -nostdlib -fPIC ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib' + else + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + esac + ;; + + hpux10*|hpux11*) + if test $with_gnu_ld = no; then + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + + case $host_cpu in + hppa*64*|ia64*) + ;; + *) + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' + ;; + esac + fi + case $host_cpu in + hppa*64*|ia64*) + _LT_TAGVAR(hardcode_direct, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + *) + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_direct_absolute, $1)=yes + _LT_TAGVAR(hardcode_minus_L, $1)=yes # Not in the search PATH, + # but as the default + # location of the library. + ;; + esac + + case $cc_basename in + CC*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + aCC*) + case $host_cpu in + hppa*64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + ia64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + *) + _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + esac + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $GREP "\-L"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; $ECHO "X$list" | $Xsed' + ;; + *) + if test "$GXX" = yes; then + if test $with_gnu_ld = no; then + case $host_cpu in + hppa*64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib -fPIC ${wl}+h ${wl}$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + ia64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib -fPIC ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + *) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + esac + fi + else + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + esac + ;; + + interix[[3-9]]*) + _LT_TAGVAR(hardcode_direct, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' + # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc. + # Instead, shared libraries are loaded at an image base (0x10000000 by + # default) and relocated if they conflict, which is a slow very memory + # consuming and fragmenting process. To avoid this, we pick a random, + # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link + # time. Moving up from 0x10000000 also allows more sbrk(2) space. + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='sed "s,^,_," $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--retain-symbols-file,$output_objdir/$soname.expsym ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + ;; + irix5* | irix6*) + case $cc_basename in + CC*) + # SGI C++ + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -all -multigot $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib' + + # Archives containing C++ object files must be created using + # "CC -ar", where "CC" is the IRIX C++ compiler. This is + # necessary to make sure instantiated templates are included + # in the archive. + _LT_TAGVAR(old_archive_cmds, $1)='$CC -ar -WR,-u -o $oldlib $oldobjs' + ;; + *) + if test "$GXX" = yes; then + if test "$with_gnu_ld" = no; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' + else + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` -o $lib' + fi + fi + _LT_TAGVAR(link_all_deplibs, $1)=yes + ;; + esac + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + _LT_TAGVAR(inherit_rpath, $1)=yes + ;; + + linux* | k*bsd*-gnu) + case $cc_basename in + KCC*) + # Kuck and Associates, Inc. (KAI) C++ Compiler + + # KCC will only create a shared library if the output file + # ends with ".so" (or ".sl" for HP-UX), so rename the library + # to its proper name (with version) after linking. + _LT_TAGVAR(archive_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib ${wl}-retain-symbols-file,$export_symbols; mv \$templib $lib' + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`$CC $CFLAGS -v conftest.$objext -o libconftest$shared_ext 2>&1 | $GREP "ld"`; rm -f libconftest$shared_ext; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; $ECHO "X$list" | $Xsed' + + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic' + + # Archives containing C++ object files must be created using + # "CC -Bstatic", where "CC" is the KAI C++ compiler. + _LT_TAGVAR(old_archive_cmds, $1)='$CC -Bstatic -o $oldlib $oldobjs' + ;; + icpc* | ecpc* ) + # Intel C++ + with_gnu_ld=yes + # version 8.0 and above of icpc choke on multiply defined symbols + # if we add $predep_objects and $postdep_objects, however 7.1 and + # earlier do not add the objects themselves. + case `$CC -V 2>&1` in + *"Version 7."*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + ;; + *) # Version 8.0 or newer + tmp_idyn= + case $host_cpu in + ia64*) tmp_idyn=' -i_dynamic';; + esac + _LT_TAGVAR(archive_cmds, $1)='$CC -shared'"$tmp_idyn"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared'"$tmp_idyn"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + ;; + esac + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic' + _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive$convenience ${wl}--no-whole-archive' + ;; + pgCC* | pgcpp*) + # Portland Group C++ compiler + case `$CC -V` in + *pgCC\ [[1-5]]* | *pgcpp\ [[1-5]]*) + _LT_TAGVAR(prelink_cmds, $1)='tpldir=Template.dir~ + rm -rf $tpldir~ + $CC --prelink_objects --instantiation_dir $tpldir $objs $libobjs $compile_deplibs~ + compile_command="$compile_command `find $tpldir -name \*.o | $NL2SP`"' + _LT_TAGVAR(old_archive_cmds, $1)='tpldir=Template.dir~ + rm -rf $tpldir~ + $CC --prelink_objects --instantiation_dir $tpldir $oldobjs$old_deplibs~ + $AR $AR_FLAGS $oldlib$oldobjs$old_deplibs `find $tpldir -name \*.o | $NL2SP`~ + $RANLIB $oldlib' + _LT_TAGVAR(archive_cmds, $1)='tpldir=Template.dir~ + rm -rf $tpldir~ + $CC --prelink_objects --instantiation_dir $tpldir $predep_objects $libobjs $deplibs $convenience $postdep_objects~ + $CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | $NL2SP` $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='tpldir=Template.dir~ + rm -rf $tpldir~ + $CC --prelink_objects --instantiation_dir $tpldir $predep_objects $libobjs $deplibs $convenience $postdep_objects~ + $CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | $NL2SP` $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname ${wl}-retain-symbols-file ${wl}$export_symbols -o $lib' + ;; + *) # Version 6 will use weak symbols + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname ${wl}-retain-symbols-file ${wl}$export_symbols -o $lib' + ;; + esac + + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}--rpath ${wl}$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic' + _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive' + ;; + cxx*) + # Compaq C++ + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib ${wl}-retain-symbols-file $wl$export_symbols' + + runpath_var=LD_RUN_PATH + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "ld"`; templist=`$ECHO "X$templist" | $Xsed -e "s/\(^.*ld.*\)\( .*ld .*$\)/\1/"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; $ECHO "X$list" | $Xsed' + ;; + xl*) + # IBM XL 8.0 on PPC, with GNU ld + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic' + _LT_TAGVAR(archive_cmds, $1)='$CC -qmkshrobj $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + if test "x$supports_anon_versioning" = xyes; then + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~ + cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ + echo "local: *; };" >> $output_objdir/$libname.ver~ + $CC -qmkshrobj $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-version-script ${wl}$output_objdir/$libname.ver -o $lib' + fi + ;; + *) + case `$CC -V 2>&1 | sed 5q` in + *Sun\ C*) + # Sun C++ 5.9 + _LT_TAGVAR(no_undefined_flag, $1)=' -zdefs' + _LT_TAGVAR(archive_cmds, $1)='$CC -G${allow_undefined_flag} -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G${allow_undefined_flag} -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-retain-symbols-file ${wl}$export_symbols' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive' + _LT_TAGVAR(compiler_needs_object, $1)=yes + + # Not sure whether something based on + # $CC $CFLAGS -v conftest.$objext -o libconftest$shared_ext 2>&1 + # would be better. + output_verbose_link_cmd='echo' + + # Archives containing C++ object files must be created using + # "CC -xar", where "CC" is the Sun C++ compiler. This is + # necessary to make sure instantiated templates are included + # in the archive. + _LT_TAGVAR(old_archive_cmds, $1)='$CC -xar -o $oldlib $oldobjs' + ;; + esac + ;; + esac + ;; + + lynxos*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + + m88k*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + + mvs*) + case $cc_basename in + cxx*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + *) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + esac + ;; + + netbsd*) + if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $predep_objects $libobjs $deplibs $postdep_objects $linker_flags' + wlarc= + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + fi + # Workaround some broken pre-1.5 toolchains + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP conftest.$objext | $SED -e "s:-lgcc -lc -lgcc::"' + ;; + + *nto* | *qnx*) + _LT_TAGVAR(ld_shlibs, $1)=yes + ;; + + openbsd2*) + # C++ shared libraries are fairly broken + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + + openbsd*) + if test -f /usr/libexec/ld.so; then + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_TAGVAR(hardcode_direct_absolute, $1)=yes + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $lib' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' + if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-retain-symbols-file,$export_symbols -o $lib' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' + _LT_TAGVAR(whole_archive_flag_spec, $1)="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive' + fi + output_verbose_link_cmd=echo + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + osf3* | osf4* | osf5*) + case $cc_basename in + KCC*) + # Kuck and Associates, Inc. (KAI) C++ Compiler + + # KCC will only create a shared library if the output file + # ends with ".so" (or ".sl" for HP-UX), so rename the library + # to its proper name (with version) after linking. + _LT_TAGVAR(archive_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo "$lib" | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib' + + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + + # Archives containing C++ object files must be created using + # the KAI C++ compiler. + case $host in + osf3*) _LT_TAGVAR(old_archive_cmds, $1)='$CC -Bstatic -o $oldlib $oldobjs' ;; + *) _LT_TAGVAR(old_archive_cmds, $1)='$CC -o $oldlib $oldobjs' ;; + esac + ;; + RCC*) + # Rational C++ 2.4.1 + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + cxx*) + case $host in + osf3*) + _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $soname `test -n "$verstring" && $ECHO "X${wl}-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + ;; + *) + _LT_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -msym -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done~ + echo "-hidden">> $lib.exp~ + $CC -shared$allow_undefined_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -msym -soname $soname ${wl}-input ${wl}$lib.exp `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib~ + $RM $lib.exp' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir' + ;; + esac + + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "ld" | $GREP -v "ld:"`; templist=`$ECHO "X$templist" | $Xsed -e "s/\(^.*ld.*\)\( .*ld.*$\)/\1/"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; $ECHO "X$list" | $Xsed' + ;; + *) + if test "$GXX" = yes && test "$with_gnu_ld" = no; then + _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*' + case $host in + osf3*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib ${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' + ;; + *) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib ${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-msym ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' + ;; + esac + + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "\-L"' + + else + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + esac + ;; + + psos*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + + sunos4*) + case $cc_basename in + CC*) + # Sun C++ 4.x + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + lcc*) + # Lucid + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + *) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + esac + ;; + + solaris*) + case $cc_basename in + CC*) + # Sun C++ 4.2, 5.x and Centerline C++ + _LT_TAGVAR(archive_cmds_need_lc,$1)=yes + _LT_TAGVAR(no_undefined_flag, $1)=' -zdefs' + _LT_TAGVAR(archive_cmds, $1)='$CC -G${allow_undefined_flag} -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $CC -G${allow_undefined_flag} ${wl}-M ${wl}$lib.exp -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp' + + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + case $host_os in + solaris2.[[0-5]] | solaris2.[[0-5]].*) ;; + *) + # The compiler driver will combine and reorder linker options, + # but understands `-z linker_flag'. + # Supported since Solaris 2.6 (maybe 2.5.1?) + _LT_TAGVAR(whole_archive_flag_spec, $1)='-z allextract$convenience -z defaultextract' + ;; + esac + _LT_TAGVAR(link_all_deplibs, $1)=yes + + output_verbose_link_cmd='echo' + + # Archives containing C++ object files must be created using + # "CC -xar", where "CC" is the Sun C++ compiler. This is + # necessary to make sure instantiated templates are included + # in the archive. + _LT_TAGVAR(old_archive_cmds, $1)='$CC -xar -o $oldlib $oldobjs' + ;; + gcx*) + # Green Hills C++ Compiler + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib' + + # The C++ compiler must be used to create the archive. + _LT_TAGVAR(old_archive_cmds, $1)='$CC $LDFLAGS -archive -o $oldlib $oldobjs' + ;; + *) + # GNU C++ compiler with Solaris linker + if test "$GXX" = yes && test "$with_gnu_ld" = no; then + _LT_TAGVAR(no_undefined_flag, $1)=' ${wl}-z ${wl}defs' + if $CC --version | $GREP -v '^2\.7' > /dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $LDFLAGS $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $CC -shared -nostdlib ${wl}-M $wl$lib.exp -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp' + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "\-L"' + else + # g++ 2.7 appears to require `-G' NOT `-shared' on this + # platform. + _LT_TAGVAR(archive_cmds, $1)='$CC -G -nostdlib $LDFLAGS $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $CC -G -nostdlib ${wl}-M $wl$lib.exp -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp' + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd='$CC -G $CFLAGS -v conftest.$objext 2>&1 | $GREP "\-L"' + fi + + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R $wl$libdir' + case $host_os in + solaris2.[[0-5]] | solaris2.[[0-5]].*) ;; + *) + _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}-z ${wl}allextract$convenience ${wl}-z ${wl}defaultextract' + ;; + esac + fi + ;; + esac + ;; + + sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[[01]].[[10]]* | unixware7* | sco3.2v5.0.[[024]]*) + _LT_TAGVAR(no_undefined_flag, $1)='${wl}-z,text' + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + runpath_var='LD_RUN_PATH' + + case $cc_basename in + CC*) + _LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + *) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + ;; + + sysv5* | sco3.2v5* | sco5v6*) + # Note: We can NOT use -z defs as we might desire, because we do not + # link with -lc, and that would cause any symbols used from libc to + # always be unresolved, which means just about no library would + # ever link correctly. If we're not using GNU ld we use -z text + # though, which does catch some bad symbols but isn't as heavy-handed + # as -z defs. + _LT_TAGVAR(no_undefined_flag, $1)='${wl}-z,text' + _LT_TAGVAR(allow_undefined_flag, $1)='${wl}-z,nodefs' + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R,$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=':' + _LT_TAGVAR(link_all_deplibs, $1)=yes + _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-Bexport' + runpath_var='LD_RUN_PATH' + + case $cc_basename in + CC*) + _LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + *) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + ;; + + tandem*) + case $cc_basename in + NCC*) + # NonStop-UX NCC 3.20 + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + *) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + esac + ;; + + vxworks*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + + *) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + esac + + AC_MSG_RESULT([$_LT_TAGVAR(ld_shlibs, $1)]) + test "$_LT_TAGVAR(ld_shlibs, $1)" = no && can_build_shared=no + + _LT_TAGVAR(GCC, $1)="$GXX" + _LT_TAGVAR(LD, $1)="$LD" + + ## CAVEAT EMPTOR: + ## There is no encapsulation within the following macros, do not change + ## the running order or otherwise move them around unless you know exactly + ## what you are doing... + _LT_SYS_HIDDEN_LIBDEPS($1) + _LT_COMPILER_PIC($1) + _LT_COMPILER_C_O($1) + _LT_COMPILER_FILE_LOCKS($1) + _LT_LINKER_SHLIBS($1) + _LT_SYS_DYNAMIC_LINKER($1) + _LT_LINKER_HARDCODE_LIBPATH($1) + + _LT_CONFIG($1) + fi # test -n "$compiler" + + CC=$lt_save_CC + LDCXX=$LD + LD=$lt_save_LD + GCC=$lt_save_GCC + with_gnu_ld=$lt_save_with_gnu_ld + lt_cv_path_LDCXX=$lt_cv_path_LD + lt_cv_path_LD=$lt_save_path_LD + lt_cv_prog_gnu_ldcxx=$lt_cv_prog_gnu_ld + lt_cv_prog_gnu_ld=$lt_save_with_gnu_ld +fi # test "$_lt_caught_CXX_error" != yes + +AC_LANG_POP +])# _LT_LANG_CXX_CONFIG + + +# _LT_SYS_HIDDEN_LIBDEPS([TAGNAME]) +# --------------------------------- +# Figure out "hidden" library dependencies from verbose +# compiler output when linking a shared library. +# Parse the compiler output and extract the necessary +# objects, libraries and library flags. +m4_defun([_LT_SYS_HIDDEN_LIBDEPS], +[m4_require([_LT_FILEUTILS_DEFAULTS])dnl +# Dependencies to place before and after the object being linked: +_LT_TAGVAR(predep_objects, $1)= +_LT_TAGVAR(postdep_objects, $1)= +_LT_TAGVAR(predeps, $1)= +_LT_TAGVAR(postdeps, $1)= +_LT_TAGVAR(compiler_lib_search_path, $1)= + +dnl we can't use the lt_simple_compile_test_code here, +dnl because it contains code intended for an executable, +dnl not a library. It's possible we should let each +dnl tag define a new lt_????_link_test_code variable, +dnl but it's only used here... +m4_if([$1], [], [cat > conftest.$ac_ext <<_LT_EOF +int a; +void foo (void) { a = 0; } +_LT_EOF +], [$1], [CXX], [cat > conftest.$ac_ext <<_LT_EOF +class Foo +{ +public: + Foo (void) { a = 0; } +private: + int a; +}; +_LT_EOF +], [$1], [F77], [cat > conftest.$ac_ext <<_LT_EOF + subroutine foo + implicit none + integer*4 a + a=0 + return + end +_LT_EOF +], [$1], [FC], [cat > conftest.$ac_ext <<_LT_EOF + subroutine foo + implicit none + integer a + a=0 + return + end +_LT_EOF +], [$1], [GCJ], [cat > conftest.$ac_ext <<_LT_EOF +public class foo { + private int a; + public void bar (void) { + a = 0; + } +}; +_LT_EOF +]) +dnl Parse the compiler output and extract the necessary +dnl objects, libraries and library flags. +if AC_TRY_EVAL(ac_compile); then + # Parse the compiler output and extract the necessary + # objects, libraries and library flags. + + # Sentinel used to keep track of whether or not we are before + # the conftest object file. + pre_test_object_deps_done=no + + for p in `eval "$output_verbose_link_cmd"`; do + case $p in + + -L* | -R* | -l*) + # Some compilers place space between "-{L,R}" and the path. + # Remove the space. + if test $p = "-L" || + test $p = "-R"; then + prev=$p + continue + else + prev= + fi + + if test "$pre_test_object_deps_done" = no; then + case $p in + -L* | -R*) + # Internal compiler library paths should come after those + # provided the user. The postdeps already come after the + # user supplied libs so there is no need to process them. + if test -z "$_LT_TAGVAR(compiler_lib_search_path, $1)"; then + _LT_TAGVAR(compiler_lib_search_path, $1)="${prev}${p}" + else + _LT_TAGVAR(compiler_lib_search_path, $1)="${_LT_TAGVAR(compiler_lib_search_path, $1)} ${prev}${p}" + fi + ;; + # The "-l" case would never come before the object being + # linked, so don't bother handling this case. + esac + else + if test -z "$_LT_TAGVAR(postdeps, $1)"; then + _LT_TAGVAR(postdeps, $1)="${prev}${p}" + else + _LT_TAGVAR(postdeps, $1)="${_LT_TAGVAR(postdeps, $1)} ${prev}${p}" + fi + fi + ;; + + *.$objext) + # This assumes that the test object file only shows up + # once in the compiler output. + if test "$p" = "conftest.$objext"; then + pre_test_object_deps_done=yes + continue + fi + + if test "$pre_test_object_deps_done" = no; then + if test -z "$_LT_TAGVAR(predep_objects, $1)"; then + _LT_TAGVAR(predep_objects, $1)="$p" + else + _LT_TAGVAR(predep_objects, $1)="$_LT_TAGVAR(predep_objects, $1) $p" + fi + else + if test -z "$_LT_TAGVAR(postdep_objects, $1)"; then + _LT_TAGVAR(postdep_objects, $1)="$p" + else + _LT_TAGVAR(postdep_objects, $1)="$_LT_TAGVAR(postdep_objects, $1) $p" + fi + fi + ;; + + *) ;; # Ignore the rest. + + esac + done + + # Clean up. + rm -f a.out a.exe +else + echo "libtool.m4: error: problem compiling $1 test program" +fi + +$RM -f confest.$objext + +# PORTME: override above test on systems where it is broken +m4_if([$1], [CXX], +[case $host_os in +interix[[3-9]]*) + # Interix 3.5 installs completely hosed .la files for C++, so rather than + # hack all around it, let's just trust "g++" to DTRT. + _LT_TAGVAR(predep_objects,$1)= + _LT_TAGVAR(postdep_objects,$1)= + _LT_TAGVAR(postdeps,$1)= + ;; + +linux*) + case `$CC -V 2>&1 | sed 5q` in + *Sun\ C*) + # Sun C++ 5.9 + + # The more standards-conforming stlport4 library is + # incompatible with the Cstd library. Avoid specifying + # it if it's in CXXFLAGS. Ignore libCrun as + # -library=stlport4 depends on it. + case " $CXX $CXXFLAGS " in + *" -library=stlport4 "*) + solaris_use_stlport4=yes + ;; + esac + + if test "$solaris_use_stlport4" != yes; then + _LT_TAGVAR(postdeps,$1)='-library=Cstd -library=Crun' + fi + ;; + esac + ;; + +solaris*) + case $cc_basename in + CC*) + # The more standards-conforming stlport4 library is + # incompatible with the Cstd library. Avoid specifying + # it if it's in CXXFLAGS. Ignore libCrun as + # -library=stlport4 depends on it. + case " $CXX $CXXFLAGS " in + *" -library=stlport4 "*) + solaris_use_stlport4=yes + ;; + esac + + # Adding this requires a known-good setup of shared libraries for + # Sun compiler versions before 5.6, else PIC objects from an old + # archive will be linked into the output, leading to subtle bugs. + if test "$solaris_use_stlport4" != yes; then + _LT_TAGVAR(postdeps,$1)='-library=Cstd -library=Crun' + fi + ;; + esac + ;; +esac +]) + +case " $_LT_TAGVAR(postdeps, $1) " in +*" -lc "*) _LT_TAGVAR(archive_cmds_need_lc, $1)=no ;; +esac + _LT_TAGVAR(compiler_lib_search_dirs, $1)= +if test -n "${_LT_TAGVAR(compiler_lib_search_path, $1)}"; then + _LT_TAGVAR(compiler_lib_search_dirs, $1)=`echo " ${_LT_TAGVAR(compiler_lib_search_path, $1)}" | ${SED} -e 's! -L! !g' -e 's!^ !!'` +fi +_LT_TAGDECL([], [compiler_lib_search_dirs], [1], + [The directories searched by this compiler when creating a shared library]) +_LT_TAGDECL([], [predep_objects], [1], + [Dependencies to place before and after the objects being linked to + create a shared library]) +_LT_TAGDECL([], [postdep_objects], [1]) +_LT_TAGDECL([], [predeps], [1]) +_LT_TAGDECL([], [postdeps], [1]) +_LT_TAGDECL([], [compiler_lib_search_path], [1], + [The library search path used internally by the compiler when linking + a shared library]) +])# _LT_SYS_HIDDEN_LIBDEPS + + +# _LT_PROG_F77 +# ------------ +# Since AC_PROG_F77 is broken, in that it returns the empty string +# if there is no fortran compiler, we have our own version here. +m4_defun([_LT_PROG_F77], +[ +pushdef([AC_MSG_ERROR], [_lt_disable_F77=yes]) +AC_PROG_F77 +if test -z "$F77" || test "X$F77" = "Xno"; then + _lt_disable_F77=yes +fi +popdef([AC_MSG_ERROR]) +])# _LT_PROG_F77 + +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([_LT_PROG_F77], []) + + +# _LT_LANG_F77_CONFIG([TAG]) +# -------------------------- +# Ensure that the configuration variables for a Fortran 77 compiler are +# suitably defined. These variables are subsequently used by _LT_CONFIG +# to write the compiler configuration to `libtool'. +m4_defun([_LT_LANG_F77_CONFIG], +[AC_REQUIRE([_LT_PROG_F77])dnl +AC_LANG_PUSH(Fortran 77) + +_LT_TAGVAR(archive_cmds_need_lc, $1)=no +_LT_TAGVAR(allow_undefined_flag, $1)= +_LT_TAGVAR(always_export_symbols, $1)=no +_LT_TAGVAR(archive_expsym_cmds, $1)= +_LT_TAGVAR(export_dynamic_flag_spec, $1)= +_LT_TAGVAR(hardcode_direct, $1)=no +_LT_TAGVAR(hardcode_direct_absolute, $1)=no +_LT_TAGVAR(hardcode_libdir_flag_spec, $1)= +_LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)= +_LT_TAGVAR(hardcode_libdir_separator, $1)= +_LT_TAGVAR(hardcode_minus_L, $1)=no +_LT_TAGVAR(hardcode_automatic, $1)=no +_LT_TAGVAR(inherit_rpath, $1)=no +_LT_TAGVAR(module_cmds, $1)= +_LT_TAGVAR(module_expsym_cmds, $1)= +_LT_TAGVAR(link_all_deplibs, $1)=unknown +_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds +_LT_TAGVAR(no_undefined_flag, $1)= +_LT_TAGVAR(whole_archive_flag_spec, $1)= +_LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no + +# Source file extension for f77 test sources. +ac_ext=f + +# Object file extension for compiled f77 test sources. +objext=o +_LT_TAGVAR(objext, $1)=$objext + +# No sense in running all these tests if we already determined that +# the F77 compiler isn't working. Some variables (like enable_shared) +# are currently assumed to apply to all compilers on this platform, +# and will be corrupted by setting them based on a non-working compiler. +if test "$_lt_disable_F77" != yes; then + # Code to be used in simple compile tests + lt_simple_compile_test_code="\ + subroutine t + return + end +" + + # Code to be used in simple link tests + lt_simple_link_test_code="\ + program t + end +" + + # ltmain only uses $CC for tagged configurations so make sure $CC is set. + _LT_TAG_COMPILER + + # save warnings/boilerplate of simple test code + _LT_COMPILER_BOILERPLATE + _LT_LINKER_BOILERPLATE + + # Allow CC to be a program name with arguments. + lt_save_CC="$CC" + lt_save_GCC=$GCC + CC=${F77-"f77"} + compiler=$CC + _LT_TAGVAR(compiler, $1)=$CC + _LT_CC_BASENAME([$compiler]) + GCC=$G77 + if test -n "$compiler"; then + AC_MSG_CHECKING([if libtool supports shared libraries]) + AC_MSG_RESULT([$can_build_shared]) + + AC_MSG_CHECKING([whether to build shared libraries]) + test "$can_build_shared" = "no" && enable_shared=no + + # On AIX, shared libraries and static libraries use the same namespace, and + # are all built from PIC. + case $host_os in + aix3*) + test "$enable_shared" = yes && enable_static=no + if test -n "$RANLIB"; then + archive_cmds="$archive_cmds~\$RANLIB \$lib" + postinstall_cmds='$RANLIB $lib' + fi + ;; + aix[[4-9]]*) + if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then + test "$enable_shared" = yes && enable_static=no + fi + ;; + esac + AC_MSG_RESULT([$enable_shared]) + + AC_MSG_CHECKING([whether to build static libraries]) + # Make sure either enable_shared or enable_static is yes. + test "$enable_shared" = yes || enable_static=yes + AC_MSG_RESULT([$enable_static]) + + _LT_TAGVAR(GCC, $1)="$G77" + _LT_TAGVAR(LD, $1)="$LD" + + ## CAVEAT EMPTOR: + ## There is no encapsulation within the following macros, do not change + ## the running order or otherwise move them around unless you know exactly + ## what you are doing... + _LT_COMPILER_PIC($1) + _LT_COMPILER_C_O($1) + _LT_COMPILER_FILE_LOCKS($1) + _LT_LINKER_SHLIBS($1) + _LT_SYS_DYNAMIC_LINKER($1) + _LT_LINKER_HARDCODE_LIBPATH($1) + + _LT_CONFIG($1) + fi # test -n "$compiler" + + GCC=$lt_save_GCC + CC="$lt_save_CC" +fi # test "$_lt_disable_F77" != yes + +AC_LANG_POP +])# _LT_LANG_F77_CONFIG + + +# _LT_PROG_FC +# ----------- +# Since AC_PROG_FC is broken, in that it returns the empty string +# if there is no fortran compiler, we have our own version here. +m4_defun([_LT_PROG_FC], +[ +pushdef([AC_MSG_ERROR], [_lt_disable_FC=yes]) +AC_PROG_FC +if test -z "$FC" || test "X$FC" = "Xno"; then + _lt_disable_FC=yes +fi +popdef([AC_MSG_ERROR]) +])# _LT_PROG_FC + +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([_LT_PROG_FC], []) + + +# _LT_LANG_FC_CONFIG([TAG]) +# ------------------------- +# Ensure that the configuration variables for a Fortran compiler are +# suitably defined. These variables are subsequently used by _LT_CONFIG +# to write the compiler configuration to `libtool'. +m4_defun([_LT_LANG_FC_CONFIG], +[AC_REQUIRE([_LT_PROG_FC])dnl +AC_LANG_PUSH(Fortran) + +_LT_TAGVAR(archive_cmds_need_lc, $1)=no +_LT_TAGVAR(allow_undefined_flag, $1)= +_LT_TAGVAR(always_export_symbols, $1)=no +_LT_TAGVAR(archive_expsym_cmds, $1)= +_LT_TAGVAR(export_dynamic_flag_spec, $1)= +_LT_TAGVAR(hardcode_direct, $1)=no +_LT_TAGVAR(hardcode_direct_absolute, $1)=no +_LT_TAGVAR(hardcode_libdir_flag_spec, $1)= +_LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)= +_LT_TAGVAR(hardcode_libdir_separator, $1)= +_LT_TAGVAR(hardcode_minus_L, $1)=no +_LT_TAGVAR(hardcode_automatic, $1)=no +_LT_TAGVAR(inherit_rpath, $1)=no +_LT_TAGVAR(module_cmds, $1)= +_LT_TAGVAR(module_expsym_cmds, $1)= +_LT_TAGVAR(link_all_deplibs, $1)=unknown +_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds +_LT_TAGVAR(no_undefined_flag, $1)= +_LT_TAGVAR(whole_archive_flag_spec, $1)= +_LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no + +# Source file extension for fc test sources. +ac_ext=${ac_fc_srcext-f} + +# Object file extension for compiled fc test sources. +objext=o +_LT_TAGVAR(objext, $1)=$objext + +# No sense in running all these tests if we already determined that +# the FC compiler isn't working. Some variables (like enable_shared) +# are currently assumed to apply to all compilers on this platform, +# and will be corrupted by setting them based on a non-working compiler. +if test "$_lt_disable_FC" != yes; then + # Code to be used in simple compile tests + lt_simple_compile_test_code="\ + subroutine t + return + end +" + + # Code to be used in simple link tests + lt_simple_link_test_code="\ + program t + end +" + + # ltmain only uses $CC for tagged configurations so make sure $CC is set. + _LT_TAG_COMPILER + + # save warnings/boilerplate of simple test code + _LT_COMPILER_BOILERPLATE + _LT_LINKER_BOILERPLATE + + # Allow CC to be a program name with arguments. + lt_save_CC="$CC" + lt_save_GCC=$GCC + CC=${FC-"f95"} + compiler=$CC + GCC=$ac_cv_fc_compiler_gnu + + _LT_TAGVAR(compiler, $1)=$CC + _LT_CC_BASENAME([$compiler]) + + if test -n "$compiler"; then + AC_MSG_CHECKING([if libtool supports shared libraries]) + AC_MSG_RESULT([$can_build_shared]) + + AC_MSG_CHECKING([whether to build shared libraries]) + test "$can_build_shared" = "no" && enable_shared=no + + # On AIX, shared libraries and static libraries use the same namespace, and + # are all built from PIC. + case $host_os in + aix3*) + test "$enable_shared" = yes && enable_static=no + if test -n "$RANLIB"; then + archive_cmds="$archive_cmds~\$RANLIB \$lib" + postinstall_cmds='$RANLIB $lib' + fi + ;; + aix[[4-9]]*) + if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then + test "$enable_shared" = yes && enable_static=no + fi + ;; + esac + AC_MSG_RESULT([$enable_shared]) + + AC_MSG_CHECKING([whether to build static libraries]) + # Make sure either enable_shared or enable_static is yes. + test "$enable_shared" = yes || enable_static=yes + AC_MSG_RESULT([$enable_static]) + + _LT_TAGVAR(GCC, $1)="$ac_cv_fc_compiler_gnu" + _LT_TAGVAR(LD, $1)="$LD" + + ## CAVEAT EMPTOR: + ## There is no encapsulation within the following macros, do not change + ## the running order or otherwise move them around unless you know exactly + ## what you are doing... + _LT_SYS_HIDDEN_LIBDEPS($1) + _LT_COMPILER_PIC($1) + _LT_COMPILER_C_O($1) + _LT_COMPILER_FILE_LOCKS($1) + _LT_LINKER_SHLIBS($1) + _LT_SYS_DYNAMIC_LINKER($1) + _LT_LINKER_HARDCODE_LIBPATH($1) + + _LT_CONFIG($1) + fi # test -n "$compiler" + + GCC=$lt_save_GCC + CC="$lt_save_CC" +fi # test "$_lt_disable_FC" != yes + +AC_LANG_POP +])# _LT_LANG_FC_CONFIG + + +# _LT_LANG_GCJ_CONFIG([TAG]) +# -------------------------- +# Ensure that the configuration variables for the GNU Java Compiler compiler +# are suitably defined. These variables are subsequently used by _LT_CONFIG +# to write the compiler configuration to `libtool'. +m4_defun([_LT_LANG_GCJ_CONFIG], +[AC_REQUIRE([LT_PROG_GCJ])dnl +AC_LANG_SAVE + +# Source file extension for Java test sources. +ac_ext=java + +# Object file extension for compiled Java test sources. +objext=o +_LT_TAGVAR(objext, $1)=$objext + +# Code to be used in simple compile tests +lt_simple_compile_test_code="class foo {}" + +# Code to be used in simple link tests +lt_simple_link_test_code='public class conftest { public static void main(String[[]] argv) {}; }' + +# ltmain only uses $CC for tagged configurations so make sure $CC is set. +_LT_TAG_COMPILER + +# save warnings/boilerplate of simple test code +_LT_COMPILER_BOILERPLATE +_LT_LINKER_BOILERPLATE + +# Allow CC to be a program name with arguments. +lt_save_CC="$CC" +lt_save_GCC=$GCC +GCC=yes +CC=${GCJ-"gcj"} +compiler=$CC +_LT_TAGVAR(compiler, $1)=$CC +_LT_TAGVAR(LD, $1)="$LD" +_LT_CC_BASENAME([$compiler]) + +# GCJ did not exist at the time GCC didn't implicitly link libc in. +_LT_TAGVAR(archive_cmds_need_lc, $1)=no + +_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds + +if test -n "$compiler"; then + _LT_COMPILER_NO_RTTI($1) + _LT_COMPILER_PIC($1) + _LT_COMPILER_C_O($1) + _LT_COMPILER_FILE_LOCKS($1) + _LT_LINKER_SHLIBS($1) + _LT_LINKER_HARDCODE_LIBPATH($1) + + _LT_CONFIG($1) +fi + +AC_LANG_RESTORE + +GCC=$lt_save_GCC +CC="$lt_save_CC" +])# _LT_LANG_GCJ_CONFIG + + +# _LT_LANG_RC_CONFIG([TAG]) +# ------------------------- +# Ensure that the configuration variables for the Windows resource compiler +# are suitably defined. These variables are subsequently used by _LT_CONFIG +# to write the compiler configuration to `libtool'. +m4_defun([_LT_LANG_RC_CONFIG], +[AC_REQUIRE([LT_PROG_RC])dnl +AC_LANG_SAVE + +# Source file extension for RC test sources. +ac_ext=rc + +# Object file extension for compiled RC test sources. +objext=o +_LT_TAGVAR(objext, $1)=$objext + +# Code to be used in simple compile tests +lt_simple_compile_test_code='sample MENU { MENUITEM "&Soup", 100, CHECKED }' + +# Code to be used in simple link tests +lt_simple_link_test_code="$lt_simple_compile_test_code" + +# ltmain only uses $CC for tagged configurations so make sure $CC is set. +_LT_TAG_COMPILER + +# save warnings/boilerplate of simple test code +_LT_COMPILER_BOILERPLATE +_LT_LINKER_BOILERPLATE + +# Allow CC to be a program name with arguments. +lt_save_CC="$CC" +lt_save_GCC=$GCC +GCC= +CC=${RC-"windres"} +compiler=$CC +_LT_TAGVAR(compiler, $1)=$CC +_LT_CC_BASENAME([$compiler]) +_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)=yes + +if test -n "$compiler"; then + : + _LT_CONFIG($1) +fi + +GCC=$lt_save_GCC +AC_LANG_RESTORE +CC="$lt_save_CC" +])# _LT_LANG_RC_CONFIG + + +# LT_PROG_GCJ +# ----------- +AC_DEFUN([LT_PROG_GCJ], +[m4_ifdef([AC_PROG_GCJ], [AC_PROG_GCJ], + [m4_ifdef([A][M_PROG_GCJ], [A][M_PROG_GCJ], + [AC_CHECK_TOOL(GCJ, gcj,) + test "x${GCJFLAGS+set}" = xset || GCJFLAGS="-g -O2" + AC_SUBST(GCJFLAGS)])])[]dnl +]) + +# Old name: +AU_ALIAS([LT_AC_PROG_GCJ], [LT_PROG_GCJ]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([LT_AC_PROG_GCJ], []) + + +# LT_PROG_RC +# ---------- +AC_DEFUN([LT_PROG_RC], +[AC_CHECK_TOOL(RC, windres,) +]) + +# Old name: +AU_ALIAS([LT_AC_PROG_RC], [LT_PROG_RC]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([LT_AC_PROG_RC], []) + + +# _LT_DECL_EGREP +# -------------- +# If we don't have a new enough Autoconf to choose the best grep +# available, choose the one first in the user's PATH. +m4_defun([_LT_DECL_EGREP], +[AC_REQUIRE([AC_PROG_EGREP])dnl +AC_REQUIRE([AC_PROG_FGREP])dnl +test -z "$GREP" && GREP=grep +_LT_DECL([], [GREP], [1], [A grep program that handles long lines]) +_LT_DECL([], [EGREP], [1], [An ERE matcher]) +_LT_DECL([], [FGREP], [1], [A literal string matcher]) +dnl Non-bleeding-edge autoconf doesn't subst GREP, so do it here too +AC_SUBST([GREP]) +]) + + +# _LT_DECL_OBJDUMP +# -------------- +# If we don't have a new enough Autoconf to choose the best objdump +# available, choose the one first in the user's PATH. +m4_defun([_LT_DECL_OBJDUMP], +[AC_CHECK_TOOL(OBJDUMP, objdump, false) +test -z "$OBJDUMP" && OBJDUMP=objdump +_LT_DECL([], [OBJDUMP], [1], [An object symbol dumper]) +AC_SUBST([OBJDUMP]) +]) + + +# _LT_DECL_SED +# ------------ +# Check for a fully-functional sed program, that truncates +# as few characters as possible. Prefer GNU sed if found. +m4_defun([_LT_DECL_SED], +[AC_PROG_SED +test -z "$SED" && SED=sed +Xsed="$SED -e 1s/^X//" +_LT_DECL([], [SED], [1], [A sed program that does not truncate output]) +_LT_DECL([], [Xsed], ["\$SED -e 1s/^X//"], + [Sed that helps us avoid accidentally triggering echo(1) options like -n]) +])# _LT_DECL_SED + +m4_ifndef([AC_PROG_SED], [ +# NOTE: This macro has been submitted for inclusion into # +# GNU Autoconf as AC_PROG_SED. When it is available in # +# a released version of Autoconf we should remove this # +# macro and use it instead. # + +m4_defun([AC_PROG_SED], +[AC_MSG_CHECKING([for a sed that does not truncate output]) +AC_CACHE_VAL(lt_cv_path_SED, +[# Loop through the user's path and test for sed and gsed. +# Then use that list of sed's as ones to test for truncation. +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for lt_ac_prog in sed gsed; do + for ac_exec_ext in '' $ac_executable_extensions; do + if $as_executable_p "$as_dir/$lt_ac_prog$ac_exec_ext"; then + lt_ac_sed_list="$lt_ac_sed_list $as_dir/$lt_ac_prog$ac_exec_ext" + fi + done + done +done +IFS=$as_save_IFS +lt_ac_max=0 +lt_ac_count=0 +# Add /usr/xpg4/bin/sed as it is typically found on Solaris +# along with /bin/sed that truncates output. +for lt_ac_sed in $lt_ac_sed_list /usr/xpg4/bin/sed; do + test ! -f $lt_ac_sed && continue + cat /dev/null > conftest.in + lt_ac_count=0 + echo $ECHO_N "0123456789$ECHO_C" >conftest.in + # Check for GNU sed and select it if it is found. + if "$lt_ac_sed" --version 2>&1 < /dev/null | grep 'GNU' > /dev/null; then + lt_cv_path_SED=$lt_ac_sed + break + fi + while true; do + cat conftest.in conftest.in >conftest.tmp + mv conftest.tmp conftest.in + cp conftest.in conftest.nl + echo >>conftest.nl + $lt_ac_sed -e 's/a$//' < conftest.nl >conftest.out || break + cmp -s conftest.out conftest.nl || break + # 10000 chars as input seems more than enough + test $lt_ac_count -gt 10 && break + lt_ac_count=`expr $lt_ac_count + 1` + if test $lt_ac_count -gt $lt_ac_max; then + lt_ac_max=$lt_ac_count + lt_cv_path_SED=$lt_ac_sed + fi + done +done +]) +SED=$lt_cv_path_SED +AC_SUBST([SED]) +AC_MSG_RESULT([$SED]) +])#AC_PROG_SED +])#m4_ifndef + +# Old name: +AU_ALIAS([LT_AC_PROG_SED], [AC_PROG_SED]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([LT_AC_PROG_SED], []) + + +# _LT_CHECK_SHELL_FEATURES +# ------------------------ +# Find out whether the shell is Bourne or XSI compatible, +# or has some other useful features. +m4_defun([_LT_CHECK_SHELL_FEATURES], +[AC_MSG_CHECKING([whether the shell understands some XSI constructs]) +# Try some XSI features +xsi_shell=no +( _lt_dummy="a/b/c" + test "${_lt_dummy##*/},${_lt_dummy%/*},"${_lt_dummy%"$_lt_dummy"}, \ + = c,a/b,, \ + && eval 'test $(( 1 + 1 )) -eq 2 \ + && test "${#_lt_dummy}" -eq 5' ) >/dev/null 2>&1 \ + && xsi_shell=yes +AC_MSG_RESULT([$xsi_shell]) +_LT_CONFIG_LIBTOOL_INIT([xsi_shell='$xsi_shell']) + +AC_MSG_CHECKING([whether the shell understands "+="]) +lt_shell_append=no +( foo=bar; set foo baz; eval "$[1]+=\$[2]" && test "$foo" = barbaz ) \ + >/dev/null 2>&1 \ + && lt_shell_append=yes +AC_MSG_RESULT([$lt_shell_append]) +_LT_CONFIG_LIBTOOL_INIT([lt_shell_append='$lt_shell_append']) + +if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then + lt_unset=unset +else + lt_unset=false +fi +_LT_DECL([], [lt_unset], [0], [whether the shell understands "unset"])dnl + +# test EBCDIC or ASCII +case `echo X|tr X '\101'` in + A) # ASCII based system + # \n is not interpreted correctly by Solaris 8 /usr/ucb/tr + lt_SP2NL='tr \040 \012' + lt_NL2SP='tr \015\012 \040\040' + ;; + *) # EBCDIC based system + lt_SP2NL='tr \100 \n' + lt_NL2SP='tr \r\n \100\100' + ;; +esac +_LT_DECL([SP2NL], [lt_SP2NL], [1], [turn spaces into newlines])dnl +_LT_DECL([NL2SP], [lt_NL2SP], [1], [turn newlines into spaces])dnl +])# _LT_CHECK_SHELL_FEATURES + + +# _LT_PROG_XSI_SHELLFNS +# --------------------- +# Bourne and XSI compatible variants of some useful shell functions. +m4_defun([_LT_PROG_XSI_SHELLFNS], +[case $xsi_shell in + yes) + cat << \_LT_EOF >> "$cfgfile" + +# func_dirname file append nondir_replacement +# Compute the dirname of FILE. If nonempty, add APPEND to the result, +# otherwise set result to NONDIR_REPLACEMENT. +func_dirname () +{ + case ${1} in + */*) func_dirname_result="${1%/*}${2}" ;; + * ) func_dirname_result="${3}" ;; + esac +} + +# func_basename file +func_basename () +{ + func_basename_result="${1##*/}" +} + +# func_dirname_and_basename file append nondir_replacement +# perform func_basename and func_dirname in a single function +# call: +# dirname: Compute the dirname of FILE. If nonempty, +# add APPEND to the result, otherwise set result +# to NONDIR_REPLACEMENT. +# value returned in "$func_dirname_result" +# basename: Compute filename of FILE. +# value retuned in "$func_basename_result" +# Implementation must be kept synchronized with func_dirname +# and func_basename. For efficiency, we do not delegate to +# those functions but instead duplicate the functionality here. +func_dirname_and_basename () +{ + case ${1} in + */*) func_dirname_result="${1%/*}${2}" ;; + * ) func_dirname_result="${3}" ;; + esac + func_basename_result="${1##*/}" +} + +# func_stripname prefix suffix name +# strip PREFIX and SUFFIX off of NAME. +# PREFIX and SUFFIX must not contain globbing or regex special +# characters, hashes, percent signs, but SUFFIX may contain a leading +# dot (in which case that matches only a dot). +func_stripname () +{ + # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are + # positional parameters, so assign one to ordinary parameter first. + func_stripname_result=${3} + func_stripname_result=${func_stripname_result#"${1}"} + func_stripname_result=${func_stripname_result%"${2}"} +} + +# func_opt_split +func_opt_split () +{ + func_opt_split_opt=${1%%=*} + func_opt_split_arg=${1#*=} +} + +# func_lo2o object +func_lo2o () +{ + case ${1} in + *.lo) func_lo2o_result=${1%.lo}.${objext} ;; + *) func_lo2o_result=${1} ;; + esac +} + +# func_xform libobj-or-source +func_xform () +{ + func_xform_result=${1%.*}.lo +} + +# func_arith arithmetic-term... +func_arith () +{ + func_arith_result=$(( $[*] )) +} + +# func_len string +# STRING may not start with a hyphen. +func_len () +{ + func_len_result=${#1} +} + +_LT_EOF + ;; + *) # Bourne compatible functions. + cat << \_LT_EOF >> "$cfgfile" + +# func_dirname file append nondir_replacement +# Compute the dirname of FILE. If nonempty, add APPEND to the result, +# otherwise set result to NONDIR_REPLACEMENT. +func_dirname () +{ + # Extract subdirectory from the argument. + func_dirname_result=`$ECHO "X${1}" | $Xsed -e "$dirname"` + if test "X$func_dirname_result" = "X${1}"; then + func_dirname_result="${3}" + else + func_dirname_result="$func_dirname_result${2}" + fi +} + +# func_basename file +func_basename () +{ + func_basename_result=`$ECHO "X${1}" | $Xsed -e "$basename"` +} + +dnl func_dirname_and_basename +dnl A portable version of this function is already defined in general.m4sh +dnl so there is no need for it here. + +# func_stripname prefix suffix name +# strip PREFIX and SUFFIX off of NAME. +# PREFIX and SUFFIX must not contain globbing or regex special +# characters, hashes, percent signs, but SUFFIX may contain a leading +# dot (in which case that matches only a dot). +# func_strip_suffix prefix name +func_stripname () +{ + case ${2} in + .*) func_stripname_result=`$ECHO "X${3}" \ + | $Xsed -e "s%^${1}%%" -e "s%\\\\${2}\$%%"`;; + *) func_stripname_result=`$ECHO "X${3}" \ + | $Xsed -e "s%^${1}%%" -e "s%${2}\$%%"`;; + esac +} + +# sed scripts: +my_sed_long_opt='1s/^\(-[[^=]]*\)=.*/\1/;q' +my_sed_long_arg='1s/^-[[^=]]*=//' + +# func_opt_split +func_opt_split () +{ + func_opt_split_opt=`$ECHO "X${1}" | $Xsed -e "$my_sed_long_opt"` + func_opt_split_arg=`$ECHO "X${1}" | $Xsed -e "$my_sed_long_arg"` +} + +# func_lo2o object +func_lo2o () +{ + func_lo2o_result=`$ECHO "X${1}" | $Xsed -e "$lo2o"` +} + +# func_xform libobj-or-source +func_xform () +{ + func_xform_result=`$ECHO "X${1}" | $Xsed -e 's/\.[[^.]]*$/.lo/'` +} + +# func_arith arithmetic-term... +func_arith () +{ + func_arith_result=`expr "$[@]"` +} + +# func_len string +# STRING may not start with a hyphen. +func_len () +{ + func_len_result=`expr "$[1]" : ".*" 2>/dev/null || echo $max_cmd_len` +} + +_LT_EOF +esac + +case $lt_shell_append in + yes) + cat << \_LT_EOF >> "$cfgfile" + +# func_append var value +# Append VALUE to the end of shell variable VAR. +func_append () +{ + eval "$[1]+=\$[2]" +} +_LT_EOF + ;; + *) + cat << \_LT_EOF >> "$cfgfile" + +# func_append var value +# Append VALUE to the end of shell variable VAR. +func_append () +{ + eval "$[1]=\$$[1]\$[2]" +} + +_LT_EOF + ;; + esac +]) + +# Helper functions for option handling. -*- Autoconf -*- +# +# Copyright (C) 2004, 2005, 2007, 2008 Free Software Foundation, Inc. +# Written by Gary V. Vaughan, 2004 +# +# This file is free software; the Free Software Foundation gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. + +# serial 6 ltoptions.m4 + +# This is to help aclocal find these macros, as it can't see m4_define. +AC_DEFUN([LTOPTIONS_VERSION], [m4_if([1])]) + + +# _LT_MANGLE_OPTION(MACRO-NAME, OPTION-NAME) +# ------------------------------------------ +m4_define([_LT_MANGLE_OPTION], +[[_LT_OPTION_]m4_bpatsubst($1__$2, [[^a-zA-Z0-9_]], [_])]) + + +# _LT_SET_OPTION(MACRO-NAME, OPTION-NAME) +# --------------------------------------- +# Set option OPTION-NAME for macro MACRO-NAME, and if there is a +# matching handler defined, dispatch to it. Other OPTION-NAMEs are +# saved as a flag. +m4_define([_LT_SET_OPTION], +[m4_define(_LT_MANGLE_OPTION([$1], [$2]))dnl +m4_ifdef(_LT_MANGLE_DEFUN([$1], [$2]), + _LT_MANGLE_DEFUN([$1], [$2]), + [m4_warning([Unknown $1 option `$2'])])[]dnl +]) + + +# _LT_IF_OPTION(MACRO-NAME, OPTION-NAME, IF-SET, [IF-NOT-SET]) +# ------------------------------------------------------------ +# Execute IF-SET if OPTION is set, IF-NOT-SET otherwise. +m4_define([_LT_IF_OPTION], +[m4_ifdef(_LT_MANGLE_OPTION([$1], [$2]), [$3], [$4])]) + + +# _LT_UNLESS_OPTIONS(MACRO-NAME, OPTION-LIST, IF-NOT-SET) +# ------------------------------------------------------- +# Execute IF-NOT-SET unless all options in OPTION-LIST for MACRO-NAME +# are set. +m4_define([_LT_UNLESS_OPTIONS], +[m4_foreach([_LT_Option], m4_split(m4_normalize([$2])), + [m4_ifdef(_LT_MANGLE_OPTION([$1], _LT_Option), + [m4_define([$0_found])])])[]dnl +m4_ifdef([$0_found], [m4_undefine([$0_found])], [$3 +])[]dnl +]) + + +# _LT_SET_OPTIONS(MACRO-NAME, OPTION-LIST) +# ---------------------------------------- +# OPTION-LIST is a space-separated list of Libtool options associated +# with MACRO-NAME. If any OPTION has a matching handler declared with +# LT_OPTION_DEFINE, dispatch to that macro; otherwise complain about +# the unknown option and exit. +m4_defun([_LT_SET_OPTIONS], +[# Set options +m4_foreach([_LT_Option], m4_split(m4_normalize([$2])), + [_LT_SET_OPTION([$1], _LT_Option)]) + +m4_if([$1],[LT_INIT],[ + dnl + dnl Simply set some default values (i.e off) if boolean options were not + dnl specified: + _LT_UNLESS_OPTIONS([LT_INIT], [dlopen], [enable_dlopen=no + ]) + _LT_UNLESS_OPTIONS([LT_INIT], [win32-dll], [enable_win32_dll=no + ]) + dnl + dnl If no reference was made to various pairs of opposing options, then + dnl we run the default mode handler for the pair. For example, if neither + dnl `shared' nor `disable-shared' was passed, we enable building of shared + dnl archives by default: + _LT_UNLESS_OPTIONS([LT_INIT], [shared disable-shared], [_LT_ENABLE_SHARED]) + _LT_UNLESS_OPTIONS([LT_INIT], [static disable-static], [_LT_ENABLE_STATIC]) + _LT_UNLESS_OPTIONS([LT_INIT], [pic-only no-pic], [_LT_WITH_PIC]) + _LT_UNLESS_OPTIONS([LT_INIT], [fast-install disable-fast-install], + [_LT_ENABLE_FAST_INSTALL]) + ]) +])# _LT_SET_OPTIONS + + + +# _LT_MANGLE_DEFUN(MACRO-NAME, OPTION-NAME) +# ----------------------------------------- +m4_define([_LT_MANGLE_DEFUN], +[[_LT_OPTION_DEFUN_]m4_bpatsubst(m4_toupper([$1__$2]), [[^A-Z0-9_]], [_])]) + + +# LT_OPTION_DEFINE(MACRO-NAME, OPTION-NAME, CODE) +# ----------------------------------------------- +m4_define([LT_OPTION_DEFINE], +[m4_define(_LT_MANGLE_DEFUN([$1], [$2]), [$3])[]dnl +])# LT_OPTION_DEFINE + + +# dlopen +# ------ +LT_OPTION_DEFINE([LT_INIT], [dlopen], [enable_dlopen=yes +]) + +AU_DEFUN([AC_LIBTOOL_DLOPEN], +[_LT_SET_OPTION([LT_INIT], [dlopen]) +AC_DIAGNOSE([obsolete], +[$0: Remove this warning and the call to _LT_SET_OPTION when you +put the `dlopen' option into LT_INIT's first parameter.]) +]) + +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_DLOPEN], []) + + +# win32-dll +# --------- +# Declare package support for building win32 dll's. +LT_OPTION_DEFINE([LT_INIT], [win32-dll], +[enable_win32_dll=yes + +case $host in +*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-cegcc*) + AC_CHECK_TOOL(AS, as, false) + AC_CHECK_TOOL(DLLTOOL, dlltool, false) + AC_CHECK_TOOL(OBJDUMP, objdump, false) + ;; +esac + +test -z "$AS" && AS=as +_LT_DECL([], [AS], [0], [Assembler program])dnl + +test -z "$DLLTOOL" && DLLTOOL=dlltool +_LT_DECL([], [DLLTOOL], [0], [DLL creation program])dnl + +test -z "$OBJDUMP" && OBJDUMP=objdump +_LT_DECL([], [OBJDUMP], [0], [Object dumper program])dnl +])# win32-dll + +AU_DEFUN([AC_LIBTOOL_WIN32_DLL], +[AC_REQUIRE([AC_CANONICAL_HOST])dnl +_LT_SET_OPTION([LT_INIT], [win32-dll]) +AC_DIAGNOSE([obsolete], +[$0: Remove this warning and the call to _LT_SET_OPTION when you +put the `win32-dll' option into LT_INIT's first parameter.]) +]) + +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_WIN32_DLL], []) + + +# _LT_ENABLE_SHARED([DEFAULT]) +# ---------------------------- +# implement the --enable-shared flag, and supports the `shared' and +# `disable-shared' LT_INIT options. +# DEFAULT is either `yes' or `no'. If omitted, it defaults to `yes'. +m4_define([_LT_ENABLE_SHARED], +[m4_define([_LT_ENABLE_SHARED_DEFAULT], [m4_if($1, no, no, yes)])dnl +AC_ARG_ENABLE([shared], + [AS_HELP_STRING([--enable-shared@<:@=PKGS@:>@], + [build shared libraries @<:@default=]_LT_ENABLE_SHARED_DEFAULT[@:>@])], + [p=${PACKAGE-default} + case $enableval in + yes) enable_shared=yes ;; + no) enable_shared=no ;; + *) + enable_shared=no + # Look at the argument we got. We use all the common list separators. + lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR," + for pkg in $enableval; do + IFS="$lt_save_ifs" + if test "X$pkg" = "X$p"; then + enable_shared=yes + fi + done + IFS="$lt_save_ifs" + ;; + esac], + [enable_shared=]_LT_ENABLE_SHARED_DEFAULT) + + _LT_DECL([build_libtool_libs], [enable_shared], [0], + [Whether or not to build shared libraries]) +])# _LT_ENABLE_SHARED + +LT_OPTION_DEFINE([LT_INIT], [shared], [_LT_ENABLE_SHARED([yes])]) +LT_OPTION_DEFINE([LT_INIT], [disable-shared], [_LT_ENABLE_SHARED([no])]) + +# Old names: +AC_DEFUN([AC_ENABLE_SHARED], +[_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[shared]) +]) + +AC_DEFUN([AC_DISABLE_SHARED], +[_LT_SET_OPTION([LT_INIT], [disable-shared]) +]) + +AU_DEFUN([AM_ENABLE_SHARED], [AC_ENABLE_SHARED($@)]) +AU_DEFUN([AM_DISABLE_SHARED], [AC_DISABLE_SHARED($@)]) + +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AM_ENABLE_SHARED], []) +dnl AC_DEFUN([AM_DISABLE_SHARED], []) + + + +# _LT_ENABLE_STATIC([DEFAULT]) +# ---------------------------- +# implement the --enable-static flag, and support the `static' and +# `disable-static' LT_INIT options. +# DEFAULT is either `yes' or `no'. If omitted, it defaults to `yes'. +m4_define([_LT_ENABLE_STATIC], +[m4_define([_LT_ENABLE_STATIC_DEFAULT], [m4_if($1, no, no, yes)])dnl +AC_ARG_ENABLE([static], + [AS_HELP_STRING([--enable-static@<:@=PKGS@:>@], + [build static libraries @<:@default=]_LT_ENABLE_STATIC_DEFAULT[@:>@])], + [p=${PACKAGE-default} + case $enableval in + yes) enable_static=yes ;; + no) enable_static=no ;; + *) + enable_static=no + # Look at the argument we got. We use all the common list separators. + lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR," + for pkg in $enableval; do + IFS="$lt_save_ifs" + if test "X$pkg" = "X$p"; then + enable_static=yes + fi + done + IFS="$lt_save_ifs" + ;; + esac], + [enable_static=]_LT_ENABLE_STATIC_DEFAULT) + + _LT_DECL([build_old_libs], [enable_static], [0], + [Whether or not to build static libraries]) +])# _LT_ENABLE_STATIC + +LT_OPTION_DEFINE([LT_INIT], [static], [_LT_ENABLE_STATIC([yes])]) +LT_OPTION_DEFINE([LT_INIT], [disable-static], [_LT_ENABLE_STATIC([no])]) + +# Old names: +AC_DEFUN([AC_ENABLE_STATIC], +[_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[static]) +]) + +AC_DEFUN([AC_DISABLE_STATIC], +[_LT_SET_OPTION([LT_INIT], [disable-static]) +]) + +AU_DEFUN([AM_ENABLE_STATIC], [AC_ENABLE_STATIC($@)]) +AU_DEFUN([AM_DISABLE_STATIC], [AC_DISABLE_STATIC($@)]) + +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AM_ENABLE_STATIC], []) +dnl AC_DEFUN([AM_DISABLE_STATIC], []) + + + +# _LT_ENABLE_FAST_INSTALL([DEFAULT]) +# ---------------------------------- +# implement the --enable-fast-install flag, and support the `fast-install' +# and `disable-fast-install' LT_INIT options. +# DEFAULT is either `yes' or `no'. If omitted, it defaults to `yes'. +m4_define([_LT_ENABLE_FAST_INSTALL], +[m4_define([_LT_ENABLE_FAST_INSTALL_DEFAULT], [m4_if($1, no, no, yes)])dnl +AC_ARG_ENABLE([fast-install], + [AS_HELP_STRING([--enable-fast-install@<:@=PKGS@:>@], + [optimize for fast installation @<:@default=]_LT_ENABLE_FAST_INSTALL_DEFAULT[@:>@])], + [p=${PACKAGE-default} + case $enableval in + yes) enable_fast_install=yes ;; + no) enable_fast_install=no ;; + *) + enable_fast_install=no + # Look at the argument we got. We use all the common list separators. + lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR," + for pkg in $enableval; do + IFS="$lt_save_ifs" + if test "X$pkg" = "X$p"; then + enable_fast_install=yes + fi + done + IFS="$lt_save_ifs" + ;; + esac], + [enable_fast_install=]_LT_ENABLE_FAST_INSTALL_DEFAULT) + +_LT_DECL([fast_install], [enable_fast_install], [0], + [Whether or not to optimize for fast installation])dnl +])# _LT_ENABLE_FAST_INSTALL + +LT_OPTION_DEFINE([LT_INIT], [fast-install], [_LT_ENABLE_FAST_INSTALL([yes])]) +LT_OPTION_DEFINE([LT_INIT], [disable-fast-install], [_LT_ENABLE_FAST_INSTALL([no])]) + +# Old names: +AU_DEFUN([AC_ENABLE_FAST_INSTALL], +[_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[fast-install]) +AC_DIAGNOSE([obsolete], +[$0: Remove this warning and the call to _LT_SET_OPTION when you put +the `fast-install' option into LT_INIT's first parameter.]) +]) + +AU_DEFUN([AC_DISABLE_FAST_INSTALL], +[_LT_SET_OPTION([LT_INIT], [disable-fast-install]) +AC_DIAGNOSE([obsolete], +[$0: Remove this warning and the call to _LT_SET_OPTION when you put +the `disable-fast-install' option into LT_INIT's first parameter.]) +]) + +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_ENABLE_FAST_INSTALL], []) +dnl AC_DEFUN([AM_DISABLE_FAST_INSTALL], []) + + +# _LT_WITH_PIC([MODE]) +# -------------------- +# implement the --with-pic flag, and support the `pic-only' and `no-pic' +# LT_INIT options. +# MODE is either `yes' or `no'. If omitted, it defaults to `both'. +m4_define([_LT_WITH_PIC], +[AC_ARG_WITH([pic], + [AS_HELP_STRING([--with-pic], + [try to use only PIC/non-PIC objects @<:@default=use both@:>@])], + [pic_mode="$withval"], + [pic_mode=default]) + +test -z "$pic_mode" && pic_mode=m4_default([$1], [default]) + +_LT_DECL([], [pic_mode], [0], [What type of objects to build])dnl +])# _LT_WITH_PIC + +LT_OPTION_DEFINE([LT_INIT], [pic-only], [_LT_WITH_PIC([yes])]) +LT_OPTION_DEFINE([LT_INIT], [no-pic], [_LT_WITH_PIC([no])]) + +# Old name: +AU_DEFUN([AC_LIBTOOL_PICMODE], +[_LT_SET_OPTION([LT_INIT], [pic-only]) +AC_DIAGNOSE([obsolete], +[$0: Remove this warning and the call to _LT_SET_OPTION when you +put the `pic-only' option into LT_INIT's first parameter.]) +]) + +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_PICMODE], []) + + +m4_define([_LTDL_MODE], []) +LT_OPTION_DEFINE([LTDL_INIT], [nonrecursive], + [m4_define([_LTDL_MODE], [nonrecursive])]) +LT_OPTION_DEFINE([LTDL_INIT], [recursive], + [m4_define([_LTDL_MODE], [recursive])]) +LT_OPTION_DEFINE([LTDL_INIT], [subproject], + [m4_define([_LTDL_MODE], [subproject])]) + +m4_define([_LTDL_TYPE], []) +LT_OPTION_DEFINE([LTDL_INIT], [installable], + [m4_define([_LTDL_TYPE], [installable])]) +LT_OPTION_DEFINE([LTDL_INIT], [convenience], + [m4_define([_LTDL_TYPE], [convenience])]) + +# ltsugar.m4 -- libtool m4 base layer. -*-Autoconf-*- +# +# Copyright (C) 2004, 2005, 2007, 2008 Free Software Foundation, Inc. +# Written by Gary V. Vaughan, 2004 +# +# This file is free software; the Free Software Foundation gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. + +# serial 6 ltsugar.m4 + +# This is to help aclocal find these macros, as it can't see m4_define. +AC_DEFUN([LTSUGAR_VERSION], [m4_if([0.1])]) + + +# lt_join(SEP, ARG1, [ARG2...]) +# ----------------------------- +# Produce ARG1SEPARG2...SEPARGn, omitting [] arguments and their +# associated separator. +# Needed until we can rely on m4_join from Autoconf 2.62, since all earlier +# versions in m4sugar had bugs. +m4_define([lt_join], +[m4_if([$#], [1], [], + [$#], [2], [[$2]], + [m4_if([$2], [], [], [[$2]_])$0([$1], m4_shift(m4_shift($@)))])]) +m4_define([_lt_join], +[m4_if([$#$2], [2], [], + [m4_if([$2], [], [], [[$1$2]])$0([$1], m4_shift(m4_shift($@)))])]) + + +# lt_car(LIST) +# lt_cdr(LIST) +# ------------ +# Manipulate m4 lists. +# These macros are necessary as long as will still need to support +# Autoconf-2.59 which quotes differently. +m4_define([lt_car], [[$1]]) +m4_define([lt_cdr], +[m4_if([$#], 0, [m4_fatal([$0: cannot be called without arguments])], + [$#], 1, [], + [m4_dquote(m4_shift($@))])]) +m4_define([lt_unquote], $1) + + +# lt_append(MACRO-NAME, STRING, [SEPARATOR]) +# ------------------------------------------ +# Redefine MACRO-NAME to hold its former content plus `SEPARATOR'`STRING'. +# Note that neither SEPARATOR nor STRING are expanded; they are appended +# to MACRO-NAME as is (leaving the expansion for when MACRO-NAME is invoked). +# No SEPARATOR is output if MACRO-NAME was previously undefined (different +# than defined and empty). +# +# This macro is needed until we can rely on Autoconf 2.62, since earlier +# versions of m4sugar mistakenly expanded SEPARATOR but not STRING. +m4_define([lt_append], +[m4_define([$1], + m4_ifdef([$1], [m4_defn([$1])[$3]])[$2])]) + + + +# lt_combine(SEP, PREFIX-LIST, INFIX, SUFFIX1, [SUFFIX2...]) +# ---------------------------------------------------------- +# Produce a SEP delimited list of all paired combinations of elements of +# PREFIX-LIST with SUFFIX1 through SUFFIXn. Each element of the list +# has the form PREFIXmINFIXSUFFIXn. +# Needed until we can rely on m4_combine added in Autoconf 2.62. +m4_define([lt_combine], +[m4_if(m4_eval([$# > 3]), [1], + [m4_pushdef([_Lt_sep], [m4_define([_Lt_sep], m4_defn([lt_car]))])]]dnl +[[m4_foreach([_Lt_prefix], [$2], + [m4_foreach([_Lt_suffix], + ]m4_dquote(m4_dquote(m4_shift(m4_shift(m4_shift($@)))))[, + [_Lt_sep([$1])[]m4_defn([_Lt_prefix])[$3]m4_defn([_Lt_suffix])])])])]) + + +# lt_if_append_uniq(MACRO-NAME, VARNAME, [SEPARATOR], [UNIQ], [NOT-UNIQ]) +# ----------------------------------------------------------------------- +# Iff MACRO-NAME does not yet contain VARNAME, then append it (delimited +# by SEPARATOR if supplied) and expand UNIQ, else NOT-UNIQ. +m4_define([lt_if_append_uniq], +[m4_ifdef([$1], + [m4_if(m4_index([$3]m4_defn([$1])[$3], [$3$2$3]), [-1], + [lt_append([$1], [$2], [$3])$4], + [$5])], + [lt_append([$1], [$2], [$3])$4])]) + + +# lt_dict_add(DICT, KEY, VALUE) +# ----------------------------- +m4_define([lt_dict_add], +[m4_define([$1($2)], [$3])]) + + +# lt_dict_add_subkey(DICT, KEY, SUBKEY, VALUE) +# -------------------------------------------- +m4_define([lt_dict_add_subkey], +[m4_define([$1($2:$3)], [$4])]) + + +# lt_dict_fetch(DICT, KEY, [SUBKEY]) +# ---------------------------------- +m4_define([lt_dict_fetch], +[m4_ifval([$3], + m4_ifdef([$1($2:$3)], [m4_defn([$1($2:$3)])]), + m4_ifdef([$1($2)], [m4_defn([$1($2)])]))]) + + +# lt_if_dict_fetch(DICT, KEY, [SUBKEY], VALUE, IF-TRUE, [IF-FALSE]) +# ----------------------------------------------------------------- +m4_define([lt_if_dict_fetch], +[m4_if(lt_dict_fetch([$1], [$2], [$3]), [$4], + [$5], + [$6])]) + + +# lt_dict_filter(DICT, [SUBKEY], VALUE, [SEPARATOR], KEY, [...]) +# -------------------------------------------------------------- +m4_define([lt_dict_filter], +[m4_if([$5], [], [], + [lt_join(m4_quote(m4_default([$4], [[, ]])), + lt_unquote(m4_split(m4_normalize(m4_foreach(_Lt_key, lt_car([m4_shiftn(4, $@)]), + [lt_if_dict_fetch([$1], _Lt_key, [$2], [$3], [_Lt_key ])])))))])[]dnl +]) + +# ltversion.m4 -- version numbers -*- Autoconf -*- +# +# Copyright (C) 2004 Free Software Foundation, Inc. +# Written by Scott James Remnant, 2004 +# +# This file is free software; the Free Software Foundation gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. + +# Generated from ltversion.in. + +# serial 3017 ltversion.m4 +# This file is part of GNU Libtool + +m4_define([LT_PACKAGE_VERSION], [2.2.6b]) +m4_define([LT_PACKAGE_REVISION], [1.3017]) + +AC_DEFUN([LTVERSION_VERSION], +[macro_version='2.2.6b' +macro_revision='1.3017' +_LT_DECL(, macro_version, 0, [Which release of libtool.m4 was used?]) +_LT_DECL(, macro_revision, 0) +]) + +# lt~obsolete.m4 -- aclocal satisfying obsolete definitions. -*-Autoconf-*- +# +# Copyright (C) 2004, 2005, 2007 Free Software Foundation, Inc. +# Written by Scott James Remnant, 2004. +# +# This file is free software; the Free Software Foundation gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. + +# serial 4 lt~obsolete.m4 + +# These exist entirely to fool aclocal when bootstrapping libtool. +# +# In the past libtool.m4 has provided macros via AC_DEFUN (or AU_DEFUN) +# which have later been changed to m4_define as they aren't part of the +# exported API, or moved to Autoconf or Automake where they belong. +# +# The trouble is, aclocal is a bit thick. It'll see the old AC_DEFUN +# in /usr/share/aclocal/libtool.m4 and remember it, then when it sees us +# using a macro with the same name in our local m4/libtool.m4 it'll +# pull the old libtool.m4 in (it doesn't see our shiny new m4_define +# and doesn't know about Autoconf macros at all.) +# +# So we provide this file, which has a silly filename so it's always +# included after everything else. This provides aclocal with the +# AC_DEFUNs it wants, but when m4 processes it, it doesn't do anything +# because those macros already exist, or will be overwritten later. +# We use AC_DEFUN over AU_DEFUN for compatibility with aclocal-1.6. +# +# Anytime we withdraw an AC_DEFUN or AU_DEFUN, remember to add it here. +# Yes, that means every name once taken will need to remain here until +# we give up compatibility with versions before 1.7, at which point +# we need to keep only those names which we still refer to. + +# This is to help aclocal find these macros, as it can't see m4_define. +AC_DEFUN([LTOBSOLETE_VERSION], [m4_if([1])]) + +m4_ifndef([AC_LIBTOOL_LINKER_OPTION], [AC_DEFUN([AC_LIBTOOL_LINKER_OPTION])]) +m4_ifndef([AC_PROG_EGREP], [AC_DEFUN([AC_PROG_EGREP])]) +m4_ifndef([_LT_AC_PROG_ECHO_BACKSLASH], [AC_DEFUN([_LT_AC_PROG_ECHO_BACKSLASH])]) +m4_ifndef([_LT_AC_SHELL_INIT], [AC_DEFUN([_LT_AC_SHELL_INIT])]) +m4_ifndef([_LT_AC_SYS_LIBPATH_AIX], [AC_DEFUN([_LT_AC_SYS_LIBPATH_AIX])]) +m4_ifndef([_LT_PROG_LTMAIN], [AC_DEFUN([_LT_PROG_LTMAIN])]) +m4_ifndef([_LT_AC_TAGVAR], [AC_DEFUN([_LT_AC_TAGVAR])]) +m4_ifndef([AC_LTDL_ENABLE_INSTALL], [AC_DEFUN([AC_LTDL_ENABLE_INSTALL])]) +m4_ifndef([AC_LTDL_PREOPEN], [AC_DEFUN([AC_LTDL_PREOPEN])]) +m4_ifndef([_LT_AC_SYS_COMPILER], [AC_DEFUN([_LT_AC_SYS_COMPILER])]) +m4_ifndef([_LT_AC_LOCK], [AC_DEFUN([_LT_AC_LOCK])]) +m4_ifndef([AC_LIBTOOL_SYS_OLD_ARCHIVE], [AC_DEFUN([AC_LIBTOOL_SYS_OLD_ARCHIVE])]) +m4_ifndef([_LT_AC_TRY_DLOPEN_SELF], [AC_DEFUN([_LT_AC_TRY_DLOPEN_SELF])]) +m4_ifndef([AC_LIBTOOL_PROG_CC_C_O], [AC_DEFUN([AC_LIBTOOL_PROG_CC_C_O])]) +m4_ifndef([AC_LIBTOOL_SYS_HARD_LINK_LOCKS], [AC_DEFUN([AC_LIBTOOL_SYS_HARD_LINK_LOCKS])]) +m4_ifndef([AC_LIBTOOL_OBJDIR], [AC_DEFUN([AC_LIBTOOL_OBJDIR])]) +m4_ifndef([AC_LTDL_OBJDIR], [AC_DEFUN([AC_LTDL_OBJDIR])]) +m4_ifndef([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH], [AC_DEFUN([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH])]) +m4_ifndef([AC_LIBTOOL_SYS_LIB_STRIP], [AC_DEFUN([AC_LIBTOOL_SYS_LIB_STRIP])]) +m4_ifndef([AC_PATH_MAGIC], [AC_DEFUN([AC_PATH_MAGIC])]) +m4_ifndef([AC_PROG_LD_GNU], [AC_DEFUN([AC_PROG_LD_GNU])]) +m4_ifndef([AC_PROG_LD_RELOAD_FLAG], [AC_DEFUN([AC_PROG_LD_RELOAD_FLAG])]) +m4_ifndef([AC_DEPLIBS_CHECK_METHOD], [AC_DEFUN([AC_DEPLIBS_CHECK_METHOD])]) +m4_ifndef([AC_LIBTOOL_PROG_COMPILER_NO_RTTI], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_NO_RTTI])]) +m4_ifndef([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE], [AC_DEFUN([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE])]) +m4_ifndef([AC_LIBTOOL_PROG_COMPILER_PIC], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_PIC])]) +m4_ifndef([AC_LIBTOOL_PROG_LD_SHLIBS], [AC_DEFUN([AC_LIBTOOL_PROG_LD_SHLIBS])]) +m4_ifndef([AC_LIBTOOL_POSTDEP_PREDEP], [AC_DEFUN([AC_LIBTOOL_POSTDEP_PREDEP])]) +m4_ifndef([LT_AC_PROG_EGREP], [AC_DEFUN([LT_AC_PROG_EGREP])]) +m4_ifndef([LT_AC_PROG_SED], [AC_DEFUN([LT_AC_PROG_SED])]) +m4_ifndef([_LT_CC_BASENAME], [AC_DEFUN([_LT_CC_BASENAME])]) +m4_ifndef([_LT_COMPILER_BOILERPLATE], [AC_DEFUN([_LT_COMPILER_BOILERPLATE])]) +m4_ifndef([_LT_LINKER_BOILERPLATE], [AC_DEFUN([_LT_LINKER_BOILERPLATE])]) +m4_ifndef([_AC_PROG_LIBTOOL], [AC_DEFUN([_AC_PROG_LIBTOOL])]) +m4_ifndef([AC_LIBTOOL_SETUP], [AC_DEFUN([AC_LIBTOOL_SETUP])]) +m4_ifndef([_LT_AC_CHECK_DLFCN], [AC_DEFUN([_LT_AC_CHECK_DLFCN])]) +m4_ifndef([AC_LIBTOOL_SYS_DYNAMIC_LINKER], [AC_DEFUN([AC_LIBTOOL_SYS_DYNAMIC_LINKER])]) +m4_ifndef([_LT_AC_TAGCONFIG], [AC_DEFUN([_LT_AC_TAGCONFIG])]) +m4_ifndef([AC_DISABLE_FAST_INSTALL], [AC_DEFUN([AC_DISABLE_FAST_INSTALL])]) +m4_ifndef([_LT_AC_LANG_CXX], [AC_DEFUN([_LT_AC_LANG_CXX])]) +m4_ifndef([_LT_AC_LANG_F77], [AC_DEFUN([_LT_AC_LANG_F77])]) +m4_ifndef([_LT_AC_LANG_GCJ], [AC_DEFUN([_LT_AC_LANG_GCJ])]) +m4_ifndef([AC_LIBTOOL_RC], [AC_DEFUN([AC_LIBTOOL_RC])]) +m4_ifndef([AC_LIBTOOL_LANG_C_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_C_CONFIG])]) +m4_ifndef([_LT_AC_LANG_C_CONFIG], [AC_DEFUN([_LT_AC_LANG_C_CONFIG])]) +m4_ifndef([AC_LIBTOOL_LANG_CXX_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_CXX_CONFIG])]) +m4_ifndef([_LT_AC_LANG_CXX_CONFIG], [AC_DEFUN([_LT_AC_LANG_CXX_CONFIG])]) +m4_ifndef([AC_LIBTOOL_LANG_F77_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_F77_CONFIG])]) +m4_ifndef([_LT_AC_LANG_F77_CONFIG], [AC_DEFUN([_LT_AC_LANG_F77_CONFIG])]) +m4_ifndef([AC_LIBTOOL_LANG_GCJ_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_GCJ_CONFIG])]) +m4_ifndef([_LT_AC_LANG_GCJ_CONFIG], [AC_DEFUN([_LT_AC_LANG_GCJ_CONFIG])]) +m4_ifndef([AC_LIBTOOL_LANG_RC_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_RC_CONFIG])]) +m4_ifndef([_LT_AC_LANG_RC_CONFIG], [AC_DEFUN([_LT_AC_LANG_RC_CONFIG])]) +m4_ifndef([AC_LIBTOOL_CONFIG], [AC_DEFUN([AC_LIBTOOL_CONFIG])]) +m4_ifndef([_LT_AC_FILE_LTDLL_C], [AC_DEFUN([_LT_AC_FILE_LTDLL_C])]) + +# Copyright (C) 2002, 2003, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# AM_AUTOMAKE_VERSION(VERSION) +# ---------------------------- +# Automake X.Y traces this macro to ensure aclocal.m4 has been +# generated from the m4 files accompanying Automake X.Y. +# (This private macro should not be called outside this file.) +AC_DEFUN([AM_AUTOMAKE_VERSION], +[am__api_version='1.11' +dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to +dnl require some minimum version. Point them to the right macro. +m4_if([$1], [1.11], [], + [AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl +]) + +# _AM_AUTOCONF_VERSION(VERSION) +# ----------------------------- +# aclocal traces this macro to find the Autoconf version. +# This is a private macro too. Using m4_define simplifies +# the logic in aclocal, which can simply ignore this definition. +m4_define([_AM_AUTOCONF_VERSION], []) + +# AM_SET_CURRENT_AUTOMAKE_VERSION +# ------------------------------- +# Call AM_AUTOMAKE_VERSION and AM_AUTOMAKE_VERSION so they can be traced. +# This function is AC_REQUIREd by AM_INIT_AUTOMAKE. +AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION], +[AM_AUTOMAKE_VERSION([1.11])dnl +m4_ifndef([AC_AUTOCONF_VERSION], + [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl +_AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))]) + +# AM_AUX_DIR_EXPAND -*- Autoconf -*- + +# Copyright (C) 2001, 2003, 2005 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# For projects using AC_CONFIG_AUX_DIR([foo]), Autoconf sets +# $ac_aux_dir to `$srcdir/foo'. In other projects, it is set to +# `$srcdir', `$srcdir/..', or `$srcdir/../..'. +# +# Of course, Automake must honor this variable whenever it calls a +# tool from the auxiliary directory. The problem is that $srcdir (and +# therefore $ac_aux_dir as well) can be either absolute or relative, +# depending on how configure is run. This is pretty annoying, since +# it makes $ac_aux_dir quite unusable in subdirectories: in the top +# source directory, any form will work fine, but in subdirectories a +# relative path needs to be adjusted first. +# +# $ac_aux_dir/missing +# fails when called from a subdirectory if $ac_aux_dir is relative +# $top_srcdir/$ac_aux_dir/missing +# fails if $ac_aux_dir is absolute, +# fails when called from a subdirectory in a VPATH build with +# a relative $ac_aux_dir +# +# The reason of the latter failure is that $top_srcdir and $ac_aux_dir +# are both prefixed by $srcdir. In an in-source build this is usually +# harmless because $srcdir is `.', but things will broke when you +# start a VPATH build or use an absolute $srcdir. +# +# So we could use something similar to $top_srcdir/$ac_aux_dir/missing, +# iff we strip the leading $srcdir from $ac_aux_dir. That would be: +# am_aux_dir='\$(top_srcdir)/'`expr "$ac_aux_dir" : "$srcdir//*\(.*\)"` +# and then we would define $MISSING as +# MISSING="\${SHELL} $am_aux_dir/missing" +# This will work as long as MISSING is not called from configure, because +# unfortunately $(top_srcdir) has no meaning in configure. +# However there are other variables, like CC, which are often used in +# configure, and could therefore not use this "fixed" $ac_aux_dir. +# +# Another solution, used here, is to always expand $ac_aux_dir to an +# absolute PATH. The drawback is that using absolute paths prevent a +# configured tree to be moved without reconfiguration. + +AC_DEFUN([AM_AUX_DIR_EXPAND], +[dnl Rely on autoconf to set up CDPATH properly. +AC_PREREQ([2.50])dnl +# expand $ac_aux_dir to an absolute path +am_aux_dir=`cd $ac_aux_dir && pwd` +]) + +# AM_CONDITIONAL -*- Autoconf -*- + +# Copyright (C) 1997, 2000, 2001, 2003, 2004, 2005, 2006, 2008 +# Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# serial 9 + +# AM_CONDITIONAL(NAME, SHELL-CONDITION) +# ------------------------------------- +# Define a conditional. +AC_DEFUN([AM_CONDITIONAL], +[AC_PREREQ(2.52)dnl + ifelse([$1], [TRUE], [AC_FATAL([$0: invalid condition: $1])], + [$1], [FALSE], [AC_FATAL([$0: invalid condition: $1])])dnl +AC_SUBST([$1_TRUE])dnl +AC_SUBST([$1_FALSE])dnl +_AM_SUBST_NOTMAKE([$1_TRUE])dnl +_AM_SUBST_NOTMAKE([$1_FALSE])dnl +m4_define([_AM_COND_VALUE_$1], [$2])dnl +if $2; then + $1_TRUE= + $1_FALSE='#' +else + $1_TRUE='#' + $1_FALSE= +fi +AC_CONFIG_COMMANDS_PRE( +[if test -z "${$1_TRUE}" && test -z "${$1_FALSE}"; then + AC_MSG_ERROR([[conditional "$1" was never defined. +Usually this means the macro was only invoked conditionally.]]) +fi])]) + +# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2009 +# Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# serial 10 + +# There are a few dirty hacks below to avoid letting `AC_PROG_CC' be +# written in clear, in which case automake, when reading aclocal.m4, +# will think it sees a *use*, and therefore will trigger all it's +# C support machinery. Also note that it means that autoscan, seeing +# CC etc. in the Makefile, will ask for an AC_PROG_CC use... + + +# _AM_DEPENDENCIES(NAME) +# ---------------------- +# See how the compiler implements dependency checking. +# NAME is "CC", "CXX", "GCJ", or "OBJC". +# We try a few techniques and use that to set a single cache variable. +# +# We don't AC_REQUIRE the corresponding AC_PROG_CC since the latter was +# modified to invoke _AM_DEPENDENCIES(CC); we would have a circular +# dependency, and given that the user is not expected to run this macro, +# just rely on AC_PROG_CC. +AC_DEFUN([_AM_DEPENDENCIES], +[AC_REQUIRE([AM_SET_DEPDIR])dnl +AC_REQUIRE([AM_OUTPUT_DEPENDENCY_COMMANDS])dnl +AC_REQUIRE([AM_MAKE_INCLUDE])dnl +AC_REQUIRE([AM_DEP_TRACK])dnl + +ifelse([$1], CC, [depcc="$CC" am_compiler_list=], + [$1], CXX, [depcc="$CXX" am_compiler_list=], + [$1], OBJC, [depcc="$OBJC" am_compiler_list='gcc3 gcc'], + [$1], UPC, [depcc="$UPC" am_compiler_list=], + [$1], GCJ, [depcc="$GCJ" am_compiler_list='gcc3 gcc'], + [depcc="$$1" am_compiler_list=]) + +AC_CACHE_CHECK([dependency style of $depcc], + [am_cv_$1_dependencies_compiler_type], +[if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then + # We make a subdir and do the tests there. Otherwise we can end up + # making bogus files that we don't know about and never remove. For + # instance it was reported that on HP-UX the gcc test will end up + # making a dummy file named `D' -- because `-MD' means `put the output + # in D'. + mkdir conftest.dir + # Copy depcomp to subdir because otherwise we won't find it if we're + # using a relative directory. + cp "$am_depcomp" conftest.dir + cd conftest.dir + # We will build objects and dependencies in a subdirectory because + # it helps to detect inapplicable dependency modes. For instance + # both Tru64's cc and ICC support -MD to output dependencies as a + # side effect of compilation, but ICC will put the dependencies in + # the current directory while Tru64 will put them in the object + # directory. + mkdir sub + + am_cv_$1_dependencies_compiler_type=none + if test "$am_compiler_list" = ""; then + am_compiler_list=`sed -n ['s/^#*\([a-zA-Z0-9]*\))$/\1/p'] < ./depcomp` + fi + am__universal=false + m4_case([$1], [CC], + [case " $depcc " in #( + *\ -arch\ *\ -arch\ *) am__universal=true ;; + esac], + [CXX], + [case " $depcc " in #( + *\ -arch\ *\ -arch\ *) am__universal=true ;; + esac]) + + for depmode in $am_compiler_list; do + # Setup a source with many dependencies, because some compilers + # like to wrap large dependency lists on column 80 (with \), and + # we should not choose a depcomp mode which is confused by this. + # + # We need to recreate these files for each test, as the compiler may + # overwrite some of them when testing with obscure command lines. + # This happens at least with the AIX C compiler. + : > sub/conftest.c + for i in 1 2 3 4 5 6; do + echo '#include "conftst'$i'.h"' >> sub/conftest.c + # Using `: > sub/conftst$i.h' creates only sub/conftst1.h with + # Solaris 8's {/usr,}/bin/sh. + touch sub/conftst$i.h + done + echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf + + # We check with `-c' and `-o' for the sake of the "dashmstdout" + # mode. It turns out that the SunPro C++ compiler does not properly + # handle `-M -o', and we need to detect this. Also, some Intel + # versions had trouble with output in subdirs + am__obj=sub/conftest.${OBJEXT-o} + am__minus_obj="-o $am__obj" + case $depmode in + gcc) + # This depmode causes a compiler race in universal mode. + test "$am__universal" = false || continue + ;; + nosideeffect) + # after this tag, mechanisms are not by side-effect, so they'll + # only be used when explicitly requested + if test "x$enable_dependency_tracking" = xyes; then + continue + else + break + fi + ;; + msvisualcpp | msvcmsys) + # This compiler won't grok `-c -o', but also, the minuso test has + # not run yet. These depmodes are late enough in the game, and + # so weak that their functioning should not be impacted. + am__obj=conftest.${OBJEXT-o} + am__minus_obj= + ;; + none) break ;; + esac + if depmode=$depmode \ + source=sub/conftest.c object=$am__obj \ + depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \ + $SHELL ./depcomp $depcc -c $am__minus_obj sub/conftest.c \ + >/dev/null 2>conftest.err && + grep sub/conftst1.h sub/conftest.Po > /dev/null 2>&1 && + grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 && + grep $am__obj sub/conftest.Po > /dev/null 2>&1 && + ${MAKE-make} -s -f confmf > /dev/null 2>&1; then + # icc doesn't choke on unknown options, it will just issue warnings + # or remarks (even with -Werror). So we grep stderr for any message + # that says an option was ignored or not supported. + # When given -MP, icc 7.0 and 7.1 complain thusly: + # icc: Command line warning: ignoring option '-M'; no argument required + # The diagnosis changed in icc 8.0: + # icc: Command line remark: option '-MP' not supported + if (grep 'ignoring option' conftest.err || + grep 'not supported' conftest.err) >/dev/null 2>&1; then :; else + am_cv_$1_dependencies_compiler_type=$depmode + break + fi + fi + done + + cd .. + rm -rf conftest.dir +else + am_cv_$1_dependencies_compiler_type=none +fi +]) +AC_SUBST([$1DEPMODE], [depmode=$am_cv_$1_dependencies_compiler_type]) +AM_CONDITIONAL([am__fastdep$1], [ + test "x$enable_dependency_tracking" != xno \ + && test "$am_cv_$1_dependencies_compiler_type" = gcc3]) +]) + + +# AM_SET_DEPDIR +# ------------- +# Choose a directory name for dependency files. +# This macro is AC_REQUIREd in _AM_DEPENDENCIES +AC_DEFUN([AM_SET_DEPDIR], +[AC_REQUIRE([AM_SET_LEADING_DOT])dnl +AC_SUBST([DEPDIR], ["${am__leading_dot}deps"])dnl +]) + + +# AM_DEP_TRACK +# ------------ +AC_DEFUN([AM_DEP_TRACK], +[AC_ARG_ENABLE(dependency-tracking, +[ --disable-dependency-tracking speeds up one-time build + --enable-dependency-tracking do not reject slow dependency extractors]) +if test "x$enable_dependency_tracking" != xno; then + am_depcomp="$ac_aux_dir/depcomp" + AMDEPBACKSLASH='\' +fi +AM_CONDITIONAL([AMDEP], [test "x$enable_dependency_tracking" != xno]) +AC_SUBST([AMDEPBACKSLASH])dnl +_AM_SUBST_NOTMAKE([AMDEPBACKSLASH])dnl +]) + +# Generate code to set up dependency tracking. -*- Autoconf -*- + +# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2008 +# Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +#serial 5 + +# _AM_OUTPUT_DEPENDENCY_COMMANDS +# ------------------------------ +AC_DEFUN([_AM_OUTPUT_DEPENDENCY_COMMANDS], +[{ + # Autoconf 2.62 quotes --file arguments for eval, but not when files + # are listed without --file. Let's play safe and only enable the eval + # if we detect the quoting. + case $CONFIG_FILES in + *\'*) eval set x "$CONFIG_FILES" ;; + *) set x $CONFIG_FILES ;; + esac + shift + for mf + do + # Strip MF so we end up with the name of the file. + mf=`echo "$mf" | sed -e 's/:.*$//'` + # Check whether this is an Automake generated Makefile or not. + # We used to match only the files named `Makefile.in', but + # some people rename them; so instead we look at the file content. + # Grep'ing the first line is not enough: some people post-process + # each Makefile.in and add a new line on top of each file to say so. + # Grep'ing the whole file is not good either: AIX grep has a line + # limit of 2048, but all sed's we know have understand at least 4000. + if sed -n 's,^#.*generated by automake.*,X,p' "$mf" | grep X >/dev/null 2>&1; then + dirpart=`AS_DIRNAME("$mf")` + else + continue + fi + # Extract the definition of DEPDIR, am__include, and am__quote + # from the Makefile without running `make'. + DEPDIR=`sed -n 's/^DEPDIR = //p' < "$mf"` + test -z "$DEPDIR" && continue + am__include=`sed -n 's/^am__include = //p' < "$mf"` + test -z "am__include" && continue + am__quote=`sed -n 's/^am__quote = //p' < "$mf"` + # When using ansi2knr, U may be empty or an underscore; expand it + U=`sed -n 's/^U = //p' < "$mf"` + # Find all dependency output files, they are included files with + # $(DEPDIR) in their names. We invoke sed twice because it is the + # simplest approach to changing $(DEPDIR) to its actual value in the + # expansion. + for file in `sed -n " + s/^$am__include $am__quote\(.*(DEPDIR).*\)$am__quote"'$/\1/p' <"$mf" | \ + sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g' -e 's/\$U/'"$U"'/g'`; do + # Make sure the directory exists. + test -f "$dirpart/$file" && continue + fdir=`AS_DIRNAME(["$file"])` + AS_MKDIR_P([$dirpart/$fdir]) + # echo "creating $dirpart/$file" + echo '# dummy' > "$dirpart/$file" + done + done +} +])# _AM_OUTPUT_DEPENDENCY_COMMANDS + + +# AM_OUTPUT_DEPENDENCY_COMMANDS +# ----------------------------- +# This macro should only be invoked once -- use via AC_REQUIRE. +# +# This code is only required when automatic dependency tracking +# is enabled. FIXME. This creates each `.P' file that we will +# need in order to bootstrap the dependency handling code. +AC_DEFUN([AM_OUTPUT_DEPENDENCY_COMMANDS], +[AC_CONFIG_COMMANDS([depfiles], + [test x"$AMDEP_TRUE" != x"" || _AM_OUTPUT_DEPENDENCY_COMMANDS], + [AMDEP_TRUE="$AMDEP_TRUE" ac_aux_dir="$ac_aux_dir"]) +]) + +# Copyright (C) 1996, 1997, 2000, 2001, 2003, 2005 +# Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# serial 8 + +# AM_CONFIG_HEADER is obsolete. It has been replaced by AC_CONFIG_HEADERS. +AU_DEFUN([AM_CONFIG_HEADER], [AC_CONFIG_HEADERS($@)]) + +# Do all the work for Automake. -*- Autoconf -*- + +# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, +# 2005, 2006, 2008, 2009 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# serial 16 + +# This macro actually does too much. Some checks are only needed if +# your package does certain things. But this isn't really a big deal. + +# AM_INIT_AUTOMAKE(PACKAGE, VERSION, [NO-DEFINE]) +# AM_INIT_AUTOMAKE([OPTIONS]) +# ----------------------------------------------- +# The call with PACKAGE and VERSION arguments is the old style +# call (pre autoconf-2.50), which is being phased out. PACKAGE +# and VERSION should now be passed to AC_INIT and removed from +# the call to AM_INIT_AUTOMAKE. +# We support both call styles for the transition. After +# the next Automake release, Autoconf can make the AC_INIT +# arguments mandatory, and then we can depend on a new Autoconf +# release and drop the old call support. +AC_DEFUN([AM_INIT_AUTOMAKE], +[AC_PREREQ([2.62])dnl +dnl Autoconf wants to disallow AM_ names. We explicitly allow +dnl the ones we care about. +m4_pattern_allow([^AM_[A-Z]+FLAGS$])dnl +AC_REQUIRE([AM_SET_CURRENT_AUTOMAKE_VERSION])dnl +AC_REQUIRE([AC_PROG_INSTALL])dnl +if test "`cd $srcdir && pwd`" != "`pwd`"; then + # Use -I$(srcdir) only when $(srcdir) != ., so that make's output + # is not polluted with repeated "-I." + AC_SUBST([am__isrc], [' -I$(srcdir)'])_AM_SUBST_NOTMAKE([am__isrc])dnl + # test to see if srcdir already configured + if test -f $srcdir/config.status; then + AC_MSG_ERROR([source directory already configured; run "make distclean" there first]) + fi +fi + +# test whether we have cygpath +if test -z "$CYGPATH_W"; then + if (cygpath --version) >/dev/null 2>/dev/null; then + CYGPATH_W='cygpath -w' + else + CYGPATH_W=echo + fi +fi +AC_SUBST([CYGPATH_W]) + +# Define the identity of the package. +dnl Distinguish between old-style and new-style calls. +m4_ifval([$2], +[m4_ifval([$3], [_AM_SET_OPTION([no-define])])dnl + AC_SUBST([PACKAGE], [$1])dnl + AC_SUBST([VERSION], [$2])], +[_AM_SET_OPTIONS([$1])dnl +dnl Diagnose old-style AC_INIT with new-style AM_AUTOMAKE_INIT. +m4_if(m4_ifdef([AC_PACKAGE_NAME], 1)m4_ifdef([AC_PACKAGE_VERSION], 1), 11,, + [m4_fatal([AC_INIT should be called with package and version arguments])])dnl + AC_SUBST([PACKAGE], ['AC_PACKAGE_TARNAME'])dnl + AC_SUBST([VERSION], ['AC_PACKAGE_VERSION'])])dnl + +_AM_IF_OPTION([no-define],, +[AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of package]) + AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version number of package])])dnl + +# Some tools Automake needs. +AC_REQUIRE([AM_SANITY_CHECK])dnl +AC_REQUIRE([AC_ARG_PROGRAM])dnl +AM_MISSING_PROG(ACLOCAL, aclocal-${am__api_version}) +AM_MISSING_PROG(AUTOCONF, autoconf) +AM_MISSING_PROG(AUTOMAKE, automake-${am__api_version}) +AM_MISSING_PROG(AUTOHEADER, autoheader) +AM_MISSING_PROG(MAKEINFO, makeinfo) +AC_REQUIRE([AM_PROG_INSTALL_SH])dnl +AC_REQUIRE([AM_PROG_INSTALL_STRIP])dnl +AC_REQUIRE([AM_PROG_MKDIR_P])dnl +# We need awk for the "check" target. The system "awk" is bad on +# some platforms. +AC_REQUIRE([AC_PROG_AWK])dnl +AC_REQUIRE([AC_PROG_MAKE_SET])dnl +AC_REQUIRE([AM_SET_LEADING_DOT])dnl +_AM_IF_OPTION([tar-ustar], [_AM_PROG_TAR([ustar])], + [_AM_IF_OPTION([tar-pax], [_AM_PROG_TAR([pax])], + [_AM_PROG_TAR([v7])])]) +_AM_IF_OPTION([no-dependencies],, +[AC_PROVIDE_IFELSE([AC_PROG_CC], + [_AM_DEPENDENCIES(CC)], + [define([AC_PROG_CC], + defn([AC_PROG_CC])[_AM_DEPENDENCIES(CC)])])dnl +AC_PROVIDE_IFELSE([AC_PROG_CXX], + [_AM_DEPENDENCIES(CXX)], + [define([AC_PROG_CXX], + defn([AC_PROG_CXX])[_AM_DEPENDENCIES(CXX)])])dnl +AC_PROVIDE_IFELSE([AC_PROG_OBJC], + [_AM_DEPENDENCIES(OBJC)], + [define([AC_PROG_OBJC], + defn([AC_PROG_OBJC])[_AM_DEPENDENCIES(OBJC)])])dnl +]) +_AM_IF_OPTION([silent-rules], [AC_REQUIRE([AM_SILENT_RULES])])dnl +dnl The `parallel-tests' driver may need to know about EXEEXT, so add the +dnl `am__EXEEXT' conditional if _AM_COMPILER_EXEEXT was seen. This macro +dnl is hooked onto _AC_COMPILER_EXEEXT early, see below. +AC_CONFIG_COMMANDS_PRE(dnl +[m4_provide_if([_AM_COMPILER_EXEEXT], + [AM_CONDITIONAL([am__EXEEXT], [test -n "$EXEEXT"])])])dnl +]) + +dnl Hook into `_AC_COMPILER_EXEEXT' early to learn its expansion. Do not +dnl add the conditional right here, as _AC_COMPILER_EXEEXT may be further +dnl mangled by Autoconf and run in a shell conditional statement. +m4_define([_AC_COMPILER_EXEEXT], +m4_defn([_AC_COMPILER_EXEEXT])[m4_provide([_AM_COMPILER_EXEEXT])]) + + +# When config.status generates a header, we must update the stamp-h file. +# This file resides in the same directory as the config header +# that is generated. The stamp files are numbered to have different names. + +# Autoconf calls _AC_AM_CONFIG_HEADER_HOOK (when defined) in the +# loop where config.status creates the headers, so we can generate +# our stamp files there. +AC_DEFUN([_AC_AM_CONFIG_HEADER_HOOK], +[# Compute $1's index in $config_headers. +_am_arg=$1 +_am_stamp_count=1 +for _am_header in $config_headers :; do + case $_am_header in + $_am_arg | $_am_arg:* ) + break ;; + * ) + _am_stamp_count=`expr $_am_stamp_count + 1` ;; + esac +done +echo "timestamp for $_am_arg" >`AS_DIRNAME(["$_am_arg"])`/stamp-h[]$_am_stamp_count]) + +# Copyright (C) 2001, 2003, 2005, 2008 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# AM_PROG_INSTALL_SH +# ------------------ +# Define $install_sh. +AC_DEFUN([AM_PROG_INSTALL_SH], +[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl +if test x"${install_sh}" != xset; then + case $am_aux_dir in + *\ * | *\ *) + install_sh="\${SHELL} '$am_aux_dir/install-sh'" ;; + *) + install_sh="\${SHELL} $am_aux_dir/install-sh" + esac +fi +AC_SUBST(install_sh)]) + +# Copyright (C) 2003, 2005 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# serial 2 + +# Check whether the underlying file-system supports filenames +# with a leading dot. For instance MS-DOS doesn't. +AC_DEFUN([AM_SET_LEADING_DOT], +[rm -rf .tst 2>/dev/null +mkdir .tst 2>/dev/null +if test -d .tst; then + am__leading_dot=. +else + am__leading_dot=_ +fi +rmdir .tst 2>/dev/null +AC_SUBST([am__leading_dot])]) + +# Add --enable-maintainer-mode option to configure. -*- Autoconf -*- +# From Jim Meyering + +# Copyright (C) 1996, 1998, 2000, 2001, 2002, 2003, 2004, 2005, 2008 +# Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# serial 5 + +# AM_MAINTAINER_MODE([DEFAULT-MODE]) +# ---------------------------------- +# Control maintainer-specific portions of Makefiles. +# Default is to disable them, unless `enable' is passed literally. +# For symmetry, `disable' may be passed as well. Anyway, the user +# can override the default with the --enable/--disable switch. +AC_DEFUN([AM_MAINTAINER_MODE], +[m4_case(m4_default([$1], [disable]), + [enable], [m4_define([am_maintainer_other], [disable])], + [disable], [m4_define([am_maintainer_other], [enable])], + [m4_define([am_maintainer_other], [enable]) + m4_warn([syntax], [unexpected argument to AM@&t@_MAINTAINER_MODE: $1])]) +AC_MSG_CHECKING([whether to am_maintainer_other maintainer-specific portions of Makefiles]) + dnl maintainer-mode's default is 'disable' unless 'enable' is passed + AC_ARG_ENABLE([maintainer-mode], +[ --][am_maintainer_other][-maintainer-mode am_maintainer_other make rules and dependencies not useful + (and sometimes confusing) to the casual installer], + [USE_MAINTAINER_MODE=$enableval], + [USE_MAINTAINER_MODE=]m4_if(am_maintainer_other, [enable], [no], [yes])) + AC_MSG_RESULT([$USE_MAINTAINER_MODE]) + AM_CONDITIONAL([MAINTAINER_MODE], [test $USE_MAINTAINER_MODE = yes]) + MAINT=$MAINTAINER_MODE_TRUE + AC_SUBST([MAINT])dnl +] +) + +AU_DEFUN([jm_MAINTAINER_MODE], [AM_MAINTAINER_MODE]) + +# Check to see how 'make' treats includes. -*- Autoconf -*- + +# Copyright (C) 2001, 2002, 2003, 2005, 2009 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# serial 4 + +# AM_MAKE_INCLUDE() +# ----------------- +# Check to see how make treats includes. +AC_DEFUN([AM_MAKE_INCLUDE], +[am_make=${MAKE-make} +cat > confinc << 'END' +am__doit: + @echo this is the am__doit target +.PHONY: am__doit +END +# If we don't find an include directive, just comment out the code. +AC_MSG_CHECKING([for style of include used by $am_make]) +am__include="#" +am__quote= +_am_result=none +# First try GNU make style include. +echo "include confinc" > confmf +# Ignore all kinds of additional output from `make'. +case `$am_make -s -f confmf 2> /dev/null` in #( +*the\ am__doit\ target*) + am__include=include + am__quote= + _am_result=GNU + ;; +esac +# Now try BSD make style include. +if test "$am__include" = "#"; then + echo '.include "confinc"' > confmf + case `$am_make -s -f confmf 2> /dev/null` in #( + *the\ am__doit\ target*) + am__include=.include + am__quote="\"" + _am_result=BSD + ;; + esac +fi +AC_SUBST([am__include]) +AC_SUBST([am__quote]) +AC_MSG_RESULT([$_am_result]) +rm -f confinc confmf +]) + +# Fake the existence of programs that GNU maintainers use. -*- Autoconf -*- + +# Copyright (C) 1997, 1999, 2000, 2001, 2003, 2004, 2005, 2008 +# Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# serial 6 + +# AM_MISSING_PROG(NAME, PROGRAM) +# ------------------------------ +AC_DEFUN([AM_MISSING_PROG], +[AC_REQUIRE([AM_MISSING_HAS_RUN]) +$1=${$1-"${am_missing_run}$2"} +AC_SUBST($1)]) + + +# AM_MISSING_HAS_RUN +# ------------------ +# Define MISSING if not defined so far and test if it supports --run. +# If it does, set am_missing_run to use it, otherwise, to nothing. +AC_DEFUN([AM_MISSING_HAS_RUN], +[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl +AC_REQUIRE_AUX_FILE([missing])dnl +if test x"${MISSING+set}" != xset; then + case $am_aux_dir in + *\ * | *\ *) + MISSING="\${SHELL} \"$am_aux_dir/missing\"" ;; + *) + MISSING="\${SHELL} $am_aux_dir/missing" ;; + esac +fi +# Use eval to expand $SHELL +if eval "$MISSING --run true"; then + am_missing_run="$MISSING --run " +else + am_missing_run= + AC_MSG_WARN([`missing' script is too old or missing]) +fi +]) + +# Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# AM_PROG_MKDIR_P +# --------------- +# Check for `mkdir -p'. +AC_DEFUN([AM_PROG_MKDIR_P], +[AC_PREREQ([2.60])dnl +AC_REQUIRE([AC_PROG_MKDIR_P])dnl +dnl Automake 1.8 to 1.9.6 used to define mkdir_p. We now use MKDIR_P, +dnl while keeping a definition of mkdir_p for backward compatibility. +dnl @MKDIR_P@ is magic: AC_OUTPUT adjusts its value for each Makefile. +dnl However we cannot define mkdir_p as $(MKDIR_P) for the sake of +dnl Makefile.ins that do not define MKDIR_P, so we do our own +dnl adjustment using top_builddir (which is defined more often than +dnl MKDIR_P). +AC_SUBST([mkdir_p], ["$MKDIR_P"])dnl +case $mkdir_p in + [[\\/$]]* | ?:[[\\/]]*) ;; + */*) mkdir_p="\$(top_builddir)/$mkdir_p" ;; +esac +]) + +# Helper functions for option handling. -*- Autoconf -*- + +# Copyright (C) 2001, 2002, 2003, 2005, 2008 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# serial 4 + +# _AM_MANGLE_OPTION(NAME) +# ----------------------- +AC_DEFUN([_AM_MANGLE_OPTION], +[[_AM_OPTION_]m4_bpatsubst($1, [[^a-zA-Z0-9_]], [_])]) + +# _AM_SET_OPTION(NAME) +# ------------------------------ +# Set option NAME. Presently that only means defining a flag for this option. +AC_DEFUN([_AM_SET_OPTION], +[m4_define(_AM_MANGLE_OPTION([$1]), 1)]) + +# _AM_SET_OPTIONS(OPTIONS) +# ---------------------------------- +# OPTIONS is a space-separated list of Automake options. +AC_DEFUN([_AM_SET_OPTIONS], +[m4_foreach_w([_AM_Option], [$1], [_AM_SET_OPTION(_AM_Option)])]) + +# _AM_IF_OPTION(OPTION, IF-SET, [IF-NOT-SET]) +# ------------------------------------------- +# Execute IF-SET if OPTION is set, IF-NOT-SET otherwise. +AC_DEFUN([_AM_IF_OPTION], +[m4_ifset(_AM_MANGLE_OPTION([$1]), [$2], [$3])]) + +# Check to make sure that the build environment is sane. -*- Autoconf -*- + +# Copyright (C) 1996, 1997, 2000, 2001, 2003, 2005, 2008 +# Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# serial 5 + +# AM_SANITY_CHECK +# --------------- +AC_DEFUN([AM_SANITY_CHECK], +[AC_MSG_CHECKING([whether build environment is sane]) +# Just in case +sleep 1 +echo timestamp > conftest.file +# Reject unsafe characters in $srcdir or the absolute working directory +# name. Accept space and tab only in the latter. +am_lf=' +' +case `pwd` in + *[[\\\"\#\$\&\'\`$am_lf]]*) + AC_MSG_ERROR([unsafe absolute working directory name]);; +esac +case $srcdir in + *[[\\\"\#\$\&\'\`$am_lf\ \ ]]*) + AC_MSG_ERROR([unsafe srcdir value: `$srcdir']);; +esac + +# Do `set' in a subshell so we don't clobber the current shell's +# arguments. Must try -L first in case configure is actually a +# symlink; some systems play weird games with the mod time of symlinks +# (eg FreeBSD returns the mod time of the symlink's containing +# directory). +if ( + set X `ls -Lt "$srcdir/configure" conftest.file 2> /dev/null` + if test "$[*]" = "X"; then + # -L didn't work. + set X `ls -t "$srcdir/configure" conftest.file` + fi + rm -f conftest.file + if test "$[*]" != "X $srcdir/configure conftest.file" \ + && test "$[*]" != "X conftest.file $srcdir/configure"; then + + # If neither matched, then we have a broken ls. This can happen + # if, for instance, CONFIG_SHELL is bash and it inherits a + # broken ls alias from the environment. This has actually + # happened. Such a system could not be considered "sane". + AC_MSG_ERROR([ls -t appears to fail. Make sure there is not a broken +alias in your environment]) + fi + + test "$[2]" = conftest.file + ) +then + # Ok. + : +else + AC_MSG_ERROR([newly created file is older than distributed files! +Check your system clock]) +fi +AC_MSG_RESULT(yes)]) + +# Copyright (C) 2001, 2003, 2005 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# AM_PROG_INSTALL_STRIP +# --------------------- +# One issue with vendor `install' (even GNU) is that you can't +# specify the program used to strip binaries. This is especially +# annoying in cross-compiling environments, where the build's strip +# is unlikely to handle the host's binaries. +# Fortunately install-sh will honor a STRIPPROG variable, so we +# always use install-sh in `make install-strip', and initialize +# STRIPPROG with the value of the STRIP variable (set by the user). +AC_DEFUN([AM_PROG_INSTALL_STRIP], +[AC_REQUIRE([AM_PROG_INSTALL_SH])dnl +# Installed binaries are usually stripped using `strip' when the user +# run `make install-strip'. However `strip' might not be the right +# tool to use in cross-compilation environments, therefore Automake +# will honor the `STRIP' environment variable to overrule this program. +dnl Don't test for $cross_compiling = yes, because it might be `maybe'. +if test "$cross_compiling" != no; then + AC_CHECK_TOOL([STRIP], [strip], :) +fi +INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s" +AC_SUBST([INSTALL_STRIP_PROGRAM])]) + +# Copyright (C) 2006, 2008 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# serial 2 + +# _AM_SUBST_NOTMAKE(VARIABLE) +# --------------------------- +# Prevent Automake from outputting VARIABLE = @VARIABLE@ in Makefile.in. +# This macro is traced by Automake. +AC_DEFUN([_AM_SUBST_NOTMAKE]) + +# AM_SUBST_NOTMAKE(VARIABLE) +# --------------------------- +# Public sister of _AM_SUBST_NOTMAKE. +AC_DEFUN([AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE($@)]) + +# Check how to create a tarball. -*- Autoconf -*- + +# Copyright (C) 2004, 2005 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# serial 2 + +# _AM_PROG_TAR(FORMAT) +# -------------------- +# Check how to create a tarball in format FORMAT. +# FORMAT should be one of `v7', `ustar', or `pax'. +# +# Substitute a variable $(am__tar) that is a command +# writing to stdout a FORMAT-tarball containing the directory +# $tardir. +# tardir=directory && $(am__tar) > result.tar +# +# Substitute a variable $(am__untar) that extract such +# a tarball read from stdin. +# $(am__untar) < result.tar +AC_DEFUN([_AM_PROG_TAR], +[# Always define AMTAR for backward compatibility. +AM_MISSING_PROG([AMTAR], [tar]) +m4_if([$1], [v7], + [am__tar='${AMTAR} chof - "$$tardir"'; am__untar='${AMTAR} xf -'], + [m4_case([$1], [ustar],, [pax],, + [m4_fatal([Unknown tar format])]) +AC_MSG_CHECKING([how to create a $1 tar archive]) +# Loop over all known methods to create a tar archive until one works. +_am_tools='gnutar m4_if([$1], [ustar], [plaintar]) pax cpio none' +_am_tools=${am_cv_prog_tar_$1-$_am_tools} +# Do not fold the above two line into one, because Tru64 sh and +# Solaris sh will not grok spaces in the rhs of `-'. +for _am_tool in $_am_tools +do + case $_am_tool in + gnutar) + for _am_tar in tar gnutar gtar; + do + AM_RUN_LOG([$_am_tar --version]) && break + done + am__tar="$_am_tar --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$$tardir"' + am__tar_="$_am_tar --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$tardir"' + am__untar="$_am_tar -xf -" + ;; + plaintar) + # Must skip GNU tar: if it does not support --format= it doesn't create + # ustar tarball either. + (tar --version) >/dev/null 2>&1 && continue + am__tar='tar chf - "$$tardir"' + am__tar_='tar chf - "$tardir"' + am__untar='tar xf -' + ;; + pax) + am__tar='pax -L -x $1 -w "$$tardir"' + am__tar_='pax -L -x $1 -w "$tardir"' + am__untar='pax -r' + ;; + cpio) + am__tar='find "$$tardir" -print | cpio -o -H $1 -L' + am__tar_='find "$tardir" -print | cpio -o -H $1 -L' + am__untar='cpio -i -H $1 -d' + ;; + none) + am__tar=false + am__tar_=false + am__untar=false + ;; + esac + + # If the value was cached, stop now. We just wanted to have am__tar + # and am__untar set. + test -n "${am_cv_prog_tar_$1}" && break + + # tar/untar a dummy directory, and stop if the command works + rm -rf conftest.dir + mkdir conftest.dir + echo GrepMe > conftest.dir/file + AM_RUN_LOG([tardir=conftest.dir && eval $am__tar_ >conftest.tar]) + rm -rf conftest.dir + if test -s conftest.tar; then + AM_RUN_LOG([$am__untar /dev/null 2>&1 && break + fi +done +rm -rf conftest.dir + +AC_CACHE_VAL([am_cv_prog_tar_$1], [am_cv_prog_tar_$1=$_am_tool]) +AC_MSG_RESULT([$am_cv_prog_tar_$1])]) +AC_SUBST([am__tar]) +AC_SUBST([am__untar]) +]) # _AM_PROG_TAR + diff --git a/libs/libpng-src/autogen.sh b/libs/libpng-src/autogen.sh new file mode 100755 index 000000000..77b63087c --- /dev/null +++ b/libs/libpng-src/autogen.sh @@ -0,0 +1,25 @@ +#! /bin/sh +# a quick hack script to generate necessary files from +# auto* tools. +# +# WARNING: if you run this you will change the versions +# of the tools which are used and, maybe, required! + touch Makefile.am configure.ac +{ + echo "running libtoolize" >&2 + libtoolize --force --copy --automake +} && { + echo "running aclocal" >&2 + aclocal +} && { + echo "running autoheader [ignore the warnings]" >&2 + autoheader +} && { + echo "running automake" >&2 + automake --force-missing --foreign -a -c +} && { + echo "running autoconf" >&2 + autoconf +} && + echo "autogen complete" >&2 || + echo "ERROR: autogen.sh failed, autogen is incomplete" >&2 diff --git a/libs/libpng-src/config.guess b/libs/libpng-src/config.guess new file mode 100755 index 000000000..da8331460 --- /dev/null +++ b/libs/libpng-src/config.guess @@ -0,0 +1,1561 @@ +#! /bin/sh +# Attempt to guess a canonical system name. +# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, +# 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 +# Free Software Foundation, Inc. + +timestamp='2009-04-27' + +# This file is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA +# 02110-1301, USA. +# +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + + +# Originally written by Per Bothner . +# Please send patches to . Submit a context +# diff and a properly formatted ChangeLog entry. +# +# This script attempts to guess a canonical system name similar to +# config.sub. If it succeeds, it prints the system name on stdout, and +# exits with 0. Otherwise, it exits with 1. +# +# The plan is that this can be called by configure scripts if you +# don't specify an explicit build system type. + +me=`echo "$0" | sed -e 's,.*/,,'` + +usage="\ +Usage: $0 [OPTION] + +Output the configuration name of the system \`$me' is run on. + +Operation modes: + -h, --help print this help, then exit + -t, --time-stamp print date of last modification, then exit + -v, --version print version number, then exit + +Report bugs and patches to ." + +version="\ +GNU config.guess ($timestamp) + +Originally written by Per Bothner. +Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, +2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. + +This is free software; see the source for copying conditions. There is NO +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." + +help=" +Try \`$me --help' for more information." + +# Parse command line +while test $# -gt 0 ; do + case $1 in + --time-stamp | --time* | -t ) + echo "$timestamp" ; exit ;; + --version | -v ) + echo "$version" ; exit ;; + --help | --h* | -h ) + echo "$usage"; exit ;; + -- ) # Stop option processing + shift; break ;; + - ) # Use stdin as input. + break ;; + -* ) + echo "$me: invalid option $1$help" >&2 + exit 1 ;; + * ) + break ;; + esac +done + +if test $# != 0; then + echo "$me: too many arguments$help" >&2 + exit 1 +fi + +trap 'exit 1' 1 2 15 + +# CC_FOR_BUILD -- compiler used by this script. Note that the use of a +# compiler to aid in system detection is discouraged as it requires +# temporary files to be created and, as you can see below, it is a +# headache to deal with in a portable fashion. + +# Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still +# use `HOST_CC' if defined, but it is deprecated. + +# Portable tmp directory creation inspired by the Autoconf team. + +set_cc_for_build=' +trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ; +trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ; +: ${TMPDIR=/tmp} ; + { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } || + { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } || + { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } || + { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ; +dummy=$tmp/dummy ; +tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy" ; +case $CC_FOR_BUILD,$HOST_CC,$CC in + ,,) echo "int x;" > $dummy.c ; + for c in cc gcc c89 c99 ; do + if ($c -c -o $dummy.o $dummy.c) >/dev/null 2>&1 ; then + CC_FOR_BUILD="$c"; break ; + fi ; + done ; + if test x"$CC_FOR_BUILD" = x ; then + CC_FOR_BUILD=no_compiler_found ; + fi + ;; + ,,*) CC_FOR_BUILD=$CC ;; + ,*,*) CC_FOR_BUILD=$HOST_CC ;; +esac ; set_cc_for_build= ;' + +# This is needed to find uname on a Pyramid OSx when run in the BSD universe. +# (ghazi@noc.rutgers.edu 1994-08-24) +if (test -f /.attbin/uname) >/dev/null 2>&1 ; then + PATH=$PATH:/.attbin ; export PATH +fi + +UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown +UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown +UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown +UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown + +# Note: order is significant - the case branches are not exclusive. + +case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in + *:NetBSD:*:*) + # NetBSD (nbsd) targets should (where applicable) match one or + # more of the tupples: *-*-netbsdelf*, *-*-netbsdaout*, + # *-*-netbsdecoff* and *-*-netbsd*. For targets that recently + # switched to ELF, *-*-netbsd* would select the old + # object file format. This provides both forward + # compatibility and a consistent mechanism for selecting the + # object file format. + # + # Note: NetBSD doesn't particularly care about the vendor + # portion of the name. We always set it to "unknown". + sysctl="sysctl -n hw.machine_arch" + UNAME_MACHINE_ARCH=`(/sbin/$sysctl 2>/dev/null || \ + /usr/sbin/$sysctl 2>/dev/null || echo unknown)` + case "${UNAME_MACHINE_ARCH}" in + armeb) machine=armeb-unknown ;; + arm*) machine=arm-unknown ;; + sh3el) machine=shl-unknown ;; + sh3eb) machine=sh-unknown ;; + sh5el) machine=sh5le-unknown ;; + *) machine=${UNAME_MACHINE_ARCH}-unknown ;; + esac + # The Operating System including object format, if it has switched + # to ELF recently, or will in the future. + case "${UNAME_MACHINE_ARCH}" in + arm*|i386|m68k|ns32k|sh3*|sparc|vax) + eval $set_cc_for_build + if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \ + | grep __ELF__ >/dev/null + then + # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout). + # Return netbsd for either. FIX? + os=netbsd + else + os=netbsdelf + fi + ;; + *) + os=netbsd + ;; + esac + # The OS release + # Debian GNU/NetBSD machines have a different userland, and + # thus, need a distinct triplet. However, they do not need + # kernel version information, so it can be replaced with a + # suitable tag, in the style of linux-gnu. + case "${UNAME_VERSION}" in + Debian*) + release='-gnu' + ;; + *) + release=`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'` + ;; + esac + # Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM: + # contains redundant information, the shorter form: + # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used. + echo "${machine}-${os}${release}" + exit ;; + *:OpenBSD:*:*) + UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'` + echo ${UNAME_MACHINE_ARCH}-unknown-openbsd${UNAME_RELEASE} + exit ;; + *:ekkoBSD:*:*) + echo ${UNAME_MACHINE}-unknown-ekkobsd${UNAME_RELEASE} + exit ;; + *:SolidBSD:*:*) + echo ${UNAME_MACHINE}-unknown-solidbsd${UNAME_RELEASE} + exit ;; + macppc:MirBSD:*:*) + echo powerpc-unknown-mirbsd${UNAME_RELEASE} + exit ;; + *:MirBSD:*:*) + echo ${UNAME_MACHINE}-unknown-mirbsd${UNAME_RELEASE} + exit ;; + alpha:OSF1:*:*) + case $UNAME_RELEASE in + *4.0) + UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'` + ;; + *5.*) + UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'` + ;; + esac + # According to Compaq, /usr/sbin/psrinfo has been available on + # OSF/1 and Tru64 systems produced since 1995. I hope that + # covers most systems running today. This code pipes the CPU + # types through head -n 1, so we only detect the type of CPU 0. + ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^ The alpha \(.*\) processor.*$/\1/p' | head -n 1` + case "$ALPHA_CPU_TYPE" in + "EV4 (21064)") + UNAME_MACHINE="alpha" ;; + "EV4.5 (21064)") + UNAME_MACHINE="alpha" ;; + "LCA4 (21066/21068)") + UNAME_MACHINE="alpha" ;; + "EV5 (21164)") + UNAME_MACHINE="alphaev5" ;; + "EV5.6 (21164A)") + UNAME_MACHINE="alphaev56" ;; + "EV5.6 (21164PC)") + UNAME_MACHINE="alphapca56" ;; + "EV5.7 (21164PC)") + UNAME_MACHINE="alphapca57" ;; + "EV6 (21264)") + UNAME_MACHINE="alphaev6" ;; + "EV6.7 (21264A)") + UNAME_MACHINE="alphaev67" ;; + "EV6.8CB (21264C)") + UNAME_MACHINE="alphaev68" ;; + "EV6.8AL (21264B)") + UNAME_MACHINE="alphaev68" ;; + "EV6.8CX (21264D)") + UNAME_MACHINE="alphaev68" ;; + "EV6.9A (21264/EV69A)") + UNAME_MACHINE="alphaev69" ;; + "EV7 (21364)") + UNAME_MACHINE="alphaev7" ;; + "EV7.9 (21364A)") + UNAME_MACHINE="alphaev79" ;; + esac + # A Pn.n version is a patched version. + # A Vn.n version is a released version. + # A Tn.n version is a released field test version. + # A Xn.n version is an unreleased experimental baselevel. + # 1.2 uses "1.2" for uname -r. + echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` + exit ;; + Alpha\ *:Windows_NT*:*) + # How do we know it's Interix rather than the generic POSIX subsystem? + # Should we change UNAME_MACHINE based on the output of uname instead + # of the specific Alpha model? + echo alpha-pc-interix + exit ;; + 21064:Windows_NT:50:3) + echo alpha-dec-winnt3.5 + exit ;; + Amiga*:UNIX_System_V:4.0:*) + echo m68k-unknown-sysv4 + exit ;; + *:[Aa]miga[Oo][Ss]:*:*) + echo ${UNAME_MACHINE}-unknown-amigaos + exit ;; + *:[Mm]orph[Oo][Ss]:*:*) + echo ${UNAME_MACHINE}-unknown-morphos + exit ;; + *:OS/390:*:*) + echo i370-ibm-openedition + exit ;; + *:z/VM:*:*) + echo s390-ibm-zvmoe + exit ;; + *:OS400:*:*) + echo powerpc-ibm-os400 + exit ;; + arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*) + echo arm-acorn-riscix${UNAME_RELEASE} + exit ;; + arm:riscos:*:*|arm:RISCOS:*:*) + echo arm-unknown-riscos + exit ;; + SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*) + echo hppa1.1-hitachi-hiuxmpp + exit ;; + Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*) + # akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE. + if test "`(/bin/universe) 2>/dev/null`" = att ; then + echo pyramid-pyramid-sysv3 + else + echo pyramid-pyramid-bsd + fi + exit ;; + NILE*:*:*:dcosx) + echo pyramid-pyramid-svr4 + exit ;; + DRS?6000:unix:4.0:6*) + echo sparc-icl-nx6 + exit ;; + DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*) + case `/usr/bin/uname -p` in + sparc) echo sparc-icl-nx7; exit ;; + esac ;; + s390x:SunOS:*:*) + echo ${UNAME_MACHINE}-ibm-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit ;; + sun4H:SunOS:5.*:*) + echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit ;; + sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*) + echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit ;; + i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*) + eval $set_cc_for_build + SUN_ARCH="i386" + # If there is a compiler, see if it is configured for 64-bit objects. + # Note that the Sun cc does not turn __LP64__ into 1 like gcc does. + # This test works for both compilers. + if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then + if (echo '#ifdef __amd64'; echo IS_64BIT_ARCH; echo '#endif') | \ + (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \ + grep IS_64BIT_ARCH >/dev/null + then + SUN_ARCH="x86_64" + fi + fi + echo ${SUN_ARCH}-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit ;; + sun4*:SunOS:6*:*) + # According to config.sub, this is the proper way to canonicalize + # SunOS6. Hard to guess exactly what SunOS6 will be like, but + # it's likely to be more like Solaris than SunOS4. + echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit ;; + sun4*:SunOS:*:*) + case "`/usr/bin/arch -k`" in + Series*|S4*) + UNAME_RELEASE=`uname -v` + ;; + esac + # Japanese Language versions have a version number like `4.1.3-JL'. + echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'` + exit ;; + sun3*:SunOS:*:*) + echo m68k-sun-sunos${UNAME_RELEASE} + exit ;; + sun*:*:4.2BSD:*) + UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null` + test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3 + case "`/bin/arch`" in + sun3) + echo m68k-sun-sunos${UNAME_RELEASE} + ;; + sun4) + echo sparc-sun-sunos${UNAME_RELEASE} + ;; + esac + exit ;; + aushp:SunOS:*:*) + echo sparc-auspex-sunos${UNAME_RELEASE} + exit ;; + # The situation for MiNT is a little confusing. The machine name + # can be virtually everything (everything which is not + # "atarist" or "atariste" at least should have a processor + # > m68000). The system name ranges from "MiNT" over "FreeMiNT" + # to the lowercase version "mint" (or "freemint"). Finally + # the system name "TOS" denotes a system which is actually not + # MiNT. But MiNT is downward compatible to TOS, so this should + # be no problem. + atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*) + echo m68k-atari-mint${UNAME_RELEASE} + exit ;; + atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*) + echo m68k-atari-mint${UNAME_RELEASE} + exit ;; + *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*) + echo m68k-atari-mint${UNAME_RELEASE} + exit ;; + milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*) + echo m68k-milan-mint${UNAME_RELEASE} + exit ;; + hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*) + echo m68k-hades-mint${UNAME_RELEASE} + exit ;; + *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*) + echo m68k-unknown-mint${UNAME_RELEASE} + exit ;; + m68k:machten:*:*) + echo m68k-apple-machten${UNAME_RELEASE} + exit ;; + powerpc:machten:*:*) + echo powerpc-apple-machten${UNAME_RELEASE} + exit ;; + RISC*:Mach:*:*) + echo mips-dec-mach_bsd4.3 + exit ;; + RISC*:ULTRIX:*:*) + echo mips-dec-ultrix${UNAME_RELEASE} + exit ;; + VAX*:ULTRIX*:*:*) + echo vax-dec-ultrix${UNAME_RELEASE} + exit ;; + 2020:CLIX:*:* | 2430:CLIX:*:*) + echo clipper-intergraph-clix${UNAME_RELEASE} + exit ;; + mips:*:*:UMIPS | mips:*:*:RISCos) + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c +#ifdef __cplusplus +#include /* for printf() prototype */ + int main (int argc, char *argv[]) { +#else + int main (argc, argv) int argc; char *argv[]; { +#endif + #if defined (host_mips) && defined (MIPSEB) + #if defined (SYSTYPE_SYSV) + printf ("mips-mips-riscos%ssysv\n", argv[1]); exit (0); + #endif + #if defined (SYSTYPE_SVR4) + printf ("mips-mips-riscos%ssvr4\n", argv[1]); exit (0); + #endif + #if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD) + printf ("mips-mips-riscos%sbsd\n", argv[1]); exit (0); + #endif + #endif + exit (-1); + } +EOF + $CC_FOR_BUILD -o $dummy $dummy.c && + dummyarg=`echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` && + SYSTEM_NAME=`$dummy $dummyarg` && + { echo "$SYSTEM_NAME"; exit; } + echo mips-mips-riscos${UNAME_RELEASE} + exit ;; + Motorola:PowerMAX_OS:*:*) + echo powerpc-motorola-powermax + exit ;; + Motorola:*:4.3:PL8-*) + echo powerpc-harris-powermax + exit ;; + Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*) + echo powerpc-harris-powermax + exit ;; + Night_Hawk:Power_UNIX:*:*) + echo powerpc-harris-powerunix + exit ;; + m88k:CX/UX:7*:*) + echo m88k-harris-cxux7 + exit ;; + m88k:*:4*:R4*) + echo m88k-motorola-sysv4 + exit ;; + m88k:*:3*:R3*) + echo m88k-motorola-sysv3 + exit ;; + AViiON:dgux:*:*) + # DG/UX returns AViiON for all architectures + UNAME_PROCESSOR=`/usr/bin/uname -p` + if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ] + then + if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \ + [ ${TARGET_BINARY_INTERFACE}x = x ] + then + echo m88k-dg-dgux${UNAME_RELEASE} + else + echo m88k-dg-dguxbcs${UNAME_RELEASE} + fi + else + echo i586-dg-dgux${UNAME_RELEASE} + fi + exit ;; + M88*:DolphinOS:*:*) # DolphinOS (SVR3) + echo m88k-dolphin-sysv3 + exit ;; + M88*:*:R3*:*) + # Delta 88k system running SVR3 + echo m88k-motorola-sysv3 + exit ;; + XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3) + echo m88k-tektronix-sysv3 + exit ;; + Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD) + echo m68k-tektronix-bsd + exit ;; + *:IRIX*:*:*) + echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'` + exit ;; + ????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX. + echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id + exit ;; # Note that: echo "'`uname -s`'" gives 'AIX ' + i*86:AIX:*:*) + echo i386-ibm-aix + exit ;; + ia64:AIX:*:*) + if [ -x /usr/bin/oslevel ] ; then + IBM_REV=`/usr/bin/oslevel` + else + IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} + fi + echo ${UNAME_MACHINE}-ibm-aix${IBM_REV} + exit ;; + *:AIX:2:3) + if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #include + + main() + { + if (!__power_pc()) + exit(1); + puts("powerpc-ibm-aix3.2.5"); + exit(0); + } +EOF + if $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` + then + echo "$SYSTEM_NAME" + else + echo rs6000-ibm-aix3.2.5 + fi + elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then + echo rs6000-ibm-aix3.2.4 + else + echo rs6000-ibm-aix3.2 + fi + exit ;; + *:AIX:*:[456]) + IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'` + if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then + IBM_ARCH=rs6000 + else + IBM_ARCH=powerpc + fi + if [ -x /usr/bin/oslevel ] ; then + IBM_REV=`/usr/bin/oslevel` + else + IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} + fi + echo ${IBM_ARCH}-ibm-aix${IBM_REV} + exit ;; + *:AIX:*:*) + echo rs6000-ibm-aix + exit ;; + ibmrt:4.4BSD:*|romp-ibm:BSD:*) + echo romp-ibm-bsd4.4 + exit ;; + ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC BSD and + echo romp-ibm-bsd${UNAME_RELEASE} # 4.3 with uname added to + exit ;; # report: romp-ibm BSD 4.3 + *:BOSX:*:*) + echo rs6000-bull-bosx + exit ;; + DPX/2?00:B.O.S.:*:*) + echo m68k-bull-sysv3 + exit ;; + 9000/[34]??:4.3bsd:1.*:*) + echo m68k-hp-bsd + exit ;; + hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*) + echo m68k-hp-bsd4.4 + exit ;; + 9000/[34678]??:HP-UX:*:*) + HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` + case "${UNAME_MACHINE}" in + 9000/31? ) HP_ARCH=m68000 ;; + 9000/[34]?? ) HP_ARCH=m68k ;; + 9000/[678][0-9][0-9]) + if [ -x /usr/bin/getconf ]; then + sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null` + sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null` + case "${sc_cpu_version}" in + 523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0 + 528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1 + 532) # CPU_PA_RISC2_0 + case "${sc_kernel_bits}" in + 32) HP_ARCH="hppa2.0n" ;; + 64) HP_ARCH="hppa2.0w" ;; + '') HP_ARCH="hppa2.0" ;; # HP-UX 10.20 + esac ;; + esac + fi + if [ "${HP_ARCH}" = "" ]; then + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + + #define _HPUX_SOURCE + #include + #include + + int main () + { + #if defined(_SC_KERNEL_BITS) + long bits = sysconf(_SC_KERNEL_BITS); + #endif + long cpu = sysconf (_SC_CPU_VERSION); + + switch (cpu) + { + case CPU_PA_RISC1_0: puts ("hppa1.0"); break; + case CPU_PA_RISC1_1: puts ("hppa1.1"); break; + case CPU_PA_RISC2_0: + #if defined(_SC_KERNEL_BITS) + switch (bits) + { + case 64: puts ("hppa2.0w"); break; + case 32: puts ("hppa2.0n"); break; + default: puts ("hppa2.0"); break; + } break; + #else /* !defined(_SC_KERNEL_BITS) */ + puts ("hppa2.0"); break; + #endif + default: puts ("hppa1.0"); break; + } + exit (0); + } +EOF + (CCOPTS= $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy` + test -z "$HP_ARCH" && HP_ARCH=hppa + fi ;; + esac + if [ ${HP_ARCH} = "hppa2.0w" ] + then + eval $set_cc_for_build + + # hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating + # 32-bit code. hppa64-hp-hpux* has the same kernel and a compiler + # generating 64-bit code. GNU and HP use different nomenclature: + # + # $ CC_FOR_BUILD=cc ./config.guess + # => hppa2.0w-hp-hpux11.23 + # $ CC_FOR_BUILD="cc +DA2.0w" ./config.guess + # => hppa64-hp-hpux11.23 + + if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | + grep __LP64__ >/dev/null + then + HP_ARCH="hppa2.0w" + else + HP_ARCH="hppa64" + fi + fi + echo ${HP_ARCH}-hp-hpux${HPUX_REV} + exit ;; + ia64:HP-UX:*:*) + HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` + echo ia64-hp-hpux${HPUX_REV} + exit ;; + 3050*:HI-UX:*:*) + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #include + int + main () + { + long cpu = sysconf (_SC_CPU_VERSION); + /* The order matters, because CPU_IS_HP_MC68K erroneously returns + true for CPU_PA_RISC1_0. CPU_IS_PA_RISC returns correct + results, however. */ + if (CPU_IS_PA_RISC (cpu)) + { + switch (cpu) + { + case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break; + case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break; + case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break; + default: puts ("hppa-hitachi-hiuxwe2"); break; + } + } + else if (CPU_IS_HP_MC68K (cpu)) + puts ("m68k-hitachi-hiuxwe2"); + else puts ("unknown-hitachi-hiuxwe2"); + exit (0); + } +EOF + $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` && + { echo "$SYSTEM_NAME"; exit; } + echo unknown-hitachi-hiuxwe2 + exit ;; + 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* ) + echo hppa1.1-hp-bsd + exit ;; + 9000/8??:4.3bsd:*:*) + echo hppa1.0-hp-bsd + exit ;; + *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*) + echo hppa1.0-hp-mpeix + exit ;; + hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* ) + echo hppa1.1-hp-osf + exit ;; + hp8??:OSF1:*:*) + echo hppa1.0-hp-osf + exit ;; + i*86:OSF1:*:*) + if [ -x /usr/sbin/sysversion ] ; then + echo ${UNAME_MACHINE}-unknown-osf1mk + else + echo ${UNAME_MACHINE}-unknown-osf1 + fi + exit ;; + parisc*:Lites*:*:*) + echo hppa1.1-hp-lites + exit ;; + C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*) + echo c1-convex-bsd + exit ;; + C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*) + if getsysinfo -f scalar_acc + then echo c32-convex-bsd + else echo c2-convex-bsd + fi + exit ;; + C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*) + echo c34-convex-bsd + exit ;; + C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*) + echo c38-convex-bsd + exit ;; + C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*) + echo c4-convex-bsd + exit ;; + CRAY*Y-MP:*:*:*) + echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit ;; + CRAY*[A-Z]90:*:*:*) + echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \ + | sed -e 's/CRAY.*\([A-Z]90\)/\1/' \ + -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \ + -e 's/\.[^.]*$/.X/' + exit ;; + CRAY*TS:*:*:*) + echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit ;; + CRAY*T3E:*:*:*) + echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit ;; + CRAY*SV1:*:*:*) + echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit ;; + *:UNICOS/mp:*:*) + echo craynv-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit ;; + F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*) + FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` + FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` + FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'` + echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" + exit ;; + 5000:UNIX_System_V:4.*:*) + FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` + FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'` + echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" + exit ;; + i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*) + echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE} + exit ;; + sparc*:BSD/OS:*:*) + echo sparc-unknown-bsdi${UNAME_RELEASE} + exit ;; + *:BSD/OS:*:*) + echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE} + exit ;; + *:FreeBSD:*:*) + case ${UNAME_MACHINE} in + pc98) + echo i386-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; + amd64) + echo x86_64-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; + *) + echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; + esac + exit ;; + i*:CYGWIN*:*) + echo ${UNAME_MACHINE}-pc-cygwin + exit ;; + *:MINGW*:*) + echo ${UNAME_MACHINE}-pc-mingw32 + exit ;; + i*:windows32*:*) + # uname -m includes "-pc" on this system. + echo ${UNAME_MACHINE}-mingw32 + exit ;; + i*:PW*:*) + echo ${UNAME_MACHINE}-pc-pw32 + exit ;; + *:Interix*:[3456]*) + case ${UNAME_MACHINE} in + x86) + echo i586-pc-interix${UNAME_RELEASE} + exit ;; + EM64T | authenticamd | genuineintel) + echo x86_64-unknown-interix${UNAME_RELEASE} + exit ;; + IA64) + echo ia64-unknown-interix${UNAME_RELEASE} + exit ;; + esac ;; + [345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*) + echo i${UNAME_MACHINE}-pc-mks + exit ;; + i*:Windows_NT*:* | Pentium*:Windows_NT*:*) + # How do we know it's Interix rather than the generic POSIX subsystem? + # It also conflicts with pre-2.0 versions of AT&T UWIN. Should we + # UNAME_MACHINE based on the output of uname instead of i386? + echo i586-pc-interix + exit ;; + i*:UWIN*:*) + echo ${UNAME_MACHINE}-pc-uwin + exit ;; + amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*) + echo x86_64-unknown-cygwin + exit ;; + p*:CYGWIN*:*) + echo powerpcle-unknown-cygwin + exit ;; + prep*:SunOS:5.*:*) + echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit ;; + *:GNU:*:*) + # the GNU system + echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'` + exit ;; + *:GNU/*:*:*) + # other systems with GNU libc and userland + echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-gnu + exit ;; + i*86:Minix:*:*) + echo ${UNAME_MACHINE}-pc-minix + exit ;; + arm*:Linux:*:*) + eval $set_cc_for_build + if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \ + | grep -q __ARM_EABI__ + then + echo ${UNAME_MACHINE}-unknown-linux-gnu + else + echo ${UNAME_MACHINE}-unknown-linux-gnueabi + fi + exit ;; + avr32*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + cris:Linux:*:*) + echo cris-axis-linux-gnu + exit ;; + crisv32:Linux:*:*) + echo crisv32-axis-linux-gnu + exit ;; + frv:Linux:*:*) + echo frv-unknown-linux-gnu + exit ;; + ia64:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + m32r*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + m68*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + mips:Linux:*:*) + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #undef CPU + #undef mips + #undef mipsel + #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) + CPU=mipsel + #else + #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) + CPU=mips + #else + CPU= + #endif + #endif +EOF + eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n ' + /^CPU/{ + s: ::g + p + }'`" + test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; } + ;; + mips64:Linux:*:*) + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #undef CPU + #undef mips64 + #undef mips64el + #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) + CPU=mips64el + #else + #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) + CPU=mips64 + #else + CPU= + #endif + #endif +EOF + eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n ' + /^CPU/{ + s: ::g + p + }'`" + test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; } + ;; + or32:Linux:*:*) + echo or32-unknown-linux-gnu + exit ;; + ppc:Linux:*:*) + echo powerpc-unknown-linux-gnu + exit ;; + ppc64:Linux:*:*) + echo powerpc64-unknown-linux-gnu + exit ;; + alpha:Linux:*:*) + case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in + EV5) UNAME_MACHINE=alphaev5 ;; + EV56) UNAME_MACHINE=alphaev56 ;; + PCA56) UNAME_MACHINE=alphapca56 ;; + PCA57) UNAME_MACHINE=alphapca56 ;; + EV6) UNAME_MACHINE=alphaev6 ;; + EV67) UNAME_MACHINE=alphaev67 ;; + EV68*) UNAME_MACHINE=alphaev68 ;; + esac + objdump --private-headers /bin/sh | grep ld.so.1 >/dev/null + if test "$?" = 0 ; then LIBC="libc1" ; else LIBC="" ; fi + echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC} + exit ;; + padre:Linux:*:*) + echo sparc-unknown-linux-gnu + exit ;; + parisc:Linux:*:* | hppa:Linux:*:*) + # Look for CPU level + case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in + PA7*) echo hppa1.1-unknown-linux-gnu ;; + PA8*) echo hppa2.0-unknown-linux-gnu ;; + *) echo hppa-unknown-linux-gnu ;; + esac + exit ;; + parisc64:Linux:*:* | hppa64:Linux:*:*) + echo hppa64-unknown-linux-gnu + exit ;; + s390:Linux:*:* | s390x:Linux:*:*) + echo ${UNAME_MACHINE}-ibm-linux + exit ;; + sh64*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + sh*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + sparc:Linux:*:* | sparc64:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + vax:Linux:*:*) + echo ${UNAME_MACHINE}-dec-linux-gnu + exit ;; + x86_64:Linux:*:*) + echo x86_64-unknown-linux-gnu + exit ;; + xtensa*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + i*86:Linux:*:*) + # The BFD linker knows what the default object file format is, so + # first see if it will tell us. cd to the root directory to prevent + # problems with other programs or directories called `ld' in the path. + # Set LC_ALL=C to ensure ld outputs messages in English. + ld_supported_targets=`cd /; LC_ALL=C ld --help 2>&1 \ + | sed -ne '/supported targets:/!d + s/[ ][ ]*/ /g + s/.*supported targets: *// + s/ .*// + p'` + case "$ld_supported_targets" in + elf32-i386) + TENTATIVE="${UNAME_MACHINE}-pc-linux-gnu" + ;; + a.out-i386-linux) + echo "${UNAME_MACHINE}-pc-linux-gnuaout" + exit ;; + "") + # Either a pre-BFD a.out linker (linux-gnuoldld) or + # one that does not give us useful --help. + echo "${UNAME_MACHINE}-pc-linux-gnuoldld" + exit ;; + esac + # Determine whether the default compiler is a.out or elf + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #include + #ifdef __ELF__ + # ifdef __GLIBC__ + # if __GLIBC__ >= 2 + LIBC=gnu + # else + LIBC=gnulibc1 + # endif + # else + LIBC=gnulibc1 + # endif + #else + #if defined(__INTEL_COMPILER) || defined(__PGI) || defined(__SUNPRO_C) || defined(__SUNPRO_CC) + LIBC=gnu + #else + LIBC=gnuaout + #endif + #endif + #ifdef __dietlibc__ + LIBC=dietlibc + #endif +EOF + eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n ' + /^LIBC/{ + s: ::g + p + }'`" + test x"${LIBC}" != x && { + echo "${UNAME_MACHINE}-pc-linux-${LIBC}" + exit + } + test x"${TENTATIVE}" != x && { echo "${TENTATIVE}"; exit; } + ;; + i*86:DYNIX/ptx:4*:*) + # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. + # earlier versions are messed up and put the nodename in both + # sysname and nodename. + echo i386-sequent-sysv4 + exit ;; + i*86:UNIX_SV:4.2MP:2.*) + # Unixware is an offshoot of SVR4, but it has its own version + # number series starting with 2... + # I am not positive that other SVR4 systems won't match this, + # I just have to hope. -- rms. + # Use sysv4.2uw... so that sysv4* matches it. + echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION} + exit ;; + i*86:OS/2:*:*) + # If we were able to find `uname', then EMX Unix compatibility + # is probably installed. + echo ${UNAME_MACHINE}-pc-os2-emx + exit ;; + i*86:XTS-300:*:STOP) + echo ${UNAME_MACHINE}-unknown-stop + exit ;; + i*86:atheos:*:*) + echo ${UNAME_MACHINE}-unknown-atheos + exit ;; + i*86:syllable:*:*) + echo ${UNAME_MACHINE}-pc-syllable + exit ;; + i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.0*:*) + echo i386-unknown-lynxos${UNAME_RELEASE} + exit ;; + i*86:*DOS:*:*) + echo ${UNAME_MACHINE}-pc-msdosdjgpp + exit ;; + i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*) + UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'` + if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then + echo ${UNAME_MACHINE}-univel-sysv${UNAME_REL} + else + echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL} + fi + exit ;; + i*86:*:5:[678]*) + # UnixWare 7.x, OpenUNIX and OpenServer 6. + case `/bin/uname -X | grep "^Machine"` in + *486*) UNAME_MACHINE=i486 ;; + *Pentium) UNAME_MACHINE=i586 ;; + *Pent*|*Celeron) UNAME_MACHINE=i686 ;; + esac + echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION} + exit ;; + i*86:*:3.2:*) + if test -f /usr/options/cb.name; then + UNAME_REL=`sed -n 's/.*Version //p' /dev/null >/dev/null ; then + UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')` + (/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486 + (/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \ + && UNAME_MACHINE=i586 + (/bin/uname -X|grep '^Machine.*Pent *II' >/dev/null) \ + && UNAME_MACHINE=i686 + (/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \ + && UNAME_MACHINE=i686 + echo ${UNAME_MACHINE}-pc-sco$UNAME_REL + else + echo ${UNAME_MACHINE}-pc-sysv32 + fi + exit ;; + pc:*:*:*) + # Left here for compatibility: + # uname -m prints for DJGPP always 'pc', but it prints nothing about + # the processor, so we play safe by assuming i586. + # Note: whatever this is, it MUST be the same as what config.sub + # prints for the "djgpp" host, or else GDB configury will decide that + # this is a cross-build. + echo i586-pc-msdosdjgpp + exit ;; + Intel:Mach:3*:*) + echo i386-pc-mach3 + exit ;; + paragon:*:*:*) + echo i860-intel-osf1 + exit ;; + i860:*:4.*:*) # i860-SVR4 + if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then + echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4 + else # Add other i860-SVR4 vendors below as they are discovered. + echo i860-unknown-sysv${UNAME_RELEASE} # Unknown i860-SVR4 + fi + exit ;; + mini*:CTIX:SYS*5:*) + # "miniframe" + echo m68010-convergent-sysv + exit ;; + mc68k:UNIX:SYSTEM5:3.51m) + echo m68k-convergent-sysv + exit ;; + M680?0:D-NIX:5.3:*) + echo m68k-diab-dnix + exit ;; + M68*:*:R3V[5678]*:*) + test -r /sysV68 && { echo 'm68k-motorola-sysv'; exit; } ;; + 3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0) + OS_REL='' + test -r /etc/.relid \ + && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` + /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ + && { echo i486-ncr-sysv4.3${OS_REL}; exit; } + /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ + && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;; + 3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*) + /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ + && { echo i486-ncr-sysv4; exit; } ;; + NCR*:*:4.2:* | MPRAS*:*:4.2:*) + OS_REL='.3' + test -r /etc/.relid \ + && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` + /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ + && { echo i486-ncr-sysv4.3${OS_REL}; exit; } + /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ + && { echo i586-ncr-sysv4.3${OS_REL}; exit; } + /bin/uname -p 2>/dev/null | /bin/grep pteron >/dev/null \ + && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;; + m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*) + echo m68k-unknown-lynxos${UNAME_RELEASE} + exit ;; + mc68030:UNIX_System_V:4.*:*) + echo m68k-atari-sysv4 + exit ;; + TSUNAMI:LynxOS:2.*:*) + echo sparc-unknown-lynxos${UNAME_RELEASE} + exit ;; + rs6000:LynxOS:2.*:*) + echo rs6000-unknown-lynxos${UNAME_RELEASE} + exit ;; + PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.0*:*) + echo powerpc-unknown-lynxos${UNAME_RELEASE} + exit ;; + SM[BE]S:UNIX_SV:*:*) + echo mips-dde-sysv${UNAME_RELEASE} + exit ;; + RM*:ReliantUNIX-*:*:*) + echo mips-sni-sysv4 + exit ;; + RM*:SINIX-*:*:*) + echo mips-sni-sysv4 + exit ;; + *:SINIX-*:*:*) + if uname -p 2>/dev/null >/dev/null ; then + UNAME_MACHINE=`(uname -p) 2>/dev/null` + echo ${UNAME_MACHINE}-sni-sysv4 + else + echo ns32k-sni-sysv + fi + exit ;; + PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort + # says + echo i586-unisys-sysv4 + exit ;; + *:UNIX_System_V:4*:FTX*) + # From Gerald Hewes . + # How about differentiating between stratus architectures? -djm + echo hppa1.1-stratus-sysv4 + exit ;; + *:*:*:FTX*) + # From seanf@swdc.stratus.com. + echo i860-stratus-sysv4 + exit ;; + i*86:VOS:*:*) + # From Paul.Green@stratus.com. + echo ${UNAME_MACHINE}-stratus-vos + exit ;; + *:VOS:*:*) + # From Paul.Green@stratus.com. + echo hppa1.1-stratus-vos + exit ;; + mc68*:A/UX:*:*) + echo m68k-apple-aux${UNAME_RELEASE} + exit ;; + news*:NEWS-OS:6*:*) + echo mips-sony-newsos6 + exit ;; + R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*) + if [ -d /usr/nec ]; then + echo mips-nec-sysv${UNAME_RELEASE} + else + echo mips-unknown-sysv${UNAME_RELEASE} + fi + exit ;; + BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only. + echo powerpc-be-beos + exit ;; + BeMac:BeOS:*:*) # BeOS running on Mac or Mac clone, PPC only. + echo powerpc-apple-beos + exit ;; + BePC:BeOS:*:*) # BeOS running on Intel PC compatible. + echo i586-pc-beos + exit ;; + BePC:Haiku:*:*) # Haiku running on Intel PC compatible. + echo i586-pc-haiku + exit ;; + SX-4:SUPER-UX:*:*) + echo sx4-nec-superux${UNAME_RELEASE} + exit ;; + SX-5:SUPER-UX:*:*) + echo sx5-nec-superux${UNAME_RELEASE} + exit ;; + SX-6:SUPER-UX:*:*) + echo sx6-nec-superux${UNAME_RELEASE} + exit ;; + SX-7:SUPER-UX:*:*) + echo sx7-nec-superux${UNAME_RELEASE} + exit ;; + SX-8:SUPER-UX:*:*) + echo sx8-nec-superux${UNAME_RELEASE} + exit ;; + SX-8R:SUPER-UX:*:*) + echo sx8r-nec-superux${UNAME_RELEASE} + exit ;; + Power*:Rhapsody:*:*) + echo powerpc-apple-rhapsody${UNAME_RELEASE} + exit ;; + *:Rhapsody:*:*) + echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE} + exit ;; + *:Darwin:*:*) + UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown + case $UNAME_PROCESSOR in + unknown) UNAME_PROCESSOR=powerpc ;; + esac + echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE} + exit ;; + *:procnto*:*:* | *:QNX:[0123456789]*:*) + UNAME_PROCESSOR=`uname -p` + if test "$UNAME_PROCESSOR" = "x86"; then + UNAME_PROCESSOR=i386 + UNAME_MACHINE=pc + fi + echo ${UNAME_PROCESSOR}-${UNAME_MACHINE}-nto-qnx${UNAME_RELEASE} + exit ;; + *:QNX:*:4*) + echo i386-pc-qnx + exit ;; + NSE-?:NONSTOP_KERNEL:*:*) + echo nse-tandem-nsk${UNAME_RELEASE} + exit ;; + NSR-?:NONSTOP_KERNEL:*:*) + echo nsr-tandem-nsk${UNAME_RELEASE} + exit ;; + *:NonStop-UX:*:*) + echo mips-compaq-nonstopux + exit ;; + BS2000:POSIX*:*:*) + echo bs2000-siemens-sysv + exit ;; + DS/*:UNIX_System_V:*:*) + echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE} + exit ;; + *:Plan9:*:*) + # "uname -m" is not consistent, so use $cputype instead. 386 + # is converted to i386 for consistency with other x86 + # operating systems. + if test "$cputype" = "386"; then + UNAME_MACHINE=i386 + else + UNAME_MACHINE="$cputype" + fi + echo ${UNAME_MACHINE}-unknown-plan9 + exit ;; + *:TOPS-10:*:*) + echo pdp10-unknown-tops10 + exit ;; + *:TENEX:*:*) + echo pdp10-unknown-tenex + exit ;; + KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*) + echo pdp10-dec-tops20 + exit ;; + XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*) + echo pdp10-xkl-tops20 + exit ;; + *:TOPS-20:*:*) + echo pdp10-unknown-tops20 + exit ;; + *:ITS:*:*) + echo pdp10-unknown-its + exit ;; + SEI:*:*:SEIUX) + echo mips-sei-seiux${UNAME_RELEASE} + exit ;; + *:DragonFly:*:*) + echo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` + exit ;; + *:*VMS:*:*) + UNAME_MACHINE=`(uname -p) 2>/dev/null` + case "${UNAME_MACHINE}" in + A*) echo alpha-dec-vms ; exit ;; + I*) echo ia64-dec-vms ; exit ;; + V*) echo vax-dec-vms ; exit ;; + esac ;; + *:XENIX:*:SysV) + echo i386-pc-xenix + exit ;; + i*86:skyos:*:*) + echo ${UNAME_MACHINE}-pc-skyos`echo ${UNAME_RELEASE}` | sed -e 's/ .*$//' + exit ;; + i*86:rdos:*:*) + echo ${UNAME_MACHINE}-pc-rdos + exit ;; + i*86:AROS:*:*) + echo ${UNAME_MACHINE}-pc-aros + exit ;; +esac + +#echo '(No uname command or uname output not recognized.)' 1>&2 +#echo "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" 1>&2 + +eval $set_cc_for_build +cat >$dummy.c < +# include +#endif +main () +{ +#if defined (sony) +#if defined (MIPSEB) + /* BFD wants "bsd" instead of "newsos". Perhaps BFD should be changed, + I don't know.... */ + printf ("mips-sony-bsd\n"); exit (0); +#else +#include + printf ("m68k-sony-newsos%s\n", +#ifdef NEWSOS4 + "4" +#else + "" +#endif + ); exit (0); +#endif +#endif + +#if defined (__arm) && defined (__acorn) && defined (__unix) + printf ("arm-acorn-riscix\n"); exit (0); +#endif + +#if defined (hp300) && !defined (hpux) + printf ("m68k-hp-bsd\n"); exit (0); +#endif + +#if defined (NeXT) +#if !defined (__ARCHITECTURE__) +#define __ARCHITECTURE__ "m68k" +#endif + int version; + version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`; + if (version < 4) + printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version); + else + printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version); + exit (0); +#endif + +#if defined (MULTIMAX) || defined (n16) +#if defined (UMAXV) + printf ("ns32k-encore-sysv\n"); exit (0); +#else +#if defined (CMU) + printf ("ns32k-encore-mach\n"); exit (0); +#else + printf ("ns32k-encore-bsd\n"); exit (0); +#endif +#endif +#endif + +#if defined (__386BSD__) + printf ("i386-pc-bsd\n"); exit (0); +#endif + +#if defined (sequent) +#if defined (i386) + printf ("i386-sequent-dynix\n"); exit (0); +#endif +#if defined (ns32000) + printf ("ns32k-sequent-dynix\n"); exit (0); +#endif +#endif + +#if defined (_SEQUENT_) + struct utsname un; + + uname(&un); + + if (strncmp(un.version, "V2", 2) == 0) { + printf ("i386-sequent-ptx2\n"); exit (0); + } + if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */ + printf ("i386-sequent-ptx1\n"); exit (0); + } + printf ("i386-sequent-ptx\n"); exit (0); + +#endif + +#if defined (vax) +# if !defined (ultrix) +# include +# if defined (BSD) +# if BSD == 43 + printf ("vax-dec-bsd4.3\n"); exit (0); +# else +# if BSD == 199006 + printf ("vax-dec-bsd4.3reno\n"); exit (0); +# else + printf ("vax-dec-bsd\n"); exit (0); +# endif +# endif +# else + printf ("vax-dec-bsd\n"); exit (0); +# endif +# else + printf ("vax-dec-ultrix\n"); exit (0); +# endif +#endif + +#if defined (alliant) && defined (i860) + printf ("i860-alliant-bsd\n"); exit (0); +#endif + + exit (1); +} +EOF + +$CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && SYSTEM_NAME=`$dummy` && + { echo "$SYSTEM_NAME"; exit; } + +# Apollos put the system type in the environment. + +test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit; } + +# Convex versions that predate uname can use getsysinfo(1) + +if [ -x /usr/convex/getsysinfo ] +then + case `getsysinfo -f cpu_type` in + c1*) + echo c1-convex-bsd + exit ;; + c2*) + if getsysinfo -f scalar_acc + then echo c32-convex-bsd + else echo c2-convex-bsd + fi + exit ;; + c34*) + echo c34-convex-bsd + exit ;; + c38*) + echo c38-convex-bsd + exit ;; + c4*) + echo c4-convex-bsd + exit ;; + esac +fi + +cat >&2 < in order to provide the needed +information to handle your system. + +config.guess timestamp = $timestamp + +uname -m = `(uname -m) 2>/dev/null || echo unknown` +uname -r = `(uname -r) 2>/dev/null || echo unknown` +uname -s = `(uname -s) 2>/dev/null || echo unknown` +uname -v = `(uname -v) 2>/dev/null || echo unknown` + +/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null` +/bin/uname -X = `(/bin/uname -X) 2>/dev/null` + +hostinfo = `(hostinfo) 2>/dev/null` +/bin/universe = `(/bin/universe) 2>/dev/null` +/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null` +/bin/arch = `(/bin/arch) 2>/dev/null` +/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null` +/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null` + +UNAME_MACHINE = ${UNAME_MACHINE} +UNAME_RELEASE = ${UNAME_RELEASE} +UNAME_SYSTEM = ${UNAME_SYSTEM} +UNAME_VERSION = ${UNAME_VERSION} +EOF + +exit 1 + +# Local variables: +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "timestamp='" +# time-stamp-format: "%:y-%02m-%02d" +# time-stamp-end: "'" +# End: diff --git a/libs/libpng-src/config.h.in b/libs/libpng-src/config.h.in new file mode 100644 index 000000000..fb2349568 --- /dev/null +++ b/libs/libpng-src/config.h.in @@ -0,0 +1,86 @@ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Define to 1 if you have the header file. */ +#undef HAVE_DLFCN_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_INTTYPES_H + +/* Define to 1 if you have the `m' library (-lm). */ +#undef HAVE_LIBM + +/* Define to 1 if you have the `z' library (-lz). */ +#undef HAVE_LIBZ + +/* Define to 1 if you have the header file. */ +#undef HAVE_MALLOC_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_MEMORY_H + +/* Define to 1 if you have the `memset' function. */ +#undef HAVE_MEMSET + +/* Define to 1 if you have the `pow' function. */ +#undef HAVE_POW + +/* Define to 1 if you have the header file. */ +#undef HAVE_STDINT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STDLIB_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STRINGS_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STRING_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_STAT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_TYPES_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_UNISTD_H + +/* Define to the sub-directory in which libtool stores uninstalled libraries. + */ +#undef LT_OBJDIR + +/* Name of package */ +#undef PACKAGE + +/* Define to the address where bug reports for this package should be sent. */ +#undef PACKAGE_BUGREPORT + +/* Define to the full name of this package. */ +#undef PACKAGE_NAME + +/* Define to the full name and version of this package. */ +#undef PACKAGE_STRING + +/* Define to the one symbol short name of this package. */ +#undef PACKAGE_TARNAME + +/* Define to the home page for this package. */ +#undef PACKAGE_URL + +/* Define to the version of this package. */ +#undef PACKAGE_VERSION + +/* Define to 1 if you have the ANSI C header files. */ +#undef STDC_HEADERS + +/* Define to 1 if your declares `struct tm'. */ +#undef TM_IN_SYS_TIME + +/* Version number of package */ +#undef VERSION + +/* Define to empty if `const' does not conform to ANSI C. */ +#undef const + +/* Define to `unsigned int' if does not define. */ +#undef size_t diff --git a/libs/libpng-src/config.sub b/libs/libpng-src/config.sub new file mode 100755 index 000000000..a39437d01 --- /dev/null +++ b/libs/libpng-src/config.sub @@ -0,0 +1,1686 @@ +#! /bin/sh +# Configuration validation subroutine script. +# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, +# 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 +# Free Software Foundation, Inc. + +timestamp='2009-04-17' + +# This file is (in principle) common to ALL GNU software. +# The presence of a machine in this file suggests that SOME GNU software +# can handle that machine. It does not imply ALL GNU software can. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA +# 02110-1301, USA. +# +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + + +# Please send patches to . Submit a context +# diff and a properly formatted ChangeLog entry. +# +# Configuration subroutine to validate and canonicalize a configuration type. +# Supply the specified configuration type as an argument. +# If it is invalid, we print an error message on stderr and exit with code 1. +# Otherwise, we print the canonical config type on stdout and succeed. + +# This file is supposed to be the same for all GNU packages +# and recognize all the CPU types, system types and aliases +# that are meaningful with *any* GNU software. +# Each package is responsible for reporting which valid configurations +# it does not support. The user should be able to distinguish +# a failure to support a valid configuration from a meaningless +# configuration. + +# The goal of this file is to map all the various variations of a given +# machine specification into a single specification in the form: +# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM +# or in some cases, the newer four-part form: +# CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM +# It is wrong to echo any other type of specification. + +me=`echo "$0" | sed -e 's,.*/,,'` + +usage="\ +Usage: $0 [OPTION] CPU-MFR-OPSYS + $0 [OPTION] ALIAS + +Canonicalize a configuration name. + +Operation modes: + -h, --help print this help, then exit + -t, --time-stamp print date of last modification, then exit + -v, --version print version number, then exit + +Report bugs and patches to ." + +version="\ +GNU config.sub ($timestamp) + +Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, +2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. + +This is free software; see the source for copying conditions. There is NO +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." + +help=" +Try \`$me --help' for more information." + +# Parse command line +while test $# -gt 0 ; do + case $1 in + --time-stamp | --time* | -t ) + echo "$timestamp" ; exit ;; + --version | -v ) + echo "$version" ; exit ;; + --help | --h* | -h ) + echo "$usage"; exit ;; + -- ) # Stop option processing + shift; break ;; + - ) # Use stdin as input. + break ;; + -* ) + echo "$me: invalid option $1$help" + exit 1 ;; + + *local*) + # First pass through any local machine types. + echo $1 + exit ;; + + * ) + break ;; + esac +done + +case $# in + 0) echo "$me: missing argument$help" >&2 + exit 1;; + 1) ;; + *) echo "$me: too many arguments$help" >&2 + exit 1;; +esac + +# Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any). +# Here we must recognize all the valid KERNEL-OS combinations. +maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'` +case $maybe_os in + nto-qnx* | linux-gnu* | linux-dietlibc | linux-newlib* | linux-uclibc* | \ + uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* | \ + kopensolaris*-gnu* | \ + storm-chaos* | os2-emx* | rtmk-nova*) + os=-$maybe_os + basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'` + ;; + *) + basic_machine=`echo $1 | sed 's/-[^-]*$//'` + if [ $basic_machine != $1 ] + then os=`echo $1 | sed 's/.*-/-/'` + else os=; fi + ;; +esac + +### Let's recognize common machines as not being operating systems so +### that things like config.sub decstation-3100 work. We also +### recognize some manufacturers as not being operating systems, so we +### can provide default operating systems below. +case $os in + -sun*os*) + # Prevent following clause from handling this invalid input. + ;; + -dec* | -mips* | -sequent* | -encore* | -pc532* | -sgi* | -sony* | \ + -att* | -7300* | -3300* | -delta* | -motorola* | -sun[234]* | \ + -unicom* | -ibm* | -next | -hp | -isi* | -apollo | -altos* | \ + -convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\ + -c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \ + -harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \ + -apple | -axis | -knuth | -cray) + os= + basic_machine=$1 + ;; + -sim | -cisco | -oki | -wec | -winbond) + os= + basic_machine=$1 + ;; + -scout) + ;; + -wrs) + os=-vxworks + basic_machine=$1 + ;; + -chorusos*) + os=-chorusos + basic_machine=$1 + ;; + -chorusrdb) + os=-chorusrdb + basic_machine=$1 + ;; + -hiux*) + os=-hiuxwe2 + ;; + -sco6) + os=-sco5v6 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco5) + os=-sco3.2v5 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco4) + os=-sco3.2v4 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco3.2.[4-9]*) + os=`echo $os | sed -e 's/sco3.2./sco3.2v/'` + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco3.2v[4-9]*) + # Don't forget version if it is 3.2v4 or newer. + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco5v6*) + # Don't forget version if it is 3.2v4 or newer. + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco*) + os=-sco3.2v2 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -udk*) + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -isc) + os=-isc2.2 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -clix*) + basic_machine=clipper-intergraph + ;; + -isc*) + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -lynx*) + os=-lynxos + ;; + -ptx*) + basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'` + ;; + -windowsnt*) + os=`echo $os | sed -e 's/windowsnt/winnt/'` + ;; + -psos*) + os=-psos + ;; + -mint | -mint[0-9]*) + basic_machine=m68k-atari + os=-mint + ;; +esac + +# Decode aliases for certain CPU-COMPANY combinations. +case $basic_machine in + # Recognize the basic CPU types without company name. + # Some are omitted here because they have special meanings below. + 1750a | 580 \ + | a29k \ + | alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \ + | alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \ + | am33_2.0 \ + | arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr | avr32 \ + | bfin \ + | c4x | clipper \ + | d10v | d30v | dlx | dsp16xx \ + | fido | fr30 | frv \ + | h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \ + | i370 | i860 | i960 | ia64 \ + | ip2k | iq2000 \ + | lm32 \ + | m32c | m32r | m32rle | m68000 | m68k | m88k \ + | maxq | mb | microblaze | mcore | mep | metag \ + | mips | mipsbe | mipseb | mipsel | mipsle \ + | mips16 \ + | mips64 | mips64el \ + | mips64octeon | mips64octeonel \ + | mips64orion | mips64orionel \ + | mips64r5900 | mips64r5900el \ + | mips64vr | mips64vrel \ + | mips64vr4100 | mips64vr4100el \ + | mips64vr4300 | mips64vr4300el \ + | mips64vr5000 | mips64vr5000el \ + | mips64vr5900 | mips64vr5900el \ + | mipsisa32 | mipsisa32el \ + | mipsisa32r2 | mipsisa32r2el \ + | mipsisa64 | mipsisa64el \ + | mipsisa64r2 | mipsisa64r2el \ + | mipsisa64sb1 | mipsisa64sb1el \ + | mipsisa64sr71k | mipsisa64sr71kel \ + | mipstx39 | mipstx39el \ + | mn10200 | mn10300 \ + | moxie \ + | mt \ + | msp430 \ + | nios | nios2 \ + | ns16k | ns32k \ + | or32 \ + | pdp10 | pdp11 | pj | pjl \ + | powerpc | powerpc64 | powerpc64le | powerpcle | ppcbe \ + | pyramid \ + | score \ + | sh | sh[1234] | sh[24]a | sh[24]aeb | sh[23]e | sh[34]eb | sheb | shbe | shle | sh[1234]le | sh3ele \ + | sh64 | sh64le \ + | sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \ + | sparcv8 | sparcv9 | sparcv9b | sparcv9v \ + | spu | strongarm \ + | tahoe | thumb | tic4x | tic80 | tron \ + | v850 | v850e \ + | we32k \ + | x86 | xc16x | xscale | xscalee[bl] | xstormy16 | xtensa \ + | z8k | z80) + basic_machine=$basic_machine-unknown + ;; + m6811 | m68hc11 | m6812 | m68hc12) + # Motorola 68HC11/12. + basic_machine=$basic_machine-unknown + os=-none + ;; + m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k) + ;; + ms1) + basic_machine=mt-unknown + ;; + + # We use `pc' rather than `unknown' + # because (1) that's what they normally are, and + # (2) the word "unknown" tends to confuse beginning users. + i*86 | x86_64) + basic_machine=$basic_machine-pc + ;; + # Object if more than one company name word. + *-*-*) + echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 + exit 1 + ;; + # Recognize the basic CPU types with company name. + 580-* \ + | a29k-* \ + | alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \ + | alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \ + | alphapca5[67]-* | alpha64pca5[67]-* | arc-* \ + | arm-* | armbe-* | armle-* | armeb-* | armv*-* \ + | avr-* | avr32-* \ + | bfin-* | bs2000-* \ + | c[123]* | c30-* | [cjt]90-* | c4x-* | c54x-* | c55x-* | c6x-* \ + | clipper-* | craynv-* | cydra-* \ + | d10v-* | d30v-* | dlx-* \ + | elxsi-* \ + | f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \ + | h8300-* | h8500-* \ + | hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \ + | i*86-* | i860-* | i960-* | ia64-* \ + | ip2k-* | iq2000-* \ + | lm32-* \ + | m32c-* | m32r-* | m32rle-* \ + | m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \ + | m88110-* | m88k-* | maxq-* | mcore-* | metag-* \ + | mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \ + | mips16-* \ + | mips64-* | mips64el-* \ + | mips64octeon-* | mips64octeonel-* \ + | mips64orion-* | mips64orionel-* \ + | mips64r5900-* | mips64r5900el-* \ + | mips64vr-* | mips64vrel-* \ + | mips64vr4100-* | mips64vr4100el-* \ + | mips64vr4300-* | mips64vr4300el-* \ + | mips64vr5000-* | mips64vr5000el-* \ + | mips64vr5900-* | mips64vr5900el-* \ + | mipsisa32-* | mipsisa32el-* \ + | mipsisa32r2-* | mipsisa32r2el-* \ + | mipsisa64-* | mipsisa64el-* \ + | mipsisa64r2-* | mipsisa64r2el-* \ + | mipsisa64sb1-* | mipsisa64sb1el-* \ + | mipsisa64sr71k-* | mipsisa64sr71kel-* \ + | mipstx39-* | mipstx39el-* \ + | mmix-* \ + | mt-* \ + | msp430-* \ + | nios-* | nios2-* \ + | none-* | np1-* | ns16k-* | ns32k-* \ + | orion-* \ + | pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \ + | powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* | ppcbe-* \ + | pyramid-* \ + | romp-* | rs6000-* \ + | sh-* | sh[1234]-* | sh[24]a-* | sh[24]aeb-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \ + | shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \ + | sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \ + | sparclite-* \ + | sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | strongarm-* | sv1-* | sx?-* \ + | tahoe-* | thumb-* \ + | tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* | tile-* \ + | tron-* \ + | v850-* | v850e-* | vax-* \ + | we32k-* \ + | x86-* | x86_64-* | xc16x-* | xps100-* | xscale-* | xscalee[bl]-* \ + | xstormy16-* | xtensa*-* \ + | ymp-* \ + | z8k-* | z80-*) + ;; + # Recognize the basic CPU types without company name, with glob match. + xtensa*) + basic_machine=$basic_machine-unknown + ;; + # Recognize the various machine names and aliases which stand + # for a CPU type and a company and sometimes even an OS. + 386bsd) + basic_machine=i386-unknown + os=-bsd + ;; + 3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc) + basic_machine=m68000-att + ;; + 3b*) + basic_machine=we32k-att + ;; + a29khif) + basic_machine=a29k-amd + os=-udi + ;; + abacus) + basic_machine=abacus-unknown + ;; + adobe68k) + basic_machine=m68010-adobe + os=-scout + ;; + alliant | fx80) + basic_machine=fx80-alliant + ;; + altos | altos3068) + basic_machine=m68k-altos + ;; + am29k) + basic_machine=a29k-none + os=-bsd + ;; + amd64) + basic_machine=x86_64-pc + ;; + amd64-*) + basic_machine=x86_64-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + amdahl) + basic_machine=580-amdahl + os=-sysv + ;; + amiga | amiga-*) + basic_machine=m68k-unknown + ;; + amigaos | amigados) + basic_machine=m68k-unknown + os=-amigaos + ;; + amigaunix | amix) + basic_machine=m68k-unknown + os=-sysv4 + ;; + apollo68) + basic_machine=m68k-apollo + os=-sysv + ;; + apollo68bsd) + basic_machine=m68k-apollo + os=-bsd + ;; + aros) + basic_machine=i386-pc + os=-aros + ;; + aux) + basic_machine=m68k-apple + os=-aux + ;; + balance) + basic_machine=ns32k-sequent + os=-dynix + ;; + blackfin) + basic_machine=bfin-unknown + os=-linux + ;; + blackfin-*) + basic_machine=bfin-`echo $basic_machine | sed 's/^[^-]*-//'` + os=-linux + ;; + c90) + basic_machine=c90-cray + os=-unicos + ;; + cegcc) + basic_machine=arm-unknown + os=-cegcc + ;; + convex-c1) + basic_machine=c1-convex + os=-bsd + ;; + convex-c2) + basic_machine=c2-convex + os=-bsd + ;; + convex-c32) + basic_machine=c32-convex + os=-bsd + ;; + convex-c34) + basic_machine=c34-convex + os=-bsd + ;; + convex-c38) + basic_machine=c38-convex + os=-bsd + ;; + cray | j90) + basic_machine=j90-cray + os=-unicos + ;; + craynv) + basic_machine=craynv-cray + os=-unicosmp + ;; + cr16) + basic_machine=cr16-unknown + os=-elf + ;; + crds | unos) + basic_machine=m68k-crds + ;; + crisv32 | crisv32-* | etraxfs*) + basic_machine=crisv32-axis + ;; + cris | cris-* | etrax*) + basic_machine=cris-axis + ;; + crx) + basic_machine=crx-unknown + os=-elf + ;; + da30 | da30-*) + basic_machine=m68k-da30 + ;; + decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn) + basic_machine=mips-dec + ;; + decsystem10* | dec10*) + basic_machine=pdp10-dec + os=-tops10 + ;; + decsystem20* | dec20*) + basic_machine=pdp10-dec + os=-tops20 + ;; + delta | 3300 | motorola-3300 | motorola-delta \ + | 3300-motorola | delta-motorola) + basic_machine=m68k-motorola + ;; + delta88) + basic_machine=m88k-motorola + os=-sysv3 + ;; + dicos) + basic_machine=i686-pc + os=-dicos + ;; + djgpp) + basic_machine=i586-pc + os=-msdosdjgpp + ;; + dpx20 | dpx20-*) + basic_machine=rs6000-bull + os=-bosx + ;; + dpx2* | dpx2*-bull) + basic_machine=m68k-bull + os=-sysv3 + ;; + ebmon29k) + basic_machine=a29k-amd + os=-ebmon + ;; + elxsi) + basic_machine=elxsi-elxsi + os=-bsd + ;; + encore | umax | mmax) + basic_machine=ns32k-encore + ;; + es1800 | OSE68k | ose68k | ose | OSE) + basic_machine=m68k-ericsson + os=-ose + ;; + fx2800) + basic_machine=i860-alliant + ;; + genix) + basic_machine=ns32k-ns + ;; + gmicro) + basic_machine=tron-gmicro + os=-sysv + ;; + go32) + basic_machine=i386-pc + os=-go32 + ;; + h3050r* | hiux*) + basic_machine=hppa1.1-hitachi + os=-hiuxwe2 + ;; + h8300hms) + basic_machine=h8300-hitachi + os=-hms + ;; + h8300xray) + basic_machine=h8300-hitachi + os=-xray + ;; + h8500hms) + basic_machine=h8500-hitachi + os=-hms + ;; + harris) + basic_machine=m88k-harris + os=-sysv3 + ;; + hp300-*) + basic_machine=m68k-hp + ;; + hp300bsd) + basic_machine=m68k-hp + os=-bsd + ;; + hp300hpux) + basic_machine=m68k-hp + os=-hpux + ;; + hp3k9[0-9][0-9] | hp9[0-9][0-9]) + basic_machine=hppa1.0-hp + ;; + hp9k2[0-9][0-9] | hp9k31[0-9]) + basic_machine=m68000-hp + ;; + hp9k3[2-9][0-9]) + basic_machine=m68k-hp + ;; + hp9k6[0-9][0-9] | hp6[0-9][0-9]) + basic_machine=hppa1.0-hp + ;; + hp9k7[0-79][0-9] | hp7[0-79][0-9]) + basic_machine=hppa1.1-hp + ;; + hp9k78[0-9] | hp78[0-9]) + # FIXME: really hppa2.0-hp + basic_machine=hppa1.1-hp + ;; + hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893) + # FIXME: really hppa2.0-hp + basic_machine=hppa1.1-hp + ;; + hp9k8[0-9][13679] | hp8[0-9][13679]) + basic_machine=hppa1.1-hp + ;; + hp9k8[0-9][0-9] | hp8[0-9][0-9]) + basic_machine=hppa1.0-hp + ;; + hppa-next) + os=-nextstep3 + ;; + hppaosf) + basic_machine=hppa1.1-hp + os=-osf + ;; + hppro) + basic_machine=hppa1.1-hp + os=-proelf + ;; + i370-ibm* | ibm*) + basic_machine=i370-ibm + ;; +# I'm not sure what "Sysv32" means. Should this be sysv3.2? + i*86v32) + basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` + os=-sysv32 + ;; + i*86v4*) + basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` + os=-sysv4 + ;; + i*86v) + basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` + os=-sysv + ;; + i*86sol2) + basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` + os=-solaris2 + ;; + i386mach) + basic_machine=i386-mach + os=-mach + ;; + i386-vsta | vsta) + basic_machine=i386-unknown + os=-vsta + ;; + iris | iris4d) + basic_machine=mips-sgi + case $os in + -irix*) + ;; + *) + os=-irix4 + ;; + esac + ;; + isi68 | isi) + basic_machine=m68k-isi + os=-sysv + ;; + m68knommu) + basic_machine=m68k-unknown + os=-linux + ;; + m68knommu-*) + basic_machine=m68k-`echo $basic_machine | sed 's/^[^-]*-//'` + os=-linux + ;; + m88k-omron*) + basic_machine=m88k-omron + ;; + magnum | m3230) + basic_machine=mips-mips + os=-sysv + ;; + merlin) + basic_machine=ns32k-utek + os=-sysv + ;; + mingw32) + basic_machine=i386-pc + os=-mingw32 + ;; + mingw32ce) + basic_machine=arm-unknown + os=-mingw32ce + ;; + miniframe) + basic_machine=m68000-convergent + ;; + *mint | -mint[0-9]* | *MiNT | *MiNT[0-9]*) + basic_machine=m68k-atari + os=-mint + ;; + mips3*-*) + basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'` + ;; + mips3*) + basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown + ;; + monitor) + basic_machine=m68k-rom68k + os=-coff + ;; + morphos) + basic_machine=powerpc-unknown + os=-morphos + ;; + msdos) + basic_machine=i386-pc + os=-msdos + ;; + ms1-*) + basic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'` + ;; + mvs) + basic_machine=i370-ibm + os=-mvs + ;; + ncr3000) + basic_machine=i486-ncr + os=-sysv4 + ;; + netbsd386) + basic_machine=i386-unknown + os=-netbsd + ;; + netwinder) + basic_machine=armv4l-rebel + os=-linux + ;; + news | news700 | news800 | news900) + basic_machine=m68k-sony + os=-newsos + ;; + news1000) + basic_machine=m68030-sony + os=-newsos + ;; + news-3600 | risc-news) + basic_machine=mips-sony + os=-newsos + ;; + necv70) + basic_machine=v70-nec + os=-sysv + ;; + next | m*-next ) + basic_machine=m68k-next + case $os in + -nextstep* ) + ;; + -ns2*) + os=-nextstep2 + ;; + *) + os=-nextstep3 + ;; + esac + ;; + nh3000) + basic_machine=m68k-harris + os=-cxux + ;; + nh[45]000) + basic_machine=m88k-harris + os=-cxux + ;; + nindy960) + basic_machine=i960-intel + os=-nindy + ;; + mon960) + basic_machine=i960-intel + os=-mon960 + ;; + nonstopux) + basic_machine=mips-compaq + os=-nonstopux + ;; + np1) + basic_machine=np1-gould + ;; + nsr-tandem) + basic_machine=nsr-tandem + ;; + op50n-* | op60c-*) + basic_machine=hppa1.1-oki + os=-proelf + ;; + openrisc | openrisc-*) + basic_machine=or32-unknown + ;; + os400) + basic_machine=powerpc-ibm + os=-os400 + ;; + OSE68000 | ose68000) + basic_machine=m68000-ericsson + os=-ose + ;; + os68k) + basic_machine=m68k-none + os=-os68k + ;; + pa-hitachi) + basic_machine=hppa1.1-hitachi + os=-hiuxwe2 + ;; + paragon) + basic_machine=i860-intel + os=-osf + ;; + parisc) + basic_machine=hppa-unknown + os=-linux + ;; + parisc-*) + basic_machine=hppa-`echo $basic_machine | sed 's/^[^-]*-//'` + os=-linux + ;; + pbd) + basic_machine=sparc-tti + ;; + pbb) + basic_machine=m68k-tti + ;; + pc532 | pc532-*) + basic_machine=ns32k-pc532 + ;; + pc98) + basic_machine=i386-pc + ;; + pc98-*) + basic_machine=i386-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pentium | p5 | k5 | k6 | nexgen | viac3) + basic_machine=i586-pc + ;; + pentiumpro | p6 | 6x86 | athlon | athlon_*) + basic_machine=i686-pc + ;; + pentiumii | pentium2 | pentiumiii | pentium3) + basic_machine=i686-pc + ;; + pentium4) + basic_machine=i786-pc + ;; + pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*) + basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pentiumpro-* | p6-* | 6x86-* | athlon-*) + basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*) + basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pentium4-*) + basic_machine=i786-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pn) + basic_machine=pn-gould + ;; + power) basic_machine=power-ibm + ;; + ppc) basic_machine=powerpc-unknown + ;; + ppc-*) basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + ppcle | powerpclittle | ppc-le | powerpc-little) + basic_machine=powerpcle-unknown + ;; + ppcle-* | powerpclittle-*) + basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + ppc64) basic_machine=powerpc64-unknown + ;; + ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + ppc64le | powerpc64little | ppc64-le | powerpc64-little) + basic_machine=powerpc64le-unknown + ;; + ppc64le-* | powerpc64little-*) + basic_machine=powerpc64le-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + ps2) + basic_machine=i386-ibm + ;; + pw32) + basic_machine=i586-unknown + os=-pw32 + ;; + rdos) + basic_machine=i386-pc + os=-rdos + ;; + rom68k) + basic_machine=m68k-rom68k + os=-coff + ;; + rm[46]00) + basic_machine=mips-siemens + ;; + rtpc | rtpc-*) + basic_machine=romp-ibm + ;; + s390 | s390-*) + basic_machine=s390-ibm + ;; + s390x | s390x-*) + basic_machine=s390x-ibm + ;; + sa29200) + basic_machine=a29k-amd + os=-udi + ;; + sb1) + basic_machine=mipsisa64sb1-unknown + ;; + sb1el) + basic_machine=mipsisa64sb1el-unknown + ;; + sde) + basic_machine=mipsisa32-sde + os=-elf + ;; + sei) + basic_machine=mips-sei + os=-seiux + ;; + sequent) + basic_machine=i386-sequent + ;; + sh) + basic_machine=sh-hitachi + os=-hms + ;; + sh5el) + basic_machine=sh5le-unknown + ;; + sh64) + basic_machine=sh64-unknown + ;; + sparclite-wrs | simso-wrs) + basic_machine=sparclite-wrs + os=-vxworks + ;; + sps7) + basic_machine=m68k-bull + os=-sysv2 + ;; + spur) + basic_machine=spur-unknown + ;; + st2000) + basic_machine=m68k-tandem + ;; + stratus) + basic_machine=i860-stratus + os=-sysv4 + ;; + sun2) + basic_machine=m68000-sun + ;; + sun2os3) + basic_machine=m68000-sun + os=-sunos3 + ;; + sun2os4) + basic_machine=m68000-sun + os=-sunos4 + ;; + sun3os3) + basic_machine=m68k-sun + os=-sunos3 + ;; + sun3os4) + basic_machine=m68k-sun + os=-sunos4 + ;; + sun4os3) + basic_machine=sparc-sun + os=-sunos3 + ;; + sun4os4) + basic_machine=sparc-sun + os=-sunos4 + ;; + sun4sol2) + basic_machine=sparc-sun + os=-solaris2 + ;; + sun3 | sun3-*) + basic_machine=m68k-sun + ;; + sun4) + basic_machine=sparc-sun + ;; + sun386 | sun386i | roadrunner) + basic_machine=i386-sun + ;; + sv1) + basic_machine=sv1-cray + os=-unicos + ;; + symmetry) + basic_machine=i386-sequent + os=-dynix + ;; + t3e) + basic_machine=alphaev5-cray + os=-unicos + ;; + t90) + basic_machine=t90-cray + os=-unicos + ;; + tic54x | c54x*) + basic_machine=tic54x-unknown + os=-coff + ;; + tic55x | c55x*) + basic_machine=tic55x-unknown + os=-coff + ;; + tic6x | c6x*) + basic_machine=tic6x-unknown + os=-coff + ;; + tile*) + basic_machine=tile-unknown + os=-linux-gnu + ;; + tx39) + basic_machine=mipstx39-unknown + ;; + tx39el) + basic_machine=mipstx39el-unknown + ;; + toad1) + basic_machine=pdp10-xkl + os=-tops20 + ;; + tower | tower-32) + basic_machine=m68k-ncr + ;; + tpf) + basic_machine=s390x-ibm + os=-tpf + ;; + udi29k) + basic_machine=a29k-amd + os=-udi + ;; + ultra3) + basic_machine=a29k-nyu + os=-sym1 + ;; + v810 | necv810) + basic_machine=v810-nec + os=-none + ;; + vaxv) + basic_machine=vax-dec + os=-sysv + ;; + vms) + basic_machine=vax-dec + os=-vms + ;; + vpp*|vx|vx-*) + basic_machine=f301-fujitsu + ;; + vxworks960) + basic_machine=i960-wrs + os=-vxworks + ;; + vxworks68) + basic_machine=m68k-wrs + os=-vxworks + ;; + vxworks29k) + basic_machine=a29k-wrs + os=-vxworks + ;; + w65*) + basic_machine=w65-wdc + os=-none + ;; + w89k-*) + basic_machine=hppa1.1-winbond + os=-proelf + ;; + xbox) + basic_machine=i686-pc + os=-mingw32 + ;; + xps | xps100) + basic_machine=xps100-honeywell + ;; + ymp) + basic_machine=ymp-cray + os=-unicos + ;; + z8k-*-coff) + basic_machine=z8k-unknown + os=-sim + ;; + z80-*-coff) + basic_machine=z80-unknown + os=-sim + ;; + none) + basic_machine=none-none + os=-none + ;; + +# Here we handle the default manufacturer of certain CPU types. It is in +# some cases the only manufacturer, in others, it is the most popular. + w89k) + basic_machine=hppa1.1-winbond + ;; + op50n) + basic_machine=hppa1.1-oki + ;; + op60c) + basic_machine=hppa1.1-oki + ;; + romp) + basic_machine=romp-ibm + ;; + mmix) + basic_machine=mmix-knuth + ;; + rs6000) + basic_machine=rs6000-ibm + ;; + vax) + basic_machine=vax-dec + ;; + pdp10) + # there are many clones, so DEC is not a safe bet + basic_machine=pdp10-unknown + ;; + pdp11) + basic_machine=pdp11-dec + ;; + we32k) + basic_machine=we32k-att + ;; + sh[1234] | sh[24]a | sh[24]aeb | sh[34]eb | sh[1234]le | sh[23]ele) + basic_machine=sh-unknown + ;; + sparc | sparcv8 | sparcv9 | sparcv9b | sparcv9v) + basic_machine=sparc-sun + ;; + cydra) + basic_machine=cydra-cydrome + ;; + orion) + basic_machine=orion-highlevel + ;; + orion105) + basic_machine=clipper-highlevel + ;; + mac | mpw | mac-mpw) + basic_machine=m68k-apple + ;; + pmac | pmac-mpw) + basic_machine=powerpc-apple + ;; + *-unknown) + # Make sure to match an already-canonicalized machine name. + ;; + *) + echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 + exit 1 + ;; +esac + +# Here we canonicalize certain aliases for manufacturers. +case $basic_machine in + *-digital*) + basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'` + ;; + *-commodore*) + basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'` + ;; + *) + ;; +esac + +# Decode manufacturer-specific aliases for certain operating systems. + +if [ x"$os" != x"" ] +then +case $os in + # First match some system type aliases + # that might get confused with valid system types. + # -solaris* is a basic system type, with this one exception. + -solaris1 | -solaris1.*) + os=`echo $os | sed -e 's|solaris1|sunos4|'` + ;; + -solaris) + os=-solaris2 + ;; + -svr4*) + os=-sysv4 + ;; + -unixware*) + os=-sysv4.2uw + ;; + -gnu/linux*) + os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'` + ;; + # First accept the basic system types. + # The portable systems comes first. + # Each alternative MUST END IN A *, to match a version number. + # -sysv* is not here because it comes later, after sysvr4. + -gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \ + | -*vms* | -sco* | -esix* | -isc* | -aix* | -sunos | -sunos[34]*\ + | -hpux* | -unos* | -osf* | -luna* | -dgux* | -solaris* | -sym* \ + | -kopensolaris* \ + | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \ + | -aos* | -aros* \ + | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \ + | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \ + | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \ + | -openbsd* | -solidbsd* \ + | -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \ + | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \ + | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \ + | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \ + | -chorusos* | -chorusrdb* | -cegcc* \ + | -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \ + | -mingw32* | -linux-gnu* | -linux-newlib* | -linux-uclibc* \ + | -uxpv* | -beos* | -mpeix* | -udk* \ + | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \ + | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \ + | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \ + | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \ + | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \ + | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \ + | -skyos* | -haiku* | -rdos* | -toppers* | -drops*) + # Remember, each alternative MUST END IN *, to match a version number. + ;; + -qnx*) + case $basic_machine in + x86-* | i*86-*) + ;; + *) + os=-nto$os + ;; + esac + ;; + -nto-qnx*) + ;; + -nto*) + os=`echo $os | sed -e 's|nto|nto-qnx|'` + ;; + -sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \ + | -windows* | -osx | -abug | -netware* | -os9* | -beos* | -haiku* \ + | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*) + ;; + -mac*) + os=`echo $os | sed -e 's|mac|macos|'` + ;; + -linux-dietlibc) + os=-linux-dietlibc + ;; + -linux*) + os=`echo $os | sed -e 's|linux|linux-gnu|'` + ;; + -sunos5*) + os=`echo $os | sed -e 's|sunos5|solaris2|'` + ;; + -sunos6*) + os=`echo $os | sed -e 's|sunos6|solaris3|'` + ;; + -opened*) + os=-openedition + ;; + -os400*) + os=-os400 + ;; + -wince*) + os=-wince + ;; + -osfrose*) + os=-osfrose + ;; + -osf*) + os=-osf + ;; + -utek*) + os=-bsd + ;; + -dynix*) + os=-bsd + ;; + -acis*) + os=-aos + ;; + -atheos*) + os=-atheos + ;; + -syllable*) + os=-syllable + ;; + -386bsd) + os=-bsd + ;; + -ctix* | -uts*) + os=-sysv + ;; + -nova*) + os=-rtmk-nova + ;; + -ns2 ) + os=-nextstep2 + ;; + -nsk*) + os=-nsk + ;; + # Preserve the version number of sinix5. + -sinix5.*) + os=`echo $os | sed -e 's|sinix|sysv|'` + ;; + -sinix*) + os=-sysv4 + ;; + -tpf*) + os=-tpf + ;; + -triton*) + os=-sysv3 + ;; + -oss*) + os=-sysv3 + ;; + -svr4) + os=-sysv4 + ;; + -svr3) + os=-sysv3 + ;; + -sysvr4) + os=-sysv4 + ;; + # This must come after -sysvr4. + -sysv*) + ;; + -ose*) + os=-ose + ;; + -es1800*) + os=-ose + ;; + -xenix) + os=-xenix + ;; + -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) + os=-mint + ;; + -aros*) + os=-aros + ;; + -kaos*) + os=-kaos + ;; + -zvmoe) + os=-zvmoe + ;; + -dicos*) + os=-dicos + ;; + -none) + ;; + *) + # Get rid of the `-' at the beginning of $os. + os=`echo $os | sed 's/[^-]*-//'` + echo Invalid configuration \`$1\': system \`$os\' not recognized 1>&2 + exit 1 + ;; +esac +else + +# Here we handle the default operating systems that come with various machines. +# The value should be what the vendor currently ships out the door with their +# machine or put another way, the most popular os provided with the machine. + +# Note that if you're going to try to match "-MANUFACTURER" here (say, +# "-sun"), then you have to tell the case statement up towards the top +# that MANUFACTURER isn't an operating system. Otherwise, code above +# will signal an error saying that MANUFACTURER isn't an operating +# system, and we'll never get to this point. + +case $basic_machine in + score-*) + os=-elf + ;; + spu-*) + os=-elf + ;; + *-acorn) + os=-riscix1.2 + ;; + arm*-rebel) + os=-linux + ;; + arm*-semi) + os=-aout + ;; + c4x-* | tic4x-*) + os=-coff + ;; + # This must come before the *-dec entry. + pdp10-*) + os=-tops20 + ;; + pdp11-*) + os=-none + ;; + *-dec | vax-*) + os=-ultrix4.2 + ;; + m68*-apollo) + os=-domain + ;; + i386-sun) + os=-sunos4.0.2 + ;; + m68000-sun) + os=-sunos3 + # This also exists in the configure program, but was not the + # default. + # os=-sunos4 + ;; + m68*-cisco) + os=-aout + ;; + mep-*) + os=-elf + ;; + mips*-cisco) + os=-elf + ;; + mips*-*) + os=-elf + ;; + or32-*) + os=-coff + ;; + *-tti) # must be before sparc entry or we get the wrong os. + os=-sysv3 + ;; + sparc-* | *-sun) + os=-sunos4.1.1 + ;; + *-be) + os=-beos + ;; + *-haiku) + os=-haiku + ;; + *-ibm) + os=-aix + ;; + *-knuth) + os=-mmixware + ;; + *-wec) + os=-proelf + ;; + *-winbond) + os=-proelf + ;; + *-oki) + os=-proelf + ;; + *-hp) + os=-hpux + ;; + *-hitachi) + os=-hiux + ;; + i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent) + os=-sysv + ;; + *-cbm) + os=-amigaos + ;; + *-dg) + os=-dgux + ;; + *-dolphin) + os=-sysv3 + ;; + m68k-ccur) + os=-rtu + ;; + m88k-omron*) + os=-luna + ;; + *-next ) + os=-nextstep + ;; + *-sequent) + os=-ptx + ;; + *-crds) + os=-unos + ;; + *-ns) + os=-genix + ;; + i370-*) + os=-mvs + ;; + *-next) + os=-nextstep3 + ;; + *-gould) + os=-sysv + ;; + *-highlevel) + os=-bsd + ;; + *-encore) + os=-bsd + ;; + *-sgi) + os=-irix + ;; + *-siemens) + os=-sysv4 + ;; + *-masscomp) + os=-rtu + ;; + f30[01]-fujitsu | f700-fujitsu) + os=-uxpv + ;; + *-rom68k) + os=-coff + ;; + *-*bug) + os=-coff + ;; + *-apple) + os=-macos + ;; + *-atari*) + os=-mint + ;; + *) + os=-none + ;; +esac +fi + +# Here we handle the case where we know the os, and the CPU type, but not the +# manufacturer. We pick the logical manufacturer. +vendor=unknown +case $basic_machine in + *-unknown) + case $os in + -riscix*) + vendor=acorn + ;; + -sunos*) + vendor=sun + ;; + -aix*) + vendor=ibm + ;; + -beos*) + vendor=be + ;; + -hpux*) + vendor=hp + ;; + -mpeix*) + vendor=hp + ;; + -hiux*) + vendor=hitachi + ;; + -unos*) + vendor=crds + ;; + -dgux*) + vendor=dg + ;; + -luna*) + vendor=omron + ;; + -genix*) + vendor=ns + ;; + -mvs* | -opened*) + vendor=ibm + ;; + -os400*) + vendor=ibm + ;; + -ptx*) + vendor=sequent + ;; + -tpf*) + vendor=ibm + ;; + -vxsim* | -vxworks* | -windiss*) + vendor=wrs + ;; + -aux*) + vendor=apple + ;; + -hms*) + vendor=hitachi + ;; + -mpw* | -macos*) + vendor=apple + ;; + -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) + vendor=atari + ;; + -vos*) + vendor=stratus + ;; + esac + basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"` + ;; +esac + +echo $basic_machine$os +exit + +# Local variables: +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "timestamp='" +# time-stamp-format: "%:y-%02m-%02d" +# time-stamp-end: "'" +# End: diff --git a/libs/libpng-src/configure b/libs/libpng-src/configure new file mode 100755 index 000000000..89657aae0 --- /dev/null +++ b/libs/libpng-src/configure @@ -0,0 +1,13891 @@ +#! /bin/sh +# Guess values for system-dependent variables and create Makefiles. +# Generated by GNU Autoconf 2.65 for libpng 1.2.46. +# +# Report bugs to . +# +# +# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, +# 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, +# Inc. +# +# +# This configure script is free software; the Free Software Foundation +# gives unlimited permission to copy, distribute and modify it. +## -------------------- ## +## M4sh Initialization. ## +## -------------------- ## + +# Be more Bourne compatible +DUALCASE=1; export DUALCASE # for MKS sh +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then : + emulate sh + NULLCMD=: + # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in #( + *posix*) : + set -o posix ;; #( + *) : + ;; +esac +fi + + +as_nl=' +' +export as_nl +# Printing a long string crashes Solaris 7 /usr/bin/printf. +as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' +as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo +as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo +# Prefer a ksh shell builtin over an external printf program on Solaris, +# but without wasting forks for bash or zsh. +if test -z "$BASH_VERSION$ZSH_VERSION" \ + && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then + as_echo='print -r --' + as_echo_n='print -rn --' +elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then + as_echo='printf %s\n' + as_echo_n='printf %s' +else + if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then + as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"' + as_echo_n='/usr/ucb/echo -n' + else + as_echo_body='eval expr "X$1" : "X\\(.*\\)"' + as_echo_n_body='eval + arg=$1; + case $arg in #( + *"$as_nl"*) + expr "X$arg" : "X\\(.*\\)$as_nl"; + arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;; + esac; + expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl" + ' + export as_echo_n_body + as_echo_n='sh -c $as_echo_n_body as_echo' + fi + export as_echo_body + as_echo='sh -c $as_echo_body as_echo' +fi + +# The user is always right. +if test "${PATH_SEPARATOR+set}" != set; then + PATH_SEPARATOR=: + (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { + (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || + PATH_SEPARATOR=';' + } +fi + + +# IFS +# We need space, tab and new line, in precisely that order. Quoting is +# there to prevent editors from complaining about space-tab. +# (If _AS_PATH_WALK were called with IFS unset, it would disable word +# splitting by setting IFS to empty value.) +IFS=" "" $as_nl" + +# Find who we are. Look in the path if we contain no directory separator. +case $0 in #(( + *[\\/]* ) as_myself=$0 ;; + *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break + done +IFS=$as_save_IFS + + ;; +esac +# We did not find ourselves, most probably we were run as `sh COMMAND' +# in which case we are not to be found in the path. +if test "x$as_myself" = x; then + as_myself=$0 +fi +if test ! -f "$as_myself"; then + $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 + exit 1 +fi + +# Unset variables that we do not need and which cause bugs (e.g. in +# pre-3.0 UWIN ksh). But do not cause bugs in bash 2.01; the "|| exit 1" +# suppresses any "Segmentation fault" message there. '((' could +# trigger a bug in pdksh 5.2.14. +for as_var in BASH_ENV ENV MAIL MAILPATH +do eval test x\${$as_var+set} = xset \ + && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : +done +PS1='$ ' +PS2='> ' +PS4='+ ' + +# NLS nuisances. +LC_ALL=C +export LC_ALL +LANGUAGE=C +export LANGUAGE + +# CDPATH. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + +if test "x$CONFIG_SHELL" = x; then + as_bourne_compatible="if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then : + emulate sh + NULLCMD=: + # Pre-4.2 versions of Zsh do word splitting on \${1+\"\$@\"}, which + # is contrary to our usage. Disable this feature. + alias -g '\${1+\"\$@\"}'='\"\$@\"' + setopt NO_GLOB_SUBST +else + case \`(set -o) 2>/dev/null\` in #( + *posix*) : + set -o posix ;; #( + *) : + ;; +esac +fi +" + as_required="as_fn_return () { (exit \$1); } +as_fn_success () { as_fn_return 0; } +as_fn_failure () { as_fn_return 1; } +as_fn_ret_success () { return 0; } +as_fn_ret_failure () { return 1; } + +exitcode=0 +as_fn_success || { exitcode=1; echo as_fn_success failed.; } +as_fn_failure && { exitcode=1; echo as_fn_failure succeeded.; } +as_fn_ret_success || { exitcode=1; echo as_fn_ret_success failed.; } +as_fn_ret_failure && { exitcode=1; echo as_fn_ret_failure succeeded.; } +if ( set x; as_fn_ret_success y && test x = \"\$1\" ); then : + +else + exitcode=1; echo positional parameters were not saved. +fi +test x\$exitcode = x0 || exit 1" + as_suggested=" as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO + as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO + eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" && + test \"x\`expr \$as_lineno_1'\$as_run' + 1\`\" = \"x\$as_lineno_2'\$as_run'\"' || exit 1 +test \$(( 1 + 1 )) = 2 || exit 1" + if (eval "$as_required") 2>/dev/null; then : + as_have_required=yes +else + as_have_required=no +fi + if test x$as_have_required = xyes && (eval "$as_suggested") 2>/dev/null; then : + +else + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +as_found=false +for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + as_found=: + case $as_dir in #( + /*) + for as_base in sh bash ksh sh5; do + # Try only shells that exist, to save several forks. + as_shell=$as_dir/$as_base + if { test -f "$as_shell" || test -f "$as_shell.exe"; } && + { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$as_shell"; } 2>/dev/null; then : + CONFIG_SHELL=$as_shell as_have_required=yes + if { $as_echo "$as_bourne_compatible""$as_suggested" | as_run=a "$as_shell"; } 2>/dev/null; then : + break 2 +fi +fi + done;; + esac + as_found=false +done +$as_found || { if { test -f "$SHELL" || test -f "$SHELL.exe"; } && + { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$SHELL"; } 2>/dev/null; then : + CONFIG_SHELL=$SHELL as_have_required=yes +fi; } +IFS=$as_save_IFS + + + if test "x$CONFIG_SHELL" != x; then : + # We cannot yet assume a decent shell, so we have to provide a + # neutralization value for shells without unset; and this also + # works around shells that cannot unset nonexistent variables. + BASH_ENV=/dev/null + ENV=/dev/null + (unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV + export CONFIG_SHELL + exec "$CONFIG_SHELL" "$as_myself" ${1+"$@"} +fi + + if test x$as_have_required = xno; then : + $as_echo "$0: This script requires a shell more modern than all" + $as_echo "$0: the shells that I found on your system." + if test x${ZSH_VERSION+set} = xset ; then + $as_echo "$0: In particular, zsh $ZSH_VERSION has bugs and should" + $as_echo "$0: be upgraded to zsh 4.3.4 or later." + else + $as_echo "$0: Please tell bug-autoconf@gnu.org and +$0: png-mng-implement@lists.sourceforge.net about your +$0: system, including any error possibly output before this +$0: message. Then install a modern shell, or manually run +$0: the script under such a shell if you do have one." + fi + exit 1 +fi +fi +fi +SHELL=${CONFIG_SHELL-/bin/sh} +export SHELL +# Unset more variables known to interfere with behavior of common tools. +CLICOLOR_FORCE= GREP_OPTIONS= +unset CLICOLOR_FORCE GREP_OPTIONS + +## --------------------- ## +## M4sh Shell Functions. ## +## --------------------- ## +# as_fn_unset VAR +# --------------- +# Portably unset VAR. +as_fn_unset () +{ + { eval $1=; unset $1;} +} +as_unset=as_fn_unset + +# as_fn_set_status STATUS +# ----------------------- +# Set $? to STATUS, without forking. +as_fn_set_status () +{ + return $1 +} # as_fn_set_status + +# as_fn_exit STATUS +# ----------------- +# Exit the shell with STATUS, even in a "trap 0" or "set -e" context. +as_fn_exit () +{ + set +e + as_fn_set_status $1 + exit $1 +} # as_fn_exit + +# as_fn_mkdir_p +# ------------- +# Create "$as_dir" as a directory, including parents if necessary. +as_fn_mkdir_p () +{ + + case $as_dir in #( + -*) as_dir=./$as_dir;; + esac + test -d "$as_dir" || eval $as_mkdir_p || { + as_dirs= + while :; do + case $as_dir in #( + *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( + *) as_qdir=$as_dir;; + esac + as_dirs="'$as_qdir' $as_dirs" + as_dir=`$as_dirname -- "$as_dir" || +$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$as_dir" : 'X\(//\)[^/]' \| \ + X"$as_dir" : 'X\(//\)$' \| \ + X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X"$as_dir" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + test -d "$as_dir" && break + done + test -z "$as_dirs" || eval "mkdir $as_dirs" + } || test -d "$as_dir" || as_fn_error "cannot create directory $as_dir" + + +} # as_fn_mkdir_p +# as_fn_append VAR VALUE +# ---------------------- +# Append the text in VALUE to the end of the definition contained in VAR. Take +# advantage of any shell optimizations that allow amortized linear growth over +# repeated appends, instead of the typical quadratic growth present in naive +# implementations. +if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then : + eval 'as_fn_append () + { + eval $1+=\$2 + }' +else + as_fn_append () + { + eval $1=\$$1\$2 + } +fi # as_fn_append + +# as_fn_arith ARG... +# ------------------ +# Perform arithmetic evaluation on the ARGs, and store the result in the +# global $as_val. Take advantage of shells that can avoid forks. The arguments +# must be portable across $(()) and expr. +if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then : + eval 'as_fn_arith () + { + as_val=$(( $* )) + }' +else + as_fn_arith () + { + as_val=`expr "$@" || test $? -eq 1` + } +fi # as_fn_arith + + +# as_fn_error ERROR [LINENO LOG_FD] +# --------------------------------- +# Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are +# provided, also output the error to LOG_FD, referencing LINENO. Then exit the +# script with status $?, using 1 if that was 0. +as_fn_error () +{ + as_status=$?; test $as_status -eq 0 && as_status=1 + if test "$3"; then + as_lineno=${as_lineno-"$2"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + $as_echo "$as_me:${as_lineno-$LINENO}: error: $1" >&$3 + fi + $as_echo "$as_me: error: $1" >&2 + as_fn_exit $as_status +} # as_fn_error + +if expr a : '\(a\)' >/dev/null 2>&1 && + test "X`expr 00001 : '.*\(...\)'`" = X001; then + as_expr=expr +else + as_expr=false +fi + +if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then + as_basename=basename +else + as_basename=false +fi + +if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then + as_dirname=dirname +else + as_dirname=false +fi + +as_me=`$as_basename -- "$0" || +$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ + X"$0" : 'X\(//\)$' \| \ + X"$0" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X/"$0" | + sed '/^.*\/\([^/][^/]*\)\/*$/{ + s//\1/ + q + } + /^X\/\(\/\/\)$/{ + s//\1/ + q + } + /^X\/\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + +# Avoid depending upon Character Ranges. +as_cr_letters='abcdefghijklmnopqrstuvwxyz' +as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' +as_cr_Letters=$as_cr_letters$as_cr_LETTERS +as_cr_digits='0123456789' +as_cr_alnum=$as_cr_Letters$as_cr_digits + + + as_lineno_1=$LINENO as_lineno_1a=$LINENO + as_lineno_2=$LINENO as_lineno_2a=$LINENO + eval 'test "x$as_lineno_1'$as_run'" != "x$as_lineno_2'$as_run'" && + test "x`expr $as_lineno_1'$as_run' + 1`" = "x$as_lineno_2'$as_run'"' || { + # Blame Lee E. McMahon (1931-1989) for sed's syntax. :-) + sed -n ' + p + /[$]LINENO/= + ' <$as_myself | + sed ' + s/[$]LINENO.*/&-/ + t lineno + b + :lineno + N + :loop + s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/ + t loop + s/-\n.*// + ' >$as_me.lineno && + chmod +x "$as_me.lineno" || + { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; } + + # Don't try to exec as it changes $[0], causing all sort of problems + # (the dirname of $[0] is not the place where we might find the + # original and so on. Autoconf is especially sensitive to this). + . "./$as_me.lineno" + # Exit status is that of the last command. + exit +} + +ECHO_C= ECHO_N= ECHO_T= +case `echo -n x` in #((((( +-n*) + case `echo 'xy\c'` in + *c*) ECHO_T=' ';; # ECHO_T is single tab character. + xy) ECHO_C='\c';; + *) echo `echo ksh88 bug on AIX 6.1` > /dev/null + ECHO_T=' ';; + esac;; +*) + ECHO_N='-n';; +esac + +rm -f conf$$ conf$$.exe conf$$.file +if test -d conf$$.dir; then + rm -f conf$$.dir/conf$$.file +else + rm -f conf$$.dir + mkdir conf$$.dir 2>/dev/null +fi +if (echo >conf$$.file) 2>/dev/null; then + if ln -s conf$$.file conf$$ 2>/dev/null; then + as_ln_s='ln -s' + # ... but there are two gotchas: + # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. + # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. + # In both cases, we have to default to `cp -p'. + ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || + as_ln_s='cp -p' + elif ln conf$$.file conf$$ 2>/dev/null; then + as_ln_s=ln + else + as_ln_s='cp -p' + fi +else + as_ln_s='cp -p' +fi +rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file +rmdir conf$$.dir 2>/dev/null + +if mkdir -p . 2>/dev/null; then + as_mkdir_p='mkdir -p "$as_dir"' +else + test -d ./-p && rmdir ./-p + as_mkdir_p=false +fi + +if test -x / >/dev/null 2>&1; then + as_test_x='test -x' +else + if ls -dL / >/dev/null 2>&1; then + as_ls_L_option=L + else + as_ls_L_option= + fi + as_test_x=' + eval sh -c '\'' + if test -d "$1"; then + test -d "$1/."; + else + case $1 in #( + -*)set "./$1";; + esac; + case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in #(( + ???[sx]*):;;*)false;;esac;fi + '\'' sh + ' +fi +as_executable_p=$as_test_x + +# Sed expression to map a string onto a valid CPP name. +as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" + +# Sed expression to map a string onto a valid variable name. +as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" + + + +# Check that we are running under the correct shell. +SHELL=${CONFIG_SHELL-/bin/sh} + +case X$lt_ECHO in +X*--fallback-echo) + # Remove one level of quotation (which was required for Make). + ECHO=`echo "$lt_ECHO" | sed 's,\\\\\$\\$0,'$0','` + ;; +esac + +ECHO=${lt_ECHO-echo} +if test "X$1" = X--no-reexec; then + # Discard the --no-reexec flag, and continue. + shift +elif test "X$1" = X--fallback-echo; then + # Avoid inline document here, it may be left over + : +elif test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t' ; then + # Yippee, $ECHO works! + : +else + # Restart under the correct shell. + exec $SHELL "$0" --no-reexec ${1+"$@"} +fi + +if test "X$1" = X--fallback-echo; then + # used as fallback echo + shift + cat <<_LT_EOF +$* +_LT_EOF + exit 0 +fi + +# The HP-UX ksh and POSIX shell print the target directory to stdout +# if CDPATH is set. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + +if test -z "$lt_ECHO"; then + if test "X${echo_test_string+set}" != Xset; then + # find a string as large as possible, as long as the shell can cope with it + for cmd in 'sed 50q "$0"' 'sed 20q "$0"' 'sed 10q "$0"' 'sed 2q "$0"' 'echo test'; do + # expected sizes: less than 2Kb, 1Kb, 512 bytes, 16 bytes, ... + if { echo_test_string=`eval $cmd`; } 2>/dev/null && + { test "X$echo_test_string" = "X$echo_test_string"; } 2>/dev/null + then + break + fi + done + fi + + if test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t' && + echo_testing_string=`{ $ECHO "$echo_test_string"; } 2>/dev/null` && + test "X$echo_testing_string" = "X$echo_test_string"; then + : + else + # The Solaris, AIX, and Digital Unix default echo programs unquote + # backslashes. This makes it impossible to quote backslashes using + # echo "$something" | sed 's/\\/\\\\/g' + # + # So, first we look for a working echo in the user's PATH. + + lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR + for dir in $PATH /usr/ucb; do + IFS="$lt_save_ifs" + if (test -f $dir/echo || test -f $dir/echo$ac_exeext) && + test "X`($dir/echo '\t') 2>/dev/null`" = 'X\t' && + echo_testing_string=`($dir/echo "$echo_test_string") 2>/dev/null` && + test "X$echo_testing_string" = "X$echo_test_string"; then + ECHO="$dir/echo" + break + fi + done + IFS="$lt_save_ifs" + + if test "X$ECHO" = Xecho; then + # We didn't find a better echo, so look for alternatives. + if test "X`{ print -r '\t'; } 2>/dev/null`" = 'X\t' && + echo_testing_string=`{ print -r "$echo_test_string"; } 2>/dev/null` && + test "X$echo_testing_string" = "X$echo_test_string"; then + # This shell has a builtin print -r that does the trick. + ECHO='print -r' + elif { test -f /bin/ksh || test -f /bin/ksh$ac_exeext; } && + test "X$CONFIG_SHELL" != X/bin/ksh; then + # If we have ksh, try running configure again with it. + ORIGINAL_CONFIG_SHELL=${CONFIG_SHELL-/bin/sh} + export ORIGINAL_CONFIG_SHELL + CONFIG_SHELL=/bin/ksh + export CONFIG_SHELL + exec $CONFIG_SHELL "$0" --no-reexec ${1+"$@"} + else + # Try using printf. + ECHO='printf %s\n' + if test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t' && + echo_testing_string=`{ $ECHO "$echo_test_string"; } 2>/dev/null` && + test "X$echo_testing_string" = "X$echo_test_string"; then + # Cool, printf works + : + elif echo_testing_string=`($ORIGINAL_CONFIG_SHELL "$0" --fallback-echo '\t') 2>/dev/null` && + test "X$echo_testing_string" = 'X\t' && + echo_testing_string=`($ORIGINAL_CONFIG_SHELL "$0" --fallback-echo "$echo_test_string") 2>/dev/null` && + test "X$echo_testing_string" = "X$echo_test_string"; then + CONFIG_SHELL=$ORIGINAL_CONFIG_SHELL + export CONFIG_SHELL + SHELL="$CONFIG_SHELL" + export SHELL + ECHO="$CONFIG_SHELL $0 --fallback-echo" + elif echo_testing_string=`($CONFIG_SHELL "$0" --fallback-echo '\t') 2>/dev/null` && + test "X$echo_testing_string" = 'X\t' && + echo_testing_string=`($CONFIG_SHELL "$0" --fallback-echo "$echo_test_string") 2>/dev/null` && + test "X$echo_testing_string" = "X$echo_test_string"; then + ECHO="$CONFIG_SHELL $0 --fallback-echo" + else + # maybe with a smaller string... + prev=: + + for cmd in 'echo test' 'sed 2q "$0"' 'sed 10q "$0"' 'sed 20q "$0"' 'sed 50q "$0"'; do + if { test "X$echo_test_string" = "X`eval $cmd`"; } 2>/dev/null + then + break + fi + prev="$cmd" + done + + if test "$prev" != 'sed 50q "$0"'; then + echo_test_string=`eval $prev` + export echo_test_string + exec ${ORIGINAL_CONFIG_SHELL-${CONFIG_SHELL-/bin/sh}} "$0" ${1+"$@"} + else + # Oops. We lost completely, so just stick with echo. + ECHO=echo + fi + fi + fi + fi + fi +fi + +# Copy echo and quote the copy suitably for passing to libtool from +# the Makefile, instead of quoting the original, which is used later. +lt_ECHO=$ECHO +if test "X$lt_ECHO" = "X$CONFIG_SHELL $0 --fallback-echo"; then + lt_ECHO="$CONFIG_SHELL \\\$\$0 --fallback-echo" +fi + + + + +test -n "$DJDIR" || exec 7<&0 &1 + +# Name of the host. +# hostname on some systems (SVR3.2, Linux) returns a bogus exit status, +# so uname gets run too. +ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q` + +# +# Initializations. +# +ac_default_prefix=/usr/local +ac_clean_files= +ac_config_libobj_dir=. +LIBOBJS= +cross_compiling=no +subdirs= +MFLAGS= +MAKEFLAGS= + +# Identity of this package. +PACKAGE_NAME='libpng' +PACKAGE_TARNAME='libpng' +PACKAGE_VERSION='1.2.46' +PACKAGE_STRING='libpng 1.2.46' +PACKAGE_BUGREPORT='png-mng-implement@lists.sourceforge.net' +PACKAGE_URL='' + +ac_unique_file="pngget.c" +# Factoring default headers for most tests. +ac_includes_default="\ +#include +#ifdef HAVE_SYS_TYPES_H +# include +#endif +#ifdef HAVE_SYS_STAT_H +# include +#endif +#ifdef STDC_HEADERS +# include +# include +#else +# ifdef HAVE_STDLIB_H +# include +# endif +#endif +#ifdef HAVE_STRING_H +# if !defined STDC_HEADERS && defined HAVE_MEMORY_H +# include +# endif +# include +#endif +#ifdef HAVE_STRINGS_H +# include +#endif +#ifdef HAVE_INTTYPES_H +# include +#endif +#ifdef HAVE_STDINT_H +# include +#endif +#ifdef HAVE_UNISTD_H +# include +#endif" + +ac_subst_vars='am__EXEEXT_FALSE +am__EXEEXT_TRUE +LTLIBOBJS +compatlib +binconfigs +pkgconfigdir +PNGLIB_RELEASE +PNGLIB_MINOR +PNGLIB_MAJOR +PNGLIB_VERSION +SYMBOL_PREFIX +HAVE_LD_VERSION_SCRIPT_FALSE +HAVE_LD_VERSION_SCRIPT_TRUE +LIBPNG_NO_MMX +LIBPNG_DEFINES +LIBOBJS +POW_LIB +OTOOL64 +OTOOL +LIPO +NMEDIT +DSYMUTIL +lt_ECHO +RANLIB +AR +NM +ac_ct_DUMPBIN +DUMPBIN +LIBTOOL +LN_S +OBJDUMP +DLLTOOL +AS +CPP +LD +FGREP +EGREP +GREP +SED +host_os +host_vendor +host_cpu +host +build_os +build_vendor +build_cpu +build +am__fastdepCC_FALSE +am__fastdepCC_TRUE +CCDEPMODE +AMDEPBACKSLASH +AMDEP_FALSE +AMDEP_TRUE +am__quote +am__include +DEPDIR +OBJEXT +EXEEXT +ac_ct_CC +CPPFLAGS +LDFLAGS +CFLAGS +CC +MAINT +MAINTAINER_MODE_FALSE +MAINTAINER_MODE_TRUE +am__untar +am__tar +AMTAR +am__leading_dot +SET_MAKE +AWK +mkdir_p +MKDIR_P +INSTALL_STRIP_PROGRAM +STRIP +install_sh +MAKEINFO +AUTOHEADER +AUTOMAKE +AUTOCONF +ACLOCAL +VERSION +PACKAGE +CYGPATH_W +am__isrc +INSTALL_DATA +INSTALL_SCRIPT +INSTALL_PROGRAM +target_alias +host_alias +build_alias +LIBS +ECHO_T +ECHO_N +ECHO_C +DEFS +mandir +localedir +libdir +psdir +pdfdir +dvidir +htmldir +infodir +docdir +oldincludedir +includedir +localstatedir +sharedstatedir +sysconfdir +datadir +datarootdir +libexecdir +sbindir +bindir +program_transform_name +prefix +exec_prefix +PACKAGE_URL +PACKAGE_BUGREPORT +PACKAGE_STRING +PACKAGE_VERSION +PACKAGE_TARNAME +PACKAGE_NAME +PATH_SEPARATOR +SHELL' +ac_subst_files='' +ac_user_opts=' +enable_option_checking +enable_maintainer_mode +enable_dependency_tracking +with_gnu_ld +enable_shared +enable_static +with_pic +enable_fast_install +enable_libtool_lock +with_pkgconfigdir +with_binconfigs +with_libpng_compat +' + ac_precious_vars='build_alias +host_alias +target_alias +CC +CFLAGS +LDFLAGS +LIBS +CPPFLAGS +CPP' + + +# Initialize some variables set by options. +ac_init_help= +ac_init_version=false +ac_unrecognized_opts= +ac_unrecognized_sep= +# The variables have the same names as the options, with +# dashes changed to underlines. +cache_file=/dev/null +exec_prefix=NONE +no_create= +no_recursion= +prefix=NONE +program_prefix=NONE +program_suffix=NONE +program_transform_name=s,x,x, +silent= +site= +srcdir= +verbose= +x_includes=NONE +x_libraries=NONE + +# Installation directory options. +# These are left unexpanded so users can "make install exec_prefix=/foo" +# and all the variables that are supposed to be based on exec_prefix +# by default will actually change. +# Use braces instead of parens because sh, perl, etc. also accept them. +# (The list follows the same order as the GNU Coding Standards.) +bindir='${exec_prefix}/bin' +sbindir='${exec_prefix}/sbin' +libexecdir='${exec_prefix}/libexec' +datarootdir='${prefix}/share' +datadir='${datarootdir}' +sysconfdir='${prefix}/etc' +sharedstatedir='${prefix}/com' +localstatedir='${prefix}/var' +includedir='${prefix}/include' +oldincludedir='/usr/include' +docdir='${datarootdir}/doc/${PACKAGE_TARNAME}' +infodir='${datarootdir}/info' +htmldir='${docdir}' +dvidir='${docdir}' +pdfdir='${docdir}' +psdir='${docdir}' +libdir='${exec_prefix}/lib' +localedir='${datarootdir}/locale' +mandir='${datarootdir}/man' + +ac_prev= +ac_dashdash= +for ac_option +do + # If the previous option needs an argument, assign it. + if test -n "$ac_prev"; then + eval $ac_prev=\$ac_option + ac_prev= + continue + fi + + case $ac_option in + *=*) ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;; + *) ac_optarg=yes ;; + esac + + # Accept the important Cygnus configure options, so we can diagnose typos. + + case $ac_dashdash$ac_option in + --) + ac_dashdash=yes ;; + + -bindir | --bindir | --bindi | --bind | --bin | --bi) + ac_prev=bindir ;; + -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*) + bindir=$ac_optarg ;; + + -build | --build | --buil | --bui | --bu) + ac_prev=build_alias ;; + -build=* | --build=* | --buil=* | --bui=* | --bu=*) + build_alias=$ac_optarg ;; + + -cache-file | --cache-file | --cache-fil | --cache-fi \ + | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c) + ac_prev=cache_file ;; + -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \ + | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*) + cache_file=$ac_optarg ;; + + --config-cache | -C) + cache_file=config.cache ;; + + -datadir | --datadir | --datadi | --datad) + ac_prev=datadir ;; + -datadir=* | --datadir=* | --datadi=* | --datad=*) + datadir=$ac_optarg ;; + + -datarootdir | --datarootdir | --datarootdi | --datarootd | --dataroot \ + | --dataroo | --dataro | --datar) + ac_prev=datarootdir ;; + -datarootdir=* | --datarootdir=* | --datarootdi=* | --datarootd=* \ + | --dataroot=* | --dataroo=* | --dataro=* | --datar=*) + datarootdir=$ac_optarg ;; + + -disable-* | --disable-*) + ac_useropt=`expr "x$ac_option" : 'x-*disable-\(.*\)'` + # Reject names that are not valid shell variable names. + expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && + as_fn_error "invalid feature name: $ac_useropt" + ac_useropt_orig=$ac_useropt + ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` + case $ac_user_opts in + *" +"enable_$ac_useropt" +"*) ;; + *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--disable-$ac_useropt_orig" + ac_unrecognized_sep=', ';; + esac + eval enable_$ac_useropt=no ;; + + -docdir | --docdir | --docdi | --doc | --do) + ac_prev=docdir ;; + -docdir=* | --docdir=* | --docdi=* | --doc=* | --do=*) + docdir=$ac_optarg ;; + + -dvidir | --dvidir | --dvidi | --dvid | --dvi | --dv) + ac_prev=dvidir ;; + -dvidir=* | --dvidir=* | --dvidi=* | --dvid=* | --dvi=* | --dv=*) + dvidir=$ac_optarg ;; + + -enable-* | --enable-*) + ac_useropt=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'` + # Reject names that are not valid shell variable names. + expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && + as_fn_error "invalid feature name: $ac_useropt" + ac_useropt_orig=$ac_useropt + ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` + case $ac_user_opts in + *" +"enable_$ac_useropt" +"*) ;; + *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--enable-$ac_useropt_orig" + ac_unrecognized_sep=', ';; + esac + eval enable_$ac_useropt=\$ac_optarg ;; + + -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \ + | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \ + | --exec | --exe | --ex) + ac_prev=exec_prefix ;; + -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \ + | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \ + | --exec=* | --exe=* | --ex=*) + exec_prefix=$ac_optarg ;; + + -gas | --gas | --ga | --g) + # Obsolete; use --with-gas. + with_gas=yes ;; + + -help | --help | --hel | --he | -h) + ac_init_help=long ;; + -help=r* | --help=r* | --hel=r* | --he=r* | -hr*) + ac_init_help=recursive ;; + -help=s* | --help=s* | --hel=s* | --he=s* | -hs*) + ac_init_help=short ;; + + -host | --host | --hos | --ho) + ac_prev=host_alias ;; + -host=* | --host=* | --hos=* | --ho=*) + host_alias=$ac_optarg ;; + + -htmldir | --htmldir | --htmldi | --htmld | --html | --htm | --ht) + ac_prev=htmldir ;; + -htmldir=* | --htmldir=* | --htmldi=* | --htmld=* | --html=* | --htm=* \ + | --ht=*) + htmldir=$ac_optarg ;; + + -includedir | --includedir | --includedi | --included | --include \ + | --includ | --inclu | --incl | --inc) + ac_prev=includedir ;; + -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \ + | --includ=* | --inclu=* | --incl=* | --inc=*) + includedir=$ac_optarg ;; + + -infodir | --infodir | --infodi | --infod | --info | --inf) + ac_prev=infodir ;; + -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*) + infodir=$ac_optarg ;; + + -libdir | --libdir | --libdi | --libd) + ac_prev=libdir ;; + -libdir=* | --libdir=* | --libdi=* | --libd=*) + libdir=$ac_optarg ;; + + -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \ + | --libexe | --libex | --libe) + ac_prev=libexecdir ;; + -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \ + | --libexe=* | --libex=* | --libe=*) + libexecdir=$ac_optarg ;; + + -localedir | --localedir | --localedi | --localed | --locale) + ac_prev=localedir ;; + -localedir=* | --localedir=* | --localedi=* | --localed=* | --locale=*) + localedir=$ac_optarg ;; + + -localstatedir | --localstatedir | --localstatedi | --localstated \ + | --localstate | --localstat | --localsta | --localst | --locals) + ac_prev=localstatedir ;; + -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \ + | --localstate=* | --localstat=* | --localsta=* | --localst=* | --locals=*) + localstatedir=$ac_optarg ;; + + -mandir | --mandir | --mandi | --mand | --man | --ma | --m) + ac_prev=mandir ;; + -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*) + mandir=$ac_optarg ;; + + -nfp | --nfp | --nf) + # Obsolete; use --without-fp. + with_fp=no ;; + + -no-create | --no-create | --no-creat | --no-crea | --no-cre \ + | --no-cr | --no-c | -n) + no_create=yes ;; + + -no-recursion | --no-recursion | --no-recursio | --no-recursi \ + | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) + no_recursion=yes ;; + + -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \ + | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \ + | --oldin | --oldi | --old | --ol | --o) + ac_prev=oldincludedir ;; + -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \ + | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \ + | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*) + oldincludedir=$ac_optarg ;; + + -prefix | --prefix | --prefi | --pref | --pre | --pr | --p) + ac_prev=prefix ;; + -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*) + prefix=$ac_optarg ;; + + -program-prefix | --program-prefix | --program-prefi | --program-pref \ + | --program-pre | --program-pr | --program-p) + ac_prev=program_prefix ;; + -program-prefix=* | --program-prefix=* | --program-prefi=* \ + | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*) + program_prefix=$ac_optarg ;; + + -program-suffix | --program-suffix | --program-suffi | --program-suff \ + | --program-suf | --program-su | --program-s) + ac_prev=program_suffix ;; + -program-suffix=* | --program-suffix=* | --program-suffi=* \ + | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*) + program_suffix=$ac_optarg ;; + + -program-transform-name | --program-transform-name \ + | --program-transform-nam | --program-transform-na \ + | --program-transform-n | --program-transform- \ + | --program-transform | --program-transfor \ + | --program-transfo | --program-transf \ + | --program-trans | --program-tran \ + | --progr-tra | --program-tr | --program-t) + ac_prev=program_transform_name ;; + -program-transform-name=* | --program-transform-name=* \ + | --program-transform-nam=* | --program-transform-na=* \ + | --program-transform-n=* | --program-transform-=* \ + | --program-transform=* | --program-transfor=* \ + | --program-transfo=* | --program-transf=* \ + | --program-trans=* | --program-tran=* \ + | --progr-tra=* | --program-tr=* | --program-t=*) + program_transform_name=$ac_optarg ;; + + -pdfdir | --pdfdir | --pdfdi | --pdfd | --pdf | --pd) + ac_prev=pdfdir ;; + -pdfdir=* | --pdfdir=* | --pdfdi=* | --pdfd=* | --pdf=* | --pd=*) + pdfdir=$ac_optarg ;; + + -psdir | --psdir | --psdi | --psd | --ps) + ac_prev=psdir ;; + -psdir=* | --psdir=* | --psdi=* | --psd=* | --ps=*) + psdir=$ac_optarg ;; + + -q | -quiet | --quiet | --quie | --qui | --qu | --q \ + | -silent | --silent | --silen | --sile | --sil) + silent=yes ;; + + -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) + ac_prev=sbindir ;; + -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ + | --sbi=* | --sb=*) + sbindir=$ac_optarg ;; + + -sharedstatedir | --sharedstatedir | --sharedstatedi \ + | --sharedstated | --sharedstate | --sharedstat | --sharedsta \ + | --sharedst | --shareds | --shared | --share | --shar \ + | --sha | --sh) + ac_prev=sharedstatedir ;; + -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \ + | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \ + | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \ + | --sha=* | --sh=*) + sharedstatedir=$ac_optarg ;; + + -site | --site | --sit) + ac_prev=site ;; + -site=* | --site=* | --sit=*) + site=$ac_optarg ;; + + -srcdir | --srcdir | --srcdi | --srcd | --src | --sr) + ac_prev=srcdir ;; + -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*) + srcdir=$ac_optarg ;; + + -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \ + | --syscon | --sysco | --sysc | --sys | --sy) + ac_prev=sysconfdir ;; + -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \ + | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*) + sysconfdir=$ac_optarg ;; + + -target | --target | --targe | --targ | --tar | --ta | --t) + ac_prev=target_alias ;; + -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*) + target_alias=$ac_optarg ;; + + -v | -verbose | --verbose | --verbos | --verbo | --verb) + verbose=yes ;; + + -version | --version | --versio | --versi | --vers | -V) + ac_init_version=: ;; + + -with-* | --with-*) + ac_useropt=`expr "x$ac_option" : 'x-*with-\([^=]*\)'` + # Reject names that are not valid shell variable names. + expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && + as_fn_error "invalid package name: $ac_useropt" + ac_useropt_orig=$ac_useropt + ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` + case $ac_user_opts in + *" +"with_$ac_useropt" +"*) ;; + *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--with-$ac_useropt_orig" + ac_unrecognized_sep=', ';; + esac + eval with_$ac_useropt=\$ac_optarg ;; + + -without-* | --without-*) + ac_useropt=`expr "x$ac_option" : 'x-*without-\(.*\)'` + # Reject names that are not valid shell variable names. + expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && + as_fn_error "invalid package name: $ac_useropt" + ac_useropt_orig=$ac_useropt + ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` + case $ac_user_opts in + *" +"with_$ac_useropt" +"*) ;; + *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--without-$ac_useropt_orig" + ac_unrecognized_sep=', ';; + esac + eval with_$ac_useropt=no ;; + + --x) + # Obsolete; use --with-x. + with_x=yes ;; + + -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \ + | --x-incl | --x-inc | --x-in | --x-i) + ac_prev=x_includes ;; + -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \ + | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*) + x_includes=$ac_optarg ;; + + -x-libraries | --x-libraries | --x-librarie | --x-librari \ + | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l) + ac_prev=x_libraries ;; + -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \ + | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*) + x_libraries=$ac_optarg ;; + + -*) as_fn_error "unrecognized option: \`$ac_option' +Try \`$0 --help' for more information." + ;; + + *=*) + ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='` + # Reject names that are not valid shell variable names. + case $ac_envvar in #( + '' | [0-9]* | *[!_$as_cr_alnum]* ) + as_fn_error "invalid variable name: \`$ac_envvar'" ;; + esac + eval $ac_envvar=\$ac_optarg + export $ac_envvar ;; + + *) + # FIXME: should be removed in autoconf 3.0. + $as_echo "$as_me: WARNING: you should use --build, --host, --target" >&2 + expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null && + $as_echo "$as_me: WARNING: invalid host type: $ac_option" >&2 + : ${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option} + ;; + + esac +done + +if test -n "$ac_prev"; then + ac_option=--`echo $ac_prev | sed 's/_/-/g'` + as_fn_error "missing argument to $ac_option" +fi + +if test -n "$ac_unrecognized_opts"; then + case $enable_option_checking in + no) ;; + fatal) as_fn_error "unrecognized options: $ac_unrecognized_opts" ;; + *) $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 ;; + esac +fi + +# Check all directory arguments for consistency. +for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ + datadir sysconfdir sharedstatedir localstatedir includedir \ + oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ + libdir localedir mandir +do + eval ac_val=\$$ac_var + # Remove trailing slashes. + case $ac_val in + */ ) + ac_val=`expr "X$ac_val" : 'X\(.*[^/]\)' \| "X$ac_val" : 'X\(.*\)'` + eval $ac_var=\$ac_val;; + esac + # Be sure to have absolute directory names. + case $ac_val in + [\\/$]* | ?:[\\/]* ) continue;; + NONE | '' ) case $ac_var in *prefix ) continue;; esac;; + esac + as_fn_error "expected an absolute directory name for --$ac_var: $ac_val" +done + +# There might be people who depend on the old broken behavior: `$host' +# used to hold the argument of --host etc. +# FIXME: To remove some day. +build=$build_alias +host=$host_alias +target=$target_alias + +# FIXME: To remove some day. +if test "x$host_alias" != x; then + if test "x$build_alias" = x; then + cross_compiling=maybe + $as_echo "$as_me: WARNING: If you wanted to set the --build type, don't use --host. + If a cross compiler is detected then cross compile mode will be used." >&2 + elif test "x$build_alias" != "x$host_alias"; then + cross_compiling=yes + fi +fi + +ac_tool_prefix= +test -n "$host_alias" && ac_tool_prefix=$host_alias- + +test "$silent" = yes && exec 6>/dev/null + + +ac_pwd=`pwd` && test -n "$ac_pwd" && +ac_ls_di=`ls -di .` && +ac_pwd_ls_di=`cd "$ac_pwd" && ls -di .` || + as_fn_error "working directory cannot be determined" +test "X$ac_ls_di" = "X$ac_pwd_ls_di" || + as_fn_error "pwd does not report name of working directory" + + +# Find the source files, if location was not specified. +if test -z "$srcdir"; then + ac_srcdir_defaulted=yes + # Try the directory containing this script, then the parent directory. + ac_confdir=`$as_dirname -- "$as_myself" || +$as_expr X"$as_myself" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$as_myself" : 'X\(//\)[^/]' \| \ + X"$as_myself" : 'X\(//\)$' \| \ + X"$as_myself" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X"$as_myself" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + srcdir=$ac_confdir + if test ! -r "$srcdir/$ac_unique_file"; then + srcdir=.. + fi +else + ac_srcdir_defaulted=no +fi +if test ! -r "$srcdir/$ac_unique_file"; then + test "$ac_srcdir_defaulted" = yes && srcdir="$ac_confdir or .." + as_fn_error "cannot find sources ($ac_unique_file) in $srcdir" +fi +ac_msg="sources are in $srcdir, but \`cd $srcdir' does not work" +ac_abs_confdir=`( + cd "$srcdir" && test -r "./$ac_unique_file" || as_fn_error "$ac_msg" + pwd)` +# When building in place, set srcdir=. +if test "$ac_abs_confdir" = "$ac_pwd"; then + srcdir=. +fi +# Remove unnecessary trailing slashes from srcdir. +# Double slashes in file names in object file debugging info +# mess up M-x gdb in Emacs. +case $srcdir in +*/) srcdir=`expr "X$srcdir" : 'X\(.*[^/]\)' \| "X$srcdir" : 'X\(.*\)'`;; +esac +for ac_var in $ac_precious_vars; do + eval ac_env_${ac_var}_set=\${${ac_var}+set} + eval ac_env_${ac_var}_value=\$${ac_var} + eval ac_cv_env_${ac_var}_set=\${${ac_var}+set} + eval ac_cv_env_${ac_var}_value=\$${ac_var} +done + +# +# Report the --help message. +# +if test "$ac_init_help" = "long"; then + # Omit some internal or obsolete options to make the list less imposing. + # This message is too long to be a string in the A/UX 3.1 sh. + cat <<_ACEOF +\`configure' configures libpng 1.2.46 to adapt to many kinds of systems. + +Usage: $0 [OPTION]... [VAR=VALUE]... + +To assign environment variables (e.g., CC, CFLAGS...), specify them as +VAR=VALUE. See below for descriptions of some of the useful variables. + +Defaults for the options are specified in brackets. + +Configuration: + -h, --help display this help and exit + --help=short display options specific to this package + --help=recursive display the short help of all the included packages + -V, --version display version information and exit + -q, --quiet, --silent do not print \`checking...' messages + --cache-file=FILE cache test results in FILE [disabled] + -C, --config-cache alias for \`--cache-file=config.cache' + -n, --no-create do not create output files + --srcdir=DIR find the sources in DIR [configure dir or \`..'] + +Installation directories: + --prefix=PREFIX install architecture-independent files in PREFIX + [$ac_default_prefix] + --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX + [PREFIX] + +By default, \`make install' will install all the files in +\`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc. You can specify +an installation prefix other than \`$ac_default_prefix' using \`--prefix', +for instance \`--prefix=\$HOME'. + +For better control, use the options below. + +Fine tuning of the installation directories: + --bindir=DIR user executables [EPREFIX/bin] + --sbindir=DIR system admin executables [EPREFIX/sbin] + --libexecdir=DIR program executables [EPREFIX/libexec] + --sysconfdir=DIR read-only single-machine data [PREFIX/etc] + --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] + --localstatedir=DIR modifiable single-machine data [PREFIX/var] + --libdir=DIR object code libraries [EPREFIX/lib] + --includedir=DIR C header files [PREFIX/include] + --oldincludedir=DIR C header files for non-gcc [/usr/include] + --datarootdir=DIR read-only arch.-independent data root [PREFIX/share] + --datadir=DIR read-only architecture-independent data [DATAROOTDIR] + --infodir=DIR info documentation [DATAROOTDIR/info] + --localedir=DIR locale-dependent data [DATAROOTDIR/locale] + --mandir=DIR man documentation [DATAROOTDIR/man] + --docdir=DIR documentation root [DATAROOTDIR/doc/libpng] + --htmldir=DIR html documentation [DOCDIR] + --dvidir=DIR dvi documentation [DOCDIR] + --pdfdir=DIR pdf documentation [DOCDIR] + --psdir=DIR ps documentation [DOCDIR] +_ACEOF + + cat <<\_ACEOF + +Program names: + --program-prefix=PREFIX prepend PREFIX to installed program names + --program-suffix=SUFFIX append SUFFIX to installed program names + --program-transform-name=PROGRAM run sed PROGRAM on installed program names + +System types: + --build=BUILD configure for building on BUILD [guessed] + --host=HOST cross-compile to build programs to run on HOST [BUILD] +_ACEOF +fi + +if test -n "$ac_init_help"; then + case $ac_init_help in + short | recursive ) echo "Configuration of libpng 1.2.46:";; + esac + cat <<\_ACEOF + +Optional Features: + --disable-option-checking ignore unrecognized --enable/--with options + --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) + --enable-FEATURE[=ARG] include FEATURE [ARG=yes] + --enable-maintainer-mode enable make rules and dependencies not useful + (and sometimes confusing) to the casual installer + --disable-dependency-tracking speeds up one-time build + --enable-dependency-tracking do not reject slow dependency extractors + --enable-shared[=PKGS] build shared libraries [default=yes] + --enable-static[=PKGS] build static libraries [default=yes] + --enable-fast-install[=PKGS] + optimize for fast installation [default=yes] + --disable-libtool-lock avoid locking (might break parallel builds) + +Optional Packages: + --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] + --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) + --with-gnu-ld assume the C compiler uses GNU ld [default=no] + --with-pic try to use only PIC/non-PIC objects [default=use + both] + --with-pkgconfigdir Use the specified pkgconfig dir (default is + libdir/pkgconfig) + --with-binconfigs Generate shell libpng-config scripts as well as + pkg-config data [default=yes] + --with-libpng-compat Generate the obsolete libpng.so library + [default=yes] + +Some influential environment variables: + CC C compiler command + CFLAGS C compiler flags + LDFLAGS linker flags, e.g. -L if you have libraries in a + nonstandard directory + LIBS libraries to pass to the linker, e.g. -l + CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I if + you have headers in a nonstandard directory + CPP C preprocessor + +Use these variables to override the choices made by `configure' or to help +it to find libraries and programs with nonstandard names/locations. + +Report bugs to . +_ACEOF +ac_status=$? +fi + +if test "$ac_init_help" = "recursive"; then + # If there are subdirs, report their specific --help. + for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue + test -d "$ac_dir" || + { cd "$srcdir" && ac_pwd=`pwd` && srcdir=. && test -d "$ac_dir"; } || + continue + ac_builddir=. + +case "$ac_dir" in +.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; +*) + ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'` + # A ".." for each directory in $ac_dir_suffix. + ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` + case $ac_top_builddir_sub in + "") ac_top_builddir_sub=. ac_top_build_prefix= ;; + *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; + esac ;; +esac +ac_abs_top_builddir=$ac_pwd +ac_abs_builddir=$ac_pwd$ac_dir_suffix +# for backward compatibility: +ac_top_builddir=$ac_top_build_prefix + +case $srcdir in + .) # We are building in place. + ac_srcdir=. + ac_top_srcdir=$ac_top_builddir_sub + ac_abs_top_srcdir=$ac_pwd ;; + [\\/]* | ?:[\\/]* ) # Absolute name. + ac_srcdir=$srcdir$ac_dir_suffix; + ac_top_srcdir=$srcdir + ac_abs_top_srcdir=$srcdir ;; + *) # Relative name. + ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix + ac_top_srcdir=$ac_top_build_prefix$srcdir + ac_abs_top_srcdir=$ac_pwd/$srcdir ;; +esac +ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix + + cd "$ac_dir" || { ac_status=$?; continue; } + # Check for guested configure. + if test -f "$ac_srcdir/configure.gnu"; then + echo && + $SHELL "$ac_srcdir/configure.gnu" --help=recursive + elif test -f "$ac_srcdir/configure"; then + echo && + $SHELL "$ac_srcdir/configure" --help=recursive + else + $as_echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2 + fi || ac_status=$? + cd "$ac_pwd" || { ac_status=$?; break; } + done +fi + +test -n "$ac_init_help" && exit $ac_status +if $ac_init_version; then + cat <<\_ACEOF +libpng configure 1.2.46 +generated by GNU Autoconf 2.65 + +Copyright (C) 2009 Free Software Foundation, Inc. +This configure script is free software; the Free Software Foundation +gives unlimited permission to copy, distribute and modify it. +_ACEOF + exit +fi + +## ------------------------ ## +## Autoconf initialization. ## +## ------------------------ ## + +# ac_fn_c_try_compile LINENO +# -------------------------- +# Try to compile conftest.$ac_ext, and return whether this succeeded. +ac_fn_c_try_compile () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + rm -f conftest.$ac_objext + if { { ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_compile") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + grep -v '^ *+' conftest.err >conftest.er1 + cat conftest.er1 >&5 + mv -f conftest.er1 conftest.err + fi + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then : + ac_retval=0 +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=1 +fi + eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;} + as_fn_set_status $ac_retval + +} # ac_fn_c_try_compile + +# ac_fn_c_try_cpp LINENO +# ---------------------- +# Try to preprocess conftest.$ac_ext, and return whether this succeeded. +ac_fn_c_try_cpp () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + if { { ac_try="$ac_cpp conftest.$ac_ext" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_cpp conftest.$ac_ext") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + grep -v '^ *+' conftest.err >conftest.er1 + cat conftest.er1 >&5 + mv -f conftest.er1 conftest.err + fi + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } >/dev/null && { + test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || + test ! -s conftest.err + }; then : + ac_retval=0 +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=1 +fi + eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;} + as_fn_set_status $ac_retval + +} # ac_fn_c_try_cpp + +# ac_fn_c_try_link LINENO +# ----------------------- +# Try to link conftest.$ac_ext, and return whether this succeeded. +ac_fn_c_try_link () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + rm -f conftest.$ac_objext conftest$ac_exeext + if { { ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_link") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + grep -v '^ *+' conftest.err >conftest.er1 + cat conftest.er1 >&5 + mv -f conftest.er1 conftest.err + fi + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest$ac_exeext && { + test "$cross_compiling" = yes || + $as_test_x conftest$ac_exeext + }; then : + ac_retval=0 +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=1 +fi + # Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information + # created by the PGI compiler (conftest_ipa8_conftest.oo), as it would + # interfere with the next link command; also delete a directory that is + # left behind by Apple's compiler. We do this before executing the actions. + rm -rf conftest.dSYM conftest_ipa8_conftest.oo + eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;} + as_fn_set_status $ac_retval + +} # ac_fn_c_try_link + +# ac_fn_c_check_header_compile LINENO HEADER VAR INCLUDES +# ------------------------------------------------------- +# Tests whether HEADER exists and can be compiled using the include files in +# INCLUDES, setting the cache variable VAR accordingly. +ac_fn_c_check_header_compile () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 +$as_echo_n "checking for $2... " >&6; } +if { as_var=$3; eval "test \"\${$as_var+set}\" = set"; }; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$4 +#include <$2> +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + eval "$3=yes" +else + eval "$3=no" +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +eval ac_res=\$$3 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;} + +} # ac_fn_c_check_header_compile + +# ac_fn_c_try_run LINENO +# ---------------------- +# Try to link conftest.$ac_ext, and return whether this succeeded. Assumes +# that executables *can* be run. +ac_fn_c_try_run () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + if { { ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_link") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && { ac_try='./conftest$ac_exeext' + { { case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; }; then : + ac_retval=0 +else + $as_echo "$as_me: program exited with status $ac_status" >&5 + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=$ac_status +fi + rm -rf conftest.dSYM conftest_ipa8_conftest.oo + eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;} + as_fn_set_status $ac_retval + +} # ac_fn_c_try_run + +# ac_fn_c_check_func LINENO FUNC VAR +# ---------------------------------- +# Tests whether FUNC exists, setting the cache variable VAR accordingly +ac_fn_c_check_func () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 +$as_echo_n "checking for $2... " >&6; } +if { as_var=$3; eval "test \"\${$as_var+set}\" = set"; }; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +/* Define $2 to an innocuous variant, in case declares $2. + For example, HP-UX 11i declares gettimeofday. */ +#define $2 innocuous_$2 + +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char $2 (); below. + Prefer to if __STDC__ is defined, since + exists even on freestanding compilers. */ + +#ifdef __STDC__ +# include +#else +# include +#endif + +#undef $2 + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char $2 (); +/* The GNU C library defines this for functions which it implements + to always fail with ENOSYS. Some functions are actually named + something starting with __ and the normal name is an alias. */ +#if defined __stub_$2 || defined __stub___$2 +choke me +#endif + +int +main () +{ +return $2 (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + eval "$3=yes" +else + eval "$3=no" +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +fi +eval ac_res=\$$3 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;} + +} # ac_fn_c_check_func + +# ac_fn_c_check_header_mongrel LINENO HEADER VAR INCLUDES +# ------------------------------------------------------- +# Tests whether HEADER exists, giving a warning if it cannot be compiled using +# the include files in INCLUDES and setting the cache variable VAR +# accordingly. +ac_fn_c_check_header_mongrel () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + if { as_var=$3; eval "test \"\${$as_var+set}\" = set"; }; then : + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 +$as_echo_n "checking for $2... " >&6; } +if { as_var=$3; eval "test \"\${$as_var+set}\" = set"; }; then : + $as_echo_n "(cached) " >&6 +fi +eval ac_res=\$$3 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } +else + # Is the header compilable? +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 usability" >&5 +$as_echo_n "checking $2 usability... " >&6; } +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$4 +#include <$2> +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_header_compiler=yes +else + ac_header_compiler=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_compiler" >&5 +$as_echo "$ac_header_compiler" >&6; } + +# Is the header present? +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 presence" >&5 +$as_echo_n "checking $2 presence... " >&6; } +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include <$2> +_ACEOF +if ac_fn_c_try_cpp "$LINENO"; then : + ac_header_preproc=yes +else + ac_header_preproc=no +fi +rm -f conftest.err conftest.$ac_ext +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_preproc" >&5 +$as_echo "$ac_header_preproc" >&6; } + +# So? What about this header? +case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in #(( + yes:no: ) + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&5 +$as_echo "$as_me: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5 +$as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;} + ;; + no:yes:* ) + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: present but cannot be compiled" >&5 +$as_echo "$as_me: WARNING: $2: present but cannot be compiled" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: check for missing prerequisite headers?" >&5 +$as_echo "$as_me: WARNING: $2: check for missing prerequisite headers?" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: see the Autoconf documentation" >&5 +$as_echo "$as_me: WARNING: $2: see the Autoconf documentation" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: section \"Present But Cannot Be Compiled\"" >&5 +$as_echo "$as_me: WARNING: $2: section \"Present But Cannot Be Compiled\"" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5 +$as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;} +( cat <<\_ASBOX +## ------------------------------------------------------ ## +## Report this to png-mng-implement@lists.sourceforge.net ## +## ------------------------------------------------------ ## +_ASBOX + ) | sed "s/^/$as_me: WARNING: /" >&2 + ;; +esac + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 +$as_echo_n "checking for $2... " >&6; } +if { as_var=$3; eval "test \"\${$as_var+set}\" = set"; }; then : + $as_echo_n "(cached) " >&6 +else + eval "$3=\$ac_header_compiler" +fi +eval ac_res=\$$3 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } +fi + eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;} + +} # ac_fn_c_check_header_mongrel + +# ac_fn_c_check_type LINENO TYPE VAR INCLUDES +# ------------------------------------------- +# Tests whether TYPE exists after having included INCLUDES, setting cache +# variable VAR accordingly. +ac_fn_c_check_type () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 +$as_echo_n "checking for $2... " >&6; } +if { as_var=$3; eval "test \"\${$as_var+set}\" = set"; }; then : + $as_echo_n "(cached) " >&6 +else + eval "$3=no" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$4 +int +main () +{ +if (sizeof ($2)) + return 0; + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$4 +int +main () +{ +if (sizeof (($2))) + return 0; + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + +else + eval "$3=yes" +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +eval ac_res=\$$3 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;} + +} # ac_fn_c_check_type +cat >config.log <<_ACEOF +This file contains any messages produced by compilers while +running configure, to aid debugging if configure makes a mistake. + +It was created by libpng $as_me 1.2.46, which was +generated by GNU Autoconf 2.65. Invocation command line was + + $ $0 $@ + +_ACEOF +exec 5>>config.log +{ +cat <<_ASUNAME +## --------- ## +## Platform. ## +## --------- ## + +hostname = `(hostname || uname -n) 2>/dev/null | sed 1q` +uname -m = `(uname -m) 2>/dev/null || echo unknown` +uname -r = `(uname -r) 2>/dev/null || echo unknown` +uname -s = `(uname -s) 2>/dev/null || echo unknown` +uname -v = `(uname -v) 2>/dev/null || echo unknown` + +/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown` +/bin/uname -X = `(/bin/uname -X) 2>/dev/null || echo unknown` + +/bin/arch = `(/bin/arch) 2>/dev/null || echo unknown` +/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null || echo unknown` +/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown` +/usr/bin/hostinfo = `(/usr/bin/hostinfo) 2>/dev/null || echo unknown` +/bin/machine = `(/bin/machine) 2>/dev/null || echo unknown` +/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null || echo unknown` +/bin/universe = `(/bin/universe) 2>/dev/null || echo unknown` + +_ASUNAME + +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + $as_echo "PATH: $as_dir" + done +IFS=$as_save_IFS + +} >&5 + +cat >&5 <<_ACEOF + + +## ----------- ## +## Core tests. ## +## ----------- ## + +_ACEOF + + +# Keep a trace of the command line. +# Strip out --no-create and --no-recursion so they do not pile up. +# Strip out --silent because we don't want to record it for future runs. +# Also quote any args containing shell meta-characters. +# Make two passes to allow for proper duplicate-argument suppression. +ac_configure_args= +ac_configure_args0= +ac_configure_args1= +ac_must_keep_next=false +for ac_pass in 1 2 +do + for ac_arg + do + case $ac_arg in + -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;; + -q | -quiet | --quiet | --quie | --qui | --qu | --q \ + | -silent | --silent | --silen | --sile | --sil) + continue ;; + *\'*) + ac_arg=`$as_echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; + esac + case $ac_pass in + 1) as_fn_append ac_configure_args0 " '$ac_arg'" ;; + 2) + as_fn_append ac_configure_args1 " '$ac_arg'" + if test $ac_must_keep_next = true; then + ac_must_keep_next=false # Got value, back to normal. + else + case $ac_arg in + *=* | --config-cache | -C | -disable-* | --disable-* \ + | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \ + | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \ + | -with-* | --with-* | -without-* | --without-* | --x) + case "$ac_configure_args0 " in + "$ac_configure_args1"*" '$ac_arg' "* ) continue ;; + esac + ;; + -* ) ac_must_keep_next=true ;; + esac + fi + as_fn_append ac_configure_args " '$ac_arg'" + ;; + esac + done +done +{ ac_configure_args0=; unset ac_configure_args0;} +{ ac_configure_args1=; unset ac_configure_args1;} + +# When interrupted or exit'd, cleanup temporary files, and complete +# config.log. We remove comments because anyway the quotes in there +# would cause problems or look ugly. +# WARNING: Use '\'' to represent an apostrophe within the trap. +# WARNING: Do not start the trap code with a newline, due to a FreeBSD 4.0 bug. +trap 'exit_status=$? + # Save into config.log some information that might help in debugging. + { + echo + + cat <<\_ASBOX +## ---------------- ## +## Cache variables. ## +## ---------------- ## +_ASBOX + echo + # The following way of writing the cache mishandles newlines in values, +( + for ac_var in `(set) 2>&1 | sed -n '\''s/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'\''`; do + eval ac_val=\$$ac_var + case $ac_val in #( + *${as_nl}*) + case $ac_var in #( + *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 +$as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; + esac + case $ac_var in #( + _ | IFS | as_nl) ;; #( + BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #( + *) { eval $ac_var=; unset $ac_var;} ;; + esac ;; + esac + done + (set) 2>&1 | + case $as_nl`(ac_space='\'' '\''; set) 2>&1` in #( + *${as_nl}ac_space=\ *) + sed -n \ + "s/'\''/'\''\\\\'\'''\''/g; + s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\''\\2'\''/p" + ;; #( + *) + sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" + ;; + esac | + sort +) + echo + + cat <<\_ASBOX +## ----------------- ## +## Output variables. ## +## ----------------- ## +_ASBOX + echo + for ac_var in $ac_subst_vars + do + eval ac_val=\$$ac_var + case $ac_val in + *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; + esac + $as_echo "$ac_var='\''$ac_val'\''" + done | sort + echo + + if test -n "$ac_subst_files"; then + cat <<\_ASBOX +## ------------------- ## +## File substitutions. ## +## ------------------- ## +_ASBOX + echo + for ac_var in $ac_subst_files + do + eval ac_val=\$$ac_var + case $ac_val in + *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; + esac + $as_echo "$ac_var='\''$ac_val'\''" + done | sort + echo + fi + + if test -s confdefs.h; then + cat <<\_ASBOX +## ----------- ## +## confdefs.h. ## +## ----------- ## +_ASBOX + echo + cat confdefs.h + echo + fi + test "$ac_signal" != 0 && + $as_echo "$as_me: caught signal $ac_signal" + $as_echo "$as_me: exit $exit_status" + } >&5 + rm -f core *.core core.conftest.* && + rm -f -r conftest* confdefs* conf$$* $ac_clean_files && + exit $exit_status +' 0 +for ac_signal in 1 2 13 15; do + trap 'ac_signal='$ac_signal'; as_fn_exit 1' $ac_signal +done +ac_signal=0 + +# confdefs.h avoids OS command line length limits that DEFS can exceed. +rm -f -r conftest* confdefs.h + +$as_echo "/* confdefs.h */" > confdefs.h + +# Predefined preprocessor variables. + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_NAME "$PACKAGE_NAME" +_ACEOF + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_TARNAME "$PACKAGE_TARNAME" +_ACEOF + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_VERSION "$PACKAGE_VERSION" +_ACEOF + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_STRING "$PACKAGE_STRING" +_ACEOF + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT" +_ACEOF + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_URL "$PACKAGE_URL" +_ACEOF + + +# Let the site file select an alternate cache file if it wants to. +# Prefer an explicitly selected file to automatically selected ones. +ac_site_file1=NONE +ac_site_file2=NONE +if test -n "$CONFIG_SITE"; then + ac_site_file1=$CONFIG_SITE +elif test "x$prefix" != xNONE; then + ac_site_file1=$prefix/share/config.site + ac_site_file2=$prefix/etc/config.site +else + ac_site_file1=$ac_default_prefix/share/config.site + ac_site_file2=$ac_default_prefix/etc/config.site +fi +for ac_site_file in "$ac_site_file1" "$ac_site_file2" +do + test "x$ac_site_file" = xNONE && continue + if test /dev/null != "$ac_site_file" && test -r "$ac_site_file"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file" >&5 +$as_echo "$as_me: loading site script $ac_site_file" >&6;} + sed 's/^/| /' "$ac_site_file" >&5 + . "$ac_site_file" + fi +done + +if test -r "$cache_file"; then + # Some versions of bash will fail to source /dev/null (special files + # actually), so we avoid doing that. DJGPP emulates it as a regular file. + if test /dev/null != "$cache_file" && test -f "$cache_file"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: loading cache $cache_file" >&5 +$as_echo "$as_me: loading cache $cache_file" >&6;} + case $cache_file in + [\\/]* | ?:[\\/]* ) . "$cache_file";; + *) . "./$cache_file";; + esac + fi +else + { $as_echo "$as_me:${as_lineno-$LINENO}: creating cache $cache_file" >&5 +$as_echo "$as_me: creating cache $cache_file" >&6;} + >$cache_file +fi + +# Check that the precious variables saved in the cache have kept the same +# value. +ac_cache_corrupted=false +for ac_var in $ac_precious_vars; do + eval ac_old_set=\$ac_cv_env_${ac_var}_set + eval ac_new_set=\$ac_env_${ac_var}_set + eval ac_old_val=\$ac_cv_env_${ac_var}_value + eval ac_new_val=\$ac_env_${ac_var}_value + case $ac_old_set,$ac_new_set in + set,) + { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5 +$as_echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;} + ac_cache_corrupted=: ;; + ,set) + { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was not set in the previous run" >&5 +$as_echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;} + ac_cache_corrupted=: ;; + ,);; + *) + if test "x$ac_old_val" != "x$ac_new_val"; then + # differences in whitespace do not lead to failure. + ac_old_val_w=`echo x $ac_old_val` + ac_new_val_w=`echo x $ac_new_val` + if test "$ac_old_val_w" != "$ac_new_val_w"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' has changed since the previous run:" >&5 +$as_echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;} + ac_cache_corrupted=: + else + { $as_echo "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&5 +$as_echo "$as_me: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&2;} + eval $ac_var=\$ac_old_val + fi + { $as_echo "$as_me:${as_lineno-$LINENO}: former value: \`$ac_old_val'" >&5 +$as_echo "$as_me: former value: \`$ac_old_val'" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: current value: \`$ac_new_val'" >&5 +$as_echo "$as_me: current value: \`$ac_new_val'" >&2;} + fi;; + esac + # Pass precious variables to config.status. + if test "$ac_new_set" = set; then + case $ac_new_val in + *\'*) ac_arg=$ac_var=`$as_echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;; + *) ac_arg=$ac_var=$ac_new_val ;; + esac + case " $ac_configure_args " in + *" '$ac_arg' "*) ;; # Avoid dups. Use of quotes ensures accuracy. + *) as_fn_append ac_configure_args " '$ac_arg'" ;; + esac + fi +done +if $ac_cache_corrupted; then + { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: error: changes in the environment can compromise the build" >&5 +$as_echo "$as_me: error: changes in the environment can compromise the build" >&2;} + as_fn_error "run \`make distclean' and/or \`rm $cache_file' and start over" "$LINENO" 5 +fi +## -------------------- ## +## Main body of script. ## +## -------------------- ## + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +am__api_version='1.11' + +ac_aux_dir= +for ac_dir in "$srcdir" "$srcdir/.." "$srcdir/../.."; do + for ac_t in install-sh install.sh shtool; do + if test -f "$ac_dir/$ac_t"; then + ac_aux_dir=$ac_dir + ac_install_sh="$ac_aux_dir/$ac_t -c" + break 2 + fi + done +done +if test -z "$ac_aux_dir"; then + as_fn_error "cannot find install-sh, install.sh, or shtool in \"$srcdir\" \"$srcdir/..\" \"$srcdir/../..\"" "$LINENO" 5 +fi + +# These three variables are undocumented and unsupported, +# and are intended to be withdrawn in a future Autoconf release. +# They can cause serious problems if a builder's source tree is in a directory +# whose full name contains unusual characters. +ac_config_guess="$SHELL $ac_aux_dir/config.guess" # Please don't use this var. +ac_config_sub="$SHELL $ac_aux_dir/config.sub" # Please don't use this var. +ac_configure="$SHELL $ac_aux_dir/configure" # Please don't use this var. + + +# Find a good install program. We prefer a C program (faster), +# so one script is as good as another. But avoid the broken or +# incompatible versions: +# SysV /etc/install, /usr/sbin/install +# SunOS /usr/etc/install +# IRIX /sbin/install +# AIX /bin/install +# AmigaOS /C/install, which installs bootblocks on floppy discs +# AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag +# AFS /usr/afsws/bin/install, which mishandles nonexistent args +# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff" +# OS/2's system install, which has a completely different semantic +# ./install, which can be erroneously created by make from ./install.sh. +# Reject install programs that cannot install multiple files. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a BSD-compatible install" >&5 +$as_echo_n "checking for a BSD-compatible install... " >&6; } +if test -z "$INSTALL"; then +if test "${ac_cv_path_install+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + # Account for people who put trailing slashes in PATH elements. +case $as_dir/ in #(( + ./ | .// | /[cC]/* | \ + /etc/* | /usr/sbin/* | /usr/etc/* | /sbin/* | /usr/afsws/bin/* | \ + ?:[\\/]os2[\\/]install[\\/]* | ?:[\\/]OS2[\\/]INSTALL[\\/]* | \ + /usr/ucb/* ) ;; + *) + # OSF1 and SCO ODT 3.0 have their own names for install. + # Don't use installbsd from OSF since it installs stuff as root + # by default. + for ac_prog in ginstall scoinst install; do + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_prog$ac_exec_ext" && $as_test_x "$as_dir/$ac_prog$ac_exec_ext"; }; then + if test $ac_prog = install && + grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then + # AIX install. It has an incompatible calling convention. + : + elif test $ac_prog = install && + grep pwplus "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then + # program-specific install script used by HP pwplus--don't use. + : + else + rm -rf conftest.one conftest.two conftest.dir + echo one > conftest.one + echo two > conftest.two + mkdir conftest.dir + if "$as_dir/$ac_prog$ac_exec_ext" -c conftest.one conftest.two "`pwd`/conftest.dir" && + test -s conftest.one && test -s conftest.two && + test -s conftest.dir/conftest.one && + test -s conftest.dir/conftest.two + then + ac_cv_path_install="$as_dir/$ac_prog$ac_exec_ext -c" + break 3 + fi + fi + fi + done + done + ;; +esac + + done +IFS=$as_save_IFS + +rm -rf conftest.one conftest.two conftest.dir + +fi + if test "${ac_cv_path_install+set}" = set; then + INSTALL=$ac_cv_path_install + else + # As a last resort, use the slow shell script. Don't cache a + # value for INSTALL within a source directory, because that will + # break other packages using the cache if that directory is + # removed, or if the value is a relative name. + INSTALL=$ac_install_sh + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $INSTALL" >&5 +$as_echo "$INSTALL" >&6; } + +# Use test -z because SunOS4 sh mishandles braces in ${var-val}. +# It thinks the first close brace ends the variable substitution. +test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}' + +test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}' + +test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644' + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether build environment is sane" >&5 +$as_echo_n "checking whether build environment is sane... " >&6; } +# Just in case +sleep 1 +echo timestamp > conftest.file +# Reject unsafe characters in $srcdir or the absolute working directory +# name. Accept space and tab only in the latter. +am_lf=' +' +case `pwd` in + *[\\\"\#\$\&\'\`$am_lf]*) + as_fn_error "unsafe absolute working directory name" "$LINENO" 5;; +esac +case $srcdir in + *[\\\"\#\$\&\'\`$am_lf\ \ ]*) + as_fn_error "unsafe srcdir value: \`$srcdir'" "$LINENO" 5;; +esac + +# Do `set' in a subshell so we don't clobber the current shell's +# arguments. Must try -L first in case configure is actually a +# symlink; some systems play weird games with the mod time of symlinks +# (eg FreeBSD returns the mod time of the symlink's containing +# directory). +if ( + set X `ls -Lt "$srcdir/configure" conftest.file 2> /dev/null` + if test "$*" = "X"; then + # -L didn't work. + set X `ls -t "$srcdir/configure" conftest.file` + fi + rm -f conftest.file + if test "$*" != "X $srcdir/configure conftest.file" \ + && test "$*" != "X conftest.file $srcdir/configure"; then + + # If neither matched, then we have a broken ls. This can happen + # if, for instance, CONFIG_SHELL is bash and it inherits a + # broken ls alias from the environment. This has actually + # happened. Such a system could not be considered "sane". + as_fn_error "ls -t appears to fail. Make sure there is not a broken +alias in your environment" "$LINENO" 5 + fi + + test "$2" = conftest.file + ) +then + # Ok. + : +else + as_fn_error "newly created file is older than distributed files! +Check your system clock" "$LINENO" 5 +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } +test "$program_prefix" != NONE && + program_transform_name="s&^&$program_prefix&;$program_transform_name" +# Use a double $ so make ignores it. +test "$program_suffix" != NONE && + program_transform_name="s&\$&$program_suffix&;$program_transform_name" +# Double any \ or $. +# By default was `s,x,x', remove it if useless. +ac_script='s/[\\$]/&&/g;s/;s,x,x,$//' +program_transform_name=`$as_echo "$program_transform_name" | sed "$ac_script"` + +# expand $ac_aux_dir to an absolute path +am_aux_dir=`cd $ac_aux_dir && pwd` + +if test x"${MISSING+set}" != xset; then + case $am_aux_dir in + *\ * | *\ *) + MISSING="\${SHELL} \"$am_aux_dir/missing\"" ;; + *) + MISSING="\${SHELL} $am_aux_dir/missing" ;; + esac +fi +# Use eval to expand $SHELL +if eval "$MISSING --run true"; then + am_missing_run="$MISSING --run " +else + am_missing_run= + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: \`missing' script is too old or missing" >&5 +$as_echo "$as_me: WARNING: \`missing' script is too old or missing" >&2;} +fi + +if test x"${install_sh}" != xset; then + case $am_aux_dir in + *\ * | *\ *) + install_sh="\${SHELL} '$am_aux_dir/install-sh'" ;; + *) + install_sh="\${SHELL} $am_aux_dir/install-sh" + esac +fi + +# Installed binaries are usually stripped using `strip' when the user +# run `make install-strip'. However `strip' might not be the right +# tool to use in cross-compilation environments, therefore Automake +# will honor the `STRIP' environment variable to overrule this program. +if test "$cross_compiling" != no; then + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}strip", so it can be a program name with args. +set dummy ${ac_tool_prefix}strip; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_STRIP+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$STRIP"; then + ac_cv_prog_STRIP="$STRIP" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_STRIP="${ac_tool_prefix}strip" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +STRIP=$ac_cv_prog_STRIP +if test -n "$STRIP"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $STRIP" >&5 +$as_echo "$STRIP" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_STRIP"; then + ac_ct_STRIP=$STRIP + # Extract the first word of "strip", so it can be a program name with args. +set dummy strip; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_ac_ct_STRIP+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_STRIP"; then + ac_cv_prog_ac_ct_STRIP="$ac_ct_STRIP" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_ac_ct_STRIP="strip" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_STRIP=$ac_cv_prog_ac_ct_STRIP +if test -n "$ac_ct_STRIP"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_STRIP" >&5 +$as_echo "$ac_ct_STRIP" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_STRIP" = x; then + STRIP=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + STRIP=$ac_ct_STRIP + fi +else + STRIP="$ac_cv_prog_STRIP" +fi + +fi +INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s" + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a thread-safe mkdir -p" >&5 +$as_echo_n "checking for a thread-safe mkdir -p... " >&6; } +if test -z "$MKDIR_P"; then + if test "${ac_cv_path_mkdir+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH$PATH_SEPARATOR/opt/sfw/bin +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_prog in mkdir gmkdir; do + for ac_exec_ext in '' $ac_executable_extensions; do + { test -f "$as_dir/$ac_prog$ac_exec_ext" && $as_test_x "$as_dir/$ac_prog$ac_exec_ext"; } || continue + case `"$as_dir/$ac_prog$ac_exec_ext" --version 2>&1` in #( + 'mkdir (GNU coreutils) '* | \ + 'mkdir (coreutils) '* | \ + 'mkdir (fileutils) '4.1*) + ac_cv_path_mkdir=$as_dir/$ac_prog$ac_exec_ext + break 3;; + esac + done + done + done +IFS=$as_save_IFS + +fi + + test -d ./--version && rmdir ./--version + if test "${ac_cv_path_mkdir+set}" = set; then + MKDIR_P="$ac_cv_path_mkdir -p" + else + # As a last resort, use the slow shell script. Don't cache a + # value for MKDIR_P within a source directory, because that will + # break other packages using the cache if that directory is + # removed, or if the value is a relative name. + MKDIR_P="$ac_install_sh -d" + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $MKDIR_P" >&5 +$as_echo "$MKDIR_P" >&6; } + +mkdir_p="$MKDIR_P" +case $mkdir_p in + [\\/$]* | ?:[\\/]*) ;; + */*) mkdir_p="\$(top_builddir)/$mkdir_p" ;; +esac + +for ac_prog in gawk mawk nawk awk +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_AWK+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$AWK"; then + ac_cv_prog_AWK="$AWK" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_AWK="$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +AWK=$ac_cv_prog_AWK +if test -n "$AWK"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AWK" >&5 +$as_echo "$AWK" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$AWK" && break +done + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${MAKE-make} sets \$(MAKE)" >&5 +$as_echo_n "checking whether ${MAKE-make} sets \$(MAKE)... " >&6; } +set x ${MAKE-make} +ac_make=`$as_echo "$2" | sed 's/+/p/g; s/[^a-zA-Z0-9_]/_/g'` +if { as_var=ac_cv_prog_make_${ac_make}_set; eval "test \"\${$as_var+set}\" = set"; }; then : + $as_echo_n "(cached) " >&6 +else + cat >conftest.make <<\_ACEOF +SHELL = /bin/sh +all: + @echo '@@@%%%=$(MAKE)=@@@%%%' +_ACEOF +# GNU make sometimes prints "make[1]: Entering...", which would confuse us. +case `${MAKE-make} -f conftest.make 2>/dev/null` in + *@@@%%%=?*=@@@%%%*) + eval ac_cv_prog_make_${ac_make}_set=yes;; + *) + eval ac_cv_prog_make_${ac_make}_set=no;; +esac +rm -f conftest.make +fi +if eval test \$ac_cv_prog_make_${ac_make}_set = yes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + SET_MAKE= +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + SET_MAKE="MAKE=${MAKE-make}" +fi + +rm -rf .tst 2>/dev/null +mkdir .tst 2>/dev/null +if test -d .tst; then + am__leading_dot=. +else + am__leading_dot=_ +fi +rmdir .tst 2>/dev/null + +if test "`cd $srcdir && pwd`" != "`pwd`"; then + # Use -I$(srcdir) only when $(srcdir) != ., so that make's output + # is not polluted with repeated "-I." + am__isrc=' -I$(srcdir)' + # test to see if srcdir already configured + if test -f $srcdir/config.status; then + as_fn_error "source directory already configured; run \"make distclean\" there first" "$LINENO" 5 + fi +fi + +# test whether we have cygpath +if test -z "$CYGPATH_W"; then + if (cygpath --version) >/dev/null 2>/dev/null; then + CYGPATH_W='cygpath -w' + else + CYGPATH_W=echo + fi +fi + + +# Define the identity of the package. + PACKAGE='libpng' + VERSION='1.2.46' + + +cat >>confdefs.h <<_ACEOF +#define PACKAGE "$PACKAGE" +_ACEOF + + +cat >>confdefs.h <<_ACEOF +#define VERSION "$VERSION" +_ACEOF + +# Some tools Automake needs. + +ACLOCAL=${ACLOCAL-"${am_missing_run}aclocal-${am__api_version}"} + + +AUTOCONF=${AUTOCONF-"${am_missing_run}autoconf"} + + +AUTOMAKE=${AUTOMAKE-"${am_missing_run}automake-${am__api_version}"} + + +AUTOHEADER=${AUTOHEADER-"${am_missing_run}autoheader"} + + +MAKEINFO=${MAKEINFO-"${am_missing_run}makeinfo"} + +# We need awk for the "check" target. The system "awk" is bad on +# some platforms. +# Always define AMTAR for backward compatibility. + +AMTAR=${AMTAR-"${am_missing_run}tar"} + +am__tar='${AMTAR} chof - "$$tardir"'; am__untar='${AMTAR} xf -' + + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable maintainer-specific portions of Makefiles" >&5 +$as_echo_n "checking whether to enable maintainer-specific portions of Makefiles... " >&6; } + # Check whether --enable-maintainer-mode was given. +if test "${enable_maintainer_mode+set}" = set; then : + enableval=$enable_maintainer_mode; USE_MAINTAINER_MODE=$enableval +else + USE_MAINTAINER_MODE=no +fi + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $USE_MAINTAINER_MODE" >&5 +$as_echo "$USE_MAINTAINER_MODE" >&6; } + if test $USE_MAINTAINER_MODE = yes; then + MAINTAINER_MODE_TRUE= + MAINTAINER_MODE_FALSE='#' +else + MAINTAINER_MODE_TRUE='#' + MAINTAINER_MODE_FALSE= +fi + + MAINT=$MAINTAINER_MODE_TRUE + + + +PNGLIB_VERSION=1.2.46 +PNGLIB_MAJOR=1 +PNGLIB_MINOR=2 +PNGLIB_RELEASE=46 + + + +ac_config_headers="$ac_config_headers config.h" + + +# Checks for programs. +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args. +set dummy ${ac_tool_prefix}gcc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_CC+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_CC="${ac_tool_prefix}gcc" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +$as_echo "$CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_CC"; then + ac_ct_CC=$CC + # Extract the first word of "gcc", so it can be a program name with args. +set dummy gcc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_ac_ct_CC+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_CC"; then + ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_ac_ct_CC="gcc" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_CC=$ac_cv_prog_ac_ct_CC +if test -n "$ac_ct_CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 +$as_echo "$ac_ct_CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_CC" = x; then + CC="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + CC=$ac_ct_CC + fi +else + CC="$ac_cv_prog_CC" +fi + +if test -z "$CC"; then + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args. +set dummy ${ac_tool_prefix}cc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_CC+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_CC="${ac_tool_prefix}cc" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +$as_echo "$CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + fi +fi +if test -z "$CC"; then + # Extract the first word of "cc", so it can be a program name with args. +set dummy cc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_CC+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else + ac_prog_rejected=no +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then + ac_prog_rejected=yes + continue + fi + ac_cv_prog_CC="cc" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +if test $ac_prog_rejected = yes; then + # We found a bogon in the path, so make sure we never use it. + set dummy $ac_cv_prog_CC + shift + if test $# != 0; then + # We chose a different compiler from the bogus one. + # However, it has the same basename, so the bogon will be chosen + # first if we set CC to just the basename; use the full file name. + shift + ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@" + fi +fi +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +$as_echo "$CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$CC"; then + if test -n "$ac_tool_prefix"; then + for ac_prog in cl.exe + do + # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. +set dummy $ac_tool_prefix$ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_CC+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_CC="$ac_tool_prefix$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +$as_echo "$CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$CC" && break + done +fi +if test -z "$CC"; then + ac_ct_CC=$CC + for ac_prog in cl.exe +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_ac_ct_CC+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_CC"; then + ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_ac_ct_CC="$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_CC=$ac_cv_prog_ac_ct_CC +if test -n "$ac_ct_CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 +$as_echo "$ac_ct_CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$ac_ct_CC" && break +done + + if test "x$ac_ct_CC" = x; then + CC="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + CC=$ac_ct_CC + fi +fi + +fi + + +test -z "$CC" && { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error "no acceptable C compiler found in \$PATH +See \`config.log' for more details." "$LINENO" 5; } + +# Provide some information about the compiler. +$as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5 +set X $ac_compile +ac_compiler=$2 +for ac_option in --version -v -V -qversion; do + { { ac_try="$ac_compiler $ac_option >&5" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_compiler $ac_option >&5") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + sed '10a\ +... rest of stderr output deleted ... + 10q' conftest.err >conftest.er1 + cat conftest.er1 >&5 + fi + rm -f conftest.er1 conftest.err + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } +done + +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +ac_clean_files_save=$ac_clean_files +ac_clean_files="$ac_clean_files a.out a.out.dSYM a.exe b.out" +# Try to create an executable without -o first, disregard a.out. +# It will help us diagnose broken compilers, and finding out an intuition +# of exeext. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C compiler works" >&5 +$as_echo_n "checking whether the C compiler works... " >&6; } +ac_link_default=`$as_echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'` + +# The possible output files: +ac_files="a.out conftest.exe conftest a.exe a_out.exe b.out conftest.*" + +ac_rmfiles= +for ac_file in $ac_files +do + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; + * ) ac_rmfiles="$ac_rmfiles $ac_file";; + esac +done +rm -f $ac_rmfiles + +if { { ac_try="$ac_link_default" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_link_default") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then : + # Autoconf-2.13 could set the ac_cv_exeext variable to `no'. +# So ignore a value of `no', otherwise this would lead to `EXEEXT = no' +# in a Makefile. We should not override ac_cv_exeext if it was cached, +# so that the user can short-circuit this test for compilers unknown to +# Autoconf. +for ac_file in $ac_files '' +do + test -f "$ac_file" || continue + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) + ;; + [ab].out ) + # We found the default executable, but exeext='' is most + # certainly right. + break;; + *.* ) + if test "${ac_cv_exeext+set}" = set && test "$ac_cv_exeext" != no; + then :; else + ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` + fi + # We set ac_cv_exeext here because the later test for it is not + # safe: cross compilers may not add the suffix if given an `-o' + # argument, so we may need to know it at that point already. + # Even if this section looks crufty: it has the advantage of + # actually working. + break;; + * ) + break;; + esac +done +test "$ac_cv_exeext" = no && ac_cv_exeext= + +else + ac_file='' +fi +if test -z "$ac_file"; then : + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +$as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +{ as_fn_set_status 77 +as_fn_error "C compiler cannot create executables +See \`config.log' for more details." "$LINENO" 5; }; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler default output file name" >&5 +$as_echo_n "checking for C compiler default output file name... " >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_file" >&5 +$as_echo "$ac_file" >&6; } +ac_exeext=$ac_cv_exeext + +rm -f -r a.out a.out.dSYM a.exe conftest$ac_cv_exeext b.out +ac_clean_files=$ac_clean_files_save +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of executables" >&5 +$as_echo_n "checking for suffix of executables... " >&6; } +if { { ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_link") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then : + # If both `conftest.exe' and `conftest' are `present' (well, observable) +# catch `conftest.exe'. For instance with Cygwin, `ls conftest' will +# work properly (i.e., refer to `conftest.exe'), while it won't with +# `rm'. +for ac_file in conftest.exe conftest conftest.*; do + test -f "$ac_file" || continue + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; + *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` + break;; + * ) break;; + esac +done +else + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error "cannot compute suffix of executables: cannot compile and link +See \`config.log' for more details." "$LINENO" 5; } +fi +rm -f conftest conftest$ac_cv_exeext +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5 +$as_echo "$ac_cv_exeext" >&6; } + +rm -f conftest.$ac_ext +EXEEXT=$ac_cv_exeext +ac_exeext=$EXEEXT +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +int +main () +{ +FILE *f = fopen ("conftest.out", "w"); + return ferror (f) || fclose (f) != 0; + + ; + return 0; +} +_ACEOF +ac_clean_files="$ac_clean_files conftest.out" +# Check that the compiler produces executables we can run. If not, either +# the compiler is broken, or we cross compile. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are cross compiling" >&5 +$as_echo_n "checking whether we are cross compiling... " >&6; } +if test "$cross_compiling" != yes; then + { { ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_link") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } + if { ac_try='./conftest$ac_cv_exeext' + { { case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; }; then + cross_compiling=no + else + if test "$cross_compiling" = maybe; then + cross_compiling=yes + else + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error "cannot run C compiled programs. +If you meant to cross compile, use \`--host'. +See \`config.log' for more details." "$LINENO" 5; } + fi + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $cross_compiling" >&5 +$as_echo "$cross_compiling" >&6; } + +rm -f conftest.$ac_ext conftest$ac_cv_exeext conftest.out +ac_clean_files=$ac_clean_files_save +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of object files" >&5 +$as_echo_n "checking for suffix of object files... " >&6; } +if test "${ac_cv_objext+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.o conftest.obj +if { { ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_compile") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then : + for ac_file in conftest.o conftest.obj conftest.*; do + test -f "$ac_file" || continue; + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM ) ;; + *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'` + break;; + esac +done +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error "cannot compute suffix of object files: cannot compile +See \`config.log' for more details." "$LINENO" 5; } +fi +rm -f conftest.$ac_cv_objext conftest.$ac_ext +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_objext" >&5 +$as_echo "$ac_cv_objext" >&6; } +OBJEXT=$ac_cv_objext +ac_objext=$OBJEXT +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C compiler" >&5 +$as_echo_n "checking whether we are using the GNU C compiler... " >&6; } +if test "${ac_cv_c_compiler_gnu+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ +#ifndef __GNUC__ + choke me +#endif + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_compiler_gnu=yes +else + ac_compiler_gnu=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +ac_cv_c_compiler_gnu=$ac_compiler_gnu + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5 +$as_echo "$ac_cv_c_compiler_gnu" >&6; } +if test $ac_compiler_gnu = yes; then + GCC=yes +else + GCC= +fi +ac_test_CFLAGS=${CFLAGS+set} +ac_save_CFLAGS=$CFLAGS +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5 +$as_echo_n "checking whether $CC accepts -g... " >&6; } +if test "${ac_cv_prog_cc_g+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + ac_save_c_werror_flag=$ac_c_werror_flag + ac_c_werror_flag=yes + ac_cv_prog_cc_g=no + CFLAGS="-g" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_prog_cc_g=yes +else + CFLAGS="" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + +else + ac_c_werror_flag=$ac_save_c_werror_flag + CFLAGS="-g" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_prog_cc_g=yes +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + ac_c_werror_flag=$ac_save_c_werror_flag +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5 +$as_echo "$ac_cv_prog_cc_g" >&6; } +if test "$ac_test_CFLAGS" = set; then + CFLAGS=$ac_save_CFLAGS +elif test $ac_cv_prog_cc_g = yes; then + if test "$GCC" = yes; then + CFLAGS="-g -O2" + else + CFLAGS="-g" + fi +else + if test "$GCC" = yes; then + CFLAGS="-O2" + else + CFLAGS= + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C89" >&5 +$as_echo_n "checking for $CC option to accept ISO C89... " >&6; } +if test "${ac_cv_prog_cc_c89+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + ac_cv_prog_cc_c89=no +ac_save_CC=$CC +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +#include +#include +/* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ +struct buf { int x; }; +FILE * (*rcsopen) (struct buf *, struct stat *, int); +static char *e (p, i) + char **p; + int i; +{ + return p[i]; +} +static char *f (char * (*g) (char **, int), char **p, ...) +{ + char *s; + va_list v; + va_start (v,p); + s = g (p, va_arg (v,int)); + va_end (v); + return s; +} + +/* OSF 4.0 Compaq cc is some sort of almost-ANSI by default. It has + function prototypes and stuff, but not '\xHH' hex character constants. + These don't provoke an error unfortunately, instead are silently treated + as 'x'. The following induces an error, until -std is added to get + proper ANSI mode. Curiously '\x00'!='x' always comes out true, for an + array size at least. It's necessary to write '\x00'==0 to get something + that's true only with -std. */ +int osf4_cc_array ['\x00' == 0 ? 1 : -1]; + +/* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters + inside strings and character constants. */ +#define FOO(x) 'x' +int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1]; + +int test (int i, double x); +struct s1 {int (*f) (int a);}; +struct s2 {int (*f) (double a);}; +int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int); +int argc; +char **argv; +int +main () +{ +return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]; + ; + return 0; +} +_ACEOF +for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \ + -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" +do + CC="$ac_save_CC $ac_arg" + if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_prog_cc_c89=$ac_arg +fi +rm -f core conftest.err conftest.$ac_objext + test "x$ac_cv_prog_cc_c89" != "xno" && break +done +rm -f conftest.$ac_ext +CC=$ac_save_CC + +fi +# AC_CACHE_VAL +case "x$ac_cv_prog_cc_c89" in + x) + { $as_echo "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 +$as_echo "none needed" >&6; } ;; + xno) + { $as_echo "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 +$as_echo "unsupported" >&6; } ;; + *) + CC="$CC $ac_cv_prog_cc_c89" + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5 +$as_echo "$ac_cv_prog_cc_c89" >&6; } ;; +esac +if test "x$ac_cv_prog_cc_c89" != xno; then : + +fi + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu +DEPDIR="${am__leading_dot}deps" + +ac_config_commands="$ac_config_commands depfiles" + + +am_make=${MAKE-make} +cat > confinc << 'END' +am__doit: + @echo this is the am__doit target +.PHONY: am__doit +END +# If we don't find an include directive, just comment out the code. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for style of include used by $am_make" >&5 +$as_echo_n "checking for style of include used by $am_make... " >&6; } +am__include="#" +am__quote= +_am_result=none +# First try GNU make style include. +echo "include confinc" > confmf +# Ignore all kinds of additional output from `make'. +case `$am_make -s -f confmf 2> /dev/null` in #( +*the\ am__doit\ target*) + am__include=include + am__quote= + _am_result=GNU + ;; +esac +# Now try BSD make style include. +if test "$am__include" = "#"; then + echo '.include "confinc"' > confmf + case `$am_make -s -f confmf 2> /dev/null` in #( + *the\ am__doit\ target*) + am__include=.include + am__quote="\"" + _am_result=BSD + ;; + esac +fi + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $_am_result" >&5 +$as_echo "$_am_result" >&6; } +rm -f confinc confmf + +# Check whether --enable-dependency-tracking was given. +if test "${enable_dependency_tracking+set}" = set; then : + enableval=$enable_dependency_tracking; +fi + +if test "x$enable_dependency_tracking" != xno; then + am_depcomp="$ac_aux_dir/depcomp" + AMDEPBACKSLASH='\' +fi + if test "x$enable_dependency_tracking" != xno; then + AMDEP_TRUE= + AMDEP_FALSE='#' +else + AMDEP_TRUE='#' + AMDEP_FALSE= +fi + + + +depcc="$CC" am_compiler_list= + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking dependency style of $depcc" >&5 +$as_echo_n "checking dependency style of $depcc... " >&6; } +if test "${am_cv_CC_dependencies_compiler_type+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then + # We make a subdir and do the tests there. Otherwise we can end up + # making bogus files that we don't know about and never remove. For + # instance it was reported that on HP-UX the gcc test will end up + # making a dummy file named `D' -- because `-MD' means `put the output + # in D'. + mkdir conftest.dir + # Copy depcomp to subdir because otherwise we won't find it if we're + # using a relative directory. + cp "$am_depcomp" conftest.dir + cd conftest.dir + # We will build objects and dependencies in a subdirectory because + # it helps to detect inapplicable dependency modes. For instance + # both Tru64's cc and ICC support -MD to output dependencies as a + # side effect of compilation, but ICC will put the dependencies in + # the current directory while Tru64 will put them in the object + # directory. + mkdir sub + + am_cv_CC_dependencies_compiler_type=none + if test "$am_compiler_list" = ""; then + am_compiler_list=`sed -n 's/^#*\([a-zA-Z0-9]*\))$/\1/p' < ./depcomp` + fi + am__universal=false + case " $depcc " in #( + *\ -arch\ *\ -arch\ *) am__universal=true ;; + esac + + for depmode in $am_compiler_list; do + # Setup a source with many dependencies, because some compilers + # like to wrap large dependency lists on column 80 (with \), and + # we should not choose a depcomp mode which is confused by this. + # + # We need to recreate these files for each test, as the compiler may + # overwrite some of them when testing with obscure command lines. + # This happens at least with the AIX C compiler. + : > sub/conftest.c + for i in 1 2 3 4 5 6; do + echo '#include "conftst'$i'.h"' >> sub/conftest.c + # Using `: > sub/conftst$i.h' creates only sub/conftst1.h with + # Solaris 8's {/usr,}/bin/sh. + touch sub/conftst$i.h + done + echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf + + # We check with `-c' and `-o' for the sake of the "dashmstdout" + # mode. It turns out that the SunPro C++ compiler does not properly + # handle `-M -o', and we need to detect this. Also, some Intel + # versions had trouble with output in subdirs + am__obj=sub/conftest.${OBJEXT-o} + am__minus_obj="-o $am__obj" + case $depmode in + gcc) + # This depmode causes a compiler race in universal mode. + test "$am__universal" = false || continue + ;; + nosideeffect) + # after this tag, mechanisms are not by side-effect, so they'll + # only be used when explicitly requested + if test "x$enable_dependency_tracking" = xyes; then + continue + else + break + fi + ;; + msvisualcpp | msvcmsys) + # This compiler won't grok `-c -o', but also, the minuso test has + # not run yet. These depmodes are late enough in the game, and + # so weak that their functioning should not be impacted. + am__obj=conftest.${OBJEXT-o} + am__minus_obj= + ;; + none) break ;; + esac + if depmode=$depmode \ + source=sub/conftest.c object=$am__obj \ + depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \ + $SHELL ./depcomp $depcc -c $am__minus_obj sub/conftest.c \ + >/dev/null 2>conftest.err && + grep sub/conftst1.h sub/conftest.Po > /dev/null 2>&1 && + grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 && + grep $am__obj sub/conftest.Po > /dev/null 2>&1 && + ${MAKE-make} -s -f confmf > /dev/null 2>&1; then + # icc doesn't choke on unknown options, it will just issue warnings + # or remarks (even with -Werror). So we grep stderr for any message + # that says an option was ignored or not supported. + # When given -MP, icc 7.0 and 7.1 complain thusly: + # icc: Command line warning: ignoring option '-M'; no argument required + # The diagnosis changed in icc 8.0: + # icc: Command line remark: option '-MP' not supported + if (grep 'ignoring option' conftest.err || + grep 'not supported' conftest.err) >/dev/null 2>&1; then :; else + am_cv_CC_dependencies_compiler_type=$depmode + break + fi + fi + done + + cd .. + rm -rf conftest.dir +else + am_cv_CC_dependencies_compiler_type=none +fi + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_CC_dependencies_compiler_type" >&5 +$as_echo "$am_cv_CC_dependencies_compiler_type" >&6; } +CCDEPMODE=depmode=$am_cv_CC_dependencies_compiler_type + + if + test "x$enable_dependency_tracking" != xno \ + && test "$am_cv_CC_dependencies_compiler_type" = gcc3; then + am__fastdepCC_TRUE= + am__fastdepCC_FALSE='#' +else + am__fastdepCC_TRUE='#' + am__fastdepCC_FALSE= +fi + + +# Make sure we can run config.sub. +$SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 || + as_fn_error "cannot run $SHELL $ac_aux_dir/config.sub" "$LINENO" 5 + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking build system type" >&5 +$as_echo_n "checking build system type... " >&6; } +if test "${ac_cv_build+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + ac_build_alias=$build_alias +test "x$ac_build_alias" = x && + ac_build_alias=`$SHELL "$ac_aux_dir/config.guess"` +test "x$ac_build_alias" = x && + as_fn_error "cannot guess build type; you must specify one" "$LINENO" 5 +ac_cv_build=`$SHELL "$ac_aux_dir/config.sub" $ac_build_alias` || + as_fn_error "$SHELL $ac_aux_dir/config.sub $ac_build_alias failed" "$LINENO" 5 + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_build" >&5 +$as_echo "$ac_cv_build" >&6; } +case $ac_cv_build in +*-*-*) ;; +*) as_fn_error "invalid value of canonical build" "$LINENO" 5;; +esac +build=$ac_cv_build +ac_save_IFS=$IFS; IFS='-' +set x $ac_cv_build +shift +build_cpu=$1 +build_vendor=$2 +shift; shift +# Remember, the first character of IFS is used to create $*, +# except with old shells: +build_os=$* +IFS=$ac_save_IFS +case $build_os in *\ *) build_os=`echo "$build_os" | sed 's/ /-/g'`;; esac + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking host system type" >&5 +$as_echo_n "checking host system type... " >&6; } +if test "${ac_cv_host+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test "x$host_alias" = x; then + ac_cv_host=$ac_cv_build +else + ac_cv_host=`$SHELL "$ac_aux_dir/config.sub" $host_alias` || + as_fn_error "$SHELL $ac_aux_dir/config.sub $host_alias failed" "$LINENO" 5 +fi + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_host" >&5 +$as_echo "$ac_cv_host" >&6; } +case $ac_cv_host in +*-*-*) ;; +*) as_fn_error "invalid value of canonical host" "$LINENO" 5;; +esac +host=$ac_cv_host +ac_save_IFS=$IFS; IFS='-' +set x $ac_cv_host +shift +host_cpu=$1 +host_vendor=$2 +shift; shift +# Remember, the first character of IFS is used to create $*, +# except with old shells: +host_os=$* +IFS=$ac_save_IFS +case $host_os in *\ *) host_os=`echo "$host_os" | sed 's/ /-/g'`;; esac + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a sed that does not truncate output" >&5 +$as_echo_n "checking for a sed that does not truncate output... " >&6; } +if test "${ac_cv_path_SED+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + ac_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/ + for ac_i in 1 2 3 4 5 6 7; do + ac_script="$ac_script$as_nl$ac_script" + done + echo "$ac_script" 2>/dev/null | sed 99q >conftest.sed + { ac_script=; unset ac_script;} + if test -z "$SED"; then + ac_path_SED_found=false + # Loop through the user's path and test for each of PROGNAME-LIST + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_prog in sed gsed; do + for ac_exec_ext in '' $ac_executable_extensions; do + ac_path_SED="$as_dir/$ac_prog$ac_exec_ext" + { test -f "$ac_path_SED" && $as_test_x "$ac_path_SED"; } || continue +# Check for GNU ac_path_SED and select it if it is found. + # Check for GNU $ac_path_SED +case `"$ac_path_SED" --version 2>&1` in +*GNU*) + ac_cv_path_SED="$ac_path_SED" ac_path_SED_found=:;; +*) + ac_count=0 + $as_echo_n 0123456789 >"conftest.in" + while : + do + cat "conftest.in" "conftest.in" >"conftest.tmp" + mv "conftest.tmp" "conftest.in" + cp "conftest.in" "conftest.nl" + $as_echo '' >> "conftest.nl" + "$ac_path_SED" -f conftest.sed < "conftest.nl" >"conftest.out" 2>/dev/null || break + diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break + as_fn_arith $ac_count + 1 && ac_count=$as_val + if test $ac_count -gt ${ac_path_SED_max-0}; then + # Best one so far, save it but keep looking for a better one + ac_cv_path_SED="$ac_path_SED" + ac_path_SED_max=$ac_count + fi + # 10*(2^10) chars as input seems more than enough + test $ac_count -gt 10 && break + done + rm -f conftest.in conftest.tmp conftest.nl conftest.out;; +esac + + $ac_path_SED_found && break 3 + done + done + done +IFS=$as_save_IFS + if test -z "$ac_cv_path_SED"; then + as_fn_error "no acceptable sed could be found in \$PATH" "$LINENO" 5 + fi +else + ac_cv_path_SED=$SED +fi + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_SED" >&5 +$as_echo "$ac_cv_path_SED" >&6; } + SED="$ac_cv_path_SED" + rm -f conftest.sed + +test -z "$SED" && SED=sed +Xsed="$SED -e 1s/^X//" + + + + + + + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e" >&5 +$as_echo_n "checking for grep that handles long lines and -e... " >&6; } +if test "${ac_cv_path_GREP+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -z "$GREP"; then + ac_path_GREP_found=false + # Loop through the user's path and test for each of PROGNAME-LIST + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_prog in grep ggrep; do + for ac_exec_ext in '' $ac_executable_extensions; do + ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext" + { test -f "$ac_path_GREP" && $as_test_x "$ac_path_GREP"; } || continue +# Check for GNU ac_path_GREP and select it if it is found. + # Check for GNU $ac_path_GREP +case `"$ac_path_GREP" --version 2>&1` in +*GNU*) + ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_found=:;; +*) + ac_count=0 + $as_echo_n 0123456789 >"conftest.in" + while : + do + cat "conftest.in" "conftest.in" >"conftest.tmp" + mv "conftest.tmp" "conftest.in" + cp "conftest.in" "conftest.nl" + $as_echo 'GREP' >> "conftest.nl" + "$ac_path_GREP" -e 'GREP$' -e '-(cannot match)-' < "conftest.nl" >"conftest.out" 2>/dev/null || break + diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break + as_fn_arith $ac_count + 1 && ac_count=$as_val + if test $ac_count -gt ${ac_path_GREP_max-0}; then + # Best one so far, save it but keep looking for a better one + ac_cv_path_GREP="$ac_path_GREP" + ac_path_GREP_max=$ac_count + fi + # 10*(2^10) chars as input seems more than enough + test $ac_count -gt 10 && break + done + rm -f conftest.in conftest.tmp conftest.nl conftest.out;; +esac + + $ac_path_GREP_found && break 3 + done + done + done +IFS=$as_save_IFS + if test -z "$ac_cv_path_GREP"; then + as_fn_error "no acceptable grep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5 + fi +else + ac_cv_path_GREP=$GREP +fi + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_GREP" >&5 +$as_echo "$ac_cv_path_GREP" >&6; } + GREP="$ac_cv_path_GREP" + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for egrep" >&5 +$as_echo_n "checking for egrep... " >&6; } +if test "${ac_cv_path_EGREP+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if echo a | $GREP -E '(a|b)' >/dev/null 2>&1 + then ac_cv_path_EGREP="$GREP -E" + else + if test -z "$EGREP"; then + ac_path_EGREP_found=false + # Loop through the user's path and test for each of PROGNAME-LIST + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_prog in egrep; do + for ac_exec_ext in '' $ac_executable_extensions; do + ac_path_EGREP="$as_dir/$ac_prog$ac_exec_ext" + { test -f "$ac_path_EGREP" && $as_test_x "$ac_path_EGREP"; } || continue +# Check for GNU ac_path_EGREP and select it if it is found. + # Check for GNU $ac_path_EGREP +case `"$ac_path_EGREP" --version 2>&1` in +*GNU*) + ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_found=:;; +*) + ac_count=0 + $as_echo_n 0123456789 >"conftest.in" + while : + do + cat "conftest.in" "conftest.in" >"conftest.tmp" + mv "conftest.tmp" "conftest.in" + cp "conftest.in" "conftest.nl" + $as_echo 'EGREP' >> "conftest.nl" + "$ac_path_EGREP" 'EGREP$' < "conftest.nl" >"conftest.out" 2>/dev/null || break + diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break + as_fn_arith $ac_count + 1 && ac_count=$as_val + if test $ac_count -gt ${ac_path_EGREP_max-0}; then + # Best one so far, save it but keep looking for a better one + ac_cv_path_EGREP="$ac_path_EGREP" + ac_path_EGREP_max=$ac_count + fi + # 10*(2^10) chars as input seems more than enough + test $ac_count -gt 10 && break + done + rm -f conftest.in conftest.tmp conftest.nl conftest.out;; +esac + + $ac_path_EGREP_found && break 3 + done + done + done +IFS=$as_save_IFS + if test -z "$ac_cv_path_EGREP"; then + as_fn_error "no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5 + fi +else + ac_cv_path_EGREP=$EGREP +fi + + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_EGREP" >&5 +$as_echo "$ac_cv_path_EGREP" >&6; } + EGREP="$ac_cv_path_EGREP" + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for fgrep" >&5 +$as_echo_n "checking for fgrep... " >&6; } +if test "${ac_cv_path_FGREP+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if echo 'ab*c' | $GREP -F 'ab*c' >/dev/null 2>&1 + then ac_cv_path_FGREP="$GREP -F" + else + if test -z "$FGREP"; then + ac_path_FGREP_found=false + # Loop through the user's path and test for each of PROGNAME-LIST + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_prog in fgrep; do + for ac_exec_ext in '' $ac_executable_extensions; do + ac_path_FGREP="$as_dir/$ac_prog$ac_exec_ext" + { test -f "$ac_path_FGREP" && $as_test_x "$ac_path_FGREP"; } || continue +# Check for GNU ac_path_FGREP and select it if it is found. + # Check for GNU $ac_path_FGREP +case `"$ac_path_FGREP" --version 2>&1` in +*GNU*) + ac_cv_path_FGREP="$ac_path_FGREP" ac_path_FGREP_found=:;; +*) + ac_count=0 + $as_echo_n 0123456789 >"conftest.in" + while : + do + cat "conftest.in" "conftest.in" >"conftest.tmp" + mv "conftest.tmp" "conftest.in" + cp "conftest.in" "conftest.nl" + $as_echo 'FGREP' >> "conftest.nl" + "$ac_path_FGREP" FGREP < "conftest.nl" >"conftest.out" 2>/dev/null || break + diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break + as_fn_arith $ac_count + 1 && ac_count=$as_val + if test $ac_count -gt ${ac_path_FGREP_max-0}; then + # Best one so far, save it but keep looking for a better one + ac_cv_path_FGREP="$ac_path_FGREP" + ac_path_FGREP_max=$ac_count + fi + # 10*(2^10) chars as input seems more than enough + test $ac_count -gt 10 && break + done + rm -f conftest.in conftest.tmp conftest.nl conftest.out;; +esac + + $ac_path_FGREP_found && break 3 + done + done + done +IFS=$as_save_IFS + if test -z "$ac_cv_path_FGREP"; then + as_fn_error "no acceptable fgrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5 + fi +else + ac_cv_path_FGREP=$FGREP +fi + + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_FGREP" >&5 +$as_echo "$ac_cv_path_FGREP" >&6; } + FGREP="$ac_cv_path_FGREP" + + +test -z "$GREP" && GREP=grep + + + + + + + + + + + + + + + + + + + +# Check whether --with-gnu-ld was given. +if test "${with_gnu_ld+set}" = set; then : + withval=$with_gnu_ld; test "$withval" = no || with_gnu_ld=yes +else + with_gnu_ld=no +fi + +ac_prog=ld +if test "$GCC" = yes; then + # Check if gcc -print-prog-name=ld gives a path. + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ld used by $CC" >&5 +$as_echo_n "checking for ld used by $CC... " >&6; } + case $host in + *-*-mingw*) + # gcc leaves a trailing carriage return which upsets mingw + ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;; + *) + ac_prog=`($CC -print-prog-name=ld) 2>&5` ;; + esac + case $ac_prog in + # Accept absolute paths. + [\\/]* | ?:[\\/]*) + re_direlt='/[^/][^/]*/\.\./' + # Canonicalize the pathname of ld + ac_prog=`$ECHO "$ac_prog"| $SED 's%\\\\%/%g'` + while $ECHO "$ac_prog" | $GREP "$re_direlt" > /dev/null 2>&1; do + ac_prog=`$ECHO $ac_prog| $SED "s%$re_direlt%/%"` + done + test -z "$LD" && LD="$ac_prog" + ;; + "") + # If it fails, then pretend we aren't using GCC. + ac_prog=ld + ;; + *) + # If it is relative, then search for the first ld in PATH. + with_gnu_ld=unknown + ;; + esac +elif test "$with_gnu_ld" = yes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GNU ld" >&5 +$as_echo_n "checking for GNU ld... " >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for non-GNU ld" >&5 +$as_echo_n "checking for non-GNU ld... " >&6; } +fi +if test "${lt_cv_path_LD+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -z "$LD"; then + lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR + for ac_dir in $PATH; do + IFS="$lt_save_ifs" + test -z "$ac_dir" && ac_dir=. + if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then + lt_cv_path_LD="$ac_dir/$ac_prog" + # Check to see if the program is GNU ld. I'd rather use --version, + # but apparently some variants of GNU ld only accept -v. + # Break only if it was the GNU/non-GNU ld that we prefer. + case `"$lt_cv_path_LD" -v 2>&1 &5 +$as_echo "$LD" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi +test -z "$LD" && as_fn_error "no acceptable ld found in \$PATH" "$LINENO" 5 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if the linker ($LD) is GNU ld" >&5 +$as_echo_n "checking if the linker ($LD) is GNU ld... " >&6; } +if test "${lt_cv_prog_gnu_ld+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + # I'd rather use --version here, but apparently some GNU lds only accept -v. +case `$LD -v 2>&1 &5 +$as_echo "$lt_cv_prog_gnu_ld" >&6; } +with_gnu_ld=$lt_cv_prog_gnu_ld + + + + + + + + + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to run the C preprocessor" >&5 +$as_echo_n "checking how to run the C preprocessor... " >&6; } +# On Suns, sometimes $CPP names a directory. +if test -n "$CPP" && test -d "$CPP"; then + CPP= +fi +if test -z "$CPP"; then + if test "${ac_cv_prog_CPP+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + # Double quotes because CPP needs to be expanded + for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp" + do + ac_preproc_ok=false +for ac_c_preproc_warn_flag in '' yes +do + # Use a header file that comes with gcc, so configuring glibc + # with a fresh cross-compiler works. + # Prefer to if __STDC__ is defined, since + # exists even on freestanding compilers. + # On the NeXT, cc -E runs the code through the compiler's parser, + # not just through cpp. "Syntax error" is here to catch this case. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#ifdef __STDC__ +# include +#else +# include +#endif + Syntax error +_ACEOF +if ac_fn_c_try_cpp "$LINENO"; then : + +else + # Broken: fails on valid input. +continue +fi +rm -f conftest.err conftest.$ac_ext + + # OK, works on sane cases. Now check whether nonexistent headers + # can be detected and how. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +_ACEOF +if ac_fn_c_try_cpp "$LINENO"; then : + # Broken: success on invalid input. +continue +else + # Passes both tests. +ac_preproc_ok=: +break +fi +rm -f conftest.err conftest.$ac_ext + +done +# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. +rm -f conftest.err conftest.$ac_ext +if $ac_preproc_ok; then : + break +fi + + done + ac_cv_prog_CPP=$CPP + +fi + CPP=$ac_cv_prog_CPP +else + ac_cv_prog_CPP=$CPP +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $CPP" >&5 +$as_echo "$CPP" >&6; } +ac_preproc_ok=false +for ac_c_preproc_warn_flag in '' yes +do + # Use a header file that comes with gcc, so configuring glibc + # with a fresh cross-compiler works. + # Prefer to if __STDC__ is defined, since + # exists even on freestanding compilers. + # On the NeXT, cc -E runs the code through the compiler's parser, + # not just through cpp. "Syntax error" is here to catch this case. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#ifdef __STDC__ +# include +#else +# include +#endif + Syntax error +_ACEOF +if ac_fn_c_try_cpp "$LINENO"; then : + +else + # Broken: fails on valid input. +continue +fi +rm -f conftest.err conftest.$ac_ext + + # OK, works on sane cases. Now check whether nonexistent headers + # can be detected and how. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +_ACEOF +if ac_fn_c_try_cpp "$LINENO"; then : + # Broken: success on invalid input. +continue +else + # Passes both tests. +ac_preproc_ok=: +break +fi +rm -f conftest.err conftest.$ac_ext + +done +# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. +rm -f conftest.err conftest.$ac_ext +if $ac_preproc_ok; then : + +else + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error "C preprocessor \"$CPP\" fails sanity check +See \`config.log' for more details." "$LINENO" 5; } +fi + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}sed", so it can be a program name with args. +set dummy ${ac_tool_prefix}sed; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_SED+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$SED"; then + ac_cv_prog_SED="$SED" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_SED="${ac_tool_prefix}sed" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +SED=$ac_cv_prog_SED +if test -n "$SED"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $SED" >&5 +$as_echo "$SED" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_SED"; then + ac_ct_SED=$SED + # Extract the first word of "sed", so it can be a program name with args. +set dummy sed; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_ac_ct_SED+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_SED"; then + ac_cv_prog_ac_ct_SED="$ac_ct_SED" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_ac_ct_SED="sed" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_SED=$ac_cv_prog_ac_ct_SED +if test -n "$ac_ct_SED"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_SED" >&5 +$as_echo "$ac_ct_SED" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_SED" = x; then + SED=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + SED=$ac_ct_SED + fi +else + SED="$ac_cv_prog_SED" +fi + +enable_win32_dll=yes + +case $host in +*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-cegcc*) + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}as", so it can be a program name with args. +set dummy ${ac_tool_prefix}as; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_AS+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$AS"; then + ac_cv_prog_AS="$AS" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_AS="${ac_tool_prefix}as" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +AS=$ac_cv_prog_AS +if test -n "$AS"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AS" >&5 +$as_echo "$AS" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_AS"; then + ac_ct_AS=$AS + # Extract the first word of "as", so it can be a program name with args. +set dummy as; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_ac_ct_AS+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_AS"; then + ac_cv_prog_ac_ct_AS="$ac_ct_AS" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_ac_ct_AS="as" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_AS=$ac_cv_prog_ac_ct_AS +if test -n "$ac_ct_AS"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_AS" >&5 +$as_echo "$ac_ct_AS" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_AS" = x; then + AS="false" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + AS=$ac_ct_AS + fi +else + AS="$ac_cv_prog_AS" +fi + + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}dlltool", so it can be a program name with args. +set dummy ${ac_tool_prefix}dlltool; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_DLLTOOL+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$DLLTOOL"; then + ac_cv_prog_DLLTOOL="$DLLTOOL" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_DLLTOOL="${ac_tool_prefix}dlltool" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +DLLTOOL=$ac_cv_prog_DLLTOOL +if test -n "$DLLTOOL"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DLLTOOL" >&5 +$as_echo "$DLLTOOL" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_DLLTOOL"; then + ac_ct_DLLTOOL=$DLLTOOL + # Extract the first word of "dlltool", so it can be a program name with args. +set dummy dlltool; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_ac_ct_DLLTOOL+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_DLLTOOL"; then + ac_cv_prog_ac_ct_DLLTOOL="$ac_ct_DLLTOOL" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_ac_ct_DLLTOOL="dlltool" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_DLLTOOL=$ac_cv_prog_ac_ct_DLLTOOL +if test -n "$ac_ct_DLLTOOL"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_DLLTOOL" >&5 +$as_echo "$ac_ct_DLLTOOL" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_DLLTOOL" = x; then + DLLTOOL="false" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + DLLTOOL=$ac_ct_DLLTOOL + fi +else + DLLTOOL="$ac_cv_prog_DLLTOOL" +fi + + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}objdump", so it can be a program name with args. +set dummy ${ac_tool_prefix}objdump; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_OBJDUMP+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$OBJDUMP"; then + ac_cv_prog_OBJDUMP="$OBJDUMP" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_OBJDUMP="${ac_tool_prefix}objdump" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +OBJDUMP=$ac_cv_prog_OBJDUMP +if test -n "$OBJDUMP"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OBJDUMP" >&5 +$as_echo "$OBJDUMP" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_OBJDUMP"; then + ac_ct_OBJDUMP=$OBJDUMP + # Extract the first word of "objdump", so it can be a program name with args. +set dummy objdump; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_ac_ct_OBJDUMP+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_OBJDUMP"; then + ac_cv_prog_ac_ct_OBJDUMP="$ac_ct_OBJDUMP" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_ac_ct_OBJDUMP="objdump" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_OBJDUMP=$ac_cv_prog_ac_ct_OBJDUMP +if test -n "$ac_ct_OBJDUMP"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OBJDUMP" >&5 +$as_echo "$ac_ct_OBJDUMP" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_OBJDUMP" = x; then + OBJDUMP="false" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + OBJDUMP=$ac_ct_OBJDUMP + fi +else + OBJDUMP="$ac_cv_prog_OBJDUMP" +fi + + ;; +esac + +test -z "$AS" && AS=as + + + + + +test -z "$DLLTOOL" && DLLTOOL=dlltool + + + + + +test -z "$OBJDUMP" && OBJDUMP=objdump + + + + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ln -s works" >&5 +$as_echo_n "checking whether ln -s works... " >&6; } +LN_S=$as_ln_s +if test "$LN_S" = "ln -s"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no, using $LN_S" >&5 +$as_echo "no, using $LN_S" >&6; } +fi + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${MAKE-make} sets \$(MAKE)" >&5 +$as_echo_n "checking whether ${MAKE-make} sets \$(MAKE)... " >&6; } +set x ${MAKE-make} +ac_make=`$as_echo "$2" | sed 's/+/p/g; s/[^a-zA-Z0-9_]/_/g'` +if { as_var=ac_cv_prog_make_${ac_make}_set; eval "test \"\${$as_var+set}\" = set"; }; then : + $as_echo_n "(cached) " >&6 +else + cat >conftest.make <<\_ACEOF +SHELL = /bin/sh +all: + @echo '@@@%%%=$(MAKE)=@@@%%%' +_ACEOF +# GNU make sometimes prints "make[1]: Entering...", which would confuse us. +case `${MAKE-make} -f conftest.make 2>/dev/null` in + *@@@%%%=?*=@@@%%%*) + eval ac_cv_prog_make_${ac_make}_set=yes;; + *) + eval ac_cv_prog_make_${ac_make}_set=no;; +esac +rm -f conftest.make +fi +if eval test \$ac_cv_prog_make_${ac_make}_set = yes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + SET_MAKE= +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + SET_MAKE="MAKE=${MAKE-make}" +fi + +case `pwd` in + *\ * | *\ *) + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Libtool does not cope well with whitespace in \`pwd\`" >&5 +$as_echo "$as_me: WARNING: Libtool does not cope well with whitespace in \`pwd\`" >&2;} ;; +esac + + + +macro_version='2.2.6b' +macro_revision='1.3017' + + + + + + + + + + + + + +ltmain="$ac_aux_dir/ltmain.sh" + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for BSD- or MS-compatible name lister (nm)" >&5 +$as_echo_n "checking for BSD- or MS-compatible name lister (nm)... " >&6; } +if test "${lt_cv_path_NM+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$NM"; then + # Let the user override the test. + lt_cv_path_NM="$NM" +else + lt_nm_to_check="${ac_tool_prefix}nm" + if test -n "$ac_tool_prefix" && test "$build" = "$host"; then + lt_nm_to_check="$lt_nm_to_check nm" + fi + for lt_tmp_nm in $lt_nm_to_check; do + lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR + for ac_dir in $PATH /usr/ccs/bin/elf /usr/ccs/bin /usr/ucb /bin; do + IFS="$lt_save_ifs" + test -z "$ac_dir" && ac_dir=. + tmp_nm="$ac_dir/$lt_tmp_nm" + if test -f "$tmp_nm" || test -f "$tmp_nm$ac_exeext" ; then + # Check to see if the nm accepts a BSD-compat flag. + # Adding the `sed 1q' prevents false positives on HP-UX, which says: + # nm: unknown option "B" ignored + # Tru64's nm complains that /dev/null is an invalid object file + case `"$tmp_nm" -B /dev/null 2>&1 | sed '1q'` in + */dev/null* | *'Invalid file or object type'*) + lt_cv_path_NM="$tmp_nm -B" + break + ;; + *) + case `"$tmp_nm" -p /dev/null 2>&1 | sed '1q'` in + */dev/null*) + lt_cv_path_NM="$tmp_nm -p" + break + ;; + *) + lt_cv_path_NM=${lt_cv_path_NM="$tmp_nm"} # keep the first match, but + continue # so that we can try to find one that supports BSD flags + ;; + esac + ;; + esac + fi + done + IFS="$lt_save_ifs" + done + : ${lt_cv_path_NM=no} +fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_path_NM" >&5 +$as_echo "$lt_cv_path_NM" >&6; } +if test "$lt_cv_path_NM" != "no"; then + NM="$lt_cv_path_NM" +else + # Didn't find any BSD compatible name lister, look for dumpbin. + if test -n "$ac_tool_prefix"; then + for ac_prog in "dumpbin -symbols" "link -dump -symbols" + do + # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. +set dummy $ac_tool_prefix$ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_DUMPBIN+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$DUMPBIN"; then + ac_cv_prog_DUMPBIN="$DUMPBIN" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_DUMPBIN="$ac_tool_prefix$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +DUMPBIN=$ac_cv_prog_DUMPBIN +if test -n "$DUMPBIN"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DUMPBIN" >&5 +$as_echo "$DUMPBIN" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$DUMPBIN" && break + done +fi +if test -z "$DUMPBIN"; then + ac_ct_DUMPBIN=$DUMPBIN + for ac_prog in "dumpbin -symbols" "link -dump -symbols" +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_ac_ct_DUMPBIN+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_DUMPBIN"; then + ac_cv_prog_ac_ct_DUMPBIN="$ac_ct_DUMPBIN" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_ac_ct_DUMPBIN="$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_DUMPBIN=$ac_cv_prog_ac_ct_DUMPBIN +if test -n "$ac_ct_DUMPBIN"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_DUMPBIN" >&5 +$as_echo "$ac_ct_DUMPBIN" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$ac_ct_DUMPBIN" && break +done + + if test "x$ac_ct_DUMPBIN" = x; then + DUMPBIN=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + DUMPBIN=$ac_ct_DUMPBIN + fi +fi + + + if test "$DUMPBIN" != ":"; then + NM="$DUMPBIN" + fi +fi +test -z "$NM" && NM=nm + + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking the name lister ($NM) interface" >&5 +$as_echo_n "checking the name lister ($NM) interface... " >&6; } +if test "${lt_cv_nm_interface+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_nm_interface="BSD nm" + echo "int some_variable = 0;" > conftest.$ac_ext + (eval echo "\"\$as_me:5158: $ac_compile\"" >&5) + (eval "$ac_compile" 2>conftest.err) + cat conftest.err >&5 + (eval echo "\"\$as_me:5161: $NM \\\"conftest.$ac_objext\\\"\"" >&5) + (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out) + cat conftest.err >&5 + (eval echo "\"\$as_me:5164: output\"" >&5) + cat conftest.out >&5 + if $GREP 'External.*some_variable' conftest.out > /dev/null; then + lt_cv_nm_interface="MS dumpbin" + fi + rm -f conftest* +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_nm_interface" >&5 +$as_echo "$lt_cv_nm_interface" >&6; } + +# find the maximum length of command line arguments +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking the maximum length of command line arguments" >&5 +$as_echo_n "checking the maximum length of command line arguments... " >&6; } +if test "${lt_cv_sys_max_cmd_len+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + i=0 + teststring="ABCD" + + case $build_os in + msdosdjgpp*) + # On DJGPP, this test can blow up pretty badly due to problems in libc + # (any single argument exceeding 2000 bytes causes a buffer overrun + # during glob expansion). Even if it were fixed, the result of this + # check would be larger than it should be. + lt_cv_sys_max_cmd_len=12288; # 12K is about right + ;; + + gnu*) + # Under GNU Hurd, this test is not required because there is + # no limit to the length of command line arguments. + # Libtool will interpret -1 as no limit whatsoever + lt_cv_sys_max_cmd_len=-1; + ;; + + cygwin* | mingw* | cegcc*) + # On Win9x/ME, this test blows up -- it succeeds, but takes + # about 5 minutes as the teststring grows exponentially. + # Worse, since 9x/ME are not pre-emptively multitasking, + # you end up with a "frozen" computer, even though with patience + # the test eventually succeeds (with a max line length of 256k). + # Instead, let's just punt: use the minimum linelength reported by + # all of the supported platforms: 8192 (on NT/2K/XP). + lt_cv_sys_max_cmd_len=8192; + ;; + + amigaos*) + # On AmigaOS with pdksh, this test takes hours, literally. + # So we just punt and use a minimum line length of 8192. + lt_cv_sys_max_cmd_len=8192; + ;; + + netbsd* | freebsd* | openbsd* | darwin* | dragonfly*) + # This has been around since 386BSD, at least. Likely further. + if test -x /sbin/sysctl; then + lt_cv_sys_max_cmd_len=`/sbin/sysctl -n kern.argmax` + elif test -x /usr/sbin/sysctl; then + lt_cv_sys_max_cmd_len=`/usr/sbin/sysctl -n kern.argmax` + else + lt_cv_sys_max_cmd_len=65536 # usable default for all BSDs + fi + # And add a safety zone + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4` + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3` + ;; + + interix*) + # We know the value 262144 and hardcode it with a safety zone (like BSD) + lt_cv_sys_max_cmd_len=196608 + ;; + + osf*) + # Dr. Hans Ekkehard Plesser reports seeing a kernel panic running configure + # due to this test when exec_disable_arg_limit is 1 on Tru64. It is not + # nice to cause kernel panics so lets avoid the loop below. + # First set a reasonable default. + lt_cv_sys_max_cmd_len=16384 + # + if test -x /sbin/sysconfig; then + case `/sbin/sysconfig -q proc exec_disable_arg_limit` in + *1*) lt_cv_sys_max_cmd_len=-1 ;; + esac + fi + ;; + sco3.2v5*) + lt_cv_sys_max_cmd_len=102400 + ;; + sysv5* | sco5v6* | sysv4.2uw2*) + kargmax=`grep ARG_MAX /etc/conf/cf.d/stune 2>/dev/null` + if test -n "$kargmax"; then + lt_cv_sys_max_cmd_len=`echo $kargmax | sed 's/.*[ ]//'` + else + lt_cv_sys_max_cmd_len=32768 + fi + ;; + *) + lt_cv_sys_max_cmd_len=`(getconf ARG_MAX) 2> /dev/null` + if test -n "$lt_cv_sys_max_cmd_len"; then + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4` + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3` + else + # Make teststring a little bigger before we do anything with it. + # a 1K string should be a reasonable start. + for i in 1 2 3 4 5 6 7 8 ; do + teststring=$teststring$teststring + done + SHELL=${SHELL-${CONFIG_SHELL-/bin/sh}} + # If test is not a shell built-in, we'll probably end up computing a + # maximum length that is only half of the actual maximum length, but + # we can't tell. + while { test "X"`$SHELL $0 --fallback-echo "X$teststring$teststring" 2>/dev/null` \ + = "XX$teststring$teststring"; } >/dev/null 2>&1 && + test $i != 17 # 1/2 MB should be enough + do + i=`expr $i + 1` + teststring=$teststring$teststring + done + # Only check the string length outside the loop. + lt_cv_sys_max_cmd_len=`expr "X$teststring" : ".*" 2>&1` + teststring= + # Add a significant safety factor because C++ compilers can tack on + # massive amounts of additional arguments before passing them to the + # linker. It appears as though 1/2 is a usable value. + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 2` + fi + ;; + esac + +fi + +if test -n $lt_cv_sys_max_cmd_len ; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_sys_max_cmd_len" >&5 +$as_echo "$lt_cv_sys_max_cmd_len" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: none" >&5 +$as_echo "none" >&6; } +fi +max_cmd_len=$lt_cv_sys_max_cmd_len + + + + + + +: ${CP="cp -f"} +: ${MV="mv -f"} +: ${RM="rm -f"} + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the shell understands some XSI constructs" >&5 +$as_echo_n "checking whether the shell understands some XSI constructs... " >&6; } +# Try some XSI features +xsi_shell=no +( _lt_dummy="a/b/c" + test "${_lt_dummy##*/},${_lt_dummy%/*},"${_lt_dummy%"$_lt_dummy"}, \ + = c,a/b,, \ + && eval 'test $(( 1 + 1 )) -eq 2 \ + && test "${#_lt_dummy}" -eq 5' ) >/dev/null 2>&1 \ + && xsi_shell=yes +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xsi_shell" >&5 +$as_echo "$xsi_shell" >&6; } + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the shell understands \"+=\"" >&5 +$as_echo_n "checking whether the shell understands \"+=\"... " >&6; } +lt_shell_append=no +( foo=bar; set foo baz; eval "$1+=\$2" && test "$foo" = barbaz ) \ + >/dev/null 2>&1 \ + && lt_shell_append=yes +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_shell_append" >&5 +$as_echo "$lt_shell_append" >&6; } + + +if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then + lt_unset=unset +else + lt_unset=false +fi + + + + + +# test EBCDIC or ASCII +case `echo X|tr X '\101'` in + A) # ASCII based system + # \n is not interpreted correctly by Solaris 8 /usr/ucb/tr + lt_SP2NL='tr \040 \012' + lt_NL2SP='tr \015\012 \040\040' + ;; + *) # EBCDIC based system + lt_SP2NL='tr \100 \n' + lt_NL2SP='tr \r\n \100\100' + ;; +esac + + + + + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $LD option to reload object files" >&5 +$as_echo_n "checking for $LD option to reload object files... " >&6; } +if test "${lt_cv_ld_reload_flag+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_ld_reload_flag='-r' +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ld_reload_flag" >&5 +$as_echo "$lt_cv_ld_reload_flag" >&6; } +reload_flag=$lt_cv_ld_reload_flag +case $reload_flag in +"" | " "*) ;; +*) reload_flag=" $reload_flag" ;; +esac +reload_cmds='$LD$reload_flag -o $output$reload_objs' +case $host_os in + darwin*) + if test "$GCC" = yes; then + reload_cmds='$LTCC $LTCFLAGS -nostdlib ${wl}-r -o $output$reload_objs' + else + reload_cmds='$LD$reload_flag -o $output$reload_objs' + fi + ;; +esac + + + + + + + + + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}objdump", so it can be a program name with args. +set dummy ${ac_tool_prefix}objdump; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_OBJDUMP+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$OBJDUMP"; then + ac_cv_prog_OBJDUMP="$OBJDUMP" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_OBJDUMP="${ac_tool_prefix}objdump" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +OBJDUMP=$ac_cv_prog_OBJDUMP +if test -n "$OBJDUMP"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OBJDUMP" >&5 +$as_echo "$OBJDUMP" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_OBJDUMP"; then + ac_ct_OBJDUMP=$OBJDUMP + # Extract the first word of "objdump", so it can be a program name with args. +set dummy objdump; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_ac_ct_OBJDUMP+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_OBJDUMP"; then + ac_cv_prog_ac_ct_OBJDUMP="$ac_ct_OBJDUMP" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_ac_ct_OBJDUMP="objdump" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_OBJDUMP=$ac_cv_prog_ac_ct_OBJDUMP +if test -n "$ac_ct_OBJDUMP"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OBJDUMP" >&5 +$as_echo "$ac_ct_OBJDUMP" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_OBJDUMP" = x; then + OBJDUMP="false" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + OBJDUMP=$ac_ct_OBJDUMP + fi +else + OBJDUMP="$ac_cv_prog_OBJDUMP" +fi + +test -z "$OBJDUMP" && OBJDUMP=objdump + + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to recognize dependent libraries" >&5 +$as_echo_n "checking how to recognize dependent libraries... " >&6; } +if test "${lt_cv_deplibs_check_method+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_file_magic_cmd='$MAGIC_CMD' +lt_cv_file_magic_test_file= +lt_cv_deplibs_check_method='unknown' +# Need to set the preceding variable on all platforms that support +# interlibrary dependencies. +# 'none' -- dependencies not supported. +# `unknown' -- same as none, but documents that we really don't know. +# 'pass_all' -- all dependencies passed with no checks. +# 'test_compile' -- check by making test program. +# 'file_magic [[regex]]' -- check by looking for files in library path +# which responds to the $file_magic_cmd with a given extended regex. +# If you have `file' or equivalent on your system and you're not sure +# whether `pass_all' will *always* work, you probably want this one. + +case $host_os in +aix[4-9]*) + lt_cv_deplibs_check_method=pass_all + ;; + +beos*) + lt_cv_deplibs_check_method=pass_all + ;; + +bsdi[45]*) + lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [ML]SB (shared object|dynamic lib)' + lt_cv_file_magic_cmd='/usr/bin/file -L' + lt_cv_file_magic_test_file=/shlib/libc.so + ;; + +cygwin*) + # func_win32_libid is a shell function defined in ltmain.sh + lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL' + lt_cv_file_magic_cmd='func_win32_libid' + ;; + +mingw* | pw32*) + # Base MSYS/MinGW do not provide the 'file' command needed by + # func_win32_libid shell function, so use a weaker test based on 'objdump', + # unless we find 'file', for example because we are cross-compiling. + if ( file / ) >/dev/null 2>&1; then + lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL' + lt_cv_file_magic_cmd='func_win32_libid' + else + lt_cv_deplibs_check_method='file_magic file format pei*-i386(.*architecture: i386)?' + lt_cv_file_magic_cmd='$OBJDUMP -f' + fi + ;; + +cegcc) + # use the weaker test based on 'objdump'. See mingw*. + lt_cv_deplibs_check_method='file_magic file format pe-arm-.*little(.*architecture: arm)?' + lt_cv_file_magic_cmd='$OBJDUMP -f' + ;; + +darwin* | rhapsody*) + lt_cv_deplibs_check_method=pass_all + ;; + +freebsd* | dragonfly*) + if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then + case $host_cpu in + i*86 ) + # Not sure whether the presence of OpenBSD here was a mistake. + # Let's accept both of them until this is cleared up. + lt_cv_deplibs_check_method='file_magic (FreeBSD|OpenBSD|DragonFly)/i[3-9]86 (compact )?demand paged shared library' + lt_cv_file_magic_cmd=/usr/bin/file + lt_cv_file_magic_test_file=`echo /usr/lib/libc.so.*` + ;; + esac + else + lt_cv_deplibs_check_method=pass_all + fi + ;; + +gnu*) + lt_cv_deplibs_check_method=pass_all + ;; + +hpux10.20* | hpux11*) + lt_cv_file_magic_cmd=/usr/bin/file + case $host_cpu in + ia64*) + lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|ELF-[0-9][0-9]) shared object file - IA64' + lt_cv_file_magic_test_file=/usr/lib/hpux32/libc.so + ;; + hppa*64*) + lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|ELF-[0-9][0-9]) shared object file - PA-RISC [0-9].[0-9]' + lt_cv_file_magic_test_file=/usr/lib/pa20_64/libc.sl + ;; + *) + lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|PA-RISC[0-9].[0-9]) shared library' + lt_cv_file_magic_test_file=/usr/lib/libc.sl + ;; + esac + ;; + +interix[3-9]*) + # PIC code is broken on Interix 3.x, that's why |\.a not |_pic\.a here + lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so|\.a)$' + ;; + +irix5* | irix6* | nonstopux*) + case $LD in + *-32|*"-32 ") libmagic=32-bit;; + *-n32|*"-n32 ") libmagic=N32;; + *-64|*"-64 ") libmagic=64-bit;; + *) libmagic=never-match;; + esac + lt_cv_deplibs_check_method=pass_all + ;; + +# This must be Linux ELF. +linux* | k*bsd*-gnu) + lt_cv_deplibs_check_method=pass_all + ;; + +netbsd*) + if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then + lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so\.[0-9]+\.[0-9]+|_pic\.a)$' + else + lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so|_pic\.a)$' + fi + ;; + +newos6*) + lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [ML]SB (executable|dynamic lib)' + lt_cv_file_magic_cmd=/usr/bin/file + lt_cv_file_magic_test_file=/usr/lib/libnls.so + ;; + +*nto* | *qnx*) + lt_cv_deplibs_check_method=pass_all + ;; + +openbsd*) + if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then + lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so\.[0-9]+\.[0-9]+|\.so|_pic\.a)$' + else + lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so\.[0-9]+\.[0-9]+|_pic\.a)$' + fi + ;; + +osf3* | osf4* | osf5*) + lt_cv_deplibs_check_method=pass_all + ;; + +rdos*) + lt_cv_deplibs_check_method=pass_all + ;; + +solaris*) + lt_cv_deplibs_check_method=pass_all + ;; + +sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*) + lt_cv_deplibs_check_method=pass_all + ;; + +sysv4 | sysv4.3*) + case $host_vendor in + motorola) + lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [ML]SB (shared object|dynamic lib) M[0-9][0-9]* Version [0-9]' + lt_cv_file_magic_test_file=`echo /usr/lib/libc.so*` + ;; + ncr) + lt_cv_deplibs_check_method=pass_all + ;; + sequent) + lt_cv_file_magic_cmd='/bin/file' + lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [LM]SB (shared object|dynamic lib )' + ;; + sni) + lt_cv_file_magic_cmd='/bin/file' + lt_cv_deplibs_check_method="file_magic ELF [0-9][0-9]*-bit [LM]SB dynamic lib" + lt_cv_file_magic_test_file=/lib/libc.so + ;; + siemens) + lt_cv_deplibs_check_method=pass_all + ;; + pc) + lt_cv_deplibs_check_method=pass_all + ;; + esac + ;; + +tpf*) + lt_cv_deplibs_check_method=pass_all + ;; +esac + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_deplibs_check_method" >&5 +$as_echo "$lt_cv_deplibs_check_method" >&6; } +file_magic_cmd=$lt_cv_file_magic_cmd +deplibs_check_method=$lt_cv_deplibs_check_method +test -z "$deplibs_check_method" && deplibs_check_method=unknown + + + + + + + + + + + + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}ar", so it can be a program name with args. +set dummy ${ac_tool_prefix}ar; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_AR+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$AR"; then + ac_cv_prog_AR="$AR" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_AR="${ac_tool_prefix}ar" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +AR=$ac_cv_prog_AR +if test -n "$AR"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AR" >&5 +$as_echo "$AR" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_AR"; then + ac_ct_AR=$AR + # Extract the first word of "ar", so it can be a program name with args. +set dummy ar; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_ac_ct_AR+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_AR"; then + ac_cv_prog_ac_ct_AR="$ac_ct_AR" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_ac_ct_AR="ar" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_AR=$ac_cv_prog_ac_ct_AR +if test -n "$ac_ct_AR"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_AR" >&5 +$as_echo "$ac_ct_AR" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_AR" = x; then + AR="false" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + AR=$ac_ct_AR + fi +else + AR="$ac_cv_prog_AR" +fi + +test -z "$AR" && AR=ar +test -z "$AR_FLAGS" && AR_FLAGS=cru + + + + + + + + + + + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}strip", so it can be a program name with args. +set dummy ${ac_tool_prefix}strip; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_STRIP+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$STRIP"; then + ac_cv_prog_STRIP="$STRIP" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_STRIP="${ac_tool_prefix}strip" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +STRIP=$ac_cv_prog_STRIP +if test -n "$STRIP"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $STRIP" >&5 +$as_echo "$STRIP" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_STRIP"; then + ac_ct_STRIP=$STRIP + # Extract the first word of "strip", so it can be a program name with args. +set dummy strip; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_ac_ct_STRIP+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_STRIP"; then + ac_cv_prog_ac_ct_STRIP="$ac_ct_STRIP" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_ac_ct_STRIP="strip" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_STRIP=$ac_cv_prog_ac_ct_STRIP +if test -n "$ac_ct_STRIP"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_STRIP" >&5 +$as_echo "$ac_ct_STRIP" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_STRIP" = x; then + STRIP=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + STRIP=$ac_ct_STRIP + fi +else + STRIP="$ac_cv_prog_STRIP" +fi + +test -z "$STRIP" && STRIP=: + + + + + + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args. +set dummy ${ac_tool_prefix}ranlib; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_RANLIB+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$RANLIB"; then + ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +RANLIB=$ac_cv_prog_RANLIB +if test -n "$RANLIB"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $RANLIB" >&5 +$as_echo "$RANLIB" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_RANLIB"; then + ac_ct_RANLIB=$RANLIB + # Extract the first word of "ranlib", so it can be a program name with args. +set dummy ranlib; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_ac_ct_RANLIB+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_RANLIB"; then + ac_cv_prog_ac_ct_RANLIB="$ac_ct_RANLIB" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_ac_ct_RANLIB="ranlib" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_RANLIB=$ac_cv_prog_ac_ct_RANLIB +if test -n "$ac_ct_RANLIB"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_RANLIB" >&5 +$as_echo "$ac_ct_RANLIB" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_RANLIB" = x; then + RANLIB=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + RANLIB=$ac_ct_RANLIB + fi +else + RANLIB="$ac_cv_prog_RANLIB" +fi + +test -z "$RANLIB" && RANLIB=: + + + + + + +# Determine commands to create old-style static archives. +old_archive_cmds='$AR $AR_FLAGS $oldlib$oldobjs' +old_postinstall_cmds='chmod 644 $oldlib' +old_postuninstall_cmds= + +if test -n "$RANLIB"; then + case $host_os in + openbsd*) + old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB -t \$oldlib" + ;; + *) + old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB \$oldlib" + ;; + esac + old_archive_cmds="$old_archive_cmds~\$RANLIB \$oldlib" +fi + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +# If no C compiler was specified, use CC. +LTCC=${LTCC-"$CC"} + +# If no C compiler flags were specified, use CFLAGS. +LTCFLAGS=${LTCFLAGS-"$CFLAGS"} + +# Allow CC to be a program name with arguments. +compiler=$CC + + +# Check for command to grab the raw symbol name followed by C symbol from nm. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking command to parse $NM output from $compiler object" >&5 +$as_echo_n "checking command to parse $NM output from $compiler object... " >&6; } +if test "${lt_cv_sys_global_symbol_pipe+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + +# These are sane defaults that work on at least a few old systems. +# [They come from Ultrix. What could be older than Ultrix?!! ;)] + +# Character class describing NM global symbol codes. +symcode='[BCDEGRST]' + +# Regexp to match symbols that can be accessed directly from C. +sympat='\([_A-Za-z][_A-Za-z0-9]*\)' + +# Define system-specific variables. +case $host_os in +aix*) + symcode='[BCDT]' + ;; +cygwin* | mingw* | pw32* | cegcc*) + symcode='[ABCDGISTW]' + ;; +hpux*) + if test "$host_cpu" = ia64; then + symcode='[ABCDEGRST]' + fi + ;; +irix* | nonstopux*) + symcode='[BCDEGRST]' + ;; +osf*) + symcode='[BCDEGQRST]' + ;; +solaris*) + symcode='[BDRT]' + ;; +sco3.2v5*) + symcode='[DT]' + ;; +sysv4.2uw2*) + symcode='[DT]' + ;; +sysv5* | sco5v6* | unixware* | OpenUNIX*) + symcode='[ABDT]' + ;; +sysv4) + symcode='[DFNSTU]' + ;; +esac + +# If we're using GNU nm, then use its standard symbol codes. +case `$NM -V 2>&1` in +*GNU* | *'with BFD'*) + symcode='[ABCDGIRSTW]' ;; +esac + +# Transform an extracted symbol line into a proper C declaration. +# Some systems (esp. on ia64) link data and code symbols differently, +# so use this general approach. +lt_cv_sys_global_symbol_to_cdecl="sed -n -e 's/^T .* \(.*\)$/extern int \1();/p' -e 's/^$symcode* .* \(.*\)$/extern char \1;/p'" + +# Transform an extracted symbol line into symbol name and symbol address +lt_cv_sys_global_symbol_to_c_name_address="sed -n -e 's/^: \([^ ]*\) $/ {\\\"\1\\\", (void *) 0},/p' -e 's/^$symcode* \([^ ]*\) \([^ ]*\)$/ {\"\2\", (void *) \&\2},/p'" +lt_cv_sys_global_symbol_to_c_name_address_lib_prefix="sed -n -e 's/^: \([^ ]*\) $/ {\\\"\1\\\", (void *) 0},/p' -e 's/^$symcode* \([^ ]*\) \(lib[^ ]*\)$/ {\"\2\", (void *) \&\2},/p' -e 's/^$symcode* \([^ ]*\) \([^ ]*\)$/ {\"lib\2\", (void *) \&\2},/p'" + +# Handle CRLF in mingw tool chain +opt_cr= +case $build_os in +mingw*) + opt_cr=`$ECHO 'x\{0,1\}' | tr x '\015'` # option cr in regexp + ;; +esac + +# Try without a prefix underscore, then with it. +for ac_symprfx in "" "_"; do + + # Transform symcode, sympat, and symprfx into a raw symbol and a C symbol. + symxfrm="\\1 $ac_symprfx\\2 \\2" + + # Write the raw and C identifiers. + if test "$lt_cv_nm_interface" = "MS dumpbin"; then + # Fake it for dumpbin and say T for any non-static function + # and D for any global variable. + # Also find C++ and __fastcall symbols from MSVC++, + # which start with @ or ?. + lt_cv_sys_global_symbol_pipe="$AWK '"\ +" {last_section=section; section=\$ 3};"\ +" /Section length .*#relocs.*(pick any)/{hide[last_section]=1};"\ +" \$ 0!~/External *\|/{next};"\ +" / 0+ UNDEF /{next}; / UNDEF \([^|]\)*()/{next};"\ +" {if(hide[section]) next};"\ +" {f=0}; \$ 0~/\(\).*\|/{f=1}; {printf f ? \"T \" : \"D \"};"\ +" {split(\$ 0, a, /\||\r/); split(a[2], s)};"\ +" s[1]~/^[@?]/{print s[1], s[1]; next};"\ +" s[1]~prfx {split(s[1],t,\"@\"); print t[1], substr(t[1],length(prfx))}"\ +" ' prfx=^$ac_symprfx" + else + lt_cv_sys_global_symbol_pipe="sed -n -e 's/^.*[ ]\($symcode$symcode*\)[ ][ ]*$ac_symprfx$sympat$opt_cr$/$symxfrm/p'" + fi + + # Check to see that the pipe works correctly. + pipe_works=no + + rm -f conftest* + cat > conftest.$ac_ext <<_LT_EOF +#ifdef __cplusplus +extern "C" { +#endif +char nm_test_var; +void nm_test_func(void); +void nm_test_func(void){} +#ifdef __cplusplus +} +#endif +int main(){nm_test_var='a';nm_test_func();return(0);} +_LT_EOF + + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + # Now try to grab the symbols. + nlist=conftest.nm + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$NM conftest.$ac_objext \| $lt_cv_sys_global_symbol_pipe \> $nlist\""; } >&5 + (eval $NM conftest.$ac_objext \| $lt_cv_sys_global_symbol_pipe \> $nlist) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && test -s "$nlist"; then + # Try sorting and uniquifying the output. + if sort "$nlist" | uniq > "$nlist"T; then + mv -f "$nlist"T "$nlist" + else + rm -f "$nlist"T + fi + + # Make sure that we snagged all the symbols we need. + if $GREP ' nm_test_var$' "$nlist" >/dev/null; then + if $GREP ' nm_test_func$' "$nlist" >/dev/null; then + cat <<_LT_EOF > conftest.$ac_ext +#ifdef __cplusplus +extern "C" { +#endif + +_LT_EOF + # Now generate the symbol file. + eval "$lt_cv_sys_global_symbol_to_cdecl"' < "$nlist" | $GREP -v main >> conftest.$ac_ext' + + cat <<_LT_EOF >> conftest.$ac_ext + +/* The mapping between symbol names and symbols. */ +const struct { + const char *name; + void *address; +} +lt__PROGRAM__LTX_preloaded_symbols[] = +{ + { "@PROGRAM@", (void *) 0 }, +_LT_EOF + $SED "s/^$symcode$symcode* \(.*\) \(.*\)$/ {\"\2\", (void *) \&\2},/" < "$nlist" | $GREP -v main >> conftest.$ac_ext + cat <<\_LT_EOF >> conftest.$ac_ext + {0, (void *) 0} +}; + +/* This works around a problem in FreeBSD linker */ +#ifdef FREEBSD_WORKAROUND +static const void *lt_preloaded_setup() { + return lt__PROGRAM__LTX_preloaded_symbols; +} +#endif + +#ifdef __cplusplus +} +#endif +_LT_EOF + # Now try linking the two files. + mv conftest.$ac_objext conftstm.$ac_objext + lt_save_LIBS="$LIBS" + lt_save_CFLAGS="$CFLAGS" + LIBS="conftstm.$ac_objext" + CFLAGS="$CFLAGS$lt_prog_compiler_no_builtin_flag" + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_link\""; } >&5 + (eval $ac_link) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && test -s conftest${ac_exeext}; then + pipe_works=yes + fi + LIBS="$lt_save_LIBS" + CFLAGS="$lt_save_CFLAGS" + else + echo "cannot find nm_test_func in $nlist" >&5 + fi + else + echo "cannot find nm_test_var in $nlist" >&5 + fi + else + echo "cannot run $lt_cv_sys_global_symbol_pipe" >&5 + fi + else + echo "$progname: failed program was:" >&5 + cat conftest.$ac_ext >&5 + fi + rm -rf conftest* conftst* + + # Do not use the global_symbol_pipe unless it works. + if test "$pipe_works" = yes; then + break + else + lt_cv_sys_global_symbol_pipe= + fi +done + +fi + +if test -z "$lt_cv_sys_global_symbol_pipe"; then + lt_cv_sys_global_symbol_to_cdecl= +fi +if test -z "$lt_cv_sys_global_symbol_pipe$lt_cv_sys_global_symbol_to_cdecl"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: failed" >&5 +$as_echo "failed" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: ok" >&5 +$as_echo "ok" >&6; } +fi + + + + + + + + + + + + + + + + + + + + + + + +# Check whether --enable-libtool-lock was given. +if test "${enable_libtool_lock+set}" = set; then : + enableval=$enable_libtool_lock; +fi + +test "x$enable_libtool_lock" != xno && enable_libtool_lock=yes + +# Some flags need to be propagated to the compiler or linker for good +# libtool support. +case $host in +ia64-*-hpux*) + # Find out which ABI we are using. + echo 'int i;' > conftest.$ac_ext + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + case `/usr/bin/file conftest.$ac_objext` in + *ELF-32*) + HPUX_IA64_MODE="32" + ;; + *ELF-64*) + HPUX_IA64_MODE="64" + ;; + esac + fi + rm -rf conftest* + ;; +*-*-irix6*) + # Find out which ABI we are using. + echo '#line 6356 "configure"' > conftest.$ac_ext + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + if test "$lt_cv_prog_gnu_ld" = yes; then + case `/usr/bin/file conftest.$ac_objext` in + *32-bit*) + LD="${LD-ld} -melf32bsmip" + ;; + *N32*) + LD="${LD-ld} -melf32bmipn32" + ;; + *64-bit*) + LD="${LD-ld} -melf64bmip" + ;; + esac + else + case `/usr/bin/file conftest.$ac_objext` in + *32-bit*) + LD="${LD-ld} -32" + ;; + *N32*) + LD="${LD-ld} -n32" + ;; + *64-bit*) + LD="${LD-ld} -64" + ;; + esac + fi + fi + rm -rf conftest* + ;; + +x86_64-*kfreebsd*-gnu|x86_64-*linux*|ppc*-*linux*|powerpc*-*linux*| \ +s390*-*linux*|s390*-*tpf*|sparc*-*linux*) + # Find out which ABI we are using. + echo 'int i;' > conftest.$ac_ext + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + case `/usr/bin/file conftest.o` in + *32-bit*) + case $host in + x86_64-*kfreebsd*-gnu) + LD="${LD-ld} -m elf_i386_fbsd" + ;; + x86_64-*linux*) + LD="${LD-ld} -m elf_i386" + ;; + ppc64-*linux*|powerpc64-*linux*) + LD="${LD-ld} -m elf32ppclinux" + ;; + s390x-*linux*) + LD="${LD-ld} -m elf_s390" + ;; + sparc64-*linux*) + LD="${LD-ld} -m elf32_sparc" + ;; + esac + ;; + *64-bit*) + case $host in + x86_64-*kfreebsd*-gnu) + LD="${LD-ld} -m elf_x86_64_fbsd" + ;; + x86_64-*linux*) + LD="${LD-ld} -m elf_x86_64" + ;; + ppc*-*linux*|powerpc*-*linux*) + LD="${LD-ld} -m elf64ppc" + ;; + s390*-*linux*|s390*-*tpf*) + LD="${LD-ld} -m elf64_s390" + ;; + sparc*-*linux*) + LD="${LD-ld} -m elf64_sparc" + ;; + esac + ;; + esac + fi + rm -rf conftest* + ;; + +*-*-sco3.2v5*) + # On SCO OpenServer 5, we need -belf to get full-featured binaries. + SAVE_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS -belf" + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C compiler needs -belf" >&5 +$as_echo_n "checking whether the C compiler needs -belf... " >&6; } +if test "${lt_cv_cc_needs_belf+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + lt_cv_cc_needs_belf=yes +else + lt_cv_cc_needs_belf=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_cc_needs_belf" >&5 +$as_echo "$lt_cv_cc_needs_belf" >&6; } + if test x"$lt_cv_cc_needs_belf" != x"yes"; then + # this is probably gcc 2.8.0, egcs 1.0 or newer; no need for -belf + CFLAGS="$SAVE_CFLAGS" + fi + ;; +sparc*-*solaris*) + # Find out which ABI we are using. + echo 'int i;' > conftest.$ac_ext + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + case `/usr/bin/file conftest.o` in + *64-bit*) + case $lt_cv_prog_gnu_ld in + yes*) LD="${LD-ld} -m elf64_sparc" ;; + *) + if ${LD-ld} -64 -r -o conftest2.o conftest.o >/dev/null 2>&1; then + LD="${LD-ld} -64" + fi + ;; + esac + ;; + esac + fi + rm -rf conftest* + ;; +esac + +need_locks="$enable_libtool_lock" + + + case $host_os in + rhapsody* | darwin*) + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}dsymutil", so it can be a program name with args. +set dummy ${ac_tool_prefix}dsymutil; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_DSYMUTIL+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$DSYMUTIL"; then + ac_cv_prog_DSYMUTIL="$DSYMUTIL" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_DSYMUTIL="${ac_tool_prefix}dsymutil" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +DSYMUTIL=$ac_cv_prog_DSYMUTIL +if test -n "$DSYMUTIL"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DSYMUTIL" >&5 +$as_echo "$DSYMUTIL" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_DSYMUTIL"; then + ac_ct_DSYMUTIL=$DSYMUTIL + # Extract the first word of "dsymutil", so it can be a program name with args. +set dummy dsymutil; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_ac_ct_DSYMUTIL+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_DSYMUTIL"; then + ac_cv_prog_ac_ct_DSYMUTIL="$ac_ct_DSYMUTIL" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_ac_ct_DSYMUTIL="dsymutil" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_DSYMUTIL=$ac_cv_prog_ac_ct_DSYMUTIL +if test -n "$ac_ct_DSYMUTIL"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_DSYMUTIL" >&5 +$as_echo "$ac_ct_DSYMUTIL" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_DSYMUTIL" = x; then + DSYMUTIL=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + DSYMUTIL=$ac_ct_DSYMUTIL + fi +else + DSYMUTIL="$ac_cv_prog_DSYMUTIL" +fi + + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}nmedit", so it can be a program name with args. +set dummy ${ac_tool_prefix}nmedit; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_NMEDIT+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$NMEDIT"; then + ac_cv_prog_NMEDIT="$NMEDIT" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_NMEDIT="${ac_tool_prefix}nmedit" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +NMEDIT=$ac_cv_prog_NMEDIT +if test -n "$NMEDIT"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $NMEDIT" >&5 +$as_echo "$NMEDIT" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_NMEDIT"; then + ac_ct_NMEDIT=$NMEDIT + # Extract the first word of "nmedit", so it can be a program name with args. +set dummy nmedit; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_ac_ct_NMEDIT+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_NMEDIT"; then + ac_cv_prog_ac_ct_NMEDIT="$ac_ct_NMEDIT" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_ac_ct_NMEDIT="nmedit" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_NMEDIT=$ac_cv_prog_ac_ct_NMEDIT +if test -n "$ac_ct_NMEDIT"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_NMEDIT" >&5 +$as_echo "$ac_ct_NMEDIT" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_NMEDIT" = x; then + NMEDIT=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + NMEDIT=$ac_ct_NMEDIT + fi +else + NMEDIT="$ac_cv_prog_NMEDIT" +fi + + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}lipo", so it can be a program name with args. +set dummy ${ac_tool_prefix}lipo; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_LIPO+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$LIPO"; then + ac_cv_prog_LIPO="$LIPO" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_LIPO="${ac_tool_prefix}lipo" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +LIPO=$ac_cv_prog_LIPO +if test -n "$LIPO"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LIPO" >&5 +$as_echo "$LIPO" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_LIPO"; then + ac_ct_LIPO=$LIPO + # Extract the first word of "lipo", so it can be a program name with args. +set dummy lipo; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_ac_ct_LIPO+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_LIPO"; then + ac_cv_prog_ac_ct_LIPO="$ac_ct_LIPO" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_ac_ct_LIPO="lipo" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_LIPO=$ac_cv_prog_ac_ct_LIPO +if test -n "$ac_ct_LIPO"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_LIPO" >&5 +$as_echo "$ac_ct_LIPO" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_LIPO" = x; then + LIPO=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + LIPO=$ac_ct_LIPO + fi +else + LIPO="$ac_cv_prog_LIPO" +fi + + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}otool", so it can be a program name with args. +set dummy ${ac_tool_prefix}otool; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_OTOOL+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$OTOOL"; then + ac_cv_prog_OTOOL="$OTOOL" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_OTOOL="${ac_tool_prefix}otool" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +OTOOL=$ac_cv_prog_OTOOL +if test -n "$OTOOL"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OTOOL" >&5 +$as_echo "$OTOOL" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_OTOOL"; then + ac_ct_OTOOL=$OTOOL + # Extract the first word of "otool", so it can be a program name with args. +set dummy otool; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_ac_ct_OTOOL+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_OTOOL"; then + ac_cv_prog_ac_ct_OTOOL="$ac_ct_OTOOL" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_ac_ct_OTOOL="otool" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_OTOOL=$ac_cv_prog_ac_ct_OTOOL +if test -n "$ac_ct_OTOOL"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OTOOL" >&5 +$as_echo "$ac_ct_OTOOL" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_OTOOL" = x; then + OTOOL=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + OTOOL=$ac_ct_OTOOL + fi +else + OTOOL="$ac_cv_prog_OTOOL" +fi + + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}otool64", so it can be a program name with args. +set dummy ${ac_tool_prefix}otool64; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_OTOOL64+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$OTOOL64"; then + ac_cv_prog_OTOOL64="$OTOOL64" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_OTOOL64="${ac_tool_prefix}otool64" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +OTOOL64=$ac_cv_prog_OTOOL64 +if test -n "$OTOOL64"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OTOOL64" >&5 +$as_echo "$OTOOL64" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_OTOOL64"; then + ac_ct_OTOOL64=$OTOOL64 + # Extract the first word of "otool64", so it can be a program name with args. +set dummy otool64; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_ac_ct_OTOOL64+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_OTOOL64"; then + ac_cv_prog_ac_ct_OTOOL64="$ac_ct_OTOOL64" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_ac_ct_OTOOL64="otool64" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_OTOOL64=$ac_cv_prog_ac_ct_OTOOL64 +if test -n "$ac_ct_OTOOL64"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OTOOL64" >&5 +$as_echo "$ac_ct_OTOOL64" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_OTOOL64" = x; then + OTOOL64=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + OTOOL64=$ac_ct_OTOOL64 + fi +else + OTOOL64="$ac_cv_prog_OTOOL64" +fi + + + + + + + + + + + + + + + + + + + + + + + + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -single_module linker flag" >&5 +$as_echo_n "checking for -single_module linker flag... " >&6; } +if test "${lt_cv_apple_cc_single_mod+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_apple_cc_single_mod=no + if test -z "${LT_MULTI_MODULE}"; then + # By default we will add the -single_module flag. You can override + # by either setting the environment variable LT_MULTI_MODULE + # non-empty at configure time, or by adding -multi_module to the + # link flags. + rm -rf libconftest.dylib* + echo "int foo(void){return 1;}" > conftest.c + echo "$LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \ +-dynamiclib -Wl,-single_module conftest.c" >&5 + $LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \ + -dynamiclib -Wl,-single_module conftest.c 2>conftest.err + _lt_result=$? + if test -f libconftest.dylib && test ! -s conftest.err && test $_lt_result = 0; then + lt_cv_apple_cc_single_mod=yes + else + cat conftest.err >&5 + fi + rm -rf libconftest.dylib* + rm -f conftest.* + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_apple_cc_single_mod" >&5 +$as_echo "$lt_cv_apple_cc_single_mod" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -exported_symbols_list linker flag" >&5 +$as_echo_n "checking for -exported_symbols_list linker flag... " >&6; } +if test "${lt_cv_ld_exported_symbols_list+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_ld_exported_symbols_list=no + save_LDFLAGS=$LDFLAGS + echo "_main" > conftest.sym + LDFLAGS="$LDFLAGS -Wl,-exported_symbols_list,conftest.sym" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + lt_cv_ld_exported_symbols_list=yes +else + lt_cv_ld_exported_symbols_list=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + LDFLAGS="$save_LDFLAGS" + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ld_exported_symbols_list" >&5 +$as_echo "$lt_cv_ld_exported_symbols_list" >&6; } + case $host_os in + rhapsody* | darwin1.[012]) + _lt_dar_allow_undefined='${wl}-undefined ${wl}suppress' ;; + darwin1.*) + _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' ;; + darwin*) # darwin 5.x on + # if running on 10.5 or later, the deployment target defaults + # to the OS version, if on x86, and 10.4, the deployment + # target defaults to 10.4. Don't you love it? + case ${MACOSX_DEPLOYMENT_TARGET-10.0},$host in + 10.0,*86*-darwin8*|10.0,*-darwin[91]*) + _lt_dar_allow_undefined='${wl}-undefined ${wl}dynamic_lookup' ;; + 10.[012]*) + _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' ;; + 10.*) + _lt_dar_allow_undefined='${wl}-undefined ${wl}dynamic_lookup' ;; + esac + ;; + esac + if test "$lt_cv_apple_cc_single_mod" = "yes"; then + _lt_dar_single_mod='$single_module' + fi + if test "$lt_cv_ld_exported_symbols_list" = "yes"; then + _lt_dar_export_syms=' ${wl}-exported_symbols_list,$output_objdir/${libname}-symbols.expsym' + else + _lt_dar_export_syms='~$NMEDIT -s $output_objdir/${libname}-symbols.expsym ${lib}' + fi + if test "$DSYMUTIL" != ":"; then + _lt_dsymutil='~$DSYMUTIL $lib || :' + else + _lt_dsymutil= + fi + ;; + esac + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5 +$as_echo_n "checking for ANSI C header files... " >&6; } +if test "${ac_cv_header_stdc+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +#include +#include + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_header_stdc=yes +else + ac_cv_header_stdc=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + +if test $ac_cv_header_stdc = yes; then + # SunOS 4.x string.h does not declare mem*, contrary to ANSI. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "memchr" >/dev/null 2>&1; then : + +else + ac_cv_header_stdc=no +fi +rm -f conftest* + +fi + +if test $ac_cv_header_stdc = yes; then + # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "free" >/dev/null 2>&1; then : + +else + ac_cv_header_stdc=no +fi +rm -f conftest* + +fi + +if test $ac_cv_header_stdc = yes; then + # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi. + if test "$cross_compiling" = yes; then : + : +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +#if ((' ' & 0x0FF) == 0x020) +# define ISLOWER(c) ('a' <= (c) && (c) <= 'z') +# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c)) +#else +# define ISLOWER(c) \ + (('a' <= (c) && (c) <= 'i') \ + || ('j' <= (c) && (c) <= 'r') \ + || ('s' <= (c) && (c) <= 'z')) +# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c)) +#endif + +#define XOR(e, f) (((e) && !(f)) || (!(e) && (f))) +int +main () +{ + int i; + for (i = 0; i < 256; i++) + if (XOR (islower (i), ISLOWER (i)) + || toupper (i) != TOUPPER (i)) + return 2; + return 0; +} +_ACEOF +if ac_fn_c_try_run "$LINENO"; then : + +else + ac_cv_header_stdc=no +fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ + conftest.$ac_objext conftest.beam conftest.$ac_ext +fi + +fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdc" >&5 +$as_echo "$ac_cv_header_stdc" >&6; } +if test $ac_cv_header_stdc = yes; then + +$as_echo "#define STDC_HEADERS 1" >>confdefs.h + +fi + +# On IRIX 5.3, sys/types and inttypes.h are conflicting. +for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \ + inttypes.h stdint.h unistd.h +do : + as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` +ac_fn_c_check_header_compile "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default +" +eval as_val=\$$as_ac_Header + if test "x$as_val" = x""yes; then : + cat >>confdefs.h <<_ACEOF +#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 +_ACEOF + +fi + +done + + +for ac_header in dlfcn.h +do : + ac_fn_c_check_header_compile "$LINENO" "dlfcn.h" "ac_cv_header_dlfcn_h" "$ac_includes_default +" +if test "x$ac_cv_header_dlfcn_h" = x""yes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_DLFCN_H 1 +_ACEOF + +fi + +done + + + +# Set options + + + + enable_dlopen=no + + + + # Check whether --enable-shared was given. +if test "${enable_shared+set}" = set; then : + enableval=$enable_shared; p=${PACKAGE-default} + case $enableval in + yes) enable_shared=yes ;; + no) enable_shared=no ;; + *) + enable_shared=no + # Look at the argument we got. We use all the common list separators. + lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR," + for pkg in $enableval; do + IFS="$lt_save_ifs" + if test "X$pkg" = "X$p"; then + enable_shared=yes + fi + done + IFS="$lt_save_ifs" + ;; + esac +else + enable_shared=yes +fi + + + + + + + + + + # Check whether --enable-static was given. +if test "${enable_static+set}" = set; then : + enableval=$enable_static; p=${PACKAGE-default} + case $enableval in + yes) enable_static=yes ;; + no) enable_static=no ;; + *) + enable_static=no + # Look at the argument we got. We use all the common list separators. + lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR," + for pkg in $enableval; do + IFS="$lt_save_ifs" + if test "X$pkg" = "X$p"; then + enable_static=yes + fi + done + IFS="$lt_save_ifs" + ;; + esac +else + enable_static=yes +fi + + + + + + + + + + +# Check whether --with-pic was given. +if test "${with_pic+set}" = set; then : + withval=$with_pic; pic_mode="$withval" +else + pic_mode=default +fi + + +test -z "$pic_mode" && pic_mode=default + + + + + + + + # Check whether --enable-fast-install was given. +if test "${enable_fast_install+set}" = set; then : + enableval=$enable_fast_install; p=${PACKAGE-default} + case $enableval in + yes) enable_fast_install=yes ;; + no) enable_fast_install=no ;; + *) + enable_fast_install=no + # Look at the argument we got. We use all the common list separators. + lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR," + for pkg in $enableval; do + IFS="$lt_save_ifs" + if test "X$pkg" = "X$p"; then + enable_fast_install=yes + fi + done + IFS="$lt_save_ifs" + ;; + esac +else + enable_fast_install=yes +fi + + + + + + + + + + + +# This can be used to rebuild libtool when needed +LIBTOOL_DEPS="$ltmain" + +# Always use our own libtool. +LIBTOOL='$(SHELL) $(top_builddir)/libtool' + + + + + + + + + + + + + + + + + + + + + + + + + +test -z "$LN_S" && LN_S="ln -s" + + + + + + + + + + + + + + +if test -n "${ZSH_VERSION+set}" ; then + setopt NO_GLOB_SUBST +fi + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for objdir" >&5 +$as_echo_n "checking for objdir... " >&6; } +if test "${lt_cv_objdir+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + rm -f .libs 2>/dev/null +mkdir .libs 2>/dev/null +if test -d .libs; then + lt_cv_objdir=.libs +else + # MS-DOS does not allow filenames that begin with a dot. + lt_cv_objdir=_libs +fi +rmdir .libs 2>/dev/null +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_objdir" >&5 +$as_echo "$lt_cv_objdir" >&6; } +objdir=$lt_cv_objdir + + + + + +cat >>confdefs.h <<_ACEOF +#define LT_OBJDIR "$lt_cv_objdir/" +_ACEOF + + + + + + + + + + + + + + + + + +case $host_os in +aix3*) + # AIX sometimes has problems with the GCC collect2 program. For some + # reason, if we set the COLLECT_NAMES environment variable, the problems + # vanish in a puff of smoke. + if test "X${COLLECT_NAMES+set}" != Xset; then + COLLECT_NAMES= + export COLLECT_NAMES + fi + ;; +esac + +# Sed substitution that helps us do robust quoting. It backslashifies +# metacharacters that are still active within double-quoted strings. +sed_quote_subst='s/\(["`$\\]\)/\\\1/g' + +# Same as above, but do not quote variable references. +double_quote_subst='s/\(["`\\]\)/\\\1/g' + +# Sed substitution to delay expansion of an escaped shell variable in a +# double_quote_subst'ed string. +delay_variable_subst='s/\\\\\\\\\\\$/\\\\\\$/g' + +# Sed substitution to delay expansion of an escaped single quote. +delay_single_quote_subst='s/'\''/'\'\\\\\\\'\''/g' + +# Sed substitution to avoid accidental globbing in evaled expressions +no_glob_subst='s/\*/\\\*/g' + +# Global variables: +ofile=libtool +can_build_shared=yes + +# All known linkers require a `.a' archive for static linking (except MSVC, +# which needs '.lib'). +libext=a + +with_gnu_ld="$lt_cv_prog_gnu_ld" + +old_CC="$CC" +old_CFLAGS="$CFLAGS" + +# Set sane defaults for various variables +test -z "$CC" && CC=cc +test -z "$LTCC" && LTCC=$CC +test -z "$LTCFLAGS" && LTCFLAGS=$CFLAGS +test -z "$LD" && LD=ld +test -z "$ac_objext" && ac_objext=o + +for cc_temp in $compiler""; do + case $cc_temp in + compile | *[\\/]compile | ccache | *[\\/]ccache ) ;; + distcc | *[\\/]distcc | purify | *[\\/]purify ) ;; + \-*) ;; + *) break;; + esac +done +cc_basename=`$ECHO "X$cc_temp" | $Xsed -e 's%.*/%%' -e "s%^$host_alias-%%"` + + +# Only perform the check for file, if the check method requires it +test -z "$MAGIC_CMD" && MAGIC_CMD=file +case $deplibs_check_method in +file_magic*) + if test "$file_magic_cmd" = '$MAGIC_CMD'; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ${ac_tool_prefix}file" >&5 +$as_echo_n "checking for ${ac_tool_prefix}file... " >&6; } +if test "${lt_cv_path_MAGIC_CMD+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + case $MAGIC_CMD in +[\\/*] | ?:[\\/]*) + lt_cv_path_MAGIC_CMD="$MAGIC_CMD" # Let the user override the test with a path. + ;; +*) + lt_save_MAGIC_CMD="$MAGIC_CMD" + lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR + ac_dummy="/usr/bin$PATH_SEPARATOR$PATH" + for ac_dir in $ac_dummy; do + IFS="$lt_save_ifs" + test -z "$ac_dir" && ac_dir=. + if test -f $ac_dir/${ac_tool_prefix}file; then + lt_cv_path_MAGIC_CMD="$ac_dir/${ac_tool_prefix}file" + if test -n "$file_magic_test_file"; then + case $deplibs_check_method in + "file_magic "*) + file_magic_regex=`expr "$deplibs_check_method" : "file_magic \(.*\)"` + MAGIC_CMD="$lt_cv_path_MAGIC_CMD" + if eval $file_magic_cmd \$file_magic_test_file 2> /dev/null | + $EGREP "$file_magic_regex" > /dev/null; then + : + else + cat <<_LT_EOF 1>&2 + +*** Warning: the command libtool uses to detect shared libraries, +*** $file_magic_cmd, produces output that libtool cannot recognize. +*** The result is that libtool may fail to recognize shared libraries +*** as such. This will affect the creation of libtool libraries that +*** depend on shared libraries, but programs linked with such libtool +*** libraries will work regardless of this problem. Nevertheless, you +*** may want to report the problem to your system manager and/or to +*** bug-libtool@gnu.org + +_LT_EOF + fi ;; + esac + fi + break + fi + done + IFS="$lt_save_ifs" + MAGIC_CMD="$lt_save_MAGIC_CMD" + ;; +esac +fi + +MAGIC_CMD="$lt_cv_path_MAGIC_CMD" +if test -n "$MAGIC_CMD"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MAGIC_CMD" >&5 +$as_echo "$MAGIC_CMD" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + + + +if test -z "$lt_cv_path_MAGIC_CMD"; then + if test -n "$ac_tool_prefix"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for file" >&5 +$as_echo_n "checking for file... " >&6; } +if test "${lt_cv_path_MAGIC_CMD+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + case $MAGIC_CMD in +[\\/*] | ?:[\\/]*) + lt_cv_path_MAGIC_CMD="$MAGIC_CMD" # Let the user override the test with a path. + ;; +*) + lt_save_MAGIC_CMD="$MAGIC_CMD" + lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR + ac_dummy="/usr/bin$PATH_SEPARATOR$PATH" + for ac_dir in $ac_dummy; do + IFS="$lt_save_ifs" + test -z "$ac_dir" && ac_dir=. + if test -f $ac_dir/file; then + lt_cv_path_MAGIC_CMD="$ac_dir/file" + if test -n "$file_magic_test_file"; then + case $deplibs_check_method in + "file_magic "*) + file_magic_regex=`expr "$deplibs_check_method" : "file_magic \(.*\)"` + MAGIC_CMD="$lt_cv_path_MAGIC_CMD" + if eval $file_magic_cmd \$file_magic_test_file 2> /dev/null | + $EGREP "$file_magic_regex" > /dev/null; then + : + else + cat <<_LT_EOF 1>&2 + +*** Warning: the command libtool uses to detect shared libraries, +*** $file_magic_cmd, produces output that libtool cannot recognize. +*** The result is that libtool may fail to recognize shared libraries +*** as such. This will affect the creation of libtool libraries that +*** depend on shared libraries, but programs linked with such libtool +*** libraries will work regardless of this problem. Nevertheless, you +*** may want to report the problem to your system manager and/or to +*** bug-libtool@gnu.org + +_LT_EOF + fi ;; + esac + fi + break + fi + done + IFS="$lt_save_ifs" + MAGIC_CMD="$lt_save_MAGIC_CMD" + ;; +esac +fi + +MAGIC_CMD="$lt_cv_path_MAGIC_CMD" +if test -n "$MAGIC_CMD"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MAGIC_CMD" >&5 +$as_echo "$MAGIC_CMD" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + else + MAGIC_CMD=: + fi +fi + + fi + ;; +esac + +# Use C for the default configuration in the libtool script + +lt_save_CC="$CC" +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +# Source file extension for C test sources. +ac_ext=c + +# Object file extension for compiled C test sources. +objext=o +objext=$objext + +# Code to be used in simple compile tests +lt_simple_compile_test_code="int some_variable = 0;" + +# Code to be used in simple link tests +lt_simple_link_test_code='int main(){return(0);}' + + + + + + + +# If no C compiler was specified, use CC. +LTCC=${LTCC-"$CC"} + +# If no C compiler flags were specified, use CFLAGS. +LTCFLAGS=${LTCFLAGS-"$CFLAGS"} + +# Allow CC to be a program name with arguments. +compiler=$CC + +# Save the default compiler, since it gets overwritten when the other +# tags are being tested, and _LT_TAGVAR(compiler, []) is a NOP. +compiler_DEFAULT=$CC + +# save warnings/boilerplate of simple test code +ac_outfile=conftest.$ac_objext +echo "$lt_simple_compile_test_code" >conftest.$ac_ext +eval "$ac_compile" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err +_lt_compiler_boilerplate=`cat conftest.err` +$RM conftest* + +ac_outfile=conftest.$ac_objext +echo "$lt_simple_link_test_code" >conftest.$ac_ext +eval "$ac_link" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err +_lt_linker_boilerplate=`cat conftest.err` +$RM -r conftest* + + +if test -n "$compiler"; then + +lt_prog_compiler_no_builtin_flag= + +if test "$GCC" = yes; then + lt_prog_compiler_no_builtin_flag=' -fno-builtin' + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -fno-rtti -fno-exceptions" >&5 +$as_echo_n "checking if $compiler supports -fno-rtti -fno-exceptions... " >&6; } +if test "${lt_cv_prog_compiler_rtti_exceptions+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_prog_compiler_rtti_exceptions=no + ac_outfile=conftest.$ac_objext + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + lt_compiler_flag="-fno-rtti -fno-exceptions" + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + # The option is referenced via a variable to avoid confusing sed. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:7743: $lt_compile\"" >&5) + (eval "$lt_compile" 2>conftest.err) + ac_status=$? + cat conftest.err >&5 + echo "$as_me:7747: \$? = $ac_status" >&5 + if (exit $ac_status) && test -s "$ac_outfile"; then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings other than the usual output. + $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' >conftest.exp + $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 + if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then + lt_cv_prog_compiler_rtti_exceptions=yes + fi + fi + $RM conftest* + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_rtti_exceptions" >&5 +$as_echo "$lt_cv_prog_compiler_rtti_exceptions" >&6; } + +if test x"$lt_cv_prog_compiler_rtti_exceptions" = xyes; then + lt_prog_compiler_no_builtin_flag="$lt_prog_compiler_no_builtin_flag -fno-rtti -fno-exceptions" +else + : +fi + +fi + + + + + + + lt_prog_compiler_wl= +lt_prog_compiler_pic= +lt_prog_compiler_static= + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $compiler option to produce PIC" >&5 +$as_echo_n "checking for $compiler option to produce PIC... " >&6; } + + if test "$GCC" = yes; then + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_static='-static' + + case $host_os in + aix*) + # All AIX code is PIC. + if test "$host_cpu" = ia64; then + # AIX 5 now supports IA64 processor + lt_prog_compiler_static='-Bstatic' + fi + ;; + + amigaos*) + case $host_cpu in + powerpc) + # see comment about AmigaOS4 .so support + lt_prog_compiler_pic='-fPIC' + ;; + m68k) + # FIXME: we need at least 68020 code to build shared libraries, but + # adding the `-m68020' flag to GCC prevents building anything better, + # like `-m68040'. + lt_prog_compiler_pic='-m68020 -resident32 -malways-restore-a4' + ;; + esac + ;; + + beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*) + # PIC is the default for these OSes. + ;; + + mingw* | cygwin* | pw32* | os2* | cegcc*) + # This hack is so that the source file can tell whether it is being + # built for inclusion in a dll (and should export symbols for example). + # Although the cygwin gcc ignores -fPIC, still need this for old-style + # (--disable-auto-import) libraries + lt_prog_compiler_pic='-DDLL_EXPORT' + ;; + + darwin* | rhapsody*) + # PIC is the default on this platform + # Common symbols not allowed in MH_DYLIB files + lt_prog_compiler_pic='-fno-common' + ;; + + hpux*) + # PIC is the default for 64-bit PA HP-UX, but not for 32-bit + # PA HP-UX. On IA64 HP-UX, PIC is the default but the pic flag + # sets the default TLS model and affects inlining. + case $host_cpu in + hppa*64*) + # +Z the default + ;; + *) + lt_prog_compiler_pic='-fPIC' + ;; + esac + ;; + + interix[3-9]*) + # Interix 3.x gcc -fpic/-fPIC options generate broken code. + # Instead, we relocate shared libraries at runtime. + ;; + + msdosdjgpp*) + # Just because we use GCC doesn't mean we suddenly get shared libraries + # on systems that don't support them. + lt_prog_compiler_can_build_shared=no + enable_shared=no + ;; + + *nto* | *qnx*) + # QNX uses GNU C++, but need to define -shared option too, otherwise + # it will coredump. + lt_prog_compiler_pic='-fPIC -shared' + ;; + + sysv4*MP*) + if test -d /usr/nec; then + lt_prog_compiler_pic=-Kconform_pic + fi + ;; + + *) + lt_prog_compiler_pic='-fPIC' + ;; + esac + else + # PORTME Check for flag to pass linker flags through the system compiler. + case $host_os in + aix*) + lt_prog_compiler_wl='-Wl,' + if test "$host_cpu" = ia64; then + # AIX 5 now supports IA64 processor + lt_prog_compiler_static='-Bstatic' + else + lt_prog_compiler_static='-bnso -bI:/lib/syscalls.exp' + fi + ;; + + mingw* | cygwin* | pw32* | os2* | cegcc*) + # This hack is so that the source file can tell whether it is being + # built for inclusion in a dll (and should export symbols for example). + lt_prog_compiler_pic='-DDLL_EXPORT' + ;; + + hpux9* | hpux10* | hpux11*) + lt_prog_compiler_wl='-Wl,' + # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but + # not for PA HP-UX. + case $host_cpu in + hppa*64*|ia64*) + # +Z the default + ;; + *) + lt_prog_compiler_pic='+Z' + ;; + esac + # Is there a better lt_prog_compiler_static that works with the bundled CC? + lt_prog_compiler_static='${wl}-a ${wl}archive' + ;; + + irix5* | irix6* | nonstopux*) + lt_prog_compiler_wl='-Wl,' + # PIC (with -KPIC) is the default. + lt_prog_compiler_static='-non_shared' + ;; + + linux* | k*bsd*-gnu) + case $cc_basename in + # old Intel for x86_64 which still supported -KPIC. + ecc*) + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_pic='-KPIC' + lt_prog_compiler_static='-static' + ;; + # icc used to be incompatible with GCC. + # ICC 10 doesn't accept -KPIC any more. + icc* | ifort*) + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_pic='-fPIC' + lt_prog_compiler_static='-static' + ;; + # Lahey Fortran 8.1. + lf95*) + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_pic='--shared' + lt_prog_compiler_static='--static' + ;; + pgcc* | pgf77* | pgf90* | pgf95*) + # Portland Group compilers (*not* the Pentium gcc compiler, + # which looks to be a dead project) + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_pic='-fpic' + lt_prog_compiler_static='-Bstatic' + ;; + ccc*) + lt_prog_compiler_wl='-Wl,' + # All Alpha code is PIC. + lt_prog_compiler_static='-non_shared' + ;; + xl*) + # IBM XL C 8.0/Fortran 10.1 on PPC + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_pic='-qpic' + lt_prog_compiler_static='-qstaticlink' + ;; + *) + case `$CC -V 2>&1 | sed 5q` in + *Sun\ C*) + # Sun C 5.9 + lt_prog_compiler_pic='-KPIC' + lt_prog_compiler_static='-Bstatic' + lt_prog_compiler_wl='-Wl,' + ;; + *Sun\ F*) + # Sun Fortran 8.3 passes all unrecognized flags to the linker + lt_prog_compiler_pic='-KPIC' + lt_prog_compiler_static='-Bstatic' + lt_prog_compiler_wl='' + ;; + esac + ;; + esac + ;; + + newsos6) + lt_prog_compiler_pic='-KPIC' + lt_prog_compiler_static='-Bstatic' + ;; + + *nto* | *qnx*) + # QNX uses GNU C++, but need to define -shared option too, otherwise + # it will coredump. + lt_prog_compiler_pic='-fPIC -shared' + ;; + + osf3* | osf4* | osf5*) + lt_prog_compiler_wl='-Wl,' + # All OSF/1 code is PIC. + lt_prog_compiler_static='-non_shared' + ;; + + rdos*) + lt_prog_compiler_static='-non_shared' + ;; + + solaris*) + lt_prog_compiler_pic='-KPIC' + lt_prog_compiler_static='-Bstatic' + case $cc_basename in + f77* | f90* | f95*) + lt_prog_compiler_wl='-Qoption ld ';; + *) + lt_prog_compiler_wl='-Wl,';; + esac + ;; + + sunos4*) + lt_prog_compiler_wl='-Qoption ld ' + lt_prog_compiler_pic='-PIC' + lt_prog_compiler_static='-Bstatic' + ;; + + sysv4 | sysv4.2uw2* | sysv4.3*) + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_pic='-KPIC' + lt_prog_compiler_static='-Bstatic' + ;; + + sysv4*MP*) + if test -d /usr/nec ;then + lt_prog_compiler_pic='-Kconform_pic' + lt_prog_compiler_static='-Bstatic' + fi + ;; + + sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*) + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_pic='-KPIC' + lt_prog_compiler_static='-Bstatic' + ;; + + unicos*) + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_can_build_shared=no + ;; + + uts4*) + lt_prog_compiler_pic='-pic' + lt_prog_compiler_static='-Bstatic' + ;; + + *) + lt_prog_compiler_can_build_shared=no + ;; + esac + fi + +case $host_os in + # For platforms which do not support PIC, -DPIC is meaningless: + *djgpp*) + lt_prog_compiler_pic= + ;; + *) + lt_prog_compiler_pic="$lt_prog_compiler_pic -DPIC" + ;; +esac +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_prog_compiler_pic" >&5 +$as_echo "$lt_prog_compiler_pic" >&6; } + + + + + + +# +# Check to make sure the PIC flag actually works. +# +if test -n "$lt_prog_compiler_pic"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler PIC flag $lt_prog_compiler_pic works" >&5 +$as_echo_n "checking if $compiler PIC flag $lt_prog_compiler_pic works... " >&6; } +if test "${lt_cv_prog_compiler_pic_works+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_prog_compiler_pic_works=no + ac_outfile=conftest.$ac_objext + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + lt_compiler_flag="$lt_prog_compiler_pic -DPIC" + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + # The option is referenced via a variable to avoid confusing sed. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:8082: $lt_compile\"" >&5) + (eval "$lt_compile" 2>conftest.err) + ac_status=$? + cat conftest.err >&5 + echo "$as_me:8086: \$? = $ac_status" >&5 + if (exit $ac_status) && test -s "$ac_outfile"; then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings other than the usual output. + $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' >conftest.exp + $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 + if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then + lt_cv_prog_compiler_pic_works=yes + fi + fi + $RM conftest* + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_pic_works" >&5 +$as_echo "$lt_cv_prog_compiler_pic_works" >&6; } + +if test x"$lt_cv_prog_compiler_pic_works" = xyes; then + case $lt_prog_compiler_pic in + "" | " "*) ;; + *) lt_prog_compiler_pic=" $lt_prog_compiler_pic" ;; + esac +else + lt_prog_compiler_pic= + lt_prog_compiler_can_build_shared=no +fi + +fi + + + + + + +# +# Check to make sure the static flag actually works. +# +wl=$lt_prog_compiler_wl eval lt_tmp_static_flag=\"$lt_prog_compiler_static\" +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler static flag $lt_tmp_static_flag works" >&5 +$as_echo_n "checking if $compiler static flag $lt_tmp_static_flag works... " >&6; } +if test "${lt_cv_prog_compiler_static_works+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_prog_compiler_static_works=no + save_LDFLAGS="$LDFLAGS" + LDFLAGS="$LDFLAGS $lt_tmp_static_flag" + echo "$lt_simple_link_test_code" > conftest.$ac_ext + if (eval $ac_link 2>conftest.err) && test -s conftest$ac_exeext; then + # The linker can only warn and ignore the option if not recognized + # So say no if there are warnings + if test -s conftest.err; then + # Append any errors to the config.log. + cat conftest.err 1>&5 + $ECHO "X$_lt_linker_boilerplate" | $Xsed -e '/^$/d' > conftest.exp + $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 + if diff conftest.exp conftest.er2 >/dev/null; then + lt_cv_prog_compiler_static_works=yes + fi + else + lt_cv_prog_compiler_static_works=yes + fi + fi + $RM -r conftest* + LDFLAGS="$save_LDFLAGS" + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_static_works" >&5 +$as_echo "$lt_cv_prog_compiler_static_works" >&6; } + +if test x"$lt_cv_prog_compiler_static_works" = xyes; then + : +else + lt_prog_compiler_static= +fi + + + + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -c -o file.$ac_objext" >&5 +$as_echo_n "checking if $compiler supports -c -o file.$ac_objext... " >&6; } +if test "${lt_cv_prog_compiler_c_o+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_prog_compiler_c_o=no + $RM -r conftest 2>/dev/null + mkdir conftest + cd conftest + mkdir out + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + + lt_compiler_flag="-o out/conftest2.$ac_objext" + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:8187: $lt_compile\"" >&5) + (eval "$lt_compile" 2>out/conftest.err) + ac_status=$? + cat out/conftest.err >&5 + echo "$as_me:8191: \$? = $ac_status" >&5 + if (exit $ac_status) && test -s out/conftest2.$ac_objext + then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings + $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' > out/conftest.exp + $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2 + if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then + lt_cv_prog_compiler_c_o=yes + fi + fi + chmod u+w . 2>&5 + $RM conftest* + # SGI C++ compiler will create directory out/ii_files/ for + # template instantiation + test -d out/ii_files && $RM out/ii_files/* && rmdir out/ii_files + $RM out/* && rmdir out + cd .. + $RM -r conftest + $RM conftest* + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_c_o" >&5 +$as_echo "$lt_cv_prog_compiler_c_o" >&6; } + + + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -c -o file.$ac_objext" >&5 +$as_echo_n "checking if $compiler supports -c -o file.$ac_objext... " >&6; } +if test "${lt_cv_prog_compiler_c_o+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_prog_compiler_c_o=no + $RM -r conftest 2>/dev/null + mkdir conftest + cd conftest + mkdir out + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + + lt_compiler_flag="-o out/conftest2.$ac_objext" + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:8242: $lt_compile\"" >&5) + (eval "$lt_compile" 2>out/conftest.err) + ac_status=$? + cat out/conftest.err >&5 + echo "$as_me:8246: \$? = $ac_status" >&5 + if (exit $ac_status) && test -s out/conftest2.$ac_objext + then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings + $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' > out/conftest.exp + $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2 + if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then + lt_cv_prog_compiler_c_o=yes + fi + fi + chmod u+w . 2>&5 + $RM conftest* + # SGI C++ compiler will create directory out/ii_files/ for + # template instantiation + test -d out/ii_files && $RM out/ii_files/* && rmdir out/ii_files + $RM out/* && rmdir out + cd .. + $RM -r conftest + $RM conftest* + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_c_o" >&5 +$as_echo "$lt_cv_prog_compiler_c_o" >&6; } + + + + +hard_links="nottested" +if test "$lt_cv_prog_compiler_c_o" = no && test "$need_locks" != no; then + # do not overwrite the value of need_locks provided by the user + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if we can lock with hard links" >&5 +$as_echo_n "checking if we can lock with hard links... " >&6; } + hard_links=yes + $RM conftest* + ln conftest.a conftest.b 2>/dev/null && hard_links=no + touch conftest.a + ln conftest.a conftest.b 2>&5 || hard_links=no + ln conftest.a conftest.b 2>/dev/null && hard_links=no + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $hard_links" >&5 +$as_echo "$hard_links" >&6; } + if test "$hard_links" = no; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: \`$CC' does not support \`-c -o', so \`make -j' may be unsafe" >&5 +$as_echo "$as_me: WARNING: \`$CC' does not support \`-c -o', so \`make -j' may be unsafe" >&2;} + need_locks=warn + fi +else + need_locks=no +fi + + + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the $compiler linker ($LD) supports shared libraries" >&5 +$as_echo_n "checking whether the $compiler linker ($LD) supports shared libraries... " >&6; } + + runpath_var= + allow_undefined_flag= + always_export_symbols=no + archive_cmds= + archive_expsym_cmds= + compiler_needs_object=no + enable_shared_with_static_runtimes=no + export_dynamic_flag_spec= + export_symbols_cmds='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' + hardcode_automatic=no + hardcode_direct=no + hardcode_direct_absolute=no + hardcode_libdir_flag_spec= + hardcode_libdir_flag_spec_ld= + hardcode_libdir_separator= + hardcode_minus_L=no + hardcode_shlibpath_var=unsupported + inherit_rpath=no + link_all_deplibs=unknown + module_cmds= + module_expsym_cmds= + old_archive_from_new_cmds= + old_archive_from_expsyms_cmds= + thread_safe_flag_spec= + whole_archive_flag_spec= + # include_expsyms should be a list of space-separated symbols to be *always* + # included in the symbol list + include_expsyms= + # exclude_expsyms can be an extended regexp of symbols to exclude + # it will be wrapped by ` (' and `)$', so one must not match beginning or + # end of line. Example: `a|bc|.*d.*' will exclude the symbols `a' and `bc', + # as well as any symbol that contains `d'. + exclude_expsyms='_GLOBAL_OFFSET_TABLE_|_GLOBAL__F[ID]_.*' + # Although _GLOBAL_OFFSET_TABLE_ is a valid symbol C name, most a.out + # platforms (ab)use it in PIC code, but their linkers get confused if + # the symbol is explicitly referenced. Since portable code cannot + # rely on this symbol name, it's probably fine to never include it in + # preloaded symbol tables. + # Exclude shared library initialization/finalization symbols. + extract_expsyms_cmds= + + case $host_os in + cygwin* | mingw* | pw32* | cegcc*) + # FIXME: the MSVC++ port hasn't been tested in a loooong time + # When not using gcc, we currently assume that we are using + # Microsoft Visual C++. + if test "$GCC" != yes; then + with_gnu_ld=no + fi + ;; + interix*) + # we just hope/assume this is gcc and not c89 (= MSVC++) + with_gnu_ld=yes + ;; + openbsd*) + with_gnu_ld=no + ;; + esac + + ld_shlibs=yes + if test "$with_gnu_ld" = yes; then + # If archive_cmds runs LD, not CC, wlarc should be empty + wlarc='${wl}' + + # Set some defaults for GNU ld with shared library support. These + # are reset later if shared libraries are not supported. Putting them + # here allows them to be overridden if necessary. + runpath_var=LD_RUN_PATH + hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' + export_dynamic_flag_spec='${wl}--export-dynamic' + # ancient GNU ld didn't support --whole-archive et. al. + if $LD --help 2>&1 | $GREP 'no-whole-archive' > /dev/null; then + whole_archive_flag_spec="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive' + else + whole_archive_flag_spec= + fi + supports_anon_versioning=no + case `$LD -v 2>&1` in + *\ [01].* | *\ 2.[0-9].* | *\ 2.10.*) ;; # catch versions < 2.11 + *\ 2.11.93.0.2\ *) supports_anon_versioning=yes ;; # RH7.3 ... + *\ 2.11.92.0.12\ *) supports_anon_versioning=yes ;; # Mandrake 8.2 ... + *\ 2.11.*) ;; # other 2.11 versions + *) supports_anon_versioning=yes ;; + esac + + # See if GNU ld supports shared libraries. + case $host_os in + aix[3-9]*) + # On AIX/PPC, the GNU linker is very broken + if test "$host_cpu" != ia64; then + ld_shlibs=no + cat <<_LT_EOF 1>&2 + +*** Warning: the GNU linker, at least up to release 2.9.1, is reported +*** to be unable to reliably create shared libraries on AIX. +*** Therefore, libtool is disabling shared libraries support. If you +*** really care for shared libraries, you may want to modify your PATH +*** so that a non-GNU linker is found, and then restart. + +_LT_EOF + fi + ;; + + amigaos*) + case $host_cpu in + powerpc) + # see comment about AmigaOS4 .so support + archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + archive_expsym_cmds='' + ;; + m68k) + archive_cmds='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)' + hardcode_libdir_flag_spec='-L$libdir' + hardcode_minus_L=yes + ;; + esac + ;; + + beos*) + if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + allow_undefined_flag=unsupported + # Joseph Beckenbach says some releases of gcc + # support --undefined. This deserves some investigation. FIXME + archive_cmds='$CC -nostart $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + else + ld_shlibs=no + fi + ;; + + cygwin* | mingw* | pw32* | cegcc*) + # _LT_TAGVAR(hardcode_libdir_flag_spec, ) is actually meaningless, + # as there is no search path for DLLs. + hardcode_libdir_flag_spec='-L$libdir' + allow_undefined_flag=unsupported + always_export_symbols=no + enable_shared_with_static_runtimes=yes + export_symbols_cmds='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[BCDGRS][ ]/s/.*[ ]\([^ ]*\)/\1 DATA/'\'' | $SED -e '\''/^[AITW][ ]/s/.*[ ]//'\'' | sort | uniq > $export_symbols' + + if $LD --help 2>&1 | $GREP 'auto-import' > /dev/null; then + archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + # If the export-symbols file already is a .def file (1st line + # is EXPORTS), use it as is; otherwise, prepend... + archive_expsym_cmds='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then + cp $export_symbols $output_objdir/$soname.def; + else + echo EXPORTS > $output_objdir/$soname.def; + cat $export_symbols >> $output_objdir/$soname.def; + fi~ + $CC -shared $output_objdir/$soname.def $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + else + ld_shlibs=no + fi + ;; + + interix[3-9]*) + hardcode_direct=no + hardcode_shlibpath_var=no + hardcode_libdir_flag_spec='${wl}-rpath,$libdir' + export_dynamic_flag_spec='${wl}-E' + # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc. + # Instead, shared libraries are loaded at an image base (0x10000000 by + # default) and relocated if they conflict, which is a slow very memory + # consuming and fragmenting process. To avoid this, we pick a random, + # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link + # time. Moving up from 0x10000000 also allows more sbrk(2) space. + archive_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + archive_expsym_cmds='sed "s,^,_," $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--retain-symbols-file,$output_objdir/$soname.expsym ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + ;; + + gnu* | linux* | tpf* | k*bsd*-gnu) + tmp_diet=no + if test "$host_os" = linux-dietlibc; then + case $cc_basename in + diet\ *) tmp_diet=yes;; # linux-dietlibc with static linking (!diet-dyn) + esac + fi + if $LD --help 2>&1 | $EGREP ': supported targets:.* elf' > /dev/null \ + && test "$tmp_diet" = no + then + tmp_addflag= + tmp_sharedflag='-shared' + case $cc_basename,$host_cpu in + pgcc*) # Portland Group C compiler + whole_archive_flag_spec='${wl}--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive' + tmp_addflag=' $pic_flag' + ;; + pgf77* | pgf90* | pgf95*) # Portland Group f77 and f90 compilers + whole_archive_flag_spec='${wl}--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive' + tmp_addflag=' $pic_flag -Mnomain' ;; + ecc*,ia64* | icc*,ia64*) # Intel C compiler on ia64 + tmp_addflag=' -i_dynamic' ;; + efc*,ia64* | ifort*,ia64*) # Intel Fortran compiler on ia64 + tmp_addflag=' -i_dynamic -nofor_main' ;; + ifc* | ifort*) # Intel Fortran compiler + tmp_addflag=' -nofor_main' ;; + lf95*) # Lahey Fortran 8.1 + whole_archive_flag_spec= + tmp_sharedflag='--shared' ;; + xl[cC]*) # IBM XL C 8.0 on PPC (deal with xlf below) + tmp_sharedflag='-qmkshrobj' + tmp_addflag= ;; + esac + case `$CC -V 2>&1 | sed 5q` in + *Sun\ C*) # Sun C 5.9 + whole_archive_flag_spec='${wl}--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive' + compiler_needs_object=yes + tmp_sharedflag='-G' ;; + *Sun\ F*) # Sun Fortran 8.3 + tmp_sharedflag='-G' ;; + esac + archive_cmds='$CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + + if test "x$supports_anon_versioning" = xyes; then + archive_expsym_cmds='echo "{ global:" > $output_objdir/$libname.ver~ + cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ + echo "local: *; };" >> $output_objdir/$libname.ver~ + $CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-version-script ${wl}$output_objdir/$libname.ver -o $lib' + fi + + case $cc_basename in + xlf*) + # IBM XL Fortran 10.1 on PPC cannot create shared libs itself + whole_archive_flag_spec='--whole-archive$convenience --no-whole-archive' + hardcode_libdir_flag_spec= + hardcode_libdir_flag_spec_ld='-rpath $libdir' + archive_cmds='$LD -shared $libobjs $deplibs $compiler_flags -soname $soname -o $lib' + if test "x$supports_anon_versioning" = xyes; then + archive_expsym_cmds='echo "{ global:" > $output_objdir/$libname.ver~ + cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ + echo "local: *; };" >> $output_objdir/$libname.ver~ + $LD -shared $libobjs $deplibs $compiler_flags -soname $soname -version-script $output_objdir/$libname.ver -o $lib' + fi + ;; + esac + else + ld_shlibs=no + fi + ;; + + netbsd*) + if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then + archive_cmds='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib' + wlarc= + else + archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + fi + ;; + + solaris*) + if $LD -v 2>&1 | $GREP 'BFD 2\.8' > /dev/null; then + ld_shlibs=no + cat <<_LT_EOF 1>&2 + +*** Warning: The releases 2.8.* of the GNU linker cannot reliably +*** create shared libraries on Solaris systems. Therefore, libtool +*** is disabling shared libraries support. We urge you to upgrade GNU +*** binutils to release 2.9.1 or newer. Another option is to modify +*** your PATH or compiler configuration so that the native linker is +*** used, and then restart. + +_LT_EOF + elif $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + else + ld_shlibs=no + fi + ;; + + sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX*) + case `$LD -v 2>&1` in + *\ [01].* | *\ 2.[0-9].* | *\ 2.1[0-5].*) + ld_shlibs=no + cat <<_LT_EOF 1>&2 + +*** Warning: Releases of the GNU linker prior to 2.16.91.0.3 can not +*** reliably create shared libraries on SCO systems. Therefore, libtool +*** is disabling shared libraries support. We urge you to upgrade GNU +*** binutils to release 2.16.91.0.3 or newer. Another option is to modify +*** your PATH or compiler configuration so that the native linker is +*** used, and then restart. + +_LT_EOF + ;; + *) + # For security reasons, it is highly recommended that you always + # use absolute paths for naming shared libraries, and exclude the + # DT_RUNPATH tag from executables and libraries. But doing so + # requires that you compile everything twice, which is a pain. + if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' + archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + else + ld_shlibs=no + fi + ;; + esac + ;; + + sunos4*) + archive_cmds='$LD -assert pure-text -Bshareable -o $lib $libobjs $deplibs $linker_flags' + wlarc= + hardcode_direct=yes + hardcode_shlibpath_var=no + ;; + + *) + if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + else + ld_shlibs=no + fi + ;; + esac + + if test "$ld_shlibs" = no; then + runpath_var= + hardcode_libdir_flag_spec= + export_dynamic_flag_spec= + whole_archive_flag_spec= + fi + else + # PORTME fill in a description of your system's linker (not GNU ld) + case $host_os in + aix3*) + allow_undefined_flag=unsupported + always_export_symbols=yes + archive_expsym_cmds='$LD -o $output_objdir/$soname $libobjs $deplibs $linker_flags -bE:$export_symbols -T512 -H512 -bM:SRE~$AR $AR_FLAGS $lib $output_objdir/$soname' + # Note: this linker hardcodes the directories in LIBPATH if there + # are no directories specified by -L. + hardcode_minus_L=yes + if test "$GCC" = yes && test -z "$lt_prog_compiler_static"; then + # Neither direct hardcoding nor static linking is supported with a + # broken collect2. + hardcode_direct=unsupported + fi + ;; + + aix[4-9]*) + if test "$host_cpu" = ia64; then + # On IA64, the linker does run time linking by default, so we don't + # have to do anything special. + aix_use_runtimelinking=no + exp_sym_flag='-Bexport' + no_entry_flag="" + else + # If we're using GNU nm, then we don't want the "-C" option. + # -C means demangle to AIX nm, but means don't demangle with GNU nm + if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then + export_symbols_cmds='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && (substr(\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols' + else + export_symbols_cmds='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && (substr(\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols' + fi + aix_use_runtimelinking=no + + # Test if we are trying to use run time linking or normal + # AIX style linking. If -brtl is somewhere in LDFLAGS, we + # need to do runtime linking. + case $host_os in aix4.[23]|aix4.[23].*|aix[5-9]*) + for ld_flag in $LDFLAGS; do + if (test $ld_flag = "-brtl" || test $ld_flag = "-Wl,-brtl"); then + aix_use_runtimelinking=yes + break + fi + done + ;; + esac + + exp_sym_flag='-bexport' + no_entry_flag='-bnoentry' + fi + + # When large executables or shared objects are built, AIX ld can + # have problems creating the table of contents. If linking a library + # or program results in "error TOC overflow" add -mminimal-toc to + # CXXFLAGS/CFLAGS for g++/gcc. In the cases where that is not + # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS. + + archive_cmds='' + hardcode_direct=yes + hardcode_direct_absolute=yes + hardcode_libdir_separator=':' + link_all_deplibs=yes + file_list_spec='${wl}-f,' + + if test "$GCC" = yes; then + case $host_os in aix4.[012]|aix4.[012].*) + # We only want to do this on AIX 4.2 and lower, the check + # below for broken collect2 doesn't work under 4.3+ + collect2name=`${CC} -print-prog-name=collect2` + if test -f "$collect2name" && + strings "$collect2name" | $GREP resolve_lib_name >/dev/null + then + # We have reworked collect2 + : + else + # We have old collect2 + hardcode_direct=unsupported + # It fails to find uninstalled libraries when the uninstalled + # path is not listed in the libpath. Setting hardcode_minus_L + # to unsupported forces relinking + hardcode_minus_L=yes + hardcode_libdir_flag_spec='-L$libdir' + hardcode_libdir_separator= + fi + ;; + esac + shared_flag='-shared' + if test "$aix_use_runtimelinking" = yes; then + shared_flag="$shared_flag "'${wl}-G' + fi + else + # not using gcc + if test "$host_cpu" = ia64; then + # VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release + # chokes on -Wl,-G. The following line is correct: + shared_flag='-G' + else + if test "$aix_use_runtimelinking" = yes; then + shared_flag='${wl}-G' + else + shared_flag='${wl}-bM:SRE' + fi + fi + fi + + export_dynamic_flag_spec='${wl}-bexpall' + # It seems that -bexpall does not export symbols beginning with + # underscore (_), so it is better to generate a list of symbols to export. + always_export_symbols=yes + if test "$aix_use_runtimelinking" = yes; then + # Warning - without using the other runtime loading flags (-brtl), + # -berok will link without error, but may produce a broken library. + allow_undefined_flag='-berok' + # Determine the default libpath from the value encoded in an + # empty executable. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + +lt_aix_libpath_sed=' + /Import File Strings/,/^$/ { + /^0/ { + s/^0 *\(.*\)$/\1/ + p + } + }' +aix_libpath=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` +# Check for a 64-bit object if we didn't find anything. +if test -z "$aix_libpath"; then + aix_libpath=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` +fi +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + + hardcode_libdir_flag_spec='${wl}-blibpath:$libdir:'"$aix_libpath" + archive_expsym_cmds='$CC -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags `if test "x${allow_undefined_flag}" != "x"; then $ECHO "X${wl}${allow_undefined_flag}" | $Xsed; else :; fi` '"\${wl}$exp_sym_flag:\$export_symbols $shared_flag" + else + if test "$host_cpu" = ia64; then + hardcode_libdir_flag_spec='${wl}-R $libdir:/usr/lib:/lib' + allow_undefined_flag="-z nodefs" + archive_expsym_cmds="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags ${wl}${allow_undefined_flag} '"\${wl}$exp_sym_flag:\$export_symbols" + else + # Determine the default libpath from the value encoded in an + # empty executable. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + +lt_aix_libpath_sed=' + /Import File Strings/,/^$/ { + /^0/ { + s/^0 *\(.*\)$/\1/ + p + } + }' +aix_libpath=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` +# Check for a 64-bit object if we didn't find anything. +if test -z "$aix_libpath"; then + aix_libpath=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` +fi +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi + + hardcode_libdir_flag_spec='${wl}-blibpath:$libdir:'"$aix_libpath" + # Warning - without using the other run time loading flags, + # -berok will link without error, but may produce a broken library. + no_undefined_flag=' ${wl}-bernotok' + allow_undefined_flag=' ${wl}-berok' + # Exported symbols can be pulled into shared objects from archives + whole_archive_flag_spec='$convenience' + archive_cmds_need_lc=yes + # This is similar to how AIX traditionally builds its shared libraries. + archive_expsym_cmds="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs ${wl}-bnoentry $compiler_flags ${wl}-bE:$export_symbols${allow_undefined_flag}~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$soname' + fi + fi + ;; + + amigaos*) + case $host_cpu in + powerpc) + # see comment about AmigaOS4 .so support + archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + archive_expsym_cmds='' + ;; + m68k) + archive_cmds='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)' + hardcode_libdir_flag_spec='-L$libdir' + hardcode_minus_L=yes + ;; + esac + ;; + + bsdi[45]*) + export_dynamic_flag_spec=-rdynamic + ;; + + cygwin* | mingw* | pw32* | cegcc*) + # When not using gcc, we currently assume that we are using + # Microsoft Visual C++. + # hardcode_libdir_flag_spec is actually meaningless, as there is + # no search path for DLLs. + hardcode_libdir_flag_spec=' ' + allow_undefined_flag=unsupported + # Tell ltmain to make .lib files, not .a files. + libext=lib + # Tell ltmain to make .dll files, not .so files. + shrext_cmds=".dll" + # FIXME: Setting linknames here is a bad hack. + archive_cmds='$CC -o $lib $libobjs $compiler_flags `$ECHO "X$deplibs" | $Xsed -e '\''s/ -lc$//'\''` -link -dll~linknames=' + # The linker will automatically build a .lib file if we build a DLL. + old_archive_from_new_cmds='true' + # FIXME: Should let the user specify the lib program. + old_archive_cmds='lib -OUT:$oldlib$oldobjs$old_deplibs' + fix_srcfile_path='`cygpath -w "$srcfile"`' + enable_shared_with_static_runtimes=yes + ;; + + darwin* | rhapsody*) + + + archive_cmds_need_lc=no + hardcode_direct=no + hardcode_automatic=yes + hardcode_shlibpath_var=unsupported + whole_archive_flag_spec='' + link_all_deplibs=yes + allow_undefined_flag="$_lt_dar_allow_undefined" + case $cc_basename in + ifort*) _lt_dar_can_shared=yes ;; + *) _lt_dar_can_shared=$GCC ;; + esac + if test "$_lt_dar_can_shared" = "yes"; then + output_verbose_link_cmd=echo + archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" + module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" + archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" + module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" + + else + ld_shlibs=no + fi + + ;; + + dgux*) + archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_libdir_flag_spec='-L$libdir' + hardcode_shlibpath_var=no + ;; + + freebsd1*) + ld_shlibs=no + ;; + + # FreeBSD 2.2.[012] allows us to include c++rt0.o to get C++ constructor + # support. Future versions do this automatically, but an explicit c++rt0.o + # does not break anything, and helps significantly (at the cost of a little + # extra space). + freebsd2.2*) + archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags /usr/lib/c++rt0.o' + hardcode_libdir_flag_spec='-R$libdir' + hardcode_direct=yes + hardcode_shlibpath_var=no + ;; + + # Unfortunately, older versions of FreeBSD 2 do not have this feature. + freebsd2*) + archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' + hardcode_direct=yes + hardcode_minus_L=yes + hardcode_shlibpath_var=no + ;; + + # FreeBSD 3 and greater uses gcc -shared to do shared libraries. + freebsd* | dragonfly*) + archive_cmds='$CC -shared -o $lib $libobjs $deplibs $compiler_flags' + hardcode_libdir_flag_spec='-R$libdir' + hardcode_direct=yes + hardcode_shlibpath_var=no + ;; + + hpux9*) + if test "$GCC" = yes; then + archive_cmds='$RM $output_objdir/$soname~$CC -shared -fPIC ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $libobjs $deplibs $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib' + else + archive_cmds='$RM $output_objdir/$soname~$LD -b +b $install_libdir -o $output_objdir/$soname $libobjs $deplibs $linker_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib' + fi + hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir' + hardcode_libdir_separator=: + hardcode_direct=yes + + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + hardcode_minus_L=yes + export_dynamic_flag_spec='${wl}-E' + ;; + + hpux10*) + if test "$GCC" = yes -a "$with_gnu_ld" = no; then + archive_cmds='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags' + else + archive_cmds='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags' + fi + if test "$with_gnu_ld" = no; then + hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir' + hardcode_libdir_flag_spec_ld='+b $libdir' + hardcode_libdir_separator=: + hardcode_direct=yes + hardcode_direct_absolute=yes + export_dynamic_flag_spec='${wl}-E' + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + hardcode_minus_L=yes + fi + ;; + + hpux11*) + if test "$GCC" = yes -a "$with_gnu_ld" = no; then + case $host_cpu in + hppa*64*) + archive_cmds='$CC -shared ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + ia64*) + archive_cmds='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags' + ;; + *) + archive_cmds='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + else + case $host_cpu in + hppa*64*) + archive_cmds='$CC -b ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + ia64*) + archive_cmds='$CC -b ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags' + ;; + *) + archive_cmds='$CC -b ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + fi + if test "$with_gnu_ld" = no; then + hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir' + hardcode_libdir_separator=: + + case $host_cpu in + hppa*64*|ia64*) + hardcode_direct=no + hardcode_shlibpath_var=no + ;; + *) + hardcode_direct=yes + hardcode_direct_absolute=yes + export_dynamic_flag_spec='${wl}-E' + + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + hardcode_minus_L=yes + ;; + esac + fi + ;; + + irix5* | irix6* | nonstopux*) + if test "$GCC" = yes; then + archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' + # Try to use the -exported_symbol ld option, if it does not + # work, assume that -exports_file does not work either and + # implicitly export all symbols. + save_LDFLAGS="$LDFLAGS" + LDFLAGS="$LDFLAGS -shared ${wl}-exported_symbol ${wl}foo ${wl}-update_registry ${wl}/dev/null" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +int foo(void) {} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations ${wl}-exports_file ${wl}$export_symbols -o $lib' + +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + LDFLAGS="$save_LDFLAGS" + else + archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib' + archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -exports_file $export_symbols -o $lib' + fi + archive_cmds_need_lc='no' + hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' + hardcode_libdir_separator=: + inherit_rpath=yes + link_all_deplibs=yes + ;; + + netbsd*) + if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then + archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' # a.out + else + archive_cmds='$LD -shared -o $lib $libobjs $deplibs $linker_flags' # ELF + fi + hardcode_libdir_flag_spec='-R$libdir' + hardcode_direct=yes + hardcode_shlibpath_var=no + ;; + + newsos6) + archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_direct=yes + hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' + hardcode_libdir_separator=: + hardcode_shlibpath_var=no + ;; + + *nto* | *qnx*) + ;; + + openbsd*) + if test -f /usr/libexec/ld.so; then + hardcode_direct=yes + hardcode_shlibpath_var=no + hardcode_direct_absolute=yes + if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then + archive_cmds='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-retain-symbols-file,$export_symbols' + hardcode_libdir_flag_spec='${wl}-rpath,$libdir' + export_dynamic_flag_spec='${wl}-E' + else + case $host_os in + openbsd[01].* | openbsd2.[0-7] | openbsd2.[0-7].*) + archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' + hardcode_libdir_flag_spec='-R$libdir' + ;; + *) + archive_cmds='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' + hardcode_libdir_flag_spec='${wl}-rpath,$libdir' + ;; + esac + fi + else + ld_shlibs=no + fi + ;; + + os2*) + hardcode_libdir_flag_spec='-L$libdir' + hardcode_minus_L=yes + allow_undefined_flag=unsupported + archive_cmds='$ECHO "LIBRARY $libname INITINSTANCE" > $output_objdir/$libname.def~$ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~$ECHO DATA >> $output_objdir/$libname.def~$ECHO " SINGLE NONSHARED" >> $output_objdir/$libname.def~$ECHO EXPORTS >> $output_objdir/$libname.def~emxexp $libobjs >> $output_objdir/$libname.def~$CC -Zdll -Zcrtdll -o $lib $libobjs $deplibs $compiler_flags $output_objdir/$libname.def' + old_archive_from_new_cmds='emximp -o $output_objdir/$libname.a $output_objdir/$libname.def' + ;; + + osf3*) + if test "$GCC" = yes; then + allow_undefined_flag=' ${wl}-expect_unresolved ${wl}\*' + archive_cmds='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' + else + allow_undefined_flag=' -expect_unresolved \*' + archive_cmds='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib' + fi + archive_cmds_need_lc='no' + hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' + hardcode_libdir_separator=: + ;; + + osf4* | osf5*) # as osf3* with the addition of -msym flag + if test "$GCC" = yes; then + allow_undefined_flag=' ${wl}-expect_unresolved ${wl}\*' + archive_cmds='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-msym ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' + hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' + else + allow_undefined_flag=' -expect_unresolved \*' + archive_cmds='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags -msym -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib' + archive_expsym_cmds='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done; printf "%s\\n" "-hidden">> $lib.exp~ + $CC -shared${allow_undefined_flag} ${wl}-input ${wl}$lib.exp $compiler_flags $libobjs $deplibs -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib~$RM $lib.exp' + + # Both c and cxx compiler support -rpath directly + hardcode_libdir_flag_spec='-rpath $libdir' + fi + archive_cmds_need_lc='no' + hardcode_libdir_separator=: + ;; + + solaris*) + no_undefined_flag=' -z defs' + if test "$GCC" = yes; then + wlarc='${wl}' + archive_cmds='$CC -shared ${wl}-z ${wl}text ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $CC -shared ${wl}-z ${wl}text ${wl}-M ${wl}$lib.exp ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp' + else + case `$CC -V 2>&1` in + *"Compilers 5.0"*) + wlarc='' + archive_cmds='$LD -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $linker_flags' + archive_expsym_cmds='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $LD -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $linker_flags~$RM $lib.exp' + ;; + *) + wlarc='${wl}' + archive_cmds='$CC -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $CC -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp' + ;; + esac + fi + hardcode_libdir_flag_spec='-R$libdir' + hardcode_shlibpath_var=no + case $host_os in + solaris2.[0-5] | solaris2.[0-5].*) ;; + *) + # The compiler driver will combine and reorder linker options, + # but understands `-z linker_flag'. GCC discards it without `$wl', + # but is careful enough not to reorder. + # Supported since Solaris 2.6 (maybe 2.5.1?) + if test "$GCC" = yes; then + whole_archive_flag_spec='${wl}-z ${wl}allextract$convenience ${wl}-z ${wl}defaultextract' + else + whole_archive_flag_spec='-z allextract$convenience -z defaultextract' + fi + ;; + esac + link_all_deplibs=yes + ;; + + sunos4*) + if test "x$host_vendor" = xsequent; then + # Use $CC to link under sequent, because it throws in some extra .o + # files that make .init and .fini sections work. + archive_cmds='$CC -G ${wl}-h $soname -o $lib $libobjs $deplibs $compiler_flags' + else + archive_cmds='$LD -assert pure-text -Bstatic -o $lib $libobjs $deplibs $linker_flags' + fi + hardcode_libdir_flag_spec='-L$libdir' + hardcode_direct=yes + hardcode_minus_L=yes + hardcode_shlibpath_var=no + ;; + + sysv4) + case $host_vendor in + sni) + archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_direct=yes # is this really true??? + ;; + siemens) + ## LD is ld it makes a PLAMLIB + ## CC just makes a GrossModule. + archive_cmds='$LD -G -o $lib $libobjs $deplibs $linker_flags' + reload_cmds='$CC -r -o $output$reload_objs' + hardcode_direct=no + ;; + motorola) + archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_direct=no #Motorola manual says yes, but my tests say they lie + ;; + esac + runpath_var='LD_RUN_PATH' + hardcode_shlibpath_var=no + ;; + + sysv4.3*) + archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_shlibpath_var=no + export_dynamic_flag_spec='-Bexport' + ;; + + sysv4*MP*) + if test -d /usr/nec; then + archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_shlibpath_var=no + runpath_var=LD_RUN_PATH + hardcode_runpath_var=yes + ld_shlibs=yes + fi + ;; + + sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[01].[10]* | unixware7* | sco3.2v5.0.[024]*) + no_undefined_flag='${wl}-z,text' + archive_cmds_need_lc=no + hardcode_shlibpath_var=no + runpath_var='LD_RUN_PATH' + + if test "$GCC" = yes; then + archive_cmds='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + else + archive_cmds='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + fi + ;; + + sysv5* | sco3.2v5* | sco5v6*) + # Note: We can NOT use -z defs as we might desire, because we do not + # link with -lc, and that would cause any symbols used from libc to + # always be unresolved, which means just about no library would + # ever link correctly. If we're not using GNU ld we use -z text + # though, which does catch some bad symbols but isn't as heavy-handed + # as -z defs. + no_undefined_flag='${wl}-z,text' + allow_undefined_flag='${wl}-z,nodefs' + archive_cmds_need_lc=no + hardcode_shlibpath_var=no + hardcode_libdir_flag_spec='${wl}-R,$libdir' + hardcode_libdir_separator=':' + link_all_deplibs=yes + export_dynamic_flag_spec='${wl}-Bexport' + runpath_var='LD_RUN_PATH' + + if test "$GCC" = yes; then + archive_cmds='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + else + archive_cmds='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + fi + ;; + + uts4*) + archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_libdir_flag_spec='-L$libdir' + hardcode_shlibpath_var=no + ;; + + *) + ld_shlibs=no + ;; + esac + + if test x$host_vendor = xsni; then + case $host in + sysv4 | sysv4.2uw2* | sysv4.3* | sysv5*) + export_dynamic_flag_spec='${wl}-Blargedynsym' + ;; + esac + fi + fi + +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ld_shlibs" >&5 +$as_echo "$ld_shlibs" >&6; } +test "$ld_shlibs" = no && can_build_shared=no + +with_gnu_ld=$with_gnu_ld + + + + + + + + + + + + + + + +# +# Do we need to explicitly link libc? +# +case "x$archive_cmds_need_lc" in +x|xyes) + # Assume -lc should be added + archive_cmds_need_lc=yes + + if test "$enable_shared" = yes && test "$GCC" = yes; then + case $archive_cmds in + *'~'*) + # FIXME: we may have to deal with multi-command sequences. + ;; + '$CC '*) + # Test whether the compiler implicitly links with -lc since on some + # systems, -lgcc has to come before -lc. If gcc already passes -lc + # to ld, don't add -lc before -lgcc. + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -lc should be explicitly linked in" >&5 +$as_echo_n "checking whether -lc should be explicitly linked in... " >&6; } + $RM conftest* + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } 2>conftest.err; then + soname=conftest + lib=conftest + libobjs=conftest.$ac_objext + deplibs= + wl=$lt_prog_compiler_wl + pic_flag=$lt_prog_compiler_pic + compiler_flags=-v + linker_flags=-v + verstring= + output_objdir=. + libname=conftest + lt_save_allow_undefined_flag=$allow_undefined_flag + allow_undefined_flag= + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$archive_cmds 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1\""; } >&5 + (eval $archive_cmds 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } + then + archive_cmds_need_lc=no + else + archive_cmds_need_lc=yes + fi + allow_undefined_flag=$lt_save_allow_undefined_flag + else + cat conftest.err 1>&5 + fi + $RM conftest* + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $archive_cmds_need_lc" >&5 +$as_echo "$archive_cmds_need_lc" >&6; } + ;; + esac + fi + ;; +esac + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking dynamic linker characteristics" >&5 +$as_echo_n "checking dynamic linker characteristics... " >&6; } + +if test "$GCC" = yes; then + case $host_os in + darwin*) lt_awk_arg="/^libraries:/,/LR/" ;; + *) lt_awk_arg="/^libraries:/" ;; + esac + lt_search_path_spec=`$CC -print-search-dirs | awk $lt_awk_arg | $SED -e "s/^libraries://" -e "s,=/,/,g"` + if $ECHO "$lt_search_path_spec" | $GREP ';' >/dev/null ; then + # if the path contains ";" then we assume it to be the separator + # otherwise default to the standard path separator (i.e. ":") - it is + # assumed that no part of a normal pathname contains ";" but that should + # okay in the real world where ";" in dirpaths is itself problematic. + lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED -e 's/;/ /g'` + else + lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"` + fi + # Ok, now we have the path, separated by spaces, we can step through it + # and add multilib dir if necessary. + lt_tmp_lt_search_path_spec= + lt_multi_os_dir=`$CC $CPPFLAGS $CFLAGS $LDFLAGS -print-multi-os-directory 2>/dev/null` + for lt_sys_path in $lt_search_path_spec; do + if test -d "$lt_sys_path/$lt_multi_os_dir"; then + lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path/$lt_multi_os_dir" + else + test -d "$lt_sys_path" && \ + lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path" + fi + done + lt_search_path_spec=`$ECHO $lt_tmp_lt_search_path_spec | awk ' +BEGIN {RS=" "; FS="/|\n";} { + lt_foo=""; + lt_count=0; + for (lt_i = NF; lt_i > 0; lt_i--) { + if ($lt_i != "" && $lt_i != ".") { + if ($lt_i == "..") { + lt_count++; + } else { + if (lt_count == 0) { + lt_foo="/" $lt_i lt_foo; + } else { + lt_count--; + } + } + } + } + if (lt_foo != "") { lt_freq[lt_foo]++; } + if (lt_freq[lt_foo] == 1) { print lt_foo; } +}'` + sys_lib_search_path_spec=`$ECHO $lt_search_path_spec` +else + sys_lib_search_path_spec="/lib /usr/lib /usr/local/lib" +fi +library_names_spec= +libname_spec='lib$name' +soname_spec= +shrext_cmds=".so" +postinstall_cmds= +postuninstall_cmds= +finish_cmds= +finish_eval= +shlibpath_var= +shlibpath_overrides_runpath=unknown +version_type=none +dynamic_linker="$host_os ld.so" +sys_lib_dlsearch_path_spec="/lib /usr/lib" +need_lib_prefix=unknown +hardcode_into_libs=no + +# when you set need_version to no, make sure it does not cause -set_version +# flags to be left without arguments +need_version=unknown + +case $host_os in +aix3*) + version_type=linux + library_names_spec='${libname}${release}${shared_ext}$versuffix $libname.a' + shlibpath_var=LIBPATH + + # AIX 3 has no versioning support, so we append a major version to the name. + soname_spec='${libname}${release}${shared_ext}$major' + ;; + +aix[4-9]*) + version_type=linux + need_lib_prefix=no + need_version=no + hardcode_into_libs=yes + if test "$host_cpu" = ia64; then + # AIX 5 supports IA64 + library_names_spec='${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext}$versuffix $libname${shared_ext}' + shlibpath_var=LD_LIBRARY_PATH + else + # With GCC up to 2.95.x, collect2 would create an import file + # for dependence libraries. The import file would start with + # the line `#! .'. This would cause the generated library to + # depend on `.', always an invalid library. This was fixed in + # development snapshots of GCC prior to 3.0. + case $host_os in + aix4 | aix4.[01] | aix4.[01].*) + if { echo '#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97)' + echo ' yes ' + echo '#endif'; } | ${CC} -E - | $GREP yes > /dev/null; then + : + else + can_build_shared=no + fi + ;; + esac + # AIX (on Power*) has no versioning support, so currently we can not hardcode correct + # soname into executable. Probably we can add versioning support to + # collect2, so additional links can be useful in future. + if test "$aix_use_runtimelinking" = yes; then + # If using run time linking (on AIX 4.2 or later) use lib.so + # instead of lib.a to let people know that these are not + # typical AIX shared libraries. + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + else + # We preserve .a as extension for shared libraries through AIX4.2 + # and later when we are not doing run time linking. + library_names_spec='${libname}${release}.a $libname.a' + soname_spec='${libname}${release}${shared_ext}$major' + fi + shlibpath_var=LIBPATH + fi + ;; + +amigaos*) + case $host_cpu in + powerpc) + # Since July 2007 AmigaOS4 officially supports .so libraries. + # When compiling the executable, add -use-dynld -Lsobjs: to the compileline. + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + ;; + m68k) + library_names_spec='$libname.ixlibrary $libname.a' + # Create ${libname}_ixlibrary.a entries in /sys/libs. + finish_eval='for lib in `ls $libdir/*.ixlibrary 2>/dev/null`; do libname=`$ECHO "X$lib" | $Xsed -e '\''s%^.*/\([^/]*\)\.ixlibrary$%\1%'\''`; test $RM /sys/libs/${libname}_ixlibrary.a; $show "cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a"; cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a || exit 1; done' + ;; + esac + ;; + +beos*) + library_names_spec='${libname}${shared_ext}' + dynamic_linker="$host_os ld.so" + shlibpath_var=LIBRARY_PATH + ;; + +bsdi[45]*) + version_type=linux + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + finish_cmds='PATH="\$PATH:/sbin" ldconfig $libdir' + shlibpath_var=LD_LIBRARY_PATH + sys_lib_search_path_spec="/shlib /usr/lib /usr/X11/lib /usr/contrib/lib /lib /usr/local/lib" + sys_lib_dlsearch_path_spec="/shlib /usr/lib /usr/local/lib" + # the default ld.so.conf also contains /usr/contrib/lib and + # /usr/X11R6/lib (/usr/X11 is a link to /usr/X11R6), but let us allow + # libtool to hard-code these into programs + ;; + +cygwin* | mingw* | pw32* | cegcc*) + version_type=windows + shrext_cmds=".dll" + need_version=no + need_lib_prefix=no + + case $GCC,$host_os in + yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*) + library_names_spec='$libname.dll.a' + # DLL is installed to $(libdir)/../bin by postinstall_cmds + postinstall_cmds='base_file=`basename \${file}`~ + dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~ + dldir=$destdir/`dirname \$dlpath`~ + test -d \$dldir || mkdir -p \$dldir~ + $install_prog $dir/$dlname \$dldir/$dlname~ + chmod a+x \$dldir/$dlname~ + if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then + eval '\''$striplib \$dldir/$dlname'\'' || exit \$?; + fi' + postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~ + dlpath=$dir/\$dldll~ + $RM \$dlpath' + shlibpath_overrides_runpath=yes + + case $host_os in + cygwin*) + # Cygwin DLLs use 'cyg' prefix rather than 'lib' + soname_spec='`echo ${libname} | sed -e 's/^lib/cyg/'``echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}' + sys_lib_search_path_spec="/usr/lib /lib/w32api /lib /usr/local/lib" + ;; + mingw* | cegcc*) + # MinGW DLLs use traditional 'lib' prefix + soname_spec='${libname}`echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}' + sys_lib_search_path_spec=`$CC -print-search-dirs | $GREP "^libraries:" | $SED -e "s/^libraries://" -e "s,=/,/,g"` + if $ECHO "$sys_lib_search_path_spec" | $GREP ';[c-zC-Z]:/' >/dev/null; then + # It is most probably a Windows format PATH printed by + # mingw gcc, but we are running on Cygwin. Gcc prints its search + # path with ; separators, and with drive letters. We can handle the + # drive letters (cygwin fileutils understands them), so leave them, + # especially as we might pass files found there to a mingw objdump, + # which wouldn't understand a cygwinified path. Ahh. + sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e 's/;/ /g'` + else + sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"` + fi + ;; + pw32*) + # pw32 DLLs use 'pw' prefix rather than 'lib' + library_names_spec='`echo ${libname} | sed -e 's/^lib/pw/'``echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}' + ;; + esac + ;; + + *) + library_names_spec='${libname}`echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext} $libname.lib' + ;; + esac + dynamic_linker='Win32 ld.exe' + # FIXME: first we should search . and the directory the executable is in + shlibpath_var=PATH + ;; + +darwin* | rhapsody*) + dynamic_linker="$host_os dyld" + version_type=darwin + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${major}$shared_ext ${libname}$shared_ext' + soname_spec='${libname}${release}${major}$shared_ext' + shlibpath_overrides_runpath=yes + shlibpath_var=DYLD_LIBRARY_PATH + shrext_cmds='`test .$module = .yes && echo .so || echo .dylib`' + + sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/local/lib" + sys_lib_dlsearch_path_spec='/usr/local/lib /lib /usr/lib' + ;; + +dgux*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname$shared_ext' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + ;; + +freebsd1*) + dynamic_linker=no + ;; + +freebsd* | dragonfly*) + # DragonFly does not have aout. When/if they implement a new + # versioning mechanism, adjust this. + if test -x /usr/bin/objformat; then + objformat=`/usr/bin/objformat` + else + case $host_os in + freebsd[123]*) objformat=aout ;; + *) objformat=elf ;; + esac + fi + version_type=freebsd-$objformat + case $version_type in + freebsd-elf*) + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}' + need_version=no + need_lib_prefix=no + ;; + freebsd-*) + library_names_spec='${libname}${release}${shared_ext}$versuffix $libname${shared_ext}$versuffix' + need_version=yes + ;; + esac + shlibpath_var=LD_LIBRARY_PATH + case $host_os in + freebsd2*) + shlibpath_overrides_runpath=yes + ;; + freebsd3.[01]* | freebsdelf3.[01]*) + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + freebsd3.[2-9]* | freebsdelf3.[2-9]* | \ + freebsd4.[0-5] | freebsdelf4.[0-5] | freebsd4.1.1 | freebsdelf4.1.1) + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + *) # from 4.6 on, and DragonFly + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + esac + ;; + +gnu*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}${major} ${libname}${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + hardcode_into_libs=yes + ;; + +hpux9* | hpux10* | hpux11*) + # Give a soname corresponding to the major version so that dld.sl refuses to + # link against other versions. + version_type=sunos + need_lib_prefix=no + need_version=no + case $host_cpu in + ia64*) + shrext_cmds='.so' + hardcode_into_libs=yes + dynamic_linker="$host_os dld.so" + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes # Unless +noenvvar is specified. + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + if test "X$HPUX_IA64_MODE" = X32; then + sys_lib_search_path_spec="/usr/lib/hpux32 /usr/local/lib/hpux32 /usr/local/lib" + else + sys_lib_search_path_spec="/usr/lib/hpux64 /usr/local/lib/hpux64" + fi + sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec + ;; + hppa*64*) + shrext_cmds='.sl' + hardcode_into_libs=yes + dynamic_linker="$host_os dld.sl" + shlibpath_var=LD_LIBRARY_PATH # How should we handle SHLIB_PATH + shlibpath_overrides_runpath=yes # Unless +noenvvar is specified. + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + sys_lib_search_path_spec="/usr/lib/pa20_64 /usr/ccs/lib/pa20_64" + sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec + ;; + *) + shrext_cmds='.sl' + dynamic_linker="$host_os dld.sl" + shlibpath_var=SHLIB_PATH + shlibpath_overrides_runpath=no # +s is required to enable SHLIB_PATH + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + ;; + esac + # HP-UX runs *really* slowly unless shared libraries are mode 555. + postinstall_cmds='chmod 555 $lib' + ;; + +interix[3-9]*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + dynamic_linker='Interix 3.x ld.so.1 (PE, like ELF)' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + +irix5* | irix6* | nonstopux*) + case $host_os in + nonstopux*) version_type=nonstopux ;; + *) + if test "$lt_cv_prog_gnu_ld" = yes; then + version_type=linux + else + version_type=irix + fi ;; + esac + need_lib_prefix=no + need_version=no + soname_spec='${libname}${release}${shared_ext}$major' + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext} $libname${shared_ext}' + case $host_os in + irix5* | nonstopux*) + libsuff= shlibsuff= + ;; + *) + case $LD in # libtool.m4 will add one of these switches to LD + *-32|*"-32 "|*-melf32bsmip|*"-melf32bsmip ") + libsuff= shlibsuff= libmagic=32-bit;; + *-n32|*"-n32 "|*-melf32bmipn32|*"-melf32bmipn32 ") + libsuff=32 shlibsuff=N32 libmagic=N32;; + *-64|*"-64 "|*-melf64bmip|*"-melf64bmip ") + libsuff=64 shlibsuff=64 libmagic=64-bit;; + *) libsuff= shlibsuff= libmagic=never-match;; + esac + ;; + esac + shlibpath_var=LD_LIBRARY${shlibsuff}_PATH + shlibpath_overrides_runpath=no + sys_lib_search_path_spec="/usr/lib${libsuff} /lib${libsuff} /usr/local/lib${libsuff}" + sys_lib_dlsearch_path_spec="/usr/lib${libsuff} /lib${libsuff}" + hardcode_into_libs=yes + ;; + +# No shared lib support for Linux oldld, aout, or coff. +linux*oldld* | linux*aout* | linux*coff*) + dynamic_linker=no + ;; + +# This must be Linux ELF. +linux* | k*bsd*-gnu) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -n $libdir' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + # Some binutils ld are patched to set DT_RUNPATH + save_LDFLAGS=$LDFLAGS + save_libdir=$libdir + eval "libdir=/foo; wl=\"$lt_prog_compiler_wl\"; \ + LDFLAGS=\"\$LDFLAGS $hardcode_libdir_flag_spec\"" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + if ($OBJDUMP -p conftest$ac_exeext) 2>/dev/null | grep "RUNPATH.*$libdir" >/dev/null; then : + shlibpath_overrides_runpath=yes +fi +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + LDFLAGS=$save_LDFLAGS + libdir=$save_libdir + + # This implies no fast_install, which is unacceptable. + # Some rework will be needed to allow for fast_install + # before this can be enabled. + hardcode_into_libs=yes + + # Append ld.so.conf contents to the search path + if test -f /etc/ld.so.conf; then + lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \$2)); skip = 1; } { if (!skip) print \$0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;/^[ ]*hwcap[ ]/d;s/[:, ]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;/^$/d' | tr '\n' ' '` + sys_lib_dlsearch_path_spec="/lib /usr/lib $lt_ld_extra" + fi + + # We used to test for /lib/ld.so.1 and disable shared libraries on + # powerpc, because MkLinux only supported shared libraries with the + # GNU dynamic linker. Since this was broken with cross compilers, + # most powerpc-linux boxes support dynamic linking these days and + # people can always --disable-shared, the test was removed, and we + # assume the GNU/Linux dynamic linker is in use. + dynamic_linker='GNU/Linux ld.so' + ;; + +netbsd*) + version_type=sunos + need_lib_prefix=no + need_version=no + if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir' + dynamic_linker='NetBSD (a.out) ld.so' + else + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + dynamic_linker='NetBSD ld.elf_so' + fi + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + +newsos6) + version_type=linux + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + ;; + +*nto* | *qnx*) + version_type=qnx + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + dynamic_linker='ldqnx.so' + ;; + +openbsd*) + version_type=sunos + sys_lib_dlsearch_path_spec="/usr/lib" + need_lib_prefix=no + # Some older versions of OpenBSD (3.3 at least) *do* need versioned libs. + case $host_os in + openbsd3.3 | openbsd3.3.*) need_version=yes ;; + *) need_version=no ;; + esac + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir' + shlibpath_var=LD_LIBRARY_PATH + if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then + case $host_os in + openbsd2.[89] | openbsd2.[89].*) + shlibpath_overrides_runpath=no + ;; + *) + shlibpath_overrides_runpath=yes + ;; + esac + else + shlibpath_overrides_runpath=yes + fi + ;; + +os2*) + libname_spec='$name' + shrext_cmds=".dll" + need_lib_prefix=no + library_names_spec='$libname${shared_ext} $libname.a' + dynamic_linker='OS/2 ld.exe' + shlibpath_var=LIBPATH + ;; + +osf3* | osf4* | osf5*) + version_type=osf + need_lib_prefix=no + need_version=no + soname_spec='${libname}${release}${shared_ext}$major' + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + shlibpath_var=LD_LIBRARY_PATH + sys_lib_search_path_spec="/usr/shlib /usr/ccs/lib /usr/lib/cmplrs/cc /usr/lib /usr/local/lib /var/shlib" + sys_lib_dlsearch_path_spec="$sys_lib_search_path_spec" + ;; + +rdos*) + dynamic_linker=no + ;; + +solaris*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + # ldd complains unless libraries are executable + postinstall_cmds='chmod +x $lib' + ;; + +sunos4*) + version_type=sunos + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix' + finish_cmds='PATH="\$PATH:/usr/etc" ldconfig $libdir' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + if test "$with_gnu_ld" = yes; then + need_lib_prefix=no + fi + need_version=yes + ;; + +sysv4 | sysv4.3*) + version_type=linux + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + case $host_vendor in + sni) + shlibpath_overrides_runpath=no + need_lib_prefix=no + runpath_var=LD_RUN_PATH + ;; + siemens) + need_lib_prefix=no + ;; + motorola) + need_lib_prefix=no + need_version=no + shlibpath_overrides_runpath=no + sys_lib_search_path_spec='/lib /usr/lib /usr/ccs/lib' + ;; + esac + ;; + +sysv4*MP*) + if test -d /usr/nec ;then + version_type=linux + library_names_spec='$libname${shared_ext}.$versuffix $libname${shared_ext}.$major $libname${shared_ext}' + soname_spec='$libname${shared_ext}.$major' + shlibpath_var=LD_LIBRARY_PATH + fi + ;; + +sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*) + version_type=freebsd-elf + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + if test "$with_gnu_ld" = yes; then + sys_lib_search_path_spec='/usr/local/lib /usr/gnu/lib /usr/ccs/lib /usr/lib /lib' + else + sys_lib_search_path_spec='/usr/ccs/lib /usr/lib' + case $host_os in + sco3.2v5*) + sys_lib_search_path_spec="$sys_lib_search_path_spec /lib" + ;; + esac + fi + sys_lib_dlsearch_path_spec='/usr/lib' + ;; + +tpf*) + # TPF is a cross-target only. Preferred cross-host = GNU/Linux. + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + +uts4*) + version_type=linux + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + ;; + +*) + dynamic_linker=no + ;; +esac +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $dynamic_linker" >&5 +$as_echo "$dynamic_linker" >&6; } +test "$dynamic_linker" = no && can_build_shared=no + +variables_saved_for_relink="PATH $shlibpath_var $runpath_var" +if test "$GCC" = yes; then + variables_saved_for_relink="$variables_saved_for_relink GCC_EXEC_PREFIX COMPILER_PATH LIBRARY_PATH" +fi + +if test "${lt_cv_sys_lib_search_path_spec+set}" = set; then + sys_lib_search_path_spec="$lt_cv_sys_lib_search_path_spec" +fi +if test "${lt_cv_sys_lib_dlsearch_path_spec+set}" = set; then + sys_lib_dlsearch_path_spec="$lt_cv_sys_lib_dlsearch_path_spec" +fi + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to hardcode library paths into programs" >&5 +$as_echo_n "checking how to hardcode library paths into programs... " >&6; } +hardcode_action= +if test -n "$hardcode_libdir_flag_spec" || + test -n "$runpath_var" || + test "X$hardcode_automatic" = "Xyes" ; then + + # We can hardcode non-existent directories. + if test "$hardcode_direct" != no && + # If the only mechanism to avoid hardcoding is shlibpath_var, we + # have to relink, otherwise we might link with an installed library + # when we should be linking with a yet-to-be-installed one + ## test "$_LT_TAGVAR(hardcode_shlibpath_var, )" != no && + test "$hardcode_minus_L" != no; then + # Linking always hardcodes the temporary library directory. + hardcode_action=relink + else + # We can link without hardcoding, and we can hardcode nonexisting dirs. + hardcode_action=immediate + fi +else + # We cannot hardcode anything, or else we can only hardcode existing + # directories. + hardcode_action=unsupported +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $hardcode_action" >&5 +$as_echo "$hardcode_action" >&6; } + +if test "$hardcode_action" = relink || + test "$inherit_rpath" = yes; then + # Fast installation is not supported + enable_fast_install=no +elif test "$shlibpath_overrides_runpath" = yes || + test "$enable_shared" = no; then + # Fast installation is not necessary + enable_fast_install=needless +fi + + + + + + + if test "x$enable_dlopen" != xyes; then + enable_dlopen=unknown + enable_dlopen_self=unknown + enable_dlopen_self_static=unknown +else + lt_cv_dlopen=no + lt_cv_dlopen_libs= + + case $host_os in + beos*) + lt_cv_dlopen="load_add_on" + lt_cv_dlopen_libs= + lt_cv_dlopen_self=yes + ;; + + mingw* | pw32* | cegcc*) + lt_cv_dlopen="LoadLibrary" + lt_cv_dlopen_libs= + ;; + + cygwin*) + lt_cv_dlopen="dlopen" + lt_cv_dlopen_libs= + ;; + + darwin*) + # if libdl is installed we need to link against it + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlopen in -ldl" >&5 +$as_echo_n "checking for dlopen in -ldl... " >&6; } +if test "${ac_cv_lib_dl_dlopen+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-ldl $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char dlopen (); +int +main () +{ +return dlopen (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_dl_dlopen=yes +else + ac_cv_lib_dl_dlopen=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dl_dlopen" >&5 +$as_echo "$ac_cv_lib_dl_dlopen" >&6; } +if test "x$ac_cv_lib_dl_dlopen" = x""yes; then : + lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl" +else + + lt_cv_dlopen="dyld" + lt_cv_dlopen_libs= + lt_cv_dlopen_self=yes + +fi + + ;; + + *) + ac_fn_c_check_func "$LINENO" "shl_load" "ac_cv_func_shl_load" +if test "x$ac_cv_func_shl_load" = x""yes; then : + lt_cv_dlopen="shl_load" +else + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for shl_load in -ldld" >&5 +$as_echo_n "checking for shl_load in -ldld... " >&6; } +if test "${ac_cv_lib_dld_shl_load+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-ldld $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char shl_load (); +int +main () +{ +return shl_load (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_dld_shl_load=yes +else + ac_cv_lib_dld_shl_load=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dld_shl_load" >&5 +$as_echo "$ac_cv_lib_dld_shl_load" >&6; } +if test "x$ac_cv_lib_dld_shl_load" = x""yes; then : + lt_cv_dlopen="shl_load" lt_cv_dlopen_libs="-ldld" +else + ac_fn_c_check_func "$LINENO" "dlopen" "ac_cv_func_dlopen" +if test "x$ac_cv_func_dlopen" = x""yes; then : + lt_cv_dlopen="dlopen" +else + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlopen in -ldl" >&5 +$as_echo_n "checking for dlopen in -ldl... " >&6; } +if test "${ac_cv_lib_dl_dlopen+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-ldl $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char dlopen (); +int +main () +{ +return dlopen (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_dl_dlopen=yes +else + ac_cv_lib_dl_dlopen=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dl_dlopen" >&5 +$as_echo "$ac_cv_lib_dl_dlopen" >&6; } +if test "x$ac_cv_lib_dl_dlopen" = x""yes; then : + lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl" +else + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlopen in -lsvld" >&5 +$as_echo_n "checking for dlopen in -lsvld... " >&6; } +if test "${ac_cv_lib_svld_dlopen+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lsvld $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char dlopen (); +int +main () +{ +return dlopen (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_svld_dlopen=yes +else + ac_cv_lib_svld_dlopen=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_svld_dlopen" >&5 +$as_echo "$ac_cv_lib_svld_dlopen" >&6; } +if test "x$ac_cv_lib_svld_dlopen" = x""yes; then : + lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-lsvld" +else + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dld_link in -ldld" >&5 +$as_echo_n "checking for dld_link in -ldld... " >&6; } +if test "${ac_cv_lib_dld_dld_link+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-ldld $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char dld_link (); +int +main () +{ +return dld_link (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_dld_dld_link=yes +else + ac_cv_lib_dld_dld_link=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dld_dld_link" >&5 +$as_echo "$ac_cv_lib_dld_dld_link" >&6; } +if test "x$ac_cv_lib_dld_dld_link" = x""yes; then : + lt_cv_dlopen="dld_link" lt_cv_dlopen_libs="-ldld" +fi + + +fi + + +fi + + +fi + + +fi + + +fi + + ;; + esac + + if test "x$lt_cv_dlopen" != xno; then + enable_dlopen=yes + else + enable_dlopen=no + fi + + case $lt_cv_dlopen in + dlopen) + save_CPPFLAGS="$CPPFLAGS" + test "x$ac_cv_header_dlfcn_h" = xyes && CPPFLAGS="$CPPFLAGS -DHAVE_DLFCN_H" + + save_LDFLAGS="$LDFLAGS" + wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $export_dynamic_flag_spec\" + + save_LIBS="$LIBS" + LIBS="$lt_cv_dlopen_libs $LIBS" + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether a program can dlopen itself" >&5 +$as_echo_n "checking whether a program can dlopen itself... " >&6; } +if test "${lt_cv_dlopen_self+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test "$cross_compiling" = yes; then : + lt_cv_dlopen_self=cross +else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +#line 10609 "configure" +#include "confdefs.h" + +#if HAVE_DLFCN_H +#include +#endif + +#include + +#ifdef RTLD_GLOBAL +# define LT_DLGLOBAL RTLD_GLOBAL +#else +# ifdef DL_GLOBAL +# define LT_DLGLOBAL DL_GLOBAL +# else +# define LT_DLGLOBAL 0 +# endif +#endif + +/* We may have to define LT_DLLAZY_OR_NOW in the command line if we + find out it does not work in some platform. */ +#ifndef LT_DLLAZY_OR_NOW +# ifdef RTLD_LAZY +# define LT_DLLAZY_OR_NOW RTLD_LAZY +# else +# ifdef DL_LAZY +# define LT_DLLAZY_OR_NOW DL_LAZY +# else +# ifdef RTLD_NOW +# define LT_DLLAZY_OR_NOW RTLD_NOW +# else +# ifdef DL_NOW +# define LT_DLLAZY_OR_NOW DL_NOW +# else +# define LT_DLLAZY_OR_NOW 0 +# endif +# endif +# endif +# endif +#endif + +void fnord() { int i=42;} +int main () +{ + void *self = dlopen (0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW); + int status = $lt_dlunknown; + + if (self) + { + if (dlsym (self,"fnord")) status = $lt_dlno_uscore; + else if (dlsym( self,"_fnord")) status = $lt_dlneed_uscore; + /* dlclose (self); */ + } + else + puts (dlerror ()); + + return status; +} +_LT_EOF + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_link\""; } >&5 + (eval $ac_link) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && test -s conftest${ac_exeext} 2>/dev/null; then + (./conftest; exit; ) >&5 2>/dev/null + lt_status=$? + case x$lt_status in + x$lt_dlno_uscore) lt_cv_dlopen_self=yes ;; + x$lt_dlneed_uscore) lt_cv_dlopen_self=yes ;; + x$lt_dlunknown|x*) lt_cv_dlopen_self=no ;; + esac + else : + # compilation failed + lt_cv_dlopen_self=no + fi +fi +rm -fr conftest* + + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_dlopen_self" >&5 +$as_echo "$lt_cv_dlopen_self" >&6; } + + if test "x$lt_cv_dlopen_self" = xyes; then + wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $lt_prog_compiler_static\" + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether a statically linked program can dlopen itself" >&5 +$as_echo_n "checking whether a statically linked program can dlopen itself... " >&6; } +if test "${lt_cv_dlopen_self_static+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test "$cross_compiling" = yes; then : + lt_cv_dlopen_self_static=cross +else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +#line 10705 "configure" +#include "confdefs.h" + +#if HAVE_DLFCN_H +#include +#endif + +#include + +#ifdef RTLD_GLOBAL +# define LT_DLGLOBAL RTLD_GLOBAL +#else +# ifdef DL_GLOBAL +# define LT_DLGLOBAL DL_GLOBAL +# else +# define LT_DLGLOBAL 0 +# endif +#endif + +/* We may have to define LT_DLLAZY_OR_NOW in the command line if we + find out it does not work in some platform. */ +#ifndef LT_DLLAZY_OR_NOW +# ifdef RTLD_LAZY +# define LT_DLLAZY_OR_NOW RTLD_LAZY +# else +# ifdef DL_LAZY +# define LT_DLLAZY_OR_NOW DL_LAZY +# else +# ifdef RTLD_NOW +# define LT_DLLAZY_OR_NOW RTLD_NOW +# else +# ifdef DL_NOW +# define LT_DLLAZY_OR_NOW DL_NOW +# else +# define LT_DLLAZY_OR_NOW 0 +# endif +# endif +# endif +# endif +#endif + +void fnord() { int i=42;} +int main () +{ + void *self = dlopen (0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW); + int status = $lt_dlunknown; + + if (self) + { + if (dlsym (self,"fnord")) status = $lt_dlno_uscore; + else if (dlsym( self,"_fnord")) status = $lt_dlneed_uscore; + /* dlclose (self); */ + } + else + puts (dlerror ()); + + return status; +} +_LT_EOF + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_link\""; } >&5 + (eval $ac_link) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && test -s conftest${ac_exeext} 2>/dev/null; then + (./conftest; exit; ) >&5 2>/dev/null + lt_status=$? + case x$lt_status in + x$lt_dlno_uscore) lt_cv_dlopen_self_static=yes ;; + x$lt_dlneed_uscore) lt_cv_dlopen_self_static=yes ;; + x$lt_dlunknown|x*) lt_cv_dlopen_self_static=no ;; + esac + else : + # compilation failed + lt_cv_dlopen_self_static=no + fi +fi +rm -fr conftest* + + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_dlopen_self_static" >&5 +$as_echo "$lt_cv_dlopen_self_static" >&6; } + fi + + CPPFLAGS="$save_CPPFLAGS" + LDFLAGS="$save_LDFLAGS" + LIBS="$save_LIBS" + ;; + esac + + case $lt_cv_dlopen_self in + yes|no) enable_dlopen_self=$lt_cv_dlopen_self ;; + *) enable_dlopen_self=unknown ;; + esac + + case $lt_cv_dlopen_self_static in + yes|no) enable_dlopen_self_static=$lt_cv_dlopen_self_static ;; + *) enable_dlopen_self_static=unknown ;; + esac +fi + + + + + + + + + + + + + + + + + +striplib= +old_striplib= +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether stripping libraries is possible" >&5 +$as_echo_n "checking whether stripping libraries is possible... " >&6; } +if test -n "$STRIP" && $STRIP -V 2>&1 | $GREP "GNU strip" >/dev/null; then + test -z "$old_striplib" && old_striplib="$STRIP --strip-debug" + test -z "$striplib" && striplib="$STRIP --strip-unneeded" + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } +else +# FIXME - insert some real tests, host_os isn't really good enough + case $host_os in + darwin*) + if test -n "$STRIP" ; then + striplib="$STRIP -x" + old_striplib="$STRIP -S" + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + fi + ;; + *) + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + ;; + esac +fi + + + + + + + + + + + + + # Report which library types will actually be built + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if libtool supports shared libraries" >&5 +$as_echo_n "checking if libtool supports shared libraries... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $can_build_shared" >&5 +$as_echo "$can_build_shared" >&6; } + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to build shared libraries" >&5 +$as_echo_n "checking whether to build shared libraries... " >&6; } + test "$can_build_shared" = "no" && enable_shared=no + + # On AIX, shared libraries and static libraries use the same namespace, and + # are all built from PIC. + case $host_os in + aix3*) + test "$enable_shared" = yes && enable_static=no + if test -n "$RANLIB"; then + archive_cmds="$archive_cmds~\$RANLIB \$lib" + postinstall_cmds='$RANLIB $lib' + fi + ;; + + aix[4-9]*) + if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then + test "$enable_shared" = yes && enable_static=no + fi + ;; + esac + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_shared" >&5 +$as_echo "$enable_shared" >&6; } + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to build static libraries" >&5 +$as_echo_n "checking whether to build static libraries... " >&6; } + # Make sure either enable_shared or enable_static is yes. + test "$enable_shared" = yes || enable_static=yes + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_static" >&5 +$as_echo "$enable_static" >&6; } + + + + +fi +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + +CC="$lt_save_CC" + + + + + + + + + + + + + + ac_config_commands="$ac_config_commands libtool" + + + + +# Only expand once: + + + +# Checks for header files. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5 +$as_echo_n "checking for ANSI C header files... " >&6; } +if test "${ac_cv_header_stdc+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +#include +#include + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_header_stdc=yes +else + ac_cv_header_stdc=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + +if test $ac_cv_header_stdc = yes; then + # SunOS 4.x string.h does not declare mem*, contrary to ANSI. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "memchr" >/dev/null 2>&1; then : + +else + ac_cv_header_stdc=no +fi +rm -f conftest* + +fi + +if test $ac_cv_header_stdc = yes; then + # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "free" >/dev/null 2>&1; then : + +else + ac_cv_header_stdc=no +fi +rm -f conftest* + +fi + +if test $ac_cv_header_stdc = yes; then + # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi. + if test "$cross_compiling" = yes; then : + : +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +#if ((' ' & 0x0FF) == 0x020) +# define ISLOWER(c) ('a' <= (c) && (c) <= 'z') +# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c)) +#else +# define ISLOWER(c) \ + (('a' <= (c) && (c) <= 'i') \ + || ('j' <= (c) && (c) <= 'r') \ + || ('s' <= (c) && (c) <= 'z')) +# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c)) +#endif + +#define XOR(e, f) (((e) && !(f)) || (!(e) && (f))) +int +main () +{ + int i; + for (i = 0; i < 256; i++) + if (XOR (islower (i), ISLOWER (i)) + || toupper (i) != TOUPPER (i)) + return 2; + return 0; +} +_ACEOF +if ac_fn_c_try_run "$LINENO"; then : + +else + ac_cv_header_stdc=no +fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ + conftest.$ac_objext conftest.beam conftest.$ac_ext +fi + +fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdc" >&5 +$as_echo "$ac_cv_header_stdc" >&6; } +if test $ac_cv_header_stdc = yes; then + +$as_echo "#define STDC_HEADERS 1" >>confdefs.h + +fi + +for ac_header in malloc.h stdlib.h string.h strings.h +do : + as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` +ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default" +eval as_val=\$$as_ac_Header + if test "x$as_val" = x""yes; then : + cat >>confdefs.h <<_ACEOF +#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 +_ACEOF + +fi + +done + + +# Checks for typedefs, structures, and compiler characteristics. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for an ANSI C-conforming const" >&5 +$as_echo_n "checking for an ANSI C-conforming const... " >&6; } +if test "${ac_cv_c_const+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ +/* FIXME: Include the comments suggested by Paul. */ +#ifndef __cplusplus + /* Ultrix mips cc rejects this. */ + typedef int charset[2]; + const charset cs; + /* SunOS 4.1.1 cc rejects this. */ + char const *const *pcpcc; + char **ppc; + /* NEC SVR4.0.2 mips cc rejects this. */ + struct point {int x, y;}; + static struct point const zero = {0,0}; + /* AIX XL C 1.02.0.0 rejects this. + It does not let you subtract one const X* pointer from another in + an arm of an if-expression whose if-part is not a constant + expression */ + const char *g = "string"; + pcpcc = &g + (g ? g-g : 0); + /* HPUX 7.0 cc rejects these. */ + ++pcpcc; + ppc = (char**) pcpcc; + pcpcc = (char const *const *) ppc; + { /* SCO 3.2v4 cc rejects this. */ + char *t; + char const *s = 0 ? (char *) 0 : (char const *) 0; + + *t++ = 0; + if (s) return 0; + } + { /* Someone thinks the Sun supposedly-ANSI compiler will reject this. */ + int x[] = {25, 17}; + const int *foo = &x[0]; + ++foo; + } + { /* Sun SC1.0 ANSI compiler rejects this -- but not the above. */ + typedef const int *iptr; + iptr p = 0; + ++p; + } + { /* AIX XL C 1.02.0.0 rejects this saying + "k.c", line 2.27: 1506-025 (S) Operand must be a modifiable lvalue. */ + struct s { int j; const int *ap[3]; }; + struct s *b; b->j = 5; + } + { /* ULTRIX-32 V3.1 (Rev 9) vcc rejects this */ + const int foo = 10; + if (!foo) return 0; + } + return !cs[0] && !zero.x; +#endif + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_c_const=yes +else + ac_cv_c_const=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_const" >&5 +$as_echo "$ac_cv_c_const" >&6; } +if test $ac_cv_c_const = no; then + +$as_echo "#define const /**/" >>confdefs.h + +fi + +ac_fn_c_check_type "$LINENO" "size_t" "ac_cv_type_size_t" "$ac_includes_default" +if test "x$ac_cv_type_size_t" = x""yes; then : + +else + +cat >>confdefs.h <<_ACEOF +#define size_t unsigned int +_ACEOF + +fi + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether struct tm is in sys/time.h or time.h" >&5 +$as_echo_n "checking whether struct tm is in sys/time.h or time.h... " >&6; } +if test "${ac_cv_struct_tm+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include + +int +main () +{ +struct tm tm; + int *p = &tm.tm_sec; + return !p; + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_struct_tm=time.h +else + ac_cv_struct_tm=sys/time.h +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_struct_tm" >&5 +$as_echo "$ac_cv_struct_tm" >&6; } +if test $ac_cv_struct_tm = sys/time.h; then + +$as_echo "#define TM_IN_SYS_TIME 1" >>confdefs.h + +fi + + +# Checks for library functions. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for working strtod" >&5 +$as_echo_n "checking for working strtod... " >&6; } +if test "${ac_cv_func_strtod+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test "$cross_compiling" = yes; then : + ac_cv_func_strtod=no +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +$ac_includes_default +#ifndef strtod +double strtod (); +#endif +int +main() +{ + { + /* Some versions of Linux strtod mis-parse strings with leading '+'. */ + char *string = " +69"; + char *term; + double value; + value = strtod (string, &term); + if (value != 69 || term != (string + 4)) + return 1; + } + + { + /* Under Solaris 2.4, strtod returns the wrong value for the + terminating character under some conditions. */ + char *string = "NaN"; + char *term; + strtod (string, &term); + if (term != string && *(term - 1) == 0) + return 1; + } + return 0; +} + +_ACEOF +if ac_fn_c_try_run "$LINENO"; then : + ac_cv_func_strtod=yes +else + ac_cv_func_strtod=no +fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ + conftest.$ac_objext conftest.beam conftest.$ac_ext +fi + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_strtod" >&5 +$as_echo "$ac_cv_func_strtod" >&6; } +if test $ac_cv_func_strtod = no; then + case " $LIBOBJS " in + *" strtod.$ac_objext "* ) ;; + *) LIBOBJS="$LIBOBJS strtod.$ac_objext" + ;; +esac + +ac_fn_c_check_func "$LINENO" "pow" "ac_cv_func_pow" +if test "x$ac_cv_func_pow" = x""yes; then : + +fi + +if test $ac_cv_func_pow = no; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for pow in -lm" >&5 +$as_echo_n "checking for pow in -lm... " >&6; } +if test "${ac_cv_lib_m_pow+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lm $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char pow (); +int +main () +{ +return pow (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_m_pow=yes +else + ac_cv_lib_m_pow=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_m_pow" >&5 +$as_echo "$ac_cv_lib_m_pow" >&6; } +if test "x$ac_cv_lib_m_pow" = x""yes; then : + POW_LIB=-lm +else + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cannot find library containing definition of pow" >&5 +$as_echo "$as_me: WARNING: cannot find library containing definition of pow" >&2;} +fi + +fi + +fi + +for ac_func in memset +do : + ac_fn_c_check_func "$LINENO" "memset" "ac_cv_func_memset" +if test "x$ac_cv_func_memset" = x""yes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_MEMSET 1 +_ACEOF + +else + as_fn_error "memset not found in libc" "$LINENO" 5 +fi +done + +for ac_func in pow +do : + ac_fn_c_check_func "$LINENO" "pow" "ac_cv_func_pow" +if test "x$ac_cv_func_pow" = x""yes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_POW 1 +_ACEOF + +else + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for pow in -lm" >&5 +$as_echo_n "checking for pow in -lm... " >&6; } +if test "${ac_cv_lib_m_pow+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lm $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char pow (); +int +main () +{ +return pow (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_m_pow=yes +else + ac_cv_lib_m_pow=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_m_pow" >&5 +$as_echo "$ac_cv_lib_m_pow" >&6; } +if test "x$ac_cv_lib_m_pow" = x""yes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_LIBM 1 +_ACEOF + + LIBS="-lm $LIBS" + +else + as_fn_error "cannot find pow" "$LINENO" 5 +fi + +fi +done + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for zlibVersion in -lz" >&5 +$as_echo_n "checking for zlibVersion in -lz... " >&6; } +if test "${ac_cv_lib_z_zlibVersion+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lz $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char zlibVersion (); +int +main () +{ +return zlibVersion (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_z_zlibVersion=yes +else + ac_cv_lib_z_zlibVersion=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_z_zlibVersion" >&5 +$as_echo "$ac_cv_lib_z_zlibVersion" >&6; } +if test "x$ac_cv_lib_z_zlibVersion" = x""yes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_LIBZ 1 +_ACEOF + + LIBS="-lz $LIBS" + +else + as_fn_error "zlib not installed" "$LINENO" 5 +fi + + +case $host_os in + aix*) + LIBPNG_DEFINES=-DPNG_CONFIGURE_LIBPNG -D_ALL_SOURCE;; + *) + LIBPNG_DEFINES=-DPNG_CONFIGURE_LIBPNG;; +esac +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if assembler code in pnggccrd.c can be compiled without PNG_NO_MMX_CODE" >&5 +$as_echo_n "checking if assembler code in pnggccrd.c can be compiled without PNG_NO_MMX_CODE... " >&6; } +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include "$srcdir/pnggccrd.c" +int +main () +{ +return 0; + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + LIBPNG_NO_MMX="" +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + LIBPNG_NO_MMX=-DPNG_NO_MMX_CODE +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +LIBPNG_DEFINES=$LIBPNG_DEFINES\ $LIBPNG_NO_MMX + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if libraries can be versioned" >&5 +$as_echo_n "checking if libraries can be versioned... " >&6; } +GLD=`$LD --help < /dev/null 2>/dev/null | grep version-script` +if test "$GLD"; then + have_ld_version_script=yes + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } +else + have_ld_version_script=no + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: *** You have not enabled versioned symbols." >&5 +$as_echo "$as_me: WARNING: *** You have not enabled versioned symbols." >&2;} +fi + if test "$have_ld_version_script" = "yes"; then + HAVE_LD_VERSION_SCRIPT_TRUE= + HAVE_LD_VERSION_SCRIPT_FALSE='#' +else + HAVE_LD_VERSION_SCRIPT_TRUE='#' + HAVE_LD_VERSION_SCRIPT_FALSE= +fi + + +if test "$have_ld_version_script" = "yes"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for symbol prefix" >&5 +$as_echo_n "checking for symbol prefix... " >&6; } + SYMBOL_PREFIX=`echo "PREFIX=__USER_LABEL_PREFIX__" \ + | ${CPP-${CC-gcc} -E} - 2>&1 \ + | ${EGREP-grep} "^PREFIX=" \ + | ${SED-sed} "s:^PREFIX=::"` + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $SYMBOL_PREFIX" >&5 +$as_echo "$SYMBOL_PREFIX" >&6; } +fi + +# Substitutions for .in files + + + + + +# Additional arguments (and substitutions) +# Allow the pkg-config directory to be set + +# Check whether --with-pkgconfigdir was given. +if test "${with_pkgconfigdir+set}" = set; then : + withval=$with_pkgconfigdir; pkgconfigdir=${withval} +else + pkgconfigdir='${libdir}/pkgconfig' +fi + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: pkgconfig directory is ${pkgconfigdir}" >&5 +$as_echo "$as_me: pkgconfig directory is ${pkgconfigdir}" >&6;} + +# Make the *-config binary config scripts optional + +# Check whether --with-binconfigs was given. +if test "${with_binconfigs+set}" = set; then : + withval=$with_binconfigs; if test "${withval}" = no; then + binconfigs= + { $as_echo "$as_me:${as_lineno-$LINENO}: libpng-config scripts will not be built" >&5 +$as_echo "$as_me: libpng-config scripts will not be built" >&6;} + else + binconfigs='${binconfigs}' + fi +else + binconfigs='${binconfigs}' +fi + + + +# Allow the old version number library, libpng.so, to be removed from +# the build + +# Check whether --with-libpng-compat was given. +if test "${with_libpng_compat+set}" = set; then : + withval=$with_libpng_compat; if test "${withval}" = no; then + compatlib= + { $as_echo "$as_me:${as_lineno-$LINENO}: libpng.so will not be built" >&5 +$as_echo "$as_me: libpng.so will not be built" >&6;} + else + compatlib=libpng.la + fi +else + compatlib=libpng.la +fi + + + +# Config files, substituting as above +ac_config_files="$ac_config_files Makefile libpng.pc:scripts/libpng.pc-configure.in" + +ac_config_files="$ac_config_files libpng-config:scripts/libpng-config.in" + + +cat >confcache <<\_ACEOF +# This file is a shell script that caches the results of configure +# tests run on this system so they can be shared between configure +# scripts and configure runs, see configure's option --config-cache. +# It is not useful on other systems. If it contains results you don't +# want to keep, you may remove or edit it. +# +# config.status only pays attention to the cache file if you give it +# the --recheck option to rerun configure. +# +# `ac_cv_env_foo' variables (set or unset) will be overridden when +# loading this file, other *unset* `ac_cv_foo' will be assigned the +# following values. + +_ACEOF + +# The following way of writing the cache mishandles newlines in values, +# but we know of no workaround that is simple, portable, and efficient. +# So, we kill variables containing newlines. +# Ultrix sh set writes to stderr and can't be redirected directly, +# and sets the high bit in the cache file unless we assign to the vars. +( + for ac_var in `(set) 2>&1 | sed -n 's/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'`; do + eval ac_val=\$$ac_var + case $ac_val in #( + *${as_nl}*) + case $ac_var in #( + *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 +$as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; + esac + case $ac_var in #( + _ | IFS | as_nl) ;; #( + BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #( + *) { eval $ac_var=; unset $ac_var;} ;; + esac ;; + esac + done + + (set) 2>&1 | + case $as_nl`(ac_space=' '; set) 2>&1` in #( + *${as_nl}ac_space=\ *) + # `set' does not quote correctly, so add quotes: double-quote + # substitution turns \\\\ into \\, and sed turns \\ into \. + sed -n \ + "s/'/'\\\\''/g; + s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p" + ;; #( + *) + # `set' quotes correctly as required by POSIX, so do not add quotes. + sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" + ;; + esac | + sort +) | + sed ' + /^ac_cv_env_/b end + t clear + :clear + s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/ + t end + s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/ + :end' >>confcache +if diff "$cache_file" confcache >/dev/null 2>&1; then :; else + if test -w "$cache_file"; then + test "x$cache_file" != "x/dev/null" && + { $as_echo "$as_me:${as_lineno-$LINENO}: updating cache $cache_file" >&5 +$as_echo "$as_me: updating cache $cache_file" >&6;} + cat confcache >$cache_file + else + { $as_echo "$as_me:${as_lineno-$LINENO}: not updating unwritable cache $cache_file" >&5 +$as_echo "$as_me: not updating unwritable cache $cache_file" >&6;} + fi +fi +rm -f confcache + +test "x$prefix" = xNONE && prefix=$ac_default_prefix +# Let make expand exec_prefix. +test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' + +DEFS=-DHAVE_CONFIG_H + +ac_libobjs= +ac_ltlibobjs= +for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue + # 1. Remove the extension, and $U if already installed. + ac_script='s/\$U\././;s/\.o$//;s/\.obj$//' + ac_i=`$as_echo "$ac_i" | sed "$ac_script"` + # 2. Prepend LIBOBJDIR. When used with automake>=1.10 LIBOBJDIR + # will be set to the directory where LIBOBJS objects are built. + as_fn_append ac_libobjs " \${LIBOBJDIR}$ac_i\$U.$ac_objext" + as_fn_append ac_ltlibobjs " \${LIBOBJDIR}$ac_i"'$U.lo' +done +LIBOBJS=$ac_libobjs + +LTLIBOBJS=$ac_ltlibobjs + + + if test -n "$EXEEXT"; then + am__EXEEXT_TRUE= + am__EXEEXT_FALSE='#' +else + am__EXEEXT_TRUE='#' + am__EXEEXT_FALSE= +fi + +if test -z "${MAINTAINER_MODE_TRUE}" && test -z "${MAINTAINER_MODE_FALSE}"; then + as_fn_error "conditional \"MAINTAINER_MODE\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${AMDEP_TRUE}" && test -z "${AMDEP_FALSE}"; then + as_fn_error "conditional \"AMDEP\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${am__fastdepCC_TRUE}" && test -z "${am__fastdepCC_FALSE}"; then + as_fn_error "conditional \"am__fastdepCC\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${HAVE_LD_VERSION_SCRIPT_TRUE}" && test -z "${HAVE_LD_VERSION_SCRIPT_FALSE}"; then + as_fn_error "conditional \"HAVE_LD_VERSION_SCRIPT\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi + +: ${CONFIG_STATUS=./config.status} +ac_write_fail=0 +ac_clean_files_save=$ac_clean_files +ac_clean_files="$ac_clean_files $CONFIG_STATUS" +{ $as_echo "$as_me:${as_lineno-$LINENO}: creating $CONFIG_STATUS" >&5 +$as_echo "$as_me: creating $CONFIG_STATUS" >&6;} +as_write_fail=0 +cat >$CONFIG_STATUS <<_ASEOF || as_write_fail=1 +#! $SHELL +# Generated by $as_me. +# Run this file to recreate the current configuration. +# Compiler output produced by configure, useful for debugging +# configure, is in config.log if it exists. + +debug=false +ac_cs_recheck=false +ac_cs_silent=false + +SHELL=\${CONFIG_SHELL-$SHELL} +export SHELL +_ASEOF +cat >>$CONFIG_STATUS <<\_ASEOF || as_write_fail=1 +## -------------------- ## +## M4sh Initialization. ## +## -------------------- ## + +# Be more Bourne compatible +DUALCASE=1; export DUALCASE # for MKS sh +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then : + emulate sh + NULLCMD=: + # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in #( + *posix*) : + set -o posix ;; #( + *) : + ;; +esac +fi + + +as_nl=' +' +export as_nl +# Printing a long string crashes Solaris 7 /usr/bin/printf. +as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' +as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo +as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo +# Prefer a ksh shell builtin over an external printf program on Solaris, +# but without wasting forks for bash or zsh. +if test -z "$BASH_VERSION$ZSH_VERSION" \ + && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then + as_echo='print -r --' + as_echo_n='print -rn --' +elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then + as_echo='printf %s\n' + as_echo_n='printf %s' +else + if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then + as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"' + as_echo_n='/usr/ucb/echo -n' + else + as_echo_body='eval expr "X$1" : "X\\(.*\\)"' + as_echo_n_body='eval + arg=$1; + case $arg in #( + *"$as_nl"*) + expr "X$arg" : "X\\(.*\\)$as_nl"; + arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;; + esac; + expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl" + ' + export as_echo_n_body + as_echo_n='sh -c $as_echo_n_body as_echo' + fi + export as_echo_body + as_echo='sh -c $as_echo_body as_echo' +fi + +# The user is always right. +if test "${PATH_SEPARATOR+set}" != set; then + PATH_SEPARATOR=: + (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { + (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || + PATH_SEPARATOR=';' + } +fi + + +# IFS +# We need space, tab and new line, in precisely that order. Quoting is +# there to prevent editors from complaining about space-tab. +# (If _AS_PATH_WALK were called with IFS unset, it would disable word +# splitting by setting IFS to empty value.) +IFS=" "" $as_nl" + +# Find who we are. Look in the path if we contain no directory separator. +case $0 in #(( + *[\\/]* ) as_myself=$0 ;; + *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break + done +IFS=$as_save_IFS + + ;; +esac +# We did not find ourselves, most probably we were run as `sh COMMAND' +# in which case we are not to be found in the path. +if test "x$as_myself" = x; then + as_myself=$0 +fi +if test ! -f "$as_myself"; then + $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 + exit 1 +fi + +# Unset variables that we do not need and which cause bugs (e.g. in +# pre-3.0 UWIN ksh). But do not cause bugs in bash 2.01; the "|| exit 1" +# suppresses any "Segmentation fault" message there. '((' could +# trigger a bug in pdksh 5.2.14. +for as_var in BASH_ENV ENV MAIL MAILPATH +do eval test x\${$as_var+set} = xset \ + && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : +done +PS1='$ ' +PS2='> ' +PS4='+ ' + +# NLS nuisances. +LC_ALL=C +export LC_ALL +LANGUAGE=C +export LANGUAGE + +# CDPATH. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + + +# as_fn_error ERROR [LINENO LOG_FD] +# --------------------------------- +# Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are +# provided, also output the error to LOG_FD, referencing LINENO. Then exit the +# script with status $?, using 1 if that was 0. +as_fn_error () +{ + as_status=$?; test $as_status -eq 0 && as_status=1 + if test "$3"; then + as_lineno=${as_lineno-"$2"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + $as_echo "$as_me:${as_lineno-$LINENO}: error: $1" >&$3 + fi + $as_echo "$as_me: error: $1" >&2 + as_fn_exit $as_status +} # as_fn_error + + +# as_fn_set_status STATUS +# ----------------------- +# Set $? to STATUS, without forking. +as_fn_set_status () +{ + return $1 +} # as_fn_set_status + +# as_fn_exit STATUS +# ----------------- +# Exit the shell with STATUS, even in a "trap 0" or "set -e" context. +as_fn_exit () +{ + set +e + as_fn_set_status $1 + exit $1 +} # as_fn_exit + +# as_fn_unset VAR +# --------------- +# Portably unset VAR. +as_fn_unset () +{ + { eval $1=; unset $1;} +} +as_unset=as_fn_unset +# as_fn_append VAR VALUE +# ---------------------- +# Append the text in VALUE to the end of the definition contained in VAR. Take +# advantage of any shell optimizations that allow amortized linear growth over +# repeated appends, instead of the typical quadratic growth present in naive +# implementations. +if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then : + eval 'as_fn_append () + { + eval $1+=\$2 + }' +else + as_fn_append () + { + eval $1=\$$1\$2 + } +fi # as_fn_append + +# as_fn_arith ARG... +# ------------------ +# Perform arithmetic evaluation on the ARGs, and store the result in the +# global $as_val. Take advantage of shells that can avoid forks. The arguments +# must be portable across $(()) and expr. +if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then : + eval 'as_fn_arith () + { + as_val=$(( $* )) + }' +else + as_fn_arith () + { + as_val=`expr "$@" || test $? -eq 1` + } +fi # as_fn_arith + + +if expr a : '\(a\)' >/dev/null 2>&1 && + test "X`expr 00001 : '.*\(...\)'`" = X001; then + as_expr=expr +else + as_expr=false +fi + +if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then + as_basename=basename +else + as_basename=false +fi + +if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then + as_dirname=dirname +else + as_dirname=false +fi + +as_me=`$as_basename -- "$0" || +$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ + X"$0" : 'X\(//\)$' \| \ + X"$0" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X/"$0" | + sed '/^.*\/\([^/][^/]*\)\/*$/{ + s//\1/ + q + } + /^X\/\(\/\/\)$/{ + s//\1/ + q + } + /^X\/\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + +# Avoid depending upon Character Ranges. +as_cr_letters='abcdefghijklmnopqrstuvwxyz' +as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' +as_cr_Letters=$as_cr_letters$as_cr_LETTERS +as_cr_digits='0123456789' +as_cr_alnum=$as_cr_Letters$as_cr_digits + +ECHO_C= ECHO_N= ECHO_T= +case `echo -n x` in #((((( +-n*) + case `echo 'xy\c'` in + *c*) ECHO_T=' ';; # ECHO_T is single tab character. + xy) ECHO_C='\c';; + *) echo `echo ksh88 bug on AIX 6.1` > /dev/null + ECHO_T=' ';; + esac;; +*) + ECHO_N='-n';; +esac + +rm -f conf$$ conf$$.exe conf$$.file +if test -d conf$$.dir; then + rm -f conf$$.dir/conf$$.file +else + rm -f conf$$.dir + mkdir conf$$.dir 2>/dev/null +fi +if (echo >conf$$.file) 2>/dev/null; then + if ln -s conf$$.file conf$$ 2>/dev/null; then + as_ln_s='ln -s' + # ... but there are two gotchas: + # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. + # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. + # In both cases, we have to default to `cp -p'. + ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || + as_ln_s='cp -p' + elif ln conf$$.file conf$$ 2>/dev/null; then + as_ln_s=ln + else + as_ln_s='cp -p' + fi +else + as_ln_s='cp -p' +fi +rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file +rmdir conf$$.dir 2>/dev/null + + +# as_fn_mkdir_p +# ------------- +# Create "$as_dir" as a directory, including parents if necessary. +as_fn_mkdir_p () +{ + + case $as_dir in #( + -*) as_dir=./$as_dir;; + esac + test -d "$as_dir" || eval $as_mkdir_p || { + as_dirs= + while :; do + case $as_dir in #( + *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( + *) as_qdir=$as_dir;; + esac + as_dirs="'$as_qdir' $as_dirs" + as_dir=`$as_dirname -- "$as_dir" || +$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$as_dir" : 'X\(//\)[^/]' \| \ + X"$as_dir" : 'X\(//\)$' \| \ + X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X"$as_dir" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + test -d "$as_dir" && break + done + test -z "$as_dirs" || eval "mkdir $as_dirs" + } || test -d "$as_dir" || as_fn_error "cannot create directory $as_dir" + + +} # as_fn_mkdir_p +if mkdir -p . 2>/dev/null; then + as_mkdir_p='mkdir -p "$as_dir"' +else + test -d ./-p && rmdir ./-p + as_mkdir_p=false +fi + +if test -x / >/dev/null 2>&1; then + as_test_x='test -x' +else + if ls -dL / >/dev/null 2>&1; then + as_ls_L_option=L + else + as_ls_L_option= + fi + as_test_x=' + eval sh -c '\'' + if test -d "$1"; then + test -d "$1/."; + else + case $1 in #( + -*)set "./$1";; + esac; + case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in #(( + ???[sx]*):;;*)false;;esac;fi + '\'' sh + ' +fi +as_executable_p=$as_test_x + +# Sed expression to map a string onto a valid CPP name. +as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" + +# Sed expression to map a string onto a valid variable name. +as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" + + +exec 6>&1 +## ----------------------------------- ## +## Main body of $CONFIG_STATUS script. ## +## ----------------------------------- ## +_ASEOF +test $as_write_fail = 0 && chmod +x $CONFIG_STATUS || ac_write_fail=1 + +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +# Save the log message, to keep $0 and so on meaningful, and to +# report actual input values of CONFIG_FILES etc. instead of their +# values after options handling. +ac_log=" +This file was extended by libpng $as_me 1.2.46, which was +generated by GNU Autoconf 2.65. Invocation command line was + + CONFIG_FILES = $CONFIG_FILES + CONFIG_HEADERS = $CONFIG_HEADERS + CONFIG_LINKS = $CONFIG_LINKS + CONFIG_COMMANDS = $CONFIG_COMMANDS + $ $0 $@ + +on `(hostname || uname -n) 2>/dev/null | sed 1q` +" + +_ACEOF + +case $ac_config_files in *" +"*) set x $ac_config_files; shift; ac_config_files=$*;; +esac + +case $ac_config_headers in *" +"*) set x $ac_config_headers; shift; ac_config_headers=$*;; +esac + + +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +# Files that config.status was made for. +config_files="$ac_config_files" +config_headers="$ac_config_headers" +config_commands="$ac_config_commands" + +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +ac_cs_usage="\ +\`$as_me' instantiates files and other configuration actions +from templates according to the current configuration. Unless the files +and actions are specified as TAGs, all are instantiated by default. + +Usage: $0 [OPTION]... [TAG]... + + -h, --help print this help, then exit + -V, --version print version number and configuration settings, then exit + --config print configuration, then exit + -q, --quiet, --silent + do not print progress messages + -d, --debug don't remove temporary files + --recheck update $as_me by reconfiguring in the same conditions + --file=FILE[:TEMPLATE] + instantiate the configuration file FILE + --header=FILE[:TEMPLATE] + instantiate the configuration header FILE + +Configuration files: +$config_files + +Configuration headers: +$config_headers + +Configuration commands: +$config_commands + +Report bugs to ." + +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" +ac_cs_version="\\ +libpng config.status 1.2.46 +configured by $0, generated by GNU Autoconf 2.65, + with options \\"\$ac_cs_config\\" + +Copyright (C) 2009 Free Software Foundation, Inc. +This config.status script is free software; the Free Software Foundation +gives unlimited permission to copy, distribute and modify it." + +ac_pwd='$ac_pwd' +srcdir='$srcdir' +INSTALL='$INSTALL' +MKDIR_P='$MKDIR_P' +AWK='$AWK' +test -n "\$AWK" || AWK=awk +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +# The default lists apply if the user does not specify any file. +ac_need_defaults=: +while test $# != 0 +do + case $1 in + --*=*) + ac_option=`expr "X$1" : 'X\([^=]*\)='` + ac_optarg=`expr "X$1" : 'X[^=]*=\(.*\)'` + ac_shift=: + ;; + *) + ac_option=$1 + ac_optarg=$2 + ac_shift=shift + ;; + esac + + case $ac_option in + # Handling of the options. + -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r) + ac_cs_recheck=: ;; + --version | --versio | --versi | --vers | --ver | --ve | --v | -V ) + $as_echo "$ac_cs_version"; exit ;; + --config | --confi | --conf | --con | --co | --c ) + $as_echo "$ac_cs_config"; exit ;; + --debug | --debu | --deb | --de | --d | -d ) + debug=: ;; + --file | --fil | --fi | --f ) + $ac_shift + case $ac_optarg in + *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;; + esac + as_fn_append CONFIG_FILES " '$ac_optarg'" + ac_need_defaults=false;; + --header | --heade | --head | --hea ) + $ac_shift + case $ac_optarg in + *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;; + esac + as_fn_append CONFIG_HEADERS " '$ac_optarg'" + ac_need_defaults=false;; + --he | --h) + # Conflict between --help and --header + as_fn_error "ambiguous option: \`$1' +Try \`$0 --help' for more information.";; + --help | --hel | -h ) + $as_echo "$ac_cs_usage"; exit ;; + -q | -quiet | --quiet | --quie | --qui | --qu | --q \ + | -silent | --silent | --silen | --sile | --sil | --si | --s) + ac_cs_silent=: ;; + + # This is an error. + -*) as_fn_error "unrecognized option: \`$1' +Try \`$0 --help' for more information." ;; + + *) as_fn_append ac_config_targets " $1" + ac_need_defaults=false ;; + + esac + shift +done + +ac_configure_extra_args= + +if $ac_cs_silent; then + exec 6>/dev/null + ac_configure_extra_args="$ac_configure_extra_args --silent" +fi + +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +if \$ac_cs_recheck; then + set X '$SHELL' '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion + shift + \$as_echo "running CONFIG_SHELL=$SHELL \$*" >&6 + CONFIG_SHELL='$SHELL' + export CONFIG_SHELL + exec "\$@" +fi + +_ACEOF +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +exec 5>>config.log +{ + echo + sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX +## Running $as_me. ## +_ASBOX + $as_echo "$ac_log" +} >&5 + +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +# +# INIT-COMMANDS +# +AMDEP_TRUE="$AMDEP_TRUE" ac_aux_dir="$ac_aux_dir" + + +# The HP-UX ksh and POSIX shell print the target directory to stdout +# if CDPATH is set. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + +sed_quote_subst='$sed_quote_subst' +double_quote_subst='$double_quote_subst' +delay_variable_subst='$delay_variable_subst' +SED='`$ECHO "X$SED" | $Xsed -e "$delay_single_quote_subst"`' +Xsed='`$ECHO "X$Xsed" | $Xsed -e "$delay_single_quote_subst"`' +GREP='`$ECHO "X$GREP" | $Xsed -e "$delay_single_quote_subst"`' +EGREP='`$ECHO "X$EGREP" | $Xsed -e "$delay_single_quote_subst"`' +FGREP='`$ECHO "X$FGREP" | $Xsed -e "$delay_single_quote_subst"`' +LD='`$ECHO "X$LD" | $Xsed -e "$delay_single_quote_subst"`' +AS='`$ECHO "X$AS" | $Xsed -e "$delay_single_quote_subst"`' +DLLTOOL='`$ECHO "X$DLLTOOL" | $Xsed -e "$delay_single_quote_subst"`' +OBJDUMP='`$ECHO "X$OBJDUMP" | $Xsed -e "$delay_single_quote_subst"`' +macro_version='`$ECHO "X$macro_version" | $Xsed -e "$delay_single_quote_subst"`' +macro_revision='`$ECHO "X$macro_revision" | $Xsed -e "$delay_single_quote_subst"`' +enable_shared='`$ECHO "X$enable_shared" | $Xsed -e "$delay_single_quote_subst"`' +enable_static='`$ECHO "X$enable_static" | $Xsed -e "$delay_single_quote_subst"`' +pic_mode='`$ECHO "X$pic_mode" | $Xsed -e "$delay_single_quote_subst"`' +enable_fast_install='`$ECHO "X$enable_fast_install" | $Xsed -e "$delay_single_quote_subst"`' +host_alias='`$ECHO "X$host_alias" | $Xsed -e "$delay_single_quote_subst"`' +host='`$ECHO "X$host" | $Xsed -e "$delay_single_quote_subst"`' +host_os='`$ECHO "X$host_os" | $Xsed -e "$delay_single_quote_subst"`' +build_alias='`$ECHO "X$build_alias" | $Xsed -e "$delay_single_quote_subst"`' +build='`$ECHO "X$build" | $Xsed -e "$delay_single_quote_subst"`' +build_os='`$ECHO "X$build_os" | $Xsed -e "$delay_single_quote_subst"`' +NM='`$ECHO "X$NM" | $Xsed -e "$delay_single_quote_subst"`' +LN_S='`$ECHO "X$LN_S" | $Xsed -e "$delay_single_quote_subst"`' +max_cmd_len='`$ECHO "X$max_cmd_len" | $Xsed -e "$delay_single_quote_subst"`' +ac_objext='`$ECHO "X$ac_objext" | $Xsed -e "$delay_single_quote_subst"`' +exeext='`$ECHO "X$exeext" | $Xsed -e "$delay_single_quote_subst"`' +lt_unset='`$ECHO "X$lt_unset" | $Xsed -e "$delay_single_quote_subst"`' +lt_SP2NL='`$ECHO "X$lt_SP2NL" | $Xsed -e "$delay_single_quote_subst"`' +lt_NL2SP='`$ECHO "X$lt_NL2SP" | $Xsed -e "$delay_single_quote_subst"`' +reload_flag='`$ECHO "X$reload_flag" | $Xsed -e "$delay_single_quote_subst"`' +reload_cmds='`$ECHO "X$reload_cmds" | $Xsed -e "$delay_single_quote_subst"`' +deplibs_check_method='`$ECHO "X$deplibs_check_method" | $Xsed -e "$delay_single_quote_subst"`' +file_magic_cmd='`$ECHO "X$file_magic_cmd" | $Xsed -e "$delay_single_quote_subst"`' +AR='`$ECHO "X$AR" | $Xsed -e "$delay_single_quote_subst"`' +AR_FLAGS='`$ECHO "X$AR_FLAGS" | $Xsed -e "$delay_single_quote_subst"`' +STRIP='`$ECHO "X$STRIP" | $Xsed -e "$delay_single_quote_subst"`' +RANLIB='`$ECHO "X$RANLIB" | $Xsed -e "$delay_single_quote_subst"`' +old_postinstall_cmds='`$ECHO "X$old_postinstall_cmds" | $Xsed -e "$delay_single_quote_subst"`' +old_postuninstall_cmds='`$ECHO "X$old_postuninstall_cmds" | $Xsed -e "$delay_single_quote_subst"`' +old_archive_cmds='`$ECHO "X$old_archive_cmds" | $Xsed -e "$delay_single_quote_subst"`' +CC='`$ECHO "X$CC" | $Xsed -e "$delay_single_quote_subst"`' +CFLAGS='`$ECHO "X$CFLAGS" | $Xsed -e "$delay_single_quote_subst"`' +compiler='`$ECHO "X$compiler" | $Xsed -e "$delay_single_quote_subst"`' +GCC='`$ECHO "X$GCC" | $Xsed -e "$delay_single_quote_subst"`' +lt_cv_sys_global_symbol_pipe='`$ECHO "X$lt_cv_sys_global_symbol_pipe" | $Xsed -e "$delay_single_quote_subst"`' +lt_cv_sys_global_symbol_to_cdecl='`$ECHO "X$lt_cv_sys_global_symbol_to_cdecl" | $Xsed -e "$delay_single_quote_subst"`' +lt_cv_sys_global_symbol_to_c_name_address='`$ECHO "X$lt_cv_sys_global_symbol_to_c_name_address" | $Xsed -e "$delay_single_quote_subst"`' +lt_cv_sys_global_symbol_to_c_name_address_lib_prefix='`$ECHO "X$lt_cv_sys_global_symbol_to_c_name_address_lib_prefix" | $Xsed -e "$delay_single_quote_subst"`' +objdir='`$ECHO "X$objdir" | $Xsed -e "$delay_single_quote_subst"`' +SHELL='`$ECHO "X$SHELL" | $Xsed -e "$delay_single_quote_subst"`' +ECHO='`$ECHO "X$ECHO" | $Xsed -e "$delay_single_quote_subst"`' +MAGIC_CMD='`$ECHO "X$MAGIC_CMD" | $Xsed -e "$delay_single_quote_subst"`' +lt_prog_compiler_no_builtin_flag='`$ECHO "X$lt_prog_compiler_no_builtin_flag" | $Xsed -e "$delay_single_quote_subst"`' +lt_prog_compiler_wl='`$ECHO "X$lt_prog_compiler_wl" | $Xsed -e "$delay_single_quote_subst"`' +lt_prog_compiler_pic='`$ECHO "X$lt_prog_compiler_pic" | $Xsed -e "$delay_single_quote_subst"`' +lt_prog_compiler_static='`$ECHO "X$lt_prog_compiler_static" | $Xsed -e "$delay_single_quote_subst"`' +lt_cv_prog_compiler_c_o='`$ECHO "X$lt_cv_prog_compiler_c_o" | $Xsed -e "$delay_single_quote_subst"`' +need_locks='`$ECHO "X$need_locks" | $Xsed -e "$delay_single_quote_subst"`' +DSYMUTIL='`$ECHO "X$DSYMUTIL" | $Xsed -e "$delay_single_quote_subst"`' +NMEDIT='`$ECHO "X$NMEDIT" | $Xsed -e "$delay_single_quote_subst"`' +LIPO='`$ECHO "X$LIPO" | $Xsed -e "$delay_single_quote_subst"`' +OTOOL='`$ECHO "X$OTOOL" | $Xsed -e "$delay_single_quote_subst"`' +OTOOL64='`$ECHO "X$OTOOL64" | $Xsed -e "$delay_single_quote_subst"`' +libext='`$ECHO "X$libext" | $Xsed -e "$delay_single_quote_subst"`' +shrext_cmds='`$ECHO "X$shrext_cmds" | $Xsed -e "$delay_single_quote_subst"`' +extract_expsyms_cmds='`$ECHO "X$extract_expsyms_cmds" | $Xsed -e "$delay_single_quote_subst"`' +archive_cmds_need_lc='`$ECHO "X$archive_cmds_need_lc" | $Xsed -e "$delay_single_quote_subst"`' +enable_shared_with_static_runtimes='`$ECHO "X$enable_shared_with_static_runtimes" | $Xsed -e "$delay_single_quote_subst"`' +export_dynamic_flag_spec='`$ECHO "X$export_dynamic_flag_spec" | $Xsed -e "$delay_single_quote_subst"`' +whole_archive_flag_spec='`$ECHO "X$whole_archive_flag_spec" | $Xsed -e "$delay_single_quote_subst"`' +compiler_needs_object='`$ECHO "X$compiler_needs_object" | $Xsed -e "$delay_single_quote_subst"`' +old_archive_from_new_cmds='`$ECHO "X$old_archive_from_new_cmds" | $Xsed -e "$delay_single_quote_subst"`' +old_archive_from_expsyms_cmds='`$ECHO "X$old_archive_from_expsyms_cmds" | $Xsed -e "$delay_single_quote_subst"`' +archive_cmds='`$ECHO "X$archive_cmds" | $Xsed -e "$delay_single_quote_subst"`' +archive_expsym_cmds='`$ECHO "X$archive_expsym_cmds" | $Xsed -e "$delay_single_quote_subst"`' +module_cmds='`$ECHO "X$module_cmds" | $Xsed -e "$delay_single_quote_subst"`' +module_expsym_cmds='`$ECHO "X$module_expsym_cmds" | $Xsed -e "$delay_single_quote_subst"`' +with_gnu_ld='`$ECHO "X$with_gnu_ld" | $Xsed -e "$delay_single_quote_subst"`' +allow_undefined_flag='`$ECHO "X$allow_undefined_flag" | $Xsed -e "$delay_single_quote_subst"`' +no_undefined_flag='`$ECHO "X$no_undefined_flag" | $Xsed -e "$delay_single_quote_subst"`' +hardcode_libdir_flag_spec='`$ECHO "X$hardcode_libdir_flag_spec" | $Xsed -e "$delay_single_quote_subst"`' +hardcode_libdir_flag_spec_ld='`$ECHO "X$hardcode_libdir_flag_spec_ld" | $Xsed -e "$delay_single_quote_subst"`' +hardcode_libdir_separator='`$ECHO "X$hardcode_libdir_separator" | $Xsed -e "$delay_single_quote_subst"`' +hardcode_direct='`$ECHO "X$hardcode_direct" | $Xsed -e "$delay_single_quote_subst"`' +hardcode_direct_absolute='`$ECHO "X$hardcode_direct_absolute" | $Xsed -e "$delay_single_quote_subst"`' +hardcode_minus_L='`$ECHO "X$hardcode_minus_L" | $Xsed -e "$delay_single_quote_subst"`' +hardcode_shlibpath_var='`$ECHO "X$hardcode_shlibpath_var" | $Xsed -e "$delay_single_quote_subst"`' +hardcode_automatic='`$ECHO "X$hardcode_automatic" | $Xsed -e "$delay_single_quote_subst"`' +inherit_rpath='`$ECHO "X$inherit_rpath" | $Xsed -e "$delay_single_quote_subst"`' +link_all_deplibs='`$ECHO "X$link_all_deplibs" | $Xsed -e "$delay_single_quote_subst"`' +fix_srcfile_path='`$ECHO "X$fix_srcfile_path" | $Xsed -e "$delay_single_quote_subst"`' +always_export_symbols='`$ECHO "X$always_export_symbols" | $Xsed -e "$delay_single_quote_subst"`' +export_symbols_cmds='`$ECHO "X$export_symbols_cmds" | $Xsed -e "$delay_single_quote_subst"`' +exclude_expsyms='`$ECHO "X$exclude_expsyms" | $Xsed -e "$delay_single_quote_subst"`' +include_expsyms='`$ECHO "X$include_expsyms" | $Xsed -e "$delay_single_quote_subst"`' +prelink_cmds='`$ECHO "X$prelink_cmds" | $Xsed -e "$delay_single_quote_subst"`' +file_list_spec='`$ECHO "X$file_list_spec" | $Xsed -e "$delay_single_quote_subst"`' +variables_saved_for_relink='`$ECHO "X$variables_saved_for_relink" | $Xsed -e "$delay_single_quote_subst"`' +need_lib_prefix='`$ECHO "X$need_lib_prefix" | $Xsed -e "$delay_single_quote_subst"`' +need_version='`$ECHO "X$need_version" | $Xsed -e "$delay_single_quote_subst"`' +version_type='`$ECHO "X$version_type" | $Xsed -e "$delay_single_quote_subst"`' +runpath_var='`$ECHO "X$runpath_var" | $Xsed -e "$delay_single_quote_subst"`' +shlibpath_var='`$ECHO "X$shlibpath_var" | $Xsed -e "$delay_single_quote_subst"`' +shlibpath_overrides_runpath='`$ECHO "X$shlibpath_overrides_runpath" | $Xsed -e "$delay_single_quote_subst"`' +libname_spec='`$ECHO "X$libname_spec" | $Xsed -e "$delay_single_quote_subst"`' +library_names_spec='`$ECHO "X$library_names_spec" | $Xsed -e "$delay_single_quote_subst"`' +soname_spec='`$ECHO "X$soname_spec" | $Xsed -e "$delay_single_quote_subst"`' +postinstall_cmds='`$ECHO "X$postinstall_cmds" | $Xsed -e "$delay_single_quote_subst"`' +postuninstall_cmds='`$ECHO "X$postuninstall_cmds" | $Xsed -e "$delay_single_quote_subst"`' +finish_cmds='`$ECHO "X$finish_cmds" | $Xsed -e "$delay_single_quote_subst"`' +finish_eval='`$ECHO "X$finish_eval" | $Xsed -e "$delay_single_quote_subst"`' +hardcode_into_libs='`$ECHO "X$hardcode_into_libs" | $Xsed -e "$delay_single_quote_subst"`' +sys_lib_search_path_spec='`$ECHO "X$sys_lib_search_path_spec" | $Xsed -e "$delay_single_quote_subst"`' +sys_lib_dlsearch_path_spec='`$ECHO "X$sys_lib_dlsearch_path_spec" | $Xsed -e "$delay_single_quote_subst"`' +hardcode_action='`$ECHO "X$hardcode_action" | $Xsed -e "$delay_single_quote_subst"`' +enable_dlopen='`$ECHO "X$enable_dlopen" | $Xsed -e "$delay_single_quote_subst"`' +enable_dlopen_self='`$ECHO "X$enable_dlopen_self" | $Xsed -e "$delay_single_quote_subst"`' +enable_dlopen_self_static='`$ECHO "X$enable_dlopen_self_static" | $Xsed -e "$delay_single_quote_subst"`' +old_striplib='`$ECHO "X$old_striplib" | $Xsed -e "$delay_single_quote_subst"`' +striplib='`$ECHO "X$striplib" | $Xsed -e "$delay_single_quote_subst"`' + +LTCC='$LTCC' +LTCFLAGS='$LTCFLAGS' +compiler='$compiler_DEFAULT' + +# Quote evaled strings. +for var in SED \ +GREP \ +EGREP \ +FGREP \ +LD \ +NM \ +LN_S \ +lt_SP2NL \ +lt_NL2SP \ +reload_flag \ +deplibs_check_method \ +file_magic_cmd \ +AR \ +AR_FLAGS \ +STRIP \ +RANLIB \ +CC \ +CFLAGS \ +compiler \ +lt_cv_sys_global_symbol_pipe \ +lt_cv_sys_global_symbol_to_cdecl \ +lt_cv_sys_global_symbol_to_c_name_address \ +lt_cv_sys_global_symbol_to_c_name_address_lib_prefix \ +SHELL \ +ECHO \ +lt_prog_compiler_no_builtin_flag \ +lt_prog_compiler_wl \ +lt_prog_compiler_pic \ +lt_prog_compiler_static \ +lt_cv_prog_compiler_c_o \ +need_locks \ +DSYMUTIL \ +NMEDIT \ +LIPO \ +OTOOL \ +OTOOL64 \ +shrext_cmds \ +export_dynamic_flag_spec \ +whole_archive_flag_spec \ +compiler_needs_object \ +with_gnu_ld \ +allow_undefined_flag \ +no_undefined_flag \ +hardcode_libdir_flag_spec \ +hardcode_libdir_flag_spec_ld \ +hardcode_libdir_separator \ +fix_srcfile_path \ +exclude_expsyms \ +include_expsyms \ +file_list_spec \ +variables_saved_for_relink \ +libname_spec \ +library_names_spec \ +soname_spec \ +finish_eval \ +old_striplib \ +striplib; do + case \`eval \\\\\$ECHO "X\\\\\$\$var"\` in + *[\\\\\\\`\\"\\\$]*) + eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"X\\\$\$var\\" | \\\$Xsed -e \\"\\\$sed_quote_subst\\"\\\`\\\\\\"" + ;; + *) + eval "lt_\$var=\\\\\\"\\\$\$var\\\\\\"" + ;; + esac +done + +# Double-quote double-evaled strings. +for var in reload_cmds \ +old_postinstall_cmds \ +old_postuninstall_cmds \ +old_archive_cmds \ +extract_expsyms_cmds \ +old_archive_from_new_cmds \ +old_archive_from_expsyms_cmds \ +archive_cmds \ +archive_expsym_cmds \ +module_cmds \ +module_expsym_cmds \ +export_symbols_cmds \ +prelink_cmds \ +postinstall_cmds \ +postuninstall_cmds \ +finish_cmds \ +sys_lib_search_path_spec \ +sys_lib_dlsearch_path_spec; do + case \`eval \\\\\$ECHO "X\\\\\$\$var"\` in + *[\\\\\\\`\\"\\\$]*) + eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"X\\\$\$var\\" | \\\$Xsed -e \\"\\\$double_quote_subst\\" -e \\"\\\$sed_quote_subst\\" -e \\"\\\$delay_variable_subst\\"\\\`\\\\\\"" + ;; + *) + eval "lt_\$var=\\\\\\"\\\$\$var\\\\\\"" + ;; + esac +done + +# Fix-up fallback echo if it was mangled by the above quoting rules. +case \$lt_ECHO in +*'\\\$0 --fallback-echo"') lt_ECHO=\`\$ECHO "X\$lt_ECHO" | \$Xsed -e 's/\\\\\\\\\\\\\\\$0 --fallback-echo"\$/\$0 --fallback-echo"/'\` + ;; +esac + +ac_aux_dir='$ac_aux_dir' +xsi_shell='$xsi_shell' +lt_shell_append='$lt_shell_append' + +# See if we are running on zsh, and set the options which allow our +# commands through without removal of \ escapes INIT. +if test -n "\${ZSH_VERSION+set}" ; then + setopt NO_GLOB_SUBST +fi + + + PACKAGE='$PACKAGE' + VERSION='$VERSION' + TIMESTAMP='$TIMESTAMP' + RM='$RM' + ofile='$ofile' + + + + +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 + +# Handling of arguments. +for ac_config_target in $ac_config_targets +do + case $ac_config_target in + "config.h") CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;; + "depfiles") CONFIG_COMMANDS="$CONFIG_COMMANDS depfiles" ;; + "libtool") CONFIG_COMMANDS="$CONFIG_COMMANDS libtool" ;; + "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;; + "libpng.pc") CONFIG_FILES="$CONFIG_FILES libpng.pc:scripts/libpng.pc-configure.in" ;; + "libpng-config") CONFIG_FILES="$CONFIG_FILES libpng-config:scripts/libpng-config.in" ;; + + *) as_fn_error "invalid argument: \`$ac_config_target'" "$LINENO" 5;; + esac +done + + +# If the user did not use the arguments to specify the items to instantiate, +# then the envvar interface is used. Set only those that are not. +# We use the long form for the default assignment because of an extremely +# bizarre bug on SunOS 4.1.3. +if $ac_need_defaults; then + test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files + test "${CONFIG_HEADERS+set}" = set || CONFIG_HEADERS=$config_headers + test "${CONFIG_COMMANDS+set}" = set || CONFIG_COMMANDS=$config_commands +fi + +# Have a temporary directory for convenience. Make it in the build tree +# simply because there is no reason against having it here, and in addition, +# creating and moving files from /tmp can sometimes cause problems. +# Hook for its removal unless debugging. +# Note that there is a small window in which the directory will not be cleaned: +# after its creation but before its name has been assigned to `$tmp'. +$debug || +{ + tmp= + trap 'exit_status=$? + { test -z "$tmp" || test ! -d "$tmp" || rm -fr "$tmp"; } && exit $exit_status +' 0 + trap 'as_fn_exit 1' 1 2 13 15 +} +# Create a (secure) tmp directory for tmp files. + +{ + tmp=`(umask 077 && mktemp -d "./confXXXXXX") 2>/dev/null` && + test -n "$tmp" && test -d "$tmp" +} || +{ + tmp=./conf$$-$RANDOM + (umask 077 && mkdir "$tmp") +} || as_fn_error "cannot create a temporary directory in ." "$LINENO" 5 + +# Set up the scripts for CONFIG_FILES section. +# No need to generate them if there are no CONFIG_FILES. +# This happens for instance with `./config.status config.h'. +if test -n "$CONFIG_FILES"; then + + +ac_cr=`echo X | tr X '\015'` +# On cygwin, bash can eat \r inside `` if the user requested igncr. +# But we know of no other shell where ac_cr would be empty at this +# point, so we can use a bashism as a fallback. +if test "x$ac_cr" = x; then + eval ac_cr=\$\'\\r\' +fi +ac_cs_awk_cr=`$AWK 'BEGIN { print "a\rb" }' /dev/null` +if test "$ac_cs_awk_cr" = "a${ac_cr}b"; then + ac_cs_awk_cr='\r' +else + ac_cs_awk_cr=$ac_cr +fi + +echo 'BEGIN {' >"$tmp/subs1.awk" && +_ACEOF + + +{ + echo "cat >conf$$subs.awk <<_ACEOF" && + echo "$ac_subst_vars" | sed 's/.*/&!$&$ac_delim/' && + echo "_ACEOF" +} >conf$$subs.sh || + as_fn_error "could not make $CONFIG_STATUS" "$LINENO" 5 +ac_delim_num=`echo "$ac_subst_vars" | grep -c '$'` +ac_delim='%!_!# ' +for ac_last_try in false false false false false :; do + . ./conf$$subs.sh || + as_fn_error "could not make $CONFIG_STATUS" "$LINENO" 5 + + ac_delim_n=`sed -n "s/.*$ac_delim\$/X/p" conf$$subs.awk | grep -c X` + if test $ac_delim_n = $ac_delim_num; then + break + elif $ac_last_try; then + as_fn_error "could not make $CONFIG_STATUS" "$LINENO" 5 + else + ac_delim="$ac_delim!$ac_delim _$ac_delim!! " + fi +done +rm -f conf$$subs.sh + +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +cat >>"\$tmp/subs1.awk" <<\\_ACAWK && +_ACEOF +sed -n ' +h +s/^/S["/; s/!.*/"]=/ +p +g +s/^[^!]*!// +:repl +t repl +s/'"$ac_delim"'$// +t delim +:nl +h +s/\(.\{148\}\)..*/\1/ +t more1 +s/["\\]/\\&/g; s/^/"/; s/$/\\n"\\/ +p +n +b repl +:more1 +s/["\\]/\\&/g; s/^/"/; s/$/"\\/ +p +g +s/.\{148\}// +t nl +:delim +h +s/\(.\{148\}\)..*/\1/ +t more2 +s/["\\]/\\&/g; s/^/"/; s/$/"/ +p +b +:more2 +s/["\\]/\\&/g; s/^/"/; s/$/"\\/ +p +g +s/.\{148\}// +t delim +' >$CONFIG_STATUS || ac_write_fail=1 +rm -f conf$$subs.awk +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +_ACAWK +cat >>"\$tmp/subs1.awk" <<_ACAWK && + for (key in S) S_is_set[key] = 1 + FS = "" + +} +{ + line = $ 0 + nfields = split(line, field, "@") + substed = 0 + len = length(field[1]) + for (i = 2; i < nfields; i++) { + key = field[i] + keylen = length(key) + if (S_is_set[key]) { + value = S[key] + line = substr(line, 1, len) "" value "" substr(line, len + keylen + 3) + len += length(value) + length(field[++i]) + substed = 1 + } else + len += 1 + keylen + } + + print line +} + +_ACAWK +_ACEOF +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +if sed "s/$ac_cr//" < /dev/null > /dev/null 2>&1; then + sed "s/$ac_cr\$//; s/$ac_cr/$ac_cs_awk_cr/g" +else + cat +fi < "$tmp/subs1.awk" > "$tmp/subs.awk" \ + || as_fn_error "could not setup config files machinery" "$LINENO" 5 +_ACEOF + +# VPATH may cause trouble with some makes, so we remove $(srcdir), +# ${srcdir} and @srcdir@ from VPATH if srcdir is ".", strip leading and +# trailing colons and then remove the whole line if VPATH becomes empty +# (actually we leave an empty line to preserve line numbers). +if test "x$srcdir" = x.; then + ac_vpsub='/^[ ]*VPATH[ ]*=/{ +s/:*\$(srcdir):*/:/ +s/:*\${srcdir}:*/:/ +s/:*@srcdir@:*/:/ +s/^\([^=]*=[ ]*\):*/\1/ +s/:*$// +s/^[^=]*=[ ]*$// +}' +fi + +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +fi # test -n "$CONFIG_FILES" + +# Set up the scripts for CONFIG_HEADERS section. +# No need to generate them if there are no CONFIG_HEADERS. +# This happens for instance with `./config.status Makefile'. +if test -n "$CONFIG_HEADERS"; then +cat >"$tmp/defines.awk" <<\_ACAWK || +BEGIN { +_ACEOF + +# Transform confdefs.h into an awk script `defines.awk', embedded as +# here-document in config.status, that substitutes the proper values into +# config.h.in to produce config.h. + +# Create a delimiter string that does not exist in confdefs.h, to ease +# handling of long lines. +ac_delim='%!_!# ' +for ac_last_try in false false :; do + ac_t=`sed -n "/$ac_delim/p" confdefs.h` + if test -z "$ac_t"; then + break + elif $ac_last_try; then + as_fn_error "could not make $CONFIG_HEADERS" "$LINENO" 5 + else + ac_delim="$ac_delim!$ac_delim _$ac_delim!! " + fi +done + +# For the awk script, D is an array of macro values keyed by name, +# likewise P contains macro parameters if any. Preserve backslash +# newline sequences. + +ac_word_re=[_$as_cr_Letters][_$as_cr_alnum]* +sed -n ' +s/.\{148\}/&'"$ac_delim"'/g +t rset +:rset +s/^[ ]*#[ ]*define[ ][ ]*/ / +t def +d +:def +s/\\$// +t bsnl +s/["\\]/\\&/g +s/^ \('"$ac_word_re"'\)\(([^()]*)\)[ ]*\(.*\)/P["\1"]="\2"\ +D["\1"]=" \3"/p +s/^ \('"$ac_word_re"'\)[ ]*\(.*\)/D["\1"]=" \2"/p +d +:bsnl +s/["\\]/\\&/g +s/^ \('"$ac_word_re"'\)\(([^()]*)\)[ ]*\(.*\)/P["\1"]="\2"\ +D["\1"]=" \3\\\\\\n"\\/p +t cont +s/^ \('"$ac_word_re"'\)[ ]*\(.*\)/D["\1"]=" \2\\\\\\n"\\/p +t cont +d +:cont +n +s/.\{148\}/&'"$ac_delim"'/g +t clear +:clear +s/\\$// +t bsnlc +s/["\\]/\\&/g; s/^/"/; s/$/"/p +d +:bsnlc +s/["\\]/\\&/g; s/^/"/; s/$/\\\\\\n"\\/p +b cont +' >$CONFIG_STATUS || ac_write_fail=1 + +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 + for (key in D) D_is_set[key] = 1 + FS = "" +} +/^[\t ]*#[\t ]*(define|undef)[\t ]+$ac_word_re([\t (]|\$)/ { + line = \$ 0 + split(line, arg, " ") + if (arg[1] == "#") { + defundef = arg[2] + mac1 = arg[3] + } else { + defundef = substr(arg[1], 2) + mac1 = arg[2] + } + split(mac1, mac2, "(") #) + macro = mac2[1] + prefix = substr(line, 1, index(line, defundef) - 1) + if (D_is_set[macro]) { + # Preserve the white space surrounding the "#". + print prefix "define", macro P[macro] D[macro] + next + } else { + # Replace #undef with comments. This is necessary, for example, + # in the case of _POSIX_SOURCE, which is predefined and required + # on some systems where configure will not decide to define it. + if (defundef == "undef") { + print "/*", prefix defundef, macro, "*/" + next + } + } +} +{ print } +_ACAWK +_ACEOF +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 + as_fn_error "could not setup config headers machinery" "$LINENO" 5 +fi # test -n "$CONFIG_HEADERS" + + +eval set X " :F $CONFIG_FILES :H $CONFIG_HEADERS :C $CONFIG_COMMANDS" +shift +for ac_tag +do + case $ac_tag in + :[FHLC]) ac_mode=$ac_tag; continue;; + esac + case $ac_mode$ac_tag in + :[FHL]*:*);; + :L* | :C*:*) as_fn_error "invalid tag \`$ac_tag'" "$LINENO" 5;; + :[FH]-) ac_tag=-:-;; + :[FH]*) ac_tag=$ac_tag:$ac_tag.in;; + esac + ac_save_IFS=$IFS + IFS=: + set x $ac_tag + IFS=$ac_save_IFS + shift + ac_file=$1 + shift + + case $ac_mode in + :L) ac_source=$1;; + :[FH]) + ac_file_inputs= + for ac_f + do + case $ac_f in + -) ac_f="$tmp/stdin";; + *) # Look for the file first in the build tree, then in the source tree + # (if the path is not absolute). The absolute path cannot be DOS-style, + # because $ac_f cannot contain `:'. + test -f "$ac_f" || + case $ac_f in + [\\/$]*) false;; + *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";; + esac || + as_fn_error "cannot find input file: \`$ac_f'" "$LINENO" 5;; + esac + case $ac_f in *\'*) ac_f=`$as_echo "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac + as_fn_append ac_file_inputs " '$ac_f'" + done + + # Let's still pretend it is `configure' which instantiates (i.e., don't + # use $as_me), people would be surprised to read: + # /* config.h. Generated by config.status. */ + configure_input='Generated from '` + $as_echo "$*" | sed 's|^[^:]*/||;s|:[^:]*/|, |g' + `' by configure.' + if test x"$ac_file" != x-; then + configure_input="$ac_file. $configure_input" + { $as_echo "$as_me:${as_lineno-$LINENO}: creating $ac_file" >&5 +$as_echo "$as_me: creating $ac_file" >&6;} + fi + # Neutralize special characters interpreted by sed in replacement strings. + case $configure_input in #( + *\&* | *\|* | *\\* ) + ac_sed_conf_input=`$as_echo "$configure_input" | + sed 's/[\\\\&|]/\\\\&/g'`;; #( + *) ac_sed_conf_input=$configure_input;; + esac + + case $ac_tag in + *:-:* | *:-) cat >"$tmp/stdin" \ + || as_fn_error "could not create $ac_file" "$LINENO" 5 ;; + esac + ;; + esac + + ac_dir=`$as_dirname -- "$ac_file" || +$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$ac_file" : 'X\(//\)[^/]' \| \ + X"$ac_file" : 'X\(//\)$' \| \ + X"$ac_file" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X"$ac_file" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + as_dir="$ac_dir"; as_fn_mkdir_p + ac_builddir=. + +case "$ac_dir" in +.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; +*) + ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'` + # A ".." for each directory in $ac_dir_suffix. + ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` + case $ac_top_builddir_sub in + "") ac_top_builddir_sub=. ac_top_build_prefix= ;; + *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; + esac ;; +esac +ac_abs_top_builddir=$ac_pwd +ac_abs_builddir=$ac_pwd$ac_dir_suffix +# for backward compatibility: +ac_top_builddir=$ac_top_build_prefix + +case $srcdir in + .) # We are building in place. + ac_srcdir=. + ac_top_srcdir=$ac_top_builddir_sub + ac_abs_top_srcdir=$ac_pwd ;; + [\\/]* | ?:[\\/]* ) # Absolute name. + ac_srcdir=$srcdir$ac_dir_suffix; + ac_top_srcdir=$srcdir + ac_abs_top_srcdir=$srcdir ;; + *) # Relative name. + ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix + ac_top_srcdir=$ac_top_build_prefix$srcdir + ac_abs_top_srcdir=$ac_pwd/$srcdir ;; +esac +ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix + + + case $ac_mode in + :F) + # + # CONFIG_FILE + # + + case $INSTALL in + [\\/$]* | ?:[\\/]* ) ac_INSTALL=$INSTALL ;; + *) ac_INSTALL=$ac_top_build_prefix$INSTALL ;; + esac + ac_MKDIR_P=$MKDIR_P + case $MKDIR_P in + [\\/$]* | ?:[\\/]* ) ;; + */*) ac_MKDIR_P=$ac_top_build_prefix$MKDIR_P ;; + esac +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +# If the template does not know about datarootdir, expand it. +# FIXME: This hack should be removed a few years after 2.60. +ac_datarootdir_hack=; ac_datarootdir_seen= +ac_sed_dataroot=' +/datarootdir/ { + p + q +} +/@datadir@/p +/@docdir@/p +/@infodir@/p +/@localedir@/p +/@mandir@/p' +case `eval "sed -n \"\$ac_sed_dataroot\" $ac_file_inputs"` in +*datarootdir*) ac_datarootdir_seen=yes;; +*@datadir@*|*@docdir@*|*@infodir@*|*@localedir@*|*@mandir@*) + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5 +$as_echo "$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&2;} +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 + ac_datarootdir_hack=' + s&@datadir@&$datadir&g + s&@docdir@&$docdir&g + s&@infodir@&$infodir&g + s&@localedir@&$localedir&g + s&@mandir@&$mandir&g + s&\\\${datarootdir}&$datarootdir&g' ;; +esac +_ACEOF + +# Neutralize VPATH when `$srcdir' = `.'. +# Shell code in configure.ac might set extrasub. +# FIXME: do we really want to maintain this feature? +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +ac_sed_extra="$ac_vpsub +$extrasub +_ACEOF +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +:t +/@[a-zA-Z_][a-zA-Z_0-9]*@/!b +s|@configure_input@|$ac_sed_conf_input|;t t +s&@top_builddir@&$ac_top_builddir_sub&;t t +s&@top_build_prefix@&$ac_top_build_prefix&;t t +s&@srcdir@&$ac_srcdir&;t t +s&@abs_srcdir@&$ac_abs_srcdir&;t t +s&@top_srcdir@&$ac_top_srcdir&;t t +s&@abs_top_srcdir@&$ac_abs_top_srcdir&;t t +s&@builddir@&$ac_builddir&;t t +s&@abs_builddir@&$ac_abs_builddir&;t t +s&@abs_top_builddir@&$ac_abs_top_builddir&;t t +s&@INSTALL@&$ac_INSTALL&;t t +s&@MKDIR_P@&$ac_MKDIR_P&;t t +$ac_datarootdir_hack +" +eval sed \"\$ac_sed_extra\" "$ac_file_inputs" | $AWK -f "$tmp/subs.awk" >$tmp/out \ + || as_fn_error "could not create $ac_file" "$LINENO" 5 + +test -z "$ac_datarootdir_hack$ac_datarootdir_seen" && + { ac_out=`sed -n '/\${datarootdir}/p' "$tmp/out"`; test -n "$ac_out"; } && + { ac_out=`sed -n '/^[ ]*datarootdir[ ]*:*=/p' "$tmp/out"`; test -z "$ac_out"; } && + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file contains a reference to the variable \`datarootdir' +which seems to be undefined. Please make sure it is defined." >&5 +$as_echo "$as_me: WARNING: $ac_file contains a reference to the variable \`datarootdir' +which seems to be undefined. Please make sure it is defined." >&2;} + + rm -f "$tmp/stdin" + case $ac_file in + -) cat "$tmp/out" && rm -f "$tmp/out";; + *) rm -f "$ac_file" && mv "$tmp/out" "$ac_file";; + esac \ + || as_fn_error "could not create $ac_file" "$LINENO" 5 + ;; + :H) + # + # CONFIG_HEADER + # + if test x"$ac_file" != x-; then + { + $as_echo "/* $configure_input */" \ + && eval '$AWK -f "$tmp/defines.awk"' "$ac_file_inputs" + } >"$tmp/config.h" \ + || as_fn_error "could not create $ac_file" "$LINENO" 5 + if diff "$ac_file" "$tmp/config.h" >/dev/null 2>&1; then + { $as_echo "$as_me:${as_lineno-$LINENO}: $ac_file is unchanged" >&5 +$as_echo "$as_me: $ac_file is unchanged" >&6;} + else + rm -f "$ac_file" + mv "$tmp/config.h" "$ac_file" \ + || as_fn_error "could not create $ac_file" "$LINENO" 5 + fi + else + $as_echo "/* $configure_input */" \ + && eval '$AWK -f "$tmp/defines.awk"' "$ac_file_inputs" \ + || as_fn_error "could not create -" "$LINENO" 5 + fi +# Compute "$ac_file"'s index in $config_headers. +_am_arg="$ac_file" +_am_stamp_count=1 +for _am_header in $config_headers :; do + case $_am_header in + $_am_arg | $_am_arg:* ) + break ;; + * ) + _am_stamp_count=`expr $_am_stamp_count + 1` ;; + esac +done +echo "timestamp for $_am_arg" >`$as_dirname -- "$_am_arg" || +$as_expr X"$_am_arg" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$_am_arg" : 'X\(//\)[^/]' \| \ + X"$_am_arg" : 'X\(//\)$' \| \ + X"$_am_arg" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X"$_am_arg" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'`/stamp-h$_am_stamp_count + ;; + + :C) { $as_echo "$as_me:${as_lineno-$LINENO}: executing $ac_file commands" >&5 +$as_echo "$as_me: executing $ac_file commands" >&6;} + ;; + esac + + + case $ac_file$ac_mode in + "depfiles":C) test x"$AMDEP_TRUE" != x"" || { + # Autoconf 2.62 quotes --file arguments for eval, but not when files + # are listed without --file. Let's play safe and only enable the eval + # if we detect the quoting. + case $CONFIG_FILES in + *\'*) eval set x "$CONFIG_FILES" ;; + *) set x $CONFIG_FILES ;; + esac + shift + for mf + do + # Strip MF so we end up with the name of the file. + mf=`echo "$mf" | sed -e 's/:.*$//'` + # Check whether this is an Automake generated Makefile or not. + # We used to match only the files named `Makefile.in', but + # some people rename them; so instead we look at the file content. + # Grep'ing the first line is not enough: some people post-process + # each Makefile.in and add a new line on top of each file to say so. + # Grep'ing the whole file is not good either: AIX grep has a line + # limit of 2048, but all sed's we know have understand at least 4000. + if sed -n 's,^#.*generated by automake.*,X,p' "$mf" | grep X >/dev/null 2>&1; then + dirpart=`$as_dirname -- "$mf" || +$as_expr X"$mf" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$mf" : 'X\(//\)[^/]' \| \ + X"$mf" : 'X\(//\)$' \| \ + X"$mf" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X"$mf" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + else + continue + fi + # Extract the definition of DEPDIR, am__include, and am__quote + # from the Makefile without running `make'. + DEPDIR=`sed -n 's/^DEPDIR = //p' < "$mf"` + test -z "$DEPDIR" && continue + am__include=`sed -n 's/^am__include = //p' < "$mf"` + test -z "am__include" && continue + am__quote=`sed -n 's/^am__quote = //p' < "$mf"` + # When using ansi2knr, U may be empty or an underscore; expand it + U=`sed -n 's/^U = //p' < "$mf"` + # Find all dependency output files, they are included files with + # $(DEPDIR) in their names. We invoke sed twice because it is the + # simplest approach to changing $(DEPDIR) to its actual value in the + # expansion. + for file in `sed -n " + s/^$am__include $am__quote\(.*(DEPDIR).*\)$am__quote"'$/\1/p' <"$mf" | \ + sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g' -e 's/\$U/'"$U"'/g'`; do + # Make sure the directory exists. + test -f "$dirpart/$file" && continue + fdir=`$as_dirname -- "$file" || +$as_expr X"$file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$file" : 'X\(//\)[^/]' \| \ + X"$file" : 'X\(//\)$' \| \ + X"$file" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X"$file" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + as_dir=$dirpart/$fdir; as_fn_mkdir_p + # echo "creating $dirpart/$file" + echo '# dummy' > "$dirpart/$file" + done + done +} + ;; + "libtool":C) + + # See if we are running on zsh, and set the options which allow our + # commands through without removal of \ escapes. + if test -n "${ZSH_VERSION+set}" ; then + setopt NO_GLOB_SUBST + fi + + cfgfile="${ofile}T" + trap "$RM \"$cfgfile\"; exit 1" 1 2 15 + $RM "$cfgfile" + + cat <<_LT_EOF >> "$cfgfile" +#! $SHELL + +# `$ECHO "$ofile" | sed 's%^.*/%%'` - Provide generalized library-building support services. +# Generated automatically by $as_me ($PACKAGE$TIMESTAMP) $VERSION +# Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`: +# NOTE: Changes made to this file will be lost: look at ltmain.sh. +# +# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, +# 2006, 2007, 2008 Free Software Foundation, Inc. +# Written by Gordon Matzigkeit, 1996 +# +# This file is part of GNU Libtool. +# +# GNU Libtool is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of +# the License, or (at your option) any later version. +# +# As a special exception to the GNU General Public License, +# if you distribute this file as part of a program or library that +# is built using GNU Libtool, you may include this file under the +# same distribution terms that you use for the rest of that program. +# +# GNU Libtool is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Libtool; see the file COPYING. If not, a copy +# can be downloaded from http://www.gnu.org/licenses/gpl.html, or +# obtained by writing to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + +# The names of the tagged configurations supported by this script. +available_tags="" + +# ### BEGIN LIBTOOL CONFIG + +# A sed program that does not truncate output. +SED=$lt_SED + +# Sed that helps us avoid accidentally triggering echo(1) options like -n. +Xsed="\$SED -e 1s/^X//" + +# A grep program that handles long lines. +GREP=$lt_GREP + +# An ERE matcher. +EGREP=$lt_EGREP + +# A literal string matcher. +FGREP=$lt_FGREP + +# Assembler program. +AS=$AS + +# DLL creation program. +DLLTOOL=$DLLTOOL + +# Object dumper program. +OBJDUMP=$OBJDUMP + +# Which release of libtool.m4 was used? +macro_version=$macro_version +macro_revision=$macro_revision + +# Whether or not to build shared libraries. +build_libtool_libs=$enable_shared + +# Whether or not to build static libraries. +build_old_libs=$enable_static + +# What type of objects to build. +pic_mode=$pic_mode + +# Whether or not to optimize for fast installation. +fast_install=$enable_fast_install + +# The host system. +host_alias=$host_alias +host=$host +host_os=$host_os + +# The build system. +build_alias=$build_alias +build=$build +build_os=$build_os + +# A BSD- or MS-compatible name lister. +NM=$lt_NM + +# Whether we need soft or hard links. +LN_S=$lt_LN_S + +# What is the maximum length of a command? +max_cmd_len=$max_cmd_len + +# Object file suffix (normally "o"). +objext=$ac_objext + +# Executable file suffix (normally ""). +exeext=$exeext + +# whether the shell understands "unset". +lt_unset=$lt_unset + +# turn spaces into newlines. +SP2NL=$lt_lt_SP2NL + +# turn newlines into spaces. +NL2SP=$lt_lt_NL2SP + +# How to create reloadable object files. +reload_flag=$lt_reload_flag +reload_cmds=$lt_reload_cmds + +# Method to check whether dependent libraries are shared objects. +deplibs_check_method=$lt_deplibs_check_method + +# Command to use when deplibs_check_method == "file_magic". +file_magic_cmd=$lt_file_magic_cmd + +# The archiver. +AR=$lt_AR +AR_FLAGS=$lt_AR_FLAGS + +# A symbol stripping program. +STRIP=$lt_STRIP + +# Commands used to install an old-style archive. +RANLIB=$lt_RANLIB +old_postinstall_cmds=$lt_old_postinstall_cmds +old_postuninstall_cmds=$lt_old_postuninstall_cmds + +# A C compiler. +LTCC=$lt_CC + +# LTCC compiler flags. +LTCFLAGS=$lt_CFLAGS + +# Take the output of nm and produce a listing of raw symbols and C names. +global_symbol_pipe=$lt_lt_cv_sys_global_symbol_pipe + +# Transform the output of nm in a proper C declaration. +global_symbol_to_cdecl=$lt_lt_cv_sys_global_symbol_to_cdecl + +# Transform the output of nm in a C name address pair. +global_symbol_to_c_name_address=$lt_lt_cv_sys_global_symbol_to_c_name_address + +# Transform the output of nm in a C name address pair when lib prefix is needed. +global_symbol_to_c_name_address_lib_prefix=$lt_lt_cv_sys_global_symbol_to_c_name_address_lib_prefix + +# The name of the directory that contains temporary libtool files. +objdir=$objdir + +# Shell to use when invoking shell scripts. +SHELL=$lt_SHELL + +# An echo program that does not interpret backslashes. +ECHO=$lt_ECHO + +# Used to examine libraries when file_magic_cmd begins with "file". +MAGIC_CMD=$MAGIC_CMD + +# Must we lock files when doing compilation? +need_locks=$lt_need_locks + +# Tool to manipulate archived DWARF debug symbol files on Mac OS X. +DSYMUTIL=$lt_DSYMUTIL + +# Tool to change global to local symbols on Mac OS X. +NMEDIT=$lt_NMEDIT + +# Tool to manipulate fat objects and archives on Mac OS X. +LIPO=$lt_LIPO + +# ldd/readelf like tool for Mach-O binaries on Mac OS X. +OTOOL=$lt_OTOOL + +# ldd/readelf like tool for 64 bit Mach-O binaries on Mac OS X 10.4. +OTOOL64=$lt_OTOOL64 + +# Old archive suffix (normally "a"). +libext=$libext + +# Shared library suffix (normally ".so"). +shrext_cmds=$lt_shrext_cmds + +# The commands to extract the exported symbol list from a shared archive. +extract_expsyms_cmds=$lt_extract_expsyms_cmds + +# Variables whose values should be saved in libtool wrapper scripts and +# restored at link time. +variables_saved_for_relink=$lt_variables_saved_for_relink + +# Do we need the "lib" prefix for modules? +need_lib_prefix=$need_lib_prefix + +# Do we need a version for libraries? +need_version=$need_version + +# Library versioning type. +version_type=$version_type + +# Shared library runtime path variable. +runpath_var=$runpath_var + +# Shared library path variable. +shlibpath_var=$shlibpath_var + +# Is shlibpath searched before the hard-coded library search path? +shlibpath_overrides_runpath=$shlibpath_overrides_runpath + +# Format of library name prefix. +libname_spec=$lt_libname_spec + +# List of archive names. First name is the real one, the rest are links. +# The last name is the one that the linker finds with -lNAME +library_names_spec=$lt_library_names_spec + +# The coded name of the library, if different from the real name. +soname_spec=$lt_soname_spec + +# Command to use after installation of a shared archive. +postinstall_cmds=$lt_postinstall_cmds + +# Command to use after uninstallation of a shared archive. +postuninstall_cmds=$lt_postuninstall_cmds + +# Commands used to finish a libtool library installation in a directory. +finish_cmds=$lt_finish_cmds + +# As "finish_cmds", except a single script fragment to be evaled but +# not shown. +finish_eval=$lt_finish_eval + +# Whether we should hardcode library paths into libraries. +hardcode_into_libs=$hardcode_into_libs + +# Compile-time system search path for libraries. +sys_lib_search_path_spec=$lt_sys_lib_search_path_spec + +# Run-time system search path for libraries. +sys_lib_dlsearch_path_spec=$lt_sys_lib_dlsearch_path_spec + +# Whether dlopen is supported. +dlopen_support=$enable_dlopen + +# Whether dlopen of programs is supported. +dlopen_self=$enable_dlopen_self + +# Whether dlopen of statically linked programs is supported. +dlopen_self_static=$enable_dlopen_self_static + +# Commands to strip libraries. +old_striplib=$lt_old_striplib +striplib=$lt_striplib + + +# The linker used to build libraries. +LD=$lt_LD + +# Commands used to build an old-style archive. +old_archive_cmds=$lt_old_archive_cmds + +# A language specific compiler. +CC=$lt_compiler + +# Is the compiler the GNU compiler? +with_gcc=$GCC + +# Compiler flag to turn off builtin functions. +no_builtin_flag=$lt_lt_prog_compiler_no_builtin_flag + +# How to pass a linker flag through the compiler. +wl=$lt_lt_prog_compiler_wl + +# Additional compiler flags for building library objects. +pic_flag=$lt_lt_prog_compiler_pic + +# Compiler flag to prevent dynamic linking. +link_static_flag=$lt_lt_prog_compiler_static + +# Does compiler simultaneously support -c and -o options? +compiler_c_o=$lt_lt_cv_prog_compiler_c_o + +# Whether or not to add -lc for building shared libraries. +build_libtool_need_lc=$archive_cmds_need_lc + +# Whether or not to disallow shared libs when runtime libs are static. +allow_libtool_libs_with_static_runtimes=$enable_shared_with_static_runtimes + +# Compiler flag to allow reflexive dlopens. +export_dynamic_flag_spec=$lt_export_dynamic_flag_spec + +# Compiler flag to generate shared objects directly from archives. +whole_archive_flag_spec=$lt_whole_archive_flag_spec + +# Whether the compiler copes with passing no objects directly. +compiler_needs_object=$lt_compiler_needs_object + +# Create an old-style archive from a shared archive. +old_archive_from_new_cmds=$lt_old_archive_from_new_cmds + +# Create a temporary old-style archive to link instead of a shared archive. +old_archive_from_expsyms_cmds=$lt_old_archive_from_expsyms_cmds + +# Commands used to build a shared archive. +archive_cmds=$lt_archive_cmds +archive_expsym_cmds=$lt_archive_expsym_cmds + +# Commands used to build a loadable module if different from building +# a shared archive. +module_cmds=$lt_module_cmds +module_expsym_cmds=$lt_module_expsym_cmds + +# Whether we are building with GNU ld or not. +with_gnu_ld=$lt_with_gnu_ld + +# Flag that allows shared libraries with undefined symbols to be built. +allow_undefined_flag=$lt_allow_undefined_flag + +# Flag that enforces no undefined symbols. +no_undefined_flag=$lt_no_undefined_flag + +# Flag to hardcode \$libdir into a binary during linking. +# This must work even if \$libdir does not exist +hardcode_libdir_flag_spec=$lt_hardcode_libdir_flag_spec + +# If ld is used when linking, flag to hardcode \$libdir into a binary +# during linking. This must work even if \$libdir does not exist. +hardcode_libdir_flag_spec_ld=$lt_hardcode_libdir_flag_spec_ld + +# Whether we need a single "-rpath" flag with a separated argument. +hardcode_libdir_separator=$lt_hardcode_libdir_separator + +# Set to "yes" if using DIR/libNAME\${shared_ext} during linking hardcodes +# DIR into the resulting binary. +hardcode_direct=$hardcode_direct + +# Set to "yes" if using DIR/libNAME\${shared_ext} during linking hardcodes +# DIR into the resulting binary and the resulting library dependency is +# "absolute",i.e impossible to change by setting \${shlibpath_var} if the +# library is relocated. +hardcode_direct_absolute=$hardcode_direct_absolute + +# Set to "yes" if using the -LDIR flag during linking hardcodes DIR +# into the resulting binary. +hardcode_minus_L=$hardcode_minus_L + +# Set to "yes" if using SHLIBPATH_VAR=DIR during linking hardcodes DIR +# into the resulting binary. +hardcode_shlibpath_var=$hardcode_shlibpath_var + +# Set to "yes" if building a shared library automatically hardcodes DIR +# into the library and all subsequent libraries and executables linked +# against it. +hardcode_automatic=$hardcode_automatic + +# Set to yes if linker adds runtime paths of dependent libraries +# to runtime path list. +inherit_rpath=$inherit_rpath + +# Whether libtool must link a program against all its dependency libraries. +link_all_deplibs=$link_all_deplibs + +# Fix the shell variable \$srcfile for the compiler. +fix_srcfile_path=$lt_fix_srcfile_path + +# Set to "yes" if exported symbols are required. +always_export_symbols=$always_export_symbols + +# The commands to list exported symbols. +export_symbols_cmds=$lt_export_symbols_cmds + +# Symbols that should not be listed in the preloaded symbols. +exclude_expsyms=$lt_exclude_expsyms + +# Symbols that must always be exported. +include_expsyms=$lt_include_expsyms + +# Commands necessary for linking programs (against libraries) with templates. +prelink_cmds=$lt_prelink_cmds + +# Specify filename containing input files. +file_list_spec=$lt_file_list_spec + +# How to hardcode a shared library path into an executable. +hardcode_action=$hardcode_action + +# ### END LIBTOOL CONFIG + +_LT_EOF + + case $host_os in + aix3*) + cat <<\_LT_EOF >> "$cfgfile" +# AIX sometimes has problems with the GCC collect2 program. For some +# reason, if we set the COLLECT_NAMES environment variable, the problems +# vanish in a puff of smoke. +if test "X${COLLECT_NAMES+set}" != Xset; then + COLLECT_NAMES= + export COLLECT_NAMES +fi +_LT_EOF + ;; + esac + + +ltmain="$ac_aux_dir/ltmain.sh" + + + # We use sed instead of cat because bash on DJGPP gets confused if + # if finds mixed CR/LF and LF-only lines. Since sed operates in + # text mode, it properly converts lines to CR/LF. This bash problem + # is reportedly fixed, but why not run on old versions too? + sed '/^# Generated shell functions inserted here/q' "$ltmain" >> "$cfgfile" \ + || (rm -f "$cfgfile"; exit 1) + + case $xsi_shell in + yes) + cat << \_LT_EOF >> "$cfgfile" + +# func_dirname file append nondir_replacement +# Compute the dirname of FILE. If nonempty, add APPEND to the result, +# otherwise set result to NONDIR_REPLACEMENT. +func_dirname () +{ + case ${1} in + */*) func_dirname_result="${1%/*}${2}" ;; + * ) func_dirname_result="${3}" ;; + esac +} + +# func_basename file +func_basename () +{ + func_basename_result="${1##*/}" +} + +# func_dirname_and_basename file append nondir_replacement +# perform func_basename and func_dirname in a single function +# call: +# dirname: Compute the dirname of FILE. If nonempty, +# add APPEND to the result, otherwise set result +# to NONDIR_REPLACEMENT. +# value returned in "$func_dirname_result" +# basename: Compute filename of FILE. +# value retuned in "$func_basename_result" +# Implementation must be kept synchronized with func_dirname +# and func_basename. For efficiency, we do not delegate to +# those functions but instead duplicate the functionality here. +func_dirname_and_basename () +{ + case ${1} in + */*) func_dirname_result="${1%/*}${2}" ;; + * ) func_dirname_result="${3}" ;; + esac + func_basename_result="${1##*/}" +} + +# func_stripname prefix suffix name +# strip PREFIX and SUFFIX off of NAME. +# PREFIX and SUFFIX must not contain globbing or regex special +# characters, hashes, percent signs, but SUFFIX may contain a leading +# dot (in which case that matches only a dot). +func_stripname () +{ + # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are + # positional parameters, so assign one to ordinary parameter first. + func_stripname_result=${3} + func_stripname_result=${func_stripname_result#"${1}"} + func_stripname_result=${func_stripname_result%"${2}"} +} + +# func_opt_split +func_opt_split () +{ + func_opt_split_opt=${1%%=*} + func_opt_split_arg=${1#*=} +} + +# func_lo2o object +func_lo2o () +{ + case ${1} in + *.lo) func_lo2o_result=${1%.lo}.${objext} ;; + *) func_lo2o_result=${1} ;; + esac +} + +# func_xform libobj-or-source +func_xform () +{ + func_xform_result=${1%.*}.lo +} + +# func_arith arithmetic-term... +func_arith () +{ + func_arith_result=$(( $* )) +} + +# func_len string +# STRING may not start with a hyphen. +func_len () +{ + func_len_result=${#1} +} + +_LT_EOF + ;; + *) # Bourne compatible functions. + cat << \_LT_EOF >> "$cfgfile" + +# func_dirname file append nondir_replacement +# Compute the dirname of FILE. If nonempty, add APPEND to the result, +# otherwise set result to NONDIR_REPLACEMENT. +func_dirname () +{ + # Extract subdirectory from the argument. + func_dirname_result=`$ECHO "X${1}" | $Xsed -e "$dirname"` + if test "X$func_dirname_result" = "X${1}"; then + func_dirname_result="${3}" + else + func_dirname_result="$func_dirname_result${2}" + fi +} + +# func_basename file +func_basename () +{ + func_basename_result=`$ECHO "X${1}" | $Xsed -e "$basename"` +} + + +# func_stripname prefix suffix name +# strip PREFIX and SUFFIX off of NAME. +# PREFIX and SUFFIX must not contain globbing or regex special +# characters, hashes, percent signs, but SUFFIX may contain a leading +# dot (in which case that matches only a dot). +# func_strip_suffix prefix name +func_stripname () +{ + case ${2} in + .*) func_stripname_result=`$ECHO "X${3}" \ + | $Xsed -e "s%^${1}%%" -e "s%\\\\${2}\$%%"`;; + *) func_stripname_result=`$ECHO "X${3}" \ + | $Xsed -e "s%^${1}%%" -e "s%${2}\$%%"`;; + esac +} + +# sed scripts: +my_sed_long_opt='1s/^\(-[^=]*\)=.*/\1/;q' +my_sed_long_arg='1s/^-[^=]*=//' + +# func_opt_split +func_opt_split () +{ + func_opt_split_opt=`$ECHO "X${1}" | $Xsed -e "$my_sed_long_opt"` + func_opt_split_arg=`$ECHO "X${1}" | $Xsed -e "$my_sed_long_arg"` +} + +# func_lo2o object +func_lo2o () +{ + func_lo2o_result=`$ECHO "X${1}" | $Xsed -e "$lo2o"` +} + +# func_xform libobj-or-source +func_xform () +{ + func_xform_result=`$ECHO "X${1}" | $Xsed -e 's/\.[^.]*$/.lo/'` +} + +# func_arith arithmetic-term... +func_arith () +{ + func_arith_result=`expr "$@"` +} + +# func_len string +# STRING may not start with a hyphen. +func_len () +{ + func_len_result=`expr "$1" : ".*" 2>/dev/null || echo $max_cmd_len` +} + +_LT_EOF +esac + +case $lt_shell_append in + yes) + cat << \_LT_EOF >> "$cfgfile" + +# func_append var value +# Append VALUE to the end of shell variable VAR. +func_append () +{ + eval "$1+=\$2" +} +_LT_EOF + ;; + *) + cat << \_LT_EOF >> "$cfgfile" + +# func_append var value +# Append VALUE to the end of shell variable VAR. +func_append () +{ + eval "$1=\$$1\$2" +} + +_LT_EOF + ;; + esac + + + sed -n '/^# Generated shell functions inserted here/,$p' "$ltmain" >> "$cfgfile" \ + || (rm -f "$cfgfile"; exit 1) + + mv -f "$cfgfile" "$ofile" || + (rm -f "$ofile" && cp "$cfgfile" "$ofile" && rm -f "$cfgfile") + chmod +x "$ofile" + + ;; + "libpng-config":F) chmod +x libpng-config ;; + + esac +done # for ac_tag + + +as_fn_exit 0 +_ACEOF +ac_clean_files=$ac_clean_files_save + +test $ac_write_fail = 0 || + as_fn_error "write failure creating $CONFIG_STATUS" "$LINENO" 5 + + +# configure is writing to config.log, and then calls config.status. +# config.status does its own redirection, appending to config.log. +# Unfortunately, on DOS this fails, as config.log is still kept open +# by configure, so config.status won't be able to write to it; its +# output is simply discarded. So we exec the FD to /dev/null, +# effectively closing config.log, so it can be properly (re)opened and +# appended to by config.status. When coming back to configure, we +# need to make the FD available again. +if test "$no_create" != yes; then + ac_cs_success=: + ac_config_status_args= + test "$silent" = yes && + ac_config_status_args="$ac_config_status_args --quiet" + exec 5>/dev/null + $SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false + exec 5>>config.log + # Use ||, not &&, to avoid exiting from the if with $? = 1, which + # would make configure fail if this is the last instruction. + $ac_cs_success || as_fn_exit $? +fi +if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts" >&5 +$as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;} +fi + diff --git a/libs/libpng-src/configure.ac b/libs/libpng-src/configure.ac new file mode 100644 index 000000000..bfdbf7a0c --- /dev/null +++ b/libs/libpng-src/configure.ac @@ -0,0 +1,153 @@ +# configure.ac + +dnl Process this file with autoconf to produce a configure script. +dnl +dnl Minor upgrades (compatible ABI): increment the package version +dnl (third field in two places below) and set the PNGLIB_RELEASE +dnl variable. +dnl +dnl Major upgrades (incompatible ABI): increment the package major +dnl version (second field, or first if desired), set the minor +dnl to 0, set PNGLIB_MAJOR below *and* follow the instructions in +dnl Makefile.am to upgrade the package name. + +dnl This is here to prevent earlier autoconf from being used, it +dnl should not be necessary to regenerate configure if the time +dnl stamps are correct +AC_PREREQ(2.59) + +dnl Version number stuff here: + +AC_INIT([libpng], [1.2.46], [png-mng-implement@lists.sourceforge.net]) +AM_INIT_AUTOMAKE +dnl stop configure from automagically running automake +AM_MAINTAINER_MODE + +PNGLIB_VERSION=1.2.46 +PNGLIB_MAJOR=1 +PNGLIB_MINOR=2 +PNGLIB_RELEASE=46 + +dnl End of version number stuff + +AC_CONFIG_SRCDIR([pngget.c]) +AM_CONFIG_HEADER(config.h) + +# Checks for programs. +AC_PROG_CC +AC_PROG_LD +AC_PROG_CPP +AC_CHECK_TOOL(SED, sed, :) +AC_LIBTOOL_WIN32_DLL +AC_PROG_INSTALL +AC_PROG_LN_S +AC_PROG_MAKE_SET +AC_PROG_LIBTOOL + +# Checks for header files. +AC_HEADER_STDC +AC_CHECK_HEADERS([malloc.h stdlib.h string.h strings.h]) + +# Checks for typedefs, structures, and compiler characteristics. +AC_C_CONST +AC_TYPE_SIZE_T +AC_STRUCT_TM + +# Checks for library functions. +AC_FUNC_STRTOD +AC_CHECK_FUNCS([memset], , AC_ERROR([memset not found in libc])) +AC_CHECK_FUNCS([pow], , AC_CHECK_LIB(m, pow, , AC_ERROR([cannot find pow])) ) +AC_CHECK_LIB(z, zlibVersion, , AC_ERROR([zlib not installed])) + +case $host_os in + aix*) + LIBPNG_DEFINES=-DPNG_CONFIGURE_LIBPNG -D_ALL_SOURCE;; + *) + LIBPNG_DEFINES=-DPNG_CONFIGURE_LIBPNG;; +esac +AC_MSG_CHECKING( + [if assembler code in pnggccrd.c can be compiled without PNG_NO_MMX_CODE]) +AC_TRY_COMPILE( + [#include "$srcdir/pnggccrd.c"], + [return 0;], + AC_MSG_RESULT(yes) + LIBPNG_NO_MMX="", + AC_MSG_RESULT(no) + LIBPNG_NO_MMX=-DPNG_NO_MMX_CODE) +LIBPNG_DEFINES=$LIBPNG_DEFINES\ $LIBPNG_NO_MMX +AC_SUBST(LIBPNG_DEFINES) +AC_SUBST(LIBPNG_NO_MMX) + +AC_MSG_CHECKING([if libraries can be versioned]) +GLD=`$LD --help < /dev/null 2>/dev/null | grep version-script` +if test "$GLD"; then + have_ld_version_script=yes + AC_MSG_RESULT(yes) +else + have_ld_version_script=no + AC_MSG_RESULT(no) + AC_MSG_WARN(*** You have not enabled versioned symbols.) +fi +AM_CONDITIONAL(HAVE_LD_VERSION_SCRIPT, test "$have_ld_version_script" = "yes") + +if test "$have_ld_version_script" = "yes"; then + AC_MSG_CHECKING([for symbol prefix]) + SYMBOL_PREFIX=`echo "PREFIX=__USER_LABEL_PREFIX__" \ + | ${CPP-${CC-gcc} -E} - 2>&1 \ + | ${EGREP-grep} "^PREFIX=" \ + | ${SED-sed} "s:^PREFIX=::"` + AC_SUBST(SYMBOL_PREFIX) + AC_MSG_RESULT($SYMBOL_PREFIX) +fi + +# Substitutions for .in files +AC_SUBST(PNGLIB_VERSION) +AC_SUBST(PNGLIB_MAJOR) +AC_SUBST(PNGLIB_MINOR) +AC_SUBST(PNGLIB_RELEASE) + +# Additional arguments (and substitutions) +# Allow the pkg-config directory to be set +AC_ARG_WITH(pkgconfigdir, + AC_HELP_STRING([--with-pkgconfigdir], + [Use the specified pkgconfig dir (default is libdir/pkgconfig)]), + [pkgconfigdir=${withval}], + [pkgconfigdir='${libdir}/pkgconfig']) + +AC_SUBST([pkgconfigdir]) +AC_MSG_NOTICE([pkgconfig directory is ${pkgconfigdir}]) + +# Make the *-config binary config scripts optional +AC_ARG_WITH(binconfigs, + AC_HELP_STRING([--with-binconfigs], + [Generate shell libpng-config scripts as well as pkg-config data] + [@<:@default=yes@:>@]), + [if test "${withval}" = no; then + binconfigs= + AC_MSG_NOTICE([libpng-config scripts will not be built]) + else + binconfigs='${binconfigs}' + fi], + [binconfigs='${binconfigs}']) +AC_SUBST([binconfigs]) + +# Allow the old version number library, libpng.so, to be removed from +# the build +AC_ARG_WITH(libpng-compat, + AC_HELP_STRING([--with-libpng-compat], + [Generate the obsolete libpng.so library @<:@default=yes@:>@]), + [if test "${withval}" = no; then + compatlib= + AC_MSG_NOTICE([libpng.so will not be built]) + else + compatlib=libpng.la + fi], + [compatlib=libpng.la]) +AC_SUBST([compatlib]) + +# Config files, substituting as above +AC_CONFIG_FILES([Makefile libpng.pc:scripts/libpng.pc-configure.in]) +AC_CONFIG_FILES([libpng-config:scripts/libpng-config.in], + [chmod +x libpng-config]) + +AC_OUTPUT diff --git a/libs/libpng-src/contrib/gregbook/COPYING b/libs/libpng-src/contrib/gregbook/COPYING new file mode 100644 index 000000000..d60c31a97 --- /dev/null +++ b/libs/libpng-src/contrib/gregbook/COPYING @@ -0,0 +1,340 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/libs/libpng-src/contrib/gregbook/LICENSE b/libs/libpng-src/contrib/gregbook/LICENSE new file mode 100644 index 000000000..d9567178c --- /dev/null +++ b/libs/libpng-src/contrib/gregbook/LICENSE @@ -0,0 +1,50 @@ + --------------------------------------------------------------------------- + + Copyright (c) 1998-2008 Greg Roelofs. All rights reserved. + + This software is provided "as is," without warranty of any kind, + express or implied. In no event shall the author or contributors + be held liable for any damages arising in any way from the use of + this software. + + The contents of this file are DUAL-LICENSED. You may modify and/or + redistribute this software according to the terms of one of the + following two licenses (at your option): + + + LICENSE 1 ("BSD-like with advertising clause"): + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute + it freely, subject to the following restrictions: + + 1. Redistributions of source code must retain the above copyright + notice, disclaimer, and this list of conditions. + 2. Redistributions in binary form must reproduce the above copyright + notice, disclaimer, and this list of conditions in the documenta- + tion and/or other materials provided with the distribution. + 3. All advertising materials mentioning features or use of this + software must display the following acknowledgment: + + This product includes software developed by Greg Roelofs + and contributors for the book, "PNG: The Definitive Guide," + published by O'Reilly and Associates. + + + LICENSE 2 (GNU GPL v2 or later): + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + --------------------------------------------------------------------------- diff --git a/libs/libpng-src/contrib/gregbook/Makefile.mingw32 b/libs/libpng-src/contrib/gregbook/Makefile.mingw32 new file mode 100644 index 000000000..e70a59aef --- /dev/null +++ b/libs/libpng-src/contrib/gregbook/Makefile.mingw32 @@ -0,0 +1,130 @@ +# Sample makefile for rpng-win / rpng2-win / wpng using mingw32-gcc and make. +# Greg Roelofs +# Last modified: 2 June 2007 +# +# The programs built by this makefile are described in the book, +# "PNG: The Definitive Guide," by Greg Roelofs (O'Reilly and +# Associates, 1999). Go buy a copy, eh? Well, OK, it's not +# generally for sale anymore, but it's the thought that counts, +# right? (Hint: http://www.libpng.org/pub/png/book/ ) +# +# Invoke this makefile from a DOS-prompt window via: +# +# make -f Makefile.mingw32 +# +# This makefile assumes libpng and zlib have already been built or downloaded +# and are in subdirectories at the same level as the current subdirectory +# (as indicated by the PNGDIR and ZDIR macros below). It makes no assumptions +# at all about the mingw32 installation tree (W32DIR). Edit as appropriate. +# +# Note that the names of the dynamic and static libpng and zlib libraries +# used below may change in later releases of the libraries. This makefile +# builds both statically and dynamically linked executables by default. +# (You need only one set, but for testing it can be handy to have both.) + + +# macros -------------------------------------------------------------------- + +#PNGDIR = ../..# for libpng-x.y.z/contrib/gregbook builds +PNGDIR = ../libpng-win32 +PNGINC = -I$(PNGDIR) +PNGLIBd = $(PNGDIR)/libpng.dll.a # dynamically linked +PNGLIBs = $(PNGDIR)/libpng.a # statically linked, local libpng + +#ZDIR = ../../../zlib-win32# for libpng-x.y.z/contrib/gregbook builds +ZDIR = ../zlib-win32 +ZINC = -I$(ZDIR) +ZLIBd = $(ZDIR)/libzdll.a +ZLIBs = $(ZDIR)/libz.a + +# change this to be the path where mingw32 installs its stuff: +W32DIR = +#W32DIR = /usr/local/cross-tools/i386-mingw32msvc +W32INC = -I$(W32DIR)/include +W32LIB = $(W32DIR)/lib/libuser32.a $(W32DIR)/lib/libgdi32.a + +CC = gcc +#CC = i386-mingw32msvc-gcc # e.g., Linux -> Win32 cross-compilation +LD = $(CC) +RM = rm -f +CFLAGS = -O -Wall $(INCS) $(MINGW_CCFLAGS) +# [note that -Wall is a gcc-specific compilation flag ("most warnings on")] +# [-ansi, -pedantic and -W can also be used] +LDFLAGS = $(MINGW_LDFLAGS) +O = .o +E = .exe + +INCS = $(PNGINC) $(ZINC) $(W32INC) +RLIBSd = $(PNGLIBd) $(ZLIBd) $(W32LIB) -lm +RLIBSs = $(PNGLIBs) $(ZLIBs) $(W32LIB) -lm +WLIBSd = $(PNGLIBd) $(ZLIBd) +WLIBSs = $(PNGLIBs) $(ZLIBs) + +RPNG = rpng-win +RPNG2 = rpng2-win +WPNG = wpng + +ROBJSd = $(RPNG)$(O) readpng.pic$(O) +ROBJS2d = $(RPNG2)$(O) readpng2.pic$(O) +WOBJSd = $(WPNG)$(O) writepng.pic$(O) + +RPNGs = $(RPNG)-static +RPNG2s = $(RPNG2)-static +WPNGs = $(WPNG)-static + +ROBJSs = $(RPNG)$(O) readpng$(O) +ROBJS2s = $(RPNG2)$(O) readpng2$(O) +WOBJSs = $(WPNG)$(O) writepng$(O) + +STATIC_EXES = $(RPNGs)$(E) $(RPNG2s)$(E) $(WPNGs)$(E) +DYNAMIC_EXES = $(RPNG)$(E) $(RPNG2)$(E) $(WPNG)$(E) + +EXES = $(STATIC_EXES) $(DYNAMIC_EXES) + + +# implicit make rules ------------------------------------------------------- + +.c$(O): + $(CC) -c $(CFLAGS) $< + +%.pic$(O): %.c + $(CC) -c $(CFLAGS) -DPNG_BUILD_DLL -o $@ $< + + +# dependencies -------------------------------------------------------------- + +all: $(EXES) + +$(RPNGs)$(E): $(ROBJSs) + $(LD) $(LDFLAGS) -o $@ $(ROBJSs) $(RLIBSs) + +$(RPNG)$(E): $(ROBJSd) + $(LD) $(LDFLAGS) -o $@ $(ROBJSd) $(RLIBSd) + +$(RPNG2s)$(E): $(ROBJS2s) + $(LD) $(LDFLAGS) -o $@ $(ROBJS2s) $(RLIBSs) + +$(RPNG2)$(E): $(ROBJS2d) + $(LD) $(LDFLAGS) -o $@ $(ROBJS2d) $(RLIBSd) + +$(WPNGs)$(E): $(WOBJSs) + $(LD) $(LDFLAGS) -o $@ $(WOBJSs) $(WLIBSs) + +$(WPNG)$(E): $(WOBJSd) + $(LD) $(LDFLAGS) -o $@ $(WOBJSd) $(WLIBSd) + +$(RPNG)$(O): $(RPNG).c readpng.h +$(RPNG2)$(O): $(RPNG2).c readpng2.h +$(WPNG)$(O): $(WPNG).c writepng.h + +readpng$(O) readpng.pic$(O): readpng.c readpng.h +readpng2$(O) readpng2.pic$(O): readpng2.c readpng2.h +writepng$(O) writepng.pic$(O): writepng.c writepng.h + + +# maintenance --------------------------------------------------------------- + +clean: + $(RM) $(EXES) + $(RM) $(ROBJSs) $(ROBJS2s) $(WOBJSs) + $(RM) $(ROBJSd) $(ROBJS2d) $(WOBJSd) diff --git a/libs/libpng-src/contrib/gregbook/Makefile.sgi b/libs/libpng-src/contrib/gregbook/Makefile.sgi new file mode 100644 index 000000000..e3ca6ce4c --- /dev/null +++ b/libs/libpng-src/contrib/gregbook/Makefile.sgi @@ -0,0 +1,104 @@ +# Sample makefile for rpng-x / rpng2-x / wpng for SGI using cc and make. +# Greg Roelofs +# Last modified: 7 March 2002 +# +# The programs built by this makefile are described in the book, +# "PNG: The Definitive Guide," by Greg Roelofs (O'Reilly and +# Associates, 1999). Go buy a copy, eh? Buy some for friends +# and family, too. (Not that this is a blatant plug or anything.) +# +# Invoke this makefile from a shell prompt in the usual way; for example: +# +# make -f Makefile.sgi +# +# This makefile assumes libpng and zlib have already been built or downloaded +# and are both installed in /usr/local/{include,lib} (as indicated by the +# PNG* and Z* macros below). Edit as appropriate--choose only ONE each of +# the PNGINC, PNGLIB, ZINC and ZLIB lines. +# +# This makefile builds dynamically linked executables (against libpng and zlib, +# that is), but that can be changed by uncommenting the appropriate PNGLIB and +# ZLIB lines. + + +# macros -------------------------------------------------------------------- + +PNGINC = -I/usr/local/include/libpng12 +PNGLIB = -L/usr/local/lib -lpng12 # dynamically linked against libpng +#PNGLIB = /usr/local/lib/libpng12.a # statically linked against libpng +# or: +#PNGINC = -I../.. +#PNGLIB = -L../.. -lpng +#PNGLIB = ../../libpng.a + +ZINC = -I/usr/local/include +ZLIB = -L/usr/local/lib -lz # dynamically linked against zlib +#ZLIB = /usr/local/lib/libz.a # statically linked against zlib +#ZINC = -I../zlib +#ZLIB = -L../zlib -lz +#ZLIB = ../../../zlib/libz.a + +XINC = -I/usr/include/X11 # old-style, stock X distributions +XLIB = -L/usr/lib/X11 -lX11 +#XINC = -I/usr/openwin/include # Sun workstations (OpenWindows) +#XLIB = -L/usr/openwin/lib -lX11 +#XINC = -I/usr/X11R6/include # new X distributions (XFree86, etc.) +#XLIB = -L/usr/X11R6/lib -lX11 + +INCS = $(PNGINC) $(ZINC) $(XINC) +RLIBS = $(PNGLIB) $(ZLIB) $(XLIB) -lm +WLIBS = $(PNGLIB) $(ZLIB) + +CC = cc +LD = cc +RM = rm -f +# ABI must be the same as that used to build libpng. +ABI= +CFLAGS = $(ABI) -O -fullwarn $(INCS) +LDFLAGS = $(ABI) +O = .o +E = + +RPNG = rpng-x +RPNG2 = rpng2-x +WPNG = wpng + +ROBJS = $(RPNG)$(O) readpng$(O) +ROBJS2 = $(RPNG2)$(O) readpng2$(O) +WOBJS = $(WPNG)$(O) writepng$(O) + +EXES = $(RPNG)$(E) $(RPNG2)$(E) $(WPNG)$(E) + + +# implicit make rules ------------------------------------------------------- + +.c$(O): + $(CC) -c $(CFLAGS) $< + + +# dependencies -------------------------------------------------------------- + +all: $(EXES) + +$(RPNG)$(E): $(ROBJS) + $(LD) $(LDFLAGS) -o $@ $(ROBJS) $(RLIBS) + +$(RPNG2)$(E): $(ROBJS2) + $(LD) $(LDFLAGS) -o $@ $(ROBJS2) $(RLIBS) + +$(WPNG)$(E): $(WOBJS) + $(LD) $(LDFLAGS) -o $@ $(WOBJS) $(WLIBS) + +$(RPNG)$(O): $(RPNG).c readpng.h +$(RPNG2)$(O): $(RPNG2).c readpng2.h +$(WPNG)$(O): $(WPNG).c writepng.h + +readpng$(O): readpng.c readpng.h +readpng2$(O): readpng2.c readpng2.h +writepng$(O): writepng.c writepng.h + + +# maintenance --------------------------------------------------------------- + +clean: + $(RM) $(EXES) $(ROBJS) $(ROBJS2) $(WOBJS) diff --git a/libs/libpng-src/contrib/gregbook/Makefile.unx b/libs/libpng-src/contrib/gregbook/Makefile.unx new file mode 100644 index 000000000..7ff65bfb7 --- /dev/null +++ b/libs/libpng-src/contrib/gregbook/Makefile.unx @@ -0,0 +1,132 @@ +# Sample makefile for rpng-x / rpng2-x / wpng using gcc and make. +# Greg Roelofs +# Last modified: 2 June 2007 +# +# The programs built by this makefile are described in the book, +# "PNG: The Definitive Guide," by Greg Roelofs (O'Reilly and +# Associates, 1999). Go buy a copy, eh? Well, OK, it's not +# generally for sale anymore, but it's the thought that counts, +# right? (Hint: http://www.libpng.org/pub/png/book/ ) +# +# Invoke this makefile from a shell prompt in the usual way; for example: +# +# make -f Makefile.unx +# +# This makefile assumes libpng and zlib have already been built or downloaded +# and are installed in /usr/local/{include,lib} or as otherwise indicated by +# the PNG* and Z* macros below. Edit as appropriate--choose only ONE each of +# the PNGINC, PNGLIBd, PNGLIBs, ZINC, ZLIBd and ZLIBs lines. +# +# This makefile builds both dynamically and statically linked executables +# (against libpng and zlib, that is), but that can be changed by modifying +# the "EXES =" line. (You need only one set, but for testing it can be handy +# to have both.) + + +# macros -------------------------------------------------------------------- + +#PNGDIR = /usr/local/lib +#PNGINC = -I/usr/local/include/libpng12 +#PNGLIBd = -L$(PNGDIR) -lpng12 # dynamically linked, installed libpng +#PNGLIBs = $(PNGDIR)/libpng12.a # statically linked, installed libpng +# or: +PNGDIR = ../..# this one is for libpng-x.y.z/contrib/gregbook builds +#PNGDIR = ../libpng +PNGINC = -I$(PNGDIR) +PNGLIBd = -Wl,-rpath,$(PNGDIR) -L$(PNGDIR) -lpng12 # dynamically linked +PNGLIBs = $(PNGDIR)/libpng.a # statically linked, local libpng + +ZDIR = /usr/local/lib +#ZDIR = /usr/lib64 +ZINC = -I/usr/local/include +ZLIBd = -L$(ZDIR) -lz # dynamically linked against zlib +ZLIBs = $(ZDIR)/libz.a # statically linked against zlib +# or: +#ZDIR = ../zlib +#ZINC = -I$(ZDIR) +#ZLIBd = -Wl,-rpath,$(ZDIR) -L$(ZDIR) -lz # -rpath allows in-place testing +#ZLIBs = $(ZDIR)/libz.a + +#XINC = -I/usr/include # old-style, stock X distributions +#XLIB = -L/usr/lib/X11 -lX11 # (including SGI IRIX) +#XINC = -I/usr/openwin/include # Sun workstations (OpenWindows) +#XLIB = -L/usr/openwin/lib -lX11 +XINC = -I/usr/X11R6/include # new X distributions (X.org, etc.) +XLIB = -L/usr/X11R6/lib -lX11 +#XLIB = -L/usr/X11R6/lib64 -lX11 # e.g., Red Hat on AMD64 + +INCS = $(PNGINC) $(ZINC) $(XINC) +RLIBSd = $(PNGLIBd) $(ZLIBd) $(XLIB) -lm +RLIBSs = $(PNGLIBs) $(ZLIBs) $(XLIB) -lm +WLIBSd = $(PNGLIBd) $(ZLIBd) -lm +WLIBSs = $(PNGLIBs) $(ZLIBs) + +CC = gcc +LD = gcc +RM = rm -f +CFLAGS = -O -Wall $(INCS) -DFEATURE_LOOP +# [note that -Wall is a gcc-specific compilation flag ("most warnings on")] +# [-ansi, -pedantic and -W can also be used] +LDFLAGS = +O = .o +E = + +RPNG = rpng-x +RPNG2 = rpng2-x +WPNG = wpng + +RPNGs = $(RPNG)-static +RPNG2s = $(RPNG2)-static +WPNGs = $(WPNG)-static + +ROBJS = $(RPNG)$(O) readpng$(O) +ROBJS2 = $(RPNG2)$(O) readpng2$(O) +WOBJS = $(WPNG)$(O) writepng$(O) + +STATIC_EXES = $(RPNGs)$(E) $(RPNG2s)$(E) $(WPNGs)$(E) +DYNAMIC_EXES = $(RPNG)$(E) $(RPNG2)$(E) $(WPNG)$(E) + +EXES = $(STATIC_EXES) $(DYNAMIC_EXES) + + +# implicit make rules ------------------------------------------------------- + +.c$(O): + $(CC) -c $(CFLAGS) $< + + +# dependencies -------------------------------------------------------------- + +all: $(EXES) + +$(RPNGs)$(E): $(ROBJS) + $(LD) $(LDFLAGS) -o $@ $(ROBJS) $(RLIBSs) + +$(RPNG)$(E): $(ROBJS) + $(LD) $(LDFLAGS) -o $@ $(ROBJS) $(RLIBSd) + +$(RPNG2s)$(E): $(ROBJS2) + $(LD) $(LDFLAGS) -o $@ $(ROBJS2) $(RLIBSs) + +$(RPNG2)$(E): $(ROBJS2) + $(LD) $(LDFLAGS) -o $@ $(ROBJS2) $(RLIBSd) + +$(WPNGs)$(E): $(WOBJS) + $(LD) $(LDFLAGS) -o $@ $(WOBJS) $(WLIBSs) + +$(WPNG)$(E): $(WOBJS) + $(LD) $(LDFLAGS) -o $@ $(WOBJS) $(WLIBSd) + +$(RPNG)$(O): $(RPNG).c readpng.h +$(RPNG2)$(O): $(RPNG2).c readpng2.h +$(WPNG)$(O): $(WPNG).c writepng.h + +readpng$(O): readpng.c readpng.h +readpng2$(O): readpng2.c readpng2.h +writepng$(O): writepng.c writepng.h + + +# maintenance --------------------------------------------------------------- + +clean: + $(RM) $(EXES) $(ROBJS) $(ROBJS2) $(WOBJS) diff --git a/libs/libpng-src/contrib/gregbook/Makefile.w32 b/libs/libpng-src/contrib/gregbook/Makefile.w32 new file mode 100644 index 000000000..3c0808593 --- /dev/null +++ b/libs/libpng-src/contrib/gregbook/Makefile.w32 @@ -0,0 +1,113 @@ +# Sample makefile for rpng-win / rpng2-win / wpng using MSVC and NMAKE. +# Greg Roelofs +# Last modified: 2 June 2007 +# +# The programs built by this makefile are described in the book, +# "PNG: The Definitive Guide," by Greg Roelofs (O'Reilly and +# Associates, 1999). Go buy a copy, eh? Well, OK, it's not +# generally for sale anymore, but it's the thought that counts, +# right? (Hint: http://www.libpng.org/pub/png/book/ ) +# +# Invoke this makefile from a DOS prompt window via: +# +# %devstudio%\vc\bin\vcvars32.bat +# nmake -nologo -f Makefile.w32 +# +# where %devstudio% is the installation directory for MSVC / DevStudio. If +# you get "environment out of space" errors, create a desktop shortcut with +# "c:\windows\command.com /e:4096" as the program command line and set the +# working directory to this directory. Then double-click to open the new +# DOS-prompt window with a bigger environment and retry the commands above. +# +# This makefile assumes libpng and zlib have already been built or downloaded +# and are in subdirectories at the same level as the current subdirectory +# (as indicated by the PNGPATH and ZPATH macros below). Edit as appropriate. +# +# Note that the names of the dynamic and static libpng and zlib libraries +# used below may change in later releases of the libraries. This makefile +# builds statically linked executables, but that can be changed by uncom- +# menting the appropriate PNGLIB and ZLIB lines. + +!include + + +# macros -------------------------------------------------------------------- + +PNGPATH = ../libpng +PNGINC = -I$(PNGPATH) +#PNGLIB = $(PNGPATH)/pngdll.lib +PNGLIB = $(PNGPATH)/libpng.lib + +ZPATH = ../zlib +ZINC = -I$(ZPATH) +#ZLIB = $(ZPATH)/zlibdll.lib +ZLIB = $(ZPATH)/zlibstat.lib + +WINLIBS = -defaultlib:user32.lib gdi32.lib +# ["real" apps may also need comctl32.lib, comdlg32.lib, winmm.lib, etc.] + +INCS = $(PNGINC) $(ZINC) +RLIBS = $(PNGLIB) $(ZLIB) $(WINLIBS) +WLIBS = $(PNGLIB) $(ZLIB) + +CC = cl +LD = link +RM = del +CFLAGS = -nologo -O -W3 $(INCS) $(cvars) +# [note that -W3 is an MSVC-specific compilation flag ("all warnings on")] +# [see %devstudio%\vc\include\win32.mak for cvars macro definition] +O = .obj +E = .exe + +RLDFLAGS = -nologo -subsystem:windows +WLDFLAGS = -nologo + +RPNG = rpng-win +RPNG2 = rpng2-win +WPNG = wpng + +ROBJS = $(RPNG)$(O) readpng$(O) +ROBJS2 = $(RPNG2)$(O) readpng2$(O) +WOBJS = $(WPNG)$(O) writepng$(O) + +EXES = $(RPNG)$(E) $(RPNG2)$(E) $(WPNG)$(E) + + +# implicit make rules ------------------------------------------------------- + +.c$(O): + $(CC) -c $(CFLAGS) $< + + +# dependencies -------------------------------------------------------------- + +all: $(EXES) + +$(RPNG)$(E): $(ROBJS) + $(LD) $(RLDFLAGS) -out:$@ $(ROBJS) $(RLIBS) + +$(RPNG2)$(E): $(ROBJS2) + $(LD) $(RLDFLAGS) -out:$@ $(ROBJS2) $(RLIBS) + +$(WPNG)$(E): $(WOBJS) + $(LD) $(WLDFLAGS) -out:$@ $(WOBJS) $(WLIBS) + +$(RPNG)$(O): $(RPNG).c readpng.h +$(RPNG2)$(O): $(RPNG2).c readpng2.h +$(WPNG)$(O): $(WPNG).c writepng.h + +readpng$(O): readpng.c readpng.h +readpng2$(O): readpng2.c readpng2.h +writepng$(O): writepng.c writepng.h + + +# maintenance --------------------------------------------------------------- + +clean: +# ideally we could just do this: +# $(RM) $(EXES) $(ROBJS) $(ROBJS2) $(WOBJS) +# ...but the Windows "DEL" command is none too bright, so: + $(RM) r*$(E) + $(RM) w*$(E) + $(RM) r*$(O) + $(RM) w*$(O) diff --git a/libs/libpng-src/contrib/gregbook/README b/libs/libpng-src/contrib/gregbook/README new file mode 100644 index 000000000..cb6e5257e --- /dev/null +++ b/libs/libpng-src/contrib/gregbook/README @@ -0,0 +1,186 @@ + =========================== + PNG: The Definitive Guide + =========================== + + Source Code + +Chapters 13, 14 and 15 of "PNG: The Definitive Guide" discuss three free, +cross-platform demo programs that show how to use the libpng reference +library: rpng, rpng2 and wpng. rpng and rpng2 are viewers; the first is +a very simple example that that shows how a standard file-viewer might use +libpng, while the second is designed to process streaming data and shows +how a web browser might be written. wpng is a simple command-line program +that reads binary PGM and PPM files (the ``raw'' grayscale and RGB subsets +of PBMPLUS/NetPBM) and converts them to PNG. + +The source code for all three demo programs currently compiles under +Unix, OpenVMS, and 32-bit Windows. (Special thanks to Martin Zinser, +zinser@decus.de, for making the necessary changes for OpenVMS and for +providing an appropriate build script.) Build instructions can be found +below. + +Files: + + README this file + LICENSE terms of distribution and reuse (BSD-like or GNU GPL) + COPYING GNU General Public License (GPL) + + Makefile.unx Unix makefile + Makefile.w32 Windows (MSVC) makefile + makevms.com OpenVMS build script + + rpng-win.c Windows front end for the basic viewer + rpng-x.c X Window System (Unix, OpenVMS) front end + readpng.c generic back end for the basic viewer + readpng.h header file for the basic viewer + + rpng2-win.c Windows front end for the progressive viewer + rpng2-x.c X front end for the progressive viewer + readpng2.c generic back end for the progressive viewer + readpng2.h header file for the progressive viewer + + wpng.c generic (text) front end for the converter + writepng.c generic back end for the converter + writepng.h header file for the converter + + toucan.png transparent PNG for testing (by Stefan Schneider) + +Note that, although the programs are designed to be functional, their +primary purpose is to illustrate how to use libpng to add PNG support to +other programs. As such, their user interfaces are crude and definitely +are not intended for everyday use. + +Please see http://www.libpng.org/pub/png/pngbook.html for further infor- +mation and links to the latest version of the source code, and Chapters +13-15 of the book for detailed discussion of the three programs. + +Greg Roelofs +http://pobox.com/~newt/greg_contact.html +16 March 2008 + + +BUILD INSTRUCTIONS + + - Prerequisites (in order of compilation): + + - zlib http://zlib.net/ + - libpng http://www.libpng.org/pub/png/libpng.html + - pngbook http://www.libpng.org/pub/png/book/sources.html + + The pngbook demo programs are explicitly designed to demonstrate proper + coding techniques for using the libpng reference library. As a result, + you need to download and build both zlib (on which libpng depends) and + libpng. A common build setup is to place the zlib, libpng and pngbook + subdirectory trees ("folders") in the same parent directory. Then the + libpng build can refer to files in ../zlib (or ..\zlib or [-.zlib]), + and similarly for the pngbook build. + + Note that all three packages are designed to be built from a command + line by default; those who wish to use a graphical or other integrated + development environments are on their own. + + + - Unix: + + Unpack the latest pngbook sources (which should correspond to this + README file) into a directory and change into that directory. + + Copy Makefile.unx to Makefile and edit the PNG* and Z* variables + appropriately (possibly also the X* variables if necessary). + + make + + There is no "install" target, so copy the three executables somewhere + in your path or run them from the current directory. All three will + print a basic usage screen when run without any command-line arguments; + see the book for more details. + + + - Windows: + + Unpack the latest pngbook sources (which should correspond to this + README file) into a folder, open a "DOS shell" or "command prompt" + or equivalent command-line window, and cd into the folder where you + unpacked the source code. + + For MSVC, set up the necessary environment variables by invoking + + %devstudio%\vc\bin\vcvars32.bat + + where where %devstudio% is the installation directory for MSVC / + DevStudio. If you get "environment out of space" errors under 95/98, + create a desktop shortcut with "c:\windows\command.com /e:4096" as + the program command line and set the working directory to the pngbook + directory. Then double-click to open the new DOS-prompt window with + a bigger environment and retry the commands above. + + Copy Makefile.w32 to Makefile and edit the PNGPATH and ZPATH variables + appropriately (possibly also the "INC" and "LIB" variables if needed). + Note that the names of the dynamic and static libpng and zlib libraries + used in the makefile may change in later releases of the libraries. + Also note that, as of libpng version 1.0.5, MSVC DLL builds do not work. + This makefile therefore builds statically linked executables, but if + the DLL problems ever get fixed, uncommenting the appropriate PNGLIB + and ZLIB lines will build dynamically linked executables instead. + + Do the build by typing + + nmake + + The result should be three executables: rpng-win.exe, rpng2-win.exe, + and wpng.exe. Copy them somewhere in your PATH or run them from the + current folder. Like the Unix versions, the two windowed programs + (rpng and rpng2) now display a usage screen in a console window when + invoked without command-line arguments; this is new behavior as of + the June 2001 release. Note that the programs use the Unix-style "-" + character to specify options, instead of the more common DOS/Windows + "/" character. (For example: "rpng2-win -bgpat 4 foo.png", not + "rpng2-win /bgpat 4 foo.png") + + + - OpenVMS: + + Unpack the pngbook sources into a subdirectory and change into that + subdirectory. + + Edit makevms.com appropriately, specifically the zpath and pngpath + variables. + + @makevms + + To run the programs, they probably first need to be set up as "foreign + symbols," with "disk" and "dir" set appropriately: + + $ rpng == "$disk:[dir]rpng-x.exe" + $ rpng2 == "$disk:[dir]rpng2-x.exe" + $ wpng == "$disk:[dir]wpng.exe" + + All three will print a basic usage screen when run without any command- + line arguments; see the book for more details. Note that the options + style is Unix-like, i.e., preceded by "-" rather than "/". + + +RUNNING THE PROGRAMS: (VERY) BRIEF INTRO + + rpng is a simple PNG viewer that can display transparent PNGs with a + specified background color; for example, + + rpng -bgcolor #ff0000 toucan.png + + would display the image with a red background. rpng2 is a progressive + viewer that simulates a web browser in some respects; it can display + images against either a background color or a dynamically generated + background image. For example: + + rpng2 -bgpat 16 toucan.png + + wpng is a purely command-line image converter from binary PBMPLUS/NetPBM + format (.pgm or .ppm) to PNG; for example, + + wpng -time < toucan-notrans.ppm > toucan-notrans.png + + would convert the specified PPM file (using redirection) to PNG, auto- + matically setting the PNG modification-time chunk. + + All options can be abbreviated to the shortest unique value; for example, + "-bgc" for -bgcolor (versus "-bgp" for -bgpat), or "-g" for -gamma. diff --git a/libs/libpng-src/contrib/gregbook/makevms.com b/libs/libpng-src/contrib/gregbook/makevms.com new file mode 100644 index 000000000..bd37dc0d7 --- /dev/null +++ b/libs/libpng-src/contrib/gregbook/makevms.com @@ -0,0 +1,132 @@ +$!------------------------------------------------------------------------------ +$! make "PNG: The Definitive Guide" demo programs (for X) under OpenVMS +$! +$! Script created by Martin Zinser for libpng; modified by Greg Roelofs +$! for standalone pngbook source distribution. +$! +$! +$! Set locations where zlib and libpng sources live. +$! +$ zpath = "" +$ pngpath = "" +$! +$ if f$search("[---.zlib]zlib.h").nes."" then zpath = "[---.zlib]" +$ if f$search("[--]png.h").nes."" then pngpath = "[--]" +$! +$ if f$search("[-.zlib]zlib.h").nes."" then zpath = "[-.zlib]" +$ if f$search("[-.libpng]png.h").nes."" then pngpath = "[-.libpng]" +$! +$ if zpath .eqs. "" +$ then +$ write sys$output "zlib include not found. Exiting..." +$ exit 2 +$ endif +$! +$ if pngpath .eqs. "" +$ then +$ write sys$output "libpng include not found. Exiting..." +$ exit 2 +$ endif +$! +$! Look for the compiler used. +$! +$ ccopt="/include=(''zpath',''pngpath')" +$ if f$getsyi("HW_MODEL").ge.1024 +$ then +$ ccopt = "/prefix=all"+ccopt +$ comp = "__decc__=1" +$ if f$trnlnm("SYS").eqs."" then define sys sys$library: +$ else +$ if f$search("SYS$SYSTEM:DECC$COMPILER.EXE").eqs."" +$ then +$ if f$trnlnm("SYS").eqs."" then define sys sys$library: +$ if f$search("SYS$SYSTEM:VAXC.EXE").eqs."" +$ then +$ comp = "__gcc__=1" +$ CC :== GCC +$ else +$ comp = "__vaxc__=1" +$ endif +$ else +$ if f$trnlnm("SYS").eqs."" then define sys decc$library_include: +$ ccopt = "/decc/prefix=all"+ccopt +$ comp = "__decc__=1" +$ endif +$ endif +$ open/write lopt lib.opt +$ write lopt "''pngpath'libpng.olb/lib" +$ write lopt "''zpath'libz.olb/lib" +$ close lopt +$ open/write xopt x11.opt +$ write xopt "sys$library:decw$xlibshr.exe/share" +$ close xopt +$! +$! Build 'em. +$! +$ write sys$output "Compiling PNG book programs ..." +$ CALL MAKE readpng.OBJ "cc ''CCOPT' readpng" - + readpng.c readpng.h +$ CALL MAKE readpng2.OBJ "cc ''CCOPT' readpng2" - + readpng2.c readpng2.h +$ CALL MAKE writepng.OBJ "cc ''CCOPT' writepng" - + writepng.c writepng.h +$ write sys$output "Building rpng-x..." +$ CALL MAKE rpng-x.OBJ "cc ''CCOPT' rpng-x" - + rpng-x.c readpng.h +$ call make rpng-x.exe - + "LINK rpng-x,readpng,lib.opt/opt,x11.opt/opt" - + rpng-x.obj readpng.obj +$ write sys$output "Building rpng2-x..." +$ CALL MAKE rpng2-x.OBJ "cc ''CCOPT' rpng2-x" - + rpng2-x.c readpng2.h +$ call make rpng2-x.exe - + "LINK rpng2-x,readpng2,lib.opt/opt,x11.opt/opt" - + rpng2-x.obj readpng2.obj +$ write sys$output "Building wpng..." +$ CALL MAKE wpng.OBJ "cc ''CCOPT' wpng" - + wpng.c writepng.h +$ call make wpng.exe - + "LINK wpng,writepng,lib.opt/opt" - + wpng.obj writepng.obj +$ exit +$! +$! +$MAKE: SUBROUTINE !SUBROUTINE TO CHECK DEPENDENCIES +$ V = 'F$Verify(0) +$! P1 = What we are trying to make +$! P2 = Command to make it +$! P3 - P8 What it depends on +$ +$ If F$Search(P1) .Eqs. "" Then Goto Makeit +$ Time = F$CvTime(F$File(P1,"RDT")) +$arg=3 +$Loop: +$ Argument = P'arg +$ If Argument .Eqs. "" Then Goto Exit +$ El=0 +$Loop2: +$ File = F$Element(El," ",Argument) +$ If File .Eqs. " " Then Goto Endl +$ AFile = "" +$Loop3: +$ OFile = AFile +$ AFile = F$Search(File) +$ If AFile .Eqs. "" .Or. AFile .Eqs. OFile Then Goto NextEl +$ If F$CvTime(F$File(AFile,"RDT")) .Ges. Time Then Goto Makeit +$ Goto Loop3 +$NextEL: +$ El = El + 1 +$ Goto Loop2 +$EndL: +$ arg=arg+1 +$ If arg .Le. 8 Then Goto Loop +$ Goto Exit +$ +$Makeit: +$ VV=F$VERIFY(0) +$ write sys$output P2 +$ 'P2 +$ VV='F$Verify(VV) +$Exit: +$ If V Then Set Verify +$ENDSUBROUTINE diff --git a/libs/libpng-src/contrib/gregbook/readpng.c b/libs/libpng-src/contrib/gregbook/readpng.c new file mode 100644 index 000000000..abfc1fb4c --- /dev/null +++ b/libs/libpng-src/contrib/gregbook/readpng.c @@ -0,0 +1,304 @@ +/*--------------------------------------------------------------------------- + + rpng - simple PNG display program readpng.c + + --------------------------------------------------------------------------- + + Copyright (c) 1998-2007 Greg Roelofs. All rights reserved. + + This software is provided "as is," without warranty of any kind, + express or implied. In no event shall the author or contributors + be held liable for any damages arising in any way from the use of + this software. + + The contents of this file are DUAL-LICENSED. You may modify and/or + redistribute this software according to the terms of one of the + following two licenses (at your option): + + + LICENSE 1 ("BSD-like with advertising clause"): + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute + it freely, subject to the following restrictions: + + 1. Redistributions of source code must retain the above copyright + notice, disclaimer, and this list of conditions. + 2. Redistributions in binary form must reproduce the above copyright + notice, disclaimer, and this list of conditions in the documenta- + tion and/or other materials provided with the distribution. + 3. All advertising materials mentioning features or use of this + software must display the following acknowledgment: + + This product includes software developed by Greg Roelofs + and contributors for the book, "PNG: The Definitive Guide," + published by O'Reilly and Associates. + + + LICENSE 2 (GNU GPL v2 or later): + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + ---------------------------------------------------------------------------*/ + +#include +#include + +#include "png.h" /* libpng header; includes zlib.h */ +#include "readpng.h" /* typedefs, common macros, public prototypes */ + +/* future versions of libpng will provide this macro: */ +#ifndef png_jmpbuf +# define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf) +#endif + + +static png_structp png_ptr = NULL; +static png_infop info_ptr = NULL; + +png_uint_32 width, height; +int bit_depth, color_type; +uch *image_data = NULL; + + +void readpng_version_info(void) +{ + fprintf(stderr, " Compiled with libpng %s; using libpng %s.\n", + PNG_LIBPNG_VER_STRING, png_libpng_ver); + fprintf(stderr, " Compiled with zlib %s; using zlib %s.\n", + ZLIB_VERSION, zlib_version); +} + + +/* return value = 0 for success, 1 for bad sig, 2 for bad IHDR, 4 for no mem */ + +int readpng_init(FILE *infile, ulg *pWidth, ulg *pHeight) +{ + uch sig[8]; + + + /* first do a quick check that the file really is a PNG image; could + * have used slightly more general png_sig_cmp() function instead */ + + fread(sig, 1, 8, infile); + if (png_sig_cmp(sig, 0, 8)) + return 1; /* bad signature */ + + + /* could pass pointers to user-defined error handlers instead of NULLs: */ + + png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); + if (!png_ptr) + return 4; /* out of memory */ + + info_ptr = png_create_info_struct(png_ptr); + if (!info_ptr) { + png_destroy_read_struct(&png_ptr, NULL, NULL); + return 4; /* out of memory */ + } + + + /* we could create a second info struct here (end_info), but it's only + * useful if we want to keep pre- and post-IDAT chunk info separated + * (mainly for PNG-aware image editors and converters) */ + + + /* setjmp() must be called in every function that calls a PNG-reading + * libpng function */ + + if (setjmp(png_jmpbuf(png_ptr))) { + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + return 2; + } + + + png_init_io(png_ptr, infile); + png_set_sig_bytes(png_ptr, 8); /* we already read the 8 signature bytes */ + + png_read_info(png_ptr, info_ptr); /* read all PNG info up to image data */ + + + /* alternatively, could make separate calls to png_get_image_width(), + * etc., but want bit_depth and color_type for later [don't care about + * compression_type and filter_type => NULLs] */ + + png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, + NULL, NULL, NULL); + *pWidth = width; + *pHeight = height; + + + /* OK, that's all we need for now; return happy */ + + return 0; +} + + + + +/* returns 0 if succeeds, 1 if fails due to no bKGD chunk, 2 if libpng error; + * scales values to 8-bit if necessary */ + +int readpng_get_bgcolor(uch *red, uch *green, uch *blue) +{ + png_color_16p pBackground; + + + /* setjmp() must be called in every function that calls a PNG-reading + * libpng function */ + + if (setjmp(png_jmpbuf(png_ptr))) { + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + return 2; + } + + + if (!png_get_valid(png_ptr, info_ptr, PNG_INFO_bKGD)) + return 1; + + /* it is not obvious from the libpng documentation, but this function + * takes a pointer to a pointer, and it always returns valid red, green + * and blue values, regardless of color_type: */ + + png_get_bKGD(png_ptr, info_ptr, &pBackground); + + + /* however, it always returns the raw bKGD data, regardless of any + * bit-depth transformations, so check depth and adjust if necessary */ + + if (bit_depth == 16) { + *red = pBackground->red >> 8; + *green = pBackground->green >> 8; + *blue = pBackground->blue >> 8; + } else if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) { + if (bit_depth == 1) + *red = *green = *blue = pBackground->gray? 255 : 0; + else if (bit_depth == 2) + *red = *green = *blue = (255/3) * pBackground->gray; + else /* bit_depth == 4 */ + *red = *green = *blue = (255/15) * pBackground->gray; + } else { + *red = (uch)pBackground->red; + *green = (uch)pBackground->green; + *blue = (uch)pBackground->blue; + } + + return 0; +} + + + + +/* display_exponent == LUT_exponent * CRT_exponent */ + +uch *readpng_get_image(double display_exponent, int *pChannels, ulg *pRowbytes) +{ + double gamma; + png_uint_32 i, rowbytes; + png_bytepp row_pointers = NULL; + + + /* setjmp() must be called in every function that calls a PNG-reading + * libpng function */ + + if (setjmp(png_jmpbuf(png_ptr))) { + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + return NULL; + } + + + /* expand palette images to RGB, low-bit-depth grayscale images to 8 bits, + * transparency chunks to full alpha channel; strip 16-bit-per-sample + * images to 8 bits per sample; and convert grayscale to RGB[A] */ + + if (color_type == PNG_COLOR_TYPE_PALETTE) + png_set_expand(png_ptr); + if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) + png_set_expand(png_ptr); + if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) + png_set_expand(png_ptr); + if (bit_depth == 16) + png_set_strip_16(png_ptr); + if (color_type == PNG_COLOR_TYPE_GRAY || + color_type == PNG_COLOR_TYPE_GRAY_ALPHA) + png_set_gray_to_rgb(png_ptr); + + + /* unlike the example in the libpng documentation, we have *no* idea where + * this file may have come from--so if it doesn't have a file gamma, don't + * do any correction ("do no harm") */ + + if (png_get_gAMA(png_ptr, info_ptr, &gamma)) + png_set_gamma(png_ptr, display_exponent, gamma); + + + /* all transformations have been registered; now update info_ptr data, + * get rowbytes and channels, and allocate image memory */ + + png_read_update_info(png_ptr, info_ptr); + + *pRowbytes = rowbytes = png_get_rowbytes(png_ptr, info_ptr); + *pChannels = (int)png_get_channels(png_ptr, info_ptr); + + if ((image_data = (uch *)malloc(rowbytes*height)) == NULL) { + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + return NULL; + } + if ((row_pointers = (png_bytepp)malloc(height*sizeof(png_bytep))) == NULL) { + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + free(image_data); + image_data = NULL; + return NULL; + } + + Trace((stderr, "readpng_get_image: channels = %d, rowbytes = %ld, height = %ld\n", *pChannels, rowbytes, height)); + + + /* set the individual row_pointers to point at the correct offsets */ + + for (i = 0; i < height; ++i) + row_pointers[i] = image_data + i*rowbytes; + + + /* now we can go ahead and just read the whole image */ + + png_read_image(png_ptr, row_pointers); + + + /* and we're done! (png_read_end() can be omitted if no processing of + * post-IDAT text/time/etc. is desired) */ + + free(row_pointers); + row_pointers = NULL; + + png_read_end(png_ptr, NULL); + + return image_data; +} + + +void readpng_cleanup(int free_image_data) +{ + if (free_image_data && image_data) { + free(image_data); + image_data = NULL; + } + + if (png_ptr && info_ptr) { + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + png_ptr = NULL; + info_ptr = NULL; + } +} diff --git a/libs/libpng-src/contrib/gregbook/readpng.h b/libs/libpng-src/contrib/gregbook/readpng.h new file mode 100644 index 000000000..fad9fe3b4 --- /dev/null +++ b/libs/libpng-src/contrib/gregbook/readpng.h @@ -0,0 +1,88 @@ +/*--------------------------------------------------------------------------- + + rpng - simple PNG display program readpng.h + + --------------------------------------------------------------------------- + + Copyright (c) 1998-2007 Greg Roelofs. All rights reserved. + + This software is provided "as is," without warranty of any kind, + express or implied. In no event shall the author or contributors + be held liable for any damages arising in any way from the use of + this software. + + The contents of this file are DUAL-LICENSED. You may modify and/or + redistribute this software according to the terms of one of the + following two licenses (at your option): + + + LICENSE 1 ("BSD-like with advertising clause"): + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute + it freely, subject to the following restrictions: + + 1. Redistributions of source code must retain the above copyright + notice, disclaimer, and this list of conditions. + 2. Redistributions in binary form must reproduce the above copyright + notice, disclaimer, and this list of conditions in the documenta- + tion and/or other materials provided with the distribution. + 3. All advertising materials mentioning features or use of this + software must display the following acknowledgment: + + This product includes software developed by Greg Roelofs + and contributors for the book, "PNG: The Definitive Guide," + published by O'Reilly and Associates. + + + LICENSE 2 (GNU GPL v2 or later): + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + ---------------------------------------------------------------------------*/ + +#ifndef TRUE +# define TRUE 1 +# define FALSE 0 +#endif + +#ifndef MAX +# define MAX(a,b) ((a) > (b)? (a) : (b)) +# define MIN(a,b) ((a) < (b)? (a) : (b)) +#endif + +#ifdef DEBUG +# define Trace(x) {fprintf x ; fflush(stderr); fflush(stdout);} +#else +# define Trace(x) ; +#endif + +typedef unsigned char uch; +typedef unsigned short ush; +typedef unsigned long ulg; + + +/* prototypes for public functions in readpng.c */ + +void readpng_version_info(void); + +int readpng_init(FILE *infile, ulg *pWidth, ulg *pHeight); + +int readpng_get_bgcolor(uch *bg_red, uch *bg_green, uch *bg_blue); + +uch *readpng_get_image(double display_exponent, int *pChannels, + ulg *pRowbytes); + +void readpng_cleanup(int free_image_data); diff --git a/libs/libpng-src/contrib/gregbook/readpng2.c b/libs/libpng-src/contrib/gregbook/readpng2.c new file mode 100644 index 000000000..2ee6b681f --- /dev/null +++ b/libs/libpng-src/contrib/gregbook/readpng2.c @@ -0,0 +1,648 @@ +/*--------------------------------------------------------------------------- + + rpng2 - progressive-model PNG display program readpng2.c + + --------------------------------------------------------------------------- + + Copyright (c) 1998-2007 Greg Roelofs. All rights reserved. + + This software is provided "as is," without warranty of any kind, + express or implied. In no event shall the author or contributors + be held liable for any damages arising in any way from the use of + this software. + + The contents of this file are DUAL-LICENSED. You may modify and/or + redistribute this software according to the terms of one of the + following two licenses (at your option): + + + LICENSE 1 ("BSD-like with advertising clause"): + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute + it freely, subject to the following restrictions: + + 1. Redistributions of source code must retain the above copyright + notice, disclaimer, and this list of conditions. + 2. Redistributions in binary form must reproduce the above copyright + notice, disclaimer, and this list of conditions in the documenta- + tion and/or other materials provided with the distribution. + 3. All advertising materials mentioning features or use of this + software must display the following acknowledgment: + + This product includes software developed by Greg Roelofs + and contributors for the book, "PNG: The Definitive Guide," + published by O'Reilly and Associates. + + + LICENSE 2 (GNU GPL v2 or later): + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + ---------------------------------------------------------------------------*/ + + +#include /* for exit() prototype */ + +#include "png.h" /* libpng header; includes zlib.h and setjmp.h */ +#include "readpng2.h" /* typedefs, common macros, public prototypes */ + + +/* local prototypes */ + +static void readpng2_info_callback(png_structp png_ptr, png_infop info_ptr); +static void readpng2_row_callback(png_structp png_ptr, png_bytep new_row, + png_uint_32 row_num, int pass); +static void readpng2_end_callback(png_structp png_ptr, png_infop info_ptr); +static void readpng2_error_handler(png_structp png_ptr, png_const_charp msg); + + + + +void readpng2_version_info(void) +{ +#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) && \ + (defined(__i386__) || defined(_M_IX86) || defined(__x86_64__)) && \ + defined(PNG_LIBPNG_VER) && (PNG_LIBPNG_VER >= 10200) + /* + * WARNING: This preprocessor approach means that the following code + * cannot be used with a libpng DLL older than 1.2.0--the + * compiled-in symbols for the new functions will not exist. + * (Could use dlopen() and dlsym() on Unix and corresponding + * calls for Windows, but not portable...) + */ + { + int mmxsupport = png_mmx_support(); + if (mmxsupport < 0) + fprintf(stderr, " Compiled with libpng %s; using libpng %s " + "without MMX support.\n", PNG_LIBPNG_VER_STRING, png_libpng_ver); + else { + int compilerID; + png_uint_32 mmx_mask = png_get_mmx_flagmask( + PNG_SELECT_READ | PNG_SELECT_WRITE, &compilerID); + + fprintf(stderr, " Compiled with libpng %s; using libpng %s " + "with MMX support\n (%s version).", PNG_LIBPNG_VER_STRING, + png_libpng_ver, compilerID == 1? "MSVC++" : + (compilerID == 2? "GNU C" : "unknown")); + fprintf(stderr, " Processor (x86%s) %s MMX instructions.\n", +#if defined(__x86_64__) + "_64", +#else + "", +#endif + mmxsupport? "supports" : "does not support"); + if (mmxsupport > 0) { + int num_optims = 0; + + fprintf(stderr, + " Potential MMX optimizations supported by libpng:\n"); + if (mmx_mask & PNG_ASM_FLAG_MMX_READ_FILTER_SUB) + ++num_optims; + if (mmx_mask & PNG_ASM_FLAG_MMX_READ_FILTER_UP) + ++num_optims; + if (mmx_mask & PNG_ASM_FLAG_MMX_READ_FILTER_AVG) + ++num_optims; + if (mmx_mask & PNG_ASM_FLAG_MMX_READ_FILTER_PAETH) + ++num_optims; + if (num_optims) + fprintf(stderr, + " decoding %s row filters (reading)\n", + (num_optims == 4)? "all non-trivial" : "some"); + if (mmx_mask & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW) { + fprintf(stderr, " combining rows (reading)\n"); + ++num_optims; + } + if (mmx_mask & PNG_ASM_FLAG_MMX_READ_INTERLACE) { + fprintf(stderr, + " expanding interlacing (reading)\n"); + ++num_optims; + } + mmx_mask &= ~( PNG_ASM_FLAG_MMX_READ_COMBINE_ROW \ + | PNG_ASM_FLAG_MMX_READ_INTERLACE \ + | PNG_ASM_FLAG_MMX_READ_FILTER_SUB \ + | PNG_ASM_FLAG_MMX_READ_FILTER_UP \ + | PNG_ASM_FLAG_MMX_READ_FILTER_AVG \ + | PNG_ASM_FLAG_MMX_READ_FILTER_PAETH ); + if (mmx_mask) { + fprintf(stderr, " other (unknown)\n"); + ++num_optims; + } + if (num_optims == 0) + fprintf(stderr, " (none)\n"); + } + } + } +#else + fprintf(stderr, " Compiled with libpng %s; using libpng %s " + "without MMX support.\n", PNG_LIBPNG_VER_STRING, png_libpng_ver); +#endif + + fprintf(stderr, " Compiled with zlib %s; using zlib %s.\n", + ZLIB_VERSION, zlib_version); +} + + + + +int readpng2_check_sig(uch *sig, int num) +{ + return !png_sig_cmp(sig, 0, num); +} + + + + +/* returns 0 for success, 2 for libpng problem, 4 for out of memory */ + +int readpng2_init(mainprog_info *mainprog_ptr) +{ + png_structp png_ptr; /* note: temporary variables! */ + png_infop info_ptr; + + + /* could also replace libpng warning-handler (final NULL), but no need: */ + + png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, mainprog_ptr, + readpng2_error_handler, NULL); + if (!png_ptr) + return 4; /* out of memory */ + + info_ptr = png_create_info_struct(png_ptr); + if (!info_ptr) { + png_destroy_read_struct(&png_ptr, NULL, NULL); + return 4; /* out of memory */ + } + + + /* we could create a second info struct here (end_info), but it's only + * useful if we want to keep pre- and post-IDAT chunk info separated + * (mainly for PNG-aware image editors and converters) */ + + + /* setjmp() must be called in every function that calls a PNG-reading + * libpng function, unless an alternate error handler was installed-- + * but compatible error handlers must either use longjmp() themselves + * (as in this program) or exit immediately, so here we are: */ + + if (setjmp(mainprog_ptr->jmpbuf)) { + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + return 2; + } + + +#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED + /* prepare the reader to ignore all recognized chunks whose data won't be + * used, i.e., all chunks recognized by libpng except for IHDR, PLTE, IDAT, + * IEND, tRNS, bKGD, gAMA, and sRGB (small performance improvement) */ + { + /* These byte strings were copied from png.h. If a future libpng + * version recognizes more chunks, add them to this list. If a + * future version of readpng2.c recognizes more chunks, delete them + * from this list. */ + static const png_byte chunks_to_ignore[] = { + 99, 72, 82, 77, '\0', /* cHRM */ + 104, 73, 83, 84, '\0', /* hIST */ + 105, 67, 67, 80, '\0', /* iCCP */ + 105, 84, 88, 116, '\0', /* iTXt */ + 111, 70, 70, 115, '\0', /* oFFs */ + 112, 67, 65, 76, '\0', /* pCAL */ + 112, 72, 89, 115, '\0', /* pHYs */ + 115, 66, 73, 84, '\0', /* sBIT */ + 115, 67, 65, 76, '\0', /* sCAL */ + 115, 80, 76, 84, '\0', /* sPLT */ + 115, 84, 69, 82, '\0', /* sTER */ + 116, 69, 88, 116, '\0', /* tEXt */ + 116, 73, 77, 69, '\0', /* tIME */ + 122, 84, 88, 116, '\0' /* zTXt */ + }; + + png_set_keep_unknown_chunks(png_ptr, 1 /* PNG_HANDLE_CHUNK_NEVER */, + chunks_to_ignore, sizeof(chunks_to_ignore)/5); + } +#endif /* PNG_UNKNOWN_CHUNKS_SUPPORTED */ + + + /* instead of doing png_init_io() here, now we set up our callback + * functions for progressive decoding */ + + png_set_progressive_read_fn(png_ptr, mainprog_ptr, + readpng2_info_callback, readpng2_row_callback, readpng2_end_callback); + + + /* + * may as well enable or disable MMX routines here, if supported; + * + * to enable all: mask = png_get_mmx_flagmask ( + * PNG_SELECT_READ | PNG_SELECT_WRITE, &compilerID); + * flags = png_get_asm_flags (png_ptr); + * flags |= mask; + * png_set_asm_flags (png_ptr, flags); + * + * to disable all: mask = png_get_mmx_flagmask ( + * PNG_SELECT_READ | PNG_SELECT_WRITE, &compilerID); + * flags = png_get_asm_flags (png_ptr); + * flags &= ~mask; + * png_set_asm_flags (png_ptr, flags); + */ + +#if (defined(__i386__) || defined(_M_IX86) || defined(__x86_64__)) && \ + defined(PNG_LIBPNG_VER) && (PNG_LIBPNG_VER >= 10200) + /* + * WARNING: This preprocessor approach means that the following code + * cannot be used with a libpng DLL older than 1.2.0--the + * compiled-in symbols for the new functions will not exist. + * (Could use dlopen() and dlsym() on Unix and corresponding + * calls for Windows, but not portable...) + */ + { +#ifdef PNG_ASSEMBLER_CODE_SUPPORTED + png_uint_32 mmx_disable_mask = 0; + png_uint_32 asm_flags, mmx_mask; + int compilerID; + + if (mainprog_ptr->nommxfilters) + mmx_disable_mask |= ( PNG_ASM_FLAG_MMX_READ_FILTER_SUB \ + | PNG_ASM_FLAG_MMX_READ_FILTER_UP \ + | PNG_ASM_FLAG_MMX_READ_FILTER_AVG \ + | PNG_ASM_FLAG_MMX_READ_FILTER_PAETH ); + if (mainprog_ptr->nommxcombine) + mmx_disable_mask |= PNG_ASM_FLAG_MMX_READ_COMBINE_ROW; + if (mainprog_ptr->nommxinterlace) + mmx_disable_mask |= PNG_ASM_FLAG_MMX_READ_INTERLACE; + asm_flags = png_get_asm_flags(png_ptr); + png_set_asm_flags(png_ptr, asm_flags & ~mmx_disable_mask); + + + /* Now query libpng's asm settings, just for yuks. Note that this + * differs from the querying of its *potential* MMX capabilities + * in readpng2_version_info(); this is true runtime verification. */ + + asm_flags = png_get_asm_flags(png_ptr); + mmx_mask = png_get_mmx_flagmask(PNG_SELECT_READ | PNG_SELECT_WRITE, + &compilerID); + if (asm_flags & PNG_ASM_FLAG_MMX_SUPPORT_COMPILED) + fprintf(stderr, + " MMX support (%s version) is compiled into libpng\n", + compilerID == 1? "MSVC++" : + (compilerID == 2? "GNU C" : "unknown")); + else + fprintf(stderr, " MMX support is not compiled into libpng\n"); + fprintf(stderr, " MMX instructions are %ssupported by CPU\n", + (asm_flags & PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU)? "" : "not "); + fprintf(stderr, " MMX read support for combining rows is %sabled\n", + (asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)? "en" : "dis"); + fprintf(stderr, + " MMX read support for expanding interlacing is %sabled\n", + (asm_flags & PNG_ASM_FLAG_MMX_READ_INTERLACE)? "en" : "dis"); + fprintf(stderr, " MMX read support for \"sub\" filter is %sabled\n", + (asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_SUB)? "en" : "dis"); + fprintf(stderr, " MMX read support for \"up\" filter is %sabled\n", + (asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_UP)? "en" : "dis"); + fprintf(stderr, " MMX read support for \"avg\" filter is %sabled\n", + (asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_AVG)? "en" : "dis"); + fprintf(stderr, " MMX read support for \"Paeth\" filter is %sabled\n", + (asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_PAETH)? "en" : "dis"); + asm_flags &= (mmx_mask & ~( PNG_ASM_FLAG_MMX_READ_COMBINE_ROW \ + | PNG_ASM_FLAG_MMX_READ_INTERLACE \ + | PNG_ASM_FLAG_MMX_READ_FILTER_SUB \ + | PNG_ASM_FLAG_MMX_READ_FILTER_UP \ + | PNG_ASM_FLAG_MMX_READ_FILTER_AVG \ + | PNG_ASM_FLAG_MMX_READ_FILTER_PAETH )); + if (asm_flags) + fprintf(stderr, + " additional MMX support is also enabled (0x%02lx)\n", + asm_flags); +#else /* !PNG_ASSEMBLER_CODE_SUPPORTED */ + fprintf(stderr, " MMX querying is disabled in libpng.\n"); +#endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */ + } +#endif + + + /* make sure we save our pointers for use in readpng2_decode_data() */ + + mainprog_ptr->png_ptr = png_ptr; + mainprog_ptr->info_ptr = info_ptr; + + + /* and that's all there is to initialization */ + + return 0; +} + + + + +/* returns 0 for success, 2 for libpng (longjmp) problem */ + +int readpng2_decode_data(mainprog_info *mainprog_ptr, uch *rawbuf, ulg length) +{ + png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr; + png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr; + + + /* setjmp() must be called in every function that calls a PNG-reading + * libpng function */ + + if (setjmp(mainprog_ptr->jmpbuf)) { + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + mainprog_ptr->png_ptr = NULL; + mainprog_ptr->info_ptr = NULL; + return 2; + } + + + /* hand off the next chunk of input data to libpng for decoding */ + + png_process_data(png_ptr, info_ptr, rawbuf, length); + + return 0; +} + + + + +static void readpng2_info_callback(png_structp png_ptr, png_infop info_ptr) +{ + mainprog_info *mainprog_ptr; + int color_type, bit_depth; + png_uint_32 width, height; + double gamma; + + + /* setjmp() doesn't make sense here, because we'd either have to exit(), + * longjmp() ourselves, or return control to libpng, which doesn't want + * to see us again. By not doing anything here, libpng will instead jump + * to readpng2_decode_data(), which can return an error value to the main + * program. */ + + + /* retrieve the pointer to our special-purpose struct, using the png_ptr + * that libpng passed back to us (i.e., not a global this time--there's + * no real difference for a single image, but for a multithreaded browser + * decoding several PNG images at the same time, one needs to avoid mixing + * up different images' structs) */ + + mainprog_ptr = png_get_progressive_ptr(png_ptr); + + if (mainprog_ptr == NULL) { /* we be hosed */ + fprintf(stderr, + "readpng2 error: main struct not recoverable in info_callback.\n"); + fflush(stderr); + return; + /* + * Alternatively, we could call our error-handler just like libpng + * does, which would effectively terminate the program. Since this + * can only happen if png_ptr gets redirected somewhere odd or the + * main PNG struct gets wiped, we're probably toast anyway. (If + * png_ptr itself is NULL, we would not have been called.) + */ + } + + + /* this is just like in the non-progressive case */ + + png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, + NULL, NULL, NULL); + mainprog_ptr->width = (ulg)width; + mainprog_ptr->height = (ulg)height; + + + /* since we know we've read all of the PNG file's "header" (i.e., up + * to IDAT), we can check for a background color here */ + + if (mainprog_ptr->need_bgcolor && + png_get_valid(png_ptr, info_ptr, PNG_INFO_bKGD)) + { + png_color_16p pBackground; + + /* it is not obvious from the libpng documentation, but this function + * takes a pointer to a pointer, and it always returns valid red, + * green and blue values, regardless of color_type: */ + png_get_bKGD(png_ptr, info_ptr, &pBackground); + + /* however, it always returns the raw bKGD data, regardless of any + * bit-depth transformations, so check depth and adjust if necessary */ + if (bit_depth == 16) { + mainprog_ptr->bg_red = pBackground->red >> 8; + mainprog_ptr->bg_green = pBackground->green >> 8; + mainprog_ptr->bg_blue = pBackground->blue >> 8; + } else if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) { + if (bit_depth == 1) + mainprog_ptr->bg_red = mainprog_ptr->bg_green = + mainprog_ptr->bg_blue = pBackground->gray? 255 : 0; + else if (bit_depth == 2) + mainprog_ptr->bg_red = mainprog_ptr->bg_green = + mainprog_ptr->bg_blue = (255/3) * pBackground->gray; + else /* bit_depth == 4 */ + mainprog_ptr->bg_red = mainprog_ptr->bg_green = + mainprog_ptr->bg_blue = (255/15) * pBackground->gray; + } else { + mainprog_ptr->bg_red = (uch)pBackground->red; + mainprog_ptr->bg_green = (uch)pBackground->green; + mainprog_ptr->bg_blue = (uch)pBackground->blue; + } + } + + + /* as before, let libpng expand palette images to RGB, low-bit-depth + * grayscale images to 8 bits, transparency chunks to full alpha channel; + * strip 16-bit-per-sample images to 8 bits per sample; and convert + * grayscale to RGB[A] */ + + if (color_type == PNG_COLOR_TYPE_PALETTE) + png_set_expand(png_ptr); + if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) + png_set_expand(png_ptr); + if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) + png_set_expand(png_ptr); + if (bit_depth == 16) + png_set_strip_16(png_ptr); + if (color_type == PNG_COLOR_TYPE_GRAY || + color_type == PNG_COLOR_TYPE_GRAY_ALPHA) + png_set_gray_to_rgb(png_ptr); + + + /* Unlike the basic viewer, which was designed to operate on local files, + * this program is intended to simulate a web browser--even though we + * actually read from a local file, too. But because we are pretending + * that most of the images originate on the Internet, we follow the recom- + * mendation of the sRGB proposal and treat unlabelled images (no gAMA + * chunk) as existing in the sRGB color space. That is, we assume that + * such images have a file gamma of 0.45455, which corresponds to a PC-like + * display system. This change in assumptions will have no effect on a + * PC-like system, but on a Mac, SGI, NeXT or other system with a non- + * identity lookup table, it will darken unlabelled images, which effec- + * tively favors images from PC-like systems over those originating on + * the local platform. Note that mainprog_ptr->display_exponent is the + * "gamma" value for the entire display system, i.e., the product of + * LUT_exponent and CRT_exponent. */ + + if (png_get_gAMA(png_ptr, info_ptr, &gamma)) + png_set_gamma(png_ptr, mainprog_ptr->display_exponent, gamma); + else + png_set_gamma(png_ptr, mainprog_ptr->display_exponent, 0.45455); + + + /* we'll let libpng expand interlaced images, too */ + + mainprog_ptr->passes = png_set_interlace_handling(png_ptr); + + + /* all transformations have been registered; now update info_ptr data and + * then get rowbytes and channels */ + + png_read_update_info(png_ptr, info_ptr); + + mainprog_ptr->rowbytes = (int)png_get_rowbytes(png_ptr, info_ptr); + mainprog_ptr->channels = png_get_channels(png_ptr, info_ptr); + + + /* Call the main program to allocate memory for the image buffer and + * initialize windows and whatnot. (The old-style function-pointer + * invocation is used for compatibility with a few supposedly ANSI + * compilers that nevertheless barf on "fn_ptr()"-style syntax.) */ + + (*mainprog_ptr->mainprog_init)(); + + + /* and that takes care of initialization */ + + return; +} + + + + + +static void readpng2_row_callback(png_structp png_ptr, png_bytep new_row, + png_uint_32 row_num, int pass) +{ + mainprog_info *mainprog_ptr; + + + /* first check whether the row differs from the previous pass; if not, + * nothing to combine or display */ + + if (!new_row) + return; + + + /* retrieve the pointer to our special-purpose struct so we can access + * the old rows and image-display callback function */ + + mainprog_ptr = png_get_progressive_ptr(png_ptr); + + + /* save the pass number for optional use by the front end */ + + mainprog_ptr->pass = pass; + + + /* have libpng either combine the new row data with the existing row data + * from previous passes (if interlaced) or else just copy the new row + * into the main program's image buffer */ + + png_progressive_combine_row(png_ptr, mainprog_ptr->row_pointers[row_num], + new_row); + + + /* finally, call the display routine in the main program with the number + * of the row we just updated */ + + (*mainprog_ptr->mainprog_display_row)(row_num); + + + /* and we're ready for more */ + + return; +} + + + + + +static void readpng2_end_callback(png_structp png_ptr, png_infop info_ptr) +{ + mainprog_info *mainprog_ptr; + + + /* retrieve the pointer to our special-purpose struct */ + + mainprog_ptr = png_get_progressive_ptr(png_ptr); + + + /* let the main program know that it should flush any buffered image + * data to the display now and set a "done" flag or whatever, but note + * that it SHOULD NOT DESTROY THE PNG STRUCTS YET--in other words, do + * NOT call readpng2_cleanup() either here or in the finish_display() + * routine; wait until control returns to the main program via + * readpng2_decode_data() */ + + (*mainprog_ptr->mainprog_finish_display)(); + + + /* all done */ + + return; +} + + + + + +void readpng2_cleanup(mainprog_info *mainprog_ptr) +{ + png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr; + png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr; + + if (png_ptr && info_ptr) + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + + mainprog_ptr->png_ptr = NULL; + mainprog_ptr->info_ptr = NULL; +} + + + + + +static void readpng2_error_handler(png_structp png_ptr, png_const_charp msg) +{ + mainprog_info *mainprog_ptr; + + /* This function, aside from the extra step of retrieving the "error + * pointer" (below) and the fact that it exists within the application + * rather than within libpng, is essentially identical to libpng's + * default error handler. The second point is critical: since both + * setjmp() and longjmp() are called from the same code, they are + * guaranteed to have compatible notions of how big a jmp_buf is, + * regardless of whether _BSD_SOURCE or anything else has (or has not) + * been defined. */ + + fprintf(stderr, "readpng2 libpng error: %s\n", msg); + fflush(stderr); + + mainprog_ptr = png_get_error_ptr(png_ptr); + if (mainprog_ptr == NULL) { /* we are completely hosed now */ + fprintf(stderr, + "readpng2 severe error: jmpbuf not recoverable; terminating.\n"); + fflush(stderr); + exit(99); + } + + longjmp(mainprog_ptr->jmpbuf, 1); +} diff --git a/libs/libpng-src/contrib/gregbook/readpng2.h b/libs/libpng-src/contrib/gregbook/readpng2.h new file mode 100644 index 000000000..fbfffb4ba --- /dev/null +++ b/libs/libpng-src/contrib/gregbook/readpng2.h @@ -0,0 +1,121 @@ +/*--------------------------------------------------------------------------- + + rpng2 - progressive-model PNG display program readpng2.h + + --------------------------------------------------------------------------- + + Copyright (c) 1998-2008 Greg Roelofs. All rights reserved. + + This software is provided "as is," without warranty of any kind, + express or implied. In no event shall the author or contributors + be held liable for any damages arising in any way from the use of + this software. + + The contents of this file are DUAL-LICENSED. You may modify and/or + redistribute this software according to the terms of one of the + following two licenses (at your option): + + + LICENSE 1 ("BSD-like with advertising clause"): + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute + it freely, subject to the following restrictions: + + 1. Redistributions of source code must retain the above copyright + notice, disclaimer, and this list of conditions. + 2. Redistributions in binary form must reproduce the above copyright + notice, disclaimer, and this list of conditions in the documenta- + tion and/or other materials provided with the distribution. + 3. All advertising materials mentioning features or use of this + software must display the following acknowledgment: + + This product includes software developed by Greg Roelofs + and contributors for the book, "PNG: The Definitive Guide," + published by O'Reilly and Associates. + + + LICENSE 2 (GNU GPL v2 or later): + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + ---------------------------------------------------------------------------*/ + +#ifndef TRUE +# define TRUE 1 +# define FALSE 0 +#endif + +#ifndef MAX +# define MAX(a,b) ((a) > (b)? (a) : (b)) +# define MIN(a,b) ((a) < (b)? (a) : (b)) +#endif + +#ifdef DEBUG +# define Trace(x) {fprintf x ; fflush(stderr); fflush(stdout);} +#else +# define Trace(x) ; +#endif + +enum rpng2_states { + kPreInit = 0, + kWindowInit, + kDone +}; + +typedef unsigned char uch; +typedef unsigned short ush; +typedef unsigned long ulg; + +typedef struct _mainprog_info { + double display_exponent; + ulg width; + ulg height; + void *png_ptr; + void *info_ptr; + void (*mainprog_init)(void); + void (*mainprog_display_row)(ulg row_num); + void (*mainprog_finish_display)(void); + uch *image_data; + uch **row_pointers; + jmp_buf jmpbuf; + int passes; /* not used */ + int pass; + int rowbytes; + int channels; + int need_bgcolor; +#if (defined(__i386__) || defined(_M_IX86) || defined(__x86_64__)) + int nommxfilters; + int nommxcombine; + int nommxinterlace; +#endif + int state; + uch bg_red; + uch bg_green; + uch bg_blue; +} mainprog_info; + + +/* prototypes for public functions in readpng2.c */ + +void readpng2_version_info(void); + +int readpng2_check_sig(uch *sig, int num); + +int readpng2_init(mainprog_info *mainprog_ptr); + +int readpng2_decode_data(mainprog_info *mainprog_ptr, uch *rawbuf, ulg length); + +void readpng2_cleanup(mainprog_info *mainprog_ptr); diff --git a/libs/libpng-src/contrib/gregbook/readppm.c b/libs/libpng-src/contrib/gregbook/readppm.c new file mode 100644 index 000000000..be9a56d95 --- /dev/null +++ b/libs/libpng-src/contrib/gregbook/readppm.c @@ -0,0 +1,179 @@ +/*--------------------------------------------------------------------------- + + rpng - simple PNG display program readppm.c + + --------------------------------------------------------------------------- + + This is a special-purpose replacement for readpng.c that allows binary + PPM files to be used in place of PNG images. + + --------------------------------------------------------------------------- + + Copyright (c) 1998-2007 Greg Roelofs. All rights reserved. + + This software is provided "as is," without warranty of any kind, + express or implied. In no event shall the author or contributors + be held liable for any damages arising in any way from the use of + this software. + + The contents of this file are DUAL-LICENSED. You may modify and/or + redistribute this software according to the terms of one of the + following two licenses (at your option): + + + LICENSE 1 ("BSD-like with advertising clause"): + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute + it freely, subject to the following restrictions: + + 1. Redistributions of source code must retain the above copyright + notice, disclaimer, and this list of conditions. + 2. Redistributions in binary form must reproduce the above copyright + notice, disclaimer, and this list of conditions in the documenta- + tion and/or other materials provided with the distribution. + 3. All advertising materials mentioning features or use of this + software must display the following acknowledgment: + + This product includes software developed by Greg Roelofs + and contributors for the book, "PNG: The Definitive Guide," + published by O'Reilly and Associates. + + + LICENSE 2 (GNU GPL v2 or later): + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + ---------------------------------------------------------------------------*/ + +#include +#include + +#include "readpng.h" /* typedefs, common macros, public prototypes */ + + +ulg width, height; +int bit_depth, color_type, channels; +uch *image_data = NULL; +FILE *saved_infile; + + +void readpng_version_info() +{ + fprintf(stderr, " Compiled without libpng, zlib or PBMPLUS/NetPBM.\n"); +} + + +/* return value = 0 for success, 1 for bad sig, 2 for bad IHDR, 4 for no mem */ + +int readpng_init(FILE *infile, ulg *pWidth, ulg *pHeight) +{ + static uch ppmline[256]; + int maxval; + + + saved_infile = infile; + + fgets(ppmline, 256, infile); + if (ppmline[0] != 'P' || ppmline[1] != '6') { + fprintf(stderr, "ERROR: not a PPM file\n"); + return 1; + } + /* possible color types: P5 = grayscale (0), P6 = RGB (2), P8 = RGBA (6) */ + if (ppmline[1] == '6') { + color_type = 2; + channels = 3; + } else if (ppmline[1] == '8') { + color_type = 6; + channels = 4; + } else /* if (ppmline[1] == '5') */ { + color_type = 0; + channels = 1; + } + + do { + fgets(ppmline, 256, infile); + } while (ppmline[0] == '#'); + sscanf(ppmline, "%lu %lu", &width, &height); + + do { + fgets(ppmline, 256, infile); + } while (ppmline[0] == '#'); + sscanf(ppmline, "%d", &maxval); + if (maxval != 255) { + fprintf(stderr, "ERROR: maxval = %d\n", maxval); + return 2; + } + bit_depth = 8; + + *pWidth = width; + *pHeight = height; + + return 0; +} + + + + +/* returns 0 if succeeds, 1 if fails due to no bKGD chunk, 2 if libpng error; + * scales values to 8-bit if necessary */ + +int readpng_get_bgcolor(uch *red, uch *green, uch *blue) +{ + return 1; +} + + + + +/* display_exponent == LUT_exponent * CRT_exponent */ + +uch *readpng_get_image(double display_exponent, int *pChannels, ulg *pRowbytes) +{ + ulg rowbytes; + + + /* expand palette images to RGB, low-bit-depth grayscale images to 8 bits, + * transparency chunks to full alpha channel; strip 16-bit-per-sample + * images to 8 bits per sample; and convert grayscale to RGB[A] */ + + /* GRR WARNING: grayscale needs to be expanded and channels reset! */ + + *pRowbytes = rowbytes = channels*width; + *pChannels = channels; + + if ((image_data = (uch *)malloc(rowbytes*height)) == NULL) { + return NULL; + } + + Trace((stderr, "readpng_get_image: rowbytes = %ld, height = %ld\n", rowbytes, height)); + + + /* now we can go ahead and just read the whole image */ + + fread(image_data, 1L, rowbytes*height, saved_infile); + + + return image_data; +} + + +void readpng_cleanup(int free_image_data) +{ + if (free_image_data && image_data) { + free(image_data); + image_data = NULL; + } +} diff --git a/libs/libpng-src/contrib/gregbook/rpng-win.c b/libs/libpng-src/contrib/gregbook/rpng-win.c new file mode 100644 index 000000000..20209611e --- /dev/null +++ b/libs/libpng-src/contrib/gregbook/rpng-win.c @@ -0,0 +1,684 @@ +/*--------------------------------------------------------------------------- + + rpng - simple PNG display program rpng-win.c + + This program decodes and displays PNG images, with gamma correction and + optionally with a user-specified background color (in case the image has + transparency). It is very nearly the most basic PNG viewer possible. + This version is for 32-bit Windows; it may compile under 16-bit Windows + with a little tweaking (or maybe not). + + to do: + - handle quoted command-line args (especially filenames with spaces) + - have minimum window width: oh well + - use %.1023s to simplify truncation of title-bar string? + + --------------------------------------------------------------------------- + + Changelog: + - 1.00: initial public release + - 1.01: modified to allow abbreviated options; fixed long/ulong mis- + match; switched to png_jmpbuf() macro + - 1.02: added extra set of parentheses to png_jmpbuf() macro; fixed + command-line parsing bug + - 1.10: enabled "message window"/console (thanks to David Geldreich) + - 2.00: dual-licensed (added GNU GPL) + - 2.01: fixed improper display of usage screen on PNG error(s) + + --------------------------------------------------------------------------- + + Copyright (c) 1998-2008 Greg Roelofs. All rights reserved. + + This software is provided "as is," without warranty of any kind, + express or implied. In no event shall the author or contributors + be held liable for any damages arising in any way from the use of + this software. + + The contents of this file are DUAL-LICENSED. You may modify and/or + redistribute this software according to the terms of one of the + following two licenses (at your option): + + + LICENSE 1 ("BSD-like with advertising clause"): + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute + it freely, subject to the following restrictions: + + 1. Redistributions of source code must retain the above copyright + notice, disclaimer, and this list of conditions. + 2. Redistributions in binary form must reproduce the above copyright + notice, disclaimer, and this list of conditions in the documenta- + tion and/or other materials provided with the distribution. + 3. All advertising materials mentioning features or use of this + software must display the following acknowledgment: + + This product includes software developed by Greg Roelofs + and contributors for the book, "PNG: The Definitive Guide," + published by O'Reilly and Associates. + + + LICENSE 2 (GNU GPL v2 or later): + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + ---------------------------------------------------------------------------*/ + +#define PROGNAME "rpng-win" +#define LONGNAME "Simple PNG Viewer for Windows" +#define VERSION "2.01 of 16 March 2008" + +#include +#include +#include +#include +#include +#include /* only for _getch() */ + +/* #define DEBUG : this enables the Trace() macros */ + +#include "readpng.h" /* typedefs, common macros, readpng prototypes */ + + +/* could just include png.h, but this macro is the only thing we need + * (name and typedefs changed to local versions); note that side effects + * only happen with alpha (which could easily be avoided with + * "ush acopy = (alpha);") */ + +#define alpha_composite(composite, fg, alpha, bg) { \ + ush temp = ((ush)(fg)*(ush)(alpha) + \ + (ush)(bg)*(ush)(255 - (ush)(alpha)) + (ush)128); \ + (composite) = (uch)((temp + (temp >> 8)) >> 8); \ +} + + +/* local prototypes */ +static int rpng_win_create_window(HINSTANCE hInst, int showmode); +static int rpng_win_display_image(void); +static void rpng_win_cleanup(void); +LRESULT CALLBACK rpng_win_wndproc(HWND, UINT, WPARAM, LPARAM); + + +static char titlebar[1024]; +static char *progname = PROGNAME; +static char *appname = LONGNAME; +static char *filename; +static FILE *infile; + +static char *bgstr; +static uch bg_red=0, bg_green=0, bg_blue=0; + +static double display_exponent; + +static ulg image_width, image_height, image_rowbytes; +static int image_channels; +static uch *image_data; + +/* Windows-specific variables */ +static ulg wimage_rowbytes; +static uch *dib; +static uch *wimage_data; +static BITMAPINFOHEADER *bmih; + +static HWND global_hwnd; + + + + +int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, PSTR cmd, int showmode) +{ + char *args[1024]; /* arbitrary limit, but should suffice */ + char *p, *q, **argv = args; + int argc = 0; + int rc, alen, flen; + int error = 0; + int have_bg = FALSE; + double LUT_exponent; /* just the lookup table */ + double CRT_exponent = 2.2; /* just the monitor */ + double default_display_exponent; /* whole display system */ + MSG msg; + + + filename = (char *)NULL; + + + /* First reenable console output, which normally goes to the bit bucket + * for windowed apps. Closing the console window will terminate the + * app. Thanks to David.Geldreich@realviz.com for supplying the magical + * incantation. */ + + AllocConsole(); + freopen("CONOUT$", "a", stderr); + freopen("CONOUT$", "a", stdout); + + + /* Next set the default value for our display-system exponent, i.e., + * the product of the CRT exponent and the exponent corresponding to + * the frame-buffer's lookup table (LUT), if any. This is not an + * exhaustive list of LUT values (e.g., OpenStep has a lot of weird + * ones), but it should cover 99% of the current possibilities. And + * yes, these ifdefs are completely wasted in a Windows program... */ + +#if defined(NeXT) + LUT_exponent = 1.0 / 2.2; + /* + if (some_next_function_that_returns_gamma(&next_gamma)) + LUT_exponent = 1.0 / next_gamma; + */ +#elif defined(sgi) + LUT_exponent = 1.0 / 1.7; + /* there doesn't seem to be any documented function to get the + * "gamma" value, so we do it the hard way */ + infile = fopen("/etc/config/system.glGammaVal", "r"); + if (infile) { + double sgi_gamma; + + fgets(tmpline, 80, infile); + fclose(infile); + sgi_gamma = atof(tmpline); + if (sgi_gamma > 0.0) + LUT_exponent = 1.0 / sgi_gamma; + } +#elif defined(Macintosh) + LUT_exponent = 1.8 / 2.61; + /* + if (some_mac_function_that_returns_gamma(&mac_gamma)) + LUT_exponent = mac_gamma / 2.61; + */ +#else + LUT_exponent = 1.0; /* assume no LUT: most PCs */ +#endif + + /* the defaults above give 1.0, 1.3, 1.5 and 2.2, respectively: */ + default_display_exponent = LUT_exponent * CRT_exponent; + + + /* If the user has set the SCREEN_GAMMA environment variable as suggested + * (somewhat imprecisely) in the libpng documentation, use that; otherwise + * use the default value we just calculated. Either way, the user may + * override this via a command-line option. */ + + if ((p = getenv("SCREEN_GAMMA")) != NULL) + display_exponent = atof(p); + else + display_exponent = default_display_exponent; + + + /* Windows really hates command lines, so we have to set up our own argv. + * Note that we do NOT bother with quoted arguments here, so don't use + * filenames with spaces in 'em! */ + + argv[argc++] = PROGNAME; + p = cmd; + for (;;) { + if (*p == ' ') + while (*++p == ' ') + ; + /* now p points at the first non-space after some spaces */ + if (*p == '\0') + break; /* nothing after the spaces: done */ + argv[argc++] = q = p; + while (*q && *q != ' ') + ++q; + /* now q points at a space or the end of the string */ + if (*q == '\0') + break; /* last argv already terminated; quit */ + *q = '\0'; /* change space to terminator */ + p = q + 1; + } + argv[argc] = NULL; /* terminate the argv array itself */ + + + /* Now parse the command line for options and the PNG filename. */ + + while (*++argv && !error) { + if (!strncmp(*argv, "-gamma", 2)) { + if (!*++argv) + ++error; + else { + display_exponent = atof(*argv); + if (display_exponent <= 0.0) + ++error; + } + } else if (!strncmp(*argv, "-bgcolor", 2)) { + if (!*++argv) + ++error; + else { + bgstr = *argv; + if (strlen(bgstr) != 7 || bgstr[0] != '#') + ++error; + else + have_bg = TRUE; + } + } else { + if (**argv != '-') { + filename = *argv; + if (argv[1]) /* shouldn't be any more args after filename */ + ++error; + } else + ++error; /* not expecting any other options */ + } + } + + if (!filename) + ++error; + + + /* print usage screen if any errors up to this point */ + + if (error) { + int ch; + + fprintf(stderr, "\n%s %s: %s\n\n", PROGNAME, VERSION, appname); + readpng_version_info(); + fprintf(stderr, "\n" + "Usage: %s [-gamma exp] [-bgcolor bg] file.png\n" + " exp \ttransfer-function exponent (``gamma'') of the display\n" + "\t\t system in floating-point format (e.g., ``%.1f''); equal\n" + "\t\t to the product of the lookup-table exponent (varies)\n" + "\t\t and the CRT exponent (usually 2.2); must be positive\n" + " bg \tdesired background color in 7-character hex RGB format\n" + "\t\t (e.g., ``#ff7700'' for orange: same as HTML colors);\n" + "\t\t used with transparent images\n" + "\nPress Q, Esc or mouse button 1 after image is displayed to quit.\n" + "Press Q or Esc to quit this usage screen.\n" + "\n", PROGNAME, default_display_exponent); + do + ch = _getch(); + while (ch != 'q' && ch != 'Q' && ch != 0x1B); + exit(1); + } + + + if (!(infile = fopen(filename, "rb"))) { + fprintf(stderr, PROGNAME ": can't open PNG file [%s]\n", filename); + ++error; + } else { + if ((rc = readpng_init(infile, &image_width, &image_height)) != 0) { + switch (rc) { + case 1: + fprintf(stderr, PROGNAME + ": [%s] is not a PNG file: incorrect signature\n", + filename); + break; + case 2: + fprintf(stderr, PROGNAME + ": [%s] has bad IHDR (libpng longjmp)\n", filename); + break; + case 4: + fprintf(stderr, PROGNAME ": insufficient memory\n"); + break; + default: + fprintf(stderr, PROGNAME + ": unknown readpng_init() error\n"); + break; + } + ++error; + } + if (error) + fclose(infile); + } + + + if (error) { + int ch; + + fprintf(stderr, PROGNAME ": aborting.\n"); + do + ch = _getch(); + while (ch != 'q' && ch != 'Q' && ch != 0x1B); + exit(2); + } else { + fprintf(stderr, "\n%s %s: %s\n", PROGNAME, VERSION, appname); + fprintf(stderr, + "\n [console window: closing this window will terminate %s]\n\n", + PROGNAME); + } + + + /* set the title-bar string, but make sure buffer doesn't overflow */ + + alen = strlen(appname); + flen = strlen(filename); + if (alen + flen + 3 > 1023) + sprintf(titlebar, "%s: ...%s", appname, filename+(alen+flen+6-1023)); + else + sprintf(titlebar, "%s: %s", appname, filename); + + + /* if the user didn't specify a background color on the command line, + * check for one in the PNG file--if not, the initialized values of 0 + * (black) will be used */ + + if (have_bg) { + unsigned r, g, b; /* this approach quiets compiler warnings */ + + sscanf(bgstr+1, "%2x%2x%2x", &r, &g, &b); + bg_red = (uch)r; + bg_green = (uch)g; + bg_blue = (uch)b; + } else if (readpng_get_bgcolor(&bg_red, &bg_green, &bg_blue) > 1) { + readpng_cleanup(TRUE); + fprintf(stderr, PROGNAME + ": libpng error while checking for background color\n"); + exit(2); + } + + + /* do the basic Windows initialization stuff, make the window and fill it + * with the background color */ + + if (rpng_win_create_window(hInst, showmode)) + exit(2); + + + /* decode the image, all at once */ + + Trace((stderr, "calling readpng_get_image()\n")) + image_data = readpng_get_image(display_exponent, &image_channels, + &image_rowbytes); + Trace((stderr, "done with readpng_get_image()\n")) + + + /* done with PNG file, so clean up to minimize memory usage (but do NOT + * nuke image_data!) */ + + readpng_cleanup(FALSE); + fclose(infile); + + if (!image_data) { + fprintf(stderr, PROGNAME ": unable to decode PNG image\n"); + exit(3); + } + + + /* display image (composite with background if requested) */ + + Trace((stderr, "calling rpng_win_display_image()\n")) + if (rpng_win_display_image()) { + free(image_data); + exit(4); + } + Trace((stderr, "done with rpng_win_display_image()\n")) + + + /* wait for the user to tell us when to quit */ + + printf( + "Done. Press Q, Esc or mouse button 1 (within image window) to quit.\n"); + fflush(stdout); + + while (GetMessage(&msg, NULL, 0, 0)) { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + + + /* OK, we're done: clean up all image and Windows resources and go away */ + + rpng_win_cleanup(); + + return msg.wParam; +} + + + + + +static int rpng_win_create_window(HINSTANCE hInst, int showmode) +{ + uch *dest; + int extra_width, extra_height; + ulg i, j; + WNDCLASSEX wndclass; + + +/*--------------------------------------------------------------------------- + Allocate memory for the display-specific version of the image (round up + to multiple of 4 for Windows DIB). + ---------------------------------------------------------------------------*/ + + wimage_rowbytes = ((3*image_width + 3L) >> 2) << 2; + + if (!(dib = (uch *)malloc(sizeof(BITMAPINFOHEADER) + + wimage_rowbytes*image_height))) + { + return 4; /* fail */ + } + +/*--------------------------------------------------------------------------- + Initialize the DIB. Negative height means to use top-down BMP ordering + (must be uncompressed, but that's what we want). Bit count of 1, 4 or 8 + implies a colormap of RGBX quads, but 24-bit BMPs just use B,G,R values + directly => wimage_data begins immediately after BMP header. + ---------------------------------------------------------------------------*/ + + memset(dib, 0, sizeof(BITMAPINFOHEADER)); + bmih = (BITMAPINFOHEADER *)dib; + bmih->biSize = sizeof(BITMAPINFOHEADER); + bmih->biWidth = image_width; + bmih->biHeight = -((long)image_height); + bmih->biPlanes = 1; + bmih->biBitCount = 24; + bmih->biCompression = 0; + wimage_data = dib + sizeof(BITMAPINFOHEADER); + +/*--------------------------------------------------------------------------- + Fill in background color (black by default); data are in BGR order. + ---------------------------------------------------------------------------*/ + + for (j = 0; j < image_height; ++j) { + dest = wimage_data + j*wimage_rowbytes; + for (i = image_width; i > 0; --i) { + *dest++ = bg_blue; + *dest++ = bg_green; + *dest++ = bg_red; + } + } + +/*--------------------------------------------------------------------------- + Set the window parameters. + ---------------------------------------------------------------------------*/ + + memset(&wndclass, 0, sizeof(wndclass)); + + wndclass.cbSize = sizeof(wndclass); + wndclass.style = CS_HREDRAW | CS_VREDRAW; + wndclass.lpfnWndProc = rpng_win_wndproc; + wndclass.hInstance = hInst; + wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); + wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); + wndclass.hbrBackground = (HBRUSH)GetStockObject(DKGRAY_BRUSH); + wndclass.lpszMenuName = NULL; + wndclass.lpszClassName = progname; + wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION); + + RegisterClassEx(&wndclass); + +/*--------------------------------------------------------------------------- + Finally, create the window. + ---------------------------------------------------------------------------*/ + + extra_width = 2*(GetSystemMetrics(SM_CXBORDER) + + GetSystemMetrics(SM_CXDLGFRAME)); + extra_height = 2*(GetSystemMetrics(SM_CYBORDER) + + GetSystemMetrics(SM_CYDLGFRAME)) + + GetSystemMetrics(SM_CYCAPTION); + + global_hwnd = CreateWindow(progname, titlebar, WS_OVERLAPPEDWINDOW, + CW_USEDEFAULT, CW_USEDEFAULT, image_width+extra_width, + image_height+extra_height, NULL, NULL, hInst, NULL); + + ShowWindow(global_hwnd, showmode); + UpdateWindow(global_hwnd); + + return 0; + +} /* end function rpng_win_create_window() */ + + + + + +static int rpng_win_display_image() +{ + uch *src, *dest; + uch r, g, b, a; + ulg i, row, lastrow; + RECT rect; + + + Trace((stderr, "beginning display loop (image_channels == %d)\n", + image_channels)) + Trace((stderr, "(width = %ld, rowbytes = %ld, wimage_rowbytes = %d)\n", + image_width, image_rowbytes, wimage_rowbytes)) + + +/*--------------------------------------------------------------------------- + Blast image data to buffer. This whole routine takes place before the + message loop begins, so there's no real point in any pseudo-progressive + display... + ---------------------------------------------------------------------------*/ + + for (lastrow = row = 0; row < image_height; ++row) { + src = image_data + row*image_rowbytes; + dest = wimage_data + row*wimage_rowbytes; + if (image_channels == 3) { + for (i = image_width; i > 0; --i) { + r = *src++; + g = *src++; + b = *src++; + *dest++ = b; + *dest++ = g; /* note reverse order */ + *dest++ = r; + } + } else /* if (image_channels == 4) */ { + for (i = image_width; i > 0; --i) { + r = *src++; + g = *src++; + b = *src++; + a = *src++; + if (a == 255) { + *dest++ = b; + *dest++ = g; + *dest++ = r; + } else if (a == 0) { + *dest++ = bg_blue; + *dest++ = bg_green; + *dest++ = bg_red; + } else { + /* this macro (copied from png.h) composites the + * foreground and background values and puts the + * result into the first argument; there are no + * side effects with the first argument */ + alpha_composite(*dest++, b, a, bg_blue); + alpha_composite(*dest++, g, a, bg_green); + alpha_composite(*dest++, r, a, bg_red); + } + } + } + /* display after every 16 lines */ + if (((row+1) & 0xf) == 0) { + rect.left = 0L; + rect.top = (LONG)lastrow; + rect.right = (LONG)image_width; /* possibly off by one? */ + rect.bottom = (LONG)lastrow + 16L; /* possibly off by one? */ + InvalidateRect(global_hwnd, &rect, FALSE); + UpdateWindow(global_hwnd); /* similar to XFlush() */ + lastrow = row + 1; + } + } + + Trace((stderr, "calling final image-flush routine\n")) + if (lastrow < image_height) { + rect.left = 0L; + rect.top = (LONG)lastrow; + rect.right = (LONG)image_width; /* possibly off by one? */ + rect.bottom = (LONG)image_height; /* possibly off by one? */ + InvalidateRect(global_hwnd, &rect, FALSE); + UpdateWindow(global_hwnd); /* similar to XFlush() */ + } + +/* + last param determines whether or not background is wiped before paint + InvalidateRect(global_hwnd, NULL, TRUE); + UpdateWindow(global_hwnd); + */ + + return 0; +} + + + + + +static void rpng_win_cleanup() +{ + if (image_data) { + free(image_data); + image_data = NULL; + } + + if (dib) { + free(dib); + dib = NULL; + } +} + + + + + +LRESULT CALLBACK rpng_win_wndproc(HWND hwnd, UINT iMsg, WPARAM wP, LPARAM lP) +{ + HDC hdc; + PAINTSTRUCT ps; + int rc; + + switch (iMsg) { + case WM_CREATE: + /* one-time processing here, if any */ + return 0; + + case WM_PAINT: + hdc = BeginPaint(hwnd, &ps); + /* dest */ + rc = StretchDIBits(hdc, 0, 0, image_width, image_height, + /* source */ + 0, 0, image_width, image_height, + wimage_data, (BITMAPINFO *)bmih, + /* iUsage: no clue */ + 0, SRCCOPY); + EndPaint(hwnd, &ps); + return 0; + + /* wait for the user to tell us when to quit */ + case WM_CHAR: + switch (wP) { /* only need one, so ignore repeat count */ + case 'q': + case 'Q': + case 0x1B: /* Esc key */ + PostQuitMessage(0); + } + return 0; + + case WM_LBUTTONDOWN: /* another way of quitting */ + case WM_DESTROY: + PostQuitMessage(0); + return 0; + } + + return DefWindowProc(hwnd, iMsg, wP, lP); +} diff --git a/libs/libpng-src/contrib/gregbook/rpng-x.c b/libs/libpng-src/contrib/gregbook/rpng-x.c new file mode 100644 index 000000000..0a9817029 --- /dev/null +++ b/libs/libpng-src/contrib/gregbook/rpng-x.c @@ -0,0 +1,904 @@ +/*--------------------------------------------------------------------------- + + rpng - simple PNG display program rpng-x.c + + This program decodes and displays PNG images, with gamma correction and + optionally with a user-specified background color (in case the image has + transparency). It is very nearly the most basic PNG viewer possible. + This version is for the X Window System (tested by author under Unix and + by Martin Zinser under OpenVMS; may work under OS/2 with some tweaking). + + to do: + - 8-bit (colormapped) X support + - use %.1023s to simplify truncation of title-bar string? + + --------------------------------------------------------------------------- + + Changelog: + - 1.01: initial public release + - 1.02: modified to allow abbreviated options; fixed long/ulong mis- + match; switched to png_jmpbuf() macro + - 1.10: added support for non-default visuals; fixed X pixel-conversion + - 1.11: added extra set of parentheses to png_jmpbuf() macro; fixed + command-line parsing bug + - 1.12: fixed some small X memory leaks (thanks to François Petitjean) + - 1.13: fixed XFreeGC() crash bug (thanks to Patrick Welche) + - 1.14: added support for X resources (thanks to Gerhard Niklasch) + - 2.00: dual-licensed (added GNU GPL) + - 2.01: fixed improper display of usage screen on PNG error(s) + + --------------------------------------------------------------------------- + + Copyright (c) 1998-2008 Greg Roelofs. All rights reserved. + + This software is provided "as is," without warranty of any kind, + express or implied. In no event shall the author or contributors + be held liable for any damages arising in any way from the use of + this software. + + The contents of this file are DUAL-LICENSED. You may modify and/or + redistribute this software according to the terms of one of the + following two licenses (at your option): + + + LICENSE 1 ("BSD-like with advertising clause"): + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute + it freely, subject to the following restrictions: + + 1. Redistributions of source code must retain the above copyright + notice, disclaimer, and this list of conditions. + 2. Redistributions in binary form must reproduce the above copyright + notice, disclaimer, and this list of conditions in the documenta- + tion and/or other materials provided with the distribution. + 3. All advertising materials mentioning features or use of this + software must display the following acknowledgment: + + This product includes software developed by Greg Roelofs + and contributors for the book, "PNG: The Definitive Guide," + published by O'Reilly and Associates. + + + LICENSE 2 (GNU GPL v2 or later): + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + ---------------------------------------------------------------------------*/ + +#define PROGNAME "rpng-x" +#define LONGNAME "Simple PNG Viewer for X" +#define VERSION "2.01 of 16 March 2008" +#define RESNAME "rpng" /* our X resource application name */ +#define RESCLASS "Rpng" /* our X resource class name */ + +#include +#include +#include +#include +#include +#include +#include +#include + +/* #define DEBUG : this enables the Trace() macros */ + +#include "readpng.h" /* typedefs, common macros, readpng prototypes */ + + +/* could just include png.h, but this macro is the only thing we need + * (name and typedefs changed to local versions); note that side effects + * only happen with alpha (which could easily be avoided with + * "ush acopy = (alpha);") */ + +#define alpha_composite(composite, fg, alpha, bg) { \ + ush temp = ((ush)(fg)*(ush)(alpha) + \ + (ush)(bg)*(ush)(255 - (ush)(alpha)) + (ush)128); \ + (composite) = (uch)((temp + (temp >> 8)) >> 8); \ +} + + +/* local prototypes */ +static int rpng_x_create_window(void); +static int rpng_x_display_image(void); +static void rpng_x_cleanup(void); +static int rpng_x_msb(ulg u32val); + + +static char titlebar[1024], *window_name = titlebar; +static char *appname = LONGNAME; +static char *icon_name = PROGNAME; +static char *res_name = RESNAME; +static char *res_class = RESCLASS; +static char *filename; +static FILE *infile; + +static char *bgstr; +static uch bg_red=0, bg_green=0, bg_blue=0; + +static double display_exponent; + +static ulg image_width, image_height, image_rowbytes; +static int image_channels; +static uch *image_data; + +/* X-specific variables */ +static char *displayname; +static XImage *ximage; +static Display *display; +static int depth; +static Visual *visual; +static XVisualInfo *visual_list; +static int RShift, GShift, BShift; +static ulg RMask, GMask, BMask; +static Window window; +static GC gc; +static Colormap colormap; + +static int have_nondefault_visual = FALSE; +static int have_colormap = FALSE; +static int have_window = FALSE; +static int have_gc = FALSE; +/* +ulg numcolors=0, pixels[256]; +ush reds[256], greens[256], blues[256]; + */ + + + + +int main(int argc, char **argv) +{ +#ifdef sgi + char tmpline[80]; +#endif + char *p; + int rc, alen, flen; + int error = 0; + int have_bg = FALSE; + double LUT_exponent; /* just the lookup table */ + double CRT_exponent = 2.2; /* just the monitor */ + double default_display_exponent; /* whole display system */ + XEvent e; + KeySym k; + + + displayname = (char *)NULL; + filename = (char *)NULL; + + + /* First set the default value for our display-system exponent, i.e., + * the product of the CRT exponent and the exponent corresponding to + * the frame-buffer's lookup table (LUT), if any. This is not an + * exhaustive list of LUT values (e.g., OpenStep has a lot of weird + * ones), but it should cover 99% of the current possibilities. */ + +#if defined(NeXT) + LUT_exponent = 1.0 / 2.2; + /* + if (some_next_function_that_returns_gamma(&next_gamma)) + LUT_exponent = 1.0 / next_gamma; + */ +#elif defined(sgi) + LUT_exponent = 1.0 / 1.7; + /* there doesn't seem to be any documented function to get the + * "gamma" value, so we do it the hard way */ + infile = fopen("/etc/config/system.glGammaVal", "r"); + if (infile) { + double sgi_gamma; + + fgets(tmpline, 80, infile); + fclose(infile); + sgi_gamma = atof(tmpline); + if (sgi_gamma > 0.0) + LUT_exponent = 1.0 / sgi_gamma; + } +#elif defined(Macintosh) + LUT_exponent = 1.8 / 2.61; + /* + if (some_mac_function_that_returns_gamma(&mac_gamma)) + LUT_exponent = mac_gamma / 2.61; + */ +#else + LUT_exponent = 1.0; /* assume no LUT: most PCs */ +#endif + + /* the defaults above give 1.0, 1.3, 1.5 and 2.2, respectively: */ + default_display_exponent = LUT_exponent * CRT_exponent; + + + /* If the user has set the SCREEN_GAMMA environment variable as suggested + * (somewhat imprecisely) in the libpng documentation, use that; otherwise + * use the default value we just calculated. Either way, the user may + * override this via a command-line option. */ + + if ((p = getenv("SCREEN_GAMMA")) != NULL) + display_exponent = atof(p); + else + display_exponent = default_display_exponent; + + + /* Now parse the command line for options and the PNG filename. */ + + while (*++argv && !error) { + if (!strncmp(*argv, "-display", 2)) { + if (!*++argv) + ++error; + else + displayname = *argv; + } else if (!strncmp(*argv, "-gamma", 2)) { + if (!*++argv) + ++error; + else { + display_exponent = atof(*argv); + if (display_exponent <= 0.0) + ++error; + } + } else if (!strncmp(*argv, "-bgcolor", 2)) { + if (!*++argv) + ++error; + else { + bgstr = *argv; + if (strlen(bgstr) != 7 || bgstr[0] != '#') + ++error; + else + have_bg = TRUE; + } + } else { + if (**argv != '-') { + filename = *argv; + if (argv[1]) /* shouldn't be any more args after filename */ + ++error; + } else + ++error; /* not expecting any other options */ + } + } + + if (!filename) + ++error; + + + /* print usage screen if any errors up to this point */ + + if (error) { + fprintf(stderr, "\n%s %s: %s\n", PROGNAME, VERSION, appname); + readpng_version_info(); + fprintf(stderr, "\n" + "Usage: %s [-display xdpy] [-gamma exp] [-bgcolor bg] file.png\n" + " xdpy\tname of the target X display (e.g., ``hostname:0'')\n" + " exp \ttransfer-function exponent (``gamma'') of the display\n" + "\t\t system in floating-point format (e.g., ``%.1f''); equal\n" + "\t\t to the product of the lookup-table exponent (varies)\n" + "\t\t and the CRT exponent (usually 2.2); must be positive\n" + " bg \tdesired background color in 7-character hex RGB format\n" + "\t\t (e.g., ``#ff7700'' for orange: same as HTML colors);\n" + "\t\t used with transparent images\n" + "\nPress Q, Esc or mouse button 1 (within image window, after image\n" + "is displayed) to quit.\n" + "\n", PROGNAME, default_display_exponent); + exit(1); + } + + + if (!(infile = fopen(filename, "rb"))) { + fprintf(stderr, PROGNAME ": can't open PNG file [%s]\n", filename); + ++error; + } else { + if ((rc = readpng_init(infile, &image_width, &image_height)) != 0) { + switch (rc) { + case 1: + fprintf(stderr, PROGNAME + ": [%s] is not a PNG file: incorrect signature\n", + filename); + break; + case 2: + fprintf(stderr, PROGNAME + ": [%s] has bad IHDR (libpng longjmp)\n", filename); + break; + case 4: + fprintf(stderr, PROGNAME ": insufficient memory\n"); + break; + default: + fprintf(stderr, PROGNAME + ": unknown readpng_init() error\n"); + break; + } + ++error; + } else { + display = XOpenDisplay(displayname); + if (!display) { + readpng_cleanup(TRUE); + fprintf(stderr, PROGNAME ": can't open X display [%s]\n", + displayname? displayname : "default"); + ++error; + } + } + if (error) + fclose(infile); + } + + + if (error) { + fprintf(stderr, PROGNAME ": aborting.\n"); + exit(2); + } + + + /* set the title-bar string, but make sure buffer doesn't overflow */ + + alen = strlen(appname); + flen = strlen(filename); + if (alen + flen + 3 > 1023) + sprintf(titlebar, "%s: ...%s", appname, filename+(alen+flen+6-1023)); + else + sprintf(titlebar, "%s: %s", appname, filename); + + + /* if the user didn't specify a background color on the command line, + * check for one in the PNG file--if not, the initialized values of 0 + * (black) will be used */ + + if (have_bg) { + unsigned r, g, b; /* this approach quiets compiler warnings */ + + sscanf(bgstr+1, "%2x%2x%2x", &r, &g, &b); + bg_red = (uch)r; + bg_green = (uch)g; + bg_blue = (uch)b; + } else if (readpng_get_bgcolor(&bg_red, &bg_green, &bg_blue) > 1) { + readpng_cleanup(TRUE); + fprintf(stderr, PROGNAME + ": libpng error while checking for background color\n"); + exit(2); + } + + + /* do the basic X initialization stuff, make the window and fill it + * with the background color */ + + if (rpng_x_create_window()) + exit(2); + + + /* decode the image, all at once */ + + Trace((stderr, "calling readpng_get_image()\n")) + image_data = readpng_get_image(display_exponent, &image_channels, + &image_rowbytes); + Trace((stderr, "done with readpng_get_image()\n")) + + + /* done with PNG file, so clean up to minimize memory usage (but do NOT + * nuke image_data!) */ + + readpng_cleanup(FALSE); + fclose(infile); + + if (!image_data) { + fprintf(stderr, PROGNAME ": unable to decode PNG image\n"); + exit(3); + } + + + /* display image (composite with background if requested) */ + + Trace((stderr, "calling rpng_x_display_image()\n")) + if (rpng_x_display_image()) { + free(image_data); + exit(4); + } + Trace((stderr, "done with rpng_x_display_image()\n")) + + + /* wait for the user to tell us when to quit */ + + printf( + "Done. Press Q, Esc or mouse button 1 (within image window) to quit.\n"); + fflush(stdout); + + do + XNextEvent(display, &e); + while (!(e.type == ButtonPress && e.xbutton.button == Button1) && + !(e.type == KeyPress && /* v--- or 1 for shifted keys */ + ((k = XLookupKeysym(&e.xkey, 0)) == XK_q || k == XK_Escape) )); + + + /* OK, we're done: clean up all image and X resources and go away */ + + rpng_x_cleanup(); + + return 0; +} + + + + + +static int rpng_x_create_window(void) +{ + uch *xdata; + int need_colormap = FALSE; + int screen, pad; + ulg bg_pixel = 0L; + ulg attrmask; + Window root; + XEvent e; + XGCValues gcvalues; + XSetWindowAttributes attr; + XTextProperty windowName, *pWindowName = &windowName; + XTextProperty iconName, *pIconName = &iconName; + XVisualInfo visual_info; + XSizeHints *size_hints; + XWMHints *wm_hints; + XClassHint *class_hints; + + + screen = DefaultScreen(display); + depth = DisplayPlanes(display, screen); + root = RootWindow(display, screen); + +#ifdef DEBUG + XSynchronize(display, True); +#endif + +#if 0 +/* GRR: add 8-bit support */ + if (/* depth != 8 && */ depth != 16 && depth != 24 && depth != 32) { + fprintf(stderr, + "screen depth %d not supported (only 16-, 24- or 32-bit TrueColor)\n", + depth); + return 2; + } + + XMatchVisualInfo(display, screen, depth, + (depth == 8)? PseudoColor : TrueColor, &visual_info); + visual = visual_info.visual; +#else + if (depth != 16 && depth != 24 && depth != 32) { + int visuals_matched = 0; + + Trace((stderr, "default depth is %d: checking other visuals\n", + depth)) + + /* 24-bit first */ + visual_info.screen = screen; + visual_info.depth = 24; + visual_list = XGetVisualInfo(display, + VisualScreenMask | VisualDepthMask, &visual_info, &visuals_matched); + if (visuals_matched == 0) { +/* GRR: add 15-, 16- and 32-bit TrueColor visuals (also DirectColor?) */ + fprintf(stderr, "default screen depth %d not supported, and no" + " 24-bit visuals found\n", depth); + return 2; + } + Trace((stderr, "XGetVisualInfo() returned %d 24-bit visuals\n", + visuals_matched)) + visual = visual_list[0].visual; + depth = visual_list[0].depth; +/* + colormap_size = visual_list[0].colormap_size; + visual_class = visual->class; + visualID = XVisualIDFromVisual(visual); + */ + have_nondefault_visual = TRUE; + need_colormap = TRUE; + } else { + XMatchVisualInfo(display, screen, depth, TrueColor, &visual_info); + visual = visual_info.visual; + } +#endif + + RMask = visual->red_mask; + GMask = visual->green_mask; + BMask = visual->blue_mask; + +/* GRR: add/check 8-bit support */ + if (depth == 8 || need_colormap) { + colormap = XCreateColormap(display, root, visual, AllocNone); + if (!colormap) { + fprintf(stderr, "XCreateColormap() failed\n"); + return 2; + } + have_colormap = TRUE; + } + if (depth == 15 || depth == 16) { + RShift = 15 - rpng_x_msb(RMask); /* these are right-shifts */ + GShift = 15 - rpng_x_msb(GMask); + BShift = 15 - rpng_x_msb(BMask); + } else if (depth > 16) { +#define NO_24BIT_MASKS +#ifdef NO_24BIT_MASKS + RShift = rpng_x_msb(RMask) - 7; /* these are left-shifts */ + GShift = rpng_x_msb(GMask) - 7; + BShift = rpng_x_msb(BMask) - 7; +#else + RShift = 7 - rpng_x_msb(RMask); /* these are right-shifts, too */ + GShift = 7 - rpng_x_msb(GMask); + BShift = 7 - rpng_x_msb(BMask); +#endif + } + if (depth >= 15 && (RShift < 0 || GShift < 0 || BShift < 0)) { + fprintf(stderr, "rpng internal logic error: negative X shift(s)!\n"); + return 2; + } + +/*--------------------------------------------------------------------------- + Finally, create the window. + ---------------------------------------------------------------------------*/ + + attr.backing_store = Always; + attr.event_mask = ExposureMask | KeyPressMask | ButtonPressMask; + attrmask = CWBackingStore | CWEventMask; + if (have_nondefault_visual) { + attr.colormap = colormap; + attr.background_pixel = 0; + attr.border_pixel = 1; + attrmask |= CWColormap | CWBackPixel | CWBorderPixel; + } + + window = XCreateWindow(display, root, 0, 0, image_width, image_height, 0, + depth, InputOutput, visual, attrmask, &attr); + + if (window == None) { + fprintf(stderr, "XCreateWindow() failed\n"); + return 2; + } else + have_window = TRUE; + + if (depth == 8) + XSetWindowColormap(display, window, colormap); + + if (!XStringListToTextProperty(&window_name, 1, pWindowName)) + pWindowName = NULL; + if (!XStringListToTextProperty(&icon_name, 1, pIconName)) + pIconName = NULL; + + /* OK if any hints allocation fails; XSetWMProperties() allows NULLs */ + + if ((size_hints = XAllocSizeHints()) != NULL) { + /* window will not be resizable */ + size_hints->flags = PMinSize | PMaxSize; + size_hints->min_width = size_hints->max_width = (int)image_width; + size_hints->min_height = size_hints->max_height = (int)image_height; + } + + if ((wm_hints = XAllocWMHints()) != NULL) { + wm_hints->initial_state = NormalState; + wm_hints->input = True; + /* wm_hints->icon_pixmap = icon_pixmap; */ + wm_hints->flags = StateHint | InputHint /* | IconPixmapHint */ ; + } + + if ((class_hints = XAllocClassHint()) != NULL) { + class_hints->res_name = res_name; + class_hints->res_class = res_class; + } + + XSetWMProperties(display, window, pWindowName, pIconName, NULL, 0, + size_hints, wm_hints, class_hints); + + /* various properties and hints no longer needed; free memory */ + if (pWindowName) + XFree(pWindowName->value); + if (pIconName) + XFree(pIconName->value); + if (size_hints) + XFree(size_hints); + if (wm_hints) + XFree(wm_hints); + if (class_hints) + XFree(class_hints); + + XMapWindow(display, window); + + gc = XCreateGC(display, window, 0, &gcvalues); + have_gc = TRUE; + +/*--------------------------------------------------------------------------- + Fill window with the specified background color. + ---------------------------------------------------------------------------*/ + + if (depth == 24 || depth == 32) { + bg_pixel = ((ulg)bg_red << RShift) | + ((ulg)bg_green << GShift) | + ((ulg)bg_blue << BShift); + } else if (depth == 16) { + bg_pixel = ((((ulg)bg_red << 8) >> RShift) & RMask) | + ((((ulg)bg_green << 8) >> GShift) & GMask) | + ((((ulg)bg_blue << 8) >> BShift) & BMask); + } else /* depth == 8 */ { + + /* GRR: add 8-bit support */ + + } + + XSetForeground(display, gc, bg_pixel); + XFillRectangle(display, window, gc, 0, 0, image_width, image_height); + +/*--------------------------------------------------------------------------- + Wait for first Expose event to do any drawing, then flush. + ---------------------------------------------------------------------------*/ + + do + XNextEvent(display, &e); + while (e.type != Expose || e.xexpose.count); + + XFlush(display); + +/*--------------------------------------------------------------------------- + Allocate memory for the X- and display-specific version of the image. + ---------------------------------------------------------------------------*/ + + if (depth == 24 || depth == 32) { + xdata = (uch *)malloc(4*image_width*image_height); + pad = 32; + } else if (depth == 16) { + xdata = (uch *)malloc(2*image_width*image_height); + pad = 16; + } else /* depth == 8 */ { + xdata = (uch *)malloc(image_width*image_height); + pad = 8; + } + + if (!xdata) { + fprintf(stderr, PROGNAME ": unable to allocate image memory\n"); + return 4; + } + + ximage = XCreateImage(display, visual, depth, ZPixmap, 0, + (char *)xdata, image_width, image_height, pad, 0); + + if (!ximage) { + fprintf(stderr, PROGNAME ": XCreateImage() failed\n"); + free(xdata); + return 3; + } + + /* to avoid testing the byte order every pixel (or doubling the size of + * the drawing routine with a giant if-test), we arbitrarily set the byte + * order to MSBFirst and let Xlib worry about inverting things on little- + * endian machines (like Linux/x86, old VAXen, etc.)--this is not the most + * efficient approach (the giant if-test would be better), but in the + * interest of clarity, we take the easy way out... */ + + ximage->byte_order = MSBFirst; + + return 0; + +} /* end function rpng_x_create_window() */ + + + + + +static int rpng_x_display_image(void) +{ + uch *src; + char *dest; + uch r, g, b, a; + ulg i, row, lastrow = 0; + ulg pixel; + int ximage_rowbytes = ximage->bytes_per_line; +/* int bpp = ximage->bits_per_pixel; */ + + + Trace((stderr, "beginning display loop (image_channels == %d)\n", + image_channels)) + Trace((stderr, " (width = %ld, rowbytes = %ld, ximage_rowbytes = %d)\n", + image_width, image_rowbytes, ximage_rowbytes)) + Trace((stderr, " (bpp = %d)\n", ximage->bits_per_pixel)) + Trace((stderr, " (byte_order = %s)\n", ximage->byte_order == MSBFirst? + "MSBFirst" : (ximage->byte_order == LSBFirst? "LSBFirst" : "unknown"))) + + if (depth == 24 || depth == 32) { + ulg red, green, blue; + + for (lastrow = row = 0; row < image_height; ++row) { + src = image_data + row*image_rowbytes; + dest = ximage->data + row*ximage_rowbytes; + if (image_channels == 3) { + for (i = image_width; i > 0; --i) { + red = *src++; + green = *src++; + blue = *src++; +#ifdef NO_24BIT_MASKS + pixel = (red << RShift) | + (green << GShift) | + (blue << BShift); + /* recall that we set ximage->byte_order = MSBFirst above */ + /* GRR BUG: this assumes bpp == 32, but may be 24: */ + *dest++ = (char)((pixel >> 24) & 0xff); + *dest++ = (char)((pixel >> 16) & 0xff); + *dest++ = (char)((pixel >> 8) & 0xff); + *dest++ = (char)( pixel & 0xff); +#else + red = (RShift < 0)? red << (-RShift) : red >> RShift; + green = (GShift < 0)? green << (-GShift) : green >> GShift; + blue = (BShift < 0)? blue << (-BShift) : blue >> BShift; + pixel = (red & RMask) | (green & GMask) | (blue & BMask); + /* recall that we set ximage->byte_order = MSBFirst above */ + *dest++ = (char)((pixel >> 24) & 0xff); + *dest++ = (char)((pixel >> 16) & 0xff); + *dest++ = (char)((pixel >> 8) & 0xff); + *dest++ = (char)( pixel & 0xff); +#endif + } + } else /* if (image_channels == 4) */ { + for (i = image_width; i > 0; --i) { + r = *src++; + g = *src++; + b = *src++; + a = *src++; + if (a == 255) { + red = r; + green = g; + blue = b; + } else if (a == 0) { + red = bg_red; + green = bg_green; + blue = bg_blue; + } else { + /* this macro (from png.h) composites the foreground + * and background values and puts the result into the + * first argument */ + alpha_composite(red, r, a, bg_red); + alpha_composite(green, g, a, bg_green); + alpha_composite(blue, b, a, bg_blue); + } + pixel = (red << RShift) | + (green << GShift) | + (blue << BShift); + /* recall that we set ximage->byte_order = MSBFirst above */ + *dest++ = (char)((pixel >> 24) & 0xff); + *dest++ = (char)((pixel >> 16) & 0xff); + *dest++ = (char)((pixel >> 8) & 0xff); + *dest++ = (char)( pixel & 0xff); + } + } + /* display after every 16 lines */ + if (((row+1) & 0xf) == 0) { + XPutImage(display, window, gc, ximage, 0, (int)lastrow, 0, + (int)lastrow, image_width, 16); + XFlush(display); + lastrow = row + 1; + } + } + + } else if (depth == 16) { + ush red, green, blue; + + for (lastrow = row = 0; row < image_height; ++row) { + src = image_data + row*image_rowbytes; + dest = ximage->data + row*ximage_rowbytes; + if (image_channels == 3) { + for (i = image_width; i > 0; --i) { + red = ((ush)(*src) << 8); + ++src; + green = ((ush)(*src) << 8); + ++src; + blue = ((ush)(*src) << 8); + ++src; + pixel = ((red >> RShift) & RMask) | + ((green >> GShift) & GMask) | + ((blue >> BShift) & BMask); + /* recall that we set ximage->byte_order = MSBFirst above */ + *dest++ = (char)((pixel >> 8) & 0xff); + *dest++ = (char)( pixel & 0xff); + } + } else /* if (image_channels == 4) */ { + for (i = image_width; i > 0; --i) { + r = *src++; + g = *src++; + b = *src++; + a = *src++; + if (a == 255) { + red = ((ush)r << 8); + green = ((ush)g << 8); + blue = ((ush)b << 8); + } else if (a == 0) { + red = ((ush)bg_red << 8); + green = ((ush)bg_green << 8); + blue = ((ush)bg_blue << 8); + } else { + /* this macro (from png.h) composites the foreground + * and background values and puts the result back into + * the first argument (== fg byte here: safe) */ + alpha_composite(r, r, a, bg_red); + alpha_composite(g, g, a, bg_green); + alpha_composite(b, b, a, bg_blue); + red = ((ush)r << 8); + green = ((ush)g << 8); + blue = ((ush)b << 8); + } + pixel = ((red >> RShift) & RMask) | + ((green >> GShift) & GMask) | + ((blue >> BShift) & BMask); + /* recall that we set ximage->byte_order = MSBFirst above */ + *dest++ = (char)((pixel >> 8) & 0xff); + *dest++ = (char)( pixel & 0xff); + } + } + /* display after every 16 lines */ + if (((row+1) & 0xf) == 0) { + XPutImage(display, window, gc, ximage, 0, (int)lastrow, 0, + (int)lastrow, image_width, 16); + XFlush(display); + lastrow = row + 1; + } + } + + } else /* depth == 8 */ { + + /* GRR: add 8-bit support */ + + } + + Trace((stderr, "calling final XPutImage()\n")) + if (lastrow < image_height) { + XPutImage(display, window, gc, ximage, 0, (int)lastrow, 0, + (int)lastrow, image_width, image_height-lastrow); + XFlush(display); + } + + return 0; +} + + + + +static void rpng_x_cleanup(void) +{ + if (image_data) { + free(image_data); + image_data = NULL; + } + + if (ximage) { + if (ximage->data) { + free(ximage->data); /* we allocated it, so we free it */ + ximage->data = (char *)NULL; /* instead of XDestroyImage() */ + } + XDestroyImage(ximage); + ximage = NULL; + } + + if (have_gc) + XFreeGC(display, gc); + + if (have_window) + XDestroyWindow(display, window); + + if (have_colormap) + XFreeColormap(display, colormap); + + if (have_nondefault_visual) + XFree(visual_list); +} + + + + + +static int rpng_x_msb(ulg u32val) +{ + int i; + + for (i = 31; i >= 0; --i) { + if (u32val & 0x80000000L) + break; + u32val <<= 1; + } + return i; +} diff --git a/libs/libpng-src/contrib/gregbook/rpng2-win.c b/libs/libpng-src/contrib/gregbook/rpng2-win.c new file mode 100644 index 000000000..9f7ad78dd --- /dev/null +++ b/libs/libpng-src/contrib/gregbook/rpng2-win.c @@ -0,0 +1,1225 @@ +/*--------------------------------------------------------------------------- + + rpng2 - progressive-model PNG display program rpng2-win.c + + This program decodes and displays PNG files progressively, as if it were + a web browser (though the front end is only set up to read from files). + It supports gamma correction, user-specified background colors, and user- + specified background patterns (for transparent images). This version is + for 32-bit Windows; it may compile under 16-bit Windows with a little + tweaking (or maybe not). Thanks to Adam Costello and Pieter S. van der + Meulen for the "diamond" and "radial waves" patterns, respectively. + + to do (someday, maybe): + - handle quoted command-line args (especially filenames with spaces) + - finish resizable checkerboard-gradient (sizes 4-128?) + - use %.1023s to simplify truncation of title-bar string? + - have minimum window width: oh well + + --------------------------------------------------------------------------- + + Changelog: + - 1.01: initial public release + - 1.02: fixed cut-and-paste error in usage screen (oops...) + - 1.03: modified to allow abbreviated options + - 1.04: removed bogus extra argument from usage fprintf() [Glenn R-P?]; + fixed command-line parsing bug + - 1.10: enabled "message window"/console (thanks to David Geldreich) + - 1.20: added runtime MMX-enabling/disabling and new -mmx* options + - 1.21: made minor tweak to usage screen to fit within 25-line console + - 1.22: added AMD64/EM64T support (__x86_64__) + - 2.00: dual-licensed (added GNU GPL) + - 2.01: fixed 64-bit typo in readpng2.c + - 2.02: fixed improper display of usage screen on PNG error(s); fixed + unexpected-EOF and file-read-error cases + + --------------------------------------------------------------------------- + + Copyright (c) 1998-2008 Greg Roelofs. All rights reserved. + + This software is provided "as is," without warranty of any kind, + express or implied. In no event shall the author or contributors + be held liable for any damages arising in any way from the use of + this software. + + The contents of this file are DUAL-LICENSED. You may modify and/or + redistribute this software according to the terms of one of the + following two licenses (at your option): + + + LICENSE 1 ("BSD-like with advertising clause"): + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute + it freely, subject to the following restrictions: + + 1. Redistributions of source code must retain the above copyright + notice, disclaimer, and this list of conditions. + 2. Redistributions in binary form must reproduce the above copyright + notice, disclaimer, and this list of conditions in the documenta- + tion and/or other materials provided with the distribution. + 3. All advertising materials mentioning features or use of this + software must display the following acknowledgment: + + This product includes software developed by Greg Roelofs + and contributors for the book, "PNG: The Definitive Guide," + published by O'Reilly and Associates. + + + LICENSE 2 (GNU GPL v2 or later): + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + ---------------------------------------------------------------------------*/ + +#define PROGNAME "rpng2-win" +#define LONGNAME "Progressive PNG Viewer for Windows" +#define VERSION "2.02 of 16 March 2008" + +#include +#include +#include +#include /* for jmpbuf declaration in readpng2.h */ +#include +#include /* only for PvdM background code */ +#include +#include /* only for _getch() */ + +/* all for PvdM background code: */ +#ifndef PI +# define PI 3.141592653589793238 +#endif +#define PI_2 (PI*0.5) +#define INV_PI_360 (360.0 / PI) +#define MAX(a,b) (a>b?a:b) +#define MIN(a,b) (a> 8)) >> 8); \ +} + + +#define INBUFSIZE 4096 /* with pseudo-timing on (1 sec delay/block), this + * block size corresponds roughly to a download + * speed 10% faster than theoretical 33.6K maximum + * (assuming 8 data bits, 1 stop bit and no other + * overhead) */ + +/* local prototypes */ +static void rpng2_win_init(void); +static int rpng2_win_create_window(void); +static int rpng2_win_load_bg_image(void); +static void rpng2_win_display_row(ulg row); +static void rpng2_win_finish_display(void); +static void rpng2_win_cleanup(void); +LRESULT CALLBACK rpng2_win_wndproc(HWND, UINT, WPARAM, LPARAM); + + +static char titlebar[1024]; +static char *progname = PROGNAME; +static char *appname = LONGNAME; +static char *filename; +static FILE *infile; + +static mainprog_info rpng2_info; + +static uch inbuf[INBUFSIZE]; +static int incount; + +static int pat = 6; /* must be less than num_bgpat */ +static int bg_image = 0; +static int bgscale = 16; +static ulg bg_rowbytes; +static uch *bg_data; + +static struct rgb_color { + uch r, g, b; +} rgb[] = { + { 0, 0, 0}, /* 0: black */ + {255, 255, 255}, /* 1: white */ + {173, 132, 57}, /* 2: tan */ + { 64, 132, 0}, /* 3: medium green */ + {189, 117, 1}, /* 4: gold */ + {253, 249, 1}, /* 5: yellow */ + { 0, 0, 255}, /* 6: blue */ + { 0, 0, 120}, /* 7: medium blue */ + {255, 0, 255}, /* 8: magenta */ + { 64, 0, 64}, /* 9: dark magenta */ + {255, 0, 0}, /* 10: red */ + { 64, 0, 0}, /* 11: dark red */ + {255, 127, 0}, /* 12: orange */ + {192, 96, 0}, /* 13: darker orange */ + { 24, 60, 0}, /* 14: dark green-yellow */ + { 85, 125, 200} /* 15: ice blue */ +}; +/* not used for now, but should be for error-checking: +static int num_rgb = sizeof(rgb) / sizeof(struct rgb_color); + */ + +/* + This whole struct is a fairly cheesy way to keep the number of + command-line options to a minimum. The radial-waves background + type is a particularly poor fit to the integer elements of the + struct...but a few macros and a little fixed-point math will do + wonders for ya. + + type bits: + F E D C B A 9 8 7 6 5 4 3 2 1 0 + | | | | | + | | +-+-+-- 0 = sharp-edged checkerboard + | | 1 = soft diamonds + | | 2 = radial waves + | | 3-7 = undefined + | +-- gradient #2 inverted? + +-- alternating columns inverted? + */ +static struct background_pattern { + ush type; + int rgb1_max, rgb1_min; /* or bg_freq, bg_gray */ + int rgb2_max, rgb2_min; /* or bg_bsat, bg_brot (both scaled by 10)*/ +} bg[] = { + {0+8, 2,0, 1,15}, /* checkered: tan/black vs. white/ice blue */ + {0+24, 2,0, 1,0}, /* checkered: tan/black vs. white/black */ + {0+8, 4,5, 0,2}, /* checkered: gold/yellow vs. black/tan */ + {0+8, 4,5, 0,6}, /* checkered: gold/yellow vs. black/blue */ + {0, 7,0, 8,9}, /* checkered: deep blue/black vs. magenta */ + {0+8, 13,0, 5,14}, /* checkered: orange/black vs. yellow */ + {0+8, 12,0, 10,11}, /* checkered: orange/black vs. red */ + {1, 7,0, 8,0}, /* diamonds: deep blue/black vs. magenta */ + {1, 12,0, 11,0}, /* diamonds: orange vs. dark red */ + {1, 10,0, 7,0}, /* diamonds: red vs. medium blue */ + {1, 4,0, 5,0}, /* diamonds: gold vs. yellow */ + {1, 3,0, 0,0}, /* diamonds: medium green vs. black */ + {2, 16, 100, 20, 0}, /* radial: ~hard radial color-beams */ + {2, 18, 100, 10, 2}, /* radial: soft, curved radial color-beams */ + {2, 16, 256, 100, 250}, /* radial: very tight spiral */ + {2, 10000, 256, 11, 0} /* radial: dipole-moire' (almost fractal) */ +}; +static int num_bgpat = sizeof(bg) / sizeof(struct background_pattern); + + +/* Windows-specific global variables (could go in struct, but messy...) */ +static ulg wimage_rowbytes; +static uch *dib; +static uch *wimage_data; +static BITMAPINFOHEADER *bmih; + +static HWND global_hwnd; +static HINSTANCE global_hInst; +static int global_showmode; + + + + +int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, PSTR cmd, int showmode) +{ + char *args[1024]; /* arbitrary limit, but should suffice */ + char **argv = args; + char *p, *q, *bgstr = NULL; + int argc = 0; + int rc, alen, flen; + int error = 0; + int timing = FALSE; + int have_bg = FALSE; + double LUT_exponent; /* just the lookup table */ + double CRT_exponent = 2.2; /* just the monitor */ + double default_display_exponent; /* whole display system */ + MSG msg; + + + /* First initialize a few things, just to be sure--memset takes care of + * default background color (black), booleans (FALSE), pointers (NULL), + * etc. */ + + global_hInst = hInst; + global_showmode = showmode; + filename = (char *)NULL; + memset(&rpng2_info, 0, sizeof(mainprog_info)); + + + /* Next reenable console output, which normally goes to the bit bucket + * for windowed apps. Closing the console window will terminate the + * app. Thanks to David.Geldreich@realviz.com for supplying the magical + * incantation. */ + + AllocConsole(); + freopen("CONOUT$", "a", stderr); + freopen("CONOUT$", "a", stdout); + + + /* Set the default value for our display-system exponent, i.e., the + * product of the CRT exponent and the exponent corresponding to + * the frame-buffer's lookup table (LUT), if any. This is not an + * exhaustive list of LUT values (e.g., OpenStep has a lot of weird + * ones), but it should cover 99% of the current possibilities. And + * yes, these ifdefs are completely wasted in a Windows program... */ + +#if defined(NeXT) + /* third-party utilities can modify the default LUT exponent */ + LUT_exponent = 1.0 / 2.2; + /* + if (some_next_function_that_returns_gamma(&next_gamma)) + LUT_exponent = 1.0 / next_gamma; + */ +#elif defined(sgi) + LUT_exponent = 1.0 / 1.7; + /* there doesn't seem to be any documented function to + * get the "gamma" value, so we do it the hard way */ + infile = fopen("/etc/config/system.glGammaVal", "r"); + if (infile) { + double sgi_gamma; + + fgets(tmpline, 80, infile); + fclose(infile); + sgi_gamma = atof(tmpline); + if (sgi_gamma > 0.0) + LUT_exponent = 1.0 / sgi_gamma; + } +#elif defined(Macintosh) + LUT_exponent = 1.8 / 2.61; + /* + if (some_mac_function_that_returns_gamma(&mac_gamma)) + LUT_exponent = mac_gamma / 2.61; + */ +#else + LUT_exponent = 1.0; /* assume no LUT: most PCs */ +#endif + + /* the defaults above give 1.0, 1.3, 1.5 and 2.2, respectively: */ + default_display_exponent = LUT_exponent * CRT_exponent; + + + /* If the user has set the SCREEN_GAMMA environment variable as suggested + * (somewhat imprecisely) in the libpng documentation, use that; otherwise + * use the default value we just calculated. Either way, the user may + * override this via a command-line option. */ + + if ((p = getenv("SCREEN_GAMMA")) != NULL) + rpng2_info.display_exponent = atof(p); + else + rpng2_info.display_exponent = default_display_exponent; + + + /* Windows really hates command lines, so we have to set up our own argv. + * Note that we do NOT bother with quoted arguments here, so don't use + * filenames with spaces in 'em! */ + + argv[argc++] = PROGNAME; + p = cmd; + for (;;) { + if (*p == ' ') + while (*++p == ' ') + ; + /* now p points at the first non-space after some spaces */ + if (*p == '\0') + break; /* nothing after the spaces: done */ + argv[argc++] = q = p; + while (*q && *q != ' ') + ++q; + /* now q points at a space or the end of the string */ + if (*q == '\0') + break; /* last argv already terminated; quit */ + *q = '\0'; /* change space to terminator */ + p = q + 1; + } + argv[argc] = NULL; /* terminate the argv array itself */ + + + /* Now parse the command line for options and the PNG filename. */ + + while (*++argv && !error) { + if (!strncmp(*argv, "-gamma", 2)) { + if (!*++argv) + ++error; + else { + rpng2_info.display_exponent = atof(*argv); + if (rpng2_info.display_exponent <= 0.0) + ++error; + } + } else if (!strncmp(*argv, "-bgcolor", 4)) { + if (!*++argv) + ++error; + else { + bgstr = *argv; + if (strlen(bgstr) != 7 || bgstr[0] != '#') + ++error; + else { + have_bg = TRUE; + bg_image = FALSE; + } + } + } else if (!strncmp(*argv, "-bgpat", 4)) { + if (!*++argv) + ++error; + else { + pat = atoi(*argv) - 1; + if (pat < 0 || pat >= num_bgpat) + ++error; + else { + bg_image = TRUE; + have_bg = FALSE; + } + } + } else if (!strncmp(*argv, "-timing", 2)) { + timing = TRUE; +#if (defined(__i386__) || defined(_M_IX86) || defined(__x86_64__)) + } else if (!strncmp(*argv, "-nommxfilters", 7)) { + rpng2_info.nommxfilters = TRUE; + } else if (!strncmp(*argv, "-nommxcombine", 7)) { + rpng2_info.nommxcombine = TRUE; + } else if (!strncmp(*argv, "-nommxinterlace", 7)) { + rpng2_info.nommxinterlace = TRUE; + } else if (!strcmp(*argv, "-nommx")) { + rpng2_info.nommxfilters = TRUE; + rpng2_info.nommxcombine = TRUE; + rpng2_info.nommxinterlace = TRUE; +#endif + } else { + if (**argv != '-') { + filename = *argv; + if (argv[1]) /* shouldn't be any more args after filename */ + ++error; + } else + ++error; /* not expecting any other options */ + } + } + + if (!filename) + ++error; + + + /* print usage screen if any errors up to this point */ + + if (error) { + int ch; + + fprintf(stderr, "\n%s %s: %s\n\n", PROGNAME, VERSION, appname); + readpng2_version_info(); + fprintf(stderr, "\n" + "Usage: %s [-gamma exp] [-bgcolor bg | -bgpat pat] [-timing]\n" +#if (defined(__i386__) || defined(_M_IX86) || defined(__x86_64__)) + " %*s [[-nommxfilters] [-nommxcombine] [-nommxinterlace] | -nommx]\n" +#endif + " %*s file.png\n\n" + " exp \ttransfer-function exponent (``gamma'') of the display\n" + "\t\t system in floating-point format (e.g., ``%.1f''); equal\n" + "\t\t to the product of the lookup-table exponent (varies)\n" + "\t\t and the CRT exponent (usually 2.2); must be positive\n" + " bg \tdesired background color in 7-character hex RGB format\n" + "\t\t (e.g., ``#ff7700'' for orange: same as HTML colors);\n" + "\t\t used with transparent images; overrides -bgpat option\n" + " pat \tdesired background pattern number (1-%d); used with\n" + "\t\t transparent images; overrides -bgcolor option\n" + " -timing\tenables delay for every block read, to simulate modem\n" + "\t\t download of image (~36 Kbps)\n" +#if (defined(__i386__) || defined(_M_IX86) || defined(__x86_64__)) + " -nommx*\tdisable optimized MMX routines for decoding row filters,\n" + "\t\t combining rows, and expanding interlacing, respectively\n" +#endif + "\nPress Q, Esc or mouse button 1 after image is displayed to quit.\n" + "Press Q or Esc to quit this usage screen. ", + PROGNAME, +#if (defined(__i386__) || defined(_M_IX86) || defined(__x86_64__)) + (int)strlen(PROGNAME), " ", +#endif + (int)strlen(PROGNAME), " ", default_display_exponent, num_bgpat); + fflush(stderr); + do + ch = _getch(); + while (ch != 'q' && ch != 'Q' && ch != 0x1B); + exit(1); + } + + + if (!(infile = fopen(filename, "rb"))) { + fprintf(stderr, PROGNAME ": can't open PNG file [%s]\n", filename); + ++error; + } else { + incount = fread(inbuf, 1, INBUFSIZE, infile); + if (incount < 8 || !readpng2_check_sig(inbuf, 8)) { + fprintf(stderr, PROGNAME + ": [%s] is not a PNG file: incorrect signature\n", + filename); + ++error; + } else if ((rc = readpng2_init(&rpng2_info)) != 0) { + switch (rc) { + case 2: + fprintf(stderr, PROGNAME + ": [%s] has bad IHDR (libpng longjmp)\n", filename); + break; + case 4: + fprintf(stderr, PROGNAME ": insufficient memory\n"); + break; + default: + fprintf(stderr, PROGNAME + ": unknown readpng2_init() error\n"); + break; + } + ++error; + } + if (error) + fclose(infile); + } + + + if (error) { + int ch; + + fprintf(stderr, PROGNAME ": aborting.\n"); + do + ch = _getch(); + while (ch != 'q' && ch != 'Q' && ch != 0x1B); + exit(2); + } else { + fprintf(stderr, "\n%s %s: %s\n", PROGNAME, VERSION, appname); + fprintf(stderr, + "\n [console window: closing this window will terminate %s]\n\n", + PROGNAME); + fflush(stderr); + } + + + /* set the title-bar string, but make sure buffer doesn't overflow */ + + alen = strlen(appname); + flen = strlen(filename); + if (alen + flen + 3 > 1023) + sprintf(titlebar, "%s: ...%s", appname, filename+(alen+flen+6-1023)); + else + sprintf(titlebar, "%s: %s", appname, filename); + + + /* set some final rpng2_info variables before entering main data loop */ + + if (have_bg) { + unsigned r, g, b; /* this approach quiets compiler warnings */ + + sscanf(bgstr+1, "%2x%2x%2x", &r, &g, &b); + rpng2_info.bg_red = (uch)r; + rpng2_info.bg_green = (uch)g; + rpng2_info.bg_blue = (uch)b; + } else + rpng2_info.need_bgcolor = TRUE; + + rpng2_info.state = kPreInit; + rpng2_info.mainprog_init = rpng2_win_init; + rpng2_info.mainprog_display_row = rpng2_win_display_row; + rpng2_info.mainprog_finish_display = rpng2_win_finish_display; + + + /* OK, this is the fun part: call readpng2_decode_data() at the start of + * the loop to deal with our first buffer of data (read in above to verify + * that the file is a PNG image), then loop through the file and continue + * calling the same routine to handle each chunk of data. It in turn + * passes the data to libpng, which will invoke one or more of our call- + * backs as decoded data become available. We optionally call Sleep() for + * one second per iteration to simulate downloading the image via an analog + * modem. */ + + for (;;) { + Trace((stderr, "about to call readpng2_decode_data()\n")) + if (readpng2_decode_data(&rpng2_info, inbuf, incount)) + ++error; + Trace((stderr, "done with readpng2_decode_data()\n")) + + if (error || incount != INBUFSIZE || rpng2_info.state == kDone) { + if (rpng2_info.state == kDone) { + Trace((stderr, "done decoding PNG image\n")) + } else if (ferror(infile)) { + fprintf(stderr, PROGNAME + ": error while reading PNG image file\n"); + exit(3); + } else if (feof(infile)) { + fprintf(stderr, PROGNAME ": end of file reached " + "(unexpectedly) while reading PNG image file\n"); + exit(3); + } else /* if (error) */ { + // will print error message below + } + break; + } + + if (timing) + Sleep(1000L); + + incount = fread(inbuf, 1, INBUFSIZE, infile); + } + + + /* clean up PNG stuff and report any decoding errors */ + + fclose(infile); + Trace((stderr, "about to call readpng2_cleanup()\n")) + readpng2_cleanup(&rpng2_info); + + if (error) { + fprintf(stderr, PROGNAME ": libpng error while decoding PNG image\n"); + exit(3); + } + + + /* wait for the user to tell us when to quit */ + + while (GetMessage(&msg, NULL, 0, 0)) { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + + + /* we're done: clean up all image and Windows resources and go away */ + + Trace((stderr, "about to call rpng2_win_cleanup()\n")) + rpng2_win_cleanup(); + + return msg.wParam; +} + + + + + +/* this function is called by readpng2_info_callback() in readpng2.c, which + * in turn is called by libpng after all of the pre-IDAT chunks have been + * read and processed--i.e., we now have enough info to finish initializing */ + +static void rpng2_win_init() +{ + ulg i; + ulg rowbytes = rpng2_info.rowbytes; + + Trace((stderr, "beginning rpng2_win_init()\n")) + Trace((stderr, " rowbytes = %d\n", rpng2_info.rowbytes)) + Trace((stderr, " width = %ld\n", rpng2_info.width)) + Trace((stderr, " height = %ld\n", rpng2_info.height)) + + rpng2_info.image_data = (uch *)malloc(rowbytes * rpng2_info.height); + if (!rpng2_info.image_data) { + readpng2_cleanup(&rpng2_info); + return; + } + + rpng2_info.row_pointers = (uch **)malloc(rpng2_info.height * sizeof(uch *)); + if (!rpng2_info.row_pointers) { + free(rpng2_info.image_data); + rpng2_info.image_data = NULL; + readpng2_cleanup(&rpng2_info); + return; + } + + for (i = 0; i < rpng2_info.height; ++i) + rpng2_info.row_pointers[i] = rpng2_info.image_data + i*rowbytes; + +/*--------------------------------------------------------------------------- + Do the basic Windows initialization stuff, make the window, and fill it + with the user-specified, file-specified or default background color. + ---------------------------------------------------------------------------*/ + + if (rpng2_win_create_window()) { + readpng2_cleanup(&rpng2_info); + return; + } + + rpng2_info.state = kWindowInit; +} + + + + + +static int rpng2_win_create_window() +{ + uch bg_red = rpng2_info.bg_red; + uch bg_green = rpng2_info.bg_green; + uch bg_blue = rpng2_info.bg_blue; + uch *dest; + int extra_width, extra_height; + ulg i, j; + WNDCLASSEX wndclass; + RECT rect; + + +/*--------------------------------------------------------------------------- + Allocate memory for the display-specific version of the image (round up + to multiple of 4 for Windows DIB). + ---------------------------------------------------------------------------*/ + + wimage_rowbytes = ((3*rpng2_info.width + 3L) >> 2) << 2; + + if (!(dib = (uch *)malloc(sizeof(BITMAPINFOHEADER) + + wimage_rowbytes*rpng2_info.height))) + { + return 4; /* fail */ + } + +/*--------------------------------------------------------------------------- + Initialize the DIB. Negative height means to use top-down BMP ordering + (must be uncompressed, but that's what we want). Bit count of 1, 4 or 8 + implies a colormap of RGBX quads, but 24-bit BMPs just use B,G,R values + directly => wimage_data begins immediately after BMP header. + ---------------------------------------------------------------------------*/ + + memset(dib, 0, sizeof(BITMAPINFOHEADER)); + bmih = (BITMAPINFOHEADER *)dib; + bmih->biSize = sizeof(BITMAPINFOHEADER); + bmih->biWidth = rpng2_info.width; + bmih->biHeight = -((long)rpng2_info.height); + bmih->biPlanes = 1; + bmih->biBitCount = 24; + bmih->biCompression = 0; + wimage_data = dib + sizeof(BITMAPINFOHEADER); + +/*--------------------------------------------------------------------------- + Fill window with the specified background color (default is black), but + defer loading faked "background image" until window is displayed (may be + slow to compute). Data are in BGR order. + ---------------------------------------------------------------------------*/ + + if (bg_image) { /* just fill with black for now */ + memset(wimage_data, 0, wimage_rowbytes*rpng2_info.height); + } else { + for (j = 0; j < rpng2_info.height; ++j) { + dest = wimage_data + j*wimage_rowbytes; + for (i = rpng2_info.width; i > 0; --i) { + *dest++ = bg_blue; + *dest++ = bg_green; + *dest++ = bg_red; + } + } + } + +/*--------------------------------------------------------------------------- + Set the window parameters. + ---------------------------------------------------------------------------*/ + + memset(&wndclass, 0, sizeof(wndclass)); + + wndclass.cbSize = sizeof(wndclass); + wndclass.style = CS_HREDRAW | CS_VREDRAW; + wndclass.lpfnWndProc = rpng2_win_wndproc; + wndclass.hInstance = global_hInst; + wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); + wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); + wndclass.hbrBackground = (HBRUSH)GetStockObject(DKGRAY_BRUSH); + wndclass.lpszMenuName = NULL; + wndclass.lpszClassName = progname; + wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION); + + RegisterClassEx(&wndclass); + +/*--------------------------------------------------------------------------- + Finally, create the window. + ---------------------------------------------------------------------------*/ + + extra_width = 2*(GetSystemMetrics(SM_CXBORDER) + + GetSystemMetrics(SM_CXDLGFRAME)); + extra_height = 2*(GetSystemMetrics(SM_CYBORDER) + + GetSystemMetrics(SM_CYDLGFRAME)) + + GetSystemMetrics(SM_CYCAPTION); + + global_hwnd = CreateWindow(progname, titlebar, WS_OVERLAPPEDWINDOW, + CW_USEDEFAULT, CW_USEDEFAULT, rpng2_info.width+extra_width, + rpng2_info.height+extra_height, NULL, NULL, global_hInst, NULL); + + ShowWindow(global_hwnd, global_showmode); + UpdateWindow(global_hwnd); + +/*--------------------------------------------------------------------------- + Now compute the background image and display it. If it fails (memory + allocation), revert to a plain background color. + ---------------------------------------------------------------------------*/ + + if (bg_image) { + static const char *msg = "Computing background image..."; + int x, y, len = strlen(msg); + HDC hdc = GetDC(global_hwnd); + TEXTMETRIC tm; + + GetTextMetrics(hdc, &tm); + x = (rpng2_info.width - len*tm.tmAveCharWidth)/2; + y = (rpng2_info.height - tm.tmHeight)/2; + SetBkMode(hdc, TRANSPARENT); + SetTextColor(hdc, GetSysColor(COLOR_HIGHLIGHTTEXT)); + /* this can still begin out of bounds even if x is positive (???): */ + TextOut(hdc, ((x < 0)? 0 : x), ((y < 0)? 0 : y), msg, len); + ReleaseDC(global_hwnd, hdc); + + rpng2_win_load_bg_image(); /* resets bg_image if fails */ + } + + if (!bg_image) { + for (j = 0; j < rpng2_info.height; ++j) { + dest = wimage_data + j*wimage_rowbytes; + for (i = rpng2_info.width; i > 0; --i) { + *dest++ = bg_blue; + *dest++ = bg_green; + *dest++ = bg_red; + } + } + } + + rect.left = 0L; + rect.top = 0L; + rect.right = (LONG)rpng2_info.width; /* possibly off by one? */ + rect.bottom = (LONG)rpng2_info.height; /* possibly off by one? */ + InvalidateRect(global_hwnd, &rect, FALSE); + UpdateWindow(global_hwnd); /* similar to XFlush() */ + + return 0; + +} /* end function rpng2_win_create_window() */ + + + + + +static int rpng2_win_load_bg_image() +{ + uch *src, *dest; + uch r1, r2, g1, g2, b1, b2; + uch r1_inv, r2_inv, g1_inv, g2_inv, b1_inv, b2_inv; + int k, hmax, max; + int xidx, yidx, yidx_max = (bgscale-1); + int even_odd_vert, even_odd_horiz, even_odd; + int invert_gradient2 = (bg[pat].type & 0x08); + int invert_column; + ulg i, row; + +/*--------------------------------------------------------------------------- + Allocate buffer for fake background image to be used with transparent + images; if this fails, revert to plain background color. + ---------------------------------------------------------------------------*/ + + bg_rowbytes = 3 * rpng2_info.width; + bg_data = (uch *)malloc(bg_rowbytes * rpng2_info.height); + if (!bg_data) { + fprintf(stderr, PROGNAME + ": unable to allocate memory for background image\n"); + bg_image = 0; + return 1; + } + +/*--------------------------------------------------------------------------- + Vertical gradients (ramps) in NxN squares, alternating direction and + colors (N == bgscale). + ---------------------------------------------------------------------------*/ + + if ((bg[pat].type & 0x07) == 0) { + uch r1_min = rgb[bg[pat].rgb1_min].r; + uch g1_min = rgb[bg[pat].rgb1_min].g; + uch b1_min = rgb[bg[pat].rgb1_min].b; + uch r2_min = rgb[bg[pat].rgb2_min].r; + uch g2_min = rgb[bg[pat].rgb2_min].g; + uch b2_min = rgb[bg[pat].rgb2_min].b; + int r1_diff = rgb[bg[pat].rgb1_max].r - r1_min; + int g1_diff = rgb[bg[pat].rgb1_max].g - g1_min; + int b1_diff = rgb[bg[pat].rgb1_max].b - b1_min; + int r2_diff = rgb[bg[pat].rgb2_max].r - r2_min; + int g2_diff = rgb[bg[pat].rgb2_max].g - g2_min; + int b2_diff = rgb[bg[pat].rgb2_max].b - b2_min; + + for (row = 0; row < rpng2_info.height; ++row) { + yidx = row % bgscale; + even_odd_vert = (row / bgscale) & 1; + + r1 = r1_min + (r1_diff * yidx) / yidx_max; + g1 = g1_min + (g1_diff * yidx) / yidx_max; + b1 = b1_min + (b1_diff * yidx) / yidx_max; + r1_inv = r1_min + (r1_diff * (yidx_max-yidx)) / yidx_max; + g1_inv = g1_min + (g1_diff * (yidx_max-yidx)) / yidx_max; + b1_inv = b1_min + (b1_diff * (yidx_max-yidx)) / yidx_max; + + r2 = r2_min + (r2_diff * yidx) / yidx_max; + g2 = g2_min + (g2_diff * yidx) / yidx_max; + b2 = b2_min + (b2_diff * yidx) / yidx_max; + r2_inv = r2_min + (r2_diff * (yidx_max-yidx)) / yidx_max; + g2_inv = g2_min + (g2_diff * (yidx_max-yidx)) / yidx_max; + b2_inv = b2_min + (b2_diff * (yidx_max-yidx)) / yidx_max; + + dest = bg_data + row*bg_rowbytes; + for (i = 0; i < rpng2_info.width; ++i) { + even_odd_horiz = (i / bgscale) & 1; + even_odd = even_odd_vert ^ even_odd_horiz; + invert_column = + (even_odd_horiz && (bg[pat].type & 0x10)); + if (even_odd == 0) { /* gradient #1 */ + if (invert_column) { + *dest++ = r1_inv; + *dest++ = g1_inv; + *dest++ = b1_inv; + } else { + *dest++ = r1; + *dest++ = g1; + *dest++ = b1; + } + } else { /* gradient #2 */ + if ((invert_column && invert_gradient2) || + (!invert_column && !invert_gradient2)) + { + *dest++ = r2; /* not inverted or */ + *dest++ = g2; /* doubly inverted */ + *dest++ = b2; + } else { + *dest++ = r2_inv; + *dest++ = g2_inv; /* singly inverted */ + *dest++ = b2_inv; + } + } + } + } + +/*--------------------------------------------------------------------------- + Soft gradient-diamonds with scale = bgscale. Code contributed by Adam + M. Costello. + ---------------------------------------------------------------------------*/ + + } else if ((bg[pat].type & 0x07) == 1) { + + hmax = (bgscale-1)/2; /* half the max weight of a color */ + max = 2*hmax; /* the max weight of a color */ + + r1 = rgb[bg[pat].rgb1_max].r; + g1 = rgb[bg[pat].rgb1_max].g; + b1 = rgb[bg[pat].rgb1_max].b; + r2 = rgb[bg[pat].rgb2_max].r; + g2 = rgb[bg[pat].rgb2_max].g; + b2 = rgb[bg[pat].rgb2_max].b; + + for (row = 0; row < rpng2_info.height; ++row) { + yidx = row % bgscale; + if (yidx > hmax) + yidx = bgscale-1 - yidx; + dest = bg_data + row*bg_rowbytes; + for (i = 0; i < rpng2_info.width; ++i) { + xidx = i % bgscale; + if (xidx > hmax) + xidx = bgscale-1 - xidx; + k = xidx + yidx; + *dest++ = (k*r1 + (max-k)*r2) / max; + *dest++ = (k*g1 + (max-k)*g2) / max; + *dest++ = (k*b1 + (max-k)*b2) / max; + } + } + +/*--------------------------------------------------------------------------- + Radial "starburst" with azimuthal sinusoids; [eventually number of sinu- + soids will equal bgscale?]. This one is slow but very cool. Code con- + tributed by Pieter S. van der Meulen (originally in Smalltalk). + ---------------------------------------------------------------------------*/ + + } else if ((bg[pat].type & 0x07) == 2) { + uch ch; + int ii, x, y, hw, hh, grayspot; + double freq, rotate, saturate, gray, intensity; + double angle=0.0, aoffset=0.0, maxDist, dist; + double red=0.0, green=0.0, blue=0.0, hue, s, v, f, p, q, t; + + fprintf(stderr, "%s: computing radial background...", + PROGNAME); + fflush(stderr); + + hh = rpng2_info.height / 2; + hw = rpng2_info.width / 2; + + /* variables for radial waves: + * aoffset: number of degrees to rotate hue [CURRENTLY NOT USED] + * freq: number of color beams originating from the center + * grayspot: size of the graying center area (anti-alias) + * rotate: rotation of the beams as a function of radius + * saturate: saturation of beams' shape azimuthally + */ + angle = CLIP(angle, 0.0, 360.0); + grayspot = CLIP(bg[pat].bg_gray, 1, (hh + hw)); + freq = MAX((double)bg[pat].bg_freq, 0.0); + saturate = (double)bg[pat].bg_bsat * 0.1; + rotate = (double)bg[pat].bg_brot * 0.1; + gray = 0.0; + intensity = 0.0; + maxDist = (double)((hw*hw) + (hh*hh)); + + for (row = 0; row < rpng2_info.height; ++row) { + y = row - hh; + dest = bg_data + row*bg_rowbytes; + for (i = 0; i < rpng2_info.width; ++i) { + x = i - hw; + angle = (x == 0)? PI_2 : atan((double)y / (double)x); + gray = (double)MAX(ABS(y), ABS(x)) / grayspot; + gray = MIN(1.0, gray); + dist = (double)((x*x) + (y*y)) / maxDist; + intensity = cos((angle+(rotate*dist*PI)) * freq) * + gray * saturate; + intensity = (MAX(MIN(intensity,1.0),-1.0) + 1.0) * 0.5; + hue = (angle + PI) * INV_PI_360 + aoffset; + s = gray * ((double)(ABS(x)+ABS(y)) / (double)(hw + hh)); + s = MIN(MAX(s,0.0), 1.0); + v = MIN(MAX(intensity,0.0), 1.0); + + if (s == 0.0) { + ch = (uch)(v * 255.0); + *dest++ = ch; + *dest++ = ch; + *dest++ = ch; + } else { + if ((hue < 0.0) || (hue >= 360.0)) + hue -= (((int)(hue / 360.0)) * 360.0); + hue /= 60.0; + ii = (int)hue; + f = hue - (double)ii; + p = (1.0 - s) * v; + q = (1.0 - (s * f)) * v; + t = (1.0 - (s * (1.0 - f))) * v; + if (ii == 0) { red = v; green = t; blue = p; } + else if (ii == 1) { red = q; green = v; blue = p; } + else if (ii == 2) { red = p; green = v; blue = t; } + else if (ii == 3) { red = p; green = q; blue = v; } + else if (ii == 4) { red = t; green = p; blue = v; } + else if (ii == 5) { red = v; green = p; blue = q; } + *dest++ = (uch)(red * 255.0); + *dest++ = (uch)(green * 255.0); + *dest++ = (uch)(blue * 255.0); + } + } + } + fprintf(stderr, "done.\n"); + fflush(stderr); + } + +/*--------------------------------------------------------------------------- + Blast background image to display buffer before beginning PNG decode; + calling function will handle invalidation and UpdateWindow() call. + ---------------------------------------------------------------------------*/ + + for (row = 0; row < rpng2_info.height; ++row) { + src = bg_data + row*bg_rowbytes; + dest = wimage_data + row*wimage_rowbytes; + for (i = rpng2_info.width; i > 0; --i) { + r1 = *src++; + g1 = *src++; + b1 = *src++; + *dest++ = b1; + *dest++ = g1; /* note reverse order */ + *dest++ = r1; + } + } + + return 0; + +} /* end function rpng2_win_load_bg_image() */ + + + + + +static void rpng2_win_display_row(ulg row) +{ + uch bg_red = rpng2_info.bg_red; + uch bg_green = rpng2_info.bg_green; + uch bg_blue = rpng2_info.bg_blue; + uch *src, *src2=NULL, *dest; + uch r, g, b, a; + ulg i; + static int rows=0; + static ulg firstrow; + +/*--------------------------------------------------------------------------- + rows and firstrow simply track how many rows (and which ones) have not + yet been displayed; alternatively, we could call InvalidateRect() for + every row and not bother with the records-keeping. + ---------------------------------------------------------------------------*/ + + Trace((stderr, "beginning rpng2_win_display_row()\n")) + + if (rows == 0) + firstrow = row; /* first row not yet displayed */ + + ++rows; /* count of rows received but not yet displayed */ + +/*--------------------------------------------------------------------------- + Aside from the use of the rpng2_info struct and the lack of an outer + loop (over rows), this routine is identical to rpng_win_display_image() + in the non-progressive version of the program. + ---------------------------------------------------------------------------*/ + + src = rpng2_info.image_data + row*rpng2_info.rowbytes; + if (bg_image) + src2 = bg_data + row*bg_rowbytes; + dest = wimage_data + row*wimage_rowbytes; + + if (rpng2_info.channels == 3) { + for (i = rpng2_info.width; i > 0; --i) { + r = *src++; + g = *src++; + b = *src++; + *dest++ = b; + *dest++ = g; /* note reverse order */ + *dest++ = r; + } + } else /* if (rpng2_info.channels == 4) */ { + for (i = rpng2_info.width; i > 0; --i) { + r = *src++; + g = *src++; + b = *src++; + a = *src++; + if (bg_image) { + bg_red = *src2++; + bg_green = *src2++; + bg_blue = *src2++; + } + if (a == 255) { + *dest++ = b; + *dest++ = g; + *dest++ = r; + } else if (a == 0) { + *dest++ = bg_blue; + *dest++ = bg_green; + *dest++ = bg_red; + } else { + /* this macro (copied from png.h) composites the + * foreground and background values and puts the + * result into the first argument; there are no + * side effects with the first argument */ + alpha_composite(*dest++, b, a, bg_blue); + alpha_composite(*dest++, g, a, bg_green); + alpha_composite(*dest++, r, a, bg_red); + } + } + } + +/*--------------------------------------------------------------------------- + Display after every 16 rows or when on last row. (Region may include + previously displayed lines due to interlacing--i.e., not contiguous.) + ---------------------------------------------------------------------------*/ + + if ((rows & 0xf) == 0 || row == rpng2_info.height-1) { + RECT rect; + + rect.left = 0L; + rect.top = (LONG)firstrow; + rect.right = (LONG)rpng2_info.width; /* possibly off by one? */ + rect.bottom = (LONG)row + 1L; /* possibly off by one? */ + InvalidateRect(global_hwnd, &rect, FALSE); + UpdateWindow(global_hwnd); /* similar to XFlush() */ + rows = 0; + } + +} /* end function rpng2_win_display_row() */ + + + + + +static void rpng2_win_finish_display() +{ + Trace((stderr, "beginning rpng2_win_finish_display()\n")) + + /* last row has already been displayed by rpng2_win_display_row(), so + * we have nothing to do here except set a flag and let the user know + * that the image is done */ + + rpng2_info.state = kDone; + printf( + "Done. Press Q, Esc or mouse button 1 (within image window) to quit.\n"); + fflush(stdout); +} + + + + + +static void rpng2_win_cleanup() +{ + if (bg_image && bg_data) { + free(bg_data); + bg_data = NULL; + } + + if (rpng2_info.image_data) { + free(rpng2_info.image_data); + rpng2_info.image_data = NULL; + } + + if (rpng2_info.row_pointers) { + free(rpng2_info.row_pointers); + rpng2_info.row_pointers = NULL; + } + + if (dib) { + free(dib); + dib = NULL; + } +} + + + + + +LRESULT CALLBACK rpng2_win_wndproc(HWND hwnd, UINT iMsg, WPARAM wP, LPARAM lP) +{ + HDC hdc; + PAINTSTRUCT ps; + int rc; + + switch (iMsg) { + case WM_CREATE: + /* one-time processing here, if any */ + return 0; + + case WM_PAINT: + hdc = BeginPaint(hwnd, &ps); + rc = StretchDIBits(hdc, 0, 0, rpng2_info.width, rpng2_info.height, + 0, 0, rpng2_info.width, rpng2_info.height, + wimage_data, (BITMAPINFO *)bmih, + 0, SRCCOPY); + EndPaint(hwnd, &ps); + return 0; + + /* wait for the user to tell us when to quit */ + case WM_CHAR: + switch (wP) { /* only need one, so ignore repeat count */ + case 'q': + case 'Q': + case 0x1B: /* Esc key */ + PostQuitMessage(0); + } + return 0; + + case WM_LBUTTONDOWN: /* another way of quitting */ + case WM_DESTROY: + PostQuitMessage(0); + return 0; + } + + return DefWindowProc(hwnd, iMsg, wP, lP); +} diff --git a/libs/libpng-src/contrib/gregbook/rpng2-x.c b/libs/libpng-src/contrib/gregbook/rpng2-x.c new file mode 100644 index 000000000..873af2335 --- /dev/null +++ b/libs/libpng-src/contrib/gregbook/rpng2-x.c @@ -0,0 +1,2127 @@ +/*--------------------------------------------------------------------------- + + rpng2 - progressive-model PNG display program rpng2-x.c + + This program decodes and displays PNG files progressively, as if it were + a web browser (though the front end is only set up to read from files). + It supports gamma correction, user-specified background colors, and user- + specified background patterns (for transparent images). This version is + for the X Window System (tested by the author under Unix and by Martin + Zinser under OpenVMS; may work under OS/2 with a little tweaking). + + Thanks to Adam Costello and Pieter S. van der Meulen for the "diamond" + and "radial waves" patterns, respectively. + + to do (someday, maybe): + - fix expose/redraw code: don't draw entire row if only part exposed + - 8-bit (colormapped) X support + - finish resizable checkerboard-gradient (sizes 4-128?) + - use %.1023s to simplify truncation of title-bar string? + + --------------------------------------------------------------------------- + + Changelog: + - 1.01: initial public release + - 1.02: modified to allow abbreviated options; fixed char/uchar mismatch + - 1.10: added support for non-default visuals; fixed X pixel-conversion + - 1.11: added -usleep option for demos; fixed command-line parsing bug + - 1.12: added -pause option for demos and testing + - 1.20: added runtime MMX-enabling/disabling and new -mmx* options + - 1.21: fixed some small X memory leaks (thanks to François Petitjean) + - 1.22: fixed XFreeGC() crash bug (thanks to Patrick Welche) + - 1.23: added -bgpat 0 mode (std white/gray checkerboard, 8x8 squares) + - 1.30: added -loop option for -bgpat (ifdef FEATURE_LOOP); fixed bpp = + 24; added support for X resources (thanks to Gerhard Niklasch) + - 1.31: added code to skip unused chunks (thanks to Glenn Randers-Pehrson) + - 1.32: added AMD64/EM64T support (__x86_64__); added basic expose/redraw + handling + - 2.00: dual-licensed (added GNU GPL) + - 2.01: fixed 64-bit typo in readpng2.c; fixed -pause usage description + - 2.02: fixed improper display of usage screen on PNG error(s); fixed + unexpected-EOF and file-read-error cases; fixed Trace() cut-and- + paste bugs + + --------------------------------------------------------------------------- + + Copyright (c) 1998-2008 Greg Roelofs. All rights reserved. + + This software is provided "as is," without warranty of any kind, + express or implied. In no event shall the author or contributors + be held liable for any damages arising in any way from the use of + this software. + + The contents of this file are DUAL-LICENSED. You may modify and/or + redistribute this software according to the terms of one of the + following two licenses (at your option): + + + LICENSE 1 ("BSD-like with advertising clause"): + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute + it freely, subject to the following restrictions: + + 1. Redistributions of source code must retain the above copyright + notice, disclaimer, and this list of conditions. + 2. Redistributions in binary form must reproduce the above copyright + notice, disclaimer, and this list of conditions in the documenta- + tion and/or other materials provided with the distribution. + 3. All advertising materials mentioning features or use of this + software must display the following acknowledgment: + + This product includes software developed by Greg Roelofs + and contributors for the book, "PNG: The Definitive Guide," + published by O'Reilly and Associates. + + + LICENSE 2 (GNU GPL v2 or later): + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + ---------------------------------------------------------------------------*/ + +#define PROGNAME "rpng2-x" +#define LONGNAME "Progressive PNG Viewer for X" +#define VERSION "2.02 of 16 March 2008" +#define RESNAME "rpng2" /* our X resource application name */ +#define RESCLASS "Rpng" /* our X resource class name */ + +#include +#include +#include +#include +#include /* for jmpbuf declaration in readpng2.h */ +#include +#include /* only for PvdM background code */ +#include +#include +#include +#include /* defines XK_* macros */ + +#ifdef VMS +# include +#endif + +/* all for PvdM background code: */ +#ifndef PI +# define PI 3.141592653589793238 +#endif +#define PI_2 (PI*0.5) +#define INV_PI_360 (360.0 / PI) +#define MAX(a,b) (a>b?a:b) +#define MIN(a,b) (a> 8)) >> 8); \ +} + + +#define INBUFSIZE 4096 /* with pseudo-timing on (1 sec delay/block), this + * block size corresponds roughly to a download + * speed 10% faster than theoretical 33.6K maximum + * (assuming 8 data bits, 1 stop bit and no other + * overhead) */ + +/* local prototypes */ +static void rpng2_x_init (void); +static int rpng2_x_create_window (void); +static int rpng2_x_load_bg_image (void); +static void rpng2_x_display_row (ulg row); +static void rpng2_x_finish_display (void); +static void rpng2_x_redisplay_image (ulg startcol, ulg startrow, + ulg width, ulg height); +#ifdef FEATURE_LOOP +static void rpng2_x_reload_bg_image (void); +static int is_number (char *p); +#endif +static void rpng2_x_cleanup (void); +static int rpng2_x_msb (ulg u32val); + + +static char titlebar[1024], *window_name = titlebar; +static char *appname = LONGNAME; +static char *icon_name = PROGNAME; +static char *res_name = RESNAME; +static char *res_class = RESCLASS; +static char *filename; +static FILE *infile; + +static mainprog_info rpng2_info; + +static uch inbuf[INBUFSIZE]; +static int incount; + +static int pat = 6; /* must be less than num_bgpat */ +static int bg_image = 0; +static int bgscale, bgscale_default = 16; +static ulg bg_rowbytes; +static uch *bg_data; + +int pause_after_pass = FALSE; +int demo_timing = FALSE; +ulg usleep_duration = 0L; + +static struct rgb_color { + uch r, g, b; +} rgb[] = { + { 0, 0, 0}, /* 0: black */ + {255, 255, 255}, /* 1: white */ + {173, 132, 57}, /* 2: tan */ + { 64, 132, 0}, /* 3: medium green */ + {189, 117, 1}, /* 4: gold */ + {253, 249, 1}, /* 5: yellow */ + { 0, 0, 255}, /* 6: blue */ + { 0, 0, 120}, /* 7: medium blue */ + {255, 0, 255}, /* 8: magenta */ + { 64, 0, 64}, /* 9: dark magenta */ + {255, 0, 0}, /* 10: red */ + { 64, 0, 0}, /* 11: dark red */ + {255, 127, 0}, /* 12: orange */ + {192, 96, 0}, /* 13: darker orange */ + { 24, 60, 0}, /* 14: dark green-yellow */ + { 85, 125, 200}, /* 15: ice blue */ + {192, 192, 192} /* 16: Netscape/Mosaic gray */ +}; +/* not used for now, but should be for error-checking: +static int num_rgb = sizeof(rgb) / sizeof(struct rgb_color); + */ + +/* + This whole struct is a fairly cheesy way to keep the number of + command-line options to a minimum. The radial-waves background + type is a particularly poor fit to the integer elements of the + struct...but a few macros and a little fixed-point math will do + wonders for ya. + + type bits: + F E D C B A 9 8 7 6 5 4 3 2 1 0 + | | | | | + | | +-+-+-- 0 = sharp-edged checkerboard + | | 1 = soft diamonds + | | 2 = radial waves + | | 3-7 = undefined + | +-- gradient #2 inverted? + +-- alternating columns inverted? + */ +static struct background_pattern { + ush type; + int rgb1_max, rgb1_min; /* or bg_freq, bg_gray */ + int rgb2_max, rgb2_min; /* or bg_bsat, bg_brot (both scaled by 10)*/ +} bg[] = { + {0, 1,1, 16,16}, /* checkered: white vs. light gray (basic) */ + {0+8, 2,0, 1,15}, /* checkered: tan/black vs. white/ice blue */ + {0+24, 2,0, 1,0}, /* checkered: tan/black vs. white/black */ + {0+8, 4,5, 0,2}, /* checkered: gold/yellow vs. black/tan */ + {0+8, 4,5, 0,6}, /* checkered: gold/yellow vs. black/blue */ + {0, 7,0, 8,9}, /* checkered: deep blue/black vs. magenta */ + {0+8, 13,0, 5,14}, /* checkered: orange/black vs. yellow */ + {0+8, 12,0, 10,11}, /* checkered: orange/black vs. red */ + {1, 7,0, 8,0}, /* diamonds: deep blue/black vs. magenta */ + {1, 12,0, 11,0}, /* diamonds: orange vs. dark red */ + {1, 10,0, 7,0}, /* diamonds: red vs. medium blue */ + {1, 4,0, 5,0}, /* diamonds: gold vs. yellow */ + {1, 3,0, 0,0}, /* diamonds: medium green vs. black */ + {2, 16, 100, 20, 0}, /* radial: ~hard radial color-beams */ + {2, 18, 100, 10, 2}, /* radial: soft, curved radial color-beams */ + {2, 16, 256, 100, 250}, /* radial: very tight spiral */ + {2, 10000, 256, 11, 0} /* radial: dipole-moire' (almost fractal) */ +}; +static int num_bgpat = sizeof(bg) / sizeof(struct background_pattern); + + +/* X-specific variables */ +static char *displayname; +static XImage *ximage; +static Display *display; +static int depth; +static Visual *visual; +static XVisualInfo *visual_list; +static int RShift, GShift, BShift; +static ulg RMask, GMask, BMask; +static Window window; +static GC gc; +static Colormap colormap; + +static int have_nondefault_visual = FALSE; +static int have_colormap = FALSE; +static int have_window = FALSE; +static int have_gc = FALSE; + + + + +int main(int argc, char **argv) +{ +#ifdef sgi + char tmpline[80]; +#endif + char *p, *bgstr = NULL; + int rc, alen, flen; + int error = 0; + int timing = FALSE; + int have_bg = FALSE; +#ifdef FEATURE_LOOP + int loop = FALSE; + long loop_interval = -1; /* seconds (100,000 max) */ +#endif + double LUT_exponent; /* just the lookup table */ + double CRT_exponent = 2.2; /* just the monitor */ + double default_display_exponent; /* whole display system */ + XEvent e; + KeySym k; + + + /* First initialize a few things, just to be sure--memset takes care of + * default background color (black), booleans (FALSE), pointers (NULL), + * etc. */ + + displayname = (char *)NULL; + filename = (char *)NULL; + memset(&rpng2_info, 0, sizeof(mainprog_info)); + + + /* Set the default value for our display-system exponent, i.e., the + * product of the CRT exponent and the exponent corresponding to + * the frame-buffer's lookup table (LUT), if any. This is not an + * exhaustive list of LUT values (e.g., OpenStep has a lot of weird + * ones), but it should cover 99% of the current possibilities. */ + +#if defined(NeXT) + /* third-party utilities can modify the default LUT exponent */ + LUT_exponent = 1.0 / 2.2; + /* + if (some_next_function_that_returns_gamma(&next_gamma)) + LUT_exponent = 1.0 / next_gamma; + */ +#elif defined(sgi) + LUT_exponent = 1.0 / 1.7; + /* there doesn't seem to be any documented function to + * get the "gamma" value, so we do it the hard way */ + infile = fopen("/etc/config/system.glGammaVal", "r"); + if (infile) { + double sgi_gamma; + + fgets(tmpline, 80, infile); + fclose(infile); + sgi_gamma = atof(tmpline); + if (sgi_gamma > 0.0) + LUT_exponent = 1.0 / sgi_gamma; + } +#elif defined(Macintosh) + LUT_exponent = 1.8 / 2.61; + /* + if (some_mac_function_that_returns_gamma(&mac_gamma)) + LUT_exponent = mac_gamma / 2.61; + */ +#else + LUT_exponent = 1.0; /* assume no LUT: most PCs */ +#endif + + /* the defaults above give 1.0, 1.3, 1.5 and 2.2, respectively: */ + default_display_exponent = LUT_exponent * CRT_exponent; + + + /* If the user has set the SCREEN_GAMMA environment variable as suggested + * (somewhat imprecisely) in the libpng documentation, use that; otherwise + * use the default value we just calculated. Either way, the user may + * override this via a command-line option. */ + + if ((p = getenv("SCREEN_GAMMA")) != NULL) + rpng2_info.display_exponent = atof(p); + else + rpng2_info.display_exponent = default_display_exponent; + + + /* Now parse the command line for options and the PNG filename. */ + + while (*++argv && !error) { + if (!strncmp(*argv, "-display", 2)) { + if (!*++argv) + ++error; + else + displayname = *argv; + } else if (!strncmp(*argv, "-gamma", 2)) { + if (!*++argv) + ++error; + else { + rpng2_info.display_exponent = atof(*argv); + if (rpng2_info.display_exponent <= 0.0) + ++error; + } + } else if (!strncmp(*argv, "-bgcolor", 4)) { + if (!*++argv) + ++error; + else { + bgstr = *argv; + if (strlen(bgstr) != 7 || bgstr[0] != '#') + ++error; + else { + have_bg = TRUE; + bg_image = FALSE; + } + } + } else if (!strncmp(*argv, "-bgpat", 4)) { + if (!*++argv) + ++error; + else { + pat = atoi(*argv); + if (pat >= 0 && pat < num_bgpat) { + bg_image = TRUE; + have_bg = FALSE; + } else + ++error; + } + } else if (!strncmp(*argv, "-usleep", 2)) { + if (!*++argv) + ++error; + else { + usleep_duration = (ulg)atol(*argv); + demo_timing = TRUE; + } + } else if (!strncmp(*argv, "-pause", 2)) { + pause_after_pass = TRUE; + } else if (!strncmp(*argv, "-timing", 2)) { + timing = TRUE; +#ifdef FEATURE_LOOP + } else if (!strncmp(*argv, "-loop", 2)) { + loop = TRUE; + if (!argv[1] || !is_number(argv[1])) + loop_interval = 2; + else { + ++argv; + loop_interval = atol(*argv); + if (loop_interval < 0) + loop_interval = 2; + else if (loop_interval > 100000) /* bit more than one day */ + loop_interval = 100000; + } +#endif +#if (defined(__i386__) || defined(_M_IX86) || defined(__x86_64__)) + } else if (!strncmp(*argv, "-nommxfilters", 7)) { + rpng2_info.nommxfilters = TRUE; + } else if (!strncmp(*argv, "-nommxcombine", 7)) { + rpng2_info.nommxcombine = TRUE; + } else if (!strncmp(*argv, "-nommxinterlace", 7)) { + rpng2_info.nommxinterlace = TRUE; + } else if (!strcmp(*argv, "-nommx")) { + rpng2_info.nommxfilters = TRUE; + rpng2_info.nommxcombine = TRUE; + rpng2_info.nommxinterlace = TRUE; +#endif + } else { + if (**argv != '-') { + filename = *argv; + if (argv[1]) /* shouldn't be any more args after filename */ + ++error; + } else + ++error; /* not expecting any other options */ + } + } + + if (!filename) + ++error; + + + /* print usage screen if any errors up to this point */ + + if (error) { + fprintf(stderr, "\n%s %s: %s\n\n", PROGNAME, VERSION, appname); + readpng2_version_info(); + fprintf(stderr, "\n" + "Usage: %s [-display xdpy] [-gamma exp] [-bgcolor bg | -bgpat pat]\n" +#if (defined(__i386__) || defined(_M_IX86) || defined(__x86_64__)) + " %*s [[-nommxfilters] [-nommxcombine] [-nommxinterlace] | -nommx]\n" +#endif +#ifdef FEATURE_LOOP + " %*s [-usleep dur | -timing] [-pause] [-loop [sec]] file.png\n\n" +#else + " %*s [-usleep dur | -timing] [-pause] file.png\n\n" +#endif + " xdpy\tname of the target X display (e.g., ``hostname:0'')\n" + " exp \ttransfer-function exponent (``gamma'') of the display\n" + "\t\t system in floating-point format (e.g., ``%.1f''); equal\n" + "\t\t to the product of the lookup-table exponent (varies)\n" + "\t\t and the CRT exponent (usually 2.2); must be positive\n" + " bg \tdesired background color in 7-character hex RGB format\n" + "\t\t (e.g., ``#ff7700'' for orange: same as HTML colors);\n" + "\t\t used with transparent images; overrides -bgpat\n" + " pat \tdesired background pattern number (0-%d); used with\n" + "\t\t transparent images; overrides -bgcolor\n" +#ifdef FEATURE_LOOP + " -loop\tloops through background images after initial display\n" + "\t\t is complete (depends on -bgpat)\n" + " sec \tseconds to display each background image (default = 2)\n" +#endif +#if (defined(__i386__) || defined(_M_IX86) || defined(__x86_64__)) + " -nommx*\tdisable optimized MMX routines for decoding row filters,\n" + "\t\t combining rows, and expanding interlacing, respectively\n" +#endif + " dur \tduration in microseconds to wait after displaying each\n" + "\t\t row (for demo purposes)\n" + " -timing\tenables delay for every block read, to simulate modem\n" + "\t\t download of image (~36 Kbps)\n" + " -pause\tpauses after displaying each pass until mouse clicked\n" + "\nPress Q, Esc or mouse button 1 (within image window, after image\n" + "is displayed) to quit.\n" + "\n", PROGNAME, +#if (defined(__i386__) || defined(_M_IX86) || defined(__x86_64__)) + (int)strlen(PROGNAME), " ", +#endif + (int)strlen(PROGNAME), " ", default_display_exponent, num_bgpat-1); + exit(1); + } + + + if (!(infile = fopen(filename, "rb"))) { + fprintf(stderr, PROGNAME ": can't open PNG file [%s]\n", filename); + ++error; + } else { + incount = fread(inbuf, 1, INBUFSIZE, infile); + if (incount < 8 || !readpng2_check_sig(inbuf, 8)) { + fprintf(stderr, PROGNAME + ": [%s] is not a PNG file: incorrect signature\n", + filename); + ++error; + } else if ((rc = readpng2_init(&rpng2_info)) != 0) { + switch (rc) { + case 2: + fprintf(stderr, PROGNAME + ": [%s] has bad IHDR (libpng longjmp)\n", filename); + break; + case 4: + fprintf(stderr, PROGNAME ": insufficient memory\n"); + break; + default: + fprintf(stderr, PROGNAME + ": unknown readpng2_init() error\n"); + break; + } + ++error; + } else { + Trace((stderr, "about to call XOpenDisplay()\n")) + display = XOpenDisplay(displayname); + if (!display) { + readpng2_cleanup(&rpng2_info); + fprintf(stderr, PROGNAME ": can't open X display [%s]\n", + displayname? displayname : "default"); + ++error; + } + } + if (error) + fclose(infile); + } + + + if (error) { + fprintf(stderr, PROGNAME ": aborting.\n"); + exit(2); + } + + + /* set the title-bar string, but make sure buffer doesn't overflow */ + + alen = strlen(appname); + flen = strlen(filename); + if (alen + flen + 3 > 1023) + sprintf(titlebar, "%s: ...%s", appname, filename+(alen+flen+6-1023)); + else + sprintf(titlebar, "%s: %s", appname, filename); + + + /* set some final rpng2_info variables before entering main data loop */ + + if (have_bg) { + unsigned r, g, b; /* this approach quiets compiler warnings */ + + sscanf(bgstr+1, "%2x%2x%2x", &r, &g, &b); + rpng2_info.bg_red = (uch)r; + rpng2_info.bg_green = (uch)g; + rpng2_info.bg_blue = (uch)b; + } else + rpng2_info.need_bgcolor = TRUE; + + rpng2_info.state = kPreInit; + rpng2_info.mainprog_init = rpng2_x_init; + rpng2_info.mainprog_display_row = rpng2_x_display_row; + rpng2_info.mainprog_finish_display = rpng2_x_finish_display; + + + /* OK, this is the fun part: call readpng2_decode_data() at the start of + * the loop to deal with our first buffer of data (read in above to verify + * that the file is a PNG image), then loop through the file and continue + * calling the same routine to handle each chunk of data. It in turn + * passes the data to libpng, which will invoke one or more of our call- + * backs as decoded data become available. We optionally call sleep() for + * one second per iteration to simulate downloading the image via an analog + * modem. */ + + for (;;) { + Trace((stderr, "about to call readpng2_decode_data()\n")) + if (readpng2_decode_data(&rpng2_info, inbuf, incount)) + ++error; + Trace((stderr, "done with readpng2_decode_data()\n")) + + if (error || incount != INBUFSIZE || rpng2_info.state == kDone) { + if (rpng2_info.state == kDone) { + Trace((stderr, "done decoding PNG image\n")) + } else if (ferror(infile)) { + fprintf(stderr, PROGNAME + ": error while reading PNG image file\n"); + exit(3); + } else if (feof(infile)) { + fprintf(stderr, PROGNAME ": end of file reached " + "(unexpectedly) while reading PNG image file\n"); + exit(3); + } else /* if (error) */ { + // will print error message below + } + break; + } + + if (timing) + sleep(1); + + incount = fread(inbuf, 1, INBUFSIZE, infile); + } + + + /* clean up PNG stuff and report any decoding errors */ + + fclose(infile); + Trace((stderr, "about to call readpng2_cleanup()\n")) + readpng2_cleanup(&rpng2_info); + + if (error) { + fprintf(stderr, PROGNAME ": libpng error while decoding PNG image\n"); + exit(3); + } + + +#ifdef FEATURE_LOOP + + if (loop && bg_image) { + Trace((stderr, "entering -loop loop (FEATURE_LOOP)\n")) + for (;;) { + int i, use_sleep; + struct timeval now, then; + + /* get current time and add loop_interval to get target time */ + if (gettimeofday(&then, NULL) == 0) { + then.tv_sec += loop_interval; + use_sleep = FALSE; + } else + use_sleep = TRUE; + + /* do quick check for a quit event but don't wait for it */ + /* GRR BUG: should also check for Expose events and redraw... */ + if (XCheckMaskEvent(display, KeyPressMask | ButtonPressMask, &e)) + if (QUIT(e,k)) + break; + + /* generate next background image */ + if (++pat >= num_bgpat) + pat = 0; + rpng2_x_reload_bg_image(); + + /* wait for timeout, using whatever means are available */ + if (use_sleep || gettimeofday(&now, NULL) != 0) { + for (i = loop_interval; i > 0; --i) { + sleep(1); + /* GRR BUG: also need to check for Expose (and redraw!) */ + if (XCheckMaskEvent(display, KeyPressMask | ButtonPressMask, + &e) && QUIT(e,k)) + break; + } + } else { + /* Y2038 BUG! */ + if (now.tv_sec < then.tv_sec || + (now.tv_sec == then.tv_sec && now.tv_usec < then.tv_usec)) + { + int quit = FALSE; + long seconds_to_go = then.tv_sec - now.tv_sec; + long usleep_usec; + + /* basically chew up most of remaining loop-interval with + * calls to sleep(1) interleaved with checks for quit + * events, but also recalc time-to-go periodically; when + * done, clean up any remaining time with usleep() call + * (could also use SIGALRM, but signals are a pain...) */ + while (seconds_to_go-- > 1) { + int seconds_done = 0; + + for (i = seconds_to_go; i > 0 && !quit; --i) { + sleep(1); + /* GRR BUG: need to check for Expose and redraw */ + if (XCheckMaskEvent(display, KeyPressMask | + ButtonPressMask, &e) && QUIT(e,k)) + quit = TRUE; + if (++seconds_done > 1000) + break; /* time to redo seconds_to_go meas. */ + } + if (quit) + break; + + /* OK, more than 1000 seconds since last check: + * correct the time-to-go measurement for drift */ + if (gettimeofday(&now, NULL) == 0) { + if (now.tv_sec >= then.tv_sec) + break; + seconds_to_go = then.tv_sec - now.tv_sec; + } else + ++seconds_to_go; /* restore what we subtracted */ + } + if (quit) + break; /* breaks outer do-loop, skips redisplay */ + + /* since difference between "now" and "then" is already + * eaten up to within a couple of seconds, don't need to + * worry about overflow--but might have overshot (neg.) */ + if (gettimeofday(&now, NULL) == 0) { + usleep_usec = 1000000L*(then.tv_sec - now.tv_sec) + + then.tv_usec - now.tv_usec; + if (usleep_usec > 0) + usleep((ulg)usleep_usec); + } + } + } + + /* composite image against new background and display (note that + * we do not take into account the time spent doing this...) */ + rpng2_x_redisplay_image (0, 0, rpng2_info.width, rpng2_info.height); + } + + } else /* FALL THROUGH and do the normal thing */ + +#endif /* FEATURE_LOOP */ + + /* wait for the user to tell us when to quit */ + + if (rpng2_info.state >= kWindowInit) { + Trace((stderr, "entering final wait-for-quit-event loop\n")) + do { + XNextEvent(display, &e); + if (e.type == Expose) { + XExposeEvent *ex = (XExposeEvent *)&e; + rpng2_x_redisplay_image (ex->x, ex->y, ex->width, ex->height); + } + } while (!QUIT(e,k)); + } else { + fprintf(stderr, PROGNAME ": init callback never called: probable " + "libpng error while decoding PNG metadata\n"); + exit(4); + } + + + /* we're done: clean up all image and X resources and go away */ + + Trace((stderr, "about to call rpng2_x_cleanup()\n")) + rpng2_x_cleanup(); + + return 0; +} + + + + + +/* this function is called by readpng2_info_callback() in readpng2.c, which + * in turn is called by libpng after all of the pre-IDAT chunks have been + * read and processed--i.e., we now have enough info to finish initializing */ + +static void rpng2_x_init(void) +{ + ulg i; + ulg rowbytes = rpng2_info.rowbytes; + + Trace((stderr, "beginning rpng2_x_init()\n")) + Trace((stderr, " rowbytes = %d\n", rpng2_info.rowbytes)) + Trace((stderr, " width = %ld\n", rpng2_info.width)) + Trace((stderr, " height = %ld\n", rpng2_info.height)) + + rpng2_info.image_data = (uch *)malloc(rowbytes * rpng2_info.height); + if (!rpng2_info.image_data) { + readpng2_cleanup(&rpng2_info); + return; + } + + rpng2_info.row_pointers = (uch **)malloc(rpng2_info.height * sizeof(uch *)); + if (!rpng2_info.row_pointers) { + free(rpng2_info.image_data); + rpng2_info.image_data = NULL; + readpng2_cleanup(&rpng2_info); + return; + } + + for (i = 0; i < rpng2_info.height; ++i) + rpng2_info.row_pointers[i] = rpng2_info.image_data + i*rowbytes; + + + /* do the basic X initialization stuff, make the window, and fill it with + * the user-specified, file-specified or default background color or + * pattern */ + + if (rpng2_x_create_window()) { + + /* GRR TEMPORARY HACK: this is fundamentally no different from cases + * above; libpng should longjmp() back to us when png_ptr goes away. + * If we/it segfault instead, seems like a libpng bug... */ + + /* we're here via libpng callback, so if window fails, clean and bail */ + readpng2_cleanup(&rpng2_info); + rpng2_x_cleanup(); + exit(2); + } + + rpng2_info.state = kWindowInit; +} + + + + + +static int rpng2_x_create_window(void) +{ + ulg bg_red = rpng2_info.bg_red; + ulg bg_green = rpng2_info.bg_green; + ulg bg_blue = rpng2_info.bg_blue; + ulg bg_pixel = 0L; + ulg attrmask; + int need_colormap = FALSE; + int screen, pad; + uch *xdata; + Window root; + XEvent e; + XGCValues gcvalues; + XSetWindowAttributes attr; + XTextProperty windowName, *pWindowName = &windowName; + XTextProperty iconName, *pIconName = &iconName; + XVisualInfo visual_info; + XSizeHints *size_hints; + XWMHints *wm_hints; + XClassHint *class_hints; + + + Trace((stderr, "beginning rpng2_x_create_window()\n")) + + screen = DefaultScreen(display); + depth = DisplayPlanes(display, screen); + root = RootWindow(display, screen); + +#ifdef DEBUG + XSynchronize(display, True); +#endif + + if (depth != 16 && depth != 24 && depth != 32) { + int visuals_matched = 0; + + Trace((stderr, "default depth is %d: checking other visuals\n", + depth)) + + /* 24-bit first */ + visual_info.screen = screen; + visual_info.depth = 24; + visual_list = XGetVisualInfo(display, + VisualScreenMask | VisualDepthMask, &visual_info, &visuals_matched); + if (visuals_matched == 0) { +/* GRR: add 15-, 16- and 32-bit TrueColor visuals (also DirectColor?) */ + fprintf(stderr, "default screen depth %d not supported, and no" + " 24-bit visuals found\n", depth); + return 2; + } + Trace((stderr, "XGetVisualInfo() returned %d 24-bit visuals\n", + visuals_matched)) + visual = visual_list[0].visual; + depth = visual_list[0].depth; +/* + colormap_size = visual_list[0].colormap_size; + visual_class = visual->class; + visualID = XVisualIDFromVisual(visual); + */ + have_nondefault_visual = TRUE; + need_colormap = TRUE; + } else { + XMatchVisualInfo(display, screen, depth, TrueColor, &visual_info); + visual = visual_info.visual; + } + + RMask = visual->red_mask; + GMask = visual->green_mask; + BMask = visual->blue_mask; + +/* GRR: add/check 8-bit support */ + if (depth == 8 || need_colormap) { + colormap = XCreateColormap(display, root, visual, AllocNone); + if (!colormap) { + fprintf(stderr, "XCreateColormap() failed\n"); + return 2; + } + have_colormap = TRUE; + if (depth == 8) + bg_image = FALSE; /* gradient just wastes palette entries */ + } + if (depth == 15 || depth == 16) { + RShift = 15 - rpng2_x_msb(RMask); /* these are right-shifts */ + GShift = 15 - rpng2_x_msb(GMask); + BShift = 15 - rpng2_x_msb(BMask); + } else if (depth > 16) { + RShift = rpng2_x_msb(RMask) - 7; /* these are left-shifts */ + GShift = rpng2_x_msb(GMask) - 7; + BShift = rpng2_x_msb(BMask) - 7; + } + if (depth >= 15 && (RShift < 0 || GShift < 0 || BShift < 0)) { + fprintf(stderr, "rpng2 internal logic error: negative X shift(s)!\n"); + return 2; + } + +/*--------------------------------------------------------------------------- + Finally, create the window. + ---------------------------------------------------------------------------*/ + + attr.backing_store = Always; + attr.event_mask = ExposureMask | KeyPressMask | ButtonPressMask; + attrmask = CWBackingStore | CWEventMask; + if (have_nondefault_visual) { + attr.colormap = colormap; + attr.background_pixel = 0; + attr.border_pixel = 1; + attrmask |= CWColormap | CWBackPixel | CWBorderPixel; + } + + window = XCreateWindow(display, root, 0, 0, rpng2_info.width, + rpng2_info.height, 0, depth, InputOutput, visual, attrmask, &attr); + + if (window == None) { + fprintf(stderr, "XCreateWindow() failed\n"); + return 2; + } else + have_window = TRUE; + + if (depth == 8) + XSetWindowColormap(display, window, colormap); + + if (!XStringListToTextProperty(&window_name, 1, pWindowName)) + pWindowName = NULL; + if (!XStringListToTextProperty(&icon_name, 1, pIconName)) + pIconName = NULL; + + /* OK if either hints allocation fails; XSetWMProperties() allows NULLs */ + + if ((size_hints = XAllocSizeHints()) != NULL) { + /* window will not be resizable */ + size_hints->flags = PMinSize | PMaxSize; + size_hints->min_width = size_hints->max_width = (int)rpng2_info.width; + size_hints->min_height = size_hints->max_height = + (int)rpng2_info.height; + } + + if ((wm_hints = XAllocWMHints()) != NULL) { + wm_hints->initial_state = NormalState; + wm_hints->input = True; + /* wm_hints->icon_pixmap = icon_pixmap; */ + wm_hints->flags = StateHint | InputHint /* | IconPixmapHint */ ; + } + + if ((class_hints = XAllocClassHint()) != NULL) { + class_hints->res_name = res_name; + class_hints->res_class = res_class; + } + + XSetWMProperties(display, window, pWindowName, pIconName, NULL, 0, + size_hints, wm_hints, class_hints); + + /* various properties and hints no longer needed; free memory */ + if (pWindowName) + XFree(pWindowName->value); + if (pIconName) + XFree(pIconName->value); + if (size_hints) + XFree(size_hints); + if (wm_hints) + XFree(wm_hints); + if (class_hints) + XFree(class_hints); + + XMapWindow(display, window); + + gc = XCreateGC(display, window, 0, &gcvalues); + have_gc = TRUE; + +/*--------------------------------------------------------------------------- + Allocate memory for the X- and display-specific version of the image. + ---------------------------------------------------------------------------*/ + + if (depth == 24 || depth == 32) { + xdata = (uch *)malloc(4*rpng2_info.width*rpng2_info.height); + pad = 32; + } else if (depth == 16) { + xdata = (uch *)malloc(2*rpng2_info.width*rpng2_info.height); + pad = 16; + } else /* depth == 8 */ { + xdata = (uch *)malloc(rpng2_info.width*rpng2_info.height); + pad = 8; + } + + if (!xdata) { + fprintf(stderr, PROGNAME ": unable to allocate image memory\n"); + return 4; + } + + ximage = XCreateImage(display, visual, depth, ZPixmap, 0, + (char *)xdata, rpng2_info.width, rpng2_info.height, pad, 0); + + if (!ximage) { + fprintf(stderr, PROGNAME ": XCreateImage() failed\n"); + free(xdata); + return 3; + } + + /* to avoid testing the byte order every pixel (or doubling the size of + * the drawing routine with a giant if-test), we arbitrarily set the byte + * order to MSBFirst and let Xlib worry about inverting things on little- + * endian machines (e.g., Linux/x86, old VAXen, etc.)--this is not the + * most efficient approach (the giant if-test would be better), but in + * the interest of clarity, we'll take the easy way out... */ + + ximage->byte_order = MSBFirst; + +/*--------------------------------------------------------------------------- + Fill window with the specified background color (default is black) or + faked "background image" (but latter is disabled if 8-bit; gradients + just waste palette entries). + ---------------------------------------------------------------------------*/ + + if (bg_image) + rpng2_x_load_bg_image(); /* resets bg_image if fails */ + + if (!bg_image) { + if (depth == 24 || depth == 32) { + bg_pixel = (bg_red << RShift) | + (bg_green << GShift) | + (bg_blue << BShift); + } else if (depth == 16) { + bg_pixel = (((bg_red << 8) >> RShift) & RMask) | + (((bg_green << 8) >> GShift) & GMask) | + (((bg_blue << 8) >> BShift) & BMask); + } else /* depth == 8 */ { + + /* GRR: add 8-bit support */ + + } + XSetForeground(display, gc, bg_pixel); + XFillRectangle(display, window, gc, 0, 0, rpng2_info.width, + rpng2_info.height); + } + +/*--------------------------------------------------------------------------- + Wait for first Expose event to do any drawing, then flush and return. + ---------------------------------------------------------------------------*/ + + do + XNextEvent(display, &e); + while (e.type != Expose || e.xexpose.count); + + XFlush(display); + + return 0; + +} /* end function rpng2_x_create_window() */ + + + + + +static int rpng2_x_load_bg_image(void) +{ + uch *src; + char *dest; + uch r1, r2, g1, g2, b1, b2; + uch r1_inv, r2_inv, g1_inv, g2_inv, b1_inv, b2_inv; + int k, hmax, max; + int xidx, yidx, yidx_max; + int even_odd_vert, even_odd_horiz, even_odd; + int invert_gradient2 = (bg[pat].type & 0x08); + int invert_column; + int ximage_rowbytes = ximage->bytes_per_line; + ulg i, row; + ulg pixel; + +/*--------------------------------------------------------------------------- + Allocate buffer for fake background image to be used with transparent + images; if this fails, revert to plain background color. + ---------------------------------------------------------------------------*/ + + bg_rowbytes = 3 * rpng2_info.width; + bg_data = (uch *)malloc(bg_rowbytes * rpng2_info.height); + if (!bg_data) { + fprintf(stderr, PROGNAME + ": unable to allocate memory for background image\n"); + bg_image = 0; + return 1; + } + + bgscale = (pat == 0)? 8 : bgscale_default; + yidx_max = bgscale - 1; + +/*--------------------------------------------------------------------------- + Vertical gradients (ramps) in NxN squares, alternating direction and + colors (N == bgscale). + ---------------------------------------------------------------------------*/ + + if ((bg[pat].type & 0x07) == 0) { + uch r1_min = rgb[bg[pat].rgb1_min].r; + uch g1_min = rgb[bg[pat].rgb1_min].g; + uch b1_min = rgb[bg[pat].rgb1_min].b; + uch r2_min = rgb[bg[pat].rgb2_min].r; + uch g2_min = rgb[bg[pat].rgb2_min].g; + uch b2_min = rgb[bg[pat].rgb2_min].b; + int r1_diff = rgb[bg[pat].rgb1_max].r - r1_min; + int g1_diff = rgb[bg[pat].rgb1_max].g - g1_min; + int b1_diff = rgb[bg[pat].rgb1_max].b - b1_min; + int r2_diff = rgb[bg[pat].rgb2_max].r - r2_min; + int g2_diff = rgb[bg[pat].rgb2_max].g - g2_min; + int b2_diff = rgb[bg[pat].rgb2_max].b - b2_min; + + for (row = 0; row < rpng2_info.height; ++row) { + yidx = (int)(row % bgscale); + even_odd_vert = (int)((row / bgscale) & 1); + + r1 = r1_min + (r1_diff * yidx) / yidx_max; + g1 = g1_min + (g1_diff * yidx) / yidx_max; + b1 = b1_min + (b1_diff * yidx) / yidx_max; + r1_inv = r1_min + (r1_diff * (yidx_max-yidx)) / yidx_max; + g1_inv = g1_min + (g1_diff * (yidx_max-yidx)) / yidx_max; + b1_inv = b1_min + (b1_diff * (yidx_max-yidx)) / yidx_max; + + r2 = r2_min + (r2_diff * yidx) / yidx_max; + g2 = g2_min + (g2_diff * yidx) / yidx_max; + b2 = b2_min + (b2_diff * yidx) / yidx_max; + r2_inv = r2_min + (r2_diff * (yidx_max-yidx)) / yidx_max; + g2_inv = g2_min + (g2_diff * (yidx_max-yidx)) / yidx_max; + b2_inv = b2_min + (b2_diff * (yidx_max-yidx)) / yidx_max; + + dest = (char *)bg_data + row*bg_rowbytes; + for (i = 0; i < rpng2_info.width; ++i) { + even_odd_horiz = (int)((i / bgscale) & 1); + even_odd = even_odd_vert ^ even_odd_horiz; + invert_column = + (even_odd_horiz && (bg[pat].type & 0x10)); + if (even_odd == 0) { /* gradient #1 */ + if (invert_column) { + *dest++ = r1_inv; + *dest++ = g1_inv; + *dest++ = b1_inv; + } else { + *dest++ = r1; + *dest++ = g1; + *dest++ = b1; + } + } else { /* gradient #2 */ + if ((invert_column && invert_gradient2) || + (!invert_column && !invert_gradient2)) + { + *dest++ = r2; /* not inverted or */ + *dest++ = g2; /* doubly inverted */ + *dest++ = b2; + } else { + *dest++ = r2_inv; + *dest++ = g2_inv; /* singly inverted */ + *dest++ = b2_inv; + } + } + } + } + +/*--------------------------------------------------------------------------- + Soft gradient-diamonds with scale = bgscale. Code contributed by Adam + M. Costello. + ---------------------------------------------------------------------------*/ + + } else if ((bg[pat].type & 0x07) == 1) { + + hmax = (bgscale-1)/2; /* half the max weight of a color */ + max = 2*hmax; /* the max weight of a color */ + + r1 = rgb[bg[pat].rgb1_max].r; + g1 = rgb[bg[pat].rgb1_max].g; + b1 = rgb[bg[pat].rgb1_max].b; + r2 = rgb[bg[pat].rgb2_max].r; + g2 = rgb[bg[pat].rgb2_max].g; + b2 = rgb[bg[pat].rgb2_max].b; + + for (row = 0; row < rpng2_info.height; ++row) { + yidx = (int)(row % bgscale); + if (yidx > hmax) + yidx = bgscale-1 - yidx; + dest = (char *)bg_data + row*bg_rowbytes; + for (i = 0; i < rpng2_info.width; ++i) { + xidx = (int)(i % bgscale); + if (xidx > hmax) + xidx = bgscale-1 - xidx; + k = xidx + yidx; + *dest++ = (k*r1 + (max-k)*r2) / max; + *dest++ = (k*g1 + (max-k)*g2) / max; + *dest++ = (k*b1 + (max-k)*b2) / max; + } + } + +/*--------------------------------------------------------------------------- + Radial "starburst" with azimuthal sinusoids; [eventually number of sinu- + soids will equal bgscale?]. This one is slow but very cool. Code con- + tributed by Pieter S. van der Meulen (originally in Smalltalk). + ---------------------------------------------------------------------------*/ + + } else if ((bg[pat].type & 0x07) == 2) { + uch ch; + int ii, x, y, hw, hh, grayspot; + double freq, rotate, saturate, gray, intensity; + double angle=0.0, aoffset=0.0, maxDist, dist; + double red=0.0, green=0.0, blue=0.0, hue, s, v, f, p, q, t; + + fprintf(stderr, "%s: computing radial background...", + PROGNAME); + fflush(stderr); + + hh = (int)(rpng2_info.height / 2); + hw = (int)(rpng2_info.width / 2); + + /* variables for radial waves: + * aoffset: number of degrees to rotate hue [CURRENTLY NOT USED] + * freq: number of color beams originating from the center + * grayspot: size of the graying center area (anti-alias) + * rotate: rotation of the beams as a function of radius + * saturate: saturation of beams' shape azimuthally + */ + angle = CLIP(angle, 0.0, 360.0); + grayspot = CLIP(bg[pat].bg_gray, 1, (hh + hw)); + freq = MAX((double)bg[pat].bg_freq, 0.0); + saturate = (double)bg[pat].bg_bsat * 0.1; + rotate = (double)bg[pat].bg_brot * 0.1; + gray = 0.0; + intensity = 0.0; + maxDist = (double)((hw*hw) + (hh*hh)); + + for (row = 0; row < rpng2_info.height; ++row) { + y = (int)(row - hh); + dest = (char *)bg_data + row*bg_rowbytes; + for (i = 0; i < rpng2_info.width; ++i) { + x = (int)(i - hw); + angle = (x == 0)? PI_2 : atan((double)y / (double)x); + gray = (double)MAX(ABS(y), ABS(x)) / grayspot; + gray = MIN(1.0, gray); + dist = (double)((x*x) + (y*y)) / maxDist; + intensity = cos((angle+(rotate*dist*PI)) * freq) * + gray * saturate; + intensity = (MAX(MIN(intensity,1.0),-1.0) + 1.0) * 0.5; + hue = (angle + PI) * INV_PI_360 + aoffset; + s = gray * ((double)(ABS(x)+ABS(y)) / (double)(hw + hh)); + s = MIN(MAX(s,0.0), 1.0); + v = MIN(MAX(intensity,0.0), 1.0); + + if (s == 0.0) { + ch = (uch)(v * 255.0); + *dest++ = ch; + *dest++ = ch; + *dest++ = ch; + } else { + if ((hue < 0.0) || (hue >= 360.0)) + hue -= (((int)(hue / 360.0)) * 360.0); + hue /= 60.0; + ii = (int)hue; + f = hue - (double)ii; + p = (1.0 - s) * v; + q = (1.0 - (s * f)) * v; + t = (1.0 - (s * (1.0 - f))) * v; + if (ii == 0) { red = v; green = t; blue = p; } + else if (ii == 1) { red = q; green = v; blue = p; } + else if (ii == 2) { red = p; green = v; blue = t; } + else if (ii == 3) { red = p; green = q; blue = v; } + else if (ii == 4) { red = t; green = p; blue = v; } + else if (ii == 5) { red = v; green = p; blue = q; } + *dest++ = (uch)(red * 255.0); + *dest++ = (uch)(green * 255.0); + *dest++ = (uch)(blue * 255.0); + } + } + } + fprintf(stderr, "done.\n"); + fflush(stderr); + } + +/*--------------------------------------------------------------------------- + Blast background image to display buffer before beginning PNG decode. + ---------------------------------------------------------------------------*/ + + if (depth == 24 || depth == 32) { + ulg red, green, blue; + int bpp = ximage->bits_per_pixel; + + for (row = 0; row < rpng2_info.height; ++row) { + src = bg_data + row*bg_rowbytes; + dest = ximage->data + row*ximage_rowbytes; + if (bpp == 32) { /* slightly optimized version */ + for (i = rpng2_info.width; i > 0; --i) { + red = *src++; + green = *src++; + blue = *src++; + pixel = (red << RShift) | + (green << GShift) | + (blue << BShift); + /* recall that we set ximage->byte_order = MSBFirst above */ + *dest++ = (char)((pixel >> 24) & 0xff); + *dest++ = (char)((pixel >> 16) & 0xff); + *dest++ = (char)((pixel >> 8) & 0xff); + *dest++ = (char)( pixel & 0xff); + } + } else { + for (i = rpng2_info.width; i > 0; --i) { + red = *src++; + green = *src++; + blue = *src++; + pixel = (red << RShift) | + (green << GShift) | + (blue << BShift); + /* recall that we set ximage->byte_order = MSBFirst above */ + /* GRR BUG? this assumes bpp == 24 & bits are packed low */ + /* (probably need to use RShift, RMask, etc.) */ + *dest++ = (char)((pixel >> 16) & 0xff); + *dest++ = (char)((pixel >> 8) & 0xff); + *dest++ = (char)( pixel & 0xff); + } + } + } + + } else if (depth == 16) { + ush red, green, blue; + + for (row = 0; row < rpng2_info.height; ++row) { + src = bg_data + row*bg_rowbytes; + dest = ximage->data + row*ximage_rowbytes; + for (i = rpng2_info.width; i > 0; --i) { + red = ((ush)(*src) << 8); ++src; + green = ((ush)(*src) << 8); ++src; + blue = ((ush)(*src) << 8); ++src; + pixel = ((red >> RShift) & RMask) | + ((green >> GShift) & GMask) | + ((blue >> BShift) & BMask); + /* recall that we set ximage->byte_order = MSBFirst above */ + *dest++ = (char)((pixel >> 8) & 0xff); + *dest++ = (char)( pixel & 0xff); + } + } + + } else /* depth == 8 */ { + + /* GRR: add 8-bit support */ + + } + + XPutImage(display, window, gc, ximage, 0, 0, 0, 0, rpng2_info.width, + rpng2_info.height); + + return 0; + +} /* end function rpng2_x_load_bg_image() */ + + + + + +static void rpng2_x_display_row(ulg row) +{ + uch bg_red = rpng2_info.bg_red; + uch bg_green = rpng2_info.bg_green; + uch bg_blue = rpng2_info.bg_blue; + uch *src, *src2=NULL; + char *dest; + uch r, g, b, a; + int ximage_rowbytes = ximage->bytes_per_line; + ulg i, pixel; + static int rows=0, prevpass=(-1); + static ulg firstrow; + +/*--------------------------------------------------------------------------- + rows and firstrow simply track how many rows (and which ones) have not + yet been displayed; alternatively, we could call XPutImage() for every + row and not bother with the records-keeping. + ---------------------------------------------------------------------------*/ + + Trace((stderr, "beginning rpng2_x_display_row()\n")) + + if (rpng2_info.pass != prevpass) { + if (pause_after_pass && rpng2_info.pass > 0) { + XEvent e; + KeySym k; + + fprintf(stderr, + "%s: end of pass %d of 7; click in image window to continue\n", + PROGNAME, prevpass + 1); + do + XNextEvent(display, &e); + while (!QUIT(e,k)); + } + fprintf(stderr, "%s: pass %d of 7\r", PROGNAME, rpng2_info.pass + 1); + fflush(stderr); + prevpass = rpng2_info.pass; + } + + if (rows == 0) + firstrow = row; /* first row that is not yet displayed */ + + ++rows; /* count of rows received but not yet displayed */ + +/*--------------------------------------------------------------------------- + Aside from the use of the rpng2_info struct, the lack of an outer loop + (over rows) and moving the XPutImage() call outside the "if (depth)" + tests, this routine is identical to rpng_x_display_image() in the non- + progressive version of the program. + ---------------------------------------------------------------------------*/ + + if (depth == 24 || depth == 32) { + ulg red, green, blue; + int bpp = ximage->bits_per_pixel; + + src = rpng2_info.image_data + row*rpng2_info.rowbytes; + if (bg_image) + src2 = bg_data + row*bg_rowbytes; + dest = ximage->data + row*ximage_rowbytes; + if (rpng2_info.channels == 3) { + for (i = rpng2_info.width; i > 0; --i) { + red = *src++; + green = *src++; + blue = *src++; + pixel = (red << RShift) | + (green << GShift) | + (blue << BShift); + /* recall that we set ximage->byte_order = MSBFirst above */ + if (bpp == 32) { + *dest++ = (char)((pixel >> 24) & 0xff); + *dest++ = (char)((pixel >> 16) & 0xff); + *dest++ = (char)((pixel >> 8) & 0xff); + *dest++ = (char)( pixel & 0xff); + } else { + /* GRR BUG? this assumes bpp == 24 & bits are packed low */ + /* (probably need to use RShift, RMask, etc.) */ + *dest++ = (char)((pixel >> 16) & 0xff); + *dest++ = (char)((pixel >> 8) & 0xff); + *dest++ = (char)( pixel & 0xff); + } + } + } else /* if (rpng2_info.channels == 4) */ { + for (i = rpng2_info.width; i > 0; --i) { + r = *src++; + g = *src++; + b = *src++; + a = *src++; + if (bg_image) { + bg_red = *src2++; + bg_green = *src2++; + bg_blue = *src2++; + } + if (a == 255) { + red = r; + green = g; + blue = b; + } else if (a == 0) { + red = bg_red; + green = bg_green; + blue = bg_blue; + } else { + /* this macro (from png.h) composites the foreground + * and background values and puts the result into the + * first argument */ + alpha_composite(red, r, a, bg_red); + alpha_composite(green, g, a, bg_green); + alpha_composite(blue, b, a, bg_blue); + } + pixel = (red << RShift) | + (green << GShift) | + (blue << BShift); + /* recall that we set ximage->byte_order = MSBFirst above */ + if (bpp == 32) { + *dest++ = (char)((pixel >> 24) & 0xff); + *dest++ = (char)((pixel >> 16) & 0xff); + *dest++ = (char)((pixel >> 8) & 0xff); + *dest++ = (char)( pixel & 0xff); + } else { + /* GRR BUG? this assumes bpp == 24 & bits are packed low */ + /* (probably need to use RShift, RMask, etc.) */ + *dest++ = (char)((pixel >> 16) & 0xff); + *dest++ = (char)((pixel >> 8) & 0xff); + *dest++ = (char)( pixel & 0xff); + } + } + } + + } else if (depth == 16) { + ush red, green, blue; + + src = rpng2_info.row_pointers[row]; + if (bg_image) + src2 = bg_data + row*bg_rowbytes; + dest = ximage->data + row*ximage_rowbytes; + if (rpng2_info.channels == 3) { + for (i = rpng2_info.width; i > 0; --i) { + red = ((ush)(*src) << 8); + ++src; + green = ((ush)(*src) << 8); + ++src; + blue = ((ush)(*src) << 8); + ++src; + pixel = ((red >> RShift) & RMask) | + ((green >> GShift) & GMask) | + ((blue >> BShift) & BMask); + /* recall that we set ximage->byte_order = MSBFirst above */ + *dest++ = (char)((pixel >> 8) & 0xff); + *dest++ = (char)( pixel & 0xff); + } + } else /* if (rpng2_info.channels == 4) */ { + for (i = rpng2_info.width; i > 0; --i) { + r = *src++; + g = *src++; + b = *src++; + a = *src++; + if (bg_image) { + bg_red = *src2++; + bg_green = *src2++; + bg_blue = *src2++; + } + if (a == 255) { + red = ((ush)r << 8); + green = ((ush)g << 8); + blue = ((ush)b << 8); + } else if (a == 0) { + red = ((ush)bg_red << 8); + green = ((ush)bg_green << 8); + blue = ((ush)bg_blue << 8); + } else { + /* this macro (from png.h) composites the foreground + * and background values and puts the result back into + * the first argument (== fg byte here: safe) */ + alpha_composite(r, r, a, bg_red); + alpha_composite(g, g, a, bg_green); + alpha_composite(b, b, a, bg_blue); + red = ((ush)r << 8); + green = ((ush)g << 8); + blue = ((ush)b << 8); + } + pixel = ((red >> RShift) & RMask) | + ((green >> GShift) & GMask) | + ((blue >> BShift) & BMask); + /* recall that we set ximage->byte_order = MSBFirst above */ + *dest++ = (char)((pixel >> 8) & 0xff); + *dest++ = (char)( pixel & 0xff); + } + } + + } else /* depth == 8 */ { + + /* GRR: add 8-bit support */ + + } + + +/*--------------------------------------------------------------------------- + Display after every 16 rows or when on one of last two rows. (Region + may include previously displayed lines due to interlacing--i.e., not + contiguous. Also, second-to-last row is final one in interlaced images + with odd number of rows.) For demos, flush (and delay) after every 16th + row so "sparse" passes don't go twice as fast. + ---------------------------------------------------------------------------*/ + + if (demo_timing && (row - firstrow >= 16 || row >= rpng2_info.height-2)) { + XPutImage(display, window, gc, ximage, 0, (int)firstrow, 0, + (int)firstrow, rpng2_info.width, row - firstrow + 1); + XFlush(display); + rows = 0; + usleep(usleep_duration); + } else + if (!demo_timing && ((rows & 0xf) == 0 || row >= rpng2_info.height-2)) { + XPutImage(display, window, gc, ximage, 0, (int)firstrow, 0, + (int)firstrow, rpng2_info.width, row - firstrow + 1); + XFlush(display); + rows = 0; + } + +} + + + + + +static void rpng2_x_finish_display(void) +{ + Trace((stderr, "beginning rpng2_x_finish_display()\n")) + + /* last row has already been displayed by rpng2_x_display_row(), so we + * have nothing to do here except set a flag and let the user know that + * the image is done */ + + rpng2_info.state = kDone; + printf( + "Done. Press Q, Esc or mouse button 1 (within image window) to quit.\n"); + fflush(stdout); +} + + + + + +static void rpng2_x_redisplay_image(ulg startcol, ulg startrow, + ulg width, ulg height) +{ + uch bg_red = rpng2_info.bg_red; + uch bg_green = rpng2_info.bg_green; + uch bg_blue = rpng2_info.bg_blue; + uch *src, *src2=NULL; + char *dest; + uch r, g, b, a; + ulg i, row, lastrow = 0; + ulg pixel; + int ximage_rowbytes = ximage->bytes_per_line; + + + Trace((stderr, "beginning display loop (image_channels == %d)\n", + rpng2_info.channels)) + Trace((stderr, " (width = %ld, rowbytes = %d, ximage_rowbytes = %d)\n", + rpng2_info.width, rpng2_info.rowbytes, ximage_rowbytes)) + Trace((stderr, " (bpp = %d)\n", ximage->bits_per_pixel)) + Trace((stderr, " (byte_order = %s)\n", ximage->byte_order == MSBFirst? + "MSBFirst" : (ximage->byte_order == LSBFirst? "LSBFirst" : "unknown"))) + +/*--------------------------------------------------------------------------- + Aside from the use of the rpng2_info struct and of src2 (for background + image), this routine is identical to rpng_x_display_image() in the non- + progressive version of the program--for the simple reason that redisplay + of the image against a new background happens after the image is fully + decoded and therefore is, by definition, non-progressive. + ---------------------------------------------------------------------------*/ + + if (depth == 24 || depth == 32) { + ulg red, green, blue; + int bpp = ximage->bits_per_pixel; + + for (lastrow = row = startrow; row < startrow+height; ++row) { + src = rpng2_info.image_data + row*rpng2_info.rowbytes; + if (bg_image) + src2 = bg_data + row*bg_rowbytes; + dest = ximage->data + row*ximage_rowbytes; + if (rpng2_info.channels == 3) { + for (i = rpng2_info.width; i > 0; --i) { + red = *src++; + green = *src++; + blue = *src++; +#ifdef NO_24BIT_MASKS + pixel = (red << RShift) | + (green << GShift) | + (blue << BShift); + /* recall that we set ximage->byte_order = MSBFirst above */ + if (bpp == 32) { + *dest++ = (char)((pixel >> 24) & 0xff); + *dest++ = (char)((pixel >> 16) & 0xff); + *dest++ = (char)((pixel >> 8) & 0xff); + *dest++ = (char)( pixel & 0xff); + } else { + /* this assumes bpp == 24 & bits are packed low */ + /* (probably need to use RShift, RMask, etc.) */ + *dest++ = (char)((pixel >> 16) & 0xff); + *dest++ = (char)((pixel >> 8) & 0xff); + *dest++ = (char)( pixel & 0xff); + } +#else + red = (RShift < 0)? red << (-RShift) : red >> RShift; + green = (GShift < 0)? green << (-GShift) : green >> GShift; + blue = (BShift < 0)? blue << (-BShift) : blue >> BShift; + pixel = (red & RMask) | (green & GMask) | (blue & BMask); + /* recall that we set ximage->byte_order = MSBFirst above */ + if (bpp == 32) { + *dest++ = (char)((pixel >> 24) & 0xff); + *dest++ = (char)((pixel >> 16) & 0xff); + *dest++ = (char)((pixel >> 8) & 0xff); + *dest++ = (char)( pixel & 0xff); + } else { + /* GRR BUG */ + /* this assumes bpp == 24 & bits are packed low */ + /* (probably need to use RShift/RMask/etc. here, too) */ + *dest++ = (char)((pixel >> 16) & 0xff); + *dest++ = (char)((pixel >> 8) & 0xff); + *dest++ = (char)( pixel & 0xff); + } +#endif + } + + } else /* if (rpng2_info.channels == 4) */ { + for (i = rpng2_info.width; i > 0; --i) { + r = *src++; + g = *src++; + b = *src++; + a = *src++; + if (bg_image) { + bg_red = *src2++; + bg_green = *src2++; + bg_blue = *src2++; + } + if (a == 255) { + red = r; + green = g; + blue = b; + } else if (a == 0) { + red = bg_red; + green = bg_green; + blue = bg_blue; + } else { + /* this macro (from png.h) composites the foreground + * and background values and puts the result into the + * first argument */ + alpha_composite(red, r, a, bg_red); + alpha_composite(green, g, a, bg_green); + alpha_composite(blue, b, a, bg_blue); + } +#ifdef NO_24BIT_MASKS + pixel = (red << RShift) | + (green << GShift) | + (blue << BShift); + /* recall that we set ximage->byte_order = MSBFirst above */ + if (bpp == 32) { + *dest++ = (char)((pixel >> 24) & 0xff); + *dest++ = (char)((pixel >> 16) & 0xff); + *dest++ = (char)((pixel >> 8) & 0xff); + *dest++ = (char)( pixel & 0xff); + } else { + /* this assumes bpp == 24 & bits are packed low */ + /* (probably need to use RShift, RMask, etc.) */ + *dest++ = (char)((pixel >> 16) & 0xff); + *dest++ = (char)((pixel >> 8) & 0xff); + *dest++ = (char)( pixel & 0xff); + } +#else + red = (RShift < 0)? red << (-RShift) : red >> RShift; + green = (GShift < 0)? green << (-GShift) : green >> GShift; + blue = (BShift < 0)? blue << (-BShift) : blue >> BShift; + pixel = (red & RMask) | (green & GMask) | (blue & BMask); + /* recall that we set ximage->byte_order = MSBFirst above */ + if (bpp == 32) { + *dest++ = (char)((pixel >> 24) & 0xff); + *dest++ = (char)((pixel >> 16) & 0xff); + *dest++ = (char)((pixel >> 8) & 0xff); + *dest++ = (char)( pixel & 0xff); + } else { + /* GRR BUG */ + /* this assumes bpp == 24 & bits are packed low */ + /* (probably need to use RShift/RMask/etc. here, too) */ + *dest++ = (char)((pixel >> 16) & 0xff); + *dest++ = (char)((pixel >> 8) & 0xff); + *dest++ = (char)( pixel & 0xff); + } +#endif + } + } + /* display after every 16 lines */ + if (((row+1) & 0xf) == 0) { + XPutImage(display, window, gc, ximage, 0, (int)lastrow, 0, + (int)lastrow, rpng2_info.width, 16); + XFlush(display); + lastrow = row + 1; + } + } + + } else if (depth == 16) { + ush red, green, blue; + + for (lastrow = row = startrow; row < startrow+height; ++row) { + src = rpng2_info.row_pointers[row]; + if (bg_image) + src2 = bg_data + row*bg_rowbytes; + dest = ximage->data + row*ximage_rowbytes; + if (rpng2_info.channels == 3) { + for (i = rpng2_info.width; i > 0; --i) { + red = ((ush)(*src) << 8); + ++src; + green = ((ush)(*src) << 8); + ++src; + blue = ((ush)(*src) << 8); + ++src; + pixel = ((red >> RShift) & RMask) | + ((green >> GShift) & GMask) | + ((blue >> BShift) & BMask); + /* recall that we set ximage->byte_order = MSBFirst above */ + *dest++ = (char)((pixel >> 8) & 0xff); + *dest++ = (char)( pixel & 0xff); + } + } else /* if (rpng2_info.channels == 4) */ { + for (i = rpng2_info.width; i > 0; --i) { + r = *src++; + g = *src++; + b = *src++; + a = *src++; + if (bg_image) { + bg_red = *src2++; + bg_green = *src2++; + bg_blue = *src2++; + } + if (a == 255) { + red = ((ush)r << 8); + green = ((ush)g << 8); + blue = ((ush)b << 8); + } else if (a == 0) { + red = ((ush)bg_red << 8); + green = ((ush)bg_green << 8); + blue = ((ush)bg_blue << 8); + } else { + /* this macro (from png.h) composites the foreground + * and background values and puts the result back into + * the first argument (== fg byte here: safe) */ + alpha_composite(r, r, a, bg_red); + alpha_composite(g, g, a, bg_green); + alpha_composite(b, b, a, bg_blue); + red = ((ush)r << 8); + green = ((ush)g << 8); + blue = ((ush)b << 8); + } + pixel = ((red >> RShift) & RMask) | + ((green >> GShift) & GMask) | + ((blue >> BShift) & BMask); + /* recall that we set ximage->byte_order = MSBFirst above */ + *dest++ = (char)((pixel >> 8) & 0xff); + *dest++ = (char)( pixel & 0xff); + } + } + /* display after every 16 lines */ + if (((row+1) & 0xf) == 0) { + XPutImage(display, window, gc, ximage, 0, (int)lastrow, 0, + (int)lastrow, rpng2_info.width, 16); + XFlush(display); + lastrow = row + 1; + } + } + + } else /* depth == 8 */ { + + /* GRR: add 8-bit support */ + + } + + Trace((stderr, "calling final XPutImage()\n")) + if (lastrow < startrow+height) { + XPutImage(display, window, gc, ximage, 0, (int)lastrow, 0, + (int)lastrow, rpng2_info.width, rpng2_info.height-lastrow); + XFlush(display); + } + +} /* end function rpng2_x_redisplay_image() */ + + + + + +#ifdef FEATURE_LOOP + +static void rpng2_x_reload_bg_image(void) +{ + char *dest; + uch r1, r2, g1, g2, b1, b2; + uch r1_inv, r2_inv, g1_inv, g2_inv, b1_inv, b2_inv; + int k, hmax, max; + int xidx, yidx, yidx_max; + int even_odd_vert, even_odd_horiz, even_odd; + int invert_gradient2 = (bg[pat].type & 0x08); + int invert_column; + ulg i, row; + + + bgscale = (pat == 0)? 8 : bgscale_default; + yidx_max = bgscale - 1; + +/*--------------------------------------------------------------------------- + Vertical gradients (ramps) in NxN squares, alternating direction and + colors (N == bgscale). + ---------------------------------------------------------------------------*/ + + if ((bg[pat].type & 0x07) == 0) { + uch r1_min = rgb[bg[pat].rgb1_min].r; + uch g1_min = rgb[bg[pat].rgb1_min].g; + uch b1_min = rgb[bg[pat].rgb1_min].b; + uch r2_min = rgb[bg[pat].rgb2_min].r; + uch g2_min = rgb[bg[pat].rgb2_min].g; + uch b2_min = rgb[bg[pat].rgb2_min].b; + int r1_diff = rgb[bg[pat].rgb1_max].r - r1_min; + int g1_diff = rgb[bg[pat].rgb1_max].g - g1_min; + int b1_diff = rgb[bg[pat].rgb1_max].b - b1_min; + int r2_diff = rgb[bg[pat].rgb2_max].r - r2_min; + int g2_diff = rgb[bg[pat].rgb2_max].g - g2_min; + int b2_diff = rgb[bg[pat].rgb2_max].b - b2_min; + + for (row = 0; row < rpng2_info.height; ++row) { + yidx = (int)(row % bgscale); + even_odd_vert = (int)((row / bgscale) & 1); + + r1 = r1_min + (r1_diff * yidx) / yidx_max; + g1 = g1_min + (g1_diff * yidx) / yidx_max; + b1 = b1_min + (b1_diff * yidx) / yidx_max; + r1_inv = r1_min + (r1_diff * (yidx_max-yidx)) / yidx_max; + g1_inv = g1_min + (g1_diff * (yidx_max-yidx)) / yidx_max; + b1_inv = b1_min + (b1_diff * (yidx_max-yidx)) / yidx_max; + + r2 = r2_min + (r2_diff * yidx) / yidx_max; + g2 = g2_min + (g2_diff * yidx) / yidx_max; + b2 = b2_min + (b2_diff * yidx) / yidx_max; + r2_inv = r2_min + (r2_diff * (yidx_max-yidx)) / yidx_max; + g2_inv = g2_min + (g2_diff * (yidx_max-yidx)) / yidx_max; + b2_inv = b2_min + (b2_diff * (yidx_max-yidx)) / yidx_max; + + dest = (char *)bg_data + row*bg_rowbytes; + for (i = 0; i < rpng2_info.width; ++i) { + even_odd_horiz = (int)((i / bgscale) & 1); + even_odd = even_odd_vert ^ even_odd_horiz; + invert_column = + (even_odd_horiz && (bg[pat].type & 0x10)); + if (even_odd == 0) { /* gradient #1 */ + if (invert_column) { + *dest++ = r1_inv; + *dest++ = g1_inv; + *dest++ = b1_inv; + } else { + *dest++ = r1; + *dest++ = g1; + *dest++ = b1; + } + } else { /* gradient #2 */ + if ((invert_column && invert_gradient2) || + (!invert_column && !invert_gradient2)) + { + *dest++ = r2; /* not inverted or */ + *dest++ = g2; /* doubly inverted */ + *dest++ = b2; + } else { + *dest++ = r2_inv; + *dest++ = g2_inv; /* singly inverted */ + *dest++ = b2_inv; + } + } + } + } + +/*--------------------------------------------------------------------------- + Soft gradient-diamonds with scale = bgscale. Code contributed by Adam + M. Costello. + ---------------------------------------------------------------------------*/ + + } else if ((bg[pat].type & 0x07) == 1) { + + hmax = (bgscale-1)/2; /* half the max weight of a color */ + max = 2*hmax; /* the max weight of a color */ + + r1 = rgb[bg[pat].rgb1_max].r; + g1 = rgb[bg[pat].rgb1_max].g; + b1 = rgb[bg[pat].rgb1_max].b; + r2 = rgb[bg[pat].rgb2_max].r; + g2 = rgb[bg[pat].rgb2_max].g; + b2 = rgb[bg[pat].rgb2_max].b; + + for (row = 0; row < rpng2_info.height; ++row) { + yidx = (int)(row % bgscale); + if (yidx > hmax) + yidx = bgscale-1 - yidx; + dest = (char *)bg_data + row*bg_rowbytes; + for (i = 0; i < rpng2_info.width; ++i) { + xidx = (int)(i % bgscale); + if (xidx > hmax) + xidx = bgscale-1 - xidx; + k = xidx + yidx; + *dest++ = (k*r1 + (max-k)*r2) / max; + *dest++ = (k*g1 + (max-k)*g2) / max; + *dest++ = (k*b1 + (max-k)*b2) / max; + } + } + +/*--------------------------------------------------------------------------- + Radial "starburst" with azimuthal sinusoids; [eventually number of sinu- + soids will equal bgscale?]. This one is slow but very cool. Code con- + tributed by Pieter S. van der Meulen (originally in Smalltalk). + ---------------------------------------------------------------------------*/ + + } else if ((bg[pat].type & 0x07) == 2) { + uch ch; + int ii, x, y, hw, hh, grayspot; + double freq, rotate, saturate, gray, intensity; + double angle=0.0, aoffset=0.0, maxDist, dist; + double red=0.0, green=0.0, blue=0.0, hue, s, v, f, p, q, t; + + hh = (int)(rpng2_info.height / 2); + hw = (int)(rpng2_info.width / 2); + + /* variables for radial waves: + * aoffset: number of degrees to rotate hue [CURRENTLY NOT USED] + * freq: number of color beams originating from the center + * grayspot: size of the graying center area (anti-alias) + * rotate: rotation of the beams as a function of radius + * saturate: saturation of beams' shape azimuthally + */ + angle = CLIP(angle, 0.0, 360.0); + grayspot = CLIP(bg[pat].bg_gray, 1, (hh + hw)); + freq = MAX((double)bg[pat].bg_freq, 0.0); + saturate = (double)bg[pat].bg_bsat * 0.1; + rotate = (double)bg[pat].bg_brot * 0.1; + gray = 0.0; + intensity = 0.0; + maxDist = (double)((hw*hw) + (hh*hh)); + + for (row = 0; row < rpng2_info.height; ++row) { + y = (int)(row - hh); + dest = (char *)bg_data + row*bg_rowbytes; + for (i = 0; i < rpng2_info.width; ++i) { + x = (int)(i - hw); + angle = (x == 0)? PI_2 : atan((double)y / (double)x); + gray = (double)MAX(ABS(y), ABS(x)) / grayspot; + gray = MIN(1.0, gray); + dist = (double)((x*x) + (y*y)) / maxDist; + intensity = cos((angle+(rotate*dist*PI)) * freq) * + gray * saturate; + intensity = (MAX(MIN(intensity,1.0),-1.0) + 1.0) * 0.5; + hue = (angle + PI) * INV_PI_360 + aoffset; + s = gray * ((double)(ABS(x)+ABS(y)) / (double)(hw + hh)); + s = MIN(MAX(s,0.0), 1.0); + v = MIN(MAX(intensity,0.0), 1.0); + + if (s == 0.0) { + ch = (uch)(v * 255.0); + *dest++ = ch; + *dest++ = ch; + *dest++ = ch; + } else { + if ((hue < 0.0) || (hue >= 360.0)) + hue -= (((int)(hue / 360.0)) * 360.0); + hue /= 60.0; + ii = (int)hue; + f = hue - (double)ii; + p = (1.0 - s) * v; + q = (1.0 - (s * f)) * v; + t = (1.0 - (s * (1.0 - f))) * v; + if (ii == 0) { red = v; green = t; blue = p; } + else if (ii == 1) { red = q; green = v; blue = p; } + else if (ii == 2) { red = p; green = v; blue = t; } + else if (ii == 3) { red = p; green = q; blue = v; } + else if (ii == 4) { red = t; green = p; blue = v; } + else if (ii == 5) { red = v; green = p; blue = q; } + *dest++ = (uch)(red * 255.0); + *dest++ = (uch)(green * 255.0); + *dest++ = (uch)(blue * 255.0); + } + } + } + } + +} /* end function rpng2_x_reload_bg_image() */ + + + + + +static int is_number(char *p) +{ + while (*p) { + if (!isdigit(*p)) + return FALSE; + ++p; + } + return TRUE; +} + +#endif /* FEATURE_LOOP */ + + + + + +static void rpng2_x_cleanup(void) +{ + if (bg_image && bg_data) { + free(bg_data); + bg_data = NULL; + } + + if (rpng2_info.image_data) { + free(rpng2_info.image_data); + rpng2_info.image_data = NULL; + } + + if (rpng2_info.row_pointers) { + free(rpng2_info.row_pointers); + rpng2_info.row_pointers = NULL; + } + + if (ximage) { + if (ximage->data) { + free(ximage->data); /* we allocated it, so we free it */ + ximage->data = (char *)NULL; /* instead of XDestroyImage() */ + } + XDestroyImage(ximage); + ximage = NULL; + } + + if (have_gc) + XFreeGC(display, gc); + + if (have_window) + XDestroyWindow(display, window); + + if (have_colormap) + XFreeColormap(display, colormap); + + if (have_nondefault_visual) + XFree(visual_list); +} + + + + + +static int rpng2_x_msb(ulg u32val) +{ + int i; + + for (i = 31; i >= 0; --i) { + if (u32val & 0x80000000L) + break; + u32val <<= 1; + } + return i; +} diff --git a/libs/libpng-src/contrib/gregbook/toucan.png b/libs/libpng-src/contrib/gregbook/toucan.png new file mode 100644 index 000000000..03960d493 Binary files /dev/null and b/libs/libpng-src/contrib/gregbook/toucan.png differ diff --git a/libs/libpng-src/contrib/gregbook/wpng.c b/libs/libpng-src/contrib/gregbook/wpng.c new file mode 100644 index 000000000..a06e3529e --- /dev/null +++ b/libs/libpng-src/contrib/gregbook/wpng.c @@ -0,0 +1,853 @@ +/*--------------------------------------------------------------------------- + + wpng - simple PNG-writing program wpng.c + + This program converts certain NetPBM binary files (grayscale and RGB, + maxval = 255) to PNG. Non-interlaced PNGs are written progressively; + interlaced PNGs are read and written in one memory-intensive blast. + + Thanks to Jean-loup Gailly for providing the necessary trick to read + interactive text from the keyboard while stdin is redirected. Thanks + to Cosmin Truta for Cygwin fixes. + + NOTE: includes provisional support for PNM type "8" (portable alphamap) + images, presumed to be a 32-bit interleaved RGBA format; no pro- + vision for possible interleaved grayscale+alpha (16-bit) format. + THIS IS UNLIKELY TO BECOME AN OFFICIAL NETPBM ALPHA FORMAT! + + to do: + - delete output file if quit before calling any writepng routines + - process backspace with -text option under DOS/Win? (currently get ^H) + + --------------------------------------------------------------------------- + + Changelog: + - 1.01: initial public release + - 1.02: modified to allow abbreviated options + - 1.03: removed extraneous character from usage screen; fixed bug in + command-line parsing + - 1.04: fixed DOS/OS2/Win32 detection, including partial Cygwin fix + (see http://home.att.net/~perlspinr/diffs/GregBook_cygwin.diff) + - 2.00: dual-licensed (added GNU GPL) + + [REPORTED BUG (win32 only): "contrib/gregbook/wpng.c - cmd line + dose not work! In order to do something useful I needed to redirect + both input and output, with cygwin and with bcc32 as well. Under + Linux, the same wpng appears to work fine. I don't know what is + the problem."] + + --------------------------------------------------------------------------- + + Copyright (c) 1998-2007 Greg Roelofs. All rights reserved. + + This software is provided "as is," without warranty of any kind, + express or implied. In no event shall the author or contributors + be held liable for any damages arising in any way from the use of + this software. + + The contents of this file are DUAL-LICENSED. You may modify and/or + redistribute this software according to the terms of one of the + following two licenses (at your option): + + + LICENSE 1 ("BSD-like with advertising clause"): + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute + it freely, subject to the following restrictions: + + 1. Redistributions of source code must retain the above copyright + notice, disclaimer, and this list of conditions. + 2. Redistributions in binary form must reproduce the above copyright + notice, disclaimer, and this list of conditions in the documenta- + tion and/or other materials provided with the distribution. + 3. All advertising materials mentioning features or use of this + software must display the following acknowledgment: + + This product includes software developed by Greg Roelofs + and contributors for the book, "PNG: The Definitive Guide," + published by O'Reilly and Associates. + + + LICENSE 2 (GNU GPL v2 or later): + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + ---------------------------------------------------------------------------*/ + +#define PROGNAME "wpng" +#define VERSION "2.00 of 2 June 2007" +#define APPNAME "Simple PGM/PPM/PAM to PNG Converter" + +#if defined(__MSDOS__) || defined(__OS2__) +# define DOS_OS2_W32 +#elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) +# ifndef __GNUC__ /* treat Win32 native ports of gcc as Unix environments */ +# define DOS_OS2_W32 +# endif +#endif + +#include +#include +#include +#include /* for jmpbuf declaration in writepng.h */ +#include + +#ifdef DOS_OS2_W32 +# include /* for isatty(), setmode() prototypes */ +# include /* O_BINARY for fdopen() without text translation */ +# ifdef __EMX__ +# ifndef getch +# define getch() _read_kbd(0, 1, 0) /* need getche() */ +# endif +# else /* !__EMX__ */ +# ifdef __GO32__ +# include +# define getch() getkey() /* GRR: need getche() */ +# else +# include /* for getche() console input */ +# endif +# endif /* ?__EMX__ */ +# define FGETS(buf,len,stream) dos_kbd_gets(buf,len) +#else +# include /* for isatty() prototype */ +# define FGETS fgets +#endif + +/* #define DEBUG : this enables the Trace() macros */ + +/* #define FORBID_LATIN1_CTRL : this requires the user to re-enter any + text that includes control characters discouraged by the PNG spec; text + that includes an escape character (27) must be re-entered regardless */ + +#include "writepng.h" /* typedefs, common macros, writepng prototypes */ + + + +/* local prototypes */ + +static int wpng_isvalid_latin1(uch *p, int len); +static void wpng_cleanup(void); + +#ifdef DOS_OS2_W32 + static char *dos_kbd_gets(char *buf, int len); +#endif + + + +static mainprog_info wpng_info; /* lone global */ + + + +int main(int argc, char **argv) +{ +#ifndef DOS_OS2_W32 + FILE *keybd; +#endif +#ifdef sgi + FILE *tmpfile; /* or we could just use keybd, since no overlap */ + char tmpline[80]; +#endif + char *inname = NULL, outname[256]; + char *p, pnmchar, pnmline[256]; + char *bgstr, *textbuf = NULL; + ulg rowbytes; + int rc, len = 0; + int error = 0; + int text = FALSE; + int maxval; + double LUT_exponent; /* just the lookup table */ + double CRT_exponent = 2.2; /* just the monitor */ + double default_display_exponent; /* whole display system */ + double default_gamma = 0.0; + + + wpng_info.infile = NULL; + wpng_info.outfile = NULL; + wpng_info.image_data = NULL; + wpng_info.row_pointers = NULL; + wpng_info.filter = FALSE; + wpng_info.interlaced = FALSE; + wpng_info.have_bg = FALSE; + wpng_info.have_time = FALSE; + wpng_info.have_text = 0; + wpng_info.gamma = 0.0; + + + /* First get the default value for our display-system exponent, i.e., + * the product of the CRT exponent and the exponent corresponding to + * the frame-buffer's lookup table (LUT), if any. If the PNM image + * looks correct on the user's display system, its file gamma is the + * inverse of this value. (Note that this is not an exhaustive list + * of LUT values--e.g., OpenStep has a lot of weird ones--but it should + * cover 99% of the current possibilities. This section must ensure + * that default_display_exponent is positive.) */ + +#if defined(NeXT) + /* third-party utilities can modify the default LUT exponent */ + LUT_exponent = 1.0 / 2.2; + /* + if (some_next_function_that_returns_gamma(&next_gamma)) + LUT_exponent = 1.0 / next_gamma; + */ +#elif defined(sgi) + LUT_exponent = 1.0 / 1.7; + /* there doesn't seem to be any documented function to + * get the "gamma" value, so we do it the hard way */ + tmpfile = fopen("/etc/config/system.glGammaVal", "r"); + if (tmpfile) { + double sgi_gamma; + + fgets(tmpline, 80, tmpfile); + fclose(tmpfile); + sgi_gamma = atof(tmpline); + if (sgi_gamma > 0.0) + LUT_exponent = 1.0 / sgi_gamma; + } +#elif defined(Macintosh) + LUT_exponent = 1.8 / 2.61; + /* + if (some_mac_function_that_returns_gamma(&mac_gamma)) + LUT_exponent = mac_gamma / 2.61; + */ +#else + LUT_exponent = 1.0; /* assume no LUT: most PCs */ +#endif + + /* the defaults above give 1.0, 1.3, 1.5 and 2.2, respectively: */ + default_display_exponent = LUT_exponent * CRT_exponent; + + + /* If the user has set the SCREEN_GAMMA environment variable as suggested + * (somewhat imprecisely) in the libpng documentation, use that; otherwise + * use the default value we just calculated. Either way, the user may + * override this via a command-line option. */ + + if ((p = getenv("SCREEN_GAMMA")) != NULL) { + double exponent = atof(p); + + if (exponent > 0.0) + default_gamma = 1.0 / exponent; + } + + if (default_gamma == 0.0) + default_gamma = 1.0 / default_display_exponent; + + + /* Now parse the command line for options and the PNM filename. */ + + while (*++argv && !error) { + if (!strncmp(*argv, "-i", 2)) { + wpng_info.interlaced = TRUE; + } else if (!strncmp(*argv, "-time", 3)) { + wpng_info.modtime = time(NULL); + wpng_info.have_time = TRUE; + } else if (!strncmp(*argv, "-text", 3)) { + text = TRUE; + } else if (!strncmp(*argv, "-gamma", 2)) { + if (!*++argv) + ++error; + else { + wpng_info.gamma = atof(*argv); + if (wpng_info.gamma <= 0.0) + ++error; + else if (wpng_info.gamma > 1.01) + fprintf(stderr, PROGNAME + " warning: file gammas are usually less than 1.0\n"); + } + } else if (!strncmp(*argv, "-bgcolor", 4)) { + if (!*++argv) + ++error; + else { + bgstr = *argv; + if (strlen(bgstr) != 7 || bgstr[0] != '#') + ++error; + else { + unsigned r, g, b; /* this way quiets compiler warnings */ + + sscanf(bgstr+1, "%2x%2x%2x", &r, &g, &b); + wpng_info.bg_red = (uch)r; + wpng_info.bg_green = (uch)g; + wpng_info.bg_blue = (uch)b; + wpng_info.have_bg = TRUE; + } + } + } else { + if (**argv != '-') { + inname = *argv; + if (argv[1]) /* shouldn't be any more args after filename */ + ++error; + } else + ++error; /* not expecting any other options */ + } + } + + + /* open the input and output files, or register an error and abort */ + + if (!inname) { + if (isatty(0)) { + fprintf(stderr, PROGNAME + ": must give input filename or provide image data via stdin\n"); + ++error; + } else { +#ifdef DOS_OS2_W32 + /* some buggy C libraries require BOTH setmode() and fdopen(bin) */ + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); +#endif + if ((wpng_info.infile = fdopen(fileno(stdin), "rb")) == NULL) { + fprintf(stderr, PROGNAME + ": unable to reopen stdin in binary mode\n"); + ++error; + } else + if ((wpng_info.outfile = fdopen(fileno(stdout), "wb")) == NULL) { + fprintf(stderr, PROGNAME + ": unable to reopen stdout in binary mode\n"); + fclose(wpng_info.infile); + ++error; + } else + wpng_info.filter = TRUE; + } + } else if ((len = strlen(inname)) > 250) { + fprintf(stderr, PROGNAME ": input filename is too long [%d chars]\n", + len); + ++error; + } else if (!(wpng_info.infile = fopen(inname, "rb"))) { + fprintf(stderr, PROGNAME ": can't open input file [%s]\n", inname); + ++error; + } + + if (!error) { + fgets(pnmline, 256, wpng_info.infile); + if (pnmline[0] != 'P' || ((pnmchar = pnmline[1]) != '5' && + pnmchar != '6' && pnmchar != '8')) + { + fprintf(stderr, PROGNAME + ": input file [%s] is not a binary PGM, PPM or PAM file\n", + inname); + ++error; + } else { + wpng_info.pnmtype = (int)(pnmchar - '0'); + if (wpng_info.pnmtype != 8) + wpng_info.have_bg = FALSE; /* no need for bg if opaque */ + do { + fgets(pnmline, 256, wpng_info.infile); /* lose any comments */ + } while (pnmline[0] == '#'); + sscanf(pnmline, "%ld %ld", &wpng_info.width, &wpng_info.height); + do { + fgets(pnmline, 256, wpng_info.infile); /* more comment lines */ + } while (pnmline[0] == '#'); + sscanf(pnmline, "%d", &maxval); + if (wpng_info.width <= 0L || wpng_info.height <= 0L || + maxval != 255) + { + fprintf(stderr, PROGNAME + ": only positive width/height, maxval == 255 allowed \n"); + ++error; + } + wpng_info.sample_depth = 8; /* <==> maxval 255 */ + + if (!wpng_info.filter) { + /* make outname from inname */ + if ((p = strrchr(inname, '.')) == NULL || + (p - inname) != (len - 4)) + { + strcpy(outname, inname); + strcpy(outname+len, ".png"); + } else { + len -= 4; + strncpy(outname, inname, len); + strcpy(outname+len, ".png"); + } + /* check if outname already exists; if not, open */ + if ((wpng_info.outfile = fopen(outname, "rb")) != NULL) { + fprintf(stderr, PROGNAME ": output file exists [%s]\n", + outname); + fclose(wpng_info.outfile); + ++error; + } else if (!(wpng_info.outfile = fopen(outname, "wb"))) { + fprintf(stderr, PROGNAME ": can't open output file [%s]\n", + outname); + ++error; + } + } + } + if (error) { + fclose(wpng_info.infile); + wpng_info.infile = NULL; + if (wpng_info.filter) { + fclose(wpng_info.outfile); + wpng_info.outfile = NULL; + } + } + } + + + /* if we had any errors, print usage and die horrible death...arrr! */ + + if (error) { + fprintf(stderr, "\n%s %s: %s\n", PROGNAME, VERSION, APPNAME); + writepng_version_info(); + fprintf(stderr, "\n" +"Usage: %s [-gamma exp] [-bgcolor bg] [-text] [-time] [-interlace] pnmfile\n" +"or: ... | %s [-gamma exp] [-bgcolor bg] [-text] [-time] [-interlace] | ...\n" + " exp \ttransfer-function exponent (``gamma'') of the image in\n" + "\t\t floating-point format (e.g., ``%.5f''); if image looks\n" + "\t\t correct on given display system, image gamma is equal to\n" + "\t\t inverse of display-system exponent, i.e., 1 / (LUT * CRT)\n" + "\t\t (where LUT = lookup-table exponent and CRT = CRT exponent;\n" + "\t\t first varies, second is usually 2.2, all are positive)\n" + " bg \tdesired background color for alpha-channel images, in\n" + "\t\t 7-character hex RGB format (e.g., ``#ff7700'' for orange:\n" + "\t\t same as HTML colors)\n" + " -text\tprompt interactively for text info (tEXt chunks)\n" + " -time\tinclude a tIME chunk (last modification time)\n" + " -interlace\twrite interlaced PNG image\n" + "\n" +"pnmfile or stdin must be a binary PGM (`P5'), PPM (`P6') or (extremely\n" +"unofficial and unsupported!) PAM (`P8') file. Currently it is required\n" +"to have maxval == 255 (i.e., no scaling). If pnmfile is specified, it\n" +"is converted to the corresponding PNG file with the same base name but a\n" +"``.png'' extension; files read from stdin are converted and sent to stdout.\n" +"The conversion is progressive (low memory usage) unless interlacing is\n" +"requested; in that case the whole image will be buffered in memory and\n" +"written in one call.\n" + "\n", PROGNAME, PROGNAME, default_gamma); + exit(1); + } + + + /* prepare the text buffers for libpng's use; note that even though + * PNG's png_text struct includes a length field, we don't have to fill + * it out */ + + if (text && +#ifndef DOS_OS2_W32 + (keybd = fdopen(fileno(stderr), "r")) != NULL && +#endif + (textbuf = (char *)malloc((5 + 9)*75)) != NULL) + { + int i, valid, result; + + fprintf(stderr, + "Enter text info (no more than 72 characters per line);\n"); + fprintf(stderr, "to skip a field, hit the key.\n"); + /* note: just leaves len == 1 */ + + do { + valid = TRUE; + p = textbuf + TEXT_TITLE_OFFSET; + fprintf(stderr, " Title: "); + fflush(stderr); + if (FGETS(p, 74, keybd) && (len = strlen(p)) > 1) { + if (p[len-1] == '\n') + p[--len] = '\0'; + wpng_info.title = p; + wpng_info.have_text |= TEXT_TITLE; + if ((result = wpng_isvalid_latin1((uch *)p, len)) >= 0) { + fprintf(stderr, " " PROGNAME " warning: character code" + " %u is %sdiscouraged by the PNG\n specification " + "[first occurrence was at character position #%d]\n", + (unsigned)p[result], (p[result] == 27)? "strongly " : "", + result+1); + fflush(stderr); +#ifdef FORBID_LATIN1_CTRL + wpng_info.have_text &= ~TEXT_TITLE; + valid = FALSE; +#else + if (p[result] == 27) { /* escape character */ + wpng_info.have_text &= ~TEXT_TITLE; + valid = FALSE; + } +#endif + } + } + } while (!valid); + + do { + valid = TRUE; + p = textbuf + TEXT_AUTHOR_OFFSET; + fprintf(stderr, " Author: "); + fflush(stderr); + if (FGETS(p, 74, keybd) && (len = strlen(p)) > 1) { + if (p[len-1] == '\n') + p[--len] = '\0'; + wpng_info.author = p; + wpng_info.have_text |= TEXT_AUTHOR; + if ((result = wpng_isvalid_latin1((uch *)p, len)) >= 0) { + fprintf(stderr, " " PROGNAME " warning: character code" + " %u is %sdiscouraged by the PNG\n specification " + "[first occurrence was at character position #%d]\n", + (unsigned)p[result], (p[result] == 27)? "strongly " : "", + result+1); + fflush(stderr); +#ifdef FORBID_LATIN1_CTRL + wpng_info.have_text &= ~TEXT_AUTHOR; + valid = FALSE; +#else + if (p[result] == 27) { /* escape character */ + wpng_info.have_text &= ~TEXT_AUTHOR; + valid = FALSE; + } +#endif + } + } + } while (!valid); + + do { + valid = TRUE; + p = textbuf + TEXT_DESC_OFFSET; + fprintf(stderr, " Description (up to 9 lines):\n"); + for (i = 1; i < 10; ++i) { + fprintf(stderr, " [%d] ", i); + fflush(stderr); + if (FGETS(p, 74, keybd) && (len = strlen(p)) > 1) + p += len; /* now points at NULL; char before is newline */ + else + break; + } + if ((len = p - (textbuf + TEXT_DESC_OFFSET)) > 1) { + if (p[-1] == '\n') { + p[-1] = '\0'; + --len; + } + wpng_info.desc = textbuf + TEXT_DESC_OFFSET; + wpng_info.have_text |= TEXT_DESC; + p = textbuf + TEXT_DESC_OFFSET; + if ((result = wpng_isvalid_latin1((uch *)p, len)) >= 0) { + fprintf(stderr, " " PROGNAME " warning: character code" + " %u is %sdiscouraged by the PNG\n specification " + "[first occurrence was at character position #%d]\n", + (unsigned)p[result], (p[result] == 27)? "strongly " : "", + result+1); + fflush(stderr); +#ifdef FORBID_LATIN1_CTRL + wpng_info.have_text &= ~TEXT_DESC; + valid = FALSE; +#else + if (p[result] == 27) { /* escape character */ + wpng_info.have_text &= ~TEXT_DESC; + valid = FALSE; + } +#endif + } + } + } while (!valid); + + do { + valid = TRUE; + p = textbuf + TEXT_COPY_OFFSET; + fprintf(stderr, " Copyright: "); + fflush(stderr); + if (FGETS(p, 74, keybd) && (len = strlen(p)) > 1) { + if (p[len-1] == '\n') + p[--len] = '\0'; + wpng_info.copyright = p; + wpng_info.have_text |= TEXT_COPY; + if ((result = wpng_isvalid_latin1((uch *)p, len)) >= 0) { + fprintf(stderr, " " PROGNAME " warning: character code" + " %u is %sdiscouraged by the PNG\n specification " + "[first occurrence was at character position #%d]\n", + (unsigned)p[result], (p[result] == 27)? "strongly " : "", + result+1); + fflush(stderr); +#ifdef FORBID_LATIN1_CTRL + wpng_info.have_text &= ~TEXT_COPY; + valid = FALSE; +#else + if (p[result] == 27) { /* escape character */ + wpng_info.have_text &= ~TEXT_COPY; + valid = FALSE; + } +#endif + } + } + } while (!valid); + + do { + valid = TRUE; + p = textbuf + TEXT_EMAIL_OFFSET; + fprintf(stderr, " E-mail: "); + fflush(stderr); + if (FGETS(p, 74, keybd) && (len = strlen(p)) > 1) { + if (p[len-1] == '\n') + p[--len] = '\0'; + wpng_info.email = p; + wpng_info.have_text |= TEXT_EMAIL; + if ((result = wpng_isvalid_latin1((uch *)p, len)) >= 0) { + fprintf(stderr, " " PROGNAME " warning: character code" + " %u is %sdiscouraged by the PNG\n specification " + "[first occurrence was at character position #%d]\n", + (unsigned)p[result], (p[result] == 27)? "strongly " : "", + result+1); + fflush(stderr); +#ifdef FORBID_LATIN1_CTRL + wpng_info.have_text &= ~TEXT_EMAIL; + valid = FALSE; +#else + if (p[result] == 27) { /* escape character */ + wpng_info.have_text &= ~TEXT_EMAIL; + valid = FALSE; + } +#endif + } + } + } while (!valid); + + do { + valid = TRUE; + p = textbuf + TEXT_URL_OFFSET; + fprintf(stderr, " URL: "); + fflush(stderr); + if (FGETS(p, 74, keybd) && (len = strlen(p)) > 1) { + if (p[len-1] == '\n') + p[--len] = '\0'; + wpng_info.url = p; + wpng_info.have_text |= TEXT_URL; + if ((result = wpng_isvalid_latin1((uch *)p, len)) >= 0) { + fprintf(stderr, " " PROGNAME " warning: character code" + " %u is %sdiscouraged by the PNG\n specification " + "[first occurrence was at character position #%d]\n", + (unsigned)p[result], (p[result] == 27)? "strongly " : "", + result+1); + fflush(stderr); +#ifdef FORBID_LATIN1_CTRL + wpng_info.have_text &= ~TEXT_URL; + valid = FALSE; +#else + if (p[result] == 27) { /* escape character */ + wpng_info.have_text &= ~TEXT_URL; + valid = FALSE; + } +#endif + } + } + } while (!valid); + +#ifndef DOS_OS2_W32 + fclose(keybd); +#endif + + } else if (text) { + fprintf(stderr, PROGNAME ": unable to allocate memory for text\n"); + text = FALSE; + wpng_info.have_text = 0; + } + + + /* allocate libpng stuff, initialize transformations, write pre-IDAT data */ + + if ((rc = writepng_init(&wpng_info)) != 0) { + switch (rc) { + case 2: + fprintf(stderr, PROGNAME + ": libpng initialization problem (longjmp)\n"); + break; + case 4: + fprintf(stderr, PROGNAME ": insufficient memory\n"); + break; + case 11: + fprintf(stderr, PROGNAME + ": internal logic error (unexpected PNM type)\n"); + break; + default: + fprintf(stderr, PROGNAME + ": unknown writepng_init() error\n"); + break; + } + exit(rc); + } + + + /* free textbuf, since it's a completely local variable and all text info + * has just been written to the PNG file */ + + if (text && textbuf) { + free(textbuf); + textbuf = NULL; + } + + + /* calculate rowbytes on basis of image type; note that this becomes much + * more complicated if we choose to support PBM type, ASCII PNM types, or + * 16-bit-per-sample binary data [currently not an official NetPBM type] */ + + if (wpng_info.pnmtype == 5) + rowbytes = wpng_info.width; + else if (wpng_info.pnmtype == 6) + rowbytes = wpng_info.width * 3; + else /* if (wpng_info.pnmtype == 8) */ + rowbytes = wpng_info.width * 4; + + + /* read and write the image, either in its entirety (if writing interlaced + * PNG) or row by row (if non-interlaced) */ + + fprintf(stderr, "Encoding image data...\n"); + fflush(stderr); + + if (wpng_info.interlaced) { + long i; + ulg bytes; + ulg image_bytes = rowbytes * wpng_info.height; /* overflow? */ + + wpng_info.image_data = (uch *)malloc(image_bytes); + wpng_info.row_pointers = (uch **)malloc(wpng_info.height*sizeof(uch *)); + if (wpng_info.image_data == NULL || wpng_info.row_pointers == NULL) { + fprintf(stderr, PROGNAME ": insufficient memory for image data\n"); + writepng_cleanup(&wpng_info); + wpng_cleanup(); + exit(5); + } + for (i = 0; i < wpng_info.height; ++i) + wpng_info.row_pointers[i] = wpng_info.image_data + i*rowbytes; + bytes = fread(wpng_info.image_data, 1, image_bytes, wpng_info.infile); + if (bytes != image_bytes) { + fprintf(stderr, PROGNAME ": expected %lu bytes, got %lu bytes\n", + image_bytes, bytes); + fprintf(stderr, " (continuing anyway)\n"); + } + if (writepng_encode_image(&wpng_info) != 0) { + fprintf(stderr, PROGNAME + ": libpng problem (longjmp) while writing image data\n"); + writepng_cleanup(&wpng_info); + wpng_cleanup(); + exit(2); + } + + } else /* not interlaced: write progressively (row by row) */ { + long j; + ulg bytes; + + wpng_info.image_data = (uch *)malloc(rowbytes); + if (wpng_info.image_data == NULL) { + fprintf(stderr, PROGNAME ": insufficient memory for row data\n"); + writepng_cleanup(&wpng_info); + wpng_cleanup(); + exit(5); + } + error = 0; + for (j = wpng_info.height; j > 0L; --j) { + bytes = fread(wpng_info.image_data, 1, rowbytes, wpng_info.infile); + if (bytes != rowbytes) { + fprintf(stderr, PROGNAME + ": expected %lu bytes, got %lu bytes (row %ld)\n", rowbytes, + bytes, wpng_info.height-j); + ++error; + break; + } + if (writepng_encode_row(&wpng_info) != 0) { + fprintf(stderr, PROGNAME + ": libpng problem (longjmp) while writing row %ld\n", + wpng_info.height-j); + ++error; + break; + } + } + if (error) { + writepng_cleanup(&wpng_info); + wpng_cleanup(); + exit(2); + } + if (writepng_encode_finish(&wpng_info) != 0) { + fprintf(stderr, PROGNAME ": error on final libpng call\n"); + writepng_cleanup(&wpng_info); + wpng_cleanup(); + exit(2); + } + } + + + /* OK, we're done (successfully): clean up all resources and quit */ + + fprintf(stderr, "Done.\n"); + fflush(stderr); + + writepng_cleanup(&wpng_info); + wpng_cleanup(); + + return 0; +} + + + + + +static int wpng_isvalid_latin1(uch *p, int len) +{ + int i, result = -1; + + for (i = 0; i < len; ++i) { + if (p[i] == 10 || (p[i] > 31 && p[i] < 127) || p[i] > 160) + continue; /* character is completely OK */ + if (result < 0 || (p[result] != 27 && p[i] == 27)) + result = i; /* mark location of first questionable one */ + } /* or of first escape character (bad) */ + + return result; +} + + + + + +static void wpng_cleanup(void) +{ + if (wpng_info.outfile) { + fclose(wpng_info.outfile); + wpng_info.outfile = NULL; + } + + if (wpng_info.infile) { + fclose(wpng_info.infile); + wpng_info.infile = NULL; + } + + if (wpng_info.image_data) { + free(wpng_info.image_data); + wpng_info.image_data = NULL; + } + + if (wpng_info.row_pointers) { + free(wpng_info.row_pointers); + wpng_info.row_pointers = NULL; + } +} + + + + +#ifdef DOS_OS2_W32 + +static char *dos_kbd_gets(char *buf, int len) +{ + int ch, count=0; + + do { + buf[count++] = ch = getche(); + } while (ch != '\r' && count < len-1); + + buf[count--] = '\0'; /* terminate string */ + if (buf[count] == '\r') /* Enter key makes CR, so change to newline */ + buf[count] = '\n'; + + fprintf(stderr, "\n"); /* Enter key does *not* cause a newline */ + fflush(stderr); + + return buf; +} + +#endif /* DOS_OS2_W32 */ diff --git a/libs/libpng-src/contrib/gregbook/writepng.c b/libs/libpng-src/contrib/gregbook/writepng.c new file mode 100644 index 000000000..e6d81ea40 --- /dev/null +++ b/libs/libpng-src/contrib/gregbook/writepng.c @@ -0,0 +1,392 @@ +/*--------------------------------------------------------------------------- + + wpng - simple PNG-writing program writepng.c + + --------------------------------------------------------------------------- + + Copyright (c) 1998-2007 Greg Roelofs. All rights reserved. + + This software is provided "as is," without warranty of any kind, + express or implied. In no event shall the author or contributors + be held liable for any damages arising in any way from the use of + this software. + + The contents of this file are DUAL-LICENSED. You may modify and/or + redistribute this software according to the terms of one of the + following two licenses (at your option): + + + LICENSE 1 ("BSD-like with advertising clause"): + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute + it freely, subject to the following restrictions: + + 1. Redistributions of source code must retain the above copyright + notice, disclaimer, and this list of conditions. + 2. Redistributions in binary form must reproduce the above copyright + notice, disclaimer, and this list of conditions in the documenta- + tion and/or other materials provided with the distribution. + 3. All advertising materials mentioning features or use of this + software must display the following acknowledgment: + + This product includes software developed by Greg Roelofs + and contributors for the book, "PNG: The Definitive Guide," + published by O'Reilly and Associates. + + + LICENSE 2 (GNU GPL v2 or later): + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + ---------------------------------------------------------------------------*/ + + +#include /* for exit() prototype */ + +#include "png.h" /* libpng header; includes zlib.h and setjmp.h */ +#include "writepng.h" /* typedefs, common macros, public prototypes */ + + +/* local prototype */ + +static void writepng_error_handler(png_structp png_ptr, png_const_charp msg); + + + +void writepng_version_info(void) +{ + fprintf(stderr, " Compiled with libpng %s; using libpng %s.\n", + PNG_LIBPNG_VER_STRING, png_libpng_ver); + fprintf(stderr, " Compiled with zlib %s; using zlib %s.\n", + ZLIB_VERSION, zlib_version); +} + + + + +/* returns 0 for success, 2 for libpng problem, 4 for out of memory, 11 for + * unexpected pnmtype; note that outfile might be stdout */ + +int writepng_init(mainprog_info *mainprog_ptr) +{ + png_structp png_ptr; /* note: temporary variables! */ + png_infop info_ptr; + int color_type, interlace_type; + + + /* could also replace libpng warning-handler (final NULL), but no need: */ + + png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, mainprog_ptr, + writepng_error_handler, NULL); + if (!png_ptr) + return 4; /* out of memory */ + + info_ptr = png_create_info_struct(png_ptr); + if (!info_ptr) { + png_destroy_write_struct(&png_ptr, NULL); + return 4; /* out of memory */ + } + + + /* setjmp() must be called in every function that calls a PNG-writing + * libpng function, unless an alternate error handler was installed-- + * but compatible error handlers must either use longjmp() themselves + * (as in this program) or exit immediately, so here we go: */ + + if (setjmp(mainprog_ptr->jmpbuf)) { + png_destroy_write_struct(&png_ptr, &info_ptr); + return 2; + } + + + /* make sure outfile is (re)opened in BINARY mode */ + + png_init_io(png_ptr, mainprog_ptr->outfile); + + + /* set the compression levels--in general, always want to leave filtering + * turned on (except for palette images) and allow all of the filters, + * which is the default; want 32K zlib window, unless entire image buffer + * is 16K or smaller (unknown here)--also the default; usually want max + * compression (NOT the default); and remaining compression flags should + * be left alone */ + + png_set_compression_level(png_ptr, Z_BEST_COMPRESSION); +/* + >> this is default for no filtering; Z_FILTERED is default otherwise: + png_set_compression_strategy(png_ptr, Z_DEFAULT_STRATEGY); + >> these are all defaults: + png_set_compression_mem_level(png_ptr, 8); + png_set_compression_window_bits(png_ptr, 15); + png_set_compression_method(png_ptr, 8); + */ + + + /* set the image parameters appropriately */ + + if (mainprog_ptr->pnmtype == 5) + color_type = PNG_COLOR_TYPE_GRAY; + else if (mainprog_ptr->pnmtype == 6) + color_type = PNG_COLOR_TYPE_RGB; + else if (mainprog_ptr->pnmtype == 8) + color_type = PNG_COLOR_TYPE_RGB_ALPHA; + else { + png_destroy_write_struct(&png_ptr, &info_ptr); + return 11; + } + + interlace_type = mainprog_ptr->interlaced? PNG_INTERLACE_ADAM7 : + PNG_INTERLACE_NONE; + + png_set_IHDR(png_ptr, info_ptr, mainprog_ptr->width, mainprog_ptr->height, + mainprog_ptr->sample_depth, color_type, interlace_type, + PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); + + if (mainprog_ptr->gamma > 0.0) + png_set_gAMA(png_ptr, info_ptr, mainprog_ptr->gamma); + + if (mainprog_ptr->have_bg) { /* we know it's RGBA, not gray+alpha */ + png_color_16 background; + + background.red = mainprog_ptr->bg_red; + background.green = mainprog_ptr->bg_green; + background.blue = mainprog_ptr->bg_blue; + png_set_bKGD(png_ptr, info_ptr, &background); + } + + if (mainprog_ptr->have_time) { + png_time modtime; + + png_convert_from_time_t(&modtime, mainprog_ptr->modtime); + png_set_tIME(png_ptr, info_ptr, &modtime); + } + + if (mainprog_ptr->have_text) { + png_text text[6]; + int num_text = 0; + + if (mainprog_ptr->have_text & TEXT_TITLE) { + text[num_text].compression = PNG_TEXT_COMPRESSION_NONE; + text[num_text].key = "Title"; + text[num_text].text = mainprog_ptr->title; + ++num_text; + } + if (mainprog_ptr->have_text & TEXT_AUTHOR) { + text[num_text].compression = PNG_TEXT_COMPRESSION_NONE; + text[num_text].key = "Author"; + text[num_text].text = mainprog_ptr->author; + ++num_text; + } + if (mainprog_ptr->have_text & TEXT_DESC) { + text[num_text].compression = PNG_TEXT_COMPRESSION_NONE; + text[num_text].key = "Description"; + text[num_text].text = mainprog_ptr->desc; + ++num_text; + } + if (mainprog_ptr->have_text & TEXT_COPY) { + text[num_text].compression = PNG_TEXT_COMPRESSION_NONE; + text[num_text].key = "Copyright"; + text[num_text].text = mainprog_ptr->copyright; + ++num_text; + } + if (mainprog_ptr->have_text & TEXT_EMAIL) { + text[num_text].compression = PNG_TEXT_COMPRESSION_NONE; + text[num_text].key = "E-mail"; + text[num_text].text = mainprog_ptr->email; + ++num_text; + } + if (mainprog_ptr->have_text & TEXT_URL) { + text[num_text].compression = PNG_TEXT_COMPRESSION_NONE; + text[num_text].key = "URL"; + text[num_text].text = mainprog_ptr->url; + ++num_text; + } + png_set_text(png_ptr, info_ptr, text, num_text); + } + + + /* write all chunks up to (but not including) first IDAT */ + + png_write_info(png_ptr, info_ptr); + + + /* if we wanted to write any more text info *after* the image data, we + * would set up text struct(s) here and call png_set_text() again, with + * just the new data; png_set_tIME() could also go here, but it would + * have no effect since we already called it above (only one tIME chunk + * allowed) */ + + + /* set up the transformations: for now, just pack low-bit-depth pixels + * into bytes (one, two or four pixels per byte) */ + + png_set_packing(png_ptr); +/* png_set_shift(png_ptr, &sig_bit); to scale low-bit-depth values */ + + + /* make sure we save our pointers for use in writepng_encode_image() */ + + mainprog_ptr->png_ptr = png_ptr; + mainprog_ptr->info_ptr = info_ptr; + + + /* OK, that's all we need to do for now; return happy */ + + return 0; +} + + + + + +/* returns 0 for success, 2 for libpng (longjmp) problem */ + +int writepng_encode_image(mainprog_info *mainprog_ptr) +{ + png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr; + png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr; + + + /* as always, setjmp() must be called in every function that calls a + * PNG-writing libpng function */ + + if (setjmp(mainprog_ptr->jmpbuf)) { + png_destroy_write_struct(&png_ptr, &info_ptr); + mainprog_ptr->png_ptr = NULL; + mainprog_ptr->info_ptr = NULL; + return 2; + } + + + /* and now we just write the whole image; libpng takes care of interlacing + * for us */ + + png_write_image(png_ptr, mainprog_ptr->row_pointers); + + + /* since that's it, we also close out the end of the PNG file now--if we + * had any text or time info to write after the IDATs, second argument + * would be info_ptr, but we optimize slightly by sending NULL pointer: */ + + png_write_end(png_ptr, NULL); + + return 0; +} + + + + + +/* returns 0 if succeeds, 2 if libpng problem */ + +int writepng_encode_row(mainprog_info *mainprog_ptr) /* NON-interlaced only! */ +{ + png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr; + png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr; + + + /* as always, setjmp() must be called in every function that calls a + * PNG-writing libpng function */ + + if (setjmp(mainprog_ptr->jmpbuf)) { + png_destroy_write_struct(&png_ptr, &info_ptr); + mainprog_ptr->png_ptr = NULL; + mainprog_ptr->info_ptr = NULL; + return 2; + } + + + /* image_data points at our one row of image data */ + + png_write_row(png_ptr, mainprog_ptr->image_data); + + return 0; +} + + + + + +/* returns 0 if succeeds, 2 if libpng problem */ + +int writepng_encode_finish(mainprog_info *mainprog_ptr) /* NON-interlaced! */ +{ + png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr; + png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr; + + + /* as always, setjmp() must be called in every function that calls a + * PNG-writing libpng function */ + + if (setjmp(mainprog_ptr->jmpbuf)) { + png_destroy_write_struct(&png_ptr, &info_ptr); + mainprog_ptr->png_ptr = NULL; + mainprog_ptr->info_ptr = NULL; + return 2; + } + + + /* close out PNG file; if we had any text or time info to write after + * the IDATs, second argument would be info_ptr: */ + + png_write_end(png_ptr, NULL); + + return 0; +} + + + + + +void writepng_cleanup(mainprog_info *mainprog_ptr) +{ + png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr; + png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr; + + if (png_ptr && info_ptr) + png_destroy_write_struct(&png_ptr, &info_ptr); +} + + + + + +static void writepng_error_handler(png_structp png_ptr, png_const_charp msg) +{ + mainprog_info *mainprog_ptr; + + /* This function, aside from the extra step of retrieving the "error + * pointer" (below) and the fact that it exists within the application + * rather than within libpng, is essentially identical to libpng's + * default error handler. The second point is critical: since both + * setjmp() and longjmp() are called from the same code, they are + * guaranteed to have compatible notions of how big a jmp_buf is, + * regardless of whether _BSD_SOURCE or anything else has (or has not) + * been defined. */ + + fprintf(stderr, "writepng libpng error: %s\n", msg); + fflush(stderr); + + mainprog_ptr = png_get_error_ptr(png_ptr); + if (mainprog_ptr == NULL) { /* we are completely hosed now */ + fprintf(stderr, + "writepng severe error: jmpbuf not recoverable; terminating.\n"); + fflush(stderr); + exit(99); + } + + longjmp(mainprog_ptr->jmpbuf, 1); +} diff --git a/libs/libpng-src/contrib/gregbook/writepng.h b/libs/libpng-src/contrib/gregbook/writepng.h new file mode 100644 index 000000000..78b966b58 --- /dev/null +++ b/libs/libpng-src/contrib/gregbook/writepng.h @@ -0,0 +1,133 @@ +/*--------------------------------------------------------------------------- + + wpng - simple PNG-writing program writepng.h + + --------------------------------------------------------------------------- + + Copyright (c) 1998-2007 Greg Roelofs. All rights reserved. + + This software is provided "as is," without warranty of any kind, + express or implied. In no event shall the author or contributors + be held liable for any damages arising in any way from the use of + this software. + + The contents of this file are DUAL-LICENSED. You may modify and/or + redistribute this software according to the terms of one of the + following two licenses (at your option): + + + LICENSE 1 ("BSD-like with advertising clause"): + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute + it freely, subject to the following restrictions: + + 1. Redistributions of source code must retain the above copyright + notice, disclaimer, and this list of conditions. + 2. Redistributions in binary form must reproduce the above copyright + notice, disclaimer, and this list of conditions in the documenta- + tion and/or other materials provided with the distribution. + 3. All advertising materials mentioning features or use of this + software must display the following acknowledgment: + + This product includes software developed by Greg Roelofs + and contributors for the book, "PNG: The Definitive Guide," + published by O'Reilly and Associates. + + + LICENSE 2 (GNU GPL v2 or later): + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + ---------------------------------------------------------------------------*/ + +#ifndef TRUE +# define TRUE 1 +# define FALSE 0 +#endif + +#ifndef MAX +# define MAX(a,b) ((a) > (b)? (a) : (b)) +# define MIN(a,b) ((a) < (b)? (a) : (b)) +#endif + +#ifdef DEBUG +# define Trace(x) {fprintf x ; fflush(stderr); fflush(stdout);} +#else +# define Trace(x) ; +#endif + +#define TEXT_TITLE 0x01 +#define TEXT_AUTHOR 0x02 +#define TEXT_DESC 0x04 +#define TEXT_COPY 0x08 +#define TEXT_EMAIL 0x10 +#define TEXT_URL 0x20 + +#define TEXT_TITLE_OFFSET 0 +#define TEXT_AUTHOR_OFFSET 72 +#define TEXT_COPY_OFFSET (2*72) +#define TEXT_EMAIL_OFFSET (3*72) +#define TEXT_URL_OFFSET (4*72) +#define TEXT_DESC_OFFSET (5*72) + +typedef unsigned char uch; +typedef unsigned short ush; +typedef unsigned long ulg; + +typedef struct _mainprog_info { + double gamma; + long width; + long height; + time_t modtime; + FILE *infile; + FILE *outfile; + void *png_ptr; + void *info_ptr; + uch *image_data; + uch **row_pointers; + char *title; + char *author; + char *desc; + char *copyright; + char *email; + char *url; + int filter; /* command-line-filter flag, not PNG row filter! */ + int pnmtype; + int sample_depth; + int interlaced; + int have_bg; + int have_time; + int have_text; + jmp_buf jmpbuf; + uch bg_red; + uch bg_green; + uch bg_blue; +} mainprog_info; + + +/* prototypes for public functions in writepng.c */ + +void writepng_version_info(void); + +int writepng_init(mainprog_info *mainprog_ptr); + +int writepng_encode_image(mainprog_info *mainprog_ptr); + +int writepng_encode_row(mainprog_info *mainprog_ptr); + +int writepng_encode_finish(mainprog_info *mainprog_ptr); + +void writepng_cleanup(mainprog_info *mainprog_ptr); diff --git a/libs/libpng-src/contrib/pngminim/decoder/README b/libs/libpng-src/contrib/pngminim/decoder/README new file mode 100644 index 000000000..a656e0b93 --- /dev/null +++ b/libs/libpng-src/contrib/pngminim/decoder/README @@ -0,0 +1,9 @@ +This demonstrates the use of PNG_USER_CONFIG and pngusr.h + +To build a minimal read-only decoder with embedded libpng and zlib, run + + gather.sh # to collect needed files from pngminus, libpng, and zlib + make + +If you prefer to use the shared libraries, go to contrib/pngminus +and build the png2pnm application there. diff --git a/libs/libpng-src/contrib/pngminim/decoder/gather.sh b/libs/libpng-src/contrib/pngminim/decoder/gather.sh new file mode 100755 index 000000000..913b78deb --- /dev/null +++ b/libs/libpng-src/contrib/pngminim/decoder/gather.sh @@ -0,0 +1,9 @@ +cp ../../pngminus/png2pnm.c pngm2pnm.c +cp ../../../*.h . +cp ../../../*.c . +rm pnggccrd.c pngvcrd.c +rm example.c pngtest.c pngpread.c pngw*.c +# change the following 2 lines if zlib is somewhere else +cp ../../../../zlib/*.h . +cp ../../../../zlib/*.c . +rm minigzip.c example.c compress.c deflate.c gz* diff --git a/libs/libpng-src/contrib/pngminim/decoder/makefile b/libs/libpng-src/contrib/pngminim/decoder/makefile new file mode 100644 index 000000000..4c738396b --- /dev/null +++ b/libs/libpng-src/contrib/pngminim/decoder/makefile @@ -0,0 +1,44 @@ +# Makefile for PngMinus (pngm2pnm) +# Linux / Unix + +#CC=cc +CC=gcc +LD=$(CC) + +RM=rm -f + +CFLAGS=-DPNG_USER_CONFIG -DNO_GZCOMPRESS -DNO_GZIP \ + -DdeflateParams\(a,b,c\)=Z_OK -I. -O1 + +C=.c +O=.o +L=.a +E= + +ZOBJS = adler32$(O) crc32$(O) \ + infback$(O) inffast$(O) inflate$(O) inftrees$(O) \ + trees$(O) uncompr$(O) zutil$(O) + +OBJS = pngm2pnm$(O) png$(O) pngerror$(O) pngget$(O) pngmem$(O) \ + pngread$(O) pngrio$(O) pngrtran$(O) pngrutil$(O) \ + pngset$(O) pngtrans$(O) $(ZOBJS) + +# implicit make rules ------------------------------------------------------- + +.c$(O): png.h pngconf.h pngusr.h zlib.h + $(CC) -c $(CFLAGS) $< + +# dependencies + +all: pngm2pnm$(E) + +pngm2pnm$(E): $(OBJS) + $(LD) -o pngm2pnm$(E) $(OBJS) + strip pngm2pnm$(E) + +clean: + $(RM) pngm2pnm$(O) + $(RM) pngm2pnm$(E) + $(RM) $(OBJS) + +# End of makefile for pngm2pnm diff --git a/libs/libpng-src/contrib/pngminim/decoder/pngusr.h b/libs/libpng-src/contrib/pngminim/decoder/pngusr.h new file mode 100644 index 000000000..2312a78b2 --- /dev/null +++ b/libs/libpng-src/contrib/pngminim/decoder/pngusr.h @@ -0,0 +1,78 @@ +/* minrdpngconf.h: headers to make a minimal png-read-only library + * + * Copyright (c) 2007, 2009 Glenn Randers-Pehrson + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + * + * Derived from pngcrush.h, Copyright 1998-2007, Glenn Randers-Pehrson + */ + +#ifndef MINRDPNGCONF_H +#define MINRDPNGCONF_H + +#ifdef NJET + /* No 16-bit support beyond reading with strip_16 */ +#endif + +#define PNG_NO_GLOBAL_ARRAYS + +#define PNG_NO_WARNINGS +#define png_warning(s1,s2) "" +#define png_chunk_warning(s1,s2) "" +#define PNG_NO_ERROR_TEXT +#define png_error(s1,s2) png_err(s1) +#define png_chunk_error(s1,s2) png_err(s1) + +#define PNG_NO_ASSEMBLER_CODE +#define PNG_NO_OPTIMIZED_CODE +#define PNG_NO_READ_GAMMA +#define PNG_NO_READ_BACKGROUND +#define PNG_NO_READ_DITHER +#define PNG_NO_READ_INVERT +#define PNG_NO_READ_SHIFT +#define PNG_NO_READ_PACK +#define PNG_NO_READ_PACKSWAP +#define PNG_NO_READ_FILLER +#define PNG_NO_READ_SWAP +#define PNG_NO_READ_SWAP_ALPHA +#define PNG_NO_READ_INVERT_ALPHA +#define PNG_NO_READ_RGB_TO_GRAY +#define PNG_NO_READ_USER_TRANSFORM +#define PNG_NO_READ_bKGD +#define PNG_NO_READ_cHRM +#define PNG_NO_READ_gAMA +#define PNG_NO_READ_hIST +#define PNG_NO_READ_iCCP +#define PNG_NO_READ_pCAL +#define PNG_NO_READ_pHYs +#define PNG_NO_READ_sBIT +#define PNG_NO_READ_sCAL +#define PNG_NO_READ_sPLT +#define PNG_NO_READ_sRGB +#define PNG_NO_READ_TEXT +#define PNG_NO_READ_tIME +#define PNG_NO_READ_UNKNOWN_CHUNKS +#define PNG_NO_READ_USER_CHUNKS +#define PNG_NO_READ_EMPTY_PLTE +#define PNG_NO_READ_OPT_PLTE +#define PNG_NO_READ_STRIP_ALPHA +#define PNG_NO_READ_oFFs +#define PNG_NO_WARN_UNINITIALIZED_ROW + +#define PNG_NO_WRITE_SUPPORTED + +#define PNG_NO_INFO_IMAGE +#define PNG_NO_USER_MEM +#define PNG_NO_FIXED_POINT_SUPPORTED +#define PNG_NO_MNG_FEATURES +#define PNG_NO_USER_TRANSFORM_PTR +#define PNG_NO_HANDLE_AS_UNKNOWN +#define PNG_NO_CONSOLE_IO +#define PNG_NO_ZALLOC_ZERO +#define PNG_NO_ERROR_NUMBERS +#define PNG_NO_EASY_ACCESS +#define PNG_NO_PROGRESSIVE_READ + +#endif /* MINRDPNGCONF_H */ diff --git a/libs/libpng-src/contrib/pngminim/encoder/README b/libs/libpng-src/contrib/pngminim/encoder/README new file mode 100644 index 000000000..2285544f4 --- /dev/null +++ b/libs/libpng-src/contrib/pngminim/encoder/README @@ -0,0 +1,9 @@ +This demonstrates the use of PNG_USER_CONFIG and pngusr.h + +To build a minimal write-only decoder with embedded libpng and zlib, run + + gather.sh # to collect needed files from pngminus, libpng, and zlib + make + +If you prefer to use the shared libraries, go to contrib/pngminus +and build the pnm2png application there. diff --git a/libs/libpng-src/contrib/pngminim/encoder/dummy_inflate.c b/libs/libpng-src/contrib/pngminim/encoder/dummy_inflate.c new file mode 100644 index 000000000..1422edb43 --- /dev/null +++ b/libs/libpng-src/contrib/pngminim/encoder/dummy_inflate.c @@ -0,0 +1,27 @@ +#include "zlib.h" + +int ZEXPORT inflate(strm, flush) +z_streamp strm; +int flush; +{ return Z_OK ; } + +int ZEXPORT inflateReset(strm) +z_streamp strm; +{ return Z_OK ; } + +int ZEXPORT inflateEnd(strm) +z_streamp strm; +{ return Z_STREAM_ERROR ; } + +int ZEXPORT inflateInit_(strm, version, stream_size) +z_streamp strm; +const char *version; +int stream_size; +{ return Z_OK ; } + +int ZEXPORT inflateInit2_(strm, windowBits, version, stream_size) +z_streamp strm; +int windowBits; +const char *version; +int stream_size; +{ return Z_STREAM_ERROR ; } diff --git a/libs/libpng-src/contrib/pngminim/encoder/gather.sh b/libs/libpng-src/contrib/pngminim/encoder/gather.sh new file mode 100755 index 000000000..61d0b13ef --- /dev/null +++ b/libs/libpng-src/contrib/pngminim/encoder/gather.sh @@ -0,0 +1,10 @@ +cp ../../pngminus/pnm2png.c pnm2pngm.c +cp ../../../*.h . +cp ../../../*.c . +rm pnggccrd.c pngvcrd.c +rm example.c pngtest.c pngr*.c pngpread.c +# Change the next 2 lines if zlib is somewhere else. +cp ../../../../zlib/*.h . +cp ../../../../zlib/*.c . +rm inf*.[ch] +rm minigzip.c example.c gz* diff --git a/libs/libpng-src/contrib/pngminim/encoder/makefile b/libs/libpng-src/contrib/pngminim/encoder/makefile new file mode 100644 index 000000000..dfde950ec --- /dev/null +++ b/libs/libpng-src/contrib/pngminim/encoder/makefile @@ -0,0 +1,43 @@ +# Makefile for PngMinus (pnm2pngm) +# Linux / Unix + +#CC=cc +CC=gcc +LD=$(CC) + +RM=rm -f + +CFLAGS=-DPNG_USER_CONFIG -DNO_GZIP -I. -O1 + +C=.c +O=.o +L=.a +E= + +ZOBJS = adler32$(O) compress$(O) crc32$(O) deflate$(O) \ + dummy_inflate$(O) \ + trees$(O) uncompr$(O) zutil$(O) + +OBJS = pnm2pngm$(O) png$(O) pngerror$(O) pngget$(O) pngmem$(O) \ + pngset$(O) pngtrans$(O) pngwio$(O) pngwrite$(O) \ + pngwtran$(O) pngwutil$(O) $(ZOBJS) + +# implicit make rules ------------------------------------------------------- + +.c$(O): png.h pngconf.h pngusr.h zlib.h + $(CC) -c $(CFLAGS) $< + +# dependencies + +all: pnm2pngm$(E) + +pnm2pngm$(E): $(OBJS) + $(LD) -o pnm2pngm$(E) $(OBJS) + strip pnm2pngm$(E) + +clean: + $(RM) pnm2pngm$(O) + $(RM) pnm2pngm$(E) + $(RM) $(OBJS) + +# End of makefile for pnm2pngm diff --git a/libs/libpng-src/contrib/pngminim/encoder/pngusr.h b/libs/libpng-src/contrib/pngminim/encoder/pngusr.h new file mode 100644 index 000000000..c98b547fc --- /dev/null +++ b/libs/libpng-src/contrib/pngminim/encoder/pngusr.h @@ -0,0 +1,73 @@ +/* minwrpngconf.h: headers to make a minimal png-write-only library + * + * Copyright (c) 2007, 2009 Glenn Randers-Pehrson + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + * + * Derived from pngcrush.h, Copyright 1998-2007, Glenn Randers-Pehrson + */ + +#ifndef MINWRPNGCONF_H +#define MINWRPNGCONF_H + +#define PNG_NO_GLOBAL_ARRAYS + +#define PNG_NO_READ_SUPPORTED + +#define PNG_NO_WARNINGS +#define png_warning(s1,s2) "" +#define png_chunk_warning(s1,s2) "" +#define PNG_NO_ERROR_TEXT +#define png_error(s1,s2) png_err(s1) +#define png_chunk_error(s1,s2) png_err(s1) + +#define PNG_NO_WRITE_BACKGROUND +#define PNG_NO_WRITE_GAMMA +#define PNG_NO_WRITE_DITHER +#define PNG_NO_WRITE_INVERT +#define PNG_NO_WRITE_SHIFT +#define PNG_NO_WRITE_PACK +#define PNG_NO_WRITE_PACKSWAP +#define PNG_NO_WRITE_FILLER +#define PNG_NO_WRITE_SWAP +#define PNG_NO_WRITE_SWAP_ALPHA +#define PNG_NO_WRITE_INVERT_ALPHA +#define PNG_NO_WRITE_RGB_TO_GRAY +#define PNG_NO_WRITE_USER_TRANSFORM +#define PNG_NO_WRITE_bKGD +#define PNG_NO_WRITE_cHRM +#define PNG_NO_WRITE_gAMA +#define PNG_NO_WRITE_hIST +#define PNG_NO_WRITE_iCCP +#define PNG_NO_WRITE_oFFs +#define PNG_NO_WRITE_pCAL +#define PNG_NO_WRITE_pHYs +#define PNG_NO_WRITE_sBIT +#define PNG_NO_WRITE_sCAL +#define PNG_NO_WRITE_sPLT +#define PNG_NO_WRITE_sRGB +#define PNG_NO_WRITE_TEXT +#define PNG_NO_WRITE_tIME +#define PNG_NO_WRITE_UNKNOWN_CHUNKS +#define PNG_NO_WRITE_USER_CHUNKS +#define PNG_NO_WRITE_EMPTY_PLTE +#define PNG_NO_WRITE_OPT_PLTE +#define PNG_NO_WRITE_FILTER +#define PNG_NO_WRITE_WEIGHTED_FILTER +#define PNG_NO_WRITE_INTERLACING_SUPPORTED +#define PNG_NO_WRITE_FLUSH + +#define PNG_NO_INFO_IMAGE +#define PNG_NO_USER_MEM +#define PNG_NO_FIXED_POINT_SUPPORTED +#define PNG_NO_MNG_FEATURES +#define PNG_NO_USER_TRANSFORM_PTR +#define PNG_NO_HANDLE_AS_UNKNOWN +#define PNG_NO_CONSOLE_IO +#define PNG_NO_ZALLOC_ZERO +#define PNG_NO_ERROR_NUMBERS +#define PNG_NO_EASY_ACCESS + +#endif /* MINWRPNGCONF_H */ diff --git a/libs/libpng-src/contrib/pngminim/preader/README b/libs/libpng-src/contrib/pngminim/preader/README new file mode 100644 index 000000000..377d641ad --- /dev/null +++ b/libs/libpng-src/contrib/pngminim/preader/README @@ -0,0 +1,14 @@ +This demonstrates the use of PNG_USER_CONFIG and pngusr.h + +To build a minimal read-only progressive decoder embedded libpng and +zlib and with your system's X library, run + + gather.sh # to collect needed files from gregbook, libpng, and zlib + +Edit makefile if required, to find your X library and include files, +then + + make + +If you prefer to use the shared libraries, go to contrib/gregbook +and build the rpng2-x application there. diff --git a/libs/libpng-src/contrib/pngminim/preader/gather.sh b/libs/libpng-src/contrib/pngminim/preader/gather.sh new file mode 100755 index 000000000..357bb9a7d --- /dev/null +++ b/libs/libpng-src/contrib/pngminim/preader/gather.sh @@ -0,0 +1,10 @@ +cp ../../gregbook/rpng2-x.c ../../gregbook/readpng2.[ch] . +cp ../../gregbook/COPYING ../../gregbook/LICENSE . +cp ../../../*.h . +cp ../../../*.c . +rm pnggccrd.c pngvcrd.c +rm example.c pngtest.c pngw*.c +# change the following 2 lines if zlib is somewhere else +cp ../../../../zlib/*.h . +cp ../../../../zlib/*.c . +rm minigzip.c example.c compress.c deflate.c gz* diff --git a/libs/libpng-src/contrib/pngminim/preader/makefile b/libs/libpng-src/contrib/pngminim/preader/makefile new file mode 100644 index 000000000..717978d5f --- /dev/null +++ b/libs/libpng-src/contrib/pngminim/preader/makefile @@ -0,0 +1,60 @@ +# Makefile for PngMinus (rpng2) +# Linux / Unix + +#CC=cc +CC=gcc +LD=$(CC) + +RM=rm -f + +#XINC = -I/usr/include # old-style, stock X distributions +#XLIB = -L/usr/lib/X11 -lX11 # (including SGI IRIX) + +#XINC = -I/usr/openwin/include # Sun workstations (OpenWindows) +#XLIB = -L/usr/openwin/lib -lX11 + +XINC = -I/usr/X11R6/include # new X distributions (X.org, etc.) +XLIB = -L/usr/X11R6/lib -lX11 +#XLIB = -L/usr/X11R6/lib64 -lX11 # e.g., Red Hat on AMD64 + +#XINC = -I/usr/local/include # FreeBSD +#XLIB = -L/usr/local/lib -lX11 + +#LIBS = $(XLIB) +LIBS = $(XLIB) -lm #platforms that need libm + +CFLAGS=-DPNG_USER_CONFIG -DNO_GZCOMPRESS -DNO_GZIP \ + -DdeflateParams\(a,b,c\)=Z_OK -I. $(XINC) -O1 + +C=.c +O=.o +L=.a +E= + +ZOBJS = adler32$(O) crc32$(O) \ + infback$(O) inffast$(O) inflate$(O) inftrees$(O) \ + trees$(O) uncompr$(O) zutil$(O) + +OBJS = rpng2-x$(O) readpng2$(O) png$(O) pngerror$(O) pngget$(O) pngmem$(O) \ + pngpread$(O) pngread$(O) pngrio$(O) pngrtran$(O) pngrutil$(O) \ + pngset$(O) pngtrans$(O) $(ZOBJS) + +# implicit make rules ------------------------------------------------------- + +.c$(O): png.h pngconf.h readpng2.h pngusr.h zlib.h + $(CC) -c $(CFLAGS) $< + +# dependencies + +all: rpng2-x$(E) + +rpng2-x$(E): $(OBJS) + $(LD) -o rpng2-x$(E) $(OBJS) $(LIBS) + strip rpng2-x$(E) + +clean: + $(RM) rpng2-x$(O) + $(RM) rpng2-x$(E) + $(RM) $(OBJS) + +# End of makefile for rpng2-x diff --git a/libs/libpng-src/contrib/pngminim/preader/pngusr.h b/libs/libpng-src/contrib/pngminim/preader/pngusr.h new file mode 100644 index 000000000..7d728c814 --- /dev/null +++ b/libs/libpng-src/contrib/pngminim/preader/pngusr.h @@ -0,0 +1,68 @@ +/* minrdpngconf.h: headers to make a minimal png-read-only library + * + * Copyright (c) 2009 Glenn Randers-Pehrson + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + * + * Derived from pngcrush.h, Copyright 1998-2007, Glenn Randers-Pehrson + */ + +#ifndef MINPRDPNGCONF_H +#define MINPRDPNGCONF_H + +#define PNG_NO_GLOBAL_ARRAYS + +#define PNG_NO_WARNINGS +#define png_warning(s1,s2) "" +#define png_chunk_warning(s1,s2) "" +#define PNG_NO_ERROR_TEXT +#define png_error(s1,s2) png_err(s1) +#define png_chunk_error(s1,s2) png_err(s1) + +#define PNG_NO_ASSEMBLER_CODE +#define PNG_NO_OPTIMIZED_CODE +#define PNG_NO_READ_DITHER +#define PNG_NO_READ_INVERT +#define PNG_NO_READ_SHIFT +#define PNG_NO_READ_PACK +#define PNG_NO_READ_PACKSWAP +#define PNG_NO_READ_FILLER +#define PNG_NO_READ_SWAP +#define PNG_NO_READ_SWAP_ALPHA +#define PNG_NO_READ_INVERT_ALPHA +#define PNG_NO_READ_RGB_TO_GRAY +#define PNG_NO_READ_USER_TRANSFORM +#define PNG_NO_READ_cHRM +#define PNG_NO_READ_hIST +#define PNG_NO_READ_iCCP +#define PNG_NO_READ_pCAL +#define PNG_NO_READ_pHYs +#define PNG_NO_READ_sBIT +#define PNG_NO_READ_sCAL +#define PNG_NO_READ_sPLT +#define PNG_NO_READ_TEXT +#define PNG_NO_READ_tIME +#define PNG_NO_READ_UNKNOWN_CHUNKS +#define PNG_NO_READ_USER_CHUNKS +#define PNG_NO_READ_EMPTY_PLTE +#define PNG_NO_READ_OPT_PLTE +#define PNG_NO_READ_STRIP_ALPHA +#define PNG_NO_READ_oFFs +#define PNG_NO_WARN_UNINITIALIZED_ROW + +#define PNG_NO_WRITE_SUPPORTED + +#define PNG_NO_INFO_IMAGE +#define PNG_NO_USER_MEM +#define PNG_NO_FIXED_POINT_SUPPORTED +#define PNG_NO_MNG_FEATURES +#define PNG_NO_USER_TRANSFORM_PTR +#define PNG_NO_HANDLE_AS_UNKNOWN +#define PNG_NO_CONSOLE_IO +#define PNG_NO_ZALLOC_ZERO +#define PNG_NO_ERROR_NUMBERS +#define PNG_NO_EASY_ACCESS + +#endif /* MINPRDPNGCONF_H */ diff --git a/libs/libpng-src/contrib/pngminus/README b/libs/libpng-src/contrib/pngminus/README new file mode 100644 index 000000000..bbe7407ec --- /dev/null +++ b/libs/libpng-src/contrib/pngminus/README @@ -0,0 +1,153 @@ +PngMinus +-------- +(copyright Willem van Schaik, 1999) + + +License +------- + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby granted, +provided that the above copyright notice appear in all copies and +that both that copyright notice and this permission notice appear in +supporting documentation. This software is provided "as is" without +express or implied warranty. + + +Some history +------------ +Soon after the creation of PNG in 1995, the need was felt for a set of +pnmtopng / pngtopnm utilities. Independantly Alexander Lehmann and I +(Willem van Schaik) started such a project. Luckily we discovered this +and merged the two together into pnmtopng.tar.gz, which is available +from a/o ftp://ftp.simplesystems.org/pub/libpng/png/. + +These two utilities have many, many options and make use of most of the +features of PNG, like gamma, alpha, sbit, text-chunks, etc. This makes +the utilities quite complex and by now not anymore very maintainable. +When we wrote these programs, libpng was still in an early stage. +Therefore, lots of the functionality that we put in our software can now +be done using transform-functions in libpng. + +Finally, to compile these programs, you need to have installed and +compiled three libraries: libpng, zlib and netpbm. Especially the latter +makes the whole setup a bit bulky. But that's unavoidable given the many +features of pnmtopng. + + +What now +-------- +At this moment libpng is in a very stable state and can do much of the +work done in pnmtopng. Also, pnmtopng needs to be upgraded to the new +interface of libpng. Hence, it is time for a rewrite from the ground up +of pnmtopng and pngtopnm. This will happen in the near future (stay +tuned). The new package will get a different name to distinguish it from +the old one: PngPlus. + +To experiment a bit with the new interface of libpng, I started off with +a small prototype that contains only the basic functionality. It doesn't +have any of the options to read or write special chunks and it will do +no gamma correction. But this makes it also a simple program that is +quite easy to understand and can serve well as a template for other +software developments. (By now there are of course a couple of programs, +like Greg Roelofs' rpng/wpng, that can be used just as good.) + + +Can and can not +--------------- +As this is the small brother of the future PngPlus, I called this fellow +PngMinus. Because I started this development in good-old Turbo-C, I +avoided the use the netpbm library, which requires DOS extenders. Again, +another reason to call it PngMinus (minus netpbm :-). So, part of the +program are some elementary routines to read / write pgm- and ppm-files. +It does not read b&w pbm-files. + +The downside of this approach is that you can not use them on images +that require blocks of memory bigger than 64k (the DOS version). For +larger images you will get an out-of-memory error. + +As said before, PngMinus doesn't correct for gamma. When reading +png-files you can do this just as well by piping the output of png2pnm +to pnmgamma, one of the standard PbmPlus tools. This same scenario will +most probably also be followed in the full-blown future PngPlus, with +the addition of course of the possibility to create gamma-chunks when +writing png-files. + +On the other hand it supports alpha-channels. When reading a png-image +you can write the alpha-channel into a pgm-file. And when creating an +RGB+A png-image, you just combine a ppm-file with a corresponding +pgm-file containing the alpha-channel. When reading, transparency chunks +are converted into an alpha-channel and from there on treated the same +way. + +Finally you can opt for writing ascii or binary pgm- and ppm-files. When +the bit-depth is 16, the format will always be ascii. + + +Using it +-------- +To distinguish them from pnmtopng and PngPlus, the utilities are named +png2pnm and pnm2png (2 instead of to). The input- and output-files can +be given as parameters or through redirection. Therefore the programs +can be part of a pipe. + +To list the options type "png2pnm -h" or "pnm2png -h". + + +Just like Scandinavian furniture +-------------------------------- +You have to put it together yourself. I did test the software under +MS-DOS with Turbo-C 3.0 and under RedHat Linux 4.2 with gcc. In both +cases I used libpng-1.0.4 and zlib-1.1.3. Later versions should be OK, +however some older libpng versions have a bug in pngmem.c when using +Turbo-C 3.0 (see below). + +You can build it using one of the two makefiles (make -f makefile.###) +or use the batch/script files pngminus.bat / pngminus.sh. This assumes +that you have built the libraries in ../libpng and ../zlib. Using Linux, +make sure that you have built libpng with makefile.std and not +makefile.linux (also called .lnx in earlier versions of libpng). The +latter creates a .so shared-library, while the PngMinus makefile assumes +a normal .a static library. + +If you create a ../pngsuite directory and then store the basn####.png +files from PngSuite (http://www.schaik.com/pngsuite/) in there, you can +test in one go the proper functioning of PngMinus, see png2pnm.bat and +pnm2png.bat (or the .sh versions). + + +Warranty +------- +Please, remember that this was just a small experiment to learn a few +things. It will have many unforeseen features . Who said bugs? Use +it when you are in need for something simple or when you want to start +developing your own stuff. + + +The Turbo bug +------------- +** pngmem.old + hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L); + hptr += 16L; +** pngmem.c + hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L); + hptr = hptr + 16L; +** + +** pngmem.old + png_ptr->offset_table_ptr[i] = (png_bytep)hptr; + hptr += (png_uint_32)65536L; +** pngmem.c + png_ptr->offset_table_ptr[i] = (png_bytep)hptr; + hptr = hptr + 65536L; +** + + +The end +------- +Willem van Schaik +mailto:willem@schaik.com +http://www.schaik.com/png/ +------- +Oct 1999 + diff --git a/libs/libpng-src/contrib/pngminus/makefile.std b/libs/libpng-src/contrib/pngminus/makefile.std new file mode 100644 index 000000000..2fb061bbe --- /dev/null +++ b/libs/libpng-src/contrib/pngminus/makefile.std @@ -0,0 +1,65 @@ +# Makefile for PngMinus (png2pnm and pnm2png) +# Linux / Unix + +#CC=cc +CC=gcc +LD=$(CC) + +RM=rm -f + +#PNGPATH = /usr/local +#PNGINC = -I$(PNGPATH)/include/libpng12 +#PNGLIB = -L$(PNGPATH)/lib -lpng12 +#PNGLIBS = $(PNGPATH)/lib/libpng12.a +PNGINC = -I../.. +PNGLIB = -L../.. -lpng +PNGLIBS = ../../libpng.a + +#ZPATH = /usr/local +#ZINC = -I$(ZPATH)/include +#ZLIB = -L$(ZPATH)/lib -lz +#ZLIBS = $(ZPATH)/lib/libz.a +ZINC = -I../../../zlib +ZLIB = -L../../../zlib -lz +ZLIBS = ../../../zlib/libz.a + +CFLAGS=-O3 $(PNGINC) $(ZINC) +LDFLAGS=$(PNGLIB) $(ZLIB) +LDFLAGSS=$(PNGLIBS) $(ZLIBS) +C=.c +O=.o +L=.a +E= + +# dependencies + +#all: png2pnm$(E) pnm2png$(E) +all: png2pnm$(E) pnm2png$(E) png2pnm-static$(E) pnm2png-static$(E) + +png2pnm$(O): png2pnm$(C) + $(CC) -c $(CFLAGS) png2pnm$(C) + +png2pnm$(E): png2pnm$(O) + $(LD) -o png2pnm$(E) png2pnm$(O) $(LDFLAGS) -lm + +png2pnm-static$(E): png2pnm$(O) + $(LD) -o png2pnm-static$(E) png2pnm$(O) $(LDFLAGSS) -lm + +pnm2png$(O): pnm2png$(C) + $(CC) -c $(CFLAGS) pnm2png$(C) + +pnm2png$(E): pnm2png$(O) + $(LD) -o pnm2png$(E) pnm2png$(O) $(LDFLAGS) -lm + +pnm2png-static$(E): pnm2png$(O) + $(LD) -o pnm2png-static$(E) pnm2png$(O) $(LDFLAGSS) -lm + +clean: + $(RM) png2pnm$(O) + $(RM) pnm2png$(O) + $(RM) png2pnm$(E) + $(RM) pnm2png$(E) + $(RM) png2pnm-static$(E) + $(RM) pnm2png-static$(E) + +# End of makefile for png2pnm / pnm2png diff --git a/libs/libpng-src/contrib/pngminus/makefile.tc3 b/libs/libpng-src/contrib/pngminus/makefile.tc3 new file mode 100644 index 000000000..404f18d5b --- /dev/null +++ b/libs/libpng-src/contrib/pngminus/makefile.tc3 @@ -0,0 +1,38 @@ +# Makefile for PngMinus (png2pnm and pnm2png) +# TurboC++ 3.0 + +CC=tcc -Ic:\tc3\inc +LD=tcc -Lc:\tc3\lib +LB=tlib +RM=del +CP=copy +MODEL=l +CCFLAGS=-O -m$(MODEL) -I..\libpng -I..\zlib +LDFLAGS=-m$(MODEL) -L..\libpng -L..\zlib +C=.c +O=.obj +L=.lib +E=.exe + +# dependencies + +all: png2pnm$(E) pnm2png$(E) + +png2pnm$(O): png2pnm$(C) + $(CC) -c $(CCFLAGS) png2pnm$(C) + +png2pnm$(E): png2pnm$(O) + $(LD) $(LDFLAGS) png2pnm$(O) libpng$(L) zlib$(L) + +pnm2png$(O): pnm2png$(C) + $(CC) -c $(CCFLAGS) pnm2png$(C) + +pnm2png$(E): pnm2png$(O) + $(LD) $(LDFLAGS) pnm2png$(O) libpng$(L) zlib$(L) + +clean: + $(RM) *$(O) + $(RM) *$(E) + +# End of makefile for png2pnm / pnm2png + diff --git a/libs/libpng-src/contrib/pngminus/makevms.com b/libs/libpng-src/contrib/pngminus/makevms.com new file mode 100644 index 000000000..00561bcd0 --- /dev/null +++ b/libs/libpng-src/contrib/pngminus/makevms.com @@ -0,0 +1,92 @@ +$!------------------------------------------------------------------------------ +$! make Contrib programs of libpng under OpenVMS +$! +$! +$! Look for the compiler used +$! +$ zlibsrc = "[---.zlib]" +$ ccopt="/include=(''zlibsrc',[--])" +$ if f$getsyi("HW_MODEL").ge.1024 +$ then +$ ccopt = "/prefix=all"+ccopt +$ comp = "__decc__=1" +$ if f$trnlnm("SYS").eqs."" then define sys sys$library: +$ else +$ if f$search("SYS$SYSTEM:DECC$COMPILER.EXE").eqs."" +$ then +$ if f$trnlnm("SYS").eqs."" then define sys sys$library: +$ if f$search("SYS$SYSTEM:VAXC.EXE").eqs."" +$ then +$ comp = "__gcc__=1" +$ CC :== GCC +$ else +$ comp = "__vaxc__=1" +$ endif +$ else +$ if f$trnlnm("SYS").eqs."" then define sys decc$library_include: +$ ccopt = "/decc/prefix=all"+ccopt +$ comp = "__decc__=1" +$ endif +$ endif +$ open/write lopt lib.opt +$ write lopt "[--]libpng.olb/lib" +$ write lopt "''zlibsrc'libz.olb/lib" +$ close lopt +$ open/write xopt x11.opt +$ write xopt "sys$library:decw$xlibshr.exe/share" +$ close xopt +$ write sys$output "Compiling PNG contrib programs ..." +$ write sys$output "Building pnm2png..." +$ CALL MAKE pnm2png.OBJ "cc ''CCOPT' pnm2png" - + pnm2png.c +$ call make pnm2png.exe - + "LINK pnm2png,lib.opt/opt" - + pnm2png.obj +$ write sys$output "Building png2pnm..." +$ CALL MAKE png2pnm.OBJ "cc ''CCOPT' png2pnm" - + png2pnm.c +$ call make png2pnm.exe - + "LINK png2pnm,lib.opt/opt" - + png2pnm.obj +$ exit +$! +$! +$MAKE: SUBROUTINE !SUBROUTINE TO CHECK DEPENDENCIES +$ V = 'F$Verify(0) +$! P1 = What we are trying to make +$! P2 = Command to make it +$! P3 - P8 What it depends on +$ +$ If F$Search(P1) .Eqs. "" Then Goto Makeit +$ Time = F$CvTime(F$File(P1,"RDT")) +$arg=3 +$Loop: +$ Argument = P'arg +$ If Argument .Eqs. "" Then Goto Exit +$ El=0 +$Loop2: +$ File = F$Element(El," ",Argument) +$ If File .Eqs. " " Then Goto Endl +$ AFile = "" +$Loop3: +$ OFile = AFile +$ AFile = F$Search(File) +$ If AFile .Eqs. "" .Or. AFile .Eqs. OFile Then Goto NextEl +$ If F$CvTime(F$File(AFile,"RDT")) .Ges. Time Then Goto Makeit +$ Goto Loop3 +$NextEL: +$ El = El + 1 +$ Goto Loop2 +$EndL: +$ arg=arg+1 +$ If arg .Le. 8 Then Goto Loop +$ Goto Exit +$ +$Makeit: +$ VV=F$VERIFY(0) +$ write sys$output P2 +$ 'P2 +$ VV='F$Verify(VV) +$Exit: +$ If V Then Set Verify +$ENDSUBROUTINE diff --git a/libs/libpng-src/contrib/pngminus/png2pnm.bat b/libs/libpng-src/contrib/pngminus/png2pnm.bat new file mode 100644 index 000000000..85abe3cbb --- /dev/null +++ b/libs/libpng-src/contrib/pngminus/png2pnm.bat @@ -0,0 +1,41 @@ +REM -- grayscale +png2pnm.exe -noraw ..\pngsuite\basn0g01.png basn0g01.pgm +png2pnm.exe -noraw ..\pngsuite\basn0g02.png basn0g02.pgm +png2pnm.exe -noraw ..\pngsuite\basn0g04.png basn0g04.pgm +png2pnm.exe -noraw ..\pngsuite\basn0g08.png basn0g08.pgm +png2pnm.exe -noraw ..\pngsuite\basn0g16.png basn0g16.pgm +REM -- full-color +png2pnm.exe -noraw ..\pngsuite\basn2c08.png basn2c08.ppm +png2pnm.exe -noraw ..\pngsuite\basn2c16.png basn2c16.ppm +REM -- palletted +png2pnm.exe -noraw ..\pngsuite\basn3p01.png basn3p01.ppm +png2pnm.exe -noraw ..\pngsuite\basn3p02.png basn3p02.ppm +png2pnm.exe -noraw ..\pngsuite\basn3p04.png basn3p04.ppm +png2pnm.exe -noraw ..\pngsuite\basn3p08.png basn3p08.ppm +REM -- gray with alpha-channel +png2pnm.exe -noraw ..\pngsuite\basn4a08.png basn4a08.pgm +png2pnm.exe -noraw ..\pngsuite\basn4a16.png basn4a16.pgm +REM -- color with alpha-channel +png2pnm.exe -noraw -alpha basn6a08.pgm ..\pngsuite\basn6a08.png basn6a08.ppm +png2pnm.exe -noraw -alpha basn6a16.pgm ..\pngsuite\basn6a16.png basn6a16.ppm +REM -- grayscale +png2pnm.exe -raw ..\pngsuite\basn0g01.png rawn0g01.pgm +png2pnm.exe -raw ..\pngsuite\basn0g02.png rawn0g02.pgm +png2pnm.exe -raw ..\pngsuite\basn0g04.png rawn0g04.pgm +png2pnm.exe -raw ..\pngsuite\basn0g08.png rawn0g08.pgm +png2pnm.exe -raw ..\pngsuite\basn0g16.png rawn0g16.pgm +REM -- full-color +png2pnm.exe -raw ..\pngsuite\basn2c08.png rawn2c08.ppm +png2pnm.exe -raw ..\pngsuite\basn2c16.png rawn2c16.ppm +REM -- palletted +png2pnm.exe -raw ..\pngsuite\basn3p01.png rawn3p01.ppm +png2pnm.exe -raw ..\pngsuite\basn3p02.png rawn3p02.ppm +png2pnm.exe -raw ..\pngsuite\basn3p04.png rawn3p04.ppm +png2pnm.exe -raw ..\pngsuite\basn3p08.png rawn3p08.ppm +REM -- gray with alpha-channel +png2pnm.exe -raw ..\pngsuite\basn4a08.png rawn4a08.pgm +png2pnm.exe -raw ..\pngsuite\basn4a16.png rawn4a16.pgm +REM -- color with alpha-channel +png2pnm.exe -noraw -alpha rawn6a08.pgm ..\pngsuite\basn6a08.png rawn6a08.ppm +png2pnm.exe -noraw -alpha rawn6a16.pgm ..\pngsuite\basn6a16.png rawn6a16.ppm + diff --git a/libs/libpng-src/contrib/pngminus/png2pnm.c b/libs/libpng-src/contrib/pngminus/png2pnm.c new file mode 100644 index 000000000..ac295aafa --- /dev/null +++ b/libs/libpng-src/contrib/pngminus/png2pnm.c @@ -0,0 +1,430 @@ +/* + * png2pnm.c --- conversion from PNG-file to PGM/PPM-file + * copyright (C) 1999 by Willem van Schaik + * + * version 1.0 - 1999.10.15 - First version. + * + * Permission to use, copy, modify, and distribute this software and + * its documentation for any purpose and without fee is hereby granted, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear in + * supporting documentation. This software is provided "as is" without + * express or implied warranty. + */ + +#include +#include +#ifdef __TURBOC__ +#include +#include +#endif + +#ifndef BOOL +#define BOOL unsigned char +#endif +#ifndef TRUE +#define TRUE (BOOL) 1 +#endif +#ifndef FALSE +#define FALSE (BOOL) 0 +#endif + +#ifdef __TURBOC__ +#define STDIN 0 +#define STDOUT 1 +#define STDERR 2 +#endif + +/* to make png2pnm verbose so we can find problems (needs to be before png.h) */ +#ifndef PNG_DEBUG +#define PNG_DEBUG 0 +#endif + +#include "png.h" + +/* Define png_jmpbuf() in case we are using a pre-1.0.6 version of libpng */ +#ifndef png_jmpbuf +# define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf) +#endif + +/* function prototypes */ + +int main (int argc, char *argv[]); +void usage (); +BOOL png2pnm (FILE *png_file, FILE *pnm_file, FILE *alpha_file, BOOL raw, BOOL alpha); + +/* + * main + */ + +int main(int argc, char *argv[]) +{ + FILE *fp_rd = stdin; + FILE *fp_wr = stdout; + FILE *fp_al = NULL; + BOOL raw = TRUE; + BOOL alpha = FALSE; + int argi; + + for (argi = 1; argi < argc; argi++) + { + if (argv[argi][0] == '-') + { + switch (argv[argi][1]) + { + case 'n': + raw = FALSE; + break; + case 'r': + raw = TRUE; + break; + case 'a': + alpha = TRUE; + argi++; + if ((fp_al = fopen (argv[argi], "wb")) == NULL) + { + fprintf (stderr, "PNM2PNG\n"); + fprintf (stderr, "Error: can not create alpha-channel file %s\n", argv[argi]); + exit (1); + } + break; + case 'h': + case '?': + usage(); + exit(0); + break; + default: + fprintf (stderr, "PNG2PNM\n"); + fprintf (stderr, "Error: unknown option %s\n", argv[argi]); + usage(); + exit(1); + break; + } /* end switch */ + } + else if (fp_rd == stdin) + { + if ((fp_rd = fopen (argv[argi], "rb")) == NULL) + { + fprintf (stderr, "PNG2PNM\n"); + fprintf (stderr, "Error: file %s does not exist\n", argv[argi]); + exit (1); + } + } + else if (fp_wr == stdout) + { + if ((fp_wr = fopen (argv[argi], "wb")) == NULL) + { + fprintf (stderr, "PNG2PNM\n"); + fprintf (stderr, "Error: can not create file %s\n", argv[argi]); + exit (1); + } + } + else + { + fprintf (stderr, "PNG2PNM\n"); + fprintf (stderr, "Error: too many parameters\n"); + usage(); + exit(1); + } + } /* end for */ + +#ifdef __TURBOC__ + /* set stdin/stdout if required to binary */ + if (fp_rd == stdin) + { + setmode (STDIN, O_BINARY); + } + if ((raw) && (fp_wr == stdout)) + { + setmode (STDOUT, O_BINARY); + } +#endif + + /* call the conversion program itself */ + if (png2pnm (fp_rd, fp_wr, fp_al, raw, alpha) == FALSE) + { + fprintf (stderr, "PNG2PNM\n"); + fprintf (stderr, "Error: unsuccessful convertion of PNG-image\n"); + exit(1); + } + + /* close input file */ + fclose (fp_rd); + /* close output file */ + fclose (fp_wr); + /* close alpha file */ + if (alpha) + fclose (fp_al); + + return 0; +} + +/* + * usage + */ + +void usage() +{ + fprintf (stderr, "PNG2PNM\n"); + fprintf (stderr, " by Willem van Schaik, 1999\n"); +#ifdef __TURBOC__ + fprintf (stderr, " for Turbo-C and Borland-C compilers\n"); +#else + fprintf (stderr, " for Linux (and Unix) compilers\n"); +#endif + fprintf (stderr, "Usage: png2pnm [options] .png [.pnm]\n"); + fprintf (stderr, " or: ... | png2pnm [options]\n"); + fprintf (stderr, "Options:\n"); + fprintf (stderr, " -r[aw] write pnm-file in binary format (P4/P5/P6) (default)\n"); + fprintf (stderr, " -n[oraw] write pnm-file in ascii format (P1/P2/P3)\n"); + fprintf (stderr, " -a[lpha] .pgm write PNG alpha channel as pgm-file\n"); + fprintf (stderr, " -h | -? print this help-information\n"); +} + +/* + * png2pnm + */ + +BOOL png2pnm (FILE *png_file, FILE *pnm_file, FILE *alpha_file, BOOL raw, BOOL alpha) +{ + png_struct *png_ptr = NULL; + png_info *info_ptr = NULL; + png_byte buf[8]; + png_byte *png_pixels = NULL; + png_byte **row_pointers = NULL; + png_byte *pix_ptr = NULL; + png_uint_32 row_bytes; + + png_uint_32 width; + png_uint_32 height; + int bit_depth; + int channels; + int color_type; + int alpha_present; + int row, col; + int ret; + int i; + long dep_16; + + /* read and check signature in PNG file */ + ret = fread (buf, 1, 8, png_file); + if (ret != 8) + return FALSE; + + ret = !png_sig_cmp (buf, 0, 8); + if (!ret) + return FALSE; + + /* create png and info structures */ + + png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING, + NULL, NULL, NULL); + if (!png_ptr) + return FALSE; /* out of memory */ + + info_ptr = png_create_info_struct (png_ptr); + if (!info_ptr) + { + png_destroy_read_struct (&png_ptr, NULL, NULL); + return FALSE; /* out of memory */ + } + + if (setjmp (png_jmpbuf(png_ptr))) + { + png_destroy_read_struct (&png_ptr, &info_ptr, NULL); + return FALSE; + } + + /* set up the input control for C streams */ + png_init_io (png_ptr, png_file); + png_set_sig_bytes (png_ptr, 8); /* we already read the 8 signature bytes */ + + /* read the file information */ + png_read_info (png_ptr, info_ptr); + + /* get size and bit-depth of the PNG-image */ + png_get_IHDR (png_ptr, info_ptr, + &width, &height, &bit_depth, &color_type, + NULL, NULL, NULL); + + /* set-up the transformations */ + + /* transform paletted images into full-color rgb */ + if (color_type == PNG_COLOR_TYPE_PALETTE) + png_set_expand (png_ptr); + /* expand images to bit-depth 8 (only applicable for grayscale images) */ + if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) + png_set_expand (png_ptr); + /* transform transparency maps into full alpha-channel */ + if (png_get_valid (png_ptr, info_ptr, PNG_INFO_tRNS)) + png_set_expand (png_ptr); + +#ifdef NJET + /* downgrade 16-bit images to 8 bit */ + if (bit_depth == 16) + png_set_strip_16 (png_ptr); + /* transform grayscale images into full-color */ + if (color_type == PNG_COLOR_TYPE_GRAY || + color_type == PNG_COLOR_TYPE_GRAY_ALPHA) + png_set_gray_to_rgb (png_ptr); + /* only if file has a file gamma, we do a correction */ + if (png_get_gAMA (png_ptr, info_ptr, &file_gamma)) + png_set_gamma (png_ptr, (double) 2.2, file_gamma); +#endif + + /* all transformations have been registered; now update info_ptr data, + * get rowbytes and channels, and allocate image memory */ + + png_read_update_info (png_ptr, info_ptr); + + /* get the new color-type and bit-depth (after expansion/stripping) */ + png_get_IHDR (png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, + NULL, NULL, NULL); + + /* check for 16-bit files */ + if (bit_depth == 16) + { + raw = FALSE; +#ifdef __TURBOC__ + pnm_file->flags &= ~((unsigned) _F_BIN); +#endif + } + + /* calculate new number of channels and store alpha-presence */ + if (color_type == PNG_COLOR_TYPE_GRAY) + channels = 1; + else if (color_type == PNG_COLOR_TYPE_GRAY_ALPHA) + channels = 2; + else if (color_type == PNG_COLOR_TYPE_RGB) + channels = 3; + else if (color_type == PNG_COLOR_TYPE_RGB_ALPHA) + channels = 4; + else + channels = 0; /* should never happen */ + alpha_present = (channels - 1) % 2; + + /* check if alpha is expected to be present in file */ + if (alpha && !alpha_present) + { + fprintf (stderr, "PNG2PNM\n"); + fprintf (stderr, "Error: PNG-file doesn't contain alpha channel\n"); + exit (1); + } + + /* row_bytes is the width x number of channels x (bit-depth / 8) */ + row_bytes = png_get_rowbytes (png_ptr, info_ptr); + + if ((png_pixels = (png_byte *) malloc (row_bytes * height * sizeof (png_byte))) == NULL) { + png_destroy_read_struct (&png_ptr, &info_ptr, NULL); + return FALSE; + } + + if ((row_pointers = (png_byte **) malloc (height * sizeof (png_bytep))) == NULL) + { + png_destroy_read_struct (&png_ptr, &info_ptr, NULL); + free (png_pixels); + png_pixels = NULL; + return FALSE; + } + + /* set the individual row_pointers to point at the correct offsets */ + for (i = 0; i < (height); i++) + row_pointers[i] = png_pixels + i * row_bytes; + + /* now we can go ahead and just read the whole image */ + png_read_image (png_ptr, row_pointers); + + /* read rest of file, and get additional chunks in info_ptr - REQUIRED */ + png_read_end (png_ptr, info_ptr); + + /* clean up after the read, and free any memory allocated - REQUIRED */ + png_destroy_read_struct (&png_ptr, &info_ptr, (png_infopp) NULL); + + /* write header of PNM file */ + + if ((color_type == PNG_COLOR_TYPE_GRAY) || + (color_type == PNG_COLOR_TYPE_GRAY_ALPHA)) + { + fprintf (pnm_file, "%s\n", (raw) ? "P5" : "P2"); + fprintf (pnm_file, "%d %d\n", (int) width, (int) height); + fprintf (pnm_file, "%ld\n", ((1L << (int) bit_depth) - 1L)); + } + else if ((color_type == PNG_COLOR_TYPE_RGB) || + (color_type == PNG_COLOR_TYPE_RGB_ALPHA)) + { + fprintf (pnm_file, "%s\n", (raw) ? "P6" : "P3"); + fprintf (pnm_file, "%d %d\n", (int) width, (int) height); + fprintf (pnm_file, "%ld\n", ((1L << (int) bit_depth) - 1L)); + } + + /* write header of PGM file with alpha channel */ + + if ((alpha) && + ((color_type == PNG_COLOR_TYPE_GRAY_ALPHA) || + (color_type == PNG_COLOR_TYPE_RGB_ALPHA))) + { + fprintf (alpha_file, "%s\n", (raw) ? "P5" : "P2"); + fprintf (alpha_file, "%d %d\n", (int) width, (int) height); + fprintf (alpha_file, "%ld\n", ((1L << (int) bit_depth) - 1L)); + } + + /* write data to PNM file */ + pix_ptr = png_pixels; + + for (row = 0; row < height; row++) + { + for (col = 0; col < width; col++) + { + for (i = 0; i < (channels - alpha_present); i++) + { + if (raw) + fputc ((int) *pix_ptr++ , pnm_file); + else + if (bit_depth == 16){ + dep_16 = (long) *pix_ptr++; + fprintf (pnm_file, "%ld ", (dep_16 << 8) + ((long) *pix_ptr++)); + } + else + fprintf (pnm_file, "%ld ", (long) *pix_ptr++); + } + if (alpha_present) + { + if (!alpha) + { + pix_ptr++; /* alpha */ + if (bit_depth == 16) + pix_ptr++; + } + else /* output alpha-channel as pgm file */ + { + if (raw) + fputc ((int) *pix_ptr++ , alpha_file); + else + if (bit_depth == 16){ + dep_16 = (long) *pix_ptr++; + fprintf (alpha_file, "%ld ", (dep_16 << 8) + (long) *pix_ptr++); + } + else + fprintf (alpha_file, "%ld ", (long) *pix_ptr++); + } + } /* if alpha_present */ + + if (!raw) + if (col % 4 == 3) + fprintf (pnm_file, "\n"); + } /* end for col */ + + if (!raw) + if (col % 4 != 0) + fprintf (pnm_file, "\n"); + } /* end for row */ + + if (row_pointers != (unsigned char**) NULL) + free (row_pointers); + if (png_pixels != (unsigned char*) NULL) + free (png_pixels); + + return TRUE; + +} /* end of source */ + diff --git a/libs/libpng-src/contrib/pngminus/png2pnm.sh b/libs/libpng-src/contrib/pngminus/png2pnm.sh new file mode 100755 index 000000000..b1c05370d --- /dev/null +++ b/libs/libpng-src/contrib/pngminus/png2pnm.sh @@ -0,0 +1,42 @@ +#!/bin/sh +# -- grayscale +./png2pnm -noraw ../pngsuite/basn0g01.png basn0g01.pgm +./png2pnm -noraw ../pngsuite/basn0g02.png basn0g02.pgm +./png2pnm -noraw ../pngsuite/basn0g04.png basn0g04.pgm +./png2pnm -noraw ../pngsuite/basn0g08.png basn0g08.pgm +./png2pnm -noraw ../pngsuite/basn0g16.png basn0g16.pgm +# -- full-color +./png2pnm -noraw ../pngsuite/basn2c08.png basn2c08.ppm +./png2pnm -noraw ../pngsuite/basn2c16.png basn2c16.ppm +# -- palletted +./png2pnm -noraw ../pngsuite/basn3p01.png basn3p01.ppm +./png2pnm -noraw ../pngsuite/basn3p02.png basn3p02.ppm +./png2pnm -noraw ../pngsuite/basn3p04.png basn3p04.ppm +./png2pnm -noraw ../pngsuite/basn3p08.png basn3p08.ppm +# -- gray with alpha-channel +./png2pnm -noraw ../pngsuite/basn4a08.png basn4a08.pgm +./png2pnm -noraw ../pngsuite/basn4a16.png basn4a16.pgm +# -- color with alpha-channel +./png2pnm -noraw -alpha basn6a08.pgm ../pngsuite/basn6a08.png basn6a08.ppm +./png2pnm -noraw -alpha basn6a16.pgm ../pngsuite/basn6a16.png basn6a16.ppm +# -- grayscale +./png2pnm -raw ../pngsuite/basn0g01.png rawn0g01.pgm +./png2pnm -raw ../pngsuite/basn0g02.png rawn0g02.pgm +./png2pnm -raw ../pngsuite/basn0g04.png rawn0g04.pgm +./png2pnm -raw ../pngsuite/basn0g08.png rawn0g08.pgm +./png2pnm -raw ../pngsuite/basn0g16.png rawn0g16.pgm +# -- full-color +./png2pnm -raw ../pngsuite/basn2c08.png rawn2c08.ppm +./png2pnm -raw ../pngsuite/basn2c16.png rawn2c16.ppm +# -- palletted +./png2pnm -raw ../pngsuite/basn3p01.png rawn3p01.ppm +./png2pnm -raw ../pngsuite/basn3p02.png rawn3p02.ppm +./png2pnm -raw ../pngsuite/basn3p04.png rawn3p04.ppm +./png2pnm -raw ../pngsuite/basn3p08.png rawn3p08.ppm +# -- gray with alpha-channel +./png2pnm -raw ../pngsuite/basn4a08.png rawn4a08.pgm +./png2pnm -raw ../pngsuite/basn4a16.png rawn4a16.pgm +# -- color with alpha-channel +./png2pnm -noraw -alpha rawn6a08.pgm ../pngsuite/basn6a08.png rawn6a08.ppm +./png2pnm -noraw -alpha rawn6a16.pgm ../pngsuite/basn6a16.png rawn6a16.ppm + diff --git a/libs/libpng-src/contrib/pngminus/pngminus.bat b/libs/libpng-src/contrib/pngminus/pngminus.bat new file mode 100644 index 000000000..5f8d2d490 --- /dev/null +++ b/libs/libpng-src/contrib/pngminus/pngminus.bat @@ -0,0 +1,4 @@ +make -f makefile.tc3 +call png2pnm.bat +call pnm2png.bat + diff --git a/libs/libpng-src/contrib/pngminus/pngminus.sh b/libs/libpng-src/contrib/pngminus/pngminus.sh new file mode 100755 index 000000000..2a0a9d8fb --- /dev/null +++ b/libs/libpng-src/contrib/pngminus/pngminus.sh @@ -0,0 +1,5 @@ +#!/bin/sh +make -f makefile.std +sh png2pnm.sh +sh pnm2png.sh + diff --git a/libs/libpng-src/contrib/pngminus/pnm2png.bat b/libs/libpng-src/contrib/pngminus/pnm2png.bat new file mode 100644 index 000000000..5b9977a98 --- /dev/null +++ b/libs/libpng-src/contrib/pngminus/pnm2png.bat @@ -0,0 +1,41 @@ +REM -- grayscale +pnm2png.exe basn0g01.pgm basn0g01.png +pnm2png.exe basn0g02.pgm basn0g02.png +pnm2png.exe basn0g04.pgm basn0g04.png +pnm2png.exe basn0g08.pgm basn0g08.png +pnm2png.exe basn0g16.pgm basn0g16.png +REM -- full-color +pnm2png.exe basn2c08.ppm basn2c08.png +pnm2png.exe basn2c16.ppm basn2c16.png +REM -- palletted +pnm2png.exe basn3p01.ppm basn3p01.png +pnm2png.exe basn3p02.ppm basn3p02.png +pnm2png.exe basn3p04.ppm basn3p04.png +pnm2png.exe basn3p08.ppm basn3p08.png +REM -- gray with alpha-channel +pnm2png.exe -alpha basn6a08.pgm basn4a08.pgm basn4a08.png +pnm2png.exe -alpha basn6a16.pgm basn4a16.pgm basn4a16.png +REM -- color with alpha-channel +pnm2png.exe -alpha basn6a08.pgm basn6a08.ppm basn6a08.png +pnm2png.exe -alpha basn6a16.pgm basn6a16.ppm basn6a16.png +REM -- grayscale +pnm2png.exe rawn0g01.pgm rawn0g01.png +pnm2png.exe rawn0g02.pgm rawn0g02.png +pnm2png.exe rawn0g04.pgm rawn0g04.png +pnm2png.exe rawn0g08.pgm rawn0g08.png +pnm2png.exe rawn0g16.pgm rawn0g16.png +REM -- full-color +pnm2png.exe rawn2c08.ppm rawn2c08.png +pnm2png.exe rawn2c16.ppm rawn2c16.png +REM -- palletted +pnm2png.exe rawn3p01.ppm rawn3p01.png +pnm2png.exe rawn3p02.ppm rawn3p02.png +pnm2png.exe rawn3p04.ppm rawn3p04.png +pnm2png.exe rawn3p08.ppm rawn3p08.png +REM -- gray with alpha-channel +pnm2png.exe -alpha rawn6a08.pgm rawn4a08.pgm rawn4a08.png +pnm2png.exe -alpha rawn6a16.pgm rawn4a16.pgm rawn4a16.png +REM -- color with alpha-channel +pnm2png.exe -alpha rawn6a08.pgm rawn6a08.ppm rawn6a08.png +pnm2png.exe -alpha rawn6a16.pgm rawn6a16.ppm rawn6a16.png + diff --git a/libs/libpng-src/contrib/pngminus/pnm2png.c b/libs/libpng-src/contrib/pngminus/pnm2png.c new file mode 100644 index 000000000..4cdfad831 --- /dev/null +++ b/libs/libpng-src/contrib/pngminus/pnm2png.c @@ -0,0 +1,533 @@ +/* + * pnm2png.c --- conversion from PBM/PGM/PPM-file to PNG-file + * copyright (C) 1999 by Willem van Schaik + * + * version 1.0 - 1999.10.15 - First version. + * + * Permission to use, copy, modify, and distribute this software and + * its documentation for any purpose and without fee is hereby granted, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear in + * supporting documentation. This software is provided "as is" without + * express or implied warranty. + */ + +#include +#include +#ifdef __TURBOC__ +#include +#include +#endif + +#ifndef BOOL +#define BOOL unsigned char +#endif +#ifndef TRUE +#define TRUE (BOOL) 1 +#endif +#ifndef FALSE +#define FALSE (BOOL) 0 +#endif + +#define STDIN 0 +#define STDOUT 1 +#define STDERR 2 + +/* to make pnm2png verbose so we can find problems (needs to be before png.h) */ +#ifndef PNG_DEBUG +#define PNG_DEBUG 0 +#endif + +#include "png.h" + +/* Define png_jmpbuf() in case we are using a pre-1.0.6 version of libpng */ +#ifndef png_jmpbuf +# define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf) +#endif + +/* function prototypes */ + +int main (int argc, char *argv[]); +void usage (); +BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace, BOOL alpha); +void get_token(FILE *pnm_file, char *token); +png_uint_32 get_data (FILE *pnm_file, int depth); +png_uint_32 get_value (FILE *pnm_file, int depth); + +/* + * main + */ + +int main(int argc, char *argv[]) +{ + FILE *fp_rd = stdin; + FILE *fp_al = NULL; + FILE *fp_wr = stdout; + BOOL interlace = FALSE; + BOOL alpha = FALSE; + int argi; + + for (argi = 1; argi < argc; argi++) + { + if (argv[argi][0] == '-') + { + switch (argv[argi][1]) + { + case 'i': + interlace = TRUE; + break; + case 'a': + alpha = TRUE; + argi++; + if ((fp_al = fopen (argv[argi], "rb")) == NULL) + { + fprintf (stderr, "PNM2PNG\n"); + fprintf (stderr, "Error: alpha-channel file %s does not exist\n", + argv[argi]); + exit (1); + } + break; + case 'h': + case '?': + usage(); + exit(0); + break; + default: + fprintf (stderr, "PNM2PNG\n"); + fprintf (stderr, "Error: unknown option %s\n", argv[argi]); + usage(); + exit(1); + break; + } /* end switch */ + } + else if (fp_rd == stdin) + { + if ((fp_rd = fopen (argv[argi], "rb")) == NULL) + { + fprintf (stderr, "PNM2PNG\n"); + fprintf (stderr, "Error: file %s does not exist\n", argv[argi]); + exit (1); + } + } + else if (fp_wr == stdout) + { + if ((fp_wr = fopen (argv[argi], "wb")) == NULL) + { + fprintf (stderr, "PNM2PNG\n"); + fprintf (stderr, "Error: can not create PNG-file %s\n", argv[argi]); + exit (1); + } + } + else + { + fprintf (stderr, "PNM2PNG\n"); + fprintf (stderr, "Error: too many parameters\n"); + usage(); + exit (1); + } + } /* end for */ + +#ifdef __TURBOC__ + /* set stdin/stdout to binary, we're reading the PNM always! in binary format */ + if (fp_rd == stdin) + { + setmode (STDIN, O_BINARY); + } + if (fp_wr == stdout) + { + setmode (STDOUT, O_BINARY); + } +#endif + + /* call the conversion program itself */ + if (pnm2png (fp_rd, fp_wr, fp_al, interlace, alpha) == FALSE) + { + fprintf (stderr, "PNM2PNG\n"); + fprintf (stderr, "Error: unsuccessful converting to PNG-image\n"); + exit (1); + } + + /* close input file */ + fclose (fp_rd); + /* close output file */ + fclose (fp_wr); + /* close alpha file */ + if (alpha) + fclose (fp_al); + + return 0; +} + +/* + * usage + */ + +void usage() +{ + fprintf (stderr, "PNM2PNG\n"); + fprintf (stderr, " by Willem van Schaik, 1999\n"); +#ifdef __TURBOC__ + fprintf (stderr, " for Turbo-C and Borland-C compilers\n"); +#else + fprintf (stderr, " for Linux (and Unix) compilers\n"); +#endif + fprintf (stderr, "Usage: pnm2png [options] . [.png]\n"); + fprintf (stderr, " or: ... | pnm2png [options]\n"); + fprintf (stderr, "Options:\n"); + fprintf (stderr, " -i[nterlace] write png-file with interlacing on\n"); + fprintf (stderr, " -a[lpha] .pgm read PNG alpha channel as pgm-file\n"); + fprintf (stderr, " -h | -? print this help-information\n"); +} + +/* + * pnm2png + */ + +BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace, BOOL alpha) +{ + png_struct *png_ptr = NULL; + png_info *info_ptr = NULL; + png_byte *png_pixels = NULL; + png_byte **row_pointers = NULL; + png_byte *pix_ptr = NULL; + png_uint_32 row_bytes; + + char type_token[16]; + char width_token[16]; + char height_token[16]; + char maxval_token[16]; + int color_type; + png_uint_32 width, alpha_width; + png_uint_32 height, alpha_height; + png_uint_32 maxval; + int bit_depth = 0; + int channels; + int alpha_depth = 0; + int alpha_present; + int row, col; + BOOL raw, alpha_raw = FALSE; + png_uint_32 tmp16; + int i; + + /* read header of PNM file */ + + get_token(pnm_file, type_token); + if (type_token[0] != 'P') + { + return FALSE; + } + else if ((type_token[1] == '1') || (type_token[1] == '4')) + { + raw = (type_token[1] == '4'); + color_type = PNG_COLOR_TYPE_GRAY; + bit_depth = 1; + } + else if ((type_token[1] == '2') || (type_token[1] == '5')) + { + raw = (type_token[1] == '5'); + color_type = PNG_COLOR_TYPE_GRAY; + get_token(pnm_file, width_token); + sscanf (width_token, "%lu", &width); + get_token(pnm_file, height_token); + sscanf (height_token, "%lu", &height); + get_token(pnm_file, maxval_token); + sscanf (maxval_token, "%lu", &maxval); + if (maxval <= 1) + bit_depth = 1; + else if (maxval <= 3) + bit_depth = 2; + else if (maxval <= 15) + bit_depth = 4; + else if (maxval <= 255) + bit_depth = 8; + else /* if (maxval <= 65535) */ + bit_depth = 16; + } + else if ((type_token[1] == '3') || (type_token[1] == '6')) + { + raw = (type_token[1] == '6'); + color_type = PNG_COLOR_TYPE_RGB; + get_token(pnm_file, width_token); + sscanf (width_token, "%lu", &width); + get_token(pnm_file, height_token); + sscanf (height_token, "%lu", &height); + get_token(pnm_file, maxval_token); + sscanf (maxval_token, "%lu", &maxval); + if (maxval <= 1) + bit_depth = 1; + else if (maxval <= 3) + bit_depth = 2; + else if (maxval <= 15) + bit_depth = 4; + else if (maxval <= 255) + bit_depth = 8; + else /* if (maxval <= 65535) */ + bit_depth = 16; + } + else + { + return FALSE; + } + + /* read header of PGM file with alpha channel */ + + if (alpha) + { + if (color_type == PNG_COLOR_TYPE_GRAY) + color_type = PNG_COLOR_TYPE_GRAY_ALPHA; + if (color_type == PNG_COLOR_TYPE_RGB) + color_type = PNG_COLOR_TYPE_RGB_ALPHA; + + get_token(alpha_file, type_token); + if (type_token[0] != 'P') + { + return FALSE; + } + else if ((type_token[1] == '2') || (type_token[1] == '5')) + { + alpha_raw = (type_token[1] == '5'); + get_token(alpha_file, width_token); + sscanf (width_token, "%lu", &alpha_width); + if (alpha_width != width) + return FALSE; + get_token(alpha_file, height_token); + sscanf (height_token, "%lu", &alpha_height); + if (alpha_height != height) + return FALSE; + get_token(alpha_file, maxval_token); + sscanf (maxval_token, "%lu", &maxval); + if (maxval <= 1) + alpha_depth = 1; + else if (maxval <= 3) + alpha_depth = 2; + else if (maxval <= 15) + alpha_depth = 4; + else if (maxval <= 255) + alpha_depth = 8; + else /* if (maxval <= 65535) */ + alpha_depth = 16; + if (alpha_depth != bit_depth) + return FALSE; + } + else + { + return FALSE; + } + } /* end if alpha */ + + /* calculate the number of channels and store alpha-presence */ + if (color_type == PNG_COLOR_TYPE_GRAY) + channels = 1; + else if (color_type == PNG_COLOR_TYPE_GRAY_ALPHA) + channels = 2; + else if (color_type == PNG_COLOR_TYPE_RGB) + channels = 3; + else if (color_type == PNG_COLOR_TYPE_RGB_ALPHA) + channels = 4; + else + channels = 0; /* should not happen */ + + alpha_present = (channels - 1) % 2; + + /* row_bytes is the width x number of channels x (bit-depth / 8) */ + row_bytes = width * channels * ((bit_depth <= 8) ? 1 : 2); + + if ((png_pixels = (png_byte *) malloc (row_bytes * height * sizeof (png_byte))) == NULL) + return FALSE; + + /* read data from PNM file */ + pix_ptr = png_pixels; + + for (row = 0; row < height; row++) + { + for (col = 0; col < width; col++) + { + for (i = 0; i < (channels - alpha_present); i++) + { + if (raw) + *pix_ptr++ = get_data (pnm_file, bit_depth); + else + if (bit_depth <= 8) + *pix_ptr++ = get_value (pnm_file, bit_depth); + else + { + tmp16 = get_value (pnm_file, bit_depth); + *pix_ptr = (png_byte) ((tmp16 >> 8) & 0xFF); + pix_ptr++; + *pix_ptr = (png_byte) (tmp16 & 0xFF); + pix_ptr++; + } + } + + if (alpha) /* read alpha-channel from pgm file */ + { + if (alpha_raw) + *pix_ptr++ = get_data (alpha_file, alpha_depth); + else + if (alpha_depth <= 8) + *pix_ptr++ = get_value (alpha_file, bit_depth); + else + { + tmp16 = get_value (alpha_file, bit_depth); + *pix_ptr++ = (png_byte) ((tmp16 >> 8) & 0xFF); + *pix_ptr++ = (png_byte) (tmp16 & 0xFF); + } + } /* if alpha */ + + } /* end for col */ + } /* end for row */ + + /* prepare the standard PNG structures */ + png_ptr = png_create_write_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); + if (!png_ptr) + { + return FALSE; + } + info_ptr = png_create_info_struct (png_ptr); + if (!info_ptr) + { + png_destroy_write_struct (&png_ptr, (png_infopp) NULL); + return FALSE; + } + + /* setjmp() must be called in every function that calls a PNG-reading libpng function */ + if (setjmp (png_jmpbuf(png_ptr))) + { + png_destroy_write_struct (&png_ptr, (png_infopp) NULL); + return FALSE; + } + + /* initialize the png structure */ + png_init_io (png_ptr, png_file); + + /* we're going to write more or less the same PNG as the input file */ + png_set_IHDR (png_ptr, info_ptr, width, height, bit_depth, color_type, + (!interlace) ? PNG_INTERLACE_NONE : PNG_INTERLACE_ADAM7, + PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); + + /* write the file header information */ + png_write_info (png_ptr, info_ptr); + + /* if needed we will allocate memory for an new array of row-pointers */ + if (row_pointers == (unsigned char**) NULL) + { + if ((row_pointers = (png_byte **) malloc (height * sizeof (png_bytep))) == NULL) + { + png_destroy_write_struct (&png_ptr, (png_infopp) NULL); + return FALSE; + } + } + + /* set the individual row_pointers to point at the correct offsets */ + for (i = 0; i < (height); i++) + row_pointers[i] = png_pixels + i * row_bytes; + + /* write out the entire image data in one call */ + png_write_image (png_ptr, row_pointers); + + /* write the additional chuncks to the PNG file (not really needed) */ + png_write_end (png_ptr, info_ptr); + + /* clean up after the write, and free any memory allocated */ + png_destroy_write_struct (&png_ptr, (png_infopp) NULL); + + if (row_pointers != (unsigned char**) NULL) + free (row_pointers); + if (png_pixels != (unsigned char*) NULL) + free (png_pixels); + + return TRUE; +} /* end of pnm2png */ + +/* + * get_token() - gets the first string after whitespace + */ + +void get_token(FILE *pnm_file, char *token) +{ + int i = 0; + + /* remove white-space */ + do + { + token[i] = (unsigned char) fgetc (pnm_file); + } + while ((token[i] == '\n') || (token[i] == '\r') || (token[i] == ' ')); + + /* read string */ + do + { + i++; + token[i] = (unsigned char) fgetc (pnm_file); + } + while ((token[i] != '\n') && (token[i] != '\r') && (token[i] != ' ')); + + token[i] = '\0'; + + return; +} + +/* + * get_data() - takes first byte and converts into next pixel value, + * taking as much bits as defined by bit-depth and + * using the bit-depth to fill up a byte (0Ah -> AAh) + */ + +png_uint_32 get_data (FILE *pnm_file, int depth) +{ + static int bits_left = 0; + static int old_value = 0; + static int mask = 0; + int i; + png_uint_32 ret_value; + + if (mask == 0) + for (i = 0; i < depth; i++) + mask = (mask >> 1) | 0x80; + + if (bits_left <= 0) + { + old_value = fgetc (pnm_file); + bits_left = 8; + } + + ret_value = old_value & mask; + for (i = 1; i < (8 / depth); i++) + ret_value = ret_value || (ret_value >> depth); + + old_value = (old_value << depth) & 0xFF; + bits_left -= depth; + + return ret_value; +} + +/* + * get_value() - takes first (numeric) string and converts into number, + * using the bit-depth to fill up a byte (0Ah -> AAh) + */ + +png_uint_32 get_value (FILE *pnm_file, int depth) +{ + static png_uint_32 mask = 0; + png_byte token[16]; + png_uint_32 ret_value; + int i = 0; + + if (mask == 0) + for (i = 0; i < depth; i++) + mask = (mask << 1) | 0x01; + + get_token (pnm_file, (char *) token); + sscanf ((const char *) token, "%lu", &ret_value); + + ret_value &= mask; + + if (depth < 8) + for (i = 0; i < (8 / depth); i++) + ret_value = (ret_value << depth) || ret_value; + + return ret_value; +} + +/* end of source */ + diff --git a/libs/libpng-src/contrib/pngminus/pnm2png.sh b/libs/libpng-src/contrib/pngminus/pnm2png.sh new file mode 100755 index 000000000..d79df2fae --- /dev/null +++ b/libs/libpng-src/contrib/pngminus/pnm2png.sh @@ -0,0 +1,42 @@ +#!/bin/sh +# -- grayscale +./pnm2png basn0g01.pgm basn0g01.png +./pnm2png basn0g02.pgm basn0g02.png +./pnm2png basn0g04.pgm basn0g04.png +./pnm2png basn0g08.pgm basn0g08.png +./pnm2png basn0g16.pgm basn0g16.png +# -- full-color +./pnm2png basn2c08.ppm basn2c08.png +./pnm2png basn2c16.ppm basn2c16.png +# -- palletted +./pnm2png basn3p01.ppm basn3p01.png +./pnm2png basn3p02.ppm basn3p02.png +./pnm2png basn3p04.ppm basn3p04.png +./pnm2png basn3p08.ppm basn3p08.png +# -- gray with alpha-channel +./pnm2png -alpha basn6a08.pgm basn4a08.pgm basn4a08.png +./pnm2png -alpha basn6a16.pgm basn4a16.pgm basn4a16.png +# -- color with alpha-channel +./pnm2png -alpha basn6a08.pgm basn6a08.ppm basn6a08.png +./pnm2png -alpha basn6a16.pgm basn6a16.ppm basn6a16.png +# -- grayscale +./pnm2png rawn0g01.pgm rawn0g01.png +./pnm2png rawn0g02.pgm rawn0g02.png +./pnm2png rawn0g04.pgm rawn0g04.png +./pnm2png rawn0g08.pgm rawn0g08.png +./pnm2png rawn0g16.pgm rawn0g16.png +# -- full-color +./pnm2png rawn2c08.ppm rawn2c08.png +./pnm2png rawn2c16.ppm rawn2c16.png +# -- palletted +./pnm2png rawn3p01.ppm rawn3p01.png +./pnm2png rawn3p02.ppm rawn3p02.png +./pnm2png rawn3p04.ppm rawn3p04.png +./pnm2png rawn3p08.ppm rawn3p08.png +# -- gray with alpha-channel +./pnm2png -alpha rawn6a08.pgm rawn4a08.pgm rawn4a08.png +./pnm2png -alpha rawn6a16.pgm rawn4a16.pgm rawn4a16.png +# -- color with alpha-channel +./pnm2png -alpha rawn6a08.pgm rawn6a08.ppm rawn6a08.png +./pnm2png -alpha rawn6a16.pgm rawn6a16.ppm rawn6a16.png + diff --git a/libs/libpng-src/contrib/pngsuite/README b/libs/libpng-src/contrib/pngsuite/README new file mode 100644 index 000000000..714d12c64 --- /dev/null +++ b/libs/libpng-src/contrib/pngsuite/README @@ -0,0 +1,85 @@ + +pngsuite +-------- +(c) Willem van Schaik, 1999 + +Permission to use, copy, and distribute these images for any purpose and +without fee is hereby granted. + +These 15 images are part of the much larger PngSuite test-set of +images, available for developers of PNG supporting software. The +complete set, available at http:/www.schaik.com/pngsuite/, contains +a variety of images to test interlacing, gamma settings, ancillary +chunks, etc. + +The images in this directory represent the basic PNG color-types: +grayscale (1-16 bit deep), full color (8 or 16 bit), paletted +(1-8 bit) and grayscale or color images with alpha channel. You +can use them to test the proper functioning of PNG software. + + filename depth type + ------------ ------ -------------- + basn0g01.png 1-bit grayscale + basn0g02.png 2-bit grayscale + basn0g04.png 4-bit grayscale + basn0g08.png 8-bit grayscale + basn0g16.png 16-bit grayscale + basn2c08.png 8-bit truecolor + basn2c16.png 16-bit truecolor + basn3p01.png 1-bit paletted + basn3p02.png 2-bit paletted + basn3p04.png 4-bit paletted + basn3p08.png 8-bit paletted + basn4a08.png 8-bit gray with alpha + basn4a16.png 16-bit gray with alpha + basn6a08.png 8-bit RGBA + basn6a16.png 16-bit RGBA + +Here is the correct result of typing "pngtest -m *.png" in +this directory: + +Testing basn0g01.png: PASS (524 zero samples) + Filter 0 was used 32 times +Testing basn0g02.png: PASS (448 zero samples) + Filter 0 was used 32 times +Testing basn0g04.png: PASS (520 zero samples) + Filter 0 was used 32 times +Testing basn0g08.png: PASS (3 zero samples) + Filter 1 was used 9 times + Filter 4 was used 23 times +Testing basn0g16.png: PASS (1 zero samples) + Filter 1 was used 1 times + Filter 2 was used 31 times +Testing basn2c08.png: PASS (6 zero samples) + Filter 1 was used 5 times + Filter 4 was used 27 times +Testing basn2c16.png: PASS (592 zero samples) + Filter 1 was used 1 times + Filter 4 was used 31 times +Testing basn3p01.png: PASS (512 zero samples) + Filter 0 was used 32 times +Testing basn3p02.png: PASS (448 zero samples) + Filter 0 was used 32 times +Testing basn3p04.png: PASS (544 zero samples) + Filter 0 was used 32 times +Testing basn3p08.png: PASS (4 zero samples) + Filter 0 was used 32 times +Testing basn4a08.png: PASS (32 zero samples) + Filter 1 was used 1 times + Filter 4 was used 31 times +Testing basn4a16.png: PASS (64 zero samples) + Filter 0 was used 1 times + Filter 1 was used 2 times + Filter 2 was used 1 times + Filter 4 was used 28 times +Testing basn6a08.png: PASS (160 zero samples) + Filter 1 was used 1 times + Filter 4 was used 31 times +Testing basn6a16.png: PASS (1072 zero samples) + Filter 1 was used 4 times + Filter 4 was used 28 times +libpng passes test + +Willem van Schaik + +October 1999 diff --git a/libs/libpng-src/contrib/pngsuite/basn0g01.png b/libs/libpng-src/contrib/pngsuite/basn0g01.png new file mode 100644 index 000000000..e31e1c7a6 Binary files /dev/null and b/libs/libpng-src/contrib/pngsuite/basn0g01.png differ diff --git a/libs/libpng-src/contrib/pngsuite/basn0g02.png b/libs/libpng-src/contrib/pngsuite/basn0g02.png new file mode 100644 index 000000000..68809dd8f Binary files /dev/null and b/libs/libpng-src/contrib/pngsuite/basn0g02.png differ diff --git a/libs/libpng-src/contrib/pngsuite/basn0g04.png b/libs/libpng-src/contrib/pngsuite/basn0g04.png new file mode 100644 index 000000000..6fa089cb8 Binary files /dev/null and b/libs/libpng-src/contrib/pngsuite/basn0g04.png differ diff --git a/libs/libpng-src/contrib/pngsuite/basn0g08.png b/libs/libpng-src/contrib/pngsuite/basn0g08.png new file mode 100644 index 000000000..bf522eef0 Binary files /dev/null and b/libs/libpng-src/contrib/pngsuite/basn0g08.png differ diff --git a/libs/libpng-src/contrib/pngsuite/basn0g16.png b/libs/libpng-src/contrib/pngsuite/basn0g16.png new file mode 100644 index 000000000..318ebcadf Binary files /dev/null and b/libs/libpng-src/contrib/pngsuite/basn0g16.png differ diff --git a/libs/libpng-src/contrib/pngsuite/basn2c08.png b/libs/libpng-src/contrib/pngsuite/basn2c08.png new file mode 100644 index 000000000..21d2f91a8 Binary files /dev/null and b/libs/libpng-src/contrib/pngsuite/basn2c08.png differ diff --git a/libs/libpng-src/contrib/pngsuite/basn2c16.png b/libs/libpng-src/contrib/pngsuite/basn2c16.png new file mode 100644 index 000000000..1bd4a4d0e Binary files /dev/null and b/libs/libpng-src/contrib/pngsuite/basn2c16.png differ diff --git a/libs/libpng-src/contrib/pngsuite/basn3p01.png b/libs/libpng-src/contrib/pngsuite/basn3p01.png new file mode 100644 index 000000000..a21db5977 Binary files /dev/null and b/libs/libpng-src/contrib/pngsuite/basn3p01.png differ diff --git a/libs/libpng-src/contrib/pngsuite/basn3p02.png b/libs/libpng-src/contrib/pngsuite/basn3p02.png new file mode 100644 index 000000000..1d0ab6197 Binary files /dev/null and b/libs/libpng-src/contrib/pngsuite/basn3p02.png differ diff --git a/libs/libpng-src/contrib/pngsuite/basn3p04.png b/libs/libpng-src/contrib/pngsuite/basn3p04.png new file mode 100644 index 000000000..6dc6eac83 Binary files /dev/null and b/libs/libpng-src/contrib/pngsuite/basn3p04.png differ diff --git a/libs/libpng-src/contrib/pngsuite/basn3p08.png b/libs/libpng-src/contrib/pngsuite/basn3p08.png new file mode 100644 index 000000000..0e07f483c Binary files /dev/null and b/libs/libpng-src/contrib/pngsuite/basn3p08.png differ diff --git a/libs/libpng-src/contrib/pngsuite/basn4a08.png b/libs/libpng-src/contrib/pngsuite/basn4a08.png new file mode 100644 index 000000000..3bb0dd06b Binary files /dev/null and b/libs/libpng-src/contrib/pngsuite/basn4a08.png differ diff --git a/libs/libpng-src/contrib/pngsuite/basn4a16.png b/libs/libpng-src/contrib/pngsuite/basn4a16.png new file mode 100644 index 000000000..6dbee9fbd Binary files /dev/null and b/libs/libpng-src/contrib/pngsuite/basn4a16.png differ diff --git a/libs/libpng-src/contrib/pngsuite/basn6a08.png b/libs/libpng-src/contrib/pngsuite/basn6a08.png new file mode 100644 index 000000000..610623085 Binary files /dev/null and b/libs/libpng-src/contrib/pngsuite/basn6a08.png differ diff --git a/libs/libpng-src/contrib/pngsuite/basn6a16.png b/libs/libpng-src/contrib/pngsuite/basn6a16.png new file mode 100644 index 000000000..a9bf3cb46 Binary files /dev/null and b/libs/libpng-src/contrib/pngsuite/basn6a16.png differ diff --git a/libs/libpng-src/contrib/visupng/PngFile.c b/libs/libpng-src/contrib/visupng/PngFile.c new file mode 100644 index 000000000..ff6d155e5 --- /dev/null +++ b/libs/libpng-src/contrib/visupng/PngFile.c @@ -0,0 +1,442 @@ +//------------------------------------- +// PNGFILE.C -- Image File Functions +//------------------------------------- + +// Copyright 2000, Willem van Schaik. +// +// This code is released under the libpng license. +// For conditions of distribution and use, see the disclaimer +// and license in png.h + +#include +#include +#include +#include + +#include "png.h" +#include "pngfile.h" +#include "cexcept.h" + +define_exception_type(const char *); +extern struct exception_context the_exception_context[1]; +struct exception_context the_exception_context[1]; +png_const_charp msg; + +static OPENFILENAME ofn; + +static png_structp png_ptr = NULL; +static png_infop info_ptr = NULL; + + +// cexcept interface + +static void +png_cexcept_error(png_structp png_ptr, png_const_charp msg) +{ + if(png_ptr) + ; +#ifndef PNG_NO_CONSOLE_IO + fprintf(stderr, "libpng error: %s\n", msg); +#endif + { + Throw msg; + } +} + +// Windows open-file functions + +void PngFileInitialize (HWND hwnd) +{ + static TCHAR szFilter[] = TEXT ("PNG Files (*.PNG)\0*.png\0") + TEXT ("All Files (*.*)\0*.*\0\0"); + + ofn.lStructSize = sizeof (OPENFILENAME); + ofn.hwndOwner = hwnd; + ofn.hInstance = NULL; + ofn.lpstrFilter = szFilter; + ofn.lpstrCustomFilter = NULL; + ofn.nMaxCustFilter = 0; + ofn.nFilterIndex = 0; + ofn.lpstrFile = NULL; // Set in Open and Close functions + ofn.nMaxFile = MAX_PATH; + ofn.lpstrFileTitle = NULL; // Set in Open and Close functions + ofn.nMaxFileTitle = MAX_PATH; + ofn.lpstrInitialDir = NULL; + ofn.lpstrTitle = NULL; + ofn.Flags = 0; // Set in Open and Close functions + ofn.nFileOffset = 0; + ofn.nFileExtension = 0; + ofn.lpstrDefExt = TEXT ("png"); + ofn.lCustData = 0; + ofn.lpfnHook = NULL; + ofn.lpTemplateName = NULL; +} + +BOOL PngFileOpenDlg (HWND hwnd, PTSTR pstrFileName, PTSTR pstrTitleName) +{ + ofn.hwndOwner = hwnd; + ofn.lpstrFile = pstrFileName; + ofn.lpstrFileTitle = pstrTitleName; + ofn.Flags = OFN_HIDEREADONLY; + + return GetOpenFileName (&ofn); +} + +BOOL PngFileSaveDlg (HWND hwnd, PTSTR pstrFileName, PTSTR pstrTitleName) +{ + ofn.hwndOwner = hwnd; + ofn.lpstrFile = pstrFileName; + ofn.lpstrFileTitle = pstrTitleName; + ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT; + + return GetSaveFileName (&ofn); +} + +// PNG image handler functions + +BOOL PngLoadImage (PTSTR pstrFileName, png_byte **ppbImageData, + int *piWidth, int *piHeight, int *piChannels, png_color *pBkgColor) +{ + static FILE *pfFile; + png_byte pbSig[8]; + int iBitDepth; + int iColorType; + double dGamma; + png_color_16 *pBackground; + png_uint_32 ulChannels; + png_uint_32 ulRowBytes; + png_byte *pbImageData = *ppbImageData; + static png_byte **ppbRowPointers = NULL; + int i; + + // open the PNG input file + + if (!pstrFileName) + { + *ppbImageData = pbImageData = NULL; + return FALSE; + } + + if (!(pfFile = fopen(pstrFileName, "rb"))) + { + *ppbImageData = pbImageData = NULL; + return FALSE; + } + + // first check the eight byte PNG signature + + fread(pbSig, 1, 8, pfFile); + if (png_sig_cmp(pbSig, 0, 8)) + { + *ppbImageData = pbImageData = NULL; + return FALSE; + } + + // create the two png(-info) structures + + png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, + (png_error_ptr)png_cexcept_error, (png_error_ptr)NULL); + if (!png_ptr) + { + *ppbImageData = pbImageData = NULL; + return FALSE; + } + + info_ptr = png_create_info_struct(png_ptr); + if (!info_ptr) + { + png_destroy_read_struct(&png_ptr, NULL, NULL); + *ppbImageData = pbImageData = NULL; + return FALSE; + } + + Try + { + + // initialize the png structure + +#if !defined(PNG_NO_STDIO) + png_init_io(png_ptr, pfFile); +#else + png_set_read_fn(png_ptr, (png_voidp)pfFile, png_read_data); +#endif + + png_set_sig_bytes(png_ptr, 8); + + // read all PNG info up to image data + + png_read_info(png_ptr, info_ptr); + + // get width, height, bit-depth and color-type + + png_get_IHDR(png_ptr, info_ptr, piWidth, piHeight, &iBitDepth, + &iColorType, NULL, NULL, NULL); + + // expand images of all color-type and bit-depth to 3x8 bit RGB images + // let the library process things like alpha, transparency, background + + if (iBitDepth == 16) + png_set_strip_16(png_ptr); + if (iColorType == PNG_COLOR_TYPE_PALETTE) + png_set_expand(png_ptr); + if (iBitDepth < 8) + png_set_expand(png_ptr); + if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) + png_set_expand(png_ptr); + if (iColorType == PNG_COLOR_TYPE_GRAY || + iColorType == PNG_COLOR_TYPE_GRAY_ALPHA) + png_set_gray_to_rgb(png_ptr); + + // set the background color to draw transparent and alpha images over. + if (png_get_bKGD(png_ptr, info_ptr, &pBackground)) + { + png_set_background(png_ptr, pBackground, PNG_BACKGROUND_GAMMA_FILE, 1, 1.0); + pBkgColor->red = (byte) pBackground->red; + pBkgColor->green = (byte) pBackground->green; + pBkgColor->blue = (byte) pBackground->blue; + } + else + { + pBkgColor = NULL; + } + + // if required set gamma conversion + if (png_get_gAMA(png_ptr, info_ptr, &dGamma)) + png_set_gamma(png_ptr, (double) 2.2, dGamma); + + // after the transformations have been registered update info_ptr data + + png_read_update_info(png_ptr, info_ptr); + + // get again width, height and the new bit-depth and color-type + + png_get_IHDR(png_ptr, info_ptr, piWidth, piHeight, &iBitDepth, + &iColorType, NULL, NULL, NULL); + + + // row_bytes is the width x number of channels + + ulRowBytes = png_get_rowbytes(png_ptr, info_ptr); + ulChannels = png_get_channels(png_ptr, info_ptr); + + *piChannels = ulChannels; + + // now we can allocate memory to store the image + + if (pbImageData) + { + free (pbImageData); + pbImageData = NULL; + } + if ((pbImageData = (png_byte *) malloc(ulRowBytes * (*piHeight) + * sizeof(png_byte))) == NULL) + { + png_error(png_ptr, "Visual PNG: out of memory"); + } + *ppbImageData = pbImageData; + + // and allocate memory for an array of row-pointers + + if ((ppbRowPointers = (png_bytepp) malloc((*piHeight) + * sizeof(png_bytep))) == NULL) + { + png_error(png_ptr, "Visual PNG: out of memory"); + } + + // set the individual row-pointers to point at the correct offsets + + for (i = 0; i < (*piHeight); i++) + ppbRowPointers[i] = pbImageData + i * ulRowBytes; + + // now we can go ahead and just read the whole image + + png_read_image(png_ptr, ppbRowPointers); + + // read the additional chunks in the PNG file (not really needed) + + png_read_end(png_ptr, NULL); + + // and we're done + + free (ppbRowPointers); + ppbRowPointers = NULL; + + // yepp, done + } + + Catch (msg) + { + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + + *ppbImageData = pbImageData = NULL; + + if(ppbRowPointers) + free (ppbRowPointers); + + fclose(pfFile); + + return FALSE; + } + + fclose (pfFile); + + return TRUE; +} + + +BOOL PngSaveImage (PTSTR pstrFileName, png_byte *pDiData, + int iWidth, int iHeight, png_color bkgColor) +{ + const int ciBitDepth = 8; + const int ciChannels = 3; + + static FILE *pfFile; + png_uint_32 ulRowBytes; + static png_byte **ppbRowPointers = NULL; + int i; + + // open the PNG output file + + if (!pstrFileName) + return FALSE; + + if (!(pfFile = fopen(pstrFileName, "wb"))) + return FALSE; + + // prepare the standard PNG structures + + png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, + (png_error_ptr)png_cexcept_error, (png_error_ptr)NULL); + if (!png_ptr) + { + fclose(pfFile); + return FALSE; + } + + info_ptr = png_create_info_struct(png_ptr); + if (!info_ptr) { + fclose(pfFile); + png_destroy_write_struct(&png_ptr, (png_infopp) NULL); + return FALSE; + } + + Try + { + // initialize the png structure + +#if !defined(PNG_NO_STDIO) + png_init_io(png_ptr, pfFile); +#else + png_set_write_fn(png_ptr, (png_voidp)pfFile, png_write_data, png_flush); +#endif + + // we're going to write a very simple 3x8 bit RGB image + + png_set_IHDR(png_ptr, info_ptr, iWidth, iHeight, ciBitDepth, + PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, + PNG_FILTER_TYPE_BASE); + + // write the file header information + + png_write_info(png_ptr, info_ptr); + + // swap the BGR pixels in the DiData structure to RGB + + png_set_bgr(png_ptr); + + // row_bytes is the width x number of channels + + ulRowBytes = iWidth * ciChannels; + + // we can allocate memory for an array of row-pointers + + if ((ppbRowPointers = (png_bytepp) malloc(iHeight * sizeof(png_bytep))) == NULL) + Throw "Visualpng: Out of memory"; + + // set the individual row-pointers to point at the correct offsets + + for (i = 0; i < iHeight; i++) + ppbRowPointers[i] = pDiData + i * (((ulRowBytes + 3) >> 2) << 2); + + // write out the entire image data in one call + + png_write_image (png_ptr, ppbRowPointers); + + // write the additional chunks to the PNG file (not really needed) + + png_write_end(png_ptr, info_ptr); + + // and we're done + + free (ppbRowPointers); + ppbRowPointers = NULL; + + // clean up after the write, and free any memory allocated + + png_destroy_write_struct(&png_ptr, (png_infopp) NULL); + + // yepp, done + } + + Catch (msg) + { + png_destroy_write_struct(&png_ptr, (png_infopp) NULL); + + if(ppbRowPointers) + free (ppbRowPointers); + + fclose(pfFile); + + return FALSE; + } + + fclose (pfFile); + + return TRUE; +} + +#ifdef PNG_NO_STDIO + +static void +png_read_data(png_structp png_ptr, png_bytep data, png_size_t length) +{ + png_size_t check; + + /* fread() returns 0 on error, so it is OK to store this in a png_size_t + * instead of an int, which is what fread() actually returns. + */ + check = (png_size_t)fread(data, (png_size_t)1, length, + (FILE *)png_ptr->io_ptr); + + if (check != length) + { + png_error(png_ptr, "Read Error"); + } +} + +static void +png_write_data(png_structp png_ptr, png_bytep data, png_size_t length) +{ + png_uint_32 check; + + check = fwrite(data, 1, length, (FILE *)(png_ptr->io_ptr)); + if (check != length) + { + png_error(png_ptr, "Write Error"); + } +} + +static void +png_flush(png_structp png_ptr) +{ + FILE *io_ptr; + io_ptr = (FILE *)CVT_PTR((png_ptr->io_ptr)); + if (io_ptr != NULL) + fflush(io_ptr); +} + +#endif + +//----------------- +// end of source +//----------------- diff --git a/libs/libpng-src/contrib/visupng/PngFile.h b/libs/libpng-src/contrib/visupng/PngFile.h new file mode 100644 index 000000000..f695811cc --- /dev/null +++ b/libs/libpng-src/contrib/visupng/PngFile.h @@ -0,0 +1,30 @@ +//------------------------------------------ +// PNGFILE.H -- Header File for pngfile.c +//------------------------------------------ + +// Copyright 2000, Willem van Schaik. + +// This code is released under the libpng license. +// For conditions of distribution and use, see the disclaimer +// and license in png.h + +#include +#include +#include +#include + +void PngFileInitialize (HWND hwnd) ; +BOOL PngFileOpenDlg (HWND hwnd, PTSTR pstrFileName, PTSTR pstrTitleName) ; +BOOL PngFileSaveDlg (HWND hwnd, PTSTR pstrFileName, PTSTR pstrTitleName) ; + +BOOL PngLoadImage (PTSTR pstrFileName, png_byte **ppbImageData, + int *piWidth, int *piHeight, int *piChannels, png_color *pBkgColor); +BOOL PngSaveImage (PTSTR pstrFileName, png_byte *pDiData, + int iWidth, int iHeight, png_color BkgColor); + +#if defined(PNG_NO_STDIO) +static void png_read_data(png_structp png_ptr, png_bytep data, png_size_t length); +static void png_write_data(png_structp png_ptr, png_bytep data, png_size_t length); +static void png_flush(png_structp png_ptr); +#endif + diff --git a/libs/libpng-src/contrib/visupng/README.txt b/libs/libpng-src/contrib/visupng/README.txt new file mode 100644 index 000000000..4047119a5 --- /dev/null +++ b/libs/libpng-src/contrib/visupng/README.txt @@ -0,0 +1,61 @@ +Microsoft Developer Studio Build File, Format Version 6.00 for VisualPng +------------------------------------------------------------------------ + +Copyright 2000, Willem van Schaik. + +This code is released under the libpng license. +For conditions of distribution and use, see the disclaimer +and license in png.h + +As a PNG .dll demo VisualPng is finished. More features would only hinder +the program's objective. However, further extensions (like support for other +graphics formats) are in development. To get these, or for pre-compiled +binaries, go to "http://www.schaik.com/png/visualpng.html". + +------------------------------------------------------------------------ + +Assumes that + + libpng DLLs and LIBs are in ..\..\projects\msvc\win32\libpng + zlib DLLs and LIBs are in ..\..\projects\msvc\win32\zlib + libpng header files are in ..\..\..\libpng + zlib header files are in ..\..\..\zlib + the pngsuite images are in ..\pngsuite + +To build: + +1) On the main menu Select "Build|Set Active configuration". + Choose the configuration that corresponds to the library you want to test. + This library must have been built using the libpng MS project located in + the "..\..\mscv" subdirectory. + +2) Select "Build|Clean" + +3) Select "Build|Rebuild All" + +4) After compiling and linking VisualPng will be started to view an image + from the PngSuite directory. Press Ctrl-N (and Ctrl-V) for other images. + + +To install: + +When distributing VisualPng (or a further development) the following options +are available: + +1) Build the program with the configuration "Win32 LIB" and you only need to + include the executable from the ./lib directory in your distribution. + +2) Build the program with the configuration "Win32 DLL" and you need to put + in your distribution the executable from the ./dll directory and the dll's + libpng1.dll, zlib.dll and msvcrt.dll. These need to be in the user's PATH. + + +Willem van Schaik +Calgary, June 6th 2000 + +P.S. VisualPng was written based on preliminary work of: + + - Simon-Pierre Cadieux + - Glenn Randers-Pehrson + - Greg Roelofs + diff --git a/libs/libpng-src/contrib/visupng/VisualPng.c b/libs/libpng-src/contrib/visupng/VisualPng.c new file mode 100644 index 000000000..2018999a0 --- /dev/null +++ b/libs/libpng-src/contrib/visupng/VisualPng.c @@ -0,0 +1,964 @@ +//------------------------------------ +// VisualPng.C -- Shows a PNG image +//------------------------------------ + +// Copyright 2000, Willem van Schaik. + +// This code is released under the libpng license. +// For conditions of distribution and use, see the disclaimer +// and license in png.h + +// switches + +// defines + +#define PROGNAME "VisualPng" +#define LONGNAME "Win32 Viewer for PNG-files" +#define VERSION "1.0 of 2000 June 07" + +// constants + +#define MARGIN 8 + +// standard includes + +#include +#include +#include +#include + +// application includes + +#include "png.h" +#include "pngfile.h" +#include "resource.h" + +// macros + +// function prototypes + +LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM); +BOOL CALLBACK AboutDlgProc (HWND, UINT, WPARAM, LPARAM) ; + +BOOL CenterAbout (HWND hwndChild, HWND hwndParent); + +BOOL BuildPngList (PTSTR pstrPathName, TCHAR **ppFileList, int *pFileCount, + int *pFileIndex); + +BOOL SearchPngList (TCHAR *pFileList, int FileCount, int *pFileIndex, + PTSTR pstrPrevName, PTSTR pstrNextName); + +BOOL LoadImageFile(HWND hwnd, PTSTR pstrPathName, + png_byte **ppbImage, int *pxImgSize, int *pyImgSize, int *piChannels, + png_color *pBkgColor); + +BOOL DisplayImage (HWND hwnd, BYTE **ppDib, + BYTE **ppDiData, int cxWinSize, int cyWinSize, + BYTE *pbImage, int cxImgSize, int cyImgSize, int cImgChannels, + BOOL bStretched); + +BOOL InitBitmap ( + BYTE *pDiData, int cxWinSize, int cyWinSize); + +BOOL FillBitmap ( + BYTE *pDiData, int cxWinSize, int cyWinSize, + BYTE *pbImage, int cxImgSize, int cyImgSize, int cImgChannels, + BOOL bStretched); + +// a few global variables + +static char *szProgName = PROGNAME; +static char *szAppName = LONGNAME; +static char *szIconName = PROGNAME; +static char szCmdFileName [MAX_PATH]; + +// MAIN routine + +int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, + PSTR szCmdLine, int iCmdShow) +{ + HACCEL hAccel; + HWND hwnd; + MSG msg; + WNDCLASS wndclass; + int ixBorders, iyBorders; + + wndclass.style = CS_HREDRAW | CS_VREDRAW; + wndclass.lpfnWndProc = WndProc; + wndclass.cbClsExtra = 0; + wndclass.cbWndExtra = 0; + wndclass.hInstance = hInstance; + wndclass.hIcon = LoadIcon (hInstance, szIconName) ; + wndclass.hCursor = LoadCursor (NULL, IDC_ARROW); + wndclass.hbrBackground = NULL; // (HBRUSH) GetStockObject (GRAY_BRUSH); + wndclass.lpszMenuName = szProgName; + wndclass.lpszClassName = szProgName; + + if (!RegisterClass (&wndclass)) + { + MessageBox (NULL, TEXT ("Error: this program requires Windows NT!"), + szProgName, MB_ICONERROR); + return 0; + } + + // if filename given on commandline, store it + if ((szCmdLine != NULL) && (*szCmdLine != '\0')) + if (szCmdLine[0] == '"') + strncpy (szCmdFileName, szCmdLine + 1, strlen(szCmdLine) - 2); + else + strcpy (szCmdFileName, szCmdLine); + else + strcpy (szCmdFileName, ""); + + // calculate size of window-borders + ixBorders = 2 * (GetSystemMetrics (SM_CXBORDER) + + GetSystemMetrics (SM_CXDLGFRAME)); + iyBorders = 2 * (GetSystemMetrics (SM_CYBORDER) + + GetSystemMetrics (SM_CYDLGFRAME)) + + GetSystemMetrics (SM_CYCAPTION) + + GetSystemMetrics (SM_CYMENUSIZE) + + 1; /* WvS: don't ask me why? */ + + hwnd = CreateWindow (szProgName, szAppName, + WS_OVERLAPPEDWINDOW, + CW_USEDEFAULT, CW_USEDEFAULT, + 512 + 2 * MARGIN + ixBorders, 384 + 2 * MARGIN + iyBorders, +// CW_USEDEFAULT, CW_USEDEFAULT, + NULL, NULL, hInstance, NULL); + + ShowWindow (hwnd, iCmdShow); + UpdateWindow (hwnd); + + hAccel = LoadAccelerators (hInstance, szProgName); + + while (GetMessage (&msg, NULL, 0, 0)) + { + if (!TranslateAccelerator (hwnd, hAccel, &msg)) + { + TranslateMessage (&msg); + DispatchMessage (&msg); + } + } + return msg.wParam; +} + +LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, + LPARAM lParam) +{ + static HINSTANCE hInstance ; + static HDC hdc; + static PAINTSTRUCT ps; + static HMENU hMenu; + + static BITMAPFILEHEADER *pbmfh; + static BITMAPINFOHEADER *pbmih; + static BYTE *pbImage; + static int cxWinSize, cyWinSize; + static int cxImgSize, cyImgSize; + static int cImgChannels; + static png_color bkgColor = {127, 127, 127}; + + static BOOL bStretched = TRUE; + + static BYTE *pDib = NULL; + static BYTE *pDiData = NULL; + + static TCHAR szImgPathName [MAX_PATH]; + static TCHAR szTitleName [MAX_PATH]; + + static TCHAR *pPngFileList = NULL; + static int iPngFileCount; + static int iPngFileIndex; + + BOOL bOk; + + switch (message) + { + case WM_CREATE: + hInstance = ((LPCREATESTRUCT) lParam)->hInstance ; + PngFileInitialize (hwnd); + + strcpy (szImgPathName, ""); + + // in case we process file given on command-line + + if (szCmdFileName[0] != '\0') + { + strcpy (szImgPathName, szCmdFileName); + + // read the other png-files in the directory for later + // next/previous commands + + BuildPngList (szImgPathName, &pPngFileList, &iPngFileCount, + &iPngFileIndex); + + // load the image from file + + if (!LoadImageFile (hwnd, szImgPathName, + &pbImage, &cxImgSize, &cyImgSize, &cImgChannels, &bkgColor)) + return 0; + + // invalidate the client area for later update + + InvalidateRect (hwnd, NULL, TRUE); + + // display the PNG into the DIBitmap + + DisplayImage (hwnd, &pDib, &pDiData, cxWinSize, cyWinSize, + pbImage, cxImgSize, cyImgSize, cImgChannels, bStretched); + } + + return 0; + + case WM_SIZE: + cxWinSize = LOWORD (lParam); + cyWinSize = HIWORD (lParam); + + // invalidate the client area for later update + + InvalidateRect (hwnd, NULL, TRUE); + + // display the PNG into the DIBitmap + + DisplayImage (hwnd, &pDib, &pDiData, cxWinSize, cyWinSize, + pbImage, cxImgSize, cyImgSize, cImgChannels, bStretched); + + return 0; + + case WM_INITMENUPOPUP: + hMenu = GetMenu (hwnd); + + if (pbImage) + EnableMenuItem (hMenu, IDM_FILE_SAVE, MF_ENABLED); + else + EnableMenuItem (hMenu, IDM_FILE_SAVE, MF_GRAYED); + + return 0; + + case WM_COMMAND: + hMenu = GetMenu (hwnd); + + switch (LOWORD (wParam)) + { + case IDM_FILE_OPEN: + + // show the File Open dialog box + + if (!PngFileOpenDlg (hwnd, szImgPathName, szTitleName)) + return 0; + + // read the other png-files in the directory for later + // next/previous commands + + BuildPngList (szImgPathName, &pPngFileList, &iPngFileCount, + &iPngFileIndex); + + // load the image from file + + if (!LoadImageFile (hwnd, szImgPathName, + &pbImage, &cxImgSize, &cyImgSize, &cImgChannels, &bkgColor)) + return 0; + + // invalidate the client area for later update + + InvalidateRect (hwnd, NULL, TRUE); + + // display the PNG into the DIBitmap + + DisplayImage (hwnd, &pDib, &pDiData, cxWinSize, cyWinSize, + pbImage, cxImgSize, cyImgSize, cImgChannels, bStretched); + + return 0; + + case IDM_FILE_SAVE: + + // show the File Save dialog box + + if (!PngFileSaveDlg (hwnd, szImgPathName, szTitleName)) + return 0; + + // save the PNG to a disk file + + SetCursor (LoadCursor (NULL, IDC_WAIT)); + ShowCursor (TRUE); + + bOk = PngSaveImage (szImgPathName, pDiData, cxWinSize, cyWinSize, + bkgColor); + + ShowCursor (FALSE); + SetCursor (LoadCursor (NULL, IDC_ARROW)); + + if (!bOk) + MessageBox (hwnd, TEXT ("Error in saving the PNG image"), + szProgName, MB_ICONEXCLAMATION | MB_OK); + return 0; + + case IDM_FILE_NEXT: + + // read next entry in the directory + + if (SearchPngList (pPngFileList, iPngFileCount, &iPngFileIndex, + NULL, szImgPathName)) + { + if (strcmp (szImgPathName, "") == 0) + return 0; + + // load the image from file + + if (!LoadImageFile (hwnd, szImgPathName, &pbImage, + &cxImgSize, &cyImgSize, &cImgChannels, &bkgColor)) + return 0; + + // invalidate the client area for later update + + InvalidateRect (hwnd, NULL, TRUE); + + // display the PNG into the DIBitmap + + DisplayImage (hwnd, &pDib, &pDiData, cxWinSize, cyWinSize, + pbImage, cxImgSize, cyImgSize, cImgChannels, bStretched); + } + + return 0; + + case IDM_FILE_PREVIOUS: + + // read previous entry in the directory + + if (SearchPngList (pPngFileList, iPngFileCount, &iPngFileIndex, + szImgPathName, NULL)) + { + + if (strcmp (szImgPathName, "") == 0) + return 0; + + // load the image from file + + if (!LoadImageFile (hwnd, szImgPathName, &pbImage, &cxImgSize, + &cyImgSize, &cImgChannels, &bkgColor)) + return 0; + + // invalidate the client area for later update + + InvalidateRect (hwnd, NULL, TRUE); + + // display the PNG into the DIBitmap + + DisplayImage (hwnd, &pDib, &pDiData, cxWinSize, cyWinSize, + pbImage, cxImgSize, cyImgSize, cImgChannels, bStretched); + } + + return 0; + + case IDM_FILE_EXIT: + + // more cleanup needed... + + // free image buffer + + if (pDib != NULL) + { + free (pDib); + pDib = NULL; + } + + // free file-list + + if (pPngFileList != NULL) + { + free (pPngFileList); + pPngFileList = NULL; + } + + // let's go ... + + exit (0); + + return 0; + + case IDM_OPTIONS_STRETCH: + bStretched = !bStretched; + if (bStretched) + CheckMenuItem (hMenu, IDM_OPTIONS_STRETCH, MF_CHECKED); + else + CheckMenuItem (hMenu, IDM_OPTIONS_STRETCH, MF_UNCHECKED); + + // invalidate the client area for later update + + InvalidateRect (hwnd, NULL, TRUE); + + // display the PNG into the DIBitmap + + DisplayImage (hwnd, &pDib, &pDiData, cxWinSize, cyWinSize, + pbImage, cxImgSize, cyImgSize, cImgChannels, bStretched); + + return 0; + + case IDM_HELP_ABOUT: + DialogBox (hInstance, TEXT ("AboutBox"), hwnd, AboutDlgProc) ; + return 0; + + } // end switch + + break; + + case WM_PAINT: + hdc = BeginPaint (hwnd, &ps); + + if (pDib) + SetDIBitsToDevice (hdc, 0, 0, cxWinSize, cyWinSize, 0, 0, + 0, cyWinSize, pDiData, (BITMAPINFO *) pDib, DIB_RGB_COLORS); + + EndPaint (hwnd, &ps); + return 0; + + case WM_DESTROY: + if (pbmfh) + { + free (pbmfh); + pbmfh = NULL; + } + + PostQuitMessage (0); + return 0; + } + + return DefWindowProc (hwnd, message, wParam, lParam); +} + +BOOL CALLBACK AboutDlgProc (HWND hDlg, UINT message, + WPARAM wParam, LPARAM lParam) +{ + switch (message) + { + case WM_INITDIALOG : + ShowWindow (hDlg, SW_HIDE); + CenterAbout (hDlg, GetWindow (hDlg, GW_OWNER)); + ShowWindow (hDlg, SW_SHOW); + return TRUE ; + + case WM_COMMAND : + switch (LOWORD (wParam)) + { + case IDOK : + case IDCANCEL : + EndDialog (hDlg, 0) ; + return TRUE ; + } + break ; + } + return FALSE ; +} + +//--------------- +// CenterAbout +//--------------- + +BOOL CenterAbout (HWND hwndChild, HWND hwndParent) +{ + RECT rChild, rParent, rWorkArea; + int wChild, hChild, wParent, hParent; + int xNew, yNew; + BOOL bResult; + + // Get the Height and Width of the child window + GetWindowRect (hwndChild, &rChild); + wChild = rChild.right - rChild.left; + hChild = rChild.bottom - rChild.top; + + // Get the Height and Width of the parent window + GetWindowRect (hwndParent, &rParent); + wParent = rParent.right - rParent.left; + hParent = rParent.bottom - rParent.top; + + // Get the limits of the 'workarea' + bResult = SystemParametersInfo( + SPI_GETWORKAREA, // system parameter to query or set + sizeof(RECT), + &rWorkArea, + 0); + if (!bResult) { + rWorkArea.left = rWorkArea.top = 0; + rWorkArea.right = GetSystemMetrics(SM_CXSCREEN); + rWorkArea.bottom = GetSystemMetrics(SM_CYSCREEN); + } + + // Calculate new X position, then adjust for workarea + xNew = rParent.left + ((wParent - wChild) /2); + if (xNew < rWorkArea.left) { + xNew = rWorkArea.left; + } else if ((xNew+wChild) > rWorkArea.right) { + xNew = rWorkArea.right - wChild; + } + + // Calculate new Y position, then adjust for workarea + yNew = rParent.top + ((hParent - hChild) /2); + if (yNew < rWorkArea.top) { + yNew = rWorkArea.top; + } else if ((yNew+hChild) > rWorkArea.bottom) { + yNew = rWorkArea.bottom - hChild; + } + + // Set it, and return + return SetWindowPos (hwndChild, NULL, xNew, yNew, 0, 0, SWP_NOSIZE | + SWP_NOZORDER); +} + +//---------------- +// BuildPngList +//---------------- + +BOOL BuildPngList (PTSTR pstrPathName, TCHAR **ppFileList, int *pFileCount, + int *pFileIndex) +{ + static TCHAR szImgPathName [MAX_PATH]; + static TCHAR szImgFileName [MAX_PATH]; + static TCHAR szImgFindName [MAX_PATH]; + + WIN32_FIND_DATA finddata; + HANDLE hFind; + + static TCHAR szTmp [MAX_PATH]; + BOOL bOk; + int i, ii; + int j, jj; + + // free previous file-list + + if (*ppFileList != NULL) + { + free (*ppFileList); + *ppFileList = NULL; + } + + // extract foldername, filename and search-name + + strcpy (szImgPathName, pstrPathName); + strcpy (szImgFileName, strrchr (pstrPathName, '\\') + 1); + + strcpy (szImgFindName, szImgPathName); + *(strrchr (szImgFindName, '\\') + 1) = '\0'; + strcat (szImgFindName, "*.png"); + + // first cycle: count number of files in directory for memory allocation + + *pFileCount = 0; + + hFind = FindFirstFile(szImgFindName, &finddata); + bOk = (hFind != (HANDLE) -1); + + while (bOk) + { + *pFileCount += 1; + bOk = FindNextFile(hFind, &finddata); + } + FindClose(hFind); + + // allocation memory for file-list + + *ppFileList = (TCHAR *) malloc (*pFileCount * MAX_PATH); + + // second cycle: read directory and store filenames in file-list + + hFind = FindFirstFile(szImgFindName, &finddata); + bOk = (hFind != (HANDLE) -1); + + i = 0; + ii = 0; + while (bOk) + { + strcpy (*ppFileList + ii, szImgPathName); + strcpy (strrchr(*ppFileList + ii, '\\') + 1, finddata.cFileName); + + if (strcmp(pstrPathName, *ppFileList + ii) == 0) + *pFileIndex = i; + + ii += MAX_PATH; + i++; + + bOk = FindNextFile(hFind, &finddata); + } + FindClose(hFind); + + // finally we must sort the file-list + + for (i = 0; i < *pFileCount - 1; i++) + { + ii = i * MAX_PATH; + for (j = i+1; j < *pFileCount; j++) + { + jj = j * MAX_PATH; + if (strcmp (*ppFileList + ii, *ppFileList + jj) > 0) + { + strcpy (szTmp, *ppFileList + jj); + strcpy (*ppFileList + jj, *ppFileList + ii); + strcpy (*ppFileList + ii, szTmp); + + // check if this was the current image that we moved + + if (*pFileIndex == i) + *pFileIndex = j; + else + if (*pFileIndex == j) + *pFileIndex = i; + } + } + } + + return TRUE; +} + +//---------------- +// SearchPngList +//---------------- + +BOOL SearchPngList ( + TCHAR *pFileList, int FileCount, int *pFileIndex, + PTSTR pstrPrevName, PTSTR pstrNextName) +{ + if (FileCount > 0) + { + // get previous entry + + if (pstrPrevName != NULL) + { + if (*pFileIndex > 0) + *pFileIndex -= 1; + else + *pFileIndex = FileCount - 1; + + strcpy (pstrPrevName, pFileList + (*pFileIndex * MAX_PATH)); + } + + // get next entry + + if (pstrNextName != NULL) + { + if (*pFileIndex < FileCount - 1) + *pFileIndex += 1; + else + *pFileIndex = 0; + + strcpy (pstrNextName, pFileList + (*pFileIndex * MAX_PATH)); + } + + return TRUE; + } + else + { + return FALSE; + } +} + +//----------------- +// LoadImageFile +//----------------- + +BOOL LoadImageFile (HWND hwnd, PTSTR pstrPathName, + png_byte **ppbImage, int *pxImgSize, int *pyImgSize, + int *piChannels, png_color *pBkgColor) +{ + static TCHAR szTmp [MAX_PATH]; + + // if there's an existing PNG, free the memory + + if (*ppbImage) + { + free (*ppbImage); + *ppbImage = NULL; + } + + // Load the entire PNG into memory + + SetCursor (LoadCursor (NULL, IDC_WAIT)); + ShowCursor (TRUE); + + PngLoadImage (pstrPathName, ppbImage, pxImgSize, pyImgSize, piChannels, + pBkgColor); + + ShowCursor (FALSE); + SetCursor (LoadCursor (NULL, IDC_ARROW)); + + if (*ppbImage != NULL) + { + sprintf (szTmp, "VisualPng - %s", strrchr(pstrPathName, '\\') + 1); + SetWindowText (hwnd, szTmp); + } + else + { + MessageBox (hwnd, TEXT ("Error in loading the PNG image"), + szProgName, MB_ICONEXCLAMATION | MB_OK); + return FALSE; + } + + return TRUE; +} + +//---------------- +// DisplayImage +//---------------- + +BOOL DisplayImage (HWND hwnd, BYTE **ppDib, + BYTE **ppDiData, int cxWinSize, int cyWinSize, + BYTE *pbImage, int cxImgSize, int cyImgSize, int cImgChannels, + BOOL bStretched) +{ + BYTE *pDib = *ppDib; + BYTE *pDiData = *ppDiData; + // BITMAPFILEHEADER *pbmfh; + BITMAPINFOHEADER *pbmih; + WORD wDIRowBytes; + png_color bkgBlack = {0, 0, 0}; + png_color bkgGray = {127, 127, 127}; + png_color bkgWhite = {255, 255, 255}; + + // allocate memory for the Device Independant bitmap + + wDIRowBytes = (WORD) ((3 * cxWinSize + 3L) >> 2) << 2; + + if (pDib) + { + free (pDib); + pDib = NULL; + } + + if (!(pDib = (BYTE *) malloc (sizeof(BITMAPINFOHEADER) + + wDIRowBytes * cyWinSize))) + { + MessageBox (hwnd, TEXT ("Error in displaying the PNG image"), + szProgName, MB_ICONEXCLAMATION | MB_OK); + *ppDib = pDib = NULL; + return FALSE; + } + *ppDib = pDib; + memset (pDib, 0, sizeof(BITMAPINFOHEADER)); + + // initialize the dib-structure + + pbmih = (BITMAPINFOHEADER *) pDib; + pbmih->biSize = sizeof(BITMAPINFOHEADER); + pbmih->biWidth = cxWinSize; + pbmih->biHeight = -((long) cyWinSize); + pbmih->biPlanes = 1; + pbmih->biBitCount = 24; + pbmih->biCompression = 0; + pDiData = pDib + sizeof(BITMAPINFOHEADER); + *ppDiData = pDiData; + + // first fill bitmap with gray and image border + + InitBitmap (pDiData, cxWinSize, cyWinSize); + + // then fill bitmap with image + + if (pbImage) + { + FillBitmap ( + pDiData, cxWinSize, cyWinSize, + pbImage, cxImgSize, cyImgSize, cImgChannels, + bStretched); + } + + return TRUE; +} + +//-------------- +// InitBitmap +//-------------- + +BOOL InitBitmap (BYTE *pDiData, int cxWinSize, int cyWinSize) +{ + BYTE *dst; + int x, y, col; + + // initialize the background with gray + + dst = pDiData; + for (y = 0; y < cyWinSize; y++) + { + col = 0; + for (x = 0; x < cxWinSize; x++) + { + // fill with GRAY + *dst++ = 127; + *dst++ = 127; + *dst++ = 127; + col += 3; + } + // rows start on 4 byte boundaries + while ((col % 4) != 0) + { + dst++; + col++; + } + } + + return TRUE; +} + +//-------------- +// FillBitmap +//-------------- + +BOOL FillBitmap ( + BYTE *pDiData, int cxWinSize, int cyWinSize, + BYTE *pbImage, int cxImgSize, int cyImgSize, int cImgChannels, + BOOL bStretched) +{ + BYTE *pStretchedImage; + BYTE *pImg; + BYTE *src, *dst; + BYTE r, g, b, a; + const int cDIChannels = 3; + WORD wImgRowBytes; + WORD wDIRowBytes; + int cxNewSize, cyNewSize; + int cxImgPos, cyImgPos; + int xImg, yImg; + int xWin, yWin; + int xOld, yOld; + int xNew, yNew; + + if (bStretched) + { + cxNewSize = cxWinSize - 2 * MARGIN; + cyNewSize = cyWinSize - 2 * MARGIN; + + // stretch the image to it's window determined size + + // the following two are the same, but the first has side-effects + // because of rounding +// if ((cyNewSize / cxNewSize) > (cyImgSize / cxImgSize)) + if ((cyNewSize * cxImgSize) > (cyImgSize * cxNewSize)) + { + cyNewSize = cxNewSize * cyImgSize / cxImgSize; + cxImgPos = MARGIN; + cyImgPos = (cyWinSize - cyNewSize) / 2; + } + else + { + cxNewSize = cyNewSize * cxImgSize / cyImgSize; + cyImgPos = MARGIN; + cxImgPos = (cxWinSize - cxNewSize) / 2; + } + + pStretchedImage = malloc (cImgChannels * cxNewSize * cyNewSize); + pImg = pStretchedImage; + + for (yNew = 0; yNew < cyNewSize; yNew++) + { + yOld = yNew * cyImgSize / cyNewSize; + for (xNew = 0; xNew < cxNewSize; xNew++) + { + xOld = xNew * cxImgSize / cxNewSize; + + r = *(pbImage + cImgChannels * ((yOld * cxImgSize) + xOld) + 0); + g = *(pbImage + cImgChannels * ((yOld * cxImgSize) + xOld) + 1); + b = *(pbImage + cImgChannels * ((yOld * cxImgSize) + xOld) + 2); + *pImg++ = r; + *pImg++ = g; + *pImg++ = b; + if (cImgChannels == 4) + { + a = *(pbImage + cImgChannels * ((yOld * cxImgSize) + xOld) + + 3); + *pImg++ = a; + } + } + } + + // calculate row-bytes + + wImgRowBytes = cImgChannels * cxNewSize; + wDIRowBytes = (WORD) ((cDIChannels * cxWinSize + 3L) >> 2) << 2; + + // copy image to screen + + for (yImg = 0, yWin = cyImgPos; yImg < cyNewSize; yImg++, yWin++) + { + if (yWin >= cyWinSize - cyImgPos) + break; + src = pStretchedImage + yImg * wImgRowBytes; + dst = pDiData + yWin * wDIRowBytes + cxImgPos * cDIChannels; + + for (xImg = 0, xWin = cxImgPos; xImg < cxNewSize; xImg++, xWin++) + { + if (xWin >= cxWinSize - cxImgPos) + break; + r = *src++; + g = *src++; + b = *src++; + *dst++ = b; /* note the reverse order */ + *dst++ = g; + *dst++ = r; + if (cImgChannels == 4) + { + a = *src++; + } + } + } + + // free memory + + if (pStretchedImage != NULL) + { + free (pStretchedImage); + pStretchedImage = NULL; + } + + } + + // process the image not-stretched + + else + { + // calculate the central position + + cxImgPos = (cxWinSize - cxImgSize) / 2; + cyImgPos = (cyWinSize - cyImgSize) / 2; + + // check for image larger than window + + if (cxImgPos < MARGIN) + cxImgPos = MARGIN; + if (cyImgPos < MARGIN) + cyImgPos = MARGIN; + + // calculate both row-bytes + + wImgRowBytes = cImgChannels * cxImgSize; + wDIRowBytes = (WORD) ((cDIChannels * cxWinSize + 3L) >> 2) << 2; + + // copy image to screen + + for (yImg = 0, yWin = cyImgPos; yImg < cyImgSize; yImg++, yWin++) + { + if (yWin >= cyWinSize - MARGIN) + break; + src = pbImage + yImg * wImgRowBytes; + dst = pDiData + yWin * wDIRowBytes + cxImgPos * cDIChannels; + + for (xImg = 0, xWin = cxImgPos; xImg < cxImgSize; xImg++, xWin++) + { + if (xWin >= cxWinSize - MARGIN) + break; + r = *src++; + g = *src++; + b = *src++; + *dst++ = b; /* note the reverse order */ + *dst++ = g; + *dst++ = r; + if (cImgChannels == 4) + { + a = *src++; + } + } + } + } + + return TRUE; +} + +//----------------- +// end of source +//----------------- diff --git a/libs/libpng-src/contrib/visupng/VisualPng.dsp b/libs/libpng-src/contrib/visupng/VisualPng.dsp new file mode 100644 index 000000000..53ef5a2bc --- /dev/null +++ b/libs/libpng-src/contrib/visupng/VisualPng.dsp @@ -0,0 +1,147 @@ +# Microsoft Developer Studio Project File - Name="VisualPng" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Application" 0x0101 + +CFG=VisualPng - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "VisualPng.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "VisualPng.mak" CFG="VisualPng - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "VisualPng - Win32 Release" (based on "Win32 (x86) Application") +!MESSAGE "VisualPng - Win32 Debug" (based on "Win32 (x86) Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "VisualPng - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Ignore_Export_Lib 0 +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /O2 /I "..\.." /I "..\..\..\zlib" /D "WIN32" /D "NDEBUG" /D "PNG_NO_STDIO" /D "PNG_NO_GLOBAL_ARRAYS" /FD /c +# SUBTRACT BASE CPP /YX +# ADD CPP /nologo /MD /W3 /O2 /I "..\.." /I "..\..\..\zlib" /D "WIN32" /D "NDEBUG" /D "PNG_NO_STDIO" /D "PNG_NO_GLOBAL_ARRAYS" /FD /c +# SUBTRACT CPP /YX +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386 +# ADD LINK32 ..\..\projects\visualc6\Win32_LIB_Release\libpng.lib ..\..\..\zlib\projects\visualc6\Win32_LIB_Release\zlib.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386 +# Begin Special Build Tool +OutDir=.\Release +SOURCE="$(InputPath)" +PostBuild_Cmds=$(outdir)\VisualPng.exe ..\..\contrib\pngsuite\basn6a16.png +# End Special Build Tool + +!ELSEIF "$(CFG)" == "VisualPng - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Ignore_Export_Lib 0 +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /ZI /Od /I "..\.." /I "..\..\..\zlib" /D "WIN32" /D "_DEBUG" /D "PNG_NO_STDIO" /D "PNG_NO_GLOBAL_ARRAYS" /FD /GZ /c +# SUBTRACT BASE CPP /YX +# ADD CPP /nologo /MDd /W3 /Gm /ZI /Od /I "..\.." /I "..\..\..\zlib" /D "WIN32" /D "_DEBUG" /D "PNG_NO_STDIO" /D "PNG_NO_GLOBAL_ARRAYS" /FD /GZ /c +# SUBTRACT CPP /YX +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept +# ADD LINK32 ..\..\projects\visualc6\Win32_LIB_Release\libpng.lib ..\..\..\zlib\projects\visualc6\Win32_LIB_Release\zlib.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /nodefaultlib:"msvcrt.lib" /pdbtype:sept +# Begin Special Build Tool +OutDir=.\Debug +SOURCE="$(InputPath)" +PostBuild_Cmds=$(outdir)\VisualPng.exe ..\..\contrib\pngsuite\basn6a16.png +# End Special Build Tool + +!ENDIF + +# Begin Target + +# Name "VisualPng - Win32 Release" +# Name "VisualPng - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\PngFile.c +# End Source File +# Begin Source File + +SOURCE=.\VisualPng.c +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# Begin Source File + +SOURCE=.\cexcept.h +# End Source File +# Begin Source File + +SOURCE=.\PngFile.h +# End Source File +# Begin Source File + +SOURCE=.\resource.h +# End Source File +# End Group +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# Begin Source File + +SOURCE=.\VisualPng.ico +# End Source File +# Begin Source File + +SOURCE=.\VisualPng.rc +# End Source File +# End Group +# End Target +# End Project diff --git a/libs/libpng-src/contrib/visupng/VisualPng.dsw b/libs/libpng-src/contrib/visupng/VisualPng.dsw new file mode 100644 index 000000000..a30e1cc1c --- /dev/null +++ b/libs/libpng-src/contrib/visupng/VisualPng.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00 +# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! + +############################################################################### + +Project: "VisualPng"=.\VisualPng.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/libs/libpng-src/contrib/visupng/VisualPng.ico b/libs/libpng-src/contrib/visupng/VisualPng.ico new file mode 100644 index 000000000..68aa3719f Binary files /dev/null and b/libs/libpng-src/contrib/visupng/VisualPng.ico differ diff --git a/libs/libpng-src/contrib/visupng/VisualPng.png b/libs/libpng-src/contrib/visupng/VisualPng.png new file mode 100644 index 000000000..c6aa80a9b Binary files /dev/null and b/libs/libpng-src/contrib/visupng/VisualPng.png differ diff --git a/libs/libpng-src/contrib/visupng/VisualPng.rc b/libs/libpng-src/contrib/visupng/VisualPng.rc new file mode 100644 index 000000000..151c68c47 --- /dev/null +++ b/libs/libpng-src/contrib/visupng/VisualPng.rc @@ -0,0 +1,152 @@ +//Microsoft Developer Studio generated resource script. +// +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "afxres.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (U.S.) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +#ifdef _WIN32 +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US +#pragma code_page(1252) +#endif //_WIN32 + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE DISCARDABLE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE DISCARDABLE +BEGIN + "#include ""afxres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE DISCARDABLE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// Menu +// + +VISUALPNG MENU DISCARDABLE +BEGIN + POPUP "&File" + BEGIN + MENUITEM "&Open Image...\tCtrl+O", IDM_FILE_OPEN + MENUITEM "Save &As...", IDM_FILE_SAVE + MENUITEM SEPARATOR + MENUITEM "&Next Image\tCtrl+N", IDM_FILE_NEXT + MENUITEM "Pre&vious Image\tCtrl+V", IDM_FILE_PREVIOUS + MENUITEM SEPARATOR + MENUITEM "E&xit\tAlt+X", IDM_FILE_EXIT + END + POPUP "&Options" + BEGIN + MENUITEM "&Stretch", IDM_OPTIONS_STRETCH, CHECKED + END + POPUP "&Help" + BEGIN + MENUITEM "&About", IDM_HELP_ABOUT + END +END + + +///////////////////////////////////////////////////////////////////////////// +// +// Accelerator +// + +VISUALPNG ACCELERATORS DISCARDABLE +BEGIN + "N", IDM_FILE_NEXT, VIRTKEY, CONTROL, NOINVERT + "O", IDM_FILE_OPEN, VIRTKEY, CONTROL, NOINVERT + "P", IDM_FILE_PREVIOUS, VIRTKEY, CONTROL, NOINVERT + "V", IDM_FILE_PREVIOUS, VIRTKEY, CONTROL, NOINVERT + "X", IDM_FILE_EXIT, VIRTKEY, ALT, NOINVERT +END + + +///////////////////////////////////////////////////////////////////////////// +// +// Icon +// + +// Icon with lowest ID value placed first to ensure application icon +// remains consistent on all systems. +VISUALPNG ICON DISCARDABLE "VisualPng.ico" + +///////////////////////////////////////////////////////////////////////////// +// +// Dialog +// + +ABOUTBOX DIALOG DISCARDABLE 0, 0, 186, 94 +STYLE DS_MODALFRAME | WS_POPUP +FONT 8, "MS Sans Serif" +BEGIN + DEFPUSHBUTTON "OK",IDOK,68,67,50,14 + CTEXT "VisualPng 1.0 - June 2000",IDC_STATIC,49,14,88,8 + LTEXT "a PNG image viewer",IDC_STATIC,60,30,66,8 + LTEXT "(c) Willem van Schaik, 2000",IDC_STATIC,48,52,90,8 + LTEXT "to demonstrate the use of libpng in Visual C", + IDC_STATIC,25,38,136,8 +END + + +///////////////////////////////////////////////////////////////////////////// +// +// DESIGNINFO +// + +#ifdef APSTUDIO_INVOKED +GUIDELINES DESIGNINFO DISCARDABLE +BEGIN + "ABOUTBOX", DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 179 + TOPMARGIN, 7 + BOTTOMMARGIN, 87 + END +END +#endif // APSTUDIO_INVOKED + +#endif // English (U.S.) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/libs/libpng-src/contrib/visupng/cexcept.h b/libs/libpng-src/contrib/visupng/cexcept.h new file mode 100644 index 000000000..5f45d7697 --- /dev/null +++ b/libs/libpng-src/contrib/visupng/cexcept.h @@ -0,0 +1,248 @@ +/*=== +cexcept.h 2.0.1 (2008-Jul-19-Sat) +http://www.nicemice.net/cexcept/ +Adam M. Costello +http://www.nicemice.net/amc/ + +An interface for exception-handling in ANSI C (C89 and subsequent ISO +standards), developed jointly with Cosmin Truta. + + Copyright (c) 2000-2008 Adam M. Costello and Cosmin Truta. + This software may be modified only if its author and version + information is updated accurately, and may be redistributed + only if accompanied by this unaltered notice. Subject to those + restrictions, permission is granted to anyone to do anything + with this software. The copyright holders make no guarantees + regarding this software, and are not responsible for any damage + resulting from its use. + +The cexcept interface is not compatible with and cannot interact +with system exceptions (like division by zero or memory segmentation +violation), compiler-generated exceptions (like C++ exceptions), or +other exception-handling interfaces. + +When using this interface across multiple .c files, do not include +this header file directly. Instead, create a wrapper header file that +includes this header file and then invokes the define_exception_type +macro (see below). The .c files should then include that header file. + +The interface consists of one type, one well-known name, and six macros. + + +define_exception_type(type_name); + + This macro is used like an external declaration. It specifies + the type of object that gets copied from the exception thrower to + the exception catcher. The type_name can be any type that can be + assigned to, that is, a non-constant arithmetic type, struct, union, + or pointer. Examples: + + define_exception_type(int); + + enum exception { out_of_memory, bad_arguments, disk_full }; + define_exception_type(enum exception); + + struct exception { int code; const char *msg; }; + define_exception_type(struct exception); + + Because throwing an exception causes the object to be copied (not + just once, but twice), programmers may wish to consider size when + choosing the exception type. + + +struct exception_context; + + This type may be used after the define_exception_type() macro has + been invoked. A struct exception_context must be known to both + the thrower and the catcher. It is expected that there be one + context for each thread that uses exceptions. It would certainly + be dangerous for multiple threads to access the same context. + One thread can use multiple contexts, but that is likely to be + confusing and not typically useful. The application can allocate + this structure in any way it pleases--automatic, static, or dynamic. + The application programmer should pretend not to know the structure + members, which are subject to change. + + +struct exception_context *the_exception_context; + + The Try/Catch and Throw statements (described below) implicitly + refer to a context, using the name the_exception_context. It is + the application's responsibility to make sure that this name yields + the address of a mutable (non-constant) struct exception_context + wherever those statements are used. Subject to that constraint, the + application may declare a variable of this name anywhere it likes + (inside a function, in a parameter list, or externally), and may + use whatever storage class specifiers (static, extern, etc) or type + qualifiers (const, volatile, etc) it likes. Examples: + + static struct exception_context + * const the_exception_context = &foo; + + { struct exception_context *the_exception_context = bar; ... } + + int blah(struct exception_context *the_exception_context, ...); + + extern struct exception_context the_exception_context[1]; + + The last example illustrates a trick that avoids creating a pointer + object separate from the structure object. + + The name could even be a macro, for example: + + struct exception_context ec_array[numthreads]; + #define the_exception_context (ec_array + thread_id) + + Be aware that the_exception_context is used several times by the + Try/Catch/Throw macros, so it shouldn't be expensive or have side + effects. The expansion must be a drop-in replacement for an + identifier, so it's safest to put parentheses around it. + + +void init_exception_context(struct exception_context *ec); + + For context structures allocated statically (by an external + definition or using the "static" keyword), the implicit + initialization to all zeros is sufficient, but contexts allocated + by other means must be initialized using this macro before they + are used by a Try/Catch statement. It does no harm to initialize + a context more than once (by using this macro on a statically + allocated context, or using this macro twice on the same context), + but a context must not be re-initialized after it has been used by a + Try/Catch statement. + + +Try statement +Catch (expression) statement + + The Try/Catch/Throw macros are capitalized in order to avoid + confusion with the C++ keywords, which have subtly different + semantics. + + A Try/Catch statement has a syntax similar to an if/else statement, + except that the parenthesized expression goes after the second + keyword rather than the first. As with if/else, there are two + clauses, each of which may be a simple statement ending with a + semicolon or a brace-enclosed compound statement. But whereas + the else clause is optional, the Catch clause is required. The + expression must be a modifiable lvalue (something capable of being + assigned to) of the same type (disregarding type qualifiers) that + was passed to define_exception_type(). + + If a Throw that uses the same exception context as the Try/Catch is + executed within the Try clause (typically within a function called + by the Try clause), and the exception is not caught by a nested + Try/Catch statement, then a copy of the exception will be assigned + to the expression, and control will jump to the Catch clause. If no + such Throw is executed, then the assignment is not performed, and + the Catch clause is not executed. + + The expression is not evaluated unless and until the exception is + caught, which is significant if it has side effects, for example: + + Try foo(); + Catch (p[++i].e) { ... } + + IMPORTANT: Jumping into or out of a Try clause (for example via + return, break, continue, goto, longjmp) is forbidden--the compiler + will not complain, but bad things will happen at run-time. Jumping + into or out of a Catch clause is okay, and so is jumping around + inside a Try clause. In many cases where one is tempted to return + from a Try clause, it will suffice to use Throw, and then return + from the Catch clause. Another option is to set a flag variable and + use goto to jump to the end of the Try clause, then check the flag + after the Try/Catch statement. + + IMPORTANT: The values of any non-volatile automatic variables + changed within the Try clause are undefined after an exception is + caught. Therefore, variables modified inside the Try block whose + values are needed later outside the Try block must either use static + storage or be declared with the "volatile" type qualifier. + + +Throw expression; + + A Throw statement is very much like a return statement, except that + the expression is required. Whereas return jumps back to the place + where the current function was called, Throw jumps back to the Catch + clause of the innermost enclosing Try clause. The expression must + be compatible with the type passed to define_exception_type(). The + exception must be caught, otherwise the program may crash. + + Slight limitation: If the expression is a comma-expression, it must + be enclosed in parentheses. + + +Try statement +Catch_anonymous statement + + When the value of the exception is not needed, a Try/Catch statement + can use Catch_anonymous instead of Catch (expression). + + +Everything below this point is for the benefit of the compiler. The +application programmer should pretend not to know any of it, because it +is subject to change. + +===*/ + + +#ifndef CEXCEPT_H +#define CEXCEPT_H + + +#include + +#define define_exception_type(etype) \ +struct exception_context { \ + jmp_buf *penv; \ + int caught; \ + volatile struct { etype etmp; } v; \ +} + +/* etmp must be volatile because the application might use automatic */ +/* storage for the_exception_context, and etmp is modified between */ +/* the calls to setjmp() and longjmp(). A wrapper struct is used to */ +/* avoid warnings about a duplicate volatile qualifier in case etype */ +/* already includes it. */ + +#define init_exception_context(ec) ((void)((ec)->penv = 0)) + +#define Try \ + { \ + jmp_buf *exception__prev, exception__env; \ + exception__prev = the_exception_context->penv; \ + the_exception_context->penv = &exception__env; \ + if (setjmp(exception__env) == 0) { \ + do + +#define exception__catch(action) \ + while (the_exception_context->caught = 0, \ + the_exception_context->caught); \ + } \ + else { \ + the_exception_context->caught = 1; \ + } \ + the_exception_context->penv = exception__prev; \ + } \ + if (!the_exception_context->caught || action) { } \ + else + +#define Catch(e) exception__catch(((e) = the_exception_context->v.etmp, 0)) +#define Catch_anonymous exception__catch(0) + +/* Try ends with do, and Catch begins with while(0) and ends with */ +/* else, to ensure that Try/Catch syntax is similar to if/else */ +/* syntax. */ +/* */ +/* The 0 in while(0) is expressed as x=0,x in order to appease */ +/* compilers that warn about constant expressions inside while(). */ +/* Most compilers should still recognize that the condition is always */ +/* false and avoid generating code for it. */ + +#define Throw \ + for (;; longjmp(*the_exception_context->penv, 1)) \ + the_exception_context->v.etmp = + + +#endif /* CEXCEPT_H */ diff --git a/libs/libpng-src/contrib/visupng/resource.h b/libs/libpng-src/contrib/visupng/resource.h new file mode 100644 index 000000000..611dd035f --- /dev/null +++ b/libs/libpng-src/contrib/visupng/resource.h @@ -0,0 +1,23 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Developer Studio generated include file. +// Used by VisualPng.rc +// +#define IDM_FILE_OPEN 40001 +#define IDM_FILE_SAVE 40002 +#define IDM_FILE_NEXT 40003 +#define IDM_FILE_PREVIOUS 40004 +#define IDM_FILE_EXIT 40005 +#define IDM_OPTIONS_BACKGROUND 40006 +#define IDM_OPTIONS_STRETCH 40007 +#define IDM_HELP_ABOUT 40008 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 113 +#define _APS_NEXT_COMMAND_VALUE 40009 +#define _APS_NEXT_CONTROL_VALUE 1001 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/libs/libpng-src/depcomp b/libs/libpng-src/depcomp new file mode 100755 index 000000000..df8eea7e4 --- /dev/null +++ b/libs/libpng-src/depcomp @@ -0,0 +1,630 @@ +#! /bin/sh +# depcomp - compile a program generating dependencies as side-effects + +scriptversion=2009-04-28.21; # UTC + +# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2006, 2007, 2009 Free +# Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + +# Originally written by Alexandre Oliva . + +case $1 in + '') + echo "$0: No command. Try \`$0 --help' for more information." 1>&2 + exit 1; + ;; + -h | --h*) + cat <<\EOF +Usage: depcomp [--help] [--version] PROGRAM [ARGS] + +Run PROGRAMS ARGS to compile a file, generating dependencies +as side-effects. + +Environment variables: + depmode Dependency tracking mode. + source Source file read by `PROGRAMS ARGS'. + object Object file output by `PROGRAMS ARGS'. + DEPDIR directory where to store dependencies. + depfile Dependency file to output. + tmpdepfile Temporary file to use when outputing dependencies. + libtool Whether libtool is used (yes/no). + +Report bugs to . +EOF + exit $? + ;; + -v | --v*) + echo "depcomp $scriptversion" + exit $? + ;; +esac + +if test -z "$depmode" || test -z "$source" || test -z "$object"; then + echo "depcomp: Variables source, object and depmode must be set" 1>&2 + exit 1 +fi + +# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. +depfile=${depfile-`echo "$object" | + sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} +tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} + +rm -f "$tmpdepfile" + +# Some modes work just like other modes, but use different flags. We +# parameterize here, but still list the modes in the big case below, +# to make depend.m4 easier to write. Note that we *cannot* use a case +# here, because this file can only contain one case statement. +if test "$depmode" = hp; then + # HP compiler uses -M and no extra arg. + gccflag=-M + depmode=gcc +fi + +if test "$depmode" = dashXmstdout; then + # This is just like dashmstdout with a different argument. + dashmflag=-xM + depmode=dashmstdout +fi + +cygpath_u="cygpath -u -f -" +if test "$depmode" = msvcmsys; then + # This is just like msvisualcpp but w/o cygpath translation. + # Just convert the backslash-escaped backslashes to single forward + # slashes to satisfy depend.m4 + cygpath_u="sed s,\\\\\\\\,/,g" + depmode=msvisualcpp +fi + +case "$depmode" in +gcc3) +## gcc 3 implements dependency tracking that does exactly what +## we want. Yay! Note: for some reason libtool 1.4 doesn't like +## it if -MD -MP comes after the -MF stuff. Hmm. +## Unfortunately, FreeBSD c89 acceptance of flags depends upon +## the command line argument order; so add the flags where they +## appear in depend2.am. Note that the slowdown incurred here +## affects only configure: in makefiles, %FASTDEP% shortcuts this. + for arg + do + case $arg in + -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; + *) set fnord "$@" "$arg" ;; + esac + shift # fnord + shift # $arg + done + "$@" + stat=$? + if test $stat -eq 0; then : + else + rm -f "$tmpdepfile" + exit $stat + fi + mv "$tmpdepfile" "$depfile" + ;; + +gcc) +## There are various ways to get dependency output from gcc. Here's +## why we pick this rather obscure method: +## - Don't want to use -MD because we'd like the dependencies to end +## up in a subdir. Having to rename by hand is ugly. +## (We might end up doing this anyway to support other compilers.) +## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like +## -MM, not -M (despite what the docs say). +## - Using -M directly means running the compiler twice (even worse +## than renaming). + if test -z "$gccflag"; then + gccflag=-MD, + fi + "$@" -Wp,"$gccflag$tmpdepfile" + stat=$? + if test $stat -eq 0; then : + else + rm -f "$tmpdepfile" + exit $stat + fi + rm -f "$depfile" + echo "$object : \\" > "$depfile" + alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz +## The second -e expression handles DOS-style file names with drive letters. + sed -e 's/^[^:]*: / /' \ + -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" +## This next piece of magic avoids the `deleted header file' problem. +## The problem is that when a header file which appears in a .P file +## is deleted, the dependency causes make to die (because there is +## typically no way to rebuild the header). We avoid this by adding +## dummy dependencies for each header file. Too bad gcc doesn't do +## this for us directly. + tr ' ' ' +' < "$tmpdepfile" | +## Some versions of gcc put a space before the `:'. On the theory +## that the space means something, we add a space to the output as +## well. +## Some versions of the HPUX 10.20 sed can't process this invocation +## correctly. Breaking it into two sed invocations is a workaround. + sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile" + rm -f "$tmpdepfile" + ;; + +hp) + # This case exists only to let depend.m4 do its work. It works by + # looking at the text of this script. This case will never be run, + # since it is checked for above. + exit 1 + ;; + +sgi) + if test "$libtool" = yes; then + "$@" "-Wp,-MDupdate,$tmpdepfile" + else + "$@" -MDupdate "$tmpdepfile" + fi + stat=$? + if test $stat -eq 0; then : + else + rm -f "$tmpdepfile" + exit $stat + fi + rm -f "$depfile" + + if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files + echo "$object : \\" > "$depfile" + + # Clip off the initial element (the dependent). Don't try to be + # clever and replace this with sed code, as IRIX sed won't handle + # lines with more than a fixed number of characters (4096 in + # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; + # the IRIX cc adds comments like `#:fec' to the end of the + # dependency line. + tr ' ' ' +' < "$tmpdepfile" \ + | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \ + tr ' +' ' ' >> "$depfile" + echo >> "$depfile" + + # The second pass generates a dummy entry for each header file. + tr ' ' ' +' < "$tmpdepfile" \ + | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ + >> "$depfile" + else + # The sourcefile does not contain any dependencies, so just + # store a dummy comment line, to avoid errors with the Makefile + # "include basename.Plo" scheme. + echo "#dummy" > "$depfile" + fi + rm -f "$tmpdepfile" + ;; + +aix) + # The C for AIX Compiler uses -M and outputs the dependencies + # in a .u file. In older versions, this file always lives in the + # current directory. Also, the AIX compiler puts `$object:' at the + # start of each line; $object doesn't have directory information. + # Version 6 uses the directory in both cases. + dir=`echo "$object" | sed -e 's|/[^/]*$|/|'` + test "x$dir" = "x$object" && dir= + base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'` + if test "$libtool" = yes; then + tmpdepfile1=$dir$base.u + tmpdepfile2=$base.u + tmpdepfile3=$dir.libs/$base.u + "$@" -Wc,-M + else + tmpdepfile1=$dir$base.u + tmpdepfile2=$dir$base.u + tmpdepfile3=$dir$base.u + "$@" -M + fi + stat=$? + + if test $stat -eq 0; then : + else + rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" + exit $stat + fi + + for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" + do + test -f "$tmpdepfile" && break + done + if test -f "$tmpdepfile"; then + # Each line is of the form `foo.o: dependent.h'. + # Do two passes, one to just change these to + # `$object: dependent.h' and one to simply `dependent.h:'. + sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile" + # That's a tab and a space in the []. + sed -e 's,^.*\.[a-z]*:[ ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile" + else + # The sourcefile does not contain any dependencies, so just + # store a dummy comment line, to avoid errors with the Makefile + # "include basename.Plo" scheme. + echo "#dummy" > "$depfile" + fi + rm -f "$tmpdepfile" + ;; + +icc) + # Intel's C compiler understands `-MD -MF file'. However on + # icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c + # ICC 7.0 will fill foo.d with something like + # foo.o: sub/foo.c + # foo.o: sub/foo.h + # which is wrong. We want: + # sub/foo.o: sub/foo.c + # sub/foo.o: sub/foo.h + # sub/foo.c: + # sub/foo.h: + # ICC 7.1 will output + # foo.o: sub/foo.c sub/foo.h + # and will wrap long lines using \ : + # foo.o: sub/foo.c ... \ + # sub/foo.h ... \ + # ... + + "$@" -MD -MF "$tmpdepfile" + stat=$? + if test $stat -eq 0; then : + else + rm -f "$tmpdepfile" + exit $stat + fi + rm -f "$depfile" + # Each line is of the form `foo.o: dependent.h', + # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. + # Do two passes, one to just change these to + # `$object: dependent.h' and one to simply `dependent.h:'. + sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" + # Some versions of the HPUX 10.20 sed can't process this invocation + # correctly. Breaking it into two sed invocations is a workaround. + sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" | + sed -e 's/$/ :/' >> "$depfile" + rm -f "$tmpdepfile" + ;; + +hp2) + # The "hp" stanza above does not work with aCC (C++) and HP's ia64 + # compilers, which have integrated preprocessors. The correct option + # to use with these is +Maked; it writes dependencies to a file named + # 'foo.d', which lands next to the object file, wherever that + # happens to be. + # Much of this is similar to the tru64 case; see comments there. + dir=`echo "$object" | sed -e 's|/[^/]*$|/|'` + test "x$dir" = "x$object" && dir= + base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'` + if test "$libtool" = yes; then + tmpdepfile1=$dir$base.d + tmpdepfile2=$dir.libs/$base.d + "$@" -Wc,+Maked + else + tmpdepfile1=$dir$base.d + tmpdepfile2=$dir$base.d + "$@" +Maked + fi + stat=$? + if test $stat -eq 0; then : + else + rm -f "$tmpdepfile1" "$tmpdepfile2" + exit $stat + fi + + for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" + do + test -f "$tmpdepfile" && break + done + if test -f "$tmpdepfile"; then + sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile" + # Add `dependent.h:' lines. + sed -ne '2,${ + s/^ *// + s/ \\*$// + s/$/:/ + p + }' "$tmpdepfile" >> "$depfile" + else + echo "#dummy" > "$depfile" + fi + rm -f "$tmpdepfile" "$tmpdepfile2" + ;; + +tru64) + # The Tru64 compiler uses -MD to generate dependencies as a side + # effect. `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'. + # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put + # dependencies in `foo.d' instead, so we check for that too. + # Subdirectories are respected. + dir=`echo "$object" | sed -e 's|/[^/]*$|/|'` + test "x$dir" = "x$object" && dir= + base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'` + + if test "$libtool" = yes; then + # With Tru64 cc, shared objects can also be used to make a + # static library. This mechanism is used in libtool 1.4 series to + # handle both shared and static libraries in a single compilation. + # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d. + # + # With libtool 1.5 this exception was removed, and libtool now + # generates 2 separate objects for the 2 libraries. These two + # compilations output dependencies in $dir.libs/$base.o.d and + # in $dir$base.o.d. We have to check for both files, because + # one of the two compilations can be disabled. We should prefer + # $dir$base.o.d over $dir.libs/$base.o.d because the latter is + # automatically cleaned when .libs/ is deleted, while ignoring + # the former would cause a distcleancheck panic. + tmpdepfile1=$dir.libs/$base.lo.d # libtool 1.4 + tmpdepfile2=$dir$base.o.d # libtool 1.5 + tmpdepfile3=$dir.libs/$base.o.d # libtool 1.5 + tmpdepfile4=$dir.libs/$base.d # Compaq CCC V6.2-504 + "$@" -Wc,-MD + else + tmpdepfile1=$dir$base.o.d + tmpdepfile2=$dir$base.d + tmpdepfile3=$dir$base.d + tmpdepfile4=$dir$base.d + "$@" -MD + fi + + stat=$? + if test $stat -eq 0; then : + else + rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4" + exit $stat + fi + + for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4" + do + test -f "$tmpdepfile" && break + done + if test -f "$tmpdepfile"; then + sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile" + # That's a tab and a space in the []. + sed -e 's,^.*\.[a-z]*:[ ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile" + else + echo "#dummy" > "$depfile" + fi + rm -f "$tmpdepfile" + ;; + +#nosideeffect) + # This comment above is used by automake to tell side-effect + # dependency tracking mechanisms from slower ones. + +dashmstdout) + # Important note: in order to support this mode, a compiler *must* + # always write the preprocessed file to stdout, regardless of -o. + "$@" || exit $? + + # Remove the call to Libtool. + if test "$libtool" = yes; then + while test "X$1" != 'X--mode=compile'; do + shift + done + shift + fi + + # Remove `-o $object'. + IFS=" " + for arg + do + case $arg in + -o) + shift + ;; + $object) + shift + ;; + *) + set fnord "$@" "$arg" + shift # fnord + shift # $arg + ;; + esac + done + + test -z "$dashmflag" && dashmflag=-M + # Require at least two characters before searching for `:' + # in the target name. This is to cope with DOS-style filenames: + # a dependency such as `c:/foo/bar' could be seen as target `c' otherwise. + "$@" $dashmflag | + sed 's:^[ ]*[^: ][^:][^:]*\:[ ]*:'"$object"'\: :' > "$tmpdepfile" + rm -f "$depfile" + cat < "$tmpdepfile" > "$depfile" + tr ' ' ' +' < "$tmpdepfile" | \ +## Some versions of the HPUX 10.20 sed can't process this invocation +## correctly. Breaking it into two sed invocations is a workaround. + sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile" + rm -f "$tmpdepfile" + ;; + +dashXmstdout) + # This case only exists to satisfy depend.m4. It is never actually + # run, as this mode is specially recognized in the preamble. + exit 1 + ;; + +makedepend) + "$@" || exit $? + # Remove any Libtool call + if test "$libtool" = yes; then + while test "X$1" != 'X--mode=compile'; do + shift + done + shift + fi + # X makedepend + shift + cleared=no eat=no + for arg + do + case $cleared in + no) + set ""; shift + cleared=yes ;; + esac + if test $eat = yes; then + eat=no + continue + fi + case "$arg" in + -D*|-I*) + set fnord "$@" "$arg"; shift ;; + # Strip any option that makedepend may not understand. Remove + # the object too, otherwise makedepend will parse it as a source file. + -arch) + eat=yes ;; + -*|$object) + ;; + *) + set fnord "$@" "$arg"; shift ;; + esac + done + obj_suffix=`echo "$object" | sed 's/^.*\././'` + touch "$tmpdepfile" + ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" + rm -f "$depfile" + cat < "$tmpdepfile" > "$depfile" + sed '1,2d' "$tmpdepfile" | tr ' ' ' +' | \ +## Some versions of the HPUX 10.20 sed can't process this invocation +## correctly. Breaking it into two sed invocations is a workaround. + sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile" + rm -f "$tmpdepfile" "$tmpdepfile".bak + ;; + +cpp) + # Important note: in order to support this mode, a compiler *must* + # always write the preprocessed file to stdout. + "$@" || exit $? + + # Remove the call to Libtool. + if test "$libtool" = yes; then + while test "X$1" != 'X--mode=compile'; do + shift + done + shift + fi + + # Remove `-o $object'. + IFS=" " + for arg + do + case $arg in + -o) + shift + ;; + $object) + shift + ;; + *) + set fnord "$@" "$arg" + shift # fnord + shift # $arg + ;; + esac + done + + "$@" -E | + sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ + -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' | + sed '$ s: \\$::' > "$tmpdepfile" + rm -f "$depfile" + echo "$object : \\" > "$depfile" + cat < "$tmpdepfile" >> "$depfile" + sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" + rm -f "$tmpdepfile" + ;; + +msvisualcpp) + # Important note: in order to support this mode, a compiler *must* + # always write the preprocessed file to stdout. + "$@" || exit $? + + # Remove the call to Libtool. + if test "$libtool" = yes; then + while test "X$1" != 'X--mode=compile'; do + shift + done + shift + fi + + IFS=" " + for arg + do + case "$arg" in + -o) + shift + ;; + $object) + shift + ;; + "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") + set fnord "$@" + shift + shift + ;; + *) + set fnord "$@" "$arg" + shift + shift + ;; + esac + done + "$@" -E 2>/dev/null | + sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" + rm -f "$depfile" + echo "$object : \\" > "$depfile" + sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s:: \1 \\:p' >> "$depfile" + echo " " >> "$depfile" + sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" + rm -f "$tmpdepfile" + ;; + +msvcmsys) + # This case exists only to let depend.m4 do its work. It works by + # looking at the text of this script. This case will never be run, + # since it is checked for above. + exit 1 + ;; + +none) + exec "$@" + ;; + +*) + echo "Unknown depmode $depmode" 1>&2 + exit 1 + ;; +esac + +exit 0 + +# Local Variables: +# mode: shell-script +# sh-indentation: 2 +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "scriptversion=" +# time-stamp-format: "%:y-%02m-%02d.%02H" +# time-stamp-time-zone: "UTC" +# time-stamp-end: "; # UTC" +# End: diff --git a/libs/libpng-src/example.c b/libs/libpng-src/example.c new file mode 100644 index 000000000..49b872422 --- /dev/null +++ b/libs/libpng-src/example.c @@ -0,0 +1,832 @@ + +#if 0 /* in case someone actually tries to compile this */ + +/* example.c - an example of using libpng + * Last changed in libpng 1.2.37 [June 4, 2009] + * This file has been placed in the public domain by the authors. + * Maintained 1998-2010 Glenn Randers-Pehrson + * Maintained 1996, 1997 Andreas Dilger) + * Written 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + */ + +/* This is an example of how to use libpng to read and write PNG files. + * The file libpng.txt is much more verbose then this. If you have not + * read it, do so first. This was designed to be a starting point of an + * implementation. This is not officially part of libpng, is hereby placed + * in the public domain, and therefore does not require a copyright notice. + * + * This file does not currently compile, because it is missing certain + * parts, like allocating memory to hold an image. You will have to + * supply these parts to get it to compile. For an example of a minimal + * working PNG reader/writer, see pngtest.c, included in this distribution; + * see also the programs in the contrib directory. + */ + +#include "png.h" + + /* The png_jmpbuf() macro, used in error handling, became available in + * libpng version 1.0.6. If you want to be able to run your code with older + * versions of libpng, you must define the macro yourself (but only if it + * is not already defined by libpng!). + */ + +#ifndef png_jmpbuf +# define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf) +#endif + +/* Check to see if a file is a PNG file using png_sig_cmp(). png_sig_cmp() + * returns zero if the image is a PNG and nonzero if it isn't a PNG. + * + * The function check_if_png() shown here, but not used, returns nonzero (true) + * if the file can be opened and is a PNG, 0 (false) otherwise. + * + * If this call is successful, and you are going to keep the file open, + * you should call png_set_sig_bytes(png_ptr, PNG_BYTES_TO_CHECK); once + * you have created the png_ptr, so that libpng knows your application + * has read that many bytes from the start of the file. Make sure you + * don't call png_set_sig_bytes() with more than 8 bytes read or give it + * an incorrect number of bytes read, or you will either have read too + * many bytes (your fault), or you are telling libpng to read the wrong + * number of magic bytes (also your fault). + * + * Many applications already read the first 2 or 4 bytes from the start + * of the image to determine the file type, so it would be easiest just + * to pass the bytes to png_sig_cmp() or even skip that if you know + * you have a PNG file, and call png_set_sig_bytes(). + */ +#define PNG_BYTES_TO_CHECK 4 +int check_if_png(char *file_name, FILE **fp) +{ + char buf[PNG_BYTES_TO_CHECK]; + + /* Open the prospective PNG file. */ + if ((*fp = fopen(file_name, "rb")) == NULL) + return 0; + + /* Read in some of the signature bytes */ + if (fread(buf, 1, PNG_BYTES_TO_CHECK, *fp) != PNG_BYTES_TO_CHECK) + return 0; + + /* Compare the first PNG_BYTES_TO_CHECK bytes of the signature. + Return nonzero (true) if they match */ + + return(!png_sig_cmp(buf, (png_size_t)0, PNG_BYTES_TO_CHECK)); +} + +/* Read a PNG file. You may want to return an error code if the read + * fails (depending upon the failure). There are two "prototypes" given + * here - one where we are given the filename, and we need to open the + * file, and the other where we are given an open file (possibly with + * some or all of the magic bytes read - see comments above). + */ +#ifdef open_file /* prototype 1 */ +void read_png(char *file_name) /* We need to open the file */ +{ + png_structp png_ptr; + png_infop info_ptr; + unsigned int sig_read = 0; + png_uint_32 width, height; + int bit_depth, color_type, interlace_type; + FILE *fp; + + if ((fp = fopen(file_name, "rb")) == NULL) + return (ERROR); + +#else no_open_file /* prototype 2 */ +void read_png(FILE *fp, unsigned int sig_read) /* File is already open */ +{ + png_structp png_ptr; + png_infop info_ptr; + png_uint_32 width, height; + int bit_depth, color_type, interlace_type; +#endif no_open_file /* Only use one prototype! */ + + /* Create and initialize the png_struct with the desired error handler + * functions. If you want to use the default stderr and longjump method, + * you can supply NULL for the last three parameters. We also supply the + * the compiler header file version, so that we know if the application + * was compiled with a compatible version of the library. REQUIRED + */ + png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, + png_voidp user_error_ptr, user_error_fn, user_warning_fn); + + if (png_ptr == NULL) + { + fclose(fp); + return (ERROR); + } + + /* Allocate/initialize the memory for image information. REQUIRED. */ + info_ptr = png_create_info_struct(png_ptr); + if (info_ptr == NULL) + { + fclose(fp); + png_destroy_read_struct(&png_ptr, png_infopp_NULL, png_infopp_NULL); + return (ERROR); + } + + /* Set error handling if you are using the setjmp/longjmp method (this is + * the normal method of doing things with libpng). REQUIRED unless you + * set up your own error handlers in the png_create_read_struct() earlier. + */ + + if (setjmp(png_jmpbuf(png_ptr))) + { + /* Free all of the memory associated with the png_ptr and info_ptr */ + png_destroy_read_struct(&png_ptr, &info_ptr, png_infopp_NULL); + fclose(fp); + /* If we get here, we had a problem reading the file */ + return (ERROR); + } + + /* One of the following I/O initialization methods is REQUIRED */ +#ifdef streams /* PNG file I/O method 1 */ + /* Set up the input control if you are using standard C streams */ + png_init_io(png_ptr, fp); + +#else no_streams /* PNG file I/O method 2 */ + /* If you are using replacement read functions, instead of calling + * png_init_io() here you would call: + */ + png_set_read_fn(png_ptr, (void *)user_io_ptr, user_read_fn); + /* where user_io_ptr is a structure you want available to the callbacks */ +#endif no_streams /* Use only one I/O method! */ + + /* If we have already read some of the signature */ + png_set_sig_bytes(png_ptr, sig_read); + +#ifdef hilevel + /* + * If you have enough memory to read in the entire image at once, + * and you need to specify only transforms that can be controlled + * with one of the PNG_TRANSFORM_* bits (this presently excludes + * dithering, filling, setting background, and doing gamma + * adjustment), then you can read the entire image (including + * pixels) into the info structure with this call: + */ + png_read_png(png_ptr, info_ptr, png_transforms, png_voidp_NULL); + +#else + /* OK, you're doing it the hard way, with the lower-level functions */ + + /* The call to png_read_info() gives us all of the information from the + * PNG file before the first IDAT (image data chunk). REQUIRED + */ + png_read_info(png_ptr, info_ptr); + + png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, + &interlace_type, int_p_NULL, int_p_NULL); + + /* Set up the data transformations you want. Note that these are all + * optional. Only call them if you want/need them. Many of the + * transformations only work on specific types of images, and many + * are mutually exclusive. + */ + + /* Tell libpng to strip 16 bit/color files down to 8 bits/color */ + png_set_strip_16(png_ptr); + + /* Strip alpha bytes from the input data without combining with the + * background (not recommended). + */ + png_set_strip_alpha(png_ptr); + + /* Extract multiple pixels with bit depths of 1, 2, and 4 from a single + * byte into separate bytes (useful for paletted and grayscale images). + */ + png_set_packing(png_ptr); + + /* Change the order of packed pixels to least significant bit first + * (not useful if you are using png_set_packing). */ + png_set_packswap(png_ptr); + + /* Expand paletted colors into true RGB triplets */ + if (color_type == PNG_COLOR_TYPE_PALETTE) + png_set_palette_to_rgb(png_ptr); + + /* Expand grayscale images to the full 8 bits from 1, 2, or 4 bits/pixel */ + if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) + png_set_expand_gray_1_2_4_to_8(png_ptr); + + /* Expand paletted or RGB images with transparency to full alpha channels + * so the data will be available as RGBA quartets. + */ + if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) + png_set_tRNS_to_alpha(png_ptr); + + /* Set the background color to draw transparent and alpha images over. + * It is possible to set the red, green, and blue components directly + * for paletted images instead of supplying a palette index. Note that + * even if the PNG file supplies a background, you are not required to + * use it - you should use the (solid) application background if it has one. + */ + + png_color_16 my_background, *image_background; + + if (png_get_bKGD(png_ptr, info_ptr, &image_background)) + png_set_background(png_ptr, image_background, + PNG_BACKGROUND_GAMMA_FILE, 1, 1.0); + else + png_set_background(png_ptr, &my_background, + PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0); + + /* Some suggestions as to how to get a screen gamma value + * + * Note that screen gamma is the display_exponent, which includes + * the CRT_exponent and any correction for viewing conditions + */ + if (/* We have a user-defined screen gamma value */) + { + screen_gamma = user-defined screen_gamma; + } + /* This is one way that applications share the same screen gamma value */ + else if ((gamma_str = getenv("SCREEN_GAMMA")) != NULL) + { + screen_gamma = atof(gamma_str); + } + /* If we don't have another value */ + else + { + screen_gamma = 2.2; /* A good guess for a PC monitor in a dimly + lit room */ + screen_gamma = 1.7 or 1.0; /* A good guess for Mac systems */ + } + + /* Tell libpng to handle the gamma conversion for you. The final call + * is a good guess for PC generated images, but it should be configurable + * by the user at run time by the user. It is strongly suggested that + * your application support gamma correction. + */ + + int intent; + + if (png_get_sRGB(png_ptr, info_ptr, &intent)) + png_set_gamma(png_ptr, screen_gamma, 0.45455); + else + { + double image_gamma; + if (png_get_gAMA(png_ptr, info_ptr, &image_gamma)) + png_set_gamma(png_ptr, screen_gamma, image_gamma); + else + png_set_gamma(png_ptr, screen_gamma, 0.45455); + } + + /* Dither RGB files down to 8 bit palette or reduce palettes + * to the number of colors available on your screen. + */ + if (color_type & PNG_COLOR_MASK_COLOR) + { + int num_palette; + png_colorp palette; + + /* This reduces the image to the application supplied palette */ + if (/* We have our own palette */) + { + /* An array of colors to which the image should be dithered */ + png_color std_color_cube[MAX_SCREEN_COLORS]; + + png_set_dither(png_ptr, std_color_cube, MAX_SCREEN_COLORS, + MAX_SCREEN_COLORS, png_uint_16p_NULL, 0); + } + /* This reduces the image to the palette supplied in the file */ + else if (png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette)) + { + png_uint_16p histogram = NULL; + + png_get_hIST(png_ptr, info_ptr, &histogram); + + png_set_dither(png_ptr, palette, num_palette, + max_screen_colors, histogram, 0); + } + } + + /* Invert monochrome files to have 0 as white and 1 as black */ + png_set_invert_mono(png_ptr); + + /* If you want to shift the pixel values from the range [0,255] or + * [0,65535] to the original [0,7] or [0,31], or whatever range the + * colors were originally in: + */ + if (png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT)) + { + png_color_8p sig_bit_p; + + png_get_sBIT(png_ptr, info_ptr, &sig_bit_p); + png_set_shift(png_ptr, sig_bit_p); + } + + /* Flip the RGB pixels to BGR (or RGBA to BGRA) */ + if (color_type & PNG_COLOR_MASK_COLOR) + png_set_bgr(png_ptr); + + /* Swap the RGBA or GA data to ARGB or AG (or BGRA to ABGR) */ + png_set_swap_alpha(png_ptr); + + /* Swap bytes of 16 bit files to least significant byte first */ + png_set_swap(png_ptr); + + /* Add filler (or alpha) byte (before/after each RGB triplet) */ + png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER); + + /* Turn on interlace handling. REQUIRED if you are not using + * png_read_image(). To see how to handle interlacing passes, + * see the png_read_row() method below: + */ + number_passes = png_set_interlace_handling(png_ptr); + + /* Optional call to gamma correct and add the background to the palette + * and update info structure. REQUIRED if you are expecting libpng to + * update the palette for you (ie you selected such a transform above). + */ + png_read_update_info(png_ptr, info_ptr); + + /* Allocate the memory to hold the image using the fields of info_ptr. */ + + /* The easiest way to read the image: */ + png_bytep row_pointers[height]; + + /* Clear the pointer array */ + for (row = 0; row < height; row++) + row_pointers[row] = NULL; + + for (row = 0; row < height; row++) + row_pointers[row] = png_malloc(png_ptr, png_get_rowbytes(png_ptr, + info_ptr)); + + /* Now it's time to read the image. One of these methods is REQUIRED */ +#ifdef entire /* Read the entire image in one go */ + png_read_image(png_ptr, row_pointers); + +#else no_entire /* Read the image one or more scanlines at a time */ + /* The other way to read images - deal with interlacing: */ + + for (pass = 0; pass < number_passes; pass++) + { +#ifdef single /* Read the image a single row at a time */ + for (y = 0; y < height; y++) + { + png_read_rows(png_ptr, &row_pointers[y], png_bytepp_NULL, 1); + } + +#else no_single /* Read the image several rows at a time */ + for (y = 0; y < height; y += number_of_rows) + { +#ifdef sparkle /* Read the image using the "sparkle" effect. */ + png_read_rows(png_ptr, &row_pointers[y], png_bytepp_NULL, + number_of_rows); +#else no_sparkle /* Read the image using the "rectangle" effect */ + png_read_rows(png_ptr, png_bytepp_NULL, &row_pointers[y], + number_of_rows); +#endif no_sparkle /* Use only one of these two methods */ + } + + /* If you want to display the image after every pass, do so here */ +#endif no_single /* Use only one of these two methods */ + } +#endif no_entire /* Use only one of these two methods */ + + /* Read rest of file, and get additional chunks in info_ptr - REQUIRED */ + png_read_end(png_ptr, info_ptr); +#endif hilevel + + /* At this point you have read the entire image */ + + /* Clean up after the read, and free any memory allocated - REQUIRED */ + png_destroy_read_struct(&png_ptr, &info_ptr, png_infopp_NULL); + + /* Close the file */ + fclose(fp); + + /* That's it */ + return (OK); +} + +/* Progressively read a file */ + +int +initialize_png_reader(png_structp *png_ptr, png_infop *info_ptr) +{ + /* Create and initialize the png_struct with the desired error handler + * functions. If you want to use the default stderr and longjump method, + * you can supply NULL for the last three parameters. We also check that + * the library version is compatible in case we are using dynamically + * linked libraries. + */ + *png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, + png_voidp user_error_ptr, user_error_fn, user_warning_fn); + + if (*png_ptr == NULL) + { + *info_ptr = NULL; + return (ERROR); + } + + *info_ptr = png_create_info_struct(png_ptr); + + if (*info_ptr == NULL) + { + png_destroy_read_struct(png_ptr, info_ptr, png_infopp_NULL); + return (ERROR); + } + + if (setjmp(png_jmpbuf((*png_ptr)))) + { + png_destroy_read_struct(png_ptr, info_ptr, png_infopp_NULL); + return (ERROR); + } + + /* This one's new. You will need to provide all three + * function callbacks, even if you aren't using them all. + * If you aren't using all functions, you can specify NULL + * parameters. Even when all three functions are NULL, + * you need to call png_set_progressive_read_fn(). + * These functions shouldn't be dependent on global or + * static variables if you are decoding several images + * simultaneously. You should store stream specific data + * in a separate struct, given as the second parameter, + * and retrieve the pointer from inside the callbacks using + * the function png_get_progressive_ptr(png_ptr). + */ + png_set_progressive_read_fn(*png_ptr, (void *)stream_data, + info_callback, row_callback, end_callback); + + return (OK); +} + +int +process_data(png_structp *png_ptr, png_infop *info_ptr, + png_bytep buffer, png_uint_32 length) +{ + if (setjmp(png_jmpbuf((*png_ptr)))) + { + /* Free the png_ptr and info_ptr memory on error */ + png_destroy_read_struct(png_ptr, info_ptr, png_infopp_NULL); + return (ERROR); + } + + /* This one's new also. Simply give it chunks of data as + * they arrive from the data stream (in order, of course). + * On segmented machines, don't give it any more than 64K. + * The library seems to run fine with sizes of 4K, although + * you can give it much less if necessary (I assume you can + * give it chunks of 1 byte, but I haven't tried with less + * than 256 bytes yet). When this function returns, you may + * want to display any rows that were generated in the row + * callback, if you aren't already displaying them there. + */ + png_process_data(*png_ptr, *info_ptr, buffer, length); + return (OK); +} + +info_callback(png_structp png_ptr, png_infop info) +{ + /* Do any setup here, including setting any of the transformations + * mentioned in the Reading PNG files section. For now, you _must_ + * call either png_start_read_image() or png_read_update_info() + * after all the transformations are set (even if you don't set + * any). You may start getting rows before png_process_data() + * returns, so this is your last chance to prepare for that. + */ +} + +row_callback(png_structp png_ptr, png_bytep new_row, + png_uint_32 row_num, int pass) +{ + /* + * This function is called for every row in the image. If the + * image is interlaced, and you turned on the interlace handler, + * this function will be called for every row in every pass. + * + * In this function you will receive a pointer to new row data from + * libpng called new_row that is to replace a corresponding row (of + * the same data format) in a buffer allocated by your application. + * + * The new row data pointer "new_row" may be NULL, indicating there is + * no new data to be replaced (in cases of interlace loading). + * + * If new_row is not NULL then you need to call + * png_progressive_combine_row() to replace the corresponding row as + * shown below: + */ + + /* Get pointer to corresponding row in our + * PNG read buffer. + */ + png_bytep old_row = ((png_bytep *)our_data)[row_num]; + + /* If both rows are allocated then copy the new row + * data to the corresponding row data. + */ + if ((old_row != NULL) && (new_row != NULL)) + png_progressive_combine_row(png_ptr, old_row, new_row); + + /* + * The rows and passes are called in order, so you don't really + * need the row_num and pass, but I'm supplying them because it + * may make your life easier. + * + * For the non-NULL rows of interlaced images, you must call + * png_progressive_combine_row() passing in the new row and the + * old row, as demonstrated above. You can call this function for + * NULL rows (it will just return) and for non-interlaced images + * (it just does the png_memcpy for you) if it will make the code + * easier. Thus, you can just do this for all cases: + */ + + png_progressive_combine_row(png_ptr, old_row, new_row); + + /* where old_row is what was displayed for previous rows. Note + * that the first pass (pass == 0 really) will completely cover + * the old row, so the rows do not have to be initialized. After + * the first pass (and only for interlaced images), you will have + * to pass the current row as new_row, and the function will combine + * the old row and the new row. + */ +} + +end_callback(png_structp png_ptr, png_infop info) +{ + /* This function is called when the whole image has been read, + * including any chunks after the image (up to and including + * the IEND). You will usually have the same info chunk as you + * had in the header, although some data may have been added + * to the comments and time fields. + * + * Most people won't do much here, perhaps setting a flag that + * marks the image as finished. + */ +} + +/* Write a png file */ +void write_png(char *file_name /* , ... other image information ... */) +{ + FILE *fp; + png_structp png_ptr; + png_infop info_ptr; + png_colorp palette; + + /* Open the file */ + fp = fopen(file_name, "wb"); + if (fp == NULL) + return (ERROR); + + /* Create and initialize the png_struct with the desired error handler + * functions. If you want to use the default stderr and longjump method, + * you can supply NULL for the last three parameters. We also check that + * the library version is compatible with the one used at compile time, + * in case we are using dynamically linked libraries. REQUIRED. + */ + png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, + png_voidp user_error_ptr, user_error_fn, user_warning_fn); + + if (png_ptr == NULL) + { + fclose(fp); + return (ERROR); + } + + /* Allocate/initialize the image information data. REQUIRED */ + info_ptr = png_create_info_struct(png_ptr); + if (info_ptr == NULL) + { + fclose(fp); + png_destroy_write_struct(&png_ptr, png_infopp_NULL); + return (ERROR); + } + + /* Set error handling. REQUIRED if you aren't supplying your own + * error handling functions in the png_create_write_struct() call. + */ + if (setjmp(png_jmpbuf(png_ptr))) + { + /* If we get here, we had a problem writing the file */ + fclose(fp); + png_destroy_write_struct(&png_ptr, &info_ptr); + return (ERROR); + } + + /* One of the following I/O initialization functions is REQUIRED */ + +#ifdef streams /* I/O initialization method 1 */ + /* Set up the output control if you are using standard C streams */ + png_init_io(png_ptr, fp); + +#else no_streams /* I/O initialization method 2 */ + /* If you are using replacement write functions, instead of calling + * png_init_io() here you would call + */ + png_set_write_fn(png_ptr, (void *)user_io_ptr, user_write_fn, + user_IO_flush_function); + /* where user_io_ptr is a structure you want available to the callbacks */ +#endif no_streams /* Only use one initialization method */ + +#ifdef hilevel + /* This is the easy way. Use it if you already have all the + * image info living in the structure. You could "|" many + * PNG_TRANSFORM flags into the png_transforms integer here. + */ + png_write_png(png_ptr, info_ptr, png_transforms, png_voidp_NULL); + +#else + /* This is the hard way */ + + /* Set the image information here. Width and height are up to 2^31, + * bit_depth is one of 1, 2, 4, 8, or 16, but valid values also depend on + * the color_type selected. color_type is one of PNG_COLOR_TYPE_GRAY, + * PNG_COLOR_TYPE_GRAY_ALPHA, PNG_COLOR_TYPE_PALETTE, PNG_COLOR_TYPE_RGB, + * or PNG_COLOR_TYPE_RGB_ALPHA. interlace is either PNG_INTERLACE_NONE or + * PNG_INTERLACE_ADAM7, and the compression_type and filter_type MUST + * currently be PNG_COMPRESSION_TYPE_BASE and PNG_FILTER_TYPE_BASE. REQUIRED + */ + png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth, PNG_COLOR_TYPE_???, + PNG_INTERLACE_????, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); + + /* Set the palette if there is one. REQUIRED for indexed-color images */ + palette = (png_colorp)png_malloc(png_ptr, PNG_MAX_PALETTE_LENGTH + * png_sizeof(png_color)); + /* ... Set palette colors ... */ + png_set_PLTE(png_ptr, info_ptr, palette, PNG_MAX_PALETTE_LENGTH); + /* You must not free palette here, because png_set_PLTE only makes a link to + * the palette that you malloced. Wait until you are about to destroy + * the png structure. + */ + + /* Optional significant bit (sBIT) chunk */ + png_color_8 sig_bit; + /* If we are dealing with a grayscale image then */ + sig_bit.gray = true_bit_depth; + /* Otherwise, if we are dealing with a color image then */ + sig_bit.red = true_red_bit_depth; + sig_bit.green = true_green_bit_depth; + sig_bit.blue = true_blue_bit_depth; + /* If the image has an alpha channel then */ + sig_bit.alpha = true_alpha_bit_depth; + png_set_sBIT(png_ptr, info_ptr, &sig_bit); + + + /* Optional gamma chunk is strongly suggested if you have any guess + * as to the correct gamma of the image. + */ + png_set_gAMA(png_ptr, info_ptr, gamma); + + /* Optionally write comments into the image */ + text_ptr[0].key = "Title"; + text_ptr[0].text = "Mona Lisa"; + text_ptr[0].compression = PNG_TEXT_COMPRESSION_NONE; + text_ptr[1].key = "Author"; + text_ptr[1].text = "Leonardo DaVinci"; + text_ptr[1].compression = PNG_TEXT_COMPRESSION_NONE; + text_ptr[2].key = "Description"; + text_ptr[2].text = ""; + text_ptr[2].compression = PNG_TEXT_COMPRESSION_zTXt; +#ifdef PNG_iTXt_SUPPORTED + text_ptr[0].lang = NULL; + text_ptr[1].lang = NULL; + text_ptr[2].lang = NULL; +#endif + png_set_text(png_ptr, info_ptr, text_ptr, 3); + + /* Other optional chunks like cHRM, bKGD, tRNS, tIME, oFFs, pHYs */ + + /* Note that if sRGB is present the gAMA and cHRM chunks must be ignored + * on read and, if your application chooses to write them, they must + * be written in accordance with the sRGB profile + */ + + /* Write the file header information. REQUIRED */ + png_write_info(png_ptr, info_ptr); + + /* If you want, you can write the info in two steps, in case you need to + * write your private chunk ahead of PLTE: + * + * png_write_info_before_PLTE(write_ptr, write_info_ptr); + * write_my_chunk(); + * png_write_info(png_ptr, info_ptr); + * + * However, given the level of known- and unknown-chunk support in 1.2.0 + * and up, this should no longer be necessary. + */ + + /* Once we write out the header, the compression type on the text + * chunks gets changed to PNG_TEXT_COMPRESSION_NONE_WR or + * PNG_TEXT_COMPRESSION_zTXt_WR, so it doesn't get written out again + * at the end. + */ + + /* Set up the transformations you want. Note that these are + * all optional. Only call them if you want them. + */ + + /* Invert monochrome pixels */ + png_set_invert_mono(png_ptr); + + /* Shift the pixels up to a legal bit depth and fill in + * as appropriate to correctly scale the image. + */ + png_set_shift(png_ptr, &sig_bit); + + /* Pack pixels into bytes */ + png_set_packing(png_ptr); + + /* Swap location of alpha bytes from ARGB to RGBA */ + png_set_swap_alpha(png_ptr); + + /* Get rid of filler (OR ALPHA) bytes, pack XRGB/RGBX/ARGB/RGBA into + * RGB (4 channels -> 3 channels). The second parameter is not used. + */ + png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE); + + /* Flip BGR pixels to RGB */ + png_set_bgr(png_ptr); + + /* Swap bytes of 16-bit files to most significant byte first */ + png_set_swap(png_ptr); + + /* Swap bits of 1, 2, 4 bit packed pixel formats */ + png_set_packswap(png_ptr); + + /* Turn on interlace handling if you are not using png_write_image() */ + if (interlacing) + number_passes = png_set_interlace_handling(png_ptr); + else + number_passes = 1; + + /* The easiest way to write the image (you may have a different memory + * layout, however, so choose what fits your needs best). You need to + * use the first method if you aren't handling interlacing yourself. + */ + png_uint_32 k, height, width; + png_byte image[height][width*bytes_per_pixel]; + png_bytep row_pointers[height]; + + if (height > PNG_UINT_32_MAX/png_sizeof(png_bytep)) + png_error (png_ptr, "Image is too tall to process in memory"); + + for (k = 0; k < height; k++) + row_pointers[k] = image + k*width*bytes_per_pixel; + + /* One of the following output methods is REQUIRED */ + +#ifdef entire /* Write out the entire image data in one call */ + png_write_image(png_ptr, row_pointers); + + /* The other way to write the image - deal with interlacing */ + +#else no_entire /* Write out the image data by one or more scanlines */ + + /* The number of passes is either 1 for non-interlaced images, + * or 7 for interlaced images. + */ + for (pass = 0; pass < number_passes; pass++) + { + /* Write a few rows at a time. */ + png_write_rows(png_ptr, &row_pointers[first_row], number_of_rows); + + /* If you are only writing one row at a time, this works */ + for (y = 0; y < height; y++) + png_write_rows(png_ptr, &row_pointers[y], 1); + } +#endif no_entire /* Use only one output method */ + + /* You can write optional chunks like tEXt, zTXt, and tIME at the end + * as well. Shouldn't be necessary in 1.2.0 and up as all the public + * chunks are supported and you can use png_set_unknown_chunks() to + * register unknown chunks into the info structure to be written out. + */ + + /* It is REQUIRED to call this to finish writing the rest of the file */ + png_write_end(png_ptr, info_ptr); +#endif hilevel + + /* If you png_malloced a palette, free it here (don't free info_ptr->palette, + * as recommended in versions 1.0.5m and earlier of this example; if + * libpng mallocs info_ptr->palette, libpng will free it). If you + * allocated it with malloc() instead of png_malloc(), use free() instead + * of png_free(). + */ + png_free(png_ptr, palette); + palette = NULL; + + /* Similarly, if you png_malloced any data that you passed in with + * png_set_something(), such as a hist or trans array, free it here, + * when you can be sure that libpng is through with it. + */ + png_free(png_ptr, trans); + trans = NULL; + /* Whenever you use png_free() it is a good idea to set the pointer to + * NULL in case your application inadvertently tries to png_free() it + * again. When png_free() sees a NULL it returns without action, thus + * avoiding the double-free security problem. + */ + + /* Clean up after the write, and free any memory allocated */ + png_destroy_write_struct(&png_ptr, &info_ptr); + + /* Close the file */ + fclose(fp); + + /* That's it */ + return (OK); +} + +#endif /* if 0 */ diff --git a/libs/libpng-src/install-sh b/libs/libpng-src/install-sh new file mode 100755 index 000000000..6781b987b --- /dev/null +++ b/libs/libpng-src/install-sh @@ -0,0 +1,520 @@ +#!/bin/sh +# install - install a program, script, or datafile + +scriptversion=2009-04-28.21; # UTC + +# This originates from X11R5 (mit/util/scripts/install.sh), which was +# later released in X11R6 (xc/config/util/install.sh) with the +# following copyright and license. +# +# Copyright (C) 1994 X Consortium +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- +# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# +# Except as contained in this notice, the name of the X Consortium shall not +# be used in advertising or otherwise to promote the sale, use or other deal- +# ings in this Software without prior written authorization from the X Consor- +# tium. +# +# +# FSF changes to this file are in the public domain. +# +# Calling this script install-sh is preferred over install.sh, to prevent +# `make' implicit rules from creating a file called install from it +# when there is no Makefile. +# +# This script is compatible with the BSD install script, but was written +# from scratch. + +nl=' +' +IFS=" "" $nl" + +# set DOITPROG to echo to test this script + +# Don't use :- since 4.3BSD and earlier shells don't like it. +doit=${DOITPROG-} +if test -z "$doit"; then + doit_exec=exec +else + doit_exec=$doit +fi + +# Put in absolute file names if you don't have them in your path; +# or use environment vars. + +chgrpprog=${CHGRPPROG-chgrp} +chmodprog=${CHMODPROG-chmod} +chownprog=${CHOWNPROG-chown} +cmpprog=${CMPPROG-cmp} +cpprog=${CPPROG-cp} +mkdirprog=${MKDIRPROG-mkdir} +mvprog=${MVPROG-mv} +rmprog=${RMPROG-rm} +stripprog=${STRIPPROG-strip} + +posix_glob='?' +initialize_posix_glob=' + test "$posix_glob" != "?" || { + if (set -f) 2>/dev/null; then + posix_glob= + else + posix_glob=: + fi + } +' + +posix_mkdir= + +# Desired mode of installed file. +mode=0755 + +chgrpcmd= +chmodcmd=$chmodprog +chowncmd= +mvcmd=$mvprog +rmcmd="$rmprog -f" +stripcmd= + +src= +dst= +dir_arg= +dst_arg= + +copy_on_change=false +no_target_directory= + +usage="\ +Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE + or: $0 [OPTION]... SRCFILES... DIRECTORY + or: $0 [OPTION]... -t DIRECTORY SRCFILES... + or: $0 [OPTION]... -d DIRECTORIES... + +In the 1st form, copy SRCFILE to DSTFILE. +In the 2nd and 3rd, copy all SRCFILES to DIRECTORY. +In the 4th, create DIRECTORIES. + +Options: + --help display this help and exit. + --version display version info and exit. + + -c (ignored) + -C install only if different (preserve the last data modification time) + -d create directories instead of installing files. + -g GROUP $chgrpprog installed files to GROUP. + -m MODE $chmodprog installed files to MODE. + -o USER $chownprog installed files to USER. + -s $stripprog installed files. + -t DIRECTORY install into DIRECTORY. + -T report an error if DSTFILE is a directory. + +Environment variables override the default commands: + CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG + RMPROG STRIPPROG +" + +while test $# -ne 0; do + case $1 in + -c) ;; + + -C) copy_on_change=true;; + + -d) dir_arg=true;; + + -g) chgrpcmd="$chgrpprog $2" + shift;; + + --help) echo "$usage"; exit $?;; + + -m) mode=$2 + case $mode in + *' '* | *' '* | *' +'* | *'*'* | *'?'* | *'['*) + echo "$0: invalid mode: $mode" >&2 + exit 1;; + esac + shift;; + + -o) chowncmd="$chownprog $2" + shift;; + + -s) stripcmd=$stripprog;; + + -t) dst_arg=$2 + shift;; + + -T) no_target_directory=true;; + + --version) echo "$0 $scriptversion"; exit $?;; + + --) shift + break;; + + -*) echo "$0: invalid option: $1" >&2 + exit 1;; + + *) break;; + esac + shift +done + +if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then + # When -d is used, all remaining arguments are directories to create. + # When -t is used, the destination is already specified. + # Otherwise, the last argument is the destination. Remove it from $@. + for arg + do + if test -n "$dst_arg"; then + # $@ is not empty: it contains at least $arg. + set fnord "$@" "$dst_arg" + shift # fnord + fi + shift # arg + dst_arg=$arg + done +fi + +if test $# -eq 0; then + if test -z "$dir_arg"; then + echo "$0: no input file specified." >&2 + exit 1 + fi + # It's OK to call `install-sh -d' without argument. + # This can happen when creating conditional directories. + exit 0 +fi + +if test -z "$dir_arg"; then + trap '(exit $?); exit' 1 2 13 15 + + # Set umask so as not to create temps with too-generous modes. + # However, 'strip' requires both read and write access to temps. + case $mode in + # Optimize common cases. + *644) cp_umask=133;; + *755) cp_umask=22;; + + *[0-7]) + if test -z "$stripcmd"; then + u_plus_rw= + else + u_plus_rw='% 200' + fi + cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; + *) + if test -z "$stripcmd"; then + u_plus_rw= + else + u_plus_rw=,u+rw + fi + cp_umask=$mode$u_plus_rw;; + esac +fi + +for src +do + # Protect names starting with `-'. + case $src in + -*) src=./$src;; + esac + + if test -n "$dir_arg"; then + dst=$src + dstdir=$dst + test -d "$dstdir" + dstdir_status=$? + else + + # Waiting for this to be detected by the "$cpprog $src $dsttmp" command + # might cause directories to be created, which would be especially bad + # if $src (and thus $dsttmp) contains '*'. + if test ! -f "$src" && test ! -d "$src"; then + echo "$0: $src does not exist." >&2 + exit 1 + fi + + if test -z "$dst_arg"; then + echo "$0: no destination specified." >&2 + exit 1 + fi + + dst=$dst_arg + # Protect names starting with `-'. + case $dst in + -*) dst=./$dst;; + esac + + # If destination is a directory, append the input filename; won't work + # if double slashes aren't ignored. + if test -d "$dst"; then + if test -n "$no_target_directory"; then + echo "$0: $dst_arg: Is a directory" >&2 + exit 1 + fi + dstdir=$dst + dst=$dstdir/`basename "$src"` + dstdir_status=0 + else + # Prefer dirname, but fall back on a substitute if dirname fails. + dstdir=` + (dirname "$dst") 2>/dev/null || + expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$dst" : 'X\(//\)[^/]' \| \ + X"$dst" : 'X\(//\)$' \| \ + X"$dst" : 'X\(/\)' \| . 2>/dev/null || + echo X"$dst" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q' + ` + + test -d "$dstdir" + dstdir_status=$? + fi + fi + + obsolete_mkdir_used=false + + if test $dstdir_status != 0; then + case $posix_mkdir in + '') + # Create intermediate dirs using mode 755 as modified by the umask. + # This is like FreeBSD 'install' as of 1997-10-28. + umask=`umask` + case $stripcmd.$umask in + # Optimize common cases. + *[2367][2367]) mkdir_umask=$umask;; + .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; + + *[0-7]) + mkdir_umask=`expr $umask + 22 \ + - $umask % 100 % 40 + $umask % 20 \ + - $umask % 10 % 4 + $umask % 2 + `;; + *) mkdir_umask=$umask,go-w;; + esac + + # With -d, create the new directory with the user-specified mode. + # Otherwise, rely on $mkdir_umask. + if test -n "$dir_arg"; then + mkdir_mode=-m$mode + else + mkdir_mode= + fi + + posix_mkdir=false + case $umask in + *[123567][0-7][0-7]) + # POSIX mkdir -p sets u+wx bits regardless of umask, which + # is incompatible with FreeBSD 'install' when (umask & 300) != 0. + ;; + *) + tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ + trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 + + if (umask $mkdir_umask && + exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 + then + if test -z "$dir_arg" || { + # Check for POSIX incompatibilities with -m. + # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or + # other-writeable bit of parent directory when it shouldn't. + # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. + ls_ld_tmpdir=`ls -ld "$tmpdir"` + case $ls_ld_tmpdir in + d????-?r-*) different_mode=700;; + d????-?--*) different_mode=755;; + *) false;; + esac && + $mkdirprog -m$different_mode -p -- "$tmpdir" && { + ls_ld_tmpdir_1=`ls -ld "$tmpdir"` + test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" + } + } + then posix_mkdir=: + fi + rmdir "$tmpdir/d" "$tmpdir" + else + # Remove any dirs left behind by ancient mkdir implementations. + rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null + fi + trap '' 0;; + esac;; + esac + + if + $posix_mkdir && ( + umask $mkdir_umask && + $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" + ) + then : + else + + # The umask is ridiculous, or mkdir does not conform to POSIX, + # or it failed possibly due to a race condition. Create the + # directory the slow way, step by step, checking for races as we go. + + case $dstdir in + /*) prefix='/';; + -*) prefix='./';; + *) prefix='';; + esac + + eval "$initialize_posix_glob" + + oIFS=$IFS + IFS=/ + $posix_glob set -f + set fnord $dstdir + shift + $posix_glob set +f + IFS=$oIFS + + prefixes= + + for d + do + test -z "$d" && continue + + prefix=$prefix$d + if test -d "$prefix"; then + prefixes= + else + if $posix_mkdir; then + (umask=$mkdir_umask && + $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break + # Don't fail if two instances are running concurrently. + test -d "$prefix" || exit 1 + else + case $prefix in + *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; + *) qprefix=$prefix;; + esac + prefixes="$prefixes '$qprefix'" + fi + fi + prefix=$prefix/ + done + + if test -n "$prefixes"; then + # Don't fail if two instances are running concurrently. + (umask $mkdir_umask && + eval "\$doit_exec \$mkdirprog $prefixes") || + test -d "$dstdir" || exit 1 + obsolete_mkdir_used=true + fi + fi + fi + + if test -n "$dir_arg"; then + { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && + { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && + { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || + test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 + else + + # Make a couple of temp file names in the proper directory. + dsttmp=$dstdir/_inst.$$_ + rmtmp=$dstdir/_rm.$$_ + + # Trap to clean up those temp files at exit. + trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 + + # Copy the file name to the temp name. + (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && + + # and set any options; do chmod last to preserve setuid bits. + # + # If any of these fail, we abort the whole thing. If we want to + # ignore errors from any of these, just make sure not to ignore + # errors from the above "$doit $cpprog $src $dsttmp" command. + # + { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && + { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && + { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && + { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && + + # If -C, don't bother to copy if it wouldn't change the file. + if $copy_on_change && + old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && + new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && + + eval "$initialize_posix_glob" && + $posix_glob set -f && + set X $old && old=:$2:$4:$5:$6 && + set X $new && new=:$2:$4:$5:$6 && + $posix_glob set +f && + + test "$old" = "$new" && + $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 + then + rm -f "$dsttmp" + else + # Rename the file to the real destination. + $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || + + # The rename failed, perhaps because mv can't rename something else + # to itself, or perhaps because mv is so ancient that it does not + # support -f. + { + # Now remove or move aside any old file at destination location. + # We try this two ways since rm can't unlink itself on some + # systems and the destination file might be busy for other + # reasons. In this case, the final cleanup might fail but the new + # file should still install successfully. + { + test ! -f "$dst" || + $doit $rmcmd -f "$dst" 2>/dev/null || + { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && + { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } + } || + { echo "$0: cannot unlink or rename $dst" >&2 + (exit 1); exit 1 + } + } && + + # Now rename the file to the real destination. + $doit $mvcmd "$dsttmp" "$dst" + } + fi || exit 1 + + trap '' 0 + fi +done + +# Local variables: +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "scriptversion=" +# time-stamp-format: "%:y-%02m-%02d.%02H" +# time-stamp-time-zone: "UTC" +# time-stamp-end: "; # UTC" +# End: diff --git a/libs/libpng-src/libpng-1.2.46.txt b/libs/libpng-src/libpng-1.2.46.txt new file mode 100644 index 000000000..9edd7aa87 --- /dev/null +++ b/libs/libpng-src/libpng-1.2.46.txt @@ -0,0 +1,3234 @@ +libpng.txt - A description on how to use and modify libpng + + libpng version 1.2.46 - July 9, 2011 + Updated and distributed by Glenn Randers-Pehrson + + Copyright (c) 1998-2009 Glenn Randers-Pehrson + + This document is released under the libpng license. + For conditions of distribution and use, see the disclaimer + and license in png.h + + Based on: + + libpng versions 0.97, January 1998, through 1.2.46 - July 9, 2011 + Updated and distributed by Glenn Randers-Pehrson + Copyright (c) 1998-2009 Glenn Randers-Pehrson + + libpng 1.0 beta 6 version 0.96 May 28, 1997 + Updated and distributed by Andreas Dilger + Copyright (c) 1996, 1997 Andreas Dilger + + libpng 1.0 beta 2 - version 0.88 January 26, 1996 + For conditions of distribution and use, see copyright + notice in png.h. Copyright (c) 1995, 1996 Guy Eric + Schalnat, Group 42, Inc. + + Updated/rewritten per request in the libpng FAQ + Copyright (c) 1995, 1996 Frank J. T. Wojcik + December 18, 1995 & January 20, 1996 + +I. Introduction + +This file describes how to use and modify the PNG reference library +(known as libpng) for your own use. There are five sections to this +file: introduction, structures, reading, writing, and modification and +configuration notes for various special platforms. In addition to this +file, example.c is a good starting point for using the library, as +it is heavily commented and should include everything most people +will need. We assume that libpng is already installed; see the +INSTALL file for instructions on how to install libpng. + +For examples of libpng usage, see the files "example.c", "pngtest.c", +and the files in the "contrib" directory, all of which are included in +the libpng distribution. + +Libpng was written as a companion to the PNG specification, as a way +of reducing the amount of time and effort it takes to support the PNG +file format in application programs. + +The PNG specification (second edition), November 2003, is available as +a W3C Recommendation and as an ISO Standard (ISO/IEC 15948:2003 (E)) at +. It is technically equivalent +to the PNG specification (second edition) but has some additional material. + +The PNG-1.0 specification is available +as RFC 2083 and as a +W3C Recommendation . + +Some additional chunks are described in the special-purpose public chunks +documents at . + +Other information +about PNG, and the latest version of libpng, can be found at the PNG home +page, . + +Most users will not have to modify the library significantly; advanced +users may want to modify it more. All attempts were made to make it as +complete as possible, while keeping the code easy to understand. +Currently, this library only supports C. Support for other languages +is being considered. + +Libpng has been designed to handle multiple sessions at one time, +to be easily modifiable, to be portable to the vast majority of +machines (ANSI, K&R, 16-, 32-, and 64-bit) available, and to be easy +to use. The ultimate goal of libpng is to promote the acceptance of +the PNG file format in whatever way possible. While there is still +work to be done (see the TODO file), libpng should cover the +majority of the needs of its users. + +Libpng uses zlib for its compression and decompression of PNG files. +Further information about zlib, and the latest version of zlib, can +be found at the zlib home page, . +The zlib compression utility is a general purpose utility that is +useful for more than PNG files, and can be used without libpng. +See the documentation delivered with zlib for more details. +You can usually find the source files for the zlib utility wherever you +find the libpng source files. + +Libpng is thread safe, provided the threads are using different +instances of the structures. Each thread should have its own +png_struct and png_info instances, and thus its own image. +Libpng does not protect itself against two threads using the +same instance of a structure. + +II. Structures + +There are two main structures that are important to libpng, png_struct +and png_info. The first, png_struct, is an internal structure that +will not, for the most part, be used by a user except as the first +variable passed to every libpng function call. + +The png_info structure is designed to provide information about the +PNG file. At one time, the fields of png_info were intended to be +directly accessible to the user. However, this tended to cause problems +with applications using dynamically loaded libraries, and as a result +a set of interface functions for png_info (the png_get_*() and png_set_*() +functions) was developed. The fields of png_info are still available for +older applications, but it is suggested that applications use the new +interfaces if at all possible. + +Applications that do make direct access to the members of png_struct (except +for png_ptr->jmpbuf) must be recompiled whenever the library is updated, +and applications that make direct access to the members of png_info must +be recompiled if they were compiled or loaded with libpng version 1.0.6, +in which the members were in a different order. In version 1.0.7, the +members of the png_info structure reverted to the old order, as they were +in versions 0.97c through 1.0.5. Starting with version 2.0.0, both +structures are going to be hidden, and the contents of the structures will +only be accessible through the png_get/png_set functions. + +The png.h header file is an invaluable reference for programming with libpng. +And while I'm on the topic, make sure you include the libpng header file: + +#include + +III. Reading + +We'll now walk you through the possible functions to call when reading +in a PNG file sequentially, briefly explaining the syntax and purpose +of each one. See example.c and png.h for more detail. While +progressive reading is covered in the next section, you will still +need some of the functions discussed in this section to read a PNG +file. + +Setup + +You will want to do the I/O initialization(*) before you get into libpng, +so if it doesn't work, you don't have much to undo. Of course, you +will also want to insure that you are, in fact, dealing with a PNG +file. Libpng provides a simple check to see if a file is a PNG file. +To use it, pass in the first 1 to 8 bytes of the file to the function +png_sig_cmp(), and it will return 0 (false) if the bytes match the +corresponding bytes of the PNG signature, or nonzero (true) otherwise. +Of course, the more bytes you pass in, the greater the accuracy of the +prediction. + +If you are intending to keep the file pointer open for use in libpng, +you must ensure you don't read more than 8 bytes from the beginning +of the file, and you also have to make a call to png_set_sig_bytes_read() +with the number of bytes you read from the beginning. Libpng will +then only check the bytes (if any) that your program didn't read. + +(*): If you are not using the standard I/O functions, you will need +to replace them with custom functions. See the discussion under +Customizing libpng. + + + FILE *fp = fopen(file_name, "rb"); + if (!fp) + { + return (ERROR); + } + fread(header, 1, number, fp); + is_png = !png_sig_cmp(header, 0, number); + if (!is_png) + { + return (NOT_PNG); + } + + +Next, png_struct and png_info need to be allocated and initialized. In +order to ensure that the size of these structures is correct even with a +dynamically linked libpng, there are functions to initialize and +allocate the structures. We also pass the library version, optional +pointers to error handling functions, and a pointer to a data struct for +use by the error functions, if necessary (the pointer and functions can +be NULL if the default error handlers are to be used). See the section +on Changes to Libpng below regarding the old initialization functions. +The structure allocation functions quietly return NULL if they fail to +create the structure, so your application should check for that. + + png_structp png_ptr = png_create_read_struct + (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr, + user_error_fn, user_warning_fn); + if (!png_ptr) + return (ERROR); + + png_infop info_ptr = png_create_info_struct(png_ptr); + if (!info_ptr) + { + png_destroy_read_struct(&png_ptr, + (png_infopp)NULL, (png_infopp)NULL); + return (ERROR); + } + + png_infop end_info = png_create_info_struct(png_ptr); + if (!end_info) + { + png_destroy_read_struct(&png_ptr, &info_ptr, + (png_infopp)NULL); + return (ERROR); + } + +If you want to use your own memory allocation routines, +define PNG_USER_MEM_SUPPORTED and use +png_create_read_struct_2() instead of png_create_read_struct(): + + png_structp png_ptr = png_create_read_struct_2 + (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr, + user_error_fn, user_warning_fn, (png_voidp) + user_mem_ptr, user_malloc_fn, user_free_fn); + +The error handling routines passed to png_create_read_struct() +and the memory alloc/free routines passed to png_create_struct_2() +are only necessary if you are not using the libpng supplied error +handling and memory alloc/free functions. + +When libpng encounters an error, it expects to longjmp back +to your routine. Therefore, you will need to call setjmp and pass +your png_jmpbuf(png_ptr). If you read the file from different +routines, you will need to update the jmpbuf field every time you enter +a new routine that will call a png_*() function. + +See your documentation of setjmp/longjmp for your compiler for more +information on setjmp/longjmp. See the discussion on libpng error +handling in the Customizing Libpng section below for more information +on the libpng error handling. If an error occurs, and libpng longjmp's +back to your setjmp, you will want to call png_destroy_read_struct() to +free any memory. + + if (setjmp(png_jmpbuf(png_ptr))) + { + png_destroy_read_struct(&png_ptr, &info_ptr, + &end_info); + fclose(fp); + return (ERROR); + } + +If you would rather avoid the complexity of setjmp/longjmp issues, +you can compile libpng with PNG_SETJMP_NOT_SUPPORTED, in which case +errors will result in a call to PNG_ABORT() which defaults to abort(). + +Now you need to set up the input code. The default for libpng is to +use the C function fread(). If you use this, you will need to pass a +valid FILE * in the function png_init_io(). Be sure that the file is +opened in binary mode. If you wish to handle reading data in another +way, you need not call the png_init_io() function, but you must then +implement the libpng I/O methods discussed in the Customizing Libpng +section below. + + png_init_io(png_ptr, fp); + +If you had previously opened the file and read any of the signature from +the beginning in order to see if this was a PNG file, you need to let +libpng know that there are some bytes missing from the start of the file. + + png_set_sig_bytes(png_ptr, number); + +Setting up callback code + +You can set up a callback function to handle any unknown chunks in the +input stream. You must supply the function + + read_chunk_callback(png_ptr ptr, + png_unknown_chunkp chunk); + { + /* The unknown chunk structure contains your + chunk data, along with similar data for any other + unknown chunks: */ + + png_byte name[5]; + png_byte *data; + png_size_t size; + + /* Note that libpng has already taken care of + the CRC handling */ + + /* put your code here. Search for your chunk in the + unknown chunk structure, process it, and return one + of the following: */ + + return (-n); /* chunk had an error */ + return (0); /* did not recognize */ + return (n); /* success */ + } + +(You can give your function another name that you like instead of +"read_chunk_callback") + +To inform libpng about your function, use + + png_set_read_user_chunk_fn(png_ptr, user_chunk_ptr, + read_chunk_callback); + +This names not only the callback function, but also a user pointer that +you can retrieve with + + png_get_user_chunk_ptr(png_ptr); + +If you call the png_set_read_user_chunk_fn() function, then all unknown +chunks will be saved when read, in case your callback function will need +one or more of them. This behavior can be changed with the +png_set_keep_unknown_chunks() function, described below. + +At this point, you can set up a callback function that will be +called after each row has been read, which you can use to control +a progress meter or the like. It's demonstrated in pngtest.c. +You must supply a function + + void read_row_callback(png_ptr ptr, png_uint_32 row, + int pass); + { + /* put your code here */ + } + +(You can give it another name that you like instead of "read_row_callback") + +To inform libpng about your function, use + + png_set_read_status_fn(png_ptr, read_row_callback); + +Unknown-chunk handling + +Now you get to set the way the library processes unknown chunks in the +input PNG stream. Both known and unknown chunks will be read. Normal +behavior is that known chunks will be parsed into information in +various info_ptr members while unknown chunks will be discarded. This +behavior can be wasteful if your application will never use some known +chunk types. To change this, you can call: + + png_set_keep_unknown_chunks(png_ptr, keep, + chunk_list, num_chunks); + keep - 0: default unknown chunk handling + 1: ignore; do not keep + 2: keep only if safe-to-copy + 3: keep even if unsafe-to-copy + You can use these definitions: + PNG_HANDLE_CHUNK_AS_DEFAULT 0 + PNG_HANDLE_CHUNK_NEVER 1 + PNG_HANDLE_CHUNK_IF_SAFE 2 + PNG_HANDLE_CHUNK_ALWAYS 3 + chunk_list - list of chunks affected (a byte string, + five bytes per chunk, NULL or '\0' if + num_chunks is 0) + num_chunks - number of chunks affected; if 0, all + unknown chunks are affected. If nonzero, + only the chunks in the list are affected + +Unknown chunks declared in this way will be saved as raw data onto a +list of png_unknown_chunk structures. If a chunk that is normally +known to libpng is named in the list, it will be handled as unknown, +according to the "keep" directive. If a chunk is named in successive +instances of png_set_keep_unknown_chunks(), the final instance will +take precedence. The IHDR and IEND chunks should not be named in +chunk_list; if they are, libpng will process them normally anyway. + +Here is an example of the usage of png_set_keep_unknown_chunks(), +where the private "vpAg" chunk will later be processed by a user chunk +callback function: + + png_byte vpAg[5]={118, 112, 65, 103, (png_byte) '\0'}; + + #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) + png_byte unused_chunks[]= + { + 104, 73, 83, 84, (png_byte) '\0', /* hIST */ + 105, 84, 88, 116, (png_byte) '\0', /* iTXt */ + 112, 67, 65, 76, (png_byte) '\0', /* pCAL */ + 115, 67, 65, 76, (png_byte) '\0', /* sCAL */ + 115, 80, 76, 84, (png_byte) '\0', /* sPLT */ + 116, 73, 77, 69, (png_byte) '\0', /* tIME */ + }; + #endif + + ... + + #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) + /* ignore all unknown chunks: */ + png_set_keep_unknown_chunks(read_ptr, 1, NULL, 0); + /* except for vpAg: */ + png_set_keep_unknown_chunks(read_ptr, 2, vpAg, 1); + /* also ignore unused known chunks: */ + png_set_keep_unknown_chunks(read_ptr, 1, unused_chunks, + (int)sizeof(unused_chunks)/5); + #endif + +User limits + +The PNG specification allows the width and height of an image to be as +large as 2^31-1 (0x7fffffff), or about 2.147 billion rows and columns. +Since very few applications really need to process such large images, +we have imposed an arbitrary 1-million limit on rows and columns. +Larger images will be rejected immediately with a png_error() call. If +you wish to override this limit, you can use + + png_set_user_limits(png_ptr, width_max, height_max); + +to set your own limits, or use width_max = height_max = 0x7fffffffL +to allow all valid dimensions (libpng may reject some very large images +anyway because of potential buffer overflow conditions). + +You should put this statement after you create the PNG structure and +before calling png_read_info(), png_read_png(), or png_process_data(). +If you need to retrieve the limits that are being applied, use + + width_max = png_get_user_width_max(png_ptr); + height_max = png_get_user_height_max(png_ptr); + +The PNG specification sets no limit on the number of ancillary chunks +allowed in a PNG datastream. You can impose a limit on the total number +of sPLT, tEXt, iTXt, zTXt, and unknown chunks that will be stored, with + + png_set_chunk_cache_max(png_ptr, user_chunk_cache_max); + +where 0x7fffffffL means unlimited. You can retrieve this limit with + + chunk_cache_max = png_get_chunk_cache_max(png_ptr); + +This limit also applies to the number of buffers that can be allocated +by png_decompress_chunk() while decompressing iTXt, zTXt, and iCCP chunks. + +The high-level read interface + +At this point there are two ways to proceed; through the high-level +read interface, or through a sequence of low-level read operations. +You can use the high-level interface if (a) you are willing to read +the entire image into memory, and (b) the input transformations +you want to do are limited to the following set: + + PNG_TRANSFORM_IDENTITY No transformation + PNG_TRANSFORM_STRIP_16 Strip 16-bit samples to + 8 bits + PNG_TRANSFORM_STRIP_ALPHA Discard the alpha channel + PNG_TRANSFORM_PACKING Expand 1, 2 and 4-bit + samples to bytes + PNG_TRANSFORM_PACKSWAP Change order of packed + pixels to LSB first + PNG_TRANSFORM_EXPAND Perform set_expand() + PNG_TRANSFORM_INVERT_MONO Invert monochrome images + PNG_TRANSFORM_SHIFT Normalize pixels to the + sBIT depth + PNG_TRANSFORM_BGR Flip RGB to BGR, RGBA + to BGRA + PNG_TRANSFORM_SWAP_ALPHA Flip RGBA to ARGB or GA + to AG + PNG_TRANSFORM_INVERT_ALPHA Change alpha from opacity + to transparency + PNG_TRANSFORM_SWAP_ENDIAN Byte-swap 16-bit samples + PNG_TRANSFORM_GRAY_TO_RGB Expand grayscale samples + to RGB (or GA to RGBA) + +(This excludes setting a background color, doing gamma transformation, +dithering, and setting filler.) If this is the case, simply do this: + + png_read_png(png_ptr, info_ptr, png_transforms, NULL) + +where png_transforms is an integer containing the bitwise OR of some +set of transformation flags. This call is equivalent to png_read_info(), +followed the set of transformations indicated by the transform mask, +then png_read_image(), and finally png_read_end(). + +(The final parameter of this call is not yet used. Someday it might point +to transformation parameters required by some future input transform.) + +You must use png_transforms and not call any png_set_transform() functions +when you use png_read_png(). + +After you have called png_read_png(), you can retrieve the image data +with + + row_pointers = png_get_rows(png_ptr, info_ptr); + +where row_pointers is an array of pointers to the pixel data for each row: + + png_bytep row_pointers[height]; + +If you know your image size and pixel size ahead of time, you can allocate +row_pointers prior to calling png_read_png() with + + if (height > PNG_UINT_32_MAX/png_sizeof(png_byte)) + png_error (png_ptr, + "Image is too tall to process in memory"); + if (width > PNG_UINT_32_MAX/pixel_size) + png_error (png_ptr, + "Image is too wide to process in memory"); + row_pointers = png_malloc(png_ptr, + height*png_sizeof(png_bytep)); + for (int i=0; i) and +png_get_(png_ptr, info_ptr, ...) functions return non-zero if the +data has been read, or zero if it is missing. The parameters to the +png_get_ are set directly if they are simple data types, or a +pointer into the info_ptr is returned for any complex types. + + png_get_PLTE(png_ptr, info_ptr, &palette, + &num_palette); + palette - the palette for the file + (array of png_color) + num_palette - number of entries in the palette + + png_get_gAMA(png_ptr, info_ptr, &gamma); + gamma - the gamma the file is written + at (PNG_INFO_gAMA) + + png_get_sRGB(png_ptr, info_ptr, &srgb_intent); + srgb_intent - the rendering intent (PNG_INFO_sRGB) + The presence of the sRGB chunk + means that the pixel data is in the + sRGB color space. This chunk also + implies specific values of gAMA and + cHRM. + + png_get_iCCP(png_ptr, info_ptr, &name, + &compression_type, &profile, &proflen); + name - The profile name. + compression - The compression type; always + PNG_COMPRESSION_TYPE_BASE for PNG 1.0. + You may give NULL to this argument to + ignore it. + profile - International Color Consortium color + profile data. May contain NULs. + proflen - length of profile data in bytes. + + png_get_sBIT(png_ptr, info_ptr, &sig_bit); + sig_bit - the number of significant bits for + (PNG_INFO_sBIT) each of the gray, + red, green, and blue channels, + whichever are appropriate for the + given color type (png_color_16) + + png_get_tRNS(png_ptr, info_ptr, &trans, &num_trans, + &trans_values); + trans - array of transparent + entries for palette (PNG_INFO_tRNS) + trans_values - graylevel or color sample values of + the single transparent color for + non-paletted images (PNG_INFO_tRNS) + num_trans - number of transparent entries + (PNG_INFO_tRNS) + + png_get_hIST(png_ptr, info_ptr, &hist); + (PNG_INFO_hIST) + hist - histogram of palette (array of + png_uint_16) + + png_get_tIME(png_ptr, info_ptr, &mod_time); + mod_time - time image was last modified + (PNG_VALID_tIME) + + png_get_bKGD(png_ptr, info_ptr, &background); + background - background color (PNG_VALID_bKGD) + valid 16-bit red, green and blue + values, regardless of color_type + + num_comments = png_get_text(png_ptr, info_ptr, + &text_ptr, &num_text); + num_comments - number of comments + text_ptr - array of png_text holding image + comments + text_ptr[i].compression - type of compression used + on "text" PNG_TEXT_COMPRESSION_NONE + PNG_TEXT_COMPRESSION_zTXt + PNG_ITXT_COMPRESSION_NONE + PNG_ITXT_COMPRESSION_zTXt + text_ptr[i].key - keyword for comment. Must contain + 1-79 characters. + text_ptr[i].text - text comments for current + keyword. Can be empty. + text_ptr[i].text_length - length of text string, + after decompression, 0 for iTXt + text_ptr[i].itxt_length - length of itxt string, + after decompression, 0 for tEXt/zTXt + text_ptr[i].lang - language of comment (empty + string for unknown). + text_ptr[i].lang_key - keyword in UTF-8 + (empty string for unknown). + Note that the itxt_length, lang, and lang_key + members of the text_ptr structure only exist + when the library is built with iTXt chunk support. + + num_text - number of comments (same as + num_comments; you can put NULL here + to avoid the duplication) + Note while png_set_text() will accept text, language, + and translated keywords that can be NULL pointers, the + structure returned by png_get_text will always contain + regular zero-terminated C strings. They might be + empty strings but they will never be NULL pointers. + + num_spalettes = png_get_sPLT(png_ptr, info_ptr, + &palette_ptr); + palette_ptr - array of palette structures holding + contents of one or more sPLT chunks + read. + num_spalettes - number of sPLT chunks read. + + png_get_oFFs(png_ptr, info_ptr, &offset_x, &offset_y, + &unit_type); + offset_x - positive offset from the left edge + of the screen + offset_y - positive offset from the top edge + of the screen + unit_type - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER + + png_get_pHYs(png_ptr, info_ptr, &res_x, &res_y, + &unit_type); + res_x - pixels/unit physical resolution in + x direction + res_y - pixels/unit physical resolution in + x direction + unit_type - PNG_RESOLUTION_UNKNOWN, + PNG_RESOLUTION_METER + + png_get_sCAL(png_ptr, info_ptr, &unit, &width, + &height) + unit - physical scale units (an integer) + width - width of a pixel in physical scale units + height - height of a pixel in physical scale units + (width and height are doubles) + + png_get_sCAL_s(png_ptr, info_ptr, &unit, &width, + &height) + unit - physical scale units (an integer) + width - width of a pixel in physical scale units + height - height of a pixel in physical scale units + (width and height are strings like "2.54") + + num_unknown_chunks = png_get_unknown_chunks(png_ptr, + info_ptr, &unknowns) + unknowns - array of png_unknown_chunk + structures holding unknown chunks + unknowns[i].name - name of unknown chunk + unknowns[i].data - data of unknown chunk + unknowns[i].size - size of unknown chunk's data + unknowns[i].location - position of chunk in file + + The value of "i" corresponds to the order in which the + chunks were read from the PNG file or inserted with the + png_set_unknown_chunks() function. + +The data from the pHYs chunk can be retrieved in several convenient +forms: + + res_x = png_get_x_pixels_per_meter(png_ptr, + info_ptr) + res_y = png_get_y_pixels_per_meter(png_ptr, + info_ptr) + res_x_and_y = png_get_pixels_per_meter(png_ptr, + info_ptr) + res_x = png_get_x_pixels_per_inch(png_ptr, + info_ptr) + res_y = png_get_y_pixels_per_inch(png_ptr, + info_ptr) + res_x_and_y = png_get_pixels_per_inch(png_ptr, + info_ptr) + aspect_ratio = png_get_pixel_aspect_ratio(png_ptr, + info_ptr) + + (Each of these returns 0 [signifying "unknown"] if + the data is not present or if res_x is 0; + res_x_and_y is 0 if res_x != res_y) + +The data from the oFFs chunk can be retrieved in several convenient +forms: + + x_offset = png_get_x_offset_microns(png_ptr, info_ptr); + y_offset = png_get_y_offset_microns(png_ptr, info_ptr); + x_offset = png_get_x_offset_inches(png_ptr, info_ptr); + y_offset = png_get_y_offset_inches(png_ptr, info_ptr); + + (Each of these returns 0 [signifying "unknown" if both + x and y are 0] if the data is not present or if the + chunk is present but the unit is the pixel) + +For more information, see the png_info definition in png.h and the +PNG specification for chunk contents. Be careful with trusting +rowbytes, as some of the transformations could increase the space +needed to hold a row (expand, filler, gray_to_rgb, etc.). +See png_read_update_info(), below. + +A quick word about text_ptr and num_text. PNG stores comments in +keyword/text pairs, one pair per chunk, with no limit on the number +of text chunks, and a 2^31 byte limit on their size. While there are +suggested keywords, there is no requirement to restrict the use to these +strings. It is strongly suggested that keywords and text be sensible +to humans (that's the point), so don't use abbreviations. Non-printing +symbols are not allowed. See the PNG specification for more details. +There is also no requirement to have text after the keyword. + +Keywords should be limited to 79 Latin-1 characters without leading or +trailing spaces, but non-consecutive spaces are allowed within the +keyword. It is possible to have the same keyword any number of times. +The text_ptr is an array of png_text structures, each holding a +pointer to a language string, a pointer to a keyword and a pointer to +a text string. The text string, language code, and translated +keyword may be empty or NULL pointers. The keyword/text +pairs are put into the array in the order that they are received. +However, some or all of the text chunks may be after the image, so, to +make sure you have read all the text chunks, don't mess with these +until after you read the stuff after the image. This will be +mentioned again below in the discussion that goes with png_read_end(). + +Input transformations + +After you've read the header information, you can set up the library +to handle any special transformations of the image data. The various +ways to transform the data will be described in the order that they +should occur. This is important, as some of these change the color +type and/or bit depth of the data, and some others only work on +certain color types and bit depths. Even though each transformation +checks to see if it has data that it can do something with, you should +make sure to only enable a transformation if it will be valid for the +data. For example, don't swap red and blue on grayscale data. + +The colors used for the background and transparency values should be +supplied in the same format/depth as the current image data. They +are stored in the same format/depth as the image data in a bKGD or tRNS +chunk, so this is what libpng expects for this data. The colors are +transformed to keep in sync with the image data when an application +calls the png_read_update_info() routine (see below). + +Data will be decoded into the supplied row buffers packed into bytes +unless the library has been told to transform it into another format. +For example, 4 bit/pixel paletted or grayscale data will be returned +2 pixels/byte with the leftmost pixel in the high-order bits of the +byte, unless png_set_packing() is called. 8-bit RGB data will be stored +in RGB RGB RGB format unless png_set_filler() or png_set_add_alpha() +is called to insert filler bytes, either before or after each RGB triplet. +16-bit RGB data will be returned RRGGBB RRGGBB, with the most significant +byte of the color value first, unless png_set_strip_16() is called to +transform it to regular RGB RGB triplets, or png_set_filler() or +png_set_add alpha() is called to insert filler bytes, either before or +after each RRGGBB triplet. Similarly, 8-bit or 16-bit grayscale data can +be modified with +png_set_filler(), png_set_add_alpha(), or png_set_strip_16(). + +The following code transforms grayscale images of less than 8 to 8 bits, +changes paletted images to RGB, and adds a full alpha channel if there is +transparency information in a tRNS chunk. This is most useful on +grayscale images with bit depths of 2 or 4 or if there is a multiple-image +viewing application that wishes to treat all images in the same way. + + if (color_type == PNG_COLOR_TYPE_PALETTE) + png_set_palette_to_rgb(png_ptr); + + if (color_type == PNG_COLOR_TYPE_GRAY && + bit_depth < 8) png_set_expand_gray_1_2_4_to_8(png_ptr); + + if (png_get_valid(png_ptr, info_ptr, + PNG_INFO_tRNS)) png_set_tRNS_to_alpha(png_ptr); + +These three functions are actually aliases for png_set_expand(), added +in libpng version 1.0.4, with the function names expanded to improve code +readability. In some future version they may actually do different +things. + +As of libpng version 1.2.9, png_set_expand_gray_1_2_4_to_8() was +added. It expands the sample depth without changing tRNS to alpha. + +As of libpng version 1.2.46, not all possible expansions are supported. + +In the following table, the 01 means grayscale with depth<8, 31 means +indexed with depth<8, other numerals represent the color type, "T" means +the tRNS chunk is present, A means an alpha channel is present, and O +means tRNS or alpha is present but all pixels in the image are opaque. + + FROM 01 31 0 0T 0O 2 2T 2O 3 3T 3O 4A 4O 6A 6O + TO + 01 - + 31 - + 0 1 - + 0T - + 0O - + 2 GX - + 2T - + 2O - + 3 1 - + 3T - + 3O - + 4A T - + 4O - + 6A GX TX TX - + 6O GX TX - + +Within the matrix, + "-" means the transformation is not supported. + "X" means the transformation is obtained by png_set_expand(). + "1" means the transformation is obtained by + png_set_expand_gray_1_2_4_to_8 + "G" means the transformation is obtained by + png_set_gray_to_rgb(). + "P" means the transformation is obtained by + png_set_expand_palette_to_rgb(). + "T" means the transformation is obtained by + png_set_tRNS_to_alpha(). + +PNG can have files with 16 bits per channel. If you only can handle +8 bits per channel, this will strip the pixels down to 8 bit. + + if (bit_depth == 16) + png_set_strip_16(png_ptr); + +If, for some reason, you don't need the alpha channel on an image, +and you want to remove it rather than combining it with the background +(but the image author certainly had in mind that you *would* combine +it with the background, so that's what you should probably do): + + if (color_type & PNG_COLOR_MASK_ALPHA) + png_set_strip_alpha(png_ptr); + +In PNG files, the alpha channel in an image +is the level of opacity. If you need the alpha channel in an image to +be the level of transparency instead of opacity, you can invert the +alpha channel (or the tRNS chunk data) after it's read, so that 0 is +fully opaque and 255 (in 8-bit or paletted images) or 65535 (in 16-bit +images) is fully transparent, with + + png_set_invert_alpha(png_ptr); + +The PNG format only supports pixels with postmultiplied alpha. +If you want to replace the pixels, after reading them, with pixels +that have premultiplied color samples, you can do this with + + png_set_premultiply_alpha(png_ptr); + +If you do this, any input with a tRNS chunk will be expanded to +have an alpha channel. + +PNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as +they can, resulting in, for example, 8 pixels per byte for 1 bit +files. This code expands to 1 pixel per byte without changing the +values of the pixels: + + if (bit_depth < 8) + png_set_packing(png_ptr); + +PNG files have possible bit depths of 1, 2, 4, 8, and 16. All pixels +stored in a PNG image have been "scaled" or "shifted" up to the next +higher possible bit depth (e.g. from 5 bits/sample in the range [0,31] +to 8 bits/sample in the range [0, 255]). However, it is also possible +to convert the PNG pixel data back to the original bit depth of the +image. This call reduces the pixels back down to the original bit depth: + + png_color_8p sig_bit; + + if (png_get_sBIT(png_ptr, info_ptr, &sig_bit)) + png_set_shift(png_ptr, sig_bit); + +PNG files store 3-color pixels in red, green, blue order. This code +changes the storage of the pixels to blue, green, red: + + if (color_type == PNG_COLOR_TYPE_RGB || + color_type == PNG_COLOR_TYPE_RGB_ALPHA) + png_set_bgr(png_ptr); + +PNG files store RGB pixels packed into 3 or 6 bytes. This code expands them +into 4 or 8 bytes for windowing systems that need them in this format: + + if (color_type == PNG_COLOR_TYPE_RGB) + png_set_filler(png_ptr, filler, PNG_FILLER_BEFORE); + +where "filler" is the 8 or 16-bit number to fill with, and the location is +either PNG_FILLER_BEFORE or PNG_FILLER_AFTER, depending upon whether +you want the filler before the RGB or after. This transformation +does not affect images that already have full alpha channels. To add an +opaque alpha channel, use filler=0xff or 0xffff and PNG_FILLER_AFTER which +will generate RGBA pixels. + +Note that png_set_filler() does not change the color type. If you want +to do that, you can add a true alpha channel with + + if (color_type == PNG_COLOR_TYPE_RGB || + color_type == PNG_COLOR_TYPE_GRAY) + png_set_add_alpha(png_ptr, filler, PNG_FILLER_AFTER); + +where "filler" contains the alpha value to assign to each pixel. +This function was added in libpng-1.2.7. + +If you are reading an image with an alpha channel, and you need the +data as ARGB instead of the normal PNG format RGBA: + + if (color_type == PNG_COLOR_TYPE_RGB_ALPHA) + png_set_swap_alpha(png_ptr); + +For some uses, you may want a grayscale image to be represented as +RGB. This code will do that conversion: + + if (color_type == PNG_COLOR_TYPE_GRAY || + color_type == PNG_COLOR_TYPE_GRAY_ALPHA) + png_set_gray_to_rgb(png_ptr); + +Conversely, you can convert an RGB or RGBA image to grayscale or grayscale +with alpha. + + if (color_type == PNG_COLOR_TYPE_RGB || + color_type == PNG_COLOR_TYPE_RGB_ALPHA) + png_set_rgb_to_gray_fixed(png_ptr, error_action, + int red_weight, int green_weight); + + error_action = 1: silently do the conversion + error_action = 2: issue a warning if the original + image has any pixel where + red != green or red != blue + error_action = 3: issue an error and abort the + conversion if the original + image has any pixel where + red != green or red != blue + + red_weight: weight of red component times 100000 + green_weight: weight of green component times 100000 + If either weight is negative, default + weights (21268, 71514) are used. + +If you have set error_action = 1 or 2, you can +later check whether the image really was gray, after processing +the image rows, with the png_get_rgb_to_gray_status(png_ptr) function. +It will return a png_byte that is zero if the image was gray or +1 if there were any non-gray pixels. bKGD and sBIT data +will be silently converted to grayscale, using the green channel +data, regardless of the error_action setting. + +With red_weight+green_weight<=100000, +the normalized graylevel is computed: + + int rw = red_weight * 65536; + int gw = green_weight * 65536; + int bw = 65536 - (rw + gw); + gray = (rw*red + gw*green + bw*blue)/65536; + +The default values approximate those recommended in the Charles +Poynton's Color FAQ, +Copyright (c) 1998-01-04 Charles Poynton + + Y = 0.212671 * R + 0.715160 * G + 0.072169 * B + +Libpng approximates this with + + Y = 0.21268 * R + 0.7151 * G + 0.07217 * B + +which can be expressed with integers as + + Y = (6969 * R + 23434 * G + 2365 * B)/32768 + +The calculation is done in a linear colorspace, if the image gamma +is known. + +If you have a grayscale and you are using png_set_expand_depth(), +png_set_expand(), or png_set_gray_to_rgb to change to truecolor or to +a higher bit-depth, you must either supply the background color as a gray +value at the original file bit-depth (need_expand = 1) or else supply the +background color as an RGB triplet at the final, expanded bit depth +(need_expand = 0). Similarly, if you are reading a paletted image, you +must either supply the background color as a palette index (need_expand = 1) +or as an RGB triplet that may or may not be in the palette (need_expand = 0). + + png_color_16 my_background; + png_color_16p image_background; + + if (png_get_bKGD(png_ptr, info_ptr, &image_background)) + png_set_background(png_ptr, image_background, + PNG_BACKGROUND_GAMMA_FILE, 1, 1.0); + else + png_set_background(png_ptr, &my_background, + PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0); + +The png_set_background() function tells libpng to composite images +with alpha or simple transparency against the supplied background +color. If the PNG file contains a bKGD chunk (PNG_INFO_bKGD valid), +you may use this color, or supply another color more suitable for +the current display (e.g., the background color from a web page). You +need to tell libpng whether the color is in the gamma space of the +display (PNG_BACKGROUND_GAMMA_SCREEN for colors you supply), the file +(PNG_BACKGROUND_GAMMA_FILE for colors from the bKGD chunk), or one +that is neither of these gammas (PNG_BACKGROUND_GAMMA_UNIQUE - I don't +know why anyone would use this, but it's here). + +To properly display PNG images on any kind of system, the application needs +to know what the display gamma is. Ideally, the user will know this, and +the application will allow them to set it. One method of allowing the user +to set the display gamma separately for each system is to check for a +SCREEN_GAMMA or DISPLAY_GAMMA environment variable, which will hopefully be +correctly set. + +Note that display_gamma is the overall gamma correction required to produce +pleasing results, which depends on the lighting conditions in the surrounding +environment. In a dim or brightly lit room, no compensation other than +the physical gamma exponent of the monitor is needed, while in a dark room +a slightly smaller exponent is better. + + double gamma, screen_gamma; + + if (/* We have a user-defined screen + gamma value */) + { + screen_gamma = user_defined_screen_gamma; + } + /* One way that applications can share the same + screen gamma value */ + else if ((gamma_str = getenv("SCREEN_GAMMA")) + != NULL) + { + screen_gamma = (double)atof(gamma_str); + } + /* If we don't have another value */ + else + { + screen_gamma = 2.2; /* A good guess for a + PC monitor in a bright office or a dim room */ + screen_gamma = 2.0; /* A good guess for a + PC monitor in a dark room */ + screen_gamma = 1.7 or 1.0; /* A good + guess for Mac systems */ + } + +The png_set_gamma() function handles gamma transformations of the data. +Pass both the file gamma and the current screen_gamma. If the file does +not have a gamma value, you can pass one anyway if you have an idea what +it is (usually 0.45455 is a good guess for GIF images on PCs). Note +that file gammas are inverted from screen gammas. See the discussions +on gamma in the PNG specification for an excellent description of what +gamma is, and why all applications should support it. It is strongly +recommended that PNG viewers support gamma correction. + + if (png_get_gAMA(png_ptr, info_ptr, &gamma)) + png_set_gamma(png_ptr, screen_gamma, gamma); + else + png_set_gamma(png_ptr, screen_gamma, 0.45455); + +If you need to reduce an RGB file to a paletted file, or if a paletted +file has more entries then will fit on your screen, png_set_dither() +will do that. Note that this is a simple match dither that merely +finds the closest color available. This should work fairly well with +optimized palettes, and fairly badly with linear color cubes. If you +pass a palette that is larger then maximum_colors, the file will +reduce the number of colors in the palette so it will fit into +maximum_colors. If there is a histogram, it will use it to make +more intelligent choices when reducing the palette. If there is no +histogram, it may not do as good a job. + + if (color_type & PNG_COLOR_MASK_COLOR) + { + if (png_get_valid(png_ptr, info_ptr, + PNG_INFO_PLTE)) + { + png_uint_16p histogram = NULL; + + png_get_hIST(png_ptr, info_ptr, + &histogram); + png_set_dither(png_ptr, palette, num_palette, + max_screen_colors, histogram, 1); + } + else + { + png_color std_color_cube[MAX_SCREEN_COLORS] = + { ... colors ... }; + + png_set_dither(png_ptr, std_color_cube, + MAX_SCREEN_COLORS, MAX_SCREEN_COLORS, + NULL,0); + } + } + +PNG files describe monochrome as black being zero and white being one. +The following code will reverse this (make black be one and white be +zero): + + if (bit_depth == 1 && color_type == PNG_COLOR_TYPE_GRAY) + png_set_invert_mono(png_ptr); + +This function can also be used to invert grayscale and gray-alpha images: + + if (color_type == PNG_COLOR_TYPE_GRAY || + color_type == PNG_COLOR_TYPE_GRAY_ALPHA) + png_set_invert_mono(png_ptr); + +PNG files store 16 bit pixels in network byte order (big-endian, +ie. most significant bits first). This code changes the storage to the +other way (little-endian, i.e. least significant bits first, the +way PCs store them): + + if (bit_depth == 16) + png_set_swap(png_ptr); + +If you are using packed-pixel images (1, 2, or 4 bits/pixel), and you +need to change the order the pixels are packed into bytes, you can use: + + if (bit_depth < 8) + png_set_packswap(png_ptr); + +Finally, you can write your own transformation function if none of +the existing ones meets your needs. This is done by setting a callback +with + + png_set_read_user_transform_fn(png_ptr, + read_transform_fn); + +You must supply the function + + void read_transform_fn(png_ptr ptr, row_info_ptr + row_info, png_bytep data) + +See pngtest.c for a working example. Your function will be called +after all of the other transformations have been processed. + +You can also set up a pointer to a user structure for use by your +callback function, and you can inform libpng that your transform +function will change the number of channels or bit depth with the +function + + png_set_user_transform_info(png_ptr, user_ptr, + user_depth, user_channels); + +The user's application, not libpng, is responsible for allocating and +freeing any memory required for the user structure. + +You can retrieve the pointer via the function +png_get_user_transform_ptr(). For example: + + voidp read_user_transform_ptr = + png_get_user_transform_ptr(png_ptr); + +The last thing to handle is interlacing; this is covered in detail below, +but you must call the function here if you want libpng to handle expansion +of the interlaced image. + + number_of_passes = png_set_interlace_handling(png_ptr); + +After setting the transformations, libpng can update your png_info +structure to reflect any transformations you've requested with this +call. This is most useful to update the info structure's rowbytes +field so you can use it to allocate your image memory. This function +will also update your palette with the correct screen_gamma and +background if these have been given with the calls above. + + png_read_update_info(png_ptr, info_ptr); + +After you call png_read_update_info(), you can allocate any +memory you need to hold the image. The row data is simply +raw byte data for all forms of images. As the actual allocation +varies among applications, no example will be given. If you +are allocating one large chunk, you will need to build an +array of pointers to each row, as it will be needed for some +of the functions below. + +Reading image data + +After you've allocated memory, you can read the image data. +The simplest way to do this is in one function call. If you are +allocating enough memory to hold the whole image, you can just +call png_read_image() and libpng will read in all the image data +and put it in the memory area supplied. You will need to pass in +an array of pointers to each row. + +This function automatically handles interlacing, so you don't need +to call png_set_interlace_handling() or call this function multiple +times, or any of that other stuff necessary with png_read_rows(). + + png_read_image(png_ptr, row_pointers); + +where row_pointers is: + + png_bytep row_pointers[height]; + +You can point to void or char or whatever you use for pixels. + +If you don't want to read in the whole image at once, you can +use png_read_rows() instead. If there is no interlacing (check +interlace_type == PNG_INTERLACE_NONE), this is simple: + + png_read_rows(png_ptr, row_pointers, NULL, + number_of_rows); + +where row_pointers is the same as in the png_read_image() call. + +If you are doing this just one row at a time, you can do this with +a single row_pointer instead of an array of row_pointers: + + png_bytep row_pointer = row; + png_read_row(png_ptr, row_pointer, NULL); + +If the file is interlaced (interlace_type != 0 in the IHDR chunk), things +get somewhat harder. The only current (PNG Specification version 1.2) +interlacing type for PNG is (interlace_type == PNG_INTERLACE_ADAM7) +is a somewhat complicated 2D interlace scheme, known as Adam7, that +breaks down an image into seven smaller images of varying size, based +on an 8x8 grid. + +libpng can fill out those images or it can give them to you "as is". +If you want them filled out, there are two ways to do that. The one +mentioned in the PNG specification is to expand each pixel to cover +those pixels that have not been read yet (the "rectangle" method). +This results in a blocky image for the first pass, which gradually +smooths out as more pixels are read. The other method is the "sparkle" +method, where pixels are drawn only in their final locations, with the +rest of the image remaining whatever colors they were initialized to +before the start of the read. The first method usually looks better, +but tends to be slower, as there are more pixels to put in the rows. + +If you don't want libpng to handle the interlacing details, just call +png_read_rows() seven times to read in all seven images. Each of the +images is a valid image by itself, or they can all be combined on an +8x8 grid to form a single image (although if you intend to combine them +you would be far better off using the libpng interlace handling). + +The first pass will return an image 1/8 as wide as the entire image +(every 8th column starting in column 0) and 1/8 as high as the original +(every 8th row starting in row 0), the second will be 1/8 as wide +(starting in column 4) and 1/8 as high (also starting in row 0). The +third pass will be 1/4 as wide (every 4th pixel starting in column 0) and +1/8 as high (every 8th row starting in row 4), and the fourth pass will +be 1/4 as wide and 1/4 as high (every 4th column starting in column 2, +and every 4th row starting in row 0). The fifth pass will return an +image 1/2 as wide, and 1/4 as high (starting at column 0 and row 2), +while the sixth pass will be 1/2 as wide and 1/2 as high as the original +(starting in column 1 and row 0). The seventh and final pass will be as +wide as the original, and 1/2 as high, containing all of the odd +numbered scanlines. Phew! + +If you want libpng to expand the images, call this before calling +png_start_read_image() or png_read_update_info(): + + if (interlace_type == PNG_INTERLACE_ADAM7) + number_of_passes + = png_set_interlace_handling(png_ptr); + +This will return the number of passes needed. Currently, this +is seven, but may change if another interlace type is added. +This function can be called even if the file is not interlaced, +where it will return one pass. + +If you are not going to display the image after each pass, but are +going to wait until the entire image is read in, use the sparkle +effect. This effect is faster and the end result of either method +is exactly the same. If you are planning on displaying the image +after each pass, the "rectangle" effect is generally considered the +better looking one. + +If you only want the "sparkle" effect, just call png_read_rows() as +normal, with the third parameter NULL. Make sure you make pass over +the image number_of_passes times, and you don't change the data in the +rows between calls. You can change the locations of the data, just +not the data. Each pass only writes the pixels appropriate for that +pass, and assumes the data from previous passes is still valid. + + png_read_rows(png_ptr, row_pointers, NULL, + number_of_rows); + +If you only want the first effect (the rectangles), do the same as +before except pass the row buffer in the third parameter, and leave +the second parameter NULL. + + png_read_rows(png_ptr, NULL, row_pointers, + number_of_rows); + +Finishing a sequential read + +After you are finished reading the image through the +low-level interface, you can finish reading the file. If you are +interested in comments or time, which may be stored either before or +after the image data, you should pass the separate png_info struct if +you want to keep the comments from before and after the image +separate. If you are not interested, you can pass NULL. + + png_read_end(png_ptr, end_info); + +When you are done, you can free all memory allocated by libpng like this: + + png_destroy_read_struct(&png_ptr, &info_ptr, + &end_info); + +It is also possible to individually free the info_ptr members that +point to libpng-allocated storage with the following function: + + png_free_data(png_ptr, info_ptr, mask, seq) + mask - identifies data to be freed, a mask + containing the bitwise OR of one or + more of + PNG_FREE_PLTE, PNG_FREE_TRNS, + PNG_FREE_HIST, PNG_FREE_ICCP, + PNG_FREE_PCAL, PNG_FREE_ROWS, + PNG_FREE_SCAL, PNG_FREE_SPLT, + PNG_FREE_TEXT, PNG_FREE_UNKN, + or simply PNG_FREE_ALL + seq - sequence number of item to be freed + (-1 for all items) + +This function may be safely called when the relevant storage has +already been freed, or has not yet been allocated, or was allocated +by the user and not by libpng, and will in those cases do nothing. +The "seq" parameter is ignored if only one item of the selected data +type, such as PLTE, is allowed. If "seq" is not -1, and multiple items +are allowed for the data type identified in the mask, such as text or +sPLT, only the n'th item in the structure is freed, where n is "seq". + +The default behavior is only to free data that was allocated internally +by libpng. This can be changed, so that libpng will not free the data, +or so that it will free data that was allocated by the user with png_malloc() +or png_zalloc() and passed in via a png_set_*() function, with + + png_data_freer(png_ptr, info_ptr, freer, mask) + mask - which data elements are affected + same choices as in png_free_data() + freer - one of + PNG_DESTROY_WILL_FREE_DATA + PNG_SET_WILL_FREE_DATA + PNG_USER_WILL_FREE_DATA + +This function only affects data that has already been allocated. +You can call this function after reading the PNG data but before calling +any png_set_*() functions, to control whether the user or the png_set_*() +function is responsible for freeing any existing data that might be present, +and again after the png_set_*() functions to control whether the user +or png_destroy_*() is supposed to free the data. When the user assumes +responsibility for libpng-allocated data, the application must use +png_free() to free it, and when the user transfers responsibility to libpng +for data that the user has allocated, the user must have used png_malloc() +or png_zalloc() to allocate it. + +If you allocated your row_pointers in a single block, as suggested above in +the description of the high level read interface, you must not transfer +responsibility for freeing it to the png_set_rows or png_read_destroy function, +because they would also try to free the individual row_pointers[i]. + +If you allocated text_ptr.text, text_ptr.lang, and text_ptr.translated_keyword +separately, do not transfer responsibility for freeing text_ptr to libpng, +because when libpng fills a png_text structure it combines these members with +the key member, and png_free_data() will free only text_ptr.key. Similarly, +if you transfer responsibility for free'ing text_ptr from libpng to your +application, your application must not separately free those members. + +The png_free_data() function will turn off the "valid" flag for anything +it frees. If you need to turn the flag off for a chunk that was freed by +your application instead of by libpng, you can use + + png_set_invalid(png_ptr, info_ptr, mask); + mask - identifies the chunks to be made invalid, + containing the bitwise OR of one or + more of + PNG_INFO_gAMA, PNG_INFO_sBIT, + PNG_INFO_cHRM, PNG_INFO_PLTE, + PNG_INFO_tRNS, PNG_INFO_bKGD, + PNG_INFO_hIST, PNG_INFO_pHYs, + PNG_INFO_oFFs, PNG_INFO_tIME, + PNG_INFO_pCAL, PNG_INFO_sRGB, + PNG_INFO_iCCP, PNG_INFO_sPLT, + PNG_INFO_sCAL, PNG_INFO_IDAT + +For a more compact example of reading a PNG image, see the file example.c. + +Reading PNG files progressively + +The progressive reader is slightly different then the non-progressive +reader. Instead of calling png_read_info(), png_read_rows(), and +png_read_end(), you make one call to png_process_data(), which calls +callbacks when it has the info, a row, or the end of the image. You +set up these callbacks with png_set_progressive_read_fn(). You don't +have to worry about the input/output functions of libpng, as you are +giving the library the data directly in png_process_data(). I will +assume that you have read the section on reading PNG files above, +so I will only highlight the differences (although I will show +all of the code). + +png_structp png_ptr; +png_infop info_ptr; + + /* An example code fragment of how you would + initialize the progressive reader in your + application. */ + int + initialize_png_reader() + { + png_ptr = png_create_read_struct + (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr, + user_error_fn, user_warning_fn); + if (!png_ptr) + return (ERROR); + info_ptr = png_create_info_struct(png_ptr); + if (!info_ptr) + { + png_destroy_read_struct(&png_ptr, (png_infopp)NULL, + (png_infopp)NULL); + return (ERROR); + } + + if (setjmp(png_jmpbuf(png_ptr))) + { + png_destroy_read_struct(&png_ptr, &info_ptr, + (png_infopp)NULL); + return (ERROR); + } + + /* This one's new. You can provide functions + to be called when the header info is valid, + when each row is completed, and when the image + is finished. If you aren't using all functions, + you can specify NULL parameters. Even when all + three functions are NULL, you need to call + png_set_progressive_read_fn(). You can use + any struct as the user_ptr (cast to a void pointer + for the function call), and retrieve the pointer + from inside the callbacks using the function + + png_get_progressive_ptr(png_ptr); + + which will return a void pointer, which you have + to cast appropriately. + */ + png_set_progressive_read_fn(png_ptr, (void *)user_ptr, + info_callback, row_callback, end_callback); + + return 0; + } + + /* A code fragment that you call as you receive blocks + of data */ + int + process_data(png_bytep buffer, png_uint_32 length) + { + if (setjmp(png_jmpbuf(png_ptr))) + { + png_destroy_read_struct(&png_ptr, &info_ptr, + (png_infopp)NULL); + return (ERROR); + } + + /* This one's new also. Simply give it a chunk + of data from the file stream (in order, of + course). On machines with segmented memory + models machines, don't give it any more than + 64K. The library seems to run fine with sizes + of 4K. Although you can give it much less if + necessary (I assume you can give it chunks of + 1 byte, I haven't tried less then 256 bytes + yet). When this function returns, you may + want to display any rows that were generated + in the row callback if you don't already do + so there. + */ + png_process_data(png_ptr, info_ptr, buffer, length); + return 0; + } + + /* This function is called (as set by + png_set_progressive_read_fn() above) when enough data + has been supplied so all of the header has been + read. + */ + void + info_callback(png_structp png_ptr, png_infop info) + { + /* Do any setup here, including setting any of + the transformations mentioned in the Reading + PNG files section. For now, you _must_ call + either png_start_read_image() or + png_read_update_info() after all the + transformations are set (even if you don't set + any). You may start getting rows before + png_process_data() returns, so this is your + last chance to prepare for that. + */ + } + + /* This function is called when each row of image + data is complete */ + void + row_callback(png_structp png_ptr, png_bytep new_row, + png_uint_32 row_num, int pass) + { + /* If the image is interlaced, and you turned + on the interlace handler, this function will + be called for every row in every pass. Some + of these rows will not be changed from the + previous pass. When the row is not changed, + the new_row variable will be NULL. The rows + and passes are called in order, so you don't + really need the row_num and pass, but I'm + supplying them because it may make your life + easier. + + For the non-NULL rows of interlaced images, + you must call png_progressive_combine_row() + passing in the row and the old row. You can + call this function for NULL rows (it will just + return) and for non-interlaced images (it just + does the memcpy for you) if it will make the + code easier. Thus, you can just do this for + all cases: + */ + + png_progressive_combine_row(png_ptr, old_row, + new_row); + + /* where old_row is what was displayed for + previously for the row. Note that the first + pass (pass == 0, really) will completely cover + the old row, so the rows do not have to be + initialized. After the first pass (and only + for interlaced images), you will have to pass + the current row, and the function will combine + the old row and the new row. + */ + } + + void + end_callback(png_structp png_ptr, png_infop info) + { + /* This function is called after the whole image + has been read, including any chunks after the + image (up to and including the IEND). You + will usually have the same info chunk as you + had in the header, although some data may have + been added to the comments and time fields. + + Most people won't do much here, perhaps setting + a flag that marks the image as finished. + */ + } + + + +IV. Writing + +Much of this is very similar to reading. However, everything of +importance is repeated here, so you won't have to constantly look +back up in the reading section to understand writing. + +Setup + +You will want to do the I/O initialization before you get into libpng, +so if it doesn't work, you don't have anything to undo. If you are not +using the standard I/O functions, you will need to replace them with +custom writing functions. See the discussion under Customizing libpng. + + FILE *fp = fopen(file_name, "wb"); + if (!fp) + { + return (ERROR); + } + +Next, png_struct and png_info need to be allocated and initialized. +As these can be both relatively large, you may not want to store these +on the stack, unless you have stack space to spare. Of course, you +will want to check if they return NULL. If you are also reading, +you won't want to name your read structure and your write structure +both "png_ptr"; you can call them anything you like, such as +"read_ptr" and "write_ptr". Look at pngtest.c, for example. + + png_structp png_ptr = png_create_write_struct + (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr, + user_error_fn, user_warning_fn); + if (!png_ptr) + return (ERROR); + + png_infop info_ptr = png_create_info_struct(png_ptr); + if (!info_ptr) + { + png_destroy_write_struct(&png_ptr, + (png_infopp)NULL); + return (ERROR); + } + +If you want to use your own memory allocation routines, +define PNG_USER_MEM_SUPPORTED and use +png_create_write_struct_2() instead of png_create_write_struct(): + + png_structp png_ptr = png_create_write_struct_2 + (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr, + user_error_fn, user_warning_fn, (png_voidp) + user_mem_ptr, user_malloc_fn, user_free_fn); + +After you have these structures, you will need to set up the +error handling. When libpng encounters an error, it expects to +longjmp() back to your routine. Therefore, you will need to call +setjmp() and pass the png_jmpbuf(png_ptr). If you +write the file from different routines, you will need to update +the png_jmpbuf(png_ptr) every time you enter a new routine that will +call a png_*() function. See your documentation of setjmp/longjmp +for your compiler for more information on setjmp/longjmp. See +the discussion on libpng error handling in the Customizing Libpng +section below for more information on the libpng error handling. + + if (setjmp(png_jmpbuf(png_ptr))) + { + png_destroy_write_struct(&png_ptr, &info_ptr); + fclose(fp); + return (ERROR); + } + ... + return; + +If you would rather avoid the complexity of setjmp/longjmp issues, +you can compile libpng with PNG_SETJMP_NOT_SUPPORTED, in which case +errors will result in a call to PNG_ABORT() which defaults to abort(). + +Now you need to set up the output code. The default for libpng is to +use the C function fwrite(). If you use this, you will need to pass a +valid FILE * in the function png_init_io(). Be sure that the file is +opened in binary mode. Again, if you wish to handle writing data in +another way, see the discussion on libpng I/O handling in the Customizing +Libpng section below. + + png_init_io(png_ptr, fp); + +If you are embedding your PNG into a datastream such as MNG, and don't +want libpng to write the 8-byte signature, or if you have already +written the signature in your application, use + + png_set_sig_bytes(png_ptr, 8); + +to inform libpng that it should not write a signature. + +Write callbacks + +At this point, you can set up a callback function that will be +called after each row has been written, which you can use to control +a progress meter or the like. It's demonstrated in pngtest.c. +You must supply a function + + void write_row_callback(png_ptr, png_uint_32 row, + int pass); + { + /* put your code here */ + } + +(You can give it another name that you like instead of "write_row_callback") + +To inform libpng about your function, use + + png_set_write_status_fn(png_ptr, write_row_callback); + +You now have the option of modifying how the compression library will +run. The following functions are mainly for testing, but may be useful +in some cases, like if you need to write PNG files extremely fast and +are willing to give up some compression, or if you want to get the +maximum possible compression at the expense of slower writing. If you +have no special needs in this area, let the library do what it wants by +not calling this function at all, as it has been tuned to deliver a good +speed/compression ratio. The second parameter to png_set_filter() is +the filter method, for which the only valid values are 0 (as of the +July 1999 PNG specification, version 1.2) or 64 (if you are writing +a PNG datastream that is to be embedded in a MNG datastream). The third +parameter is a flag that indicates which filter type(s) are to be tested +for each scanline. See the PNG specification for details on the specific +filter types. + + + /* turn on or off filtering, and/or choose + specific filters. You can use either a single + PNG_FILTER_VALUE_NAME or the bitwise OR of one + or more PNG_FILTER_NAME masks. */ + png_set_filter(png_ptr, 0, + PNG_FILTER_NONE | PNG_FILTER_VALUE_NONE | + PNG_FILTER_SUB | PNG_FILTER_VALUE_SUB | + PNG_FILTER_UP | PNG_FILTER_VALUE_UP | + PNG_FILTER_AVG | PNG_FILTER_VALUE_AVG | + PNG_FILTER_PAETH | PNG_FILTER_VALUE_PAETH| + PNG_ALL_FILTERS); + +If an application +wants to start and stop using particular filters during compression, +it should start out with all of the filters (to ensure that the previous +row of pixels will be stored in case it's needed later), and then add +and remove them after the start of compression. + +If you are writing a PNG datastream that is to be embedded in a MNG +datastream, the second parameter can be either 0 or 64. + +The png_set_compression_*() functions interface to the zlib compression +library, and should mostly be ignored unless you really know what you are +doing. The only generally useful call is png_set_compression_level() +which changes how much time zlib spends on trying to compress the image +data. See the Compression Library (zlib.h and algorithm.txt, distributed +with zlib) for details on the compression levels. + + /* set the zlib compression level */ + png_set_compression_level(png_ptr, + Z_BEST_COMPRESSION); + + /* set other zlib parameters */ + png_set_compression_mem_level(png_ptr, 8); + png_set_compression_strategy(png_ptr, + Z_DEFAULT_STRATEGY); + png_set_compression_window_bits(png_ptr, 15); + png_set_compression_method(png_ptr, 8); + png_set_compression_buffer_size(png_ptr, 8192) + +extern PNG_EXPORT(void,png_set_zbuf_size) + +Setting the contents of info for output + +You now need to fill in the png_info structure with all the data you +wish to write before the actual image. Note that the only thing you +are allowed to write after the image is the text chunks and the time +chunk (as of PNG Specification 1.2, anyway). See png_write_end() and +the latest PNG specification for more information on that. If you +wish to write them before the image, fill them in now, and flag that +data as being valid. If you want to wait until after the data, don't +fill them until png_write_end(). For all the fields in png_info and +their data types, see png.h. For explanations of what the fields +contain, see the PNG specification. + +Some of the more important parts of the png_info are: + + png_set_IHDR(png_ptr, info_ptr, width, height, + bit_depth, color_type, interlace_type, + compression_type, filter_method) + width - holds the width of the image + in pixels (up to 2^31). + height - holds the height of the image + in pixels (up to 2^31). + bit_depth - holds the bit depth of one of the + image channels. + (valid values are 1, 2, 4, 8, 16 + and depend also on the + color_type. See also significant + bits (sBIT) below). + color_type - describes which color/alpha + channels are present. + PNG_COLOR_TYPE_GRAY + (bit depths 1, 2, 4, 8, 16) + PNG_COLOR_TYPE_GRAY_ALPHA + (bit depths 8, 16) + PNG_COLOR_TYPE_PALETTE + (bit depths 1, 2, 4, 8) + PNG_COLOR_TYPE_RGB + (bit_depths 8, 16) + PNG_COLOR_TYPE_RGB_ALPHA + (bit_depths 8, 16) + + PNG_COLOR_MASK_PALETTE + PNG_COLOR_MASK_COLOR + PNG_COLOR_MASK_ALPHA + + interlace_type - PNG_INTERLACE_NONE or + PNG_INTERLACE_ADAM7 + compression_type - (must be + PNG_COMPRESSION_TYPE_DEFAULT) + filter_method - (must be PNG_FILTER_TYPE_DEFAULT + or, if you are writing a PNG to + be embedded in a MNG datastream, + can also be + PNG_INTRAPIXEL_DIFFERENCING) + +If you call png_set_IHDR(), the call must appear before any of the +other png_set_*() functions, because they might require access to some of +the IHDR settings. The remaining png_set_*() functions can be called +in any order. + +If you wish, you can reset the compression_type, interlace_type, or +filter_method later by calling png_set_IHDR() again; if you do this, the +width, height, bit_depth, and color_type must be the same in each call. + + png_set_PLTE(png_ptr, info_ptr, palette, + num_palette); + palette - the palette for the file + (array of png_color) + num_palette - number of entries in the palette + + png_set_gAMA(png_ptr, info_ptr, gamma); + gamma - the gamma the image was created + at (PNG_INFO_gAMA) + + png_set_sRGB(png_ptr, info_ptr, srgb_intent); + srgb_intent - the rendering intent + (PNG_INFO_sRGB) The presence of + the sRGB chunk means that the pixel + data is in the sRGB color space. + This chunk also implies specific + values of gAMA and cHRM. Rendering + intent is the CSS-1 property that + has been defined by the International + Color Consortium + (http://www.color.org). + It can be one of + PNG_sRGB_INTENT_SATURATION, + PNG_sRGB_INTENT_PERCEPTUAL, + PNG_sRGB_INTENT_ABSOLUTE, or + PNG_sRGB_INTENT_RELATIVE. + + + png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr, + srgb_intent); + srgb_intent - the rendering intent + (PNG_INFO_sRGB) The presence of the + sRGB chunk means that the pixel + data is in the sRGB color space. + This function also causes gAMA and + cHRM chunks with the specific values + that are consistent with sRGB to be + written. + + png_set_iCCP(png_ptr, info_ptr, name, compression_type, + profile, proflen); + name - The profile name. + compression - The compression type; always + PNG_COMPRESSION_TYPE_BASE for PNG 1.0. + You may give NULL to this argument to + ignore it. + profile - International Color Consortium color + profile data. May contain NULs. + proflen - length of profile data in bytes. + + png_set_sBIT(png_ptr, info_ptr, sig_bit); + sig_bit - the number of significant bits for + (PNG_INFO_sBIT) each of the gray, red, + green, and blue channels, whichever are + appropriate for the given color type + (png_color_16) + + png_set_tRNS(png_ptr, info_ptr, trans, num_trans, + trans_values); + trans - array of transparent + entries for palette (PNG_INFO_tRNS) + trans_values - graylevel or color sample values + (in order red, green, blue) of the + single transparent color for + non-paletted images (PNG_INFO_tRNS) + num_trans - number of transparent entries + (PNG_INFO_tRNS) + + png_set_hIST(png_ptr, info_ptr, hist); + (PNG_INFO_hIST) + hist - histogram of palette (array of + png_uint_16) + + png_set_tIME(png_ptr, info_ptr, mod_time); + mod_time - time image was last modified + (PNG_VALID_tIME) + + png_set_bKGD(png_ptr, info_ptr, background); + background - background color (PNG_VALID_bKGD) + + png_set_text(png_ptr, info_ptr, text_ptr, num_text); + text_ptr - array of png_text holding image + comments + text_ptr[i].compression - type of compression used + on "text" PNG_TEXT_COMPRESSION_NONE + PNG_TEXT_COMPRESSION_zTXt + PNG_ITXT_COMPRESSION_NONE + PNG_ITXT_COMPRESSION_zTXt + text_ptr[i].key - keyword for comment. Must contain + 1-79 characters. + text_ptr[i].text - text comments for current + keyword. Can be NULL or empty. + text_ptr[i].text_length - length of text string, + after decompression, 0 for iTXt + text_ptr[i].itxt_length - length of itxt string, + after decompression, 0 for tEXt/zTXt + text_ptr[i].lang - language of comment (NULL or + empty for unknown). + text_ptr[i].translated_keyword - keyword in UTF-8 (NULL + or empty for unknown). + Note that the itxt_length, lang, and lang_key + members of the text_ptr structure only exist + when the library is built with iTXt chunk support. + + num_text - number of comments + + png_set_sPLT(png_ptr, info_ptr, &palette_ptr, + num_spalettes); + palette_ptr - array of png_sPLT_struct structures + to be added to the list of palettes + in the info structure. + num_spalettes - number of palette structures to be + added. + + png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y, + unit_type); + offset_x - positive offset from the left + edge of the screen + offset_y - positive offset from the top + edge of the screen + unit_type - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER + + png_set_pHYs(png_ptr, info_ptr, res_x, res_y, + unit_type); + res_x - pixels/unit physical resolution + in x direction + res_y - pixels/unit physical resolution + in y direction + unit_type - PNG_RESOLUTION_UNKNOWN, + PNG_RESOLUTION_METER + + png_set_sCAL(png_ptr, info_ptr, unit, width, height) + unit - physical scale units (an integer) + width - width of a pixel in physical scale units + height - height of a pixel in physical scale units + (width and height are doubles) + + png_set_sCAL_s(png_ptr, info_ptr, unit, width, height) + unit - physical scale units (an integer) + width - width of a pixel in physical scale units + height - height of a pixel in physical scale units + (width and height are strings like "2.54") + + png_set_unknown_chunks(png_ptr, info_ptr, &unknowns, + num_unknowns) + unknowns - array of png_unknown_chunk + structures holding unknown chunks + unknowns[i].name - name of unknown chunk + unknowns[i].data - data of unknown chunk + unknowns[i].size - size of unknown chunk's data + unknowns[i].location - position to write chunk in file + 0: do not write chunk + PNG_HAVE_IHDR: before PLTE + PNG_HAVE_PLTE: before IDAT + PNG_AFTER_IDAT: after IDAT + +The "location" member is set automatically according to +what part of the output file has already been written. +You can change its value after calling png_set_unknown_chunks() +as demonstrated in pngtest.c. Within each of the "locations", +the chunks are sequenced according to their position in the +structure (that is, the value of "i", which is the order in which +the chunk was either read from the input file or defined with +png_set_unknown_chunks). + +A quick word about text and num_text. text is an array of png_text +structures. num_text is the number of valid structures in the array. +Each png_text structure holds a language code, a keyword, a text value, +and a compression type. + +The compression types have the same valid numbers as the compression +types of the image data. Currently, the only valid number is zero. +However, you can store text either compressed or uncompressed, unlike +images, which always have to be compressed. So if you don't want the +text compressed, set the compression type to PNG_TEXT_COMPRESSION_NONE. +Because tEXt and zTXt chunks don't have a language field, if you +specify PNG_TEXT_COMPRESSION_NONE or PNG_TEXT_COMPRESSION_zTXt +any language code or translated keyword will not be written out. + +Until text gets around 1000 bytes, it is not worth compressing it. +After the text has been written out to the file, the compression type +is set to PNG_TEXT_COMPRESSION_NONE_WR or PNG_TEXT_COMPRESSION_zTXt_WR, +so that it isn't written out again at the end (in case you are calling +png_write_end() with the same struct. + +The keywords that are given in the PNG Specification are: + + Title Short (one line) title or + caption for image + Author Name of image's creator + Description Description of image (possibly long) + Copyright Copyright notice + Creation Time Time of original image creation + (usually RFC 1123 format, see below) + Software Software used to create the image + Disclaimer Legal disclaimer + Warning Warning of nature of content + Source Device used to create the image + Comment Miscellaneous comment; conversion + from other image format + +The keyword-text pairs work like this. Keywords should be short +simple descriptions of what the comment is about. Some typical +keywords are found in the PNG specification, as is some recommendations +on keywords. You can repeat keywords in a file. You can even write +some text before the image and some after. For example, you may want +to put a description of the image before the image, but leave the +disclaimer until after, so viewers working over modem connections +don't have to wait for the disclaimer to go over the modem before +they start seeing the image. Finally, keywords should be full +words, not abbreviations. Keywords and text are in the ISO 8859-1 +(Latin-1) character set (a superset of regular ASCII) and can not +contain NUL characters, and should not contain control or other +unprintable characters. To make the comments widely readable, stick +with basic ASCII, and avoid machine specific character set extensions +like the IBM-PC character set. The keyword must be present, but +you can leave off the text string on non-compressed pairs. +Compressed pairs must have a text string, as only the text string +is compressed anyway, so the compression would be meaningless. + +PNG supports modification time via the png_time structure. Two +conversion routines are provided, png_convert_from_time_t() for +time_t and png_convert_from_struct_tm() for struct tm. The +time_t routine uses gmtime(). You don't have to use either of +these, but if you wish to fill in the png_time structure directly, +you should provide the time in universal time (GMT) if possible +instead of your local time. Note that the year number is the full +year (e.g. 1998, rather than 98 - PNG is year 2000 compliant!), and +that months start with 1. + +If you want to store the time of the original image creation, you should +use a plain tEXt chunk with the "Creation Time" keyword. This is +necessary because the "creation time" of a PNG image is somewhat vague, +depending on whether you mean the PNG file, the time the image was +created in a non-PNG format, a still photo from which the image was +scanned, or possibly the subject matter itself. In order to facilitate +machine-readable dates, it is recommended that the "Creation Time" +tEXt chunk use RFC 1123 format dates (e.g. "22 May 1997 18:07:10 GMT"), +although this isn't a requirement. Unlike the tIME chunk, the +"Creation Time" tEXt chunk is not expected to be automatically changed +by the software. To facilitate the use of RFC 1123 dates, a function +png_convert_to_rfc1123(png_timep) is provided to convert from PNG +time to an RFC 1123 format string. + +Writing unknown chunks + +You can use the png_set_unknown_chunks function to queue up chunks +for writing. You give it a chunk name, raw data, and a size; that's +all there is to it. The chunks will be written by the next following +png_write_info_before_PLTE, png_write_info, or png_write_end function. +Any chunks previously read into the info structure's unknown-chunk +list will also be written out in a sequence that satisfies the PNG +specification's ordering rules. + +The high-level write interface + +At this point there are two ways to proceed; through the high-level +write interface, or through a sequence of low-level write operations. +You can use the high-level interface if your image data is present +in the info structure. All defined output +transformations are permitted, enabled by the following masks. + + PNG_TRANSFORM_IDENTITY No transformation + PNG_TRANSFORM_PACKING Pack 1, 2 and 4-bit samples + PNG_TRANSFORM_PACKSWAP Change order of packed + pixels to LSB first + PNG_TRANSFORM_INVERT_MONO Invert monochrome images + PNG_TRANSFORM_SHIFT Normalize pixels to the + sBIT depth + PNG_TRANSFORM_BGR Flip RGB to BGR, RGBA + to BGRA + PNG_TRANSFORM_SWAP_ALPHA Flip RGBA to ARGB or GA + to AG + PNG_TRANSFORM_INVERT_ALPHA Change alpha from opacity + to transparency + PNG_TRANSFORM_SWAP_ENDIAN Byte-swap 16-bit samples + PNG_TRANSFORM_STRIP_FILLER Strip out filler + bytes (deprecated). + PNG_TRANSFORM_STRIP_FILLER_BEFORE Strip out leading + filler bytes + PNG_TRANSFORM_STRIP_FILLER_AFTER Strip out trailing + filler bytes + +If you have valid image data in the info structure (you can use +png_set_rows() to put image data in the info structure), simply do this: + + png_write_png(png_ptr, info_ptr, png_transforms, NULL) + +where png_transforms is an integer containing the bitwise OR of some set of +transformation flags. This call is equivalent to png_write_info(), +followed the set of transformations indicated by the transform mask, +then png_write_image(), and finally png_write_end(). + +(The final parameter of this call is not yet used. Someday it might point +to transformation parameters required by some future output transform.) + +You must use png_transforms and not call any png_set_transform() functions +when you use png_write_png(). + +The low-level write interface + +If you are going the low-level route instead, you are now ready to +write all the file information up to the actual image data. You do +this with a call to png_write_info(). + + png_write_info(png_ptr, info_ptr); + +Note that there is one transformation you may need to do before +png_write_info(). In PNG files, the alpha channel in an image is the +level of opacity. If your data is supplied as a level of transparency, +you can invert the alpha channel before you write it, so that 0 is +fully transparent and 255 (in 8-bit or paletted images) or 65535 +(in 16-bit images) is fully opaque, with + + png_set_invert_alpha(png_ptr); + +This must appear before png_write_info() instead of later with the +other transformations because in the case of paletted images the tRNS +chunk data has to be inverted before the tRNS chunk is written. If +your image is not a paletted image, the tRNS data (which in such cases +represents a single color to be rendered as transparent) won't need to +be changed, and you can safely do this transformation after your +png_write_info() call. + +If you need to write a private chunk that you want to appear before +the PLTE chunk when PLTE is present, you can write the PNG info in +two steps, and insert code to write your own chunk between them: + + png_write_info_before_PLTE(png_ptr, info_ptr); + png_set_unknown_chunks(png_ptr, info_ptr, ...); + png_write_info(png_ptr, info_ptr); + +After you've written the file information, you can set up the library +to handle any special transformations of the image data. The various +ways to transform the data will be described in the order that they +should occur. This is important, as some of these change the color +type and/or bit depth of the data, and some others only work on +certain color types and bit depths. Even though each transformation +checks to see if it has data that it can do something with, you should +make sure to only enable a transformation if it will be valid for the +data. For example, don't swap red and blue on grayscale data. + +PNG files store RGB pixels packed into 3 or 6 bytes. This code tells +the library to strip input data that has 4 or 8 bytes per pixel down +to 3 or 6 bytes (or strip 2 or 4-byte grayscale+filler data to 1 or 2 +bytes per pixel). + + png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE); + +where the 0 is unused, and the location is either PNG_FILLER_BEFORE or +PNG_FILLER_AFTER, depending upon whether the filler byte in the pixel +is stored XRGB or RGBX. + +PNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as +they can, resulting in, for example, 8 pixels per byte for 1 bit files. +If the data is supplied at 1 pixel per byte, use this code, which will +correctly pack the pixels into a single byte: + + png_set_packing(png_ptr); + +PNG files reduce possible bit depths to 1, 2, 4, 8, and 16. If your +data is of another bit depth, you can write an sBIT chunk into the +file so that decoders can recover the original data if desired. + + /* Set the true bit depth of the image data */ + if (color_type & PNG_COLOR_MASK_COLOR) + { + sig_bit.red = true_bit_depth; + sig_bit.green = true_bit_depth; + sig_bit.blue = true_bit_depth; + } + else + { + sig_bit.gray = true_bit_depth; + } + if (color_type & PNG_COLOR_MASK_ALPHA) + { + sig_bit.alpha = true_bit_depth; + } + + png_set_sBIT(png_ptr, info_ptr, &sig_bit); + +If the data is stored in the row buffer in a bit depth other than +one supported by PNG (e.g. 3 bit data in the range 0-7 for a 4-bit PNG), +this will scale the values to appear to be the correct bit depth as +is required by PNG. + + png_set_shift(png_ptr, &sig_bit); + +PNG files store 16 bit pixels in network byte order (big-endian, +ie. most significant bits first). This code would be used if they are +supplied the other way (little-endian, i.e. least significant bits +first, the way PCs store them): + + if (bit_depth > 8) + png_set_swap(png_ptr); + +If you are using packed-pixel images (1, 2, or 4 bits/pixel), and you +need to change the order the pixels are packed into bytes, you can use: + + if (bit_depth < 8) + png_set_packswap(png_ptr); + +PNG files store 3 color pixels in red, green, blue order. This code +would be used if they are supplied as blue, green, red: + + png_set_bgr(png_ptr); + +PNG files describe monochrome as black being zero and white being +one. This code would be used if the pixels are supplied with this reversed +(black being one and white being zero): + + png_set_invert_mono(png_ptr); + +Finally, you can write your own transformation function if none of +the existing ones meets your needs. This is done by setting a callback +with + + png_set_write_user_transform_fn(png_ptr, + write_transform_fn); + +You must supply the function + + void write_transform_fn(png_ptr ptr, row_info_ptr + row_info, png_bytep data) + +See pngtest.c for a working example. Your function will be called +before any of the other transformations are processed. + +You can also set up a pointer to a user structure for use by your +callback function. + + png_set_user_transform_info(png_ptr, user_ptr, 0, 0); + +The user_channels and user_depth parameters of this function are ignored +when writing; you can set them to zero as shown. + +You can retrieve the pointer via the function png_get_user_transform_ptr(). +For example: + + voidp write_user_transform_ptr = + png_get_user_transform_ptr(png_ptr); + +It is possible to have libpng flush any pending output, either manually, +or automatically after a certain number of lines have been written. To +flush the output stream a single time call: + + png_write_flush(png_ptr); + +and to have libpng flush the output stream periodically after a certain +number of scanlines have been written, call: + + png_set_flush(png_ptr, nrows); + +Note that the distance between rows is from the last time png_write_flush() +was called, or the first row of the image if it has never been called. +So if you write 50 lines, and then png_set_flush 25, it will flush the +output on the next scanline, and every 25 lines thereafter, unless +png_write_flush() is called before 25 more lines have been written. +If nrows is too small (less than about 10 lines for a 640 pixel wide +RGB image) the image compression may decrease noticeably (although this +may be acceptable for real-time applications). Infrequent flushing will +only degrade the compression performance by a few percent over images +that do not use flushing. + +Writing the image data + +That's it for the transformations. Now you can write the image data. +The simplest way to do this is in one function call. If you have the +whole image in memory, you can just call png_write_image() and libpng +will write the image. You will need to pass in an array of pointers to +each row. This function automatically handles interlacing, so you don't +need to call png_set_interlace_handling() or call this function multiple +times, or any of that other stuff necessary with png_write_rows(). + + png_write_image(png_ptr, row_pointers); + +where row_pointers is: + + png_byte *row_pointers[height]; + +You can point to void or char or whatever you use for pixels. + +If you don't want to write the whole image at once, you can +use png_write_rows() instead. If the file is not interlaced, +this is simple: + + png_write_rows(png_ptr, row_pointers, + number_of_rows); + +row_pointers is the same as in the png_write_image() call. + +If you are just writing one row at a time, you can do this with +a single row_pointer instead of an array of row_pointers: + + png_bytep row_pointer = row; + + png_write_row(png_ptr, row_pointer); + +When the file is interlaced, things can get a good deal more complicated. +The only currently (as of the PNG Specification version 1.2, dated July +1999) defined interlacing scheme for PNG files is the "Adam7" interlace +scheme, that breaks down an image into seven smaller images of varying +size. libpng will build these images for you, or you can do them +yourself. If you want to build them yourself, see the PNG specification +for details of which pixels to write when. + +If you don't want libpng to handle the interlacing details, just +use png_set_interlace_handling() and call png_write_rows() the +correct number of times to write all seven sub-images. + +If you want libpng to build the sub-images, call this before you start +writing any rows: + + number_of_passes = + png_set_interlace_handling(png_ptr); + +This will return the number of passes needed. Currently, this is seven, +but may change if another interlace type is added. + +Then write the complete image number_of_passes times. + + png_write_rows(png_ptr, row_pointers, + number_of_rows); + +As some of these rows are not used, and thus return immediately, you may +want to read about interlacing in the PNG specification, and only update +the rows that are actually used. + +Finishing a sequential write + +After you are finished writing the image, you should finish writing +the file. If you are interested in writing comments or time, you should +pass an appropriately filled png_info pointer. If you are not interested, +you can pass NULL. + + png_write_end(png_ptr, info_ptr); + +When you are done, you can free all memory used by libpng like this: + + png_destroy_write_struct(&png_ptr, &info_ptr); + +It is also possible to individually free the info_ptr members that +point to libpng-allocated storage with the following function: + + png_free_data(png_ptr, info_ptr, mask, seq) + mask - identifies data to be freed, a mask + containing the bitwise OR of one or + more of + PNG_FREE_PLTE, PNG_FREE_TRNS, + PNG_FREE_HIST, PNG_FREE_ICCP, + PNG_FREE_PCAL, PNG_FREE_ROWS, + PNG_FREE_SCAL, PNG_FREE_SPLT, + PNG_FREE_TEXT, PNG_FREE_UNKN, + or simply PNG_FREE_ALL + seq - sequence number of item to be freed + (-1 for all items) + +This function may be safely called when the relevant storage has +already been freed, or has not yet been allocated, or was allocated +by the user and not by libpng, and will in those cases do nothing. +The "seq" parameter is ignored if only one item of the selected data +type, such as PLTE, is allowed. If "seq" is not -1, and multiple items +are allowed for the data type identified in the mask, such as text or +sPLT, only the n'th item in the structure is freed, where n is "seq". + +If you allocated data such as a palette that you passed in to libpng +with png_set_*, you must not free it until just before the call to +png_destroy_write_struct(). + +The default behavior is only to free data that was allocated internally +by libpng. This can be changed, so that libpng will not free the data, +or so that it will free data that was allocated by the user with png_malloc() +or png_zalloc() and passed in via a png_set_*() function, with + + png_data_freer(png_ptr, info_ptr, freer, mask) + mask - which data elements are affected + same choices as in png_free_data() + freer - one of + PNG_DESTROY_WILL_FREE_DATA + PNG_SET_WILL_FREE_DATA + PNG_USER_WILL_FREE_DATA + +For example, to transfer responsibility for some data from a read structure +to a write structure, you could use + + png_data_freer(read_ptr, read_info_ptr, + PNG_USER_WILL_FREE_DATA, + PNG_FREE_PLTE|PNG_FREE_tRNS|PNG_FREE_hIST) + png_data_freer(write_ptr, write_info_ptr, + PNG_DESTROY_WILL_FREE_DATA, + PNG_FREE_PLTE|PNG_FREE_tRNS|PNG_FREE_hIST) + +thereby briefly reassigning responsibility for freeing to the user but +immediately afterwards reassigning it once more to the write_destroy +function. Having done this, it would then be safe to destroy the read +structure and continue to use the PLTE, tRNS, and hIST data in the write +structure. + +This function only affects data that has already been allocated. +You can call this function before calling after the png_set_*() functions +to control whether the user or png_destroy_*() is supposed to free the data. +When the user assumes responsibility for libpng-allocated data, the +application must use +png_free() to free it, and when the user transfers responsibility to libpng +for data that the user has allocated, the user must have used png_malloc() +or png_zalloc() to allocate it. + +If you allocated text_ptr.text, text_ptr.lang, and text_ptr.translated_keyword +separately, do not transfer responsibility for freeing text_ptr to libpng, +because when libpng fills a png_text structure it combines these members with +the key member, and png_free_data() will free only text_ptr.key. Similarly, +if you transfer responsibility for free'ing text_ptr from libpng to your +application, your application must not separately free those members. +For a more compact example of writing a PNG image, see the file example.c. + +V. Modifying/Customizing libpng: + +There are two issues here. The first is changing how libpng does +standard things like memory allocation, input/output, and error handling. +The second deals with more complicated things like adding new chunks, +adding new transformations, and generally changing how libpng works. +Both of those are compile-time issues; that is, they are generally +determined at the time the code is written, and there is rarely a need +to provide the user with a means of changing them. + +Memory allocation, input/output, and error handling + +All of the memory allocation, input/output, and error handling in libpng +goes through callbacks that are user-settable. The default routines are +in pngmem.c, pngrio.c, pngwio.c, and pngerror.c, respectively. To change +these functions, call the appropriate png_set_*_fn() function. + +Memory allocation is done through the functions png_malloc(), png_calloc(), +and png_free(). These currently just call the standard C functions. +png_calloc() calls png_malloc() and then png_memset() to clear the newly +allocated memory to zero. If your pointers can't access more then 64K +at a time, you will want to set MAXSEG_64K in zlib.h. Since it is +unlikely that the method of handling memory allocation on a platform +will change between applications, these functions must be modified in +the library at compile time. If you prefer to use a different method +of allocating and freeing data, you can use png_create_read_struct_2() or +png_create_write_struct_2() to register your own functions as described +above. These functions also provide a void pointer that can be retrieved +via + + mem_ptr=png_get_mem_ptr(png_ptr); + +Your replacement memory functions must have prototypes as follows: + + png_voidp malloc_fn(png_structp png_ptr, + png_size_t size); + void free_fn(png_structp png_ptr, png_voidp ptr); + +Your malloc_fn() must return NULL in case of failure. The png_malloc() +function will normally call png_error() if it receives a NULL from the +system memory allocator or from your replacement malloc_fn(). + +Your free_fn() will never be called with a NULL ptr, since libpng's +png_free() checks for NULL before calling free_fn(). + +Input/Output in libpng is done through png_read() and png_write(), +which currently just call fread() and fwrite(). The FILE * is stored in +png_struct and is initialized via png_init_io(). If you wish to change +the method of I/O, the library supplies callbacks that you can set +through the function png_set_read_fn() and png_set_write_fn() at run +time, instead of calling the png_init_io() function. These functions +also provide a void pointer that can be retrieved via the function +png_get_io_ptr(). For example: + + png_set_read_fn(png_structp read_ptr, + voidp read_io_ptr, png_rw_ptr read_data_fn) + + png_set_write_fn(png_structp write_ptr, + voidp write_io_ptr, png_rw_ptr write_data_fn, + png_flush_ptr output_flush_fn); + + voidp read_io_ptr = png_get_io_ptr(read_ptr); + voidp write_io_ptr = png_get_io_ptr(write_ptr); + +The replacement I/O functions must have prototypes as follows: + + void user_read_data(png_structp png_ptr, + png_bytep data, png_size_t length); + void user_write_data(png_structp png_ptr, + png_bytep data, png_size_t length); + void user_flush_data(png_structp png_ptr); + +The user_read_data() function is responsible for detecting and +handling end-of-data errors. + +Supplying NULL for the read, write, or flush functions sets them back +to using the default C stream functions, which expect the io_ptr to +point to a standard *FILE structure. It is probably a mistake +to use NULL for one of write_data_fn and output_flush_fn but not both +of them, unless you have built libpng with PNG_NO_WRITE_FLUSH defined. +It is an error to read from a write stream, and vice versa. + +Error handling in libpng is done through png_error() and png_warning(). +Errors handled through png_error() are fatal, meaning that png_error() +should never return to its caller. Currently, this is handled via +setjmp() and longjmp() (unless you have compiled libpng with +PNG_SETJMP_NOT_SUPPORTED, in which case it is handled via PNG_ABORT()), +but you could change this to do things like exit() if you should wish. + +On non-fatal errors, png_warning() is called +to print a warning message, and then control returns to the calling code. +By default png_error() and png_warning() print a message on stderr via +fprintf() unless the library is compiled with PNG_NO_CONSOLE_IO defined +(because you don't want the messages) or PNG_NO_STDIO defined (because +fprintf() isn't available). If you wish to change the behavior of the error +functions, you will need to set up your own message callbacks. These +functions are normally supplied at the time that the png_struct is created. +It is also possible to redirect errors and warnings to your own replacement +functions after png_create_*_struct() has been called by calling: + + png_set_error_fn(png_structp png_ptr, + png_voidp error_ptr, png_error_ptr error_fn, + png_error_ptr warning_fn); + + png_voidp error_ptr = png_get_error_ptr(png_ptr); + +If NULL is supplied for either error_fn or warning_fn, then the libpng +default function will be used, calling fprintf() and/or longjmp() if a +problem is encountered. The replacement error functions should have +parameters as follows: + + void user_error_fn(png_structp png_ptr, + png_const_charp error_msg); + void user_warning_fn(png_structp png_ptr, + png_const_charp warning_msg); + +The motivation behind using setjmp() and longjmp() is the C++ throw and +catch exception handling methods. This makes the code much easier to write, +as there is no need to check every return code of every function call. +However, there are some uncertainties about the status of local variables +after a longjmp, so the user may want to be careful about doing anything +after setjmp returns non-zero besides returning itself. Consult your +compiler documentation for more details. For an alternative approach, you +may wish to use the "cexcept" facility (see http://cexcept.sourceforge.net). + +Custom chunks + +If you need to read or write custom chunks, you may need to get deeper +into the libpng code. The library now has mechanisms for storing +and writing chunks of unknown type; you can even declare callbacks +for custom chunks. However, this may not be good enough if the +library code itself needs to know about interactions between your +chunk and existing `intrinsic' chunks. + +If you need to write a new intrinsic chunk, first read the PNG +specification. Acquire a first level of understanding of how it works. +Pay particular attention to the sections that describe chunk names, +and look at how other chunks were designed, so you can do things +similarly. Second, check out the sections of libpng that read and +write chunks. Try to find a chunk that is similar to yours and use +it as a template. More details can be found in the comments inside +the code. It is best to handle unknown chunks in a generic method, +via callback functions, instead of by modifying libpng functions. + +If you wish to write your own transformation for the data, look through +the part of the code that does the transformations, and check out some of +the simpler ones to get an idea of how they work. Try to find a similar +transformation to the one you want to add and copy off of it. More details +can be found in the comments inside the code itself. + +Configuring for 16 bit platforms + +You will want to look into zconf.h to tell zlib (and thus libpng) that +it cannot allocate more then 64K at a time. Even if you can, the memory +won't be accessible. So limit zlib and libpng to 64K by defining MAXSEG_64K. + +Configuring for DOS + +For DOS users who only have access to the lower 640K, you will +have to limit zlib's memory usage via a png_set_compression_mem_level() +call. See zlib.h or zconf.h in the zlib library for more information. + +Configuring for Medium Model + +Libpng's support for medium model has been tested on most of the popular +compilers. Make sure MAXSEG_64K gets defined, USE_FAR_KEYWORD gets +defined, and FAR gets defined to far in pngconf.h, and you should be +all set. Everything in the library (except for zlib's structure) is +expecting far data. You must use the typedefs with the p or pp on +the end for pointers (or at least look at them and be careful). Make +note that the rows of data are defined as png_bytepp, which is an +unsigned char far * far *. + +Configuring for gui/windowing platforms: + +You will need to write new error and warning functions that use the GUI +interface, as described previously, and set them to be the error and +warning functions at the time that png_create_*_struct() is called, +in order to have them available during the structure initialization. +They can be changed later via png_set_error_fn(). On some compilers, +you may also have to change the memory allocators (png_malloc, etc.). + +Configuring for compiler xxx: + +All includes for libpng are in pngconf.h. If you need to add, change +or delete an include, this is the place to do it. +The includes that are not needed outside libpng are protected by the +PNG_INTERNAL definition, which is only defined for those routines inside +libpng itself. The files in libpng proper only include png.h, which +includes pngconf.h. + +Configuring zlib: + +There are special functions to configure the compression. Perhaps the +most useful one changes the compression level, which currently uses +input compression values in the range 0 - 9. The library normally +uses the default compression level (Z_DEFAULT_COMPRESSION = 6). Tests +have shown that for a large majority of images, compression values in +the range 3-6 compress nearly as well as higher levels, and do so much +faster. For online applications it may be desirable to have maximum speed +(Z_BEST_SPEED = 1). With versions of zlib after v0.99, you can also +specify no compression (Z_NO_COMPRESSION = 0), but this would create +files larger than just storing the raw bitmap. You can specify the +compression level by calling: + + png_set_compression_level(png_ptr, level); + +Another useful one is to reduce the memory level used by the library. +The memory level defaults to 8, but it can be lowered if you are +short on memory (running DOS, for example, where you only have 640K). +Note that the memory level does have an effect on compression; among +other things, lower levels will result in sections of incompressible +data being emitted in smaller stored blocks, with a correspondingly +larger relative overhead of up to 15% in the worst case. + + png_set_compression_mem_level(png_ptr, level); + +The other functions are for configuring zlib. They are not recommended +for normal use and may result in writing an invalid PNG file. See +zlib.h for more information on what these mean. + + png_set_compression_strategy(png_ptr, + strategy); + png_set_compression_window_bits(png_ptr, + window_bits); + png_set_compression_method(png_ptr, method); + png_set_compression_buffer_size(png_ptr, size); + +Controlling row filtering + +If you want to control whether libpng uses filtering or not, which +filters are used, and how it goes about picking row filters, you +can call one of these functions. The selection and configuration +of row filters can have a significant impact on the size and +encoding speed and a somewhat lesser impact on the decoding speed +of an image. Filtering is enabled by default for RGB and grayscale +images (with and without alpha), but not for paletted images nor +for any images with bit depths less than 8 bits/pixel. + +The 'method' parameter sets the main filtering method, which is +currently only '0' in the PNG 1.2 specification. The 'filters' +parameter sets which filter(s), if any, should be used for each +scanline. Possible values are PNG_ALL_FILTERS and PNG_NO_FILTERS +to turn filtering on and off, respectively. + +Individual filter types are PNG_FILTER_NONE, PNG_FILTER_SUB, +PNG_FILTER_UP, PNG_FILTER_AVG, PNG_FILTER_PAETH, which can be bitwise +ORed together with '|' to specify one or more filters to use. +These filters are described in more detail in the PNG specification. +If you intend to change the filter type during the course of writing +the image, you should start with flags set for all of the filters +you intend to use so that libpng can initialize its internal +structures appropriately for all of the filter types. (Note that this +means the first row must always be adaptively filtered, because libpng +currently does not allocate the filter buffers until png_write_row() +is called for the first time.) + + filters = PNG_FILTER_NONE | PNG_FILTER_SUB + PNG_FILTER_UP | PNG_FILTER_AVG | + PNG_FILTER_PAETH | PNG_ALL_FILTERS; + + png_set_filter(png_ptr, PNG_FILTER_TYPE_BASE, + filters); + The second parameter can also be + PNG_INTRAPIXEL_DIFFERENCING if you are + writing a PNG to be embedded in a MNG + datastream. This parameter must be the + same as the value of filter_method used + in png_set_IHDR(). + +It is also possible to influence how libpng chooses from among the +available filters. This is done in one or both of two ways - by +telling it how important it is to keep the same filter for successive +rows, and by telling it the relative computational costs of the filters. + + double weights[3] = {1.5, 1.3, 1.1}, + costs[PNG_FILTER_VALUE_LAST] = + {1.0, 1.3, 1.3, 1.5, 1.7}; + + png_set_filter_heuristics(png_ptr, + PNG_FILTER_HEURISTIC_WEIGHTED, 3, + weights, costs); + +The weights are multiplying factors that indicate to libpng that the +row filter should be the same for successive rows unless another row filter +is that many times better than the previous filter. In the above example, +if the previous 3 filters were SUB, SUB, NONE, the SUB filter could have a +"sum of absolute differences" 1.5 x 1.3 times higher than other filters +and still be chosen, while the NONE filter could have a sum 1.1 times +higher than other filters and still be chosen. Unspecified weights are +taken to be 1.0, and the specified weights should probably be declining +like those above in order to emphasize recent filters over older filters. + +The filter costs specify for each filter type a relative decoding cost +to be considered when selecting row filters. This means that filters +with higher costs are less likely to be chosen over filters with lower +costs, unless their "sum of absolute differences" is that much smaller. +The costs do not necessarily reflect the exact computational speeds of +the various filters, since this would unduly influence the final image +size. + +Note that the numbers above were invented purely for this example and +are given only to help explain the function usage. Little testing has +been done to find optimum values for either the costs or the weights. + +Removing unwanted object code + +There are a bunch of #define's in pngconf.h that control what parts of +libpng are compiled. All the defines end in _SUPPORTED. If you are +never going to use a capability, you can change the #define to #undef +before recompiling libpng and save yourself code and data space, or +you can turn off individual capabilities with defines that begin with +PNG_NO_. + +You can also turn all of the transforms and ancillary chunk capabilities +off en masse with compiler directives that define +PNG_NO_READ[or WRITE]_TRANSFORMS, or PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS, +or all four, +along with directives to turn on any of the capabilities that you do +want. The PNG_NO_READ[or WRITE]_TRANSFORMS directives disable the extra +transformations but still leave the library fully capable of reading +and writing PNG files with all known public chunks. Use of the +PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS directive produces a library +that is incapable of reading or writing ancillary chunks. If you are +not using the progressive reading capability, you can turn that off +with PNG_NO_PROGRESSIVE_READ (don't confuse this with the INTERLACING +capability, which you'll still have). + +All the reading and writing specific code are in separate files, so the +linker should only grab the files it needs. However, if you want to +make sure, or if you are building a stand alone library, all the +reading files start with pngr and all the writing files start with +pngw. The files that don't match either (like png.c, pngtrans.c, etc.) +are used for both reading and writing, and always need to be included. +The progressive reader is in pngpread.c + +If you are creating or distributing a dynamically linked library (a .so +or DLL file), you should not remove or disable any parts of the library, +as this will cause applications linked with different versions of the +library to fail if they call functions not available in your library. +The size of the library itself should not be an issue, because only +those sections that are actually used will be loaded into memory. + +Requesting debug printout + +The macro definition PNG_DEBUG can be used to request debugging +printout. Set it to an integer value in the range 0 to 3. Higher +numbers result in increasing amounts of debugging information. The +information is printed to the "stderr" file, unless another file +name is specified in the PNG_DEBUG_FILE macro definition. + +When PNG_DEBUG > 0, the following functions (macros) become available: + + png_debug(level, message) + png_debug1(level, message, p1) + png_debug2(level, message, p1, p2) + +in which "level" is compared to PNG_DEBUG to decide whether to print +the message, "message" is the formatted string to be printed, +and p1 and p2 are parameters that are to be embedded in the string +according to printf-style formatting directives. For example, + + png_debug1(2, "foo=%d\n", foo); + +is expanded to + + if(PNG_DEBUG > 2) + fprintf(PNG_DEBUG_FILE, "foo=%d\n", foo); + +When PNG_DEBUG is defined but is zero, the macros aren't defined, but you +can still use PNG_DEBUG to control your own debugging: + + #ifdef PNG_DEBUG + fprintf(stderr, ... + #endif + +When PNG_DEBUG = 1, the macros are defined, but only png_debug statements +having level = 0 will be printed. There aren't any such statements in +this version of libpng, but if you insert some they will be printed. + +VI. MNG support + +The MNG specification (available at http://www.libpng.org/pub/mng) allows +certain extensions to PNG for PNG images that are embedded in MNG datastreams. +Libpng can support some of these extensions. To enable them, use the +png_permit_mng_features() function: + + feature_set = png_permit_mng_features(png_ptr, mask) + mask is a png_uint_32 containing the bitwise OR of the + features you want to enable. These include + PNG_FLAG_MNG_EMPTY_PLTE + PNG_FLAG_MNG_FILTER_64 + PNG_ALL_MNG_FEATURES + feature_set is a png_uint_32 that is the bitwise AND of + your mask with the set of MNG features that is + supported by the version of libpng that you are using. + +It is an error to use this function when reading or writing a standalone +PNG file with the PNG 8-byte signature. The PNG datastream must be wrapped +in a MNG datastream. As a minimum, it must have the MNG 8-byte signature +and the MHDR and MEND chunks. Libpng does not provide support for these +or any other MNG chunks; your application must provide its own support for +them. You may wish to consider using libmng (available at +http://www.libmng.com) instead. + +VII. Changes to Libpng from version 0.88 + +It should be noted that versions of libpng later than 0.96 are not +distributed by the original libpng author, Guy Schalnat, nor by +Andreas Dilger, who had taken over from Guy during 1996 and 1997, and +distributed versions 0.89 through 0.96, but rather by another member +of the original PNG Group, Glenn Randers-Pehrson. Guy and Andreas are +still alive and well, but they have moved on to other things. + +The old libpng functions png_read_init(), png_write_init(), +png_info_init(), png_read_destroy(), and png_write_destroy() have been +moved to PNG_INTERNAL in version 0.95 to discourage their use. These +functions will be removed from libpng version 2.0.0. + +The preferred method of creating and initializing the libpng structures is +via the png_create_read_struct(), png_create_write_struct(), and +png_create_info_struct() because they isolate the size of the structures +from the application, allow version error checking, and also allow the +use of custom error handling routines during the initialization, which +the old functions do not. The functions png_read_destroy() and +png_write_destroy() do not actually free the memory that libpng +allocated for these structs, but just reset the data structures, so they +can be used instead of png_destroy_read_struct() and +png_destroy_write_struct() if you feel there is too much system overhead +allocating and freeing the png_struct for each image read. + +Setting the error callbacks via png_set_message_fn() before +png_read_init() as was suggested in libpng-0.88 is no longer supported +because this caused applications that do not use custom error functions +to fail if the png_ptr was not initialized to zero. It is still possible +to set the error callbacks AFTER png_read_init(), or to change them with +png_set_error_fn(), which is essentially the same function, but with a new +name to force compilation errors with applications that try to use the old +method. + +Starting with version 1.0.7, you can find out which version of the library +you are using at run-time: + + png_uint_32 libpng_vn = png_access_version_number(); + +The number libpng_vn is constructed from the major version, minor +version with leading zero, and release number with leading zero, +(e.g., libpng_vn for version 1.0.7 is 10007). + +You can also check which version of png.h you used when compiling your +application: + + png_uint_32 application_vn = PNG_LIBPNG_VER; + +VIII. Changes to Libpng from version 1.0.x to 1.2.x + +Support for user memory management was enabled by default. To +accomplish this, the functions png_create_read_struct_2(), +png_create_write_struct_2(), png_set_mem_fn(), png_get_mem_ptr(), +png_malloc_default(), and png_free_default() were added. + +Support for the iTXt chunk has been enabled by default as of +version 1.2.41. + +Support for certain MNG features was enabled. + +Support for numbered error messages was added. However, we never got +around to actually numbering the error messages. The function +png_set_strip_error_numbers() was added (Note: the prototype for this +function was inadvertently removed from png.h in PNG_NO_ASSEMBLER_CODE +builds of libpng-1.2.15. It was restored in libpng-1.2.36). + +The png_malloc_warn() function was added at libpng-1.2.3. This issues +a png_warning and returns NULL instead of aborting when it fails to +acquire the requested memory allocation. + +Support for setting user limits on image width and height was enabled +by default. The functions png_set_user_limits(), png_get_user_width_max(), +and png_get_user_height_max() were added at libpng-1.2.6. + +The png_set_add_alpha() function was added at libpng-1.2.7. + +The function png_set_expand_gray_1_2_4_to_8() was added at libpng-1.2.9. +Unlike png_set_gray_1_2_4_to_8(), the new function does not expand the +tRNS chunk to alpha. The png_set_gray_1_2_4_to_8() function is +deprecated. + +A number of macro definitions in support of runtime selection of +assembler code features (especially Intel MMX code support) were +added at libpng-1.2.0: + + PNG_ASM_FLAG_MMX_SUPPORT_COMPILED + PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU + PNG_ASM_FLAG_MMX_READ_COMBINE_ROW + PNG_ASM_FLAG_MMX_READ_INTERLACE + PNG_ASM_FLAG_MMX_READ_FILTER_SUB + PNG_ASM_FLAG_MMX_READ_FILTER_UP + PNG_ASM_FLAG_MMX_READ_FILTER_AVG + PNG_ASM_FLAG_MMX_READ_FILTER_PAETH + PNG_ASM_FLAGS_INITIALIZED + PNG_MMX_READ_FLAGS + PNG_MMX_FLAGS + PNG_MMX_WRITE_FLAGS + PNG_MMX_FLAGS + +We added the following functions in support of runtime +selection of assembler code features: + + png_get_mmx_flagmask() + png_set_mmx_thresholds() + png_get_asm_flags() + png_get_mmx_bitdepth_threshold() + png_get_mmx_rowbytes_threshold() + png_set_asm_flags() + +We replaced all of these functions with simple stubs in libpng-1.2.20, +when the Intel assembler code was removed due to a licensing issue. + +These macros are deprecated: + + PNG_READ_TRANSFORMS_NOT_SUPPORTED + PNG_PROGRESSIVE_READ_NOT_SUPPORTED + PNG_NO_SEQUENTIAL_READ_SUPPORTED + PNG_WRITE_TRANSFORMS_NOT_SUPPORTED + PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED + PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED + +They have been replaced, respectively, by: + + PNG_NO_READ_TRANSFORMS + PNG_NO_PROGRESSIVE_READ + PNG_NO_SEQUENTIAL_READ + PNG_NO_WRITE_TRANSFORMS + PNG_NO_READ_ANCILLARY_CHUNKS + PNG_NO_WRITE_ANCILLARY_CHUNKS + +PNG_MAX_UINT was replaced with PNG_UINT_31_MAX. It has been +deprecated since libpng-1.0.16 and libpng-1.2.6. + +The function + png_check_sig(sig, num) +was replaced with + !png_sig_cmp(sig, 0, num) +It has been deprecated since libpng-0.90. + +The function + png_set_gray_1_2_4_to_8() +which also expands tRNS to alpha was replaced with + png_set_expand_gray_1_2_4_to_8() +which does not. It has been deprecated since libpng-1.0.18 and 1.2.9. + +IX. (Omitted) + + +X. Detecting libpng + +The png_get_io_ptr() function has been present since libpng-0.88, has never +changed, and is unaffected by conditional compilation macros. It is the +best choice for use in configure scripts for detecting the presence of any +libpng version since 0.88. In an autoconf "configure.in" you could use + + AC_CHECK_LIB(png, png_get_io_ptr, ... + +XI. Source code repository + +Since about February 2009, version 1.2.34, libpng has been under "git" source +control. The git repository was built from old libpng-x.y.z.tar.gz files +going back to version 0.70. You can access the git repository (read only) +at + + git://libpng.git.sourceforge.net/gitroot/libpng + +or you can browse it via "gitweb" at + + http://libpng.git.sourceforge.net/git/gitweb.cgi?p=libpng + +Patches can be sent to glennrp at users.sourceforge.net or to +png-mng-implement at lists.sourceforge.net or you can upload them to +the libpng bug tracker at + + http://libpng.sourceforge.net + +XII. Coding style + +Our coding style is similar to the "Allman" style, with curly +braces on separate lines: + + if (condition) + { + action; + } + + else if (another condition) + { + another action; + } + +The braces can be omitted from simple one-line actions: + + if (condition) + return (0); + +We use 3-space indentation, except for continued statements which +are usually indented the same as the first line of the statement +plus four more spaces. + +For macro definitions we use 2-space indentation, always leaving the "#" +in the first column. + + #ifndef PNG_NO_FEATURE + # ifndef PNG_FEATURE_SUPPORTED + # define PNG_FEATURE_SUPPORTED + # endif + #endif + +Comments appear with the leading "/*" at the same indentation as +the statement that follows the comment: + + /* Single-line comment */ + statement; + + /* Multiple-line + * comment + */ + statement; + +Very short comments can be placed at the end of the statement +to which they pertain: + + statement; /* comment */ + +We don't use C++ style ("//") comments. We have, however, +used them in the past in some now-abandoned MMX assembler +code. + +Functions and their curly braces are not indented, and +exported functions are marked with PNGAPI: + + /* This is a public function that is visible to + * application programers. It does thus-and-so. + */ + void PNGAPI + png_exported_function(png_ptr, png_info, foo) + { + body; + } + +The prototypes for all exported functions appear in png.h, +above the comment that says + + /* Maintainer: Put new public prototypes here ... */ + +We mark all non-exported functions with "/* PRIVATE */"": + + void /* PRIVATE */ + png_non_exported_function(png_ptr, png_info, foo) + { + body; + } + +The prototypes for non-exported functions (except for those in +pngtest) appear in +the PNG_INTERNAL section of png.h +above the comment that says + + /* Maintainer: Put new private prototypes here ^ and in libpngpf.3 */ + +The names of all exported functions and variables begin +with "png_", and all publicly visible C preprocessor +macros begin with "PNG_". + +We put a space after each comma and after each semicolon +in "for" statments, and we put spaces before and after each +C binary operator and after "for" or "while". We don't +put a space between a typecast and the expression being +cast, nor do we put one between a function name and the +left parenthesis that follows it: + + for (i = 2; i > 0; --i) + y[i] = a(x) + (int)b; + +We prefer #ifdef and #ifndef to #if defined() and if !defined() +when there is only one macro being tested. + +We do not use the TAB character for indentation in the C sources. + +Lines do not exceed 80 characters. + +Other rules can be inferred by inspecting the libpng source. + +XIII. Y2K Compliance in libpng + +July 9, 2011 + +Since the PNG Development group is an ad-hoc body, we can't make +an official declaration. + +This is your unofficial assurance that libpng from version 0.71 and +upward through 1.2.46 are Y2K compliant. It is my belief that earlier +versions were also Y2K compliant. + +Libpng only has three year fields. One is a 2-byte unsigned integer that +will hold years up to 65535. The other two hold the date in text +format, and will hold years up to 9999. + +The integer is + "png_uint_16 year" in png_time_struct. + +The strings are + "png_charp time_buffer" in png_struct and + "near_time_buffer", which is a local character string in png.c. + +There are seven time-related functions: + + png_convert_to_rfc_1123() in png.c + (formerly png_convert_to_rfc_1152() in error) + png_convert_from_struct_tm() in pngwrite.c, called + in pngwrite.c + png_convert_from_time_t() in pngwrite.c + png_get_tIME() in pngget.c + png_handle_tIME() in pngrutil.c, called in pngread.c + png_set_tIME() in pngset.c + png_write_tIME() in pngwutil.c, called in pngwrite.c + +All appear to handle dates properly in a Y2K environment. The +png_convert_from_time_t() function calls gmtime() to convert from system +clock time, which returns (year - 1900), which we properly convert to +the full 4-digit year. There is a possibility that applications using +libpng are not passing 4-digit years into the png_convert_to_rfc_1123() +function, or that they are incorrectly passing only a 2-digit year +instead of "year - 1900" into the png_convert_from_struct_tm() function, +but this is not under our control. The libpng documentation has always +stated that it works with 4-digit years, and the APIs have been +documented as such. + +The tIME chunk itself is also Y2K compliant. It uses a 2-byte unsigned +integer to hold the year, and can hold years as large as 65535. + +zlib, upon which libpng depends, is also Y2K compliant. It contains +no date-related code. + + + Glenn Randers-Pehrson + libpng maintainer + PNG Development Group diff --git a/libs/libpng-src/libpng.3 b/libs/libpng-src/libpng.3 new file mode 100644 index 000000000..80c5d0b51 --- /dev/null +++ b/libs/libpng-src/libpng.3 @@ -0,0 +1,4498 @@ +.TH LIBPNG 3 "July 9, 2011" +.SH NAME +libpng \- Portable Network Graphics (PNG) Reference Library 1.2.46 +.SH SYNOPSIS +\fI\fB + +\fB#include \fP + +\fI\fB + +\fBpng_uint_32 png_access_version_number \fI(void\fP\fB);\fP + +\fI\fB + +\fBint png_check_sig (png_bytep \fP\fIsig\fP\fB, int \fInum\fP\fB);\fP + +\fI\fB + +\fBvoid png_chunk_error (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fIerror\fP\fB);\fP + +\fI\fB + +\fBvoid png_chunk_warning (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fImessage\fP\fB);\fP + +\fI\fB + +\fBvoid png_convert_from_struct_tm (png_timep \fP\fIptime\fP\fB, struct tm FAR * \fIttime\fP\fB);\fP + +\fI\fB + +\fBvoid png_convert_from_time_t (png_timep \fP\fIptime\fP\fB, time_t \fIttime\fP\fB);\fP + +\fI\fB + +\fBpng_charp png_convert_to_rfc1123 (png_structp \fP\fIpng_ptr\fP\fB, png_timep \fIptime\fP\fB);\fP + +\fI\fB + +\fBpng_infop png_create_info_struct (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_structp png_create_read_struct (png_const_charp \fP\fIuser_png_ver\fP\fB, png_voidp \fP\fIerror_ptr\fP\fB, png_error_ptr \fP\fIerror_fn\fP\fB, png_error_ptr \fIwarn_fn\fP\fB);\fP + +\fI\fB + +\fBpng_structp png_create_read_struct_2(png_const_charp \fP\fIuser_png_ver\fP\fB, png_voidp \fP\fIerror_ptr\fP\fB, png_error_ptr \fP\fIerror_fn\fP\fB, png_error_ptr \fP\fIwarn_fn\fP\fB, png_voidp \fP\fImem_ptr\fP\fB, png_malloc_ptr \fP\fImalloc_fn\fP\fB, png_free_ptr \fIfree_fn\fP\fB);\fP + +\fI\fB + +\fBpng_structp png_create_write_struct (png_const_charp \fP\fIuser_png_ver\fP\fB, png_voidp \fP\fIerror_ptr\fP\fB, png_error_ptr \fP\fIerror_fn\fP\fB, png_error_ptr \fIwarn_fn\fP\fB);\fP + +\fI\fB + +\fBpng_structp png_create_write_struct_2(png_const_charp \fP\fIuser_png_ver\fP\fB, png_voidp \fP\fIerror_ptr\fP\fB, png_error_ptr \fP\fIerror_fn\fP\fB, png_error_ptr \fP\fIwarn_fn\fP\fB, png_voidp \fP\fImem_ptr\fP\fB, png_malloc_ptr \fP\fImalloc_fn\fP\fB, png_free_ptr \fIfree_fn\fP\fB);\fP + +\fI\fB + +\fBint png_debug(int \fP\fIlevel\fP\fB, png_const_charp \fImessage\fP\fB);\fP + +\fI\fB + +\fBint png_debug1(int \fP\fIlevel\fP\fB, png_const_charp \fP\fImessage\fP\fB, \fIp1\fP\fB);\fP + +\fI\fB + +\fBint png_debug2(int \fP\fIlevel\fP\fB, png_const_charp \fP\fImessage\fP\fB, \fP\fIp1\fP\fB, \fIp2\fP\fB);\fP + +\fI\fB + +\fBvoid png_destroy_info_struct (png_structp \fP\fIpng_ptr\fP\fB, png_infopp \fIinfo_ptr_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_destroy_read_struct (png_structpp \fP\fIpng_ptr_ptr\fP\fB, png_infopp \fP\fIinfo_ptr_ptr\fP\fB, png_infopp \fIend_info_ptr_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_destroy_write_struct (png_structpp \fP\fIpng_ptr_ptr\fP\fB, png_infopp \fIinfo_ptr_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_error (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fIerror\fP\fB);\fP + +\fI\fB + +\fBvoid png_free (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fIptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_free_chunk_list (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_free_default(png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fIptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_free_data (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fInum\fP\fB);\fP + +\fI\fB + +\fBpng_byte png_get_bit_depth (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_bKGD (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_color_16p \fI*background\fP\fB);\fP + +\fI\fB + +\fBpng_byte png_get_channels (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_cHRM (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, double \fP\fI*white_x\fP\fB, double \fP\fI*white_y\fP\fB, double \fP\fI*red_x\fP\fB, double \fP\fI*red_y\fP\fB, double \fP\fI*green_x\fP\fB, double \fP\fI*green_y\fP\fB, double \fP\fI*blue_x\fP\fB, double \fI*blue_y\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_cHRM_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fI*white_x\fP\fB, png_uint_32 \fP\fI*white_y\fP\fB, png_uint_32 \fP\fI*red_x\fP\fB, png_uint_32 \fP\fI*red_y\fP\fB, png_uint_32 \fP\fI*green_x\fP\fB, png_uint_32 \fP\fI*green_y\fP\fB, png_uint_32 \fP\fI*blue_x\fP\fB, png_uint_32 \fI*blue_y\fP\fB);\fP + +\fI\fB + +\fBpng_byte png_get_color_type (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_byte png_get_compression_type (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_byte png_get_copyright (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_voidp png_get_error_ptr (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_byte png_get_filter_type (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_gAMA (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, double \fI*file_gamma\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_gAMA_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fI*int_file_gamma\fP\fB);\fP + +\fI\fB + +\fBpng_byte png_get_header_ver (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_byte png_get_header_version (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_hIST (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_16p \fI*hist\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_iCCP (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_charpp \fP\fIname\fP\fB, int \fP\fI*compression_type\fP\fB, png_charpp \fP\fIprofile\fP\fB, png_uint_32 \fI*proflen\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_IHDR (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fI*width\fP\fB, png_uint_32 \fP\fI*height\fP\fB, int \fP\fI*bit_depth\fP\fB, int \fP\fI*color_type\fP\fB, int \fP\fI*interlace_type\fP\fB, int \fP\fI*compression_type\fP\fB, int \fI*filter_type\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_image_height (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_image_width (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fB#if \fI!defined(PNG_1_0_X) + +\fBpng_int_32 png_get_int_32 (png_bytep \fIbuf\fP\fB);\fP + +\fI\fB#endif + +\fI\fB + +\fBpng_byte png_get_interlace_type (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_voidp png_get_io_ptr (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_byte png_get_libpng_ver (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_voidp png_get_mem_ptr(png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_oFFs (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fI*offset_x\fP\fB, png_uint_32 \fP\fI*offset_y\fP\fB, int \fI*unit_type\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_pCAL (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_charp \fP\fI*purpose\fP\fB, png_int_32 \fP\fI*X0\fP\fB, png_int_32 \fP\fI*X1\fP\fB, int \fP\fI*type\fP\fB, int \fP\fI*nparams\fP\fB, png_charp \fP\fI*units\fP\fB, png_charpp \fI*params\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_pHYs (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fI*res_x\fP\fB, png_uint_32 \fP\fI*res_y\fP\fB, int \fI*unit_type\fP\fB);\fP + +\fI\fB + +\fBfloat png_get_pixel_aspect_ratio (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_pixels_per_meter (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_voidp png_get_progressive_ptr (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_PLTE (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_colorp \fP\fI*palette\fP\fB, int \fI*num_palette\fP\fB);\fP + +\fI\fB + +\fBpng_byte png_get_rgb_to_gray_status (png_structp \fIpng_ptr) + +\fBpng_uint_32 png_get_rowbytes (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_bytepp png_get_rows (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_sBIT (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_color_8p \fI*sig_bit\fP\fB);\fP + +\fI\fB + +\fBpng_bytep png_get_signature (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_sPLT (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_spalette_p \fI*splt_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_sRGB (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fI*intent\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_text (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_textp \fP\fI*text_ptr\fP\fB, int \fI*num_text\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_tIME (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_timep \fI*mod_time\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_tRNS (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_bytep \fP\fI*trans\fP\fB, int \fP\fI*num_trans\fP\fB, png_color_16p \fI*trans_values\fP\fB);\fP + +\fI\fB + +\fB#if \fI!defined(PNG_1_0_X) + +\fBpng_uint_16 png_get_uint_16 (png_bytep \fIbuf\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_uint_31 (png_bytep \fIbuf\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_uint_32 (png_bytep \fIbuf\fP\fB);\fP + +\fI\fB#endif + +\fI\fB + +\fBpng_uint_32 png_get_unknown_chunks (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_unknown_chunkpp \fIunknowns\fP\fB);\fP + +\fI\fB + +\fBpng_voidp png_get_user_chunk_ptr (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_user_height_max( png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_voidp png_get_user_transform_ptr (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_user_width_max (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_valid (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIflag\fP\fB);\fP + +\fI\fB + +\fBpng_int_32 png_get_x_offset_microns (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_int_32 png_get_x_offset_pixels (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_x_pixels_per_meter (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_int_32 png_get_y_offset_microns (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_int_32 png_get_y_offset_pixels (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_y_pixels_per_meter (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_get_compression_buffer_size (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBint png_handle_as_unknown (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIchunk_name\fP\fB);\fP + +\fI\fB + +\fBvoid png_init_io (png_structp \fP\fIpng_ptr\fP\fB, FILE \fI*fp\fP\fB);\fP + +\fI\fB + +\fBDEPRECATED: void png_info_init (png_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBDEPRECATED: void png_info_init_2 (png_infopp \fP\fIptr_ptr\fP\fB, png_size_t \fIpng_info_struct_size\fP\fB);\fP + +\fI\fB + +\fBpng_voidp png_malloc (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIsize\fP\fB);\fP + +\fI\fB + +\fBpng_voidp png_malloc_default(png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIsize\fP\fB);\fP + +\fI\fB + +\fBvoidp png_memcpy (png_voidp \fP\fIs1\fP\fB, png_voidp \fP\fIs2\fP\fB, png_size_t \fIsize\fP\fB);\fP + +\fI\fB + +\fBpng_voidp png_memcpy_check (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIs1\fP\fB, png_voidp \fP\fIs2\fP\fB, png_uint_32 \fIsize\fP\fB);\fP + +\fI\fB + +\fBvoidp png_memset (png_voidp \fP\fIs1\fP\fB, int \fP\fIvalue\fP\fB, png_size_t \fIsize\fP\fB);\fP + +\fI\fB + +\fBpng_voidp png_memset_check (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIs1\fP\fB, int \fP\fIvalue\fP\fB, png_uint_32 \fIsize\fP\fB);\fP + +\fI\fB + +\fBDEPRECATED: void png_permit_empty_plte (png_structp \fP\fIpng_ptr\fP\fB, int \fIempty_plte_permitted\fP\fB);\fP + +\fI\fB + +\fBvoid png_process_data (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_bytep \fP\fIbuffer\fP\fB, png_size_t \fIbuffer_size\fP\fB);\fP + +\fI\fB + +\fBvoid png_progressive_combine_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIold_row\fP\fB, png_bytep \fInew_row\fP\fB);\fP + +\fI\fB + +\fBvoid png_read_destroy (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_infop \fIend_info_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_read_end (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_read_image (png_structp \fP\fIpng_ptr\fP\fB, png_bytepp \fIimage\fP\fB);\fP + +\fI\fB + +\fBDEPRECATED: void png_read_init (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBDEPRECATED: void png_read_init_2 (png_structpp \fP\fIptr_ptr\fP\fB, png_const_charp \fP\fIuser_png_ver\fP\fB, png_size_t \fP\fIpng_struct_size\fP\fB, png_size_t \fIpng_info_size\fP\fB);\fP + +\fI\fB + +\fBvoid png_read_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_read_png (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fP\fItransforms\fP\fB, png_voidp \fIparams\fP\fB);\fP + +\fI\fB + +\fBvoid png_read_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIrow\fP\fB, png_bytep \fIdisplay_row\fP\fB);\fP + +\fI\fB + +\fBvoid png_read_rows (png_structp \fP\fIpng_ptr\fP\fB, png_bytepp \fP\fIrow\fP\fB, png_bytepp \fP\fIdisplay_row\fP\fB, png_uint_32 \fInum_rows\fP\fB);\fP + +\fI\fB + +\fBvoid png_read_update_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fB#if \fI!defined(PNG_1_0_X) + +\fBpng_save_int_32 (png_bytep \fP\fIbuf\fP\fB, png_int_32 \fIi\fP\fB);\fP + +\fI\fB + +\fBvoid png_save_uint_16 (png_bytep \fP\fIbuf\fP\fB, unsigned int \fIi\fP\fB);\fP + +\fI\fB + +\fBvoid png_save_uint_32 (png_bytep \fP\fIbuf\fP\fB, png_uint_32 \fIi\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_add_alpha (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIfiller\fP\fB, int \fIflags\fP\fB);\fP + +\fI\fB#endif + +\fI\fB + +\fBvoid png_set_background (png_structp \fP\fIpng_ptr\fP\fB, png_color_16p \fP\fIbackground_color\fP\fB, int \fP\fIbackground_gamma_code\fP\fB, int \fP\fIneed_expand\fP\fB, double \fIbackground_gamma\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_bgr (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_bKGD (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_color_16p \fIbackground\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_cHRM (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, double \fP\fIwhite_x\fP\fB, double \fP\fIwhite_y\fP\fB, double \fP\fIred_x\fP\fB, double \fP\fIred_y\fP\fB, double \fP\fIgreen_x\fP\fB, double \fP\fIgreen_y\fP\fB, double \fP\fIblue_x\fP\fB, double \fIblue_y\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_cHRM_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fIwhite_x\fP\fB, png_uint_32 \fP\fIwhite_y\fP\fB, png_uint_32 \fP\fIred_x\fP\fB, png_uint_32 \fP\fIred_y\fP\fB, png_uint_32 \fP\fIgreen_x\fP\fB, png_uint_32 \fP\fIgreen_y\fP\fB, png_uint_32 \fP\fIblue_x\fP\fB, png_uint_32 \fIblue_y\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_compression_level (png_structp \fP\fIpng_ptr\fP\fB, int \fIlevel\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_compression_mem_level (png_structp \fP\fIpng_ptr\fP\fB, int \fImem_level\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_compression_method (png_structp \fP\fIpng_ptr\fP\fB, int \fImethod\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_compression_strategy (png_structp \fP\fIpng_ptr\fP\fB, int \fIstrategy\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_compression_window_bits (png_structp \fP\fIpng_ptr\fP\fB, int \fIwindow_bits\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_crc_action (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fIcrit_action\fP\fB, int \fIancil_action\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_dither (png_structp \fP\fIpng_ptr\fP\fB, png_colorp \fP\fIpalette\fP\fB, int \fP\fInum_palette\fP\fB, int \fP\fImaximum_colors\fP\fB, png_uint_16p \fP\fIhistogram\fP\fB, int \fIfull_dither\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_error_fn (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIerror_ptr\fP\fB, png_error_ptr \fP\fIerror_fn\fP\fB, png_error_ptr \fIwarning_fn\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_expand (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_expand_gray_1_2_4_to_8(png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_filler (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIfiller\fP\fB, int \fIflags\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_filter (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fImethod\fP\fB, int \fIfilters\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_filter_heuristics (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fIheuristic_method\fP\fB, int \fP\fInum_weights\fP\fB, png_doublep \fP\fIfilter_weights\fP\fB, png_doublep \fIfilter_costs\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_flush (png_structp \fP\fIpng_ptr\fP\fB, int \fInrows\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_gamma (png_structp \fP\fIpng_ptr\fP\fB, double \fP\fIscreen_gamma\fP\fB, double \fIdefault_file_gamma\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_gAMA (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, double \fIfile_gamma\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_gAMA_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIfile_gamma\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_gray_1_2_4_to_8(png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_gray_to_rgb (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_hIST (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_16p \fIhist\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_iCCP (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_charp \fP\fIname\fP\fB, int \fP\fIcompression_type\fP\fB, png_charp \fP\fIprofile\fP\fB, png_uint_32 \fIproflen\fP\fB);\fP + +\fI\fB + +\fBint png_set_interlace_handling (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_invalid (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fImask\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_invert_alpha (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_invert_mono (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_IHDR (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fIwidth\fP\fB, png_uint_32 \fP\fIheight\fP\fB, int \fP\fIbit_depth\fP\fB, int \fP\fIcolor_type\fP\fB, int \fP\fIinterlace_type\fP\fB, int \fP\fIcompression_type\fP\fB, int \fIfilter_type\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_keep_unknown_chunks (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fIkeep\fP\fB, png_bytep \fP\fIchunk_list\fP\fB, int \fInum_chunks\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_mem_fn(png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fImem_ptr\fP\fB, png_malloc_ptr \fP\fImalloc_fn\fP\fB, png_free_ptr \fIfree_fn\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_oFFs (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fIoffset_x\fP\fB, png_uint_32 \fP\fIoffset_y\fP\fB, int \fIunit_type\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_packing (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_packswap (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_palette_to_rgb(png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_pCAL (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_charp \fP\fIpurpose\fP\fB, png_int_32 \fP\fIX0\fP\fB, png_int_32 \fP\fIX1\fP\fB, int \fP\fItype\fP\fB, int \fP\fInparams\fP\fB, png_charp \fP\fIunits\fP\fB, png_charpp \fIparams\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_pHYs (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fIres_x\fP\fB, png_uint_32 \fP\fIres_y\fP\fB, int \fIunit_type\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_progressive_read_fn (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIprogressive_ptr\fP\fB, png_progressive_info_ptr \fP\fIinfo_fn\fP\fB, png_progressive_row_ptr \fP\fIrow_fn\fP\fB, png_progressive_end_ptr \fIend_fn\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_PLTE (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_colorp \fP\fIpalette\fP\fB, int \fInum_palette\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_read_fn (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIio_ptr\fP\fB, png_rw_ptr \fIread_data_fn\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_read_status_fn (png_structp \fP\fIpng_ptr\fP\fB, png_read_status_ptr \fIread_row_fn\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_read_user_transform_fn (png_structp \fP\fIpng_ptr\fP\fB, png_user_transform_ptr \fIread_user_transform_fn\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_rgb_to_gray (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fIerror_action\fP\fB, double \fP\fIred\fP\fB, double \fIgreen\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_rgb_to_gray_fixed (png_structp \fP\fIpng_ptr\fP\fB, int error_action png_fixed_point \fP\fIred\fP\fB, png_fixed_point \fIgreen\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_rows (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_bytepp \fIrow_pointers\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_sBIT (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_color_8p \fIsig_bit\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_sCAL (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_charp \fP\fIunit\fP\fB, double \fP\fIwidth\fP\fB, double \fIheight\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_shift (png_structp \fP\fIpng_ptr\fP\fB, png_color_8p \fItrue_bits\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_sig_bytes (png_structp \fP\fIpng_ptr\fP\fB, int \fInum_bytes\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_sPLT (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_spalette_p \fP\fIsplt_ptr\fP\fB, int \fInum_spalettes\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_sRGB (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fIintent\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_sRGB_gAMA_and_cHRM (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fIintent\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_strip_16 (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_strip_alpha (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_swap (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_swap_alpha (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_text (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_textp \fP\fItext_ptr\fP\fB, int \fInum_text\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_tIME (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_timep \fImod_time\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_tRNS (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_bytep \fP\fItrans\fP\fB, int \fP\fInum_trans\fP\fB, png_color_16p \fItrans_values\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_tRNS_to_alpha(png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBpng_uint_32 png_set_unknown_chunks (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_unknown_chunkp \fP\fIunknowns\fP\fB, int \fP\fInum\fP\fB, int \fIlocation\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_unknown_chunk_location(png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fP\fIchunk\fP\fB, int \fIlocation\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_read_user_chunk_fn (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIuser_chunk_ptr\fP\fB, png_user_chunk_ptr \fIread_user_chunk_fn\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_user_limits (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIuser_width_max\fP\fB, png_uint_32 \fIuser_height_max\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_user_transform_info (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIuser_transform_ptr\fP\fB, int \fP\fIuser_transform_depth\fP\fB, int \fIuser_transform_channels\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_write_fn (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIio_ptr\fP\fB, png_rw_ptr \fP\fIwrite_data_fn\fP\fB, png_flush_ptr \fIoutput_flush_fn\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_write_status_fn (png_structp \fP\fIpng_ptr\fP\fB, png_write_status_ptr \fIwrite_row_fn\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_write_user_transform_fn (png_structp \fP\fIpng_ptr\fP\fB, png_user_transform_ptr \fIwrite_user_transform_fn\fP\fB);\fP + +\fI\fB + +\fBvoid png_set_compression_buffer_size(png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIsize\fP\fB);\fP + +\fI\fB + +\fBint png_sig_cmp (png_bytep \fP\fIsig\fP\fB, png_size_t \fP\fIstart\fP\fB, png_size_t \fInum_to_check\fP\fB);\fP + +\fI\fB + +\fBvoid png_start_read_image (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_warning (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fImessage\fP\fB);\fP + +\fI\fB + +\fBvoid png_write_chunk (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIchunk_name\fP\fB, png_bytep \fP\fIdata\fP\fB, png_size_t \fIlength\fP\fB);\fP + +\fI\fB + +\fBvoid png_write_chunk_data (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIdata\fP\fB, png_size_t \fIlength\fP\fB);\fP + +\fI\fB + +\fBvoid png_write_chunk_end (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_write_chunk_start (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIchunk_name\fP\fB, png_uint_32 \fIlength\fP\fB);\fP + +\fI\fB + +\fBvoid png_write_destroy (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_write_end (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_write_flush (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_write_image (png_structp \fP\fIpng_ptr\fP\fB, png_bytepp \fIimage\fP\fB);\fP + +\fI\fB + +\fBDEPRECATED: void png_write_init (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fBDEPRECATED: void png_write_init_2 (png_structpp \fP\fIptr_ptr\fP\fB, png_const_charp \fP\fIuser_png_ver\fP\fB, png_size_t \fP\fIpng_struct_size\fP\fB, png_size_t \fIpng_info_size\fP\fB);\fP + +\fI\fB + +\fBvoid png_write_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_write_info_before_PLTE (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fBvoid png_write_png (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fP\fItransforms\fP\fB, png_voidp \fIparams\fP\fB);\fP + +\fI\fB + +\fBvoid png_write_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIrow\fP\fB);\fP + +\fI\fB + +\fBvoid png_write_rows (png_structp \fP\fIpng_ptr\fP\fB, png_bytepp \fP\fIrow\fP\fB, png_uint_32 \fInum_rows\fP\fB);\fP + +\fI\fB + +\fBvoidpf png_zalloc (voidpf \fP\fIpng_ptr\fP\fB, uInt \fP\fIitems\fP\fB, uInt \fIsize\fP\fB);\fP + +\fI\fB + +\fBvoid png_zfree (voidpf \fP\fIpng_ptr\fP\fB, voidpf \fIptr\fP\fB);\fP + +\fI\fB + +.SH DESCRIPTION +The +.I libpng +library supports encoding, decoding, and various manipulations of +the Portable Network Graphics (PNG) format image files. It uses the +.IR zlib(3) +compression library. +Following is a copy of the libpng.txt file that accompanies libpng. +.SH LIBPNG.TXT +libpng.txt - A description on how to use and modify libpng + + libpng version 1.2.46 - July 9, 2011 + Updated and distributed by Glenn Randers-Pehrson + + Copyright (c) 1998-2009 Glenn Randers-Pehrson + + This document is released under the libpng license. + For conditions of distribution and use, see the disclaimer + and license in png.h + + Based on: + + libpng versions 0.97, January 1998, through 1.2.46 - July 9, 2011 + Updated and distributed by Glenn Randers-Pehrson + Copyright (c) 1998-2009 Glenn Randers-Pehrson + + libpng 1.0 beta 6 version 0.96 May 28, 1997 + Updated and distributed by Andreas Dilger + Copyright (c) 1996, 1997 Andreas Dilger + + libpng 1.0 beta 2 - version 0.88 January 26, 1996 + For conditions of distribution and use, see copyright + notice in png.h. Copyright (c) 1995, 1996 Guy Eric + Schalnat, Group 42, Inc. + + Updated/rewritten per request in the libpng FAQ + Copyright (c) 1995, 1996 Frank J. T. Wojcik + December 18, 1995 & January 20, 1996 + +.SH I. Introduction + +This file describes how to use and modify the PNG reference library +(known as libpng) for your own use. There are five sections to this +file: introduction, structures, reading, writing, and modification and +configuration notes for various special platforms. In addition to this +file, example.c is a good starting point for using the library, as +it is heavily commented and should include everything most people +will need. We assume that libpng is already installed; see the +INSTALL file for instructions on how to install libpng. + +For examples of libpng usage, see the files "example.c", "pngtest.c", +and the files in the "contrib" directory, all of which are included in +the libpng distribution. + +Libpng was written as a companion to the PNG specification, as a way +of reducing the amount of time and effort it takes to support the PNG +file format in application programs. + +The PNG specification (second edition), November 2003, is available as +a W3C Recommendation and as an ISO Standard (ISO/IEC 15948:2003 (E)) at +. It is technically equivalent +to the PNG specification (second edition) but has some additional material. + +The PNG-1.0 specification is available +as RFC 2083 and as a +W3C Recommendation . + +Some additional chunks are described in the special-purpose public chunks +documents at . + +Other information +about PNG, and the latest version of libpng, can be found at the PNG home +page, . + +Most users will not have to modify the library significantly; advanced +users may want to modify it more. All attempts were made to make it as +complete as possible, while keeping the code easy to understand. +Currently, this library only supports C. Support for other languages +is being considered. + +Libpng has been designed to handle multiple sessions at one time, +to be easily modifiable, to be portable to the vast majority of +machines (ANSI, K&R, 16-, 32-, and 64-bit) available, and to be easy +to use. The ultimate goal of libpng is to promote the acceptance of +the PNG file format in whatever way possible. While there is still +work to be done (see the TODO file), libpng should cover the +majority of the needs of its users. + +Libpng uses zlib for its compression and decompression of PNG files. +Further information about zlib, and the latest version of zlib, can +be found at the zlib home page, . +The zlib compression utility is a general purpose utility that is +useful for more than PNG files, and can be used without libpng. +See the documentation delivered with zlib for more details. +You can usually find the source files for the zlib utility wherever you +find the libpng source files. + +Libpng is thread safe, provided the threads are using different +instances of the structures. Each thread should have its own +png_struct and png_info instances, and thus its own image. +Libpng does not protect itself against two threads using the +same instance of a structure. + +.SH II. Structures + +There are two main structures that are important to libpng, png_struct +and png_info. The first, png_struct, is an internal structure that +will not, for the most part, be used by a user except as the first +variable passed to every libpng function call. + +The png_info structure is designed to provide information about the +PNG file. At one time, the fields of png_info were intended to be +directly accessible to the user. However, this tended to cause problems +with applications using dynamically loaded libraries, and as a result +a set of interface functions for png_info (the png_get_*() and png_set_*() +functions) was developed. The fields of png_info are still available for +older applications, but it is suggested that applications use the new +interfaces if at all possible. + +Applications that do make direct access to the members of png_struct (except +for png_ptr->jmpbuf) must be recompiled whenever the library is updated, +and applications that make direct access to the members of png_info must +be recompiled if they were compiled or loaded with libpng version 1.0.6, +in which the members were in a different order. In version 1.0.7, the +members of the png_info structure reverted to the old order, as they were +in versions 0.97c through 1.0.5. Starting with version 2.0.0, both +structures are going to be hidden, and the contents of the structures will +only be accessible through the png_get/png_set functions. + +The png.h header file is an invaluable reference for programming with libpng. +And while I'm on the topic, make sure you include the libpng header file: + +#include + +.SH III. Reading + +We'll now walk you through the possible functions to call when reading +in a PNG file sequentially, briefly explaining the syntax and purpose +of each one. See example.c and png.h for more detail. While +progressive reading is covered in the next section, you will still +need some of the functions discussed in this section to read a PNG +file. + +.SS Setup + +You will want to do the I/O initialization(*) before you get into libpng, +so if it doesn't work, you don't have much to undo. Of course, you +will also want to insure that you are, in fact, dealing with a PNG +file. Libpng provides a simple check to see if a file is a PNG file. +To use it, pass in the first 1 to 8 bytes of the file to the function +png_sig_cmp(), and it will return 0 (false) if the bytes match the +corresponding bytes of the PNG signature, or nonzero (true) otherwise. +Of course, the more bytes you pass in, the greater the accuracy of the +prediction. + +If you are intending to keep the file pointer open for use in libpng, +you must ensure you don't read more than 8 bytes from the beginning +of the file, and you also have to make a call to png_set_sig_bytes_read() +with the number of bytes you read from the beginning. Libpng will +then only check the bytes (if any) that your program didn't read. + +(*): If you are not using the standard I/O functions, you will need +to replace them with custom functions. See the discussion under +Customizing libpng. + + + FILE *fp = fopen(file_name, "rb"); + if (!fp) + { + return (ERROR); + } + fread(header, 1, number, fp); + is_png = !png_sig_cmp(header, 0, number); + if (!is_png) + { + return (NOT_PNG); + } + + +Next, png_struct and png_info need to be allocated and initialized. In +order to ensure that the size of these structures is correct even with a +dynamically linked libpng, there are functions to initialize and +allocate the structures. We also pass the library version, optional +pointers to error handling functions, and a pointer to a data struct for +use by the error functions, if necessary (the pointer and functions can +be NULL if the default error handlers are to be used). See the section +on Changes to Libpng below regarding the old initialization functions. +The structure allocation functions quietly return NULL if they fail to +create the structure, so your application should check for that. + + png_structp png_ptr = png_create_read_struct + (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr, + user_error_fn, user_warning_fn); + if (!png_ptr) + return (ERROR); + + png_infop info_ptr = png_create_info_struct(png_ptr); + if (!info_ptr) + { + png_destroy_read_struct(&png_ptr, + (png_infopp)NULL, (png_infopp)NULL); + return (ERROR); + } + + png_infop end_info = png_create_info_struct(png_ptr); + if (!end_info) + { + png_destroy_read_struct(&png_ptr, &info_ptr, + (png_infopp)NULL); + return (ERROR); + } + +If you want to use your own memory allocation routines, +define PNG_USER_MEM_SUPPORTED and use +png_create_read_struct_2() instead of png_create_read_struct(): + + png_structp png_ptr = png_create_read_struct_2 + (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr, + user_error_fn, user_warning_fn, (png_voidp) + user_mem_ptr, user_malloc_fn, user_free_fn); + +The error handling routines passed to png_create_read_struct() +and the memory alloc/free routines passed to png_create_struct_2() +are only necessary if you are not using the libpng supplied error +handling and memory alloc/free functions. + +When libpng encounters an error, it expects to longjmp back +to your routine. Therefore, you will need to call setjmp and pass +your png_jmpbuf(png_ptr). If you read the file from different +routines, you will need to update the jmpbuf field every time you enter +a new routine that will call a png_*() function. + +See your documentation of setjmp/longjmp for your compiler for more +information on setjmp/longjmp. See the discussion on libpng error +handling in the Customizing Libpng section below for more information +on the libpng error handling. If an error occurs, and libpng longjmp's +back to your setjmp, you will want to call png_destroy_read_struct() to +free any memory. + + if (setjmp(png_jmpbuf(png_ptr))) + { + png_destroy_read_struct(&png_ptr, &info_ptr, + &end_info); + fclose(fp); + return (ERROR); + } + +If you would rather avoid the complexity of setjmp/longjmp issues, +you can compile libpng with PNG_SETJMP_NOT_SUPPORTED, in which case +errors will result in a call to PNG_ABORT() which defaults to abort(). + +Now you need to set up the input code. The default for libpng is to +use the C function fread(). If you use this, you will need to pass a +valid FILE * in the function png_init_io(). Be sure that the file is +opened in binary mode. If you wish to handle reading data in another +way, you need not call the png_init_io() function, but you must then +implement the libpng I/O methods discussed in the Customizing Libpng +section below. + + png_init_io(png_ptr, fp); + +If you had previously opened the file and read any of the signature from +the beginning in order to see if this was a PNG file, you need to let +libpng know that there are some bytes missing from the start of the file. + + png_set_sig_bytes(png_ptr, number); + +.SS Setting up callback code + +You can set up a callback function to handle any unknown chunks in the +input stream. You must supply the function + + read_chunk_callback(png_ptr ptr, + png_unknown_chunkp chunk); + { + /* The unknown chunk structure contains your + chunk data, along with similar data for any other + unknown chunks: */ + + png_byte name[5]; + png_byte *data; + png_size_t size; + + /* Note that libpng has already taken care of + the CRC handling */ + + /* put your code here. Search for your chunk in the + unknown chunk structure, process it, and return one + of the following: */ + + return (-n); /* chunk had an error */ + return (0); /* did not recognize */ + return (n); /* success */ + } + +(You can give your function another name that you like instead of +"read_chunk_callback") + +To inform libpng about your function, use + + png_set_read_user_chunk_fn(png_ptr, user_chunk_ptr, + read_chunk_callback); + +This names not only the callback function, but also a user pointer that +you can retrieve with + + png_get_user_chunk_ptr(png_ptr); + +If you call the png_set_read_user_chunk_fn() function, then all unknown +chunks will be saved when read, in case your callback function will need +one or more of them. This behavior can be changed with the +png_set_keep_unknown_chunks() function, described below. + +At this point, you can set up a callback function that will be +called after each row has been read, which you can use to control +a progress meter or the like. It's demonstrated in pngtest.c. +You must supply a function + + void read_row_callback(png_ptr ptr, png_uint_32 row, + int pass); + { + /* put your code here */ + } + +(You can give it another name that you like instead of "read_row_callback") + +To inform libpng about your function, use + + png_set_read_status_fn(png_ptr, read_row_callback); + +.SS Unknown-chunk handling + +Now you get to set the way the library processes unknown chunks in the +input PNG stream. Both known and unknown chunks will be read. Normal +behavior is that known chunks will be parsed into information in +various info_ptr members while unknown chunks will be discarded. This +behavior can be wasteful if your application will never use some known +chunk types. To change this, you can call: + + png_set_keep_unknown_chunks(png_ptr, keep, + chunk_list, num_chunks); + keep - 0: default unknown chunk handling + 1: ignore; do not keep + 2: keep only if safe-to-copy + 3: keep even if unsafe-to-copy + You can use these definitions: + PNG_HANDLE_CHUNK_AS_DEFAULT 0 + PNG_HANDLE_CHUNK_NEVER 1 + PNG_HANDLE_CHUNK_IF_SAFE 2 + PNG_HANDLE_CHUNK_ALWAYS 3 + chunk_list - list of chunks affected (a byte string, + five bytes per chunk, NULL or '\0' if + num_chunks is 0) + num_chunks - number of chunks affected; if 0, all + unknown chunks are affected. If nonzero, + only the chunks in the list are affected + +Unknown chunks declared in this way will be saved as raw data onto a +list of png_unknown_chunk structures. If a chunk that is normally +known to libpng is named in the list, it will be handled as unknown, +according to the "keep" directive. If a chunk is named in successive +instances of png_set_keep_unknown_chunks(), the final instance will +take precedence. The IHDR and IEND chunks should not be named in +chunk_list; if they are, libpng will process them normally anyway. + +Here is an example of the usage of png_set_keep_unknown_chunks(), +where the private "vpAg" chunk will later be processed by a user chunk +callback function: + + png_byte vpAg[5]={118, 112, 65, 103, (png_byte) '\0'}; + + #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) + png_byte unused_chunks[]= + { + 104, 73, 83, 84, (png_byte) '\0', /* hIST */ + 105, 84, 88, 116, (png_byte) '\0', /* iTXt */ + 112, 67, 65, 76, (png_byte) '\0', /* pCAL */ + 115, 67, 65, 76, (png_byte) '\0', /* sCAL */ + 115, 80, 76, 84, (png_byte) '\0', /* sPLT */ + 116, 73, 77, 69, (png_byte) '\0', /* tIME */ + }; + #endif + + ... + + #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) + /* ignore all unknown chunks: */ + png_set_keep_unknown_chunks(read_ptr, 1, NULL, 0); + /* except for vpAg: */ + png_set_keep_unknown_chunks(read_ptr, 2, vpAg, 1); + /* also ignore unused known chunks: */ + png_set_keep_unknown_chunks(read_ptr, 1, unused_chunks, + (int)sizeof(unused_chunks)/5); + #endif + +.SS User limits + +The PNG specification allows the width and height of an image to be as +large as 2^31-1 (0x7fffffff), or about 2.147 billion rows and columns. +Since very few applications really need to process such large images, +we have imposed an arbitrary 1-million limit on rows and columns. +Larger images will be rejected immediately with a png_error() call. If +you wish to override this limit, you can use + + png_set_user_limits(png_ptr, width_max, height_max); + +to set your own limits, or use width_max = height_max = 0x7fffffffL +to allow all valid dimensions (libpng may reject some very large images +anyway because of potential buffer overflow conditions). + +You should put this statement after you create the PNG structure and +before calling png_read_info(), png_read_png(), or png_process_data(). +If you need to retrieve the limits that are being applied, use + + width_max = png_get_user_width_max(png_ptr); + height_max = png_get_user_height_max(png_ptr); + +The PNG specification sets no limit on the number of ancillary chunks +allowed in a PNG datastream. You can impose a limit on the total number +of sPLT, tEXt, iTXt, zTXt, and unknown chunks that will be stored, with + + png_set_chunk_cache_max(png_ptr, user_chunk_cache_max); + +where 0x7fffffffL means unlimited. You can retrieve this limit with + + chunk_cache_max = png_get_chunk_cache_max(png_ptr); + +This limit also applies to the number of buffers that can be allocated +by png_decompress_chunk() while decompressing iTXt, zTXt, and iCCP chunks. + +.SS The high-level read interface + +At this point there are two ways to proceed; through the high-level +read interface, or through a sequence of low-level read operations. +You can use the high-level interface if (a) you are willing to read +the entire image into memory, and (b) the input transformations +you want to do are limited to the following set: + + PNG_TRANSFORM_IDENTITY No transformation + PNG_TRANSFORM_STRIP_16 Strip 16-bit samples to + 8 bits + PNG_TRANSFORM_STRIP_ALPHA Discard the alpha channel + PNG_TRANSFORM_PACKING Expand 1, 2 and 4-bit + samples to bytes + PNG_TRANSFORM_PACKSWAP Change order of packed + pixels to LSB first + PNG_TRANSFORM_EXPAND Perform set_expand() + PNG_TRANSFORM_INVERT_MONO Invert monochrome images + PNG_TRANSFORM_SHIFT Normalize pixels to the + sBIT depth + PNG_TRANSFORM_BGR Flip RGB to BGR, RGBA + to BGRA + PNG_TRANSFORM_SWAP_ALPHA Flip RGBA to ARGB or GA + to AG + PNG_TRANSFORM_INVERT_ALPHA Change alpha from opacity + to transparency + PNG_TRANSFORM_SWAP_ENDIAN Byte-swap 16-bit samples + PNG_TRANSFORM_GRAY_TO_RGB Expand grayscale samples + to RGB (or GA to RGBA) + +(This excludes setting a background color, doing gamma transformation, +dithering, and setting filler.) If this is the case, simply do this: + + png_read_png(png_ptr, info_ptr, png_transforms, NULL) + +where png_transforms is an integer containing the bitwise OR of some +set of transformation flags. This call is equivalent to png_read_info(), +followed the set of transformations indicated by the transform mask, +then png_read_image(), and finally png_read_end(). + +(The final parameter of this call is not yet used. Someday it might point +to transformation parameters required by some future input transform.) + +You must use png_transforms and not call any png_set_transform() functions +when you use png_read_png(). + +After you have called png_read_png(), you can retrieve the image data +with + + row_pointers = png_get_rows(png_ptr, info_ptr); + +where row_pointers is an array of pointers to the pixel data for each row: + + png_bytep row_pointers[height]; + +If you know your image size and pixel size ahead of time, you can allocate +row_pointers prior to calling png_read_png() with + + if (height > PNG_UINT_32_MAX/png_sizeof(png_byte)) + png_error (png_ptr, + "Image is too tall to process in memory"); + if (width > PNG_UINT_32_MAX/pixel_size) + png_error (png_ptr, + "Image is too wide to process in memory"); + row_pointers = png_malloc(png_ptr, + height*png_sizeof(png_bytep)); + for (int i=0; i) and +png_get_(png_ptr, info_ptr, ...) functions return non-zero if the +data has been read, or zero if it is missing. The parameters to the +png_get_ are set directly if they are simple data types, or a +pointer into the info_ptr is returned for any complex types. + + png_get_PLTE(png_ptr, info_ptr, &palette, + &num_palette); + palette - the palette for the file + (array of png_color) + num_palette - number of entries in the palette + + png_get_gAMA(png_ptr, info_ptr, &gamma); + gamma - the gamma the file is written + at (PNG_INFO_gAMA) + + png_get_sRGB(png_ptr, info_ptr, &srgb_intent); + srgb_intent - the rendering intent (PNG_INFO_sRGB) + The presence of the sRGB chunk + means that the pixel data is in the + sRGB color space. This chunk also + implies specific values of gAMA and + cHRM. + + png_get_iCCP(png_ptr, info_ptr, &name, + &compression_type, &profile, &proflen); + name - The profile name. + compression - The compression type; always + PNG_COMPRESSION_TYPE_BASE for PNG 1.0. + You may give NULL to this argument to + ignore it. + profile - International Color Consortium color + profile data. May contain NULs. + proflen - length of profile data in bytes. + + png_get_sBIT(png_ptr, info_ptr, &sig_bit); + sig_bit - the number of significant bits for + (PNG_INFO_sBIT) each of the gray, + red, green, and blue channels, + whichever are appropriate for the + given color type (png_color_16) + + png_get_tRNS(png_ptr, info_ptr, &trans, &num_trans, + &trans_values); + trans - array of transparent + entries for palette (PNG_INFO_tRNS) + trans_values - graylevel or color sample values of + the single transparent color for + non-paletted images (PNG_INFO_tRNS) + num_trans - number of transparent entries + (PNG_INFO_tRNS) + + png_get_hIST(png_ptr, info_ptr, &hist); + (PNG_INFO_hIST) + hist - histogram of palette (array of + png_uint_16) + + png_get_tIME(png_ptr, info_ptr, &mod_time); + mod_time - time image was last modified + (PNG_VALID_tIME) + + png_get_bKGD(png_ptr, info_ptr, &background); + background - background color (PNG_VALID_bKGD) + valid 16-bit red, green and blue + values, regardless of color_type + + num_comments = png_get_text(png_ptr, info_ptr, + &text_ptr, &num_text); + num_comments - number of comments + text_ptr - array of png_text holding image + comments + text_ptr[i].compression - type of compression used + on "text" PNG_TEXT_COMPRESSION_NONE + PNG_TEXT_COMPRESSION_zTXt + PNG_ITXT_COMPRESSION_NONE + PNG_ITXT_COMPRESSION_zTXt + text_ptr[i].key - keyword for comment. Must contain + 1-79 characters. + text_ptr[i].text - text comments for current + keyword. Can be empty. + text_ptr[i].text_length - length of text string, + after decompression, 0 for iTXt + text_ptr[i].itxt_length - length of itxt string, + after decompression, 0 for tEXt/zTXt + text_ptr[i].lang - language of comment (empty + string for unknown). + text_ptr[i].lang_key - keyword in UTF-8 + (empty string for unknown). + Note that the itxt_length, lang, and lang_key + members of the text_ptr structure only exist + when the library is built with iTXt chunk support. + + num_text - number of comments (same as + num_comments; you can put NULL here + to avoid the duplication) + Note while png_set_text() will accept text, language, + and translated keywords that can be NULL pointers, the + structure returned by png_get_text will always contain + regular zero-terminated C strings. They might be + empty strings but they will never be NULL pointers. + + num_spalettes = png_get_sPLT(png_ptr, info_ptr, + &palette_ptr); + palette_ptr - array of palette structures holding + contents of one or more sPLT chunks + read. + num_spalettes - number of sPLT chunks read. + + png_get_oFFs(png_ptr, info_ptr, &offset_x, &offset_y, + &unit_type); + offset_x - positive offset from the left edge + of the screen + offset_y - positive offset from the top edge + of the screen + unit_type - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER + + png_get_pHYs(png_ptr, info_ptr, &res_x, &res_y, + &unit_type); + res_x - pixels/unit physical resolution in + x direction + res_y - pixels/unit physical resolution in + x direction + unit_type - PNG_RESOLUTION_UNKNOWN, + PNG_RESOLUTION_METER + + png_get_sCAL(png_ptr, info_ptr, &unit, &width, + &height) + unit - physical scale units (an integer) + width - width of a pixel in physical scale units + height - height of a pixel in physical scale units + (width and height are doubles) + + png_get_sCAL_s(png_ptr, info_ptr, &unit, &width, + &height) + unit - physical scale units (an integer) + width - width of a pixel in physical scale units + height - height of a pixel in physical scale units + (width and height are strings like "2.54") + + num_unknown_chunks = png_get_unknown_chunks(png_ptr, + info_ptr, &unknowns) + unknowns - array of png_unknown_chunk + structures holding unknown chunks + unknowns[i].name - name of unknown chunk + unknowns[i].data - data of unknown chunk + unknowns[i].size - size of unknown chunk's data + unknowns[i].location - position of chunk in file + + The value of "i" corresponds to the order in which the + chunks were read from the PNG file or inserted with the + png_set_unknown_chunks() function. + +The data from the pHYs chunk can be retrieved in several convenient +forms: + + res_x = png_get_x_pixels_per_meter(png_ptr, + info_ptr) + res_y = png_get_y_pixels_per_meter(png_ptr, + info_ptr) + res_x_and_y = png_get_pixels_per_meter(png_ptr, + info_ptr) + res_x = png_get_x_pixels_per_inch(png_ptr, + info_ptr) + res_y = png_get_y_pixels_per_inch(png_ptr, + info_ptr) + res_x_and_y = png_get_pixels_per_inch(png_ptr, + info_ptr) + aspect_ratio = png_get_pixel_aspect_ratio(png_ptr, + info_ptr) + + (Each of these returns 0 [signifying "unknown"] if + the data is not present or if res_x is 0; + res_x_and_y is 0 if res_x != res_y) + +The data from the oFFs chunk can be retrieved in several convenient +forms: + + x_offset = png_get_x_offset_microns(png_ptr, info_ptr); + y_offset = png_get_y_offset_microns(png_ptr, info_ptr); + x_offset = png_get_x_offset_inches(png_ptr, info_ptr); + y_offset = png_get_y_offset_inches(png_ptr, info_ptr); + + (Each of these returns 0 [signifying "unknown" if both + x and y are 0] if the data is not present or if the + chunk is present but the unit is the pixel) + +For more information, see the png_info definition in png.h and the +PNG specification for chunk contents. Be careful with trusting +rowbytes, as some of the transformations could increase the space +needed to hold a row (expand, filler, gray_to_rgb, etc.). +See png_read_update_info(), below. + +A quick word about text_ptr and num_text. PNG stores comments in +keyword/text pairs, one pair per chunk, with no limit on the number +of text chunks, and a 2^31 byte limit on their size. While there are +suggested keywords, there is no requirement to restrict the use to these +strings. It is strongly suggested that keywords and text be sensible +to humans (that's the point), so don't use abbreviations. Non-printing +symbols are not allowed. See the PNG specification for more details. +There is also no requirement to have text after the keyword. + +Keywords should be limited to 79 Latin-1 characters without leading or +trailing spaces, but non-consecutive spaces are allowed within the +keyword. It is possible to have the same keyword any number of times. +The text_ptr is an array of png_text structures, each holding a +pointer to a language string, a pointer to a keyword and a pointer to +a text string. The text string, language code, and translated +keyword may be empty or NULL pointers. The keyword/text +pairs are put into the array in the order that they are received. +However, some or all of the text chunks may be after the image, so, to +make sure you have read all the text chunks, don't mess with these +until after you read the stuff after the image. This will be +mentioned again below in the discussion that goes with png_read_end(). + +.SS Input transformations + +After you've read the header information, you can set up the library +to handle any special transformations of the image data. The various +ways to transform the data will be described in the order that they +should occur. This is important, as some of these change the color +type and/or bit depth of the data, and some others only work on +certain color types and bit depths. Even though each transformation +checks to see if it has data that it can do something with, you should +make sure to only enable a transformation if it will be valid for the +data. For example, don't swap red and blue on grayscale data. + +The colors used for the background and transparency values should be +supplied in the same format/depth as the current image data. They +are stored in the same format/depth as the image data in a bKGD or tRNS +chunk, so this is what libpng expects for this data. The colors are +transformed to keep in sync with the image data when an application +calls the png_read_update_info() routine (see below). + +Data will be decoded into the supplied row buffers packed into bytes +unless the library has been told to transform it into another format. +For example, 4 bit/pixel paletted or grayscale data will be returned +2 pixels/byte with the leftmost pixel in the high-order bits of the +byte, unless png_set_packing() is called. 8-bit RGB data will be stored +in RGB RGB RGB format unless png_set_filler() or png_set_add_alpha() +is called to insert filler bytes, either before or after each RGB triplet. +16-bit RGB data will be returned RRGGBB RRGGBB, with the most significant +byte of the color value first, unless png_set_strip_16() is called to +transform it to regular RGB RGB triplets, or png_set_filler() or +png_set_add alpha() is called to insert filler bytes, either before or +after each RRGGBB triplet. Similarly, 8-bit or 16-bit grayscale data can +be modified with +png_set_filler(), png_set_add_alpha(), or png_set_strip_16(). + +The following code transforms grayscale images of less than 8 to 8 bits, +changes paletted images to RGB, and adds a full alpha channel if there is +transparency information in a tRNS chunk. This is most useful on +grayscale images with bit depths of 2 or 4 or if there is a multiple-image +viewing application that wishes to treat all images in the same way. + + if (color_type == PNG_COLOR_TYPE_PALETTE) + png_set_palette_to_rgb(png_ptr); + + if (color_type == PNG_COLOR_TYPE_GRAY && + bit_depth < 8) png_set_expand_gray_1_2_4_to_8(png_ptr); + + if (png_get_valid(png_ptr, info_ptr, + PNG_INFO_tRNS)) png_set_tRNS_to_alpha(png_ptr); + +These three functions are actually aliases for png_set_expand(), added +in libpng version 1.0.4, with the function names expanded to improve code +readability. In some future version they may actually do different +things. + +As of libpng version 1.2.9, png_set_expand_gray_1_2_4_to_8() was +added. It expands the sample depth without changing tRNS to alpha. + +As of libpng version 1.2.46, not all possible expansions are supported. + +In the following table, the 01 means grayscale with depth<8, 31 means +indexed with depth<8, other numerals represent the color type, "T" means +the tRNS chunk is present, A means an alpha channel is present, and O +means tRNS or alpha is present but all pixels in the image are opaque. + + FROM 01 31 0 0T 0O 2 2T 2O 3 3T 3O 4A 4O 6A 6O + TO + 01 - + 31 - + 0 1 - + 0T - + 0O - + 2 GX - + 2T - + 2O - + 3 1 - + 3T - + 3O - + 4A T - + 4O - + 6A GX TX TX - + 6O GX TX - + +Within the matrix, + "-" means the transformation is not supported. + "X" means the transformation is obtained by png_set_expand(). + "1" means the transformation is obtained by + png_set_expand_gray_1_2_4_to_8 + "G" means the transformation is obtained by + png_set_gray_to_rgb(). + "P" means the transformation is obtained by + png_set_expand_palette_to_rgb(). + "T" means the transformation is obtained by + png_set_tRNS_to_alpha(). + +PNG can have files with 16 bits per channel. If you only can handle +8 bits per channel, this will strip the pixels down to 8 bit. + + if (bit_depth == 16) + png_set_strip_16(png_ptr); + +If, for some reason, you don't need the alpha channel on an image, +and you want to remove it rather than combining it with the background +(but the image author certainly had in mind that you *would* combine +it with the background, so that's what you should probably do): + + if (color_type & PNG_COLOR_MASK_ALPHA) + png_set_strip_alpha(png_ptr); + +In PNG files, the alpha channel in an image +is the level of opacity. If you need the alpha channel in an image to +be the level of transparency instead of opacity, you can invert the +alpha channel (or the tRNS chunk data) after it's read, so that 0 is +fully opaque and 255 (in 8-bit or paletted images) or 65535 (in 16-bit +images) is fully transparent, with + + png_set_invert_alpha(png_ptr); + +The PNG format only supports pixels with postmultiplied alpha. +If you want to replace the pixels, after reading them, with pixels +that have premultiplied color samples, you can do this with + + png_set_premultiply_alpha(png_ptr); + +If you do this, any input with a tRNS chunk will be expanded to +have an alpha channel. + +PNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as +they can, resulting in, for example, 8 pixels per byte for 1 bit +files. This code expands to 1 pixel per byte without changing the +values of the pixels: + + if (bit_depth < 8) + png_set_packing(png_ptr); + +PNG files have possible bit depths of 1, 2, 4, 8, and 16. All pixels +stored in a PNG image have been "scaled" or "shifted" up to the next +higher possible bit depth (e.g. from 5 bits/sample in the range [0,31] +to 8 bits/sample in the range [0, 255]). However, it is also possible +to convert the PNG pixel data back to the original bit depth of the +image. This call reduces the pixels back down to the original bit depth: + + png_color_8p sig_bit; + + if (png_get_sBIT(png_ptr, info_ptr, &sig_bit)) + png_set_shift(png_ptr, sig_bit); + +PNG files store 3-color pixels in red, green, blue order. This code +changes the storage of the pixels to blue, green, red: + + if (color_type == PNG_COLOR_TYPE_RGB || + color_type == PNG_COLOR_TYPE_RGB_ALPHA) + png_set_bgr(png_ptr); + +PNG files store RGB pixels packed into 3 or 6 bytes. This code expands them +into 4 or 8 bytes for windowing systems that need them in this format: + + if (color_type == PNG_COLOR_TYPE_RGB) + png_set_filler(png_ptr, filler, PNG_FILLER_BEFORE); + +where "filler" is the 8 or 16-bit number to fill with, and the location is +either PNG_FILLER_BEFORE or PNG_FILLER_AFTER, depending upon whether +you want the filler before the RGB or after. This transformation +does not affect images that already have full alpha channels. To add an +opaque alpha channel, use filler=0xff or 0xffff and PNG_FILLER_AFTER which +will generate RGBA pixels. + +Note that png_set_filler() does not change the color type. If you want +to do that, you can add a true alpha channel with + + if (color_type == PNG_COLOR_TYPE_RGB || + color_type == PNG_COLOR_TYPE_GRAY) + png_set_add_alpha(png_ptr, filler, PNG_FILLER_AFTER); + +where "filler" contains the alpha value to assign to each pixel. +This function was added in libpng-1.2.7. + +If you are reading an image with an alpha channel, and you need the +data as ARGB instead of the normal PNG format RGBA: + + if (color_type == PNG_COLOR_TYPE_RGB_ALPHA) + png_set_swap_alpha(png_ptr); + +For some uses, you may want a grayscale image to be represented as +RGB. This code will do that conversion: + + if (color_type == PNG_COLOR_TYPE_GRAY || + color_type == PNG_COLOR_TYPE_GRAY_ALPHA) + png_set_gray_to_rgb(png_ptr); + +Conversely, you can convert an RGB or RGBA image to grayscale or grayscale +with alpha. + + if (color_type == PNG_COLOR_TYPE_RGB || + color_type == PNG_COLOR_TYPE_RGB_ALPHA) + png_set_rgb_to_gray_fixed(png_ptr, error_action, + int red_weight, int green_weight); + + error_action = 1: silently do the conversion + error_action = 2: issue a warning if the original + image has any pixel where + red != green or red != blue + error_action = 3: issue an error and abort the + conversion if the original + image has any pixel where + red != green or red != blue + + red_weight: weight of red component times 100000 + green_weight: weight of green component times 100000 + If either weight is negative, default + weights (21268, 71514) are used. + +If you have set error_action = 1 or 2, you can +later check whether the image really was gray, after processing +the image rows, with the png_get_rgb_to_gray_status(png_ptr) function. +It will return a png_byte that is zero if the image was gray or +1 if there were any non-gray pixels. bKGD and sBIT data +will be silently converted to grayscale, using the green channel +data, regardless of the error_action setting. + +With red_weight+green_weight<=100000, +the normalized graylevel is computed: + + int rw = red_weight * 65536; + int gw = green_weight * 65536; + int bw = 65536 - (rw + gw); + gray = (rw*red + gw*green + bw*blue)/65536; + +The default values approximate those recommended in the Charles +Poynton's Color FAQ, +Copyright (c) 1998-01-04 Charles Poynton + + Y = 0.212671 * R + 0.715160 * G + 0.072169 * B + +Libpng approximates this with + + Y = 0.21268 * R + 0.7151 * G + 0.07217 * B + +which can be expressed with integers as + + Y = (6969 * R + 23434 * G + 2365 * B)/32768 + +The calculation is done in a linear colorspace, if the image gamma +is known. + +If you have a grayscale and you are using png_set_expand_depth(), +png_set_expand(), or png_set_gray_to_rgb to change to truecolor or to +a higher bit-depth, you must either supply the background color as a gray +value at the original file bit-depth (need_expand = 1) or else supply the +background color as an RGB triplet at the final, expanded bit depth +(need_expand = 0). Similarly, if you are reading a paletted image, you +must either supply the background color as a palette index (need_expand = 1) +or as an RGB triplet that may or may not be in the palette (need_expand = 0). + + png_color_16 my_background; + png_color_16p image_background; + + if (png_get_bKGD(png_ptr, info_ptr, &image_background)) + png_set_background(png_ptr, image_background, + PNG_BACKGROUND_GAMMA_FILE, 1, 1.0); + else + png_set_background(png_ptr, &my_background, + PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0); + +The png_set_background() function tells libpng to composite images +with alpha or simple transparency against the supplied background +color. If the PNG file contains a bKGD chunk (PNG_INFO_bKGD valid), +you may use this color, or supply another color more suitable for +the current display (e.g., the background color from a web page). You +need to tell libpng whether the color is in the gamma space of the +display (PNG_BACKGROUND_GAMMA_SCREEN for colors you supply), the file +(PNG_BACKGROUND_GAMMA_FILE for colors from the bKGD chunk), or one +that is neither of these gammas (PNG_BACKGROUND_GAMMA_UNIQUE - I don't +know why anyone would use this, but it's here). + +To properly display PNG images on any kind of system, the application needs +to know what the display gamma is. Ideally, the user will know this, and +the application will allow them to set it. One method of allowing the user +to set the display gamma separately for each system is to check for a +SCREEN_GAMMA or DISPLAY_GAMMA environment variable, which will hopefully be +correctly set. + +Note that display_gamma is the overall gamma correction required to produce +pleasing results, which depends on the lighting conditions in the surrounding +environment. In a dim or brightly lit room, no compensation other than +the physical gamma exponent of the monitor is needed, while in a dark room +a slightly smaller exponent is better. + + double gamma, screen_gamma; + + if (/* We have a user-defined screen + gamma value */) + { + screen_gamma = user_defined_screen_gamma; + } + /* One way that applications can share the same + screen gamma value */ + else if ((gamma_str = getenv("SCREEN_GAMMA")) + != NULL) + { + screen_gamma = (double)atof(gamma_str); + } + /* If we don't have another value */ + else + { + screen_gamma = 2.2; /* A good guess for a + PC monitor in a bright office or a dim room */ + screen_gamma = 2.0; /* A good guess for a + PC monitor in a dark room */ + screen_gamma = 1.7 or 1.0; /* A good + guess for Mac systems */ + } + +The png_set_gamma() function handles gamma transformations of the data. +Pass both the file gamma and the current screen_gamma. If the file does +not have a gamma value, you can pass one anyway if you have an idea what +it is (usually 0.45455 is a good guess for GIF images on PCs). Note +that file gammas are inverted from screen gammas. See the discussions +on gamma in the PNG specification for an excellent description of what +gamma is, and why all applications should support it. It is strongly +recommended that PNG viewers support gamma correction. + + if (png_get_gAMA(png_ptr, info_ptr, &gamma)) + png_set_gamma(png_ptr, screen_gamma, gamma); + else + png_set_gamma(png_ptr, screen_gamma, 0.45455); + +If you need to reduce an RGB file to a paletted file, or if a paletted +file has more entries then will fit on your screen, png_set_dither() +will do that. Note that this is a simple match dither that merely +finds the closest color available. This should work fairly well with +optimized palettes, and fairly badly with linear color cubes. If you +pass a palette that is larger then maximum_colors, the file will +reduce the number of colors in the palette so it will fit into +maximum_colors. If there is a histogram, it will use it to make +more intelligent choices when reducing the palette. If there is no +histogram, it may not do as good a job. + + if (color_type & PNG_COLOR_MASK_COLOR) + { + if (png_get_valid(png_ptr, info_ptr, + PNG_INFO_PLTE)) + { + png_uint_16p histogram = NULL; + + png_get_hIST(png_ptr, info_ptr, + &histogram); + png_set_dither(png_ptr, palette, num_palette, + max_screen_colors, histogram, 1); + } + else + { + png_color std_color_cube[MAX_SCREEN_COLORS] = + { ... colors ... }; + + png_set_dither(png_ptr, std_color_cube, + MAX_SCREEN_COLORS, MAX_SCREEN_COLORS, + NULL,0); + } + } + +PNG files describe monochrome as black being zero and white being one. +The following code will reverse this (make black be one and white be +zero): + + if (bit_depth == 1 && color_type == PNG_COLOR_TYPE_GRAY) + png_set_invert_mono(png_ptr); + +This function can also be used to invert grayscale and gray-alpha images: + + if (color_type == PNG_COLOR_TYPE_GRAY || + color_type == PNG_COLOR_TYPE_GRAY_ALPHA) + png_set_invert_mono(png_ptr); + +PNG files store 16 bit pixels in network byte order (big-endian, +ie. most significant bits first). This code changes the storage to the +other way (little-endian, i.e. least significant bits first, the +way PCs store them): + + if (bit_depth == 16) + png_set_swap(png_ptr); + +If you are using packed-pixel images (1, 2, or 4 bits/pixel), and you +need to change the order the pixels are packed into bytes, you can use: + + if (bit_depth < 8) + png_set_packswap(png_ptr); + +Finally, you can write your own transformation function if none of +the existing ones meets your needs. This is done by setting a callback +with + + png_set_read_user_transform_fn(png_ptr, + read_transform_fn); + +You must supply the function + + void read_transform_fn(png_ptr ptr, row_info_ptr + row_info, png_bytep data) + +See pngtest.c for a working example. Your function will be called +after all of the other transformations have been processed. + +You can also set up a pointer to a user structure for use by your +callback function, and you can inform libpng that your transform +function will change the number of channels or bit depth with the +function + + png_set_user_transform_info(png_ptr, user_ptr, + user_depth, user_channels); + +The user's application, not libpng, is responsible for allocating and +freeing any memory required for the user structure. + +You can retrieve the pointer via the function +png_get_user_transform_ptr(). For example: + + voidp read_user_transform_ptr = + png_get_user_transform_ptr(png_ptr); + +The last thing to handle is interlacing; this is covered in detail below, +but you must call the function here if you want libpng to handle expansion +of the interlaced image. + + number_of_passes = png_set_interlace_handling(png_ptr); + +After setting the transformations, libpng can update your png_info +structure to reflect any transformations you've requested with this +call. This is most useful to update the info structure's rowbytes +field so you can use it to allocate your image memory. This function +will also update your palette with the correct screen_gamma and +background if these have been given with the calls above. + + png_read_update_info(png_ptr, info_ptr); + +After you call png_read_update_info(), you can allocate any +memory you need to hold the image. The row data is simply +raw byte data for all forms of images. As the actual allocation +varies among applications, no example will be given. If you +are allocating one large chunk, you will need to build an +array of pointers to each row, as it will be needed for some +of the functions below. + +.SS Reading image data + +After you've allocated memory, you can read the image data. +The simplest way to do this is in one function call. If you are +allocating enough memory to hold the whole image, you can just +call png_read_image() and libpng will read in all the image data +and put it in the memory area supplied. You will need to pass in +an array of pointers to each row. + +This function automatically handles interlacing, so you don't need +to call png_set_interlace_handling() or call this function multiple +times, or any of that other stuff necessary with png_read_rows(). + + png_read_image(png_ptr, row_pointers); + +where row_pointers is: + + png_bytep row_pointers[height]; + +You can point to void or char or whatever you use for pixels. + +If you don't want to read in the whole image at once, you can +use png_read_rows() instead. If there is no interlacing (check +interlace_type == PNG_INTERLACE_NONE), this is simple: + + png_read_rows(png_ptr, row_pointers, NULL, + number_of_rows); + +where row_pointers is the same as in the png_read_image() call. + +If you are doing this just one row at a time, you can do this with +a single row_pointer instead of an array of row_pointers: + + png_bytep row_pointer = row; + png_read_row(png_ptr, row_pointer, NULL); + +If the file is interlaced (interlace_type != 0 in the IHDR chunk), things +get somewhat harder. The only current (PNG Specification version 1.2) +interlacing type for PNG is (interlace_type == PNG_INTERLACE_ADAM7) +is a somewhat complicated 2D interlace scheme, known as Adam7, that +breaks down an image into seven smaller images of varying size, based +on an 8x8 grid. + +libpng can fill out those images or it can give them to you "as is". +If you want them filled out, there are two ways to do that. The one +mentioned in the PNG specification is to expand each pixel to cover +those pixels that have not been read yet (the "rectangle" method). +This results in a blocky image for the first pass, which gradually +smooths out as more pixels are read. The other method is the "sparkle" +method, where pixels are drawn only in their final locations, with the +rest of the image remaining whatever colors they were initialized to +before the start of the read. The first method usually looks better, +but tends to be slower, as there are more pixels to put in the rows. + +If you don't want libpng to handle the interlacing details, just call +png_read_rows() seven times to read in all seven images. Each of the +images is a valid image by itself, or they can all be combined on an +8x8 grid to form a single image (although if you intend to combine them +you would be far better off using the libpng interlace handling). + +The first pass will return an image 1/8 as wide as the entire image +(every 8th column starting in column 0) and 1/8 as high as the original +(every 8th row starting in row 0), the second will be 1/8 as wide +(starting in column 4) and 1/8 as high (also starting in row 0). The +third pass will be 1/4 as wide (every 4th pixel starting in column 0) and +1/8 as high (every 8th row starting in row 4), and the fourth pass will +be 1/4 as wide and 1/4 as high (every 4th column starting in column 2, +and every 4th row starting in row 0). The fifth pass will return an +image 1/2 as wide, and 1/4 as high (starting at column 0 and row 2), +while the sixth pass will be 1/2 as wide and 1/2 as high as the original +(starting in column 1 and row 0). The seventh and final pass will be as +wide as the original, and 1/2 as high, containing all of the odd +numbered scanlines. Phew! + +If you want libpng to expand the images, call this before calling +png_start_read_image() or png_read_update_info(): + + if (interlace_type == PNG_INTERLACE_ADAM7) + number_of_passes + = png_set_interlace_handling(png_ptr); + +This will return the number of passes needed. Currently, this +is seven, but may change if another interlace type is added. +This function can be called even if the file is not interlaced, +where it will return one pass. + +If you are not going to display the image after each pass, but are +going to wait until the entire image is read in, use the sparkle +effect. This effect is faster and the end result of either method +is exactly the same. If you are planning on displaying the image +after each pass, the "rectangle" effect is generally considered the +better looking one. + +If you only want the "sparkle" effect, just call png_read_rows() as +normal, with the third parameter NULL. Make sure you make pass over +the image number_of_passes times, and you don't change the data in the +rows between calls. You can change the locations of the data, just +not the data. Each pass only writes the pixels appropriate for that +pass, and assumes the data from previous passes is still valid. + + png_read_rows(png_ptr, row_pointers, NULL, + number_of_rows); + +If you only want the first effect (the rectangles), do the same as +before except pass the row buffer in the third parameter, and leave +the second parameter NULL. + + png_read_rows(png_ptr, NULL, row_pointers, + number_of_rows); + +.SS Finishing a sequential read + +After you are finished reading the image through the +low-level interface, you can finish reading the file. If you are +interested in comments or time, which may be stored either before or +after the image data, you should pass the separate png_info struct if +you want to keep the comments from before and after the image +separate. If you are not interested, you can pass NULL. + + png_read_end(png_ptr, end_info); + +When you are done, you can free all memory allocated by libpng like this: + + png_destroy_read_struct(&png_ptr, &info_ptr, + &end_info); + +It is also possible to individually free the info_ptr members that +point to libpng-allocated storage with the following function: + + png_free_data(png_ptr, info_ptr, mask, seq) + mask - identifies data to be freed, a mask + containing the bitwise OR of one or + more of + PNG_FREE_PLTE, PNG_FREE_TRNS, + PNG_FREE_HIST, PNG_FREE_ICCP, + PNG_FREE_PCAL, PNG_FREE_ROWS, + PNG_FREE_SCAL, PNG_FREE_SPLT, + PNG_FREE_TEXT, PNG_FREE_UNKN, + or simply PNG_FREE_ALL + seq - sequence number of item to be freed + (-1 for all items) + +This function may be safely called when the relevant storage has +already been freed, or has not yet been allocated, or was allocated +by the user and not by libpng, and will in those cases do nothing. +The "seq" parameter is ignored if only one item of the selected data +type, such as PLTE, is allowed. If "seq" is not -1, and multiple items +are allowed for the data type identified in the mask, such as text or +sPLT, only the n'th item in the structure is freed, where n is "seq". + +The default behavior is only to free data that was allocated internally +by libpng. This can be changed, so that libpng will not free the data, +or so that it will free data that was allocated by the user with png_malloc() +or png_zalloc() and passed in via a png_set_*() function, with + + png_data_freer(png_ptr, info_ptr, freer, mask) + mask - which data elements are affected + same choices as in png_free_data() + freer - one of + PNG_DESTROY_WILL_FREE_DATA + PNG_SET_WILL_FREE_DATA + PNG_USER_WILL_FREE_DATA + +This function only affects data that has already been allocated. +You can call this function after reading the PNG data but before calling +any png_set_*() functions, to control whether the user or the png_set_*() +function is responsible for freeing any existing data that might be present, +and again after the png_set_*() functions to control whether the user +or png_destroy_*() is supposed to free the data. When the user assumes +responsibility for libpng-allocated data, the application must use +png_free() to free it, and when the user transfers responsibility to libpng +for data that the user has allocated, the user must have used png_malloc() +or png_zalloc() to allocate it. + +If you allocated your row_pointers in a single block, as suggested above in +the description of the high level read interface, you must not transfer +responsibility for freeing it to the png_set_rows or png_read_destroy function, +because they would also try to free the individual row_pointers[i]. + +If you allocated text_ptr.text, text_ptr.lang, and text_ptr.translated_keyword +separately, do not transfer responsibility for freeing text_ptr to libpng, +because when libpng fills a png_text structure it combines these members with +the key member, and png_free_data() will free only text_ptr.key. Similarly, +if you transfer responsibility for free'ing text_ptr from libpng to your +application, your application must not separately free those members. + +The png_free_data() function will turn off the "valid" flag for anything +it frees. If you need to turn the flag off for a chunk that was freed by +your application instead of by libpng, you can use + + png_set_invalid(png_ptr, info_ptr, mask); + mask - identifies the chunks to be made invalid, + containing the bitwise OR of one or + more of + PNG_INFO_gAMA, PNG_INFO_sBIT, + PNG_INFO_cHRM, PNG_INFO_PLTE, + PNG_INFO_tRNS, PNG_INFO_bKGD, + PNG_INFO_hIST, PNG_INFO_pHYs, + PNG_INFO_oFFs, PNG_INFO_tIME, + PNG_INFO_pCAL, PNG_INFO_sRGB, + PNG_INFO_iCCP, PNG_INFO_sPLT, + PNG_INFO_sCAL, PNG_INFO_IDAT + +For a more compact example of reading a PNG image, see the file example.c. + +.SS Reading PNG files progressively + +The progressive reader is slightly different then the non-progressive +reader. Instead of calling png_read_info(), png_read_rows(), and +png_read_end(), you make one call to png_process_data(), which calls +callbacks when it has the info, a row, or the end of the image. You +set up these callbacks with png_set_progressive_read_fn(). You don't +have to worry about the input/output functions of libpng, as you are +giving the library the data directly in png_process_data(). I will +assume that you have read the section on reading PNG files above, +so I will only highlight the differences (although I will show +all of the code). + +png_structp png_ptr; +png_infop info_ptr; + + /* An example code fragment of how you would + initialize the progressive reader in your + application. */ + int + initialize_png_reader() + { + png_ptr = png_create_read_struct + (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr, + user_error_fn, user_warning_fn); + if (!png_ptr) + return (ERROR); + info_ptr = png_create_info_struct(png_ptr); + if (!info_ptr) + { + png_destroy_read_struct(&png_ptr, (png_infopp)NULL, + (png_infopp)NULL); + return (ERROR); + } + + if (setjmp(png_jmpbuf(png_ptr))) + { + png_destroy_read_struct(&png_ptr, &info_ptr, + (png_infopp)NULL); + return (ERROR); + } + + /* This one's new. You can provide functions + to be called when the header info is valid, + when each row is completed, and when the image + is finished. If you aren't using all functions, + you can specify NULL parameters. Even when all + three functions are NULL, you need to call + png_set_progressive_read_fn(). You can use + any struct as the user_ptr (cast to a void pointer + for the function call), and retrieve the pointer + from inside the callbacks using the function + + png_get_progressive_ptr(png_ptr); + + which will return a void pointer, which you have + to cast appropriately. + */ + png_set_progressive_read_fn(png_ptr, (void *)user_ptr, + info_callback, row_callback, end_callback); + + return 0; + } + + /* A code fragment that you call as you receive blocks + of data */ + int + process_data(png_bytep buffer, png_uint_32 length) + { + if (setjmp(png_jmpbuf(png_ptr))) + { + png_destroy_read_struct(&png_ptr, &info_ptr, + (png_infopp)NULL); + return (ERROR); + } + + /* This one's new also. Simply give it a chunk + of data from the file stream (in order, of + course). On machines with segmented memory + models machines, don't give it any more than + 64K. The library seems to run fine with sizes + of 4K. Although you can give it much less if + necessary (I assume you can give it chunks of + 1 byte, I haven't tried less then 256 bytes + yet). When this function returns, you may + want to display any rows that were generated + in the row callback if you don't already do + so there. + */ + png_process_data(png_ptr, info_ptr, buffer, length); + return 0; + } + + /* This function is called (as set by + png_set_progressive_read_fn() above) when enough data + has been supplied so all of the header has been + read. + */ + void + info_callback(png_structp png_ptr, png_infop info) + { + /* Do any setup here, including setting any of + the transformations mentioned in the Reading + PNG files section. For now, you _must_ call + either png_start_read_image() or + png_read_update_info() after all the + transformations are set (even if you don't set + any). You may start getting rows before + png_process_data() returns, so this is your + last chance to prepare for that. + */ + } + + /* This function is called when each row of image + data is complete */ + void + row_callback(png_structp png_ptr, png_bytep new_row, + png_uint_32 row_num, int pass) + { + /* If the image is interlaced, and you turned + on the interlace handler, this function will + be called for every row in every pass. Some + of these rows will not be changed from the + previous pass. When the row is not changed, + the new_row variable will be NULL. The rows + and passes are called in order, so you don't + really need the row_num and pass, but I'm + supplying them because it may make your life + easier. + + For the non-NULL rows of interlaced images, + you must call png_progressive_combine_row() + passing in the row and the old row. You can + call this function for NULL rows (it will just + return) and for non-interlaced images (it just + does the memcpy for you) if it will make the + code easier. Thus, you can just do this for + all cases: + */ + + png_progressive_combine_row(png_ptr, old_row, + new_row); + + /* where old_row is what was displayed for + previously for the row. Note that the first + pass (pass == 0, really) will completely cover + the old row, so the rows do not have to be + initialized. After the first pass (and only + for interlaced images), you will have to pass + the current row, and the function will combine + the old row and the new row. + */ + } + + void + end_callback(png_structp png_ptr, png_infop info) + { + /* This function is called after the whole image + has been read, including any chunks after the + image (up to and including the IEND). You + will usually have the same info chunk as you + had in the header, although some data may have + been added to the comments and time fields. + + Most people won't do much here, perhaps setting + a flag that marks the image as finished. + */ + } + + + +.SH IV. Writing + +Much of this is very similar to reading. However, everything of +importance is repeated here, so you won't have to constantly look +back up in the reading section to understand writing. + +.SS Setup + +You will want to do the I/O initialization before you get into libpng, +so if it doesn't work, you don't have anything to undo. If you are not +using the standard I/O functions, you will need to replace them with +custom writing functions. See the discussion under Customizing libpng. + + FILE *fp = fopen(file_name, "wb"); + if (!fp) + { + return (ERROR); + } + +Next, png_struct and png_info need to be allocated and initialized. +As these can be both relatively large, you may not want to store these +on the stack, unless you have stack space to spare. Of course, you +will want to check if they return NULL. If you are also reading, +you won't want to name your read structure and your write structure +both "png_ptr"; you can call them anything you like, such as +"read_ptr" and "write_ptr". Look at pngtest.c, for example. + + png_structp png_ptr = png_create_write_struct + (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr, + user_error_fn, user_warning_fn); + if (!png_ptr) + return (ERROR); + + png_infop info_ptr = png_create_info_struct(png_ptr); + if (!info_ptr) + { + png_destroy_write_struct(&png_ptr, + (png_infopp)NULL); + return (ERROR); + } + +If you want to use your own memory allocation routines, +define PNG_USER_MEM_SUPPORTED and use +png_create_write_struct_2() instead of png_create_write_struct(): + + png_structp png_ptr = png_create_write_struct_2 + (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr, + user_error_fn, user_warning_fn, (png_voidp) + user_mem_ptr, user_malloc_fn, user_free_fn); + +After you have these structures, you will need to set up the +error handling. When libpng encounters an error, it expects to +longjmp() back to your routine. Therefore, you will need to call +setjmp() and pass the png_jmpbuf(png_ptr). If you +write the file from different routines, you will need to update +the png_jmpbuf(png_ptr) every time you enter a new routine that will +call a png_*() function. See your documentation of setjmp/longjmp +for your compiler for more information on setjmp/longjmp. See +the discussion on libpng error handling in the Customizing Libpng +section below for more information on the libpng error handling. + + if (setjmp(png_jmpbuf(png_ptr))) + { + png_destroy_write_struct(&png_ptr, &info_ptr); + fclose(fp); + return (ERROR); + } + ... + return; + +If you would rather avoid the complexity of setjmp/longjmp issues, +you can compile libpng with PNG_SETJMP_NOT_SUPPORTED, in which case +errors will result in a call to PNG_ABORT() which defaults to abort(). + +Now you need to set up the output code. The default for libpng is to +use the C function fwrite(). If you use this, you will need to pass a +valid FILE * in the function png_init_io(). Be sure that the file is +opened in binary mode. Again, if you wish to handle writing data in +another way, see the discussion on libpng I/O handling in the Customizing +Libpng section below. + + png_init_io(png_ptr, fp); + +If you are embedding your PNG into a datastream such as MNG, and don't +want libpng to write the 8-byte signature, or if you have already +written the signature in your application, use + + png_set_sig_bytes(png_ptr, 8); + +to inform libpng that it should not write a signature. + +.SS Write callbacks + +At this point, you can set up a callback function that will be +called after each row has been written, which you can use to control +a progress meter or the like. It's demonstrated in pngtest.c. +You must supply a function + + void write_row_callback(png_ptr, png_uint_32 row, + int pass); + { + /* put your code here */ + } + +(You can give it another name that you like instead of "write_row_callback") + +To inform libpng about your function, use + + png_set_write_status_fn(png_ptr, write_row_callback); + +You now have the option of modifying how the compression library will +run. The following functions are mainly for testing, but may be useful +in some cases, like if you need to write PNG files extremely fast and +are willing to give up some compression, or if you want to get the +maximum possible compression at the expense of slower writing. If you +have no special needs in this area, let the library do what it wants by +not calling this function at all, as it has been tuned to deliver a good +speed/compression ratio. The second parameter to png_set_filter() is +the filter method, for which the only valid values are 0 (as of the +July 1999 PNG specification, version 1.2) or 64 (if you are writing +a PNG datastream that is to be embedded in a MNG datastream). The third +parameter is a flag that indicates which filter type(s) are to be tested +for each scanline. See the PNG specification for details on the specific +filter types. + + + /* turn on or off filtering, and/or choose + specific filters. You can use either a single + PNG_FILTER_VALUE_NAME or the bitwise OR of one + or more PNG_FILTER_NAME masks. */ + png_set_filter(png_ptr, 0, + PNG_FILTER_NONE | PNG_FILTER_VALUE_NONE | + PNG_FILTER_SUB | PNG_FILTER_VALUE_SUB | + PNG_FILTER_UP | PNG_FILTER_VALUE_UP | + PNG_FILTER_AVG | PNG_FILTER_VALUE_AVG | + PNG_FILTER_PAETH | PNG_FILTER_VALUE_PAETH| + PNG_ALL_FILTERS); + +If an application +wants to start and stop using particular filters during compression, +it should start out with all of the filters (to ensure that the previous +row of pixels will be stored in case it's needed later), and then add +and remove them after the start of compression. + +If you are writing a PNG datastream that is to be embedded in a MNG +datastream, the second parameter can be either 0 or 64. + +The png_set_compression_*() functions interface to the zlib compression +library, and should mostly be ignored unless you really know what you are +doing. The only generally useful call is png_set_compression_level() +which changes how much time zlib spends on trying to compress the image +data. See the Compression Library (zlib.h and algorithm.txt, distributed +with zlib) for details on the compression levels. + + /* set the zlib compression level */ + png_set_compression_level(png_ptr, + Z_BEST_COMPRESSION); + + /* set other zlib parameters */ + png_set_compression_mem_level(png_ptr, 8); + png_set_compression_strategy(png_ptr, + Z_DEFAULT_STRATEGY); + png_set_compression_window_bits(png_ptr, 15); + png_set_compression_method(png_ptr, 8); + png_set_compression_buffer_size(png_ptr, 8192) + +extern PNG_EXPORT(void,png_set_zbuf_size) + +.SS Setting the contents of info for output + +You now need to fill in the png_info structure with all the data you +wish to write before the actual image. Note that the only thing you +are allowed to write after the image is the text chunks and the time +chunk (as of PNG Specification 1.2, anyway). See png_write_end() and +the latest PNG specification for more information on that. If you +wish to write them before the image, fill them in now, and flag that +data as being valid. If you want to wait until after the data, don't +fill them until png_write_end(). For all the fields in png_info and +their data types, see png.h. For explanations of what the fields +contain, see the PNG specification. + +Some of the more important parts of the png_info are: + + png_set_IHDR(png_ptr, info_ptr, width, height, + bit_depth, color_type, interlace_type, + compression_type, filter_method) + width - holds the width of the image + in pixels (up to 2^31). + height - holds the height of the image + in pixels (up to 2^31). + bit_depth - holds the bit depth of one of the + image channels. + (valid values are 1, 2, 4, 8, 16 + and depend also on the + color_type. See also significant + bits (sBIT) below). + color_type - describes which color/alpha + channels are present. + PNG_COLOR_TYPE_GRAY + (bit depths 1, 2, 4, 8, 16) + PNG_COLOR_TYPE_GRAY_ALPHA + (bit depths 8, 16) + PNG_COLOR_TYPE_PALETTE + (bit depths 1, 2, 4, 8) + PNG_COLOR_TYPE_RGB + (bit_depths 8, 16) + PNG_COLOR_TYPE_RGB_ALPHA + (bit_depths 8, 16) + + PNG_COLOR_MASK_PALETTE + PNG_COLOR_MASK_COLOR + PNG_COLOR_MASK_ALPHA + + interlace_type - PNG_INTERLACE_NONE or + PNG_INTERLACE_ADAM7 + compression_type - (must be + PNG_COMPRESSION_TYPE_DEFAULT) + filter_method - (must be PNG_FILTER_TYPE_DEFAULT + or, if you are writing a PNG to + be embedded in a MNG datastream, + can also be + PNG_INTRAPIXEL_DIFFERENCING) + +If you call png_set_IHDR(), the call must appear before any of the +other png_set_*() functions, because they might require access to some of +the IHDR settings. The remaining png_set_*() functions can be called +in any order. + +If you wish, you can reset the compression_type, interlace_type, or +filter_method later by calling png_set_IHDR() again; if you do this, the +width, height, bit_depth, and color_type must be the same in each call. + + png_set_PLTE(png_ptr, info_ptr, palette, + num_palette); + palette - the palette for the file + (array of png_color) + num_palette - number of entries in the palette + + png_set_gAMA(png_ptr, info_ptr, gamma); + gamma - the gamma the image was created + at (PNG_INFO_gAMA) + + png_set_sRGB(png_ptr, info_ptr, srgb_intent); + srgb_intent - the rendering intent + (PNG_INFO_sRGB) The presence of + the sRGB chunk means that the pixel + data is in the sRGB color space. + This chunk also implies specific + values of gAMA and cHRM. Rendering + intent is the CSS-1 property that + has been defined by the International + Color Consortium + (http://www.color.org). + It can be one of + PNG_sRGB_INTENT_SATURATION, + PNG_sRGB_INTENT_PERCEPTUAL, + PNG_sRGB_INTENT_ABSOLUTE, or + PNG_sRGB_INTENT_RELATIVE. + + + png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr, + srgb_intent); + srgb_intent - the rendering intent + (PNG_INFO_sRGB) The presence of the + sRGB chunk means that the pixel + data is in the sRGB color space. + This function also causes gAMA and + cHRM chunks with the specific values + that are consistent with sRGB to be + written. + + png_set_iCCP(png_ptr, info_ptr, name, compression_type, + profile, proflen); + name - The profile name. + compression - The compression type; always + PNG_COMPRESSION_TYPE_BASE for PNG 1.0. + You may give NULL to this argument to + ignore it. + profile - International Color Consortium color + profile data. May contain NULs. + proflen - length of profile data in bytes. + + png_set_sBIT(png_ptr, info_ptr, sig_bit); + sig_bit - the number of significant bits for + (PNG_INFO_sBIT) each of the gray, red, + green, and blue channels, whichever are + appropriate for the given color type + (png_color_16) + + png_set_tRNS(png_ptr, info_ptr, trans, num_trans, + trans_values); + trans - array of transparent + entries for palette (PNG_INFO_tRNS) + trans_values - graylevel or color sample values + (in order red, green, blue) of the + single transparent color for + non-paletted images (PNG_INFO_tRNS) + num_trans - number of transparent entries + (PNG_INFO_tRNS) + + png_set_hIST(png_ptr, info_ptr, hist); + (PNG_INFO_hIST) + hist - histogram of palette (array of + png_uint_16) + + png_set_tIME(png_ptr, info_ptr, mod_time); + mod_time - time image was last modified + (PNG_VALID_tIME) + + png_set_bKGD(png_ptr, info_ptr, background); + background - background color (PNG_VALID_bKGD) + + png_set_text(png_ptr, info_ptr, text_ptr, num_text); + text_ptr - array of png_text holding image + comments + text_ptr[i].compression - type of compression used + on "text" PNG_TEXT_COMPRESSION_NONE + PNG_TEXT_COMPRESSION_zTXt + PNG_ITXT_COMPRESSION_NONE + PNG_ITXT_COMPRESSION_zTXt + text_ptr[i].key - keyword for comment. Must contain + 1-79 characters. + text_ptr[i].text - text comments for current + keyword. Can be NULL or empty. + text_ptr[i].text_length - length of text string, + after decompression, 0 for iTXt + text_ptr[i].itxt_length - length of itxt string, + after decompression, 0 for tEXt/zTXt + text_ptr[i].lang - language of comment (NULL or + empty for unknown). + text_ptr[i].translated_keyword - keyword in UTF-8 (NULL + or empty for unknown). + Note that the itxt_length, lang, and lang_key + members of the text_ptr structure only exist + when the library is built with iTXt chunk support. + + num_text - number of comments + + png_set_sPLT(png_ptr, info_ptr, &palette_ptr, + num_spalettes); + palette_ptr - array of png_sPLT_struct structures + to be added to the list of palettes + in the info structure. + num_spalettes - number of palette structures to be + added. + + png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y, + unit_type); + offset_x - positive offset from the left + edge of the screen + offset_y - positive offset from the top + edge of the screen + unit_type - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER + + png_set_pHYs(png_ptr, info_ptr, res_x, res_y, + unit_type); + res_x - pixels/unit physical resolution + in x direction + res_y - pixels/unit physical resolution + in y direction + unit_type - PNG_RESOLUTION_UNKNOWN, + PNG_RESOLUTION_METER + + png_set_sCAL(png_ptr, info_ptr, unit, width, height) + unit - physical scale units (an integer) + width - width of a pixel in physical scale units + height - height of a pixel in physical scale units + (width and height are doubles) + + png_set_sCAL_s(png_ptr, info_ptr, unit, width, height) + unit - physical scale units (an integer) + width - width of a pixel in physical scale units + height - height of a pixel in physical scale units + (width and height are strings like "2.54") + + png_set_unknown_chunks(png_ptr, info_ptr, &unknowns, + num_unknowns) + unknowns - array of png_unknown_chunk + structures holding unknown chunks + unknowns[i].name - name of unknown chunk + unknowns[i].data - data of unknown chunk + unknowns[i].size - size of unknown chunk's data + unknowns[i].location - position to write chunk in file + 0: do not write chunk + PNG_HAVE_IHDR: before PLTE + PNG_HAVE_PLTE: before IDAT + PNG_AFTER_IDAT: after IDAT + +The "location" member is set automatically according to +what part of the output file has already been written. +You can change its value after calling png_set_unknown_chunks() +as demonstrated in pngtest.c. Within each of the "locations", +the chunks are sequenced according to their position in the +structure (that is, the value of "i", which is the order in which +the chunk was either read from the input file or defined with +png_set_unknown_chunks). + +A quick word about text and num_text. text is an array of png_text +structures. num_text is the number of valid structures in the array. +Each png_text structure holds a language code, a keyword, a text value, +and a compression type. + +The compression types have the same valid numbers as the compression +types of the image data. Currently, the only valid number is zero. +However, you can store text either compressed or uncompressed, unlike +images, which always have to be compressed. So if you don't want the +text compressed, set the compression type to PNG_TEXT_COMPRESSION_NONE. +Because tEXt and zTXt chunks don't have a language field, if you +specify PNG_TEXT_COMPRESSION_NONE or PNG_TEXT_COMPRESSION_zTXt +any language code or translated keyword will not be written out. + +Until text gets around 1000 bytes, it is not worth compressing it. +After the text has been written out to the file, the compression type +is set to PNG_TEXT_COMPRESSION_NONE_WR or PNG_TEXT_COMPRESSION_zTXt_WR, +so that it isn't written out again at the end (in case you are calling +png_write_end() with the same struct. + +The keywords that are given in the PNG Specification are: + + Title Short (one line) title or + caption for image + Author Name of image's creator + Description Description of image (possibly long) + Copyright Copyright notice + Creation Time Time of original image creation + (usually RFC 1123 format, see below) + Software Software used to create the image + Disclaimer Legal disclaimer + Warning Warning of nature of content + Source Device used to create the image + Comment Miscellaneous comment; conversion + from other image format + +The keyword-text pairs work like this. Keywords should be short +simple descriptions of what the comment is about. Some typical +keywords are found in the PNG specification, as is some recommendations +on keywords. You can repeat keywords in a file. You can even write +some text before the image and some after. For example, you may want +to put a description of the image before the image, but leave the +disclaimer until after, so viewers working over modem connections +don't have to wait for the disclaimer to go over the modem before +they start seeing the image. Finally, keywords should be full +words, not abbreviations. Keywords and text are in the ISO 8859-1 +(Latin-1) character set (a superset of regular ASCII) and can not +contain NUL characters, and should not contain control or other +unprintable characters. To make the comments widely readable, stick +with basic ASCII, and avoid machine specific character set extensions +like the IBM-PC character set. The keyword must be present, but +you can leave off the text string on non-compressed pairs. +Compressed pairs must have a text string, as only the text string +is compressed anyway, so the compression would be meaningless. + +PNG supports modification time via the png_time structure. Two +conversion routines are provided, png_convert_from_time_t() for +time_t and png_convert_from_struct_tm() for struct tm. The +time_t routine uses gmtime(). You don't have to use either of +these, but if you wish to fill in the png_time structure directly, +you should provide the time in universal time (GMT) if possible +instead of your local time. Note that the year number is the full +year (e.g. 1998, rather than 98 - PNG is year 2000 compliant!), and +that months start with 1. + +If you want to store the time of the original image creation, you should +use a plain tEXt chunk with the "Creation Time" keyword. This is +necessary because the "creation time" of a PNG image is somewhat vague, +depending on whether you mean the PNG file, the time the image was +created in a non-PNG format, a still photo from which the image was +scanned, or possibly the subject matter itself. In order to facilitate +machine-readable dates, it is recommended that the "Creation Time" +tEXt chunk use RFC 1123 format dates (e.g. "22 May 1997 18:07:10 GMT"), +although this isn't a requirement. Unlike the tIME chunk, the +"Creation Time" tEXt chunk is not expected to be automatically changed +by the software. To facilitate the use of RFC 1123 dates, a function +png_convert_to_rfc1123(png_timep) is provided to convert from PNG +time to an RFC 1123 format string. + +.SS Writing unknown chunks + +You can use the png_set_unknown_chunks function to queue up chunks +for writing. You give it a chunk name, raw data, and a size; that's +all there is to it. The chunks will be written by the next following +png_write_info_before_PLTE, png_write_info, or png_write_end function. +Any chunks previously read into the info structure's unknown-chunk +list will also be written out in a sequence that satisfies the PNG +specification's ordering rules. + +.SS The high-level write interface + +At this point there are two ways to proceed; through the high-level +write interface, or through a sequence of low-level write operations. +You can use the high-level interface if your image data is present +in the info structure. All defined output +transformations are permitted, enabled by the following masks. + + PNG_TRANSFORM_IDENTITY No transformation + PNG_TRANSFORM_PACKING Pack 1, 2 and 4-bit samples + PNG_TRANSFORM_PACKSWAP Change order of packed + pixels to LSB first + PNG_TRANSFORM_INVERT_MONO Invert monochrome images + PNG_TRANSFORM_SHIFT Normalize pixels to the + sBIT depth + PNG_TRANSFORM_BGR Flip RGB to BGR, RGBA + to BGRA + PNG_TRANSFORM_SWAP_ALPHA Flip RGBA to ARGB or GA + to AG + PNG_TRANSFORM_INVERT_ALPHA Change alpha from opacity + to transparency + PNG_TRANSFORM_SWAP_ENDIAN Byte-swap 16-bit samples + PNG_TRANSFORM_STRIP_FILLER Strip out filler + bytes (deprecated). + PNG_TRANSFORM_STRIP_FILLER_BEFORE Strip out leading + filler bytes + PNG_TRANSFORM_STRIP_FILLER_AFTER Strip out trailing + filler bytes + +If you have valid image data in the info structure (you can use +png_set_rows() to put image data in the info structure), simply do this: + + png_write_png(png_ptr, info_ptr, png_transforms, NULL) + +where png_transforms is an integer containing the bitwise OR of some set of +transformation flags. This call is equivalent to png_write_info(), +followed the set of transformations indicated by the transform mask, +then png_write_image(), and finally png_write_end(). + +(The final parameter of this call is not yet used. Someday it might point +to transformation parameters required by some future output transform.) + +You must use png_transforms and not call any png_set_transform() functions +when you use png_write_png(). + +.SS The low-level write interface + +If you are going the low-level route instead, you are now ready to +write all the file information up to the actual image data. You do +this with a call to png_write_info(). + + png_write_info(png_ptr, info_ptr); + +Note that there is one transformation you may need to do before +png_write_info(). In PNG files, the alpha channel in an image is the +level of opacity. If your data is supplied as a level of transparency, +you can invert the alpha channel before you write it, so that 0 is +fully transparent and 255 (in 8-bit or paletted images) or 65535 +(in 16-bit images) is fully opaque, with + + png_set_invert_alpha(png_ptr); + +This must appear before png_write_info() instead of later with the +other transformations because in the case of paletted images the tRNS +chunk data has to be inverted before the tRNS chunk is written. If +your image is not a paletted image, the tRNS data (which in such cases +represents a single color to be rendered as transparent) won't need to +be changed, and you can safely do this transformation after your +png_write_info() call. + +If you need to write a private chunk that you want to appear before +the PLTE chunk when PLTE is present, you can write the PNG info in +two steps, and insert code to write your own chunk between them: + + png_write_info_before_PLTE(png_ptr, info_ptr); + png_set_unknown_chunks(png_ptr, info_ptr, ...); + png_write_info(png_ptr, info_ptr); + +After you've written the file information, you can set up the library +to handle any special transformations of the image data. The various +ways to transform the data will be described in the order that they +should occur. This is important, as some of these change the color +type and/or bit depth of the data, and some others only work on +certain color types and bit depths. Even though each transformation +checks to see if it has data that it can do something with, you should +make sure to only enable a transformation if it will be valid for the +data. For example, don't swap red and blue on grayscale data. + +PNG files store RGB pixels packed into 3 or 6 bytes. This code tells +the library to strip input data that has 4 or 8 bytes per pixel down +to 3 or 6 bytes (or strip 2 or 4-byte grayscale+filler data to 1 or 2 +bytes per pixel). + + png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE); + +where the 0 is unused, and the location is either PNG_FILLER_BEFORE or +PNG_FILLER_AFTER, depending upon whether the filler byte in the pixel +is stored XRGB or RGBX. + +PNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as +they can, resulting in, for example, 8 pixels per byte for 1 bit files. +If the data is supplied at 1 pixel per byte, use this code, which will +correctly pack the pixels into a single byte: + + png_set_packing(png_ptr); + +PNG files reduce possible bit depths to 1, 2, 4, 8, and 16. If your +data is of another bit depth, you can write an sBIT chunk into the +file so that decoders can recover the original data if desired. + + /* Set the true bit depth of the image data */ + if (color_type & PNG_COLOR_MASK_COLOR) + { + sig_bit.red = true_bit_depth; + sig_bit.green = true_bit_depth; + sig_bit.blue = true_bit_depth; + } + else + { + sig_bit.gray = true_bit_depth; + } + if (color_type & PNG_COLOR_MASK_ALPHA) + { + sig_bit.alpha = true_bit_depth; + } + + png_set_sBIT(png_ptr, info_ptr, &sig_bit); + +If the data is stored in the row buffer in a bit depth other than +one supported by PNG (e.g. 3 bit data in the range 0-7 for a 4-bit PNG), +this will scale the values to appear to be the correct bit depth as +is required by PNG. + + png_set_shift(png_ptr, &sig_bit); + +PNG files store 16 bit pixels in network byte order (big-endian, +ie. most significant bits first). This code would be used if they are +supplied the other way (little-endian, i.e. least significant bits +first, the way PCs store them): + + if (bit_depth > 8) + png_set_swap(png_ptr); + +If you are using packed-pixel images (1, 2, or 4 bits/pixel), and you +need to change the order the pixels are packed into bytes, you can use: + + if (bit_depth < 8) + png_set_packswap(png_ptr); + +PNG files store 3 color pixels in red, green, blue order. This code +would be used if they are supplied as blue, green, red: + + png_set_bgr(png_ptr); + +PNG files describe monochrome as black being zero and white being +one. This code would be used if the pixels are supplied with this reversed +(black being one and white being zero): + + png_set_invert_mono(png_ptr); + +Finally, you can write your own transformation function if none of +the existing ones meets your needs. This is done by setting a callback +with + + png_set_write_user_transform_fn(png_ptr, + write_transform_fn); + +You must supply the function + + void write_transform_fn(png_ptr ptr, row_info_ptr + row_info, png_bytep data) + +See pngtest.c for a working example. Your function will be called +before any of the other transformations are processed. + +You can also set up a pointer to a user structure for use by your +callback function. + + png_set_user_transform_info(png_ptr, user_ptr, 0, 0); + +The user_channels and user_depth parameters of this function are ignored +when writing; you can set them to zero as shown. + +You can retrieve the pointer via the function png_get_user_transform_ptr(). +For example: + + voidp write_user_transform_ptr = + png_get_user_transform_ptr(png_ptr); + +It is possible to have libpng flush any pending output, either manually, +or automatically after a certain number of lines have been written. To +flush the output stream a single time call: + + png_write_flush(png_ptr); + +and to have libpng flush the output stream periodically after a certain +number of scanlines have been written, call: + + png_set_flush(png_ptr, nrows); + +Note that the distance between rows is from the last time png_write_flush() +was called, or the first row of the image if it has never been called. +So if you write 50 lines, and then png_set_flush 25, it will flush the +output on the next scanline, and every 25 lines thereafter, unless +png_write_flush() is called before 25 more lines have been written. +If nrows is too small (less than about 10 lines for a 640 pixel wide +RGB image) the image compression may decrease noticeably (although this +may be acceptable for real-time applications). Infrequent flushing will +only degrade the compression performance by a few percent over images +that do not use flushing. + +.SS Writing the image data + +That's it for the transformations. Now you can write the image data. +The simplest way to do this is in one function call. If you have the +whole image in memory, you can just call png_write_image() and libpng +will write the image. You will need to pass in an array of pointers to +each row. This function automatically handles interlacing, so you don't +need to call png_set_interlace_handling() or call this function multiple +times, or any of that other stuff necessary with png_write_rows(). + + png_write_image(png_ptr, row_pointers); + +where row_pointers is: + + png_byte *row_pointers[height]; + +You can point to void or char or whatever you use for pixels. + +If you don't want to write the whole image at once, you can +use png_write_rows() instead. If the file is not interlaced, +this is simple: + + png_write_rows(png_ptr, row_pointers, + number_of_rows); + +row_pointers is the same as in the png_write_image() call. + +If you are just writing one row at a time, you can do this with +a single row_pointer instead of an array of row_pointers: + + png_bytep row_pointer = row; + + png_write_row(png_ptr, row_pointer); + +When the file is interlaced, things can get a good deal more complicated. +The only currently (as of the PNG Specification version 1.2, dated July +1999) defined interlacing scheme for PNG files is the "Adam7" interlace +scheme, that breaks down an image into seven smaller images of varying +size. libpng will build these images for you, or you can do them +yourself. If you want to build them yourself, see the PNG specification +for details of which pixels to write when. + +If you don't want libpng to handle the interlacing details, just +use png_set_interlace_handling() and call png_write_rows() the +correct number of times to write all seven sub-images. + +If you want libpng to build the sub-images, call this before you start +writing any rows: + + number_of_passes = + png_set_interlace_handling(png_ptr); + +This will return the number of passes needed. Currently, this is seven, +but may change if another interlace type is added. + +Then write the complete image number_of_passes times. + + png_write_rows(png_ptr, row_pointers, + number_of_rows); + +As some of these rows are not used, and thus return immediately, you may +want to read about interlacing in the PNG specification, and only update +the rows that are actually used. + +.SS Finishing a sequential write + +After you are finished writing the image, you should finish writing +the file. If you are interested in writing comments or time, you should +pass an appropriately filled png_info pointer. If you are not interested, +you can pass NULL. + + png_write_end(png_ptr, info_ptr); + +When you are done, you can free all memory used by libpng like this: + + png_destroy_write_struct(&png_ptr, &info_ptr); + +It is also possible to individually free the info_ptr members that +point to libpng-allocated storage with the following function: + + png_free_data(png_ptr, info_ptr, mask, seq) + mask - identifies data to be freed, a mask + containing the bitwise OR of one or + more of + PNG_FREE_PLTE, PNG_FREE_TRNS, + PNG_FREE_HIST, PNG_FREE_ICCP, + PNG_FREE_PCAL, PNG_FREE_ROWS, + PNG_FREE_SCAL, PNG_FREE_SPLT, + PNG_FREE_TEXT, PNG_FREE_UNKN, + or simply PNG_FREE_ALL + seq - sequence number of item to be freed + (-1 for all items) + +This function may be safely called when the relevant storage has +already been freed, or has not yet been allocated, or was allocated +by the user and not by libpng, and will in those cases do nothing. +The "seq" parameter is ignored if only one item of the selected data +type, such as PLTE, is allowed. If "seq" is not -1, and multiple items +are allowed for the data type identified in the mask, such as text or +sPLT, only the n'th item in the structure is freed, where n is "seq". + +If you allocated data such as a palette that you passed in to libpng +with png_set_*, you must not free it until just before the call to +png_destroy_write_struct(). + +The default behavior is only to free data that was allocated internally +by libpng. This can be changed, so that libpng will not free the data, +or so that it will free data that was allocated by the user with png_malloc() +or png_zalloc() and passed in via a png_set_*() function, with + + png_data_freer(png_ptr, info_ptr, freer, mask) + mask - which data elements are affected + same choices as in png_free_data() + freer - one of + PNG_DESTROY_WILL_FREE_DATA + PNG_SET_WILL_FREE_DATA + PNG_USER_WILL_FREE_DATA + +For example, to transfer responsibility for some data from a read structure +to a write structure, you could use + + png_data_freer(read_ptr, read_info_ptr, + PNG_USER_WILL_FREE_DATA, + PNG_FREE_PLTE|PNG_FREE_tRNS|PNG_FREE_hIST) + png_data_freer(write_ptr, write_info_ptr, + PNG_DESTROY_WILL_FREE_DATA, + PNG_FREE_PLTE|PNG_FREE_tRNS|PNG_FREE_hIST) + +thereby briefly reassigning responsibility for freeing to the user but +immediately afterwards reassigning it once more to the write_destroy +function. Having done this, it would then be safe to destroy the read +structure and continue to use the PLTE, tRNS, and hIST data in the write +structure. + +This function only affects data that has already been allocated. +You can call this function before calling after the png_set_*() functions +to control whether the user or png_destroy_*() is supposed to free the data. +When the user assumes responsibility for libpng-allocated data, the +application must use +png_free() to free it, and when the user transfers responsibility to libpng +for data that the user has allocated, the user must have used png_malloc() +or png_zalloc() to allocate it. + +If you allocated text_ptr.text, text_ptr.lang, and text_ptr.translated_keyword +separately, do not transfer responsibility for freeing text_ptr to libpng, +because when libpng fills a png_text structure it combines these members with +the key member, and png_free_data() will free only text_ptr.key. Similarly, +if you transfer responsibility for free'ing text_ptr from libpng to your +application, your application must not separately free those members. +For a more compact example of writing a PNG image, see the file example.c. + +.SH V. Modifying/Customizing libpng: + +There are two issues here. The first is changing how libpng does +standard things like memory allocation, input/output, and error handling. +The second deals with more complicated things like adding new chunks, +adding new transformations, and generally changing how libpng works. +Both of those are compile-time issues; that is, they are generally +determined at the time the code is written, and there is rarely a need +to provide the user with a means of changing them. + +Memory allocation, input/output, and error handling + +All of the memory allocation, input/output, and error handling in libpng +goes through callbacks that are user-settable. The default routines are +in pngmem.c, pngrio.c, pngwio.c, and pngerror.c, respectively. To change +these functions, call the appropriate png_set_*_fn() function. + +Memory allocation is done through the functions png_malloc(), png_calloc(), +and png_free(). These currently just call the standard C functions. +png_calloc() calls png_malloc() and then png_memset() to clear the newly +allocated memory to zero. If your pointers can't access more then 64K +at a time, you will want to set MAXSEG_64K in zlib.h. Since it is +unlikely that the method of handling memory allocation on a platform +will change between applications, these functions must be modified in +the library at compile time. If you prefer to use a different method +of allocating and freeing data, you can use png_create_read_struct_2() or +png_create_write_struct_2() to register your own functions as described +above. These functions also provide a void pointer that can be retrieved +via + + mem_ptr=png_get_mem_ptr(png_ptr); + +Your replacement memory functions must have prototypes as follows: + + png_voidp malloc_fn(png_structp png_ptr, + png_size_t size); + void free_fn(png_structp png_ptr, png_voidp ptr); + +Your malloc_fn() must return NULL in case of failure. The png_malloc() +function will normally call png_error() if it receives a NULL from the +system memory allocator or from your replacement malloc_fn(). + +Your free_fn() will never be called with a NULL ptr, since libpng's +png_free() checks for NULL before calling free_fn(). + +Input/Output in libpng is done through png_read() and png_write(), +which currently just call fread() and fwrite(). The FILE * is stored in +png_struct and is initialized via png_init_io(). If you wish to change +the method of I/O, the library supplies callbacks that you can set +through the function png_set_read_fn() and png_set_write_fn() at run +time, instead of calling the png_init_io() function. These functions +also provide a void pointer that can be retrieved via the function +png_get_io_ptr(). For example: + + png_set_read_fn(png_structp read_ptr, + voidp read_io_ptr, png_rw_ptr read_data_fn) + + png_set_write_fn(png_structp write_ptr, + voidp write_io_ptr, png_rw_ptr write_data_fn, + png_flush_ptr output_flush_fn); + + voidp read_io_ptr = png_get_io_ptr(read_ptr); + voidp write_io_ptr = png_get_io_ptr(write_ptr); + +The replacement I/O functions must have prototypes as follows: + + void user_read_data(png_structp png_ptr, + png_bytep data, png_size_t length); + void user_write_data(png_structp png_ptr, + png_bytep data, png_size_t length); + void user_flush_data(png_structp png_ptr); + +The user_read_data() function is responsible for detecting and +handling end-of-data errors. + +Supplying NULL for the read, write, or flush functions sets them back +to using the default C stream functions, which expect the io_ptr to +point to a standard *FILE structure. It is probably a mistake +to use NULL for one of write_data_fn and output_flush_fn but not both +of them, unless you have built libpng with PNG_NO_WRITE_FLUSH defined. +It is an error to read from a write stream, and vice versa. + +Error handling in libpng is done through png_error() and png_warning(). +Errors handled through png_error() are fatal, meaning that png_error() +should never return to its caller. Currently, this is handled via +setjmp() and longjmp() (unless you have compiled libpng with +PNG_SETJMP_NOT_SUPPORTED, in which case it is handled via PNG_ABORT()), +but you could change this to do things like exit() if you should wish. + +On non-fatal errors, png_warning() is called +to print a warning message, and then control returns to the calling code. +By default png_error() and png_warning() print a message on stderr via +fprintf() unless the library is compiled with PNG_NO_CONSOLE_IO defined +(because you don't want the messages) or PNG_NO_STDIO defined (because +fprintf() isn't available). If you wish to change the behavior of the error +functions, you will need to set up your own message callbacks. These +functions are normally supplied at the time that the png_struct is created. +It is also possible to redirect errors and warnings to your own replacement +functions after png_create_*_struct() has been called by calling: + + png_set_error_fn(png_structp png_ptr, + png_voidp error_ptr, png_error_ptr error_fn, + png_error_ptr warning_fn); + + png_voidp error_ptr = png_get_error_ptr(png_ptr); + +If NULL is supplied for either error_fn or warning_fn, then the libpng +default function will be used, calling fprintf() and/or longjmp() if a +problem is encountered. The replacement error functions should have +parameters as follows: + + void user_error_fn(png_structp png_ptr, + png_const_charp error_msg); + void user_warning_fn(png_structp png_ptr, + png_const_charp warning_msg); + +The motivation behind using setjmp() and longjmp() is the C++ throw and +catch exception handling methods. This makes the code much easier to write, +as there is no need to check every return code of every function call. +However, there are some uncertainties about the status of local variables +after a longjmp, so the user may want to be careful about doing anything +after setjmp returns non-zero besides returning itself. Consult your +compiler documentation for more details. For an alternative approach, you +may wish to use the "cexcept" facility (see http://cexcept.sourceforge.net). + +.SS Custom chunks + +If you need to read or write custom chunks, you may need to get deeper +into the libpng code. The library now has mechanisms for storing +and writing chunks of unknown type; you can even declare callbacks +for custom chunks. However, this may not be good enough if the +library code itself needs to know about interactions between your +chunk and existing `intrinsic' chunks. + +If you need to write a new intrinsic chunk, first read the PNG +specification. Acquire a first level of understanding of how it works. +Pay particular attention to the sections that describe chunk names, +and look at how other chunks were designed, so you can do things +similarly. Second, check out the sections of libpng that read and +write chunks. Try to find a chunk that is similar to yours and use +it as a template. More details can be found in the comments inside +the code. It is best to handle unknown chunks in a generic method, +via callback functions, instead of by modifying libpng functions. + +If you wish to write your own transformation for the data, look through +the part of the code that does the transformations, and check out some of +the simpler ones to get an idea of how they work. Try to find a similar +transformation to the one you want to add and copy off of it. More details +can be found in the comments inside the code itself. + +.SS Configuring for 16 bit platforms + +You will want to look into zconf.h to tell zlib (and thus libpng) that +it cannot allocate more then 64K at a time. Even if you can, the memory +won't be accessible. So limit zlib and libpng to 64K by defining MAXSEG_64K. + +.SS Configuring for DOS + +For DOS users who only have access to the lower 640K, you will +have to limit zlib's memory usage via a png_set_compression_mem_level() +call. See zlib.h or zconf.h in the zlib library for more information. + +.SS Configuring for Medium Model + +Libpng's support for medium model has been tested on most of the popular +compilers. Make sure MAXSEG_64K gets defined, USE_FAR_KEYWORD gets +defined, and FAR gets defined to far in pngconf.h, and you should be +all set. Everything in the library (except for zlib's structure) is +expecting far data. You must use the typedefs with the p or pp on +the end for pointers (or at least look at them and be careful). Make +note that the rows of data are defined as png_bytepp, which is an +unsigned char far * far *. + +.SS Configuring for gui/windowing platforms: + +You will need to write new error and warning functions that use the GUI +interface, as described previously, and set them to be the error and +warning functions at the time that png_create_*_struct() is called, +in order to have them available during the structure initialization. +They can be changed later via png_set_error_fn(). On some compilers, +you may also have to change the memory allocators (png_malloc, etc.). + +.SS Configuring for compiler xxx: + +All includes for libpng are in pngconf.h. If you need to add, change +or delete an include, this is the place to do it. +The includes that are not needed outside libpng are protected by the +PNG_INTERNAL definition, which is only defined for those routines inside +libpng itself. The files in libpng proper only include png.h, which +includes pngconf.h. + +.SS Configuring zlib: + +There are special functions to configure the compression. Perhaps the +most useful one changes the compression level, which currently uses +input compression values in the range 0 - 9. The library normally +uses the default compression level (Z_DEFAULT_COMPRESSION = 6). Tests +have shown that for a large majority of images, compression values in +the range 3-6 compress nearly as well as higher levels, and do so much +faster. For online applications it may be desirable to have maximum speed +(Z_BEST_SPEED = 1). With versions of zlib after v0.99, you can also +specify no compression (Z_NO_COMPRESSION = 0), but this would create +files larger than just storing the raw bitmap. You can specify the +compression level by calling: + + png_set_compression_level(png_ptr, level); + +Another useful one is to reduce the memory level used by the library. +The memory level defaults to 8, but it can be lowered if you are +short on memory (running DOS, for example, where you only have 640K). +Note that the memory level does have an effect on compression; among +other things, lower levels will result in sections of incompressible +data being emitted in smaller stored blocks, with a correspondingly +larger relative overhead of up to 15% in the worst case. + + png_set_compression_mem_level(png_ptr, level); + +The other functions are for configuring zlib. They are not recommended +for normal use and may result in writing an invalid PNG file. See +zlib.h for more information on what these mean. + + png_set_compression_strategy(png_ptr, + strategy); + png_set_compression_window_bits(png_ptr, + window_bits); + png_set_compression_method(png_ptr, method); + png_set_compression_buffer_size(png_ptr, size); + +.SS Controlling row filtering + +If you want to control whether libpng uses filtering or not, which +filters are used, and how it goes about picking row filters, you +can call one of these functions. The selection and configuration +of row filters can have a significant impact on the size and +encoding speed and a somewhat lesser impact on the decoding speed +of an image. Filtering is enabled by default for RGB and grayscale +images (with and without alpha), but not for paletted images nor +for any images with bit depths less than 8 bits/pixel. + +The 'method' parameter sets the main filtering method, which is +currently only '0' in the PNG 1.2 specification. The 'filters' +parameter sets which filter(s), if any, should be used for each +scanline. Possible values are PNG_ALL_FILTERS and PNG_NO_FILTERS +to turn filtering on and off, respectively. + +Individual filter types are PNG_FILTER_NONE, PNG_FILTER_SUB, +PNG_FILTER_UP, PNG_FILTER_AVG, PNG_FILTER_PAETH, which can be bitwise +ORed together with '|' to specify one or more filters to use. +These filters are described in more detail in the PNG specification. +If you intend to change the filter type during the course of writing +the image, you should start with flags set for all of the filters +you intend to use so that libpng can initialize its internal +structures appropriately for all of the filter types. (Note that this +means the first row must always be adaptively filtered, because libpng +currently does not allocate the filter buffers until png_write_row() +is called for the first time.) + + filters = PNG_FILTER_NONE | PNG_FILTER_SUB + PNG_FILTER_UP | PNG_FILTER_AVG | + PNG_FILTER_PAETH | PNG_ALL_FILTERS; + + png_set_filter(png_ptr, PNG_FILTER_TYPE_BASE, + filters); + The second parameter can also be + PNG_INTRAPIXEL_DIFFERENCING if you are + writing a PNG to be embedded in a MNG + datastream. This parameter must be the + same as the value of filter_method used + in png_set_IHDR(). + +It is also possible to influence how libpng chooses from among the +available filters. This is done in one or both of two ways - by +telling it how important it is to keep the same filter for successive +rows, and by telling it the relative computational costs of the filters. + + double weights[3] = {1.5, 1.3, 1.1}, + costs[PNG_FILTER_VALUE_LAST] = + {1.0, 1.3, 1.3, 1.5, 1.7}; + + png_set_filter_heuristics(png_ptr, + PNG_FILTER_HEURISTIC_WEIGHTED, 3, + weights, costs); + +The weights are multiplying factors that indicate to libpng that the +row filter should be the same for successive rows unless another row filter +is that many times better than the previous filter. In the above example, +if the previous 3 filters were SUB, SUB, NONE, the SUB filter could have a +"sum of absolute differences" 1.5 x 1.3 times higher than other filters +and still be chosen, while the NONE filter could have a sum 1.1 times +higher than other filters and still be chosen. Unspecified weights are +taken to be 1.0, and the specified weights should probably be declining +like those above in order to emphasize recent filters over older filters. + +The filter costs specify for each filter type a relative decoding cost +to be considered when selecting row filters. This means that filters +with higher costs are less likely to be chosen over filters with lower +costs, unless their "sum of absolute differences" is that much smaller. +The costs do not necessarily reflect the exact computational speeds of +the various filters, since this would unduly influence the final image +size. + +Note that the numbers above were invented purely for this example and +are given only to help explain the function usage. Little testing has +been done to find optimum values for either the costs or the weights. + +.SS Removing unwanted object code + +There are a bunch of #define's in pngconf.h that control what parts of +libpng are compiled. All the defines end in _SUPPORTED. If you are +never going to use a capability, you can change the #define to #undef +before recompiling libpng and save yourself code and data space, or +you can turn off individual capabilities with defines that begin with +PNG_NO_. + +You can also turn all of the transforms and ancillary chunk capabilities +off en masse with compiler directives that define +PNG_NO_READ[or WRITE]_TRANSFORMS, or PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS, +or all four, +along with directives to turn on any of the capabilities that you do +want. The PNG_NO_READ[or WRITE]_TRANSFORMS directives disable the extra +transformations but still leave the library fully capable of reading +and writing PNG files with all known public chunks. Use of the +PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS directive produces a library +that is incapable of reading or writing ancillary chunks. If you are +not using the progressive reading capability, you can turn that off +with PNG_NO_PROGRESSIVE_READ (don't confuse this with the INTERLACING +capability, which you'll still have). + +All the reading and writing specific code are in separate files, so the +linker should only grab the files it needs. However, if you want to +make sure, or if you are building a stand alone library, all the +reading files start with pngr and all the writing files start with +pngw. The files that don't match either (like png.c, pngtrans.c, etc.) +are used for both reading and writing, and always need to be included. +The progressive reader is in pngpread.c + +If you are creating or distributing a dynamically linked library (a .so +or DLL file), you should not remove or disable any parts of the library, +as this will cause applications linked with different versions of the +library to fail if they call functions not available in your library. +The size of the library itself should not be an issue, because only +those sections that are actually used will be loaded into memory. + +.SS Requesting debug printout + +The macro definition PNG_DEBUG can be used to request debugging +printout. Set it to an integer value in the range 0 to 3. Higher +numbers result in increasing amounts of debugging information. The +information is printed to the "stderr" file, unless another file +name is specified in the PNG_DEBUG_FILE macro definition. + +When PNG_DEBUG > 0, the following functions (macros) become available: + + png_debug(level, message) + png_debug1(level, message, p1) + png_debug2(level, message, p1, p2) + +in which "level" is compared to PNG_DEBUG to decide whether to print +the message, "message" is the formatted string to be printed, +and p1 and p2 are parameters that are to be embedded in the string +according to printf-style formatting directives. For example, + + png_debug1(2, "foo=%d\n", foo); + +is expanded to + + if(PNG_DEBUG > 2) + fprintf(PNG_DEBUG_FILE, "foo=%d\n", foo); + +When PNG_DEBUG is defined but is zero, the macros aren't defined, but you +can still use PNG_DEBUG to control your own debugging: + + #ifdef PNG_DEBUG + fprintf(stderr, ... + #endif + +When PNG_DEBUG = 1, the macros are defined, but only png_debug statements +having level = 0 will be printed. There aren't any such statements in +this version of libpng, but if you insert some they will be printed. + +.SH VI. MNG support + +The MNG specification (available at http://www.libpng.org/pub/mng) allows +certain extensions to PNG for PNG images that are embedded in MNG datastreams. +Libpng can support some of these extensions. To enable them, use the +png_permit_mng_features() function: + + feature_set = png_permit_mng_features(png_ptr, mask) + mask is a png_uint_32 containing the bitwise OR of the + features you want to enable. These include + PNG_FLAG_MNG_EMPTY_PLTE + PNG_FLAG_MNG_FILTER_64 + PNG_ALL_MNG_FEATURES + feature_set is a png_uint_32 that is the bitwise AND of + your mask with the set of MNG features that is + supported by the version of libpng that you are using. + +It is an error to use this function when reading or writing a standalone +PNG file with the PNG 8-byte signature. The PNG datastream must be wrapped +in a MNG datastream. As a minimum, it must have the MNG 8-byte signature +and the MHDR and MEND chunks. Libpng does not provide support for these +or any other MNG chunks; your application must provide its own support for +them. You may wish to consider using libmng (available at +http://www.libmng.com) instead. + +.SH VII. Changes to Libpng from version 0.88 + +It should be noted that versions of libpng later than 0.96 are not +distributed by the original libpng author, Guy Schalnat, nor by +Andreas Dilger, who had taken over from Guy during 1996 and 1997, and +distributed versions 0.89 through 0.96, but rather by another member +of the original PNG Group, Glenn Randers-Pehrson. Guy and Andreas are +still alive and well, but they have moved on to other things. + +The old libpng functions png_read_init(), png_write_init(), +png_info_init(), png_read_destroy(), and png_write_destroy() have been +moved to PNG_INTERNAL in version 0.95 to discourage their use. These +functions will be removed from libpng version 2.0.0. + +The preferred method of creating and initializing the libpng structures is +via the png_create_read_struct(), png_create_write_struct(), and +png_create_info_struct() because they isolate the size of the structures +from the application, allow version error checking, and also allow the +use of custom error handling routines during the initialization, which +the old functions do not. The functions png_read_destroy() and +png_write_destroy() do not actually free the memory that libpng +allocated for these structs, but just reset the data structures, so they +can be used instead of png_destroy_read_struct() and +png_destroy_write_struct() if you feel there is too much system overhead +allocating and freeing the png_struct for each image read. + +Setting the error callbacks via png_set_message_fn() before +png_read_init() as was suggested in libpng-0.88 is no longer supported +because this caused applications that do not use custom error functions +to fail if the png_ptr was not initialized to zero. It is still possible +to set the error callbacks AFTER png_read_init(), or to change them with +png_set_error_fn(), which is essentially the same function, but with a new +name to force compilation errors with applications that try to use the old +method. + +Starting with version 1.0.7, you can find out which version of the library +you are using at run-time: + + png_uint_32 libpng_vn = png_access_version_number(); + +The number libpng_vn is constructed from the major version, minor +version with leading zero, and release number with leading zero, +(e.g., libpng_vn for version 1.0.7 is 10007). + +You can also check which version of png.h you used when compiling your +application: + + png_uint_32 application_vn = PNG_LIBPNG_VER; + +.SH VIII. Changes to Libpng from version 1.0.x to 1.2.x + +Support for user memory management was enabled by default. To +accomplish this, the functions png_create_read_struct_2(), +png_create_write_struct_2(), png_set_mem_fn(), png_get_mem_ptr(), +png_malloc_default(), and png_free_default() were added. + +Support for the iTXt chunk has been enabled by default as of +version 1.2.41. + +Support for certain MNG features was enabled. + +Support for numbered error messages was added. However, we never got +around to actually numbering the error messages. The function +png_set_strip_error_numbers() was added (Note: the prototype for this +function was inadvertently removed from png.h in PNG_NO_ASSEMBLER_CODE +builds of libpng-1.2.15. It was restored in libpng-1.2.36). + +The png_malloc_warn() function was added at libpng-1.2.3. This issues +a png_warning and returns NULL instead of aborting when it fails to +acquire the requested memory allocation. + +Support for setting user limits on image width and height was enabled +by default. The functions png_set_user_limits(), png_get_user_width_max(), +and png_get_user_height_max() were added at libpng-1.2.6. + +The png_set_add_alpha() function was added at libpng-1.2.7. + +The function png_set_expand_gray_1_2_4_to_8() was added at libpng-1.2.9. +Unlike png_set_gray_1_2_4_to_8(), the new function does not expand the +tRNS chunk to alpha. The png_set_gray_1_2_4_to_8() function is +deprecated. + +A number of macro definitions in support of runtime selection of +assembler code features (especially Intel MMX code support) were +added at libpng-1.2.0: + + PNG_ASM_FLAG_MMX_SUPPORT_COMPILED + PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU + PNG_ASM_FLAG_MMX_READ_COMBINE_ROW + PNG_ASM_FLAG_MMX_READ_INTERLACE + PNG_ASM_FLAG_MMX_READ_FILTER_SUB + PNG_ASM_FLAG_MMX_READ_FILTER_UP + PNG_ASM_FLAG_MMX_READ_FILTER_AVG + PNG_ASM_FLAG_MMX_READ_FILTER_PAETH + PNG_ASM_FLAGS_INITIALIZED + PNG_MMX_READ_FLAGS + PNG_MMX_FLAGS + PNG_MMX_WRITE_FLAGS + PNG_MMX_FLAGS + +We added the following functions in support of runtime +selection of assembler code features: + + png_get_mmx_flagmask() + png_set_mmx_thresholds() + png_get_asm_flags() + png_get_mmx_bitdepth_threshold() + png_get_mmx_rowbytes_threshold() + png_set_asm_flags() + +We replaced all of these functions with simple stubs in libpng-1.2.20, +when the Intel assembler code was removed due to a licensing issue. + +These macros are deprecated: + + PNG_READ_TRANSFORMS_NOT_SUPPORTED + PNG_PROGRESSIVE_READ_NOT_SUPPORTED + PNG_NO_SEQUENTIAL_READ_SUPPORTED + PNG_WRITE_TRANSFORMS_NOT_SUPPORTED + PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED + PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED + +They have been replaced, respectively, by: + + PNG_NO_READ_TRANSFORMS + PNG_NO_PROGRESSIVE_READ + PNG_NO_SEQUENTIAL_READ + PNG_NO_WRITE_TRANSFORMS + PNG_NO_READ_ANCILLARY_CHUNKS + PNG_NO_WRITE_ANCILLARY_CHUNKS + +PNG_MAX_UINT was replaced with PNG_UINT_31_MAX. It has been +deprecated since libpng-1.0.16 and libpng-1.2.6. + +The function + png_check_sig(sig, num) +was replaced with + !png_sig_cmp(sig, 0, num) +It has been deprecated since libpng-0.90. + +The function + png_set_gray_1_2_4_to_8() +which also expands tRNS to alpha was replaced with + png_set_expand_gray_1_2_4_to_8() +which does not. It has been deprecated since libpng-1.0.18 and 1.2.9. + +.SH IX. (Omitted) + + +.SH X. Detecting libpng + +The png_get_io_ptr() function has been present since libpng-0.88, has never +changed, and is unaffected by conditional compilation macros. It is the +best choice for use in configure scripts for detecting the presence of any +libpng version since 0.88. In an autoconf "configure.in" you could use + + AC_CHECK_LIB(png, png_get_io_ptr, ... + +.SH XI. Source code repository + +Since about February 2009, version 1.2.34, libpng has been under "git" source +control. The git repository was built from old libpng-x.y.z.tar.gz files +going back to version 0.70. You can access the git repository (read only) +at + + git://libpng.git.sourceforge.net/gitroot/libpng + +or you can browse it via "gitweb" at + + http://libpng.git.sourceforge.net/git/gitweb.cgi?p=libpng + +Patches can be sent to glennrp at users.sourceforge.net or to +png-mng-implement at lists.sourceforge.net or you can upload them to +the libpng bug tracker at + + http://libpng.sourceforge.net + +.SH XII. Coding style + +Our coding style is similar to the "Allman" style, with curly +braces on separate lines: + + if (condition) + { + action; + } + + else if (another condition) + { + another action; + } + +The braces can be omitted from simple one-line actions: + + if (condition) + return (0); + +We use 3-space indentation, except for continued statements which +are usually indented the same as the first line of the statement +plus four more spaces. + +For macro definitions we use 2-space indentation, always leaving the "#" +in the first column. + + #ifndef PNG_NO_FEATURE + # ifndef PNG_FEATURE_SUPPORTED + # define PNG_FEATURE_SUPPORTED + # endif + #endif + +Comments appear with the leading "/*" at the same indentation as +the statement that follows the comment: + + /* Single-line comment */ + statement; + + /* Multiple-line + * comment + */ + statement; + +Very short comments can be placed at the end of the statement +to which they pertain: + + statement; /* comment */ + +We don't use C++ style ("//") comments. We have, however, +used them in the past in some now-abandoned MMX assembler +code. + +Functions and their curly braces are not indented, and +exported functions are marked with PNGAPI: + + /* This is a public function that is visible to + * application programers. It does thus-and-so. + */ + void PNGAPI + png_exported_function(png_ptr, png_info, foo) + { + body; + } + +The prototypes for all exported functions appear in png.h, +above the comment that says + + /* Maintainer: Put new public prototypes here ... */ + +We mark all non-exported functions with "/* PRIVATE */"": + + void /* PRIVATE */ + png_non_exported_function(png_ptr, png_info, foo) + { + body; + } + +The prototypes for non-exported functions (except for those in +pngtest) appear in +the PNG_INTERNAL section of png.h +above the comment that says + + /* Maintainer: Put new private prototypes here ^ and in libpngpf.3 */ + +The names of all exported functions and variables begin +with "png_", and all publicly visible C preprocessor +macros begin with "PNG_". + +We put a space after each comma and after each semicolon +in "for" statments, and we put spaces before and after each +C binary operator and after "for" or "while". We don't +put a space between a typecast and the expression being +cast, nor do we put one between a function name and the +left parenthesis that follows it: + + for (i = 2; i > 0; --i) + y[i] = a(x) + (int)b; + +We prefer #ifdef and #ifndef to #if defined() and if !defined() +when there is only one macro being tested. + +We do not use the TAB character for indentation in the C sources. + +Lines do not exceed 80 characters. + +Other rules can be inferred by inspecting the libpng source. + +.SH XIII. Y2K Compliance in libpng + +July 9, 2011 + +Since the PNG Development group is an ad-hoc body, we can't make +an official declaration. + +This is your unofficial assurance that libpng from version 0.71 and +upward through 1.2.46 are Y2K compliant. It is my belief that earlier +versions were also Y2K compliant. + +Libpng only has three year fields. One is a 2-byte unsigned integer that +will hold years up to 65535. The other two hold the date in text +format, and will hold years up to 9999. + +The integer is + "png_uint_16 year" in png_time_struct. + +The strings are + "png_charp time_buffer" in png_struct and + "near_time_buffer", which is a local character string in png.c. + +There are seven time-related functions: + + png_convert_to_rfc_1123() in png.c + (formerly png_convert_to_rfc_1152() in error) + png_convert_from_struct_tm() in pngwrite.c, called + in pngwrite.c + png_convert_from_time_t() in pngwrite.c + png_get_tIME() in pngget.c + png_handle_tIME() in pngrutil.c, called in pngread.c + png_set_tIME() in pngset.c + png_write_tIME() in pngwutil.c, called in pngwrite.c + +All appear to handle dates properly in a Y2K environment. The +png_convert_from_time_t() function calls gmtime() to convert from system +clock time, which returns (year - 1900), which we properly convert to +the full 4-digit year. There is a possibility that applications using +libpng are not passing 4-digit years into the png_convert_to_rfc_1123() +function, or that they are incorrectly passing only a 2-digit year +instead of "year - 1900" into the png_convert_from_struct_tm() function, +but this is not under our control. The libpng documentation has always +stated that it works with 4-digit years, and the APIs have been +documented as such. + +The tIME chunk itself is also Y2K compliant. It uses a 2-byte unsigned +integer to hold the year, and can hold years as large as 65535. + +zlib, upon which libpng depends, is also Y2K compliant. It contains +no date-related code. + + + Glenn Randers-Pehrson + libpng maintainer + PNG Development Group + +.SH NOTE + +Note about libpng version numbers: + +Due to various miscommunications, unforeseen code incompatibilities +and occasional factors outside the authors' control, version numbering +on the library has not always been consistent and straightforward. +The following table summarizes matters since version 0.89c, which was +the first widely used release: + + source png.h png.h shared-lib + version string int version + ------- ------ ----- ---------- + 0.89c ("beta 3") 0.89 89 1.0.89 + 0.90 ("beta 4") 0.90 90 0.90 + 0.95 ("beta 5") 0.95 95 0.95 + 0.96 ("beta 6") 0.96 96 0.96 + 0.97b ("beta 7") 1.00.97 97 1.0.1 + 0.97c 0.97 97 2.0.97 + 0.98 0.98 98 2.0.98 + 0.99 0.99 98 2.0.99 + 0.99a-m 0.99 99 2.0.99 + 1.00 1.00 100 2.1.0 + 1.0.0 1.0.0 100 2.1.0 + 1.0.0 (from here on, the 100 2.1.0 + 1.0.1 png.h string is 10001 2.1.0 + 1.0.1a-e identical to the 10002 from here on, the + 1.0.2 source version) 10002 shared library is 2.V + 1.0.2a-b 10003 where V is the source + 1.0.1 10001 code version except as + 1.0.1a-e 10002 2.1.0.1a-e noted. + 1.0.2 10002 2.1.0.2 + 1.0.2a-b 10003 2.1.0.2a-b + 1.0.3 10003 2.1.0.3 + 1.0.3a-d 10004 2.1.0.3a-d + 1.0.4 10004 2.1.0.4 + 1.0.4a-f 10005 2.1.0.4a-f + 1.0.5 (+ 2 patches) 10005 2.1.0.5 + 1.0.5a-d 10006 2.1.0.5a-d + 1.0.5e-r 10100 2.1.0.5e-r + 1.0.5s-v 10006 2.1.0.5s-v + 1.0.6 (+ 3 patches) 10006 2.1.0.6 + 1.0.6d-g 10007 2.1.0.6d-g + 1.0.6h 10007 10.6h + 1.0.6i 10007 10.6i + 1.0.6j 10007 2.1.0.6j + 1.0.7beta11-14 DLLNUM 10007 2.1.0.7beta11-14 + 1.0.7beta15-18 1 10007 2.1.0.7beta15-18 + 1.0.7rc1-2 1 10007 2.1.0.7rc1-2 + 1.0.7 1 10007 2.1.0.7 + 1.0.8beta1-4 1 10008 2.1.0.8beta1-4 + 1.0.8rc1 1 10008 2.1.0.8rc1 + 1.0.8 1 10008 2.1.0.8 + 1.0.9beta1-6 1 10009 2.1.0.9beta1-6 + 1.0.9rc1 1 10009 2.1.0.9rc1 + 1.0.9beta7-10 1 10009 2.1.0.9beta7-10 + 1.0.9rc2 1 10009 2.1.0.9rc2 + 1.0.9 1 10009 2.1.0.9 + 1.0.10beta1 1 10010 2.1.0.10beta1 + 1.0.10rc1 1 10010 2.1.0.10rc1 + 1.0.10 1 10010 2.1.0.10 + 1.0.11beta1-3 1 10011 2.1.0.11beta1-3 + 1.0.11rc1 1 10011 2.1.0.11rc1 + 1.0.11 1 10011 2.1.0.11 + 1.0.12beta1-2 2 10012 2.1.0.12beta1-2 + 1.0.12rc1 2 10012 2.1.0.12rc1 + 1.0.12 2 10012 2.1.0.12 + 1.1.0a-f - 10100 2.1.1.0a-f abandoned + 1.2.0beta1-2 2 10200 2.1.2.0beta1-2 + 1.2.0beta3-5 3 10200 3.1.2.0beta3-5 + 1.2.0rc1 3 10200 3.1.2.0rc1 + 1.2.0 3 10200 3.1.2.0 + 1.2.1beta-4 3 10201 3.1.2.1beta1-4 + 1.2.1rc1-2 3 10201 3.1.2.1rc1-2 + 1.2.1 3 10201 3.1.2.1 + 1.2.2beta1-6 12 10202 12.so.0.1.2.2beta1-6 + 1.0.13beta1 10 10013 10.so.0.1.0.13beta1 + 1.0.13rc1 10 10013 10.so.0.1.0.13rc1 + 1.2.2rc1 12 10202 12.so.0.1.2.2rc1 + 1.0.13 10 10013 10.so.0.1.0.13 + 1.2.2 12 10202 12.so.0.1.2.2 + 1.2.3rc1-6 12 10203 12.so.0.1.2.3rc1-6 + 1.2.3 12 10203 12.so.0.1.2.3 + 1.2.4beta1-3 13 10204 12.so.0.1.2.4beta1-3 + 1.2.4rc1 13 10204 12.so.0.1.2.4rc1 + 1.0.14 10 10014 10.so.0.1.0.14 + 1.2.4 13 10204 12.so.0.1.2.4 + 1.2.5beta1-2 13 10205 12.so.0.1.2.5beta1-2 + 1.0.15rc1 10 10015 10.so.0.1.0.15rc1 + 1.0.15 10 10015 10.so.0.1.0.15 + 1.2.5 13 10205 12.so.0.1.2.5 + 1.2.6beta1-4 13 10206 12.so.0.1.2.6beta1-4 + 1.2.6rc1-5 13 10206 12.so.0.1.2.6rc1-5 + 1.0.16 10 10016 10.so.0.1.0.16 + 1.2.6 13 10206 12.so.0.1.2.6 + 1.2.7beta1-2 13 10207 12.so.0.1.2.7beta1-2 + 1.0.17rc1 10 10017 10.so.0.1.0.17rc1 + 1.2.7rc1 13 10207 12.so.0.1.2.7rc1 + 1.0.17 10 10017 10.so.0.1.0.17 + 1.2.7 13 10207 12.so.0.1.2.7 + 1.2.8beta1-5 13 10208 12.so.0.1.2.8beta1-5 + 1.0.18rc1-5 10 10018 10.so.0.1.0.18rc1-5 + 1.2.8rc1-5 13 10208 12.so.0.1.2.8rc1-5 + 1.0.18 10 10018 10.so.0.1.0.18 + 1.2.8 13 10208 12.so.0.1.2.8 + 1.2.9beta1-3 13 10209 12.so.0.1.2.9beta1-3 + 1.2.9beta4-11 13 10209 12.so.0.9[.0] + 1.2.9rc1 13 10209 12.so.0.9[.0] + 1.2.9 13 10209 12.so.0.9[.0] + 1.2.10beta1-8 13 10210 12.so.0.10[.0] + 1.2.10rc1-3 13 10210 12.so.0.10[.0] + 1.2.10 13 10210 12.so.0.10[.0] + 1.2.11beta1-4 13 10211 12.so.0.11[.0] + 1.0.19rc1-5 10 10019 10.so.0.19[.0] + 1.2.11rc1-5 13 10211 12.so.0.11[.0] + 1.0.19 10 10019 10.so.0.19[.0] + 1.2.11 13 10211 12.so.0.11[.0] + 1.0.20 10 10020 10.so.0.20[.0] + 1.2.12 13 10212 12.so.0.12[.0] + 1.2.13beta1 13 10213 12.so.0.13[.0] + 1.0.21 10 10021 10.so.0.21[.0] + 1.2.13 13 10213 12.so.0.13[.0] + 1.2.14beta1-2 13 10214 12.so.0.14[.0] + 1.0.22rc1 10 10022 10.so.0.22[.0] + 1.2.14rc1 13 10214 12.so.0.14[.0] + 1.2.15beta1-6 13 10215 12.so.0.15[.0] + 1.0.23rc1-5 10 10023 10.so.0.23[.0] + 1.2.15rc1-5 13 10215 12.so.0.15[.0] + 1.0.23 10 10023 10.so.0.23[.0] + 1.2.15 13 10215 12.so.0.15[.0] + 1.2.16beta1-2 13 10216 12.so.0.16[.0] + 1.2.16rc1 13 10216 12.so.0.16[.0] + 1.0.24 10 10024 10.so.0.24[.0] + 1.2.16 13 10216 12.so.0.16[.0] + 1.2.17beta1-2 13 10217 12.so.0.17[.0] + 1.0.25rc1 10 10025 10.so.0.25[.0] + 1.2.17rc1-3 13 10217 12.so.0.17[.0] + 1.0.25 10 10025 10.so.0.25[.0] + 1.2.17 13 10217 12.so.0.17[.0] + 1.0.26 10 10026 10.so.0.26[.0] + 1.2.18 13 10218 12.so.0.18[.0] + 1.2.19beta1-31 13 10219 12.so.0.19[.0] + 1.0.27rc1-6 10 10027 10.so.0.27[.0] + 1.2.19rc1-6 13 10219 12.so.0.19[.0] + 1.0.27 10 10027 10.so.0.27[.0] + 1.2.19 13 10219 12.so.0.19[.0] + 1.2.20beta01-04 13 10220 12.so.0.20[.0] + 1.0.28rc1-6 10 10028 10.so.0.28[.0] + 1.2.20rc1-6 13 10220 12.so.0.20[.0] + 1.0.28 10 10028 10.so.0.28[.0] + 1.2.20 13 10220 12.so.0.20[.0] + 1.2.21beta1-2 13 10221 12.so.0.21[.0] + 1.2.21rc1-3 13 10221 12.so.0.21[.0] + 1.0.29 10 10029 10.so.0.29[.0] + 1.2.21 13 10221 12.so.0.21[.0] + 1.2.22beta1-4 13 10222 12.so.0.22[.0] + 1.0.30rc1 13 10030 10.so.0.30[.0] + 1.2.22rc1 13 10222 12.so.0.22[.0] + 1.0.30 10 10030 10.so.0.30[.0] + 1.2.22 13 10222 12.so.0.22[.0] + 1.2.23beta01-05 13 10223 12.so.0.23[.0] + 1.2.23rc01 13 10223 12.so.0.23[.0] + 1.2.23 13 10223 12.so.0.23[.0] + 1.2.24beta01-02 13 10224 12.so.0.24[.0] + 1.2.24rc01 13 10224 12.so.0.24[.0] + 1.2.24 13 10224 12.so.0.24[.0] + 1.2.25beta01-06 13 10225 12.so.0.25[.0] + 1.2.25rc01-02 13 10225 12.so.0.25[.0] + 1.0.31 10 10031 10.so.0.31[.0] + 1.2.25 13 10225 12.so.0.25[.0] + 1.2.26beta01-06 13 10226 12.so.0.26[.0] + 1.2.26rc01 13 10226 12.so.0.26[.0] + 1.2.26 13 10226 12.so.0.26[.0] + 1.0.32 10 10032 10.so.0.32[.0] + 1.2.27beta01-06 13 10227 12.so.0.27[.0] + 1.2.27rc01 13 10227 12.so.0.27[.0] + 1.0.33 10 10033 10.so.0.33[.0] + 1.2.27 13 10227 12.so.0.27[.0] + 1.0.34 10 10034 10.so.0.34[.0] + 1.2.28 13 10228 12.so.0.28[.0] + 1.2.29beta01-03 13 10229 12.so.0.29[.0] + 1.2.29rc01 13 10229 12.so.0.29[.0] + 1.0.35 10 10035 10.so.0.35[.0] + 1.2.29 13 10229 12.so.0.29[.0] + 1.0.37 10 10037 10.so.0.37[.0] + 1.2.30beta01-04 13 10230 12.so.0.30[.0] + 1.0.38rc01-08 10 10038 10.so.0.38[.0] + 1.2.30rc01-08 13 10230 12.so.0.30[.0] + 1.0.38 10 10038 10.so.0.38[.0] + 1.2.30 13 10230 12.so.0.30[.0] + 1.0.39rc01-03 10 10039 10.so.0.39[.0] + 1.2.31rc01-03 13 10231 12.so.0.31[.0] + 1.0.39 10 10039 10.so.0.39[.0] + 1.2.31 13 10231 12.so.0.31[.0] + 1.2.32beta01-02 13 10232 12.so.0.32[.0] + 1.0.40rc01 10 10040 10.so.0.40[.0] + 1.2.32rc01 13 10232 12.so.0.32[.0] + 1.0.40 10 10040 10.so.0.40[.0] + 1.2.32 13 10232 12.so.0.32[.0] + 1.2.33beta01-02 13 10233 12.so.0.33[.0] + 1.2.33rc01-02 13 10233 12.so.0.33[.0] + 1.0.41rc01 10 10041 10.so.0.41[.0] + 1.2.33 13 10233 12.so.0.33[.0] + 1.0.41 10 10041 10.so.0.41[.0] + 1.2.34beta01-07 13 10234 12.so.0.34[.0] + 1.0.42rc01 10 10042 10.so.0.42[.0] + 1.2.34rc01 13 10234 12.so.0.34[.0] + 1.0.42 10 10042 10.so.0.42[.0] + 1.2.34 13 10234 12.so.0.34[.0] + 1.2.35beta01-03 13 10235 12.so.0.35[.0] + 1.0.43rc01-02 10 10043 10.so.0.43[.0] + 1.2.35rc01-02 13 10235 12.so.0.35[.0] + 1.0.43 10 10043 10.so.0.43[.0] + 1.2.35 13 10235 12.so.0.35[.0] + 1.2.36beta01-05 13 10236 12.so.0.36[.0] + 1.2.36rc01 13 10236 12.so.0.36[.0] + 1.0.44 10 10044 10.so.0.44[.0] + 1.2.36 13 10236 12.so.0.36[.0] + 1.2.37beta01-03 13 10237 12.so.0.37[.0] + 1.2.37rc01 13 10237 12.so.0.37[.0] + 1.2.37 13 10237 12.so.0.37[.0] + 1.0.45 10 10045 12.so.0.45[.0] + 1.0.46 10 10046 10.so.0.46[.0] + 1.2.38beta01 13 10238 12.so.0.38[.0] + 1.2.38rc01-03 13 10238 12.so.0.38[.0] + 1.0.47 10 10047 10.so.0.47[.0] + 1.2.38 13 10238 12.so.0.38[.0] + 1.2.39beta01-05 13 10239 12.so.0.39[.0] + 1.2.39rc01 13 10239 12.so.0.39[.0] + 1.0.48 10 10048 10.so.0.48[.0] + 1.2.39 13 10239 12.so.0.39[.0] + 1.2.40beta01 13 10240 12.so.0.40[.0] + 1.2.40rc01 13 10240 12.so.0.40[.0] + 1.0.49 10 10049 10.so.0.49[.0] + 1.2.40 13 10240 12.so.0.40[.0] + 1.0.50 10 10050 10.so.0.50[.0] + 1.2.41beta01-18 13 10241 12.so.0.41[.0] + 1.0.51rc01 10 10051 10.so.0.51[.0] + 1.2.41rc01-03 13 10241 12.so.0.41[.0] + 1.0.51 10 10051 10.so.0.51[.0] + 1.2.41 13 10241 12.so.0.41[.0] + 1.2.42beta01-02 13 10242 12.so.0.42[.0] + 1.2.42rc01-05 13 10242 12.so.0.42[.0] + 1.0.52 10 10052 10.so.0.52[.0] + 1.2.42 13 10242 12.so.0.42[.0] + 1.2.43beta01-05 13 10243 12.so.0.43[.0] + 1.0.53rc01-02 10 10053 10.so.0.53[.0] + 1.2.43rc01-02 13 10243 12.so.0.43[.0] + 1.0.53 10 10053 10.so.0.53[.0] + 1.2.43 13 10243 12.so.0.43[.0] + 1.2.44beta01-03 13 10244 12.so.0.44[.0] + 1.2.44rc01-03 13 10244 12.so.0.44[.0] + 1.2.44 13 10244 12.so.0.44[.0] + 1.2.45beta01-03 13 10245 12.so.0.45[.0] + 1.0.55rc01 10 10055 10.so.0.55[.0] + 1.2.45rc01 13 10245 12.so.0.45[.0] + 1.0.55 10 10055 10.so.0.55[.0] + 1.2.45 13 10245 12.so.0.45[.0] + 1.2.46rc01-02 13 10246 12.so.0.46[.0] + 1.0.56 10 10056 10.so.0.56[.0] + 1.2.46 13 10246 12.so.0.46[.0] + +Henceforth the source version will match the shared-library minor +and patch numbers; the shared-library major version number will be +used for changes in backward compatibility, as it is intended. The +PNG_PNGLIB_VER macro, which is not used within libpng but is available +for applications, is an unsigned integer of the form xyyzz corresponding +to the source version x.y.z (leading zeros in y and z). Beta versions +were given the previous public release number plus a letter, until +version 1.0.6j; from then on they were given the upcoming public +release number plus "betaNN" or "rcN". + +.SH "SEE ALSO" +.IR libpngpf(3) ", " png(5) +.LP +.IR libpng : +.IP +http://libpng.sourceforge.net (follow the [DOWNLOAD] link) +http://www.libpng.org/pub/png + +.LP +.IR zlib : +.IP +(generally) at the same location as +.I libpng +or at +.br +ftp://ftp.info-zip.org/pub/infozip/zlib + +.LP +.IR PNG specification: RFC 2083 +.IP +(generally) at the same location as +.I libpng +or at +.br +ftp://ftp.rfc-editor.org:/in-notes/rfc2083.txt +.br +or (as a W3C Recommendation) at +.br +http://www.w3.org/TR/REC-png.html + +.LP +In the case of any inconsistency between the PNG specification +and this library, the specification takes precedence. + +.SH AUTHORS +This man page: Glenn Randers-Pehrson + + +The contributing authors would like to thank all those who helped +with testing, bug fixes, and patience. This wouldn't have been +possible without all of you. + +Thanks to Frank J. T. Wojcik for helping with the documentation. + +Libpng version 1.2.46 - July 9, 2011: +Initially created in 1995 by Guy Eric Schalnat, then of Group 42, Inc. +Currently maintained by Glenn Randers-Pehrson (glennrp at users.sourceforge.net). + +Supported by the PNG development group +.br +png-mng-implement at lists.sf.net +(subscription required; visit +png-mng-implement at lists.sourceforge.net (subscription required; visit +https://lists.sourceforge.net/lists/listinfo/png-mng-implement +to subscribe). + +.SH COPYRIGHT NOTICE, DISCLAIMER, and LICENSE: + +(This copy of the libpng notices is provided for your convenience. In case of +any discrepancy between this copy and the notices in the file png.h that is +included in the libpng distribution, the latter shall prevail.) + +If you modify libpng you may insert additional notices immediately following +this sentence. + +This code is released under the libpng license. + +libpng versions 1.2.6, August 15, 2004, through 1.2.46, July 9, 2011, are +Copyright (c) 2004,2006-2008 Glenn Randers-Pehrson, and are +distributed according to the same disclaimer and license as libpng-1.2.5 +with the following individual added to the list of Contributing Authors + + Cosmin Truta + +libpng versions 1.0.7, July 1, 2000, through 1.2.5 - October 3, 2002, are +Copyright (c) 2000-2002 Glenn Randers-Pehrson, and are +distributed according to the same disclaimer and license as libpng-1.0.6 +with the following individuals added to the list of Contributing Authors + + Simon-Pierre Cadieux + Eric S. Raymond + Gilles Vollant + +and with the following additions to the disclaimer: + + There is no warranty against interference with your + enjoyment of the library or against infringement. + There is no warranty that our efforts or the library + will fulfill any of your particular purposes or needs. + This library is provided with all faults, and the entire + risk of satisfactory quality, performance, accuracy, and + effort is with the user. + +libpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are +Copyright (c) 1998, 1999 Glenn Randers-Pehrson +Distributed according to the same disclaimer and license as libpng-0.96, +with the following individuals added to the list of Contributing Authors: + + Tom Lane + Glenn Randers-Pehrson + Willem van Schaik + +libpng versions 0.89, June 1996, through 0.96, May 1997, are +Copyright (c) 1996, 1997 Andreas Dilger +Distributed according to the same disclaimer and license as libpng-0.88, +with the following individuals added to the list of Contributing Authors: + + John Bowler + Kevin Bracey + Sam Bushell + Magnus Holmgren + Greg Roelofs + Tom Tanner + +libpng versions 0.5, May 1995, through 0.88, January 1996, are +Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. + +For the purposes of this copyright and license, "Contributing Authors" +is defined as the following set of individuals: + + Andreas Dilger + Dave Martindale + Guy Eric Schalnat + Paul Schmidt + Tim Wegner + +The PNG Reference Library is supplied "AS IS". The Contributing Authors +and Group 42, Inc. disclaim all warranties, expressed or implied, +including, without limitation, the warranties of merchantability and of +fitness for any purpose. The Contributing Authors and Group 42, Inc. +assume no liability for direct, indirect, incidental, special, exemplary, +or consequential damages, which may result from the use of the PNG +Reference Library, even if advised of the possibility of such damage. + +Permission is hereby granted to use, copy, modify, and distribute this +source code, or portions hereof, for any purpose, without fee, subject +to the following restrictions: + +1. The origin of this source code must not be misrepresented. + +2. Altered versions must be plainly marked as such and + must not be misrepresented as being the original source. + +3. This Copyright notice may not be removed or altered from + any source or altered source distribution. + +The Contributing Authors and Group 42, Inc. specifically permit, without +fee, and encourage the use of this source code as a component to +supporting the PNG file format in commercial products. If you use this +source code in a product, acknowledgment is not required but would be +appreciated. + + +A "png_get_copyright" function is available, for convenient use in "about" +boxes and the like: + + printf("%s",png_get_copyright(NULL)); + +Also, the PNG logo (in PNG format, of course) is supplied in the +files "pngbar.png" and "pngbar.jpg (88x31) and "pngnow.png" (98x31). + +Libpng is OSI Certified Open Source Software. OSI Certified Open Source is a +certification mark of the Open Source Initiative. + +Glenn Randers-Pehrson +glennrp at users.sourceforge.net +July 9, 2011 + +.\" end of man page + diff --git a/libs/libpng-src/libpngpf.3 b/libs/libpng-src/libpngpf.3 new file mode 100644 index 000000000..b5a416c57 --- /dev/null +++ b/libs/libpng-src/libpngpf.3 @@ -0,0 +1,806 @@ +.TH LIBPNGPF 3 "July 9, 2011" +.SH NAME +libpng \- Portable Network Graphics (PNG) Reference Library 1.2.46 +(private functions) +.SH SYNOPSIS +\fB#include \fP + +\fI\fB + +\fBvoid png_64bit_product (long \fP\fIv1\fP\fB, long \fP\fIv2\fP\fB, unsigned long \fI*hi_product, + +\fBunsigned long \fI*lo_product\fP\fB);\fP + +\fI\fB + +\fBvoid png_build_gamma_table (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_build_grayscale_palette (int \fP\fIbit_depth\fP\fB, png_colorp \fIpalette\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_calculate_crc (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIptr\fP\fB, png_size_t \fIlength\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBint png_check_cHRM_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_fixed_point \fP\fIint_white_x\fP\fB, png_fixed_point \fP\fIint_white_y\fP\fB, png_fixed_point \fP\fIint_red_x\fP\fB, png_fixed_point \fP\fIint_red_y\fP\fB, png_fixed_point \fP\fIint_green_x\fP\fB, png_fixed_point \fP\fIint_green_y\fP\fB, png_fixed_point \fP\fIint_blue_x\fP\fB, png_fixed_point \fIint_blue_y\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_check_IHDR (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIwidth\fP\fB, png_uint_32 \fP\fIheight\fP\fB, int \fP\fIbit_depth\fP\fB, int \fP\fIcolor_type\fP\fB, int \fP\fIinterlace_type\fP\fB, int \fP\fIcompression_type\fP\fB, int \fIfilter_type\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_check_chunk_name (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIchunk_name\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBpng_size_t png_check_keyword (png_structp \fP\fIpng_ptr\fP\fB, png_charp \fP\fIkey\fP\fB, png_charpp \fInew_key\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_combine_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIrow\fP\fB, int \fImask\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_correct_palette (png_structp \fP\fIpng_ptr\fP\fB, png_colorp \fP\fIpalette\fP\fB, int \fInum_palette\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBint png_crc_error (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBint png_crc_finish (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIskip\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_crc_read (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIbuf\fP\fB, png_size_t \fIlength\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBpng_voidp png_create_struct (int \fItype\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBpng_voidp png_create_struct_2 (int \fP\fItype\fP\fB, png_malloc_ptr \fP\fImalloc_fn\fP\fB, png_voidp \fImem_ptr\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_decompress_chunk (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fIcomp_type\fP\fB, png_charp \fP\fIchunkdata\fP\fB, png_size_t \fP\fIchunklength\fP\fB, png_size_t \fP\fIprefix_length\fP\fB, png_size_t \fI*data_length\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_destroy_struct (png_voidp \fIstruct_ptr\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_destroy_struct_2 (png_voidp \fP\fIstruct_ptr\fP\fB, png_free_ptr \fP\fIfree_fn\fP\fB, png_voidp \fImem_ptr\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_do_background (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, png_color_16p \fP\fItrans_values\fP\fB, png_color_16p \fP\fIbackground\fP\fB, png_color_16p \fP\fIbackground_1\fP\fB, png_bytep \fP\fIgamma_table\fP\fB, png_bytep \fP\fIgamma_from_1\fP\fB, png_bytep \fP\fIgamma_to_1\fP\fB, png_uint_16pp \fP\fIgamma_16\fP\fB, png_uint_16pp \fP\fIgamma_16_from_1\fP\fB, png_uint_16pp \fP\fIgamma_16_to_1\fP\fB, int \fIgamma_shift\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_do_bgr (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_do_chop (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_do_dither (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, png_bytep \fP\fIpalette_lookup\fP\fB, png_bytep \fIdither_lookup\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_do_expand (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, png_color_16p \fItrans_value\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_do_expand_palette (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, png_colorp \fP\fIpalette\fP\fB, png_bytep \fP\fItrans\fP\fB, int \fInum_trans\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_do_gamma (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, png_bytep \fP\fIgamma_table\fP\fB, png_uint_16pp \fP\fIgamma_16_table\fP\fB, int \fIgamma_shift\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_do_gray_to_rgb (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_do_invert (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_do_pack (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, png_uint_32 \fIbit_depth\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_do_packswap (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_do_read_filler (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, png_uint_32 \fP\fIfiller\fP\fB, png_uint_32 \fIflags\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_do_read_interlace (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, int \fP\fIpass\fP\fB, png_uint_32 \fItransformations\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_do_read_invert_alpha (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_do_read_swap_alpha (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_do_read_transformations (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBint png_do_rgb_to_gray (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_do_shift (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, png_color_8p \fIbit_depth\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_do_strip_filler (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, png_uint_32 \fIflags\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_do_swap (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_do_unpack (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_do_unshift (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, png_color_8p \fIsig_bits\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_do_write_interlace (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, int \fIpass\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_do_write_invert_alpha (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_do_write_swap_alpha (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_do_write_transformations (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid *png_far_to_near (png_structp png_ptr,png_voidp \fP\fIptr\fP\fB, int \fIcheck\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_flush (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_handle_bKGD (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_handle_cHRM (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_handle_gAMA (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_handle_hIST (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_handle_IEND (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_handle_IHDR (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_handle_iCCP (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_handle_iTXt (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_handle_oFFs (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_handle_pCAL (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_handle_pHYs (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_handle_PLTE (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_handle_sBIT (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_handle_sCAL (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_handle_sPLT (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_handle_sRGB (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_handle_tEXt (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_handle_tIME (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_handle_tRNS (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_handle_unknown (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_handle_zTXt (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_info_destroy (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_init_mmx_flags (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_init_read_transformations (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_process_IDAT_data (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIbuffer\fP\fB, png_size_t \fIbuffer_length\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_process_some_data (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_push_check_crc (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_push_crc_finish (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_push_crc_skip (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_push_fill_buffer (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIbuffer\fP\fB, png_size_t \fIlength\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_push_handle_tEXt (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_push_handle_unknown (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_push_handle_zTXt (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_push_have_end (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_push_have_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_push_have_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIrow\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_push_process_row (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_push_read_chunk (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_push_read_end (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_push_read_IDAT (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_push_read_sig (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_push_read_tEXt (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_push_read_zTXt (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_push_restore_buffer (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIbuffer\fP\fB, png_size_t \fIbuffer_length\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_push_save_buffer (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBpng_uint_32 png_read_chunk_header (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_read_data (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIdata\fP\fB, png_size_t \fIlength\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_read_filter_row (png_structp \fP\fIpng_ptr\fP\fB, png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, png_bytep \fP\fIprev_row\fP\fB, int \fIfilter\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_read_finish_row (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_read_push_finish_row (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_read_start_row (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_read_transform_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_reset_crc (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBint png_set_text_2 (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_textp \fP\fItext_ptr\fP\fB, int \fInum_text\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_write_cHRM (png_structp \fP\fIpng_ptr\fP\fB, double \fP\fIwhite_x\fP\fB, double \fP\fIwhite_y\fP\fB, double \fP\fIred_x\fP\fB, double \fP\fIred_y\fP\fB, double \fP\fIgreen_x\fP\fB, double \fP\fIgreen_y\fP\fB, double \fP\fIblue_x\fP\fB, double \fIblue_y\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_write_cHRM_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIwhite_x\fP\fB, png_uint_32 \fP\fIwhite_y\fP\fB, png_uint_32 \fP\fIred_x\fP\fB, png_uint_32 \fP\fIred_y\fP\fB, png_uint_32 \fP\fIgreen_x\fP\fB, png_uint_32 \fP\fIgreen_y\fP\fB, png_uint_32 \fP\fIblue_x\fP\fB, png_uint_32 \fIblue_y\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_write_data (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIdata\fP\fB, png_size_t \fIlength\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_write_filtered_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIfiltered_row\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_write_find_filter (png_structp \fP\fIpng_ptr\fP\fB, png_row_infop \fIrow_info\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_write_finish_row (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_write_gAMA (png_structp \fP\fIpng_ptr\fP\fB, double \fIfile_gamma\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_write_gAMA_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIint_file_gamma\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_write_hIST (png_structp \fP\fIpng_ptr\fP\fB, png_uint_16p \fP\fIhist\fP\fB, int \fInum_hist\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_write_iCCP (png_structp \fP\fIpng_ptr\fP\fB, png_charp \fP\fIname\fP\fB, int \fP\fIcompression_type\fP\fB, png_charp \fP\fIprofile\fP\fB, int \fIproflen\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_write_IDAT (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIdata\fP\fB, png_size_t \fIlength\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_write_IEND (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_write_IHDR (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIwidth\fP\fB, png_uint_32 \fP\fIheight\fP\fB, int \fP\fIbit_depth\fP\fB, int \fP\fIcolor_type\fP\fB, int \fP\fIcompression_type\fP\fB, int \fP\fIfilter_type\fP\fB, int \fIinterlace_type\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_write_iTXt (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fIcompression\fP\fB, png_charp \fP\fIkey\fP\fB, png_charp \fP\fIlang\fP\fB, png_charp \fP\fItranslated_key\fP\fB, png_charp \fItext\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_write_oFFs (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIx_offset\fP\fB, png_uint_32 \fP\fIy_offset\fP\fB, int \fIunit_type\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_write_pCAL (png_structp \fP\fIpng_ptr\fP\fB, png_charp \fP\fIpurpose\fP\fB, png_int_32 \fP\fIX0\fP\fB, png_int_32 \fP\fIX1\fP\fB, int \fP\fItype\fP\fB, int \fP\fInparams\fP\fB, png_charp \fP\fIunits\fP\fB, png_charpp \fIparams\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_write_pHYs (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIx_pixels_per_unit\fP\fB, png_uint_32 \fP\fIy_pixels_per_unit\fP\fB, int \fIunit_type\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_write_PLTE (png_structp \fP\fIpng_ptr\fP\fB, png_colorp \fP\fIpalette\fP\fB, png_uint_32 \fInum_pal\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_write_sBIT (png_structp \fP\fIpng_ptr\fP\fB, png_color_8p \fP\fIsbit\fP\fB, int \fIcolor_type\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_write_sCAL (png_structp \fP\fIpng_ptr\fP\fB, png_charp \fP\fIunit\fP\fB, double \fP\fIwidth\fP\fB, double \fIheight\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_write_sCAL_s (png_structp \fP\fIpng_ptr\fP\fB, png_charp \fP\fIunit\fP\fB, png_charp \fP\fIwidth\fP\fB, png_charp \fIheight\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_write_sig (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_write_sRGB (png_structp \fP\fIpng_ptr\fP\fB, int \fIintent\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_write_sPLT (png_structp \fP\fIpng_ptr\fP\fB, png_spalette_p \fIpalette\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_write_start_row (png_structp \fIpng_ptr\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_write_tEXt (png_structp \fP\fIpng_ptr\fP\fB, png_charp \fP\fIkey\fP\fB, png_charp \fP\fItext\fP\fB, png_size_t \fItext_len\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_write_tIME (png_structp \fP\fIpng_ptr\fP\fB, png_timep \fImod_time\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_write_tRNS (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fItrans\fP\fB, png_color_16p \fP\fIvalues\fP\fB, int \fP\fInumber\fP\fB, int \fIcolor_type\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_write_zTXt (png_structp \fP\fIpng_ptr\fP\fB, png_charp \fP\fIkey\fP\fB, png_charp \fP\fItext\fP\fB, png_size_t \fP\fItext_len\fP\fB, int \fIcompression\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoidpf png_zalloc (voidpf \fP\fIpng_ptr\fP\fB, uInt \fP\fIitems\fP\fB, uInt \fIsize\fP\fB);\fP + +\fI\fB + +\fI\fB + +\fBvoid png_zfree (voidpf \fP\fIpng_ptr\fP\fB, voidpf \fIptr\fP\fB);\fP + +\fI\fB + +\fI\fB + +.SH DESCRIPTION +The functions listed above are used privately by libpng +and are not recommended for use by applications. They are +not "exported" to applications using shared libraries. They +are listed alphabetically here as an aid to libpng maintainers. +See png.h for more information on these functions. + +.SH SEE ALSO +.IR libpng(3) ", " png(5) +.SH AUTHOR +Glenn Randers-Pehrson diff --git a/libs/libpng-src/ltmain.sh b/libs/libpng-src/ltmain.sh new file mode 100755 index 000000000..a72f2fd78 --- /dev/null +++ b/libs/libpng-src/ltmain.sh @@ -0,0 +1,8406 @@ +# Generated from ltmain.m4sh. + +# ltmain.sh (GNU libtool) 2.2.6b +# Written by Gordon Matzigkeit , 1996 + +# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006, 2007 2008 Free Software Foundation, Inc. +# This is free software; see the source for copying conditions. There is NO +# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +# GNU Libtool is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# As a special exception to the GNU General Public License, +# if you distribute this file as part of a program or library that +# is built using GNU Libtool, you may include this file under the +# same distribution terms that you use for the rest of that program. +# +# GNU Libtool is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Libtool; see the file COPYING. If not, a copy +# can be downloaded from http://www.gnu.org/licenses/gpl.html, +# or obtained by writing to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +# Usage: $progname [OPTION]... [MODE-ARG]... +# +# Provide generalized library-building support services. +# +# --config show all configuration variables +# --debug enable verbose shell tracing +# -n, --dry-run display commands without modifying any files +# --features display basic configuration information and exit +# --mode=MODE use operation mode MODE +# --preserve-dup-deps don't remove duplicate dependency libraries +# --quiet, --silent don't print informational messages +# --tag=TAG use configuration variables from tag TAG +# -v, --verbose print informational messages (default) +# --version print version information +# -h, --help print short or long help message +# +# MODE must be one of the following: +# +# clean remove files from the build directory +# compile compile a source file into a libtool object +# execute automatically set library path, then run a program +# finish complete the installation of libtool libraries +# install install libraries or executables +# link create a library or an executable +# uninstall remove libraries from an installed directory +# +# MODE-ARGS vary depending on the MODE. +# Try `$progname --help --mode=MODE' for a more detailed description of MODE. +# +# When reporting a bug, please describe a test case to reproduce it and +# include the following information: +# +# host-triplet: $host +# shell: $SHELL +# compiler: $LTCC +# compiler flags: $LTCFLAGS +# linker: $LD (gnu? $with_gnu_ld) +# $progname: (GNU libtool) 2.2.6b +# automake: $automake_version +# autoconf: $autoconf_version +# +# Report bugs to . + +PROGRAM=ltmain.sh +PACKAGE=libtool +VERSION=2.2.6b +TIMESTAMP="" +package_revision=1.3017 + +# Be Bourne compatible +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then + emulate sh + NULLCMD=: + # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac +fi +BIN_SH=xpg4; export BIN_SH # for Tru64 +DUALCASE=1; export DUALCASE # for MKS sh + +# NLS nuisances: We save the old values to restore during execute mode. +# Only set LANG and LC_ALL to C if already set. +# These must not be set unconditionally because not all systems understand +# e.g. LANG=C (notably SCO). +lt_user_locale= +lt_safe_locale= +for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES +do + eval "if test \"\${$lt_var+set}\" = set; then + save_$lt_var=\$$lt_var + $lt_var=C + export $lt_var + lt_user_locale=\"$lt_var=\\\$save_\$lt_var; \$lt_user_locale\" + lt_safe_locale=\"$lt_var=C; \$lt_safe_locale\" + fi" +done + +$lt_unset CDPATH + + + + + +: ${CP="cp -f"} +: ${ECHO="echo"} +: ${EGREP="/bin/grep -E"} +: ${FGREP="/bin/grep -F"} +: ${GREP="/bin/grep"} +: ${LN_S="ln -s"} +: ${MAKE="make"} +: ${MKDIR="mkdir"} +: ${MV="mv -f"} +: ${RM="rm -f"} +: ${SED="/bin/sed"} +: ${SHELL="${CONFIG_SHELL-/bin/sh}"} +: ${Xsed="$SED -e 1s/^X//"} + +# Global variables: +EXIT_SUCCESS=0 +EXIT_FAILURE=1 +EXIT_MISMATCH=63 # $? = 63 is used to indicate version mismatch to missing. +EXIT_SKIP=77 # $? = 77 is used to indicate a skipped test to automake. + +exit_status=$EXIT_SUCCESS + +# Make sure IFS has a sensible default +lt_nl=' +' +IFS=" $lt_nl" + +dirname="s,/[^/]*$,," +basename="s,^.*/,," + +# func_dirname_and_basename file append nondir_replacement +# perform func_basename and func_dirname in a single function +# call: +# dirname: Compute the dirname of FILE. If nonempty, +# add APPEND to the result, otherwise set result +# to NONDIR_REPLACEMENT. +# value returned in "$func_dirname_result" +# basename: Compute filename of FILE. +# value retuned in "$func_basename_result" +# Implementation must be kept synchronized with func_dirname +# and func_basename. For efficiency, we do not delegate to +# those functions but instead duplicate the functionality here. +func_dirname_and_basename () +{ + # Extract subdirectory from the argument. + func_dirname_result=`$ECHO "X${1}" | $Xsed -e "$dirname"` + if test "X$func_dirname_result" = "X${1}"; then + func_dirname_result="${3}" + else + func_dirname_result="$func_dirname_result${2}" + fi + func_basename_result=`$ECHO "X${1}" | $Xsed -e "$basename"` +} + +# Generated shell functions inserted here. + +# Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh +# is ksh but when the shell is invoked as "sh" and the current value of +# the _XPG environment variable is not equal to 1 (one), the special +# positional parameter $0, within a function call, is the name of the +# function. +progpath="$0" + +# The name of this program: +# In the unlikely event $progname began with a '-', it would play havoc with +# func_echo (imagine progname=-n), so we prepend ./ in that case: +func_dirname_and_basename "$progpath" +progname=$func_basename_result +case $progname in + -*) progname=./$progname ;; +esac + +# Make sure we have an absolute path for reexecution: +case $progpath in + [\\/]*|[A-Za-z]:\\*) ;; + *[\\/]*) + progdir=$func_dirname_result + progdir=`cd "$progdir" && pwd` + progpath="$progdir/$progname" + ;; + *) + save_IFS="$IFS" + IFS=: + for progdir in $PATH; do + IFS="$save_IFS" + test -x "$progdir/$progname" && break + done + IFS="$save_IFS" + test -n "$progdir" || progdir=`pwd` + progpath="$progdir/$progname" + ;; +esac + +# Sed substitution that helps us do robust quoting. It backslashifies +# metacharacters that are still active within double-quoted strings. +Xsed="${SED}"' -e 1s/^X//' +sed_quote_subst='s/\([`"$\\]\)/\\\1/g' + +# Same as above, but do not quote variable references. +double_quote_subst='s/\(["`\\]\)/\\\1/g' + +# Re-`\' parameter expansions in output of double_quote_subst that were +# `\'-ed in input to the same. If an odd number of `\' preceded a '$' +# in input to double_quote_subst, that '$' was protected from expansion. +# Since each input `\' is now two `\'s, look for any number of runs of +# four `\'s followed by two `\'s and then a '$'. `\' that '$'. +bs='\\' +bs2='\\\\' +bs4='\\\\\\\\' +dollar='\$' +sed_double_backslash="\ + s/$bs4/&\\ +/g + s/^$bs2$dollar/$bs&/ + s/\\([^$bs]\\)$bs2$dollar/\\1$bs2$bs$dollar/g + s/\n//g" + +# Standard options: +opt_dry_run=false +opt_help=false +opt_quiet=false +opt_verbose=false +opt_warning=: + +# func_echo arg... +# Echo program name prefixed message, along with the current mode +# name if it has been set yet. +func_echo () +{ + $ECHO "$progname${mode+: }$mode: $*" +} + +# func_verbose arg... +# Echo program name prefixed message in verbose mode only. +func_verbose () +{ + $opt_verbose && func_echo ${1+"$@"} + + # A bug in bash halts the script if the last line of a function + # fails when set -e is in force, so we need another command to + # work around that: + : +} + +# func_error arg... +# Echo program name prefixed message to standard error. +func_error () +{ + $ECHO "$progname${mode+: }$mode: "${1+"$@"} 1>&2 +} + +# func_warning arg... +# Echo program name prefixed warning message to standard error. +func_warning () +{ + $opt_warning && $ECHO "$progname${mode+: }$mode: warning: "${1+"$@"} 1>&2 + + # bash bug again: + : +} + +# func_fatal_error arg... +# Echo program name prefixed message to standard error, and exit. +func_fatal_error () +{ + func_error ${1+"$@"} + exit $EXIT_FAILURE +} + +# func_fatal_help arg... +# Echo program name prefixed message to standard error, followed by +# a help hint, and exit. +func_fatal_help () +{ + func_error ${1+"$@"} + func_fatal_error "$help" +} +help="Try \`$progname --help' for more information." ## default + + +# func_grep expression filename +# Check whether EXPRESSION matches any line of FILENAME, without output. +func_grep () +{ + $GREP "$1" "$2" >/dev/null 2>&1 +} + + +# func_mkdir_p directory-path +# Make sure the entire path to DIRECTORY-PATH is available. +func_mkdir_p () +{ + my_directory_path="$1" + my_dir_list= + + if test -n "$my_directory_path" && test "$opt_dry_run" != ":"; then + + # Protect directory names starting with `-' + case $my_directory_path in + -*) my_directory_path="./$my_directory_path" ;; + esac + + # While some portion of DIR does not yet exist... + while test ! -d "$my_directory_path"; do + # ...make a list in topmost first order. Use a colon delimited + # list incase some portion of path contains whitespace. + my_dir_list="$my_directory_path:$my_dir_list" + + # If the last portion added has no slash in it, the list is done + case $my_directory_path in */*) ;; *) break ;; esac + + # ...otherwise throw away the child directory and loop + my_directory_path=`$ECHO "X$my_directory_path" | $Xsed -e "$dirname"` + done + my_dir_list=`$ECHO "X$my_dir_list" | $Xsed -e 's,:*$,,'` + + save_mkdir_p_IFS="$IFS"; IFS=':' + for my_dir in $my_dir_list; do + IFS="$save_mkdir_p_IFS" + # mkdir can fail with a `File exist' error if two processes + # try to create one of the directories concurrently. Don't + # stop in that case! + $MKDIR "$my_dir" 2>/dev/null || : + done + IFS="$save_mkdir_p_IFS" + + # Bail out if we (or some other process) failed to create a directory. + test -d "$my_directory_path" || \ + func_fatal_error "Failed to create \`$1'" + fi +} + + +# func_mktempdir [string] +# Make a temporary directory that won't clash with other running +# libtool processes, and avoids race conditions if possible. If +# given, STRING is the basename for that directory. +func_mktempdir () +{ + my_template="${TMPDIR-/tmp}/${1-$progname}" + + if test "$opt_dry_run" = ":"; then + # Return a directory name, but don't create it in dry-run mode + my_tmpdir="${my_template}-$$" + else + + # If mktemp works, use that first and foremost + my_tmpdir=`mktemp -d "${my_template}-XXXXXXXX" 2>/dev/null` + + if test ! -d "$my_tmpdir"; then + # Failing that, at least try and use $RANDOM to avoid a race + my_tmpdir="${my_template}-${RANDOM-0}$$" + + save_mktempdir_umask=`umask` + umask 0077 + $MKDIR "$my_tmpdir" + umask $save_mktempdir_umask + fi + + # If we're not in dry-run mode, bomb out on failure + test -d "$my_tmpdir" || \ + func_fatal_error "cannot create temporary directory \`$my_tmpdir'" + fi + + $ECHO "X$my_tmpdir" | $Xsed +} + + +# func_quote_for_eval arg +# Aesthetically quote ARG to be evaled later. +# This function returns two values: FUNC_QUOTE_FOR_EVAL_RESULT +# is double-quoted, suitable for a subsequent eval, whereas +# FUNC_QUOTE_FOR_EVAL_UNQUOTED_RESULT has merely all characters +# which are still active within double quotes backslashified. +func_quote_for_eval () +{ + case $1 in + *[\\\`\"\$]*) + func_quote_for_eval_unquoted_result=`$ECHO "X$1" | $Xsed -e "$sed_quote_subst"` ;; + *) + func_quote_for_eval_unquoted_result="$1" ;; + esac + + case $func_quote_for_eval_unquoted_result in + # Double-quote args containing shell metacharacters to delay + # word splitting, command substitution and and variable + # expansion for a subsequent eval. + # Many Bourne shells cannot handle close brackets correctly + # in scan sets, so we specify it separately. + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + func_quote_for_eval_result="\"$func_quote_for_eval_unquoted_result\"" + ;; + *) + func_quote_for_eval_result="$func_quote_for_eval_unquoted_result" + esac +} + + +# func_quote_for_expand arg +# Aesthetically quote ARG to be evaled later; same as above, +# but do not quote variable references. +func_quote_for_expand () +{ + case $1 in + *[\\\`\"]*) + my_arg=`$ECHO "X$1" | $Xsed \ + -e "$double_quote_subst" -e "$sed_double_backslash"` ;; + *) + my_arg="$1" ;; + esac + + case $my_arg in + # Double-quote args containing shell metacharacters to delay + # word splitting and command substitution for a subsequent eval. + # Many Bourne shells cannot handle close brackets correctly + # in scan sets, so we specify it separately. + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + my_arg="\"$my_arg\"" + ;; + esac + + func_quote_for_expand_result="$my_arg" +} + + +# func_show_eval cmd [fail_exp] +# Unless opt_silent is true, then output CMD. Then, if opt_dryrun is +# not true, evaluate CMD. If the evaluation of CMD fails, and FAIL_EXP +# is given, then evaluate it. +func_show_eval () +{ + my_cmd="$1" + my_fail_exp="${2-:}" + + ${opt_silent-false} || { + func_quote_for_expand "$my_cmd" + eval "func_echo $func_quote_for_expand_result" + } + + if ${opt_dry_run-false}; then :; else + eval "$my_cmd" + my_status=$? + if test "$my_status" -eq 0; then :; else + eval "(exit $my_status); $my_fail_exp" + fi + fi +} + + +# func_show_eval_locale cmd [fail_exp] +# Unless opt_silent is true, then output CMD. Then, if opt_dryrun is +# not true, evaluate CMD. If the evaluation of CMD fails, and FAIL_EXP +# is given, then evaluate it. Use the saved locale for evaluation. +func_show_eval_locale () +{ + my_cmd="$1" + my_fail_exp="${2-:}" + + ${opt_silent-false} || { + func_quote_for_expand "$my_cmd" + eval "func_echo $func_quote_for_expand_result" + } + + if ${opt_dry_run-false}; then :; else + eval "$lt_user_locale + $my_cmd" + my_status=$? + eval "$lt_safe_locale" + if test "$my_status" -eq 0; then :; else + eval "(exit $my_status); $my_fail_exp" + fi + fi +} + + + + + +# func_version +# Echo version message to standard output and exit. +func_version () +{ + $SED -n '/^# '$PROGRAM' (GNU /,/# warranty; / { + s/^# // + s/^# *$// + s/\((C)\)[ 0-9,-]*\( [1-9][0-9]*\)/\1\2/ + p + }' < "$progpath" + exit $? +} + +# func_usage +# Echo short help message to standard output and exit. +func_usage () +{ + $SED -n '/^# Usage:/,/# -h/ { + s/^# // + s/^# *$// + s/\$progname/'$progname'/ + p + }' < "$progpath" + $ECHO + $ECHO "run \`$progname --help | more' for full usage" + exit $? +} + +# func_help +# Echo long help message to standard output and exit. +func_help () +{ + $SED -n '/^# Usage:/,/# Report bugs to/ { + s/^# // + s/^# *$// + s*\$progname*'$progname'* + s*\$host*'"$host"'* + s*\$SHELL*'"$SHELL"'* + s*\$LTCC*'"$LTCC"'* + s*\$LTCFLAGS*'"$LTCFLAGS"'* + s*\$LD*'"$LD"'* + s/\$with_gnu_ld/'"$with_gnu_ld"'/ + s/\$automake_version/'"`(automake --version) 2>/dev/null |$SED 1q`"'/ + s/\$autoconf_version/'"`(autoconf --version) 2>/dev/null |$SED 1q`"'/ + p + }' < "$progpath" + exit $? +} + +# func_missing_arg argname +# Echo program name prefixed message to standard error and set global +# exit_cmd. +func_missing_arg () +{ + func_error "missing argument for $1" + exit_cmd=exit +} + +exit_cmd=: + + + + + +# Check that we have a working $ECHO. +if test "X$1" = X--no-reexec; then + # Discard the --no-reexec flag, and continue. + shift +elif test "X$1" = X--fallback-echo; then + # Avoid inline document here, it may be left over + : +elif test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t'; then + # Yippee, $ECHO works! + : +else + # Restart under the correct shell, and then maybe $ECHO will work. + exec $SHELL "$progpath" --no-reexec ${1+"$@"} +fi + +if test "X$1" = X--fallback-echo; then + # used as fallback echo + shift + cat </dev/null 2>&1; then + taglist="$taglist $tagname" + + # Evaluate the configuration. Be careful to quote the path + # and the sed script, to avoid splitting on whitespace, but + # also don't use non-portable quotes within backquotes within + # quotes we have to do it in 2 steps: + extractedcf=`$SED -n -e "$sed_extractcf" < "$progpath"` + eval "$extractedcf" + else + func_error "ignoring unknown tag $tagname" + fi + ;; + esac +} + +# Parse options once, thoroughly. This comes as soon as possible in +# the script to make things like `libtool --version' happen quickly. +{ + + # Shorthand for --mode=foo, only valid as the first argument + case $1 in + clean|clea|cle|cl) + shift; set dummy --mode clean ${1+"$@"}; shift + ;; + compile|compil|compi|comp|com|co|c) + shift; set dummy --mode compile ${1+"$@"}; shift + ;; + execute|execut|execu|exec|exe|ex|e) + shift; set dummy --mode execute ${1+"$@"}; shift + ;; + finish|finis|fini|fin|fi|f) + shift; set dummy --mode finish ${1+"$@"}; shift + ;; + install|instal|insta|inst|ins|in|i) + shift; set dummy --mode install ${1+"$@"}; shift + ;; + link|lin|li|l) + shift; set dummy --mode link ${1+"$@"}; shift + ;; + uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u) + shift; set dummy --mode uninstall ${1+"$@"}; shift + ;; + esac + + # Parse non-mode specific arguments: + while test "$#" -gt 0; do + opt="$1" + shift + + case $opt in + --config) func_config ;; + + --debug) preserve_args="$preserve_args $opt" + func_echo "enabling shell trace mode" + opt_debug='set -x' + $opt_debug + ;; + + -dlopen) test "$#" -eq 0 && func_missing_arg "$opt" && break + execute_dlfiles="$execute_dlfiles $1" + shift + ;; + + --dry-run | -n) opt_dry_run=: ;; + --features) func_features ;; + --finish) mode="finish" ;; + + --mode) test "$#" -eq 0 && func_missing_arg "$opt" && break + case $1 in + # Valid mode arguments: + clean) ;; + compile) ;; + execute) ;; + finish) ;; + install) ;; + link) ;; + relink) ;; + uninstall) ;; + + # Catch anything else as an error + *) func_error "invalid argument for $opt" + exit_cmd=exit + break + ;; + esac + + mode="$1" + shift + ;; + + --preserve-dup-deps) + opt_duplicate_deps=: ;; + + --quiet|--silent) preserve_args="$preserve_args $opt" + opt_silent=: + ;; + + --verbose| -v) preserve_args="$preserve_args $opt" + opt_silent=false + ;; + + --tag) test "$#" -eq 0 && func_missing_arg "$opt" && break + preserve_args="$preserve_args $opt $1" + func_enable_tag "$1" # tagname is set here + shift + ;; + + # Separate optargs to long options: + -dlopen=*|--mode=*|--tag=*) + func_opt_split "$opt" + set dummy "$func_opt_split_opt" "$func_opt_split_arg" ${1+"$@"} + shift + ;; + + -\?|-h) func_usage ;; + --help) opt_help=: ;; + --version) func_version ;; + + -*) func_fatal_help "unrecognized option \`$opt'" ;; + + *) nonopt="$opt" + break + ;; + esac + done + + + case $host in + *cygwin* | *mingw* | *pw32* | *cegcc*) + # don't eliminate duplications in $postdeps and $predeps + opt_duplicate_compiler_generated_deps=: + ;; + *) + opt_duplicate_compiler_generated_deps=$opt_duplicate_deps + ;; + esac + + # Having warned about all mis-specified options, bail out if + # anything was wrong. + $exit_cmd $EXIT_FAILURE +} + +# func_check_version_match +# Ensure that we are using m4 macros, and libtool script from the same +# release of libtool. +func_check_version_match () +{ + if test "$package_revision" != "$macro_revision"; then + if test "$VERSION" != "$macro_version"; then + if test -z "$macro_version"; then + cat >&2 <<_LT_EOF +$progname: Version mismatch error. This is $PACKAGE $VERSION, but the +$progname: definition of this LT_INIT comes from an older release. +$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION +$progname: and run autoconf again. +_LT_EOF + else + cat >&2 <<_LT_EOF +$progname: Version mismatch error. This is $PACKAGE $VERSION, but the +$progname: definition of this LT_INIT comes from $PACKAGE $macro_version. +$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION +$progname: and run autoconf again. +_LT_EOF + fi + else + cat >&2 <<_LT_EOF +$progname: Version mismatch error. This is $PACKAGE $VERSION, revision $package_revision, +$progname: but the definition of this LT_INIT comes from revision $macro_revision. +$progname: You should recreate aclocal.m4 with macros from revision $package_revision +$progname: of $PACKAGE $VERSION and run autoconf again. +_LT_EOF + fi + + exit $EXIT_MISMATCH + fi +} + + +## ----------- ## +## Main. ## +## ----------- ## + +$opt_help || { + # Sanity checks first: + func_check_version_match + + if test "$build_libtool_libs" != yes && test "$build_old_libs" != yes; then + func_fatal_configuration "not configured to build any kind of library" + fi + + test -z "$mode" && func_fatal_error "error: you must specify a MODE." + + + # Darwin sucks + eval std_shrext=\"$shrext_cmds\" + + + # Only execute mode is allowed to have -dlopen flags. + if test -n "$execute_dlfiles" && test "$mode" != execute; then + func_error "unrecognized option \`-dlopen'" + $ECHO "$help" 1>&2 + exit $EXIT_FAILURE + fi + + # Change the help message to a mode-specific one. + generic_help="$help" + help="Try \`$progname --help --mode=$mode' for more information." +} + + +# func_lalib_p file +# True iff FILE is a libtool `.la' library or `.lo' object file. +# This function is only a basic sanity check; it will hardly flush out +# determined imposters. +func_lalib_p () +{ + test -f "$1" && + $SED -e 4q "$1" 2>/dev/null \ + | $GREP "^# Generated by .*$PACKAGE" > /dev/null 2>&1 +} + +# func_lalib_unsafe_p file +# True iff FILE is a libtool `.la' library or `.lo' object file. +# This function implements the same check as func_lalib_p without +# resorting to external programs. To this end, it redirects stdin and +# closes it afterwards, without saving the original file descriptor. +# As a safety measure, use it only where a negative result would be +# fatal anyway. Works if `file' does not exist. +func_lalib_unsafe_p () +{ + lalib_p=no + if test -f "$1" && test -r "$1" && exec 5<&0 <"$1"; then + for lalib_p_l in 1 2 3 4 + do + read lalib_p_line + case "$lalib_p_line" in + \#\ Generated\ by\ *$PACKAGE* ) lalib_p=yes; break;; + esac + done + exec 0<&5 5<&- + fi + test "$lalib_p" = yes +} + +# func_ltwrapper_script_p file +# True iff FILE is a libtool wrapper script +# This function is only a basic sanity check; it will hardly flush out +# determined imposters. +func_ltwrapper_script_p () +{ + func_lalib_p "$1" +} + +# func_ltwrapper_executable_p file +# True iff FILE is a libtool wrapper executable +# This function is only a basic sanity check; it will hardly flush out +# determined imposters. +func_ltwrapper_executable_p () +{ + func_ltwrapper_exec_suffix= + case $1 in + *.exe) ;; + *) func_ltwrapper_exec_suffix=.exe ;; + esac + $GREP "$magic_exe" "$1$func_ltwrapper_exec_suffix" >/dev/null 2>&1 +} + +# func_ltwrapper_scriptname file +# Assumes file is an ltwrapper_executable +# uses $file to determine the appropriate filename for a +# temporary ltwrapper_script. +func_ltwrapper_scriptname () +{ + func_ltwrapper_scriptname_result="" + if func_ltwrapper_executable_p "$1"; then + func_dirname_and_basename "$1" "" "." + func_stripname '' '.exe' "$func_basename_result" + func_ltwrapper_scriptname_result="$func_dirname_result/$objdir/${func_stripname_result}_ltshwrapper" + fi +} + +# func_ltwrapper_p file +# True iff FILE is a libtool wrapper script or wrapper executable +# This function is only a basic sanity check; it will hardly flush out +# determined imposters. +func_ltwrapper_p () +{ + func_ltwrapper_script_p "$1" || func_ltwrapper_executable_p "$1" +} + + +# func_execute_cmds commands fail_cmd +# Execute tilde-delimited COMMANDS. +# If FAIL_CMD is given, eval that upon failure. +# FAIL_CMD may read-access the current command in variable CMD! +func_execute_cmds () +{ + $opt_debug + save_ifs=$IFS; IFS='~' + for cmd in $1; do + IFS=$save_ifs + eval cmd=\"$cmd\" + func_show_eval "$cmd" "${2-:}" + done + IFS=$save_ifs +} + + +# func_source file +# Source FILE, adding directory component if necessary. +# Note that it is not necessary on cygwin/mingw to append a dot to +# FILE even if both FILE and FILE.exe exist: automatic-append-.exe +# behavior happens only for exec(3), not for open(2)! Also, sourcing +# `FILE.' does not work on cygwin managed mounts. +func_source () +{ + $opt_debug + case $1 in + */* | *\\*) . "$1" ;; + *) . "./$1" ;; + esac +} + + +# func_infer_tag arg +# Infer tagged configuration to use if any are available and +# if one wasn't chosen via the "--tag" command line option. +# Only attempt this if the compiler in the base compile +# command doesn't match the default compiler. +# arg is usually of the form 'gcc ...' +func_infer_tag () +{ + $opt_debug + if test -n "$available_tags" && test -z "$tagname"; then + CC_quoted= + for arg in $CC; do + func_quote_for_eval "$arg" + CC_quoted="$CC_quoted $func_quote_for_eval_result" + done + case $@ in + # Blanks in the command may have been stripped by the calling shell, + # but not from the CC environment variable when configure was run. + " $CC "* | "$CC "* | " `$ECHO $CC` "* | "`$ECHO $CC` "* | " $CC_quoted"* | "$CC_quoted "* | " `$ECHO $CC_quoted` "* | "`$ECHO $CC_quoted` "*) ;; + # Blanks at the start of $base_compile will cause this to fail + # if we don't check for them as well. + *) + for z in $available_tags; do + if $GREP "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$progpath" > /dev/null; then + # Evaluate the configuration. + eval "`${SED} -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# ### END LIBTOOL TAG CONFIG: '$z'$/p' < $progpath`" + CC_quoted= + for arg in $CC; do + # Double-quote args containing other shell metacharacters. + func_quote_for_eval "$arg" + CC_quoted="$CC_quoted $func_quote_for_eval_result" + done + case "$@ " in + " $CC "* | "$CC "* | " `$ECHO $CC` "* | "`$ECHO $CC` "* | " $CC_quoted"* | "$CC_quoted "* | " `$ECHO $CC_quoted` "* | "`$ECHO $CC_quoted` "*) + # The compiler in the base compile command matches + # the one in the tagged configuration. + # Assume this is the tagged configuration we want. + tagname=$z + break + ;; + esac + fi + done + # If $tagname still isn't set, then no tagged configuration + # was found and let the user know that the "--tag" command + # line option must be used. + if test -z "$tagname"; then + func_echo "unable to infer tagged configuration" + func_fatal_error "specify a tag with \`--tag'" +# else +# func_verbose "using $tagname tagged configuration" + fi + ;; + esac + fi +} + + + +# func_write_libtool_object output_name pic_name nonpic_name +# Create a libtool object file (analogous to a ".la" file), +# but don't create it if we're doing a dry run. +func_write_libtool_object () +{ + write_libobj=${1} + if test "$build_libtool_libs" = yes; then + write_lobj=\'${2}\' + else + write_lobj=none + fi + + if test "$build_old_libs" = yes; then + write_oldobj=\'${3}\' + else + write_oldobj=none + fi + + $opt_dry_run || { + cat >${write_libobj}T <?"'"'"' &()|`$[]' \ + && func_warning "libobj name \`$libobj' may not contain shell special characters." + func_dirname_and_basename "$obj" "/" "" + objname="$func_basename_result" + xdir="$func_dirname_result" + lobj=${xdir}$objdir/$objname + + test -z "$base_compile" && \ + func_fatal_help "you must specify a compilation command" + + # Delete any leftover library objects. + if test "$build_old_libs" = yes; then + removelist="$obj $lobj $libobj ${libobj}T" + else + removelist="$lobj $libobj ${libobj}T" + fi + + # On Cygwin there's no "real" PIC flag so we must build both object types + case $host_os in + cygwin* | mingw* | pw32* | os2* | cegcc*) + pic_mode=default + ;; + esac + if test "$pic_mode" = no && test "$deplibs_check_method" != pass_all; then + # non-PIC code in shared libraries is not supported + pic_mode=default + fi + + # Calculate the filename of the output object if compiler does + # not support -o with -c + if test "$compiler_c_o" = no; then + output_obj=`$ECHO "X$srcfile" | $Xsed -e 's%^.*/%%' -e 's%\.[^.]*$%%'`.${objext} + lockfile="$output_obj.lock" + else + output_obj= + need_locks=no + lockfile= + fi + + # Lock this critical section if it is needed + # We use this script file to make the link, it avoids creating a new file + if test "$need_locks" = yes; then + until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do + func_echo "Waiting for $lockfile to be removed" + sleep 2 + done + elif test "$need_locks" = warn; then + if test -f "$lockfile"; then + $ECHO "\ +*** ERROR, $lockfile exists and contains: +`cat $lockfile 2>/dev/null` + +This indicates that another process is trying to use the same +temporary object file, and libtool could not work around it because +your compiler does not support \`-c' and \`-o' together. If you +repeat this compilation, it may succeed, by chance, but you had better +avoid parallel builds (make -j) in this platform, or get a better +compiler." + + $opt_dry_run || $RM $removelist + exit $EXIT_FAILURE + fi + removelist="$removelist $output_obj" + $ECHO "$srcfile" > "$lockfile" + fi + + $opt_dry_run || $RM $removelist + removelist="$removelist $lockfile" + trap '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE' 1 2 15 + + if test -n "$fix_srcfile_path"; then + eval srcfile=\"$fix_srcfile_path\" + fi + func_quote_for_eval "$srcfile" + qsrcfile=$func_quote_for_eval_result + + # Only build a PIC object if we are building libtool libraries. + if test "$build_libtool_libs" = yes; then + # Without this assignment, base_compile gets emptied. + fbsd_hideous_sh_bug=$base_compile + + if test "$pic_mode" != no; then + command="$base_compile $qsrcfile $pic_flag" + else + # Don't build PIC code + command="$base_compile $qsrcfile" + fi + + func_mkdir_p "$xdir$objdir" + + if test -z "$output_obj"; then + # Place PIC objects in $objdir + command="$command -o $lobj" + fi + + func_show_eval_locale "$command" \ + 'test -n "$output_obj" && $RM $removelist; exit $EXIT_FAILURE' + + if test "$need_locks" = warn && + test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then + $ECHO "\ +*** ERROR, $lockfile contains: +`cat $lockfile 2>/dev/null` + +but it should contain: +$srcfile + +This indicates that another process is trying to use the same +temporary object file, and libtool could not work around it because +your compiler does not support \`-c' and \`-o' together. If you +repeat this compilation, it may succeed, by chance, but you had better +avoid parallel builds (make -j) in this platform, or get a better +compiler." + + $opt_dry_run || $RM $removelist + exit $EXIT_FAILURE + fi + + # Just move the object if needed, then go on to compile the next one + if test -n "$output_obj" && test "X$output_obj" != "X$lobj"; then + func_show_eval '$MV "$output_obj" "$lobj"' \ + 'error=$?; $opt_dry_run || $RM $removelist; exit $error' + fi + + # Allow error messages only from the first compilation. + if test "$suppress_opt" = yes; then + suppress_output=' >/dev/null 2>&1' + fi + fi + + # Only build a position-dependent object if we build old libraries. + if test "$build_old_libs" = yes; then + if test "$pic_mode" != yes; then + # Don't build PIC code + command="$base_compile $qsrcfile$pie_flag" + else + command="$base_compile $qsrcfile $pic_flag" + fi + if test "$compiler_c_o" = yes; then + command="$command -o $obj" + fi + + # Suppress compiler output if we already did a PIC compilation. + command="$command$suppress_output" + func_show_eval_locale "$command" \ + '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE' + + if test "$need_locks" = warn && + test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then + $ECHO "\ +*** ERROR, $lockfile contains: +`cat $lockfile 2>/dev/null` + +but it should contain: +$srcfile + +This indicates that another process is trying to use the same +temporary object file, and libtool could not work around it because +your compiler does not support \`-c' and \`-o' together. If you +repeat this compilation, it may succeed, by chance, but you had better +avoid parallel builds (make -j) in this platform, or get a better +compiler." + + $opt_dry_run || $RM $removelist + exit $EXIT_FAILURE + fi + + # Just move the object if needed + if test -n "$output_obj" && test "X$output_obj" != "X$obj"; then + func_show_eval '$MV "$output_obj" "$obj"' \ + 'error=$?; $opt_dry_run || $RM $removelist; exit $error' + fi + fi + + $opt_dry_run || { + func_write_libtool_object "$libobj" "$objdir/$objname" "$objname" + + # Unlock the critical section if it was locked + if test "$need_locks" != no; then + removelist=$lockfile + $RM "$lockfile" + fi + } + + exit $EXIT_SUCCESS +} + +$opt_help || { +test "$mode" = compile && func_mode_compile ${1+"$@"} +} + +func_mode_help () +{ + # We need to display help for each of the modes. + case $mode in + "") + # Generic help is extracted from the usage comments + # at the start of this file. + func_help + ;; + + clean) + $ECHO \ +"Usage: $progname [OPTION]... --mode=clean RM [RM-OPTION]... FILE... + +Remove files from the build directory. + +RM is the name of the program to use to delete files associated with each FILE +(typically \`/bin/rm'). RM-OPTIONS are options (such as \`-f') to be passed +to RM. + +If FILE is a libtool library, object or program, all the files associated +with it are deleted. Otherwise, only FILE itself is deleted using RM." + ;; + + compile) + $ECHO \ +"Usage: $progname [OPTION]... --mode=compile COMPILE-COMMAND... SOURCEFILE + +Compile a source file into a libtool library object. + +This mode accepts the following additional options: + + -o OUTPUT-FILE set the output file name to OUTPUT-FILE + -no-suppress do not suppress compiler output for multiple passes + -prefer-pic try to building PIC objects only + -prefer-non-pic try to building non-PIC objects only + -shared do not build a \`.o' file suitable for static linking + -static only build a \`.o' file suitable for static linking + +COMPILE-COMMAND is a command to be used in creating a \`standard' object file +from the given SOURCEFILE. + +The output file name is determined by removing the directory component from +SOURCEFILE, then substituting the C source code suffix \`.c' with the +library object suffix, \`.lo'." + ;; + + execute) + $ECHO \ +"Usage: $progname [OPTION]... --mode=execute COMMAND [ARGS]... + +Automatically set library path, then run a program. + +This mode accepts the following additional options: + + -dlopen FILE add the directory containing FILE to the library path + +This mode sets the library path environment variable according to \`-dlopen' +flags. + +If any of the ARGS are libtool executable wrappers, then they are translated +into their corresponding uninstalled binary, and any of their required library +directories are added to the library path. + +Then, COMMAND is executed, with ARGS as arguments." + ;; + + finish) + $ECHO \ +"Usage: $progname [OPTION]... --mode=finish [LIBDIR]... + +Complete the installation of libtool libraries. + +Each LIBDIR is a directory that contains libtool libraries. + +The commands that this mode executes may require superuser privileges. Use +the \`--dry-run' option if you just want to see what would be executed." + ;; + + install) + $ECHO \ +"Usage: $progname [OPTION]... --mode=install INSTALL-COMMAND... + +Install executables or libraries. + +INSTALL-COMMAND is the installation command. The first component should be +either the \`install' or \`cp' program. + +The following components of INSTALL-COMMAND are treated specially: + + -inst-prefix PREFIX-DIR Use PREFIX-DIR as a staging area for installation + +The rest of the components are interpreted as arguments to that command (only +BSD-compatible install options are recognized)." + ;; + + link) + $ECHO \ +"Usage: $progname [OPTION]... --mode=link LINK-COMMAND... + +Link object files or libraries together to form another library, or to +create an executable program. + +LINK-COMMAND is a command using the C compiler that you would use to create +a program from several object files. + +The following components of LINK-COMMAND are treated specially: + + -all-static do not do any dynamic linking at all + -avoid-version do not add a version suffix if possible + -dlopen FILE \`-dlpreopen' FILE if it cannot be dlopened at runtime + -dlpreopen FILE link in FILE and add its symbols to lt_preloaded_symbols + -export-dynamic allow symbols from OUTPUT-FILE to be resolved with dlsym(3) + -export-symbols SYMFILE + try to export only the symbols listed in SYMFILE + -export-symbols-regex REGEX + try to export only the symbols matching REGEX + -LLIBDIR search LIBDIR for required installed libraries + -lNAME OUTPUT-FILE requires the installed library libNAME + -module build a library that can dlopened + -no-fast-install disable the fast-install mode + -no-install link a not-installable executable + -no-undefined declare that a library does not refer to external symbols + -o OUTPUT-FILE create OUTPUT-FILE from the specified objects + -objectlist FILE Use a list of object files found in FILE to specify objects + -precious-files-regex REGEX + don't remove output files matching REGEX + -release RELEASE specify package release information + -rpath LIBDIR the created library will eventually be installed in LIBDIR + -R[ ]LIBDIR add LIBDIR to the runtime path of programs and libraries + -shared only do dynamic linking of libtool libraries + -shrext SUFFIX override the standard shared library file extension + -static do not do any dynamic linking of uninstalled libtool libraries + -static-libtool-libs + do not do any dynamic linking of libtool libraries + -version-info CURRENT[:REVISION[:AGE]] + specify library version info [each variable defaults to 0] + -weak LIBNAME declare that the target provides the LIBNAME interface + +All other options (arguments beginning with \`-') are ignored. + +Every other argument is treated as a filename. Files ending in \`.la' are +treated as uninstalled libtool libraries, other files are standard or library +object files. + +If the OUTPUT-FILE ends in \`.la', then a libtool library is created, +only library objects (\`.lo' files) may be specified, and \`-rpath' is +required, except when creating a convenience library. + +If OUTPUT-FILE ends in \`.a' or \`.lib', then a standard library is created +using \`ar' and \`ranlib', or on Windows using \`lib'. + +If OUTPUT-FILE ends in \`.lo' or \`.${objext}', then a reloadable object file +is created, otherwise an executable program is created." + ;; + + uninstall) + $ECHO \ +"Usage: $progname [OPTION]... --mode=uninstall RM [RM-OPTION]... FILE... + +Remove libraries from an installation directory. + +RM is the name of the program to use to delete files associated with each FILE +(typically \`/bin/rm'). RM-OPTIONS are options (such as \`-f') to be passed +to RM. + +If FILE is a libtool library, all the files associated with it are deleted. +Otherwise, only FILE itself is deleted using RM." + ;; + + *) + func_fatal_help "invalid operation mode \`$mode'" + ;; + esac + + $ECHO + $ECHO "Try \`$progname --help' for more information about other modes." + + exit $? +} + + # Now that we've collected a possible --mode arg, show help if necessary + $opt_help && func_mode_help + + +# func_mode_execute arg... +func_mode_execute () +{ + $opt_debug + # The first argument is the command name. + cmd="$nonopt" + test -z "$cmd" && \ + func_fatal_help "you must specify a COMMAND" + + # Handle -dlopen flags immediately. + for file in $execute_dlfiles; do + test -f "$file" \ + || func_fatal_help "\`$file' is not a file" + + dir= + case $file in + *.la) + # Check to see that this really is a libtool archive. + func_lalib_unsafe_p "$file" \ + || func_fatal_help "\`$lib' is not a valid libtool archive" + + # Read the libtool library. + dlname= + library_names= + func_source "$file" + + # Skip this library if it cannot be dlopened. + if test -z "$dlname"; then + # Warn if it was a shared library. + test -n "$library_names" && \ + func_warning "\`$file' was not linked with \`-export-dynamic'" + continue + fi + + func_dirname "$file" "" "." + dir="$func_dirname_result" + + if test -f "$dir/$objdir/$dlname"; then + dir="$dir/$objdir" + else + if test ! -f "$dir/$dlname"; then + func_fatal_error "cannot find \`$dlname' in \`$dir' or \`$dir/$objdir'" + fi + fi + ;; + + *.lo) + # Just add the directory containing the .lo file. + func_dirname "$file" "" "." + dir="$func_dirname_result" + ;; + + *) + func_warning "\`-dlopen' is ignored for non-libtool libraries and objects" + continue + ;; + esac + + # Get the absolute pathname. + absdir=`cd "$dir" && pwd` + test -n "$absdir" && dir="$absdir" + + # Now add the directory to shlibpath_var. + if eval "test -z \"\$$shlibpath_var\""; then + eval "$shlibpath_var=\"\$dir\"" + else + eval "$shlibpath_var=\"\$dir:\$$shlibpath_var\"" + fi + done + + # This variable tells wrapper scripts just to set shlibpath_var + # rather than running their programs. + libtool_execute_magic="$magic" + + # Check if any of the arguments is a wrapper script. + args= + for file + do + case $file in + -*) ;; + *) + # Do a test to see if this is really a libtool program. + if func_ltwrapper_script_p "$file"; then + func_source "$file" + # Transform arg to wrapped name. + file="$progdir/$program" + elif func_ltwrapper_executable_p "$file"; then + func_ltwrapper_scriptname "$file" + func_source "$func_ltwrapper_scriptname_result" + # Transform arg to wrapped name. + file="$progdir/$program" + fi + ;; + esac + # Quote arguments (to preserve shell metacharacters). + func_quote_for_eval "$file" + args="$args $func_quote_for_eval_result" + done + + if test "X$opt_dry_run" = Xfalse; then + if test -n "$shlibpath_var"; then + # Export the shlibpath_var. + eval "export $shlibpath_var" + fi + + # Restore saved environment variables + for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES + do + eval "if test \"\${save_$lt_var+set}\" = set; then + $lt_var=\$save_$lt_var; export $lt_var + else + $lt_unset $lt_var + fi" + done + + # Now prepare to actually exec the command. + exec_cmd="\$cmd$args" + else + # Display what would be done. + if test -n "$shlibpath_var"; then + eval "\$ECHO \"\$shlibpath_var=\$$shlibpath_var\"" + $ECHO "export $shlibpath_var" + fi + $ECHO "$cmd$args" + exit $EXIT_SUCCESS + fi +} + +test "$mode" = execute && func_mode_execute ${1+"$@"} + + +# func_mode_finish arg... +func_mode_finish () +{ + $opt_debug + libdirs="$nonopt" + admincmds= + + if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then + for dir + do + libdirs="$libdirs $dir" + done + + for libdir in $libdirs; do + if test -n "$finish_cmds"; then + # Do each command in the finish commands. + func_execute_cmds "$finish_cmds" 'admincmds="$admincmds +'"$cmd"'"' + fi + if test -n "$finish_eval"; then + # Do the single finish_eval. + eval cmds=\"$finish_eval\" + $opt_dry_run || eval "$cmds" || admincmds="$admincmds + $cmds" + fi + done + fi + + # Exit here if they wanted silent mode. + $opt_silent && exit $EXIT_SUCCESS + + $ECHO "X----------------------------------------------------------------------" | $Xsed + $ECHO "Libraries have been installed in:" + for libdir in $libdirs; do + $ECHO " $libdir" + done + $ECHO + $ECHO "If you ever happen to want to link against installed libraries" + $ECHO "in a given directory, LIBDIR, you must either use libtool, and" + $ECHO "specify the full pathname of the library, or use the \`-LLIBDIR'" + $ECHO "flag during linking and do at least one of the following:" + if test -n "$shlibpath_var"; then + $ECHO " - add LIBDIR to the \`$shlibpath_var' environment variable" + $ECHO " during execution" + fi + if test -n "$runpath_var"; then + $ECHO " - add LIBDIR to the \`$runpath_var' environment variable" + $ECHO " during linking" + fi + if test -n "$hardcode_libdir_flag_spec"; then + libdir=LIBDIR + eval flag=\"$hardcode_libdir_flag_spec\" + + $ECHO " - use the \`$flag' linker flag" + fi + if test -n "$admincmds"; then + $ECHO " - have your system administrator run these commands:$admincmds" + fi + if test -f /etc/ld.so.conf; then + $ECHO " - have your system administrator add LIBDIR to \`/etc/ld.so.conf'" + fi + $ECHO + + $ECHO "See any operating system documentation about shared libraries for" + case $host in + solaris2.[6789]|solaris2.1[0-9]) + $ECHO "more information, such as the ld(1), crle(1) and ld.so(8) manual" + $ECHO "pages." + ;; + *) + $ECHO "more information, such as the ld(1) and ld.so(8) manual pages." + ;; + esac + $ECHO "X----------------------------------------------------------------------" | $Xsed + exit $EXIT_SUCCESS +} + +test "$mode" = finish && func_mode_finish ${1+"$@"} + + +# func_mode_install arg... +func_mode_install () +{ + $opt_debug + # There may be an optional sh(1) argument at the beginning of + # install_prog (especially on Windows NT). + if test "$nonopt" = "$SHELL" || test "$nonopt" = /bin/sh || + # Allow the use of GNU shtool's install command. + $ECHO "X$nonopt" | $GREP shtool >/dev/null; then + # Aesthetically quote it. + func_quote_for_eval "$nonopt" + install_prog="$func_quote_for_eval_result " + arg=$1 + shift + else + install_prog= + arg=$nonopt + fi + + # The real first argument should be the name of the installation program. + # Aesthetically quote it. + func_quote_for_eval "$arg" + install_prog="$install_prog$func_quote_for_eval_result" + + # We need to accept at least all the BSD install flags. + dest= + files= + opts= + prev= + install_type= + isdir=no + stripme= + for arg + do + if test -n "$dest"; then + files="$files $dest" + dest=$arg + continue + fi + + case $arg in + -d) isdir=yes ;; + -f) + case " $install_prog " in + *[\\\ /]cp\ *) ;; + *) prev=$arg ;; + esac + ;; + -g | -m | -o) + prev=$arg + ;; + -s) + stripme=" -s" + continue + ;; + -*) + ;; + *) + # If the previous option needed an argument, then skip it. + if test -n "$prev"; then + prev= + else + dest=$arg + continue + fi + ;; + esac + + # Aesthetically quote the argument. + func_quote_for_eval "$arg" + install_prog="$install_prog $func_quote_for_eval_result" + done + + test -z "$install_prog" && \ + func_fatal_help "you must specify an install program" + + test -n "$prev" && \ + func_fatal_help "the \`$prev' option requires an argument" + + if test -z "$files"; then + if test -z "$dest"; then + func_fatal_help "no file or destination specified" + else + func_fatal_help "you must specify a destination" + fi + fi + + # Strip any trailing slash from the destination. + func_stripname '' '/' "$dest" + dest=$func_stripname_result + + # Check to see that the destination is a directory. + test -d "$dest" && isdir=yes + if test "$isdir" = yes; then + destdir="$dest" + destname= + else + func_dirname_and_basename "$dest" "" "." + destdir="$func_dirname_result" + destname="$func_basename_result" + + # Not a directory, so check to see that there is only one file specified. + set dummy $files; shift + test "$#" -gt 1 && \ + func_fatal_help "\`$dest' is not a directory" + fi + case $destdir in + [\\/]* | [A-Za-z]:[\\/]*) ;; + *) + for file in $files; do + case $file in + *.lo) ;; + *) + func_fatal_help "\`$destdir' must be an absolute directory name" + ;; + esac + done + ;; + esac + + # This variable tells wrapper scripts just to set variables rather + # than running their programs. + libtool_install_magic="$magic" + + staticlibs= + future_libdirs= + current_libdirs= + for file in $files; do + + # Do each installation. + case $file in + *.$libext) + # Do the static libraries later. + staticlibs="$staticlibs $file" + ;; + + *.la) + # Check to see that this really is a libtool archive. + func_lalib_unsafe_p "$file" \ + || func_fatal_help "\`$file' is not a valid libtool archive" + + library_names= + old_library= + relink_command= + func_source "$file" + + # Add the libdir to current_libdirs if it is the destination. + if test "X$destdir" = "X$libdir"; then + case "$current_libdirs " in + *" $libdir "*) ;; + *) current_libdirs="$current_libdirs $libdir" ;; + esac + else + # Note the libdir as a future libdir. + case "$future_libdirs " in + *" $libdir "*) ;; + *) future_libdirs="$future_libdirs $libdir" ;; + esac + fi + + func_dirname "$file" "/" "" + dir="$func_dirname_result" + dir="$dir$objdir" + + if test -n "$relink_command"; then + # Determine the prefix the user has applied to our future dir. + inst_prefix_dir=`$ECHO "X$destdir" | $Xsed -e "s%$libdir\$%%"` + + # Don't allow the user to place us outside of our expected + # location b/c this prevents finding dependent libraries that + # are installed to the same prefix. + # At present, this check doesn't affect windows .dll's that + # are installed into $libdir/../bin (currently, that works fine) + # but it's something to keep an eye on. + test "$inst_prefix_dir" = "$destdir" && \ + func_fatal_error "error: cannot install \`$file' to a directory not ending in $libdir" + + if test -n "$inst_prefix_dir"; then + # Stick the inst_prefix_dir data into the link command. + relink_command=`$ECHO "X$relink_command" | $Xsed -e "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%"` + else + relink_command=`$ECHO "X$relink_command" | $Xsed -e "s%@inst_prefix_dir@%%"` + fi + + func_warning "relinking \`$file'" + func_show_eval "$relink_command" \ + 'func_fatal_error "error: relink \`$file'\'' with the above command before installing it"' + fi + + # See the names of the shared library. + set dummy $library_names; shift + if test -n "$1"; then + realname="$1" + shift + + srcname="$realname" + test -n "$relink_command" && srcname="$realname"T + + # Install the shared library and build the symlinks. + func_show_eval "$install_prog $dir/$srcname $destdir/$realname" \ + 'exit $?' + tstripme="$stripme" + case $host_os in + cygwin* | mingw* | pw32* | cegcc*) + case $realname in + *.dll.a) + tstripme="" + ;; + esac + ;; + esac + if test -n "$tstripme" && test -n "$striplib"; then + func_show_eval "$striplib $destdir/$realname" 'exit $?' + fi + + if test "$#" -gt 0; then + # Delete the old symlinks, and create new ones. + # Try `ln -sf' first, because the `ln' binary might depend on + # the symlink we replace! Solaris /bin/ln does not understand -f, + # so we also need to try rm && ln -s. + for linkname + do + test "$linkname" != "$realname" \ + && func_show_eval "(cd $destdir && { $LN_S -f $realname $linkname || { $RM $linkname && $LN_S $realname $linkname; }; })" + done + fi + + # Do each command in the postinstall commands. + lib="$destdir/$realname" + func_execute_cmds "$postinstall_cmds" 'exit $?' + fi + + # Install the pseudo-library for information purposes. + func_basename "$file" + name="$func_basename_result" + instname="$dir/$name"i + func_show_eval "$install_prog $instname $destdir/$name" 'exit $?' + + # Maybe install the static library, too. + test -n "$old_library" && staticlibs="$staticlibs $dir/$old_library" + ;; + + *.lo) + # Install (i.e. copy) a libtool object. + + # Figure out destination file name, if it wasn't already specified. + if test -n "$destname"; then + destfile="$destdir/$destname" + else + func_basename "$file" + destfile="$func_basename_result" + destfile="$destdir/$destfile" + fi + + # Deduce the name of the destination old-style object file. + case $destfile in + *.lo) + func_lo2o "$destfile" + staticdest=$func_lo2o_result + ;; + *.$objext) + staticdest="$destfile" + destfile= + ;; + *) + func_fatal_help "cannot copy a libtool object to \`$destfile'" + ;; + esac + + # Install the libtool object if requested. + test -n "$destfile" && \ + func_show_eval "$install_prog $file $destfile" 'exit $?' + + # Install the old object if enabled. + if test "$build_old_libs" = yes; then + # Deduce the name of the old-style object file. + func_lo2o "$file" + staticobj=$func_lo2o_result + func_show_eval "$install_prog \$staticobj \$staticdest" 'exit $?' + fi + exit $EXIT_SUCCESS + ;; + + *) + # Figure out destination file name, if it wasn't already specified. + if test -n "$destname"; then + destfile="$destdir/$destname" + else + func_basename "$file" + destfile="$func_basename_result" + destfile="$destdir/$destfile" + fi + + # If the file is missing, and there is a .exe on the end, strip it + # because it is most likely a libtool script we actually want to + # install + stripped_ext="" + case $file in + *.exe) + if test ! -f "$file"; then + func_stripname '' '.exe' "$file" + file=$func_stripname_result + stripped_ext=".exe" + fi + ;; + esac + + # Do a test to see if this is really a libtool program. + case $host in + *cygwin* | *mingw*) + if func_ltwrapper_executable_p "$file"; then + func_ltwrapper_scriptname "$file" + wrapper=$func_ltwrapper_scriptname_result + else + func_stripname '' '.exe' "$file" + wrapper=$func_stripname_result + fi + ;; + *) + wrapper=$file + ;; + esac + if func_ltwrapper_script_p "$wrapper"; then + notinst_deplibs= + relink_command= + + func_source "$wrapper" + + # Check the variables that should have been set. + test -z "$generated_by_libtool_version" && \ + func_fatal_error "invalid libtool wrapper script \`$wrapper'" + + finalize=yes + for lib in $notinst_deplibs; do + # Check to see that each library is installed. + libdir= + if test -f "$lib"; then + func_source "$lib" + fi + libfile="$libdir/"`$ECHO "X$lib" | $Xsed -e 's%^.*/%%g'` ### testsuite: skip nested quoting test + if test -n "$libdir" && test ! -f "$libfile"; then + func_warning "\`$lib' has not been installed in \`$libdir'" + finalize=no + fi + done + + relink_command= + func_source "$wrapper" + + outputname= + if test "$fast_install" = no && test -n "$relink_command"; then + $opt_dry_run || { + if test "$finalize" = yes; then + tmpdir=`func_mktempdir` + func_basename "$file$stripped_ext" + file="$func_basename_result" + outputname="$tmpdir/$file" + # Replace the output file specification. + relink_command=`$ECHO "X$relink_command" | $Xsed -e 's%@OUTPUT@%'"$outputname"'%g'` + + $opt_silent || { + func_quote_for_expand "$relink_command" + eval "func_echo $func_quote_for_expand_result" + } + if eval "$relink_command"; then : + else + func_error "error: relink \`$file' with the above command before installing it" + $opt_dry_run || ${RM}r "$tmpdir" + continue + fi + file="$outputname" + else + func_warning "cannot relink \`$file'" + fi + } + else + # Install the binary that we compiled earlier. + file=`$ECHO "X$file$stripped_ext" | $Xsed -e "s%\([^/]*\)$%$objdir/\1%"` + fi + fi + + # remove .exe since cygwin /usr/bin/install will append another + # one anyway + case $install_prog,$host in + */usr/bin/install*,*cygwin*) + case $file:$destfile in + *.exe:*.exe) + # this is ok + ;; + *.exe:*) + destfile=$destfile.exe + ;; + *:*.exe) + func_stripname '' '.exe' "$destfile" + destfile=$func_stripname_result + ;; + esac + ;; + esac + func_show_eval "$install_prog\$stripme \$file \$destfile" 'exit $?' + $opt_dry_run || if test -n "$outputname"; then + ${RM}r "$tmpdir" + fi + ;; + esac + done + + for file in $staticlibs; do + func_basename "$file" + name="$func_basename_result" + + # Set up the ranlib parameters. + oldlib="$destdir/$name" + + func_show_eval "$install_prog \$file \$oldlib" 'exit $?' + + if test -n "$stripme" && test -n "$old_striplib"; then + func_show_eval "$old_striplib $oldlib" 'exit $?' + fi + + # Do each command in the postinstall commands. + func_execute_cmds "$old_postinstall_cmds" 'exit $?' + done + + test -n "$future_libdirs" && \ + func_warning "remember to run \`$progname --finish$future_libdirs'" + + if test -n "$current_libdirs"; then + # Maybe just do a dry run. + $opt_dry_run && current_libdirs=" -n$current_libdirs" + exec_cmd='$SHELL $progpath $preserve_args --finish$current_libdirs' + else + exit $EXIT_SUCCESS + fi +} + +test "$mode" = install && func_mode_install ${1+"$@"} + + +# func_generate_dlsyms outputname originator pic_p +# Extract symbols from dlprefiles and create ${outputname}S.o with +# a dlpreopen symbol table. +func_generate_dlsyms () +{ + $opt_debug + my_outputname="$1" + my_originator="$2" + my_pic_p="${3-no}" + my_prefix=`$ECHO "$my_originator" | sed 's%[^a-zA-Z0-9]%_%g'` + my_dlsyms= + + if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then + if test -n "$NM" && test -n "$global_symbol_pipe"; then + my_dlsyms="${my_outputname}S.c" + else + func_error "not configured to extract global symbols from dlpreopened files" + fi + fi + + if test -n "$my_dlsyms"; then + case $my_dlsyms in + "") ;; + *.c) + # Discover the nlist of each of the dlfiles. + nlist="$output_objdir/${my_outputname}.nm" + + func_show_eval "$RM $nlist ${nlist}S ${nlist}T" + + # Parse the name list into a source file. + func_verbose "creating $output_objdir/$my_dlsyms" + + $opt_dry_run || $ECHO > "$output_objdir/$my_dlsyms" "\ +/* $my_dlsyms - symbol resolution table for \`$my_outputname' dlsym emulation. */ +/* Generated by $PROGRAM (GNU $PACKAGE$TIMESTAMP) $VERSION */ + +#ifdef __cplusplus +extern \"C\" { +#endif + +/* External symbol declarations for the compiler. */\ +" + + if test "$dlself" = yes; then + func_verbose "generating symbol list for \`$output'" + + $opt_dry_run || echo ': @PROGRAM@ ' > "$nlist" + + # Add our own program objects to the symbol list. + progfiles=`$ECHO "X$objs$old_deplibs" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP` + for progfile in $progfiles; do + func_verbose "extracting global C symbols from \`$progfile'" + $opt_dry_run || eval "$NM $progfile | $global_symbol_pipe >> '$nlist'" + done + + if test -n "$exclude_expsyms"; then + $opt_dry_run || { + eval '$EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T' + eval '$MV "$nlist"T "$nlist"' + } + fi + + if test -n "$export_symbols_regex"; then + $opt_dry_run || { + eval '$EGREP -e "$export_symbols_regex" "$nlist" > "$nlist"T' + eval '$MV "$nlist"T "$nlist"' + } + fi + + # Prepare the list of exported symbols + if test -z "$export_symbols"; then + export_symbols="$output_objdir/$outputname.exp" + $opt_dry_run || { + $RM $export_symbols + eval "${SED} -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"' + case $host in + *cygwin* | *mingw* | *cegcc* ) + eval "echo EXPORTS "'> "$output_objdir/$outputname.def"' + eval 'cat "$export_symbols" >> "$output_objdir/$outputname.def"' + ;; + esac + } + else + $opt_dry_run || { + eval "${SED} -e 's/\([].[*^$]\)/\\\\\1/g' -e 's/^/ /' -e 's/$/$/'"' < "$export_symbols" > "$output_objdir/$outputname.exp"' + eval '$GREP -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T' + eval '$MV "$nlist"T "$nlist"' + case $host in + *cygwin | *mingw* | *cegcc* ) + eval "echo EXPORTS "'> "$output_objdir/$outputname.def"' + eval 'cat "$nlist" >> "$output_objdir/$outputname.def"' + ;; + esac + } + fi + fi + + for dlprefile in $dlprefiles; do + func_verbose "extracting global C symbols from \`$dlprefile'" + func_basename "$dlprefile" + name="$func_basename_result" + $opt_dry_run || { + eval '$ECHO ": $name " >> "$nlist"' + eval "$NM $dlprefile 2>/dev/null | $global_symbol_pipe >> '$nlist'" + } + done + + $opt_dry_run || { + # Make sure we have at least an empty file. + test -f "$nlist" || : > "$nlist" + + if test -n "$exclude_expsyms"; then + $EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T + $MV "$nlist"T "$nlist" + fi + + # Try sorting and uniquifying the output. + if $GREP -v "^: " < "$nlist" | + if sort -k 3 /dev/null 2>&1; then + sort -k 3 + else + sort +2 + fi | + uniq > "$nlist"S; then + : + else + $GREP -v "^: " < "$nlist" > "$nlist"S + fi + + if test -f "$nlist"S; then + eval "$global_symbol_to_cdecl"' < "$nlist"S >> "$output_objdir/$my_dlsyms"' + else + $ECHO '/* NONE */' >> "$output_objdir/$my_dlsyms" + fi + + $ECHO >> "$output_objdir/$my_dlsyms" "\ + +/* The mapping between symbol names and symbols. */ +typedef struct { + const char *name; + void *address; +} lt_dlsymlist; +" + case $host in + *cygwin* | *mingw* | *cegcc* ) + $ECHO >> "$output_objdir/$my_dlsyms" "\ +/* DATA imports from DLLs on WIN32 con't be const, because + runtime relocations are performed -- see ld's documentation + on pseudo-relocs. */" + lt_dlsym_const= ;; + *osf5*) + echo >> "$output_objdir/$my_dlsyms" "\ +/* This system does not cope well with relocations in const data */" + lt_dlsym_const= ;; + *) + lt_dlsym_const=const ;; + esac + + $ECHO >> "$output_objdir/$my_dlsyms" "\ +extern $lt_dlsym_const lt_dlsymlist +lt_${my_prefix}_LTX_preloaded_symbols[]; +$lt_dlsym_const lt_dlsymlist +lt_${my_prefix}_LTX_preloaded_symbols[] = +{\ + { \"$my_originator\", (void *) 0 }," + + case $need_lib_prefix in + no) + eval "$global_symbol_to_c_name_address" < "$nlist" >> "$output_objdir/$my_dlsyms" + ;; + *) + eval "$global_symbol_to_c_name_address_lib_prefix" < "$nlist" >> "$output_objdir/$my_dlsyms" + ;; + esac + $ECHO >> "$output_objdir/$my_dlsyms" "\ + {0, (void *) 0} +}; + +/* This works around a problem in FreeBSD linker */ +#ifdef FREEBSD_WORKAROUND +static const void *lt_preloaded_setup() { + return lt_${my_prefix}_LTX_preloaded_symbols; +} +#endif + +#ifdef __cplusplus +} +#endif\ +" + } # !$opt_dry_run + + pic_flag_for_symtable= + case "$compile_command " in + *" -static "*) ;; + *) + case $host in + # compiling the symbol table file with pic_flag works around + # a FreeBSD bug that causes programs to crash when -lm is + # linked before any other PIC object. But we must not use + # pic_flag when linking with -static. The problem exists in + # FreeBSD 2.2.6 and is fixed in FreeBSD 3.1. + *-*-freebsd2*|*-*-freebsd3.0*|*-*-freebsdelf3.0*) + pic_flag_for_symtable=" $pic_flag -DFREEBSD_WORKAROUND" ;; + *-*-hpux*) + pic_flag_for_symtable=" $pic_flag" ;; + *) + if test "X$my_pic_p" != Xno; then + pic_flag_for_symtable=" $pic_flag" + fi + ;; + esac + ;; + esac + symtab_cflags= + for arg in $LTCFLAGS; do + case $arg in + -pie | -fpie | -fPIE) ;; + *) symtab_cflags="$symtab_cflags $arg" ;; + esac + done + + # Now compile the dynamic symbol file. + func_show_eval '(cd $output_objdir && $LTCC$symtab_cflags -c$no_builtin_flag$pic_flag_for_symtable "$my_dlsyms")' 'exit $?' + + # Clean up the generated files. + func_show_eval '$RM "$output_objdir/$my_dlsyms" "$nlist" "${nlist}S" "${nlist}T"' + + # Transform the symbol file into the correct name. + symfileobj="$output_objdir/${my_outputname}S.$objext" + case $host in + *cygwin* | *mingw* | *cegcc* ) + if test -f "$output_objdir/$my_outputname.def"; then + compile_command=`$ECHO "X$compile_command" | $Xsed -e "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"` + finalize_command=`$ECHO "X$finalize_command" | $Xsed -e "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"` + else + compile_command=`$ECHO "X$compile_command" | $Xsed -e "s%@SYMFILE@%$symfileobj%"` + finalize_command=`$ECHO "X$finalize_command" | $Xsed -e "s%@SYMFILE@%$symfileobj%"` + fi + ;; + *) + compile_command=`$ECHO "X$compile_command" | $Xsed -e "s%@SYMFILE@%$symfileobj%"` + finalize_command=`$ECHO "X$finalize_command" | $Xsed -e "s%@SYMFILE@%$symfileobj%"` + ;; + esac + ;; + *) + func_fatal_error "unknown suffix for \`$my_dlsyms'" + ;; + esac + else + # We keep going just in case the user didn't refer to + # lt_preloaded_symbols. The linker will fail if global_symbol_pipe + # really was required. + + # Nullify the symbol file. + compile_command=`$ECHO "X$compile_command" | $Xsed -e "s% @SYMFILE@%%"` + finalize_command=`$ECHO "X$finalize_command" | $Xsed -e "s% @SYMFILE@%%"` + fi +} + +# func_win32_libid arg +# return the library type of file 'arg' +# +# Need a lot of goo to handle *both* DLLs and import libs +# Has to be a shell function in order to 'eat' the argument +# that is supplied when $file_magic_command is called. +func_win32_libid () +{ + $opt_debug + win32_libid_type="unknown" + win32_fileres=`file -L $1 2>/dev/null` + case $win32_fileres in + *ar\ archive\ import\ library*) # definitely import + win32_libid_type="x86 archive import" + ;; + *ar\ archive*) # could be an import, or static + if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null | + $EGREP 'file format pe-i386(.*architecture: i386)?' >/dev/null ; then + win32_nmres=`eval $NM -f posix -A $1 | + $SED -n -e ' + 1,100{ + / I /{ + s,.*,import, + p + q + } + }'` + case $win32_nmres in + import*) win32_libid_type="x86 archive import";; + *) win32_libid_type="x86 archive static";; + esac + fi + ;; + *DLL*) + win32_libid_type="x86 DLL" + ;; + *executable*) # but shell scripts are "executable" too... + case $win32_fileres in + *MS\ Windows\ PE\ Intel*) + win32_libid_type="x86 DLL" + ;; + esac + ;; + esac + $ECHO "$win32_libid_type" +} + + + +# func_extract_an_archive dir oldlib +func_extract_an_archive () +{ + $opt_debug + f_ex_an_ar_dir="$1"; shift + f_ex_an_ar_oldlib="$1" + func_show_eval "(cd \$f_ex_an_ar_dir && $AR x \"\$f_ex_an_ar_oldlib\")" 'exit $?' + if ($AR t "$f_ex_an_ar_oldlib" | sort | sort -uc >/dev/null 2>&1); then + : + else + func_fatal_error "object name conflicts in archive: $f_ex_an_ar_dir/$f_ex_an_ar_oldlib" + fi +} + + +# func_extract_archives gentop oldlib ... +func_extract_archives () +{ + $opt_debug + my_gentop="$1"; shift + my_oldlibs=${1+"$@"} + my_oldobjs="" + my_xlib="" + my_xabs="" + my_xdir="" + + for my_xlib in $my_oldlibs; do + # Extract the objects. + case $my_xlib in + [\\/]* | [A-Za-z]:[\\/]*) my_xabs="$my_xlib" ;; + *) my_xabs=`pwd`"/$my_xlib" ;; + esac + func_basename "$my_xlib" + my_xlib="$func_basename_result" + my_xlib_u=$my_xlib + while :; do + case " $extracted_archives " in + *" $my_xlib_u "*) + func_arith $extracted_serial + 1 + extracted_serial=$func_arith_result + my_xlib_u=lt$extracted_serial-$my_xlib ;; + *) break ;; + esac + done + extracted_archives="$extracted_archives $my_xlib_u" + my_xdir="$my_gentop/$my_xlib_u" + + func_mkdir_p "$my_xdir" + + case $host in + *-darwin*) + func_verbose "Extracting $my_xabs" + # Do not bother doing anything if just a dry run + $opt_dry_run || { + darwin_orig_dir=`pwd` + cd $my_xdir || exit $? + darwin_archive=$my_xabs + darwin_curdir=`pwd` + darwin_base_archive=`basename "$darwin_archive"` + darwin_arches=`$LIPO -info "$darwin_archive" 2>/dev/null | $GREP Architectures 2>/dev/null || true` + if test -n "$darwin_arches"; then + darwin_arches=`$ECHO "$darwin_arches" | $SED -e 's/.*are://'` + darwin_arch= + func_verbose "$darwin_base_archive has multiple architectures $darwin_arches" + for darwin_arch in $darwin_arches ; do + func_mkdir_p "unfat-$$/${darwin_base_archive}-${darwin_arch}" + $LIPO -thin $darwin_arch -output "unfat-$$/${darwin_base_archive}-${darwin_arch}/${darwin_base_archive}" "${darwin_archive}" + cd "unfat-$$/${darwin_base_archive}-${darwin_arch}" + func_extract_an_archive "`pwd`" "${darwin_base_archive}" + cd "$darwin_curdir" + $RM "unfat-$$/${darwin_base_archive}-${darwin_arch}/${darwin_base_archive}" + done # $darwin_arches + ## Okay now we've a bunch of thin objects, gotta fatten them up :) + darwin_filelist=`find unfat-$$ -type f -name \*.o -print -o -name \*.lo -print | $SED -e "$basename" | sort -u` + darwin_file= + darwin_files= + for darwin_file in $darwin_filelist; do + darwin_files=`find unfat-$$ -name $darwin_file -print | $NL2SP` + $LIPO -create -output "$darwin_file" $darwin_files + done # $darwin_filelist + $RM -rf unfat-$$ + cd "$darwin_orig_dir" + else + cd $darwin_orig_dir + func_extract_an_archive "$my_xdir" "$my_xabs" + fi # $darwin_arches + } # !$opt_dry_run + ;; + *) + func_extract_an_archive "$my_xdir" "$my_xabs" + ;; + esac + my_oldobjs="$my_oldobjs "`find $my_xdir -name \*.$objext -print -o -name \*.lo -print | $NL2SP` + done + + func_extract_archives_result="$my_oldobjs" +} + + + +# func_emit_wrapper_part1 [arg=no] +# +# Emit the first part of a libtool wrapper script on stdout. +# For more information, see the description associated with +# func_emit_wrapper(), below. +func_emit_wrapper_part1 () +{ + func_emit_wrapper_part1_arg1=no + if test -n "$1" ; then + func_emit_wrapper_part1_arg1=$1 + fi + + $ECHO "\ +#! $SHELL + +# $output - temporary wrapper script for $objdir/$outputname +# Generated by $PROGRAM (GNU $PACKAGE$TIMESTAMP) $VERSION +# +# The $output program cannot be directly executed until all the libtool +# libraries that it depends on are installed. +# +# This wrapper script should never be moved out of the build directory. +# If it is, it will not operate correctly. + +# Sed substitution that helps us do robust quoting. It backslashifies +# metacharacters that are still active within double-quoted strings. +Xsed='${SED} -e 1s/^X//' +sed_quote_subst='$sed_quote_subst' + +# Be Bourne compatible +if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then + emulate sh + NULLCMD=: + # Zsh 3.x and 4.x performs word splitting on \${1+\"\$@\"}, which + # is contrary to our usage. Disable this feature. + alias -g '\${1+\"\$@\"}'='\"\$@\"' + setopt NO_GLOB_SUBST +else + case \`(set -o) 2>/dev/null\` in *posix*) set -o posix;; esac +fi +BIN_SH=xpg4; export BIN_SH # for Tru64 +DUALCASE=1; export DUALCASE # for MKS sh + +# The HP-UX ksh and POSIX shell print the target directory to stdout +# if CDPATH is set. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + +relink_command=\"$relink_command\" + +# This environment variable determines our operation mode. +if test \"\$libtool_install_magic\" = \"$magic\"; then + # install mode needs the following variables: + generated_by_libtool_version='$macro_version' + notinst_deplibs='$notinst_deplibs' +else + # When we are sourced in execute mode, \$file and \$ECHO are already set. + if test \"\$libtool_execute_magic\" != \"$magic\"; then + ECHO=\"$qecho\" + file=\"\$0\" + # Make sure echo works. + if test \"X\$1\" = X--no-reexec; then + # Discard the --no-reexec flag, and continue. + shift + elif test \"X\`{ \$ECHO '\t'; } 2>/dev/null\`\" = 'X\t'; then + # Yippee, \$ECHO works! + : + else + # Restart under the correct shell, and then maybe \$ECHO will work. + exec $SHELL \"\$0\" --no-reexec \${1+\"\$@\"} + fi + fi\ +" + $ECHO "\ + + # Find the directory that this script lives in. + thisdir=\`\$ECHO \"X\$file\" | \$Xsed -e 's%/[^/]*$%%'\` + test \"x\$thisdir\" = \"x\$file\" && thisdir=. + + # Follow symbolic links until we get to the real thisdir. + file=\`ls -ld \"\$file\" | ${SED} -n 's/.*-> //p'\` + while test -n \"\$file\"; do + destdir=\`\$ECHO \"X\$file\" | \$Xsed -e 's%/[^/]*\$%%'\` + + # If there was a directory component, then change thisdir. + if test \"x\$destdir\" != \"x\$file\"; then + case \"\$destdir\" in + [\\\\/]* | [A-Za-z]:[\\\\/]*) thisdir=\"\$destdir\" ;; + *) thisdir=\"\$thisdir/\$destdir\" ;; + esac + fi + + file=\`\$ECHO \"X\$file\" | \$Xsed -e 's%^.*/%%'\` + file=\`ls -ld \"\$thisdir/\$file\" | ${SED} -n 's/.*-> //p'\` + done +" +} +# end: func_emit_wrapper_part1 + +# func_emit_wrapper_part2 [arg=no] +# +# Emit the second part of a libtool wrapper script on stdout. +# For more information, see the description associated with +# func_emit_wrapper(), below. +func_emit_wrapper_part2 () +{ + func_emit_wrapper_part2_arg1=no + if test -n "$1" ; then + func_emit_wrapper_part2_arg1=$1 + fi + + $ECHO "\ + + # Usually 'no', except on cygwin/mingw when embedded into + # the cwrapper. + WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=$func_emit_wrapper_part2_arg1 + if test \"\$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR\" = \"yes\"; then + # special case for '.' + if test \"\$thisdir\" = \".\"; then + thisdir=\`pwd\` + fi + # remove .libs from thisdir + case \"\$thisdir\" in + *[\\\\/]$objdir ) thisdir=\`\$ECHO \"X\$thisdir\" | \$Xsed -e 's%[\\\\/][^\\\\/]*$%%'\` ;; + $objdir ) thisdir=. ;; + esac + fi + + # Try to get the absolute directory name. + absdir=\`cd \"\$thisdir\" && pwd\` + test -n \"\$absdir\" && thisdir=\"\$absdir\" +" + + if test "$fast_install" = yes; then + $ECHO "\ + program=lt-'$outputname'$exeext + progdir=\"\$thisdir/$objdir\" + + if test ! -f \"\$progdir/\$program\" || + { file=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | ${SED} 1q\`; \\ + test \"X\$file\" != \"X\$progdir/\$program\"; }; then + + file=\"\$\$-\$program\" + + if test ! -d \"\$progdir\"; then + $MKDIR \"\$progdir\" + else + $RM \"\$progdir/\$file\" + fi" + + $ECHO "\ + + # relink executable if necessary + if test -n \"\$relink_command\"; then + if relink_command_output=\`eval \$relink_command 2>&1\`; then : + else + $ECHO \"\$relink_command_output\" >&2 + $RM \"\$progdir/\$file\" + exit 1 + fi + fi + + $MV \"\$progdir/\$file\" \"\$progdir/\$program\" 2>/dev/null || + { $RM \"\$progdir/\$program\"; + $MV \"\$progdir/\$file\" \"\$progdir/\$program\"; } + $RM \"\$progdir/\$file\" + fi" + else + $ECHO "\ + program='$outputname' + progdir=\"\$thisdir/$objdir\" +" + fi + + $ECHO "\ + + if test -f \"\$progdir/\$program\"; then" + + # Export our shlibpath_var if we have one. + if test "$shlibpath_overrides_runpath" = yes && test -n "$shlibpath_var" && test -n "$temp_rpath"; then + $ECHO "\ + # Add our own library path to $shlibpath_var + $shlibpath_var=\"$temp_rpath\$$shlibpath_var\" + + # Some systems cannot cope with colon-terminated $shlibpath_var + # The second colon is a workaround for a bug in BeOS R4 sed + $shlibpath_var=\`\$ECHO \"X\$$shlibpath_var\" | \$Xsed -e 's/::*\$//'\` + + export $shlibpath_var +" + fi + + # fixup the dll searchpath if we need to. + if test -n "$dllsearchpath"; then + $ECHO "\ + # Add the dll search path components to the executable PATH + PATH=$dllsearchpath:\$PATH +" + fi + + $ECHO "\ + if test \"\$libtool_execute_magic\" != \"$magic\"; then + # Run the actual program with our arguments. +" + case $host in + # Backslashes separate directories on plain windows + *-*-mingw | *-*-os2* | *-cegcc*) + $ECHO "\ + exec \"\$progdir\\\\\$program\" \${1+\"\$@\"} +" + ;; + + *) + $ECHO "\ + exec \"\$progdir/\$program\" \${1+\"\$@\"} +" + ;; + esac + $ECHO "\ + \$ECHO \"\$0: cannot exec \$program \$*\" 1>&2 + exit 1 + fi + else + # The program doesn't exist. + \$ECHO \"\$0: error: \\\`\$progdir/\$program' does not exist\" 1>&2 + \$ECHO \"This script is just a wrapper for \$program.\" 1>&2 + $ECHO \"See the $PACKAGE documentation for more information.\" 1>&2 + exit 1 + fi +fi\ +" +} +# end: func_emit_wrapper_part2 + + +# func_emit_wrapper [arg=no] +# +# Emit a libtool wrapper script on stdout. +# Don't directly open a file because we may want to +# incorporate the script contents within a cygwin/mingw +# wrapper executable. Must ONLY be called from within +# func_mode_link because it depends on a number of variables +# set therein. +# +# ARG is the value that the WRAPPER_SCRIPT_BELONGS_IN_OBJDIR +# variable will take. If 'yes', then the emitted script +# will assume that the directory in which it is stored is +# the $objdir directory. This is a cygwin/mingw-specific +# behavior. +func_emit_wrapper () +{ + func_emit_wrapper_arg1=no + if test -n "$1" ; then + func_emit_wrapper_arg1=$1 + fi + + # split this up so that func_emit_cwrapperexe_src + # can call each part independently. + func_emit_wrapper_part1 "${func_emit_wrapper_arg1}" + func_emit_wrapper_part2 "${func_emit_wrapper_arg1}" +} + + +# func_to_host_path arg +# +# Convert paths to host format when used with build tools. +# Intended for use with "native" mingw (where libtool itself +# is running under the msys shell), or in the following cross- +# build environments: +# $build $host +# mingw (msys) mingw [e.g. native] +# cygwin mingw +# *nix + wine mingw +# where wine is equipped with the `winepath' executable. +# In the native mingw case, the (msys) shell automatically +# converts paths for any non-msys applications it launches, +# but that facility isn't available from inside the cwrapper. +# Similar accommodations are necessary for $host mingw and +# $build cygwin. Calling this function does no harm for other +# $host/$build combinations not listed above. +# +# ARG is the path (on $build) that should be converted to +# the proper representation for $host. The result is stored +# in $func_to_host_path_result. +func_to_host_path () +{ + func_to_host_path_result="$1" + if test -n "$1" ; then + case $host in + *mingw* ) + lt_sed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g' + case $build in + *mingw* ) # actually, msys + # awkward: cmd appends spaces to result + lt_sed_strip_trailing_spaces="s/[ ]*\$//" + func_to_host_path_tmp1=`( cmd //c echo "$1" |\ + $SED -e "$lt_sed_strip_trailing_spaces" ) 2>/dev/null || echo ""` + func_to_host_path_result=`echo "$func_to_host_path_tmp1" |\ + $SED -e "$lt_sed_naive_backslashify"` + ;; + *cygwin* ) + func_to_host_path_tmp1=`cygpath -w "$1"` + func_to_host_path_result=`echo "$func_to_host_path_tmp1" |\ + $SED -e "$lt_sed_naive_backslashify"` + ;; + * ) + # Unfortunately, winepath does not exit with a non-zero + # error code, so we are forced to check the contents of + # stdout. On the other hand, if the command is not + # found, the shell will set an exit code of 127 and print + # *an error message* to stdout. So we must check for both + # error code of zero AND non-empty stdout, which explains + # the odd construction: + func_to_host_path_tmp1=`winepath -w "$1" 2>/dev/null` + if test "$?" -eq 0 && test -n "${func_to_host_path_tmp1}"; then + func_to_host_path_result=`echo "$func_to_host_path_tmp1" |\ + $SED -e "$lt_sed_naive_backslashify"` + else + # Allow warning below. + func_to_host_path_result="" + fi + ;; + esac + if test -z "$func_to_host_path_result" ; then + func_error "Could not determine host path corresponding to" + func_error " '$1'" + func_error "Continuing, but uninstalled executables may not work." + # Fallback: + func_to_host_path_result="$1" + fi + ;; + esac + fi +} +# end: func_to_host_path + +# func_to_host_pathlist arg +# +# Convert pathlists to host format when used with build tools. +# See func_to_host_path(), above. This function supports the +# following $build/$host combinations (but does no harm for +# combinations not listed here): +# $build $host +# mingw (msys) mingw [e.g. native] +# cygwin mingw +# *nix + wine mingw +# +# Path separators are also converted from $build format to +# $host format. If ARG begins or ends with a path separator +# character, it is preserved (but converted to $host format) +# on output. +# +# ARG is a pathlist (on $build) that should be converted to +# the proper representation on $host. The result is stored +# in $func_to_host_pathlist_result. +func_to_host_pathlist () +{ + func_to_host_pathlist_result="$1" + if test -n "$1" ; then + case $host in + *mingw* ) + lt_sed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g' + # Remove leading and trailing path separator characters from + # ARG. msys behavior is inconsistent here, cygpath turns them + # into '.;' and ';.', and winepath ignores them completely. + func_to_host_pathlist_tmp2="$1" + # Once set for this call, this variable should not be + # reassigned. It is used in tha fallback case. + func_to_host_pathlist_tmp1=`echo "$func_to_host_pathlist_tmp2" |\ + $SED -e 's|^:*||' -e 's|:*$||'` + case $build in + *mingw* ) # Actually, msys. + # Awkward: cmd appends spaces to result. + lt_sed_strip_trailing_spaces="s/[ ]*\$//" + func_to_host_pathlist_tmp2=`( cmd //c echo "$func_to_host_pathlist_tmp1" |\ + $SED -e "$lt_sed_strip_trailing_spaces" ) 2>/dev/null || echo ""` + func_to_host_pathlist_result=`echo "$func_to_host_pathlist_tmp2" |\ + $SED -e "$lt_sed_naive_backslashify"` + ;; + *cygwin* ) + func_to_host_pathlist_tmp2=`cygpath -w -p "$func_to_host_pathlist_tmp1"` + func_to_host_pathlist_result=`echo "$func_to_host_pathlist_tmp2" |\ + $SED -e "$lt_sed_naive_backslashify"` + ;; + * ) + # unfortunately, winepath doesn't convert pathlists + func_to_host_pathlist_result="" + func_to_host_pathlist_oldIFS=$IFS + IFS=: + for func_to_host_pathlist_f in $func_to_host_pathlist_tmp1 ; do + IFS=$func_to_host_pathlist_oldIFS + if test -n "$func_to_host_pathlist_f" ; then + func_to_host_path "$func_to_host_pathlist_f" + if test -n "$func_to_host_path_result" ; then + if test -z "$func_to_host_pathlist_result" ; then + func_to_host_pathlist_result="$func_to_host_path_result" + else + func_to_host_pathlist_result="$func_to_host_pathlist_result;$func_to_host_path_result" + fi + fi + fi + IFS=: + done + IFS=$func_to_host_pathlist_oldIFS + ;; + esac + if test -z "$func_to_host_pathlist_result" ; then + func_error "Could not determine the host path(s) corresponding to" + func_error " '$1'" + func_error "Continuing, but uninstalled executables may not work." + # Fallback. This may break if $1 contains DOS-style drive + # specifications. The fix is not to complicate the expression + # below, but for the user to provide a working wine installation + # with winepath so that path translation in the cross-to-mingw + # case works properly. + lt_replace_pathsep_nix_to_dos="s|:|;|g" + func_to_host_pathlist_result=`echo "$func_to_host_pathlist_tmp1" |\ + $SED -e "$lt_replace_pathsep_nix_to_dos"` + fi + # Now, add the leading and trailing path separators back + case "$1" in + :* ) func_to_host_pathlist_result=";$func_to_host_pathlist_result" + ;; + esac + case "$1" in + *: ) func_to_host_pathlist_result="$func_to_host_pathlist_result;" + ;; + esac + ;; + esac + fi +} +# end: func_to_host_pathlist + +# func_emit_cwrapperexe_src +# emit the source code for a wrapper executable on stdout +# Must ONLY be called from within func_mode_link because +# it depends on a number of variable set therein. +func_emit_cwrapperexe_src () +{ + cat < +#include +#ifdef _MSC_VER +# include +# include +# include +# define setmode _setmode +#else +# include +# include +# ifdef __CYGWIN__ +# include +# define HAVE_SETENV +# ifdef __STRICT_ANSI__ +char *realpath (const char *, char *); +int putenv (char *); +int setenv (const char *, const char *, int); +# endif +# endif +#endif +#include +#include +#include +#include +#include +#include +#include +#include + +#if defined(PATH_MAX) +# define LT_PATHMAX PATH_MAX +#elif defined(MAXPATHLEN) +# define LT_PATHMAX MAXPATHLEN +#else +# define LT_PATHMAX 1024 +#endif + +#ifndef S_IXOTH +# define S_IXOTH 0 +#endif +#ifndef S_IXGRP +# define S_IXGRP 0 +#endif + +#ifdef _MSC_VER +# define S_IXUSR _S_IEXEC +# define stat _stat +# ifndef _INTPTR_T_DEFINED +# define intptr_t int +# endif +#endif + +#ifndef DIR_SEPARATOR +# define DIR_SEPARATOR '/' +# define PATH_SEPARATOR ':' +#endif + +#if defined (_WIN32) || defined (__MSDOS__) || defined (__DJGPP__) || \ + defined (__OS2__) +# define HAVE_DOS_BASED_FILE_SYSTEM +# define FOPEN_WB "wb" +# ifndef DIR_SEPARATOR_2 +# define DIR_SEPARATOR_2 '\\' +# endif +# ifndef PATH_SEPARATOR_2 +# define PATH_SEPARATOR_2 ';' +# endif +#endif + +#ifndef DIR_SEPARATOR_2 +# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR) +#else /* DIR_SEPARATOR_2 */ +# define IS_DIR_SEPARATOR(ch) \ + (((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2)) +#endif /* DIR_SEPARATOR_2 */ + +#ifndef PATH_SEPARATOR_2 +# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR) +#else /* PATH_SEPARATOR_2 */ +# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR_2) +#endif /* PATH_SEPARATOR_2 */ + +#ifdef __CYGWIN__ +# define FOPEN_WB "wb" +#endif + +#ifndef FOPEN_WB +# define FOPEN_WB "w" +#endif +#ifndef _O_BINARY +# define _O_BINARY 0 +#endif + +#define XMALLOC(type, num) ((type *) xmalloc ((num) * sizeof(type))) +#define XFREE(stale) do { \ + if (stale) { free ((void *) stale); stale = 0; } \ +} while (0) + +#undef LTWRAPPER_DEBUGPRINTF +#if defined DEBUGWRAPPER +# define LTWRAPPER_DEBUGPRINTF(args) ltwrapper_debugprintf args +static void +ltwrapper_debugprintf (const char *fmt, ...) +{ + va_list args; + va_start (args, fmt); + (void) vfprintf (stderr, fmt, args); + va_end (args); +} +#else +# define LTWRAPPER_DEBUGPRINTF(args) +#endif + +const char *program_name = NULL; + +void *xmalloc (size_t num); +char *xstrdup (const char *string); +const char *base_name (const char *name); +char *find_executable (const char *wrapper); +char *chase_symlinks (const char *pathspec); +int make_executable (const char *path); +int check_executable (const char *path); +char *strendzap (char *str, const char *pat); +void lt_fatal (const char *message, ...); +void lt_setenv (const char *name, const char *value); +char *lt_extend_str (const char *orig_value, const char *add, int to_end); +void lt_opt_process_env_set (const char *arg); +void lt_opt_process_env_prepend (const char *arg); +void lt_opt_process_env_append (const char *arg); +int lt_split_name_value (const char *arg, char** name, char** value); +void lt_update_exe_path (const char *name, const char *value); +void lt_update_lib_path (const char *name, const char *value); + +static const char *script_text_part1 = +EOF + + func_emit_wrapper_part1 yes | + $SED -e 's/\([\\"]\)/\\\1/g' \ + -e 's/^/ "/' -e 's/$/\\n"/' + echo ";" + cat <"))); + for (i = 0; i < newargc; i++) + { + LTWRAPPER_DEBUGPRINTF (("(main) newargz[%d] : %s\n", i, (newargz[i] ? newargz[i] : ""))); + } + +EOF + + case $host_os in + mingw*) + cat <<"EOF" + /* execv doesn't actually work on mingw as expected on unix */ + rval = _spawnv (_P_WAIT, lt_argv_zero, (const char * const *) newargz); + if (rval == -1) + { + /* failed to start process */ + LTWRAPPER_DEBUGPRINTF (("(main) failed to launch target \"%s\": errno = %d\n", lt_argv_zero, errno)); + return 127; + } + return rval; +EOF + ;; + *) + cat <<"EOF" + execv (lt_argv_zero, newargz); + return rval; /* =127, but avoids unused variable warning */ +EOF + ;; + esac + + cat <<"EOF" +} + +void * +xmalloc (size_t num) +{ + void *p = (void *) malloc (num); + if (!p) + lt_fatal ("Memory exhausted"); + + return p; +} + +char * +xstrdup (const char *string) +{ + return string ? strcpy ((char *) xmalloc (strlen (string) + 1), + string) : NULL; +} + +const char * +base_name (const char *name) +{ + const char *base; + +#if defined (HAVE_DOS_BASED_FILE_SYSTEM) + /* Skip over the disk name in MSDOS pathnames. */ + if (isalpha ((unsigned char) name[0]) && name[1] == ':') + name += 2; +#endif + + for (base = name; *name; name++) + if (IS_DIR_SEPARATOR (*name)) + base = name + 1; + return base; +} + +int +check_executable (const char *path) +{ + struct stat st; + + LTWRAPPER_DEBUGPRINTF (("(check_executable) : %s\n", + path ? (*path ? path : "EMPTY!") : "NULL!")); + if ((!path) || (!*path)) + return 0; + + if ((stat (path, &st) >= 0) + && (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH))) + return 1; + else + return 0; +} + +int +make_executable (const char *path) +{ + int rval = 0; + struct stat st; + + LTWRAPPER_DEBUGPRINTF (("(make_executable) : %s\n", + path ? (*path ? path : "EMPTY!") : "NULL!")); + if ((!path) || (!*path)) + return 0; + + if (stat (path, &st) >= 0) + { + rval = chmod (path, st.st_mode | S_IXOTH | S_IXGRP | S_IXUSR); + } + return rval; +} + +/* Searches for the full path of the wrapper. Returns + newly allocated full path name if found, NULL otherwise + Does not chase symlinks, even on platforms that support them. +*/ +char * +find_executable (const char *wrapper) +{ + int has_slash = 0; + const char *p; + const char *p_next; + /* static buffer for getcwd */ + char tmp[LT_PATHMAX + 1]; + int tmp_len; + char *concat_name; + + LTWRAPPER_DEBUGPRINTF (("(find_executable) : %s\n", + wrapper ? (*wrapper ? wrapper : "EMPTY!") : "NULL!")); + + if ((wrapper == NULL) || (*wrapper == '\0')) + return NULL; + + /* Absolute path? */ +#if defined (HAVE_DOS_BASED_FILE_SYSTEM) + if (isalpha ((unsigned char) wrapper[0]) && wrapper[1] == ':') + { + concat_name = xstrdup (wrapper); + if (check_executable (concat_name)) + return concat_name; + XFREE (concat_name); + } + else + { +#endif + if (IS_DIR_SEPARATOR (wrapper[0])) + { + concat_name = xstrdup (wrapper); + if (check_executable (concat_name)) + return concat_name; + XFREE (concat_name); + } +#if defined (HAVE_DOS_BASED_FILE_SYSTEM) + } +#endif + + for (p = wrapper; *p; p++) + if (*p == '/') + { + has_slash = 1; + break; + } + if (!has_slash) + { + /* no slashes; search PATH */ + const char *path = getenv ("PATH"); + if (path != NULL) + { + for (p = path; *p; p = p_next) + { + const char *q; + size_t p_len; + for (q = p; *q; q++) + if (IS_PATH_SEPARATOR (*q)) + break; + p_len = q - p; + p_next = (*q == '\0' ? q : q + 1); + if (p_len == 0) + { + /* empty path: current directory */ + if (getcwd (tmp, LT_PATHMAX) == NULL) + lt_fatal ("getcwd failed"); + tmp_len = strlen (tmp); + concat_name = + XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1); + memcpy (concat_name, tmp, tmp_len); + concat_name[tmp_len] = '/'; + strcpy (concat_name + tmp_len + 1, wrapper); + } + else + { + concat_name = + XMALLOC (char, p_len + 1 + strlen (wrapper) + 1); + memcpy (concat_name, p, p_len); + concat_name[p_len] = '/'; + strcpy (concat_name + p_len + 1, wrapper); + } + if (check_executable (concat_name)) + return concat_name; + XFREE (concat_name); + } + } + /* not found in PATH; assume curdir */ + } + /* Relative path | not found in path: prepend cwd */ + if (getcwd (tmp, LT_PATHMAX) == NULL) + lt_fatal ("getcwd failed"); + tmp_len = strlen (tmp); + concat_name = XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1); + memcpy (concat_name, tmp, tmp_len); + concat_name[tmp_len] = '/'; + strcpy (concat_name + tmp_len + 1, wrapper); + + if (check_executable (concat_name)) + return concat_name; + XFREE (concat_name); + return NULL; +} + +char * +chase_symlinks (const char *pathspec) +{ +#ifndef S_ISLNK + return xstrdup (pathspec); +#else + char buf[LT_PATHMAX]; + struct stat s; + char *tmp_pathspec = xstrdup (pathspec); + char *p; + int has_symlinks = 0; + while (strlen (tmp_pathspec) && !has_symlinks) + { + LTWRAPPER_DEBUGPRINTF (("checking path component for symlinks: %s\n", + tmp_pathspec)); + if (lstat (tmp_pathspec, &s) == 0) + { + if (S_ISLNK (s.st_mode) != 0) + { + has_symlinks = 1; + break; + } + + /* search backwards for last DIR_SEPARATOR */ + p = tmp_pathspec + strlen (tmp_pathspec) - 1; + while ((p > tmp_pathspec) && (!IS_DIR_SEPARATOR (*p))) + p--; + if ((p == tmp_pathspec) && (!IS_DIR_SEPARATOR (*p))) + { + /* no more DIR_SEPARATORS left */ + break; + } + *p = '\0'; + } + else + { + char *errstr = strerror (errno); + lt_fatal ("Error accessing file %s (%s)", tmp_pathspec, errstr); + } + } + XFREE (tmp_pathspec); + + if (!has_symlinks) + { + return xstrdup (pathspec); + } + + tmp_pathspec = realpath (pathspec, buf); + if (tmp_pathspec == 0) + { + lt_fatal ("Could not follow symlinks for %s", pathspec); + } + return xstrdup (tmp_pathspec); +#endif +} + +char * +strendzap (char *str, const char *pat) +{ + size_t len, patlen; + + assert (str != NULL); + assert (pat != NULL); + + len = strlen (str); + patlen = strlen (pat); + + if (patlen <= len) + { + str += len - patlen; + if (strcmp (str, pat) == 0) + *str = '\0'; + } + return str; +} + +static void +lt_error_core (int exit_status, const char *mode, + const char *message, va_list ap) +{ + fprintf (stderr, "%s: %s: ", program_name, mode); + vfprintf (stderr, message, ap); + fprintf (stderr, ".\n"); + + if (exit_status >= 0) + exit (exit_status); +} + +void +lt_fatal (const char *message, ...) +{ + va_list ap; + va_start (ap, message); + lt_error_core (EXIT_FAILURE, "FATAL", message, ap); + va_end (ap); +} + +void +lt_setenv (const char *name, const char *value) +{ + LTWRAPPER_DEBUGPRINTF (("(lt_setenv) setting '%s' to '%s'\n", + (name ? name : ""), + (value ? value : ""))); + { +#ifdef HAVE_SETENV + /* always make a copy, for consistency with !HAVE_SETENV */ + char *str = xstrdup (value); + setenv (name, str, 1); +#else + int len = strlen (name) + 1 + strlen (value) + 1; + char *str = XMALLOC (char, len); + sprintf (str, "%s=%s", name, value); + if (putenv (str) != EXIT_SUCCESS) + { + XFREE (str); + } +#endif + } +} + +char * +lt_extend_str (const char *orig_value, const char *add, int to_end) +{ + char *new_value; + if (orig_value && *orig_value) + { + int orig_value_len = strlen (orig_value); + int add_len = strlen (add); + new_value = XMALLOC (char, add_len + orig_value_len + 1); + if (to_end) + { + strcpy (new_value, orig_value); + strcpy (new_value + orig_value_len, add); + } + else + { + strcpy (new_value, add); + strcpy (new_value + add_len, orig_value); + } + } + else + { + new_value = xstrdup (add); + } + return new_value; +} + +int +lt_split_name_value (const char *arg, char** name, char** value) +{ + const char *p; + int len; + if (!arg || !*arg) + return 1; + + p = strchr (arg, (int)'='); + + if (!p) + return 1; + + *value = xstrdup (++p); + + len = strlen (arg) - strlen (*value); + *name = XMALLOC (char, len); + strncpy (*name, arg, len-1); + (*name)[len - 1] = '\0'; + + return 0; +} + +void +lt_opt_process_env_set (const char *arg) +{ + char *name = NULL; + char *value = NULL; + + if (lt_split_name_value (arg, &name, &value) != 0) + { + XFREE (name); + XFREE (value); + lt_fatal ("bad argument for %s: '%s'", env_set_opt, arg); + } + + lt_setenv (name, value); + XFREE (name); + XFREE (value); +} + +void +lt_opt_process_env_prepend (const char *arg) +{ + char *name = NULL; + char *value = NULL; + char *new_value = NULL; + + if (lt_split_name_value (arg, &name, &value) != 0) + { + XFREE (name); + XFREE (value); + lt_fatal ("bad argument for %s: '%s'", env_prepend_opt, arg); + } + + new_value = lt_extend_str (getenv (name), value, 0); + lt_setenv (name, new_value); + XFREE (new_value); + XFREE (name); + XFREE (value); +} + +void +lt_opt_process_env_append (const char *arg) +{ + char *name = NULL; + char *value = NULL; + char *new_value = NULL; + + if (lt_split_name_value (arg, &name, &value) != 0) + { + XFREE (name); + XFREE (value); + lt_fatal ("bad argument for %s: '%s'", env_append_opt, arg); + } + + new_value = lt_extend_str (getenv (name), value, 1); + lt_setenv (name, new_value); + XFREE (new_value); + XFREE (name); + XFREE (value); +} + +void +lt_update_exe_path (const char *name, const char *value) +{ + LTWRAPPER_DEBUGPRINTF (("(lt_update_exe_path) modifying '%s' by prepending '%s'\n", + (name ? name : ""), + (value ? value : ""))); + + if (name && *name && value && *value) + { + char *new_value = lt_extend_str (getenv (name), value, 0); + /* some systems can't cope with a ':'-terminated path #' */ + int len = strlen (new_value); + while (((len = strlen (new_value)) > 0) && IS_PATH_SEPARATOR (new_value[len-1])) + { + new_value[len-1] = '\0'; + } + lt_setenv (name, new_value); + XFREE (new_value); + } +} + +void +lt_update_lib_path (const char *name, const char *value) +{ + LTWRAPPER_DEBUGPRINTF (("(lt_update_lib_path) modifying '%s' by prepending '%s'\n", + (name ? name : ""), + (value ? value : ""))); + + if (name && *name && value && *value) + { + char *new_value = lt_extend_str (getenv (name), value, 0); + lt_setenv (name, new_value); + XFREE (new_value); + } +} + + +EOF +} +# end: func_emit_cwrapperexe_src + +# func_mode_link arg... +func_mode_link () +{ + $opt_debug + case $host in + *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*) + # It is impossible to link a dll without this setting, and + # we shouldn't force the makefile maintainer to figure out + # which system we are compiling for in order to pass an extra + # flag for every libtool invocation. + # allow_undefined=no + + # FIXME: Unfortunately, there are problems with the above when trying + # to make a dll which has undefined symbols, in which case not + # even a static library is built. For now, we need to specify + # -no-undefined on the libtool link line when we can be certain + # that all symbols are satisfied, otherwise we get a static library. + allow_undefined=yes + ;; + *) + allow_undefined=yes + ;; + esac + libtool_args=$nonopt + base_compile="$nonopt $@" + compile_command=$nonopt + finalize_command=$nonopt + + compile_rpath= + finalize_rpath= + compile_shlibpath= + finalize_shlibpath= + convenience= + old_convenience= + deplibs= + old_deplibs= + compiler_flags= + linker_flags= + dllsearchpath= + lib_search_path=`pwd` + inst_prefix_dir= + new_inherited_linker_flags= + + avoid_version=no + dlfiles= + dlprefiles= + dlself=no + export_dynamic=no + export_symbols= + export_symbols_regex= + generated= + libobjs= + ltlibs= + module=no + no_install=no + objs= + non_pic_objects= + precious_files_regex= + prefer_static_libs=no + preload=no + prev= + prevarg= + release= + rpath= + xrpath= + perm_rpath= + temp_rpath= + thread_safe=no + vinfo= + vinfo_number=no + weak_libs= + single_module="${wl}-single_module" + func_infer_tag $base_compile + + # We need to know -static, to get the right output filenames. + for arg + do + case $arg in + -shared) + test "$build_libtool_libs" != yes && \ + func_fatal_configuration "can not build a shared library" + build_old_libs=no + break + ;; + -all-static | -static | -static-libtool-libs) + case $arg in + -all-static) + if test "$build_libtool_libs" = yes && test -z "$link_static_flag"; then + func_warning "complete static linking is impossible in this configuration" + fi + if test -n "$link_static_flag"; then + dlopen_self=$dlopen_self_static + fi + prefer_static_libs=yes + ;; + -static) + if test -z "$pic_flag" && test -n "$link_static_flag"; then + dlopen_self=$dlopen_self_static + fi + prefer_static_libs=built + ;; + -static-libtool-libs) + if test -z "$pic_flag" && test -n "$link_static_flag"; then + dlopen_self=$dlopen_self_static + fi + prefer_static_libs=yes + ;; + esac + build_libtool_libs=no + build_old_libs=yes + break + ;; + esac + done + + # See if our shared archives depend on static archives. + test -n "$old_archive_from_new_cmds" && build_old_libs=yes + + # Go through the arguments, transforming them on the way. + while test "$#" -gt 0; do + arg="$1" + shift + func_quote_for_eval "$arg" + qarg=$func_quote_for_eval_unquoted_result + func_append libtool_args " $func_quote_for_eval_result" + + # If the previous option needs an argument, assign it. + if test -n "$prev"; then + case $prev in + output) + func_append compile_command " @OUTPUT@" + func_append finalize_command " @OUTPUT@" + ;; + esac + + case $prev in + dlfiles|dlprefiles) + if test "$preload" = no; then + # Add the symbol object into the linking commands. + func_append compile_command " @SYMFILE@" + func_append finalize_command " @SYMFILE@" + preload=yes + fi + case $arg in + *.la | *.lo) ;; # We handle these cases below. + force) + if test "$dlself" = no; then + dlself=needless + export_dynamic=yes + fi + prev= + continue + ;; + self) + if test "$prev" = dlprefiles; then + dlself=yes + elif test "$prev" = dlfiles && test "$dlopen_self" != yes; then + dlself=yes + else + dlself=needless + export_dynamic=yes + fi + prev= + continue + ;; + *) + if test "$prev" = dlfiles; then + dlfiles="$dlfiles $arg" + else + dlprefiles="$dlprefiles $arg" + fi + prev= + continue + ;; + esac + ;; + expsyms) + export_symbols="$arg" + test -f "$arg" \ + || func_fatal_error "symbol file \`$arg' does not exist" + prev= + continue + ;; + expsyms_regex) + export_symbols_regex="$arg" + prev= + continue + ;; + framework) + case $host in + *-*-darwin*) + case "$deplibs " in + *" $qarg.ltframework "*) ;; + *) deplibs="$deplibs $qarg.ltframework" # this is fixed later + ;; + esac + ;; + esac + prev= + continue + ;; + inst_prefix) + inst_prefix_dir="$arg" + prev= + continue + ;; + objectlist) + if test -f "$arg"; then + save_arg=$arg + moreargs= + for fil in `cat "$save_arg"` + do +# moreargs="$moreargs $fil" + arg=$fil + # A libtool-controlled object. + + # Check to see that this really is a libtool object. + if func_lalib_unsafe_p "$arg"; then + pic_object= + non_pic_object= + + # Read the .lo file + func_source "$arg" + + if test -z "$pic_object" || + test -z "$non_pic_object" || + test "$pic_object" = none && + test "$non_pic_object" = none; then + func_fatal_error "cannot find name of object for \`$arg'" + fi + + # Extract subdirectory from the argument. + func_dirname "$arg" "/" "" + xdir="$func_dirname_result" + + if test "$pic_object" != none; then + # Prepend the subdirectory the object is found in. + pic_object="$xdir$pic_object" + + if test "$prev" = dlfiles; then + if test "$build_libtool_libs" = yes && test "$dlopen_support" = yes; then + dlfiles="$dlfiles $pic_object" + prev= + continue + else + # If libtool objects are unsupported, then we need to preload. + prev=dlprefiles + fi + fi + + # CHECK ME: I think I busted this. -Ossama + if test "$prev" = dlprefiles; then + # Preload the old-style object. + dlprefiles="$dlprefiles $pic_object" + prev= + fi + + # A PIC object. + func_append libobjs " $pic_object" + arg="$pic_object" + fi + + # Non-PIC object. + if test "$non_pic_object" != none; then + # Prepend the subdirectory the object is found in. + non_pic_object="$xdir$non_pic_object" + + # A standard non-PIC object + func_append non_pic_objects " $non_pic_object" + if test -z "$pic_object" || test "$pic_object" = none ; then + arg="$non_pic_object" + fi + else + # If the PIC object exists, use it instead. + # $xdir was prepended to $pic_object above. + non_pic_object="$pic_object" + func_append non_pic_objects " $non_pic_object" + fi + else + # Only an error if not doing a dry-run. + if $opt_dry_run; then + # Extract subdirectory from the argument. + func_dirname "$arg" "/" "" + xdir="$func_dirname_result" + + func_lo2o "$arg" + pic_object=$xdir$objdir/$func_lo2o_result + non_pic_object=$xdir$func_lo2o_result + func_append libobjs " $pic_object" + func_append non_pic_objects " $non_pic_object" + else + func_fatal_error "\`$arg' is not a valid libtool object" + fi + fi + done + else + func_fatal_error "link input file \`$arg' does not exist" + fi + arg=$save_arg + prev= + continue + ;; + precious_regex) + precious_files_regex="$arg" + prev= + continue + ;; + release) + release="-$arg" + prev= + continue + ;; + rpath | xrpath) + # We need an absolute path. + case $arg in + [\\/]* | [A-Za-z]:[\\/]*) ;; + *) + func_fatal_error "only absolute run-paths are allowed" + ;; + esac + if test "$prev" = rpath; then + case "$rpath " in + *" $arg "*) ;; + *) rpath="$rpath $arg" ;; + esac + else + case "$xrpath " in + *" $arg "*) ;; + *) xrpath="$xrpath $arg" ;; + esac + fi + prev= + continue + ;; + shrext) + shrext_cmds="$arg" + prev= + continue + ;; + weak) + weak_libs="$weak_libs $arg" + prev= + continue + ;; + xcclinker) + linker_flags="$linker_flags $qarg" + compiler_flags="$compiler_flags $qarg" + prev= + func_append compile_command " $qarg" + func_append finalize_command " $qarg" + continue + ;; + xcompiler) + compiler_flags="$compiler_flags $qarg" + prev= + func_append compile_command " $qarg" + func_append finalize_command " $qarg" + continue + ;; + xlinker) + linker_flags="$linker_flags $qarg" + compiler_flags="$compiler_flags $wl$qarg" + prev= + func_append compile_command " $wl$qarg" + func_append finalize_command " $wl$qarg" + continue + ;; + *) + eval "$prev=\"\$arg\"" + prev= + continue + ;; + esac + fi # test -n "$prev" + + prevarg="$arg" + + case $arg in + -all-static) + if test -n "$link_static_flag"; then + # See comment for -static flag below, for more details. + func_append compile_command " $link_static_flag" + func_append finalize_command " $link_static_flag" + fi + continue + ;; + + -allow-undefined) + # FIXME: remove this flag sometime in the future. + func_fatal_error "\`-allow-undefined' must not be used because it is the default" + ;; + + -avoid-version) + avoid_version=yes + continue + ;; + + -dlopen) + prev=dlfiles + continue + ;; + + -dlpreopen) + prev=dlprefiles + continue + ;; + + -export-dynamic) + export_dynamic=yes + continue + ;; + + -export-symbols | -export-symbols-regex) + if test -n "$export_symbols" || test -n "$export_symbols_regex"; then + func_fatal_error "more than one -exported-symbols argument is not allowed" + fi + if test "X$arg" = "X-export-symbols"; then + prev=expsyms + else + prev=expsyms_regex + fi + continue + ;; + + -framework) + prev=framework + continue + ;; + + -inst-prefix-dir) + prev=inst_prefix + continue + ;; + + # The native IRIX linker understands -LANG:*, -LIST:* and -LNO:* + # so, if we see these flags be careful not to treat them like -L + -L[A-Z][A-Z]*:*) + case $with_gcc/$host in + no/*-*-irix* | /*-*-irix*) + func_append compile_command " $arg" + func_append finalize_command " $arg" + ;; + esac + continue + ;; + + -L*) + func_stripname '-L' '' "$arg" + dir=$func_stripname_result + if test -z "$dir"; then + if test "$#" -gt 0; then + func_fatal_error "require no space between \`-L' and \`$1'" + else + func_fatal_error "need path for \`-L' option" + fi + fi + # We need an absolute path. + case $dir in + [\\/]* | [A-Za-z]:[\\/]*) ;; + *) + absdir=`cd "$dir" && pwd` + test -z "$absdir" && \ + func_fatal_error "cannot determine absolute directory name of \`$dir'" + dir="$absdir" + ;; + esac + case "$deplibs " in + *" -L$dir "*) ;; + *) + deplibs="$deplibs -L$dir" + lib_search_path="$lib_search_path $dir" + ;; + esac + case $host in + *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*) + testbindir=`$ECHO "X$dir" | $Xsed -e 's*/lib$*/bin*'` + case :$dllsearchpath: in + *":$dir:"*) ;; + ::) dllsearchpath=$dir;; + *) dllsearchpath="$dllsearchpath:$dir";; + esac + case :$dllsearchpath: in + *":$testbindir:"*) ;; + ::) dllsearchpath=$testbindir;; + *) dllsearchpath="$dllsearchpath:$testbindir";; + esac + ;; + esac + continue + ;; + + -l*) + if test "X$arg" = "X-lc" || test "X$arg" = "X-lm"; then + case $host in + *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-beos* | *-cegcc*) + # These systems don't actually have a C or math library (as such) + continue + ;; + *-*-os2*) + # These systems don't actually have a C library (as such) + test "X$arg" = "X-lc" && continue + ;; + *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*) + # Do not include libc due to us having libc/libc_r. + test "X$arg" = "X-lc" && continue + ;; + *-*-rhapsody* | *-*-darwin1.[012]) + # Rhapsody C and math libraries are in the System framework + deplibs="$deplibs System.ltframework" + continue + ;; + *-*-sco3.2v5* | *-*-sco5v6*) + # Causes problems with __ctype + test "X$arg" = "X-lc" && continue + ;; + *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*) + # Compiler inserts libc in the correct place for threads to work + test "X$arg" = "X-lc" && continue + ;; + esac + elif test "X$arg" = "X-lc_r"; then + case $host in + *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*) + # Do not include libc_r directly, use -pthread flag. + continue + ;; + esac + fi + deplibs="$deplibs $arg" + continue + ;; + + -module) + module=yes + continue + ;; + + # Tru64 UNIX uses -model [arg] to determine the layout of C++ + # classes, name mangling, and exception handling. + # Darwin uses the -arch flag to determine output architecture. + -model|-arch|-isysroot) + compiler_flags="$compiler_flags $arg" + func_append compile_command " $arg" + func_append finalize_command " $arg" + prev=xcompiler + continue + ;; + + -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe|-threads) + compiler_flags="$compiler_flags $arg" + func_append compile_command " $arg" + func_append finalize_command " $arg" + case "$new_inherited_linker_flags " in + *" $arg "*) ;; + * ) new_inherited_linker_flags="$new_inherited_linker_flags $arg" ;; + esac + continue + ;; + + -multi_module) + single_module="${wl}-multi_module" + continue + ;; + + -no-fast-install) + fast_install=no + continue + ;; + + -no-install) + case $host in + *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*) + # The PATH hackery in wrapper scripts is required on Windows + # and Darwin in order for the loader to find any dlls it needs. + func_warning "\`-no-install' is ignored for $host" + func_warning "assuming \`-no-fast-install' instead" + fast_install=no + ;; + *) no_install=yes ;; + esac + continue + ;; + + -no-undefined) + allow_undefined=no + continue + ;; + + -objectlist) + prev=objectlist + continue + ;; + + -o) prev=output ;; + + -precious-files-regex) + prev=precious_regex + continue + ;; + + -release) + prev=release + continue + ;; + + -rpath) + prev=rpath + continue + ;; + + -R) + prev=xrpath + continue + ;; + + -R*) + func_stripname '-R' '' "$arg" + dir=$func_stripname_result + # We need an absolute path. + case $dir in + [\\/]* | [A-Za-z]:[\\/]*) ;; + *) + func_fatal_error "only absolute run-paths are allowed" + ;; + esac + case "$xrpath " in + *" $dir "*) ;; + *) xrpath="$xrpath $dir" ;; + esac + continue + ;; + + -shared) + # The effects of -shared are defined in a previous loop. + continue + ;; + + -shrext) + prev=shrext + continue + ;; + + -static | -static-libtool-libs) + # The effects of -static are defined in a previous loop. + # We used to do the same as -all-static on platforms that + # didn't have a PIC flag, but the assumption that the effects + # would be equivalent was wrong. It would break on at least + # Digital Unix and AIX. + continue + ;; + + -thread-safe) + thread_safe=yes + continue + ;; + + -version-info) + prev=vinfo + continue + ;; + + -version-number) + prev=vinfo + vinfo_number=yes + continue + ;; + + -weak) + prev=weak + continue + ;; + + -Wc,*) + func_stripname '-Wc,' '' "$arg" + args=$func_stripname_result + arg= + save_ifs="$IFS"; IFS=',' + for flag in $args; do + IFS="$save_ifs" + func_quote_for_eval "$flag" + arg="$arg $wl$func_quote_for_eval_result" + compiler_flags="$compiler_flags $func_quote_for_eval_result" + done + IFS="$save_ifs" + func_stripname ' ' '' "$arg" + arg=$func_stripname_result + ;; + + -Wl,*) + func_stripname '-Wl,' '' "$arg" + args=$func_stripname_result + arg= + save_ifs="$IFS"; IFS=',' + for flag in $args; do + IFS="$save_ifs" + func_quote_for_eval "$flag" + arg="$arg $wl$func_quote_for_eval_result" + compiler_flags="$compiler_flags $wl$func_quote_for_eval_result" + linker_flags="$linker_flags $func_quote_for_eval_result" + done + IFS="$save_ifs" + func_stripname ' ' '' "$arg" + arg=$func_stripname_result + ;; + + -Xcompiler) + prev=xcompiler + continue + ;; + + -Xlinker) + prev=xlinker + continue + ;; + + -XCClinker) + prev=xcclinker + continue + ;; + + # -msg_* for osf cc + -msg_*) + func_quote_for_eval "$arg" + arg="$func_quote_for_eval_result" + ;; + + # -64, -mips[0-9] enable 64-bit mode on the SGI compiler + # -r[0-9][0-9]* specifies the processor on the SGI compiler + # -xarch=*, -xtarget=* enable 64-bit mode on the Sun compiler + # +DA*, +DD* enable 64-bit mode on the HP compiler + # -q* pass through compiler args for the IBM compiler + # -m*, -t[45]*, -txscale* pass through architecture-specific + # compiler args for GCC + # -F/path gives path to uninstalled frameworks, gcc on darwin + # -p, -pg, --coverage, -fprofile-* pass through profiling flag for GCC + # @file GCC response files + -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \ + -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*) + func_quote_for_eval "$arg" + arg="$func_quote_for_eval_result" + func_append compile_command " $arg" + func_append finalize_command " $arg" + compiler_flags="$compiler_flags $arg" + continue + ;; + + # Some other compiler flag. + -* | +*) + func_quote_for_eval "$arg" + arg="$func_quote_for_eval_result" + ;; + + *.$objext) + # A standard object. + objs="$objs $arg" + ;; + + *.lo) + # A libtool-controlled object. + + # Check to see that this really is a libtool object. + if func_lalib_unsafe_p "$arg"; then + pic_object= + non_pic_object= + + # Read the .lo file + func_source "$arg" + + if test -z "$pic_object" || + test -z "$non_pic_object" || + test "$pic_object" = none && + test "$non_pic_object" = none; then + func_fatal_error "cannot find name of object for \`$arg'" + fi + + # Extract subdirectory from the argument. + func_dirname "$arg" "/" "" + xdir="$func_dirname_result" + + if test "$pic_object" != none; then + # Prepend the subdirectory the object is found in. + pic_object="$xdir$pic_object" + + if test "$prev" = dlfiles; then + if test "$build_libtool_libs" = yes && test "$dlopen_support" = yes; then + dlfiles="$dlfiles $pic_object" + prev= + continue + else + # If libtool objects are unsupported, then we need to preload. + prev=dlprefiles + fi + fi + + # CHECK ME: I think I busted this. -Ossama + if test "$prev" = dlprefiles; then + # Preload the old-style object. + dlprefiles="$dlprefiles $pic_object" + prev= + fi + + # A PIC object. + func_append libobjs " $pic_object" + arg="$pic_object" + fi + + # Non-PIC object. + if test "$non_pic_object" != none; then + # Prepend the subdirectory the object is found in. + non_pic_object="$xdir$non_pic_object" + + # A standard non-PIC object + func_append non_pic_objects " $non_pic_object" + if test -z "$pic_object" || test "$pic_object" = none ; then + arg="$non_pic_object" + fi + else + # If the PIC object exists, use it instead. + # $xdir was prepended to $pic_object above. + non_pic_object="$pic_object" + func_append non_pic_objects " $non_pic_object" + fi + else + # Only an error if not doing a dry-run. + if $opt_dry_run; then + # Extract subdirectory from the argument. + func_dirname "$arg" "/" "" + xdir="$func_dirname_result" + + func_lo2o "$arg" + pic_object=$xdir$objdir/$func_lo2o_result + non_pic_object=$xdir$func_lo2o_result + func_append libobjs " $pic_object" + func_append non_pic_objects " $non_pic_object" + else + func_fatal_error "\`$arg' is not a valid libtool object" + fi + fi + ;; + + *.$libext) + # An archive. + deplibs="$deplibs $arg" + old_deplibs="$old_deplibs $arg" + continue + ;; + + *.la) + # A libtool-controlled library. + + if test "$prev" = dlfiles; then + # This library was specified with -dlopen. + dlfiles="$dlfiles $arg" + prev= + elif test "$prev" = dlprefiles; then + # The library was specified with -dlpreopen. + dlprefiles="$dlprefiles $arg" + prev= + else + deplibs="$deplibs $arg" + fi + continue + ;; + + # Some other compiler argument. + *) + # Unknown arguments in both finalize_command and compile_command need + # to be aesthetically quoted because they are evaled later. + func_quote_for_eval "$arg" + arg="$func_quote_for_eval_result" + ;; + esac # arg + + # Now actually substitute the argument into the commands. + if test -n "$arg"; then + func_append compile_command " $arg" + func_append finalize_command " $arg" + fi + done # argument parsing loop + + test -n "$prev" && \ + func_fatal_help "the \`$prevarg' option requires an argument" + + if test "$export_dynamic" = yes && test -n "$export_dynamic_flag_spec"; then + eval arg=\"$export_dynamic_flag_spec\" + func_append compile_command " $arg" + func_append finalize_command " $arg" + fi + + oldlibs= + # calculate the name of the file, without its directory + func_basename "$output" + outputname="$func_basename_result" + libobjs_save="$libobjs" + + if test -n "$shlibpath_var"; then + # get the directories listed in $shlibpath_var + eval shlib_search_path=\`\$ECHO \"X\${$shlibpath_var}\" \| \$Xsed -e \'s/:/ /g\'\` + else + shlib_search_path= + fi + eval sys_lib_search_path=\"$sys_lib_search_path_spec\" + eval sys_lib_dlsearch_path=\"$sys_lib_dlsearch_path_spec\" + + func_dirname "$output" "/" "" + output_objdir="$func_dirname_result$objdir" + # Create the object directory. + func_mkdir_p "$output_objdir" + + # Determine the type of output + case $output in + "") + func_fatal_help "you must specify an output file" + ;; + *.$libext) linkmode=oldlib ;; + *.lo | *.$objext) linkmode=obj ;; + *.la) linkmode=lib ;; + *) linkmode=prog ;; # Anything else should be a program. + esac + + specialdeplibs= + + libs= + # Find all interdependent deplibs by searching for libraries + # that are linked more than once (e.g. -la -lb -la) + for deplib in $deplibs; do + if $opt_duplicate_deps ; then + case "$libs " in + *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;; + esac + fi + libs="$libs $deplib" + done + + if test "$linkmode" = lib; then + libs="$predeps $libs $compiler_lib_search_path $postdeps" + + # Compute libraries that are listed more than once in $predeps + # $postdeps and mark them as special (i.e., whose duplicates are + # not to be eliminated). + pre_post_deps= + if $opt_duplicate_compiler_generated_deps; then + for pre_post_dep in $predeps $postdeps; do + case "$pre_post_deps " in + *" $pre_post_dep "*) specialdeplibs="$specialdeplibs $pre_post_deps" ;; + esac + pre_post_deps="$pre_post_deps $pre_post_dep" + done + fi + pre_post_deps= + fi + + deplibs= + newdependency_libs= + newlib_search_path= + need_relink=no # whether we're linking any uninstalled libtool libraries + notinst_deplibs= # not-installed libtool libraries + notinst_path= # paths that contain not-installed libtool libraries + + case $linkmode in + lib) + passes="conv dlpreopen link" + for file in $dlfiles $dlprefiles; do + case $file in + *.la) ;; + *) + func_fatal_help "libraries can \`-dlopen' only libtool libraries: $file" + ;; + esac + done + ;; + prog) + compile_deplibs= + finalize_deplibs= + alldeplibs=no + newdlfiles= + newdlprefiles= + passes="conv scan dlopen dlpreopen link" + ;; + *) passes="conv" + ;; + esac + + for pass in $passes; do + # The preopen pass in lib mode reverses $deplibs; put it back here + # so that -L comes before libs that need it for instance... + if test "$linkmode,$pass" = "lib,link"; then + ## FIXME: Find the place where the list is rebuilt in the wrong + ## order, and fix it there properly + tmp_deplibs= + for deplib in $deplibs; do + tmp_deplibs="$deplib $tmp_deplibs" + done + deplibs="$tmp_deplibs" + fi + + if test "$linkmode,$pass" = "lib,link" || + test "$linkmode,$pass" = "prog,scan"; then + libs="$deplibs" + deplibs= + fi + if test "$linkmode" = prog; then + case $pass in + dlopen) libs="$dlfiles" ;; + dlpreopen) libs="$dlprefiles" ;; + link) libs="$deplibs %DEPLIBS% $dependency_libs" ;; + esac + fi + if test "$linkmode,$pass" = "lib,dlpreopen"; then + # Collect and forward deplibs of preopened libtool libs + for lib in $dlprefiles; do + # Ignore non-libtool-libs + dependency_libs= + case $lib in + *.la) func_source "$lib" ;; + esac + + # Collect preopened libtool deplibs, except any this library + # has declared as weak libs + for deplib in $dependency_libs; do + deplib_base=`$ECHO "X$deplib" | $Xsed -e "$basename"` + case " $weak_libs " in + *" $deplib_base "*) ;; + *) deplibs="$deplibs $deplib" ;; + esac + done + done + libs="$dlprefiles" + fi + if test "$pass" = dlopen; then + # Collect dlpreopened libraries + save_deplibs="$deplibs" + deplibs= + fi + + for deplib in $libs; do + lib= + found=no + case $deplib in + -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe|-threads) + if test "$linkmode,$pass" = "prog,link"; then + compile_deplibs="$deplib $compile_deplibs" + finalize_deplibs="$deplib $finalize_deplibs" + else + compiler_flags="$compiler_flags $deplib" + if test "$linkmode" = lib ; then + case "$new_inherited_linker_flags " in + *" $deplib "*) ;; + * ) new_inherited_linker_flags="$new_inherited_linker_flags $deplib" ;; + esac + fi + fi + continue + ;; + -l*) + if test "$linkmode" != lib && test "$linkmode" != prog; then + func_warning "\`-l' is ignored for archives/objects" + continue + fi + func_stripname '-l' '' "$deplib" + name=$func_stripname_result + if test "$linkmode" = lib; then + searchdirs="$newlib_search_path $lib_search_path $compiler_lib_search_dirs $sys_lib_search_path $shlib_search_path" + else + searchdirs="$newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path" + fi + for searchdir in $searchdirs; do + for search_ext in .la $std_shrext .so .a; do + # Search the libtool library + lib="$searchdir/lib${name}${search_ext}" + if test -f "$lib"; then + if test "$search_ext" = ".la"; then + found=yes + else + found=no + fi + break 2 + fi + done + done + if test "$found" != yes; then + # deplib doesn't seem to be a libtool library + if test "$linkmode,$pass" = "prog,link"; then + compile_deplibs="$deplib $compile_deplibs" + finalize_deplibs="$deplib $finalize_deplibs" + else + deplibs="$deplib $deplibs" + test "$linkmode" = lib && newdependency_libs="$deplib $newdependency_libs" + fi + continue + else # deplib is a libtool library + # If $allow_libtool_libs_with_static_runtimes && $deplib is a stdlib, + # We need to do some special things here, and not later. + if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then + case " $predeps $postdeps " in + *" $deplib "*) + if func_lalib_p "$lib"; then + library_names= + old_library= + func_source "$lib" + for l in $old_library $library_names; do + ll="$l" + done + if test "X$ll" = "X$old_library" ; then # only static version available + found=no + func_dirname "$lib" "" "." + ladir="$func_dirname_result" + lib=$ladir/$old_library + if test "$linkmode,$pass" = "prog,link"; then + compile_deplibs="$deplib $compile_deplibs" + finalize_deplibs="$deplib $finalize_deplibs" + else + deplibs="$deplib $deplibs" + test "$linkmode" = lib && newdependency_libs="$deplib $newdependency_libs" + fi + continue + fi + fi + ;; + *) ;; + esac + fi + fi + ;; # -l + *.ltframework) + if test "$linkmode,$pass" = "prog,link"; then + compile_deplibs="$deplib $compile_deplibs" + finalize_deplibs="$deplib $finalize_deplibs" + else + deplibs="$deplib $deplibs" + if test "$linkmode" = lib ; then + case "$new_inherited_linker_flags " in + *" $deplib "*) ;; + * ) new_inherited_linker_flags="$new_inherited_linker_flags $deplib" ;; + esac + fi + fi + continue + ;; + -L*) + case $linkmode in + lib) + deplibs="$deplib $deplibs" + test "$pass" = conv && continue + newdependency_libs="$deplib $newdependency_libs" + func_stripname '-L' '' "$deplib" + newlib_search_path="$newlib_search_path $func_stripname_result" + ;; + prog) + if test "$pass" = conv; then + deplibs="$deplib $deplibs" + continue + fi + if test "$pass" = scan; then + deplibs="$deplib $deplibs" + else + compile_deplibs="$deplib $compile_deplibs" + finalize_deplibs="$deplib $finalize_deplibs" + fi + func_stripname '-L' '' "$deplib" + newlib_search_path="$newlib_search_path $func_stripname_result" + ;; + *) + func_warning "\`-L' is ignored for archives/objects" + ;; + esac # linkmode + continue + ;; # -L + -R*) + if test "$pass" = link; then + func_stripname '-R' '' "$deplib" + dir=$func_stripname_result + # Make sure the xrpath contains only unique directories. + case "$xrpath " in + *" $dir "*) ;; + *) xrpath="$xrpath $dir" ;; + esac + fi + deplibs="$deplib $deplibs" + continue + ;; + *.la) lib="$deplib" ;; + *.$libext) + if test "$pass" = conv; then + deplibs="$deplib $deplibs" + continue + fi + case $linkmode in + lib) + # Linking convenience modules into shared libraries is allowed, + # but linking other static libraries is non-portable. + case " $dlpreconveniencelibs " in + *" $deplib "*) ;; + *) + valid_a_lib=no + case $deplibs_check_method in + match_pattern*) + set dummy $deplibs_check_method; shift + match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"` + if eval "\$ECHO \"X$deplib\"" 2>/dev/null | $Xsed -e 10q \ + | $EGREP "$match_pattern_regex" > /dev/null; then + valid_a_lib=yes + fi + ;; + pass_all) + valid_a_lib=yes + ;; + esac + if test "$valid_a_lib" != yes; then + $ECHO + $ECHO "*** Warning: Trying to link with static lib archive $deplib." + $ECHO "*** I have the capability to make that library automatically link in when" + $ECHO "*** you link to this library. But I can only do this if you have a" + $ECHO "*** shared version of the library, which you do not appear to have" + $ECHO "*** because the file extensions .$libext of this argument makes me believe" + $ECHO "*** that it is just a static archive that I should not use here." + else + $ECHO + $ECHO "*** Warning: Linking the shared library $output against the" + $ECHO "*** static library $deplib is not portable!" + deplibs="$deplib $deplibs" + fi + ;; + esac + continue + ;; + prog) + if test "$pass" != link; then + deplibs="$deplib $deplibs" + else + compile_deplibs="$deplib $compile_deplibs" + finalize_deplibs="$deplib $finalize_deplibs" + fi + continue + ;; + esac # linkmode + ;; # *.$libext + *.lo | *.$objext) + if test "$pass" = conv; then + deplibs="$deplib $deplibs" + elif test "$linkmode" = prog; then + if test "$pass" = dlpreopen || test "$dlopen_support" != yes || test "$build_libtool_libs" = no; then + # If there is no dlopen support or we're linking statically, + # we need to preload. + newdlprefiles="$newdlprefiles $deplib" + compile_deplibs="$deplib $compile_deplibs" + finalize_deplibs="$deplib $finalize_deplibs" + else + newdlfiles="$newdlfiles $deplib" + fi + fi + continue + ;; + %DEPLIBS%) + alldeplibs=yes + continue + ;; + esac # case $deplib + + if test "$found" = yes || test -f "$lib"; then : + else + func_fatal_error "cannot find the library \`$lib' or unhandled argument \`$deplib'" + fi + + # Check to see that this really is a libtool archive. + func_lalib_unsafe_p "$lib" \ + || func_fatal_error "\`$lib' is not a valid libtool archive" + + func_dirname "$lib" "" "." + ladir="$func_dirname_result" + + dlname= + dlopen= + dlpreopen= + libdir= + library_names= + old_library= + inherited_linker_flags= + # If the library was installed with an old release of libtool, + # it will not redefine variables installed, or shouldnotlink + installed=yes + shouldnotlink=no + avoidtemprpath= + + + # Read the .la file + func_source "$lib" + + # Convert "-framework foo" to "foo.ltframework" + if test -n "$inherited_linker_flags"; then + tmp_inherited_linker_flags=`$ECHO "X$inherited_linker_flags" | $Xsed -e 's/-framework \([^ $]*\)/\1.ltframework/g'` + for tmp_inherited_linker_flag in $tmp_inherited_linker_flags; do + case " $new_inherited_linker_flags " in + *" $tmp_inherited_linker_flag "*) ;; + *) new_inherited_linker_flags="$new_inherited_linker_flags $tmp_inherited_linker_flag";; + esac + done + fi + dependency_libs=`$ECHO "X $dependency_libs" | $Xsed -e 's% \([^ $]*\).ltframework% -framework \1%g'` + if test "$linkmode,$pass" = "lib,link" || + test "$linkmode,$pass" = "prog,scan" || + { test "$linkmode" != prog && test "$linkmode" != lib; }; then + test -n "$dlopen" && dlfiles="$dlfiles $dlopen" + test -n "$dlpreopen" && dlprefiles="$dlprefiles $dlpreopen" + fi + + if test "$pass" = conv; then + # Only check for convenience libraries + deplibs="$lib $deplibs" + if test -z "$libdir"; then + if test -z "$old_library"; then + func_fatal_error "cannot find name of link library for \`$lib'" + fi + # It is a libtool convenience library, so add in its objects. + convenience="$convenience $ladir/$objdir/$old_library" + old_convenience="$old_convenience $ladir/$objdir/$old_library" + elif test "$linkmode" != prog && test "$linkmode" != lib; then + func_fatal_error "\`$lib' is not a convenience library" + fi + tmp_libs= + for deplib in $dependency_libs; do + deplibs="$deplib $deplibs" + if $opt_duplicate_deps ; then + case "$tmp_libs " in + *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;; + esac + fi + tmp_libs="$tmp_libs $deplib" + done + continue + fi # $pass = conv + + + # Get the name of the library we link against. + linklib= + for l in $old_library $library_names; do + linklib="$l" + done + if test -z "$linklib"; then + func_fatal_error "cannot find name of link library for \`$lib'" + fi + + # This library was specified with -dlopen. + if test "$pass" = dlopen; then + if test -z "$libdir"; then + func_fatal_error "cannot -dlopen a convenience library: \`$lib'" + fi + if test -z "$dlname" || + test "$dlopen_support" != yes || + test "$build_libtool_libs" = no; then + # If there is no dlname, no dlopen support or we're linking + # statically, we need to preload. We also need to preload any + # dependent libraries so libltdl's deplib preloader doesn't + # bomb out in the load deplibs phase. + dlprefiles="$dlprefiles $lib $dependency_libs" + else + newdlfiles="$newdlfiles $lib" + fi + continue + fi # $pass = dlopen + + # We need an absolute path. + case $ladir in + [\\/]* | [A-Za-z]:[\\/]*) abs_ladir="$ladir" ;; + *) + abs_ladir=`cd "$ladir" && pwd` + if test -z "$abs_ladir"; then + func_warning "cannot determine absolute directory name of \`$ladir'" + func_warning "passing it literally to the linker, although it might fail" + abs_ladir="$ladir" + fi + ;; + esac + func_basename "$lib" + laname="$func_basename_result" + + # Find the relevant object directory and library name. + if test "X$installed" = Xyes; then + if test ! -f "$libdir/$linklib" && test -f "$abs_ladir/$linklib"; then + func_warning "library \`$lib' was moved." + dir="$ladir" + absdir="$abs_ladir" + libdir="$abs_ladir" + else + dir="$libdir" + absdir="$libdir" + fi + test "X$hardcode_automatic" = Xyes && avoidtemprpath=yes + else + if test ! -f "$ladir/$objdir/$linklib" && test -f "$abs_ladir/$linklib"; then + dir="$ladir" + absdir="$abs_ladir" + # Remove this search path later + notinst_path="$notinst_path $abs_ladir" + else + dir="$ladir/$objdir" + absdir="$abs_ladir/$objdir" + # Remove this search path later + notinst_path="$notinst_path $abs_ladir" + fi + fi # $installed = yes + func_stripname 'lib' '.la' "$laname" + name=$func_stripname_result + + # This library was specified with -dlpreopen. + if test "$pass" = dlpreopen; then + if test -z "$libdir" && test "$linkmode" = prog; then + func_fatal_error "only libraries may -dlpreopen a convenience library: \`$lib'" + fi + # Prefer using a static library (so that no silly _DYNAMIC symbols + # are required to link). + if test -n "$old_library"; then + newdlprefiles="$newdlprefiles $dir/$old_library" + # Keep a list of preopened convenience libraries to check + # that they are being used correctly in the link pass. + test -z "$libdir" && \ + dlpreconveniencelibs="$dlpreconveniencelibs $dir/$old_library" + # Otherwise, use the dlname, so that lt_dlopen finds it. + elif test -n "$dlname"; then + newdlprefiles="$newdlprefiles $dir/$dlname" + else + newdlprefiles="$newdlprefiles $dir/$linklib" + fi + fi # $pass = dlpreopen + + if test -z "$libdir"; then + # Link the convenience library + if test "$linkmode" = lib; then + deplibs="$dir/$old_library $deplibs" + elif test "$linkmode,$pass" = "prog,link"; then + compile_deplibs="$dir/$old_library $compile_deplibs" + finalize_deplibs="$dir/$old_library $finalize_deplibs" + else + deplibs="$lib $deplibs" # used for prog,scan pass + fi + continue + fi + + + if test "$linkmode" = prog && test "$pass" != link; then + newlib_search_path="$newlib_search_path $ladir" + deplibs="$lib $deplibs" + + linkalldeplibs=no + if test "$link_all_deplibs" != no || test -z "$library_names" || + test "$build_libtool_libs" = no; then + linkalldeplibs=yes + fi + + tmp_libs= + for deplib in $dependency_libs; do + case $deplib in + -L*) func_stripname '-L' '' "$deplib" + newlib_search_path="$newlib_search_path $func_stripname_result" + ;; + esac + # Need to link against all dependency_libs? + if test "$linkalldeplibs" = yes; then + deplibs="$deplib $deplibs" + else + # Need to hardcode shared library paths + # or/and link against static libraries + newdependency_libs="$deplib $newdependency_libs" + fi + if $opt_duplicate_deps ; then + case "$tmp_libs " in + *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;; + esac + fi + tmp_libs="$tmp_libs $deplib" + done # for deplib + continue + fi # $linkmode = prog... + + if test "$linkmode,$pass" = "prog,link"; then + if test -n "$library_names" && + { { test "$prefer_static_libs" = no || + test "$prefer_static_libs,$installed" = "built,yes"; } || + test -z "$old_library"; }; then + # We need to hardcode the library path + if test -n "$shlibpath_var" && test -z "$avoidtemprpath" ; then + # Make sure the rpath contains only unique directories. + case "$temp_rpath:" in + *"$absdir:"*) ;; + *) temp_rpath="$temp_rpath$absdir:" ;; + esac + fi + + # Hardcode the library path. + # Skip directories that are in the system default run-time + # search path. + case " $sys_lib_dlsearch_path " in + *" $absdir "*) ;; + *) + case "$compile_rpath " in + *" $absdir "*) ;; + *) compile_rpath="$compile_rpath $absdir" + esac + ;; + esac + case " $sys_lib_dlsearch_path " in + *" $libdir "*) ;; + *) + case "$finalize_rpath " in + *" $libdir "*) ;; + *) finalize_rpath="$finalize_rpath $libdir" + esac + ;; + esac + fi # $linkmode,$pass = prog,link... + + if test "$alldeplibs" = yes && + { test "$deplibs_check_method" = pass_all || + { test "$build_libtool_libs" = yes && + test -n "$library_names"; }; }; then + # We only need to search for static libraries + continue + fi + fi + + link_static=no # Whether the deplib will be linked statically + use_static_libs=$prefer_static_libs + if test "$use_static_libs" = built && test "$installed" = yes; then + use_static_libs=no + fi + if test -n "$library_names" && + { test "$use_static_libs" = no || test -z "$old_library"; }; then + case $host in + *cygwin* | *mingw* | *cegcc*) + # No point in relinking DLLs because paths are not encoded + notinst_deplibs="$notinst_deplibs $lib" + need_relink=no + ;; + *) + if test "$installed" = no; then + notinst_deplibs="$notinst_deplibs $lib" + need_relink=yes + fi + ;; + esac + # This is a shared library + + # Warn about portability, can't link against -module's on some + # systems (darwin). Don't bleat about dlopened modules though! + dlopenmodule="" + for dlpremoduletest in $dlprefiles; do + if test "X$dlpremoduletest" = "X$lib"; then + dlopenmodule="$dlpremoduletest" + break + fi + done + if test -z "$dlopenmodule" && test "$shouldnotlink" = yes && test "$pass" = link; then + $ECHO + if test "$linkmode" = prog; then + $ECHO "*** Warning: Linking the executable $output against the loadable module" + else + $ECHO "*** Warning: Linking the shared library $output against the loadable module" + fi + $ECHO "*** $linklib is not portable!" + fi + if test "$linkmode" = lib && + test "$hardcode_into_libs" = yes; then + # Hardcode the library path. + # Skip directories that are in the system default run-time + # search path. + case " $sys_lib_dlsearch_path " in + *" $absdir "*) ;; + *) + case "$compile_rpath " in + *" $absdir "*) ;; + *) compile_rpath="$compile_rpath $absdir" + esac + ;; + esac + case " $sys_lib_dlsearch_path " in + *" $libdir "*) ;; + *) + case "$finalize_rpath " in + *" $libdir "*) ;; + *) finalize_rpath="$finalize_rpath $libdir" + esac + ;; + esac + fi + + if test -n "$old_archive_from_expsyms_cmds"; then + # figure out the soname + set dummy $library_names + shift + realname="$1" + shift + libname=`eval "\\$ECHO \"$libname_spec\""` + # use dlname if we got it. it's perfectly good, no? + if test -n "$dlname"; then + soname="$dlname" + elif test -n "$soname_spec"; then + # bleh windows + case $host in + *cygwin* | mingw* | *cegcc*) + func_arith $current - $age + major=$func_arith_result + versuffix="-$major" + ;; + esac + eval soname=\"$soname_spec\" + else + soname="$realname" + fi + + # Make a new name for the extract_expsyms_cmds to use + soroot="$soname" + func_basename "$soroot" + soname="$func_basename_result" + func_stripname 'lib' '.dll' "$soname" + newlib=libimp-$func_stripname_result.a + + # If the library has no export list, then create one now + if test -f "$output_objdir/$soname-def"; then : + else + func_verbose "extracting exported symbol list from \`$soname'" + func_execute_cmds "$extract_expsyms_cmds" 'exit $?' + fi + + # Create $newlib + if test -f "$output_objdir/$newlib"; then :; else + func_verbose "generating import library for \`$soname'" + func_execute_cmds "$old_archive_from_expsyms_cmds" 'exit $?' + fi + # make sure the library variables are pointing to the new library + dir=$output_objdir + linklib=$newlib + fi # test -n "$old_archive_from_expsyms_cmds" + + if test "$linkmode" = prog || test "$mode" != relink; then + add_shlibpath= + add_dir= + add= + lib_linked=yes + case $hardcode_action in + immediate | unsupported) + if test "$hardcode_direct" = no; then + add="$dir/$linklib" + case $host in + *-*-sco3.2v5.0.[024]*) add_dir="-L$dir" ;; + *-*-sysv4*uw2*) add_dir="-L$dir" ;; + *-*-sysv5OpenUNIX* | *-*-sysv5UnixWare7.[01].[10]* | \ + *-*-unixware7*) add_dir="-L$dir" ;; + *-*-darwin* ) + # if the lib is a (non-dlopened) module then we can not + # link against it, someone is ignoring the earlier warnings + if /usr/bin/file -L $add 2> /dev/null | + $GREP ": [^:]* bundle" >/dev/null ; then + if test "X$dlopenmodule" != "X$lib"; then + $ECHO "*** Warning: lib $linklib is a module, not a shared library" + if test -z "$old_library" ; then + $ECHO + $ECHO "*** And there doesn't seem to be a static archive available" + $ECHO "*** The link will probably fail, sorry" + else + add="$dir/$old_library" + fi + elif test -n "$old_library"; then + add="$dir/$old_library" + fi + fi + esac + elif test "$hardcode_minus_L" = no; then + case $host in + *-*-sunos*) add_shlibpath="$dir" ;; + esac + add_dir="-L$dir" + add="-l$name" + elif test "$hardcode_shlibpath_var" = no; then + add_shlibpath="$dir" + add="-l$name" + else + lib_linked=no + fi + ;; + relink) + if test "$hardcode_direct" = yes && + test "$hardcode_direct_absolute" = no; then + add="$dir/$linklib" + elif test "$hardcode_minus_L" = yes; then + add_dir="-L$dir" + # Try looking first in the location we're being installed to. + if test -n "$inst_prefix_dir"; then + case $libdir in + [\\/]*) + add_dir="$add_dir -L$inst_prefix_dir$libdir" + ;; + esac + fi + add="-l$name" + elif test "$hardcode_shlibpath_var" = yes; then + add_shlibpath="$dir" + add="-l$name" + else + lib_linked=no + fi + ;; + *) lib_linked=no ;; + esac + + if test "$lib_linked" != yes; then + func_fatal_configuration "unsupported hardcode properties" + fi + + if test -n "$add_shlibpath"; then + case :$compile_shlibpath: in + *":$add_shlibpath:"*) ;; + *) compile_shlibpath="$compile_shlibpath$add_shlibpath:" ;; + esac + fi + if test "$linkmode" = prog; then + test -n "$add_dir" && compile_deplibs="$add_dir $compile_deplibs" + test -n "$add" && compile_deplibs="$add $compile_deplibs" + else + test -n "$add_dir" && deplibs="$add_dir $deplibs" + test -n "$add" && deplibs="$add $deplibs" + if test "$hardcode_direct" != yes && + test "$hardcode_minus_L" != yes && + test "$hardcode_shlibpath_var" = yes; then + case :$finalize_shlibpath: in + *":$libdir:"*) ;; + *) finalize_shlibpath="$finalize_shlibpath$libdir:" ;; + esac + fi + fi + fi + + if test "$linkmode" = prog || test "$mode" = relink; then + add_shlibpath= + add_dir= + add= + # Finalize command for both is simple: just hardcode it. + if test "$hardcode_direct" = yes && + test "$hardcode_direct_absolute" = no; then + add="$libdir/$linklib" + elif test "$hardcode_minus_L" = yes; then + add_dir="-L$libdir" + add="-l$name" + elif test "$hardcode_shlibpath_var" = yes; then + case :$finalize_shlibpath: in + *":$libdir:"*) ;; + *) finalize_shlibpath="$finalize_shlibpath$libdir:" ;; + esac + add="-l$name" + elif test "$hardcode_automatic" = yes; then + if test -n "$inst_prefix_dir" && + test -f "$inst_prefix_dir$libdir/$linklib" ; then + add="$inst_prefix_dir$libdir/$linklib" + else + add="$libdir/$linklib" + fi + else + # We cannot seem to hardcode it, guess we'll fake it. + add_dir="-L$libdir" + # Try looking first in the location we're being installed to. + if test -n "$inst_prefix_dir"; then + case $libdir in + [\\/]*) + add_dir="$add_dir -L$inst_prefix_dir$libdir" + ;; + esac + fi + add="-l$name" + fi + + if test "$linkmode" = prog; then + test -n "$add_dir" && finalize_deplibs="$add_dir $finalize_deplibs" + test -n "$add" && finalize_deplibs="$add $finalize_deplibs" + else + test -n "$add_dir" && deplibs="$add_dir $deplibs" + test -n "$add" && deplibs="$add $deplibs" + fi + fi + elif test "$linkmode" = prog; then + # Here we assume that one of hardcode_direct or hardcode_minus_L + # is not unsupported. This is valid on all known static and + # shared platforms. + if test "$hardcode_direct" != unsupported; then + test -n "$old_library" && linklib="$old_library" + compile_deplibs="$dir/$linklib $compile_deplibs" + finalize_deplibs="$dir/$linklib $finalize_deplibs" + else + compile_deplibs="-l$name -L$dir $compile_deplibs" + finalize_deplibs="-l$name -L$dir $finalize_deplibs" + fi + elif test "$build_libtool_libs" = yes; then + # Not a shared library + if test "$deplibs_check_method" != pass_all; then + # We're trying link a shared library against a static one + # but the system doesn't support it. + + # Just print a warning and add the library to dependency_libs so + # that the program can be linked against the static library. + $ECHO + $ECHO "*** Warning: This system can not link to static lib archive $lib." + $ECHO "*** I have the capability to make that library automatically link in when" + $ECHO "*** you link to this library. But I can only do this if you have a" + $ECHO "*** shared version of the library, which you do not appear to have." + if test "$module" = yes; then + $ECHO "*** But as you try to build a module library, libtool will still create " + $ECHO "*** a static module, that should work as long as the dlopening application" + $ECHO "*** is linked with the -dlopen flag to resolve symbols at runtime." + if test -z "$global_symbol_pipe"; then + $ECHO + $ECHO "*** However, this would only work if libtool was able to extract symbol" + $ECHO "*** lists from a program, using \`nm' or equivalent, but libtool could" + $ECHO "*** not find such a program. So, this module is probably useless." + $ECHO "*** \`nm' from GNU binutils and a full rebuild may help." + fi + if test "$build_old_libs" = no; then + build_libtool_libs=module + build_old_libs=yes + else + build_libtool_libs=no + fi + fi + else + deplibs="$dir/$old_library $deplibs" + link_static=yes + fi + fi # link shared/static library? + + if test "$linkmode" = lib; then + if test -n "$dependency_libs" && + { test "$hardcode_into_libs" != yes || + test "$build_old_libs" = yes || + test "$link_static" = yes; }; then + # Extract -R from dependency_libs + temp_deplibs= + for libdir in $dependency_libs; do + case $libdir in + -R*) func_stripname '-R' '' "$libdir" + temp_xrpath=$func_stripname_result + case " $xrpath " in + *" $temp_xrpath "*) ;; + *) xrpath="$xrpath $temp_xrpath";; + esac;; + *) temp_deplibs="$temp_deplibs $libdir";; + esac + done + dependency_libs="$temp_deplibs" + fi + + newlib_search_path="$newlib_search_path $absdir" + # Link against this library + test "$link_static" = no && newdependency_libs="$abs_ladir/$laname $newdependency_libs" + # ... and its dependency_libs + tmp_libs= + for deplib in $dependency_libs; do + newdependency_libs="$deplib $newdependency_libs" + if $opt_duplicate_deps ; then + case "$tmp_libs " in + *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;; + esac + fi + tmp_libs="$tmp_libs $deplib" + done + + if test "$link_all_deplibs" != no; then + # Add the search paths of all dependency libraries + for deplib in $dependency_libs; do + case $deplib in + -L*) path="$deplib" ;; + *.la) + func_dirname "$deplib" "" "." + dir="$func_dirname_result" + # We need an absolute path. + case $dir in + [\\/]* | [A-Za-z]:[\\/]*) absdir="$dir" ;; + *) + absdir=`cd "$dir" && pwd` + if test -z "$absdir"; then + func_warning "cannot determine absolute directory name of \`$dir'" + absdir="$dir" + fi + ;; + esac + if $GREP "^installed=no" $deplib > /dev/null; then + case $host in + *-*-darwin*) + depdepl= + eval deplibrary_names=`${SED} -n -e 's/^library_names=\(.*\)$/\1/p' $deplib` + if test -n "$deplibrary_names" ; then + for tmp in $deplibrary_names ; do + depdepl=$tmp + done + if test -f "$absdir/$objdir/$depdepl" ; then + depdepl="$absdir/$objdir/$depdepl" + darwin_install_name=`${OTOOL} -L $depdepl | awk '{if (NR == 2) {print $1;exit}}'` + if test -z "$darwin_install_name"; then + darwin_install_name=`${OTOOL64} -L $depdepl | awk '{if (NR == 2) {print $1;exit}}'` + fi + compiler_flags="$compiler_flags ${wl}-dylib_file ${wl}${darwin_install_name}:${depdepl}" + linker_flags="$linker_flags -dylib_file ${darwin_install_name}:${depdepl}" + path= + fi + fi + ;; + *) + path="-L$absdir/$objdir" + ;; + esac + else + eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $deplib` + test -z "$libdir" && \ + func_fatal_error "\`$deplib' is not a valid libtool archive" + test "$absdir" != "$libdir" && \ + func_warning "\`$deplib' seems to be moved" + + path="-L$absdir" + fi + ;; + esac + case " $deplibs " in + *" $path "*) ;; + *) deplibs="$path $deplibs" ;; + esac + done + fi # link_all_deplibs != no + fi # linkmode = lib + done # for deplib in $libs + if test "$pass" = link; then + if test "$linkmode" = "prog"; then + compile_deplibs="$new_inherited_linker_flags $compile_deplibs" + finalize_deplibs="$new_inherited_linker_flags $finalize_deplibs" + else + compiler_flags="$compiler_flags "`$ECHO "X $new_inherited_linker_flags" | $Xsed -e 's% \([^ $]*\).ltframework% -framework \1%g'` + fi + fi + dependency_libs="$newdependency_libs" + if test "$pass" = dlpreopen; then + # Link the dlpreopened libraries before other libraries + for deplib in $save_deplibs; do + deplibs="$deplib $deplibs" + done + fi + if test "$pass" != dlopen; then + if test "$pass" != conv; then + # Make sure lib_search_path contains only unique directories. + lib_search_path= + for dir in $newlib_search_path; do + case "$lib_search_path " in + *" $dir "*) ;; + *) lib_search_path="$lib_search_path $dir" ;; + esac + done + newlib_search_path= + fi + + if test "$linkmode,$pass" != "prog,link"; then + vars="deplibs" + else + vars="compile_deplibs finalize_deplibs" + fi + for var in $vars dependency_libs; do + # Add libraries to $var in reverse order + eval tmp_libs=\"\$$var\" + new_libs= + for deplib in $tmp_libs; do + # FIXME: Pedantically, this is the right thing to do, so + # that some nasty dependency loop isn't accidentally + # broken: + #new_libs="$deplib $new_libs" + # Pragmatically, this seems to cause very few problems in + # practice: + case $deplib in + -L*) new_libs="$deplib $new_libs" ;; + -R*) ;; + *) + # And here is the reason: when a library appears more + # than once as an explicit dependence of a library, or + # is implicitly linked in more than once by the + # compiler, it is considered special, and multiple + # occurrences thereof are not removed. Compare this + # with having the same library being listed as a + # dependency of multiple other libraries: in this case, + # we know (pedantically, we assume) the library does not + # need to be listed more than once, so we keep only the + # last copy. This is not always right, but it is rare + # enough that we require users that really mean to play + # such unportable linking tricks to link the library + # using -Wl,-lname, so that libtool does not consider it + # for duplicate removal. + case " $specialdeplibs " in + *" $deplib "*) new_libs="$deplib $new_libs" ;; + *) + case " $new_libs " in + *" $deplib "*) ;; + *) new_libs="$deplib $new_libs" ;; + esac + ;; + esac + ;; + esac + done + tmp_libs= + for deplib in $new_libs; do + case $deplib in + -L*) + case " $tmp_libs " in + *" $deplib "*) ;; + *) tmp_libs="$tmp_libs $deplib" ;; + esac + ;; + *) tmp_libs="$tmp_libs $deplib" ;; + esac + done + eval $var=\"$tmp_libs\" + done # for var + fi + # Last step: remove runtime libs from dependency_libs + # (they stay in deplibs) + tmp_libs= + for i in $dependency_libs ; do + case " $predeps $postdeps $compiler_lib_search_path " in + *" $i "*) + i="" + ;; + esac + if test -n "$i" ; then + tmp_libs="$tmp_libs $i" + fi + done + dependency_libs=$tmp_libs + done # for pass + if test "$linkmode" = prog; then + dlfiles="$newdlfiles" + fi + if test "$linkmode" = prog || test "$linkmode" = lib; then + dlprefiles="$newdlprefiles" + fi + + case $linkmode in + oldlib) + if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then + func_warning "\`-dlopen' is ignored for archives" + fi + + case " $deplibs" in + *\ -l* | *\ -L*) + func_warning "\`-l' and \`-L' are ignored for archives" ;; + esac + + test -n "$rpath" && \ + func_warning "\`-rpath' is ignored for archives" + + test -n "$xrpath" && \ + func_warning "\`-R' is ignored for archives" + + test -n "$vinfo" && \ + func_warning "\`-version-info/-version-number' is ignored for archives" + + test -n "$release" && \ + func_warning "\`-release' is ignored for archives" + + test -n "$export_symbols$export_symbols_regex" && \ + func_warning "\`-export-symbols' is ignored for archives" + + # Now set the variables for building old libraries. + build_libtool_libs=no + oldlibs="$output" + objs="$objs$old_deplibs" + ;; + + lib) + # Make sure we only generate libraries of the form `libNAME.la'. + case $outputname in + lib*) + func_stripname 'lib' '.la' "$outputname" + name=$func_stripname_result + eval shared_ext=\"$shrext_cmds\" + eval libname=\"$libname_spec\" + ;; + *) + test "$module" = no && \ + func_fatal_help "libtool library \`$output' must begin with \`lib'" + + if test "$need_lib_prefix" != no; then + # Add the "lib" prefix for modules if required + func_stripname '' '.la' "$outputname" + name=$func_stripname_result + eval shared_ext=\"$shrext_cmds\" + eval libname=\"$libname_spec\" + else + func_stripname '' '.la' "$outputname" + libname=$func_stripname_result + fi + ;; + esac + + if test -n "$objs"; then + if test "$deplibs_check_method" != pass_all; then + func_fatal_error "cannot build libtool library \`$output' from non-libtool objects on this host:$objs" + else + $ECHO + $ECHO "*** Warning: Linking the shared library $output against the non-libtool" + $ECHO "*** objects $objs is not portable!" + libobjs="$libobjs $objs" + fi + fi + + test "$dlself" != no && \ + func_warning "\`-dlopen self' is ignored for libtool libraries" + + set dummy $rpath + shift + test "$#" -gt 1 && \ + func_warning "ignoring multiple \`-rpath's for a libtool library" + + install_libdir="$1" + + oldlibs= + if test -z "$rpath"; then + if test "$build_libtool_libs" = yes; then + # Building a libtool convenience library. + # Some compilers have problems with a `.al' extension so + # convenience libraries should have the same extension an + # archive normally would. + oldlibs="$output_objdir/$libname.$libext $oldlibs" + build_libtool_libs=convenience + build_old_libs=yes + fi + + test -n "$vinfo" && \ + func_warning "\`-version-info/-version-number' is ignored for convenience libraries" + + test -n "$release" && \ + func_warning "\`-release' is ignored for convenience libraries" + else + + # Parse the version information argument. + save_ifs="$IFS"; IFS=':' + set dummy $vinfo 0 0 0 + shift + IFS="$save_ifs" + + test -n "$7" && \ + func_fatal_help "too many parameters to \`-version-info'" + + # convert absolute version numbers to libtool ages + # this retains compatibility with .la files and attempts + # to make the code below a bit more comprehensible + + case $vinfo_number in + yes) + number_major="$1" + number_minor="$2" + number_revision="$3" + # + # There are really only two kinds -- those that + # use the current revision as the major version + # and those that subtract age and use age as + # a minor version. But, then there is irix + # which has an extra 1 added just for fun + # + case $version_type in + darwin|linux|osf|windows|none) + func_arith $number_major + $number_minor + current=$func_arith_result + age="$number_minor" + revision="$number_revision" + ;; + freebsd-aout|freebsd-elf|sunos) + current="$number_major" + revision="$number_minor" + age="0" + ;; + irix|nonstopux) + func_arith $number_major + $number_minor + current=$func_arith_result + age="$number_minor" + revision="$number_minor" + lt_irix_increment=no + ;; + esac + ;; + no) + current="$1" + revision="$2" + age="$3" + ;; + esac + + # Check that each of the things are valid numbers. + case $current in + 0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;; + *) + func_error "CURRENT \`$current' must be a nonnegative integer" + func_fatal_error "\`$vinfo' is not valid version information" + ;; + esac + + case $revision in + 0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;; + *) + func_error "REVISION \`$revision' must be a nonnegative integer" + func_fatal_error "\`$vinfo' is not valid version information" + ;; + esac + + case $age in + 0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;; + *) + func_error "AGE \`$age' must be a nonnegative integer" + func_fatal_error "\`$vinfo' is not valid version information" + ;; + esac + + if test "$age" -gt "$current"; then + func_error "AGE \`$age' is greater than the current interface number \`$current'" + func_fatal_error "\`$vinfo' is not valid version information" + fi + + # Calculate the version variables. + major= + versuffix= + verstring= + case $version_type in + none) ;; + + darwin) + # Like Linux, but with the current version available in + # verstring for coding it into the library header + func_arith $current - $age + major=.$func_arith_result + versuffix="$major.$age.$revision" + # Darwin ld doesn't like 0 for these options... + func_arith $current + 1 + minor_current=$func_arith_result + xlcverstring="${wl}-compatibility_version ${wl}$minor_current ${wl}-current_version ${wl}$minor_current.$revision" + verstring="-compatibility_version $minor_current -current_version $minor_current.$revision" + ;; + + freebsd-aout) + major=".$current" + versuffix=".$current.$revision"; + ;; + + freebsd-elf) + major=".$current" + versuffix=".$current" + ;; + + irix | nonstopux) + if test "X$lt_irix_increment" = "Xno"; then + func_arith $current - $age + else + func_arith $current - $age + 1 + fi + major=$func_arith_result + + case $version_type in + nonstopux) verstring_prefix=nonstopux ;; + *) verstring_prefix=sgi ;; + esac + verstring="$verstring_prefix$major.$revision" + + # Add in all the interfaces that we are compatible with. + loop=$revision + while test "$loop" -ne 0; do + func_arith $revision - $loop + iface=$func_arith_result + func_arith $loop - 1 + loop=$func_arith_result + verstring="$verstring_prefix$major.$iface:$verstring" + done + + # Before this point, $major must not contain `.'. + major=.$major + versuffix="$major.$revision" + ;; + + linux) + func_arith $current - $age + major=.$func_arith_result + versuffix="$major.$age.$revision" + ;; + + osf) + func_arith $current - $age + major=.$func_arith_result + versuffix=".$current.$age.$revision" + verstring="$current.$age.$revision" + + # Add in all the interfaces that we are compatible with. + loop=$age + while test "$loop" -ne 0; do + func_arith $current - $loop + iface=$func_arith_result + func_arith $loop - 1 + loop=$func_arith_result + verstring="$verstring:${iface}.0" + done + + # Make executables depend on our current version. + verstring="$verstring:${current}.0" + ;; + + qnx) + major=".$current" + versuffix=".$current" + ;; + + sunos) + major=".$current" + versuffix=".$current.$revision" + ;; + + windows) + # Use '-' rather than '.', since we only want one + # extension on DOS 8.3 filesystems. + func_arith $current - $age + major=$func_arith_result + versuffix="-$major" + ;; + + *) + func_fatal_configuration "unknown library version type \`$version_type'" + ;; + esac + + # Clear the version info if we defaulted, and they specified a release. + if test -z "$vinfo" && test -n "$release"; then + major= + case $version_type in + darwin) + # we can't check for "0.0" in archive_cmds due to quoting + # problems, so we reset it completely + verstring= + ;; + *) + verstring="0.0" + ;; + esac + if test "$need_version" = no; then + versuffix= + else + versuffix=".0.0" + fi + fi + + # Remove version info from name if versioning should be avoided + if test "$avoid_version" = yes && test "$need_version" = no; then + major= + versuffix= + verstring="" + fi + + # Check to see if the archive will have undefined symbols. + if test "$allow_undefined" = yes; then + if test "$allow_undefined_flag" = unsupported; then + func_warning "undefined symbols not allowed in $host shared libraries" + build_libtool_libs=no + build_old_libs=yes + fi + else + # Don't allow undefined symbols. + allow_undefined_flag="$no_undefined_flag" + fi + + fi + + func_generate_dlsyms "$libname" "$libname" "yes" + libobjs="$libobjs $symfileobj" + test "X$libobjs" = "X " && libobjs= + + if test "$mode" != relink; then + # Remove our outputs, but don't remove object files since they + # may have been created when compiling PIC objects. + removelist= + tempremovelist=`$ECHO "$output_objdir/*"` + for p in $tempremovelist; do + case $p in + *.$objext | *.gcno) + ;; + $output_objdir/$outputname | $output_objdir/$libname.* | $output_objdir/${libname}${release}.*) + if test "X$precious_files_regex" != "X"; then + if $ECHO "$p" | $EGREP -e "$precious_files_regex" >/dev/null 2>&1 + then + continue + fi + fi + removelist="$removelist $p" + ;; + *) ;; + esac + done + test -n "$removelist" && \ + func_show_eval "${RM}r \$removelist" + fi + + # Now set the variables for building old libraries. + if test "$build_old_libs" = yes && test "$build_libtool_libs" != convenience ; then + oldlibs="$oldlibs $output_objdir/$libname.$libext" + + # Transform .lo files to .o files. + oldobjs="$objs "`$ECHO "X$libobjs" | $SP2NL | $Xsed -e '/\.'${libext}'$/d' -e "$lo2o" | $NL2SP` + fi + + # Eliminate all temporary directories. + #for path in $notinst_path; do + # lib_search_path=`$ECHO "X$lib_search_path " | $Xsed -e "s% $path % %g"` + # deplibs=`$ECHO "X$deplibs " | $Xsed -e "s% -L$path % %g"` + # dependency_libs=`$ECHO "X$dependency_libs " | $Xsed -e "s% -L$path % %g"` + #done + + if test -n "$xrpath"; then + # If the user specified any rpath flags, then add them. + temp_xrpath= + for libdir in $xrpath; do + temp_xrpath="$temp_xrpath -R$libdir" + case "$finalize_rpath " in + *" $libdir "*) ;; + *) finalize_rpath="$finalize_rpath $libdir" ;; + esac + done + if test "$hardcode_into_libs" != yes || test "$build_old_libs" = yes; then + dependency_libs="$temp_xrpath $dependency_libs" + fi + fi + + # Make sure dlfiles contains only unique files that won't be dlpreopened + old_dlfiles="$dlfiles" + dlfiles= + for lib in $old_dlfiles; do + case " $dlprefiles $dlfiles " in + *" $lib "*) ;; + *) dlfiles="$dlfiles $lib" ;; + esac + done + + # Make sure dlprefiles contains only unique files + old_dlprefiles="$dlprefiles" + dlprefiles= + for lib in $old_dlprefiles; do + case "$dlprefiles " in + *" $lib "*) ;; + *) dlprefiles="$dlprefiles $lib" ;; + esac + done + + if test "$build_libtool_libs" = yes; then + if test -n "$rpath"; then + case $host in + *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-beos* | *-cegcc*) + # these systems don't actually have a c library (as such)! + ;; + *-*-rhapsody* | *-*-darwin1.[012]) + # Rhapsody C library is in the System framework + deplibs="$deplibs System.ltframework" + ;; + *-*-netbsd*) + # Don't link with libc until the a.out ld.so is fixed. + ;; + *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*) + # Do not include libc due to us having libc/libc_r. + ;; + *-*-sco3.2v5* | *-*-sco5v6*) + # Causes problems with __ctype + ;; + *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*) + # Compiler inserts libc in the correct place for threads to work + ;; + *) + # Add libc to deplibs on all other systems if necessary. + if test "$build_libtool_need_lc" = "yes"; then + deplibs="$deplibs -lc" + fi + ;; + esac + fi + + # Transform deplibs into only deplibs that can be linked in shared. + name_save=$name + libname_save=$libname + release_save=$release + versuffix_save=$versuffix + major_save=$major + # I'm not sure if I'm treating the release correctly. I think + # release should show up in the -l (ie -lgmp5) so we don't want to + # add it in twice. Is that correct? + release="" + versuffix="" + major="" + newdeplibs= + droppeddeps=no + case $deplibs_check_method in + pass_all) + # Don't check for shared/static. Everything works. + # This might be a little naive. We might want to check + # whether the library exists or not. But this is on + # osf3 & osf4 and I'm not really sure... Just + # implementing what was already the behavior. + newdeplibs=$deplibs + ;; + test_compile) + # This code stresses the "libraries are programs" paradigm to its + # limits. Maybe even breaks it. We compile a program, linking it + # against the deplibs as a proxy for the library. Then we can check + # whether they linked in statically or dynamically with ldd. + $opt_dry_run || $RM conftest.c + cat > conftest.c </dev/null` + for potent_lib in $potential_libs; do + # Follow soft links. + if ls -lLd "$potent_lib" 2>/dev/null | + $GREP " -> " >/dev/null; then + continue + fi + # The statement above tries to avoid entering an + # endless loop below, in case of cyclic links. + # We might still enter an endless loop, since a link + # loop can be closed while we follow links, + # but so what? + potlib="$potent_lib" + while test -h "$potlib" 2>/dev/null; do + potliblink=`ls -ld $potlib | ${SED} 's/.* -> //'` + case $potliblink in + [\\/]* | [A-Za-z]:[\\/]*) potlib="$potliblink";; + *) potlib=`$ECHO "X$potlib" | $Xsed -e 's,[^/]*$,,'`"$potliblink";; + esac + done + if eval $file_magic_cmd \"\$potlib\" 2>/dev/null | + $SED -e 10q | + $EGREP "$file_magic_regex" > /dev/null; then + newdeplibs="$newdeplibs $a_deplib" + a_deplib="" + break 2 + fi + done + done + fi + if test -n "$a_deplib" ; then + droppeddeps=yes + $ECHO + $ECHO "*** Warning: linker path does not have real file for library $a_deplib." + $ECHO "*** I have the capability to make that library automatically link in when" + $ECHO "*** you link to this library. But I can only do this if you have a" + $ECHO "*** shared version of the library, which you do not appear to have" + $ECHO "*** because I did check the linker path looking for a file starting" + if test -z "$potlib" ; then + $ECHO "*** with $libname but no candidates were found. (...for file magic test)" + else + $ECHO "*** with $libname and none of the candidates passed a file format test" + $ECHO "*** using a file magic. Last file checked: $potlib" + fi + fi + ;; + *) + # Add a -L argument. + newdeplibs="$newdeplibs $a_deplib" + ;; + esac + done # Gone through all deplibs. + ;; + match_pattern*) + set dummy $deplibs_check_method; shift + match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"` + for a_deplib in $deplibs; do + case $a_deplib in + -l*) + func_stripname -l '' "$a_deplib" + name=$func_stripname_result + if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then + case " $predeps $postdeps " in + *" $a_deplib "*) + newdeplibs="$newdeplibs $a_deplib" + a_deplib="" + ;; + esac + fi + if test -n "$a_deplib" ; then + libname=`eval "\\$ECHO \"$libname_spec\""` + for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do + potential_libs=`ls $i/$libname[.-]* 2>/dev/null` + for potent_lib in $potential_libs; do + potlib="$potent_lib" # see symlink-check above in file_magic test + if eval "\$ECHO \"X$potent_lib\"" 2>/dev/null | $Xsed -e 10q | \ + $EGREP "$match_pattern_regex" > /dev/null; then + newdeplibs="$newdeplibs $a_deplib" + a_deplib="" + break 2 + fi + done + done + fi + if test -n "$a_deplib" ; then + droppeddeps=yes + $ECHO + $ECHO "*** Warning: linker path does not have real file for library $a_deplib." + $ECHO "*** I have the capability to make that library automatically link in when" + $ECHO "*** you link to this library. But I can only do this if you have a" + $ECHO "*** shared version of the library, which you do not appear to have" + $ECHO "*** because I did check the linker path looking for a file starting" + if test -z "$potlib" ; then + $ECHO "*** with $libname but no candidates were found. (...for regex pattern test)" + else + $ECHO "*** with $libname and none of the candidates passed a file format test" + $ECHO "*** using a regex pattern. Last file checked: $potlib" + fi + fi + ;; + *) + # Add a -L argument. + newdeplibs="$newdeplibs $a_deplib" + ;; + esac + done # Gone through all deplibs. + ;; + none | unknown | *) + newdeplibs="" + tmp_deplibs=`$ECHO "X $deplibs" | $Xsed \ + -e 's/ -lc$//' -e 's/ -[LR][^ ]*//g'` + if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then + for i in $predeps $postdeps ; do + # can't use Xsed below, because $i might contain '/' + tmp_deplibs=`$ECHO "X $tmp_deplibs" | $Xsed -e "s,$i,,"` + done + fi + if $ECHO "X $tmp_deplibs" | $Xsed -e 's/[ ]//g' | + $GREP . >/dev/null; then + $ECHO + if test "X$deplibs_check_method" = "Xnone"; then + $ECHO "*** Warning: inter-library dependencies are not supported in this platform." + else + $ECHO "*** Warning: inter-library dependencies are not known to be supported." + fi + $ECHO "*** All declared inter-library dependencies are being dropped." + droppeddeps=yes + fi + ;; + esac + versuffix=$versuffix_save + major=$major_save + release=$release_save + libname=$libname_save + name=$name_save + + case $host in + *-*-rhapsody* | *-*-darwin1.[012]) + # On Rhapsody replace the C library with the System framework + newdeplibs=`$ECHO "X $newdeplibs" | $Xsed -e 's/ -lc / System.ltframework /'` + ;; + esac + + if test "$droppeddeps" = yes; then + if test "$module" = yes; then + $ECHO + $ECHO "*** Warning: libtool could not satisfy all declared inter-library" + $ECHO "*** dependencies of module $libname. Therefore, libtool will create" + $ECHO "*** a static module, that should work as long as the dlopening" + $ECHO "*** application is linked with the -dlopen flag." + if test -z "$global_symbol_pipe"; then + $ECHO + $ECHO "*** However, this would only work if libtool was able to extract symbol" + $ECHO "*** lists from a program, using \`nm' or equivalent, but libtool could" + $ECHO "*** not find such a program. So, this module is probably useless." + $ECHO "*** \`nm' from GNU binutils and a full rebuild may help." + fi + if test "$build_old_libs" = no; then + oldlibs="$output_objdir/$libname.$libext" + build_libtool_libs=module + build_old_libs=yes + else + build_libtool_libs=no + fi + else + $ECHO "*** The inter-library dependencies that have been dropped here will be" + $ECHO "*** automatically added whenever a program is linked with this library" + $ECHO "*** or is declared to -dlopen it." + + if test "$allow_undefined" = no; then + $ECHO + $ECHO "*** Since this library must not contain undefined symbols," + $ECHO "*** because either the platform does not support them or" + $ECHO "*** it was explicitly requested with -no-undefined," + $ECHO "*** libtool will only create a static version of it." + if test "$build_old_libs" = no; then + oldlibs="$output_objdir/$libname.$libext" + build_libtool_libs=module + build_old_libs=yes + else + build_libtool_libs=no + fi + fi + fi + fi + # Done checking deplibs! + deplibs=$newdeplibs + fi + # Time to change all our "foo.ltframework" stuff back to "-framework foo" + case $host in + *-*-darwin*) + newdeplibs=`$ECHO "X $newdeplibs" | $Xsed -e 's% \([^ $]*\).ltframework% -framework \1%g'` + new_inherited_linker_flags=`$ECHO "X $new_inherited_linker_flags" | $Xsed -e 's% \([^ $]*\).ltframework% -framework \1%g'` + deplibs=`$ECHO "X $deplibs" | $Xsed -e 's% \([^ $]*\).ltframework% -framework \1%g'` + ;; + esac + + # move library search paths that coincide with paths to not yet + # installed libraries to the beginning of the library search list + new_libs= + for path in $notinst_path; do + case " $new_libs " in + *" -L$path/$objdir "*) ;; + *) + case " $deplibs " in + *" -L$path/$objdir "*) + new_libs="$new_libs -L$path/$objdir" ;; + esac + ;; + esac + done + for deplib in $deplibs; do + case $deplib in + -L*) + case " $new_libs " in + *" $deplib "*) ;; + *) new_libs="$new_libs $deplib" ;; + esac + ;; + *) new_libs="$new_libs $deplib" ;; + esac + done + deplibs="$new_libs" + + # All the library-specific variables (install_libdir is set above). + library_names= + old_library= + dlname= + + # Test again, we may have decided not to build it any more + if test "$build_libtool_libs" = yes; then + if test "$hardcode_into_libs" = yes; then + # Hardcode the library paths + hardcode_libdirs= + dep_rpath= + rpath="$finalize_rpath" + test "$mode" != relink && rpath="$compile_rpath$rpath" + for libdir in $rpath; do + if test -n "$hardcode_libdir_flag_spec"; then + if test -n "$hardcode_libdir_separator"; then + if test -z "$hardcode_libdirs"; then + hardcode_libdirs="$libdir" + else + # Just accumulate the unique libdirs. + case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in + *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*) + ;; + *) + hardcode_libdirs="$hardcode_libdirs$hardcode_libdir_separator$libdir" + ;; + esac + fi + else + eval flag=\"$hardcode_libdir_flag_spec\" + dep_rpath="$dep_rpath $flag" + fi + elif test -n "$runpath_var"; then + case "$perm_rpath " in + *" $libdir "*) ;; + *) perm_rpath="$perm_rpath $libdir" ;; + esac + fi + done + # Substitute the hardcoded libdirs into the rpath. + if test -n "$hardcode_libdir_separator" && + test -n "$hardcode_libdirs"; then + libdir="$hardcode_libdirs" + if test -n "$hardcode_libdir_flag_spec_ld"; then + eval dep_rpath=\"$hardcode_libdir_flag_spec_ld\" + else + eval dep_rpath=\"$hardcode_libdir_flag_spec\" + fi + fi + if test -n "$runpath_var" && test -n "$perm_rpath"; then + # We should set the runpath_var. + rpath= + for dir in $perm_rpath; do + rpath="$rpath$dir:" + done + eval "$runpath_var='$rpath\$$runpath_var'; export $runpath_var" + fi + test -n "$dep_rpath" && deplibs="$dep_rpath $deplibs" + fi + + shlibpath="$finalize_shlibpath" + test "$mode" != relink && shlibpath="$compile_shlibpath$shlibpath" + if test -n "$shlibpath"; then + eval "$shlibpath_var='$shlibpath\$$shlibpath_var'; export $shlibpath_var" + fi + + # Get the real and link names of the library. + eval shared_ext=\"$shrext_cmds\" + eval library_names=\"$library_names_spec\" + set dummy $library_names + shift + realname="$1" + shift + + if test -n "$soname_spec"; then + eval soname=\"$soname_spec\" + else + soname="$realname" + fi + if test -z "$dlname"; then + dlname=$soname + fi + + lib="$output_objdir/$realname" + linknames= + for link + do + linknames="$linknames $link" + done + + # Use standard objects if they are pic + test -z "$pic_flag" && libobjs=`$ECHO "X$libobjs" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP` + test "X$libobjs" = "X " && libobjs= + + delfiles= + if test -n "$export_symbols" && test -n "$include_expsyms"; then + $opt_dry_run || cp "$export_symbols" "$output_objdir/$libname.uexp" + export_symbols="$output_objdir/$libname.uexp" + delfiles="$delfiles $export_symbols" + fi + + orig_export_symbols= + case $host_os in + cygwin* | mingw* | cegcc*) + if test -n "$export_symbols" && test -z "$export_symbols_regex"; then + # exporting using user supplied symfile + if test "x`$SED 1q $export_symbols`" != xEXPORTS; then + # and it's NOT already a .def file. Must figure out + # which of the given symbols are data symbols and tag + # them as such. So, trigger use of export_symbols_cmds. + # export_symbols gets reassigned inside the "prepare + # the list of exported symbols" if statement, so the + # include_expsyms logic still works. + orig_export_symbols="$export_symbols" + export_symbols= + always_export_symbols=yes + fi + fi + ;; + esac + + # Prepare the list of exported symbols + if test -z "$export_symbols"; then + if test "$always_export_symbols" = yes || test -n "$export_symbols_regex"; then + func_verbose "generating symbol list for \`$libname.la'" + export_symbols="$output_objdir/$libname.exp" + $opt_dry_run || $RM $export_symbols + cmds=$export_symbols_cmds + save_ifs="$IFS"; IFS='~' + for cmd in $cmds; do + IFS="$save_ifs" + eval cmd=\"$cmd\" + func_len " $cmd" + len=$func_len_result + if test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then + func_show_eval "$cmd" 'exit $?' + skipped_export=false + else + # The command line is too long to execute in one step. + func_verbose "using reloadable object file for export list..." + skipped_export=: + # Break out early, otherwise skipped_export may be + # set to false by a later but shorter cmd. + break + fi + done + IFS="$save_ifs" + if test -n "$export_symbols_regex" && test "X$skipped_export" != "X:"; then + func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"' + func_show_eval '$MV "${export_symbols}T" "$export_symbols"' + fi + fi + fi + + if test -n "$export_symbols" && test -n "$include_expsyms"; then + tmp_export_symbols="$export_symbols" + test -n "$orig_export_symbols" && tmp_export_symbols="$orig_export_symbols" + $opt_dry_run || eval '$ECHO "X$include_expsyms" | $Xsed | $SP2NL >> "$tmp_export_symbols"' + fi + + if test "X$skipped_export" != "X:" && test -n "$orig_export_symbols"; then + # The given exports_symbols file has to be filtered, so filter it. + func_verbose "filter symbol list for \`$libname.la' to tag DATA exports" + # FIXME: $output_objdir/$libname.filter potentially contains lots of + # 's' commands which not all seds can handle. GNU sed should be fine + # though. Also, the filter scales superlinearly with the number of + # global variables. join(1) would be nice here, but unfortunately + # isn't a blessed tool. + $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter + delfiles="$delfiles $export_symbols $output_objdir/$libname.filter" + export_symbols=$output_objdir/$libname.def + $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols + fi + + tmp_deplibs= + for test_deplib in $deplibs; do + case " $convenience " in + *" $test_deplib "*) ;; + *) + tmp_deplibs="$tmp_deplibs $test_deplib" + ;; + esac + done + deplibs="$tmp_deplibs" + + if test -n "$convenience"; then + if test -n "$whole_archive_flag_spec" && + test "$compiler_needs_object" = yes && + test -z "$libobjs"; then + # extract the archives, so we have objects to list. + # TODO: could optimize this to just extract one archive. + whole_archive_flag_spec= + fi + if test -n "$whole_archive_flag_spec"; then + save_libobjs=$libobjs + eval libobjs=\"\$libobjs $whole_archive_flag_spec\" + test "X$libobjs" = "X " && libobjs= + else + gentop="$output_objdir/${outputname}x" + generated="$generated $gentop" + + func_extract_archives $gentop $convenience + libobjs="$libobjs $func_extract_archives_result" + test "X$libobjs" = "X " && libobjs= + fi + fi + + if test "$thread_safe" = yes && test -n "$thread_safe_flag_spec"; then + eval flag=\"$thread_safe_flag_spec\" + linker_flags="$linker_flags $flag" + fi + + # Make a backup of the uninstalled library when relinking + if test "$mode" = relink; then + $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}U && $MV $realname ${realname}U)' || exit $? + fi + + # Do each of the archive commands. + if test "$module" = yes && test -n "$module_cmds" ; then + if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then + eval test_cmds=\"$module_expsym_cmds\" + cmds=$module_expsym_cmds + else + eval test_cmds=\"$module_cmds\" + cmds=$module_cmds + fi + else + if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then + eval test_cmds=\"$archive_expsym_cmds\" + cmds=$archive_expsym_cmds + else + eval test_cmds=\"$archive_cmds\" + cmds=$archive_cmds + fi + fi + + if test "X$skipped_export" != "X:" && + func_len " $test_cmds" && + len=$func_len_result && + test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then + : + else + # The command line is too long to link in one step, link piecewise + # or, if using GNU ld and skipped_export is not :, use a linker + # script. + + # Save the value of $output and $libobjs because we want to + # use them later. If we have whole_archive_flag_spec, we + # want to use save_libobjs as it was before + # whole_archive_flag_spec was expanded, because we can't + # assume the linker understands whole_archive_flag_spec. + # This may have to be revisited, in case too many + # convenience libraries get linked in and end up exceeding + # the spec. + if test -z "$convenience" || test -z "$whole_archive_flag_spec"; then + save_libobjs=$libobjs + fi + save_output=$output + output_la=`$ECHO "X$output" | $Xsed -e "$basename"` + + # Clear the reloadable object creation command queue and + # initialize k to one. + test_cmds= + concat_cmds= + objlist= + last_robj= + k=1 + + if test -n "$save_libobjs" && test "X$skipped_export" != "X:" && test "$with_gnu_ld" = yes; then + output=${output_objdir}/${output_la}.lnkscript + func_verbose "creating GNU ld script: $output" + $ECHO 'INPUT (' > $output + for obj in $save_libobjs + do + $ECHO "$obj" >> $output + done + $ECHO ')' >> $output + delfiles="$delfiles $output" + elif test -n "$save_libobjs" && test "X$skipped_export" != "X:" && test "X$file_list_spec" != X; then + output=${output_objdir}/${output_la}.lnk + func_verbose "creating linker input file list: $output" + : > $output + set x $save_libobjs + shift + firstobj= + if test "$compiler_needs_object" = yes; then + firstobj="$1 " + shift + fi + for obj + do + $ECHO "$obj" >> $output + done + delfiles="$delfiles $output" + output=$firstobj\"$file_list_spec$output\" + else + if test -n "$save_libobjs"; then + func_verbose "creating reloadable object files..." + output=$output_objdir/$output_la-${k}.$objext + eval test_cmds=\"$reload_cmds\" + func_len " $test_cmds" + len0=$func_len_result + len=$len0 + + # Loop over the list of objects to be linked. + for obj in $save_libobjs + do + func_len " $obj" + func_arith $len + $func_len_result + len=$func_arith_result + if test "X$objlist" = X || + test "$len" -lt "$max_cmd_len"; then + func_append objlist " $obj" + else + # The command $test_cmds is almost too long, add a + # command to the queue. + if test "$k" -eq 1 ; then + # The first file doesn't have a previous command to add. + eval concat_cmds=\"$reload_cmds $objlist $last_robj\" + else + # All subsequent reloadable object files will link in + # the last one created. + eval concat_cmds=\"\$concat_cmds~$reload_cmds $objlist $last_robj~\$RM $last_robj\" + fi + last_robj=$output_objdir/$output_la-${k}.$objext + func_arith $k + 1 + k=$func_arith_result + output=$output_objdir/$output_la-${k}.$objext + objlist=$obj + func_len " $last_robj" + func_arith $len0 + $func_len_result + len=$func_arith_result + fi + done + # Handle the remaining objects by creating one last + # reloadable object file. All subsequent reloadable object + # files will link in the last one created. + test -z "$concat_cmds" || concat_cmds=$concat_cmds~ + eval concat_cmds=\"\${concat_cmds}$reload_cmds $objlist $last_robj\" + if test -n "$last_robj"; then + eval concat_cmds=\"\${concat_cmds}~\$RM $last_robj\" + fi + delfiles="$delfiles $output" + + else + output= + fi + + if ${skipped_export-false}; then + func_verbose "generating symbol list for \`$libname.la'" + export_symbols="$output_objdir/$libname.exp" + $opt_dry_run || $RM $export_symbols + libobjs=$output + # Append the command to create the export file. + test -z "$concat_cmds" || concat_cmds=$concat_cmds~ + eval concat_cmds=\"\$concat_cmds$export_symbols_cmds\" + if test -n "$last_robj"; then + eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\" + fi + fi + + test -n "$save_libobjs" && + func_verbose "creating a temporary reloadable object file: $output" + + # Loop through the commands generated above and execute them. + save_ifs="$IFS"; IFS='~' + for cmd in $concat_cmds; do + IFS="$save_ifs" + $opt_silent || { + func_quote_for_expand "$cmd" + eval "func_echo $func_quote_for_expand_result" + } + $opt_dry_run || eval "$cmd" || { + lt_exit=$? + + # Restore the uninstalled library and exit + if test "$mode" = relink; then + ( cd "$output_objdir" && \ + $RM "${realname}T" && \ + $MV "${realname}U" "$realname" ) + fi + + exit $lt_exit + } + done + IFS="$save_ifs" + + if test -n "$export_symbols_regex" && ${skipped_export-false}; then + func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"' + func_show_eval '$MV "${export_symbols}T" "$export_symbols"' + fi + fi + + if ${skipped_export-false}; then + if test -n "$export_symbols" && test -n "$include_expsyms"; then + tmp_export_symbols="$export_symbols" + test -n "$orig_export_symbols" && tmp_export_symbols="$orig_export_symbols" + $opt_dry_run || eval '$ECHO "X$include_expsyms" | $Xsed | $SP2NL >> "$tmp_export_symbols"' + fi + + if test -n "$orig_export_symbols"; then + # The given exports_symbols file has to be filtered, so filter it. + func_verbose "filter symbol list for \`$libname.la' to tag DATA exports" + # FIXME: $output_objdir/$libname.filter potentially contains lots of + # 's' commands which not all seds can handle. GNU sed should be fine + # though. Also, the filter scales superlinearly with the number of + # global variables. join(1) would be nice here, but unfortunately + # isn't a blessed tool. + $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter + delfiles="$delfiles $export_symbols $output_objdir/$libname.filter" + export_symbols=$output_objdir/$libname.def + $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols + fi + fi + + libobjs=$output + # Restore the value of output. + output=$save_output + + if test -n "$convenience" && test -n "$whole_archive_flag_spec"; then + eval libobjs=\"\$libobjs $whole_archive_flag_spec\" + test "X$libobjs" = "X " && libobjs= + fi + # Expand the library linking commands again to reset the + # value of $libobjs for piecewise linking. + + # Do each of the archive commands. + if test "$module" = yes && test -n "$module_cmds" ; then + if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then + cmds=$module_expsym_cmds + else + cmds=$module_cmds + fi + else + if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then + cmds=$archive_expsym_cmds + else + cmds=$archive_cmds + fi + fi + fi + + if test -n "$delfiles"; then + # Append the command to remove temporary files to $cmds. + eval cmds=\"\$cmds~\$RM $delfiles\" + fi + + # Add any objects from preloaded convenience libraries + if test -n "$dlprefiles"; then + gentop="$output_objdir/${outputname}x" + generated="$generated $gentop" + + func_extract_archives $gentop $dlprefiles + libobjs="$libobjs $func_extract_archives_result" + test "X$libobjs" = "X " && libobjs= + fi + + save_ifs="$IFS"; IFS='~' + for cmd in $cmds; do + IFS="$save_ifs" + eval cmd=\"$cmd\" + $opt_silent || { + func_quote_for_expand "$cmd" + eval "func_echo $func_quote_for_expand_result" + } + $opt_dry_run || eval "$cmd" || { + lt_exit=$? + + # Restore the uninstalled library and exit + if test "$mode" = relink; then + ( cd "$output_objdir" && \ + $RM "${realname}T" && \ + $MV "${realname}U" "$realname" ) + fi + + exit $lt_exit + } + done + IFS="$save_ifs" + + # Restore the uninstalled library and exit + if test "$mode" = relink; then + $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}T && $MV $realname ${realname}T && $MV ${realname}U $realname)' || exit $? + + if test -n "$convenience"; then + if test -z "$whole_archive_flag_spec"; then + func_show_eval '${RM}r "$gentop"' + fi + fi + + exit $EXIT_SUCCESS + fi + + # Create links to the real library. + for linkname in $linknames; do + if test "$realname" != "$linkname"; then + func_show_eval '(cd "$output_objdir" && $RM "$linkname" && $LN_S "$realname" "$linkname")' 'exit $?' + fi + done + + # If -module or -export-dynamic was specified, set the dlname. + if test "$module" = yes || test "$export_dynamic" = yes; then + # On all known operating systems, these are identical. + dlname="$soname" + fi + fi + ;; + + obj) + if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then + func_warning "\`-dlopen' is ignored for objects" + fi + + case " $deplibs" in + *\ -l* | *\ -L*) + func_warning "\`-l' and \`-L' are ignored for objects" ;; + esac + + test -n "$rpath" && \ + func_warning "\`-rpath' is ignored for objects" + + test -n "$xrpath" && \ + func_warning "\`-R' is ignored for objects" + + test -n "$vinfo" && \ + func_warning "\`-version-info' is ignored for objects" + + test -n "$release" && \ + func_warning "\`-release' is ignored for objects" + + case $output in + *.lo) + test -n "$objs$old_deplibs" && \ + func_fatal_error "cannot build library object \`$output' from non-libtool objects" + + libobj=$output + func_lo2o "$libobj" + obj=$func_lo2o_result + ;; + *) + libobj= + obj="$output" + ;; + esac + + # Delete the old objects. + $opt_dry_run || $RM $obj $libobj + + # Objects from convenience libraries. This assumes + # single-version convenience libraries. Whenever we create + # different ones for PIC/non-PIC, this we'll have to duplicate + # the extraction. + reload_conv_objs= + gentop= + # reload_cmds runs $LD directly, so let us get rid of + # -Wl from whole_archive_flag_spec and hope we can get by with + # turning comma into space.. + wl= + + if test -n "$convenience"; then + if test -n "$whole_archive_flag_spec"; then + eval tmp_whole_archive_flags=\"$whole_archive_flag_spec\" + reload_conv_objs=$reload_objs\ `$ECHO "X$tmp_whole_archive_flags" | $Xsed -e 's|,| |g'` + else + gentop="$output_objdir/${obj}x" + generated="$generated $gentop" + + func_extract_archives $gentop $convenience + reload_conv_objs="$reload_objs $func_extract_archives_result" + fi + fi + + # Create the old-style object. + reload_objs="$objs$old_deplibs "`$ECHO "X$libobjs" | $SP2NL | $Xsed -e '/\.'${libext}$'/d' -e '/\.lib$/d' -e "$lo2o" | $NL2SP`" $reload_conv_objs" ### testsuite: skip nested quoting test + + output="$obj" + func_execute_cmds "$reload_cmds" 'exit $?' + + # Exit if we aren't doing a library object file. + if test -z "$libobj"; then + if test -n "$gentop"; then + func_show_eval '${RM}r "$gentop"' + fi + + exit $EXIT_SUCCESS + fi + + if test "$build_libtool_libs" != yes; then + if test -n "$gentop"; then + func_show_eval '${RM}r "$gentop"' + fi + + # Create an invalid libtool object if no PIC, so that we don't + # accidentally link it into a program. + # $show "echo timestamp > $libobj" + # $opt_dry_run || eval "echo timestamp > $libobj" || exit $? + exit $EXIT_SUCCESS + fi + + if test -n "$pic_flag" || test "$pic_mode" != default; then + # Only do commands if we really have different PIC objects. + reload_objs="$libobjs $reload_conv_objs" + output="$libobj" + func_execute_cmds "$reload_cmds" 'exit $?' + fi + + if test -n "$gentop"; then + func_show_eval '${RM}r "$gentop"' + fi + + exit $EXIT_SUCCESS + ;; + + prog) + case $host in + *cygwin*) func_stripname '' '.exe' "$output" + output=$func_stripname_result.exe;; + esac + test -n "$vinfo" && \ + func_warning "\`-version-info' is ignored for programs" + + test -n "$release" && \ + func_warning "\`-release' is ignored for programs" + + test "$preload" = yes \ + && test "$dlopen_support" = unknown \ + && test "$dlopen_self" = unknown \ + && test "$dlopen_self_static" = unknown && \ + func_warning "\`LT_INIT([dlopen])' not used. Assuming no dlopen support." + + case $host in + *-*-rhapsody* | *-*-darwin1.[012]) + # On Rhapsody replace the C library is the System framework + compile_deplibs=`$ECHO "X $compile_deplibs" | $Xsed -e 's/ -lc / System.ltframework /'` + finalize_deplibs=`$ECHO "X $finalize_deplibs" | $Xsed -e 's/ -lc / System.ltframework /'` + ;; + esac + + case $host in + *-*-darwin*) + # Don't allow lazy linking, it breaks C++ global constructors + # But is supposedly fixed on 10.4 or later (yay!). + if test "$tagname" = CXX ; then + case ${MACOSX_DEPLOYMENT_TARGET-10.0} in + 10.[0123]) + compile_command="$compile_command ${wl}-bind_at_load" + finalize_command="$finalize_command ${wl}-bind_at_load" + ;; + esac + fi + # Time to change all our "foo.ltframework" stuff back to "-framework foo" + compile_deplibs=`$ECHO "X $compile_deplibs" | $Xsed -e 's% \([^ $]*\).ltframework% -framework \1%g'` + finalize_deplibs=`$ECHO "X $finalize_deplibs" | $Xsed -e 's% \([^ $]*\).ltframework% -framework \1%g'` + ;; + esac + + + # move library search paths that coincide with paths to not yet + # installed libraries to the beginning of the library search list + new_libs= + for path in $notinst_path; do + case " $new_libs " in + *" -L$path/$objdir "*) ;; + *) + case " $compile_deplibs " in + *" -L$path/$objdir "*) + new_libs="$new_libs -L$path/$objdir" ;; + esac + ;; + esac + done + for deplib in $compile_deplibs; do + case $deplib in + -L*) + case " $new_libs " in + *" $deplib "*) ;; + *) new_libs="$new_libs $deplib" ;; + esac + ;; + *) new_libs="$new_libs $deplib" ;; + esac + done + compile_deplibs="$new_libs" + + + compile_command="$compile_command $compile_deplibs" + finalize_command="$finalize_command $finalize_deplibs" + + if test -n "$rpath$xrpath"; then + # If the user specified any rpath flags, then add them. + for libdir in $rpath $xrpath; do + # This is the magic to use -rpath. + case "$finalize_rpath " in + *" $libdir "*) ;; + *) finalize_rpath="$finalize_rpath $libdir" ;; + esac + done + fi + + # Now hardcode the library paths + rpath= + hardcode_libdirs= + for libdir in $compile_rpath $finalize_rpath; do + if test -n "$hardcode_libdir_flag_spec"; then + if test -n "$hardcode_libdir_separator"; then + if test -z "$hardcode_libdirs"; then + hardcode_libdirs="$libdir" + else + # Just accumulate the unique libdirs. + case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in + *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*) + ;; + *) + hardcode_libdirs="$hardcode_libdirs$hardcode_libdir_separator$libdir" + ;; + esac + fi + else + eval flag=\"$hardcode_libdir_flag_spec\" + rpath="$rpath $flag" + fi + elif test -n "$runpath_var"; then + case "$perm_rpath " in + *" $libdir "*) ;; + *) perm_rpath="$perm_rpath $libdir" ;; + esac + fi + case $host in + *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*) + testbindir=`${ECHO} "$libdir" | ${SED} -e 's*/lib$*/bin*'` + case :$dllsearchpath: in + *":$libdir:"*) ;; + ::) dllsearchpath=$libdir;; + *) dllsearchpath="$dllsearchpath:$libdir";; + esac + case :$dllsearchpath: in + *":$testbindir:"*) ;; + ::) dllsearchpath=$testbindir;; + *) dllsearchpath="$dllsearchpath:$testbindir";; + esac + ;; + esac + done + # Substitute the hardcoded libdirs into the rpath. + if test -n "$hardcode_libdir_separator" && + test -n "$hardcode_libdirs"; then + libdir="$hardcode_libdirs" + eval rpath=\" $hardcode_libdir_flag_spec\" + fi + compile_rpath="$rpath" + + rpath= + hardcode_libdirs= + for libdir in $finalize_rpath; do + if test -n "$hardcode_libdir_flag_spec"; then + if test -n "$hardcode_libdir_separator"; then + if test -z "$hardcode_libdirs"; then + hardcode_libdirs="$libdir" + else + # Just accumulate the unique libdirs. + case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in + *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*) + ;; + *) + hardcode_libdirs="$hardcode_libdirs$hardcode_libdir_separator$libdir" + ;; + esac + fi + else + eval flag=\"$hardcode_libdir_flag_spec\" + rpath="$rpath $flag" + fi + elif test -n "$runpath_var"; then + case "$finalize_perm_rpath " in + *" $libdir "*) ;; + *) finalize_perm_rpath="$finalize_perm_rpath $libdir" ;; + esac + fi + done + # Substitute the hardcoded libdirs into the rpath. + if test -n "$hardcode_libdir_separator" && + test -n "$hardcode_libdirs"; then + libdir="$hardcode_libdirs" + eval rpath=\" $hardcode_libdir_flag_spec\" + fi + finalize_rpath="$rpath" + + if test -n "$libobjs" && test "$build_old_libs" = yes; then + # Transform all the library objects into standard objects. + compile_command=`$ECHO "X$compile_command" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP` + finalize_command=`$ECHO "X$finalize_command" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP` + fi + + func_generate_dlsyms "$outputname" "@PROGRAM@" "no" + + # template prelinking step + if test -n "$prelink_cmds"; then + func_execute_cmds "$prelink_cmds" 'exit $?' + fi + + wrappers_required=yes + case $host in + *cygwin* | *mingw* ) + if test "$build_libtool_libs" != yes; then + wrappers_required=no + fi + ;; + *cegcc) + # Disable wrappers for cegcc, we are cross compiling anyway. + wrappers_required=no + ;; + *) + if test "$need_relink" = no || test "$build_libtool_libs" != yes; then + wrappers_required=no + fi + ;; + esac + if test "$wrappers_required" = no; then + # Replace the output file specification. + compile_command=`$ECHO "X$compile_command" | $Xsed -e 's%@OUTPUT@%'"$output"'%g'` + link_command="$compile_command$compile_rpath" + + # We have no uninstalled library dependencies, so finalize right now. + exit_status=0 + func_show_eval "$link_command" 'exit_status=$?' + + # Delete the generated files. + if test -f "$output_objdir/${outputname}S.${objext}"; then + func_show_eval '$RM "$output_objdir/${outputname}S.${objext}"' + fi + + exit $exit_status + fi + + if test -n "$compile_shlibpath$finalize_shlibpath"; then + compile_command="$shlibpath_var=\"$compile_shlibpath$finalize_shlibpath\$$shlibpath_var\" $compile_command" + fi + if test -n "$finalize_shlibpath"; then + finalize_command="$shlibpath_var=\"$finalize_shlibpath\$$shlibpath_var\" $finalize_command" + fi + + compile_var= + finalize_var= + if test -n "$runpath_var"; then + if test -n "$perm_rpath"; then + # We should set the runpath_var. + rpath= + for dir in $perm_rpath; do + rpath="$rpath$dir:" + done + compile_var="$runpath_var=\"$rpath\$$runpath_var\" " + fi + if test -n "$finalize_perm_rpath"; then + # We should set the runpath_var. + rpath= + for dir in $finalize_perm_rpath; do + rpath="$rpath$dir:" + done + finalize_var="$runpath_var=\"$rpath\$$runpath_var\" " + fi + fi + + if test "$no_install" = yes; then + # We don't need to create a wrapper script. + link_command="$compile_var$compile_command$compile_rpath" + # Replace the output file specification. + link_command=`$ECHO "X$link_command" | $Xsed -e 's%@OUTPUT@%'"$output"'%g'` + # Delete the old output file. + $opt_dry_run || $RM $output + # Link the executable and exit + func_show_eval "$link_command" 'exit $?' + exit $EXIT_SUCCESS + fi + + if test "$hardcode_action" = relink; then + # Fast installation is not supported + link_command="$compile_var$compile_command$compile_rpath" + relink_command="$finalize_var$finalize_command$finalize_rpath" + + func_warning "this platform does not like uninstalled shared libraries" + func_warning "\`$output' will be relinked during installation" + else + if test "$fast_install" != no; then + link_command="$finalize_var$compile_command$finalize_rpath" + if test "$fast_install" = yes; then + relink_command=`$ECHO "X$compile_var$compile_command$compile_rpath" | $Xsed -e 's%@OUTPUT@%\$progdir/\$file%g'` + else + # fast_install is set to needless + relink_command= + fi + else + link_command="$compile_var$compile_command$compile_rpath" + relink_command="$finalize_var$finalize_command$finalize_rpath" + fi + fi + + # Replace the output file specification. + link_command=`$ECHO "X$link_command" | $Xsed -e 's%@OUTPUT@%'"$output_objdir/$outputname"'%g'` + + # Delete the old output files. + $opt_dry_run || $RM $output $output_objdir/$outputname $output_objdir/lt-$outputname + + func_show_eval "$link_command" 'exit $?' + + # Now create the wrapper script. + func_verbose "creating $output" + + # Quote the relink command for shipping. + if test -n "$relink_command"; then + # Preserve any variables that may affect compiler behavior + for var in $variables_saved_for_relink; do + if eval test -z \"\${$var+set}\"; then + relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command" + elif eval var_value=\$$var; test -z "$var_value"; then + relink_command="$var=; export $var; $relink_command" + else + func_quote_for_eval "$var_value" + relink_command="$var=$func_quote_for_eval_result; export $var; $relink_command" + fi + done + relink_command="(cd `pwd`; $relink_command)" + relink_command=`$ECHO "X$relink_command" | $Xsed -e "$sed_quote_subst"` + fi + + # Quote $ECHO for shipping. + if test "X$ECHO" = "X$SHELL $progpath --fallback-echo"; then + case $progpath in + [\\/]* | [A-Za-z]:[\\/]*) qecho="$SHELL $progpath --fallback-echo";; + *) qecho="$SHELL `pwd`/$progpath --fallback-echo";; + esac + qecho=`$ECHO "X$qecho" | $Xsed -e "$sed_quote_subst"` + else + qecho=`$ECHO "X$ECHO" | $Xsed -e "$sed_quote_subst"` + fi + + # Only actually do things if not in dry run mode. + $opt_dry_run || { + # win32 will think the script is a binary if it has + # a .exe suffix, so we strip it off here. + case $output in + *.exe) func_stripname '' '.exe' "$output" + output=$func_stripname_result ;; + esac + # test for cygwin because mv fails w/o .exe extensions + case $host in + *cygwin*) + exeext=.exe + func_stripname '' '.exe' "$outputname" + outputname=$func_stripname_result ;; + *) exeext= ;; + esac + case $host in + *cygwin* | *mingw* ) + func_dirname_and_basename "$output" "" "." + output_name=$func_basename_result + output_path=$func_dirname_result + cwrappersource="$output_path/$objdir/lt-$output_name.c" + cwrapper="$output_path/$output_name.exe" + $RM $cwrappersource $cwrapper + trap "$RM $cwrappersource $cwrapper; exit $EXIT_FAILURE" 1 2 15 + + func_emit_cwrapperexe_src > $cwrappersource + + # The wrapper executable is built using the $host compiler, + # because it contains $host paths and files. If cross- + # compiling, it, like the target executable, must be + # executed on the $host or under an emulation environment. + $opt_dry_run || { + $LTCC $LTCFLAGS -o $cwrapper $cwrappersource + $STRIP $cwrapper + } + + # Now, create the wrapper script for func_source use: + func_ltwrapper_scriptname $cwrapper + $RM $func_ltwrapper_scriptname_result + trap "$RM $func_ltwrapper_scriptname_result; exit $EXIT_FAILURE" 1 2 15 + $opt_dry_run || { + # note: this script will not be executed, so do not chmod. + if test "x$build" = "x$host" ; then + $cwrapper --lt-dump-script > $func_ltwrapper_scriptname_result + else + func_emit_wrapper no > $func_ltwrapper_scriptname_result + fi + } + ;; + * ) + $RM $output + trap "$RM $output; exit $EXIT_FAILURE" 1 2 15 + + func_emit_wrapper no > $output + chmod +x $output + ;; + esac + } + exit $EXIT_SUCCESS + ;; + esac + + # See if we need to build an old-fashioned archive. + for oldlib in $oldlibs; do + + if test "$build_libtool_libs" = convenience; then + oldobjs="$libobjs_save $symfileobj" + addlibs="$convenience" + build_libtool_libs=no + else + if test "$build_libtool_libs" = module; then + oldobjs="$libobjs_save" + build_libtool_libs=no + else + oldobjs="$old_deplibs $non_pic_objects" + if test "$preload" = yes && test -f "$symfileobj"; then + oldobjs="$oldobjs $symfileobj" + fi + fi + addlibs="$old_convenience" + fi + + if test -n "$addlibs"; then + gentop="$output_objdir/${outputname}x" + generated="$generated $gentop" + + func_extract_archives $gentop $addlibs + oldobjs="$oldobjs $func_extract_archives_result" + fi + + # Do each command in the archive commands. + if test -n "$old_archive_from_new_cmds" && test "$build_libtool_libs" = yes; then + cmds=$old_archive_from_new_cmds + else + + # Add any objects from preloaded convenience libraries + if test -n "$dlprefiles"; then + gentop="$output_objdir/${outputname}x" + generated="$generated $gentop" + + func_extract_archives $gentop $dlprefiles + oldobjs="$oldobjs $func_extract_archives_result" + fi + + # POSIX demands no paths to be encoded in archives. We have + # to avoid creating archives with duplicate basenames if we + # might have to extract them afterwards, e.g., when creating a + # static archive out of a convenience library, or when linking + # the entirety of a libtool archive into another (currently + # not supported by libtool). + if (for obj in $oldobjs + do + func_basename "$obj" + $ECHO "$func_basename_result" + done | sort | sort -uc >/dev/null 2>&1); then + : + else + $ECHO "copying selected object files to avoid basename conflicts..." + gentop="$output_objdir/${outputname}x" + generated="$generated $gentop" + func_mkdir_p "$gentop" + save_oldobjs=$oldobjs + oldobjs= + counter=1 + for obj in $save_oldobjs + do + func_basename "$obj" + objbase="$func_basename_result" + case " $oldobjs " in + " ") oldobjs=$obj ;; + *[\ /]"$objbase "*) + while :; do + # Make sure we don't pick an alternate name that also + # overlaps. + newobj=lt$counter-$objbase + func_arith $counter + 1 + counter=$func_arith_result + case " $oldobjs " in + *[\ /]"$newobj "*) ;; + *) if test ! -f "$gentop/$newobj"; then break; fi ;; + esac + done + func_show_eval "ln $obj $gentop/$newobj || cp $obj $gentop/$newobj" + oldobjs="$oldobjs $gentop/$newobj" + ;; + *) oldobjs="$oldobjs $obj" ;; + esac + done + fi + eval cmds=\"$old_archive_cmds\" + + func_len " $cmds" + len=$func_len_result + if test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then + cmds=$old_archive_cmds + else + # the command line is too long to link in one step, link in parts + func_verbose "using piecewise archive linking..." + save_RANLIB=$RANLIB + RANLIB=: + objlist= + concat_cmds= + save_oldobjs=$oldobjs + oldobjs= + # Is there a better way of finding the last object in the list? + for obj in $save_oldobjs + do + last_oldobj=$obj + done + eval test_cmds=\"$old_archive_cmds\" + func_len " $test_cmds" + len0=$func_len_result + len=$len0 + for obj in $save_oldobjs + do + func_len " $obj" + func_arith $len + $func_len_result + len=$func_arith_result + func_append objlist " $obj" + if test "$len" -lt "$max_cmd_len"; then + : + else + # the above command should be used before it gets too long + oldobjs=$objlist + if test "$obj" = "$last_oldobj" ; then + RANLIB=$save_RANLIB + fi + test -z "$concat_cmds" || concat_cmds=$concat_cmds~ + eval concat_cmds=\"\${concat_cmds}$old_archive_cmds\" + objlist= + len=$len0 + fi + done + RANLIB=$save_RANLIB + oldobjs=$objlist + if test "X$oldobjs" = "X" ; then + eval cmds=\"\$concat_cmds\" + else + eval cmds=\"\$concat_cmds~\$old_archive_cmds\" + fi + fi + fi + func_execute_cmds "$cmds" 'exit $?' + done + + test -n "$generated" && \ + func_show_eval "${RM}r$generated" + + # Now create the libtool archive. + case $output in + *.la) + old_library= + test "$build_old_libs" = yes && old_library="$libname.$libext" + func_verbose "creating $output" + + # Preserve any variables that may affect compiler behavior + for var in $variables_saved_for_relink; do + if eval test -z \"\${$var+set}\"; then + relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command" + elif eval var_value=\$$var; test -z "$var_value"; then + relink_command="$var=; export $var; $relink_command" + else + func_quote_for_eval "$var_value" + relink_command="$var=$func_quote_for_eval_result; export $var; $relink_command" + fi + done + # Quote the link command for shipping. + relink_command="(cd `pwd`; $SHELL $progpath $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)" + relink_command=`$ECHO "X$relink_command" | $Xsed -e "$sed_quote_subst"` + if test "$hardcode_automatic" = yes ; then + relink_command= + fi + + # Only create the output if not a dry run. + $opt_dry_run || { + for installed in no yes; do + if test "$installed" = yes; then + if test -z "$install_libdir"; then + break + fi + output="$output_objdir/$outputname"i + # Replace all uninstalled libtool libraries with the installed ones + newdependency_libs= + for deplib in $dependency_libs; do + case $deplib in + *.la) + func_basename "$deplib" + name="$func_basename_result" + eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $deplib` + test -z "$libdir" && \ + func_fatal_error "\`$deplib' is not a valid libtool archive" + newdependency_libs="$newdependency_libs $libdir/$name" + ;; + *) newdependency_libs="$newdependency_libs $deplib" ;; + esac + done + dependency_libs="$newdependency_libs" + newdlfiles= + + for lib in $dlfiles; do + case $lib in + *.la) + func_basename "$lib" + name="$func_basename_result" + eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $lib` + test -z "$libdir" && \ + func_fatal_error "\`$lib' is not a valid libtool archive" + newdlfiles="$newdlfiles $libdir/$name" + ;; + *) newdlfiles="$newdlfiles $lib" ;; + esac + done + dlfiles="$newdlfiles" + newdlprefiles= + for lib in $dlprefiles; do + case $lib in + *.la) + # Only pass preopened files to the pseudo-archive (for + # eventual linking with the app. that links it) if we + # didn't already link the preopened objects directly into + # the library: + func_basename "$lib" + name="$func_basename_result" + eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $lib` + test -z "$libdir" && \ + func_fatal_error "\`$lib' is not a valid libtool archive" + newdlprefiles="$newdlprefiles $libdir/$name" + ;; + esac + done + dlprefiles="$newdlprefiles" + else + newdlfiles= + for lib in $dlfiles; do + case $lib in + [\\/]* | [A-Za-z]:[\\/]*) abs="$lib" ;; + *) abs=`pwd`"/$lib" ;; + esac + newdlfiles="$newdlfiles $abs" + done + dlfiles="$newdlfiles" + newdlprefiles= + for lib in $dlprefiles; do + case $lib in + [\\/]* | [A-Za-z]:[\\/]*) abs="$lib" ;; + *) abs=`pwd`"/$lib" ;; + esac + newdlprefiles="$newdlprefiles $abs" + done + dlprefiles="$newdlprefiles" + fi + $RM $output + # place dlname in correct position for cygwin + tdlname=$dlname + case $host,$output,$installed,$module,$dlname in + *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll | *cegcc*,*lai,yes,no,*.dll) tdlname=../bin/$dlname ;; + esac + $ECHO > $output "\ +# $outputname - a libtool library file +# Generated by $PROGRAM (GNU $PACKAGE$TIMESTAMP) $VERSION +# +# Please DO NOT delete this file! +# It is necessary for linking the library. + +# The name that we can dlopen(3). +dlname='$tdlname' + +# Names of this library. +library_names='$library_names' + +# The name of the static archive. +old_library='$old_library' + +# Linker flags that can not go in dependency_libs. +inherited_linker_flags='$new_inherited_linker_flags' + +# Libraries that this one depends upon. +dependency_libs='$dependency_libs' + +# Names of additional weak libraries provided by this library +weak_library_names='$weak_libs' + +# Version information for $libname. +current=$current +age=$age +revision=$revision + +# Is this an already installed library? +installed=$installed + +# Should we warn about portability when linking against -modules? +shouldnotlink=$module + +# Files to dlopen/dlpreopen +dlopen='$dlfiles' +dlpreopen='$dlprefiles' + +# Directory that this library needs to be installed in: +libdir='$install_libdir'" + if test "$installed" = no && test "$need_relink" = yes; then + $ECHO >> $output "\ +relink_command=\"$relink_command\"" + fi + done + } + + # Do a symbolic link so that the libtool archive can be found in + # LD_LIBRARY_PATH before the program is installed. + func_show_eval '( cd "$output_objdir" && $RM "$outputname" && $LN_S "../$outputname" "$outputname" )' 'exit $?' + ;; + esac + exit $EXIT_SUCCESS +} + +{ test "$mode" = link || test "$mode" = relink; } && + func_mode_link ${1+"$@"} + + +# func_mode_uninstall arg... +func_mode_uninstall () +{ + $opt_debug + RM="$nonopt" + files= + rmforce= + exit_status=0 + + # This variable tells wrapper scripts just to set variables rather + # than running their programs. + libtool_install_magic="$magic" + + for arg + do + case $arg in + -f) RM="$RM $arg"; rmforce=yes ;; + -*) RM="$RM $arg" ;; + *) files="$files $arg" ;; + esac + done + + test -z "$RM" && \ + func_fatal_help "you must specify an RM program" + + rmdirs= + + origobjdir="$objdir" + for file in $files; do + func_dirname "$file" "" "." + dir="$func_dirname_result" + if test "X$dir" = X.; then + objdir="$origobjdir" + else + objdir="$dir/$origobjdir" + fi + func_basename "$file" + name="$func_basename_result" + test "$mode" = uninstall && objdir="$dir" + + # Remember objdir for removal later, being careful to avoid duplicates + if test "$mode" = clean; then + case " $rmdirs " in + *" $objdir "*) ;; + *) rmdirs="$rmdirs $objdir" ;; + esac + fi + + # Don't error if the file doesn't exist and rm -f was used. + if { test -L "$file"; } >/dev/null 2>&1 || + { test -h "$file"; } >/dev/null 2>&1 || + test -f "$file"; then + : + elif test -d "$file"; then + exit_status=1 + continue + elif test "$rmforce" = yes; then + continue + fi + + rmfiles="$file" + + case $name in + *.la) + # Possibly a libtool archive, so verify it. + if func_lalib_p "$file"; then + func_source $dir/$name + + # Delete the libtool libraries and symlinks. + for n in $library_names; do + rmfiles="$rmfiles $objdir/$n" + done + test -n "$old_library" && rmfiles="$rmfiles $objdir/$old_library" + + case "$mode" in + clean) + case " $library_names " in + # " " in the beginning catches empty $dlname + *" $dlname "*) ;; + *) rmfiles="$rmfiles $objdir/$dlname" ;; + esac + test -n "$libdir" && rmfiles="$rmfiles $objdir/$name $objdir/${name}i" + ;; + uninstall) + if test -n "$library_names"; then + # Do each command in the postuninstall commands. + func_execute_cmds "$postuninstall_cmds" 'test "$rmforce" = yes || exit_status=1' + fi + + if test -n "$old_library"; then + # Do each command in the old_postuninstall commands. + func_execute_cmds "$old_postuninstall_cmds" 'test "$rmforce" = yes || exit_status=1' + fi + # FIXME: should reinstall the best remaining shared library. + ;; + esac + fi + ;; + + *.lo) + # Possibly a libtool object, so verify it. + if func_lalib_p "$file"; then + + # Read the .lo file + func_source $dir/$name + + # Add PIC object to the list of files to remove. + if test -n "$pic_object" && + test "$pic_object" != none; then + rmfiles="$rmfiles $dir/$pic_object" + fi + + # Add non-PIC object to the list of files to remove. + if test -n "$non_pic_object" && + test "$non_pic_object" != none; then + rmfiles="$rmfiles $dir/$non_pic_object" + fi + fi + ;; + + *) + if test "$mode" = clean ; then + noexename=$name + case $file in + *.exe) + func_stripname '' '.exe' "$file" + file=$func_stripname_result + func_stripname '' '.exe' "$name" + noexename=$func_stripname_result + # $file with .exe has already been added to rmfiles, + # add $file without .exe + rmfiles="$rmfiles $file" + ;; + esac + # Do a test to see if this is a libtool program. + if func_ltwrapper_p "$file"; then + if func_ltwrapper_executable_p "$file"; then + func_ltwrapper_scriptname "$file" + relink_command= + func_source $func_ltwrapper_scriptname_result + rmfiles="$rmfiles $func_ltwrapper_scriptname_result" + else + relink_command= + func_source $dir/$noexename + fi + + # note $name still contains .exe if it was in $file originally + # as does the version of $file that was added into $rmfiles + rmfiles="$rmfiles $objdir/$name $objdir/${name}S.${objext}" + if test "$fast_install" = yes && test -n "$relink_command"; then + rmfiles="$rmfiles $objdir/lt-$name" + fi + if test "X$noexename" != "X$name" ; then + rmfiles="$rmfiles $objdir/lt-${noexename}.c" + fi + fi + fi + ;; + esac + func_show_eval "$RM $rmfiles" 'exit_status=1' + done + objdir="$origobjdir" + + # Try to remove the ${objdir}s in the directories where we deleted files + for dir in $rmdirs; do + if test -d "$dir"; then + func_show_eval "rmdir $dir >/dev/null 2>&1" + fi + done + + exit $exit_status +} + +{ test "$mode" = uninstall || test "$mode" = clean; } && + func_mode_uninstall ${1+"$@"} + +test -z "$mode" && { + help="$generic_help" + func_fatal_help "you must specify a MODE" +} + +test -z "$exec_cmd" && \ + func_fatal_help "invalid operation mode \`$mode'" + +if test -n "$exec_cmd"; then + eval exec "$exec_cmd" + exit $EXIT_FAILURE +fi + +exit $exit_status + + +# The TAGs below are defined such that we never get into a situation +# in which we disable both kinds of libraries. Given conflicting +# choices, we go for a static library, that is the most portable, +# since we can't tell whether shared libraries were disabled because +# the user asked for that or because the platform doesn't support +# them. This is particularly important on AIX, because we don't +# support having both static and shared libraries enabled at the same +# time on that platform, so we default to a shared-only configuration. +# If a disable-shared tag is given, we'll fallback to a static-only +# configuration. But we'll never go from static-only to shared-only. + +# ### BEGIN LIBTOOL TAG CONFIG: disable-shared +build_libtool_libs=no +build_old_libs=yes +# ### END LIBTOOL TAG CONFIG: disable-shared + +# ### BEGIN LIBTOOL TAG CONFIG: disable-static +build_old_libs=`case $build_libtool_libs in yes) echo no;; *) echo yes;; esac` +# ### END LIBTOOL TAG CONFIG: disable-static + +# Local Variables: +# mode:shell-script +# sh-indentation:2 +# End: +# vi:sw=2 + diff --git a/libs/libpng-src/missing b/libs/libpng-src/missing new file mode 100755 index 000000000..28055d2ae --- /dev/null +++ b/libs/libpng-src/missing @@ -0,0 +1,376 @@ +#! /bin/sh +# Common stub for a few missing GNU programs while installing. + +scriptversion=2009-04-28.21; # UTC + +# Copyright (C) 1996, 1997, 1999, 2000, 2002, 2003, 2004, 2005, 2006, +# 2008, 2009 Free Software Foundation, Inc. +# Originally by Fran,cois Pinard , 1996. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + +if test $# -eq 0; then + echo 1>&2 "Try \`$0 --help' for more information" + exit 1 +fi + +run=: +sed_output='s/.* --output[ =]\([^ ]*\).*/\1/p' +sed_minuso='s/.* -o \([^ ]*\).*/\1/p' + +# In the cases where this matters, `missing' is being run in the +# srcdir already. +if test -f configure.ac; then + configure_ac=configure.ac +else + configure_ac=configure.in +fi + +msg="missing on your system" + +case $1 in +--run) + # Try to run requested program, and just exit if it succeeds. + run= + shift + "$@" && exit 0 + # Exit code 63 means version mismatch. This often happens + # when the user try to use an ancient version of a tool on + # a file that requires a minimum version. In this case we + # we should proceed has if the program had been absent, or + # if --run hadn't been passed. + if test $? = 63; then + run=: + msg="probably too old" + fi + ;; + + -h|--h|--he|--hel|--help) + echo "\ +$0 [OPTION]... PROGRAM [ARGUMENT]... + +Handle \`PROGRAM [ARGUMENT]...' for when PROGRAM is missing, or return an +error status if there is no known handling for PROGRAM. + +Options: + -h, --help display this help and exit + -v, --version output version information and exit + --run try to run the given command, and emulate it if it fails + +Supported PROGRAM values: + aclocal touch file \`aclocal.m4' + autoconf touch file \`configure' + autoheader touch file \`config.h.in' + autom4te touch the output file, or create a stub one + automake touch all \`Makefile.in' files + bison create \`y.tab.[ch]', if possible, from existing .[ch] + flex create \`lex.yy.c', if possible, from existing .c + help2man touch the output file + lex create \`lex.yy.c', if possible, from existing .c + makeinfo touch the output file + tar try tar, gnutar, gtar, then tar without non-portable flags + yacc create \`y.tab.[ch]', if possible, from existing .[ch] + +Version suffixes to PROGRAM as well as the prefixes \`gnu-', \`gnu', and +\`g' are ignored when checking the name. + +Send bug reports to ." + exit $? + ;; + + -v|--v|--ve|--ver|--vers|--versi|--versio|--version) + echo "missing $scriptversion (GNU Automake)" + exit $? + ;; + + -*) + echo 1>&2 "$0: Unknown \`$1' option" + echo 1>&2 "Try \`$0 --help' for more information" + exit 1 + ;; + +esac + +# normalize program name to check for. +program=`echo "$1" | sed ' + s/^gnu-//; t + s/^gnu//; t + s/^g//; t'` + +# Now exit if we have it, but it failed. Also exit now if we +# don't have it and --version was passed (most likely to detect +# the program). This is about non-GNU programs, so use $1 not +# $program. +case $1 in + lex*|yacc*) + # Not GNU programs, they don't have --version. + ;; + + tar*) + if test -n "$run"; then + echo 1>&2 "ERROR: \`tar' requires --run" + exit 1 + elif test "x$2" = "x--version" || test "x$2" = "x--help"; then + exit 1 + fi + ;; + + *) + if test -z "$run" && ($1 --version) > /dev/null 2>&1; then + # We have it, but it failed. + exit 1 + elif test "x$2" = "x--version" || test "x$2" = "x--help"; then + # Could not run --version or --help. This is probably someone + # running `$TOOL --version' or `$TOOL --help' to check whether + # $TOOL exists and not knowing $TOOL uses missing. + exit 1 + fi + ;; +esac + +# If it does not exist, or fails to run (possibly an outdated version), +# try to emulate it. +case $program in + aclocal*) + echo 1>&2 "\ +WARNING: \`$1' is $msg. You should only need it if + you modified \`acinclude.m4' or \`${configure_ac}'. You might want + to install the \`Automake' and \`Perl' packages. Grab them from + any GNU archive site." + touch aclocal.m4 + ;; + + autoconf*) + echo 1>&2 "\ +WARNING: \`$1' is $msg. You should only need it if + you modified \`${configure_ac}'. You might want to install the + \`Autoconf' and \`GNU m4' packages. Grab them from any GNU + archive site." + touch configure + ;; + + autoheader*) + echo 1>&2 "\ +WARNING: \`$1' is $msg. You should only need it if + you modified \`acconfig.h' or \`${configure_ac}'. You might want + to install the \`Autoconf' and \`GNU m4' packages. Grab them + from any GNU archive site." + files=`sed -n 's/^[ ]*A[CM]_CONFIG_HEADER(\([^)]*\)).*/\1/p' ${configure_ac}` + test -z "$files" && files="config.h" + touch_files= + for f in $files; do + case $f in + *:*) touch_files="$touch_files "`echo "$f" | + sed -e 's/^[^:]*://' -e 's/:.*//'`;; + *) touch_files="$touch_files $f.in";; + esac + done + touch $touch_files + ;; + + automake*) + echo 1>&2 "\ +WARNING: \`$1' is $msg. You should only need it if + you modified \`Makefile.am', \`acinclude.m4' or \`${configure_ac}'. + You might want to install the \`Automake' and \`Perl' packages. + Grab them from any GNU archive site." + find . -type f -name Makefile.am -print | + sed 's/\.am$/.in/' | + while read f; do touch "$f"; done + ;; + + autom4te*) + echo 1>&2 "\ +WARNING: \`$1' is needed, but is $msg. + You might have modified some files without having the + proper tools for further handling them. + You can get \`$1' as part of \`Autoconf' from any GNU + archive site." + + file=`echo "$*" | sed -n "$sed_output"` + test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"` + if test -f "$file"; then + touch $file + else + test -z "$file" || exec >$file + echo "#! /bin/sh" + echo "# Created by GNU Automake missing as a replacement of" + echo "# $ $@" + echo "exit 0" + chmod +x $file + exit 1 + fi + ;; + + bison*|yacc*) + echo 1>&2 "\ +WARNING: \`$1' $msg. You should only need it if + you modified a \`.y' file. You may need the \`Bison' package + in order for those modifications to take effect. You can get + \`Bison' from any GNU archive site." + rm -f y.tab.c y.tab.h + if test $# -ne 1; then + eval LASTARG="\${$#}" + case $LASTARG in + *.y) + SRCFILE=`echo "$LASTARG" | sed 's/y$/c/'` + if test -f "$SRCFILE"; then + cp "$SRCFILE" y.tab.c + fi + SRCFILE=`echo "$LASTARG" | sed 's/y$/h/'` + if test -f "$SRCFILE"; then + cp "$SRCFILE" y.tab.h + fi + ;; + esac + fi + if test ! -f y.tab.h; then + echo >y.tab.h + fi + if test ! -f y.tab.c; then + echo 'main() { return 0; }' >y.tab.c + fi + ;; + + lex*|flex*) + echo 1>&2 "\ +WARNING: \`$1' is $msg. You should only need it if + you modified a \`.l' file. You may need the \`Flex' package + in order for those modifications to take effect. You can get + \`Flex' from any GNU archive site." + rm -f lex.yy.c + if test $# -ne 1; then + eval LASTARG="\${$#}" + case $LASTARG in + *.l) + SRCFILE=`echo "$LASTARG" | sed 's/l$/c/'` + if test -f "$SRCFILE"; then + cp "$SRCFILE" lex.yy.c + fi + ;; + esac + fi + if test ! -f lex.yy.c; then + echo 'main() { return 0; }' >lex.yy.c + fi + ;; + + help2man*) + echo 1>&2 "\ +WARNING: \`$1' is $msg. You should only need it if + you modified a dependency of a manual page. You may need the + \`Help2man' package in order for those modifications to take + effect. You can get \`Help2man' from any GNU archive site." + + file=`echo "$*" | sed -n "$sed_output"` + test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"` + if test -f "$file"; then + touch $file + else + test -z "$file" || exec >$file + echo ".ab help2man is required to generate this page" + exit $? + fi + ;; + + makeinfo*) + echo 1>&2 "\ +WARNING: \`$1' is $msg. You should only need it if + you modified a \`.texi' or \`.texinfo' file, or any other file + indirectly affecting the aspect of the manual. The spurious + call might also be the consequence of using a buggy \`make' (AIX, + DU, IRIX). You might want to install the \`Texinfo' package or + the \`GNU make' package. Grab either from any GNU archive site." + # The file to touch is that specified with -o ... + file=`echo "$*" | sed -n "$sed_output"` + test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"` + if test -z "$file"; then + # ... or it is the one specified with @setfilename ... + infile=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'` + file=`sed -n ' + /^@setfilename/{ + s/.* \([^ ]*\) *$/\1/ + p + q + }' $infile` + # ... or it is derived from the source name (dir/f.texi becomes f.info) + test -z "$file" && file=`echo "$infile" | sed 's,.*/,,;s,.[^.]*$,,'`.info + fi + # If the file does not exist, the user really needs makeinfo; + # let's fail without touching anything. + test -f $file || exit 1 + touch $file + ;; + + tar*) + shift + + # We have already tried tar in the generic part. + # Look for gnutar/gtar before invocation to avoid ugly error + # messages. + if (gnutar --version > /dev/null 2>&1); then + gnutar "$@" && exit 0 + fi + if (gtar --version > /dev/null 2>&1); then + gtar "$@" && exit 0 + fi + firstarg="$1" + if shift; then + case $firstarg in + *o*) + firstarg=`echo "$firstarg" | sed s/o//` + tar "$firstarg" "$@" && exit 0 + ;; + esac + case $firstarg in + *h*) + firstarg=`echo "$firstarg" | sed s/h//` + tar "$firstarg" "$@" && exit 0 + ;; + esac + fi + + echo 1>&2 "\ +WARNING: I can't seem to be able to run \`tar' with the given arguments. + You may want to install GNU tar or Free paxutils, or check the + command line arguments." + exit 1 + ;; + + *) + echo 1>&2 "\ +WARNING: \`$1' is needed, and is $msg. + You might have modified some files without having the + proper tools for further handling them. Check the \`README' file, + it often tells you about the needed prerequisites for installing + this package. You may also peek at any GNU archive site, in case + some other package would contain this missing \`$1' program." + exit 1 + ;; +esac + +exit 0 + +# Local variables: +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "scriptversion=" +# time-stamp-format: "%:y-%02m-%02d.%02H" +# time-stamp-time-zone: "UTC" +# time-stamp-end: "; # UTC" +# End: diff --git a/libs/libpng-src/mkinstalldirs b/libs/libpng-src/mkinstalldirs new file mode 100755 index 000000000..4191a45db --- /dev/null +++ b/libs/libpng-src/mkinstalldirs @@ -0,0 +1,162 @@ +#! /bin/sh +# mkinstalldirs --- make directory hierarchy + +scriptversion=2009-04-28.21; # UTC + +# Original author: Noah Friedman +# Created: 1993-05-16 +# Public domain. +# +# This file is maintained in Automake, please report +# bugs to or send patches to +# . + +nl=' +' +IFS=" "" $nl" +errstatus=0 +dirmode= + +usage="\ +Usage: mkinstalldirs [-h] [--help] [--version] [-m MODE] DIR ... + +Create each directory DIR (with mode MODE, if specified), including all +leading file name components. + +Report bugs to ." + +# process command line arguments +while test $# -gt 0 ; do + case $1 in + -h | --help | --h*) # -h for help + echo "$usage" + exit $? + ;; + -m) # -m PERM arg + shift + test $# -eq 0 && { echo "$usage" 1>&2; exit 1; } + dirmode=$1 + shift + ;; + --version) + echo "$0 $scriptversion" + exit $? + ;; + --) # stop option processing + shift + break + ;; + -*) # unknown option + echo "$usage" 1>&2 + exit 1 + ;; + *) # first non-opt arg + break + ;; + esac +done + +for file +do + if test -d "$file"; then + shift + else + break + fi +done + +case $# in + 0) exit 0 ;; +esac + +# Solaris 8's mkdir -p isn't thread-safe. If you mkdir -p a/b and +# mkdir -p a/c at the same time, both will detect that a is missing, +# one will create a, then the other will try to create a and die with +# a "File exists" error. This is a problem when calling mkinstalldirs +# from a parallel make. We use --version in the probe to restrict +# ourselves to GNU mkdir, which is thread-safe. +case $dirmode in + '') + if mkdir -p --version . >/dev/null 2>&1 && test ! -d ./--version; then + echo "mkdir -p -- $*" + exec mkdir -p -- "$@" + else + # On NextStep and OpenStep, the `mkdir' command does not + # recognize any option. It will interpret all options as + # directories to create, and then abort because `.' already + # exists. + test -d ./-p && rmdir ./-p + test -d ./--version && rmdir ./--version + fi + ;; + *) + if mkdir -m "$dirmode" -p --version . >/dev/null 2>&1 && + test ! -d ./--version; then + echo "mkdir -m $dirmode -p -- $*" + exec mkdir -m "$dirmode" -p -- "$@" + else + # Clean up after NextStep and OpenStep mkdir. + for d in ./-m ./-p ./--version "./$dirmode"; + do + test -d $d && rmdir $d + done + fi + ;; +esac + +for file +do + case $file in + /*) pathcomp=/ ;; + *) pathcomp= ;; + esac + oIFS=$IFS + IFS=/ + set fnord $file + shift + IFS=$oIFS + + for d + do + test "x$d" = x && continue + + pathcomp=$pathcomp$d + case $pathcomp in + -*) pathcomp=./$pathcomp ;; + esac + + if test ! -d "$pathcomp"; then + echo "mkdir $pathcomp" + + mkdir "$pathcomp" || lasterr=$? + + if test ! -d "$pathcomp"; then + errstatus=$lasterr + else + if test ! -z "$dirmode"; then + echo "chmod $dirmode $pathcomp" + lasterr= + chmod "$dirmode" "$pathcomp" || lasterr=$? + + if test ! -z "$lasterr"; then + errstatus=$lasterr + fi + fi + fi + fi + + pathcomp=$pathcomp/ + done +done + +exit $errstatus + +# Local Variables: +# mode: shell-script +# sh-indentation: 2 +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "scriptversion=" +# time-stamp-format: "%:y-%02m-%02d.%02H" +# time-stamp-time-zone: "UTC" +# time-stamp-end: "; # UTC" +# End: diff --git a/libs/libpng-src/png.5 b/libs/libpng-src/png.5 new file mode 100644 index 000000000..20b584ebc --- /dev/null +++ b/libs/libpng-src/png.5 @@ -0,0 +1,74 @@ +.TH PNG 5 "July 9, 2011" +.SH NAME +png \- Portable Network Graphics (PNG) format +.SH DESCRIPTION +PNG (Portable Network Graphics) is an extensible file format for the +lossless, portable, well-compressed storage of raster images. PNG provides +a patent-free replacement for GIF and can also replace many +common uses of TIFF. Indexed-color, grayscale, and truecolor images are +supported, plus an optional alpha channel. Sample depths range from +1 to 16 bits. +.br + +PNG is designed to work well in online viewing applications, such as the +World Wide Web, so it is fully streamable with a progressive display +option. PNG is robust, providing both full file integrity checking and +fast, simple detection of common transmission errors. Also, PNG can store +gamma and chromaticity data for improved color matching on heterogeneous +platforms. + +.SH "SEE ALSO" +.IR libpng(3) ", " zlib(3) ", " deflate(5) ", and " zlib(5) +.LP +PNG specification (second edition), November 2003: +.IP +.br + 8) + png_error(png_ptr, "Too many bytes for PNG signature."); + + png_ptr->sig_bytes = (png_byte)(num_bytes < 0 ? 0 : num_bytes); +} + +/* Checks whether the supplied bytes match the PNG signature. We allow + * checking less than the full 8-byte signature so that those apps that + * already read the first few bytes of a file to determine the file type + * can simply check the remaining bytes for extra assurance. Returns + * an integer less than, equal to, or greater than zero if sig is found, + * respectively, to be less than, to match, or be greater than the correct + * PNG signature (this is the same behaviour as strcmp, memcmp, etc). + */ +int PNGAPI +png_sig_cmp(png_bytep sig, png_size_t start, png_size_t num_to_check) +{ + png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10}; + if (num_to_check > 8) + num_to_check = 8; + else if (num_to_check < 1) + return (-1); + + if (start > 7) + return (-1); + + if (start + num_to_check > 8) + num_to_check = 8 - start; + + return ((int)(png_memcmp(&sig[start], &png_signature[start], num_to_check))); +} + +#if defined(PNG_1_0_X) || defined(PNG_1_2_X) +/* (Obsolete) function to check signature bytes. It does not allow one + * to check a partial signature. This function might be removed in the + * future - use png_sig_cmp(). Returns true (nonzero) if the file is PNG. + */ +int PNGAPI +png_check_sig(png_bytep sig, int num) +{ + return ((int)!png_sig_cmp(sig, (png_size_t)0, (png_size_t)num)); +} +#endif +#endif /* PNG_READ_SUPPORTED */ + +#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) +/* Function to allocate memory for zlib and clear it to 0. */ +#ifdef PNG_1_0_X +voidpf PNGAPI +#else +voidpf /* PRIVATE */ +#endif +png_zalloc(voidpf png_ptr, uInt items, uInt size) +{ + png_voidp ptr; + png_structp p=(png_structp)png_ptr; + png_uint_32 save_flags=p->flags; + png_uint_32 num_bytes; + + if (png_ptr == NULL) + return (NULL); + if (items > PNG_UINT_32_MAX/size) + { + png_warning (p, "Potential overflow in png_zalloc()"); + return (NULL); + } + num_bytes = (png_uint_32)items * size; + + p->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK; + ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes); + p->flags=save_flags; + +#if defined(PNG_1_0_X) && !defined(PNG_NO_ZALLOC_ZERO) + if (ptr == NULL) + return ((voidpf)ptr); + + if (num_bytes > (png_uint_32)0x8000L) + { + png_memset(ptr, 0, (png_size_t)0x8000L); + png_memset((png_bytep)ptr + (png_size_t)0x8000L, 0, + (png_size_t)(num_bytes - (png_uint_32)0x8000L)); + } + else + { + png_memset(ptr, 0, (png_size_t)num_bytes); + } +#endif + return ((voidpf)ptr); +} + +/* Function to free memory for zlib */ +#ifdef PNG_1_0_X +void PNGAPI +#else +void /* PRIVATE */ +#endif +png_zfree(voidpf png_ptr, voidpf ptr) +{ + png_free((png_structp)png_ptr, (png_voidp)ptr); +} + +/* Reset the CRC variable to 32 bits of 1's. Care must be taken + * in case CRC is > 32 bits to leave the top bits 0. + */ +void /* PRIVATE */ +png_reset_crc(png_structp png_ptr) +{ + png_ptr->crc = crc32(0, Z_NULL, 0); +} + +/* Calculate the CRC over a section of data. We can only pass as + * much data to this routine as the largest single buffer size. We + * also check that this data will actually be used before going to the + * trouble of calculating it. + */ +void /* PRIVATE */ +png_calculate_crc(png_structp png_ptr, png_bytep ptr, png_size_t length) +{ + int need_crc = 1; + + if (png_ptr->chunk_name[0] & 0x20) /* ancillary */ + { + if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) == + (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN)) + need_crc = 0; + } + else /* critical */ + { + if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE) + need_crc = 0; + } + + if (need_crc) + png_ptr->crc = crc32(png_ptr->crc, ptr, (uInt)length); +} + +/* Allocate the memory for an info_struct for the application. We don't + * really need the png_ptr, but it could potentially be useful in the + * future. This should be used in favour of malloc(png_sizeof(png_info)) + * and png_info_init() so that applications that want to use a shared + * libpng don't have to be recompiled if png_info changes size. + */ +png_infop PNGAPI +png_create_info_struct(png_structp png_ptr) +{ + png_infop info_ptr; + + png_debug(1, "in png_create_info_struct"); + + if (png_ptr == NULL) + return (NULL); + +#ifdef PNG_USER_MEM_SUPPORTED + info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO, + png_ptr->malloc_fn, png_ptr->mem_ptr); +#else + info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO); +#endif + if (info_ptr != NULL) + png_info_init_3(&info_ptr, png_sizeof(png_info)); + + return (info_ptr); +} + +/* This function frees the memory associated with a single info struct. + * Normally, one would use either png_destroy_read_struct() or + * png_destroy_write_struct() to free an info struct, but this may be + * useful for some applications. + */ +void PNGAPI +png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr) +{ + png_infop info_ptr = NULL; + + png_debug(1, "in png_destroy_info_struct"); + + if (png_ptr == NULL) + return; + + if (info_ptr_ptr != NULL) + info_ptr = *info_ptr_ptr; + + if (info_ptr != NULL) + { + png_info_destroy(png_ptr, info_ptr); + +#ifdef PNG_USER_MEM_SUPPORTED + png_destroy_struct_2((png_voidp)info_ptr, png_ptr->free_fn, + png_ptr->mem_ptr); +#else + png_destroy_struct((png_voidp)info_ptr); +#endif + *info_ptr_ptr = NULL; + } +} + +/* Initialize the info structure. This is now an internal function (0.89) + * and applications using it are urged to use png_create_info_struct() + * instead. + */ +#if defined(PNG_1_0_X) || defined(PNG_1_2_X) +#undef png_info_init +void PNGAPI +png_info_init(png_infop info_ptr) +{ + /* We only come here via pre-1.0.12-compiled applications */ + png_info_init_3(&info_ptr, 0); +} +#endif + +void PNGAPI +png_info_init_3(png_infopp ptr_ptr, png_size_t png_info_struct_size) +{ + png_infop info_ptr = *ptr_ptr; + + png_debug(1, "in png_info_init_3"); + + if (info_ptr == NULL) + return; + + if (png_sizeof(png_info) > png_info_struct_size) + { + png_destroy_struct(info_ptr); + info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO); + *ptr_ptr = info_ptr; + } + + /* Set everything to 0 */ + png_memset(info_ptr, 0, png_sizeof(png_info)); +} + +#ifdef PNG_FREE_ME_SUPPORTED +void PNGAPI +png_data_freer(png_structp png_ptr, png_infop info_ptr, + int freer, png_uint_32 mask) +{ + png_debug(1, "in png_data_freer"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + if (freer == PNG_DESTROY_WILL_FREE_DATA) + info_ptr->free_me |= mask; + else if (freer == PNG_USER_WILL_FREE_DATA) + info_ptr->free_me &= ~mask; + else + png_warning(png_ptr, + "Unknown freer parameter in png_data_freer."); +} +#endif + +void PNGAPI +png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask, + int num) +{ + png_debug(1, "in png_free_data"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + +#ifdef PNG_TEXT_SUPPORTED + /* Free text item num or (if num == -1) all text items */ +#ifdef PNG_FREE_ME_SUPPORTED + if ((mask & PNG_FREE_TEXT) & info_ptr->free_me) +#else + if (mask & PNG_FREE_TEXT) +#endif + { + if (num != -1) + { + if (info_ptr->text && info_ptr->text[num].key) + { + png_free(png_ptr, info_ptr->text[num].key); + info_ptr->text[num].key = NULL; + } + } + else + { + int i; + for (i = 0; i < info_ptr->num_text; i++) + png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, i); + png_free(png_ptr, info_ptr->text); + info_ptr->text = NULL; + info_ptr->num_text=0; + } + } +#endif + +#ifdef PNG_tRNS_SUPPORTED + /* Free any tRNS entry */ +#ifdef PNG_FREE_ME_SUPPORTED + if ((mask & PNG_FREE_TRNS) & info_ptr->free_me) +#else + if ((mask & PNG_FREE_TRNS) && (png_ptr->flags & PNG_FLAG_FREE_TRNS)) +#endif + { + png_free(png_ptr, info_ptr->trans); + info_ptr->trans = NULL; + info_ptr->valid &= ~PNG_INFO_tRNS; +#ifndef PNG_FREE_ME_SUPPORTED + png_ptr->flags &= ~PNG_FLAG_FREE_TRNS; +#endif + } +#endif + +#ifdef PNG_sCAL_SUPPORTED + /* Free any sCAL entry */ +#ifdef PNG_FREE_ME_SUPPORTED + if ((mask & PNG_FREE_SCAL) & info_ptr->free_me) +#else + if (mask & PNG_FREE_SCAL) +#endif + { +#if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED) + png_free(png_ptr, info_ptr->scal_s_width); + png_free(png_ptr, info_ptr->scal_s_height); + info_ptr->scal_s_width = NULL; + info_ptr->scal_s_height = NULL; +#endif + info_ptr->valid &= ~PNG_INFO_sCAL; + } +#endif + +#ifdef PNG_pCAL_SUPPORTED + /* Free any pCAL entry */ +#ifdef PNG_FREE_ME_SUPPORTED + if ((mask & PNG_FREE_PCAL) & info_ptr->free_me) +#else + if (mask & PNG_FREE_PCAL) +#endif + { + png_free(png_ptr, info_ptr->pcal_purpose); + png_free(png_ptr, info_ptr->pcal_units); + info_ptr->pcal_purpose = NULL; + info_ptr->pcal_units = NULL; + if (info_ptr->pcal_params != NULL) + { + int i; + for (i = 0; i < (int)info_ptr->pcal_nparams; i++) + { + png_free(png_ptr, info_ptr->pcal_params[i]); + info_ptr->pcal_params[i] = NULL; + } + png_free(png_ptr, info_ptr->pcal_params); + info_ptr->pcal_params = NULL; + } + info_ptr->valid &= ~PNG_INFO_pCAL; + } +#endif + +#ifdef PNG_iCCP_SUPPORTED + /* Free any iCCP entry */ +#ifdef PNG_FREE_ME_SUPPORTED + if ((mask & PNG_FREE_ICCP) & info_ptr->free_me) +#else + if (mask & PNG_FREE_ICCP) +#endif + { + png_free(png_ptr, info_ptr->iccp_name); + png_free(png_ptr, info_ptr->iccp_profile); + info_ptr->iccp_name = NULL; + info_ptr->iccp_profile = NULL; + info_ptr->valid &= ~PNG_INFO_iCCP; + } +#endif + +#ifdef PNG_sPLT_SUPPORTED + /* Free a given sPLT entry, or (if num == -1) all sPLT entries */ +#ifdef PNG_FREE_ME_SUPPORTED + if ((mask & PNG_FREE_SPLT) & info_ptr->free_me) +#else + if (mask & PNG_FREE_SPLT) +#endif + { + if (num != -1) + { + if (info_ptr->splt_palettes) + { + png_free(png_ptr, info_ptr->splt_palettes[num].name); + png_free(png_ptr, info_ptr->splt_palettes[num].entries); + info_ptr->splt_palettes[num].name = NULL; + info_ptr->splt_palettes[num].entries = NULL; + } + } + else + { + if (info_ptr->splt_palettes_num) + { + int i; + for (i = 0; i < (int)info_ptr->splt_palettes_num; i++) + png_free_data(png_ptr, info_ptr, PNG_FREE_SPLT, i); + + png_free(png_ptr, info_ptr->splt_palettes); + info_ptr->splt_palettes = NULL; + info_ptr->splt_palettes_num = 0; + } + info_ptr->valid &= ~PNG_INFO_sPLT; + } + } +#endif + +#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED + if (png_ptr->unknown_chunk.data) + { + png_free(png_ptr, png_ptr->unknown_chunk.data); + png_ptr->unknown_chunk.data = NULL; + } + +#ifdef PNG_FREE_ME_SUPPORTED + if ((mask & PNG_FREE_UNKN) & info_ptr->free_me) +#else + if (mask & PNG_FREE_UNKN) +#endif + { + if (num != -1) + { + if (info_ptr->unknown_chunks) + { + png_free(png_ptr, info_ptr->unknown_chunks[num].data); + info_ptr->unknown_chunks[num].data = NULL; + } + } + else + { + int i; + + if (info_ptr->unknown_chunks_num) + { + for (i = 0; i < (int)info_ptr->unknown_chunks_num; i++) + png_free_data(png_ptr, info_ptr, PNG_FREE_UNKN, i); + + png_free(png_ptr, info_ptr->unknown_chunks); + info_ptr->unknown_chunks = NULL; + info_ptr->unknown_chunks_num = 0; + } + } + } +#endif + +#ifdef PNG_hIST_SUPPORTED + /* Free any hIST entry */ +#ifdef PNG_FREE_ME_SUPPORTED + if ((mask & PNG_FREE_HIST) & info_ptr->free_me) +#else + if ((mask & PNG_FREE_HIST) && (png_ptr->flags & PNG_FLAG_FREE_HIST)) +#endif + { + png_free(png_ptr, info_ptr->hist); + info_ptr->hist = NULL; + info_ptr->valid &= ~PNG_INFO_hIST; +#ifndef PNG_FREE_ME_SUPPORTED + png_ptr->flags &= ~PNG_FLAG_FREE_HIST; +#endif + } +#endif + + /* Free any PLTE entry that was internally allocated */ +#ifdef PNG_FREE_ME_SUPPORTED + if ((mask & PNG_FREE_PLTE) & info_ptr->free_me) +#else + if ((mask & PNG_FREE_PLTE) && (png_ptr->flags & PNG_FLAG_FREE_PLTE)) +#endif + { + png_zfree(png_ptr, info_ptr->palette); + info_ptr->palette = NULL; + info_ptr->valid &= ~PNG_INFO_PLTE; +#ifndef PNG_FREE_ME_SUPPORTED + png_ptr->flags &= ~PNG_FLAG_FREE_PLTE; +#endif + info_ptr->num_palette = 0; + } + +#ifdef PNG_INFO_IMAGE_SUPPORTED + /* Free any image bits attached to the info structure */ +#ifdef PNG_FREE_ME_SUPPORTED + if ((mask & PNG_FREE_ROWS) & info_ptr->free_me) +#else + if (mask & PNG_FREE_ROWS) +#endif + { + if (info_ptr->row_pointers) + { + int row; + for (row = 0; row < (int)info_ptr->height; row++) + { + png_free(png_ptr, info_ptr->row_pointers[row]); + info_ptr->row_pointers[row] = NULL; + } + png_free(png_ptr, info_ptr->row_pointers); + info_ptr->row_pointers = NULL; + } + info_ptr->valid &= ~PNG_INFO_IDAT; + } +#endif + +#ifdef PNG_FREE_ME_SUPPORTED + if (num == -1) + info_ptr->free_me &= ~mask; + else + info_ptr->free_me &= ~(mask & ~PNG_FREE_MUL); +#endif +} + +/* This is an internal routine to free any memory that the info struct is + * pointing to before re-using it or freeing the struct itself. Recall + * that png_free() checks for NULL pointers for us. + */ +void /* PRIVATE */ +png_info_destroy(png_structp png_ptr, png_infop info_ptr) +{ + png_debug(1, "in png_info_destroy"); + + png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1); + +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED + if (png_ptr->num_chunk_list) + { + png_free(png_ptr, png_ptr->chunk_list); + png_ptr->chunk_list = NULL; + png_ptr->num_chunk_list = 0; + } +#endif + + png_info_init_3(&info_ptr, png_sizeof(png_info)); +} +#endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */ + +/* This function returns a pointer to the io_ptr associated with the user + * functions. The application should free any memory associated with this + * pointer before png_write_destroy() or png_read_destroy() are called. + */ +png_voidp PNGAPI +png_get_io_ptr(png_structp png_ptr) +{ + if (png_ptr == NULL) + return (NULL); + return (png_ptr->io_ptr); +} + +#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) +#ifdef PNG_STDIO_SUPPORTED +/* Initialize the default input/output functions for the PNG file. If you + * use your own read or write routines, you can call either png_set_read_fn() + * or png_set_write_fn() instead of png_init_io(). If you have defined + * PNG_NO_STDIO, you must use a function of your own because "FILE *" isn't + * necessarily available. + */ +void PNGAPI +png_init_io(png_structp png_ptr, png_FILE_p fp) +{ + png_debug(1, "in png_init_io"); + + if (png_ptr == NULL) + return; + + png_ptr->io_ptr = (png_voidp)fp; +} +#endif + +#ifdef PNG_TIME_RFC1123_SUPPORTED +/* Convert the supplied time into an RFC 1123 string suitable for use in + * a "Creation Time" or other text-based time string. + */ +png_charp PNGAPI +png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime) +{ + static PNG_CONST char short_months[12][4] = + {"Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; + + if (png_ptr == NULL) + return (NULL); + if (png_ptr->time_buffer == NULL) + { + png_ptr->time_buffer = (png_charp)png_malloc(png_ptr, (png_uint_32)(29* + png_sizeof(char))); + } + +#ifdef _WIN32_WCE + { + wchar_t time_buf[29]; + wsprintf(time_buf, TEXT("%d %S %d %02d:%02d:%02d +0000"), + ptime->day % 32, short_months[(ptime->month - 1) % 12], + ptime->year, ptime->hour % 24, ptime->minute % 60, + ptime->second % 61); + WideCharToMultiByte(CP_ACP, 0, time_buf, -1, png_ptr->time_buffer, + 29, NULL, NULL); + } +#else +#ifdef USE_FAR_KEYWORD + { + char near_time_buf[29]; + png_snprintf6(near_time_buf, 29, "%d %s %d %02d:%02d:%02d +0000", + ptime->day % 32, short_months[(ptime->month - 1) % 12], + ptime->year, ptime->hour % 24, ptime->minute % 60, + ptime->second % 61); + png_memcpy(png_ptr->time_buffer, near_time_buf, + 29*png_sizeof(char)); + } +#else + png_snprintf6(png_ptr->time_buffer, 29, "%d %s %d %02d:%02d:%02d +0000", + ptime->day % 32, short_months[(ptime->month - 1) % 12], + ptime->year, ptime->hour % 24, ptime->minute % 60, + ptime->second % 61); +#endif +#endif /* _WIN32_WCE */ + return ((png_charp)png_ptr->time_buffer); +} +#endif /* PNG_TIME_RFC1123_SUPPORTED */ + +#endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */ + +png_charp PNGAPI +png_get_copyright(png_structp png_ptr) +{ + png_ptr = png_ptr; /* Silence compiler warning about unused png_ptr */ +#ifdef PNG_STRING_COPYRIGHT + return PNG_STRING_COPYRIGHT +#else +#ifdef __STDC__ + return ((png_charp) PNG_STRING_NEWLINE \ + "libpng version 1.2.46 - July 9, 2011" PNG_STRING_NEWLINE \ + "Copyright (c) 1998-2011 Glenn Randers-Pehrson" PNG_STRING_NEWLINE \ + "Copyright (c) 1996-1997 Andreas Dilger" PNG_STRING_NEWLINE \ + "Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \ + PNG_STRING_NEWLINE); +#else + return ((png_charp) "libpng version 1.2.46 - July 9, 2011\ + Copyright (c) 1998-2011 Glenn Randers-Pehrson\ + Copyright (c) 1996-1997 Andreas Dilger\ + Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc."); +#endif +#endif +} + +/* The following return the library version as a short string in the + * format 1.0.0 through 99.99.99zz. To get the version of *.h files + * used with your application, print out PNG_LIBPNG_VER_STRING, which + * is defined in png.h. + * Note: now there is no difference between png_get_libpng_ver() and + * png_get_header_ver(). Due to the version_nn_nn_nn typedef guard, + * it is guaranteed that png.c uses the correct version of png.h. + */ +png_charp PNGAPI +png_get_libpng_ver(png_structp png_ptr) +{ + /* Version of *.c files used when building libpng */ + png_ptr = png_ptr; /* Silence compiler warning about unused png_ptr */ + return ((png_charp) PNG_LIBPNG_VER_STRING); +} + +png_charp PNGAPI +png_get_header_ver(png_structp png_ptr) +{ + /* Version of *.h files used when building libpng */ + png_ptr = png_ptr; /* Silence compiler warning about unused png_ptr */ + return ((png_charp) PNG_LIBPNG_VER_STRING); +} + +png_charp PNGAPI +png_get_header_version(png_structp png_ptr) +{ + /* Returns longer string containing both version and date */ + png_ptr = png_ptr; /* Silence compiler warning about unused png_ptr */ +#ifdef __STDC__ + return ((png_charp) PNG_HEADER_VERSION_STRING +#ifndef PNG_READ_SUPPORTED + " (NO READ SUPPORT)" +#endif + PNG_STRING_NEWLINE); +#else + return ((png_charp) PNG_HEADER_VERSION_STRING); +#endif +} + +#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED +int PNGAPI +png_handle_as_unknown(png_structp png_ptr, png_bytep chunk_name) +{ + /* Check chunk_name and return "keep" value if it's on the list, else 0 */ + int i; + png_bytep p; + if (png_ptr == NULL || chunk_name == NULL || png_ptr->num_chunk_list<=0) + return 0; + p = png_ptr->chunk_list + png_ptr->num_chunk_list*5 - 5; + for (i = png_ptr->num_chunk_list; i; i--, p -= 5) + if (!png_memcmp(chunk_name, p, 4)) + return ((int)*(p + 4)); + return 0; +} +#endif + +/* This function, added to libpng-1.0.6g, is untested. */ +int PNGAPI +png_reset_zstream(png_structp png_ptr) +{ + if (png_ptr == NULL) + return Z_STREAM_ERROR; + return (inflateReset(&png_ptr->zstream)); +} +#endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */ + +/* This function was added to libpng-1.0.7 */ +png_uint_32 PNGAPI +png_access_version_number(void) +{ + /* Version of *.c files used when building libpng */ + return((png_uint_32) PNG_LIBPNG_VER); +} + + +#if defined(PNG_READ_SUPPORTED) && defined(PNG_ASSEMBLER_CODE_SUPPORTED) +#ifndef PNG_1_0_X +/* This function was added to libpng 1.2.0 */ +int PNGAPI +png_mmx_support(void) +{ + /* Obsolete, to be removed from libpng-1.4.0 */ + return -1; +} +#endif /* PNG_1_0_X */ +#endif /* PNG_READ_SUPPORTED && PNG_ASSEMBLER_CODE_SUPPORTED */ + +#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) +#ifdef PNG_SIZE_T +/* Added at libpng version 1.2.6 */ + PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size)); +png_size_t PNGAPI +png_convert_size(size_t size) +{ + if (size > (png_size_t)-1) + PNG_ABORT(); /* We haven't got access to png_ptr, so no png_error() */ + return ((png_size_t)size); +} +#endif /* PNG_SIZE_T */ + +/* Added at libpng version 1.2.34 and 1.4.0 (moved from pngset.c) */ +#ifdef PNG_cHRM_SUPPORTED +#ifdef PNG_CHECK_cHRM_SUPPORTED + +/* + * Multiply two 32-bit numbers, V1 and V2, using 32-bit + * arithmetic, to produce a 64 bit result in the HI/LO words. + * + * A B + * x C D + * ------ + * AD || BD + * AC || CB || 0 + * + * where A and B are the high and low 16-bit words of V1, + * C and D are the 16-bit words of V2, AD is the product of + * A and D, and X || Y is (X << 16) + Y. +*/ + +void /* PRIVATE */ +png_64bit_product (long v1, long v2, unsigned long *hi_product, + unsigned long *lo_product) +{ + int a, b, c, d; + long lo, hi, x, y; + + a = (v1 >> 16) & 0xffff; + b = v1 & 0xffff; + c = (v2 >> 16) & 0xffff; + d = v2 & 0xffff; + + lo = b * d; /* BD */ + x = a * d + c * b; /* AD + CB */ + y = ((lo >> 16) & 0xffff) + x; + + lo = (lo & 0xffff) | ((y & 0xffff) << 16); + hi = (y >> 16) & 0xffff; + + hi += a * c; /* AC */ + + *hi_product = (unsigned long)hi; + *lo_product = (unsigned long)lo; +} + +int /* PRIVATE */ +png_check_cHRM_fixed(png_structp png_ptr, + png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x, + png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y, + png_fixed_point blue_x, png_fixed_point blue_y) +{ + int ret = 1; + unsigned long xy_hi,xy_lo,yx_hi,yx_lo; + + png_debug(1, "in function png_check_cHRM_fixed"); + + if (png_ptr == NULL) + return 0; + + if (white_x < 0 || white_y <= 0 || + red_x < 0 || red_y < 0 || + green_x < 0 || green_y < 0 || + blue_x < 0 || blue_y < 0) + { + png_warning(png_ptr, + "Ignoring attempt to set negative chromaticity value"); + ret = 0; + } + if (white_x > (png_fixed_point) PNG_UINT_31_MAX || + white_y > (png_fixed_point) PNG_UINT_31_MAX || + red_x > (png_fixed_point) PNG_UINT_31_MAX || + red_y > (png_fixed_point) PNG_UINT_31_MAX || + green_x > (png_fixed_point) PNG_UINT_31_MAX || + green_y > (png_fixed_point) PNG_UINT_31_MAX || + blue_x > (png_fixed_point) PNG_UINT_31_MAX || + blue_y > (png_fixed_point) PNG_UINT_31_MAX ) + { + png_warning(png_ptr, + "Ignoring attempt to set chromaticity value exceeding 21474.83"); + ret = 0; + } + if (white_x > 100000L - white_y) + { + png_warning(png_ptr, "Invalid cHRM white point"); + ret = 0; + } + if (red_x > 100000L - red_y) + { + png_warning(png_ptr, "Invalid cHRM red point"); + ret = 0; + } + if (green_x > 100000L - green_y) + { + png_warning(png_ptr, "Invalid cHRM green point"); + ret = 0; + } + if (blue_x > 100000L - blue_y) + { + png_warning(png_ptr, "Invalid cHRM blue point"); + ret = 0; + } + + png_64bit_product(green_x - red_x, blue_y - red_y, &xy_hi, &xy_lo); + png_64bit_product(green_y - red_y, blue_x - red_x, &yx_hi, &yx_lo); + + if (xy_hi == yx_hi && xy_lo == yx_lo) + { + png_warning(png_ptr, + "Ignoring attempt to set cHRM RGB triangle with zero area"); + ret = 0; + } + + return ret; +} +#endif /* PNG_CHECK_cHRM_SUPPORTED */ +#endif /* PNG_cHRM_SUPPORTED */ + +void /* PRIVATE */ +png_check_IHDR(png_structp png_ptr, + png_uint_32 width, png_uint_32 height, int bit_depth, + int color_type, int interlace_type, int compression_type, + int filter_type) +{ + int error = 0; + + /* Check for width and height valid values */ + if (width == 0) + { + png_warning(png_ptr, "Image width is zero in IHDR"); + error = 1; + } + + if (height == 0) + { + png_warning(png_ptr, "Image height is zero in IHDR"); + error = 1; + } + +#ifdef PNG_SET_USER_LIMITS_SUPPORTED + if (width > png_ptr->user_width_max || width > PNG_USER_WIDTH_MAX) +#else + if (width > PNG_USER_WIDTH_MAX) +#endif + { + png_warning(png_ptr, "Image width exceeds user limit in IHDR"); + error = 1; + } + +#ifdef PNG_SET_USER_LIMITS_SUPPORTED + if (height > png_ptr->user_height_max || height > PNG_USER_HEIGHT_MAX) +#else + if (height > PNG_USER_HEIGHT_MAX) +#endif + { + png_warning(png_ptr, "Image height exceeds user limit in IHDR"); + error = 1; + } + + if (width > PNG_UINT_31_MAX) + { + png_warning(png_ptr, "Invalid image width in IHDR"); + error = 1; + } + + if ( height > PNG_UINT_31_MAX) + { + png_warning(png_ptr, "Invalid image height in IHDR"); + error = 1; + } + + if ( width > (PNG_UINT_32_MAX + >> 3) /* 8-byte RGBA pixels */ + - 64 /* bigrowbuf hack */ + - 1 /* filter byte */ + - 7*8 /* rounding of width to multiple of 8 pixels */ + - 8) /* extra max_pixel_depth pad */ + png_warning(png_ptr, "Width is too large for libpng to process pixels"); + + /* Check other values */ + if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 && + bit_depth != 8 && bit_depth != 16) + { + png_warning(png_ptr, "Invalid bit depth in IHDR"); + error = 1; + } + + if (color_type < 0 || color_type == 1 || + color_type == 5 || color_type > 6) + { + png_warning(png_ptr, "Invalid color type in IHDR"); + error = 1; + } + + if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) || + ((color_type == PNG_COLOR_TYPE_RGB || + color_type == PNG_COLOR_TYPE_GRAY_ALPHA || + color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8)) + { + png_warning(png_ptr, "Invalid color type/bit depth combination in IHDR"); + error = 1; + } + + if (interlace_type >= PNG_INTERLACE_LAST) + { + png_warning(png_ptr, "Unknown interlace method in IHDR"); + error = 1; + } + + if (compression_type != PNG_COMPRESSION_TYPE_BASE) + { + png_warning(png_ptr, "Unknown compression method in IHDR"); + error = 1; + } + +#ifdef PNG_MNG_FEATURES_SUPPORTED + /* Accept filter_method 64 (intrapixel differencing) only if + * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and + * 2. Libpng did not read a PNG signature (this filter_method is only + * used in PNG datastreams that are embedded in MNG datastreams) and + * 3. The application called png_permit_mng_features with a mask that + * included PNG_FLAG_MNG_FILTER_64 and + * 4. The filter_method is 64 and + * 5. The color_type is RGB or RGBA + */ + if ((png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) && + png_ptr->mng_features_permitted) + png_warning(png_ptr, "MNG features are not allowed in a PNG datastream"); + + if (filter_type != PNG_FILTER_TYPE_BASE) + { + if (!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && + (filter_type == PNG_INTRAPIXEL_DIFFERENCING) && + ((png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) == 0) && + (color_type == PNG_COLOR_TYPE_RGB || + color_type == PNG_COLOR_TYPE_RGB_ALPHA))) + { + png_warning(png_ptr, "Unknown filter method in IHDR"); + error = 1; + } + + if (png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) + { + png_warning(png_ptr, "Invalid filter method in IHDR"); + error = 1; + } + } + +#else + if (filter_type != PNG_FILTER_TYPE_BASE) + { + png_warning(png_ptr, "Unknown filter method in IHDR"); + error = 1; + } +#endif + + if (error == 1) + png_error(png_ptr, "Invalid IHDR data"); +} +#endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */ diff --git a/libs/libpng-src/png.h b/libs/libpng-src/png.h new file mode 100644 index 000000000..4157dfd8e --- /dev/null +++ b/libs/libpng-src/png.h @@ -0,0 +1,3963 @@ +/* png.h - header file for PNG reference library + * + * libpng version 1.2.46 - July 9, 2011 + * Copyright (c) 1998-2011 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + * + * This code is released under the libpng license (See LICENSE, below) + * + * Authors and maintainers: + * libpng versions 0.71, May 1995, through 0.88, January 1996: Guy Schalnat + * libpng versions 0.89c, June 1996, through 0.96, May 1997: Andreas Dilger + * libpng versions 0.97, January 1998, through 1.2.46 - July 9, 2011: Glenn + * See also "Contributing Authors", below. + * + * Note about libpng version numbers: + * + * Due to various miscommunications, unforeseen code incompatibilities + * and occasional factors outside the authors' control, version numbering + * on the library has not always been consistent and straightforward. + * The following table summarizes matters since version 0.89c, which was + * the first widely used release: + * + * source png.h png.h shared-lib + * version string int version + * ------- ------ ----- ---------- + * 0.89c "1.0 beta 3" 0.89 89 1.0.89 + * 0.90 "1.0 beta 4" 0.90 90 0.90 [should have been 2.0.90] + * 0.95 "1.0 beta 5" 0.95 95 0.95 [should have been 2.0.95] + * 0.96 "1.0 beta 6" 0.96 96 0.96 [should have been 2.0.96] + * 0.97b "1.00.97 beta 7" 1.00.97 97 1.0.1 [should have been 2.0.97] + * 0.97c 0.97 97 2.0.97 + * 0.98 0.98 98 2.0.98 + * 0.99 0.99 98 2.0.99 + * 0.99a-m 0.99 99 2.0.99 + * 1.00 1.00 100 2.1.0 [100 should be 10000] + * 1.0.0 (from here on, the 100 2.1.0 [100 should be 10000] + * 1.0.1 png.h string is 10001 2.1.0 + * 1.0.1a-e identical to the 10002 from here on, the shared library + * 1.0.2 source version) 10002 is 2.V where V is the source code + * 1.0.2a-b 10003 version, except as noted. + * 1.0.3 10003 + * 1.0.3a-d 10004 + * 1.0.4 10004 + * 1.0.4a-f 10005 + * 1.0.5 (+ 2 patches) 10005 + * 1.0.5a-d 10006 + * 1.0.5e-r 10100 (not source compatible) + * 1.0.5s-v 10006 (not binary compatible) + * 1.0.6 (+ 3 patches) 10006 (still binary incompatible) + * 1.0.6d-f 10007 (still binary incompatible) + * 1.0.6g 10007 + * 1.0.6h 10007 10.6h (testing xy.z so-numbering) + * 1.0.6i 10007 10.6i + * 1.0.6j 10007 2.1.0.6j (incompatible with 1.0.0) + * 1.0.7beta11-14 DLLNUM 10007 2.1.0.7beta11-14 (binary compatible) + * 1.0.7beta15-18 1 10007 2.1.0.7beta15-18 (binary compatible) + * 1.0.7rc1-2 1 10007 2.1.0.7rc1-2 (binary compatible) + * 1.0.7 1 10007 (still compatible) + * 1.0.8beta1-4 1 10008 2.1.0.8beta1-4 + * 1.0.8rc1 1 10008 2.1.0.8rc1 + * 1.0.8 1 10008 2.1.0.8 + * 1.0.9beta1-6 1 10009 2.1.0.9beta1-6 + * 1.0.9rc1 1 10009 2.1.0.9rc1 + * 1.0.9beta7-10 1 10009 2.1.0.9beta7-10 + * 1.0.9rc2 1 10009 2.1.0.9rc2 + * 1.0.9 1 10009 2.1.0.9 + * 1.0.10beta1 1 10010 2.1.0.10beta1 + * 1.0.10rc1 1 10010 2.1.0.10rc1 + * 1.0.10 1 10010 2.1.0.10 + * 1.0.11beta1-3 1 10011 2.1.0.11beta1-3 + * 1.0.11rc1 1 10011 2.1.0.11rc1 + * 1.0.11 1 10011 2.1.0.11 + * 1.0.12beta1-2 2 10012 2.1.0.12beta1-2 + * 1.0.12rc1 2 10012 2.1.0.12rc1 + * 1.0.12 2 10012 2.1.0.12 + * 1.1.0a-f - 10100 2.1.1.0a-f (branch abandoned) + * 1.2.0beta1-2 2 10200 2.1.2.0beta1-2 + * 1.2.0beta3-5 3 10200 3.1.2.0beta3-5 + * 1.2.0rc1 3 10200 3.1.2.0rc1 + * 1.2.0 3 10200 3.1.2.0 + * 1.2.1beta1-4 3 10201 3.1.2.1beta1-4 + * 1.2.1rc1-2 3 10201 3.1.2.1rc1-2 + * 1.2.1 3 10201 3.1.2.1 + * 1.2.2beta1-6 12 10202 12.so.0.1.2.2beta1-6 + * 1.0.13beta1 10 10013 10.so.0.1.0.13beta1 + * 1.0.13rc1 10 10013 10.so.0.1.0.13rc1 + * 1.2.2rc1 12 10202 12.so.0.1.2.2rc1 + * 1.0.13 10 10013 10.so.0.1.0.13 + * 1.2.2 12 10202 12.so.0.1.2.2 + * 1.2.3rc1-6 12 10203 12.so.0.1.2.3rc1-6 + * 1.2.3 12 10203 12.so.0.1.2.3 + * 1.2.4beta1-3 13 10204 12.so.0.1.2.4beta1-3 + * 1.0.14rc1 13 10014 10.so.0.1.0.14rc1 + * 1.2.4rc1 13 10204 12.so.0.1.2.4rc1 + * 1.0.14 10 10014 10.so.0.1.0.14 + * 1.2.4 13 10204 12.so.0.1.2.4 + * 1.2.5beta1-2 13 10205 12.so.0.1.2.5beta1-2 + * 1.0.15rc1-3 10 10015 10.so.0.1.0.15rc1-3 + * 1.2.5rc1-3 13 10205 12.so.0.1.2.5rc1-3 + * 1.0.15 10 10015 10.so.0.1.0.15 + * 1.2.5 13 10205 12.so.0.1.2.5 + * 1.2.6beta1-4 13 10206 12.so.0.1.2.6beta1-4 + * 1.0.16 10 10016 10.so.0.1.0.16 + * 1.2.6 13 10206 12.so.0.1.2.6 + * 1.2.7beta1-2 13 10207 12.so.0.1.2.7beta1-2 + * 1.0.17rc1 10 10017 10.so.0.1.0.17rc1 + * 1.2.7rc1 13 10207 12.so.0.1.2.7rc1 + * 1.0.17 10 10017 10.so.0.1.0.17 + * 1.2.7 13 10207 12.so.0.1.2.7 + * 1.2.8beta1-5 13 10208 12.so.0.1.2.8beta1-5 + * 1.0.18rc1-5 10 10018 10.so.0.1.0.18rc1-5 + * 1.2.8rc1-5 13 10208 12.so.0.1.2.8rc1-5 + * 1.0.18 10 10018 10.so.0.1.0.18 + * 1.2.8 13 10208 12.so.0.1.2.8 + * 1.2.9beta1-3 13 10209 12.so.0.1.2.9beta1-3 + * 1.2.9beta4-11 13 10209 12.so.0.9[.0] + * 1.2.9rc1 13 10209 12.so.0.9[.0] + * 1.2.9 13 10209 12.so.0.9[.0] + * 1.2.10beta1-8 13 10210 12.so.0.10[.0] + * 1.2.10rc1-3 13 10210 12.so.0.10[.0] + * 1.2.10 13 10210 12.so.0.10[.0] + * 1.2.11beta1-4 13 10211 12.so.0.11[.0] + * 1.0.19rc1-5 10 10019 10.so.0.19[.0] + * 1.2.11rc1-5 13 10211 12.so.0.11[.0] + * 1.0.19 10 10019 10.so.0.19[.0] + * 1.2.11 13 10211 12.so.0.11[.0] + * 1.0.20 10 10020 10.so.0.20[.0] + * 1.2.12 13 10212 12.so.0.12[.0] + * 1.2.13beta1 13 10213 12.so.0.13[.0] + * 1.0.21 10 10021 10.so.0.21[.0] + * 1.2.13 13 10213 12.so.0.13[.0] + * 1.2.14beta1-2 13 10214 12.so.0.14[.0] + * 1.0.22rc1 10 10022 10.so.0.22[.0] + * 1.2.14rc1 13 10214 12.so.0.14[.0] + * 1.0.22 10 10022 10.so.0.22[.0] + * 1.2.14 13 10214 12.so.0.14[.0] + * 1.2.15beta1-6 13 10215 12.so.0.15[.0] + * 1.0.23rc1-5 10 10023 10.so.0.23[.0] + * 1.2.15rc1-5 13 10215 12.so.0.15[.0] + * 1.0.23 10 10023 10.so.0.23[.0] + * 1.2.15 13 10215 12.so.0.15[.0] + * 1.2.16beta1-2 13 10216 12.so.0.16[.0] + * 1.2.16rc1 13 10216 12.so.0.16[.0] + * 1.0.24 10 10024 10.so.0.24[.0] + * 1.2.16 13 10216 12.so.0.16[.0] + * 1.2.17beta1-2 13 10217 12.so.0.17[.0] + * 1.0.25rc1 10 10025 10.so.0.25[.0] + * 1.2.17rc1-3 13 10217 12.so.0.17[.0] + * 1.0.25 10 10025 10.so.0.25[.0] + * 1.2.17 13 10217 12.so.0.17[.0] + * 1.0.26 10 10026 10.so.0.26[.0] + * 1.2.18 13 10218 12.so.0.18[.0] + * 1.2.19beta1-31 13 10219 12.so.0.19[.0] + * 1.0.27rc1-6 10 10027 10.so.0.27[.0] + * 1.2.19rc1-6 13 10219 12.so.0.19[.0] + * 1.0.27 10 10027 10.so.0.27[.0] + * 1.2.19 13 10219 12.so.0.19[.0] + * 1.2.20beta01-04 13 10220 12.so.0.20[.0] + * 1.0.28rc1-6 10 10028 10.so.0.28[.0] + * 1.2.20rc1-6 13 10220 12.so.0.20[.0] + * 1.0.28 10 10028 10.so.0.28[.0] + * 1.2.20 13 10220 12.so.0.20[.0] + * 1.2.21beta1-2 13 10221 12.so.0.21[.0] + * 1.2.21rc1-3 13 10221 12.so.0.21[.0] + * 1.0.29 10 10029 10.so.0.29[.0] + * 1.2.21 13 10221 12.so.0.21[.0] + * 1.2.22beta1-4 13 10222 12.so.0.22[.0] + * 1.0.30rc1 10 10030 10.so.0.30[.0] + * 1.2.22rc1 13 10222 12.so.0.22[.0] + * 1.0.30 10 10030 10.so.0.30[.0] + * 1.2.22 13 10222 12.so.0.22[.0] + * 1.2.23beta01-05 13 10223 12.so.0.23[.0] + * 1.2.23rc01 13 10223 12.so.0.23[.0] + * 1.2.23 13 10223 12.so.0.23[.0] + * 1.2.24beta01-02 13 10224 12.so.0.24[.0] + * 1.2.24rc01 13 10224 12.so.0.24[.0] + * 1.2.24 13 10224 12.so.0.24[.0] + * 1.2.25beta01-06 13 10225 12.so.0.25[.0] + * 1.2.25rc01-02 13 10225 12.so.0.25[.0] + * 1.0.31 10 10031 10.so.0.31[.0] + * 1.2.25 13 10225 12.so.0.25[.0] + * 1.2.26beta01-06 13 10226 12.so.0.26[.0] + * 1.2.26rc01 13 10226 12.so.0.26[.0] + * 1.2.26 13 10226 12.so.0.26[.0] + * 1.0.32 10 10032 10.so.0.32[.0] + * 1.2.27beta01-06 13 10227 12.so.0.27[.0] + * 1.2.27rc01 13 10227 12.so.0.27[.0] + * 1.0.33 10 10033 10.so.0.33[.0] + * 1.2.27 13 10227 12.so.0.27[.0] + * 1.0.34 10 10034 10.so.0.34[.0] + * 1.2.28 13 10228 12.so.0.28[.0] + * 1.2.29beta01-03 13 10229 12.so.0.29[.0] + * 1.2.29rc01 13 10229 12.so.0.29[.0] + * 1.0.35 10 10035 10.so.0.35[.0] + * 1.2.29 13 10229 12.so.0.29[.0] + * 1.0.37 10 10037 10.so.0.37[.0] + * 1.2.30beta01-04 13 10230 12.so.0.30[.0] + * 1.0.38rc01-08 10 10038 10.so.0.38[.0] + * 1.2.30rc01-08 13 10230 12.so.0.30[.0] + * 1.0.38 10 10038 10.so.0.38[.0] + * 1.2.30 13 10230 12.so.0.30[.0] + * 1.0.39rc01-03 10 10039 10.so.0.39[.0] + * 1.2.31rc01-03 13 10231 12.so.0.31[.0] + * 1.0.39 10 10039 10.so.0.39[.0] + * 1.2.31 13 10231 12.so.0.31[.0] + * 1.2.32beta01-02 13 10232 12.so.0.32[.0] + * 1.0.40rc01 10 10040 10.so.0.40[.0] + * 1.2.32rc01 13 10232 12.so.0.32[.0] + * 1.0.40 10 10040 10.so.0.40[.0] + * 1.2.32 13 10232 12.so.0.32[.0] + * 1.2.33beta01-02 13 10233 12.so.0.33[.0] + * 1.2.33rc01-02 13 10233 12.so.0.33[.0] + * 1.0.41rc01 10 10041 10.so.0.41[.0] + * 1.2.33 13 10233 12.so.0.33[.0] + * 1.0.41 10 10041 10.so.0.41[.0] + * 1.2.34beta01-07 13 10234 12.so.0.34[.0] + * 1.0.42rc01 10 10042 10.so.0.42[.0] + * 1.2.34rc01 13 10234 12.so.0.34[.0] + * 1.0.42 10 10042 10.so.0.42[.0] + * 1.2.34 13 10234 12.so.0.34[.0] + * 1.2.35beta01-03 13 10235 12.so.0.35[.0] + * 1.0.43rc01-02 10 10043 10.so.0.43[.0] + * 1.2.35rc01-02 13 10235 12.so.0.35[.0] + * 1.0.43 10 10043 10.so.0.43[.0] + * 1.2.35 13 10235 12.so.0.35[.0] + * 1.2.36beta01-05 13 10236 12.so.0.36[.0] + * 1.2.36rc01 13 10236 12.so.0.36[.0] + * 1.0.44 10 10044 10.so.0.44[.0] + * 1.2.36 13 10236 12.so.0.36[.0] + * 1.2.37beta01-03 13 10237 12.so.0.37[.0] + * 1.2.37rc01 13 10237 12.so.0.37[.0] + * 1.2.37 13 10237 12.so.0.37[.0] + * 1.0.45 10 10045 12.so.0.45[.0] + * 1.0.46 10 10046 10.so.0.46[.0] + * 1.2.38beta01 13 10238 12.so.0.38[.0] + * 1.2.38rc01-03 13 10238 12.so.0.38[.0] + * 1.0.47 10 10047 10.so.0.47[.0] + * 1.2.38 13 10238 12.so.0.38[.0] + * 1.2.39beta01-05 13 10239 12.so.0.39[.0] + * 1.2.39rc01 13 10239 12.so.0.39[.0] + * 1.0.48 10 10048 10.so.0.48[.0] + * 1.2.39 13 10239 12.so.0.39[.0] + * 1.2.40beta01 13 10240 12.so.0.40[.0] + * 1.2.40rc01 13 10240 12.so.0.40[.0] + * 1.0.49 10 10049 10.so.0.49[.0] + * 1.2.40 13 10240 12.so.0.40[.0] + * 1.2.41beta01-18 13 10241 12.so.0.41[.0] + * 1.0.51rc01 10 10051 10.so.0.51[.0] + * 1.2.41rc01-03 13 10241 12.so.0.41[.0] + * 1.0.51 10 10051 10.so.0.51[.0] + * 1.2.41 13 10241 12.so.0.41[.0] + * 1.2.42beta01-02 13 10242 12.so.0.42[.0] + * 1.2.42rc01-05 13 10242 12.so.0.42[.0] + * 1.0.52 10 10052 10.so.0.52[.0] + * 1.2.42 13 10242 12.so.0.42[.0] + * 1.2.43beta01-05 13 10243 12.so.0.43[.0] + * 1.0.53rc01-02 10 10053 10.so.0.53[.0] + * 1.2.43rc01-02 13 10243 12.so.0.43[.0] + * 1.0.53 10 10053 10.so.0.53[.0] + * 1.2.43 13 10243 12.so.0.43[.0] + * 1.2.44beta01-03 13 10244 12.so.0.44[.0] + * 1.2.44rc01-03 13 10244 12.so.0.44[.0] + * 1.2.44 13 10244 12.so.0.44[.0] + * 1.2.45beta01-03 13 10245 12.so.0.45[.0] + * 1.0.55rc01 10 10055 10.so.0.55[.0] + * 1.2.45rc01 13 10245 12.so.0.45[.0] + * 1.0.55 10 10055 10.so.0.55[.0] + * 1.2.45 13 10245 12.so.0.45[.0] + * 1.2.46rc01-02 13 10246 12.so.0.46[.0] + * 1.0.56 10 10056 10.so.0.56[.0] + * 1.2.46 13 10246 12.so.0.46[.0] + * + * Henceforth the source version will match the shared-library major + * and minor numbers; the shared-library major version number will be + * used for changes in backward compatibility, as it is intended. The + * PNG_LIBPNG_VER macro, which is not used within libpng but is available + * for applications, is an unsigned integer of the form xyyzz corresponding + * to the source version x.y.z (leading zeros in y and z). Beta versions + * were given the previous public release number plus a letter, until + * version 1.0.6j; from then on they were given the upcoming public + * release number plus "betaNN" or "rcNN". + * + * Binary incompatibility exists only when applications make direct access + * to the info_ptr or png_ptr members through png.h, and the compiled + * application is loaded with a different version of the library. + * + * DLLNUM will change each time there are forward or backward changes + * in binary compatibility (e.g., when a new feature is added). + * + * See libpng.txt or libpng.3 for more information. The PNG specification + * is available as a W3C Recommendation and as an ISO Specification, + * defines should NOT be changed. + */ +#define PNG_INFO_gAMA 0x0001 +#define PNG_INFO_sBIT 0x0002 +#define PNG_INFO_cHRM 0x0004 +#define PNG_INFO_PLTE 0x0008 +#define PNG_INFO_tRNS 0x0010 +#define PNG_INFO_bKGD 0x0020 +#define PNG_INFO_hIST 0x0040 +#define PNG_INFO_pHYs 0x0080 +#define PNG_INFO_oFFs 0x0100 +#define PNG_INFO_tIME 0x0200 +#define PNG_INFO_pCAL 0x0400 +#define PNG_INFO_sRGB 0x0800 /* GR-P, 0.96a */ +#define PNG_INFO_iCCP 0x1000 /* ESR, 1.0.6 */ +#define PNG_INFO_sPLT 0x2000 /* ESR, 1.0.6 */ +#define PNG_INFO_sCAL 0x4000 /* ESR, 1.0.6 */ +#define PNG_INFO_IDAT 0x8000L /* ESR, 1.0.6 */ +#define PNG_INFO_acTL 0x10000L +#define PNG_INFO_fcTL 0x20000L + +/* This is used for the transformation routines, as some of them + * change these values for the row. It also should enable using + * the routines for other purposes. + */ +typedef struct png_row_info_struct +{ + png_uint_32 width; /* width of row */ + png_uint_32 rowbytes; /* number of bytes in row */ + png_byte color_type; /* color type of row */ + png_byte bit_depth; /* bit depth of row */ + png_byte channels; /* number of channels (1, 2, 3, or 4) */ + png_byte pixel_depth; /* bits per pixel (depth * channels) */ +} png_row_info; + +typedef png_row_info FAR * png_row_infop; +typedef png_row_info FAR * FAR * png_row_infopp; + +/* These are the function types for the I/O functions and for the functions + * that allow the user to override the default I/O functions with his or her + * own. The png_error_ptr type should match that of user-supplied warning + * and error functions, while the png_rw_ptr type should match that of the + * user read/write data functions. + */ +typedef struct png_struct_def png_struct; +typedef png_struct FAR * png_structp; + +typedef void (PNGAPI *png_error_ptr) PNGARG((png_structp, png_const_charp)); +typedef void (PNGAPI *png_rw_ptr) PNGARG((png_structp, png_bytep, png_size_t)); +typedef void (PNGAPI *png_flush_ptr) PNGARG((png_structp)); +typedef void (PNGAPI *png_read_status_ptr) PNGARG((png_structp, png_uint_32, + int)); +typedef void (PNGAPI *png_write_status_ptr) PNGARG((png_structp, png_uint_32, + int)); + +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED +typedef void (PNGAPI *png_progressive_info_ptr) PNGARG((png_structp, png_infop)); +typedef void (PNGAPI *png_progressive_end_ptr) PNGARG((png_structp, png_infop)); +typedef void (PNGAPI *png_progressive_row_ptr) PNGARG((png_structp, png_bytep, + png_uint_32, int)); +#if defined(PNG_APNG_SUPPORTED) +typedef void (PNGAPI *png_progressive_frame_ptr) PNGARG((png_structp, + png_uint_32)); +#endif +#endif + +#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ + defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \ + defined(PNG_LEGACY_SUPPORTED) +typedef void (PNGAPI *png_user_transform_ptr) PNGARG((png_structp, + png_row_infop, png_bytep)); +#endif + +#ifdef PNG_USER_CHUNKS_SUPPORTED +typedef int (PNGAPI *png_user_chunk_ptr) PNGARG((png_structp, png_unknown_chunkp)); +#endif +#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED +typedef void (PNGAPI *png_unknown_chunk_ptr) PNGARG((png_structp)); +#endif + +/* Transform masks for the high-level interface */ +#define PNG_TRANSFORM_IDENTITY 0x0000 /* read and write */ +#define PNG_TRANSFORM_STRIP_16 0x0001 /* read only */ +#define PNG_TRANSFORM_STRIP_ALPHA 0x0002 /* read only */ +#define PNG_TRANSFORM_PACKING 0x0004 /* read and write */ +#define PNG_TRANSFORM_PACKSWAP 0x0008 /* read and write */ +#define PNG_TRANSFORM_EXPAND 0x0010 /* read only */ +#define PNG_TRANSFORM_INVERT_MONO 0x0020 /* read and write */ +#define PNG_TRANSFORM_SHIFT 0x0040 /* read and write */ +#define PNG_TRANSFORM_BGR 0x0080 /* read and write */ +#define PNG_TRANSFORM_SWAP_ALPHA 0x0100 /* read and write */ +#define PNG_TRANSFORM_SWAP_ENDIAN 0x0200 /* read and write */ +#define PNG_TRANSFORM_INVERT_ALPHA 0x0400 /* read and write */ +#define PNG_TRANSFORM_STRIP_FILLER 0x0800 /* write only, deprecated */ +/* Added to libpng-1.2.34 */ +#define PNG_TRANSFORM_STRIP_FILLER_BEFORE 0x0800 /* write only */ +#define PNG_TRANSFORM_STRIP_FILLER_AFTER 0x1000 /* write only */ +/* Added to libpng-1.2.41 */ +#define PNG_TRANSFORM_GRAY_TO_RGB 0x2000 /* read only */ + +/* Flags for MNG supported features */ +#define PNG_FLAG_MNG_EMPTY_PLTE 0x01 +#define PNG_FLAG_MNG_FILTER_64 0x04 +#define PNG_ALL_MNG_FEATURES 0x05 + +typedef png_voidp (*png_malloc_ptr) PNGARG((png_structp, png_size_t)); +typedef void (*png_free_ptr) PNGARG((png_structp, png_voidp)); + +/* The structure that holds the information to read and write PNG files. + * The only people who need to care about what is inside of this are the + * people who will be modifying the library for their own special needs. + * It should NOT be accessed directly by an application, except to store + * the jmp_buf. + */ + +struct png_struct_def +{ +#ifdef PNG_SETJMP_SUPPORTED + jmp_buf jmpbuf; /* used in png_error */ +#endif + png_error_ptr error_fn PNG_DEPSTRUCT; /* function for printing errors and aborting */ + png_error_ptr warning_fn PNG_DEPSTRUCT; /* function for printing warnings */ + png_voidp error_ptr PNG_DEPSTRUCT; /* user supplied struct for error functions */ + png_rw_ptr write_data_fn PNG_DEPSTRUCT; /* function for writing output data */ + png_rw_ptr read_data_fn PNG_DEPSTRUCT; /* function for reading input data */ + png_voidp io_ptr PNG_DEPSTRUCT; /* ptr to application struct for I/O functions */ + +#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED + png_user_transform_ptr read_user_transform_fn PNG_DEPSTRUCT; /* user read transform */ +#endif + +#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED + png_user_transform_ptr write_user_transform_fn PNG_DEPSTRUCT; /* user write transform */ +#endif + +/* These were added in libpng-1.0.2 */ +#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED +#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ + defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) + png_voidp user_transform_ptr PNG_DEPSTRUCT; /* user supplied struct for user transform */ + png_byte user_transform_depth PNG_DEPSTRUCT; /* bit depth of user transformed pixels */ + png_byte user_transform_channels PNG_DEPSTRUCT; /* channels in user transformed pixels */ +#endif +#endif + + png_uint_32 mode PNG_DEPSTRUCT; /* tells us where we are in the PNG file */ + png_uint_32 flags PNG_DEPSTRUCT; /* flags indicating various things to libpng */ + png_uint_32 transformations PNG_DEPSTRUCT; /* which transformations to perform */ + + z_stream zstream PNG_DEPSTRUCT; /* pointer to decompression structure (below) */ + png_bytep zbuf PNG_DEPSTRUCT; /* buffer for zlib */ + png_size_t zbuf_size PNG_DEPSTRUCT; /* size of zbuf */ + int zlib_level PNG_DEPSTRUCT; /* holds zlib compression level */ + int zlib_method PNG_DEPSTRUCT; /* holds zlib compression method */ + int zlib_window_bits PNG_DEPSTRUCT; /* holds zlib compression window bits */ + int zlib_mem_level PNG_DEPSTRUCT; /* holds zlib compression memory level */ + int zlib_strategy PNG_DEPSTRUCT; /* holds zlib compression strategy */ + + png_uint_32 width PNG_DEPSTRUCT; /* width of image in pixels */ + png_uint_32 height PNG_DEPSTRUCT; /* height of image in pixels */ + png_uint_32 num_rows PNG_DEPSTRUCT; /* number of rows in current pass */ + png_uint_32 usr_width PNG_DEPSTRUCT; /* width of row at start of write */ + png_uint_32 rowbytes PNG_DEPSTRUCT; /* size of row in bytes */ +#if 1 /* Replaced with the following in libpng-1.2.43 */ + png_size_t irowbytes PNG_DEPSTRUCT; +#endif +/* Added in libpng-1.2.43 */ +#ifdef PNG_USER_LIMITS_SUPPORTED + /* Added in libpng-1.4.0: Total number of sPLT, text, and unknown + * chunks that can be stored (0 means unlimited). + */ + png_uint_32 user_chunk_cache_max PNG_DEPSTRUCT; +#endif + png_uint_32 iwidth PNG_DEPSTRUCT; /* width of current interlaced row in pixels */ + png_uint_32 row_number PNG_DEPSTRUCT; /* current row in interlace pass */ + png_bytep prev_row PNG_DEPSTRUCT; /* buffer to save previous (unfiltered) row */ + png_bytep row_buf PNG_DEPSTRUCT; /* buffer to save current (unfiltered) row */ +#ifndef PNG_NO_WRITE_FILTER + png_bytep sub_row PNG_DEPSTRUCT; /* buffer to save "sub" row when filtering */ + png_bytep up_row PNG_DEPSTRUCT; /* buffer to save "up" row when filtering */ + png_bytep avg_row PNG_DEPSTRUCT; /* buffer to save "avg" row when filtering */ + png_bytep paeth_row PNG_DEPSTRUCT; /* buffer to save "Paeth" row when filtering */ +#endif + png_row_info row_info PNG_DEPSTRUCT; /* used for transformation routines */ + + png_uint_32 idat_size PNG_DEPSTRUCT; /* current IDAT size for read */ + png_uint_32 crc PNG_DEPSTRUCT; /* current chunk CRC value */ + png_colorp palette PNG_DEPSTRUCT; /* palette from the input file */ + png_uint_16 num_palette PNG_DEPSTRUCT; /* number of color entries in palette */ + png_uint_16 num_trans PNG_DEPSTRUCT; /* number of transparency values */ + png_byte chunk_name[5] PNG_DEPSTRUCT; /* null-terminated name of current chunk */ + png_byte compression PNG_DEPSTRUCT; /* file compression type (always 0) */ + png_byte filter PNG_DEPSTRUCT; /* file filter type (always 0) */ + png_byte interlaced PNG_DEPSTRUCT; /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */ + png_byte pass PNG_DEPSTRUCT; /* current interlace pass (0 - 6) */ + png_byte do_filter PNG_DEPSTRUCT; /* row filter flags (see PNG_FILTER_ below ) */ + png_byte color_type PNG_DEPSTRUCT; /* color type of file */ + png_byte bit_depth PNG_DEPSTRUCT; /* bit depth of file */ + png_byte usr_bit_depth PNG_DEPSTRUCT; /* bit depth of users row */ + png_byte pixel_depth PNG_DEPSTRUCT; /* number of bits per pixel */ + png_byte channels PNG_DEPSTRUCT; /* number of channels in file */ + png_byte usr_channels PNG_DEPSTRUCT; /* channels at start of write */ + png_byte sig_bytes PNG_DEPSTRUCT; /* magic bytes read/written from start of file */ + +#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED) +#ifdef PNG_LEGACY_SUPPORTED + png_byte filler PNG_DEPSTRUCT; /* filler byte for pixel expansion */ +#else + png_uint_16 filler PNG_DEPSTRUCT; /* filler bytes for pixel expansion */ +#endif +#endif + +#ifdef PNG_bKGD_SUPPORTED + png_byte background_gamma_type PNG_DEPSTRUCT; +# ifdef PNG_FLOATING_POINT_SUPPORTED + float background_gamma PNG_DEPSTRUCT; +# endif + png_color_16 background PNG_DEPSTRUCT; /* background color in screen gamma space */ +#ifdef PNG_READ_GAMMA_SUPPORTED + png_color_16 background_1 PNG_DEPSTRUCT; /* background normalized to gamma 1.0 */ +#endif +#endif /* PNG_bKGD_SUPPORTED */ + +#ifdef PNG_WRITE_FLUSH_SUPPORTED + png_flush_ptr output_flush_fn PNG_DEPSTRUCT; /* Function for flushing output */ + png_uint_32 flush_dist PNG_DEPSTRUCT; /* how many rows apart to flush, 0 - no flush */ + png_uint_32 flush_rows PNG_DEPSTRUCT; /* number of rows written since last flush */ +#endif + +#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) + int gamma_shift PNG_DEPSTRUCT; /* number of "insignificant" bits 16-bit gamma */ +#ifdef PNG_FLOATING_POINT_SUPPORTED + float gamma PNG_DEPSTRUCT; /* file gamma value */ + float screen_gamma PNG_DEPSTRUCT; /* screen gamma value (display_exponent) */ +#endif +#endif + +#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) + png_bytep gamma_table PNG_DEPSTRUCT; /* gamma table for 8-bit depth files */ + png_bytep gamma_from_1 PNG_DEPSTRUCT; /* converts from 1.0 to screen */ + png_bytep gamma_to_1 PNG_DEPSTRUCT; /* converts from file to 1.0 */ + png_uint_16pp gamma_16_table PNG_DEPSTRUCT; /* gamma table for 16-bit depth files */ + png_uint_16pp gamma_16_from_1 PNG_DEPSTRUCT; /* converts from 1.0 to screen */ + png_uint_16pp gamma_16_to_1 PNG_DEPSTRUCT; /* converts from file to 1.0 */ +#endif + +#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_sBIT_SUPPORTED) + png_color_8 sig_bit PNG_DEPSTRUCT; /* significant bits in each available channel */ +#endif + +#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED) + png_color_8 shift PNG_DEPSTRUCT; /* shift for significant bit tranformation */ +#endif + +#if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \ + || defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) + png_bytep trans PNG_DEPSTRUCT; /* transparency values for paletted files */ + png_color_16 trans_values PNG_DEPSTRUCT; /* transparency values for non-paletted files */ +#endif + + png_read_status_ptr read_row_fn PNG_DEPSTRUCT; /* called after each row is decoded */ + png_write_status_ptr write_row_fn PNG_DEPSTRUCT; /* called after each row is encoded */ +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED + png_progressive_info_ptr info_fn PNG_DEPSTRUCT; /* called after header data fully read */ + png_progressive_row_ptr row_fn PNG_DEPSTRUCT; /* called after each prog. row is decoded */ + png_progressive_end_ptr end_fn PNG_DEPSTRUCT; /* called after image is complete */ + png_bytep save_buffer_ptr PNG_DEPSTRUCT; /* current location in save_buffer */ + png_bytep save_buffer PNG_DEPSTRUCT; /* buffer for previously read data */ + png_bytep current_buffer_ptr PNG_DEPSTRUCT; /* current location in current_buffer */ + png_bytep current_buffer PNG_DEPSTRUCT; /* buffer for recently used data */ + png_uint_32 push_length PNG_DEPSTRUCT; /* size of current input chunk */ + png_uint_32 skip_length PNG_DEPSTRUCT; /* bytes to skip in input data */ + png_size_t save_buffer_size PNG_DEPSTRUCT; /* amount of data now in save_buffer */ + png_size_t save_buffer_max PNG_DEPSTRUCT; /* total size of save_buffer */ + png_size_t buffer_size PNG_DEPSTRUCT; /* total amount of available input data */ + png_size_t current_buffer_size PNG_DEPSTRUCT; /* amount of data now in current_buffer */ + int process_mode PNG_DEPSTRUCT; /* what push library is currently doing */ + int cur_palette PNG_DEPSTRUCT; /* current push library palette index */ + +# ifdef PNG_TEXT_SUPPORTED + png_size_t current_text_size PNG_DEPSTRUCT; /* current size of text input data */ + png_size_t current_text_left PNG_DEPSTRUCT; /* how much text left to read in input */ + png_charp current_text PNG_DEPSTRUCT; /* current text chunk buffer */ + png_charp current_text_ptr PNG_DEPSTRUCT; /* current location in current_text */ +# endif /* PNG_TEXT_SUPPORTED */ +#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ + +#if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__) +/* for the Borland special 64K segment handler */ + png_bytepp offset_table_ptr PNG_DEPSTRUCT; + png_bytep offset_table PNG_DEPSTRUCT; + png_uint_16 offset_table_number PNG_DEPSTRUCT; + png_uint_16 offset_table_count PNG_DEPSTRUCT; + png_uint_16 offset_table_count_free PNG_DEPSTRUCT; +#endif + +#ifdef PNG_READ_DITHER_SUPPORTED + png_bytep palette_lookup PNG_DEPSTRUCT; /* lookup table for dithering */ + png_bytep dither_index PNG_DEPSTRUCT; /* index translation for palette files */ +#endif + +#if defined(PNG_READ_DITHER_SUPPORTED) || defined(PNG_hIST_SUPPORTED) + png_uint_16p hist PNG_DEPSTRUCT; /* histogram */ +#endif + +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED + png_byte heuristic_method PNG_DEPSTRUCT; /* heuristic for row filter selection */ + png_byte num_prev_filters PNG_DEPSTRUCT; /* number of weights for previous rows */ + png_bytep prev_filters PNG_DEPSTRUCT; /* filter type(s) of previous row(s) */ + png_uint_16p filter_weights PNG_DEPSTRUCT; /* weight(s) for previous line(s) */ + png_uint_16p inv_filter_weights PNG_DEPSTRUCT; /* 1/weight(s) for previous line(s) */ + png_uint_16p filter_costs PNG_DEPSTRUCT; /* relative filter calculation cost */ + png_uint_16p inv_filter_costs PNG_DEPSTRUCT; /* 1/relative filter calculation cost */ +#endif + +#ifdef PNG_TIME_RFC1123_SUPPORTED + png_charp time_buffer PNG_DEPSTRUCT; /* String to hold RFC 1123 time text */ +#endif + +/* New members added in libpng-1.0.6 */ + +#ifdef PNG_FREE_ME_SUPPORTED + png_uint_32 free_me PNG_DEPSTRUCT; /* flags items libpng is responsible for freeing */ +#endif + +#ifdef PNG_USER_CHUNKS_SUPPORTED + png_voidp user_chunk_ptr PNG_DEPSTRUCT; + png_user_chunk_ptr read_user_chunk_fn PNG_DEPSTRUCT; /* user read chunk handler */ +#endif + +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED + int num_chunk_list PNG_DEPSTRUCT; + png_bytep chunk_list PNG_DEPSTRUCT; +#endif + +/* New members added in libpng-1.0.3 */ +#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED + png_byte rgb_to_gray_status PNG_DEPSTRUCT; + /* These were changed from png_byte in libpng-1.0.6 */ + png_uint_16 rgb_to_gray_red_coeff PNG_DEPSTRUCT; + png_uint_16 rgb_to_gray_green_coeff PNG_DEPSTRUCT; + png_uint_16 rgb_to_gray_blue_coeff PNG_DEPSTRUCT; +#endif + +/* New member added in libpng-1.0.4 (renamed in 1.0.9) */ +#if defined(PNG_MNG_FEATURES_SUPPORTED) || \ + defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \ + defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED) +/* Changed from png_byte to png_uint_32 at version 1.2.0 */ +#ifdef PNG_1_0_X + png_byte mng_features_permitted PNG_DEPSTRUCT; +#else + png_uint_32 mng_features_permitted PNG_DEPSTRUCT; +#endif /* PNG_1_0_X */ +#endif + +/* New member added in libpng-1.0.7 */ +#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) + png_fixed_point int_gamma PNG_DEPSTRUCT; +#endif + +/* New member added in libpng-1.0.9, ifdef'ed out in 1.0.12, enabled in 1.2.0 */ +#ifdef PNG_MNG_FEATURES_SUPPORTED + png_byte filter_type PNG_DEPSTRUCT; +#endif + +#ifdef PNG_1_0_X +/* New member added in libpng-1.0.10, ifdef'ed out in 1.2.0 */ + png_uint_32 row_buf_size PNG_DEPSTRUCT; +#endif + +/* New members added in libpng-1.2.0 */ +#ifdef PNG_ASSEMBLER_CODE_SUPPORTED +# ifndef PNG_1_0_X +# ifdef PNG_MMX_CODE_SUPPORTED + png_byte mmx_bitdepth_threshold PNG_DEPSTRUCT; + png_uint_32 mmx_rowbytes_threshold PNG_DEPSTRUCT; +# endif + png_uint_32 asm_flags PNG_DEPSTRUCT; +# endif +#endif + +/* New members added in libpng-1.0.2 but first enabled by default in 1.2.0 */ +#ifdef PNG_USER_MEM_SUPPORTED + png_voidp mem_ptr PNG_DEPSTRUCT; /* user supplied struct for mem functions */ + png_malloc_ptr malloc_fn PNG_DEPSTRUCT; /* function for allocating memory */ + png_free_ptr free_fn PNG_DEPSTRUCT; /* function for freeing memory */ +#endif + +/* New member added in libpng-1.0.13 and 1.2.0 */ + png_bytep big_row_buf PNG_DEPSTRUCT; /* buffer to save current (unfiltered) row */ + +#ifdef PNG_READ_DITHER_SUPPORTED +/* The following three members were added at version 1.0.14 and 1.2.4 */ + png_bytep dither_sort PNG_DEPSTRUCT; /* working sort array */ + png_bytep index_to_palette PNG_DEPSTRUCT; /* where the original index currently is */ + /* in the palette */ + png_bytep palette_to_index PNG_DEPSTRUCT; /* which original index points to this */ + /* palette color */ +#endif + +/* New members added in libpng-1.0.16 and 1.2.6 */ + png_byte compression_type PNG_DEPSTRUCT; + +#ifdef PNG_USER_LIMITS_SUPPORTED + png_uint_32 user_width_max PNG_DEPSTRUCT; + png_uint_32 user_height_max PNG_DEPSTRUCT; +#endif + +#if defined(PNG_APNG_SUPPORTED) + png_uint_32 apng_flags; + png_uint_32 next_seq_num; /* next fcTL/fdAT chunk sequence number */ + png_uint_32 first_frame_width; + png_uint_32 first_frame_height; + +#if defined(PNG_READ_APNG_SUPPORTED) + png_uint_32 num_frames_read; /* incremented after all image data of */ + /* a frame is read */ +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED + png_progressive_frame_ptr frame_info_fn; /* frame info read callback */ + png_progressive_frame_ptr frame_end_fn; /* frame data read callback */ +#endif +#endif + +#if defined(PNG_WRITE_APNG_SUPPORTED) + png_uint_32 num_frames_to_write; + png_uint_32 num_frames_written; +#endif +#endif + +/* For png_struct.apng_flags: */ +#define PNG_FIRST_FRAME_HIDDEN 0x0001 + +/* dispose_op flags from inside fcTL */ +#define PNG_DISPOSE_OP_NONE 0x00 +#define PNG_DISPOSE_OP_BACKGROUND 0x01 +#define PNG_DISPOSE_OP_PREVIOUS 0x02 + +/* blend_op flags from inside fcTL */ +#define PNG_BLEND_OP_SOURCE 0x00 +#define PNG_BLEND_OP_OVER 0x01 + +/* New member added in libpng-1.0.25 and 1.2.17 */ +#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED + /* Storage for unknown chunk that the library doesn't recognize. */ + png_unknown_chunk unknown_chunk PNG_DEPSTRUCT; +#endif + +/* New members added in libpng-1.2.26 */ + png_uint_32 old_big_row_buf_size PNG_DEPSTRUCT; + png_uint_32 old_prev_row_size PNG_DEPSTRUCT; + +/* New member added in libpng-1.2.30 */ + png_charp chunkdata PNG_DEPSTRUCT; /* buffer for reading chunk data */ + + +}; + + +/* This triggers a compiler error in png.c, if png.c and png.h + * do not agree upon the version number. + */ +typedef png_structp version_1_2_46; + +typedef png_struct FAR * FAR * png_structpp; + +/* Here are the function definitions most commonly used. This is not + * the place to find out how to use libpng. See libpng.txt for the + * full explanation, see example.c for the summary. This just provides + * a simple one line description of the use of each function. + */ + +/* Returns the version number of the library */ +extern PNG_EXPORT(png_uint_32,png_access_version_number) PNGARG((void)); + +/* Tell lib we have already handled the first magic bytes. + * Handling more than 8 bytes from the beginning of the file is an error. + */ +extern PNG_EXPORT(void,png_set_sig_bytes) PNGARG((png_structp png_ptr, + int num_bytes)); + +/* Check sig[start] through sig[start + num_to_check - 1] to see if it's a + * PNG file. Returns zero if the supplied bytes match the 8-byte PNG + * signature, and non-zero otherwise. Having num_to_check == 0 or + * start > 7 will always fail (ie return non-zero). + */ +extern PNG_EXPORT(int,png_sig_cmp) PNGARG((png_bytep sig, png_size_t start, + png_size_t num_to_check)); + +/* Simple signature checking function. This is the same as calling + * png_check_sig(sig, n) := !png_sig_cmp(sig, 0, n). + */ +extern PNG_EXPORT(int,png_check_sig) PNGARG((png_bytep sig, int num)) PNG_DEPRECATED; + +/* Allocate and initialize png_ptr struct for reading, and any other memory. */ +extern PNG_EXPORT(png_structp,png_create_read_struct) + PNGARG((png_const_charp user_png_ver, png_voidp error_ptr, + png_error_ptr error_fn, png_error_ptr warn_fn)) PNG_ALLOCATED; + +/* Allocate and initialize png_ptr struct for writing, and any other memory */ +extern PNG_EXPORT(png_structp,png_create_write_struct) + PNGARG((png_const_charp user_png_ver, png_voidp error_ptr, + png_error_ptr error_fn, png_error_ptr warn_fn)) PNG_ALLOCATED; + +#ifdef PNG_WRITE_SUPPORTED +extern PNG_EXPORT(png_uint_32,png_get_compression_buffer_size) + PNGARG((png_structp png_ptr)); +#endif + +#ifdef PNG_WRITE_SUPPORTED +extern PNG_EXPORT(void,png_set_compression_buffer_size) + PNGARG((png_structp png_ptr, png_uint_32 size)); +#endif + +/* Reset the compression stream */ +extern PNG_EXPORT(int,png_reset_zstream) PNGARG((png_structp png_ptr)); + +/* New functions added in libpng-1.0.2 (not enabled by default until 1.2.0) */ +#ifdef PNG_USER_MEM_SUPPORTED +extern PNG_EXPORT(png_structp,png_create_read_struct_2) + PNGARG((png_const_charp user_png_ver, png_voidp error_ptr, + png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr, + png_malloc_ptr malloc_fn, png_free_ptr free_fn)) PNG_ALLOCATED; +extern PNG_EXPORT(png_structp,png_create_write_struct_2) + PNGARG((png_const_charp user_png_ver, png_voidp error_ptr, + png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr, + png_malloc_ptr malloc_fn, png_free_ptr free_fn)) PNG_ALLOCATED; +#endif + +/* Write a PNG chunk - size, type, (optional) data, CRC. */ +extern PNG_EXPORT(void,png_write_chunk) PNGARG((png_structp png_ptr, + png_bytep chunk_name, png_bytep data, png_size_t length)); + +/* Write the start of a PNG chunk - length and chunk name. */ +extern PNG_EXPORT(void,png_write_chunk_start) PNGARG((png_structp png_ptr, + png_bytep chunk_name, png_uint_32 length)); + +/* Write the data of a PNG chunk started with png_write_chunk_start(). */ +extern PNG_EXPORT(void,png_write_chunk_data) PNGARG((png_structp png_ptr, + png_bytep data, png_size_t length)); + +/* Finish a chunk started with png_write_chunk_start() (includes CRC). */ +extern PNG_EXPORT(void,png_write_chunk_end) PNGARG((png_structp png_ptr)); + +/* Allocate and initialize the info structure */ +extern PNG_EXPORT(png_infop,png_create_info_struct) + PNGARG((png_structp png_ptr)) PNG_ALLOCATED; + +#if defined(PNG_1_0_X) || defined (PNG_1_2_X) +/* Initialize the info structure (old interface - DEPRECATED) */ +extern PNG_EXPORT(void,png_info_init) PNGARG((png_infop info_ptr)) + PNG_DEPRECATED; +#undef png_info_init +#define png_info_init(info_ptr) png_info_init_3(&info_ptr,\ + png_sizeof(png_info)); +#endif + +extern PNG_EXPORT(void,png_info_init_3) PNGARG((png_infopp info_ptr, + png_size_t png_info_struct_size)); + +/* Writes all the PNG information before the image. */ +extern PNG_EXPORT(void,png_write_info_before_PLTE) PNGARG((png_structp png_ptr, + png_infop info_ptr)); +extern PNG_EXPORT(void,png_write_info) PNGARG((png_structp png_ptr, + png_infop info_ptr)); + +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED +/* Read the information before the actual image data. */ +extern PNG_EXPORT(void,png_read_info) PNGARG((png_structp png_ptr, + png_infop info_ptr)); +#endif + +#ifdef PNG_TIME_RFC1123_SUPPORTED +extern PNG_EXPORT(png_charp,png_convert_to_rfc1123) + PNGARG((png_structp png_ptr, png_timep ptime)); +#endif + +#ifdef PNG_CONVERT_tIME_SUPPORTED +/* Convert from a struct tm to png_time */ +extern PNG_EXPORT(void,png_convert_from_struct_tm) PNGARG((png_timep ptime, + struct tm FAR * ttime)); + +/* Convert from time_t to png_time. Uses gmtime() */ +extern PNG_EXPORT(void,png_convert_from_time_t) PNGARG((png_timep ptime, + time_t ttime)); +#endif /* PNG_CONVERT_tIME_SUPPORTED */ + +#ifdef PNG_READ_EXPAND_SUPPORTED +/* Expand data to 24-bit RGB, or 8-bit grayscale, with alpha if available. */ +extern PNG_EXPORT(void,png_set_expand) PNGARG((png_structp png_ptr)); +#ifndef PNG_1_0_X +extern PNG_EXPORT(void,png_set_expand_gray_1_2_4_to_8) PNGARG((png_structp + png_ptr)); +#endif +extern PNG_EXPORT(void,png_set_palette_to_rgb) PNGARG((png_structp png_ptr)); +extern PNG_EXPORT(void,png_set_tRNS_to_alpha) PNGARG((png_structp png_ptr)); +#if defined(PNG_1_0_X) || defined (PNG_1_2_X) +/* Deprecated */ +extern PNG_EXPORT(void,png_set_gray_1_2_4_to_8) PNGARG((png_structp + png_ptr)) PNG_DEPRECATED; +#endif +#endif + +#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED) +/* Use blue, green, red order for pixels. */ +extern PNG_EXPORT(void,png_set_bgr) PNGARG((png_structp png_ptr)); +#endif + +#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED +/* Expand the grayscale to 24-bit RGB if necessary. */ +extern PNG_EXPORT(void,png_set_gray_to_rgb) PNGARG((png_structp png_ptr)); +#endif + +#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED +/* Reduce RGB to grayscale. */ +#ifdef PNG_FLOATING_POINT_SUPPORTED +extern PNG_EXPORT(void,png_set_rgb_to_gray) PNGARG((png_structp png_ptr, + int error_action, double red, double green )); +#endif +extern PNG_EXPORT(void,png_set_rgb_to_gray_fixed) PNGARG((png_structp png_ptr, + int error_action, png_fixed_point red, png_fixed_point green )); +extern PNG_EXPORT(png_byte,png_get_rgb_to_gray_status) PNGARG((png_structp + png_ptr)); +#endif + +extern PNG_EXPORT(void,png_build_grayscale_palette) PNGARG((int bit_depth, + png_colorp palette)); + +#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED +extern PNG_EXPORT(void,png_set_strip_alpha) PNGARG((png_structp png_ptr)); +#endif + +#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \ + defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED) +extern PNG_EXPORT(void,png_set_swap_alpha) PNGARG((png_structp png_ptr)); +#endif + +#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \ + defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED) +extern PNG_EXPORT(void,png_set_invert_alpha) PNGARG((png_structp png_ptr)); +#endif + +#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED) +/* Add a filler byte to 8-bit Gray or 24-bit RGB images. */ +extern PNG_EXPORT(void,png_set_filler) PNGARG((png_structp png_ptr, + png_uint_32 filler, int flags)); +/* The values of the PNG_FILLER_ defines should NOT be changed */ +#define PNG_FILLER_BEFORE 0 +#define PNG_FILLER_AFTER 1 +/* Add an alpha byte to 8-bit Gray or 24-bit RGB images. */ +#ifndef PNG_1_0_X +extern PNG_EXPORT(void,png_set_add_alpha) PNGARG((png_structp png_ptr, + png_uint_32 filler, int flags)); +#endif +#endif /* PNG_READ_FILLER_SUPPORTED || PNG_WRITE_FILLER_SUPPORTED */ + +#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED) +/* Swap bytes in 16-bit depth files. */ +extern PNG_EXPORT(void,png_set_swap) PNGARG((png_structp png_ptr)); +#endif + +#if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED) +/* Use 1 byte per pixel in 1, 2, or 4-bit depth files. */ +extern PNG_EXPORT(void,png_set_packing) PNGARG((png_structp png_ptr)); +#endif + +#if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED) +/* Swap packing order of pixels in bytes. */ +extern PNG_EXPORT(void,png_set_packswap) PNGARG((png_structp png_ptr)); +#endif + +#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED) +/* Converts files to legal bit depths. */ +extern PNG_EXPORT(void,png_set_shift) PNGARG((png_structp png_ptr, + png_color_8p true_bits)); +#endif + +#if defined(PNG_READ_INTERLACING_SUPPORTED) || \ + defined(PNG_WRITE_INTERLACING_SUPPORTED) +/* Have the code handle the interlacing. Returns the number of passes. */ +extern PNG_EXPORT(int,png_set_interlace_handling) PNGARG((png_structp png_ptr)); +#endif + +#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED) +/* Invert monochrome files */ +extern PNG_EXPORT(void,png_set_invert_mono) PNGARG((png_structp png_ptr)); +#endif + +#ifdef PNG_READ_BACKGROUND_SUPPORTED +/* Handle alpha and tRNS by replacing with a background color. */ +#ifdef PNG_FLOATING_POINT_SUPPORTED +extern PNG_EXPORT(void,png_set_background) PNGARG((png_structp png_ptr, + png_color_16p background_color, int background_gamma_code, + int need_expand, double background_gamma)); +#endif +#define PNG_BACKGROUND_GAMMA_UNKNOWN 0 +#define PNG_BACKGROUND_GAMMA_SCREEN 1 +#define PNG_BACKGROUND_GAMMA_FILE 2 +#define PNG_BACKGROUND_GAMMA_UNIQUE 3 +#endif + +#ifdef PNG_READ_16_TO_8_SUPPORTED +/* Strip the second byte of information from a 16-bit depth file. */ +extern PNG_EXPORT(void,png_set_strip_16) PNGARG((png_structp png_ptr)); +#endif + +#ifdef PNG_READ_DITHER_SUPPORTED +/* Turn on dithering, and reduce the palette to the number of colors available. */ +extern PNG_EXPORT(void,png_set_dither) PNGARG((png_structp png_ptr, + png_colorp palette, int num_palette, int maximum_colors, + png_uint_16p histogram, int full_dither)); +#endif + +#ifdef PNG_READ_GAMMA_SUPPORTED +/* Handle gamma correction. Screen_gamma=(display_exponent) */ +#ifdef PNG_FLOATING_POINT_SUPPORTED +extern PNG_EXPORT(void,png_set_gamma) PNGARG((png_structp png_ptr, + double screen_gamma, double default_file_gamma)); +#endif +#endif + +#if defined(PNG_1_0_X) || defined (PNG_1_2_X) +#if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \ + defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED) +/* Permit or disallow empty PLTE (0: not permitted, 1: permitted) */ +/* Deprecated and will be removed. Use png_permit_mng_features() instead. */ +extern PNG_EXPORT(void,png_permit_empty_plte) PNGARG((png_structp png_ptr, + int empty_plte_permitted)) PNG_DEPRECATED; +#endif +#endif + +#ifdef PNG_WRITE_FLUSH_SUPPORTED +/* Set how many lines between output flushes - 0 for no flushing */ +extern PNG_EXPORT(void,png_set_flush) PNGARG((png_structp png_ptr, int nrows)); +/* Flush the current PNG output buffer */ +extern PNG_EXPORT(void,png_write_flush) PNGARG((png_structp png_ptr)); +#endif + +/* Optional update palette with requested transformations */ +extern PNG_EXPORT(void,png_start_read_image) PNGARG((png_structp png_ptr)); + +/* Optional call to update the users info structure */ +extern PNG_EXPORT(void,png_read_update_info) PNGARG((png_structp png_ptr, + png_infop info_ptr)); + +#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED +/* Read one or more rows of image data. */ +extern PNG_EXPORT(void,png_read_rows) PNGARG((png_structp png_ptr, + png_bytepp row, png_bytepp display_row, png_uint_32 num_rows)); +#endif + +#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED +/* Read a row of data. */ +extern PNG_EXPORT(void,png_read_row) PNGARG((png_structp png_ptr, + png_bytep row, + png_bytep display_row)); +#endif + +#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED +/* Read the whole image into memory at once. */ +extern PNG_EXPORT(void,png_read_image) PNGARG((png_structp png_ptr, + png_bytepp image)); +#endif + +/* Write a row of image data */ +extern PNG_EXPORT(void,png_write_row) PNGARG((png_structp png_ptr, + png_bytep row)); + +/* Write a few rows of image data */ +extern PNG_EXPORT(void,png_write_rows) PNGARG((png_structp png_ptr, + png_bytepp row, png_uint_32 num_rows)); + +/* Write the image data */ +extern PNG_EXPORT(void,png_write_image) PNGARG((png_structp png_ptr, + png_bytepp image)); + +#if defined(PNG_WRITE_APNG_SUPPORTED) +extern PNG_EXPORT (void,png_write_frame_head) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_bytepp row_pointers, + png_uint_32 width, png_uint_32 height, + png_uint_32 x_offset, png_uint_32 y_offset, + png_uint_16 delay_num, png_uint_16 delay_den, png_byte dispose_op, + png_byte blend_op)); + +extern PNG_EXPORT (void,png_write_frame_tail) PNGARG((png_structp png_ptr, + png_infop info_ptr)); +#endif + +/* Writes the end of the PNG file. */ +extern PNG_EXPORT(void,png_write_end) PNGARG((png_structp png_ptr, + png_infop info_ptr)); + +#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED +/* Read the end of the PNG file. */ +extern PNG_EXPORT(void,png_read_end) PNGARG((png_structp png_ptr, + png_infop info_ptr)); +#endif + +/* Free any memory associated with the png_info_struct */ +extern PNG_EXPORT(void,png_destroy_info_struct) PNGARG((png_structp png_ptr, + png_infopp info_ptr_ptr)); + +/* Free any memory associated with the png_struct and the png_info_structs */ +extern PNG_EXPORT(void,png_destroy_read_struct) PNGARG((png_structpp + png_ptr_ptr, png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr)); + +/* Free all memory used by the read (old method - NOT DLL EXPORTED) */ +extern void png_read_destroy PNGARG((png_structp png_ptr, png_infop info_ptr, + png_infop end_info_ptr)) PNG_DEPRECATED; + +/* Free any memory associated with the png_struct and the png_info_structs */ +extern PNG_EXPORT(void,png_destroy_write_struct) + PNGARG((png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)); + +/* Free any memory used in png_ptr struct (old method - NOT DLL EXPORTED) */ +extern void png_write_destroy PNGARG((png_structp png_ptr)) PNG_DEPRECATED; + +/* Set the libpng method of handling chunk CRC errors */ +extern PNG_EXPORT(void,png_set_crc_action) PNGARG((png_structp png_ptr, + int crit_action, int ancil_action)); + +/* Values for png_set_crc_action() to say how to handle CRC errors in + * ancillary and critical chunks, and whether to use the data contained + * therein. Note that it is impossible to "discard" data in a critical + * chunk. For versions prior to 0.90, the action was always error/quit, + * whereas in version 0.90 and later, the action for CRC errors in ancillary + * chunks is warn/discard. These values should NOT be changed. + * + * value action:critical action:ancillary + */ +#define PNG_CRC_DEFAULT 0 /* error/quit warn/discard data */ +#define PNG_CRC_ERROR_QUIT 1 /* error/quit error/quit */ +#define PNG_CRC_WARN_DISCARD 2 /* (INVALID) warn/discard data */ +#define PNG_CRC_WARN_USE 3 /* warn/use data warn/use data */ +#define PNG_CRC_QUIET_USE 4 /* quiet/use data quiet/use data */ +#define PNG_CRC_NO_CHANGE 5 /* use current value use current value */ + +/* These functions give the user control over the scan-line filtering in + * libpng and the compression methods used by zlib. These functions are + * mainly useful for testing, as the defaults should work with most users. + * Those users who are tight on memory or want faster performance at the + * expense of compression can modify them. See the compression library + * header file (zlib.h) for an explination of the compression functions. + */ + +/* Set the filtering method(s) used by libpng. Currently, the only valid + * value for "method" is 0. + */ +extern PNG_EXPORT(void,png_set_filter) PNGARG((png_structp png_ptr, int method, + int filters)); + +/* Flags for png_set_filter() to say which filters to use. The flags + * are chosen so that they don't conflict with real filter types + * below, in case they are supplied instead of the #defined constants. + * These values should NOT be changed. + */ +#define PNG_NO_FILTERS 0x00 +#define PNG_FILTER_NONE 0x08 +#define PNG_FILTER_SUB 0x10 +#define PNG_FILTER_UP 0x20 +#define PNG_FILTER_AVG 0x40 +#define PNG_FILTER_PAETH 0x80 +#define PNG_ALL_FILTERS (PNG_FILTER_NONE | PNG_FILTER_SUB | PNG_FILTER_UP | \ + PNG_FILTER_AVG | PNG_FILTER_PAETH) + +/* Filter values (not flags) - used in pngwrite.c, pngwutil.c for now. + * These defines should NOT be changed. + */ +#define PNG_FILTER_VALUE_NONE 0 +#define PNG_FILTER_VALUE_SUB 1 +#define PNG_FILTER_VALUE_UP 2 +#define PNG_FILTER_VALUE_AVG 3 +#define PNG_FILTER_VALUE_PAETH 4 +#define PNG_FILTER_VALUE_LAST 5 + +#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* EXPERIMENTAL */ +/* The "heuristic_method" is given by one of the PNG_FILTER_HEURISTIC_ + * defines, either the default (minimum-sum-of-absolute-differences), or + * the experimental method (weighted-minimum-sum-of-absolute-differences). + * + * Weights are factors >= 1.0, indicating how important it is to keep the + * filter type consistent between rows. Larger numbers mean the current + * filter is that many times as likely to be the same as the "num_weights" + * previous filters. This is cumulative for each previous row with a weight. + * There needs to be "num_weights" values in "filter_weights", or it can be + * NULL if the weights aren't being specified. Weights have no influence on + * the selection of the first row filter. Well chosen weights can (in theory) + * improve the compression for a given image. + * + * Costs are factors >= 1.0 indicating the relative decoding costs of a + * filter type. Higher costs indicate more decoding expense, and are + * therefore less likely to be selected over a filter with lower computational + * costs. There needs to be a value in "filter_costs" for each valid filter + * type (given by PNG_FILTER_VALUE_LAST), or it can be NULL if you aren't + * setting the costs. Costs try to improve the speed of decompression without + * unduly increasing the compressed image size. + * + * A negative weight or cost indicates the default value is to be used, and + * values in the range [0.0, 1.0) indicate the value is to remain unchanged. + * The default values for both weights and costs are currently 1.0, but may + * change if good general weighting/cost heuristics can be found. If both + * the weights and costs are set to 1.0, this degenerates the WEIGHTED method + * to the UNWEIGHTED method, but with added encoding time/computation. + */ +#ifdef PNG_FLOATING_POINT_SUPPORTED +extern PNG_EXPORT(void,png_set_filter_heuristics) PNGARG((png_structp png_ptr, + int heuristic_method, int num_weights, png_doublep filter_weights, + png_doublep filter_costs)); +#endif +#endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */ + +/* Heuristic used for row filter selection. These defines should NOT be + * changed. + */ +#define PNG_FILTER_HEURISTIC_DEFAULT 0 /* Currently "UNWEIGHTED" */ +#define PNG_FILTER_HEURISTIC_UNWEIGHTED 1 /* Used by libpng < 0.95 */ +#define PNG_FILTER_HEURISTIC_WEIGHTED 2 /* Experimental feature */ +#define PNG_FILTER_HEURISTIC_LAST 3 /* Not a valid value */ + +/* Set the library compression level. Currently, valid values range from + * 0 - 9, corresponding directly to the zlib compression levels 0 - 9 + * (0 - no compression, 9 - "maximal" compression). Note that tests have + * shown that zlib compression levels 3-6 usually perform as well as level 9 + * for PNG images, and do considerably fewer caclulations. In the future, + * these values may not correspond directly to the zlib compression levels. + */ +extern PNG_EXPORT(void,png_set_compression_level) PNGARG((png_structp png_ptr, + int level)); + +extern PNG_EXPORT(void,png_set_compression_mem_level) + PNGARG((png_structp png_ptr, int mem_level)); + +extern PNG_EXPORT(void,png_set_compression_strategy) + PNGARG((png_structp png_ptr, int strategy)); + +extern PNG_EXPORT(void,png_set_compression_window_bits) + PNGARG((png_structp png_ptr, int window_bits)); + +extern PNG_EXPORT(void,png_set_compression_method) PNGARG((png_structp png_ptr, + int method)); + +/* These next functions are called for input/output, memory, and error + * handling. They are in the file pngrio.c, pngwio.c, and pngerror.c, + * and call standard C I/O routines such as fread(), fwrite(), and + * fprintf(). These functions can be made to use other I/O routines + * at run time for those applications that need to handle I/O in a + * different manner by calling png_set_???_fn(). See libpng.txt for + * more information. + */ + +#ifdef PNG_STDIO_SUPPORTED +/* Initialize the input/output for the PNG file to the default functions. */ +extern PNG_EXPORT(void,png_init_io) PNGARG((png_structp png_ptr, png_FILE_p fp)); +#endif + +/* Replace the (error and abort), and warning functions with user + * supplied functions. If no messages are to be printed you must still + * write and use replacement functions. The replacement error_fn should + * still do a longjmp to the last setjmp location if you are using this + * method of error handling. If error_fn or warning_fn is NULL, the + * default function will be used. + */ + +extern PNG_EXPORT(void,png_set_error_fn) PNGARG((png_structp png_ptr, + png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warning_fn)); + +/* Return the user pointer associated with the error functions */ +extern PNG_EXPORT(png_voidp,png_get_error_ptr) PNGARG((png_structp png_ptr)); + +/* Replace the default data output functions with a user supplied one(s). + * If buffered output is not used, then output_flush_fn can be set to NULL. + * If PNG_WRITE_FLUSH_SUPPORTED is not defined at libpng compile time + * output_flush_fn will be ignored (and thus can be NULL). + * It is probably a mistake to use NULL for output_flush_fn if + * write_data_fn is not also NULL unless you have built libpng with + * PNG_WRITE_FLUSH_SUPPORTED undefined, because in this case libpng's + * default flush function, which uses the standard *FILE structure, will + * be used. + */ +extern PNG_EXPORT(void,png_set_write_fn) PNGARG((png_structp png_ptr, + png_voidp io_ptr, png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn)); + +/* Replace the default data input function with a user supplied one. */ +extern PNG_EXPORT(void,png_set_read_fn) PNGARG((png_structp png_ptr, + png_voidp io_ptr, png_rw_ptr read_data_fn)); + +/* Return the user pointer associated with the I/O functions */ +extern PNG_EXPORT(png_voidp,png_get_io_ptr) PNGARG((png_structp png_ptr)); + +extern PNG_EXPORT(void,png_set_read_status_fn) PNGARG((png_structp png_ptr, + png_read_status_ptr read_row_fn)); + +extern PNG_EXPORT(void,png_set_write_status_fn) PNGARG((png_structp png_ptr, + png_write_status_ptr write_row_fn)); + +#ifdef PNG_USER_MEM_SUPPORTED +/* Replace the default memory allocation functions with user supplied one(s). */ +extern PNG_EXPORT(void,png_set_mem_fn) PNGARG((png_structp png_ptr, + png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn)); +/* Return the user pointer associated with the memory functions */ +extern PNG_EXPORT(png_voidp,png_get_mem_ptr) PNGARG((png_structp png_ptr)); +#endif + +#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ + defined(PNG_LEGACY_SUPPORTED) +extern PNG_EXPORT(void,png_set_read_user_transform_fn) PNGARG((png_structp + png_ptr, png_user_transform_ptr read_user_transform_fn)); +#endif + +#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \ + defined(PNG_LEGACY_SUPPORTED) +extern PNG_EXPORT(void,png_set_write_user_transform_fn) PNGARG((png_structp + png_ptr, png_user_transform_ptr write_user_transform_fn)); +#endif + +#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ + defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \ + defined(PNG_LEGACY_SUPPORTED) +extern PNG_EXPORT(void,png_set_user_transform_info) PNGARG((png_structp + png_ptr, png_voidp user_transform_ptr, int user_transform_depth, + int user_transform_channels)); +/* Return the user pointer associated with the user transform functions */ +extern PNG_EXPORT(png_voidp,png_get_user_transform_ptr) + PNGARG((png_structp png_ptr)); +#endif + +#ifdef PNG_USER_CHUNKS_SUPPORTED +extern PNG_EXPORT(void,png_set_read_user_chunk_fn) PNGARG((png_structp png_ptr, + png_voidp user_chunk_ptr, png_user_chunk_ptr read_user_chunk_fn)); +extern PNG_EXPORT(png_voidp,png_get_user_chunk_ptr) PNGARG((png_structp + png_ptr)); +#endif + +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED +/* Sets the function callbacks for the push reader, and a pointer to a + * user-defined structure available to the callback functions. + */ +extern PNG_EXPORT(void,png_set_progressive_read_fn) PNGARG((png_structp png_ptr, + png_voidp progressive_ptr, + png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn, + png_progressive_end_ptr end_fn)); +#if defined(PNG_READ_APNG_SUPPORTED) +extern PNG_EXPORT(void,png_set_progressive_frame_fn) PNGARG((png_structp png_ptr, + png_progressive_frame_ptr frame_info_fn, + png_progressive_frame_ptr frame_end_fn)); +#endif + +/* Returns the user pointer associated with the push read functions */ +extern PNG_EXPORT(png_voidp,png_get_progressive_ptr) + PNGARG((png_structp png_ptr)); + +/* Function to be called when data becomes available */ +extern PNG_EXPORT(void,png_process_data) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_bytep buffer, png_size_t buffer_size)); + +/* Function that combines rows. Not very much different than the + * png_combine_row() call. Is this even used????? + */ +extern PNG_EXPORT(void,png_progressive_combine_row) PNGARG((png_structp png_ptr, + png_bytep old_row, png_bytep new_row)); +#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ + +extern PNG_EXPORT(png_voidp,png_malloc) PNGARG((png_structp png_ptr, + png_uint_32 size)) PNG_ALLOCATED; + +#ifdef PNG_1_0_X +# define png_malloc_warn png_malloc +#else +/* Added at libpng version 1.2.4 */ +extern PNG_EXPORT(png_voidp,png_malloc_warn) PNGARG((png_structp png_ptr, + png_uint_32 size)) PNG_ALLOCATED; +#endif + +/* Frees a pointer allocated by png_malloc() */ +extern PNG_EXPORT(void,png_free) PNGARG((png_structp png_ptr, png_voidp ptr)); + +#ifdef PNG_1_0_X +/* Function to allocate memory for zlib. */ +extern PNG_EXPORT(voidpf,png_zalloc) PNGARG((voidpf png_ptr, uInt items, + uInt size)); + +/* Function to free memory for zlib */ +extern PNG_EXPORT(void,png_zfree) PNGARG((voidpf png_ptr, voidpf ptr)); +#endif + +/* Free data that was allocated internally */ +extern PNG_EXPORT(void,png_free_data) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_uint_32 free_me, int num)); +#ifdef PNG_FREE_ME_SUPPORTED +/* Reassign responsibility for freeing existing data, whether allocated + * by libpng or by the application + */ +extern PNG_EXPORT(void,png_data_freer) PNGARG((png_structp png_ptr, + png_infop info_ptr, int freer, png_uint_32 mask)); +#endif +/* Assignments for png_data_freer */ +#define PNG_DESTROY_WILL_FREE_DATA 1 +#define PNG_SET_WILL_FREE_DATA 1 +#define PNG_USER_WILL_FREE_DATA 2 +/* Flags for png_ptr->free_me and info_ptr->free_me */ +#define PNG_FREE_HIST 0x0008 +#define PNG_FREE_ICCP 0x0010 +#define PNG_FREE_SPLT 0x0020 +#define PNG_FREE_ROWS 0x0040 +#define PNG_FREE_PCAL 0x0080 +#define PNG_FREE_SCAL 0x0100 +#define PNG_FREE_UNKN 0x0200 +#define PNG_FREE_LIST 0x0400 +#define PNG_FREE_PLTE 0x1000 +#define PNG_FREE_TRNS 0x2000 +#define PNG_FREE_TEXT 0x4000 +#define PNG_FREE_ALL 0x7fff +#define PNG_FREE_MUL 0x4220 /* PNG_FREE_SPLT|PNG_FREE_TEXT|PNG_FREE_UNKN */ + +#ifdef PNG_USER_MEM_SUPPORTED +extern PNG_EXPORT(png_voidp,png_malloc_default) PNGARG((png_structp png_ptr, + png_uint_32 size)) PNG_ALLOCATED; +extern PNG_EXPORT(void,png_free_default) PNGARG((png_structp png_ptr, + png_voidp ptr)); +#endif + +extern PNG_EXPORT(png_voidp,png_memcpy_check) PNGARG((png_structp png_ptr, + png_voidp s1, png_voidp s2, png_uint_32 size)) PNG_DEPRECATED; + +extern PNG_EXPORT(png_voidp,png_memset_check) PNGARG((png_structp png_ptr, + png_voidp s1, int value, png_uint_32 size)) PNG_DEPRECATED; + +#if defined(USE_FAR_KEYWORD) /* memory model conversion function */ +extern void *png_far_to_near PNGARG((png_structp png_ptr,png_voidp ptr, + int check)); +#endif /* USE_FAR_KEYWORD */ + +#ifndef PNG_NO_ERROR_TEXT +/* Fatal error in PNG image of libpng - can't continue */ +extern PNG_EXPORT(void,png_error) PNGARG((png_structp png_ptr, + png_const_charp error_message)) PNG_NORETURN; + +/* The same, but the chunk name is prepended to the error string. */ +extern PNG_EXPORT(void,png_chunk_error) PNGARG((png_structp png_ptr, + png_const_charp error_message)) PNG_NORETURN; +#else +/* Fatal error in PNG image of libpng - can't continue */ +extern PNG_EXPORT(void,png_err) PNGARG((png_structp png_ptr)) PNG_NORETURN; +#endif + +#ifndef PNG_NO_WARNINGS +/* Non-fatal error in libpng. Can continue, but may have a problem. */ +extern PNG_EXPORT(void,png_warning) PNGARG((png_structp png_ptr, + png_const_charp warning_message)); + +#ifdef PNG_READ_SUPPORTED +/* Non-fatal error in libpng, chunk name is prepended to message. */ +extern PNG_EXPORT(void,png_chunk_warning) PNGARG((png_structp png_ptr, + png_const_charp warning_message)); +#endif /* PNG_READ_SUPPORTED */ +#endif /* PNG_NO_WARNINGS */ + +/* The png_set_ functions are for storing values in the png_info_struct. + * Similarly, the png_get_ calls are used to read values from the + * png_info_struct, either storing the parameters in the passed variables, or + * setting pointers into the png_info_struct where the data is stored. The + * png_get_ functions return a non-zero value if the data was available + * in info_ptr, or return zero and do not change any of the parameters if the + * data was not available. + * + * These functions should be used instead of directly accessing png_info + * to avoid problems with future changes in the size and internal layout of + * png_info_struct. + */ +/* Returns "flag" if chunk data is valid in info_ptr. */ +extern PNG_EXPORT(png_uint_32,png_get_valid) PNGARG((png_structp png_ptr, +png_infop info_ptr, png_uint_32 flag)); + +/* Returns number of bytes needed to hold a transformed row. */ +extern PNG_EXPORT(png_uint_32,png_get_rowbytes) PNGARG((png_structp png_ptr, +png_infop info_ptr)); + +#ifdef PNG_INFO_IMAGE_SUPPORTED +/* Returns row_pointers, which is an array of pointers to scanlines that was + * returned from png_read_png(). + */ +extern PNG_EXPORT(png_bytepp,png_get_rows) PNGARG((png_structp png_ptr, +png_infop info_ptr)); +/* Set row_pointers, which is an array of pointers to scanlines for use + * by png_write_png(). + */ +extern PNG_EXPORT(void,png_set_rows) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_bytepp row_pointers)); +#endif + +/* Returns number of color channels in image. */ +extern PNG_EXPORT(png_byte,png_get_channels) PNGARG((png_structp png_ptr, +png_infop info_ptr)); + +#ifdef PNG_EASY_ACCESS_SUPPORTED +/* Returns image width in pixels. */ +extern PNG_EXPORT(png_uint_32, png_get_image_width) PNGARG((png_structp +png_ptr, png_infop info_ptr)); + +/* Returns image height in pixels. */ +extern PNG_EXPORT(png_uint_32, png_get_image_height) PNGARG((png_structp +png_ptr, png_infop info_ptr)); + +/* Returns image bit_depth. */ +extern PNG_EXPORT(png_byte, png_get_bit_depth) PNGARG((png_structp +png_ptr, png_infop info_ptr)); + +/* Returns image color_type. */ +extern PNG_EXPORT(png_byte, png_get_color_type) PNGARG((png_structp +png_ptr, png_infop info_ptr)); + +/* Returns image filter_type. */ +extern PNG_EXPORT(png_byte, png_get_filter_type) PNGARG((png_structp +png_ptr, png_infop info_ptr)); + +/* Returns image interlace_type. */ +extern PNG_EXPORT(png_byte, png_get_interlace_type) PNGARG((png_structp +png_ptr, png_infop info_ptr)); + +/* Returns image compression_type. */ +extern PNG_EXPORT(png_byte, png_get_compression_type) PNGARG((png_structp +png_ptr, png_infop info_ptr)); + +/* Returns image resolution in pixels per meter, from pHYs chunk data. */ +extern PNG_EXPORT(png_uint_32, png_get_pixels_per_meter) PNGARG((png_structp +png_ptr, png_infop info_ptr)); +extern PNG_EXPORT(png_uint_32, png_get_x_pixels_per_meter) PNGARG((png_structp +png_ptr, png_infop info_ptr)); +extern PNG_EXPORT(png_uint_32, png_get_y_pixels_per_meter) PNGARG((png_structp +png_ptr, png_infop info_ptr)); + +/* Returns pixel aspect ratio, computed from pHYs chunk data. */ +#ifdef PNG_FLOATING_POINT_SUPPORTED +extern PNG_EXPORT(float, png_get_pixel_aspect_ratio) PNGARG((png_structp +png_ptr, png_infop info_ptr)); +#endif + +/* Returns image x, y offset in pixels or microns, from oFFs chunk data. */ +extern PNG_EXPORT(png_int_32, png_get_x_offset_pixels) PNGARG((png_structp +png_ptr, png_infop info_ptr)); +extern PNG_EXPORT(png_int_32, png_get_y_offset_pixels) PNGARG((png_structp +png_ptr, png_infop info_ptr)); +extern PNG_EXPORT(png_int_32, png_get_x_offset_microns) PNGARG((png_structp +png_ptr, png_infop info_ptr)); +extern PNG_EXPORT(png_int_32, png_get_y_offset_microns) PNGARG((png_structp +png_ptr, png_infop info_ptr)); + +#endif /* PNG_EASY_ACCESS_SUPPORTED */ + +/* Returns pointer to signature string read from PNG header */ +extern PNG_EXPORT(png_bytep,png_get_signature) PNGARG((png_structp png_ptr, +png_infop info_ptr)); + +#ifdef PNG_bKGD_SUPPORTED +extern PNG_EXPORT(png_uint_32,png_get_bKGD) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_color_16p *background)); +#endif + +#ifdef PNG_bKGD_SUPPORTED +extern PNG_EXPORT(void,png_set_bKGD) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_color_16p background)); +#endif + +#ifdef PNG_cHRM_SUPPORTED +#ifdef PNG_FLOATING_POINT_SUPPORTED +extern PNG_EXPORT(png_uint_32,png_get_cHRM) PNGARG((png_structp png_ptr, + png_infop info_ptr, double *white_x, double *white_y, double *red_x, + double *red_y, double *green_x, double *green_y, double *blue_x, + double *blue_y)); +#endif +#ifdef PNG_FIXED_POINT_SUPPORTED +extern PNG_EXPORT(png_uint_32,png_get_cHRM_fixed) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_fixed_point *int_white_x, png_fixed_point + *int_white_y, png_fixed_point *int_red_x, png_fixed_point *int_red_y, + png_fixed_point *int_green_x, png_fixed_point *int_green_y, png_fixed_point + *int_blue_x, png_fixed_point *int_blue_y)); +#endif +#endif + +#ifdef PNG_cHRM_SUPPORTED +#ifdef PNG_FLOATING_POINT_SUPPORTED +extern PNG_EXPORT(void,png_set_cHRM) PNGARG((png_structp png_ptr, + png_infop info_ptr, double white_x, double white_y, double red_x, + double red_y, double green_x, double green_y, double blue_x, double blue_y)); +#endif +#ifdef PNG_FIXED_POINT_SUPPORTED +extern PNG_EXPORT(void,png_set_cHRM_fixed) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_fixed_point int_white_x, png_fixed_point int_white_y, + png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point + int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x, + png_fixed_point int_blue_y)); +#endif +#endif + +#ifdef PNG_gAMA_SUPPORTED +#ifdef PNG_FLOATING_POINT_SUPPORTED +extern PNG_EXPORT(png_uint_32,png_get_gAMA) PNGARG((png_structp png_ptr, + png_infop info_ptr, double *file_gamma)); +#endif +extern PNG_EXPORT(png_uint_32,png_get_gAMA_fixed) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_fixed_point *int_file_gamma)); +#endif + +#ifdef PNG_gAMA_SUPPORTED +#ifdef PNG_FLOATING_POINT_SUPPORTED +extern PNG_EXPORT(void,png_set_gAMA) PNGARG((png_structp png_ptr, + png_infop info_ptr, double file_gamma)); +#endif +extern PNG_EXPORT(void,png_set_gAMA_fixed) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_fixed_point int_file_gamma)); +#endif + +#ifdef PNG_hIST_SUPPORTED +extern PNG_EXPORT(png_uint_32,png_get_hIST) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_uint_16p *hist)); +#endif + +#ifdef PNG_hIST_SUPPORTED +extern PNG_EXPORT(void,png_set_hIST) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_uint_16p hist)); +#endif + +extern PNG_EXPORT(png_uint_32,png_get_IHDR) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_uint_32 *width, png_uint_32 *height, + int *bit_depth, int *color_type, int *interlace_method, + int *compression_method, int *filter_method)); + +extern PNG_EXPORT(void,png_set_IHDR) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_uint_32 width, png_uint_32 height, int bit_depth, + int color_type, int interlace_method, int compression_method, + int filter_method)); + +#ifdef PNG_oFFs_SUPPORTED +extern PNG_EXPORT(png_uint_32,png_get_oFFs) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_int_32 *offset_x, png_int_32 *offset_y, + int *unit_type)); +#endif + +#ifdef PNG_oFFs_SUPPORTED +extern PNG_EXPORT(void,png_set_oFFs) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_int_32 offset_x, png_int_32 offset_y, + int unit_type)); +#endif + +#ifdef PNG_pCAL_SUPPORTED +extern PNG_EXPORT(png_uint_32,png_get_pCAL) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_charp *purpose, png_int_32 *X0, png_int_32 *X1, + int *type, int *nparams, png_charp *units, png_charpp *params)); +#endif + +#ifdef PNG_pCAL_SUPPORTED +extern PNG_EXPORT(void,png_set_pCAL) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_charp purpose, png_int_32 X0, png_int_32 X1, + int type, int nparams, png_charp units, png_charpp params)); +#endif + +#ifdef PNG_pHYs_SUPPORTED +extern PNG_EXPORT(png_uint_32,png_get_pHYs) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)); +#endif + +#ifdef PNG_pHYs_SUPPORTED +extern PNG_EXPORT(void,png_set_pHYs) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_uint_32 res_x, png_uint_32 res_y, int unit_type)); +#endif + +extern PNG_EXPORT(png_uint_32,png_get_PLTE) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_colorp *palette, int *num_palette)); + +extern PNG_EXPORT(void,png_set_PLTE) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_colorp palette, int num_palette)); + +#ifdef PNG_sBIT_SUPPORTED +extern PNG_EXPORT(png_uint_32,png_get_sBIT) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_color_8p *sig_bit)); +#endif + +#ifdef PNG_sBIT_SUPPORTED +extern PNG_EXPORT(void,png_set_sBIT) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_color_8p sig_bit)); +#endif + +#ifdef PNG_sRGB_SUPPORTED +extern PNG_EXPORT(png_uint_32,png_get_sRGB) PNGARG((png_structp png_ptr, + png_infop info_ptr, int *intent)); +#endif + +#ifdef PNG_sRGB_SUPPORTED +extern PNG_EXPORT(void,png_set_sRGB) PNGARG((png_structp png_ptr, + png_infop info_ptr, int intent)); +extern PNG_EXPORT(void,png_set_sRGB_gAMA_and_cHRM) PNGARG((png_structp png_ptr, + png_infop info_ptr, int intent)); +#endif + +#ifdef PNG_iCCP_SUPPORTED +extern PNG_EXPORT(png_uint_32,png_get_iCCP) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_charpp name, int *compression_type, + png_charpp profile, png_uint_32 *proflen)); + /* Note to maintainer: profile should be png_bytepp */ +#endif + +#ifdef PNG_iCCP_SUPPORTED +extern PNG_EXPORT(void,png_set_iCCP) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_charp name, int compression_type, + png_charp profile, png_uint_32 proflen)); + /* Note to maintainer: profile should be png_bytep */ +#endif + +#ifdef PNG_sPLT_SUPPORTED +extern PNG_EXPORT(png_uint_32,png_get_sPLT) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_sPLT_tpp entries)); +#endif + +#ifdef PNG_sPLT_SUPPORTED +extern PNG_EXPORT(void,png_set_sPLT) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_sPLT_tp entries, int nentries)); +#endif + +#ifdef PNG_TEXT_SUPPORTED +/* png_get_text also returns the number of text chunks in *num_text */ +extern PNG_EXPORT(png_uint_32,png_get_text) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_textp *text_ptr, int *num_text)); +#endif + +/* + * Note while png_set_text() will accept a structure whose text, + * language, and translated keywords are NULL pointers, the structure + * returned by png_get_text will always contain regular + * zero-terminated C strings. They might be empty strings but + * they will never be NULL pointers. + */ + +#ifdef PNG_TEXT_SUPPORTED +extern PNG_EXPORT(void,png_set_text) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_textp text_ptr, int num_text)); +#endif + +#ifdef PNG_tIME_SUPPORTED +extern PNG_EXPORT(png_uint_32,png_get_tIME) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_timep *mod_time)); +#endif + +#ifdef PNG_tIME_SUPPORTED +extern PNG_EXPORT(void,png_set_tIME) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_timep mod_time)); +#endif + +#ifdef PNG_tRNS_SUPPORTED +extern PNG_EXPORT(png_uint_32,png_get_tRNS) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_bytep *trans, int *num_trans, + png_color_16p *trans_values)); +#endif + +#ifdef PNG_tRNS_SUPPORTED +extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_bytep trans, int num_trans, + png_color_16p trans_values)); +#endif + +#ifdef PNG_tRNS_SUPPORTED +#endif + +#ifdef PNG_sCAL_SUPPORTED +#ifdef PNG_FLOATING_POINT_SUPPORTED +extern PNG_EXPORT(png_uint_32,png_get_sCAL) PNGARG((png_structp png_ptr, + png_infop info_ptr, int *unit, double *width, double *height)); +#else +#ifdef PNG_FIXED_POINT_SUPPORTED +extern PNG_EXPORT(png_uint_32,png_get_sCAL_s) PNGARG((png_structp png_ptr, + png_infop info_ptr, int *unit, png_charpp swidth, png_charpp sheight)); +#endif +#endif +#endif /* PNG_sCAL_SUPPORTED */ + +#ifdef PNG_sCAL_SUPPORTED +#ifdef PNG_FLOATING_POINT_SUPPORTED +extern PNG_EXPORT(void,png_set_sCAL) PNGARG((png_structp png_ptr, + png_infop info_ptr, int unit, double width, double height)); +#else +#ifdef PNG_FIXED_POINT_SUPPORTED +extern PNG_EXPORT(void,png_set_sCAL_s) PNGARG((png_structp png_ptr, + png_infop info_ptr, int unit, png_charp swidth, png_charp sheight)); +#endif +#endif +#endif /* PNG_sCAL_SUPPORTED || PNG_WRITE_sCAL_SUPPORTED */ + +#if defined(PNG_APNG_SUPPORTED) +extern PNG_EXPORT(png_uint_32,png_get_acTL) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_uint_32 *num_frames, png_uint_32 *num_plays)); +extern PNG_EXPORT(png_uint_32,png_set_acTL) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_uint_32 num_frames, png_uint_32 num_plays)); +extern PNG_EXPORT(png_uint_32,png_get_num_frames) PNGARG((png_structp png_ptr, + png_infop info_ptr)); +extern PNG_EXPORT(png_uint_32,png_get_num_plays) + PNGARG((png_structp png_ptr, png_infop info_ptr)); + +extern PNG_EXPORT(png_uint_32,png_get_next_frame_fcTL) + PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 *width, + png_uint_32 *height, png_uint_32 *x_offset, png_uint_32 *y_offset, + png_uint_16 *delay_num, png_uint_16 *delay_den, png_byte *dispose_op, + png_byte *blend_op)); +extern PNG_EXPORT(png_uint_32,png_set_next_frame_fcTL) + PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 width, + png_uint_32 height, png_uint_32 x_offset, png_uint_32 y_offset, + png_uint_16 delay_num, png_uint_16 delay_den, png_byte dispose_op, + png_byte blend_op)); +extern PNG_EXPORT(void,png_ensure_fcTL_is_valid) + PNGARG((png_structp png_ptr, + png_uint_32 width, png_uint_32 height, + png_uint_32 x_offset, png_uint_32 y_offset, + png_uint_16 delay_num, png_uint_16 delay_den, + png_byte dispose_op, png_byte blend_op)); +extern PNG_EXPORT(png_uint_32,png_get_next_frame_width) + PNGARG((png_structp png_ptr, png_infop info_ptr)); +extern PNG_EXPORT(png_uint_32,png_get_next_frame_height) + PNGARG((png_structp png_ptr, png_infop info_ptr)); +extern PNG_EXPORT(png_uint_32,png_get_next_frame_x_offset) + PNGARG((png_structp png_ptr, png_infop info_ptr)); +extern PNG_EXPORT(png_uint_32,png_get_next_frame_y_offset) + PNGARG((png_structp png_ptr, png_infop info_ptr)); +extern PNG_EXPORT(png_uint_16,png_get_next_frame_delay_num) + PNGARG((png_structp png_ptr, png_infop info_ptr)); +extern PNG_EXPORT(png_uint_16,png_get_next_frame_delay_den) + PNGARG((png_structp png_ptr, png_infop info_ptr)); +extern PNG_EXPORT(png_byte,png_get_next_frame_dispose_op) + PNGARG((png_structp png_ptr, png_infop info_ptr)); +extern PNG_EXPORT(png_byte,png_get_next_frame_blend_op) + PNGARG((png_structp png_ptr, png_infop info_ptr)); +extern PNG_EXPORT(png_byte,png_get_first_frame_is_hidden) + PNGARG((png_structp png_ptr, png_infop info_ptr)); +extern PNG_EXPORT(png_uint_32,png_set_first_frame_is_hidden) + PNGARG((png_structp png_ptr, png_infop info_ptr, png_byte is_hidden)); +#endif /* PNG_APNG_SUPPORTED */ + +#if defined(PNG_READ_APNG_SUPPORTED) +extern PNG_EXPORT(void,png_read_frame_head) PNGARG((png_structp png_ptr, + png_infop info_ptr)); +#endif + +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED +/* Provide a list of chunks and how they are to be handled, if the built-in + handling or default unknown chunk handling is not desired. Any chunks not + listed will be handled in the default manner. The IHDR and IEND chunks + must not be listed. + keep = 0: follow default behaviour + = 1: do not keep + = 2: keep only if safe-to-copy + = 3: keep even if unsafe-to-copy +*/ +extern PNG_EXPORT(void, png_set_keep_unknown_chunks) PNGARG((png_structp + png_ptr, int keep, png_bytep chunk_list, int num_chunks)); +PNG_EXPORT(int,png_handle_as_unknown) PNGARG((png_structp png_ptr, png_bytep + chunk_name)); +#endif +#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED +extern PNG_EXPORT(void, png_set_unknown_chunks) PNGARG((png_structp png_ptr, + png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns)); +extern PNG_EXPORT(void, png_set_unknown_chunk_location) + PNGARG((png_structp png_ptr, png_infop info_ptr, int chunk, int location)); +extern PNG_EXPORT(png_uint_32,png_get_unknown_chunks) PNGARG((png_structp + png_ptr, png_infop info_ptr, png_unknown_chunkpp entries)); +#endif + +/* Png_free_data() will turn off the "valid" flag for anything it frees. + * If you need to turn it off for a chunk that your application has freed, + * you can use png_set_invalid(png_ptr, info_ptr, PNG_INFO_CHNK); + */ +extern PNG_EXPORT(void, png_set_invalid) PNGARG((png_structp png_ptr, + png_infop info_ptr, int mask)); + +#ifdef PNG_INFO_IMAGE_SUPPORTED +/* The "params" pointer is currently not used and is for future expansion. */ +extern PNG_EXPORT(void, png_read_png) PNGARG((png_structp png_ptr, + png_infop info_ptr, + int transforms, + png_voidp params)); +extern PNG_EXPORT(void, png_write_png) PNGARG((png_structp png_ptr, + png_infop info_ptr, + int transforms, + png_voidp params)); +#endif + +/* Define PNG_DEBUG at compile time for debugging information. Higher + * numbers for PNG_DEBUG mean more debugging information. This has + * only been added since version 0.95 so it is not implemented throughout + * libpng yet, but more support will be added as needed. + */ +#ifdef PNG_DEBUG +#if (PNG_DEBUG > 0) +#if !defined(PNG_DEBUG_FILE) && defined(_MSC_VER) +#include +#if (PNG_DEBUG > 1) +#ifndef _DEBUG +# define _DEBUG +#endif +#ifndef png_debug +#define png_debug(l,m) _RPT0(_CRT_WARN,m PNG_STRING_NEWLINE) +#endif +#ifndef png_debug1 +#define png_debug1(l,m,p1) _RPT1(_CRT_WARN,m PNG_STRING_NEWLINE,p1) +#endif +#ifndef png_debug2 +#define png_debug2(l,m,p1,p2) _RPT2(_CRT_WARN,m PNG_STRING_NEWLINE,p1,p2) +#endif +#endif +#else /* PNG_DEBUG_FILE || !_MSC_VER */ +#ifndef PNG_DEBUG_FILE +#define PNG_DEBUG_FILE stderr +#endif /* PNG_DEBUG_FILE */ + +#if (PNG_DEBUG > 1) +/* Note: ["%s"m PNG_STRING_NEWLINE] probably does not work on non-ISO + * compilers. + */ +# ifdef __STDC__ +# ifndef png_debug +# define png_debug(l,m) \ + { \ + int num_tabs=l; \ + fprintf(PNG_DEBUG_FILE,"%s"m PNG_STRING_NEWLINE,(num_tabs==1 ? "\t" : \ + (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":"")))); \ + } +# endif +# ifndef png_debug1 +# define png_debug1(l,m,p1) \ + { \ + int num_tabs=l; \ + fprintf(PNG_DEBUG_FILE,"%s"m PNG_STRING_NEWLINE,(num_tabs==1 ? "\t" : \ + (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1); \ + } +# endif +# ifndef png_debug2 +# define png_debug2(l,m,p1,p2) \ + { \ + int num_tabs=l; \ + fprintf(PNG_DEBUG_FILE,"%s"m PNG_STRING_NEWLINE,(num_tabs==1 ? "\t" : \ + (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1,p2); \ + } +# endif +# else /* __STDC __ */ +# ifndef png_debug +# define png_debug(l,m) \ + { \ + int num_tabs=l; \ + char format[256]; \ + snprintf(format,256,"%s%s%s",(num_tabs==1 ? "\t" : \ + (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))), \ + m,PNG_STRING_NEWLINE); \ + fprintf(PNG_DEBUG_FILE,format); \ + } +# endif +# ifndef png_debug1 +# define png_debug1(l,m,p1) \ + { \ + int num_tabs=l; \ + char format[256]; \ + snprintf(format,256,"%s%s%s",(num_tabs==1 ? "\t" : \ + (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))), \ + m,PNG_STRING_NEWLINE); \ + fprintf(PNG_DEBUG_FILE,format,p1); \ + } +# endif +# ifndef png_debug2 +# define png_debug2(l,m,p1,p2) \ + { \ + int num_tabs=l; \ + char format[256]; \ + snprintf(format,256,"%s%s%s",(num_tabs==1 ? "\t" : \ + (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))), \ + m,PNG_STRING_NEWLINE); \ + fprintf(PNG_DEBUG_FILE,format,p1,p2); \ + } +# endif +# endif /* __STDC __ */ +#endif /* (PNG_DEBUG > 1) */ + +#endif /* _MSC_VER */ +#endif /* (PNG_DEBUG > 0) */ +#endif /* PNG_DEBUG */ +#ifndef png_debug +#define png_debug(l, m) +#endif +#ifndef png_debug1 +#define png_debug1(l, m, p1) +#endif +#ifndef png_debug2 +#define png_debug2(l, m, p1, p2) +#endif + +extern PNG_EXPORT(png_charp,png_get_copyright) PNGARG((png_structp png_ptr)); +extern PNG_EXPORT(png_charp,png_get_header_ver) PNGARG((png_structp png_ptr)); +extern PNG_EXPORT(png_charp,png_get_header_version) PNGARG((png_structp png_ptr)); +extern PNG_EXPORT(png_charp,png_get_libpng_ver) PNGARG((png_structp png_ptr)); + +#ifdef PNG_MNG_FEATURES_SUPPORTED +extern PNG_EXPORT(png_uint_32,png_permit_mng_features) PNGARG((png_structp + png_ptr, png_uint_32 mng_features_permitted)); +#endif + +/* For use in png_set_keep_unknown, added to version 1.2.6 */ +#define PNG_HANDLE_CHUNK_AS_DEFAULT 0 +#define PNG_HANDLE_CHUNK_NEVER 1 +#define PNG_HANDLE_CHUNK_IF_SAFE 2 +#define PNG_HANDLE_CHUNK_ALWAYS 3 + +/* Added to version 1.2.0 */ +#ifdef PNG_ASSEMBLER_CODE_SUPPORTED +#ifdef PNG_MMX_CODE_SUPPORTED +#define PNG_ASM_FLAG_MMX_SUPPORT_COMPILED 0x01 /* not user-settable */ +#define PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU 0x02 /* not user-settable */ +#define PNG_ASM_FLAG_MMX_READ_COMBINE_ROW 0x04 +#define PNG_ASM_FLAG_MMX_READ_INTERLACE 0x08 +#define PNG_ASM_FLAG_MMX_READ_FILTER_SUB 0x10 +#define PNG_ASM_FLAG_MMX_READ_FILTER_UP 0x20 +#define PNG_ASM_FLAG_MMX_READ_FILTER_AVG 0x40 +#define PNG_ASM_FLAG_MMX_READ_FILTER_PAETH 0x80 +#define PNG_ASM_FLAGS_INITIALIZED 0x80000000 /* not user-settable */ + +#define PNG_MMX_READ_FLAGS ( PNG_ASM_FLAG_MMX_READ_COMBINE_ROW \ + | PNG_ASM_FLAG_MMX_READ_INTERLACE \ + | PNG_ASM_FLAG_MMX_READ_FILTER_SUB \ + | PNG_ASM_FLAG_MMX_READ_FILTER_UP \ + | PNG_ASM_FLAG_MMX_READ_FILTER_AVG \ + | PNG_ASM_FLAG_MMX_READ_FILTER_PAETH ) +#define PNG_MMX_WRITE_FLAGS ( 0 ) + +#define PNG_MMX_FLAGS ( PNG_ASM_FLAG_MMX_SUPPORT_COMPILED \ + | PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU \ + | PNG_MMX_READ_FLAGS \ + | PNG_MMX_WRITE_FLAGS ) + +#define PNG_SELECT_READ 1 +#define PNG_SELECT_WRITE 2 +#endif /* PNG_MMX_CODE_SUPPORTED */ + +#ifndef PNG_1_0_X +/* pngget.c */ +extern PNG_EXPORT(png_uint_32,png_get_mmx_flagmask) + PNGARG((int flag_select, int *compilerID)); + +/* pngget.c */ +extern PNG_EXPORT(png_uint_32,png_get_asm_flagmask) + PNGARG((int flag_select)); + +/* pngget.c */ +extern PNG_EXPORT(png_uint_32,png_get_asm_flags) + PNGARG((png_structp png_ptr)); + +/* pngget.c */ +extern PNG_EXPORT(png_byte,png_get_mmx_bitdepth_threshold) + PNGARG((png_structp png_ptr)); + +/* pngget.c */ +extern PNG_EXPORT(png_uint_32,png_get_mmx_rowbytes_threshold) + PNGARG((png_structp png_ptr)); + +/* pngset.c */ +extern PNG_EXPORT(void,png_set_asm_flags) + PNGARG((png_structp png_ptr, png_uint_32 asm_flags)); + +/* pngset.c */ +extern PNG_EXPORT(void,png_set_mmx_thresholds) + PNGARG((png_structp png_ptr, png_byte mmx_bitdepth_threshold, + png_uint_32 mmx_rowbytes_threshold)); + +#endif /* PNG_1_0_X */ + +#ifndef PNG_1_0_X +/* png.c, pnggccrd.c, or pngvcrd.c */ +extern PNG_EXPORT(int,png_mmx_support) PNGARG((void)); +#endif /* PNG_1_0_X */ +#endif /* PNG_ASSEMBLER_CODE_SUPPORTED */ + +/* Strip the prepended error numbers ("#nnn ") from error and warning + * messages before passing them to the error or warning handler. + */ +#ifdef PNG_ERROR_NUMBERS_SUPPORTED +extern PNG_EXPORT(void,png_set_strip_error_numbers) PNGARG((png_structp + png_ptr, png_uint_32 strip_mode)); +#endif + +/* Added at libpng-1.2.6 */ +#ifdef PNG_SET_USER_LIMITS_SUPPORTED +extern PNG_EXPORT(void,png_set_user_limits) PNGARG((png_structp + png_ptr, png_uint_32 user_width_max, png_uint_32 user_height_max)); +extern PNG_EXPORT(png_uint_32,png_get_user_width_max) PNGARG((png_structp + png_ptr)); +extern PNG_EXPORT(png_uint_32,png_get_user_height_max) PNGARG((png_structp + png_ptr)); +#endif +/* Maintainer: Put new public prototypes here ^, in libpng.3, and in + * project defs + */ + +#ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED +/* With these routines we avoid an integer divide, which will be slower on + * most machines. However, it does take more operations than the corresponding + * divide method, so it may be slower on a few RISC systems. There are two + * shifts (by 8 or 16 bits) and an addition, versus a single integer divide. + * + * Note that the rounding factors are NOT supposed to be the same! 128 and + * 32768 are correct for the NODIV code; 127 and 32767 are correct for the + * standard method. + * + * [Optimized code by Greg Roelofs and Mark Adler...blame us for bugs. :-) ] + */ + + /* fg and bg should be in `gamma 1.0' space; alpha is the opacity */ + +# define png_composite(composite, fg, alpha, bg) \ + { png_uint_16 temp = (png_uint_16)((png_uint_16)(fg) * (png_uint_16)(alpha) \ + + (png_uint_16)(bg)*(png_uint_16)(255 - \ + (png_uint_16)(alpha)) + (png_uint_16)128); \ + (composite) = (png_byte)((temp + (temp >> 8)) >> 8); } + +# define png_composite_16(composite, fg, alpha, bg) \ + { png_uint_32 temp = (png_uint_32)((png_uint_32)(fg) * (png_uint_32)(alpha) \ + + (png_uint_32)(bg)*(png_uint_32)(65535L - \ + (png_uint_32)(alpha)) + (png_uint_32)32768L); \ + (composite) = (png_uint_16)((temp + (temp >> 16)) >> 16); } + +#else /* Standard method using integer division */ + +# define png_composite(composite, fg, alpha, bg) \ + (composite) = (png_byte)(((png_uint_16)(fg) * (png_uint_16)(alpha) + \ + (png_uint_16)(bg) * (png_uint_16)(255 - (png_uint_16)(alpha)) + \ + (png_uint_16)127) / 255) + +# define png_composite_16(composite, fg, alpha, bg) \ + (composite) = (png_uint_16)(((png_uint_32)(fg) * (png_uint_32)(alpha) + \ + (png_uint_32)(bg)*(png_uint_32)(65535L - (png_uint_32)(alpha)) + \ + (png_uint_32)32767) / (png_uint_32)65535L) + +#endif /* PNG_READ_COMPOSITE_NODIV_SUPPORTED */ + +/* Inline macros to do direct reads of bytes from the input buffer. These + * require that you are using an architecture that uses PNG byte ordering + * (MSB first) and supports unaligned data storage. I think that PowerPC + * in big-endian mode and 680x0 are the only ones that will support this. + * The x86 line of processors definitely do not. The png_get_int_32() + * routine also assumes we are using two's complement format for negative + * values, which is almost certainly true. + */ +#ifdef PNG_READ_BIG_ENDIAN_SUPPORTED +# define png_get_uint_32(buf) ( *((png_uint_32p) (buf))) +# define png_get_uint_16(buf) ( *((png_uint_16p) (buf))) +# define png_get_int_32(buf) ( *((png_int_32p) (buf))) +#else +extern PNG_EXPORT(png_uint_32,png_get_uint_32) PNGARG((png_bytep buf)); +extern PNG_EXPORT(png_uint_16,png_get_uint_16) PNGARG((png_bytep buf)); +extern PNG_EXPORT(png_int_32,png_get_int_32) PNGARG((png_bytep buf)); +#endif /* !PNG_READ_BIG_ENDIAN_SUPPORTED */ +extern PNG_EXPORT(png_uint_32,png_get_uint_31) + PNGARG((png_structp png_ptr, png_bytep buf)); +/* No png_get_int_16 -- may be added if there's a real need for it. */ + +/* Place a 32-bit number into a buffer in PNG byte order (big-endian). + */ +extern PNG_EXPORT(void,png_save_uint_32) + PNGARG((png_bytep buf, png_uint_32 i)); +extern PNG_EXPORT(void,png_save_int_32) + PNGARG((png_bytep buf, png_int_32 i)); + +/* Place a 16-bit number into a buffer in PNG byte order. + * The parameter is declared unsigned int, not png_uint_16, + * just to avoid potential problems on pre-ANSI C compilers. + */ +extern PNG_EXPORT(void,png_save_uint_16) + PNGARG((png_bytep buf, unsigned int i)); +/* No png_save_int_16 -- may be added if there's a real need for it. */ + +/* ************************************************************************* */ + +/* These next functions are used internally in the code. They generally + * shouldn't be used unless you are writing code to add or replace some + * functionality in libpng. More information about most functions can + * be found in the files where the functions are located. + */ + + +/* Various modes of operation, that are visible to applications because + * they are used for unknown chunk location. + */ +#define PNG_HAVE_IHDR 0x01 +#define PNG_HAVE_PLTE 0x02 +#define PNG_HAVE_IDAT 0x04 +#define PNG_AFTER_IDAT 0x08 /* Have complete zlib datastream */ +#define PNG_HAVE_IEND 0x10 + +#ifdef PNG_INTERNAL + +/* More modes of operation. Note that after an init, mode is set to + * zero automatically when the structure is created. + */ +#define PNG_HAVE_gAMA 0x20 +#define PNG_HAVE_cHRM 0x40 +#define PNG_HAVE_sRGB 0x80 +#define PNG_HAVE_CHUNK_HEADER 0x100 +#define PNG_WROTE_tIME 0x200 +#define PNG_WROTE_INFO_BEFORE_PLTE 0x400 +#define PNG_BACKGROUND_IS_GRAY 0x800 +#define PNG_HAVE_PNG_SIGNATURE 0x1000 +#define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000 /* Have another chunk after IDAT */ +#define PNG_HAVE_acTL 0x4000 +#define PNG_HAVE_fcTL 0x8000L + +/* Flags for the transformations the PNG library does on the image data */ +#define PNG_BGR 0x0001 +#define PNG_INTERLACE 0x0002 +#define PNG_PACK 0x0004 +#define PNG_SHIFT 0x0008 +#define PNG_SWAP_BYTES 0x0010 +#define PNG_INVERT_MONO 0x0020 +#define PNG_DITHER 0x0040 +#define PNG_BACKGROUND 0x0080 +#define PNG_BACKGROUND_EXPAND 0x0100 + /* 0x0200 unused */ +#define PNG_16_TO_8 0x0400 +#define PNG_RGBA 0x0800 +#define PNG_EXPAND 0x1000 +#define PNG_GAMMA 0x2000 +#define PNG_GRAY_TO_RGB 0x4000 +#define PNG_FILLER 0x8000L +#define PNG_PACKSWAP 0x10000L +#define PNG_SWAP_ALPHA 0x20000L +#define PNG_STRIP_ALPHA 0x40000L +#define PNG_INVERT_ALPHA 0x80000L +#define PNG_USER_TRANSFORM 0x100000L +#define PNG_RGB_TO_GRAY_ERR 0x200000L +#define PNG_RGB_TO_GRAY_WARN 0x400000L +#define PNG_RGB_TO_GRAY 0x600000L /* two bits, RGB_TO_GRAY_ERR|WARN */ + /* 0x800000L Unused */ +#define PNG_ADD_ALPHA 0x1000000L /* Added to libpng-1.2.7 */ +#define PNG_EXPAND_tRNS 0x2000000L /* Added to libpng-1.2.9 */ +#define PNG_PREMULTIPLY_ALPHA 0x4000000L /* Added to libpng-1.2.41 */ + /* by volker */ + /* 0x8000000L unused */ + /* 0x10000000L unused */ + /* 0x20000000L unused */ + /* 0x40000000L unused */ + +/* Flags for png_create_struct */ +#define PNG_STRUCT_PNG 0x0001 +#define PNG_STRUCT_INFO 0x0002 + +/* Scaling factor for filter heuristic weighting calculations */ +#define PNG_WEIGHT_SHIFT 8 +#define PNG_WEIGHT_FACTOR (1<<(PNG_WEIGHT_SHIFT)) +#define PNG_COST_SHIFT 3 +#define PNG_COST_FACTOR (1<<(PNG_COST_SHIFT)) + +/* Flags for the png_ptr->flags rather than declaring a byte for each one */ +#define PNG_FLAG_ZLIB_CUSTOM_STRATEGY 0x0001 +#define PNG_FLAG_ZLIB_CUSTOM_LEVEL 0x0002 +#define PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL 0x0004 +#define PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS 0x0008 +#define PNG_FLAG_ZLIB_CUSTOM_METHOD 0x0010 +#define PNG_FLAG_ZLIB_FINISHED 0x0020 +#define PNG_FLAG_ROW_INIT 0x0040 +#define PNG_FLAG_FILLER_AFTER 0x0080 +#define PNG_FLAG_CRC_ANCILLARY_USE 0x0100 +#define PNG_FLAG_CRC_ANCILLARY_NOWARN 0x0200 +#define PNG_FLAG_CRC_CRITICAL_USE 0x0400 +#define PNG_FLAG_CRC_CRITICAL_IGNORE 0x0800 +#define PNG_FLAG_FREE_PLTE 0x1000 +#define PNG_FLAG_FREE_TRNS 0x2000 +#define PNG_FLAG_FREE_HIST 0x4000 +#define PNG_FLAG_KEEP_UNKNOWN_CHUNKS 0x8000L +#define PNG_FLAG_KEEP_UNSAFE_CHUNKS 0x10000L +#define PNG_FLAG_LIBRARY_MISMATCH 0x20000L +#define PNG_FLAG_STRIP_ERROR_NUMBERS 0x40000L +#define PNG_FLAG_STRIP_ERROR_TEXT 0x80000L +#define PNG_FLAG_MALLOC_NULL_MEM_OK 0x100000L +#define PNG_FLAG_ADD_ALPHA 0x200000L /* Added to libpng-1.2.8 */ +#define PNG_FLAG_STRIP_ALPHA 0x400000L /* Added to libpng-1.2.8 */ + /* 0x800000L unused */ + /* 0x1000000L unused */ + /* 0x2000000L unused */ + /* 0x4000000L unused */ + /* 0x8000000L unused */ + /* 0x10000000L unused */ + /* 0x20000000L unused */ + /* 0x40000000L unused */ + +#define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \ + PNG_FLAG_CRC_ANCILLARY_NOWARN) + +#define PNG_FLAG_CRC_CRITICAL_MASK (PNG_FLAG_CRC_CRITICAL_USE | \ + PNG_FLAG_CRC_CRITICAL_IGNORE) + +#define PNG_FLAG_CRC_MASK (PNG_FLAG_CRC_ANCILLARY_MASK | \ + PNG_FLAG_CRC_CRITICAL_MASK) + +/* Save typing and make code easier to understand */ + +#define PNG_COLOR_DIST(c1, c2) (abs((int)((c1).red) - (int)((c2).red)) + \ + abs((int)((c1).green) - (int)((c2).green)) + \ + abs((int)((c1).blue) - (int)((c2).blue))) + +/* Added to libpng-1.2.6 JB */ +#define PNG_ROWBYTES(pixel_bits, width) \ + ((pixel_bits) >= 8 ? \ + ((width) * (((png_uint_32)(pixel_bits)) >> 3)) : \ + (( ((width) * ((png_uint_32)(pixel_bits))) + 7) >> 3) ) + +/* PNG_OUT_OF_RANGE returns true if value is outside the range + * ideal-delta..ideal+delta. Each argument is evaluated twice. + * "ideal" and "delta" should be constants, normally simple + * integers, "value" a variable. Added to libpng-1.2.6 JB + */ +#define PNG_OUT_OF_RANGE(value, ideal, delta) \ + ( (value) < (ideal)-(delta) || (value) > (ideal)+(delta) ) + +/* Variables declared in png.c - only it needs to define PNG_NO_EXTERN */ +#if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN) +/* Place to hold the signature string for a PNG file. */ +#ifdef PNG_USE_GLOBAL_ARRAYS + PNG_EXPORT_VAR (PNG_CONST png_byte FARDATA) png_sig[8]; +#else +#endif +#endif /* PNG_NO_EXTERN */ + +/* Constant strings for known chunk types. If you need to add a chunk, + * define the name here, and add an invocation of the macro in png.c and + * wherever it's needed. + */ +#define PNG_IHDR png_byte png_IHDR[5] = { 73, 72, 68, 82, '\0'} +#define PNG_IDAT png_byte png_IDAT[5] = { 73, 68, 65, 84, '\0'} +#define PNG_IEND png_byte png_IEND[5] = { 73, 69, 78, 68, '\0'} +#define PNG_PLTE png_byte png_PLTE[5] = { 80, 76, 84, 69, '\0'} +#define PNG_bKGD png_byte png_bKGD[5] = { 98, 75, 71, 68, '\0'} +#define PNG_cHRM png_byte png_cHRM[5] = { 99, 72, 82, 77, '\0'} +#define PNG_gAMA png_byte png_gAMA[5] = {103, 65, 77, 65, '\0'} +#define PNG_hIST png_byte png_hIST[5] = {104, 73, 83, 84, '\0'} +#define PNG_iCCP png_byte png_iCCP[5] = {105, 67, 67, 80, '\0'} +#define PNG_iTXt png_byte png_iTXt[5] = {105, 84, 88, 116, '\0'} +#define PNG_oFFs png_byte png_oFFs[5] = {111, 70, 70, 115, '\0'} +#define PNG_pCAL png_byte png_pCAL[5] = {112, 67, 65, 76, '\0'} +#define PNG_sCAL png_byte png_sCAL[5] = {115, 67, 65, 76, '\0'} +#define PNG_pHYs png_byte png_pHYs[5] = {112, 72, 89, 115, '\0'} +#define PNG_sBIT png_byte png_sBIT[5] = {115, 66, 73, 84, '\0'} +#define PNG_sPLT png_byte png_sPLT[5] = {115, 80, 76, 84, '\0'} +#define PNG_sRGB png_byte png_sRGB[5] = {115, 82, 71, 66, '\0'} +#define PNG_tEXt png_byte png_tEXt[5] = {116, 69, 88, 116, '\0'} +#define PNG_tIME png_byte png_tIME[5] = {116, 73, 77, 69, '\0'} +#define PNG_tRNS png_byte png_tRNS[5] = {116, 82, 78, 83, '\0'} +#define PNG_zTXt png_byte png_zTXt[5] = {122, 84, 88, 116, '\0'} +#define PNG_acTL png_byte png_acTL[5] = { 97, 99, 84, 76, '\0'} +#define PNG_fcTL png_byte png_fcTL[5] = {102, 99, 84, 76, '\0'} +#define PNG_fdAT png_byte png_fdAT[5] = {102, 100, 65, 84, '\0'} + +#ifdef PNG_USE_GLOBAL_ARRAYS +PNG_EXPORT_VAR (png_byte FARDATA) png_IHDR[5]; +PNG_EXPORT_VAR (png_byte FARDATA) png_IDAT[5]; +PNG_EXPORT_VAR (png_byte FARDATA) png_IEND[5]; +PNG_EXPORT_VAR (png_byte FARDATA) png_PLTE[5]; +PNG_EXPORT_VAR (png_byte FARDATA) png_bKGD[5]; +PNG_EXPORT_VAR (png_byte FARDATA) png_cHRM[5]; +PNG_EXPORT_VAR (png_byte FARDATA) png_gAMA[5]; +PNG_EXPORT_VAR (png_byte FARDATA) png_hIST[5]; +PNG_EXPORT_VAR (png_byte FARDATA) png_iCCP[5]; +PNG_EXPORT_VAR (png_byte FARDATA) png_iTXt[5]; +PNG_EXPORT_VAR (png_byte FARDATA) png_oFFs[5]; +PNG_EXPORT_VAR (png_byte FARDATA) png_pCAL[5]; +PNG_EXPORT_VAR (png_byte FARDATA) png_sCAL[5]; +PNG_EXPORT_VAR (png_byte FARDATA) png_pHYs[5]; +PNG_EXPORT_VAR (png_byte FARDATA) png_sBIT[5]; +PNG_EXPORT_VAR (png_byte FARDATA) png_sPLT[5]; +PNG_EXPORT_VAR (png_byte FARDATA) png_sRGB[5]; +PNG_EXPORT_VAR (png_byte FARDATA) png_tEXt[5]; +PNG_EXPORT_VAR (png_byte FARDATA) png_tIME[5]; +PNG_EXPORT_VAR (png_byte FARDATA) png_tRNS[5]; +PNG_EXPORT_VAR (png_byte FARDATA) png_zTXt[5]; +PNG_EXPORT_VAR (png_byte FARDATA) png_acTL[5]; +PNG_EXPORT_VAR (png_byte FARDATA) png_fcTL[5]; +PNG_EXPORT_VAR (png_byte FARDATA) png_fdAT[5]; +#endif /* PNG_USE_GLOBAL_ARRAYS */ + +#if defined(PNG_1_0_X) || defined (PNG_1_2_X) +/* Initialize png_ptr struct for reading, and allocate any other memory. + * (old interface - DEPRECATED - use png_create_read_struct instead). + */ +extern PNG_EXPORT(void,png_read_init) PNGARG((png_structp png_ptr)) + PNG_DEPRECATED; +#undef png_read_init +#define png_read_init(png_ptr) png_read_init_3(&png_ptr, \ + PNG_LIBPNG_VER_STRING, png_sizeof(png_struct)); +#endif + +extern PNG_EXPORT(void,png_read_init_3) PNGARG((png_structpp ptr_ptr, + png_const_charp user_png_ver, png_size_t png_struct_size)); +#if defined(PNG_1_0_X) || defined (PNG_1_2_X) +extern PNG_EXPORT(void,png_read_init_2) PNGARG((png_structp png_ptr, + png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t + png_info_size)); +#endif + +#if defined(PNG_1_0_X) || defined (PNG_1_2_X) +/* Initialize png_ptr struct for writing, and allocate any other memory. + * (old interface - DEPRECATED - use png_create_write_struct instead). + */ +extern PNG_EXPORT(void,png_write_init) PNGARG((png_structp png_ptr)) + PNG_DEPRECATED; +#undef png_write_init +#define png_write_init(png_ptr) png_write_init_3(&png_ptr, \ + PNG_LIBPNG_VER_STRING, png_sizeof(png_struct)); +#endif + +extern PNG_EXPORT(void,png_write_init_3) PNGARG((png_structpp ptr_ptr, + png_const_charp user_png_ver, png_size_t png_struct_size)); +extern PNG_EXPORT(void,png_write_init_2) PNGARG((png_structp png_ptr, + png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t + png_info_size)); + +/* Allocate memory for an internal libpng struct */ +PNG_EXTERN png_voidp png_create_struct PNGARG((int type)) PNG_PRIVATE; + +/* Free memory from internal libpng struct */ +PNG_EXTERN void png_destroy_struct PNGARG((png_voidp struct_ptr)) PNG_PRIVATE; + +PNG_EXTERN png_voidp png_create_struct_2 PNGARG((int type, png_malloc_ptr + malloc_fn, png_voidp mem_ptr)) PNG_PRIVATE; +PNG_EXTERN void png_destroy_struct_2 PNGARG((png_voidp struct_ptr, + png_free_ptr free_fn, png_voidp mem_ptr)) PNG_PRIVATE; + +/* Free any memory that info_ptr points to and reset struct. */ +PNG_EXTERN void png_info_destroy PNGARG((png_structp png_ptr, + png_infop info_ptr)) PNG_PRIVATE; + +#ifndef PNG_1_0_X +/* Function to allocate memory for zlib. */ +PNG_EXTERN voidpf png_zalloc PNGARG((voidpf png_ptr, uInt items, + uInt size)) PNG_PRIVATE; + +/* Function to free memory for zlib */ +PNG_EXTERN void png_zfree PNGARG((voidpf png_ptr, voidpf ptr)) PNG_PRIVATE; + +#ifdef PNG_SIZE_T +/* Function to convert a sizeof an item to png_sizeof item */ + PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size)) + PNG_PRIVATE; +#endif + +/* Next four functions are used internally as callbacks. PNGAPI is required + * but not PNG_EXPORT. PNGAPI added at libpng version 1.2.3. + */ + +PNG_EXTERN void PNGAPI png_default_read_data PNGARG((png_structp png_ptr, + png_bytep data, png_size_t length)) PNG_PRIVATE; + +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED +PNG_EXTERN void PNGAPI png_push_fill_buffer PNGARG((png_structp png_ptr, + png_bytep buffer, png_size_t length)) PNG_PRIVATE; +#endif + +PNG_EXTERN void PNGAPI png_default_write_data PNGARG((png_structp png_ptr, + png_bytep data, png_size_t length)) PNG_PRIVATE; + +#ifdef PNG_WRITE_FLUSH_SUPPORTED +#ifdef PNG_STDIO_SUPPORTED +PNG_EXTERN void PNGAPI png_default_flush PNGARG((png_structp png_ptr)) + PNG_PRIVATE; +#endif +#endif +#else /* PNG_1_0_X */ +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED +PNG_EXTERN void png_push_fill_buffer PNGARG((png_structp png_ptr, + png_bytep buffer, png_size_t length)) PNG_PRIVATE; +#endif +#endif /* PNG_1_0_X */ + +/* Reset the CRC variable */ +PNG_EXTERN void png_reset_crc PNGARG((png_structp png_ptr)) PNG_PRIVATE; + +/* Write the "data" buffer to whatever output you are using. */ +PNG_EXTERN void png_write_data PNGARG((png_structp png_ptr, png_bytep data, + png_size_t length)) PNG_PRIVATE; + +/* Read data from whatever input you are using into the "data" buffer */ +PNG_EXTERN void png_read_data PNGARG((png_structp png_ptr, png_bytep data, + png_size_t length)) PNG_PRIVATE; + +/* Read bytes into buf, and update png_ptr->crc */ +PNG_EXTERN void png_crc_read PNGARG((png_structp png_ptr, png_bytep buf, + png_size_t length)) PNG_PRIVATE; + +/* Decompress data in a chunk that uses compression */ +#if defined(PNG_zTXt_SUPPORTED) || defined(PNG_iTXt_SUPPORTED) || \ + defined(PNG_iCCP_SUPPORTED) || defined(PNG_sPLT_SUPPORTED) +PNG_EXTERN void png_decompress_chunk PNGARG((png_structp png_ptr, + int comp_type, png_size_t chunklength, + png_size_t prefix_length, png_size_t *data_length)) PNG_PRIVATE; +#endif + +/* Read "skip" bytes, read the file crc, and (optionally) verify png_ptr->crc */ +PNG_EXTERN int png_crc_finish PNGARG((png_structp png_ptr, png_uint_32 skip) + PNG_PRIVATE); + +/* Read the CRC from the file and compare it to the libpng calculated CRC */ +PNG_EXTERN int png_crc_error PNGARG((png_structp png_ptr)) PNG_PRIVATE; + +/* Calculate the CRC over a section of data. Note that we are only + * passing a maximum of 64K on systems that have this as a memory limit, + * since this is the maximum buffer size we can specify. + */ +PNG_EXTERN void png_calculate_crc PNGARG((png_structp png_ptr, png_bytep ptr, + png_size_t length)) PNG_PRIVATE; + +#ifdef PNG_WRITE_FLUSH_SUPPORTED +PNG_EXTERN void png_flush PNGARG((png_structp png_ptr)) PNG_PRIVATE; +#endif + +/* Simple function to write the signature */ +PNG_EXTERN void png_write_sig PNGARG((png_structp png_ptr)) PNG_PRIVATE; + +/* Write various chunks */ + +/* Write the IHDR chunk, and update the png_struct with the necessary + * information. + */ +PNG_EXTERN void png_write_IHDR PNGARG((png_structp png_ptr, png_uint_32 width, + png_uint_32 height, + int bit_depth, int color_type, int compression_method, int filter_method, + int interlace_method)) PNG_PRIVATE; + +PNG_EXTERN void png_write_PLTE PNGARG((png_structp png_ptr, png_colorp palette, + png_uint_32 num_pal)) PNG_PRIVATE; + +PNG_EXTERN void png_write_IDAT PNGARG((png_structp png_ptr, png_bytep data, + png_size_t length)) PNG_PRIVATE; + +PNG_EXTERN void png_write_IEND PNGARG((png_structp png_ptr)) PNG_PRIVATE; + +#ifdef PNG_WRITE_gAMA_SUPPORTED +#ifdef PNG_FLOATING_POINT_SUPPORTED +PNG_EXTERN void png_write_gAMA PNGARG((png_structp png_ptr, double file_gamma)) + PNG_PRIVATE; +#endif +#ifdef PNG_FIXED_POINT_SUPPORTED +PNG_EXTERN void png_write_gAMA_fixed PNGARG((png_structp png_ptr, + png_fixed_point file_gamma)) PNG_PRIVATE; +#endif +#endif + +#ifdef PNG_WRITE_sBIT_SUPPORTED +PNG_EXTERN void png_write_sBIT PNGARG((png_structp png_ptr, png_color_8p sbit, + int color_type)) PNG_PRIVATE; +#endif + +#ifdef PNG_WRITE_cHRM_SUPPORTED +#ifdef PNG_FLOATING_POINT_SUPPORTED +PNG_EXTERN void png_write_cHRM PNGARG((png_structp png_ptr, + double white_x, double white_y, + double red_x, double red_y, double green_x, double green_y, + double blue_x, double blue_y)) PNG_PRIVATE; +#endif +#ifdef PNG_FIXED_POINT_SUPPORTED +PNG_EXTERN void png_write_cHRM_fixed PNGARG((png_structp png_ptr, + png_fixed_point int_white_x, png_fixed_point int_white_y, + png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point + int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x, + png_fixed_point int_blue_y)) PNG_PRIVATE; +#endif +#endif + +#ifdef PNG_WRITE_sRGB_SUPPORTED +PNG_EXTERN void png_write_sRGB PNGARG((png_structp png_ptr, + int intent)) PNG_PRIVATE; +#endif + +#ifdef PNG_WRITE_iCCP_SUPPORTED +PNG_EXTERN void png_write_iCCP PNGARG((png_structp png_ptr, + png_charp name, int compression_type, + png_charp profile, int proflen)) PNG_PRIVATE; + /* Note to maintainer: profile should be png_bytep */ +#endif + +#ifdef PNG_WRITE_sPLT_SUPPORTED +PNG_EXTERN void png_write_sPLT PNGARG((png_structp png_ptr, + png_sPLT_tp palette)) PNG_PRIVATE; +#endif + +#ifdef PNG_WRITE_tRNS_SUPPORTED +PNG_EXTERN void png_write_tRNS PNGARG((png_structp png_ptr, png_bytep trans, + png_color_16p values, int number, int color_type)) PNG_PRIVATE; +#endif + +#ifdef PNG_WRITE_bKGD_SUPPORTED +PNG_EXTERN void png_write_bKGD PNGARG((png_structp png_ptr, + png_color_16p values, int color_type)) PNG_PRIVATE; +#endif + +#ifdef PNG_WRITE_hIST_SUPPORTED +PNG_EXTERN void png_write_hIST PNGARG((png_structp png_ptr, png_uint_16p hist, + int num_hist)) PNG_PRIVATE; +#endif + +#if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \ + defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED) +PNG_EXTERN png_size_t png_check_keyword PNGARG((png_structp png_ptr, + png_charp key, png_charpp new_key)) PNG_PRIVATE; +#endif + +#ifdef PNG_WRITE_tEXt_SUPPORTED +PNG_EXTERN void png_write_tEXt PNGARG((png_structp png_ptr, png_charp key, + png_charp text, png_size_t text_len)) PNG_PRIVATE; +#endif + +#ifdef PNG_WRITE_zTXt_SUPPORTED +PNG_EXTERN void png_write_zTXt PNGARG((png_structp png_ptr, png_charp key, + png_charp text, png_size_t text_len, int compression)) PNG_PRIVATE; +#endif + +#ifdef PNG_WRITE_iTXt_SUPPORTED +PNG_EXTERN void png_write_iTXt PNGARG((png_structp png_ptr, + int compression, png_charp key, png_charp lang, png_charp lang_key, + png_charp text)) PNG_PRIVATE; +#endif + +#ifdef PNG_TEXT_SUPPORTED /* Added at version 1.0.14 and 1.2.4 */ +PNG_EXTERN int png_set_text_2 PNGARG((png_structp png_ptr, + png_infop info_ptr, png_textp text_ptr, int num_text)) PNG_PRIVATE; +#endif + +#ifdef PNG_WRITE_oFFs_SUPPORTED +PNG_EXTERN void png_write_oFFs PNGARG((png_structp png_ptr, + png_int_32 x_offset, png_int_32 y_offset, int unit_type)) PNG_PRIVATE; +#endif + +#ifdef PNG_WRITE_pCAL_SUPPORTED +PNG_EXTERN void png_write_pCAL PNGARG((png_structp png_ptr, png_charp purpose, + png_int_32 X0, png_int_32 X1, int type, int nparams, + png_charp units, png_charpp params)) PNG_PRIVATE; +#endif + +#ifdef PNG_WRITE_pHYs_SUPPORTED +PNG_EXTERN void png_write_pHYs PNGARG((png_structp png_ptr, + png_uint_32 x_pixels_per_unit, png_uint_32 y_pixels_per_unit, + int unit_type)) PNG_PRIVATE; +#endif + +#ifdef PNG_WRITE_tIME_SUPPORTED +PNG_EXTERN void png_write_tIME PNGARG((png_structp png_ptr, + png_timep mod_time)) PNG_PRIVATE; +#endif + +#ifdef PNG_WRITE_sCAL_SUPPORTED +#if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO) +PNG_EXTERN void png_write_sCAL PNGARG((png_structp png_ptr, + int unit, double width, double height)) PNG_PRIVATE; +#else +#ifdef PNG_FIXED_POINT_SUPPORTED +PNG_EXTERN void png_write_sCAL_s PNGARG((png_structp png_ptr, + int unit, png_charp width, png_charp height)) PNG_PRIVATE; +#endif +#endif +#endif + +#if defined(PNG_WRITE_APNG_SUPPORTED) +PNG_EXTERN void png_write_acTL PNGARG((png_structp png_ptr, + png_uint_32 num_frames, png_uint_32 num_plays)); + +PNG_EXTERN void png_write_fcTL PNGARG((png_structp png_ptr, + png_uint_32 width, png_uint_32 height, + png_uint_32 x_offset, png_uint_32 y_offset, + png_uint_16 delay_num, png_uint_16 delay_den, + png_byte dispose_op, png_byte blend_op)); +#endif + +/* Called when finished processing a row of data */ +PNG_EXTERN void png_write_finish_row PNGARG((png_structp png_ptr)) PNG_PRIVATE; + +/* Internal use only. Called before first row of data */ +PNG_EXTERN void png_write_start_row PNGARG((png_structp png_ptr)) PNG_PRIVATE; + +#ifdef PNG_READ_GAMMA_SUPPORTED +PNG_EXTERN void png_build_gamma_table PNGARG((png_structp png_ptr)) PNG_PRIVATE; +#endif + +/* Combine a row of data, dealing with alpha, etc. if requested */ +PNG_EXTERN void png_combine_row PNGARG((png_structp png_ptr, png_bytep row, + int mask)) PNG_PRIVATE; + +#ifdef PNG_READ_INTERLACING_SUPPORTED +/* Expand an interlaced row */ +/* OLD pre-1.0.9 interface: +PNG_EXTERN void png_do_read_interlace PNGARG((png_row_infop row_info, + png_bytep row, int pass, png_uint_32 transformations)) PNG_PRIVATE; + */ +PNG_EXTERN void png_do_read_interlace PNGARG((png_structp png_ptr)) PNG_PRIVATE; +#endif + +/* GRR TO DO (2.0 or whenever): simplify other internal calling interfaces */ + +#ifdef PNG_WRITE_INTERLACING_SUPPORTED +/* Grab pixels out of a row for an interlaced pass */ +PNG_EXTERN void png_do_write_interlace PNGARG((png_row_infop row_info, + png_bytep row, int pass)) PNG_PRIVATE; +#endif + +/* Unfilter a row */ +PNG_EXTERN void png_read_filter_row PNGARG((png_structp png_ptr, + png_row_infop row_info, png_bytep row, png_bytep prev_row, + int filter)) PNG_PRIVATE; + +/* Choose the best filter to use and filter the row data */ +PNG_EXTERN void png_write_find_filter PNGARG((png_structp png_ptr, + png_row_infop row_info)) PNG_PRIVATE; + +/* Write out the filtered row. */ +PNG_EXTERN void png_write_filtered_row PNGARG((png_structp png_ptr, + png_bytep filtered_row)) PNG_PRIVATE; +/* Finish a row while reading, dealing with interlacing passes, etc. */ +PNG_EXTERN void png_read_finish_row PNGARG((png_structp png_ptr)); + +/* Initialize the row buffers, etc. */ +PNG_EXTERN void png_read_start_row PNGARG((png_structp png_ptr)) PNG_PRIVATE; +/* Optional call to update the users info structure */ +PNG_EXTERN void png_read_transform_info PNGARG((png_structp png_ptr, + png_infop info_ptr)) PNG_PRIVATE; + +#if defined(PNG_READ_APNG_SUPPORTED) +/* private, reset some things to become ready for reading next frame */ +PNG_EXTERN void png_read_reset PNGARG((png_structp png_ptr)); +PNG_EXTERN void png_read_reinit PNGARG((png_structp png_ptr, + png_infop info_ptr)); +PNG_EXTERN void png_progressive_read_reset PNGARG((png_structp png_ptr)); +#endif +#if defined(PNG_WRITE_APNG_SUPPORTED) +/* private, reset some things to become ready for writing next frame */ +PNG_EXTERN void png_write_reset PNGARG((png_structp png_ptr)); +PNG_EXTERN void png_write_reinit PNGARG((png_structp png_ptr, + png_infop info_ptr, png_uint_32 width, png_uint_32 height)); +#endif + +/* These are the functions that do the transformations */ +#ifdef PNG_READ_FILLER_SUPPORTED +PNG_EXTERN void png_do_read_filler PNGARG((png_row_infop row_info, + png_bytep row, png_uint_32 filler, png_uint_32 flags)) PNG_PRIVATE; +#endif + +#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED +PNG_EXTERN void png_do_read_swap_alpha PNGARG((png_row_infop row_info, + png_bytep row)) PNG_PRIVATE; +#endif + +#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED +PNG_EXTERN void png_do_write_swap_alpha PNGARG((png_row_infop row_info, + png_bytep row)) PNG_PRIVATE; +#endif + +#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED +PNG_EXTERN void png_do_read_invert_alpha PNGARG((png_row_infop row_info, + png_bytep row)) PNG_PRIVATE; +#endif + +#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED +PNG_EXTERN void png_do_write_invert_alpha PNGARG((png_row_infop row_info, + png_bytep row)) PNG_PRIVATE; +#endif + +#if defined(PNG_WRITE_FILLER_SUPPORTED) || \ + defined(PNG_READ_STRIP_ALPHA_SUPPORTED) +PNG_EXTERN void png_do_strip_filler PNGARG((png_row_infop row_info, + png_bytep row, png_uint_32 flags)) PNG_PRIVATE; +#endif + +#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED) +PNG_EXTERN void png_do_swap PNGARG((png_row_infop row_info, + png_bytep row)) PNG_PRIVATE; +#endif + +#if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED) +PNG_EXTERN void png_do_packswap PNGARG((png_row_infop row_info, + png_bytep row)) PNG_PRIVATE; +#endif + +#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED +PNG_EXTERN int png_do_rgb_to_gray PNGARG((png_structp png_ptr, png_row_infop + row_info, png_bytep row)) PNG_PRIVATE; +#endif + +#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED +PNG_EXTERN void png_do_gray_to_rgb PNGARG((png_row_infop row_info, + png_bytep row)) PNG_PRIVATE; +#endif + +#ifdef PNG_READ_PACK_SUPPORTED +PNG_EXTERN void png_do_unpack PNGARG((png_row_infop row_info, + png_bytep row)) PNG_PRIVATE; +#endif + +#ifdef PNG_READ_SHIFT_SUPPORTED +PNG_EXTERN void png_do_unshift PNGARG((png_row_infop row_info, png_bytep row, + png_color_8p sig_bits)) PNG_PRIVATE; +#endif + +#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED) +PNG_EXTERN void png_do_invert PNGARG((png_row_infop row_info, + png_bytep row)) PNG_PRIVATE; +#endif + +#ifdef PNG_READ_16_TO_8_SUPPORTED +PNG_EXTERN void png_do_chop PNGARG((png_row_infop row_info, + png_bytep row)) PNG_PRIVATE; +#endif + +#ifdef PNG_READ_DITHER_SUPPORTED +PNG_EXTERN void png_do_dither PNGARG((png_row_infop row_info, + png_bytep row, png_bytep palette_lookup, + png_bytep dither_lookup)) PNG_PRIVATE; + +# ifdef PNG_CORRECT_PALETTE_SUPPORTED +PNG_EXTERN void png_correct_palette PNGARG((png_structp png_ptr, + png_colorp palette, int num_palette)) PNG_PRIVATE; +# endif +#endif + +#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED) +PNG_EXTERN void png_do_bgr PNGARG((png_row_infop row_info, + png_bytep row)) PNG_PRIVATE; +#endif + +#ifdef PNG_WRITE_PACK_SUPPORTED +PNG_EXTERN void png_do_pack PNGARG((png_row_infop row_info, + png_bytep row, png_uint_32 bit_depth)) PNG_PRIVATE; +#endif + +#ifdef PNG_WRITE_SHIFT_SUPPORTED +PNG_EXTERN void png_do_shift PNGARG((png_row_infop row_info, png_bytep row, + png_color_8p bit_depth)) PNG_PRIVATE; +#endif + +#ifdef PNG_READ_BACKGROUND_SUPPORTED +#ifdef PNG_READ_GAMMA_SUPPORTED +PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row, + png_color_16p trans_values, png_color_16p background, + png_color_16p background_1, + png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1, + png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1, + png_uint_16pp gamma_16_to_1, int gamma_shift)) PNG_PRIVATE; +#else +PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row, + png_color_16p trans_values, png_color_16p background)) PNG_PRIVATE; +#endif +#endif + +#ifdef PNG_READ_GAMMA_SUPPORTED +PNG_EXTERN void png_do_gamma PNGARG((png_row_infop row_info, png_bytep row, + png_bytep gamma_table, png_uint_16pp gamma_16_table, + int gamma_shift)) PNG_PRIVATE; +#endif + +#ifdef PNG_READ_EXPAND_SUPPORTED +PNG_EXTERN void png_do_expand_palette PNGARG((png_row_infop row_info, + png_bytep row, png_colorp palette, png_bytep trans, + int num_trans)) PNG_PRIVATE; +PNG_EXTERN void png_do_expand PNGARG((png_row_infop row_info, + png_bytep row, png_color_16p trans_value)) PNG_PRIVATE; +#endif + +/* The following decodes the appropriate chunks, and does error correction, + * then calls the appropriate callback for the chunk if it is valid. + */ + +/* Decode the IHDR chunk */ +PNG_EXTERN void png_handle_IHDR PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)) PNG_PRIVATE; +PNG_EXTERN void png_handle_PLTE PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +PNG_EXTERN void png_handle_IEND PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); + +#ifdef PNG_READ_bKGD_SUPPORTED +PNG_EXTERN void png_handle_bKGD PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)) PNG_PRIVATE; +#endif + +#ifdef PNG_READ_cHRM_SUPPORTED +PNG_EXTERN void png_handle_cHRM PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)) PNG_PRIVATE; +#endif + +#ifdef PNG_READ_gAMA_SUPPORTED +PNG_EXTERN void png_handle_gAMA PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)) PNG_PRIVATE; +#endif + +#ifdef PNG_READ_hIST_SUPPORTED +PNG_EXTERN void png_handle_hIST PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)) PNG_PRIVATE; +#endif + +#ifdef PNG_READ_iCCP_SUPPORTED +extern void png_handle_iCCP PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +#endif /* PNG_READ_iCCP_SUPPORTED */ + +#ifdef PNG_READ_iTXt_SUPPORTED +PNG_EXTERN void png_handle_iTXt PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)) PNG_PRIVATE; +#endif + +#ifdef PNG_READ_oFFs_SUPPORTED +PNG_EXTERN void png_handle_oFFs PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)) PNG_PRIVATE; +#endif + +#ifdef PNG_READ_pCAL_SUPPORTED +PNG_EXTERN void png_handle_pCAL PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)) PNG_PRIVATE; +#endif + +#ifdef PNG_READ_pHYs_SUPPORTED +PNG_EXTERN void png_handle_pHYs PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)) PNG_PRIVATE; +#endif + +#ifdef PNG_READ_sBIT_SUPPORTED +PNG_EXTERN void png_handle_sBIT PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)) PNG_PRIVATE; +#endif + +#ifdef PNG_READ_sCAL_SUPPORTED +PNG_EXTERN void png_handle_sCAL PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)) PNG_PRIVATE; +#endif + +#ifdef PNG_READ_sPLT_SUPPORTED +extern void png_handle_sPLT PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)) PNG_PRIVATE; +#endif /* PNG_READ_sPLT_SUPPORTED */ + +#ifdef PNG_READ_sRGB_SUPPORTED +PNG_EXTERN void png_handle_sRGB PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)) PNG_PRIVATE; +#endif + +#ifdef PNG_READ_tEXt_SUPPORTED +PNG_EXTERN void png_handle_tEXt PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)) PNG_PRIVATE; +#endif + +#ifdef PNG_READ_tIME_SUPPORTED +PNG_EXTERN void png_handle_tIME PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)) PNG_PRIVATE; +#endif + +#ifdef PNG_READ_tRNS_SUPPORTED +PNG_EXTERN void png_handle_tRNS PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)) PNG_PRIVATE; +#endif + +#ifdef PNG_READ_zTXt_SUPPORTED +PNG_EXTERN void png_handle_zTXt PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)) PNG_PRIVATE; +#endif + +#if defined(PNG_READ_APNG_SUPPORTED) +PNG_EXTERN void png_handle_acTL PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +PNG_EXTERN void png_handle_fcTL PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +PNG_EXTERN void png_have_info PNGARG((png_structp png_ptr, png_infop info_ptr)); +PNG_EXTERN void png_handle_fdAT PNGARG((png_structp png_ptr, png_infop info_ptr, + png_uint_32 length)); +PNG_EXTERN void png_ensure_sequence_number PNGARG((png_structp png_ptr, + png_uint_32 length)); +#endif + +PNG_EXTERN void png_handle_unknown PNGARG((png_structp png_ptr, + png_infop info_ptr, png_uint_32 length)) PNG_PRIVATE; + +PNG_EXTERN void png_check_chunk_name PNGARG((png_structp png_ptr, + png_bytep chunk_name)) PNG_PRIVATE; + +/* Handle the transformations for reading and writing */ +PNG_EXTERN void png_do_read_transformations + PNGARG((png_structp png_ptr)) PNG_PRIVATE; +PNG_EXTERN void png_do_write_transformations + PNGARG((png_structp png_ptr)) PNG_PRIVATE; + +PNG_EXTERN void png_init_read_transformations + PNGARG((png_structp png_ptr)) PNG_PRIVATE; + +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED +PNG_EXTERN void png_push_read_chunk PNGARG((png_structp png_ptr, + png_infop info_ptr)) PNG_PRIVATE; +PNG_EXTERN void png_push_read_sig PNGARG((png_structp png_ptr, + png_infop info_ptr)) PNG_PRIVATE; +PNG_EXTERN void png_push_check_crc PNGARG((png_structp png_ptr)) PNG_PRIVATE; +PNG_EXTERN void png_push_crc_skip PNGARG((png_structp png_ptr, + png_uint_32 length)) PNG_PRIVATE; +PNG_EXTERN void png_push_crc_finish PNGARG((png_structp png_ptr)) PNG_PRIVATE; +PNG_EXTERN void png_push_save_buffer PNGARG((png_structp png_ptr)) PNG_PRIVATE; +PNG_EXTERN void png_push_restore_buffer PNGARG((png_structp png_ptr, + png_bytep buffer, png_size_t buffer_length)) PNG_PRIVATE; +PNG_EXTERN void png_push_read_IDAT PNGARG((png_structp png_ptr)) PNG_PRIVATE; +PNG_EXTERN void png_process_IDAT_data PNGARG((png_structp png_ptr, + png_bytep buffer, png_size_t buffer_length)) PNG_PRIVATE; +PNG_EXTERN void png_push_process_row PNGARG((png_structp png_ptr)) PNG_PRIVATE; +PNG_EXTERN void png_push_handle_unknown PNGARG((png_structp png_ptr, + png_infop info_ptr, png_uint_32 length)) PNG_PRIVATE; +PNG_EXTERN void png_push_have_info PNGARG((png_structp png_ptr, + png_infop info_ptr)) PNG_PRIVATE; +PNG_EXTERN void png_push_have_end PNGARG((png_structp png_ptr, + png_infop info_ptr)) PNG_PRIVATE; +PNG_EXTERN void png_push_have_row PNGARG((png_structp png_ptr, + png_bytep row)) PNG_PRIVATE; +PNG_EXTERN void png_push_read_end PNGARG((png_structp png_ptr, + png_infop info_ptr)) PNG_PRIVATE; +PNG_EXTERN void png_process_some_data PNGARG((png_structp png_ptr, + png_infop info_ptr)) PNG_PRIVATE; +PNG_EXTERN void png_read_push_finish_row + PNGARG((png_structp png_ptr)) PNG_PRIVATE; +#ifdef PNG_READ_tEXt_SUPPORTED +PNG_EXTERN void png_push_handle_tEXt PNGARG((png_structp png_ptr, + png_infop info_ptr, png_uint_32 length)) PNG_PRIVATE; +PNG_EXTERN void png_push_read_tEXt PNGARG((png_structp png_ptr, + png_infop info_ptr)) PNG_PRIVATE; +#endif +#ifdef PNG_READ_zTXt_SUPPORTED +PNG_EXTERN void png_push_handle_zTXt PNGARG((png_structp png_ptr, + png_infop info_ptr, png_uint_32 length)) PNG_PRIVATE; +PNG_EXTERN void png_push_read_zTXt PNGARG((png_structp png_ptr, + png_infop info_ptr)) PNG_PRIVATE; +#endif +#ifdef PNG_READ_iTXt_SUPPORTED +PNG_EXTERN void png_push_handle_iTXt PNGARG((png_structp png_ptr, + png_infop info_ptr, png_uint_32 length)) PNG_PRIVATE; +PNG_EXTERN void png_push_read_iTXt PNGARG((png_structp png_ptr, + png_infop info_ptr)) PNG_PRIVATE; +#endif + +#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ + +#ifdef PNG_MNG_FEATURES_SUPPORTED +PNG_EXTERN void png_do_read_intrapixel PNGARG((png_row_infop row_info, + png_bytep row)) PNG_PRIVATE; +PNG_EXTERN void png_do_write_intrapixel PNGARG((png_row_infop row_info, + png_bytep row)) PNG_PRIVATE; +#endif + +#ifdef PNG_ASSEMBLER_CODE_SUPPORTED +#ifdef PNG_MMX_CODE_SUPPORTED +/* png.c */ /* PRIVATE */ +PNG_EXTERN void png_init_mmx_flags PNGARG((png_structp png_ptr)) PNG_PRIVATE; +#endif +#endif + + +/* The following six functions will be exported in libpng-1.4.0. */ +#if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED) +PNG_EXTERN png_uint_32 png_get_pixels_per_inch PNGARG((png_structp png_ptr, +png_infop info_ptr)); + +PNG_EXTERN png_uint_32 png_get_x_pixels_per_inch PNGARG((png_structp png_ptr, +png_infop info_ptr)); + +PNG_EXTERN png_uint_32 png_get_y_pixels_per_inch PNGARG((png_structp png_ptr, +png_infop info_ptr)); + +PNG_EXTERN float png_get_x_offset_inches PNGARG((png_structp png_ptr, +png_infop info_ptr)); + +PNG_EXTERN float png_get_y_offset_inches PNGARG((png_structp png_ptr, +png_infop info_ptr)); + +#ifdef PNG_pHYs_SUPPORTED +PNG_EXTERN png_uint_32 png_get_pHYs_dpi PNGARG((png_structp png_ptr, +png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)); +#endif /* PNG_pHYs_SUPPORTED */ +#endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */ + +/* Read the chunk header (length + type name) */ +PNG_EXTERN png_uint_32 png_read_chunk_header + PNGARG((png_structp png_ptr)) PNG_PRIVATE; + +/* Added at libpng version 1.2.34 */ +#ifdef PNG_cHRM_SUPPORTED +PNG_EXTERN int png_check_cHRM_fixed PNGARG((png_structp png_ptr, + png_fixed_point int_white_x, png_fixed_point int_white_y, + png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point + int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x, + png_fixed_point int_blue_y)) PNG_PRIVATE; +#endif + +#ifdef PNG_cHRM_SUPPORTED +#ifdef PNG_CHECK_cHRM_SUPPORTED +/* Added at libpng version 1.2.34 */ +PNG_EXTERN void png_64bit_product PNGARG((long v1, long v2, + unsigned long *hi_product, unsigned long *lo_product)) PNG_PRIVATE; +#endif +#endif + +/* Added at libpng version 1.2.41 */ +PNG_EXTERN void png_check_IHDR PNGARG((png_structp png_ptr, + png_uint_32 width, png_uint_32 height, int bit_depth, + int color_type, int interlace_type, int compression_type, + int filter_type)) PNG_PRIVATE; + +/* Added at libpng version 1.2.41 */ +PNG_EXTERN png_voidp png_calloc PNGARG((png_structp png_ptr, + png_uint_32 size)); + +/* Maintainer: Put new private prototypes here ^ and in libpngpf.3 */ + +#endif /* PNG_INTERNAL */ + +#ifdef __cplusplus +} +#endif + +#endif /* PNG_VERSION_INFO_ONLY */ +/* Do not put anything past this line */ +#endif /* PNG_H */ diff --git a/libs/libpng-src/pngbar.jpg b/libs/libpng-src/pngbar.jpg new file mode 100644 index 000000000..70ba8d817 Binary files /dev/null and b/libs/libpng-src/pngbar.jpg differ diff --git a/libs/libpng-src/pngbar.png b/libs/libpng-src/pngbar.png new file mode 100644 index 000000000..49798c8ed Binary files /dev/null and b/libs/libpng-src/pngbar.png differ diff --git a/libs/libpng-src/pngconf.h b/libs/libpng-src/pngconf.h new file mode 100644 index 000000000..23f8313c3 --- /dev/null +++ b/libs/libpng-src/pngconf.h @@ -0,0 +1,1723 @@ + +/* pngconf.h - machine configurable file for libpng + * + * libpng version 1.2.46 - July 9, 2011 + * Copyright (c) 1998-2011 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + */ + +/* Any machine specific code is near the front of this file, so if you + * are configuring libpng for a machine, you may want to read the section + * starting here down to where it starts to typedef png_color, png_text, + * and png_info. + */ + +#ifndef PNGCONF_H +#define PNGCONF_H + +#define PNG_1_2_X + +/* + * PNG_USER_CONFIG has to be defined on the compiler command line. This + * includes the resource compiler for Windows DLL configurations. + */ +#ifdef PNG_USER_CONFIG +# ifndef PNG_USER_PRIVATEBUILD +# define PNG_USER_PRIVATEBUILD +# endif +#include "pngusr.h" +#endif + +#ifdef _WIN32 +#define PNG_WRITE_BGR_SUPPORTED + +#define PNG_NO_MNG_FEATURES +#define PNG_NO_FLOATING_POINT_SUPPORTED + +#define PNG_NO_FREE_ME +#define PNG_NO_WRITE_TRANSFORMS +#define PNG_NO_WRITE_FLUSH +#define PNG_NO_WRITE_EMPTY_PLTE +#define PNG_NO_WRITE_SWAP +#define PNG_NO_WRITE_bKGD +#define PNG_NO_WRITE_cHRM +#define PNG_NO_WRITE_gAMA +#define PNG_NO_WRITE_hIST +#define PNG_NO_WRITE_iCCP +#define PNG_NO_WRITE_oFFs +#define PNG_NO_WRITE_pCAL +#define PNG_NO_WRITE_sCAL +#define PNG_NO_WRITE_pHYs +#define PNG_NO_WRITE_sBIT +#define PNG_NO_WRITE_sPLT +#define PNG_NO_WRITE_sRGB +#define PNG_NO_WRITE_tIME +#define PNG_NO_WRITE_tRNS +#define PNG_NO_WRITE_UNKNOWN_CHUNKS + +#define PNG_NO_READ_iTXt +#define PNG_NO_READ_APNG +#define PNG_NO_READ_UNKNOWN_CHUNKS +#define PNG_NO_READ_USER_TRANSFORM +#define PNG_READ_BGR_SUPPORTED +#define PNG_NO_READ_SWAP_ALPHA +#define PNG_NO_READ_INVERT_ALPHA +#define PNG_NO_READ_SWAP +#define PNG_NO_EASY_ACCESS +#define PNG_NO_PROGRESSIVE_READ + +#define PNG_NO_USER_TRANSFORM_PTR +#define PNG_NO_EASY_ACCESS +#define PNG_NO_USER_MEM + +#define PNG_USE_GLOBAL_ARRAYS +#define PNGAPI __cdecl +#define PNG_STATIC +#define PNG_USE_LOCAL_ARRAYS +#endif + +/* PNG_CONFIGURE_LIBPNG is set by the "configure" script. */ +#ifdef PNG_CONFIGURE_LIBPNG +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#endif + +/* + * Added at libpng-1.2.8 + * + * If you create a private DLL you need to define in "pngusr.h" the followings: + * #define PNG_USER_PRIVATEBUILD + * e.g. #define PNG_USER_PRIVATEBUILD "Build by MyCompany for xyz reasons." + * #define PNG_USER_DLLFNAME_POSTFIX + * e.g. // private DLL "libpng13gx.dll" + * #define PNG_USER_DLLFNAME_POSTFIX "gx" + * + * The following macros are also at your disposal if you want to complete the + * DLL VERSIONINFO structure. + * - PNG_USER_VERSIONINFO_COMMENTS + * - PNG_USER_VERSIONINFO_COMPANYNAME + * - PNG_USER_VERSIONINFO_LEGALTRADEMARKS + */ + +#ifdef __STDC__ +#ifdef SPECIALBUILD +# pragma message("PNG_LIBPNG_SPECIALBUILD (and deprecated SPECIALBUILD)\ + are now LIBPNG reserved macros. Use PNG_USER_PRIVATEBUILD instead.") +#endif + +#ifdef PRIVATEBUILD +# pragma message("PRIVATEBUILD is deprecated.\ + Use PNG_USER_PRIVATEBUILD instead.") +# define PNG_USER_PRIVATEBUILD PRIVATEBUILD +#endif +#endif /* __STDC__ */ + +#ifndef PNG_VERSION_INFO_ONLY + +/* End of material added to libpng-1.2.8 */ + +/* Added at libpng-1.2.19, removed at libpng-1.2.20 because it caused trouble + Restored at libpng-1.2.21 */ +#if !defined(PNG_NO_WARN_UNINITIALIZED_ROW) && \ + !defined(PNG_WARN_UNINITIALIZED_ROW) +# define PNG_WARN_UNINITIALIZED_ROW 1 +#endif +/* End of material added at libpng-1.2.19/1.2.21 */ + +/* This is the size of the compression buffer, and thus the size of + * an IDAT chunk. Make this whatever size you feel is best for your + * machine. One of these will be allocated per png_struct. When this + * is full, it writes the data to the disk, and does some other + * calculations. Making this an extremely small size will slow + * the library down, but you may want to experiment to determine + * where it becomes significant, if you are concerned with memory + * usage. Note that zlib allocates at least 32Kb also. For readers, + * this describes the size of the buffer available to read the data in. + * Unless this gets smaller than the size of a row (compressed), + * it should not make much difference how big this is. + */ + +#ifndef PNG_ZBUF_SIZE +# define PNG_ZBUF_SIZE 8192 +#endif + +/* Enable if you want a write-only libpng */ + +#ifndef PNG_NO_READ_SUPPORTED +# define PNG_READ_SUPPORTED +#endif + +/* Enable if you want a read-only libpng */ + +#ifndef PNG_NO_WRITE_SUPPORTED +# define PNG_WRITE_SUPPORTED +#endif + +/* Enabled in 1.2.41. */ +#ifdef PNG_ALLOW_BENIGN_ERRORS +# define png_benign_error png_warning +# define png_chunk_benign_error png_chunk_warning +#else +# ifndef PNG_BENIGN_ERRORS_SUPPORTED +# define png_benign_error png_error +# define png_chunk_benign_error png_chunk_error +# endif +#endif + +/* Added in libpng-1.2.41 */ +#if !defined(PNG_NO_WARNINGS) && !defined(PNG_WARNINGS_SUPPORTED) +# define PNG_WARNINGS_SUPPORTED +#endif + +#if !defined(PNG_NO_ERROR_TEXT) && !defined(PNG_ERROR_TEXT_SUPPORTED) +# define PNG_ERROR_TEXT_SUPPORTED +#endif + +#if !defined(PNG_NO_CHECK_cHRM) && !defined(PNG_CHECK_cHRM_SUPPORTED) +# define PNG_CHECK_cHRM_SUPPORTED +#endif + +/* Enabled by default in 1.2.0. You can disable this if you don't need to + * support PNGs that are embedded in MNG datastreams + */ +#if !defined(PNG_1_0_X) && !defined(PNG_NO_MNG_FEATURES) +# ifndef PNG_MNG_FEATURES_SUPPORTED +# define PNG_MNG_FEATURES_SUPPORTED +# endif +#endif + +#ifndef PNG_NO_FLOATING_POINT_SUPPORTED +# ifndef PNG_FLOATING_POINT_SUPPORTED +# define PNG_FLOATING_POINT_SUPPORTED +# endif +#endif + +/* If you are running on a machine where you cannot allocate more + * than 64K of memory at once, uncomment this. While libpng will not + * normally need that much memory in a chunk (unless you load up a very + * large file), zlib needs to know how big of a chunk it can use, and + * libpng thus makes sure to check any memory allocation to verify it + * will fit into memory. +#define PNG_MAX_MALLOC_64K + */ +#if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K) +# define PNG_MAX_MALLOC_64K +#endif + +/* Special munging to support doing things the 'cygwin' way: + * 'Normal' png-on-win32 defines/defaults: + * PNG_BUILD_DLL -- building dll + * PNG_USE_DLL -- building an application, linking to dll + * (no define) -- building static library, or building an + * application and linking to the static lib + * 'Cygwin' defines/defaults: + * PNG_BUILD_DLL -- (ignored) building the dll + * (no define) -- (ignored) building an application, linking to the dll + * PNG_STATIC -- (ignored) building the static lib, or building an + * application that links to the static lib. + * ALL_STATIC -- (ignored) building various static libs, or building an + * application that links to the static libs. + * Thus, + * a cygwin user should define either PNG_BUILD_DLL or PNG_STATIC, and + * this bit of #ifdefs will define the 'correct' config variables based on + * that. If a cygwin user *wants* to define 'PNG_USE_DLL' that's okay, but + * unnecessary. + * + * Also, the precedence order is: + * ALL_STATIC (since we can't #undef something outside our namespace) + * PNG_BUILD_DLL + * PNG_STATIC + * (nothing) == PNG_USE_DLL + * + * CYGWIN (2002-01-20): The preceding is now obsolete. With the advent + * of auto-import in binutils, we no longer need to worry about + * __declspec(dllexport) / __declspec(dllimport) and friends. Therefore, + * we don't need to worry about PNG_STATIC or ALL_STATIC when it comes + * to __declspec() stuff. However, we DO need to worry about + * PNG_BUILD_DLL and PNG_STATIC because those change some defaults + * such as CONSOLE_IO and whether GLOBAL_ARRAYS are allowed. + */ +#ifdef __CYGWIN__ +# ifdef ALL_STATIC +# ifdef PNG_BUILD_DLL +# undef PNG_BUILD_DLL +# endif +# ifdef PNG_USE_DLL +# undef PNG_USE_DLL +# endif +# ifdef PNG_DLL +# undef PNG_DLL +# endif +# ifndef PNG_STATIC +# define PNG_STATIC +# endif +# else +# ifdef PNG_BUILD_DLL +# ifdef PNG_STATIC +# undef PNG_STATIC +# endif +# ifdef PNG_USE_DLL +# undef PNG_USE_DLL +# endif +# ifndef PNG_DLL +# define PNG_DLL +# endif +# else +# ifdef PNG_STATIC +# ifdef PNG_USE_DLL +# undef PNG_USE_DLL +# endif +# ifdef PNG_DLL +# undef PNG_DLL +# endif +# else +# ifndef PNG_USE_DLL +# define PNG_USE_DLL +# endif +# ifndef PNG_DLL +# define PNG_DLL +# endif +# endif +# endif +# endif +#endif + +/* This protects us against compilers that run on a windowing system + * and thus don't have or would rather us not use the stdio types: + * stdin, stdout, and stderr. The only one currently used is stderr + * in png_error() and png_warning(). #defining PNG_NO_CONSOLE_IO will + * prevent these from being compiled and used. #defining PNG_NO_STDIO + * will also prevent these, plus will prevent the entire set of stdio + * macros and functions (FILE *, printf, etc.) from being compiled and used, + * unless (PNG_DEBUG > 0) has been #defined. + * + * #define PNG_NO_CONSOLE_IO + * #define PNG_NO_STDIO + */ + +#if !defined(PNG_NO_STDIO) && !defined(PNG_STDIO_SUPPORTED) +# define PNG_STDIO_SUPPORTED +#endif + +#ifdef _WIN32_WCE +# include + /* Console I/O functions are not supported on WindowsCE */ +# define PNG_NO_CONSOLE_IO + /* abort() may not be supported on some/all Windows CE platforms */ +# define PNG_ABORT() exit(-1) +# ifdef PNG_DEBUG +# undef PNG_DEBUG +# endif +#endif + +#ifdef PNG_BUILD_DLL +# ifndef PNG_CONSOLE_IO_SUPPORTED +# ifndef PNG_NO_CONSOLE_IO +# define PNG_NO_CONSOLE_IO +# endif +# endif +#endif + +# ifdef PNG_NO_STDIO +# ifndef PNG_NO_CONSOLE_IO +# define PNG_NO_CONSOLE_IO +# endif +# ifdef PNG_DEBUG +# if (PNG_DEBUG > 0) +# include +# endif +# endif +# else +# ifndef _WIN32_WCE +/* "stdio.h" functions are not supported on WindowsCE */ +# include +# endif +# endif + +#if !(defined PNG_NO_CONSOLE_IO) && !defined(PNG_CONSOLE_IO_SUPPORTED) +# define PNG_CONSOLE_IO_SUPPORTED +#endif + +/* This macro protects us against machines that don't have function + * prototypes (ie K&R style headers). If your compiler does not handle + * function prototypes, define this macro and use the included ansi2knr. + * I've always been able to use _NO_PROTO as the indicator, but you may + * need to drag the empty declaration out in front of here, or change the + * ifdef to suit your own needs. + */ +#ifndef PNGARG + +#ifdef OF /* zlib prototype munger */ +# define PNGARG(arglist) OF(arglist) +#else + +#ifdef _NO_PROTO +# define PNGARG(arglist) () +# ifndef PNG_TYPECAST_NULL +# define PNG_TYPECAST_NULL +# endif +#else +# define PNGARG(arglist) arglist +#endif /* _NO_PROTO */ + + +#endif /* OF */ + +#endif /* PNGARG */ + +/* Try to determine if we are compiling on a Mac. Note that testing for + * just __MWERKS__ is not good enough, because the Codewarrior is now used + * on non-Mac platforms. + */ +#ifndef MACOS +# if (defined(__MWERKS__) && defined(macintosh)) || defined(applec) || \ + defined(THINK_C) || defined(__SC__) || defined(TARGET_OS_MAC) +# define MACOS +# endif +#endif + +/* enough people need this for various reasons to include it here */ +#if !defined(MACOS) && !defined(RISCOS) && !defined(_WIN32_WCE) +# include +#endif + +#if !defined(PNG_SETJMP_NOT_SUPPORTED) && !defined(PNG_NO_SETJMP_SUPPORTED) +# define PNG_SETJMP_SUPPORTED +#endif + +#ifdef PNG_SETJMP_SUPPORTED +/* This is an attempt to force a single setjmp behaviour on Linux. If + * the X config stuff didn't define _BSD_SOURCE we wouldn't need this. + * + * You can bypass this test if you know that your application uses exactly + * the same setjmp.h that was included when libpng was built. Only define + * PNG_SKIP_SETJMP_CHECK while building your application, prior to the + * application's '#include "png.h"'. Don't define PNG_SKIP_SETJMP_CHECK + * while building a separate libpng library for general use. + */ + +# ifndef PNG_SKIP_SETJMP_CHECK +# ifdef __linux__ +# ifdef _BSD_SOURCE +# define PNG_SAVE_BSD_SOURCE +# undef _BSD_SOURCE +# endif +# ifdef _SETJMP_H + /* If you encounter a compiler error here, see the explanation + * near the end of INSTALL. + */ + __pngconf.h__ in libpng already includes setjmp.h; + __dont__ include it again.; +# endif +# endif /* __linux__ */ +# endif /* PNG_SKIP_SETJMP_CHECK */ + + /* include setjmp.h for error handling */ +# include + +# ifdef __linux__ +# ifdef PNG_SAVE_BSD_SOURCE +# ifndef _BSD_SOURCE +# define _BSD_SOURCE +# endif +# undef PNG_SAVE_BSD_SOURCE +# endif +# endif /* __linux__ */ +#endif /* PNG_SETJMP_SUPPORTED */ + +#ifdef BSD +# include +#else +# include +#endif + +/* Other defines for things like memory and the like can go here. */ +#ifdef PNG_INTERNAL + +#include + +/* The functions exported by PNG_EXTERN are PNG_INTERNAL functions, which + * aren't usually used outside the library (as far as I know), so it is + * debatable if they should be exported at all. In the future, when it is + * possible to have run-time registry of chunk-handling functions, some of + * these will be made available again. +#define PNG_EXTERN extern + */ +#define PNG_EXTERN + +/* Other defines specific to compilers can go here. Try to keep + * them inside an appropriate ifdef/endif pair for portability. + */ + +#ifdef PNG_FLOATING_POINT_SUPPORTED +# ifdef MACOS + /* We need to check that hasn't already been included earlier + * as it seems it doesn't agree with , yet we should really use + * if possible. + */ +# if !defined(__MATH_H__) && !defined(__MATH_H) && !defined(__cmath__) +# include +# endif +# else +# include +# endif +# if defined(_AMIGA) && defined(__SASC) && defined(_M68881) + /* Amiga SAS/C: We must include builtin FPU functions when compiling using + * MATH=68881 + */ +# include +# endif +#endif + +/* Codewarrior on NT has linking problems without this. */ +#if (defined(__MWERKS__) && defined(WIN32)) || defined(__STDC__) +# define PNG_ALWAYS_EXTERN +#endif + +/* This provides the non-ANSI (far) memory allocation routines. */ +#if defined(__TURBOC__) && defined(__MSDOS__) +# include +# include +#endif + +/* I have no idea why is this necessary... */ +#if defined(_MSC_VER) && (defined(WIN32) || defined(_Windows) || \ + defined(_WINDOWS) || defined(_WIN32) || defined(__WIN32__)) +# include +#endif + +/* This controls how fine the dithering gets. As this allocates + * a largish chunk of memory (32K), those who are not as concerned + * with dithering quality can decrease some or all of these. + */ +#ifndef PNG_DITHER_RED_BITS +# define PNG_DITHER_RED_BITS 5 +#endif +#ifndef PNG_DITHER_GREEN_BITS +# define PNG_DITHER_GREEN_BITS 5 +#endif +#ifndef PNG_DITHER_BLUE_BITS +# define PNG_DITHER_BLUE_BITS 5 +#endif + +/* This controls how fine the gamma correction becomes when you + * are only interested in 8 bits anyway. Increasing this value + * results in more memory being used, and more pow() functions + * being called to fill in the gamma tables. Don't set this value + * less then 8, and even that may not work (I haven't tested it). + */ + +#ifndef PNG_MAX_GAMMA_8 +# define PNG_MAX_GAMMA_8 11 +#endif + +/* This controls how much a difference in gamma we can tolerate before + * we actually start doing gamma conversion. + */ +#ifndef PNG_GAMMA_THRESHOLD +# define PNG_GAMMA_THRESHOLD 0.05 +#endif + +#endif /* PNG_INTERNAL */ + +/* The following uses const char * instead of char * for error + * and warning message functions, so some compilers won't complain. + * If you do not want to use const, define PNG_NO_CONST here. + */ + +#ifndef PNG_NO_CONST +# define PNG_CONST const +#else +# define PNG_CONST +#endif + +/* The following defines give you the ability to remove code from the + * library that you will not be using. I wish I could figure out how to + * automate this, but I can't do that without making it seriously hard + * on the users. So if you are not using an ability, change the #define + * to and #undef, and that part of the library will not be compiled. If + * your linker can't find a function, you may want to make sure the + * ability is defined here. Some of these depend upon some others being + * defined. I haven't figured out all the interactions here, so you may + * have to experiment awhile to get everything to compile. If you are + * creating or using a shared library, you probably shouldn't touch this, + * as it will affect the size of the structures, and this will cause bad + * things to happen if the library and/or application ever change. + */ + +/* Any features you will not be using can be undef'ed here */ + +/* GR-P, 0.96a: Set "*TRANSFORMS_SUPPORTED as default but allow user + * to turn it off with "*TRANSFORMS_NOT_SUPPORTED" or *PNG_NO_*_TRANSFORMS + * on the compile line, then pick and choose which ones to define without + * having to edit this file. It is safe to use the *TRANSFORMS_NOT_SUPPORTED + * if you only want to have a png-compliant reader/writer but don't need + * any of the extra transformations. This saves about 80 kbytes in a + * typical installation of the library. (PNG_NO_* form added in version + * 1.0.1c, for consistency) + */ + +/* The size of the png_text structure changed in libpng-1.0.6 when + * iTXt support was added. iTXt support was turned off by default through + * libpng-1.2.x, to support old apps that malloc the png_text structure + * instead of calling png_set_text() and letting libpng malloc it. It + * will be turned on by default in libpng-1.4.0. + */ + +#if defined(PNG_1_0_X) || defined (PNG_1_2_X) +# ifndef PNG_NO_iTXt_SUPPORTED +# define PNG_NO_iTXt_SUPPORTED +# endif +# ifndef PNG_NO_READ_iTXt +# define PNG_NO_READ_iTXt +# endif +# ifndef PNG_NO_WRITE_iTXt +# define PNG_NO_WRITE_iTXt +# endif +#endif + +#if !defined(PNG_NO_iTXt_SUPPORTED) +# if !defined(PNG_READ_iTXt_SUPPORTED) && !defined(PNG_NO_READ_iTXt) +# define PNG_READ_iTXt +# endif +# if !defined(PNG_WRITE_iTXt_SUPPORTED) && !defined(PNG_NO_WRITE_iTXt) +# define PNG_WRITE_iTXt +# endif +#endif + +/* The following support, added after version 1.0.0, can be turned off here en + * masse by defining PNG_LEGACY_SUPPORTED in case you need binary compatibility + * with old applications that require the length of png_struct and png_info + * to remain unchanged. + */ + +#ifdef PNG_LEGACY_SUPPORTED +# define PNG_NO_FREE_ME +# define PNG_NO_READ_UNKNOWN_CHUNKS +# define PNG_NO_WRITE_UNKNOWN_CHUNKS +# define PNG_NO_HANDLE_AS_UNKNOWN +# define PNG_NO_READ_USER_CHUNKS +# define PNG_NO_READ_iCCP +# define PNG_NO_WRITE_iCCP +# define PNG_NO_READ_iTXt +# define PNG_NO_WRITE_iTXt +# define PNG_NO_READ_sCAL +# define PNG_NO_WRITE_sCAL +# define PNG_NO_READ_sPLT +# define PNG_NO_WRITE_sPLT +# define PNG_NO_INFO_IMAGE +# define PNG_NO_READ_RGB_TO_GRAY +# define PNG_NO_READ_USER_TRANSFORM +# define PNG_NO_WRITE_USER_TRANSFORM +# define PNG_NO_USER_MEM +# define PNG_NO_READ_EMPTY_PLTE +# define PNG_NO_MNG_FEATURES +# define PNG_NO_FIXED_POINT_SUPPORTED +#endif + +/* Ignore attempt to turn off both floating and fixed point support */ +#if !defined(PNG_FLOATING_POINT_SUPPORTED) || \ + !defined(PNG_NO_FIXED_POINT_SUPPORTED) +# define PNG_FIXED_POINT_SUPPORTED +#endif + +#ifndef PNG_NO_FREE_ME +# define PNG_FREE_ME_SUPPORTED +#endif + +#ifdef PNG_READ_SUPPORTED + +#if !defined(PNG_READ_TRANSFORMS_NOT_SUPPORTED) && \ + !defined(PNG_NO_READ_TRANSFORMS) +# define PNG_READ_TRANSFORMS_SUPPORTED +#endif + +#ifdef PNG_READ_TRANSFORMS_SUPPORTED +# ifndef PNG_NO_READ_EXPAND +# define PNG_READ_EXPAND_SUPPORTED +# endif +# ifndef PNG_NO_READ_SHIFT +# define PNG_READ_SHIFT_SUPPORTED +# endif +# ifndef PNG_NO_READ_PACK +# define PNG_READ_PACK_SUPPORTED +# endif +# ifndef PNG_NO_READ_BGR +# define PNG_READ_BGR_SUPPORTED +# endif +# ifndef PNG_NO_READ_SWAP +# define PNG_READ_SWAP_SUPPORTED +# endif +# ifndef PNG_NO_READ_PACKSWAP +# define PNG_READ_PACKSWAP_SUPPORTED +# endif +# ifndef PNG_NO_READ_INVERT +# define PNG_READ_INVERT_SUPPORTED +# endif +# ifndef PNG_NO_READ_DITHER +# define PNG_READ_DITHER_SUPPORTED +# endif +# ifndef PNG_NO_READ_BACKGROUND +# define PNG_READ_BACKGROUND_SUPPORTED +# endif +# ifndef PNG_NO_READ_16_TO_8 +# define PNG_READ_16_TO_8_SUPPORTED +# endif +# ifndef PNG_NO_READ_FILLER +# define PNG_READ_FILLER_SUPPORTED +# endif +# ifndef PNG_NO_READ_GAMMA +# define PNG_READ_GAMMA_SUPPORTED +# endif +# ifndef PNG_NO_READ_GRAY_TO_RGB +# define PNG_READ_GRAY_TO_RGB_SUPPORTED +# endif +# ifndef PNG_NO_READ_SWAP_ALPHA +# define PNG_READ_SWAP_ALPHA_SUPPORTED +# endif +# ifndef PNG_NO_READ_INVERT_ALPHA +# define PNG_READ_INVERT_ALPHA_SUPPORTED +# endif +# ifndef PNG_NO_READ_STRIP_ALPHA +# define PNG_READ_STRIP_ALPHA_SUPPORTED +# endif +# ifndef PNG_NO_READ_USER_TRANSFORM +# define PNG_READ_USER_TRANSFORM_SUPPORTED +# endif +# ifndef PNG_NO_READ_RGB_TO_GRAY +# define PNG_READ_RGB_TO_GRAY_SUPPORTED +# endif +#endif /* PNG_READ_TRANSFORMS_SUPPORTED */ + +/* PNG_PROGRESSIVE_READ_NOT_SUPPORTED is deprecated. */ +#if !defined(PNG_NO_PROGRESSIVE_READ) && \ + !defined(PNG_PROGRESSIVE_READ_NOT_SUPPORTED) /* if you don't do progressive */ +# define PNG_PROGRESSIVE_READ_SUPPORTED /* reading. This is not talking */ +#endif /* about interlacing capability! You'll */ + /* still have interlacing unless you change the following define: */ +#define PNG_READ_INTERLACING_SUPPORTED /* required for PNG-compliant decoders */ + +/* PNG_NO_SEQUENTIAL_READ_SUPPORTED is deprecated. */ +#if !defined(PNG_NO_SEQUENTIAL_READ) && \ + !defined(PNG_SEQUENTIAL_READ_SUPPORTED) && \ + !defined(PNG_NO_SEQUENTIAL_READ_SUPPORTED) +# define PNG_SEQUENTIAL_READ_SUPPORTED +#endif + +#define PNG_READ_INTERLACING_SUPPORTED /* required in PNG-compliant decoders */ + +#ifndef PNG_NO_READ_COMPOSITE_NODIV +# ifndef PNG_NO_READ_COMPOSITED_NODIV /* libpng-1.0.x misspelling */ +# define PNG_READ_COMPOSITE_NODIV_SUPPORTED /* well tested on Intel, SGI */ +# endif +#endif + +#if defined(PNG_1_0_X) || defined (PNG_1_2_X) +/* Deprecated, will be removed from version 2.0.0. + Use PNG_MNG_FEATURES_SUPPORTED instead. */ +#ifndef PNG_NO_READ_EMPTY_PLTE +# define PNG_READ_EMPTY_PLTE_SUPPORTED +#endif +#endif + +#endif /* PNG_READ_SUPPORTED */ + +#ifdef PNG_WRITE_SUPPORTED + +# if !defined(PNG_WRITE_TRANSFORMS_NOT_SUPPORTED) && \ + !defined(PNG_NO_WRITE_TRANSFORMS) +# define PNG_WRITE_TRANSFORMS_SUPPORTED +#endif + +#ifdef PNG_WRITE_TRANSFORMS_SUPPORTED +# ifndef PNG_NO_WRITE_SHIFT +# define PNG_WRITE_SHIFT_SUPPORTED +# endif +# ifndef PNG_NO_WRITE_PACK +# define PNG_WRITE_PACK_SUPPORTED +# endif +# ifndef PNG_NO_WRITE_BGR +# define PNG_WRITE_BGR_SUPPORTED +# endif +# ifndef PNG_NO_WRITE_SWAP +# define PNG_WRITE_SWAP_SUPPORTED +# endif +# ifndef PNG_NO_WRITE_PACKSWAP +# define PNG_WRITE_PACKSWAP_SUPPORTED +# endif +# ifndef PNG_NO_WRITE_INVERT +# define PNG_WRITE_INVERT_SUPPORTED +# endif +# ifndef PNG_NO_WRITE_FILLER +# define PNG_WRITE_FILLER_SUPPORTED /* same as WRITE_STRIP_ALPHA */ +# endif +# ifndef PNG_NO_WRITE_SWAP_ALPHA +# define PNG_WRITE_SWAP_ALPHA_SUPPORTED +# endif +#ifndef PNG_1_0_X +# ifndef PNG_NO_WRITE_INVERT_ALPHA +# define PNG_WRITE_INVERT_ALPHA_SUPPORTED +# endif +#endif +# ifndef PNG_NO_WRITE_USER_TRANSFORM +# define PNG_WRITE_USER_TRANSFORM_SUPPORTED +# endif +#endif /* PNG_WRITE_TRANSFORMS_SUPPORTED */ + +#if !defined(PNG_NO_WRITE_INTERLACING_SUPPORTED) && \ + !defined(PNG_WRITE_INTERLACING_SUPPORTED) +#define PNG_WRITE_INTERLACING_SUPPORTED /* not required for PNG-compliant + encoders, but can cause trouble + if left undefined */ +#endif + +#if !defined(PNG_NO_WRITE_WEIGHTED_FILTER) && \ + !defined(PNG_WRITE_WEIGHTED_FILTER) && \ + defined(PNG_FLOATING_POINT_SUPPORTED) +# define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED +#endif + +#ifndef PNG_NO_WRITE_FLUSH +# define PNG_WRITE_FLUSH_SUPPORTED +#endif + +#if defined(PNG_1_0_X) || defined (PNG_1_2_X) +/* Deprecated, see PNG_MNG_FEATURES_SUPPORTED, above */ +#ifndef PNG_NO_WRITE_EMPTY_PLTE +# define PNG_WRITE_EMPTY_PLTE_SUPPORTED +#endif +#endif + +#endif /* PNG_WRITE_SUPPORTED */ + +#ifndef PNG_1_0_X +# ifndef PNG_NO_ERROR_NUMBERS +# define PNG_ERROR_NUMBERS_SUPPORTED +# endif +#endif /* PNG_1_0_X */ + +#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ + defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) +# ifndef PNG_NO_USER_TRANSFORM_PTR +# define PNG_USER_TRANSFORM_PTR_SUPPORTED +# endif +#endif + +#ifndef PNG_NO_STDIO +# define PNG_TIME_RFC1123_SUPPORTED +#endif + +/* This adds extra functions in pngget.c for accessing data from the + * info pointer (added in version 0.99) + * png_get_image_width() + * png_get_image_height() + * png_get_bit_depth() + * png_get_color_type() + * png_get_compression_type() + * png_get_filter_type() + * png_get_interlace_type() + * png_get_pixel_aspect_ratio() + * png_get_pixels_per_meter() + * png_get_x_offset_pixels() + * png_get_y_offset_pixels() + * png_get_x_offset_microns() + * png_get_y_offset_microns() + */ +#if !defined(PNG_NO_EASY_ACCESS) && !defined(PNG_EASY_ACCESS_SUPPORTED) +# define PNG_EASY_ACCESS_SUPPORTED +#endif + +/* PNG_ASSEMBLER_CODE was enabled by default in version 1.2.0 + * and removed from version 1.2.20. The following will be removed + * from libpng-1.4.0 +*/ + +#if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_OPTIMIZED_CODE) +# ifndef PNG_OPTIMIZED_CODE_SUPPORTED +# define PNG_OPTIMIZED_CODE_SUPPORTED +# endif +#endif + +#if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_ASSEMBLER_CODE) +# ifndef PNG_ASSEMBLER_CODE_SUPPORTED +# define PNG_ASSEMBLER_CODE_SUPPORTED +# endif + +# if defined(__GNUC__) && defined(__x86_64__) && (__GNUC__ < 4) + /* work around 64-bit gcc compiler bugs in gcc-3.x */ +# if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE) +# define PNG_NO_MMX_CODE +# endif +# endif + +# ifdef __APPLE__ +# if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE) +# define PNG_NO_MMX_CODE +# endif +# endif + +# if (defined(__MWERKS__) && ((__MWERKS__ < 0x0900) || macintosh)) +# if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE) +# define PNG_NO_MMX_CODE +# endif +# endif + +# if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE) +# define PNG_MMX_CODE_SUPPORTED +# endif + +#endif +/* end of obsolete code to be removed from libpng-1.4.0 */ + +/* Added at libpng-1.2.0 */ +#ifndef PNG_1_0_X +#if !defined(PNG_NO_USER_MEM) && !defined(PNG_USER_MEM_SUPPORTED) +# define PNG_USER_MEM_SUPPORTED +#endif +#endif /* PNG_1_0_X */ + +/* Added at libpng-1.2.6 */ +#ifndef PNG_1_0_X +# ifndef PNG_SET_USER_LIMITS_SUPPORTED +# ifndef PNG_NO_SET_USER_LIMITS +# define PNG_SET_USER_LIMITS_SUPPORTED +# endif +# endif +#endif /* PNG_1_0_X */ + +/* Added at libpng-1.0.53 and 1.2.43 */ +#ifndef PNG_USER_LIMITS_SUPPORTED +# ifndef PNG_NO_USER_LIMITS +# define PNG_USER_LIMITS_SUPPORTED +# endif +#endif + +/* Added at libpng-1.0.16 and 1.2.6. To accept all valid PNGS no matter + * how large, set these limits to 0x7fffffffL + */ +#ifndef PNG_USER_WIDTH_MAX +# define PNG_USER_WIDTH_MAX 1000000L +#endif +#ifndef PNG_USER_HEIGHT_MAX +# define PNG_USER_HEIGHT_MAX 1000000L +#endif + +/* Added at libpng-1.2.43. To accept all valid PNGs no matter + * how large, set these two limits to 0. + */ +#ifndef PNG_USER_CHUNK_CACHE_MAX +# define PNG_USER_CHUNK_CACHE_MAX 0 +#endif + +/* Added at libpng-1.2.43 */ +#ifndef PNG_USER_CHUNK_MALLOC_MAX +# define PNG_USER_CHUNK_MALLOC_MAX 0 +#endif + +#ifndef PNG_LITERAL_SHARP +# define PNG_LITERAL_SHARP 0x23 +#endif +#ifndef PNG_LITERAL_LEFT_SQUARE_BRACKET +# define PNG_LITERAL_LEFT_SQUARE_BRACKET 0x5b +#endif +#ifndef PNG_LITERAL_RIGHT_SQUARE_BRACKET +# define PNG_LITERAL_RIGHT_SQUARE_BRACKET 0x5d +#endif + +/* Added at libpng-1.2.34 */ +#ifndef PNG_STRING_NEWLINE +#define PNG_STRING_NEWLINE "\n" +#endif + +/* These are currently experimental features, define them if you want */ + +/* very little testing */ +/* +#ifdef PNG_READ_SUPPORTED +# ifndef PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED +# define PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED +# endif +#endif +*/ + +/* This is only for PowerPC big-endian and 680x0 systems */ +/* some testing */ +/* +#ifndef PNG_READ_BIG_ENDIAN_SUPPORTED +# define PNG_READ_BIG_ENDIAN_SUPPORTED +#endif +*/ + +/* Buggy compilers (e.g., gcc 2.7.2.2) need this */ +/* +#define PNG_NO_POINTER_INDEXING +*/ + +#if !defined(PNG_NO_POINTER_INDEXING) && \ + !defined(PNG_POINTER_INDEXING_SUPPORTED) +# define PNG_POINTER_INDEXING_SUPPORTED +#endif + +/* These functions are turned off by default, as they will be phased out. */ +/* +#define PNG_USELESS_TESTS_SUPPORTED +#define PNG_CORRECT_PALETTE_SUPPORTED +*/ + +/* Any chunks you are not interested in, you can undef here. The + * ones that allocate memory may be expecially important (hIST, + * tEXt, zTXt, tRNS, pCAL). Others will just save time and make png_info + * a bit smaller. + */ + +#if defined(PNG_READ_SUPPORTED) && \ + !defined(PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \ + !defined(PNG_NO_READ_ANCILLARY_CHUNKS) +# define PNG_READ_ANCILLARY_CHUNKS_SUPPORTED +#endif + +#if defined(PNG_WRITE_SUPPORTED) && \ + !defined(PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \ + !defined(PNG_NO_WRITE_ANCILLARY_CHUNKS) +# define PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED +#endif + +#ifdef PNG_READ_ANCILLARY_CHUNKS_SUPPORTED + +#ifdef PNG_NO_READ_TEXT +# define PNG_NO_READ_iTXt +# define PNG_NO_READ_tEXt +# define PNG_NO_READ_zTXt +#endif +#ifndef PNG_NO_READ_bKGD +# define PNG_READ_bKGD_SUPPORTED +# define PNG_bKGD_SUPPORTED +#endif +#ifndef PNG_NO_READ_cHRM +# define PNG_READ_cHRM_SUPPORTED +# define PNG_cHRM_SUPPORTED +#endif +#ifndef PNG_NO_READ_gAMA +# define PNG_READ_gAMA_SUPPORTED +# define PNG_gAMA_SUPPORTED +#endif +#ifndef PNG_NO_READ_hIST +# define PNG_READ_hIST_SUPPORTED +# define PNG_hIST_SUPPORTED +#endif +#ifndef PNG_NO_READ_iCCP +# define PNG_READ_iCCP_SUPPORTED +# define PNG_iCCP_SUPPORTED +#endif +#ifndef PNG_NO_READ_iTXt +# ifndef PNG_READ_iTXt_SUPPORTED +# define PNG_READ_iTXt_SUPPORTED +# endif +# ifndef PNG_iTXt_SUPPORTED +# define PNG_iTXt_SUPPORTED +# endif +#endif +#ifndef PNG_NO_READ_oFFs +# define PNG_READ_oFFs_SUPPORTED +# define PNG_oFFs_SUPPORTED +#endif +#ifndef PNG_NO_READ_pCAL +# define PNG_READ_pCAL_SUPPORTED +# define PNG_pCAL_SUPPORTED +#endif +#ifndef PNG_NO_READ_sCAL +# define PNG_READ_sCAL_SUPPORTED +# define PNG_sCAL_SUPPORTED +#endif +#ifndef PNG_NO_READ_pHYs +# define PNG_READ_pHYs_SUPPORTED +# define PNG_pHYs_SUPPORTED +#endif +#ifndef PNG_NO_READ_sBIT +# define PNG_READ_sBIT_SUPPORTED +# define PNG_sBIT_SUPPORTED +#endif +#ifndef PNG_NO_READ_sPLT +# define PNG_READ_sPLT_SUPPORTED +# define PNG_sPLT_SUPPORTED +#endif +#ifndef PNG_NO_READ_sRGB +# define PNG_READ_sRGB_SUPPORTED +# define PNG_sRGB_SUPPORTED +#endif +#ifndef PNG_NO_READ_tEXt +# define PNG_READ_tEXt_SUPPORTED +# define PNG_tEXt_SUPPORTED +#endif +#ifndef PNG_NO_READ_tIME +# define PNG_READ_tIME_SUPPORTED +# define PNG_tIME_SUPPORTED +#endif +#ifndef PNG_NO_READ_tRNS +# define PNG_READ_tRNS_SUPPORTED +# define PNG_tRNS_SUPPORTED +#endif +#ifndef PNG_NO_READ_zTXt +# define PNG_READ_zTXt_SUPPORTED +# define PNG_zTXt_SUPPORTED +#endif +#ifndef PNG_NO_READ_APNG +# define PNG_READ_APNG_SUPPORTED +# define PNG_APNG_SUPPORTED +#endif +#ifndef PNG_NO_READ_OPT_PLTE +# define PNG_READ_OPT_PLTE_SUPPORTED /* only affects support of the */ +#endif /* optional PLTE chunk in RGB and RGBA images */ +#if defined(PNG_READ_iTXt_SUPPORTED) || defined(PNG_READ_tEXt_SUPPORTED) || \ + defined(PNG_READ_zTXt_SUPPORTED) +# define PNG_READ_TEXT_SUPPORTED +# define PNG_TEXT_SUPPORTED +#endif + +#endif /* PNG_READ_ANCILLARY_CHUNKS_SUPPORTED */ + +#ifndef PNG_NO_READ_UNKNOWN_CHUNKS +# define PNG_READ_UNKNOWN_CHUNKS_SUPPORTED +# ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED +# define PNG_UNKNOWN_CHUNKS_SUPPORTED +# endif +#endif +#if !defined(PNG_NO_READ_USER_CHUNKS) && \ + defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) +# define PNG_READ_USER_CHUNKS_SUPPORTED +# define PNG_USER_CHUNKS_SUPPORTED +# ifdef PNG_NO_READ_UNKNOWN_CHUNKS +# undef PNG_NO_READ_UNKNOWN_CHUNKS +# endif +# ifdef PNG_NO_HANDLE_AS_UNKNOWN +# undef PNG_NO_HANDLE_AS_UNKNOWN +# endif +#endif + +#ifndef PNG_NO_HANDLE_AS_UNKNOWN +# ifndef PNG_HANDLE_AS_UNKNOWN_SUPPORTED +# define PNG_HANDLE_AS_UNKNOWN_SUPPORTED +# endif +#endif + +#ifdef PNG_WRITE_SUPPORTED +#ifdef PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED + +#ifdef PNG_NO_WRITE_TEXT +# define PNG_NO_WRITE_iTXt +# define PNG_NO_WRITE_tEXt +# define PNG_NO_WRITE_zTXt +#endif +#ifndef PNG_NO_WRITE_bKGD +# define PNG_WRITE_bKGD_SUPPORTED +# ifndef PNG_bKGD_SUPPORTED +# define PNG_bKGD_SUPPORTED +# endif +#endif +#ifndef PNG_NO_WRITE_cHRM +# define PNG_WRITE_cHRM_SUPPORTED +# ifndef PNG_cHRM_SUPPORTED +# define PNG_cHRM_SUPPORTED +# endif +#endif +#ifndef PNG_NO_WRITE_gAMA +# define PNG_WRITE_gAMA_SUPPORTED +# ifndef PNG_gAMA_SUPPORTED +# define PNG_gAMA_SUPPORTED +# endif +#endif +#ifndef PNG_NO_WRITE_hIST +# define PNG_WRITE_hIST_SUPPORTED +# ifndef PNG_hIST_SUPPORTED +# define PNG_hIST_SUPPORTED +# endif +#endif +#ifndef PNG_NO_WRITE_iCCP +# define PNG_WRITE_iCCP_SUPPORTED +# ifndef PNG_iCCP_SUPPORTED +# define PNG_iCCP_SUPPORTED +# endif +#endif +#ifndef PNG_NO_WRITE_iTXt +# ifndef PNG_WRITE_iTXt_SUPPORTED +# define PNG_WRITE_iTXt_SUPPORTED +# endif +# ifndef PNG_iTXt_SUPPORTED +# define PNG_iTXt_SUPPORTED +# endif +#endif +#ifndef PNG_NO_WRITE_oFFs +# define PNG_WRITE_oFFs_SUPPORTED +# ifndef PNG_oFFs_SUPPORTED +# define PNG_oFFs_SUPPORTED +# endif +#endif +#ifndef PNG_NO_WRITE_pCAL +# define PNG_WRITE_pCAL_SUPPORTED +# ifndef PNG_pCAL_SUPPORTED +# define PNG_pCAL_SUPPORTED +# endif +#endif +#ifndef PNG_NO_WRITE_sCAL +# define PNG_WRITE_sCAL_SUPPORTED +# ifndef PNG_sCAL_SUPPORTED +# define PNG_sCAL_SUPPORTED +# endif +#endif +#ifndef PNG_NO_WRITE_pHYs +# define PNG_WRITE_pHYs_SUPPORTED +# ifndef PNG_pHYs_SUPPORTED +# define PNG_pHYs_SUPPORTED +# endif +#endif +#ifndef PNG_NO_WRITE_sBIT +# define PNG_WRITE_sBIT_SUPPORTED +# ifndef PNG_sBIT_SUPPORTED +# define PNG_sBIT_SUPPORTED +# endif +#endif +#ifndef PNG_NO_WRITE_sPLT +# define PNG_WRITE_sPLT_SUPPORTED +# ifndef PNG_sPLT_SUPPORTED +# define PNG_sPLT_SUPPORTED +# endif +#endif +#ifndef PNG_NO_WRITE_sRGB +# define PNG_WRITE_sRGB_SUPPORTED +# ifndef PNG_sRGB_SUPPORTED +# define PNG_sRGB_SUPPORTED +# endif +#endif +#ifndef PNG_NO_WRITE_tEXt +# define PNG_WRITE_tEXt_SUPPORTED +# ifndef PNG_tEXt_SUPPORTED +# define PNG_tEXt_SUPPORTED +# endif +#endif +#ifndef PNG_NO_WRITE_tIME +# define PNG_WRITE_tIME_SUPPORTED +# ifndef PNG_tIME_SUPPORTED +# define PNG_tIME_SUPPORTED +# endif +#endif +#ifndef PNG_NO_WRITE_tRNS +# define PNG_WRITE_tRNS_SUPPORTED +# ifndef PNG_tRNS_SUPPORTED +# define PNG_tRNS_SUPPORTED +# endif +#endif +#ifndef PNG_NO_WRITE_zTXt +# define PNG_WRITE_zTXt_SUPPORTED +# ifndef PNG_zTXt_SUPPORTED +# define PNG_zTXt_SUPPORTED +# endif +#endif +#ifndef PNG_NO_WRITE_APNG +# define PNG_WRITE_APNG_SUPPORTED +# ifndef PNG_APNG_SUPPORTED +# define PNG_APNG_SUPPORTED +# endif +#endif +#if defined(PNG_WRITE_iTXt_SUPPORTED) || defined(PNG_WRITE_tEXt_SUPPORTED) || \ + defined(PNG_WRITE_zTXt_SUPPORTED) +# define PNG_WRITE_TEXT_SUPPORTED +# ifndef PNG_TEXT_SUPPORTED +# define PNG_TEXT_SUPPORTED +# endif +#endif + +#ifdef PNG_WRITE_tIME_SUPPORTED +# ifndef PNG_NO_CONVERT_tIME +# ifndef _WIN32_WCE +/* The "tm" structure is not supported on WindowsCE */ +# ifndef PNG_CONVERT_tIME_SUPPORTED +# define PNG_CONVERT_tIME_SUPPORTED +# endif +# endif +# endif +#endif + +#endif /* PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED */ + +#if !defined(PNG_NO_WRITE_FILTER) && !defined(PNG_WRITE_FILTER_SUPPORTED) +# define PNG_WRITE_FILTER_SUPPORTED +#endif + +#ifndef PNG_NO_WRITE_UNKNOWN_CHUNKS +# define PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED +# ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED +# define PNG_UNKNOWN_CHUNKS_SUPPORTED +# endif +#endif + +#ifndef PNG_NO_HANDLE_AS_UNKNOWN +# ifndef PNG_HANDLE_AS_UNKNOWN_SUPPORTED +# define PNG_HANDLE_AS_UNKNOWN_SUPPORTED +# endif +#endif +#endif /* PNG_WRITE_SUPPORTED */ + +/* Turn this off to disable png_read_png() and + * png_write_png() and leave the row_pointers member + * out of the info structure. + */ +#ifndef PNG_NO_INFO_IMAGE +# define PNG_INFO_IMAGE_SUPPORTED +#endif + +/* Need the time information for converting tIME chunks */ +#ifdef PNG_CONVERT_tIME_SUPPORTED + /* "time.h" functions are not supported on WindowsCE */ +# include +#endif + +/* Some typedefs to get us started. These should be safe on most of the + * common platforms. The typedefs should be at least as large as the + * numbers suggest (a png_uint_32 must be at least 32 bits long), but they + * don't have to be exactly that size. Some compilers dislike passing + * unsigned shorts as function parameters, so you may be better off using + * unsigned int for png_uint_16. Likewise, for 64-bit systems, you may + * want to have unsigned int for png_uint_32 instead of unsigned long. + */ + +typedef unsigned long png_uint_32; +typedef long png_int_32; +typedef unsigned short png_uint_16; +typedef short png_int_16; +typedef unsigned char png_byte; + +/* This is usually size_t. It is typedef'ed just in case you need it to + change (I'm not sure if you will or not, so I thought I'd be safe) */ +#ifdef PNG_SIZE_T + typedef PNG_SIZE_T png_size_t; +# define png_sizeof(x) png_convert_size(sizeof(x)) +#else + typedef size_t png_size_t; +# define png_sizeof(x) sizeof(x) +#endif + +/* The following is needed for medium model support. It cannot be in the + * PNG_INTERNAL section. Needs modification for other compilers besides + * MSC. Model independent support declares all arrays and pointers to be + * large using the far keyword. The zlib version used must also support + * model independent data. As of version zlib 1.0.4, the necessary changes + * have been made in zlib. The USE_FAR_KEYWORD define triggers other + * changes that are needed. (Tim Wegner) + */ + +/* Separate compiler dependencies (problem here is that zlib.h always + defines FAR. (SJT) */ +#ifdef __BORLANDC__ +# if defined(__LARGE__) || defined(__HUGE__) || defined(__COMPACT__) +# define LDATA 1 +# else +# define LDATA 0 +# endif + /* GRR: why is Cygwin in here? Cygwin is not Borland C... */ +# if !defined(__WIN32__) && !defined(__FLAT__) && !defined(__CYGWIN__) +# define PNG_MAX_MALLOC_64K +# if (LDATA != 1) +# ifndef FAR +# define FAR __far +# endif +# define USE_FAR_KEYWORD +# endif /* LDATA != 1 */ + /* Possibly useful for moving data out of default segment. + * Uncomment it if you want. Could also define FARDATA as + * const if your compiler supports it. (SJT) +# define FARDATA FAR + */ +# endif /* __WIN32__, __FLAT__, __CYGWIN__ */ +#endif /* __BORLANDC__ */ + + +/* Suggest testing for specific compiler first before testing for + * FAR. The Watcom compiler defines both __MEDIUM__ and M_I86MM, + * making reliance oncertain keywords suspect. (SJT) + */ + +/* MSC Medium model */ +#ifdef FAR +# ifdef M_I86MM +# define USE_FAR_KEYWORD +# define FARDATA FAR +# include +# endif +#endif + +/* SJT: default case */ +#ifndef FAR +# define FAR +#endif + +/* At this point FAR is always defined */ +#ifndef FARDATA +# define FARDATA +#endif + +/* Typedef for floating-point numbers that are converted + to fixed-point with a multiple of 100,000, e.g., int_gamma */ +typedef png_int_32 png_fixed_point; + +/* Add typedefs for pointers */ +typedef void FAR * png_voidp; +typedef png_byte FAR * png_bytep; +typedef png_uint_32 FAR * png_uint_32p; +typedef png_int_32 FAR * png_int_32p; +typedef png_uint_16 FAR * png_uint_16p; +typedef png_int_16 FAR * png_int_16p; +typedef PNG_CONST char FAR * png_const_charp; +typedef char FAR * png_charp; +typedef png_fixed_point FAR * png_fixed_point_p; + +#ifndef PNG_NO_STDIO +#ifdef _WIN32_WCE +typedef HANDLE png_FILE_p; +#else +typedef FILE * png_FILE_p; +#endif +#endif + +#ifdef PNG_FLOATING_POINT_SUPPORTED +typedef double FAR * png_doublep; +#endif + +/* Pointers to pointers; i.e. arrays */ +typedef png_byte FAR * FAR * png_bytepp; +typedef png_uint_32 FAR * FAR * png_uint_32pp; +typedef png_int_32 FAR * FAR * png_int_32pp; +typedef png_uint_16 FAR * FAR * png_uint_16pp; +typedef png_int_16 FAR * FAR * png_int_16pp; +typedef PNG_CONST char FAR * FAR * png_const_charpp; +typedef char FAR * FAR * png_charpp; +typedef png_fixed_point FAR * FAR * png_fixed_point_pp; +#ifdef PNG_FLOATING_POINT_SUPPORTED +typedef double FAR * FAR * png_doublepp; +#endif + +/* Pointers to pointers to pointers; i.e., pointer to array */ +typedef char FAR * FAR * FAR * png_charppp; + +#if defined(PNG_1_0_X) || defined(PNG_1_2_X) +/* SPC - Is this stuff deprecated? */ +/* It'll be removed as of libpng-1.4.0 - GR-P */ +/* libpng typedefs for types in zlib. If zlib changes + * or another compression library is used, then change these. + * Eliminates need to change all the source files. + */ +typedef charf * png_zcharp; +typedef charf * FAR * png_zcharpp; +typedef z_stream FAR * png_zstreamp; +#endif /* (PNG_1_0_X) || defined(PNG_1_2_X) */ + +/* + * Define PNG_BUILD_DLL if the module being built is a Windows + * LIBPNG DLL. + * + * Define PNG_USE_DLL if you want to *link* to the Windows LIBPNG DLL. + * It is equivalent to Microsoft predefined macro _DLL that is + * automatically defined when you compile using the share + * version of the CRT (C Run-Time library) + * + * The cygwin mods make this behavior a little different: + * Define PNG_BUILD_DLL if you are building a dll for use with cygwin + * Define PNG_STATIC if you are building a static library for use with cygwin, + * -or- if you are building an application that you want to link to the + * static library. + * PNG_USE_DLL is defined by default (no user action needed) unless one of + * the other flags is defined. + */ + +#if !defined(PNG_DLL) && (defined(PNG_BUILD_DLL) || defined(PNG_USE_DLL)) +# define PNG_DLL +#endif +/* If CYGWIN, then disallow GLOBAL ARRAYS unless building a static lib. + * When building a static lib, default to no GLOBAL ARRAYS, but allow + * command-line override + */ +#ifdef __CYGWIN__ +# ifndef PNG_STATIC +# ifdef PNG_USE_GLOBAL_ARRAYS +# undef PNG_USE_GLOBAL_ARRAYS +# endif +# ifndef PNG_USE_LOCAL_ARRAYS +# define PNG_USE_LOCAL_ARRAYS +# endif +# else +# if defined(PNG_USE_LOCAL_ARRAYS) || defined(PNG_NO_GLOBAL_ARRAYS) +# ifdef PNG_USE_GLOBAL_ARRAYS +# undef PNG_USE_GLOBAL_ARRAYS +# endif +# endif +# endif +# if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS) +# define PNG_USE_LOCAL_ARRAYS +# endif +#endif + +/* Do not use global arrays (helps with building DLL's) + * They are no longer used in libpng itself, since version 1.0.5c, + * but might be required for some pre-1.0.5c applications. + */ +#if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS) +# if defined(PNG_NO_GLOBAL_ARRAYS) || \ + (defined(__GNUC__) && defined(PNG_DLL)) || defined(_MSC_VER) +# define PNG_USE_LOCAL_ARRAYS +# else +# define PNG_USE_GLOBAL_ARRAYS +# endif +#endif + +#ifdef __CYGWIN__ +# undef PNGAPI +# define PNGAPI __cdecl +# undef PNG_IMPEXP +# define PNG_IMPEXP +#endif + +/* If you define PNGAPI, e.g., with compiler option "-DPNGAPI=__stdcall", + * you may get warnings regarding the linkage of png_zalloc and png_zfree. + * Don't ignore those warnings; you must also reset the default calling + * convention in your compiler to match your PNGAPI, and you must build + * zlib and your applications the same way you build libpng. + */ + +#if defined(__MINGW32__) && !defined(PNG_MODULEDEF) +# ifndef PNG_NO_MODULEDEF +# define PNG_NO_MODULEDEF +# endif +#endif + +#if !defined(PNG_IMPEXP) && defined(PNG_BUILD_DLL) && !defined(PNG_NO_MODULEDEF) +# define PNG_IMPEXP +#endif + +#if defined(PNG_DLL) || defined(_DLL) || defined(__DLL__ ) || \ + (( defined(_Windows) || defined(_WINDOWS) || \ + defined(WIN32) || defined(_WIN32) || defined(__WIN32__) )) + +# ifndef PNGAPI +# if defined(__GNUC__) || (defined (_MSC_VER) && (_MSC_VER >= 800)) +# define PNGAPI __cdecl +# else +# define PNGAPI _cdecl +# endif +# endif + +# if !defined(PNG_IMPEXP) && (!defined(PNG_DLL) || \ + 0 /* WINCOMPILER_WITH_NO_SUPPORT_FOR_DECLIMPEXP */) +# define PNG_IMPEXP +# endif + +# ifndef PNG_IMPEXP + +# define PNG_EXPORT_TYPE1(type,symbol) PNG_IMPEXP type PNGAPI symbol +# define PNG_EXPORT_TYPE2(type,symbol) type PNG_IMPEXP PNGAPI symbol + + /* Borland/Microsoft */ +# if defined(_MSC_VER) || defined(__BORLANDC__) +# if (_MSC_VER >= 800) || (__BORLANDC__ >= 0x500) +# define PNG_EXPORT PNG_EXPORT_TYPE1 +# else +# define PNG_EXPORT PNG_EXPORT_TYPE2 +# ifdef PNG_BUILD_DLL +# define PNG_IMPEXP __export +# else +# define PNG_IMPEXP /*__import */ /* doesn't exist AFAIK in + VC++ */ +# endif /* Exists in Borland C++ for + C++ classes (== huge) */ +# endif +# endif + +# ifndef PNG_IMPEXP +# ifdef PNG_BUILD_DLL +# define PNG_IMPEXP __declspec(dllexport) +# else +# define PNG_IMPEXP __declspec(dllimport) +# endif +# endif +# endif /* PNG_IMPEXP */ +#else /* !(DLL || non-cygwin WINDOWS) */ +# if (defined(__IBMC__) || defined(__IBMCPP__)) && defined(__OS2__) +# ifndef PNGAPI +# define PNGAPI _System +# endif +# else +# if 0 /* ... other platforms, with other meanings */ +# endif +# endif +#endif + +#ifndef PNGAPI +# define PNGAPI +#endif +#ifndef PNG_IMPEXP +# define PNG_IMPEXP +#endif + +#ifdef PNG_BUILDSYMS +# ifndef PNG_EXPORT +# define PNG_EXPORT(type,symbol) PNG_FUNCTION_EXPORT symbol END +# endif +# ifdef PNG_USE_GLOBAL_ARRAYS +# ifndef PNG_EXPORT_VAR +# define PNG_EXPORT_VAR(type) PNG_DATA_EXPORT +# endif +# endif +#endif + +#ifndef PNG_EXPORT +# define PNG_EXPORT(type,symbol) PNG_IMPEXP type PNGAPI symbol +#endif + +#ifdef PNG_USE_GLOBAL_ARRAYS +# ifndef PNG_EXPORT_VAR +# define PNG_EXPORT_VAR(type) extern PNG_IMPEXP type +# endif +#endif + +#ifdef PNG_PEDANTIC_WARNINGS +# ifndef PNG_PEDANTIC_WARNINGS_SUPPORTED +# define PNG_PEDANTIC_WARNINGS_SUPPORTED +# endif +#endif + +#ifdef PNG_PEDANTIC_WARNINGS_SUPPORTED +/* Support for compiler specific function attributes. These are used + * so that where compiler support is available incorrect use of API + * functions in png.h will generate compiler warnings. Added at libpng + * version 1.2.41. + */ +# ifdef __GNUC__ +# ifndef PNG_USE_RESULT +# define PNG_USE_RESULT __attribute__((__warn_unused_result__)) +# endif +# ifndef PNG_NORETURN +# define PNG_NORETURN __attribute__((__noreturn__)) +# endif +# ifndef PNG_ALLOCATED +# define PNG_ALLOCATED __attribute__((__malloc__)) +# endif + + /* This specifically protects structure members that should only be + * accessed from within the library, therefore should be empty during + * a library build. + */ +# ifndef PNG_DEPRECATED +# define PNG_DEPRECATED __attribute__((__deprecated__)) +# endif +# ifndef PNG_DEPSTRUCT +# define PNG_DEPSTRUCT __attribute__((__deprecated__)) +# endif +# ifndef PNG_PRIVATE +# if 0 /* Doesn't work so we use deprecated instead*/ +# define PNG_PRIVATE \ + __attribute__((warning("This function is not exported by libpng."))) +# else +# define PNG_PRIVATE \ + __attribute__((__deprecated__)) +# endif +# endif /* PNG_PRIVATE */ +# endif /* __GNUC__ */ +#endif /* PNG_PEDANTIC_WARNINGS */ + +#ifndef PNG_DEPRECATED +# define PNG_DEPRECATED /* Use of this function is deprecated */ +#endif +#ifndef PNG_USE_RESULT +# define PNG_USE_RESULT /* The result of this function must be checked */ +#endif +#ifndef PNG_NORETURN +# define PNG_NORETURN /* This function does not return */ +#endif +#ifndef PNG_ALLOCATED +# define PNG_ALLOCATED /* The result of the function is new memory */ +#endif +#ifndef PNG_DEPSTRUCT +# define PNG_DEPSTRUCT /* Access to this struct member is deprecated */ +#endif +#ifndef PNG_PRIVATE +# define PNG_PRIVATE /* This is a private libpng function */ +#endif + +/* User may want to use these so they are not in PNG_INTERNAL. Any library + * functions that are passed far data must be model independent. + */ + +#ifndef PNG_ABORT +# define PNG_ABORT() abort() +#endif + +#ifdef PNG_SETJMP_SUPPORTED +# define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf) +#else +# define png_jmpbuf(png_ptr) \ + (LIBPNG_WAS_COMPILED_WITH__PNG_SETJMP_NOT_SUPPORTED) +#endif + +#ifdef USE_FAR_KEYWORD /* memory model independent fns */ +/* Use this to make far-to-near assignments */ +# define CHECK 1 +# define NOCHECK 0 +# define CVT_PTR(ptr) (png_far_to_near(png_ptr,ptr,CHECK)) +# define CVT_PTR_NOCHECK(ptr) (png_far_to_near(png_ptr,ptr,NOCHECK)) +# define png_snprintf _fsnprintf /* Added to v 1.2.19 */ +# define png_strlen _fstrlen +# define png_memcmp _fmemcmp /* SJT: added */ +# define png_memcpy _fmemcpy +# define png_memset _fmemset +#else /* Use the usual functions */ +# define CVT_PTR(ptr) (ptr) +# define CVT_PTR_NOCHECK(ptr) (ptr) +# ifndef PNG_NO_SNPRINTF +# ifdef _MSC_VER +# define png_snprintf _snprintf /* Added to v 1.2.19 */ +# define png_snprintf2 _snprintf +# define png_snprintf6 _snprintf +# else +# define png_snprintf snprintf /* Added to v 1.2.19 */ +# define png_snprintf2 snprintf +# define png_snprintf6 snprintf +# endif +# else + /* You don't have or don't want to use snprintf(). Caution: Using + * sprintf instead of snprintf exposes your application to accidental + * or malevolent buffer overflows. If you don't have snprintf() + * as a general rule you should provide one (you can get one from + * Portable OpenSSH). + */ +# define png_snprintf(s1,n,fmt,x1) sprintf(s1,fmt,x1) +# define png_snprintf2(s1,n,fmt,x1,x2) sprintf(s1,fmt,x1,x2) +# define png_snprintf6(s1,n,fmt,x1,x2,x3,x4,x5,x6) \ + sprintf(s1,fmt,x1,x2,x3,x4,x5,x6) +# endif +# define png_strlen strlen +# define png_memcmp memcmp /* SJT: added */ +# define png_memcpy memcpy +# define png_memset memset +#endif +/* End of memory model independent support */ + +/* Just a little check that someone hasn't tried to define something + * contradictory. + */ +#if (PNG_ZBUF_SIZE > 65536L) && defined(PNG_MAX_MALLOC_64K) +# undef PNG_ZBUF_SIZE +# define PNG_ZBUF_SIZE 65536L +#endif + +/* Added at libpng-1.2.8 */ +#endif /* PNG_VERSION_INFO_ONLY */ + +#endif /* PNGCONF_H */ diff --git a/libs/libpng-src/pngerror.c b/libs/libpng-src/pngerror.c new file mode 100644 index 000000000..025d52e77 --- /dev/null +++ b/libs/libpng-src/pngerror.c @@ -0,0 +1,396 @@ + +/* pngerror.c - stub functions for i/o and memory allocation + * + * Last changed in libpng 1.2.45 [July 7, 2011] + * Copyright (c) 1998-2011 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + * + * This file provides a location for all error handling. Users who + * need special error handling are expected to write replacement functions + * and use png_set_error_fn() to use those functions. See the instructions + * at each function. + */ + +#define PNG_INTERNAL +#define PNG_NO_PEDANTIC_WARNINGS +#include "png.h" +#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) + +static void /* PRIVATE */ +png_default_error PNGARG((png_structp png_ptr, + png_const_charp error_message)) PNG_NORETURN; +#ifdef PNG_WARNINGS_SUPPORTED +static void /* PRIVATE */ +png_default_warning PNGARG((png_structp png_ptr, + png_const_charp warning_message)); +#endif /* PNG_WARNINGS_SUPPORTED */ + +/* This function is called whenever there is a fatal error. This function + * should not be changed. If there is a need to handle errors differently, + * you should supply a replacement error function and use png_set_error_fn() + * to replace the error function at run-time. + */ +#ifdef PNG_ERROR_TEXT_SUPPORTED +void PNGAPI +png_error(png_structp png_ptr, png_const_charp error_message) +{ +#ifdef PNG_ERROR_NUMBERS_SUPPORTED + char msg[16]; + if (png_ptr != NULL) + { + if (png_ptr->flags& + (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT)) + { + if (*error_message == PNG_LITERAL_SHARP) + { + /* Strip "#nnnn " from beginning of error message. */ + int offset; + for (offset = 1; offset<15; offset++) + if (error_message[offset] == ' ') + break; + if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT) + { + int i; + for (i = 0; i < offset - 1; i++) + msg[i] = error_message[i + 1]; + msg[i - 1] = '\0'; + error_message = msg; + } + else + error_message += offset; + } + else + { + if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT) + { + msg[0] = '0'; + msg[1] = '\0'; + error_message = msg; + } + } + } + } +#endif + if (png_ptr != NULL && png_ptr->error_fn != NULL) + (*(png_ptr->error_fn))(png_ptr, error_message); + + /* If the custom handler doesn't exist, or if it returns, + use the default handler, which will not return. */ + png_default_error(png_ptr, error_message); +} +#else +void PNGAPI +png_err(png_structp png_ptr) +{ + /* Prior to 1.2.45 the error_fn received a NULL pointer, expressed + * erroneously as '\0', instead of the empty string "". This was + * apparently an error, introduced in libpng-1.2.20, and png_default_error + * will crash in this case. + */ + if (png_ptr != NULL && png_ptr->error_fn != NULL) + (*(png_ptr->error_fn))(png_ptr, ""); + + /* If the custom handler doesn't exist, or if it returns, + use the default handler, which will not return. */ + png_default_error(png_ptr, ""); +} +#endif /* PNG_ERROR_TEXT_SUPPORTED */ + +#ifdef PNG_WARNINGS_SUPPORTED +/* This function is called whenever there is a non-fatal error. This function + * should not be changed. If there is a need to handle warnings differently, + * you should supply a replacement warning function and use + * png_set_error_fn() to replace the warning function at run-time. + */ +void PNGAPI +png_warning(png_structp png_ptr, png_const_charp warning_message) +{ + int offset = 0; + if (png_ptr != NULL) + { +#ifdef PNG_ERROR_NUMBERS_SUPPORTED + if (png_ptr->flags& + (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT)) +#endif + { + if (*warning_message == PNG_LITERAL_SHARP) + { + for (offset = 1; offset < 15; offset++) + if (warning_message[offset] == ' ') + break; + } + } + } + if (png_ptr != NULL && png_ptr->warning_fn != NULL) + (*(png_ptr->warning_fn))(png_ptr, warning_message + offset); + else + png_default_warning(png_ptr, warning_message + offset); +} +#endif /* PNG_WARNINGS_SUPPORTED */ + +#ifdef PNG_BENIGN_ERRORS_SUPPORTED +void PNGAPI +png_benign_error(png_structp png_ptr, png_const_charp error_message) +{ + if (png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN) + png_warning(png_ptr, error_message); + else + png_error(png_ptr, error_message); +} +#endif + +/* These utilities are used internally to build an error message that relates + * to the current chunk. The chunk name comes from png_ptr->chunk_name, + * this is used to prefix the message. The message is limited in length + * to 63 bytes, the name characters are output as hex digits wrapped in [] + * if the character is invalid. + */ +#define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97)) +static PNG_CONST char png_digit[16] = { + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', + 'A', 'B', 'C', 'D', 'E', 'F' +}; + +#define PNG_MAX_ERROR_TEXT 64 +#if defined(PNG_WARNINGS_SUPPORTED) || defined(PNG_ERROR_TEXT_SUPPORTED) +static void /* PRIVATE */ +png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp + error_message) +{ + int iout = 0, iin = 0; + + while (iin < 4) + { + int c = png_ptr->chunk_name[iin++]; + if (isnonalpha(c)) + { + buffer[iout++] = PNG_LITERAL_LEFT_SQUARE_BRACKET; + buffer[iout++] = png_digit[(c & 0xf0) >> 4]; + buffer[iout++] = png_digit[c & 0x0f]; + buffer[iout++] = PNG_LITERAL_RIGHT_SQUARE_BRACKET; + } + else + { + buffer[iout++] = (png_byte)c; + } + } + + if (error_message == NULL) + buffer[iout] = '\0'; + else + { + buffer[iout++] = ':'; + buffer[iout++] = ' '; + + iin = 0; + while (iin < PNG_MAX_ERROR_TEXT-1 && error_message[iin] != '\0') + buffer[iout++] = error_message[iin++]; + + /* iin < PNG_MAX_ERROR_TEXT, so the following is safe: */ + buffer[iout] = '\0'; + } +} + +#ifdef PNG_READ_SUPPORTED +void PNGAPI +png_chunk_error(png_structp png_ptr, png_const_charp error_message) +{ + char msg[18+PNG_MAX_ERROR_TEXT]; + if (png_ptr == NULL) + png_error(png_ptr, error_message); + else + { + png_format_buffer(png_ptr, msg, error_message); + png_error(png_ptr, msg); + } +} +#endif /* PNG_READ_SUPPORTED */ +#endif /* PNG_WARNINGS_SUPPORTED || PNG_ERROR_TEXT_SUPPORTED */ + +#ifdef PNG_WARNINGS_SUPPORTED +void PNGAPI +png_chunk_warning(png_structp png_ptr, png_const_charp warning_message) +{ + char msg[18+PNG_MAX_ERROR_TEXT]; + if (png_ptr == NULL) + png_warning(png_ptr, warning_message); + else + { + png_format_buffer(png_ptr, msg, warning_message); + png_warning(png_ptr, msg); + } +} +#endif /* PNG_WARNINGS_SUPPORTED */ + +#ifdef PNG_READ_SUPPORTED +#ifdef PNG_BENIGN_ERRORS_SUPPORTED +void PNGAPI +png_chunk_benign_error(png_structp png_ptr, png_const_charp error_message) +{ + if (png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN) + png_chunk_warning(png_ptr, error_message); + else + png_chunk_error(png_ptr, error_message); +} +#endif +#endif /* PNG_READ_SUPPORTED */ + +/* This is the default error handling function. Note that replacements for + * this function MUST NOT RETURN, or the program will likely crash. This + * function is used by default, or if the program supplies NULL for the + * error function pointer in png_set_error_fn(). + */ +static void /* PRIVATE */ +png_default_error(png_structp png_ptr, png_const_charp error_message) +{ +#ifdef PNG_CONSOLE_IO_SUPPORTED +#ifdef PNG_ERROR_NUMBERS_SUPPORTED + if (*error_message == PNG_LITERAL_SHARP) + { + /* Strip "#nnnn " from beginning of error message. */ + int offset; + char error_number[16]; + for (offset = 0; offset<15; offset++) + { + error_number[offset] = error_message[offset + 1]; + if (error_message[offset] == ' ') + break; + } + if ((offset > 1) && (offset < 15)) + { + error_number[offset - 1] = '\0'; + fprintf(stderr, "libpng error no. %s: %s", + error_number, error_message + offset + 1); + fprintf(stderr, PNG_STRING_NEWLINE); + } + else + { + fprintf(stderr, "libpng error: %s, offset=%d", + error_message, offset); + fprintf(stderr, PNG_STRING_NEWLINE); + } + } + else +#endif + { + fprintf(stderr, "libpng error: %s", error_message); + fprintf(stderr, PNG_STRING_NEWLINE); + } +#endif + +#ifdef PNG_SETJMP_SUPPORTED + if (png_ptr) + { +# ifdef USE_FAR_KEYWORD + { + jmp_buf jmpbuf; + png_memcpy(jmpbuf, png_ptr->jmpbuf, png_sizeof(jmp_buf)); + longjmp(jmpbuf,1); + } +# else + longjmp(png_ptr->jmpbuf, 1); +# endif + } +#endif + /* Here if not setjmp support or if png_ptr is null. */ + PNG_ABORT(); +#ifndef PNG_CONSOLE_IO_SUPPORTED + error_message = error_message; /* Make compiler happy */ +#endif +} + +#ifdef PNG_WARNINGS_SUPPORTED +/* This function is called when there is a warning, but the library thinks + * it can continue anyway. Replacement functions don't have to do anything + * here if you don't want them to. In the default configuration, png_ptr is + * not used, but it is passed in case it may be useful. + */ +static void /* PRIVATE */ +png_default_warning(png_structp png_ptr, png_const_charp warning_message) +{ +#ifdef PNG_CONSOLE_IO_SUPPORTED +# ifdef PNG_ERROR_NUMBERS_SUPPORTED + if (*warning_message == PNG_LITERAL_SHARP) + { + int offset; + char warning_number[16]; + for (offset = 0; offset < 15; offset++) + { + warning_number[offset] = warning_message[offset + 1]; + if (warning_message[offset] == ' ') + break; + } + if ((offset > 1) && (offset < 15)) + { + warning_number[offset + 1] = '\0'; + fprintf(stderr, "libpng warning no. %s: %s", + warning_number, warning_message + offset); + fprintf(stderr, PNG_STRING_NEWLINE); + } + else + { + fprintf(stderr, "libpng warning: %s", + warning_message); + fprintf(stderr, PNG_STRING_NEWLINE); + } + } + else +# endif + { + fprintf(stderr, "libpng warning: %s", warning_message); + fprintf(stderr, PNG_STRING_NEWLINE); + } +#else + warning_message = warning_message; /* Make compiler happy */ +#endif + png_ptr = png_ptr; /* Make compiler happy */ +} +#endif /* PNG_WARNINGS_SUPPORTED */ + +/* This function is called when the application wants to use another method + * of handling errors and warnings. Note that the error function MUST NOT + * return to the calling routine or serious problems will occur. The return + * method used in the default routine calls longjmp(png_ptr->jmpbuf, 1) + */ +void PNGAPI +png_set_error_fn(png_structp png_ptr, png_voidp error_ptr, + png_error_ptr error_fn, png_error_ptr warning_fn) +{ + if (png_ptr == NULL) + return; + png_ptr->error_ptr = error_ptr; + png_ptr->error_fn = error_fn; + png_ptr->warning_fn = warning_fn; +} + + +/* This function returns a pointer to the error_ptr associated with the user + * functions. The application should free any memory associated with this + * pointer before png_write_destroy and png_read_destroy are called. + */ +png_voidp PNGAPI +png_get_error_ptr(png_structp png_ptr) +{ + if (png_ptr == NULL) + return NULL; + return ((png_voidp)png_ptr->error_ptr); +} + + +#ifdef PNG_ERROR_NUMBERS_SUPPORTED +void PNGAPI +png_set_strip_error_numbers(png_structp png_ptr, png_uint_32 strip_mode) +{ + if (png_ptr != NULL) + { + png_ptr->flags &= + ((~(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))&strip_mode); + } +} +#endif +#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ diff --git a/libs/libpng-src/pnggccrd.c b/libs/libpng-src/pnggccrd.c new file mode 100644 index 000000000..78b8a7e41 --- /dev/null +++ b/libs/libpng-src/pnggccrd.c @@ -0,0 +1,103 @@ +/* pnggccrd.c was removed from libpng-1.2.20. */ + +/* This code snippet is for use by configure's compilation test. */ + +#if (!defined _MSC_VER) && \ + defined(PNG_ASSEMBLER_CODE_SUPPORTED) && \ + defined(PNG_MMX_CODE_SUPPORTED) + +int PNGAPI png_dummy_mmx_support(void); + +static int _mmx_supported = 2; // 0: no MMX; 1: MMX supported; 2: not tested + +int PNGAPI +png_dummy_mmx_support(void) __attribute__((noinline)); + +int PNGAPI +png_dummy_mmx_support(void) +{ + int result; +#ifdef PNG_MMX_CODE_SUPPORTED // superfluous, but what the heck + __asm__ __volatile__ ( +#ifdef __x86_64__ + "pushq %%rbx \n\t" // rbx gets clobbered by CPUID instruction + "pushq %%rcx \n\t" // so does rcx... + "pushq %%rdx \n\t" // ...and rdx (but rcx & rdx safe on Linux) + "pushfq \n\t" // save Eflag to stack + "popq %%rax \n\t" // get Eflag from stack into rax + "movq %%rax, %%rcx \n\t" // make another copy of Eflag in rcx + "xorl $0x200000, %%eax \n\t" // toggle ID bit in Eflag (i.e., bit 21) + "pushq %%rax \n\t" // save modified Eflag back to stack + "popfq \n\t" // restore modified value to Eflag reg + "pushfq \n\t" // save Eflag to stack + "popq %%rax \n\t" // get Eflag from stack + "pushq %%rcx \n\t" // save original Eflag to stack + "popfq \n\t" // restore original Eflag +#else + "pushl %%ebx \n\t" // ebx gets clobbered by CPUID instruction + "pushl %%ecx \n\t" // so does ecx... + "pushl %%edx \n\t" // ...and edx (but ecx & edx safe on Linux) + "pushfl \n\t" // save Eflag to stack + "popl %%eax \n\t" // get Eflag from stack into eax + "movl %%eax, %%ecx \n\t" // make another copy of Eflag in ecx + "xorl $0x200000, %%eax \n\t" // toggle ID bit in Eflag (i.e., bit 21) + "pushl %%eax \n\t" // save modified Eflag back to stack + "popfl \n\t" // restore modified value to Eflag reg + "pushfl \n\t" // save Eflag to stack + "popl %%eax \n\t" // get Eflag from stack + "pushl %%ecx \n\t" // save original Eflag to stack + "popfl \n\t" // restore original Eflag +#endif + "xorl %%ecx, %%eax \n\t" // compare new Eflag with original Eflag + "jz 0f \n\t" // if same, CPUID instr. is not supported + + "xorl %%eax, %%eax \n\t" // set eax to zero +// ".byte 0x0f, 0xa2 \n\t" // CPUID instruction (two-byte opcode) + "cpuid \n\t" // get the CPU identification info + "cmpl $1, %%eax \n\t" // make sure eax return non-zero value + "jl 0f \n\t" // if eax is zero, MMX is not supported + + "xorl %%eax, %%eax \n\t" // set eax to zero and... + "incl %%eax \n\t" // ...increment eax to 1. This pair is + // faster than the instruction "mov eax, 1" + "cpuid \n\t" // get the CPU identification info again + "andl $0x800000, %%edx \n\t" // mask out all bits but MMX bit (23) + "cmpl $0, %%edx \n\t" // 0 = MMX not supported + "jz 0f \n\t" // non-zero = yes, MMX IS supported + + "movl $1, %%eax \n\t" // set return value to 1 + "jmp 1f \n\t" // DONE: have MMX support + + "0: \n\t" // .NOT_SUPPORTED: target label for jump instructions + "movl $0, %%eax \n\t" // set return value to 0 + "1: \n\t" // .RETURN: target label for jump instructions +#ifdef __x86_64__ + "popq %%rdx \n\t" // restore rdx + "popq %%rcx \n\t" // restore rcx + "popq %%rbx \n\t" // restore rbx +#else + "popl %%edx \n\t" // restore edx + "popl %%ecx \n\t" // restore ecx + "popl %%ebx \n\t" // restore ebx +#endif + +// "ret \n\t" // DONE: no MMX support + // (fall through to standard C "ret") + + : "=a" (result) // output list + + : // any variables used on input (none) + + // no clobber list +// , "%ebx", "%ecx", "%edx" // GRR: we handle these manually +// , "memory" // if write to a variable gcc thought was in a reg +// , "cc" // "condition codes" (flag bits) + ); + _mmx_supported = result; +#else + _mmx_supported = 0; +#endif /* PNG_MMX_CODE_SUPPORTED */ + + return _mmx_supported; +} +#endif diff --git a/libs/libpng-src/pngget.c b/libs/libpng-src/pngget.c new file mode 100644 index 000000000..85ca86de5 --- /dev/null +++ b/libs/libpng-src/pngget.c @@ -0,0 +1,1105 @@ + +/* pngget.c - retrieval of values from info struct + * + * Last changed in libpng 1.2.43 [February 25, 2010] + * Copyright (c) 1998-2010 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + * + */ + +#define PNG_INTERNAL +#define PNG_NO_PEDANTIC_WARNINGS +#include "png.h" +#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) + +png_uint_32 PNGAPI +png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag) +{ + if (png_ptr != NULL && info_ptr != NULL) + return(info_ptr->valid & flag); + + else + return(0); +} + +png_uint_32 PNGAPI +png_get_rowbytes(png_structp png_ptr, png_infop info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) + return(info_ptr->rowbytes); + + else + return(0); +} + +#ifdef PNG_INFO_IMAGE_SUPPORTED +png_bytepp PNGAPI +png_get_rows(png_structp png_ptr, png_infop info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) + return(info_ptr->row_pointers); + + else + return(0); +} +#endif + +#ifdef PNG_EASY_ACCESS_SUPPORTED +/* Easy access to info, added in libpng-0.99 */ +png_uint_32 PNGAPI +png_get_image_width(png_structp png_ptr, png_infop info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) + return info_ptr->width; + + return (0); +} + +png_uint_32 PNGAPI +png_get_image_height(png_structp png_ptr, png_infop info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) + return info_ptr->height; + + return (0); +} + +png_byte PNGAPI +png_get_bit_depth(png_structp png_ptr, png_infop info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) + return info_ptr->bit_depth; + + return (0); +} + +png_byte PNGAPI +png_get_color_type(png_structp png_ptr, png_infop info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) + return info_ptr->color_type; + + return (0); +} + +png_byte PNGAPI +png_get_filter_type(png_structp png_ptr, png_infop info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) + return info_ptr->filter_type; + + return (0); +} + +png_byte PNGAPI +png_get_interlace_type(png_structp png_ptr, png_infop info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) + return info_ptr->interlace_type; + + return (0); +} + +png_byte PNGAPI +png_get_compression_type(png_structp png_ptr, png_infop info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) + return info_ptr->compression_type; + + return (0); +} + +png_uint_32 PNGAPI +png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) +#ifdef PNG_pHYs_SUPPORTED + if (info_ptr->valid & PNG_INFO_pHYs) + { + png_debug1(1, "in %s retrieval function", "png_get_x_pixels_per_meter"); + + if (info_ptr->phys_unit_type != PNG_RESOLUTION_METER) + return (0); + + else + return (info_ptr->x_pixels_per_unit); + } +#else + return (0); +#endif + return (0); +} + +png_uint_32 PNGAPI +png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) +#ifdef PNG_pHYs_SUPPORTED + if (info_ptr->valid & PNG_INFO_pHYs) + { + png_debug1(1, "in %s retrieval function", "png_get_y_pixels_per_meter"); + + if (info_ptr->phys_unit_type != PNG_RESOLUTION_METER) + return (0); + + else + return (info_ptr->y_pixels_per_unit); + } +#else + return (0); +#endif + return (0); +} + +png_uint_32 PNGAPI +png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) +#ifdef PNG_pHYs_SUPPORTED + if (info_ptr->valid & PNG_INFO_pHYs) + { + png_debug1(1, "in %s retrieval function", "png_get_pixels_per_meter"); + + if (info_ptr->phys_unit_type != PNG_RESOLUTION_METER || + info_ptr->x_pixels_per_unit != info_ptr->y_pixels_per_unit) + return (0); + + else + return (info_ptr->x_pixels_per_unit); + } +#else + return (0); +#endif + return (0); +} + +#ifdef PNG_FLOATING_POINT_SUPPORTED +float PNGAPI +png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr) + { + if (png_ptr != NULL && info_ptr != NULL) +#ifdef PNG_pHYs_SUPPORTED + + if (info_ptr->valid & PNG_INFO_pHYs) + { + png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio"); + + if (info_ptr->x_pixels_per_unit == 0) + return ((float)0.0); + + else + return ((float)((float)info_ptr->y_pixels_per_unit + /(float)info_ptr->x_pixels_per_unit)); + } +#else + return (0.0); +#endif + return ((float)0.0); +} +#endif + +png_int_32 PNGAPI +png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) +#ifdef PNG_oFFs_SUPPORTED + + if (info_ptr->valid & PNG_INFO_oFFs) + { + png_debug1(1, "in %s retrieval function", "png_get_x_offset_microns"); + + if (info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER) + return (0); + + else + return (info_ptr->x_offset); + } +#else + return (0); +#endif + return (0); +} + +png_int_32 PNGAPI +png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) + +#ifdef PNG_oFFs_SUPPORTED + if (info_ptr->valid & PNG_INFO_oFFs) + { + png_debug1(1, "in %s retrieval function", "png_get_y_offset_microns"); + + if (info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER) + return (0); + + else + return (info_ptr->y_offset); + } +#else + return (0); +#endif + return (0); +} + +png_int_32 PNGAPI +png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) + +#ifdef PNG_oFFs_SUPPORTED + if (info_ptr->valid & PNG_INFO_oFFs) + { + png_debug1(1, "in %s retrieval function", "png_get_x_offset_microns"); + + if (info_ptr->offset_unit_type != PNG_OFFSET_PIXEL) + return (0); + + else + return (info_ptr->x_offset); + } +#else + return (0); +#endif + return (0); +} + +png_int_32 PNGAPI +png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) + +#ifdef PNG_oFFs_SUPPORTED + if (info_ptr->valid & PNG_INFO_oFFs) + { + png_debug1(1, "in %s retrieval function", "png_get_y_offset_microns"); + + if (info_ptr->offset_unit_type != PNG_OFFSET_PIXEL) + return (0); + + else + return (info_ptr->y_offset); + } +#else + return (0); +#endif + return (0); +} + +#if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED) +png_uint_32 PNGAPI +png_get_pixels_per_inch(png_structp png_ptr, png_infop info_ptr) +{ + return ((png_uint_32)((float)png_get_pixels_per_meter(png_ptr, info_ptr) + *.0254 +.5)); +} + +png_uint_32 PNGAPI +png_get_x_pixels_per_inch(png_structp png_ptr, png_infop info_ptr) +{ + return ((png_uint_32)((float)png_get_x_pixels_per_meter(png_ptr, info_ptr) + *.0254 +.5)); +} + +png_uint_32 PNGAPI +png_get_y_pixels_per_inch(png_structp png_ptr, png_infop info_ptr) +{ + return ((png_uint_32)((float)png_get_y_pixels_per_meter(png_ptr, info_ptr) + *.0254 +.5)); +} + +float PNGAPI +png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr) +{ + return ((float)png_get_x_offset_microns(png_ptr, info_ptr) + *.00003937); +} + +float PNGAPI +png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr) +{ + return ((float)png_get_y_offset_microns(png_ptr, info_ptr) + *.00003937); +} + +#ifdef PNG_pHYs_SUPPORTED +png_uint_32 PNGAPI +png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr, + png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type) +{ + png_uint_32 retval = 0; + + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) + { + png_debug1(1, "in %s retrieval function", "pHYs"); + + if (res_x != NULL) + { + *res_x = info_ptr->x_pixels_per_unit; + retval |= PNG_INFO_pHYs; + } + if (res_y != NULL) + { + *res_y = info_ptr->y_pixels_per_unit; + retval |= PNG_INFO_pHYs; + } + if (unit_type != NULL) + { + *unit_type = (int)info_ptr->phys_unit_type; + retval |= PNG_INFO_pHYs; + if (*unit_type == 1) + { + if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50); + if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50); + } + } + } + return (retval); +} +#endif /* PNG_pHYs_SUPPORTED */ +#endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */ + +/* png_get_channels really belongs in here, too, but it's been around longer */ + +#endif /* PNG_EASY_ACCESS_SUPPORTED */ + +png_byte PNGAPI +png_get_channels(png_structp png_ptr, png_infop info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) + return(info_ptr->channels); + else + return (0); +} + +png_bytep PNGAPI +png_get_signature(png_structp png_ptr, png_infop info_ptr) +{ + if (png_ptr != NULL && info_ptr != NULL) + return(info_ptr->signature); + else + return (NULL); +} + +#ifdef PNG_bKGD_SUPPORTED +png_uint_32 PNGAPI +png_get_bKGD(png_structp png_ptr, png_infop info_ptr, + png_color_16p *background) +{ + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD) + && background != NULL) + { + png_debug1(1, "in %s retrieval function", "bKGD"); + + *background = &(info_ptr->background); + return (PNG_INFO_bKGD); + } + return (0); +} +#endif + +#ifdef PNG_cHRM_SUPPORTED +#ifdef PNG_FLOATING_POINT_SUPPORTED +png_uint_32 PNGAPI +png_get_cHRM(png_structp png_ptr, png_infop info_ptr, + double *white_x, double *white_y, double *red_x, double *red_y, + double *green_x, double *green_y, double *blue_x, double *blue_y) +{ + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)) + { + png_debug1(1, "in %s retrieval function", "cHRM"); + + if (white_x != NULL) + *white_x = (double)info_ptr->x_white; + if (white_y != NULL) + *white_y = (double)info_ptr->y_white; + if (red_x != NULL) + *red_x = (double)info_ptr->x_red; + if (red_y != NULL) + *red_y = (double)info_ptr->y_red; + if (green_x != NULL) + *green_x = (double)info_ptr->x_green; + if (green_y != NULL) + *green_y = (double)info_ptr->y_green; + if (blue_x != NULL) + *blue_x = (double)info_ptr->x_blue; + if (blue_y != NULL) + *blue_y = (double)info_ptr->y_blue; + return (PNG_INFO_cHRM); + } + return (0); +} +#endif +#ifdef PNG_FIXED_POINT_SUPPORTED +png_uint_32 PNGAPI +png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr, + png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x, + png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y, + png_fixed_point *blue_x, png_fixed_point *blue_y) +{ + png_debug1(1, "in %s retrieval function", "cHRM"); + + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)) + { + if (white_x != NULL) + *white_x = info_ptr->int_x_white; + if (white_y != NULL) + *white_y = info_ptr->int_y_white; + if (red_x != NULL) + *red_x = info_ptr->int_x_red; + if (red_y != NULL) + *red_y = info_ptr->int_y_red; + if (green_x != NULL) + *green_x = info_ptr->int_x_green; + if (green_y != NULL) + *green_y = info_ptr->int_y_green; + if (blue_x != NULL) + *blue_x = info_ptr->int_x_blue; + if (blue_y != NULL) + *blue_y = info_ptr->int_y_blue; + return (PNG_INFO_cHRM); + } + return (0); +} +#endif +#endif + +#ifdef PNG_gAMA_SUPPORTED +#ifdef PNG_FLOATING_POINT_SUPPORTED +png_uint_32 PNGAPI +png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma) +{ + png_debug1(1, "in %s retrieval function", "gAMA"); + + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA) + && file_gamma != NULL) + { + *file_gamma = (double)info_ptr->gamma; + return (PNG_INFO_gAMA); + } + return (0); +} +#endif +#ifdef PNG_FIXED_POINT_SUPPORTED +png_uint_32 PNGAPI +png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, + png_fixed_point *int_file_gamma) +{ + png_debug1(1, "in %s retrieval function", "gAMA"); + + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA) + && int_file_gamma != NULL) + { + *int_file_gamma = info_ptr->int_gamma; + return (PNG_INFO_gAMA); + } + return (0); +} +#endif +#endif + +#ifdef PNG_sRGB_SUPPORTED +png_uint_32 PNGAPI +png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent) +{ + png_debug1(1, "in %s retrieval function", "sRGB"); + + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB) + && file_srgb_intent != NULL) + { + *file_srgb_intent = (int)info_ptr->srgb_intent; + return (PNG_INFO_sRGB); + } + return (0); +} +#endif + +#ifdef PNG_iCCP_SUPPORTED +png_uint_32 PNGAPI +png_get_iCCP(png_structp png_ptr, png_infop info_ptr, + png_charpp name, int *compression_type, + png_charpp profile, png_uint_32 *proflen) +{ + png_debug1(1, "in %s retrieval function", "iCCP"); + + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP) + && name != NULL && profile != NULL && proflen != NULL) + { + *name = info_ptr->iccp_name; + *profile = info_ptr->iccp_profile; + /* Compression_type is a dummy so the API won't have to change + * if we introduce multiple compression types later. + */ + *proflen = (int)info_ptr->iccp_proflen; + *compression_type = (int)info_ptr->iccp_compression; + return (PNG_INFO_iCCP); + } + return (0); +} +#endif + +#ifdef PNG_sPLT_SUPPORTED +png_uint_32 PNGAPI +png_get_sPLT(png_structp png_ptr, png_infop info_ptr, + png_sPLT_tpp spalettes) +{ + if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL) + { + *spalettes = info_ptr->splt_palettes; + return ((png_uint_32)info_ptr->splt_palettes_num); + } + return (0); +} +#endif + +#ifdef PNG_hIST_SUPPORTED +png_uint_32 PNGAPI +png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist) +{ + png_debug1(1, "in %s retrieval function", "hIST"); + + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST) + && hist != NULL) + { + *hist = info_ptr->hist; + return (PNG_INFO_hIST); + } + return (0); +} +#endif + +png_uint_32 PNGAPI +png_get_IHDR(png_structp png_ptr, png_infop info_ptr, + png_uint_32 *width, png_uint_32 *height, int *bit_depth, + int *color_type, int *interlace_type, int *compression_type, + int *filter_type) + +{ + png_debug1(1, "in %s retrieval function", "IHDR"); + + if (png_ptr == NULL || info_ptr == NULL || width == NULL || + height == NULL || bit_depth == NULL || color_type == NULL) + return (0); + + *width = info_ptr->width; + *height = info_ptr->height; + *bit_depth = info_ptr->bit_depth; + *color_type = info_ptr->color_type; + + if (compression_type != NULL) + *compression_type = info_ptr->compression_type; + + if (filter_type != NULL) + *filter_type = info_ptr->filter_type; + + if (interlace_type != NULL) + *interlace_type = info_ptr->interlace_type; + + /* This is redundant if we can be sure that the info_ptr values were all + * assigned in png_set_IHDR(). We do the check anyhow in case an + * application has ignored our advice not to mess with the members + * of info_ptr directly. + */ + png_check_IHDR (png_ptr, info_ptr->width, info_ptr->height, + info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type, + info_ptr->compression_type, info_ptr->filter_type); + + return (1); +} + +#ifdef PNG_oFFs_SUPPORTED +png_uint_32 PNGAPI +png_get_oFFs(png_structp png_ptr, png_infop info_ptr, + png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type) +{ + png_debug1(1, "in %s retrieval function", "oFFs"); + + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs) + && offset_x != NULL && offset_y != NULL && unit_type != NULL) + { + *offset_x = info_ptr->x_offset; + *offset_y = info_ptr->y_offset; + *unit_type = (int)info_ptr->offset_unit_type; + return (PNG_INFO_oFFs); + } + return (0); +} +#endif + +#ifdef PNG_pCAL_SUPPORTED +png_uint_32 PNGAPI +png_get_pCAL(png_structp png_ptr, png_infop info_ptr, + png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams, + png_charp *units, png_charpp *params) +{ + png_debug1(1, "in %s retrieval function", "pCAL"); + + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL) + && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL && + nparams != NULL && units != NULL && params != NULL) + { + *purpose = info_ptr->pcal_purpose; + *X0 = info_ptr->pcal_X0; + *X1 = info_ptr->pcal_X1; + *type = (int)info_ptr->pcal_type; + *nparams = (int)info_ptr->pcal_nparams; + *units = info_ptr->pcal_units; + *params = info_ptr->pcal_params; + return (PNG_INFO_pCAL); + } + return (0); +} +#endif + +#ifdef PNG_sCAL_SUPPORTED +#ifdef PNG_FLOATING_POINT_SUPPORTED +png_uint_32 PNGAPI +png_get_sCAL(png_structp png_ptr, png_infop info_ptr, + int *unit, double *width, double *height) +{ + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_sCAL)) + { + *unit = info_ptr->scal_unit; + *width = info_ptr->scal_pixel_width; + *height = info_ptr->scal_pixel_height; + return (PNG_INFO_sCAL); + } + return(0); +} +#else +#ifdef PNG_FIXED_POINT_SUPPORTED +png_uint_32 PNGAPI +png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr, + int *unit, png_charpp width, png_charpp height) +{ + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_sCAL)) + { + *unit = info_ptr->scal_unit; + *width = info_ptr->scal_s_width; + *height = info_ptr->scal_s_height; + return (PNG_INFO_sCAL); + } + return(0); +} +#endif +#endif +#endif + +#ifdef PNG_pHYs_SUPPORTED +png_uint_32 PNGAPI +png_get_pHYs(png_structp png_ptr, png_infop info_ptr, + png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type) +{ + png_uint_32 retval = 0; + + png_debug1(1, "in %s retrieval function", "pHYs"); + + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_pHYs)) + { + if (res_x != NULL) + { + *res_x = info_ptr->x_pixels_per_unit; + retval |= PNG_INFO_pHYs; + } + + if (res_y != NULL) + { + *res_y = info_ptr->y_pixels_per_unit; + retval |= PNG_INFO_pHYs; + } + + if (unit_type != NULL) + { + *unit_type = (int)info_ptr->phys_unit_type; + retval |= PNG_INFO_pHYs; + } + } + return (retval); +} +#endif + +png_uint_32 PNGAPI +png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette, + int *num_palette) +{ + png_debug1(1, "in %s retrieval function", "PLTE"); + + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE) + && palette != NULL) + { + *palette = info_ptr->palette; + *num_palette = info_ptr->num_palette; + png_debug1(3, "num_palette = %d", *num_palette); + return (PNG_INFO_PLTE); + } + return (0); +} + +#ifdef PNG_sBIT_SUPPORTED +png_uint_32 PNGAPI +png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit) +{ + png_debug1(1, "in %s retrieval function", "sBIT"); + + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT) + && sig_bit != NULL) + { + *sig_bit = &(info_ptr->sig_bit); + return (PNG_INFO_sBIT); + } + return (0); +} +#endif + +#ifdef PNG_TEXT_SUPPORTED +png_uint_32 PNGAPI +png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr, + int *num_text) +{ + if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0) + { + png_debug1(1, "in %s retrieval function", + (png_ptr->chunk_name[0] == '\0' ? "text" + : (png_const_charp)png_ptr->chunk_name)); + + if (text_ptr != NULL) + *text_ptr = info_ptr->text; + + if (num_text != NULL) + *num_text = info_ptr->num_text; + + return ((png_uint_32)info_ptr->num_text); + } + if (num_text != NULL) + *num_text = 0; + return(0); +} +#endif + +#ifdef PNG_tIME_SUPPORTED +png_uint_32 PNGAPI +png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time) +{ + png_debug1(1, "in %s retrieval function", "tIME"); + + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME) + && mod_time != NULL) + { + *mod_time = &(info_ptr->mod_time); + return (PNG_INFO_tIME); + } + return (0); +} +#endif + +#ifdef PNG_tRNS_SUPPORTED +png_uint_32 PNGAPI +png_get_tRNS(png_structp png_ptr, png_infop info_ptr, + png_bytep *trans, int *num_trans, png_color_16p *trans_values) +{ + png_uint_32 retval = 0; + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS)) + { + png_debug1(1, "in %s retrieval function", "tRNS"); + + if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + { + if (trans != NULL) + { + *trans = info_ptr->trans; + retval |= PNG_INFO_tRNS; + } + + if (trans_values != NULL) + *trans_values = &(info_ptr->trans_values); + } + else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */ + { + if (trans_values != NULL) + { + *trans_values = &(info_ptr->trans_values); + retval |= PNG_INFO_tRNS; + } + + if (trans != NULL) + *trans = NULL; + } + if (num_trans != NULL) + { + *num_trans = info_ptr->num_trans; + retval |= PNG_INFO_tRNS; + } + } + return (retval); +} +#endif + +#if defined(PNG_APNG_SUPPORTED) +png_uint_32 PNGAPI +png_get_acTL(png_structp png_ptr, png_infop info_ptr, + png_uint_32 *num_frames, png_uint_32 *num_plays) +{ + png_debug1(1, "in %s retrieval function", "acTL"); + + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_acTL) && + num_frames != NULL && num_plays != NULL) + { + *num_frames = info_ptr->num_frames; + *num_plays = info_ptr->num_plays; + return (1); + } + + return (0); +} + +png_uint_32 PNGAPI +png_get_num_frames(png_structp png_ptr, png_infop info_ptr) +{ + png_debug(1, "in png_get_num_frames()"); + + if (png_ptr != NULL && info_ptr != NULL) + return (info_ptr->num_frames); + return (0); +} + +png_uint_32 PNGAPI +png_get_num_plays(png_structp png_ptr, png_infop info_ptr) +{ + png_debug(1, "in png_get_num_plays()"); + + if (png_ptr != NULL && info_ptr != NULL) + return (info_ptr->num_plays); + return (0); +} + +png_uint_32 PNGAPI +png_get_next_frame_fcTL(png_structp png_ptr, png_infop info_ptr, + png_uint_32 *width, png_uint_32 *height, + png_uint_32 *x_offset, png_uint_32 *y_offset, + png_uint_16 *delay_num, png_uint_16 *delay_den, + png_byte *dispose_op, png_byte *blend_op) +{ + png_debug1(1, "in %s retrieval function", "fcTL"); + + if (png_ptr != NULL && info_ptr != NULL && + (info_ptr->valid & PNG_INFO_fcTL) && + width != NULL && height != NULL && + x_offset != NULL && x_offset != NULL && + delay_num != NULL && delay_den != NULL && + dispose_op != NULL && blend_op != NULL) + { + *width = info_ptr->next_frame_width; + *height = info_ptr->next_frame_height; + *x_offset = info_ptr->next_frame_x_offset; + *y_offset = info_ptr->next_frame_y_offset; + *delay_num = info_ptr->next_frame_delay_num; + *delay_den = info_ptr->next_frame_delay_den; + *dispose_op = info_ptr->next_frame_dispose_op; + *blend_op = info_ptr->next_frame_blend_op; + return (1); + } + + return (0); +} + +png_uint_32 PNGAPI +png_get_next_frame_width(png_structp png_ptr, png_infop info_ptr) +{ + png_debug(1, "in png_get_next_frame_width()"); + + if (png_ptr != NULL && info_ptr != NULL) + return (info_ptr->next_frame_width); + return (0); +} + +png_uint_32 PNGAPI +png_get_next_frame_height(png_structp png_ptr, png_infop info_ptr) +{ + png_debug(1, "in png_get_next_frame_height()"); + + if (png_ptr != NULL && info_ptr != NULL) + return (info_ptr->next_frame_height); + return (0); +} + +png_uint_32 PNGAPI +png_get_next_frame_x_offset(png_structp png_ptr, png_infop info_ptr) +{ + png_debug(1, "in png_get_next_frame_x_offset()"); + + if (png_ptr != NULL && info_ptr != NULL) + return (info_ptr->next_frame_x_offset); + return (0); +} + +png_uint_32 PNGAPI +png_get_next_frame_y_offset(png_structp png_ptr, png_infop info_ptr) +{ + png_debug(1, "in png_get_next_frame_y_offset()"); + + if (png_ptr != NULL && info_ptr != NULL) + return (info_ptr->next_frame_y_offset); + return (0); +} + +png_uint_16 PNGAPI +png_get_next_frame_delay_num(png_structp png_ptr, png_infop info_ptr) +{ + png_debug(1, "in png_get_next_frame_delay_num()"); + + if (png_ptr != NULL && info_ptr != NULL) + return (info_ptr->next_frame_delay_num); + return (0); +} + +png_uint_16 PNGAPI +png_get_next_frame_delay_den(png_structp png_ptr, png_infop info_ptr) +{ + png_debug(1, "in png_get_next_frame_delay_den()"); + + if (png_ptr != NULL && info_ptr != NULL) + return (info_ptr->next_frame_delay_den); + return (0); +} + +png_byte PNGAPI +png_get_next_frame_dispose_op(png_structp png_ptr, png_infop info_ptr) +{ + png_debug(1, "in png_get_next_frame_dispose_op()"); + + if (png_ptr != NULL && info_ptr != NULL) + return (info_ptr->next_frame_dispose_op); + return (0); +} + +png_byte PNGAPI +png_get_next_frame_blend_op(png_structp png_ptr, png_infop info_ptr) +{ + png_debug(1, "in png_get_next_frame_blend_op()"); + + if (png_ptr != NULL && info_ptr != NULL) + return (info_ptr->next_frame_blend_op); + return (0); +} + +png_byte PNGAPI +png_get_first_frame_is_hidden(png_structp png_ptr, png_infop info_ptr) +{ + png_debug(1, "in png_first_frame_is_hidden()"); + + if (png_ptr != NULL) + return (png_byte)(png_ptr->apng_flags & PNG_FIRST_FRAME_HIDDEN); + + return 0; +} +#endif /* PNG_APNG_SUPPORTED */ + +#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED +png_uint_32 PNGAPI +png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr, + png_unknown_chunkpp unknowns) +{ + if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL) + { + *unknowns = info_ptr->unknown_chunks; + return ((png_uint_32)info_ptr->unknown_chunks_num); + } + return (0); +} +#endif + +#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED +png_byte PNGAPI +png_get_rgb_to_gray_status (png_structp png_ptr) +{ + return (png_byte)(png_ptr? png_ptr->rgb_to_gray_status : 0); +} +#endif + +#ifdef PNG_USER_CHUNKS_SUPPORTED +png_voidp PNGAPI +png_get_user_chunk_ptr(png_structp png_ptr) +{ + return (png_ptr? png_ptr->user_chunk_ptr : NULL); +} +#endif + +png_uint_32 PNGAPI +png_get_compression_buffer_size(png_structp png_ptr) +{ + return (png_uint_32)(png_ptr? png_ptr->zbuf_size : 0L); +} + +#ifdef PNG_ASSEMBLER_CODE_SUPPORTED +#ifndef PNG_1_0_X +/* This function was added to libpng 1.2.0 and should exist by default */ +png_uint_32 PNGAPI +png_get_asm_flags (png_structp png_ptr) +{ + /* Obsolete, to be removed from libpng-1.4.0 */ + return (png_ptr? 0L: 0L); +} + +/* This function was added to libpng 1.2.0 and should exist by default */ +png_uint_32 PNGAPI +png_get_asm_flagmask (int flag_select) +{ + /* Obsolete, to be removed from libpng-1.4.0 */ + flag_select=flag_select; + return 0L; +} + + /* GRR: could add this: && defined(PNG_MMX_CODE_SUPPORTED) */ +/* This function was added to libpng 1.2.0 */ +png_uint_32 PNGAPI +png_get_mmx_flagmask (int flag_select, int *compilerID) +{ + /* Obsolete, to be removed from libpng-1.4.0 */ + flag_select=flag_select; + *compilerID = -1; /* unknown (i.e., no asm/MMX code compiled) */ + return 0L; +} + +/* This function was added to libpng 1.2.0 */ +png_byte PNGAPI +png_get_mmx_bitdepth_threshold (png_structp png_ptr) +{ + /* Obsolete, to be removed from libpng-1.4.0 */ + return (png_ptr? 0: 0); +} + +/* This function was added to libpng 1.2.0 */ +png_uint_32 PNGAPI +png_get_mmx_rowbytes_threshold (png_structp png_ptr) +{ + /* Obsolete, to be removed from libpng-1.4.0 */ + return (png_ptr? 0L: 0L); +} +#endif /* ?PNG_1_0_X */ +#endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */ + +#ifdef PNG_SET_USER_LIMITS_SUPPORTED +/* These functions were added to libpng 1.2.6 but not enabled +* by default. They will be enabled in libpng-1.4.0 */ +png_uint_32 PNGAPI +png_get_user_width_max (png_structp png_ptr) +{ + return (png_ptr? png_ptr->user_width_max : 0); +} +png_uint_32 PNGAPI +png_get_user_height_max (png_structp png_ptr) +{ + return (png_ptr? png_ptr->user_height_max : 0); +} +#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */ + +#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ diff --git a/libs/libpng-src/pngmem.c b/libs/libpng-src/pngmem.c new file mode 100644 index 000000000..a18719b81 --- /dev/null +++ b/libs/libpng-src/pngmem.c @@ -0,0 +1,641 @@ + +/* pngmem.c - stub functions for memory allocation + * + * Last changed in libpng 1.2.41 [February 25, 2010] + * Copyright (c) 1998-2010 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + * + * This file provides a location for all memory allocation. Users who + * need special memory handling are expected to supply replacement + * functions for png_malloc() and png_free(), and to use + * png_create_read_struct_2() and png_create_write_struct_2() to + * identify the replacement functions. + */ + +#define PNG_INTERNAL +#define PNG_NO_PEDANTIC_WARNINGS +#include "png.h" +#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) + +/* Borland DOS special memory handler */ +#if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__) +/* If you change this, be sure to change the one in png.h also */ + +/* Allocate memory for a png_struct. The malloc and memset can be replaced + by a single call to calloc() if this is thought to improve performance. */ +png_voidp /* PRIVATE */ +png_create_struct(int type) +{ +#ifdef PNG_USER_MEM_SUPPORTED + return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL)); +} + +/* Alternate version of png_create_struct, for use with user-defined malloc. */ +png_voidp /* PRIVATE */ +png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr) +{ +#endif /* PNG_USER_MEM_SUPPORTED */ + png_size_t size; + png_voidp struct_ptr; + + if (type == PNG_STRUCT_INFO) + size = png_sizeof(png_info); + else if (type == PNG_STRUCT_PNG) + size = png_sizeof(png_struct); + else + return (png_get_copyright(NULL)); + +#ifdef PNG_USER_MEM_SUPPORTED + if (malloc_fn != NULL) + { + png_struct dummy_struct; + png_structp png_ptr = &dummy_struct; + png_ptr->mem_ptr=mem_ptr; + struct_ptr = (*(malloc_fn))(png_ptr, (png_uint_32)size); + } + else +#endif /* PNG_USER_MEM_SUPPORTED */ + struct_ptr = (png_voidp)farmalloc(size); + if (struct_ptr != NULL) + png_memset(struct_ptr, 0, size); + return (struct_ptr); +} + +/* Free memory allocated by a png_create_struct() call */ +void /* PRIVATE */ +png_destroy_struct(png_voidp struct_ptr) +{ +#ifdef PNG_USER_MEM_SUPPORTED + png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL); +} + +/* Free memory allocated by a png_create_struct() call */ +void /* PRIVATE */ +png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn, + png_voidp mem_ptr) +{ +#endif + if (struct_ptr != NULL) + { +#ifdef PNG_USER_MEM_SUPPORTED + if (free_fn != NULL) + { + png_struct dummy_struct; + png_structp png_ptr = &dummy_struct; + png_ptr->mem_ptr=mem_ptr; + (*(free_fn))(png_ptr, struct_ptr); + return; + } +#endif /* PNG_USER_MEM_SUPPORTED */ + farfree (struct_ptr); + } +} + +/* Allocate memory. For reasonable files, size should never exceed + * 64K. However, zlib may allocate more then 64K if you don't tell + * it not to. See zconf.h and png.h for more information. zlib does + * need to allocate exactly 64K, so whatever you call here must + * have the ability to do that. + * + * Borland seems to have a problem in DOS mode for exactly 64K. + * It gives you a segment with an offset of 8 (perhaps to store its + * memory stuff). zlib doesn't like this at all, so we have to + * detect and deal with it. This code should not be needed in + * Windows or OS/2 modes, and only in 16 bit mode. This code has + * been updated by Alexander Lehmann for version 0.89 to waste less + * memory. + * + * Note that we can't use png_size_t for the "size" declaration, + * since on some systems a png_size_t is a 16-bit quantity, and as a + * result, we would be truncating potentially larger memory requests + * (which should cause a fatal error) and introducing major problems. + */ +png_voidp /* PRIVATE */ +png_calloc(png_structp png_ptr, png_uint_32 size) +{ + png_voidp ret; + + ret = (png_malloc(png_ptr, size)); + if (ret != NULL) + png_memset(ret,0,(png_size_t)size); + return (ret); +} + +png_voidp PNGAPI +png_malloc(png_structp png_ptr, png_uint_32 size) +{ + png_voidp ret; + + if (png_ptr == NULL || size == 0) + return (NULL); + +#ifdef PNG_USER_MEM_SUPPORTED + if (png_ptr->malloc_fn != NULL) + ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size)); + else + ret = (png_malloc_default(png_ptr, size)); + if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) + png_error(png_ptr, "Out of memory!"); + return (ret); +} + +png_voidp PNGAPI +png_malloc_default(png_structp png_ptr, png_uint_32 size) +{ + png_voidp ret; +#endif /* PNG_USER_MEM_SUPPORTED */ + + if (png_ptr == NULL || size == 0) + return (NULL); + +#ifdef PNG_MAX_MALLOC_64K + if (size > (png_uint_32)65536L) + { + png_warning(png_ptr, "Cannot Allocate > 64K"); + ret = NULL; + } + else +#endif + + if (size != (size_t)size) + ret = NULL; + else if (size == (png_uint_32)65536L) + { + if (png_ptr->offset_table == NULL) + { + /* Try to see if we need to do any of this fancy stuff */ + ret = farmalloc(size); + if (ret == NULL || ((png_size_t)ret & 0xffff)) + { + int num_blocks; + png_uint_32 total_size; + png_bytep table; + int i; + png_byte huge * hptr; + + if (ret != NULL) + { + farfree(ret); + ret = NULL; + } + + if (png_ptr->zlib_window_bits > 14) + num_blocks = (int)(1 << (png_ptr->zlib_window_bits - 14)); + else + num_blocks = 1; + if (png_ptr->zlib_mem_level >= 7) + num_blocks += (int)(1 << (png_ptr->zlib_mem_level - 7)); + else + num_blocks++; + + total_size = ((png_uint_32)65536L) * (png_uint_32)num_blocks+16; + + table = farmalloc(total_size); + + if (table == NULL) + { +#ifndef PNG_USER_MEM_SUPPORTED + if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) + png_error(png_ptr, "Out Of Memory."); /* Note "O", "M" */ + else + png_warning(png_ptr, "Out Of Memory."); +#endif + return (NULL); + } + + if ((png_size_t)table & 0xfff0) + { +#ifndef PNG_USER_MEM_SUPPORTED + if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) + png_error(png_ptr, + "Farmalloc didn't return normalized pointer"); + else + png_warning(png_ptr, + "Farmalloc didn't return normalized pointer"); +#endif + return (NULL); + } + + png_ptr->offset_table = table; + png_ptr->offset_table_ptr = farmalloc(num_blocks * + png_sizeof(png_bytep)); + + if (png_ptr->offset_table_ptr == NULL) + { +#ifndef PNG_USER_MEM_SUPPORTED + if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) + png_error(png_ptr, "Out Of memory."); /* Note "O", "m" */ + else + png_warning(png_ptr, "Out Of memory."); +#endif + return (NULL); + } + + hptr = (png_byte huge *)table; + if ((png_size_t)hptr & 0xf) + { + hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L); + hptr = hptr + 16L; /* "hptr += 16L" fails on Turbo C++ 3.0 */ + } + for (i = 0; i < num_blocks; i++) + { + png_ptr->offset_table_ptr[i] = (png_bytep)hptr; + hptr = hptr + (png_uint_32)65536L; /* "+=" fails on TC++3.0 */ + } + + png_ptr->offset_table_number = num_blocks; + png_ptr->offset_table_count = 0; + png_ptr->offset_table_count_free = 0; + } + } + + if (png_ptr->offset_table_count >= png_ptr->offset_table_number) + { +#ifndef PNG_USER_MEM_SUPPORTED + if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) + png_error(png_ptr, "Out of Memory."); /* Note "o" and "M" */ + else + png_warning(png_ptr, "Out of Memory."); +#endif + return (NULL); + } + + ret = png_ptr->offset_table_ptr[png_ptr->offset_table_count++]; + } + else + ret = farmalloc(size); + +#ifndef PNG_USER_MEM_SUPPORTED + if (ret == NULL) + { + if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) + png_error(png_ptr, "Out of memory."); /* Note "o" and "m" */ + else + png_warning(png_ptr, "Out of memory."); /* Note "o" and "m" */ + } +#endif + + return (ret); +} + +/* Free a pointer allocated by png_malloc(). In the default + * configuration, png_ptr is not used, but is passed in case it + * is needed. If ptr is NULL, return without taking any action. + */ +void PNGAPI +png_free(png_structp png_ptr, png_voidp ptr) +{ + if (png_ptr == NULL || ptr == NULL) + return; + +#ifdef PNG_USER_MEM_SUPPORTED + if (png_ptr->free_fn != NULL) + { + (*(png_ptr->free_fn))(png_ptr, ptr); + return; + } + else + png_free_default(png_ptr, ptr); +} + +void PNGAPI +png_free_default(png_structp png_ptr, png_voidp ptr) +{ +#endif /* PNG_USER_MEM_SUPPORTED */ + + if (png_ptr == NULL || ptr == NULL) + return; + + if (png_ptr->offset_table != NULL) + { + int i; + + for (i = 0; i < png_ptr->offset_table_count; i++) + { + if (ptr == png_ptr->offset_table_ptr[i]) + { + ptr = NULL; + png_ptr->offset_table_count_free++; + break; + } + } + if (png_ptr->offset_table_count_free == png_ptr->offset_table_count) + { + farfree(png_ptr->offset_table); + farfree(png_ptr->offset_table_ptr); + png_ptr->offset_table = NULL; + png_ptr->offset_table_ptr = NULL; + } + } + + if (ptr != NULL) + { + farfree(ptr); + } +} + +#else /* Not the Borland DOS special memory handler */ + +/* Allocate memory for a png_struct or a png_info. The malloc and + memset can be replaced by a single call to calloc() if this is thought + to improve performance noticably. */ +png_voidp /* PRIVATE */ +png_create_struct(int type) +{ +#ifdef PNG_USER_MEM_SUPPORTED + return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL)); +} + +/* Allocate memory for a png_struct or a png_info. The malloc and + memset can be replaced by a single call to calloc() if this is thought + to improve performance noticably. */ +png_voidp /* PRIVATE */ +png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr) +{ +#endif /* PNG_USER_MEM_SUPPORTED */ + png_size_t size; + png_voidp struct_ptr; + + if (type == PNG_STRUCT_INFO) + size = png_sizeof(png_info); + else if (type == PNG_STRUCT_PNG) + size = png_sizeof(png_struct); + else + return (NULL); + +#ifdef PNG_USER_MEM_SUPPORTED + if (malloc_fn != NULL) + { + png_struct dummy_struct; + png_structp png_ptr = &dummy_struct; + png_ptr->mem_ptr=mem_ptr; + struct_ptr = (*(malloc_fn))(png_ptr, size); + if (struct_ptr != NULL) + png_memset(struct_ptr, 0, size); + return (struct_ptr); + } +#endif /* PNG_USER_MEM_SUPPORTED */ + +#if defined(__TURBOC__) && !defined(__FLAT__) + struct_ptr = (png_voidp)farmalloc(size); +#else +# if defined(_MSC_VER) && defined(MAXSEG_64K) + struct_ptr = (png_voidp)halloc(size, 1); +# else + struct_ptr = (png_voidp)malloc(size); +# endif +#endif + if (struct_ptr != NULL) + png_memset(struct_ptr, 0, size); + + return (struct_ptr); +} + + +/* Free memory allocated by a png_create_struct() call */ +void /* PRIVATE */ +png_destroy_struct(png_voidp struct_ptr) +{ +#ifdef PNG_USER_MEM_SUPPORTED + png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL); +} + +/* Free memory allocated by a png_create_struct() call */ +void /* PRIVATE */ +png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn, + png_voidp mem_ptr) +{ +#endif /* PNG_USER_MEM_SUPPORTED */ + if (struct_ptr != NULL) + { +#ifdef PNG_USER_MEM_SUPPORTED + if (free_fn != NULL) + { + png_struct dummy_struct; + png_structp png_ptr = &dummy_struct; + png_ptr->mem_ptr=mem_ptr; + (*(free_fn))(png_ptr, struct_ptr); + return; + } +#endif /* PNG_USER_MEM_SUPPORTED */ +#if defined(__TURBOC__) && !defined(__FLAT__) + farfree(struct_ptr); +#else +# if defined(_MSC_VER) && defined(MAXSEG_64K) + hfree(struct_ptr); +# else + free(struct_ptr); +# endif +#endif + } +} + +/* Allocate memory. For reasonable files, size should never exceed + * 64K. However, zlib may allocate more then 64K if you don't tell + * it not to. See zconf.h and png.h for more information. zlib does + * need to allocate exactly 64K, so whatever you call here must + * have the ability to do that. + */ + +png_voidp /* PRIVATE */ +png_calloc(png_structp png_ptr, png_uint_32 size) +{ + png_voidp ret; + + ret = (png_malloc(png_ptr, size)); + if (ret != NULL) + png_memset(ret,0,(png_size_t)size); + return (ret); +} + +png_voidp PNGAPI +png_malloc(png_structp png_ptr, png_uint_32 size) +{ + png_voidp ret; + +#ifdef PNG_USER_MEM_SUPPORTED + if (png_ptr == NULL || size == 0) + return (NULL); + + if (png_ptr->malloc_fn != NULL) + ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size)); + else + ret = (png_malloc_default(png_ptr, size)); + if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) + png_error(png_ptr, "Out of Memory!"); + return (ret); +} + +png_voidp PNGAPI +png_malloc_default(png_structp png_ptr, png_uint_32 size) +{ + png_voidp ret; +#endif /* PNG_USER_MEM_SUPPORTED */ + + if (png_ptr == NULL || size == 0) + return (NULL); + +#ifdef PNG_MAX_MALLOC_64K + if (size > (png_uint_32)65536L) + { +#ifndef PNG_USER_MEM_SUPPORTED + if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) + png_error(png_ptr, "Cannot Allocate > 64K"); + else +#endif + return NULL; + } +#endif + + /* Check for overflow */ +#if defined(__TURBOC__) && !defined(__FLAT__) + if (size != (unsigned long)size) + ret = NULL; + else + ret = farmalloc(size); +#else +# if defined(_MSC_VER) && defined(MAXSEG_64K) + if (size != (unsigned long)size) + ret = NULL; + else + ret = halloc(size, 1); +# else + if (size != (size_t)size) + ret = NULL; + else + ret = malloc((size_t)size); +# endif +#endif + +#ifndef PNG_USER_MEM_SUPPORTED + if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) + png_error(png_ptr, "Out of Memory"); +#endif + + return (ret); +} + +/* Free a pointer allocated by png_malloc(). If ptr is NULL, return + * without taking any action. + */ +void PNGAPI +png_free(png_structp png_ptr, png_voidp ptr) +{ + if (png_ptr == NULL || ptr == NULL) + return; + +#ifdef PNG_USER_MEM_SUPPORTED + if (png_ptr->free_fn != NULL) + { + (*(png_ptr->free_fn))(png_ptr, ptr); + return; + } + else + png_free_default(png_ptr, ptr); +} +void PNGAPI +png_free_default(png_structp png_ptr, png_voidp ptr) +{ + if (png_ptr == NULL || ptr == NULL) + return; + +#endif /* PNG_USER_MEM_SUPPORTED */ + +#if defined(__TURBOC__) && !defined(__FLAT__) + farfree(ptr); +#else +# if defined(_MSC_VER) && defined(MAXSEG_64K) + hfree(ptr); +# else + free(ptr); +# endif +#endif +} + +#endif /* Not Borland DOS special memory handler */ + +#ifdef PNG_1_0_X +# define png_malloc_warn png_malloc +#else +/* This function was added at libpng version 1.2.3. The png_malloc_warn() + * function will set up png_malloc() to issue a png_warning and return NULL + * instead of issuing a png_error, if it fails to allocate the requested + * memory. + */ +png_voidp PNGAPI +png_malloc_warn(png_structp png_ptr, png_uint_32 size) +{ + png_voidp ptr; + png_uint_32 save_flags; + if (png_ptr == NULL) + return (NULL); + + save_flags = png_ptr->flags; + png_ptr->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK; + ptr = (png_voidp)png_malloc((png_structp)png_ptr, size); + png_ptr->flags=save_flags; + return(ptr); +} +#endif + +png_voidp PNGAPI +png_memcpy_check (png_structp png_ptr, png_voidp s1, png_voidp s2, + png_uint_32 length) +{ + png_size_t size; + + size = (png_size_t)length; + if ((png_uint_32)size != length) + png_error(png_ptr, "Overflow in png_memcpy_check."); + + return(png_memcpy (s1, s2, size)); +} + +png_voidp PNGAPI +png_memset_check (png_structp png_ptr, png_voidp s1, int value, + png_uint_32 length) +{ + png_size_t size; + + size = (png_size_t)length; + if ((png_uint_32)size != length) + png_error(png_ptr, "Overflow in png_memset_check."); + + return (png_memset (s1, value, size)); + +} + +#ifdef PNG_USER_MEM_SUPPORTED +/* This function is called when the application wants to use another method + * of allocating and freeing memory. + */ +void PNGAPI +png_set_mem_fn(png_structp png_ptr, png_voidp mem_ptr, png_malloc_ptr + malloc_fn, png_free_ptr free_fn) +{ + if (png_ptr != NULL) + { + png_ptr->mem_ptr = mem_ptr; + png_ptr->malloc_fn = malloc_fn; + png_ptr->free_fn = free_fn; + } +} + +/* This function returns a pointer to the mem_ptr associated with the user + * functions. The application should free any memory associated with this + * pointer before png_write_destroy and png_read_destroy are called. + */ +png_voidp PNGAPI +png_get_mem_ptr(png_structp png_ptr) +{ + if (png_ptr == NULL) + return (NULL); + return ((png_voidp)png_ptr->mem_ptr); +} +#endif /* PNG_USER_MEM_SUPPORTED */ +#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ diff --git a/libs/libpng-src/pngnow.png b/libs/libpng-src/pngnow.png new file mode 100644 index 000000000..82793ebdd Binary files /dev/null and b/libs/libpng-src/pngnow.png differ diff --git a/libs/libpng-src/pngpread.c b/libs/libpng-src/pngpread.c new file mode 100644 index 000000000..95c52ea79 --- /dev/null +++ b/libs/libpng-src/pngpread.c @@ -0,0 +1,1970 @@ + +/* pngpread.c - read a png file in push mode + * + * Last changed in libpng 1.2.44 [June 26, 2010] + * Copyright (c) 1998-2010 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + */ + +#define PNG_INTERNAL +#define PNG_NO_PEDANTIC_WARNINGS +#include "png.h" +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED + +/* Push model modes */ +#define PNG_READ_SIG_MODE 0 +#define PNG_READ_CHUNK_MODE 1 +#define PNG_READ_IDAT_MODE 2 +#define PNG_SKIP_MODE 3 +#define PNG_READ_tEXt_MODE 4 +#define PNG_READ_zTXt_MODE 5 +#define PNG_READ_DONE_MODE 6 +#define PNG_READ_iTXt_MODE 7 +#define PNG_ERROR_MODE 8 + +void PNGAPI +png_process_data(png_structp png_ptr, png_infop info_ptr, + png_bytep buffer, png_size_t buffer_size) +{ + if (png_ptr == NULL || info_ptr == NULL) + return; + + png_push_restore_buffer(png_ptr, buffer, buffer_size); + + while (png_ptr->buffer_size) + { + png_process_some_data(png_ptr, info_ptr); + } +} + +/* What we do with the incoming data depends on what we were previously + * doing before we ran out of data... + */ +void /* PRIVATE */ +png_process_some_data(png_structp png_ptr, png_infop info_ptr) +{ + if (png_ptr == NULL) + return; + + switch (png_ptr->process_mode) + { + case PNG_READ_SIG_MODE: + { + png_push_read_sig(png_ptr, info_ptr); + break; + } + + case PNG_READ_CHUNK_MODE: + { + png_push_read_chunk(png_ptr, info_ptr); + break; + } + + case PNG_READ_IDAT_MODE: + { + png_push_read_IDAT(png_ptr); + break; + } + +#ifdef PNG_READ_tEXt_SUPPORTED + case PNG_READ_tEXt_MODE: + { + png_push_read_tEXt(png_ptr, info_ptr); + break; + } + +#endif +#ifdef PNG_READ_zTXt_SUPPORTED + case PNG_READ_zTXt_MODE: + { + png_push_read_zTXt(png_ptr, info_ptr); + break; + } + +#endif +#ifdef PNG_READ_iTXt_SUPPORTED + case PNG_READ_iTXt_MODE: + { + png_push_read_iTXt(png_ptr, info_ptr); + break; + } + +#endif + case PNG_SKIP_MODE: + { + png_push_crc_finish(png_ptr); + break; + } + + default: + { + png_ptr->buffer_size = 0; + break; + } + } +} + +/* Read any remaining signature bytes from the stream and compare them with + * the correct PNG signature. It is possible that this routine is called + * with bytes already read from the signature, either because they have been + * checked by the calling application, or because of multiple calls to this + * routine. + */ +void /* PRIVATE */ +png_push_read_sig(png_structp png_ptr, png_infop info_ptr) +{ + png_size_t num_checked = png_ptr->sig_bytes, + num_to_check = 8 - num_checked; + + if (png_ptr->buffer_size < num_to_check) + { + num_to_check = png_ptr->buffer_size; + } + + png_push_fill_buffer(png_ptr, &(info_ptr->signature[num_checked]), + num_to_check); + png_ptr->sig_bytes = (png_byte)(png_ptr->sig_bytes + num_to_check); + + if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check)) + { + if (num_checked < 4 && + png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4)) + png_error(png_ptr, "Not a PNG file"); + else + png_error(png_ptr, "PNG file corrupted by ASCII conversion"); + } + else + { + if (png_ptr->sig_bytes >= 8) + { + png_ptr->process_mode = PNG_READ_CHUNK_MODE; + } + } +} + +void /* PRIVATE */ +png_push_read_chunk(png_structp png_ptr, png_infop info_ptr) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_CONST PNG_IHDR; + PNG_CONST PNG_IDAT; + PNG_CONST PNG_IEND; + PNG_CONST PNG_PLTE; +#ifdef PNG_READ_bKGD_SUPPORTED + PNG_CONST PNG_bKGD; +#endif +#ifdef PNG_READ_cHRM_SUPPORTED + PNG_CONST PNG_cHRM; +#endif +#ifdef PNG_READ_gAMA_SUPPORTED + PNG_CONST PNG_gAMA; +#endif +#ifdef PNG_READ_hIST_SUPPORTED + PNG_CONST PNG_hIST; +#endif +#ifdef PNG_READ_iCCP_SUPPORTED + PNG_CONST PNG_iCCP; +#endif +#ifdef PNG_READ_iTXt_SUPPORTED + PNG_CONST PNG_iTXt; +#endif +#ifdef PNG_READ_oFFs_SUPPORTED + PNG_CONST PNG_oFFs; +#endif +#ifdef PNG_READ_pCAL_SUPPORTED + PNG_CONST PNG_pCAL; +#endif +#ifdef PNG_READ_pHYs_SUPPORTED + PNG_CONST PNG_pHYs; +#endif +#ifdef PNG_READ_sBIT_SUPPORTED + PNG_CONST PNG_sBIT; +#endif +#ifdef PNG_READ_sCAL_SUPPORTED + PNG_CONST PNG_sCAL; +#endif +#ifdef PNG_READ_sRGB_SUPPORTED + PNG_CONST PNG_sRGB; +#endif +#ifdef PNG_READ_sPLT_SUPPORTED + PNG_CONST PNG_sPLT; +#endif +#ifdef PNG_READ_tEXt_SUPPORTED + PNG_CONST PNG_tEXt; +#endif +#ifdef PNG_READ_tIME_SUPPORTED + PNG_CONST PNG_tIME; +#endif +#ifdef PNG_READ_tRNS_SUPPORTED + PNG_CONST PNG_tRNS; +#endif +#ifdef PNG_READ_zTXt_SUPPORTED + PNG_CONST PNG_zTXt; +#endif +#if defined(PNG_READ_APNG_SUPPORTED) + PNG_CONST PNG_acTL; + PNG_CONST PNG_fcTL; + PNG_CONST PNG_fdAT; +#endif +#endif /* PNG_USE_LOCAL_ARRAYS */ + + /* First we make sure we have enough data for the 4 byte chunk name + * and the 4 byte chunk length before proceeding with decoding the + * chunk data. To fully decode each of these chunks, we also make + * sure we have enough data in the buffer for the 4 byte CRC at the + * end of every chunk (except IDAT, which is handled separately). + */ + if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER)) + { + png_byte chunk_length[4]; + + if (png_ptr->buffer_size < 8) + { + png_push_save_buffer(png_ptr); + return; + } + + png_push_fill_buffer(png_ptr, chunk_length, 4); + png_ptr->push_length = png_get_uint_31(png_ptr, chunk_length); + png_reset_crc(png_ptr); + png_crc_read(png_ptr, png_ptr->chunk_name, 4); + png_check_chunk_name(png_ptr, png_ptr->chunk_name); + png_ptr->mode |= PNG_HAVE_CHUNK_HEADER; + } + +#if defined(PNG_READ_APNG_SUPPORTED) + if (png_ptr->num_frames_read > 0 && + png_ptr->num_frames_read < info_ptr->num_frames) + { + if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) + { + /* discard trailing IDATs for the first frame */ + if (png_ptr->mode & PNG_HAVE_fcTL || png_ptr->num_frames_read > 1) + png_error(png_ptr, "out of place IDAT"); + + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + png_push_crc_skip(png_ptr, png_ptr->push_length); + png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER; + return; + } + else if (!png_memcmp(png_ptr->chunk_name, png_fdAT, 4)) + { + if (png_ptr->buffer_size < 4) + { + png_push_save_buffer(png_ptr); + return; + } + png_ensure_sequence_number(png_ptr, 4); + + if (!(png_ptr->mode & PNG_HAVE_fcTL)) + { + /* discard trailing fdATs for frames other than the first */ + if (png_ptr->num_frames_read < 2) + png_error(png_ptr, "out of place fdAT"); + + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + png_push_crc_skip(png_ptr, png_ptr->push_length); + png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER; + return; + } + else + { + /* frame data follows */ + png_ptr->idat_size = png_ptr->push_length - 4; + png_ptr->mode |= PNG_HAVE_IDAT; + png_ptr->process_mode = PNG_READ_IDAT_MODE; + + return; + } + } + else if(!png_memcmp(png_ptr->chunk_name, png_fcTL, 4)) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + + png_read_reset(png_ptr); + png_ptr->mode &= ~PNG_HAVE_fcTL; + + png_handle_fcTL(png_ptr, info_ptr, png_ptr->push_length); + + if (!(png_ptr->mode & PNG_HAVE_fcTL)) + png_error(png_ptr, "missing required fcTL chunk"); + + png_read_reinit(png_ptr, info_ptr); + png_progressive_read_reset(png_ptr); + + if (png_ptr->frame_info_fn != NULL) + (*(png_ptr->frame_info_fn))(png_ptr, png_ptr->num_frames_read); + + png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER; + + return; + } + else + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + png_warning(png_ptr, "Skipped (ignored) a chunk " + "between APNG chunks"); + png_push_crc_skip(png_ptr, png_ptr->push_length); + png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER; + return; + } + + return; + } +#endif /* PNG_READ_APNG_SUPPORTED */ + + if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) + if (png_ptr->mode & PNG_AFTER_IDAT) + png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT; + + if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4)) + { + if (png_ptr->push_length != 13) + png_error(png_ptr, "Invalid IHDR length"); + + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + + png_handle_IHDR(png_ptr, info_ptr, png_ptr->push_length); + } + + else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4)) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + + png_handle_IEND(png_ptr, info_ptr, png_ptr->push_length); + + png_ptr->process_mode = PNG_READ_DONE_MODE; + png_push_have_end(png_ptr, info_ptr); + } + +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED + else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name)) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + + if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) + png_ptr->mode |= PNG_HAVE_IDAT; + + png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length); + + if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4)) + png_ptr->mode |= PNG_HAVE_PLTE; + + else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) + { + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before IDAT"); + + else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && + !(png_ptr->mode & PNG_HAVE_PLTE)) + png_error(png_ptr, "Missing PLTE before IDAT"); + } + } + +#endif + else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4)) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + png_handle_PLTE(png_ptr, info_ptr, png_ptr->push_length); + } + + else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) + { + /* If we reach an IDAT chunk, this means we have read all of the + * header chunks, and we can start reading the image (or if this + * is called after the image has been read - we have an error). + */ + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before IDAT"); + + else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && + !(png_ptr->mode & PNG_HAVE_PLTE)) + png_error(png_ptr, "Missing PLTE before IDAT"); + + if (png_ptr->mode & PNG_HAVE_IDAT) + { + if (!(png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT)) + if (png_ptr->push_length == 0) + return; + + if (png_ptr->mode & PNG_AFTER_IDAT) + png_error(png_ptr, "Too many IDAT's found"); + } + +#if defined(PNG_READ_APNG_SUPPORTED) + png_have_info(png_ptr, info_ptr); +#endif + png_ptr->idat_size = png_ptr->push_length; + png_ptr->mode |= PNG_HAVE_IDAT; + png_ptr->process_mode = PNG_READ_IDAT_MODE; + png_push_have_info(png_ptr, info_ptr); + png_ptr->zstream.avail_out = + (uInt) PNG_ROWBYTES(png_ptr->pixel_depth, + png_ptr->iwidth) + 1; + png_ptr->zstream.next_out = png_ptr->row_buf; + return; + } + +#ifdef PNG_READ_gAMA_SUPPORTED + else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4)) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + + png_handle_gAMA(png_ptr, info_ptr, png_ptr->push_length); + } + +#endif +#ifdef PNG_READ_sBIT_SUPPORTED + else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4)) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + + png_handle_sBIT(png_ptr, info_ptr, png_ptr->push_length); + } + +#endif +#ifdef PNG_READ_cHRM_SUPPORTED + else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4)) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + + png_handle_cHRM(png_ptr, info_ptr, png_ptr->push_length); + } + +#endif +#ifdef PNG_READ_sRGB_SUPPORTED + else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4)) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + + png_handle_sRGB(png_ptr, info_ptr, png_ptr->push_length); + } + +#endif +#ifdef PNG_READ_iCCP_SUPPORTED + else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4)) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + + png_handle_iCCP(png_ptr, info_ptr, png_ptr->push_length); + } + +#endif +#ifdef PNG_READ_sPLT_SUPPORTED + else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4)) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + + png_handle_sPLT(png_ptr, info_ptr, png_ptr->push_length); + } + +#endif +#ifdef PNG_READ_tRNS_SUPPORTED + else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4)) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + + png_handle_tRNS(png_ptr, info_ptr, png_ptr->push_length); + } + +#endif +#ifdef PNG_READ_bKGD_SUPPORTED + else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4)) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + + png_handle_bKGD(png_ptr, info_ptr, png_ptr->push_length); + } + +#endif +#ifdef PNG_READ_hIST_SUPPORTED + else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4)) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + + png_handle_hIST(png_ptr, info_ptr, png_ptr->push_length); + } + +#endif +#ifdef PNG_READ_pHYs_SUPPORTED + else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4)) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + + png_handle_pHYs(png_ptr, info_ptr, png_ptr->push_length); + } + +#endif +#ifdef PNG_READ_oFFs_SUPPORTED + else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4)) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + + png_handle_oFFs(png_ptr, info_ptr, png_ptr->push_length); + } +#endif + +#ifdef PNG_READ_pCAL_SUPPORTED + else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4)) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + + png_handle_pCAL(png_ptr, info_ptr, png_ptr->push_length); + } + +#endif +#ifdef PNG_READ_sCAL_SUPPORTED + else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4)) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + + png_handle_sCAL(png_ptr, info_ptr, png_ptr->push_length); + } + +#endif +#ifdef PNG_READ_tIME_SUPPORTED + else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4)) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + + png_handle_tIME(png_ptr, info_ptr, png_ptr->push_length); + } + +#endif +#ifdef PNG_READ_tEXt_SUPPORTED + else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4)) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + + png_push_handle_tEXt(png_ptr, info_ptr, png_ptr->push_length); + } + +#endif +#ifdef PNG_READ_zTXt_SUPPORTED + else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4)) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + + png_push_handle_zTXt(png_ptr, info_ptr, png_ptr->push_length); + } + +#endif +#ifdef PNG_READ_iTXt_SUPPORTED + else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4)) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + + png_push_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length); + } + +#endif +#if defined(PNG_READ_APNG_SUPPORTED) + else if (!png_memcmp(png_ptr->chunk_name, png_acTL, 4)) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + png_handle_acTL(png_ptr, info_ptr, png_ptr->push_length); + } + else if (!png_memcmp(png_ptr->chunk_name, png_fcTL, 4)) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + png_handle_fcTL(png_ptr, info_ptr, png_ptr->push_length); + } + else if (!png_memcmp(png_ptr->chunk_name, png_fdAT, 4)) + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + png_handle_fdAT(png_ptr, info_ptr, png_ptr->push_length); + } +#endif /* PNG_READ_APNG_SUPPORTED */ + else + { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + png_push_handle_unknown(png_ptr, info_ptr, png_ptr->push_length); + } + + png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER; +} + +void /* PRIVATE */ +png_push_crc_skip(png_structp png_ptr, png_uint_32 skip) +{ + png_ptr->process_mode = PNG_SKIP_MODE; + png_ptr->skip_length = skip; +} + +void /* PRIVATE */ +png_push_crc_finish(png_structp png_ptr) +{ + if (png_ptr->skip_length && png_ptr->save_buffer_size) + { + png_size_t save_size; + + if (png_ptr->skip_length < (png_uint_32)png_ptr->save_buffer_size) + save_size = (png_size_t)png_ptr->skip_length; + else + save_size = png_ptr->save_buffer_size; + + png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size); + + png_ptr->skip_length -= save_size; + png_ptr->buffer_size -= save_size; + png_ptr->save_buffer_size -= save_size; + png_ptr->save_buffer_ptr += save_size; + } + if (png_ptr->skip_length && png_ptr->current_buffer_size) + { + png_size_t save_size; + + if (png_ptr->skip_length < (png_uint_32)png_ptr->current_buffer_size) + save_size = (png_size_t)png_ptr->skip_length; + else + save_size = png_ptr->current_buffer_size; + + png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size); + + png_ptr->skip_length -= save_size; + png_ptr->buffer_size -= save_size; + png_ptr->current_buffer_size -= save_size; + png_ptr->current_buffer_ptr += save_size; + } + if (!png_ptr->skip_length) + { + if (png_ptr->buffer_size < 4) + { + png_push_save_buffer(png_ptr); + return; + } + + png_crc_finish(png_ptr, 0); + png_ptr->process_mode = PNG_READ_CHUNK_MODE; + } +} + +void PNGAPI +png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length) +{ + png_bytep ptr; + + if (png_ptr == NULL) + return; + + ptr = buffer; + if (png_ptr->save_buffer_size) + { + png_size_t save_size; + + if (length < png_ptr->save_buffer_size) + save_size = length; + else + save_size = png_ptr->save_buffer_size; + + png_memcpy(ptr, png_ptr->save_buffer_ptr, save_size); + length -= save_size; + ptr += save_size; + png_ptr->buffer_size -= save_size; + png_ptr->save_buffer_size -= save_size; + png_ptr->save_buffer_ptr += save_size; + } + if (length && png_ptr->current_buffer_size) + { + png_size_t save_size; + + if (length < png_ptr->current_buffer_size) + save_size = length; + + else + save_size = png_ptr->current_buffer_size; + + png_memcpy(ptr, png_ptr->current_buffer_ptr, save_size); + png_ptr->buffer_size -= save_size; + png_ptr->current_buffer_size -= save_size; + png_ptr->current_buffer_ptr += save_size; + } +} + +void /* PRIVATE */ +png_push_save_buffer(png_structp png_ptr) +{ + if (png_ptr->save_buffer_size) + { + if (png_ptr->save_buffer_ptr != png_ptr->save_buffer) + { + png_size_t i, istop; + png_bytep sp; + png_bytep dp; + + istop = png_ptr->save_buffer_size; + for (i = 0, sp = png_ptr->save_buffer_ptr, dp = png_ptr->save_buffer; + i < istop; i++, sp++, dp++) + { + *dp = *sp; + } + } + } + if (png_ptr->save_buffer_size + png_ptr->current_buffer_size > + png_ptr->save_buffer_max) + { + png_size_t new_max; + png_bytep old_buffer; + + if (png_ptr->save_buffer_size > PNG_SIZE_MAX - + (png_ptr->current_buffer_size + 256)) + { + png_error(png_ptr, "Potential overflow of save_buffer"); + } + + new_max = png_ptr->save_buffer_size + png_ptr->current_buffer_size + 256; + old_buffer = png_ptr->save_buffer; + png_ptr->save_buffer = (png_bytep)png_malloc_warn(png_ptr, + (png_uint_32)new_max); + if (png_ptr->save_buffer == NULL) + { + png_free(png_ptr, old_buffer); + png_error(png_ptr, "Insufficient memory for save_buffer"); + } + png_memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size); + png_free(png_ptr, old_buffer); + png_ptr->save_buffer_max = new_max; + } + if (png_ptr->current_buffer_size) + { + png_memcpy(png_ptr->save_buffer + png_ptr->save_buffer_size, + png_ptr->current_buffer_ptr, png_ptr->current_buffer_size); + png_ptr->save_buffer_size += png_ptr->current_buffer_size; + png_ptr->current_buffer_size = 0; + } + png_ptr->save_buffer_ptr = png_ptr->save_buffer; + png_ptr->buffer_size = 0; +} + +void /* PRIVATE */ +png_push_restore_buffer(png_structp png_ptr, png_bytep buffer, + png_size_t buffer_length) +{ + png_ptr->current_buffer = buffer; + png_ptr->current_buffer_size = buffer_length; + png_ptr->buffer_size = buffer_length + png_ptr->save_buffer_size; + png_ptr->current_buffer_ptr = png_ptr->current_buffer; +} + +void /* PRIVATE */ +png_push_read_IDAT(png_structp png_ptr) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_CONST PNG_IDAT; +#if defined(PNG_READ_APNG_SUPPORTED) + PNG_fdAT; + PNG_IEND; +#endif +#endif + if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER)) + { + png_byte chunk_length[4]; + + if (png_ptr->buffer_size < 8) + { + png_push_save_buffer(png_ptr); + return; + } + + png_push_fill_buffer(png_ptr, chunk_length, 4); + png_ptr->push_length = png_get_uint_31(png_ptr, chunk_length); + png_reset_crc(png_ptr); + png_crc_read(png_ptr, png_ptr->chunk_name, 4); + png_ptr->mode |= PNG_HAVE_CHUNK_HEADER; + +#if defined(PNG_READ_APNG_SUPPORTED) + if (png_memcmp(png_ptr->chunk_name, (png_bytep)png_fdAT, 4) + && png_ptr->num_frames_read > 0) + { + if (png_ptr->flags & PNG_FLAG_ZLIB_FINISHED) + { + png_ptr->process_mode = PNG_READ_CHUNK_MODE; + if (png_ptr->frame_end_fn != NULL) + (*(png_ptr->frame_end_fn))(png_ptr, png_ptr->num_frames_read); + png_ptr->num_frames_read++; + return; + } + else + { + if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4)) + png_error(png_ptr, "Not enough image data"); + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } + png_warning(png_ptr, "Skipping (ignoring) a chunk between " + "APNG chunks"); + png_crc_finish(png_ptr, png_ptr->push_length); + png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER; + return; + } + } + else +#endif + if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4) +#if defined(PNG_READ_APNG_SUPPORTED) + && (png_ptr->num_frames_read == 0) +#endif + ) + { + png_ptr->process_mode = PNG_READ_CHUNK_MODE; + if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED)) + png_error(png_ptr, "Not enough compressed data"); +#if defined(PNG_READ_APNG_SUPPORTED) + if (png_ptr->frame_end_fn != NULL) + (*(png_ptr->frame_end_fn))(png_ptr, png_ptr->num_frames_read); + png_ptr->num_frames_read++; +#endif + return; + } + + png_ptr->idat_size = png_ptr->push_length; + +#if defined(PNG_READ_APNG_SUPPORTED) + if (png_ptr->num_frames_read > 0) + { + png_ensure_sequence_number(png_ptr, 4); + png_ptr->idat_size -= 4; + } +#endif + } + if (png_ptr->idat_size && png_ptr->save_buffer_size) + { + png_size_t save_size; + + if (png_ptr->idat_size < (png_uint_32)png_ptr->save_buffer_size) + { + save_size = (png_size_t)png_ptr->idat_size; + + /* Check for overflow */ + if ((png_uint_32)save_size != png_ptr->idat_size) + png_error(png_ptr, "save_size overflowed in pngpread"); + } + else + save_size = png_ptr->save_buffer_size; + + png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size); + + png_process_IDAT_data(png_ptr, png_ptr->save_buffer_ptr, save_size); + + png_ptr->idat_size -= save_size; + png_ptr->buffer_size -= save_size; + png_ptr->save_buffer_size -= save_size; + png_ptr->save_buffer_ptr += save_size; + } + if (png_ptr->idat_size && png_ptr->current_buffer_size) + { + png_size_t save_size; + + if (png_ptr->idat_size < (png_uint_32)png_ptr->current_buffer_size) + { + save_size = (png_size_t)png_ptr->idat_size; + + /* Check for overflow */ + if ((png_uint_32)save_size != png_ptr->idat_size) + png_error(png_ptr, "save_size overflowed in pngpread"); + } + else + save_size = png_ptr->current_buffer_size; + + png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size); + + png_process_IDAT_data(png_ptr, png_ptr->current_buffer_ptr, save_size); + + png_ptr->idat_size -= save_size; + png_ptr->buffer_size -= save_size; + png_ptr->current_buffer_size -= save_size; + png_ptr->current_buffer_ptr += save_size; + } + if (!png_ptr->idat_size) + { + if (png_ptr->buffer_size < 4) + { + png_push_save_buffer(png_ptr); + return; + } + + png_crc_finish(png_ptr, 0); + png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER; + png_ptr->mode |= PNG_AFTER_IDAT; + } +} + +void /* PRIVATE */ +png_process_IDAT_data(png_structp png_ptr, png_bytep buffer, + png_size_t buffer_length) +{ + /* The caller checks for a non-zero buffer length. */ + if (!(buffer_length > 0) || buffer == NULL) + png_error(png_ptr, "No IDAT data (internal error)"); + + /* This routine must process all the data it has been given + * before returning, calling the row callback as required to + * handle the uncompressed results. + */ + png_ptr->zstream.next_in = buffer; + png_ptr->zstream.avail_in = (uInt)buffer_length; + + /* Keep going until the decompressed data is all processed + * or the stream marked as finished. + */ + while (png_ptr->zstream.avail_in > 0 && + !(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED)) + { + int ret; + + /* We have data for zlib, but we must check that zlib + * has somewhere to put the results. It doesn't matter + * if we don't expect any results -- it may be the input + * data is just the LZ end code. + */ + if (!(png_ptr->zstream.avail_out > 0)) + { + png_ptr->zstream.avail_out = + (uInt) PNG_ROWBYTES(png_ptr->pixel_depth, + png_ptr->iwidth) + 1; + png_ptr->zstream.next_out = png_ptr->row_buf; + } + + /* Using Z_SYNC_FLUSH here means that an unterminated + * LZ stream can still be handled (a stream with a missing + * end code), otherwise (Z_NO_FLUSH) a future zlib + * implementation might defer output and, therefore, + * change the current behavior. (See comments in inflate.c + * for why this doesn't happen at present with zlib 1.2.5.) + */ + ret = inflate(&png_ptr->zstream, Z_SYNC_FLUSH); + + /* Check for any failure before proceeding. */ + if (ret != Z_OK && ret != Z_STREAM_END) + { + /* Terminate the decompression. */ + png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED; + + /* This may be a truncated stream (missing or + * damaged end code). Treat that as a warning. + */ + if (png_ptr->row_number >= png_ptr->num_rows || + png_ptr->pass > 6) + png_warning(png_ptr, "Truncated compressed data in IDAT"); + else + png_error(png_ptr, "Decompression error in IDAT"); + + /* Skip the check on unprocessed input */ + return; + } + + /* Did inflate output any data? */ + if (png_ptr->zstream.next_out != png_ptr->row_buf) + { + /* Is this unexpected data after the last row? + * If it is, artificially terminate the LZ output + * here. + */ + if (png_ptr->row_number >= png_ptr->num_rows || + png_ptr->pass > 6) + { + /* Extra data. */ + png_warning(png_ptr, "Extra compressed data in IDAT"); + png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED; + /* Do no more processing; skip the unprocessed + * input check below. + */ + return; + } + + /* Do we have a complete row? */ + if (png_ptr->zstream.avail_out == 0) + png_push_process_row(png_ptr); + } + + /* And check for the end of the stream. */ + if (ret == Z_STREAM_END) + png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED; + } + + /* All the data should have been processed, if anything + * is left at this point we have bytes of IDAT data + * after the zlib end code. + */ + if (png_ptr->zstream.avail_in > 0) + png_warning(png_ptr, "Extra compression data"); +} + +void /* PRIVATE */ +png_push_process_row(png_structp png_ptr) +{ + png_ptr->row_info.color_type = png_ptr->color_type; + png_ptr->row_info.width = png_ptr->iwidth; + png_ptr->row_info.channels = png_ptr->channels; + png_ptr->row_info.bit_depth = png_ptr->bit_depth; + png_ptr->row_info.pixel_depth = png_ptr->pixel_depth; + + png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth, + png_ptr->row_info.width); + + png_read_filter_row(png_ptr, &(png_ptr->row_info), + png_ptr->row_buf + 1, png_ptr->prev_row + 1, + (int)(png_ptr->row_buf[0])); + + png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf, + png_ptr->rowbytes + 1); + + if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA)) + png_do_read_transformations(png_ptr); + +#ifdef PNG_READ_INTERLACING_SUPPORTED + /* Blow up interlaced rows to full size */ + if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE)) + { + if (png_ptr->pass < 6) +/* old interface (pre-1.0.9): + png_do_read_interlace(&(png_ptr->row_info), + png_ptr->row_buf + 1, png_ptr->pass, png_ptr->transformations); + */ + png_do_read_interlace(png_ptr); + + switch (png_ptr->pass) + { + case 0: + { + int i; + for (i = 0; i < 8 && png_ptr->pass == 0; i++) + { + png_push_have_row(png_ptr, png_ptr->row_buf + 1); + png_read_push_finish_row(png_ptr); /* Updates png_ptr->pass */ + } + + if (png_ptr->pass == 2) /* Pass 1 might be empty */ + { + for (i = 0; i < 4 && png_ptr->pass == 2; i++) + { + png_push_have_row(png_ptr, png_bytep_NULL); + png_read_push_finish_row(png_ptr); + } + } + + if (png_ptr->pass == 4 && png_ptr->height <= 4) + { + for (i = 0; i < 2 && png_ptr->pass == 4; i++) + { + png_push_have_row(png_ptr, png_bytep_NULL); + png_read_push_finish_row(png_ptr); + } + } + + if (png_ptr->pass == 6 && png_ptr->height <= 4) + { + png_push_have_row(png_ptr, png_bytep_NULL); + png_read_push_finish_row(png_ptr); + } + + break; + } + + case 1: + { + int i; + for (i = 0; i < 8 && png_ptr->pass == 1; i++) + { + png_push_have_row(png_ptr, png_ptr->row_buf + 1); + png_read_push_finish_row(png_ptr); + } + + if (png_ptr->pass == 2) /* Skip top 4 generated rows */ + { + for (i = 0; i < 4 && png_ptr->pass == 2; i++) + { + png_push_have_row(png_ptr, png_bytep_NULL); + png_read_push_finish_row(png_ptr); + } + } + + break; + } + + case 2: + { + int i; + + for (i = 0; i < 4 && png_ptr->pass == 2; i++) + { + png_push_have_row(png_ptr, png_ptr->row_buf + 1); + png_read_push_finish_row(png_ptr); + } + + for (i = 0; i < 4 && png_ptr->pass == 2; i++) + { + png_push_have_row(png_ptr, png_bytep_NULL); + png_read_push_finish_row(png_ptr); + } + + if (png_ptr->pass == 4) /* Pass 3 might be empty */ + { + for (i = 0; i < 2 && png_ptr->pass == 4; i++) + { + png_push_have_row(png_ptr, png_bytep_NULL); + png_read_push_finish_row(png_ptr); + } + } + + break; + } + + case 3: + { + int i; + + for (i = 0; i < 4 && png_ptr->pass == 3; i++) + { + png_push_have_row(png_ptr, png_ptr->row_buf + 1); + png_read_push_finish_row(png_ptr); + } + + if (png_ptr->pass == 4) /* Skip top two generated rows */ + { + for (i = 0; i < 2 && png_ptr->pass == 4; i++) + { + png_push_have_row(png_ptr, png_bytep_NULL); + png_read_push_finish_row(png_ptr); + } + } + + break; + } + + case 4: + { + int i; + + for (i = 0; i < 2 && png_ptr->pass == 4; i++) + { + png_push_have_row(png_ptr, png_ptr->row_buf + 1); + png_read_push_finish_row(png_ptr); + } + + for (i = 0; i < 2 && png_ptr->pass == 4; i++) + { + png_push_have_row(png_ptr, png_bytep_NULL); + png_read_push_finish_row(png_ptr); + } + + if (png_ptr->pass == 6) /* Pass 5 might be empty */ + { + png_push_have_row(png_ptr, png_bytep_NULL); + png_read_push_finish_row(png_ptr); + } + + break; + } + + case 5: + { + int i; + + for (i = 0; i < 2 && png_ptr->pass == 5; i++) + { + png_push_have_row(png_ptr, png_ptr->row_buf + 1); + png_read_push_finish_row(png_ptr); + } + + if (png_ptr->pass == 6) /* Skip top generated row */ + { + png_push_have_row(png_ptr, png_bytep_NULL); + png_read_push_finish_row(png_ptr); + } + + break; + } + case 6: + { + png_push_have_row(png_ptr, png_ptr->row_buf + 1); + png_read_push_finish_row(png_ptr); + + if (png_ptr->pass != 6) + break; + + png_push_have_row(png_ptr, png_bytep_NULL); + png_read_push_finish_row(png_ptr); + } + } + } + else +#endif + { + png_push_have_row(png_ptr, png_ptr->row_buf + 1); + png_read_push_finish_row(png_ptr); + } +} + +void /* PRIVATE */ +png_read_push_finish_row(png_structp png_ptr) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ + + /* Start of interlace block */ + PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; + + /* Offset to next interlace block */ + PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; + + /* Start of interlace block in the y direction */ + PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1}; + + /* Offset to next interlace block in the y direction */ + PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2}; + + /* Height of interlace block. This is not currently used - if you need + * it, uncomment it here and in png.h + PNG_CONST int FARDATA png_pass_height[] = {8, 8, 4, 4, 2, 2, 1}; + */ +#endif + + png_ptr->row_number++; + if (png_ptr->row_number < png_ptr->num_rows) + return; + +#ifdef PNG_READ_INTERLACING_SUPPORTED + if (png_ptr->interlaced) + { + png_ptr->row_number = 0; + png_memset_check(png_ptr, png_ptr->prev_row, 0, + png_ptr->rowbytes + 1); + do + { + png_ptr->pass++; + if ((png_ptr->pass == 1 && png_ptr->width < 5) || + (png_ptr->pass == 3 && png_ptr->width < 3) || + (png_ptr->pass == 5 && png_ptr->width < 2)) + png_ptr->pass++; + + if (png_ptr->pass > 7) + png_ptr->pass--; + + if (png_ptr->pass >= 7) + break; + + png_ptr->iwidth = (png_ptr->width + + png_pass_inc[png_ptr->pass] - 1 - + png_pass_start[png_ptr->pass]) / + png_pass_inc[png_ptr->pass]; + + if (png_ptr->transformations & PNG_INTERLACE) + break; + + png_ptr->num_rows = (png_ptr->height + + png_pass_yinc[png_ptr->pass] - 1 - + png_pass_ystart[png_ptr->pass]) / + png_pass_yinc[png_ptr->pass]; + + } while (png_ptr->iwidth == 0 || png_ptr->num_rows == 0); + } +#endif /* PNG_READ_INTERLACING_SUPPORTED */ +} + +#ifdef PNG_READ_tEXt_SUPPORTED +void /* PRIVATE */ +png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 + length) +{ + if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND)) + { + png_error(png_ptr, "Out of place tEXt"); + info_ptr = info_ptr; /* To quiet some compiler warnings */ + } + +#ifdef PNG_MAX_MALLOC_64K + png_ptr->skip_length = 0; /* This may not be necessary */ + + if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */ + { + png_warning(png_ptr, "tEXt chunk too large to fit in memory"); + png_ptr->skip_length = length - (png_uint_32)65535L; + length = (png_uint_32)65535L; + } +#endif + + png_ptr->current_text = (png_charp)png_malloc(png_ptr, + (png_uint_32)(length + 1)); + png_ptr->current_text[length] = '\0'; + png_ptr->current_text_ptr = png_ptr->current_text; + png_ptr->current_text_size = (png_size_t)length; + png_ptr->current_text_left = (png_size_t)length; + png_ptr->process_mode = PNG_READ_tEXt_MODE; +} + +void /* PRIVATE */ +png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr) +{ + if (png_ptr->buffer_size && png_ptr->current_text_left) + { + png_size_t text_size; + + if (png_ptr->buffer_size < png_ptr->current_text_left) + text_size = png_ptr->buffer_size; + + else + text_size = png_ptr->current_text_left; + + png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size); + png_ptr->current_text_left -= text_size; + png_ptr->current_text_ptr += text_size; + } + if (!(png_ptr->current_text_left)) + { + png_textp text_ptr; + png_charp text; + png_charp key; + int ret; + + if (png_ptr->buffer_size < 4) + { + png_push_save_buffer(png_ptr); + return; + } + + png_push_crc_finish(png_ptr); + +#ifdef PNG_MAX_MALLOC_64K + if (png_ptr->skip_length) + return; +#endif + + key = png_ptr->current_text; + + for (text = key; *text; text++) + /* Empty loop */ ; + + if (text < key + png_ptr->current_text_size) + text++; + + text_ptr = (png_textp)png_malloc(png_ptr, + (png_uint_32)png_sizeof(png_text)); + text_ptr->compression = PNG_TEXT_COMPRESSION_NONE; + text_ptr->key = key; +#ifdef PNG_iTXt_SUPPORTED + text_ptr->lang = NULL; + text_ptr->lang_key = NULL; +#endif + text_ptr->text = text; + + ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1); + + png_free(png_ptr, key); + png_free(png_ptr, text_ptr); + png_ptr->current_text = NULL; + + if (ret) + png_warning(png_ptr, "Insufficient memory to store text chunk."); + } +} +#endif + +#ifdef PNG_READ_zTXt_SUPPORTED +void /* PRIVATE */ +png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 + length) +{ + if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND)) + { + png_error(png_ptr, "Out of place zTXt"); + info_ptr = info_ptr; /* To quiet some compiler warnings */ + } + +#ifdef PNG_MAX_MALLOC_64K + /* We can't handle zTXt chunks > 64K, since we don't have enough space + * to be able to store the uncompressed data. Actually, the threshold + * is probably around 32K, but it isn't as definite as 64K is. + */ + if (length > (png_uint_32)65535L) + { + png_warning(png_ptr, "zTXt chunk too large to fit in memory"); + png_push_crc_skip(png_ptr, length); + return; + } +#endif + + png_ptr->current_text = (png_charp)png_malloc(png_ptr, + (png_uint_32)(length + 1)); + png_ptr->current_text[length] = '\0'; + png_ptr->current_text_ptr = png_ptr->current_text; + png_ptr->current_text_size = (png_size_t)length; + png_ptr->current_text_left = (png_size_t)length; + png_ptr->process_mode = PNG_READ_zTXt_MODE; +} + +void /* PRIVATE */ +png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr) +{ + if (png_ptr->buffer_size && png_ptr->current_text_left) + { + png_size_t text_size; + + if (png_ptr->buffer_size < (png_uint_32)png_ptr->current_text_left) + text_size = png_ptr->buffer_size; + + else + text_size = png_ptr->current_text_left; + + png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size); + png_ptr->current_text_left -= text_size; + png_ptr->current_text_ptr += text_size; + } + if (!(png_ptr->current_text_left)) + { + png_textp text_ptr; + png_charp text; + png_charp key; + int ret; + png_size_t text_size, key_size; + + if (png_ptr->buffer_size < 4) + { + png_push_save_buffer(png_ptr); + return; + } + + png_push_crc_finish(png_ptr); + + key = png_ptr->current_text; + + for (text = key; *text; text++) + /* Empty loop */ ; + + /* zTXt can't have zero text */ + if (text >= key + png_ptr->current_text_size) + { + png_ptr->current_text = NULL; + png_free(png_ptr, key); + return; + } + + text++; + + if (*text != PNG_TEXT_COMPRESSION_zTXt) /* Check compression byte */ + { + png_ptr->current_text = NULL; + png_free(png_ptr, key); + return; + } + + text++; + + png_ptr->zstream.next_in = (png_bytep )text; + png_ptr->zstream.avail_in = (uInt)(png_ptr->current_text_size - + (text - key)); + png_ptr->zstream.next_out = png_ptr->zbuf; + png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; + + key_size = text - key; + text_size = 0; + text = NULL; + ret = Z_STREAM_END; + + while (png_ptr->zstream.avail_in) + { + ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH); + if (ret != Z_OK && ret != Z_STREAM_END) + { + inflateReset(&png_ptr->zstream); + png_ptr->zstream.avail_in = 0; + png_ptr->current_text = NULL; + png_free(png_ptr, key); + png_free(png_ptr, text); + return; + } + if (!(png_ptr->zstream.avail_out) || ret == Z_STREAM_END) + { + if (text == NULL) + { + text = (png_charp)png_malloc(png_ptr, + (png_uint_32)(png_ptr->zbuf_size + - png_ptr->zstream.avail_out + key_size + 1)); + + png_memcpy(text + key_size, png_ptr->zbuf, + png_ptr->zbuf_size - png_ptr->zstream.avail_out); + + png_memcpy(text, key, key_size); + + text_size = key_size + png_ptr->zbuf_size - + png_ptr->zstream.avail_out; + + *(text + text_size) = '\0'; + } + else + { + png_charp tmp; + + tmp = text; + text = (png_charp)png_malloc(png_ptr, text_size + + (png_uint_32)(png_ptr->zbuf_size + - png_ptr->zstream.avail_out + 1)); + + png_memcpy(text, tmp, text_size); + png_free(png_ptr, tmp); + + png_memcpy(text + text_size, png_ptr->zbuf, + png_ptr->zbuf_size - png_ptr->zstream.avail_out); + + text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out; + *(text + text_size) = '\0'; + } + if (ret != Z_STREAM_END) + { + png_ptr->zstream.next_out = png_ptr->zbuf; + png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; + } + } + else + { + break; + } + + if (ret == Z_STREAM_END) + break; + } + + inflateReset(&png_ptr->zstream); + png_ptr->zstream.avail_in = 0; + + if (ret != Z_STREAM_END) + { + png_ptr->current_text = NULL; + png_free(png_ptr, key); + png_free(png_ptr, text); + return; + } + + png_ptr->current_text = NULL; + png_free(png_ptr, key); + key = text; + text += key_size; + + text_ptr = (png_textp)png_malloc(png_ptr, + (png_uint_32)png_sizeof(png_text)); + text_ptr->compression = PNG_TEXT_COMPRESSION_zTXt; + text_ptr->key = key; +#ifdef PNG_iTXt_SUPPORTED + text_ptr->lang = NULL; + text_ptr->lang_key = NULL; +#endif + text_ptr->text = text; + + ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1); + + png_free(png_ptr, key); + png_free(png_ptr, text_ptr); + + if (ret) + png_warning(png_ptr, "Insufficient memory to store text chunk."); + } +} +#endif + +#ifdef PNG_READ_iTXt_SUPPORTED +void /* PRIVATE */ +png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 + length) +{ + if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND)) + { + png_error(png_ptr, "Out of place iTXt"); + info_ptr = info_ptr; /* To quiet some compiler warnings */ + } + +#ifdef PNG_MAX_MALLOC_64K + png_ptr->skip_length = 0; /* This may not be necessary */ + + if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */ + { + png_warning(png_ptr, "iTXt chunk too large to fit in memory"); + png_ptr->skip_length = length - (png_uint_32)65535L; + length = (png_uint_32)65535L; + } +#endif + + png_ptr->current_text = (png_charp)png_malloc(png_ptr, + (png_uint_32)(length + 1)); + png_ptr->current_text[length] = '\0'; + png_ptr->current_text_ptr = png_ptr->current_text; + png_ptr->current_text_size = (png_size_t)length; + png_ptr->current_text_left = (png_size_t)length; + png_ptr->process_mode = PNG_READ_iTXt_MODE; +} + +void /* PRIVATE */ +png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr) +{ + + if (png_ptr->buffer_size && png_ptr->current_text_left) + { + png_size_t text_size; + + if (png_ptr->buffer_size < png_ptr->current_text_left) + text_size = png_ptr->buffer_size; + + else + text_size = png_ptr->current_text_left; + + png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size); + png_ptr->current_text_left -= text_size; + png_ptr->current_text_ptr += text_size; + } + if (!(png_ptr->current_text_left)) + { + png_textp text_ptr; + png_charp key; + int comp_flag; + png_charp lang; + png_charp lang_key; + png_charp text; + int ret; + + if (png_ptr->buffer_size < 4) + { + png_push_save_buffer(png_ptr); + return; + } + + png_push_crc_finish(png_ptr); + +#ifdef PNG_MAX_MALLOC_64K + if (png_ptr->skip_length) + return; +#endif + + key = png_ptr->current_text; + + for (lang = key; *lang; lang++) + /* Empty loop */ ; + + if (lang < key + png_ptr->current_text_size - 3) + lang++; + + comp_flag = *lang++; + lang++; /* Skip comp_type, always zero */ + + for (lang_key = lang; *lang_key; lang_key++) + /* Empty loop */ ; + + lang_key++; /* Skip NUL separator */ + + text=lang_key; + + if (lang_key < key + png_ptr->current_text_size - 1) + { + for (; *text; text++) + /* Empty loop */ ; + } + + if (text < key + png_ptr->current_text_size) + text++; + + text_ptr = (png_textp)png_malloc(png_ptr, + (png_uint_32)png_sizeof(png_text)); + + text_ptr->compression = comp_flag + 2; + text_ptr->key = key; + text_ptr->lang = lang; + text_ptr->lang_key = lang_key; + text_ptr->text = text; + text_ptr->text_length = 0; + text_ptr->itxt_length = png_strlen(text); + + ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1); + + png_ptr->current_text = NULL; + + png_free(png_ptr, text_ptr); + if (ret) + png_warning(png_ptr, "Insufficient memory to store iTXt chunk."); + } +} +#endif + +/* This function is called when we haven't found a handler for this + * chunk. If there isn't a problem with the chunk itself (ie a bad chunk + * name or a critical chunk), the chunk is (currently) silently ignored. + */ +void /* PRIVATE */ +png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 + length) +{ + png_uint_32 skip = 0; + + if (!(png_ptr->chunk_name[0] & 0x20)) + { +#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED + if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name) != + PNG_HANDLE_CHUNK_ALWAYS +#ifdef PNG_READ_USER_CHUNKS_SUPPORTED + && png_ptr->read_user_chunk_fn == NULL +#endif + ) +#endif + png_chunk_error(png_ptr, "unknown critical chunk"); + + info_ptr = info_ptr; /* To quiet some compiler warnings */ + } + +#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED + if (png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS) + { +#ifdef PNG_MAX_MALLOC_64K + if (length > (png_uint_32)65535L) + { + png_warning(png_ptr, "unknown chunk too large to fit in memory"); + skip = length - (png_uint_32)65535L; + length = (png_uint_32)65535L; + } +#endif + png_memcpy((png_charp)png_ptr->unknown_chunk.name, + (png_charp)png_ptr->chunk_name, + png_sizeof(png_ptr->unknown_chunk.name)); + png_ptr->unknown_chunk.name[png_sizeof(png_ptr->unknown_chunk.name) - 1] + = '\0'; + + png_ptr->unknown_chunk.size = (png_size_t)length; + + if (length == 0) + png_ptr->unknown_chunk.data = NULL; + + else + { + png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, + (png_uint_32)length); + png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length); + } + +#ifdef PNG_READ_USER_CHUNKS_SUPPORTED + if (png_ptr->read_user_chunk_fn != NULL) + { + /* Callback to user unknown chunk handler */ + int ret; + ret = (*(png_ptr->read_user_chunk_fn)) + (png_ptr, &png_ptr->unknown_chunk); + + if (ret < 0) + png_chunk_error(png_ptr, "error in user chunk"); + + if (ret == 0) + { + if (!(png_ptr->chunk_name[0] & 0x20)) + if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name) != + PNG_HANDLE_CHUNK_ALWAYS) + png_chunk_error(png_ptr, "unknown critical chunk"); + png_set_unknown_chunks(png_ptr, info_ptr, + &png_ptr->unknown_chunk, 1); + } + } + + else +#endif + png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1); + png_free(png_ptr, png_ptr->unknown_chunk.data); + png_ptr->unknown_chunk.data = NULL; + } + + else +#endif + skip=length; + png_push_crc_skip(png_ptr, skip); +} + +void /* PRIVATE */ +png_push_have_info(png_structp png_ptr, png_infop info_ptr) +{ + if (png_ptr->info_fn != NULL) + (*(png_ptr->info_fn))(png_ptr, info_ptr); +} + +void /* PRIVATE */ +png_push_have_end(png_structp png_ptr, png_infop info_ptr) +{ + if (png_ptr->end_fn != NULL) + (*(png_ptr->end_fn))(png_ptr, info_ptr); +} + +void /* PRIVATE */ +png_push_have_row(png_structp png_ptr, png_bytep row) +{ + if (png_ptr->row_fn != NULL) + (*(png_ptr->row_fn))(png_ptr, row, png_ptr->row_number, + (int)png_ptr->pass); +} + +void PNGAPI +png_progressive_combine_row (png_structp png_ptr, + png_bytep old_row, png_bytep new_row) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_CONST int FARDATA png_pass_dsp_mask[7] = + {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff}; +#endif + + if (png_ptr == NULL) + return; + + if (new_row != NULL) /* new_row must == png_ptr->row_buf here. */ + png_combine_row(png_ptr, old_row, png_pass_dsp_mask[png_ptr->pass]); +} + +void PNGAPI +png_set_progressive_read_fn(png_structp png_ptr, png_voidp progressive_ptr, + png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn, + png_progressive_end_ptr end_fn) +{ + if (png_ptr == NULL) + return; + + png_ptr->info_fn = info_fn; + png_ptr->row_fn = row_fn; + png_ptr->end_fn = end_fn; + + png_set_read_fn(png_ptr, progressive_ptr, png_push_fill_buffer); +} + +#if defined(PNG_READ_APNG_SUPPORTED) +void PNGAPI +png_set_progressive_frame_fn(png_structp png_ptr, + png_progressive_frame_ptr frame_info_fn, + png_progressive_frame_ptr frame_end_fn) +{ + png_ptr->frame_info_fn = frame_info_fn; + png_ptr->frame_end_fn = frame_end_fn; +} +#endif + +png_voidp PNGAPI +png_get_progressive_ptr(png_structp png_ptr) +{ + if (png_ptr == NULL) + return (NULL); + + return png_ptr->io_ptr; +} +#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ diff --git a/libs/libpng-src/pngread.c b/libs/libpng-src/pngread.c new file mode 100644 index 000000000..620970b48 --- /dev/null +++ b/libs/libpng-src/pngread.c @@ -0,0 +1,1667 @@ + +/* pngread.c - read a PNG file + * + * Last changed in libpng 1.2.44 [June 26, 2010] + * Copyright (c) 1998-2010 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + * + * This file contains routines that an application calls directly to + * read a PNG file or stream. + */ + +#define PNG_INTERNAL +#define PNG_NO_PEDANTIC_WARNINGS +#include "png.h" +#ifdef PNG_READ_SUPPORTED + + +/* Create a PNG structure for reading, and allocate any memory needed. */ +png_structp PNGAPI +png_create_read_struct(png_const_charp user_png_ver, png_voidp error_ptr, + png_error_ptr error_fn, png_error_ptr warn_fn) +{ + +#ifdef PNG_USER_MEM_SUPPORTED + return (png_create_read_struct_2(user_png_ver, error_ptr, error_fn, + warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL)); +} + +/* Alternate create PNG structure for reading, and allocate any memory + * needed. + */ +png_structp PNGAPI +png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr, + png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr, + png_malloc_ptr malloc_fn, png_free_ptr free_fn) +{ +#endif /* PNG_USER_MEM_SUPPORTED */ + +#ifdef PNG_SETJMP_SUPPORTED + volatile +#endif + png_structp png_ptr; + +#ifdef PNG_SETJMP_SUPPORTED +#ifdef USE_FAR_KEYWORD + jmp_buf jmpbuf; +#endif +#endif + + int i; + + png_debug(1, "in png_create_read_struct"); + +#ifdef PNG_USER_MEM_SUPPORTED + png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG, + (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr); +#else + png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG); +#endif + if (png_ptr == NULL) + return (NULL); + + /* Added at libpng-1.2.6 */ +#ifdef PNG_USER_LIMITS_SUPPORTED + png_ptr->user_width_max = PNG_USER_WIDTH_MAX; + png_ptr->user_height_max = PNG_USER_HEIGHT_MAX; +# ifdef PNG_USER_CHUNK_CACHE_MAX + /* Added at libpng-1.2.43 and 1.4.0 */ + png_ptr->user_chunk_cache_max = PNG_USER_CHUNK_CACHE_MAX; +# endif +# ifdef PNG_SET_USER_CHUNK_MALLOC_MAX + /* Added at libpng-1.2.43 and 1.4.1 */ + png_ptr->user_chunk_malloc_max = PNG_USER_CHUNK_MALLOC_MAX; +# endif +#endif + +#ifdef PNG_SETJMP_SUPPORTED +#ifdef USE_FAR_KEYWORD + if (setjmp(jmpbuf)) +#else + if (setjmp(png_ptr->jmpbuf)) +#endif + { + png_free(png_ptr, png_ptr->zbuf); + png_ptr->zbuf = NULL; +#ifdef PNG_USER_MEM_SUPPORTED + png_destroy_struct_2((png_voidp)png_ptr, + (png_free_ptr)free_fn, (png_voidp)mem_ptr); +#else + png_destroy_struct((png_voidp)png_ptr); +#endif + return (NULL); + } +#ifdef USE_FAR_KEYWORD + png_memcpy(png_ptr->jmpbuf, jmpbuf, png_sizeof(jmp_buf)); +#endif +#endif /* PNG_SETJMP_SUPPORTED */ + +#ifdef PNG_USER_MEM_SUPPORTED + png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn); +#endif + + png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn); + + if (user_png_ver) + { + i = 0; + do + { + if (user_png_ver[i] != png_libpng_ver[i]) + png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; + } while (png_libpng_ver[i++]); + } + else + png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; + + + if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH) + { + /* Libpng 0.90 and later are binary incompatible with libpng 0.89, so + * we must recompile any applications that use any older library version. + * For versions after libpng 1.0, we will be compatible, so we need + * only check the first digit. + */ + if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] || + (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) || + (user_png_ver[0] == '0' && user_png_ver[2] < '9')) + { +#if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE) + char msg[80]; + if (user_png_ver) + { + png_snprintf(msg, 80, + "Application was compiled with png.h from libpng-%.20s", + user_png_ver); + png_warning(png_ptr, msg); + } + png_snprintf(msg, 80, + "Application is running with png.c from libpng-%.20s", + png_libpng_ver); + png_warning(png_ptr, msg); +#endif +#ifdef PNG_ERROR_NUMBERS_SUPPORTED + png_ptr->flags = 0; +#endif + png_error(png_ptr, + "Incompatible libpng version in application and library"); + } + } + + /* Initialize zbuf - compression buffer */ + png_ptr->zbuf_size = PNG_ZBUF_SIZE; + png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, + (png_uint_32)png_ptr->zbuf_size); + png_ptr->zstream.zalloc = png_zalloc; + png_ptr->zstream.zfree = png_zfree; + png_ptr->zstream.opaque = (voidpf)png_ptr; + + switch (inflateInit(&png_ptr->zstream)) + { + case Z_OK: /* Do nothing */ break; + case Z_MEM_ERROR: + case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory error"); + break; + case Z_VERSION_ERROR: png_error(png_ptr, "zlib version error"); + break; + default: png_error(png_ptr, "Unknown zlib error"); + } + + + png_ptr->zstream.next_out = png_ptr->zbuf; + png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; + + png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL); + +#ifdef PNG_SETJMP_SUPPORTED +/* Applications that neglect to set up their own setjmp() and then + encounter a png_error() will longjmp here. Since the jmpbuf is + then meaningless we abort instead of returning. */ +#ifdef USE_FAR_KEYWORD + if (setjmp(jmpbuf)) + PNG_ABORT(); + png_memcpy(png_ptr->jmpbuf, jmpbuf, png_sizeof(jmp_buf)); +#else + if (setjmp(png_ptr->jmpbuf)) + PNG_ABORT(); +#endif +#endif /* PNG_SETJMP_SUPPORTED */ + + return (png_ptr); +} + +#if defined(PNG_1_0_X) || defined(PNG_1_2_X) +/* Initialize PNG structure for reading, and allocate any memory needed. + * This interface is deprecated in favour of the png_create_read_struct(), + * and it will disappear as of libpng-1.3.0. + */ +#undef png_read_init +void PNGAPI +png_read_init(png_structp png_ptr) +{ + /* We only come here via pre-1.0.7-compiled applications */ + png_read_init_2(png_ptr, "1.0.6 or earlier", 0, 0); +} + +void PNGAPI +png_read_init_2(png_structp png_ptr, png_const_charp user_png_ver, + png_size_t png_struct_size, png_size_t png_info_size) +{ + /* We only come here via pre-1.0.12-compiled applications */ + if (png_ptr == NULL) + return; +#if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE) + if (png_sizeof(png_struct) > png_struct_size || + png_sizeof(png_info) > png_info_size) + { + char msg[80]; + png_ptr->warning_fn = NULL; + if (user_png_ver) + { + png_snprintf(msg, 80, + "Application was compiled with png.h from libpng-%.20s", + user_png_ver); + png_warning(png_ptr, msg); + } + png_snprintf(msg, 80, + "Application is running with png.c from libpng-%.20s", + png_libpng_ver); + png_warning(png_ptr, msg); + } +#endif + if (png_sizeof(png_struct) > png_struct_size) + { + png_ptr->error_fn = NULL; +#ifdef PNG_ERROR_NUMBERS_SUPPORTED + png_ptr->flags = 0; +#endif + png_error(png_ptr, + "The png struct allocated by the application for reading is" + " too small."); + } + if (png_sizeof(png_info) > png_info_size) + { + png_ptr->error_fn = NULL; +#ifdef PNG_ERROR_NUMBERS_SUPPORTED + png_ptr->flags = 0; +#endif + png_error(png_ptr, + "The info struct allocated by application for reading is" + " too small."); + } + png_read_init_3(&png_ptr, user_png_ver, png_struct_size); +} +#endif /* PNG_1_0_X || PNG_1_2_X */ + +void PNGAPI +png_read_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver, + png_size_t png_struct_size) +{ +#ifdef PNG_SETJMP_SUPPORTED + jmp_buf tmp_jmp; /* to save current jump buffer */ +#endif + + int i = 0; + + png_structp png_ptr=*ptr_ptr; + + if (png_ptr == NULL) + return; + + do + { + if (user_png_ver[i] != png_libpng_ver[i]) + { +#ifdef PNG_LEGACY_SUPPORTED + png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; +#else + png_ptr->warning_fn = NULL; + png_warning(png_ptr, + "Application uses deprecated png_read_init() and should be" + " recompiled."); + break; +#endif + } + } while (png_libpng_ver[i++]); + + png_debug(1, "in png_read_init_3"); + +#ifdef PNG_SETJMP_SUPPORTED + /* Save jump buffer and error functions */ + png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof(jmp_buf)); +#endif + + if (png_sizeof(png_struct) > png_struct_size) + { + png_destroy_struct(png_ptr); + *ptr_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG); + png_ptr = *ptr_ptr; + } + + /* Reset all variables to 0 */ + png_memset(png_ptr, 0, png_sizeof(png_struct)); + +#ifdef PNG_SETJMP_SUPPORTED + /* Restore jump buffer */ + png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof(jmp_buf)); +#endif + + /* Added at libpng-1.2.6 */ +#ifdef PNG_SET_USER_LIMITS_SUPPORTED + png_ptr->user_width_max = PNG_USER_WIDTH_MAX; + png_ptr->user_height_max = PNG_USER_HEIGHT_MAX; +#endif + + /* Initialize zbuf - compression buffer */ + png_ptr->zbuf_size = PNG_ZBUF_SIZE; + png_ptr->zstream.zalloc = png_zalloc; + png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, + (png_uint_32)png_ptr->zbuf_size); + png_ptr->zstream.zalloc = png_zalloc; + png_ptr->zstream.zfree = png_zfree; + png_ptr->zstream.opaque = (voidpf)png_ptr; + + switch (inflateInit(&png_ptr->zstream)) + { + case Z_OK: /* Do nothing */ break; + case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory error"); break; + case Z_VERSION_ERROR: png_error(png_ptr, "zlib version error"); + break; + default: png_error(png_ptr, "Unknown zlib error"); + } + + png_ptr->zstream.next_out = png_ptr->zbuf; + png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; + + png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL); +} + +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED +/* Read the information before the actual image data. This has been + * changed in v0.90 to allow reading a file that already has the magic + * bytes read from the stream. You can tell libpng how many bytes have + * been read from the beginning of the stream (up to the maximum of 8) + * via png_set_sig_bytes(), and we will only check the remaining bytes + * here. The application can then have access to the signature bytes we + * read if it is determined that this isn't a valid PNG file. + */ +void PNGAPI +png_read_info(png_structp png_ptr, png_infop info_ptr) +{ + png_debug(1, "in png_read_info"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + /* If we haven't checked all of the PNG signature bytes, do so now. */ + if (png_ptr->sig_bytes < 8) + { + png_size_t num_checked = png_ptr->sig_bytes, + num_to_check = 8 - num_checked; + + png_read_data(png_ptr, &(info_ptr->signature[num_checked]), num_to_check); + png_ptr->sig_bytes = 8; + + if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check)) + { + if (num_checked < 4 && + png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4)) + png_error(png_ptr, "Not a PNG file"); + else + png_error(png_ptr, "PNG file corrupted by ASCII conversion"); + } + if (num_checked < 3) + png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE; + } + + for (;;) + { +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_CONST PNG_IHDR; + PNG_CONST PNG_IDAT; + PNG_CONST PNG_IEND; + PNG_CONST PNG_PLTE; +#ifdef PNG_READ_bKGD_SUPPORTED + PNG_CONST PNG_bKGD; +#endif +#ifdef PNG_READ_cHRM_SUPPORTED + PNG_CONST PNG_cHRM; +#endif +#ifdef PNG_READ_gAMA_SUPPORTED + PNG_CONST PNG_gAMA; +#endif +#ifdef PNG_READ_hIST_SUPPORTED + PNG_CONST PNG_hIST; +#endif +#ifdef PNG_READ_iCCP_SUPPORTED + PNG_CONST PNG_iCCP; +#endif +#ifdef PNG_READ_iTXt_SUPPORTED + PNG_CONST PNG_iTXt; +#endif +#ifdef PNG_READ_oFFs_SUPPORTED + PNG_CONST PNG_oFFs; +#endif +#ifdef PNG_READ_pCAL_SUPPORTED + PNG_CONST PNG_pCAL; +#endif +#ifdef PNG_READ_pHYs_SUPPORTED + PNG_CONST PNG_pHYs; +#endif +#ifdef PNG_READ_sBIT_SUPPORTED + PNG_CONST PNG_sBIT; +#endif +#ifdef PNG_READ_sCAL_SUPPORTED + PNG_CONST PNG_sCAL; +#endif +#ifdef PNG_READ_sPLT_SUPPORTED + PNG_CONST PNG_sPLT; +#endif +#ifdef PNG_READ_sRGB_SUPPORTED + PNG_CONST PNG_sRGB; +#endif +#ifdef PNG_READ_tEXt_SUPPORTED + PNG_CONST PNG_tEXt; +#endif +#ifdef PNG_READ_tIME_SUPPORTED + PNG_CONST PNG_tIME; +#endif +#ifdef PNG_READ_tRNS_SUPPORTED + PNG_CONST PNG_tRNS; +#endif +#ifdef PNG_READ_zTXt_SUPPORTED + PNG_CONST PNG_zTXt; +#endif +#if defined(PNG_READ_APNG_SUPPORTED) + PNG_CONST PNG_acTL; + PNG_CONST PNG_fcTL; + PNG_CONST PNG_fdAT; +#endif +#endif /* PNG_USE_LOCAL_ARRAYS */ + png_uint_32 length = png_read_chunk_header(png_ptr); + PNG_CONST png_bytep chunk_name = png_ptr->chunk_name; + + /* This should be a binary subdivision search or a hash for + * matching the chunk name rather than a linear search. + */ + if (!png_memcmp(chunk_name, png_IDAT, 4)) + if (png_ptr->mode & PNG_AFTER_IDAT) + png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT; + + if (!png_memcmp(chunk_name, png_IHDR, 4)) + png_handle_IHDR(png_ptr, info_ptr, length); + else if (!png_memcmp(chunk_name, png_IEND, 4)) + png_handle_IEND(png_ptr, info_ptr, length); +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED + else if (png_handle_as_unknown(png_ptr, chunk_name)) + { + if (!png_memcmp(chunk_name, png_IDAT, 4)) + png_ptr->mode |= PNG_HAVE_IDAT; + png_handle_unknown(png_ptr, info_ptr, length); + if (!png_memcmp(chunk_name, png_PLTE, 4)) + png_ptr->mode |= PNG_HAVE_PLTE; + else if (!png_memcmp(chunk_name, png_IDAT, 4)) + { + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before IDAT"); + else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && + !(png_ptr->mode & PNG_HAVE_PLTE)) + png_error(png_ptr, "Missing PLTE before IDAT"); + break; + } + } +#endif + else if (!png_memcmp(chunk_name, png_PLTE, 4)) + png_handle_PLTE(png_ptr, info_ptr, length); + else if (!png_memcmp(chunk_name, png_IDAT, 4)) + { + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before IDAT"); + else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && + !(png_ptr->mode & PNG_HAVE_PLTE)) + png_error(png_ptr, "Missing PLTE before IDAT"); +#if defined(PNG_READ_APNG_SUPPORTED) + png_have_info(png_ptr, info_ptr); +#endif + png_ptr->idat_size = length; + png_ptr->mode |= PNG_HAVE_IDAT; + break; + } +#ifdef PNG_READ_bKGD_SUPPORTED + else if (!png_memcmp(chunk_name, png_bKGD, 4)) + png_handle_bKGD(png_ptr, info_ptr, length); +#endif +#ifdef PNG_READ_cHRM_SUPPORTED + else if (!png_memcmp(chunk_name, png_cHRM, 4)) + png_handle_cHRM(png_ptr, info_ptr, length); +#endif +#ifdef PNG_READ_gAMA_SUPPORTED + else if (!png_memcmp(chunk_name, png_gAMA, 4)) + png_handle_gAMA(png_ptr, info_ptr, length); +#endif +#ifdef PNG_READ_hIST_SUPPORTED + else if (!png_memcmp(chunk_name, png_hIST, 4)) + png_handle_hIST(png_ptr, info_ptr, length); +#endif +#ifdef PNG_READ_oFFs_SUPPORTED + else if (!png_memcmp(chunk_name, png_oFFs, 4)) + png_handle_oFFs(png_ptr, info_ptr, length); +#endif +#ifdef PNG_READ_pCAL_SUPPORTED + else if (!png_memcmp(chunk_name, png_pCAL, 4)) + png_handle_pCAL(png_ptr, info_ptr, length); +#endif +#ifdef PNG_READ_sCAL_SUPPORTED + else if (!png_memcmp(chunk_name, png_sCAL, 4)) + png_handle_sCAL(png_ptr, info_ptr, length); +#endif +#ifdef PNG_READ_pHYs_SUPPORTED + else if (!png_memcmp(chunk_name, png_pHYs, 4)) + png_handle_pHYs(png_ptr, info_ptr, length); +#endif +#ifdef PNG_READ_sBIT_SUPPORTED + else if (!png_memcmp(chunk_name, png_sBIT, 4)) + png_handle_sBIT(png_ptr, info_ptr, length); +#endif +#ifdef PNG_READ_sRGB_SUPPORTED + else if (!png_memcmp(chunk_name, png_sRGB, 4)) + png_handle_sRGB(png_ptr, info_ptr, length); +#endif +#ifdef PNG_READ_iCCP_SUPPORTED + else if (!png_memcmp(chunk_name, png_iCCP, 4)) + png_handle_iCCP(png_ptr, info_ptr, length); +#endif +#ifdef PNG_READ_sPLT_SUPPORTED + else if (!png_memcmp(chunk_name, png_sPLT, 4)) + png_handle_sPLT(png_ptr, info_ptr, length); +#endif +#ifdef PNG_READ_tEXt_SUPPORTED + else if (!png_memcmp(chunk_name, png_tEXt, 4)) + png_handle_tEXt(png_ptr, info_ptr, length); +#endif +#ifdef PNG_READ_tIME_SUPPORTED + else if (!png_memcmp(chunk_name, png_tIME, 4)) + png_handle_tIME(png_ptr, info_ptr, length); +#endif +#ifdef PNG_READ_tRNS_SUPPORTED + else if (!png_memcmp(chunk_name, png_tRNS, 4)) + png_handle_tRNS(png_ptr, info_ptr, length); +#endif +#ifdef PNG_READ_zTXt_SUPPORTED + else if (!png_memcmp(chunk_name, png_zTXt, 4)) + png_handle_zTXt(png_ptr, info_ptr, length); +#endif +#ifdef PNG_READ_iTXt_SUPPORTED + else if (!png_memcmp(chunk_name, png_iTXt, 4)) + png_handle_iTXt(png_ptr, info_ptr, length); +#endif +#if defined(PNG_READ_APNG_SUPPORTED) + else if (!png_memcmp(chunk_name, png_acTL, 4)) + png_handle_acTL(png_ptr, info_ptr, length); + else if (!png_memcmp(chunk_name, png_fcTL, 4)) + png_handle_fcTL(png_ptr, info_ptr, length); + else if (!png_memcmp(chunk_name, png_fdAT, 4)) + png_handle_fdAT(png_ptr, info_ptr, length); +#endif + else + png_handle_unknown(png_ptr, info_ptr, length); + } +} +#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ + +#if defined(PNG_READ_APNG_SUPPORTED) +void PNGAPI +png_read_frame_head(png_structp png_ptr, png_infop info_ptr) +{ + png_byte have_chunk_after_DAT; /* after IDAT or after fdAT */ + + png_debug(0, "Reading frame head"); + + if (!(png_ptr->mode & PNG_HAVE_acTL)) + png_error(png_ptr, "attempt to png_read_frame_head() but " + "no acTL present"); + + /* do nothing for the main IDAT */ + if (png_ptr->num_frames_read == 0) + return; + + png_crc_finish(png_ptr, 0); /* CRC from last IDAT or fdAT chunk */ + + png_read_reset(png_ptr); + png_ptr->mode &= ~PNG_HAVE_fcTL; + + have_chunk_after_DAT = 0; + for (;;) + { +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_IDAT; + PNG_fdAT; + PNG_fcTL; +#endif + png_byte chunk_length[4]; + png_uint_32 length; + + png_read_data(png_ptr, chunk_length, 4); + length = png_get_uint_31(png_ptr, chunk_length); + + png_reset_crc(png_ptr); + png_crc_read(png_ptr, png_ptr->chunk_name, 4); + + if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) + { + /* discard trailing IDATs for the first frame */ + if (have_chunk_after_DAT || png_ptr->num_frames_read > 1) + png_error(png_ptr, "png_read_frame_head(): out of place IDAT"); + png_crc_finish(png_ptr, length); + } + else if (!png_memcmp(png_ptr->chunk_name, png_fcTL, 4)) + { + png_handle_fcTL(png_ptr, info_ptr, length); + have_chunk_after_DAT = 1; + } + else if (!png_memcmp(png_ptr->chunk_name, png_fdAT, 4)) + { + png_ensure_sequence_number(png_ptr, length); + + /* discard trailing fdATs for frames other than the first */ + if (!have_chunk_after_DAT && png_ptr->num_frames_read > 1) + png_crc_finish(png_ptr, length - 4); + else if(png_ptr->mode & PNG_HAVE_fcTL) + { + png_ptr->idat_size = length - 4; + png_ptr->mode |= PNG_HAVE_IDAT; + + break; + } + else + png_error(png_ptr, "png_read_frame_head(): out of place fdAT"); + } + else + { + png_warning(png_ptr, "Skipped (ignored) a chunk " + "between APNG chunks"); + png_crc_finish(png_ptr, length); + } + } +} +#endif /* PNG_READ_APNG_SUPPORTED */ + +/* Optional call to update the users info_ptr structure */ +void PNGAPI +png_read_update_info(png_structp png_ptr, png_infop info_ptr) +{ + png_debug(1, "in png_read_update_info"); + + if (png_ptr == NULL) + return; + if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) + png_read_start_row(png_ptr); + else + png_warning(png_ptr, + "Ignoring extra png_read_update_info() call; row buffer not reallocated"); + + png_read_transform_info(png_ptr, info_ptr); +} + +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED +/* Initialize palette, background, etc, after transformations + * are set, but before any reading takes place. This allows + * the user to obtain a gamma-corrected palette, for example. + * If the user doesn't call this, we will do it ourselves. + */ +void PNGAPI +png_start_read_image(png_structp png_ptr) +{ + png_debug(1, "in png_start_read_image"); + + if (png_ptr == NULL) + return; + if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) + png_read_start_row(png_ptr); +} +#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ + +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED +void PNGAPI +png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row) +{ + PNG_CONST PNG_IDAT; +#if defined(PNG_READ_APNG_SUPPORTED) + PNG_CONST PNG_fdAT; + PNG_CONST PNG_IEND; +#endif + PNG_CONST int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, + 0xff}; + PNG_CONST int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff}; + int ret; + + if (png_ptr == NULL) + return; + + png_debug2(1, "in png_read_row (row %lu, pass %d)", + png_ptr->row_number, png_ptr->pass); + + if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) + png_read_start_row(png_ptr); + if (png_ptr->row_number == 0 && png_ptr->pass == 0) + { + /* Check for transforms that have been set but were defined out */ +#if defined(PNG_WRITE_INVERT_SUPPORTED) && !defined(PNG_READ_INVERT_SUPPORTED) + if (png_ptr->transformations & PNG_INVERT_MONO) + png_warning(png_ptr, "PNG_READ_INVERT_SUPPORTED is not defined."); +#endif +#if defined(PNG_WRITE_FILLER_SUPPORTED) && !defined(PNG_READ_FILLER_SUPPORTED) + if (png_ptr->transformations & PNG_FILLER) + png_warning(png_ptr, "PNG_READ_FILLER_SUPPORTED is not defined."); +#endif +#if defined(PNG_WRITE_PACKSWAP_SUPPORTED) && \ + !defined(PNG_READ_PACKSWAP_SUPPORTED) + if (png_ptr->transformations & PNG_PACKSWAP) + png_warning(png_ptr, "PNG_READ_PACKSWAP_SUPPORTED is not defined."); +#endif +#if defined(PNG_WRITE_PACK_SUPPORTED) && !defined(PNG_READ_PACK_SUPPORTED) + if (png_ptr->transformations & PNG_PACK) + png_warning(png_ptr, "PNG_READ_PACK_SUPPORTED is not defined."); +#endif +#if defined(PNG_WRITE_SHIFT_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED) + if (png_ptr->transformations & PNG_SHIFT) + png_warning(png_ptr, "PNG_READ_SHIFT_SUPPORTED is not defined."); +#endif +#if defined(PNG_WRITE_BGR_SUPPORTED) && !defined(PNG_READ_BGR_SUPPORTED) + if (png_ptr->transformations & PNG_BGR) + png_warning(png_ptr, "PNG_READ_BGR_SUPPORTED is not defined."); +#endif +#if defined(PNG_WRITE_SWAP_SUPPORTED) && !defined(PNG_READ_SWAP_SUPPORTED) + if (png_ptr->transformations & PNG_SWAP_BYTES) + png_warning(png_ptr, "PNG_READ_SWAP_SUPPORTED is not defined."); +#endif + } + +#ifdef PNG_READ_INTERLACING_SUPPORTED + /* If interlaced and we do not need a new row, combine row and return */ + if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE)) + { + switch (png_ptr->pass) + { + case 0: + if (png_ptr->row_number & 0x07) + { + if (dsp_row != NULL) + png_combine_row(png_ptr, dsp_row, + png_pass_dsp_mask[png_ptr->pass]); + png_read_finish_row(png_ptr); + return; + } + break; + case 1: + if ((png_ptr->row_number & 0x07) || png_ptr->width < 5) + { + if (dsp_row != NULL) + png_combine_row(png_ptr, dsp_row, + png_pass_dsp_mask[png_ptr->pass]); + png_read_finish_row(png_ptr); + return; + } + break; + case 2: + if ((png_ptr->row_number & 0x07) != 4) + { + if (dsp_row != NULL && (png_ptr->row_number & 4)) + png_combine_row(png_ptr, dsp_row, + png_pass_dsp_mask[png_ptr->pass]); + png_read_finish_row(png_ptr); + return; + } + break; + case 3: + if ((png_ptr->row_number & 3) || png_ptr->width < 3) + { + if (dsp_row != NULL) + png_combine_row(png_ptr, dsp_row, + png_pass_dsp_mask[png_ptr->pass]); + png_read_finish_row(png_ptr); + return; + } + break; + case 4: + if ((png_ptr->row_number & 3) != 2) + { + if (dsp_row != NULL && (png_ptr->row_number & 2)) + png_combine_row(png_ptr, dsp_row, + png_pass_dsp_mask[png_ptr->pass]); + png_read_finish_row(png_ptr); + return; + } + break; + case 5: + if ((png_ptr->row_number & 1) || png_ptr->width < 2) + { + if (dsp_row != NULL) + png_combine_row(png_ptr, dsp_row, + png_pass_dsp_mask[png_ptr->pass]); + png_read_finish_row(png_ptr); + return; + } + break; + case 6: + if (!(png_ptr->row_number & 1)) + { + png_read_finish_row(png_ptr); + return; + } + break; + } + } +#endif + + if (!(png_ptr->mode & PNG_HAVE_IDAT)) + png_error(png_ptr, "Invalid attempt to read row data"); + + png_ptr->zstream.next_out = png_ptr->row_buf; + png_ptr->zstream.avail_out = + (uInt)(PNG_ROWBYTES(png_ptr->pixel_depth, + png_ptr->iwidth) + 1); + do + { + if (!(png_ptr->zstream.avail_in)) + { + png_uint_32 bytes_to_skip = 0; + + while (!png_ptr->idat_size || bytes_to_skip != 0) + { + png_crc_finish(png_ptr, bytes_to_skip); + bytes_to_skip = 0; + + png_ptr->idat_size = png_read_chunk_header(png_ptr); + +#if defined(PNG_READ_APNG_SUPPORTED) + if (png_ptr->num_frames_read == 0) + { +#endif + if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) + png_error(png_ptr, "Not enough image data"); +#if defined(PNG_READ_APNG_SUPPORTED) + } + else + { + if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4)) + png_error(png_ptr, "Not enough image data"); + if (png_memcmp(png_ptr->chunk_name, png_fdAT, 4)) + { + png_warning(png_ptr, "Skipped (ignored) a chunk " + "between APNG chunks"); + bytes_to_skip = png_ptr->idat_size; + continue; + } + + png_ensure_sequence_number(png_ptr, png_ptr->idat_size); + + png_ptr->idat_size -= 4; + } +#endif + } + png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size; + png_ptr->zstream.next_in = png_ptr->zbuf; + if (png_ptr->zbuf_size > png_ptr->idat_size) + png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size; + png_crc_read(png_ptr, png_ptr->zbuf, + (png_size_t)png_ptr->zstream.avail_in); + png_ptr->idat_size -= png_ptr->zstream.avail_in; + } + ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH); + if (ret == Z_STREAM_END) + { + if (png_ptr->zstream.avail_out || png_ptr->zstream.avail_in || + png_ptr->idat_size) + png_error(png_ptr, "Extra compressed data"); + png_ptr->mode |= PNG_AFTER_IDAT; + png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED; +#if defined(PNG_READ_APNG_SUPPORTED) + png_ptr->num_frames_read++; +#endif + break; + } + if (ret != Z_OK) + png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg : + "Decompression error"); + + } while (png_ptr->zstream.avail_out); + + png_ptr->row_info.color_type = png_ptr->color_type; + png_ptr->row_info.width = png_ptr->iwidth; + png_ptr->row_info.channels = png_ptr->channels; + png_ptr->row_info.bit_depth = png_ptr->bit_depth; + png_ptr->row_info.pixel_depth = png_ptr->pixel_depth; + png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth, + png_ptr->row_info.width); + + if (png_ptr->row_buf[0]) + png_read_filter_row(png_ptr, &(png_ptr->row_info), + png_ptr->row_buf + 1, png_ptr->prev_row + 1, + (int)(png_ptr->row_buf[0])); + + png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf, + png_ptr->rowbytes + 1); + +#ifdef PNG_MNG_FEATURES_SUPPORTED + if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && + (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING)) + { + /* Intrapixel differencing */ + png_do_read_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1); + } +#endif + + + if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA)) + png_do_read_transformations(png_ptr); + +#ifdef PNG_READ_INTERLACING_SUPPORTED + /* Blow up interlaced rows to full size */ + if (png_ptr->interlaced && + (png_ptr->transformations & PNG_INTERLACE)) + { + if (png_ptr->pass < 6) + /* Old interface (pre-1.0.9): + * png_do_read_interlace(&(png_ptr->row_info), + * png_ptr->row_buf + 1, png_ptr->pass, png_ptr->transformations); + */ + png_do_read_interlace(png_ptr); + + if (dsp_row != NULL) + png_combine_row(png_ptr, dsp_row, + png_pass_dsp_mask[png_ptr->pass]); + if (row != NULL) + png_combine_row(png_ptr, row, + png_pass_mask[png_ptr->pass]); + } + else +#endif + { + if (row != NULL) + png_combine_row(png_ptr, row, 0xff); + if (dsp_row != NULL) + png_combine_row(png_ptr, dsp_row, 0xff); + } + png_read_finish_row(png_ptr); + + if (png_ptr->read_row_fn != NULL) + (*(png_ptr->read_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass); +} +#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ + +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED +/* Read one or more rows of image data. If the image is interlaced, + * and png_set_interlace_handling() has been called, the rows need to + * contain the contents of the rows from the previous pass. If the + * image has alpha or transparency, and png_handle_alpha()[*] has been + * called, the rows contents must be initialized to the contents of the + * screen. + * + * "row" holds the actual image, and pixels are placed in it + * as they arrive. If the image is displayed after each pass, it will + * appear to "sparkle" in. "display_row" can be used to display a + * "chunky" progressive image, with finer detail added as it becomes + * available. If you do not want this "chunky" display, you may pass + * NULL for display_row. If you do not want the sparkle display, and + * you have not called png_handle_alpha(), you may pass NULL for rows. + * If you have called png_handle_alpha(), and the image has either an + * alpha channel or a transparency chunk, you must provide a buffer for + * rows. In this case, you do not have to provide a display_row buffer + * also, but you may. If the image is not interlaced, or if you have + * not called png_set_interlace_handling(), the display_row buffer will + * be ignored, so pass NULL to it. + * + * [*] png_handle_alpha() does not exist yet, as of this version of libpng + */ + +void PNGAPI +png_read_rows(png_structp png_ptr, png_bytepp row, + png_bytepp display_row, png_uint_32 num_rows) +{ + png_uint_32 i; + png_bytepp rp; + png_bytepp dp; + + png_debug(1, "in png_read_rows"); + + if (png_ptr == NULL) + return; + rp = row; + dp = display_row; + if (rp != NULL && dp != NULL) + for (i = 0; i < num_rows; i++) + { + png_bytep rptr = *rp++; + png_bytep dptr = *dp++; + + png_read_row(png_ptr, rptr, dptr); + } + else if (rp != NULL) + for (i = 0; i < num_rows; i++) + { + png_bytep rptr = *rp; + png_read_row(png_ptr, rptr, png_bytep_NULL); + rp++; + } + else if (dp != NULL) + for (i = 0; i < num_rows; i++) + { + png_bytep dptr = *dp; + png_read_row(png_ptr, png_bytep_NULL, dptr); + dp++; + } +} +#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ + +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED +/* Read the entire image. If the image has an alpha channel or a tRNS + * chunk, and you have called png_handle_alpha()[*], you will need to + * initialize the image to the current image that PNG will be overlaying. + * We set the num_rows again here, in case it was incorrectly set in + * png_read_start_row() by a call to png_read_update_info() or + * png_start_read_image() if png_set_interlace_handling() wasn't called + * prior to either of these functions like it should have been. You can + * only call this function once. If you desire to have an image for + * each pass of a interlaced image, use png_read_rows() instead. + * + * [*] png_handle_alpha() does not exist yet, as of this version of libpng + */ +void PNGAPI +png_read_image(png_structp png_ptr, png_bytepp image) +{ + png_uint_32 i, image_height; + int pass, j; + png_bytepp rp; + + png_debug(1, "in png_read_image"); + + if (png_ptr == NULL) + return; + +#ifdef PNG_READ_INTERLACING_SUPPORTED + pass = png_set_interlace_handling(png_ptr); +#else + if (png_ptr->interlaced) + png_error(png_ptr, + "Cannot read interlaced image -- interlace handler disabled."); + pass = 1; +#endif + + + image_height=png_ptr->height; + png_ptr->num_rows = image_height; /* Make sure this is set correctly */ + + for (j = 0; j < pass; j++) + { + rp = image; + for (i = 0; i < image_height; i++) + { + png_read_row(png_ptr, *rp, png_bytep_NULL); + rp++; + } + } +} +#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ + +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED +/* Read the end of the PNG file. Will not read past the end of the + * file, will verify the end is accurate, and will read any comments + * or time information at the end of the file, if info is not NULL. + */ +void PNGAPI +png_read_end(png_structp png_ptr, png_infop info_ptr) +{ + png_debug(1, "in png_read_end"); + + if (png_ptr == NULL) + return; + png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */ + + do + { +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_CONST PNG_IHDR; + PNG_CONST PNG_IDAT; + PNG_CONST PNG_IEND; + PNG_CONST PNG_PLTE; +#ifdef PNG_READ_bKGD_SUPPORTED + PNG_CONST PNG_bKGD; +#endif +#ifdef PNG_READ_cHRM_SUPPORTED + PNG_CONST PNG_cHRM; +#endif +#ifdef PNG_READ_gAMA_SUPPORTED + PNG_CONST PNG_gAMA; +#endif +#ifdef PNG_READ_hIST_SUPPORTED + PNG_CONST PNG_hIST; +#endif +#ifdef PNG_READ_iCCP_SUPPORTED + PNG_CONST PNG_iCCP; +#endif +#ifdef PNG_READ_iTXt_SUPPORTED + PNG_CONST PNG_iTXt; +#endif +#ifdef PNG_READ_oFFs_SUPPORTED + PNG_CONST PNG_oFFs; +#endif +#ifdef PNG_READ_pCAL_SUPPORTED + PNG_CONST PNG_pCAL; +#endif +#ifdef PNG_READ_pHYs_SUPPORTED + PNG_CONST PNG_pHYs; +#endif +#ifdef PNG_READ_sBIT_SUPPORTED + PNG_CONST PNG_sBIT; +#endif +#ifdef PNG_READ_sCAL_SUPPORTED + PNG_CONST PNG_sCAL; +#endif +#ifdef PNG_READ_sPLT_SUPPORTED + PNG_CONST PNG_sPLT; +#endif +#ifdef PNG_READ_sRGB_SUPPORTED + PNG_CONST PNG_sRGB; +#endif +#ifdef PNG_READ_tEXt_SUPPORTED + PNG_CONST PNG_tEXt; +#endif +#ifdef PNG_READ_tIME_SUPPORTED + PNG_CONST PNG_tIME; +#endif +#ifdef PNG_READ_tRNS_SUPPORTED + PNG_CONST PNG_tRNS; +#endif +#ifdef PNG_READ_zTXt_SUPPORTED + PNG_CONST PNG_zTXt; +#endif +#if defined(PNG_READ_APNG_SUPPORTED) + PNG_CONST PNG_acTL; + PNG_CONST PNG_fcTL; + PNG_CONST PNG_fdAT; +#endif +#endif /* PNG_USE_LOCAL_ARRAYS */ + png_uint_32 length = png_read_chunk_header(png_ptr); + PNG_CONST png_bytep chunk_name = png_ptr->chunk_name; + + if (!png_memcmp(chunk_name, png_IHDR, 4)) + png_handle_IHDR(png_ptr, info_ptr, length); + else if (!png_memcmp(chunk_name, png_IEND, 4)) + png_handle_IEND(png_ptr, info_ptr, length); +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED + else if (png_handle_as_unknown(png_ptr, chunk_name)) + { + if (!png_memcmp(chunk_name, png_IDAT, 4)) + { + if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT)) + png_error(png_ptr, "Too many IDAT's found"); + } + png_handle_unknown(png_ptr, info_ptr, length); + if (!png_memcmp(chunk_name, png_PLTE, 4)) + png_ptr->mode |= PNG_HAVE_PLTE; + } +#endif + else if (!png_memcmp(chunk_name, png_IDAT, 4)) + { + /* Zero length IDATs are legal after the last IDAT has been + * read, but not after other chunks have been read. + */ + if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT)) + png_error(png_ptr, "Too many IDAT's found"); + png_crc_finish(png_ptr, length); + } + else if (!png_memcmp(chunk_name, png_PLTE, 4)) + png_handle_PLTE(png_ptr, info_ptr, length); +#ifdef PNG_READ_bKGD_SUPPORTED + else if (!png_memcmp(chunk_name, png_bKGD, 4)) + png_handle_bKGD(png_ptr, info_ptr, length); +#endif +#ifdef PNG_READ_cHRM_SUPPORTED + else if (!png_memcmp(chunk_name, png_cHRM, 4)) + png_handle_cHRM(png_ptr, info_ptr, length); +#endif +#ifdef PNG_READ_gAMA_SUPPORTED + else if (!png_memcmp(chunk_name, png_gAMA, 4)) + png_handle_gAMA(png_ptr, info_ptr, length); +#endif +#ifdef PNG_READ_hIST_SUPPORTED + else if (!png_memcmp(chunk_name, png_hIST, 4)) + png_handle_hIST(png_ptr, info_ptr, length); +#endif +#ifdef PNG_READ_oFFs_SUPPORTED + else if (!png_memcmp(chunk_name, png_oFFs, 4)) + png_handle_oFFs(png_ptr, info_ptr, length); +#endif +#ifdef PNG_READ_pCAL_SUPPORTED + else if (!png_memcmp(chunk_name, png_pCAL, 4)) + png_handle_pCAL(png_ptr, info_ptr, length); +#endif +#ifdef PNG_READ_sCAL_SUPPORTED + else if (!png_memcmp(chunk_name, png_sCAL, 4)) + png_handle_sCAL(png_ptr, info_ptr, length); +#endif +#ifdef PNG_READ_pHYs_SUPPORTED + else if (!png_memcmp(chunk_name, png_pHYs, 4)) + png_handle_pHYs(png_ptr, info_ptr, length); +#endif +#ifdef PNG_READ_sBIT_SUPPORTED + else if (!png_memcmp(chunk_name, png_sBIT, 4)) + png_handle_sBIT(png_ptr, info_ptr, length); +#endif +#ifdef PNG_READ_sRGB_SUPPORTED + else if (!png_memcmp(chunk_name, png_sRGB, 4)) + png_handle_sRGB(png_ptr, info_ptr, length); +#endif +#ifdef PNG_READ_iCCP_SUPPORTED + else if (!png_memcmp(chunk_name, png_iCCP, 4)) + png_handle_iCCP(png_ptr, info_ptr, length); +#endif +#ifdef PNG_READ_sPLT_SUPPORTED + else if (!png_memcmp(chunk_name, png_sPLT, 4)) + png_handle_sPLT(png_ptr, info_ptr, length); +#endif +#ifdef PNG_READ_tEXt_SUPPORTED + else if (!png_memcmp(chunk_name, png_tEXt, 4)) + png_handle_tEXt(png_ptr, info_ptr, length); +#endif +#ifdef PNG_READ_tIME_SUPPORTED + else if (!png_memcmp(chunk_name, png_tIME, 4)) + png_handle_tIME(png_ptr, info_ptr, length); +#endif +#ifdef PNG_READ_tRNS_SUPPORTED + else if (!png_memcmp(chunk_name, png_tRNS, 4)) + png_handle_tRNS(png_ptr, info_ptr, length); +#endif +#ifdef PNG_READ_zTXt_SUPPORTED + else if (!png_memcmp(chunk_name, png_zTXt, 4)) + png_handle_zTXt(png_ptr, info_ptr, length); +#endif +#ifdef PNG_READ_iTXt_SUPPORTED + else if (!png_memcmp(chunk_name, png_iTXt, 4)) + png_handle_iTXt(png_ptr, info_ptr, length); +#endif +#if defined(PNG_READ_APNG_SUPPORTED) + else if (!png_memcmp(png_ptr->chunk_name, png_acTL, 4)) + png_handle_acTL(png_ptr, info_ptr, length); + else if (!png_memcmp(png_ptr->chunk_name, png_fcTL, 4)) + png_handle_fcTL(png_ptr, info_ptr, length); + else if (!png_memcmp(png_ptr->chunk_name, png_fdAT, 4)) + png_handle_fdAT(png_ptr, info_ptr, length); +#endif + else + png_handle_unknown(png_ptr, info_ptr, length); + } while (!(png_ptr->mode & PNG_HAVE_IEND)); +} +#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ + +/* Free all memory used by the read */ +void PNGAPI +png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr, + png_infopp end_info_ptr_ptr) +{ + png_structp png_ptr = NULL; + png_infop info_ptr = NULL, end_info_ptr = NULL; +#ifdef PNG_USER_MEM_SUPPORTED + png_free_ptr free_fn = NULL; + png_voidp mem_ptr = NULL; +#endif + + png_debug(1, "in png_destroy_read_struct"); + + if (png_ptr_ptr != NULL) + png_ptr = *png_ptr_ptr; + if (png_ptr == NULL) + return; + +#ifdef PNG_USER_MEM_SUPPORTED + free_fn = png_ptr->free_fn; + mem_ptr = png_ptr->mem_ptr; +#endif + + if (info_ptr_ptr != NULL) + info_ptr = *info_ptr_ptr; + + if (end_info_ptr_ptr != NULL) + end_info_ptr = *end_info_ptr_ptr; + + png_read_destroy(png_ptr, info_ptr, end_info_ptr); + + if (info_ptr != NULL) + { +#ifdef PNG_TEXT_SUPPORTED + png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, -1); +#endif + +#ifdef PNG_USER_MEM_SUPPORTED + png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn, + (png_voidp)mem_ptr); +#else + png_destroy_struct((png_voidp)info_ptr); +#endif + *info_ptr_ptr = NULL; + } + + if (end_info_ptr != NULL) + { +#ifdef PNG_READ_TEXT_SUPPORTED + png_free_data(png_ptr, end_info_ptr, PNG_FREE_TEXT, -1); +#endif +#ifdef PNG_USER_MEM_SUPPORTED + png_destroy_struct_2((png_voidp)end_info_ptr, (png_free_ptr)free_fn, + (png_voidp)mem_ptr); +#else + png_destroy_struct((png_voidp)end_info_ptr); +#endif + *end_info_ptr_ptr = NULL; + } + + if (png_ptr != NULL) + { +#ifdef PNG_USER_MEM_SUPPORTED + png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn, + (png_voidp)mem_ptr); +#else + png_destroy_struct((png_voidp)png_ptr); +#endif + *png_ptr_ptr = NULL; + } +} + +/* Free all memory used by the read (old method) */ +void /* PRIVATE */ +png_read_destroy(png_structp png_ptr, png_infop info_ptr, + png_infop end_info_ptr) +{ +#ifdef PNG_SETJMP_SUPPORTED + jmp_buf tmp_jmp; +#endif + png_error_ptr error_fn; + png_error_ptr warning_fn; + png_voidp error_ptr; +#ifdef PNG_USER_MEM_SUPPORTED + png_free_ptr free_fn; +#endif + + png_debug(1, "in png_read_destroy"); + + if (info_ptr != NULL) + png_info_destroy(png_ptr, info_ptr); + + if (end_info_ptr != NULL) + png_info_destroy(png_ptr, end_info_ptr); + + png_free(png_ptr, png_ptr->zbuf); + png_free(png_ptr, png_ptr->big_row_buf); + png_free(png_ptr, png_ptr->prev_row); + png_free(png_ptr, png_ptr->chunkdata); +#ifdef PNG_READ_DITHER_SUPPORTED + png_free(png_ptr, png_ptr->palette_lookup); + png_free(png_ptr, png_ptr->dither_index); +#endif +#ifdef PNG_READ_GAMMA_SUPPORTED + png_free(png_ptr, png_ptr->gamma_table); +#endif +#ifdef PNG_READ_BACKGROUND_SUPPORTED + png_free(png_ptr, png_ptr->gamma_from_1); + png_free(png_ptr, png_ptr->gamma_to_1); +#endif +#ifdef PNG_FREE_ME_SUPPORTED + if (png_ptr->free_me & PNG_FREE_PLTE) + png_zfree(png_ptr, png_ptr->palette); + png_ptr->free_me &= ~PNG_FREE_PLTE; +#else + if (png_ptr->flags & PNG_FLAG_FREE_PLTE) + png_zfree(png_ptr, png_ptr->palette); + png_ptr->flags &= ~PNG_FLAG_FREE_PLTE; +#endif +#if defined(PNG_tRNS_SUPPORTED) || \ + defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) +#ifdef PNG_FREE_ME_SUPPORTED + if (png_ptr->free_me & PNG_FREE_TRNS) + png_free(png_ptr, png_ptr->trans); + png_ptr->free_me &= ~PNG_FREE_TRNS; +#else + if (png_ptr->flags & PNG_FLAG_FREE_TRNS) + png_free(png_ptr, png_ptr->trans); + png_ptr->flags &= ~PNG_FLAG_FREE_TRNS; +#endif +#endif +#ifdef PNG_READ_hIST_SUPPORTED +#ifdef PNG_FREE_ME_SUPPORTED + if (png_ptr->free_me & PNG_FREE_HIST) + png_free(png_ptr, png_ptr->hist); + png_ptr->free_me &= ~PNG_FREE_HIST; +#else + if (png_ptr->flags & PNG_FLAG_FREE_HIST) + png_free(png_ptr, png_ptr->hist); + png_ptr->flags &= ~PNG_FLAG_FREE_HIST; +#endif +#endif +#ifdef PNG_READ_GAMMA_SUPPORTED + if (png_ptr->gamma_16_table != NULL) + { + int i; + int istop = (1 << (8 - png_ptr->gamma_shift)); + for (i = 0; i < istop; i++) + { + png_free(png_ptr, png_ptr->gamma_16_table[i]); + } + png_free(png_ptr, png_ptr->gamma_16_table); + } +#ifdef PNG_READ_BACKGROUND_SUPPORTED + if (png_ptr->gamma_16_from_1 != NULL) + { + int i; + int istop = (1 << (8 - png_ptr->gamma_shift)); + for (i = 0; i < istop; i++) + { + png_free(png_ptr, png_ptr->gamma_16_from_1[i]); + } + png_free(png_ptr, png_ptr->gamma_16_from_1); + } + if (png_ptr->gamma_16_to_1 != NULL) + { + int i; + int istop = (1 << (8 - png_ptr->gamma_shift)); + for (i = 0; i < istop; i++) + { + png_free(png_ptr, png_ptr->gamma_16_to_1[i]); + } + png_free(png_ptr, png_ptr->gamma_16_to_1); + } +#endif +#endif +#ifdef PNG_TIME_RFC1123_SUPPORTED + png_free(png_ptr, png_ptr->time_buffer); +#endif + + inflateEnd(&png_ptr->zstream); +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED + png_free(png_ptr, png_ptr->save_buffer); +#endif + +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED +#ifdef PNG_TEXT_SUPPORTED + png_free(png_ptr, png_ptr->current_text); +#endif /* PNG_TEXT_SUPPORTED */ +#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ + + /* Save the important info out of the png_struct, in case it is + * being used again. + */ +#ifdef PNG_SETJMP_SUPPORTED + png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof(jmp_buf)); +#endif + + error_fn = png_ptr->error_fn; + warning_fn = png_ptr->warning_fn; + error_ptr = png_ptr->error_ptr; +#ifdef PNG_USER_MEM_SUPPORTED + free_fn = png_ptr->free_fn; +#endif + + png_memset(png_ptr, 0, png_sizeof(png_struct)); + + png_ptr->error_fn = error_fn; + png_ptr->warning_fn = warning_fn; + png_ptr->error_ptr = error_ptr; +#ifdef PNG_USER_MEM_SUPPORTED + png_ptr->free_fn = free_fn; +#endif + +#ifdef PNG_SETJMP_SUPPORTED + png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof(jmp_buf)); +#endif + +} + +void PNGAPI +png_set_read_status_fn(png_structp png_ptr, png_read_status_ptr read_row_fn) +{ + if (png_ptr == NULL) + return; + png_ptr->read_row_fn = read_row_fn; +} + + +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED +#ifdef PNG_INFO_IMAGE_SUPPORTED +void PNGAPI +png_read_png(png_structp png_ptr, png_infop info_ptr, + int transforms, + voidp params) +{ + int row; + + if (png_ptr == NULL) + return; +#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED + /* Invert the alpha channel from opacity to transparency + */ + if (transforms & PNG_TRANSFORM_INVERT_ALPHA) + png_set_invert_alpha(png_ptr); +#endif + + /* png_read_info() gives us all of the information from the + * PNG file before the first IDAT (image data chunk). + */ + png_read_info(png_ptr, info_ptr); + if (info_ptr->height > PNG_UINT_32_MAX/png_sizeof(png_bytep)) + png_error(png_ptr, "Image is too high to process with png_read_png()"); + + /* -------------- image transformations start here ------------------- */ + +#ifdef PNG_READ_16_TO_8_SUPPORTED + /* Tell libpng to strip 16 bit/color files down to 8 bits per color. + */ + if (transforms & PNG_TRANSFORM_STRIP_16) + png_set_strip_16(png_ptr); +#endif + +#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED + /* Strip alpha bytes from the input data without combining with + * the background (not recommended). + */ + if (transforms & PNG_TRANSFORM_STRIP_ALPHA) + png_set_strip_alpha(png_ptr); +#endif + +#if defined(PNG_READ_PACK_SUPPORTED) && !defined(PNG_READ_EXPAND_SUPPORTED) + /* Extract multiple pixels with bit depths of 1, 2, or 4 from a single + * byte into separate bytes (useful for paletted and grayscale images). + */ + if (transforms & PNG_TRANSFORM_PACKING) + png_set_packing(png_ptr); +#endif + +#ifdef PNG_READ_PACKSWAP_SUPPORTED + /* Change the order of packed pixels to least significant bit first + * (not useful if you are using png_set_packing). + */ + if (transforms & PNG_TRANSFORM_PACKSWAP) + png_set_packswap(png_ptr); +#endif + +#ifdef PNG_READ_EXPAND_SUPPORTED + /* Expand paletted colors into true RGB triplets + * Expand grayscale images to full 8 bits from 1, 2, or 4 bits/pixel + * Expand paletted or RGB images with transparency to full alpha + * channels so the data will be available as RGBA quartets. + */ + if (transforms & PNG_TRANSFORM_EXPAND) + if ((png_ptr->bit_depth < 8) || + (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) || + (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))) + png_set_expand(png_ptr); +#endif + + /* We don't handle background color or gamma transformation or dithering. + */ + +#ifdef PNG_READ_INVERT_SUPPORTED + /* Invert monochrome files to have 0 as white and 1 as black + */ + if (transforms & PNG_TRANSFORM_INVERT_MONO) + png_set_invert_mono(png_ptr); +#endif + +#ifdef PNG_READ_SHIFT_SUPPORTED + /* If you want to shift the pixel values from the range [0,255] or + * [0,65535] to the original [0,7] or [0,31], or whatever range the + * colors were originally in: + */ + if ((transforms & PNG_TRANSFORM_SHIFT) + && png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT)) + { + png_color_8p sig_bit; + + png_get_sBIT(png_ptr, info_ptr, &sig_bit); + png_set_shift(png_ptr, sig_bit); + } +#endif + +#ifdef PNG_READ_BGR_SUPPORTED + /* Flip the RGB pixels to BGR (or RGBA to BGRA) + */ + if (transforms & PNG_TRANSFORM_BGR) + png_set_bgr(png_ptr); +#endif + +#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED + /* Swap the RGBA or GA data to ARGB or AG (or BGRA to ABGR) + */ + if (transforms & PNG_TRANSFORM_SWAP_ALPHA) + png_set_swap_alpha(png_ptr); +#endif + +#ifdef PNG_READ_SWAP_SUPPORTED + /* Swap bytes of 16 bit files to least significant byte first + */ + if (transforms & PNG_TRANSFORM_SWAP_ENDIAN) + png_set_swap(png_ptr); +#endif + +/* Added at libpng-1.2.41 */ +#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED + /* Invert the alpha channel from opacity to transparency + */ + if (transforms & PNG_TRANSFORM_INVERT_ALPHA) + png_set_invert_alpha(png_ptr); +#endif + +/* Added at libpng-1.2.41 */ +#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED + /* Expand grayscale image to RGB + */ + if (transforms & PNG_TRANSFORM_GRAY_TO_RGB) + png_set_gray_to_rgb(png_ptr); +#endif + + /* We don't handle adding filler bytes */ + + /* Optional call to gamma correct and add the background to the palette + * and update info structure. REQUIRED if you are expecting libpng to + * update the palette for you (i.e., you selected such a transform above). + */ + png_read_update_info(png_ptr, info_ptr); + + /* -------------- image transformations end here ------------------- */ + +#ifdef PNG_FREE_ME_SUPPORTED + png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0); +#endif + if (info_ptr->row_pointers == NULL) + { + info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr, + info_ptr->height * png_sizeof(png_bytep)); + png_memset(info_ptr->row_pointers, 0, info_ptr->height + * png_sizeof(png_bytep)); + +#ifdef PNG_FREE_ME_SUPPORTED + info_ptr->free_me |= PNG_FREE_ROWS; +#endif + + for (row = 0; row < (int)info_ptr->height; row++) + info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr, + png_get_rowbytes(png_ptr, info_ptr)); + } + + png_read_image(png_ptr, info_ptr->row_pointers); + info_ptr->valid |= PNG_INFO_IDAT; + + /* Read rest of file, and get additional chunks in info_ptr - REQUIRED */ + png_read_end(png_ptr, info_ptr); + + transforms = transforms; /* Quiet compiler warnings */ + params = params; + +} +#endif /* PNG_INFO_IMAGE_SUPPORTED */ +#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ +#endif /* PNG_READ_SUPPORTED */ diff --git a/libs/libpng-src/pngrio.c b/libs/libpng-src/pngrio.c new file mode 100644 index 000000000..6978682c7 --- /dev/null +++ b/libs/libpng-src/pngrio.c @@ -0,0 +1,180 @@ + +/* pngrio.c - functions for data input + * + * Last changed in libpng 1.2.43 [February 25, 2010] + * Copyright (c) 1998-2010 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + * + * This file provides a location for all input. Users who need + * special handling are expected to write a function that has the same + * arguments as this and performs a similar function, but that possibly + * has a different input method. Note that you shouldn't change this + * function, but rather write a replacement function and then make + * libpng use it at run time with png_set_read_fn(...). + */ + +#define PNG_INTERNAL +#define PNG_NO_PEDANTIC_WARNINGS +#include "png.h" +#ifdef PNG_READ_SUPPORTED + +/* Read the data from whatever input you are using. The default routine + * reads from a file pointer. Note that this routine sometimes gets called + * with very small lengths, so you should implement some kind of simple + * buffering if you are using unbuffered reads. This should never be asked + * to read more then 64K on a 16 bit machine. + */ +void /* PRIVATE */ +png_read_data(png_structp png_ptr, png_bytep data, png_size_t length) +{ + png_debug1(4, "reading %d bytes", (int)length); + + if (png_ptr->read_data_fn != NULL) + (*(png_ptr->read_data_fn))(png_ptr, data, length); + else + png_error(png_ptr, "Call to NULL read function"); +} + +#ifdef PNG_STDIO_SUPPORTED +/* This is the function that does the actual reading of data. If you are + * not reading from a standard C stream, you should create a replacement + * read_data function and use it at run time with png_set_read_fn(), rather + * than changing the library. + */ +#ifndef USE_FAR_KEYWORD +void PNGAPI +png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length) +{ + png_size_t check; + + if (png_ptr == NULL) + return; + /* fread() returns 0 on error, so it is OK to store this in a png_size_t + * instead of an int, which is what fread() actually returns. + */ +#ifdef _WIN32_WCE + if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) ) + check = 0; +#else + check = (png_size_t)fread(data, (png_size_t)1, length, + (png_FILE_p)png_ptr->io_ptr); +#endif + + if (check != length) + png_error(png_ptr, "Read Error"); +} +#else +/* This is the model-independent version. Since the standard I/O library + can't handle far buffers in the medium and small models, we have to copy + the data. +*/ + +#define NEAR_BUF_SIZE 1024 +#define MIN(a,b) (a <= b ? a : b) + +static void PNGAPI +png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length) +{ + int check; + png_byte *n_data; + png_FILE_p io_ptr; + + if (png_ptr == NULL) + return; + /* Check if data really is near. If so, use usual code. */ + n_data = (png_byte *)CVT_PTR_NOCHECK(data); + io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr); + if ((png_bytep)n_data == data) + { +#ifdef _WIN32_WCE + if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, + NULL) ) + check = 0; +#else + check = fread(n_data, 1, length, io_ptr); +#endif + } + else + { + png_byte buf[NEAR_BUF_SIZE]; + png_size_t read, remaining, err; + check = 0; + remaining = length; + do + { + read = MIN(NEAR_BUF_SIZE, remaining); +#ifdef _WIN32_WCE + if ( !ReadFile((HANDLE)(io_ptr), buf, read, &err, NULL) ) + err = 0; +#else + err = fread(buf, (png_size_t)1, read, io_ptr); +#endif + png_memcpy(data, buf, read); /* copy far buffer to near buffer */ + if (err != read) + break; + else + check += err; + data += read; + remaining -= read; + } + while (remaining != 0); + } + if ((png_uint_32)check != (png_uint_32)length) + png_error(png_ptr, "read Error"); +} +#endif +#endif + +/* This function allows the application to supply a new input function + * for libpng if standard C streams aren't being used. + * + * This function takes as its arguments: + * png_ptr - pointer to a png input data structure + * io_ptr - pointer to user supplied structure containing info about + * the input functions. May be NULL. + * read_data_fn - pointer to a new input function that takes as its + * arguments a pointer to a png_struct, a pointer to + * a location where input data can be stored, and a 32-bit + * unsigned int that is the number of bytes to be read. + * To exit and output any fatal error messages the new write + * function should call png_error(png_ptr, "Error msg"). + * May be NULL, in which case libpng's default function will + * be used. + */ +void PNGAPI +png_set_read_fn(png_structp png_ptr, png_voidp io_ptr, + png_rw_ptr read_data_fn) +{ + if (png_ptr == NULL) + return; + png_ptr->io_ptr = io_ptr; + +#ifdef PNG_STDIO_SUPPORTED + if (read_data_fn != NULL) + png_ptr->read_data_fn = read_data_fn; + else + png_ptr->read_data_fn = png_default_read_data; +#else + png_ptr->read_data_fn = read_data_fn; +#endif + + /* It is an error to write to a read device */ + if (png_ptr->write_data_fn != NULL) + { + png_ptr->write_data_fn = NULL; + png_warning(png_ptr, + "It's an error to set both read_data_fn and write_data_fn in the "); + png_warning(png_ptr, + "same structure. Resetting write_data_fn to NULL."); + } + +#ifdef PNG_WRITE_FLUSH_SUPPORTED + png_ptr->output_flush_fn = NULL; +#endif +} +#endif /* PNG_READ_SUPPORTED */ diff --git a/libs/libpng-src/pngrtran.c b/libs/libpng-src/pngrtran.c new file mode 100644 index 000000000..33703d46e --- /dev/null +++ b/libs/libpng-src/pngrtran.c @@ -0,0 +1,4467 @@ + +/* pngrtran.c - transforms the data in a row for PNG readers + * + * Last changed in libpng 1.2.45 [July 7, 2011] + * Copyright (c) 1998-2011 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + * + * This file contains functions optionally called by an application + * in order to tell libpng how to handle data when reading a PNG. + * Transformations that are used in both reading and writing are + * in pngtrans.c. + */ + +#define PNG_INTERNAL +#define PNG_NO_PEDANTIC_WARNINGS +#include "png.h" +#ifdef PNG_READ_SUPPORTED + +/* Set the action on getting a CRC error for an ancillary or critical chunk. */ +void PNGAPI +png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action) +{ + png_debug(1, "in png_set_crc_action"); + + if (png_ptr == NULL) + return; + + /* Tell libpng how we react to CRC errors in critical chunks */ + switch (crit_action) + { + case PNG_CRC_NO_CHANGE: /* Leave setting as is */ + break; + + case PNG_CRC_WARN_USE: /* Warn/use data */ + png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK; + png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE; + break; + + case PNG_CRC_QUIET_USE: /* Quiet/use data */ + png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK; + png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE | + PNG_FLAG_CRC_CRITICAL_IGNORE; + break; + + case PNG_CRC_WARN_DISCARD: /* Not a valid action for critical data */ + png_warning(png_ptr, + "Can't discard critical data on CRC error."); + case PNG_CRC_ERROR_QUIT: /* Error/quit */ + + case PNG_CRC_DEFAULT: + default: + png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK; + break; + } + + /* Tell libpng how we react to CRC errors in ancillary chunks */ + switch (ancil_action) + { + case PNG_CRC_NO_CHANGE: /* Leave setting as is */ + break; + + case PNG_CRC_WARN_USE: /* Warn/use data */ + png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK; + png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE; + break; + + case PNG_CRC_QUIET_USE: /* Quiet/use data */ + png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK; + png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE | + PNG_FLAG_CRC_ANCILLARY_NOWARN; + break; + + case PNG_CRC_ERROR_QUIT: /* Error/quit */ + png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK; + png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_NOWARN; + break; + + case PNG_CRC_WARN_DISCARD: /* Warn/discard data */ + + case PNG_CRC_DEFAULT: + default: + png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK; + break; + } +} + +#if defined(PNG_READ_BACKGROUND_SUPPORTED) && \ + defined(PNG_FLOATING_POINT_SUPPORTED) +/* Handle alpha and tRNS via a background color */ +void PNGAPI +png_set_background(png_structp png_ptr, + png_color_16p background_color, int background_gamma_code, + int need_expand, double background_gamma) +{ + png_debug(1, "in png_set_background"); + + if (png_ptr == NULL) + return; + if (background_gamma_code == PNG_BACKGROUND_GAMMA_UNKNOWN) + { + png_warning(png_ptr, "Application must supply a known background gamma"); + return; + } + + png_ptr->transformations |= PNG_BACKGROUND; + png_memcpy(&(png_ptr->background), background_color, + png_sizeof(png_color_16)); + png_ptr->background_gamma = (float)background_gamma; + png_ptr->background_gamma_type = (png_byte)(background_gamma_code); + png_ptr->transformations |= (need_expand ? PNG_BACKGROUND_EXPAND : 0); +} +#endif + +#ifdef PNG_READ_16_TO_8_SUPPORTED +/* Strip 16 bit depth files to 8 bit depth */ +void PNGAPI +png_set_strip_16(png_structp png_ptr) +{ + png_debug(1, "in png_set_strip_16"); + + if (png_ptr == NULL) + return; + png_ptr->transformations |= PNG_16_TO_8; +} +#endif + +#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED +void PNGAPI +png_set_strip_alpha(png_structp png_ptr) +{ + png_debug(1, "in png_set_strip_alpha"); + + if (png_ptr == NULL) + return; + png_ptr->flags |= PNG_FLAG_STRIP_ALPHA; +} +#endif + +#ifdef PNG_READ_DITHER_SUPPORTED +/* Dither file to 8 bit. Supply a palette, the current number + * of elements in the palette, the maximum number of elements + * allowed, and a histogram if possible. If the current number + * of colors is greater then the maximum number, the palette will be + * modified to fit in the maximum number. "full_dither" indicates + * whether we need a dithering cube set up for RGB images, or if we + * simply are reducing the number of colors in a paletted image. + */ + +typedef struct png_dsort_struct +{ + struct png_dsort_struct FAR * next; + png_byte left; + png_byte right; +} png_dsort; +typedef png_dsort FAR * png_dsortp; +typedef png_dsort FAR * FAR * png_dsortpp; + +void PNGAPI +png_set_dither(png_structp png_ptr, png_colorp palette, + int num_palette, int maximum_colors, png_uint_16p histogram, + int full_dither) +{ + png_debug(1, "in png_set_dither"); + + if (png_ptr == NULL) + return; + png_ptr->transformations |= PNG_DITHER; + + if (!full_dither) + { + int i; + + png_ptr->dither_index = (png_bytep)png_malloc(png_ptr, + (png_uint_32)(num_palette * png_sizeof(png_byte))); + for (i = 0; i < num_palette; i++) + png_ptr->dither_index[i] = (png_byte)i; + } + + if (num_palette > maximum_colors) + { + if (histogram != NULL) + { + /* This is easy enough, just throw out the least used colors. + * Perhaps not the best solution, but good enough. + */ + + int i; + + /* Initialize an array to sort colors */ + png_ptr->dither_sort = (png_bytep)png_malloc(png_ptr, + (png_uint_32)(num_palette * png_sizeof(png_byte))); + + /* Initialize the dither_sort array */ + for (i = 0; i < num_palette; i++) + png_ptr->dither_sort[i] = (png_byte)i; + + /* Find the least used palette entries by starting a + * bubble sort, and running it until we have sorted + * out enough colors. Note that we don't care about + * sorting all the colors, just finding which are + * least used. + */ + + for (i = num_palette - 1; i >= maximum_colors; i--) + { + int done; /* To stop early if the list is pre-sorted */ + int j; + + done = 1; + for (j = 0; j < i; j++) + { + if (histogram[png_ptr->dither_sort[j]] + < histogram[png_ptr->dither_sort[j + 1]]) + { + png_byte t; + + t = png_ptr->dither_sort[j]; + png_ptr->dither_sort[j] = png_ptr->dither_sort[j + 1]; + png_ptr->dither_sort[j + 1] = t; + done = 0; + } + } + if (done) + break; + } + + /* Swap the palette around, and set up a table, if necessary */ + if (full_dither) + { + int j = num_palette; + + /* Put all the useful colors within the max, but don't + * move the others. + */ + for (i = 0; i < maximum_colors; i++) + { + if ((int)png_ptr->dither_sort[i] >= maximum_colors) + { + do + j--; + while ((int)png_ptr->dither_sort[j] >= maximum_colors); + palette[i] = palette[j]; + } + } + } + else + { + int j = num_palette; + + /* Move all the used colors inside the max limit, and + * develop a translation table. + */ + for (i = 0; i < maximum_colors; i++) + { + /* Only move the colors we need to */ + if ((int)png_ptr->dither_sort[i] >= maximum_colors) + { + png_color tmp_color; + + do + j--; + while ((int)png_ptr->dither_sort[j] >= maximum_colors); + + tmp_color = palette[j]; + palette[j] = palette[i]; + palette[i] = tmp_color; + /* Indicate where the color went */ + png_ptr->dither_index[j] = (png_byte)i; + png_ptr->dither_index[i] = (png_byte)j; + } + } + + /* Find closest color for those colors we are not using */ + for (i = 0; i < num_palette; i++) + { + if ((int)png_ptr->dither_index[i] >= maximum_colors) + { + int min_d, k, min_k, d_index; + + /* Find the closest color to one we threw out */ + d_index = png_ptr->dither_index[i]; + min_d = PNG_COLOR_DIST(palette[d_index], palette[0]); + for (k = 1, min_k = 0; k < maximum_colors; k++) + { + int d; + + d = PNG_COLOR_DIST(palette[d_index], palette[k]); + + if (d < min_d) + { + min_d = d; + min_k = k; + } + } + /* Point to closest color */ + png_ptr->dither_index[i] = (png_byte)min_k; + } + } + } + png_free(png_ptr, png_ptr->dither_sort); + png_ptr->dither_sort = NULL; + } + else + { + /* This is much harder to do simply (and quickly). Perhaps + * we need to go through a median cut routine, but those + * don't always behave themselves with only a few colors + * as input. So we will just find the closest two colors, + * and throw out one of them (chosen somewhat randomly). + * [We don't understand this at all, so if someone wants to + * work on improving it, be our guest - AED, GRP] + */ + int i; + int max_d; + int num_new_palette; + png_dsortp t; + png_dsortpp hash; + + t = NULL; + + /* Initialize palette index arrays */ + png_ptr->index_to_palette = (png_bytep)png_malloc(png_ptr, + (png_uint_32)(num_palette * png_sizeof(png_byte))); + png_ptr->palette_to_index = (png_bytep)png_malloc(png_ptr, + (png_uint_32)(num_palette * png_sizeof(png_byte))); + + /* Initialize the sort array */ + for (i = 0; i < num_palette; i++) + { + png_ptr->index_to_palette[i] = (png_byte)i; + png_ptr->palette_to_index[i] = (png_byte)i; + } + + hash = (png_dsortpp)png_calloc(png_ptr, (png_uint_32)(769 * + png_sizeof(png_dsortp))); + + num_new_palette = num_palette; + + /* Initial wild guess at how far apart the farthest pixel + * pair we will be eliminating will be. Larger + * numbers mean more areas will be allocated, Smaller + * numbers run the risk of not saving enough data, and + * having to do this all over again. + * + * I have not done extensive checking on this number. + */ + max_d = 96; + + while (num_new_palette > maximum_colors) + { + for (i = 0; i < num_new_palette - 1; i++) + { + int j; + + for (j = i + 1; j < num_new_palette; j++) + { + int d; + + d = PNG_COLOR_DIST(palette[i], palette[j]); + + if (d <= max_d) + { + + t = (png_dsortp)png_malloc_warn(png_ptr, + (png_uint_32)(png_sizeof(png_dsort))); + if (t == NULL) + break; + t->next = hash[d]; + t->left = (png_byte)i; + t->right = (png_byte)j; + hash[d] = t; + } + } + if (t == NULL) + break; + } + + if (t != NULL) + for (i = 0; i <= max_d; i++) + { + if (hash[i] != NULL) + { + png_dsortp p; + + for (p = hash[i]; p; p = p->next) + { + if ((int)png_ptr->index_to_palette[p->left] + < num_new_palette && + (int)png_ptr->index_to_palette[p->right] + < num_new_palette) + { + int j, next_j; + + if (num_new_palette & 0x01) + { + j = p->left; + next_j = p->right; + } + else + { + j = p->right; + next_j = p->left; + } + + num_new_palette--; + palette[png_ptr->index_to_palette[j]] + = palette[num_new_palette]; + if (!full_dither) + { + int k; + + for (k = 0; k < num_palette; k++) + { + if (png_ptr->dither_index[k] == + png_ptr->index_to_palette[j]) + png_ptr->dither_index[k] = + png_ptr->index_to_palette[next_j]; + if ((int)png_ptr->dither_index[k] == + num_new_palette) + png_ptr->dither_index[k] = + png_ptr->index_to_palette[j]; + } + } + + png_ptr->index_to_palette[png_ptr->palette_to_index + [num_new_palette]] = png_ptr->index_to_palette[j]; + png_ptr->palette_to_index[png_ptr->index_to_palette[j]] + = png_ptr->palette_to_index[num_new_palette]; + + png_ptr->index_to_palette[j] = + (png_byte)num_new_palette; + png_ptr->palette_to_index[num_new_palette] = + (png_byte)j; + } + if (num_new_palette <= maximum_colors) + break; + } + if (num_new_palette <= maximum_colors) + break; + } + } + + for (i = 0; i < 769; i++) + { + if (hash[i] != NULL) + { + png_dsortp p = hash[i]; + while (p) + { + t = p->next; + png_free(png_ptr, p); + p = t; + } + } + hash[i] = 0; + } + max_d += 96; + } + png_free(png_ptr, hash); + png_free(png_ptr, png_ptr->palette_to_index); + png_free(png_ptr, png_ptr->index_to_palette); + png_ptr->palette_to_index = NULL; + png_ptr->index_to_palette = NULL; + } + num_palette = maximum_colors; + } + if (png_ptr->palette == NULL) + { + png_ptr->palette = palette; + } + png_ptr->num_palette = (png_uint_16)num_palette; + + if (full_dither) + { + int i; + png_bytep distance; + int total_bits = PNG_DITHER_RED_BITS + PNG_DITHER_GREEN_BITS + + PNG_DITHER_BLUE_BITS; + int num_red = (1 << PNG_DITHER_RED_BITS); + int num_green = (1 << PNG_DITHER_GREEN_BITS); + int num_blue = (1 << PNG_DITHER_BLUE_BITS); + png_size_t num_entries = ((png_size_t)1 << total_bits); + + png_ptr->palette_lookup = (png_bytep )png_calloc(png_ptr, + (png_uint_32)(num_entries * png_sizeof(png_byte))); + + distance = (png_bytep)png_malloc(png_ptr, (png_uint_32)(num_entries * + png_sizeof(png_byte))); + png_memset(distance, 0xff, num_entries * png_sizeof(png_byte)); + + for (i = 0; i < num_palette; i++) + { + int ir, ig, ib; + int r = (palette[i].red >> (8 - PNG_DITHER_RED_BITS)); + int g = (palette[i].green >> (8 - PNG_DITHER_GREEN_BITS)); + int b = (palette[i].blue >> (8 - PNG_DITHER_BLUE_BITS)); + + for (ir = 0; ir < num_red; ir++) + { + /* int dr = abs(ir - r); */ + int dr = ((ir > r) ? ir - r : r - ir); + int index_r = (ir << (PNG_DITHER_BLUE_BITS + + PNG_DITHER_GREEN_BITS)); + + for (ig = 0; ig < num_green; ig++) + { + /* int dg = abs(ig - g); */ + int dg = ((ig > g) ? ig - g : g - ig); + int dt = dr + dg; + int dm = ((dr > dg) ? dr : dg); + int index_g = index_r | (ig << PNG_DITHER_BLUE_BITS); + + for (ib = 0; ib < num_blue; ib++) + { + int d_index = index_g | ib; + /* int db = abs(ib - b); */ + int db = ((ib > b) ? ib - b : b - ib); + int dmax = ((dm > db) ? dm : db); + int d = dmax + dt + db; + + if (d < (int)distance[d_index]) + { + distance[d_index] = (png_byte)d; + png_ptr->palette_lookup[d_index] = (png_byte)i; + } + } + } + } + } + + png_free(png_ptr, distance); + } +} +#endif + +#if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED) +/* Transform the image from the file_gamma to the screen_gamma. We + * only do transformations on images where the file_gamma and screen_gamma + * are not close reciprocals, otherwise it slows things down slightly, and + * also needlessly introduces small errors. + * + * We will turn off gamma transformation later if no semitransparent entries + * are present in the tRNS array for palette images. We can't do it here + * because we don't necessarily have the tRNS chunk yet. + */ +void PNGAPI +png_set_gamma(png_structp png_ptr, double scrn_gamma, double file_gamma) +{ + png_debug(1, "in png_set_gamma"); + + if (png_ptr == NULL) + return; + + if ((fabs(scrn_gamma * file_gamma - 1.0) > PNG_GAMMA_THRESHOLD) || + (png_ptr->color_type & PNG_COLOR_MASK_ALPHA) || + (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)) + png_ptr->transformations |= PNG_GAMMA; + png_ptr->gamma = (float)file_gamma; + png_ptr->screen_gamma = (float)scrn_gamma; +} +#endif + +#ifdef PNG_READ_EXPAND_SUPPORTED +/* Expand paletted images to RGB, expand grayscale images of + * less than 8-bit depth to 8-bit depth, and expand tRNS chunks + * to alpha channels. + */ +void PNGAPI +png_set_expand(png_structp png_ptr) +{ + png_debug(1, "in png_set_expand"); + + if (png_ptr == NULL) + return; + + png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS); + png_ptr->flags &= ~PNG_FLAG_ROW_INIT; +} + +/* GRR 19990627: the following three functions currently are identical + * to png_set_expand(). However, it is entirely reasonable that someone + * might wish to expand an indexed image to RGB but *not* expand a single, + * fully transparent palette entry to a full alpha channel--perhaps instead + * convert tRNS to the grayscale/RGB format (16-bit RGB value), or replace + * the transparent color with a particular RGB value, or drop tRNS entirely. + * IOW, a future version of the library may make the transformations flag + * a bit more fine-grained, with separate bits for each of these three + * functions. + * + * More to the point, these functions make it obvious what libpng will be + * doing, whereas "expand" can (and does) mean any number of things. + * + * GRP 20060307: In libpng-1.2.9, png_set_gray_1_2_4_to_8() was modified + * to expand only the sample depth but not to expand the tRNS to alpha + * and its name was changed to png_set_expand_gray_1_2_4_to_8(). + */ + +/* Expand paletted images to RGB. */ +void PNGAPI +png_set_palette_to_rgb(png_structp png_ptr) +{ + png_debug(1, "in png_set_palette_to_rgb"); + + if (png_ptr == NULL) + return; + + png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS); + png_ptr->flags &= ~PNG_FLAG_ROW_INIT; +} + +#ifndef PNG_1_0_X +/* Expand grayscale images of less than 8-bit depth to 8 bits. */ +void PNGAPI +png_set_expand_gray_1_2_4_to_8(png_structp png_ptr) +{ + png_debug(1, "in png_set_expand_gray_1_2_4_to_8"); + + if (png_ptr == NULL) + return; + + png_ptr->transformations |= PNG_EXPAND; + png_ptr->flags &= ~PNG_FLAG_ROW_INIT; +} +#endif + +#if defined(PNG_1_0_X) || defined(PNG_1_2_X) +/* Expand grayscale images of less than 8-bit depth to 8 bits. */ +/* Deprecated as of libpng-1.2.9 */ +void PNGAPI +png_set_gray_1_2_4_to_8(png_structp png_ptr) +{ + png_debug(1, "in png_set_gray_1_2_4_to_8"); + + if (png_ptr == NULL) + return; + + png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS); +} +#endif + + +/* Expand tRNS chunks to alpha channels. */ +void PNGAPI +png_set_tRNS_to_alpha(png_structp png_ptr) +{ + png_debug(1, "in png_set_tRNS_to_alpha"); + + png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS); + png_ptr->flags &= ~PNG_FLAG_ROW_INIT; +} +#endif /* defined(PNG_READ_EXPAND_SUPPORTED) */ + +#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED +void PNGAPI +png_set_gray_to_rgb(png_structp png_ptr) +{ + png_debug(1, "in png_set_gray_to_rgb"); + + png_ptr->transformations |= PNG_GRAY_TO_RGB; + png_ptr->flags &= ~PNG_FLAG_ROW_INIT; +} +#endif + +#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED +#ifdef PNG_FLOATING_POINT_SUPPORTED +/* Convert a RGB image to a grayscale of the same width. This allows us, + * for example, to convert a 24 bpp RGB image into an 8 bpp grayscale image. + */ + +void PNGAPI +png_set_rgb_to_gray(png_structp png_ptr, int error_action, double red, + double green) +{ + int red_fixed, green_fixed; + if (png_ptr == NULL) + return; + if (red > 21474.83647 || red < -21474.83648 || + green > 21474.83647 || green < -21474.83648) + { + png_warning(png_ptr, "ignoring out of range rgb_to_gray coefficients"); + red_fixed = -1; + green_fixed = -1; + } + else + { + red_fixed = (int)((float)red*100000.0 + 0.5); + green_fixed = (int)((float)green*100000.0 + 0.5); + } + png_set_rgb_to_gray_fixed(png_ptr, error_action, red_fixed, green_fixed); +} +#endif + +void PNGAPI +png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action, + png_fixed_point red, png_fixed_point green) +{ + png_debug(1, "in png_set_rgb_to_gray"); + + if (png_ptr == NULL) + return; + + switch(error_action) + { + case 1: png_ptr->transformations |= PNG_RGB_TO_GRAY; + break; + + case 2: png_ptr->transformations |= PNG_RGB_TO_GRAY_WARN; + break; + + case 3: png_ptr->transformations |= PNG_RGB_TO_GRAY_ERR; + } + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) +#ifdef PNG_READ_EXPAND_SUPPORTED + png_ptr->transformations |= PNG_EXPAND; +#else + { + png_warning(png_ptr, + "Cannot do RGB_TO_GRAY without EXPAND_SUPPORTED."); + png_ptr->transformations &= ~PNG_RGB_TO_GRAY; + } +#endif + { + png_uint_16 red_int, green_int; + if (red < 0 || green < 0) + { + red_int = 6968; /* .212671 * 32768 + .5 */ + green_int = 23434; /* .715160 * 32768 + .5 */ + } + else if (red + green < 100000L) + { + red_int = (png_uint_16)(((png_uint_32)red*32768L)/100000L); + green_int = (png_uint_16)(((png_uint_32)green*32768L)/100000L); + } + else + { + png_warning(png_ptr, "ignoring out of range rgb_to_gray coefficients"); + red_int = 6968; + green_int = 23434; + } + png_ptr->rgb_to_gray_red_coeff = red_int; + png_ptr->rgb_to_gray_green_coeff = green_int; + png_ptr->rgb_to_gray_blue_coeff = + (png_uint_16)(32768 - red_int - green_int); + } +} +#endif + +#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ + defined(PNG_LEGACY_SUPPORTED) || \ + defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) +void PNGAPI +png_set_read_user_transform_fn(png_structp png_ptr, png_user_transform_ptr + read_user_transform_fn) +{ + png_debug(1, "in png_set_read_user_transform_fn"); + + if (png_ptr == NULL) + return; + +#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED + png_ptr->transformations |= PNG_USER_TRANSFORM; + png_ptr->read_user_transform_fn = read_user_transform_fn; +#endif +#ifdef PNG_LEGACY_SUPPORTED + if (read_user_transform_fn) + png_warning(png_ptr, + "This version of libpng does not support user transforms"); +#endif +} +#endif + +/* Initialize everything needed for the read. This includes modifying + * the palette. + */ +void /* PRIVATE */ +png_init_read_transformations(png_structp png_ptr) +{ + png_debug(1, "in png_init_read_transformations"); + +#ifdef PNG_USELESS_TESTS_SUPPORTED + if (png_ptr != NULL) +#endif + { +#if defined(PNG_READ_BACKGROUND_SUPPORTED) || \ + defined(PNG_READ_SHIFT_SUPPORTED) || \ + defined(PNG_READ_GAMMA_SUPPORTED) + int color_type = png_ptr->color_type; +#endif + +#if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED) + +#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED + /* Detect gray background and attempt to enable optimization + * for gray --> RGB case + * + * Note: if PNG_BACKGROUND_EXPAND is set and color_type is either RGB or + * RGB_ALPHA (in which case need_expand is superfluous anyway), the + * background color might actually be gray yet not be flagged as such. + * This is not a problem for the current code, which uses + * PNG_BACKGROUND_IS_GRAY only to decide when to do the + * png_do_gray_to_rgb() transformation. + */ + if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) && + !(color_type & PNG_COLOR_MASK_COLOR)) + { + png_ptr->mode |= PNG_BACKGROUND_IS_GRAY; + } else if ((png_ptr->transformations & PNG_BACKGROUND) && + !(png_ptr->transformations & PNG_BACKGROUND_EXPAND) && + (png_ptr->transformations & PNG_GRAY_TO_RGB) && + png_ptr->background.red == png_ptr->background.green && + png_ptr->background.red == png_ptr->background.blue) + { + png_ptr->mode |= PNG_BACKGROUND_IS_GRAY; + png_ptr->background.gray = png_ptr->background.red; + } +#endif + + if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) && + (png_ptr->transformations & PNG_EXPAND)) + { + if (!(color_type & PNG_COLOR_MASK_COLOR)) /* i.e., GRAY or GRAY_ALPHA */ + { + /* Expand background and tRNS chunks */ + switch (png_ptr->bit_depth) + { + case 1: + png_ptr->background.gray *= (png_uint_16)0xff; + png_ptr->background.red = png_ptr->background.green + = png_ptr->background.blue = png_ptr->background.gray; + if (!(png_ptr->transformations & PNG_EXPAND_tRNS)) + { + png_ptr->trans_values.gray *= (png_uint_16)0xff; + png_ptr->trans_values.red = png_ptr->trans_values.green + = png_ptr->trans_values.blue = png_ptr->trans_values.gray; + } + break; + + case 2: + png_ptr->background.gray *= (png_uint_16)0x55; + png_ptr->background.red = png_ptr->background.green + = png_ptr->background.blue = png_ptr->background.gray; + if (!(png_ptr->transformations & PNG_EXPAND_tRNS)) + { + png_ptr->trans_values.gray *= (png_uint_16)0x55; + png_ptr->trans_values.red = png_ptr->trans_values.green + = png_ptr->trans_values.blue = png_ptr->trans_values.gray; + } + break; + + case 4: + png_ptr->background.gray *= (png_uint_16)0x11; + png_ptr->background.red = png_ptr->background.green + = png_ptr->background.blue = png_ptr->background.gray; + if (!(png_ptr->transformations & PNG_EXPAND_tRNS)) + { + png_ptr->trans_values.gray *= (png_uint_16)0x11; + png_ptr->trans_values.red = png_ptr->trans_values.green + = png_ptr->trans_values.blue = png_ptr->trans_values.gray; + } + break; + + case 8: + + case 16: + png_ptr->background.red = png_ptr->background.green + = png_ptr->background.blue = png_ptr->background.gray; + break; + } + } + else if (color_type == PNG_COLOR_TYPE_PALETTE) + { + png_ptr->background.red = + png_ptr->palette[png_ptr->background.index].red; + png_ptr->background.green = + png_ptr->palette[png_ptr->background.index].green; + png_ptr->background.blue = + png_ptr->palette[png_ptr->background.index].blue; + +#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED + if (png_ptr->transformations & PNG_INVERT_ALPHA) + { +#ifdef PNG_READ_EXPAND_SUPPORTED + if (!(png_ptr->transformations & PNG_EXPAND_tRNS)) +#endif + { + /* Invert the alpha channel (in tRNS) unless the pixels are + * going to be expanded, in which case leave it for later + */ + int i, istop; + istop=(int)png_ptr->num_trans; + for (i=0; itrans[i] = (png_byte)(255 - png_ptr->trans[i]); + } + } +#endif + + } + } +#endif + +#if defined(PNG_READ_BACKGROUND_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED) + png_ptr->background_1 = png_ptr->background; +#endif +#if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED) + + if ((color_type == PNG_COLOR_TYPE_PALETTE && png_ptr->num_trans != 0) + && (fabs(png_ptr->screen_gamma * png_ptr->gamma - 1.0) + < PNG_GAMMA_THRESHOLD)) + { + int i, k; + k=0; + for (i=0; inum_trans; i++) + { + if (png_ptr->trans[i] != 0 && png_ptr->trans[i] != 0xff) + k=1; /* Partial transparency is present */ + } + if (k == 0) + png_ptr->transformations &= ~PNG_GAMMA; + } + + if ((png_ptr->transformations & (PNG_GAMMA | PNG_RGB_TO_GRAY)) && + png_ptr->gamma != 0.0) + { + png_build_gamma_table(png_ptr); + +#ifdef PNG_READ_BACKGROUND_SUPPORTED + if (png_ptr->transformations & PNG_BACKGROUND) + { + if (color_type == PNG_COLOR_TYPE_PALETTE) + { + /* Could skip if no transparency */ + png_color back, back_1; + png_colorp palette = png_ptr->palette; + int num_palette = png_ptr->num_palette; + int i; + if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE) + { + back.red = png_ptr->gamma_table[png_ptr->background.red]; + back.green = png_ptr->gamma_table[png_ptr->background.green]; + back.blue = png_ptr->gamma_table[png_ptr->background.blue]; + + back_1.red = png_ptr->gamma_to_1[png_ptr->background.red]; + back_1.green = png_ptr->gamma_to_1[png_ptr->background.green]; + back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue]; + } + else + { + double g, gs; + + switch (png_ptr->background_gamma_type) + { + case PNG_BACKGROUND_GAMMA_SCREEN: + g = (png_ptr->screen_gamma); + gs = 1.0; + break; + + case PNG_BACKGROUND_GAMMA_FILE: + g = 1.0 / (png_ptr->gamma); + gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma); + break; + + case PNG_BACKGROUND_GAMMA_UNIQUE: + g = 1.0 / (png_ptr->background_gamma); + gs = 1.0 / (png_ptr->background_gamma * + png_ptr->screen_gamma); + break; + default: + g = 1.0; /* back_1 */ + gs = 1.0; /* back */ + } + + if ( fabs(gs - 1.0) < PNG_GAMMA_THRESHOLD) + { + back.red = (png_byte)png_ptr->background.red; + back.green = (png_byte)png_ptr->background.green; + back.blue = (png_byte)png_ptr->background.blue; + } + else + { + back.red = (png_byte)(pow( + (double)png_ptr->background.red/255, gs) * 255.0 + .5); + back.green = (png_byte)(pow( + (double)png_ptr->background.green/255, gs) * 255.0 + + .5); + back.blue = (png_byte)(pow( + (double)png_ptr->background.blue/255, gs) * 255.0 + .5); + } + + back_1.red = (png_byte)(pow( + (double)png_ptr->background.red/255, g) * 255.0 + .5); + back_1.green = (png_byte)(pow( + (double)png_ptr->background.green/255, g) * 255.0 + .5); + back_1.blue = (png_byte)(pow( + (double)png_ptr->background.blue/255, g) * 255.0 + .5); + } + for (i = 0; i < num_palette; i++) + { + if (i < (int)png_ptr->num_trans && png_ptr->trans[i] != 0xff) + { + if (png_ptr->trans[i] == 0) + { + palette[i] = back; + } + else /* if (png_ptr->trans[i] != 0xff) */ + { + png_byte v, w; + + v = png_ptr->gamma_to_1[palette[i].red]; + png_composite(w, v, png_ptr->trans[i], back_1.red); + palette[i].red = png_ptr->gamma_from_1[w]; + + v = png_ptr->gamma_to_1[palette[i].green]; + png_composite(w, v, png_ptr->trans[i], back_1.green); + palette[i].green = png_ptr->gamma_from_1[w]; + + v = png_ptr->gamma_to_1[palette[i].blue]; + png_composite(w, v, png_ptr->trans[i], back_1.blue); + palette[i].blue = png_ptr->gamma_from_1[w]; + } + } + else + { + palette[i].red = png_ptr->gamma_table[palette[i].red]; + palette[i].green = png_ptr->gamma_table[palette[i].green]; + palette[i].blue = png_ptr->gamma_table[palette[i].blue]; + } + } + /* Prevent the transformations being done again, and make sure + * that the now spurious alpha channel is stripped - the code + * has just reduced background composition and gamma correction + * to a simple alpha channel strip. + */ + png_ptr->transformations &= ~PNG_BACKGROUND; + png_ptr->transformations &= ~PNG_GAMMA; + png_ptr->transformations |= PNG_STRIP_ALPHA; + } + /* if (png_ptr->background_gamma_type!=PNG_BACKGROUND_GAMMA_UNKNOWN) */ + else + /* color_type != PNG_COLOR_TYPE_PALETTE */ + { + double m = (double)(((png_uint_32)1 << png_ptr->bit_depth) - 1); + double g = 1.0; + double gs = 1.0; + + switch (png_ptr->background_gamma_type) + { + case PNG_BACKGROUND_GAMMA_SCREEN: + g = (png_ptr->screen_gamma); + gs = 1.0; + break; + + case PNG_BACKGROUND_GAMMA_FILE: + g = 1.0 / (png_ptr->gamma); + gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma); + break; + + case PNG_BACKGROUND_GAMMA_UNIQUE: + g = 1.0 / (png_ptr->background_gamma); + gs = 1.0 / (png_ptr->background_gamma * + png_ptr->screen_gamma); + break; + } + + png_ptr->background_1.gray = (png_uint_16)(pow( + (double)png_ptr->background.gray / m, g) * m + .5); + png_ptr->background.gray = (png_uint_16)(pow( + (double)png_ptr->background.gray / m, gs) * m + .5); + + if ((png_ptr->background.red != png_ptr->background.green) || + (png_ptr->background.red != png_ptr->background.blue) || + (png_ptr->background.red != png_ptr->background.gray)) + { + /* RGB or RGBA with color background */ + png_ptr->background_1.red = (png_uint_16)(pow( + (double)png_ptr->background.red / m, g) * m + .5); + png_ptr->background_1.green = (png_uint_16)(pow( + (double)png_ptr->background.green / m, g) * m + .5); + png_ptr->background_1.blue = (png_uint_16)(pow( + (double)png_ptr->background.blue / m, g) * m + .5); + png_ptr->background.red = (png_uint_16)(pow( + (double)png_ptr->background.red / m, gs) * m + .5); + png_ptr->background.green = (png_uint_16)(pow( + (double)png_ptr->background.green / m, gs) * m + .5); + png_ptr->background.blue = (png_uint_16)(pow( + (double)png_ptr->background.blue / m, gs) * m + .5); + } + else + { + /* GRAY, GRAY ALPHA, RGB, or RGBA with gray background */ + png_ptr->background_1.red = png_ptr->background_1.green + = png_ptr->background_1.blue = png_ptr->background_1.gray; + png_ptr->background.red = png_ptr->background.green + = png_ptr->background.blue = png_ptr->background.gray; + } + } + } + else + /* Transformation does not include PNG_BACKGROUND */ +#endif /* PNG_READ_BACKGROUND_SUPPORTED */ + if (color_type == PNG_COLOR_TYPE_PALETTE) + { + png_colorp palette = png_ptr->palette; + int num_palette = png_ptr->num_palette; + int i; + + for (i = 0; i < num_palette; i++) + { + palette[i].red = png_ptr->gamma_table[palette[i].red]; + palette[i].green = png_ptr->gamma_table[palette[i].green]; + palette[i].blue = png_ptr->gamma_table[palette[i].blue]; + } + + /* Done the gamma correction. */ + png_ptr->transformations &= ~PNG_GAMMA; + } + } +#ifdef PNG_READ_BACKGROUND_SUPPORTED + else +#endif +#endif /* PNG_READ_GAMMA_SUPPORTED && PNG_FLOATING_POINT_SUPPORTED */ +#ifdef PNG_READ_BACKGROUND_SUPPORTED + /* No GAMMA transformation */ + if ((png_ptr->transformations & PNG_BACKGROUND) && + (color_type == PNG_COLOR_TYPE_PALETTE)) + { + int i; + int istop = (int)png_ptr->num_trans; + png_color back; + png_colorp palette = png_ptr->palette; + + back.red = (png_byte)png_ptr->background.red; + back.green = (png_byte)png_ptr->background.green; + back.blue = (png_byte)png_ptr->background.blue; + + for (i = 0; i < istop; i++) + { + if (png_ptr->trans[i] == 0) + { + palette[i] = back; + } + else if (png_ptr->trans[i] != 0xff) + { + /* The png_composite() macro is defined in png.h */ + png_composite(palette[i].red, palette[i].red, + png_ptr->trans[i], back.red); + png_composite(palette[i].green, palette[i].green, + png_ptr->trans[i], back.green); + png_composite(palette[i].blue, palette[i].blue, + png_ptr->trans[i], back.blue); + } + } + + /* Handled alpha, still need to strip the channel. */ + png_ptr->transformations &= ~PNG_BACKGROUND; + png_ptr->transformations |= PNG_STRIP_ALPHA; + } +#endif /* PNG_READ_BACKGROUND_SUPPORTED */ + +#ifdef PNG_READ_SHIFT_SUPPORTED + if ((png_ptr->transformations & PNG_SHIFT) && + (color_type == PNG_COLOR_TYPE_PALETTE)) + { + png_uint_16 i; + png_uint_16 istop = png_ptr->num_palette; + int sr = 8 - png_ptr->sig_bit.red; + int sg = 8 - png_ptr->sig_bit.green; + int sb = 8 - png_ptr->sig_bit.blue; + + if (sr < 0 || sr > 8) + sr = 0; + if (sg < 0 || sg > 8) + sg = 0; + if (sb < 0 || sb > 8) + sb = 0; + for (i = 0; i < istop; i++) + { + png_ptr->palette[i].red >>= sr; + png_ptr->palette[i].green >>= sg; + png_ptr->palette[i].blue >>= sb; + } + } +#endif /* PNG_READ_SHIFT_SUPPORTED */ + } +#if !defined(PNG_READ_GAMMA_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED) \ + && !defined(PNG_READ_BACKGROUND_SUPPORTED) + if (png_ptr) + return; +#endif +} + +/* Modify the info structure to reflect the transformations. The + * info should be updated so a PNG file could be written with it, + * assuming the transformations result in valid PNG data. + */ +void /* PRIVATE */ +png_read_transform_info(png_structp png_ptr, png_infop info_ptr) +{ + png_debug(1, "in png_read_transform_info"); + +#ifdef PNG_READ_EXPAND_SUPPORTED + if (png_ptr->transformations & PNG_EXPAND) + { + if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + { + if (png_ptr->num_trans) + info_ptr->color_type = PNG_COLOR_TYPE_RGB_ALPHA; + else + info_ptr->color_type = PNG_COLOR_TYPE_RGB; + info_ptr->bit_depth = 8; + info_ptr->num_trans = 0; + } + else + { + if (png_ptr->num_trans) + { + if (png_ptr->transformations & PNG_EXPAND_tRNS) + info_ptr->color_type |= PNG_COLOR_MASK_ALPHA; + } + if (info_ptr->bit_depth < 8) + info_ptr->bit_depth = 8; + info_ptr->num_trans = 0; + } + } +#endif + +#ifdef PNG_READ_BACKGROUND_SUPPORTED + if (png_ptr->transformations & PNG_BACKGROUND) + { + info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA; + info_ptr->num_trans = 0; + info_ptr->background = png_ptr->background; + } +#endif + +#ifdef PNG_READ_GAMMA_SUPPORTED + if (png_ptr->transformations & PNG_GAMMA) + { +#ifdef PNG_FLOATING_POINT_SUPPORTED + info_ptr->gamma = png_ptr->gamma; +#endif +#ifdef PNG_FIXED_POINT_SUPPORTED + info_ptr->int_gamma = png_ptr->int_gamma; +#endif + } +#endif + +#ifdef PNG_READ_16_TO_8_SUPPORTED + if ((png_ptr->transformations & PNG_16_TO_8) && (info_ptr->bit_depth == 16)) + info_ptr->bit_depth = 8; +#endif + +#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED + if (png_ptr->transformations & PNG_GRAY_TO_RGB) + info_ptr->color_type |= PNG_COLOR_MASK_COLOR; +#endif + +#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED + if (png_ptr->transformations & PNG_RGB_TO_GRAY) + info_ptr->color_type &= ~PNG_COLOR_MASK_COLOR; +#endif + +#ifdef PNG_READ_DITHER_SUPPORTED + if (png_ptr->transformations & PNG_DITHER) + { + if (((info_ptr->color_type == PNG_COLOR_TYPE_RGB) || + (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)) && + png_ptr->palette_lookup && info_ptr->bit_depth == 8) + { + info_ptr->color_type = PNG_COLOR_TYPE_PALETTE; + } + } +#endif + +#ifdef PNG_READ_PACK_SUPPORTED + if ((png_ptr->transformations & PNG_PACK) && (info_ptr->bit_depth < 8)) + info_ptr->bit_depth = 8; +#endif + + if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + info_ptr->channels = 1; + else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR) + info_ptr->channels = 3; + else + info_ptr->channels = 1; + +#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED + if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA) + info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA; +#endif + + if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA) + info_ptr->channels++; + +#ifdef PNG_READ_FILLER_SUPPORTED + /* STRIP_ALPHA and FILLER allowed: MASK_ALPHA bit stripped above */ + if ((png_ptr->transformations & PNG_FILLER) && + ((info_ptr->color_type == PNG_COLOR_TYPE_RGB) || + (info_ptr->color_type == PNG_COLOR_TYPE_GRAY))) + { + info_ptr->channels++; + /* If adding a true alpha channel not just filler */ +#ifndef PNG_1_0_X + if (png_ptr->transformations & PNG_ADD_ALPHA) + info_ptr->color_type |= PNG_COLOR_MASK_ALPHA; +#endif + } +#endif + +#if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) && \ +defined(PNG_READ_USER_TRANSFORM_SUPPORTED) + if (png_ptr->transformations & PNG_USER_TRANSFORM) + { + if (info_ptr->bit_depth < png_ptr->user_transform_depth) + info_ptr->bit_depth = png_ptr->user_transform_depth; + if (info_ptr->channels < png_ptr->user_transform_channels) + info_ptr->channels = png_ptr->user_transform_channels; + } +#endif + + info_ptr->pixel_depth = (png_byte)(info_ptr->channels * + info_ptr->bit_depth); + + info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, info_ptr->width); + +#ifndef PNG_READ_EXPAND_SUPPORTED + if (png_ptr) + return; +#endif +} + +/* Transform the row. The order of transformations is significant, + * and is very touchy. If you add a transformation, take care to + * decide how it fits in with the other transformations here. + */ +void /* PRIVATE */ +png_do_read_transformations(png_structp png_ptr) +{ + png_debug(1, "in png_do_read_transformations"); + + if (png_ptr->row_buf == NULL) + { +#if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE) + char msg[50]; + + png_snprintf2(msg, 50, + "NULL row buffer for row %ld, pass %d", (long)png_ptr->row_number, + png_ptr->pass); + png_error(png_ptr, msg); +#else + png_error(png_ptr, "NULL row buffer"); +#endif + } +#ifdef PNG_WARN_UNINITIALIZED_ROW + if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) + /* Application has failed to call either png_read_start_image() + * or png_read_update_info() after setting transforms that expand + * pixels. This check added to libpng-1.2.19 + */ +#if (PNG_WARN_UNINITIALIZED_ROW==1) + png_error(png_ptr, "Uninitialized row"); +#else + png_warning(png_ptr, "Uninitialized row"); +#endif +#endif + +#ifdef PNG_READ_EXPAND_SUPPORTED + if (png_ptr->transformations & PNG_EXPAND) + { + if (png_ptr->row_info.color_type == PNG_COLOR_TYPE_PALETTE) + { + png_do_expand_palette(&(png_ptr->row_info), png_ptr->row_buf + 1, + png_ptr->palette, png_ptr->trans, png_ptr->num_trans); + } + else + { + if (png_ptr->num_trans && + (png_ptr->transformations & PNG_EXPAND_tRNS)) + png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1, + &(png_ptr->trans_values)); + else + png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1, + NULL); + } + } +#endif + +#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED + if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA) + png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1, + PNG_FLAG_FILLER_AFTER | (png_ptr->flags & PNG_FLAG_STRIP_ALPHA)); +#endif + +#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED + if (png_ptr->transformations & PNG_RGB_TO_GRAY) + { + int rgb_error = + png_do_rgb_to_gray(png_ptr, &(png_ptr->row_info), + png_ptr->row_buf + 1); + if (rgb_error) + { + png_ptr->rgb_to_gray_status=1; + if ((png_ptr->transformations & PNG_RGB_TO_GRAY) == + PNG_RGB_TO_GRAY_WARN) + png_warning(png_ptr, "png_do_rgb_to_gray found nongray pixel"); + if ((png_ptr->transformations & PNG_RGB_TO_GRAY) == + PNG_RGB_TO_GRAY_ERR) + png_error(png_ptr, "png_do_rgb_to_gray found nongray pixel"); + } + } +#endif + +/* From Andreas Dilger e-mail to png-implement, 26 March 1998: + * + * In most cases, the "simple transparency" should be done prior to doing + * gray-to-RGB, or you will have to test 3x as many bytes to check if a + * pixel is transparent. You would also need to make sure that the + * transparency information is upgraded to RGB. + * + * To summarize, the current flow is: + * - Gray + simple transparency -> compare 1 or 2 gray bytes and composite + * with background "in place" if transparent, + * convert to RGB if necessary + * - Gray + alpha -> composite with gray background and remove alpha bytes, + * convert to RGB if necessary + * + * To support RGB backgrounds for gray images we need: + * - Gray + simple transparency -> convert to RGB + simple transparency, + * compare 3 or 6 bytes and composite with + * background "in place" if transparent + * (3x compare/pixel compared to doing + * composite with gray bkgrnd) + * - Gray + alpha -> convert to RGB + alpha, composite with background and + * remove alpha bytes (3x float + * operations/pixel compared with composite + * on gray background) + * + * Greg's change will do this. The reason it wasn't done before is for + * performance, as this increases the per-pixel operations. If we would check + * in advance if the background was gray or RGB, and position the gray-to-RGB + * transform appropriately, then it would save a lot of work/time. + */ + +#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED + /* If gray -> RGB, do so now only if background is non-gray; else do later + * for performance reasons + */ + if ((png_ptr->transformations & PNG_GRAY_TO_RGB) && + !(png_ptr->mode & PNG_BACKGROUND_IS_GRAY)) + png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1); +#endif + +#ifdef PNG_READ_BACKGROUND_SUPPORTED + if ((png_ptr->transformations & PNG_BACKGROUND) && + ((png_ptr->num_trans != 0 ) || + (png_ptr->color_type & PNG_COLOR_MASK_ALPHA))) + png_do_background(&(png_ptr->row_info), png_ptr->row_buf + 1, + &(png_ptr->trans_values), &(png_ptr->background) +#ifdef PNG_READ_GAMMA_SUPPORTED + , &(png_ptr->background_1), + png_ptr->gamma_table, png_ptr->gamma_from_1, + png_ptr->gamma_to_1, png_ptr->gamma_16_table, + png_ptr->gamma_16_from_1, png_ptr->gamma_16_to_1, + png_ptr->gamma_shift +#endif +); +#endif + +#ifdef PNG_READ_GAMMA_SUPPORTED + if ((png_ptr->transformations & PNG_GAMMA) && +#ifdef PNG_READ_BACKGROUND_SUPPORTED + !((png_ptr->transformations & PNG_BACKGROUND) && + ((png_ptr->num_trans != 0) || + (png_ptr->color_type & PNG_COLOR_MASK_ALPHA))) && +#endif + (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)) + png_do_gamma(&(png_ptr->row_info), png_ptr->row_buf + 1, + png_ptr->gamma_table, png_ptr->gamma_16_table, + png_ptr->gamma_shift); +#endif + +#ifdef PNG_READ_16_TO_8_SUPPORTED + if (png_ptr->transformations & PNG_16_TO_8) + png_do_chop(&(png_ptr->row_info), png_ptr->row_buf + 1); +#endif + +#ifdef PNG_READ_DITHER_SUPPORTED + if (png_ptr->transformations & PNG_DITHER) + { + png_do_dither((png_row_infop)&(png_ptr->row_info), png_ptr->row_buf + 1, + png_ptr->palette_lookup, png_ptr->dither_index); + if (png_ptr->row_info.rowbytes == (png_uint_32)0) + png_error(png_ptr, "png_do_dither returned rowbytes=0"); + } +#endif + +#ifdef PNG_READ_INVERT_SUPPORTED + if (png_ptr->transformations & PNG_INVERT_MONO) + png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1); +#endif + +#ifdef PNG_READ_SHIFT_SUPPORTED + if (png_ptr->transformations & PNG_SHIFT) + png_do_unshift(&(png_ptr->row_info), png_ptr->row_buf + 1, + &(png_ptr->shift)); +#endif + +#ifdef PNG_READ_PACK_SUPPORTED + if (png_ptr->transformations & PNG_PACK) + png_do_unpack(&(png_ptr->row_info), png_ptr->row_buf + 1); +#endif + +#ifdef PNG_READ_BGR_SUPPORTED + if (png_ptr->transformations & PNG_BGR) + png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1); +#endif + +#ifdef PNG_READ_PACKSWAP_SUPPORTED + if (png_ptr->transformations & PNG_PACKSWAP) + png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1); +#endif + +#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED + /* If gray -> RGB, do so now only if we did not do so above */ + if ((png_ptr->transformations & PNG_GRAY_TO_RGB) && + (png_ptr->mode & PNG_BACKGROUND_IS_GRAY)) + png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1); +#endif + +#ifdef PNG_READ_FILLER_SUPPORTED + if (png_ptr->transformations & PNG_FILLER) + png_do_read_filler(&(png_ptr->row_info), png_ptr->row_buf + 1, + (png_uint_32)png_ptr->filler, png_ptr->flags); +#endif + +#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED + if (png_ptr->transformations & PNG_INVERT_ALPHA) + png_do_read_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1); +#endif + +#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED + if (png_ptr->transformations & PNG_SWAP_ALPHA) + png_do_read_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1); +#endif + +#ifdef PNG_READ_SWAP_SUPPORTED + if (png_ptr->transformations & PNG_SWAP_BYTES) + png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1); +#endif + +#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED + if (png_ptr->transformations & PNG_USER_TRANSFORM) + { + if (png_ptr->read_user_transform_fn != NULL) + (*(png_ptr->read_user_transform_fn)) /* User read transform function */ + (png_ptr, /* png_ptr */ + &(png_ptr->row_info), /* row_info: */ + /* png_uint_32 width; width of row */ + /* png_uint_32 rowbytes; number of bytes in row */ + /* png_byte color_type; color type of pixels */ + /* png_byte bit_depth; bit depth of samples */ + /* png_byte channels; number of channels (1-4) */ + /* png_byte pixel_depth; bits per pixel (depth*channels) */ + png_ptr->row_buf + 1); /* start of pixel data for row */ +#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED + if (png_ptr->user_transform_depth) + png_ptr->row_info.bit_depth = png_ptr->user_transform_depth; + if (png_ptr->user_transform_channels) + png_ptr->row_info.channels = png_ptr->user_transform_channels; +#endif + png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth * + png_ptr->row_info.channels); + png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth, + png_ptr->row_info.width); + } +#endif + +} + +#ifdef PNG_READ_PACK_SUPPORTED +/* Unpack pixels of 1, 2, or 4 bits per pixel into 1 byte per pixel, + * without changing the actual values. Thus, if you had a row with + * a bit depth of 1, you would end up with bytes that only contained + * the numbers 0 or 1. If you would rather they contain 0 and 255, use + * png_do_shift() after this. + */ +void /* PRIVATE */ +png_do_unpack(png_row_infop row_info, png_bytep row) +{ + png_debug(1, "in png_do_unpack"); + +#ifdef PNG_USELESS_TESTS_SUPPORTED + if (row != NULL && row_info != NULL && row_info->bit_depth < 8) +#else + if (row_info->bit_depth < 8) +#endif + { + png_uint_32 i; + png_uint_32 row_width=row_info->width; + + switch (row_info->bit_depth) + { + case 1: + { + png_bytep sp = row + (png_size_t)((row_width - 1) >> 3); + png_bytep dp = row + (png_size_t)row_width - 1; + png_uint_32 shift = 7 - (int)((row_width + 7) & 0x07); + for (i = 0; i < row_width; i++) + { + *dp = (png_byte)((*sp >> shift) & 0x01); + if (shift == 7) + { + shift = 0; + sp--; + } + else + shift++; + + dp--; + } + break; + } + + case 2: + { + + png_bytep sp = row + (png_size_t)((row_width - 1) >> 2); + png_bytep dp = row + (png_size_t)row_width - 1; + png_uint_32 shift = (int)((3 - ((row_width + 3) & 0x03)) << 1); + for (i = 0; i < row_width; i++) + { + *dp = (png_byte)((*sp >> shift) & 0x03); + if (shift == 6) + { + shift = 0; + sp--; + } + else + shift += 2; + + dp--; + } + break; + } + + case 4: + { + png_bytep sp = row + (png_size_t)((row_width - 1) >> 1); + png_bytep dp = row + (png_size_t)row_width - 1; + png_uint_32 shift = (int)((1 - ((row_width + 1) & 0x01)) << 2); + for (i = 0; i < row_width; i++) + { + *dp = (png_byte)((*sp >> shift) & 0x0f); + if (shift == 4) + { + shift = 0; + sp--; + } + else + shift = 4; + + dp--; + } + break; + } + } + row_info->bit_depth = 8; + row_info->pixel_depth = (png_byte)(8 * row_info->channels); + row_info->rowbytes = row_width * row_info->channels; + } +} +#endif + +#ifdef PNG_READ_SHIFT_SUPPORTED +/* Reverse the effects of png_do_shift. This routine merely shifts the + * pixels back to their significant bits values. Thus, if you have + * a row of bit depth 8, but only 5 are significant, this will shift + * the values back to 0 through 31. + */ +void /* PRIVATE */ +png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits) +{ + png_debug(1, "in png_do_unshift"); + + if ( +#ifdef PNG_USELESS_TESTS_SUPPORTED + row != NULL && row_info != NULL && sig_bits != NULL && +#endif + row_info->color_type != PNG_COLOR_TYPE_PALETTE) + { + int shift[4]; + int channels = 0; + int c; + png_uint_16 value = 0; + png_uint_32 row_width = row_info->width; + + if (row_info->color_type & PNG_COLOR_MASK_COLOR) + { + shift[channels++] = row_info->bit_depth - sig_bits->red; + shift[channels++] = row_info->bit_depth - sig_bits->green; + shift[channels++] = row_info->bit_depth - sig_bits->blue; + } + else + { + shift[channels++] = row_info->bit_depth - sig_bits->gray; + } + if (row_info->color_type & PNG_COLOR_MASK_ALPHA) + { + shift[channels++] = row_info->bit_depth - sig_bits->alpha; + } + + for (c = 0; c < channels; c++) + { + if (shift[c] <= 0) + shift[c] = 0; + else + value = 1; + } + + if (!value) + return; + + switch (row_info->bit_depth) + { + case 2: + { + png_bytep bp; + png_uint_32 i; + png_uint_32 istop = row_info->rowbytes; + + for (bp = row, i = 0; i < istop; i++) + { + *bp >>= 1; + *bp++ &= 0x55; + } + break; + } + + case 4: + { + png_bytep bp = row; + png_uint_32 i; + png_uint_32 istop = row_info->rowbytes; + png_byte mask = (png_byte)((((int)0xf0 >> shift[0]) & (int)0xf0) | + (png_byte)((int)0xf >> shift[0])); + + for (i = 0; i < istop; i++) + { + *bp >>= shift[0]; + *bp++ &= mask; + } + break; + } + + case 8: + { + png_bytep bp = row; + png_uint_32 i; + png_uint_32 istop = row_width * channels; + + for (i = 0; i < istop; i++) + { + *bp++ >>= shift[i%channels]; + } + break; + } + + case 16: + { + png_bytep bp = row; + png_uint_32 i; + png_uint_32 istop = channels * row_width; + + for (i = 0; i < istop; i++) + { + value = (png_uint_16)((*bp << 8) + *(bp + 1)); + value >>= shift[i%channels]; + *bp++ = (png_byte)(value >> 8); + *bp++ = (png_byte)(value & 0xff); + } + break; + } + } + } +} +#endif + +#ifdef PNG_READ_16_TO_8_SUPPORTED +/* Chop rows of bit depth 16 down to 8 */ +void /* PRIVATE */ +png_do_chop(png_row_infop row_info, png_bytep row) +{ + png_debug(1, "in png_do_chop"); + +#ifdef PNG_USELESS_TESTS_SUPPORTED + if (row != NULL && row_info != NULL && row_info->bit_depth == 16) +#else + if (row_info->bit_depth == 16) +#endif + { + png_bytep sp = row; + png_bytep dp = row; + png_uint_32 i; + png_uint_32 istop = row_info->width * row_info->channels; + + for (i = 0; i> 8)) >> 8; + * + * Approximate calculation with shift/add instead of multiply/divide: + * *dp = ((((png_uint_32)(*sp) << 8) | + * (png_uint_32)((int)(*(sp + 1)) - *sp)) + 128) >> 8; + * + * What we actually do to avoid extra shifting and conversion: + */ + + *dp = *sp + ((((int)(*(sp + 1)) - *sp) > 128) ? 1 : 0); +#else + /* Simply discard the low order byte */ + *dp = *sp; +#endif + } + row_info->bit_depth = 8; + row_info->pixel_depth = (png_byte)(8 * row_info->channels); + row_info->rowbytes = row_info->width * row_info->channels; + } +} +#endif + +#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED +void /* PRIVATE */ +png_do_read_swap_alpha(png_row_infop row_info, png_bytep row) +{ + png_debug(1, "in png_do_read_swap_alpha"); + +#ifdef PNG_USELESS_TESTS_SUPPORTED + if (row != NULL && row_info != NULL) +#endif + { + png_uint_32 row_width = row_info->width; + if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + { + /* This converts from RGBA to ARGB */ + if (row_info->bit_depth == 8) + { + png_bytep sp = row + row_info->rowbytes; + png_bytep dp = sp; + png_byte save; + png_uint_32 i; + + for (i = 0; i < row_width; i++) + { + save = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = save; + } + } + /* This converts from RRGGBBAA to AARRGGBB */ + else + { + png_bytep sp = row + row_info->rowbytes; + png_bytep dp = sp; + png_byte save[2]; + png_uint_32 i; + + for (i = 0; i < row_width; i++) + { + save[0] = *(--sp); + save[1] = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = save[0]; + *(--dp) = save[1]; + } + } + } + else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) + { + /* This converts from GA to AG */ + if (row_info->bit_depth == 8) + { + png_bytep sp = row + row_info->rowbytes; + png_bytep dp = sp; + png_byte save; + png_uint_32 i; + + for (i = 0; i < row_width; i++) + { + save = *(--sp); + *(--dp) = *(--sp); + *(--dp) = save; + } + } + /* This converts from GGAA to AAGG */ + else + { + png_bytep sp = row + row_info->rowbytes; + png_bytep dp = sp; + png_byte save[2]; + png_uint_32 i; + + for (i = 0; i < row_width; i++) + { + save[0] = *(--sp); + save[1] = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = save[0]; + *(--dp) = save[1]; + } + } + } + } +} +#endif + +#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED +void /* PRIVATE */ +png_do_read_invert_alpha(png_row_infop row_info, png_bytep row) +{ + png_debug(1, "in png_do_read_invert_alpha"); + +#ifdef PNG_USELESS_TESTS_SUPPORTED + if (row != NULL && row_info != NULL) +#endif + { + png_uint_32 row_width = row_info->width; + if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + { + /* This inverts the alpha channel in RGBA */ + if (row_info->bit_depth == 8) + { + png_bytep sp = row + row_info->rowbytes; + png_bytep dp = sp; + png_uint_32 i; + + for (i = 0; i < row_width; i++) + { + *(--dp) = (png_byte)(255 - *(--sp)); + +/* This does nothing: + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + We can replace it with: +*/ + sp-=3; + dp=sp; + } + } + /* This inverts the alpha channel in RRGGBBAA */ + else + { + png_bytep sp = row + row_info->rowbytes; + png_bytep dp = sp; + png_uint_32 i; + + for (i = 0; i < row_width; i++) + { + *(--dp) = (png_byte)(255 - *(--sp)); + *(--dp) = (png_byte)(255 - *(--sp)); + +/* This does nothing: + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + We can replace it with: +*/ + sp-=6; + dp=sp; + } + } + } + else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) + { + /* This inverts the alpha channel in GA */ + if (row_info->bit_depth == 8) + { + png_bytep sp = row + row_info->rowbytes; + png_bytep dp = sp; + png_uint_32 i; + + for (i = 0; i < row_width; i++) + { + *(--dp) = (png_byte)(255 - *(--sp)); + *(--dp) = *(--sp); + } + } + /* This inverts the alpha channel in GGAA */ + else + { + png_bytep sp = row + row_info->rowbytes; + png_bytep dp = sp; + png_uint_32 i; + + for (i = 0; i < row_width; i++) + { + *(--dp) = (png_byte)(255 - *(--sp)); + *(--dp) = (png_byte)(255 - *(--sp)); +/* + *(--dp) = *(--sp); + *(--dp) = *(--sp); +*/ + sp-=2; + dp=sp; + } + } + } + } +} +#endif + +#ifdef PNG_READ_FILLER_SUPPORTED +/* Add filler channel if we have RGB color */ +void /* PRIVATE */ +png_do_read_filler(png_row_infop row_info, png_bytep row, + png_uint_32 filler, png_uint_32 flags) +{ + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + png_byte hi_filler = (png_byte)((filler>>8) & 0xff); + png_byte lo_filler = (png_byte)(filler & 0xff); + + png_debug(1, "in png_do_read_filler"); + + if ( +#ifdef PNG_USELESS_TESTS_SUPPORTED + row != NULL && row_info != NULL && +#endif + row_info->color_type == PNG_COLOR_TYPE_GRAY) + { + if (row_info->bit_depth == 8) + { + /* This changes the data from G to GX */ + if (flags & PNG_FLAG_FILLER_AFTER) + { + png_bytep sp = row + (png_size_t)row_width; + png_bytep dp = sp + (png_size_t)row_width; + for (i = 1; i < row_width; i++) + { + *(--dp) = lo_filler; + *(--dp) = *(--sp); + } + *(--dp) = lo_filler; + row_info->channels = 2; + row_info->pixel_depth = 16; + row_info->rowbytes = row_width * 2; + } + /* This changes the data from G to XG */ + else + { + png_bytep sp = row + (png_size_t)row_width; + png_bytep dp = sp + (png_size_t)row_width; + for (i = 0; i < row_width; i++) + { + *(--dp) = *(--sp); + *(--dp) = lo_filler; + } + row_info->channels = 2; + row_info->pixel_depth = 16; + row_info->rowbytes = row_width * 2; + } + } + else if (row_info->bit_depth == 16) + { + /* This changes the data from GG to GGXX */ + if (flags & PNG_FLAG_FILLER_AFTER) + { + png_bytep sp = row + (png_size_t)row_width * 2; + png_bytep dp = sp + (png_size_t)row_width * 2; + for (i = 1; i < row_width; i++) + { + *(--dp) = hi_filler; + *(--dp) = lo_filler; + *(--dp) = *(--sp); + *(--dp) = *(--sp); + } + *(--dp) = hi_filler; + *(--dp) = lo_filler; + row_info->channels = 2; + row_info->pixel_depth = 32; + row_info->rowbytes = row_width * 4; + } + /* This changes the data from GG to XXGG */ + else + { + png_bytep sp = row + (png_size_t)row_width * 2; + png_bytep dp = sp + (png_size_t)row_width * 2; + for (i = 0; i < row_width; i++) + { + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = hi_filler; + *(--dp) = lo_filler; + } + row_info->channels = 2; + row_info->pixel_depth = 32; + row_info->rowbytes = row_width * 4; + } + } + } /* COLOR_TYPE == GRAY */ + else if (row_info->color_type == PNG_COLOR_TYPE_RGB) + { + if (row_info->bit_depth == 8) + { + /* This changes the data from RGB to RGBX */ + if (flags & PNG_FLAG_FILLER_AFTER) + { + png_bytep sp = row + (png_size_t)row_width * 3; + png_bytep dp = sp + (png_size_t)row_width; + for (i = 1; i < row_width; i++) + { + *(--dp) = lo_filler; + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + } + *(--dp) = lo_filler; + row_info->channels = 4; + row_info->pixel_depth = 32; + row_info->rowbytes = row_width * 4; + } + /* This changes the data from RGB to XRGB */ + else + { + png_bytep sp = row + (png_size_t)row_width * 3; + png_bytep dp = sp + (png_size_t)row_width; + for (i = 0; i < row_width; i++) + { + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = lo_filler; + } + row_info->channels = 4; + row_info->pixel_depth = 32; + row_info->rowbytes = row_width * 4; + } + } + else if (row_info->bit_depth == 16) + { + /* This changes the data from RRGGBB to RRGGBBXX */ + if (flags & PNG_FLAG_FILLER_AFTER) + { + png_bytep sp = row + (png_size_t)row_width * 6; + png_bytep dp = sp + (png_size_t)row_width * 2; + for (i = 1; i < row_width; i++) + { + *(--dp) = hi_filler; + *(--dp) = lo_filler; + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + } + *(--dp) = hi_filler; + *(--dp) = lo_filler; + row_info->channels = 4; + row_info->pixel_depth = 64; + row_info->rowbytes = row_width * 8; + } + /* This changes the data from RRGGBB to XXRRGGBB */ + else + { + png_bytep sp = row + (png_size_t)row_width * 6; + png_bytep dp = sp + (png_size_t)row_width * 2; + for (i = 0; i < row_width; i++) + { + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = *(--sp); + *(--dp) = hi_filler; + *(--dp) = lo_filler; + } + row_info->channels = 4; + row_info->pixel_depth = 64; + row_info->rowbytes = row_width * 8; + } + } + } /* COLOR_TYPE == RGB */ +} +#endif + +#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED +/* Expand grayscale files to RGB, with or without alpha */ +void /* PRIVATE */ +png_do_gray_to_rgb(png_row_infop row_info, png_bytep row) +{ + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + png_debug(1, "in png_do_gray_to_rgb"); + + if (row_info->bit_depth >= 8 && +#ifdef PNG_USELESS_TESTS_SUPPORTED + row != NULL && row_info != NULL && +#endif + !(row_info->color_type & PNG_COLOR_MASK_COLOR)) + { + if (row_info->color_type == PNG_COLOR_TYPE_GRAY) + { + if (row_info->bit_depth == 8) + { + png_bytep sp = row + (png_size_t)row_width - 1; + png_bytep dp = sp + (png_size_t)row_width * 2; + for (i = 0; i < row_width; i++) + { + *(dp--) = *sp; + *(dp--) = *sp; + *(dp--) = *(sp--); + } + } + else + { + png_bytep sp = row + (png_size_t)row_width * 2 - 1; + png_bytep dp = sp + (png_size_t)row_width * 4; + for (i = 0; i < row_width; i++) + { + *(dp--) = *sp; + *(dp--) = *(sp - 1); + *(dp--) = *sp; + *(dp--) = *(sp - 1); + *(dp--) = *(sp--); + *(dp--) = *(sp--); + } + } + } + else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) + { + if (row_info->bit_depth == 8) + { + png_bytep sp = row + (png_size_t)row_width * 2 - 1; + png_bytep dp = sp + (png_size_t)row_width * 2; + for (i = 0; i < row_width; i++) + { + *(dp--) = *(sp--); + *(dp--) = *sp; + *(dp--) = *sp; + *(dp--) = *(sp--); + } + } + else + { + png_bytep sp = row + (png_size_t)row_width * 4 - 1; + png_bytep dp = sp + (png_size_t)row_width * 4; + for (i = 0; i < row_width; i++) + { + *(dp--) = *(sp--); + *(dp--) = *(sp--); + *(dp--) = *sp; + *(dp--) = *(sp - 1); + *(dp--) = *sp; + *(dp--) = *(sp - 1); + *(dp--) = *(sp--); + *(dp--) = *(sp--); + } + } + } + row_info->channels += (png_byte)2; + row_info->color_type |= PNG_COLOR_MASK_COLOR; + row_info->pixel_depth = (png_byte)(row_info->channels * + row_info->bit_depth); + row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width); + } +} +#endif + +#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED +/* Reduce RGB files to grayscale, with or without alpha + * using the equation given in Poynton's ColorFAQ at + * (THIS LINK IS DEAD June 2008) + * New link: + * + * Charles Poynton poynton at poynton.com + * + * Y = 0.212671 * R + 0.715160 * G + 0.072169 * B + * + * We approximate this with + * + * Y = 0.21268 * R + 0.7151 * G + 0.07217 * B + * + * which can be expressed with integers as + * + * Y = (6969 * R + 23434 * G + 2365 * B)/32768 + * + * The calculation is to be done in a linear colorspace. + * + * Other integer coefficents can be used via png_set_rgb_to_gray(). + */ +int /* PRIVATE */ +png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row) + +{ + png_uint_32 i; + + png_uint_32 row_width = row_info->width; + int rgb_error = 0; + + png_debug(1, "in png_do_rgb_to_gray"); + + if ( +#ifdef PNG_USELESS_TESTS_SUPPORTED + row != NULL && row_info != NULL && +#endif + (row_info->color_type & PNG_COLOR_MASK_COLOR)) + { + png_uint_32 rc = png_ptr->rgb_to_gray_red_coeff; + png_uint_32 gc = png_ptr->rgb_to_gray_green_coeff; + png_uint_32 bc = png_ptr->rgb_to_gray_blue_coeff; + + if (row_info->color_type == PNG_COLOR_TYPE_RGB) + { + if (row_info->bit_depth == 8) + { +#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) + if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL) + { + png_bytep sp = row; + png_bytep dp = row; + + for (i = 0; i < row_width; i++) + { + png_byte red = png_ptr->gamma_to_1[*(sp++)]; + png_byte green = png_ptr->gamma_to_1[*(sp++)]; + png_byte blue = png_ptr->gamma_to_1[*(sp++)]; + if (red != green || red != blue) + { + rgb_error |= 1; + *(dp++) = png_ptr->gamma_from_1[ + (rc*red + gc*green + bc*blue)>>15]; + } + else + *(dp++) = *(sp - 1); + } + } + else +#endif + { + png_bytep sp = row; + png_bytep dp = row; + for (i = 0; i < row_width; i++) + { + png_byte red = *(sp++); + png_byte green = *(sp++); + png_byte blue = *(sp++); + if (red != green || red != blue) + { + rgb_error |= 1; + *(dp++) = (png_byte)((rc*red + gc*green + bc*blue)>>15); + } + else + *(dp++) = *(sp - 1); + } + } + } + + else /* RGB bit_depth == 16 */ + { +#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) + if (png_ptr->gamma_16_to_1 != NULL && + png_ptr->gamma_16_from_1 != NULL) + { + png_bytep sp = row; + png_bytep dp = row; + for (i = 0; i < row_width; i++) + { + png_uint_16 red, green, blue, w; + + red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2; + green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2; + blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2; + + if (red == green && red == blue) + w = red; + else + { + png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >> + png_ptr->gamma_shift][red>>8]; + png_uint_16 green_1 = + png_ptr->gamma_16_to_1[(green&0xff) >> + png_ptr->gamma_shift][green>>8]; + png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >> + png_ptr->gamma_shift][blue>>8]; + png_uint_16 gray16 = (png_uint_16)((rc*red_1 + gc*green_1 + + bc*blue_1)>>15); + w = png_ptr->gamma_16_from_1[(gray16&0xff) >> + png_ptr->gamma_shift][gray16 >> 8]; + rgb_error |= 1; + } + + *(dp++) = (png_byte)((w>>8) & 0xff); + *(dp++) = (png_byte)(w & 0xff); + } + } + else +#endif + { + png_bytep sp = row; + png_bytep dp = row; + for (i = 0; i < row_width; i++) + { + png_uint_16 red, green, blue, gray16; + + red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2; + green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2; + blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2; + + if (red != green || red != blue) + rgb_error |= 1; + gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15); + *(dp++) = (png_byte)((gray16>>8) & 0xff); + *(dp++) = (png_byte)(gray16 & 0xff); + } + } + } + } + if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + { + if (row_info->bit_depth == 8) + { +#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) + if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL) + { + png_bytep sp = row; + png_bytep dp = row; + for (i = 0; i < row_width; i++) + { + png_byte red = png_ptr->gamma_to_1[*(sp++)]; + png_byte green = png_ptr->gamma_to_1[*(sp++)]; + png_byte blue = png_ptr->gamma_to_1[*(sp++)]; + if (red != green || red != blue) + rgb_error |= 1; + *(dp++) = png_ptr->gamma_from_1 + [(rc*red + gc*green + bc*blue)>>15]; + *(dp++) = *(sp++); /* alpha */ + } + } + else +#endif + { + png_bytep sp = row; + png_bytep dp = row; + for (i = 0; i < row_width; i++) + { + png_byte red = *(sp++); + png_byte green = *(sp++); + png_byte blue = *(sp++); + if (red != green || red != blue) + rgb_error |= 1; + *(dp++) = (png_byte)((rc*red + gc*green + bc*blue)>>15); + *(dp++) = *(sp++); /* alpha */ + } + } + } + else /* RGBA bit_depth == 16 */ + { +#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) + if (png_ptr->gamma_16_to_1 != NULL && + png_ptr->gamma_16_from_1 != NULL) + { + png_bytep sp = row; + png_bytep dp = row; + for (i = 0; i < row_width; i++) + { + png_uint_16 red, green, blue, w; + + red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2; + green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2; + blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2; + + if (red == green && red == blue) + w = red; + else + { + png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >> + png_ptr->gamma_shift][red>>8]; + png_uint_16 green_1 = + png_ptr->gamma_16_to_1[(green&0xff) >> + png_ptr->gamma_shift][green>>8]; + png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >> + png_ptr->gamma_shift][blue>>8]; + png_uint_16 gray16 = (png_uint_16)((rc * red_1 + + gc * green_1 + bc * blue_1)>>15); + w = png_ptr->gamma_16_from_1[(gray16&0xff) >> + png_ptr->gamma_shift][gray16 >> 8]; + rgb_error |= 1; + } + + *(dp++) = (png_byte)((w>>8) & 0xff); + *(dp++) = (png_byte)(w & 0xff); + *(dp++) = *(sp++); /* alpha */ + *(dp++) = *(sp++); + } + } + else +#endif + { + png_bytep sp = row; + png_bytep dp = row; + for (i = 0; i < row_width; i++) + { + png_uint_16 red, green, blue, gray16; + red = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2; + green = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2; + blue = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2; + if (red != green || red != blue) + rgb_error |= 1; + gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15); + *(dp++) = (png_byte)((gray16>>8) & 0xff); + *(dp++) = (png_byte)(gray16 & 0xff); + *(dp++) = *(sp++); /* alpha */ + *(dp++) = *(sp++); + } + } + } + } + row_info->channels -= (png_byte)2; + row_info->color_type &= ~PNG_COLOR_MASK_COLOR; + row_info->pixel_depth = (png_byte)(row_info->channels * + row_info->bit_depth); + row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width); + } + return rgb_error; +} +#endif + +/* Build a grayscale palette. Palette is assumed to be 1 << bit_depth + * large of png_color. This lets grayscale images be treated as + * paletted. Most useful for gamma correction and simplification + * of code. + */ +void PNGAPI +png_build_grayscale_palette(int bit_depth, png_colorp palette) +{ + int num_palette; + int color_inc; + int i; + int v; + + png_debug(1, "in png_do_build_grayscale_palette"); + + if (palette == NULL) + return; + + switch (bit_depth) + { + case 1: + num_palette = 2; + color_inc = 0xff; + break; + + case 2: + num_palette = 4; + color_inc = 0x55; + break; + + case 4: + num_palette = 16; + color_inc = 0x11; + break; + + case 8: + num_palette = 256; + color_inc = 1; + break; + + default: + num_palette = 0; + color_inc = 0; + break; + } + + for (i = 0, v = 0; i < num_palette; i++, v += color_inc) + { + palette[i].red = (png_byte)v; + palette[i].green = (png_byte)v; + palette[i].blue = (png_byte)v; + } +} + +/* This function is currently unused. Do we really need it? */ +#if defined(PNG_READ_DITHER_SUPPORTED) && \ + defined(PNG_CORRECT_PALETTE_SUPPORTED) +void /* PRIVATE */ +png_correct_palette(png_structp png_ptr, png_colorp palette, + int num_palette) +{ + png_debug(1, "in png_correct_palette"); + +#if defined(PNG_READ_BACKGROUND_SUPPORTED) && \ + defined(PNG_READ_GAMMA_SUPPORTED) && \ + defined(PNG_FLOATING_POINT_SUPPORTED) + if (png_ptr->transformations & (PNG_GAMMA | PNG_BACKGROUND)) + { + png_color back, back_1; + + if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE) + { + back.red = png_ptr->gamma_table[png_ptr->background.red]; + back.green = png_ptr->gamma_table[png_ptr->background.green]; + back.blue = png_ptr->gamma_table[png_ptr->background.blue]; + + back_1.red = png_ptr->gamma_to_1[png_ptr->background.red]; + back_1.green = png_ptr->gamma_to_1[png_ptr->background.green]; + back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue]; + } + else + { + double g; + + g = 1.0 / (png_ptr->background_gamma * png_ptr->screen_gamma); + + if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_SCREEN + || fabs(g - 1.0) < PNG_GAMMA_THRESHOLD) + { + back.red = png_ptr->background.red; + back.green = png_ptr->background.green; + back.blue = png_ptr->background.blue; + } + else + { + back.red = + (png_byte)(pow((double)png_ptr->background.red/255, g) * + 255.0 + 0.5); + back.green = + (png_byte)(pow((double)png_ptr->background.green/255, g) * + 255.0 + 0.5); + back.blue = + (png_byte)(pow((double)png_ptr->background.blue/255, g) * + 255.0 + 0.5); + } + + g = 1.0 / png_ptr->background_gamma; + + back_1.red = + (png_byte)(pow((double)png_ptr->background.red/255, g) * + 255.0 + 0.5); + back_1.green = + (png_byte)(pow((double)png_ptr->background.green/255, g) * + 255.0 + 0.5); + back_1.blue = + (png_byte)(pow((double)png_ptr->background.blue/255, g) * + 255.0 + 0.5); + } + + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + { + png_uint_32 i; + + for (i = 0; i < (png_uint_32)num_palette; i++) + { + if (i < png_ptr->num_trans && png_ptr->trans[i] == 0) + { + palette[i] = back; + } + else if (i < png_ptr->num_trans && png_ptr->trans[i] != 0xff) + { + png_byte v, w; + + v = png_ptr->gamma_to_1[png_ptr->palette[i].red]; + png_composite(w, v, png_ptr->trans[i], back_1.red); + palette[i].red = png_ptr->gamma_from_1[w]; + + v = png_ptr->gamma_to_1[png_ptr->palette[i].green]; + png_composite(w, v, png_ptr->trans[i], back_1.green); + palette[i].green = png_ptr->gamma_from_1[w]; + + v = png_ptr->gamma_to_1[png_ptr->palette[i].blue]; + png_composite(w, v, png_ptr->trans[i], back_1.blue); + palette[i].blue = png_ptr->gamma_from_1[w]; + } + else + { + palette[i].red = png_ptr->gamma_table[palette[i].red]; + palette[i].green = png_ptr->gamma_table[palette[i].green]; + palette[i].blue = png_ptr->gamma_table[palette[i].blue]; + } + } + } + else + { + int i; + + for (i = 0; i < num_palette; i++) + { + if (palette[i].red == (png_byte)png_ptr->trans_values.gray) + { + palette[i] = back; + } + else + { + palette[i].red = png_ptr->gamma_table[palette[i].red]; + palette[i].green = png_ptr->gamma_table[palette[i].green]; + palette[i].blue = png_ptr->gamma_table[palette[i].blue]; + } + } + } + } + else +#endif +#ifdef PNG_READ_GAMMA_SUPPORTED + if (png_ptr->transformations & PNG_GAMMA) + { + int i; + + for (i = 0; i < num_palette; i++) + { + palette[i].red = png_ptr->gamma_table[palette[i].red]; + palette[i].green = png_ptr->gamma_table[palette[i].green]; + palette[i].blue = png_ptr->gamma_table[palette[i].blue]; + } + } +#ifdef PNG_READ_BACKGROUND_SUPPORTED + else +#endif +#endif +#ifdef PNG_READ_BACKGROUND_SUPPORTED + if (png_ptr->transformations & PNG_BACKGROUND) + { + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + { + png_color back; + + back.red = (png_byte)png_ptr->background.red; + back.green = (png_byte)png_ptr->background.green; + back.blue = (png_byte)png_ptr->background.blue; + + for (i = 0; i < (int)png_ptr->num_trans; i++) + { + if (png_ptr->trans[i] == 0) + { + palette[i].red = back.red; + palette[i].green = back.green; + palette[i].blue = back.blue; + } + else if (png_ptr->trans[i] != 0xff) + { + png_composite(palette[i].red, png_ptr->palette[i].red, + png_ptr->trans[i], back.red); + png_composite(palette[i].green, png_ptr->palette[i].green, + png_ptr->trans[i], back.green); + png_composite(palette[i].blue, png_ptr->palette[i].blue, + png_ptr->trans[i], back.blue); + } + } + } + else /* Assume grayscale palette (what else could it be?) */ + { + int i; + + for (i = 0; i < num_palette; i++) + { + if (i == (png_byte)png_ptr->trans_values.gray) + { + palette[i].red = (png_byte)png_ptr->background.red; + palette[i].green = (png_byte)png_ptr->background.green; + palette[i].blue = (png_byte)png_ptr->background.blue; + } + } + } + } +#endif +} +#endif + +#ifdef PNG_READ_BACKGROUND_SUPPORTED +/* Replace any alpha or transparency with the supplied background color. + * "background" is already in the screen gamma, while "background_1" is + * at a gamma of 1.0. Paletted files have already been taken care of. + */ +void /* PRIVATE */ +png_do_background(png_row_infop row_info, png_bytep row, + png_color_16p trans_values, png_color_16p background +#ifdef PNG_READ_GAMMA_SUPPORTED + , png_color_16p background_1, + png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1, + png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1, + png_uint_16pp gamma_16_to_1, int gamma_shift +#endif + ) +{ + png_bytep sp, dp; + png_uint_32 i; + png_uint_32 row_width=row_info->width; + int shift; + + png_debug(1, "in png_do_background"); + + if (background != NULL && +#ifdef PNG_USELESS_TESTS_SUPPORTED + row != NULL && row_info != NULL && +#endif + (!(row_info->color_type & PNG_COLOR_MASK_ALPHA) || + (row_info->color_type != PNG_COLOR_TYPE_PALETTE && trans_values))) + { + switch (row_info->color_type) + { + case PNG_COLOR_TYPE_GRAY: + { + switch (row_info->bit_depth) + { + case 1: + { + sp = row; + shift = 7; + for (i = 0; i < row_width; i++) + { + if ((png_uint_16)((*sp >> shift) & 0x01) + == trans_values->gray) + { + *sp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff); + *sp |= (png_byte)(background->gray << shift); + } + if (!shift) + { + shift = 7; + sp++; + } + else + shift--; + } + break; + } + + case 2: + { +#ifdef PNG_READ_GAMMA_SUPPORTED + if (gamma_table != NULL) + { + sp = row; + shift = 6; + for (i = 0; i < row_width; i++) + { + if ((png_uint_16)((*sp >> shift) & 0x03) + == trans_values->gray) + { + *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff); + *sp |= (png_byte)(background->gray << shift); + } + else + { + png_byte p = (png_byte)((*sp >> shift) & 0x03); + png_byte g = (png_byte)((gamma_table [p | (p << 2) | + (p << 4) | (p << 6)] >> 6) & 0x03); + *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff); + *sp |= (png_byte)(g << shift); + } + if (!shift) + { + shift = 6; + sp++; + } + else + shift -= 2; + } + } + else +#endif + { + sp = row; + shift = 6; + for (i = 0; i < row_width; i++) + { + if ((png_uint_16)((*sp >> shift) & 0x03) + == trans_values->gray) + { + *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff); + *sp |= (png_byte)(background->gray << shift); + } + if (!shift) + { + shift = 6; + sp++; + } + else + shift -= 2; + } + } + break; + } + + case 4: + { +#ifdef PNG_READ_GAMMA_SUPPORTED + if (gamma_table != NULL) + { + sp = row; + shift = 4; + for (i = 0; i < row_width; i++) + { + if ((png_uint_16)((*sp >> shift) & 0x0f) + == trans_values->gray) + { + *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff); + *sp |= (png_byte)(background->gray << shift); + } + else + { + png_byte p = (png_byte)((*sp >> shift) & 0x0f); + png_byte g = (png_byte)((gamma_table[p | + (p << 4)] >> 4) & 0x0f); + *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff); + *sp |= (png_byte)(g << shift); + } + if (!shift) + { + shift = 4; + sp++; + } + else + shift -= 4; + } + } + else +#endif + { + sp = row; + shift = 4; + for (i = 0; i < row_width; i++) + { + if ((png_uint_16)((*sp >> shift) & 0x0f) + == trans_values->gray) + { + *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff); + *sp |= (png_byte)(background->gray << shift); + } + if (!shift) + { + shift = 4; + sp++; + } + else + shift -= 4; + } + } + break; + } + + case 8: + { +#ifdef PNG_READ_GAMMA_SUPPORTED + if (gamma_table != NULL) + { + sp = row; + for (i = 0; i < row_width; i++, sp++) + { + if (*sp == trans_values->gray) + { + *sp = (png_byte)background->gray; + } + else + { + *sp = gamma_table[*sp]; + } + } + } + else +#endif + { + sp = row; + for (i = 0; i < row_width; i++, sp++) + { + if (*sp == trans_values->gray) + { + *sp = (png_byte)background->gray; + } + } + } + break; + } + + case 16: + { +#ifdef PNG_READ_GAMMA_SUPPORTED + if (gamma_16 != NULL) + { + sp = row; + for (i = 0; i < row_width; i++, sp += 2) + { + png_uint_16 v; + + v = (png_uint_16)(((*sp) << 8) + *(sp + 1)); + if (v == trans_values->gray) + { + /* Background is already in screen gamma */ + *sp = (png_byte)((background->gray >> 8) & 0xff); + *(sp + 1) = (png_byte)(background->gray & 0xff); + } + else + { + v = gamma_16[*(sp + 1) >> gamma_shift][*sp]; + *sp = (png_byte)((v >> 8) & 0xff); + *(sp + 1) = (png_byte)(v & 0xff); + } + } + } + else +#endif + { + sp = row; + for (i = 0; i < row_width; i++, sp += 2) + { + png_uint_16 v; + + v = (png_uint_16)(((*sp) << 8) + *(sp + 1)); + if (v == trans_values->gray) + { + *sp = (png_byte)((background->gray >> 8) & 0xff); + *(sp + 1) = (png_byte)(background->gray & 0xff); + } + } + } + break; + } + } + break; + } + + case PNG_COLOR_TYPE_RGB: + { + if (row_info->bit_depth == 8) + { +#ifdef PNG_READ_GAMMA_SUPPORTED + if (gamma_table != NULL) + { + sp = row; + for (i = 0; i < row_width; i++, sp += 3) + { + if (*sp == trans_values->red && + *(sp + 1) == trans_values->green && + *(sp + 2) == trans_values->blue) + { + *sp = (png_byte)background->red; + *(sp + 1) = (png_byte)background->green; + *(sp + 2) = (png_byte)background->blue; + } + else + { + *sp = gamma_table[*sp]; + *(sp + 1) = gamma_table[*(sp + 1)]; + *(sp + 2) = gamma_table[*(sp + 2)]; + } + } + } + else +#endif + { + sp = row; + for (i = 0; i < row_width; i++, sp += 3) + { + if (*sp == trans_values->red && + *(sp + 1) == trans_values->green && + *(sp + 2) == trans_values->blue) + { + *sp = (png_byte)background->red; + *(sp + 1) = (png_byte)background->green; + *(sp + 2) = (png_byte)background->blue; + } + } + } + } + else /* if (row_info->bit_depth == 16) */ + { +#ifdef PNG_READ_GAMMA_SUPPORTED + if (gamma_16 != NULL) + { + sp = row; + for (i = 0; i < row_width; i++, sp += 6) + { + png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1)); + png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3)); + png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5)); + if (r == trans_values->red && g == trans_values->green && + b == trans_values->blue) + { + /* Background is already in screen gamma */ + *sp = (png_byte)((background->red >> 8) & 0xff); + *(sp + 1) = (png_byte)(background->red & 0xff); + *(sp + 2) = (png_byte)((background->green >> 8) & 0xff); + *(sp + 3) = (png_byte)(background->green & 0xff); + *(sp + 4) = (png_byte)((background->blue >> 8) & 0xff); + *(sp + 5) = (png_byte)(background->blue & 0xff); + } + else + { + png_uint_16 v = gamma_16[*(sp + 1) >> gamma_shift][*sp]; + *sp = (png_byte)((v >> 8) & 0xff); + *(sp + 1) = (png_byte)(v & 0xff); + v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)]; + *(sp + 2) = (png_byte)((v >> 8) & 0xff); + *(sp + 3) = (png_byte)(v & 0xff); + v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)]; + *(sp + 4) = (png_byte)((v >> 8) & 0xff); + *(sp + 5) = (png_byte)(v & 0xff); + } + } + } + else +#endif + { + sp = row; + for (i = 0; i < row_width; i++, sp += 6) + { + png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp+1)); + png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3)); + png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5)); + + if (r == trans_values->red && g == trans_values->green && + b == trans_values->blue) + { + *sp = (png_byte)((background->red >> 8) & 0xff); + *(sp + 1) = (png_byte)(background->red & 0xff); + *(sp + 2) = (png_byte)((background->green >> 8) & 0xff); + *(sp + 3) = (png_byte)(background->green & 0xff); + *(sp + 4) = (png_byte)((background->blue >> 8) & 0xff); + *(sp + 5) = (png_byte)(background->blue & 0xff); + } + } + } + } + break; + } + + case PNG_COLOR_TYPE_GRAY_ALPHA: + { + if (row_info->bit_depth == 8) + { +#ifdef PNG_READ_GAMMA_SUPPORTED + if (gamma_to_1 != NULL && gamma_from_1 != NULL && + gamma_table != NULL) + { + sp = row; + dp = row; + for (i = 0; i < row_width; i++, sp += 2, dp++) + { + png_uint_16 a = *(sp + 1); + + if (a == 0xff) + { + *dp = gamma_table[*sp]; + } + else if (a == 0) + { + /* Background is already in screen gamma */ + *dp = (png_byte)background->gray; + } + else + { + png_byte v, w; + + v = gamma_to_1[*sp]; + png_composite(w, v, a, background_1->gray); + *dp = gamma_from_1[w]; + } + } + } + else +#endif + { + sp = row; + dp = row; + for (i = 0; i < row_width; i++, sp += 2, dp++) + { + png_byte a = *(sp + 1); + + if (a == 0xff) + { + *dp = *sp; + } +#ifdef PNG_READ_GAMMA_SUPPORTED + else if (a == 0) + { + *dp = (png_byte)background->gray; + } + else + { + png_composite(*dp, *sp, a, background_1->gray); + } +#else + *dp = (png_byte)background->gray; +#endif + } + } + } + else /* if (png_ptr->bit_depth == 16) */ + { +#ifdef PNG_READ_GAMMA_SUPPORTED + if (gamma_16 != NULL && gamma_16_from_1 != NULL && + gamma_16_to_1 != NULL) + { + sp = row; + dp = row; + for (i = 0; i < row_width; i++, sp += 4, dp += 2) + { + png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3)); + + if (a == (png_uint_16)0xffff) + { + png_uint_16 v; + + v = gamma_16[*(sp + 1) >> gamma_shift][*sp]; + *dp = (png_byte)((v >> 8) & 0xff); + *(dp + 1) = (png_byte)(v & 0xff); + } +#ifdef PNG_READ_GAMMA_SUPPORTED + else if (a == 0) +#else + else +#endif + { + /* Background is already in screen gamma */ + *dp = (png_byte)((background->gray >> 8) & 0xff); + *(dp + 1) = (png_byte)(background->gray & 0xff); + } +#ifdef PNG_READ_GAMMA_SUPPORTED + else + { + png_uint_16 g, v, w; + + g = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp]; + png_composite_16(v, g, a, background_1->gray); + w = gamma_16_from_1[(v&0xff) >> gamma_shift][v >> 8]; + *dp = (png_byte)((w >> 8) & 0xff); + *(dp + 1) = (png_byte)(w & 0xff); + } +#endif + } + } + else +#endif + { + sp = row; + dp = row; + for (i = 0; i < row_width; i++, sp += 4, dp += 2) + { + png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3)); + if (a == (png_uint_16)0xffff) + { + png_memcpy(dp, sp, 2); + } +#ifdef PNG_READ_GAMMA_SUPPORTED + else if (a == 0) +#else + else +#endif + { + *dp = (png_byte)((background->gray >> 8) & 0xff); + *(dp + 1) = (png_byte)(background->gray & 0xff); + } +#ifdef PNG_READ_GAMMA_SUPPORTED + else + { + png_uint_16 g, v; + + g = (png_uint_16)(((*sp) << 8) + *(sp + 1)); + png_composite_16(v, g, a, background_1->gray); + *dp = (png_byte)((v >> 8) & 0xff); + *(dp + 1) = (png_byte)(v & 0xff); + } +#endif + } + } + } + break; + } + + case PNG_COLOR_TYPE_RGB_ALPHA: + { + if (row_info->bit_depth == 8) + { +#ifdef PNG_READ_GAMMA_SUPPORTED + if (gamma_to_1 != NULL && gamma_from_1 != NULL && + gamma_table != NULL) + { + sp = row; + dp = row; + for (i = 0; i < row_width; i++, sp += 4, dp += 3) + { + png_byte a = *(sp + 3); + + if (a == 0xff) + { + *dp = gamma_table[*sp]; + *(dp + 1) = gamma_table[*(sp + 1)]; + *(dp + 2) = gamma_table[*(sp + 2)]; + } + else if (a == 0) + { + /* Background is already in screen gamma */ + *dp = (png_byte)background->red; + *(dp + 1) = (png_byte)background->green; + *(dp + 2) = (png_byte)background->blue; + } + else + { + png_byte v, w; + + v = gamma_to_1[*sp]; + png_composite(w, v, a, background_1->red); + *dp = gamma_from_1[w]; + v = gamma_to_1[*(sp + 1)]; + png_composite(w, v, a, background_1->green); + *(dp + 1) = gamma_from_1[w]; + v = gamma_to_1[*(sp + 2)]; + png_composite(w, v, a, background_1->blue); + *(dp + 2) = gamma_from_1[w]; + } + } + } + else +#endif + { + sp = row; + dp = row; + for (i = 0; i < row_width; i++, sp += 4, dp += 3) + { + png_byte a = *(sp + 3); + + if (a == 0xff) + { + *dp = *sp; + *(dp + 1) = *(sp + 1); + *(dp + 2) = *(sp + 2); + } + else if (a == 0) + { + *dp = (png_byte)background->red; + *(dp + 1) = (png_byte)background->green; + *(dp + 2) = (png_byte)background->blue; + } + else + { + png_composite(*dp, *sp, a, background->red); + png_composite(*(dp + 1), *(sp + 1), a, + background->green); + png_composite(*(dp + 2), *(sp + 2), a, + background->blue); + } + } + } + } + else /* if (row_info->bit_depth == 16) */ + { +#ifdef PNG_READ_GAMMA_SUPPORTED + if (gamma_16 != NULL && gamma_16_from_1 != NULL && + gamma_16_to_1 != NULL) + { + sp = row; + dp = row; + for (i = 0; i < row_width; i++, sp += 8, dp += 6) + { + png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6)) + << 8) + (png_uint_16)(*(sp + 7))); + if (a == (png_uint_16)0xffff) + { + png_uint_16 v; + + v = gamma_16[*(sp + 1) >> gamma_shift][*sp]; + *dp = (png_byte)((v >> 8) & 0xff); + *(dp + 1) = (png_byte)(v & 0xff); + v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)]; + *(dp + 2) = (png_byte)((v >> 8) & 0xff); + *(dp + 3) = (png_byte)(v & 0xff); + v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)]; + *(dp + 4) = (png_byte)((v >> 8) & 0xff); + *(dp + 5) = (png_byte)(v & 0xff); + } + else if (a == 0) + { + /* Background is already in screen gamma */ + *dp = (png_byte)((background->red >> 8) & 0xff); + *(dp + 1) = (png_byte)(background->red & 0xff); + *(dp + 2) = (png_byte)((background->green >> 8) & 0xff); + *(dp + 3) = (png_byte)(background->green & 0xff); + *(dp + 4) = (png_byte)((background->blue >> 8) & 0xff); + *(dp + 5) = (png_byte)(background->blue & 0xff); + } + else + { + png_uint_16 v, w, x; + + v = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp]; + png_composite_16(w, v, a, background_1->red); + x = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8]; + *dp = (png_byte)((x >> 8) & 0xff); + *(dp + 1) = (png_byte)(x & 0xff); + v = gamma_16_to_1[*(sp + 3) >> gamma_shift][*(sp + 2)]; + png_composite_16(w, v, a, background_1->green); + x = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8]; + *(dp + 2) = (png_byte)((x >> 8) & 0xff); + *(dp + 3) = (png_byte)(x & 0xff); + v = gamma_16_to_1[*(sp + 5) >> gamma_shift][*(sp + 4)]; + png_composite_16(w, v, a, background_1->blue); + x = gamma_16_from_1[(w & 0xff) >> gamma_shift][w >> 8]; + *(dp + 4) = (png_byte)((x >> 8) & 0xff); + *(dp + 5) = (png_byte)(x & 0xff); + } + } + } + else +#endif + { + sp = row; + dp = row; + for (i = 0; i < row_width; i++, sp += 8, dp += 6) + { + png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6)) + << 8) + (png_uint_16)(*(sp + 7))); + if (a == (png_uint_16)0xffff) + { + png_memcpy(dp, sp, 6); + } + else if (a == 0) + { + *dp = (png_byte)((background->red >> 8) & 0xff); + *(dp + 1) = (png_byte)(background->red & 0xff); + *(dp + 2) = (png_byte)((background->green >> 8) & 0xff); + *(dp + 3) = (png_byte)(background->green & 0xff); + *(dp + 4) = (png_byte)((background->blue >> 8) & 0xff); + *(dp + 5) = (png_byte)(background->blue & 0xff); + } + else + { + png_uint_16 v; + + png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1)); + png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8) + + *(sp + 3)); + png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8) + + *(sp + 5)); + + png_composite_16(v, r, a, background->red); + *dp = (png_byte)((v >> 8) & 0xff); + *(dp + 1) = (png_byte)(v & 0xff); + png_composite_16(v, g, a, background->green); + *(dp + 2) = (png_byte)((v >> 8) & 0xff); + *(dp + 3) = (png_byte)(v & 0xff); + png_composite_16(v, b, a, background->blue); + *(dp + 4) = (png_byte)((v >> 8) & 0xff); + *(dp + 5) = (png_byte)(v & 0xff); + } + } + } + } + break; + } + } + + if (row_info->color_type & PNG_COLOR_MASK_ALPHA) + { + row_info->color_type &= ~PNG_COLOR_MASK_ALPHA; + row_info->channels--; + row_info->pixel_depth = (png_byte)(row_info->channels * + row_info->bit_depth); + row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width); + } + } +} +#endif + +#ifdef PNG_READ_GAMMA_SUPPORTED +/* Gamma correct the image, avoiding the alpha channel. Make sure + * you do this after you deal with the transparency issue on grayscale + * or RGB images. If your bit depth is 8, use gamma_table, if it + * is 16, use gamma_16_table and gamma_shift. Build these with + * build_gamma_table(). + */ +void /* PRIVATE */ +png_do_gamma(png_row_infop row_info, png_bytep row, + png_bytep gamma_table, png_uint_16pp gamma_16_table, + int gamma_shift) +{ + png_bytep sp; + png_uint_32 i; + png_uint_32 row_width=row_info->width; + + png_debug(1, "in png_do_gamma"); + + if ( +#ifdef PNG_USELESS_TESTS_SUPPORTED + row != NULL && row_info != NULL && +#endif + ((row_info->bit_depth <= 8 && gamma_table != NULL) || + (row_info->bit_depth == 16 && gamma_16_table != NULL))) + { + switch (row_info->color_type) + { + case PNG_COLOR_TYPE_RGB: + { + if (row_info->bit_depth == 8) + { + sp = row; + for (i = 0; i < row_width; i++) + { + *sp = gamma_table[*sp]; + sp++; + *sp = gamma_table[*sp]; + sp++; + *sp = gamma_table[*sp]; + sp++; + } + } + else /* if (row_info->bit_depth == 16) */ + { + sp = row; + for (i = 0; i < row_width; i++) + { + png_uint_16 v; + + v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp]; + *sp = (png_byte)((v >> 8) & 0xff); + *(sp + 1) = (png_byte)(v & 0xff); + sp += 2; + v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp]; + *sp = (png_byte)((v >> 8) & 0xff); + *(sp + 1) = (png_byte)(v & 0xff); + sp += 2; + v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp]; + *sp = (png_byte)((v >> 8) & 0xff); + *(sp + 1) = (png_byte)(v & 0xff); + sp += 2; + } + } + break; + } + + case PNG_COLOR_TYPE_RGB_ALPHA: + { + if (row_info->bit_depth == 8) + { + sp = row; + for (i = 0; i < row_width; i++) + { + *sp = gamma_table[*sp]; + sp++; + *sp = gamma_table[*sp]; + sp++; + *sp = gamma_table[*sp]; + sp++; + sp++; + } + } + else /* if (row_info->bit_depth == 16) */ + { + sp = row; + for (i = 0; i < row_width; i++) + { + png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp]; + *sp = (png_byte)((v >> 8) & 0xff); + *(sp + 1) = (png_byte)(v & 0xff); + sp += 2; + v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp]; + *sp = (png_byte)((v >> 8) & 0xff); + *(sp + 1) = (png_byte)(v & 0xff); + sp += 2; + v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp]; + *sp = (png_byte)((v >> 8) & 0xff); + *(sp + 1) = (png_byte)(v & 0xff); + sp += 4; + } + } + break; + } + + case PNG_COLOR_TYPE_GRAY_ALPHA: + { + if (row_info->bit_depth == 8) + { + sp = row; + for (i = 0; i < row_width; i++) + { + *sp = gamma_table[*sp]; + sp += 2; + } + } + else /* if (row_info->bit_depth == 16) */ + { + sp = row; + for (i = 0; i < row_width; i++) + { + png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp]; + *sp = (png_byte)((v >> 8) & 0xff); + *(sp + 1) = (png_byte)(v & 0xff); + sp += 4; + } + } + break; + } + + case PNG_COLOR_TYPE_GRAY: + { + if (row_info->bit_depth == 2) + { + sp = row; + for (i = 0; i < row_width; i += 4) + { + int a = *sp & 0xc0; + int b = *sp & 0x30; + int c = *sp & 0x0c; + int d = *sp & 0x03; + + *sp = (png_byte)( + ((((int)gamma_table[a|(a>>2)|(a>>4)|(a>>6)]) ) & 0xc0)| + ((((int)gamma_table[(b<<2)|b|(b>>2)|(b>>4)])>>2) & 0x30)| + ((((int)gamma_table[(c<<4)|(c<<2)|c|(c>>2)])>>4) & 0x0c)| + ((((int)gamma_table[(d<<6)|(d<<4)|(d<<2)|d])>>6) )); + sp++; + } + } + + if (row_info->bit_depth == 4) + { + sp = row; + for (i = 0; i < row_width; i += 2) + { + int msb = *sp & 0xf0; + int lsb = *sp & 0x0f; + + *sp = (png_byte)((((int)gamma_table[msb | (msb >> 4)]) & 0xf0) + | (((int)gamma_table[(lsb << 4) | lsb]) >> 4)); + sp++; + } + } + + else if (row_info->bit_depth == 8) + { + sp = row; + for (i = 0; i < row_width; i++) + { + *sp = gamma_table[*sp]; + sp++; + } + } + + else if (row_info->bit_depth == 16) + { + sp = row; + for (i = 0; i < row_width; i++) + { + png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp]; + *sp = (png_byte)((v >> 8) & 0xff); + *(sp + 1) = (png_byte)(v & 0xff); + sp += 2; + } + } + break; + } + } + } +} +#endif + +#ifdef PNG_READ_EXPAND_SUPPORTED +/* Expands a palette row to an RGB or RGBA row depending + * upon whether you supply trans and num_trans. + */ +void /* PRIVATE */ +png_do_expand_palette(png_row_infop row_info, png_bytep row, + png_colorp palette, png_bytep trans, int num_trans) +{ + int shift, value; + png_bytep sp, dp; + png_uint_32 i; + png_uint_32 row_width=row_info->width; + + png_debug(1, "in png_do_expand_palette"); + + if ( +#ifdef PNG_USELESS_TESTS_SUPPORTED + row != NULL && row_info != NULL && +#endif + row_info->color_type == PNG_COLOR_TYPE_PALETTE) + { + if (row_info->bit_depth < 8) + { + switch (row_info->bit_depth) + { + case 1: + { + sp = row + (png_size_t)((row_width - 1) >> 3); + dp = row + (png_size_t)row_width - 1; + shift = 7 - (int)((row_width + 7) & 0x07); + for (i = 0; i < row_width; i++) + { + if ((*sp >> shift) & 0x01) + *dp = 1; + else + *dp = 0; + if (shift == 7) + { + shift = 0; + sp--; + } + else + shift++; + + dp--; + } + break; + } + + case 2: + { + sp = row + (png_size_t)((row_width - 1) >> 2); + dp = row + (png_size_t)row_width - 1; + shift = (int)((3 - ((row_width + 3) & 0x03)) << 1); + for (i = 0; i < row_width; i++) + { + value = (*sp >> shift) & 0x03; + *dp = (png_byte)value; + if (shift == 6) + { + shift = 0; + sp--; + } + else + shift += 2; + + dp--; + } + break; + } + + case 4: + { + sp = row + (png_size_t)((row_width - 1) >> 1); + dp = row + (png_size_t)row_width - 1; + shift = (int)((row_width & 0x01) << 2); + for (i = 0; i < row_width; i++) + { + value = (*sp >> shift) & 0x0f; + *dp = (png_byte)value; + if (shift == 4) + { + shift = 0; + sp--; + } + else + shift += 4; + + dp--; + } + break; + } + } + row_info->bit_depth = 8; + row_info->pixel_depth = 8; + row_info->rowbytes = row_width; + } + switch (row_info->bit_depth) + { + case 8: + { + if (trans != NULL) + { + sp = row + (png_size_t)row_width - 1; + dp = row + (png_size_t)(row_width << 2) - 1; + + for (i = 0; i < row_width; i++) + { + if ((int)(*sp) >= num_trans) + *dp-- = 0xff; + else + *dp-- = trans[*sp]; + *dp-- = palette[*sp].blue; + *dp-- = palette[*sp].green; + *dp-- = palette[*sp].red; + sp--; + } + row_info->bit_depth = 8; + row_info->pixel_depth = 32; + row_info->rowbytes = row_width * 4; + row_info->color_type = 6; + row_info->channels = 4; + } + else + { + sp = row + (png_size_t)row_width - 1; + dp = row + (png_size_t)(row_width * 3) - 1; + + for (i = 0; i < row_width; i++) + { + *dp-- = palette[*sp].blue; + *dp-- = palette[*sp].green; + *dp-- = palette[*sp].red; + sp--; + } + + row_info->bit_depth = 8; + row_info->pixel_depth = 24; + row_info->rowbytes = row_width * 3; + row_info->color_type = 2; + row_info->channels = 3; + } + break; + } + } + } +} + +/* If the bit depth < 8, it is expanded to 8. Also, if the already + * expanded transparency value is supplied, an alpha channel is built. + */ +void /* PRIVATE */ +png_do_expand(png_row_infop row_info, png_bytep row, + png_color_16p trans_value) +{ + int shift, value; + png_bytep sp, dp; + png_uint_32 i; + png_uint_32 row_width=row_info->width; + + png_debug(1, "in png_do_expand"); + +#ifdef PNG_USELESS_TESTS_SUPPORTED + if (row != NULL && row_info != NULL) +#endif + { + if (row_info->color_type == PNG_COLOR_TYPE_GRAY) + { + png_uint_16 gray = (png_uint_16)(trans_value ? trans_value->gray : 0); + + if (row_info->bit_depth < 8) + { + switch (row_info->bit_depth) + { + case 1: + { + gray = (png_uint_16)((gray&0x01)*0xff); + sp = row + (png_size_t)((row_width - 1) >> 3); + dp = row + (png_size_t)row_width - 1; + shift = 7 - (int)((row_width + 7) & 0x07); + for (i = 0; i < row_width; i++) + { + if ((*sp >> shift) & 0x01) + *dp = 0xff; + else + *dp = 0; + if (shift == 7) + { + shift = 0; + sp--; + } + else + shift++; + + dp--; + } + break; + } + + case 2: + { + gray = (png_uint_16)((gray&0x03)*0x55); + sp = row + (png_size_t)((row_width - 1) >> 2); + dp = row + (png_size_t)row_width - 1; + shift = (int)((3 - ((row_width + 3) & 0x03)) << 1); + for (i = 0; i < row_width; i++) + { + value = (*sp >> shift) & 0x03; + *dp = (png_byte)(value | (value << 2) | (value << 4) | + (value << 6)); + if (shift == 6) + { + shift = 0; + sp--; + } + else + shift += 2; + + dp--; + } + break; + } + + case 4: + { + gray = (png_uint_16)((gray&0x0f)*0x11); + sp = row + (png_size_t)((row_width - 1) >> 1); + dp = row + (png_size_t)row_width - 1; + shift = (int)((1 - ((row_width + 1) & 0x01)) << 2); + for (i = 0; i < row_width; i++) + { + value = (*sp >> shift) & 0x0f; + *dp = (png_byte)(value | (value << 4)); + if (shift == 4) + { + shift = 0; + sp--; + } + else + shift = 4; + + dp--; + } + break; + } + } + + row_info->bit_depth = 8; + row_info->pixel_depth = 8; + row_info->rowbytes = row_width; + } + + if (trans_value != NULL) + { + if (row_info->bit_depth == 8) + { + gray = gray & 0xff; + sp = row + (png_size_t)row_width - 1; + dp = row + (png_size_t)(row_width << 1) - 1; + for (i = 0; i < row_width; i++) + { + if (*sp == gray) + *dp-- = 0; + else + *dp-- = 0xff; + *dp-- = *sp--; + } + } + + else if (row_info->bit_depth == 16) + { + png_byte gray_high = (gray >> 8) & 0xff; + png_byte gray_low = gray & 0xff; + sp = row + row_info->rowbytes - 1; + dp = row + (row_info->rowbytes << 1) - 1; + for (i = 0; i < row_width; i++) + { + if (*(sp - 1) == gray_high && *(sp) == gray_low) + { + *dp-- = 0; + *dp-- = 0; + } + else + { + *dp-- = 0xff; + *dp-- = 0xff; + } + *dp-- = *sp--; + *dp-- = *sp--; + } + } + + row_info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA; + row_info->channels = 2; + row_info->pixel_depth = (png_byte)(row_info->bit_depth << 1); + row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, + row_width); + } + } + else if (row_info->color_type == PNG_COLOR_TYPE_RGB && trans_value) + { + if (row_info->bit_depth == 8) + { + png_byte red = trans_value->red & 0xff; + png_byte green = trans_value->green & 0xff; + png_byte blue = trans_value->blue & 0xff; + sp = row + (png_size_t)row_info->rowbytes - 1; + dp = row + (png_size_t)(row_width << 2) - 1; + for (i = 0; i < row_width; i++) + { + if (*(sp - 2) == red && *(sp - 1) == green && *(sp) == blue) + *dp-- = 0; + else + *dp-- = 0xff; + *dp-- = *sp--; + *dp-- = *sp--; + *dp-- = *sp--; + } + } + else if (row_info->bit_depth == 16) + { + png_byte red_high = (trans_value->red >> 8) & 0xff; + png_byte green_high = (trans_value->green >> 8) & 0xff; + png_byte blue_high = (trans_value->blue >> 8) & 0xff; + png_byte red_low = trans_value->red & 0xff; + png_byte green_low = trans_value->green & 0xff; + png_byte blue_low = trans_value->blue & 0xff; + sp = row + row_info->rowbytes - 1; + dp = row + (png_size_t)(row_width << 3) - 1; + for (i = 0; i < row_width; i++) + { + if (*(sp - 5) == red_high && + *(sp - 4) == red_low && + *(sp - 3) == green_high && + *(sp - 2) == green_low && + *(sp - 1) == blue_high && + *(sp ) == blue_low) + { + *dp-- = 0; + *dp-- = 0; + } + else + { + *dp-- = 0xff; + *dp-- = 0xff; + } + *dp-- = *sp--; + *dp-- = *sp--; + *dp-- = *sp--; + *dp-- = *sp--; + *dp-- = *sp--; + *dp-- = *sp--; + } + } + row_info->color_type = PNG_COLOR_TYPE_RGB_ALPHA; + row_info->channels = 4; + row_info->pixel_depth = (png_byte)(row_info->bit_depth << 2); + row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width); + } + } +} +#endif + +#ifdef PNG_READ_DITHER_SUPPORTED +void /* PRIVATE */ +png_do_dither(png_row_infop row_info, png_bytep row, + png_bytep palette_lookup, png_bytep dither_lookup) +{ + png_bytep sp, dp; + png_uint_32 i; + png_uint_32 row_width=row_info->width; + + png_debug(1, "in png_do_dither"); + +#ifdef PNG_USELESS_TESTS_SUPPORTED + if (row != NULL && row_info != NULL) +#endif + { + if (row_info->color_type == PNG_COLOR_TYPE_RGB && + palette_lookup && row_info->bit_depth == 8) + { + int r, g, b, p; + sp = row; + dp = row; + for (i = 0; i < row_width; i++) + { + r = *sp++; + g = *sp++; + b = *sp++; + + /* This looks real messy, but the compiler will reduce + * it down to a reasonable formula. For example, with + * 5 bits per color, we get: + * p = (((r >> 3) & 0x1f) << 10) | + * (((g >> 3) & 0x1f) << 5) | + * ((b >> 3) & 0x1f); + */ + p = (((r >> (8 - PNG_DITHER_RED_BITS)) & + ((1 << PNG_DITHER_RED_BITS) - 1)) << + (PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) | + (((g >> (8 - PNG_DITHER_GREEN_BITS)) & + ((1 << PNG_DITHER_GREEN_BITS) - 1)) << + (PNG_DITHER_BLUE_BITS)) | + ((b >> (8 - PNG_DITHER_BLUE_BITS)) & + ((1 << PNG_DITHER_BLUE_BITS) - 1)); + + *dp++ = palette_lookup[p]; + } + row_info->color_type = PNG_COLOR_TYPE_PALETTE; + row_info->channels = 1; + row_info->pixel_depth = row_info->bit_depth; + row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width); + } + else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA && + palette_lookup != NULL && row_info->bit_depth == 8) + { + int r, g, b, p; + sp = row; + dp = row; + for (i = 0; i < row_width; i++) + { + r = *sp++; + g = *sp++; + b = *sp++; + sp++; + + p = (((r >> (8 - PNG_DITHER_RED_BITS)) & + ((1 << PNG_DITHER_RED_BITS) - 1)) << + (PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) | + (((g >> (8 - PNG_DITHER_GREEN_BITS)) & + ((1 << PNG_DITHER_GREEN_BITS) - 1)) << + (PNG_DITHER_BLUE_BITS)) | + ((b >> (8 - PNG_DITHER_BLUE_BITS)) & + ((1 << PNG_DITHER_BLUE_BITS) - 1)); + + *dp++ = palette_lookup[p]; + } + row_info->color_type = PNG_COLOR_TYPE_PALETTE; + row_info->channels = 1; + row_info->pixel_depth = row_info->bit_depth; + row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width); + } + else if (row_info->color_type == PNG_COLOR_TYPE_PALETTE && + dither_lookup && row_info->bit_depth == 8) + { + sp = row; + for (i = 0; i < row_width; i++, sp++) + { + *sp = dither_lookup[*sp]; + } + } + } +} +#endif + +#ifdef PNG_FLOATING_POINT_SUPPORTED +#ifdef PNG_READ_GAMMA_SUPPORTED +static PNG_CONST int png_gamma_shift[] = + {0x10, 0x21, 0x42, 0x84, 0x110, 0x248, 0x550, 0xff0, 0x00}; + +/* We build the 8- or 16-bit gamma tables here. Note that for 16-bit + * tables, we don't make a full table if we are reducing to 8-bit in + * the future. Note also how the gamma_16 tables are segmented so that + * we don't need to allocate > 64K chunks for a full 16-bit table. + * + * See the PNG extensions document for an integer algorithm for creating + * the gamma tables. Maybe we will implement that here someday. + * + * We should only reach this point if + * + * the file_gamma is known (i.e., the gAMA or sRGB chunk is present, + * or the application has provided a file_gamma) + * + * AND + * { + * the screen_gamma is known + * OR + * + * RGB_to_gray transformation is being performed + * } + * + * AND + * { + * the screen_gamma is different from the reciprocal of the + * file_gamma by more than the specified threshold + * + * OR + * + * a background color has been specified and the file_gamma + * and screen_gamma are not 1.0, within the specified threshold. + * } + */ + +void /* PRIVATE */ +png_build_gamma_table(png_structp png_ptr) +{ + png_debug(1, "in png_build_gamma_table"); + + if (png_ptr->bit_depth <= 8) + { + int i; + double g; + + if (png_ptr->screen_gamma > .000001) + g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma); + + else + g = 1.0; + + png_ptr->gamma_table = (png_bytep)png_malloc(png_ptr, + (png_uint_32)256); + + for (i = 0; i < 256; i++) + { + png_ptr->gamma_table[i] = (png_byte)(pow((double)i / 255.0, + g) * 255.0 + .5); + } + +#if defined(PNG_READ_BACKGROUND_SUPPORTED) || \ + defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) + if (png_ptr->transformations & ((PNG_BACKGROUND) | PNG_RGB_TO_GRAY)) + { + + g = 1.0 / (png_ptr->gamma); + + png_ptr->gamma_to_1 = (png_bytep)png_malloc(png_ptr, + (png_uint_32)256); + + for (i = 0; i < 256; i++) + { + png_ptr->gamma_to_1[i] = (png_byte)(pow((double)i / 255.0, + g) * 255.0 + .5); + } + + + png_ptr->gamma_from_1 = (png_bytep)png_malloc(png_ptr, + (png_uint_32)256); + + if (png_ptr->screen_gamma > 0.000001) + g = 1.0 / png_ptr->screen_gamma; + + else + g = png_ptr->gamma; /* Probably doing rgb_to_gray */ + + for (i = 0; i < 256; i++) + { + png_ptr->gamma_from_1[i] = (png_byte)(pow((double)i / 255.0, + g) * 255.0 + .5); + + } + } +#endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */ + } + else + { + double g; + int i, j, shift, num; + int sig_bit; + png_uint_32 ig; + + if (png_ptr->color_type & PNG_COLOR_MASK_COLOR) + { + sig_bit = (int)png_ptr->sig_bit.red; + + if ((int)png_ptr->sig_bit.green > sig_bit) + sig_bit = png_ptr->sig_bit.green; + + if ((int)png_ptr->sig_bit.blue > sig_bit) + sig_bit = png_ptr->sig_bit.blue; + } + else + { + sig_bit = (int)png_ptr->sig_bit.gray; + } + + if (sig_bit > 0) + shift = 16 - sig_bit; + + else + shift = 0; + + if (png_ptr->transformations & PNG_16_TO_8) + { + if (shift < (16 - PNG_MAX_GAMMA_8)) + shift = (16 - PNG_MAX_GAMMA_8); + } + + if (shift > 8) + shift = 8; + + if (shift < 0) + shift = 0; + + png_ptr->gamma_shift = (png_byte)shift; + + num = (1 << (8 - shift)); + + if (png_ptr->screen_gamma > .000001) + g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma); + else + g = 1.0; + + png_ptr->gamma_16_table = (png_uint_16pp)png_calloc(png_ptr, + (png_uint_32)(num * png_sizeof(png_uint_16p))); + + if (png_ptr->transformations & (PNG_16_TO_8 | PNG_BACKGROUND)) + { + double fin, fout; + png_uint_32 last, max; + + for (i = 0; i < num; i++) + { + png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr, + (png_uint_32)(256 * png_sizeof(png_uint_16))); + } + + g = 1.0 / g; + last = 0; + for (i = 0; i < 256; i++) + { + fout = ((double)i + 0.5) / 256.0; + fin = pow(fout, g); + max = (png_uint_32)(fin * (double)((png_uint_32)num << 8)); + while (last <= max) + { + png_ptr->gamma_16_table[(int)(last & (0xff >> shift))] + [(int)(last >> (8 - shift))] = (png_uint_16)( + (png_uint_16)i | ((png_uint_16)i << 8)); + last++; + } + } + while (last < ((png_uint_32)num << 8)) + { + png_ptr->gamma_16_table[(int)(last & (0xff >> shift))] + [(int)(last >> (8 - shift))] = (png_uint_16)65535L; + last++; + } + } + else + { + for (i = 0; i < num; i++) + { + png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr, + (png_uint_32)(256 * png_sizeof(png_uint_16))); + + ig = (((png_uint_32)i * (png_uint_32)png_gamma_shift[shift]) >> 4); + + for (j = 0; j < 256; j++) + { + png_ptr->gamma_16_table[i][j] = + (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) / + 65535.0, g) * 65535.0 + .5); + } + } + } + +#if defined(PNG_READ_BACKGROUND_SUPPORTED) || \ + defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) + if (png_ptr->transformations & (PNG_BACKGROUND | PNG_RGB_TO_GRAY)) + { + + g = 1.0 / (png_ptr->gamma); + + png_ptr->gamma_16_to_1 = (png_uint_16pp)png_calloc(png_ptr, + (png_uint_32)(num * png_sizeof(png_uint_16p ))); + + for (i = 0; i < num; i++) + { + png_ptr->gamma_16_to_1[i] = (png_uint_16p)png_malloc(png_ptr, + (png_uint_32)(256 * png_sizeof(png_uint_16))); + + ig = (((png_uint_32)i * + (png_uint_32)png_gamma_shift[shift]) >> 4); + for (j = 0; j < 256; j++) + { + png_ptr->gamma_16_to_1[i][j] = + (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) / + 65535.0, g) * 65535.0 + .5); + } + } + + if (png_ptr->screen_gamma > 0.000001) + g = 1.0 / png_ptr->screen_gamma; + + else + g = png_ptr->gamma; /* Probably doing rgb_to_gray */ + + png_ptr->gamma_16_from_1 = (png_uint_16pp)png_calloc(png_ptr, + (png_uint_32)(num * png_sizeof(png_uint_16p))); + + for (i = 0; i < num; i++) + { + png_ptr->gamma_16_from_1[i] = (png_uint_16p)png_malloc(png_ptr, + (png_uint_32)(256 * png_sizeof(png_uint_16))); + + ig = (((png_uint_32)i * + (png_uint_32)png_gamma_shift[shift]) >> 4); + + for (j = 0; j < 256; j++) + { + png_ptr->gamma_16_from_1[i][j] = + (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) / + 65535.0, g) * 65535.0 + .5); + } + } + } +#endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */ + } +} +#endif +/* To do: install integer version of png_build_gamma_table here */ +#endif + +#ifdef PNG_MNG_FEATURES_SUPPORTED +/* Undoes intrapixel differencing */ +void /* PRIVATE */ +png_do_read_intrapixel(png_row_infop row_info, png_bytep row) +{ + png_debug(1, "in png_do_read_intrapixel"); + + if ( +#ifdef PNG_USELESS_TESTS_SUPPORTED + row != NULL && row_info != NULL && +#endif + (row_info->color_type & PNG_COLOR_MASK_COLOR)) + { + int bytes_per_pixel; + png_uint_32 row_width = row_info->width; + if (row_info->bit_depth == 8) + { + png_bytep rp; + png_uint_32 i; + + if (row_info->color_type == PNG_COLOR_TYPE_RGB) + bytes_per_pixel = 3; + + else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + bytes_per_pixel = 4; + + else + return; + + for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel) + { + *(rp) = (png_byte)((256 + *rp + *(rp+1))&0xff); + *(rp+2) = (png_byte)((256 + *(rp+2) + *(rp+1))&0xff); + } + } + else if (row_info->bit_depth == 16) + { + png_bytep rp; + png_uint_32 i; + + if (row_info->color_type == PNG_COLOR_TYPE_RGB) + bytes_per_pixel = 6; + + else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + bytes_per_pixel = 8; + + else + return; + + for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel) + { + png_uint_32 s0 = (*(rp ) << 8) | *(rp + 1); + png_uint_32 s1 = (*(rp + 2) << 8) | *(rp + 3); + png_uint_32 s2 = (*(rp + 4) << 8) | *(rp + 5); + png_uint_32 red = (png_uint_32)((s0 + s1 + 65536L) & 0xffffL); + png_uint_32 blue = (png_uint_32)((s2 + s1 + 65536L) & 0xffffL); + *(rp ) = (png_byte)((red >> 8) & 0xff); + *(rp+1) = (png_byte)(red & 0xff); + *(rp+4) = (png_byte)((blue >> 8) & 0xff); + *(rp+5) = (png_byte)(blue & 0xff); + } + } + } +} +#endif /* PNG_MNG_FEATURES_SUPPORTED */ +#endif /* PNG_READ_SUPPORTED */ diff --git a/libs/libpng-src/pngrutil.c b/libs/libpng-src/pngrutil.c new file mode 100644 index 000000000..eec8d1024 --- /dev/null +++ b/libs/libpng-src/pngrutil.c @@ -0,0 +1,3633 @@ + +/* pngrutil.c - utilities to read a PNG file + * + * Last changed in libpng 1.2.45 [July 7, 2011] + * Copyright (c) 1998-2011 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + * + * This file contains routines that are only called from within + * libpng itself during the course of reading an image. + */ + +#define PNG_INTERNAL +#define PNG_NO_PEDANTIC_WARNINGS +#include "png.h" +#ifdef PNG_READ_SUPPORTED + +#if defined(_WIN32_WCE) && (_WIN32_WCE<0x500) +# define WIN32_WCE_OLD +#endif + +#ifdef PNG_FLOATING_POINT_SUPPORTED +# ifdef WIN32_WCE_OLD +/* The strtod() function is not supported on WindowsCE */ +__inline double png_strtod(png_structp png_ptr, PNG_CONST char *nptr, + char **endptr) +{ + double result = 0; + int len; + wchar_t *str, *end; + + len = MultiByteToWideChar(CP_ACP, 0, nptr, -1, NULL, 0); + str = (wchar_t *)png_malloc(png_ptr, len * png_sizeof(wchar_t)); + if ( NULL != str ) + { + MultiByteToWideChar(CP_ACP, 0, nptr, -1, str, len); + result = wcstod(str, &end); + len = WideCharToMultiByte(CP_ACP, 0, end, -1, NULL, 0, NULL, NULL); + *endptr = (char *)nptr + (png_strlen(nptr) - len + 1); + png_free(png_ptr, str); + } + return result; +} +# else +# define png_strtod(p,a,b) strtod(a,b) +# endif +#endif + +png_uint_32 PNGAPI +png_get_uint_31(png_structp png_ptr, png_bytep buf) +{ +#ifdef PNG_READ_BIG_ENDIAN_SUPPORTED + png_uint_32 i = png_get_uint_32(buf); +#else + /* Avoid an extra function call by inlining the result. */ + png_uint_32 i = ((png_uint_32)(*buf) << 24) + + ((png_uint_32)(*(buf + 1)) << 16) + + ((png_uint_32)(*(buf + 2)) << 8) + + (png_uint_32)(*(buf + 3)); +#endif + if (i > PNG_UINT_31_MAX) + png_error(png_ptr, "PNG unsigned integer out of range."); + return (i); +} +#ifndef PNG_READ_BIG_ENDIAN_SUPPORTED +/* Grab an unsigned 32-bit integer from a buffer in big-endian format. */ +png_uint_32 PNGAPI +png_get_uint_32(png_bytep buf) +{ + png_uint_32 i = ((png_uint_32)(*buf) << 24) + + ((png_uint_32)(*(buf + 1)) << 16) + + ((png_uint_32)(*(buf + 2)) << 8) + + (png_uint_32)(*(buf + 3)); + + return (i); +} + +/* Grab a signed 32-bit integer from a buffer in big-endian format. The + * data is stored in the PNG file in two's complement format, and it is + * assumed that the machine format for signed integers is the same. + */ +png_int_32 PNGAPI +png_get_int_32(png_bytep buf) +{ + png_int_32 i = ((png_int_32)(*buf) << 24) + + ((png_int_32)(*(buf + 1)) << 16) + + ((png_int_32)(*(buf + 2)) << 8) + + (png_int_32)(*(buf + 3)); + + return (i); +} + +/* Grab an unsigned 16-bit integer from a buffer in big-endian format. */ +png_uint_16 PNGAPI +png_get_uint_16(png_bytep buf) +{ + png_uint_16 i = (png_uint_16)(((png_uint_16)(*buf) << 8) + + (png_uint_16)(*(buf + 1))); + + return (i); +} +#endif /* PNG_READ_BIG_ENDIAN_SUPPORTED */ + +/* Read the chunk header (length + type name). + * Put the type name into png_ptr->chunk_name, and return the length. + */ +png_uint_32 /* PRIVATE */ +png_read_chunk_header(png_structp png_ptr) +{ + png_byte buf[8]; + png_uint_32 length; + + /* Read the length and the chunk name */ + png_read_data(png_ptr, buf, 8); + length = png_get_uint_31(png_ptr, buf); + + /* Put the chunk name into png_ptr->chunk_name */ + png_memcpy(png_ptr->chunk_name, buf + 4, 4); + + png_debug2(0, "Reading %s chunk, length = %lu", + png_ptr->chunk_name, length); + + /* Reset the crc and run it over the chunk name */ + png_reset_crc(png_ptr); + png_calculate_crc(png_ptr, png_ptr->chunk_name, 4); + + /* Check to see if chunk name is valid */ + png_check_chunk_name(png_ptr, png_ptr->chunk_name); + + return length; +} + +/* Read data, and (optionally) run it through the CRC. */ +void /* PRIVATE */ +png_crc_read(png_structp png_ptr, png_bytep buf, png_size_t length) +{ + if (png_ptr == NULL) + return; + png_read_data(png_ptr, buf, length); + png_calculate_crc(png_ptr, buf, length); +} + +/* Optionally skip data and then check the CRC. Depending on whether we + * are reading a ancillary or critical chunk, and how the program has set + * things up, we may calculate the CRC on the data and print a message. + * Returns '1' if there was a CRC error, '0' otherwise. + */ +int /* PRIVATE */ +png_crc_finish(png_structp png_ptr, png_uint_32 skip) +{ + png_size_t i; + png_size_t istop = png_ptr->zbuf_size; + + for (i = (png_size_t)skip; i > istop; i -= istop) + { + png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size); + } + if (i) + { + png_crc_read(png_ptr, png_ptr->zbuf, i); + } + + if (png_crc_error(png_ptr)) + { + if (((png_ptr->chunk_name[0] & 0x20) && /* Ancillary */ + !(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)) || + (!(png_ptr->chunk_name[0] & 0x20) && /* Critical */ + (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_USE))) + { + png_chunk_warning(png_ptr, "CRC error"); + } + else + { + png_chunk_error(png_ptr, "CRC error"); + } + return (1); + } + + return (0); +} + +/* Compare the CRC stored in the PNG file with that calculated by libpng from + * the data it has read thus far. + */ +int /* PRIVATE */ +png_crc_error(png_structp png_ptr) +{ + png_byte crc_bytes[4]; + png_uint_32 crc; + int need_crc = 1; + + if (png_ptr->chunk_name[0] & 0x20) /* ancillary */ + { + if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) == + (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN)) + need_crc = 0; + } + else /* critical */ + { + if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE) + need_crc = 0; + } + + png_read_data(png_ptr, crc_bytes, 4); + + if (need_crc) + { + crc = png_get_uint_32(crc_bytes); + return ((int)(crc != png_ptr->crc)); + } + else + return (0); +} + +#if defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_READ_iTXt_SUPPORTED) || \ + defined(PNG_READ_iCCP_SUPPORTED) +static png_size_t +png_inflate(png_structp png_ptr, const png_byte *data, png_size_t size, + png_bytep output, png_size_t output_size) +{ + png_size_t count = 0; + + png_ptr->zstream.next_in = (png_bytep)data; /* const_cast: VALID */ + png_ptr->zstream.avail_in = size; + + while (1) + { + int ret, avail; + + /* Reset the output buffer each time round - we empty it + * after every inflate call. + */ + png_ptr->zstream.next_out = png_ptr->zbuf; + png_ptr->zstream.avail_out = png_ptr->zbuf_size; + + ret = inflate(&png_ptr->zstream, Z_NO_FLUSH); + avail = png_ptr->zbuf_size - png_ptr->zstream.avail_out; + + /* First copy/count any new output - but only if we didn't + * get an error code. + */ + if ((ret == Z_OK || ret == Z_STREAM_END) && avail > 0) + { + if (output != 0 && output_size > count) + { + int copy = output_size - count; + if (avail < copy) copy = avail; + png_memcpy(output + count, png_ptr->zbuf, copy); + } + count += avail; + } + + if (ret == Z_OK) + continue; + + /* Termination conditions - always reset the zstream, it + * must be left in inflateInit state. + */ + png_ptr->zstream.avail_in = 0; + inflateReset(&png_ptr->zstream); + + if (ret == Z_STREAM_END) + return count; /* NOTE: may be zero. */ + + /* Now handle the error codes - the API always returns 0 + * and the error message is dumped into the uncompressed + * buffer if available. + */ + { + PNG_CONST char *msg; + if (png_ptr->zstream.msg != 0) + msg = png_ptr->zstream.msg; + else + { +#if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE) + char umsg[52]; + + switch (ret) + { + case Z_BUF_ERROR: + msg = "Buffer error in compressed datastream in %s chunk"; + break; + case Z_DATA_ERROR: + msg = "Data error in compressed datastream in %s chunk"; + break; + default: + msg = "Incomplete compressed datastream in %s chunk"; + break; + } + + png_snprintf(umsg, sizeof umsg, msg, png_ptr->chunk_name); + msg = umsg; +#else + msg = "Damaged compressed datastream in chunk other than IDAT"; +#endif + } + + png_warning(png_ptr, msg); + } + + /* 0 means an error - notice that this code simple ignores + * zero length compressed chunks as a result. + */ + return 0; + } +} + +/* + * Decompress trailing data in a chunk. The assumption is that chunkdata + * points at an allocated area holding the contents of a chunk with a + * trailing compressed part. What we get back is an allocated area + * holding the original prefix part and an uncompressed version of the + * trailing part (the malloc area passed in is freed). + */ +void /* PRIVATE */ +png_decompress_chunk(png_structp png_ptr, int comp_type, + png_size_t chunklength, + png_size_t prefix_size, png_size_t *newlength) +{ + /* The caller should guarantee this */ + if (prefix_size > chunklength) + { + /* The recovery is to delete the chunk. */ + png_warning(png_ptr, "invalid chunklength"); + prefix_size = 0; /* To delete everything */ + } + + else if (comp_type == PNG_COMPRESSION_TYPE_BASE) + { + png_size_t expanded_size = png_inflate(png_ptr, + (png_bytep)(png_ptr->chunkdata + prefix_size), + chunklength - prefix_size, + 0/*output*/, 0/*output size*/); + + /* Now check the limits on this chunk - if the limit fails the + * compressed data will be removed, the prefix will remain. + */ +#ifdef PNG_SET_CHUNK_MALLOC_LIMIT_SUPPORTED + if (png_ptr->user_chunk_malloc_max && + (prefix_size + expanded_size >= png_ptr->user_chunk_malloc_max - 1)) +#else +# ifdef PNG_USER_CHUNK_MALLOC_MAX + if ((PNG_USER_CHUNK_MALLOC_MAX > 0) && + prefix_size + expanded_size >= PNG_USER_CHUNK_MALLOC_MAX - 1) +# endif +#endif + png_warning(png_ptr, "Exceeded size limit while expanding chunk"); + + /* If the size is zero either there was an error and a message + * has already been output (warning) or the size really is zero + * and we have nothing to do - the code will exit through the + * error case below. + */ +#if defined(PNG_SET_CHUNK_MALLOC_LIMIT_SUPPORTED) || \ + defined(PNG_USER_CHUNK_MALLOC_MAX) + else +#endif + if (expanded_size > 0) + { + /* Success (maybe) - really uncompress the chunk. */ + png_size_t new_size = 0; + png_charp text = png_malloc_warn(png_ptr, + prefix_size + expanded_size + 1); + + if (text != NULL) + { + png_memcpy(text, png_ptr->chunkdata, prefix_size); + new_size = png_inflate(png_ptr, + (png_bytep)(png_ptr->chunkdata + prefix_size), + chunklength - prefix_size, + (png_bytep)(text + prefix_size), expanded_size); + text[prefix_size + expanded_size] = 0; /* just in case */ + + if (new_size == expanded_size) + { + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = text; + *newlength = prefix_size + expanded_size; + return; /* The success return! */ + } + + png_warning(png_ptr, "png_inflate logic error"); + png_free(png_ptr, text); + } + else + png_warning(png_ptr, "Not enough memory to decompress chunk."); + } + } + + else /* if (comp_type != PNG_COMPRESSION_TYPE_BASE) */ + { +#if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE) + char umsg[50]; + + png_snprintf(umsg, sizeof umsg, "Unknown zTXt compression type %d", + comp_type); + png_warning(png_ptr, umsg); +#else + png_warning(png_ptr, "Unknown zTXt compression type"); +#endif + + /* The recovery is to simply drop the data. */ + } + + /* Generic error return - leave the prefix, delete the compressed + * data, reallocate the chunkdata to remove the potentially large + * amount of compressed data. + */ + { + png_charp text = png_malloc_warn(png_ptr, prefix_size + 1); + if (text != NULL) + { + if (prefix_size > 0) + png_memcpy(text, png_ptr->chunkdata, prefix_size); + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = text; + + /* This is an extra zero in the 'uncompressed' part. */ + *(png_ptr->chunkdata + prefix_size) = 0x00; + } + /* Ignore a malloc error here - it is safe. */ + } + + *newlength = prefix_size; +} +#endif + +/* Read and check the IDHR chunk */ +void /* PRIVATE */ +png_handle_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + png_byte buf[13]; + png_uint_32 width, height; + int bit_depth, color_type, compression_type, filter_type; + int interlace_type; + + png_debug(1, "in png_handle_IHDR"); + + if (png_ptr->mode & PNG_HAVE_IHDR) + png_error(png_ptr, "Out of place IHDR"); + + /* Check the length */ + if (length != 13) + png_error(png_ptr, "Invalid IHDR chunk"); + + png_ptr->mode |= PNG_HAVE_IHDR; + + png_crc_read(png_ptr, buf, 13); + png_crc_finish(png_ptr, 0); + + width = png_get_uint_31(png_ptr, buf); + height = png_get_uint_31(png_ptr, buf + 4); + bit_depth = buf[8]; + color_type = buf[9]; + compression_type = buf[10]; + filter_type = buf[11]; + interlace_type = buf[12]; + +#if defined(PNG_READ_APNG_SUPPORTED) + png_ptr->first_frame_width = width; + png_ptr->first_frame_height = height; +#endif + + /* Set internal variables */ + png_ptr->width = width; + png_ptr->height = height; + png_ptr->bit_depth = (png_byte)bit_depth; + png_ptr->interlaced = (png_byte)interlace_type; + png_ptr->color_type = (png_byte)color_type; +#ifdef PNG_MNG_FEATURES_SUPPORTED + png_ptr->filter_type = (png_byte)filter_type; +#endif + png_ptr->compression_type = (png_byte)compression_type; + + /* Find number of channels */ + switch (png_ptr->color_type) + { + case PNG_COLOR_TYPE_GRAY: + case PNG_COLOR_TYPE_PALETTE: + png_ptr->channels = 1; + break; + + case PNG_COLOR_TYPE_RGB: + png_ptr->channels = 3; + break; + + case PNG_COLOR_TYPE_GRAY_ALPHA: + png_ptr->channels = 2; + break; + + case PNG_COLOR_TYPE_RGB_ALPHA: + png_ptr->channels = 4; + break; + } + + /* Set up other useful info */ + png_ptr->pixel_depth = (png_byte)(png_ptr->bit_depth * + png_ptr->channels); + png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, png_ptr->width); + png_debug1(3, "bit_depth = %d", png_ptr->bit_depth); + png_debug1(3, "channels = %d", png_ptr->channels); + png_debug1(3, "rowbytes = %lu", png_ptr->rowbytes); + png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth, + color_type, interlace_type, compression_type, filter_type); +} + +/* Read and check the palette */ +void /* PRIVATE */ +png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + png_color palette[PNG_MAX_PALETTE_LENGTH]; + int num, i; +#ifdef PNG_POINTER_INDEXING_SUPPORTED + png_colorp pal_ptr; +#endif + + png_debug(1, "in png_handle_PLTE"); + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before PLTE"); + + else if (png_ptr->mode & PNG_HAVE_IDAT) + { + png_warning(png_ptr, "Invalid PLTE after IDAT"); + png_crc_finish(png_ptr, length); + return; + } + + else if (png_ptr->mode & PNG_HAVE_PLTE) + png_error(png_ptr, "Duplicate PLTE chunk"); + + png_ptr->mode |= PNG_HAVE_PLTE; + + if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR)) + { + png_warning(png_ptr, + "Ignoring PLTE chunk in grayscale PNG"); + png_crc_finish(png_ptr, length); + return; + } +#ifndef PNG_READ_OPT_PLTE_SUPPORTED + if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE) + { + png_crc_finish(png_ptr, length); + return; + } +#endif + + if (length > 3*PNG_MAX_PALETTE_LENGTH || length % 3) + { + if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE) + { + png_warning(png_ptr, "Invalid palette chunk"); + png_crc_finish(png_ptr, length); + return; + } + + else + { + png_error(png_ptr, "Invalid palette chunk"); + } + } + + num = (int)length / 3; + +#ifdef PNG_POINTER_INDEXING_SUPPORTED + for (i = 0, pal_ptr = palette; i < num; i++, pal_ptr++) + { + png_byte buf[3]; + + png_crc_read(png_ptr, buf, 3); + pal_ptr->red = buf[0]; + pal_ptr->green = buf[1]; + pal_ptr->blue = buf[2]; + } +#else + for (i = 0; i < num; i++) + { + png_byte buf[3]; + + png_crc_read(png_ptr, buf, 3); + /* Don't depend upon png_color being any order */ + palette[i].red = buf[0]; + palette[i].green = buf[1]; + palette[i].blue = buf[2]; + } +#endif + + /* If we actually NEED the PLTE chunk (ie for a paletted image), we do + * whatever the normal CRC configuration tells us. However, if we + * have an RGB image, the PLTE can be considered ancillary, so + * we will act as though it is. + */ +#ifndef PNG_READ_OPT_PLTE_SUPPORTED + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) +#endif + { + png_crc_finish(png_ptr, 0); + } +#ifndef PNG_READ_OPT_PLTE_SUPPORTED + else if (png_crc_error(png_ptr)) /* Only if we have a CRC error */ + { + /* If we don't want to use the data from an ancillary chunk, + we have two options: an error abort, or a warning and we + ignore the data in this chunk (which should be OK, since + it's considered ancillary for a RGB or RGBA image). */ + if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_USE)) + { + if (png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN) + { + png_chunk_error(png_ptr, "CRC error"); + } + else + { + png_chunk_warning(png_ptr, "CRC error"); + return; + } + } + /* Otherwise, we (optionally) emit a warning and use the chunk. */ + else if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)) + { + png_chunk_warning(png_ptr, "CRC error"); + } + } +#endif + + png_set_PLTE(png_ptr, info_ptr, palette, num); + +#ifdef PNG_READ_tRNS_SUPPORTED + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + { + if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS)) + { + if (png_ptr->num_trans > (png_uint_16)num) + { + png_warning(png_ptr, "Truncating incorrect tRNS chunk length"); + png_ptr->num_trans = (png_uint_16)num; + } + if (info_ptr->num_trans > (png_uint_16)num) + { + png_warning(png_ptr, "Truncating incorrect info tRNS chunk length"); + info_ptr->num_trans = (png_uint_16)num; + } + } + } +#endif + +} + +void /* PRIVATE */ +png_handle_IEND(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + png_debug(1, "in png_handle_IEND"); + + if (!(png_ptr->mode & PNG_HAVE_IHDR) || !(png_ptr->mode & PNG_HAVE_IDAT)) + { + png_error(png_ptr, "No image in file"); + } + + png_ptr->mode |= (PNG_AFTER_IDAT | PNG_HAVE_IEND); + + if (length != 0) + { + png_warning(png_ptr, "Incorrect IEND chunk length"); + } + png_crc_finish(png_ptr, length); + + info_ptr = info_ptr; /* Quiet compiler warnings about unused info_ptr */ +} + +#ifdef PNG_READ_gAMA_SUPPORTED +void /* PRIVATE */ +png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + png_fixed_point igamma; +#ifdef PNG_FLOATING_POINT_SUPPORTED + float file_gamma; +#endif + png_byte buf[4]; + + png_debug(1, "in png_handle_gAMA"); + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before gAMA"); + else if (png_ptr->mode & PNG_HAVE_IDAT) + { + png_warning(png_ptr, "Invalid gAMA after IDAT"); + png_crc_finish(png_ptr, length); + return; + } + else if (png_ptr->mode & PNG_HAVE_PLTE) + /* Should be an error, but we can cope with it */ + png_warning(png_ptr, "Out of place gAMA chunk"); + + if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA) +#ifdef PNG_READ_sRGB_SUPPORTED + && !(info_ptr->valid & PNG_INFO_sRGB) +#endif + ) + { + png_warning(png_ptr, "Duplicate gAMA chunk"); + png_crc_finish(png_ptr, length); + return; + } + + if (length != 4) + { + png_warning(png_ptr, "Incorrect gAMA chunk length"); + png_crc_finish(png_ptr, length); + return; + } + + png_crc_read(png_ptr, buf, 4); + if (png_crc_finish(png_ptr, 0)) + return; + + igamma = (png_fixed_point)png_get_uint_32(buf); + /* Check for zero gamma */ + if (igamma == 0) + { + png_warning(png_ptr, + "Ignoring gAMA chunk with gamma=0"); + return; + } + +#ifdef PNG_READ_sRGB_SUPPORTED + if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)) + if (PNG_OUT_OF_RANGE(igamma, 45500L, 500)) + { + png_warning(png_ptr, + "Ignoring incorrect gAMA value when sRGB is also present"); +#ifdef PNG_CONSOLE_IO_SUPPORTED + fprintf(stderr, "gamma = (%d/100000)", (int)igamma); +#endif + return; + } +#endif /* PNG_READ_sRGB_SUPPORTED */ + +#ifdef PNG_FLOATING_POINT_SUPPORTED + file_gamma = (float)igamma / (float)100000.0; +# ifdef PNG_READ_GAMMA_SUPPORTED + png_ptr->gamma = file_gamma; +# endif + png_set_gAMA(png_ptr, info_ptr, file_gamma); +#endif +#ifdef PNG_FIXED_POINT_SUPPORTED + png_set_gAMA_fixed(png_ptr, info_ptr, igamma); +#endif +} +#endif + +#ifdef PNG_READ_sBIT_SUPPORTED +void /* PRIVATE */ +png_handle_sBIT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + png_size_t truelen; + png_byte buf[4]; + + png_debug(1, "in png_handle_sBIT"); + + buf[0] = buf[1] = buf[2] = buf[3] = 0; + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before sBIT"); + else if (png_ptr->mode & PNG_HAVE_IDAT) + { + png_warning(png_ptr, "Invalid sBIT after IDAT"); + png_crc_finish(png_ptr, length); + return; + } + else if (png_ptr->mode & PNG_HAVE_PLTE) + { + /* Should be an error, but we can cope with it */ + png_warning(png_ptr, "Out of place sBIT chunk"); + } + if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)) + { + png_warning(png_ptr, "Duplicate sBIT chunk"); + png_crc_finish(png_ptr, length); + return; + } + + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + truelen = 3; + else + truelen = (png_size_t)png_ptr->channels; + + if (length != truelen || length > 4) + { + png_warning(png_ptr, "Incorrect sBIT chunk length"); + png_crc_finish(png_ptr, length); + return; + } + + png_crc_read(png_ptr, buf, truelen); + if (png_crc_finish(png_ptr, 0)) + return; + + if (png_ptr->color_type & PNG_COLOR_MASK_COLOR) + { + png_ptr->sig_bit.red = buf[0]; + png_ptr->sig_bit.green = buf[1]; + png_ptr->sig_bit.blue = buf[2]; + png_ptr->sig_bit.alpha = buf[3]; + } + else + { + png_ptr->sig_bit.gray = buf[0]; + png_ptr->sig_bit.red = buf[0]; + png_ptr->sig_bit.green = buf[0]; + png_ptr->sig_bit.blue = buf[0]; + png_ptr->sig_bit.alpha = buf[1]; + } + png_set_sBIT(png_ptr, info_ptr, &(png_ptr->sig_bit)); +} +#endif + +#ifdef PNG_READ_cHRM_SUPPORTED +void /* PRIVATE */ +png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + png_byte buf[32]; +#ifdef PNG_FLOATING_POINT_SUPPORTED + float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y; +#endif + png_fixed_point int_x_white, int_y_white, int_x_red, int_y_red, int_x_green, + int_y_green, int_x_blue, int_y_blue; + + png_uint_32 uint_x, uint_y; + + png_debug(1, "in png_handle_cHRM"); + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before cHRM"); + else if (png_ptr->mode & PNG_HAVE_IDAT) + { + png_warning(png_ptr, "Invalid cHRM after IDAT"); + png_crc_finish(png_ptr, length); + return; + } + else if (png_ptr->mode & PNG_HAVE_PLTE) + /* Should be an error, but we can cope with it */ + png_warning(png_ptr, "Missing PLTE before cHRM"); + + if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM) +#ifdef PNG_READ_sRGB_SUPPORTED + && !(info_ptr->valid & PNG_INFO_sRGB) +#endif + ) + { + png_warning(png_ptr, "Duplicate cHRM chunk"); + png_crc_finish(png_ptr, length); + return; + } + + if (length != 32) + { + png_warning(png_ptr, "Incorrect cHRM chunk length"); + png_crc_finish(png_ptr, length); + return; + } + + png_crc_read(png_ptr, buf, 32); + if (png_crc_finish(png_ptr, 0)) + return; + + uint_x = png_get_uint_32(buf); + uint_y = png_get_uint_32(buf + 4); + int_x_white = (png_fixed_point)uint_x; + int_y_white = (png_fixed_point)uint_y; + + uint_x = png_get_uint_32(buf + 8); + uint_y = png_get_uint_32(buf + 12); + int_x_red = (png_fixed_point)uint_x; + int_y_red = (png_fixed_point)uint_y; + + uint_x = png_get_uint_32(buf + 16); + uint_y = png_get_uint_32(buf + 20); + int_x_green = (png_fixed_point)uint_x; + int_y_green = (png_fixed_point)uint_y; + + uint_x = png_get_uint_32(buf + 24); + uint_y = png_get_uint_32(buf + 28); + int_x_blue = (png_fixed_point)uint_x; + int_y_blue = (png_fixed_point)uint_y; + +#ifdef PNG_FLOATING_POINT_SUPPORTED + white_x = (float)int_x_white / (float)100000.0; + white_y = (float)int_y_white / (float)100000.0; + red_x = (float)int_x_red / (float)100000.0; + red_y = (float)int_y_red / (float)100000.0; + green_x = (float)int_x_green / (float)100000.0; + green_y = (float)int_y_green / (float)100000.0; + blue_x = (float)int_x_blue / (float)100000.0; + blue_y = (float)int_y_blue / (float)100000.0; +#endif + +#ifdef PNG_READ_sRGB_SUPPORTED + if ((info_ptr != NULL) && (info_ptr->valid & PNG_INFO_sRGB)) + { + if (PNG_OUT_OF_RANGE(int_x_white, 31270, 1000) || + PNG_OUT_OF_RANGE(int_y_white, 32900, 1000) || + PNG_OUT_OF_RANGE(int_x_red, 64000L, 1000) || + PNG_OUT_OF_RANGE(int_y_red, 33000, 1000) || + PNG_OUT_OF_RANGE(int_x_green, 30000, 1000) || + PNG_OUT_OF_RANGE(int_y_green, 60000L, 1000) || + PNG_OUT_OF_RANGE(int_x_blue, 15000, 1000) || + PNG_OUT_OF_RANGE(int_y_blue, 6000, 1000)) + { + png_warning(png_ptr, + "Ignoring incorrect cHRM value when sRGB is also present"); +#ifdef PNG_CONSOLE_IO_SUPPORTED +#ifdef PNG_FLOATING_POINT_SUPPORTED + fprintf(stderr, "wx=%f, wy=%f, rx=%f, ry=%f\n", + white_x, white_y, red_x, red_y); + fprintf(stderr, "gx=%f, gy=%f, bx=%f, by=%f\n", + green_x, green_y, blue_x, blue_y); +#else + fprintf(stderr, "wx=%ld, wy=%ld, rx=%ld, ry=%ld\n", + (long)int_x_white, (long)int_y_white, + (long)int_x_red, (long)int_y_red); + fprintf(stderr, "gx=%ld, gy=%ld, bx=%ld, by=%ld\n", + (long)int_x_green, (long)int_y_green, + (long)int_x_blue, (long)int_y_blue); +#endif +#endif /* PNG_CONSOLE_IO_SUPPORTED */ + } + return; + } +#endif /* PNG_READ_sRGB_SUPPORTED */ + +#ifdef PNG_FLOATING_POINT_SUPPORTED + png_set_cHRM(png_ptr, info_ptr, + white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y); +#endif +#ifdef PNG_FIXED_POINT_SUPPORTED + png_set_cHRM_fixed(png_ptr, info_ptr, + int_x_white, int_y_white, int_x_red, int_y_red, int_x_green, + int_y_green, int_x_blue, int_y_blue); +#endif +} +#endif + +#ifdef PNG_READ_sRGB_SUPPORTED +void /* PRIVATE */ +png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + int intent; + png_byte buf[1]; + + png_debug(1, "in png_handle_sRGB"); + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before sRGB"); + else if (png_ptr->mode & PNG_HAVE_IDAT) + { + png_warning(png_ptr, "Invalid sRGB after IDAT"); + png_crc_finish(png_ptr, length); + return; + } + else if (png_ptr->mode & PNG_HAVE_PLTE) + /* Should be an error, but we can cope with it */ + png_warning(png_ptr, "Out of place sRGB chunk"); + + if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)) + { + png_warning(png_ptr, "Duplicate sRGB chunk"); + png_crc_finish(png_ptr, length); + return; + } + + if (length != 1) + { + png_warning(png_ptr, "Incorrect sRGB chunk length"); + png_crc_finish(png_ptr, length); + return; + } + + png_crc_read(png_ptr, buf, 1); + if (png_crc_finish(png_ptr, 0)) + return; + + intent = buf[0]; + /* Check for bad intent */ + if (intent >= PNG_sRGB_INTENT_LAST) + { + png_warning(png_ptr, "Unknown sRGB intent"); + return; + } + +#if defined(PNG_READ_gAMA_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED) + if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)) + { + png_fixed_point igamma; +#ifdef PNG_FIXED_POINT_SUPPORTED + igamma=info_ptr->int_gamma; +#else +# ifdef PNG_FLOATING_POINT_SUPPORTED + igamma=(png_fixed_point)(info_ptr->gamma * 100000.); +# endif +#endif + if (PNG_OUT_OF_RANGE(igamma, 45500L, 500)) + { + png_warning(png_ptr, + "Ignoring incorrect gAMA value when sRGB is also present"); +#ifdef PNG_CONSOLE_IO_SUPPORTED +# ifdef PNG_FIXED_POINT_SUPPORTED + fprintf(stderr, "incorrect gamma=(%d/100000)\n", + (int)png_ptr->int_gamma); +# else +# ifdef PNG_FLOATING_POINT_SUPPORTED + fprintf(stderr, "incorrect gamma=%f\n", png_ptr->gamma); +# endif +# endif +#endif + } + } +#endif /* PNG_READ_gAMA_SUPPORTED */ + +#ifdef PNG_READ_cHRM_SUPPORTED +#ifdef PNG_FIXED_POINT_SUPPORTED + if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)) + if (PNG_OUT_OF_RANGE(info_ptr->int_x_white, 31270, 1000) || + PNG_OUT_OF_RANGE(info_ptr->int_y_white, 32900, 1000) || + PNG_OUT_OF_RANGE(info_ptr->int_x_red, 64000L, 1000) || + PNG_OUT_OF_RANGE(info_ptr->int_y_red, 33000, 1000) || + PNG_OUT_OF_RANGE(info_ptr->int_x_green, 30000, 1000) || + PNG_OUT_OF_RANGE(info_ptr->int_y_green, 60000L, 1000) || + PNG_OUT_OF_RANGE(info_ptr->int_x_blue, 15000, 1000) || + PNG_OUT_OF_RANGE(info_ptr->int_y_blue, 6000, 1000)) + { + png_warning(png_ptr, + "Ignoring incorrect cHRM value when sRGB is also present"); + } +#endif /* PNG_FIXED_POINT_SUPPORTED */ +#endif /* PNG_READ_cHRM_SUPPORTED */ + + png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr, intent); +} +#endif /* PNG_READ_sRGB_SUPPORTED */ + +#ifdef PNG_READ_iCCP_SUPPORTED +void /* PRIVATE */ +png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +/* Note: this does not properly handle chunks that are > 64K under DOS */ +{ + png_byte compression_type; + png_bytep pC; + png_charp profile; + png_uint_32 skip = 0; + png_uint_32 profile_size, profile_length; + png_size_t slength, prefix_length, data_length; + + png_debug(1, "in png_handle_iCCP"); + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before iCCP"); + else if (png_ptr->mode & PNG_HAVE_IDAT) + { + png_warning(png_ptr, "Invalid iCCP after IDAT"); + png_crc_finish(png_ptr, length); + return; + } + else if (png_ptr->mode & PNG_HAVE_PLTE) + /* Should be an error, but we can cope with it */ + png_warning(png_ptr, "Out of place iCCP chunk"); + + if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)) + { + png_warning(png_ptr, "Duplicate iCCP chunk"); + png_crc_finish(png_ptr, length); + return; + } + +#ifdef PNG_MAX_MALLOC_64K + if (length > (png_uint_32)65535L) + { + png_warning(png_ptr, "iCCP chunk too large to fit in memory"); + skip = length - (png_uint_32)65535L; + length = (png_uint_32)65535L; + } +#endif + + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = (png_charp)png_malloc(png_ptr, length + 1); + slength = (png_size_t)length; + png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength); + + if (png_crc_finish(png_ptr, skip)) + { + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + return; + } + + png_ptr->chunkdata[slength] = 0x00; + + for (profile = png_ptr->chunkdata; *profile; profile++) + /* Empty loop to find end of name */ ; + + ++profile; + + /* There should be at least one zero (the compression type byte) + * following the separator, and we should be on it + */ + if ( profile >= png_ptr->chunkdata + slength - 1) + { + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + png_warning(png_ptr, "Malformed iCCP chunk"); + return; + } + + /* Compression_type should always be zero */ + compression_type = *profile++; + if (compression_type) + { + png_warning(png_ptr, "Ignoring nonzero compression type in iCCP chunk"); + compression_type = 0x00; /* Reset it to zero (libpng-1.0.6 through 1.0.8 + wrote nonzero) */ + } + + prefix_length = profile - png_ptr->chunkdata; + png_decompress_chunk(png_ptr, compression_type, + slength, prefix_length, &data_length); + + profile_length = data_length - prefix_length; + + if ( prefix_length > data_length || profile_length < 4) + { + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + png_warning(png_ptr, "Profile size field missing from iCCP chunk"); + return; + } + + /* Check the profile_size recorded in the first 32 bits of the ICC profile */ + pC = (png_bytep)(png_ptr->chunkdata + prefix_length); + profile_size = ((*(pC ))<<24) | + ((*(pC + 1))<<16) | + ((*(pC + 2))<< 8) | + ((*(pC + 3)) ); + + if (profile_size < profile_length) + profile_length = profile_size; + + if (profile_size > profile_length) + { + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + png_warning(png_ptr, "Ignoring truncated iCCP profile."); + return; + } + + png_set_iCCP(png_ptr, info_ptr, png_ptr->chunkdata, + compression_type, png_ptr->chunkdata + prefix_length, profile_length); + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; +} +#endif /* PNG_READ_iCCP_SUPPORTED */ + +#ifdef PNG_READ_sPLT_SUPPORTED +void /* PRIVATE */ +png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +/* Note: this does not properly handle chunks that are > 64K under DOS */ +{ + png_bytep entry_start; + png_sPLT_t new_palette; +#ifdef PNG_POINTER_INDEXING_SUPPORTED + png_sPLT_entryp pp; +#endif + int data_length, entry_size, i; + png_uint_32 skip = 0; + png_size_t slength; + + png_debug(1, "in png_handle_sPLT"); + +#ifdef PNG_USER_LIMITS_SUPPORTED + + if (png_ptr->user_chunk_cache_max != 0) + { + if (png_ptr->user_chunk_cache_max == 1) + { + png_crc_finish(png_ptr, length); + return; + } + if (--png_ptr->user_chunk_cache_max == 1) + { + png_warning(png_ptr, "No space in chunk cache for sPLT"); + png_crc_finish(png_ptr, length); + return; + } + } +#endif + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before sPLT"); + else if (png_ptr->mode & PNG_HAVE_IDAT) + { + png_warning(png_ptr, "Invalid sPLT after IDAT"); + png_crc_finish(png_ptr, length); + return; + } + +#ifdef PNG_MAX_MALLOC_64K + if (length > (png_uint_32)65535L) + { + png_warning(png_ptr, "sPLT chunk too large to fit in memory"); + skip = length - (png_uint_32)65535L; + length = (png_uint_32)65535L; + } +#endif + + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = (png_charp)png_malloc(png_ptr, length + 1); + slength = (png_size_t)length; + png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength); + + if (png_crc_finish(png_ptr, skip)) + { + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + return; + } + + png_ptr->chunkdata[slength] = 0x00; + + for (entry_start = (png_bytep)png_ptr->chunkdata; *entry_start; + entry_start++) + /* Empty loop to find end of name */ ; + ++entry_start; + + /* A sample depth should follow the separator, and we should be on it */ + if (entry_start > (png_bytep)png_ptr->chunkdata + slength - 2) + { + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + png_warning(png_ptr, "malformed sPLT chunk"); + return; + } + + new_palette.depth = *entry_start++; + entry_size = (new_palette.depth == 8 ? 6 : 10); + data_length = (slength - (entry_start - (png_bytep)png_ptr->chunkdata)); + + /* Integrity-check the data length */ + if (data_length % entry_size) + { + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + png_warning(png_ptr, "sPLT chunk has bad length"); + return; + } + + new_palette.nentries = (png_int_32) ( data_length / entry_size); + if ((png_uint_32) new_palette.nentries > + (png_uint_32) (PNG_SIZE_MAX / png_sizeof(png_sPLT_entry))) + { + png_warning(png_ptr, "sPLT chunk too long"); + return; + } + new_palette.entries = (png_sPLT_entryp)png_malloc_warn( + png_ptr, new_palette.nentries * png_sizeof(png_sPLT_entry)); + if (new_palette.entries == NULL) + { + png_warning(png_ptr, "sPLT chunk requires too much memory"); + return; + } + +#ifdef PNG_POINTER_INDEXING_SUPPORTED + for (i = 0; i < new_palette.nentries; i++) + { + pp = new_palette.entries + i; + + if (new_palette.depth == 8) + { + pp->red = *entry_start++; + pp->green = *entry_start++; + pp->blue = *entry_start++; + pp->alpha = *entry_start++; + } + else + { + pp->red = png_get_uint_16(entry_start); entry_start += 2; + pp->green = png_get_uint_16(entry_start); entry_start += 2; + pp->blue = png_get_uint_16(entry_start); entry_start += 2; + pp->alpha = png_get_uint_16(entry_start); entry_start += 2; + } + pp->frequency = png_get_uint_16(entry_start); entry_start += 2; + } +#else + pp = new_palette.entries; + for (i = 0; i < new_palette.nentries; i++) + { + + if (new_palette.depth == 8) + { + pp[i].red = *entry_start++; + pp[i].green = *entry_start++; + pp[i].blue = *entry_start++; + pp[i].alpha = *entry_start++; + } + else + { + pp[i].red = png_get_uint_16(entry_start); entry_start += 2; + pp[i].green = png_get_uint_16(entry_start); entry_start += 2; + pp[i].blue = png_get_uint_16(entry_start); entry_start += 2; + pp[i].alpha = png_get_uint_16(entry_start); entry_start += 2; + } + pp->frequency = png_get_uint_16(entry_start); entry_start += 2; + } +#endif + + /* Discard all chunk data except the name and stash that */ + new_palette.name = png_ptr->chunkdata; + + png_set_sPLT(png_ptr, info_ptr, &new_palette, 1); + + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + png_free(png_ptr, new_palette.entries); +} +#endif /* PNG_READ_sPLT_SUPPORTED */ + +#ifdef PNG_READ_tRNS_SUPPORTED +void /* PRIVATE */ +png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + png_byte readbuf[PNG_MAX_PALETTE_LENGTH]; + + png_debug(1, "in png_handle_tRNS"); + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before tRNS"); + else if (png_ptr->mode & PNG_HAVE_IDAT) + { + png_warning(png_ptr, "Invalid tRNS after IDAT"); + png_crc_finish(png_ptr, length); + return; + } + else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS)) + { + png_warning(png_ptr, "Duplicate tRNS chunk"); + png_crc_finish(png_ptr, length); + return; + } + + if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY) + { + png_byte buf[2]; + + if (length != 2) + { + png_warning(png_ptr, "Incorrect tRNS chunk length"); + png_crc_finish(png_ptr, length); + return; + } + + png_crc_read(png_ptr, buf, 2); + png_ptr->num_trans = 1; + png_ptr->trans_values.gray = png_get_uint_16(buf); + } + else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB) + { + png_byte buf[6]; + + if (length != 6) + { + png_warning(png_ptr, "Incorrect tRNS chunk length"); + png_crc_finish(png_ptr, length); + return; + } + png_crc_read(png_ptr, buf, (png_size_t)length); + png_ptr->num_trans = 1; + png_ptr->trans_values.red = png_get_uint_16(buf); + png_ptr->trans_values.green = png_get_uint_16(buf + 2); + png_ptr->trans_values.blue = png_get_uint_16(buf + 4); + } + else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + { + if (!(png_ptr->mode & PNG_HAVE_PLTE)) + { + /* Should be an error, but we can cope with it. */ + png_warning(png_ptr, "Missing PLTE before tRNS"); + } + if (length > (png_uint_32)png_ptr->num_palette || + length > PNG_MAX_PALETTE_LENGTH) + { + png_warning(png_ptr, "Incorrect tRNS chunk length"); + png_crc_finish(png_ptr, length); + return; + } + if (length == 0) + { + png_warning(png_ptr, "Zero length tRNS chunk"); + png_crc_finish(png_ptr, length); + return; + } + png_crc_read(png_ptr, readbuf, (png_size_t)length); + png_ptr->num_trans = (png_uint_16)length; + } + else + { + png_warning(png_ptr, "tRNS chunk not allowed with alpha channel"); + png_crc_finish(png_ptr, length); + return; + } + + if (png_crc_finish(png_ptr, 0)) + { + png_ptr->num_trans = 0; + return; + } + + png_set_tRNS(png_ptr, info_ptr, readbuf, png_ptr->num_trans, + &(png_ptr->trans_values)); +} +#endif + +#ifdef PNG_READ_bKGD_SUPPORTED +void /* PRIVATE */ +png_handle_bKGD(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + png_size_t truelen; + png_byte buf[6]; + + png_debug(1, "in png_handle_bKGD"); + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before bKGD"); + else if (png_ptr->mode & PNG_HAVE_IDAT) + { + png_warning(png_ptr, "Invalid bKGD after IDAT"); + png_crc_finish(png_ptr, length); + return; + } + else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && + !(png_ptr->mode & PNG_HAVE_PLTE)) + { + png_warning(png_ptr, "Missing PLTE before bKGD"); + png_crc_finish(png_ptr, length); + return; + } + else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)) + { + png_warning(png_ptr, "Duplicate bKGD chunk"); + png_crc_finish(png_ptr, length); + return; + } + + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + truelen = 1; + else if (png_ptr->color_type & PNG_COLOR_MASK_COLOR) + truelen = 6; + else + truelen = 2; + + if (length != truelen) + { + png_warning(png_ptr, "Incorrect bKGD chunk length"); + png_crc_finish(png_ptr, length); + return; + } + + png_crc_read(png_ptr, buf, truelen); + if (png_crc_finish(png_ptr, 0)) + return; + + /* We convert the index value into RGB components so that we can allow + * arbitrary RGB values for background when we have transparency, and + * so it is easy to determine the RGB values of the background color + * from the info_ptr struct. */ + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + { + png_ptr->background.index = buf[0]; + if (info_ptr && info_ptr->num_palette) + { + if (buf[0] >= info_ptr->num_palette) + { + png_warning(png_ptr, "Incorrect bKGD chunk index value"); + return; + } + png_ptr->background.red = + (png_uint_16)png_ptr->palette[buf[0]].red; + png_ptr->background.green = + (png_uint_16)png_ptr->palette[buf[0]].green; + png_ptr->background.blue = + (png_uint_16)png_ptr->palette[buf[0]].blue; + } + } + else if (!(png_ptr->color_type & PNG_COLOR_MASK_COLOR)) /* GRAY */ + { + png_ptr->background.red = + png_ptr->background.green = + png_ptr->background.blue = + png_ptr->background.gray = png_get_uint_16(buf); + } + else + { + png_ptr->background.red = png_get_uint_16(buf); + png_ptr->background.green = png_get_uint_16(buf + 2); + png_ptr->background.blue = png_get_uint_16(buf + 4); + } + + png_set_bKGD(png_ptr, info_ptr, &(png_ptr->background)); +} +#endif + +#ifdef PNG_READ_hIST_SUPPORTED +void /* PRIVATE */ +png_handle_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + unsigned int num, i; + png_uint_16 readbuf[PNG_MAX_PALETTE_LENGTH]; + + png_debug(1, "in png_handle_hIST"); + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before hIST"); + else if (png_ptr->mode & PNG_HAVE_IDAT) + { + png_warning(png_ptr, "Invalid hIST after IDAT"); + png_crc_finish(png_ptr, length); + return; + } + else if (!(png_ptr->mode & PNG_HAVE_PLTE)) + { + png_warning(png_ptr, "Missing PLTE before hIST"); + png_crc_finish(png_ptr, length); + return; + } + else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)) + { + png_warning(png_ptr, "Duplicate hIST chunk"); + png_crc_finish(png_ptr, length); + return; + } + + num = length / 2 ; + if (num != (unsigned int) png_ptr->num_palette || num > + (unsigned int) PNG_MAX_PALETTE_LENGTH) + { + png_warning(png_ptr, "Incorrect hIST chunk length"); + png_crc_finish(png_ptr, length); + return; + } + + for (i = 0; i < num; i++) + { + png_byte buf[2]; + + png_crc_read(png_ptr, buf, 2); + readbuf[i] = png_get_uint_16(buf); + } + + if (png_crc_finish(png_ptr, 0)) + return; + + png_set_hIST(png_ptr, info_ptr, readbuf); +} +#endif + +#ifdef PNG_READ_pHYs_SUPPORTED +void /* PRIVATE */ +png_handle_pHYs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + png_byte buf[9]; + png_uint_32 res_x, res_y; + int unit_type; + + png_debug(1, "in png_handle_pHYs"); + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before pHYs"); + else if (png_ptr->mode & PNG_HAVE_IDAT) + { + png_warning(png_ptr, "Invalid pHYs after IDAT"); + png_crc_finish(png_ptr, length); + return; + } + else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) + { + png_warning(png_ptr, "Duplicate pHYs chunk"); + png_crc_finish(png_ptr, length); + return; + } + + if (length != 9) + { + png_warning(png_ptr, "Incorrect pHYs chunk length"); + png_crc_finish(png_ptr, length); + return; + } + + png_crc_read(png_ptr, buf, 9); + if (png_crc_finish(png_ptr, 0)) + return; + + res_x = png_get_uint_32(buf); + res_y = png_get_uint_32(buf + 4); + unit_type = buf[8]; + png_set_pHYs(png_ptr, info_ptr, res_x, res_y, unit_type); +} +#endif + +#ifdef PNG_READ_oFFs_SUPPORTED +void /* PRIVATE */ +png_handle_oFFs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + png_byte buf[9]; + png_int_32 offset_x, offset_y; + int unit_type; + + png_debug(1, "in png_handle_oFFs"); + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before oFFs"); + else if (png_ptr->mode & PNG_HAVE_IDAT) + { + png_warning(png_ptr, "Invalid oFFs after IDAT"); + png_crc_finish(png_ptr, length); + return; + } + else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)) + { + png_warning(png_ptr, "Duplicate oFFs chunk"); + png_crc_finish(png_ptr, length); + return; + } + + if (length != 9) + { + png_warning(png_ptr, "Incorrect oFFs chunk length"); + png_crc_finish(png_ptr, length); + return; + } + + png_crc_read(png_ptr, buf, 9); + if (png_crc_finish(png_ptr, 0)) + return; + + offset_x = png_get_int_32(buf); + offset_y = png_get_int_32(buf + 4); + unit_type = buf[8]; + png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y, unit_type); +} +#endif + +#ifdef PNG_READ_pCAL_SUPPORTED +/* Read the pCAL chunk (described in the PNG Extensions document) */ +void /* PRIVATE */ +png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + png_int_32 X0, X1; + png_byte type, nparams; + png_charp buf, units, endptr; + png_charpp params; + png_size_t slength; + int i; + + png_debug(1, "in png_handle_pCAL"); + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before pCAL"); + else if (png_ptr->mode & PNG_HAVE_IDAT) + { + png_warning(png_ptr, "Invalid pCAL after IDAT"); + png_crc_finish(png_ptr, length); + return; + } + else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)) + { + png_warning(png_ptr, "Duplicate pCAL chunk"); + png_crc_finish(png_ptr, length); + return; + } + + png_debug1(2, "Allocating and reading pCAL chunk data (%lu bytes)", + length + 1); + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1); + if (png_ptr->chunkdata == NULL) + { + png_warning(png_ptr, "No memory for pCAL purpose."); + return; + } + slength = (png_size_t)length; + png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength); + + if (png_crc_finish(png_ptr, 0)) + { + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + return; + } + + png_ptr->chunkdata[slength] = 0x00; /* Null terminate the last string */ + + png_debug(3, "Finding end of pCAL purpose string"); + for (buf = png_ptr->chunkdata; *buf; buf++) + /* Empty loop */ ; + + endptr = png_ptr->chunkdata + slength; + + /* We need to have at least 12 bytes after the purpose string + in order to get the parameter information. */ + if (endptr <= buf + 12) + { + png_warning(png_ptr, "Invalid pCAL data"); + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + return; + } + + png_debug(3, "Reading pCAL X0, X1, type, nparams, and units"); + X0 = png_get_int_32((png_bytep)buf+1); + X1 = png_get_int_32((png_bytep)buf+5); + type = buf[9]; + nparams = buf[10]; + units = buf + 11; + + png_debug(3, "Checking pCAL equation type and number of parameters"); + /* Check that we have the right number of parameters for known + equation types. */ + if ((type == PNG_EQUATION_LINEAR && nparams != 2) || + (type == PNG_EQUATION_BASE_E && nparams != 3) || + (type == PNG_EQUATION_ARBITRARY && nparams != 3) || + (type == PNG_EQUATION_HYPERBOLIC && nparams != 4)) + { + png_warning(png_ptr, "Invalid pCAL parameters for equation type"); + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + return; + } + else if (type >= PNG_EQUATION_LAST) + { + png_warning(png_ptr, "Unrecognized equation type for pCAL chunk"); + } + + for (buf = units; *buf; buf++) + /* Empty loop to move past the units string. */ ; + + png_debug(3, "Allocating pCAL parameters array"); + params = (png_charpp)png_malloc_warn(png_ptr, + (png_uint_32)(nparams * png_sizeof(png_charp))) ; + if (params == NULL) + { + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + png_warning(png_ptr, "No memory for pCAL params."); + return; + } + + /* Get pointers to the start of each parameter string. */ + for (i = 0; i < (int)nparams; i++) + { + buf++; /* Skip the null string terminator from previous parameter. */ + + png_debug1(3, "Reading pCAL parameter %d", i); + for (params[i] = buf; buf <= endptr && *buf != 0x00; buf++) + /* Empty loop to move past each parameter string */ ; + + /* Make sure we haven't run out of data yet */ + if (buf > endptr) + { + png_warning(png_ptr, "Invalid pCAL data"); + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + png_free(png_ptr, params); + return; + } + } + + png_set_pCAL(png_ptr, info_ptr, png_ptr->chunkdata, X0, X1, type, nparams, + units, params); + + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + png_free(png_ptr, params); +} +#endif + +#ifdef PNG_READ_sCAL_SUPPORTED +/* Read the sCAL chunk */ +void /* PRIVATE */ +png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + png_charp ep; +#ifdef PNG_FLOATING_POINT_SUPPORTED + double width, height; + png_charp vp; +#else +#ifdef PNG_FIXED_POINT_SUPPORTED + png_charp swidth, sheight; +#endif +#endif + png_size_t slength; + + png_debug(1, "in png_handle_sCAL"); + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before sCAL"); + else if (png_ptr->mode & PNG_HAVE_IDAT) + { + png_warning(png_ptr, "Invalid sCAL after IDAT"); + png_crc_finish(png_ptr, length); + return; + } + else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sCAL)) + { + png_warning(png_ptr, "Duplicate sCAL chunk"); + png_crc_finish(png_ptr, length); + return; + } + + /* Need unit type, width, \0, height: minimum 4 bytes */ + else if (length < 4) + { + png_warning(png_ptr, "sCAL chunk too short"); + png_crc_finish(png_ptr, length); + return; + } + + png_debug1(2, "Allocating and reading sCAL chunk data (%lu bytes)", + length + 1); + png_ptr->chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1); + if (png_ptr->chunkdata == NULL) + { + png_warning(png_ptr, "Out of memory while processing sCAL chunk"); + png_crc_finish(png_ptr, length); + return; + } + slength = (png_size_t)length; + png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength); + + if (png_crc_finish(png_ptr, 0)) + { + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + return; + } + + png_ptr->chunkdata[slength] = 0x00; /* Null terminate the last string */ + + ep = png_ptr->chunkdata + 1; /* Skip unit byte */ + +#ifdef PNG_FLOATING_POINT_SUPPORTED + width = png_strtod(png_ptr, ep, &vp); + if (*vp) + { + png_warning(png_ptr, "malformed width string in sCAL chunk"); + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + return; + } +#else +#ifdef PNG_FIXED_POINT_SUPPORTED + swidth = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1); + if (swidth == NULL) + { + png_warning(png_ptr, "Out of memory while processing sCAL chunk width"); + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + return; + } + png_memcpy(swidth, ep, (png_size_t)png_strlen(ep)); +#endif +#endif + + for (ep = png_ptr->chunkdata; *ep; ep++) + /* Empty loop */ ; + ep++; + + if (png_ptr->chunkdata + slength < ep) + { + png_warning(png_ptr, "Truncated sCAL chunk"); +#if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED) + png_free(png_ptr, swidth); +#endif + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + return; + } + +#ifdef PNG_FLOATING_POINT_SUPPORTED + height = png_strtod(png_ptr, ep, &vp); + if (*vp) + { + png_warning(png_ptr, "malformed height string in sCAL chunk"); + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; +#if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED) + png_free(png_ptr, swidth); +#endif + return; + } +#else +#ifdef PNG_FIXED_POINT_SUPPORTED + sheight = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1); + if (sheight == NULL) + { + png_warning(png_ptr, "Out of memory while processing sCAL chunk height"); + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; +#if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED) + png_free(png_ptr, swidth); +#endif + return; + } + png_memcpy(sheight, ep, (png_size_t)png_strlen(ep)); +#endif +#endif + + if (png_ptr->chunkdata + slength < ep +#ifdef PNG_FLOATING_POINT_SUPPORTED + || width <= 0. || height <= 0. +#endif + ) + { + png_warning(png_ptr, "Invalid sCAL data"); + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; +#if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED) + png_free(png_ptr, swidth); + png_free(png_ptr, sheight); +#endif + return; + } + + +#ifdef PNG_FLOATING_POINT_SUPPORTED + png_set_sCAL(png_ptr, info_ptr, png_ptr->chunkdata[0], width, height); +#else +#ifdef PNG_FIXED_POINT_SUPPORTED + png_set_sCAL_s(png_ptr, info_ptr, png_ptr->chunkdata[0], swidth, sheight); +#endif +#endif + + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; +#if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED) + png_free(png_ptr, swidth); + png_free(png_ptr, sheight); +#endif +} +#endif + +#ifdef PNG_READ_tIME_SUPPORTED +void /* PRIVATE */ +png_handle_tIME(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + png_byte buf[7]; + png_time mod_time; + + png_debug(1, "in png_handle_tIME"); + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Out of place tIME chunk"); + else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)) + { + png_warning(png_ptr, "Duplicate tIME chunk"); + png_crc_finish(png_ptr, length); + return; + } + + if (png_ptr->mode & PNG_HAVE_IDAT) + png_ptr->mode |= PNG_AFTER_IDAT; + + if (length != 7) + { + png_warning(png_ptr, "Incorrect tIME chunk length"); + png_crc_finish(png_ptr, length); + return; + } + + png_crc_read(png_ptr, buf, 7); + if (png_crc_finish(png_ptr, 0)) + return; + + mod_time.second = buf[6]; + mod_time.minute = buf[5]; + mod_time.hour = buf[4]; + mod_time.day = buf[3]; + mod_time.month = buf[2]; + mod_time.year = png_get_uint_16(buf); + + png_set_tIME(png_ptr, info_ptr, &mod_time); +} +#endif + +#ifdef PNG_READ_tEXt_SUPPORTED +/* Note: this does not properly handle chunks that are > 64K under DOS */ +void /* PRIVATE */ +png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + png_textp text_ptr; + png_charp key; + png_charp text; + png_uint_32 skip = 0; + png_size_t slength; + int ret; + + png_debug(1, "in png_handle_tEXt"); + +#ifdef PNG_USER_LIMITS_SUPPORTED + if (png_ptr->user_chunk_cache_max != 0) + { + if (png_ptr->user_chunk_cache_max == 1) + { + png_crc_finish(png_ptr, length); + return; + } + if (--png_ptr->user_chunk_cache_max == 1) + { + png_warning(png_ptr, "No space in chunk cache for tEXt"); + png_crc_finish(png_ptr, length); + return; + } + } +#endif + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before tEXt"); + + if (png_ptr->mode & PNG_HAVE_IDAT) + png_ptr->mode |= PNG_AFTER_IDAT; + +#ifdef PNG_MAX_MALLOC_64K + if (length > (png_uint_32)65535L) + { + png_warning(png_ptr, "tEXt chunk too large to fit in memory"); + skip = length - (png_uint_32)65535L; + length = (png_uint_32)65535L; + } +#endif + + png_free(png_ptr, png_ptr->chunkdata); + + png_ptr->chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1); + if (png_ptr->chunkdata == NULL) + { + png_warning(png_ptr, "No memory to process text chunk."); + return; + } + slength = (png_size_t)length; + png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength); + + if (png_crc_finish(png_ptr, skip)) + { + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + return; + } + + key = png_ptr->chunkdata; + + key[slength] = 0x00; + + for (text = key; *text; text++) + /* Empty loop to find end of key */ ; + + if (text != key + slength) + text++; + + text_ptr = (png_textp)png_malloc_warn(png_ptr, + (png_uint_32)png_sizeof(png_text)); + if (text_ptr == NULL) + { + png_warning(png_ptr, "Not enough memory to process text chunk."); + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + return; + } + text_ptr->compression = PNG_TEXT_COMPRESSION_NONE; + text_ptr->key = key; +#ifdef PNG_iTXt_SUPPORTED + text_ptr->lang = NULL; + text_ptr->lang_key = NULL; + text_ptr->itxt_length = 0; +#endif + text_ptr->text = text; + text_ptr->text_length = png_strlen(text); + + ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1); + + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + png_free(png_ptr, text_ptr); + if (ret) + png_warning(png_ptr, "Insufficient memory to process text chunk."); +} +#endif + +#ifdef PNG_READ_zTXt_SUPPORTED +/* Note: this does not correctly handle chunks that are > 64K under DOS */ +void /* PRIVATE */ +png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + png_textp text_ptr; + png_charp text; + int comp_type; + int ret; + png_size_t slength, prefix_len, data_len; + + png_debug(1, "in png_handle_zTXt"); + +#ifdef PNG_USER_LIMITS_SUPPORTED + if (png_ptr->user_chunk_cache_max != 0) + { + if (png_ptr->user_chunk_cache_max == 1) + { + png_crc_finish(png_ptr, length); + return; + } + if (--png_ptr->user_chunk_cache_max == 1) + { + png_warning(png_ptr, "No space in chunk cache for zTXt"); + png_crc_finish(png_ptr, length); + return; + } + } +#endif + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before zTXt"); + + if (png_ptr->mode & PNG_HAVE_IDAT) + png_ptr->mode |= PNG_AFTER_IDAT; + +#ifdef PNG_MAX_MALLOC_64K + /* We will no doubt have problems with chunks even half this size, but + there is no hard and fast rule to tell us where to stop. */ + if (length > (png_uint_32)65535L) + { + png_warning(png_ptr, "zTXt chunk too large to fit in memory"); + png_crc_finish(png_ptr, length); + return; + } +#endif + + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1); + if (png_ptr->chunkdata == NULL) + { + png_warning(png_ptr, "Out of memory processing zTXt chunk."); + return; + } + slength = (png_size_t)length; + png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength); + if (png_crc_finish(png_ptr, 0)) + { + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + return; + } + + png_ptr->chunkdata[slength] = 0x00; + + for (text = png_ptr->chunkdata; *text; text++) + /* Empty loop */ ; + + /* zTXt must have some text after the chunkdataword */ + if (text >= png_ptr->chunkdata + slength - 2) + { + png_warning(png_ptr, "Truncated zTXt chunk"); + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + return; + } + else + { + comp_type = *(++text); + if (comp_type != PNG_TEXT_COMPRESSION_zTXt) + { + png_warning(png_ptr, "Unknown compression type in zTXt chunk"); + comp_type = PNG_TEXT_COMPRESSION_zTXt; + } + text++; /* Skip the compression_method byte */ + } + prefix_len = text - png_ptr->chunkdata; + + png_decompress_chunk(png_ptr, comp_type, + (png_size_t)length, prefix_len, &data_len); + + text_ptr = (png_textp)png_malloc_warn(png_ptr, + (png_uint_32)png_sizeof(png_text)); + if (text_ptr == NULL) + { + png_warning(png_ptr, "Not enough memory to process zTXt chunk."); + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + return; + } + text_ptr->compression = comp_type; + text_ptr->key = png_ptr->chunkdata; +#ifdef PNG_iTXt_SUPPORTED + text_ptr->lang = NULL; + text_ptr->lang_key = NULL; + text_ptr->itxt_length = 0; +#endif + text_ptr->text = png_ptr->chunkdata + prefix_len; + text_ptr->text_length = data_len; + + ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1); + + png_free(png_ptr, text_ptr); + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + if (ret) + png_error(png_ptr, "Insufficient memory to store zTXt chunk."); +} +#endif + +#ifdef PNG_READ_iTXt_SUPPORTED +/* Note: this does not correctly handle chunks that are > 64K under DOS */ +void /* PRIVATE */ +png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + png_textp text_ptr; + png_charp key, lang, text, lang_key; + int comp_flag; + int comp_type = 0; + int ret; + png_size_t slength, prefix_len, data_len; + + png_debug(1, "in png_handle_iTXt"); + +#ifdef PNG_USER_LIMITS_SUPPORTED + if (png_ptr->user_chunk_cache_max != 0) + { + if (png_ptr->user_chunk_cache_max == 1) + { + png_crc_finish(png_ptr, length); + return; + } + if (--png_ptr->user_chunk_cache_max == 1) + { + png_warning(png_ptr, "No space in chunk cache for iTXt"); + png_crc_finish(png_ptr, length); + return; + } + } +#endif + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + png_error(png_ptr, "Missing IHDR before iTXt"); + + if (png_ptr->mode & PNG_HAVE_IDAT) + png_ptr->mode |= PNG_AFTER_IDAT; + +#ifdef PNG_MAX_MALLOC_64K + /* We will no doubt have problems with chunks even half this size, but + there is no hard and fast rule to tell us where to stop. */ + if (length > (png_uint_32)65535L) + { + png_warning(png_ptr, "iTXt chunk too large to fit in memory"); + png_crc_finish(png_ptr, length); + return; + } +#endif + + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1); + if (png_ptr->chunkdata == NULL) + { + png_warning(png_ptr, "No memory to process iTXt chunk."); + return; + } + slength = (png_size_t)length; + png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength); + if (png_crc_finish(png_ptr, 0)) + { + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + return; + } + + png_ptr->chunkdata[slength] = 0x00; + + for (lang = png_ptr->chunkdata; *lang; lang++) + /* Empty loop */ ; + lang++; /* Skip NUL separator */ + + /* iTXt must have a language tag (possibly empty), two compression bytes, + * translated keyword (possibly empty), and possibly some text after the + * keyword + */ + + if (lang >= png_ptr->chunkdata + slength - 3) + { + png_warning(png_ptr, "Truncated iTXt chunk"); + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + return; + } + else + { + comp_flag = *lang++; + comp_type = *lang++; + } + + for (lang_key = lang; *lang_key; lang_key++) + /* Empty loop */ ; + lang_key++; /* Skip NUL separator */ + + if (lang_key >= png_ptr->chunkdata + slength) + { + png_warning(png_ptr, "Truncated iTXt chunk"); + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + return; + } + + for (text = lang_key; *text; text++) + /* Empty loop */ ; + text++; /* Skip NUL separator */ + if (text >= png_ptr->chunkdata + slength) + { + png_warning(png_ptr, "Malformed iTXt chunk"); + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + return; + } + + prefix_len = text - png_ptr->chunkdata; + + key=png_ptr->chunkdata; + if (comp_flag) + png_decompress_chunk(png_ptr, comp_type, + (size_t)length, prefix_len, &data_len); + else + data_len = png_strlen(png_ptr->chunkdata + prefix_len); + text_ptr = (png_textp)png_malloc_warn(png_ptr, + (png_uint_32)png_sizeof(png_text)); + if (text_ptr == NULL) + { + png_warning(png_ptr, "Not enough memory to process iTXt chunk."); + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + return; + } + text_ptr->compression = (int)comp_flag + 1; + text_ptr->lang_key = png_ptr->chunkdata + (lang_key - key); + text_ptr->lang = png_ptr->chunkdata + (lang - key); + text_ptr->itxt_length = data_len; + text_ptr->text_length = 0; + text_ptr->key = png_ptr->chunkdata; + text_ptr->text = png_ptr->chunkdata + prefix_len; + + ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1); + + png_free(png_ptr, text_ptr); + png_free(png_ptr, png_ptr->chunkdata); + png_ptr->chunkdata = NULL; + if (ret) + png_error(png_ptr, "Insufficient memory to store iTXt chunk."); +} +#endif + +#if defined(PNG_READ_APNG_SUPPORTED) +void /* PRIVATE */ +png_handle_acTL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + png_byte data[8]; + png_uint_32 num_frames; + png_uint_32 num_plays; + png_uint_32 didSet; + + png_debug(1, "in png_handle_acTL"); + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + { + png_error(png_ptr, "Missing IHDR before acTL"); + } + else if (png_ptr->mode & PNG_HAVE_IDAT) + { + png_warning(png_ptr, "Invalid acTL after IDAT skipped"); + png_crc_finish(png_ptr, length); + return; + } + else if (png_ptr->mode & PNG_HAVE_acTL) + { + png_warning(png_ptr, "Duplicate acTL skipped"); + png_crc_finish(png_ptr, length); + return; + } + else if (length != 8) + { + png_warning(png_ptr, "acTL with invalid length skipped"); + png_crc_finish(png_ptr, length); + return; + } + + png_crc_read(png_ptr, data, 8); + png_crc_finish(png_ptr, 0); + + num_frames = png_get_uint_31(png_ptr, data); + num_plays = png_get_uint_31(png_ptr, data + 4); + + /* the set function will do error checking on num_frames */ + didSet = png_set_acTL(png_ptr, info_ptr, num_frames, num_plays); + if(didSet) + png_ptr->mode |= PNG_HAVE_acTL; +} + +void /* PRIVATE */ +png_handle_fcTL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + png_byte data[22]; + png_uint_32 width; + png_uint_32 height; + png_uint_32 x_offset; + png_uint_32 y_offset; + png_uint_16 delay_num; + png_uint_16 delay_den; + png_byte dispose_op; + png_byte blend_op; + + png_debug(1, "in png_handle_fcTL"); + + if (!(png_ptr->mode & PNG_HAVE_IHDR)) + { + png_error(png_ptr, "Missing IHDR before fcTL"); + } + else if (png_ptr->mode & PNG_HAVE_IDAT) + { + /* for any frames other then the first this message may be misleading, + * but correct. PNG_HAVE_IDAT is unset before the frame head is read + * i can't think of a better message */ + png_warning(png_ptr, "Invalid fcTL after IDAT skipped"); + png_crc_finish(png_ptr, length); + return; + } + else if (png_ptr->mode & PNG_HAVE_fcTL) + { + png_warning(png_ptr, "Duplicate fcTL within one frame skipped"); + png_crc_finish(png_ptr, length); + return; + } + else if (length != 26) + { + png_warning(png_ptr, "fcTL with invalid length skipped"); + png_crc_finish(png_ptr, length); + return; + } + + png_ensure_sequence_number(png_ptr, length); + + png_crc_read(png_ptr, data, 22); + png_crc_finish(png_ptr, 0); + + width = png_get_uint_31(png_ptr, data); + height = png_get_uint_31(png_ptr, data + 4); + x_offset = png_get_uint_31(png_ptr, data + 8); + y_offset = png_get_uint_31(png_ptr, data + 12); + delay_num = png_get_uint_16(data + 16); + delay_den = png_get_uint_16(data + 18); + dispose_op = data[20]; + blend_op = data[21]; + + if (png_ptr->num_frames_read == 0 && (x_offset != 0 || y_offset != 0)) + png_error(png_ptr, "fcTL for the first frame must have zero offset"); + if (png_ptr->num_frames_read == 0 && + (width != info_ptr->width || height != info_ptr->height)) + png_error(png_ptr, "size in first frame's fcTL must match " + "the size in IHDR"); + + /* the set function will do more error checking */ + png_set_next_frame_fcTL(png_ptr, info_ptr, width, height, + x_offset, y_offset, delay_num, delay_den, + dispose_op, blend_op); + + png_read_reinit(png_ptr, info_ptr); + + png_ptr->mode |= PNG_HAVE_fcTL; +} + +void /* PRIVATE */ +png_have_info(png_structp png_ptr, png_infop info_ptr) +{ + if((info_ptr->valid & PNG_INFO_acTL) && !(info_ptr->valid & PNG_INFO_fcTL)) + { + png_ptr->apng_flags |= PNG_FIRST_FRAME_HIDDEN; + info_ptr->num_frames++; + } +} + +void /* PRIVATE */ +png_handle_fdAT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + png_ensure_sequence_number(png_ptr, length); + + /* This function is only called from png_read_end(), png_read_info(), + * and png_push_read_chunk() which means that: + * - the user doesn't want to read this frame + * - or this is an out-of-place fdAT + * in either case it is safe to ignore the chunk with a warning */ + png_warning(png_ptr, "ignoring fdAT chunk"); + png_crc_finish(png_ptr, length - 4); +} + +void /* PRIVATE */ +png_ensure_sequence_number(png_structp png_ptr, png_uint_32 length) +{ + png_byte data[4]; + png_uint_32 sequence_number; + + if (length < 4) + png_error(png_ptr, "invalid fcTL or fdAT chunk found"); + + png_crc_read(png_ptr, data, 4); + sequence_number = png_get_uint_31(png_ptr, data); + + if (sequence_number != png_ptr->next_seq_num) + png_error(png_ptr, "fcTL or fdAT chunk with out-of-order sequence " + "number found"); + + png_ptr->next_seq_num++; +} +#endif /* PNG_READ_APNG_SUPPORTED */ +/* This function is called when we haven't found a handler for a + chunk. If there isn't a problem with the chunk itself (ie bad + chunk name, CRC, or a critical chunk), the chunk is silently ignored + -- unless the PNG_FLAG_UNKNOWN_CHUNKS_SUPPORTED flag is on in which + case it will be saved away to be written out later. */ +void /* PRIVATE */ +png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) +{ + png_uint_32 skip = 0; + + png_debug(1, "in png_handle_unknown"); + +#ifdef PNG_USER_LIMITS_SUPPORTED + if (png_ptr->user_chunk_cache_max != 0) + { + if (png_ptr->user_chunk_cache_max == 1) + { + png_crc_finish(png_ptr, length); + return; + } + if (--png_ptr->user_chunk_cache_max == 1) + { + png_warning(png_ptr, "No space in chunk cache for unknown chunk"); + png_crc_finish(png_ptr, length); + return; + } + } +#endif + + if (png_ptr->mode & PNG_HAVE_IDAT) + { +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_CONST PNG_IDAT; +#endif + if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) /* Not an IDAT */ + png_ptr->mode |= PNG_AFTER_IDAT; + } + + if (!(png_ptr->chunk_name[0] & 0x20)) + { +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED + if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name) != + PNG_HANDLE_CHUNK_ALWAYS +#ifdef PNG_READ_USER_CHUNKS_SUPPORTED + && png_ptr->read_user_chunk_fn == NULL +#endif + ) +#endif + png_chunk_error(png_ptr, "unknown critical chunk"); + } + +#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED + if ((png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS) +#ifdef PNG_READ_USER_CHUNKS_SUPPORTED + || (png_ptr->read_user_chunk_fn != NULL) +#endif + ) + { +#ifdef PNG_MAX_MALLOC_64K + if (length > (png_uint_32)65535L) + { + png_warning(png_ptr, "unknown chunk too large to fit in memory"); + skip = length - (png_uint_32)65535L; + length = (png_uint_32)65535L; + } +#endif + png_memcpy((png_charp)png_ptr->unknown_chunk.name, + (png_charp)png_ptr->chunk_name, + png_sizeof(png_ptr->unknown_chunk.name)); + png_ptr->unknown_chunk.name[png_sizeof(png_ptr->unknown_chunk.name)-1] + = '\0'; + png_ptr->unknown_chunk.size = (png_size_t)length; + if (length == 0) + png_ptr->unknown_chunk.data = NULL; + else + { + png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length); + png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length); + } +#ifdef PNG_READ_USER_CHUNKS_SUPPORTED + if (png_ptr->read_user_chunk_fn != NULL) + { + /* Callback to user unknown chunk handler */ + int ret; + ret = (*(png_ptr->read_user_chunk_fn)) + (png_ptr, &png_ptr->unknown_chunk); + if (ret < 0) + png_chunk_error(png_ptr, "error in user chunk"); + if (ret == 0) + { + if (!(png_ptr->chunk_name[0] & 0x20)) +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED + if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name) != + PNG_HANDLE_CHUNK_ALWAYS) +#endif + png_chunk_error(png_ptr, "unknown critical chunk"); + png_set_unknown_chunks(png_ptr, info_ptr, + &png_ptr->unknown_chunk, 1); + } + } + else +#endif + png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1); + png_free(png_ptr, png_ptr->unknown_chunk.data); + png_ptr->unknown_chunk.data = NULL; + } + else +#endif + skip = length; + + png_crc_finish(png_ptr, skip); + +#ifndef PNG_READ_USER_CHUNKS_SUPPORTED + info_ptr = info_ptr; /* Quiet compiler warnings about unused info_ptr */ +#endif +} + +/* This function is called to verify that a chunk name is valid. + This function can't have the "critical chunk check" incorporated + into it, since in the future we will need to be able to call user + functions to handle unknown critical chunks after we check that + the chunk name itself is valid. */ + +#define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97)) + +void /* PRIVATE */ +png_check_chunk_name(png_structp png_ptr, png_bytep chunk_name) +{ + png_debug(1, "in png_check_chunk_name"); + if (isnonalpha(chunk_name[0]) || isnonalpha(chunk_name[1]) || + isnonalpha(chunk_name[2]) || isnonalpha(chunk_name[3])) + { + png_chunk_error(png_ptr, "invalid chunk type"); + } +} + +/* Combines the row recently read in with the existing pixels in the + row. This routine takes care of alpha and transparency if requested. + This routine also handles the two methods of progressive display + of interlaced images, depending on the mask value. + The mask value describes which pixels are to be combined with + the row. The pattern always repeats every 8 pixels, so just 8 + bits are needed. A one indicates the pixel is to be combined, + a zero indicates the pixel is to be skipped. This is in addition + to any alpha or transparency value associated with the pixel. If + you want all pixels to be combined, pass 0xff (255) in mask. */ + +void /* PRIVATE */ +png_combine_row(png_structp png_ptr, png_bytep row, int mask) +{ + png_debug(1, "in png_combine_row"); + if (mask == 0xff) + { + png_memcpy(row, png_ptr->row_buf + 1, + PNG_ROWBYTES(png_ptr->row_info.pixel_depth, png_ptr->width)); + } + else + { + switch (png_ptr->row_info.pixel_depth) + { + case 1: + { + png_bytep sp = png_ptr->row_buf + 1; + png_bytep dp = row; + int s_inc, s_start, s_end; + int m = 0x80; + int shift; + png_uint_32 i; + png_uint_32 row_width = png_ptr->width; + +#ifdef PNG_READ_PACKSWAP_SUPPORTED + if (png_ptr->transformations & PNG_PACKSWAP) + { + s_start = 0; + s_end = 7; + s_inc = 1; + } + else +#endif + { + s_start = 7; + s_end = 0; + s_inc = -1; + } + + shift = s_start; + + for (i = 0; i < row_width; i++) + { + if (m & mask) + { + int value; + + value = (*sp >> shift) & 0x01; + *dp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff); + *dp |= (png_byte)(value << shift); + } + + if (shift == s_end) + { + shift = s_start; + sp++; + dp++; + } + else + shift += s_inc; + + if (m == 1) + m = 0x80; + else + m >>= 1; + } + break; + } + case 2: + { + png_bytep sp = png_ptr->row_buf + 1; + png_bytep dp = row; + int s_start, s_end, s_inc; + int m = 0x80; + int shift; + png_uint_32 i; + png_uint_32 row_width = png_ptr->width; + int value; + +#ifdef PNG_READ_PACKSWAP_SUPPORTED + if (png_ptr->transformations & PNG_PACKSWAP) + { + s_start = 0; + s_end = 6; + s_inc = 2; + } + else +#endif + { + s_start = 6; + s_end = 0; + s_inc = -2; + } + + shift = s_start; + + for (i = 0; i < row_width; i++) + { + if (m & mask) + { + value = (*sp >> shift) & 0x03; + *dp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff); + *dp |= (png_byte)(value << shift); + } + + if (shift == s_end) + { + shift = s_start; + sp++; + dp++; + } + else + shift += s_inc; + if (m == 1) + m = 0x80; + else + m >>= 1; + } + break; + } + case 4: + { + png_bytep sp = png_ptr->row_buf + 1; + png_bytep dp = row; + int s_start, s_end, s_inc; + int m = 0x80; + int shift; + png_uint_32 i; + png_uint_32 row_width = png_ptr->width; + int value; + +#ifdef PNG_READ_PACKSWAP_SUPPORTED + if (png_ptr->transformations & PNG_PACKSWAP) + { + s_start = 0; + s_end = 4; + s_inc = 4; + } + else +#endif + { + s_start = 4; + s_end = 0; + s_inc = -4; + } + shift = s_start; + + for (i = 0; i < row_width; i++) + { + if (m & mask) + { + value = (*sp >> shift) & 0xf; + *dp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff); + *dp |= (png_byte)(value << shift); + } + + if (shift == s_end) + { + shift = s_start; + sp++; + dp++; + } + else + shift += s_inc; + if (m == 1) + m = 0x80; + else + m >>= 1; + } + break; + } + default: + { + png_bytep sp = png_ptr->row_buf + 1; + png_bytep dp = row; + png_size_t pixel_bytes = (png_ptr->row_info.pixel_depth >> 3); + png_uint_32 i; + png_uint_32 row_width = png_ptr->width; + png_byte m = 0x80; + + + for (i = 0; i < row_width; i++) + { + if (m & mask) + { + png_memcpy(dp, sp, pixel_bytes); + } + + sp += pixel_bytes; + dp += pixel_bytes; + + if (m == 1) + m = 0x80; + else + m >>= 1; + } + break; + } + } + } +} + +#ifdef PNG_READ_INTERLACING_SUPPORTED +/* OLD pre-1.0.9 interface: +void png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass, + png_uint_32 transformations) + */ +void /* PRIVATE */ +png_do_read_interlace(png_structp png_ptr) +{ + png_row_infop row_info = &(png_ptr->row_info); + png_bytep row = png_ptr->row_buf + 1; + int pass = png_ptr->pass; + png_uint_32 transformations = png_ptr->transformations; + /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ + /* Offset to next interlace block */ + PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; + + png_debug(1, "in png_do_read_interlace"); + if (row != NULL && row_info != NULL) + { + png_uint_32 final_width; + + final_width = row_info->width * png_pass_inc[pass]; + + switch (row_info->pixel_depth) + { + case 1: + { + png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 3); + png_bytep dp = row + (png_size_t)((final_width - 1) >> 3); + int sshift, dshift; + int s_start, s_end, s_inc; + int jstop = png_pass_inc[pass]; + png_byte v; + png_uint_32 i; + int j; + +#ifdef PNG_READ_PACKSWAP_SUPPORTED + if (transformations & PNG_PACKSWAP) + { + sshift = (int)((row_info->width + 7) & 0x07); + dshift = (int)((final_width + 7) & 0x07); + s_start = 7; + s_end = 0; + s_inc = -1; + } + else +#endif + { + sshift = 7 - (int)((row_info->width + 7) & 0x07); + dshift = 7 - (int)((final_width + 7) & 0x07); + s_start = 0; + s_end = 7; + s_inc = 1; + } + + for (i = 0; i < row_info->width; i++) + { + v = (png_byte)((*sp >> sshift) & 0x01); + for (j = 0; j < jstop; j++) + { + *dp &= (png_byte)((0x7f7f >> (7 - dshift)) & 0xff); + *dp |= (png_byte)(v << dshift); + if (dshift == s_end) + { + dshift = s_start; + dp--; + } + else + dshift += s_inc; + } + if (sshift == s_end) + { + sshift = s_start; + sp--; + } + else + sshift += s_inc; + } + break; + } + case 2: + { + png_bytep sp = row + (png_uint_32)((row_info->width - 1) >> 2); + png_bytep dp = row + (png_uint_32)((final_width - 1) >> 2); + int sshift, dshift; + int s_start, s_end, s_inc; + int jstop = png_pass_inc[pass]; + png_uint_32 i; + +#ifdef PNG_READ_PACKSWAP_SUPPORTED + if (transformations & PNG_PACKSWAP) + { + sshift = (int)(((row_info->width + 3) & 0x03) << 1); + dshift = (int)(((final_width + 3) & 0x03) << 1); + s_start = 6; + s_end = 0; + s_inc = -2; + } + else +#endif + { + sshift = (int)((3 - ((row_info->width + 3) & 0x03)) << 1); + dshift = (int)((3 - ((final_width + 3) & 0x03)) << 1); + s_start = 0; + s_end = 6; + s_inc = 2; + } + + for (i = 0; i < row_info->width; i++) + { + png_byte v; + int j; + + v = (png_byte)((*sp >> sshift) & 0x03); + for (j = 0; j < jstop; j++) + { + *dp &= (png_byte)((0x3f3f >> (6 - dshift)) & 0xff); + *dp |= (png_byte)(v << dshift); + if (dshift == s_end) + { + dshift = s_start; + dp--; + } + else + dshift += s_inc; + } + if (sshift == s_end) + { + sshift = s_start; + sp--; + } + else + sshift += s_inc; + } + break; + } + case 4: + { + png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 1); + png_bytep dp = row + (png_size_t)((final_width - 1) >> 1); + int sshift, dshift; + int s_start, s_end, s_inc; + png_uint_32 i; + int jstop = png_pass_inc[pass]; + +#ifdef PNG_READ_PACKSWAP_SUPPORTED + if (transformations & PNG_PACKSWAP) + { + sshift = (int)(((row_info->width + 1) & 0x01) << 2); + dshift = (int)(((final_width + 1) & 0x01) << 2); + s_start = 4; + s_end = 0; + s_inc = -4; + } + else +#endif + { + sshift = (int)((1 - ((row_info->width + 1) & 0x01)) << 2); + dshift = (int)((1 - ((final_width + 1) & 0x01)) << 2); + s_start = 0; + s_end = 4; + s_inc = 4; + } + + for (i = 0; i < row_info->width; i++) + { + png_byte v = (png_byte)((*sp >> sshift) & 0xf); + int j; + + for (j = 0; j < jstop; j++) + { + *dp &= (png_byte)((0xf0f >> (4 - dshift)) & 0xff); + *dp |= (png_byte)(v << dshift); + if (dshift == s_end) + { + dshift = s_start; + dp--; + } + else + dshift += s_inc; + } + if (sshift == s_end) + { + sshift = s_start; + sp--; + } + else + sshift += s_inc; + } + break; + } + default: + { + png_size_t pixel_bytes = (row_info->pixel_depth >> 3); + png_bytep sp = row + (png_size_t)(row_info->width - 1) + * pixel_bytes; + png_bytep dp = row + (png_size_t)(final_width - 1) * pixel_bytes; + + int jstop = png_pass_inc[pass]; + png_uint_32 i; + + for (i = 0; i < row_info->width; i++) + { + png_byte v[8]; + int j; + + png_memcpy(v, sp, pixel_bytes); + for (j = 0; j < jstop; j++) + { + png_memcpy(dp, v, pixel_bytes); + dp -= pixel_bytes; + } + sp -= pixel_bytes; + } + break; + } + } + row_info->width = final_width; + row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, final_width); + } +#ifndef PNG_READ_PACKSWAP_SUPPORTED + transformations = transformations; /* Silence compiler warning */ +#endif +} +#endif /* PNG_READ_INTERLACING_SUPPORTED */ + +void /* PRIVATE */ +png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row, + png_bytep prev_row, int filter) +{ + png_debug(1, "in png_read_filter_row"); + png_debug2(2, "row = %lu, filter = %d", png_ptr->row_number, filter); + switch (filter) + { + case PNG_FILTER_VALUE_NONE: + break; + case PNG_FILTER_VALUE_SUB: + { + png_uint_32 i; + png_uint_32 istop = row_info->rowbytes; + png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3; + png_bytep rp = row + bpp; + png_bytep lp = row; + + for (i = bpp; i < istop; i++) + { + *rp = (png_byte)(((int)(*rp) + (int)(*lp++)) & 0xff); + rp++; + } + break; + } + case PNG_FILTER_VALUE_UP: + { + png_uint_32 i; + png_uint_32 istop = row_info->rowbytes; + png_bytep rp = row; + png_bytep pp = prev_row; + + for (i = 0; i < istop; i++) + { + *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff); + rp++; + } + break; + } + case PNG_FILTER_VALUE_AVG: + { + png_uint_32 i; + png_bytep rp = row; + png_bytep pp = prev_row; + png_bytep lp = row; + png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3; + png_uint_32 istop = row_info->rowbytes - bpp; + + for (i = 0; i < bpp; i++) + { + *rp = (png_byte)(((int)(*rp) + + ((int)(*pp++) / 2 )) & 0xff); + rp++; + } + + for (i = 0; i < istop; i++) + { + *rp = (png_byte)(((int)(*rp) + + (int)(*pp++ + *lp++) / 2 ) & 0xff); + rp++; + } + break; + } + case PNG_FILTER_VALUE_PAETH: + { + png_uint_32 i; + png_bytep rp = row; + png_bytep pp = prev_row; + png_bytep lp = row; + png_bytep cp = prev_row; + png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3; + png_uint_32 istop=row_info->rowbytes - bpp; + + for (i = 0; i < bpp; i++) + { + *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff); + rp++; + } + + for (i = 0; i < istop; i++) /* Use leftover rp,pp */ + { + int a, b, c, pa, pb, pc, p; + + a = *lp++; + b = *pp++; + c = *cp++; + + p = b - c; + pc = a - c; + +#ifdef PNG_USE_ABS + pa = abs(p); + pb = abs(pc); + pc = abs(p + pc); +#else + pa = p < 0 ? -p : p; + pb = pc < 0 ? -pc : pc; + pc = (p + pc) < 0 ? -(p + pc) : p + pc; +#endif + + /* + if (pa <= pb && pa <= pc) + p = a; + else if (pb <= pc) + p = b; + else + p = c; + */ + + p = (pa <= pb && pa <= pc) ? a : (pb <= pc) ? b : c; + + *rp = (png_byte)(((int)(*rp) + p) & 0xff); + rp++; + } + break; + } + default: + png_warning(png_ptr, "Ignoring bad adaptive filter type"); + *row = 0; + break; + } +} + +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED +void /* PRIVATE */ +png_read_finish_row(png_structp png_ptr) +{ +#ifdef PNG_READ_INTERLACING_SUPPORTED + /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ + + /* Start of interlace block */ + PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0}; + + /* Offset to next interlace block */ + PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; + + /* Start of interlace block in the y direction */ + PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1}; + + /* Offset to next interlace block in the y direction */ + PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; +#endif /* PNG_READ_INTERLACING_SUPPORTED */ + + png_debug(1, "in png_read_finish_row"); + png_ptr->row_number++; + if (png_ptr->row_number < png_ptr->num_rows) + return; + +#ifdef PNG_READ_INTERLACING_SUPPORTED + if (png_ptr->interlaced) + { + png_ptr->row_number = 0; + png_memset_check(png_ptr, png_ptr->prev_row, 0, + png_ptr->rowbytes + 1); + do + { + png_ptr->pass++; + if (png_ptr->pass >= 7) + break; + png_ptr->iwidth = (png_ptr->width + + png_pass_inc[png_ptr->pass] - 1 - + png_pass_start[png_ptr->pass]) / + png_pass_inc[png_ptr->pass]; + + if (!(png_ptr->transformations & PNG_INTERLACE)) + { + png_ptr->num_rows = (png_ptr->height + + png_pass_yinc[png_ptr->pass] - 1 - + png_pass_ystart[png_ptr->pass]) / + png_pass_yinc[png_ptr->pass]; + if (!(png_ptr->num_rows)) + continue; + } + else /* if (png_ptr->transformations & PNG_INTERLACE) */ + break; + } while (png_ptr->iwidth == 0); + + if (png_ptr->pass < 7) + return; + } +#endif /* PNG_READ_INTERLACING_SUPPORTED */ + + if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED)) + { +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_CONST PNG_IDAT; +#endif + char extra; + int ret; + + png_ptr->zstream.next_out = (Byte *)&extra; + png_ptr->zstream.avail_out = (uInt)1; + for (;;) + { + if (!(png_ptr->zstream.avail_in)) + { + while (!png_ptr->idat_size) + { + png_byte chunk_length[4]; + + png_crc_finish(png_ptr, 0); + + png_read_data(png_ptr, chunk_length, 4); + png_ptr->idat_size = png_get_uint_31(png_ptr, chunk_length); + png_reset_crc(png_ptr); + png_crc_read(png_ptr, png_ptr->chunk_name, 4); + if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) + png_error(png_ptr, "Not enough image data"); + + } + png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size; + png_ptr->zstream.next_in = png_ptr->zbuf; + if (png_ptr->zbuf_size > png_ptr->idat_size) + png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size; + png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zstream.avail_in); + png_ptr->idat_size -= png_ptr->zstream.avail_in; + } + ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH); + if (ret == Z_STREAM_END) + { + if (!(png_ptr->zstream.avail_out) || png_ptr->zstream.avail_in || + png_ptr->idat_size) + png_warning(png_ptr, "Extra compressed data."); + png_ptr->mode |= PNG_AFTER_IDAT; + png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED; + break; + } + if (ret != Z_OK) + png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg : + "Decompression Error"); + + if (!(png_ptr->zstream.avail_out)) + { + png_warning(png_ptr, "Extra compressed data."); + png_ptr->mode |= PNG_AFTER_IDAT; + png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED; + break; + } + + } + png_ptr->zstream.avail_out = 0; + } + + if (png_ptr->idat_size || png_ptr->zstream.avail_in) + png_warning(png_ptr, "Extra compression data."); + + inflateReset(&png_ptr->zstream); + + png_ptr->mode |= PNG_AFTER_IDAT; +} +#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ + +void /* PRIVATE */ +png_read_start_row(png_structp png_ptr) +{ +#ifdef PNG_READ_INTERLACING_SUPPORTED + /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ + + /* Start of interlace block */ + PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0}; + + /* Offset to next interlace block */ + PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; + + /* Start of interlace block in the y direction */ + PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1}; + + /* Offset to next interlace block in the y direction */ + PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; +#endif + + int max_pixel_depth; + png_size_t row_bytes; + + png_debug(1, "in png_read_start_row"); + png_ptr->zstream.avail_in = 0; + png_init_read_transformations(png_ptr); +#ifdef PNG_READ_INTERLACING_SUPPORTED + if (png_ptr->interlaced) + { + if (!(png_ptr->transformations & PNG_INTERLACE)) + png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 - + png_pass_ystart[0]) / png_pass_yinc[0]; + else + png_ptr->num_rows = png_ptr->height; + + png_ptr->iwidth = (png_ptr->width + + png_pass_inc[png_ptr->pass] - 1 - + png_pass_start[png_ptr->pass]) / + png_pass_inc[png_ptr->pass]; + } + else +#endif /* PNG_READ_INTERLACING_SUPPORTED */ + { + png_ptr->num_rows = png_ptr->height; + png_ptr->iwidth = png_ptr->width; + } + max_pixel_depth = png_ptr->pixel_depth; + +#ifdef PNG_READ_PACK_SUPPORTED + if ((png_ptr->transformations & PNG_PACK) && png_ptr->bit_depth < 8) + max_pixel_depth = 8; +#endif + +#ifdef PNG_READ_EXPAND_SUPPORTED + if (png_ptr->transformations & PNG_EXPAND) + { + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + { + if (png_ptr->num_trans) + max_pixel_depth = 32; + else + max_pixel_depth = 24; + } + else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY) + { + if (max_pixel_depth < 8) + max_pixel_depth = 8; + if (png_ptr->num_trans) + max_pixel_depth *= 2; + } + else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB) + { + if (png_ptr->num_trans) + { + max_pixel_depth *= 4; + max_pixel_depth /= 3; + } + } + } +#endif + +#ifdef PNG_READ_FILLER_SUPPORTED + if (png_ptr->transformations & (PNG_FILLER)) + { + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + max_pixel_depth = 32; + else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY) + { + if (max_pixel_depth <= 8) + max_pixel_depth = 16; + else + max_pixel_depth = 32; + } + else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB) + { + if (max_pixel_depth <= 32) + max_pixel_depth = 32; + else + max_pixel_depth = 64; + } + } +#endif + +#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED + if (png_ptr->transformations & PNG_GRAY_TO_RGB) + { + if ( +#ifdef PNG_READ_EXPAND_SUPPORTED + (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND)) || +#endif +#ifdef PNG_READ_FILLER_SUPPORTED + (png_ptr->transformations & (PNG_FILLER)) || +#endif + png_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) + { + if (max_pixel_depth <= 16) + max_pixel_depth = 32; + else + max_pixel_depth = 64; + } + else + { + if (max_pixel_depth <= 8) + { + if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + max_pixel_depth = 32; + else + max_pixel_depth = 24; + } + else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + max_pixel_depth = 64; + else + max_pixel_depth = 48; + } + } +#endif + +#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) && \ +defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) + if (png_ptr->transformations & PNG_USER_TRANSFORM) + { + int user_pixel_depth = png_ptr->user_transform_depth* + png_ptr->user_transform_channels; + if (user_pixel_depth > max_pixel_depth) + max_pixel_depth=user_pixel_depth; + } +#endif + + /* Align the width on the next larger 8 pixels. Mainly used + * for interlacing + */ + row_bytes = ((png_ptr->width + 7) & ~((png_uint_32)7)); + /* Calculate the maximum bytes needed, adding a byte and a pixel + * for safety's sake + */ + row_bytes = PNG_ROWBYTES(max_pixel_depth, row_bytes) + + 1 + ((max_pixel_depth + 7) >> 3); +#ifdef PNG_MAX_MALLOC_64K + if (row_bytes > (png_uint_32)65536L) + png_error(png_ptr, "This image requires a row greater than 64KB"); +#endif + + if (row_bytes + 64 > png_ptr->old_big_row_buf_size) + { + png_free(png_ptr, png_ptr->big_row_buf); + if (png_ptr->interlaced) + png_ptr->big_row_buf = (png_bytep)png_calloc(png_ptr, + row_bytes + 64); + else + png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, + row_bytes + 64); + png_ptr->old_big_row_buf_size = row_bytes + 64; + + /* Use 32 bytes of padding before and after row_buf. */ + png_ptr->row_buf = png_ptr->big_row_buf + 32; + png_ptr->old_big_row_buf_size = row_bytes + 64; + } + +#ifdef PNG_MAX_MALLOC_64K + if ((png_uint_32)row_bytes + 1 > (png_uint_32)65536L) + png_error(png_ptr, "This image requires a row greater than 64KB"); +#endif + if ((png_uint_32)row_bytes > (png_uint_32)(PNG_SIZE_MAX - 1)) + png_error(png_ptr, "Row has too many bytes to allocate in memory."); + + if (row_bytes + 1 > png_ptr->old_prev_row_size) + { + png_free(png_ptr, png_ptr->prev_row); + png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)( + row_bytes + 1)); + png_memset_check(png_ptr, png_ptr->prev_row, 0, row_bytes + 1); + png_ptr->old_prev_row_size = row_bytes + 1; + } + + png_ptr->rowbytes = row_bytes; + + png_debug1(3, "width = %lu,", png_ptr->width); + png_debug1(3, "height = %lu,", png_ptr->height); + png_debug1(3, "iwidth = %lu,", png_ptr->iwidth); + png_debug1(3, "num_rows = %lu,", png_ptr->num_rows); + png_debug1(3, "rowbytes = %lu,", png_ptr->rowbytes); + png_debug1(3, "irowbytes = %lu", + PNG_ROWBYTES(png_ptr->pixel_depth, png_ptr->iwidth) + 1); + + png_ptr->flags |= PNG_FLAG_ROW_INIT; +} + +#if defined(PNG_READ_APNG_SUPPORTED) +/* This function is to be called after the main IDAT set has been read and + * before a new IDAT is read. It resets some parts of png_ptr + * to make them usable by the read functions again */ +void /* PRIVATE */ +png_read_reset(png_structp png_ptr) +{ + png_ptr->mode &= ~PNG_HAVE_IDAT; + png_ptr->mode &= ~PNG_AFTER_IDAT; + png_ptr->row_number = 0; + png_ptr->pass = 0; + png_ptr->flags &= ~PNG_FLAG_ROW_INIT; +} + +void /* PRIVATE */ +png_read_reinit(png_structp png_ptr, png_infop info_ptr) +{ + png_ptr->width = info_ptr->next_frame_width; + png_ptr->height = info_ptr->next_frame_height; + png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->width); +} + +/* same as png_read_reset() but for the progressive reader */ +void /* PRIVATE */ +png_progressive_read_reset(png_structp png_ptr) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + /* start of interlace block */ + const int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; + + /* offset to next interlace block */ + const int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; + + /* start of interlace block in the y direction */ + const int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1}; + + /* offset to next interlace block in the y direction */ + const int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2}; +#endif + png_uint_32 row_bytes; + + if (png_ptr->interlaced) + { + if (!(png_ptr->transformations & PNG_INTERLACE)) + png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 - + png_pass_ystart[0]) / png_pass_yinc[0]; + else + png_ptr->num_rows = png_ptr->height; + + png_ptr->iwidth = (png_ptr->width + + png_pass_inc[png_ptr->pass] - 1 - + png_pass_start[png_ptr->pass]) / + png_pass_inc[png_ptr->pass]; + + row_bytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->iwidth) + 1; + + png_ptr->irowbytes = (png_size_t)row_bytes; + if((png_uint_32)png_ptr->irowbytes != row_bytes) + png_error(png_ptr, "png_progressive_read_reset(): Rowbytes " + "overflow"); + } + else + { + png_ptr->num_rows = png_ptr->height; + png_ptr->iwidth = png_ptr->width; + png_ptr->irowbytes = png_ptr->rowbytes + 1; + } + png_ptr->flags &= ~PNG_FLAG_ZLIB_FINISHED; + if (inflateReset(&(png_ptr->zstream)) != Z_OK) + png_error(png_ptr, "inflateReset failed"); + png_ptr->zstream.avail_in = 0; + png_ptr->zstream.next_in = 0; + png_ptr->zstream.next_out = png_ptr->row_buf; + png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes; +} +#endif /* PNG_READ_APNG_SUPPORTED */ +#endif /* PNG_READ_SUPPORTED */ diff --git a/libs/libpng-src/pngset.c b/libs/libpng-src/pngset.c new file mode 100644 index 000000000..28c1c5ee9 --- /dev/null +++ b/libs/libpng-src/pngset.c @@ -0,0 +1,1366 @@ + +/* pngset.c - storage of image information into info struct + * + * Last changed in libpng 1.2.43 [February 25, 2010] + * Copyright (c) 1998-2010 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + * + * The functions here are used during reads to store data from the file + * into the info struct, and during writes to store application data + * into the info struct for writing into the file. This abstracts the + * info struct and allows us to change the structure in the future. + */ + +#define PNG_INTERNAL +#define PNG_NO_PEDANTIC_WARNINGS +#include "png.h" +#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) + +#ifdef PNG_bKGD_SUPPORTED +void PNGAPI +png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background) +{ + png_debug1(1, "in %s storage function", "bKGD"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + png_memcpy(&(info_ptr->background), background, png_sizeof(png_color_16)); + info_ptr->valid |= PNG_INFO_bKGD; +} +#endif + +#ifdef PNG_cHRM_SUPPORTED +#ifdef PNG_FLOATING_POINT_SUPPORTED +void PNGAPI +png_set_cHRM(png_structp png_ptr, png_infop info_ptr, + double white_x, double white_y, double red_x, double red_y, + double green_x, double green_y, double blue_x, double blue_y) +{ + png_debug1(1, "in %s storage function", "cHRM"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + info_ptr->x_white = (float)white_x; + info_ptr->y_white = (float)white_y; + info_ptr->x_red = (float)red_x; + info_ptr->y_red = (float)red_y; + info_ptr->x_green = (float)green_x; + info_ptr->y_green = (float)green_y; + info_ptr->x_blue = (float)blue_x; + info_ptr->y_blue = (float)blue_y; +#ifdef PNG_FIXED_POINT_SUPPORTED + info_ptr->int_x_white = (png_fixed_point)(white_x*100000.+0.5); + info_ptr->int_y_white = (png_fixed_point)(white_y*100000.+0.5); + info_ptr->int_x_red = (png_fixed_point)( red_x*100000.+0.5); + info_ptr->int_y_red = (png_fixed_point)( red_y*100000.+0.5); + info_ptr->int_x_green = (png_fixed_point)(green_x*100000.+0.5); + info_ptr->int_y_green = (png_fixed_point)(green_y*100000.+0.5); + info_ptr->int_x_blue = (png_fixed_point)( blue_x*100000.+0.5); + info_ptr->int_y_blue = (png_fixed_point)( blue_y*100000.+0.5); +#endif + info_ptr->valid |= PNG_INFO_cHRM; +} +#endif /* PNG_FLOATING_POINT_SUPPORTED */ + +#ifdef PNG_FIXED_POINT_SUPPORTED +void PNGAPI +png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr, + png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x, + png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y, + png_fixed_point blue_x, png_fixed_point blue_y) +{ + png_debug1(1, "in %s storage function", "cHRM fixed"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + +#ifdef PNG_CHECK_cHRM_SUPPORTED + if (png_check_cHRM_fixed(png_ptr, + white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y)) +#endif + { + info_ptr->int_x_white = white_x; + info_ptr->int_y_white = white_y; + info_ptr->int_x_red = red_x; + info_ptr->int_y_red = red_y; + info_ptr->int_x_green = green_x; + info_ptr->int_y_green = green_y; + info_ptr->int_x_blue = blue_x; + info_ptr->int_y_blue = blue_y; +#ifdef PNG_FLOATING_POINT_SUPPORTED + info_ptr->x_white = (float)(white_x/100000.); + info_ptr->y_white = (float)(white_y/100000.); + info_ptr->x_red = (float)( red_x/100000.); + info_ptr->y_red = (float)( red_y/100000.); + info_ptr->x_green = (float)(green_x/100000.); + info_ptr->y_green = (float)(green_y/100000.); + info_ptr->x_blue = (float)( blue_x/100000.); + info_ptr->y_blue = (float)( blue_y/100000.); +#endif + info_ptr->valid |= PNG_INFO_cHRM; + } +} +#endif /* PNG_FIXED_POINT_SUPPORTED */ +#endif /* PNG_cHRM_SUPPORTED */ + +#ifdef PNG_gAMA_SUPPORTED +#ifdef PNG_FLOATING_POINT_SUPPORTED +void PNGAPI +png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma) +{ + double png_gamma; + + png_debug1(1, "in %s storage function", "gAMA"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + /* Check for overflow */ + if (file_gamma > 21474.83) + { + png_warning(png_ptr, "Limiting gamma to 21474.83"); + png_gamma=21474.83; + } + else + png_gamma = file_gamma; + info_ptr->gamma = (float)png_gamma; +#ifdef PNG_FIXED_POINT_SUPPORTED + info_ptr->int_gamma = (int)(png_gamma*100000.+.5); +#endif + info_ptr->valid |= PNG_INFO_gAMA; + if (png_gamma == 0.0) + png_warning(png_ptr, "Setting gamma=0"); +} +#endif +void PNGAPI +png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point + int_gamma) +{ + png_fixed_point png_gamma; + + png_debug1(1, "in %s storage function", "gAMA"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + if (int_gamma > (png_fixed_point)PNG_UINT_31_MAX) + { + png_warning(png_ptr, "Limiting gamma to 21474.83"); + png_gamma=PNG_UINT_31_MAX; + } + else + { + if (int_gamma < 0) + { + png_warning(png_ptr, "Setting negative gamma to zero"); + png_gamma = 0; + } + else + png_gamma = int_gamma; + } +#ifdef PNG_FLOATING_POINT_SUPPORTED + info_ptr->gamma = (float)(png_gamma/100000.); +#endif +#ifdef PNG_FIXED_POINT_SUPPORTED + info_ptr->int_gamma = png_gamma; +#endif + info_ptr->valid |= PNG_INFO_gAMA; + if (png_gamma == 0) + png_warning(png_ptr, "Setting gamma=0"); +} +#endif + +#ifdef PNG_hIST_SUPPORTED +void PNGAPI +png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist) +{ + int i; + + png_debug1(1, "in %s storage function", "hIST"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + if (info_ptr->num_palette == 0 || info_ptr->num_palette + > PNG_MAX_PALETTE_LENGTH) + { + png_warning(png_ptr, + "Invalid palette size, hIST allocation skipped."); + return; + } + +#ifdef PNG_FREE_ME_SUPPORTED + png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0); +#endif + /* Changed from info->num_palette to PNG_MAX_PALETTE_LENGTH in + * version 1.2.1 + */ + png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr, + (png_uint_32)(PNG_MAX_PALETTE_LENGTH * png_sizeof(png_uint_16))); + if (png_ptr->hist == NULL) + { + png_warning(png_ptr, "Insufficient memory for hIST chunk data."); + return; + } + + for (i = 0; i < info_ptr->num_palette; i++) + png_ptr->hist[i] = hist[i]; + info_ptr->hist = png_ptr->hist; + info_ptr->valid |= PNG_INFO_hIST; + +#ifdef PNG_FREE_ME_SUPPORTED + info_ptr->free_me |= PNG_FREE_HIST; +#else + png_ptr->flags |= PNG_FLAG_FREE_HIST; +#endif +} +#endif + +void PNGAPI +png_set_IHDR(png_structp png_ptr, png_infop info_ptr, + png_uint_32 width, png_uint_32 height, int bit_depth, + int color_type, int interlace_type, int compression_type, + int filter_type) +{ + png_debug1(1, "in %s storage function", "IHDR"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + info_ptr->width = width; + info_ptr->height = height; + info_ptr->bit_depth = (png_byte)bit_depth; + info_ptr->color_type = (png_byte)color_type; + info_ptr->compression_type = (png_byte)compression_type; + info_ptr->filter_type = (png_byte)filter_type; + info_ptr->interlace_type = (png_byte)interlace_type; + + png_check_IHDR (png_ptr, info_ptr->width, info_ptr->height, + info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type, + info_ptr->compression_type, info_ptr->filter_type); + + if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + info_ptr->channels = 1; + else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR) + info_ptr->channels = 3; + else + info_ptr->channels = 1; + if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA) + info_ptr->channels++; + info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth); + + /* Check for potential overflow */ + if (width > (PNG_UINT_32_MAX + >> 3) /* 8-byte RGBA pixels */ + - 64 /* bigrowbuf hack */ + - 1 /* filter byte */ + - 7*8 /* rounding of width to multiple of 8 pixels */ + - 8) /* extra max_pixel_depth pad */ + info_ptr->rowbytes = (png_size_t)0; + else + info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, width); + +#if defined(PNG_APNG_SUPPORTED) + /* for non-animated png. this may be overritten from an acTL chunk later */ + info_ptr->num_frames = 1; +#endif +} + +#ifdef PNG_oFFs_SUPPORTED +void PNGAPI +png_set_oFFs(png_structp png_ptr, png_infop info_ptr, + png_int_32 offset_x, png_int_32 offset_y, int unit_type) +{ + png_debug1(1, "in %s storage function", "oFFs"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + info_ptr->x_offset = offset_x; + info_ptr->y_offset = offset_y; + info_ptr->offset_unit_type = (png_byte)unit_type; + info_ptr->valid |= PNG_INFO_oFFs; +} +#endif + +#ifdef PNG_pCAL_SUPPORTED +void PNGAPI +png_set_pCAL(png_structp png_ptr, png_infop info_ptr, + png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams, + png_charp units, png_charpp params) +{ + png_uint_32 length; + int i; + + png_debug1(1, "in %s storage function", "pCAL"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + length = png_strlen(purpose) + 1; + png_debug1(3, "allocating purpose for info (%lu bytes)", + (unsigned long)length); + info_ptr->pcal_purpose = (png_charp)png_malloc_warn(png_ptr, length); + if (info_ptr->pcal_purpose == NULL) + { + png_warning(png_ptr, "Insufficient memory for pCAL purpose."); + return; + } + png_memcpy(info_ptr->pcal_purpose, purpose, (png_size_t)length); + + png_debug(3, "storing X0, X1, type, and nparams in info"); + info_ptr->pcal_X0 = X0; + info_ptr->pcal_X1 = X1; + info_ptr->pcal_type = (png_byte)type; + info_ptr->pcal_nparams = (png_byte)nparams; + + length = png_strlen(units) + 1; + png_debug1(3, "allocating units for info (%lu bytes)", + (unsigned long)length); + info_ptr->pcal_units = (png_charp)png_malloc_warn(png_ptr, length); + if (info_ptr->pcal_units == NULL) + { + png_warning(png_ptr, "Insufficient memory for pCAL units."); + return; + } + png_memcpy(info_ptr->pcal_units, units, (png_size_t)length); + + info_ptr->pcal_params = (png_charpp)png_malloc_warn(png_ptr, + (png_uint_32)((nparams + 1) * png_sizeof(png_charp))); + if (info_ptr->pcal_params == NULL) + { + png_warning(png_ptr, "Insufficient memory for pCAL params."); + return; + } + + png_memset(info_ptr->pcal_params, 0, (nparams + 1) * png_sizeof(png_charp)); + + for (i = 0; i < nparams; i++) + { + length = png_strlen(params[i]) + 1; + png_debug2(3, "allocating parameter %d for info (%lu bytes)", i, + (unsigned long)length); + info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length); + if (info_ptr->pcal_params[i] == NULL) + { + png_warning(png_ptr, "Insufficient memory for pCAL parameter."); + return; + } + png_memcpy(info_ptr->pcal_params[i], params[i], (png_size_t)length); + } + + info_ptr->valid |= PNG_INFO_pCAL; +#ifdef PNG_FREE_ME_SUPPORTED + info_ptr->free_me |= PNG_FREE_PCAL; +#endif +} +#endif + +#if defined(PNG_READ_sCAL_SUPPORTED) || defined(PNG_WRITE_sCAL_SUPPORTED) +#ifdef PNG_FLOATING_POINT_SUPPORTED +void PNGAPI +png_set_sCAL(png_structp png_ptr, png_infop info_ptr, + int unit, double width, double height) +{ + png_debug1(1, "in %s storage function", "sCAL"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + info_ptr->scal_unit = (png_byte)unit; + info_ptr->scal_pixel_width = width; + info_ptr->scal_pixel_height = height; + + info_ptr->valid |= PNG_INFO_sCAL; +} +#else +#ifdef PNG_FIXED_POINT_SUPPORTED +void PNGAPI +png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr, + int unit, png_charp swidth, png_charp sheight) +{ + png_uint_32 length; + + png_debug1(1, "in %s storage function", "sCAL"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + info_ptr->scal_unit = (png_byte)unit; + + length = png_strlen(swidth) + 1; + png_debug1(3, "allocating unit for info (%u bytes)", + (unsigned int)length); + info_ptr->scal_s_width = (png_charp)png_malloc_warn(png_ptr, length); + if (info_ptr->scal_s_width == NULL) + { + png_warning(png_ptr, + "Memory allocation failed while processing sCAL."); + return; + } + png_memcpy(info_ptr->scal_s_width, swidth, (png_size_t)length); + + length = png_strlen(sheight) + 1; + png_debug1(3, "allocating unit for info (%u bytes)", + (unsigned int)length); + info_ptr->scal_s_height = (png_charp)png_malloc_warn(png_ptr, length); + if (info_ptr->scal_s_height == NULL) + { + png_free (png_ptr, info_ptr->scal_s_width); + info_ptr->scal_s_width = NULL; + png_warning(png_ptr, + "Memory allocation failed while processing sCAL."); + return; + } + png_memcpy(info_ptr->scal_s_height, sheight, (png_size_t)length); + info_ptr->valid |= PNG_INFO_sCAL; +#ifdef PNG_FREE_ME_SUPPORTED + info_ptr->free_me |= PNG_FREE_SCAL; +#endif +} +#endif +#endif +#endif + +#ifdef PNG_pHYs_SUPPORTED +void PNGAPI +png_set_pHYs(png_structp png_ptr, png_infop info_ptr, + png_uint_32 res_x, png_uint_32 res_y, int unit_type) +{ + png_debug1(1, "in %s storage function", "pHYs"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + info_ptr->x_pixels_per_unit = res_x; + info_ptr->y_pixels_per_unit = res_y; + info_ptr->phys_unit_type = (png_byte)unit_type; + info_ptr->valid |= PNG_INFO_pHYs; +} +#endif + +void PNGAPI +png_set_PLTE(png_structp png_ptr, png_infop info_ptr, + png_colorp palette, int num_palette) +{ + + png_debug1(1, "in %s storage function", "PLTE"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH) + { + if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + png_error(png_ptr, "Invalid palette length"); + else + { + png_warning(png_ptr, "Invalid palette length"); + return; + } + } + + /* It may not actually be necessary to set png_ptr->palette here; + * we do it for backward compatibility with the way the png_handle_tRNS + * function used to do the allocation. + */ +#ifdef PNG_FREE_ME_SUPPORTED + png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0); +#endif + + /* Changed in libpng-1.2.1 to allocate PNG_MAX_PALETTE_LENGTH instead + * of num_palette entries, in case of an invalid PNG file that has + * too-large sample values. + */ + png_ptr->palette = (png_colorp)png_calloc(png_ptr, + PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color)); + png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof(png_color)); + info_ptr->palette = png_ptr->palette; + info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette; + +#ifdef PNG_FREE_ME_SUPPORTED + info_ptr->free_me |= PNG_FREE_PLTE; +#else + png_ptr->flags |= PNG_FLAG_FREE_PLTE; +#endif + + info_ptr->valid |= PNG_INFO_PLTE; +} + +#ifdef PNG_sBIT_SUPPORTED +void PNGAPI +png_set_sBIT(png_structp png_ptr, png_infop info_ptr, + png_color_8p sig_bit) +{ + png_debug1(1, "in %s storage function", "sBIT"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + png_memcpy(&(info_ptr->sig_bit), sig_bit, png_sizeof(png_color_8)); + info_ptr->valid |= PNG_INFO_sBIT; +} +#endif + +#ifdef PNG_sRGB_SUPPORTED +void PNGAPI +png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent) +{ + png_debug1(1, "in %s storage function", "sRGB"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + info_ptr->srgb_intent = (png_byte)intent; + info_ptr->valid |= PNG_INFO_sRGB; +} + +void PNGAPI +png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr, + int intent) +{ +#ifdef PNG_gAMA_SUPPORTED +#ifdef PNG_FLOATING_POINT_SUPPORTED + float file_gamma; +#endif +#ifdef PNG_FIXED_POINT_SUPPORTED + png_fixed_point int_file_gamma; +#endif +#endif +#ifdef PNG_cHRM_SUPPORTED +#ifdef PNG_FLOATING_POINT_SUPPORTED + float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y; +#endif + png_fixed_point int_white_x, int_white_y, int_red_x, int_red_y, int_green_x, + int_green_y, int_blue_x, int_blue_y; +#endif + png_debug1(1, "in %s storage function", "sRGB_gAMA_and_cHRM"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + png_set_sRGB(png_ptr, info_ptr, intent); + +#ifdef PNG_gAMA_SUPPORTED +#ifdef PNG_FLOATING_POINT_SUPPORTED + file_gamma = (float).45455; + png_set_gAMA(png_ptr, info_ptr, file_gamma); +#endif +#ifdef PNG_FIXED_POINT_SUPPORTED + int_file_gamma = 45455L; + png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma); +#endif +#endif + +#ifdef PNG_cHRM_SUPPORTED + int_white_x = 31270L; + int_white_y = 32900L; + int_red_x = 64000L; + int_red_y = 33000L; + int_green_x = 30000L; + int_green_y = 60000L; + int_blue_x = 15000L; + int_blue_y = 6000L; + +#ifdef PNG_FLOATING_POINT_SUPPORTED + white_x = (float).3127; + white_y = (float).3290; + red_x = (float).64; + red_y = (float).33; + green_x = (float).30; + green_y = (float).60; + blue_x = (float).15; + blue_y = (float).06; +#endif + +#ifdef PNG_FIXED_POINT_SUPPORTED + png_set_cHRM_fixed(png_ptr, info_ptr, + int_white_x, int_white_y, int_red_x, int_red_y, int_green_x, + int_green_y, int_blue_x, int_blue_y); +#endif +#ifdef PNG_FLOATING_POINT_SUPPORTED + png_set_cHRM(png_ptr, info_ptr, + white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y); +#endif +#endif /* cHRM */ +} +#endif /* sRGB */ + + +#ifdef PNG_iCCP_SUPPORTED +void PNGAPI +png_set_iCCP(png_structp png_ptr, png_infop info_ptr, + png_charp name, int compression_type, + png_charp profile, png_uint_32 proflen) +{ + png_charp new_iccp_name; + png_charp new_iccp_profile; + png_uint_32 length; + + png_debug1(1, "in %s storage function", "iCCP"); + + if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL) + return; + + length = png_strlen(name)+1; + new_iccp_name = (png_charp)png_malloc_warn(png_ptr, length); + if (new_iccp_name == NULL) + { + png_warning(png_ptr, "Insufficient memory to process iCCP chunk."); + return; + } + png_memcpy(new_iccp_name, name, length); + new_iccp_profile = (png_charp)png_malloc_warn(png_ptr, proflen); + if (new_iccp_profile == NULL) + { + png_free (png_ptr, new_iccp_name); + png_warning(png_ptr, + "Insufficient memory to process iCCP profile."); + return; + } + png_memcpy(new_iccp_profile, profile, (png_size_t)proflen); + + png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0); + + info_ptr->iccp_proflen = proflen; + info_ptr->iccp_name = new_iccp_name; + info_ptr->iccp_profile = new_iccp_profile; + /* Compression is always zero but is here so the API and info structure + * does not have to change if we introduce multiple compression types + */ + info_ptr->iccp_compression = (png_byte)compression_type; +#ifdef PNG_FREE_ME_SUPPORTED + info_ptr->free_me |= PNG_FREE_ICCP; +#endif + info_ptr->valid |= PNG_INFO_iCCP; +} +#endif + +#ifdef PNG_TEXT_SUPPORTED +void PNGAPI +png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr, + int num_text) +{ + int ret; + ret = png_set_text_2(png_ptr, info_ptr, text_ptr, num_text); + if (ret) + png_error(png_ptr, "Insufficient memory to store text"); +} + +int /* PRIVATE */ +png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr, + int num_text) +{ + int i; + + png_debug1(1, "in %s storage function", ((png_ptr == NULL || + png_ptr->chunk_name[0] == '\0') ? + "text" : (png_const_charp)png_ptr->chunk_name)); + + if (png_ptr == NULL || info_ptr == NULL || num_text == 0) + return(0); + + /* Make sure we have enough space in the "text" array in info_struct + * to hold all of the incoming text_ptr objects. + */ + if (info_ptr->num_text + num_text > info_ptr->max_text) + { + if (info_ptr->text != NULL) + { + png_textp old_text; + int old_max; + + old_max = info_ptr->max_text; + info_ptr->max_text = info_ptr->num_text + num_text + 8; + old_text = info_ptr->text; + info_ptr->text = (png_textp)png_malloc_warn(png_ptr, + (png_uint_32)(info_ptr->max_text * png_sizeof(png_text))); + if (info_ptr->text == NULL) + { + png_free(png_ptr, old_text); + return(1); + } + png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max * + png_sizeof(png_text))); + png_free(png_ptr, old_text); + } + else + { + info_ptr->max_text = num_text + 8; + info_ptr->num_text = 0; + info_ptr->text = (png_textp)png_malloc_warn(png_ptr, + (png_uint_32)(info_ptr->max_text * png_sizeof(png_text))); + if (info_ptr->text == NULL) + return(1); +#ifdef PNG_FREE_ME_SUPPORTED + info_ptr->free_me |= PNG_FREE_TEXT; +#endif + } + png_debug1(3, "allocated %d entries for info_ptr->text", + info_ptr->max_text); + } + for (i = 0; i < num_text; i++) + { + png_size_t text_length, key_len; + png_size_t lang_len, lang_key_len; + png_textp textp = &(info_ptr->text[info_ptr->num_text]); + + if (text_ptr[i].key == NULL) + continue; + + key_len = png_strlen(text_ptr[i].key); + + if (text_ptr[i].compression <= 0) + { + lang_len = 0; + lang_key_len = 0; + } + + else +#ifdef PNG_iTXt_SUPPORTED + { + /* Set iTXt data */ + + if (text_ptr[i].lang != NULL) + lang_len = png_strlen(text_ptr[i].lang); + else + lang_len = 0; + if (text_ptr[i].lang_key != NULL) + lang_key_len = png_strlen(text_ptr[i].lang_key); + else + lang_key_len = 0; + } +#else /* PNG_iTXt_SUPPORTED */ + { + png_warning(png_ptr, "iTXt chunk not supported."); + continue; + } +#endif + + if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0') + { + text_length = 0; +#ifdef PNG_iTXt_SUPPORTED + if (text_ptr[i].compression > 0) + textp->compression = PNG_ITXT_COMPRESSION_NONE; + else +#endif + textp->compression = PNG_TEXT_COMPRESSION_NONE; + } + + else + { + text_length = png_strlen(text_ptr[i].text); + textp->compression = text_ptr[i].compression; + } + + textp->key = (png_charp)png_malloc_warn(png_ptr, + (png_uint_32) + (key_len + text_length + lang_len + lang_key_len + 4)); + if (textp->key == NULL) + return(1); + png_debug2(2, "Allocated %lu bytes at %x in png_set_text", + (png_uint_32) + (key_len + lang_len + lang_key_len + text_length + 4), + (int)textp->key); + + png_memcpy(textp->key, text_ptr[i].key,(png_size_t)(key_len)); + *(textp->key + key_len) = '\0'; +#ifdef PNG_iTXt_SUPPORTED + if (text_ptr[i].compression > 0) + { + textp->lang = textp->key + key_len + 1; + png_memcpy(textp->lang, text_ptr[i].lang, lang_len); + *(textp->lang + lang_len) = '\0'; + textp->lang_key = textp->lang + lang_len + 1; + png_memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len); + *(textp->lang_key + lang_key_len) = '\0'; + textp->text = textp->lang_key + lang_key_len + 1; + } + else +#endif + { +#ifdef PNG_iTXt_SUPPORTED + textp->lang=NULL; + textp->lang_key=NULL; +#endif + textp->text = textp->key + key_len + 1; + } + if (text_length) + png_memcpy(textp->text, text_ptr[i].text, + (png_size_t)(text_length)); + *(textp->text + text_length) = '\0'; + +#ifdef PNG_iTXt_SUPPORTED + if (textp->compression > 0) + { + textp->text_length = 0; + textp->itxt_length = text_length; + } + else +#endif + + { + textp->text_length = text_length; +#ifdef PNG_iTXt_SUPPORTED + textp->itxt_length = 0; +#endif + } + info_ptr->num_text++; + png_debug1(3, "transferred text chunk %d", info_ptr->num_text); + } + return(0); +} +#endif + +#ifdef PNG_tIME_SUPPORTED +void PNGAPI +png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time) +{ + png_debug1(1, "in %s storage function", "tIME"); + + if (png_ptr == NULL || info_ptr == NULL || + (png_ptr->mode & PNG_WROTE_tIME)) + return; + + png_memcpy(&(info_ptr->mod_time), mod_time, png_sizeof(png_time)); + info_ptr->valid |= PNG_INFO_tIME; +} +#endif + +#ifdef PNG_tRNS_SUPPORTED +void PNGAPI +png_set_tRNS(png_structp png_ptr, png_infop info_ptr, + png_bytep trans, int num_trans, png_color_16p trans_values) +{ + png_debug1(1, "in %s storage function", "tRNS"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + if (trans != NULL) + { + /* It may not actually be necessary to set png_ptr->trans here; + * we do it for backward compatibility with the way the png_handle_tRNS + * function used to do the allocation. + */ + +#ifdef PNG_FREE_ME_SUPPORTED + png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0); +#endif + + /* Changed from num_trans to PNG_MAX_PALETTE_LENGTH in version 1.2.1 */ + png_ptr->trans = info_ptr->trans = (png_bytep)png_malloc(png_ptr, + (png_uint_32)PNG_MAX_PALETTE_LENGTH); + if (num_trans > 0 && num_trans <= PNG_MAX_PALETTE_LENGTH) + png_memcpy(info_ptr->trans, trans, (png_size_t)num_trans); + } + + if (trans_values != NULL) + { + int sample_max = (1 << info_ptr->bit_depth); + if ((info_ptr->color_type == PNG_COLOR_TYPE_GRAY && + (int)trans_values->gray > sample_max) || + (info_ptr->color_type == PNG_COLOR_TYPE_RGB && + ((int)trans_values->red > sample_max || + (int)trans_values->green > sample_max || + (int)trans_values->blue > sample_max))) + png_warning(png_ptr, + "tRNS chunk has out-of-range samples for bit_depth"); + png_memcpy(&(info_ptr->trans_values), trans_values, + png_sizeof(png_color_16)); + if (num_trans == 0) + num_trans = 1; + } + + info_ptr->num_trans = (png_uint_16)num_trans; + if (num_trans != 0) + { + info_ptr->valid |= PNG_INFO_tRNS; +#ifdef PNG_FREE_ME_SUPPORTED + info_ptr->free_me |= PNG_FREE_TRNS; +#else + png_ptr->flags |= PNG_FLAG_FREE_TRNS; +#endif + } +} +#endif + +#ifdef PNG_sPLT_SUPPORTED +void PNGAPI +png_set_sPLT(png_structp png_ptr, + png_infop info_ptr, png_sPLT_tp entries, int nentries) +/* + * entries - array of png_sPLT_t structures + * to be added to the list of palettes + * in the info structure. + * nentries - number of palette structures to be + * added. + */ +{ + png_sPLT_tp np; + int i; + + if (png_ptr == NULL || info_ptr == NULL) + return; + + np = (png_sPLT_tp)png_malloc_warn(png_ptr, + (info_ptr->splt_palettes_num + nentries) * + (png_uint_32)png_sizeof(png_sPLT_t)); + if (np == NULL) + { + png_warning(png_ptr, "No memory for sPLT palettes."); + return; + } + + png_memcpy(np, info_ptr->splt_palettes, + info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t)); + png_free(png_ptr, info_ptr->splt_palettes); + info_ptr->splt_palettes=NULL; + + for (i = 0; i < nentries; i++) + { + png_sPLT_tp to = np + info_ptr->splt_palettes_num + i; + png_sPLT_tp from = entries + i; + png_uint_32 length; + + length = png_strlen(from->name) + 1; + to->name = (png_charp)png_malloc_warn(png_ptr, length); + if (to->name == NULL) + { + png_warning(png_ptr, + "Out of memory while processing sPLT chunk"); + continue; + } + png_memcpy(to->name, from->name, length); + to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr, + (png_uint_32)(from->nentries * png_sizeof(png_sPLT_entry))); + if (to->entries == NULL) + { + png_warning(png_ptr, + "Out of memory while processing sPLT chunk"); + png_free(png_ptr, to->name); + to->name = NULL; + continue; + } + png_memcpy(to->entries, from->entries, + from->nentries * png_sizeof(png_sPLT_entry)); + to->nentries = from->nentries; + to->depth = from->depth; + } + + info_ptr->splt_palettes = np; + info_ptr->splt_palettes_num += nentries; + info_ptr->valid |= PNG_INFO_sPLT; +#ifdef PNG_FREE_ME_SUPPORTED + info_ptr->free_me |= PNG_FREE_SPLT; +#endif +} +#endif /* PNG_sPLT_SUPPORTED */ + +#if defined(PNG_APNG_SUPPORTED) +png_uint_32 PNGAPI +png_set_acTL(png_structp png_ptr, png_infop info_ptr, + png_uint_32 num_frames, png_uint_32 num_plays) +{ + png_debug1(1, "in %s storage function", "acTL"); + + if (png_ptr == NULL || info_ptr == NULL) + { + png_warning(png_ptr, + "Call to png_set_acTL() with NULL png_ptr " + "or info_ptr ignored"); + return (0); + } + if (num_frames == 0) + { + png_warning(png_ptr, + "Ignoring attempt to set acTL with num_frames zero"); + return (0); + } + if (num_frames > PNG_UINT_31_MAX) + { + png_warning(png_ptr, + "Ignoring attempt to set acTL with num_frames > 2^31-1"); + return (0); + } + if (num_plays > PNG_UINT_31_MAX) + { + png_warning(png_ptr, + "Ignoring attempt to set acTL with num_plays " + "> 2^31-1"); + return (0); + } + + info_ptr->num_frames = num_frames; + info_ptr->num_plays = num_plays; + + info_ptr->valid |= PNG_INFO_acTL; + + return (1); +} + +/* delay_num and delay_den can hold any 16-bit values including zero */ +png_uint_32 PNGAPI +png_set_next_frame_fcTL(png_structp png_ptr, png_infop info_ptr, + png_uint_32 width, png_uint_32 height, + png_uint_32 x_offset, png_uint_32 y_offset, + png_uint_16 delay_num, png_uint_16 delay_den, + png_byte dispose_op, png_byte blend_op) +{ + png_debug1(1, "in %s storage function", "fcTL"); + + if (png_ptr == NULL || info_ptr == NULL) + { + png_warning(png_ptr, + "Call to png_set_fcTL() with NULL png_ptr or info_ptr " + "ignored"); + return (0); + } + + png_ensure_fcTL_is_valid(png_ptr, width, height, x_offset, y_offset, + delay_num, delay_den, dispose_op, blend_op); + + info_ptr->next_frame_width = width; + info_ptr->next_frame_height = height; + info_ptr->next_frame_x_offset = x_offset; + info_ptr->next_frame_y_offset = y_offset; + info_ptr->next_frame_delay_num = delay_num; + info_ptr->next_frame_delay_den = delay_den; + info_ptr->next_frame_dispose_op = dispose_op; + info_ptr->next_frame_blend_op = blend_op; + + info_ptr->valid |= PNG_INFO_fcTL; + + return (1); +} + +void /* PRIVATE */ +png_ensure_fcTL_is_valid(png_structp png_ptr, + png_uint_32 width, png_uint_32 height, + png_uint_32 x_offset, png_uint_32 y_offset, + png_uint_16 delay_num, png_uint_16 delay_den, + png_byte dispose_op, png_byte blend_op) +{ + if (width + x_offset > png_ptr->first_frame_width || + height + y_offset > png_ptr->first_frame_height) + png_error(png_ptr, "dimensions of a frame are greater than" + "the ones in IHDR"); + if (width > PNG_UINT_31_MAX) + png_error(png_ptr, "invalid width in fcTL (> 2^31-1)"); + if (height > PNG_UINT_31_MAX) + png_error(png_ptr, "invalid height in fcTL (> 2^31-1)"); + if (x_offset > PNG_UINT_31_MAX) + png_error(png_ptr, "invalid x_offset in fcTL (> 2^31-1)"); + if (y_offset > PNG_UINT_31_MAX) + png_error(png_ptr, "invalid y_offset in fcTL (> 2^31-1)"); + + if (dispose_op != PNG_DISPOSE_OP_NONE && + dispose_op != PNG_DISPOSE_OP_BACKGROUND && + dispose_op != PNG_DISPOSE_OP_PREVIOUS) + png_error(png_ptr, "invalid dispose_op in fcTL"); + + if (blend_op != PNG_BLEND_OP_SOURCE && + blend_op != PNG_BLEND_OP_OVER) + png_error(png_ptr, "invalid blend_op in fcTL"); + + if (blend_op == PNG_BLEND_OP_OVER) { + if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY) + png_error(png_ptr, "PNG_BLEND_OP_OVER is not valid for " + "color type 'greyscale without alpha'"); + else if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) && + !(png_ptr->color_type & PNG_COLOR_MASK_ALPHA)) + png_error(png_ptr, "PNG_BLEND_OP_OVER is not valid for " + "color type 'truecolor without alpha'"); + } +} + +png_uint_32 PNGAPI +png_set_first_frame_is_hidden(png_structp png_ptr, png_infop info_ptr, + png_byte is_hidden) +{ + png_debug(1, "in png_first_frame_is_hidden()"); + + if (png_ptr == NULL) + return 0; + + if(is_hidden) + png_ptr->apng_flags |= PNG_FIRST_FRAME_HIDDEN; + else + png_ptr->apng_flags &= ~PNG_FIRST_FRAME_HIDDEN; + + return 1; +} +#endif /* PNG_APNG_SUPPORTED */ + +#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED +void PNGAPI +png_set_unknown_chunks(png_structp png_ptr, + png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns) +{ + png_unknown_chunkp np; + int i; + + if (png_ptr == NULL || info_ptr == NULL || num_unknowns == 0) + return; + + np = (png_unknown_chunkp)png_malloc_warn(png_ptr, + (png_uint_32)((info_ptr->unknown_chunks_num + num_unknowns) * + png_sizeof(png_unknown_chunk))); + if (np == NULL) + { + png_warning(png_ptr, + "Out of memory while processing unknown chunk."); + return; + } + + png_memcpy(np, info_ptr->unknown_chunks, + info_ptr->unknown_chunks_num * png_sizeof(png_unknown_chunk)); + png_free(png_ptr, info_ptr->unknown_chunks); + info_ptr->unknown_chunks = NULL; + + for (i = 0; i < num_unknowns; i++) + { + png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i; + png_unknown_chunkp from = unknowns + i; + + png_memcpy((png_charp)to->name, (png_charp)from->name, + png_sizeof(from->name)); + to->name[png_sizeof(to->name)-1] = '\0'; + to->size = from->size; + /* Note our location in the read or write sequence */ + to->location = (png_byte)(png_ptr->mode & 0xff); + + if (from->size == 0) + to->data=NULL; + else + { + to->data = (png_bytep)png_malloc_warn(png_ptr, + (png_uint_32)from->size); + if (to->data == NULL) + { + png_warning(png_ptr, + "Out of memory while processing unknown chunk."); + to->size = 0; + } + else + png_memcpy(to->data, from->data, from->size); + } + } + + info_ptr->unknown_chunks = np; + info_ptr->unknown_chunks_num += num_unknowns; +#ifdef PNG_FREE_ME_SUPPORTED + info_ptr->free_me |= PNG_FREE_UNKN; +#endif +} +void PNGAPI +png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr, + int chunk, int location) +{ + if (png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk < + (int)info_ptr->unknown_chunks_num) + info_ptr->unknown_chunks[chunk].location = (png_byte)location; +} +#endif + +#if defined(PNG_1_0_X) || defined(PNG_1_2_X) +#if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \ + defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED) +void PNGAPI +png_permit_empty_plte (png_structp png_ptr, int empty_plte_permitted) +{ + /* This function is deprecated in favor of png_permit_mng_features() + and will be removed from libpng-1.3.0 */ + + png_debug(1, "in png_permit_empty_plte, DEPRECATED."); + + if (png_ptr == NULL) + return; + png_ptr->mng_features_permitted = (png_byte) + ((png_ptr->mng_features_permitted & (~PNG_FLAG_MNG_EMPTY_PLTE)) | + ((empty_plte_permitted & PNG_FLAG_MNG_EMPTY_PLTE))); +} +#endif +#endif + +#ifdef PNG_MNG_FEATURES_SUPPORTED +png_uint_32 PNGAPI +png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features) +{ + png_debug(1, "in png_permit_mng_features"); + + if (png_ptr == NULL) + return (png_uint_32)0; + png_ptr->mng_features_permitted = + (png_byte)(mng_features & PNG_ALL_MNG_FEATURES); + return (png_uint_32)png_ptr->mng_features_permitted; +} +#endif + +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED +void PNGAPI +png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep + chunk_list, int num_chunks) +{ + png_bytep new_list, p; + int i, old_num_chunks; + if (png_ptr == NULL) + return; + if (num_chunks == 0) + { + if (keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE) + png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS; + else + png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS; + + if (keep == PNG_HANDLE_CHUNK_ALWAYS) + png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS; + else + png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS; + return; + } + if (chunk_list == NULL) + return; + old_num_chunks = png_ptr->num_chunk_list; + new_list=(png_bytep)png_malloc(png_ptr, + (png_uint_32) + (5*(num_chunks + old_num_chunks))); + if (png_ptr->chunk_list != NULL) + { + png_memcpy(new_list, png_ptr->chunk_list, + (png_size_t)(5*old_num_chunks)); + png_free(png_ptr, png_ptr->chunk_list); + png_ptr->chunk_list=NULL; + } + png_memcpy(new_list + 5*old_num_chunks, chunk_list, + (png_size_t)(5*num_chunks)); + for (p = new_list + 5*old_num_chunks + 4, i = 0; inum_chunk_list = old_num_chunks + num_chunks; + png_ptr->chunk_list = new_list; +#ifdef PNG_FREE_ME_SUPPORTED + png_ptr->free_me |= PNG_FREE_LIST; +#endif +} +#endif + +#ifdef PNG_READ_USER_CHUNKS_SUPPORTED +void PNGAPI +png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr, + png_user_chunk_ptr read_user_chunk_fn) +{ + png_debug(1, "in png_set_read_user_chunk_fn"); + + if (png_ptr == NULL) + return; + + png_ptr->read_user_chunk_fn = read_user_chunk_fn; + png_ptr->user_chunk_ptr = user_chunk_ptr; +} +#endif + +#ifdef PNG_INFO_IMAGE_SUPPORTED +void PNGAPI +png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers) +{ + png_debug1(1, "in %s storage function", "rows"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + if (info_ptr->row_pointers && (info_ptr->row_pointers != row_pointers)) + png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0); + info_ptr->row_pointers = row_pointers; + if (row_pointers) + info_ptr->valid |= PNG_INFO_IDAT; +} +#endif + +void PNGAPI +png_set_compression_buffer_size(png_structp png_ptr, + png_uint_32 size) +{ + if (png_ptr == NULL) + return; + png_free(png_ptr, png_ptr->zbuf); + png_ptr->zbuf_size = (png_size_t)size; + png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size); + png_ptr->zstream.next_out = png_ptr->zbuf; + png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; +} + +void PNGAPI +png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask) +{ + if (png_ptr && info_ptr) + info_ptr->valid &= ~mask; +} + + +#ifndef PNG_1_0_X +#ifdef PNG_ASSEMBLER_CODE_SUPPORTED +/* Function was added to libpng 1.2.0 and should always exist by default */ +void PNGAPI +png_set_asm_flags (png_structp png_ptr, png_uint_32 asm_flags) +{ +/* Obsolete as of libpng-1.2.20 and will be removed from libpng-1.4.0 */ + if (png_ptr != NULL) + png_ptr->asm_flags = 0; + asm_flags = asm_flags; /* Quiet the compiler */ +} + +/* This function was added to libpng 1.2.0 */ +void PNGAPI +png_set_mmx_thresholds (png_structp png_ptr, + png_byte mmx_bitdepth_threshold, + png_uint_32 mmx_rowbytes_threshold) +{ +/* Obsolete as of libpng-1.2.20 and will be removed from libpng-1.4.0 */ + if (png_ptr == NULL) + return; + /* Quiet the compiler */ + mmx_bitdepth_threshold = mmx_bitdepth_threshold; + mmx_rowbytes_threshold = mmx_rowbytes_threshold; +} +#endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */ + +#ifdef PNG_SET_USER_LIMITS_SUPPORTED +/* This function was added to libpng 1.2.6 */ +void PNGAPI +png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max, + png_uint_32 user_height_max) +{ + /* Images with dimensions larger than these limits will be + * rejected by png_set_IHDR(). To accept any PNG datastream + * regardless of dimensions, set both limits to 0x7ffffffL. + */ + if (png_ptr == NULL) + return; + png_ptr->user_width_max = user_width_max; + png_ptr->user_height_max = user_height_max; +} +#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */ + + +#ifdef PNG_BENIGN_ERRORS_SUPPORTED +void PNGAPI +png_set_benign_errors(png_structp png_ptr, int allowed) +{ + png_debug(1, "in png_set_benign_errors"); + + if (allowed) + png_ptr->flags |= PNG_FLAG_BENIGN_ERRORS_WARN; + else + png_ptr->flags &= ~PNG_FLAG_BENIGN_ERRORS_WARN; +} +#endif /* PNG_BENIGN_ERRORS_SUPPORTED */ +#endif /* ?PNG_1_0_X */ +#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ diff --git a/libs/libpng-src/pngtest.c b/libs/libpng-src/pngtest.c new file mode 100644 index 000000000..cc3097a2c --- /dev/null +++ b/libs/libpng-src/pngtest.c @@ -0,0 +1,1705 @@ + +/* pngtest.c - a simple test program to test libpng + * + * Last changed in libpng 1.2.43 [February 25, 2010] + * Copyright (c) 1998-2010 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + * + * This program reads in a PNG image, writes it out again, and then + * compares the two files. If the files are identical, this shows that + * the basic chunk handling, filtering, and (de)compression code is working + * properly. It does not currently test all of the transforms, although + * it probably should. + * + * The program will report "FAIL" in certain legitimate cases: + * 1) when the compression level or filter selection method is changed. + * 2) when the maximum IDAT size (PNG_ZBUF_SIZE in pngconf.h) is not 8192. + * 3) unknown unsafe-to-copy ancillary chunks or unknown critical chunks + * exist in the input file. + * 4) others not listed here... + * In these cases, it is best to check with another tool such as "pngcheck" + * to see what the differences between the two files are. + * + * If a filename is given on the command-line, then this file is used + * for the input, rather than the default "pngtest.png". This allows + * testing a wide variety of files easily. You can also test a number + * of files at once by typing "pngtest -m file1.png file2.png ..." + */ + +#define PNG_PEDANTIC_WARNINGS +#include "png.h" + +#ifdef _WIN32_WCE +# if _WIN32_WCE < 211 + __error__ (f|w)printf functions are not supported on old WindowsCE.; +# endif +# include +# include +# define READFILE(file, data, length, check) \ + if (ReadFile(file, data, length, &check, NULL)) check = 0 +# define WRITEFILE(file, data, length, check)) \ + if (WriteFile(file, data, length, &check, NULL)) check = 0 +# define FCLOSE(file) CloseHandle(file) +#else +# include +# include +# define READFILE(file, data, length, check) \ + check=(png_size_t)fread(data, (png_size_t)1, length, file) +# define WRITEFILE(file, data, length, check) \ + check=(png_size_t)fwrite(data, (png_size_t)1, length, file) +# define FCLOSE(file) fclose(file) +#endif + +#ifndef PNG_STDIO_SUPPORTED +# ifdef _WIN32_WCE + typedef HANDLE png_FILE_p; +# else + typedef FILE * png_FILE_p; +# endif +#endif + +/* Makes pngtest verbose so we can find problems (needs to be before png.h) */ +#ifndef PNG_DEBUG +# define PNG_DEBUG 0 +#endif + +#if !PNG_DEBUG +# define SINGLE_ROWBUF_ALLOC /* Makes buffer overruns easier to nail */ +#endif + +/* Turn on CPU timing +#define PNGTEST_TIMING +*/ + +#ifndef PNG_FLOATING_POINT_SUPPORTED +#undef PNGTEST_TIMING +#endif + +#ifdef PNGTEST_TIMING +static float t_start, t_stop, t_decode, t_encode, t_misc; +#include +#endif + +#ifdef PNG_TIME_RFC1123_SUPPORTED +#define PNG_tIME_STRING_LENGTH 29 +static int tIME_chunk_present = 0; +static char tIME_string[PNG_tIME_STRING_LENGTH] = "tIME chunk is not present"; +#endif + +static int verbose = 0; + +int test_one_file PNGARG((PNG_CONST char *inname, PNG_CONST char *outname)); + +#ifdef __TURBOC__ +#include +#endif + +/* Defined so I can write to a file on gui/windowing platforms */ +/* #define STDERR stderr */ +#define STDERR stdout /* For DOS */ + +/* In case a system header (e.g., on AIX) defined jmpbuf */ +#ifdef jmpbuf +# undef jmpbuf +#endif + +/* Define png_jmpbuf() in case we are using a pre-1.0.6 version of libpng */ +#ifndef png_jmpbuf +# define png_jmpbuf(png_ptr) png_ptr->jmpbuf +#endif + +/* Example of using row callbacks to make a simple progress meter */ +static int status_pass = 1; +static int status_dots_requested = 0; +static int status_dots = 1; + +void +#ifdef PNG_1_0_X +PNGAPI +#endif +read_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass); +void +#ifdef PNG_1_0_X +PNGAPI +#endif +read_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass) +{ + if (png_ptr == NULL || row_number > PNG_UINT_31_MAX) + return; + if (status_pass != pass) + { + fprintf(stdout, "\n Pass %d: ", pass); + status_pass = pass; + status_dots = 31; + } + status_dots--; + if (status_dots == 0) + { + fprintf(stdout, "\n "); + status_dots=30; + } + fprintf(stdout, "r"); +} + +void +#ifdef PNG_1_0_X +PNGAPI +#endif +write_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass); +void +#ifdef PNG_1_0_X +PNGAPI +#endif +write_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass) +{ + if (png_ptr == NULL || row_number > PNG_UINT_31_MAX || pass > 7) + return; + fprintf(stdout, "w"); +} + + +#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED +/* Example of using user transform callback (we don't transform anything, + * but merely examine the row filters. We set this to 256 rather than + * 5 in case illegal filter values are present.) + */ +static png_uint_32 filters_used[256]; +void +#ifdef PNG_1_0_X +PNGAPI +#endif +count_filters(png_structp png_ptr, png_row_infop row_info, png_bytep data); +void +#ifdef PNG_1_0_X +PNGAPI +#endif +count_filters(png_structp png_ptr, png_row_infop row_info, png_bytep data) +{ + if (png_ptr != NULL && row_info != NULL) + ++filters_used[*(data - 1)]; +} +#endif + +#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED +/* Example of using user transform callback (we don't transform anything, + * but merely count the zero samples) + */ + +static png_uint_32 zero_samples; + +void +#ifdef PNG_1_0_X +PNGAPI +#endif +count_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data); +void +#ifdef PNG_1_0_X +PNGAPI +#endif +count_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data) +{ + png_bytep dp = data; + if (png_ptr == NULL)return; + + /* Contents of row_info: + * png_uint_32 width width of row + * png_uint_32 rowbytes number of bytes in row + * png_byte color_type color type of pixels + * png_byte bit_depth bit depth of samples + * png_byte channels number of channels (1-4) + * png_byte pixel_depth bits per pixel (depth*channels) + */ + + /* Counts the number of zero samples (or zero pixels if color_type is 3 */ + + if (row_info->color_type == 0 || row_info->color_type == 3) + { + int pos = 0; + png_uint_32 n, nstop; + for (n = 0, nstop=row_info->width; nbit_depth == 1) + { + if (((*dp << pos++ ) & 0x80) == 0) + zero_samples++; + if (pos == 8) + { + pos = 0; + dp++; + } + } + if (row_info->bit_depth == 2) + { + if (((*dp << (pos+=2)) & 0xc0) == 0) + zero_samples++; + if (pos == 8) + { + pos = 0; + dp++; + } + } + if (row_info->bit_depth == 4) + { + if (((*dp << (pos+=4)) & 0xf0) == 0) + zero_samples++; + if (pos == 8) + { + pos = 0; + dp++; + } + } + if (row_info->bit_depth == 8) + if (*dp++ == 0) + zero_samples++; + if (row_info->bit_depth == 16) + { + if ((*dp | *(dp+1)) == 0) + zero_samples++; + dp+=2; + } + } + } + else /* Other color types */ + { + png_uint_32 n, nstop; + int channel; + int color_channels = row_info->channels; + if (row_info->color_type > 3)color_channels--; + + for (n = 0, nstop=row_info->width; nbit_depth == 8) + if (*dp++ == 0) + zero_samples++; + if (row_info->bit_depth == 16) + { + if ((*dp | *(dp+1)) == 0) + zero_samples++; + dp+=2; + } + } + if (row_info->color_type > 3) + { + dp++; + if (row_info->bit_depth == 16) + dp++; + } + } + } +} +#endif /* PNG_WRITE_USER_TRANSFORM_SUPPORTED */ + +static int wrote_question = 0; + +#ifndef PNG_STDIO_SUPPORTED +/* START of code to validate stdio-free compilation */ +/* These copies of the default read/write functions come from pngrio.c and + * pngwio.c. They allow "don't include stdio" testing of the library. + * This is the function that does the actual reading of data. If you are + * not reading from a standard C stream, you should create a replacement + * read_data function and use it at run time with png_set_read_fn(), rather + * than changing the library. + */ + +#ifndef USE_FAR_KEYWORD +static void +pngtest_read_data(png_structp png_ptr, png_bytep data, png_size_t length) +{ + png_size_t check = 0; + png_voidp io_ptr; + + /* fread() returns 0 on error, so it is OK to store this in a png_size_t + * instead of an int, which is what fread() actually returns. + */ + io_ptr = png_get_io_ptr(png_ptr); + if (io_ptr != NULL) + { + READFILE((png_FILE_p)io_ptr, data, length, check); + } + + if (check != length) + { + png_error(png_ptr, "Read Error!"); + } +} +#else +/* This is the model-independent version. Since the standard I/O library + can't handle far buffers in the medium and small models, we have to copy + the data. +*/ + +#define NEAR_BUF_SIZE 1024 +#define MIN(a,b) (a <= b ? a : b) + +static void +pngtest_read_data(png_structp png_ptr, png_bytep data, png_size_t length) +{ + int check; + png_byte *n_data; + png_FILE_p io_ptr; + + /* Check if data really is near. If so, use usual code. */ + n_data = (png_byte *)CVT_PTR_NOCHECK(data); + io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr); + if ((png_bytep)n_data == data) + { + READFILE(io_ptr, n_data, length, check); + } + else + { + png_byte buf[NEAR_BUF_SIZE]; + png_size_t read, remaining, err; + check = 0; + remaining = length; + do + { + read = MIN(NEAR_BUF_SIZE, remaining); + READFILE(io_ptr, buf, 1, err); + png_memcpy(data, buf, read); /* Copy far buffer to near buffer */ + if (err != read) + break; + else + check += err; + data += read; + remaining -= read; + } + while (remaining != 0); + } + if (check != length) + png_error(png_ptr, "read Error"); +} +#endif /* USE_FAR_KEYWORD */ + +#ifdef PNG_WRITE_FLUSH_SUPPORTED +static void +pngtest_flush(png_structp png_ptr) +{ + /* Do nothing; fflush() is said to be just a waste of energy. */ + png_ptr = png_ptr; /* Stifle compiler warning */ +} +#endif + +/* This is the function that does the actual writing of data. If you are + * not writing to a standard C stream, you should create a replacement + * write_data function and use it at run time with png_set_write_fn(), rather + * than changing the library. + */ +#ifndef USE_FAR_KEYWORD +static void +pngtest_write_data(png_structp png_ptr, png_bytep data, png_size_t length) +{ + png_uint_32 check; + + WRITEFILE((png_FILE_p)png_ptr->io_ptr, data, length, check); + if (check != length) + { + png_error(png_ptr, "Write Error"); + } +} +#else +/* This is the model-independent version. Since the standard I/O library + can't handle far buffers in the medium and small models, we have to copy + the data. +*/ + +#define NEAR_BUF_SIZE 1024 +#define MIN(a,b) (a <= b ? a : b) + +static void +pngtest_write_data(png_structp png_ptr, png_bytep data, png_size_t length) +{ + png_uint_32 check; + png_byte *near_data; /* Needs to be "png_byte *" instead of "png_bytep" */ + png_FILE_p io_ptr; + + /* Check if data really is near. If so, use usual code. */ + near_data = (png_byte *)CVT_PTR_NOCHECK(data); + io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr); + if ((png_bytep)near_data == data) + { + WRITEFILE(io_ptr, near_data, length, check); + } + else + { + png_byte buf[NEAR_BUF_SIZE]; + png_size_t written, remaining, err; + check = 0; + remaining = length; + do + { + written = MIN(NEAR_BUF_SIZE, remaining); + png_memcpy(buf, data, written); /* Copy far buffer to near buffer */ + WRITEFILE(io_ptr, buf, written, err); + if (err != written) + break; + else + check += err; + data += written; + remaining -= written; + } + while (remaining != 0); + } + if (check != length) + { + png_error(png_ptr, "Write Error"); + } +} +#endif /* USE_FAR_KEYWORD */ + +/* This function is called when there is a warning, but the library thinks + * it can continue anyway. Replacement functions don't have to do anything + * here if you don't want to. In the default configuration, png_ptr is + * not used, but it is passed in case it may be useful. + */ +static void +pngtest_warning(png_structp png_ptr, png_const_charp message) +{ + PNG_CONST char *name = "UNKNOWN (ERROR!)"; + char *test; + test = png_get_error_ptr(png_ptr); + if (test == NULL) + fprintf(STDERR, "%s: libpng warning: %s\n", name, message); + else + fprintf(STDERR, "%s: libpng warning: %s\n", test, message); +} + +/* This is the default error handling function. Note that replacements for + * this function MUST NOT RETURN, or the program will likely crash. This + * function is used by default, or if the program supplies NULL for the + * error function pointer in png_set_error_fn(). + */ +static void +pngtest_error(png_structp png_ptr, png_const_charp message) +{ + pngtest_warning(png_ptr, message); + /* We can return because png_error calls the default handler, which is + * actually OK in this case. + */ +} +#endif /* !PNG_STDIO_SUPPORTED */ +/* END of code to validate stdio-free compilation */ + +/* START of code to validate memory allocation and deallocation */ +#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG + +/* Allocate memory. For reasonable files, size should never exceed + * 64K. However, zlib may allocate more then 64K if you don't tell + * it not to. See zconf.h and png.h for more information. zlib does + * need to allocate exactly 64K, so whatever you call here must + * have the ability to do that. + * + * This piece of code can be compiled to validate max 64K allocations + * by setting MAXSEG_64K in zlib zconf.h *or* PNG_MAX_MALLOC_64K. + */ +typedef struct memory_information +{ + png_uint_32 size; + png_voidp pointer; + struct memory_information FAR *next; +} memory_information; +typedef memory_information FAR *memory_infop; + +static memory_infop pinformation = NULL; +static int current_allocation = 0; +static int maximum_allocation = 0; +static int total_allocation = 0; +static int num_allocations = 0; + +png_voidp png_debug_malloc PNGARG((png_structp png_ptr, png_uint_32 size)); +void png_debug_free PNGARG((png_structp png_ptr, png_voidp ptr)); + +png_voidp +png_debug_malloc(png_structp png_ptr, png_uint_32 size) +{ + + /* png_malloc has already tested for NULL; png_create_struct calls + * png_debug_malloc directly, with png_ptr == NULL which is OK + */ + + if (size == 0) + return (NULL); + + /* This calls the library allocator twice, once to get the requested + buffer and once to get a new free list entry. */ + { + /* Disable malloc_fn and free_fn */ + memory_infop pinfo; + png_set_mem_fn(png_ptr, NULL, NULL, NULL); + pinfo = (memory_infop)png_malloc(png_ptr, + (png_uint_32)png_sizeof(*pinfo)); + pinfo->size = size; + current_allocation += size; + total_allocation += size; + num_allocations ++; + if (current_allocation > maximum_allocation) + maximum_allocation = current_allocation; + pinfo->pointer = (png_voidp)png_malloc(png_ptr, size); + /* Restore malloc_fn and free_fn */ + png_set_mem_fn(png_ptr, + png_voidp_NULL, (png_malloc_ptr)png_debug_malloc, + (png_free_ptr)png_debug_free); + if (size != 0 && pinfo->pointer == NULL) + { + current_allocation -= size; + total_allocation -= size; + png_error(png_ptr, + "out of memory in pngtest->png_debug_malloc."); + } + pinfo->next = pinformation; + pinformation = pinfo; + /* Make sure the caller isn't assuming zeroed memory. */ + png_memset(pinfo->pointer, 0xdd, pinfo->size); + if (verbose) + printf("png_malloc %lu bytes at %x\n", (unsigned long)size, + pinfo->pointer); + return (png_voidp)(pinfo->pointer); + } +} + +/* Free a pointer. It is removed from the list at the same time. */ +void +png_debug_free(png_structp png_ptr, png_voidp ptr) +{ + if (png_ptr == NULL) + fprintf(STDERR, "NULL pointer to png_debug_free.\n"); + if (ptr == 0) + { +#if 0 /* This happens all the time. */ + fprintf(STDERR, "WARNING: freeing NULL pointer\n"); +#endif + return; + } + + /* Unlink the element from the list. */ + { + memory_infop FAR *ppinfo = &pinformation; + for (;;) + { + memory_infop pinfo = *ppinfo; + if (pinfo->pointer == ptr) + { + *ppinfo = pinfo->next; + current_allocation -= pinfo->size; + if (current_allocation < 0) + fprintf(STDERR, "Duplicate free of memory\n"); + /* We must free the list element too, but first kill + the memory that is to be freed. */ + png_memset(ptr, 0x55, pinfo->size); + png_free_default(png_ptr, pinfo); + pinfo = NULL; + break; + } + if (pinfo->next == NULL) + { + fprintf(STDERR, "Pointer %x not found\n", (unsigned int)ptr); + break; + } + ppinfo = &pinfo->next; + } + } + + /* Finally free the data. */ + if (verbose) + printf("Freeing %x\n", ptr); + png_free_default(png_ptr, ptr); + ptr = NULL; +} +#endif /* PNG_USER_MEM_SUPPORTED && PNG_DEBUG */ +/* END of code to test memory allocation/deallocation */ + + +/* Demonstration of user chunk support of the sTER and vpAg chunks */ +#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED + +/* (sTER is a public chunk not yet known by libpng. vpAg is a private +chunk used in ImageMagick to store "virtual page" size). */ + +static png_uint_32 user_chunk_data[4]; + + /* 0: sTER mode + 1 + * 1: vpAg width + * 2: vpAg height + * 3: vpAg units + */ + +static int read_user_chunk_callback(png_struct *png_ptr, + png_unknown_chunkp chunk) +{ + png_uint_32 + *my_user_chunk_data; + + /* Return one of the following: + * return (-n); chunk had an error + * return (0); did not recognize + * return (n); success + * + * The unknown chunk structure contains the chunk data: + * png_byte name[5]; + * png_byte *data; + * png_size_t size; + * + * Note that libpng has already taken care of the CRC handling. + */ + + if (chunk->name[0] == 115 && chunk->name[1] == 84 && /* s T */ + chunk->name[2] == 69 && chunk->name[3] == 82) /* E R */ + { + /* Found sTER chunk */ + if (chunk->size != 1) + return (-1); /* Error return */ + if (chunk->data[0] != 0 && chunk->data[0] != 1) + return (-1); /* Invalid mode */ + my_user_chunk_data=(png_uint_32 *) png_get_user_chunk_ptr(png_ptr); + my_user_chunk_data[0]=chunk->data[0]+1; + return (1); + } + + if (chunk->name[0] != 118 || chunk->name[1] != 112 || /* v p */ + chunk->name[2] != 65 || chunk->name[3] != 103) /* A g */ + return (0); /* Did not recognize */ + + /* Found ImageMagick vpAg chunk */ + + if (chunk->size != 9) + return (-1); /* Error return */ + + my_user_chunk_data=(png_uint_32 *) png_get_user_chunk_ptr(png_ptr); + + my_user_chunk_data[1]=png_get_uint_31(png_ptr, chunk->data); + my_user_chunk_data[2]=png_get_uint_31(png_ptr, chunk->data + 4); + my_user_chunk_data[3]=(png_uint_32)chunk->data[8]; + + return (1); + +} +#endif +/* END of code to demonstrate user chunk support */ + +/* Test one file */ +int +test_one_file(PNG_CONST char *inname, PNG_CONST char *outname) +{ + static png_FILE_p fpin; + static png_FILE_p fpout; /* "static" prevents setjmp corruption */ + png_structp read_ptr; + png_infop read_info_ptr, end_info_ptr; +#ifdef PNG_WRITE_SUPPORTED + png_structp write_ptr; + png_infop write_info_ptr; + png_infop write_end_info_ptr; +#else + png_structp write_ptr = NULL; + png_infop write_info_ptr = NULL; + png_infop write_end_info_ptr = NULL; +#endif + png_bytep row_buf; + png_uint_32 y; + png_uint_32 width, height; + int num_pass, pass; + int bit_depth, color_type; +#ifdef PNG_SETJMP_SUPPORTED +#ifdef USE_FAR_KEYWORD + jmp_buf jmpbuf; +#endif +#endif + +#ifdef _WIN32_WCE + TCHAR path[MAX_PATH]; +#endif + char inbuf[256], outbuf[256]; + + row_buf = NULL; + +#ifdef _WIN32_WCE + MultiByteToWideChar(CP_ACP, 0, inname, -1, path, MAX_PATH); + if ((fpin = CreateFile(path, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, + NULL)) == INVALID_HANDLE_VALUE) +#else + if ((fpin = fopen(inname, "rb")) == NULL) +#endif + { + fprintf(STDERR, "Could not find input file %s\n", inname); + return (1); + } + +#ifdef _WIN32_WCE + MultiByteToWideChar(CP_ACP, 0, outname, -1, path, MAX_PATH); + if ((fpout = CreateFile(path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, + 0, NULL)) == INVALID_HANDLE_VALUE) +#else + if ((fpout = fopen(outname, "wb")) == NULL) +#endif + { + fprintf(STDERR, "Could not open output file %s\n", outname); + FCLOSE(fpin); + return (1); + } + + png_debug(0, "Allocating read and write structures"); +#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG + read_ptr = + png_create_read_struct_2(PNG_LIBPNG_VER_STRING, png_voidp_NULL, + png_error_ptr_NULL, png_error_ptr_NULL, png_voidp_NULL, + (png_malloc_ptr)png_debug_malloc, (png_free_ptr)png_debug_free); +#else + read_ptr = + png_create_read_struct(PNG_LIBPNG_VER_STRING, png_voidp_NULL, + png_error_ptr_NULL, png_error_ptr_NULL); +#endif +#ifndef PNG_STDIO_SUPPORTED + png_set_error_fn(read_ptr, (png_voidp)inname, pngtest_error, + pngtest_warning); +#endif + +#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED + user_chunk_data[0] = 0; + user_chunk_data[1] = 0; + user_chunk_data[2] = 0; + user_chunk_data[3] = 0; + png_set_read_user_chunk_fn(read_ptr, user_chunk_data, + read_user_chunk_callback); + +#endif +#ifdef PNG_WRITE_SUPPORTED +#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG + write_ptr = + png_create_write_struct_2(PNG_LIBPNG_VER_STRING, png_voidp_NULL, + png_error_ptr_NULL, png_error_ptr_NULL, png_voidp_NULL, + (png_malloc_ptr)png_debug_malloc, (png_free_ptr)png_debug_free); +#else + write_ptr = + png_create_write_struct(PNG_LIBPNG_VER_STRING, png_voidp_NULL, + png_error_ptr_NULL, png_error_ptr_NULL); +#endif +#ifndef PNG_STDIO_SUPPORTED + png_set_error_fn(write_ptr, (png_voidp)inname, pngtest_error, + pngtest_warning); +#endif +#endif + png_debug(0, "Allocating read_info, write_info and end_info structures"); + read_info_ptr = png_create_info_struct(read_ptr); + end_info_ptr = png_create_info_struct(read_ptr); +#ifdef PNG_WRITE_SUPPORTED + write_info_ptr = png_create_info_struct(write_ptr); + write_end_info_ptr = png_create_info_struct(write_ptr); +#endif + +#ifdef PNG_SETJMP_SUPPORTED + png_debug(0, "Setting jmpbuf for read struct"); +#ifdef USE_FAR_KEYWORD + if (setjmp(jmpbuf)) +#else + if (setjmp(png_jmpbuf(read_ptr))) +#endif + { + fprintf(STDERR, "%s -> %s: libpng read error\n", inname, outname); + png_free(read_ptr, row_buf); + row_buf = NULL; + png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr); +#ifdef PNG_WRITE_SUPPORTED + png_destroy_info_struct(write_ptr, &write_end_info_ptr); + png_destroy_write_struct(&write_ptr, &write_info_ptr); +#endif + FCLOSE(fpin); + FCLOSE(fpout); + return (1); + } +#ifdef USE_FAR_KEYWORD + png_memcpy(png_jmpbuf(read_ptr), jmpbuf, png_sizeof(jmp_buf)); +#endif + +#ifdef PNG_WRITE_SUPPORTED + png_debug(0, "Setting jmpbuf for write struct"); +#ifdef USE_FAR_KEYWORD + if (setjmp(jmpbuf)) +#else + if (setjmp(png_jmpbuf(write_ptr))) +#endif + { + fprintf(STDERR, "%s -> %s: libpng write error\n", inname, outname); + png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr); + png_destroy_info_struct(write_ptr, &write_end_info_ptr); +#ifdef PNG_WRITE_SUPPORTED + png_destroy_write_struct(&write_ptr, &write_info_ptr); +#endif + FCLOSE(fpin); + FCLOSE(fpout); + return (1); + } +#ifdef USE_FAR_KEYWORD + png_memcpy(png_jmpbuf(write_ptr), jmpbuf, png_sizeof(jmp_buf)); +#endif +#endif +#endif + + png_debug(0, "Initializing input and output streams"); +#ifdef PNG_STDIO_SUPPORTED + png_init_io(read_ptr, fpin); +# ifdef PNG_WRITE_SUPPORTED + png_init_io(write_ptr, fpout); +# endif +#else + png_set_read_fn(read_ptr, (png_voidp)fpin, pngtest_read_data); +# ifdef PNG_WRITE_SUPPORTED + png_set_write_fn(write_ptr, (png_voidp)fpout, pngtest_write_data, +# ifdef PNG_WRITE_FLUSH_SUPPORTED + pngtest_flush); +# else + NULL); +# endif +# endif +#endif + if (status_dots_requested == 1) + { +#ifdef PNG_WRITE_SUPPORTED + png_set_write_status_fn(write_ptr, write_row_callback); +#endif + png_set_read_status_fn(read_ptr, read_row_callback); + } + else + { +#ifdef PNG_WRITE_SUPPORTED + png_set_write_status_fn(write_ptr, png_write_status_ptr_NULL); +#endif + png_set_read_status_fn(read_ptr, png_read_status_ptr_NULL); + } + +#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED + { + int i; + for (i = 0; i<256; i++) + filters_used[i] = 0; + png_set_read_user_transform_fn(read_ptr, count_filters); + } +#endif +#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED + zero_samples = 0; + png_set_write_user_transform_fn(write_ptr, count_zero_samples); +#endif + +#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED +# ifndef PNG_HANDLE_CHUNK_ALWAYS +# define PNG_HANDLE_CHUNK_ALWAYS 3 +# endif + png_set_keep_unknown_chunks(read_ptr, PNG_HANDLE_CHUNK_ALWAYS, + png_bytep_NULL, 0); +#endif +#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED +# ifndef PNG_HANDLE_CHUNK_IF_SAFE +# define PNG_HANDLE_CHUNK_IF_SAFE 2 +# endif + png_set_keep_unknown_chunks(write_ptr, PNG_HANDLE_CHUNK_IF_SAFE, + png_bytep_NULL, 0); +#endif + + png_debug(0, "Reading info struct"); + png_read_info(read_ptr, read_info_ptr); + + png_debug(0, "Transferring info struct"); + { + int interlace_type, compression_type, filter_type; + + if (png_get_IHDR(read_ptr, read_info_ptr, &width, &height, &bit_depth, + &color_type, &interlace_type, &compression_type, &filter_type)) + { + png_set_IHDR(write_ptr, write_info_ptr, width, height, bit_depth, +#ifdef PNG_WRITE_INTERLACING_SUPPORTED + color_type, interlace_type, compression_type, filter_type); +#else + color_type, PNG_INTERLACE_NONE, compression_type, filter_type); +#endif + } + } +#ifdef PNG_FIXED_POINT_SUPPORTED +#ifdef PNG_cHRM_SUPPORTED + { + png_fixed_point white_x, white_y, red_x, red_y, green_x, green_y, blue_x, + blue_y; + if (png_get_cHRM_fixed(read_ptr, read_info_ptr, &white_x, &white_y, + &red_x, &red_y, &green_x, &green_y, &blue_x, &blue_y)) + { + png_set_cHRM_fixed(write_ptr, write_info_ptr, white_x, white_y, red_x, + red_y, green_x, green_y, blue_x, blue_y); + } + } +#endif +#ifdef PNG_gAMA_SUPPORTED + { + png_fixed_point gamma; + + if (png_get_gAMA_fixed(read_ptr, read_info_ptr, &gamma)) + png_set_gAMA_fixed(write_ptr, write_info_ptr, gamma); + } +#endif +#else /* Use floating point versions */ +#ifdef PNG_FLOATING_POINT_SUPPORTED +#ifdef PNG_cHRM_SUPPORTED + { + double white_x, white_y, red_x, red_y, green_x, green_y, blue_x, + blue_y; + if (png_get_cHRM(read_ptr, read_info_ptr, &white_x, &white_y, &red_x, + &red_y, &green_x, &green_y, &blue_x, &blue_y)) + { + png_set_cHRM(write_ptr, write_info_ptr, white_x, white_y, red_x, + red_y, green_x, green_y, blue_x, blue_y); + } + } +#endif +#ifdef PNG_gAMA_SUPPORTED + { + double gamma; + + if (png_get_gAMA(read_ptr, read_info_ptr, &gamma)) + png_set_gAMA(write_ptr, write_info_ptr, gamma); + } +#endif +#endif /* Floating point */ +#endif /* Fixed point */ +#ifdef PNG_iCCP_SUPPORTED + { + png_charp name; + png_charp profile; + png_uint_32 proflen; + int compression_type; + + if (png_get_iCCP(read_ptr, read_info_ptr, &name, &compression_type, + &profile, &proflen)) + { + png_set_iCCP(write_ptr, write_info_ptr, name, compression_type, + profile, proflen); + } + } +#endif +#ifdef PNG_sRGB_SUPPORTED + { + int intent; + + if (png_get_sRGB(read_ptr, read_info_ptr, &intent)) + png_set_sRGB(write_ptr, write_info_ptr, intent); + } +#endif + { + png_colorp palette; + int num_palette; + + if (png_get_PLTE(read_ptr, read_info_ptr, &palette, &num_palette)) + png_set_PLTE(write_ptr, write_info_ptr, palette, num_palette); + } +#ifdef PNG_bKGD_SUPPORTED + { + png_color_16p background; + + if (png_get_bKGD(read_ptr, read_info_ptr, &background)) + { + png_set_bKGD(write_ptr, write_info_ptr, background); + } + } +#endif +#ifdef PNG_hIST_SUPPORTED + { + png_uint_16p hist; + + if (png_get_hIST(read_ptr, read_info_ptr, &hist)) + png_set_hIST(write_ptr, write_info_ptr, hist); + } +#endif +#ifdef PNG_oFFs_SUPPORTED + { + png_int_32 offset_x, offset_y; + int unit_type; + + if (png_get_oFFs(read_ptr, read_info_ptr, &offset_x, &offset_y, + &unit_type)) + { + png_set_oFFs(write_ptr, write_info_ptr, offset_x, offset_y, unit_type); + } + } +#endif +#ifdef PNG_pCAL_SUPPORTED + { + png_charp purpose, units; + png_charpp params; + png_int_32 X0, X1; + int type, nparams; + + if (png_get_pCAL(read_ptr, read_info_ptr, &purpose, &X0, &X1, &type, + &nparams, &units, ¶ms)) + { + png_set_pCAL(write_ptr, write_info_ptr, purpose, X0, X1, type, + nparams, units, params); + } + } +#endif +#ifdef PNG_pHYs_SUPPORTED + { + png_uint_32 res_x, res_y; + int unit_type; + + if (png_get_pHYs(read_ptr, read_info_ptr, &res_x, &res_y, &unit_type)) + png_set_pHYs(write_ptr, write_info_ptr, res_x, res_y, unit_type); + } +#endif +#ifdef PNG_sBIT_SUPPORTED + { + png_color_8p sig_bit; + + if (png_get_sBIT(read_ptr, read_info_ptr, &sig_bit)) + png_set_sBIT(write_ptr, write_info_ptr, sig_bit); + } +#endif +#ifdef PNG_sCAL_SUPPORTED +#ifdef PNG_FLOATING_POINT_SUPPORTED + { + int unit; + double scal_width, scal_height; + + if (png_get_sCAL(read_ptr, read_info_ptr, &unit, &scal_width, + &scal_height)) + { + png_set_sCAL(write_ptr, write_info_ptr, unit, scal_width, scal_height); + } + } +#else +#ifdef PNG_FIXED_POINT_SUPPORTED + { + int unit; + png_charp scal_width, scal_height; + + if (png_get_sCAL_s(read_ptr, read_info_ptr, &unit, &scal_width, + &scal_height)) + { + png_set_sCAL_s(write_ptr, write_info_ptr, unit, scal_width, + scal_height); + } + } +#endif +#endif +#endif +#ifdef PNG_TEXT_SUPPORTED + { + png_textp text_ptr; + int num_text; + + if (png_get_text(read_ptr, read_info_ptr, &text_ptr, &num_text) > 0) + { + png_debug1(0, "Handling %d iTXt/tEXt/zTXt chunks", num_text); + png_set_text(write_ptr, write_info_ptr, text_ptr, num_text); + } + } +#endif +#ifdef PNG_tIME_SUPPORTED + { + png_timep mod_time; + + if (png_get_tIME(read_ptr, read_info_ptr, &mod_time)) + { + png_set_tIME(write_ptr, write_info_ptr, mod_time); +#ifdef PNG_TIME_RFC1123_SUPPORTED + /* We have to use png_memcpy instead of "=" because the string + * pointed to by png_convert_to_rfc1123() gets free'ed before + * we use it. + */ + png_memcpy(tIME_string, + png_convert_to_rfc1123(read_ptr, mod_time), + png_sizeof(tIME_string)); + tIME_string[png_sizeof(tIME_string) - 1] = '\0'; + tIME_chunk_present++; +#endif /* PNG_TIME_RFC1123_SUPPORTED */ + } + } +#endif +#ifdef PNG_tRNS_SUPPORTED + { + png_bytep trans; + int num_trans; + png_color_16p trans_values; + + if (png_get_tRNS(read_ptr, read_info_ptr, &trans, &num_trans, + &trans_values)) + { + int sample_max = (1 << bit_depth); + /* libpng doesn't reject a tRNS chunk with out-of-range samples */ + if (!((color_type == PNG_COLOR_TYPE_GRAY && + (int)trans_values->gray > sample_max) || + (color_type == PNG_COLOR_TYPE_RGB && + ((int)trans_values->red > sample_max || + (int)trans_values->green > sample_max || + (int)trans_values->blue > sample_max)))) + png_set_tRNS(write_ptr, write_info_ptr, trans, num_trans, + trans_values); + } + } +#endif +#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED + { + png_unknown_chunkp unknowns; + int num_unknowns = (int)png_get_unknown_chunks(read_ptr, read_info_ptr, + &unknowns); + if (num_unknowns) + { + png_size_t i; + png_set_unknown_chunks(write_ptr, write_info_ptr, unknowns, + num_unknowns); + /* Copy the locations from the read_info_ptr. The automatically + * generated locations in write_info_ptr are wrong because we + * haven't written anything yet. + */ + for (i = 0; i < (png_size_t)num_unknowns; i++) + png_set_unknown_chunk_location(write_ptr, write_info_ptr, i, + unknowns[i].location); + } + } +#endif + +#ifdef PNG_WRITE_SUPPORTED + png_debug(0, "Writing info struct"); + +/* If we wanted, we could write info in two steps: + * png_write_info_before_PLTE(write_ptr, write_info_ptr); + */ + png_write_info(write_ptr, write_info_ptr); + +#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED + if (user_chunk_data[0] != 0) + { + png_byte png_sTER[5] = {115, 84, 69, 82, '\0'}; + + unsigned char + ster_chunk_data[1]; + + if (verbose) + fprintf(STDERR, "\n stereo mode = %lu\n", + (unsigned long)(user_chunk_data[0] - 1)); + ster_chunk_data[0]=(unsigned char)(user_chunk_data[0] - 1); + png_write_chunk(write_ptr, png_sTER, ster_chunk_data, 1); + } + if (user_chunk_data[1] != 0 || user_chunk_data[2] != 0) + { + png_byte png_vpAg[5] = {118, 112, 65, 103, '\0'}; + + unsigned char + vpag_chunk_data[9]; + + if (verbose) + fprintf(STDERR, " vpAg = %lu x %lu, units = %lu\n", + (unsigned long)user_chunk_data[1], + (unsigned long)user_chunk_data[2], + (unsigned long)user_chunk_data[3]); + png_save_uint_32(vpag_chunk_data, user_chunk_data[1]); + png_save_uint_32(vpag_chunk_data + 4, user_chunk_data[2]); + vpag_chunk_data[8] = (unsigned char)(user_chunk_data[3] & 0xff); + png_write_chunk(write_ptr, png_vpAg, vpag_chunk_data, 9); + } + +#endif +#endif + +#ifdef SINGLE_ROWBUF_ALLOC + png_debug(0, "Allocating row buffer..."); + row_buf = (png_bytep)png_malloc(read_ptr, + png_get_rowbytes(read_ptr, read_info_ptr)); + png_debug1(0, "0x%08lx", (unsigned long)row_buf); +#endif /* SINGLE_ROWBUF_ALLOC */ + png_debug(0, "Writing row data"); + +#if defined(PNG_READ_INTERLACING_SUPPORTED) || \ + defined(PNG_WRITE_INTERLACING_SUPPORTED) + num_pass = png_set_interlace_handling(read_ptr); +# ifdef PNG_WRITE_SUPPORTED + png_set_interlace_handling(write_ptr); +# endif +#else + num_pass = 1; +#endif + +#ifdef PNGTEST_TIMING + t_stop = (float)clock(); + t_misc += (t_stop - t_start); + t_start = t_stop; +#endif + for (pass = 0; pass < num_pass; pass++) + { + png_debug1(0, "Writing row data for pass %d", pass); + for (y = 0; y < height; y++) + { +#ifndef SINGLE_ROWBUF_ALLOC + png_debug2(0, "Allocating row buffer (pass %d, y = %ld)...", pass, y); + row_buf = (png_bytep)png_malloc(read_ptr, + png_get_rowbytes(read_ptr, read_info_ptr)); + png_debug2(0, "0x%08lx (%ld bytes)", (unsigned long)row_buf, + png_get_rowbytes(read_ptr, read_info_ptr)); +#endif /* !SINGLE_ROWBUF_ALLOC */ + png_read_rows(read_ptr, (png_bytepp)&row_buf, png_bytepp_NULL, 1); + +#ifdef PNG_WRITE_SUPPORTED +#ifdef PNGTEST_TIMING + t_stop = (float)clock(); + t_decode += (t_stop - t_start); + t_start = t_stop; +#endif + png_write_rows(write_ptr, (png_bytepp)&row_buf, 1); +#ifdef PNGTEST_TIMING + t_stop = (float)clock(); + t_encode += (t_stop - t_start); + t_start = t_stop; +#endif +#endif /* PNG_WRITE_SUPPORTED */ + +#ifndef SINGLE_ROWBUF_ALLOC + png_debug2(0, "Freeing row buffer (pass %d, y = %ld)", pass, y); + png_free(read_ptr, row_buf); + row_buf = NULL; +#endif /* !SINGLE_ROWBUF_ALLOC */ + } + } + +#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED + png_free_data(read_ptr, read_info_ptr, PNG_FREE_UNKN, -1); +#endif +#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED + png_free_data(write_ptr, write_info_ptr, PNG_FREE_UNKN, -1); +#endif + + png_debug(0, "Reading and writing end_info data"); + + png_read_end(read_ptr, end_info_ptr); +#ifdef PNG_TEXT_SUPPORTED + { + png_textp text_ptr; + int num_text; + + if (png_get_text(read_ptr, end_info_ptr, &text_ptr, &num_text) > 0) + { + png_debug1(0, "Handling %d iTXt/tEXt/zTXt chunks", num_text); + png_set_text(write_ptr, write_end_info_ptr, text_ptr, num_text); + } + } +#endif +#ifdef PNG_tIME_SUPPORTED + { + png_timep mod_time; + + if (png_get_tIME(read_ptr, end_info_ptr, &mod_time)) + { + png_set_tIME(write_ptr, write_end_info_ptr, mod_time); +#ifdef PNG_TIME_RFC1123_SUPPORTED + /* We have to use png_memcpy instead of "=" because the string + pointed to by png_convert_to_rfc1123() gets free'ed before + we use it */ + png_memcpy(tIME_string, + png_convert_to_rfc1123(read_ptr, mod_time), + png_sizeof(tIME_string)); + tIME_string[png_sizeof(tIME_string) - 1] = '\0'; + tIME_chunk_present++; +#endif /* PNG_TIME_RFC1123_SUPPORTED */ + } + } +#endif +#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED + { + png_unknown_chunkp unknowns; + int num_unknowns; + num_unknowns = (int)png_get_unknown_chunks(read_ptr, end_info_ptr, + &unknowns); + if (num_unknowns) + { + png_size_t i; + png_set_unknown_chunks(write_ptr, write_end_info_ptr, unknowns, + num_unknowns); + /* Copy the locations from the read_info_ptr. The automatically + * generated locations in write_end_info_ptr are wrong because we + * haven't written the end_info yet. + */ + for (i = 0; i < (png_size_t)num_unknowns; i++) + png_set_unknown_chunk_location(write_ptr, write_end_info_ptr, i, + unknowns[i].location); + } + } +#endif +#ifdef PNG_WRITE_SUPPORTED + png_write_end(write_ptr, write_end_info_ptr); +#endif + +#ifdef PNG_EASY_ACCESS_SUPPORTED + if (verbose) + { + png_uint_32 iwidth, iheight; + iwidth = png_get_image_width(write_ptr, write_info_ptr); + iheight = png_get_image_height(write_ptr, write_info_ptr); + fprintf(STDERR, "\n Image width = %lu, height = %lu\n", + (unsigned long)iwidth, (unsigned long)iheight); + } +#endif + + png_debug(0, "Destroying data structs"); +#ifdef SINGLE_ROWBUF_ALLOC + png_debug(1, "destroying row_buf for read_ptr"); + png_free(read_ptr, row_buf); + row_buf = NULL; +#endif /* SINGLE_ROWBUF_ALLOC */ + png_debug(1, "destroying read_ptr, read_info_ptr, end_info_ptr"); + png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr); +#ifdef PNG_WRITE_SUPPORTED + png_debug(1, "destroying write_end_info_ptr"); + png_destroy_info_struct(write_ptr, &write_end_info_ptr); + png_debug(1, "destroying write_ptr, write_info_ptr"); + png_destroy_write_struct(&write_ptr, &write_info_ptr); +#endif + png_debug(0, "Destruction complete."); + + FCLOSE(fpin); + FCLOSE(fpout); + + png_debug(0, "Opening files for comparison"); +#ifdef _WIN32_WCE + MultiByteToWideChar(CP_ACP, 0, inname, -1, path, MAX_PATH); + if ((fpin = CreateFile(path, GENERIC_READ, 0, NULL, OPEN_EXISTING, + 0, NULL)) == INVALID_HANDLE_VALUE) +#else + if ((fpin = fopen(inname, "rb")) == NULL) +#endif + { + fprintf(STDERR, "Could not find file %s\n", inname); + return (1); + } + +#ifdef _WIN32_WCE + MultiByteToWideChar(CP_ACP, 0, outname, -1, path, MAX_PATH); + if ((fpout = CreateFile(path, GENERIC_READ, 0, NULL, OPEN_EXISTING, + 0, NULL)) == INVALID_HANDLE_VALUE) +#else + if ((fpout = fopen(outname, "rb")) == NULL) +#endif + { + fprintf(STDERR, "Could not find file %s\n", outname); + FCLOSE(fpin); + return (1); + } + + for (;;) + { + png_size_t num_in, num_out; + + READFILE(fpin, inbuf, 1, num_in); + READFILE(fpout, outbuf, 1, num_out); + + if (num_in != num_out) + { + fprintf(STDERR, "\nFiles %s and %s are of a different size\n", + inname, outname); + if (wrote_question == 0) + { + fprintf(STDERR, + " Was %s written with the same maximum IDAT chunk size (%d bytes),", + inname, PNG_ZBUF_SIZE); + fprintf(STDERR, + "\n filtering heuristic (libpng default), compression"); + fprintf(STDERR, + " level (zlib default),\n and zlib version (%s)?\n\n", + ZLIB_VERSION); + wrote_question = 1; + } + FCLOSE(fpin); + FCLOSE(fpout); + return (0); + } + + if (!num_in) + break; + + if (png_memcmp(inbuf, outbuf, num_in)) + { + fprintf(STDERR, "\nFiles %s and %s are different\n", inname, outname); + if (wrote_question == 0) + { + fprintf(STDERR, + " Was %s written with the same maximum IDAT chunk size (%d bytes),", + inname, PNG_ZBUF_SIZE); + fprintf(STDERR, + "\n filtering heuristic (libpng default), compression"); + fprintf(STDERR, + " level (zlib default),\n and zlib version (%s)?\n\n", + ZLIB_VERSION); + wrote_question = 1; + } + FCLOSE(fpin); + FCLOSE(fpout); + return (0); + } + } + + FCLOSE(fpin); + FCLOSE(fpout); + + return (0); +} + +/* Input and output filenames */ +#ifdef RISCOS +static PNG_CONST char *inname = "pngtest/png"; +static PNG_CONST char *outname = "pngout/png"; +#else +static PNG_CONST char *inname = "pngtest.png"; +static PNG_CONST char *outname = "pngout.png"; +#endif + +int +main(int argc, char *argv[]) +{ + int multiple = 0; + int ierror = 0; + + fprintf(STDERR, "\n Testing libpng version %s\n", PNG_LIBPNG_VER_STRING); + fprintf(STDERR, " with zlib version %s\n", ZLIB_VERSION); + fprintf(STDERR, "%s", png_get_copyright(NULL)); + /* Show the version of libpng used in building the library */ + fprintf(STDERR, " library (%lu):%s", + (unsigned long)png_access_version_number(), + png_get_header_version(NULL)); + /* Show the version of libpng used in building the application */ + fprintf(STDERR, " pngtest (%lu):%s", (unsigned long)PNG_LIBPNG_VER, + PNG_HEADER_VERSION_STRING); + fprintf(STDERR, " sizeof(png_struct)=%ld, sizeof(png_info)=%ld\n", + (long)png_sizeof(png_struct), (long)png_sizeof(png_info)); + + /* Do some consistency checking on the memory allocation settings, I'm + * not sure this matters, but it is nice to know, the first of these + * tests should be impossible because of the way the macros are set + * in pngconf.h + */ +#if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K) + fprintf(STDERR, " NOTE: Zlib compiled for max 64k, libpng not\n"); +#endif + /* I think the following can happen. */ +#if !defined(MAXSEG_64K) && defined(PNG_MAX_MALLOC_64K) + fprintf(STDERR, " NOTE: libpng compiled for max 64k, zlib not\n"); +#endif + + if (strcmp(png_libpng_ver, PNG_LIBPNG_VER_STRING)) + { + fprintf(STDERR, + "Warning: versions are different between png.h and png.c\n"); + fprintf(STDERR, " png.h version: %s\n", PNG_LIBPNG_VER_STRING); + fprintf(STDERR, " png.c version: %s\n\n", png_libpng_ver); + ++ierror; + } + + if (argc > 1) + { + if (strcmp(argv[1], "-m") == 0) + { + multiple = 1; + status_dots_requested = 0; + } + else if (strcmp(argv[1], "-mv") == 0 || + strcmp(argv[1], "-vm") == 0 ) + { + multiple = 1; + verbose = 1; + status_dots_requested = 1; + } + else if (strcmp(argv[1], "-v") == 0) + { + verbose = 1; + status_dots_requested = 1; + inname = argv[2]; + } + else + { + inname = argv[1]; + status_dots_requested = 0; + } + } + + if (!multiple && argc == 3 + verbose) + outname = argv[2 + verbose]; + + if ((!multiple && argc > 3 + verbose) || (multiple && argc < 2)) + { + fprintf(STDERR, + "usage: %s [infile.png] [outfile.png]\n\t%s -m {infile.png}\n", + argv[0], argv[0]); + fprintf(STDERR, + " reads/writes one PNG file (without -m) or multiple files (-m)\n"); + fprintf(STDERR, + " with -m %s is used as a temporary file\n", outname); + exit(1); + } + + if (multiple) + { + int i; +#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG + int allocation_now = current_allocation; +#endif + for (i=2; isize, + (unsigned int) pinfo->pointer); + pinfo = pinfo->next; + } + } +#endif + } +#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG + fprintf(STDERR, " Current memory allocation: %10d bytes\n", + current_allocation); + fprintf(STDERR, " Maximum memory allocation: %10d bytes\n", + maximum_allocation); + fprintf(STDERR, " Total memory allocation: %10d bytes\n", + total_allocation); + fprintf(STDERR, " Number of allocations: %10d\n", + num_allocations); +#endif + } + else + { + int i; + for (i = 0; i<3; ++i) + { + int kerror; +#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG + int allocation_now = current_allocation; +#endif + if (i == 1) status_dots_requested = 1; + else if (verbose == 0)status_dots_requested = 0; + if (i == 0 || verbose == 1 || ierror != 0) + fprintf(STDERR, "\n Testing %s:", inname); + kerror = test_one_file(inname, outname); + if (kerror == 0) + { + if (verbose == 1 || i == 2) + { +#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED + int k; +#endif +#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED + fprintf(STDERR, "\n PASS (%lu zero samples)\n", + (unsigned long)zero_samples); +#else + fprintf(STDERR, " PASS\n"); +#endif +#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED + for (k = 0; k<256; k++) + if (filters_used[k]) + fprintf(STDERR, " Filter %d was used %lu times\n", + k, (unsigned long)filters_used[k]); +#endif +#ifdef PNG_TIME_RFC1123_SUPPORTED + if (tIME_chunk_present != 0) + fprintf(STDERR, " tIME = %s\n", tIME_string); +#endif /* PNG_TIME_RFC1123_SUPPORTED */ + } + } + else + { + if (verbose == 0 && i != 2) + fprintf(STDERR, "\n Testing %s:", inname); + fprintf(STDERR, " FAIL\n"); + ierror += kerror; + } +#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG + if (allocation_now != current_allocation) + fprintf(STDERR, "MEMORY ERROR: %d bytes lost\n", + current_allocation - allocation_now); + if (current_allocation != 0) + { + memory_infop pinfo = pinformation; + + fprintf(STDERR, "MEMORY ERROR: %d bytes still allocated\n", + current_allocation); + while (pinfo != NULL) + { + fprintf(STDERR, " %lu bytes at %x\n", + (unsigned long)pinfo->size, (unsigned int)pinfo->pointer); + pinfo = pinfo->next; + } + } +#endif + } +#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG + fprintf(STDERR, " Current memory allocation: %10d bytes\n", + current_allocation); + fprintf(STDERR, " Maximum memory allocation: %10d bytes\n", + maximum_allocation); + fprintf(STDERR, " Total memory allocation: %10d bytes\n", + total_allocation); + fprintf(STDERR, " Number of allocations: %10d\n", + num_allocations); +#endif + } + +#ifdef PNGTEST_TIMING + t_stop = (float)clock(); + t_misc += (t_stop - t_start); + t_start = t_stop; + fprintf(STDERR, " CPU time used = %.3f seconds", + (t_misc+t_decode+t_encode)/(float)CLOCKS_PER_SEC); + fprintf(STDERR, " (decoding %.3f,\n", + t_decode/(float)CLOCKS_PER_SEC); + fprintf(STDERR, " encoding %.3f ,", + t_encode/(float)CLOCKS_PER_SEC); + fprintf(STDERR, " other %.3f seconds)\n\n", + t_misc/(float)CLOCKS_PER_SEC); +#endif + + if (ierror == 0) + fprintf(STDERR, " libpng passes test\n"); + else + fprintf(STDERR, " libpng FAILS test\n"); + return (int)(ierror != 0); +} + +/* Generate a compiler error if there is an old png.h in the search path. */ +typedef version_1_2_46 your_png_h_is_not_version_1_2_46; diff --git a/libs/libpng-src/pngtest.png b/libs/libpng-src/pngtest.png new file mode 100644 index 000000000..f3a6df448 Binary files /dev/null and b/libs/libpng-src/pngtest.png differ diff --git a/libs/libpng-src/pngtrans.c b/libs/libpng-src/pngtrans.c new file mode 100644 index 000000000..6ad9dcf62 --- /dev/null +++ b/libs/libpng-src/pngtrans.c @@ -0,0 +1,699 @@ + +/* pngtrans.c - transforms the data in a row (used by both readers and writers) + * + * Last changed in libpng 1.2.41 [December 3, 2009] + * Copyright (c) 1998-2009 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + */ + +#define PNG_INTERNAL +#define PNG_NO_PEDANTIC_WARNINGS +#include "png.h" +#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) + +#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED) +/* Turn on BGR-to-RGB mapping */ +void PNGAPI +png_set_bgr(png_structp png_ptr) +{ + png_debug(1, "in png_set_bgr"); + + if (png_ptr == NULL) + return; + png_ptr->transformations |= PNG_BGR; +} +#endif + +#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED) +/* Turn on 16 bit byte swapping */ +void PNGAPI +png_set_swap(png_structp png_ptr) +{ + png_debug(1, "in png_set_swap"); + + if (png_ptr == NULL) + return; + if (png_ptr->bit_depth == 16) + png_ptr->transformations |= PNG_SWAP_BYTES; +} +#endif + +#if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED) +/* Turn on pixel packing */ +void PNGAPI +png_set_packing(png_structp png_ptr) +{ + png_debug(1, "in png_set_packing"); + + if (png_ptr == NULL) + return; + if (png_ptr->bit_depth < 8) + { + png_ptr->transformations |= PNG_PACK; + png_ptr->usr_bit_depth = 8; + } +} +#endif + +#if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED) +/* Turn on packed pixel swapping */ +void PNGAPI +png_set_packswap(png_structp png_ptr) +{ + png_debug(1, "in png_set_packswap"); + + if (png_ptr == NULL) + return; + if (png_ptr->bit_depth < 8) + png_ptr->transformations |= PNG_PACKSWAP; +} +#endif + +#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED) +void PNGAPI +png_set_shift(png_structp png_ptr, png_color_8p true_bits) +{ + png_debug(1, "in png_set_shift"); + + if (png_ptr == NULL) + return; + png_ptr->transformations |= PNG_SHIFT; + png_ptr->shift = *true_bits; +} +#endif + +#if defined(PNG_READ_INTERLACING_SUPPORTED) || \ + defined(PNG_WRITE_INTERLACING_SUPPORTED) +int PNGAPI +png_set_interlace_handling(png_structp png_ptr) +{ + png_debug(1, "in png_set_interlace handling"); + + if (png_ptr && png_ptr->interlaced) + { + png_ptr->transformations |= PNG_INTERLACE; + return (7); + } + + return (1); +} +#endif + +#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED) +/* Add a filler byte on read, or remove a filler or alpha byte on write. + * The filler type has changed in v0.95 to allow future 2-byte fillers + * for 48-bit input data, as well as to avoid problems with some compilers + * that don't like bytes as parameters. + */ +void PNGAPI +png_set_filler(png_structp png_ptr, png_uint_32 filler, int filler_loc) +{ + png_debug(1, "in png_set_filler"); + + if (png_ptr == NULL) + return; + png_ptr->transformations |= PNG_FILLER; +#ifdef PNG_LEGACY_SUPPORTED + png_ptr->filler = (png_byte)filler; +#else + png_ptr->filler = (png_uint_16)filler; +#endif + if (filler_loc == PNG_FILLER_AFTER) + png_ptr->flags |= PNG_FLAG_FILLER_AFTER; + else + png_ptr->flags &= ~PNG_FLAG_FILLER_AFTER; + + /* This should probably go in the "do_read_filler" routine. + * I attempted to do that in libpng-1.0.1a but that caused problems + * so I restored it in libpng-1.0.2a + */ + + if (png_ptr->color_type == PNG_COLOR_TYPE_RGB) + { + png_ptr->usr_channels = 4; + } + + /* Also I added this in libpng-1.0.2a (what happens when we expand + * a less-than-8-bit grayscale to GA? */ + + if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY && png_ptr->bit_depth >= 8) + { + png_ptr->usr_channels = 2; + } +} + +#ifndef PNG_1_0_X +/* Added to libpng-1.2.7 */ +void PNGAPI +png_set_add_alpha(png_structp png_ptr, png_uint_32 filler, int filler_loc) +{ + png_debug(1, "in png_set_add_alpha"); + + if (png_ptr == NULL) + return; + png_set_filler(png_ptr, filler, filler_loc); + png_ptr->transformations |= PNG_ADD_ALPHA; +} +#endif + +#endif + +#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \ + defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED) +void PNGAPI +png_set_swap_alpha(png_structp png_ptr) +{ + png_debug(1, "in png_set_swap_alpha"); + + if (png_ptr == NULL) + return; + png_ptr->transformations |= PNG_SWAP_ALPHA; +} +#endif + +#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \ + defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED) +void PNGAPI +png_set_invert_alpha(png_structp png_ptr) +{ + png_debug(1, "in png_set_invert_alpha"); + + if (png_ptr == NULL) + return; + png_ptr->transformations |= PNG_INVERT_ALPHA; +} +#endif + +#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED) +void PNGAPI +png_set_invert_mono(png_structp png_ptr) +{ + png_debug(1, "in png_set_invert_mono"); + + if (png_ptr == NULL) + return; + png_ptr->transformations |= PNG_INVERT_MONO; +} + +/* Invert monochrome grayscale data */ +void /* PRIVATE */ +png_do_invert(png_row_infop row_info, png_bytep row) +{ + png_debug(1, "in png_do_invert"); + + /* This test removed from libpng version 1.0.13 and 1.2.0: + * if (row_info->bit_depth == 1 && + */ +#ifdef PNG_USELESS_TESTS_SUPPORTED + if (row == NULL || row_info == NULL) + return; +#endif + if (row_info->color_type == PNG_COLOR_TYPE_GRAY) + { + png_bytep rp = row; + png_uint_32 i; + png_uint_32 istop = row_info->rowbytes; + + for (i = 0; i < istop; i++) + { + *rp = (png_byte)(~(*rp)); + rp++; + } + } + else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA && + row_info->bit_depth == 8) + { + png_bytep rp = row; + png_uint_32 i; + png_uint_32 istop = row_info->rowbytes; + + for (i = 0; i < istop; i+=2) + { + *rp = (png_byte)(~(*rp)); + rp+=2; + } + } + else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA && + row_info->bit_depth == 16) + { + png_bytep rp = row; + png_uint_32 i; + png_uint_32 istop = row_info->rowbytes; + + for (i = 0; i < istop; i+=4) + { + *rp = (png_byte)(~(*rp)); + *(rp+1) = (png_byte)(~(*(rp+1))); + rp+=4; + } + } +} +#endif + +#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED) +/* Swaps byte order on 16 bit depth images */ +void /* PRIVATE */ +png_do_swap(png_row_infop row_info, png_bytep row) +{ + png_debug(1, "in png_do_swap"); + + if ( +#ifdef PNG_USELESS_TESTS_SUPPORTED + row != NULL && row_info != NULL && +#endif + row_info->bit_depth == 16) + { + png_bytep rp = row; + png_uint_32 i; + png_uint_32 istop= row_info->width * row_info->channels; + + for (i = 0; i < istop; i++, rp += 2) + { + png_byte t = *rp; + *rp = *(rp + 1); + *(rp + 1) = t; + } + } +} +#endif + +#if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED) +static PNG_CONST png_byte onebppswaptable[256] = { + 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, + 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0, + 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8, + 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8, + 0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4, + 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4, + 0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC, + 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC, + 0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2, + 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2, + 0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA, + 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA, + 0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6, + 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6, + 0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE, + 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE, + 0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1, + 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1, + 0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9, + 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9, + 0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5, + 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5, + 0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED, + 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD, + 0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3, + 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3, + 0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB, + 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB, + 0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7, + 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7, + 0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF, + 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF +}; + +static PNG_CONST png_byte twobppswaptable[256] = { + 0x00, 0x40, 0x80, 0xC0, 0x10, 0x50, 0x90, 0xD0, + 0x20, 0x60, 0xA0, 0xE0, 0x30, 0x70, 0xB0, 0xF0, + 0x04, 0x44, 0x84, 0xC4, 0x14, 0x54, 0x94, 0xD4, + 0x24, 0x64, 0xA4, 0xE4, 0x34, 0x74, 0xB4, 0xF4, + 0x08, 0x48, 0x88, 0xC8, 0x18, 0x58, 0x98, 0xD8, + 0x28, 0x68, 0xA8, 0xE8, 0x38, 0x78, 0xB8, 0xF8, + 0x0C, 0x4C, 0x8C, 0xCC, 0x1C, 0x5C, 0x9C, 0xDC, + 0x2C, 0x6C, 0xAC, 0xEC, 0x3C, 0x7C, 0xBC, 0xFC, + 0x01, 0x41, 0x81, 0xC1, 0x11, 0x51, 0x91, 0xD1, + 0x21, 0x61, 0xA1, 0xE1, 0x31, 0x71, 0xB1, 0xF1, + 0x05, 0x45, 0x85, 0xC5, 0x15, 0x55, 0x95, 0xD5, + 0x25, 0x65, 0xA5, 0xE5, 0x35, 0x75, 0xB5, 0xF5, + 0x09, 0x49, 0x89, 0xC9, 0x19, 0x59, 0x99, 0xD9, + 0x29, 0x69, 0xA9, 0xE9, 0x39, 0x79, 0xB9, 0xF9, + 0x0D, 0x4D, 0x8D, 0xCD, 0x1D, 0x5D, 0x9D, 0xDD, + 0x2D, 0x6D, 0xAD, 0xED, 0x3D, 0x7D, 0xBD, 0xFD, + 0x02, 0x42, 0x82, 0xC2, 0x12, 0x52, 0x92, 0xD2, + 0x22, 0x62, 0xA2, 0xE2, 0x32, 0x72, 0xB2, 0xF2, + 0x06, 0x46, 0x86, 0xC6, 0x16, 0x56, 0x96, 0xD6, + 0x26, 0x66, 0xA6, 0xE6, 0x36, 0x76, 0xB6, 0xF6, + 0x0A, 0x4A, 0x8A, 0xCA, 0x1A, 0x5A, 0x9A, 0xDA, + 0x2A, 0x6A, 0xAA, 0xEA, 0x3A, 0x7A, 0xBA, 0xFA, + 0x0E, 0x4E, 0x8E, 0xCE, 0x1E, 0x5E, 0x9E, 0xDE, + 0x2E, 0x6E, 0xAE, 0xEE, 0x3E, 0x7E, 0xBE, 0xFE, + 0x03, 0x43, 0x83, 0xC3, 0x13, 0x53, 0x93, 0xD3, + 0x23, 0x63, 0xA3, 0xE3, 0x33, 0x73, 0xB3, 0xF3, + 0x07, 0x47, 0x87, 0xC7, 0x17, 0x57, 0x97, 0xD7, + 0x27, 0x67, 0xA7, 0xE7, 0x37, 0x77, 0xB7, 0xF7, + 0x0B, 0x4B, 0x8B, 0xCB, 0x1B, 0x5B, 0x9B, 0xDB, + 0x2B, 0x6B, 0xAB, 0xEB, 0x3B, 0x7B, 0xBB, 0xFB, + 0x0F, 0x4F, 0x8F, 0xCF, 0x1F, 0x5F, 0x9F, 0xDF, + 0x2F, 0x6F, 0xAF, 0xEF, 0x3F, 0x7F, 0xBF, 0xFF +}; + +static PNG_CONST png_byte fourbppswaptable[256] = { + 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, + 0x80, 0x90, 0xA0, 0xB0, 0xC0, 0xD0, 0xE0, 0xF0, + 0x01, 0x11, 0x21, 0x31, 0x41, 0x51, 0x61, 0x71, + 0x81, 0x91, 0xA1, 0xB1, 0xC1, 0xD1, 0xE1, 0xF1, + 0x02, 0x12, 0x22, 0x32, 0x42, 0x52, 0x62, 0x72, + 0x82, 0x92, 0xA2, 0xB2, 0xC2, 0xD2, 0xE2, 0xF2, + 0x03, 0x13, 0x23, 0x33, 0x43, 0x53, 0x63, 0x73, + 0x83, 0x93, 0xA3, 0xB3, 0xC3, 0xD3, 0xE3, 0xF3, + 0x04, 0x14, 0x24, 0x34, 0x44, 0x54, 0x64, 0x74, + 0x84, 0x94, 0xA4, 0xB4, 0xC4, 0xD4, 0xE4, 0xF4, + 0x05, 0x15, 0x25, 0x35, 0x45, 0x55, 0x65, 0x75, + 0x85, 0x95, 0xA5, 0xB5, 0xC5, 0xD5, 0xE5, 0xF5, + 0x06, 0x16, 0x26, 0x36, 0x46, 0x56, 0x66, 0x76, + 0x86, 0x96, 0xA6, 0xB6, 0xC6, 0xD6, 0xE6, 0xF6, + 0x07, 0x17, 0x27, 0x37, 0x47, 0x57, 0x67, 0x77, + 0x87, 0x97, 0xA7, 0xB7, 0xC7, 0xD7, 0xE7, 0xF7, + 0x08, 0x18, 0x28, 0x38, 0x48, 0x58, 0x68, 0x78, + 0x88, 0x98, 0xA8, 0xB8, 0xC8, 0xD8, 0xE8, 0xF8, + 0x09, 0x19, 0x29, 0x39, 0x49, 0x59, 0x69, 0x79, + 0x89, 0x99, 0xA9, 0xB9, 0xC9, 0xD9, 0xE9, 0xF9, + 0x0A, 0x1A, 0x2A, 0x3A, 0x4A, 0x5A, 0x6A, 0x7A, + 0x8A, 0x9A, 0xAA, 0xBA, 0xCA, 0xDA, 0xEA, 0xFA, + 0x0B, 0x1B, 0x2B, 0x3B, 0x4B, 0x5B, 0x6B, 0x7B, + 0x8B, 0x9B, 0xAB, 0xBB, 0xCB, 0xDB, 0xEB, 0xFB, + 0x0C, 0x1C, 0x2C, 0x3C, 0x4C, 0x5C, 0x6C, 0x7C, + 0x8C, 0x9C, 0xAC, 0xBC, 0xCC, 0xDC, 0xEC, 0xFC, + 0x0D, 0x1D, 0x2D, 0x3D, 0x4D, 0x5D, 0x6D, 0x7D, + 0x8D, 0x9D, 0xAD, 0xBD, 0xCD, 0xDD, 0xED, 0xFD, + 0x0E, 0x1E, 0x2E, 0x3E, 0x4E, 0x5E, 0x6E, 0x7E, + 0x8E, 0x9E, 0xAE, 0xBE, 0xCE, 0xDE, 0xEE, 0xFE, + 0x0F, 0x1F, 0x2F, 0x3F, 0x4F, 0x5F, 0x6F, 0x7F, + 0x8F, 0x9F, 0xAF, 0xBF, 0xCF, 0xDF, 0xEF, 0xFF +}; + +/* Swaps pixel packing order within bytes */ +void /* PRIVATE */ +png_do_packswap(png_row_infop row_info, png_bytep row) +{ + png_debug(1, "in png_do_packswap"); + + if ( +#ifdef PNG_USELESS_TESTS_SUPPORTED + row != NULL && row_info != NULL && +#endif + row_info->bit_depth < 8) + { + png_bytep rp, end, table; + + end = row + row_info->rowbytes; + + if (row_info->bit_depth == 1) + table = (png_bytep)onebppswaptable; + else if (row_info->bit_depth == 2) + table = (png_bytep)twobppswaptable; + else if (row_info->bit_depth == 4) + table = (png_bytep)fourbppswaptable; + else + return; + + for (rp = row; rp < end; rp++) + *rp = table[*rp]; + } +} +#endif /* PNG_READ_PACKSWAP_SUPPORTED or PNG_WRITE_PACKSWAP_SUPPORTED */ + +#if defined(PNG_WRITE_FILLER_SUPPORTED) || \ + defined(PNG_READ_STRIP_ALPHA_SUPPORTED) +/* Remove filler or alpha byte(s) */ +void /* PRIVATE */ +png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags) +{ + png_debug(1, "in png_do_strip_filler"); + +#ifdef PNG_USELESS_TESTS_SUPPORTED + if (row != NULL && row_info != NULL) +#endif + { + png_bytep sp=row; + png_bytep dp=row; + png_uint_32 row_width=row_info->width; + png_uint_32 i; + + if ((row_info->color_type == PNG_COLOR_TYPE_RGB || + (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA && + (flags & PNG_FLAG_STRIP_ALPHA))) && + row_info->channels == 4) + { + if (row_info->bit_depth == 8) + { + /* This converts from RGBX or RGBA to RGB */ + if (flags & PNG_FLAG_FILLER_AFTER) + { + dp+=3; sp+=4; + for (i = 1; i < row_width; i++) + { + *dp++ = *sp++; + *dp++ = *sp++; + *dp++ = *sp++; + sp++; + } + } + /* This converts from XRGB or ARGB to RGB */ + else + { + for (i = 0; i < row_width; i++) + { + sp++; + *dp++ = *sp++; + *dp++ = *sp++; + *dp++ = *sp++; + } + } + row_info->pixel_depth = 24; + row_info->rowbytes = row_width * 3; + } + else /* if (row_info->bit_depth == 16) */ + { + if (flags & PNG_FLAG_FILLER_AFTER) + { + /* This converts from RRGGBBXX or RRGGBBAA to RRGGBB */ + sp += 8; dp += 6; + for (i = 1; i < row_width; i++) + { + /* This could be (although png_memcpy is probably slower): + png_memcpy(dp, sp, 6); + sp += 8; + dp += 6; + */ + + *dp++ = *sp++; + *dp++ = *sp++; + *dp++ = *sp++; + *dp++ = *sp++; + *dp++ = *sp++; + *dp++ = *sp++; + sp += 2; + } + } + else + { + /* This converts from XXRRGGBB or AARRGGBB to RRGGBB */ + for (i = 0; i < row_width; i++) + { + /* This could be (although png_memcpy is probably slower): + png_memcpy(dp, sp, 6); + sp += 8; + dp += 6; + */ + + sp+=2; + *dp++ = *sp++; + *dp++ = *sp++; + *dp++ = *sp++; + *dp++ = *sp++; + *dp++ = *sp++; + *dp++ = *sp++; + } + } + row_info->pixel_depth = 48; + row_info->rowbytes = row_width * 6; + } + row_info->channels = 3; + } + else if ((row_info->color_type == PNG_COLOR_TYPE_GRAY || + (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA && + (flags & PNG_FLAG_STRIP_ALPHA))) && + row_info->channels == 2) + { + if (row_info->bit_depth == 8) + { + /* This converts from GX or GA to G */ + if (flags & PNG_FLAG_FILLER_AFTER) + { + for (i = 0; i < row_width; i++) + { + *dp++ = *sp++; + sp++; + } + } + /* This converts from XG or AG to G */ + else + { + for (i = 0; i < row_width; i++) + { + sp++; + *dp++ = *sp++; + } + } + row_info->pixel_depth = 8; + row_info->rowbytes = row_width; + } + else /* if (row_info->bit_depth == 16) */ + { + if (flags & PNG_FLAG_FILLER_AFTER) + { + /* This converts from GGXX or GGAA to GG */ + sp += 4; dp += 2; + for (i = 1; i < row_width; i++) + { + *dp++ = *sp++; + *dp++ = *sp++; + sp += 2; + } + } + else + { + /* This converts from XXGG or AAGG to GG */ + for (i = 0; i < row_width; i++) + { + sp += 2; + *dp++ = *sp++; + *dp++ = *sp++; + } + } + row_info->pixel_depth = 16; + row_info->rowbytes = row_width * 2; + } + row_info->channels = 1; + } + if (flags & PNG_FLAG_STRIP_ALPHA) + row_info->color_type &= ~PNG_COLOR_MASK_ALPHA; + } +} +#endif + +#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED) +/* Swaps red and blue bytes within a pixel */ +void /* PRIVATE */ +png_do_bgr(png_row_infop row_info, png_bytep row) +{ + png_debug(1, "in png_do_bgr"); + + if ( +#ifdef PNG_USELESS_TESTS_SUPPORTED + row != NULL && row_info != NULL && +#endif + (row_info->color_type & PNG_COLOR_MASK_COLOR)) + { + png_uint_32 row_width = row_info->width; + if (row_info->bit_depth == 8) + { + if (row_info->color_type == PNG_COLOR_TYPE_RGB) + { + png_bytep rp; + png_uint_32 i; + + for (i = 0, rp = row; i < row_width; i++, rp += 3) + { + png_byte save = *rp; + *rp = *(rp + 2); + *(rp + 2) = save; + } + } + else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + { + png_bytep rp; + png_uint_32 i; + + for (i = 0, rp = row; i < row_width; i++, rp += 4) + { + png_byte save = *rp; + *rp = *(rp + 2); + *(rp + 2) = save; + } + } + } + else if (row_info->bit_depth == 16) + { + if (row_info->color_type == PNG_COLOR_TYPE_RGB) + { + png_bytep rp; + png_uint_32 i; + + for (i = 0, rp = row; i < row_width; i++, rp += 6) + { + png_byte save = *rp; + *rp = *(rp + 4); + *(rp + 4) = save; + save = *(rp + 1); + *(rp + 1) = *(rp + 5); + *(rp + 5) = save; + } + } + else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + { + png_bytep rp; + png_uint_32 i; + + for (i = 0, rp = row; i < row_width; i++, rp += 8) + { + png_byte save = *rp; + *rp = *(rp + 4); + *(rp + 4) = save; + save = *(rp + 1); + *(rp + 1) = *(rp + 5); + *(rp + 5) = save; + } + } + } + } +} +#endif /* PNG_READ_BGR_SUPPORTED or PNG_WRITE_BGR_SUPPORTED */ + +#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ + defined(PNG_LEGACY_SUPPORTED) || \ + defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) +void PNGAPI +png_set_user_transform_info(png_structp png_ptr, png_voidp + user_transform_ptr, int user_transform_depth, int user_transform_channels) +{ + png_debug(1, "in png_set_user_transform_info"); + + if (png_ptr == NULL) + return; +#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED + png_ptr->user_transform_ptr = user_transform_ptr; + png_ptr->user_transform_depth = (png_byte)user_transform_depth; + png_ptr->user_transform_channels = (png_byte)user_transform_channels; +#else + if (user_transform_ptr || user_transform_depth || user_transform_channels) + png_warning(png_ptr, + "This version of libpng does not support user transform info"); +#endif +} +#endif + +/* This function returns a pointer to the user_transform_ptr associated with + * the user transform functions. The application should free any memory + * associated with this pointer before png_write_destroy and png_read_destroy + * are called. + */ +png_voidp PNGAPI +png_get_user_transform_ptr(png_structp png_ptr) +{ + if (png_ptr == NULL) + return (NULL); +#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED + return ((png_voidp)png_ptr->user_transform_ptr); +#else + return (NULL); +#endif +} +#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ diff --git a/libs/libpng-src/pngvcrd.c b/libs/libpng-src/pngvcrd.c new file mode 100644 index 000000000..ce4233efe --- /dev/null +++ b/libs/libpng-src/pngvcrd.c @@ -0,0 +1 @@ +/* pnggvrd.c was removed from libpng-1.2.20. */ diff --git a/libs/libpng-src/pngwio.c b/libs/libpng-src/pngwio.c new file mode 100644 index 000000000..44e5ea91c --- /dev/null +++ b/libs/libpng-src/pngwio.c @@ -0,0 +1,260 @@ + +/* pngwio.c - functions for data output + * + * Last changed in libpng 1.2.41 [December 3, 2009] + * Copyright (c) 1998-2009 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + * + * This file provides a location for all output. Users who need + * special handling are expected to write functions that have the same + * arguments as these and perform similar functions, but that possibly + * use different output methods. Note that you shouldn't change these + * functions, but rather write replacement functions and then change + * them at run time with png_set_write_fn(...). + */ + +#define PNG_INTERNAL +#define PNG_NO_PEDANTIC_WARNINGS +#include "png.h" +#ifdef PNG_WRITE_SUPPORTED + +/* Write the data to whatever output you are using. The default routine + * writes to a file pointer. Note that this routine sometimes gets called + * with very small lengths, so you should implement some kind of simple + * buffering if you are using unbuffered writes. This should never be asked + * to write more than 64K on a 16 bit machine. + */ + +void /* PRIVATE */ +png_write_data(png_structp png_ptr, png_bytep data, png_size_t length) +{ + if (png_ptr->write_data_fn != NULL ) + (*(png_ptr->write_data_fn))(png_ptr, data, length); + else + png_error(png_ptr, "Call to NULL write function"); +} + +#ifdef PNG_STDIO_SUPPORTED +/* This is the function that does the actual writing of data. If you are + * not writing to a standard C stream, you should create a replacement + * write_data function and use it at run time with png_set_write_fn(), rather + * than changing the library. + */ +#ifndef USE_FAR_KEYWORD +void PNGAPI +png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length) +{ + png_uint_32 check; + + if (png_ptr == NULL) + return; +#ifdef _WIN32_WCE + if ( !WriteFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) ) + check = 0; +#else + check = fwrite(data, 1, length, (png_FILE_p)(png_ptr->io_ptr)); +#endif + if (check != length) + png_error(png_ptr, "Write Error"); +} +#else +/* This is the model-independent version. Since the standard I/O library + * can't handle far buffers in the medium and small models, we have to copy + * the data. + */ + +#define NEAR_BUF_SIZE 1024 +#define MIN(a,b) (a <= b ? a : b) + +void PNGAPI +png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length) +{ + png_uint_32 check; + png_byte *near_data; /* Needs to be "png_byte *" instead of "png_bytep" */ + png_FILE_p io_ptr; + + if (png_ptr == NULL) + return; + /* Check if data really is near. If so, use usual code. */ + near_data = (png_byte *)CVT_PTR_NOCHECK(data); + io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr); + if ((png_bytep)near_data == data) + { +#ifdef _WIN32_WCE + if ( !WriteFile(io_ptr, near_data, length, &check, NULL) ) + check = 0; +#else + check = fwrite(near_data, 1, length, io_ptr); +#endif + } + else + { + png_byte buf[NEAR_BUF_SIZE]; + png_size_t written, remaining, err; + check = 0; + remaining = length; + do + { + written = MIN(NEAR_BUF_SIZE, remaining); + png_memcpy(buf, data, written); /* Copy far buffer to near buffer */ +#ifdef _WIN32_WCE + if ( !WriteFile(io_ptr, buf, written, &err, NULL) ) + err = 0; +#else + err = fwrite(buf, 1, written, io_ptr); +#endif + if (err != written) + break; + + else + check += err; + + data += written; + remaining -= written; + } + while (remaining != 0); + } + if (check != length) + png_error(png_ptr, "Write Error"); +} + +#endif +#endif + +/* This function is called to output any data pending writing (normally + * to disk). After png_flush is called, there should be no data pending + * writing in any buffers. + */ +#ifdef PNG_WRITE_FLUSH_SUPPORTED +void /* PRIVATE */ +png_flush(png_structp png_ptr) +{ + if (png_ptr->output_flush_fn != NULL) + (*(png_ptr->output_flush_fn))(png_ptr); +} + +#ifdef PNG_STDIO_SUPPORTED +void PNGAPI +png_default_flush(png_structp png_ptr) +{ +#ifndef _WIN32_WCE + png_FILE_p io_ptr; +#endif + if (png_ptr == NULL) + return; +#ifndef _WIN32_WCE + io_ptr = (png_FILE_p)CVT_PTR((png_ptr->io_ptr)); + fflush(io_ptr); +#endif +} +#endif +#endif + +/* This function allows the application to supply new output functions for + * libpng if standard C streams aren't being used. + * + * This function takes as its arguments: + * png_ptr - pointer to a png output data structure + * io_ptr - pointer to user supplied structure containing info about + * the output functions. May be NULL. + * write_data_fn - pointer to a new output function that takes as its + * arguments a pointer to a png_struct, a pointer to + * data to be written, and a 32-bit unsigned int that is + * the number of bytes to be written. The new write + * function should call png_error(png_ptr, "Error msg") + * to exit and output any fatal error messages. May be + * NULL, in which case libpng's default function will + * be used. + * flush_data_fn - pointer to a new flush function that takes as its + * arguments a pointer to a png_struct. After a call to + * the flush function, there should be no data in any buffers + * or pending transmission. If the output method doesn't do + * any buffering of output, a function prototype must still be + * supplied although it doesn't have to do anything. If + * PNG_WRITE_FLUSH_SUPPORTED is not defined at libpng compile + * time, output_flush_fn will be ignored, although it must be + * supplied for compatibility. May be NULL, in which case + * libpng's default function will be used, if + * PNG_WRITE_FLUSH_SUPPORTED is defined. This is not + * a good idea if io_ptr does not point to a standard + * *FILE structure. + */ +void PNGAPI +png_set_write_fn(png_structp png_ptr, png_voidp io_ptr, + png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn) +{ + if (png_ptr == NULL) + return; + + png_ptr->io_ptr = io_ptr; + +#ifdef PNG_STDIO_SUPPORTED + if (write_data_fn != NULL) + png_ptr->write_data_fn = write_data_fn; + + else + png_ptr->write_data_fn = png_default_write_data; +#else + png_ptr->write_data_fn = write_data_fn; +#endif + +#ifdef PNG_WRITE_FLUSH_SUPPORTED +#ifdef PNG_STDIO_SUPPORTED + if (output_flush_fn != NULL) + png_ptr->output_flush_fn = output_flush_fn; + + else + png_ptr->output_flush_fn = png_default_flush; +#else + png_ptr->output_flush_fn = output_flush_fn; +#endif +#endif /* PNG_WRITE_FLUSH_SUPPORTED */ + + /* It is an error to read while writing a png file */ + if (png_ptr->read_data_fn != NULL) + { + png_ptr->read_data_fn = NULL; + png_warning(png_ptr, + "Attempted to set both read_data_fn and write_data_fn in"); + png_warning(png_ptr, + "the same structure. Resetting read_data_fn to NULL."); + } +} + +#ifdef USE_FAR_KEYWORD +#ifdef _MSC_VER +void *png_far_to_near(png_structp png_ptr, png_voidp ptr, int check) +{ + void *near_ptr; + void FAR *far_ptr; + FP_OFF(near_ptr) = FP_OFF(ptr); + far_ptr = (void FAR *)near_ptr; + + if (check != 0) + if (FP_SEG(ptr) != FP_SEG(far_ptr)) + png_error(png_ptr, "segment lost in conversion"); + + return(near_ptr); +} +# else +void *png_far_to_near(png_structp png_ptr, png_voidp ptr, int check) +{ + void *near_ptr; + void FAR *far_ptr; + near_ptr = (void FAR *)ptr; + far_ptr = (void FAR *)near_ptr; + + if (check != 0) + if (far_ptr != ptr) + png_error(png_ptr, "segment lost in conversion"); + + return(near_ptr); +} +# endif +# endif +#endif /* PNG_WRITE_SUPPORTED */ diff --git a/libs/libpng-src/pngwrite.c b/libs/libpng-src/pngwrite.c new file mode 100644 index 000000000..68da9360d --- /dev/null +++ b/libs/libpng-src/pngwrite.c @@ -0,0 +1,1636 @@ + +/* pngwrite.c - general routines to write a PNG file + * + * Last changed in libpng 1.2.45 [July 7, 2011] + * Copyright (c) 1998-2011 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + */ + +/* Get internal access to png.h */ +#define PNG_INTERNAL +#define PNG_NO_PEDANTIC_WARNINGS +#include "png.h" +#ifdef PNG_WRITE_SUPPORTED + +/* Writes all the PNG information. This is the suggested way to use the + * library. If you have a new chunk to add, make a function to write it, + * and put it in the correct location here. If you want the chunk written + * after the image data, put it in png_write_end(). I strongly encourage + * you to supply a PNG_INFO_ flag, and check info_ptr->valid before writing + * the chunk, as that will keep the code from breaking if you want to just + * write a plain PNG file. If you have long comments, I suggest writing + * them in png_write_end(), and compressing them. + */ +void PNGAPI +png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr) +{ + png_debug(1, "in png_write_info_before_PLTE"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE)) + { + /* Write PNG signature */ + png_write_sig(png_ptr); +#ifdef PNG_MNG_FEATURES_SUPPORTED + if ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) && \ + (png_ptr->mng_features_permitted)) + { + png_warning(png_ptr, "MNG features are not allowed in a PNG datastream"); + png_ptr->mng_features_permitted = 0; + } +#endif + /* Write IHDR information. */ + png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height, + info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type, + info_ptr->filter_type, +#ifdef PNG_WRITE_INTERLACING_SUPPORTED + info_ptr->interlace_type); +#else + 0); +#endif + /* The rest of these check to see if the valid field has the appropriate + * flag set, and if it does, writes the chunk. + */ +#ifdef PNG_WRITE_gAMA_SUPPORTED + if (info_ptr->valid & PNG_INFO_gAMA) + { +# ifdef PNG_FLOATING_POINT_SUPPORTED + png_write_gAMA(png_ptr, info_ptr->gamma); +#else +#ifdef PNG_FIXED_POINT_SUPPORTED + png_write_gAMA_fixed(png_ptr, info_ptr->int_gamma); +# endif +#endif + } +#endif +#ifdef PNG_WRITE_sRGB_SUPPORTED + if (info_ptr->valid & PNG_INFO_sRGB) + png_write_sRGB(png_ptr, (int)info_ptr->srgb_intent); +#endif +#ifdef PNG_WRITE_iCCP_SUPPORTED + if (info_ptr->valid & PNG_INFO_iCCP) + png_write_iCCP(png_ptr, info_ptr->iccp_name, PNG_COMPRESSION_TYPE_BASE, + info_ptr->iccp_profile, (int)info_ptr->iccp_proflen); +#endif +#ifdef PNG_WRITE_sBIT_SUPPORTED + if (info_ptr->valid & PNG_INFO_sBIT) + png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type); +#endif +#ifdef PNG_WRITE_cHRM_SUPPORTED + if (info_ptr->valid & PNG_INFO_cHRM) + { +#ifdef PNG_FLOATING_POINT_SUPPORTED + png_write_cHRM(png_ptr, + info_ptr->x_white, info_ptr->y_white, + info_ptr->x_red, info_ptr->y_red, + info_ptr->x_green, info_ptr->y_green, + info_ptr->x_blue, info_ptr->y_blue); +#else +# ifdef PNG_FIXED_POINT_SUPPORTED + png_write_cHRM_fixed(png_ptr, + info_ptr->int_x_white, info_ptr->int_y_white, + info_ptr->int_x_red, info_ptr->int_y_red, + info_ptr->int_x_green, info_ptr->int_y_green, + info_ptr->int_x_blue, info_ptr->int_y_blue); +# endif +#endif + } +#endif +#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED + if (info_ptr->unknown_chunks_num) + { + png_unknown_chunk *up; + + png_debug(5, "writing extra chunks"); + + for (up = info_ptr->unknown_chunks; + up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num; + up++) + { + int keep = png_handle_as_unknown(png_ptr, up->name); + if (keep != PNG_HANDLE_CHUNK_NEVER && + up->location && !(up->location & PNG_HAVE_PLTE) && + !(up->location & PNG_HAVE_IDAT) && + ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS || + (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS))) + { + if (up->size == 0) + png_warning(png_ptr, "Writing zero-length unknown chunk"); + png_write_chunk(png_ptr, up->name, up->data, up->size); + } + } + } +#endif + png_ptr->mode |= PNG_WROTE_INFO_BEFORE_PLTE; + } +} + +void PNGAPI +png_write_info(png_structp png_ptr, png_infop info_ptr) +{ +#if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED) + int i; +#endif + + png_debug(1, "in png_write_info"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + + png_write_info_before_PLTE(png_ptr, info_ptr); + + if (info_ptr->valid & PNG_INFO_PLTE) + png_write_PLTE(png_ptr, info_ptr->palette, + (png_uint_32)info_ptr->num_palette); + else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + png_error(png_ptr, "Valid palette required for paletted images"); + +#ifdef PNG_WRITE_tRNS_SUPPORTED + if (info_ptr->valid & PNG_INFO_tRNS) + { +#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED + /* Invert the alpha channel (in tRNS) */ + if ((png_ptr->transformations & PNG_INVERT_ALPHA) && + info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + { + int j; + for (j = 0; j<(int)info_ptr->num_trans; j++) + info_ptr->trans[j] = (png_byte)(255 - info_ptr->trans[j]); + } +#endif + png_write_tRNS(png_ptr, info_ptr->trans, &(info_ptr->trans_values), + info_ptr->num_trans, info_ptr->color_type); + } +#endif +#ifdef PNG_WRITE_bKGD_SUPPORTED + if (info_ptr->valid & PNG_INFO_bKGD) + png_write_bKGD(png_ptr, &(info_ptr->background), info_ptr->color_type); +#endif +#ifdef PNG_WRITE_hIST_SUPPORTED + if (info_ptr->valid & PNG_INFO_hIST) + png_write_hIST(png_ptr, info_ptr->hist, info_ptr->num_palette); +#endif +#ifdef PNG_WRITE_oFFs_SUPPORTED + if (info_ptr->valid & PNG_INFO_oFFs) + png_write_oFFs(png_ptr, info_ptr->x_offset, info_ptr->y_offset, + info_ptr->offset_unit_type); +#endif +#ifdef PNG_WRITE_pCAL_SUPPORTED + if (info_ptr->valid & PNG_INFO_pCAL) + png_write_pCAL(png_ptr, info_ptr->pcal_purpose, info_ptr->pcal_X0, + info_ptr->pcal_X1, info_ptr->pcal_type, info_ptr->pcal_nparams, + info_ptr->pcal_units, info_ptr->pcal_params); +#endif + +#ifdef PNG_sCAL_SUPPORTED + if (info_ptr->valid & PNG_INFO_sCAL) +#ifdef PNG_WRITE_sCAL_SUPPORTED +#if defined(PNG_FLOATING_POINT_SUPPORTED) && defined(PNG_STDIO_SUPPORTED) + png_write_sCAL(png_ptr, (int)info_ptr->scal_unit, + info_ptr->scal_pixel_width, info_ptr->scal_pixel_height); +#else /* !FLOATING_POINT */ +#ifdef PNG_FIXED_POINT_SUPPORTED + png_write_sCAL_s(png_ptr, (int)info_ptr->scal_unit, + info_ptr->scal_s_width, info_ptr->scal_s_height); +#endif /* FIXED_POINT */ +#endif /* FLOATING_POINT */ +#else /* !WRITE_sCAL */ + png_warning(png_ptr, + "png_write_sCAL not supported; sCAL chunk not written."); +#endif /* WRITE_sCAL */ +#endif /* sCAL */ + +#ifdef PNG_WRITE_pHYs_SUPPORTED + if (info_ptr->valid & PNG_INFO_pHYs) + png_write_pHYs(png_ptr, info_ptr->x_pixels_per_unit, + info_ptr->y_pixels_per_unit, info_ptr->phys_unit_type); +#endif /* pHYs */ + +#ifdef PNG_WRITE_tIME_SUPPORTED + if (info_ptr->valid & PNG_INFO_tIME) + { + png_write_tIME(png_ptr, &(info_ptr->mod_time)); + png_ptr->mode |= PNG_WROTE_tIME; + } +#endif /* tIME */ + +#ifdef PNG_WRITE_sPLT_SUPPORTED + if (info_ptr->valid & PNG_INFO_sPLT) + for (i = 0; i < (int)info_ptr->splt_palettes_num; i++) + png_write_sPLT(png_ptr, info_ptr->splt_palettes + i); +#endif /* sPLT */ + +#ifdef PNG_WRITE_TEXT_SUPPORTED + /* Check to see if we need to write text chunks */ + for (i = 0; i < info_ptr->num_text; i++) + { + png_debug2(2, "Writing header text chunk %d, type %d", i, + info_ptr->text[i].compression); + /* An internationalized chunk? */ + if (info_ptr->text[i].compression > 0) + { +#ifdef PNG_WRITE_iTXt_SUPPORTED + /* Write international chunk */ + png_write_iTXt(png_ptr, + info_ptr->text[i].compression, + info_ptr->text[i].key, + info_ptr->text[i].lang, + info_ptr->text[i].lang_key, + info_ptr->text[i].text); +#else + png_warning(png_ptr, "Unable to write international text"); +#endif + /* Mark this chunk as written */ + info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR; + } + /* If we want a compressed text chunk */ + else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_zTXt) + { +#ifdef PNG_WRITE_zTXt_SUPPORTED + /* Write compressed chunk */ + png_write_zTXt(png_ptr, info_ptr->text[i].key, + info_ptr->text[i].text, 0, + info_ptr->text[i].compression); +#else + png_warning(png_ptr, "Unable to write compressed text"); +#endif + /* Mark this chunk as written */ + info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR; + } + else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE) + { +#ifdef PNG_WRITE_tEXt_SUPPORTED + /* Write uncompressed chunk */ + png_write_tEXt(png_ptr, info_ptr->text[i].key, + info_ptr->text[i].text, + 0); + /* Mark this chunk as written */ + info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR; +#else + /* Can't get here */ + png_warning(png_ptr, "Unable to write uncompressed text"); +#endif + } + } +#endif /* tEXt */ + +#if defined(PNG_WRITE_APNG_SUPPORTED) + if (info_ptr->valid & PNG_INFO_acTL) + png_write_acTL(png_ptr, info_ptr->num_frames, info_ptr->num_plays); +#endif +#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED + if (info_ptr->unknown_chunks_num) + { + png_unknown_chunk *up; + + png_debug(5, "writing extra chunks"); + + for (up = info_ptr->unknown_chunks; + up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num; + up++) + { + int keep = png_handle_as_unknown(png_ptr, up->name); + if (keep != PNG_HANDLE_CHUNK_NEVER && + up->location && (up->location & PNG_HAVE_PLTE) && + !(up->location & PNG_HAVE_IDAT) && + !(up->location & PNG_AFTER_IDAT) && + ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS || + (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS))) + { + png_write_chunk(png_ptr, up->name, up->data, up->size); + } + } + } +#endif +} + +/* Writes the end of the PNG file. If you don't want to write comments or + * time information, you can pass NULL for info. If you already wrote these + * in png_write_info(), do not write them again here. If you have long + * comments, I suggest writing them here, and compressing them. + */ +void PNGAPI +png_write_end(png_structp png_ptr, png_infop info_ptr) +{ + png_debug(1, "in png_write_end"); + + if (png_ptr == NULL) + return; + if (!(png_ptr->mode & PNG_HAVE_IDAT)) + png_error(png_ptr, "No IDATs written into file"); +#if defined(PNG_WRITE_APNG_SUPPORTED) + if (png_ptr->num_frames_written != png_ptr->num_frames_to_write) + png_error(png_ptr, "Not enough frames written"); +#endif + + /* See if user wants us to write information chunks */ + if (info_ptr != NULL) + { +#ifdef PNG_WRITE_TEXT_SUPPORTED + int i; /* local index variable */ +#endif +#ifdef PNG_WRITE_tIME_SUPPORTED + /* Check to see if user has supplied a time chunk */ + if ((info_ptr->valid & PNG_INFO_tIME) && + !(png_ptr->mode & PNG_WROTE_tIME)) + png_write_tIME(png_ptr, &(info_ptr->mod_time)); +#endif +#ifdef PNG_WRITE_TEXT_SUPPORTED + /* Loop through comment chunks */ + for (i = 0; i < info_ptr->num_text; i++) + { + png_debug2(2, "Writing trailer text chunk %d, type %d", i, + info_ptr->text[i].compression); + /* An internationalized chunk? */ + if (info_ptr->text[i].compression > 0) + { +#ifdef PNG_WRITE_iTXt_SUPPORTED + /* Write international chunk */ + png_write_iTXt(png_ptr, + info_ptr->text[i].compression, + info_ptr->text[i].key, + info_ptr->text[i].lang, + info_ptr->text[i].lang_key, + info_ptr->text[i].text); +#else + png_warning(png_ptr, "Unable to write international text"); +#endif + /* Mark this chunk as written */ + info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR; + } + else if (info_ptr->text[i].compression >= PNG_TEXT_COMPRESSION_zTXt) + { +#ifdef PNG_WRITE_zTXt_SUPPORTED + /* Write compressed chunk */ + png_write_zTXt(png_ptr, info_ptr->text[i].key, + info_ptr->text[i].text, 0, + info_ptr->text[i].compression); +#else + png_warning(png_ptr, "Unable to write compressed text"); +#endif + /* Mark this chunk as written */ + info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR; + } + else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE) + { +#ifdef PNG_WRITE_tEXt_SUPPORTED + /* Write uncompressed chunk */ + png_write_tEXt(png_ptr, info_ptr->text[i].key, + info_ptr->text[i].text, 0); +#else + png_warning(png_ptr, "Unable to write uncompressed text"); +#endif + + /* Mark this chunk as written */ + info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR; + } + } +#endif +#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED + if (info_ptr->unknown_chunks_num) + { + png_unknown_chunk *up; + + png_debug(5, "writing extra chunks"); + + for (up = info_ptr->unknown_chunks; + up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num; + up++) + { + int keep = png_handle_as_unknown(png_ptr, up->name); + if (keep != PNG_HANDLE_CHUNK_NEVER && + up->location && (up->location & PNG_AFTER_IDAT) && + ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS || + (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS))) + { + png_write_chunk(png_ptr, up->name, up->data, up->size); + } + } + } +#endif + } + + png_ptr->mode |= PNG_AFTER_IDAT; + + /* Write end of PNG file */ + png_write_IEND(png_ptr); + /* This flush, added in libpng-1.0.8, removed from libpng-1.0.9beta03, + * and restored again in libpng-1.2.30, may cause some applications that + * do not set png_ptr->output_flush_fn to crash. If your application + * experiences a problem, please try building libpng with + * PNG_WRITE_FLUSH_AFTER_IEND_SUPPORTED defined, and report the event to + * png-mng-implement at lists.sf.net . + */ +#ifdef PNG_WRITE_FLUSH_SUPPORTED +# ifdef PNG_WRITE_FLUSH_AFTER_IEND_SUPPORTED + png_flush(png_ptr); +# endif +#endif +} + +#ifdef PNG_CONVERT_tIME_SUPPORTED +/* "tm" structure is not supported on WindowsCE */ +void PNGAPI +png_convert_from_struct_tm(png_timep ptime, struct tm FAR * ttime) +{ + png_debug(1, "in png_convert_from_struct_tm"); + + ptime->year = (png_uint_16)(1900 + ttime->tm_year); + ptime->month = (png_byte)(ttime->tm_mon + 1); + ptime->day = (png_byte)ttime->tm_mday; + ptime->hour = (png_byte)ttime->tm_hour; + ptime->minute = (png_byte)ttime->tm_min; + ptime->second = (png_byte)ttime->tm_sec; +} + +void PNGAPI +png_convert_from_time_t(png_timep ptime, time_t ttime) +{ + struct tm *tbuf; + + png_debug(1, "in png_convert_from_time_t"); + + tbuf = gmtime(&ttime); + png_convert_from_struct_tm(ptime, tbuf); +} +#endif + +/* Initialize png_ptr structure, and allocate any memory needed */ +png_structp PNGAPI +png_create_write_struct(png_const_charp user_png_ver, png_voidp error_ptr, + png_error_ptr error_fn, png_error_ptr warn_fn) +{ +#ifdef PNG_USER_MEM_SUPPORTED + return (png_create_write_struct_2(user_png_ver, error_ptr, error_fn, + warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL)); +} + +/* Alternate initialize png_ptr structure, and allocate any memory needed */ +png_structp PNGAPI +png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr, + png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr, + png_malloc_ptr malloc_fn, png_free_ptr free_fn) +{ +#endif /* PNG_USER_MEM_SUPPORTED */ +#ifdef PNG_SETJMP_SUPPORTED + volatile +#endif + png_structp png_ptr; +#ifdef PNG_SETJMP_SUPPORTED +#ifdef USE_FAR_KEYWORD + jmp_buf jmpbuf; +#endif +#endif + int i; + + png_debug(1, "in png_create_write_struct"); + +#ifdef PNG_USER_MEM_SUPPORTED + png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG, + (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr); +#else + png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG); +#endif /* PNG_USER_MEM_SUPPORTED */ + if (png_ptr == NULL) + return (NULL); + + /* Added at libpng-1.2.6 */ +#ifdef PNG_SET_USER_LIMITS_SUPPORTED + png_ptr->user_width_max = PNG_USER_WIDTH_MAX; + png_ptr->user_height_max = PNG_USER_HEIGHT_MAX; +#endif + +#ifdef PNG_SETJMP_SUPPORTED +#ifdef USE_FAR_KEYWORD + if (setjmp(jmpbuf)) +#else + if (setjmp(png_ptr->jmpbuf)) +#endif + { + png_free(png_ptr, png_ptr->zbuf); + png_ptr->zbuf = NULL; +#ifdef PNG_USER_MEM_SUPPORTED + png_destroy_struct_2((png_voidp)png_ptr, + (png_free_ptr)free_fn, (png_voidp)mem_ptr); +#else + png_destroy_struct((png_voidp)png_ptr); +#endif + return (NULL); + } +#ifdef USE_FAR_KEYWORD + png_memcpy(png_ptr->jmpbuf, jmpbuf, png_sizeof(jmp_buf)); +#endif +#endif + +#ifdef PNG_USER_MEM_SUPPORTED + png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn); +#endif /* PNG_USER_MEM_SUPPORTED */ + png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn); + + if (user_png_ver) + { + i = 0; + do + { + if (user_png_ver[i] != png_libpng_ver[i]) + png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; + } while (png_libpng_ver[i++]); + } + + if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH) + { + /* Libpng 0.90 and later are binary incompatible with libpng 0.89, so + * we must recompile any applications that use any older library version. + * For versions after libpng 1.0, we will be compatible, so we need + * only check the first digit. + */ + if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] || + (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) || + (user_png_ver[0] == '0' && user_png_ver[2] < '9')) + { +#if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE) + char msg[80]; + if (user_png_ver) + { + png_snprintf(msg, 80, + "Application was compiled with png.h from libpng-%.20s", + user_png_ver); + png_warning(png_ptr, msg); + } + png_snprintf(msg, 80, + "Application is running with png.c from libpng-%.20s", + png_libpng_ver); + png_warning(png_ptr, msg); +#endif +#ifdef PNG_ERROR_NUMBERS_SUPPORTED + png_ptr->flags = 0; +#endif + png_error(png_ptr, + "Incompatible libpng version in application and library"); + } + } + + /* Initialize zbuf - compression buffer */ + png_ptr->zbuf_size = PNG_ZBUF_SIZE; + png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, + (png_uint_32)png_ptr->zbuf_size); + + png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL, + png_flush_ptr_NULL); + +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED + png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT, + 1, png_doublep_NULL, png_doublep_NULL); +#endif + +#ifdef PNG_SETJMP_SUPPORTED + /* Applications that neglect to set up their own setjmp() and then + * encounter a png_error() will longjmp here. Since the jmpbuf is + * then meaningless we abort instead of returning. + */ +#ifdef USE_FAR_KEYWORD + if (setjmp(jmpbuf)) + PNG_ABORT(); + png_memcpy(png_ptr->jmpbuf, jmpbuf, png_sizeof(jmp_buf)); +#else + if (setjmp(png_ptr->jmpbuf)) + PNG_ABORT(); +#endif +#endif + return (png_ptr); +} + +/* Initialize png_ptr structure, and allocate any memory needed */ +#if defined(PNG_1_0_X) || defined(PNG_1_2_X) +/* Deprecated. */ +#undef png_write_init +void PNGAPI +png_write_init(png_structp png_ptr) +{ + /* We only come here via pre-1.0.7-compiled applications */ + png_write_init_2(png_ptr, "1.0.6 or earlier", 0, 0); +} + +void PNGAPI +png_write_init_2(png_structp png_ptr, png_const_charp user_png_ver, + png_size_t png_struct_size, png_size_t png_info_size) +{ + /* We only come here via pre-1.0.12-compiled applications */ + if (png_ptr == NULL) return; +#if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE) + if (png_sizeof(png_struct) > png_struct_size || + png_sizeof(png_info) > png_info_size) + { + char msg[80]; + png_ptr->warning_fn = NULL; + if (user_png_ver) + { + png_snprintf(msg, 80, + "Application was compiled with png.h from libpng-%.20s", + user_png_ver); + png_warning(png_ptr, msg); + } + png_snprintf(msg, 80, + "Application is running with png.c from libpng-%.20s", + png_libpng_ver); + png_warning(png_ptr, msg); + } +#endif + if (png_sizeof(png_struct) > png_struct_size) + { + png_ptr->error_fn = NULL; +#ifdef PNG_ERROR_NUMBERS_SUPPORTED + png_ptr->flags = 0; +#endif + png_error(png_ptr, + "The png struct allocated by the application for writing is" + " too small."); + } + if (png_sizeof(png_info) > png_info_size) + { + png_ptr->error_fn = NULL; +#ifdef PNG_ERROR_NUMBERS_SUPPORTED + png_ptr->flags = 0; +#endif + png_error(png_ptr, + "The info struct allocated by the application for writing is" + " too small."); + } + png_write_init_3(&png_ptr, user_png_ver, png_struct_size); +} +#endif /* PNG_1_0_X || PNG_1_2_X */ + + +void PNGAPI +png_write_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver, + png_size_t png_struct_size) +{ + png_structp png_ptr = *ptr_ptr; +#ifdef PNG_SETJMP_SUPPORTED + jmp_buf tmp_jmp; /* to save current jump buffer */ +#endif + + int i = 0; + + if (png_ptr == NULL) + return; + + do + { + if (user_png_ver[i] != png_libpng_ver[i]) + { +#ifdef PNG_LEGACY_SUPPORTED + png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; +#else + png_ptr->warning_fn = NULL; + png_warning(png_ptr, + "Application uses deprecated png_write_init() and should be recompiled."); +#endif + } + } while (png_libpng_ver[i++]); + + png_debug(1, "in png_write_init_3"); + +#ifdef PNG_SETJMP_SUPPORTED + /* Save jump buffer and error functions */ + png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof(jmp_buf)); +#endif + + if (png_sizeof(png_struct) > png_struct_size) + { + png_destroy_struct(png_ptr); + png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG); + *ptr_ptr = png_ptr; + } + + /* Reset all variables to 0 */ + png_memset(png_ptr, 0, png_sizeof(png_struct)); + + /* Added at libpng-1.2.6 */ +#ifdef PNG_SET_USER_LIMITS_SUPPORTED + png_ptr->user_width_max = PNG_USER_WIDTH_MAX; + png_ptr->user_height_max = PNG_USER_HEIGHT_MAX; +#endif + +#ifdef PNG_SETJMP_SUPPORTED + /* Restore jump buffer */ + png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof(jmp_buf)); +#endif + + png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL, + png_flush_ptr_NULL); + + /* Initialize zbuf - compression buffer */ + png_ptr->zbuf_size = PNG_ZBUF_SIZE; + png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, + (png_uint_32)png_ptr->zbuf_size); +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED + png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT, + 1, png_doublep_NULL, png_doublep_NULL); +#endif +} + +/* Write a few rows of image data. If the image is interlaced, + * either you will have to write the 7 sub images, or, if you + * have called png_set_interlace_handling(), you will have to + * "write" the image seven times. + */ +void PNGAPI +png_write_rows(png_structp png_ptr, png_bytepp row, + png_uint_32 num_rows) +{ + png_uint_32 i; /* row counter */ + png_bytepp rp; /* row pointer */ + + png_debug(1, "in png_write_rows"); + + if (png_ptr == NULL) + return; + + /* Loop through the rows */ + for (i = 0, rp = row; i < num_rows; i++, rp++) + { + png_write_row(png_ptr, *rp); + } +} + +/* Write the image. You only need to call this function once, even + * if you are writing an interlaced image. + */ +void PNGAPI +png_write_image(png_structp png_ptr, png_bytepp image) +{ + png_uint_32 i; /* row index */ + int pass, num_pass; /* pass variables */ + png_bytepp rp; /* points to current row */ + + if (png_ptr == NULL) + return; + + png_debug(1, "in png_write_image"); + +#ifdef PNG_WRITE_INTERLACING_SUPPORTED + /* Initialize interlace handling. If image is not interlaced, + * this will set pass to 1 + */ + num_pass = png_set_interlace_handling(png_ptr); +#else + num_pass = 1; +#endif + /* Loop through passes */ + for (pass = 0; pass < num_pass; pass++) + { + /* Loop through image */ + for (i = 0, rp = image; i < png_ptr->height; i++, rp++) + { + png_write_row(png_ptr, *rp); + } + } +} + +/* Called by user to write a row of image data */ +void PNGAPI +png_write_row(png_structp png_ptr, png_bytep row) +{ + if (png_ptr == NULL) + return; + + png_debug2(1, "in png_write_row (row %ld, pass %d)", + png_ptr->row_number, png_ptr->pass); + + /* Initialize transformations and other stuff if first time */ + if (png_ptr->row_number == 0 && png_ptr->pass == 0) + { + /* Make sure we wrote the header info */ + if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE)) + png_error(png_ptr, + "png_write_info was never called before png_write_row."); + + /* Check for transforms that have been set but were defined out */ +#if !defined(PNG_WRITE_INVERT_SUPPORTED) && defined(PNG_READ_INVERT_SUPPORTED) + if (png_ptr->transformations & PNG_INVERT_MONO) + png_warning(png_ptr, + "PNG_WRITE_INVERT_SUPPORTED is not defined."); +#endif +#if !defined(PNG_WRITE_FILLER_SUPPORTED) && defined(PNG_READ_FILLER_SUPPORTED) + if (png_ptr->transformations & PNG_FILLER) + png_warning(png_ptr, + "PNG_WRITE_FILLER_SUPPORTED is not defined."); +#endif +#if !defined(PNG_WRITE_PACKSWAP_SUPPORTED) && \ + defined(PNG_READ_PACKSWAP_SUPPORTED) + if (png_ptr->transformations & PNG_PACKSWAP) + png_warning(png_ptr, + "PNG_WRITE_PACKSWAP_SUPPORTED is not defined."); +#endif +#if !defined(PNG_WRITE_PACK_SUPPORTED) && defined(PNG_READ_PACK_SUPPORTED) + if (png_ptr->transformations & PNG_PACK) + png_warning(png_ptr, "PNG_WRITE_PACK_SUPPORTED is not defined."); +#endif +#if !defined(PNG_WRITE_SHIFT_SUPPORTED) && defined(PNG_READ_SHIFT_SUPPORTED) + if (png_ptr->transformations & PNG_SHIFT) + png_warning(png_ptr, "PNG_WRITE_SHIFT_SUPPORTED is not defined."); +#endif +#if !defined(PNG_WRITE_BGR_SUPPORTED) && defined(PNG_READ_BGR_SUPPORTED) + if (png_ptr->transformations & PNG_BGR) + png_warning(png_ptr, "PNG_WRITE_BGR_SUPPORTED is not defined."); +#endif +#if !defined(PNG_WRITE_SWAP_SUPPORTED) && defined(PNG_READ_SWAP_SUPPORTED) + if (png_ptr->transformations & PNG_SWAP_BYTES) + png_warning(png_ptr, "PNG_WRITE_SWAP_SUPPORTED is not defined."); +#endif + + png_write_start_row(png_ptr); + } + +#ifdef PNG_WRITE_INTERLACING_SUPPORTED + /* If interlaced and not interested in row, return */ + if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE)) + { + switch (png_ptr->pass) + { + case 0: + if (png_ptr->row_number & 0x07) + { + png_write_finish_row(png_ptr); + return; + } + break; + case 1: + if ((png_ptr->row_number & 0x07) || png_ptr->width < 5) + { + png_write_finish_row(png_ptr); + return; + } + break; + case 2: + if ((png_ptr->row_number & 0x07) != 4) + { + png_write_finish_row(png_ptr); + return; + } + break; + case 3: + if ((png_ptr->row_number & 0x03) || png_ptr->width < 3) + { + png_write_finish_row(png_ptr); + return; + } + break; + case 4: + if ((png_ptr->row_number & 0x03) != 2) + { + png_write_finish_row(png_ptr); + return; + } + break; + case 5: + if ((png_ptr->row_number & 0x01) || png_ptr->width < 2) + { + png_write_finish_row(png_ptr); + return; + } + break; + case 6: + if (!(png_ptr->row_number & 0x01)) + { + png_write_finish_row(png_ptr); + return; + } + break; + } + } +#endif + + /* Set up row info for transformations */ + png_ptr->row_info.color_type = png_ptr->color_type; + png_ptr->row_info.width = png_ptr->usr_width; + png_ptr->row_info.channels = png_ptr->usr_channels; + png_ptr->row_info.bit_depth = png_ptr->usr_bit_depth; + png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth * + png_ptr->row_info.channels); + + png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth, + png_ptr->row_info.width); + + png_debug1(3, "row_info->color_type = %d", png_ptr->row_info.color_type); + png_debug1(3, "row_info->width = %lu", png_ptr->row_info.width); + png_debug1(3, "row_info->channels = %d", png_ptr->row_info.channels); + png_debug1(3, "row_info->bit_depth = %d", png_ptr->row_info.bit_depth); + png_debug1(3, "row_info->pixel_depth = %d", png_ptr->row_info.pixel_depth); + png_debug1(3, "row_info->rowbytes = %lu", png_ptr->row_info.rowbytes); + + /* Copy user's row into buffer, leaving room for filter byte. */ + png_memcpy_check(png_ptr, png_ptr->row_buf + 1, row, + png_ptr->row_info.rowbytes); + +#ifdef PNG_WRITE_INTERLACING_SUPPORTED + /* Handle interlacing */ + if (png_ptr->interlaced && png_ptr->pass < 6 && + (png_ptr->transformations & PNG_INTERLACE)) + { + png_do_write_interlace(&(png_ptr->row_info), + png_ptr->row_buf + 1, png_ptr->pass); + /* This should always get caught above, but still ... */ + if (!(png_ptr->row_info.width)) + { + png_write_finish_row(png_ptr); + return; + } + } +#endif + + /* Handle other transformations */ + if (png_ptr->transformations) + png_do_write_transformations(png_ptr); + +#ifdef PNG_MNG_FEATURES_SUPPORTED + /* Write filter_method 64 (intrapixel differencing) only if + * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and + * 2. Libpng did not write a PNG signature (this filter_method is only + * used in PNG datastreams that are embedded in MNG datastreams) and + * 3. The application called png_permit_mng_features with a mask that + * included PNG_FLAG_MNG_FILTER_64 and + * 4. The filter_method is 64 and + * 5. The color_type is RGB or RGBA + */ + if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && + (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING)) + { + /* Intrapixel differencing */ + png_do_write_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1); + } +#endif + + /* Find a filter if necessary, filter the row and write it out. */ + png_write_find_filter(png_ptr, &(png_ptr->row_info)); + + if (png_ptr->write_row_fn != NULL) + (*(png_ptr->write_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass); +} + +#ifdef PNG_WRITE_FLUSH_SUPPORTED +/* Set the automatic flush interval or 0 to turn flushing off */ +void PNGAPI +png_set_flush(png_structp png_ptr, int nrows) +{ + png_debug(1, "in png_set_flush"); + + if (png_ptr == NULL) + return; + png_ptr->flush_dist = (nrows < 0 ? 0 : nrows); +} + +/* Flush the current output buffers now */ +void PNGAPI +png_write_flush(png_structp png_ptr) +{ + int wrote_IDAT; + + png_debug(1, "in png_write_flush"); + + if (png_ptr == NULL) + return; + /* We have already written out all of the data */ + if (png_ptr->row_number >= png_ptr->num_rows) + return; + + do + { + int ret; + + /* Compress the data */ + ret = deflate(&png_ptr->zstream, Z_SYNC_FLUSH); + wrote_IDAT = 0; + + /* Check for compression errors */ + if (ret != Z_OK) + { + if (png_ptr->zstream.msg != NULL) + png_error(png_ptr, png_ptr->zstream.msg); + else + png_error(png_ptr, "zlib error"); + } + + if (!(png_ptr->zstream.avail_out)) + { + /* Write the IDAT and reset the zlib output buffer */ + png_write_IDAT(png_ptr, png_ptr->zbuf, + png_ptr->zbuf_size); + png_ptr->zstream.next_out = png_ptr->zbuf; + png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; + wrote_IDAT = 1; + } + } while(wrote_IDAT == 1); + + /* If there is any data left to be output, write it into a new IDAT */ + if (png_ptr->zbuf_size != png_ptr->zstream.avail_out) + { + /* Write the IDAT and reset the zlib output buffer */ + png_write_IDAT(png_ptr, png_ptr->zbuf, + png_ptr->zbuf_size - png_ptr->zstream.avail_out); + png_ptr->zstream.next_out = png_ptr->zbuf; + png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; + } + png_ptr->flush_rows = 0; + png_flush(png_ptr); +} +#endif /* PNG_WRITE_FLUSH_SUPPORTED */ + +/* Free all memory used by the write */ +void PNGAPI +png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr) +{ + png_structp png_ptr = NULL; + png_infop info_ptr = NULL; +#ifdef PNG_USER_MEM_SUPPORTED + png_free_ptr free_fn = NULL; + png_voidp mem_ptr = NULL; +#endif + + png_debug(1, "in png_destroy_write_struct"); + + if (png_ptr_ptr != NULL) + { + png_ptr = *png_ptr_ptr; +#ifdef PNG_USER_MEM_SUPPORTED + free_fn = png_ptr->free_fn; + mem_ptr = png_ptr->mem_ptr; +#endif + } + +#ifdef PNG_USER_MEM_SUPPORTED + if (png_ptr != NULL) + { + free_fn = png_ptr->free_fn; + mem_ptr = png_ptr->mem_ptr; + } +#endif + + if (info_ptr_ptr != NULL) + info_ptr = *info_ptr_ptr; + + if (info_ptr != NULL) + { + if (png_ptr != NULL) + { + png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1); + +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED + if (png_ptr->num_chunk_list) + { + png_free(png_ptr, png_ptr->chunk_list); + png_ptr->chunk_list = NULL; + png_ptr->num_chunk_list = 0; + } +#endif + } + +#ifdef PNG_USER_MEM_SUPPORTED + png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn, + (png_voidp)mem_ptr); +#else + png_destroy_struct((png_voidp)info_ptr); +#endif + *info_ptr_ptr = NULL; + } + + if (png_ptr != NULL) + { + png_write_destroy(png_ptr); +#ifdef PNG_USER_MEM_SUPPORTED + png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn, + (png_voidp)mem_ptr); +#else + png_destroy_struct((png_voidp)png_ptr); +#endif + *png_ptr_ptr = NULL; + } +} + + +/* Free any memory used in png_ptr struct (old method) */ +void /* PRIVATE */ +png_write_destroy(png_structp png_ptr) +{ +#ifdef PNG_SETJMP_SUPPORTED + jmp_buf tmp_jmp; /* Save jump buffer */ +#endif + png_error_ptr error_fn; + png_error_ptr warning_fn; + png_voidp error_ptr; +#ifdef PNG_USER_MEM_SUPPORTED + png_free_ptr free_fn; +#endif + + png_debug(1, "in png_write_destroy"); + + /* Free any memory zlib uses */ + deflateEnd(&png_ptr->zstream); + + /* Free our memory. png_free checks NULL for us. */ + png_free(png_ptr, png_ptr->zbuf); + png_free(png_ptr, png_ptr->row_buf); +#ifdef PNG_WRITE_FILTER_SUPPORTED + png_free(png_ptr, png_ptr->prev_row); + png_free(png_ptr, png_ptr->sub_row); + png_free(png_ptr, png_ptr->up_row); + png_free(png_ptr, png_ptr->avg_row); + png_free(png_ptr, png_ptr->paeth_row); +#endif + +#ifdef PNG_TIME_RFC1123_SUPPORTED + png_free(png_ptr, png_ptr->time_buffer); +#endif + +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED + png_free(png_ptr, png_ptr->prev_filters); + png_free(png_ptr, png_ptr->filter_weights); + png_free(png_ptr, png_ptr->inv_filter_weights); + png_free(png_ptr, png_ptr->filter_costs); + png_free(png_ptr, png_ptr->inv_filter_costs); +#endif + +#ifdef PNG_SETJMP_SUPPORTED + /* Reset structure */ + png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof(jmp_buf)); +#endif + + error_fn = png_ptr->error_fn; + warning_fn = png_ptr->warning_fn; + error_ptr = png_ptr->error_ptr; +#ifdef PNG_USER_MEM_SUPPORTED + free_fn = png_ptr->free_fn; +#endif + + png_memset(png_ptr, 0, png_sizeof(png_struct)); + + png_ptr->error_fn = error_fn; + png_ptr->warning_fn = warning_fn; + png_ptr->error_ptr = error_ptr; +#ifdef PNG_USER_MEM_SUPPORTED + png_ptr->free_fn = free_fn; +#endif + +#ifdef PNG_SETJMP_SUPPORTED + png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof(jmp_buf)); +#endif +} + +/* Allow the application to select one or more row filters to use. */ +void PNGAPI +png_set_filter(png_structp png_ptr, int method, int filters) +{ + png_debug(1, "in png_set_filter"); + + if (png_ptr == NULL) + return; +#ifdef PNG_MNG_FEATURES_SUPPORTED + if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && + (method == PNG_INTRAPIXEL_DIFFERENCING)) + method = PNG_FILTER_TYPE_BASE; +#endif + if (method == PNG_FILTER_TYPE_BASE) + { + switch (filters & (PNG_ALL_FILTERS | 0x07)) + { +#ifdef PNG_WRITE_FILTER_SUPPORTED + case 5: + case 6: + case 7: png_warning(png_ptr, "Unknown row filter for method 0"); +#endif /* PNG_WRITE_FILTER_SUPPORTED */ + case PNG_FILTER_VALUE_NONE: + png_ptr->do_filter = PNG_FILTER_NONE; break; +#ifdef PNG_WRITE_FILTER_SUPPORTED + case PNG_FILTER_VALUE_SUB: + png_ptr->do_filter = PNG_FILTER_SUB; break; + case PNG_FILTER_VALUE_UP: + png_ptr->do_filter = PNG_FILTER_UP; break; + case PNG_FILTER_VALUE_AVG: + png_ptr->do_filter = PNG_FILTER_AVG; break; + case PNG_FILTER_VALUE_PAETH: + png_ptr->do_filter = PNG_FILTER_PAETH; break; + default: png_ptr->do_filter = (png_byte)filters; break; +#else + default: png_warning(png_ptr, "Unknown row filter for method 0"); +#endif /* PNG_WRITE_FILTER_SUPPORTED */ + } + + /* If we have allocated the row_buf, this means we have already started + * with the image and we should have allocated all of the filter buffers + * that have been selected. If prev_row isn't already allocated, then + * it is too late to start using the filters that need it, since we + * will be missing the data in the previous row. If an application + * wants to start and stop using particular filters during compression, + * it should start out with all of the filters, and then add and + * remove them after the start of compression. + */ + if (png_ptr->row_buf != NULL) + { +#ifdef PNG_WRITE_FILTER_SUPPORTED + if ((png_ptr->do_filter & PNG_FILTER_SUB) && png_ptr->sub_row == NULL) + { + png_ptr->sub_row = (png_bytep)png_malloc(png_ptr, + (png_ptr->rowbytes + 1)); + png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB; + } + + if ((png_ptr->do_filter & PNG_FILTER_UP) && png_ptr->up_row == NULL) + { + if (png_ptr->prev_row == NULL) + { + png_warning(png_ptr, "Can't add Up filter after starting"); + png_ptr->do_filter &= ~PNG_FILTER_UP; + } + else + { + png_ptr->up_row = (png_bytep)png_malloc(png_ptr, + (png_ptr->rowbytes + 1)); + png_ptr->up_row[0] = PNG_FILTER_VALUE_UP; + } + } + + if ((png_ptr->do_filter & PNG_FILTER_AVG) && png_ptr->avg_row == NULL) + { + if (png_ptr->prev_row == NULL) + { + png_warning(png_ptr, "Can't add Average filter after starting"); + png_ptr->do_filter &= ~PNG_FILTER_AVG; + } + else + { + png_ptr->avg_row = (png_bytep)png_malloc(png_ptr, + (png_ptr->rowbytes + 1)); + png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG; + } + } + + if ((png_ptr->do_filter & PNG_FILTER_PAETH) && + png_ptr->paeth_row == NULL) + { + if (png_ptr->prev_row == NULL) + { + png_warning(png_ptr, "Can't add Paeth filter after starting"); + png_ptr->do_filter &= (png_byte)(~PNG_FILTER_PAETH); + } + else + { + png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr, + (png_ptr->rowbytes + 1)); + png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH; + } + } + + if (png_ptr->do_filter == PNG_NO_FILTERS) +#endif /* PNG_WRITE_FILTER_SUPPORTED */ + png_ptr->do_filter = PNG_FILTER_NONE; + } + } + else + png_error(png_ptr, "Unknown custom filter method"); +} + +/* This allows us to influence the way in which libpng chooses the "best" + * filter for the current scanline. While the "minimum-sum-of-absolute- + * differences metric is relatively fast and effective, there is some + * question as to whether it can be improved upon by trying to keep the + * filtered data going to zlib more consistent, hopefully resulting in + * better compression. + */ +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED /* GRR 970116 */ +void PNGAPI +png_set_filter_heuristics(png_structp png_ptr, int heuristic_method, + int num_weights, png_doublep filter_weights, + png_doublep filter_costs) +{ + int i; + + png_debug(1, "in png_set_filter_heuristics"); + + if (png_ptr == NULL) + return; + if (heuristic_method >= PNG_FILTER_HEURISTIC_LAST) + { + png_warning(png_ptr, "Unknown filter heuristic method"); + return; + } + + if (heuristic_method == PNG_FILTER_HEURISTIC_DEFAULT) + { + heuristic_method = PNG_FILTER_HEURISTIC_UNWEIGHTED; + } + + if (num_weights < 0 || filter_weights == NULL || + heuristic_method == PNG_FILTER_HEURISTIC_UNWEIGHTED) + { + num_weights = 0; + } + + png_ptr->num_prev_filters = (png_byte)num_weights; + png_ptr->heuristic_method = (png_byte)heuristic_method; + + if (num_weights > 0) + { + if (png_ptr->prev_filters == NULL) + { + png_ptr->prev_filters = (png_bytep)png_malloc(png_ptr, + (png_uint_32)(png_sizeof(png_byte) * num_weights)); + + /* To make sure that the weighting starts out fairly */ + for (i = 0; i < num_weights; i++) + { + png_ptr->prev_filters[i] = 255; + } + } + + if (png_ptr->filter_weights == NULL) + { + png_ptr->filter_weights = (png_uint_16p)png_malloc(png_ptr, + (png_uint_32)(png_sizeof(png_uint_16) * num_weights)); + + png_ptr->inv_filter_weights = (png_uint_16p)png_malloc(png_ptr, + (png_uint_32)(png_sizeof(png_uint_16) * num_weights)); + for (i = 0; i < num_weights; i++) + { + png_ptr->inv_filter_weights[i] = + png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR; + } + } + + for (i = 0; i < num_weights; i++) + { + if (filter_weights[i] < 0.0) + { + png_ptr->inv_filter_weights[i] = + png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR; + } + else + { + png_ptr->inv_filter_weights[i] = + (png_uint_16)((double)PNG_WEIGHT_FACTOR*filter_weights[i]+0.5); + png_ptr->filter_weights[i] = + (png_uint_16)((double)PNG_WEIGHT_FACTOR/filter_weights[i]+0.5); + } + } + } + + /* If, in the future, there are other filter methods, this would + * need to be based on png_ptr->filter. + */ + if (png_ptr->filter_costs == NULL) + { + png_ptr->filter_costs = (png_uint_16p)png_malloc(png_ptr, + (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST)); + + png_ptr->inv_filter_costs = (png_uint_16p)png_malloc(png_ptr, + (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST)); + + for (i = 0; i < PNG_FILTER_VALUE_LAST; i++) + { + png_ptr->inv_filter_costs[i] = + png_ptr->filter_costs[i] = PNG_COST_FACTOR; + } + } + + /* Here is where we set the relative costs of the different filters. We + * should take the desired compression level into account when setting + * the costs, so that Paeth, for instance, has a high relative cost at low + * compression levels, while it has a lower relative cost at higher + * compression settings. The filter types are in order of increasing + * relative cost, so it would be possible to do this with an algorithm. + */ + for (i = 0; i < PNG_FILTER_VALUE_LAST; i++) + { + if (filter_costs == NULL || filter_costs[i] < 0.0) + { + png_ptr->inv_filter_costs[i] = + png_ptr->filter_costs[i] = PNG_COST_FACTOR; + } + else if (filter_costs[i] >= 1.0) + { + png_ptr->inv_filter_costs[i] = + (png_uint_16)((double)PNG_COST_FACTOR / filter_costs[i] + 0.5); + png_ptr->filter_costs[i] = + (png_uint_16)((double)PNG_COST_FACTOR * filter_costs[i] + 0.5); + } + } +} +#endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */ + +void PNGAPI +png_set_compression_level(png_structp png_ptr, int level) +{ + png_debug(1, "in png_set_compression_level"); + + if (png_ptr == NULL) + return; + png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_LEVEL; + png_ptr->zlib_level = level; +} + +void PNGAPI +png_set_compression_mem_level(png_structp png_ptr, int mem_level) +{ + png_debug(1, "in png_set_compression_mem_level"); + + if (png_ptr == NULL) + return; + png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL; + png_ptr->zlib_mem_level = mem_level; +} + +void PNGAPI +png_set_compression_strategy(png_structp png_ptr, int strategy) +{ + png_debug(1, "in png_set_compression_strategy"); + + if (png_ptr == NULL) + return; + png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_STRATEGY; + png_ptr->zlib_strategy = strategy; +} + +void PNGAPI +png_set_compression_window_bits(png_structp png_ptr, int window_bits) +{ + if (png_ptr == NULL) + return; + if (window_bits > 15) + png_warning(png_ptr, "Only compression windows <= 32k supported by PNG"); + else if (window_bits < 8) + png_warning(png_ptr, "Only compression windows >= 256 supported by PNG"); +#ifndef WBITS_8_OK + /* Avoid libpng bug with 256-byte windows */ + if (window_bits == 8) + { + png_warning(png_ptr, "Compression window is being reset to 512"); + window_bits = 9; + } +#endif + png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS; + png_ptr->zlib_window_bits = window_bits; +} + +void PNGAPI +png_set_compression_method(png_structp png_ptr, int method) +{ + png_debug(1, "in png_set_compression_method"); + + if (png_ptr == NULL) + return; + if (method != 8) + png_warning(png_ptr, "Only compression method 8 is supported by PNG"); + png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_METHOD; + png_ptr->zlib_method = method; +} + +void PNGAPI +png_set_write_status_fn(png_structp png_ptr, png_write_status_ptr write_row_fn) +{ + if (png_ptr == NULL) + return; + png_ptr->write_row_fn = write_row_fn; +} + +#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED +void PNGAPI +png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr + write_user_transform_fn) +{ + png_debug(1, "in png_set_write_user_transform_fn"); + + if (png_ptr == NULL) + return; + png_ptr->transformations |= PNG_USER_TRANSFORM; + png_ptr->write_user_transform_fn = write_user_transform_fn; +} +#endif + + +#ifdef PNG_INFO_IMAGE_SUPPORTED +void PNGAPI +png_write_png(png_structp png_ptr, png_infop info_ptr, + int transforms, voidp params) +{ + if (png_ptr == NULL || info_ptr == NULL) + return; + + /* Write the file header information. */ + png_write_info(png_ptr, info_ptr); + + /* ------ these transformations don't touch the info structure ------- */ + +#ifdef PNG_WRITE_INVERT_SUPPORTED + /* Invert monochrome pixels */ + if (transforms & PNG_TRANSFORM_INVERT_MONO) + png_set_invert_mono(png_ptr); +#endif + +#ifdef PNG_WRITE_SHIFT_SUPPORTED + /* Shift the pixels up to a legal bit depth and fill in + * as appropriate to correctly scale the image. + */ + if ((transforms & PNG_TRANSFORM_SHIFT) + && (info_ptr->valid & PNG_INFO_sBIT)) + png_set_shift(png_ptr, &info_ptr->sig_bit); +#endif + +#ifdef PNG_WRITE_PACK_SUPPORTED + /* Pack pixels into bytes */ + if (transforms & PNG_TRANSFORM_PACKING) + png_set_packing(png_ptr); +#endif + +#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED + /* Swap location of alpha bytes from ARGB to RGBA */ + if (transforms & PNG_TRANSFORM_SWAP_ALPHA) + png_set_swap_alpha(png_ptr); +#endif + +#ifdef PNG_WRITE_FILLER_SUPPORTED + /* Pack XRGB/RGBX/ARGB/RGBA into * RGB (4 channels -> 3 channels) */ + if (transforms & PNG_TRANSFORM_STRIP_FILLER_AFTER) + png_set_filler(png_ptr, 0, PNG_FILLER_AFTER); + else if (transforms & PNG_TRANSFORM_STRIP_FILLER_BEFORE) + png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE); +#endif + +#ifdef PNG_WRITE_BGR_SUPPORTED + /* Flip BGR pixels to RGB */ + if (transforms & PNG_TRANSFORM_BGR) + png_set_bgr(png_ptr); +#endif + +#ifdef PNG_WRITE_SWAP_SUPPORTED + /* Swap bytes of 16-bit files to most significant byte first */ + if (transforms & PNG_TRANSFORM_SWAP_ENDIAN) + png_set_swap(png_ptr); +#endif + +#ifdef PNG_WRITE_PACKSWAP_SUPPORTED + /* Swap bits of 1, 2, 4 bit packed pixel formats */ + if (transforms & PNG_TRANSFORM_PACKSWAP) + png_set_packswap(png_ptr); +#endif + +#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED + /* Invert the alpha channel from opacity to transparency */ + if (transforms & PNG_TRANSFORM_INVERT_ALPHA) + png_set_invert_alpha(png_ptr); +#endif + + /* ----------------------- end of transformations ------------------- */ + + /* Write the bits */ + if (info_ptr->valid & PNG_INFO_IDAT) + png_write_image(png_ptr, info_ptr->row_pointers); + + /* It is REQUIRED to call this to finish writing the rest of the file */ + png_write_end(png_ptr, info_ptr); + + transforms = transforms; /* Quiet compiler warnings */ + params = params; +} +#endif + +#if defined(PNG_WRITE_APNG_SUPPORTED) +void PNGAPI +png_write_frame_head(png_structp png_ptr, png_infop info_ptr, + png_bytepp row_pointers, png_uint_32 width, png_uint_32 height, + png_uint_32 x_offset, png_uint_32 y_offset, + png_uint_16 delay_num, png_uint_16 delay_den, png_byte dispose_op, + png_byte blend_op) +{ + png_debug(1, "in png_write_frame_head"); + + /* there is a chance this has been set after png_write_info was called, + * so it would be set but not written. is there a way to be sure? */ + if (!(info_ptr->valid & PNG_INFO_acTL)) + png_error(png_ptr, "png_write_frame_head(): acTL not set"); + + png_write_reset(png_ptr); + + png_write_reinit(png_ptr, info_ptr, width, height); + + if ( !(png_ptr->num_frames_written == 0 && + (png_ptr->apng_flags & PNG_FIRST_FRAME_HIDDEN) ) ) + png_write_fcTL(png_ptr, width, height, x_offset, y_offset, + delay_num, delay_den, dispose_op, blend_op); +} + +void PNGAPI +png_write_frame_tail(png_structp png_ptr, png_infop png_info) +{ + png_debug(1, "in png_write_frame_tail"); + + png_ptr->num_frames_written++; +} +#endif /* PNG_WRITE_APNG_SUPPORTED */ + +#endif /* PNG_WRITE_SUPPORTED */ diff --git a/libs/libpng-src/pngwtran.c b/libs/libpng-src/pngwtran.c new file mode 100644 index 000000000..0ce9b9b50 --- /dev/null +++ b/libs/libpng-src/pngwtran.c @@ -0,0 +1,582 @@ + +/* pngwtran.c - transforms the data in a row for PNG writers + * + * Last changed in libpng 1.2.43 [February 25, 2010] + * Copyright (c) 1998-2010 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + */ + +#define PNG_INTERNAL +#define PNG_NO_PEDANTIC_WARNINGS +#include "png.h" +#ifdef PNG_WRITE_SUPPORTED + +/* Transform the data according to the user's wishes. The order of + * transformations is significant. + */ +void /* PRIVATE */ +png_do_write_transformations(png_structp png_ptr) +{ + png_debug(1, "in png_do_write_transformations"); + + if (png_ptr == NULL) + return; + +#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED + if (png_ptr->transformations & PNG_USER_TRANSFORM) + if (png_ptr->write_user_transform_fn != NULL) + (*(png_ptr->write_user_transform_fn)) /* User write transform + function */ + (png_ptr, /* png_ptr */ + &(png_ptr->row_info), /* row_info: */ + /* png_uint_32 width; width of row */ + /* png_uint_32 rowbytes; number of bytes in row */ + /* png_byte color_type; color type of pixels */ + /* png_byte bit_depth; bit depth of samples */ + /* png_byte channels; number of channels (1-4) */ + /* png_byte pixel_depth; bits per pixel (depth*channels) */ + png_ptr->row_buf + 1); /* start of pixel data for row */ +#endif +#ifdef PNG_WRITE_FILLER_SUPPORTED + if (png_ptr->transformations & PNG_FILLER) + png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1, + png_ptr->flags); +#endif +#ifdef PNG_WRITE_PACKSWAP_SUPPORTED + if (png_ptr->transformations & PNG_PACKSWAP) + png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1); +#endif +#ifdef PNG_WRITE_PACK_SUPPORTED + if (png_ptr->transformations & PNG_PACK) + png_do_pack(&(png_ptr->row_info), png_ptr->row_buf + 1, + (png_uint_32)png_ptr->bit_depth); +#endif +#ifdef PNG_WRITE_SWAP_SUPPORTED + if (png_ptr->transformations & PNG_SWAP_BYTES) + png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1); +#endif +#ifdef PNG_WRITE_SHIFT_SUPPORTED + if (png_ptr->transformations & PNG_SHIFT) + png_do_shift(&(png_ptr->row_info), png_ptr->row_buf + 1, + &(png_ptr->shift)); +#endif +#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED + if (png_ptr->transformations & PNG_SWAP_ALPHA) + png_do_write_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1); +#endif +#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED + if (png_ptr->transformations & PNG_INVERT_ALPHA) + png_do_write_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1); +#endif +#ifdef PNG_WRITE_BGR_SUPPORTED + if (png_ptr->transformations & PNG_BGR) + png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1); +#endif +#ifdef PNG_WRITE_INVERT_SUPPORTED + if (png_ptr->transformations & PNG_INVERT_MONO) + png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1); +#endif +} + +#ifdef PNG_WRITE_PACK_SUPPORTED +/* Pack pixels into bytes. Pass the true bit depth in bit_depth. The + * row_info bit depth should be 8 (one pixel per byte). The channels + * should be 1 (this only happens on grayscale and paletted images). + */ +void /* PRIVATE */ +png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth) +{ + png_debug(1, "in png_do_pack"); + + if (row_info->bit_depth == 8 && +#ifdef PNG_USELESS_TESTS_SUPPORTED + row != NULL && row_info != NULL && +#endif + row_info->channels == 1) + { + switch ((int)bit_depth) + { + case 1: + { + png_bytep sp, dp; + int mask, v; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + sp = row; + dp = row; + mask = 0x80; + v = 0; + + for (i = 0; i < row_width; i++) + { + if (*sp != 0) + v |= mask; + sp++; + if (mask > 1) + mask >>= 1; + else + { + mask = 0x80; + *dp = (png_byte)v; + dp++; + v = 0; + } + } + if (mask != 0x80) + *dp = (png_byte)v; + break; + } + case 2: + { + png_bytep sp, dp; + int shift, v; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + sp = row; + dp = row; + shift = 6; + v = 0; + for (i = 0; i < row_width; i++) + { + png_byte value; + + value = (png_byte)(*sp & 0x03); + v |= (value << shift); + if (shift == 0) + { + shift = 6; + *dp = (png_byte)v; + dp++; + v = 0; + } + else + shift -= 2; + sp++; + } + if (shift != 6) + *dp = (png_byte)v; + break; + } + case 4: + { + png_bytep sp, dp; + int shift, v; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + sp = row; + dp = row; + shift = 4; + v = 0; + for (i = 0; i < row_width; i++) + { + png_byte value; + + value = (png_byte)(*sp & 0x0f); + v |= (value << shift); + + if (shift == 0) + { + shift = 4; + *dp = (png_byte)v; + dp++; + v = 0; + } + else + shift -= 4; + + sp++; + } + if (shift != 4) + *dp = (png_byte)v; + break; + } + } + row_info->bit_depth = (png_byte)bit_depth; + row_info->pixel_depth = (png_byte)(bit_depth * row_info->channels); + row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, + row_info->width); + } +} +#endif + +#ifdef PNG_WRITE_SHIFT_SUPPORTED +/* Shift pixel values to take advantage of whole range. Pass the + * true number of bits in bit_depth. The row should be packed + * according to row_info->bit_depth. Thus, if you had a row of + * bit depth 4, but the pixels only had values from 0 to 7, you + * would pass 3 as bit_depth, and this routine would translate the + * data to 0 to 15. + */ +void /* PRIVATE */ +png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth) +{ + png_debug(1, "in png_do_shift"); + +#ifdef PNG_USELESS_TESTS_SUPPORTED + if (row != NULL && row_info != NULL && +#else + if ( +#endif + row_info->color_type != PNG_COLOR_TYPE_PALETTE) + { + int shift_start[4], shift_dec[4]; + int channels = 0; + + if (row_info->color_type & PNG_COLOR_MASK_COLOR) + { + shift_start[channels] = row_info->bit_depth - bit_depth->red; + shift_dec[channels] = bit_depth->red; + channels++; + shift_start[channels] = row_info->bit_depth - bit_depth->green; + shift_dec[channels] = bit_depth->green; + channels++; + shift_start[channels] = row_info->bit_depth - bit_depth->blue; + shift_dec[channels] = bit_depth->blue; + channels++; + } + else + { + shift_start[channels] = row_info->bit_depth - bit_depth->gray; + shift_dec[channels] = bit_depth->gray; + channels++; + } + if (row_info->color_type & PNG_COLOR_MASK_ALPHA) + { + shift_start[channels] = row_info->bit_depth - bit_depth->alpha; + shift_dec[channels] = bit_depth->alpha; + channels++; + } + + /* With low row depths, could only be grayscale, so one channel */ + if (row_info->bit_depth < 8) + { + png_bytep bp = row; + png_uint_32 i; + png_byte mask; + png_uint_32 row_bytes = row_info->rowbytes; + + if (bit_depth->gray == 1 && row_info->bit_depth == 2) + mask = 0x55; + else if (row_info->bit_depth == 4 && bit_depth->gray == 3) + mask = 0x11; + else + mask = 0xff; + + for (i = 0; i < row_bytes; i++, bp++) + { + png_uint_16 v; + int j; + + v = *bp; + *bp = 0; + for (j = shift_start[0]; j > -shift_dec[0]; j -= shift_dec[0]) + { + if (j > 0) + *bp |= (png_byte)((v << j) & 0xff); + else + *bp |= (png_byte)((v >> (-j)) & mask); + } + } + } + else if (row_info->bit_depth == 8) + { + png_bytep bp = row; + png_uint_32 i; + png_uint_32 istop = channels * row_info->width; + + for (i = 0; i < istop; i++, bp++) + { + + png_uint_16 v; + int j; + int c = (int)(i%channels); + + v = *bp; + *bp = 0; + for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c]) + { + if (j > 0) + *bp |= (png_byte)((v << j) & 0xff); + else + *bp |= (png_byte)((v >> (-j)) & 0xff); + } + } + } + else + { + png_bytep bp; + png_uint_32 i; + png_uint_32 istop = channels * row_info->width; + + for (bp = row, i = 0; i < istop; i++) + { + int c = (int)(i%channels); + png_uint_16 value, v; + int j; + + v = (png_uint_16)(((png_uint_16)(*bp) << 8) + *(bp + 1)); + value = 0; + for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c]) + { + if (j > 0) + value |= (png_uint_16)((v << j) & (png_uint_16)0xffff); + else + value |= (png_uint_16)((v >> (-j)) & (png_uint_16)0xffff); + } + *bp++ = (png_byte)(value >> 8); + *bp++ = (png_byte)(value & 0xff); + } + } + } +} +#endif + +#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED +void /* PRIVATE */ +png_do_write_swap_alpha(png_row_infop row_info, png_bytep row) +{ + png_debug(1, "in png_do_write_swap_alpha"); + +#ifdef PNG_USELESS_TESTS_SUPPORTED + if (row != NULL && row_info != NULL) +#endif + { + if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + { + /* This converts from ARGB to RGBA */ + if (row_info->bit_depth == 8) + { + png_bytep sp, dp; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + for (i = 0, sp = dp = row; i < row_width; i++) + { + png_byte save = *(sp++); + *(dp++) = *(sp++); + *(dp++) = *(sp++); + *(dp++) = *(sp++); + *(dp++) = save; + } + } + /* This converts from AARRGGBB to RRGGBBAA */ + else + { + png_bytep sp, dp; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + for (i = 0, sp = dp = row; i < row_width; i++) + { + png_byte save[2]; + save[0] = *(sp++); + save[1] = *(sp++); + *(dp++) = *(sp++); + *(dp++) = *(sp++); + *(dp++) = *(sp++); + *(dp++) = *(sp++); + *(dp++) = *(sp++); + *(dp++) = *(sp++); + *(dp++) = save[0]; + *(dp++) = save[1]; + } + } + } + else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) + { + /* This converts from AG to GA */ + if (row_info->bit_depth == 8) + { + png_bytep sp, dp; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + for (i = 0, sp = dp = row; i < row_width; i++) + { + png_byte save = *(sp++); + *(dp++) = *(sp++); + *(dp++) = save; + } + } + /* This converts from AAGG to GGAA */ + else + { + png_bytep sp, dp; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + for (i = 0, sp = dp = row; i < row_width; i++) + { + png_byte save[2]; + save[0] = *(sp++); + save[1] = *(sp++); + *(dp++) = *(sp++); + *(dp++) = *(sp++); + *(dp++) = save[0]; + *(dp++) = save[1]; + } + } + } + } +} +#endif + +#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED +void /* PRIVATE */ +png_do_write_invert_alpha(png_row_infop row_info, png_bytep row) +{ + png_debug(1, "in png_do_write_invert_alpha"); + +#ifdef PNG_USELESS_TESTS_SUPPORTED + if (row != NULL && row_info != NULL) +#endif + { + if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + { + /* This inverts the alpha channel in RGBA */ + if (row_info->bit_depth == 8) + { + png_bytep sp, dp; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + for (i = 0, sp = dp = row; i < row_width; i++) + { + /* Does nothing + *(dp++) = *(sp++); + *(dp++) = *(sp++); + *(dp++) = *(sp++); + */ + sp+=3; dp = sp; + *(dp++) = (png_byte)(255 - *(sp++)); + } + } + /* This inverts the alpha channel in RRGGBBAA */ + else + { + png_bytep sp, dp; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + for (i = 0, sp = dp = row; i < row_width; i++) + { + /* Does nothing + *(dp++) = *(sp++); + *(dp++) = *(sp++); + *(dp++) = *(sp++); + *(dp++) = *(sp++); + *(dp++) = *(sp++); + *(dp++) = *(sp++); + */ + sp+=6; dp = sp; + *(dp++) = (png_byte)(255 - *(sp++)); + *(dp++) = (png_byte)(255 - *(sp++)); + } + } + } + else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) + { + /* This inverts the alpha channel in GA */ + if (row_info->bit_depth == 8) + { + png_bytep sp, dp; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + for (i = 0, sp = dp = row; i < row_width; i++) + { + *(dp++) = *(sp++); + *(dp++) = (png_byte)(255 - *(sp++)); + } + } + /* This inverts the alpha channel in GGAA */ + else + { + png_bytep sp, dp; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + for (i = 0, sp = dp = row; i < row_width; i++) + { + /* Does nothing + *(dp++) = *(sp++); + *(dp++) = *(sp++); + */ + sp+=2; dp = sp; + *(dp++) = (png_byte)(255 - *(sp++)); + *(dp++) = (png_byte)(255 - *(sp++)); + } + } + } + } +} +#endif + +#ifdef PNG_MNG_FEATURES_SUPPORTED +/* Undoes intrapixel differencing */ +void /* PRIVATE */ +png_do_write_intrapixel(png_row_infop row_info, png_bytep row) +{ + png_debug(1, "in png_do_write_intrapixel"); + + if ( +#ifdef PNG_USELESS_TESTS_SUPPORTED + row != NULL && row_info != NULL && +#endif + (row_info->color_type & PNG_COLOR_MASK_COLOR)) + { + int bytes_per_pixel; + png_uint_32 row_width = row_info->width; + if (row_info->bit_depth == 8) + { + png_bytep rp; + png_uint_32 i; + + if (row_info->color_type == PNG_COLOR_TYPE_RGB) + bytes_per_pixel = 3; + else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + bytes_per_pixel = 4; + else + return; + + for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel) + { + *(rp) = (png_byte)((*rp - *(rp+1))&0xff); + *(rp+2) = (png_byte)((*(rp+2) - *(rp+1))&0xff); + } + } + else if (row_info->bit_depth == 16) + { + png_bytep rp; + png_uint_32 i; + + if (row_info->color_type == PNG_COLOR_TYPE_RGB) + bytes_per_pixel = 6; + else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + bytes_per_pixel = 8; + else + return; + + for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel) + { + png_uint_32 s0 = (*(rp ) << 8) | *(rp+1); + png_uint_32 s1 = (*(rp+2) << 8) | *(rp+3); + png_uint_32 s2 = (*(rp+4) << 8) | *(rp+5); + png_uint_32 red = (png_uint_32)((s0 - s1) & 0xffffL); + png_uint_32 blue = (png_uint_32)((s2 - s1) & 0xffffL); + *(rp ) = (png_byte)((red >> 8) & 0xff); + *(rp+1) = (png_byte)(red & 0xff); + *(rp+4) = (png_byte)((blue >> 8) & 0xff); + *(rp+5) = (png_byte)(blue & 0xff); + } + } + } +} +#endif /* PNG_MNG_FEATURES_SUPPORTED */ +#endif /* PNG_WRITE_SUPPORTED */ diff --git a/libs/libpng-src/pngwutil.c b/libs/libpng-src/pngwutil.c new file mode 100644 index 000000000..386cb4a49 --- /dev/null +++ b/libs/libpng-src/pngwutil.c @@ -0,0 +1,2960 @@ + +/* pngwutil.c - utilities to write a PNG file + * + * Last changed in libpng 1.2.43 [February 25, 2010] + * Copyright (c) 1998-2010 Glenn Randers-Pehrson + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + */ + +#define PNG_INTERNAL +#define PNG_NO_PEDANTIC_WARNINGS +#include "png.h" +#ifdef PNG_WRITE_SUPPORTED + +/* Place a 32-bit number into a buffer in PNG byte order. We work + * with unsigned numbers for convenience, although one supported + * ancillary chunk uses signed (two's complement) numbers. + */ +void PNGAPI +png_save_uint_32(png_bytep buf, png_uint_32 i) +{ + buf[0] = (png_byte)((i >> 24) & 0xff); + buf[1] = (png_byte)((i >> 16) & 0xff); + buf[2] = (png_byte)((i >> 8) & 0xff); + buf[3] = (png_byte)(i & 0xff); +} + +/* The png_save_int_32 function assumes integers are stored in two's + * complement format. If this isn't the case, then this routine needs to + * be modified to write data in two's complement format. + */ +void PNGAPI +png_save_int_32(png_bytep buf, png_int_32 i) +{ + buf[0] = (png_byte)((i >> 24) & 0xff); + buf[1] = (png_byte)((i >> 16) & 0xff); + buf[2] = (png_byte)((i >> 8) & 0xff); + buf[3] = (png_byte)(i & 0xff); +} + +/* Place a 16-bit number into a buffer in PNG byte order. + * The parameter is declared unsigned int, not png_uint_16, + * just to avoid potential problems on pre-ANSI C compilers. + */ +void PNGAPI +png_save_uint_16(png_bytep buf, unsigned int i) +{ + buf[0] = (png_byte)((i >> 8) & 0xff); + buf[1] = (png_byte)(i & 0xff); +} + +/* Simple function to write the signature. If we have already written + * the magic bytes of the signature, or more likely, the PNG stream is + * being embedded into another stream and doesn't need its own signature, + * we should call png_set_sig_bytes() to tell libpng how many of the + * bytes have already been written. + */ +void /* PRIVATE */ +png_write_sig(png_structp png_ptr) +{ + png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10}; + + /* Write the rest of the 8 byte signature */ + png_write_data(png_ptr, &png_signature[png_ptr->sig_bytes], + (png_size_t)(8 - png_ptr->sig_bytes)); + if (png_ptr->sig_bytes < 3) + png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE; +} + +/* Write a PNG chunk all at once. The type is an array of ASCII characters + * representing the chunk name. The array must be at least 4 bytes in + * length, and does not need to be null terminated. To be safe, pass the + * pre-defined chunk names here, and if you need a new one, define it + * where the others are defined. The length is the length of the data. + * All the data must be present. If that is not possible, use the + * png_write_chunk_start(), png_write_chunk_data(), and png_write_chunk_end() + * functions instead. + */ +void PNGAPI +png_write_chunk(png_structp png_ptr, png_bytep chunk_name, + png_bytep data, png_size_t length) +{ + if (png_ptr == NULL) + return; + png_write_chunk_start(png_ptr, chunk_name, (png_uint_32)length); + png_write_chunk_data(png_ptr, data, (png_size_t)length); + png_write_chunk_end(png_ptr); +} + +/* Write the start of a PNG chunk. The type is the chunk type. + * The total_length is the sum of the lengths of all the data you will be + * passing in png_write_chunk_data(). + */ +void PNGAPI +png_write_chunk_start(png_structp png_ptr, png_bytep chunk_name, + png_uint_32 length) +{ + png_byte buf[8]; + + png_debug2(0, "Writing %s chunk, length = %lu", chunk_name, + (unsigned long)length); + + if (png_ptr == NULL) + return; + + + /* Write the length and the chunk name */ + png_save_uint_32(buf, length); + png_memcpy(buf + 4, chunk_name, 4); + png_write_data(png_ptr, buf, (png_size_t)8); + /* Put the chunk name into png_ptr->chunk_name */ + png_memcpy(png_ptr->chunk_name, chunk_name, 4); + /* Reset the crc and run it over the chunk name */ + png_reset_crc(png_ptr); + png_calculate_crc(png_ptr, chunk_name, (png_size_t)4); +} + +/* Write the data of a PNG chunk started with png_write_chunk_start(). + * Note that multiple calls to this function are allowed, and that the + * sum of the lengths from these calls *must* add up to the total_length + * given to png_write_chunk_start(). + */ +void PNGAPI +png_write_chunk_data(png_structp png_ptr, png_bytep data, png_size_t length) +{ + /* Write the data, and run the CRC over it */ + if (png_ptr == NULL) + return; + if (data != NULL && length > 0) + { + png_write_data(png_ptr, data, length); + /* Update the CRC after writing the data, + * in case that the user I/O routine alters it. + */ + png_calculate_crc(png_ptr, data, length); + } +} + +/* Finish a chunk started with png_write_chunk_start(). */ +void PNGAPI +png_write_chunk_end(png_structp png_ptr) +{ + png_byte buf[4]; + + if (png_ptr == NULL) return; + + /* Write the crc in a single operation */ + png_save_uint_32(buf, png_ptr->crc); + + png_write_data(png_ptr, buf, (png_size_t)4); +} + +#if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_iCCP_SUPPORTED) +/* This pair of functions encapsulates the operation of (a) compressing a + * text string, and (b) issuing it later as a series of chunk data writes. + * The compression_state structure is shared context for these functions + * set up by the caller in order to make the whole mess thread-safe. + */ + +typedef struct +{ + char *input; /* The uncompressed input data */ + int input_len; /* Its length */ + int num_output_ptr; /* Number of output pointers used */ + int max_output_ptr; /* Size of output_ptr */ + png_charpp output_ptr; /* Array of pointers to output */ +} compression_state; + +/* Compress given text into storage in the png_ptr structure */ +static int /* PRIVATE */ +png_text_compress(png_structp png_ptr, + png_charp text, png_size_t text_len, int compression, + compression_state *comp) +{ + int ret; + + comp->num_output_ptr = 0; + comp->max_output_ptr = 0; + comp->output_ptr = NULL; + comp->input = NULL; + comp->input_len = 0; + + /* We may just want to pass the text right through */ + if (compression == PNG_TEXT_COMPRESSION_NONE) + { + comp->input = text; + comp->input_len = text_len; + return((int)text_len); + } + + if (compression >= PNG_TEXT_COMPRESSION_LAST) + { +#if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE) + char msg[50]; + png_snprintf(msg, 50, "Unknown compression type %d", compression); + png_warning(png_ptr, msg); +#else + png_warning(png_ptr, "Unknown compression type"); +#endif + } + + /* We can't write the chunk until we find out how much data we have, + * which means we need to run the compressor first and save the + * output. This shouldn't be a problem, as the vast majority of + * comments should be reasonable, but we will set up an array of + * malloc'd pointers to be sure. + * + * If we knew the application was well behaved, we could simplify this + * greatly by assuming we can always malloc an output buffer large + * enough to hold the compressed text ((1001 * text_len / 1000) + 12) + * and malloc this directly. The only time this would be a bad idea is + * if we can't malloc more than 64K and we have 64K of random input + * data, or if the input string is incredibly large (although this + * wouldn't cause a failure, just a slowdown due to swapping). + */ + + /* Set up the compression buffers */ + png_ptr->zstream.avail_in = (uInt)text_len; + png_ptr->zstream.next_in = (Bytef *)text; + png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; + png_ptr->zstream.next_out = (Bytef *)png_ptr->zbuf; + + /* This is the same compression loop as in png_write_row() */ + do + { + /* Compress the data */ + ret = deflate(&png_ptr->zstream, Z_NO_FLUSH); + if (ret != Z_OK) + { + /* Error */ + if (png_ptr->zstream.msg != NULL) + png_error(png_ptr, png_ptr->zstream.msg); + else + png_error(png_ptr, "zlib error"); + } + /* Check to see if we need more room */ + if (!(png_ptr->zstream.avail_out)) + { + /* Make sure the output array has room */ + if (comp->num_output_ptr >= comp->max_output_ptr) + { + int old_max; + + old_max = comp->max_output_ptr; + comp->max_output_ptr = comp->num_output_ptr + 4; + if (comp->output_ptr != NULL) + { + png_charpp old_ptr; + + old_ptr = comp->output_ptr; + comp->output_ptr = (png_charpp)png_malloc(png_ptr, + (png_uint_32) + (comp->max_output_ptr * png_sizeof(png_charpp))); + png_memcpy(comp->output_ptr, old_ptr, old_max + * png_sizeof(png_charp)); + png_free(png_ptr, old_ptr); + } + else + comp->output_ptr = (png_charpp)png_malloc(png_ptr, + (png_uint_32) + (comp->max_output_ptr * png_sizeof(png_charp))); + } + + /* Save the data */ + comp->output_ptr[comp->num_output_ptr] = + (png_charp)png_malloc(png_ptr, + (png_uint_32)png_ptr->zbuf_size); + png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf, + png_ptr->zbuf_size); + comp->num_output_ptr++; + + /* and reset the buffer */ + png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; + png_ptr->zstream.next_out = png_ptr->zbuf; + } + /* Continue until we don't have any more to compress */ + } while (png_ptr->zstream.avail_in); + + /* Finish the compression */ + do + { + /* Tell zlib we are finished */ + ret = deflate(&png_ptr->zstream, Z_FINISH); + + if (ret == Z_OK) + { + /* Check to see if we need more room */ + if (!(png_ptr->zstream.avail_out)) + { + /* Check to make sure our output array has room */ + if (comp->num_output_ptr >= comp->max_output_ptr) + { + int old_max; + + old_max = comp->max_output_ptr; + comp->max_output_ptr = comp->num_output_ptr + 4; + if (comp->output_ptr != NULL) + { + png_charpp old_ptr; + + old_ptr = comp->output_ptr; + /* This could be optimized to realloc() */ + comp->output_ptr = (png_charpp)png_malloc(png_ptr, + (png_uint_32)(comp->max_output_ptr * + png_sizeof(png_charp))); + png_memcpy(comp->output_ptr, old_ptr, + old_max * png_sizeof(png_charp)); + png_free(png_ptr, old_ptr); + } + else + comp->output_ptr = (png_charpp)png_malloc(png_ptr, + (png_uint_32)(comp->max_output_ptr * + png_sizeof(png_charp))); + } + + /* Save the data */ + comp->output_ptr[comp->num_output_ptr] = + (png_charp)png_malloc(png_ptr, + (png_uint_32)png_ptr->zbuf_size); + png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf, + png_ptr->zbuf_size); + comp->num_output_ptr++; + + /* and reset the buffer pointers */ + png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; + png_ptr->zstream.next_out = png_ptr->zbuf; + } + } + else if (ret != Z_STREAM_END) + { + /* We got an error */ + if (png_ptr->zstream.msg != NULL) + png_error(png_ptr, png_ptr->zstream.msg); + else + png_error(png_ptr, "zlib error"); + } + } while (ret != Z_STREAM_END); + + /* Text length is number of buffers plus last buffer */ + text_len = png_ptr->zbuf_size * comp->num_output_ptr; + if (png_ptr->zstream.avail_out < png_ptr->zbuf_size) + text_len += png_ptr->zbuf_size - (png_size_t)png_ptr->zstream.avail_out; + + return((int)text_len); +} + +/* Ship the compressed text out via chunk writes */ +static void /* PRIVATE */ +png_write_compressed_data_out(png_structp png_ptr, compression_state *comp) +{ + int i; + + /* Handle the no-compression case */ + if (comp->input) + { + png_write_chunk_data(png_ptr, (png_bytep)comp->input, + (png_size_t)comp->input_len); + return; + } + + /* Write saved output buffers, if any */ + for (i = 0; i < comp->num_output_ptr; i++) + { + png_write_chunk_data(png_ptr, (png_bytep)comp->output_ptr[i], + (png_size_t)png_ptr->zbuf_size); + png_free(png_ptr, comp->output_ptr[i]); + comp->output_ptr[i]=NULL; + } + if (comp->max_output_ptr != 0) + png_free(png_ptr, comp->output_ptr); + comp->output_ptr=NULL; + /* Write anything left in zbuf */ + if (png_ptr->zstream.avail_out < (png_uint_32)png_ptr->zbuf_size) + png_write_chunk_data(png_ptr, png_ptr->zbuf, + (png_size_t)(png_ptr->zbuf_size - png_ptr->zstream.avail_out)); + + /* Reset zlib for another zTXt/iTXt or image data */ + deflateReset(&png_ptr->zstream); + png_ptr->zstream.data_type = Z_BINARY; +} +#endif + +/* Write the IHDR chunk, and update the png_struct with the necessary + * information. Note that the rest of this code depends upon this + * information being correct. + */ +void /* PRIVATE */ +png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height, + int bit_depth, int color_type, int compression_type, int filter_type, + int interlace_type) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_IHDR; +#endif + int ret; + + png_byte buf[13]; /* Buffer to store the IHDR info */ + + png_debug(1, "in png_write_IHDR"); + + /* Check that we have valid input data from the application info */ + switch (color_type) + { + case PNG_COLOR_TYPE_GRAY: + switch (bit_depth) + { + case 1: + case 2: + case 4: + case 8: + case 16: png_ptr->channels = 1; break; + default: png_error(png_ptr, + "Invalid bit depth for grayscale image"); + } + break; + case PNG_COLOR_TYPE_RGB: + if (bit_depth != 8 && bit_depth != 16) + png_error(png_ptr, "Invalid bit depth for RGB image"); + png_ptr->channels = 3; + break; + case PNG_COLOR_TYPE_PALETTE: + switch (bit_depth) + { + case 1: + case 2: + case 4: + case 8: png_ptr->channels = 1; break; + default: png_error(png_ptr, "Invalid bit depth for paletted image"); + } + break; + case PNG_COLOR_TYPE_GRAY_ALPHA: + if (bit_depth != 8 && bit_depth != 16) + png_error(png_ptr, "Invalid bit depth for grayscale+alpha image"); + png_ptr->channels = 2; + break; + case PNG_COLOR_TYPE_RGB_ALPHA: + if (bit_depth != 8 && bit_depth != 16) + png_error(png_ptr, "Invalid bit depth for RGBA image"); + png_ptr->channels = 4; + break; + default: + png_error(png_ptr, "Invalid image color type specified"); + } + + if (compression_type != PNG_COMPRESSION_TYPE_BASE) + { + png_warning(png_ptr, "Invalid compression type specified"); + compression_type = PNG_COMPRESSION_TYPE_BASE; + } + + /* Write filter_method 64 (intrapixel differencing) only if + * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and + * 2. Libpng did not write a PNG signature (this filter_method is only + * used in PNG datastreams that are embedded in MNG datastreams) and + * 3. The application called png_permit_mng_features with a mask that + * included PNG_FLAG_MNG_FILTER_64 and + * 4. The filter_method is 64 and + * 5. The color_type is RGB or RGBA + */ + if ( +#ifdef PNG_MNG_FEATURES_SUPPORTED + !((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && + ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) && + (color_type == PNG_COLOR_TYPE_RGB || + color_type == PNG_COLOR_TYPE_RGB_ALPHA) && + (filter_type == PNG_INTRAPIXEL_DIFFERENCING)) && +#endif + filter_type != PNG_FILTER_TYPE_BASE) + { + png_warning(png_ptr, "Invalid filter type specified"); + filter_type = PNG_FILTER_TYPE_BASE; + } + +#ifdef PNG_WRITE_INTERLACING_SUPPORTED + if (interlace_type != PNG_INTERLACE_NONE && + interlace_type != PNG_INTERLACE_ADAM7) + { + png_warning(png_ptr, "Invalid interlace type specified"); + interlace_type = PNG_INTERLACE_ADAM7; + } +#else + interlace_type=PNG_INTERLACE_NONE; +#endif + + /* Save the relevent information */ + png_ptr->bit_depth = (png_byte)bit_depth; + png_ptr->color_type = (png_byte)color_type; + png_ptr->interlaced = (png_byte)interlace_type; +#ifdef PNG_MNG_FEATURES_SUPPORTED + png_ptr->filter_type = (png_byte)filter_type; +#endif + png_ptr->compression_type = (png_byte)compression_type; + png_ptr->width = width; + png_ptr->height = height; + + png_ptr->pixel_depth = (png_byte)(bit_depth * png_ptr->channels); + png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, width); + /* Set the usr info, so any transformations can modify it */ + png_ptr->usr_width = png_ptr->width; + png_ptr->usr_bit_depth = png_ptr->bit_depth; + png_ptr->usr_channels = png_ptr->channels; + + /* Pack the header information into the buffer */ + png_save_uint_32(buf, width); + png_save_uint_32(buf + 4, height); + buf[8] = (png_byte)bit_depth; + buf[9] = (png_byte)color_type; + buf[10] = (png_byte)compression_type; + buf[11] = (png_byte)filter_type; + buf[12] = (png_byte)interlace_type; + + /* Write the chunk */ + png_write_chunk(png_ptr, (png_bytep)png_IHDR, buf, (png_size_t)13); + +#if defined(PNG_WRITE_APNG_SUPPORTED) + png_ptr->first_frame_width = width; + png_ptr->first_frame_height = height; +#endif + + /* Initialize zlib with PNG info */ + png_ptr->zstream.zalloc = png_zalloc; + png_ptr->zstream.zfree = png_zfree; + png_ptr->zstream.opaque = (voidpf)png_ptr; + if (!(png_ptr->do_filter)) + { + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE || + png_ptr->bit_depth < 8) + png_ptr->do_filter = PNG_FILTER_NONE; + else + png_ptr->do_filter = PNG_ALL_FILTERS; + } + if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_STRATEGY)) + { + if (png_ptr->do_filter != PNG_FILTER_NONE) + png_ptr->zlib_strategy = Z_FILTERED; + else + png_ptr->zlib_strategy = Z_DEFAULT_STRATEGY; + } + if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_LEVEL)) + png_ptr->zlib_level = Z_DEFAULT_COMPRESSION; + if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL)) + png_ptr->zlib_mem_level = 8; + if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS)) + png_ptr->zlib_window_bits = 15; + if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_METHOD)) + png_ptr->zlib_method = 8; + ret = deflateInit2(&png_ptr->zstream, png_ptr->zlib_level, + png_ptr->zlib_method, png_ptr->zlib_window_bits, + png_ptr->zlib_mem_level, png_ptr->zlib_strategy); + if (ret != Z_OK) + { + if (ret == Z_VERSION_ERROR) png_error(png_ptr, + "zlib failed to initialize compressor -- version error"); + if (ret == Z_STREAM_ERROR) png_error(png_ptr, + "zlib failed to initialize compressor -- stream error"); + if (ret == Z_MEM_ERROR) png_error(png_ptr, + "zlib failed to initialize compressor -- mem error"); + png_error(png_ptr, "zlib failed to initialize compressor"); + } + png_ptr->zstream.next_out = png_ptr->zbuf; + png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; + /* libpng is not interested in zstream.data_type */ + /* Set it to a predefined value, to avoid its evaluation inside zlib */ + png_ptr->zstream.data_type = Z_BINARY; + + png_ptr->mode = PNG_HAVE_IHDR; +} + +/* Write the palette. We are careful not to trust png_color to be in the + * correct order for PNG, so people can redefine it to any convenient + * structure. + */ +void /* PRIVATE */ +png_write_PLTE(png_structp png_ptr, png_colorp palette, png_uint_32 num_pal) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_PLTE; +#endif + png_uint_32 i; + png_colorp pal_ptr; + png_byte buf[3]; + + png_debug(1, "in png_write_PLTE"); + + if (( +#ifdef PNG_MNG_FEATURES_SUPPORTED + !(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) && +#endif + num_pal == 0) || num_pal > 256) + { + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + { + png_error(png_ptr, "Invalid number of colors in palette"); + } + else + { + png_warning(png_ptr, "Invalid number of colors in palette"); + return; + } + } + + if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR)) + { + png_warning(png_ptr, + "Ignoring request to write a PLTE chunk in grayscale PNG"); + return; + } + + png_ptr->num_palette = (png_uint_16)num_pal; + png_debug1(3, "num_palette = %d", png_ptr->num_palette); + + png_write_chunk_start(png_ptr, (png_bytep)png_PLTE, + (png_uint_32)(num_pal * 3)); +#ifdef PNG_POINTER_INDEXING_SUPPORTED + for (i = 0, pal_ptr = palette; i < num_pal; i++, pal_ptr++) + { + buf[0] = pal_ptr->red; + buf[1] = pal_ptr->green; + buf[2] = pal_ptr->blue; + png_write_chunk_data(png_ptr, buf, (png_size_t)3); + } +#else + /* This is a little slower but some buggy compilers need to do this + * instead + */ + pal_ptr=palette; + for (i = 0; i < num_pal; i++) + { + buf[0] = pal_ptr[i].red; + buf[1] = pal_ptr[i].green; + buf[2] = pal_ptr[i].blue; + png_write_chunk_data(png_ptr, buf, (png_size_t)3); + } +#endif + png_write_chunk_end(png_ptr); + png_ptr->mode |= PNG_HAVE_PLTE; +} + +/* Write an IDAT chunk */ +void /* PRIVATE */ +png_write_IDAT(png_structp png_ptr, png_bytep data, png_size_t length) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_IDAT; +#if defined(PNG_WRITE_APNG_SUPPORTED) + PNG_fdAT; +#endif +#endif + + png_debug(1, "in png_write_IDAT"); + + /* Optimize the CMF field in the zlib stream. */ + /* This hack of the zlib stream is compliant to the stream specification. */ + if (!(png_ptr->mode & PNG_HAVE_IDAT) && + png_ptr->compression_type == PNG_COMPRESSION_TYPE_BASE) + { + unsigned int z_cmf = data[0]; /* zlib compression method and flags */ + if ((z_cmf & 0x0f) == 8 && (z_cmf & 0xf0) <= 0x70) + { + /* Avoid memory underflows and multiplication overflows. + * + * The conditions below are practically always satisfied; + * however, they still must be checked. + */ + if (length >= 2 && + png_ptr->height < 16384 && png_ptr->width < 16384) + { + png_uint_32 uncompressed_idat_size = png_ptr->height * + ((png_ptr->width * + png_ptr->channels * png_ptr->bit_depth + 15) >> 3); + unsigned int z_cinfo = z_cmf >> 4; + unsigned int half_z_window_size = 1 << (z_cinfo + 7); + while (uncompressed_idat_size <= half_z_window_size && + half_z_window_size >= 256) + { + z_cinfo--; + half_z_window_size >>= 1; + } + z_cmf = (z_cmf & 0x0f) | (z_cinfo << 4); + if (data[0] != (png_byte)z_cmf) + { + data[0] = (png_byte)z_cmf; + data[1] &= 0xe0; + data[1] += (png_byte)(0x1f - ((z_cmf << 8) + data[1]) % 0x1f); + } + } + } + else + png_error(png_ptr, + "Invalid zlib compression method or flags in IDAT"); + } + +#if defined(PNG_WRITE_APNG_SUPPORTED) + if(png_ptr->num_frames_written == 0) +#endif + png_write_chunk(png_ptr, (png_bytep)png_IDAT, data, length); +#if defined(PNG_WRITE_APNG_SUPPORTED) + else + { + png_byte buf[4]; + + png_write_chunk_start(png_ptr, (png_bytep)png_fdAT, 4 + length); + + png_save_uint_32(buf, png_ptr->next_seq_num); + png_write_chunk_data(png_ptr, buf, 4); + + png_write_chunk_data(png_ptr, data, length); + + png_write_chunk_end(png_ptr); + + png_ptr->next_seq_num++; + } +#endif + + png_ptr->mode |= PNG_HAVE_IDAT; +} + +/* Write an IEND chunk */ +void /* PRIVATE */ +png_write_IEND(png_structp png_ptr) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_IEND; +#endif + + png_debug(1, "in png_write_IEND"); + + png_write_chunk(png_ptr, (png_bytep)png_IEND, png_bytep_NULL, + (png_size_t)0); + png_ptr->mode |= PNG_HAVE_IEND; +} + +#ifdef PNG_WRITE_gAMA_SUPPORTED +/* Write a gAMA chunk */ +#ifdef PNG_FLOATING_POINT_SUPPORTED +void /* PRIVATE */ +png_write_gAMA(png_structp png_ptr, double file_gamma) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_gAMA; +#endif + png_uint_32 igamma; + png_byte buf[4]; + + png_debug(1, "in png_write_gAMA"); + + /* file_gamma is saved in 1/100,000ths */ + igamma = (png_uint_32)(file_gamma * 100000.0 + 0.5); + png_save_uint_32(buf, igamma); + png_write_chunk(png_ptr, (png_bytep)png_gAMA, buf, (png_size_t)4); +} +#endif +#ifdef PNG_FIXED_POINT_SUPPORTED +void /* PRIVATE */ +png_write_gAMA_fixed(png_structp png_ptr, png_fixed_point file_gamma) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_gAMA; +#endif + png_byte buf[4]; + + png_debug(1, "in png_write_gAMA"); + + /* file_gamma is saved in 1/100,000ths */ + png_save_uint_32(buf, (png_uint_32)file_gamma); + png_write_chunk(png_ptr, (png_bytep)png_gAMA, buf, (png_size_t)4); +} +#endif +#endif + +#ifdef PNG_WRITE_sRGB_SUPPORTED +/* Write a sRGB chunk */ +void /* PRIVATE */ +png_write_sRGB(png_structp png_ptr, int srgb_intent) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_sRGB; +#endif + png_byte buf[1]; + + png_debug(1, "in png_write_sRGB"); + + if (srgb_intent >= PNG_sRGB_INTENT_LAST) + png_warning(png_ptr, + "Invalid sRGB rendering intent specified"); + buf[0]=(png_byte)srgb_intent; + png_write_chunk(png_ptr, (png_bytep)png_sRGB, buf, (png_size_t)1); +} +#endif + +#ifdef PNG_WRITE_iCCP_SUPPORTED +/* Write an iCCP chunk */ +void /* PRIVATE */ +png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type, + png_charp profile, int profile_len) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_iCCP; +#endif + png_size_t name_len; + png_charp new_name; + compression_state comp; + int embedded_profile_len = 0; + + png_debug(1, "in png_write_iCCP"); + + comp.num_output_ptr = 0; + comp.max_output_ptr = 0; + comp.output_ptr = NULL; + comp.input = NULL; + comp.input_len = 0; + + if ((name_len = png_check_keyword(png_ptr, name, + &new_name)) == 0) + return; + + if (compression_type != PNG_COMPRESSION_TYPE_BASE) + png_warning(png_ptr, "Unknown compression type in iCCP chunk"); + + if (profile == NULL) + profile_len = 0; + + if (profile_len > 3) + embedded_profile_len = + ((*( (png_bytep)profile ))<<24) | + ((*( (png_bytep)profile + 1))<<16) | + ((*( (png_bytep)profile + 2))<< 8) | + ((*( (png_bytep)profile + 3)) ); + + if (embedded_profile_len < 0) + { + png_warning(png_ptr, + "Embedded profile length in iCCP chunk is negative"); + png_free(png_ptr, new_name); + return; + } + + if (profile_len < embedded_profile_len) + { + png_warning(png_ptr, + "Embedded profile length too large in iCCP chunk"); + png_free(png_ptr, new_name); + return; + } + + if (profile_len > embedded_profile_len) + { + png_warning(png_ptr, + "Truncating profile to actual length in iCCP chunk"); + profile_len = embedded_profile_len; + } + + if (profile_len) + profile_len = png_text_compress(png_ptr, profile, + (png_size_t)profile_len, PNG_COMPRESSION_TYPE_BASE, &comp); + + /* Make sure we include the NULL after the name and the compression type */ + png_write_chunk_start(png_ptr, (png_bytep)png_iCCP, + (png_uint_32)(name_len + profile_len + 2)); + new_name[name_len + 1] = 0x00; + png_write_chunk_data(png_ptr, (png_bytep)new_name, + (png_size_t)(name_len + 2)); + + if (profile_len) + png_write_compressed_data_out(png_ptr, &comp); + + png_write_chunk_end(png_ptr); + png_free(png_ptr, new_name); +} +#endif + +#ifdef PNG_WRITE_sPLT_SUPPORTED +/* Write a sPLT chunk */ +void /* PRIVATE */ +png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_sPLT; +#endif + png_size_t name_len; + png_charp new_name; + png_byte entrybuf[10]; + int entry_size = (spalette->depth == 8 ? 6 : 10); + int palette_size = entry_size * spalette->nentries; + png_sPLT_entryp ep; +#ifndef PNG_POINTER_INDEXING_SUPPORTED + int i; +#endif + + png_debug(1, "in png_write_sPLT"); + + if ((name_len = png_check_keyword(png_ptr,spalette->name, &new_name))==0) + return; + + /* Make sure we include the NULL after the name */ + png_write_chunk_start(png_ptr, (png_bytep)png_sPLT, + (png_uint_32)(name_len + 2 + palette_size)); + png_write_chunk_data(png_ptr, (png_bytep)new_name, + (png_size_t)(name_len + 1)); + png_write_chunk_data(png_ptr, (png_bytep)&spalette->depth, (png_size_t)1); + + /* Loop through each palette entry, writing appropriately */ +#ifdef PNG_POINTER_INDEXING_SUPPORTED + for (ep = spalette->entries; epentries + spalette->nentries; ep++) + { + if (spalette->depth == 8) + { + entrybuf[0] = (png_byte)ep->red; + entrybuf[1] = (png_byte)ep->green; + entrybuf[2] = (png_byte)ep->blue; + entrybuf[3] = (png_byte)ep->alpha; + png_save_uint_16(entrybuf + 4, ep->frequency); + } + else + { + png_save_uint_16(entrybuf + 0, ep->red); + png_save_uint_16(entrybuf + 2, ep->green); + png_save_uint_16(entrybuf + 4, ep->blue); + png_save_uint_16(entrybuf + 6, ep->alpha); + png_save_uint_16(entrybuf + 8, ep->frequency); + } + png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size); + } +#else + ep=spalette->entries; + for (i=0; i>spalette->nentries; i++) + { + if (spalette->depth == 8) + { + entrybuf[0] = (png_byte)ep[i].red; + entrybuf[1] = (png_byte)ep[i].green; + entrybuf[2] = (png_byte)ep[i].blue; + entrybuf[3] = (png_byte)ep[i].alpha; + png_save_uint_16(entrybuf + 4, ep[i].frequency); + } + else + { + png_save_uint_16(entrybuf + 0, ep[i].red); + png_save_uint_16(entrybuf + 2, ep[i].green); + png_save_uint_16(entrybuf + 4, ep[i].blue); + png_save_uint_16(entrybuf + 6, ep[i].alpha); + png_save_uint_16(entrybuf + 8, ep[i].frequency); + } + png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size); + } +#endif + + png_write_chunk_end(png_ptr); + png_free(png_ptr, new_name); +} +#endif + +#ifdef PNG_WRITE_sBIT_SUPPORTED +/* Write the sBIT chunk */ +void /* PRIVATE */ +png_write_sBIT(png_structp png_ptr, png_color_8p sbit, int color_type) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_sBIT; +#endif + png_byte buf[4]; + png_size_t size; + + png_debug(1, "in png_write_sBIT"); + + /* Make sure we don't depend upon the order of PNG_COLOR_8 */ + if (color_type & PNG_COLOR_MASK_COLOR) + { + png_byte maxbits; + + maxbits = (png_byte)(color_type==PNG_COLOR_TYPE_PALETTE ? 8 : + png_ptr->usr_bit_depth); + if (sbit->red == 0 || sbit->red > maxbits || + sbit->green == 0 || sbit->green > maxbits || + sbit->blue == 0 || sbit->blue > maxbits) + { + png_warning(png_ptr, "Invalid sBIT depth specified"); + return; + } + buf[0] = sbit->red; + buf[1] = sbit->green; + buf[2] = sbit->blue; + size = 3; + } + else + { + if (sbit->gray == 0 || sbit->gray > png_ptr->usr_bit_depth) + { + png_warning(png_ptr, "Invalid sBIT depth specified"); + return; + } + buf[0] = sbit->gray; + size = 1; + } + + if (color_type & PNG_COLOR_MASK_ALPHA) + { + if (sbit->alpha == 0 || sbit->alpha > png_ptr->usr_bit_depth) + { + png_warning(png_ptr, "Invalid sBIT depth specified"); + return; + } + buf[size++] = sbit->alpha; + } + + png_write_chunk(png_ptr, (png_bytep)png_sBIT, buf, size); +} +#endif + +#ifdef PNG_WRITE_cHRM_SUPPORTED +/* Write the cHRM chunk */ +#ifdef PNG_FLOATING_POINT_SUPPORTED +void /* PRIVATE */ +png_write_cHRM(png_structp png_ptr, double white_x, double white_y, + double red_x, double red_y, double green_x, double green_y, + double blue_x, double blue_y) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_cHRM; +#endif + png_byte buf[32]; + + png_fixed_point int_white_x, int_white_y, int_red_x, int_red_y, + int_green_x, int_green_y, int_blue_x, int_blue_y; + + png_debug(1, "in png_write_cHRM"); + + int_white_x = (png_uint_32)(white_x * 100000.0 + 0.5); + int_white_y = (png_uint_32)(white_y * 100000.0 + 0.5); + int_red_x = (png_uint_32)(red_x * 100000.0 + 0.5); + int_red_y = (png_uint_32)(red_y * 100000.0 + 0.5); + int_green_x = (png_uint_32)(green_x * 100000.0 + 0.5); + int_green_y = (png_uint_32)(green_y * 100000.0 + 0.5); + int_blue_x = (png_uint_32)(blue_x * 100000.0 + 0.5); + int_blue_y = (png_uint_32)(blue_y * 100000.0 + 0.5); + +#ifdef PNG_CHECK_cHRM_SUPPORTED + if (png_check_cHRM_fixed(png_ptr, int_white_x, int_white_y, + int_red_x, int_red_y, int_green_x, int_green_y, int_blue_x, int_blue_y)) +#endif + { + /* Each value is saved in 1/100,000ths */ + + png_save_uint_32(buf, int_white_x); + png_save_uint_32(buf + 4, int_white_y); + + png_save_uint_32(buf + 8, int_red_x); + png_save_uint_32(buf + 12, int_red_y); + + png_save_uint_32(buf + 16, int_green_x); + png_save_uint_32(buf + 20, int_green_y); + + png_save_uint_32(buf + 24, int_blue_x); + png_save_uint_32(buf + 28, int_blue_y); + + png_write_chunk(png_ptr, (png_bytep)png_cHRM, buf, (png_size_t)32); + } +} +#endif +#ifdef PNG_FIXED_POINT_SUPPORTED +void /* PRIVATE */ +png_write_cHRM_fixed(png_structp png_ptr, png_fixed_point white_x, + png_fixed_point white_y, png_fixed_point red_x, png_fixed_point red_y, + png_fixed_point green_x, png_fixed_point green_y, png_fixed_point blue_x, + png_fixed_point blue_y) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_cHRM; +#endif + png_byte buf[32]; + + png_debug(1, "in png_write_cHRM"); + + /* Each value is saved in 1/100,000ths */ +#ifdef PNG_CHECK_cHRM_SUPPORTED + if (png_check_cHRM_fixed(png_ptr, white_x, white_y, red_x, red_y, + green_x, green_y, blue_x, blue_y)) +#endif + { + png_save_uint_32(buf, (png_uint_32)white_x); + png_save_uint_32(buf + 4, (png_uint_32)white_y); + + png_save_uint_32(buf + 8, (png_uint_32)red_x); + png_save_uint_32(buf + 12, (png_uint_32)red_y); + + png_save_uint_32(buf + 16, (png_uint_32)green_x); + png_save_uint_32(buf + 20, (png_uint_32)green_y); + + png_save_uint_32(buf + 24, (png_uint_32)blue_x); + png_save_uint_32(buf + 28, (png_uint_32)blue_y); + + png_write_chunk(png_ptr, (png_bytep)png_cHRM, buf, (png_size_t)32); + } +} +#endif +#endif + +#ifdef PNG_WRITE_tRNS_SUPPORTED +/* Write the tRNS chunk */ +void /* PRIVATE */ +png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran, + int num_trans, int color_type) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_tRNS; +#endif + png_byte buf[6]; + + png_debug(1, "in png_write_tRNS"); + + if (color_type == PNG_COLOR_TYPE_PALETTE) + { + if (num_trans <= 0 || num_trans > (int)png_ptr->num_palette) + { + png_warning(png_ptr, "Invalid number of transparent colors specified"); + return; + } + /* Write the chunk out as it is */ + png_write_chunk(png_ptr, (png_bytep)png_tRNS, trans, + (png_size_t)num_trans); + } + else if (color_type == PNG_COLOR_TYPE_GRAY) + { + /* One 16 bit value */ + if (tran->gray >= (1 << png_ptr->bit_depth)) + { + png_warning(png_ptr, + "Ignoring attempt to write tRNS chunk out-of-range for bit_depth"); + return; + } + png_save_uint_16(buf, tran->gray); + png_write_chunk(png_ptr, (png_bytep)png_tRNS, buf, (png_size_t)2); + } + else if (color_type == PNG_COLOR_TYPE_RGB) + { + /* Three 16 bit values */ + png_save_uint_16(buf, tran->red); + png_save_uint_16(buf + 2, tran->green); + png_save_uint_16(buf + 4, tran->blue); + if (png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4])) + { + png_warning(png_ptr, + "Ignoring attempt to write 16-bit tRNS chunk when bit_depth is 8"); + return; + } + png_write_chunk(png_ptr, (png_bytep)png_tRNS, buf, (png_size_t)6); + } + else + { + png_warning(png_ptr, "Can't write tRNS with an alpha channel"); + } +} +#endif + +#ifdef PNG_WRITE_bKGD_SUPPORTED +/* Write the background chunk */ +void /* PRIVATE */ +png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_bKGD; +#endif + png_byte buf[6]; + + png_debug(1, "in png_write_bKGD"); + + if (color_type == PNG_COLOR_TYPE_PALETTE) + { + if ( +#ifdef PNG_MNG_FEATURES_SUPPORTED + (png_ptr->num_palette || + (!(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE))) && +#endif + back->index >= png_ptr->num_palette) + { + png_warning(png_ptr, "Invalid background palette index"); + return; + } + buf[0] = back->index; + png_write_chunk(png_ptr, (png_bytep)png_bKGD, buf, (png_size_t)1); + } + else if (color_type & PNG_COLOR_MASK_COLOR) + { + png_save_uint_16(buf, back->red); + png_save_uint_16(buf + 2, back->green); + png_save_uint_16(buf + 4, back->blue); + if (png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4])) + { + png_warning(png_ptr, + "Ignoring attempt to write 16-bit bKGD chunk when bit_depth is 8"); + return; + } + png_write_chunk(png_ptr, (png_bytep)png_bKGD, buf, (png_size_t)6); + } + else + { + if (back->gray >= (1 << png_ptr->bit_depth)) + { + png_warning(png_ptr, + "Ignoring attempt to write bKGD chunk out-of-range for bit_depth"); + return; + } + png_save_uint_16(buf, back->gray); + png_write_chunk(png_ptr, (png_bytep)png_bKGD, buf, (png_size_t)2); + } +} +#endif + +#ifdef PNG_WRITE_hIST_SUPPORTED +/* Write the histogram */ +void /* PRIVATE */ +png_write_hIST(png_structp png_ptr, png_uint_16p hist, int num_hist) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_hIST; +#endif + int i; + png_byte buf[3]; + + png_debug(1, "in png_write_hIST"); + + if (num_hist > (int)png_ptr->num_palette) + { + png_debug2(3, "num_hist = %d, num_palette = %d", num_hist, + png_ptr->num_palette); + png_warning(png_ptr, "Invalid number of histogram entries specified"); + return; + } + + png_write_chunk_start(png_ptr, (png_bytep)png_hIST, + (png_uint_32)(num_hist * 2)); + for (i = 0; i < num_hist; i++) + { + png_save_uint_16(buf, hist[i]); + png_write_chunk_data(png_ptr, buf, (png_size_t)2); + } + png_write_chunk_end(png_ptr); +} +#endif + +#if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \ + defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED) +/* Check that the tEXt or zTXt keyword is valid per PNG 1.0 specification, + * and if invalid, correct the keyword rather than discarding the entire + * chunk. The PNG 1.0 specification requires keywords 1-79 characters in + * length, forbids leading or trailing whitespace, multiple internal spaces, + * and the non-break space (0x80) from ISO 8859-1. Returns keyword length. + * + * The new_key is allocated to hold the corrected keyword and must be freed + * by the calling routine. This avoids problems with trying to write to + * static keywords without having to have duplicate copies of the strings. + */ +png_size_t /* PRIVATE */ +png_check_keyword(png_structp png_ptr, png_charp key, png_charpp new_key) +{ + png_size_t key_len; + png_charp kp, dp; + int kflag; + int kwarn=0; + + png_debug(1, "in png_check_keyword"); + + *new_key = NULL; + + if (key == NULL || (key_len = png_strlen(key)) == 0) + { + png_warning(png_ptr, "zero length keyword"); + return ((png_size_t)0); + } + + png_debug1(2, "Keyword to be checked is '%s'", key); + + *new_key = (png_charp)png_malloc_warn(png_ptr, (png_uint_32)(key_len + 2)); + if (*new_key == NULL) + { + png_warning(png_ptr, "Out of memory while procesing keyword"); + return ((png_size_t)0); + } + + /* Replace non-printing characters with a blank and print a warning */ + for (kp = key, dp = *new_key; *kp != '\0'; kp++, dp++) + { + if ((png_byte)*kp < 0x20 || + ((png_byte)*kp > 0x7E && (png_byte)*kp < 0xA1)) + { +#if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE) + char msg[40]; + + png_snprintf(msg, 40, + "invalid keyword character 0x%02X", (png_byte)*kp); + png_warning(png_ptr, msg); +#else + png_warning(png_ptr, "invalid character in keyword"); +#endif + *dp = ' '; + } + else + { + *dp = *kp; + } + } + *dp = '\0'; + + /* Remove any trailing white space. */ + kp = *new_key + key_len - 1; + if (*kp == ' ') + { + png_warning(png_ptr, "trailing spaces removed from keyword"); + + while (*kp == ' ') + { + *(kp--) = '\0'; + key_len--; + } + } + + /* Remove any leading white space. */ + kp = *new_key; + if (*kp == ' ') + { + png_warning(png_ptr, "leading spaces removed from keyword"); + + while (*kp == ' ') + { + kp++; + key_len--; + } + } + + png_debug1(2, "Checking for multiple internal spaces in '%s'", kp); + + /* Remove multiple internal spaces. */ + for (kflag = 0, dp = *new_key; *kp != '\0'; kp++) + { + if (*kp == ' ' && kflag == 0) + { + *(dp++) = *kp; + kflag = 1; + } + else if (*kp == ' ') + { + key_len--; + kwarn=1; + } + else + { + *(dp++) = *kp; + kflag = 0; + } + } + *dp = '\0'; + if (kwarn) + png_warning(png_ptr, "extra interior spaces removed from keyword"); + + if (key_len == 0) + { + png_free(png_ptr, *new_key); + *new_key=NULL; + png_warning(png_ptr, "Zero length keyword"); + } + + if (key_len > 79) + { + png_warning(png_ptr, "keyword length must be 1 - 79 characters"); + (*new_key)[79] = '\0'; + key_len = 79; + } + + return (key_len); +} +#endif + +#ifdef PNG_WRITE_tEXt_SUPPORTED +/* Write a tEXt chunk */ +void /* PRIVATE */ +png_write_tEXt(png_structp png_ptr, png_charp key, png_charp text, + png_size_t text_len) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_tEXt; +#endif + png_size_t key_len; + png_charp new_key; + + png_debug(1, "in png_write_tEXt"); + + if ((key_len = png_check_keyword(png_ptr, key, &new_key))==0) + return; + + if (text == NULL || *text == '\0') + text_len = 0; + else + text_len = png_strlen(text); + + /* Make sure we include the 0 after the key */ + png_write_chunk_start(png_ptr, (png_bytep)png_tEXt, + (png_uint_32)(key_len + text_len + 1)); + /* + * We leave it to the application to meet PNG-1.0 requirements on the + * contents of the text. PNG-1.0 through PNG-1.2 discourage the use of + * any non-Latin-1 characters except for NEWLINE. ISO PNG will forbid them. + * The NUL character is forbidden by PNG-1.0 through PNG-1.2 and ISO PNG. + */ + png_write_chunk_data(png_ptr, (png_bytep)new_key, + (png_size_t)(key_len + 1)); + if (text_len) + png_write_chunk_data(png_ptr, (png_bytep)text, (png_size_t)text_len); + + png_write_chunk_end(png_ptr); + png_free(png_ptr, new_key); +} +#endif + +#ifdef PNG_WRITE_zTXt_SUPPORTED +/* Write a compressed text chunk */ +void /* PRIVATE */ +png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text, + png_size_t text_len, int compression) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_zTXt; +#endif + png_size_t key_len; + char buf[1]; + png_charp new_key; + compression_state comp; + + png_debug(1, "in png_write_zTXt"); + + comp.num_output_ptr = 0; + comp.max_output_ptr = 0; + comp.output_ptr = NULL; + comp.input = NULL; + comp.input_len = 0; + + if ((key_len = png_check_keyword(png_ptr, key, &new_key))==0) + { + png_free(png_ptr, new_key); + return; + } + + if (text == NULL || *text == '\0' || compression==PNG_TEXT_COMPRESSION_NONE) + { + png_write_tEXt(png_ptr, new_key, text, (png_size_t)0); + png_free(png_ptr, new_key); + return; + } + + text_len = png_strlen(text); + + /* Compute the compressed data; do it now for the length */ + text_len = png_text_compress(png_ptr, text, text_len, compression, + &comp); + + /* Write start of chunk */ + png_write_chunk_start(png_ptr, (png_bytep)png_zTXt, + (png_uint_32)(key_len+text_len + 2)); + /* Write key */ + png_write_chunk_data(png_ptr, (png_bytep)new_key, + (png_size_t)(key_len + 1)); + png_free(png_ptr, new_key); + + buf[0] = (png_byte)compression; + /* Write compression */ + png_write_chunk_data(png_ptr, (png_bytep)buf, (png_size_t)1); + /* Write the compressed data */ + png_write_compressed_data_out(png_ptr, &comp); + + /* Close the chunk */ + png_write_chunk_end(png_ptr); +} +#endif + +#ifdef PNG_WRITE_iTXt_SUPPORTED +/* Write an iTXt chunk */ +void /* PRIVATE */ +png_write_iTXt(png_structp png_ptr, int compression, png_charp key, + png_charp lang, png_charp lang_key, png_charp text) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_iTXt; +#endif + png_size_t lang_len, key_len, lang_key_len, text_len; + png_charp new_lang; + png_charp new_key = NULL; + png_byte cbuf[2]; + compression_state comp; + + png_debug(1, "in png_write_iTXt"); + + comp.num_output_ptr = 0; + comp.max_output_ptr = 0; + comp.output_ptr = NULL; + comp.input = NULL; + + if ((key_len = png_check_keyword(png_ptr, key, &new_key))==0) + return; + + if ((lang_len = png_check_keyword(png_ptr, lang, &new_lang))==0) + { + png_warning(png_ptr, "Empty language field in iTXt chunk"); + new_lang = NULL; + lang_len = 0; + } + + if (lang_key == NULL) + lang_key_len = 0; + else + lang_key_len = png_strlen(lang_key); + + if (text == NULL) + text_len = 0; + else + text_len = png_strlen(text); + + /* Compute the compressed data; do it now for the length */ + text_len = png_text_compress(png_ptr, text, text_len, compression-2, + &comp); + + + /* Make sure we include the compression flag, the compression byte, + * and the NULs after the key, lang, and lang_key parts */ + + png_write_chunk_start(png_ptr, (png_bytep)png_iTXt, + (png_uint_32)( + 5 /* comp byte, comp flag, terminators for key, lang and lang_key */ + + key_len + + lang_len + + lang_key_len + + text_len)); + + /* We leave it to the application to meet PNG-1.0 requirements on the + * contents of the text. PNG-1.0 through PNG-1.2 discourage the use of + * any non-Latin-1 characters except for NEWLINE. ISO PNG will forbid them. + * The NUL character is forbidden by PNG-1.0 through PNG-1.2 and ISO PNG. + */ + png_write_chunk_data(png_ptr, (png_bytep)new_key, + (png_size_t)(key_len + 1)); + + /* Set the compression flag */ + if (compression == PNG_ITXT_COMPRESSION_NONE || \ + compression == PNG_TEXT_COMPRESSION_NONE) + cbuf[0] = 0; + else /* compression == PNG_ITXT_COMPRESSION_zTXt */ + cbuf[0] = 1; + /* Set the compression method */ + cbuf[1] = 0; + png_write_chunk_data(png_ptr, cbuf, (png_size_t)2); + + cbuf[0] = 0; + png_write_chunk_data(png_ptr, (new_lang ? (png_bytep)new_lang : cbuf), + (png_size_t)(lang_len + 1)); + png_write_chunk_data(png_ptr, (lang_key ? (png_bytep)lang_key : cbuf), + (png_size_t)(lang_key_len + 1)); + png_write_compressed_data_out(png_ptr, &comp); + + png_write_chunk_end(png_ptr); + png_free(png_ptr, new_key); + png_free(png_ptr, new_lang); +} +#endif + +#ifdef PNG_WRITE_oFFs_SUPPORTED +/* Write the oFFs chunk */ +void /* PRIVATE */ +png_write_oFFs(png_structp png_ptr, png_int_32 x_offset, png_int_32 y_offset, + int unit_type) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_oFFs; +#endif + png_byte buf[9]; + + png_debug(1, "in png_write_oFFs"); + + if (unit_type >= PNG_OFFSET_LAST) + png_warning(png_ptr, "Unrecognized unit type for oFFs chunk"); + + png_save_int_32(buf, x_offset); + png_save_int_32(buf + 4, y_offset); + buf[8] = (png_byte)unit_type; + + png_write_chunk(png_ptr, (png_bytep)png_oFFs, buf, (png_size_t)9); +} +#endif +#ifdef PNG_WRITE_pCAL_SUPPORTED +/* Write the pCAL chunk (described in the PNG extensions document) */ +void /* PRIVATE */ +png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0, + png_int_32 X1, int type, int nparams, png_charp units, png_charpp params) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_pCAL; +#endif + png_size_t purpose_len, units_len, total_len; + png_uint_32p params_len; + png_byte buf[10]; + png_charp new_purpose; + int i; + + png_debug1(1, "in png_write_pCAL (%d parameters)", nparams); + + if (type >= PNG_EQUATION_LAST) + png_warning(png_ptr, "Unrecognized equation type for pCAL chunk"); + + purpose_len = png_check_keyword(png_ptr, purpose, &new_purpose) + 1; + png_debug1(3, "pCAL purpose length = %d", (int)purpose_len); + units_len = png_strlen(units) + (nparams == 0 ? 0 : 1); + png_debug1(3, "pCAL units length = %d", (int)units_len); + total_len = purpose_len + units_len + 10; + + params_len = (png_uint_32p)png_malloc(png_ptr, + (png_uint_32)(nparams * png_sizeof(png_uint_32))); + + /* Find the length of each parameter, making sure we don't count the + null terminator for the last parameter. */ + for (i = 0; i < nparams; i++) + { + params_len[i] = png_strlen(params[i]) + (i == nparams - 1 ? 0 : 1); + png_debug2(3, "pCAL parameter %d length = %lu", i, + (unsigned long) params_len[i]); + total_len += (png_size_t)params_len[i]; + } + + png_debug1(3, "pCAL total length = %d", (int)total_len); + png_write_chunk_start(png_ptr, (png_bytep)png_pCAL, (png_uint_32)total_len); + png_write_chunk_data(png_ptr, (png_bytep)new_purpose, + (png_size_t)purpose_len); + png_save_int_32(buf, X0); + png_save_int_32(buf + 4, X1); + buf[8] = (png_byte)type; + buf[9] = (png_byte)nparams; + png_write_chunk_data(png_ptr, buf, (png_size_t)10); + png_write_chunk_data(png_ptr, (png_bytep)units, (png_size_t)units_len); + + png_free(png_ptr, new_purpose); + + for (i = 0; i < nparams; i++) + { + png_write_chunk_data(png_ptr, (png_bytep)params[i], + (png_size_t)params_len[i]); + } + + png_free(png_ptr, params_len); + png_write_chunk_end(png_ptr); +} +#endif + +#ifdef PNG_WRITE_sCAL_SUPPORTED +/* Write the sCAL chunk */ +#if defined(PNG_FLOATING_POINT_SUPPORTED) && defined(PNG_STDIO_SUPPORTED) +void /* PRIVATE */ +png_write_sCAL(png_structp png_ptr, int unit, double width, double height) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_sCAL; +#endif + char buf[64]; + png_size_t total_len; + + png_debug(1, "in png_write_sCAL"); + + buf[0] = (char)unit; +#ifdef _WIN32_WCE +/* sprintf() function is not supported on WindowsCE */ + { + wchar_t wc_buf[32]; + size_t wc_len; + swprintf(wc_buf, TEXT("%12.12e"), width); + wc_len = wcslen(wc_buf); + WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + 1, wc_len, NULL, + NULL); + total_len = wc_len + 2; + swprintf(wc_buf, TEXT("%12.12e"), height); + wc_len = wcslen(wc_buf); + WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + total_len, wc_len, + NULL, NULL); + total_len += wc_len; + } +#else + png_snprintf(buf + 1, 63, "%12.12e", width); + total_len = 1 + png_strlen(buf + 1) + 1; + png_snprintf(buf + total_len, 64-total_len, "%12.12e", height); + total_len += png_strlen(buf + total_len); +#endif + + png_debug1(3, "sCAL total length = %u", (unsigned int)total_len); + png_write_chunk(png_ptr, (png_bytep)png_sCAL, (png_bytep)buf, total_len); +} +#else +#ifdef PNG_FIXED_POINT_SUPPORTED +void /* PRIVATE */ +png_write_sCAL_s(png_structp png_ptr, int unit, png_charp width, + png_charp height) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_sCAL; +#endif + png_byte buf[64]; + png_size_t wlen, hlen, total_len; + + png_debug(1, "in png_write_sCAL_s"); + + wlen = png_strlen(width); + hlen = png_strlen(height); + total_len = wlen + hlen + 2; + if (total_len > 64) + { + png_warning(png_ptr, "Can't write sCAL (buffer too small)"); + return; + } + + buf[0] = (png_byte)unit; + png_memcpy(buf + 1, width, wlen + 1); /* Append the '\0' here */ + png_memcpy(buf + wlen + 2, height, hlen); /* Do NOT append the '\0' here */ + + png_debug1(3, "sCAL total length = %u", (unsigned int)total_len); + png_write_chunk(png_ptr, (png_bytep)png_sCAL, buf, total_len); +} +#endif +#endif +#endif + +#ifdef PNG_WRITE_pHYs_SUPPORTED +/* Write the pHYs chunk */ +void /* PRIVATE */ +png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit, + png_uint_32 y_pixels_per_unit, + int unit_type) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_pHYs; +#endif + png_byte buf[9]; + + png_debug(1, "in png_write_pHYs"); + + if (unit_type >= PNG_RESOLUTION_LAST) + png_warning(png_ptr, "Unrecognized unit type for pHYs chunk"); + + png_save_uint_32(buf, x_pixels_per_unit); + png_save_uint_32(buf + 4, y_pixels_per_unit); + buf[8] = (png_byte)unit_type; + + png_write_chunk(png_ptr, (png_bytep)png_pHYs, buf, (png_size_t)9); +} +#endif + +#ifdef PNG_WRITE_tIME_SUPPORTED +/* Write the tIME chunk. Use either png_convert_from_struct_tm() + * or png_convert_from_time_t(), or fill in the structure yourself. + */ +void /* PRIVATE */ +png_write_tIME(png_structp png_ptr, png_timep mod_time) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_tIME; +#endif + png_byte buf[7]; + + png_debug(1, "in png_write_tIME"); + + if (mod_time->month > 12 || mod_time->month < 1 || + mod_time->day > 31 || mod_time->day < 1 || + mod_time->hour > 23 || mod_time->second > 60) + { + png_warning(png_ptr, "Invalid time specified for tIME chunk"); + return; + } + + png_save_uint_16(buf, mod_time->year); + buf[2] = mod_time->month; + buf[3] = mod_time->day; + buf[4] = mod_time->hour; + buf[5] = mod_time->minute; + buf[6] = mod_time->second; + + png_write_chunk(png_ptr, (png_bytep)png_tIME, buf, (png_size_t)7); +} +#endif + +#if defined(PNG_WRITE_APNG_SUPPORTED) +void /* PRIVATE */ +png_write_acTL(png_structp png_ptr, + png_uint_32 num_frames, png_uint_32 num_plays) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_acTL; +#endif + png_byte data[16]; + + png_debug(1, "in png_write_acTL"); + + png_ptr->num_frames_to_write = num_frames; + + if (png_ptr->apng_flags & PNG_FIRST_FRAME_HIDDEN) + num_frames--; + + png_save_uint_32(data, num_frames); + png_save_uint_32(data + 4, num_plays); + + png_write_chunk(png_ptr, (png_bytep)png_acTL, data, (png_size_t)8); +} + +void /* PRIVATE */ +png_write_fcTL(png_structp png_ptr, png_uint_32 width, png_uint_32 height, + png_uint_32 x_offset, png_uint_32 y_offset, + png_uint_16 delay_num, png_uint_16 delay_den, png_byte dispose_op, + png_byte blend_op) +{ +#ifdef PNG_USE_LOCAL_ARRAYS + PNG_fcTL; +#endif + png_byte data[26]; + + png_debug(1, "in png_write_fcTL"); + + if (png_ptr->num_frames_written == 0 && (x_offset != 0 || y_offset != 0)) + png_error(png_ptr, "x and/or y offset for the first frame aren't 0"); + if (png_ptr->num_frames_written == 0 && + (width != png_ptr->first_frame_width || + height != png_ptr->first_frame_height)) + png_error(png_ptr, "width and/or height in the first frame's fcTL " + "don't match the ones in IHDR"); + + /* more error checking */ + png_ensure_fcTL_is_valid(png_ptr, width, height, x_offset, y_offset, + delay_num, delay_den, dispose_op, blend_op); + + png_save_uint_32(data, png_ptr->next_seq_num); + png_save_uint_32(data + 4, width); + png_save_uint_32(data + 8, height); + png_save_uint_32(data + 12, x_offset); + png_save_uint_32(data + 16, y_offset); + png_save_uint_16(data + 20, delay_num); + png_save_uint_16(data + 22, delay_den); + data[24] = dispose_op; + data[25] = blend_op; + + png_write_chunk(png_ptr, (png_bytep)png_fcTL, data, (png_size_t)26); + + png_ptr->next_seq_num++; +} +#endif /* PNG_WRITE_APNG_SUPPORTED */ + +/* Initializes the row writing capability of libpng */ +void /* PRIVATE */ +png_write_start_row(png_structp png_ptr) +{ +#ifdef PNG_WRITE_INTERLACING_SUPPORTED + /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ + + /* Start of interlace block */ + int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0}; + + /* Offset to next interlace block */ + int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; + + /* Start of interlace block in the y direction */ + int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1}; + + /* Offset to next interlace block in the y direction */ + int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; +#endif + + png_size_t buf_size; + + png_debug(1, "in png_write_start_row"); + + buf_size = (png_size_t)(PNG_ROWBYTES( + png_ptr->usr_channels*png_ptr->usr_bit_depth, png_ptr->width) + 1); + + /* Set up row buffer */ + png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, + (png_uint_32)buf_size); + png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE; + +#ifdef PNG_WRITE_FILTER_SUPPORTED + /* Set up filtering buffer, if using this filter */ + if (png_ptr->do_filter & PNG_FILTER_SUB) + { + png_ptr->sub_row = (png_bytep)png_malloc(png_ptr, + (png_uint_32)(png_ptr->rowbytes + 1)); + png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB; + } + + /* We only need to keep the previous row if we are using one of these. */ + if (png_ptr->do_filter & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH)) + { + /* Set up previous row buffer */ + png_ptr->prev_row = (png_bytep)png_calloc(png_ptr, + (png_uint_32)buf_size); + + if (png_ptr->do_filter & PNG_FILTER_UP) + { + png_ptr->up_row = (png_bytep)png_malloc(png_ptr, + (png_uint_32)(png_ptr->rowbytes + 1)); + png_ptr->up_row[0] = PNG_FILTER_VALUE_UP; + } + + if (png_ptr->do_filter & PNG_FILTER_AVG) + { + png_ptr->avg_row = (png_bytep)png_malloc(png_ptr, + (png_uint_32)(png_ptr->rowbytes + 1)); + png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG; + } + + if (png_ptr->do_filter & PNG_FILTER_PAETH) + { + png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr, + (png_uint_32)(png_ptr->rowbytes + 1)); + png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH; + } + } +#endif /* PNG_WRITE_FILTER_SUPPORTED */ + +#ifdef PNG_WRITE_INTERLACING_SUPPORTED + /* If interlaced, we need to set up width and height of pass */ + if (png_ptr->interlaced) + { + if (!(png_ptr->transformations & PNG_INTERLACE)) + { + png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 - + png_pass_ystart[0]) / png_pass_yinc[0]; + png_ptr->usr_width = (png_ptr->width + png_pass_inc[0] - 1 - + png_pass_start[0]) / png_pass_inc[0]; + } + else + { + png_ptr->num_rows = png_ptr->height; + png_ptr->usr_width = png_ptr->width; + } + } + else +#endif + { + png_ptr->num_rows = png_ptr->height; + png_ptr->usr_width = png_ptr->width; + } + png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; + png_ptr->zstream.next_out = png_ptr->zbuf; +} + +/* Internal use only. Called when finished processing a row of data. */ +void /* PRIVATE */ +png_write_finish_row(png_structp png_ptr) +{ +#ifdef PNG_WRITE_INTERLACING_SUPPORTED + /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ + + /* Start of interlace block */ + int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0}; + + /* Offset to next interlace block */ + int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; + + /* Start of interlace block in the y direction */ + int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1}; + + /* Offset to next interlace block in the y direction */ + int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; +#endif + + int ret; + + png_debug(1, "in png_write_finish_row"); + + /* Next row */ + png_ptr->row_number++; + + /* See if we are done */ + if (png_ptr->row_number < png_ptr->num_rows) + return; + +#ifdef PNG_WRITE_INTERLACING_SUPPORTED + /* If interlaced, go to next pass */ + if (png_ptr->interlaced) + { + png_ptr->row_number = 0; + if (png_ptr->transformations & PNG_INTERLACE) + { + png_ptr->pass++; + } + else + { + /* Loop until we find a non-zero width or height pass */ + do + { + png_ptr->pass++; + if (png_ptr->pass >= 7) + break; + png_ptr->usr_width = (png_ptr->width + + png_pass_inc[png_ptr->pass] - 1 - + png_pass_start[png_ptr->pass]) / + png_pass_inc[png_ptr->pass]; + png_ptr->num_rows = (png_ptr->height + + png_pass_yinc[png_ptr->pass] - 1 - + png_pass_ystart[png_ptr->pass]) / + png_pass_yinc[png_ptr->pass]; + if (png_ptr->transformations & PNG_INTERLACE) + break; + } while (png_ptr->usr_width == 0 || png_ptr->num_rows == 0); + + } + + /* Reset the row above the image for the next pass */ + if (png_ptr->pass < 7) + { + if (png_ptr->prev_row != NULL) + png_memset(png_ptr->prev_row, 0, + (png_size_t)(PNG_ROWBYTES(png_ptr->usr_channels* + png_ptr->usr_bit_depth, png_ptr->width)) + 1); + return; + } + } +#endif + + /* If we get here, we've just written the last row, so we need + to flush the compressor */ + do + { + /* Tell the compressor we are done */ + ret = deflate(&png_ptr->zstream, Z_FINISH); + /* Check for an error */ + if (ret == Z_OK) + { + /* Check to see if we need more room */ + if (!(png_ptr->zstream.avail_out)) + { + png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size); + png_ptr->zstream.next_out = png_ptr->zbuf; + png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; + } + } + else if (ret != Z_STREAM_END) + { + if (png_ptr->zstream.msg != NULL) + png_error(png_ptr, png_ptr->zstream.msg); + else + png_error(png_ptr, "zlib error"); + } + } while (ret != Z_STREAM_END); + + /* Write any extra space */ + if (png_ptr->zstream.avail_out < png_ptr->zbuf_size) + { + png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size - + png_ptr->zstream.avail_out); + } + + deflateReset(&png_ptr->zstream); + png_ptr->zstream.data_type = Z_BINARY; +} + +#ifdef PNG_WRITE_INTERLACING_SUPPORTED +/* Pick out the correct pixels for the interlace pass. + * The basic idea here is to go through the row with a source + * pointer and a destination pointer (sp and dp), and copy the + * correct pixels for the pass. As the row gets compacted, + * sp will always be >= dp, so we should never overwrite anything. + * See the default: case for the easiest code to understand. + */ +void /* PRIVATE */ +png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass) +{ + /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ + + /* Start of interlace block */ + int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0}; + + /* Offset to next interlace block */ + int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; + + png_debug(1, "in png_do_write_interlace"); + + /* We don't have to do anything on the last pass (6) */ +#ifdef PNG_USELESS_TESTS_SUPPORTED + if (row != NULL && row_info != NULL && pass < 6) +#else + if (pass < 6) +#endif + { + /* Each pixel depth is handled separately */ + switch (row_info->pixel_depth) + { + case 1: + { + png_bytep sp; + png_bytep dp; + int shift; + int d; + int value; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + dp = row; + d = 0; + shift = 7; + for (i = png_pass_start[pass]; i < row_width; + i += png_pass_inc[pass]) + { + sp = row + (png_size_t)(i >> 3); + value = (int)(*sp >> (7 - (int)(i & 0x07))) & 0x01; + d |= (value << shift); + + if (shift == 0) + { + shift = 7; + *dp++ = (png_byte)d; + d = 0; + } + else + shift--; + + } + if (shift != 7) + *dp = (png_byte)d; + break; + } + case 2: + { + png_bytep sp; + png_bytep dp; + int shift; + int d; + int value; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + dp = row; + shift = 6; + d = 0; + for (i = png_pass_start[pass]; i < row_width; + i += png_pass_inc[pass]) + { + sp = row + (png_size_t)(i >> 2); + value = (*sp >> ((3 - (int)(i & 0x03)) << 1)) & 0x03; + d |= (value << shift); + + if (shift == 0) + { + shift = 6; + *dp++ = (png_byte)d; + d = 0; + } + else + shift -= 2; + } + if (shift != 6) + *dp = (png_byte)d; + break; + } + case 4: + { + png_bytep sp; + png_bytep dp; + int shift; + int d; + int value; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + + dp = row; + shift = 4; + d = 0; + for (i = png_pass_start[pass]; i < row_width; + i += png_pass_inc[pass]) + { + sp = row + (png_size_t)(i >> 1); + value = (*sp >> ((1 - (int)(i & 0x01)) << 2)) & 0x0f; + d |= (value << shift); + + if (shift == 0) + { + shift = 4; + *dp++ = (png_byte)d; + d = 0; + } + else + shift -= 4; + } + if (shift != 4) + *dp = (png_byte)d; + break; + } + default: + { + png_bytep sp; + png_bytep dp; + png_uint_32 i; + png_uint_32 row_width = row_info->width; + png_size_t pixel_bytes; + + /* Start at the beginning */ + dp = row; + /* Find out how many bytes each pixel takes up */ + pixel_bytes = (row_info->pixel_depth >> 3); + /* Loop through the row, only looking at the pixels that + matter */ + for (i = png_pass_start[pass]; i < row_width; + i += png_pass_inc[pass]) + { + /* Find out where the original pixel is */ + sp = row + (png_size_t)i * pixel_bytes; + /* Move the pixel */ + if (dp != sp) + png_memcpy(dp, sp, pixel_bytes); + /* Next pixel */ + dp += pixel_bytes; + } + break; + } + } + /* Set new row width */ + row_info->width = (row_info->width + + png_pass_inc[pass] - 1 - + png_pass_start[pass]) / + png_pass_inc[pass]; + row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, + row_info->width); + } +} +#endif + +/* This filters the row, chooses which filter to use, if it has not already + * been specified by the application, and then writes the row out with the + * chosen filter. + */ +#define PNG_MAXSUM (((png_uint_32)(-1)) >> 1) +#define PNG_HISHIFT 10 +#define PNG_LOMASK ((png_uint_32)0xffffL) +#define PNG_HIMASK ((png_uint_32)(~PNG_LOMASK >> PNG_HISHIFT)) +void /* PRIVATE */ +png_write_find_filter(png_structp png_ptr, png_row_infop row_info) +{ + png_bytep best_row; +#ifdef PNG_WRITE_FILTER_SUPPORTED + png_bytep prev_row, row_buf; + png_uint_32 mins, bpp; + png_byte filter_to_do = png_ptr->do_filter; + png_uint_32 row_bytes = row_info->rowbytes; +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED + int num_p_filters = (int)png_ptr->num_prev_filters; +#endif + + png_debug(1, "in png_write_find_filter"); + +#ifndef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED + if (png_ptr->row_number == 0 && filter_to_do == PNG_ALL_FILTERS) + { + /* These will never be selected so we need not test them. */ + filter_to_do &= ~(PNG_FILTER_UP | PNG_FILTER_PAETH); + } +#endif + + /* Find out how many bytes offset each pixel is */ + bpp = (row_info->pixel_depth + 7) >> 3; + + prev_row = png_ptr->prev_row; +#endif + best_row = png_ptr->row_buf; +#ifdef PNG_WRITE_FILTER_SUPPORTED + row_buf = best_row; + mins = PNG_MAXSUM; + + /* The prediction method we use is to find which method provides the + * smallest value when summing the absolute values of the distances + * from zero, using anything >= 128 as negative numbers. This is known + * as the "minimum sum of absolute differences" heuristic. Other + * heuristics are the "weighted minimum sum of absolute differences" + * (experimental and can in theory improve compression), and the "zlib + * predictive" method (not implemented yet), which does test compressions + * of lines using different filter methods, and then chooses the + * (series of) filter(s) that give minimum compressed data size (VERY + * computationally expensive). + * + * GRR 980525: consider also + * (1) minimum sum of absolute differences from running average (i.e., + * keep running sum of non-absolute differences & count of bytes) + * [track dispersion, too? restart average if dispersion too large?] + * (1b) minimum sum of absolute differences from sliding average, probably + * with window size <= deflate window (usually 32K) + * (2) minimum sum of squared differences from zero or running average + * (i.e., ~ root-mean-square approach) + */ + + + /* We don't need to test the 'no filter' case if this is the only filter + * that has been chosen, as it doesn't actually do anything to the data. + */ + if ((filter_to_do & PNG_FILTER_NONE) && + filter_to_do != PNG_FILTER_NONE) + { + png_bytep rp; + png_uint_32 sum = 0; + png_uint_32 i; + int v; + + for (i = 0, rp = row_buf + 1; i < row_bytes; i++, rp++) + { + v = *rp; + sum += (v < 128) ? v : 256 - v; + } + +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED + if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) + { + png_uint_32 sumhi, sumlo; + int j; + sumlo = sum & PNG_LOMASK; + sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; /* Gives us some footroom */ + + /* Reduce the sum if we match any of the previous rows */ + for (j = 0; j < num_p_filters; j++) + { + if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE) + { + sumlo = (sumlo * png_ptr->filter_weights[j]) >> + PNG_WEIGHT_SHIFT; + sumhi = (sumhi * png_ptr->filter_weights[j]) >> + PNG_WEIGHT_SHIFT; + } + } + + /* Factor in the cost of this filter (this is here for completeness, + * but it makes no sense to have a "cost" for the NONE filter, as + * it has the minimum possible computational cost - none). + */ + sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >> + PNG_COST_SHIFT; + sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >> + PNG_COST_SHIFT; + + if (sumhi > PNG_HIMASK) + sum = PNG_MAXSUM; + else + sum = (sumhi << PNG_HISHIFT) + sumlo; + } +#endif + mins = sum; + } + + /* Sub filter */ + if (filter_to_do == PNG_FILTER_SUB) + /* It's the only filter so no testing is needed */ + { + png_bytep rp, lp, dp; + png_uint_32 i; + for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp; + i++, rp++, dp++) + { + *dp = *rp; + } + for (lp = row_buf + 1; i < row_bytes; + i++, rp++, lp++, dp++) + { + *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff); + } + best_row = png_ptr->sub_row; + } + + else if (filter_to_do & PNG_FILTER_SUB) + { + png_bytep rp, dp, lp; + png_uint_32 sum = 0, lmins = mins; + png_uint_32 i; + int v; + +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED + /* We temporarily increase the "minimum sum" by the factor we + * would reduce the sum of this filter, so that we can do the + * early exit comparison without scaling the sum each time. + */ + if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) + { + int j; + png_uint_32 lmhi, lmlo; + lmlo = lmins & PNG_LOMASK; + lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK; + + for (j = 0; j < num_p_filters; j++) + { + if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB) + { + lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >> + PNG_WEIGHT_SHIFT; + lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >> + PNG_WEIGHT_SHIFT; + } + } + + lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >> + PNG_COST_SHIFT; + lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >> + PNG_COST_SHIFT; + + if (lmhi > PNG_HIMASK) + lmins = PNG_MAXSUM; + else + lmins = (lmhi << PNG_HISHIFT) + lmlo; + } +#endif + + for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp; + i++, rp++, dp++) + { + v = *dp = *rp; + + sum += (v < 128) ? v : 256 - v; + } + for (lp = row_buf + 1; i < row_bytes; + i++, rp++, lp++, dp++) + { + v = *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff); + + sum += (v < 128) ? v : 256 - v; + + if (sum > lmins) /* We are already worse, don't continue. */ + break; + } + +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED + if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) + { + int j; + png_uint_32 sumhi, sumlo; + sumlo = sum & PNG_LOMASK; + sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; + + for (j = 0; j < num_p_filters; j++) + { + if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB) + { + sumlo = (sumlo * png_ptr->inv_filter_weights[j]) >> + PNG_WEIGHT_SHIFT; + sumhi = (sumhi * png_ptr->inv_filter_weights[j]) >> + PNG_WEIGHT_SHIFT; + } + } + + sumlo = (sumlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >> + PNG_COST_SHIFT; + sumhi = (sumhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >> + PNG_COST_SHIFT; + + if (sumhi > PNG_HIMASK) + sum = PNG_MAXSUM; + else + sum = (sumhi << PNG_HISHIFT) + sumlo; + } +#endif + + if (sum < mins) + { + mins = sum; + best_row = png_ptr->sub_row; + } + } + + /* Up filter */ + if (filter_to_do == PNG_FILTER_UP) + { + png_bytep rp, dp, pp; + png_uint_32 i; + + for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1, + pp = prev_row + 1; i < row_bytes; + i++, rp++, pp++, dp++) + { + *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff); + } + best_row = png_ptr->up_row; + } + + else if (filter_to_do & PNG_FILTER_UP) + { + png_bytep rp, dp, pp; + png_uint_32 sum = 0, lmins = mins; + png_uint_32 i; + int v; + + +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED + if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) + { + int j; + png_uint_32 lmhi, lmlo; + lmlo = lmins & PNG_LOMASK; + lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK; + + for (j = 0; j < num_p_filters; j++) + { + if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP) + { + lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >> + PNG_WEIGHT_SHIFT; + lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >> + PNG_WEIGHT_SHIFT; + } + } + + lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >> + PNG_COST_SHIFT; + lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >> + PNG_COST_SHIFT; + + if (lmhi > PNG_HIMASK) + lmins = PNG_MAXSUM; + else + lmins = (lmhi << PNG_HISHIFT) + lmlo; + } +#endif + + for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1, + pp = prev_row + 1; i < row_bytes; i++) + { + v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff); + + sum += (v < 128) ? v : 256 - v; + + if (sum > lmins) /* We are already worse, don't continue. */ + break; + } + +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED + if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) + { + int j; + png_uint_32 sumhi, sumlo; + sumlo = sum & PNG_LOMASK; + sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; + + for (j = 0; j < num_p_filters; j++) + { + if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP) + { + sumlo = (sumlo * png_ptr->filter_weights[j]) >> + PNG_WEIGHT_SHIFT; + sumhi = (sumhi * png_ptr->filter_weights[j]) >> + PNG_WEIGHT_SHIFT; + } + } + + sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >> + PNG_COST_SHIFT; + sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >> + PNG_COST_SHIFT; + + if (sumhi > PNG_HIMASK) + sum = PNG_MAXSUM; + else + sum = (sumhi << PNG_HISHIFT) + sumlo; + } +#endif + + if (sum < mins) + { + mins = sum; + best_row = png_ptr->up_row; + } + } + + /* Avg filter */ + if (filter_to_do == PNG_FILTER_AVG) + { + png_bytep rp, dp, pp, lp; + png_uint_32 i; + for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1, + pp = prev_row + 1; i < bpp; i++) + { + *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff); + } + for (lp = row_buf + 1; i < row_bytes; i++) + { + *dp++ = (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2)) + & 0xff); + } + best_row = png_ptr->avg_row; + } + + else if (filter_to_do & PNG_FILTER_AVG) + { + png_bytep rp, dp, pp, lp; + png_uint_32 sum = 0, lmins = mins; + png_uint_32 i; + int v; + +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED + if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) + { + int j; + png_uint_32 lmhi, lmlo; + lmlo = lmins & PNG_LOMASK; + lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK; + + for (j = 0; j < num_p_filters; j++) + { + if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_AVG) + { + lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >> + PNG_WEIGHT_SHIFT; + lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >> + PNG_WEIGHT_SHIFT; + } + } + + lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >> + PNG_COST_SHIFT; + lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >> + PNG_COST_SHIFT; + + if (lmhi > PNG_HIMASK) + lmins = PNG_MAXSUM; + else + lmins = (lmhi << PNG_HISHIFT) + lmlo; + } +#endif + + for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1, + pp = prev_row + 1; i < bpp; i++) + { + v = *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff); + + sum += (v < 128) ? v : 256 - v; + } + for (lp = row_buf + 1; i < row_bytes; i++) + { + v = *dp++ = + (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2)) & 0xff); + + sum += (v < 128) ? v : 256 - v; + + if (sum > lmins) /* We are already worse, don't continue. */ + break; + } + +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED + if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) + { + int j; + png_uint_32 sumhi, sumlo; + sumlo = sum & PNG_LOMASK; + sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; + + for (j = 0; j < num_p_filters; j++) + { + if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE) + { + sumlo = (sumlo * png_ptr->filter_weights[j]) >> + PNG_WEIGHT_SHIFT; + sumhi = (sumhi * png_ptr->filter_weights[j]) >> + PNG_WEIGHT_SHIFT; + } + } + + sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >> + PNG_COST_SHIFT; + sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >> + PNG_COST_SHIFT; + + if (sumhi > PNG_HIMASK) + sum = PNG_MAXSUM; + else + sum = (sumhi << PNG_HISHIFT) + sumlo; + } +#endif + + if (sum < mins) + { + mins = sum; + best_row = png_ptr->avg_row; + } + } + + /* Paeth filter */ + if (filter_to_do == PNG_FILTER_PAETH) + { + png_bytep rp, dp, pp, cp, lp; + png_uint_32 i; + for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1, + pp = prev_row + 1; i < bpp; i++) + { + *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff); + } + + for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++) + { + int a, b, c, pa, pb, pc, p; + + b = *pp++; + c = *cp++; + a = *lp++; + + p = b - c; + pc = a - c; + +#ifdef PNG_USE_ABS + pa = abs(p); + pb = abs(pc); + pc = abs(p + pc); +#else + pa = p < 0 ? -p : p; + pb = pc < 0 ? -pc : pc; + pc = (p + pc) < 0 ? -(p + pc) : p + pc; +#endif + + p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c; + + *dp++ = (png_byte)(((int)*rp++ - p) & 0xff); + } + best_row = png_ptr->paeth_row; + } + + else if (filter_to_do & PNG_FILTER_PAETH) + { + png_bytep rp, dp, pp, cp, lp; + png_uint_32 sum = 0, lmins = mins; + png_uint_32 i; + int v; + +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED + if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) + { + int j; + png_uint_32 lmhi, lmlo; + lmlo = lmins & PNG_LOMASK; + lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK; + + for (j = 0; j < num_p_filters; j++) + { + if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH) + { + lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >> + PNG_WEIGHT_SHIFT; + lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >> + PNG_WEIGHT_SHIFT; + } + } + + lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >> + PNG_COST_SHIFT; + lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >> + PNG_COST_SHIFT; + + if (lmhi > PNG_HIMASK) + lmins = PNG_MAXSUM; + else + lmins = (lmhi << PNG_HISHIFT) + lmlo; + } +#endif + + for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1, + pp = prev_row + 1; i < bpp; i++) + { + v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff); + + sum += (v < 128) ? v : 256 - v; + } + + for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++) + { + int a, b, c, pa, pb, pc, p; + + b = *pp++; + c = *cp++; + a = *lp++; + +#ifndef PNG_SLOW_PAETH + p = b - c; + pc = a - c; +#ifdef PNG_USE_ABS + pa = abs(p); + pb = abs(pc); + pc = abs(p + pc); +#else + pa = p < 0 ? -p : p; + pb = pc < 0 ? -pc : pc; + pc = (p + pc) < 0 ? -(p + pc) : p + pc; +#endif + p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c; +#else /* PNG_SLOW_PAETH */ + p = a + b - c; + pa = abs(p - a); + pb = abs(p - b); + pc = abs(p - c); + if (pa <= pb && pa <= pc) + p = a; + else if (pb <= pc) + p = b; + else + p = c; +#endif /* PNG_SLOW_PAETH */ + + v = *dp++ = (png_byte)(((int)*rp++ - p) & 0xff); + + sum += (v < 128) ? v : 256 - v; + + if (sum > lmins) /* We are already worse, don't continue. */ + break; + } + +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED + if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) + { + int j; + png_uint_32 sumhi, sumlo; + sumlo = sum & PNG_LOMASK; + sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; + + for (j = 0; j < num_p_filters; j++) + { + if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH) + { + sumlo = (sumlo * png_ptr->filter_weights[j]) >> + PNG_WEIGHT_SHIFT; + sumhi = (sumhi * png_ptr->filter_weights[j]) >> + PNG_WEIGHT_SHIFT; + } + } + + sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >> + PNG_COST_SHIFT; + sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >> + PNG_COST_SHIFT; + + if (sumhi > PNG_HIMASK) + sum = PNG_MAXSUM; + else + sum = (sumhi << PNG_HISHIFT) + sumlo; + } +#endif + + if (sum < mins) + { + best_row = png_ptr->paeth_row; + } + } +#endif /* PNG_WRITE_FILTER_SUPPORTED */ + /* Do the actual writing of the filtered row data from the chosen filter. */ + + png_write_filtered_row(png_ptr, best_row); + +#ifdef PNG_WRITE_FILTER_SUPPORTED +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED + /* Save the type of filter we picked this time for future calculations */ + if (png_ptr->num_prev_filters > 0) + { + int j; + for (j = 1; j < num_p_filters; j++) + { + png_ptr->prev_filters[j] = png_ptr->prev_filters[j - 1]; + } + png_ptr->prev_filters[j] = best_row[0]; + } +#endif +#endif /* PNG_WRITE_FILTER_SUPPORTED */ +} + + +/* Do the actual writing of a previously filtered row. */ +void /* PRIVATE */ +png_write_filtered_row(png_structp png_ptr, png_bytep filtered_row) +{ + png_debug(1, "in png_write_filtered_row"); + + png_debug1(2, "filter = %d", filtered_row[0]); + /* Set up the zlib input buffer */ + + png_ptr->zstream.next_in = filtered_row; + png_ptr->zstream.avail_in = (uInt)png_ptr->row_info.rowbytes + 1; + /* Repeat until we have compressed all the data */ + do + { + int ret; /* Return of zlib */ + + /* Compress the data */ + ret = deflate(&png_ptr->zstream, Z_NO_FLUSH); + /* Check for compression errors */ + if (ret != Z_OK) + { + if (png_ptr->zstream.msg != NULL) + png_error(png_ptr, png_ptr->zstream.msg); + else + png_error(png_ptr, "zlib error"); + } + + /* See if it is time to write another IDAT */ + if (!(png_ptr->zstream.avail_out)) + { + /* Write the IDAT and reset the zlib output buffer */ + png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size); + png_ptr->zstream.next_out = png_ptr->zbuf; + png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; + } + /* Repeat until all data has been compressed */ + } while (png_ptr->zstream.avail_in); + + /* Swap the current and previous rows */ + if (png_ptr->prev_row != NULL) + { + png_bytep tptr; + + tptr = png_ptr->prev_row; + png_ptr->prev_row = png_ptr->row_buf; + png_ptr->row_buf = tptr; + } + + /* Finish row - updates counters and flushes zlib if last row */ + png_write_finish_row(png_ptr); + +#ifdef PNG_WRITE_FLUSH_SUPPORTED + png_ptr->flush_rows++; + + if (png_ptr->flush_dist > 0 && + png_ptr->flush_rows >= png_ptr->flush_dist) + { + png_write_flush(png_ptr); + } +#endif +} + +#if defined(PNG_WRITE_APNG_SUPPORTED) +void /* PRIVATE */ +png_write_reset(png_structp png_ptr) +{ + png_ptr->row_number = 0; + png_ptr->pass = 0; + png_ptr->mode &= ~PNG_HAVE_IDAT; +} + +void /* PRIVATE */ +png_write_reinit(png_structp png_ptr, png_infop info_ptr, + png_uint_32 width, png_uint_32 height) +{ + if (png_ptr->num_frames_written == 0 && + (width != png_ptr->first_frame_width || + height != png_ptr->first_frame_height)) + png_error(png_ptr, "width and/or height in the first frame's fcTL " + "don't match the ones in IHDR"); + if (width > png_ptr->first_frame_width || + height > png_ptr->first_frame_height) + png_error(png_ptr, "width and/or height for a frame greater than" + "the ones in IHDR"); + + png_set_IHDR(png_ptr, info_ptr, width, height, + info_ptr->bit_depth, info_ptr->color_type, + info_ptr->interlace_type, info_ptr->compression_type, + info_ptr->filter_type); + + png_ptr->width = width; + png_ptr->height = height; + png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, width); + png_ptr->usr_width = png_ptr->width; +} +#endif +#endif /* PNG_WRITE_SUPPORTED */ diff --git a/libs/libpng-src/projects/beos/x86-shared.proj b/libs/libpng-src/projects/beos/x86-shared.proj new file mode 100644 index 000000000..6d2e3c319 Binary files /dev/null and b/libs/libpng-src/projects/beos/x86-shared.proj differ diff --git a/libs/libpng-src/projects/beos/x86-shared.txt b/libs/libpng-src/projects/beos/x86-shared.txt new file mode 100644 index 000000000..0cd4d9db4 --- /dev/null +++ b/libs/libpng-src/projects/beos/x86-shared.txt @@ -0,0 +1,22 @@ +This project builds a shared library version of libpng on x86 BeOS. + +It defines PNG_USE_PNGGCCRD, which activates the assembly code in +pnggccrd.c; this hasn't been extensively tested on BeOS. + +To install: + +1) build + + Note: As of version 1.0.10, you'll get a fair number of warnings when + you compile pnggccrd.c. As far as I know, these are harmless, + but it would be better if someone fixed them. + +2) copy and png.h, pngconf.h somewhere; /boot/home/config/include (which + you'll have to make) is a good choice + +3) copy libpng.so to /boot/home/config/lib + +4) build your libpng.so applications (remember to include libz.a as + well when you link) + +- Chris Herborth, March 27, 2001 diff --git a/libs/libpng-src/projects/beos/x86-static.proj b/libs/libpng-src/projects/beos/x86-static.proj new file mode 100644 index 000000000..37c075366 Binary files /dev/null and b/libs/libpng-src/projects/beos/x86-static.proj differ diff --git a/libs/libpng-src/projects/beos/x86-static.txt b/libs/libpng-src/projects/beos/x86-static.txt new file mode 100644 index 000000000..bb80aaa5f --- /dev/null +++ b/libs/libpng-src/projects/beos/x86-static.txt @@ -0,0 +1,22 @@ +This project builds a static library version of libpng on x86 BeOS. + +It defines PNG_USE_PNGGCCRD, which activates the assembly code in +pnggccrd.c; this hasn't been extensively tested on BeOS. + +To install: + +1) build + + Note: As of version 1.0.10, you'll get a fair number of warnings when + you compile pnggccrd.c. As far as I know, these are harmless, + but it would be better if someone fixed them. + +2) copy and png.h, pngconf.h somewhere; /boot/home/config/include (which + you'll have to make) is a good choice + +3) copy libpng.a to /boot/home/config/lib + +4) build your libpng.a applications (remember to include libz.a as + well when you link) + +- Chris Herborth, March 27, 2001 diff --git a/libs/libpng-src/projects/cbuilder5/libpng.bpf b/libs/libpng-src/projects/cbuilder5/libpng.bpf new file mode 100644 index 000000000..2af81e77c --- /dev/null +++ b/libs/libpng-src/projects/cbuilder5/libpng.bpf @@ -0,0 +1,22 @@ +USEUNIT("libpng.cpp"); +USEUNIT("..\..\png.c"); +USEUNIT("..\..\pngerror.c"); +USEUNIT("..\..\pngget.c"); +USEUNIT("..\..\pngmem.c"); +USEUNIT("..\..\pngpread.c"); +USEUNIT("..\..\pngread.c"); +USEUNIT("..\..\pngrio.c"); +USEUNIT("..\..\pngrtran.c"); +USEUNIT("..\..\pngrutil.c"); +USEUNIT("..\..\pngset.c"); +USEUNIT("..\..\pngtrans.c"); +USEUNIT("..\..\pngwio.c"); +USEUNIT("..\..\pngwrite.c"); +USEUNIT("..\..\pngwtran.c"); +USEUNIT("..\..\pngwutil.c"); +USELIB("..\..\..\zlib\zlib.lib"); +//--------------------------------------------------------------------------- +This file is used by the project manager only and should be treated like the project file + + +DllEntryPoint diff --git a/libs/libpng-src/projects/cbuilder5/libpng.bpg b/libs/libpng-src/projects/cbuilder5/libpng.bpg new file mode 100644 index 000000000..80c197719 --- /dev/null +++ b/libs/libpng-src/projects/cbuilder5/libpng.bpg @@ -0,0 +1,25 @@ +#------------------------------------------------------------------------------ +VERSION = BWS.01 +#------------------------------------------------------------------------------ +!ifndef ROOT +ROOT = $(MAKEDIR)\.. +!endif +#------------------------------------------------------------------------------ +MAKE = $(ROOT)\bin\make.exe -$(MAKEFLAGS) -f$** +DCC = $(ROOT)\bin\dcc32.exe $** +BRCC = $(ROOT)\bin\brcc32.exe $** +#------------------------------------------------------------------------------ +PROJECTS = libpngstat.lib libpng.dll +#------------------------------------------------------------------------------ +default: $(PROJECTS) +#------------------------------------------------------------------------------ + +libpngstat.lib: libpngstat.bpr + $(ROOT)\bin\bpr2mak -t$(ROOT)\bin\deflib.bmk $** + $(ROOT)\bin\make -$(MAKEFLAGS) -f$*.mak + +libpng.dll: libpng.bpr + $(ROOT)\bin\bpr2mak $** + $(ROOT)\bin\make -$(MAKEFLAGS) -f$*.mak + + diff --git a/libs/libpng-src/projects/cbuilder5/libpng.bpr b/libs/libpng-src/projects/cbuilder5/libpng.bpr new file mode 100644 index 000000000..b9fdbe4d0 --- /dev/null +++ b/libs/libpng-src/projects/cbuilder5/libpng.bpr @@ -0,0 +1,157 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +[Version Info] +IncludeVerInfo=0 +AutoIncBuild=0 +MajorVer=1 +MinorVer=0 +Release=0 +Build=0 +Debug=0 +PreRelease=0 +Special=0 +Private=0 +DLL=1 +Locale=2057 +CodePage=1252 + +[Version Info Keys] +CompanyName= +FileDescription= +FileVersion=1.0.0.0 +InternalName= +LegalCopyright= +LegalTrademarks= +OriginalFilename= +ProductName= +ProductVersion= +Comments= + +[HistoryLists\hlIncludePath] +Count=18 +Item0=..\..;..\..\..\zlib;$(BCB)\include +Item1=..\..;P:\My Documents\Source\PNG+ZLib\zlib;$(BCB)\include +Item2=..\..;..\Source\ThirdParty\PortableNetworkGraphics\external;..\Source\ThirdParty\PortableNetworkGraphics;..\Source\ThirdParty\ZLibCompression\external;$(BCB)\include +Item3=..\Source\ThirdParty\PortableNetworkGraphics\external;..\Source\ThirdParty\PortableNetworkGraphics;..\Source\ThirdParty\ZLibCompression\external;$(BCB)\include +Item4=..\Source\ThirdParty\PortableNetworkGraphics\external;..\Source\ThirdParty\PortableNetworkGraphics;..\Source\ThirdParty\ZLibCompression;$(BCB)\include +Item5=..\Source\ThirdParty\PortableNetworkGraphics;..\Source\ThirdParty\ZLibCompression;$(BCB)\include +Item6=..\Source\ThirdParty\PortableNetworkGraphics;P:\Development\Source\ThirdParty\ZLibCompression;$(BCB)\include +Item7=..\Source\ThirdParty\PortableNetworkGraphics;$(BCB)\include +Item8=$(BCB)\include +Item9=..\Source;..\Source\General\Templates;..\Source\SIMUtilities;$(BCB)\include;$(BCB)\include\vcl +Item10=P:\Development\Source\;P:\Development\Source\General\Templates\;P:\Development\Source\SIMUtilities\;$(BCB)\include;$(BCB)\include\vcl +Item11=P:\Development\Source;P:\Development\Source\General\Templates\;P:\Development\Source\SIMUtilities\;$(BCB)\include;$(BCB)\include\vcl +Item12=P:\Development\Source\General\Templates\;P:\Development\Source\SIMUtilities\;$(BCB)\include;$(BCB)\include\vcl +Item13=P:\Development\Source\General\Templates\;P:\Development\Source\SIMUtilities;$(BCB)\include;$(BCB)\include\vcl +Item14=P:\Development\Source\General\Templates\;$(BCB)\include;$(BCB)\include\vcl +Item15=P:\Development\Source\General\Templates;$(BCB)\include;$(BCB)\include\vcl +Item16=P:\Development\Source;$(BCB)\include;$(BCB)\include\vcl +Item17=$(BCB)\include;$(BCB)\include\vcl + +[HistoryLists\hlLibraryPath] +Count=10 +Item0=..\..;$(BCB)\lib\obj;$(BCB)\lib +Item1=..\..;..\Source\ThirdParty\PortableNetworkGraphics\external;..\Source\ThirdParty\PortableNetworkGraphics;$(BCB)\lib\obj;$(BCB)\lib +Item2=..\Source\ThirdParty\PortableNetworkGraphics\external;..\Source\ThirdParty\PortableNetworkGraphics;$(BCB)\lib\obj;$(BCB)\lib +Item3=..\Source\ThirdParty\PortableNetworkGraphics;$(BCB)\lib\obj;$(BCB)\lib +Item4=$(BCB)\lib\obj;$(BCB)\lib +Item5=..\Source\SIMUtilities;..\Source;$(BCB)\lib\obj;$(BCB)\lib +Item6=P:\Development\Source\SIMUtilities\;P:\Development\Source\;$(BCB)\lib\obj;$(BCB)\lib +Item7=P:\Development\Source\SIMUtilities;P:\Development\Source\;$(BCB)\lib\obj;$(BCB)\lib +Item8=P:\Development\Source\;$(BCB)\lib\obj;$(BCB)\lib +Item9=P:\Development\Source;$(BCB)\lib\obj;$(BCB)\lib + +[HistoryLists\hlDebugSourcePath] +Count=1 +Item0=$(BCB)\source\vcl + +[HistoryLists\hlConditionals] +Count=20 +Item0=ZLIB_DLL;Z_PREFIX;PNG_BUILD_DLL;PNG_NO_MODULEDEF +Item1=_DEBUG;ZLIB_DLL;Z_PREFIX;PNG_BUILD_DLL;PNG_NO_MODULEDEF +Item2=PNG_BUILD_DLL;ZLIB_DLL;_DEBUG;PNG_NO_MODULEDEF +Item3=PNG_BUILD_DLL;ZLIB_DLL;_DEBUG;PNG_DEBUG=5;PNG_NO_MODULEDEF;PNG_NO_GLOBAL_ARRAYS +Item4=PNG_BUILD_DLL;ZLIB_DLL;_DEBUG;PNG_DEBUG=5;PNG_NO_MODULEDEF;PNG_SETJMP_NOT_SUPPORTED;PNG_DEBUG_FILE=stderr +Item5=PNG_BUILD_DLL;ZLIB_DLL;_DEBUG;PNG_DEBUG;PNG_NO_MODULEDEF;PNG_SETJMP_NOT_SUPPORTED +Item6=PNG_BUILD_DLL;ZLIB_DLL;_DEBUG;PNG_DEBUG=5;PNG_NO_MODULEDEF;PNG_SETJMP_NOT_SUPPORTED +Item7=PNG_BUILD_DLL;ZLIB_DLL;_DEBUG;PNG_DEBUG=5;PNG_NO_MODULEDEF +Item8=PNG_BUILD_DLL;ZLIB_DLL;_DEBUG;PNG_DEBUG=5 +Item9=PNG_BUILD_DLL;ZLIB_DLL;_DEBUG +Item10=PNG_BUILD_DLL;ZLIB_DLL +Item11=PNG_BUILD_DLL +Item12=PNG_DLL;PNG_BUILD_DLL;ZLIB_DLL +Item13=PNG_DLL;PNG_BUILD_DLL;PNG_NO_GLOBAL_ARRAYS;ZLIB_DLL +Item14=PNG_DLL;PNG_BUILD_DLL;PNG_NO_GLOBAL_ARRAYS +Item15=PNG_DLL;PNG_BUILD_DLL +Item16=PNG_DLL;PNG_BUILD_DLL;PNG_MODULEDEF +Item17=_HTML_FORM +Item18=_DEBUG;_HTML_FORM +Item19=_DEBUG + +[HistoryLists\hlIntOutputDir] +Count=2 +Item0=..\Obj +Item1=P:\Development\Obj + +[Debugging] +DebugSourceDirs= + +[Parameters] +RunParams= +HostApplication=P:\Development\Executables\LibPNGTestApp.exe +RemoteHost= +RemotePath= +RemoteDebug=0 + +[Compiler] +ShowInfoMsgs=0 +LinkDebugVcl=0 +LinkCGLIB=0 + + \ No newline at end of file diff --git a/libs/libpng-src/projects/cbuilder5/libpng.cpp b/libs/libpng-src/projects/cbuilder5/libpng.cpp new file mode 100644 index 000000000..4e2f274d4 --- /dev/null +++ b/libs/libpng-src/projects/cbuilder5/libpng.cpp @@ -0,0 +1,29 @@ +//--------------------------------------------------------------------------- +#include +//--------------------------------------------------------------------------- +// Important note about DLL memory management when your DLL uses the +// static version of the RunTime Library: +// +// If your DLL exports any functions that pass String objects (or structs/ +// classes containing nested Strings) as parameter or function results, +// you will need to add the library MEMMGR.LIB to both the DLL project and +// any other projects that use the DLL. You will also need to use MEMMGR.LIB +// if any other projects which use the DLL will be performing new or delete +// operations on any non-TObject-derived classes which are exported from the +// DLL. Adding MEMMGR.LIB to your project will change the DLL and its calling +// EXE's to use the BORLNDMM.DLL as their memory manager. In these cases, +// the file BORLNDMM.DLL should be deployed along with your DLL. +// +// To avoid using BORLNDMM.DLL, pass string information using "char *" or +// ShortString parameters. +// +// If your DLL uses the dynamic version of the RTL, you do not need to +// explicitly add MEMMGR.LIB as this will be done implicitly for you +//--------------------------------------------------------------------------- + +int WINAPI DllEntryPoint(HINSTANCE, unsigned long, void*) +{ + return 1; +} +//--------------------------------------------------------------------------- + \ No newline at end of file diff --git a/libs/libpng-src/projects/cbuilder5/libpng.readme.txt b/libs/libpng-src/projects/cbuilder5/libpng.readme.txt new file mode 100644 index 000000000..c99c1e9a7 --- /dev/null +++ b/libs/libpng-src/projects/cbuilder5/libpng.readme.txt @@ -0,0 +1,25 @@ +Project files to build libpng using Borland C++ Builder v5.0 + +In order to build and use libpng, please follow these steps: + + 1). Install zlib in a directory at the same level with libpng. + + 2). In a console window, go to the zlib directory and type: + make -f win32\Makefile.bor + After performing this step, you should have a file named + zlib.lib in the zlib directory. + + 3). Add the following conditional define to your project: + PNG_USE_DLL + + 4). Add libpng.lib or libpngstat.lib to the project. + Build the project. + + 5). If the build fails, add the paths to png.h and zlib.h to + your include path, and restart the build. + +By default, the libpng project uses zlib as a static library. If +you wish to use zlib as a DLL, please read the important notes from +the zlib DLL FAQ, found inside the zlib distribution. + +See the libpng documentation for instructions on how to use the code. diff --git a/libs/libpng-src/projects/cbuilder5/libpngstat.bpf b/libs/libpng-src/projects/cbuilder5/libpngstat.bpf new file mode 100644 index 000000000..fbc5c406c --- /dev/null +++ b/libs/libpng-src/projects/cbuilder5/libpngstat.bpf @@ -0,0 +1,22 @@ +USEUNIT("..\..\png.c"); +USEUNIT("..\..\pngerror.c"); +USEUNIT("..\..\pngget.c"); +USEUNIT("..\..\pngmem.c"); +USEUNIT("..\..\pngpread.c"); +USEUNIT("..\..\pngread.c"); +USEUNIT("..\..\pngrio.c"); +USEUNIT("..\..\pngrtran.c"); +USEUNIT("..\..\pngrutil.c"); +USEUNIT("..\..\pngset.c"); +USEUNIT("..\..\pngtrans.c"); +USEUNIT("..\..\pngwio.c"); +USEUNIT("..\..\pngwrite.c"); +USEUNIT("..\..\pngwtran.c"); +USEUNIT("..\..\pngwutil.c"); +USELIB("..\..\..\zlib\zlib.lib"); +//--------------------------------------------------------------------------- +#define Library + +// To add a file to the library use the Project menu 'Add to Project'. + + \ No newline at end of file diff --git a/libs/libpng-src/projects/cbuilder5/libpngstat.bpr b/libs/libpng-src/projects/cbuilder5/libpngstat.bpr new file mode 100644 index 000000000..9a51ecc88 --- /dev/null +++ b/libs/libpng-src/projects/cbuilder5/libpngstat.bpr @@ -0,0 +1,109 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +[Version Info] +IncludeVerInfo=0 +AutoIncBuild=0 +MajorVer=1 +MinorVer=0 +Release=0 +Build=0 +Debug=0 +PreRelease=0 +Special=0 +Private=0 +DLL=0 +Locale=2057 +CodePage=1252 + +[Version Info Keys] +CompanyName= +FileDescription= +FileVersion=1.0.0.0 +InternalName= +LegalCopyright= +LegalTrademarks= +OriginalFilename= +ProductName= +ProductVersion=1.0.0.0 +Comments= + +[HistoryLists\hlIncludePath] +Count=2 +Item0=..\..;P:\My Documents\Source\PNG+ZLib\zlib;$(BCB)\include +Item1=..\..;$(BCB)\include;$(BCB)\include\vcl + +[HistoryLists\hlLibraryPath] +Count=1 +Item0=..\..;$(BCB)\lib\obj;$(BCB)\lib + +[HistoryLists\hlDebugSourcePath] +Count=1 +Item0=$(BCB)\source\vcl + +[HistoryLists\hlConditionals] +Count=1 +Item0=_DEBUG + +[HistoryLists\hlTlibPageSize] +Count=1 +Item0=0x0010 + +[Debugging] +DebugSourceDirs=$(BCB)\source\vcl + +[Parameters] +RunParams= +HostApplication= +RemoteHost= +RemotePath= +RemoteDebug=0 + +[Compiler] +ShowInfoMsgs=0 +LinkDebugVcl=0 +LinkCGLIB=0 + +[Language] +ActiveLang= +ProjectLang= +RootDir= + + \ No newline at end of file diff --git a/libs/libpng-src/projects/cbuilder5/zlib.readme.txt b/libs/libpng-src/projects/cbuilder5/zlib.readme.txt new file mode 100644 index 000000000..cb6a7a81e --- /dev/null +++ b/libs/libpng-src/projects/cbuilder5/zlib.readme.txt @@ -0,0 +1,14 @@ +The project that builds libpng under Borland C++ Builder does not +explicitly build zlib. By taking this decision, there is no need +to update the libpng project each time when there is a change in +the list of zlib source files. After all, this list is private to +zlib, and applications (such as libpng) should not assume anything +about it. + +If you wish to contribute a project that builds zlib under Borland +C++ Builder, please submit it to the zlib developers, not to the +libpng developers. + +By default, the libpng project uses zlib as a static library. If +you wish to use zlib as a DLL, please read the important notes from +the zlib DLL FAQ, found inside the zlib distribution. diff --git a/libs/libpng-src/projects/libpng32.a b/libs/libpng-src/projects/libpng32.a new file mode 100644 index 000000000..74cb54e8c Binary files /dev/null and b/libs/libpng-src/projects/libpng32.a differ diff --git a/libs/libpng-src/projects/libpng64.a b/libs/libpng-src/projects/libpng64.a new file mode 100644 index 000000000..bba4c9121 Binary files /dev/null and b/libs/libpng-src/projects/libpng64.a differ diff --git a/libs/libpng-src/projects/netware.txt b/libs/libpng-src/projects/netware.txt new file mode 100644 index 000000000..178361da8 --- /dev/null +++ b/libs/libpng-src/projects/netware.txt @@ -0,0 +1,6 @@ +A set of project files is available for Netware. Get +libpng-1.2.5-project-netware.zip from a libpng distribution +site such as http://libpng.sourceforge.net + +Put the zip file in this directory (projects) and then run +"unzip -a libpng-1.2.5-project-netware.zip" diff --git a/libs/libpng-src/projects/visualc10/.gitignore b/libs/libpng-src/projects/visualc10/.gitignore new file mode 100644 index 000000000..118a15cbb --- /dev/null +++ b/libs/libpng-src/projects/visualc10/.gitignore @@ -0,0 +1,3 @@ +/Win32 +/x64 +/libpng.vcproj.*.*.user diff --git a/libs/libpng-src/projects/visualc10/libpng.vcxproj b/libs/libpng-src/projects/visualc10/libpng.vcxproj new file mode 100644 index 000000000..1893783c0 --- /dev/null +++ b/libs/libpng-src/projects/visualc10/libpng.vcxproj @@ -0,0 +1,397 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {72B01ACA-7A1A-4F7B-ACEF-2607299CF052} + libpng + + + + StaticLibrary + false + + + StaticLibrary + false + + + StaticLibrary + false + + + StaticLibrary + false + + + + + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>10.0.30319.1 + $(ProjectDir)$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + + + + MaxSpeed + OnlyExplicitInline + ..\..;..\..\..\zlib;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;PNG_USE_PNGVCRD;PNG_LIBPNG_SPECIALBUILD;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + MultiThreaded + true + $(ProjectDir)$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + Level3 + true + CompileAsC + true + + + NDEBUG;%(PreprocessorDefinitions) + 0x0409 + ..\..;%(AdditionalIncludeDirectories) + + + $(ProjectDir)$(Platform)\$(Configuration)\libpng.lib + true + MachineX86 + + + true + $(ProjectDir)$(PlatformName)\$(ConfigurationName)\libpng.bsc + + + + + X64 + + + MaxSpeed + OnlyExplicitInline + ..\..;..\..\..\zlib;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;PNG_USE_PNGVCRD;PNG_LIBPNG_SPECIALBUILD;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + MultiThreaded + true + $(ProjectDir)$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + Level3 + true + CompileAsC + 4267;%(DisableSpecificWarnings) + true + + + NDEBUG;%(PreprocessorDefinitions) + 0x0409 + ..\..;%(AdditionalIncludeDirectories) + + + $(ProjectDir)$(Platform)\$(Configuration)\libpng.lib + true + MachineX64 + + + true + $(ProjectDir)$(PlatformName)\$(ConfigurationName)\libpng.bsc + + + + + Disabled + ..\..;..\..\..\zlib;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;DEBUG;PNG_DEBUG=1;PNG_USE_PNGVCRD;PNG_LIBPNG_SPECIALBUILD;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + EnableFastChecks + MultiThreadedDebug + $(ProjectDir)$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + Level3 + true + EditAndContinue + CompileAsC + false + + + _DEBUG;%(PreprocessorDefinitions) + 0x0409 + + + $(ProjectDir)$(Platform)\$(Configuration)\libpng.lib + true + MachineX86 + + + true + $(ProjectDir)$(PlatformName)\$(ConfigurationName)\libpng.bsc + + + + + X64 + + + Disabled + ..\..;..\..\..\zlib;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;DEBUG;PNG_DEBUG=1;PNG_USE_PNGVCRD;PNG_LIBPNG_SPECIALBUILD;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + EnableFastChecks + MultiThreadedDebug + $(ProjectDir)$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + Level3 + true + ProgramDatabase + CompileAsC + 4267;%(DisableSpecificWarnings) + false + + + _DEBUG;%(PreprocessorDefinitions) + 0x0409 + + + $(ProjectDir)$(Platform)\$(Configuration)\libpng.lib + true + MachineX64 + + + true + $(ProjectDir)$(PlatformName)\$(ConfigurationName)\libpng.bsc + + + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + + + true + true + true + true + + + + + + + + + + true + %(PreprocessorDefinitions) + \Oogaland\Projects\orospakr.ca\srb2\tools\libpng-src\scripts;%(AdditionalIncludeDirectories) + true + %(PreprocessorDefinitions) + \Oogaland\Projects\orospakr.ca\srb2\tools\libpng-src\scripts;%(AdditionalIncludeDirectories) + true + %(PreprocessorDefinitions) + \Oogaland\Projects\orospakr.ca\srb2\tools\libpng-src\scripts;%(AdditionalIncludeDirectories) + true + %(PreprocessorDefinitions) + \Oogaland\Projects\orospakr.ca\srb2\tools\libpng-src\scripts;%(AdditionalIncludeDirectories) + + + + + {73a5729c-7323-41d4-ab48-8a03c9f81603} + false + + + + + + \ No newline at end of file diff --git a/libs/libpng-src/projects/visualc6/README.txt b/libs/libpng-src/projects/visualc6/README.txt new file mode 100644 index 000000000..d34980d57 --- /dev/null +++ b/libs/libpng-src/projects/visualc6/README.txt @@ -0,0 +1,57 @@ +Microsoft Developer Studio Project File, Format Version 6.00 for libpng. + +Copyright (C) 2000-2004 Simon-Pierre Cadieux. +Copyright (C) 2004 Cosmin Truta. +For conditions of distribution and use, see copyright notice in png.h + + +Assumptions: +* The libpng source files are in ..\.. +* The zlib source files are in ..\..\..\zlib +* The zlib project files are in ..\..\..\zlib\projects\visualc6 + + +To use: + +1) On the main menu, select "File | Open Workspace". + Open "libpng.dsw". + +2) Select "Build | Set Active Configuration". + Choose the configuration you wish to build. + (Choose libpng or pngtest; zlib will be built automatically.) + +3) Select "Build | Clean". + +4) Select "Build | Build ... (F7)". Ignore warning messages about + not being able to find certain include files (e.g. alloc.h). + +5) If you built the sample program (pngtest), + select "Build | Execute ... (Ctrl+F5)". + + +This project builds the libpng binaries as follows: + +* Win32_DLL_Release\libpng13.dll DLL build +* Win32_DLL_Debug\libpng13d.dll DLL build (debug version) +* Win32_DLL_ASM_Release\libpng13.dll DLL build using ASM code +* Win32_DLL_ASM_Debug\libpng13d.dll DLL build using ASM (debug version) +* Win32_DLL_VB\libpng13vb.dll DLL build for Visual Basic, using stdcall +* Win32_LIB_Release\libpng.lib static build +* Win32_LIB_Debug\libpngd.lib static build (debug version) +* Win32_LIB_ASM_Release\libpng.lib static build using ASM code +* Win32_LIB_ASM_Debug\libpngd.lib static build using ASM (debug version) + + +Notes: + +If you change anything in the source files, or select different compiler +settings, please change the DLL name to something different than any of +the above names. Also, make sure that in your "pngusr.h" you define +PNG_USER_PRIVATEBUILD and PNG_USER_DLLFNAME_POSTFIX according to the +instructions provided in "pngconf.h". + +All DLLs built by this project use the Microsoft dynamic C runtime library +MSVCRT.DLL (MSVCRTD.DLL for debug versions). If you distribute any of the +above mentioned libraries you should also include this DLL in your package. +For a list of files that are redistributable in Visual C++ 6.0, see +Common\Redist\Redist.txt on Disc 1 of the Visual C++ 6.0 product CDs. diff --git a/libs/libpng-src/projects/visualc6/libpng.dsp b/libs/libpng-src/projects/visualc6/libpng.dsp new file mode 100644 index 000000000..61ffd2ac8 --- /dev/null +++ b/libs/libpng-src/projects/visualc6/libpng.dsp @@ -0,0 +1,180 @@ +# Microsoft Developer Studio Project File - Name="libpng" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Static Library" 0x0104 + +CFG=libpng - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "libpng.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "libpng.mak" CFG="libpng - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "libpng - Win32 Release" (based on "Win32 (x86) Static Library") +!MESSAGE "libpng - Win32 Debug" (based on "Win32 (x86) Static Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "libpng - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "libpng___Win32_LIB_ASM_Release" +# PROP BASE Intermediate_Dir "libpng___Win32_LIB_ASM_Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Win32_LIB_ASM_Release" +# PROP Intermediate_Dir "Win32_LIB_ASM_Release" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c +# SUBTRACT BASE CPP /YX /Yc /Yu +# ADD CPP /nologo /W3 /O2 /I "..\.." /I "..\..\..\zlib" /D "WIN32" /D "NDEBUG" /D "PNG_USE_PNGVCRD" /D "PNG_LIBPNG_SPECIALBUILD" /D "_CRT_SECURE_NO_WARNINGS" /FD /c +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /i "..\.." /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LIB32=link.exe -lib +# ADD BASE LIB32 /nologo +# ADD LIB32 /nologo + +!ELSEIF "$(CFG)" == "libpng - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "libpng___Win32_LIB_ASM_Debug" +# PROP BASE Intermediate_Dir "libpng___Win32_LIB_ASM_Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Win32_LIB_ASM_Debug" +# PROP Intermediate_Dir "Win32_LIB_ASM_Debug" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c +# SUBTRACT BASE CPP /YX /Yc /Yu +# ADD CPP /nologo /W3 /Gm /ZI /Od /I "..\.." /I "..\..\..\zlib" /D "WIN32" /D "_DEBUG" /D "DEBUG" /D PNG_DEBUG=1 /D "PNG_USE_PNGVCRD" /D "PNG_LIBPNG_SPECIALBUILD" /D "_CRT_SECURE_NO_WARNINGS" /FD /GZ /c +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LIB32=link.exe -lib +# ADD BASE LIB32 /nologo +# ADD LIB32 /nologo + +!ENDIF + +# Begin Target + +# Name "libpng - Win32 Release" +# Name "libpng - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=..\..\png.c +# End Source File +# Begin Source File + +SOURCE=..\..\pngerror.c +# End Source File +# Begin Source File + +SOURCE=..\..\pngget.c +# End Source File +# Begin Source File + +SOURCE=..\..\pngmem.c +# End Source File +# Begin Source File + +SOURCE=..\..\pngpread.c +# End Source File +# Begin Source File + +SOURCE=..\..\pngread.c +# End Source File +# Begin Source File + +SOURCE=..\..\pngrio.c +# End Source File +# Begin Source File + +SOURCE=..\..\pngrtran.c +# End Source File +# Begin Source File + +SOURCE=..\..\pngrutil.c +# End Source File +# Begin Source File + +SOURCE=..\..\pngset.c +# End Source File +# Begin Source File + +SOURCE=..\..\pngtrans.c +# End Source File +# Begin Source File + +SOURCE=..\..\scripts\pngw32.def +# PROP Exclude_From_Build 1 +# End Source File +# Begin Source File + +SOURCE=..\..\pngwio.c +# End Source File +# Begin Source File + +SOURCE=..\..\pngwrite.c +# End Source File +# Begin Source File + +SOURCE=..\..\pngwtran.c +# End Source File +# Begin Source File + +SOURCE=..\..\pngwutil.c +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# Begin Source File + +SOURCE=..\..\png.h +# End Source File +# Begin Source File + +SOURCE=..\..\pngconf.h +# End Source File +# End Group +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# Begin Source File + +SOURCE=..\..\scripts\pngw32.rc +# PROP Exclude_From_Build 1 +# End Source File +# End Group +# Begin Source File + +SOURCE=.\README.txt +# End Source File +# End Target +# End Project diff --git a/libs/libpng-src/projects/visualc6/libpng.dsw b/libs/libpng-src/projects/visualc6/libpng.dsw new file mode 100644 index 000000000..2a9864674 --- /dev/null +++ b/libs/libpng-src/projects/visualc6/libpng.dsw @@ -0,0 +1,59 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00 +# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! + +############################################################################### + +Project: "libpng"=".\libpng.dsp" - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ + Begin Project Dependency + Project_Dep_Name zlib + End Project Dependency +}}} + +############################################################################### + +Project: "pngtest"=".\pngtest.dsp" - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ + Begin Project Dependency + Project_Dep_Name libpng + End Project Dependency +}}} + +############################################################################### + +Project: "zlib"="..\..\..\zlib\projects\visualc6\zlib.dsp" - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/libs/libpng-src/projects/visualc6/pngtest.dsp b/libs/libpng-src/projects/visualc6/pngtest.dsp new file mode 100644 index 000000000..2e5845c95 --- /dev/null +++ b/libs/libpng-src/projects/visualc6/pngtest.dsp @@ -0,0 +1,314 @@ +# Microsoft Developer Studio Project File - Name="pngtest" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=pngtest - Win32 DLL Release +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "pngtest.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "pngtest.mak" CFG="pngtest - Win32 DLL Release" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "pngtest - Win32 DLL Release" (based on "Win32 (x86) Console Application") +!MESSAGE "pngtest - Win32 DLL Debug" (based on "Win32 (x86) Console Application") +!MESSAGE "pngtest - Win32 DLL ASM Release" (based on "Win32 (x86) Console Application") +!MESSAGE "pngtest - Win32 DLL ASM Debug" (based on "Win32 (x86) Console Application") +!MESSAGE "pngtest - Win32 LIB Release" (based on "Win32 (x86) Console Application") +!MESSAGE "pngtest - Win32 LIB Debug" (based on "Win32 (x86) Console Application") +!MESSAGE "pngtest - Win32 LIB ASM Release" (based on "Win32 (x86) Console Application") +!MESSAGE "pngtest - Win32 LIB ASM Debug" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "pngtest - Win32 DLL Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "pngtest___Win32_DLL_Release" +# PROP BASE Intermediate_Dir "pngtest___Win32_DLL_Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Win32_DLL_Release" +# PROP Intermediate_Dir "Win32_DLL_Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c +# SUBTRACT BASE CPP /YX +# ADD CPP /nologo /MD /W3 /O2 /I "..\..\..\zlib" /D "WIN32" /D "NDEBUG" /D "PNG_DLL" /D "PNG_NO_STDIO" /D "PNG_NO_GLOBAL_ARRAYS" /FD /c +# SUBTRACT CPP /YX +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 /nologo /subsystem:console /machine:I386 +# ADD LINK32 Win32_DLL_Release\libpng13.lib ..\..\..\zlib\projects\visualc6\Win32_DLL_Release\zlib1.lib /nologo /subsystem:console /machine:I386 +# Begin Special Build Tool +OutDir=.\Win32_DLL_Release +SOURCE="$(InputPath)" +PostBuild_Desc=[Run Test] +PostBuild_Cmds=set path=$(outdir);..\..\..\zlib\projects\visualc6\Win32_DLL_Release; $(outdir)\pngtest.exe ..\..\pngtest.png +# End Special Build Tool + +!ELSEIF "$(CFG)" == "pngtest - Win32 DLL Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "pngtest___Win32_DLL_Debug" +# PROP BASE Intermediate_Dir "pngtest___Win32_DLL_Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Win32_DLL_Debug" +# PROP Intermediate_Dir "Win32_DLL_Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c +# SUBTRACT BASE CPP /YX +# ADD CPP /nologo /MDd /W3 /Gm /ZI /Od /I "..\..\..\zlib" /D "WIN32" /D "_DEBUG" /D "PNG_DLL" /D "PNG_NO_STDIO" /D "PNG_NO_GLOBAL_ARRAYS" /FD /GZ /c +# SUBTRACT CPP /YX +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 Win32_DLL_Debug\libpng13d.lib ..\..\..\zlib\projects\visualc6\Win32_DLL_Debug\zlib1d.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# Begin Special Build Tool +OutDir=.\Win32_DLL_Debug +SOURCE="$(InputPath)" +PostBuild_Desc=[Run Test] +PostBuild_Cmds=set path=$(outdir);..\..\..\zlib\projects\visualc6\Win32_DLL_Debug; $(outdir)\pngtest.exe ..\..\pngtest.png +# End Special Build Tool + +!ELSEIF "$(CFG)" == "pngtest - Win32 DLL ASM Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "pngtest___Win32_DLL_ASM_Release" +# PROP BASE Intermediate_Dir "pngtest___Win32_DLL_ASM_Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Win32_DLL_ASM_Release" +# PROP Intermediate_Dir "Win32_DLL_ASM_Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c +# SUBTRACT BASE CPP /YX +# ADD CPP /nologo /MD /W3 /O2 /I "..\..\..\zlib" /D "WIN32" /D "NDEBUG" /D "PNG_DLL" /D "PNG_NO_STDIO" /D "PNG_NO_GLOBAL_ARRAYS" /FD /c +# SUBTRACT CPP /YX +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 /nologo /subsystem:console /machine:I386 +# ADD LINK32 Win32_DLL_ASM_Release\libpng13.lib ..\..\..\zlib\projects\visualc6\Win32_DLL_ASM_Release\zlib1.lib /nologo /subsystem:console /machine:I386 +# Begin Special Build Tool +OutDir=.\Win32_DLL_ASM_Release +SOURCE="$(InputPath)" +PostBuild_Desc=[Run Test] +PostBuild_Cmds=set path=$(outdir);..\..\..\zlib\projects\visualc6\Win32_DLL_ASM_Release; $(outdir)\pngtest.exe ..\..\pngtest.png +# End Special Build Tool + +!ELSEIF "$(CFG)" == "pngtest - Win32 DLL ASM Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "pngtest___Win32_DLL_ASM_Debug" +# PROP BASE Intermediate_Dir "pngtest___Win32_DLL_ASM_Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Win32_DLL_ASM_Debug" +# PROP Intermediate_Dir "Win32_DLL_ASM_Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c +# SUBTRACT BASE CPP /YX +# ADD CPP /nologo /MDd /W3 /Gm /ZI /Od /I "..\..\..\zlib" /D "WIN32" /D "_DEBUG" /D "PNG_DLL" /D "PNG_NO_STDIO" /D "PNG_NO_GLOBAL_ARRAYS" /FD /GZ /c +# SUBTRACT CPP /YX +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 Win32_DLL_ASM_Debug\libpng13d.lib ..\..\..\zlib\projects\visualc6\Win32_DLL_ASM_Debug\zlib1d.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# Begin Special Build Tool +OutDir=.\Win32_DLL_ASM_Debug +SOURCE="$(InputPath)" +PostBuild_Desc=[Run Test] +PostBuild_Cmds=set path=$(outdir);..\..\..\zlib\projects\visualc6\Win32_DLL_ASM_Debug; $(outdir)\pngtest.exe ..\..\pngtest.png +# End Special Build Tool + +!ELSEIF "$(CFG)" == "pngtest - Win32 LIB Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "pngtest___Win32_LIB_Release" +# PROP BASE Intermediate_Dir "pngtest___Win32_LIB_Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Win32_LIB_Release" +# PROP Intermediate_Dir "Win32_LIB_Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c +# SUBTRACT BASE CPP /YX +# ADD CPP /nologo /MD /W3 /O2 /I "..\..\..\zlib" /D "WIN32" /D "NDEBUG" /FD /c +# SUBTRACT CPP /YX +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 /nologo /subsystem:console /machine:I386 +# ADD LINK32 Win32_LIB_Release\libpng.lib ..\..\..\zlib\projects\visualc6\Win32_LIB_Release\zlib.lib /nologo /subsystem:console /machine:I386 +# Begin Special Build Tool +OutDir=.\Win32_LIB_Release +SOURCE="$(InputPath)" +PostBuild_Desc=[Run Test] +PostBuild_Cmds=$(outdir)\pngtest.exe ..\..\pngtest.png +# End Special Build Tool + +!ELSEIF "$(CFG)" == "pngtest - Win32 LIB Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "pngtest___Win32_LIB_Debug" +# PROP BASE Intermediate_Dir "pngtest___Win32_LIB_Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Win32_LIB_Debug" +# PROP Intermediate_Dir "Win32_LIB_Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c +# SUBTRACT BASE CPP /YX +# ADD CPP /nologo /MDd /W3 /Gm /ZI /Od /I "..\..\..\zlib" /D "WIN32" /D "_DEBUG" /FD /GZ /c +# SUBTRACT CPP /YX +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 Win32_LIB_Debug\libpngd.lib ..\..\..\zlib\projects\visualc6\Win32_LIB_Debug\zlibd.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# Begin Special Build Tool +OutDir=.\Win32_LIB_Debug +SOURCE="$(InputPath)" +PostBuild_Desc=[Run Test] +PostBuild_Cmds=$(outdir)\pngtest.exe ..\..\pngtest.png +# End Special Build Tool + +!ELSEIF "$(CFG)" == "pngtest - Win32 LIB ASM Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "pngtest___Win32_LIB_ASM_Release" +# PROP BASE Intermediate_Dir "pngtest___Win32_LIB_ASM_Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Win32_LIB_ASM_Release" +# PROP Intermediate_Dir "Win32_LIB_ASM_Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c +# SUBTRACT BASE CPP /YX +# ADD CPP /nologo /MD /W3 /O2 /I "..\..\..\zlib" /D "WIN32" /D "NDEBUG" /FD /c +# SUBTRACT CPP /YX +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 /nologo /subsystem:console /machine:I386 +# ADD LINK32 Win32_LIB_ASM_Release\libpng.lib ..\..\..\zlib\projects\visualc6\Win32_LIB_ASM_Release\zlib.lib /nologo /subsystem:console /machine:I386 +# Begin Special Build Tool +OutDir=.\Win32_LIB_ASM_Release +SOURCE="$(InputPath)" +PostBuild_Desc=[Run Test] +PostBuild_Cmds=$(outdir)\pngtest.exe ..\..\pngtest.png +# End Special Build Tool + +!ELSEIF "$(CFG)" == "pngtest - Win32 LIB ASM Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "pngtest___Win32_LIB_ASM_Debug" +# PROP BASE Intermediate_Dir "pngtest___Win32_LIB_ASM_Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Win32_LIB_ASM_Debug" +# PROP Intermediate_Dir "Win32_LIB_ASM_Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c +# SUBTRACT BASE CPP /YX +# ADD CPP /nologo /MDd /W3 /Gm /ZI /Od /I "..\..\..\zlib" /D "WIN32" /D "_DEBUG" /FD /GZ /c +# SUBTRACT CPP /YX +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 Win32_LIB_ASM_Debug\libpngd.lib ..\..\..\zlib\projects\visualc6\Win32_LIB_ASM_Debug\zlibd.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# Begin Special Build Tool +OutDir=.\Win32_LIB_ASM_Debug +SOURCE="$(InputPath)" +PostBuild_Desc=[Run Test] +PostBuild_Cmds=$(outdir)\pngtest.exe ..\..\pngtest.png +# End Special Build Tool + +!ENDIF + +# Begin Target + +# Name "pngtest - Win32 DLL Release" +# Name "pngtest - Win32 DLL Debug" +# Name "pngtest - Win32 DLL ASM Release" +# Name "pngtest - Win32 DLL ASM Debug" +# Name "pngtest - Win32 LIB Release" +# Name "pngtest - Win32 LIB Debug" +# Name "pngtest - Win32 LIB ASM Release" +# Name "pngtest - Win32 LIB ASM Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=..\..\pngtest.c +# End Source File +# End Group +# End Target +# End Project diff --git a/libs/libpng-src/projects/visualc71/PRJ0041.mak b/libs/libpng-src/projects/visualc71/PRJ0041.mak new file mode 100644 index 000000000..a1f166d66 --- /dev/null +++ b/libs/libpng-src/projects/visualc71/PRJ0041.mak @@ -0,0 +1,21 @@ +# Prevent "Cannot find missing dependency..." warnings while compiling +# pngw32.rc (PRJ0041). + +all: $(IntDir)\alloc.h \ + $(IntDir)\fp.h \ + $(IntDir)\m68881.h \ + $(IntDir)\mem.h \ + $(IntDir)\pngusr.h \ + $(IntDir)\strings.h \ + $(IntDir)\unistd.h \ + $(IntDir)\unixio.h + +$(IntDir)\alloc.h \ +$(IntDir)\fp.h \ +$(IntDir)\m68881.h \ +$(IntDir)\mem.h \ +$(IntDir)\pngusr.h \ +$(IntDir)\strings.h \ +$(IntDir)\unistd.h \ +$(IntDir)\unixio.h: + @!echo.>$@ diff --git a/libs/libpng-src/projects/visualc71/README.txt b/libs/libpng-src/projects/visualc71/README.txt new file mode 100644 index 000000000..7bd63327e --- /dev/null +++ b/libs/libpng-src/projects/visualc71/README.txt @@ -0,0 +1,57 @@ +Microsoft Developer Studio Project File, Format Version 7.10 for libpng. + +Copyright (C) 2004 Simon-Pierre Cadieux. +For conditions of distribution and use, see copyright notice in png.h + +Assumptions: +* The libpng source files are in ..\.. +* The zlib source files are in ..\..\..\zlib +* The zlib project file is in . /* Warning: This is until the zlib project + files get intergrated into the next zlib release. The final zlib project + directory will then be ..\..\..\zlib\projects\visualc71. */ + +To use: + +1) On the main menu, select "File | Open Solution". + Open "libpng.sln". + +2) Display the Solution Explorer view (Ctrl+Alt+L) + +3) Set one of the project as the StartUp project. If you just want to build the + binaries set "libpng" as the startup project (Select "libpng" tree view + item + Project | Set as StartUp project). If you want to build and test the + binaries set it to "pngtest" (Select "pngtest" tree view item + + Project | Set as StartUp project) + +4) Select "Build | Configuration Manager...". + Choose the configuration you wish to build. + +5) Select "Build | Clean Solution". + +6) Select "Build | Build Solution (Ctrl-Shift-B)" + +This project builds the libpng binaries as follows: + +* Win32_DLL_Release\libpng13.dll DLL build +* Win32_DLL_Debug\libpng13d.dll DLL build (debug version) +* Win32_DLL_ASM_Release\libpng13.dll DLL build using ASM code +* Win32_DLL_ASM_Debug\libpng13d.dll DLL build using ASM (debug version) +* Win32_DLL_VB\libpng13vb.dll DLL build for Visual Basic, using stdcall +* Win32_LIB_Release\libpng.lib static build +* Win32_LIB_Debug\libpngd.lib static build (debug version) +* Win32_LIB_ASM_Release\libpng.lib static build using ASM code +* Win32_LIB_ASM_Debug\libpngd.lib static build using ASM (debug version) + +Notes: + +If you change anything in the source files, or select different compiler +settings, please change the DLL name to something different than any of +the above names. Also, make sure that in your "pngusr.h" you define +PNG_USER_PRIVATEBUILD and PNG_USER_DLLFNAME_POSTFIX according to the +instructions provided in "pngconf.h". + +All DLLs built by this project use the Microsoft dynamic C runtime library +MSVCR71.DLL (MSVCR71D.DLL for debug versions). If you distribute any of the +above mentioned libraries you may have to include this DLL in your package. +For a list of files that are redistributable in Visual Studio see +$(VCINSTALLDIR)\redist.txt. diff --git a/libs/libpng-src/projects/visualc71/README_zlib.txt b/libs/libpng-src/projects/visualc71/README_zlib.txt new file mode 100644 index 000000000..ff6a5c7cb --- /dev/null +++ b/libs/libpng-src/projects/visualc71/README_zlib.txt @@ -0,0 +1,44 @@ +/* WARNING: This file was put in the LibPNG distribution for convenience only. + It is expected to be part of the next zlib release under + "projects\visualc71\README.txt." */ + +Microsoft Developer Studio Project File, Format Version 7.10 for zlib. + +Copyright (C) 2004 Simon-Pierre Cadieux. +Copyright (C) 2004 Cosmin Truta. +For conditions of distribution and use, see copyright notice in zlib.h. + + +To use: + +1) On the main menu, select "File | Open Solution". + Open "zlib.sln". + +2) Display the Solution Explorer view (Ctrl+Alt+L) + +3) Set one of the project as the StartUp project. If you just want to build the + binaries set "zlib" as the startup project (Select "zlib" tree view item + + Project | Set as StartUp project). If you want to build and test the + binaries set it to "example" (Select "example" tree view item + Project | + Set as StartUp project), If you want to build the minigzip utility set it to + "minigzip" (Select "minigzip" tree view item + Project | Set as StartUp + project + +4) Select "Build | Configuration Manager...". + Choose the configuration you wish to build. + +5) Select "Build | Clean Solution". + +6) Select "Build | Build Solution (Ctrl-Shift-B)" + +This project builds the zlib binaries as follows: + +* Win32_DLL_Release\zlib1.dll DLL build +* Win32_DLL_Debug\zlib1d.dll DLL build (debug version) +* Win32_DLL_ASM_Release\zlib1.dll DLL build using ASM code +* Win32_DLL_ASM_Debug\zlib1d.dll DLL build using ASM code (debug version) +* Win32_LIB_Release\zlib.lib static build +* Win32_LIB_Debug\zlibd.lib static build (debug version) +* Win32_LIB_ASM_Release\zlib.lib static build using ASM code +* Win32_LIB_ASM_Debug\zlibd.lib static build using ASM code (debug version) + diff --git a/libs/libpng-src/projects/visualc71/libpng.sln b/libs/libpng-src/projects/visualc71/libpng.sln new file mode 100644 index 000000000..7f75b0c6b --- /dev/null +++ b/libs/libpng-src/projects/visualc71/libpng.sln @@ -0,0 +1,88 @@ +Microsoft Visual Studio Solution File, Format Version 8.00 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libpng", "libpng.vcproj", "{0008960E-E0DD-41A6-8265-00B31DDB4C21}" + ProjectSection(ProjectDependencies) = postProject + {2D4F8105-7D21-454C-9932-B47CAB71A5C0} = {2D4F8105-7D21-454C-9932-B47CAB71A5C0} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pngtest", "pngtest.vcproj", "{FD1C2F86-9EEF-47BD-95A4-530917E17FDA}" + ProjectSection(ProjectDependencies) = postProject + {0008960E-E0DD-41A6-8265-00B31DDB4C21} = {0008960E-E0DD-41A6-8265-00B31DDB4C21} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlib", "zlib.vcproj", "{2D4F8105-7D21-454C-9932-B47CAB71A5C0}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfiguration) = preSolution + DLL ASM Debug = DLL ASM Debug + DLL ASM Release = DLL ASM Release + DLL Debug = DLL Debug + DLL Release = DLL Release + DLL VB = DLL VB + LIB ASM Debug = LIB ASM Debug + LIB ASM Release = LIB ASM Release + LIB Debug = LIB Debug + LIB Release = LIB Release + EndGlobalSection + GlobalSection(ProjectConfiguration) = postSolution + {0008960E-E0DD-41A6-8265-00B31DDB4C21}.DLL ASM Debug.ActiveCfg = DLL ASM Debug|Win32 + {0008960E-E0DD-41A6-8265-00B31DDB4C21}.DLL ASM Debug.Build.0 = DLL ASM Debug|Win32 + {0008960E-E0DD-41A6-8265-00B31DDB4C21}.DLL ASM Release.ActiveCfg = DLL ASM Release|Win32 + {0008960E-E0DD-41A6-8265-00B31DDB4C21}.DLL ASM Release.Build.0 = DLL ASM Release|Win32 + {0008960E-E0DD-41A6-8265-00B31DDB4C21}.DLL Debug.ActiveCfg = DLL Debug|Win32 + {0008960E-E0DD-41A6-8265-00B31DDB4C21}.DLL Debug.Build.0 = DLL Debug|Win32 + {0008960E-E0DD-41A6-8265-00B31DDB4C21}.DLL Release.ActiveCfg = DLL Release|Win32 + {0008960E-E0DD-41A6-8265-00B31DDB4C21}.DLL Release.Build.0 = DLL Release|Win32 + {0008960E-E0DD-41A6-8265-00B31DDB4C21}.DLL VB.ActiveCfg = DLL VB|Win32 + {0008960E-E0DD-41A6-8265-00B31DDB4C21}.DLL VB.Build.0 = DLL VB|Win32 + {0008960E-E0DD-41A6-8265-00B31DDB4C21}.LIB ASM Debug.ActiveCfg = LIB ASM Debug|Win32 + {0008960E-E0DD-41A6-8265-00B31DDB4C21}.LIB ASM Debug.Build.0 = LIB ASM Debug|Win32 + {0008960E-E0DD-41A6-8265-00B31DDB4C21}.LIB ASM Release.ActiveCfg = LIB ASM Release|Win32 + {0008960E-E0DD-41A6-8265-00B31DDB4C21}.LIB ASM Release.Build.0 = LIB ASM Release|Win32 + {0008960E-E0DD-41A6-8265-00B31DDB4C21}.LIB Debug.ActiveCfg = LIB Debug|Win32 + {0008960E-E0DD-41A6-8265-00B31DDB4C21}.LIB Debug.Build.0 = LIB Debug|Win32 + {0008960E-E0DD-41A6-8265-00B31DDB4C21}.LIB Release.ActiveCfg = LIB Release|Win32 + {0008960E-E0DD-41A6-8265-00B31DDB4C21}.LIB Release.Build.0 = LIB Release|Win32 + {FD1C2F86-9EEF-47BD-95A4-530917E17FDA}.DLL ASM Debug.ActiveCfg = DLL ASM Debug|Win32 + {FD1C2F86-9EEF-47BD-95A4-530917E17FDA}.DLL ASM Debug.Build.0 = DLL ASM Debug|Win32 + {FD1C2F86-9EEF-47BD-95A4-530917E17FDA}.DLL ASM Release.ActiveCfg = DLL ASM Release|Win32 + {FD1C2F86-9EEF-47BD-95A4-530917E17FDA}.DLL ASM Release.Build.0 = DLL ASM Release|Win32 + {FD1C2F86-9EEF-47BD-95A4-530917E17FDA}.DLL Debug.ActiveCfg = DLL Debug|Win32 + {FD1C2F86-9EEF-47BD-95A4-530917E17FDA}.DLL Debug.Build.0 = DLL Debug|Win32 + {FD1C2F86-9EEF-47BD-95A4-530917E17FDA}.DLL Release.ActiveCfg = DLL Release|Win32 + {FD1C2F86-9EEF-47BD-95A4-530917E17FDA}.DLL Release.Build.0 = DLL Release|Win32 + {FD1C2F86-9EEF-47BD-95A4-530917E17FDA}.DLL VB.ActiveCfg = DLL VB|Win32 + {FD1C2F86-9EEF-47BD-95A4-530917E17FDA}.DLL VB.Build.0 = DLL VB|Win32 + {FD1C2F86-9EEF-47BD-95A4-530917E17FDA}.LIB ASM Debug.ActiveCfg = LIB ASM Debug|Win32 + {FD1C2F86-9EEF-47BD-95A4-530917E17FDA}.LIB ASM Debug.Build.0 = LIB ASM Debug|Win32 + {FD1C2F86-9EEF-47BD-95A4-530917E17FDA}.LIB ASM Release.ActiveCfg = LIB ASM Release|Win32 + {FD1C2F86-9EEF-47BD-95A4-530917E17FDA}.LIB ASM Release.Build.0 = LIB ASM Release|Win32 + {FD1C2F86-9EEF-47BD-95A4-530917E17FDA}.LIB Debug.ActiveCfg = LIB Debug|Win32 + {FD1C2F86-9EEF-47BD-95A4-530917E17FDA}.LIB Debug.Build.0 = LIB Debug|Win32 + {FD1C2F86-9EEF-47BD-95A4-530917E17FDA}.LIB Release.ActiveCfg = LIB Release|Win32 + {FD1C2F86-9EEF-47BD-95A4-530917E17FDA}.LIB Release.Build.0 = LIB Release|Win32 + {2D4F8105-7D21-454C-9932-B47CAB71A5C0}.DLL ASM Debug.ActiveCfg = DLL ASM Debug|Win32 + {2D4F8105-7D21-454C-9932-B47CAB71A5C0}.DLL ASM Debug.Build.0 = DLL ASM Debug|Win32 + {2D4F8105-7D21-454C-9932-B47CAB71A5C0}.DLL ASM Release.ActiveCfg = DLL ASM Release|Win32 + {2D4F8105-7D21-454C-9932-B47CAB71A5C0}.DLL ASM Release.Build.0 = DLL ASM Release|Win32 + {2D4F8105-7D21-454C-9932-B47CAB71A5C0}.DLL Debug.ActiveCfg = DLL Debug|Win32 + {2D4F8105-7D21-454C-9932-B47CAB71A5C0}.DLL Debug.Build.0 = DLL Debug|Win32 + {2D4F8105-7D21-454C-9932-B47CAB71A5C0}.DLL Release.ActiveCfg = DLL Release|Win32 + {2D4F8105-7D21-454C-9932-B47CAB71A5C0}.DLL Release.Build.0 = DLL Release|Win32 + {2D4F8105-7D21-454C-9932-B47CAB71A5C0}.DLL VB.ActiveCfg = DLL Release|Win32 + {2D4F8105-7D21-454C-9932-B47CAB71A5C0}.DLL VB.Build.0 = DLL Release|Win32 + {2D4F8105-7D21-454C-9932-B47CAB71A5C0}.LIB ASM Debug.ActiveCfg = LIB ASM Debug|Win32 + {2D4F8105-7D21-454C-9932-B47CAB71A5C0}.LIB ASM Debug.Build.0 = LIB ASM Debug|Win32 + {2D4F8105-7D21-454C-9932-B47CAB71A5C0}.LIB ASM Release.ActiveCfg = LIB ASM Release|Win32 + {2D4F8105-7D21-454C-9932-B47CAB71A5C0}.LIB ASM Release.Build.0 = LIB ASM Release|Win32 + {2D4F8105-7D21-454C-9932-B47CAB71A5C0}.LIB Debug.ActiveCfg = LIB Debug|Win32 + {2D4F8105-7D21-454C-9932-B47CAB71A5C0}.LIB Debug.Build.0 = LIB Debug|Win32 + {2D4F8105-7D21-454C-9932-B47CAB71A5C0}.LIB Release.ActiveCfg = LIB Release|Win32 + {2D4F8105-7D21-454C-9932-B47CAB71A5C0}.LIB Release.Build.0 = LIB Release|Win32 + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + EndGlobalSection + GlobalSection(ExtensibilityAddIns) = postSolution + EndGlobalSection +EndGlobal diff --git a/libs/libpng-src/projects/visualc71/libpng.vcproj b/libs/libpng-src/projects/visualc71/libpng.vcproj new file mode 100644 index 000000000..794e289d8 --- /dev/null +++ b/libs/libpng-src/projects/visualc71/libpng.vcproj @@ -0,0 +1,702 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/libpng-src/projects/visualc71/pngtest.vcproj b/libs/libpng-src/projects/visualc71/pngtest.vcproj new file mode 100644 index 000000000..210566c5a --- /dev/null +++ b/libs/libpng-src/projects/visualc71/pngtest.vcproj @@ -0,0 +1,459 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/libpng-src/projects/visualc71/zlib.vcproj b/libs/libpng-src/projects/visualc71/zlib.vcproj new file mode 100644 index 000000000..bc0a2bf33 --- /dev/null +++ b/libs/libpng-src/projects/visualc71/zlib.vcproj @@ -0,0 +1,670 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/libpng-src/projects/visualc9/.gitignore b/libs/libpng-src/projects/visualc9/.gitignore new file mode 100644 index 000000000..118a15cbb --- /dev/null +++ b/libs/libpng-src/projects/visualc9/.gitignore @@ -0,0 +1,3 @@ +/Win32 +/x64 +/libpng.vcproj.*.*.user diff --git a/libs/libpng-src/projects/visualc9/libpng.vcproj b/libs/libpng-src/projects/visualc9/libpng.vcproj new file mode 100644 index 000000000..ce337e5ea --- /dev/null +++ b/libs/libpng-src/projects/visualc9/libpng.vcproj @@ -0,0 +1,1039 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/libpng-src/projects/wince.txt b/libs/libpng-src/projects/wince.txt new file mode 100644 index 000000000..b35e101a7 --- /dev/null +++ b/libs/libpng-src/projects/wince.txt @@ -0,0 +1,6 @@ +A set of project files is available for WinCE. Get +libpng-1.2.46-project-wince.zip from a libpng distribution +site such as http://libpng.sourceforge.net/index.html + +Put the zip file in this directory (projects) and then run +"unzip -a libpng-1.2.46-project-wince.zip" diff --git a/libs/libpng-src/projects/xcode/Info.plist b/libs/libpng-src/projects/xcode/Info.plist new file mode 100644 index 000000000..0b525dfff --- /dev/null +++ b/libs/libpng-src/projects/xcode/Info.plist @@ -0,0 +1,26 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleExecutable + libpng + CFBundleIconFile + + CFBundleIdentifier + com.apple.carbonframeworktemplate + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + FMWK + CFBundleSignature + ???? + CFBundleVersion + 1.0 + CFBundleShortVersionString + 1.0 + CSResourcesFileMapped + + + diff --git a/libs/libpng-src/projects/xcode/libpng.xcodeproj/.gitignore b/libs/libpng-src/projects/xcode/libpng.xcodeproj/.gitignore new file mode 100644 index 000000000..0a2b14bae --- /dev/null +++ b/libs/libpng-src/projects/xcode/libpng.xcodeproj/.gitignore @@ -0,0 +1,2 @@ +*.mode1* +*.pbxuser diff --git a/libs/libpng-src/projects/xcode/libpng.xcodeproj/project.pbxproj b/libs/libpng-src/projects/xcode/libpng.xcodeproj/project.pbxproj new file mode 100644 index 000000000..0c6a1e4e2 --- /dev/null +++ b/libs/libpng-src/projects/xcode/libpng.xcodeproj/project.pbxproj @@ -0,0 +1,349 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 44; + objects = { + +/* Begin PBXBuildFile section */ + 14461C7109C3C37F005840C0 /* png.c in Sources */ = {isa = PBXBuildFile; fileRef = 14461C5D09C3C37F005840C0 /* png.c */; }; + 14461C7209C3C37F005840C0 /* png.h in Headers */ = {isa = PBXBuildFile; fileRef = 14461C5E09C3C37F005840C0 /* png.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 14461C7309C3C37F005840C0 /* pngconf.h in Headers */ = {isa = PBXBuildFile; fileRef = 14461C5F09C3C37F005840C0 /* pngconf.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 14461C7409C3C37F005840C0 /* pngerror.c in Sources */ = {isa = PBXBuildFile; fileRef = 14461C6009C3C37F005840C0 /* pngerror.c */; }; + 14461C7509C3C37F005840C0 /* pnggccrd.c in Sources */ = {isa = PBXBuildFile; fileRef = 14461C6109C3C37F005840C0 /* pnggccrd.c */; }; + 14461C7609C3C37F005840C0 /* pngget.c in Sources */ = {isa = PBXBuildFile; fileRef = 14461C6209C3C37F005840C0 /* pngget.c */; }; + 14461C7709C3C37F005840C0 /* pngmem.c in Sources */ = {isa = PBXBuildFile; fileRef = 14461C6309C3C37F005840C0 /* pngmem.c */; }; + 14461C7809C3C37F005840C0 /* pngpread.c in Sources */ = {isa = PBXBuildFile; fileRef = 14461C6409C3C37F005840C0 /* pngpread.c */; }; + 14461C7909C3C37F005840C0 /* pngread.c in Sources */ = {isa = PBXBuildFile; fileRef = 14461C6509C3C37F005840C0 /* pngread.c */; }; + 14461C7A09C3C37F005840C0 /* pngrio.c in Sources */ = {isa = PBXBuildFile; fileRef = 14461C6609C3C37F005840C0 /* pngrio.c */; }; + 14461C7B09C3C37F005840C0 /* pngrtran.c in Sources */ = {isa = PBXBuildFile; fileRef = 14461C6709C3C37F005840C0 /* pngrtran.c */; }; + 14461C7C09C3C37F005840C0 /* pngrutil.c in Sources */ = {isa = PBXBuildFile; fileRef = 14461C6809C3C37F005840C0 /* pngrutil.c */; }; + 14461C7D09C3C37F005840C0 /* pngset.c in Sources */ = {isa = PBXBuildFile; fileRef = 14461C6909C3C37F005840C0 /* pngset.c */; }; + 14461C7F09C3C37F005840C0 /* pngtrans.c in Sources */ = {isa = PBXBuildFile; fileRef = 14461C6B09C3C37F005840C0 /* pngtrans.c */; }; + 14461C8009C3C37F005840C0 /* pngvcrd.c in Sources */ = {isa = PBXBuildFile; fileRef = 14461C6C09C3C37F005840C0 /* pngvcrd.c */; }; + 14461C8109C3C37F005840C0 /* pngwio.c in Sources */ = {isa = PBXBuildFile; fileRef = 14461C6D09C3C37F005840C0 /* pngwio.c */; }; + 14461C8209C3C37F005840C0 /* pngwrite.c in Sources */ = {isa = PBXBuildFile; fileRef = 14461C6E09C3C37F005840C0 /* pngwrite.c */; }; + 14461C8309C3C37F005840C0 /* pngwtran.c in Sources */ = {isa = PBXBuildFile; fileRef = 14461C6F09C3C37F005840C0 /* pngwtran.c */; }; + 14461C8409C3C37F005840C0 /* pngwutil.c in Sources */ = {isa = PBXBuildFile; fileRef = 14461C7009C3C37F005840C0 /* pngwutil.c */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 14461C5D09C3C37F005840C0 /* png.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = png.c; path = ../../png.c; sourceTree = SOURCE_ROOT; }; + 14461C5E09C3C37F005840C0 /* png.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = png.h; path = ../../png.h; sourceTree = SOURCE_ROOT; }; + 14461C5F09C3C37F005840C0 /* pngconf.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = pngconf.h; path = ../../pngconf.h; sourceTree = SOURCE_ROOT; }; + 14461C6009C3C37F005840C0 /* pngerror.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = pngerror.c; path = ../../pngerror.c; sourceTree = SOURCE_ROOT; }; + 14461C6109C3C37F005840C0 /* pnggccrd.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = pnggccrd.c; path = ../../pnggccrd.c; sourceTree = SOURCE_ROOT; }; + 14461C6209C3C37F005840C0 /* pngget.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = pngget.c; path = ../../pngget.c; sourceTree = SOURCE_ROOT; }; + 14461C6309C3C37F005840C0 /* pngmem.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = pngmem.c; path = ../../pngmem.c; sourceTree = SOURCE_ROOT; }; + 14461C6409C3C37F005840C0 /* pngpread.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = pngpread.c; path = ../../pngpread.c; sourceTree = SOURCE_ROOT; }; + 14461C6509C3C37F005840C0 /* pngread.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = pngread.c; path = ../../pngread.c; sourceTree = SOURCE_ROOT; }; + 14461C6609C3C37F005840C0 /* pngrio.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = pngrio.c; path = ../../pngrio.c; sourceTree = SOURCE_ROOT; }; + 14461C6709C3C37F005840C0 /* pngrtran.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = pngrtran.c; path = ../../pngrtran.c; sourceTree = SOURCE_ROOT; }; + 14461C6809C3C37F005840C0 /* pngrutil.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = pngrutil.c; path = ../../pngrutil.c; sourceTree = SOURCE_ROOT; }; + 14461C6909C3C37F005840C0 /* pngset.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = pngset.c; path = ../../pngset.c; sourceTree = SOURCE_ROOT; }; + 14461C6B09C3C37F005840C0 /* pngtrans.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = pngtrans.c; path = ../../pngtrans.c; sourceTree = SOURCE_ROOT; }; + 14461C6C09C3C37F005840C0 /* pngvcrd.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = pngvcrd.c; path = ../../pngvcrd.c; sourceTree = SOURCE_ROOT; }; + 14461C6D09C3C37F005840C0 /* pngwio.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = pngwio.c; path = ../../pngwio.c; sourceTree = SOURCE_ROOT; }; + 14461C6E09C3C37F005840C0 /* pngwrite.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = pngwrite.c; path = ../../pngwrite.c; sourceTree = SOURCE_ROOT; }; + 14461C6F09C3C37F005840C0 /* pngwtran.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = pngwtran.c; path = ../../pngwtran.c; sourceTree = SOURCE_ROOT; }; + 14461C7009C3C37F005840C0 /* pngwutil.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = pngwutil.c; path = ../../pngwutil.c; sourceTree = SOURCE_ROOT; }; + 8D07F2C70486CC7A007CD1D0 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = Info.plist; sourceTree = ""; }; + 8D07F2C80486CC7A007CD1D0 /* libpng.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = libpng.framework; sourceTree = BUILT_PRODUCTS_DIR; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 8D07F2C30486CC7A007CD1D0 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 034768DDFF38A45A11DB9C8B /* Products */ = { + isa = PBXGroup; + children = ( + 8D07F2C80486CC7A007CD1D0 /* libpng.framework */, + ); + name = Products; + sourceTree = ""; + }; + 0867D691FE84028FC02AAC07 /* libpng */ = { + isa = PBXGroup; + children = ( + 08FB77ACFE841707C02AAC07 /* Source */, + 089C1665FE841158C02AAC07 /* Resources */, + 034768DDFF38A45A11DB9C8B /* Products */, + ); + name = libpng; + sourceTree = ""; + }; + 089C1665FE841158C02AAC07 /* Resources */ = { + isa = PBXGroup; + children = ( + 8D07F2C70486CC7A007CD1D0 /* Info.plist */, + ); + name = Resources; + sourceTree = ""; + }; + 08FB77ACFE841707C02AAC07 /* Source */ = { + isa = PBXGroup; + children = ( + 14461C5D09C3C37F005840C0 /* png.c */, + 14461C5E09C3C37F005840C0 /* png.h */, + 14461C5F09C3C37F005840C0 /* pngconf.h */, + 14461C6009C3C37F005840C0 /* pngerror.c */, + 14461C6109C3C37F005840C0 /* pnggccrd.c */, + 14461C6209C3C37F005840C0 /* pngget.c */, + 14461C6309C3C37F005840C0 /* pngmem.c */, + 14461C6409C3C37F005840C0 /* pngpread.c */, + 14461C6509C3C37F005840C0 /* pngread.c */, + 14461C6609C3C37F005840C0 /* pngrio.c */, + 14461C6709C3C37F005840C0 /* pngrtran.c */, + 14461C6809C3C37F005840C0 /* pngrutil.c */, + 14461C6909C3C37F005840C0 /* pngset.c */, + 14461C6B09C3C37F005840C0 /* pngtrans.c */, + 14461C6C09C3C37F005840C0 /* pngvcrd.c */, + 14461C6D09C3C37F005840C0 /* pngwio.c */, + 14461C6E09C3C37F005840C0 /* pngwrite.c */, + 14461C6F09C3C37F005840C0 /* pngwtran.c */, + 14461C7009C3C37F005840C0 /* pngwutil.c */, + ); + name = Source; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXHeadersBuildPhase section */ + 8D07F2BD0486CC7A007CD1D0 /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + 14461C7209C3C37F005840C0 /* png.h in Headers */, + 14461C7309C3C37F005840C0 /* pngconf.h in Headers */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXHeadersBuildPhase section */ + +/* Begin PBXNativeTarget section */ + 8D07F2BC0486CC7A007CD1D0 /* libpng */ = { + isa = PBXNativeTarget; + buildConfigurationList = 4FADC24208B4156D00ABE55E /* Build configuration list for PBXNativeTarget "libpng" */; + buildPhases = ( + 8D07F2BD0486CC7A007CD1D0 /* Headers */, + 8D07F2BF0486CC7A007CD1D0 /* Resources */, + 8D07F2C10486CC7A007CD1D0 /* Sources */, + 8D07F2C30486CC7A007CD1D0 /* Frameworks */, + 8D07F2C50486CC7A007CD1D0 /* Rez */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = libpng; + productInstallPath = "$(HOME)/Library/Frameworks"; + productName = libpng; + productReference = 8D07F2C80486CC7A007CD1D0 /* libpng.framework */; + productType = "com.apple.product-type.framework"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 0867D690FE84028FC02AAC07 /* Project object */ = { + isa = PBXProject; + buildConfigurationList = 4FADC24608B4156D00ABE55E /* Build configuration list for PBXProject "libpng" */; + compatibilityVersion = "Xcode 2.4"; + hasScannedForEncodings = 1; + mainGroup = 0867D691FE84028FC02AAC07 /* libpng */; + productRefGroup = 034768DDFF38A45A11DB9C8B /* Products */; + projectDirPath = ""; + projectRoot = ../..; + targets = ( + 8D07F2BC0486CC7A007CD1D0 /* libpng */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 8D07F2BF0486CC7A007CD1D0 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXRezBuildPhase section */ + 8D07F2C50486CC7A007CD1D0 /* Rez */ = { + isa = PBXRezBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXRezBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 8D07F2C10486CC7A007CD1D0 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 14461C7109C3C37F005840C0 /* png.c in Sources */, + 14461C7409C3C37F005840C0 /* pngerror.c in Sources */, + 14461C7509C3C37F005840C0 /* pnggccrd.c in Sources */, + 14461C7609C3C37F005840C0 /* pngget.c in Sources */, + 14461C7709C3C37F005840C0 /* pngmem.c in Sources */, + 14461C7809C3C37F005840C0 /* pngpread.c in Sources */, + 14461C7909C3C37F005840C0 /* pngread.c in Sources */, + 14461C7A09C3C37F005840C0 /* pngrio.c in Sources */, + 14461C7B09C3C37F005840C0 /* pngrtran.c in Sources */, + 14461C7C09C3C37F005840C0 /* pngrutil.c in Sources */, + 14461C7D09C3C37F005840C0 /* pngset.c in Sources */, + 14461C7F09C3C37F005840C0 /* pngtrans.c in Sources */, + 14461C8009C3C37F005840C0 /* pngvcrd.c in Sources */, + 14461C8109C3C37F005840C0 /* pngwio.c in Sources */, + 14461C8209C3C37F005840C0 /* pngwrite.c in Sources */, + 14461C8309C3C37F005840C0 /* pngwtran.c in Sources */, + 14461C8409C3C37F005840C0 /* pngwutil.c in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 4FADC24308B4156D00ABE55E /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + COPY_PHASE_STRIP = NO; + DYLIB_COMPATIBILITY_VERSION = 3; + DYLIB_CURRENT_VERSION = 3; + FRAMEWORK_VERSION = 1.2.46; + GCC_PRECOMPILE_PREFIX_HEADER = NO; + GCC_PREFIX_HEADER = ""; + INFOPLIST_FILE = Info.plist; + INSTALL_PATH = "@executable_path/../Frameworks"; + LIBRARY_STYLE = DYNAMIC; + MACH_O_TYPE = mh_dylib; + OTHER_LDFLAGS = "-lz"; + PRODUCT_NAME = libpng; + WRAPPER_EXTENSION = framework; + }; + name = Debug; + }; + 4FADC24408B4156D00ABE55E /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + DYLIB_COMPATIBILITY_VERSION = 3; + DYLIB_CURRENT_VERSION = 3; + FRAMEWORK_VERSION = 1.2.46; + GCC_PRECOMPILE_PREFIX_HEADER = NO; + GCC_PREFIX_HEADER = ""; + INFOPLIST_FILE = Info.plist; + INSTALL_PATH = "@executable_path/../Frameworks"; + LIBRARY_STYLE = DYNAMIC; + MACH_O_TYPE = mh_dylib; + OTHER_LDFLAGS = "-lz"; + PRODUCT_NAME = libpng; + WRAPPER_EXTENSION = framework; + }; + name = Release; + }; + 4FADC24708B4156D00ABE55E /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ARCHS = ( + i386, + ppc, + ppc64, + x86_64, + ); + DEPLOYMENT_POSTPROCESSING = YES; + GCC_ENABLE_CPP_EXCEPTIONS = NO; + GCC_ENABLE_CPP_RTTI = NO; + GCC_ENABLE_FIX_AND_CONTINUE = YES; + GCC_GENERATE_DEBUGGING_SYMBOLS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES; + GCC_VERSION_i386 = 4.0; + GCC_VERSION_ppc0 = 3.3; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.5; + "MACOSX_DEPLOYMENT_TARGET[arch=i386]" = 10.4; + "MACOSX_DEPLOYMENT_TARGET[arch=ppc]" = 10.2; + MACOSX_DEPLOYMENT_TARGET_i386 = 10.4; + MACOSX_DEPLOYMENT_TARGET_ppc = 10.2; + PREBINDING = NO; + SDKROOT = "$(DEVELOPER_SDK_DIR)/MacOSX10.5.sdk"; + "SDKROOT[arch=i386]" = "$(DEVELOPER_SDK_DIR)/MacOSX10.4u.sdk"; + "SDKROOT[arch=ppc]" = "$(DEVELOPER_SDK_DIR)/MacOSX10.3.9.sdk"; + SDKROOT_i386 = "$(DEVELOPER_SDK_DIR)/MacOSX10.4u.sdk"; + SDKROOT_ppc = "$(DEVELOPER_SDK_DIR)/MacOSX10.3.9.sdk"; + ZERO_LINK = NO; + }; + name = Debug; + }; + 4FADC24808B4156D00ABE55E /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ARCHS = ( + i386, + ppc, + ppc64, + x86_64, + ); + GCC_ENABLE_CPP_EXCEPTIONS = NO; + GCC_ENABLE_CPP_RTTI = NO; + GCC_ENABLE_FIX_AND_CONTINUE = NO; + GCC_GENERATE_DEBUGGING_SYMBOLS = NO; + GCC_OPTIMIZATION_LEVEL = 2; + GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES; + GCC_VERSION_i386 = 4.0; + GCC_VERSION_ppc0 = 3.3; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.5; + "MACOSX_DEPLOYMENT_TARGET[arch=i386]" = 10.4; + "MACOSX_DEPLOYMENT_TARGET[arch=ppc]" = 10.2; + MACOSX_DEPLOYMENT_TARGET_i386 = 10.4; + MACOSX_DEPLOYMENT_TARGET_ppc = 10.2; + PREBINDING = NO; + SDKROOT = "$(DEVELOPER_SDK_DIR)/MacOSX10.5.sdk"; + "SDKROOT[arch=i386]" = "$(DEVELOPER_SDK_DIR)/MacOSX10.4u.sdk"; + "SDKROOT[arch=ppc]" = "$(DEVELOPER_SDK_DIR)/MacOSX10.3.9.sdk"; + SDKROOT_i386 = "$(DEVELOPER_SDK_DIR)/MacOSX10.4u.sdk"; + SDKROOT_ppc = "$(DEVELOPER_SDK_DIR)/MacOSX10.3.9.sdk"; + ZERO_LINK = NO; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 4FADC24208B4156D00ABE55E /* Build configuration list for PBXNativeTarget "libpng" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 4FADC24308B4156D00ABE55E /* Debug */, + 4FADC24408B4156D00ABE55E /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 4FADC24608B4156D00ABE55E /* Build configuration list for PBXProject "libpng" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 4FADC24708B4156D00ABE55E /* Debug */, + 4FADC24808B4156D00ABE55E /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 0867D690FE84028FC02AAC07 /* Project object */; +} diff --git a/libs/libpng-src/scripts/README.txt b/libs/libpng-src/scripts/README.txt new file mode 100644 index 000000000..177b22cbd --- /dev/null +++ b/libs/libpng-src/scripts/README.txt @@ -0,0 +1,76 @@ + +Makefiles for libpng version 1.2.46 - July 9, 2011 + + makefile.linux => Linux/ELF makefile + (gcc, creates libpng12.so.0.1.2.46) + makefile.gcc => Generic makefile (gcc, creates static libpng.a) + makefile.knr => Archaic UNIX Makefile that converts files with + ansi2knr (Requires ansi2knr.c from + ftp://ftp.cs.wisc.edu/ghost) + makefile.acorn => Acorn makefile + makefile.aix => AIX/gcc makefile + makefile.amiga => Amiga makefile + makefile.atari => Atari makefile + makefile.bc32 => 32-bit Borland C++ (all modules compiled in C mode) + makefile.beos => beos makefile + makefile.bor => Borland makefile (uses bcc) + makefile.cegcc => minge32ce for Windows CE makefile + makefile.cygwin => Cygwin/gcc makefile + makefile.darwin => Darwin makefile, can use on MacosX + makefile.dec => DEC Alpha UNIX makefile + makefile.dj2 => DJGPP 2 makefile + makefile.elf => Linux/ELF makefile symbol versioning, + gcc, creates libpng12.so.0.1.2.46) + makefile.freebsd => FreeBSD makefile + makefile.gcc => Generic gcc makefile + makefile.gccmmx => Generic gcc makefile previously using MMX code + makefile.hpgcc => HPUX makefile using gcc + makefile.hpux => HPUX (10.20 and 11.00) makefile + makefile.hp64 => HPUX (10.20 and 11.00) makefile, 64-bit + makefile.ibmc => IBM C/C++ version 3.x for Win32 and OS/2 (static) + makefile.intel => Intel C/C++ version 4.0 and later + makefile.mingw => Mingw makefile + makefile.mips => MIPS makefile + makefile.msc => Microsoft C makefile + makefile.netbsd => NetBSD/cc makefile, makes libpng.so. + makefile.nommx => Generic gcc makefile not using MMX code + makefile.openbsd => OpenBSD makefile + makefile.os2 => OS/2 Makefile (gcc and emx, requires pngos2.def) + makefile.sco => For SCO OSr5 ELF and Unixware 7 with Native cc + makefile.sggcc => Silicon Graphics (gcc, + creates libpng12.so.0.1.2.46) + makefile.sgi => Silicon Graphics IRIX makefile (cc, creates static lib) + makefile.solaris => Solaris 2.X makefile (gcc, + creates libpng12.so.0.1.2.46) + makefile.solaris-x86 => Solaris 2.X makefile (gcc, no MMX code, + creates libpng12.so.0.1.2.46) + makefile.so9 => Solaris 9 makefile (gcc, + creates libpng12.so.0.1.2.46) + makefile.std => Generic UNIX makefile (cc, creates static libpng.a) + makefile.sunos => Sun makefile + makefile.32sunu => Sun Ultra 32-bit makefile + makefile.64sunu => Sun Ultra 64-bit makefile + makefile.tc3 => Turbo C 3.0 makefile + makefile.vcawin32 => makefile for Microsoft Visual C++ 4.0 and later + previously using MMX code + makefile.vcwin32 => makefile for Microsoft Visual C++ 4.0 and later + makefile.watcom => Watcom 10a+ Makefile, 32-bit flat memory model + makevms.com => VMS build script + smakefile.ppc => AMIGA smakefile for SAS C V6.58/7.00 PPC compiler + (Requires SCOPTIONS, copied from scripts/SCOPTIONS.ppc) + +Other supporting scripts: + descrip.mms => VMS makefile for MMS or MMK + libpng-config.in => Used by "configure" to create libpng-config. + libpng-config-body.in => used by several makefiles to create libpng-config + libpng-config-head.in => used by several makefiles to create libpng-config + libpng.pc.in => Used by several makefiles to create libpng.pc + libpng.pc-configure.in => Used by "configure" to create libpng.pc + libpng.icc + pngos2.def => OS/2 module definition file used by makefile.os2 + pngw32.def => Module definitions for makefile.cygwin and mingw + png32ce.def => Module definition file used by makefile.cegcc + pngw32.rc => Used by the visualc6 and visualc71 projects. + SCOPTIONS.ppc => Used with smakefile.ppc + +Further information can be found in comments in the individual makefiles. diff --git a/libs/libpng-src/scripts/SCOPTIONS.ppc b/libs/libpng-src/scripts/SCOPTIONS.ppc new file mode 100644 index 000000000..2c3503e9e --- /dev/null +++ b/libs/libpng-src/scripts/SCOPTIONS.ppc @@ -0,0 +1,7 @@ +OPTIMIZE +OPTPEEP +OPTTIME +OPTSCHED +AUTOREGISTER +PARMS=REGISTERS +INCLUDEDIR=hlp:ppc/include diff --git a/libs/libpng-src/scripts/descrip.mms b/libs/libpng-src/scripts/descrip.mms new file mode 100644 index 000000000..f3a8d7bab --- /dev/null +++ b/libs/libpng-src/scripts/descrip.mms @@ -0,0 +1,52 @@ + +cc_defs = /inc=$(ZLIBSRC) +c_deb = + +.ifdef __DECC__ +pref = /prefix=all +.endif + + + +OBJS = png.obj, pngset.obj, pngget.obj, pngrutil.obj, pngtrans.obj,\ + pngwutil.obj, pngread.obj, pngmem.obj, pngwrite.obj, pngrtran.obj,\ + pngwtran.obj, pngrio.obj, pngwio.obj, pngerror.obj, pngpread.obj + + +CFLAGS= $(C_DEB) $(CC_DEFS) $(PREF) + +all : pngtest.exe libpng.olb + @ write sys$output " pngtest available" + +libpng.olb : libpng.olb($(OBJS)) + @ write sys$output " Libpng available" + + +pngtest.exe : pngtest.obj libpng.olb + link pngtest,libpng.olb/lib,$(ZLIBSRC)libz.olb/lib + +test : pngtest.exe + run pngtest + +clean : + delete *.obj;*,*.exe; + + +# Other dependencies. +png.obj : png.h, pngconf.h +pngpread.obj : png.h, pngconf.h +pngset.obj : png.h, pngconf.h +pngget.obj : png.h, pngconf.h +pngread.obj : png.h, pngconf.h +pngrtran.obj : png.h, pngconf.h +pngrutil.obj : png.h, pngconf.h +pngerror.obj : png.h, pngconf.h +pngmem.obj : png.h, pngconf.h +pngrio.obj : png.h, pngconf.h +pngwio.obj : png.h, pngconf.h +pngtrans.obj : png.h, pngconf.h +pngwrite.obj : png.h, pngconf.h +pngwtran.obj : png.h, pngconf.h +pngwutil.obj : png.h, pngconf.h + +pngtest.obj : png.h, pngconf.h diff --git a/libs/libpng-src/scripts/libpng-config-body.in b/libs/libpng-src/scripts/libpng-config-body.in new file mode 100644 index 000000000..b466432d5 --- /dev/null +++ b/libs/libpng-src/scripts/libpng-config-body.in @@ -0,0 +1,96 @@ + +usage() +{ + cat < libpng.pc + +libpng-config: + ( cat scripts/libpng-config-head.in; \ + echo prefix=\"$(prefix)\"; \ + echo libdir=\"$(LIBPATH)\"; \ + echo I_opts=\"-I$(INCPATH)/$(LIBNAME)\"; \ + echo L_opts=\"-L$(LIBPATH)\"; \ + echo R_opts=\"-R$(LIBPATH)\"; \ + echo ccopts=\"-xtarget=ultra\"; \ + echo ldopts=\"-xtarget=ultra\"; \ + echo libs=\"-lpng12 -lz -lm\"; \ + cat scripts/libpng-config-body.in ) > libpng-config + chmod +x libpng-config + +$(LIBSO): $(LIBSOMAJ) + $(LN_SF) $(LIBSOMAJ) $(LIBSO) + +$(LIBSOMAJ): $(LIBSOVER) + $(LN_SF) $(LIBSOVER) $(LIBSOMAJ) + +$(LIBSOVER): $(OBJSDLL) + @case "`type ld`" in *ucb*) \ + echo; \ + echo '## WARNING:'; \ + echo '## The commands "CC" and "LD" must NOT refer to /usr/ucb/cc'; \ + echo '## and /usr/ucb/ld. If they do, you need to adjust your PATH'; \ + echo '## environment variable to put /usr/ccs/bin ahead of /usr/ucb.'; \ + echo '## The environment variable LD_LIBRARY_PATH should not be set'; \ + echo '## at all. If it is, things are likely to break because of'; \ + echo '## the libucb dependency that is created.'; \ + echo; \ + ;; \ + esac + $(LD) -G -L$(ZLIBLIB) -R$(ZLIBLIB) -h $(LIBSOMAJ) \ + -o $(LIBSOVER) $(OBJSDLL) + +$(OLDSOVER): $(OBJSDLL) + $(LD) -G -L$(ZLIBLIB) -R$(ZLIBLIB) -h $(OLDSOMAJ) \ + -o $(OLDSOVER) $(OBJSDLL) + +pngtest: pngtest.o $(LIBSO) + $(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS) + +test: pngtest + ./pngtest + +install-headers: png.h pngconf.h + -@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi + -@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi + cp png.h pngconf.h $(DI)/$(LIBNAME) + chmod 644 $(DI)/$(LIBNAME)/png.h $(DI)/$(LIBNAME)/pngconf.h + -@$(RM_F) $(DI)/png.h $(DI)/pngconf.h + -@$(RM_F) $(DI)/libpng + (cd $(DI); $(LN_SF) $(LIBNAME) libpng; $(LN_SF) $(LIBNAME)/* .) + +install-static: install-headers libpng.a + -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi + cp libpng.a $(DL)/$(LIBNAME).a + chmod 644 $(DL)/$(LIBNAME).a + -@$(RM_F) $(DL)/libpng.a + (cd $(DL); $(LN_SF) $(LIBNAME).a libpng.a) + +install-shared: install-headers $(LIBSOVER) libpng.pc \ + $(OLDSOVER) + -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi + -@$(RM_F) $(DL)/$(LIBSOVER)* $(DL)/$(LIBSO) + -@$(RM_F) $(DL)/$(LIBSOMAJ) + -@$(RM_F) $(DL)/$(LIBSO) + -@$(RM_F) $(DL)/$(OLDSO) + -@$(RM_F) $(DL)/$(OLDSOMAJ) + -@$(RM_F) $(DL)/$(OLDSOMAJ).$(PNGVER)* + cp $(LIBSOVER) $(DL) + cp $(OLDSOVER) $(DL) + chmod 755 $(DL)/$(LIBSOVER) + chmod 755 $(DL)/$(OLDSOVER) + (cd $(DL); \ + $(LN_SF) $(OLDSOVER) $(OLDSOMAJ); \ + $(LN_SF) $(OLDSOMAJ) $(OLDSO); \ + $(LN_SF) $(LIBSOVER) $(LIBSOMAJ); \ + $(LN_SF) $(LIBSOMAJ) $(LIBSO)) + -@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi + -@$(RM_F) $(DL)/pkgconfig/$(LIBNAME).pc + -@$(RM_F) $(DL)/pkgconfig/libpng.pc + cp libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc + chmod 644 $(DL)/pkgconfig/$(LIBNAME).pc + (cd $(DL)/pkgconfig; $(LN_SF) $(LIBNAME).pc libpng.pc) + +install-man: libpng.3 libpngpf.3 png.5 + -@if [ ! -d $(DM) ]; then $(MKDIR_P) $(DM); fi + -@if [ ! -d $(DM)/man3 ]; then $(MKDIR_P) $(DM)/man3; fi + -@$(RM_F) $(DM)/man3/libpng.3 + -@$(RM_F) $(DM)/man3/libpngpf.3 + cp libpng.3 $(DM)/man3 + cp libpngpf.3 $(DM)/man3 + -@if [ ! -d $(DM)/man5 ]; then $(MKDIR_P) $(DM)/man5; fi + -@$(RM_F) $(DM)/man5/png.5 + cp png.5 $(DM)/man5 + +install-config: libpng-config + -@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi + -@$(RM_F) $(DB)/libpng-config + -@$(RM_F) $(DB)/$(LIBNAME)-config + cp libpng-config $(DB)/$(LIBNAME)-config + chmod 755 $(DB)/$(LIBNAME)-config + (cd $(DB); $(LN_SF) $(LIBNAME)-config libpng-config) + +install: install-static install-shared install-man install-config + +# If you installed in $(DESTDIR), test-installed won't work until you +# move the library to its final location. Use test-dd to test it +# before then. + +test-dd: + echo + echo Testing installed dynamic shared library in $(DL). + $(CC) $(SUN_CC_FLAGS) -I$(DI) -I$(ZLIBINC) \ + `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \ + -o pngtestd -L$(DL) -R$(DL) `$(BINPATH)/$(LIBNAME)-config --ldflags` \ + $(SUN_LD_FLAGS) -L$(ZLIBLIB) -R$(ZLIBLIB) + ./pngtestd pngtest.png + +test-installed: + echo + echo Testing installed dynamic shared library. + $(CC) $(SUN_CC_FLAGS) -I$(ZLIBINC) \ + `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \ + -o pngtesti `$(BINPATH)/$(LIBNAME)-config --ldflags` \ + $(SUN_LD_FLAGS) -L$(ZLIBLIB) -R$(ZLIBLIB) + ./pngtesti pngtest.png + +clean: + $(RM_F) *.o libpng.a pngtest pngtesti pngout.png \ + libpng-config $(LIBSO) $(LIBSOMAJ)* \ + $(OLDSOVER) \ + libpng.pc + +DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO +writelock: + chmod a-w *.[ch35] $(DOCS) scripts/* + +# DO NOT DELETE THIS LINE -- make depend depends on it. + +png.o png.pic.o: png.h pngconf.h +pngerror.o pngerror.pic.o: png.h pngconf.h +pngrio.o pngrio.pic.o: png.h pngconf.h +pngwio.o pngwio.pic.o: png.h pngconf.h +pngmem.o pngmem.pic.o: png.h pngconf.h +pngset.o pngset.pic.o: png.h pngconf.h +pngget.o pngget.pic.o: png.h pngconf.h +pngread.o pngread.pic.o: png.h pngconf.h +pngrtran.o pngrtran.pic.o: png.h pngconf.h +pngrutil.o pngrutil.pic.o: png.h pngconf.h +pngtrans.o pngtrans.pic.o: png.h pngconf.h +pngwrite.o pngwrite.pic.o: png.h pngconf.h +pngwtran.o pngwtran.pic.o: png.h pngconf.h +pngwutil.o pngwutil.pic.o: png.h pngconf.h +pngpread.o pngpread.pic.o: png.h pngconf.h + +pngtest.o: png.h pngconf.h diff --git a/libs/libpng-src/scripts/makefile.64sunu b/libs/libpng-src/scripts/makefile.64sunu new file mode 100644 index 000000000..37716655a --- /dev/null +++ b/libs/libpng-src/scripts/makefile.64sunu @@ -0,0 +1,257 @@ +# makefile for libpng on Solaris 2.x with cc +# Contributed by William L. Sebok, based on makefile.linux +# Copyright (C) 2002, 2006 Glenn Randers-Pehrson +# Copyright (C) 1998 Greg Roelofs +# Copyright (C) 1996, 1997 Andreas Dilger + +# This code is released under the libpng license. +# For conditions of distribution and use, see the disclaimer +# and license in png.h + +# Library name: +LIBNAME=libpng12 +PNGMAJ = 0 +PNGMIN = 1.2.46 +PNGVER = $(PNGMAJ).$(PNGMIN) + +# Shared library names: +LIBSO=$(LIBNAME).so +LIBSOMAJ=$(LIBNAME).so.$(PNGMAJ) +LIBSOVER=$(LIBNAME).so.$(PNGVER) +OLDSO=libpng.so +OLDSOMAJ=libpng.so.3 +OLDSOVER=libpng.so.3.$(PNGMIN) + +# Utilities: +CC=cc +AR_RC=ar rc +MKDIR_P=mkdir -p +LN_SF=ln -f -s +RANLIB=echo +RM_F=/bin/rm -f + +SUN_CC_FLAGS=-fast -xtarget=ultra -xarch=v9 +SUN_LD_FLAGS=-fast -xtarget=ultra -xarch=v9 + +# where make install puts libpng.a, libpng12.so and libpng12/png.h +prefix=/a +exec_prefix=$(prefix) + +# Where the zlib library and include files are located +# Changing these to ../zlib poses a security risk. If you want +# to have zlib in an adjacent directory, specify the full path instead of "..". +#ZLIBLIB=../zlib +#ZLIBINC=../zlib + +ZLIBLIB=/usr/lib +ZLIBINC=/usr/include + +WARNMORE=-Wwrite-strings -Wpointer-arith -Wshadow \ + -Wmissing-declarations -Wtraditional -Wcast-align \ + -Wstrict-prototypes -Wmissing-prototypes #-Wconversion +CFLAGS=-I$(ZLIBINC) $(SUN_CC_FLAGS) \ + # $(WARNMORE) -g -DPNG_DEBUG=5 +LDFLAGS=-L. -R. $(SUN_LD_FLAGS) -L$(ZLIBLIB) -R$(ZLIBLIB) -lpng12 -lz -lm + +INCPATH=$(prefix)/include +LIBPATH=$(exec_prefix)/lib +MANPATH=$(prefix)/man +BINPATH=$(exec_prefix)/bin + +# override DESTDIR= on the make install command line to easily support +# installing into a temporary location. Example: +# +# make install DESTDIR=/tmp/build/libpng +# +# If you're going to install into a temporary location +# via DESTDIR, $(DESTDIR)$(prefix) must already exist before +# you execute make install. +DESTDIR= + +DB=$(DESTDIR)$(BINPATH) +DI=$(DESTDIR)$(INCPATH) +DL=$(DESTDIR)$(LIBPATH) +DM=$(DESTDIR)$(MANPATH) + +OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \ + pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \ + pngwtran.o pngmem.o pngerror.o pngpread.o + +OBJSDLL = $(OBJS:.o=.pic.o) + +.SUFFIXES: .c .o .pic.o + +.c.pic.o: + $(CC) -c $(CFLAGS) -KPIC -o $@ $*.c + +all: libpng.a $(LIBSO) pngtest libpng.pc libpng-config + +libpng.a: $(OBJS) + $(AR_RC) $@ $(OBJS) + $(RANLIB) $@ + +libpng.pc: + cat scripts/libpng.pc.in | sed -e s!@prefix@!$(prefix)! \ + -e s!@exec_prefix@!$(exec_prefix)! \ + -e s!@libdir@!$(LIBPATH)! \ + -e s!@includedir@!$(INCPATH)! \ + -e s!-lpng12!-lpng12\ -lz\ -lm! > libpng.pc + +libpng-config: + ( cat scripts/libpng-config-head.in; \ + echo prefix=\"$(prefix)\"; \ + echo libdir=\"$(LIBPATH)\"; \ + echo I_opts=\"-I$(INCPATH)/$(LIBNAME)\"; \ + echo L_opts=\"-L$(LIBPATH)\"; \ + echo R_opts=\"-R$(LIBPATH)\"; \ + echo ccopts=\"-xtarget=ultra -xarch=v9\"; \ + echo ldopts=\"-xtarget=ultra -xarch=v9\"; \ + echo libs=\"-lpng12 -lz -lm\"; \ + cat scripts/libpng-config-body.in ) > libpng-config + chmod +x libpng-config + +$(LIBSO): $(LIBSOMAJ) + $(LN_SF) $(LIBSOMAJ) $(LIBSO) + +$(LIBSOMAJ): $(LIBSOVER) + $(LN_SF) $(LIBSOVER) $(LIBSOMAJ) + +$(LIBSOVER): $(OBJSDLL) + @case "`type ld`" in *ucb*) \ + echo; \ + echo '## WARNING:'; \ + echo '## The commands "CC" and "LD" must NOT refer to /usr/ucb/cc'; \ + echo '## and /usr/ucb/ld. If they do, you need to adjust your PATH'; \ + echo '## environment variable to put /usr/ccs/bin ahead of /usr/ucb.'; \ + echo '## The environment variable LD_LIBRARY_PATH should not be set'; \ + echo '## at all. If it is, things are likely to break because of'; \ + echo '## the libucb dependency that is created.'; \ + echo; \ + ;; \ + esac + $(LD) -G -L$(ZLIBLIB) -R$(ZLIBLIB) -h $(LIBSOMAJ) \ + -o $(LIBSOVER) $(OBJSDLL) + +$(OLDSOVER): $(OBJSDLL) + $(LD) -G -L$(ZLIBLIB) -R$(ZLIBLIB) -h $(OLDSOMAJ) \ + -o $(OLDSOVER) $(OBJSDLL) + +pngtest: pngtest.o $(LIBSO) + $(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS) + +test: pngtest + ./pngtest + +install-headers: png.h pngconf.h + -@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi + -@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi + cp png.h pngconf.h $(DI)/$(LIBNAME) + chmod 644 $(DI)/$(LIBNAME)/png.h $(DI)/$(LIBNAME)/pngconf.h + -@$(RM_F) $(DI)/png.h $(DI)/pngconf.h + -@$(RM_F) $(DI)/libpng + (cd $(DI); $(LN_SF) $(LIBNAME) libpng; $(LN_SF) $(LIBNAME)/* .) + +install-static: install-headers libpng.a + -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi + cp libpng.a $(DL)/$(LIBNAME).a + chmod 644 $(DL)/$(LIBNAME).a + -@$(RM_F) $(DL)/libpng.a + (cd $(DL); $(LN_SF) $(LIBNAME).a libpng.a) + +install-shared: install-headers $(LIBSOVER) libpng.pc \ + $(OLDSOVER) + -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi + -@$(RM_F) $(DL)/$(LIBSOVER)* $(DL)/$(LIBSO) + -@$(RM_F) $(DL)/$(LIBSOMAJ) + -@$(RM_F) $(DL)/$(LIBSO) + -@$(RM_F) $(DL)/$(OLDSO) + -@$(RM_F) $(DL)/$(OLDSOMAJ) + -@$(RM_F) $(DL)/$(OLDSOMAJ).$(PNGVER)* + cp $(LIBSOVER) $(DL) + cp $(OLDSOVER) $(DL) + chmod 755 $(DL)/$(LIBSOVER) + chmod 755 $(DL)/$(OLDSOVER) + (cd $(DL); \ + $(LN_SF) $(OLDSOVER) $(OLDSOMAJ); \ + $(LN_SF) $(OLDSOMAJ) $(OLDSO); \ + $(LN_SF) $(LIBSOVER) $(LIBSOMAJ); \ + $(LN_SF) $(LIBSOMAJ) $(LIBSO)) + -@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi + -@$(RM_F) $(DL)/pkgconfig/$(LIBNAME).pc + -@$(RM_F) $(DL)/pkgconfig/libpng.pc + cp libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc + chmod 644 $(DL)/pkgconfig/$(LIBNAME).pc + (cd $(DL)/pkgconfig; $(LN_SF) $(LIBNAME).pc libpng.pc) + +install-man: libpng.3 libpngpf.3 png.5 + -@if [ ! -d $(DM) ]; then $(MKDIR_P) $(DM); fi + -@if [ ! -d $(DM)/man3 ]; then $(MKDIR_P) $(DM)/man3; fi + -@$(RM_F) $(DM)/man3/libpng.3 + -@$(RM_F) $(DM)/man3/libpngpf.3 + cp libpng.3 $(DM)/man3 + cp libpngpf.3 $(DM)/man3 + -@if [ ! -d $(DM)/man5 ]; then $(MKDIR_P) $(DM)/man5; fi + -@$(RM_F) $(DM)/man5/png.5 + cp png.5 $(DM)/man5 + +install-config: libpng-config + -@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi + -@$(RM_F) $(DB)/libpng-config + -@$(RM_F) $(DB)/$(LIBNAME)-config + cp libpng-config $(DB)/$(LIBNAME)-config + chmod 755 $(DB)/$(LIBNAME)-config + (cd $(DB); $(LN_SF) $(LIBNAME)-config libpng-config) + +install: install-static install-shared install-man install-config + +# If you installed in $(DESTDIR), test-installed won't work until you +# move the library to its final location. Use test-dd to test it +# before then. + +test-dd: + echo + echo Testing installed dynamic shared library in $(DL). + $(CC) $(SUN_CC_FLAGS) -I$(DI) -I$(ZLIBINC) \ + `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \ + -o pngtestd -L$(DL) -R$(DL) `$(BINPATH)/$(LIBNAME)-config --ldflags` \ + $(SUN_LD_FLAGS) -L$(ZLIBLIB) -R$(ZLIBLIB) + ./pngtestd pngtest.png + +test-installed: + echo + echo Testing installed dynamic shared library. + $(CC) $(SUN_CC_FLAGS) -I$(ZLIBINC) \ + `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \ + -o pngtesti `$(BINPATH)/$(LIBNAME)-config --ldflags` \ + $(SUN_LD_FLAGS) -L$(ZLIBLIB) -R$(ZLIBLIB) + ./pngtesti pngtest.png + +clean: + $(RM_F) *.o libpng.a pngtest pngtesti pngout.png \ + libpng-config $(LIBSO) $(LIBSOMAJ)* \ + $(OLDSOVER) \ + libpng.pc + +DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO +writelock: + chmod a-w *.[ch35] $(DOCS) scripts/* + +# DO NOT DELETE THIS LINE -- make depend depends on it. + +png.o png.pic.o: png.h pngconf.h +pngerror.o pngerror.pic.o: png.h pngconf.h +pngrio.o pngrio.pic.o: png.h pngconf.h +pngwio.o pngwio.pic.o: png.h pngconf.h +pngmem.o pngmem.pic.o: png.h pngconf.h +pngset.o pngset.pic.o: png.h pngconf.h +pngget.o pngget.pic.o: png.h pngconf.h +pngread.o pngread.pic.o: png.h pngconf.h +pngrtran.o pngrtran.pic.o: png.h pngconf.h +pngrutil.o pngrutil.pic.o: png.h pngconf.h +pngtrans.o pngtrans.pic.o: png.h pngconf.h +pngwrite.o pngwrite.pic.o: png.h pngconf.h +pngwtran.o pngwtran.pic.o: png.h pngconf.h +pngwutil.o pngwutil.pic.o: png.h pngconf.h +pngpread.o pngpread.pic.o: png.h pngconf.h + +pngtest.o: png.h pngconf.h diff --git a/libs/libpng-src/scripts/makefile.acorn b/libs/libpng-src/scripts/makefile.acorn new file mode 100644 index 000000000..a0e577b24 --- /dev/null +++ b/libs/libpng-src/scripts/makefile.acorn @@ -0,0 +1,50 @@ +# Project: libpng + + +# Toolflags: +CCflags = -c -depend !Depend -IC:,Zlib: -g -throwback -DRISCOS -fnah +C++flags = -c -depend !Depend -IC: -throwback +Linkflags = -aif -c++ -o $@ +ObjAsmflags = -throwback -NoCache -depend !Depend +CMHGflags = +LibFileflags = -c -l -o $@ +Squeezeflags = -o $@ + +# Final targets: +@.libpng-lib: @.o.png @.o.pngerror @.o.pngrio @.o.pngwio @.o.pngmem \ + @.o.pngpread @.o.pngset @.o.pngget @.o.pngread @.o.pngrtran \ + @.o.pngrutil @.o.pngtrans @.o.pngwrite @.o.pngwtran @.o.pngwutil + LibFile $(LibFileflags) @.o.png @.o.pngerror @.o.pngrio @.o.pngrtran \ + @.o.pngmem @.o.pngpread @.o.pngset @.o.pngget @.o.pngread @.o.pngwio \ + @.o.pngrutil @.o.pngtrans @.o.pngwrite @.o.pngwtran @.o.pngwutil +@.mm-libpng-lib: @.mm.png @.mm.pngerror @.mm.pngrio @.mm.pngwio @.mm.pngmem \ + @.mm.pngpread @.mm.pngset @.mm.pngget @.mm.pngread @.mm.pngrtran \ + @.mm.pngrutil @.mm.pngtrans @.mm.pngwrite @.mm.pngwtran @.mm.pngwutil + LibFile $(LibFileflags) @.mm.png @.mm.pngerror @.mm.pngrio \ + @.mm.pngwio @.mm.pngmem @.mm.pngpread @.mm.pngset @.mm.pngget \ + @.mm.pngread @.mm.pngrtran @.mm.pngrutil @.mm.pngtrans @.mm.pngwrite \ + @.mm.pngwtran @.mm.pngwutil + + +# User-editable dependencies: +# (C) Copyright 1997 Tom Tanner +Test: @.pngtest + .pngtest + @remove .pngtest + +#It would be nice if you could stop "make" listing from here on! +@.pngtest: @.o.pngtest @.libpng-lib C:o.Stubs Zlib:zlib_lib + Link $(Linkflags) @.o.pngtest @.libpng-lib C:o.Stubs Zlib:zlib_lib + +.SUFFIXES: .o .mm .c + +.c.mm: + MemCheck.CC cc $(ccflags) -o $@ LibPng:$< +.c.o: + cc $(ccflags) -o $@ $< + + +# Static dependencies: + + +# Dynamic dependencies: diff --git a/libs/libpng-src/scripts/makefile.aix b/libs/libpng-src/scripts/makefile.aix new file mode 100644 index 000000000..7ef49c571 --- /dev/null +++ b/libs/libpng-src/scripts/makefile.aix @@ -0,0 +1,116 @@ +# makefile for libpng using gcc (generic, static library) +# Copyright (C) 2002, 2006-2009 Glenn Randers-Pehrson +# Copyright (C) 2000 Cosmin Truta +# Copyright (C) 2000 Marc O. Gloor (AIX support added, from makefile.gcc) +# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc. +# +# This code is released under the libpng license. +# For conditions of distribution and use, see the disclaimer +# and license in png.h + +# Location of the zlib library and include files +ZLIBINC = ../zlib +ZLIBLIB = ../zlib + +# Compiler, linker, lib and other tools +CC = gcc +LD = $(CC) +AR_RC = ar rcs +MKDIR_P = mkdir -p +RANLIB = ranlib +RM_F = rm -f +LN_SF = ln -f -s + +LIBNAME=libpng12 +PNGMAJ = 0 +PNGMIN = 1.2.46 +PNGVER = $(PNGMAJ).$(PNGMIN) + +prefix=/usr/local +INCPATH=$(prefix)/include +LIBPATH=$(prefix)/lib + +# override DESTDIR= on the make install command line to easily support +# installing into a temporary location. Example: +# +# make install DESTDIR=/tmp/build/libpng +# +# If you're going to install into a temporary location +# via DESTDIR, $(DESTDIR)$(prefix) must already exist before +# you execute make install. +DESTDIR= + +DI=$(DESTDIR)$(INCPATH) +DL=$(DESTDIR)$(LIBPATH) + +CDEBUG = -g -DPNG_DEBUG=5 +LDDEBUG = +CRELEASE = -O2 +LDRELEASE = -s +WARNMORE=-W -Wall +CFLAGS = -D_ALL_SOURCE -I$(ZLIBINC) $(WARNMORE) $(CRELEASE) +LDFLAGS = -L. -L$(ZLIBLIB) -lpng12 -lz -lm $(LDRELEASE) + +# File extensions +O=.o +A=.a +E= + +# Variables +OBJS = png$(O) pngerror$(O) pngget$(O) pngmem$(O) pngpread$(O) \ + pngread$(O) pngrio$(O) pngrtran$(O) pngrutil$(O) pngset$(O) \ + pngtrans$(O) pngwio$(O) pngwrite$(O) pngwtran$(O) pngwutil$(O) + +# Targets +all: $(LIBNAME)$(A) pngtest$(E) + +$(LIBNAME)$(A): $(OBJS) + $(AR_RC) $@ $(OBJS) + $(RANLIB) $@ + +test: pngtest$(E) + ./pngtest$(E) + +pngtest$(E): pngtest$(O) $(LIBNAME)$(A) + $(LD) -o $@ pngtest$(O) $(LDFLAGS) + +install: $(LIBNAME)$(A) + -@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi + -@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi + -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi + -@$(RM_F) $(DI)/$(LIBNAME)/png.h + -@$(RM_F) $(DI)/$(LIBNAME)/pngconf.h + -@$(RM_F) $(DI)/png.h + -@$(RM_F) $(DI)/pngconf.h + cp png.h pngconf.h $(DI)/$(LIBNAME) + chmod 644 $(DI)/$(LIBNAME)/png.h \ + $(DI)/$(LIBNAME)/pngconf.h + -@$(RM_F) -r $(DI)/libpng + (cd $(DI); $(LN_SF) $(LIBNAME) libpng; $(LN_SF) $(LIBNAME)/* .) + -@$(RM_F) $(DL)/$(LIBNAME)$(A) + -@$(RM_F) $(DL)/libpng$(A) + cp $(LIBNAME)$(A) $(DL)/$(LIBNAME)$(A) + chmod 644 $(DL)/$(LIBNAME)$(A) + (cd $(DL); $(LN_SF) $(LIBNAME)$(A) libpng$(A)) + (cd $(DI); $(LN_SF) libpng/* .;) + +clean: + $(RM_F) *.o $(LIBNAME)$(A) pngtest pngout.png + +png$(O): png.h pngconf.h +pngerror$(O): png.h pngconf.h +pngget$(O): png.h pngconf.h +pngmem$(O): png.h pngconf.h +pngpread$(O): png.h pngconf.h +pngread$(O): png.h pngconf.h +pngrio$(O): png.h pngconf.h +pngrtran$(O): png.h pngconf.h +pngrutil$(O): png.h pngconf.h +pngset$(O): png.h pngconf.h +pngtrans$(O): png.h pngconf.h +pngwio$(O): png.h pngconf.h +pngwrite$(O): png.h pngconf.h +pngwtran$(O): png.h pngconf.h +pngwutil$(O): png.h pngconf.h + +pngtest$(O): png.h pngconf.h diff --git a/libs/libpng-src/scripts/makefile.amiga b/libs/libpng-src/scripts/makefile.amiga new file mode 100644 index 000000000..8bf0f455f --- /dev/null +++ b/libs/libpng-src/scripts/makefile.amiga @@ -0,0 +1,51 @@ +# Commodore Amiga Makefile +# makefile for libpng and SAS C V6.5x compiler +# Copyright (C) 1995-2000 Wolf Faust +# +# This code is released under the libpng license. +# For conditions of distribution and use, see the disclaimer +# and license in png.h +# +# Note: Use #define PNG_READ_BIG_ENDIAN_SUPPORTED in pngconf.h +# +# Location/path of zlib include files +ZLIB=/zlib +#compiler +CC=sc +#compiler flags +# WARNING: a bug in V6.51 causes bad code with OPTGO +# So use V6.55 or set NOOPTGO!!!!!!!!! +CFLAGS= NOSTKCHK PARMS=REG OPTIMIZE OPTGO OPTPEEP OPTINLOCAL OPTINL\ + OPTLOOP OPTRDEP=4 OPTDEP=4 OPTCOMP=4 INCLUDEDIR=$(ZLIB) \ + DEFINE=PNG_INTERNAL +#linker flags +LDFLAGS= SD ND BATCH +#link libs +LDLIBS= libpng.lib libgz.lib LIB:scm.lib LIB:sc.lib Lib:amiga.lib +# linker +LN= slink +# file deletion command +RM= delete quiet +# library (.lib) file creation command +AR= oml +# make directory command +MKDIR= makedir + +OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \ + pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \ + pngwtran.o pngmem.o pngerror.o pngpread.o + +all: libpng.lib pngtest + +libpng.lib: $(OBJS) +-$(RM) libpng.lib +$(AR) libpng.lib r $(OBJS) + +pngtest: pngtest.o libpng.lib +$(LN) libpng.pc + +libpng-config: + ( cat scripts/libpng-config-head.in; \ + echo prefix=\"$(prefix)\"; \ + echo I_opts=\"-I$(INCPATH)/$(LIBNAME)\"; \ + echo libs=\"-lpng12 -lz \"; \ + cat scripts/libpng-config-body.in ) > libpng-config + chmod +x libpng-config + +$(LIBSO): $(LIBSOMAJ) + $(LN_SF) $(LIBSOMAJ) $(LIBSO) + cp $(LIBSO)* /boot/home/config/lib + +$(LIBSOMAJ): $(LIBSOVER) + $(LN_SF) $(LIBSOVER) $(LIBSOMAJ) + +$(LIBSOVER): $(OBJSDLL) + $(CC) -nostart -Wl,-soname,$(LIBSOMAJ) -o \ + $(LIBSOVER) $(OBJSDLL) $(LDFLAGS) + +$(OLDSOVER): $(OBJSDLL) + $(CC) -nostart -Wl,-soname,$(OLDSOMAJ) -o \ + $(OLDSOVER) $(OBJSDLL) $(LDFLAGS) + +pngtest: pngtest.o $(LIBSO) + $(CC) -L$(ZLIBLIB) -L. -lz -lpng12 -o pngtest pngtest.o + +test: pngtest + ./pngtest + +install-headers: png.h pngconf.h + -@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi + -@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi + cp png.h pngconf.h $(DI)/$(LIBNAME) + chmod 644 $(DI)/$(LIBNAME)/png.h $(DI)/$(LIBNAME)/pngconf.h + -@$(RM_F) $(DI)/png.h $(DI)/pngconf.h + -@$(RM_F) $(DI)/libpng + (cd $(DI); $(LN_SF) $(LIBNAME) libpng; $(LN_SF) $(LIBNAME)/* .) + +install-static: install-headers libpng.a + -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi + cp libpng.a $(DL)/$(LIBNAME).a + chmod 644 $(DL)/$(LIBNAME).a + -@$(RM_F) $(DL)/libpng.a + (cd $(DL); $(LN_SF) $(LIBNAME).a libpng.a) + +install-shared: install-headers $(LIBSOVER) libpng.pc \ + $(OLDSOVER) + -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi + -@$(RM_F) $(DL)/$(LIBSOVER)* $(DL)/$(LIBSO) + -@$(RM_F) $(DL)/$(LIBSOMAJ) + -@$(RM_F) $(DL)/$(OLDSO) + -@$(RM_F) $(DL)/$(OLDSOMAJ) + -@$(RM_F) $(DL)/$(OLDSOVER)* + cp $(LIBSOVER) $(DL) + cp $(OLDSOVER) $(DL) + chmod 755 $(DL)/$(LIBSOVER) + chmod 755 $(DL)/$(OLDSOVER) + (cd $(DL); \ + $(LN_SF) $(OLDSOVER) $(OLDSOMAJ); \ + $(LN_SF) $(OLDSOMAJ) $(OLDSO); \ + $(LN_SF) $(LIBSOVER) $(LIBSOMAJ); \ + $(LN_SF) $(LIBSOMAJ) $(LIBSO)) + -@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi + -@$(RM_F) $(DL)/pkgconfig/$(LIBNAME).pc + -@$(RM_F) $(DL)/pkgconfig/libpng.pc + cp libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc + chmod 644 $(DL)/pkgconfig/$(LIBNAME).pc + (cd $(DL)/pkgconfig; $(LN_SF) $(LIBNAME).pc libpng.pc) + +install-man: libpng.3 libpngpf.3 png.5 + -@if [ ! -d $(DM) ]; then $(MKDIR_P) $(DM); fi + -@if [ ! -d $(DM)/man3 ]; then $(MKDIR_P) $(DM)/man3; fi + -@$(RM_F) $(DM)/man3/libpng.3 + -@$(RM_F) $(DM)/man3/libpngpf.3 + cp libpng.3 $(DM)/man3 + cp libpngpf.3 $(DM)/man3 + -@if [ ! -d $(DM)/man5 ]; then $(MKDIR_P) $(DM)/man5; fi + -@$(RM_F) $(DM)/man5/png.5 + cp png.5 $(DM)/man5 + +install-config: libpng-config + -@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi + -@$(RM_F) $(DB)/libpng-config + -@$(RM_F) $(DB)/$(LIBNAME)-config + cp libpng-config $(DB)/$(LIBNAME)-config + chmod 755 $(DB)/$(LIBNAME)-config + (cd $(DB); $(LN_SF) $(LIBNAME)-config libpng-config) + +install: install-static install-shared install-man install-config + +# If you installed in $(DESTDIR), test-installed won't work until you +# move the library to its final location. Use test-dd to test it +# before then. + +test-dd: + echo + echo Testing installed dynamic shared library in $(DL). + $(CC) -I$(DI) $(CFLAGS) \ + `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \ + -L$(DL) -L$(ZLIBLIB) -Wl,-rpath $(ZLIBLIB):$(DL) \ + -o pngtestd `$(BINPATH)/$(LIBNAME)-config --ldflags` + ./pngtestd pngtest.png + +test-installed: + $(CC) $(CFLAGS) \ + `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \ + -L$(ZLIBLIB) -Wl,-rpath,$(ZLIBLIB) \ + -o pngtesti `$(BINPATH)/$(LIBNAME)-config --ldflags` + ./pngtesti pngtest.png + +clean: + $(RM_F) *.o libpng.a pngtest pngout.png libpng-config \ + $(LIBSO) $(LIBSOMAJ)* pngtesti \ + $(OLDSOVER) \ + libpng.pc + +# DO NOT DELETE THIS LINE -- make depend depends on it. + +png.o png.pic.o: png.h pngconf.h +pngerror.o pngerror.pic.o: png.h pngconf.h +pngrio.o pngrio.pic.o: png.h pngconf.h +pngwio.o pngwio.pic.o: png.h pngconf.h +pngmem.o pngmem.pic.o: png.h pngconf.h +pngset.o pngset.pic.o: png.h pngconf.h +pngget.o pngget.pic.o: png.h pngconf.h +pngread.o pngread.pic.o: png.h pngconf.h +pngrtran.o pngrtran.pic.o: png.h pngconf.h +pngrutil.o pngrutil.pic.o: png.h pngconf.h +pngtrans.o pngtrans.pic.o: png.h pngconf.h +pngwrite.o pngwrite.pic.o: png.h pngconf.h +pngwtran.o pngwtran.pic.o: png.h pngconf.h +pngwutil.o pngwutil.pic.o: png.h pngconf.h +pngpread.o pngpread.pic.o: png.h pngconf.h + +pngtest.o: png.h pngconf.h diff --git a/libs/libpng-src/scripts/makefile.bor b/libs/libpng-src/scripts/makefile.bor new file mode 100644 index 000000000..e80318469 --- /dev/null +++ b/libs/libpng-src/scripts/makefile.bor @@ -0,0 +1,156 @@ +# Makefile for libpng +# 16-bit Borland C++ (Note: All modules are compiled in C mode) +# To build the library, do: +# "make -fmakefile.bor -DMODEL=c" +# or: "make -fmakefile.bor -DMODEL=l" +# +# ------------ Borland C++ ------------ + +### Absolutely necessary for this makefile to work +.AUTODEPEND + +## Where zlib.h, zconf.h and zlib_MODEL.lib are +ZLIB_DIR=..\zlib + +## Compiler, linker and lib stuff +CC=bcc +LD=bcc +LIB=tlib + +!ifndef MODEL +MODEL=l +!endif + +MODEL_ARG=-m$(MODEL) + +#TARGET_CPU=3 +# 2 = 286, 3 = 386, etc. +!ifndef TARGET_CPU +TARGET_CPU=2 +!endif + +# Use this if you don't want Borland's fancy exception handling +# (for Borland C++ 4.0 or later) +#NOEHLIB=noeh$(MODEL).lib + +!ifdef DEBUG +CDEBUG=-v +LDEBUG=-v +!else +CDEBUG= +LDEBUG= +!endif + +# STACKOFLOW=1 +!ifdef STACKOFLOW +CDEBUG=$(CDEBUG) -N +LDEBUG=$(LDEBUG) -N +!endif + +# -X- turn on dependency generation in the object file +# -w set all warnings on +# -O2 optimize for speed +# -Z global optimization +CFLAGS=-O2 -Z -X- -w -I$(ZLIB_DIR) -$(TARGET_CPU) $(MODEL_ARG) $(CDEBUG) + +# -M generate map file +LDFLAGS=-M -L$(ZLIB_DIR) $(MODEL_ARG) $(LDEBUG) + +## Variables + +OBJS = \ + png.obj \ + pngerror.obj \ + pngget.obj \ + pngmem.obj \ + pngpread.obj \ + pngread.obj \ + pngrio.obj \ + pngrtran.obj \ + pngrutil.obj \ + pngset.obj \ + pngtrans.obj \ + pngwio.obj \ + pngwrite.obj \ + pngwtran.obj \ + pngwutil.obj + +LIBOBJS = \ + +png.obj \ + +pngerror.obj \ + +pngget.obj \ + +pngmem.obj \ + +pngpread.obj \ + +pngread.obj \ + +pngrio.obj \ + +pngrtran.obj \ + +pngrutil.obj \ + +pngset.obj \ + +pngtrans.obj \ + +pngwio.obj \ + +pngwrite.obj \ + +pngwtran.obj \ + +pngwutil.obj + +LIBNAME=libpng$(MODEL).lib + +## Implicit rules + +# Braces let make "batch" calls to the compiler, +# 2 calls instead of 12; space is important. +.c.obj: + $(CC) $(CFLAGS) -c {$*.c } + +.c.exe: + $(CC) $(CFLAGS) $(LDFLAGS) $*.c $(LIBNAME) zlib_$(MODEL).lib $(NOEHLIB) + +## Major targets + +all: libpng pngtest + +libpng: $(LIBNAME) + +pngtest: pngtest$(MODEL).exe + +test: pngtest$(MODEL).exe + pngtest$(MODEL) + +## Minor Targets + +png.obj: png.c png.h pngconf.h +pngerror.obj: pngerror.c png.h pngconf.h +pngget.obj: pngget.c png.h pngconf.h +pngmem.obj: pngmem.c png.h pngconf.h +pngpread.obj: pngpread.c png.h pngconf.h +pngread.obj: pngread.c png.h pngconf.h +pngrio.obj: pngrio.c png.h pngconf.h +pngrtran.obj: pngrtran.c png.h pngconf.h +pngrutil.obj: pngrutil.c png.h pngconf.h +pngset.obj: pngset.c png.h pngconf.h +pngtrans.obj: pngtrans.c png.h pngconf.h +pngwio.obj: pngwio.c png.h pngconf.h +pngwrite.obj: pngwrite.c png.h pngconf.h +pngwtran.obj: pngwtran.c png.h pngconf.h +pngwutil.obj: pngwutil.c png.h pngconf.h + +$(LIBNAME): $(OBJS) + -del $(LIBNAME) + $(LIB) $(LIBNAME) @&&| +$(LIBOBJS), libpng$(MODEL) +| + +pngtest$(MODEL).obj: pngtest.c png.h pngconf.h + $(CC) $(CFLAGS) -opngtest$(MODEL) -c pngtest.c + +pngtest$(MODEL).exe: pngtest$(MODEL).obj + $(LD) $(LDFLAGS) pngtest$(MODEL).obj $(LIBNAME) zlib_$(MODEL).lib $(NOEHLIB) + +# Clean up anything else you want +clean: + -del *.obj + -del *.exe + -del *.lib + -del *.lst + -del *.map + +# End of makefile for libpng diff --git a/libs/libpng-src/scripts/makefile.cegcc b/libs/libpng-src/scripts/makefile.cegcc new file mode 100644 index 000000000..6e9cd7504 --- /dev/null +++ b/libs/libpng-src/scripts/makefile.cegcc @@ -0,0 +1,113 @@ +# Makefile for creating Windows CE release archives, with the +# mingw32ce compiler. + +# Last updated: 22-Jul-2008 + +# Copyright (C) 2008 Vincent Torri + +# This code is released under the libpng license. +# For conditions of distribution and use, see the disclaimer +# and license in png.h + +# To get some help, type +# +# make help +# +# To create the archives +# +# make +# +# To remove everything, type: +# +# make clean + +VERMAJ = 1 +VERMIN = 2 +VERMIC = 46 +VER = $(VERMAJ).$(VERMIN).$(VERMIC) +NAME = libpng +PACKAGE = $(NAME)-$(VER) + +BIN = libpng12-0.dll libpng-3.dll +LIB = libpng12.a libpng12.dll.a libpng.a libpng.dll.a scripts/png32ce.def +INCLUDE = png.h pngconf.h +PC = libpng12.pc libpng.pc + +MANIFESTVERBIN = "Libpng-$(VER): Binary files" +MANIFESTVERDEV = "Libpng-$(VER): Developer files" +MANIFESTVERDESC = "Libpng: the official PNG reference library" + +all: $(NAME) + +$(NAME): remove-old copy-src compilation copy manifest archive + @echo " * Removal of the directories" + @rm -rf $(PACKAGE)/ $(PACKAGE)-bin/ $(PACKAGE)-dev/ + +remove-old: + @echo " * Removal of the old files" + @rm -rf $(PACKAGE)-bin* + @rm -rf $(PACKAGE)-dev* + +copy-src: + @echo " * Copy of source files" + @cp -R ../src/$(PACKAGE) . + @echo " * Creation of directories and files" + @mkdir -p $(PACKAGE)-bin/bin + @mkdir -p $(PACKAGE)-bin/manifest + @mkdir -p $(PACKAGE)-dev/lib/pkgconfig + @mkdir -p $(PACKAGE)-dev/include/$(NAME)$(VERMAJ)$(VERMIN) + @mkdir -p $(PACKAGE)-dev/manifest + @touch $(PACKAGE)-bin/manifest/$(PACKAGE)-bin.mft + @touch $(PACKAGE)-bin/manifest/$(PACKAGE)-bin.ver + @touch $(PACKAGE)-dev/manifest/$(PACKAGE)-dev.mft + @touch $(PACKAGE)-dev/manifest/$(PACKAGE)-dev.ver + +compilation: + @echo " * Compilation of $(PACKAGE)" + cd $(PACKAGE) && CPPFLAGS="$(CPPFLAGS) -DPNG_BUILD_DLL -DPNG_CONSOLE_IO_SUPPORTED -DPNG_NO_MMX_CODE -D_WIN32_WCE=0x0420" CFLAGS="$(CFLAGS) -mms-bitfields -O3 -pipe -fomit-frame-pointer" LDFLAGS="$(LDFLAGS) -Wl,--enable-auto-import -Wl,-s" ./configure --prefix=/opt/wince --host=arm-mingw32ce && make + +copy: + @echo " * Copy of binary and development files" + @for i in $(BIN); do \ + cp $(PACKAGE)/.libs/$$i $(PACKAGE)-bin/bin; \ + done + @for i in $(LIB); do \ + cp $(PACKAGE)/.libs/$$i $(PACKAGE)-dev/lib; \ + done + @for i in $(INCLUDE); do \ + cp $(PACKAGE)/$$i $(PACKAGE)-dev/include/$(NAME)$(VERMAJ)$(VERMIN); \ + done + @for i in $(PC); do \ + cp $(PACKAGE)/$$i $(PACKAGE)-dev/lib/pkgconfig; \ + done + +manifest: + @echo " * Creation of the manifest" + @cd $(PACKAGE)-bin && find * >> manifest/$(PACKAGE)-bin.mft + @cd $(PACKAGE)-bin && \ + echo $(MANIFESTVERBIN) >> manifest/$(PACKAGE)-bin.ver && \ + echo $(MANIFESTVERDESC) >> manifest/$(PACKAGE)-bin.ver + @cd $(PACKAGE)-dev && find * >> manifest/$(PACKAGE)-dev.mft + @cd $(PACKAGE)-dev && \ + echo $(MANIFESTVERDEV) >> manifest/$(PACKAGE)-dev.ver && \ + echo $(MANIFESTVERDESC) >> manifest/$(PACKAGE)-dev.ver + +archive: + @echo " * Creation of the archives" + @tar cf $(PACKAGE)-bin.tar $(PACKAGE)-bin + @bzip2 -9 $(PACKAGE)-bin.tar + @tar cf $(PACKAGE)-dev.tar $(PACKAGE)-dev + @bzip2 -9 $(PACKAGE)-dev.tar + +clean: + @echo " * Cleaning" + @rm -rf $(PACKAGE)* + +help: + @echo + @echo "To create the archives, type:" + @echo " make" + @echo + @echo "To remove everything, type:" + @echo " make clean" + @echo diff --git a/libs/libpng-src/scripts/makefile.cygwin b/libs/libpng-src/scripts/makefile.cygwin new file mode 100644 index 000000000..4a1c7ada5 --- /dev/null +++ b/libs/libpng-src/scripts/makefile.cygwin @@ -0,0 +1,302 @@ +# makefile for cygwin on x86 +# Builds both dll (with import lib) and static lib versions +# of the library, and builds two copies of pngtest: one +# statically linked and one dynamically linked. +# +# Copyright (C) 2002, 2006-2008 Soren Anderson, Charles Wilson, +# and Glenn Randers-Pehrson, based on makefile for linux-elf w/mmx by: +# Copyright (C) 1998-2000 Greg Roelofs +# Copyright (C) 1996, 1997 Andreas Dilger +# +# This code is released under the libpng license. +# For conditions of distribution and use, see the disclaimer +# and license in png.h + +# This makefile intends to support building outside the src directory +# if desired. When invoking it, specify an argument to SRCDIR on the +# command line that points to the top of the directory where your source +# is located. + +ifdef SRCDIR +VPATH = $(SRCDIR) +else +SRCDIR = . +endif + +# Override DESTDIR= on the make install command line to easily support +# installing into a temporary location. Example: +# +# make install DESTDIR=/tmp/build/libpng +# +# If you're going to install into a temporary location +# via DESTDIR, $(DESTDIR)$(prefix) must already exist before +# you execute make install. + +DESTDIR= + +CC=gcc +ifdef MINGW +MINGW_CCFLAGS=-mno-cygwin -I/usr/include/mingw +MINGW_LDFLAGS=-mno-cygwin -L/usr/lib/mingw +endif + +# Where "make install" puts libpng*.a, *png*.dll, png.h, and pngconf.h +ifndef prefix +prefix=/usr +$(warning You haven't specified a 'prefix=' location. Defaulting to "/usr") +endif +exec_prefix=$(prefix) + +# Where the zlib library and include files are located +ZLIBLIB= /usr/lib +ZLIBINC= +#ZLIBLIB=../zlib +#ZLIBINC=../zlib + +ALIGN= +# for i386: +#ALIGN=-malign-loops=2 -malign-functions=2 + +WARNMORE=-Wwrite-strings -Wpointer-arith -Wshadow \ + -Wmissing-declarations -Wtraditional -Wcast-align \ + -Wstrict-prototypes -Wmissing-prototypes #-Wconversion + +### if you don't need thread safety, but want the asm accel +#CFLAGS= $(strip $(MINGW_CCFLAGS) -DPNG_THREAD_UNSAFE_OK \ +# $(addprefix -I,$(ZLIBINC)) -W -Wall -O $(ALIGN) -funroll-loops \ +# -fomit-frame-pointer) # $(WARNMORE) -g -DPNG_DEBUG=5 +### if you need thread safety and want (minimal) asm accel +#CFLAGS= $(strip $(MINGW_CCFLAGS) $(addprefix -I,$(ZLIBINC)) \ +# -W -Wall -O $(ALIGN) -funroll-loops \ +# -fomit-frame-pointer) # $(WARNMORE) -g -DPNG_DEBUG=5 +### Normal (non-asm) compilation +CFLAGS= $(strip $(MINGW_CCFLAGS) $(addprefix -I,$(ZLIBINC)) \ + -W -Wall -O3 $(ALIGN) -funroll-loops -DPNG_NO_MMX_CODE \ + -fomit-frame-pointer) # $(WARNMORE) -g -DPNG_DEBUG=5 + +LIBNAME = libpng12 +PNGMAJ = 0 +CYGDLL = 12 +PNGMIN = 1.2.46 +PNGVER = $(PNGMAJ).$(PNGMIN) + +SHAREDLIB=cygpng$(CYGDLL).dll +STATLIB=libpng.a +IMPLIB=libpng.dll.a +SHAREDDEF=libpng.def +LIBS=$(SHAREDLIB) $(STATLIB) +EXE=.exe + +LDFLAGS=$(strip -L. $(MINGW_LDFLAGS) -lpng $(addprefix -L,$(ZLIBLIB)) -lz) +LDSFLAGS=$(strip -shared -L. $(MINGW_LDFLAGS) -Wl,--export-all) +LDEXTRA=-Wl,--out-implib=$(IMPLIB) $(addprefix -L,$(ZLIBLIB)) -lz + +MKDIR_P=/bin/mkdir -pv +RANLIB=ranlib +#RANLIB=echo + +INCPATH=$(prefix)/include +LIBPATH=$(exec_prefix)/lib + +BINPATH=$(exec_prefix)/bin +MANPATH=$(prefix)/man +MAN3PATH=$(MANPATH)/man3 +MAN5PATH=$(MANPATH)/man5 + +# cosmetic: shortened strings: +S =$(SRCDIR) +D =$(DESTDIR) +DB =$(D)$(BINPATH) +DI =$(D)$(INCPATH) +DL =$(D)$(LIBPATH) + +OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \ + pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \ + pngwtran.o pngmem.o pngerror.o pngpread.o + +OBJSDLL = $(OBJS:.o=.pic.o) + +.SUFFIXES: .c .o .pic.o + +%.o : %.c + $(CC) -c $(CFLAGS) -o $@ $< +%.pic.o : CFLAGS += -DPNG_BUILD_DLL +%.pic.o : %.c + $(CC) -c $(CFLAGS) -o $@ $< + +all: all-static all-shared libpng.pc libpng-config libpng.pc libpng-config + +# Make this to verify that "make [...] install" will do what you want. +buildsetup-tell: + @echo VPATH is set to: \"$(VPATH)\" + @echo prefix is set to: \"$(prefix)\" + @echo -e INCPATH,LIBPATH, etc. are set to:'\n' \ + $(addprefix $(D),$(INCPATH)'\n' $(LIBPATH)'\n' $(BINPATH)'\n' \ + $(MANPATH)'\n' $(MAN3PATH)'\n' $(MAN5PATH)'\n')'\n' + +libpng.pc: scripts/libpng.pc.in + @echo -e Making pkg-config file for this libpng installation..'\n' \ + using PREFIX=\"$(prefix)\"'\n' + cat scripts/libpng.pc.in | sed -e s!@prefix@!$(prefix)! \ + -e s!@exec_prefix@!$(exec_prefix)! \ + -e s!@libdir@!$(LIBPATH)! \ + -e s!@includedir@!$(INCPATH)! \ + -e s!-lpng12!-lpng12\ -lz! > libpng.pc + +libpng-config: scripts/libpng-config-head.in scripts/libpng-config-body.in + @echo -e Making $(LIBNAME) libpng-config file for this libpng \ + installation..'\n' using PREFIX=\"$(prefix)\"'\n' + ( cat $(S)/scripts/libpng-config-head.in; \ + echo prefix=\"$(prefix)\"; \ + echo I_opts=\"-I$(INCPATH)/$(LIBNAME)\"; \ + echo L_opts=\"-L$(LIBPATH)\"; \ + echo libs=\"-lpng$(CYGDLL) -lz\"; \ + cat $(S)/scripts/libpng-config-body.in ) > libpng-config + chmod +x libpng-config + +static: all-static +shared: all-shared +all-static: $(STATLIB) pngtest-stat$(EXE) +all-shared: $(SHAREDLIB) pngtest$(EXE) + +$(STATLIB): $(OBJS) + ar rc $@ $(OBJS) + $(RANLIB) $@ + +$(SHAREDDEF): scripts/pngw32.def + cat $< | sed -e '1{G;s/^\(.*\)\(\n\)/EXPORTS/;};2,/^EXPORTS/d' | \ + sed -e 's/\([^;]*\);/;/' > $@ + +$(SHAREDLIB): $(OBJSDLL) $(SHAREDDEF) + $(CC) $(LDSFLAGS) -o $@ $(OBJSDLL) -L. $(LDEXTRA) + +pngtest$(EXE): pngtest.pic.o $(SHAREDLIB) + $(CC) $(CFLAGS) $< $(LDFLAGS) -o $@ + +pngtest-stat$(EXE): pngtest.o $(STATLIB) + $(CC) -static $(CFLAGS) $< $(LDFLAGS) -o $@ + +pngtest.pic.o: pngtest.c + $(CC) $(CFLAGS) -c $< -o $@ + +pngtest.o: pngtest.c png.h pngconf.h + $(CC) $(CFLAGS) -c $< -o $@ + +test: test-static test-shared + +test-static: pngtest-stat$(EXE) + ./pngtest-stat $(S)/pngtest.png + +test-shared: pngtest$(EXE) + ./pngtest $(S)/pngtest.png + +install-static: $(STATLIB) install-headers install-man + -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi + install -m 644 $(STATLIB) $(DL)/$(LIBNAME).a + -@rm -f $(DL)/$(STATLIB) + (cd $(DL); ln -sf $(LIBNAME).a $(STATLIB)) + +install-shared: $(SHAREDLIB) libpng.pc libpng-config install-headers install-man + -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi + -@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi + -@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi + -@/bin/rm -f $(DL)/pkgconfig/$(LIBNAME).pc + -@/bin/rm -f $(DL)/pkgconfig/libpng.pc + install -m 644 $(IMPLIB) $(DL)/$(LIBNAME).dll.a + -@rm -f $(DL)/$(IMPLIB) + (cd $(DL); ln -sf $(LIBNAME).dll.a $(IMPLIB)) + install -s -m 755 $(SHAREDLIB) $(DB) + install -m 644 libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc + (cd $(DL)/pkgconfig; ln -sf $(LIBNAME).pc libpng.pc) + +install-headers: + -@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi + -@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi + -@rm -f $(DI)/png.h + -@rm -f $(DI)/pngconf.h + install -m 644 $(S)/png.h $(S)/pngconf.h $(DI)/$(LIBNAME) + -@rm -f $(DI)/libpng + (cd $(DI); ln -sf $(LIBNAME) libpng; ln -sf $(LIBNAME)/* .) + +install-man: + -@if [ ! -d $(D)$(MAN3PATH) ]; then $(MKDIR_P) $(D)$(MAN3PATH); fi + -@if [ ! -d $(D)$(MAN5PATH) ]; then $(MKDIR_P) $(D)$(MAN5PATH); fi + install -m 644 $(S)/libpngpf.3 $(S)/libpng.3 $(D)$(MAN3PATH) + install -m 644 $(S)/png.5 $(D)$(MAN5PATH) + +install-config: libpng-config + -@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi + -@/bin/rm -f $(DB)/libpng-config + -@/bin/rm -f $(DB)/$(LIBNAME)-config + cp libpng-config $(DB)/$(LIBNAME)-config + chmod 755 $(DB)/$(LIBNAME)-config + (cd $(DB); ln -sf $(LIBNAME)-config libpng-config) + +# Run this to verify that a future `configure' run will pick up the settings +# you want. +test-config-install: SHELL=/bin/bash +test-config-install: $(DB)/libpng-config + @echo -e Testing libpng-config functions...'\n' + @ for TYRA in LDFLAGS CPPFLAGS CFLAGS LIBS VERSION; \ + do \ + printf "(%d)\t %10s =%s\n" $$(($$gytiu + 1)) $$TYRA \ + "$$($(DB)/libpng-config `echo --$$TYRA |tr '[:upper:]' '[:lower:]'`)"; \ + gytiu=$$(( $$gytiu + 1 )); \ + done + +install: install-static install-shared install-man install-config + +# If you installed in $(DESTDIR), test-installed won't work until you +# move the library to its final location. Use test-dd to test it +# before then. + +test-dd: + echo + echo Testing installed dynamic shared library in $(DL). + $(CC) -I$(DI) $(CFLAGS) \ + `$(BINPATH)/libpng12-config --cflags` pngtest.c \ + -L$(DL) -L$(ZLIBLIB) \ + -o pngtestd `$(BINPATH)/libpng12-config --ldflags` + ./pngtestd pngtest.png + +test-installed: + $(CC) $(CFLAGS) \ + `$(BINPATH)/libpng12-config --cflags` pngtest.c \ + -L$(ZLIBLIB) \ + -o pngtesti$(EXE) `$(BINPATH)/libpng12-config --ldflags` + ./pngtesti$(EXE) pngtest.png + +clean: + /bin/rm -f *.pic.o *.o $(STATLIB) $(IMPLIB) $(SHAREDLIB) \ + pngtest-stat$(EXE) pngtest$(EXE) pngout.png $(SHAREDDEF) \ + libpng-config libpng.pc pngtesti$(EXE) + +DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO +writelock: + chmod a-w *.[ch35] $(DOCS) scripts/* + +.PHONY: buildsetup-tell libpng.pc libpng-config test-config-install clean + +# DO NOT DELETE THIS LINE -- make depend depends on it. + +png.o png.pic.o: png.h pngconf.h png.c +pngerror.o pngerror.pic.o: png.h pngconf.h pngerror.c +pngrio.o pngrio.pic.o: png.h pngconf.h pngrio.c +pngwio.o pngwio.pic.o: png.h pngconf.h pngwio.c +pngmem.o pngmem.pic.o: png.h pngconf.h pngmem.c +pngset.o pngset.pic.o: png.h pngconf.h pngset.c +pngget.o pngget.pic.o: png.h pngconf.h pngget.c +pngread.o pngread.pic.o: png.h pngconf.h pngread.c +pngrtran.o pngrtran.pic.o: png.h pngconf.h pngrtran.c +pngrutil.o pngrutil.pic.o: png.h pngconf.h pngrutil.c +pngtrans.o pngtrans.pic.o: png.h pngconf.h pngtrans.c +pngwrite.o pngwrite.pic.o: png.h pngconf.h pngwrite.c +pngwtran.o pngwtran.pic.o: png.h pngconf.h pngwtran.c +pngwutil.o pngwutil.pic.o: png.h pngconf.h pngwutil.c +pngpread.o pngpread.pic.o: png.h pngconf.h pngpread.c + +pngtest.o: png.h pngconf.h pngtest.c +pngtest-stat.o: png.h pngconf.h pngtest.c + + + diff --git a/libs/libpng-src/scripts/makefile.darwin b/libs/libpng-src/scripts/makefile.darwin new file mode 100644 index 000000000..5b53046a3 --- /dev/null +++ b/libs/libpng-src/scripts/makefile.darwin @@ -0,0 +1,237 @@ +# makefile for libpng on Darwin / Mac OS X +# Copyright (C) 2002, 2004, 2006, 2008 Glenn Randers-Pehrson +# Copyright (C) 2001 Christoph Pfisterer +# derived from makefile.linux: +# Copyright (C) 1998, 1999 Greg Roelofs +# Copyright (C) 1996, 1997 Andreas Dilger +# +# This code is released under the libpng license. +# For conditions of distribution and use, see the disclaimer +# and license in png.h + +# where "make install" puts libpng.a, libpng12.dylib, png.h and pngconf.h +prefix=/usr/local +exec_prefix=$(prefix) + +# Where the zlib library and include files are located +#ZLIBLIB=/usr/local/lib +#ZLIBINC=/usr/local/include +ZLIBLIB=../zlib +ZLIBINC=../zlib + +# Library name: +LIBNAME = libpng12 +PNGMAJ = 12 +PNGMIN = 1.2.46 +PNGVER = $(PNGMAJ).$(PNGMIN) + +# Shared library names: +LIBSO=$(LIBNAME).dylib +LIBSOMAJ=$(LIBNAME).$(PNGMAJ).dylib +LIBSOVER=$(LIBNAME).$(PNGVER).dylib +OLDSO=libpng.dylib +OLDSOMAJ=libpng.3.dylib +OLDSOVER=libpng.3.$(PNGMIN).dylib + +# Utilities: +CC=cc +AR_RC=ar rc +MKDIR_P=mkdir -p +LN_SF=ln -sf +RANLIB=ranlib +RM_F=/bin/rm -f + +# CFLAGS=-I$(ZLIBINC) -W -Wall -O3 -funroll-loops -DPNG_NO_MMX_CODE +CFLAGS=-I$(ZLIBINC) -W -Wall -O -funroll-loops +LDFLAGS=-L. -L$(ZLIBLIB) -lpng12 -lz + +INCPATH=$(prefix)/include +LIBPATH=$(exec_prefix)/lib +MANPATH=$(prefix)/man +BINPATH=$(exec_prefix)/bin + +# override DESTDIR= on the make install command line to easily support +# installing into a temporary location. Example: +# +# make install DESTDIR=/tmp/build/libpng +# +# If you're going to install into a temporary location +# via DESTDIR, $(DESTDIR)$(prefix) must already exist before +# you execute make install. +DESTDIR= + +DB=$(DESTDIR)$(BINPATH) +DI=$(DESTDIR)$(INCPATH) +DL=$(DESTDIR)$(LIBPATH) +DM=$(DESTDIR)$(MANPATH) + +OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \ + pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \ + pngwtran.o pngmem.o pngerror.o pngpread.o + +OBJSDLL = $(OBJS:.o=.pic.o) + +.SUFFIXES: .c .o .pic.o + +.c.pic.o: + $(CC) -c $(CFLAGS) -fno-common -o $@ $*.c + +all: libpng.a $(LIBSO) pngtest libpng.pc libpng-config + +libpng.a: $(OBJS) + $(AR_RC) $@ $(OBJS) + $(RANLIB) $@ + +libpng.pc: + cat scripts/libpng.pc.in | sed -e s!@prefix@!$(prefix)! \ + -e s!@exec_prefix@!$(exec_prefix)! \ + -e s!@libdir@!$(LIBPATH)! \ + -e s!@includedir@!$(INCPATH)! \ + -e s!-lpng12!-lpng12\ -lz! > libpng.pc + +libpng-config: + ( cat scripts/libpng-config-head.in; \ + echo prefix=\"$(prefix)\"; \ + echo I_opts=\"-I$(INCPATH)/$(LIBNAME)\"; \ + echo L_opts=\"-L$(LIBPATH)\"; \ + echo libs=\"-lpng12 -lz\"; \ + cat scripts/libpng-config-body.in ) > libpng-config + chmod +x libpng-config + +$(LIBSO): $(LIBSOMAJ) + $(LN_SF) $(LIBSOMAJ) $(LIBSO) + +$(LIBSOMAJ): $(LIBSOVER) + $(LN_SF) $(LIBSOVER) $(LIBSOMAJ) + +$(LIBSOVER): $(OBJSDLL) + $(CC) -dynamiclib \ + -install_name $(LIBPATH)/$(LIBSOMAJ) \ + -current_version 0 -compatibility_version 0 \ + -o $(LIBSOVER) \ + $(OBJSDLL) -L$(ZLIBLIB) -lz + +$(OLDSOVER): $(OBJSDLL) + $(CC) -dynamiclib \ + -install_name $(LIBPATH)/$(OLDSOMAJ) \ + -current_version 3 -compatibility_version 3 \ + -o $(OLDSOVER) \ + $(OBJSDLL) -L$(ZLIBLIB) -lz + +pngtest: pngtest.o $(LIBSO) + $(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS) + +test: pngtest + ./pngtest + +install-headers: png.h pngconf.h + -@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi + -@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi + cp png.h pngconf.h $(DI)/$(LIBNAME) + chmod 644 $(DI)/$(LIBNAME)/png.h $(DI)/$(LIBNAME)/pngconf.h + -@$(RM_F) $(DI)/png.h $(DI)/pngconf.h + -@$(RM_F) $(DI)/libpng + (cd $(DI); $(LN_SF) $(LIBNAME) libpng; $(LN_SF) $(LIBNAME)/* .) + +install-static: install-headers libpng.a + -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi + cp libpng.a $(DL)/$(LIBNAME).a + chmod 644 $(DL)/$(LIBNAME).a + $(RANLIB) $(DL)/$(LIBNAME).a + -@$(RM_F) $(DL)/libpng.a + (cd $(DL); $(LN_SF) $(LIBNAME).a libpng.a) + +install-shared: install-headers $(LIBSO) libpng.pc \ + $(OLDSOVER) + -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi + -@$(RM_F) $(DL)/$(LIBNAME).$(PNGVER)*.dylib + -@$(RM_F) $(DL)/$(LIBNAME).$(PNGMAJ)*.dylib + -@$(RM_F) $(DL)/$(LIBSO) + -@$(RM_F) $(DL)/$(OLDSO) + -@$(RM_F) $(DL)/$(OLDSOMAJ) + -@$(RM_F) $(DL)/libpng.3.$(PNGMIN)*.dylib + cp $(LIBSOVER) $(DL) + cp $(OLDSOVER) $(DL) + chmod 755 $(DL)/$(LIBSOVER) + chmod 755 $(DL)/$(OLDSOVER) + (cd $(DL); \ + $(LN_SF) $(OLDSOVER) $(OLDSOMAJ); \ + $(LN_SF) $(OLDSOMAJ) $(OLDSO); \ + $(LN_SF) $(LIBSOVER) $(LIBSOMAJ); \ + $(LN_SF) $(LIBSOMAJ) $(LIBSO)) + -@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi + -@$(RM_F) $(DL)/pkgconfig/$(LIBNAME).pc + -@$(RM_F) $(DL)/pkgconfig/libpng.pc + cp libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc + chmod 644 $(DL)/pkgconfig/$(LIBNAME).pc + (cd $(DL)/pkgconfig; $(LN_SF) $(LIBNAME).pc libpng.pc) + +install-man: libpng.3 libpngpf.3 png.5 + -@if [ ! -d $(DM) ]; then $(MKDIR_P) $(DM); fi + -@if [ ! -d $(DM)/man3 ]; then $(MKDIR_P) $(DM)/man3; fi + -@$(RM_F) $(DM)/man3/libpng.3 + -@$(RM_F) $(DM)/man3/libpngpf.3 + cp libpng.3 $(DM)/man3 + cp libpngpf.3 $(DM)/man3 + -@if [ ! -d $(DM)/man5 ]; then $(MKDIR_P) $(DM)/man5; fi + -@$(RM_F) $(DM)/man5/png.5 + cp png.5 $(DM)/man5 + +install-config: libpng-config + -@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi + -@$(RM_F) $(DB)/libpng-config + -@$(RM_F) $(DB)/$(LIBNAME)-config + cp libpng-config $(DB)/$(LIBNAME)-config + chmod 755 $(DB)/$(LIBNAME)-config + (cd $(DB); $(LN_SF) $(LIBNAME)-config libpng-config) + +install: install-static install-shared install-man install-config + +# If you installed in $(DESTDIR), test-installed won't work until you +# move the library to its final location. Use test-dd to test it +# before then. + +test-dd: + echo + echo Testing installed dynamic shared library in $(DL). + $(CC) -I$(DI) -I$(ZLIBINC) \ + `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \ + -L$(DL) -L$(ZLIBLIB) \ + -o pngtestd `$(BINPATH)/$(LIBNAME)-config --ldflags` + ./pngtestd pngtest.png + +test-installed: + $(CC) $(CFLAGS) \ + `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \ + -L$(ZLIBLIB) \ + -o pngtesti `$(BINPATH)/$(LIBNAME)-config --ldflags` + ./pngtesti pngtest.png + +clean: + $(RM_F) *.o libpng.a pngtest pngout.png libpng-config \ + $(OLDSOVER) \ + libpng.pc $(LIBNAME).*dylib pngtesti + +DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO +writelock: + chmod a-w *.[ch35] $(DOCS) scripts/* + +# DO NOT DELETE THIS LINE -- make depend depends on it. + +png.o png.pic.o: png.h pngconf.h +pngerror.o pngerror.pic.o: png.h pngconf.h +pngrio.o pngrio.pic.o: png.h pngconf.h +pngwio.o pngwio.pic.o: png.h pngconf.h +pngmem.o pngmem.pic.o: png.h pngconf.h +pngset.o pngset.pic.o: png.h pngconf.h +pngget.o pngget.pic.o: png.h pngconf.h +pngread.o pngread.pic.o: png.h pngconf.h +pngrtran.o pngrtran.pic.o: png.h pngconf.h +pngrutil.o pngrutil.pic.o: png.h pngconf.h +pngtrans.o pngtrans.pic.o: png.h pngconf.h +pngwrite.o pngwrite.pic.o: png.h pngconf.h +pngwtran.o pngwtran.pic.o: png.h pngconf.h +pngwutil.o pngwutil.pic.o: png.h pngconf.h +pngpread.o pngpread.pic.o: png.h pngconf.h + +pngtest.o: png.h pngconf.h diff --git a/libs/libpng-src/scripts/makefile.dec b/libs/libpng-src/scripts/makefile.dec new file mode 100644 index 000000000..36bdd4f82 --- /dev/null +++ b/libs/libpng-src/scripts/makefile.dec @@ -0,0 +1,217 @@ +# makefile for libpng on DEC Alpha Unix +# Copyright (C) 2000-2002, 2006 Glenn Randers-Pehrson +# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc. +# +# This code is released under the libpng license. +# For conditions of distribution and use, see the disclaimer +# and license in png.h + +# Library name: +PNGMAJ = 0 +PNGMIN = 1.2.46 +PNGVER = $(PNGMAJ).$(PNGMIN) +LIBNAME = libpng12 + +# Shared library names: +LIBSO=$(LIBNAME).so +LIBSOMAJ=$(LIBNAME).so.$(PNGMAJ) +LIBSOVER=$(LIBNAME).so.$(PNGVER) +OLDSO=libpng.so +OLDSOMAJ=libpng.so.3 +OLDSOVER=libpng.so.3.$(PNGMIN) + +# Utilities: +AR_RC=ar rc +CC=cc +MKDIR_P=mkdir +LN_SF=ln -f -s +RANLIB=ranlib +RM_F=/bin/rm -f + +# where make install puts libpng.a and png.h +prefix=/usr/local +exec_prefix=$(prefix) +INCPATH=$(prefix)/include +LIBPATH=$(exec_prefix)/lib +MANPATH=$(prefix)/man +BINPATH=$(exec_prefix)/bin + +# override DESTDIR= on the make install command line to easily support +# installing into a temporary location. Example: +# +# make install DESTDIR=/tmp/build/libpng +# +# If you're going to install into a temporary location +# via DESTDIR, $(DESTDIR)$(prefix) must already exist before +# you execute make install. +DESTDIR= + +DB=$(DESTDIR)$(BINPATH) +DI=$(DESTDIR)$(INCPATH) +DL=$(DESTDIR)$(LIBPATH) +DM=$(DESTDIR)$(MANPATH) + +# Where the zlib library and include files are located +#ZLIBLIB=/usr/local/lib +#ZLIBINC=/usr/local/include +ZLIBLIB=../zlib +ZLIBINC=../zlib + +CFLAGS=-std -w1 -I$(ZLIBINC) -O # -g -DPNG_DEBUG=1 +LDFLAGS=-L$(ZLIBLIB) -rpath $(ZLIBLIB) libpng.a -lz -lm + +OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \ + pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \ + pngwtran.o pngmem.o pngerror.o pngpread.o + +all: $(LIBSO) libpng.a pngtest libpng.pc libpng-config + +libpng.a: $(OBJS) + $(AR_RC) $@ $(OBJS) + $(RANLIB) $@ + +libpng.pc: + cat scripts/libpng.pc.in | sed -e s!@prefix@!$(prefix)! \ + -e s!@exec_prefix@!$(exec_prefix)! \ + -e s!@libdir@!$(LIBPATH)! \ + -e s!@includedir@!$(INCPATH)! \ + -e s!-lpng12!-lpng12\ -lz\ -lm! > libpng.pc + +libpng-config: + ( cat scripts/libpng-config-head.in; \ + echo prefix=\"$(prefix)\"; \ + echo I_opts=\"-I$(INCPATH)/$(LIBNAME)\"; \ + echo ccopts=\"-std\"; \ + echo L_opts=\"-L$(LIBPATH)\"; \ + echo libs=\"-lpng12 -lz -lm\"; \ + cat scripts/libpng-config-body.in ) > libpng-config + chmod +x libpng-config + +$(LIBSO): $(LIBSOMAJ) + $(LN_SF) $(LIBSOMAJ) $(LIBSO) + +$(LIBSOMAJ): $(LIBSOVER) + $(LN_SF) $(LIBSOVER) $(LIBSOMAJ) + +$(LIBSOVER): $(OBJS) + $(CC) -shared -o $@ $(OBJS) -L$(ZLIBLIB) \ + -soname $(LIBSOMAJ) + +$(OLDSOVER): $(OBJS) + $(CC) -shared -o $@ $(OBJS) -L$(ZLIBLIB) \ + -soname $(OLDSOMAJ) + +pngtest: pngtest.o libpng.a + $(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS) + +test: pngtest + ./pngtest + +install-headers: png.h pngconf.h + -@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi + -@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi + cp png.h pngconf.h $(DI)/$(LIBNAME) + chmod 644 $(DI)/$(LIBNAME)/png.h $(DI)/$(LIBNAME)/pngconf.h + -@/bin/rm -f $(DI)/png.h $(DI)/pngconf.h + -@/bin/rm -f $(DI)/libpng + (cd $(DI); $(LN_SF)(LIBNAME) libpng; $(LN_SF)(LIBNAME)/* .) + +install-static: install-headers libpng.a + -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi + cp libpng.a $(DL)/$(LIBNAME).a + chmod 644 $(DL)/$(LIBNAME).a + -@/bin/rm -f $(DL)/libpng.a + (cd $(DL); $(LN_SF)(LIBNAME).a libpng.a) + +install-shared: install-headers $(LIBSOVER) libpng.pc \ + $(OLDSOVER) + -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi + -@/bin/rm -f $(DL)/$(LIBSOVER)* $(DL)/$(LIBSO) + -@/bin/rm -f $(DL)/$(LIBSOMAJ) + -@/bin/rm -f $(DL)/$(OLDSO) + -@/bin/rm -f $(DL)/$(OLDSOMAJ) + -@/bin/rm -f $(DL)/$(OLDSOVER)* + cp $(LIBSOVER) $(DL) + cp $(OLDSOVER) $(DL) + chmod 755 $(DL)/$(LIBSOVER) + chmod 755 $(DL)/$(OLDSOVER) + (cd $(DL); \ + $(LN_SF) $(OLDSOVER) $(OLDSOMAJ); \ + $(LN_SF) $(OLDSOMAJ) $(OLDSO); \ + $(LN_SF)(LIBSOVER) $(LIBSOMAJ); \ + $(LN_SF)(LIBSOMAJ) $(LIBSO)) + -@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi + -@/bin/rm -f $(DL)/pkgconfig/$(LIBNAME).pc + -@/bin/rm -f $(DL)/pkgconfig/libpng.pc + cp libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc + chmod 644 $(DL)/pkgconfig/$(LIBNAME).pc + (cd $(DL)/pkgconfig; $(LN_SF)(LIBNAME).pc libpng.pc) + +install-man: libpng.3 libpngpf.3 png.5 + -@if [ ! -d $(DM) ]; then $(MKDIR_P) $(DM); fi + -@if [ ! -d $(DM)/man3 ]; then $(MKDIR_P) $(DM)/man3; fi + -@/bin/rm -f $(DM)/man3/libpng.3 + -@/bin/rm -f $(DM)/man3/libpngpf.3 + cp libpng.3 $(DM)/man3 + cp libpngpf.3 $(DM)/man3 + -@if [ ! -d $(DM)/man5 ]; then $(MKDIR_P) $(DM)/man5; fi + -@/bin/rm -f $(DM)/man5/png.5 + cp png.5 $(DM)/man5 + +install-config: libpng-config + -@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi + -@/bin/rm -f $(DB)/libpng-config + -@/bin/rm -f $(DB)/$(LIBNAME)-config + cp libpng-config $(DB)/$(LIBNAME)-config + chmod 755 $(DB)/$(LIBNAME)-config + (cd $(DB); $(LN_SF)(LIBNAME)-config libpng-config) + +install: install-static install-shared install-man install-config + +# If you installed in $(DESTDIR), test-installed won't work until you +# move the library to its final location. Use test-dd to test it +# before then. + +test-dd: + echo + echo Testing installed dynamic shared library in $(DL). + $(CC) -w1 -I$(DI) -I$(ZLIBINC) \ + `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \ + -L$(DL) -L$(ZLIBLIB) -R$(ZLIBLIB) -R$(DL) \ + -o pngtestd `$(BINPATH)/$(LIBNAME)-config --ldflags` + ./pngtestd pngtest.png + +test-installed: + echo + echo Testing installed dynamic shared library. + $(CC) -w1 -I$(ZLIBINC) \ + `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \ + -L$(ZLIBLIB) -R$(ZLIBLIB) \ + -o pngtesti `$(BINPATH)/$(LIBNAME)-config --ldflags` + ./pngtesti pngtest.png + +clean: + /bin/rm -f *.o libpng.a pngtest pngtesti pngout.png \ + libpng-config $(LIBSO) $(LIBSOMAJ)* \ + $(OLDSOVER) \ + libpng.pc + +# DO NOT DELETE THIS LINE -- make depend depends on it. + +png.o: png.h pngconf.h +pngerror.o: png.h pngconf.h +pngrio.o: png.h pngconf.h +pngwio.o: png.h pngconf.h +pngmem.o: png.h pngconf.h +pngset.o: png.h pngconf.h +pngget.o: png.h pngconf.h +pngread.o: png.h pngconf.h +pngrtran.o: png.h pngconf.h +pngrutil.o: png.h pngconf.h +pngtrans.o: png.h pngconf.h +pngwrite.o: png.h pngconf.h +pngwtran.o: png.h pngconf.h +pngwutil.o: png.h pngconf.h +pngpread.o: png.h pngconf.h + +pngtest.o: png.h pngconf.h diff --git a/libs/libpng-src/scripts/makefile.dj2 b/libs/libpng-src/scripts/makefile.dj2 new file mode 100644 index 000000000..b8457ee49 --- /dev/null +++ b/libs/libpng-src/scripts/makefile.dj2 @@ -0,0 +1,58 @@ +# DJGPP (DOS gcc) makefile for libpng +# Copyright (C) 2002, 2006, 2009 Glenn Randers-Pehrson +# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc. +# +# This code is released under the libpng license. +# For conditions of distribution and use, see the disclaimer +# and license in png.h + +# where make install will put libpng.a and png.h +#prefix=/usr/local +prefix=. +INCPATH=$(prefix)/include +LIBPATH=$(prefix)/lib + +CC=gcc +CFLAGS=-I../zlib -O +LDFLAGS=-L. -L../zlib/ -lpng -lz -lm + +RANLIB=ranlib + +OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \ + pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o pngwtran.o \ + pngmem.o pngerror.o pngpread.o + +all: libpng.a pngtest + +libpng.a: $(OBJS) + ar rc $@ $(OBJS) + $(RANLIB) $@ + +pngtest: pngtest.o libpng.a + $(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS) + coff2exe pngtest + +test: pngtest + ./pngtest +clean: + rm -f *.o libpng.a pngtest pngout.png + +# DO NOT DELETE THIS LINE -- make depend depends on it. + +png.o: png.h pngconf.h +pngerror.o: png.h pngconf.h +pngrio.o: png.h pngconf.h +pngwio.o: png.h pngconf.h +pngmem.o: png.h pngconf.h +pngset.o: png.h pngconf.h +pngget.o: png.h pngconf.h +pngread.o: png.h pngconf.h +pngpread.o: png.h pngconf.h +pngrtran.o: png.h pngconf.h +pngrutil.o: png.h pngconf.h +pngtrans.o: png.h pngconf.h +pngwrite.o: png.h pngconf.h +pngwtran.o: png.h pngconf.h +pngwutil.o: png.h pngconf.h + +pngtest.o: png.h pngconf.h diff --git a/libs/libpng-src/scripts/makefile.elf b/libs/libpng-src/scripts/makefile.elf new file mode 100644 index 000000000..705db1ba2 --- /dev/null +++ b/libs/libpng-src/scripts/makefile.elf @@ -0,0 +1,279 @@ +# makefile for libpng.a and libpng12.so on Linux ELF with gcc +# Copyright (C) 1998, 1999, 2002, 2006, 2008 Greg Roelofs +# and Glenn Randers-Pehrson +# Copyright (C) 1996, 1997 Andreas Dilger +# +# This code is released under the libpng license. +# For conditions of distribution and use, see the disclaimer +# and license in png.h + +# Modified for Debian by Junichi Uekawa and Josselin Mouette +# Major modifications are: +# * link libpng explicitly with libz and libm +# * $(OLDSO).3 is a symlink rather than a different library +# * versioned symbols + +# Library name: +LIBNAME = libpng12 +PNGMAJ = 0 +PNGMIN = 1.2.46 +PNGVER = $(PNGMAJ).$(PNGMIN) + +# Shared library names: +LIBSO=$(LIBNAME).so +LIBSOMAJ=$(LIBNAME).so.$(PNGMAJ) +LIBSOVER=$(LIBNAME).so.$(PNGVER) +OLDSO=libpng.so +OLDSOMAJ=libpng.so.3 +OLDSOVER=libpng.so.3.$(PNGMIN) + +# Utilities: +AR_RC=ar rc +CC=gcc +MKDIR_P=mkdir -p +LN_SF=ln -sf +RANLIB=ranlib +RM_F=/bin/rm -f + +# where "make install" puts libpng12.a, libpng12.so*, +# libpng12/png.h and libpng12/pngconf.h +# Prefix must be a full pathname. +prefix=/usr/local +exec_prefix=$(prefix) + +# Where the zlib library and include files are located. +ZLIBLIB=/usr/local/lib +ZLIBINC=/usr/local/include +# ZLIBLIB=../zlib +# ZLIBINC=../zlib + +ALIGN= +# for i386: +#ALIGN=-malign-loops=2 -malign-functions=2 + +WARNMORE=-Wwrite-strings -Wpointer-arith -Wshadow \ + -Wmissing-declarations -Wtraditional -Wcast-align \ + -Wstrict-prototypes -Wmissing-prototypes #-Wconversion + +# for pgcc version 2.95.1, -O3 is buggy; don't use it. + +CFLAGS=-W -Wall -D_REENTRANT -O2 \ + $(ALIGN) # $(WARNMORE) -g -DPNG_DEBUG=5 + +LDFLAGS=-L. -lpng12 +LDFLAGS_A=libpng.a -lz -lm +LIBADDFLAGS=-lz -lm + + +INCPATH=$(prefix)/include +LIBPATH=$(exec_prefix)/lib +MANPATH=$(prefix)/man +BINPATH=$(exec_prefix)/bin + +# override DESTDIR= on the make install command line to easily support +# installing into a temporary location. Example: +# +# make install DESTDIR=/tmp/build/libpng +# +# If you're going to install into a temporary location +# via DESTDIR, $(DESTDIR)$(prefix) must already exist before +# you execute make install. +DESTDIR= + +DB=$(DESTDIR)$(BINPATH) +DI=$(DESTDIR)$(INCPATH) +DL=$(DESTDIR)$(LIBPATH) +DM=$(DESTDIR)$(MANPATH) + +OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \ + pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \ + pngwtran.o pngmem.o pngerror.o pngpread.o + +OBJSDLL = $(OBJS:.o=.pic.o) + +.SUFFIXES: .c .o .pic.o + +.c.pic.o: + $(CC) -c $(CFLAGS) -fPIC -o $@ $*.c + +all: libpng.a $(LIBSO) pngtest pngtest-static libpng.pc libpng-config + +libpng.a: $(OBJS) + $(AR_RC) $@ $(OBJS) + $(RANLIB) $@ + +libpng.pc: + cat scripts/libpng.pc.in | sed -e s!@prefix@!$(prefix)! \ + -e s!@exec_prefix@!$(exec_prefix)! \ + -e s!@libdir@!$(LIBPATH)! \ + -e s!@includedir@!$(INCPATH)! \ + -e s!-lpng12!-lpng12\ -lz\ -lm! > libpng.pc + +libpng.syms: png.h pngconf.h + $(CC) $(CFLAGS) -E -DPNG_BUILDSYMS -DPNG_INTERNAL png.h |\ + awk -F '[\t [\\]();]' -v PNGMAJ=$(PNGMAJ) 'BEGIN{printf("PNG12_%s {global:\n",PNGMAJ)}\ + { for (i=1;i+2<=NF;++i)\ + if ($$(i)=="PNG_FUNCTION_EXPORT" && $$(i+2)=="END")\ + print $$(i+1) ";";\ + for (i=1;i+1<=NF;++i)\ + if ($$(i)=="PNG_DATA_EXPORT")\ + print $$(i+1) ";";}\ + END{print "local: *; };"}' >$@.new + $(RM_F) $@ + mv $@.new $@ + +libpng-config: + ( cat scripts/libpng-config-head.in; \ + echo prefix=\"$(prefix)\"; \ + echo I_opts=\"-I$(INCPATH)/$(LIBNAME)\"; \ + echo L_opts=\"\"; \ + echo R_opts=\"\"; \ + echo libs=\"-lpng12\"; \ + echo all_libs=\"-lpng12 $(LIBADDFLAGS)\"; \ + cat scripts/libpng-config-body.in ) > libpng-config + chmod +x libpng-config + +$(LIBSO): $(LIBSOMAJ) + $(LN_SF) $(LIBSOMAJ) $(LIBSO) + +$(LIBSOMAJ): $(LIBSOVER) + $(LN_SF) $(LIBSOVER) $(LIBSOMAJ) + +$(LIBSOVER): $(OBJSDLL) libpng.syms + $(CC) -shared -Wl,-soname,$(LIBSOMAJ) \ + -Wl,-version-script,libpng.syms \ + -o $(LIBSOVER) \ + $(OBJSDLL) + +$(OLDSOVER): $(OBJSDLL) libpng.syms + $(CC) -shared -Wl,-soname,$(OLDSOMAJ) \ + -Wl,-version-script,libpng.syms \ + -o $(OLDSOVER) \ + $(OBJSDLL) + +pngtest: pngtest.o $(LIBSO) + $(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS) + +pngtest-static: pngtest.o libpng.a + $(CC) -o pngtest-static $(CFLAGS) pngtest.o $(LDFLAGS_A) + +test: pngtest pngtest-static + @echo "" + @echo " Running pngtest dynamically linked with $(LIBSO):" + @echo "" + LD_LIBRARY_PATH=".:${LD_LIBRARY_PATH}" ./pngtest + @echo "" + @echo " Running pngtest statically linked with libpng.a:" + @echo "" + ./pngtest-static + +install-headers: png.h pngconf.h + -@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi + -@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi + cp png.h pngconf.h $(DI)/$(LIBNAME) + chmod 644 $(DI)/$(LIBNAME)/png.h $(DI)/$(LIBNAME)/pngconf.h + -@$(RM_F) $(DI)/png.h $(DI)/pngconf.h + -@$(RM_F) $(DI)/libpng + (cd $(DI); $(LN_SF) $(LIBNAME) libpng; $(LN_SF) $(LIBNAME)/* .) + +install-static: install-headers libpng.a + -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi + cp libpng.a $(DL)/$(LIBNAME).a + chmod 644 $(DL)/$(LIBNAME).a + -@$(RM_F) $(DL)/libpng.a + (cd $(DL); $(LN_SF) $(LIBNAME).a libpng.a) + +install-shared: install-headers $(LIBSOVER) libpng.pc \ + $(OLDSOVER) + -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi + -@$(RM_F) $(DL)/$(LIBSOVER)* $(DL)/$(LIBSO) + -@$(RM_F) $(DL)/$(LIBSOMAJ) + -@$(RM_F) $(DL)/$(OLDSO) + -@$(RM_F) $(DL)/$(OLDSOMAJ) + -@$(RM_F) $(DL)/$(OLDSOVER)* + cp $(LIBSOVER) $(DL) + cp $(OLDSOVER) $(DL) + chmod 755 $(DL)/$(LIBSOVER) + chmod 755 $(DL)/$(OLDSOVER) + (cd $(DL); \ + $(LN_SF) $(OLDSOVER) $(OLDSOMAJ); \ + $(LN_SF) $(OLDSOMAJ) $(OLDSO); \ + $(LN_SF) $(LIBSOVER) $(LIBSOMAJ); \ + $(LN_SF) $(LIBSOMAJ) $(LIBSO)) + -@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi + -@$(RM_F) $(DL)/pkgconfig/$(LIBNAME).pc + -@$(RM_F) $(DL)/pkgconfig/libpng.pc + cp libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc + chmod 644 $(DL)/pkgconfig/$(LIBNAME).pc + (cd $(DL)/pkgconfig; $(LN_SF) $(LIBNAME).pc libpng.pc) + +install-man: libpng.3 libpngpf.3 png.5 + -@if [ ! -d $(DM) ]; then $(MKDIR_P) $(DM); fi + -@if [ ! -d $(DM)/man3 ]; then $(MKDIR_P) $(DM)/man3; fi + -@$(RM_F) $(DM)/man3/libpng.3 + -@$(RM_F) $(DM)/man3/libpngpf.3 + cp libpng.3 $(DM)/man3 + cp libpngpf.3 $(DM)/man3 + -@if [ ! -d $(DM)/man5 ]; then $(MKDIR_P) $(DM)/man5; fi + -@$(RM_F) $(DM)/man5/png.5 + cp png.5 $(DM)/man5 + +install-config: libpng-config + -@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi + -@$(RM_F) $(DB)/libpng-config + -@$(RM_F) $(DB)/$(LIBNAME)-config + cp libpng-config $(DB)/$(LIBNAME)-config + chmod 755 $(DB)/$(LIBNAME)-config + (cd $(DB); $(LN_SF) $(LIBNAME)-config libpng-config) + +install: install-static install-shared install-man install-config + +# If you installed in $(DESTDIR), test-installed won't work until you +# move the library to its final location. Use test-dd to test it +# before then. + +test-dd: + echo + echo Testing installed dynamic shared library in $(DL). + $(CC) -I$(DI) -I$(ZLIBINC) \ + `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \ + -L$(DL) -L$(ZLIBLIB) -Wl, -rpath,$(DL) -Wl,-rpath,$(ZLIBLIB) \ + -o pngtestd `$(BINPATH)/$(LIBNAME)-config --ldflags` + ./pngtestd pngtest.png + +test-installed: + $(CC) -I$(ZLIBINC) \ + `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \ + -L$(ZLIBLIB) -Wl,-rpath,$(ZLIBLIB) \ + -o pngtesti `$(BINPATH)/$(LIBNAME)-config --ldflags` + ./pngtesti pngtest.png + +clean: + $(RM_F) *.o libpng.a libpng.syms pngtest pngout.png libpng-config \ + $(LIBSO) $(LIBSOMAJ)* pngtest-static pngtesti \ + $(OLDSOVER) \ + libpng.pc + +DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO +writelock: + chmod a-w *.[ch35] $(DOCS) scripts/* + +# DO NOT DELETE THIS LINE -- make depend depends on it. + +png.o png.pic.o: png.h pngconf.h +pngerror.o pngerror.pic.o: png.h pngconf.h +pngrio.o pngrio.pic.o: png.h pngconf.h +pngwio.o pngwio.pic.o: png.h pngconf.h +pngmem.o pngmem.pic.o: png.h pngconf.h +pngset.o pngset.pic.o: png.h pngconf.h +pngget.o pngget.pic.o: png.h pngconf.h +pngread.o pngread.pic.o: png.h pngconf.h +pngrtran.o pngrtran.pic.o: png.h pngconf.h +pngrutil.o pngrutil.pic.o: png.h pngconf.h +pngtrans.o pngtrans.pic.o: png.h pngconf.h +pngwrite.o pngwrite.pic.o: png.h pngconf.h +pngwtran.o pngwtran.pic.o: png.h pngconf.h +pngwutil.o pngwutil.pic.o: png.h pngconf.h +pngpread.o pngpread.pic.o: png.h pngconf.h + +pngtest.o: png.h pngconf.h diff --git a/libs/libpng-src/scripts/makefile.freebsd b/libs/libpng-src/scripts/makefile.freebsd new file mode 100644 index 000000000..daf91bd99 --- /dev/null +++ b/libs/libpng-src/scripts/makefile.freebsd @@ -0,0 +1,51 @@ +# makefile for libpng under FreeBSD +# Copyright (C) 2002, 2007, 2009 Glenn Randers-Pehrson and Andrey A. Chernov +# +# This code is released under the libpng license. +# For conditions of distribution and use, see the disclaimer +# and license in png.h + +PREFIX?= /usr/local +SHLIB_VER?= 5 + +LIB= png +SHLIB_MAJOR= ${SHLIB_VER} +SHLIB_MINOR= 0 +NOPROFILE= YES +NOOBJ= YES + +# where make install puts libpng.a and png.h +DESTDIR= ${PREFIX} +LIBDIR= /lib +INCS= png.h pngconf.h +INCSDIR= /include/libpng +INCDIR= ${INCSDIR} # for 4.x bsd.lib.mk +MAN= libpng.3 libpngpf.3 png.5 +MANDIR= /man/man +SYMLINKS= libpng/png.h ${INCSDIR}/../png.h \ + libpng/pngconf.h ${INCSDIR}/../pngconf.h +LDADD+= -lm -lz +DPADD+= ${LIBM} ${LIBZ} + +CFLAGS+= -I. +.if (${MACHINE_ARCH} != "i386") +CFLAGS+= -DPNG_CONFIGURE_LIBPNG -DPNG_NO_MMX_CODE +.endif + +SRCS= png.c pngset.c pngget.c pngrutil.c pngtrans.c pngwutil.c \ + pngread.c pngrio.c pngwio.c pngwrite.c pngrtran.c \ + pngwtran.c pngmem.c pngerror.c pngpread.c + +pngtest: pngtest.o libpng.a + ${CC} ${CFLAGS} -L. -static -o pngtest pngtest.o -lpng -lz -lm + +CLEANFILES= pngtest pngtest.o pngout.png + +test: pngtest + ./pngtest + +DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO +writelock: + chmod a-w *.[ch35] $(DOCS) scripts/* + +.include diff --git a/libs/libpng-src/scripts/makefile.gcc b/libs/libpng-src/scripts/makefile.gcc new file mode 100644 index 000000000..ed7cd8668 --- /dev/null +++ b/libs/libpng-src/scripts/makefile.gcc @@ -0,0 +1,83 @@ +# makefile for libpng using gcc (generic, static library) +# Copyright (C) 2008 Glenn Randers-Pehrson +# Copyright (C) 2000 Cosmin Truta +# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc. +# +# This code is released under the libpng license. +# For conditions of distribution and use, see the disclaimer +# and license in png.h + +# Location of the zlib library and include files +ZLIBINC = ../zlib +ZLIBLIB = ../zlib + +# Compiler, linker, lib and other tools +CC = gcc +LD = $(CC) +AR_RC = ar rcs +RANLIB = ranlib +RM_F = rm -f + +CDEBUG = -g -DPNG_DEBUG=5 +LDDEBUG = +CRELEASE = -O2 +LDRELEASE = -s +#CFLAGS = -W -Wall $(CDEBUG) +CFLAGS = -W -Wall $(CRELEASE) +#LDFLAGS = $(LDDEBUG) +LDFLAGS = $(LDRELEASE) +LIBS = -lz -lm + +# File extensions +O=.o +A=.a +EXE= + +# Variables +OBJS = png$(O) pngerror$(O) pngget$(O) pngmem$(O) pngpread$(O) \ + pngread$(O) pngrio$(O) pngrtran$(O) pngrutil$(O) pngset$(O) \ + pngtrans$(O) pngwio$(O) pngwrite$(O) pngwtran$(O) pngwutil$(O) + +# Targets +all: static + +.c$(O): + $(CC) -c $(CFLAGS) -I$(ZLIBINC) $< + +static: libpng$(A) pngtest$(EXE) + +shared: + @echo This is a generic makefile that cannot create shared libraries. + @echo Please use a configuration that is specific to your platform. + @false + +libpng$(A): $(OBJS) + $(AR_RC) $@ $(OBJS) + $(RANLIB) $@ + +test: pngtest$(EXE) + ./pngtest$(EXE) + +pngtest$(EXE): pngtest$(O) libpng$(A) + $(LD) $(LDFLAGS) -L$(ZLIBLIB) -o $@ pngtest$(O) libpng$(A) $(LIBS) + +clean: + $(RM_F) *$(O) libpng$(A) pngtest$(EXE) pngout.png + +png$(O): png.h pngconf.h +pngerror$(O): png.h pngconf.h +pngget$(O): png.h pngconf.h +pngmem$(O): png.h pngconf.h +pngpread$(O): png.h pngconf.h +pngread$(O): png.h pngconf.h +pngrio$(O): png.h pngconf.h +pngrtran$(O): png.h pngconf.h +pngrutil$(O): png.h pngconf.h +pngset$(O): png.h pngconf.h +pngtrans$(O): png.h pngconf.h +pngwio$(O): png.h pngconf.h +pngwrite$(O): png.h pngconf.h +pngwtran$(O): png.h pngconf.h +pngwutil$(O): png.h pngconf.h + +pngtest$(O): png.h pngconf.h diff --git a/libs/libpng-src/scripts/makefile.gcmmx b/libs/libpng-src/scripts/makefile.gcmmx new file mode 100644 index 000000000..c5402e949 --- /dev/null +++ b/libs/libpng-src/scripts/makefile.gcmmx @@ -0,0 +1,274 @@ +# makefile for libpng.a and libpng12.so on Linux ELF with gcc using MMX +# assembler code +# Copyright 2002, 2006, 2008 Greg Roelofs and Glenn Randers-Pehrson +# Copyright 1998-2001 Greg Roelofs +# Copyright 1996-1997 Andreas Dilger + +# This code is released under the libpng license. +# For conditions of distribution and use, see the disclaimer +# and license in png.h + +# CAUTION: Do not use this makefile with gcc versions 2.7.2.2 and earlier. + +# NOTE: When testing MMX performance on a multitasking system, make sure +# there are no floating-point programs (e.g., SETI@Home) running in +# the background! Context switches between MMX and FPU are expensive. + +# Library name: +LIBNAME = libpng12 +PNGMAJ = 0 +PNGMIN = 1.2.46 +PNGVER = $(PNGMAJ).$(PNGMIN) + +# Shared library names: +LIBSO=$(LIBNAME).so +LIBSOMAJ=$(LIBNAME).so.$(PNGMAJ) +LIBSOVER=$(LIBNAME).so.$(PNGVER) +OLDSO=libpng.so +OLDSOMAJ=libpng.so.3 +OLDSOVER=libpng.so.3.$(PNGMIN) + +# Utilities: +CC = gcc +LD = $(CC) +AR_RC = ar rc +LN_SF = ln -sf +MKDIR_P = mkdir -p +RANLIB = ranlib +RM_F = /bin/rm -f + +# where "make install" puts libpng12.a, libpng12.so*, +# libpng12/png.h and libpng12/pngconf.h +# Prefix must be a full pathname. +prefix=/usr/local +exec_prefix=$(prefix) + +# Where the zlib library and include files are located. +#ZLIBLIB=/usr/local/lib +#ZLIBINC=/usr/local/include +ZLIBLIB=../zlib +ZLIBINC=../zlib + +ALIGN= +# for i386: +#ALIGN=-malign-loops=2 -malign-functions=2 + +WARNMORE=-Wwrite-strings -Wpointer-arith -Wshadow \ + -Wmissing-declarations -Wtraditional -Wcast-align \ + -Wstrict-prototypes -Wmissing-prototypes #-Wconversion + +# for pgcc version 2.95.1, -O3 is buggy; don't use it. + +# Remove -DPNG_THREAD_UNSAFE_OK if you need thread safety +### for generic gcc: +CFLAGS=-DPNG_THREAD_UNSAFE_OK -I$(ZLIBINC) -W -Wall -O \ + $(ALIGN) -funroll-loops \ + -fomit-frame-pointer # $(WARNMORE) -g -DPNG_DEBUG=5 +### for gcc 2.95.2 on 686: +#CFLAGS=-DPNG_THREAD_UNSAFE_OK -I$(ZLIBINC) -W -Wall -O \ +# -mcpu=i686 -malign-double -ffast-math -fstrict-aliasing \ +# $(ALIGN) -funroll-loops -funroll-all-loops -fomit-frame-pointer +### for gcc 2.7.2.3 on 486 and up: +#CFLAGS=-DPNG_THREAD_UNSAFE_OK -I$(ZLIBINC) -W -Wall -O \ +# -m486 -malign-double -ffast-math \ +# $(ALIGN) -funroll-loops -funroll-all-loops -fomit-frame-pointer + +LDFLAGS=-L. -Wl,-rpath,. -L$(ZLIBLIB) -Wl,-rpath,$(ZLIBLIB) -lpng12 -lz -lm +LDFLAGS_A=-L$(ZLIBLIB) -Wl,-rpath,$(ZLIBLIB) libpng.a -lz -lm + + +INCPATH=$(prefix)/include +LIBPATH=$(exec_prefix)/lib +MANPATH=$(prefix)/man +BINPATH=$(exec_prefix)/bin + +# override DESTDIR= on the make install command line to easily support +# installing into a temporary location. Example: +# +# make install DESTDIR=/tmp/build/libpng +# +# If you're going to install into a temporary location +# via DESTDIR, $(DESTDIR)$(prefix) must already exist before +# you execute make install. +DESTDIR= + +DB=$(DESTDIR)$(BINPATH) +DI=$(DESTDIR)$(INCPATH) +DL=$(DESTDIR)$(LIBPATH) +DM=$(DESTDIR)$(MANPATH) + +OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \ + pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \ + pngwtran.o pngmem.o pngerror.o pngpread.o + +OBJSDLL = $(OBJS:.o=.pic.o) + +.SUFFIXES: .c .o .pic.o + +.c.pic.o: + $(CC) -c $(CFLAGS) -fPIC -o $@ $*.c + +all: libpng.a $(LIBSO) pngtest pngtest-static libpng.pc libpng-config + +libpng.a: $(OBJS) + $(AR_RC) $@ $(OBJS) + $(RANLIB) $@ + +libpng.pc: + cat scripts/libpng.pc.in | sed -e s!@prefix@!$(prefix)! \ + -e s!@exec_prefix@!$(exec_prefix)! \ + -e s!@libdir@!$(LIBPATH)! \ + -e s!@includedir@!$(INCPATH)! \ + -e s!-lpng12!-lpng12\ -lz\ -lm! > libpng.pc + +libpng-config: + ( cat scripts/libpng-config-head.in; \ + echo prefix=\"$(prefix)\"; \ + echo I_opts=\"-I$(INCPATH)/$(LIBNAME)\"; \ + echo cppflags=\"-DPNG_THREAD_UNSAFE_OK \"; \ + echo L_opts=\"-L$(LIBPATH)\"; \ + echo R_opts=\"-Wl,-rpath,$(LIBPATH)\"; \ + echo libs=\"-lpng12 -lz -lm\"; \ + cat scripts/libpng-config-body.in ) > libpng-config + chmod +x libpng-config + +$(LIBSO): $(LIBSOMAJ) + $(LN_SF) $(LIBSOMAJ) $(LIBSO) + +$(LIBSOMAJ): $(LIBSOVER) + $(LN_SF) $(LIBSOVER) $(LIBSOMAJ) + +$(LIBSOVER): $(OBJSDLL) + $(CC) -shared -Wl,-soname,$(LIBSOMAJ) \ + -o $(LIBSOVER) \ + $(OBJSDLL) + +$(OLDSOVER): $(OBJSDLL) + $(CC) -shared -Wl,-soname,$(OLDSOMAJ) \ + -o $(OLDSOVER) \ + $(OBJSDLL) + +pngtest: pngtest.o $(LIBSO) + $(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS) + +pngtest-static: pngtest.o libpng.a + $(CC) -o pngtest-static $(CFLAGS) pngtest.o $(LDFLAGS_A) + +test: pngtest pngtest-static + @echo "" + @echo " Running pngtest dynamically linked with $(LIBSO):" + @echo "" + ./pngtest + @echo "" + @echo " Running pngtest statically linked with libpng.a:" + @echo "" + ./pngtest-static + +install-headers: png.h pngconf.h + -@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi + -@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi + cp png.h pngconf.h $(DI)/$(LIBNAME) + chmod 644 $(DI)/$(LIBNAME)/png.h $(DI)/$(LIBNAME)/pngconf.h + -@$(RM_F) $(DI)/png.h $(DI)/pngconf.h + -@$(RM_F) $(DI)/libpng + (cd $(DI); $(LN_SF) $(LIBNAME) libpng; $(LN_SF) $(LIBNAME)/* .) + +install-static: install-headers libpng.a + -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi + cp libpng.a $(DL)/$(LIBNAME).a + chmod 644 $(DL)/$(LIBNAME).a + -@$(RM_F) $(DL)/libpng.a + (cd $(DL); $(LN_SF) $(LIBNAME).a libpng.a) + +install-shared: install-headers $(LIBSOVER) libpng.pc \ + $(OLDSOVER) + -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi + -@$(RM_F) $(DL)/$(LIBSOVER)* $(DL)/$(LIBSO) + -@$(RM_F) $(DL)/$(LIBSOMAJ) + -@$(RM_F) $(DL)/$(OLDSO) + -@$(RM_F) $(DL)/$(OLDSOMAJ) + -@$(RM_F) $(DL)/$(OLDSOVER)* + cp $(LIBSOVER) $(DL) + cp $(OLDSOVER) $(DL) + chmod 755 $(DL)/$(LIBSOVER) + chmod 755 $(DL)/$(OLDSOVER) + (cd $(DL); \ + $(LN_SF) $(OLDSOVER) $(OLDSOMAJ); \ + $(LN_SF) $(OLDSOMAJ) $(OLDSO); \ + $(LN_SF) $(LIBSOVER) $(LIBSOMAJ); \ + $(LN_SF) $(LIBSOMAJ) $(LIBSO)) + -@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi + -@$(RM_F) $(DL)/pkgconfig/$(LIBNAME).pc + -@$(RM_F) $(DL)/pkgconfig/libpng.pc + cp libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc + chmod 644 $(DL)/pkgconfig/$(LIBNAME).pc + (cd $(DL)/pkgconfig; $(LN_SF) $(LIBNAME).pc libpng.pc) + +install-man: libpng.3 libpngpf.3 png.5 + -@if [ ! -d $(DM) ]; then $(MKDIR_P) $(DM); fi + -@if [ ! -d $(DM)/man3 ]; then $(MKDIR_P) $(DM)/man3; fi + -@$(RM_F) $(DM)/man3/libpng.3 + -@$(RM_F) $(DM)/man3/libpngpf.3 + cp libpng.3 $(DM)/man3 + cp libpngpf.3 $(DM)/man3 + -@if [ ! -d $(DM)/man5 ]; then $(MKDIR_P) $(DM)/man5; fi + -@$(RM_F) $(DM)/man5/png.5 + cp png.5 $(DM)/man5 + +install-config: libpng-config + -@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi + -@$(RM_F) $(DB)/libpng-config + -@$(RM_F) $(DB)/$(LIBNAME)-config + cp libpng-config $(DB)/$(LIBNAME)-config + chmod 755 $(DB)/$(LIBNAME)-config + (cd $(DB); $(LN_SF) $(LIBNAME)-config libpng-config) + +install: install-static install-shared install-man install-config + +# If you installed in $(DESTDIR), test-installed won't work until you +# move the library to its final location. Use test-dd to test it +# before then. + +test-dd: + echo + echo Testing installed dynamic shared library in $(DL). + $(CC) -I$(DI) -I$(ZLIBINC) \ + `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \ + -L$(DL) -L$(ZLIBLIB) -Wl, -rpath,$(DL) -Wl,-rpath,$(ZLIBLIB) \ + -o pngtestd `$(BINPATH)/$(LIBNAME)-config --ldflags` + ./pngtestd pngtest.png + +test-installed: + $(CC) -I$(ZLIBINC) \ + `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \ + -L$(ZLIBLIB) -Wl,-rpath,$(ZLIBLIB) \ + -o pngtesti `$(BINPATH)/$(LIBNAME)-config --ldflags` + ./pngtesti pngtest.png + +clean: + $(RM_F) *.o libpng.a pngtest pngout.png libpng-config \ + $(LIBSO) $(LIBSOMAJ)* pngtest-static pngtesti \ + $(OLDSOVER) \ + libpng.pc + +DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO +writelock: + chmod a-w *.[ch35] $(DOCS) scripts/* + +png.o png.pic.o: png.h pngconf.h png.c +pngerror.o pngerror.pic.o: png.h pngconf.h pngerror.c +pngrio.o pngrio.pic.o: png.h pngconf.h pngrio.c +pngwio.o pngwio.pic.o: png.h pngconf.h pngwio.c +pngmem.o pngmem.pic.o: png.h pngconf.h pngmem.c +pngset.o pngset.pic.o: png.h pngconf.h pngset.c +pngget.o pngget.pic.o: png.h pngconf.h pngget.c +pngread.o pngread.pic.o: png.h pngconf.h pngread.c +pngrtran.o pngrtran.pic.o: png.h pngconf.h pngrtran.c +pngrutil.o pngrutil.pic.o: png.h pngconf.h pngrutil.c +pngtrans.o pngtrans.pic.o: png.h pngconf.h pngtrans.c +pngwrite.o pngwrite.pic.o: png.h pngconf.h pngwrite.c +pngwtran.o pngwtran.pic.o: png.h pngconf.h pngwtran.c +pngwutil.o pngwutil.pic.o: png.h pngconf.h pngwutil.c +pngpread.o pngpread.pic.o: png.h pngconf.h pngpread.c + +pngtest.o: png.h pngconf.h pngtest.c diff --git a/libs/libpng-src/scripts/makefile.hp64 b/libs/libpng-src/scripts/makefile.hp64 new file mode 100644 index 000000000..b693f75ef --- /dev/null +++ b/libs/libpng-src/scripts/makefile.hp64 @@ -0,0 +1,239 @@ +# makefile for libpng, HPUX (10.20 and 11.00) using the ANSI/C product. +# Copyright (C) 1999-2002, 2006, 2009 Glenn Randers-Pehrson +# Copyright (C) 1995 Guy Eric Schalnat, Group 42 +# contributed by Jim Rice and updated by Chris Schleicher, Hewlett Packard +# +# This code is released under the libpng license. +# For conditions of distribution and use, see the disclaimer +# and license in png.h + +# Where the zlib library and include files are located +ZLIBLIB=/opt/zlib/lib +ZLIBINC=/opt/zlib/include + +# Note that if you plan to build a libpng shared library, zlib must also +# be a shared library, which zlib's configure does not do. After running +# zlib's configure, edit the appropriate lines of makefile to read: +# CFLAGS=-O1 -DHAVE_UNISTD -DUSE_MAP -fPIC \ +# LDSHARED=ld -b +# SHAREDLIB=libz.sl + +# Library name: +LIBNAME = libpng12 +PNGMAJ = 0 +PNGMIN = 1.2.46 +PNGVER = $(PNGMAJ).$(PNGMIN) + +# Shared library names: +LIBSO=$(LIBNAME).sl +LIBSOMAJ=$(LIBNAME).sl.$(PNGMAJ) +LIBSOVER=$(LIBNAME).sl.$(PNGVER) +OLDSO=libpng.sl +OLDSOMAJ=libpng.sl.3 +OLDSOVER=libpng.sl.3.$(PNGMIN) + +# Utilities: +AR_RC=ar rc +CC=cc +MKDIR_P=mkdir -p +LN_SF=ln -sf +RANLIB=ranlib +RM_F=/bin/rm -f + +CFLAGS=-I$(ZLIBINC) -O -Ae -Wl,+vnocompatwarnings +DD64 \ +-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 +Z -DHAVE_UNISTD_H -DUSE_MMAP +# Caution: be sure you have built zlib with the same CFLAGS. +CCFLAGS=-I$(ZLIBINC) -O -Ae -Wl,+vnocompatwarnings +DD64 \ +-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 +Z -DHAVE_UNISTD_H -DUSE_MMAP + +LDFLAGS=-L. -L$(ZLIBLIB) -lpng -lz -lm + +# where make install puts libpng.a, libpng12.sl, and png.h +prefix=/opt/libpng +exec_prefix=$(prefix) +INCPATH=$(prefix)/include +LIBPATH=$(exec_prefix)/lib +MANPATH=$(prefix)/man +BINPATH=$(exec_prefix)/bin + +# override DESTDIR= on the make install command line to easily support +# installing into a temporary location. Example: +# +# make install DESTDIR=/tmp/build/libpng +# +# If you're going to install into a temporary location +# via DESTDIR, $(DESTDIR)$(prefix) must already exist before +# you execute make install. +DESTDIR= + +DB=$(DESTDIR)$(BINPATH) +DI=$(DESTDIR)$(INCPATH) +DL=$(DESTDIR)$(LIBPATH) +DM=$(DESTDIR)$(MANPATH) + +OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \ + pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \ + pngwtran.o pngmem.o pngerror.o pngpread.o + +OBJSDLL = $(OBJS:.o=.pic.o) + +.SUFFIXES: .c .o .pic.o + +.c.pic.o: + $(CC) -c $(CFLAGS) +z -o $@ $*.c + +all: libpng.a $(LIBSO) pngtest libpng.pc libpng-config + +libpng.a: $(OBJS) + $(AR_RC) $@ $(OBJS) + $(RANLIB) $@ + +libpng.pc: + cat scripts/libpng.pc.in | sed -e s!@prefix@!$(prefix)! \ + -e s!@exec_prefix@!$(exec_prefix)! \ + -e s!@libdir@!$(LIBPATH)! \ + -e s!@includedir@!$(INCPATH)! \ + -e s!-lpng12!-lpng12\ -lz\ -lm! > libpng.pc + +libpng-config: + ( cat scripts/libpng-config-head.in; \ + echo prefix=\"$(prefix)\"; \ + echo I_opts=\"-I$(INCPATH)/$(LIBNAME)\"; \ + echo ccopts=\"-Ae +DA1.1 +DS2.0\"; \ + echo L_opts=\"-L$(LIBPATH)\"; \ + echo libs=\"-lpng12 -lz -lm\"; \ + cat scripts/libpng-config-body.in ) > libpng-config + chmod +x libpng-config + +$(LIBSO): $(LIBSOMAJ) + $(LN_SF) $(LIBSOMAJ) $(LIBSO) + +$(LIBSOMAJ): $(LIBSOVER) + $(LN_SF) $(LIBSOVER) $(LIBSOMAJ) + +$(LIBSOVER): $(OBJSDLL) + $(LD) -b +s \ + +h $(LIBSOMAJ) -o $(LIBSOVER) $(OBJSDLL) + +$(OLDSOVER): $(OBJSDLL) + $(LD) -b +s \ + +h $(OLDSOMAJ) -o $(OLDSOVER) $(OBJSDLL) + +pngtest: pngtest.o libpng.a + $(CC) -o pngtest $(CCFLAGS) pngtest.o $(LDFLAGS) + +test: pngtest + ./pngtest + +install-headers: png.h pngconf.h + -@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi + -@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi + cp png.h pngconf.h $(DI)/$(LIBNAME) + chmod 644 $(DI)/$(LIBNAME)/png.h $(DI)/$(LIBNAME)/pngconf.h + -@$(RM_F) $(DI)/png.h $(DI)/pngconf.h + -@$(RM_F) $(DI)/libpng + (cd $(DI); $(LN_SF) $(LIBNAME) libpng; $(LN_SF) $(LIBNAME)/* .) + +install-static: install-headers libpng.a + -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi + cp libpng.a $(DL)/$(LIBNAME).a + chmod 644 $(DL)/$(LIBNAME).a + -@$(RM_F) $(DL)/libpng.a + (cd $(DL); $(LN_SF) $(LIBNAME).a libpng.a) + +install-shared: install-headers $(LIBSOVER) libpng.pc \ + $(OLDSOVER) + -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi + -@$(RM_F) $(DL)/$(LIBSOVER)* $(DL)/$(LIBSO) + -@$(RM_F) $(DL)/$(LIBSOMAJ) + -@$(RM_F) $(DL)/$(OLDSO) + -@$(RM_F) $(DL)/$(OLDSOMAJ) + -@$(RM_F) $(DL)/$(OLDSOVER)* + cp $(LIBSOVER) $(DL) + cp $(OLDSOVER) $(DL) + chmod 755 $(DL)/$(LIBSOVER) + chmod 755 $(DL)/$(OLDSOVER) + (cd $(DL); \ + $(LN_SF) $(OLDSOVER) $(OLDSOMAJ); \ + $(LN_SF) $(OLDSOMAJ) $(OLDSO); \ + $(LN_SF) $(LIBSOVER) $(LIBSOMAJ); \ + $(LN_SF) $(LIBSOMAJ) $(LIBSO)) + -@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi + -@$(RM_F) $(DL)/pkgconfig/$(LIBNAME).pc + -@$(RM_F) $(DL)/pkgconfig/libpng.pc + cp libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc + chmod 644 $(DL)/pkgconfig/$(LIBNAME).pc + (cd $(DL)/pkgconfig; $(LN_SF) $(LIBNAME).pc libpng.pc) + +install-man: libpng.3 libpngpf.3 png.5 + -@if [ ! -d $(DM) ]; then $(MKDIR_P) $(DM); fi + -@if [ ! -d $(DM)/man3 ]; then $(MKDIR_P) $(DM)/man3; fi + -@$(RM_F) $(DM)/man3/libpng.3 + -@$(RM_F) $(DM)/man3/libpngpf.3 + cp libpng.3 $(DM)/man3 + cp libpngpf.3 $(DM)/man3 + -@if [ ! -d $(DM)/man5 ]; then $(MKDIR_P) $(DM)/man5; fi + -@$(RM_F) $(DM)/man5/png.5 + cp png.5 $(DM)/man5 + +install-config: libpng-config + -@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi + -@$(RM_F) $(DB)/libpng-config + -@$(RM_F) $(DB)/$(LIBNAME)-config + cp libpng-config $(DB)/$(LIBNAME)-config + chmod 755 $(DB)/$(LIBNAME)-config + (cd $(DB); $(LN_SF) $(LIBNAME)-config libpng-config) + +install: install-static install-shared install-man install-config + +# If you installed in $(DESTDIR), test-installed won't work until you +# move the library to its final location. Use test-dd to test it +# before then. + +test-dd: + echo + echo Testing installed dynamic shared library in $(DL). + $(CC) -I$(DI) -I$(ZLIBINC) $(CCFLAGS) \ + `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \ + -L$(DL) -L$(ZLIBLIB) \ + -o pngtestd `$(BINPATH)/$(LIBNAME)-config --ldflags` + ./pngtestd pngtest.png + +test-installed: + echo + echo Testing installed dynamic shared library. + $(CC) $(CCFLAGS) \ + `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \ + -L$(ZLIBLIB) \ + -o pngtesti `$(BINPATH)/$(LIBNAME)-config --ldflags` + ./pngtesti pngtest.png + +clean: + $(RM_F) *.o libpng.a pngtest pngtesti pngout.png \ + libpng-config $(LIBSO) $(LIBSOMAJ)* \ + $(OLDSOVER) \ + libpng.pc + +DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO +writelock: + chmod a-w *.[ch35] $(DOCS) scripts/* + +# DO NOT DELETE THIS LINE -- make depend depends on it. + +png.o: png.h pngconf.h +pngerror.o: png.h pngconf.h +pngrio.o: png.h pngconf.h +pngwio.o: png.h pngconf.h +pngmem.o: png.h pngconf.h +pngset.o: png.h pngconf.h +pngget.o: png.h pngconf.h +pngread.o: png.h pngconf.h +pngrtran.o: png.h pngconf.h +pngrutil.o: png.h pngconf.h +pngtrans.o: png.h pngconf.h +pngwrite.o: png.h pngconf.h +pngwtran.o: png.h pngconf.h +pngwutil.o: png.h pngconf.h +pngpread.o: png.h pngconf.h + +pngtest.o: png.h pngconf.h diff --git a/libs/libpng-src/scripts/makefile.hpgcc b/libs/libpng-src/scripts/makefile.hpgcc new file mode 100644 index 000000000..ff0d3c144 --- /dev/null +++ b/libs/libpng-src/scripts/makefile.hpgcc @@ -0,0 +1,248 @@ +# makefile for libpng on HP-UX using GCC with the HP ANSI/C linker. +# Copyright (C) 2002, 2006-2008 Glenn Randers-Pehrson +# Copyright (C) 2001, Laurent faillie +# Copyright (C) 1998, 1999 Greg Roelofs +# Copyright (C) 1996, 1997 Andreas Dilger +# +# This code is released under the libpng license. +# For conditions of distribution and use, see the disclaimer +# and license in png.h + +# Library name: +LIBNAME = libpng12 +PNGMAJ = 0 +PNGMIN = 1.2.46 +PNGVER = $(PNGMAJ).$(PNGMIN) + +# Shared library names: +LIBSO=$(LIBNAME).sl +LIBSOMAJ=$(LIBNAME).sl.$(PNGMAJ) +LIBSOVER=$(LIBNAME).sl.$(PNGVER) +OLDSO=libpng.sl +OLDSOMAJ=libpng.sl.3 +OLDSOVER=libpng.sl.3.$(PNGMIN) + +# Utilities: +CC=gcc +LD=ld +AR_RC=ar rc +MKDIR_P=mkdir -p +LN_SF=ln -sf +RANLIB=ranlib +RM_F=/bin/rm -f + +# where "make install" puts libpng.a, $(OLDSO)*, png.h and pngconf.h +prefix=/usr/local +exec_prefix=$(prefix) + +# Where the zlib library and include files are located +ZLIBLIB=/opt/zlib/lib +ZLIBINC=/opt/zlib/include + +# Note that if you plan to build a libpng shared library, zlib must also +# be a shared library, which zlib's configure does not do. After running +# zlib's configure, edit the appropriate lines of makefile to read: +# CFLAGS=-O1 -DHAVE_UNISTD -DUSE_MAP -fPIC \ +# LDSHARED=ld -b +# SHAREDLIB=libz.sl + +ALIGN= +# for i386: +#ALIGN=-malign-loops=2 -malign-functions=2 + +WARNMORE=-Wwrite-strings -Wpointer-arith -Wshadow \ + -Wmissing-declarations -Wtraditional -Wcast-align \ + -Wstrict-prototypes -Wmissing-prototypes #-Wconversion + +# for pgcc version 2.95.1, -O3 is buggy; don't use it. + +CFLAGS=-I$(ZLIBINC) -W -Wall -O3 -funroll-loops -DPNG_NO_MMX_CODE \ + $(ALIGN) # $(WARNMORE) -g -DPNG_DEBUG=5 +#LDFLAGS=-L. -Wl,-rpath,. -L$(ZLIBLIB) -Wl,-rpath,$(ZLIBLIB) -lpng12 -lz -lm +LDFLAGS=-L. -L$(ZLIBLIB) -lpng12 -lz -lm + +INCPATH=$(prefix)/include +LIBPATH=$(exec_prefix)/lib +MANPATH=$(prefix)/man +BINPATH=$(exec_prefix)/bin + +# override DESTDIR= on the make install command line to easily support +# installing into a temporary location. Example: +# +# make install DESTDIR=/tmp/build/libpng +# +# If you're going to install into a temporary location +# via DESTDIR, $(DESTDIR)$(prefix) must already exist before +# you execute make install. +DESTDIR= + +DB=$(DESTDIR)$(BINPATH) +DI=$(DESTDIR)$(INCPATH) +DL=$(DESTDIR)$(LIBPATH) +DM=$(DESTDIR)$(MANPATH) + +OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \ + pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \ + pngwtran.o pngmem.o pngerror.o pngpread.o + +OBJSDLL = $(OBJS:.o=.pic.o) + +.SUFFIXES: .c .o .pic.o + +.c.pic.o: + $(CC) -c $(CFLAGS) -fPIC -o $@ $*.c + +all: libpng.a $(LIBSO) pngtest libpng.pc libpng-config + +libpng.a: $(OBJS) + $(AR_RC) $@ $(OBJS) + $(RANLIB) $@ + +libpng.pc: + cat scripts/libpng.pc.in | sed -e s!@prefix@!$(prefix)! \ + -e s!@exec_prefix@!$(exec_prefix)! \ + -e s!@libdir@!$(LIBPATH)! \ + -e s!@includedir@!$(INCPATH)! \ + -e s!-lpng12!-lpng12\ -lz\ -lm! > libpng.pc + +libpng-config: + ( cat scripts/libpng-config-head.in; \ + echo prefix=\"$(prefix)\"; \ + echo I_opts=\"-I$(INCPATH)/$(LIBNAME)\"; \ + echo libs=\"-lpng12 -lz -lm\"; \ + cat scripts/libpng-config-body.in ) > libpng-config + chmod +x libpng-config + +$(LIBSO): $(LIBSOMAJ) + $(LN_SF) $(LIBSOMAJ) $(LIBSO) + +$(LIBSOMAJ): $(LIBSOVER) + $(LN_SF) $(LIBSOVER) $(LIBSOMAJ) + +$(LIBSOVER): $(OBJSDLL) + $(LD) -b +s \ + +h $(LIBSOMAJ) -o $(LIBSOVER) $(OBJSDLL) + +$(OLDSOVER): $(OBJSDLL) + $(LD) -b +s \ + +h $(OLDSOMAJ) -o $(OLDSOVER) $(OBJSDLL) + +pngtest: pngtest.o $(LIBSO) + $(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS) + +test: pngtest + ./pngtest + + +install-headers: png.h pngconf.h + -@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi + -@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi + cp png.h pngconf.h $(DI)/$(LIBNAME) + chmod 644 $(DI)/$(LIBNAME)/png.h $(DI)/$(LIBNAME)/pngconf.h + -@$(RM_F) $(DI)/png.h $(DI)/pngconf.h + -@$(RM_F) $(DI)/libpng + (cd $(DI); $(LN_SF) $(LIBNAME) libpng; $(LN_SF) $(LIBNAME)/* .) + +install-static: install-headers libpng.a + -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi + cp libpng.a $(DL)/$(LIBNAME).a + chmod 644 $(DL)/$(LIBNAME).a + -@$(RM_F) $(DL)/libpng.a + (cd $(DL); $(LN_SF) $(LIBNAME).a libpng.a) + +install-shared: install-headers $(LIBSOVER) libpng.pc \ + $(OLDSOVER) + -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi + -@$(RM_F) $(DL)/$(LIBSOVER)* $(DL)/$(LIBSO) + -@$(RM_F) $(DL)/$(LIBSOMAJ) + -@$(RM_F) $(DL)/$(OLDSO) + -@$(RM_F) $(DL)/$(OLDSOMAJ) + -@$(RM_F) $(DL)/$(OLDSOVER)* + cp $(LIBSOVER) $(DL) + cp $(OLDSOVER) $(DL) + chmod 755 $(DL)/$(LIBSOVER) + chmod 755 $(DL)/$(OLDSOVER) + (cd $(DL); \ + $(LN_SF) $(OLDSOVER) $(OLDSOMAJ); \ + $(LN_SF) $(OLDSOMAJ) $(OLDSO); \ + $(LN_SF) $(LIBSOVER) $(LIBSOMAJ); \ + $(LN_SF) $(LIBSOMAJ) $(LIBSO)) + -@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi + -@$(RM_F) $(DL)/pkgconfig/$(LIBNAME).pc + -@$(RM_F) $(DL)/pkgconfig/libpng.pc + cp libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc + chmod 644 $(DL)/pkgconfig/$(LIBNAME).pc + (cd $(DL)/pkgconfig; $(LN_SF) $(LIBNAME).pc libpng.pc) + +install-man: libpng.3 libpngpf.3 png.5 + -@if [ ! -d $(DM) ]; then $(MKDIR_P) $(DM); fi + -@if [ ! -d $(DM)/man3 ]; then $(MKDIR_P) $(DM)/man3; fi + -@$(RM_F) $(DM)/man3/libpng.3 + -@$(RM_F) $(DM)/man3/libpngpf.3 + cp libpng.3 $(DM)/man3 + cp libpngpf.3 $(DM)/man3 + -@if [ ! -d $(DM)/man5 ]; then $(MKDIR_P) $(DM)/man5; fi + -@$(RM_F) $(DM)/man5/png.5 + cp png.5 $(DM)/man5 + +install-config: libpng-config + -@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi + -@$(RM_F) $(DB)/libpng-config + -@$(RM_F) $(DB)/$(LIBNAME)-config + cp libpng-config $(DB)/$(LIBNAME)-config + chmod 755 $(DB)/$(LIBNAME)-config + (cd $(DB); $(LN_SF) $(LIBNAME)-config libpng-config) + +install: install-static install-shared install-man install-config + +# If you installed in $(DESTDIR), test-installed won't work until you +# move the library to its final location. Use test-dd to test it +# before then. + +test-dd: + echo + echo Testing installed dynamic shared library in $(DL). + $(CC) -I$(DI) -I$(ZLIBINC) \ + `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \ + -L$(DL) -L$(ZLIBLIB) -Wl,-rpath,$(DL) -Wl,-rpath,$(ZLIBLIB) \ + -o pngtestd `$(BINPATH)/$(LIBNAME)-config --ldflags` + ./pngtestd pngtest.png + +test-installed: + echo + echo Testing installed dynamic shared library. + $(CC) -I$(ZLIBINC) \ + `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \ + -L$(ZLIBLIB) -Wl,-rpath,$(ZLIBLIB) \ + -o pngtesti `$(BINPATH)/$(LIBNAME)-config --ldflags` + ./pngtesti pngtest.png + +clean: + $(RM_F) *.o libpng.a pngtest pngtesti pngout.png \ + libpng-config $(LIBSO) $(LIBSOMAJ)* \ + $(OLDSOVER) \ + libpng.pc + +DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO +writelock: + chmod a-w *.[ch35] $(DOCS) scripts/* + +# DO NOT DELETE THIS LINE -- make depend depends on it. + +png.o png.pic.o: png.h pngconf.h +pngerror.o pngerror.pic.o: png.h pngconf.h +pngrio.o pngrio.pic.o: png.h pngconf.h +pngwio.o pngwio.pic.o: png.h pngconf.h +pngmem.o pngmem.pic.o: png.h pngconf.h +pngset.o pngset.pic.o: png.h pngconf.h +pngget.o pngget.pic.o: png.h pngconf.h +pngread.o pngread.pic.o: png.h pngconf.h +pngrtran.o pngrtran.pic.o: png.h pngconf.h +pngrutil.o pngrutil.pic.o: png.h pngconf.h +pngtrans.o pngtrans.pic.o: png.h pngconf.h +pngwrite.o pngwrite.pic.o: png.h pngconf.h +pngwtran.o pngwtran.pic.o: png.h pngconf.h +pngwutil.o pngwutil.pic.o: png.h pngconf.h +pngpread.o pngpread.pic.o: png.h pngconf.h + +pngtest.o: png.h pngconf.h diff --git a/libs/libpng-src/scripts/makefile.hpux b/libs/libpng-src/scripts/makefile.hpux new file mode 100644 index 000000000..6c94bade0 --- /dev/null +++ b/libs/libpng-src/scripts/makefile.hpux @@ -0,0 +1,236 @@ +# makefile for libpng, HPUX (10.20 and 11.00) using the ANSI/C product. +# Copyright (C) 1999-2002, 2006 Glenn Randers-Pehrson +# Copyright (C) 1995 Guy Eric Schalnat, Group 42 +# contributed by Jim Rice and updated by Chris Schleicher, Hewlett Packard +# +# This code is released under the libpng license. +# For conditions of distribution and use, see the disclaimer +# and license in png.h + +# Where the zlib library and include files are located +ZLIBLIB=/opt/zlib/lib +ZLIBINC=/opt/zlib/include + +# Note that if you plan to build a libpng shared library, zlib must also +# be a shared library, which zlib's configure does not do. After running +# zlib's configure, edit the appropriate lines of makefile to read: +# CFLAGS=-O1 -DHAVE_UNISTD -DUSE_MAP -fPIC \ +# LDSHARED=ld -b +# SHAREDLIB=libz.sl + +# Library name: +LIBNAME = libpng12 +PNGMAJ = 0 +PNGMIN = 1.2.46 +PNGVER = $(PNGMAJ).$(PNGMIN) + +# Shared library names: +LIBSO=$(LIBNAME).sl +LIBSOMAJ=$(LIBNAME).sl.$(PNGMAJ) +LIBSOVER=$(LIBNAME).sl.$(PNGVER) +OLDSO=libpng.sl +OLDSOMAJ=libpng.sl.3 +OLDSOVER=libpng.sl.3.$(PNGMIN) + +# Utilities: +AR_RC=ar rc +CC=cc +MKDIR_P=mkdir -p +LN_SF=ln -sf +RANLIB=ranlib +RM_F=/bin/rm -f + +# where make install puts libpng.a, libpng12.sl, and png.h +prefix=/opt/libpng +exec_prefix=$(prefix) +INCPATH=$(prefix)/include +LIBPATH=$(exec_prefix)/lib +MANPATH=$(prefix)/man +BINPATH=$(exec_prefix)/bin + +CFLAGS=-I$(ZLIBINC) -O -Ae +DA1.1 +DS2.0 -DPNG_NO_MMX_CODE +# Caution: be sure you have built zlib with the same CFLAGS. +CCFLAGS=-I$(ZLIBINC) -O -Ae +DA1.1 +DS2.0 +LDFLAGS=-L. -L$(ZLIBLIB) -lpng -lz -lm + +# override DESTDIR= on the make install command line to easily support +# installing into a temporary location. Example: +# +# make install DESTDIR=/tmp/build/libpng +# +# If you're going to install into a temporary location +# via DESTDIR, $(DESTDIR)$(prefix) must already exist before +# you execute make install. +DESTDIR= + +DB=$(DESTDIR)$(BINPATH) +DI=$(DESTDIR)$(INCPATH) +DL=$(DESTDIR)$(LIBPATH) +DM=$(DESTDIR)$(MANPATH) + +OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \ + pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \ + pngwtran.o pngmem.o pngerror.o pngpread.o + +OBJSDLL = $(OBJS:.o=.pic.o) + +.SUFFIXES: .c .o .pic.o + +.c.pic.o: + $(CC) -c $(CFLAGS) +z -o $@ $*.c + +all: libpng.a $(LIBSO) pngtest libpng.pc libpng-config + +libpng.a: $(OBJS) + $(AR_RC) $@ $(OBJS) + $(RANLIB) $@ + +libpng.pc: + cat scripts/libpng.pc.in | sed -e s!@prefix@!$(prefix)! \ + -e s!@exec_prefix@!$(exec_prefix)! \ + -e s!@libdir@!$(LIBPATH)! \ + -e s!@includedir@!$(INCPATH)! \ + -e s!-lpng12!-lpng12\ -lz\ -lm! > libpng.pc + +libpng-config: + ( cat scripts/libpng-config-head.in; \ + echo prefix=\"$(prefix)\"; \ + echo I_opts=\"-I$(INCPATH)/$(LIBNAME)\"; \ + echo ccopts=\"-Ae +DA1.1 +DS2.0\"; \ + echo L_opts=\"-L$(LIBPATH)\"; \ + echo libs=\"-lpng12 -lz -lm\"; \ + cat scripts/libpng-config-body.in ) > libpng-config + chmod +x libpng-config + +$(LIBSO): $(LIBSOMAJ) + $(LN_SF) $(LIBSOMAJ) $(LIBSO) + +$(LIBSOMAJ): $(LIBSOVER) + $(LN_SF) $(LIBSOVER) $(LIBSOMAJ) + +$(LIBSOVER): $(OBJSDLL) + $(LD) -b +s \ + +h $(LIBSOMAJ) -o $(LIBSOVER) $(OBJSDLL) + +$(OLDSOVER): $(OBJSDLL) + $(LD) -b +s \ + +h $(OLDSOMAJ) -o $(OLDSOVER) $(OBJSDLL) + +pngtest: pngtest.o libpng.a + $(CC) -o pngtest $(CCFLAGS) pngtest.o $(LDFLAGS) + +test: pngtest + ./pngtest + +install-headers: png.h pngconf.h + -@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi + -@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi + cp png.h pngconf.h $(DI)/$(LIBNAME) + chmod 644 $(DI)/$(LIBNAME)/png.h $(DI)/$(LIBNAME)/pngconf.h + -@$(RM_F) $(DI)/png.h $(DI)/pngconf.h + -@$(RM_F) $(DI)/libpng + (cd $(DI); $(LN_SF) $(LIBNAME) libpng; $(LN_SF) $(LIBNAME)/* .) + +install-static: install-headers libpng.a + -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi + cp libpng.a $(DL)/$(LIBNAME).a + chmod 644 $(DL)/$(LIBNAME).a + -@$(RM_F) $(DL)/libpng.a + (cd $(DL); $(LN_SF) $(LIBNAME).a libpng.a) + +install-shared: install-headers $(LIBSOVER) libpng.pc \ + $(OLDSOVER) + -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi + -@$(RM_F) $(DL)/$(LIBSOVER)* $(DL)/$(LIBSO) + -@$(RM_F) $(DL)/$(LIBSOMAJ) + -@$(RM_F) $(DL)/$(OLDSO) + -@$(RM_F) $(DL)/$(OLDSOMAJ) + -@$(RM_F) $(DL)/$(OLDSOVER)* + cp $(LIBSOVER) $(DL) + cp $(OLDSOVER) $(DL) + chmod 755 $(DL)/$(LIBSOVER) + chmod 755 $(DL)/$(OLDSOVER) + (cd $(DL); \ + $(LN_SF) $(OLDSOVER) $(OLDSOMAJ); \ + $(LN_SF) $(OLDSOMAJ) $(OLDSO); \ + $(LN_SF) $(LIBSOVER) $(LIBSOMAJ); \ + $(LN_SF) $(LIBSOMAJ) $(LIBSO)) + -@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi + -@$(RM_F) $(DL)/pkgconfig/$(LIBNAME).pc + -@$(RM_F) $(DL)/pkgconfig/libpng.pc + cp libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc + chmod 644 $(DL)/pkgconfig/$(LIBNAME).pc + (cd $(DL)/pkgconfig; $(LN_SF) $(LIBNAME).pc libpng.pc) + +install-man: libpng.3 libpngpf.3 png.5 + -@if [ ! -d $(DM) ]; then $(MKDIR_P) $(DM); fi + -@if [ ! -d $(DM)/man3 ]; then $(MKDIR_P) $(DM)/man3; fi + -@$(RM_F) $(DM)/man3/libpng.3 + -@$(RM_F) $(DM)/man3/libpngpf.3 + cp libpng.3 $(DM)/man3 + cp libpngpf.3 $(DM)/man3 + -@if [ ! -d $(DM)/man5 ]; then $(MKDIR_P) $(DM)/man5; fi + -@$(RM_F) $(DM)/man5/png.5 + cp png.5 $(DM)/man5 + +install-config: libpng-config + -@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi + -@$(RM_F) $(DB)/libpng-config + -@$(RM_F) $(DB)/$(LIBNAME)-config + cp libpng-config $(DB)/$(LIBNAME)-config + chmod 755 $(DB)/$(LIBNAME)-config + (cd $(DB); $(LN_SF) $(LIBNAME)-config libpng-config) + +install: install-static install-shared install-man install-config + +# If you installed in $(DESTDIR), test-installed won't work until you +# move the library to its final location. Use test-dd to test it +# before then. + +test-dd: + echo + echo Testing installed dynamic shared library in $(DL). + $(CC) -I$(DI) -I$(ZLIBINC) $(CCFLAGS) \ + `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \ + -L$(DL) -L$(ZLIBLIB) \ + -o pngtestd `$(BINPATH)/$(LIBNAME)-config --ldflags` + ./pngtestd pngtest.png + +test-installed: + echo + echo Testing installed dynamic shared library. + $(CC) $(CCFLAGS) \ + `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \ + -L$(ZLIBLIB) \ + -o pngtesti `$(BINPATH)/$(LIBNAME)-config --ldflags` + ./pngtesti pngtest.png + +clean: + $(RM_F) *.o libpng.a pngtest pngtesti pngout.png \ + libpng-config $(LIBSO) $(LIBSOMAJ)* \ + $(OLDSOVER) \ + libpng.pc + +DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO +writelock: + chmod a-w *.[ch35] $(DOCS) scripts/* + +# DO NOT DELETE THIS LINE -- make depend depends on it. + +png.o: png.h pngconf.h +pngerror.o: png.h pngconf.h +pngrio.o: png.h pngconf.h +pngwio.o: png.h pngconf.h +pngmem.o: png.h pngconf.h +pngset.o: png.h pngconf.h +pngget.o: png.h pngconf.h +pngread.o: png.h pngconf.h +pngrtran.o: png.h pngconf.h +pngrutil.o: png.h pngconf.h +pngtrans.o: png.h pngconf.h +pngwrite.o: png.h pngconf.h +pngwtran.o: png.h pngconf.h +pngwutil.o: png.h pngconf.h +pngpread.o: png.h pngconf.h + +pngtest.o: png.h pngconf.h diff --git a/libs/libpng-src/scripts/makefile.ibmc b/libs/libpng-src/scripts/makefile.ibmc new file mode 100644 index 000000000..3d540d286 --- /dev/null +++ b/libs/libpng-src/scripts/makefile.ibmc @@ -0,0 +1,77 @@ +# Makefile for libpng (static) +# IBM C version 3.x for Win32 and OS/2 +# Copyright (C) 2006 Glenn Randers-Pehrson +# Copyright (C) 2000 Cosmin Truta +# +# This code is released under the libpng license. +# For conditions of distribution and use, see the disclaimer +# and license in png.h +# +# Notes: +# Derived from makefile.std +# All modules are compiled in C mode +# Tested under Win32, expected to work under OS/2 +# Can be easily adapted for IBM VisualAge/C++ for AIX + +# Location of the zlib library and include files +ZLIBINC = ../zlib +ZLIBLIB = ../zlib + +# Compiler, linker, lib and other tools +CC = icc +LD = ilink +AR = ilib +RM = del + +CFLAGS = -I$(ZLIBINC) -Mc -O2 -W3 +LDFLAGS = + +# File extensions +O=.obj +A=.lib +E=.exe + +# Variables +OBJS = png$(O) pngerror$(O) pngget$(O) pngmem$(O) pngpread$(O) \ + pngread$(O) pngrio$(O) pngrtran$(O) pngrutil$(O) pngset$(O) \ + pngtrans$(O) pngwio$(O) pngwrite$(O) pngwtran$(O) pngwutil$(O) + +LIBS = libpng$(A) $(ZLIBLIB)/zlib$(A) + +# Targets +all: libpng$(A) pngtest$(E) + +libpng$(A): $(OBJS) + $(AR) -out:$@ $(OBJS) + +test: pngtest$(E) + pngtest$(E) + +pngtest: pngtest$(E) + +pngtest$(E): pngtest$(O) libpng$(A) + $(LD) $(LDFLAGS) pngtest$(O) $(LIBS) + +clean: + $(RM) *$(O) + $(RM) libpng$(A) + $(RM) pngtest$(E) + $(RM) pngout.png + +png$(O): png.h pngconf.h +pngerror$(O): png.h pngconf.h +pngget$(O): png.h pngconf.h +pngmem$(O): png.h pngconf.h +pngpread$(O): png.h pngconf.h +pngread$(O): png.h pngconf.h +pngrio$(O): png.h pngconf.h +pngrtran$(O): png.h pngconf.h +pngrutil$(O): png.h pngconf.h +pngset$(O): png.h pngconf.h +pngtrans$(O): png.h pngconf.h +pngwio$(O): png.h pngconf.h +pngwrite$(O): png.h pngconf.h +pngwtran$(O): png.h pngconf.h +pngwutil$(O): png.h pngconf.h + +pngtest$(O): png.h pngconf.h diff --git a/libs/libpng-src/scripts/makefile.intel b/libs/libpng-src/scripts/makefile.intel new file mode 100644 index 000000000..3b1cdde40 --- /dev/null +++ b/libs/libpng-src/scripts/makefile.intel @@ -0,0 +1,106 @@ +# Makefile for libpng +# Microsoft Visual C++ with Intel C/C++ Compiler 4.0 and later + +# Copyright (C) 2006 Glenn Randers-Pehrson +# Copyright (C) 2000, Pawel Mrochen, based on makefile.msc which is +# copyright 1995 Guy Eric Schalnat, Group 42, Inc. +# +# This code is released under the libpng license. +# For conditions of distribution and use, see the disclaimer +# and license in png.h +# +# To use, do "nmake /f scripts\makefile.intel" +# +# ------------------- Intel C/C++ Compiler 4.0 and later ------------------- + +# Where the zlib library and include files are located +ZLIBLIB=..\zlib +ZLIBINC=..\zlib + +# Target CPU +CPU=6 # Pentium II +#CPU=5 # Pentium + +# Calling convention +CALLING=r # __fastcall +#CALLING=z # __stdcall +#CALLING=d # __cdecl + +# Uncomment next to put error messages in a file +#ERRFILE=>>pngerrs + +# -------------------------------------------------------------------------- + +CC=icl -c +CFLAGS=-O2 -G$(CPU)$(CALLING) -Qip -Qunroll4 -I$(ZLIBINC) -nologo +LD=link +LDFLAGS=/SUBSYSTEM:CONSOLE /NOLOGO + +O=.obj + +OBJS=png$(O) pngset$(O) pngget$(O) pngrutil$(O) pngtrans$(O) pngwutil$(O) \ +pngmem$(O) pngpread$(O) pngread$(O) pngerror$(O) pngwrite$(O) \ +pngrtran$(O) pngwtran$(O) pngrio$(O) pngwio$(O) + +all: test + +png$(O): png.h pngconf.h + $(CC) $(CFLAGS) $*.c $(ERRFILE) + +pngset$(O): png.h pngconf.h + $(CC) $(CFLAGS) $*.c $(ERRFILE) + +pngget$(O): png.h pngconf.h + $(CC) $(CFLAGS) $*.c $(ERRFILE) + +pngread$(O): png.h pngconf.h + $(CC) $(CFLAGS) $*.c $(ERRFILE) + +pngpread$(O): png.h pngconf.h + $(CC) $(CFLAGS) $*.c $(ERRFILE) + +pngrtran$(O): png.h pngconf.h + $(CC) $(CFLAGS) $*.c $(ERRFILE) + +pngrutil$(O): png.h pngconf.h + $(CC) $(CFLAGS) $*.c $(ERRFILE) + +pngerror$(O): png.h pngconf.h + $(CC) $(CFLAGS) $*.c $(ERRFILE) + +pngmem$(O): png.h pngconf.h + $(CC) $(CFLAGS) $*.c $(ERRFILE) + +pngrio$(O): png.h pngconf.h + $(CC) $(CFLAGS) $*.c $(ERRFILE) + +pngwio$(O): png.h pngconf.h + $(CC) $(CFLAGS) $*.c $(ERRFILE) + +pngtrans$(O): png.h pngconf.h + $(CC) $(CFLAGS) $*.c $(ERRFILE) + +pngwrite$(O): png.h pngconf.h + $(CC) $(CFLAGS) $*.c $(ERRFILE) + +pngwtran$(O): png.h pngconf.h + $(CC) $(CFLAGS) $*.c $(ERRFILE) + +pngwutil$(O): png.h pngconf.h + $(CC) $(CFLAGS) $*.c $(ERRFILE) + +libpng.lib: $(OBJS) + if exist libpng.lib del libpng.lib + lib /NOLOGO /OUT:libpng.lib $(OBJS) + +pngtest.exe: pngtest.obj libpng.lib + $(LD) $(LDFLAGS) /OUT:pngtest.exe pngtest.obj libpng.lib $(ZLIBLIB)\zlib.lib + +pngtest$(O): png.h pngconf.h + $(CC) $(CFLAGS) $*.c $(ERRFILE) + +test: pngtest.exe + pngtest.exe + + +# End of makefile for libpng diff --git a/libs/libpng-src/scripts/makefile.knr b/libs/libpng-src/scripts/makefile.knr new file mode 100644 index 000000000..3a2067481 --- /dev/null +++ b/libs/libpng-src/scripts/makefile.knr @@ -0,0 +1,103 @@ +# makefile for libpng +# Copyright (C) 2002, 2006, 2009 Glenn Randers-Pehrson +# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc. +# +# This code is released under the libpng license. +# For conditions of distribution and use, see the disclaimer +# and license in png.h +# +# This makefile requires the file ansi2knr.c, which you can get +# from the Ghostscript ftp site at ftp://ftp.cs.wisc.edu/ghost/ +# If you have libjpeg, you probably already have ansi2knr.c in the jpeg +# source distribution. + +# where make install puts libpng.a and png.h +prefix=/usr/local +INCPATH=$(prefix)/include +LIBPATH=$(prefix)/lib + +# override DESTDIR= on the make install command line to easily support +# installing into a temporary location. Example: +# +# make install DESTDIR=/tmp/build/libpng +# +# If you're going to install into a temporary location +# via DESTDIR, $(DESTDIR)$(prefix) must already exist before +# you execute make install. +DESTDIR= + +CC=cc +CFLAGS=-I../zlib -O +LDFLAGS=-L. -L../zlib/ -lpng -lz -lm +# flags for ansi2knr +ANSI2KNRFLAGS= + +RANLIB=ranlib +#RANLIB=echo + +OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \ + pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \ + pngwtran.o pngmem.o pngerror.o pngpread.o + +all: ansi2knr libpng.a pngtest + +# general rule to allow ansi2knr to work +.c.o: + ./ansi2knr $*.c T$*.c + $(CC) $(CFLAGS) -c T$*.c + rm -f T$*.c $*.o + mv T$*.o $*.o + +ansi2knr: ansi2knr.c + $(CC) $(CFLAGS) $(ANSI2KNRFLAGS) -o ansi2knr ansi2knr.c + +libpng.a: ansi2knr $(OBJS) + ar rc $@ $(OBJS) + $(RANLIB) $@ + +pngtest: pngtest.o libpng.a + $(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS) + +test: pngtest + ./pngtest + +install: libpng.a png.h pngconf.h + -@mkdir $(DESTDIR)$(INCPATH) + -@mkdir $(DESTDIR)$(INCPATH)/libpng + -@mkdir $(DESTDIR)$(LIBPATH) + -@rm -f $(DESTDIR)$(INCPATH)/png.h + -@rm -f $(DESTDIR)$(INCPATH)/pngconf.h + cp png.h $(DESTDIR)$(INCPATH)/libpng + cp pngconf.h $(DESTDIR)$(INCPATH)/libpng + chmod 644 $(DESTDIR)$(INCPATH)/libpng/png.h + chmod 644 $(DESTDIR)$(INCPATH)/libpng/pngconf.h + (cd $(DESTDIR)$(INCPATH); ln -f -s libpng/* .) + cp libpng.a $(DESTDIR)$(LIBPATH) + chmod 644 $(DESTDIR)$(LIBPATH)/libpng.a + +clean: + rm -f *.o libpng.a pngtest pngout.png ansi2knr + +DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO +writelock: + chmod a-w *.[ch35] $(DOCS) scripts/* + +# DO NOT DELETE THIS LINE -- make depend depends on it. + +png.o: png.h pngconf.h +pngerror.o: png.h pngconf.h +pngrio.o: png.h pngconf.h +pngwio.o: png.h pngconf.h +pngmem.o: png.h pngconf.h +pngset.o: png.h pngconf.h +pngget.o: png.h pngconf.h +pngread.o: png.h pngconf.h +pngpread.o: png.h pngconf.h +pngrtran.o: png.h pngconf.h +pngrutil.o: png.h pngconf.h +pngtrans.o: png.h pngconf.h +pngwrite.o: png.h pngconf.h +pngwtran.o: png.h pngconf.h +pngwutil.o: png.h pngconf.h + +pngtest.o: png.h pngconf.h diff --git a/libs/libpng-src/scripts/makefile.linux b/libs/libpng-src/scripts/makefile.linux new file mode 100644 index 000000000..562126048 --- /dev/null +++ b/libs/libpng-src/scripts/makefile.linux @@ -0,0 +1,253 @@ +# makefile for libpng.a and libpng12.so on Linux ELF with gcc +# Copyright (C) 1998, 1999, 2002, 2006, 2008 Greg Roelofs and +# Glenn Randers-Pehrson +# Copyright (C) 1996, 1997 Andreas Dilger +# +# This code is released under the libpng license. +# For conditions of distribution and use, see the disclaimer +# and license in png.h + +# Library name: +LIBNAME = libpng12 +PNGMAJ = 0 +PNGMIN = 1.2.46 +PNGVER = $(PNGMAJ).$(PNGMIN) + +# Shared library names: +LIBSO=$(LIBNAME).so +LIBSOMAJ=$(LIBNAME).so.$(PNGMAJ) +LIBSOVER=$(LIBNAME).so.$(PNGVER) +OLDSO=libpng.so +OLDSOMAJ=libpng.so.3 +OLDSOVER=libpng.so.3.$(PNGMIN) + +# Utilities: +AR_RC=ar rc +CC=gcc +MKDIR_P=mkdir -p +LN_SF=ln -sf +RANLIB=ranlib +RM_F=/bin/rm -f + +# where "make install" puts libpng12.a, libpng12.so*, +# libpng12/png.h and libpng12/pngconf.h +# Prefix must be a full pathname. +prefix=/usr/local +exec_prefix=$(prefix) + +# Where the zlib library and include files are located. +#ZLIBLIB=/usr/local/lib +#ZLIBINC=/usr/local/include +ZLIBLIB=../zlib +ZLIBINC=../zlib + +ALIGN= +# for i386: +#ALIGN=-malign-loops=2 -malign-functions=2 + +WARNMORE=-Wwrite-strings -Wpointer-arith -Wshadow \ + -Wmissing-declarations -Wtraditional -Wcast-align \ + -Wstrict-prototypes -Wmissing-prototypes #-Wconversion + +# for pgcc version 2.95.1, -O3 is buggy; don't use it. + +CFLAGS=-I$(ZLIBINC) -W -Wall -O3 -funroll-loops -DPNG_NO_MMX_CODE \ + $(ALIGN) # $(WARNMORE) -g -DPNG_DEBUG=5 + +LDFLAGS=-L. -Wl,-rpath,. -L$(ZLIBLIB) -Wl,-rpath,$(ZLIBLIB) -lpng12 -lz -lm +LDFLAGS_A=-L$(ZLIBLIB) -Wl,-rpath,$(ZLIBLIB) libpng.a -lz -lm + +INCPATH=$(prefix)/include +LIBPATH=$(exec_prefix)/lib +MANPATH=$(prefix)/man +BINPATH=$(exec_prefix)/bin + +# override DESTDIR= on the make install command line to easily support +# installing into a temporary location. Example: +# +# make install DESTDIR=/tmp/build/libpng +# +# If you're going to install into a temporary location +# via DESTDIR, $(DESTDIR)$(prefix) must already exist before +# you execute make install. +DESTDIR= + +DB=$(DESTDIR)$(BINPATH) +DI=$(DESTDIR)$(INCPATH) +DL=$(DESTDIR)$(LIBPATH) +DM=$(DESTDIR)$(MANPATH) + +OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \ + pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \ + pngwtran.o pngmem.o pngerror.o pngpread.o + +OBJSDLL = $(OBJS:.o=.pic.o) + +.SUFFIXES: .c .o .pic.o + +.c.pic.o: + $(CC) -c $(CFLAGS) -fPIC -o $@ $*.c + +all: libpng.a $(LIBSO) pngtest pngtest-static libpng.pc libpng-config + +libpng.a: $(OBJS) + $(AR_RC) $@ $(OBJS) + $(RANLIB) $@ + +libpng.pc: + cat scripts/libpng.pc.in | sed -e s!@prefix@!$(prefix)! \ + -e s!@exec_prefix@!$(exec_prefix)! \ + -e s!@libdir@!$(LIBPATH)! \ + -e s!@includedir@!$(INCPATH)! \ + -e s!-lpng12!-lpng12\ -lz\ -lm! > libpng.pc + +libpng-config: + ( cat scripts/libpng-config-head.in; \ + echo prefix=\"$(prefix)\"; \ + echo I_opts=\"-I$(INCPATH)/$(LIBNAME)\"; \ + echo L_opts=\"-L$(LIBPATH)\"; \ + echo R_opts=\"-Wl,-rpath,$(LIBPATH)\"; \ + echo libs=\"-lpng12 -lz -lm\"; \ + cat scripts/libpng-config-body.in ) > libpng-config + chmod +x libpng-config + +$(LIBSO): $(LIBSOMAJ) + $(LN_SF) $(LIBSOMAJ) $(LIBSO) + +$(LIBSOMAJ): $(LIBSOVER) + $(LN_SF) $(LIBSOVER) $(LIBSOMAJ) + +$(LIBSOVER): $(OBJSDLL) + $(CC) -shared -Wl,-soname,$(LIBSOMAJ) -o $(LIBSOVER) $(OBJSDLL) + +$(OLDSOVER): $(OBJSDLL) + $(CC) -shared -Wl,-soname,$(OLDSOMAJ) \ + -o $(OLDSOVER) \ + $(OBJSDLL) + +pngtest: pngtest.o $(LIBSO) + $(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS) + +pngtest-static: pngtest.o libpng.a + $(CC) -o pngtest-static $(CFLAGS) pngtest.o $(LDFLAGS_A) + +test: pngtest pngtest-static + @echo "" + @echo " Running pngtest dynamically linked with $(LIBSO):" + @echo "" + ./pngtest + @echo "" + @echo " Running pngtest statically linked with libpng.a:" + @echo "" + ./pngtest-static + +install-headers: png.h pngconf.h + -@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi + -@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi + cp png.h pngconf.h $(DI)/$(LIBNAME) + chmod 644 $(DI)/$(LIBNAME)/png.h $(DI)/$(LIBNAME)/pngconf.h + -@$(RM_F) $(DI)/png.h $(DI)/pngconf.h + -@$(RM_F) $(DI)/libpng + (cd $(DI); $(LN_SF) $(LIBNAME) libpng; $(LN_SF) $(LIBNAME)/* .) + +install-static: install-headers libpng.a + -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi + cp libpng.a $(DL)/$(LIBNAME).a + chmod 644 $(DL)/$(LIBNAME).a + -@$(RM_F) $(DL)/libpng.a + (cd $(DL); $(LN_SF) $(LIBNAME).a libpng.a) + +install-shared: install-headers $(LIBSOVER) libpng.pc \ + $(OLDSOVER) + -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi + -@$(RM_F) $(DL)/$(LIBSOVER)* $(DL)/$(LIBSO) + -@$(RM_F) $(DL)/$(LIBSOMAJ) + -@$(RM_F) $(DL)/$(OLDSO) + -@$(RM_F) $(DL)/$(OLDSOMAJ) + -@$(RM_F) $(DL)/$(OLDSOVER)* + cp $(LIBSOVER) $(DL) + cp $(OLDSOVER) $(DL) + chmod 755 $(DL)/$(LIBSOVER) + chmod 755 $(DL)/$(OLDSOVER) + (cd $(DL); \ + $(LN_SF) $(OLDSOVER) $(OLDSOMAJ); \ + $(LN_SF) $(OLDSOMAJ) $(OLDSO); \ + $(LN_SF) $(LIBSOVER) $(LIBSOMAJ); \ + $(LN_SF) $(LIBSOMAJ) $(LIBSO)) + -@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi + -@$(RM_F) $(DL)/pkgconfig/$(LIBNAME).pc + -@$(RM_F) $(DL)/pkgconfig/libpng.pc + cp libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc + chmod 644 $(DL)/pkgconfig/$(LIBNAME).pc + (cd $(DL)/pkgconfig; $(LN_SF) $(LIBNAME).pc libpng.pc) + +install-man: libpng.3 libpngpf.3 png.5 + -@if [ ! -d $(DM) ]; then $(MKDIR_P) $(DM); fi + -@if [ ! -d $(DM)/man3 ]; then $(MKDIR_P) $(DM)/man3; fi + -@$(RM_F) $(DM)/man3/libpng.3 + -@$(RM_F) $(DM)/man3/libpngpf.3 + cp libpng.3 $(DM)/man3 + cp libpngpf.3 $(DM)/man3 + -@if [ ! -d $(DM)/man5 ]; then $(MKDIR_P) $(DM)/man5; fi + -@$(RM_F) $(DM)/man5/png.5 + cp png.5 $(DM)/man5 + +install-config: libpng-config + -@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi + -@$(RM_F) $(DB)/libpng-config + -@$(RM_F) $(DB)/$(LIBNAME)-config + cp libpng-config $(DB)/$(LIBNAME)-config + chmod 755 $(DB)/$(LIBNAME)-config + (cd $(DB); $(LN_SF) $(LIBNAME)-config libpng-config) + +install: install-static install-shared install-man install-config + +# If you installed in $(DESTDIR), test-installed won't work until you +# move the library to its final location. Use test-dd to test it +# before then. + +test-dd: + echo + echo Testing installed dynamic shared library in $(DL). + $(CC) -I$(DI) -I$(ZLIBINC) \ + `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \ + -L$(DL) -L$(ZLIBLIB) -Wl, -rpath,$(DL) -Wl,-rpath,$(ZLIBLIB) \ + -o pngtestd `$(BINPATH)/$(LIBNAME)-config --ldflags` + ./pngtestd pngtest.png + +test-installed: + $(CC) -I$(ZLIBINC) \ + `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \ + -L$(ZLIBLIB) -Wl,-rpath,$(ZLIBLIB) \ + -o pngtesti `$(BINPATH)/$(LIBNAME)-config --ldflags` + ./pngtesti pngtest.png + +clean: + $(RM_F) *.o libpng.a pngtest pngout.png libpng-config \ + $(LIBSO) $(LIBSOMAJ)* pngtest-static pngtesti \ + $(OLDSOVER) \ + libpng.pc + +DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO +writelock: + chmod a-w *.[ch35] $(DOCS) scripts/* + +# DO NOT DELETE THIS LINE -- make depend depends on it. + +png.o png.pic.o: png.h pngconf.h +pngerror.o pngerror.pic.o: png.h pngconf.h +pngrio.o pngrio.pic.o: png.h pngconf.h +pngwio.o pngwio.pic.o: png.h pngconf.h +pngmem.o pngmem.pic.o: png.h pngconf.h +pngset.o pngset.pic.o: png.h pngconf.h +pngget.o pngget.pic.o: png.h pngconf.h +pngread.o pngread.pic.o: png.h pngconf.h +pngrtran.o pngrtran.pic.o: png.h pngconf.h +pngrutil.o pngrutil.pic.o: png.h pngconf.h +pngtrans.o pngtrans.pic.o: png.h pngconf.h +pngwrite.o pngwrite.pic.o: png.h pngconf.h +pngwtran.o pngwtran.pic.o: png.h pngconf.h +pngwutil.o pngwutil.pic.o: png.h pngconf.h +pngpread.o pngpread.pic.o: png.h pngconf.h + +pngtest.o: png.h pngconf.h diff --git a/libs/libpng-src/scripts/makefile.mingw b/libs/libpng-src/scripts/makefile.mingw new file mode 100644 index 000000000..caf946936 --- /dev/null +++ b/libs/libpng-src/scripts/makefile.mingw @@ -0,0 +1,293 @@ +# makefile for mingw on x86 +# Builds both dll (with import lib) and static lib versions +# of the library, and builds two copies of pngtest: one +# statically linked and one dynamically linked. +# +# Copyright (C) 2002, 2006, 2008 Soren Anderson, Charles Wilson, +# and Glenn Randers-Pehrson, based on makefile for linux-elf w/mmx by: +# Copyright (C) 1998-2000, 2007 Greg Roelofs +# Copyright (C) 1996, 1997 Andreas Dilger +# +# This code is released under the libpng license. +# For conditions of distribution and use, see the disclaimer +# and license in png.h + +# Built from makefile.cygwin + +# This makefile expects to be run under the MSYS shell (part of +# the MINGW project) and not under CMD.EXE which does not provide +# "cat" or "sed". + +# This makefile intends to support building outside the src directory +# if desired. When invoking it, specify an argument to SRCDIR on the +# command line that points to the top of the directory where your source +# is located. +ifdef SRCDIR +VPATH = $(SRCDIR) +else +SRCDIR = . +endif + +# Override DESTDIR= on the make install command line to easily support +# installing into a temporary location. Example: +# +# make install DESTDIR=/tmp/build/libpng +# +# If you're going to install into a temporary location +# via DESTDIR, $(DESTDIR)$(prefix) must already exist before +# you execute make install. +DESTDIR= + +# If you're using a cross-compiler, add the appropriate prefix (e.g., +# "i386-mingw32msvc-") to the following three commands: +CC=gcc +AR=ar +RANLIB=ranlib + +MKDIR_P=/bin/mkdir -pv + +# Where "make install" puts libpng*.a, *png*.dll, png.h, and pngconf.h +ifndef prefix +prefix=/usr +$(warning "You haven't specified a 'prefix=' location. Defaulting to '/usr'") +endif +exec_prefix=$(prefix) + +# Where the zlib library and include files are located +ZLIBLIB= /usr/lib +ZLIBINC= + +ALIGN= +# for i386: +#ALIGN=-malign-loops=2 -malign-functions=2 + +WARNMORE=-Wwrite-strings -Wpointer-arith -Wshadow \ + -Wmissing-declarations -Wtraditional -Wcast-align \ + -Wstrict-prototypes -Wmissing-prototypes #-Wconversion + +### if you don't need thread safety, but want the asm accel +#CFLAGS= $(strip $(MINGW_CCFLAGS) -DPNG_THREAD_UNSAFE_OK \ +# $(addprefix -I,$(ZLIBINC)) -W -Wall -O $(ALIGN) -funroll-loops \ +# -fomit-frame-pointer) # $(WARNMORE) -g -DPNG_DEBUG=5 +### if you need thread safety and want (minimal) asm accel +#CFLAGS= $(strip $(MINGW_CCFLAGS) $(addprefix -I,$(ZLIBINC)) \ +# -W -Wall -O $(ALIGN) -funroll-loops \ +# -fomit-frame-pointer) # $(WARNMORE) -g -DPNG_DEBUG=5 +### Normal (non-asm) compilation +CFLAGS= $(strip $(MINGW_CCFLAGS) $(addprefix -I,$(ZLIBINC)) \ + -W -Wall -O3 $(ALIGN) -funroll-loops -DPNG_NO_MMX_CODE \ + -fomit-frame-pointer) # $(WARNMORE) -g -DPNG_DEBUG=5 + +LIBNAME = libpng12 +PNGMAJ = 0 +MINGDLL = 12 +PNGMIN = 1.2.46 +PNGVER = $(PNGMAJ).$(PNGMIN) + +SHAREDLIB=libpng$(MINGDLL).dll +STATLIB=libpng.a +IMPLIB=libpng.dll.a +SHAREDDEF=libpng.def +LIBS=$(SHAREDLIB) $(STATLIB) +EXE=.exe + +LDFLAGS=$(strip -L. $(MINGW_LDFLAGS) -lpng $(addprefix -L,$(ZLIBLIB)) -lz) +LDSFLAGS=$(strip -shared -L. $(MINGW_LDFLAGS)) +LDEXTRA=-Wl,--out-implib=$(IMPLIB) $(addprefix -L,$(ZLIBLIB)) -lz + +INCPATH=$(prefix)/include +LIBPATH=$(exec_prefix)/lib + +BINPATH=$(exec_prefix)/bin +MANPATH=$(prefix)/man +MAN3PATH=$(MANPATH)/man3 +MAN5PATH=$(MANPATH)/man5 + +# cosmetic: shortened strings: +S =$(SRCDIR) +D =$(DESTDIR) +DB =$(D)$(BINPATH) +DI =$(D)$(INCPATH) +DL =$(D)$(LIBPATH) + +OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \ + pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \ + pngwtran.o pngmem.o pngerror.o pngpread.o + +OBJSDLL = $(OBJS:.o=.pic.o) + +.SUFFIXES: .c .o .pic.o + +%.o : %.c + $(CC) -c $(CFLAGS) -o $@ $< +%.pic.o : CFLAGS += -DPNG_BUILD_DLL +%.pic.o : %.c + $(CC) -c $(CFLAGS) -o $@ $< + +all: all-static all-shared libpng.pc libpng-config libpng.pc libpng-config + +# Make this to verify that "make [...] install" will do what you want. +buildsetup-tell: + @echo VPATH is set to: \"$(VPATH)\" + @echo prefix is set to: \"$(prefix)\" + @echo -e INCPATH,LIBPATH, etc. are set to:'\n' \ + $(addprefix $(D),$(INCPATH)'\n' $(LIBPATH)'\n' $(BINPATH)'\n' \ + $(MANPATH)'\n' $(MAN3PATH)'\n' $(MAN5PATH)'\n')'\n' + +libpng.pc: scripts/libpng.pc.in + @echo -e Making pkg-config file for this libpng installation..'\n' \ + using PREFIX=\"$(prefix)\"'\n' + cat scripts/libpng.pc.in | sed -e s!@prefix@!$(prefix)! \ + -e s!@exec_prefix@!$(exec_prefix)! \ + -e s!@libdir@!$(LIBPATH)! \ + -e s!@includedir@!$(INCPATH)! \ + -e s!@includedir@!$(INCPATH)! \ + -e s!-lpng12!-lpng12\ -lz\ -lm! > libpng.pc + +libpng-config: scripts/libpng-config-head.in scripts/libpng-config-body.in + @echo -e Making $(LIBNAME) libpng-config file for this libpng \ + installation..'\n' using PREFIX=\"$(prefix)\"'\n' + ( cat $(S)/scripts/libpng-config-head.in; \ + echo prefix=\"$(prefix)\"; \ + echo I_opts=\"-I$(INCPATH)/$(LIBNAME)\"; \ + echo L_opts=\"-L$(LIBPATH)\"; \ + echo libs=\"-lpng$(MINGDLL) -lz\"; \ + cat $(S)/scripts/libpng-config-body.in ) > libpng-config + chmod +x libpng-config + +static: all-static +shared: all-shared +all-static: $(STATLIB) pngtest-stat$(EXE) +all-shared: $(SHAREDLIB) pngtest$(EXE) + +$(STATLIB): $(OBJS) + $(AR) rc $@ $(OBJS) + $(RANLIB) $@ + +$(SHAREDDEF): scripts/pngw32.def + cat $< | sed -e '1{G;s/^\(.*\)\(\n\)/EXPORTS/;};2,/^EXPORTS/d' | \ + sed -e 's/\([^;]*\);/;/' > $@ + +$(SHAREDLIB): $(OBJSDLL) $(SHAREDDEF) + $(CC) $(LDSFLAGS) -o $@ $(OBJSDLL) -L. $(LDEXTRA) + +pngtest$(EXE): pngtest.pic.o $(SHAREDLIB) + $(CC) $(CFLAGS) $< $(LDFLAGS) -o $@ + +pngtest-stat$(EXE): pngtest.o $(STATLIB) + $(CC) -static $(CFLAGS) $< $(LDFLAGS) -o $@ + +test: test-static test-shared + +test-static: pngtest-stat$(EXE) + ./pngtest-stat $(S)/pngtest.png + +test-shared: pngtest$(EXE) + ./pngtest $(S)/pngtest.png + +install-static: $(STATLIB) install-headers install-man + -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi + install -m 644 $(STATLIB) $(DL)/$(LIBNAME).a + -@rm -f $(DL)/$(STATLIB) + (cd $(DL); ln -sf $(LIBNAME).a $(STATLIB)) + +install-shared: $(SHAREDLIB) libpng.pc libpng-config install-headers install-man + -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi + -@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi + -@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi + -@/bin/rm -f $(DL)/pkgconfig/$(LIBNAME).pc + -@/bin/rm -f $(DL)/pkgconfig/libpng.pc + install -m 644 $(IMPLIB) $(DL)/$(LIBNAME).dll.a + -@rm -f $(DL)/$(IMPLIB) + (cd $(DL); ln -sf $(LIBNAME).dll.a $(IMPLIB)) + install -s -m 755 $(SHAREDLIB) $(DB) + install -m 644 libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc + (cd $(DL)/pkgconfig; ln -sf $(LIBNAME).pc libpng.pc) + +install-headers: + -@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi + -@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi + -@rm -f $(DI)/png.h + -@rm -f $(DI)/pngconf.h + install -m 644 $(S)/png.h $(S)/pngconf.h $(DI)/$(LIBNAME) + -@rm -f $(DI)/libpng + (cd $(DI); ln -sf $(LIBNAME) libpng; ln -sf $(LIBNAME)/* .) + +install-man: + -@if [ ! -d $(D)$(MAN3PATH) ]; then $(MKDIR_P) $(D)$(MAN3PATH); fi + -@if [ ! -d $(D)$(MAN5PATH) ]; then $(MKDIR_P) $(D)$(MAN5PATH); fi + install -m 644 $(S)/libpngpf.3 $(S)/libpng.3 $(D)$(MAN3PATH) + install -m 644 $(S)/png.5 $(D)$(MAN5PATH) + +install-config: libpng-config + -@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi + -@/bin/rm -f $(DB)/libpng-config + -@/bin/rm -f $(DB)/$(LIBNAME)-config + cp libpng-config $(DB)/$(LIBNAME)-config + chmod 755 $(DB)/$(LIBNAME)-config + (cd $(DB); ln -sf $(LIBNAME)-config libpng-config) + +# Run this to verify that a future `configure' run will pick up the settings +# you want. +test-config-install: SHELL=/bin/bash +test-config-install: $(DB)/libpng-config + @echo -e Testing libpng-config functions...'\n' + @ for TYRA in LDFLAGS CPPFLAGS CFLAGS LIBS VERSION; \ + do \ + printf "(%d)\t %10s =%s\n" $$(($$gytiu + 1)) $$TYRA \ + "$$($(DB)/libpng-config `echo --$$TYRA |tr '[:upper:]' '[:lower:]'`)"; \ + gytiu=$$(( $$gytiu + 1 )); \ + done + +install: install-static install-shared install-man install-config + +# If you installed in $(DESTDIR), test-installed won't work until you +# move the library to its final location. Use test-dd to test it +# before then. + +test-dd: + echo + echo Testing installed dynamic shared library in $(DL). + $(CC) -I$(DI) $(CFLAGS) \ + `$(BINPATH)/libpng12-config --cflags` pngtest.c \ + -L$(DL) -L$(ZLIBLIB) \ + -o pngtestd `$(BINPATH)/libpng12-config --ldflags` + ./pngtestd pngtest.png + +test-installed: + $(CC) $(CFLAGS) \ + `$(BINPATH)/libpng12-config --cflags` pngtest.c \ + -L$(ZLIBLIB) \ + -o pngtesti$(EXE) `$(BINPATH)/libpng12-config --ldflags` + ./pngtesti$(EXE) pngtest.png + +clean: + /bin/rm -f *.pic.o *.o $(STATLIB) $(IMPLIB) $(SHAREDLIB) \ + pngtest-stat$(EXE) pngtest$(EXE) pngout.png $(SHAREDDEF) \ + libpng-config libpng.pc pngtesti$(EXE) + +DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO +writelock: + chmod a-w *.[ch35] $(DOCS) scripts/* + +.PHONY: buildsetup-tell libpng.pc libpng-config test-config-install clean + +# DO NOT DELETE THIS LINE -- make depend depends on it. + +png.o png.pic.o: png.h pngconf.h png.c +pngerror.o pngerror.pic.o: png.h pngconf.h pngerror.c +pngrio.o pngrio.pic.o: png.h pngconf.h pngrio.c +pngwio.o pngwio.pic.o: png.h pngconf.h pngwio.c +pngmem.o pngmem.pic.o: png.h pngconf.h pngmem.c +pngset.o pngset.pic.o: png.h pngconf.h pngset.c +pngget.o pngget.pic.o: png.h pngconf.h pngget.c +pngread.o pngread.pic.o: png.h pngconf.h pngread.c +pngrtran.o pngrtran.pic.o: png.h pngconf.h pngrtran.c +pngrutil.o pngrutil.pic.o: png.h pngconf.h pngrutil.c +pngtrans.o pngtrans.pic.o: png.h pngconf.h pngtrans.c +pngwrite.o pngwrite.pic.o: png.h pngconf.h pngwrite.c +pngwtran.o pngwtran.pic.o: png.h pngconf.h pngwtran.c +pngwutil.o pngwutil.pic.o: png.h pngconf.h pngwutil.c +pngpread.o pngpread.pic.o: png.h pngconf.h pngpread.c + +pngtest.o pngtest.pic.o: png.h pngconf.h pngtest.c diff --git a/libs/libpng-src/scripts/makefile.mips b/libs/libpng-src/scripts/makefile.mips new file mode 100644 index 000000000..2c7082dec --- /dev/null +++ b/libs/libpng-src/scripts/makefile.mips @@ -0,0 +1,87 @@ +# makefile for libpng +# Copyright (C) Glenn Randers-Pehrson +# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc. +# +# This code is released under the libpng license. +# For conditions of distribution and use, see the disclaimer +# and license in png.h + +# where make install puts libpng.a and png.h +prefix=/usr/local +INCPATH=$(prefix)/include +LIBPATH=$(prefix)/lib + +# override DESTDIR= on the make install command line to easily support +# installing into a temporary location. Example: +# +# make install DESTDIR=/tmp/build/libpng +# +# If you're going to install into a temporary location +# via DESTDIR, $(DESTDIR)$(prefix) must already exist before +# you execute make install. +DESTDIR= + +CC=cc +CFLAGS=-I../zlib -O -systype sysv -DSYSV -w -Dmips +#CFLAGS=-O +LDFLAGS=-L. -L../zlib/ -lpng -lz -lm + +#RANLIB=ranlib +RANLIB=echo + +OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \ + pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \ + pngwtran.o pngmem.o pngerror.o pngpread.o + +all: libpng.a pngtest + +libpng.a: $(OBJS) + ar rc $@ $(OBJS) + $(RANLIB) $@ + +pngtest: pngtest.o libpng.a + $(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS) + +test: pngtest + ./pngtest + +install: libpng.a + -@mkdir $(DESTDIR)$(INCPATH) + -@mkdir $(DESTDIR)$(INCPATH)/libpng + -@mkdir $(DESTDIR)$(LIBPATH) + -@rm -f $(DESTDIR)$(INCPATH)/png.h + -@rm -f $(DESTDIR)$(INCPATH)/pngconf.h + cp png.h $(DESTDIR)$(INCPATH)/libpng + cp pngconf.h $(DESTDIR)$(INCPATH)/libpng + chmod 644 $(DESTDIR)$(INCPATH)/libpng/png.h + chmod 644 $(DESTDIR)$(INCPATH)/libpng/pngconf.h + (cd $(DESTDIR)$(INCPATH); ln -f -s libpng/* .) + cp libpng.a $(DESTDIR)$(LIBPATH) + chmod 644 $(DESTDIR)$(LIBPATH)/libpng.a + +clean: + rm -f *.o libpng.a pngtest pngout.png + +DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO +writelock: + chmod a-w *.[ch35] $(DOCS) scripts/* + +# DO NOT DELETE THIS LINE -- make depend depends on it. + +png.o: png.h pngconf.h +pngerror.o: png.h pngconf.h +pngrio.o: png.h pngconf.h +pngwio.o: png.h pngconf.h +pngmem.o: png.h pngconf.h +pngset.o: png.h pngconf.h +pngget.o: png.h pngconf.h +pngread.o: png.h pngconf.h +pngpread.o: png.h pngconf.h +pngrtran.o: png.h pngconf.h +pngrutil.o: png.h pngconf.h +pngtrans.o: png.h pngconf.h +pngwrite.o: png.h pngconf.h +pngwtran.o: png.h pngconf.h +pngwutil.o: png.h pngconf.h + +pngtest.o: png.h pngconf.h diff --git a/libs/libpng-src/scripts/makefile.msc b/libs/libpng-src/scripts/makefile.msc new file mode 100644 index 000000000..df9e84dd7 --- /dev/null +++ b/libs/libpng-src/scripts/makefile.msc @@ -0,0 +1,91 @@ +# makefile for libpng +# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc. +# Copyright (C) 2006, 2009 Glenn Randers-Pehrson +# +# This code is released under the libpng license. +# For conditions of distribution and use, see the disclaimer +# and license in png.h +# +# Assumes that zlib.lib, zconf.h, and zlib.h have been copied to ..\zlib + +# -------- Microsoft C 5.1 and later, does not use assembler code -------- +MODEL=L +CFLAGS=-Oait -Gs -nologo -W3 -A$(MODEL) -I..\zlib +#-Ox generates bad code with MSC 5.1 +CC=cl +LD=link +LDFLAGS=/e/st:0x1500/noe +O=.obj + +#uncomment next to put error messages in a file +ERRFILE= >> pngerrs + +# variables +OBJS1 = png$(O) pngset$(O) pngget$(O) pngrutil$(O) pngtrans$(O) pngwutil$(O) +OBJS2 = pngmem$(O) pngpread$(O) pngread$(O) pngerror$(O) pngwrite$(O) +OBJS3 = pngrtran$(O) pngwtran$(O) pngrio$(O) pngwio$(O) + +all: libpng.lib + +png$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c $(ERRFILE) + +pngset$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c $(ERRFILE) + +pngget$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c $(ERRFILE) + +pngread$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c $(ERRFILE) + +pngpread$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c $(ERRFILE) + +pngrtran$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c $(ERRFILE) + +pngrutil$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c $(ERRFILE) + +pngerror$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c $(ERRFILE) + +pngmem$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c $(ERRFILE) + +pngrio$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c $(ERRFILE) + +pngwio$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c $(ERRFILE) + +pngtrans$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c $(ERRFILE) + +pngwrite$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c $(ERRFILE) + +pngwtran$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c $(ERRFILE) + +pngwutil$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c $(ERRFILE) + +libpng.lib: $(OBJS1) $(OBJS2) $(OBJS3) + del libpng.lib + lib libpng $(OBJS1); + lib libpng $(OBJS2); + lib libpng $(OBJS3); + +pngtest$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c $(ERRFILE) + +pngtest.exe: pngtest.obj libpng.lib + $(LD) $(LDFLAGS) pngtest.obj,,,libpng.lib ..\zlib\zlib.lib ; + +test: pngtest.exe + pngtest + +# End of makefile for libpng + diff --git a/libs/libpng-src/scripts/makefile.ne12bsd b/libs/libpng-src/scripts/makefile.ne12bsd new file mode 100644 index 000000000..d4687da00 --- /dev/null +++ b/libs/libpng-src/scripts/makefile.ne12bsd @@ -0,0 +1,49 @@ +# makefile for libpng for NetBSD for the standard +# make obj && make depend && make && make test +# make includes && make install +# Copyright (C) 2002 Patrick R.L. Welche +# Copyright (C) 2007, 2009 Glenn Randers-Pehrson +# +# This code is released under the libpng license. +# For conditions of distribution and use, see the disclaimer +# and license in png.h + +# You should also run makefile.netbsd + +LOCALBASE?=/usr/local +LIBDIR= ${LOCALBASE}/lib +MANDIR= ${LOCALBASE}/man +INCSDIR=${LOCALBASE}/include/libpng12 + +LIB= png12 +SHLIB_MAJOR= 0 +SHLIB_MINOR= 1.2.46 +SRCS= png.c pngset.c pngget.c pngrutil.c pngtrans.c pngwutil.c \ + pngread.c pngrio.c pngwio.c pngwrite.c pngrtran.c \ + pngwtran.c pngmem.c pngerror.c pngpread.c +INCS= png.h pngconf.h +MAN= libpng.3 libpngpf.3 png.5 + +CPPFLAGS+=-I${.CURDIR} + +# We should be able to do something like this instead of the manual +# uncommenting, but it core dumps for me at the moment: +# .if ${MACHINE_ARCH} == "i386" +# CPPFLAGS+=-DPNG_THREAD_UNSAFE_OK +# MKLINT= no +# .else + CPPFLAGS+=-DPNG_NO_MMX_CODE +# .endif + +CLEANFILES+=pngtest.o pngtest + +pngtest.o: pngtest.c + ${CC} -c ${CPPFLAGS} ${CFLAGS} ${.ALLSRC} -o ${.TARGET} + +pngtest: pngtest.o libpng.a + ${CC} ${LDFLAGS} ${.ALLSRC} -o${.TARGET} -lz -lm + +test: pngtest + cd ${.CURDIR} && ${.OBJDIR}/pngtest + +.include diff --git a/libs/libpng-src/scripts/makefile.netbsd b/libs/libpng-src/scripts/makefile.netbsd new file mode 100644 index 000000000..32164c7d3 --- /dev/null +++ b/libs/libpng-src/scripts/makefile.netbsd @@ -0,0 +1,49 @@ +# makefile for libpng for NetBSD for the standard +# make obj && make depend && make && make test +# make includes && make install +# Copyright (C) 2002 Patrick R.L. Welche +# Copyright (C) 2007-2009 Glenn Randers-Pehrson +# +# This code is released under the libpng license. +# For conditions of distribution and use, see the disclaimer +# and license in png.h + +# You should also run makefile.ne12bsd + +LOCALBASE?=/usr/local +LIBDIR= ${LOCALBASE}/lib +MANDIR= ${LOCALBASE}/man +INCSDIR=${LOCALBASE}/include + +LIB= png +SHLIB_MAJOR= 3 +SHLIB_MINOR= 1.2.46 +SRCS= png.c pngset.c pngget.c pngrutil.c pngtrans.c pngwutil.c \ + pngread.c pngrio.c pngwio.c pngwrite.c pngrtran.c \ + pngwtran.c pngmem.c pngerror.c pngpread.c +INCS= png.h pngconf.h +MAN= libpng.3 libpngpf.3 png.5 + +CPPFLAGS+=-I${.CURDIR} + +# We should be able to do something like this instead of the manual +# uncommenting, but it core dumps for me at the moment: +# .if ${MACHINE_ARCH} == "i386" +# CPPFLAGS+=-DPNG_THREAD_UNSAFE_OK +# MKLINT= no +# .else + CPPFLAGS+=-DPNG_NO_MMX_CODE +# .endif + +CLEANFILES+=pngtest.o pngtest + +pngtest.o: pngtest.c + ${CC} -c ${CPPFLAGS} ${CFLAGS} ${.ALLSRC} -o ${.TARGET} + +pngtest: pngtest.o libpng.a + ${CC} ${LDFLAGS} ${.ALLSRC} -o${.TARGET} -lz -lm + +test: pngtest + cd ${.CURDIR} && ${.OBJDIR}/pngtest + +.include diff --git a/libs/libpng-src/scripts/makefile.nommx b/libs/libpng-src/scripts/makefile.nommx new file mode 100644 index 000000000..1d2842e22 --- /dev/null +++ b/libs/libpng-src/scripts/makefile.nommx @@ -0,0 +1,255 @@ +# makefile for libpng.a and libpng12.so on Linux ELF with gcc +# Copyright (C) 1998, 1999, 2002, 2006-2008 Greg Roelofs and +# Glenn Randers-Pehrson +# Copyright (C) 1996, 1997 Andreas Dilger +# +# This code is released under the libpng license. +# For conditions of distribution and use, see the disclaimer +# and license in png.h + +# Library name: +LIBNAME = libpng12 +PNGMAJ = 0 +PNGMIN = 1.2.46 +PNGVER = $(PNGMAJ).$(PNGMIN) + +# Shared library names: +LIBSO=$(LIBNAME).so +LIBSOMAJ=$(LIBNAME).so.$(PNGMAJ) +LIBSOVER=$(LIBNAME).so.$(PNGVER) +OLDSO=libpng.so +OLDSOMAJ=libpng.so.3 +OLDSOVER=libpng.so.3.$(PNGMIN) + +# Utilities: +AR_RC=ar rc +CC=gcc +MKDIR_P=mkdir -p +LN_SF=ln -sf +RANLIB=ranlib +RM_F=/bin/rm -f + +# where "make install" puts libpng12.a, libpng12.so*, +# libpng12/png.h and libpng12/pngconf.h +# Prefix must be a full pathname. +prefix=/usr/local +exec_prefix=$(prefix) + +# Where the zlib library and include files are located. +#ZLIBLIB=/usr/local/lib +#ZLIBINC=/usr/local/include +ZLIBLIB=../zlib +ZLIBINC=../zlib + +ALIGN= +# for i386: +#ALIGN=-malign-loops=2 -malign-functions=2 + +WARNMORE=-Wwrite-strings -Wpointer-arith -Wshadow \ + -Wmissing-declarations -Wtraditional -Wcast-align \ + -Wstrict-prototypes -Wmissing-prototypes #-Wconversion + +# for pgcc version 2.95.1, -O3 is buggy; don't use it. + +CFLAGS=-I$(ZLIBINC) -W -Wall -O3 -funroll-loops -DPNG_NO_MMX_CODE \ + $(ALIGN) # $(WARNMORE) -g -DPNG_DEBUG=5 + +LDFLAGS=-L. -Wl,-rpath,. -L$(ZLIBLIB) -Wl,-rpath,$(ZLIBLIB) -lpng12 -lz -lm +LDFLAGS_A=-L$(ZLIBLIB) -Wl,-rpath,$(ZLIBLIB) libpng.a -lz -lm + +INCPATH=$(prefix)/include +LIBPATH=$(exec_prefix)/lib +MANPATH=$(prefix)/man +BINPATH=$(exec_prefix)/bin + +# override DESTDIR= on the make install command line to easily support +# installing into a temporary location. Example: +# +# make install DESTDIR=/tmp/build/libpng +# +# If you're going to install into a temporary location +# via DESTDIR, $(DESTDIR)$(prefix) must already exist before +# you execute make install. +DESTDIR= + +DB=$(DESTDIR)$(BINPATH) +DI=$(DESTDIR)$(INCPATH) +DL=$(DESTDIR)$(LIBPATH) +DM=$(DESTDIR)$(MANPATH) + +OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \ + pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \ + pngwtran.o pngmem.o pngerror.o pngpread.o + +OBJSDLL = $(OBJS:.o=.pic.o) + +.SUFFIXES: .c .o .pic.o + +.c.pic.o: + $(CC) -c $(CFLAGS) -fPIC -o $@ $*.c + +all: libpng.a $(LIBSO) pngtest pngtest-static libpng.pc libpng-config + +libpng.a: $(OBJS) + $(AR_RC) $@ $(OBJS) + $(RANLIB) $@ + +libpng.pc: + cat scripts/libpng.pc.in | sed -e s!@prefix@!$(prefix)! \ + -e s!@exec_prefix@!$(exec_prefix)! \ + -e s!@libdir@!$(LIBPATH)! \ + -e s!@includedir@!$(INCPATH)! \ + -e s!@includedir@!$(INCPATH)! \ + -e s!-lpng12!-lpng12\ -lz\ -lm! \ + -e s!Cflags: !Cflags:\ -DPNG_NO_MMX_CODE!> libpng.pc + +libpng-config: + ( cat scripts/libpng-config-head.in; \ + echo prefix=\"$(prefix)\"; \ + echo I_opts=\"-I$(INCPATH)/$(LIBNAME) -DPNG_NO_MMX_CODE\"; \ + echo L_opts=\"-L$(LIBPATH)\"; \ + echo R_opts=\"-Wl,-rpath,$(LIBPATH)\"; \ + echo libs=\"-lpng12 -lz -lm\"; \ + cat scripts/libpng-config-body.in ) > libpng-config + chmod +x libpng-config + +$(LIBSO): $(LIBSOMAJ) + $(LN_SF) $(LIBSOMAJ) $(LIBSO) + +$(LIBSOMAJ): $(LIBSOVER) + $(LN_SF) $(LIBSOVER) $(LIBSOMAJ) + +$(LIBSOVER): $(OBJSDLL) + $(CC) -shared -Wl,-soname,$(LIBSOMAJ) -o $(LIBSOVER) $(OBJSDLL) + +$(OLDSOVER): $(OBJSDLL) + $(CC) -shared -Wl,-soname,$(OLDSOMAJ) \ + -o $(OLDSOVER) \ + $(OBJSDLL) + +pngtest: pngtest.o $(LIBSO) + $(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS) + +pngtest-static: pngtest.o libpng.a + $(CC) -o pngtest-static $(CFLAGS) pngtest.o $(LDFLAGS_A) + +test: pngtest pngtest-static + @echo "" + @echo " Running pngtest dynamically linked with $(LIBSO):" + @echo "" + ./pngtest + @echo "" + @echo " Running pngtest statically linked with libpng.a:" + @echo "" + ./pngtest-static + +install-headers: png.h pngconf.h + -@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi + -@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi + cp png.h pngconf.h $(DI)/$(LIBNAME) + chmod 644 $(DI)/$(LIBNAME)/png.h $(DI)/$(LIBNAME)/pngconf.h + -@$(RM_F) $(DI)/png.h $(DI)/pngconf.h + -@$(RM_F) $(DI)/libpng + (cd $(DI); $(LN_SF) $(LIBNAME) libpng; $(LN_SF) $(LIBNAME)/* .) + +install-static: install-headers libpng.a + -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi + cp libpng.a $(DL)/$(LIBNAME).a + chmod 644 $(DL)/$(LIBNAME).a + -@$(RM_F) $(DL)/libpng.a + (cd $(DL); $(LN_SF) $(LIBNAME).a libpng.a) + +install-shared: install-headers $(LIBSOVER) libpng.pc \ + $(OLDSOVER) + -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi + -@$(RM_F) $(DL)/$(LIBSOVER)* $(DL)/$(LIBSO) + -@$(RM_F) $(DL)/$(LIBSOMAJ) + -@$(RM_F) $(DL)/$(OLDSO) + -@$(RM_F) $(DL)/$(OLDSOMAJ) + -@$(RM_F) $(DL)/$(OLDSOVER)* + cp $(LIBSOVER) $(DL) + cp $(OLDSOVER) $(DL) + chmod 755 $(DL)/$(LIBSOVER) + chmod 755 $(DL)/$(OLDSOVER) + (cd $(DL); \ + $(LN_SF) $(OLDSOVER) $(OLDSOMAJ); \ + $(LN_SF) $(OLDSOMAJ) $(OLDSO); \ + $(LN_SF) $(LIBSOVER) $(LIBSOMAJ); \ + $(LN_SF) $(LIBSOMAJ) $(LIBSO)) + -@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi + -@$(RM_F) $(DL)/pkgconfig/$(LIBNAME).pc + -@$(RM_F) $(DL)/pkgconfig/libpng.pc + cp libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc + chmod 644 $(DL)/pkgconfig/$(LIBNAME).pc + (cd $(DL)/pkgconfig; $(LN_SF) $(LIBNAME).pc libpng.pc) + +install-man: libpng.3 libpngpf.3 png.5 + -@if [ ! -d $(DM) ]; then $(MKDIR_P) $(DM); fi + -@if [ ! -d $(DM)/man3 ]; then $(MKDIR_P) $(DM)/man3; fi + -@$(RM_F) $(DM)/man3/libpng.3 + -@$(RM_F) $(DM)/man3/libpngpf.3 + cp libpng.3 $(DM)/man3 + cp libpngpf.3 $(DM)/man3 + -@if [ ! -d $(DM)/man5 ]; then $(MKDIR_P) $(DM)/man5; fi + -@$(RM_F) $(DM)/man5/png.5 + cp png.5 $(DM)/man5 + +install-config: libpng-config + -@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi + -@$(RM_F) $(DB)/libpng-config + -@$(RM_F) $(DB)/$(LIBNAME)-config + cp libpng-config $(DB)/$(LIBNAME)-config + chmod 755 $(DB)/$(LIBNAME)-config + (cd $(DB); $(LN_SF) $(LIBNAME)-config libpng-config) + +install: install-static install-shared install-man install-config + +# If you installed in $(DESTDIR), test-installed won't work until you +# move the library to its final location. Use test-dd to test it +# before then. + +test-dd: + echo + echo Testing installed dynamic shared library in $(DL). + $(CC) -I$(DI) -I$(ZLIBINC) \ + `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \ + -L$(DL) -L$(ZLIBLIB) -Wl, -rpath,$(DL) -Wl,-rpath,$(ZLIBLIB) \ + -o pngtestd `$(BINPATH)/$(LIBNAME)-config --ldflags` + ./pngtestd pngtest.png + +test-installed: + $(CC) -I$(ZLIBINC) \ + `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \ + -L$(ZLIBLIB) -Wl,-rpath,$(ZLIBLIB) \ + -o pngtesti `$(BINPATH)/$(LIBNAME)-config --ldflags` + ./pngtesti pngtest.png + +clean: + $(RM_F) *.o libpng.a pngtest pngout.png libpng-config \ + $(LIBSO) $(LIBSOMAJ)* pngtest-static pngtesti \ + $(OLDSOVER) \ + libpng.pc + +DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO +writelock: + chmod a-w *.[ch35] $(DOCS) scripts/* + +# DO NOT DELETE THIS LINE -- make depend depends on it. + +png.o png.pic.o: png.h pngconf.h png.c +pngerror.o pngerror.pic.o: png.h pngconf.h pngerror.c +pngrio.o pngrio.pic.o: png.h pngconf.h pngrio.c +pngwio.o pngwio.pic.o: png.h pngconf.h pngwio.c +pngmem.o pngmem.pic.o: png.h pngconf.h pngmem.c +pngset.o pngset.pic.o: png.h pngconf.h pngset.c +pngget.o pngget.pic.o: png.h pngconf.h pngget.c +pngread.o pngread.pic.o: png.h pngconf.h pngread.c +pngrtran.o pngrtran.pic.o: png.h pngconf.h pngrtran.c +pngrutil.o pngrutil.pic.o: png.h pngconf.h pngrutil.c +pngtrans.o pngtrans.pic.o: png.h pngconf.h pngtrans.c +pngwrite.o pngwrite.pic.o: png.h pngconf.h pngwrite.c +pngwtran.o pngwtran.pic.o: png.h pngconf.h pngwtran.c +pngwutil.o pngwutil.pic.o: png.h pngconf.h pngwutil.c +pngpread.o pngpread.pic.o: png.h pngconf.h pngpread.c + +pngtest.o: png.h pngconf.h pngtest.c diff --git a/libs/libpng-src/scripts/makefile.openbsd b/libs/libpng-src/scripts/makefile.openbsd new file mode 100644 index 000000000..c3c2e3b44 --- /dev/null +++ b/libs/libpng-src/scripts/makefile.openbsd @@ -0,0 +1,76 @@ +# makefile for libpng +# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc. +# Copyright (C) 2007-2009 Glenn Randers-Pehrson +# +# This code is released under the libpng license. +# For conditions of distribution and use, see the disclaimer +# and license in png.h + +PREFIX?= /usr/local +LIBDIR= ${PREFIX}/lib +MANDIR= ${PREFIX}/man/cat + +SHLIB_MAJOR= 0 +SHLIB_MINOR= 1.2.46 + +LIB= png +SRCS= png.c pngerror.c pngget.c pngmem.c pngpread.c \ + pngread.c pngrio.c pngrtran.c pngrutil.c pngset.c pngtrans.c \ + pngwio.c pngwrite.c pngwtran.c pngwutil.c + +HDRS= png.h pngconf.h + +CFLAGS+= -W -Wall +CPPFLAGS+= -I${.CURDIR} -DPNG_NO_MMX_CODE + +NOPROFILE= Yes + +CLEANFILES+= pngtest.o pngtest + +MAN= libpng.3 libpngpf.3 png.5 +DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO libpng.txt + +pngtest.o: pngtest.c + ${CC} ${CPPFLAGS} ${CFLAGS} -c ${.ALLSRC} -o ${.TARGET} + +pngtest: pngtest.o + ${CC} ${LDFLAGS} ${.ALLSRC} -o ${.TARGET} -L${.OBJDIR} -lpng -lz -lm + +test: pngtest + cd ${.OBJDIR} && env \ + LD_LIBRARY_PATH="${.OBJDIR}" ${.OBJDIR}/pngtest + +beforeinstall: + if [ ! -d ${DESTDIR}${PREFIX}/include/libpng ]; then \ + ${INSTALL} -d -o root -g wheel ${DESTDIR}${PREFIX}/include; \ + fi + if [ ! -d ${DESTDIR}${LIBDIR} ]; then \ + ${INSTALL} -d -o root -g wheel ${DESTDIR}${LIBDIR}; \ + fi + if [ ! -d ${DESTDIR}${LIBDIR}/debug ]; then \ + ${INSTALL} -d -o root -g wheel ${DESTDIR}${LIBDIR}/debug; \ + fi + if [ ! -d ${DESTDIR}${MANDIR}3 ]; then \ + ${INSTALL} -d -o root -g wheel ${DESTDIR}${MANDIR}3; \ + fi + if [ ! -d ${DESTDIR}${MANDIR}5 ]; then \ + ${INSTALL} -d -o root -g wheel ${DESTDIR}${MANDIR}5; \ + fi + if [ ! -d ${DESTDIR}${PREFIX}/share/doc/png ]; then \ + ${INSTALL} -d -o root -g wheel ${DESTDIR}${PREFIX}/share/doc/png; \ + fi + +afterinstall: + @rm -f ${DESTDIR}${LIBDIR}/libpng_pic.a + @rm -f ${DESTDIR}${LIBDIR}/debug/libpng.a + @rm -f ${DESTDIR}${PREFIX}/include/png.h + @rm -f ${DESTDIR}${PREFIX}/include/pngconf.h + @rmdir ${DESTDIR}${LIBDIR}/debug 2>/dev/null || true + ${INSTALL} ${INSTALL_COPY} -o ${SHAREOWN} -g ${SHAREGRP} \ + -m ${NONBINMODE} ${HDRS} ${DESTDIR}${PREFIX}/include + ${INSTALL} ${INSTALL_COPY} -o ${SHAREOWN} -g ${SHAREGRP} \ + -m ${NONBINMODE} ${HDRS} ${DESTDIR}${PREFIX}/include + ${INSTALL} ${INSTALL_COPY} -o ${SHAREOWN} -g ${SHAREGRP} \ + -m ${NONBINMODE} ${DOCS} ${DESTDIR}${PREFIX}/share/doc/png + +.include diff --git a/libs/libpng-src/scripts/makefile.os2 b/libs/libpng-src/scripts/makefile.os2 new file mode 100644 index 000000000..907cfc894 --- /dev/null +++ b/libs/libpng-src/scripts/makefile.os2 @@ -0,0 +1,72 @@ +# makefile for libpng on OS/2 with gcc +# +# This code is released under the libpng license. +# For conditions of distribution and use, see the disclaimer +# and license in png.h + +# Related files: pngos2.def + +CC=gcc -Zomf -s + +# Where the zlib library and include files are located +ZLIBLIB=../zlib +ZLIBINC=../zlib + +WARNMORE=-Wwrite-strings -Wpointer-arith -Wshadow \ + -Wmissing-declarations -Wtraditional -Wcast-align \ + -Wstrict-prototypes -Wmissing-prototypes #-Wconversion +CFLAGS=-I$(ZLIBINC) -W -Wall -O6 -funroll-loops -malign-loops=2 \ + -malign-functions=2 #$(WARNMORE) -g -DPNG_DEBUG=5 +LDFLAGS=-L. -L$(ZLIBLIB) -lpng -lzdll -Zcrtdll +AR=emxomfar + +PNGLIB=png.lib +IMPLIB=emximp +SHAREDLIB=png.dll +SHAREDLIBIMP=pngdll.lib + +OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \ + pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \ + pngwtran.o pngmem.o pngerror.o pngpread.o + +.SUFFIXES: .c .o + +all: $(PNGLIB) $(SHAREDLIB) $(SHAREDLIBIMP) + +$(PNGLIB): $(OBJS) + $(AR) rc $@ $(OBJS) + +$(SHAREDLIB): $(OBJS) pngos2.def + $(CC) $(LDFLAGS) -Zdll -o $@ $^ + +$(SHAREDLIBIMP): pngos2.def + $(IMPLIB) -o $@ $^ + +pngtest.exe: pngtest.o png.dll pngdll.lib + $(CC) -o $@ $(CFLAGS) $< $(LDFLAGS) + +test: pngtest.exe + ./pngtest.exe + +clean: + rm -f *.o $(PNGLIB) png.dll pngdll.lib pngtest.exe pngout.png + +# DO NOT DELETE THIS LINE -- make depend depends on it. + +png.o png.pic.o: png.h pngconf.h +pngerror.o pngerror.pic.o: png.h pngconf.h +pngrio.o pngrio.pic.o: png.h pngconf.h +pngwio.o pngwio.pic.o: png.h pngconf.h +pngmem.o pngmem.pic.o: png.h pngconf.h +pngset.o pngset.pic.o: png.h pngconf.h +pngget.o pngget.pic.o: png.h pngconf.h +pngread.o pngread.pic.o: png.h pngconf.h +pngrtran.o pngrtran.pic.o: png.h pngconf.h +pngrutil.o pngrutil.pic.o: png.h pngconf.h +pngtrans.o pngtrans.pic.o: png.h pngconf.h +pngwrite.o pngwrite.pic.o: png.h pngconf.h +pngwtran.o pngwtran.pic.o: png.h pngconf.h +pngwutil.o pngwutil.pic.o: png.h pngconf.h +pngpread.o pngpread.pic.o: png.h pngconf.h + +pngtest.o: png.h pngconf.h diff --git a/libs/libpng-src/scripts/makefile.sco b/libs/libpng-src/scripts/makefile.sco new file mode 100644 index 000000000..0e5942398 --- /dev/null +++ b/libs/libpng-src/scripts/makefile.sco @@ -0,0 +1,232 @@ +# makefile for SCO OSr5 ELF and Unixware 7 with Native cc +# Contributed by Mike Hopkirk (hops@sco.com) modified from Makefile.lnx +# force ELF build dynamic linking, SONAME setting in lib and RPATH in app +# Copyright (C) 2002, 2006 Glenn Randers-Pehrson +# Copyright (C) 1998 Greg Roelofs +# Copyright (C) 1996, 1997 Andreas Dilger +# +# This code is released under the libpng license. +# For conditions of distribution and use, see the disclaimer +# and license in png.h + +# Library name: +LIBNAME = libpng12 +PNGMAJ = 0 +PNGMIN = 1.2.46 +PNGVER = $(PNGMAJ).$(PNGMIN) + +# Shared library names: +LIBSO=$(LIBNAME).so +LIBSOMAJ=$(LIBNAME).so.$(PNGMAJ) +LIBSOVER=$(LIBNAME).so.$(PNGVER) +OLDSO=libpng.so +OLDSOMAJ=libpng.so.3 +OLDSOVER=libpng.so.3.$(PNGMIN) + +# Utilities: +CC=cc +AR_RC=ar rc +MKDIR_P=mkdir +LN_SF=ln -f -s +RANLIB=echo +RM_F=/bin/rm -f + +# where make install puts libpng.a, $(OLDSO)*, and png.h +prefix=/usr/local +exec_prefix=$(prefix) + +# Where the zlib library and include files are located +#ZLIBLIB=/usr/local/lib +#ZLIBINC=/usr/local/include +ZLIBLIB=../zlib +ZLIBINC=../zlib + +CFLAGS= -dy -belf -I$(ZLIBINC) -O3 -DPNG_NO_MMX_CODE +LDFLAGS=-L. -L$(ZLIBLIB) -lpng12 -lz -lm + +INCPATH=$(prefix)/include +LIBPATH=$(exec_prefix)/lib +MANPATH=$(prefix)/man +BINPATH=$(exec_prefix)/bin + +# override DESTDIR= on the make install command line to easily support +# installing into a temporary location. Example: +# +# make install DESTDIR=/tmp/build/libpng +# +# If you're going to install into a temporary location +# via DESTDIR, $(DESTDIR)$(prefix) must already exist before +# you execute make install. +DESTDIR= + +DB=$(DESTDIR)$(BINPATH) +DI=$(DESTDIR)$(INCPATH) +DL=$(DESTDIR)$(LIBPATH) +DM=$(DESTDIR)$(MANPATH) + +OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \ + pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \ + pngwtran.o pngmem.o pngerror.o pngpread.o + +OBJSDLL = $(OBJS:.o=.pic.o) + +.SUFFIXES: .c .o .pic.o + +.c.pic.o: + $(CC) -c $(CFLAGS) -KPIC -o $@ $*.c + +all: libpng.a $(LIBSO) pngtest libpng.pc libpng-config + +libpng.a: $(OBJS) + $(AR_RC) $@ $(OBJS) + $(RANLIB) $@ + +libpng.pc: + cat scripts/libpng.pc.in | sed -e s!@prefix@!$(prefix)! \ + -e s!@exec_prefix@!$(exec_prefix)! \ + -e s!@libdir@!$(LIBPATH)! \ + -e s!@includedir@!$(INCPATH)! \ + -e s!-lpng12!-lpng12\ -lz\ -lm! > libpng.pc + +libpng-config: + ( cat scripts/libpng-config-head.in; \ + echo prefix=\"$(prefix)\"; \ + echo I_opts=\"-I$(INCPATH)/$(LIBNAME)\"; \ + echo ccopts=\"-belf\"; \ + echo L_opts=\"-L$(LIBPATH)\"; \ + echo libs=\"-lpng12 -lz -lm\"; \ + cat scripts/libpng-config-body.in ) > libpng-config + chmod +x libpng-config + +$(LIBSO): $(LIBSOMAJ) + $(LN_SF) $(LIBSOMAJ) $(LIBSO) + +$(LIBSOMAJ): $(LIBSOVER) + $(LN_SF) $(LIBSOVER) $(LIBSOMAJ) + +$(LIBSOVER): $(OBJSDLL) + $(CC) -G -Wl,-h,$(LIBSOMAJ) -o $(LIBSOVER) \ + $(OBJSDLL) + +$(OLDSOVER): $(OBJSDLL) + $(CC) -G -Wl,-h,$(OLDSOMAJ) -o $(OLDSOVER) \ + $(OBJSDLL) + +pngtest: pngtest.o $(LIBSO) + LD_RUN_PATH=.:$(ZLIBLIB) $(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS) + +test: pngtest + ./pngtest + +install-headers: png.h pngconf.h + -@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi + -@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi + -@$(RM_F) $(DI)/png.h + -@$(RM_F) $(DI)/pngconf.h + cp png.h pngconf.h $(DI)/$(LIBNAME) + chmod 644 $(DI)/$(LIBNAME)/png.h $(DI)/$(LIBNAME)/pngconf.h + -@$(RM_F) $(DI)/png.h $(DI)/pngconf.h + -@$(RM_F) $(DI)/libpng + (cd $(DI); $(LN_SF) $(LIBNAME) libpng; $(LN_SF) $(LIBNAME)/* .) + +install-static: install-headers libpng.a + -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi + cp libpng.a $(DL)/$(LIBNAME).a + chmod 644 $(DL)/$(LIBNAME).a + -@$(RM_F) $(DL)/libpng.a + (cd $(DL); $(LN_SF) $(LIBNAME).a libpng.a) + +install-shared: install-headers $(LIBSOVER) libpng.pc \ + $(OLDSOVER) + -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi + -@$(RM_F) $(DL)/$(LIBSOVER)* $(DL)/$(LIBSO) + -@$(RM_F) $(DL)/$(LIBSOMAJ) + -@$(RM_F) $(DL)/$(OLDSO) + -@$(RM_F) $(DL)/$(OLDSOMAJ) + -@$(RM_F) $(DL)/$(OLDSOVER)* + cp $(LIBSOVER) $(DL) + cp $(OLDSOVER) $(DL) + chmod 755 $(DL)/$(LIBSOVER) + chmod 755 $(DL)/$(OLDSOVER) + (cd $(DL); \ + $(LN_SF) $(OLDSOVER) $(OLDSOMAJ); \ + $(LN_SF) $(OLDSOMAJ) $(OLDSO); \ + $(LN_SF) $(LIBSOVER) $(LIBSOMAJ); \ + $(LN_SF) $(LIBSOMAJ) $(LIBSO)) + -@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi + -@$(RM_F) $(DL)/pkgconfig/$(LIBNAME).pc + -@$(RM_F) $(DL)/pkgconfig/libpng.pc + cp libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc + chmod 644 $(DL)/pkgconfig/$(LIBNAME).pc + (cd $(DL)/pkgconfig; $(LN_SF) $(LIBNAME).pc libpng.pc) + +install-man: libpng.3 libpngpf.3 png.5 + -@if [ ! -d $(DM) ]; then $(MKDIR_P) $(DM); fi + -@if [ ! -d $(DM)/man3 ]; then $(MKDIR_P) $(DM)/man3; fi + -@$(RM_F) $(DM)/man3/libpng.3 + -@$(RM_F) $(DM)/man3/libpngpf.3 + cp libpng.3 $(DM)/man3 + cp libpngpf.3 $(DM)/man3 + -@if [ ! -d $(DM)/man5 ]; then $(MKDIR_P) $(DM)/man5; fi + -@$(RM_F) $(DM)/man5/png.5 + cp png.5 $(DM)/man5 + +install-config: libpng-config + -@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi + -@$(RM_F) $(DB)/libpng-config + -@$(RM_F) $(DB)/$(LIBNAME)-config + cp libpng-config $(DB)/$(LIBNAME)-config + chmod 755 $(DB)/$(LIBNAME)-config + (cd $(DB); $(LN_SF) $(LIBNAME)-config libpng-config) + +install: install-static install-shared install-man install-config + +# If you installed in $(DESTDIR), test-installed won't work until you +# move the library to its final location. Use test-dd to test it +# before then. + +test-dd: + echo + echo Testing installed dynamic shared library in $(DL). + $(CC) -I$(DI) $(CFLAGS) \ + `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \ + -L$(DL) -L$(ZLIBLIB) \ + -o pngtestd `$(BINPATH)/$(LIBNAME)-config --ldflags` + ./pngtestd pngtest.png + +test-installed: + $(CC) $(CFLAGS) \ + `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \ + -L$(ZLIBLIB) \ + -o pngtesti `$(BINPATH)/$(LIBNAME)-config --ldflags` + ./pngtesti pngtest.png + +clean: + $(RM_F) *.o libpng.a pngtest pngout.png libpng-config \ + $(LIBSO) $(LIBSOMAJ)* pngtest-static pngtesti \ + $(OLDSOVER) \ + libpng.pc + +DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO +writelock: + chmod a-w *.[ch35] $(DOCS) scripts/* + +# DO NOT DELETE THIS LINE -- make depend depends on it. + +png.o png.pic.o: png.h pngconf.h +pngerror.o pngerror.pic.o: png.h pngconf.h +pngrio.o pngrio.pic.o: png.h pngconf.h +pngwio.o pngwio.pic.o: png.h pngconf.h +pngmem.o pngmem.pic.o: png.h pngconf.h +pngset.o pngset.pic.o: png.h pngconf.h +pngget.o pngget.pic.o: png.h pngconf.h +pngread.o pngread.pic.o: png.h pngconf.h +pngrtran.o pngrtran.pic.o: png.h pngconf.h +pngrutil.o pngrutil.pic.o: png.h pngconf.h +pngtrans.o pngtrans.pic.o: png.h pngconf.h +pngwrite.o pngwrite.pic.o: png.h pngconf.h +pngwtran.o pngwtran.pic.o: png.h pngconf.h +pngwutil.o pngwutil.pic.o: png.h pngconf.h +pngpread.o pngpread.pic.o: png.h pngconf.h + +pngtest.o: png.h pngconf.h diff --git a/libs/libpng-src/scripts/makefile.sggcc b/libs/libpng-src/scripts/makefile.sggcc new file mode 100644 index 000000000..c6b3e5062 --- /dev/null +++ b/libs/libpng-src/scripts/makefile.sggcc @@ -0,0 +1,243 @@ +# makefile for libpng.a and libpng12.so, SGI IRIX with 'cc' +# Copyright (C) 2001-2002, 2006 Glenn Randers-Pehrson +# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc. +# +# This code is released under the libpng license. +# For conditions of distribution and use, see the disclaimer +# and license in png.h + +# Library name: +LIBNAME=libpng12 +PNGMAJ = 0 +PNGMIN = 1.2.46 +PNGVER = $(PNGMAJ).$(PNGMIN) + +# Shared library names: +LIBSO=$(LIBNAME).so +LIBSOMAJ=$(LIBNAME).so.$(PNGMAJ) +LIBSOVER=$(LIBNAME).so.$(PNGVER) +OLDSO=libpng.so +OLDSOMAJ=libpng.so.3 +OLDSOVER=libpng.so.3.$(PNGMIN) + +# Utilities: +AR_RC=ar rc +CC=gcc +MKDIR_P=mkdir -p +LN_SF=ln -sf +RANLIB=echo +RM_F=/bin/rm -f + +# Where make install puts libpng.a, libpng12.so, and libpng12/png.h +# Prefix must be a full pathname. + +prefix=/usr/local +exec_prefix=$(prefix) + +# Where the zlib library and include files are located +#ZLIBLIB=/usr/local/lib32 +#ZLIBINC=/usr/local/include +#ZLIBLIB=/usr/local/lib +#ZLIBINC=/usr/local/include +ZLIBLIB=../zlib +ZLIBINC=../zlib + +# ABI can be blank to use default for your system, -32, -o32, -n32, or -64 +# See "man abi". zlib must be built with the same ABI. +ABI= + +WARNMORE= # -g -DPNG_DEBUG=5 +CFLAGS=$(ABI) -I$(ZLIBINC) -O $(WARNMORE) -fPIC -mabi=n32 -DPNG_NO_MMX_CODE +LDFLAGS=$(ABI) -L. -L$(ZLIBLIB) -lpng -lz -lm +LDSHARED=cc $(ABI) -shared -soname $(LIBSOMAJ) \ + -set_version sgi$(PNGMAJ).0 +LDLEGACY=cc $(ABI) -shared -soname $(OLDSOMAJ) \ + -set_version sgi$3.0 +# See "man dso" for info about shared objects + +INCPATH=$(prefix)/include +LIBPATH=$(exec_prefix)/lib +#LIBPATH=$(exec_prefix)/lib32 +MANPATH=$(prefix)/man +BINPATH=$(exec_prefix)/bin + +# override DESTDIR= on the make install command line to easily support +# installing into a temporary location. Example: +# +# make install DESTDIR=/tmp/build/libpng +# +# If you're going to install into a temporary location +# via DESTDIR, $(DESTDIR)$(prefix) must already exist before +# you execute make install. +DESTDIR= + +DB=$(DESTDIR)$(BINPATH) +DI=$(DESTDIR)$(INCPATH) +DL=$(DESTDIR)$(LIBPATH) +DM=$(DESTDIR)$(MANPATH) + +OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \ + pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \ + pngwtran.o pngmem.o pngerror.o pngpread.o + +all: libpng.a pngtest shared libpng.pc libpng-config + +libpng.a: $(OBJS) + $(AR_RC) $@ $(OBJS) + $(RANLIB) $@ + +shared: $(LIBSOVER) + +libpng.pc: + cat scripts/libpng.pc.in | sed -e s!@prefix@!$(prefix)! \ + -e s!@exec_prefix@!$(exec_prefix)! \ + -e s!@libdir@!$(LIBPATH)! \ + -e s!@includedir@!$(INCPATH)! \ + -e s!-lpng12!-lpng12\ -lz\ -lm! > libpng.pc + +libpng-config: + ( cat scripts/libpng-config-head.in; \ + echo prefix=\"$(prefix)\"; \ + echo I_opts=\"-I$(INCPATH)/$(LIBNAME)\"; \ + echo ccopts=\"$(ABI)\"; \ + echo cppflags=\"-DPNG_NO_MMX_CODE\"; \ + echo ldopts=\"$(ABI)\"; \ + echo L_opts=\"-L$(LIBPATH)\"; \ + echo libdir=\"$(LIBPATH)\"; \ + echo libs=\"-lpng12 -lz -lm\"; \ + cat scripts/libpng-config-body.in ) > libpng-config + chmod +x libpng-config + +$(LIBSO): $(LIBSOMAJ) + $(LN_SF) $(LIBSOMAJ) $(LIBSO) + +$(LIBSOMAJ): $(LIBSOVER) + $(LN_SF) $(LIBSOVER) $(LIBSOMAJ) + +$(LIBSOVER): $(OBJS) + $(LDSHARED) -o $@ $(OBJS) + $(RM_F) $(LIBSO) $(LIBSOMAJ) + +$(OLDSOVER): $(OBJS) + $(LDLEGACY) -o $@ $(OBJS) + +pngtest: pngtest.o libpng.a + $(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS) + +test: pngtest + echo + echo Testing local static library. + ./pngtest + +install-headers: png.h pngconf.h + -@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi + -@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi + cp png.h pngconf.h $(DI)/$(LIBNAME) + chmod 644 $(DI)/$(LIBNAME)/png.h $(DI)/$(LIBNAME)/pngconf.h + -@$(RM_F) $(DI)/png.h $(DI)/pngconf.h + -@$(RM_F) $(DI)/libpng + (cd $(DI); $(LN_SF) $(LIBNAME) libpng; $(LN_SF) $(LIBNAME)/* .) + +install-static: install-headers libpng.a + -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi + cp libpng.a $(DL)/$(LIBNAME).a + chmod 644 $(DL)/$(LIBNAME).a + -@$(RM_F) $(DL)/libpng.a + (cd $(DL); $(LN_SF) $(LIBNAME).a libpng.a) + +install-shared: install-headers $(LIBSOVER) libpng.pc \ + $(OLDSOVER) + -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi + -@$(RM_F) $(DL)/$(LIBSOVER)* $(DL)/$(LIBSO) + -@$(RM_F) $(DL)/$(LIBSOMAJ) + -@$(RM_F) $(DL)/$(OLDSO) + -@$(RM_F) $(DL)/$(OLDSOMAJ) + -@$(RM_F) $(DL)/$(OLDSOVER)* + cp $(LIBSOVER) $(DL) + cp $(OLDSOVER) $(DL) + chmod 755 $(DL)/$(LIBSOVER) + chmod 755 $(DL)/$(OLDSOVER) + (cd $(DL); \ + $(LN_SF) $(OLDSOVER) $(OLDSOMAJ); \ + $(LN_SF) $(OLDSOMAJ) $(OLDSO); \ + $(LN_SF) $(LIBSOVER) $(LIBSOMAJ); \ + $(LN_SF) $(LIBSOMAJ) $(LIBSO)) + -@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi + -@$(RM_F) $(DL)/pkgconfig/$(LIBNAME).pc + -@$(RM_F) $(DL)/pkgconfig/libpng.pc + cp libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc + chmod 644 $(DL)/pkgconfig/$(LIBNAME).pc + (cd $(DL)/pkgconfig; $(LN_SF) $(LIBNAME).pc libpng.pc) + +install-man: libpng.3 libpngpf.3 png.5 + -@if [ ! -d $(DM) ]; then $(MKDIR_P) $(DM); fi + -@if [ ! -d $(DM)/man3 ]; then $(MKDIR_P) $(DM)/man3; fi + -@$(RM_F) $(DM)/man3/libpng.3 + -@$(RM_F) $(DM)/man3/libpngpf.3 + cp libpng.3 $(DM)/man3 + cp libpngpf.3 $(DM)/man3 + -@if [ ! -d $(DM)/man5 ]; then $(MKDIR_P) $(DM)/man5; fi + -@$(RM_F) $(DM)/man5/png.5 + cp png.5 $(DM)/man5 + +install-config: libpng-config + -@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi + -@$(RM_F) $(DB)/libpng-config + -@$(RM_F) $(DB)/$(LIBNAME)-config + cp libpng-config $(DB)/$(LIBNAME)-config + chmod 755 $(DB)/$(LIBNAME)-config + (cd $(DB); $(LN_SF) $(LIBNAME)-config libpng-config) + +install: install-static install-shared install-man install-config + +# If you installed in $(DESTDIR), test-installed won't work until you +# move the library to its final location. Use test-dd to test it +# before then. + +test-dd: + echo + echo Testing installed dynamic shared library in $(DL). + $(CC) -I$(DI) -I$(ZLIBINC) \ + `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \ + -L$(DL) -L$(ZLIBLIB) \ + -rpath $(ZLIBLIB):$(DL) \ + -o pngtestd `$(BINPATH)/$(LIBNAME)-config --ldflags` + ./pngtestd pngtest.png + +test-installed: + echo + echo Testing installed dynamic shared library. + $(CC) -I$(ZLIBINC) \ + `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \ + -L$(ZLIBLIB) \ + -rpath $(ZLIBLIB):`$(BINPATH)/$(LIBNAME)-config --libdir` \ + -o pngtesti `$(BINPATH)/$(LIBNAME)-config --ldflags` + ./pngtesti pngtest.png + +clean: + $(RM_F) libpng.a pngtest pngtesti pngout.png libpng.pc \ + so_locations libpng-config $(LIBSO) $(LIBSOMAJ)* $(OLDSOVER) + +DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO +writelock: + chmod a-w *.[ch35] $(DOCS) scripts/* + +# DO NOT DELETE THIS LINE -- make depend depends on it. + +png.o: png.h pngconf.h +pngerror.o: png.h pngconf.h +pngrio.o: png.h pngconf.h +pngwio.o: png.h pngconf.h +pngmem.o: png.h pngconf.h +pngset.o: png.h pngconf.h +pngget.o: png.h pngconf.h +pngread.o: png.h pngconf.h +pngrtran.o: png.h pngconf.h +pngrutil.o: png.h pngconf.h +pngtrans.o: png.h pngconf.h +pngwrite.o: png.h pngconf.h +pngwtran.o: png.h pngconf.h +pngwutil.o: png.h pngconf.h +pngpread.o: png.h pngconf.h + +pngtest.o: png.h pngconf.h diff --git a/libs/libpng-src/scripts/makefile.sgi b/libs/libpng-src/scripts/makefile.sgi new file mode 100644 index 000000000..d34ea99c0 --- /dev/null +++ b/libs/libpng-src/scripts/makefile.sgi @@ -0,0 +1,248 @@ +# makefile for libpng.a and libpng12.so, SGI IRIX with 'cc' +# Copyright (C) 2001-2002, 2006, 2007 Glenn Randers-Pehrson +# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc. +# +# This code is released under the libpng license. +# For conditions of distribution and use, see the disclaimer +# and license in png.h + +# Library name: +LIBNAME=libpng12 +PNGMAJ = 0 +PNGMIN = 1.2.46 +PNGVER = $(PNGMAJ).$(PNGMIN) + +# Shared library names: +LIBSO=$(LIBNAME).so +LIBSOMAJ=$(LIBNAME).so.$(PNGMAJ) +LIBSOVER=$(LIBNAME).so.$(PNGVER) +OLDSO=libpng.so +OLDSOMAJ=libpng.so.3 +OLDSOVER=libpng.so.3.$(PNGMIN) + +# Utilities: +AR_RC=ar rc +CC=cc +MKDIR_P=mkdir -p +LN_SF=ln -sf +RANLIB=echo +RM_F=/bin/rm -f + +# Where make install puts libpng.a, libpng12.so, and libpng12/png.h +# Prefix must be a full pathname. + +prefix=/usr/local +exec_prefix=$(prefix) + +# Where the zlib library and include files are located +#ZLIBLIB=/usr/local/lib32 +#ZLIBINC=/usr/local/include +#ZLIBLIB=/usr/local/lib +#ZLIBINC=/usr/local/include +ZLIBLIB=../zlib +ZLIBINC=../zlib + +# ABI can be blank to use default for your system, -32, -o32, -n32, or -64 +# See "man abi". zlib must be built with the same ABI. +ABI= + +WARNMORE=-fullwarn +# Note: -KPIC is the default anyhow +#CFLAGS= $(ABI) -I$(ZLIBINC) -O $(WARNMORE) -KPIC -DPNG_NO_MMX_CODE # -g -DPNG_DEBUG=5 +CFLAGS=$(ABI) -I$(ZLIBINC) -O $(WARNMORE) -DPNG_NO_MMX_CODE +LDFLAGS_A=$(ABI) -L. -L$(ZLIBLIB) -lpng12 -lz -lm +LDFLAGS=$(ABI) -L. -L$(ZLIBLIB) -lpng -lz -lm +LDSHARED=cc $(ABI) -shared -soname $(LIBSOMAJ) \ + -set_version sgi$(PNGMAJ).0 +LDLEGACY=cc $(ABI) -shared -soname $(OLDSOMAJ) \ + -set_version sgi$3.0 +# See "man dso" for info about shared objects + +INCPATH=$(prefix)/include +LIBPATH=$(exec_prefix)/lib +#LIBPATH=$(exec_prefix)/lib32 +MANPATH=$(prefix)/man +BINPATH=$(exec_prefix)/bin + +# override DESTDIR= on the make install command line to easily support +# installing into a temporary location. Example: +# +# make install DESTDIR=/tmp/build/libpng +# +# If you're going to install into a temporary location +# via DESTDIR, $(DESTDIR)$(prefix) must already exist before +# you execute make install. +DESTDIR= + +DB=$(DESTDIR)$(BINPATH) +DI=$(DESTDIR)$(INCPATH) +DL=$(DESTDIR)$(LIBPATH) +DM=$(DESTDIR)$(MANPATH) + +OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \ + pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \ + pngwtran.o pngmem.o pngerror.o pngpread.o + +all: libpng.a pngtest shared libpng.pc libpng-config + +libpng.a: $(OBJS) + $(AR_RC) $@ $(OBJS) + $(RANLIB) $@ + +shared: $(LIBSOVER) + +libpng.pc: + cat scripts/libpng.pc.in | sed -e s!@prefix@!$(prefix)! \ + -e s!@exec_prefix@!$(exec_prefix)! \ + -e s!@libdir@!$(LIBPATH)! \ + -e s!@includedir@!$(INCPATH)! \ + -e s!-lpng12!-lpng12\ -lz\ -lm! > libpng.pc + +libpng-config: + ( cat scripts/libpng-config-head.in; \ + echo prefix=\"$(prefix)\"; \ + echo I_opts=\"-I$(INCPATH)/$(LIBNAME)\"; \ + echo cppflags=\"-DPNG_NO_MMX_CODE\"; \ + echo ccopts=\"$(ABI)\"; \ + echo ldopts=\"$(ABI)\"; \ + echo L_opts=\"-L$(LIBPATH)\"; \ + echo libdir=\"$(LIBPATH)\"; \ + echo libs=\"-lpng12 -lz -lm\"; \ + cat scripts/libpng-config-body.in ) > libpng-config + chmod +x libpng-config + +$(LIBSO): $(LIBSOMAJ) + $(LN_SF) $(LIBSOMAJ) $(LIBSO) + +$(LIBSOMAJ): $(LIBSOVER) + $(LN_SF) $(LIBSOVER) $(LIBSOMAJ) + +$(LIBSOVER): $(OBJS) + $(LDSHARED) -o $@ $(OBJS) + $(RM_F) $(LIBSO) $(LIBSOMAJ) + +$(OLDSOVER): $(OBJS) + $(LDLEGACY) -o $@ $(OBJS) + +pngtest: pngtest.o libpng.a + $(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS) + +test: pngtest + echo + echo Testing local static library. + ./pngtest + +install-headers: png.h pngconf.h + -@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi + -@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi + cp png.h pngconf.h $(DI)/$(LIBNAME) + chmod 644 $(DI)/$(LIBNAME)/png.h $(DI)/$(LIBNAME)/pngconf.h + -@$(RM_F) $(DI)/png.h $(DI)/pngconf.h + -@$(RM_F) $(DI)/libpng + (cd $(DI); $(LN_SF) $(LIBNAME) libpng; $(LN_SF) $(LIBNAME)/* .) + +install-static: install-headers libpng.a + -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi + cp libpng.a $(DL)/$(LIBNAME).a + chmod 644 $(DL)/$(LIBNAME).a + -@$(RM_F) $(DL)/libpng.a + (cd $(DL); $(LN_SF) $(LIBNAME).a libpng.a) + +install-shared: install-headers $(LIBSOVER) libpng.pc \ + $(OLDSOVER) + -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi + -@$(RM_F) $(DL)/$(LIBSOVER)* $(DL)/$(LIBSO) + -@$(RM_F) $(DL)/$(LIBSOMAJ) + -@$(RM_F) $(DL)/$(OLDSO) + -@$(RM_F) $(DL)/$(OLDSOMAJ) + -@$(RM_F) $(DL)/$(OLDSOVER)* + cp $(LIBSOVER) $(DL) + cp $(OLDSOVER) $(DL) + chmod 755 $(DL)/$(LIBSOVER) + chmod 755 $(DL)/$(OLDSOVER) + (cd $(DL); \ + $(LN_SF) $(OLDSOVER) $(OLDSOMAJ); \ + $(LN_SF) $(OLDSOMAJ) $(OLDSO); \ + $(LN_SF) $(LIBSOVER) $(LIBSOMAJ); \ + $(LN_SF) $(LIBSOMAJ) $(LIBSO)) + -@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi + -@$(RM_F) $(DL)/pkgconfig/$(LIBNAME).pc + -@$(RM_F) $(DL)/pkgconfig/libpng.pc + cp libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc + chmod 644 $(DL)/pkgconfig/$(LIBNAME).pc + (cd $(DL)/pkgconfig; $(LN_SF) $(LIBNAME).pc libpng.pc) + +install-man: libpng.3 libpngpf.3 png.5 + -@if [ ! -d $(DM) ]; then $(MKDIR_P) $(DM); fi + -@if [ ! -d $(DM)/man3 ]; then $(MKDIR_P) $(DM)/man3; fi + -@$(RM_F) $(DM)/man3/libpng.3 + -@$(RM_F) $(DM)/man3/libpngpf.3 + cp libpng.3 $(DM)/man3 + cp libpngpf.3 $(DM)/man3 + -@if [ ! -d $(DM)/man5 ]; then $(MKDIR_P) $(DM)/man5; fi + -@$(RM_F) $(DM)/man5/png.5 + cp png.5 $(DM)/man5 + +install-config: libpng-config + -@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi + -@$(RM_F) $(DB)/libpng-config + -@$(RM_F) $(DB)/$(LIBNAME)-config + cp libpng-config $(DB)/$(LIBNAME)-config + chmod 755 $(DB)/$(LIBNAME)-config + (cd $(DB); $(LN_SF) $(LIBNAME)-config libpng-config) + +install: install-static install-shared install-man install-config + +# If you installed in $(DESTDIR), test-installed won't work until you +# move the library to its final location. Use test-dd to test it +# before then. + +test-dd: + echo + echo Testing installed dynamic shared library in $(DL). + $(CC) -I$(DI) -I$(ZLIBINC) \ + `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \ + -L$(DL) -L$(ZLIBLIB) \ + -rpath $(ZLIBLIB):$(DL) \ + -o pngtestd `$(BINPATH)/$(LIBNAME)-config --ldflags` + ./pngtestd pngtest.png + +test-installed: + echo + echo Testing installed dynamic shared library. + $(CC) -I$(ZLIBINC) \ + `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \ + -L$(ZLIBLIB) \ + -rpath $(ZLIBLIB):`$(BINPATH)/$(LIBNAME)-config --libdir` \ + -o pngtesti `$(BINPATH)/$(LIBNAME)-config --ldflags` + ./pngtesti pngtest.png + +clean: + $(RM_F) *.o libpng.a pngtest pngtesti pngout.png libpng.pc libpng-config \ + $(LIBSO) $(LIBSOMAJ)* \ + $(OLDSOVER) \ + so_locations + +DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO +writelock: + chmod a-w *.[ch35] $(DOCS) scripts/* + +# DO NOT DELETE THIS LINE -- make depend depends on it. + +png.o: png.h pngconf.h +pngerror.o: png.h pngconf.h +pngrio.o: png.h pngconf.h +pngwio.o: png.h pngconf.h +pngmem.o: png.h pngconf.h +pngset.o: png.h pngconf.h +pngget.o: png.h pngconf.h +pngread.o: png.h pngconf.h +pngrtran.o: png.h pngconf.h +pngrutil.o: png.h pngconf.h +pngtrans.o: png.h pngconf.h +pngwrite.o: png.h pngconf.h +pngwtran.o: png.h pngconf.h +pngwutil.o: png.h pngconf.h +pngpread.o: png.h pngconf.h + +pngtest.o: png.h pngconf.h diff --git a/libs/libpng-src/scripts/makefile.so9 b/libs/libpng-src/scripts/makefile.so9 new file mode 100644 index 000000000..f202fb4e3 --- /dev/null +++ b/libs/libpng-src/scripts/makefile.so9 @@ -0,0 +1,254 @@ +# makefile for libpng on Solaris 9 (beta) with Forte cc +# Updated by Chad Schrock for Solaris 9 +# Contributed by William L. Sebok, based on makefile.linux +# Copyright (C) 2002, 2006, 2008 Glenn Randers-Pehrson +# Copyright (C) 1998-2001 Greg Roelofs +# Copyright (C) 1996-1997 Andreas Dilger +# +# This code is released under the libpng license. +# For conditions of distribution and use, see the disclaimer +# and license in png.h + +# Library name: +PNGMAJ = 0 +PNGMIN = 1.2.46 +PNGVER = $(PNGMAJ).$(PNGMIN) +LIBNAME = libpng12 + +# Shared library names: +LIBSO=$(LIBNAME).so +LIBSOMAJ=$(LIBNAME).so.$(PNGMAJ) +LIBSOVER=$(LIBNAME).so.$(PNGVER) +OLDSO=libpng.so +OLDSOMAJ=libpng.so.3 +OLDSOVER=libpng.so.3.$(PNGMIN) + +# Utilities: +# gcc 2.95 doesn't work. +CC=cc +AR_RC=ar rc +MKDIR_P=mkdir -p +LN_SF=ln -f -s +RANLIB=echo +RM_F=/bin/rm -f + +# Where make install puts libpng.a, $(OLDSO)*, and png.h +prefix=/usr/local +exec_prefix=$(prefix) + +# Where the zlib library and include files are located +# Changing these to ../zlib poses a security risk. If you want +# to have zlib in an adjacent directory, specify the full path instead of "..". +#ZLIBLIB=../zlib +#ZLIBINC=../zlib +#ZLIBLIB=/usr/local/lib +#ZLIBINC=/usr/local/include +#Use the preinstalled zlib that comes with Solaris 9: +ZLIBLIB=/usr/lib +ZLIBINC=/usr/include + +#WARNMORE=-Wwrite-strings -Wpointer-arith -Wshadow \ + -Wmissing-declarations -Wtraditional -Wcast-align \ + -Wstrict-prototypes -Wmissing-prototypes #-Wconversion +#CFLAGS=-I$(ZLIBINC) -W -Wall -O3 $(WARNMORE) -g -DPNG_DEBUG=5 -DPNG_NO_MMX_CODE +CFLAGS=-I$(ZLIBINC) -O3 -DPNG_NO_MMX_CODE +LDFLAGS=-L. -R. -L$(ZLIBLIB) -R$(ZLIBLIB) -lpng12 -lz -lm + +INCPATH=$(prefix)/include +LIBPATH=$(exec_prefix)/lib +MANPATH=$(prefix)/man +BINPATH=$(exec_prefix)/bin + +# override DESTDIR= on the make install command line to easily support +# installing into a temporary location. Example: +# +# make install DESTDIR=/tmp/build/libpng +# +# If you're going to install into a temporary location +# via DESTDIR, $(DESTDIR)$(prefix) must already exist before +# you execute make install. +DESTDIR= + +DB=$(DESTDIR)$(BINPATH) +DI=$(DESTDIR)$(INCPATH) +DL=$(DESTDIR)$(LIBPATH) +DM=$(DESTDIR)$(MANPATH) + +OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \ + pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \ + pngwtran.o pngmem.o pngerror.o pngpread.o + +OBJSDLL = $(OBJS:.o=.pic.o) + +.SUFFIXES: .c .o .pic.o + +.c.pic.o: + $(CC) -c $(CFLAGS) -KPIC -o $@ $*.c + +all: libpng.a $(LIBSO) pngtest libpng.pc libpng-config + +libpng.a: $(OBJS) + $(AR_RC) $@ $(OBJS) + $(RANLIB) $@ + +libpng.pc: + cat scripts/libpng.pc.in | sed -e s!@prefix@!$(prefix)! \ + -e s!@exec_prefix@!$(exec_prefix)! \ + -e s!@libdir@!$(LIBPATH)! \ + -e s!@includedir@!$(INCPATH)! \ + -e s!-lpng12!-lpng12\ -lz\ -lm! > libpng.pc + +libpng-config: + ( cat scripts/libpng-config-head.in; \ + echo prefix=\"$(prefix)\"; \ + echo I_opts=\"-I$(INCPATH)/$(LIBNAME)\"; \ + echo L_opts=\"-L$(LIBPATH)\"; \ + echo R_opts=\"-R$(LIBPATH)\"; \ + echo libs=\"-lpng12 -lz -lm\"; \ + cat scripts/libpng-config-body.in ) > libpng-config + chmod +x libpng-config + +$(LIBSO): $(LIBSOMAJ) + $(LN_SF) $(LIBSOMAJ) $(LIBSO) + +$(LIBSOMAJ): $(LIBSOVER) + $(LN_SF) $(LIBSOVER) $(LIBSOMAJ) + +$(LIBSOVER): $(OBJSDLL) + @case "`type ld`" in *ucb*) \ + echo; \ + echo '## WARNING:'; \ + echo '## The commands "CC" and "LD" must NOT refer to /usr/ucb/cc'; \ + echo '## and /usr/ucb/ld. If they do, you need to adjust your PATH'; \ + echo '## environment variable to put /usr/ccs/bin ahead of /usr/ucb.'; \ + echo '## The environment variable LD_LIBRARY_PATH should not be set'; \ + echo '## at all. If it is, things are likely to break because of'; \ + echo '## the libucb dependency that is created.'; \ + echo; \ + ;; \ + esac + $(LD) -G -h $(LIBSOMAJ) \ + -o $(LIBSOVER) $(OBJSDLL) + +$(OLDSOVER): $(OBJS) + $(LD) -G -h $(OLDSOMAJ) \ + -o $(OLDSOVER) $(OBJSDLL) + +pngtest: pngtest.o $(LIBSO) + $(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS) + +test: pngtest + ./pngtest + +install-headers: png.h pngconf.h + -@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi + -@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi + cp png.h pngconf.h $(DI)/$(LIBNAME) + chmod 644 $(DI)/$(LIBNAME)/png.h $(DI)/$(LIBNAME)/pngconf.h + -@$(RM_F) $(DI)/png.h $(DI)/pngconf.h + -@$(RM_F) $(DI)/libpng + (cd $(DI); $(LN_SF) $(LIBNAME) libpng; $(LN_SF) $(LIBNAME)/* .) + +install-static: install-headers libpng.a + -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi + cp libpng.a $(DL)/$(LIBNAME).a + chmod 644 $(DL)/$(LIBNAME).a + -@$(RM_F) $(DL)/libpng.a + (cd $(DL); $(LN_SF) $(LIBNAME).a libpng.a) + +install-shared: install-headers $(LIBSOVER) libpng.pc \ + $(OLDSOVER) + -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi + -@$(RM_F) $(DL)/$(LIBSOVER)* $(DL)/$(LIBSO) + -@$(RM_F) $(DL)/$(LIBSOMAJ) + -@$(RM_F) $(DL)/$(OLDSO) + -@$(RM_F) $(DL)/$(OLDSOMAJ) + -@$(RM_F) $(DL)/$(OLDSOVER)* + cp $(LIBSOVER) $(DL) + cp $(OLDSOVER) $(DL) + chmod 755 $(DL)/$(LIBSOVER) + chmod 755 $(DL)/$(OLDSOVER) + (cd $(DL); \ + $(LN_SF) $(OLDSOVER) $(OLDSOMAJ); \ + $(LN_SF) $(OLDSOMAJ) $(OLDSO); \ + $(LN_SF) $(LIBSOVER) $(LIBSOMAJ); \ + $(LN_SF) $(LIBSOMAJ) $(LIBSO)) + -@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi + -@$(RM_F) $(DL)/pkgconfig/$(LIBNAME).pc + -@$(RM_F) $(DL)/pkgconfig/libpng.pc + cp libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc + chmod 644 $(DL)/pkgconfig/$(LIBNAME).pc + (cd $(DL)/pkgconfig; $(LN_SF) $(LIBNAME).pc libpng.pc) + +install-man: libpng.3 libpngpf.3 png.5 + -@if [ ! -d $(DM) ]; then $(MKDIR_P) $(DM); fi + -@if [ ! -d $(DM)/man3 ]; then $(MKDIR_P) $(DM)/man3; fi + -@$(RM_F) $(DM)/man3/libpng.3 + -@$(RM_F) $(DM)/man3/libpngpf.3 + cp libpng.3 $(DM)/man3 + cp libpngpf.3 $(DM)/man3 + -@if [ ! -d $(DM)/man5 ]; then $(MKDIR_P) $(DM)/man5; fi + -@$(RM_F) $(DM)/man5/png.5 + cp png.5 $(DM)/man5 + +install-config: libpng-config + -@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi + -@$(RM_F) $(DB)/libpng-config + -@$(RM_F) $(DB)/$(LIBNAME)-config + cp libpng-config $(DB)/$(LIBNAME)-config + chmod 755 $(DB)/$(LIBNAME)-config + (cd $(DB); $(LN_SF) $(LIBNAME)-config libpng-config) + +install: install-static install-shared install-man install-config + +# If you installed in $(DESTDIR), test-installed won't work until you +# move the library to its final location. Use test-dd to test it +# before then. + +test-dd: + echo + echo Testing installed dynamic shared library in $(DL). + $(CC) -I$(DI) -I$(ZLIBINC) \ + `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \ + -o pngtestd `$(BINPATH)/$(LIBNAME)-config --ldflags` \ + -L$(DL) -L$(ZLIBLIB) -R$(ZLIBLIB) -R$(DL) + ./pngtestd pngtest.png + +test-installed: + echo + echo Testing installed dynamic shared library. + $(CC) -I$(ZLIBINC) \ + `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \ + -o pngtesti `$(BINPATH)/$(LIBNAME)-config --ldflags` \ + -L$(ZLIBLIB) -R$(ZLIBLIB) + ./pngtesti pngtest.png + +clean: + $(RM_F) *.o libpng.a pngtest pngtesti pngout.png \ + libpng-config $(LIBSO) $(LIBSOMAJ)* \ + $(OLDSOVER) \ + libpng.pc + +DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO +writelock: + chmod a-w *.[ch35] $(DOCS) scripts/* + +# DO NOT DELETE THIS LINE -- make depend depends on it. + +png.o png.pic.o: png.h pngconf.h +pngerror.o pngerror.pic.o: png.h pngconf.h +pngrio.o pngrio.pic.o: png.h pngconf.h +pngwio.o pngwio.pic.o: png.h pngconf.h +pngmem.o pngmem.pic.o: png.h pngconf.h +pngset.o pngset.pic.o: png.h pngconf.h +pngget.o pngget.pic.o: png.h pngconf.h +pngread.o pngread.pic.o: png.h pngconf.h +pngrtran.o pngrtran.pic.o: png.h pngconf.h +pngrutil.o pngrutil.pic.o: png.h pngconf.h +pngtrans.o pngtrans.pic.o: png.h pngconf.h +pngwrite.o pngwrite.pic.o: png.h pngconf.h +pngwtran.o pngwtran.pic.o: png.h pngconf.h +pngwutil.o pngwutil.pic.o: png.h pngconf.h +pngpread.o pngpread.pic.o: png.h pngconf.h + +pngtest.o: png.h pngconf.h diff --git a/libs/libpng-src/scripts/makefile.solaris b/libs/libpng-src/scripts/makefile.solaris new file mode 100644 index 000000000..294b0f795 --- /dev/null +++ b/libs/libpng-src/scripts/makefile.solaris @@ -0,0 +1,251 @@ +# makefile for libpng on Solaris 2.x with gcc +# Copyright (C) 2004, 2006-2008 Glenn Randers-Pehrson +# Contributed by William L. Sebok, based on makefile.linux +# Copyright (C) 1998 Greg Roelofs +# Copyright (C) 1996, 1997 Andreas Dilger +# +# This code is released under the libpng license. +# For conditions of distribution and use, see the disclaimer +# and license in png.h + +# Library name: +LIBNAME = libpng12 +PNGMAJ = 0 +PNGMIN = 1.2.46 +PNGVER = $(PNGMAJ).$(PNGMIN) + +# Shared library names: +LIBSO=$(LIBNAME).so +LIBSOMAJ=$(LIBNAME).so.$(PNGMAJ) +LIBSOVER=$(LIBNAME).so.$(PNGVER) +OLDSO=libpng.so +OLDSOMAJ=libpng.so.3 +OLDSOVER=libpng.so.3.$(PNGMIN) + +# Utilities: +AR_RC=ar rc +CC=gcc +MKDIR_P=mkdir -p +LN_SF=ln -f -s +RANLIB=echo +RM_F=/bin/rm -f + +# Where make install puts libpng.a, libpng12.so*, and png.h +prefix=/usr/local +exec_prefix=$(prefix) + +# Where the zlib library and include files are located +# Changing these to ../zlib poses a security risk. If you want +# to have zlib in an adjacent directory, specify the full path instead of "..". +#ZLIBLIB=../zlib +#ZLIBINC=../zlib + +ZLIBLIB=/usr/local/lib +ZLIBINC=/usr/local/include + +WARNMORE=-Wwrite-strings -Wpointer-arith -Wshadow \ + -Wmissing-declarations -Wtraditional -Wcast-align \ + -Wstrict-prototypes -Wmissing-prototypes #-Wconversion +CFLAGS=-I$(ZLIBINC) -W -Wall -O -DPNG_NO_MMX_CODE; \ + # $(WARNMORE) -g -DPNG_DEBUG=5 +LDFLAGS=-L. -R. -L$(ZLIBLIB) -R$(ZLIBLIB) -lpng12 -lz -lm + +INCPATH=$(prefix)/include +LIBPATH=$(exec_prefix)/lib +MANPATH=$(prefix)/man +BINPATH=$(exec_prefix)/bin + +# override DESTDIR= on the make install command line to easily support +# installing into a temporary location. Example: +# +# make install DESTDIR=/tmp/build/libpng +# +# If you're going to install into a temporary location +# via DESTDIR, $(DESTDIR)$(prefix) must already exist before +# you execute make install. +DESTDIR= + +DB=$(DESTDIR)$(BINPATH) +DI=$(DESTDIR)$(INCPATH) +DL=$(DESTDIR)$(LIBPATH) +DM=$(DESTDIR)$(MANPATH) + +OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \ + pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \ + pngwtran.o pngmem.o pngerror.o pngpread.o + +OBJSDLL = $(OBJS:.o=.pic.o) + +.SUFFIXES: .c .o .pic.o + +.c.pic.o: + $(CC) -c $(CFLAGS) -fPIC -o $@ $*.c + +all: libpng.a $(LIBSO) pngtest libpng.pc libpng-config + +libpng.a: $(OBJS) + $(AR_RC) $@ $(OBJS) + $(RANLIB) $@ + +libpng.pc: + cat scripts/libpng.pc.in | sed -e s!@prefix@!$(prefix)! \ + -e s!@exec_prefix@!$(exec_prefix)! \ + -e s!@libdir@!$(LIBPATH)! \ + -e s!@includedir@!$(INCPATH)! \ + -e s!-lpng12!-lpng12\ -lz\ -lm! > libpng.pc + +libpng-config: + ( cat scripts/libpng-config-head.in; \ + echo prefix=\"$(prefix)\"; \ + echo I_opts=\"-I$(INCPATH)/$(LIBNAME)\"; \ + echo cppflags=\"-DPNG_NO_MMX_CODE\"; \ + echo L_opts=\"-L$(LIBPATH)\"; \ + echo R_opts=\"-R$(LIBPATH)\"; \ + echo libs=\"-lpng12 -lz -lm\"; \ + cat scripts/libpng-config-body.in ) > libpng-config + chmod +x libpng-config + +$(LIBSO): $(LIBSOMAJ) + $(LN_SF) $(LIBSOMAJ) $(LIBSO) + +$(LIBSOMAJ): $(LIBSOVER) + $(LN_SF) $(LIBSOVER) $(LIBSOMAJ) + +$(LIBSOVER): $(OBJSDLL) + @case "`type ld`" in *ucb*) \ + echo; \ + echo '## WARNING:'; \ + echo '## The commands "CC" and "LD" must NOT refer to /usr/ucb/cc'; \ + echo '## and /usr/ucb/ld. If they do, you need to adjust your PATH'; \ + echo '## environment variable to put /usr/ccs/bin ahead of /usr/ucb.'; \ + echo '## The environment variable LD_LIBRARY_PATH should not be set'; \ + echo '## at all. If it is, things are likely to break because of'; \ + echo '## the libucb dependency that is created.'; \ + echo; \ + ;; \ + esac + $(LD) -G -h $(LIBSOMAJ) \ + -o $(LIBSOVER) $(OBJSDLL) + +$(OLDSOVER): $(OBJS) + $(LD) -G -h $(OLDSOMAJ) \ + -o $(OLDSOVER) $(OBJSDLL) + +pngtest: pngtest.o $(LIBSO) + $(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS) + +test: pngtest + ./pngtest + +install-headers: png.h pngconf.h + -@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi + -@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi + cp png.h pngconf.h $(DI)/$(LIBNAME) + chmod 644 $(DI)/$(LIBNAME)/png.h $(DI)/$(LIBNAME)/pngconf.h + -@$(RM_F) $(DI)/png.h $(DI)/pngconf.h + -@$(RM_F) $(DI)/libpng + (cd $(DI); $(LN_SF) $(LIBNAME) libpng; $(LN_SF) $(LIBNAME)/* .) + +install-static: install-headers libpng.a + -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi + cp libpng.a $(DL)/$(LIBNAME).a + chmod 644 $(DL)/$(LIBNAME).a + -@$(RM_F) $(DL)/libpng.a + (cd $(DL); $(LN_SF) $(LIBNAME).a libpng.a) + +install-shared: install-headers $(LIBSOVER) libpng.pc \ + $(OLDSOVER) + -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi + -@$(RM_F) $(DL)/$(LIBSOVER)* $(DL)/$(LIBSO) + -@$(RM_F) $(DL)/$(LIBSOMAJ) + -@$(RM_F) $(DL)/$(OLDSO) + -@$(RM_F) $(DL)/$(OLDSOMAJ) + -@$(RM_F) $(DL)/$(OLDSOVER)* + cp $(LIBSOVER) $(DL) + cp $(OLDSOVER) $(DL) + chmod 755 $(DL)/$(LIBSOVER) + chmod 755 $(DL)/$(OLDSOVER) + (cd $(DL); \ + $(LN_SF) $(OLDSOVER) $(OLDSOMAJ); \ + $(LN_SF) $(OLDSOMAJ) $(OLDSO); \ + $(LN_SF) $(LIBSOVER) $(LIBSO); \ + $(LN_SF) $(LIBSOVER) $(LIBSOMAJ)) + -@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi + -@$(RM_F) $(DL)/pkgconfig/$(LIBNAME).pc + -@$(RM_F) $(DL)/pkgconfig/libpng.pc + cp libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc + chmod 644 $(DL)/pkgconfig/$(LIBNAME).pc + (cd $(DL)/pkgconfig; $(LN_SF) $(LIBNAME).pc libpng.pc) + +install-man: libpng.3 libpngpf.3 png.5 + -@if [ ! -d $(DM) ]; then $(MKDIR_P) $(DM); fi + -@if [ ! -d $(DM)/man3 ]; then $(MKDIR_P) $(DM)/man3; fi + -@$(RM_F) $(DM)/man3/libpng.3 + -@$(RM_F) $(DM)/man3/libpngpf.3 + cp libpng.3 $(DM)/man3 + cp libpngpf.3 $(DM)/man3 + -@if [ ! -d $(DM)/man5 ]; then $(MKDIR_P) $(DM)/man5; fi + -@$(RM_F) $(DM)/man5/png.5 + cp png.5 $(DM)/man5 + +install-config: libpng-config + -@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi + -@$(RM_F) $(DB)/libpng-config + -@$(RM_F) $(DB)/$(LIBNAME)-config + cp libpng-config $(DB)/$(LIBNAME)-config + chmod 755 $(DB)/$(LIBNAME)-config + (cd $(DB); $(LN_SF) $(LIBNAME)-config libpng-config) + +install: install-static install-shared install-man install-config + +# If you installed in $(DESTDIR), test-installed won't work until you +# move the library to its final location. Use test-dd to test it +# before then. + +test-dd: + echo + echo Testing installed dynamic shared library in $(DL). + $(CC) -I$(DI) -I$(ZLIBINC) \ + `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \ + -o pngtestd `$(BINPATH)/$(LIBNAME)-config --ldflags` \ + -L$(DL) -L$(ZLIBLIB) -R$(ZLIBLIB) -R$(DL) + ./pngtestd pngtest.png + +test-installed: + echo + echo Testing installed dynamic shared library. + $(CC) -I$(ZLIBINC) \ + `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \ + -o pngtesti `$(BINPATH)/$(LIBNAME)-config --ldflags` \ + -L$(ZLIBLIB) -R$(ZLIBLIB) + ./pngtesti pngtest.png + +clean: + $(RM_F) *.o libpng.a pngtest pngtesti pngout.png \ + libpng-config $(LIBSO) $(LIBSOMAJ)* \ + $(OLDSOVER) \ + libpng.pc + +DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO +writelock: + chmod a-w *.[ch35] $(DOCS) scripts/* + +# DO NOT DELETE THIS LINE -- make depend depends on it. + +png.o png.pic.o: png.h pngconf.h +pngerror.o pngerror.pic.o: png.h pngconf.h +pngrio.o pngrio.pic.o: png.h pngconf.h +pngwio.o pngwio.pic.o: png.h pngconf.h +pngmem.o pngmem.pic.o: png.h pngconf.h +pngset.o pngset.pic.o: png.h pngconf.h +pngget.o pngget.pic.o: png.h pngconf.h +pngread.o pngread.pic.o: png.h pngconf.h +pngrtran.o pngrtran.pic.o: png.h pngconf.h +pngrutil.o pngrutil.pic.o: png.h pngconf.h +pngtrans.o pngtrans.pic.o: png.h pngconf.h +pngwrite.o pngwrite.pic.o: png.h pngconf.h +pngwtran.o pngwtran.pic.o: png.h pngconf.h +pngwutil.o pngwutil.pic.o: png.h pngconf.h +pngpread.o pngpread.pic.o: png.h pngconf.h + +pngtest.o: png.h pngconf.h diff --git a/libs/libpng-src/scripts/makefile.solaris-x86 b/libs/libpng-src/scripts/makefile.solaris-x86 new file mode 100644 index 000000000..575d789d1 --- /dev/null +++ b/libs/libpng-src/scripts/makefile.solaris-x86 @@ -0,0 +1,251 @@ +# makefile for libpng on Solaris 2.x with gcc +# Copyright (C) 2004, 2006-2008 Glenn Randers-Pehrson +# Contributed by William L. Sebok, based on makefile.linux +# Copyright (C) 1998 Greg Roelofs +# Copyright (C) 1996, 1997 Andreas Dilger + +# This code is released under the libpng license. +# For conditions of distribution and use, see the disclaimer +# and license in png.h + +# Library name: +LIBNAME = libpng12 +PNGMAJ = 0 +PNGMIN = 1.2.46 +PNGVER = $(PNGMAJ).$(PNGMIN) + +# Shared library names: +LIBSO=$(LIBNAME).so +LIBSOMAJ=$(LIBNAME).so.$(PNGMAJ) +LIBSOVER=$(LIBNAME).so.$(PNGVER) +OLDSO=libpng.so +OLDSOMAJ=libpng.so.3 +OLDSOVER=libpng.so.3.$(PNGMIN) + +# Utilities: +AR_RC=ar rc +CC=gcc +MKDIR_P=mkdir -p +LN_SF=ln -f -s +RANLIB=echo +RM_F=/bin/rm -f + +# Where make install puts libpng.a, libpng12.so*, and png.h +prefix=/usr/local +exec_prefix=$(prefix) + +# Where the zlib library and include files are located +# Changing these to ../zlib poses a security risk. If you want +# to have zlib in an adjacent directory, specify the full path instead of "..". +#ZLIBLIB=../zlib +#ZLIBINC=../zlib + +ZLIBLIB=/usr/local/lib +ZLIBINC=/usr/local/include + +WARNMORE=-Wwrite-strings -Wpointer-arith -Wshadow \ + -Wmissing-declarations -Wtraditional -Wcast-align \ + -Wstrict-prototypes -Wmissing-prototypes #-Wconversion +CFLAGS=-I$(ZLIBINC) -W -Wall -O \ + # $(WARNMORE) -g -DPNG_DEBUG=5 +LDFLAGS=-L. -R. -L$(ZLIBLIB) -R$(ZLIBLIB) -lpng12 -lz -lm + +INCPATH=$(prefix)/include +LIBPATH=$(exec_prefix)/lib +MANPATH=$(prefix)/man +BINPATH=$(exec_prefix)/bin + +# override DESTDIR= on the make install command line to easily support +# installing into a temporary location. Example: +# +# make install DESTDIR=/tmp/build/libpng +# +# If you're going to install into a temporary location +# via DESTDIR, $(DESTDIR)$(prefix) must already exist before +# you execute make install. +DESTDIR= + +DB=$(DESTDIR)$(BINPATH) +DI=$(DESTDIR)$(INCPATH) +DL=$(DESTDIR)$(LIBPATH) +DM=$(DESTDIR)$(MANPATH) + +OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \ + pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \ + pngwtran.o pngmem.o pngerror.o pngpread.o + +OBJSDLL = $(OBJS:.o=.pic.o) + +.SUFFIXES: .c .o .pic.o + +.c.pic.o: + $(CC) -c $(CFLAGS) -fPIC -o $@ $*.c + +all: libpng.a $(LIBSO) pngtest libpng.pc libpng-config + +libpng.a: $(OBJS) + $(AR_RC) $@ $(OBJS) + $(RANLIB) $@ + +libpng.pc: + cat scripts/libpng.pc.in | sed -e s!@prefix@!$(prefix)! \ + -e s!@exec_prefix@!$(exec_prefix)! \ + -e s!@libdir@!$(LIBPATH)! \ + -e s!@includedir@!$(INCPATH)! \ + -e s!-lpng12!-lpng12\ -lz\ -lm! > libpng.pc + +libpng-config: + ( cat scripts/libpng-config-head.in; \ + echo prefix=\"$(prefix)\"; \ + echo I_opts=\"-I$(INCPATH)/$(LIBNAME)\"; \ + echo cppflags=\""; \ + echo L_opts=\"-L$(LIBPATH)\"; \ + echo R_opts=\"-R$(LIBPATH)\"; \ + echo libs=\"-lpng12 -lz -lm\"; \ + cat scripts/libpng-config-body.in ) > libpng-config + chmod +x libpng-config + +$(LIBSO): $(LIBSOMAJ) + $(LN_SF) $(LIBSOMAJ) $(LIBSO) + +$(LIBSOMAJ): $(LIBSOVER) + $(LN_SF) $(LIBSOVER) $(LIBSOMAJ) + +$(LIBSOVER): $(OBJSDLL) + @case "`type ld`" in *ucb*) \ + echo; \ + echo '## WARNING:'; \ + echo '## The commands "CC" and "LD" must NOT refer to /usr/ucb/cc'; \ + echo '## and /usr/ucb/ld. If they do, you need to adjust your PATH'; \ + echo '## environment variable to put /usr/ccs/bin ahead of /usr/ucb.'; \ + echo '## The environment variable LD_LIBRARY_PATH should not be set'; \ + echo '## at all. If it is, things are likely to break because of'; \ + echo '## the libucb dependency that is created.'; \ + echo; \ + ;; \ + esac + $(LD) -G -h $(LIBSOMAJ) \ + -o $(LIBSOVER) $(OBJSDLL) + +$(OLDSOVER): $(OBJS) + $(LD) -G -h $(OLDSOMAJ) \ + -o $(OLDSOVER) $(OBJSDLL) + +pngtest: pngtest.o $(LIBSO) + $(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS) + +test: pngtest + ./pngtest + +install-headers: png.h pngconf.h + -@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi + -@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi + cp png.h pngconf.h $(DI)/$(LIBNAME) + chmod 644 $(DI)/$(LIBNAME)/png.h $(DI)/$(LIBNAME)/pngconf.h + -@$(RM_F) $(DI)/png.h $(DI)/pngconf.h + -@$(RM_F) $(DI)/libpng + (cd $(DI); $(LN_SF) $(LIBNAME) libpng; $(LN_SF) $(LIBNAME)/* .) + +install-static: install-headers libpng.a + -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi + cp libpng.a $(DL)/$(LIBNAME).a + chmod 644 $(DL)/$(LIBNAME).a + -@$(RM_F) $(DL)/libpng.a + (cd $(DL); $(LN_SF) $(LIBNAME).a libpng.a) + +install-shared: install-headers $(LIBSOVER) libpng.pc \ + $(OLDSOVER) + -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi + -@$(RM_F) $(DL)/$(LIBSOVER)* $(DL)/$(LIBSO) + -@$(RM_F) $(DL)/$(LIBSOMAJ) + -@$(RM_F) $(DL)/$(OLDSO) + -@$(RM_F) $(DL)/$(OLDSOMAJ) + -@$(RM_F) $(DL)/$(OLDSOVER)* + cp $(LIBSOVER) $(DL) + cp $(OLDSOVER) $(DL) + chmod 755 $(DL)/$(LIBSOVER) + chmod 755 $(DL)/$(OLDSOVER) + (cd $(DL); \ + $(LN_SF) $(OLDSOVER) $(OLDSOMAJ); \ + $(LN_SF) $(OLDSOMAJ) $(OLDSO); \ + $(LN_SF) $(LIBSOVER) $(LIBSO); \ + $(LN_SF) $(LIBSOVER) $(LIBSOMAJ)) + -@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi + -@$(RM_F) $(DL)/pkgconfig/$(LIBNAME).pc + -@$(RM_F) $(DL)/pkgconfig/libpng.pc + cp libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc + chmod 644 $(DL)/pkgconfig/$(LIBNAME).pc + (cd $(DL)/pkgconfig; $(LN_SF) $(LIBNAME).pc libpng.pc) + +install-man: libpng.3 libpngpf.3 png.5 + -@if [ ! -d $(DM) ]; then $(MKDIR_P) $(DM); fi + -@if [ ! -d $(DM)/man3 ]; then $(MKDIR_P) $(DM)/man3; fi + -@$(RM_F) $(DM)/man3/libpng.3 + -@$(RM_F) $(DM)/man3/libpngpf.3 + cp libpng.3 $(DM)/man3 + cp libpngpf.3 $(DM)/man3 + -@if [ ! -d $(DM)/man5 ]; then $(MKDIR_P) $(DM)/man5; fi + -@$(RM_F) $(DM)/man5/png.5 + cp png.5 $(DM)/man5 + +install-config: libpng-config + -@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi + -@$(RM_F) $(DB)/libpng-config + -@$(RM_F) $(DB)/$(LIBNAME)-config + cp libpng-config $(DB)/$(LIBNAME)-config + chmod 755 $(DB)/$(LIBNAME)-config + (cd $(DB); $(LN_SF) $(LIBNAME)-config libpng-config) + +install: install-static install-shared install-man install-config + +# If you installed in $(DESTDIR), test-installed won't work until you +# move the library to its final location. Use test-dd to test it +# before then. + +test-dd: + echo + echo Testing installed dynamic shared library in $(DL). + $(CC) -I$(DI) -I$(ZLIBINC) \ + `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \ + -o pngtestd `$(BINPATH)/$(LIBNAME)-config --ldflags` \ + -L$(DL) -L$(ZLIBLIB) -R$(ZLIBLIB) -R$(DL) + ./pngtestd pngtest.png + +test-installed: + echo + echo Testing installed dynamic shared library. + $(CC) -I$(ZLIBINC) \ + `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \ + -o pngtesti `$(BINPATH)/$(LIBNAME)-config --ldflags` \ + -L$(ZLIBLIB) -R$(ZLIBLIB) + ./pngtesti pngtest.png + +clean: + $(RM_F) *.o libpng.a pngtest pngtesti pngout.png \ + libpng-config $(LIBSO) $(LIBSOMAJ)* \ + $(OLDSOVER) \ + libpng.pc + +DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO +writelock: + chmod a-w *.[ch35] $(DOCS) scripts/* + +# DO NOT DELETE THIS LINE -- make depend depends on it. + +png.o png.pic.o: png.h pngconf.h +pngerror.o pngerror.pic.o: png.h pngconf.h +pngrio.o pngrio.pic.o: png.h pngconf.h +pngwio.o pngwio.pic.o: png.h pngconf.h +pngmem.o pngmem.pic.o: png.h pngconf.h +pngset.o pngset.pic.o: png.h pngconf.h +pngget.o pngget.pic.o: png.h pngconf.h +pngread.o pngread.pic.o: png.h pngconf.h +pngrtran.o pngrtran.pic.o: png.h pngconf.h +pngrutil.o pngrutil.pic.o: png.h pngconf.h +pngtrans.o pngtrans.pic.o: png.h pngconf.h +pngwrite.o pngwrite.pic.o: png.h pngconf.h +pngwtran.o pngwtran.pic.o: png.h pngconf.h +pngwutil.o pngwutil.pic.o: png.h pngconf.h +pngpread.o pngpread.pic.o: png.h pngconf.h + +pngtest.o: png.h pngconf.h diff --git a/libs/libpng-src/scripts/makefile.std b/libs/libpng-src/scripts/makefile.std new file mode 100644 index 000000000..262d153c3 --- /dev/null +++ b/libs/libpng-src/scripts/makefile.std @@ -0,0 +1,95 @@ +# makefile for libpng +# Copyright (C) 2002, 2006 Glenn Randers-Pehrson +# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc. +# +# This code is released under the libpng license. +# For conditions of distribution and use, see the disclaimer +# and license in png.h + +# where make install puts libpng.a and png.h +prefix=/usr/local +INCPATH=$(prefix)/include +LIBPATH=$(prefix)/lib + +# override DESTDIR= on the make install command line to easily support +# installing into a temporary location. Example: +# +# make install DESTDIR=/tmp/build/libpng +# +# If you're going to install into a temporary location +# via DESTDIR, $(DESTDIR)$(prefix) must already exist before +# you execute make install. +DESTDIR= + +# Where the zlib library and include files are located +#ZLIBLIB=/usr/local/lib +#ZLIBINC=/usr/local/include +ZLIBLIB=../zlib +ZLIBINC=../zlib + +CC=cc +AR_RC=ar rc +MKDIR_P=mkdir +LN_SF=ln -sf +RANLIB=ranlib +RM_F=rm -f + +CFLAGS=-I$(ZLIBINC) -O # -g -DPNG_DEBUG=5 +LDFLAGS=-L. -L$(ZLIBLIB) -lpng -lz -lm + +OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \ + pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \ + pngwtran.o pngmem.o pngerror.o pngpread.o + +all: libpng.a pngtest + +libpng.a: $(OBJS) + $(AR_RC) $@ $(OBJS) + $(RANLIB) $@ + +pngtest: pngtest.o libpng.a + $(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS) + +test: pngtest + ./pngtest + +install: libpng.a + -@$(MKDIR_P) $(DESTDIR)$(INCPATH) + -@$(MKDIR_P) $(DESTDIR)$(INCPATH)/libpng + -@$(MKDIR_P) $(DESTDIR)$(LIBPATH) + -@$(RM_F) $(DESTDIR)$(INCPATH)/png.h + -@$(RM_F) $(DESTDIR)$(INCPATH)/pngconf.h + cp png.h $(DESTDIR)$(INCPATH)/libpng + cp pngconf.h $(DESTDIR)$(INCPATH)/libpng + chmod 644 $(DESTDIR)$(INCPATH)/libpng/png.h + chmod 644 $(DESTDIR)$(INCPATH)/libpng/pngconf.h + (cd $(DESTDIR)$(INCPATH); ln -f -s libpng/* .) + cp libpng.a $(DESTDIR)$(LIBPATH) + chmod 644 $(DESTDIR)$(LIBPATH)/libpng.a + +clean: + $(RM_F) *.o libpng.a pngtest pngout.png + +DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO +writelock: + chmod a-w *.[ch35] $(DOCS) scripts/* + +# DO NOT DELETE THIS LINE -- make depend depends on it. + +png.o: png.h pngconf.h +pngerror.o: png.h pngconf.h +pngrio.o: png.h pngconf.h +pngwio.o: png.h pngconf.h +pngmem.o: png.h pngconf.h +pngset.o: png.h pngconf.h +pngget.o: png.h pngconf.h +pngread.o: png.h pngconf.h +pngrtran.o: png.h pngconf.h +pngrutil.o: png.h pngconf.h +pngtrans.o: png.h pngconf.h +pngwrite.o: png.h pngconf.h +pngwtran.o: png.h pngconf.h +pngwutil.o: png.h pngconf.h +pngpread.o: png.h pngconf.h + +pngtest.o: png.h pngconf.h diff --git a/libs/libpng-src/scripts/makefile.sunos b/libs/libpng-src/scripts/makefile.sunos new file mode 100644 index 000000000..0cef4fcb9 --- /dev/null +++ b/libs/libpng-src/scripts/makefile.sunos @@ -0,0 +1,100 @@ +# makefile for libpng +# Copyright (C) 2002, 2006 Glenn Randers-Pehrson +# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc. +# +# This code is released under the libpng license. +# For conditions of distribution and use, see the disclaimer +# and license in png.h + +# where make install puts libpng.a and png.h +prefix=/usr/local +INCPATH=$(prefix)/include +LIBPATH=$(prefix)/lib + +# override DESTDIR= on the make install command line to easily support +# installing into a temporary location. Example: +# +# make install DESTDIR=/tmp/build/libpng +# +# If you're going to install into a temporary location +# via DESTDIR, $(DESTDIR)$(prefix) must already exist before +# you execute make install. +DESTDIR= + +# Where the zlib library and include files are located +#ZLIBLIB=/usr/local/lib +#ZLIBINC=/usr/local/include +ZLIBLIB=../zlib +ZLIBINC=../zlib + + +WARNMORE=-Wwrite-strings -Wpointer-arith -Wshadow -Wconversion \ + -Wmissing-declarations -Wtraditional -Wcast-align \ + -Wstrict-prototypes -Wmissing-prototypes + +CC=gcc +AR_RC=ar rc +MKDIR_P=mkdir -p +LN_SF=ln -f -s +RANLIB=ranlib +RM_F=/bin/rm -f + +CFLAGS=-I$(ZLIBINC) -O # $(WARNMORE) -DPNG_DEBUG=5 +LDFLAGS=-L. -L$(ZLIBLIB) -lpng -lz -lm + +OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \ + pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \ + pngwtran.o pngmem.o pngerror.o pngpread.o + +all: libpng.a pngtest + +libpng.a: $(OBJS) + $(AR_RC) $@ $(OBJS) + $(RANLIB) $@ + +pngtest: pngtest.o libpng.a + $(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS) + +test: pngtest + ./pngtest + +install: libpng.a + -@$(MKDIR_P) $(DESTDIR)$(INCPATH) + -@$(MKDIR_P) $(DESTDIR)$(INCPATH)/libpng + -@$(MKDIR_P) $(DESTDIR)$(LIBPATH) + -@$(RM_F) $(DESTDIR)$(INCPATH)/png.h + -@$(RM_F) $(DESTDIR)$(INCPATH)/pngconf.h + cp png.h $(DESTDIR)$(INCPATH)/libpng + cp pngconf.h $(DESTDIR)$(INCPATH)/libpng + chmod 644 $(DESTDIR)$(INCPATH)/libpng/png.h + chmod 644 $(DESTDIR)$(INCPATH)/libpng/pngconf.h + (cd $(DESTDIR)$(INCPATH); $(LN_SF) libpng/* .) + cp libpng.a $(DESTDIR)$(LIBPATH) + chmod 644 $(DESTDIR)$(LIBPATH)/libpng.a + +clean: + $(RM_F) *.o libpng.a pngtest pngout.png + +DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO +writelock: + chmod a-w *.[ch35] $(DOCS) scripts/* + +# DO NOT DELETE THIS LINE -- make depend depends on it. + +png.o: png.h pngconf.h +pngerror.o: png.h pngconf.h +pngrio.o: png.h pngconf.h +pngwio.o: png.h pngconf.h +pngmem.o: png.h pngconf.h +pngset.o: png.h pngconf.h +pngget.o: png.h pngconf.h +pngread.o: png.h pngconf.h +pngrtran.o: png.h pngconf.h +pngrutil.o: png.h pngconf.h +pngtrans.o: png.h pngconf.h +pngwrite.o: png.h pngconf.h +pngwtran.o: png.h pngconf.h +pngwutil.o: png.h pngconf.h +pngpread.o: png.h pngconf.h + +pngtest.o: png.h pngconf.h diff --git a/libs/libpng-src/scripts/makefile.tc3 b/libs/libpng-src/scripts/makefile.tc3 new file mode 100644 index 000000000..21435a68e --- /dev/null +++ b/libs/libpng-src/scripts/makefile.tc3 @@ -0,0 +1,89 @@ +# Makefile for libpng +# TurboC/C++ (Note: All modules are compiled in C mode) + +# To use, do "make -fmakefile.tc3" + +# ----- Turbo C 3.00 (can be modified to work with earlier versions) ----- + +MODEL=l +CFLAGS=-O2 -Z -m$(MODEL) -I..\zlib +#CFLAGS=-D_NO_PROTO -O2 -Z -m$(MODEL) -I..\zlib # Turbo C older than 3.00 +CC=tcc +LD=tcc +LIB=tlib +LDFLAGS=-m$(MODEL) -L..\zlib +O=.obj +E=.exe + +# variables +OBJS1 = png$(O) pngset$(O) pngget$(O) pngrutil$(O) pngtrans$(O) pngwutil$(O) +OBJS2 = pngmem$(O) pngpread$(O) pngread$(O) pngerror$(O) pngwrite$(O) +OBJS3 = pngrtran$(O) pngwtran$(O) pngrio$(O) pngwio$(O) +OBJSL1 = +png$(O) +pngset$(O) +pngget$(O) +pngrutil$(O) +pngtrans$(O) +OBJSL2 = +pngwutil$(O) +pngmem$(O) +pngpread$(O) +pngread$(O) +pngerror$(O) +OBJSL3 = +pngwrite$(O) +pngrtran$(O) +pngwtran$(O) +pngrio$(O) +pngwio$(O) + +all: libpng$(MODEL).lib pngtest$(E) + +pngtest: pngtest$(E) + +test: pngtest$(E) + pngtest$(E) + +png$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c + +pngset$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c + +pngget$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c + +pngread$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c + +pngpread$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c + +pngrtran$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c + +pngrutil$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c + +pngerror$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c + +pngmem$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c + +pngrio$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c + +pngwio$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c + +pngtest$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c + +pngtrans$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c + +pngwrite$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c + +pngwtran$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c + +pngwutil$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c + +libpng$(MODEL).lib: $(OBJS1) $(OBJS2) $(OBJS3) + $(LIB) libpng$(MODEL) +$(OBJSL1) + $(LIB) libpng$(MODEL) +$(OBJSL2) + $(LIB) libpng$(MODEL) +$(OBJSL3) + +pngtest$(E): pngtest$(O) libpng$(MODEL).lib + $(LD) $(LDFLAGS) pngtest.obj libpng$(MODEL).lib zlib_$(MODEL).lib + +# End of makefile for libpng diff --git a/libs/libpng-src/scripts/makefile.vcawin32 b/libs/libpng-src/scripts/makefile.vcawin32 new file mode 100644 index 000000000..1b58300f5 --- /dev/null +++ b/libs/libpng-src/scripts/makefile.vcawin32 @@ -0,0 +1,104 @@ +# makefile for libpng +# Copyright (C) 2006,2009 Glenn Randers-Pehrson +# Copyright (C) 1998 Tim Wegner +# +# This code is released under the libpng license. +# For conditions of distribution and use, see the disclaimer +# and license in png.h +# +# Assumes that zlib.lib, zconf.h, and zlib.h have been copied to ..\zlib +# To use, do "nmake /f scripts\makefile.vcawin32" + +# -------- Microsoft Visual C++ 2.0 and later, no assembler code -------- +# If you don't want to use assembler (MMX) code, use makefile.vcwin32 instead. + +# Compiler, linker, librarian, and other tools +CC = cl +LD = link +AR = lib +CFLAGS = -nologo -DPNG_USE_PNGVCRD -MD -O2 -W3 -I..\zlib +LDFLAGS = -nologo +ARFLAGS = -nologo +RM = del + +# File extensions +O=.obj + +#uncomment next to put error messages in a file +#ERRFILE= >> pngerrs.log + +# Variables +OBJS1 = png$(O) pngerror$(O) pngget$(O) pngmem$(O) pngpread$(O) +OBJS2 = pngread$(O) pngrio$(O) pngrtran$(O) pngrutil$(O) pngset$(O) +OBJS3 = pngtrans$(O) pngwio$(O) pngwrite$(O) pngwtran$(O) pngwutil$(O) +OBJS = $(OBJS1) $(OBJS2) $(OBJS3) + +# Targets +all: libpng.lib + +png$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c $(ERRFILE) + +pngset$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c $(ERRFILE) + +pngget$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c $(ERRFILE) + +pngread$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c $(ERRFILE) + +pngpread$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c $(ERRFILE) + +pngrtran$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c $(ERRFILE) + +pngrutil$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c $(ERRFILE) + +pngerror$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c $(ERRFILE) + +pngmem$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c $(ERRFILE) + +pngrio$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c $(ERRFILE) + +pngwio$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c $(ERRFILE) + +pngtrans$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c $(ERRFILE) + +pngwrite$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c $(ERRFILE) + +pngwtran$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c $(ERRFILE) + +pngwutil$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c $(ERRFILE) + +libpng.lib: $(OBJS) + -$(RM) $@ + $(AR) $(ARFLAGS) -out:$@ $(OBJS) $(ERRFILE) + +pngtest$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c $(ERRFILE) + +pngtest.exe: pngtest$(O) libpng.lib + $(LD) $(LDFLAGS) -out:$@ pngtest$(O) libpng.lib ..\zlib\zlib.lib $(ERRFILE) + +test: pngtest.exe + pngtest + +clean: + -$(RM) *$(O) + -$(RM) libpng.lib + -$(RM) pngtest.exe + -$(RM) pngout.png + +# End of makefile for libpng + diff --git a/libs/libpng-src/scripts/makefile.vcwin32 b/libs/libpng-src/scripts/makefile.vcwin32 new file mode 100644 index 000000000..3cdfb3904 --- /dev/null +++ b/libs/libpng-src/scripts/makefile.vcwin32 @@ -0,0 +1,104 @@ +# makefile for libpng +# Copyright (C) 1998 Tim Wegner +# Copyright (C) 2006,2009 Glenn Randers-Pehrson +# +# This code is released under the libpng license. +# For conditions of distribution and use, see the disclaimer +# and license in png.h +# +# Assumes that zlib.lib, zconf.h, and zlib.h have been copied to ..\zlib +# To use, do "nmake /f scripts\makefile.vcwin32" + +# -------- Microsoft Visual C++ 2.0 and later, no assembler code -------- +# If you want to use assembler (MMX) code, use makefile.vcawin32 instead. + +# Compiler, linker, librarian, and other tools +CC = cl +LD = link +AR = lib +CFLAGS = -nologo -DPNG_NO_MMX_CODE -MD -O2 -W3 -I..\zlib +LDFLAGS = -nologo +ARFLAGS = -nologo +RM = del + +# File extensions +O=.obj + +#uncomment next to put error messages in a file +#ERRFILE= >> pngerrs.log + +# Variables +OBJS1 = png$(O) pngerror$(O) pngget$(O) pngmem$(O) pngpread$(O) +OBJS2 = pngread$(O) pngrio$(O) pngrtran$(O) pngrutil$(O) pngset$(O) +OBJS3 = pngtrans$(O) pngwio$(O) pngwrite$(O) pngwtran$(O) pngwutil$(O) +OBJS = $(OBJS1) $(OBJS2) $(OBJS3) + +# Targets +all: libpng.lib + +png$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c $(ERRFILE) + +pngset$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c $(ERRFILE) + +pngget$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c $(ERRFILE) + +pngread$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c $(ERRFILE) + +pngpread$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c $(ERRFILE) + +pngrtran$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c $(ERRFILE) + +pngrutil$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c $(ERRFILE) + +pngerror$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c $(ERRFILE) + +pngmem$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c $(ERRFILE) + +pngrio$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c $(ERRFILE) + +pngwio$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c $(ERRFILE) + +pngtrans$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c $(ERRFILE) + +pngwrite$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c $(ERRFILE) + +pngwtran$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c $(ERRFILE) + +pngwutil$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c $(ERRFILE) + +libpng.lib: $(OBJS) + -$(RM) $@ + $(AR) $(ARFLAGS) -out:$@ $(OBJS) $(ERRFILE) + +pngtest$(O): png.h pngconf.h + $(CC) -c $(CFLAGS) $*.c $(ERRFILE) + +pngtest.exe: pngtest$(O) libpng.lib + $(LD) $(LDFLAGS) -out:$@ pngtest$(O) libpng.lib ..\zlib\zlib.lib $(ERRFILE) + +test: pngtest.exe + pngtest + +clean: + -$(RM) *$(O) + -$(RM) libpng.lib + -$(RM) pngtest.exe + -$(RM) pngout.png + +# End of makefile for libpng + diff --git a/libs/libpng-src/scripts/makefile.watcom b/libs/libpng-src/scripts/makefile.watcom new file mode 100644 index 000000000..4a8c7d7d2 --- /dev/null +++ b/libs/libpng-src/scripts/makefile.watcom @@ -0,0 +1,112 @@ +# Makefile for libpng +# Watcom C/C++ 10.0 and later, 32-bit protected mode, flat memory model + +# Copyright (C) 2000, Pawel Mrochen, based on makefile.msc which is +# copyright 1995 Guy Eric Schalnat, Group 42, Inc. +# +# This code is released under the libpng license. +# For conditions of distribution and use, see the disclaimer +# and license in png.h + +# To use, do "wmake /f scripts\makefile.watcom" + + +# ---------------------- Watcom C/C++ 10.0 and later ----------------------- + +# Where the zlib library and include files are located +ZLIBLIB=..\zlib +ZLIBINC=..\zlib + +# Target OS +OS=DOS +#OS=NT + +# Target CPU +CPU=6 # Pentium Pro +#CPU=5 # Pentium + +# Calling convention +CALLING=r # registers +#CALLING=s # stack + +# Uncomment next to put error messages in a file +#ERRFILE=>>pngerrs + +# -------------------------------------------------------------------------- + + +CC=wcc386 +CFLAGS=-$(CPU)$(CALLING) -fp$(CPU) -fpi87 -oneatx -mf -bt=$(OS) -i=$(ZLIBINC) -zq +LD=wcl386 +LDFLAGS=-zq + +O=.obj + +OBJS1=png$(O) pngset$(O) pngget$(O) pngrutil$(O) pngtrans$(O) pngwutil$(O) +OBJS2=pngmem$(O) pngpread$(O) pngread$(O) pngerror$(O) pngwrite$(O) +OBJS3=pngrtran$(O) pngwtran$(O) pngrio$(O) pngwio$(O) + + +all: test + +png$(O): png.h pngconf.h + $(CC) $(CFLAGS) $*.c $(ERRFILE) + +pngset$(O): png.h pngconf.h + $(CC) $(CFLAGS) $*.c $(ERRFILE) + +pngget$(O): png.h pngconf.h + $(CC) $(CFLAGS) $*.c $(ERRFILE) + +pngread$(O): png.h pngconf.h + $(CC) $(CFLAGS) $*.c $(ERRFILE) + +pngpread$(O): png.h pngconf.h + $(CC) $(CFLAGS) $*.c $(ERRFILE) + +pngrtran$(O): png.h pngconf.h + $(CC) $(CFLAGS) $*.c $(ERRFILE) + +pngrutil$(O): png.h pngconf.h + $(CC) $(CFLAGS) $*.c $(ERRFILE) + +pngerror$(O): png.h pngconf.h + $(CC) $(CFLAGS) $*.c $(ERRFILE) + +pngmem$(O): png.h pngconf.h + $(CC) $(CFLAGS) $*.c $(ERRFILE) + +pngrio$(O): png.h pngconf.h + $(CC) $(CFLAGS) $*.c $(ERRFILE) + +pngwio$(O): png.h pngconf.h + $(CC) $(CFLAGS) $*.c $(ERRFILE) + +pngtest$(O): png.h pngconf.h + $(CC) $(CFLAGS) $*.c $(ERRFILE) + +pngtrans$(O): png.h pngconf.h + $(CC) $(CFLAGS) $*.c $(ERRFILE) + +pngwrite$(O): png.h pngconf.h + $(CC) $(CFLAGS) $*.c $(ERRFILE) + +pngwtran$(O): png.h pngconf.h + $(CC) $(CFLAGS) $*.c $(ERRFILE) + +pngwutil$(O): png.h pngconf.h + $(CC) $(CFLAGS) $*.c $(ERRFILE) + +libpng.lib: $(OBJS1) $(OBJS2) $(OBJS3) + wlib -b -c -n -q libpng.lib $(OBJS1) + wlib -b -c -q libpng.lib $(OBJS2) + wlib -b -c -q libpng.lib $(OBJS3) + +pngtest.exe: pngtest.obj libpng.lib + $(LD) $(LDFLAGS) pngtest.obj libpng.lib $(ZLIBLIB)\zlib.lib + +test: pngtest.exe .symbolic + pngtest.exe + + +# End of makefile for libpng diff --git a/libs/libpng-src/scripts/makevms.com b/libs/libpng-src/scripts/makevms.com new file mode 100644 index 000000000..36d119067 --- /dev/null +++ b/libs/libpng-src/scripts/makevms.com @@ -0,0 +1,142 @@ +$! make libpng under VMS +$! +$! +$! Check for MMK/MMS +$! +$! This procedure accepts one parameter (contrib), which causes it to build +$! the programs from the contrib directory instead of libpng. +$! +$ p1 = f$edit(p1,"UPCASE") +$ if p1 .eqs. "CONTRIB" +$ then +$ set def [.contrib.gregbook] +$ @makevms +$ set def [-.pngminus] +$ @makevms +$ set def [--] +$ exit +$ endif +$ Make = "" +$ If F$Search ("Sys$System:MMS.EXE") .nes. "" Then Make = "MMS" +$ If F$Type (MMK) .eqs. "STRING" Then Make = "MMK" +$! +$! Look for the compiler used +$! +$ zlibsrc = "[-.zlib]" +$ ccopt="/include=''zlibsrc'" +$ if f$getsyi("HW_MODEL").ge.1024 +$ then +$ ccopt = "/prefix=all"+ccopt +$ comp = "__decc__=1" +$ if f$trnlnm("SYS").eqs."" then define sys sys$library: +$ else +$ if f$search("SYS$SYSTEM:DECC$COMPILER.EXE").eqs."" +$ then +$ if f$trnlnm("SYS").eqs."" then define sys sys$library: +$ if f$search("SYS$SYSTEM:VAXC.EXE").eqs."" +$ then +$ comp = "__gcc__=1" +$ CC :== GCC +$ else +$ comp = "__vaxc__=1" +$ endif +$ else +$ if f$trnlnm("SYS").eqs."" then define sys decc$library_include: +$ ccopt = "/decc/prefix=all"+ccopt +$ comp = "__decc__=1" +$ endif +$ endif +$! +$! Build the thing plain or with mms/mmk +$! +$ write sys$output "Compiling Libpng sources ..." +$ if make.eqs."" +$ then +$ dele pngtest.obj;* +$ CALL MAKE png.OBJ "cc ''CCOPT' png" - + png.c png.h pngconf.h +$ CALL MAKE pngset.OBJ "cc ''CCOPT' pngset" - + pngset.c png.h pngconf.h +$ CALL MAKE pngget.OBJ "cc ''CCOPT' pngget" - + pngget.c png.h pngconf.h +$ CALL MAKE pngread.OBJ "cc ''CCOPT' pngread" - + pngread.c png.h pngconf.h +$ CALL MAKE pngpread.OBJ "cc ''CCOPT' pngpread" - + pngpread.c png.h pngconf.h +$ CALL MAKE pngrtran.OBJ "cc ''CCOPT' pngrtran" - + pngrtran.c png.h pngconf.h +$ CALL MAKE pngrutil.OBJ "cc ''CCOPT' pngrutil" - + pngrutil.c png.h pngconf.h +$ CALL MAKE pngerror.OBJ "cc ''CCOPT' pngerror" - + pngerror.c png.h pngconf.h +$ CALL MAKE pngmem.OBJ "cc ''CCOPT' pngmem" - + pngmem.c png.h pngconf.h +$ CALL MAKE pngrio.OBJ "cc ''CCOPT' pngrio" - + pngrio.c png.h pngconf.h +$ CALL MAKE pngwio.OBJ "cc ''CCOPT' pngwio" - + pngwio.c png.h pngconf.h +$ CALL MAKE pngtrans.OBJ "cc ''CCOPT' pngtrans" - + pngtrans.c png.h pngconf.h +$ CALL MAKE pngwrite.OBJ "cc ''CCOPT' pngwrite" - + pngwrite.c png.h pngconf.h +$ CALL MAKE pngwtran.OBJ "cc ''CCOPT' pngwtran" - + pngwtran.c png.h pngconf.h +$ CALL MAKE pngwutil.OBJ "cc ''CCOPT' pngwutil" - + pngwutil.c png.h pngconf.h +$ write sys$output "Building Libpng ..." +$ CALL MAKE libpng.OLB "lib/crea libpng.olb *.obj" *.OBJ +$ write sys$output "Building pngtest..." +$ CALL MAKE pngtest.OBJ "cc ''CCOPT' pngtest" - + pngtest.c png.h pngconf.h +$ call make pngtest.exe - + "LINK pngtest,libpng.olb/lib,''zlibsrc'libz.olb/lib" - + pngtest.obj libpng.olb +$ write sys$output "Testing Libpng..." +$ run pngtest +$ else +$ if f$search("DESCRIP.MMS") .eqs. "" then copy/nolog [.SCRIPTS]DESCRIP.MMS [] +$ 'make'/macro=('comp',zlibsrc='zlibsrc') +$ endif +$ write sys$output "Libpng build completed" +$ exit +$! +$! +$MAKE: SUBROUTINE !SUBROUTINE TO CHECK DEPENDENCIES +$ V = 'F$Verify(0) +$! P1 = What we are trying to make +$! P2 = Command to make it +$! P3 - P8 What it depends on +$ +$ If F$Search(P1) .Eqs. "" Then Goto Makeit +$ Time = F$CvTime(F$File(P1,"RDT")) +$arg=3 +$Loop: +$ Argument = P'arg +$ If Argument .Eqs. "" Then Goto Exit +$ El=0 +$Loop2: +$ File = F$Element(El," ",Argument) +$ If File .Eqs. " " Then Goto Endl +$ AFile = "" +$Loop3: +$ OFile = AFile +$ AFile = F$Search(File) +$ If AFile .Eqs. "" .Or. AFile .Eqs. OFile Then Goto NextEl +$ If F$CvTime(F$File(AFile,"RDT")) .Ges. Time Then Goto Makeit +$ Goto Loop3 +$NextEL: +$ El = El + 1 +$ Goto Loop2 +$EndL: +$ arg=arg+1 +$ If arg .Le. 8 Then Goto Loop +$ Goto Exit +$ +$Makeit: +$ VV=F$VERIFY(0) +$ write sys$output P2 +$ 'P2 +$ VV='F$Verify(VV) +$Exit: +$ If V Then Set Verify +$ENDSUBROUTINE diff --git a/libs/libpng-src/scripts/png32ce.def b/libs/libpng-src/scripts/png32ce.def new file mode 100644 index 000000000..8b00637e6 --- /dev/null +++ b/libs/libpng-src/scripts/png32ce.def @@ -0,0 +1,236 @@ +;------------------------------------------ +; LIBPNG module definition file for Windows +;------------------------------------------ + +LIBRARY lpngce + +EXPORTS +;Version 1.2.46 + png_build_grayscale_palette @1 + png_check_sig @2 + png_chunk_error @3 + png_chunk_warning @4 +; png_convert_from_struct_tm @5 +; png_convert_from_time_t @6 + png_create_info_struct @7 + png_create_read_struct @8 + png_create_write_struct @9 + png_data_freer @10 + png_destroy_info_struct @11 + png_destroy_read_struct @12 + png_destroy_write_struct @13 + png_error @14 + png_free @15 + png_free_data @16 + png_get_IHDR @17 + png_get_PLTE @18 + png_get_bKGD @19 + png_get_bit_depth @20 + png_get_cHRM @21 + png_get_cHRM_fixed @22 + png_get_channels @23 + png_get_color_type @24 + png_get_compression_buffer_size @25 + png_get_compression_type @26 + png_get_copyright @27 + png_get_error_ptr @28 + png_get_filter_type @29 + png_get_gAMA @30 + png_get_gAMA_fixed @31 + png_get_hIST @32 + png_get_header_ver @33 + png_get_header_version @34 + png_get_iCCP @35 + png_get_image_height @36 + png_get_image_width @37 + png_get_interlace_type @38 + png_get_libpng_ver @40 + png_get_oFFs @41 + png_get_pCAL @42 + png_get_pHYs @43 + png_get_pixel_aspect_ratio @44 + png_get_pixels_per_meter @45 + png_get_progressive_ptr @46 + png_get_rgb_to_gray_status @47 + png_get_rowbytes @48 + png_get_rows @49 + png_get_sBIT @50 + png_get_sCAL @51 + png_get_sPLT @52 + png_get_sRGB @53 + png_get_signature @54 + png_get_tIME @55 + png_get_tRNS @56 + png_get_text @57 + png_get_unknown_chunks @58 + png_get_user_chunk_ptr @59 + png_get_user_transform_ptr @60 + png_get_valid @61 + png_get_x_offset_microns @62 + png_get_x_offset_pixels @63 + png_get_x_pixels_per_meter @64 + png_get_y_offset_microns @65 + png_get_y_offset_pixels @66 + png_get_y_pixels_per_meter @67 + png_malloc @68 + png_memcpy_check @69 + png_memset_check @70 + png_permit_empty_plte @71 + png_process_data @72 + png_progressive_combine_row @73 + png_read_end @74 + png_read_image @75 + png_read_info @76 +; png_read_init is deprecated + png_read_init @77 + png_read_png @78 + png_read_row @79 + png_read_rows @80 + png_read_update_info @81 + png_reset_zstream @82 + png_set_IHDR @83 + png_set_PLTE @84 + png_set_bKGD @85 + png_set_background @86 + png_set_bgr @87 + png_set_cHRM @88 + png_set_cHRM_fixed @89 + png_set_compression_buffer_size @90 + png_set_compression_level @91 + png_set_compression_mem_level @92 + png_set_compression_method @93 + png_set_compression_strategy @94 + png_set_compression_window_bits @95 + png_set_crc_action @96 + png_set_dither @97 + png_set_error_fn @98 + png_set_expand @99 + png_set_filler @100 + png_set_filter @101 + png_set_filter_heuristics @102 + png_set_flush @103 + png_set_gAMA @104 + png_set_gAMA_fixed @105 + png_set_gamma @106 + png_set_gray_1_2_4_to_8 @107 ; deprecated + png_set_gray_to_rgb @108 + png_set_hIST @109 + png_set_iCCP @110 + png_set_interlace_handling @111 + png_set_invert_alpha @112 + png_set_invert_mono @113 + png_set_keep_unknown_chunks @114 + png_set_oFFs @115 + png_set_pCAL @116 + png_set_pHYs @117 + png_set_packing @118 + png_set_packswap @119 + png_set_palette_to_rgb @120 + png_set_progressive_read_fn @121 + png_set_read_fn @122 + png_set_read_status_fn @123 + png_set_read_user_chunk_fn @124 + png_set_read_user_transform_fn @125 + png_set_rgb_to_gray @126 + png_set_rgb_to_gray_fixed @127 + png_set_rows @128 + png_set_sBIT @129 + png_set_sCAL @130 + png_set_sPLT @131 + png_set_sRGB @132 + png_set_sRGB_gAMA_and_cHRM @133 + png_set_shift @134 + png_set_sig_bytes @135 + png_set_strip_16 @136 + png_set_strip_alpha @137 + png_set_swap @138 + png_set_swap_alpha @139 + png_set_tIME @140 + png_set_tRNS @141 + png_set_tRNS_to_alpha @142 + png_set_text @143 + png_set_unknown_chunk_location @144 + png_set_unknown_chunks @145 + png_set_user_transform_info @146 + png_set_write_fn @147 + png_set_write_status_fn @148 + png_set_write_user_transform_fn @149 + png_sig_cmp @150 + png_start_read_image @151 + png_warning @152 + png_write_chunk @153 + png_write_chunk_data @154 + png_write_chunk_end @155 + png_write_chunk_start @156 + png_write_end @157 + png_write_flush @158 + png_write_image @159 + png_write_info @160 + png_write_info_before_PLTE @161 +; png_write_init is deprecated + png_write_init @162 + png_write_png @163 + png_write_row @164 + png_write_rows @165 +; png_read_init_2 and png_write_init_2 are deprecated. + png_read_init_2 @166 + png_write_init_2 @167 + png_access_version_number @168 +; png_sig_bytes @169 +; png_libpng_ver @170 + png_init_io @171 + png_convert_to_rfc1123 @172 + png_set_invalid @173 +; Added at version 1.0.12 +; For compatiblity with 1.0.7-1.0.11 + png_info_init @174 + png_read_init_3 @175 + png_write_init_3 @176 + png_info_init_3 @177 + png_destroy_struct @178 +; Added at version 1.2.0 +; For use with PNG_USER_MEM_SUPPORTED +; png_destroy_struct_2 @179 +; png_create_read_struct_2 @180 +; png_create_write_struct_2 @181 +; png_malloc_default @182 +; png_free_default @183 +; MNG features +; png_permit_mng_features @184 +; MMX support +; png_mmx_support @185 +; png_get_mmx_flagmask @186 +; png_get_asm_flagmask @187 +; png_get_asm_flags @188 +; png_get_mmx_bitdepth_threshold @189 +; png_get_mmx_rowbytes_threshold @190 +; png_set_asm_flags @191 +; png_init_mmx_flags @192 +; Strip error numbers + png_set_strip_error_numbers @193 +; Added at version 1.2.2 + png_handle_as_unknown @179 + png_zalloc @180 + png_zfree @181 +; png_handle_as_unknown @194 +; png_zalloc @195 +; png_zfree @196 +; Added at version 1.2.6 + png_malloc_warn @195 + png_get_user_height_max @196 + png_get_user_width_max @197 + png_set_user_limits @198 +; Added at version 1.2.7 + png_set_add_alpha @199 +; Added at version 1.2.9 + png_get_uint_32 @200 + png_save_uint_32 @201 + png_get_uint_16 @202 + png_save_uint_16 @203 + png_get_int_32 @204 + png_save_int_32 @205 + png_get_uint_31 @206 + png_set_expand_gray_1_2_4_to_8 @207 +; Added at version 1.2.41 + png_write_sig @208 + png_check_cHRM_fixed @217 diff --git a/libs/libpng-src/scripts/pngos2.def b/libs/libpng-src/scripts/pngos2.def new file mode 100644 index 000000000..e9e92f979 --- /dev/null +++ b/libs/libpng-src/scripts/pngos2.def @@ -0,0 +1,260 @@ +;---------------------------------------- +; PNG.LIB module definition file for OS/2 +;---------------------------------------- + +; Version 1.2.46 + +LIBRARY PNG +DESCRIPTION "PNG image compression library for OS/2" +CODE PRELOAD MOVEABLE DISCARDABLE +DATA PRELOAD MOVEABLE MULTIPLE + +EXPORTS + + png_build_grayscale_palette + png_check_sig + png_chunk_error + png_chunk_warning + png_convert_from_struct_tm + png_convert_from_time_t + png_create_info_struct + png_create_read_struct + png_create_write_struct + png_data_freer + png_destroy_info_struct + png_destroy_read_struct + png_destroy_write_struct + png_error + png_free + png_free_data + png_get_IHDR + png_get_PLTE + png_get_bKGD + png_get_bit_depth + png_get_cHRM + png_get_cHRM_fixed + png_get_channels + png_get_color_type + png_get_compression_buffer_size + png_get_compression_type + png_get_copyright + png_get_error_ptr + png_get_filter_type + png_get_gAMA + png_get_gAMA_fixed + png_get_hIST + png_get_header_ver + png_get_header_version + png_get_iCCP + png_get_image_height + png_get_image_width + png_get_interlace_type + png_get_io_ptr + png_get_libpng_ver + png_get_oFFs + png_get_pCAL + png_get_pHYs + png_get_pixel_aspect_ratio + png_get_pixels_per_meter + png_get_progressive_ptr + png_get_rgb_to_gray_status + png_get_rowbytes + png_get_rows + png_get_sBIT + png_get_sCAL + png_get_sPLT + png_get_sRGB + png_get_signature + png_get_tIME + png_get_tRNS + png_get_text + png_get_unknown_chunks + png_get_user_chunk_ptr + png_get_user_transform_ptr + png_get_valid + png_get_x_offset_microns + png_get_x_offset_pixels + png_get_x_pixels_per_meter + png_get_y_offset_microns + png_get_y_offset_pixels + png_get_y_pixels_per_meter + png_malloc + png_memcpy_check + png_memset_check + png_permit_empty_plte + png_process_data + png_progressive_combine_row + png_read_end + png_read_image + png_read_info +; png_read_init ; deprecated + png_read_png + png_read_row + png_read_rows + png_read_update_info + png_reset_zstream + png_set_IHDR + png_set_PLTE + png_set_bKGD + png_set_background + png_set_bgr + png_set_cHRM + png_set_cHRM_fixed + png_set_compression_buffer_size + png_set_compression_level + png_set_compression_mem_level + png_set_compression_method + png_set_compression_strategy + png_set_compression_window_bits + png_set_crc_action + png_set_dither + png_set_error_fn + png_set_expand + png_set_filler + png_set_filter + png_set_filter_heuristics + png_set_flush + png_set_gAMA + png_set_gAMA_fixed + png_set_gamma +; png_set_gray_1_2_4_to_8 ; deprecated as of libpng-1.2.9 + png_set_gray_to_rgb + png_set_hIST + png_set_iCCP + png_set_interlace_handling + png_set_invert_alpha + png_set_invert_mono + png_set_keep_unknown_chunks + png_set_oFFs + png_set_pCAL + png_set_pHYs + png_set_packing + png_set_packswap + png_set_palette_to_rgb + png_set_progressive_read_fn + png_set_read_fn + png_set_read_status_fn + png_set_read_user_chunk_fn + png_set_read_user_transform_fn + png_set_rgb_to_gray + png_set_rgb_to_gray_fixed + png_set_rows + png_set_sBIT + png_set_sCAL + png_set_sPLT + png_set_sRGB + png_set_sRGB_gAMA_and_cHRM + png_set_shift + png_set_sig_bytes + png_set_strip_16 + png_set_strip_alpha + png_set_swap + png_set_swap_alpha + png_set_tIME + png_set_tRNS + png_set_tRNS_to_alpha + png_set_text + png_set_unknown_chunk_location + png_set_unknown_chunks + png_set_user_transform_info + png_set_write_fn + png_set_write_status_fn + png_set_write_user_transform_fn + png_sig_cmp + png_start_read_image + png_warning + png_write_chunk + png_write_chunk_data + png_write_chunk_end + png_write_chunk_start + png_write_end + png_write_flush + png_write_image + png_write_info + png_write_info_before_PLTE +; png_write_init ; deprecated + png_write_png + png_write_row + png_write_rows + png_read_init_2 + png_write_init_2 + png_access_version_number + png_init_io + png_convert_to_rfc1123 + png_set_invalid + +; Added at version 1.2.0: + png_mmx_support + png_permit_empty_plte + png_permit_mng_features + png_get_mmx_flagmask + png_get_asm_flagmask + png_get_asm_flags + png_get_mmx_bitdepth_threshold + png_get_mmx_rowbytes_threshold + png_set_asm_flags + png_init_mmx_flags + +; Added at version 1.2.2: + png_handle_as_unknown + +; Added at version 1.2.2 and deleted from 1.2.3: +; png_zalloc +; png_zfree + +; Added at version 1.2.4 + png_malloc_warn + +; Added at version 1.2.6 + png_set_user_limits + png_get_user_height_max + png_get_user_width_max +; Added at version 1.2.7 + png_set_add_alpha + +; Added at version 1.2.9 + png_get_uint_32 + png_save_uint_32 + png_get_uint_16 + png_save_uint_16 + png_get_int_32 + png_save_int_32 + png_get_uint_31 + png_set_expand_gray_1_2_4_to_8 + +; Added at version 1.2.41 + png_write_sig + png_check_cHRM_fixed + +; These are not present when libpng is compiled with PNG_NO_GLOBAL_ARRAYS + png_pass_start + png_pass_inc + png_pass_ystart + png_pass_yinc + png_pass_mask + png_pass_dsp_mask +; png_pass_width +; png_pass_height + +; These are not present when libpng is compiled with PNG_NO_GLOBAL_ARRAYS + png_IHDR + png_IDAT + png_IEND + png_PLTE + png_bKGD + png_cHRM + png_gAMA + png_hIST + png_iCCP + png_iTXt + png_oFFs + png_pCAL + png_pHYs + png_sBIT + png_sCAL + png_sPLT + png_sRGB + png_tEXt + png_tIME + png_tRNS + png_zTXt diff --git a/libs/libpng-src/scripts/pngw32.def b/libs/libpng-src/scripts/pngw32.def new file mode 100644 index 000000000..ba5e91af9 --- /dev/null +++ b/libs/libpng-src/scripts/pngw32.def @@ -0,0 +1,242 @@ +;------------------------------------------ +; LIBPNG module definition file for Windows +;------------------------------------------ + +LIBRARY + +EXPORTS +;Version 1.2.46 + png_build_grayscale_palette @1 + png_check_sig @2 + png_chunk_error @3 + png_chunk_warning @4 + png_convert_from_struct_tm @5 + png_convert_from_time_t @6 + png_create_info_struct @7 + png_create_read_struct @8 + png_create_write_struct @9 + png_data_freer @10 + png_destroy_info_struct @11 + png_destroy_read_struct @12 + png_destroy_write_struct @13 + png_error @14 + png_free @15 + png_free_data @16 + png_get_IHDR @17 + png_get_PLTE @18 + png_get_bKGD @19 + png_get_bit_depth @20 + png_get_cHRM @21 + png_get_cHRM_fixed @22 + png_get_channels @23 + png_get_color_type @24 + png_get_compression_buffer_size @25 + png_get_compression_type @26 + png_get_copyright @27 + png_get_error_ptr @28 + png_get_filter_type @29 + png_get_gAMA @30 + png_get_gAMA_fixed @31 + png_get_hIST @32 + png_get_header_ver @33 + png_get_header_version @34 + png_get_iCCP @35 + png_get_image_height @36 + png_get_image_width @37 + png_get_interlace_type @38 + png_get_io_ptr @39 + ; png_get_libpng_ver @40 + png_get_oFFs @41 + png_get_pCAL @42 + png_get_pHYs @43 + png_get_pixel_aspect_ratio @44 + png_get_pixels_per_meter @45 + png_get_progressive_ptr @46 + png_get_rgb_to_gray_status @47 + png_get_rowbytes @48 + png_get_rows @49 + png_get_sBIT @50 + png_get_sCAL @51 + png_get_sPLT @52 + png_get_sRGB @53 + png_get_signature @54 + png_get_tIME @55 + png_get_tRNS @56 + png_get_text @57 + png_get_unknown_chunks @58 + png_get_user_chunk_ptr @59 + png_get_user_transform_ptr @60 + png_get_valid @61 + png_get_x_offset_microns @62 + png_get_x_offset_pixels @63 + png_get_x_pixels_per_meter @64 + png_get_y_offset_microns @65 + png_get_y_offset_pixels @66 + png_get_y_pixels_per_meter @67 + png_malloc @68 + png_memcpy_check @69 + png_memset_check @70 +; png_permit_empty_plte is deprecated + png_permit_empty_plte @71 + png_process_data @72 + png_progressive_combine_row @73 + png_read_end @74 + png_read_image @75 + png_read_info @76 +; png_read_init is deprecated + png_read_init @77 + png_read_png @78 + png_read_row @79 + png_read_rows @80 + png_read_update_info @81 + png_reset_zstream @82 + png_set_IHDR @83 + png_set_PLTE @84 + png_set_bKGD @85 + png_set_background @86 + png_set_bgr @87 + png_set_cHRM @88 + png_set_cHRM_fixed @89 + png_set_compression_buffer_size @90 + png_set_compression_level @91 + png_set_compression_mem_level @92 + png_set_compression_method @93 + png_set_compression_strategy @94 + png_set_compression_window_bits @95 + png_set_crc_action @96 + png_set_dither @97 + png_set_error_fn @98 + png_set_expand @99 + png_set_filler @100 + png_set_filter @101 + png_set_filter_heuristics @102 + png_set_flush @103 + png_set_gAMA @104 + png_set_gAMA_fixed @105 + png_set_gamma @106 +; png_set_gray_1_2_4_to_8 is deprecated + png_set_gray_1_2_4_to_8 @107 + png_set_gray_to_rgb @108 + png_set_hIST @109 + png_set_iCCP @110 + png_set_interlace_handling @111 + png_set_invert_alpha @112 + png_set_invert_mono @113 + png_set_keep_unknown_chunks @114 + png_set_oFFs @115 + png_set_pCAL @116 + png_set_pHYs @117 + png_set_packing @118 + png_set_packswap @119 + png_set_palette_to_rgb @120 + png_set_progressive_read_fn @121 + png_set_read_fn @122 + png_set_read_status_fn @123 + png_set_read_user_chunk_fn @124 + png_set_read_user_transform_fn @125 + png_set_rgb_to_gray @126 + png_set_rgb_to_gray_fixed @127 + png_set_rows @128 + png_set_sBIT @129 + png_set_sCAL @130 + png_set_sPLT @131 + png_set_sRGB @132 + png_set_sRGB_gAMA_and_cHRM @133 + png_set_shift @134 + png_set_sig_bytes @135 + png_set_strip_16 @136 + png_set_strip_alpha @137 + png_set_swap @138 + png_set_swap_alpha @139 + png_set_tIME @140 + png_set_tRNS @141 + png_set_tRNS_to_alpha @142 + png_set_text @143 + png_set_unknown_chunk_location @144 + png_set_unknown_chunks @145 + png_set_user_transform_info @146 + png_set_write_fn @147 + png_set_write_status_fn @148 + png_set_write_user_transform_fn @149 + png_sig_cmp @150 + png_start_read_image @151 + png_warning @152 + png_write_chunk @153 + png_write_chunk_data @154 + png_write_chunk_end @155 + png_write_chunk_start @156 + png_write_end @157 + png_write_flush @158 + png_write_image @159 + png_write_info @160 + png_write_info_before_PLTE @161 +; png_write_init is deprecated + png_write_init @162 + png_write_png @163 + png_write_row @164 + png_write_rows @165 +; png_read_init_2 and png_write_init_2 are deprecated. + png_read_init_2 @166 + png_write_init_2 @167 + png_access_version_number @168 +; png_sig_bytes @169 +; Removed from version 1.2.20 +; png_libpng_ver @170 +; + png_init_io @171 + png_convert_to_rfc1123 @172 + png_set_invalid @173 +; Added at version 1.0.12 +; For compatibility with 1.0.7-1.0.11 +; png_info_init @174 +; png_read_init_3, png_info_init_3, and png_write_init_3 are deprecated. + png_read_init_3 @175 + png_write_init_3 @176 + png_info_init_3 @177 + png_destroy_struct @178 +; Added at version 1.2.0 +; For use with PNG_USER_MEM_SUPPORTED + png_destroy_struct_2 @179 + png_create_read_struct_2 @180 + png_create_write_struct_2 @181 + png_malloc_default @182 + png_free_default @183 +; MNG features + png_permit_mng_features @184 +; MMX support + png_mmx_support @185 +; png_get_mmx_flagmask @186 + png_get_asm_flagmask @187 + png_get_asm_flags @188 +; png_get_mmx_bitdepth_threshold @189 +; png_get_mmx_rowbytes_threshold @190 + png_set_asm_flags @191 +; png_init_mmx_flags @192 +; Strip error numbers + png_set_strip_error_numbers @193 +; Added at version 1.2.2 + png_handle_as_unknown @194 +; Added at version 1.2.2 and deleted from 1.2.3 +; png_zalloc @195 +; png_zfree @196 +; Added at version 1.2.4 + png_malloc_warn @195 +; Added at version 1.2.6 + png_malloc_warn @195 + png_get_user_height_max @196 + png_get_user_width_max @197 + png_set_user_limits @198 +; Added at version 1.2.7 + png_set_add_alpha @199 +; Added at version 1.2.9 + png_get_uint_32 @200 + png_save_uint_32 @201 + png_get_uint_16 @202 + png_save_uint_16 @203 + png_get_int_32 @204 + png_save_int_32 @205 + png_get_uint_31 @206 + png_set_expand_gray_1_2_4_to_8 @207 +; Added at version 1.2.41 + png_write_sig @208 + png_check_cHRM_fixed @217 diff --git a/libs/libpng-src/scripts/pngw32.rc b/libs/libpng-src/scripts/pngw32.rc new file mode 100644 index 000000000..9335cbbe0 --- /dev/null +++ b/libs/libpng-src/scripts/pngw32.rc @@ -0,0 +1,112 @@ +#define PNG_VERSION_INFO_ONLY + +#include +#include "../png.h" + +#define _QUOTE(x) # x +#define QUOTE(x) _QUOTE(x) + +#define PNG_LIBPNG_DLLFNAME "LIBPNG" + +/* Support deprecated PRIVATEBUILD macro */ +#if defined(PRIVATEBUILD) && !defined(PNG_USER_PRIVATEBUILD) +# define PNG_USER_PRIVATEBUILD PRIVATEBUILD +#endif + +#if defined(PNG_USER_DLLFNAME_POSTFIX) && !defined(PNG_USER_PRIVATEBUILD) +# error "PNG_USER_PRIVATEBUILD must be defined as a string describing the\ + custom changes made to the library." +#endif + +/* Prioritize PNG_USER_x over PNG_LIBPNG_x */ +#ifdef PNG_USER_DLLFNAME_POSTFIX +# undef PNG_LIBPNG_DLLFNAME_POSTFIX +# define PNG_LIBPNG_DLLFNAME_POSTFIX PNG_USER_DLLFNAME_POSTFIX +#endif + +#ifdef PNG_USER_VERSIONINFO_COMMENTS +# undef PNG_LIBPNG_VERSIONINFO_COMMENTS +# define PNG_LIBPNG_VERSIONINFO_COMMENTS PNG_USER_VERSIONINFO_COMMENTS +#endif + +#if defined(PNG_DEBUG) && (PNG_DEBUG > 0) +# define VS_DEBUG VS_FF_DEBUG +# ifndef PNG_LIBPNG_DLLFNAME_POSTFIX +# define PNG_LIBPNG_DLLFNAME_POSTFIX "D" +# endif /* PNG_LIBPNG_DLLFNAME_POSTFIX */ +# ifndef PNG_LIBPNG_VERSIONINFO_COMMENTS +# define PNG_LIBPNG_VERSIONINFO_COMMENTS "PNG_DEBUG=" QUOTE(PNG_DEBUG) +# endif /* PNG_LIBPNG_VERSIONINFO_COMMENTS */ +#else +# define VS_DEBUG 0 +# ifndef PNG_LIBPNG_DLLFNAME_POSTFIX +# define PNG_LIBPNG_DLLFNAME_POSTFIX +# endif /* PNG_LIBPNG_DLLFNAME_POSTFIX */ +#endif /* defined(DEBUG)... */ + +#ifdef PNG_USER_PRIVATEBUILD +# define VS_PRIVATEBUILD VS_FF_PRIVATEBUILD +#else +# define VS_PRIVATEBUILD 0 +#endif /* PNG_USER_PRIVATEBUILD */ + +#ifdef PNG_LIBPNG_SPECIALBUILD +# define VS_SPECIALBUILD VS_FF_SPECIALBUILD +#else +# define VS_SPECIALBUILD 0 +#endif /* PNG_LIBPNG_BUILD_SPECIAL */ + +#if ((PNG_LIBPNG_BUILD_BASE_TYPE & PNG_LIBPNG_RELEASE_STATUS_MASK) !=\ + PNG_LIBPNG_BUILD_STABLE) +# define VS_PRERELEASE VS_FF_PRERELEASE +# define VS_PATCHED 0 +#else +# define VS_PRERELEASE 0 +# if (PNG_LIBPNG_BUILD_BASE_TYPE & PNG_LIBPNG_BUILD_PATCHED) +# define VS_PATCHED VS_FF_PATCHED +# else +# define VS_PATCHED 0 +# endif +#endif + +VS_VERSION_INFO VERSIONINFO +FILEVERSION PNG_LIBPNG_VER_MAJOR, PNG_LIBPNG_VER_MINOR, PNG_LIBPNG_VER_RELEASE, PNG_LIBPNG_VER_BUILD +PRODUCTVERSION PNG_LIBPNG_VER_MAJOR, PNG_LIBPNG_VER_MINOR, PNG_LIBPNG_VER_RELEASE, PNG_LIBPNG_VER_BUILD +FILEFLAGSMASK VS_FFI_FILEFLAGSMASK +FILEFLAGS VS_DEBUG | VS_PRIVATEBUILD | VS_SPECIALBUILD | VS_PRERELEASE | VS_PATCHED +FILEOS VOS__WINDOWS32 +FILETYPE VFT_DLL +FILESUBTYPE VFT2_UNKNOWN +BEGIN + BLOCK "StringFileInfo" + BEGIN BLOCK "040904E4" /* Language type = U.S English(0x0409) and Character Set = Windows, Multilingual(0x04E4) */ + BEGIN +#ifdef PNG_LIBPNG_VERSIONINFO_COMMENTS + VALUE "Comments", PNG_LIBPNG_VERSIONINFO_COMMENTS "\000" +#endif /* PNG_LIBPNG_VERSIONINFO_COMMENTS */ +#ifdef PNG_USER_VERSIONINFO_COMPANYNAME + VALUE "CompanyName", PNG_USER_VERSIONINFO_COMPANYNAME "\000" +#endif /* PNG_USER_VERSIONINFO_COMPANYNAME */ + VALUE "FileDescription", "PNG image compression library\000" + VALUE "FileVersion", PNG_LIBPNG_VER_STRING "\000" + VALUE "InternalName", PNG_LIBPNG_DLLFNAME QUOTE(PNG_LIBPNG_VER_DLLNUM) PNG_LIBPNG_DLLFNAME_POSTFIX " (Windows 32 bit)\000" + VALUE "LegalCopyright", "\251 1998-2009 Glenn Randers-Pehrson et al.\000" +#ifdef PNG_USER_VERSIONINFO_LEGALTRADEMARKS + VALUE "LegalTrademarks", PNG_USER_VERSIONINFO_LEGALTRADEMARKS "\000" +#endif /* PNG_USER_VERSIONINFO_LEGALTRADEMARKS */ + VALUE "OriginalFilename", PNG_LIBPNG_DLLFNAME QUOTE(PNG_LIBPNG_VER_DLLNUM) PNG_LIBPNG_DLLFNAME_POSTFIX ".DLL\000" +#ifdef PNG_USER_PRIVATEBUILD + VALUE "PrivateBuild", PNG_USER_PRIVATEBUILD "\000" +#endif /* PNG_USER_PRIVATEBUILD */ + VALUE "ProductName", "LibPNG\000" + VALUE "ProductVersion", "1\000" +#ifdef PNG_LIBPNG_SPECIALBUILD + VALUE "SpecialBuild", PNG_LIBPNG_SPECIALBUILD "\000" +#endif /* PNG_LIBPNG_SPECIALBUILD */ + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x0409, 0x04E4 + END +END diff --git a/libs/libpng-src/scripts/smakefile.ppc b/libs/libpng-src/scripts/smakefile.ppc new file mode 100644 index 000000000..531c693f6 --- /dev/null +++ b/libs/libpng-src/scripts/smakefile.ppc @@ -0,0 +1,33 @@ +# Amiga powerUP (TM) Makefile +# makefile for libpng and SAS C V6.58/7.00 PPC compiler +# Copyright (C) 1998 by Andreas R. Kleinert +# +# This code is released under the libpng license. +# For conditions of distribution and use, see the disclaimer +# and license in png.h + +CC = scppc +CFLAGS = NOSTKCHK NOSINT OPTIMIZE OPTGO OPTPEEP OPTINLOCAL OPTINL IDIR /zlib \ + OPTLOOP OPTRDEP=8 OPTDEP=8 OPTCOMP=8 +LIBNAME = libpng.a +AR = ppc-amigaos-ar +AR_FLAGS = cr +RANLIB = ppc-amigaos-ranlib +LDFLAGS = -r -o +LDLIBS = ../zlib/libzip.a LIB:scppc.a +LN = ppc-amigaos-ld +RM = delete quiet +MKDIR = makedir + +OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o pngread.o \ +pngerror.o pngpread.o pngwrite.o pngrtran.o pngwtran.o pngrio.o pngwio.o pngmem.o + +all: $(LIBNAME) pngtest + +$(LIBNAME): $(OBJS) + $(AR) $(AR_FLAGS) $@ $(OBJS) + $(RANLIB) $@ + +pngtest: pngtest.o $(LIBNAME) + $(LN) $(LDFLAGS) pngtest LIB:c_ppc.o pngtest.o $(LIBNAME) $(LDLIBS) \ +LIB:end.o diff --git a/libs/libpng-src/test-pngtest.sh b/libs/libpng-src/test-pngtest.sh new file mode 100755 index 000000000..c134a8a84 --- /dev/null +++ b/libs/libpng-src/test-pngtest.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +./pngtest ${srcdir}/pngtest.png diff --git a/libs/miniupnpc/.gitignore b/libs/miniupnpc/.gitignore new file mode 100644 index 000000000..fc62e4c97 --- /dev/null +++ b/libs/miniupnpc/.gitignore @@ -0,0 +1,13 @@ +/*.o +/*.a +/libminiupnpc.so +/miniupnpcstrings.h +/upnpc-shared +/upnpc-static +/dll +/init +/miniupnpc.dll +/miniupnpc.dll.def +/miniupnpc.lib +/testminixml +/wingenminiupnpcstrings diff --git a/libs/miniupnpc/CMakeLists.txt b/libs/miniupnpc/CMakeLists.txt new file mode 100644 index 000000000..082b653a9 --- /dev/null +++ b/libs/miniupnpc/CMakeLists.txt @@ -0,0 +1,172 @@ +cmake_minimum_required (VERSION 2.6) + +project (miniupnpc C) +set (MINIUPNPC_VERSION 1.5) +set (MINIUPNPC_API_VERSION 8) + +if (NOT CMAKE_BUILD_TYPE) + if (WIN32) + set (DEFAULT_BUILD_TYPE MinSizeRel) + else (WIN32) + set (DEFAULT_BUILD_TYPE RelWithDebInfo) + endif(WIN32) + set (CMAKE_BUILD_TYPE ${DEFAULT_BUILD_TYPE} CACHE STRING + "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." + FORCE) +endif() + +option (UPNPC_BUILD_STATIC "Build static library" TRUE) +option (UPNPC_BUILD_SHARED "Build shared library" TRUE) +if (NOT WIN32) + option (UPNPC_BUILD_TESTS "Build test executables" TRUE) +endif (NOT WIN32) +option (NO_GETADDRINFO "Define NO_GETADDRINFO" FALSE) + +mark_as_advanced (NO_GETADDRINFO) + +if (NO_GETADDRINFO) + add_definitions (-DNO_GETADDRINFO) +endif (NO_GETADDRINFO) + +if (NOT WIN32) + add_definitions (-DMINIUPNPC_SET_SOCKET_TIMEOUT) +else (NOT WIN32) + add_definitions (-D_WIN32_WINNT=0x0501) # XP or higher for getnameinfo and friends +endif (NOT WIN32) + +if (CMAKE_SYSTEM_NAME STREQUAL "Darwin") + add_definitions (-DMACOSX -D_DARWIN_C_SOURCE) +endif () + +# Set compiler specific build flags +if (CMAKE_COMPILER_IS_GNUC) + # Set our own default flags at first run. + if (NOT CONFIGURED) + + if (NOT CMAKE_SYSTEM_NAME STREQUAL "AmigaOS") + set (_PIC -fPIC) + endif (CMAKE_SYSTEM_NAME STREQUAL "AmigaOS") + + set (CMAKE_C_FLAGS "${_PIC} -Wall $ENV{CFLAGS}" # CMAKE_C_FLAGS gets appended to the other C flags + CACHE STRING "Flags used by the C compiler during normal builds." FORCE) + set (CMAKE_C_FLAGS_DEBUG "-g -DDDEBUG" + CACHE STRING "Flags used by the C compiler during debug builds." FORCE) + set (CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG" + CACHE STRING "Flags used by the C compiler during release builds." FORCE) + set (CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g -DNDEBUG" + CACHE STRING "Flags used by the C compiler during release builds." FORCE) + set (CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG" + CACHE STRING "Flags used by the C compiler during release builds." FORCE) + + endif (NOT CONFIGURED) +endif () + +configure_file (${CMAKE_SOURCE_DIR}/miniupnpcstrings.h.cmake ${CMAKE_BINARY_DIR}/miniupnpcstrings.h) +include_directories (${CMAKE_BINARY_DIR}) + +set (MINIUPNPC_SOURCES + igd_desc_parse.c + miniupnpc.c + minixml.c + minisoap.c + miniwget.c + upnpc.c + upnpcommands.c + upnpreplyparse.c + upnperrors.c + connecthostport.c + portlistingparse.c +) + +if (NOT WIN32 AND NOT CMAKE_SYSTEM_NAME STREQUAL "AmigaOS") + set (MINIUPNPC_SOURCES ${MINIUPNPC_SOURCES} minissdpc.c) +endif (NOT WIN32 AND NOT CMAKE_SYSTEM_NAME STREQUAL "AmigaOS") + +if (WIN32) + set_source_files_properties (${MINIUPNPC_SOURCES} PROPERTIES + COMPILE_DEFINITIONS STATICLIB + COMPILE_DEFINITIONS MINIUPNP_EXPORTS + ) +endif (WIN32) + +if (WIN32) + find_library (WINSOCK2_LIBRARY NAMES ws2_32 WS2_32 Ws2_32) + find_library (IPHLPAPI_LIBRARY NAMES iphlpapi) + set (LDLIBS ${WINSOCK2_LIBRARY} ${IPHLPAPI_LIBRARY} ${LDLIBS}) +#elseif (CMAKE_SYSTEM_NAME STREQUAL "Solaris") +# find_library (SOCKET_LIBRARY NAMES socket) +# find_library (NSL_LIBRARY NAMES nsl) +# find_library (RESOLV_LIBRARY NAMES resolv) +# set (LDLIBS ${SOCKET_LIBRARY} ${NSL_LIBRARY} ${RESOLV_LIBRARY} ${LDLIBS}) +endif (WIN32) + +if (NOT UPNPC_BUILD_STATIC AND NOT UPNPC_BUILD_SHARED) + message (FATAL "Both shared and static libraries are disabled!") +endif (NOT UPNPC_BUILD_STATIC AND NOT UPNPC_BUILD_SHARED) + +if (UPNPC_BUILD_STATIC) + add_library (upnpc-static STATIC ${MINIUPNPC_SOURCES}) + set_target_properties (upnpc-static PROPERTIES OUTPUT_NAME "miniupnpc") + target_link_libraries (upnpc-static ${LDLIBS}) + set (UPNPC_INSTALL_TARGETS ${UPNPC_INSTALL_TARGETS} upnpc-static) + set (UPNPC_LIBRARY_TARGET upnpc-static) +endif (UPNPC_BUILD_STATIC) + +if (UPNPC_BUILD_SHARED) + add_library (upnpc-shared SHARED ${MINIUPNPC_SOURCES}) + set_target_properties (upnpc-shared PROPERTIES OUTPUT_NAME "miniupnpc") + set_target_properties (upnpc-shared PROPERTIES VERSION ${MINIUPNPC_VERSION}) + set_target_properties (upnpc-shared PROPERTIES SOVERSION ${MINIUPNPC_API_VERSION}) + target_link_libraries (upnpc-shared ${LDLIBS}) + set (UPNPC_INSTALL_TARGETS ${UPNPC_INSTALL_TARGETS} upnpc-shared) + set (UPNPC_LIBRARY_TARGET upnpc-shared) +endif (UPNPC_BUILD_SHARED) + +if (UPNPC_BUILD_TESTS) + add_executable (testminixml testminixml.c minixml.c igd_desc_parse.c) + target_link_libraries (testminixml ${LDLIBS}) + + add_executable (minixmlvalid minixmlvalid.c minixml.c) + target_link_libraries (minixmlvalid ${LDLIBS}) + + add_executable (testupnpreplyparse testupnpreplyparse.c + minixml.c upnpreplyparse.c) + target_link_libraries (testupnpreplyparse ${LDLIBS}) + + add_executable (testigddescparse testigddescparse.c + igd_desc_parse.c minixml.c miniupnpc.c miniwget.c minissdpc.c + upnpcommands.c upnpreplyparse.c minisoap.c connecthostport.c + portlistingparse.c + ) + target_link_libraries (testigddescparse ${LDLIBS}) + + add_executable (testminiwget testminiwget.c + miniwget.c miniupnpc.c minisoap.c upnpcommands.c minissdpc.c + upnpreplyparse.c minixml.c igd_desc_parse.c connecthostport.c + portlistingparse.c + ) + target_link_libraries (testminiwget ${LDLIBS}) + +# set (UPNPC_INSTALL_TARGETS ${UPNPC_INSTALL_TARGETS} testminixml minixmlvalid testupnpreplyparse testigddescparse testminiwget) +endif (UPNPC_BUILD_TESTS) + + +install (TARGETS ${UPNPC_INSTALL_TARGETS} + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib${LIB_SUFFIX} + ARCHIVE DESTINATION lib${LIB_SUFFIX} +) +install (FILES + miniupnpc.h + miniwget.h + upnpcommands.h + igd_desc_parse.h + upnpreplyparse.h + upnperrors.h + declspec.h + DESTINATION include/miniupnpc +) + +set (CONFIGURED YES CACHE INTERNAL "") + +# vim: ts=2:sw=2 diff --git a/libs/miniupnpc/Changelog.txt b/libs/miniupnpc/Changelog.txt new file mode 100644 index 000000000..70b656498 --- /dev/null +++ b/libs/miniupnpc/Changelog.txt @@ -0,0 +1,452 @@ +$Id: Changelog.txt,v 1.152 2011/07/25 18:02:11 nanard Exp $ +miniUPnP client Changelog. + +VERSION 1.6 : released 2011/07/25 + +2011/07/25: + Update doc for version 1.6 release + +2011/06/18: + Fix for windows in miniwget.c + +2011/06/04: + display remote host in port mapping listing + +2011/06/03: + Fix in make install : there were missing headers + +2011/05/26: + Fix the socket leak in miniwget thanks to Richard Marsh. + Permit to add leaseduration in -a command. Display lease duration. + +2011/05/15: + Try both LinkLocal and SiteLocal multicast address for SSDP in IPv6 + +2011/05/09: + add a test in testminiwget.sh. + more error checking in miniwget.c + +2011/05/06: + Adding some tool to test and validate miniwget.c + simplified and debugged miniwget.c + +2011/04/11: + moving ReceiveData() to a receivedata.c file. + parsing presentation url + adding IGD v2 WANIPv6FirewallControl commands + +2011/04/10: + update of miniupnpcmodule.c + comments in miniwget.c, update in testminiwget + Adding errors codes from IGD v2 + new functions in upnpc.c for IGD v2 + +2011/04/09: + Support for litteral ip v6 address in miniwget + +2011/04/08: + Adding support for urn:schemas-upnp-org:service:WANIPv6FirewallControl:1 + Updating APIVERSION + Supporting IPV6 in upnpDiscover() + Adding a -6 option to upnpc command line tool + +2011/03/18: + miniwget/parseURL() : return an error when url param is null. + fixing GetListOfPortMappings() + +2011/03/14: + upnpDiscover() now reporting an error code. + improvements in comments. + +2011/03/11: + adding miniupnpcstrings.h.cmake and CMakeLists.txt files. + +2011/02/15: + Implementation of GetListOfPortMappings() + +2011/02/07: + updates to minixml to support character data starting with spaces + minixml now support CDATA + upnpreplyparse treats specificaly + change in simpleUPnPcommand to return the buffer (simplification) + +2011/02/06: + Added leaseDuration argument to AddPortMapping() + Starting to implement GetListOfPortMappings() + +2011/01/11: + updating wingenminiupnpcstrings.c + +2011/01/04: + improving updateminiupnpcstrings.sh + +VERSION 1.5 : released 2011/01/01 + +2010/12/21: + use NO_GETADDRINFO macro to disable the use of getaddrinfo/freeaddrinfo + +2010/12/11: + Improvements on getHTTPResponse() code. + +2010/12/09: + new code for miniwget that handle Chunked transfer encoding + using getHTTPResponse() in SOAP call code + Adding MANIFEST.in for 'python setup.py bdist_rpm' + +2010/11/25: + changes to minissdpc.c to compile under Win32. + see http://miniupnp.tuxfamily.org/forum/viewtopic.php?t=729 + +2010/09/17: + Various improvement to Makefile from MichaÅ‚ Górny + +2010/08/05: + Adding the script "external-ip.sh" from Reuben Hawkins + +2010/06/09: + update to python module to match modification made on 2010/04/05 + update to Java test code to match modification made on 2010/04/05 + all UPNP_* function now return an error if the SOAP request failed + at HTTP level. + +2010/04/17: + Using GetBestRoute() under win32 in order to find the + right interface to use. + +2010/04/12: + Retrying with HTTP/1.1 if HTTP/1.0 failed. see + http://miniupnp.tuxfamily.org/forum/viewtopic.php?p=1703 + +2010/04/07: + avoid returning duplicates in upnpDiscover() + +2010/04/05: + Create a connecthostport.h/.c with connecthostport() function + and use it in miniwget and miniupnpc. + Use getnameinfo() instead of inet_ntop or inet_ntoa + Work to make miniupnpc IPV6 compatible... + Add java test code. + Big changes in order to support device having both WANIPConnection + and WANPPPConnection. + +2010/04/04: + Use getaddrinfo() instead of gethostbyname() in miniwget. + +2010/01/06: + #define _DARWIN_C_SOURCE for Mac OS X + +2009/12/19: + Improve MinGW32 build + +2009/12/11: + adding a MSVC9 project to build the static library and executable + +2009/12/10: + Fixing some compilation stuff for Windows/MinGW + +2009/12/07: + adaptations in Makefile and updateminiupnpcstring.sh for AmigaOS + some fixes for Windows when using virtual ethernet adapters (it is the + case with VMWare installed). + +2009/12/04: + some fixes for AmigaOS compilation + Changed HTTP version to HTTP/1.0 for Soap too (to prevent chunked + transfer encoding) + +2009/12/03: + updating printIDG and testigddescparse.c for debug. + modifications to compile under AmigaOS + adding a testminiwget program + Changed miniwget to advertise itself as HTTP/1.0 to prevent chunked + transfer encoding + +2009/11/26: + fixing updateminiupnpcstrings.sh to take into account + which command that does not return an error code. + +VERSION 1.4 : released 2009/10/30 + +2009/10/16: + using Py_BEGIN_ALLOW_THREADS and Py_END_ALLOW_THREADS in python module. + +2009/10/10: + Some fixes for compilation under Solaris + compilation fixes : http://miniupnp.tuxfamily.org/forum/viewtopic.php?p=1464 + +2009/09/21: + fixing the code to ignore EINTR during connect() calls. + +2009/08/07: + Set socket timeout for connect() + Some cleanup in miniwget.c + +2009/08/04: + remove multiple redirections with -d in upnpc.c + Print textual error code in upnpc.c + Ignore EINTR during the connect() and poll() calls. + +2009/07/29: + fix in updateminiupnpcstrings.sh if OS name contains "/" + Sending a correct value for MX: field in SSDP request + +2009/07/20: + Change the Makefile to compile under Mac OS X + Fixed a stackoverflow in getDevicesFromMiniSSDPD() + +2009/07/09: + Compile under Haiku + generate miniupnpcstrings.h.in from miniupnpcstrings.h + +2009/06/04: + patching to compile under CygWin and cross compile for minGW + +VERSION 1.3 : + +2009/04/17: + updating python module + Use strtoull() when using C99 + +2009/02/28: + Fixed miniwget.c for compiling under sun + +2008/12/18: + cleanup in Makefile (thanks to Paul de Weerd) + minissdpc.c : win32 compatibility + miniupnpc.c : changed xmlns prefix from 'm' to 'u' + Removed NDEBUG (using DEBUG) + +2008/10/14: + Added the ExternalHost argument to DeletePortMapping() + +2008/10/11: + Added the ExternalHost argument to AddPortMapping() + Put a correct User-Agent: header in HTTP requests. + +VERSION 1.2 : + +2008/10/07: + Update docs + +2008/09/25: + Integrated sameport patch from Dario Meloni : Added a "sameport" + argument to upnpDiscover(). + +2008/07/18: + small modif to make Clang happy :) + +2008/07/17: + #define SOAPPREFIX "s" in miniupnpc.c in order to remove SOAP-ENV... + +2008/07/14: + include declspec.h in installation (to /usr/include/miniupnpc) + +VERSION 1.1 : + +2008/07/04: + standard options for install/ln instead of gnu-specific stuff. + +2008/07/03: + now builds a .dll and .lib with win32. (mingw32) + +2008/04/28: + make install now install the binary of the upnpc tool + +2008/04/27: + added testupnpigd.py + added error strings for miniupnpc "internal" errors + improved python module error/exception reporting. + +2008/04/23: + Completely rewrite igd_desc_parse.c in order to be compatible with + Linksys WAG200G + Added testigddescparse + updated python module + +VERSION 1.0 : + +2008/02/21: + put some #ifdef DEBUG around DisplayNameValueList() + +2008/02/18: + Improved error reporting in upnpcommands.c + UPNP_GetStatusInfo() returns LastConnectionError + +2008/02/16: + better error handling in minisoap.c + improving display of "valid IGD found" in upnpc.c + +2008/02/03: + Fixing UPNP_GetValidIGD() + improved make install :) + +2007/12/22: + Adding upnperrors.c/h to provide a strupnperror() function + used to translate UPnP error codes to string. + +2007/12/19: + Fixing getDevicesFromMiniSSDPD() + improved error reporting of UPnP functions + +2007/12/18: + It is now possible to specify a different location for MiniSSDPd socket. + working with MiniSSDPd is now more efficient. + python module improved. + +2007/12/16: + improving error reporting + +2007/12/13: + Try to improve compatibility by using HTTP/1.0 instead of 1.1 and + XML a bit different for SOAP. + +2007/11/25: + fixed select() call for linux + +2007/11/15: + Added -fPIC to CFLAG for better shared library code. + +2007/11/02: + Fixed a potential socket leak in miniwget2() + +2007/10/16: + added a parameter to upnpDiscover() in order to allow the use of another + interface than the default multicast interface. + +2007/10/12: + Fixed the creation of symbolic link in Makefile + +2007/10/08: + Added man page + +2007/10/02: + fixed memory bug in GetUPNPUrls() + +2007/10/01: + fixes in the Makefile + Added UPNP_GetIGDFromUrl() and adapted the sample program accordingly. + Added SONAME in the shared library to please debian :) + fixed MS Windows compilation (minissdpd is not available under MS Windows). + +2007/09/25: + small change to Makefile to be able to install in a different location + (default is /usr) + +2007/09/24: + now compiling both shared and static library + +2007/09/19: + Cosmetic changes on upnpc.c + +2007/09/02: + adapting to new miniSSDPd (release version ?) + +2007/08/31: + Usage of miniSSDPd to skip discovery process. + +2007/08/27: + fixed python module to allow compilation with Python older than Python 2.4 + +2007/06/12: + Added a python module. + +2007/05/19: + Fixed compilation under MinGW + +2007/05/15: + fixed a memory leak in AddPortMapping() + Added testupnpreplyparse executable to check the parsing of + upnp soap messages + minixml now ignore namespace prefixes. + +2007/04/26: + upnpc now displays external ip address with -s or -l + +2007/04/11: + changed MINIUPNPC_URL_MAXSIZE to 128 to accomodate the "BT Voyager 210" + +2007/03/19: + cleanup in miniwget.c + +2007/03/01: + Small typo fix... + +2007/01/30: + Now parsing the HTTP header from SOAP responses in order to + get content-length value. + +2007/01/29: + Fixed the Soap Query to speedup the HTTP request. + added some Win32 DLL stuff... + +2007/01/27: + Fixed some WIN32 compatibility issues + +2006/12/14: + Added UPNPIGD_IsConnected() function in miniupnp.c/.h + Added UPNP_GetValidIGD() in miniupnp.c/.h + cleaned upnpc.c main(). now using UPNP_GetValidIGD() + +2006/12/07: + Version 1.0-RC1 released + +2006/12/03: + Minor changes to compile under SunOS/Solaris + +2006/11/30: + made a minixml parser validator program + updated minixml to handle attributes correctly + +2006/11/22: + Added a -r option to the upnpc sample thanks to Alexander Hubmann. + +2006/11/19: + Cleanup code to make it more ANSI C compliant + +2006/11/10: + detect and display local lan address. + +2006/11/04: + Packets and Bytes Sent/Received are now unsigned int. + +2006/11/01: + Bug fix thanks to Giuseppe D'Angelo + +2006/10/31: + C++ compatibility for .h files. + Added a way to get ip Address on the LAN used to reach the IGD. + +2006/10/25: + Added M-SEARCH to the services in the discovery process. + +2006/10/22: + updated the Makefile to use makedepend, added a "make install" + update Makefile + +2006/10/20: + fixing the description url parsing thanks to patch sent by + Wayne Dawe. + Fixed/translated some comments. + Implemented a better discover process, first looking + for IGD then for root devices (as some devices only reply to + M-SEARCH for root devices). + +2006/09/02: + added freeUPNPDevlist() function. + +2006/08/04: + More command line arguments checking + +2006/08/01: + Added the .bat file to compile under Win32 with minGW32 + +2006/07/31: + Fixed the rootdesc parser (igd_desc_parse.c) + +2006/07/20: + parseMSEARCHReply() is now returning the ST: line as well + starting changes to detect several UPnP devices on the network + +2006/07/19: + using GetCommonLinkProperties to get down/upload bitrate + diff --git a/libs/miniupnpc/LICENSE b/libs/miniupnpc/LICENSE new file mode 100644 index 000000000..2434c86e4 --- /dev/null +++ b/libs/miniupnpc/LICENSE @@ -0,0 +1,27 @@ +MiniUPnPc +Copyright (c) 2005-2011, Thomas BERNARD +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. + * The name of the author may not be used to endorse or promote products + derived from this software without specific prior written permission. + +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 OWNER 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. + diff --git a/libs/miniupnpc/MANIFEST.in b/libs/miniupnpc/MANIFEST.in new file mode 100644 index 000000000..54b86f95e --- /dev/null +++ b/libs/miniupnpc/MANIFEST.in @@ -0,0 +1,5 @@ +include README +include miniupnpcmodule.c +include setup.py +include *.h +include libminiupnpc.a diff --git a/libs/miniupnpc/Makefile b/libs/miniupnpc/Makefile new file mode 100644 index 000000000..2f46e6d19 --- /dev/null +++ b/libs/miniupnpc/Makefile @@ -0,0 +1,214 @@ +# $Id: Makefile,v 1.81 2011/06/21 15:24:14 nanard Exp $ +# MiniUPnP Project +# http://miniupnp.free.fr/ +# (c) 2005-2011 Thomas Bernard +# to install use : +# $ PREFIX=/tmp/dummylocation make install +# or +# $ INSTALLPREFIX=/usr/local make install +# or +# make install (will go to /usr/bin, /usr/lib, etc...) +OS = $(shell uname -s) +CC ?= gcc +#AR = gar +#CFLAGS = -O -Wall -g -DDEBUG +CFLAGS ?= -O -Wall -DNDEBUG -DMINIUPNPC_SET_SOCKET_TIMEOUT -Wstrict-prototypes +# -DNO_GETADDRINFO +INSTALL = install +SH = /bin/sh +JAVA = java +# see http://code.google.com/p/jnaerator/ +JNAERATOR = jnaerator-0.9.3.jar +#following libs are needed on Solaris +#LDLIBS=-lsocket -lnsl -lresolv + +# APIVERSION is used to build SONAME +APIVERSION = 8 + +SRCS = igd_desc_parse.c miniupnpc.c minixml.c minisoap.c miniwget.c \ + upnpc.c upnpcommands.c upnpreplyparse.c testminixml.c \ + minixmlvalid.c testupnpreplyparse.c minissdpc.c \ + upnperrors.c testigddescparse.c testminiwget.c \ + connecthostport.c portlistringparse.c receivedata.c + +LIBOBJS = miniwget.o minixml.o igd_desc_parse.o minisoap.o \ + miniupnpc.o upnpreplyparse.o upnpcommands.o upnperrors.o \ + connecthostport.o portlistingparse.o receivedata.o + +ifneq ($(OS), AmigaOS) +CFLAGS := -fPIC $(CFLAGS) +LIBOBJS := $(LIBOBJS) minissdpc.o +endif + +OBJS = $(patsubst %.c,%.o,$(SRCS)) + +# HEADERS to install +HEADERS = miniupnpc.h miniwget.h upnpcommands.h igd_desc_parse.h \ + upnpreplyparse.h upnperrors.h miniupnpctypes.h \ + portlistingparse.h \ + declspec.h + +# library names +LIBRARY = libminiupnpc.a +ifeq ($(OS), Darwin) + SHAREDLIBRARY = libminiupnpc.dylib + SONAME = $(basename $(SHAREDLIBRARY)).$(APIVERSION).dylib + CFLAGS := -DMACOSX -D_DARWIN_C_SOURCE $(CFLAGS) +else + SHAREDLIBRARY = libminiupnpc.so + SONAME = $(SHAREDLIBRARY).$(APIVERSION) +endif + +EXECUTABLES = upnpc-static +EXECUTABLES_ADDTESTS = testminixml minixmlvalid testupnpreplyparse \ + testigddescparse testminiwget + +TESTMINIXMLOBJS = minixml.o igd_desc_parse.o testminixml.o + +TESTMINIWGETOBJS = miniwget.o testminiwget.o connecthostport.o receivedata.o + +TESTUPNPREPLYPARSE = testupnpreplyparse.o minixml.o upnpreplyparse.o + +TESTIGDDESCPARSE = testigddescparse.o igd_desc_parse.o minixml.o \ + miniupnpc.o miniwget.o upnpcommands.o upnpreplyparse.o \ + minisoap.o connecthostport.o receivedata.o \ + portlistingparse.o + +ifneq ($(OS), AmigaOS) +EXECUTABLES := $(EXECUTABLES) upnpc-shared +TESTMINIWGETOBJS := $(TESTMINIWGETOBJS) minissdpc.o +TESTIGDDESCPARSE := $(TESTIGDDESCPARSE) minissdpc.o +endif + +# install directories +INSTALLPREFIX ?= $(PREFIX)/usr +INSTALLDIRINC = $(INSTALLPREFIX)/include/miniupnpc +INSTALLDIRLIB = $(INSTALLPREFIX)/lib +INSTALLDIRBIN = $(INSTALLPREFIX)/bin + +FILESTOINSTALL = $(LIBRARY) $(EXECUTABLES) +ifneq ($(OS), AmigaOS) +FILESTOINSTALL := $(FILESTOINSTALL) $(SHAREDLIBRARY) +endif + + +.PHONY: install clean depend all check everything \ + installpythonmodule +# validateminixml validateminiwget + +all: $(LIBRARY) $(EXECUTABLES) + +check: validateminixml validateminiwget + +everything: all $(EXECUTABLES_ADDTESTS) + +pythonmodule: $(LIBRARY) miniupnpcmodule.c setup.py + python setup.py build + touch $@ + +installpythonmodule: pythonmodule + python setup.py install + +validateminixml: minixmlvalid + @echo "minixml validation test" + ./minixmlvalid + touch $@ + +validateminiwget: testminiwget minihttptestserver testminiwget.sh + @echo "miniwget validation test" + ./testminiwget.sh + touch $@ + +clean: + $(RM) $(LIBRARY) $(SHAREDLIBRARY) $(EXECUTABLES) $(OBJS) miniupnpcstrings.h + # clean python stuff + $(RM) pythonmodule validateminixml + $(RM) -r build/ dist/ + #python setup.py clean + +install: $(FILESTOINSTALL) + $(INSTALL) -d $(INSTALLDIRINC) + $(INSTALL) -m 644 $(HEADERS) $(INSTALLDIRINC) + $(INSTALL) -d $(INSTALLDIRLIB) + $(INSTALL) -m 644 $(LIBRARY) $(INSTALLDIRLIB) +ifneq ($(OS), AmigaOS) + $(INSTALL) -m 644 $(SHAREDLIBRARY) $(INSTALLDIRLIB)/$(SONAME) + ln -fs $(SONAME) $(INSTALLDIRLIB)/$(SHAREDLIBRARY) +endif + $(INSTALL) -d $(INSTALLDIRBIN) +ifeq ($(OS), AmigaOS) + $(INSTALL) -m 755 upnpc-static $(INSTALLDIRBIN)/upnpc +else + $(INSTALL) -m 755 upnpc-shared $(INSTALLDIRBIN)/upnpc +endif + $(INSTALL) -m 755 external-ip.sh $(INSTALLDIRBIN)/external-ip + +cleaninstall: + $(RM) -r $(INSTALLDIRINC) + $(RM) $(INSTALLDIRLIB)/$(LIBRARY) + $(RM) $(INSTALLDIRLIB)/$(SHAREDLIBRARY) + +depend: + makedepend -Y -- $(CFLAGS) -- $(SRCS) 2>/dev/null + +$(LIBRARY): $(LIBOBJS) + $(AR) crs $@ $? + +$(SHAREDLIBRARY): $(LIBOBJS) +ifeq ($(OS), Darwin) + $(CC) -dynamiclib $(LDFLAGS) -Wl,-install_name,$(SONAME) -o $@ $^ +else + $(CC) -shared $(LDFLAGS) -Wl,-soname,$(SONAME) -o $@ $^ +endif + +upnpc-static: upnpc.o $(LIBRARY) $(LDLIBS) + $(CC) $(LDFLAGS) -o $@ $^ + +upnpc-shared: upnpc.o $(SHAREDLIBRARY) $(LDLIBS) + $(CC) $(LDFLAGS) -o $@ $^ + +testminixml: $(TESTMINIXMLOBJS) + +testminiwget: $(TESTMINIWGETOBJS) + +minixmlvalid: minixml.o minixmlvalid.o + +testupnpreplyparse: $(TESTUPNPREPLYPARSE) + +testigddescparse: $(TESTIGDDESCPARSE) + +miniupnpcstrings.h: miniupnpcstrings.h.in updateminiupnpcstrings.sh + $(SH) updateminiupnpcstrings.sh + +jar: $(SHAREDLIBRARY) + $(JAVA) -jar $(JNAERATOR) -library miniupnpc miniupnpc.h declspec.h upnpcommands.h upnpreplyparse.h igd_desc_parse.h miniwget.h upnperrors.h $(SHAREDLIBRARY) -package fr.free.miniupnp -o . -jar java/miniupnpc_$(OS).jar -v + +minihttptestserver: minihttptestserver.o + +# DO NOT DELETE THIS LINE -- make depend depends on it. + +igd_desc_parse.o: igd_desc_parse.h +miniupnpc.o: miniupnpc.h declspec.h igd_desc_parse.h minissdpc.h miniwget.h +miniupnpc.o: minisoap.h minixml.h upnpcommands.h upnpreplyparse.h +miniupnpc.o: portlistingparse.h miniupnpctypes.h connecthostport.h +miniupnpc.o: receivedata.h +minixml.o: minixml.h +minisoap.o: minisoap.h miniupnpcstrings.h +miniwget.o: miniupnpcstrings.h miniwget.h declspec.h connecthostport.h +miniwget.o: receivedata.h +upnpc.o: miniwget.h declspec.h miniupnpc.h igd_desc_parse.h upnpcommands.h +upnpc.o: upnpreplyparse.h portlistingparse.h miniupnpctypes.h upnperrors.h +upnpcommands.o: upnpcommands.h upnpreplyparse.h portlistingparse.h declspec.h +upnpcommands.o: miniupnpctypes.h miniupnpc.h igd_desc_parse.h +upnpreplyparse.o: upnpreplyparse.h minixml.h +testminixml.o: minixml.h igd_desc_parse.h +minixmlvalid.o: minixml.h +testupnpreplyparse.o: upnpreplyparse.h +minissdpc.o: minissdpc.h miniupnpc.h declspec.h igd_desc_parse.h codelength.h +upnperrors.o: upnperrors.h declspec.h upnpcommands.h upnpreplyparse.h +upnperrors.o: portlistingparse.h miniupnpctypes.h miniupnpc.h +upnperrors.o: igd_desc_parse.h +testigddescparse.o: igd_desc_parse.h minixml.h miniupnpc.h declspec.h +testminiwget.o: miniwget.h declspec.h +connecthostport.o: connecthostport.h +receivedata.o: receivedata.h diff --git a/libs/miniupnpc/Makefile.mingw b/libs/miniupnpc/Makefile.mingw new file mode 100644 index 000000000..2b66211a7 --- /dev/null +++ b/libs/miniupnpc/Makefile.mingw @@ -0,0 +1,93 @@ +# $Id: Makefile.mingw,v 1.16 2011/04/18 17:39:31 nanard Exp $ +# Miniupnp project. +# http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ +# (c) 2005-2011 Thomas Bernard +# This Makefile is made for MinGW +# +CC = gcc +DLLWRAP = dllwrap +#CFLAGS = -Wall -g -DDEBUG -D_WIN32_WINNT=0X501 +CFLAGS = -Wall -Os -DNDEBUG -D_WIN32_WINNT=0X501 +LDLIBS = -lws2_32 -liphlpapi +SH = /bin/sh +# -lwsock32 +# -liphlpapi is used for GetBestRoute() +PYTHON=\utils\python25\python +OBJS=miniwget.o minixml.o igd_desc_parse.o minisoap.o \ + miniupnpc.o upnpreplyparse.o upnpcommands.o upnperrors.o \ + connecthostport.o portlistingparse.o receivedata.o +OBJSDLL=$(addprefix dll/, $(OBJS)) + +all: init upnpc-static upnpc-shared testminixml libminiupnpc.a miniupnpc.dll + +init: + mkdir dll + echo init > init + +clean: + $(RM) upnpc testminixml *.o + $(RM) dll\*.o + $(RM) *.exe + $(RM) miniupnpc.dll + $(RM) libminiupnpc.a + +libminiupnpc.a: $(OBJS) + $(AR) cr $@ $? + +pythonmodule: libminiupnpc.a + $(PYTHON) setupmingw32.py build --compiler=mingw32 + $(PYTHON) setupmingw32.py install --skip-build + +miniupnpc.dll: libminiupnpc.a $(OBJSDLL) + $(DLLWRAP) -k --driver-name "$(CC)" \ + --def miniupnpc.def \ + --output-def miniupnpc.dll.def \ + --implib miniupnpc.lib -o $@ \ + $(OBJSDLL) $(LDLIBS) + +miniupnpc.lib: miniupnpc.dll + echo $@ generated with $< + +dll/upnpc.o: upnpc.o + echo $@ generated with $< + +.c.o: + $(CC) $(CFLAGS) $(CPPFLAGS) -DSTATICLIB -c -o $@ $< + $(CC) $(CFLAGS) $(CPPFLAGS) -DMINIUPNP_EXPORTS -c -o dll/$@ $< + +upnpc.o: + $(CC) $(CFLAGS) $(CPPFLAGS) -DSTATICLIB -c -o $@ $< + $(CC) $(CFLAGS) $(CPPFLAGS) -c -o dll/$@ $< + +upnpc-static: upnpc.o libminiupnpc.a + $(CC) -o $@ $^ $(LDLIBS) + +upnpc-shared: dll/upnpc.o miniupnpc.lib + $(CC) -o $@ $^ $(LDLIBS) + +wingenminiupnpcstrings: wingenminiupnpcstrings.o + +wingenminiupnpcstrings.o: wingenminiupnpcstrings.c + +miniupnpcstrings.h: miniupnpcstrings.h.in wingenminiupnpcstrings + -$(SH) updateminiupnpcstrings.sh + -wingenminiupnpcstrings $< $@ + +minixml.o: minixml.c minixml.h miniupnpcstrings.h + +upnpc.o: upnpc.c miniwget.h minisoap.h miniupnpc.h igd_desc_parse.h upnpreplyparse.h upnpcommands.h upnperrors.h + +miniwget.o: miniwget.c miniwget.h miniupnpcstrings.h connecthostport.h + +minisoap.o: minisoap.c minisoap.h miniupnpcstrings.h + +miniupnpc.o: miniupnpc.c miniupnpc.h minisoap.h miniwget.h minixml.h + +igd_desc_parse.o: igd_desc_parse.c igd_desc_parse.h + +testminixml: minixml.o igd_desc_parse.o testminixml.c + +upnpreplyparse.o: upnpreplyparse.c upnpreplyparse.h minixml.h + +upnpcommands.o: upnpcommands.c upnpcommands.h upnpreplyparse.h miniupnpc.h portlistingparse.h + diff --git a/libs/miniupnpc/README b/libs/miniupnpc/README new file mode 100644 index 000000000..12c7fed35 --- /dev/null +++ b/libs/miniupnpc/README @@ -0,0 +1,59 @@ +Project: miniupnp +Project web page: http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ +Author: Thomas Bernard +Copyright (c) 2005-2011 Thomas Bernard +This software is subject to the conditions detailed in the +LICENSE file provided within this distribution. + +For the comfort of Win32 users, bsdqueue.h is included in the distribution. +Its licence is included in the header of the file. +bsdqueue.h is a copy of the sys/queue.h of an OpenBSD system. + +* miniupnp Client * + +To compile, simply run 'gmake' (could be 'make' on your system). +Under win32, to compile with MinGW, type "mingw32make.bat". +The compilation is known to work under linux, FreeBSD, +OpenBSD, MacOS X, AmigaOS and cygwin. +The official AmigaOS4.1 SDK was used for AmigaOS4 and GeekGadgets for AmigaOS3. +upx (http://upx.sourceforge.net) is used to compress the win32 .exe files. + +To install the library and headers on the system use : +> su +> make install +> exit + +alternatively, to install in a specific location, use : +> INSTALLPREFIX=/usr/local make install + +upnpc.c is a sample client using the libminiupnpc. +To use the libminiupnpc in your application, link it with +libminiupnpc.a (or .so) and use the following functions found in miniupnpc.h, +upnpcommands.h and miniwget.h : +- upnpDiscover() +- miniwget() +- parserootdesc() +- GetUPNPUrls() +- UPNP_* (calling UPNP methods) + +Note : use #include etc... for the includes +and -lminiupnpc for the link + +Discovery process is speeded up when MiniSSDPd is running on the machine. + +* Python module * + +you can build a python module with 'make pythonmodule' +and install it with 'make installpythonmodule'. +setup.py (and setupmingw32.py) are included in the distribution. + + +Feel free to contact me if you have any problem : +e-mail : miniupnp@free.fr + +If you are using libminiupnpc in your application, please +send me an email ! + +For any question, you can use the web forum : +http://miniupnp.tuxfamily.org/forum/ + diff --git a/libs/miniupnpc/VERSION b/libs/miniupnpc/VERSION new file mode 100644 index 000000000..810ee4e91 --- /dev/null +++ b/libs/miniupnpc/VERSION @@ -0,0 +1 @@ +1.6 diff --git a/libs/miniupnpc/bsdqueue.h b/libs/miniupnpc/bsdqueue.h new file mode 100644 index 000000000..1fe0599f5 --- /dev/null +++ b/libs/miniupnpc/bsdqueue.h @@ -0,0 +1,531 @@ +/* $OpenBSD: queue.h,v 1.31 2005/11/25 08:06:25 otto Exp $ */ +/* $NetBSD: queue.h,v 1.11 1996/05/16 05:17:14 mycroft Exp $ */ + +/* + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * 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 the University 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 REGENTS 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 REGENTS 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. + * + * @(#)queue.h 8.5 (Berkeley) 8/20/94 + */ + +#ifndef _SYS_QUEUE_H_ +#define _SYS_QUEUE_H_ + +/* + * This file defines five types of data structures: singly-linked lists, + * lists, simple queues, tail queues, and circular queues. + * + * + * A singly-linked list is headed by a single forward pointer. The elements + * are singly linked for minimum space and pointer manipulation overhead at + * the expense of O(n) removal for arbitrary elements. New elements can be + * added to the list after an existing element or at the head of the list. + * Elements being removed from the head of the list should use the explicit + * macro for this purpose for optimum efficiency. A singly-linked list may + * only be traversed in the forward direction. Singly-linked lists are ideal + * for applications with large datasets and few or no removals or for + * implementing a LIFO queue. + * + * A list is headed by a single forward pointer (or an array of forward + * pointers for a hash table header). The elements are doubly linked + * so that an arbitrary element can be removed without a need to + * traverse the list. New elements can be added to the list before + * or after an existing element or at the head of the list. A list + * may only be traversed in the forward direction. + * + * A simple queue is headed by a pair of pointers, one the head of the + * list and the other to the tail of the list. The elements are singly + * linked to save space, so elements can only be removed from the + * head of the list. New elements can be added to the list before or after + * an existing element, at the head of the list, or at the end of the + * list. A simple queue may only be traversed in the forward direction. + * + * A tail queue is headed by a pair of pointers, one to the head of the + * list and the other to the tail of the list. The elements are doubly + * linked so that an arbitrary element can be removed without a need to + * traverse the list. New elements can be added to the list before or + * after an existing element, at the head of the list, or at the end of + * the list. A tail queue may be traversed in either direction. + * + * A circle queue is headed by a pair of pointers, one to the head of the + * list and the other to the tail of the list. The elements are doubly + * linked so that an arbitrary element can be removed without a need to + * traverse the list. New elements can be added to the list before or after + * an existing element, at the head of the list, or at the end of the list. + * A circle queue may be traversed in either direction, but has a more + * complex end of list detection. + * + * For details on the use of these macros, see the queue(3) manual page. + */ + +#ifdef QUEUE_MACRO_DEBUG +#define _Q_INVALIDATE(a) (a) = ((void *)-1) +#else +#define _Q_INVALIDATE(a) +#endif + +/* + * Singly-linked List definitions. + */ +#define SLIST_HEAD(name, type) \ +struct name { \ + struct type *slh_first; /* first element */ \ +} + +#define SLIST_HEAD_INITIALIZER(head) \ + { NULL } + +#ifdef SLIST_ENTRY +#undef SLIST_ENTRY +#endif + +#define SLIST_ENTRY(type) \ +struct { \ + struct type *sle_next; /* next element */ \ +} + +/* + * Singly-linked List access methods. + */ +#define SLIST_FIRST(head) ((head)->slh_first) +#define SLIST_END(head) NULL +#define SLIST_EMPTY(head) (SLIST_FIRST(head) == SLIST_END(head)) +#define SLIST_NEXT(elm, field) ((elm)->field.sle_next) + +#define SLIST_FOREACH(var, head, field) \ + for((var) = SLIST_FIRST(head); \ + (var) != SLIST_END(head); \ + (var) = SLIST_NEXT(var, field)) + +#define SLIST_FOREACH_PREVPTR(var, varp, head, field) \ + for ((varp) = &SLIST_FIRST((head)); \ + ((var) = *(varp)) != SLIST_END(head); \ + (varp) = &SLIST_NEXT((var), field)) + +/* + * Singly-linked List functions. + */ +#define SLIST_INIT(head) { \ + SLIST_FIRST(head) = SLIST_END(head); \ +} + +#define SLIST_INSERT_AFTER(slistelm, elm, field) do { \ + (elm)->field.sle_next = (slistelm)->field.sle_next; \ + (slistelm)->field.sle_next = (elm); \ +} while (0) + +#define SLIST_INSERT_HEAD(head, elm, field) do { \ + (elm)->field.sle_next = (head)->slh_first; \ + (head)->slh_first = (elm); \ +} while (0) + +#define SLIST_REMOVE_NEXT(head, elm, field) do { \ + (elm)->field.sle_next = (elm)->field.sle_next->field.sle_next; \ +} while (0) + +#define SLIST_REMOVE_HEAD(head, field) do { \ + (head)->slh_first = (head)->slh_first->field.sle_next; \ +} while (0) + +#define SLIST_REMOVE(head, elm, type, field) do { \ + if ((head)->slh_first == (elm)) { \ + SLIST_REMOVE_HEAD((head), field); \ + } else { \ + struct type *curelm = (head)->slh_first; \ + \ + while (curelm->field.sle_next != (elm)) \ + curelm = curelm->field.sle_next; \ + curelm->field.sle_next = \ + curelm->field.sle_next->field.sle_next; \ + _Q_INVALIDATE((elm)->field.sle_next); \ + } \ +} while (0) + +/* + * List definitions. + */ +#define LIST_HEAD(name, type) \ +struct name { \ + struct type *lh_first; /* first element */ \ +} + +#define LIST_HEAD_INITIALIZER(head) \ + { NULL } + +#define LIST_ENTRY(type) \ +struct { \ + struct type *le_next; /* next element */ \ + struct type **le_prev; /* address of previous next element */ \ +} + +/* + * List access methods + */ +#define LIST_FIRST(head) ((head)->lh_first) +#define LIST_END(head) NULL +#define LIST_EMPTY(head) (LIST_FIRST(head) == LIST_END(head)) +#define LIST_NEXT(elm, field) ((elm)->field.le_next) + +#define LIST_FOREACH(var, head, field) \ + for((var) = LIST_FIRST(head); \ + (var)!= LIST_END(head); \ + (var) = LIST_NEXT(var, field)) + +/* + * List functions. + */ +#define LIST_INIT(head) do { \ + LIST_FIRST(head) = LIST_END(head); \ +} while (0) + +#define LIST_INSERT_AFTER(listelm, elm, field) do { \ + if (((elm)->field.le_next = (listelm)->field.le_next) != NULL) \ + (listelm)->field.le_next->field.le_prev = \ + &(elm)->field.le_next; \ + (listelm)->field.le_next = (elm); \ + (elm)->field.le_prev = &(listelm)->field.le_next; \ +} while (0) + +#define LIST_INSERT_BEFORE(listelm, elm, field) do { \ + (elm)->field.le_prev = (listelm)->field.le_prev; \ + (elm)->field.le_next = (listelm); \ + *(listelm)->field.le_prev = (elm); \ + (listelm)->field.le_prev = &(elm)->field.le_next; \ +} while (0) + +#define LIST_INSERT_HEAD(head, elm, field) do { \ + if (((elm)->field.le_next = (head)->lh_first) != NULL) \ + (head)->lh_first->field.le_prev = &(elm)->field.le_next;\ + (head)->lh_first = (elm); \ + (elm)->field.le_prev = &(head)->lh_first; \ +} while (0) + +#define LIST_REMOVE(elm, field) do { \ + if ((elm)->field.le_next != NULL) \ + (elm)->field.le_next->field.le_prev = \ + (elm)->field.le_prev; \ + *(elm)->field.le_prev = (elm)->field.le_next; \ + _Q_INVALIDATE((elm)->field.le_prev); \ + _Q_INVALIDATE((elm)->field.le_next); \ +} while (0) + +#define LIST_REPLACE(elm, elm2, field) do { \ + if (((elm2)->field.le_next = (elm)->field.le_next) != NULL) \ + (elm2)->field.le_next->field.le_prev = \ + &(elm2)->field.le_next; \ + (elm2)->field.le_prev = (elm)->field.le_prev; \ + *(elm2)->field.le_prev = (elm2); \ + _Q_INVALIDATE((elm)->field.le_prev); \ + _Q_INVALIDATE((elm)->field.le_next); \ +} while (0) + +/* + * Simple queue definitions. + */ +#define SIMPLEQ_HEAD(name, type) \ +struct name { \ + struct type *sqh_first; /* first element */ \ + struct type **sqh_last; /* addr of last next element */ \ +} + +#define SIMPLEQ_HEAD_INITIALIZER(head) \ + { NULL, &(head).sqh_first } + +#define SIMPLEQ_ENTRY(type) \ +struct { \ + struct type *sqe_next; /* next element */ \ +} + +/* + * Simple queue access methods. + */ +#define SIMPLEQ_FIRST(head) ((head)->sqh_first) +#define SIMPLEQ_END(head) NULL +#define SIMPLEQ_EMPTY(head) (SIMPLEQ_FIRST(head) == SIMPLEQ_END(head)) +#define SIMPLEQ_NEXT(elm, field) ((elm)->field.sqe_next) + +#define SIMPLEQ_FOREACH(var, head, field) \ + for((var) = SIMPLEQ_FIRST(head); \ + (var) != SIMPLEQ_END(head); \ + (var) = SIMPLEQ_NEXT(var, field)) + +/* + * Simple queue functions. + */ +#define SIMPLEQ_INIT(head) do { \ + (head)->sqh_first = NULL; \ + (head)->sqh_last = &(head)->sqh_first; \ +} while (0) + +#define SIMPLEQ_INSERT_HEAD(head, elm, field) do { \ + if (((elm)->field.sqe_next = (head)->sqh_first) == NULL) \ + (head)->sqh_last = &(elm)->field.sqe_next; \ + (head)->sqh_first = (elm); \ +} while (0) + +#define SIMPLEQ_INSERT_TAIL(head, elm, field) do { \ + (elm)->field.sqe_next = NULL; \ + *(head)->sqh_last = (elm); \ + (head)->sqh_last = &(elm)->field.sqe_next; \ +} while (0) + +#define SIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do { \ + if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL)\ + (head)->sqh_last = &(elm)->field.sqe_next; \ + (listelm)->field.sqe_next = (elm); \ +} while (0) + +#define SIMPLEQ_REMOVE_HEAD(head, field) do { \ + if (((head)->sqh_first = (head)->sqh_first->field.sqe_next) == NULL) \ + (head)->sqh_last = &(head)->sqh_first; \ +} while (0) + +/* + * Tail queue definitions. + */ +#define TAILQ_HEAD(name, type) \ +struct name { \ + struct type *tqh_first; /* first element */ \ + struct type **tqh_last; /* addr of last next element */ \ +} + +#define TAILQ_HEAD_INITIALIZER(head) \ + { NULL, &(head).tqh_first } + +#define TAILQ_ENTRY(type) \ +struct { \ + struct type *tqe_next; /* next element */ \ + struct type **tqe_prev; /* address of previous next element */ \ +} + +/* + * tail queue access methods + */ +#define TAILQ_FIRST(head) ((head)->tqh_first) +#define TAILQ_END(head) NULL +#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next) +#define TAILQ_LAST(head, headname) \ + (*(((struct headname *)((head)->tqh_last))->tqh_last)) +/* XXX */ +#define TAILQ_PREV(elm, headname, field) \ + (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last)) +#define TAILQ_EMPTY(head) \ + (TAILQ_FIRST(head) == TAILQ_END(head)) + +#define TAILQ_FOREACH(var, head, field) \ + for((var) = TAILQ_FIRST(head); \ + (var) != TAILQ_END(head); \ + (var) = TAILQ_NEXT(var, field)) + +#define TAILQ_FOREACH_REVERSE(var, head, headname, field) \ + for((var) = TAILQ_LAST(head, headname); \ + (var) != TAILQ_END(head); \ + (var) = TAILQ_PREV(var, headname, field)) + +/* + * Tail queue functions. + */ +#define TAILQ_INIT(head) do { \ + (head)->tqh_first = NULL; \ + (head)->tqh_last = &(head)->tqh_first; \ +} while (0) + +#define TAILQ_INSERT_HEAD(head, elm, field) do { \ + if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \ + (head)->tqh_first->field.tqe_prev = \ + &(elm)->field.tqe_next; \ + else \ + (head)->tqh_last = &(elm)->field.tqe_next; \ + (head)->tqh_first = (elm); \ + (elm)->field.tqe_prev = &(head)->tqh_first; \ +} while (0) + +#define TAILQ_INSERT_TAIL(head, elm, field) do { \ + (elm)->field.tqe_next = NULL; \ + (elm)->field.tqe_prev = (head)->tqh_last; \ + *(head)->tqh_last = (elm); \ + (head)->tqh_last = &(elm)->field.tqe_next; \ +} while (0) + +#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \ + if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\ + (elm)->field.tqe_next->field.tqe_prev = \ + &(elm)->field.tqe_next; \ + else \ + (head)->tqh_last = &(elm)->field.tqe_next; \ + (listelm)->field.tqe_next = (elm); \ + (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \ +} while (0) + +#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \ + (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \ + (elm)->field.tqe_next = (listelm); \ + *(listelm)->field.tqe_prev = (elm); \ + (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \ +} while (0) + +#define TAILQ_REMOVE(head, elm, field) do { \ + if (((elm)->field.tqe_next) != NULL) \ + (elm)->field.tqe_next->field.tqe_prev = \ + (elm)->field.tqe_prev; \ + else \ + (head)->tqh_last = (elm)->field.tqe_prev; \ + *(elm)->field.tqe_prev = (elm)->field.tqe_next; \ + _Q_INVALIDATE((elm)->field.tqe_prev); \ + _Q_INVALIDATE((elm)->field.tqe_next); \ +} while (0) + +#define TAILQ_REPLACE(head, elm, elm2, field) do { \ + if (((elm2)->field.tqe_next = (elm)->field.tqe_next) != NULL) \ + (elm2)->field.tqe_next->field.tqe_prev = \ + &(elm2)->field.tqe_next; \ + else \ + (head)->tqh_last = &(elm2)->field.tqe_next; \ + (elm2)->field.tqe_prev = (elm)->field.tqe_prev; \ + *(elm2)->field.tqe_prev = (elm2); \ + _Q_INVALIDATE((elm)->field.tqe_prev); \ + _Q_INVALIDATE((elm)->field.tqe_next); \ +} while (0) + +/* + * Circular queue definitions. + */ +#define CIRCLEQ_HEAD(name, type) \ +struct name { \ + struct type *cqh_first; /* first element */ \ + struct type *cqh_last; /* last element */ \ +} + +#define CIRCLEQ_HEAD_INITIALIZER(head) \ + { CIRCLEQ_END(&head), CIRCLEQ_END(&head) } + +#define CIRCLEQ_ENTRY(type) \ +struct { \ + struct type *cqe_next; /* next element */ \ + struct type *cqe_prev; /* previous element */ \ +} + +/* + * Circular queue access methods + */ +#define CIRCLEQ_FIRST(head) ((head)->cqh_first) +#define CIRCLEQ_LAST(head) ((head)->cqh_last) +#define CIRCLEQ_END(head) ((void *)(head)) +#define CIRCLEQ_NEXT(elm, field) ((elm)->field.cqe_next) +#define CIRCLEQ_PREV(elm, field) ((elm)->field.cqe_prev) +#define CIRCLEQ_EMPTY(head) \ + (CIRCLEQ_FIRST(head) == CIRCLEQ_END(head)) + +#define CIRCLEQ_FOREACH(var, head, field) \ + for((var) = CIRCLEQ_FIRST(head); \ + (var) != CIRCLEQ_END(head); \ + (var) = CIRCLEQ_NEXT(var, field)) + +#define CIRCLEQ_FOREACH_REVERSE(var, head, field) \ + for((var) = CIRCLEQ_LAST(head); \ + (var) != CIRCLEQ_END(head); \ + (var) = CIRCLEQ_PREV(var, field)) + +/* + * Circular queue functions. + */ +#define CIRCLEQ_INIT(head) do { \ + (head)->cqh_first = CIRCLEQ_END(head); \ + (head)->cqh_last = CIRCLEQ_END(head); \ +} while (0) + +#define CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do { \ + (elm)->field.cqe_next = (listelm)->field.cqe_next; \ + (elm)->field.cqe_prev = (listelm); \ + if ((listelm)->field.cqe_next == CIRCLEQ_END(head)) \ + (head)->cqh_last = (elm); \ + else \ + (listelm)->field.cqe_next->field.cqe_prev = (elm); \ + (listelm)->field.cqe_next = (elm); \ +} while (0) + +#define CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do { \ + (elm)->field.cqe_next = (listelm); \ + (elm)->field.cqe_prev = (listelm)->field.cqe_prev; \ + if ((listelm)->field.cqe_prev == CIRCLEQ_END(head)) \ + (head)->cqh_first = (elm); \ + else \ + (listelm)->field.cqe_prev->field.cqe_next = (elm); \ + (listelm)->field.cqe_prev = (elm); \ +} while (0) + +#define CIRCLEQ_INSERT_HEAD(head, elm, field) do { \ + (elm)->field.cqe_next = (head)->cqh_first; \ + (elm)->field.cqe_prev = CIRCLEQ_END(head); \ + if ((head)->cqh_last == CIRCLEQ_END(head)) \ + (head)->cqh_last = (elm); \ + else \ + (head)->cqh_first->field.cqe_prev = (elm); \ + (head)->cqh_first = (elm); \ +} while (0) + +#define CIRCLEQ_INSERT_TAIL(head, elm, field) do { \ + (elm)->field.cqe_next = CIRCLEQ_END(head); \ + (elm)->field.cqe_prev = (head)->cqh_last; \ + if ((head)->cqh_first == CIRCLEQ_END(head)) \ + (head)->cqh_first = (elm); \ + else \ + (head)->cqh_last->field.cqe_next = (elm); \ + (head)->cqh_last = (elm); \ +} while (0) + +#define CIRCLEQ_REMOVE(head, elm, field) do { \ + if ((elm)->field.cqe_next == CIRCLEQ_END(head)) \ + (head)->cqh_last = (elm)->field.cqe_prev; \ + else \ + (elm)->field.cqe_next->field.cqe_prev = \ + (elm)->field.cqe_prev; \ + if ((elm)->field.cqe_prev == CIRCLEQ_END(head)) \ + (head)->cqh_first = (elm)->field.cqe_next; \ + else \ + (elm)->field.cqe_prev->field.cqe_next = \ + (elm)->field.cqe_next; \ + _Q_INVALIDATE((elm)->field.cqe_prev); \ + _Q_INVALIDATE((elm)->field.cqe_next); \ +} while (0) + +#define CIRCLEQ_REPLACE(head, elm, elm2, field) do { \ + if (((elm2)->field.cqe_next = (elm)->field.cqe_next) == \ + CIRCLEQ_END(head)) \ + (head).cqh_last = (elm2); \ + else \ + (elm2)->field.cqe_next->field.cqe_prev = (elm2); \ + if (((elm2)->field.cqe_prev = (elm)->field.cqe_prev) == \ + CIRCLEQ_END(head)) \ + (head).cqh_first = (elm2); \ + else \ + (elm2)->field.cqe_prev->field.cqe_next = (elm2); \ + _Q_INVALIDATE((elm)->field.cqe_prev); \ + _Q_INVALIDATE((elm)->field.cqe_next); \ +} while (0) + +#endif /* !_SYS_QUEUE_H_ */ diff --git a/libs/miniupnpc/codelength.h b/libs/miniupnpc/codelength.h new file mode 100644 index 000000000..f11e5e936 --- /dev/null +++ b/libs/miniupnpc/codelength.h @@ -0,0 +1,24 @@ +/* $Id: codelength.h,v 1.1 2008/10/06 22:04:06 nanard Exp $ */ +/* Project : miniupnp + * Author : Thomas BERNARD + * copyright (c) 2005-2008 Thomas Bernard + * This software is subjet to the conditions detailed in the + * provided LICENCE file. */ +#ifndef __CODELENGTH_H__ +#define __CODELENGTH_H__ + +/* Encode length by using 7bit per Byte : + * Most significant bit of each byte specifies that the + * following byte is part of the code */ +#define DECODELENGTH(n, p) n = 0; \ + do { n = (n << 7) | (*p & 0x7f); } \ + while(*(p++)&0x80); + +#define CODELENGTH(n, p) if(n>=268435456) *(p++) = (n >> 28) | 0x80; \ + if(n>=2097152) *(p++) = (n >> 21) | 0x80; \ + if(n>=16384) *(p++) = (n >> 14) | 0x80; \ + if(n>=128) *(p++) = (n >> 7) | 0x80; \ + *(p++) = n & 0x7f; + +#endif + diff --git a/libs/miniupnpc/connecthostport.c b/libs/miniupnpc/connecthostport.c new file mode 100644 index 000000000..76e8e374b --- /dev/null +++ b/libs/miniupnpc/connecthostport.c @@ -0,0 +1,241 @@ +/* $Id: connecthostport.c,v 1.5 2011/04/09 08:49:50 nanard Exp $ */ +/* Project : miniupnp + * Author : Thomas Bernard + * Copyright (c) 2010-2011 Thomas Bernard + * This software is subject to the conditions detailed in the + * LICENCE file provided in this distribution. */ + +/* use getaddrinfo() or gethostbyname() + * uncomment the following line in order to use gethostbyname() */ +#ifdef NO_GETADDRINFO +#define USE_GETHOSTBYNAME +#endif + +#include +#include +#ifdef WIN32 +#include +#include +#include +#define MAXHOSTNAMELEN 64 +#define snprintf _snprintf +#define herror +#define socklen_t int +#else /* #ifdef WIN32 */ +#include +#include +#include +#define closesocket close +#include +/* defining MINIUPNPC_IGNORE_EINTR enable the ignore of interruptions + * during the connect() call */ +#define MINIUPNPC_IGNORE_EINTR +#ifndef USE_GETHOSTBYNAME +#include +#include +#endif /* #ifndef USE_GETHOSTBYNAME */ +#endif /* #else WIN32 */ + +/* definition of PRINT_SOCKET_ERROR */ +#ifdef WIN32 +#define PRINT_SOCKET_ERROR(x) printf("Socket error: %s, %d\n", x, WSAGetLastError()); +#else +#define PRINT_SOCKET_ERROR(x) perror(x) +#endif + +#if defined(__amigaos__) || defined(__amigaos4__) +#define herror(A) printf("%s\n", A) +#endif + +#include "connecthostport.h" + +/* connecthostport() + * return a socket connected (TCP) to the host and port + * or -1 in case of error */ +int connecthostport(const char * host, unsigned short port) +{ + int s, n; +#ifdef USE_GETHOSTBYNAME + struct sockaddr_in dest; + struct hostent *hp; +#else /* #ifdef USE_GETHOSTBYNAME */ + char tmp_host[MAXHOSTNAMELEN+1]; + char port_str[8]; + struct addrinfo *ai, *p; + struct addrinfo hints; +#endif /* #ifdef USE_GETHOSTBYNAME */ +#ifdef MINIUPNPC_SET_SOCKET_TIMEOUT + struct timeval timeout; +#endif /* #ifdef MINIUPNPC_SET_SOCKET_TIMEOUT */ + +#ifdef USE_GETHOSTBYNAME + hp = gethostbyname(host); + if(hp == NULL) + { + herror(host); + return -1; + } + memcpy(&dest.sin_addr, hp->h_addr, sizeof(dest.sin_addr)); + memset(dest.sin_zero, 0, sizeof(dest.sin_zero)); + s = socket(PF_INET, SOCK_STREAM, 0); + if(s < 0) + { + PRINT_SOCKET_ERROR("socket"); + return -1; + } +#ifdef MINIUPNPC_SET_SOCKET_TIMEOUT + /* setting a 3 seconds timeout for the connect() call */ + timeout.tv_sec = 3; + timeout.tv_usec = 0; + if(setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(struct timeval)) < 0) + { + PRINT_SOCKET_ERROR("setsockopt"); + } + timeout.tv_sec = 3; + timeout.tv_usec = 0; + if(setsockopt(s, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(struct timeval)) < 0) + { + PRINT_SOCKET_ERROR("setsockopt"); + } +#endif /* #ifdef MINIUPNPC_SET_SOCKET_TIMEOUT */ + dest.sin_family = AF_INET; + dest.sin_port = htons(port); + n = connect(s, (struct sockaddr *)&dest, sizeof(struct sockaddr_in)); +#ifdef MINIUPNPC_IGNORE_EINTR + while(n < 0 && errno == EINTR) + { + socklen_t len; + fd_set wset; + int err; + FD_ZERO(&wset); + FD_SET(s, &wset); + if((n = select(s + 1, NULL, &wset, NULL, NULL)) == -1 && errno == EINTR) + continue; + /*len = 0;*/ + /*n = getpeername(s, NULL, &len);*/ + len = sizeof(err); + if(getsockopt(s, SOL_SOCKET, SO_ERROR, &err, &len) < 0) { + PRINT_SOCKET_ERROR("getsockopt"); + closesocket(s); + return -1; + } + if(err != 0) { + errno = err; + n = -1; + } + } +#endif /* #ifdef MINIUPNPC_IGNORE_EINTR */ + if(n<0) + { + PRINT_SOCKET_ERROR("connect"); + closesocket(s); + return -1; + } +#else /* #ifdef USE_GETHOSTBYNAME */ + /* use getaddrinfo() instead of gethostbyname() */ + memset(&hints, 0, sizeof(hints)); + /* hints.ai_flags = AI_ADDRCONFIG; */ +#ifdef AI_NUMERICSERV + hints.ai_flags = AI_NUMERICSERV; +#endif + hints.ai_socktype = SOCK_STREAM; + hints.ai_family = AF_UNSPEC; /* AF_INET, AF_INET6 or AF_UNSPEC */ + /* hints.ai_protocol = IPPROTO_TCP; */ + snprintf(port_str, sizeof(port_str), "%hu", port); + if(host[0] == '[') + { + /* literal ip v6 address */ + int i; + for(i = 0; host[i+1] && (host[i+1] != ']') && i < MAXHOSTNAMELEN; i++) + { + tmp_host[i] = host[i+1]; + } + tmp_host[i] = '\0'; + } + else + { + strncpy(tmp_host, host, MAXHOSTNAMELEN); + } + tmp_host[MAXHOSTNAMELEN] = '\0'; + n = getaddrinfo(tmp_host, port_str, &hints, &ai); + if(n != 0) + { +#ifdef WIN32 + fprintf(stderr, "getaddrinfo() error : %d\n", n); +#else + fprintf(stderr, "getaddrinfo() error : %s\n", gai_strerror(n)); +#endif + return -1; + } + s = -1; + for(p = ai; p; p = p->ai_next) + { + s = socket(p->ai_family, p->ai_socktype, p->ai_protocol); + if(s < 0) + continue; +#ifdef MINIUPNPC_SET_SOCKET_TIMEOUT + /* setting a 3 seconds timeout for the connect() call */ + timeout.tv_sec = 3; + timeout.tv_usec = 0; + if(setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(struct timeval)) < 0) + { + PRINT_SOCKET_ERROR("setsockopt"); + } + timeout.tv_sec = 3; + timeout.tv_usec = 0; + if(setsockopt(s, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(struct timeval)) < 0) + { + PRINT_SOCKET_ERROR("setsockopt"); + } +#endif /* #ifdef MINIUPNPC_SET_SOCKET_TIMEOUT */ + n = connect(s, p->ai_addr, p->ai_addrlen); +#ifdef MINIUPNPC_IGNORE_EINTR + while(n < 0 && errno == EINTR) + { + socklen_t len; + fd_set wset; + int err; + FD_ZERO(&wset); + FD_SET(s, &wset); + if((n = select(s + 1, NULL, &wset, NULL, NULL)) == -1 && errno == EINTR) + continue; + /*len = 0;*/ + /*n = getpeername(s, NULL, &len);*/ + len = sizeof(err); + if(getsockopt(s, SOL_SOCKET, SO_ERROR, &err, &len) < 0) { + PRINT_SOCKET_ERROR("getsockopt"); + closesocket(s); + freeaddrinfo(ai); + return -1; + } + if(err != 0) { + errno = err; + n = -1; + } + } +#endif /* #ifdef MINIUPNPC_IGNORE_EINTR */ + if(n < 0) + { + closesocket(s); + continue; + } + else + { + break; + } + } + freeaddrinfo(ai); + if(s < 0) + { + PRINT_SOCKET_ERROR("socket"); + return -1; + } + if(n < 0) + { + PRINT_SOCKET_ERROR("connect"); + return -1; + } +#endif /* #ifdef USE_GETHOSTBYNAME */ + return s; +} + diff --git a/libs/miniupnpc/connecthostport.h b/libs/miniupnpc/connecthostport.h new file mode 100644 index 000000000..57e24eb27 --- /dev/null +++ b/libs/miniupnpc/connecthostport.h @@ -0,0 +1,17 @@ +/* $Id: connecthostport.h,v 1.1 2010/04/04 23:21:03 nanard Exp $ */ +/* Project: miniupnp + * http://miniupnp.free.fr/ + * Author: Thomas Bernard + * Copyright (c) 2010 Thomas Bernard + * This software is subjects to the conditions detailed + * in the LICENCE file provided within this distribution */ +#ifndef __CONNECTHOSTPORT_H__ +#define __CONNECTHOSTPORT_H__ + +/* connecthostport() + * return a socket connected (TCP) to the host and port + * or -1 in case of error */ +int connecthostport(const char * host, unsigned short port); + +#endif + diff --git a/libs/miniupnpc/declspec.h b/libs/miniupnpc/declspec.h new file mode 100644 index 000000000..b804247d2 --- /dev/null +++ b/libs/miniupnpc/declspec.h @@ -0,0 +1,15 @@ +#ifndef __DECLSPEC_H__ +#define __DECLSPEC_H__ + +#if defined(WIN32) && !defined(STATICLIB) + #ifdef MINIUPNP_EXPORTS + #define LIBSPEC __declspec(dllexport) + #else + #define LIBSPEC __declspec(dllimport) + #endif +#else + #define LIBSPEC +#endif + +#endif + diff --git a/libs/miniupnpc/external-ip.sh b/libs/miniupnpc/external-ip.sh new file mode 100755 index 000000000..965d86b2a --- /dev/null +++ b/libs/miniupnpc/external-ip.sh @@ -0,0 +1,4 @@ +#!/bin/sh +# $Id: external-ip.sh,v 1.1 2010/08/05 12:57:41 nanard Exp $ +# (c) 2010 Reuben Hawkins +upnpc -s | grep ExternalIPAddress | sed 's/[^0-9\.]//g' diff --git a/libs/miniupnpc/igd_desc_parse.c b/libs/miniupnpc/igd_desc_parse.c new file mode 100644 index 000000000..6c3e65677 --- /dev/null +++ b/libs/miniupnpc/igd_desc_parse.c @@ -0,0 +1,125 @@ +/* $Id: igd_desc_parse.c,v 1.14 2011/04/11 09:19:24 nanard Exp $ */ +/* Project : miniupnp + * http://miniupnp.free.fr/ + * Author : Thomas Bernard + * Copyright (c) 2005-2010 Thomas Bernard + * This software is subject to the conditions detailed in the + * LICENCE file provided in this distribution. */ + +#include "igd_desc_parse.h" +#include +#include + +/* Start element handler : + * update nesting level counter and copy element name */ +void IGDstartelt(void * d, const char * name, int l) +{ + struct IGDdatas * datas = (struct IGDdatas *)d; + memcpy( datas->cureltname, name, l); + datas->cureltname[l] = '\0'; + datas->level++; + if( (l==7) && !memcmp(name, "service", l) ) { + datas->tmp.controlurl[0] = '\0'; + datas->tmp.eventsuburl[0] = '\0'; + datas->tmp.scpdurl[0] = '\0'; + datas->tmp.servicetype[0] = '\0'; + } +} + +/* End element handler : + * update nesting level counter and update parser state if + * service element is parsed */ +void IGDendelt(void * d, const char * name, int l) +{ + struct IGDdatas * datas = (struct IGDdatas *)d; + datas->level--; + /*printf("endelt %2d %.*s\n", datas->level, l, name);*/ + if( (l==7) && !memcmp(name, "service", l) ) + { + /* + if( datas->state < 1 + && !strcmp(datas->servicetype, + // "urn:schemas-upnp-org:service:WANIPConnection:1") ) + "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1")) + datas->state ++; + */ + if(0==strcmp(datas->tmp.servicetype, + "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1")) { + memcpy(&datas->CIF, &datas->tmp, sizeof(struct IGDdatas_service)); + } else if(0==strcmp(datas->tmp.servicetype, + "urn:schemas-upnp-org:service:WANIPv6FirewallControl:1")) { + memcpy(&datas->IPv6FC, &datas->tmp, sizeof(struct IGDdatas_service)); + } else if(0==strcmp(datas->tmp.servicetype, + "urn:schemas-upnp-org:service:WANIPConnection:1") + || 0==strcmp(datas->tmp.servicetype, + "urn:schemas-upnp-org:service:WANPPPConnection:1") ) { + if(datas->first.servicetype[0] == '\0') { + memcpy(&datas->first, &datas->tmp, sizeof(struct IGDdatas_service)); + } else { + memcpy(&datas->second, &datas->tmp, sizeof(struct IGDdatas_service)); + } + } + } +} + +/* Data handler : + * copy data depending on the current element name and state */ +void IGDdata(void * d, const char * data, int l) +{ + struct IGDdatas * datas = (struct IGDdatas *)d; + char * dstmember = 0; + /*printf("%2d %s : %.*s\n", + datas->level, datas->cureltname, l, data); */ + if( !strcmp(datas->cureltname, "URLBase") ) + dstmember = datas->urlbase; + else if( !strcmp(datas->cureltname, "presentationURL") ) + dstmember = datas->presentationurl; + else if( !strcmp(datas->cureltname, "serviceType") ) + dstmember = datas->tmp.servicetype; + else if( !strcmp(datas->cureltname, "controlURL") ) + dstmember = datas->tmp.controlurl; + else if( !strcmp(datas->cureltname, "eventSubURL") ) + dstmember = datas->tmp.eventsuburl; + else if( !strcmp(datas->cureltname, "SCPDURL") ) + dstmember = datas->tmp.scpdurl; +/* else if( !strcmp(datas->cureltname, "deviceType") ) + dstmember = datas->devicetype_tmp;*/ + if(dstmember) + { + if(l>=MINIUPNPC_URL_MAXSIZE) + l = MINIUPNPC_URL_MAXSIZE-1; + memcpy(dstmember, data, l); + dstmember[l] = '\0'; + } +} + +void printIGD(struct IGDdatas * d) +{ + printf("urlbase = '%s'\n", d->urlbase); + printf("WAN Device (Common interface config) :\n"); + /*printf(" deviceType = '%s'\n", d->CIF.devicetype);*/ + printf(" serviceType = '%s'\n", d->CIF.servicetype); + printf(" controlURL = '%s'\n", d->CIF.controlurl); + printf(" eventSubURL = '%s'\n", d->CIF.eventsuburl); + printf(" SCPDURL = '%s'\n", d->CIF.scpdurl); + printf("primary WAN Connection Device (IP or PPP Connection):\n"); + /*printf(" deviceType = '%s'\n", d->first.devicetype);*/ + printf(" servicetype = '%s'\n", d->first.servicetype); + printf(" controlURL = '%s'\n", d->first.controlurl); + printf(" eventSubURL = '%s'\n", d->first.eventsuburl); + printf(" SCPDURL = '%s'\n", d->first.scpdurl); + printf("secondary WAN Connection Device (IP or PPP Connection):\n"); + /*printf(" deviceType = '%s'\n", d->second.devicetype);*/ + printf(" servicetype = '%s'\n", d->second.servicetype); + printf(" controlURL = '%s'\n", d->second.controlurl); + printf(" eventSubURL = '%s'\n", d->second.eventsuburl); + printf(" SCPDURL = '%s'\n", d->second.scpdurl); + printf("WAN IPv6 Firewall Control :\n"); + /*printf(" deviceType = '%s'\n", d->IPv6FC.devicetype);*/ + printf(" servicetype = '%s'\n", d->IPv6FC.servicetype); + printf(" controlURL = '%s'\n", d->IPv6FC.controlurl); + printf(" eventSubURL = '%s'\n", d->IPv6FC.eventsuburl); + printf(" SCPDURL = '%s'\n", d->IPv6FC.scpdurl); +} + + diff --git a/libs/miniupnpc/igd_desc_parse.h b/libs/miniupnpc/igd_desc_parse.h new file mode 100644 index 000000000..bab1fd56f --- /dev/null +++ b/libs/miniupnpc/igd_desc_parse.h @@ -0,0 +1,48 @@ +/* $Id: igd_desc_parse.h,v 1.10 2011/04/11 09:19:24 nanard Exp $ */ +/* Project : miniupnp + * http://miniupnp.free.fr/ + * Author : Thomas Bernard + * Copyright (c) 2005-2010 Thomas Bernard + * This software is subject to the conditions detailed in the + * LICENCE file provided in this distribution. + * */ +#ifndef __IGD_DESC_PARSE_H__ +#define __IGD_DESC_PARSE_H__ + +/* Structure to store the result of the parsing of UPnP + * descriptions of Internet Gateway Devices */ +#define MINIUPNPC_URL_MAXSIZE (128) +struct IGDdatas_service { + char controlurl[MINIUPNPC_URL_MAXSIZE]; + char eventsuburl[MINIUPNPC_URL_MAXSIZE]; + char scpdurl[MINIUPNPC_URL_MAXSIZE]; + char servicetype[MINIUPNPC_URL_MAXSIZE]; + /*char devicetype[MINIUPNPC_URL_MAXSIZE];*/ +}; + +struct IGDdatas { + char cureltname[MINIUPNPC_URL_MAXSIZE]; + char urlbase[MINIUPNPC_URL_MAXSIZE]; + char presentationurl[MINIUPNPC_URL_MAXSIZE]; + int level; + /*int state;*/ + /* "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1" */ + struct IGDdatas_service CIF; + /* "urn:schemas-upnp-org:service:WANIPConnection:1" + * "urn:schemas-upnp-org:service:WANPPPConnection:1" */ + struct IGDdatas_service first; + /* if both WANIPConnection and WANPPPConnection are present */ + struct IGDdatas_service second; + /* "urn:schemas-upnp-org:service:WANIPv6FirewallControl:1" */ + struct IGDdatas_service IPv6FC; + /* tmp */ + struct IGDdatas_service tmp; +}; + +void IGDstartelt(void *, const char *, int); +void IGDendelt(void *, const char *, int); +void IGDdata(void *, const char *, int); +void printIGD(struct IGDdatas *); + +#endif + diff --git a/libs/miniupnpc/java/JavaBridgeTest.java b/libs/miniupnpc/java/JavaBridgeTest.java new file mode 100644 index 000000000..62bba345c --- /dev/null +++ b/libs/miniupnpc/java/JavaBridgeTest.java @@ -0,0 +1,95 @@ +import java.nio.ByteBuffer; +import fr.free.miniupnp.*; + +/** + * + * @author syuu + */ +public class JavaBridgeTest { + public static void main(String[] args) { + int UPNP_DELAY = 2000; + MiniupnpcLibrary miniupnpc = MiniupnpcLibrary.INSTANCE; + UPNPDev devlist = null; + UPNPUrls urls = new UPNPUrls(); + IGDdatas data = new IGDdatas(); + ByteBuffer lanaddr = ByteBuffer.allocate(16); + ByteBuffer intClient = ByteBuffer.allocate(16); + ByteBuffer intPort = ByteBuffer.allocate(6); + ByteBuffer desc = ByteBuffer.allocate(80); + ByteBuffer enabled = ByteBuffer.allocate(4); + ByteBuffer leaseDuration = ByteBuffer.allocate(16); + int ret; + int i; + + if(args.length < 2) { + System.err.println("Usage : java [...] JavaBridgeTest port protocol"); + System.out.println(" port is numeric, protocol is TCP or UDP"); + return; + } + + devlist = miniupnpc.upnpDiscover(UPNP_DELAY, (String) null, (String) null, 0, null); + if (devlist != null) { + System.out.println("List of UPNP devices found on the network :"); + for (UPNPDev device = devlist; device != null; device = device.pNext) { + System.out.println("desc: " + device.descURL.getString(0) + " st: " + device.st.getString(0)); + } + if ((i = miniupnpc.UPNP_GetValidIGD(devlist, urls, data, lanaddr, 16)) != 0) { + switch (i) { + case 1: + System.out.println("Found valid IGD : " + urls.controlURL.getString(0)); + break; + case 2: + System.out.println("Found a (not connected?) IGD : " + urls.controlURL.getString(0)); + System.out.println("Trying to continue anyway"); + break; + case 3: + System.out.println("UPnP device found. Is it an IGD ? : " + urls.controlURL.getString(0)); + System.out.println("Trying to continue anyway"); + break; + default: + System.out.println("Found device (igd ?) : " + urls.controlURL.getString(0)); + System.out.println("Trying to continue anyway"); + + } + System.out.println("Local LAN ip address : " + new String(lanaddr.array())); + ByteBuffer externalAddress = ByteBuffer.allocate(16); + miniupnpc.UPNP_GetExternalIPAddress(urls.controlURL.getString(0), + new String(data.first.servicetype), externalAddress); + System.out.println("ExternalIPAddress = " + new String(externalAddress.array())); + ret = miniupnpc.UPNP_AddPortMapping( + urls.controlURL.getString(0), // controlURL + new String(data.first.servicetype), // servicetype + args[0], // external Port + args[0], // internal Port + new String(lanaddr.array()), // internal client + "added via miniupnpc/JAVA !", // description + args[1], // protocol UDP or TCP + null, // remote host (useless) + "0"); // leaseDuration + if (ret != MiniupnpcLibrary.UPNPCOMMAND_SUCCESS) + System.out.println("AddPortMapping() failed with code " + ret); + ret = miniupnpc.UPNP_GetSpecificPortMappingEntry( + urls.controlURL.getString(0), new String(data.first.servicetype), + args[0], args[1], intClient, intPort, + desc, enabled, leaseDuration); + if (ret != MiniupnpcLibrary.UPNPCOMMAND_SUCCESS) + System.out.println("GetSpecificPortMappingEntry() failed with code " + ret); + System.out.println("InternalIP:Port = " + + new String(intClient.array()) + ":" + new String(intPort.array()) + + " (" + new String(desc.array()) + ")"); + ret = miniupnpc.UPNP_DeletePortMapping( + urls.controlURL.getString(0), + new String(data.first.servicetype), + args[0], args[1], null); + if (ret != MiniupnpcLibrary.UPNPCOMMAND_SUCCESS) + System.out.println("DelPortMapping() failed with code " + ret); + miniupnpc.FreeUPNPUrls(urls); + } else { + System.out.println("No valid UPNP Internet Gateway Device found."); + } + miniupnpc.freeUPNPDevlist(devlist); + } else { + System.out.println("No IGD UPnP Device found on the network !\n"); + } + } +} diff --git a/libs/miniupnpc/java/testjava.sh b/libs/miniupnpc/java/testjava.sh new file mode 100755 index 000000000..c997baf9e --- /dev/null +++ b/libs/miniupnpc/java/testjava.sh @@ -0,0 +1,8 @@ +#! /bin/sh + +JAVA=java +JAVAC=javac + +$JAVAC -cp miniupnpc_Linux.jar JavaBridgeTest.java +$JAVA -cp miniupnpc_Linux.jar:. JavaBridgeTest 12345 UDP + diff --git a/libs/miniupnpc/man3/miniupnpc.3 b/libs/miniupnpc/man3/miniupnpc.3 new file mode 100644 index 000000000..0e35aaac5 --- /dev/null +++ b/libs/miniupnpc/man3/miniupnpc.3 @@ -0,0 +1,53 @@ +\" $Id: miniupnpc.3,v 1.3 2011/07/25 18:02:11 nanard Exp $ +.TH miniupnpc 3 +.SH NAME +miniupnpc \- UPnP client library +.SH SYNOPSIS +.SH DESCRIPTION +The miniupnpc library implement the UPnP protocol defined +to dialog with Internet Gateway Devices. It also has +the ability to use data gathered by minissdpd(1) about +UPnP devices up on the network in order to skip the +long UPnP device discovery process. +.PP +At first, upnpDiscover(3) has to be used to discover UPnP IGD present +on the network. Then UPNP_GetValidIGD(3) to select the right one. +Alternatively, UPNP_GetIGDFromUrl(3) could be used to bypass discovery +process if the root description url of the device to use is known. +Then all the UPNP_* functions can be used, such as +UPNP_GetConnectionTypeInfo(3), UPNP_AddPortMapping(3), etc... +.SH "HEADER FILES" +.IP miniupnpc.h +That's the main header file for the miniupnpc library API. +It contains all the functions and structures related to device discovery. +.IP upnpcommands.h +This header file contain the UPnP IGD methods that are accessible +through the miniupnpc API. The name of the C functions are matching +the UPnP methods names. ie: GetGenericPortMappingEntry is +UPNP_GetGenericPortMappingEntry. +.SH "API FUNCTIONS" +.IP "struct UPNPDev * upnpDiscover(int delay, const char * multicastif, const char * minissdpdsock, int sameport, int ipv6, int * error);" +execute the discovery process. +delay (in millisecond) is the maximum time for waiting any device response. +If available, device list will be obtained from MiniSSDPd. +Default path for minissdpd socket will be used if minissdpdsock argument is NULL. +If multicastif is not NULL, it will be used instead of the default multicast interface for sending SSDP discover packets. +If sameport is not null, SSDP packets will be sent from the source port 1900 (same as destination port) otherwise system assign a source port. +If ipv6 is not 0, IPv6 is used instead of IPv4 for the discovery process. +.IP "void freeUPNPDevlist(struct UPNPDev * devlist);" +free the list returned by upnpDiscover(). +.IP "int UPNP_GetValidIGD(struct UPNPDev * devlist, struct UPNPUrls * urls, struct IGDdatas * data, char * lanaddr, int lanaddrlen);" +browse the list of device returned by upnpDiscover(), find +a live UPnP internet gateway device and fill structures passed as arguments +with data used for UPNP methods invokation. +.IP "int UPNP_GetIGDFromUrl(const char * rootdescurl, struct UPNPUrls * urls, struct IGDdatas * data, char * lanaddr, int lanaddrlen);" +permit to bypass the upnpDiscover() call if the xml root description +URL of the UPnP IGD is known. +Fill structures passed as arguments +with data used for UPNP methods invokation. +.IP "void GetUPNPUrls(struct UPNPUrls *, struct IGDdatas *, const char *);" +.IP "void FreeUPNPUrls(struct UPNPUrls *);" + +.SH "SEE ALSO" +minissdpd(1) +.SH BUGS diff --git a/libs/miniupnpc/mingw32/libminiupnpc.a b/libs/miniupnpc/mingw32/libminiupnpc.a new file mode 100644 index 000000000..fb2065753 Binary files /dev/null and b/libs/miniupnpc/mingw32/libminiupnpc.a differ diff --git a/libs/miniupnpc/mingw32make.bat b/libs/miniupnpc/mingw32make.bat new file mode 100644 index 000000000..92efad963 --- /dev/null +++ b/libs/miniupnpc/mingw32make.bat @@ -0,0 +1,8 @@ +@mingw32-make -f Makefile.mingw %1 +@if errorlevel 1 goto end +@if not exist upnpc-static.exe goto end +@strip upnpc-static.exe +@upx --best upnpc-static.exe +@strip upnpc-shared.exe +@upx --best upnpc-shared.exe +:end diff --git a/libs/miniupnpc/mingw64/libminiupnpc.a b/libs/miniupnpc/mingw64/libminiupnpc.a new file mode 100644 index 000000000..4275196d3 Binary files /dev/null and b/libs/miniupnpc/mingw64/libminiupnpc.a differ diff --git a/libs/miniupnpc/minihttptestserver.c b/libs/miniupnpc/minihttptestserver.c new file mode 100644 index 000000000..a1dddf0ea --- /dev/null +++ b/libs/miniupnpc/minihttptestserver.c @@ -0,0 +1,461 @@ +/* $Id: minihttptestserver.c,v 1.6 2011/05/09 08:53:15 nanard Exp $ */ +/* Project : miniUPnP + * Author : Thomas Bernard + * Copyright (c) 2011 Thomas Bernard + * This software is subject to the conditions detailed in the + * LICENCE file provided in this distribution. + * */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define CRAP_LENGTH (2048) + +volatile int quit = 0; +volatile int child_to_wait_for = 0; + +/** + * signal handler for SIGCHLD (child status has changed) + */ +void handle_signal_chld(int sig) +{ + printf("handle_signal_chld(%d)\n", sig); + ++child_to_wait_for; +} + +/** + * signal handler for SIGINT (CRTL C) + */ +#if 0 +void handle_signal_int(int sig) +{ + printf("handle_signal_int(%d)\n", sig); + quit = 1; +} +#endif + +/** + * build a text/plain content of the specified length + */ +void build_content(char * p, int n) +{ + char line_buffer[80]; + int k; + int i = 0; + + while(n > 0) { + k = snprintf(line_buffer, sizeof(line_buffer), + "%04d_ABCDEFGHIJKL_This_line_is_64_bytes_long_ABCDEFGHIJKL_%04d\r\n", + i, i); + if(k != 64) { + fprintf(stderr, "snprintf() returned %d in build_content()\n", k); + } + ++i; + if(n >= 64) { + memcpy(p, line_buffer, 64); + p += 64; + n -= 64; + } else { + memcpy(p, line_buffer, n); + p += n; + n = 0; + } + } +} + +/** + * build crappy content + */ +void build_crap(char * p, int n) +{ + static const char crap[] = "_CRAP_\r\n"; + int i; + + while(n > 0) { + i = sizeof(crap) - 1; + if(i > n) + i = n; + memcpy(p, crap, i); + p += i; + n -= i; + } +} + +/** + * build chunked response. + * return a malloc'ed buffer + */ +char * build_chunked_response(int content_length, int * response_len) { + char * response_buffer; + char * content_buffer; + int buffer_length; + int i, n; + + /* allocate to have some margin */ + buffer_length = 256 + content_length + (content_length >> 4); + response_buffer = malloc(buffer_length); + *response_len = snprintf(response_buffer, buffer_length, + "HTTP/1.1 200 OK\r\n" + "Content-Type: text/plain\r\n" + "Transfer-Encoding: chunked\r\n" + "\r\n"); + + /* build the content */ + content_buffer = malloc(content_length); + build_content(content_buffer, content_length); + + /* chunk it */ + i = 0; + while(i < content_length) { + n = (rand() % 199) + 1; + if(i + n > content_length) { + n = content_length - i; + } + /* TODO : check buffer size ! */ + *response_len += snprintf(response_buffer + *response_len, + buffer_length - *response_len, + "%x\r\n", n); + memcpy(response_buffer + *response_len, content_buffer + i, n); + *response_len += n; + i += n; + response_buffer[(*response_len)++] = '\r'; + response_buffer[(*response_len)++] = '\n'; + } + memcpy(response_buffer + *response_len, "0\r\n", 3); + *response_len += 3; + free(content_buffer); + + printf("resp_length=%d buffer_length=%d content_length=%d\n", + *response_len, buffer_length, content_length); + return response_buffer; +} + +enum modes { MODE_INVALID, MODE_CHUNKED, MODE_ADDCRAP, MODE_NORMAL }; +const struct { + const enum modes mode; + const char * text; +} modes_array[] = { + {MODE_CHUNKED, "chunked"}, + {MODE_ADDCRAP, "addcrap"}, + {MODE_NORMAL, "normal"}, + {MODE_INVALID, NULL} +}; + +/** + * write the response with random behaviour ! + */ +void send_response(int c, const char * buffer, int len) +{ + int n; + while(len > 0) { + n = (rand() % 99) + 1; + if(n > len) + n = len; + n = write(c, buffer, n); + if(n < 0) { + perror("write"); + return; + } else { + len -= n; + buffer += n; + } + usleep(10000); /* 10ms */ + } +} + +/** + * handle the HTTP connection + */ +void handle_http_connection(int c) +{ + char request_buffer[2048]; + int request_len = 0; + int headers_found = 0; + int n, i; + char request_method[16]; + char request_uri[256]; + char http_version[16]; + char * p; + char * response_buffer; + int response_len; + enum modes mode; + int content_length = 16*1024; + + /* read the request */ + while(request_len < sizeof(request_buffer) && !headers_found) { + n = read(c, + request_buffer + request_len, + sizeof(request_buffer) - request_len); + if(n < 0) { + perror("read"); + return; + } else if(n==0) { + /* remote host closed the connection */ + break; + } else { + request_len += n; + for(i = 0; i < request_len - 3; i++) { + if(0 == memcmp(request_buffer + i, "\r\n\r\n", 4)) { + /* found the end of headers */ + headers_found = 1; + break; + } + } + } + } + if(!headers_found) { + /* error */ + return; + } + printf("headers :\n%.*s", request_len, request_buffer); + /* the request have been received, now parse the request line */ + p = request_buffer; + for(i = 0; i < sizeof(request_method) - 1; i++) { + if(*p == ' ' || *p == '\r') + break; + request_method[i] = *p; + ++p; + } + request_method[i] = '\0'; + while(*p == ' ') + p++; + for(i = 0; i < sizeof(request_uri) - 1; i++) { + if(*p == ' ' || *p == '\r') + break; + request_uri[i] = *p; + ++p; + } + request_uri[i] = '\0'; + while(*p == ' ') + p++; + for(i = 0; i < sizeof(http_version) - 1; i++) { + if(*p == ' ' || *p == '\r') + break; + http_version[i] = *p; + ++p; + } + http_version[i] = '\0'; + printf("Method = %s, URI = %s, %s\n", + request_method, request_uri, http_version); + /* check if the request method is allowed */ + if(0 != strcmp(request_method, "GET")) { + const char response405[] = "HTTP/1.1 405 Method Not Allowed\r\n" + "Allow: GET\r\n\r\n"; + /* 405 Method Not Allowed */ + /* The response MUST include an Allow header containing a list + * of valid methods for the requested resource. */ + write(c, response405, sizeof(response405) - 1); + return; + } + + mode = MODE_INVALID; + /* use the request URI to know what to do */ + for(i = 0; modes_array[i].mode != MODE_INVALID; i++) { + if(strstr(request_uri, modes_array[i].text)) { + mode = modes_array[i].mode; /* found */ + break; + } + } + + switch(mode) { + case MODE_CHUNKED: + response_buffer = build_chunked_response(content_length, &response_len); + break; + case MODE_ADDCRAP: + response_len = content_length+256; + response_buffer = malloc(response_len); + n = snprintf(response_buffer, response_len, + "HTTP/1.1 200 OK\r\n" + "Server: minihttptestserver\r\n" + "Content-Type: text/plain\r\n" + "Content-Length: %d\r\n" + "\r\n", content_length); + response_len = content_length+n+CRAP_LENGTH; + response_buffer = realloc(response_buffer, response_len); + build_content(response_buffer + n, content_length); + build_crap(response_buffer + n + content_length, CRAP_LENGTH); + break; + default: + response_len = content_length+256; + response_buffer = malloc(response_len); + n = snprintf(response_buffer, response_len, + "HTTP/1.1 200 OK\r\n" + "Server: minihttptestserver\r\n" + "Content-Type: text/plain\r\n" + "\r\n"); + response_len = content_length+n; + response_buffer = realloc(response_buffer, response_len); + build_content(response_buffer + n, response_len - n); + } + + if(response_buffer) { + send_response(c, response_buffer, response_len); + free(response_buffer); + } else { + /* Error 500 */ + } +} + +/** + */ +int main(int argc, char * * argv) { + int ipv6 = 0; + int s, c, i; + unsigned short port = 0; + struct sockaddr_storage server_addr; + socklen_t server_addrlen; + struct sockaddr_storage client_addr; + socklen_t client_addrlen; + pid_t pid; + int child = 0; + int status; + const char * expected_file_name = NULL; + + for(i = 1; i < argc; i++) { + if(argv[i][0] == '-') { + switch(argv[i][1]) { + case '6': + ipv6 = 1; + break; + case 'e': + /* write expected file ! */ + expected_file_name = argv[++i]; + break; + case 'p': + /* port */ + if(++i < argc) { + port = (unsigned short)atoi(argv[i]); + } + break; + default: + fprintf(stderr, "unknown command line switch '%s'\n", argv[i]); + } + } else { + fprintf(stderr, "unkown command line argument '%s'\n", argv[i]); + } + } + + srand(time(NULL)); + signal(SIGCHLD, handle_signal_chld); +#if 0 + signal(SIGINT, handle_signal_int); +#endif + + s = socket(ipv6 ? AF_INET6 : AF_INET, SOCK_STREAM, 0); + if(s < 0) { + perror("socket"); + return 1; + } + memset(&server_addr, 0, sizeof(struct sockaddr_storage)); + memset(&client_addr, 0, sizeof(struct sockaddr_storage)); + if(ipv6) { + struct sockaddr_in6 * addr = (struct sockaddr_in6 *)&server_addr; + addr->sin6_family = AF_INET6; + addr->sin6_port = htons(port); + addr->sin6_addr = in6addr_any; + } else { + struct sockaddr_in * addr = (struct sockaddr_in *)&server_addr; + addr->sin_family = AF_INET; + addr->sin_port = htons(port); + addr->sin_addr.s_addr = htonl(INADDR_ANY); + } + if(bind(s, (struct sockaddr *)&server_addr, + ipv6 ? sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in)) < 0) { + perror("bind"); + return 1; + } + if(listen(s, 5) < 0) { + perror("listen"); + } + if(port == 0) { + server_addrlen = sizeof(struct sockaddr_storage); + if(getsockname(s, (struct sockaddr *)&server_addr, &server_addrlen) < 0) { + perror("getsockname"); + return 1; + } + if(ipv6) { + struct sockaddr_in6 * addr = (struct sockaddr_in6 *)&server_addr; + port = ntohs(addr->sin6_port); + } else { + struct sockaddr_in * addr = (struct sockaddr_in *)&server_addr; + port = ntohs(addr->sin_port); + } + printf("Listening on port %hu\n", port); + fflush(stdout); + } + + /* write expected file */ + if(expected_file_name) { + FILE * f; + f = fopen(expected_file_name, "wb"); + if(f) { + char * buffer; + buffer = malloc(16*1024); + build_content(buffer, 16*1024); + fwrite(buffer, 1, 16*1024, f); + free(buffer); + fclose(f); + } + } + + /* fork() loop */ + while(!child && !quit) { + while(child_to_wait_for > 0) { + pid = wait(&status); + if(pid < 0) { + perror("wait"); + } else { + printf("child(%d) terminated with status %d\n", pid, status); + } + --child_to_wait_for; + } + /* TODO : add a select() call in order to handle the case + * when a signal is caught */ + client_addrlen = sizeof(struct sockaddr_storage); + c = accept(s, (struct sockaddr *)&client_addr, + &client_addrlen); + if(c < 0) { + perror("accept"); + return 1; + } + printf("accept...\n"); + pid = fork(); + if(pid < 0) { + perror("fork"); + return 1; + } else if(pid == 0) { + /* child */ + child = 1; + close(s); + s = -1; + handle_http_connection(c); + } + close(c); + } + if(s >= 0) { + close(s); + s = -1; + } + if(!child) { + while(child_to_wait_for > 0) { + pid = wait(&status); + if(pid < 0) { + perror("wait"); + } else { + printf("child(%d) terminated with status %d\n", pid, status); + } + --child_to_wait_for; + } + printf("Bye...\n"); + } + return 0; +} + diff --git a/libs/miniupnpc/minisoap.c b/libs/miniupnpc/minisoap.c new file mode 100644 index 000000000..8889bf040 --- /dev/null +++ b/libs/miniupnpc/minisoap.c @@ -0,0 +1,121 @@ +/* $Id: minisoap.c,v 1.21 2011/03/22 19:15:35 nanard Exp $ */ +/* Project : miniupnp + * Author : Thomas Bernard + * Copyright (c) 2005-2009 Thomas Bernard + * This software is subject to the conditions detailed in the + * LICENCE file provided in this distribution. + * + * Minimal SOAP implementation for UPnP protocol. + */ +#include +#include +#ifdef WIN32 +#include +#include +#define snprintf _snprintf +#else +#include +#include +#include +#endif +#include "minisoap.h" +#include "miniupnpcstrings.h" + +/* only for malloc */ +#include + +#ifdef WIN32 +#define PRINT_SOCKET_ERROR(x) printf("Socket error: %s, %d\n", x, WSAGetLastError()); +#else +#define PRINT_SOCKET_ERROR(x) perror(x) +#endif + +/* httpWrite sends the headers and the body to the socket + * and returns the number of bytes sent */ +static int +httpWrite(int fd, const char * body, int bodysize, + const char * headers, int headerssize) +{ + int n = 0; + /*n = write(fd, headers, headerssize);*/ + /*if(bodysize>0) + n += write(fd, body, bodysize);*/ + /* Note : my old linksys router only took into account + * soap request that are sent into only one packet */ + char * p; + /* TODO: AVOID MALLOC */ + p = malloc(headerssize+bodysize); + if(!p) + return 0; + memcpy(p, headers, headerssize); + memcpy(p+headerssize, body, bodysize); + /*n = write(fd, p, headerssize+bodysize);*/ + n = send(fd, p, headerssize+bodysize, 0); + if(n<0) { + PRINT_SOCKET_ERROR("send"); + } + /* disable send on the socket */ + /* draytek routers dont seems to like that... */ +#if 0 +#ifdef WIN32 + if(shutdown(fd, SD_SEND)<0) { +#else + if(shutdown(fd, SHUT_WR)<0) { /*SD_SEND*/ +#endif + PRINT_SOCKET_ERROR("shutdown"); + } +#endif + free(p); + return n; +} + +/* self explanatory */ +int soapPostSubmit(int fd, + const char * url, + const char * host, + unsigned short port, + const char * action, + const char * body, + const char * httpversion) +{ + int bodysize; + char headerbuf[512]; + int headerssize; + char portstr[8]; + bodysize = (int)strlen(body); + /* We are not using keep-alive HTTP connections. + * HTTP/1.1 needs the header Connection: close to do that. + * This is the default with HTTP/1.0 + * Using HTTP/1.1 means we need to support chunked transfer-encoding : + * When using HTTP/1.1, the router "BiPAC 7404VNOX" always use chunked + * transfer encoding. */ + /* Connection: Close is normally there only in HTTP/1.1 but who knows */ + portstr[0] = '\0'; + if(port != 80) + snprintf(portstr, sizeof(portstr), ":%hu", port); + headerssize = snprintf(headerbuf, sizeof(headerbuf), + "POST %s HTTP/%s\r\n" + "Host: %s%s\r\n" + "User-Agent: " OS_STRING ", UPnP/1.0, MiniUPnPc/" MINIUPNPC_VERSION_STRING "\r\n" + "Content-Length: %d\r\n" + "Content-Type: text/xml\r\n" + "SOAPAction: \"%s\"\r\n" + "Connection: Close\r\n" + "Cache-Control: no-cache\r\n" /* ??? */ + "Pragma: no-cache\r\n" + "\r\n", + url, httpversion, host, portstr, bodysize, action); +#ifdef DEBUG + /*printf("SOAP request : headersize=%d bodysize=%d\n", + headerssize, bodysize); + */ + printf("SOAP request : POST %s HTTP/%s - Host: %s%s\n", + url, httpversion, host, portstr); + printf("SOAPAction: \"%s\" - Content-Length: %d\n", action, bodysize); + printf("Headers :\n%s", headerbuf); + printf("Body :\n%s\n", body); +#endif + return httpWrite(fd, body, bodysize, headerbuf, headerssize); +} + + diff --git a/libs/miniupnpc/minisoap.h b/libs/miniupnpc/minisoap.h new file mode 100644 index 000000000..696725f62 --- /dev/null +++ b/libs/miniupnpc/minisoap.h @@ -0,0 +1,15 @@ +/* $Id: minisoap.h,v 1.4 2010/04/12 20:39:41 nanard Exp $ */ +/* Project : miniupnp + * Author : Thomas Bernard + * Copyright (c) 2005 Thomas Bernard + * This software is subject to the conditions detailed in the + * LICENCE file provided in this distribution. */ +#ifndef __MINISOAP_H__ +#define __MINISOAP_H__ + +/*int httpWrite(int, const char *, int, const char *);*/ +int soapPostSubmit(int, const char *, const char *, unsigned short, + const char *, const char *, const char *); + +#endif + diff --git a/libs/miniupnpc/minissdpc.c b/libs/miniupnpc/minissdpc.c new file mode 100644 index 000000000..e5e852855 --- /dev/null +++ b/libs/miniupnpc/minissdpc.c @@ -0,0 +1,132 @@ +/* $Id: minissdpc.c,v 1.14 2010/11/25 09:57:25 nanard Exp $ */ +/* Project : miniupnp + * Author : Thomas BERNARD + * copyright (c) 2005-2009 Thomas Bernard + * This software is subjet to the conditions detailed in the + * provided LICENCE file. */ +/*#include */ +#include +#include +#include +#include +#include +#if defined(WIN32) || defined(__amigaos__) || defined(__amigaos4__) +#ifdef WIN32 +#include +#include +#include +#include +#include +#endif +#if defined(__amigaos__) || defined(__amigaos4__) +#include +#endif +#if defined(__amigaos__) +#define uint16_t unsigned short +#endif +/* Hack */ +#define UNIX_PATH_LEN 108 +struct sockaddr_un { + uint16_t sun_family; + char sun_path[UNIX_PATH_LEN]; +}; +#else +#include +#include +#endif + +#include "minissdpc.h" +#include "miniupnpc.h" + +#include "codelength.h" + +struct UPNPDev * +getDevicesFromMiniSSDPD(const char * devtype, const char * socketpath) +{ + struct UPNPDev * tmp; + struct UPNPDev * devlist = NULL; + unsigned char buffer[2048]; + ssize_t n; + unsigned char * p; + unsigned char * url; + unsigned int i; + unsigned int urlsize, stsize, usnsize, l; + int s; + struct sockaddr_un addr; + + s = socket(AF_UNIX, SOCK_STREAM, 0); + if(s < 0) + { + /*syslog(LOG_ERR, "socket(unix): %m");*/ + perror("socket(unix)"); + return NULL; + } + addr.sun_family = AF_UNIX; + strncpy(addr.sun_path, socketpath, sizeof(addr.sun_path)); + /* TODO : check if we need to handle the EINTR */ + if(connect(s, (struct sockaddr *)&addr, sizeof(struct sockaddr_un)) < 0) + { + /*syslog(LOG_WARNING, "connect(\"%s\"): %m", socketpath);*/ + close(s); + return NULL; + } + stsize = strlen(devtype); + buffer[0] = 1; /* request type 1 : request devices/services by type */ + p = buffer + 1; + l = stsize; CODELENGTH(l, p); + if(p + stsize > buffer + sizeof(buffer)) + { + /* devtype is too long ! */ + close(s); + return NULL; + } + memcpy(p, devtype, stsize); + p += stsize; + if(write(s, buffer, p - buffer) < 0) + { + /*syslog(LOG_ERR, "write(): %m");*/ + perror("minissdpc.c: write()"); + close(s); + return NULL; + } + n = read(s, buffer, sizeof(buffer)); + if(n<=0) + { + perror("minissdpc.c: read()"); + close(s); + return NULL; + } + p = buffer + 1; + for(i = 0; i < buffer[0]; i++) + { + if(p+2>=buffer+sizeof(buffer)) + break; + DECODELENGTH(urlsize, p); + if(p+urlsize+2>=buffer+sizeof(buffer)) + break; + url = p; + p += urlsize; + DECODELENGTH(stsize, p); + if(p+stsize+2>=buffer+sizeof(buffer)) + break; + tmp = (struct UPNPDev *)malloc(sizeof(struct UPNPDev)+urlsize+stsize); + tmp->pNext = devlist; + tmp->descURL = tmp->buffer; + tmp->st = tmp->buffer + 1 + urlsize; + memcpy(tmp->buffer, url, urlsize); + tmp->buffer[urlsize] = '\0'; + memcpy(tmp->buffer + urlsize + 1, p, stsize); + p += stsize; + tmp->buffer[urlsize+1+stsize] = '\0'; + devlist = tmp; + /* added for compatibility with recent versions of MiniSSDPd + * >= 2007/12/19 */ + DECODELENGTH(usnsize, p); + p += usnsize; + if(p>buffer + sizeof(buffer)) + break; + } + close(s); + return devlist; +} + diff --git a/libs/miniupnpc/minissdpc.h b/libs/miniupnpc/minissdpc.h new file mode 100644 index 000000000..25e91ce31 --- /dev/null +++ b/libs/miniupnpc/minissdpc.h @@ -0,0 +1,15 @@ +/* $Id: minissdpc.h,v 1.1 2007/08/31 15:15:33 nanard Exp $ */ +/* Project: miniupnp + * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ + * Author: Thomas Bernard + * Copyright (c) 2005-2007 Thomas Bernard + * This software is subjects to the conditions detailed + * in the LICENCE file provided within this distribution */ +#ifndef __MINISSDPC_H__ +#define __MINISSDPC_H__ + +struct UPNPDev * +getDevicesFromMiniSSDPD(const char * devtype, const char * socketpath); + +#endif + diff --git a/libs/miniupnpc/miniupnpc.c b/libs/miniupnpc/miniupnpc.c new file mode 100644 index 000000000..0a3aae33d --- /dev/null +++ b/libs/miniupnpc/miniupnpc.c @@ -0,0 +1,943 @@ +/* $Id: miniupnpc.c,v 1.95 2011/05/15 21:42:26 nanard Exp $ */ +/* Project : miniupnp + * Author : Thomas BERNARD + * copyright (c) 2005-2011 Thomas Bernard + * This software is subjet to the conditions detailed in the + * provided LICENSE file. */ +#define __EXTENSIONS__ 1 +#if !defined(MACOSX) && !defined(__sun) +#if !defined(_XOPEN_SOURCE) && !defined(__OpenBSD__) && !defined(__NetBSD__) +#ifndef __cplusplus +#define _XOPEN_SOURCE 600 +#endif +#endif +#ifndef __BSD_VISIBLE +#define __BSD_VISIBLE 1 +#endif +#endif + +#include +#include +#include +#ifdef WIN32 +/* Win32 Specific includes and defines */ +#include +#include +#include +#include +#define snprintf _snprintf +#ifndef strncasecmp +#if defined(_MSC_VER) && (_MSC_VER >= 1400) +#define strncasecmp _memicmp +#else /* defined(_MSC_VER) && (_MSC_VER >= 1400) */ +#define strncasecmp memicmp +#endif /* defined(_MSC_VER) && (_MSC_VER >= 1400) */ +#endif /* #ifndef strncasecmp */ +#define MAXHOSTNAMELEN 64 +#else /* #ifdef WIN32 */ +/* Standard POSIX includes */ +#include +#if defined(__amigaos__) && !defined(__amigaos4__) +/* Amiga OS 3 specific stuff */ +#define socklen_t int +#else +#include +#endif +#include +#include +#include +#include +#include +#include +#include +#if !defined(__amigaos__) && !defined(__amigaos4__) +#include +#endif +#include +#include +#define closesocket close +#endif /* #else WIN32 */ +#ifdef MINIUPNPC_SET_SOCKET_TIMEOUT +#include +#endif +#if defined(__amigaos__) || defined(__amigaos4__) +/* Amiga OS specific stuff */ +#define TIMEVAL struct timeval +#endif + +#include "miniupnpc.h" +#include "minissdpc.h" +#include "miniwget.h" +#include "minisoap.h" +#include "minixml.h" +#include "upnpcommands.h" +#include "connecthostport.h" +#include "receivedata.h" + +#ifdef WIN32 +#define PRINT_SOCKET_ERROR(x) printf("Socket error: %s, %d\n", x, WSAGetLastError()); +#else +#define PRINT_SOCKET_ERROR(x) perror(x) +#endif + +#define SOAPPREFIX "s" +#define SERVICEPREFIX "u" +#define SERVICEPREFIX2 'u' + +/* root description parsing */ +LIBSPEC void parserootdesc(const char * buffer, int bufsize, struct IGDdatas * data) +{ + struct xmlparser parser; + /* xmlparser object */ + parser.xmlstart = buffer; + parser.xmlsize = bufsize; + parser.data = data; + parser.starteltfunc = IGDstartelt; + parser.endeltfunc = IGDendelt; + parser.datafunc = IGDdata; + parser.attfunc = 0; + parsexml(&parser); +#ifdef DEBUG + printIGD(data); +#endif +} + +/* simpleUPnPcommand2 : + * not so simple ! + * return values : + * pointer - OK + * NULL - error */ +char * simpleUPnPcommand2(int s, const char * url, const char * service, + const char * action, struct UPNParg * args, + int * bufsize, const char * httpversion) +{ + char hostname[MAXHOSTNAMELEN+1]; + unsigned short port = 0; + char * path; + char soapact[128]; + char soapbody[2048]; + char * buf; + int n; + + *bufsize = 0; + snprintf(soapact, sizeof(soapact), "%s#%s", service, action); + if(args==NULL) + { + /*soapbodylen = */snprintf(soapbody, sizeof(soapbody), + "\r\n" + "<" SOAPPREFIX ":Envelope " + "xmlns:" SOAPPREFIX "=\"http://schemas.xmlsoap.org/soap/envelope/\" " + SOAPPREFIX ":encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">" + "<" SOAPPREFIX ":Body>" + "<" SERVICEPREFIX ":%s xmlns:" SERVICEPREFIX "=\"%s\">" + "" + "" + "\r\n", action, service, action); + } + else + { + char * p; + const char * pe, * pv; + int soapbodylen; + soapbodylen = snprintf(soapbody, sizeof(soapbody), + "\r\n" + "<" SOAPPREFIX ":Envelope " + "xmlns:" SOAPPREFIX "=\"http://schemas.xmlsoap.org/soap/envelope/\" " + SOAPPREFIX ":encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">" + "<" SOAPPREFIX ":Body>" + "<" SERVICEPREFIX ":%s xmlns:" SERVICEPREFIX "=\"%s\">", + action, service); + p = soapbody + soapbodylen; + while(args->elt) + { + /* check that we are never overflowing the string... */ + if(soapbody + sizeof(soapbody) <= p + 100) + { + /* we keep a margin of at least 100 bytes */ + return NULL; + } + *(p++) = '<'; + pe = args->elt; + while(*pe) + *(p++) = *(pe++); + *(p++) = '>'; + if((pv = args->val)) + { + while(*pv) + *(p++) = *(pv++); + } + *(p++) = '<'; + *(p++) = '/'; + pe = args->elt; + while(*pe) + *(p++) = *(pe++); + *(p++) = '>'; + args++; + } + *(p++) = '<'; + *(p++) = '/'; + *(p++) = SERVICEPREFIX2; + *(p++) = ':'; + pe = action; + while(*pe) + *(p++) = *(pe++); + strncpy(p, ">\r\n", + soapbody + sizeof(soapbody) - p); + } + if(!parseURL(url, hostname, &port, &path)) return NULL; + if(s<0) + { + s = connecthostport(hostname, port); + if(s < 0) + { + return NULL; + } + } + + n = soapPostSubmit(s, path, hostname, port, soapact, soapbody, httpversion); + if(n<=0) { +#ifdef DEBUG + printf("Error sending SOAP request\n"); +#endif + closesocket(s); + return NULL; + } + + buf = getHTTPResponse(s, bufsize); +#ifdef DEBUG + if(*bufsize > 0 && buf) + { + printf("SOAP Response :\n%.*s\n", *bufsize, buf); + } +#endif + closesocket(s); + return buf; +} + +/* simpleUPnPcommand : + * not so simple ! + * return values : + * pointer - OK + * NULL - error */ +char * simpleUPnPcommand(int s, const char * url, const char * service, + const char * action, struct UPNParg * args, + int * bufsize) +{ + char * buf; + + buf = simpleUPnPcommand2(s, url, service, action, args, bufsize, "1.1"); +/* + buf = simpleUPnPcommand2(s, url, service, action, args, bufsize, "1.0"); + if (!buf || *bufsize == 0) + { +#if DEBUG + printf("Error or no result from SOAP request; retrying with HTTP/1.1\n"); +#endif + buf = simpleUPnPcommand2(s, url, service, action, args, bufsize, "1.1"); + } +*/ + return buf; +} + +/* parseMSEARCHReply() + * the last 4 arguments are filled during the parsing : + * - location/locationsize : "location:" field of the SSDP reply packet + * - st/stsize : "st:" field of the SSDP reply packet. + * The strings are NOT null terminated */ +static void +parseMSEARCHReply(const char * reply, int size, + const char * * location, int * locationsize, + const char * * st, int * stsize) +{ + int a, b, i; + i = 0; + a = i; /* start of the line */ + b = 0; /* end of the "header" (position of the colon) */ + while(isin_addr, sizeof (struct in_addr)); + break; + + case AF_INET6: + memcpy (dst, &sin6->sin6_addr, sizeof (struct in6_addr)); + break; + } + return 1; + } + + return 0; + } +#endif + +/* upnpDiscover() : + * return a chained list of all devices found or NULL if + * no devices was found. + * It is up to the caller to free the chained list + * delay is in millisecond (poll) */ +LIBSPEC struct UPNPDev * +upnpDiscover(int delay, const char * multicastif, + const char * minissdpdsock, int sameport, + int ipv6, + int * error) +{ + struct UPNPDev * tmp; + struct UPNPDev * devlist = 0; + int opt = 1; + static const char MSearchMsgFmt[] = + "M-SEARCH * HTTP/1.1\r\n" + "HOST: %s:" XSTR(PORT) "\r\n" + "ST: %s\r\n" + "MAN: \"ssdp:discover\"\r\n" + "MX: %u\r\n" + "\r\n"; + static const char * const deviceList[] = { +#if 0 + "urn:schemas-upnp-org:device:InternetGatewayDevice:2", + "urn:schemas-upnp-org:service:WANIPConnection:2", +#endif + "urn:schemas-upnp-org:device:InternetGatewayDevice:1", + "urn:schemas-upnp-org:service:WANIPConnection:1", + "urn:schemas-upnp-org:service:WANPPPConnection:1", + "upnp:rootdevice", + 0 + }; + int deviceIndex = 0; + char bufr[1536]; /* reception and emission buffer */ + int sudp; + int n; + struct sockaddr_storage sockudp_r; + unsigned int mx; +#ifdef NO_GETADDRINFO + struct sockaddr_storage sockudp_w; +#else + int rv; + struct addrinfo hints, *servinfo, *p; +#endif +#ifdef WIN32 + MIB_IPFORWARDROW ip_forward; +#endif + int linklocal = 1; + + if(error) + *error = UPNPDISCOVER_UNKNOWN_ERROR; +#if !defined(WIN32) && !defined(__amigaos__) && !defined(__amigaos4__) + /* first try to get infos from minissdpd ! */ + if(!minissdpdsock) + minissdpdsock = "/var/run/minissdpd.sock"; + while(!devlist && deviceList[deviceIndex]) { + devlist = getDevicesFromMiniSSDPD(deviceList[deviceIndex], + minissdpdsock); + /* We return what we have found if it was not only a rootdevice */ + if(devlist && !strstr(deviceList[deviceIndex], "rootdevice")) { + if(error) + *error = UPNPDISCOVER_SUCCESS; + return devlist; + } + deviceIndex++; + } + deviceIndex = 0; +#endif + /* fallback to direct discovery */ +#ifdef WIN32 + sudp = socket(ipv6 ? PF_INET6 : PF_INET, SOCK_DGRAM, IPPROTO_UDP); +#else + sudp = socket(ipv6 ? PF_INET6 : PF_INET, SOCK_DGRAM, 0); +#endif + if(sudp < 0) + { + if(error) + *error = UPNPDISCOVER_SOCKET_ERROR; + PRINT_SOCKET_ERROR("socket"); + return NULL; + } + /* reception */ + memset(&sockudp_r, 0, sizeof(struct sockaddr_storage)); + if(ipv6) { + struct sockaddr_in6 * p = (struct sockaddr_in6 *)&sockudp_r; + p->sin6_family = AF_INET6; + if(sameport) + p->sin6_port = htons(PORT); + p->sin6_addr = in6addr_any; /* in6addr_any is not available with MinGW32 3.4.2 */ + } else { + struct sockaddr_in * p = (struct sockaddr_in *)&sockudp_r; + p->sin_family = AF_INET; + if(sameport) + p->sin_port = htons(PORT); + p->sin_addr.s_addr = INADDR_ANY; + } +#ifdef WIN32 +/* This code could help us to use the right Network interface for + * SSDP multicast traffic */ +/* Get IP associated with the index given in the ip_forward struct + * in order to give this ip to setsockopt(sudp, IPPROTO_IP, IP_MULTICAST_IF) */ + if(!ipv6 + && (GetBestRoute(inet_addr("223.255.255.255"), 0, &ip_forward) == NO_ERROR)) { + DWORD dwRetVal = 0; + PMIB_IPADDRTABLE pIPAddrTable; + DWORD dwSize = 0; +#ifdef DEBUG + IN_ADDR IPAddr; +#endif + int i; +#ifdef DEBUG + printf("ifIndex=%lu nextHop=%lx \n", ip_forward.dwForwardIfIndex, ip_forward.dwForwardNextHop); +#endif + pIPAddrTable = (MIB_IPADDRTABLE *) malloc(sizeof (MIB_IPADDRTABLE)); + if (GetIpAddrTable(pIPAddrTable, &dwSize, 0) == ERROR_INSUFFICIENT_BUFFER) { + free(pIPAddrTable); + pIPAddrTable = (MIB_IPADDRTABLE *) malloc(dwSize); + } + if(pIPAddrTable) { + dwRetVal = GetIpAddrTable( pIPAddrTable, &dwSize, 0 ); +#ifdef DEBUG + printf("\tNum Entries: %ld\n", pIPAddrTable->dwNumEntries); +#endif + for (i=0; i < (int) pIPAddrTable->dwNumEntries; i++) { +#ifdef DEBUG + printf("\n\tInterface Index[%d]:\t%ld\n", i, pIPAddrTable->table[i].dwIndex); + IPAddr.S_un.S_addr = (u_long) pIPAddrTable->table[i].dwAddr; + printf("\tIP Address[%d]: \t%s\n", i, inet_ntoa(IPAddr) ); + IPAddr.S_un.S_addr = (u_long) pIPAddrTable->table[i].dwMask; + printf("\tSubnet Mask[%d]: \t%s\n", i, inet_ntoa(IPAddr) ); + IPAddr.S_un.S_addr = (u_long) pIPAddrTable->table[i].dwBCastAddr; + printf("\tBroadCast[%d]: \t%s (%ld)\n", i, inet_ntoa(IPAddr), pIPAddrTable->table[i].dwBCastAddr); + printf("\tReassembly size[%d]:\t%ld\n", i, pIPAddrTable->table[i].dwReasmSize); + printf("\tType and State[%d]:", i); + printf("\n"); +#endif + if (pIPAddrTable->table[i].dwIndex == ip_forward.dwForwardIfIndex) { + /* Set the address of this interface to be used */ + struct in_addr mc_if; + memset(&mc_if, 0, sizeof(mc_if)); + mc_if.s_addr = pIPAddrTable->table[i].dwAddr; + if(setsockopt(sudp, IPPROTO_IP, IP_MULTICAST_IF, (const char *)&mc_if, sizeof(mc_if)) < 0) { + PRINT_SOCKET_ERROR("setsockopt"); + } + ((struct sockaddr_in *)&sockudp_r)->sin_addr.s_addr = pIPAddrTable->table[i].dwAddr; +#ifndef DEBUG + break; +#endif + } + } + free(pIPAddrTable); + pIPAddrTable = NULL; + } + } +#endif + +#ifdef WIN32 + if (setsockopt(sudp, SOL_SOCKET, SO_REUSEADDR, (const char *)&opt, sizeof (opt)) < 0) +#else + if (setsockopt(sudp, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof (opt)) < 0) +#endif + { + if(error) + *error = UPNPDISCOVER_SOCKET_ERROR; + PRINT_SOCKET_ERROR("setsockopt"); + return NULL; + } + + if(multicastif) + { + if(ipv6) { +#if !defined(WIN32) + /* according to MSDN, if_nametoindex() is supported since + * MS Windows Vista and MS Windows Server 2008. + * http://msdn.microsoft.com/en-us/library/bb408409%28v=vs.85%29.aspx */ + unsigned int ifindex = if_nametoindex(multicastif); /* eth0, etc. */ + if(setsockopt(sudp, IPPROTO_IPV6, IPV6_MULTICAST_IF, &ifindex, sizeof(&ifindex)) < 0) + { + PRINT_SOCKET_ERROR("setsockopt"); + } +#else +#ifdef DEBUG + printf("Setting of multicast interface not supported in IPv6 under Windows.\n"); +#endif +#endif + } else { + struct in_addr mc_if; + mc_if.s_addr = inet_addr(multicastif); /* ex: 192.168.x.x */ + ((struct sockaddr_in *)&sockudp_r)->sin_addr.s_addr = mc_if.s_addr; + if(setsockopt(sudp, IPPROTO_IP, IP_MULTICAST_IF, (const char *)&mc_if, sizeof(mc_if)) < 0) + { + PRINT_SOCKET_ERROR("setsockopt"); + } + } + } + + /* Avant d'envoyer le paquet on bind pour recevoir la reponse */ + if (bind(sudp, (const struct sockaddr *)&sockudp_r, + ipv6 ? sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in)) != 0) + { + if(error) + *error = UPNPDISCOVER_SOCKET_ERROR; + PRINT_SOCKET_ERROR("bind"); + closesocket(sudp); + return NULL; + } + + if(error) + *error = UPNPDISCOVER_SUCCESS; + /* Calculating maximum response time in seconds */ + mx = ((unsigned int)delay) / 1000u; + /* receiving SSDP response packet */ + for(n = 0; deviceList[deviceIndex]; deviceIndex++) + { + if(n == 0) + { + /* sending the SSDP M-SEARCH packet */ + n = snprintf(bufr, sizeof(bufr), + MSearchMsgFmt, + ipv6 ? + (linklocal ? "[" UPNP_MCAST_LL_ADDR "]" : "[" UPNP_MCAST_SL_ADDR "]") + : UPNP_MCAST_ADDR, + deviceList[deviceIndex], mx); +#ifdef DEBUG + printf("Sending %s", bufr); +#endif +#ifdef NO_GETADDRINFO + /* the following code is not using getaddrinfo */ + /* emission */ + memset(&sockudp_w, 0, sizeof(struct sockaddr_storage)); + if(ipv6) { + struct sockaddr_in6 * p = (struct sockaddr_in6 *)&sockudp_w; + p->sin6_family = AF_INET6; + p->sin6_port = htons(PORT); + inet_pton(AF_INET6, + linklocal ? UPNP_MCAST_LL_ADDR : UPNP_MCAST_SL_ADDR, + &(p->sin6_addr)); + } else { + struct sockaddr_in * p = (struct sockaddr_in *)&sockudp_w; + p->sin_family = AF_INET; + p->sin_port = htons(PORT); + p->sin_addr.s_addr = inet_addr(UPNP_MCAST_ADDR); + } + n = sendto(sudp, bufr, n, 0, + (const void *)&sockudp_w, + ipv6 ? sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in)); + if (n < 0) { + if(error) + *error = UPNPDISCOVER_SOCKET_ERROR; + PRINT_SOCKET_ERROR("sendto"); + break; + } +#else /* #ifdef NO_GETADDRINFO */ + memset(&hints, 0, sizeof(hints)); + hints.ai_family = AF_UNSPEC; // AF_INET6 or AF_INET + hints.ai_socktype = SOCK_DGRAM; + /*hints.ai_flags = */ + if ((rv = getaddrinfo(ipv6 + ? (linklocal ? UPNP_MCAST_LL_ADDR : UPNP_MCAST_SL_ADDR) + : UPNP_MCAST_ADDR, + XSTR(PORT), &hints, &servinfo)) != 0) { + if(error) + *error = UPNPDISCOVER_SOCKET_ERROR; +#ifdef WIN32 + fprintf(stderr, "getaddrinfo() failed: %d\n", rv); +#else + fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv)); +#endif + break; + } + for(p = servinfo; p; p = p->ai_next) { + n = sendto(sudp, bufr, n, 0, p->ai_addr, p->ai_addrlen); + if (n < 0) { + PRINT_SOCKET_ERROR("sendto"); + continue; + } + } + freeaddrinfo(servinfo); + if(n < 0) { + if(error) + *error = UPNPDISCOVER_SOCKET_ERROR; + break; + } +#endif /* #ifdef NO_GETADDRINFO */ + } + /* Waiting for SSDP REPLY packet to M-SEARCH */ + n = receivedata(sudp, bufr, sizeof(bufr), delay); + if (n < 0) { + /* error */ + if(error) + *error = UPNPDISCOVER_SOCKET_ERROR; + break; + } else if (n == 0) { + /* no data or Time Out */ + if (devlist) { + /* no more device type to look for... */ + if(error) + *error = UPNPDISCOVER_SUCCESS; + break; + } + if(ipv6) { + if(linklocal) { + linklocal = 0; + --deviceIndex; + } else { + linklocal = 1; + } + } + } else { + const char * descURL=NULL; + int urlsize=0; + const char * st=NULL; + int stsize=0; + /*printf("%d byte(s) :\n%s\n", n, bufr);*/ /* affichage du message */ + parseMSEARCHReply(bufr, n, &descURL, &urlsize, &st, &stsize); + if(st&&descURL) + { +#ifdef DEBUG + printf("M-SEARCH Reply:\nST: %.*s\nLocation: %.*s\n", + stsize, st, urlsize, descURL); +#endif + for(tmp=devlist; tmp; tmp = tmp->pNext) { + if(memcmp(tmp->descURL, descURL, urlsize) == 0 && + tmp->descURL[urlsize] == '\0' && + memcmp(tmp->st, st, stsize) == 0 && + tmp->st[stsize] == '\0') + break; + } + /* at the exit of the loop above, tmp is null if + * no duplicate device was found */ + if(tmp) + continue; + tmp = (struct UPNPDev *)malloc(sizeof(struct UPNPDev)+urlsize+stsize); + if(!tmp) { + /* memory allocation error */ + if(error) + *error = UPNPDISCOVER_MEMORY_ERROR; + break; + } + tmp->pNext = devlist; + tmp->descURL = tmp->buffer; + tmp->st = tmp->buffer + 1 + urlsize; + memcpy(tmp->buffer, descURL, urlsize); + tmp->buffer[urlsize] = '\0'; + memcpy(tmp->buffer + urlsize + 1, st, stsize); + tmp->buffer[urlsize+1+stsize] = '\0'; + devlist = tmp; + } + } + } + closesocket(sudp); + return devlist; +} + +/* freeUPNPDevlist() should be used to + * free the chained list returned by upnpDiscover() */ +LIBSPEC void freeUPNPDevlist(struct UPNPDev * devlist) +{ + struct UPNPDev * next; + while(devlist) + { + next = devlist->pNext; + free(devlist); + devlist = next; + } +} + +static void +url_cpy_or_cat(char * dst, const char * src, int n) +{ + if( (src[0] == 'h') + &&(src[1] == 't') + &&(src[2] == 't') + &&(src[3] == 'p') + &&(src[4] == ':') + &&(src[5] == '/') + &&(src[6] == '/')) + { + strncpy(dst, src, n); + } + else + { + int l = strlen(dst); + if(src[0] != '/') + dst[l++] = '/'; + if(l<=n) + strncpy(dst + l, src, n - l); + } +} + +/* Prepare the Urls for usage... + */ +LIBSPEC void GetUPNPUrls(struct UPNPUrls * urls, struct IGDdatas * data, + const char * descURL) +{ + char * p; + int n1, n2, n3, n4; + n1 = strlen(data->urlbase); + if(n1==0) + n1 = strlen(descURL); + n1 += 2; /* 1 byte more for Null terminator, 1 byte for '/' if needed */ + n2 = n1; n3 = n1; n4 = n1; + n1 += strlen(data->first.scpdurl); + n2 += strlen(data->first.controlurl); + n3 += strlen(data->CIF.controlurl); + n4 += strlen(data->IPv6FC.controlurl); + + urls->ipcondescURL = (char *)malloc(n1); + urls->controlURL = (char *)malloc(n2); + urls->controlURL_CIF = (char *)malloc(n3); + urls->controlURL_6FC = (char *)malloc(n4); + /* maintenant on chope la desc du WANIPConnection */ + if(data->urlbase[0] != '\0') + strncpy(urls->ipcondescURL, data->urlbase, n1); + else + strncpy(urls->ipcondescURL, descURL, n1); + p = strchr(urls->ipcondescURL+7, '/'); + if(p) p[0] = '\0'; + strncpy(urls->controlURL, urls->ipcondescURL, n2); + strncpy(urls->controlURL_CIF, urls->ipcondescURL, n3); + strncpy(urls->controlURL_6FC, urls->ipcondescURL, n4); + + url_cpy_or_cat(urls->ipcondescURL, data->first.scpdurl, n1); + + url_cpy_or_cat(urls->controlURL, data->first.controlurl, n2); + + url_cpy_or_cat(urls->controlURL_CIF, data->CIF.controlurl, n3); + + url_cpy_or_cat(urls->controlURL_6FC, data->IPv6FC.controlurl, n4); + +#ifdef DEBUG + printf("urls->ipcondescURL='%s' %u n1=%d\n", urls->ipcondescURL, + (unsigned)strlen(urls->ipcondescURL), n1); + printf("urls->controlURL='%s' %u n2=%d\n", urls->controlURL, + (unsigned)strlen(urls->controlURL), n2); + printf("urls->controlURL_CIF='%s' %u n3=%d\n", urls->controlURL_CIF, + (unsigned)strlen(urls->controlURL_CIF), n3); + printf("urls->controlURL_6FC='%s' %u n4=%d\n", urls->controlURL_6FC, + (unsigned)strlen(urls->controlURL_6FC), n4); +#endif +} + +LIBSPEC void +FreeUPNPUrls(struct UPNPUrls * urls) +{ + if(!urls) + return; + free(urls->controlURL); + urls->controlURL = 0; + free(urls->ipcondescURL); + urls->ipcondescURL = 0; + free(urls->controlURL_CIF); + urls->controlURL_CIF = 0; + free(urls->controlURL_6FC); + urls->controlURL_6FC = 0; +} + +int +UPNPIGD_IsConnected(struct UPNPUrls * urls, struct IGDdatas * data) +{ + char status[64]; + unsigned int uptime; + status[0] = '\0'; + UPNP_GetStatusInfo(urls->controlURL, data->first.servicetype, + status, &uptime, NULL); + if(0 == strcmp("Connected", status)) + { + return 1; + } + else + return 0; +} + + +/* UPNP_GetValidIGD() : + * return values : + * 0 = NO IGD found + * 1 = A valid connected IGD has been found + * 2 = A valid IGD has been found but it reported as + * not connected + * 3 = an UPnP device has been found but was not recognized as an IGD + * + * In any non zero return case, the urls and data structures + * passed as parameters are set. Donc forget to call FreeUPNPUrls(urls) to + * free allocated memory. + */ +LIBSPEC int +UPNP_GetValidIGD(struct UPNPDev * devlist, + struct UPNPUrls * urls, + struct IGDdatas * data, + char * lanaddr, int lanaddrlen) +{ + char * descXML; + int descXMLsize = 0; + struct UPNPDev * dev; + int ndev = 0; + int state; /* state 1 : IGD connected. State 2 : IGD. State 3 : anything */ + if(!devlist) + { +#ifdef DEBUG + printf("Empty devlist\n"); +#endif + return 0; + } + for(state = 1; state <= 3; state++) + { + for(dev = devlist; dev; dev = dev->pNext) + { + /* we should choose an internet gateway device. + * with st == urn:schemas-upnp-org:device:InternetGatewayDevice:1 */ + descXML = miniwget_getaddr(dev->descURL, &descXMLsize, + lanaddr, lanaddrlen); + if(descXML) + { + ndev++; + memset(data, 0, sizeof(struct IGDdatas)); + memset(urls, 0, sizeof(struct UPNPUrls)); + parserootdesc(descXML, descXMLsize, data); + free(descXML); + descXML = NULL; + if(0==strcmp(data->CIF.servicetype, + "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1") + || state >= 3 ) + { + GetUPNPUrls(urls, data, dev->descURL); + +#ifdef DEBUG + printf("UPNPIGD_IsConnected(%s) = %d\n", + urls->controlURL, + UPNPIGD_IsConnected(urls, data)); +#endif + if((state >= 2) || UPNPIGD_IsConnected(urls, data)) + return state; + FreeUPNPUrls(urls); + if(data->second.servicetype[0] != '\0') { +#ifdef DEBUG + printf("We tried %s, now we try %s !\n", + data->first.servicetype, data->second.servicetype); +#endif + /* swaping WANPPPConnection and WANIPConnection ! */ + memcpy(&data->tmp, &data->first, sizeof(struct IGDdatas_service)); + memcpy(&data->first, &data->second, sizeof(struct IGDdatas_service)); + memcpy(&data->second, &data->tmp, sizeof(struct IGDdatas_service)); + GetUPNPUrls(urls, data, dev->descURL); +#ifdef DEBUG + printf("UPNPIGD_IsConnected(%s) = %d\n", + urls->controlURL, + UPNPIGD_IsConnected(urls, data)); +#endif + if((state >= 2) || UPNPIGD_IsConnected(urls, data)) + return state; + FreeUPNPUrls(urls); + } + } + memset(data, 0, sizeof(struct IGDdatas)); + } +#ifdef DEBUG + else + { + printf("error getting XML description %s\n", dev->descURL); + } +#endif + } + } + return 0; +} + +/* UPNP_GetIGDFromUrl() + * Used when skipping the discovery process. + * return value : + * 0 - Not ok + * 1 - OK */ +int +UPNP_GetIGDFromUrl(const char * rootdescurl, + struct UPNPUrls * urls, + struct IGDdatas * data, + char * lanaddr, int lanaddrlen) +{ + char * descXML; + int descXMLsize = 0; + descXML = miniwget_getaddr(rootdescurl, &descXMLsize, + lanaddr, lanaddrlen); + if(descXML) { + memset(data, 0, sizeof(struct IGDdatas)); + memset(urls, 0, sizeof(struct UPNPUrls)); + parserootdesc(descXML, descXMLsize, data); + free(descXML); + descXML = NULL; + GetUPNPUrls(urls, data, rootdescurl); + return 1; + } else { + return 0; + } +} + diff --git a/libs/miniupnpc/miniupnpc.def b/libs/miniupnpc/miniupnpc.def new file mode 100644 index 000000000..10b9f5800 --- /dev/null +++ b/libs/miniupnpc/miniupnpc.def @@ -0,0 +1,42 @@ +LIBRARY +; miniupnpc library + +EXPORTS +; miniupnpc + upnpDiscover + freeUPNPDevlist + parserootdesc + UPNP_GetValidIGD + UPNP_GetIGDFromUrl + GetUPNPUrls + FreeUPNPUrls +; miniwget + miniwget + miniwget_getaddr +; upnpcommands + UPNP_GetTotalBytesSent + UPNP_GetTotalBytesReceived + UPNP_GetTotalPacketsSent + UPNP_GetTotalPacketsReceived + UPNP_GetStatusInfo + UPNP_GetConnectionTypeInfo + UPNP_GetExternalIPAddress + UPNP_GetLinkLayerMaxBitRates + UPNP_AddPortMapping + UPNP_DeletePortMapping + UPNP_GetPortMappingNumberOfEntries + UPNP_GetSpecificPortMappingEntry + UPNP_GetGenericPortMappingEntry + UPNP_GetListOfPortMappings + UPNP_AddPinhole + UPNP_CheckPinholeWorking + UPNP_UpdatePinhole + UPNP_GetPinholePackets + UPNP_DeletePinhole + UPNP_GetFirewallStatus + UPNP_GetOutboundPinholeTimeout +; upnperrors + strupnperror +; portlistingparse + ParsePortListing + FreePortListing diff --git a/libs/miniupnpc/miniupnpc.h b/libs/miniupnpc/miniupnpc.h new file mode 100644 index 000000000..50df01777 --- /dev/null +++ b/libs/miniupnpc/miniupnpc.h @@ -0,0 +1,121 @@ +/* $Id: miniupnpc.h,v 1.23 2011/04/11 08:21:46 nanard Exp $ */ +/* Project: miniupnp + * http://miniupnp.free.fr/ + * Author: Thomas Bernard + * Copyright (c) 2005-2011 Thomas Bernard + * This software is subjects to the conditions detailed + * in the LICENCE file provided within this distribution */ +#ifndef __MINIUPNPC_H__ +#define __MINIUPNPC_H__ + +#include "declspec.h" +#include "igd_desc_parse.h" + +/* error codes : */ +#define UPNPDISCOVER_SUCCESS (0) +#define UPNPDISCOVER_UNKNOWN_ERROR (-1) +#define UPNPDISCOVER_SOCKET_ERROR (-101) +#define UPNPDISCOVER_MEMORY_ERROR (-102) + +#ifdef __cplusplus +extern "C" { +#endif + +/* Structures definitions : */ +struct UPNParg { const char * elt; const char * val; }; + +char * +simpleUPnPcommand(int, const char *, const char *, + const char *, struct UPNParg *, + int *); + +struct UPNPDev { + struct UPNPDev * pNext; + char * descURL; + char * st; + char buffer[2]; +}; + +/* upnpDiscover() + * discover UPnP devices on the network. + * The discovered devices are returned as a chained list. + * It is up to the caller to free the list with freeUPNPDevlist(). + * delay (in millisecond) is the maximum time for waiting any device + * response. + * If available, device list will be obtained from MiniSSDPd. + * Default path for minissdpd socket will be used if minissdpdsock argument + * is NULL. + * If multicastif is not NULL, it will be used instead of the default + * multicast interface for sending SSDP discover packets. + * If sameport is not null, SSDP packets will be sent from the source port + * 1900 (same as destination port) otherwise system assign a source port. */ +LIBSPEC struct UPNPDev * +upnpDiscover(int delay, const char * multicastif, + const char * minissdpdsock, int sameport, + int ipv6, + int * error); +/* freeUPNPDevlist() + * free list returned by upnpDiscover() */ +LIBSPEC void freeUPNPDevlist(struct UPNPDev * devlist); + +/* parserootdesc() : + * parse root XML description of a UPnP device and fill the IGDdatas + * structure. */ +LIBSPEC void parserootdesc(const char *, int, struct IGDdatas *); + +/* structure used to get fast access to urls + * controlURL: controlURL of the WANIPConnection + * ipcondescURL: url of the description of the WANIPConnection + * controlURL_CIF: controlURL of the WANCommonInterfaceConfig + * controlURL_6FC: controlURL of the WANIPv6FirewallControl + */ +struct UPNPUrls { + char * controlURL; + char * ipcondescURL; + char * controlURL_CIF; + char * controlURL_6FC; +}; + +/* UPNP_GetValidIGD() : + * return values : + * 0 = NO IGD found + * 1 = A valid connected IGD has been found + * 2 = A valid IGD has been found but it reported as + * not connected + * 3 = an UPnP device has been found but was not recognized as an IGD + * + * In any non zero return case, the urls and data structures + * passed as parameters are set. Donc forget to call FreeUPNPUrls(urls) to + * free allocated memory. + */ +LIBSPEC int +UPNP_GetValidIGD(struct UPNPDev * devlist, + struct UPNPUrls * urls, + struct IGDdatas * data, + char * lanaddr, int lanaddrlen); + +/* UPNP_GetIGDFromUrl() + * Used when skipping the discovery process. + * return value : + * 0 - Not ok + * 1 - OK */ +LIBSPEC int +UPNP_GetIGDFromUrl(const char * rootdescurl, + struct UPNPUrls * urls, + struct IGDdatas * data, + char * lanaddr, int lanaddrlen); + +LIBSPEC void GetUPNPUrls(struct UPNPUrls *, struct IGDdatas *, const char *); + +LIBSPEC void FreeUPNPUrls(struct UPNPUrls *); + +/* return 0 or 1 */ +LIBSPEC int UPNPIGD_IsConnected(struct UPNPUrls *, struct IGDdatas *); + + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/libs/miniupnpc/miniupnpcmodule.c b/libs/miniupnpc/miniupnpcmodule.c new file mode 100644 index 000000000..08a61d22f --- /dev/null +++ b/libs/miniupnpc/miniupnpcmodule.c @@ -0,0 +1,507 @@ +/* $Id: miniupnpcmodule.c,v 1.18 2011/04/10 11:21:23 nanard Exp $*/ +/* Project : miniupnp + * Author : Thomas BERNARD + * website : http://miniupnp.tuxfamily.org/ + * copyright (c) 2007-2009 Thomas Bernard + * This software is subjet to the conditions detailed in the + * provided LICENCE file. */ +#include +#define STATICLIB +#include "structmember.h" +#include "miniupnpc.h" +#include "upnpcommands.h" +#include "upnperrors.h" + +/* for compatibility with Python < 2.4 */ +#ifndef Py_RETURN_NONE +#define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None +#endif + +#ifndef Py_RETURN_TRUE +#define Py_RETURN_TRUE return Py_INCREF(Py_True), Py_True +#endif + +#ifndef Py_RETURN_FALSE +#define Py_RETURN_FALSE return Py_INCREF(Py_False), Py_False +#endif + +typedef struct { + PyObject_HEAD + /* Type-specific fields go here. */ + struct UPNPDev * devlist; + struct UPNPUrls urls; + struct IGDdatas data; + unsigned int discoverdelay; /* value passed to upnpDiscover() */ + char lanaddr[40]; /* our ip address on the LAN */ + char * multicastif; + char * minissdpdsocket; +} UPnPObject; + +static PyMemberDef UPnP_members[] = { + {"lanaddr", T_STRING_INPLACE, offsetof(UPnPObject, lanaddr), + READONLY, "ip address on the LAN" + }, + {"discoverdelay", T_UINT, offsetof(UPnPObject, discoverdelay), + 0/*READWRITE*/, "value in ms used to wait for SSDP responses" + }, + /* T_STRING is allways readonly :( */ + {"multicastif", T_STRING, offsetof(UPnPObject, multicastif), + 0, "IP of the network interface to be used for multicast operations" + }, + {"minissdpdsocket", T_STRING, offsetof(UPnPObject, multicastif), + 0, "path of the MiniSSDPd unix socket" + }, + {NULL} +}; + +static void +UPnPObject_dealloc(UPnPObject *self) +{ + freeUPNPDevlist(self->devlist); + FreeUPNPUrls(&self->urls); + self->ob_type->tp_free((PyObject*)self); +} + +static PyObject * +UPnP_discover(UPnPObject *self) +{ + struct UPNPDev * dev; + int i; + PyObject *res = NULL; + if(self->devlist) + { + freeUPNPDevlist(self->devlist); + self->devlist = 0; + } + Py_BEGIN_ALLOW_THREADS + self->devlist = upnpDiscover((int)self->discoverdelay/*timeout in ms*/, + 0/* multicast if*/, + 0/*minissdpd socket*/, + 0/*sameport flag*/, + 0/*ip v6*/, + 0/*error */); + Py_END_ALLOW_THREADS + /* Py_RETURN_NONE ??? */ + for(dev = self->devlist, i = 0; dev; dev = dev->pNext) + i++; + res = Py_BuildValue("i", i); + return res; +} + +static PyObject * +UPnP_selectigd(UPnPObject *self) +{ + int r; +Py_BEGIN_ALLOW_THREADS + r = UPNP_GetValidIGD(self->devlist, &self->urls, &self->data, + self->lanaddr, sizeof(self->lanaddr)); +Py_END_ALLOW_THREADS + if(r) + { + return Py_BuildValue("s", self->urls.controlURL); + } + else + { + /* TODO: have our own exception type ! */ + PyErr_SetString(PyExc_Exception, "No UPnP device discovered"); + return NULL; + } +} + +static PyObject * +UPnP_totalbytesent(UPnPObject *self) +{ + UNSIGNED_INTEGER i; +Py_BEGIN_ALLOW_THREADS + i = UPNP_GetTotalBytesSent(self->urls.controlURL_CIF, + self->data.CIF.servicetype); +Py_END_ALLOW_THREADS + return Py_BuildValue("I", i); +} + +static PyObject * +UPnP_totalbytereceived(UPnPObject *self) +{ + UNSIGNED_INTEGER i; +Py_BEGIN_ALLOW_THREADS + i = UPNP_GetTotalBytesReceived(self->urls.controlURL_CIF, + self->data.CIF.servicetype); +Py_END_ALLOW_THREADS + return Py_BuildValue("I", i); +} + +static PyObject * +UPnP_totalpacketsent(UPnPObject *self) +{ + UNSIGNED_INTEGER i; +Py_BEGIN_ALLOW_THREADS + i = UPNP_GetTotalPacketsSent(self->urls.controlURL_CIF, + self->data.CIF.servicetype); +Py_END_ALLOW_THREADS + return Py_BuildValue("I", i); +} + +static PyObject * +UPnP_totalpacketreceived(UPnPObject *self) +{ + UNSIGNED_INTEGER i; +Py_BEGIN_ALLOW_THREADS + i = UPNP_GetTotalPacketsReceived(self->urls.controlURL_CIF, + self->data.CIF.servicetype); +Py_END_ALLOW_THREADS + return Py_BuildValue("I", i); +} + +static PyObject * +UPnP_statusinfo(UPnPObject *self) +{ + char status[64]; + char lastconnerror[64]; + unsigned int uptime = 0; + int r; + status[0] = '\0'; + lastconnerror[0] = '\0'; +Py_BEGIN_ALLOW_THREADS + r = UPNP_GetStatusInfo(self->urls.controlURL, self->data.first.servicetype, + status, &uptime, lastconnerror); +Py_END_ALLOW_THREADS + if(r==UPNPCOMMAND_SUCCESS) { + return Py_BuildValue("(s,I,s)", status, uptime, lastconnerror); + } else { + /* TODO: have our own exception type ! */ + PyErr_SetString(PyExc_Exception, strupnperror(r)); + return NULL; + } +} + +static PyObject * +UPnP_connectiontype(UPnPObject *self) +{ + char connectionType[64]; + int r; + connectionType[0] = '\0'; +Py_BEGIN_ALLOW_THREADS + r = UPNP_GetConnectionTypeInfo(self->urls.controlURL, + self->data.first.servicetype, + connectionType); +Py_END_ALLOW_THREADS + if(r==UPNPCOMMAND_SUCCESS) { + return Py_BuildValue("s", connectionType); + } else { + /* TODO: have our own exception type ! */ + PyErr_SetString(PyExc_Exception, strupnperror(r)); + return NULL; + } +} + +static PyObject * +UPnP_externalipaddress(UPnPObject *self) +{ + char externalIPAddress[40]; + int r; + externalIPAddress[0] = '\0'; +Py_BEGIN_ALLOW_THREADS + r = UPNP_GetExternalIPAddress(self->urls.controlURL, + self->data.first.servicetype, + externalIPAddress); +Py_END_ALLOW_THREADS + if(r==UPNPCOMMAND_SUCCESS) { + return Py_BuildValue("s", externalIPAddress); + } else { + /* TODO: have our own exception type ! */ + PyErr_SetString(PyExc_Exception, strupnperror(r)); + return NULL; + } +} + +/* AddPortMapping(externalPort, protocol, internalHost, internalPort, desc, + * remoteHost) + * protocol is 'UDP' or 'TCP' */ +static PyObject * +UPnP_addportmapping(UPnPObject *self, PyObject *args) +{ + char extPort[6]; + unsigned short ePort; + char inPort[6]; + unsigned short iPort; + const char * proto; + const char * host; + const char * desc; + const char * remoteHost; + const char * leaseDuration = "0"; + int r; + if (!PyArg_ParseTuple(args, "HssHss", &ePort, &proto, + &host, &iPort, &desc, &remoteHost)) + return NULL; +Py_BEGIN_ALLOW_THREADS + sprintf(extPort, "%hu", ePort); + sprintf(inPort, "%hu", iPort); + r = UPNP_AddPortMapping(self->urls.controlURL, self->data.first.servicetype, + extPort, inPort, host, desc, proto, + remoteHost, leaseDuration); +Py_END_ALLOW_THREADS + if(r==UPNPCOMMAND_SUCCESS) + { + Py_RETURN_TRUE; + } + else + { + // TODO: RAISE an Exception. See upnpcommands.h for errors codes. + // upnperrors.c + //Py_RETURN_FALSE; + /* TODO: have our own exception type ! */ + PyErr_SetString(PyExc_Exception, strupnperror(r)); + return NULL; + } +} + +/* DeletePortMapping(extPort, proto, removeHost='') + * proto = 'UDP', 'TCP' */ +static PyObject * +UPnP_deleteportmapping(UPnPObject *self, PyObject *args) +{ + char extPort[6]; + unsigned short ePort; + const char * proto; + const char * remoteHost = ""; + int r; + if(!PyArg_ParseTuple(args, "Hs|z", &ePort, &proto, &remoteHost)) + return NULL; +Py_BEGIN_ALLOW_THREADS + sprintf(extPort, "%hu", ePort); + r = UPNP_DeletePortMapping(self->urls.controlURL, self->data.first.servicetype, + extPort, proto, remoteHost); +Py_END_ALLOW_THREADS + if(r==UPNPCOMMAND_SUCCESS) { + Py_RETURN_TRUE; + } else { + /* TODO: have our own exception type ! */ + PyErr_SetString(PyExc_Exception, strupnperror(r)); + return NULL; + } +} + +static PyObject * +UPnP_getportmappingnumberofentries(UPnPObject *self) +{ + unsigned int n = 0; + int r; +Py_BEGIN_ALLOW_THREADS + r = UPNP_GetPortMappingNumberOfEntries(self->urls.controlURL, + self->data.first.servicetype, + &n); +Py_END_ALLOW_THREADS + if(r==UPNPCOMMAND_SUCCESS) { + return Py_BuildValue("I", n); + } else { + /* TODO: have our own exception type ! */ + PyErr_SetString(PyExc_Exception, strupnperror(r)); + return NULL; + } +} + +/* GetSpecificPortMapping(ePort, proto) + * proto = 'UDP' or 'TCP' */ +static PyObject * +UPnP_getspecificportmapping(UPnPObject *self, PyObject *args) +{ + char extPort[6]; + unsigned short ePort; + const char * proto; + char intClient[40]; + char intPort[6]; + unsigned short iPort; + char desc[80]; + char enabled[4]; + char leaseDuration[16]; + if(!PyArg_ParseTuple(args, "Hs", &ePort, &proto)) + return NULL; + extPort[0] = '\0'; intClient[0] = '\0'; intPort[0] = '\0'; + desc[0] = '\0'; enabled[0] = '\0'; leaseDuration[0] = '\0'; +Py_BEGIN_ALLOW_THREADS + sprintf(extPort, "%hu", ePort); + UPNP_GetSpecificPortMappingEntry(self->urls.controlURL, + self->data.first.servicetype, + extPort, proto, + intClient, intPort, + desc, enabled, leaseDuration); +Py_END_ALLOW_THREADS + if(intClient[0]) + { + iPort = (unsigned short)atoi(intPort); + return Py_BuildValue("(s,H,s,O,i)", + intClient, iPort, desc, + PyBool_FromLong(atoi(enabled)), + atoi(leaseDuration)); + } + else + { + Py_RETURN_NONE; + } +} + +/* GetGenericPortMapping(index) */ +static PyObject * +UPnP_getgenericportmapping(UPnPObject *self, PyObject *args) +{ + int i, r; + char index[8]; + char intClient[40]; + char intPort[6]; + unsigned short iPort; + char extPort[6]; + unsigned short ePort; + char protocol[4]; + char desc[80]; + char enabled[6]; + char rHost[64]; + char duration[16]; /* lease duration */ + unsigned int dur; + if(!PyArg_ParseTuple(args, "i", &i)) + return NULL; +Py_BEGIN_ALLOW_THREADS + snprintf(index, sizeof(index), "%d", i); + rHost[0] = '\0'; enabled[0] = '\0'; + duration[0] = '\0'; desc[0] = '\0'; + extPort[0] = '\0'; intPort[0] = '\0'; intClient[0] = '\0'; + r = UPNP_GetGenericPortMappingEntry(self->urls.controlURL, + self->data.first.servicetype, + index, + extPort, intClient, intPort, + protocol, desc, enabled, rHost, + duration); +Py_END_ALLOW_THREADS + if(r==UPNPCOMMAND_SUCCESS) + { + ePort = (unsigned short)atoi(extPort); + iPort = (unsigned short)atoi(intPort); + dur = (unsigned int)strtoul(duration, 0, 0); + return Py_BuildValue("(H,s,(s,H),s,s,s,I)", + ePort, protocol, intClient, iPort, + desc, enabled, rHost, dur); + } + else + { + Py_RETURN_NONE; + } +} + +/* miniupnpc.UPnP object Method Table */ +static PyMethodDef UPnP_methods[] = { + {"discover", (PyCFunction)UPnP_discover, METH_NOARGS, + "discover UPnP IGD devices on the network" + }, + {"selectigd", (PyCFunction)UPnP_selectigd, METH_NOARGS, + "select a valid UPnP IGD among discovered devices" + }, + {"totalbytesent", (PyCFunction)UPnP_totalbytesent, METH_NOARGS, + "return the total number of bytes sent by UPnP IGD" + }, + {"totalbytereceived", (PyCFunction)UPnP_totalbytereceived, METH_NOARGS, + "return the total number of bytes received by UPnP IGD" + }, + {"totalpacketsent", (PyCFunction)UPnP_totalpacketsent, METH_NOARGS, + "return the total number of packets sent by UPnP IGD" + }, + {"totalpacketreceived", (PyCFunction)UPnP_totalpacketreceived, METH_NOARGS, + "return the total number of packets received by UPnP IGD" + }, + {"statusinfo", (PyCFunction)UPnP_statusinfo, METH_NOARGS, + "return status and uptime" + }, + {"connectiontype", (PyCFunction)UPnP_connectiontype, METH_NOARGS, + "return IGD WAN connection type" + }, + {"externalipaddress", (PyCFunction)UPnP_externalipaddress, METH_NOARGS, + "return external IP address" + }, + {"addportmapping", (PyCFunction)UPnP_addportmapping, METH_VARARGS, + "add a port mapping" + }, + {"deleteportmapping", (PyCFunction)UPnP_deleteportmapping, METH_VARARGS, + "delete a port mapping" + }, + {"getportmappingnumberofentries", (PyCFunction)UPnP_getportmappingnumberofentries, METH_NOARGS, + "-- non standard --" + }, + {"getspecificportmapping", (PyCFunction)UPnP_getspecificportmapping, METH_VARARGS, + "get details about a specific port mapping entry" + }, + {"getgenericportmapping", (PyCFunction)UPnP_getgenericportmapping, METH_VARARGS, + "get all details about the port mapping at index" + }, + {NULL} /* Sentinel */ +}; + +static PyTypeObject UPnPType = { + PyObject_HEAD_INIT(NULL) + 0, /*ob_size*/ + "miniupnpc.UPnP", /*tp_name*/ + sizeof(UPnPObject), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + (destructor)UPnPObject_dealloc,/*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + 0, /*tp_compare*/ + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash */ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT, /*tp_flags*/ + "UPnP objects", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + UPnP_methods, /* tp_methods */ + UPnP_members, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0,/*(initproc)UPnP_init,*/ /* tp_init */ + 0, /* tp_alloc */ +#ifndef WIN32 + PyType_GenericNew,/*UPnP_new,*/ /* tp_new */ +#else + 0, +#endif +}; + +/* module methods */ +static PyMethodDef miniupnpc_methods[] = { + {NULL} /* Sentinel */ +}; + +#ifndef PyMODINIT_FUNC /* declarations for DLL import/export */ +#define PyMODINIT_FUNC void +#endif +PyMODINIT_FUNC +initminiupnpc(void) +{ + PyObject* m; + +#ifdef WIN32 + UPnPType.tp_new = PyType_GenericNew; +#endif + if (PyType_Ready(&UPnPType) < 0) + return; + + m = Py_InitModule3("miniupnpc", miniupnpc_methods, + "miniupnpc module."); + + Py_INCREF(&UPnPType); + PyModule_AddObject(m, "UPnP", (PyObject *)&UPnPType); +} + diff --git a/libs/miniupnpc/miniupnpcstrings.h.cmake b/libs/miniupnpc/miniupnpcstrings.h.cmake new file mode 100644 index 000000000..a3726350c --- /dev/null +++ b/libs/miniupnpc/miniupnpcstrings.h.cmake @@ -0,0 +1,7 @@ +#ifndef __MINIUPNPCSTRINGS_H__ +#define __MINIUPNPCSTRINGS_H__ + +#define OS_STRING "${CMAKE_SYSTEM_NAME}" +#define MINIUPNPC_VERSION_STRING "${MINIUPNPC_VERSION}" + +#endif diff --git a/libs/miniupnpc/miniupnpcstrings.h.in b/libs/miniupnpc/miniupnpcstrings.h.in new file mode 100644 index 000000000..201c9a862 --- /dev/null +++ b/libs/miniupnpc/miniupnpcstrings.h.in @@ -0,0 +1,15 @@ +/* $Id: miniupnpcstrings.h.in,v 1.4 2011/01/04 11:41:53 nanard Exp $ */ +/* Project: miniupnp + * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ + * Author: Thomas Bernard + * Copyright (c) 2005-2011 Thomas Bernard + * This software is subjects to the conditions detailed + * in the LICENCE file provided within this distribution */ +#ifndef __MINIUPNPCSTRINGS_H__ +#define __MINIUPNPCSTRINGS_H__ + +#define OS_STRING "OS/version" +#define MINIUPNPC_VERSION_STRING "version" + +#endif + diff --git a/libs/miniupnpc/miniupnpctypes.h b/libs/miniupnpc/miniupnpctypes.h new file mode 100644 index 000000000..86081c3cc --- /dev/null +++ b/libs/miniupnpc/miniupnpctypes.h @@ -0,0 +1,19 @@ +/* $Id: miniupnpctypes.h,v 1.1 2011/02/15 11:10:40 nanard Exp $ */ +/* Miniupnp project : http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org + * Author : Thomas Bernard + * Copyright (c) 2011 Thomas Bernard + * This software is subject to the conditions detailed in the + * LICENCE file provided within this distribution */ +#ifndef __MINIUPNPCTYPES_H__ +#define __MINIUPNPCTYPES_H__ + +#if (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L) +#define UNSIGNED_INTEGER unsigned long long +#define STRTOUI strtoull +#else +#define UNSIGNED_INTEGER unsigned int +#define STRTOUI strtoul +#endif + +#endif + diff --git a/libs/miniupnpc/miniwget.c b/libs/miniupnpc/miniwget.c new file mode 100644 index 000000000..7c9cb3ad5 --- /dev/null +++ b/libs/miniupnpc/miniwget.c @@ -0,0 +1,524 @@ +/* $Id: miniwget.c,v 1.52 2011/06/17 22:59:42 nanard Exp $ */ +/* Project : miniupnp + * Author : Thomas Bernard + * Copyright (c) 2005-2011 Thomas Bernard + * This software is subject to the conditions detailed in the + * LICENCE file provided in this distribution. */ + +#include +#include +#include +#include +#ifdef WIN32 +#include +#include +#include +#define MAXHOSTNAMELEN 64 +#define MIN(x,y) (((x)<(y))?(x):(y)) +#define snprintf _snprintf +#define socklen_t int +#ifndef strncasecmp +#if defined(_MSC_VER) && (_MSC_VER >= 1400) +#define strncasecmp _memicmp +#else /* defined(_MSC_VER) && (_MSC_VER >= 1400) */ +#define strncasecmp memicmp +#endif /* defined(_MSC_VER) && (_MSC_VER >= 1400) */ +#endif /* #ifndef strncasecmp */ +#else /* #ifdef WIN32 */ +#include +#include +#if defined(__amigaos__) && !defined(__amigaos4__) +#define socklen_t int +#else /* #if defined(__amigaos__) && !defined(__amigaos4__) */ +#include +#endif /* #else defined(__amigaos__) && !defined(__amigaos4__) */ +#include +#include +#include +#define closesocket close +/* defining MINIUPNPC_IGNORE_EINTR enable the ignore of interruptions + * during the connect() call */ +#define MINIUPNPC_IGNORE_EINTR +#endif /* #else WIN32 */ +#if defined(__sun) || defined(sun) +#define MIN(x,y) (((x)<(y))?(x):(y)) +#endif + +#include "miniupnpcstrings.h" +#include "miniwget.h" +#include "connecthostport.h" +#include "receivedata.h" + +/* + * Read a HTTP response from a socket. + * Process Content-Length and Transfer-encoding headers. + * return a pointer to the content buffer, which length is saved + * to the length parameter. + */ +void * +getHTTPResponse(int s, int * size) +{ + char buf[2048]; + int n; + int endofheaders = 0; + int chunked = 0; + int content_length = -1; + unsigned int chunksize = 0; + unsigned int bytestocopy = 0; + /* buffers : */ + char * header_buf; + int header_buf_len = 2048; + int header_buf_used = 0; + char * content_buf; + int content_buf_len = 2048; + int content_buf_used = 0; + char chunksize_buf[32]; + int chunksize_buf_index; + + header_buf = malloc(header_buf_len); + content_buf = malloc(content_buf_len); + chunksize_buf[0] = '\0'; + chunksize_buf_index = 0; + + while((n = receivedata(s, buf, 2048, 5000)) > 0) + { + if(endofheaders == 0) + { + int i; + int linestart=0; + int colon=0; + int valuestart=0; + if(header_buf_used + n > header_buf_len) { + header_buf = realloc(header_buf, header_buf_used + n); + header_buf_len = header_buf_used + n; + } + memcpy(header_buf + header_buf_used, buf, n); + header_buf_used += n; + /* search for CR LF CR LF (end of headers) + * recognize also LF LF */ + i = 0; + while(i < (header_buf_used-1) && (endofheaders == 0)) { + if(header_buf[i] == '\r') { + i++; + if(header_buf[i] == '\n') { + i++; + if(i < header_buf_used && header_buf[i] == '\r') { + i++; + if(i < header_buf_used && header_buf[i] == '\n') { + endofheaders = i+1; + } + } + } + } else if(header_buf[i] == '\n') { + i++; + if(header_buf[i] == '\n') { + endofheaders = i+1; + } + } + i++; + } + if(endofheaders == 0) + continue; + /* parse header lines */ + for(i = 0; i < endofheaders - 1; i++) { + if(colon <= linestart && header_buf[i]==':') + { + colon = i; + while(i < (endofheaders-1) + && (header_buf[i+1] == ' ' || header_buf[i+1] == '\t')) + i++; + valuestart = i + 1; + } + /* detecting end of line */ + else if(header_buf[i]=='\r' || header_buf[i]=='\n') + { + if(colon > linestart && valuestart > colon) + { +#ifdef DEBUG + printf("header='%.*s', value='%.*s'\n", + colon-linestart, header_buf+linestart, + i-valuestart, header_buf+valuestart); +#endif + if(0==strncasecmp(header_buf+linestart, "content-length", colon-linestart)) + { + content_length = atoi(header_buf+valuestart); +#ifdef DEBUG + printf("Content-Length: %d\n", content_length); +#endif + } + else if(0==strncasecmp(header_buf+linestart, "transfer-encoding", colon-linestart) + && 0==strncasecmp(header_buf+valuestart, "chunked", 7)) + { +#ifdef DEBUG + printf("chunked transfer-encoding!\n"); +#endif + chunked = 1; + } + } + while(header_buf[i]=='\r' || header_buf[i] == '\n') + i++; + linestart = i; + colon = linestart; + valuestart = 0; + } + } + /* copy the remaining of the received data back to buf */ + n = header_buf_used - endofheaders; + memcpy(buf, header_buf + endofheaders, n); + /* if(headers) */ + } + if(endofheaders) + { + /* content */ + if(chunked) + { + int i = 0; + while(i < n) + { + if(chunksize == 0) + { + /* reading chunk size */ + if(chunksize_buf_index == 0) { + /* skipping any leading CR LF */ + if(i= '0' + && chunksize_buf[j] <= '9') + chunksize = (chunksize << 4) + (chunksize_buf[j] - '0'); + else + chunksize = (chunksize << 4) + ((chunksize_buf[j] | 32) - 'a' + 10); + } + chunksize_buf[0] = '\0'; + chunksize_buf_index = 0; + i++; + } else { + /* not finished to get chunksize */ + continue; + } +#ifdef DEBUG + printf("chunksize = %u (%x)\n", chunksize, chunksize); +#endif + if(chunksize == 0) + { +#ifdef DEBUG + printf("end of HTTP content - %d %d\n", i, n); + /*printf("'%.*s'\n", n-i, buf+i);*/ +#endif + goto end_of_stream; + } + } + bytestocopy = ((int)chunksize < n - i)?chunksize:(n - i); + if((int)(content_buf_used + bytestocopy) > content_buf_len) + { + if(content_length >= content_buf_used + (int)bytestocopy) { + content_buf_len = content_length; + } else { + content_buf_len = content_buf_used + (int)bytestocopy; + } + content_buf = (char *)realloc((void *)content_buf, + content_buf_len); + } + memcpy(content_buf + content_buf_used, buf + i, bytestocopy); + content_buf_used += bytestocopy; + i += bytestocopy; + chunksize -= bytestocopy; + } + } + else + { + /* not chunked */ + if(content_length > 0 + && (content_buf_used + n) > content_length) { + /* skipping additional bytes */ + n = content_length - content_buf_used; + } + if(content_buf_used + n > content_buf_len) + { + if(content_length >= content_buf_used + n) { + content_buf_len = content_length; + } else { + content_buf_len = content_buf_used + n; + } + content_buf = (char *)realloc((void *)content_buf, + content_buf_len); + } + memcpy(content_buf + content_buf_used, buf, n); + content_buf_used += n; + } + } + /* use the Content-Length header value if available */ + if(content_length > 0 && content_buf_used >= content_length) + { +#ifdef DEBUG + printf("End of HTTP content\n"); +#endif + break; + } + } +end_of_stream: + free(header_buf); header_buf = NULL; + *size = content_buf_used; + if(content_buf_used == 0) + { + free(content_buf); + content_buf = NULL; + } + return content_buf; +} + +/* miniwget3() : + * do all the work. + * Return NULL if something failed. */ +static void * +miniwget3(const char * url, const char * host, + unsigned short port, const char * path, + int * size, char * addr_str, int addr_str_len, + const char * httpversion) +{ + char buf[2048]; + int s; + int n = -1; + int len; + int sent; + void * content; + + *size = 0; + s = connecthostport(host, port); + if(s < 0) + return NULL; + + /* get address for caller ! */ + if(addr_str) + { + struct sockaddr_storage saddr; + socklen_t saddrlen; + + saddrlen = sizeof(saddr); + if(getsockname(s, (struct sockaddr *)&saddr, &saddrlen) < 0) + { + perror("getsockname"); + } + else + { +#if defined(__amigaos__) && !defined(__amigaos4__) + /* using INT WINAPI WSAAddressToStringA(LPSOCKADDR, DWORD, LPWSAPROTOCOL_INFOA, LPSTR, LPDWORD); + * But his function make a string with the port : nn.nn.nn.nn:port */ +/* if(WSAAddressToStringA((SOCKADDR *)&saddr, sizeof(saddr), + NULL, addr_str, (DWORD *)&addr_str_len)) + { + printf("WSAAddressToStringA() failed : %d\n", WSAGetLastError()); + }*/ + /* the following code is only compatible with ip v4 addresses */ + strncpy(addr_str, inet_ntoa(((struct sockaddr_in *)&saddr)->sin_addr), addr_str_len); +#else +#if 0 + if(saddr.sa_family == AF_INET6) { + inet_ntop(AF_INET6, + &(((struct sockaddr_in6 *)&saddr)->sin6_addr), + addr_str, addr_str_len); + } else { + inet_ntop(AF_INET, + &(((struct sockaddr_in *)&saddr)->sin_addr), + addr_str, addr_str_len); + } +#endif +#ifndef NO_GETADDRINFO + /* getnameinfo return ip v6 address with the scope identifier + * such as : 2a01:e35:8b2b:7330::%4281128194 */ + n = getnameinfo((const struct sockaddr *)&saddr, saddrlen, + addr_str, addr_str_len, + NULL, 0, + NI_NUMERICHOST | NI_NUMERICSERV); +#endif + if(n != 0) { +#ifdef WIN32 + fprintf(stderr, "getnameinfo() failed : %d\n", n); +#else + fprintf(stderr, "getnameinfo() failed : %s\n", gai_strerror(n)); +#endif + } +#endif + } +#ifdef DEBUG + printf("address miniwget : %s\n", addr_str); +#endif + } + + len = snprintf(buf, sizeof(buf), + "GET %s HTTP/%s\r\n" + "Host: %s:%d\r\n" + "Connection: Close\r\n" + "User-Agent: " OS_STRING ", UPnP/1.0, MiniUPnPc/" MINIUPNPC_VERSION_STRING "\r\n" + + "\r\n", + path, httpversion, host, port); + sent = 0; + /* sending the HTTP request */ + while(sent < len) + { + n = send(s, buf+sent, len-sent, 0); + if(n < 0) + { + perror("send"); + closesocket(s); + return NULL; + } + else + { + sent += n; + } + } + content = getHTTPResponse(s, size); + closesocket(s); + return content; +} + +/* miniwget2() : + * Call miniwget3(); retry with HTTP/1.1 if 1.0 fails. */ +static void * +miniwget2(const char * url, const char * host, + unsigned short port, const char * path, + int * size, char * addr_str, int addr_str_len) +{ + char * respbuffer; + + respbuffer = miniwget3(url, host, port, path, size, addr_str, addr_str_len, "1.1"); +/* + respbuffer = miniwget3(url, host, port, path, size, addr_str, addr_str_len, "1.0"); + if (*size == 0) + { +#ifdef DEBUG + printf("Retrying with HTTP/1.1\n"); +#endif + free(respbuffer); + respbuffer = miniwget3(url, host, port, path, size, addr_str, addr_str_len, "1.1"); + } +*/ + return respbuffer; +} + + + + +/* parseURL() + * arguments : + * url : source string not modified + * hostname : hostname destination string (size of MAXHOSTNAMELEN+1) + * port : port (destination) + * path : pointer to the path part of the URL + * + * Return values : + * 0 - Failure + * 1 - Success */ +int parseURL(const char * url, char * hostname, unsigned short * port, char * * path) +{ + char * p1, *p2, *p3; + if(!url) + return 0; + p1 = strstr(url, "://"); + if(!p1) + return 0; + p1 += 3; + if( (url[0]!='h') || (url[1]!='t') + ||(url[2]!='t') || (url[3]!='p')) + return 0; + memset(hostname, 0, MAXHOSTNAMELEN + 1); + if(*p1 == '[') + { + /* IP v6 : http://[2a00:1450:8002::6a]/path/abc */ + p2 = strchr(p1, ']'); + p3 = strchr(p1, '/'); + if(p2 && p3) + { + p2++; + strncpy(hostname, p1, MIN(MAXHOSTNAMELEN, (int)(p2-p1))); + if(*p2 == ':') + { + *port = 0; + p2++; + while( (*p2 >= '0') && (*p2 <= '9')) + { + *port *= 10; + *port += (unsigned short)(*p2 - '0'); + p2++; + } + } + else + { + *port = 80; + } + *path = p3; + return 1; + } + } + p2 = strchr(p1, ':'); + p3 = strchr(p1, '/'); + if(!p3) + return 0; + if(!p2 || (p2>p3)) + { + strncpy(hostname, p1, MIN(MAXHOSTNAMELEN, (int)(p3-p1))); + *port = 80; + } + else + { + strncpy(hostname, p1, MIN(MAXHOSTNAMELEN, (int)(p2-p1))); + *port = 0; + p2++; + while( (*p2 >= '0') && (*p2 <= '9')) + { + *port *= 10; + *port += (unsigned short)(*p2 - '0'); + p2++; + } + } + *path = p3; + return 1; +} + +void * miniwget(const char * url, int * size) +{ + unsigned short port; + char * path; + /* protocol://host:port/chemin */ + char hostname[MAXHOSTNAMELEN+1]; + *size = 0; + if(!parseURL(url, hostname, &port, &path)) + return NULL; +#ifdef DEBUG + printf("parsed url : hostname='%s' port=%hu path='%s'\n", hostname, port, path); +#endif + return miniwget2(url, hostname, port, path, size, 0, 0); +} + +void * miniwget_getaddr(const char * url, int * size, char * addr, int addrlen) +{ + unsigned short port; + char * path; + /* protocol://host:port/chemin */ + char hostname[MAXHOSTNAMELEN+1]; + *size = 0; + if(addr) + addr[0] = '\0'; + if(!parseURL(url, hostname, &port, &path)) + return NULL; +#ifdef DEBUG + printf("parsed url : hostname='%s' port=%hu path='%s'\n", hostname, port, path); +#endif + return miniwget2(url, hostname, port, path, size, addr, addrlen); +} + diff --git a/libs/miniupnpc/miniwget.h b/libs/miniupnpc/miniwget.h new file mode 100644 index 000000000..8314b4000 --- /dev/null +++ b/libs/miniupnpc/miniwget.h @@ -0,0 +1,30 @@ +/* $Id: miniwget.h,v 1.6 2010/12/09 16:11:33 nanard Exp $ */ +/* Project : miniupnp + * Author : Thomas Bernard + * Copyright (c) 2005 Thomas Bernard + * This software is subject to the conditions detailed in the + * LICENCE file provided in this distribution. + * */ +#ifndef __MINIWGET_H__ +#define __MINIWGET_H__ + +#include "declspec.h" + +#ifdef __cplusplus +extern "C" { +#endif + +LIBSPEC void * getHTTPResponse(int s, int * size); + +LIBSPEC void * miniwget(const char *, int *); + +LIBSPEC void * miniwget_getaddr(const char *, int *, char *, int); + +int parseURL(const char *, char *, unsigned short *, char * *); + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/libs/miniupnpc/minixml.c b/libs/miniupnpc/minixml.c new file mode 100644 index 000000000..8b5594c88 --- /dev/null +++ b/libs/miniupnpc/minixml.c @@ -0,0 +1,216 @@ +/* $Id: minixml.c,v 1.9 2011/02/07 13:44:57 nanard Exp $ */ +/* minixml.c : the minimum size a xml parser can be ! */ +/* Project : miniupnp + * webpage: http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ + * Author : Thomas Bernard + +Copyright (c) 2005-2011, Thomas BERNARD +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. + * The name of the author may not be used to endorse or promote products + derived from this software without specific prior written permission. + +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 OWNER 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 +#include "minixml.h" + +/* parseatt : used to parse the argument list + * return 0 (false) in case of success and -1 (true) if the end + * of the xmlbuffer is reached. */ +static int parseatt(struct xmlparser * p) +{ + const char * attname; + int attnamelen; + const char * attvalue; + int attvaluelen; + while(p->xml < p->xmlend) + { + if(*p->xml=='/' || *p->xml=='>') + return 0; + if( !IS_WHITE_SPACE(*p->xml) ) + { + char sep; + attname = p->xml; + attnamelen = 0; + while(*p->xml!='=' && !IS_WHITE_SPACE(*p->xml) ) + { + attnamelen++; p->xml++; + if(p->xml >= p->xmlend) + return -1; + } + while(*(p->xml++) != '=') + { + if(p->xml >= p->xmlend) + return -1; + } + while(IS_WHITE_SPACE(*p->xml)) + { + p->xml++; + if(p->xml >= p->xmlend) + return -1; + } + sep = *p->xml; + if(sep=='\'' || sep=='\"') + { + p->xml++; + if(p->xml >= p->xmlend) + return -1; + attvalue = p->xml; + attvaluelen = 0; + while(*p->xml != sep) + { + attvaluelen++; p->xml++; + if(p->xml >= p->xmlend) + return -1; + } + } + else + { + attvalue = p->xml; + attvaluelen = 0; + while( !IS_WHITE_SPACE(*p->xml) + && *p->xml != '>' && *p->xml != '/') + { + attvaluelen++; p->xml++; + if(p->xml >= p->xmlend) + return -1; + } + } + /*printf("%.*s='%.*s'\n", + attnamelen, attname, attvaluelen, attvalue);*/ + if(p->attfunc) + p->attfunc(p->data, attname, attnamelen, attvalue, attvaluelen); + } + p->xml++; + } + return -1; +} + +/* parseelt parse the xml stream and + * call the callback functions when needed... */ +static void parseelt(struct xmlparser * p) +{ + int i; + const char * elementname; + while(p->xml < (p->xmlend - 1)) + { + if((p->xml)[0]=='<' && (p->xml)[1]!='?') + { + i = 0; elementname = ++p->xml; + while( !IS_WHITE_SPACE(*p->xml) + && (*p->xml!='>') && (*p->xml!='/') + ) + { + i++; p->xml++; + if (p->xml >= p->xmlend) + return; + /* to ignore namespace : */ + if(*p->xml==':') + { + i = 0; + elementname = ++p->xml; + } + } + if(i>0) + { + if(p->starteltfunc) + p->starteltfunc(p->data, elementname, i); + if(parseatt(p)) + return; + if(*p->xml!='/') + { + const char * data; + i = 0; data = ++p->xml; + if (p->xml >= p->xmlend) + return; + while( IS_WHITE_SPACE(*p->xml) ) + { + i++; p->xml++; + if (p->xml >= p->xmlend) + return; + } + if(memcmp(p->xml, "xml += 9; + data = p->xml; + i = 0; + while(memcmp(p->xml, "]]>", 3) != 0) + { + i++; p->xml++; + if ((p->xml + 3) >= p->xmlend) + return; + } + if(i>0 && p->datafunc) + p->datafunc(p->data, data, i); + while(*p->xml!='<') + { + p->xml++; + if (p->xml >= p->xmlend) + return; + } + } + else + { + while(*p->xml!='<') + { + i++; p->xml++; + if ((p->xml + 1) >= p->xmlend) + return; + } + if(i>0 && p->datafunc && *(p->xml + 1) == '/') + p->datafunc(p->data, data, i); + } + } + } + else if(*p->xml == '/') + { + i = 0; elementname = ++p->xml; + if (p->xml >= p->xmlend) + return; + while((*p->xml != '>')) + { + i++; p->xml++; + if (p->xml >= p->xmlend) + return; + } + if(p->endeltfunc) + p->endeltfunc(p->data, elementname, i); + p->xml++; + } + } + else + { + p->xml++; + } + } +} + +/* the parser must be initialized before calling this function */ +void parsexml(struct xmlparser * parser) +{ + parser->xml = parser->xmlstart; + parser->xmlend = parser->xmlstart + parser->xmlsize; + parseelt(parser); +} + + diff --git a/libs/miniupnpc/minixml.h b/libs/miniupnpc/minixml.h new file mode 100644 index 000000000..857c70ee9 --- /dev/null +++ b/libs/miniupnpc/minixml.h @@ -0,0 +1,37 @@ +/* $Id: minixml.h,v 1.6 2006/11/30 11:47:21 nanard Exp $ */ +/* minimal xml parser + * + * Project : miniupnp + * Website : http://miniupnp.free.fr/ + * Author : Thomas Bernard + * Copyright (c) 2005 Thomas Bernard + * This software is subject to the conditions detailed in the + * LICENCE file provided in this distribution. + * */ +#ifndef __MINIXML_H__ +#define __MINIXML_H__ +#define IS_WHITE_SPACE(c) ((c==' ') || (c=='\t') || (c=='\r') || (c=='\n')) + +/* if a callback function pointer is set to NULL, + * the function is not called */ +struct xmlparser { + const char *xmlstart; + const char *xmlend; + const char *xml; /* pointer to current character */ + int xmlsize; + void * data; + void (*starteltfunc) (void *, const char *, int); + void (*endeltfunc) (void *, const char *, int); + void (*datafunc) (void *, const char *, int); + void (*attfunc) (void *, const char *, int, const char *, int); +}; + +/* parsexml() + * the xmlparser structure must be initialized before the call + * the following structure members have to be initialized : + * xmlstart, xmlsize, data, *func + * xml is for internal usage, xmlend is computed automatically */ +void parsexml(struct xmlparser *); + +#endif + diff --git a/libs/miniupnpc/minixmlvalid.c b/libs/miniupnpc/minixmlvalid.c new file mode 100644 index 000000000..766211bcf --- /dev/null +++ b/libs/miniupnpc/minixmlvalid.c @@ -0,0 +1,156 @@ +/* $Id: minixmlvalid.c,v 1.4 2011/02/07 13:44:57 nanard Exp $ */ +/* MiniUPnP Project + * http://miniupnp.tuxfamily.org/ or http://miniupnp.free.fr/ + * minixmlvalid.c : + * validation program for the minixml parser + * + * (c) 2006-2011 Thomas Bernard */ + +#include +#include +#include +#include "minixml.h" + +/* xml event structure */ +struct event { + enum { ELTSTART, ELTEND, ATT, CHARDATA } type; + const char * data; + int len; +}; + +struct eventlist { + int n; + struct event * events; +}; + +/* compare 2 xml event lists + * return 0 if the two lists are equals */ +int evtlistcmp(struct eventlist * a, struct eventlist * b) +{ + int i; + struct event * ae, * be; + if(a->n != b->n) + { + printf("event number not matching : %d != %d\n", a->n, b->n); + //return 1; + } + for(i=0; in; i++) + { + ae = a->events + i; + be = b->events + i; + if( (ae->type != be->type) + ||(ae->len != be->len) + ||memcmp(ae->data, be->data, ae->len)) + { + printf("Found a difference : %d '%.*s' != %d '%.*s'\n", + ae->type, ae->len, ae->data, + be->type, be->len, be->data); + return 1; + } + } + return 0; +} + +/* Test data */ +static const char xmldata[] = +"\n" +" " +"character data" +" \n \t" +"" +"\nstuff !\n ]]> \n\n" +" \tchardata1 chardata2 " +""; + +static const struct event evtref[] = +{ + {ELTSTART, "xmlroot", 7}, + {ELTSTART, "elt1", 4}, + /* attributes */ + {CHARDATA, "character data", 14}, + {ELTEND, "elt1", 4}, + {ELTSTART, "elt1b", 5}, + {ELTSTART, "elt1", 4}, + {CHARDATA, " stuff !\n ", 16}, + {ELTEND, "elt1", 4}, + {ELTSTART, "elt2a", 5}, + {ELTSTART, "elt2b", 5}, + {CHARDATA, "chardata1", 9}, + {ELTEND, "elt2b", 5}, + {ELTSTART, "elt2b", 5}, + {CHARDATA, " chardata2 ", 11}, + {ELTEND, "elt2b", 5}, + {ELTEND, "elt2a", 5}, + {ELTEND, "xmlroot", 7} +}; + +void startelt(void * data, const char * p, int l) +{ + struct eventlist * evtlist = data; + struct event * evt; + evt = evtlist->events + evtlist->n; + /*printf("startelt : %.*s\n", l, p);*/ + evt->type = ELTSTART; + evt->data = p; + evt->len = l; + evtlist->n++; +} + +void endelt(void * data, const char * p, int l) +{ + struct eventlist * evtlist = data; + struct event * evt; + evt = evtlist->events + evtlist->n; + /*printf("endelt : %.*s\n", l, p);*/ + evt->type = ELTEND; + evt->data = p; + evt->len = l; + evtlist->n++; +} + +void chardata(void * data, const char * p, int l) +{ + struct eventlist * evtlist = data; + struct event * evt; + evt = evtlist->events + evtlist->n; + /*printf("chardata : '%.*s'\n", l, p);*/ + evt->type = CHARDATA; + evt->data = p; + evt->len = l; + evtlist->n++; +} + +int testxmlparser(const char * xml, int size) +{ + int r; + struct eventlist evtlist; + struct eventlist evtlistref; + struct xmlparser parser; + evtlist.n = 0; + evtlist.events = malloc(sizeof(struct event)*100); + memset(&parser, 0, sizeof(parser)); + parser.xmlstart = xml; + parser.xmlsize = size; + parser.data = &evtlist; + parser.starteltfunc = startelt; + parser.endeltfunc = endelt; + parser.datafunc = chardata; + parsexml(&parser); + printf("%d events\n", evtlist.n); + /* compare */ + evtlistref.n = sizeof(evtref)/sizeof(struct event); + evtlistref.events = (struct event *)evtref; + r = evtlistcmp(&evtlistref, &evtlist); + free(evtlist.events); + return r; +} + +int main(int argc, char * * argv) +{ + int r; + r = testxmlparser(xmldata, sizeof(xmldata)-1); + if(r) + printf("minixml validation test failed\n"); + return r; +} + diff --git a/libs/miniupnpc/msvc/miniupnpc.sln b/libs/miniupnpc/msvc/miniupnpc.sln new file mode 100644 index 000000000..405d09a26 --- /dev/null +++ b/libs/miniupnpc/msvc/miniupnpc.sln @@ -0,0 +1,29 @@ + +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual C++ Express 2008 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "miniupnpc", "miniupnpc.vcproj", "{D28CE435-CB33-4BAE-8A52-C6EF915956F5}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "upnpc-static", "upnpc-static.vcproj", "{469E1CF6-08A2-4B7B-A2AA-5BDB089857C1}" + ProjectSection(ProjectDependencies) = postProject + {D28CE435-CB33-4BAE-8A52-C6EF915956F5} = {D28CE435-CB33-4BAE-8A52-C6EF915956F5} + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D28CE435-CB33-4BAE-8A52-C6EF915956F5}.Debug|Win32.ActiveCfg = Debug|Win32 + {D28CE435-CB33-4BAE-8A52-C6EF915956F5}.Debug|Win32.Build.0 = Debug|Win32 + {D28CE435-CB33-4BAE-8A52-C6EF915956F5}.Release|Win32.ActiveCfg = Release|Win32 + {D28CE435-CB33-4BAE-8A52-C6EF915956F5}.Release|Win32.Build.0 = Release|Win32 + {469E1CF6-08A2-4B7B-A2AA-5BDB089857C1}.Debug|Win32.ActiveCfg = Debug|Win32 + {469E1CF6-08A2-4B7B-A2AA-5BDB089857C1}.Debug|Win32.Build.0 = Debug|Win32 + {469E1CF6-08A2-4B7B-A2AA-5BDB089857C1}.Release|Win32.ActiveCfg = Release|Win32 + {469E1CF6-08A2-4B7B-A2AA-5BDB089857C1}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/libs/miniupnpc/msvc/miniupnpc.vcproj b/libs/miniupnpc/msvc/miniupnpc.vcproj new file mode 100644 index 000000000..cce2de576 --- /dev/null +++ b/libs/miniupnpc/msvc/miniupnpc.vcproj @@ -0,0 +1,271 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/miniupnpc/msvc/upnpc-static.vcproj b/libs/miniupnpc/msvc/upnpc-static.vcproj new file mode 100644 index 000000000..37fbbca27 --- /dev/null +++ b/libs/miniupnpc/msvc/upnpc-static.vcproj @@ -0,0 +1,195 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/miniupnpc/portlistingparse.c b/libs/miniupnpc/portlistingparse.c new file mode 100644 index 000000000..e09e80f39 --- /dev/null +++ b/libs/miniupnpc/portlistingparse.c @@ -0,0 +1,157 @@ +/* $Id: portlistingparse.c,v 1.4 2011/03/18 11:02:17 nanard Exp $ */ +/* MiniUPnP project + * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ + * (c) 2011 Thomas Bernard + * This software is subject to the conditions detailed + * in the LICENCE file provided within the distribution */ +#include +#include +#include "portlistingparse.h" +#include "minixml.h" + +/* list of the elements */ +static const struct { + const portMappingElt code; + const char * const str; +} elements[] = { + { PortMappingEntry, "PortMappingEntry"}, + { NewRemoteHost, "NewRemoteHost"}, + { NewExternalPort, "NewExternalPort"}, + { NewProtocol, "NewProtocol"}, + { NewInternalPort, "NewInternalPort"}, + { NewInternalClient, "NewInternalClient"}, + { NewEnabled, "NewEnabled"}, + { NewDescription, "NewDescription"}, + { NewLeaseTime, "NewLeaseTime"}, + { PortMappingEltNone, NULL} +}; + +/* Helper function */ +static UNSIGNED_INTEGER +atoui(const char * p, int l) +{ + UNSIGNED_INTEGER r = 0; + while(l > 0 && *p) + { + if(*p >= '0' && *p <= '9') + r = r*10 + (*p - '0'); + else + break; + p++; + l--; + } + return r; +} + +/* Start element handler */ +static void +startelt(void * d, const char * name, int l) +{ + int i; + struct PortMappingParserData * pdata = (struct PortMappingParserData *)d; + pdata->curelt = PortMappingEltNone; + for(i = 0; elements[i].str; i++) + { + if(memcmp(name, elements[i].str, l) == 0) + { + pdata->curelt = elements[i].code; + break; + } + } + if(pdata->curelt == PortMappingEntry) + { + struct PortMapping * pm; + pm = calloc(1, sizeof(struct PortMapping)); + LIST_INSERT_HEAD( &(pdata->head), pm, entries); + } +} + +/* End element handler */ +static void +endelt(void * d, const char * name, int l) +{ + struct PortMappingParserData * pdata = (struct PortMappingParserData *)d; + pdata->curelt = PortMappingEltNone; +} + +/* Data handler */ +static void +data(void * d, const char * data, int l) +{ + struct PortMapping * pm; + struct PortMappingParserData * pdata = (struct PortMappingParserData *)d; + pm = pdata->head.lh_first; + if(!pm) + return; + if(l > 63) + l = 63; + switch(pdata->curelt) + { + case NewRemoteHost: + memcpy(pm->remoteHost, data, l); + pm->remoteHost[l] = '\0'; + break; + case NewExternalPort: + pm->externalPort = (unsigned short)atoui(data, l); + break; + case NewProtocol: + if(l > 3) + l = 3; + memcpy(pm->protocol, data, l); + pm->protocol[l] = '\0'; + break; + case NewInternalPort: + pm->internalPort = (unsigned short)atoui(data, l); + break; + case NewInternalClient: + memcpy(pm->internalClient, data, l); + pm->internalClient[l] = '\0'; + break; + case NewEnabled: + pm->enabled = (unsigned char)atoui(data, l); + break; + case NewDescription: + memcpy(pm->description, data, l); + pm->description[l] = '\0'; + break; + case NewLeaseTime: + pm->leaseTime = atoui(data, l); + break; + default: + break; + } +} + + +/* Parse the PortMappingList XML document for IGD version 2 + */ +void +ParsePortListing(const char * buffer, int bufsize, + struct PortMappingParserData * pdata) +{ + struct xmlparser parser; + + memset(pdata, 0, sizeof(struct PortMappingParserData)); + LIST_INIT(&(pdata->head)); + /* init xmlparser */ + parser.xmlstart = buffer; + parser.xmlsize = bufsize; + parser.data = pdata; + parser.starteltfunc = startelt; + parser.endeltfunc = endelt; + parser.datafunc = data; + parser.attfunc = 0; + parsexml(&parser); +} + +void +FreePortListing(struct PortMappingParserData * pdata) +{ + struct PortMapping * pm; + while((pm = pdata->head.lh_first) != NULL) + { + LIST_REMOVE(pm, entries); + free(pm); + } +} + diff --git a/libs/miniupnpc/portlistingparse.h b/libs/miniupnpc/portlistingparse.h new file mode 100644 index 000000000..18524786c --- /dev/null +++ b/libs/miniupnpc/portlistingparse.h @@ -0,0 +1,71 @@ +/* $Id: portlistingparse.h,v 1.4 2011/02/15 23:03:56 nanard Exp $ */ +/* MiniUPnP project + * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ + * (c) 2011 Thomas Bernard + * This software is subject to the conditions detailed + * in the LICENCE file provided within the distribution */ +#ifndef __PORTLISTINGPARSE_H__ +#define __PORTLISTINGPARSE_H__ + +#include "declspec.h" +/* for the definition of UNSIGNED_INTEGER */ +#include "miniupnpctypes.h" + +#if defined(NO_SYS_QUEUE_H) || defined(WIN32) || defined(__HAIKU__) +#include "bsdqueue.h" +#else +#include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* sample of PortMappingEntry : + + 202.233.2.1 + 2345 + TCP + 2345 + 192.168.1.137 + 1 + dooom + 345 + + */ +typedef enum { PortMappingEltNone, + PortMappingEntry, NewRemoteHost, + NewExternalPort, NewProtocol, + NewInternalPort, NewInternalClient, + NewEnabled, NewDescription, + NewLeaseTime } portMappingElt; + +struct PortMapping { + LIST_ENTRY(PortMapping) entries; + UNSIGNED_INTEGER leaseTime; + unsigned short externalPort; + unsigned short internalPort; + char remoteHost[64]; + char internalClient[64]; + char description[64]; + char protocol[4]; + unsigned char enabled; +}; + +struct PortMappingParserData { + LIST_HEAD(portmappinglisthead, PortMapping) head; + portMappingElt curelt; +}; + +LIBSPEC void +ParsePortListing(const char * buffer, int bufsize, + struct PortMappingParserData * pdata); + +LIBSPEC void +FreePortListing(struct PortMappingParserData * pdata); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libs/miniupnpc/pymoduletest.py b/libs/miniupnpc/pymoduletest.py new file mode 100644 index 000000000..d35a3b092 --- /dev/null +++ b/libs/miniupnpc/pymoduletest.py @@ -0,0 +1,52 @@ +#! /usr/bin/python +# MiniUPnP project +# Author : Thomas Bernard +# This Sample code is public domain. +# website : http://miniupnp.tuxfamily.org/ + +# import the python miniupnpc module +import miniupnpc +import sys + +# create the object +u = miniupnpc.UPnP() +print 'inital(default) values :' +print ' discoverdelay', u.discoverdelay +print ' lanaddr', u.lanaddr +print ' multicastif', u.multicastif +print ' minissdpdsocket', u.minissdpdsocket +u.discoverdelay = 200; +#u.minissdpdsocket = '../minissdpd/minissdpd.sock' +# discovery process, it usualy takes several seconds (2 seconds or more) +print 'Discovering... delay=%ums' % u.discoverdelay +print u.discover(), 'device(s) detected' +# select an igd +try: + u.selectigd() +except Exception, e: + print 'Exception :', e + sys.exit(1) +# display information about the IGD and the internet connection +print 'local ip address :', u.lanaddr +print 'external ip address :', u.externalipaddress() +print u.statusinfo(), u.connectiontype() + +#print u.addportmapping(64000, 'TCP', +# '192.168.1.166', 63000, 'port mapping test', '') +#print u.deleteportmapping(64000, 'TCP') + +port = 0 +proto = 'UDP' +# list the redirections : +i = 0 +while True: + p = u.getgenericportmapping(i) + if p==None: + break + print i, p + (port, proto, (ihost,iport), desc, c, d, e) = p + #print port, desc + i = i + 1 + +print u.getspecificportmapping(port, proto) + diff --git a/libs/miniupnpc/receivedata.c b/libs/miniupnpc/receivedata.c new file mode 100644 index 000000000..a1eadfc46 --- /dev/null +++ b/libs/miniupnpc/receivedata.c @@ -0,0 +1,81 @@ +/* $Id: receivedata.c,v 1.1 2011/04/11 08:21:47 nanard Exp $ */ +/* Project : miniupnp + * Author : Thomas Bernard + * Copyright (c) 2011 Thomas Bernard + * This software is subject to the conditions detailed in the + * LICENCE file provided in this distribution. */ + +#include +#ifdef WIN32 +#include +#include +#else +#include +#if defined(__amigaos__) && !defined(__amigaos4__) +#define socklen_t int +#else /* #if defined(__amigaos__) && !defined(__amigaos4__) */ +#include +#endif /* #else defined(__amigaos__) && !defined(__amigaos4__) */ +#include +#if !defined(__amigaos__) && !defined(__amigaos4__) +#include +#endif +#include +#define MINIUPNPC_IGNORE_EINTR +#endif + +#ifdef WIN32 +#define PRINT_SOCKET_ERROR(x) printf("Socket error: %s, %d\n", x, WSAGetLastError()); +#else +#define PRINT_SOCKET_ERROR(x) perror(x) +#endif + +#include "receivedata.h" + +int +receivedata(int socket, char * data, int length, int timeout) +{ + int n; +#if !defined(WIN32) && !defined(__amigaos__) && !defined(__amigaos4__) + /* using poll */ + struct pollfd fds[1]; /* for the poll */ +#ifdef MINIUPNPC_IGNORE_EINTR + do { +#endif + fds[0].fd = socket; + fds[0].events = POLLIN; + n = poll(fds, 1, timeout); +#ifdef MINIUPNPC_IGNORE_EINTR + } while(n < 0 && errno == EINTR); +#endif + if(n < 0) { + PRINT_SOCKET_ERROR("poll"); + return -1; + } else if(n == 0) { + /* timeout */ + return 0; + } +#else /* !defined(WIN32) && !defined(__amigaos__) && !defined(__amigaos4__) */ + /* using select under WIN32 and amigaos */ + fd_set socketSet; + TIMEVAL timeval; + FD_ZERO(&socketSet); + FD_SET(socket, &socketSet); + timeval.tv_sec = timeout / 1000; + timeval.tv_usec = (timeout % 1000) * 1000; + n = select(FD_SETSIZE, &socketSet, NULL, NULL, &timeval); + if(n < 0) { + PRINT_SOCKET_ERROR("select"); + return -1; + } else if(n == 0) { + return 0; + } +#endif + n = recv(socket, data, length, 0); + if(n<0) { + PRINT_SOCKET_ERROR("recv"); + } + return n; +} + + diff --git a/libs/miniupnpc/receivedata.h b/libs/miniupnpc/receivedata.h new file mode 100644 index 000000000..7a551b9ac --- /dev/null +++ b/libs/miniupnpc/receivedata.h @@ -0,0 +1,17 @@ +/* $Id: receivedata.h,v 1.1 2011/04/11 08:21:47 nanard Exp $ */ +/* Project: miniupnp + * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ + * Author: Thomas Bernard + * Copyright (c) 2011 Thomas Bernard + * This software is subjects to the conditions detailed + * in the LICENCE file provided within this distribution */ +#ifndef __RECEIVEDATA_H__ +#define __RECEIVEDATA_H__ + +/* Reads data from the specified socket. + * Returns the number of bytes read if successful, zero if no bytes were + * read or if we timed out. Returns negative if there was an error. */ +int receivedata(int socket, char * data, int length, int timeout); + +#endif + diff --git a/libs/miniupnpc/setup.py b/libs/miniupnpc/setup.py new file mode 100644 index 000000000..ca31f9615 --- /dev/null +++ b/libs/miniupnpc/setup.py @@ -0,0 +1,15 @@ +#! /usr/bin/python +# $Id: setup.py,v 1.6 2011/01/04 09:46:08 nanard Exp $ +# the MiniUPnP Project (c) 2007-2011 Thomas Bernard +# http://miniupnp.tuxfamily.org/ or http://miniupnp.free.fr/ +# +# python script to build the miniupnpc module under unix +# +# replace libminiupnpc.a by libminiupnpc.so for shared library usage +from distutils.core import setup, Extension +setup(name="miniupnpc", version="1.5", + ext_modules=[ + Extension(name="miniupnpc", sources=["miniupnpcmodule.c"], + extra_objects=["libminiupnpc.a"]) + ]) + diff --git a/libs/miniupnpc/setupmingw32.py b/libs/miniupnpc/setupmingw32.py new file mode 100644 index 000000000..d0539e450 --- /dev/null +++ b/libs/miniupnpc/setupmingw32.py @@ -0,0 +1,15 @@ +#! /usr/bin/python +# $Id: setupmingw32.py,v 1.5 2011/05/15 21:18:43 nanard Exp $ +# the MiniUPnP Project (c) 2007-2011 Thomas Bernard +# http://miniupnp.tuxfamily.org/ or http://miniupnp.free.fr/ +# +# python script to build the miniupnpc module under windows (using mingw32) +# +from distutils.core import setup, Extension +setup(name="miniupnpc", version="1.5", + ext_modules=[ + Extension(name="miniupnpc", sources=["miniupnpcmodule.c"], + libraries=["ws2_32", "iphlpapi"], + extra_objects=["libminiupnpc.a"]) + ]) + diff --git a/libs/miniupnpc/testigddescparse.c b/libs/miniupnpc/testigddescparse.c new file mode 100644 index 000000000..1b0cde90e --- /dev/null +++ b/libs/miniupnpc/testigddescparse.c @@ -0,0 +1,64 @@ +/* $Id: testigddescparse.c,v 1.2 2009/12/03 13:50:06 nanard Exp $ */ +/* Project : miniupnp + * http://miniupnp.free.fr/ + * Author : Thomas Bernard + * Copyright (c) 2008-2009 Thomas Bernard + * This software is subject to the conditions detailed in the + * LICENCE file provided in this distribution. + * */ +#include +#include +#include +#include "igd_desc_parse.h" +#include "minixml.h" +#include "miniupnpc.h" + +int test_igd_desc_parse(char * buffer, int len) +{ + struct IGDdatas igd; + struct xmlparser parser; + struct UPNPUrls urls; + memset(&igd, 0, sizeof(struct IGDdatas)); + memset(&parser, 0, sizeof(struct xmlparser)); + parser.xmlstart = buffer; + parser.xmlsize = len; + parser.data = &igd; + parser.starteltfunc = IGDstartelt; + parser.endeltfunc = IGDendelt; + parser.datafunc = IGDdata; + parsexml(&parser); + printIGD(&igd); + GetUPNPUrls(&urls, &igd, "http://fake/desc/url/file.xml"); + printf("ipcondescURL='%s'\n", urls.ipcondescURL); + printf("controlURL='%s'\n", urls.controlURL); + printf("controlURL_CIF='%s'\n", urls.controlURL_CIF); + FreeUPNPUrls(&urls); + return 0; +} + +int main(int argc, char * * argv) +{ + FILE * f; + char * buffer; + int len; + int r = 0; + if(argc<2) { + fprintf(stderr, "Usage: %s file.xml\n", argv[0]); + return 1; + } + f = fopen(argv[1], "r"); + if(!f) { + fprintf(stderr, "Cannot open %s for reading.\n", argv[1]); + return 1; + } + fseek(f, 0, SEEK_END); + len = ftell(f); + fseek(f, 0, SEEK_SET); + buffer = malloc(len); + fread(buffer, 1, len, f); + fclose(f); + r = test_igd_desc_parse(buffer, len); + free(buffer); + return r; +} + diff --git a/libs/miniupnpc/testminiwget.c b/libs/miniupnpc/testminiwget.c new file mode 100644 index 000000000..b68fbfeed --- /dev/null +++ b/libs/miniupnpc/testminiwget.c @@ -0,0 +1,53 @@ +/* $Id: testminiwget.c,v 1.3 2011/05/06 16:33:53 nanard Exp $ */ +/* Project : miniupnp + * Author : Thomas Bernard + * Copyright (c) 2005-2011 Thomas Bernard + * This software is subject to the conditions detailed in the + * LICENCE file provided in this distribution. + * */ +#include +#include +#include "miniwget.h" + +/** + * This program uses the miniwget / miniwget_getaddr function + * from miniwget.c in order to retreive a web ressource using + * a GET HTTP method, and store it in a file. + */ +int main(int argc, char * * argv) +{ + void * data; + int size, writtensize; + FILE *f; + char addr[64]; + if(argc < 3) { + fprintf(stderr, "Usage:\t%s url file\n", argv[0]); + fprintf(stderr, "Example:\t%s http://www.google.com/ out.html\n", argv[0]); + return 1; + } + /*data = miniwget(argv[1], &size);*/ + data = miniwget_getaddr(argv[1], &size, addr, sizeof(addr)); + if(!data) { + fprintf(stderr, "Error fetching %s\n", argv[1]); + return 1; + } + printf("local address : %s\n", addr); + printf("got %d bytes\n", size); + f = fopen(argv[2], "wb"); + if(!f) { + fprintf(stderr, "Cannot open file %s for writing\n", argv[2]); + free(data); + return 1; + } + writtensize = fwrite(data, 1, size, f); + if(writtensize != size) { + fprintf(stderr, "Could only write %d bytes out of %d to %s\n", + writtensize, size, argv[2]); + } else { + printf("%d bytes written to %s\n", writtensize, argv[2]); + } + fclose(f); + free(data); + return 0; +} + diff --git a/libs/miniupnpc/testminiwget.sh b/libs/miniupnpc/testminiwget.sh new file mode 100755 index 000000000..c048e5bd1 --- /dev/null +++ b/libs/miniupnpc/testminiwget.sh @@ -0,0 +1,79 @@ +#!/bin/sh +# $Id: testminiwget.sh,v 1.4 2011/05/09 08:53:15 nanard Exp $ +# project miniupnp : http://miniupnp.free.fr/ +# (c) 2011 Thomas Bernard +# +# test program for miniwget.c +# is usually invoked by "make check" +# +# This test program : +# 1 - launches a local HTTP server (minihttptestserver) +# 2 - uses testminiwget to retreive data from this server +# 3 - compares served and received data +# 4 - kills the local HTTP server and exits +# + +HTTPSERVEROUT=/tmp/httpserverout +EXPECTEDFILE=/tmp/expectedfile +DOWNLOADEDFILE=/tmp/downloadedfile +#ADDR=localhost +ADDR="[::1]" +PORT= +RET=0 + +#make minihttptestserver +#make testminiwget + +# launching the test HTTP server +./minihttptestserver -6 -e $EXPECTEDFILE > $HTTPSERVEROUT & +while [ "$PORT" == "" ]; do + PORT=`cat $HTTPSERVEROUT | sed 's/Listening on port \([0-9]*\)/\1/' ` +done +echo "Test HTTP server is listening on $PORT" + +URL1="http://$ADDR:$PORT/index.html" +URL2="http://$ADDR:$PORT/chunked" +URL3="http://$ADDR:$PORT/addcrap" + +echo "standard test ..." +./testminiwget $URL1 "${DOWNLOADEDFILE}.1" +if cmp $EXPECTEDFILE "${DOWNLOADEDFILE}.1" ; then + echo "ok" +else + echo "standard test FAILED" + RET=1 +fi + +echo "chunked transfert encoding test ..." +./testminiwget $URL2 "${DOWNLOADEDFILE}.2" +if cmp $EXPECTEDFILE "${DOWNLOADEDFILE}.2" ; then + echo "ok" +else + echo "chunked transfert encoding test FAILED" + RET=1 +fi + +echo "response too long test ..." +./testminiwget $URL3 "${DOWNLOADEDFILE}.3" +if cmp $EXPECTEDFILE "${DOWNLOADEDFILE}.3" ; then + echo "ok" +else + echo "response too long test FAILED" + RET=1 +fi + +# kill the test HTTP server +kill %1 +wait %1 + +# remove temporary files (for success cases) +if [ $RET -eq 0 ]; then + rm -f "${DOWNLOADEDFILE}.1" + rm -f "${DOWNLOADEDFILE}.2" + rm -f "${DOWNLOADEDFILE}.3" + rm -f $EXPECTEDFILE $HTTPSERVEROUT +else + echo "at least one of the test FAILED" +fi +exit $RET + diff --git a/libs/miniupnpc/testminixml.c b/libs/miniupnpc/testminixml.c new file mode 100644 index 000000000..3d82527b7 --- /dev/null +++ b/libs/miniupnpc/testminixml.c @@ -0,0 +1,88 @@ +/* $Id: testminixml.c,v 1.6 2006/11/19 22:32:35 nanard Exp $ + * testminixml.c + * test program for the "minixml" functions. + * Author : Thomas Bernard. + */ +#include +#include +#include +#include "minixml.h" +#include "igd_desc_parse.h" + +#ifdef WIN32 +#define NO_BZERO +#endif + +#ifdef NO_BZERO +#define bzero(p, n) memset(p, 0, n) +#endif + +/* ---------------------------------------------------------------------- */ +void printeltname1(void * d, const char * name, int l) +{ + int i; + printf("element "); + for(i=0;i %s port %u TCP' % (externalipaddress, eport, u.lanaddr, httpd.server_port) + + b = u.addportmapping(eport, 'TCP', u.lanaddr, httpd.server_port, + 'UPnP IGD Tester port %u' % eport, '') + if b: + print 'Success. Now waiting for some HTTP request on http://%s:%u' % (externalipaddress ,eport) + try: + httpd.handle_request() + httpd.server_close() + except KeyboardInterrupt, details: + print "CTRL-C exception!", details + b = u.deleteportmapping(eport, 'TCP') + if b: + print 'Successfully deleted port mapping' + else: + print 'Failed to remove port mapping' + else: + print 'Failed' + + httpd.server_close() + +except Exception, e: + print 'Exception :', e diff --git a/libs/miniupnpc/testupnpreplyparse.c b/libs/miniupnpc/testupnpreplyparse.c new file mode 100644 index 000000000..a02e8f6a6 --- /dev/null +++ b/libs/miniupnpc/testupnpreplyparse.c @@ -0,0 +1,44 @@ +/* $Id: testupnpreplyparse.c,v 1.2 2008/02/21 13:05:27 nanard Exp $ */ +/* MiniUPnP project + * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ + * (c) 2006-2007 Thomas Bernard + * This software is subject to the conditions detailed + * in the LICENCE file provided within the distribution */ +#include +#include +#include "upnpreplyparse.h" + +void +test_parsing(const char * buf, int len) +{ + struct NameValueParserData pdata; + ParseNameValue(buf, len, &pdata); + ClearNameValueList(&pdata); +} + +int main(int argc, char * * argv) +{ + FILE * f; + char buffer[4096]; + int l; + if(argc<2) + { + fprintf(stderr, "Usage: %s file.xml\n", argv[0]); + return 1; + } + f = fopen(argv[1], "r"); + if(!f) + { + fprintf(stderr, "Error : can not open file %s\n", argv[1]); + return 2; + } + l = fread(buffer, 1, sizeof(buffer)-1, f); + fclose(f); + buffer[l] = '\0'; +#ifdef DEBUG + DisplayNameValueList(buffer, l); +#endif + test_parsing(buffer, l); + return 0; +} + diff --git a/libs/miniupnpc/updateminiupnpcstrings.sh b/libs/miniupnpc/updateminiupnpcstrings.sh new file mode 100755 index 000000000..dde4354a8 --- /dev/null +++ b/libs/miniupnpc/updateminiupnpcstrings.sh @@ -0,0 +1,53 @@ +#! /bin/sh +# $Id: updateminiupnpcstrings.sh,v 1.7 2011/01/04 11:41:53 nanard Exp $ +# project miniupnp : http://miniupnp.free.fr/ +# (c) 2009 Thomas Bernard + +FILE=miniupnpcstrings.h +TMPFILE=miniupnpcstrings.h.tmp +TEMPLATE_FILE=${FILE}.in + +# detecting the OS name and version +OS_NAME=`uname -s` +OS_VERSION=`uname -r` +if [ -f /etc/debian_version ]; then + OS_NAME=Debian + OS_VERSION=`cat /etc/debian_version` +fi +# use lsb_release (Linux Standard Base) when available +LSB_RELEASE=`which lsb_release` +if [ 0 -eq $? -a -x "${LSB_RELEASE}" ]; then + OS_NAME=`${LSB_RELEASE} -i -s` + OS_VERSION=`${LSB_RELEASE} -r -s` + case $OS_NAME in + Debian) + #OS_VERSION=`${LSB_RELEASE} -c -s` + ;; + Ubuntu) + #OS_VERSION=`${LSB_RELEASE} -c -s` + ;; + esac +fi + +# on AmigaOS 3, uname -r returns "unknown", so we use uname -v +if [ "$OS_NAME" = "AmigaOS" ]; then + if [ "$OS_VERSION" = "unknown" ]; then + OS_VERSION=`uname -v` + fi +fi + +echo "Detected OS [$OS_NAME] version [$OS_VERSION]" +MINIUPNPC_VERSION=`cat VERSION` +echo "MiniUPnPc version [${MINIUPNPC_VERSION}]" + +EXPR="s|OS_STRING \".*\"|OS_STRING \"${OS_NAME}/${OS_VERSION}\"|" +#echo $EXPR +test -f ${FILE}.in +echo "setting OS_STRING macro value to ${OS_NAME}/${OS_VERSION} in $FILE." +sed -e "$EXPR" < $TEMPLATE_FILE > $TMPFILE + +EXPR="s|MINIUPNPC_VERSION_STRING \".*\"|MINIUPNPC_VERSION_STRING \"${MINIUPNPC_VERSION}\"|" +echo "setting MINIUPNPC_VERSION_STRING macro value to ${MINIUPNPC_VERSION} in $FILE." +sed -e "$EXPR" < $TMPFILE > $FILE +rm $TMPFILE + diff --git a/libs/miniupnpc/upnpc.c b/libs/miniupnpc/upnpc.c new file mode 100644 index 000000000..b136d9d1f --- /dev/null +++ b/libs/miniupnpc/upnpc.c @@ -0,0 +1,683 @@ +/* $Id: upnpc.c,v 1.88 2011/06/17 23:31:01 nanard Exp $ */ +/* Project : miniupnp + * Author : Thomas Bernard + * Copyright (c) 2005-2011 Thomas Bernard + * This software is subject to the conditions detailed in the + * LICENCE file provided in this distribution. */ + +#include +#include +#include +#include +#ifdef WIN32 +#include +#define snprintf _snprintf +#endif +#include "miniwget.h" +#include "miniupnpc.h" +#include "upnpcommands.h" +#include "upnperrors.h" + +/* protofix() checks if protocol is "UDP" or "TCP" + * returns NULL if not */ +const char * protofix(const char * proto) +{ + static const char proto_tcp[4] = { 'T', 'C', 'P', 0}; + static const char proto_udp[4] = { 'U', 'D', 'P', 0}; + int i, b; + for(i=0, b=1; i<4; i++) + b = b && ( (proto[i] == proto_tcp[i]) + || (proto[i] == (proto_tcp[i] | 32)) ); + if(b) + return proto_tcp; + for(i=0, b=1; i<4; i++) + b = b && ( (proto[i] == proto_udp[i]) + || (proto[i] == (proto_udp[i] | 32)) ); + if(b) + return proto_udp; + return 0; +} + +static void DisplayInfos(struct UPNPUrls * urls, + struct IGDdatas * data) +{ + char externalIPAddress[40]; + char connectionType[64]; + char status[64]; + char lastconnerr[64]; + unsigned int uptime; + unsigned int brUp, brDown; + time_t timenow, timestarted; + int r; + UPNP_GetConnectionTypeInfo(urls->controlURL, + data->first.servicetype, + connectionType); + if(connectionType[0]) + printf("Connection Type : %s\n", connectionType); + else + printf("GetConnectionTypeInfo failed.\n"); + UPNP_GetStatusInfo(urls->controlURL, data->first.servicetype, + status, &uptime, lastconnerr); + printf("Status : %s, uptime=%us, LastConnectionError : %s\n", + status, uptime, lastconnerr); + timenow = time(NULL); + timestarted = timenow - uptime; + printf(" Time started : %s", ctime(×tarted)); + UPNP_GetLinkLayerMaxBitRates(urls->controlURL_CIF, data->CIF.servicetype, + &brDown, &brUp); + printf("MaxBitRateDown : %u bps", brDown); + if(brDown >= 1000000) { + printf(" (%u.%u Mbps)", brDown / 1000000, (brDown / 100000) % 10); + } else if(brDown >= 1000) { + printf(" (%u Kbps)", brDown / 1000); + } + printf(" MaxBitRateUp %u bps", brUp); + if(brUp >= 1000000) { + printf(" (%u.%u Mbps)", brUp / 1000000, (brUp / 100000) % 10); + } else if(brUp >= 1000) { + printf(" (%u Kbps)", brUp / 1000); + } + printf("\n"); + r = UPNP_GetExternalIPAddress(urls->controlURL, + data->first.servicetype, + externalIPAddress); + if(r != UPNPCOMMAND_SUCCESS) + printf("GetExternalIPAddress() returned %d\n", r); + if(externalIPAddress[0]) + printf("ExternalIPAddress = %s\n", externalIPAddress); + else + printf("GetExternalIPAddress failed.\n"); +} + +static void GetConnectionStatus(struct UPNPUrls * urls, + struct IGDdatas * data) +{ + unsigned int bytessent, bytesreceived, packetsreceived, packetssent; + DisplayInfos(urls, data); + bytessent = UPNP_GetTotalBytesSent(urls->controlURL_CIF, data->CIF.servicetype); + bytesreceived = UPNP_GetTotalBytesReceived(urls->controlURL_CIF, data->CIF.servicetype); + packetssent = UPNP_GetTotalPacketsSent(urls->controlURL_CIF, data->CIF.servicetype); + packetsreceived = UPNP_GetTotalPacketsReceived(urls->controlURL_CIF, data->CIF.servicetype); + printf("Bytes: Sent: %8u\tRecv: %8u\n", bytessent, bytesreceived); + printf("Packets: Sent: %8u\tRecv: %8u\n", packetssent, packetsreceived); +} + +static void ListRedirections(struct UPNPUrls * urls, + struct IGDdatas * data) +{ + int r; + int i = 0; + char index[6]; + char intClient[40]; + char intPort[6]; + char extPort[6]; + char protocol[4]; + char desc[80]; + char enabled[6]; + char rHost[64]; + char duration[16]; + /*unsigned int num=0; + UPNP_GetPortMappingNumberOfEntries(urls->controlURL, data->servicetype, &num); + printf("PortMappingNumberOfEntries : %u\n", num);*/ + do { + snprintf(index, 6, "%d", i); + rHost[0] = '\0'; enabled[0] = '\0'; + duration[0] = '\0'; desc[0] = '\0'; + extPort[0] = '\0'; intPort[0] = '\0'; intClient[0] = '\0'; + r = UPNP_GetGenericPortMappingEntry(urls->controlURL, + data->first.servicetype, + index, + extPort, intClient, intPort, + protocol, desc, enabled, + rHost, duration); + if(r==0) + /* + printf("%02d - %s %s->%s:%s\tenabled=%s leaseDuration=%s\n" + " desc='%s' rHost='%s'\n", + i, protocol, extPort, intClient, intPort, + enabled, duration, + desc, rHost); + */ + printf("%2d %s %5s->%s:%-5s '%s' '%s' %s\n", + i, protocol, extPort, intClient, intPort, + desc, rHost, duration); + else + printf("GetGenericPortMappingEntry() returned %d (%s)\n", + r, strupnperror(r)); + i++; + } while(r==0); +} + +static void NewListRedirections(struct UPNPUrls * urls, + struct IGDdatas * data) +{ + int r; + int i = 0; + struct PortMappingParserData pdata; + struct PortMapping * pm; + + memset(&pdata, 0, sizeof(struct PortMappingParserData)); + r = UPNP_GetListOfPortMappings(urls->controlURL, + data->first.servicetype, + "0", + "65535", + "TCP", + "1000", + &pdata); + if(r == UPNPCOMMAND_SUCCESS) + { + for(pm = pdata.head.lh_first; pm != NULL; pm = pm->entries.le_next) + { + printf("%2d %s %5hu->%s:%-5hu '%s' '%s' %u\n", + i, pm->protocol, pm->externalPort, pm->internalClient, + pm->internalPort, + pm->description, pm->remoteHost, + (unsigned)pm->leaseTime); + i++; + } + FreePortListing(&pdata); + } + else + { + printf("GetListOfPortMappings() returned %d (%s)\n", + r, strupnperror(r)); + } + r = UPNP_GetListOfPortMappings(urls->controlURL, + data->first.servicetype, + "0", + "65535", + "UDP", + "1000", + &pdata); + if(r == UPNPCOMMAND_SUCCESS) + { + for(pm = pdata.head.lh_first; pm != NULL; pm = pm->entries.le_next) + { + printf("%2d %s %5hu->%s:%-5hu '%s' '%s' %u\n", + i, pm->protocol, pm->externalPort, pm->internalClient, + pm->internalPort, + pm->description, pm->remoteHost, + (unsigned)pm->leaseTime); + i++; + } + FreePortListing(&pdata); + } + else + { + printf("GetListOfPortMappings() returned %d (%s)\n", + r, strupnperror(r)); + } +} + +/* Test function + * 1 - get connection type + * 2 - get extenal ip address + * 3 - Add port mapping + * 4 - get this port mapping from the IGD */ +static void SetRedirectAndTest(struct UPNPUrls * urls, + struct IGDdatas * data, + const char * iaddr, + const char * iport, + const char * eport, + const char * proto, + const char * leaseDuration) +{ + char externalIPAddress[40]; + char intClient[40]; + char intPort[6]; + char duration[16]; + int r; + + if(!iaddr || !iport || !eport || !proto) + { + fprintf(stderr, "Wrong arguments\n"); + return; + } + proto = protofix(proto); + if(!proto) + { + fprintf(stderr, "invalid protocol\n"); + return; + } + + UPNP_GetExternalIPAddress(urls->controlURL, + data->first.servicetype, + externalIPAddress); + if(externalIPAddress[0]) + printf("ExternalIPAddress = %s\n", externalIPAddress); + else + printf("GetExternalIPAddress failed.\n"); + + r = UPNP_AddPortMapping(urls->controlURL, data->first.servicetype, + eport, iport, iaddr, 0, proto, 0, leaseDuration); + if(r!=UPNPCOMMAND_SUCCESS) + printf("AddPortMapping(%s, %s, %s) failed with code %d (%s)\n", + eport, iport, iaddr, r, strupnperror(r)); + + r = UPNP_GetSpecificPortMappingEntry(urls->controlURL, + data->first.servicetype, + eport, proto, + intClient, intPort, NULL/*desc*/, + NULL/*enabled*/, duration); + if(r!=UPNPCOMMAND_SUCCESS) + printf("GetSpecificPortMappingEntry() failed with code %d (%s)\n", + r, strupnperror(r)); + + if(intClient[0]) { + printf("InternalIP:Port = %s:%s\n", intClient, intPort); + printf("external %s:%s %s is redirected to internal %s:%s (duration=%s)\n", + externalIPAddress, eport, proto, intClient, intPort, duration); + } +} + +static void +RemoveRedirect(struct UPNPUrls * urls, + struct IGDdatas * data, + const char * eport, + const char * proto) +{ + int r; + if(!proto || !eport) + { + fprintf(stderr, "invalid arguments\n"); + return; + } + proto = protofix(proto); + if(!proto) + { + fprintf(stderr, "protocol invalid\n"); + return; + } + r = UPNP_DeletePortMapping(urls->controlURL, data->first.servicetype, eport, proto, 0); + printf("UPNP_DeletePortMapping() returned : %d\n", r); +} + +/* IGD:2, functions for service WANIPv6FirewallControl:1 */ +static void GetFirewallStatus(struct UPNPUrls * urls, struct IGDdatas * data) +{ + unsigned int bytessent, bytesreceived, packetsreceived, packetssent; + int firewallEnabled = 0, inboundPinholeAllowed = 0; + + UPNP_GetFirewallStatus(urls->controlURL_6FC, data->IPv6FC.servicetype, &firewallEnabled, &inboundPinholeAllowed); + printf("FirewallEnabled: %d & Inbound Pinhole Allowed: %d\n", firewallEnabled, inboundPinholeAllowed); + printf("GetFirewallStatus:\n Firewall Enabled: %s\n Inbound Pinhole Allowed: %s\n", (firewallEnabled)? "Yes":"No", (inboundPinholeAllowed)? "Yes":"No"); + + bytessent = UPNP_GetTotalBytesSent(urls->controlURL_CIF, data->CIF.servicetype); + bytesreceived = UPNP_GetTotalBytesReceived(urls->controlURL_CIF, data->CIF.servicetype); + packetssent = UPNP_GetTotalPacketsSent(urls->controlURL_CIF, data->CIF.servicetype); + packetsreceived = UPNP_GetTotalPacketsReceived(urls->controlURL_CIF, data->CIF.servicetype); + printf("Bytes: Sent: %8u\tRecv: %8u\n", bytessent, bytesreceived); + printf("Packets: Sent: %8u\tRecv: %8u\n", packetssent, packetsreceived); +} + +/* Test function + * 1 - Add pinhole + * 2 - Check if pinhole is working from the IGD side */ +static void SetPinholeAndTest(struct UPNPUrls * urls, struct IGDdatas * data, + const char * remoteaddr, const char * eport, + const char * intaddr, const char * iport, + const char * proto, const char * lease_time) +{ + char uniqueID[8]; + //int isWorking = 0; + int r; + + if(!intaddr || !remoteaddr || !iport || !eport || !proto || !lease_time) + { + fprintf(stderr, "Wrong arguments\n"); + return; + } + /*proto = protofix(proto); + if(!proto) + { + fprintf(stderr, "invalid protocol\n"); + return; + }*/ + r = UPNP_AddPinhole(urls->controlURL_6FC, data->IPv6FC.servicetype, remoteaddr, eport, intaddr, iport, proto, lease_time, uniqueID); + if(r!=UPNPCOMMAND_SUCCESS) + printf("AddPinhole([%s]:%s -> [%s]:%s) failed with code %d (%s)\n", + intaddr, iport, remoteaddr, eport, r, strupnperror(r)); + else + { + printf("AddPinhole: ([%s]:%s -> [%s]:%s) / Pinhole ID = %s\n", intaddr, iport, remoteaddr, eport, uniqueID); + /*r = UPNP_CheckPinholeWorking(urls->controlURL_6FC, data->servicetype_6FC, uniqueID, &isWorking); + if(r!=UPNPCOMMAND_SUCCESS) + printf("CheckPinholeWorking() failed with code %d (%s)\n", r, strupnperror(r)); + printf("CheckPinholeWorking: Pinhole ID = %s / IsWorking = %s\n", uniqueID, (isWorking)? "Yes":"No");*/ + } +} + +/* Test function + * 1 - Check if pinhole is working from the IGD side + * 2 - Update pinhole */ +static void GetPinholeAndUpdate(struct UPNPUrls * urls, struct IGDdatas * data, + const char * uniqueID, const char * lease_time) +{ + int isWorking = 0; + int r; + + if(!uniqueID || !lease_time) + { + fprintf(stderr, "Wrong arguments\n"); + return; + } + r = UPNP_CheckPinholeWorking(urls->controlURL_6FC, data->IPv6FC.servicetype, uniqueID, &isWorking); + printf("CheckPinholeWorking: Pinhole ID = %s / IsWorking = %s\n", uniqueID, (isWorking)? "Yes":"No"); + if(r!=UPNPCOMMAND_SUCCESS) + printf("CheckPinholeWorking() failed with code %d (%s)\n", r, strupnperror(r)); + if(isWorking || r==709) + { + r = UPNP_UpdatePinhole(urls->controlURL_6FC, data->IPv6FC.servicetype, uniqueID, lease_time); + printf("UpdatePinhole: Pinhole ID = %s with Lease Time: %s\n", uniqueID, lease_time); + if(r!=UPNPCOMMAND_SUCCESS) + printf("UpdatePinhole: ID (%s) failed with code %d (%s)\n", uniqueID, r, strupnperror(r)); + } +} + +/* Test function + * Get pinhole timeout + */ +static void GetPinholeOutboundTimeout(struct UPNPUrls * urls, struct IGDdatas * data, + const char * remoteaddr, const char * eport, + const char * intaddr, const char * iport, + const char * proto) +{ + int timeout = 0; + int r; + + if(!intaddr || !remoteaddr || !iport || !eport || !proto) + { + fprintf(stderr, "Wrong arguments\n"); + return; + } + + r = UPNP_GetOutboundPinholeTimeout(urls->controlURL_6FC, data->IPv6FC.servicetype, remoteaddr, eport, intaddr, iport, proto, &timeout); + if(r!=UPNPCOMMAND_SUCCESS) + printf("GetOutboundPinholeTimeout([%s]:%s -> [%s]:%s) failed with code %d (%s)\n", + intaddr, iport, remoteaddr, eport, r, strupnperror(r)); + else + printf("GetOutboundPinholeTimeout: ([%s]:%s -> [%s]:%s) / Timeout = %d\n", intaddr, iport, remoteaddr, eport, timeout); +} + +static void +GetPinholePackets(struct UPNPUrls * urls, + struct IGDdatas * data, const char * uniqueID) +{ + int r, pinholePackets = 0; + if(!uniqueID) + { + fprintf(stderr, "invalid arguments\n"); + return; + } + r = UPNP_GetPinholePackets(urls->controlURL_6FC, data->IPv6FC.servicetype, uniqueID, &pinholePackets); + if(r!=UPNPCOMMAND_SUCCESS) + printf("GetPinholePackets() failed with code %d (%s)\n", r, strupnperror(r)); + else + printf("GetPinholePackets: Pinhole ID = %s / PinholePackets = %d\n", uniqueID, pinholePackets); +} + +static void +CheckPinhole(struct UPNPUrls * urls, + struct IGDdatas * data, const char * uniqueID) +{ + int r, isWorking = 0; + if(!uniqueID) + { + fprintf(stderr, "invalid arguments\n"); + return; + } + r = UPNP_CheckPinholeWorking(urls->controlURL_6FC, data->IPv6FC.servicetype, uniqueID, &isWorking); + if(r!=UPNPCOMMAND_SUCCESS) + printf("CheckPinholeWorking() failed with code %d (%s)\n", r, strupnperror(r)); + else + printf("CheckPinholeWorking: Pinhole ID = %s / IsWorking = %s\n", uniqueID, (isWorking)? "Yes":"No"); +} + +static void +RemovePinhole(struct UPNPUrls * urls, + struct IGDdatas * data, const char * uniqueID) +{ + int r; + if(!uniqueID) + { + fprintf(stderr, "invalid arguments\n"); + return; + } + r = UPNP_DeletePinhole(urls->controlURL_6FC, data->IPv6FC.servicetype, uniqueID); + printf("UPNP_DeletePinhole() returned : %d\n", r); +} + + +/* sample upnp client program */ +int main(int argc, char ** argv) +{ + char command = 0; + char ** commandargv = 0; + int commandargc = 0; + struct UPNPDev * devlist = 0; + char lanaddr[64]; /* my ip address on the LAN */ + int i; + const char * rootdescurl = 0; + const char * multicastif = 0; + const char * minissdpdpath = 0; + int retcode = 0; + int error = 0; + int ipv6 = 0; + +#ifdef WIN32 + WSADATA wsaData; + int nResult = WSAStartup(MAKEWORD(2,2), &wsaData); + if(nResult != NO_ERROR) + { + fprintf(stderr, "WSAStartup() failed.\n"); + return -1; + } +#endif + printf("upnpc : miniupnpc library test client. (c) 2006-2011 Thomas Bernard\n"); + printf("Go to http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/\n" + "for more information.\n"); + /* command line processing */ + for(i=1; ipNext) + { + printf(" desc: %s\n st: %s\n\n", + device->descURL, device->st); + } + } + else + { + printf("upnpDiscover() error code=%d\n", error); + } + i = 1; + if( (rootdescurl && UPNP_GetIGDFromUrl(rootdescurl, &urls, &data, lanaddr, sizeof(lanaddr))) + || (i = UPNP_GetValidIGD(devlist, &urls, &data, lanaddr, sizeof(lanaddr)))) + { + switch(i) { + case 1: + printf("Found valid IGD : %s\n", urls.controlURL); + break; + case 2: + printf("Found a (not connected?) IGD : %s\n", urls.controlURL); + printf("Trying to continue anyway\n"); + break; + case 3: + printf("UPnP device found. Is it an IGD ? : %s\n", urls.controlURL); + printf("Trying to continue anyway\n"); + break; + default: + printf("Found device (igd ?) : %s\n", urls.controlURL); + printf("Trying to continue anyway\n"); + } + printf("Local LAN ip address : %s\n", lanaddr); + #if 0 + printf("getting \"%s\"\n", urls.ipcondescURL); + descXML = miniwget(urls.ipcondescURL, &descXMLsize); + if(descXML) + { + /*fwrite(descXML, 1, descXMLsize, stdout);*/ + free(descXML); descXML = NULL; + } + #endif + + switch(command) + { + case 'l': + DisplayInfos(&urls, &data); + ListRedirections(&urls, &data); + break; + case 'L': + NewListRedirections(&urls, &data); + break; + case 'a': + SetRedirectAndTest(&urls, &data, + commandargv[0], commandargv[1], + commandargv[2], commandargv[3], + (commandargc > 4)?commandargv[4]:"0"); + break; + case 'd': + for(i=0; i +#include +#include +#include "upnpcommands.h" +#include "miniupnpc.h" +#include "portlistingparse.h" + +static UNSIGNED_INTEGER +my_atoui(const char * s) +{ + return s ? ((UNSIGNED_INTEGER)STRTOUI(s, NULL, 0)) : 0; +} + +/* + * */ +LIBSPEC UNSIGNED_INTEGER +UPNP_GetTotalBytesSent(const char * controlURL, + const char * servicetype) +{ + struct NameValueParserData pdata; + char * buffer; + int bufsize; + unsigned int r = 0; + char * p; + if(!(buffer = simpleUPnPcommand(-1, controlURL, servicetype, + "GetTotalBytesSent", 0, &bufsize))) { + return UPNPCOMMAND_HTTP_ERROR; + } + ParseNameValue(buffer, bufsize, &pdata); + /*DisplayNameValueList(buffer, bufsize);*/ + free(buffer); buffer = NULL; + p = GetValueFromNameValueList(&pdata, "NewTotalBytesSent"); + r = my_atoui(p); + ClearNameValueList(&pdata); + return r; +} + +/* + * */ +LIBSPEC UNSIGNED_INTEGER +UPNP_GetTotalBytesReceived(const char * controlURL, + const char * servicetype) +{ + struct NameValueParserData pdata; + char * buffer; + int bufsize; + unsigned int r = 0; + char * p; + if(!(buffer = simpleUPnPcommand(-1, controlURL, servicetype, + "GetTotalBytesReceived", 0, &bufsize))) { + return UPNPCOMMAND_HTTP_ERROR; + } + ParseNameValue(buffer, bufsize, &pdata); + /*DisplayNameValueList(buffer, bufsize);*/ + free(buffer); buffer = NULL; + p = GetValueFromNameValueList(&pdata, "NewTotalBytesReceived"); + r = my_atoui(p); + ClearNameValueList(&pdata); + return r; +} + +/* + * */ +LIBSPEC UNSIGNED_INTEGER +UPNP_GetTotalPacketsSent(const char * controlURL, + const char * servicetype) +{ + struct NameValueParserData pdata; + char * buffer; + int bufsize; + unsigned int r = 0; + char * p; + if(!(buffer = simpleUPnPcommand(-1, controlURL, servicetype, + "GetTotalPacketsSent", 0, &bufsize))) { + return UPNPCOMMAND_HTTP_ERROR; + } + ParseNameValue(buffer, bufsize, &pdata); + /*DisplayNameValueList(buffer, bufsize);*/ + free(buffer); buffer = NULL; + p = GetValueFromNameValueList(&pdata, "NewTotalPacketsSent"); + r = my_atoui(p); + ClearNameValueList(&pdata); + return r; +} + +/* + * */ +LIBSPEC UNSIGNED_INTEGER +UPNP_GetTotalPacketsReceived(const char * controlURL, + const char * servicetype) +{ + struct NameValueParserData pdata; + char * buffer; + int bufsize; + unsigned int r = 0; + char * p; + if(!(buffer = simpleUPnPcommand(-1, controlURL, servicetype, + "GetTotalPacketsReceived", 0, &bufsize))) { + return UPNPCOMMAND_HTTP_ERROR; + } + ParseNameValue(buffer, bufsize, &pdata); + /*DisplayNameValueList(buffer, bufsize);*/ + free(buffer); buffer = NULL; + p = GetValueFromNameValueList(&pdata, "NewTotalPacketsReceived"); + r = my_atoui(p); + ClearNameValueList(&pdata); + return r; +} + +/* UPNP_GetStatusInfo() call the corresponding UPNP method + * returns the current status and uptime */ +LIBSPEC int +UPNP_GetStatusInfo(const char * controlURL, + const char * servicetype, + char * status, + unsigned int * uptime, + char * lastconnerror) +{ + struct NameValueParserData pdata; + char * buffer; + int bufsize; + char * p; + char * up; + char * err; + int ret = UPNPCOMMAND_UNKNOWN_ERROR; + + if(!status && !uptime) + return UPNPCOMMAND_INVALID_ARGS; + + if(!(buffer = simpleUPnPcommand(-1, controlURL, servicetype, + "GetStatusInfo", 0, &bufsize))) { + return UPNPCOMMAND_HTTP_ERROR; + } + ParseNameValue(buffer, bufsize, &pdata); + /*DisplayNameValueList(buffer, bufsize);*/ + free(buffer); buffer = NULL; + up = GetValueFromNameValueList(&pdata, "NewUptime"); + p = GetValueFromNameValueList(&pdata, "NewConnectionStatus"); + err = GetValueFromNameValueList(&pdata, "NewLastConnectionError"); + if(p && up) + ret = UPNPCOMMAND_SUCCESS; + + if(status) { + if(p){ + strncpy(status, p, 64 ); + status[63] = '\0'; + }else + status[0]= '\0'; + } + + if(uptime) { + if(up) + sscanf(up,"%u",uptime); + else + uptime = 0; + } + + if(lastconnerror) { + if(err) { + strncpy(lastconnerror, err, 64 ); + lastconnerror[63] = '\0'; + } else + lastconnerror[0] = '\0'; + } + + p = GetValueFromNameValueList(&pdata, "errorCode"); + if(p) { + ret = UPNPCOMMAND_UNKNOWN_ERROR; + sscanf(p, "%d", &ret); + } + ClearNameValueList(&pdata); + return ret; +} + +/* UPNP_GetConnectionTypeInfo() call the corresponding UPNP method + * returns the connection type */ +LIBSPEC int +UPNP_GetConnectionTypeInfo(const char * controlURL, + const char * servicetype, + char * connectionType) +{ + struct NameValueParserData pdata; + char * buffer; + int bufsize; + char * p; + int ret = UPNPCOMMAND_UNKNOWN_ERROR; + + if(!connectionType) + return UPNPCOMMAND_INVALID_ARGS; + + if(!(buffer = simpleUPnPcommand(-1, controlURL, servicetype, + "GetConnectionTypeInfo", 0, &bufsize))) { + return UPNPCOMMAND_HTTP_ERROR; + } + ParseNameValue(buffer, bufsize, &pdata); + free(buffer); buffer = NULL; + p = GetValueFromNameValueList(&pdata, "NewConnectionType"); + /*p = GetValueFromNameValueList(&pdata, "NewPossibleConnectionTypes");*/ + /* PossibleConnectionTypes will have several values.... */ + if(p) { + strncpy(connectionType, p, 64 ); + connectionType[63] = '\0'; + ret = UPNPCOMMAND_SUCCESS; + } else + connectionType[0] = '\0'; + p = GetValueFromNameValueList(&pdata, "errorCode"); + if(p) { + ret = UPNPCOMMAND_UNKNOWN_ERROR; + sscanf(p, "%d", &ret); + } + ClearNameValueList(&pdata); + return ret; +} + +/* UPNP_GetLinkLayerMaxBitRate() call the corresponding UPNP method. + * Returns 2 values: Downloadlink bandwidth and Uplink bandwidth. + * One of the values can be null + * Note : GetLinkLayerMaxBitRates belongs to WANPPPConnection:1 only + * We can use the GetCommonLinkProperties from WANCommonInterfaceConfig:1 */ +LIBSPEC int +UPNP_GetLinkLayerMaxBitRates(const char * controlURL, + const char * servicetype, + unsigned int * bitrateDown, + unsigned int * bitrateUp) +{ + struct NameValueParserData pdata; + char * buffer; + int bufsize; + int ret = UPNPCOMMAND_UNKNOWN_ERROR; + char * down; + char * up; + char * p; + + if(!bitrateDown && !bitrateUp) + return UPNPCOMMAND_INVALID_ARGS; + + /* shouldn't we use GetCommonLinkProperties ? */ + if(!(buffer = simpleUPnPcommand(-1, controlURL, servicetype, + "GetCommonLinkProperties", 0, &bufsize))) { + /*"GetLinkLayerMaxBitRates", 0, &bufsize);*/ + return UPNPCOMMAND_HTTP_ERROR; + } + /*DisplayNameValueList(buffer, bufsize);*/ + ParseNameValue(buffer, bufsize, &pdata); + free(buffer); buffer = NULL; + /*down = GetValueFromNameValueList(&pdata, "NewDownstreamMaxBitRate");*/ + /*up = GetValueFromNameValueList(&pdata, "NewUpstreamMaxBitRate");*/ + down = GetValueFromNameValueList(&pdata, "NewLayer1DownstreamMaxBitRate"); + up = GetValueFromNameValueList(&pdata, "NewLayer1UpstreamMaxBitRate"); + /*GetValueFromNameValueList(&pdata, "NewWANAccessType");*/ + /*GetValueFromNameValueList(&pdata, "NewPhysicalLinkStatus");*/ + if(down && up) + ret = UPNPCOMMAND_SUCCESS; + + if(bitrateDown) { + if(down) + sscanf(down,"%u",bitrateDown); + else + *bitrateDown = 0; + } + + if(bitrateUp) { + if(up) + sscanf(up,"%u",bitrateUp); + else + *bitrateUp = 0; + } + p = GetValueFromNameValueList(&pdata, "errorCode"); + if(p) { + ret = UPNPCOMMAND_UNKNOWN_ERROR; + sscanf(p, "%d", &ret); + } + ClearNameValueList(&pdata); + return ret; +} + + +/* UPNP_GetExternalIPAddress() call the corresponding UPNP method. + * if the third arg is not null the value is copied to it. + * at least 16 bytes must be available + * + * Return values : + * 0 : SUCCESS + * NON ZERO : ERROR Either an UPnP error code or an unknown error. + * + * 402 Invalid Args - See UPnP Device Architecture section on Control. + * 501 Action Failed - See UPnP Device Architecture section on Control. + */ +LIBSPEC int +UPNP_GetExternalIPAddress(const char * controlURL, + const char * servicetype, + char * extIpAdd) +{ + struct NameValueParserData pdata; + char * buffer; + int bufsize; + char * p; + int ret = UPNPCOMMAND_UNKNOWN_ERROR; + + if(!extIpAdd || !controlURL || !servicetype) + return UPNPCOMMAND_INVALID_ARGS; + + if(!(buffer = simpleUPnPcommand(-1, controlURL, servicetype, + "GetExternalIPAddress", 0, &bufsize))) { + return UPNPCOMMAND_HTTP_ERROR; + } + /*DisplayNameValueList(buffer, bufsize);*/ + ParseNameValue(buffer, bufsize, &pdata); + free(buffer); buffer = NULL; + /*printf("external ip = %s\n", GetValueFromNameValueList(&pdata, "NewExternalIPAddress") );*/ + p = GetValueFromNameValueList(&pdata, "NewExternalIPAddress"); + if(p) { + strncpy(extIpAdd, p, 16 ); + extIpAdd[15] = '\0'; + ret = UPNPCOMMAND_SUCCESS; + } else + extIpAdd[0] = '\0'; + + p = GetValueFromNameValueList(&pdata, "errorCode"); + if(p) { + ret = UPNPCOMMAND_UNKNOWN_ERROR; + sscanf(p, "%d", &ret); + } + + ClearNameValueList(&pdata); + return ret; +} + +LIBSPEC int +UPNP_AddPortMapping(const char * controlURL, const char * servicetype, + const char * extPort, + const char * inPort, + const char * inClient, + const char * desc, + const char * proto, + const char * remoteHost, + const char * leaseDuration) +{ + struct UPNParg * AddPortMappingArgs; + char * buffer; + int bufsize; + struct NameValueParserData pdata; + const char * resVal; + int ret; + + if(!inPort || !inClient || !proto || !extPort) + return UPNPCOMMAND_INVALID_ARGS; + + AddPortMappingArgs = calloc(9, sizeof(struct UPNParg)); + AddPortMappingArgs[0].elt = "NewRemoteHost"; + AddPortMappingArgs[0].val = remoteHost; + AddPortMappingArgs[1].elt = "NewExternalPort"; + AddPortMappingArgs[1].val = extPort; + AddPortMappingArgs[2].elt = "NewProtocol"; + AddPortMappingArgs[2].val = proto; + AddPortMappingArgs[3].elt = "NewInternalPort"; + AddPortMappingArgs[3].val = inPort; + AddPortMappingArgs[4].elt = "NewInternalClient"; + AddPortMappingArgs[4].val = inClient; + AddPortMappingArgs[5].elt = "NewEnabled"; + AddPortMappingArgs[5].val = "1"; + AddPortMappingArgs[6].elt = "NewPortMappingDescription"; + AddPortMappingArgs[6].val = desc?desc:"libminiupnpc"; + AddPortMappingArgs[7].elt = "NewLeaseDuration"; + AddPortMappingArgs[7].val = leaseDuration?leaseDuration:"0"; + if(!(buffer = simpleUPnPcommand(-1, controlURL, servicetype, + "AddPortMapping", AddPortMappingArgs, + &bufsize))) { + free(AddPortMappingArgs); + return UPNPCOMMAND_HTTP_ERROR; + } + /*DisplayNameValueList(buffer, bufsize);*/ + /*buffer[bufsize] = '\0';*/ + /*puts(buffer);*/ + ParseNameValue(buffer, bufsize, &pdata); + free(buffer); buffer = NULL; + resVal = GetValueFromNameValueList(&pdata, "errorCode"); + if(resVal) { + /*printf("AddPortMapping errorCode = '%s'\n", resVal); */ + ret = UPNPCOMMAND_UNKNOWN_ERROR; + sscanf(resVal, "%d", &ret); + } else { + ret = UPNPCOMMAND_SUCCESS; + } + ClearNameValueList(&pdata); + free(AddPortMappingArgs); + return ret; +} + +LIBSPEC int +UPNP_DeletePortMapping(const char * controlURL, const char * servicetype, + const char * extPort, const char * proto, + const char * remoteHost) +{ + /*struct NameValueParserData pdata;*/ + struct UPNParg * DeletePortMappingArgs; + char * buffer; + int bufsize; + struct NameValueParserData pdata; + const char * resVal; + int ret; + + if(!extPort || !proto) + return UPNPCOMMAND_INVALID_ARGS; + + DeletePortMappingArgs = calloc(4, sizeof(struct UPNParg)); + DeletePortMappingArgs[0].elt = "NewRemoteHost"; + DeletePortMappingArgs[0].val = remoteHost; + DeletePortMappingArgs[1].elt = "NewExternalPort"; + DeletePortMappingArgs[1].val = extPort; + DeletePortMappingArgs[2].elt = "NewProtocol"; + DeletePortMappingArgs[2].val = proto; + if(!(buffer = simpleUPnPcommand(-1, controlURL, servicetype, + "DeletePortMapping", + DeletePortMappingArgs, &bufsize))) { + free(DeletePortMappingArgs); + return UPNPCOMMAND_HTTP_ERROR; + } + /*DisplayNameValueList(buffer, bufsize);*/ + ParseNameValue(buffer, bufsize, &pdata); + free(buffer); buffer = NULL; + resVal = GetValueFromNameValueList(&pdata, "errorCode"); + if(resVal) { + ret = UPNPCOMMAND_UNKNOWN_ERROR; + sscanf(resVal, "%d", &ret); + } else { + ret = UPNPCOMMAND_SUCCESS; + } + ClearNameValueList(&pdata); + free(DeletePortMappingArgs); + return ret; +} + +LIBSPEC int +UPNP_GetGenericPortMappingEntry(const char * controlURL, + const char * servicetype, + const char * index, + char * extPort, + char * intClient, + char * intPort, + char * protocol, + char * desc, + char * enabled, + char * rHost, + char * duration) +{ + struct NameValueParserData pdata; + struct UPNParg * GetPortMappingArgs; + char * buffer; + int bufsize; + char * p; + int r = UPNPCOMMAND_UNKNOWN_ERROR; + if(!index) + return UPNPCOMMAND_INVALID_ARGS; + intClient[0] = '\0'; + intPort[0] = '\0'; + GetPortMappingArgs = calloc(2, sizeof(struct UPNParg)); + GetPortMappingArgs[0].elt = "NewPortMappingIndex"; + GetPortMappingArgs[0].val = index; + if(!(buffer = simpleUPnPcommand(-1, controlURL, servicetype, + "GetGenericPortMappingEntry", + GetPortMappingArgs, &bufsize))) { + free(GetPortMappingArgs); + return UPNPCOMMAND_HTTP_ERROR; + } + ParseNameValue(buffer, bufsize, &pdata); + free(buffer); buffer = NULL; + + p = GetValueFromNameValueList(&pdata, "NewRemoteHost"); + if(p && rHost) + { + strncpy(rHost, p, 64); + rHost[63] = '\0'; + } + p = GetValueFromNameValueList(&pdata, "NewExternalPort"); + if(p && extPort) + { + strncpy(extPort, p, 6); + extPort[5] = '\0'; + r = UPNPCOMMAND_SUCCESS; + } + p = GetValueFromNameValueList(&pdata, "NewProtocol"); + if(p && protocol) + { + strncpy(protocol, p, 4); + protocol[3] = '\0'; + } + p = GetValueFromNameValueList(&pdata, "NewInternalClient"); + if(p && intClient) + { + strncpy(intClient, p, 16); + intClient[15] = '\0'; + r = 0; + } + p = GetValueFromNameValueList(&pdata, "NewInternalPort"); + if(p && intPort) + { + strncpy(intPort, p, 6); + intPort[5] = '\0'; + } + p = GetValueFromNameValueList(&pdata, "NewEnabled"); + if(p && enabled) + { + strncpy(enabled, p, 4); + enabled[3] = '\0'; + } + p = GetValueFromNameValueList(&pdata, "NewPortMappingDescription"); + if(p && desc) + { + strncpy(desc, p, 80); + desc[79] = '\0'; + } + p = GetValueFromNameValueList(&pdata, "NewLeaseDuration"); + if(p && duration) + { + strncpy(duration, p, 16); + duration[15] = '\0'; + } + p = GetValueFromNameValueList(&pdata, "errorCode"); + if(p) { + r = UPNPCOMMAND_UNKNOWN_ERROR; + sscanf(p, "%d", &r); + } + ClearNameValueList(&pdata); + free(GetPortMappingArgs); + return r; +} + +LIBSPEC int +UPNP_GetPortMappingNumberOfEntries(const char * controlURL, + const char * servicetype, + unsigned int * numEntries) +{ + struct NameValueParserData pdata; + char * buffer; + int bufsize; + char* p; + int ret = UPNPCOMMAND_UNKNOWN_ERROR; + if(!(buffer = simpleUPnPcommand(-1, controlURL, servicetype, + "GetPortMappingNumberOfEntries", 0, + &bufsize))) { + return UPNPCOMMAND_HTTP_ERROR; + } +#ifdef DEBUG + DisplayNameValueList(buffer, bufsize); +#endif + ParseNameValue(buffer, bufsize, &pdata); + free(buffer); buffer = NULL; + + p = GetValueFromNameValueList(&pdata, "NewPortMappingNumberOfEntries"); + if(numEntries && p) { + *numEntries = 0; + sscanf(p, "%u", numEntries); + ret = UPNPCOMMAND_SUCCESS; + } + + p = GetValueFromNameValueList(&pdata, "errorCode"); + if(p) { + ret = UPNPCOMMAND_UNKNOWN_ERROR; + sscanf(p, "%d", &ret); + } + + ClearNameValueList(&pdata); + return ret; +} + +/* UPNP_GetSpecificPortMappingEntry retrieves an existing port mapping + * the result is returned in the intClient and intPort strings + * please provide 16 and 6 bytes of data */ +LIBSPEC int +UPNP_GetSpecificPortMappingEntry(const char * controlURL, + const char * servicetype, + const char * extPort, + const char * proto, + char * intClient, + char * intPort, + char * desc, + char * enabled, + char * leaseDuration) +{ + struct NameValueParserData pdata; + struct UPNParg * GetPortMappingArgs; + char * buffer; + int bufsize; + char * p; + int ret = UPNPCOMMAND_UNKNOWN_ERROR; + + if(!intPort || !intClient || !extPort || !proto) + return UPNPCOMMAND_INVALID_ARGS; + + GetPortMappingArgs = calloc(4, sizeof(struct UPNParg)); + GetPortMappingArgs[0].elt = "NewRemoteHost"; + /* TODO : add remote host ? */ + GetPortMappingArgs[1].elt = "NewExternalPort"; + GetPortMappingArgs[1].val = extPort; + GetPortMappingArgs[2].elt = "NewProtocol"; + GetPortMappingArgs[2].val = proto; + if(!(buffer = simpleUPnPcommand(-1, controlURL, servicetype, + "GetSpecificPortMappingEntry", + GetPortMappingArgs, &bufsize))) { + free(GetPortMappingArgs); + return UPNPCOMMAND_HTTP_ERROR; + } + /*DisplayNameValueList(buffer, bufsize);*/ + ParseNameValue(buffer, bufsize, &pdata); + free(buffer); buffer = NULL; + + p = GetValueFromNameValueList(&pdata, "NewInternalClient"); + if(p) { + strncpy(intClient, p, 16); + intClient[15] = '\0'; + ret = UPNPCOMMAND_SUCCESS; + } else + intClient[0] = '\0'; + + p = GetValueFromNameValueList(&pdata, "NewInternalPort"); + if(p) { + strncpy(intPort, p, 6); + intPort[5] = '\0'; + } else + intPort[0] = '\0'; + + p = GetValueFromNameValueList(&pdata, "NewEnabled"); + if(p && enabled) { + strncpy(enabled, p, 4); + enabled[3] = '\0'; + } + + p = GetValueFromNameValueList(&pdata, "NewPortMappingDescription"); + if(p && desc) { + strncpy(desc, p, 80); + desc[79] = '\0'; + } + + p = GetValueFromNameValueList(&pdata, "NewLeaseDuration"); + if(p && leaseDuration) + { + strncpy(leaseDuration, p, 16); + leaseDuration[15] = '\0'; + } + + p = GetValueFromNameValueList(&pdata, "errorCode"); + if(p) { + ret = UPNPCOMMAND_UNKNOWN_ERROR; + sscanf(p, "%d", &ret); + } + + ClearNameValueList(&pdata); + free(GetPortMappingArgs); + return ret; +} + +/* UPNP_GetListOfPortMappings() + * + * Possible UPNP Error codes : + * 606 Action not Authorized + * 730 PortMappingNotFound - no port mapping is found in the specified range. + * 733 InconsistantParameters - NewStartPort and NewEndPort values are not + * consistent. + */ +LIBSPEC int +UPNP_GetListOfPortMappings(const char * controlURL, + const char * servicetype, + const char * startPort, + const char * endPort, + const char * protocol, + const char * numberOfPorts, + struct PortMappingParserData * data) +{ + struct NameValueParserData pdata; + struct UPNParg * GetListOfPortMappingsArgs; + const char * p; + char * buffer; + int bufsize; + int ret = UPNPCOMMAND_UNKNOWN_ERROR; + + if(!startPort || !endPort || !protocol) + return UPNPCOMMAND_INVALID_ARGS; + + GetListOfPortMappingsArgs = calloc(6, sizeof(struct UPNParg)); + GetListOfPortMappingsArgs[0].elt = "NewStartPort"; + GetListOfPortMappingsArgs[0].val = startPort; + GetListOfPortMappingsArgs[1].elt = "NewEndPort"; + GetListOfPortMappingsArgs[1].val = endPort; + GetListOfPortMappingsArgs[2].elt = "NewProtocol"; + GetListOfPortMappingsArgs[2].val = protocol; + GetListOfPortMappingsArgs[3].elt = "NewManage"; + GetListOfPortMappingsArgs[3].val = "1"; + GetListOfPortMappingsArgs[4].elt = "NewNumberOfPorts"; + GetListOfPortMappingsArgs[4].val = numberOfPorts?numberOfPorts:"1000"; + + if(!(buffer = simpleUPnPcommand(-1, controlURL, servicetype, + "GetListOfPortMappings", + GetListOfPortMappingsArgs, &bufsize))) { + free(GetListOfPortMappingsArgs); + return UPNPCOMMAND_HTTP_ERROR; + } + free(GetListOfPortMappingsArgs); + + /*DisplayNameValueList(buffer, bufsize);*/ + ParseNameValue(buffer, bufsize, &pdata); + free(buffer); buffer = NULL; + + /*p = GetValueFromNameValueList(&pdata, "NewPortListing");*/ + /*if(p) { + printf("NewPortListing : %s\n", p); + }*/ + /*printf("NewPortListing(%d chars) : %s\n", + pdata.portListingLength, pdata.portListing);*/ + if(pdata.portListing) + { + /*struct PortMapping * pm; + int i = 0;*/ + ParsePortListing(pdata.portListing, pdata.portListingLength, + data); + ret = UPNPCOMMAND_SUCCESS; + /* + for(pm = data->head.lh_first; pm != NULL; pm = pm->entries.le_next) + { + printf("%2d %s %5hu->%s:%-5hu '%s' '%s'\n", + i, pm->protocol, pm->externalPort, pm->internalClient, + pm->internalPort, + pm->description, pm->remoteHost); + i++; + } + */ + /*FreePortListing(&data);*/ + } + + p = GetValueFromNameValueList(&pdata, "errorCode"); + if(p) { + ret = UPNPCOMMAND_UNKNOWN_ERROR; + sscanf(p, "%d", &ret); + } + ClearNameValueList(&pdata); + + //printf("%.*s", bufsize, buffer); + + return ret; +} + +/* IGD:2, functions for service WANIPv6FirewallControl:1 */ +LIBSPEC int +UPNP_GetFirewallStatus(const char * controlURL, + const char * servicetype, + int * firewallEnabled, + int * inboundPinholeAllowed) +{ + struct NameValueParserData pdata; + char * buffer; + int bufsize; + char * fe, *ipa, *p; + int ret = UPNPCOMMAND_UNKNOWN_ERROR; + + if(!firewallEnabled && !inboundPinholeAllowed) + return UPNPCOMMAND_INVALID_ARGS; + + buffer = simpleUPnPcommand(-1, controlURL, servicetype, + "GetFirewallStatus", 0, &bufsize); + if(!buffer) { + return UPNPCOMMAND_HTTP_ERROR; + } + ParseNameValue(buffer, bufsize, &pdata); + free(buffer); buffer = NULL; + fe = GetValueFromNameValueList(&pdata, "FirewallEnabled"); + ipa = GetValueFromNameValueList(&pdata, "InboundPinholeAllowed"); + if(ipa && fe) + ret = UPNPCOMMAND_SUCCESS; + if(fe) + *firewallEnabled = my_atoui(fe); + /*else + *firewallEnabled = 0;*/ + if(ipa) + *inboundPinholeAllowed = my_atoui(ipa); + /*else + *inboundPinholeAllowed = 0;*/ + p = GetValueFromNameValueList(&pdata, "errorCode"); + if(p) + { + ret = UPNPCOMMAND_UNKNOWN_ERROR; + sscanf(p, "%d", &ret); + } + ClearNameValueList(&pdata); + return ret; +} + +LIBSPEC int +UPNP_GetOutboundPinholeTimeout(const char * controlURL, const char * servicetype, + const char * remoteHost, + const char * remotePort, + const char * intClient, + const char * intPort, + const char * proto, + int * opTimeout) +{ + struct UPNParg * GetOutboundPinholeTimeoutArgs; + char * buffer; + int bufsize; + struct NameValueParserData pdata; + const char * resVal; + char * p; + int ret; + + if(!intPort || !intClient || !proto || !remotePort || !remoteHost) + return UPNPCOMMAND_INVALID_ARGS; + + GetOutboundPinholeTimeoutArgs = calloc(6, sizeof(struct UPNParg)); + GetOutboundPinholeTimeoutArgs[0].elt = "RemoteHost"; + GetOutboundPinholeTimeoutArgs[0].val = remoteHost; + GetOutboundPinholeTimeoutArgs[1].elt = "RemotePort"; + GetOutboundPinholeTimeoutArgs[1].val = remotePort; + GetOutboundPinholeTimeoutArgs[2].elt = "Protocol"; + GetOutboundPinholeTimeoutArgs[2].val = proto; + GetOutboundPinholeTimeoutArgs[3].elt = "InternalPort"; + GetOutboundPinholeTimeoutArgs[3].val = intPort; + GetOutboundPinholeTimeoutArgs[4].elt = "InternalClient"; + GetOutboundPinholeTimeoutArgs[4].val = intClient; + buffer = simpleUPnPcommand(-1, controlURL, servicetype, + "GetOutboundPinholeTimeout", GetOutboundPinholeTimeoutArgs, &bufsize); + if(!buffer) + return UPNPCOMMAND_HTTP_ERROR; + ParseNameValue(buffer, bufsize, &pdata); + free(buffer); buffer = NULL; + resVal = GetValueFromNameValueList(&pdata, "errorCode"); + if(resVal) + { + ret = UPNPCOMMAND_UNKNOWN_ERROR; + sscanf(resVal, "%d", &ret); + } + else + { + ret = UPNPCOMMAND_SUCCESS; + p = GetValueFromNameValueList(&pdata, "OutboundPinholeTimeout"); + if(p) + *opTimeout = my_atoui(p); + } + ClearNameValueList(&pdata); + free(GetOutboundPinholeTimeoutArgs); + return ret; +} + +LIBSPEC int +UPNP_AddPinhole(const char * controlURL, const char * servicetype, + const char * remoteHost, + const char * remotePort, + const char * intClient, + const char * intPort, + const char * proto, + const char * leaseTime, + char * uniqueID) +{ + struct UPNParg * AddPinholeArgs; + char * buffer; + int bufsize; + struct NameValueParserData pdata; + const char * resVal; + char * p; + int ret; + + if(!intPort || !intClient || !proto || !remoteHost || !remotePort || !leaseTime) + return UPNPCOMMAND_INVALID_ARGS; + + AddPinholeArgs = calloc(7, sizeof(struct UPNParg)); + // RemoteHost can be wilcarded + if(strncmp(remoteHost, "empty", 5)==0) + { + AddPinholeArgs[0].elt = "RemoteHost"; + AddPinholeArgs[0].val = ""; + } + else + { + AddPinholeArgs[0].elt = "RemoteHost"; + AddPinholeArgs[0].val = remoteHost; + } + AddPinholeArgs[1].elt = "RemotePort"; + AddPinholeArgs[1].val = remotePort; + AddPinholeArgs[2].elt = "Protocol"; + AddPinholeArgs[2].val = proto; + AddPinholeArgs[3].elt = "InternalPort"; + AddPinholeArgs[3].val = intPort; + if(strncmp(intClient, "empty", 5)==0) + { + AddPinholeArgs[4].elt = "InternalClient"; + AddPinholeArgs[4].val = ""; + } + else + { + AddPinholeArgs[4].elt = "InternalClient"; + AddPinholeArgs[4].val = intClient; + } + AddPinholeArgs[5].elt = "LeaseTime"; + AddPinholeArgs[5].val = leaseTime; + buffer = simpleUPnPcommand(-1, controlURL, servicetype, + "AddPinhole", AddPinholeArgs, &bufsize); + if(!buffer) + return UPNPCOMMAND_HTTP_ERROR; + ParseNameValue(buffer, bufsize, &pdata); + free(buffer); buffer = NULL; + p = GetValueFromNameValueList(&pdata, "UniqueID"); + if(p) + { + strncpy(uniqueID, p, 8); + uniqueID[7] = '\0'; + } + resVal = GetValueFromNameValueList(&pdata, "errorCode"); + if(resVal) + { + //printf("AddPortMapping errorCode = '%s'\n", resVal); + ret = UPNPCOMMAND_UNKNOWN_ERROR; + sscanf(resVal, "%d", &ret); + } + else + { + ret = UPNPCOMMAND_SUCCESS; + } + ClearNameValueList(&pdata); + free(AddPinholeArgs); + return ret; +} + +LIBSPEC int +UPNP_UpdatePinhole(const char * controlURL, const char * servicetype, + const char * uniqueID, + const char * leaseTime) +{ + struct UPNParg * UpdatePinholeArgs; + char * buffer; + int bufsize; + struct NameValueParserData pdata; + const char * resVal; + int ret; + + if(!uniqueID || !leaseTime) + return UPNPCOMMAND_INVALID_ARGS; + + UpdatePinholeArgs = calloc(3, sizeof(struct UPNParg)); + UpdatePinholeArgs[0].elt = "UniqueID"; + UpdatePinholeArgs[0].val = uniqueID; + UpdatePinholeArgs[1].elt = "NewLeaseTime"; + UpdatePinholeArgs[1].val = leaseTime; + buffer = simpleUPnPcommand(-1, controlURL, servicetype, + "UpdatePinhole", UpdatePinholeArgs, &bufsize); + if(!buffer) + return UPNPCOMMAND_HTTP_ERROR; + ParseNameValue(buffer, bufsize, &pdata); + free(buffer); buffer = NULL; + resVal = GetValueFromNameValueList(&pdata, "errorCode"); + if(resVal) + { + /*printf("AddPortMapping errorCode = '%s'\n", resVal); */ + ret = UPNPCOMMAND_UNKNOWN_ERROR; + sscanf(resVal, "%d", &ret); + } + else + { + ret = UPNPCOMMAND_SUCCESS; + } + ClearNameValueList(&pdata); + free(UpdatePinholeArgs); + return ret; +} + +LIBSPEC int +UPNP_DeletePinhole(const char * controlURL, const char * servicetype, const char * uniqueID) +{ + /*struct NameValueParserData pdata;*/ + struct UPNParg * DeletePinholeArgs; + char * buffer; + int bufsize; + struct NameValueParserData pdata; + const char * resVal; + int ret; + + if(!uniqueID) + return UPNPCOMMAND_INVALID_ARGS; + + DeletePinholeArgs = calloc(2, sizeof(struct UPNParg)); + DeletePinholeArgs[0].elt = "UniqueID"; + DeletePinholeArgs[0].val = uniqueID; + buffer = simpleUPnPcommand(-1, controlURL, servicetype, + "DeletePinhole", DeletePinholeArgs, &bufsize); + if(!buffer) + return UPNPCOMMAND_HTTP_ERROR; + /*DisplayNameValueList(buffer, bufsize);*/ + ParseNameValue(buffer, bufsize, &pdata); + free(buffer); buffer = NULL; + resVal = GetValueFromNameValueList(&pdata, "errorCode"); + if(resVal) + { + ret = UPNPCOMMAND_UNKNOWN_ERROR; + sscanf(resVal, "%d", &ret); + } + else + { + ret = UPNPCOMMAND_SUCCESS; + } + ClearNameValueList(&pdata); + free(DeletePinholeArgs); + return ret; +} + +LIBSPEC int +UPNP_CheckPinholeWorking(const char * controlURL, const char * servicetype, + const char * uniqueID, int * isWorking) +{ + struct NameValueParserData pdata; + struct UPNParg * CheckPinholeWorkingArgs; + char * buffer; + int bufsize; + char * p; + int ret = UPNPCOMMAND_UNKNOWN_ERROR; + + if(!uniqueID) + return UPNPCOMMAND_INVALID_ARGS; + + CheckPinholeWorkingArgs = calloc(4, sizeof(struct UPNParg)); + CheckPinholeWorkingArgs[0].elt = "UniqueID"; + CheckPinholeWorkingArgs[0].val = uniqueID; + buffer = simpleUPnPcommand(-1, controlURL, servicetype, + "CheckPinholeWorking", CheckPinholeWorkingArgs, &bufsize); + if(!buffer) + return UPNPCOMMAND_HTTP_ERROR; + ParseNameValue(buffer, bufsize, &pdata); + free(buffer); buffer = NULL; + + p = GetValueFromNameValueList(&pdata, "IsWorking"); + if(p) + { + *isWorking=my_atoui(p); + ret = UPNPCOMMAND_SUCCESS; + } + else + *isWorking = 0; + + p = GetValueFromNameValueList(&pdata, "errorCode"); + if(p) + { + ret = UPNPCOMMAND_UNKNOWN_ERROR; + sscanf(p, "%d", &ret); + } + + ClearNameValueList(&pdata); + free(CheckPinholeWorkingArgs); + return ret; +} + +LIBSPEC int +UPNP_GetPinholePackets(const char * controlURL, const char * servicetype, + const char * uniqueID, int * packets) +{ + struct NameValueParserData pdata; + struct UPNParg * GetPinholePacketsArgs; + char * buffer; + int bufsize; + char * p; + int ret = UPNPCOMMAND_UNKNOWN_ERROR; + + if(!uniqueID) + return UPNPCOMMAND_INVALID_ARGS; + + GetPinholePacketsArgs = calloc(4, sizeof(struct UPNParg)); + GetPinholePacketsArgs[0].elt = "UniqueID"; + GetPinholePacketsArgs[0].val = uniqueID; + buffer = simpleUPnPcommand(-1, controlURL, servicetype, + "GetPinholePackets", GetPinholePacketsArgs, &bufsize); + if(!buffer) + return UPNPCOMMAND_HTTP_ERROR; + ParseNameValue(buffer, bufsize, &pdata); + free(buffer); buffer = NULL; + + p = GetValueFromNameValueList(&pdata, "PinholePackets"); + if(p) + { + *packets=my_atoui(p); + ret = UPNPCOMMAND_SUCCESS; + } + + p = GetValueFromNameValueList(&pdata, "errorCode"); + if(p) + { + ret = UPNPCOMMAND_UNKNOWN_ERROR; + sscanf(p, "%d", &ret); + } + + ClearNameValueList(&pdata); + free(GetPinholePacketsArgs); + return ret; +} + + diff --git a/libs/miniupnpc/upnpcommands.h b/libs/miniupnpc/upnpcommands.h new file mode 100644 index 000000000..66d95e0ca --- /dev/null +++ b/libs/miniupnpc/upnpcommands.h @@ -0,0 +1,271 @@ +/* $Id: upnpcommands.h,v 1.23 2011/04/11 09:14:00 nanard Exp $ */ +/* Miniupnp project : http://miniupnp.free.fr/ + * Author : Thomas Bernard + * Copyright (c) 2005-2011 Thomas Bernard + * This software is subject to the conditions detailed in the + * LICENCE file provided within this distribution */ +#ifndef __UPNPCOMMANDS_H__ +#define __UPNPCOMMANDS_H__ + +#include "upnpreplyparse.h" +#include "portlistingparse.h" +#include "declspec.h" +#include "miniupnpctypes.h" + +/* MiniUPnPc return codes : */ +#define UPNPCOMMAND_SUCCESS (0) +#define UPNPCOMMAND_UNKNOWN_ERROR (-1) +#define UPNPCOMMAND_INVALID_ARGS (-2) +#define UPNPCOMMAND_HTTP_ERROR (-3) + +#ifdef __cplusplus +extern "C" { +#endif + +LIBSPEC UNSIGNED_INTEGER +UPNP_GetTotalBytesSent(const char * controlURL, + const char * servicetype); + +LIBSPEC UNSIGNED_INTEGER +UPNP_GetTotalBytesReceived(const char * controlURL, + const char * servicetype); + +LIBSPEC UNSIGNED_INTEGER +UPNP_GetTotalPacketsSent(const char * controlURL, + const char * servicetype); + +LIBSPEC UNSIGNED_INTEGER +UPNP_GetTotalPacketsReceived(const char * controlURL, + const char * servicetype); + +/* UPNP_GetStatusInfo() + * status and lastconnerror are 64 byte buffers + * Return values : + * UPNPCOMMAND_SUCCESS, UPNPCOMMAND_INVALID_ARGS, UPNPCOMMAND_UNKNOWN_ERROR + * or a UPnP Error code */ +LIBSPEC int +UPNP_GetStatusInfo(const char * controlURL, + const char * servicetype, + char * status, + unsigned int * uptime, + char * lastconnerror); + +/* UPNP_GetConnectionTypeInfo() + * argument connectionType is a 64 character buffer + * Return Values : + * UPNPCOMMAND_SUCCESS, UPNPCOMMAND_INVALID_ARGS, UPNPCOMMAND_UNKNOWN_ERROR + * or a UPnP Error code */ +LIBSPEC int +UPNP_GetConnectionTypeInfo(const char * controlURL, + const char * servicetype, + char * connectionType); + +/* UPNP_GetExternalIPAddress() call the corresponding UPNP method. + * if the third arg is not null the value is copied to it. + * at least 16 bytes must be available + * + * Return values : + * 0 : SUCCESS + * NON ZERO : ERROR Either an UPnP error code or an unknown error. + * + * possible UPnP Errors : + * 402 Invalid Args - See UPnP Device Architecture section on Control. + * 501 Action Failed - See UPnP Device Architecture section on Control. */ +LIBSPEC int +UPNP_GetExternalIPAddress(const char * controlURL, + const char * servicetype, + char * extIpAdd); + +/* UPNP_GetLinkLayerMaxBitRates() + * call WANCommonInterfaceConfig:1#GetCommonLinkProperties + * + * return values : + * UPNPCOMMAND_SUCCESS, UPNPCOMMAND_INVALID_ARGS, UPNPCOMMAND_UNKNOWN_ERROR + * or a UPnP Error Code. */ +LIBSPEC int +UPNP_GetLinkLayerMaxBitRates(const char* controlURL, + const char* servicetype, + unsigned int * bitrateDown, + unsigned int * bitrateUp); + +/* UPNP_AddPortMapping() + * if desc is NULL, it will be defaulted to "libminiupnpc" + * remoteHost is usually NULL because IGD don't support it. + * + * Return values : + * 0 : SUCCESS + * NON ZERO : ERROR. Either an UPnP error code or an unknown error. + * + * List of possible UPnP errors for AddPortMapping : + * errorCode errorDescription (short) - Description (long) + * 402 Invalid Args - See UPnP Device Architecture section on Control. + * 501 Action Failed - See UPnP Device Architecture section on Control. + * 715 WildCardNotPermittedInSrcIP - The source IP address cannot be + * wild-carded + * 716 WildCardNotPermittedInExtPort - The external port cannot be wild-carded + * 718 ConflictInMappingEntry - The port mapping entry specified conflicts + * with a mapping assigned previously to another client + * 724 SamePortValuesRequired - Internal and External port values + * must be the same + * 725 OnlyPermanentLeasesSupported - The NAT implementation only supports + * permanent lease times on port mappings + * 726 RemoteHostOnlySupportsWildcard - RemoteHost must be a wildcard + * and cannot be a specific IP address or DNS name + * 727 ExternalPortOnlySupportsWildcard - ExternalPort must be a wildcard and + * cannot be a specific port value */ +LIBSPEC int +UPNP_AddPortMapping(const char * controlURL, const char * servicetype, + const char * extPort, + const char * inPort, + const char * inClient, + const char * desc, + const char * proto, + const char * remoteHost, + const char * leaseDuration); + +/* UPNP_DeletePortMapping() + * Use same argument values as what was used for AddPortMapping(). + * remoteHost is usually NULL because IGD don't support it. + * Return Values : + * 0 : SUCCESS + * NON ZERO : error. Either an UPnP error code or an undefined error. + * + * List of possible UPnP errors for DeletePortMapping : + * 402 Invalid Args - See UPnP Device Architecture section on Control. + * 714 NoSuchEntryInArray - The specified value does not exist in the array */ +LIBSPEC int +UPNP_DeletePortMapping(const char * controlURL, const char * servicetype, + const char * extPort, const char * proto, + const char * remoteHost); + +/* UPNP_GetPortMappingNumberOfEntries() + * not supported by all routers */ +LIBSPEC int +UPNP_GetPortMappingNumberOfEntries(const char* controlURL, + const char* servicetype, + unsigned int * num); + +/* UPNP_GetSpecificPortMappingEntry() + * retrieves an existing port mapping + * params : + * in extPort + * in proto + * out intClient (16 bytes) + * out intPort (6 bytes) + * out desc (80 bytes) + * out enabled (4 bytes) + * out leaseDuration (16 bytes) + * + * return value : + * UPNPCOMMAND_SUCCESS, UPNPCOMMAND_INVALID_ARGS, UPNPCOMMAND_UNKNOWN_ERROR + * or a UPnP Error Code. */ +LIBSPEC int +UPNP_GetSpecificPortMappingEntry(const char * controlURL, + const char * servicetype, + const char * extPort, + const char * proto, + char * intClient, + char * intPort, + char * desc, + char * enabled, + char * leaseDuration); + +/* UPNP_GetGenericPortMappingEntry() + * params : + * in index + * out extPort (6 bytes) + * out intClient (16 bytes) + * out intPort (6 bytes) + * out protocol (4 bytes) + * out desc (80 bytes) + * out enabled (4 bytes) + * out rHost (64 bytes) + * out duration (16 bytes) + * + * return value : + * UPNPCOMMAND_SUCCESS, UPNPCOMMAND_INVALID_ARGS, UPNPCOMMAND_UNKNOWN_ERROR + * or a UPnP Error Code. + * + * Possible UPNP Error codes : + * 402 Invalid Args - See UPnP Device Architecture section on Control. + * 713 SpecifiedArrayIndexInvalid - The specified array index is out of bounds + */ +LIBSPEC int +UPNP_GetGenericPortMappingEntry(const char * controlURL, + const char * servicetype, + const char * index, + char * extPort, + char * intClient, + char * intPort, + char * protocol, + char * desc, + char * enabled, + char * rHost, + char * duration); + +/* UPNP_GetListOfPortMappings() Available in IGD v2 + * + * + * Possible UPNP Error codes : + * 606 Action not Authorized + * 730 PortMappingNotFound - no port mapping is found in the specified range. + * 733 InconsistantParameters - NewStartPort and NewEndPort values are not + * consistent. + */ +LIBSPEC int +UPNP_GetListOfPortMappings(const char * controlURL, + const char * servicetype, + const char * startPort, + const char * endPort, + const char * protocol, + const char * numberOfPorts, + struct PortMappingParserData * data); + +/* IGD:2, functions for service WANIPv6FirewallControl:1 */ +LIBSPEC int +UPNP_GetFirewallStatus(const char * controlURL, + const char * servicetype, + int * firewallEnabled, + int * inboundPinholeAllowed); + +LIBSPEC int +UPNP_GetOutboundPinholeTimeout(const char * controlURL, const char * servicetype, + const char * remoteHost, + const char * remotePort, + const char * intClient, + const char * intPort, + const char * proto, + int * opTimeout); + +LIBSPEC int +UPNP_AddPinhole(const char * controlURL, const char * servicetype, + const char * remoteHost, + const char * remotePort, + const char * intClient, + const char * intPort, + const char * proto, + const char * leaseTime, + char * uniqueID); + +LIBSPEC int +UPNP_UpdatePinhole(const char * controlURL, const char * servicetype, + const char * uniqueID, + const char * leaseTime); + +LIBSPEC int +UPNP_DeletePinhole(const char * controlURL, const char * servicetype, const char * uniqueID); + +LIBSPEC int +UPNP_CheckPinholeWorking(const char * controlURL, const char * servicetype, + const char * uniqueID, int * isWorking); + +LIBSPEC int +UPNP_GetPinholePackets(const char * controlURL, const char * servicetype, + const char * uniqueID, int * packets); + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/libs/miniupnpc/upnperrors.c b/libs/miniupnpc/upnperrors.c new file mode 100644 index 000000000..a48ae10d3 --- /dev/null +++ b/libs/miniupnpc/upnperrors.c @@ -0,0 +1,103 @@ +/* $Id: upnperrors.c,v 1.5 2011/04/10 11:19:36 nanard Exp $ */ +/* Project : miniupnp + * Author : Thomas BERNARD + * copyright (c) 2007 Thomas Bernard + * All Right reserved. + * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ + * This software is subjet to the conditions detailed in the + * provided LICENCE file. */ +#include +#include "upnperrors.h" +#include "upnpcommands.h" +#include "miniupnpc.h" + +const char * strupnperror(int err) +{ + const char * s = NULL; + switch(err) { + case UPNPCOMMAND_SUCCESS: + s = "Success"; + break; + case UPNPCOMMAND_UNKNOWN_ERROR: + s = "Miniupnpc Unknown Error"; + break; + case UPNPCOMMAND_INVALID_ARGS: + s = "Miniupnpc Invalid Arguments"; + break; + case UPNPDISCOVER_SOCKET_ERROR: + s = "Miniupnpc Socket error"; + break; + case UPNPDISCOVER_MEMORY_ERROR: + s = "Miniupnpc Memory allocation error"; + break; + case 401: + s = "Invalid Action"; + break; + case 402: + s = "Invalid Args"; + break; + case 501: + s = "Action Failed"; + break; + case 606: + s = "Action not authorized"; + break; + case 701: + s = "PinholeSpaceExhausted"; + break; + case 702: + s = "FirewallDisabled"; + break; + case 703: + s = "InboundPinholeNotAllowed"; + break; + case 704: + s = "NoSuchEntry"; + break; + case 705: + s = "ProtocolNotSupported"; + break; + case 706: + s = "InternalPortWildcardingNotAllowed"; + break; + case 707: + s = "ProtocolWildcardingNotAllowed"; + break; + case 708: + s = "WildcardNotPermittedInSrcIP"; + break; + case 709: + s = "NoPacketSent"; + break; + case 713: + s = "SpecifiedArrayIndexInvalid"; + break; + case 714: + s = "NoSuchEntryInArray"; + break; + case 715: + s = "WildCardNotPermittedInSrcIP"; + break; + case 716: + s = "WildCardNotPermittedInExtPort"; + break; + case 718: + s = "ConflictInMappingEntry"; + break; + case 724: + s = "SamePortValuesRequired"; + break; + case 725: + s = "OnlyPermanentLeasesSupported"; + break; + case 726: + s = "RemoteHostOnlySupportsWildcard"; + break; + case 727: + s = "ExternalPortOnlySupportsWildcard"; + break; + default: + s = NULL; + } + return s; +} diff --git a/libs/miniupnpc/upnperrors.h b/libs/miniupnpc/upnperrors.h new file mode 100644 index 000000000..2c544c97c --- /dev/null +++ b/libs/miniupnpc/upnperrors.h @@ -0,0 +1,26 @@ +/* $Id: upnperrors.h,v 1.2 2008/07/02 23:31:15 nanard Exp $ */ +/* (c) 2007 Thomas Bernard + * All rights reserved. + * MiniUPnP Project. + * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ + * This software is subjet to the conditions detailed in the + * provided LICENCE file. */ +#ifndef __UPNPERRORS_H__ +#define __UPNPERRORS_H__ + +#include "declspec.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* strupnperror() + * Return a string description of the UPnP error code + * or NULL for undefinded errors */ +LIBSPEC const char * strupnperror(int err); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libs/miniupnpc/upnpreplyparse.c b/libs/miniupnpc/upnpreplyparse.c new file mode 100644 index 000000000..482030b35 --- /dev/null +++ b/libs/miniupnpc/upnpreplyparse.c @@ -0,0 +1,152 @@ +/* $Id: upnpreplyparse.c,v 1.11 2011/02/07 16:17:06 nanard Exp $ */ +/* MiniUPnP project + * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ + * (c) 2006-2011 Thomas Bernard + * This software is subject to the conditions detailed + * in the LICENCE file provided within the distribution */ + +#include +#include +#include + +#include "upnpreplyparse.h" +#include "minixml.h" + +static void +NameValueParserStartElt(void * d, const char * name, int l) +{ + struct NameValueParserData * data = (struct NameValueParserData *)d; + if(l>63) + l = 63; + memcpy(data->curelt, name, l); + data->curelt[l] = '\0'; +} + +static void +NameValueParserGetData(void * d, const char * datas, int l) +{ + struct NameValueParserData * data = (struct NameValueParserData *)d; + struct NameValue * nv; + if(strcmp(data->curelt, "NewPortListing") == 0) + { + /* specific case for NewPortListing which is a XML Document */ + data->portListing = malloc(l + 1); + if(!data->portListing) + { + /* malloc error */ + return; + } + memcpy(data->portListing, datas, l); + data->portListing[l] = '\0'; + data->portListingLength = l; + } + else + { + /* standard case. Limited to 63 chars strings */ + nv = malloc(sizeof(struct NameValue)); + if(l>63) + l = 63; + strncpy(nv->name, data->curelt, 64); + nv->name[63] = '\0'; + memcpy(nv->value, datas, l); + nv->value[l] = '\0'; + LIST_INSERT_HEAD( &(data->head), nv, entries); + } +} + +void +ParseNameValue(const char * buffer, int bufsize, + struct NameValueParserData * data) +{ + struct xmlparser parser; + LIST_INIT(&(data->head)); + data->portListing = NULL; + data->portListingLength = 0; + /* init xmlparser object */ + parser.xmlstart = buffer; + parser.xmlsize = bufsize; + parser.data = data; + parser.starteltfunc = NameValueParserStartElt; + parser.endeltfunc = 0; + parser.datafunc = NameValueParserGetData; + parser.attfunc = 0; + parsexml(&parser); +} + +void +ClearNameValueList(struct NameValueParserData * pdata) +{ + struct NameValue * nv; + if(pdata->portListing) + { + free(pdata->portListing); + pdata->portListing = NULL; + pdata->portListingLength = 0; + } + while((nv = pdata->head.lh_first) != NULL) + { + LIST_REMOVE(nv, entries); + free(nv); + } +} + +char * +GetValueFromNameValueList(struct NameValueParserData * pdata, + const char * Name) +{ + struct NameValue * nv; + char * p = NULL; + for(nv = pdata->head.lh_first; + (nv != NULL) && (p == NULL); + nv = nv->entries.le_next) + { + if(strcmp(nv->name, Name) == 0) + p = nv->value; + } + return p; +} + +#if 0 +/* useless now that minixml ignores namespaces by itself */ +char * +GetValueFromNameValueListIgnoreNS(struct NameValueParserData * pdata, + const char * Name) +{ + struct NameValue * nv; + char * p = NULL; + char * pname; + for(nv = pdata->head.lh_first; + (nv != NULL) && (p == NULL); + nv = nv->entries.le_next) + { + pname = strrchr(nv->name, ':'); + if(pname) + pname++; + else + pname = nv->name; + if(strcmp(pname, Name)==0) + p = nv->value; + } + return p; +} +#endif + +/* debug all-in-one function + * do parsing then display to stdout */ +#ifdef DEBUG +void +DisplayNameValueList(char * buffer, int bufsize) +{ + struct NameValueParserData pdata; + struct NameValue * nv; + ParseNameValue(buffer, bufsize, &pdata); + for(nv = pdata.head.lh_first; + nv != NULL; + nv = nv->entries.le_next) + { + printf("%s = %s\n", nv->name, nv->value); + } + ClearNameValueList(&pdata); +} +#endif + diff --git a/libs/miniupnpc/upnpreplyparse.h b/libs/miniupnpc/upnpreplyparse.h new file mode 100644 index 000000000..267ea8783 --- /dev/null +++ b/libs/miniupnpc/upnpreplyparse.h @@ -0,0 +1,64 @@ +/* $Id: upnpreplyparse.h,v 1.11 2011/02/07 16:17:06 nanard Exp $ */ +/* MiniUPnP project + * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ + * (c) 2006-2011 Thomas Bernard + * This software is subject to the conditions detailed + * in the LICENCE file provided within the distribution */ + +#ifndef __UPNPREPLYPARSE_H__ +#define __UPNPREPLYPARSE_H__ + +#if defined(NO_SYS_QUEUE_H) || defined(WIN32) || defined(__HAIKU__) +#include "bsdqueue.h" +#else +#include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +struct NameValue { + LIST_ENTRY(NameValue) entries; + char name[64]; + char value[64]; +}; + +struct NameValueParserData { + LIST_HEAD(listhead, NameValue) head; + char curelt[64]; + char * portListing; + int portListingLength; +}; + +/* ParseNameValue() */ +void +ParseNameValue(const char * buffer, int bufsize, + struct NameValueParserData * data); + +/* ClearNameValueList() */ +void +ClearNameValueList(struct NameValueParserData * pdata); + +/* GetValueFromNameValueList() */ +char * +GetValueFromNameValueList(struct NameValueParserData * pdata, + const char * Name); + +/* GetValueFromNameValueListIgnoreNS() */ +char * +GetValueFromNameValueListIgnoreNS(struct NameValueParserData * pdata, + const char * Name); + +/* DisplayNameValueList() */ +#ifdef DEBUG +void +DisplayNameValueList(char * buffer, int bufsize); +#endif + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/libs/miniupnpc/wingenminiupnpcstrings.c b/libs/miniupnpc/wingenminiupnpcstrings.c new file mode 100644 index 000000000..38dd01783 --- /dev/null +++ b/libs/miniupnpc/wingenminiupnpcstrings.c @@ -0,0 +1,82 @@ +/* $Id: wingenminiupnpcstrings.c,v 1.2 2011/01/11 15:31:13 nanard Exp $ */ +/* Project: miniupnp + * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ + * Author: Thomas Bernard + * Copyright (c) 2005-2009 Thomas Bernard + * This software is subjects to the conditions detailed + * in the LICENSE file provided within this distribution */ +#include +#include + +/* This program display the Windows version and is used to + * generate the miniupnpcstrings.h + * wingenminiupnpcstrings miniupnpcstrings.h.in miniupnpcstrings.h + */ +int main(int argc, char * * argv) { + char buffer[256]; + OSVERSIONINFO osvi; + FILE * fin; + FILE * fout; + int n; + char miniupnpcVersion[32]; + /* dwMajorVersion : + The major version number of the operating system. For more information, see Remarks. + dwMinorVersion : + The minor version number of the operating system. For more information, see Remarks. + dwBuildNumber : + The build number of the operating system. + dwPlatformId + The operating system platform. This member can be the following value. + szCSDVersion + A null-terminated string, such as "Service Pack 3", that indicates the + latest Service Pack installed on the system. If no Service Pack has + been installed, the string is empty. + */ + ZeroMemory(&osvi, sizeof(OSVERSIONINFO)); + osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + + GetVersionEx(&osvi); + + printf("Windows %lu.%lu Build %lu %s\n", + osvi.dwMajorVersion, osvi.dwMinorVersion, + osvi.dwBuildNumber, (const char *)&(osvi.szCSDVersion)); + + fin = fopen("VERSION", "r"); + fgets(miniupnpcVersion, sizeof(miniupnpcVersion), fin); + fclose(fin); + for(n = 0; n < sizeof(miniupnpcVersion); n++) { + if(miniupnpcVersion[n] < ' ') + miniupnpcVersion[n] = '\0'; + } + printf("MiniUPnPc version %s\n", miniupnpcVersion); + + if(argc >= 3) { + fin = fopen(argv[1], "r"); + if(!fin) { + fprintf(stderr, "Cannot open %s for reading.\n", argv[1]); + return 1; + } + fout = fopen(argv[2], "w"); + if(!fout) { + fprintf(stderr, "Cannot open %s for writing.\n", argv[2]); + return 1; + } + n = 0; + while(fgets(buffer, sizeof(buffer), fin)) { + if(0 == memcmp(buffer, "#define OS_STRING \"OS/version\"", 30)) { + sprintf(buffer, "#define OS_STRING \"MSWindows/%ld.%ld.%ld\"\n", + osvi.dwMajorVersion, osvi.dwMinorVersion, osvi.dwBuildNumber); + } else if(0 == memcmp(buffer, "#define MINIUPNPC_VERSION_STRING \"version\"", 42)) { + sprintf(buffer, "#define MINIUPNPC_VERSION_STRING \"%s\"\n", + miniupnpcVersion); + } + /*fputs(buffer, stdout);*/ + fputs(buffer, fout); + n++; + } + fclose(fin); + fclose(fout); + printf("%d lines written to %s.\n", n, argv[2]); + } + return 0; +} diff --git a/libs/win-iconv/CMakeLists.txt b/libs/win-iconv/CMakeLists.txt new file mode 100644 index 000000000..35fc6385a --- /dev/null +++ b/libs/win-iconv/CMakeLists.txt @@ -0,0 +1,64 @@ +project(win_iconv) + +cmake_minimum_required(VERSION 2.6) +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}) + +set(CPACK_GENERATOR "TBZ2") +include(CPack) +option(BUILD_TEST "build test executable" OFF) +option(BUILD_STATIC "build the static lib" OFF) +if(BUILD_TEST) + enable_testing() +endif(BUILD_TEST) + +if(MSVC) + add_definitions(-D_CRT_SECURE_NO_WARNINGS) +endif(MSVC) + +if(NOT WINCE) + add_definitions(-DUSE_LIBICONV_DLL) + if(DEFAULT_LIBICONV_DLL) + add_definitions(-DDEFAULT_LIBICONV_DLL=${DEFAULT_LIBICONV_DLL}) + endif(DEFAULT_LIBICONV_DLL) +else(NOT WINCE) + find_package(Wcecompat REQUIRED) + include_directories(${WCECOMPAT_INCLUDE_DIR}) +endif(NOT WINCE) + +add_library(iconv SHARED win_iconv.c iconv.def) +set_target_properties(iconv PROPERTIES COMPILE_FLAGS "-DMAKE_DLL") + +add_executable(win_iconv win_iconv.c) +set_target_properties(win_iconv PROPERTIES COMPILE_FLAGS "-DMAKE_EXE") + +if(WINCE) + target_link_libraries(iconv ${WCECOMPAT_LIBRARIES}) + target_link_libraries(win_iconv ${WCECOMPAT_LIBRARIES}) +endif(WINCE) + +install(TARGETS iconv win_iconv RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib) + +if(BUILD_STATIC) + add_library(iconv-static STATIC win_iconv.c) + set_target_properties(iconv-static PROPERTIES OUTPUT_NAME "iconv") + if(WINCE) + target_link_libraries(iconv-static ${WCECOMPAT_LIBRARIES}) + endif(WINCE) + install(TARGETS iconv-static RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib) +endif(BUILD_STATIC) + + +install(FILES iconv.h DESTINATION include) + +if(BUILD_TEST) + # tests: + add_executable(win_iconv_test win_iconv_test.c) + add_test(win_iconv_test win_iconv_test) + if(WINCE) + target_link_libraries(win_iconv_test ${WCECOMPAT_LIBRARIES}) + endif(WINCE) +endif(BUILD_TEST) diff --git a/libs/win-iconv/ChangeLog b/libs/win-iconv/ChangeLog new file mode 100644 index 000000000..d6f145a95 --- /dev/null +++ b/libs/win-iconv/ChangeLog @@ -0,0 +1,82 @@ +2011-01-13 Yukihiro Nakadaira + + * win_iconv_test.c: Removed unused variable. + + * win_iconv_test.c: Added USE_ICONV_H flag to compile with -liconv. + (Issue 2) (Thanks to amorilia.gamebox) + +2010-04-14 Patrick von Reth + + * added c++ support + +2010-03-28 Patrick Spendrin + + * CMakeLists.txt, win_iconv.c: add CMake buildsystem, fix bug from issue tracker + +2009-07-25 Yukihiro Nakadaira + + * win_iconv.c, readme.txt: doc fix + +2009-07-06 Yukihiro Nakadaira + + * win_iconv.c, Makefile, readme.txt: doc fix + +2009-06-19 Yukihiro Nakadaira + + * win_iconv.c: cosmetic change + * win_iconv.c: Change Unicode BOM behavior + 1. Remove the BOM when "fromcode" is utf-16 or utf-32. + 2. Add the BOM when "tocode" is utf-16 or utf-32. + +2009-06-18 Yukihiro Nakadaira + + * win_iconv.c: Fixed a bug that invalid input may cause an + endless loop + +2009-06-18 Yukihiro Nakadaira + + * win_iconv.c: Fixed a bug that libiconv_iconv_open() doesn't + work (Christophe Benoit) + +2008-04-01 Yukihiro Nakadaira + + * win_iconv.c: Added //TRANSLIT option. + http://bugzilla.gnome.org/show_bug.cgi?id=524314 + +2008-03-20 Yukihiro Nakadaira + + * win_iconv.c: The dwFlags parameter to MultiByteToWideChars() + must be zero for some code pages (Tor Lillqvist) + +2008-03-19 Yukihiro Nakadaira + + * win_iconv.c: Added support for UCS-2 and GB18030 (Tor Lillqvist) + +2007-12-03 Yukihiro Nakadaira + + * iconv.h: #include to use size_t + +2007-11-28 Yukihiro Nakadaira + + * win_iconv.c: bug fix for two things (Tor Lillqvist) + 1) This is probably not important: Add a function + must_use_null_useddefaultchar() that checks for those + codepages for which the docs for WideCharToMultiByte() say + one has to use a NULL lpDefaultChar pointer. Don't know if + this is actually needed, but better to be safe than sorry. + 2) This is essential: In kernel_wctomb(), the code should first + check if bufsize is zero, and return the E2BIG error in that + case. + +2007-11-26 Yukihiro Nakadaira + + * win_iconv.c: ISO-8859-1 should be CP28591, not CP1252 (Tor + Lillqvist) + +2007-11-26 Yukihiro Nakadaira + + * win_iconv.c: patch from Tor Lillqvist (with alteration) + +2007-09-04 Yukihiro Nakadaira + + * : Initial import diff --git a/libs/win-iconv/FindWcecompat.cmake b/libs/win-iconv/FindWcecompat.cmake new file mode 100644 index 000000000..427697509 --- /dev/null +++ b/libs/win-iconv/FindWcecompat.cmake @@ -0,0 +1,33 @@ +# Try to find Wcecompat functionality +# Once done this will define +# +# WCECOMPAT_FOUND - system has Wcecompat +# WCECOMPAT_INCLUDE_DIR - Wcecompat include directory +# WCECOMPAT_LIBRARIES - Libraries needed to use Wcecompat +# +# Copyright (c) 2010, Andreas Holzammer, +# +# Redistribution and use is allowed according to the terms of the BSD license. + +if(WCECOMPAT_INCLUDE_DIR AND WCECOMPAT_LIB_FOUND) + set(Wcecompat_FIND_QUIETLY TRUE) +endif(WCECOMPAT_INCLUDE_DIR AND WCECOMPAT_LIB_FOUND) + +find_path(WCECOMPAT_INCLUDE_DIR errno.h PATH_SUFFIXES wcecompat) + +set(WCECOMPAT_LIB_FOUND FALSE) + +if(WCECOMPAT_INCLUDE_DIR) + find_library(WCECOMPAT_LIBRARIES NAMES wcecompat wcecompatex ) + if(WCECOMPAT_LIBRARIES) + set(WCECOMPAT_LIB_FOUND TRUE) + endif(WCECOMPAT_LIBRARIES) +endif(WCECOMPAT_INCLUDE_DIR) + +# I have no idea what this is about, but it seems to be used quite often, so I add this here +set(WCECOMPAT_CONST const) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Wcecompat DEFAULT_MSG WCECOMPAT_LIBRARIES WCECOMPAT_LIB_FOUND) + +mark_as_advanced(WCECOMPAT_INCLUDE_DIR WCECOMPAT_LIBRARIES WCECOMPAT_CONST WCECOMPAT_LIB_FOUND) diff --git a/libs/win-iconv/Makefile b/libs/win-iconv/Makefile new file mode 100644 index 000000000..50bffbb74 --- /dev/null +++ b/libs/win-iconv/Makefile @@ -0,0 +1,91 @@ + +# comma separated list (e.g. "iconv.dll,libiconv.dll") +DEFAULT_LIBICONV_DLL ?= \"\" + + +prefix ?=/usr/local/mingw +INSTALL ?=install + +COPY ?=cp +MKDIR ?=mkdir +SVN_EXPORT ?=svn export +ZIP ?=zip + +CFLAGS += -pedantic -Wall +CPPFLAGS += -DUSE_LIBICONV_DLL +CPPFLAGS += -DDEFAULT_LIBICONV_DLL=$(DEFAULT_LIBICONV_DLL) + +DLLWRAP ?=dllwrap +RANLIB ?=ranlib +STRIP ?=strip + +all: iconv.dll libiconv.a win_iconv.exe + +dist: test win_iconv.zip + +iconv.dll: win_iconv.c + $(CC) $(CPPFLAGS) $(CFLAGS) -c $< -DMAKE_DLL + $(DLLWRAP) --dllname $@ --def iconv.def win_iconv.o $(SPECS_FLAGS) + $(STRIP) $@ + +libiconv.a: win_iconv.c + $(CC) $(CPPFLAGS) $(CFLAGS) -c $< + $(AR) rcs $@ win_iconv.o + $(RANLIB) $@ + +win_iconv.exe: win_iconv.c + $(CC) $(CPPFLAGS) $(CFLAGS) -s -o$@ $< -DMAKE_EXE + +libmlang.a: mlang.def + $(DLLTOOL) --kill-at --input-def $< --output-lib $@ + +test: + $(CC) $(CPPFLAGS) $(CFLAGS) -s -o win_iconv_test.exe win_iconv_test.c + ./win_iconv_test.exe + +win_iconv.zip: msvcrt msvcr70 msvcr71 + $(RM) -r win_iconv + $(SVN_EXPORT) . win_iconv + $(COPY) msvcrt/iconv.dll msvcrt/win_iconv.exe win_iconv/ + $(MKDIR) win_iconv/msvcr70 + $(COPY) msvcr70/iconv.dll win_iconv/msvcr70/ + $(MKDIR) win_iconv/msvcr71 + $(COPY) msvcr71/iconv.dll win_iconv/msvcr71/ + $(ZIP) -r $@ win_iconv + +msvcrt: + $(SVN_EXPORT) . $@ + $(MAKE) -C $@ + +msvcr70: + $(SVN_EXPORT) . $@ + $(CC) -dumpspecs | sed s/-lmsvcrt/-l$@/ > $@/specs + $(MAKE) -C $@ "SPECS_FLAGS=-specs=$$PWD/specs" + +msvcr71: + $(SVN_EXPORT) . $@ + $(CC) -dumpspecs | sed s/-lmsvcrt/-l$@/ > $@/specs + $(MAKE) -C $@ "SPECS_FLAGS=-specs=$$PWD/specs" + +install: all + -$(MKDIR) -p $(DESTDIR)$(prefix)/bin + $(INSTALL) iconv.dll $(DESTDIR)$(prefix)/bin/iconv.dll + $(INSTALL) win_iconv.exe $(DESTDIR)$(prefix)/bin/win_iconv.exe + -$(MKDIR) -p $(DESTDIR)$(prefix)/lib + $(INSTALL) libiconv.a $(DESTDIR)$(prefix)/lib/libiconv.a + -$(MKDIR) -p $(DESTDIR)$(prefix)/include + $(INSTALL) iconv.h $(DESTDIR)$(prefix)/include/iconv.h + +clean: + $(RM) win_iconv.exe + $(RM) win_iconv.o + $(RM) iconv.dll* + $(RM) libiconv.a + $(RM) libiconv.dll + $(RM) win_iconv_test.exe + $(RM) libmlang.a + $(RM) -r win_iconv + $(RM) -r win_iconv.zip + $(RM) -r msvcrt + $(RM) -r msvcr70 + $(RM) -r msvcr71 diff --git a/libs/win-iconv/iconv.def b/libs/win-iconv/iconv.def new file mode 100644 index 000000000..f0564b1f3 --- /dev/null +++ b/libs/win-iconv/iconv.def @@ -0,0 +1,24 @@ +LIBRARY ICONV.DLL +EXPORTS + iconv + iconv_open + iconv_close + iconvctl + libiconv=iconv + libiconv_open=iconv_open + libiconv_close=iconv_close + libiconvctl=iconvctl +;; libiconv-1.11.dll +;; TODO for binary compatibility +; _libiconv_version @1 +; aliases2_lookup @2 +; aliases_lookup @3 +; iconv_canonicalize @4 +; libiconv @5 +; libiconv_close @6 +; libiconv_open @7 +; libiconv_relocate @8 +; libiconv_set_relocation_prefix @9 +; libiconvctl @10 +; libiconvlist @11 +; locale_charset @12 diff --git a/libs/win-iconv/iconv.h b/libs/win-iconv/iconv.h new file mode 100644 index 000000000..eca8070bb --- /dev/null +++ b/libs/win-iconv/iconv.h @@ -0,0 +1,14 @@ +#ifndef _LIBICONV_H +#define _LIBICONV_H +#include +#ifdef __cplusplus +extern "C" { +#endif +typedef void* iconv_t; +iconv_t iconv_open(const char *tocode, const char *fromcode); +int iconv_close(iconv_t cd); +size_t iconv(iconv_t cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft); +#ifdef __cplusplus +} +#endif +#endif//_LIBICONV_H \ No newline at end of file diff --git a/libs/win-iconv/libiconv32.a b/libs/win-iconv/libiconv32.a new file mode 100644 index 000000000..9906a4b1a Binary files /dev/null and b/libs/win-iconv/libiconv32.a differ diff --git a/libs/win-iconv/libiconv64.a b/libs/win-iconv/libiconv64.a new file mode 100644 index 000000000..47b86e5ff Binary files /dev/null and b/libs/win-iconv/libiconv64.a differ diff --git a/libs/win-iconv/mlang.def b/libs/win-iconv/mlang.def new file mode 100644 index 000000000..95026899a --- /dev/null +++ b/libs/win-iconv/mlang.def @@ -0,0 +1,11 @@ +LIBRARY MLANG.DLL +EXPORTS + ConvertINetMultiByteToUnicode@24 + ;; ConvertINetReset (not documented) + ConvertINetString@28 + ConvertINetUnicodeToMultiByte@24 + IsConvertINetStringAvailable@8 + LcidToRfc1766A@12 + LcidToRfc1766W@12 + Rfc1766ToLcidA@8 + Rfc1766ToLcidW@8 diff --git a/libs/win-iconv/mlang.h b/libs/win-iconv/mlang.h new file mode 100644 index 000000000..5cbf779c9 --- /dev/null +++ b/libs/win-iconv/mlang.h @@ -0,0 +1,54 @@ +HRESULT WINAPI ConvertINetString( + LPDWORD lpdwMode, + DWORD dwSrcEncoding, + DWORD dwDstEncoding, + LPCSTR lpSrcStr, + LPINT lpnSrcSize, + LPBYTE lpDstStr, + LPINT lpnDstSize +); + +HRESULT WINAPI ConvertINetMultiByteToUnicode( + LPDWORD lpdwMode, + DWORD dwSrcEncoding, + LPCSTR lpSrcStr, + LPINT lpnMultiCharCount, + LPWSTR lpDstStr, + LPINT lpnWideCharCount +); + +HRESULT WINAPI ConvertINetUnicodeToMultiByte( + LPDWORD lpdwMode, + DWORD dwEncoding, + LPCWSTR lpSrcStr, + LPINT lpnWideCharCount, + LPSTR lpDstStr, + LPINT lpnMultiCharCount +); + +HRESULT WINAPI IsConvertINetStringAvailable( + DWORD dwSrcEncoding, + DWORD dwDstEncoding +); + +HRESULT WINAPI LcidToRfc1766A( + LCID Locale, + LPSTR pszRfc1766, + int nChar +); + +HRESULT WINAPI LcidToRfc1766W( + LCID Locale, + LPWSTR pszRfc1766, + int nChar +); + +HRESULT WINAPI Rfc1766ToLcidA( + LCID *pLocale, + LPSTR pszRfc1766 +); + +HRESULT WINAPI Rfc1766ToLcidW( + LCID *pLocale, + LPWSTR pszRfc1766 +); diff --git a/libs/win-iconv/readme.txt b/libs/win-iconv/readme.txt new file mode 100644 index 000000000..fc0616030 --- /dev/null +++ b/libs/win-iconv/readme.txt @@ -0,0 +1,20 @@ +win_iconv is a iconv implementation using Win32 API to convert. + +win_iconv is placed in the public domain. + +ENVIRONMENT VARIABLE: + WINICONV_LIBICONV_DLL + If $WINICONV_LIBICONV_DLL is set, win_iconv uses the DLL. If + loading the DLL or iconv_open() failed, falls back to internal + conversion. If a few DLL are specified as comma separated list, + the first loadable DLL is used. The DLL should have + iconv_open(), iconv_close() and iconv(). Or libiconv_open(), + libiconv_close() and libiconv(). + (only available when USE_LIBICONV_DLL is defined at compile time) + +Win32 API does not support strict encoding conversion for some codepage. +And MLang function drop or replace invalid bytes and does not return +useful error status as iconv. This implementation cannot be used for +encoding validation purpose. + +Yukihiro Nakadaira diff --git a/libs/win-iconv/win32/iconv.dll b/libs/win-iconv/win32/iconv.dll new file mode 100644 index 000000000..336c47649 Binary files /dev/null and b/libs/win-iconv/win32/iconv.dll differ diff --git a/libs/win-iconv/win32/win_iconv.exe b/libs/win-iconv/win32/win_iconv.exe new file mode 100644 index 000000000..ed5ed6a7d Binary files /dev/null and b/libs/win-iconv/win32/win_iconv.exe differ diff --git a/libs/win-iconv/win64/iconv.dll b/libs/win-iconv/win64/iconv.dll new file mode 100644 index 000000000..5eb3d455e Binary files /dev/null and b/libs/win-iconv/win64/iconv.dll differ diff --git a/libs/win-iconv/win64/win_iconv.exe b/libs/win-iconv/win64/win_iconv.exe new file mode 100644 index 000000000..eb2c3360e Binary files /dev/null and b/libs/win-iconv/win64/win_iconv.exe differ diff --git a/libs/win-iconv/win_iconv.c b/libs/win-iconv/win_iconv.c new file mode 100644 index 000000000..9ce8d951b --- /dev/null +++ b/libs/win-iconv/win_iconv.c @@ -0,0 +1,1983 @@ +/* + * iconv implementation using Win32 API to convert. + * + * This file is placed in the public domain. + */ + +/* for WC_NO_BEST_FIT_CHARS */ +#ifndef WINVER +# define WINVER 0x0500 +#endif + +#define STRICT +#include +#include +#include +#include + +#if 0 +# define MAKE_EXE +# define MAKE_DLL +# define USE_LIBICONV_DLL +#endif + +#if !defined(DEFAULT_LIBICONV_DLL) +# define DEFAULT_LIBICONV_DLL "" +#endif + +#define MB_CHAR_MAX 16 + +#define UNICODE_MODE_BOM_DONE 1 +#define UNICODE_MODE_SWAPPED 2 + +#define FLAG_USE_BOM 1 +#define FLAG_TRANSLIT 2 /* //TRANSLIT */ +#define FLAG_IGNORE 4 /* //IGNORE (not implemented) */ + +typedef unsigned char uchar; +typedef unsigned short ushort; +typedef unsigned int uint; + +typedef void* iconv_t; + +iconv_t iconv_open(const char *tocode, const char *fromcode); +int iconv_close(iconv_t cd); +size_t iconv(iconv_t cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft); + +/* libiconv interface for vim */ +#if defined(MAKE_DLL) +int +iconvctl (iconv_t cd, int request, void* argument) +{ + /* not supported */ + return 0; +} +#endif + +typedef struct compat_t compat_t; +typedef struct csconv_t csconv_t; +typedef struct rec_iconv_t rec_iconv_t; + +typedef iconv_t (*f_iconv_open)(const char *tocode, const char *fromcode); +typedef int (*f_iconv_close)(iconv_t cd); +typedef size_t (*f_iconv)(iconv_t cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft); +typedef int* (*f_errno)(void); +typedef int (*f_mbtowc)(csconv_t *cv, const uchar *buf, int bufsize, ushort *wbuf, int *wbufsize); +typedef int (*f_wctomb)(csconv_t *cv, ushort *wbuf, int wbufsize, uchar *buf, int bufsize); +typedef int (*f_mblen)(csconv_t *cv, const uchar *buf, int bufsize); +typedef int (*f_flush)(csconv_t *cv, uchar *buf, int bufsize); + +#define COMPAT_IN 1 +#define COMPAT_OUT 2 + +/* unicode mapping for compatibility with other conversion table. */ +struct compat_t { + uint in; + uint out; + uint flag; +}; + +struct csconv_t { + int codepage; + int flags; + f_mbtowc mbtowc; + f_wctomb wctomb; + f_mblen mblen; + f_flush flush; + DWORD mode; + compat_t *compat; +}; + +struct rec_iconv_t { + iconv_t cd; + f_iconv_close iconv_close; + f_iconv iconv; + f_errno _errno; + csconv_t from; + csconv_t to; +#if defined(USE_LIBICONV_DLL) + HMODULE hlibiconv; +#endif +}; + +static int win_iconv_open(rec_iconv_t *cd, const char *tocode, const char *fromcode); +static int win_iconv_close(iconv_t cd); +static size_t win_iconv(iconv_t cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft); + +static int load_mlang(); +static int make_csconv(const char *name, csconv_t *cv); +static int name_to_codepage(const char *name); +static uint utf16_to_ucs4(const ushort *wbuf); +static void ucs4_to_utf16(uint wc, ushort *wbuf, int *wbufsize); +static int mbtowc_flags(int codepage); +static int must_use_null_useddefaultchar(int codepage); +static char *strrstr(const char *str, const char *token); +static char *xstrndup(const char *s, size_t n); +static int seterror(int err); + +#if defined(USE_LIBICONV_DLL) +static int libiconv_iconv_open(rec_iconv_t *cd, const char *tocode, const char *fromcode); +static PVOID MyImageDirectoryEntryToData(LPVOID Base, BOOLEAN MappedAsImage, USHORT DirectoryEntry, PULONG Size); +static HMODULE find_imported_module_by_funcname(HMODULE hModule, const char *funcname); + +static HMODULE hwiniconv; +#endif + +static int sbcs_mblen(csconv_t *cv, const uchar *buf, int bufsize); +static int dbcs_mblen(csconv_t *cv, const uchar *buf, int bufsize); +static int mbcs_mblen(csconv_t *cv, const uchar *buf, int bufsize); +static int utf8_mblen(csconv_t *cv, const uchar *buf, int bufsize); +static int eucjp_mblen(csconv_t *cv, const uchar *buf, int bufsize); + +static int kernel_mbtowc(csconv_t *cv, const uchar *buf, int bufsize, ushort *wbuf, int *wbufsize); +static int kernel_wctomb(csconv_t *cv, ushort *wbuf, int wbufsize, uchar *buf, int bufsize); +static int mlang_mbtowc(csconv_t *cv, const uchar *buf, int bufsize, ushort *wbuf, int *wbufsize); +static int mlang_wctomb(csconv_t *cv, ushort *wbuf, int wbufsize, uchar *buf, int bufsize); +static int utf16_mbtowc(csconv_t *cv, const uchar *buf, int bufsize, ushort *wbuf, int *wbufsize); +static int utf16_wctomb(csconv_t *cv, ushort *wbuf, int wbufsize, uchar *buf, int bufsize); +static int utf32_mbtowc(csconv_t *cv, const uchar *buf, int bufsize, ushort *wbuf, int *wbufsize); +static int utf32_wctomb(csconv_t *cv, ushort *wbuf, int wbufsize, uchar *buf, int bufsize); +static int iso2022jp_mbtowc(csconv_t *cv, const uchar *buf, int bufsize, ushort *wbuf, int *wbufsize); +static int iso2022jp_wctomb(csconv_t *cv, ushort *wbuf, int wbufsize, uchar *buf, int bufsize); +static int iso2022jp_flush(csconv_t *cv, uchar *buf, int bufsize); + +static struct { + int codepage; + const char *name; +} codepage_alias[] = { + {65001, "CP65001"}, + {65001, "UTF8"}, + {65001, "UTF-8"}, + + {1200, "CP1200"}, + {1200, "UTF16LE"}, + {1200, "UTF-16LE"}, + {1200, "UCS2LE"}, + {1200, "UCS-2LE"}, + + {1201, "CP1201"}, + {1201, "UTF16BE"}, + {1201, "UTF-16BE"}, + {1201, "UCS2BE"}, + {1201, "UCS-2BE"}, + {1201, "unicodeFFFE"}, + + {12000, "CP12000"}, + {12000, "UTF32LE"}, + {12000, "UTF-32LE"}, + {12000, "UCS4LE"}, + {12000, "UCS-4LE"}, + + {12001, "CP12001"}, + {12001, "UTF32BE"}, + {12001, "UTF-32BE"}, + {12001, "UCS4BE"}, + {12001, "UCS-4BE"}, + +#ifndef GLIB_COMPILATION + /* + * Default is big endian. + * See rfc2781 4.3 Interpreting text labelled as UTF-16. + */ + {1201, "UTF16"}, + {1201, "UTF-16"}, + {12001, "UTF32"}, + {12001, "UTF-32"}, + {12001, "UCS-4"}, + {12001, "UCS4"}, +#else + /* Default is little endian, because the platform is */ + {1200, "UTF16"}, + {1200, "UTF-16"}, + {1200, "UCS2"}, + {1200, "UCS-2"}, + {12000, "UTF32"}, + {12000, "UTF-32"}, + {12000, "UCS4"}, + {12000, "UCS-4"}, +#endif + + /* copy from libiconv `iconv -l` */ + /* !IsValidCodePage(367) */ + {20127, "ANSI_X3.4-1968"}, + {20127, "ANSI_X3.4-1986"}, + {20127, "ASCII"}, + {20127, "CP367"}, + {20127, "IBM367"}, + {20127, "ISO-IR-6"}, + {20127, "ISO646-US"}, + {20127, "ISO_646.IRV:1991"}, + {20127, "US"}, + {20127, "US-ASCII"}, + {20127, "CSASCII"}, + + /* !IsValidCodePage(819) */ + {1252, "CP819"}, + {1252, "IBM819"}, + {28591, "ISO-8859-1"}, + {28591, "ISO-IR-100"}, + {28591, "ISO8859-1"}, + {28591, "ISO_8859-1"}, + {28591, "ISO_8859-1:1987"}, + {28591, "L1"}, + {28591, "LATIN1"}, + {28591, "CSISOLATIN1"}, + + {1250, "CP1250"}, + {1250, "MS-EE"}, + {1250, "WINDOWS-1250"}, + + {1251, "CP1251"}, + {1251, "MS-CYRL"}, + {1251, "WINDOWS-1251"}, + + {1252, "CP1252"}, + {1252, "MS-ANSI"}, + {1252, "WINDOWS-1252"}, + + {1253, "CP1253"}, + {1253, "MS-GREEK"}, + {1253, "WINDOWS-1253"}, + + {1254, "CP1254"}, + {1254, "MS-TURK"}, + {1254, "WINDOWS-1254"}, + + {1255, "CP1255"}, + {1255, "MS-HEBR"}, + {1255, "WINDOWS-1255"}, + + {1256, "CP1256"}, + {1256, "MS-ARAB"}, + {1256, "WINDOWS-1256"}, + + {1257, "CP1257"}, + {1257, "WINBALTRIM"}, + {1257, "WINDOWS-1257"}, + + {1258, "CP1258"}, + {1258, "WINDOWS-1258"}, + + {850, "850"}, + {850, "CP850"}, + {850, "IBM850"}, + {850, "CSPC850MULTILINGUAL"}, + + /* !IsValidCodePage(862) */ + {862, "862"}, + {862, "CP862"}, + {862, "IBM862"}, + {862, "CSPC862LATINHEBREW"}, + + {866, "866"}, + {866, "CP866"}, + {866, "IBM866"}, + {866, "CSIBM866"}, + + /* !IsValidCodePage(154) */ + {154, "CP154"}, + {154, "CYRILLIC-ASIAN"}, + {154, "PT154"}, + {154, "PTCP154"}, + {154, "CSPTCP154"}, + + /* !IsValidCodePage(1133) */ + {1133, "CP1133"}, + {1133, "IBM-CP1133"}, + + {874, "CP874"}, + {874, "WINDOWS-874"}, + + /* !IsValidCodePage(51932) */ + {51932, "CP51932"}, + {51932, "MS51932"}, + {51932, "WINDOWS-51932"}, + {51932, "EUC-JP"}, + + {932, "CP932"}, + {932, "MS932"}, + {932, "SHIFFT_JIS"}, + {932, "SHIFFT_JIS-MS"}, + {932, "SJIS"}, + {932, "SJIS-MS"}, + {932, "SJIS-OPEN"}, + {932, "SJIS-WIN"}, + {932, "WINDOWS-31J"}, + {932, "WINDOWS-932"}, + {932, "CSWINDOWS31J"}, + + {50221, "CP50221"}, + {50221, "ISO-2022-JP"}, + {50221, "ISO-2022-JP-MS"}, + {50221, "ISO2022-JP"}, + {50221, "ISO2022-JP-MS"}, + {50221, "MS50221"}, + {50221, "WINDOWS-50221"}, + + {936, "CP936"}, + {936, "GBK"}, + {936, "MS936"}, + {936, "WINDOWS-936"}, + + {950, "CP950"}, + {950, "BIG5"}, + + {949, "CP949"}, + {949, "UHC"}, + {949, "EUC-KR"}, + + {1361, "CP1361"}, + {1361, "JOHAB"}, + + {437, "437"}, + {437, "CP437"}, + {437, "IBM437"}, + {437, "CSPC8CODEPAGE437"}, + + {737, "CP737"}, + + {775, "CP775"}, + {775, "IBM775"}, + {775, "CSPC775BALTIC"}, + + {852, "852"}, + {852, "CP852"}, + {852, "IBM852"}, + {852, "CSPCP852"}, + + /* !IsValidCodePage(853) */ + {853, "CP853"}, + + {855, "855"}, + {855, "CP855"}, + {855, "IBM855"}, + {855, "CSIBM855"}, + + {857, "857"}, + {857, "CP857"}, + {857, "IBM857"}, + {857, "CSIBM857"}, + + /* !IsValidCodePage(858) */ + {858, "CP858"}, + + {860, "860"}, + {860, "CP860"}, + {860, "IBM860"}, + {860, "CSIBM860"}, + + {861, "861"}, + {861, "CP-IS"}, + {861, "CP861"}, + {861, "IBM861"}, + {861, "CSIBM861"}, + + {863, "863"}, + {863, "CP863"}, + {863, "IBM863"}, + {863, "CSIBM863"}, + + {864, "CP864"}, + {864, "IBM864"}, + {864, "CSIBM864"}, + + {865, "865"}, + {865, "CP865"}, + {865, "IBM865"}, + {865, "CSIBM865"}, + + {869, "869"}, + {869, "CP-GR"}, + {869, "CP869"}, + {869, "IBM869"}, + {869, "CSIBM869"}, + + /* !IsValidCodePage(1152) */ + {1125, "CP1125"}, + + /* + * Code Page Identifiers + * http://msdn2.microsoft.com/en-us/library/ms776446.aspx + */ + {37, "IBM037"}, /* IBM EBCDIC US-Canada */ + {437, "IBM437"}, /* OEM United States */ + {500, "IBM500"}, /* IBM EBCDIC International */ + {708, "ASMO-708"}, /* Arabic (ASMO 708) */ + /* 709 Arabic (ASMO-449+, BCON V4) */ + /* 710 Arabic - Transparent Arabic */ + {720, "DOS-720"}, /* Arabic (Transparent ASMO); Arabic (DOS) */ + {737, "ibm737"}, /* OEM Greek (formerly 437G); Greek (DOS) */ + {775, "ibm775"}, /* OEM Baltic; Baltic (DOS) */ + {850, "ibm850"}, /* OEM Multilingual Latin 1; Western European (DOS) */ + {852, "ibm852"}, /* OEM Latin 2; Central European (DOS) */ + {855, "IBM855"}, /* OEM Cyrillic (primarily Russian) */ + {857, "ibm857"}, /* OEM Turkish; Turkish (DOS) */ + {858, "IBM00858"}, /* OEM Multilingual Latin 1 + Euro symbol */ + {860, "IBM860"}, /* OEM Portuguese; Portuguese (DOS) */ + {861, "ibm861"}, /* OEM Icelandic; Icelandic (DOS) */ + {862, "DOS-862"}, /* OEM Hebrew; Hebrew (DOS) */ + {863, "IBM863"}, /* OEM French Canadian; French Canadian (DOS) */ + {864, "IBM864"}, /* OEM Arabic; Arabic (864) */ + {865, "IBM865"}, /* OEM Nordic; Nordic (DOS) */ + {866, "cp866"}, /* OEM Russian; Cyrillic (DOS) */ + {869, "ibm869"}, /* OEM Modern Greek; Greek, Modern (DOS) */ + {870, "IBM870"}, /* IBM EBCDIC Multilingual/ROECE (Latin 2); IBM EBCDIC Multilingual Latin 2 */ + {874, "windows-874"}, /* ANSI/OEM Thai (same as 28605, ISO 8859-15); Thai (Windows) */ + {875, "cp875"}, /* IBM EBCDIC Greek Modern */ + {932, "shift_jis"}, /* ANSI/OEM Japanese; Japanese (Shift-JIS) */ + {932, "shift-jis"}, /* alternative name for it */ + {936, "gb2312"}, /* ANSI/OEM Simplified Chinese (PRC, Singapore); Chinese Simplified (GB2312) */ + {949, "ks_c_5601-1987"}, /* ANSI/OEM Korean (Unified Hangul Code) */ + {950, "big5"}, /* ANSI/OEM Traditional Chinese (Taiwan; Hong Kong SAR, PRC); Chinese Traditional (Big5) */ + {1026, "IBM1026"}, /* IBM EBCDIC Turkish (Latin 5) */ + {1047, "IBM01047"}, /* IBM EBCDIC Latin 1/Open System */ + {1140, "IBM01140"}, /* IBM EBCDIC US-Canada (037 + Euro symbol); IBM EBCDIC (US-Canada-Euro) */ + {1141, "IBM01141"}, /* IBM EBCDIC Germany (20273 + Euro symbol); IBM EBCDIC (Germany-Euro) */ + {1142, "IBM01142"}, /* IBM EBCDIC Denmark-Norway (20277 + Euro symbol); IBM EBCDIC (Denmark-Norway-Euro) */ + {1143, "IBM01143"}, /* IBM EBCDIC Finland-Sweden (20278 + Euro symbol); IBM EBCDIC (Finland-Sweden-Euro) */ + {1144, "IBM01144"}, /* IBM EBCDIC Italy (20280 + Euro symbol); IBM EBCDIC (Italy-Euro) */ + {1145, "IBM01145"}, /* IBM EBCDIC Latin America-Spain (20284 + Euro symbol); IBM EBCDIC (Spain-Euro) */ + {1146, "IBM01146"}, /* IBM EBCDIC United Kingdom (20285 + Euro symbol); IBM EBCDIC (UK-Euro) */ + {1147, "IBM01147"}, /* IBM EBCDIC France (20297 + Euro symbol); IBM EBCDIC (France-Euro) */ + {1148, "IBM01148"}, /* IBM EBCDIC International (500 + Euro symbol); IBM EBCDIC (International-Euro) */ + {1149, "IBM01149"}, /* IBM EBCDIC Icelandic (20871 + Euro symbol); IBM EBCDIC (Icelandic-Euro) */ + {1250, "windows-1250"}, /* ANSI Central European; Central European (Windows) */ + {1251, "windows-1251"}, /* ANSI Cyrillic; Cyrillic (Windows) */ + {1252, "windows-1252"}, /* ANSI Latin 1; Western European (Windows) */ + {1253, "windows-1253"}, /* ANSI Greek; Greek (Windows) */ + {1254, "windows-1254"}, /* ANSI Turkish; Turkish (Windows) */ + {1255, "windows-1255"}, /* ANSI Hebrew; Hebrew (Windows) */ + {1256, "windows-1256"}, /* ANSI Arabic; Arabic (Windows) */ + {1257, "windows-1257"}, /* ANSI Baltic; Baltic (Windows) */ + {1258, "windows-1258"}, /* ANSI/OEM Vietnamese; Vietnamese (Windows) */ + {1361, "Johab"}, /* Korean (Johab) */ + {10000, "macintosh"}, /* MAC Roman; Western European (Mac) */ + {10001, "x-mac-japanese"}, /* Japanese (Mac) */ + {10002, "x-mac-chinesetrad"}, /* MAC Traditional Chinese (Big5); Chinese Traditional (Mac) */ + {10003, "x-mac-korean"}, /* Korean (Mac) */ + {10004, "x-mac-arabic"}, /* Arabic (Mac) */ + {10005, "x-mac-hebrew"}, /* Hebrew (Mac) */ + {10006, "x-mac-greek"}, /* Greek (Mac) */ + {10007, "x-mac-cyrillic"}, /* Cyrillic (Mac) */ + {10008, "x-mac-chinesesimp"}, /* MAC Simplified Chinese (GB 2312); Chinese Simplified (Mac) */ + {10010, "x-mac-romanian"}, /* Romanian (Mac) */ + {10017, "x-mac-ukrainian"}, /* Ukrainian (Mac) */ + {10021, "x-mac-thai"}, /* Thai (Mac) */ + {10029, "x-mac-ce"}, /* MAC Latin 2; Central European (Mac) */ + {10079, "x-mac-icelandic"}, /* Icelandic (Mac) */ + {10081, "x-mac-turkish"}, /* Turkish (Mac) */ + {10082, "x-mac-croatian"}, /* Croatian (Mac) */ + {20000, "x-Chinese_CNS"}, /* CNS Taiwan; Chinese Traditional (CNS) */ + {20001, "x-cp20001"}, /* TCA Taiwan */ + {20002, "x_Chinese-Eten"}, /* Eten Taiwan; Chinese Traditional (Eten) */ + {20003, "x-cp20003"}, /* IBM5550 Taiwan */ + {20004, "x-cp20004"}, /* TeleText Taiwan */ + {20005, "x-cp20005"}, /* Wang Taiwan */ + {20105, "x-IA5"}, /* IA5 (IRV International Alphabet No. 5, 7-bit); Western European (IA5) */ + {20106, "x-IA5-German"}, /* IA5 German (7-bit) */ + {20107, "x-IA5-Swedish"}, /* IA5 Swedish (7-bit) */ + {20108, "x-IA5-Norwegian"}, /* IA5 Norwegian (7-bit) */ + {20127, "us-ascii"}, /* US-ASCII (7-bit) */ + {20261, "x-cp20261"}, /* T.61 */ + {20269, "x-cp20269"}, /* ISO 6937 Non-Spacing Accent */ + {20273, "IBM273"}, /* IBM EBCDIC Germany */ + {20277, "IBM277"}, /* IBM EBCDIC Denmark-Norway */ + {20278, "IBM278"}, /* IBM EBCDIC Finland-Sweden */ + {20280, "IBM280"}, /* IBM EBCDIC Italy */ + {20284, "IBM284"}, /* IBM EBCDIC Latin America-Spain */ + {20285, "IBM285"}, /* IBM EBCDIC United Kingdom */ + {20290, "IBM290"}, /* IBM EBCDIC Japanese Katakana Extended */ + {20297, "IBM297"}, /* IBM EBCDIC France */ + {20420, "IBM420"}, /* IBM EBCDIC Arabic */ + {20423, "IBM423"}, /* IBM EBCDIC Greek */ + {20424, "IBM424"}, /* IBM EBCDIC Hebrew */ + {20833, "x-EBCDIC-KoreanExtended"}, /* IBM EBCDIC Korean Extended */ + {20838, "IBM-Thai"}, /* IBM EBCDIC Thai */ + {20866, "koi8-r"}, /* Russian (KOI8-R); Cyrillic (KOI8-R) */ + {20871, "IBM871"}, /* IBM EBCDIC Icelandic */ + {20880, "IBM880"}, /* IBM EBCDIC Cyrillic Russian */ + {20905, "IBM905"}, /* IBM EBCDIC Turkish */ + {20924, "IBM00924"}, /* IBM EBCDIC Latin 1/Open System (1047 + Euro symbol) */ + {20932, "EUC-JP"}, /* Japanese (JIS 0208-1990 and 0121-1990) */ + {20936, "x-cp20936"}, /* Simplified Chinese (GB2312); Chinese Simplified (GB2312-80) */ + {20949, "x-cp20949"}, /* Korean Wansung */ + {21025, "cp1025"}, /* IBM EBCDIC Cyrillic Serbian-Bulgarian */ + /* 21027 (deprecated) */ + {21866, "koi8-u"}, /* Ukrainian (KOI8-U); Cyrillic (KOI8-U) */ + {28591, "iso-8859-1"}, /* ISO 8859-1 Latin 1; Western European (ISO) */ + {28591, "iso8859-1"}, /* ISO 8859-1 Latin 1; Western European (ISO) */ + {28592, "iso-8859-2"}, /* ISO 8859-2 Central European; Central European (ISO) */ + {28592, "iso8859-2"}, /* ISO 8859-2 Central European; Central European (ISO) */ + {28593, "iso-8859-3"}, /* ISO 8859-3 Latin 3 */ + {28593, "iso8859-3"}, /* ISO 8859-3 Latin 3 */ + {28594, "iso-8859-4"}, /* ISO 8859-4 Baltic */ + {28594, "iso8859-4"}, /* ISO 8859-4 Baltic */ + {28595, "iso-8859-5"}, /* ISO 8859-5 Cyrillic */ + {28595, "iso8859-5"}, /* ISO 8859-5 Cyrillic */ + {28596, "iso-8859-6"}, /* ISO 8859-6 Arabic */ + {28596, "iso8859-6"}, /* ISO 8859-6 Arabic */ + {28597, "iso-8859-7"}, /* ISO 8859-7 Greek */ + {28597, "iso8859-7"}, /* ISO 8859-7 Greek */ + {28598, "iso-8859-8"}, /* ISO 8859-8 Hebrew; Hebrew (ISO-Visual) */ + {28598, "iso8859-8"}, /* ISO 8859-8 Hebrew; Hebrew (ISO-Visual) */ + {28599, "iso-8859-9"}, /* ISO 8859-9 Turkish */ + {28599, "iso8859-9"}, /* ISO 8859-9 Turkish */ + {28603, "iso-8859-13"}, /* ISO 8859-13 Estonian */ + {28603, "iso8859-13"}, /* ISO 8859-13 Estonian */ + {28605, "iso-8859-15"}, /* ISO 8859-15 Latin 9 */ + {28605, "iso8859-15"}, /* ISO 8859-15 Latin 9 */ + {29001, "x-Europa"}, /* Europa 3 */ + {38598, "iso-8859-8-i"}, /* ISO 8859-8 Hebrew; Hebrew (ISO-Logical) */ + {38598, "iso8859-8-i"}, /* ISO 8859-8 Hebrew; Hebrew (ISO-Logical) */ + {50220, "iso-2022-jp"}, /* ISO 2022 Japanese with no halfwidth Katakana; Japanese (JIS) */ + {50221, "csISO2022JP"}, /* ISO 2022 Japanese with halfwidth Katakana; Japanese (JIS-Allow 1 byte Kana) */ + {50222, "iso-2022-jp"}, /* ISO 2022 Japanese JIS X 0201-1989; Japanese (JIS-Allow 1 byte Kana - SO/SI) */ + {50225, "iso-2022-kr"}, /* ISO 2022 Korean */ + {50225, "iso2022-kr"}, /* ISO 2022 Korean */ + {50227, "x-cp50227"}, /* ISO 2022 Simplified Chinese; Chinese Simplified (ISO 2022) */ + /* 50229 ISO 2022 Traditional Chinese */ + /* 50930 EBCDIC Japanese (Katakana) Extended */ + /* 50931 EBCDIC US-Canada and Japanese */ + /* 50933 EBCDIC Korean Extended and Korean */ + /* 50935 EBCDIC Simplified Chinese Extended and Simplified Chinese */ + /* 50936 EBCDIC Simplified Chinese */ + /* 50937 EBCDIC US-Canada and Traditional Chinese */ + /* 50939 EBCDIC Japanese (Latin) Extended and Japanese */ + {51932, "euc-jp"}, /* EUC Japanese */ + {51936, "EUC-CN"}, /* EUC Simplified Chinese; Chinese Simplified (EUC) */ + {51949, "euc-kr"}, /* EUC Korean */ + /* 51950 EUC Traditional Chinese */ + {52936, "hz-gb-2312"}, /* HZ-GB2312 Simplified Chinese; Chinese Simplified (HZ) */ + {54936, "GB18030"}, /* Windows XP and later: GB18030 Simplified Chinese (4 byte); Chinese Simplified (GB18030) */ + {57002, "x-iscii-de"}, /* ISCII Devanagari */ + {57003, "x-iscii-be"}, /* ISCII Bengali */ + {57004, "x-iscii-ta"}, /* ISCII Tamil */ + {57005, "x-iscii-te"}, /* ISCII Telugu */ + {57006, "x-iscii-as"}, /* ISCII Assamese */ + {57007, "x-iscii-or"}, /* ISCII Oriya */ + {57008, "x-iscii-ka"}, /* ISCII Kannada */ + {57009, "x-iscii-ma"}, /* ISCII Malayalam */ + {57010, "x-iscii-gu"}, /* ISCII Gujarati */ + {57011, "x-iscii-pa"}, /* ISCII Punjabi */ + + {0, NULL} +}; + +/* + * SJIS SHIFTJIS table CP932 table + * ---- --------------------------- -------------------------------- + * 5C U+00A5 YEN SIGN U+005C REVERSE SOLIDUS + * 7E U+203E OVERLINE U+007E TILDE + * 815C U+2014 EM DASH U+2015 HORIZONTAL BAR + * 815F U+005C REVERSE SOLIDUS U+FF3C FULLWIDTH REVERSE SOLIDUS + * 8160 U+301C WAVE DASH U+FF5E FULLWIDTH TILDE + * 8161 U+2016 DOUBLE VERTICAL LINE U+2225 PARALLEL TO + * 817C U+2212 MINUS SIGN U+FF0D FULLWIDTH HYPHEN-MINUS + * 8191 U+00A2 CENT SIGN U+FFE0 FULLWIDTH CENT SIGN + * 8192 U+00A3 POUND SIGN U+FFE1 FULLWIDTH POUND SIGN + * 81CA U+00AC NOT SIGN U+FFE2 FULLWIDTH NOT SIGN + * + * EUC-JP and ISO-2022-JP should be compatible with CP932. + * + * Kernel and MLang have different Unicode mapping table. Make sure + * which API is used. + */ +static compat_t cp932_compat[] = { + {0x00A5, 0x005C, COMPAT_OUT}, + {0x203E, 0x007E, COMPAT_OUT}, + {0x2014, 0x2015, COMPAT_OUT}, + {0x301C, 0xFF5E, COMPAT_OUT}, + {0x2016, 0x2225, COMPAT_OUT}, + {0x2212, 0xFF0D, COMPAT_OUT}, + {0x00A2, 0xFFE0, COMPAT_OUT}, + {0x00A3, 0xFFE1, COMPAT_OUT}, + {0x00AC, 0xFFE2, COMPAT_OUT}, + {0, 0, 0} +}; + +static compat_t cp20932_compat[] = { + {0x00A5, 0x005C, COMPAT_OUT}, + {0x203E, 0x007E, COMPAT_OUT}, + {0x2014, 0x2015, COMPAT_OUT}, + {0xFF5E, 0x301C, COMPAT_OUT|COMPAT_IN}, + {0x2225, 0x2016, COMPAT_OUT|COMPAT_IN}, + {0xFF0D, 0x2212, COMPAT_OUT|COMPAT_IN}, + {0xFFE0, 0x00A2, COMPAT_OUT|COMPAT_IN}, + {0xFFE1, 0x00A3, COMPAT_OUT|COMPAT_IN}, + {0xFFE2, 0x00AC, COMPAT_OUT|COMPAT_IN}, + {0, 0, 0} +}; + +static compat_t *cp51932_compat = cp932_compat; + +/* cp20932_compat for kernel. cp932_compat for mlang. */ +static compat_t *cp5022x_compat = cp932_compat; + +typedef HRESULT (WINAPI *CONVERTINETSTRING)( + LPDWORD lpdwMode, + DWORD dwSrcEncoding, + DWORD dwDstEncoding, + LPCSTR lpSrcStr, + LPINT lpnSrcSize, + LPBYTE lpDstStr, + LPINT lpnDstSize +); +typedef HRESULT (WINAPI *CONVERTINETMULTIBYTETOUNICODE)( + LPDWORD lpdwMode, + DWORD dwSrcEncoding, + LPCSTR lpSrcStr, + LPINT lpnMultiCharCount, + LPWSTR lpDstStr, + LPINT lpnWideCharCount +); +typedef HRESULT (WINAPI *CONVERTINETUNICODETOMULTIBYTE)( + LPDWORD lpdwMode, + DWORD dwEncoding, + LPCWSTR lpSrcStr, + LPINT lpnWideCharCount, + LPSTR lpDstStr, + LPINT lpnMultiCharCount +); +typedef HRESULT (WINAPI *ISCONVERTINETSTRINGAVAILABLE)( + DWORD dwSrcEncoding, + DWORD dwDstEncoding +); +typedef HRESULT (WINAPI *LCIDTORFC1766A)( + LCID Locale, + LPSTR pszRfc1766, + int nChar +); +typedef HRESULT (WINAPI *LCIDTORFC1766W)( + LCID Locale, + LPWSTR pszRfc1766, + int nChar +); +typedef HRESULT (WINAPI *RFC1766TOLCIDA)( + LCID *pLocale, + LPSTR pszRfc1766 +); +typedef HRESULT (WINAPI *RFC1766TOLCIDW)( + LCID *pLocale, + LPWSTR pszRfc1766 +); +static CONVERTINETSTRING ConvertINetString; +static CONVERTINETMULTIBYTETOUNICODE ConvertINetMultiByteToUnicode; +static CONVERTINETUNICODETOMULTIBYTE ConvertINetUnicodeToMultiByte; +static ISCONVERTINETSTRINGAVAILABLE IsConvertINetStringAvailable; +static LCIDTORFC1766A LcidToRfc1766A; +static RFC1766TOLCIDA Rfc1766ToLcidA; + +static int +load_mlang() +{ + HMODULE h; + if (ConvertINetString != NULL) + return TRUE; + h = LoadLibrary(TEXT("mlang.dll")); + if (!h) + return FALSE; + ConvertINetString = (CONVERTINETSTRING)GetProcAddress(h, "ConvertINetString"); + ConvertINetMultiByteToUnicode = (CONVERTINETMULTIBYTETOUNICODE)GetProcAddress(h, "ConvertINetMultiByteToUnicode"); + ConvertINetUnicodeToMultiByte = (CONVERTINETUNICODETOMULTIBYTE)GetProcAddress(h, "ConvertINetUnicodeToMultiByte"); + IsConvertINetStringAvailable = (ISCONVERTINETSTRINGAVAILABLE)GetProcAddress(h, "IsConvertINetStringAvailable"); + LcidToRfc1766A = (LCIDTORFC1766A)GetProcAddress(h, "LcidToRfc1766A"); + Rfc1766ToLcidA = (RFC1766TOLCIDA)GetProcAddress(h, "Rfc1766ToLcidA"); + return TRUE; +} + +iconv_t +iconv_open(const char *tocode, const char *fromcode) +{ + rec_iconv_t *cd; + + cd = (rec_iconv_t *)calloc(1, sizeof(rec_iconv_t)); + if (cd == NULL) + return (iconv_t)(-1); + +#if defined(USE_LIBICONV_DLL) + errno = 0; + if (libiconv_iconv_open(cd, tocode, fromcode)) + return (iconv_t)cd; +#endif + + /* reset the errno to prevent reporting wrong error code. + * 0 for unsorted error. */ + errno = 0; + if (win_iconv_open(cd, tocode, fromcode)) + return (iconv_t)cd; + + free(cd); + + return (iconv_t)(-1); +} + +int +iconv_close(iconv_t _cd) +{ + rec_iconv_t *cd = (rec_iconv_t *)_cd; + int r = cd->iconv_close(cd->cd); + int e = *(cd->_errno()); +#if defined(USE_LIBICONV_DLL) + if (cd->hlibiconv != NULL) + FreeLibrary(cd->hlibiconv); +#endif + free(cd); + errno = e; + return r; +} + +size_t +iconv(iconv_t _cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft) +{ + rec_iconv_t *cd = (rec_iconv_t *)_cd; + size_t r = cd->iconv(cd->cd, inbuf, inbytesleft, outbuf, outbytesleft); + errno = *(cd->_errno()); + return r; +} + +static int +win_iconv_open(rec_iconv_t *cd, const char *tocode, const char *fromcode) +{ + if (!make_csconv(fromcode, &cd->from) || !make_csconv(tocode, &cd->to)) + return FALSE; + cd->iconv_close = win_iconv_close; + cd->iconv = win_iconv; + cd->_errno = _errno; + cd->cd = (iconv_t)cd; + return TRUE; +} + +static int +win_iconv_close(iconv_t cd) +{ + return 0; +} + +static size_t +win_iconv(iconv_t _cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft) +{ + rec_iconv_t *cd = (rec_iconv_t *)_cd; + ushort wbuf[MB_CHAR_MAX]; /* enough room for one character */ + int insize; + int outsize; + int wsize; + DWORD frommode; + DWORD tomode; + uint wc; + compat_t *cp; + int i; + + if (inbuf == NULL || *inbuf == NULL) + { + if (outbuf != NULL && *outbuf != NULL && cd->to.flush != NULL) + { + tomode = cd->to.mode; + outsize = cd->to.flush(&cd->to, (uchar *)*outbuf, *outbytesleft); + if (outsize == -1) + { + cd->to.mode = tomode; + return (size_t)(-1); + } + *outbuf += outsize; + *outbytesleft -= outsize; + } + cd->from.mode = 0; + cd->to.mode = 0; + return 0; + } + + while (*inbytesleft != 0) + { + frommode = cd->from.mode; + tomode = cd->to.mode; + wsize = MB_CHAR_MAX; + + insize = cd->from.mbtowc(&cd->from, (const uchar *)*inbuf, *inbytesleft, wbuf, &wsize); + if (insize == -1) + { + cd->from.mode = frommode; + return (size_t)(-1); + } + + if (wsize == 0) + { + *inbuf += insize; + *inbytesleft -= insize; + continue; + } + + if (cd->from.compat != NULL) + { + wc = utf16_to_ucs4(wbuf); + cp = cd->from.compat; + for (i = 0; cp[i].in != 0; ++i) + { + if ((cp[i].flag & COMPAT_IN) && cp[i].out == wc) + { + ucs4_to_utf16(cp[i].in, wbuf, &wsize); + break; + } + } + } + + if (cd->to.compat != NULL) + { + wc = utf16_to_ucs4(wbuf); + cp = cd->to.compat; + for (i = 0; cp[i].in != 0; ++i) + { + if ((cp[i].flag & COMPAT_OUT) && cp[i].in == wc) + { + ucs4_to_utf16(cp[i].out, wbuf, &wsize); + break; + } + } + } + + outsize = cd->to.wctomb(&cd->to, wbuf, wsize, (uchar *)*outbuf, *outbytesleft); + if (outsize == -1) + { + cd->from.mode = frommode; + cd->to.mode = tomode; + return (size_t)(-1); + } + + *inbuf += insize; + *outbuf += outsize; + *inbytesleft -= insize; + *outbytesleft -= outsize; + } + + return 0; +} + +static int +make_csconv(const char *_name, csconv_t *cv) +{ + CPINFO cpinfo; + int use_compat = TRUE; + int flag = 0; + char *name; + char *p; + + name = xstrndup(_name, strlen(_name)); + if (name == NULL) + return FALSE; + + /* check for option "enc_name//opt1//opt2" */ + while ((p = strrstr(name, "//")) != NULL) + { + if (_stricmp(p + 2, "nocompat") == 0) + use_compat = FALSE; + else if (_stricmp(p + 2, "translit") == 0) + flag |= FLAG_TRANSLIT; + else if (_stricmp(p + 2, "ignore") == 0) + flag |= FLAG_IGNORE; + *p = 0; + } + + cv->mode = 0; + cv->flags = flag; + cv->mblen = NULL; + cv->flush = NULL; + cv->compat = NULL; + cv->codepage = name_to_codepage(name); + if (cv->codepage == 1200 || cv->codepage == 1201) + { + cv->mbtowc = utf16_mbtowc; + cv->wctomb = utf16_wctomb; + if (_stricmp(name, "UTF-16") == 0 || _stricmp(name, "UTF16") == 0 + || _stricmp(name, "UCS-2") == 0 || _stricmp(name, "UCS2") == 0) + + cv->flags |= FLAG_USE_BOM; + } + else if (cv->codepage == 12000 || cv->codepage == 12001) + { + cv->mbtowc = utf32_mbtowc; + cv->wctomb = utf32_wctomb; + if (_stricmp(name, "UTF-32") == 0 || _stricmp(name, "UTF32") == 0 + || _stricmp(name, "UCS-4") == 0 || _stricmp(name, "UCS4") == 0) + cv->flags |= FLAG_USE_BOM; + } + else if (cv->codepage == 65001) + { + cv->mbtowc = kernel_mbtowc; + cv->wctomb = kernel_wctomb; + cv->mblen = utf8_mblen; + } + else if ((cv->codepage == 50220 || cv->codepage == 50221 || cv->codepage == 50222) && load_mlang()) + { + cv->mbtowc = iso2022jp_mbtowc; + cv->wctomb = iso2022jp_wctomb; + cv->flush = iso2022jp_flush; + } + else if (cv->codepage == 51932 && load_mlang()) + { + cv->mbtowc = mlang_mbtowc; + cv->wctomb = mlang_wctomb; + cv->mblen = eucjp_mblen; + } + else if (IsValidCodePage(cv->codepage) + && GetCPInfo(cv->codepage, &cpinfo) != 0) + { + cv->mbtowc = kernel_mbtowc; + cv->wctomb = kernel_wctomb; + if (cpinfo.MaxCharSize == 1) + cv->mblen = sbcs_mblen; + else if (cpinfo.MaxCharSize == 2) + cv->mblen = dbcs_mblen; + else + cv->mblen = mbcs_mblen; + } + else + { + /* not supported */ + free(name); + errno = EINVAL; + return FALSE; + } + + if (use_compat) + { + switch (cv->codepage) + { + case 932: cv->compat = cp932_compat; break; + case 20932: cv->compat = cp20932_compat; break; + case 51932: cv->compat = cp51932_compat; break; + case 50220: case 50221: case 50222: cv->compat = cp5022x_compat; break; + } + } + + free(name); + + return TRUE; +} + +static int +name_to_codepage(const char *name) +{ + int i; + + if (*name == '\0' || + strcmp(name, "char") == 0) + return GetACP(); + else if (strcmp(name, "wchar_t") == 0) + return 1200; + else if (_strnicmp(name, "cp", 2) == 0) + return atoi(name + 2); /* CP123 */ + else if ('0' <= name[0] && name[0] <= '9') + return atoi(name); /* 123 */ + else if (_strnicmp(name, "xx", 2) == 0) + return atoi(name + 2); /* XX123 for debug */ + + for (i = 0; codepage_alias[i].name != NULL; ++i) + if (_stricmp(name, codepage_alias[i].name) == 0) + return codepage_alias[i].codepage; + return -1; +} + +/* + * http://www.faqs.org/rfcs/rfc2781.html + */ +static uint +utf16_to_ucs4(const ushort *wbuf) +{ + uint wc = wbuf[0]; + if (0xD800 <= wbuf[0] && wbuf[0] <= 0xDBFF) + wc = ((wbuf[0] & 0x3FF) << 10) + (wbuf[1] & 0x3FF) + 0x10000; + return wc; +} + +static void +ucs4_to_utf16(uint wc, ushort *wbuf, int *wbufsize) +{ + if (wc < 0x10000) + { + wbuf[0] = wc; + *wbufsize = 1; + } + else + { + wc -= 0x10000; + wbuf[0] = 0xD800 | ((wc >> 10) & 0x3FF); + wbuf[1] = 0xDC00 | (wc & 0x3FF); + *wbufsize = 2; + } +} + +/* + * Check if codepage is one of those for which the dwFlags parameter + * to MultiByteToWideChar() must be zero. Return zero or + * MB_ERR_INVALID_CHARS. The docs in Platform SDK for for Windows + * Server 2003 R2 claims that also codepage 65001 is one of these, but + * that doesn't seem to be the case. The MSDN docs for MSVS2008 leave + * out 65001 (UTF-8), and that indeed seems to be the case on XP, it + * works fine to pass MB_ERR_INVALID_CHARS in dwFlags when converting + * from UTF-8. + */ +static int +mbtowc_flags(int codepage) +{ + return (codepage == 50220 || codepage == 50221 || + codepage == 50222 || codepage == 50225 || + codepage == 50227 || codepage == 50229 || + codepage == 52936 || codepage == 54936 || + (codepage >= 57002 && codepage <= 57011) || + codepage == 65000 || codepage == 42) ? 0 : MB_ERR_INVALID_CHARS; +} + +/* + * Check if codepage is one those for which the lpUsedDefaultChar + * parameter to WideCharToMultiByte() must be NULL. The docs in + * Platform SDK for for Windows Server 2003 R2 claims that this is the + * list below, while the MSDN docs for MSVS2008 claim that it is only + * for 65000 (UTF-7) and 65001 (UTF-8). This time the earlier Platform + * SDK seems to be correct, at least for XP. + */ +static int +must_use_null_useddefaultchar(int codepage) +{ + return (codepage == 65000 || codepage == 65001 || + codepage == 50220 || codepage == 50221 || + codepage == 50222 || codepage == 50225 || + codepage == 50227 || codepage == 50229 || + codepage == 52936 || codepage == 54936 || + (codepage >= 57002 && codepage <= 57011) || + codepage == 42); +} + +static char * +strrstr(const char *str, const char *token) +{ + int len = strlen(token); + const char *p = str + strlen(str); + + while (str <= --p) + if (p[0] == token[0] && strncmp(p, token, len) == 0) + return (char *)p; + return NULL; +} + +static char * +xstrndup(const char *s, size_t n) +{ + char *p; + + p = malloc(n + 1); + if (p == NULL) + return NULL; + memcpy(p, s, n); + p[n] = '\0'; + return p; +} + +static int +seterror(int err) +{ + errno = err; + return -1; +} + +#if defined(USE_LIBICONV_DLL) +static int +libiconv_iconv_open(rec_iconv_t *cd, const char *tocode, const char *fromcode) +{ + HMODULE hlibiconv = NULL; + HMODULE hmsvcrt = NULL; + char *dllname; + const char *p; + const char *e; + f_iconv_open _iconv_open; + + /* + * always try to load dll, so that we can switch dll in runtime. + */ + + /* XXX: getenv() can't get variable set by SetEnvironmentVariable() */ + p = getenv("WINICONV_LIBICONV_DLL"); + if (p == NULL) + p = DEFAULT_LIBICONV_DLL; + /* parse comma separated value */ + for ( ; *p != 0; p = (*e == ',') ? e + 1 : e) + { + e = strchr(p, ','); + if (p == e) + continue; + else if (e == NULL) + e = p + strlen(p); + dllname = xstrndup(p, e - p); + if (dllname == NULL) + return FALSE; + hlibiconv = LoadLibraryA(dllname); + free(dllname); + if (hlibiconv != NULL) + { + if (hlibiconv == hwiniconv) + { + FreeLibrary(hlibiconv); + hlibiconv = NULL; + continue; + } + break; + } + } + + if (hlibiconv == NULL) + goto failed; + + hmsvcrt = find_imported_module_by_funcname(hlibiconv, "_errno"); + if (hmsvcrt == NULL) + goto failed; + + _iconv_open = (f_iconv_open)GetProcAddress(hlibiconv, "libiconv_open"); + if (_iconv_open == NULL) + _iconv_open = (f_iconv_open)GetProcAddress(hlibiconv, "iconv_open"); + cd->iconv_close = (f_iconv_close)GetProcAddress(hlibiconv, "libiconv_close"); + if (cd->iconv_close == NULL) + cd->iconv_close = (f_iconv_close)GetProcAddress(hlibiconv, "iconv_close"); + cd->iconv = (f_iconv)GetProcAddress(hlibiconv, "libiconv"); + if (cd->iconv == NULL) + cd->iconv = (f_iconv)GetProcAddress(hlibiconv, "iconv"); + cd->_errno = (f_errno)GetProcAddress(hmsvcrt, "_errno"); + if (_iconv_open == NULL || cd->iconv_close == NULL + || cd->iconv == NULL || cd->_errno == NULL) + goto failed; + + cd->cd = _iconv_open(tocode, fromcode); + if (cd->cd == (iconv_t)(-1)) + goto failed; + + cd->hlibiconv = hlibiconv; + return TRUE; + +failed: + if (hlibiconv != NULL) + FreeLibrary(hlibiconv); + /* do not free hmsvcrt which is obtained by GetModuleHandle() */ + return FALSE; +} + +/* + * Reference: + * http://forums.belution.com/ja/vc/000/234/78s.shtml + * http://nienie.com/~masapico/api_ImageDirectoryEntryToData.html + * + * The formal way is + * imagehlp.h or dbghelp.h + * imagehlp.lib or dbghelp.lib + * ImageDirectoryEntryToData() + */ +#define TO_DOS_HEADER(base) ((PIMAGE_DOS_HEADER)(base)) +#define TO_NT_HEADERS(base) ((PIMAGE_NT_HEADERS)((LPBYTE)(base) + TO_DOS_HEADER(base)->e_lfanew)) +static PVOID +MyImageDirectoryEntryToData(LPVOID Base, BOOLEAN MappedAsImage, USHORT DirectoryEntry, PULONG Size) +{ + /* TODO: MappedAsImage? */ + PIMAGE_DATA_DIRECTORY p; + p = TO_NT_HEADERS(Base)->OptionalHeader.DataDirectory + DirectoryEntry; + if (p->VirtualAddress == 0) { + *Size = 0; + return NULL; + } + *Size = p->Size; + return (PVOID)((LPBYTE)Base + p->VirtualAddress); +} + +static HMODULE +find_imported_module_by_funcname(HMODULE hModule, const char *funcname) +{ + DWORD_PTR Base; + ULONG Size; + PIMAGE_IMPORT_DESCRIPTOR Imp; + PIMAGE_THUNK_DATA Name; /* Import Name Table */ + PIMAGE_IMPORT_BY_NAME ImpName; + + Base = (DWORD_PTR)hModule; + Imp = MyImageDirectoryEntryToData( + (LPVOID)Base, + TRUE, + IMAGE_DIRECTORY_ENTRY_IMPORT, + &Size); + if (Imp == NULL) + return NULL; + for ( ; Imp->OriginalFirstThunk != 0; ++Imp) + { + Name = (PIMAGE_THUNK_DATA)(Base + Imp->OriginalFirstThunk); + for ( ; Name->u1.Ordinal != 0; ++Name) + { + if (!IMAGE_SNAP_BY_ORDINAL(Name->u1.Ordinal)) + { + ImpName = (PIMAGE_IMPORT_BY_NAME) + (Base + (DWORD_PTR)Name->u1.AddressOfData); + if (strcmp((char *)ImpName->Name, funcname) == 0) + return GetModuleHandleA((char *)(Base + Imp->Name)); + } + } + } + return NULL; +} +#endif + +static int +sbcs_mblen(csconv_t *cv, const uchar *buf, int bufsize) +{ + return 1; +} + +static int +dbcs_mblen(csconv_t *cv, const uchar *buf, int bufsize) +{ + int len = IsDBCSLeadByteEx(cv->codepage, buf[0]) ? 2 : 1; + if (bufsize < len) + return seterror(EINVAL); + return len; +} + +static int +mbcs_mblen(csconv_t *cv, const uchar *buf, int bufsize) +{ + int len = 0; + + if (cv->codepage == 54936) { + if (buf[0] <= 0x7F) len = 1; + else if (buf[0] >= 0x81 && buf[0] <= 0xFE && + bufsize >= 2 && + ((buf[1] >= 0x40 && buf[1] <= 0x7E) || + (buf[1] >= 0x80 && buf[1] <= 0xFE))) len = 2; + else if (buf[0] >= 0x81 && buf[0] <= 0xFE && + bufsize >= 4 && + buf[1] >= 0x30 && buf[1] <= 0x39) len = 4; + else + return seterror(EINVAL); + return len; + } + else + return seterror(EINVAL); +} + +static int +utf8_mblen(csconv_t *cv, const uchar *buf, int bufsize) +{ + int len = 0; + + if (buf[0] < 0x80) len = 1; + else if ((buf[0] & 0xE0) == 0xC0) len = 2; + else if ((buf[0] & 0xF0) == 0xE0) len = 3; + else if ((buf[0] & 0xF8) == 0xF0) len = 4; + else if ((buf[0] & 0xFC) == 0xF8) len = 5; + else if ((buf[0] & 0xFE) == 0xFC) len = 6; + + if (len == 0) + return seterror(EILSEQ); + else if (bufsize < len) + return seterror(EINVAL); + return len; +} + +static int +eucjp_mblen(csconv_t *cv, const uchar *buf, int bufsize) +{ + if (buf[0] < 0x80) /* ASCII */ + return 1; + else if (buf[0] == 0x8E) /* JIS X 0201 */ + { + if (bufsize < 2) + return seterror(EINVAL); + else if (!(0xA1 <= buf[1] && buf[1] <= 0xDF)) + return seterror(EILSEQ); + return 2; + } + else if (buf[0] == 0x8F) /* JIS X 0212 */ + { + if (bufsize < 3) + return seterror(EINVAL); + else if (!(0xA1 <= buf[1] && buf[1] <= 0xFE) + || !(0xA1 <= buf[2] && buf[2] <= 0xFE)) + return seterror(EILSEQ); + return 3; + } + else /* JIS X 0208 */ + { + if (bufsize < 2) + return seterror(EINVAL); + else if (!(0xA1 <= buf[0] && buf[0] <= 0xFE) + || !(0xA1 <= buf[1] && buf[1] <= 0xFE)) + return seterror(EILSEQ); + return 2; + } +} + +static int +kernel_mbtowc(csconv_t *cv, const uchar *buf, int bufsize, ushort *wbuf, int *wbufsize) +{ + int len; + + len = cv->mblen(cv, buf, bufsize); + if (len == -1) + return -1; + *wbufsize = MultiByteToWideChar(cv->codepage, mbtowc_flags (cv->codepage), + (const char *)buf, len, (wchar_t *)wbuf, *wbufsize); + if (*wbufsize == 0) + return seterror(EILSEQ); + return len; +} + +static int +kernel_wctomb(csconv_t *cv, ushort *wbuf, int wbufsize, uchar *buf, int bufsize) +{ + BOOL usedDefaultChar = 0; + BOOL *p = NULL; + int flags = 0; + int len; + + if (bufsize == 0) + return seterror(E2BIG); + if (!must_use_null_useddefaultchar(cv->codepage)) + { + p = &usedDefaultChar; +#ifdef WC_NO_BEST_FIT_CHARS + if (!(cv->flags & FLAG_TRANSLIT)) + flags |= WC_NO_BEST_FIT_CHARS; +#endif + } + len = WideCharToMultiByte(cv->codepage, flags, + (const wchar_t *)wbuf, wbufsize, (char *)buf, bufsize, NULL, p); + if (len == 0) + { + if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) + return seterror(E2BIG); + return seterror(EILSEQ); + } + else if (usedDefaultChar) + return seterror(EILSEQ); + else if (cv->mblen(cv, buf, len) != len) /* validate result */ + return seterror(EILSEQ); + return len; +} + +/* + * It seems that the mode (cv->mode) is fixnum. + * For example, when converting iso-2022-jp(cp50221) to unicode: + * in ascii sequence: mode=0xC42C0000 + * in jisx0208 sequence: mode=0xC42C0001 + * "C42C" is same for each convert session. + * It should be: ((codepage-1)<<16)|state + */ +static int +mlang_mbtowc(csconv_t *cv, const uchar *buf, int bufsize, ushort *wbuf, int *wbufsize) +{ + int len; + int insize; + HRESULT hr; + + len = cv->mblen(cv, buf, bufsize); + if (len == -1) + return -1; + insize = len; + hr = ConvertINetMultiByteToUnicode(&cv->mode, cv->codepage, + (const char *)buf, &insize, (wchar_t *)wbuf, wbufsize); + if (hr != S_OK || insize != len) + return seterror(EILSEQ); + return len; +} + +static int +mlang_wctomb(csconv_t *cv, ushort *wbuf, int wbufsize, uchar *buf, int bufsize) +{ + char tmpbuf[MB_CHAR_MAX]; /* enough room for one character */ + int tmpsize = MB_CHAR_MAX; + int insize = wbufsize; + HRESULT hr; + + hr = ConvertINetUnicodeToMultiByte(&cv->mode, cv->codepage, + (const wchar_t *)wbuf, &wbufsize, tmpbuf, &tmpsize); + if (hr != S_OK || insize != wbufsize) + return seterror(EILSEQ); + else if (bufsize < tmpsize) + return seterror(E2BIG); + else if (cv->mblen(cv, (uchar *)tmpbuf, tmpsize) != tmpsize) + return seterror(EILSEQ); + memcpy(buf, tmpbuf, tmpsize); + return tmpsize; +} + +static int +utf16_mbtowc(csconv_t *cv, const uchar *buf, int bufsize, ushort *wbuf, int *wbufsize) +{ + int codepage = cv->codepage; + + /* swap endian: 1200 <-> 1201 */ + if (cv->mode & UNICODE_MODE_SWAPPED) + codepage ^= 1; + + if (bufsize < 2) + return seterror(EINVAL); + if (codepage == 1200) /* little endian */ + wbuf[0] = (buf[1] << 8) | buf[0]; + else if (codepage == 1201) /* big endian */ + wbuf[0] = (buf[0] << 8) | buf[1]; + + if ((cv->flags & FLAG_USE_BOM) && !(cv->mode & UNICODE_MODE_BOM_DONE)) + { + cv->mode |= UNICODE_MODE_BOM_DONE; + if (wbuf[0] == 0xFFFE) + { + cv->mode |= UNICODE_MODE_SWAPPED; + *wbufsize = 0; + return 2; + } + else if (wbuf[0] == 0xFEFF) + { + *wbufsize = 0; + return 2; + } + } + + if (0xDC00 <= wbuf[0] && wbuf[0] <= 0xDFFF) + return seterror(EILSEQ); + if (0xD800 <= wbuf[0] && wbuf[0] <= 0xDBFF) + { + if (bufsize < 4) + return seterror(EINVAL); + if (codepage == 1200) /* little endian */ + wbuf[1] = (buf[3] << 8) | buf[2]; + else if (codepage == 1201) /* big endian */ + wbuf[1] = (buf[2] << 8) | buf[3]; + if (!(0xDC00 <= wbuf[1] && wbuf[1] <= 0xDFFF)) + return seterror(EILSEQ); + *wbufsize = 2; + return 4; + } + *wbufsize = 1; + return 2; +} + +static int +utf16_wctomb(csconv_t *cv, ushort *wbuf, int wbufsize, uchar *buf, int bufsize) +{ + if ((cv->flags & FLAG_USE_BOM) && !(cv->mode & UNICODE_MODE_BOM_DONE)) + { + int r; + + cv->mode |= UNICODE_MODE_BOM_DONE; + if (bufsize < 2) + return seterror(E2BIG); + if (cv->codepage == 1200) /* little endian */ + memcpy(buf, "\xFF\xFE", 2); + else if (cv->codepage == 1201) /* big endian */ + memcpy(buf, "\xFE\xFF", 2); + + r = utf16_wctomb(cv, wbuf, wbufsize, buf + 2, bufsize - 2); + if (r == -1) + return -1; + return r + 2; + } + + if (bufsize < 2) + return seterror(E2BIG); + if (cv->codepage == 1200) /* little endian */ + { + buf[0] = (wbuf[0] & 0x00FF); + buf[1] = (wbuf[0] & 0xFF00) >> 8; + } + else if (cv->codepage == 1201) /* big endian */ + { + buf[0] = (wbuf[0] & 0xFF00) >> 8; + buf[1] = (wbuf[0] & 0x00FF); + } + if (0xD800 <= wbuf[0] && wbuf[0] <= 0xDBFF) + { + if (bufsize < 4) + return seterror(E2BIG); + if (cv->codepage == 1200) /* little endian */ + { + buf[2] = (wbuf[1] & 0x00FF); + buf[3] = (wbuf[1] & 0xFF00) >> 8; + } + else if (cv->codepage == 1201) /* big endian */ + { + buf[2] = (wbuf[1] & 0xFF00) >> 8; + buf[3] = (wbuf[1] & 0x00FF); + } + return 4; + } + return 2; +} + +static int +utf32_mbtowc(csconv_t *cv, const uchar *buf, int bufsize, ushort *wbuf, int *wbufsize) +{ + int codepage = cv->codepage; + uint wc; + + /* swap endian: 12000 <-> 12001 */ + if (cv->mode & UNICODE_MODE_SWAPPED) + codepage ^= 1; + + if (bufsize < 4) + return seterror(EINVAL); + if (codepage == 12000) /* little endian */ + wc = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0]; + else if (codepage == 12001) /* big endian */ + wc = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]; + + if ((cv->flags & FLAG_USE_BOM) && !(cv->mode & UNICODE_MODE_BOM_DONE)) + { + cv->mode |= UNICODE_MODE_BOM_DONE; + if (wc == 0xFFFE0000) + { + cv->mode |= UNICODE_MODE_SWAPPED; + *wbufsize = 0; + return 4; + } + else if (wc == 0x0000FEFF) + { + *wbufsize = 0; + return 4; + } + } + + if ((0xD800 <= wc && wc <= 0xDFFF) || 0x10FFFF < wc) + return seterror(EILSEQ); + ucs4_to_utf16(wc, wbuf, wbufsize); + return 4; +} + +static int +utf32_wctomb(csconv_t *cv, ushort *wbuf, int wbufsize, uchar *buf, int bufsize) +{ + uint wc; + + if ((cv->flags & FLAG_USE_BOM) && !(cv->mode & UNICODE_MODE_BOM_DONE)) + { + int r; + + cv->mode |= UNICODE_MODE_BOM_DONE; + if (bufsize < 4) + return seterror(E2BIG); + if (cv->codepage == 12000) /* little endian */ + memcpy(buf, "\xFF\xFE\x00\x00", 4); + else if (cv->codepage == 12001) /* big endian */ + memcpy(buf, "\x00\x00\xFE\xFF", 4); + + r = utf32_wctomb(cv, wbuf, wbufsize, buf + 4, bufsize - 4); + if (r == -1) + return -1; + return r + 4; + } + + if (bufsize < 4) + return seterror(E2BIG); + wc = utf16_to_ucs4(wbuf); + if (cv->codepage == 12000) /* little endian */ + { + buf[0] = wc & 0x000000FF; + buf[1] = (wc & 0x0000FF00) >> 8; + buf[2] = (wc & 0x00FF0000) >> 16; + buf[3] = (wc & 0xFF000000) >> 24; + } + else if (cv->codepage == 12001) /* big endian */ + { + buf[0] = (wc & 0xFF000000) >> 24; + buf[1] = (wc & 0x00FF0000) >> 16; + buf[2] = (wc & 0x0000FF00) >> 8; + buf[3] = wc & 0x000000FF; + } + return 4; +} + +/* + * 50220: ISO 2022 Japanese with no halfwidth Katakana; Japanese (JIS) + * 50221: ISO 2022 Japanese with halfwidth Katakana; Japanese (JIS-Allow + * 1 byte Kana) + * 50222: ISO 2022 Japanese JIS X 0201-1989; Japanese (JIS-Allow 1 byte + * Kana - SO/SI) + * + * MultiByteToWideChar() and WideCharToMultiByte() behave differently + * depending on Windows version. On XP, WideCharToMultiByte() doesn't + * terminate result sequence with ascii escape. But Vista does. + * Use MLang instead. + */ + +#define ISO2022_MODE(cs, shift) (((cs) << 8) | (shift)) +#define ISO2022_MODE_CS(mode) (((mode) >> 8) & 0xFF) +#define ISO2022_MODE_SHIFT(mode) ((mode) & 0xFF) + +#define ISO2022_SI 0 +#define ISO2022_SO 1 + +/* shift in */ +static const char iso2022_SI_seq[] = "\x0F"; +/* shift out */ +static const char iso2022_SO_seq[] = "\x0E"; + +typedef struct iso2022_esc_t iso2022_esc_t; +struct iso2022_esc_t { + const char *esc; + int esc_len; + int len; + int cs; +}; + +#define ISO2022JP_CS_ASCII 0 +#define ISO2022JP_CS_JISX0201_ROMAN 1 +#define ISO2022JP_CS_JISX0201_KANA 2 +#define ISO2022JP_CS_JISX0208_1978 3 +#define ISO2022JP_CS_JISX0208_1983 4 +#define ISO2022JP_CS_JISX0212 5 + +static iso2022_esc_t iso2022jp_esc[] = { + {"\x1B\x28\x42", 3, 1, ISO2022JP_CS_ASCII}, + {"\x1B\x28\x4A", 3, 1, ISO2022JP_CS_JISX0201_ROMAN}, + {"\x1B\x28\x49", 3, 1, ISO2022JP_CS_JISX0201_KANA}, + {"\x1B\x24\x40", 3, 2, ISO2022JP_CS_JISX0208_1983}, /* unify 1978 with 1983 */ + {"\x1B\x24\x42", 3, 2, ISO2022JP_CS_JISX0208_1983}, + {"\x1B\x24\x28\x44", 4, 2, ISO2022JP_CS_JISX0212}, + {NULL, 0, 0, 0} +}; + +static int +iso2022jp_mbtowc(csconv_t *cv, const uchar *buf, int bufsize, ushort *wbuf, int *wbufsize) +{ + iso2022_esc_t *iesc = iso2022jp_esc; + char tmp[MB_CHAR_MAX]; + int insize; + HRESULT hr; + DWORD dummy = 0; + int len; + int esc_len; + int cs; + int shift; + int i; + + if (buf[0] == 0x1B) + { + for (i = 0; iesc[i].esc != NULL; ++i) + { + esc_len = iesc[i].esc_len; + if (bufsize < esc_len) + { + if (strncmp((char *)buf, iesc[i].esc, bufsize) == 0) + return seterror(EINVAL); + } + else + { + if (strncmp((char *)buf, iesc[i].esc, esc_len) == 0) + { + cv->mode = ISO2022_MODE(iesc[i].cs, ISO2022_SI); + *wbufsize = 0; + return esc_len; + } + } + } + /* not supported escape sequence */ + return seterror(EILSEQ); + } + else if (buf[0] == iso2022_SO_seq[0]) + { + cv->mode = ISO2022_MODE(ISO2022_MODE_CS(cv->mode), ISO2022_SO); + *wbufsize = 0; + return 1; + } + else if (buf[0] == iso2022_SI_seq[0]) + { + cv->mode = ISO2022_MODE(ISO2022_MODE_CS(cv->mode), ISO2022_SI); + *wbufsize = 0; + return 1; + } + + cs = ISO2022_MODE_CS(cv->mode); + shift = ISO2022_MODE_SHIFT(cv->mode); + + /* reset the mode for informal sequence */ + if (buf[0] < 0x20) + { + cs = ISO2022JP_CS_ASCII; + shift = ISO2022_SI; + } + + len = iesc[cs].len; + if (bufsize < len) + return seterror(EINVAL); + for (i = 0; i < len; ++i) + if (!(buf[i] < 0x80)) + return seterror(EILSEQ); + esc_len = iesc[cs].esc_len; + memcpy(tmp, iesc[cs].esc, esc_len); + if (shift == ISO2022_SO) + { + memcpy(tmp + esc_len, iso2022_SO_seq, 1); + esc_len += 1; + } + memcpy(tmp + esc_len, buf, len); + + if ((cv->codepage == 50220 || cv->codepage == 50221 + || cv->codepage == 50222) && shift == ISO2022_SO) + { + /* XXX: shift-out cannot be used for mbtowc (both kernel and + * mlang) */ + esc_len = iesc[ISO2022JP_CS_JISX0201_KANA].esc_len; + memcpy(tmp, iesc[ISO2022JP_CS_JISX0201_KANA].esc, esc_len); + memcpy(tmp + esc_len, buf, len); + } + + insize = len + esc_len; + hr = ConvertINetMultiByteToUnicode(&dummy, cv->codepage, + (const char *)tmp, &insize, (wchar_t *)wbuf, wbufsize); + if (hr != S_OK || insize != len + esc_len) + return seterror(EILSEQ); + + /* Check for conversion error. Assuming defaultChar is 0x3F. */ + /* ascii should be converted from ascii */ + if (wbuf[0] == buf[0] + && cv->mode != ISO2022_MODE(ISO2022JP_CS_ASCII, ISO2022_SI)) + return seterror(EILSEQ); + + /* reset the mode for informal sequence */ + if (cv->mode != ISO2022_MODE(cs, shift)) + cv->mode = ISO2022_MODE(cs, shift); + + return len; +} + +static int +iso2022jp_wctomb(csconv_t *cv, ushort *wbuf, int wbufsize, uchar *buf, int bufsize) +{ + iso2022_esc_t *iesc = iso2022jp_esc; + char tmp[MB_CHAR_MAX]; + int tmpsize = MB_CHAR_MAX; + int insize = wbufsize; + HRESULT hr; + DWORD dummy = 0; + int len; + int esc_len; + int cs; + int shift; + int i; + + /* + * MultiByte = [escape sequence] + character + [escape sequence] + * + * Whether trailing escape sequence is added depends on which API is + * used (kernel or MLang, and its version). + */ + hr = ConvertINetUnicodeToMultiByte(&dummy, cv->codepage, + (const wchar_t *)wbuf, &wbufsize, tmp, &tmpsize); + if (hr != S_OK || insize != wbufsize) + return seterror(EILSEQ); + else if (bufsize < tmpsize) + return seterror(E2BIG); + + if (tmpsize == 1) + { + cs = ISO2022JP_CS_ASCII; + esc_len = 0; + } + else + { + for (i = 1; iesc[i].esc != NULL; ++i) + { + esc_len = iesc[i].esc_len; + if (strncmp(tmp, iesc[i].esc, esc_len) == 0) + { + cs = iesc[i].cs; + break; + } + } + if (iesc[i].esc == NULL) + /* not supported escape sequence */ + return seterror(EILSEQ); + } + + shift = ISO2022_SI; + if (tmp[esc_len] == iso2022_SO_seq[0]) + { + shift = ISO2022_SO; + esc_len += 1; + } + + len = iesc[cs].len; + + /* Check for converting error. Assuming defaultChar is 0x3F. */ + /* ascii should be converted from ascii */ + if (cs == ISO2022JP_CS_ASCII && !(wbuf[0] < 0x80)) + return seterror(EILSEQ); + else if (tmpsize < esc_len + len) + return seterror(EILSEQ); + + if (cv->mode == ISO2022_MODE(cs, shift)) + { + /* remove escape sequence */ + if (esc_len != 0) + memmove(tmp, tmp + esc_len, len); + esc_len = 0; + } + else + { + if (cs == ISO2022JP_CS_ASCII) + { + esc_len = iesc[ISO2022JP_CS_ASCII].esc_len; + memmove(tmp + esc_len, tmp, len); + memcpy(tmp, iesc[ISO2022JP_CS_ASCII].esc, esc_len); + } + if (ISO2022_MODE_SHIFT(cv->mode) == ISO2022_SO) + { + /* shift-in before changing to other mode */ + memmove(tmp + 1, tmp, len + esc_len); + memcpy(tmp, iso2022_SI_seq, 1); + esc_len += 1; + } + } + + if (bufsize < len + esc_len) + return seterror(E2BIG); + memcpy(buf, tmp, len + esc_len); + cv->mode = ISO2022_MODE(cs, shift); + return len + esc_len; +} + +static int +iso2022jp_flush(csconv_t *cv, uchar *buf, int bufsize) +{ + iso2022_esc_t *iesc = iso2022jp_esc; + int esc_len; + + if (cv->mode != ISO2022_MODE(ISO2022JP_CS_ASCII, ISO2022_SI)) + { + esc_len = 0; + if (ISO2022_MODE_SHIFT(cv->mode) != ISO2022_SI) + esc_len += 1; + if (ISO2022_MODE_CS(cv->mode) != ISO2022JP_CS_ASCII) + esc_len += iesc[ISO2022JP_CS_ASCII].esc_len; + if (bufsize < esc_len) + return seterror(E2BIG); + + esc_len = 0; + if (ISO2022_MODE_SHIFT(cv->mode) != ISO2022_SI) + { + memcpy(buf, iso2022_SI_seq, 1); + esc_len += 1; + } + if (ISO2022_MODE_CS(cv->mode) != ISO2022JP_CS_ASCII) + { + memcpy(buf + esc_len, iesc[ISO2022JP_CS_ASCII].esc, + iesc[ISO2022JP_CS_ASCII].esc_len); + esc_len += iesc[ISO2022JP_CS_ASCII].esc_len; + } + return esc_len; + } + return 0; +} + +#if defined(MAKE_DLL) && defined(USE_LIBICONV_DLL) +BOOL WINAPI +DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) +{ + switch( fdwReason ) + { + case DLL_PROCESS_ATTACH: + hwiniconv = (HMODULE)hinstDLL; + break; + case DLL_THREAD_ATTACH: + case DLL_THREAD_DETACH: + case DLL_PROCESS_DETACH: + break; + } + return TRUE; +} +#endif + +#if defined(MAKE_EXE) +#include +#include +#include +int +main(int argc, char **argv) +{ + char *fromcode = NULL; + char *tocode = NULL; + int i; + char inbuf[BUFSIZ]; + char outbuf[BUFSIZ]; + const char *pin; + char *pout; + size_t inbytesleft; + size_t outbytesleft; + size_t rest = 0; + iconv_t cd; + size_t r; + FILE *in = stdin; + + _setmode(_fileno(stdin), _O_BINARY); + _setmode(_fileno(stdout), _O_BINARY); + + for (i = 1; i < argc; ++i) + { + if (strcmp(argv[i], "-l") == 0) + { + for (i = 0; codepage_alias[i].name != NULL; ++i) + printf("%s\n", codepage_alias[i].name); + return 0; + } + + if (strcmp(argv[i], "-f") == 0) + fromcode = argv[++i]; + else if (strcmp(argv[i], "-t") == 0) + tocode = argv[++i]; + else + { + in = fopen(argv[i], "rb"); + if (in == NULL) + { + fprintf(stderr, "cannot open %s\n", argv[i]); + return 1; + } + break; + } + } + + if (fromcode == NULL || tocode == NULL) + { + printf("usage: %s -f from-enc -t to-enc [file]\n", argv[0]); + return 0; + } + + cd = iconv_open(tocode, fromcode); + if (cd == (iconv_t)(-1)) + { + perror("iconv_open error"); + return 1; + } + + while ((inbytesleft = fread(inbuf + rest, 1, sizeof(inbuf) - rest, in)) != 0 + || rest != 0) + { + inbytesleft += rest; + pin = inbuf; + pout = outbuf; + outbytesleft = sizeof(outbuf); + r = iconv(cd, &pin, &inbytesleft, &pout, &outbytesleft); + fwrite(outbuf, 1, sizeof(outbuf) - outbytesleft, stdout); + if (r == (size_t)(-1) && errno != E2BIG && (errno != EINVAL || feof(in))) + { + perror("conversion error"); + return 1; + } + memmove(inbuf, pin, inbytesleft); + rest = inbytesleft; + } + pout = outbuf; + outbytesleft = sizeof(outbuf); + r = iconv(cd, NULL, NULL, &pout, &outbytesleft); + fwrite(outbuf, 1, sizeof(outbuf) - outbytesleft, stdout); + if (r == (size_t)(-1)) + { + perror("conversion error"); + return 1; + } + + iconv_close(cd); + + return 0; +} +#endif diff --git a/libs/win-iconv/win_iconv_test.c b/libs/win-iconv/win_iconv_test.c new file mode 100644 index 000000000..a6cd3a3ab --- /dev/null +++ b/libs/win-iconv/win_iconv_test.c @@ -0,0 +1,271 @@ + +#ifdef USE_ICONV_H +#include +#include +#include +#include +#include +#else +#include "win_iconv.c" +#endif + +#include + +const char * +tohex(const char *str, int size) +{ + static char buf[BUFSIZ]; + char *pbuf = buf; + int i; + buf[0] = 0; + for (i = 0; i < size; ++i) + pbuf += sprintf(pbuf, "%02X", str[i] & 0xFF); + return buf; +} + +const char * +errstr(int errcode) +{ + static char buf[BUFSIZ]; + switch (errcode) + { + case 0: return "NOERROR"; + case EINVAL: return "EINVAL"; + case EILSEQ: return "EILSEQ"; + case E2BIG: return "E2BIG"; + } + sprintf(buf, "%d\n", errcode); + return buf; +} + +#ifdef USE_LIBICONV_DLL +int use_dll; + +int +setdll(const char *dllpath) +{ + char buf[BUFSIZ]; + rec_iconv_t cd; + + sprintf(buf, "WINICONV_LIBICONV_DLL=%s", dllpath); + putenv(buf); + if (libiconv_iconv_open(&cd, "ascii", "ascii")) + { + FreeLibrary(cd.hlibiconv); + use_dll = TRUE; + return TRUE; + } + use_dll = FALSE; + return FALSE; +} +#endif + +/* + * We can test the codepage that is installed in the system. + */ +int +check_enc(const char *encname, int codepage) +{ + iconv_t cd; + int cp; + cd = iconv_open("utf-8", encname); + if (cd == (iconv_t)(-1)) + { + printf("%s(%d) IS NOT SUPPORTED: SKIP THE TEST\n", encname, codepage); + return FALSE; + } +#ifndef USE_ICONV_H + cp = ((rec_iconv_t *)cd)->from.codepage; + if (cp != codepage) + { + printf("%s(%d) ALIAS IS MAPPED TO DIFFERENT CODEPAGE (%d)\n", encname, codepage, cp); + exit(1); + } +#endif + iconv_close(cd); + return TRUE; +} + +void +test(const char *from, const char *fromstr, int fromsize, const char *to, const char *tostr, int tosize, int errcode, int bufsize, int line) +{ + char outbuf[BUFSIZ]; + const char *pin; + char *pout; + size_t inbytesleft; + size_t outbytesleft; + iconv_t cd; + size_t r; +#ifdef USE_LIBICONV_DLL + char dllpath[_MAX_PATH]; +#endif + + cd = iconv_open(to, from); + if (cd == (iconv_t)(-1)) + { + printf("%s -> %s: NG: INVALID ENCODING NAME: line=%d\n", from, to, line); + exit(1); + } + +#ifdef USE_LIBICONV_DLL + if (((rec_iconv_t *)cd)->hlibiconv != NULL) + GetModuleFileName(((rec_iconv_t *)cd)->hlibiconv, dllpath, sizeof(dllpath)); + + if (use_dll && ((rec_iconv_t *)cd)->hlibiconv == NULL) + { + printf("%s: %s -> %s: NG: FAILED TO USE DLL: line=%d\n", dllpath, from, to, line); + exit(1); + } + else if (!use_dll && ((rec_iconv_t *)cd)->hlibiconv != NULL) + { + printf("%s: %s -> %s: NG: DLL IS LOADED UNEXPECTEDLY: line=%d\n", dllpath, from, to, line); + exit(1); + } +#endif + + errno = 0; + + pin = fromstr; + pout = outbuf; + inbytesleft = fromsize; + outbytesleft = bufsize; + r = iconv(cd, &pin, &inbytesleft, &pout, &outbytesleft); + if (r != (size_t)(-1)) + r = iconv(cd, NULL, NULL, &pout, &outbytesleft); + *pout = 0; + +#ifdef USE_LIBICONV_DLL + if (use_dll) + printf("%s: ", dllpath); +#endif + printf("%s(%s) -> ", from, tohex(fromstr, fromsize)); + printf("%s(%s%s%s): ", to, tohex(tostr, tosize), + errcode == 0 ? "" : ":", + errcode == 0 ? "" : errstr(errcode)); + if (strcmp(outbuf, tostr) == 0 && errno == errcode) + printf("OK\n"); + else + { + printf("RESULT(%s:%s): ", tohex(outbuf, sizeof(outbuf) - outbytesleft), + errstr(errno)); + printf("NG: line=%d\n", line); + exit(1); + } +} + +#define STATIC_STRLEN(arr) (sizeof(arr) - 1) + +#define success(from, fromstr, to, tostr) test(from, fromstr, STATIC_STRLEN(fromstr), to, tostr, STATIC_STRLEN(tostr), 0, BUFSIZ, __LINE__) +#define einval(from, fromstr, to, tostr) test(from, fromstr, STATIC_STRLEN(fromstr), to, tostr, STATIC_STRLEN(tostr), EINVAL, BUFSIZ, __LINE__) +#define eilseq(from, fromstr, to, tostr) test(from, fromstr, STATIC_STRLEN(fromstr), to, tostr, STATIC_STRLEN(tostr), EILSEQ, BUFSIZ, __LINE__) +#define e2big(from, fromstr, to, tostr, bufsize) test(from, fromstr, STATIC_STRLEN(fromstr), to, tostr, STATIC_STRLEN(tostr), E2BIG, bufsize, __LINE__) + +int +main(int argc, char **argv) +{ +#ifdef USE_LIBICONV_DLL + /* test use of dll if $DEFAULT_LIBICONV_DLL was defined. */ + if (setdll("")) + { + success("ascii", "ABC", "ascii", "ABC"); + success("ascii", "ABC", "utf-16be", "\x00\x41\x00\x42\x00\x43"); + } + else + { + printf("\nDLL TEST IS SKIPPED\n\n"); + } + + setdll("none"); +#endif + + if (check_enc("ascii", 20127)) + { + success("ascii", "ABC", "ascii", "ABC"); + /* MSB is dropped. Hmm... */ + success("ascii", "\x80\xFF", "ascii", "\x00\x7F"); + } + + /* unicode (CP1200 CP1201 CP12000 CP12001 CP65001) */ + if (check_enc("utf-8", 65001) + && check_enc("utf-16be", 1201) && check_enc("utf-16le", 1200) + && check_enc("utf-32be", 12001) && check_enc("utf-32le", 12000) + ) + { + /* Test the BOM behavior + * 1. Remove the BOM when "fromcode" is utf-16 or utf-32. + * 2. Add the BOM when "tocode" is utf-16 or utf-32. */ + success("utf-16", "\xFE\xFF\x01\x02", "utf-16be", "\x01\x02"); + success("utf-16", "\xFF\xFE\x02\x01", "utf-16be", "\x01\x02"); + success("utf-32", "\x00\x00\xFE\xFF\x00\x00\x01\x02", "utf-32be", "\x00\x00\x01\x02"); + success("utf-32", "\xFF\xFE\x00\x00\x02\x01\x00\x00", "utf-32be", "\x00\x00\x01\x02"); + success("utf-16", "\xFE\xFF\x00\x01", "utf-8", "\x01"); +#ifndef GLIB_COMPILATION + success("utf-8", "\x01", "utf-16", "\xFE\xFF\x00\x01"); + success("utf-8", "\x01", "utf-32", "\x00\x00\xFE\xFF\x00\x00\x00\x01"); +#else + success("utf-8", "\x01", "utf-16", "\xFF\xFE\x01\x00"); + success("utf-8", "\x01", "utf-32", "\xFF\xFE\x00\x00\x01\x00\x00\x00"); +#endif + + success("utf-16be", "\xFE\xFF\x01\x02", "utf-16be", "\xFE\xFF\x01\x02"); + success("utf-16le", "\xFF\xFE\x02\x01", "utf-16be", "\xFE\xFF\x01\x02"); + success("utf-32be", "\x00\x00\xFE\xFF\x00\x00\x01\x02", "utf-32be", "\x00\x00\xFE\xFF\x00\x00\x01\x02"); + success("utf-32le", "\xFF\xFE\x00\x00\x02\x01\x00\x00", "utf-32be", "\x00\x00\xFE\xFF\x00\x00\x01\x02"); + success("utf-16be", "\xFE\xFF\x00\x01", "utf-8", "\xEF\xBB\xBF\x01"); + success("utf-8", "\xEF\xBB\xBF\x01", "utf-8", "\xEF\xBB\xBF\x01"); + + success("utf-16be", "\x01\x02", "utf-16le", "\x02\x01"); + success("utf-16le", "\x02\x01", "utf-16be", "\x01\x02"); + success("utf-16be", "\xFE\xFF", "utf-16le", "\xFF\xFE"); + success("utf-16le", "\xFF\xFE", "utf-16be", "\xFE\xFF"); + success("utf-32be", "\x00\x00\x03\x04", "utf-32le", "\x04\x03\x00\x00"); + success("utf-32le", "\x04\x03\x00\x00", "utf-32be", "\x00\x00\x03\x04"); + success("utf-32be", "\x00\x00\xFF\xFF", "utf-16be", "\xFF\xFF"); + success("utf-16be", "\xFF\xFF", "utf-32be", "\x00\x00\xFF\xFF"); + success("utf-32be", "\x00\x01\x00\x00", "utf-16be", "\xD8\x00\xDC\x00"); + success("utf-16be", "\xD8\x00\xDC\x00", "utf-32be", "\x00\x01\x00\x00"); + success("utf-32be", "\x00\x10\xFF\xFF", "utf-16be", "\xDB\xFF\xDF\xFF"); + success("utf-16be", "\xDB\xFF\xDF\xFF", "utf-32be", "\x00\x10\xFF\xFF"); + eilseq("utf-32be", "\x00\x11\x00\x00", "utf-16be", ""); + eilseq("utf-16be", "\xDB\xFF\xE0\x00", "utf-32be", ""); + success("utf-8", "\xE3\x81\x82", "utf-16be", "\x30\x42"); + einval("utf-8", "\xE3", "utf-16be", ""); + } + + /* Japanese (CP932 CP20932 CP50220 CP50221 CP50222 CP51932) */ + if (check_enc("cp932", 932) + && check_enc("cp20932", 20932) && check_enc("euc-jp", 51932) + && check_enc("cp50220", 50220) && check_enc("cp50221", 50221) + && check_enc("cp50222", 50222) && check_enc("iso-2022-jp", 50221)) + { + /* Test the compatibility for each other Japanese codepage. + * And validate the escape sequence handling for iso-2022-jp. */ + success("utf-16be", "\xFF\x5E", "cp932", "\x81\x60"); + success("utf-16be", "\x30\x1C", "cp932", "\x81\x60"); + success("utf-16be", "\xFF\x5E", "cp932//nocompat", "\x81\x60"); + eilseq("utf-16be", "\x30\x1C", "cp932//nocompat", ""); + success("euc-jp", "\xA4\xA2", "utf-16be", "\x30\x42"); + einval("euc-jp", "\xA4\xA2\xA4", "utf-16be", "\x30\x42"); + eilseq("euc-jp", "\xA4\xA2\xFF\xFF", "utf-16be", "\x30\x42"); + success("cp932", "\x81\x60", "iso-2022-jp", "\x1B\x24\x42\x21\x41\x1B\x28\x42"); + success("UTF-16BE", "\xFF\x5E", "iso-2022-jp", "\x1B\x24\x42\x21\x41\x1B\x28\x42"); + eilseq("UTF-16BE", "\x30\x1C", "iso-2022-jp//nocompat", ""); + success("UTF-16BE", "\x30\x42\x30\x44", "iso-2022-jp", "\x1B\x24\x42\x24\x22\x24\x24\x1B\x28\x42"); + success("iso-2022-jp", "\x1B\x24\x42\x21\x41\x1B\x28\x42", "UTF-16BE", "\xFF\x5E"); + } + + /* + * test for //translit + * U+FF41 (FULLWIDTH LATIN SMALL LETTER A) <-> U+0062 (LATIN SMALL LETTER A) + */ + eilseq("UTF-16BE", "\xFF\x41", "iso-8859-1", ""); + success("UTF-16BE", "\xFF\x41", "iso-8859-1//translit", "a"); + + /* + * TODO: + * Test for state after iconv() failed. + * Ensure iconv() error is safe and continuable. + */ + + return 0; +} diff --git a/libs/zlib/CMakeLists.txt b/libs/zlib/CMakeLists.txt new file mode 100644 index 000000000..0a56ff6f2 --- /dev/null +++ b/libs/zlib/CMakeLists.txt @@ -0,0 +1,199 @@ +cmake_minimum_required(VERSION 2.4.4) +set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON) + +project(zlib C) + +if(NOT DEFINED BUILD_SHARED_LIBS) + option(BUILD_SHARED_LIBS "Build a shared library form of zlib" ON) +endif() + +include(CheckTypeSize) +include(CheckFunctionExists) +include(CheckIncludeFile) +include(CheckCSourceCompiles) +enable_testing() + +check_include_file(sys/types.h HAVE_SYS_TYPES_H) +check_include_file(stdint.h HAVE_STDINT_H) +check_include_file(stddef.h HAVE_STDDEF_H) + +# +# Check to see if we have large file support +# +set(CMAKE_REQUIRED_DEFINITIONS -D_LARGEFILE64_SOURCE=1) +# We add these other definitions here because CheckTypeSize.cmake +# in CMake 2.4.x does not automatically do so and we want +# compatibility with CMake 2.4.x. +if(HAVE_SYS_TYPES_H) + list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_SYS_TYPES_H) +endif() +if(HAVE_STDINT_H) + list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDINT_H) +endif() +if(HAVE_STDDEF_H) + list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDDEF_H) +endif() +check_type_size(off64_t OFF64_T) +if(HAVE_OFF64_T) + add_definitions(-D_LARGEFILE64_SOURCE=1) +endif() +set(CMAKE_REQUIRED_DEFINITIONS) # clear variable + +# +# Check for fseeko +# +check_function_exists(fseeko HAVE_FSEEKO) +if(NOT HAVE_FSEEKO) + add_definitions(-DNO_FSEEKO) +endif() + +# +# Check for unistd.h +# +check_include_file(unistd.h Z_HAVE_UNISTD_H) + +if(MSVC) + set(CMAKE_DEBUG_POSTFIX "d") + add_definitions(-D_CRT_SECURE_NO_DEPRECATE) + add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE) +endif() + +if(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR) + # If we're doing an out of source build and the user has a zconf.h + # in their source tree... + if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h) + message(FATAL_ERROR + "You must remove ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h " + "from the source tree. This file is included with zlib " + "but CMake generates this file for you automatically " + "in the build directory.") + endif() +endif() + +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/zconf.h.cmakein + ${CMAKE_CURRENT_BINARY_DIR}/zconf.h @ONLY) +include_directories(${CMAKE_CURRENT_BINARY_DIR}) + + +#============================================================================ +# zlib +#============================================================================ + +set(ZLIB_PUBLIC_HDRS + ${CMAKE_CURRENT_BINARY_DIR}/zconf.h + zlib.h +) +set(ZLIB_PRIVATE_HDRS + crc32.h + deflate.h + gzguts.h + inffast.h + inffixed.h + inflate.h + inftrees.h + trees.h + zutil.h +) +set(ZLIB_SRCS + adler32.c + compress.c + crc32.c + deflate.c + gzclose.c + gzlib.c + gzread.c + gzwrite.c + inflate.c + infback.c + inftrees.c + inffast.c + trees.c + uncompr.c + zutil.c +) + +if(NOT MINGW) + set(ZLIB_SRCS ${ZLIB_SRCS} + win32/zlib1.rc # If present will override custom build rule below. + ) +endif() + +# parse the full version number from zlib.h and include in ZLIB_FULL_VERSION +file(READ ${CMAKE_CURRENT_SOURCE_DIR}/zlib.h _zlib_h_contents) +string(REGEX REPLACE ".*#define[ \t]+ZLIB_VERSION[ \t]+\"([0-9A-Za-z.]+)\".*" + "\\1" ZLIB_FULL_VERSION ${_zlib_h_contents}) + +if(MINGW) + # This gets us DLL resource information when compiling on MinGW. + if(NOT CMAKE_RC_COMPILER) + SET(CMAKE_RC_COMPILER windres.exe) + endif() + + add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj + COMMAND ${CMAKE_RC_COMPILER} + -D GCC_WINDRES + -I ${CMAKE_CURRENT_SOURCE_DIR} + -I ${CMAKE_CURRENT_BINARY_DIR} + -o ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj + -i ${CMAKE_CURRENT_SOURCE_DIR}/win32/zlib1.rc) + set(ZLIB_SRCS ${ZLIB_SRCS} ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj) +endif(MINGW) + +add_library(zlib ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS}) +set_target_properties(zlib PROPERTIES DEFINE_SYMBOL ZLIB_DLL) + +set_target_properties(zlib PROPERTIES SOVERSION 1) + +if(NOT CYGWIN) + # This property causes shared libraries on Linux to have the full version + # encoded into their final filename. We disable this on Cygwin because + # it causes cygz-${ZLIB_FULL_VERSION}.dll to be created when cygz.dll + # seems to be the default. + # + # This has no effect with MSVC, on that platform the version info for + # the DLL comes from the resource file win32/zlib1.rc + set_target_properties(zlib PROPERTIES VERSION ${ZLIB_FULL_VERSION}) +endif() + +if(UNIX) + # On unix-like platforms the library is almost always called libz + set_target_properties(zlib PROPERTIES OUTPUT_NAME z) +elseif(BUILD_SHARED_LIBS AND WIN32) + # Creates zlib1.dll when building shared library version + set_target_properties(zlib PROPERTIES SUFFIX "1.dll") +endif() + +if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL ) + install(TARGETS zlib + RUNTIME DESTINATION bin + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib ) +endif() +if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL ) + install(FILES ${ZLIB_PUBLIC_HDRS} DESTINATION include) +endif() +if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL ) + install(FILES zlib.3 DESTINATION share/man/man3) +endif() + +#============================================================================ +# Example binaries +#============================================================================ + +add_executable(example test/example.c) +target_link_libraries(example zlib) +add_test(example example) + +add_executable(minigzip test/minigzip.c) +target_link_libraries(minigzip zlib) + +if(HAVE_OFF64_T) + add_executable(example64 test/example.c) + target_link_libraries(example64 zlib) + set_target_properties(example64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64") + add_test(example64 example64) + + add_executable(minigzip64 test/minigzip.c) + target_link_libraries(minigzip64 zlib) + set_target_properties(minigzip64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64") +endif() diff --git a/libs/zlib/ChangeLog b/libs/zlib/ChangeLog new file mode 100644 index 000000000..6fa5d4411 --- /dev/null +++ b/libs/zlib/ChangeLog @@ -0,0 +1,1347 @@ + + ChangeLog file for zlib + +Changes in 1.2.6 (29 Jan 2012) +- Update the Pascal interface in contrib/pascal +- Fix function numbers for gzgetc_ in zlibvc.def files +- Fix configure.ac for contrib/minizip [Schiffer] +- Fix large-entry detection in minizip on 64-bit systems [Schiffer] +- Have ./configure use the compiler return code for error indication +- Fix CMakeLists.txt for cross compilation [McClure] +- Fix contrib/minizip/zip.c for 64-bit architectures [Dalsnes] +- Fix compilation of contrib/minizip on FreeBSD [Marquez] +- Correct suggested usages in win32/Makefile.msc [Shachar, Horvath] +- Include io.h for Turbo C / Borland C on all platforms [Truta] +- Make version explicit in contrib/minizip/configure.ac [Bosmans] +- Avoid warning for no encryption in contrib/minizip/zip.c [Vollant] +- Minor cleanup up contrib/minizip/unzip.c [Vollant] +- Fix bug when compiling minizip with C++ [Vollant] +- Protect for long name and extra fields in contrib/minizip [Vollant] +- Avoid some warnings in contrib/minizip [Vollant] +- Add -I../.. -L../.. to CFLAGS for minizip and miniunzip +- Add missing libs to minizip linker command +- Add support for VPATH builds in contrib/minizip +- Add an --enable-demos option to contrib/minizip/configure +- Add the generation of configure.log by ./configure +- Exit when required parameters not provided to win32/Makefile.gcc +- Have gzputc return the character written instead of the argument +- Use the -m option on ldconfig for BSD systems [Tobias] +- Correct in zlib.map when deflateResetKeep was added + +Changes in 1.2.5.3 (15 Jan 2012) +- Restore gzgetc function for binary compatibility +- Do not use _lseeki64 under Borland C++ [Truta] +- Update win32/Makefile.msc to build test/*.c [Truta] +- Remove old/visualc6 given CMakefile and other alternatives +- Update AS400 build files and documentation [Monnerat] +- Update win32/Makefile.gcc to build test/*.c [Truta] +- Permit stronger flushes after Z_BLOCK flushes +- Avoid extraneous empty blocks when doing empty flushes +- Permit Z_NULL arguments to deflatePending +- Allow deflatePrime() to insert bits in the middle of a stream +- Remove second empty static block for Z_PARTIAL_FLUSH +- Write out all of the available bits when using Z_BLOCK +- Insert the first two strings in the hash table after a flush + +Changes in 1.2.5.2 (17 Dec 2011) +- fix ld error: unable to find version dependency 'ZLIB_1.2.5' +- use relative symlinks for shared libs +- Avoid searching past window for Z_RLE strategy +- Assure that high-water mark initialization is always applied in deflate +- Add assertions to fill_window() in deflate.c to match comments +- Update python link in README +- Correct spelling error in gzread.c +- Fix bug in gzgets() for a concatenated empty gzip stream +- Correct error in comment for gz_make() +- Change gzread() and related to ignore junk after gzip streams +- Allow gzread() and related to continue after gzclearerr() +- Allow gzrewind() and gzseek() after a premature end-of-file +- Simplify gzseek() now that raw after gzip is ignored +- Change gzgetc() to a macro for speed (~40% speedup in testing) +- Fix gzclose() to return the actual error last encountered +- Always add large file support for windows +- Include zconf.h for windows large file support +- Include zconf.h.cmakein for windows large file support +- Update zconf.h.cmakein on make distclean +- Merge vestigial vsnprintf determination from zutil.h to gzguts.h +- Clarify how gzopen() appends in zlib.h comments +- Correct documentation of gzdirect() since junk at end now ignored +- Add a transparent write mode to gzopen() when 'T' is in the mode +- Update python link in zlib man page +- Get inffixed.h and MAKEFIXED result to match +- Add a ./config --solo option to make zlib subset with no libary use +- Add undocumented inflateResetKeep() function for CAB file decoding +- Add --cover option to ./configure for gcc coverage testing +- Add #define ZLIB_CONST option to use const in the z_stream interface +- Add comment to gzdopen() in zlib.h to use dup() when using fileno() +- Note behavior of uncompress() to provide as much data as it can +- Add files in contrib/minizip to aid in building libminizip +- Split off AR options in Makefile.in and configure +- Change ON macro to Z_ARG to avoid application conflicts +- Facilitate compilation with Borland C++ for pragmas and vsnprintf +- Include io.h for Turbo C / Borland C++ +- Move example.c and minigzip.c to test/ +- Simplify incomplete code table filling in inflate_table() +- Remove code from inflate.c and infback.c that is impossible to execute +- Test the inflate code with full coverage +- Allow deflateSetDictionary, inflateSetDictionary at any time (in raw) +- Add deflateResetKeep and fix inflateResetKeep to retain dictionary +- Fix gzwrite.c to accommodate reduced memory zlib compilation +- Have inflate() with Z_FINISH avoid the allocation of a window +- Do not set strm->adler when doing raw inflate +- Fix gzeof() to behave just like feof() when read is not past end of file +- Fix bug in gzread.c when end-of-file is reached +- Avoid use of Z_BUF_ERROR in gz* functions except for premature EOF +- Document gzread() capability to read concurrently written files +- Remove hard-coding of resource compiler in CMakeLists.txt [Blammo] + +Changes in 1.2.5.1 (10 Sep 2011) +- Update FAQ entry on shared builds (#13) +- Avoid symbolic argument to chmod in Makefile.in +- Fix bug and add consts in contrib/puff [Oberhumer] +- Update contrib/puff/zeros.raw test file to have all block types +- Add full coverage test for puff in contrib/puff/Makefile +- Fix static-only-build install in Makefile.in +- Fix bug in unzGetCurrentFileInfo() in contrib/minizip [Kuno] +- Add libz.a dependency to shared in Makefile.in for parallel builds +- Spell out "number" (instead of "nb") in zlib.h for total_in, total_out +- Replace $(...) with `...` in configure for non-bash sh [Bowler] +- Add darwin* to Darwin* and solaris* to SunOS\ 5* in configure [Groffen] +- Add solaris* to Linux* in configure to allow gcc use [Groffen] +- Add *bsd* to Linux* case in configure [Bar-Lev] +- Add inffast.obj to dependencies in win32/Makefile.msc +- Correct spelling error in deflate.h [Kohler] +- Change libzdll.a again to libz.dll.a (!) in win32/Makefile.gcc +- Add test to configure for GNU C looking for gcc in output of $cc -v +- Add zlib.pc generation to win32/Makefile.gcc [Weigelt] +- Fix bug in zlib.h for _FILE_OFFSET_BITS set and _LARGEFILE64_SOURCE not +- Add comment in zlib.h that adler32_combine with len2 < 0 makes no sense +- Make NO_DIVIDE option in adler32.c much faster (thanks to John Reiser) +- Make stronger test in zconf.h to include unistd.h for LFS +- Apply Darwin patches for 64-bit file offsets to contrib/minizip [Slack] +- Fix zlib.h LFS support when Z_PREFIX used +- Add updated as400 support (removed from old) [Monnerat] +- Avoid deflate sensitivity to volatile input data +- Avoid division in adler32_combine for NO_DIVIDE +- Clarify the use of Z_FINISH with deflateBound() amount of space +- Set binary for output file in puff.c +- Use u4 type for crc_table to avoid conversion warnings +- Apply casts in zlib.h to avoid conversion warnings +- Add OF to prototypes for adler32_combine_ and crc32_combine_ [Miller] +- Improve inflateSync() documentation to note indeterminancy +- Add deflatePending() function to return the amount of pending output +- Correct the spelling of "specification" in FAQ [Randers-Pehrson] +- Add a check in configure for stdarg.h, use for gzprintf() +- Check that pointers fit in ints when gzprint() compiled old style +- Add dummy name before $(SHAREDLIBV) in Makefile [Bar-Lev, Bowler] +- Delete line in configure that adds -L. libz.a to LDFLAGS [Weigelt] +- Add debug records in assmebler code [Londer] +- Update RFC references to use http://tools.ietf.org/html/... [Li] +- Add --archs option, use of libtool to configure for Mac OS X [Borstel] + +Changes in 1.2.5 (19 Apr 2010) +- Disable visibility attribute in win32/Makefile.gcc [Bar-Lev] +- Default to libdir as sharedlibdir in configure [Nieder] +- Update copyright dates on modified source files +- Update trees.c to be able to generate modified trees.h +- Exit configure for MinGW, suggesting win32/Makefile.gcc +- Check for NULL path in gz_open [Homurlu] + +Changes in 1.2.4.5 (18 Apr 2010) +- Set sharedlibdir in configure [Torok] +- Set LDFLAGS in Makefile.in [Bar-Lev] +- Avoid mkdir objs race condition in Makefile.in [Bowler] +- Add ZLIB_INTERNAL in front of internal inter-module functions and arrays +- Define ZLIB_INTERNAL to hide internal functions and arrays for GNU C +- Don't use hidden attribute when it is a warning generator (e.g. Solaris) + +Changes in 1.2.4.4 (18 Apr 2010) +- Fix CROSS_PREFIX executable testing, CHOST extract, mingw* [Torok] +- Undefine _LARGEFILE64_SOURCE in zconf.h if it is zero, but not if empty +- Try to use bash or ksh regardless of functionality of /bin/sh +- Fix configure incompatibility with NetBSD sh +- Remove attempt to run under bash or ksh since have better NetBSD fix +- Fix win32/Makefile.gcc for MinGW [Bar-Lev] +- Add diagnostic messages when using CROSS_PREFIX in configure +- Added --sharedlibdir option to configure [Weigelt] +- Use hidden visibility attribute when available [Frysinger] + +Changes in 1.2.4.3 (10 Apr 2010) +- Only use CROSS_PREFIX in configure for ar and ranlib if they exist +- Use CROSS_PREFIX for nm [Bar-Lev] +- Assume _LARGEFILE64_SOURCE defined is equivalent to true +- Avoid use of undefined symbols in #if with && and || +- Make *64 prototypes in gzguts.h consistent with functions +- Add -shared load option for MinGW in configure [Bowler] +- Move z_off64_t to public interface, use instead of off64_t +- Remove ! from shell test in configure (not portable to Solaris) +- Change +0 macro tests to -0 for possibly increased portability + +Changes in 1.2.4.2 (9 Apr 2010) +- Add consistent carriage returns to readme.txt's in masmx86 and masmx64 +- Really provide prototypes for *64 functions when building without LFS +- Only define unlink() in minigzip.c if unistd.h not included +- Update README to point to contrib/vstudio project files +- Move projects/vc6 to old/ and remove projects/ +- Include stdlib.h in minigzip.c for setmode() definition under WinCE +- Clean up assembler builds in win32/Makefile.msc [Rowe] +- Include sys/types.h for Microsoft for off_t definition +- Fix memory leak on error in gz_open() +- Symbolize nm as $NM in configure [Weigelt] +- Use TEST_LDSHARED instead of LDSHARED to link test programs [Weigelt] +- Add +0 to _FILE_OFFSET_BITS and _LFS64_LARGEFILE in case not defined +- Fix bug in gzeof() to take into account unused input data +- Avoid initialization of structures with variables in puff.c +- Updated win32/README-WIN32.txt [Rowe] + +Changes in 1.2.4.1 (28 Mar 2010) +- Remove the use of [a-z] constructs for sed in configure [gentoo 310225] +- Remove $(SHAREDLIB) from LIBS in Makefile.in [Creech] +- Restore "for debugging" comment on sprintf() in gzlib.c +- Remove fdopen for MVS from gzguts.h +- Put new README-WIN32.txt in win32 [Rowe] +- Add check for shell to configure and invoke another shell if needed +- Fix big fat stinking bug in gzseek() on uncompressed files +- Remove vestigial F_OPEN64 define in zutil.h +- Set and check the value of _LARGEFILE_SOURCE and _LARGEFILE64_SOURCE +- Avoid errors on non-LFS systems when applications define LFS macros +- Set EXE to ".exe" in configure for MINGW [Kahle] +- Match crc32() in crc32.c exactly to the prototype in zlib.h [Sherrill] +- Add prefix for cross-compilation in win32/makefile.gcc [Bar-Lev] +- Add DLL install in win32/makefile.gcc [Bar-Lev] +- Allow Linux* or linux* from uname in configure [Bar-Lev] +- Allow ldconfig to be redefined in configure and Makefile.in [Bar-Lev] +- Add cross-compilation prefixes to configure [Bar-Lev] +- Match type exactly in gz_load() invocation in gzread.c +- Match type exactly of zcalloc() in zutil.c to zlib.h alloc_func +- Provide prototypes for *64 functions when building zlib without LFS +- Don't use -lc when linking shared library on MinGW +- Remove errno.h check in configure and vestigial errno code in zutil.h + +Changes in 1.2.4 (14 Mar 2010) +- Fix VER3 extraction in configure for no fourth subversion +- Update zlib.3, add docs to Makefile.in to make .pdf out of it +- Add zlib.3.pdf to distribution +- Don't set error code in gzerror() if passed pointer is NULL +- Apply destination directory fixes to CMakeLists.txt [Lowman] +- Move #cmakedefine's to a new zconf.in.cmakein +- Restore zconf.h for builds that don't use configure or cmake +- Add distclean to dummy Makefile for convenience +- Update and improve INDEX, README, and FAQ +- Update CMakeLists.txt for the return of zconf.h [Lowman] +- Update contrib/vstudio/vc9 and vc10 [Vollant] +- Change libz.dll.a back to libzdll.a in win32/Makefile.gcc +- Apply license and readme changes to contrib/asm686 [Raiter] +- Check file name lengths and add -c option in minigzip.c [Li] +- Update contrib/amd64 and contrib/masmx86/ [Vollant] +- Avoid use of "eof" parameter in trees.c to not shadow library variable +- Update make_vms.com for removal of zlibdefs.h [Zinser] +- Update assembler code and vstudio projects in contrib [Vollant] +- Remove outdated assembler code contrib/masm686 and contrib/asm586 +- Remove old vc7 and vc8 from contrib/vstudio +- Update win32/Makefile.msc, add ZLIB_VER_SUBREVISION [Rowe] +- Fix memory leaks in gzclose_r() and gzclose_w(), file leak in gz_open() +- Add contrib/gcc_gvmat64 for longest_match and inflate_fast [Vollant] +- Remove *64 functions from win32/zlib.def (they're not 64-bit yet) +- Fix bug in void-returning vsprintf() case in gzwrite.c +- Fix name change from inflate.h in contrib/inflate86/inffas86.c +- Check if temporary file exists before removing in make_vms.com [Zinser] +- Fix make install and uninstall for --static option +- Fix usage of _MSC_VER in gzguts.h and zutil.h [Truta] +- Update readme.txt in contrib/masmx64 and masmx86 to assemble + +Changes in 1.2.3.9 (21 Feb 2010) +- Expunge gzio.c +- Move as400 build information to old +- Fix updates in contrib/minizip and contrib/vstudio +- Add const to vsnprintf test in configure to avoid warnings [Weigelt] +- Delete zconf.h (made by configure) [Weigelt] +- Change zconf.in.h to zconf.h.in per convention [Weigelt] +- Check for NULL buf in gzgets() +- Return empty string for gzgets() with len == 1 (like fgets()) +- Fix description of gzgets() in zlib.h for end-of-file, NULL return +- Update minizip to 1.1 [Vollant] +- Avoid MSVC loss of data warnings in gzread.c, gzwrite.c +- Note in zlib.h that gzerror() should be used to distinguish from EOF +- Remove use of snprintf() from gzlib.c +- Fix bug in gzseek() +- Update contrib/vstudio, adding vc9 and vc10 [Kuno, Vollant] +- Fix zconf.h generation in CMakeLists.txt [Lowman] +- Improve comments in zconf.h where modified by configure + +Changes in 1.2.3.8 (13 Feb 2010) +- Clean up text files (tabs, trailing whitespace, etc.) [Oberhumer] +- Use z_off64_t in gz_zero() and gz_skip() to match state->skip +- Avoid comparison problem when sizeof(int) == sizeof(z_off64_t) +- Revert to Makefile.in from 1.2.3.6 (live with the clutter) +- Fix missing error return in gzflush(), add zlib.h note +- Add *64 functions to zlib.map [Levin] +- Fix signed/unsigned comparison in gz_comp() +- Use SFLAGS when testing shared linking in configure +- Add --64 option to ./configure to use -m64 with gcc +- Fix ./configure --help to correctly name options +- Have make fail if a test fails [Levin] +- Avoid buffer overrun in contrib/masmx64/gvmat64.asm [Simpson] +- Remove assembler object files from contrib + +Changes in 1.2.3.7 (24 Jan 2010) +- Always gzopen() with O_LARGEFILE if available +- Fix gzdirect() to work immediately after gzopen() or gzdopen() +- Make gzdirect() more precise when the state changes while reading +- Improve zlib.h documentation in many places +- Catch memory allocation failure in gz_open() +- Complete close operation if seek forward in gzclose_w() fails +- Return Z_ERRNO from gzclose_r() if close() fails +- Return Z_STREAM_ERROR instead of EOF for gzclose() being passed NULL +- Return zero for gzwrite() errors to match zlib.h description +- Return -1 on gzputs() error to match zlib.h description +- Add zconf.in.h to allow recovery from configure modification [Weigelt] +- Fix static library permissions in Makefile.in [Weigelt] +- Avoid warnings in configure tests that hide functionality [Weigelt] +- Add *BSD and DragonFly to Linux case in configure [gentoo 123571] +- Change libzdll.a to libz.dll.a in win32/Makefile.gcc [gentoo 288212] +- Avoid access of uninitialized data for first inflateReset2 call [Gomes] +- Keep object files in subdirectories to reduce the clutter somewhat +- Remove default Makefile and zlibdefs.h, add dummy Makefile +- Add new external functions to Z_PREFIX, remove duplicates, z_z_ -> z_ +- Remove zlibdefs.h completely -- modify zconf.h instead + +Changes in 1.2.3.6 (17 Jan 2010) +- Avoid void * arithmetic in gzread.c and gzwrite.c +- Make compilers happier with const char * for gz_error message +- Avoid unused parameter warning in inflate.c +- Avoid signed-unsigned comparison warning in inflate.c +- Indent #pragma's for traditional C +- Fix usage of strwinerror() in glib.c, change to gz_strwinerror() +- Correct email address in configure for system options +- Update make_vms.com and add make_vms.com to contrib/minizip [Zinser] +- Update zlib.map [Brown] +- Fix Makefile.in for Solaris 10 make of example64 and minizip64 [Torok] +- Apply various fixes to CMakeLists.txt [Lowman] +- Add checks on len in gzread() and gzwrite() +- Add error message for no more room for gzungetc() +- Remove zlib version check in gzwrite() +- Defer compression of gzprintf() result until need to +- Use snprintf() in gzdopen() if available +- Remove USE_MMAP configuration determination (only used by minigzip) +- Remove examples/pigz.c (available separately) +- Update examples/gun.c to 1.6 + +Changes in 1.2.3.5 (8 Jan 2010) +- Add space after #if in zutil.h for some compilers +- Fix relatively harmless bug in deflate_fast() [Exarevsky] +- Fix same problem in deflate_slow() +- Add $(SHAREDLIBV) to LIBS in Makefile.in [Brown] +- Add deflate_rle() for faster Z_RLE strategy run-length encoding +- Add deflate_huff() for faster Z_HUFFMAN_ONLY encoding +- Change name of "write" variable in inffast.c to avoid library collisions +- Fix premature EOF from gzread() in gzio.c [Brown] +- Use zlib header window size if windowBits is 0 in inflateInit2() +- Remove compressBound() call in deflate.c to avoid linking compress.o +- Replace use of errno in gz* with functions, support WinCE [Alves] +- Provide alternative to perror() in minigzip.c for WinCE [Alves] +- Don't use _vsnprintf on later versions of MSVC [Lowman] +- Add CMake build script and input file [Lowman] +- Update contrib/minizip to 1.1 [Svensson, Vollant] +- Moved nintendods directory from contrib to . +- Replace gzio.c with a new set of routines with the same functionality +- Add gzbuffer(), gzoffset(), gzclose_r(), gzclose_w() as part of above +- Update contrib/minizip to 1.1b +- Change gzeof() to return 0 on error instead of -1 to agree with zlib.h + +Changes in 1.2.3.4 (21 Dec 2009) +- Use old school .SUFFIXES in Makefile.in for FreeBSD compatibility +- Update comments in configure and Makefile.in for default --shared +- Fix test -z's in configure [Marquess] +- Build examplesh and minigzipsh when not testing +- Change NULL's to Z_NULL's in deflate.c and in comments in zlib.h +- Import LDFLAGS from the environment in configure +- Fix configure to populate SFLAGS with discovered CFLAGS options +- Adapt make_vms.com to the new Makefile.in [Zinser] +- Add zlib2ansi script for C++ compilation [Marquess] +- Add _FILE_OFFSET_BITS=64 test to make test (when applicable) +- Add AMD64 assembler code for longest match to contrib [Teterin] +- Include options from $SFLAGS when doing $LDSHARED +- Simplify 64-bit file support by introducing z_off64_t type +- Make shared object files in objs directory to work around old Sun cc +- Use only three-part version number for Darwin shared compiles +- Add rc option to ar in Makefile.in for when ./configure not run +- Add -WI,-rpath,. to LDFLAGS for OSF 1 V4* +- Set LD_LIBRARYN32_PATH for SGI IRIX shared compile +- Protect against _FILE_OFFSET_BITS being defined when compiling zlib +- Rename Makefile.in targets allstatic to static and allshared to shared +- Fix static and shared Makefile.in targets to be independent +- Correct error return bug in gz_open() by setting state [Brown] +- Put spaces before ;;'s in configure for better sh compatibility +- Add pigz.c (parallel implementation of gzip) to examples/ +- Correct constant in crc32.c to UL [Leventhal] +- Reject negative lengths in crc32_combine() +- Add inflateReset2() function to work like inflateEnd()/inflateInit2() +- Include sys/types.h for _LARGEFILE64_SOURCE [Brown] +- Correct typo in doc/algorithm.txt [Janik] +- Fix bug in adler32_combine() [Zhu] +- Catch missing-end-of-block-code error in all inflates and in puff + Assures that random input to inflate eventually results in an error +- Added enough.c (calculation of ENOUGH for inftrees.h) to examples/ +- Update ENOUGH and its usage to reflect discovered bounds +- Fix gzerror() error report on empty input file [Brown] +- Add ush casts in trees.c to avoid pedantic runtime errors +- Fix typo in zlib.h uncompress() description [Reiss] +- Correct inflate() comments with regard to automatic header detection +- Remove deprecation comment on Z_PARTIAL_FLUSH (it stays) +- Put new version of gzlog (2.0) in examples with interruption recovery +- Add puff compile option to permit invalid distance-too-far streams +- Add puff TEST command options, ability to read piped input +- Prototype the *64 functions in zlib.h when _FILE_OFFSET_BITS == 64, but + _LARGEFILE64_SOURCE not defined +- Fix Z_FULL_FLUSH to truly erase the past by resetting s->strstart +- Fix deflateSetDictionary() to use all 32K for output consistency +- Remove extraneous #define MIN_LOOKAHEAD in deflate.c (in deflate.h) +- Clear bytes after deflate lookahead to avoid use of uninitialized data +- Change a limit in inftrees.c to be more transparent to Coverity Prevent +- Update win32/zlib.def with exported symbols from zlib.h +- Correct spelling errors in zlib.h [Willem, Sobrado] +- Allow Z_BLOCK for deflate() to force a new block +- Allow negative bits in inflatePrime() to delete existing bit buffer +- Add Z_TREES flush option to inflate() to return at end of trees +- Add inflateMark() to return current state information for random access +- Add Makefile for NintendoDS to contrib [Costa] +- Add -w in configure compile tests to avoid spurious warnings [Beucler] +- Fix typos in zlib.h comments for deflateSetDictionary() +- Fix EOF detection in transparent gzread() [Maier] + +Changes in 1.2.3.3 (2 October 2006) +- Make --shared the default for configure, add a --static option +- Add compile option to permit invalid distance-too-far streams +- Add inflateUndermine() function which is required to enable above +- Remove use of "this" variable name for C++ compatibility [Marquess] +- Add testing of shared library in make test, if shared library built +- Use ftello() and fseeko() if available instead of ftell() and fseek() +- Provide two versions of all functions that use the z_off_t type for + binary compatibility -- a normal version and a 64-bit offset version, + per the Large File Support Extension when _LARGEFILE64_SOURCE is + defined; use the 64-bit versions by default when _FILE_OFFSET_BITS + is defined to be 64 +- Add a --uname= option to configure to perhaps help with cross-compiling + +Changes in 1.2.3.2 (3 September 2006) +- Turn off silly Borland warnings [Hay] +- Use off64_t and define _LARGEFILE64_SOURCE when present +- Fix missing dependency on inffixed.h in Makefile.in +- Rig configure --shared to build both shared and static [Teredesai, Truta] +- Remove zconf.in.h and instead create a new zlibdefs.h file +- Fix contrib/minizip/unzip.c non-encrypted after encrypted [Vollant] +- Add treebuild.xml (see http://treebuild.metux.de/) [Weigelt] + +Changes in 1.2.3.1 (16 August 2006) +- Add watcom directory with OpenWatcom make files [Daniel] +- Remove #undef of FAR in zconf.in.h for MVS [Fedtke] +- Update make_vms.com [Zinser] +- Use -fPIC for shared build in configure [Teredesai, Nicholson] +- Use only major version number for libz.so on IRIX and OSF1 [Reinholdtsen] +- Use fdopen() (not _fdopen()) for Interix in zutil.h [BŠck] +- Add some FAQ entries about the contrib directory +- Update the MVS question in the FAQ +- Avoid extraneous reads after EOF in gzio.c [Brown] +- Correct spelling of "successfully" in gzio.c [Randers-Pehrson] +- Add comments to zlib.h about gzerror() usage [Brown] +- Set extra flags in gzip header in gzopen() like deflate() does +- Make configure options more compatible with double-dash conventions + [Weigelt] +- Clean up compilation under Solaris SunStudio cc [Rowe, Reinholdtsen] +- Fix uninstall target in Makefile.in [Truta] +- Add pkgconfig support [Weigelt] +- Use $(DESTDIR) macro in Makefile.in [Reinholdtsen, Weigelt] +- Replace set_data_type() with a more accurate detect_data_type() in + trees.c, according to the txtvsbin.txt document [Truta] +- Swap the order of #include and #include "zlib.h" in + gzio.c, example.c and minigzip.c [Truta] +- Shut up annoying VS2005 warnings about standard C deprecation [Rowe, + Truta] (where?) +- Fix target "clean" from win32/Makefile.bor [Truta] +- Create .pdb and .manifest files in win32/makefile.msc [Ziegler, Rowe] +- Update zlib www home address in win32/DLL_FAQ.txt [Truta] +- Update contrib/masmx86/inffas32.asm for VS2005 [Vollant, Van Wassenhove] +- Enable browse info in the "Debug" and "ASM Debug" configurations in + the Visual C++ 6 project, and set (non-ASM) "Debug" as default [Truta] +- Add pkgconfig support [Weigelt] +- Add ZLIB_VER_MAJOR, ZLIB_VER_MINOR and ZLIB_VER_REVISION in zlib.h, + for use in win32/zlib1.rc [Polushin, Rowe, Truta] +- Add a document that explains the new text detection scheme to + doc/txtvsbin.txt [Truta] +- Add rfc1950.txt, rfc1951.txt and rfc1952.txt to doc/ [Truta] +- Move algorithm.txt into doc/ [Truta] +- Synchronize FAQ with website +- Fix compressBound(), was low for some pathological cases [Fearnley] +- Take into account wrapper variations in deflateBound() +- Set examples/zpipe.c input and output to binary mode for Windows +- Update examples/zlib_how.html with new zpipe.c (also web site) +- Fix some warnings in examples/gzlog.c and examples/zran.c (it seems + that gcc became pickier in 4.0) +- Add zlib.map for Linux: "All symbols from zlib-1.1.4 remain + un-versioned, the patch adds versioning only for symbols introduced in + zlib-1.2.0 or later. It also declares as local those symbols which are + not designed to be exported." [Levin] +- Update Z_PREFIX list in zconf.in.h, add --zprefix option to configure +- Do not initialize global static by default in trees.c, add a response + NO_INIT_GLOBAL_POINTERS to initialize them if needed [Marquess] +- Don't use strerror() in gzio.c under WinCE [Yakimov] +- Don't use errno.h in zutil.h under WinCE [Yakimov] +- Move arguments for AR to its usage to allow replacing ar [Marot] +- Add HAVE_VISIBILITY_PRAGMA in zconf.in.h for Mozilla [Randers-Pehrson] +- Improve inflateInit() and inflateInit2() documentation +- Fix structure size comment in inflate.h +- Change configure help option from --h* to --help [Santos] + +Changes in 1.2.3 (18 July 2005) +- Apply security vulnerability fixes to contrib/infback9 as well +- Clean up some text files (carriage returns, trailing space) +- Update testzlib, vstudio, masmx64, and masmx86 in contrib [Vollant] + +Changes in 1.2.2.4 (11 July 2005) +- Add inflatePrime() function for starting inflation at bit boundary +- Avoid some Visual C warnings in deflate.c +- Avoid more silly Visual C warnings in inflate.c and inftrees.c for 64-bit + compile +- Fix some spelling errors in comments [Betts] +- Correct inflateInit2() error return documentation in zlib.h +- Add zran.c example of compressed data random access to examples + directory, shows use of inflatePrime() +- Fix cast for assignments to strm->state in inflate.c and infback.c +- Fix zlibCompileFlags() in zutil.c to use 1L for long shifts [Oberhumer] +- Move declarations of gf2 functions to right place in crc32.c [Oberhumer] +- Add cast in trees.c t avoid a warning [Oberhumer] +- Avoid some warnings in fitblk.c, gun.c, gzjoin.c in examples [Oberhumer] +- Update make_vms.com [Zinser] +- Initialize state->write in inflateReset() since copied in inflate_fast() +- Be more strict on incomplete code sets in inflate_table() and increase + ENOUGH and MAXD -- this repairs a possible security vulnerability for + invalid inflate input. Thanks to Tavis Ormandy and Markus Oberhumer for + discovering the vulnerability and providing test cases. +- Add ia64 support to configure for HP-UX [Smith] +- Add error return to gzread() for format or i/o error [Levin] +- Use malloc.h for OS/2 [Necasek] + +Changes in 1.2.2.3 (27 May 2005) +- Replace 1U constants in inflate.c and inftrees.c for 64-bit compile +- Typecast fread() return values in gzio.c [Vollant] +- Remove trailing space in minigzip.c outmode (VC++ can't deal with it) +- Fix crc check bug in gzread() after gzungetc() [Heiner] +- Add the deflateTune() function to adjust internal compression parameters +- Add a fast gzip decompressor, gun.c, to examples (use of inflateBack) +- Remove an incorrect assertion in examples/zpipe.c +- Add C++ wrapper in infback9.h [Donais] +- Fix bug in inflateCopy() when decoding fixed codes +- Note in zlib.h how much deflateSetDictionary() actually uses +- Remove USE_DICT_HEAD in deflate.c (would mess up inflate if used) +- Add _WIN32_WCE to define WIN32 in zconf.in.h [Spencer] +- Don't include stderr.h or errno.h for _WIN32_WCE in zutil.h [Spencer] +- Add gzdirect() function to indicate transparent reads +- Update contrib/minizip [Vollant] +- Fix compilation of deflate.c when both ASMV and FASTEST [Oberhumer] +- Add casts in crc32.c to avoid warnings [Oberhumer] +- Add contrib/masmx64 [Vollant] +- Update contrib/asm586, asm686, masmx86, testzlib, vstudio [Vollant] + +Changes in 1.2.2.2 (30 December 2004) +- Replace structure assignments in deflate.c and inflate.c with zmemcpy to + avoid implicit memcpy calls (portability for no-library compilation) +- Increase sprintf() buffer size in gzdopen() to allow for large numbers +- Add INFLATE_STRICT to check distances against zlib header +- Improve WinCE errno handling and comments [Chang] +- Remove comment about no gzip header processing in FAQ +- Add Z_FIXED strategy option to deflateInit2() to force fixed trees +- Add updated make_vms.com [Coghlan], update README +- Create a new "examples" directory, move gzappend.c there, add zpipe.c, + fitblk.c, gzlog.[ch], gzjoin.c, and zlib_how.html. +- Add FAQ entry and comments in deflate.c on uninitialized memory access +- Add Solaris 9 make options in configure [Gilbert] +- Allow strerror() usage in gzio.c for STDC +- Fix DecompressBuf in contrib/delphi/ZLib.pas [ManChesTer] +- Update contrib/masmx86/inffas32.asm and gvmat32.asm [Vollant] +- Use z_off_t for adler32_combine() and crc32_combine() lengths +- Make adler32() much faster for small len +- Use OS_CODE in deflate() default gzip header + +Changes in 1.2.2.1 (31 October 2004) +- Allow inflateSetDictionary() call for raw inflate +- Fix inflate header crc check bug for file names and comments +- Add deflateSetHeader() and gz_header structure for custom gzip headers +- Add inflateGetheader() to retrieve gzip headers +- Add crc32_combine() and adler32_combine() functions +- Add alloc_func, free_func, in_func, out_func to Z_PREFIX list +- Use zstreamp consistently in zlib.h (inflate_back functions) +- Remove GUNZIP condition from definition of inflate_mode in inflate.h + and in contrib/inflate86/inffast.S [Truta, Anderson] +- Add support for AMD64 in contrib/inflate86/inffas86.c [Anderson] +- Update projects/README.projects and projects/visualc6 [Truta] +- Update win32/DLL_FAQ.txt [Truta] +- Avoid warning under NO_GZCOMPRESS in gzio.c; fix typo [Truta] +- Deprecate Z_ASCII; use Z_TEXT instead [Truta] +- Use a new algorithm for setting strm->data_type in trees.c [Truta] +- Do not define an exit() prototype in zutil.c unless DEBUG defined +- Remove prototype of exit() from zutil.c, example.c, minigzip.c [Truta] +- Add comment in zlib.h for Z_NO_FLUSH parameter to deflate() +- Fix Darwin build version identification [Peterson] + +Changes in 1.2.2 (3 October 2004) +- Update zlib.h comments on gzip in-memory processing +- Set adler to 1 in inflateReset() to support Java test suite [Walles] +- Add contrib/dotzlib [Ravn] +- Update win32/DLL_FAQ.txt [Truta] +- Update contrib/minizip [Vollant] +- Move contrib/visual-basic.txt to old/ [Truta] +- Fix assembler builds in projects/visualc6/ [Truta] + +Changes in 1.2.1.2 (9 September 2004) +- Update INDEX file +- Fix trees.c to update strm->data_type (no one ever noticed!) +- Fix bug in error case in inflate.c, infback.c, and infback9.c [Brown] +- Add "volatile" to crc table flag declaration (for DYNAMIC_CRC_TABLE) +- Add limited multitasking protection to DYNAMIC_CRC_TABLE +- Add NO_vsnprintf for VMS in zutil.h [Mozilla] +- Don't declare strerror() under VMS [Mozilla] +- Add comment to DYNAMIC_CRC_TABLE to use get_crc_table() to initialize +- Update contrib/ada [Anisimkov] +- Update contrib/minizip [Vollant] +- Fix configure to not hardcode directories for Darwin [Peterson] +- Fix gzio.c to not return error on empty files [Brown] +- Fix indentation; update version in contrib/delphi/ZLib.pas and + contrib/pascal/zlibpas.pas [Truta] +- Update mkasm.bat in contrib/masmx86 [Truta] +- Update contrib/untgz [Truta] +- Add projects/README.projects [Truta] +- Add project for MS Visual C++ 6.0 in projects/visualc6 [Cadieux, Truta] +- Update win32/DLL_FAQ.txt [Truta] +- Update list of Z_PREFIX symbols in zconf.h [Randers-Pehrson, Truta] +- Remove an unnecessary assignment to curr in inftrees.c [Truta] +- Add OS/2 to exe builds in configure [Poltorak] +- Remove err dummy parameter in zlib.h [Kientzle] + +Changes in 1.2.1.1 (9 January 2004) +- Update email address in README +- Several FAQ updates +- Fix a big fat bug in inftrees.c that prevented decoding valid + dynamic blocks with only literals and no distance codes -- + Thanks to "Hot Emu" for the bug report and sample file +- Add a note to puff.c on no distance codes case. + +Changes in 1.2.1 (17 November 2003) +- Remove a tab in contrib/gzappend/gzappend.c +- Update some interfaces in contrib for new zlib functions +- Update zlib version number in some contrib entries +- Add Windows CE definition for ptrdiff_t in zutil.h [Mai, Truta] +- Support shared libraries on Hurd and KFreeBSD [Brown] +- Fix error in NO_DIVIDE option of adler32.c + +Changes in 1.2.0.8 (4 November 2003) +- Update version in contrib/delphi/ZLib.pas and contrib/pascal/zlibpas.pas +- Add experimental NO_DIVIDE #define in adler32.c + - Possibly faster on some processors (let me know if it is) +- Correct Z_BLOCK to not return on first inflate call if no wrap +- Fix strm->data_type on inflate() return to correctly indicate EOB +- Add deflatePrime() function for appending in the middle of a byte +- Add contrib/gzappend for an example of appending to a stream +- Update win32/DLL_FAQ.txt [Truta] +- Delete Turbo C comment in README [Truta] +- Improve some indentation in zconf.h [Truta] +- Fix infinite loop on bad input in configure script [Church] +- Fix gzeof() for concatenated gzip files [Johnson] +- Add example to contrib/visual-basic.txt [Michael B.] +- Add -p to mkdir's in Makefile.in [vda] +- Fix configure to properly detect presence or lack of printf functions +- Add AS400 support [Monnerat] +- Add a little Cygwin support [Wilson] + +Changes in 1.2.0.7 (21 September 2003) +- Correct some debug formats in contrib/infback9 +- Cast a type in a debug statement in trees.c +- Change search and replace delimiter in configure from % to # [Beebe] +- Update contrib/untgz to 0.2 with various fixes [Truta] +- Add build support for Amiga [Nikl] +- Remove some directories in old that have been updated to 1.2 +- Add dylib building for Mac OS X in configure and Makefile.in +- Remove old distribution stuff from Makefile +- Update README to point to DLL_FAQ.txt, and add comment on Mac OS X +- Update links in README + +Changes in 1.2.0.6 (13 September 2003) +- Minor FAQ updates +- Update contrib/minizip to 1.00 [Vollant] +- Remove test of gz functions in example.c when GZ_COMPRESS defined [Truta] +- Update POSTINC comment for 68060 [Nikl] +- Add contrib/infback9 with deflate64 decoding (unsupported) +- For MVS define NO_vsnprintf and undefine FAR [van Burik] +- Add pragma for fdopen on MVS [van Burik] + +Changes in 1.2.0.5 (8 September 2003) +- Add OF to inflateBackEnd() declaration in zlib.h +- Remember start when using gzdopen in the middle of a file +- Use internal off_t counters in gz* functions to properly handle seeks +- Perform more rigorous check for distance-too-far in inffast.c +- Add Z_BLOCK flush option to return from inflate at block boundary +- Set strm->data_type on return from inflate + - Indicate bits unused, if at block boundary, and if in last block +- Replace size_t with ptrdiff_t in crc32.c, and check for correct size +- Add condition so old NO_DEFLATE define still works for compatibility +- FAQ update regarding the Windows DLL [Truta] +- INDEX update: add qnx entry, remove aix entry [Truta] +- Install zlib.3 into mandir [Wilson] +- Move contrib/zlib_dll_FAQ.txt to win32/DLL_FAQ.txt; update [Truta] +- Adapt the zlib interface to the new DLL convention guidelines [Truta] +- Introduce ZLIB_WINAPI macro to allow the export of functions using + the WINAPI calling convention, for Visual Basic [Vollant, Truta] +- Update msdos and win32 scripts and makefiles [Truta] +- Export symbols by name, not by ordinal, in win32/zlib.def [Truta] +- Add contrib/ada [Anisimkov] +- Move asm files from contrib/vstudio/vc70_32 to contrib/asm386 [Truta] +- Rename contrib/asm386 to contrib/masmx86 [Truta, Vollant] +- Add contrib/masm686 [Truta] +- Fix offsets in contrib/inflate86 and contrib/masmx86/inffas32.asm + [Truta, Vollant] +- Update contrib/delphi; rename to contrib/pascal; add example [Truta] +- Remove contrib/delphi2; add a new contrib/delphi [Truta] +- Avoid inclusion of the nonstandard in contrib/iostream, + and fix some method prototypes [Truta] +- Fix the ZCR_SEED2 constant to avoid warnings in contrib/minizip + [Truta] +- Avoid the use of backslash (\) in contrib/minizip [Vollant] +- Fix file time handling in contrib/untgz; update makefiles [Truta] +- Update contrib/vstudio/vc70_32 to comply with the new DLL guidelines + [Vollant] +- Remove contrib/vstudio/vc15_16 [Vollant] +- Rename contrib/vstudio/vc70_32 to contrib/vstudio/vc7 [Truta] +- Update README.contrib [Truta] +- Invert the assignment order of match_head and s->prev[...] in + INSERT_STRING [Truta] +- Compare TOO_FAR with 32767 instead of 32768, to avoid 16-bit warnings + [Truta] +- Compare function pointers with 0, not with NULL or Z_NULL [Truta] +- Fix prototype of syncsearch in inflate.c [Truta] +- Introduce ASMINF macro to be enabled when using an ASM implementation + of inflate_fast [Truta] +- Change NO_DEFLATE to NO_GZCOMPRESS [Truta] +- Modify test_gzio in example.c to take a single file name as a + parameter [Truta] +- Exit the example.c program if gzopen fails [Truta] +- Add type casts around strlen in example.c [Truta] +- Remove casting to sizeof in minigzip.c; give a proper type + to the variable compared with SUFFIX_LEN [Truta] +- Update definitions of STDC and STDC99 in zconf.h [Truta] +- Synchronize zconf.h with the new Windows DLL interface [Truta] +- Use SYS16BIT instead of __32BIT__ to distinguish between + 16- and 32-bit platforms [Truta] +- Use far memory allocators in small 16-bit memory models for + Turbo C [Truta] +- Add info about the use of ASMV, ASMINF and ZLIB_WINAPI in + zlibCompileFlags [Truta] +- Cygwin has vsnprintf [Wilson] +- In Windows16, OS_CODE is 0, as in MSDOS [Truta] +- In Cygwin, OS_CODE is 3 (Unix), not 11 (Windows32) [Wilson] + +Changes in 1.2.0.4 (10 August 2003) +- Minor FAQ updates +- Be more strict when checking inflateInit2's windowBits parameter +- Change NO_GUNZIP compile option to NO_GZIP to cover deflate as well +- Add gzip wrapper option to deflateInit2 using windowBits +- Add updated QNX rule in configure and qnx directory [Bonnefoy] +- Make inflate distance-too-far checks more rigorous +- Clean up FAR usage in inflate +- Add casting to sizeof() in gzio.c and minigzip.c + +Changes in 1.2.0.3 (19 July 2003) +- Fix silly error in gzungetc() implementation [Vollant] +- Update contrib/minizip and contrib/vstudio [Vollant] +- Fix printf format in example.c +- Correct cdecl support in zconf.in.h [Anisimkov] +- Minor FAQ updates + +Changes in 1.2.0.2 (13 July 2003) +- Add ZLIB_VERNUM in zlib.h for numerical preprocessor comparisons +- Attempt to avoid warnings in crc32.c for pointer-int conversion +- Add AIX to configure, remove aix directory [Bakker] +- Add some casts to minigzip.c +- Improve checking after insecure sprintf() or vsprintf() calls +- Remove #elif's from crc32.c +- Change leave label to inf_leave in inflate.c and infback.c to avoid + library conflicts +- Remove inflate gzip decoding by default--only enable gzip decoding by + special request for stricter backward compatibility +- Add zlibCompileFlags() function to return compilation information +- More typecasting in deflate.c to avoid warnings +- Remove leading underscore from _Capital #defines [Truta] +- Fix configure to link shared library when testing +- Add some Windows CE target adjustments [Mai] +- Remove #define ZLIB_DLL in zconf.h [Vollant] +- Add zlib.3 [Rodgers] +- Update RFC URL in deflate.c and algorithm.txt [Mai] +- Add zlib_dll_FAQ.txt to contrib [Truta] +- Add UL to some constants [Truta] +- Update minizip and vstudio [Vollant] +- Remove vestigial NEED_DUMMY_RETURN from zconf.in.h +- Expand use of NO_DUMMY_DECL to avoid all dummy structures +- Added iostream3 to contrib [Schwardt] +- Replace rewind() with fseek() for WinCE [Truta] +- Improve setting of zlib format compression level flags + - Report 0 for huffman and rle strategies and for level == 0 or 1 + - Report 2 only for level == 6 +- Only deal with 64K limit when necessary at compile time [Truta] +- Allow TOO_FAR check to be turned off at compile time [Truta] +- Add gzclearerr() function [Souza] +- Add gzungetc() function + +Changes in 1.2.0.1 (17 March 2003) +- Add Z_RLE strategy for run-length encoding [Truta] + - When Z_RLE requested, restrict matches to distance one + - Update zlib.h, minigzip.c, gzopen(), gzdopen() for Z_RLE +- Correct FASTEST compilation to allow level == 0 +- Clean up what gets compiled for FASTEST +- Incorporate changes to zconf.in.h [Vollant] + - Refine detection of Turbo C need for dummy returns + - Refine ZLIB_DLL compilation + - Include additional header file on VMS for off_t typedef +- Try to use _vsnprintf where it supplants vsprintf [Vollant] +- Add some casts in inffast.c +- Enchance comments in zlib.h on what happens if gzprintf() tries to + write more than 4095 bytes before compression +- Remove unused state from inflateBackEnd() +- Remove exit(0) from minigzip.c, example.c +- Get rid of all those darn tabs +- Add "check" target to Makefile.in that does the same thing as "test" +- Add "mostlyclean" and "maintainer-clean" targets to Makefile.in +- Update contrib/inflate86 [Anderson] +- Update contrib/testzlib, contrib/vstudio, contrib/minizip [Vollant] +- Add msdos and win32 directories with makefiles [Truta] +- More additions and improvements to the FAQ + +Changes in 1.2.0 (9 March 2003) +- New and improved inflate code + - About 20% faster + - Does not allocate 32K window unless and until needed + - Automatically detects and decompresses gzip streams + - Raw inflate no longer needs an extra dummy byte at end + - Added inflateBack functions using a callback interface--even faster + than inflate, useful for file utilities (gzip, zip) + - Added inflateCopy() function to record state for random access on + externally generated deflate streams (e.g. in gzip files) + - More readable code (I hope) +- New and improved crc32() + - About 50% faster, thanks to suggestions from Rodney Brown +- Add deflateBound() and compressBound() functions +- Fix memory leak in deflateInit2() +- Permit setting dictionary for raw deflate (for parallel deflate) +- Fix const declaration for gzwrite() +- Check for some malloc() failures in gzio.c +- Fix bug in gzopen() on single-byte file 0x1f +- Fix bug in gzread() on concatenated file with 0x1f at end of buffer + and next buffer doesn't start with 0x8b +- Fix uncompress() to return Z_DATA_ERROR on truncated input +- Free memory at end of example.c +- Remove MAX #define in trees.c (conflicted with some libraries) +- Fix static const's in deflate.c, gzio.c, and zutil.[ch] +- Declare malloc() and free() in gzio.c if STDC not defined +- Use malloc() instead of calloc() in zutil.c if int big enough +- Define STDC for AIX +- Add aix/ with approach for compiling shared library on AIX +- Add HP-UX support for shared libraries in configure +- Add OpenUNIX support for shared libraries in configure +- Use $cc instead of gcc to build shared library +- Make prefix directory if needed when installing +- Correct Macintosh avoidance of typedef Byte in zconf.h +- Correct Turbo C memory allocation when under Linux +- Use libz.a instead of -lz in Makefile (assure use of compiled library) +- Update configure to check for snprintf or vsnprintf functions and their + return value, warn during make if using an insecure function +- Fix configure problem with compile-time knowledge of HAVE_UNISTD_H that + is lost when library is used--resolution is to build new zconf.h +- Documentation improvements (in zlib.h): + - Document raw deflate and inflate + - Update RFCs URL + - Point out that zlib and gzip formats are different + - Note that Z_BUF_ERROR is not fatal + - Document string limit for gzprintf() and possible buffer overflow + - Note requirement on avail_out when flushing + - Note permitted values of flush parameter of inflate() +- Add some FAQs (and even answers) to the FAQ +- Add contrib/inflate86/ for x86 faster inflate +- Add contrib/blast/ for PKWare Data Compression Library decompression +- Add contrib/puff/ simple inflate for deflate format description + +Changes in 1.1.4 (11 March 2002) +- ZFREE was repeated on same allocation on some error conditions. + This creates a security problem described in + http://www.zlib.org/advisory-2002-03-11.txt +- Returned incorrect error (Z_MEM_ERROR) on some invalid data +- Avoid accesses before window for invalid distances with inflate window + less than 32K. +- force windowBits > 8 to avoid a bug in the encoder for a window size + of 256 bytes. (A complete fix will be available in 1.1.5). + +Changes in 1.1.3 (9 July 1998) +- fix "an inflate input buffer bug that shows up on rare but persistent + occasions" (Mark) +- fix gzread and gztell for concatenated .gz files (Didier Le Botlan) +- fix gzseek(..., SEEK_SET) in write mode +- fix crc check after a gzeek (Frank Faubert) +- fix miniunzip when the last entry in a zip file is itself a zip file + (J Lillge) +- add contrib/asm586 and contrib/asm686 (Brian Raiter) + See http://www.muppetlabs.com/~breadbox/software/assembly.html +- add support for Delphi 3 in contrib/delphi (Bob Dellaca) +- add support for C++Builder 3 and Delphi 3 in contrib/delphi2 (Davide Moretti) +- do not exit prematurely in untgz if 0 at start of block (Magnus Holmgren) +- use macro EXTERN instead of extern to support DLL for BeOS (Sander Stoks) +- added a FAQ file + +- Support gzdopen on Mac with Metrowerks (Jason Linhart) +- Do not redefine Byte on Mac (Brad Pettit & Jason Linhart) +- define SEEK_END too if SEEK_SET is not defined (Albert Chin-A-Young) +- avoid some warnings with Borland C (Tom Tanner) +- fix a problem in contrib/minizip/zip.c for 16-bit MSDOS (Gilles Vollant) +- emulate utime() for WIN32 in contrib/untgz (Gilles Vollant) +- allow several arguments to configure (Tim Mooney, Frodo Looijaard) +- use libdir and includedir in Makefile.in (Tim Mooney) +- support shared libraries on OSF1 V4 (Tim Mooney) +- remove so_locations in "make clean" (Tim Mooney) +- fix maketree.c compilation error (Glenn, Mark) +- Python interface to zlib now in Python 1.5 (Jeremy Hylton) +- new Makefile.riscos (Rich Walker) +- initialize static descriptors in trees.c for embedded targets (Nick Smith) +- use "foo-gz" in example.c for RISCOS and VMS (Nick Smith) +- add the OS/2 files in Makefile.in too (Andrew Zabolotny) +- fix fdopen and halloc macros for Microsoft C 6.0 (Tom Lane) +- fix maketree.c to allow clean compilation of inffixed.h (Mark) +- fix parameter check in deflateCopy (Gunther Nikl) +- cleanup trees.c, use compressed_len only in debug mode (Christian Spieler) +- Many portability patches by Christian Spieler: + . zutil.c, zutil.h: added "const" for zmem* + . Make_vms.com: fixed some typos + . Make_vms.com: msdos/Makefile.*: removed zutil.h from some dependency lists + . msdos/Makefile.msc: remove "default rtl link library" info from obj files + . msdos/Makefile.*: use model-dependent name for the built zlib library + . msdos/Makefile.emx, nt/Makefile.emx, nt/Makefile.gcc: + new makefiles, for emx (DOS/OS2), emx&rsxnt and mingw32 (Windows 9x / NT) +- use define instead of typedef for Bytef also for MSC small/medium (Tom Lane) +- replace __far with _far for better portability (Christian Spieler, Tom Lane) +- fix test for errno.h in configure (Tim Newsham) + +Changes in 1.1.2 (19 March 98) +- added contrib/minzip, mini zip and unzip based on zlib (Gilles Vollant) + See http://www.winimage.com/zLibDll/unzip.html +- preinitialize the inflate tables for fixed codes, to make the code + completely thread safe (Mark) +- some simplifications and slight speed-up to the inflate code (Mark) +- fix gzeof on non-compressed files (Allan Schrum) +- add -std1 option in configure for OSF1 to fix gzprintf (Martin Mokrejs) +- use default value of 4K for Z_BUFSIZE for 16-bit MSDOS (Tim Wegner + Glenn) +- added os2/Makefile.def and os2/zlib.def (Andrew Zabolotny) +- add shared lib support for UNIX_SV4.2MP (MATSUURA Takanori) +- do not wrap extern "C" around system includes (Tom Lane) +- mention zlib binding for TCL in README (Andreas Kupries) +- added amiga/Makefile.pup for Amiga powerUP SAS/C PPC (Andreas Kleinert) +- allow "make install prefix=..." even after configure (Glenn Randers-Pehrson) +- allow "configure --prefix $HOME" (Tim Mooney) +- remove warnings in example.c and gzio.c (Glenn Randers-Pehrson) +- move Makefile.sas to amiga/Makefile.sas + +Changes in 1.1.1 (27 Feb 98) +- fix macros _tr_tally_* in deflate.h for debug mode (Glenn Randers-Pehrson) +- remove block truncation heuristic which had very marginal effect for zlib + (smaller lit_bufsize than in gzip 1.2.4) and degraded a little the + compression ratio on some files. This also allows inlining _tr_tally for + matches in deflate_slow. +- added msdos/Makefile.w32 for WIN32 Microsoft Visual C++ (Bob Frazier) + +Changes in 1.1.0 (24 Feb 98) +- do not return STREAM_END prematurely in inflate (John Bowler) +- revert to the zlib 1.0.8 inflate to avoid the gcc 2.8.0 bug (Jeremy Buhler) +- compile with -DFASTEST to get compression code optimized for speed only +- in minigzip, try mmap'ing the input file first (Miguel Albrecht) +- increase size of I/O buffers in minigzip.c and gzio.c (not a big gain + on Sun but significant on HP) + +- add a pointer to experimental unzip library in README (Gilles Vollant) +- initialize variable gcc in configure (Chris Herborth) + +Changes in 1.0.9 (17 Feb 1998) +- added gzputs and gzgets functions +- do not clear eof flag in gzseek (Mark Diekhans) +- fix gzseek for files in transparent mode (Mark Diekhans) +- do not assume that vsprintf returns the number of bytes written (Jens Krinke) +- replace EXPORT with ZEXPORT to avoid conflict with other programs +- added compress2 in zconf.h, zlib.def, zlib.dnt +- new asm code from Gilles Vollant in contrib/asm386 +- simplify the inflate code (Mark): + . Replace ZALLOC's in huft_build() with single ZALLOC in inflate_blocks_new() + . ZALLOC the length list in inflate_trees_fixed() instead of using stack + . ZALLOC the value area for huft_build() instead of using stack + . Simplify Z_FINISH check in inflate() + +- Avoid gcc 2.8.0 comparison bug a little differently than zlib 1.0.8 +- in inftrees.c, avoid cc -O bug on HP (Farshid Elahi) +- in zconf.h move the ZLIB_DLL stuff earlier to avoid problems with + the declaration of FAR (Gilles VOllant) +- install libz.so* with mode 755 (executable) instead of 644 (Marc Lehmann) +- read_buf buf parameter of type Bytef* instead of charf* +- zmemcpy parameters are of type Bytef*, not charf* (Joseph Strout) +- do not redeclare unlink in minigzip.c for WIN32 (John Bowler) +- fix check for presence of directories in "make install" (Ian Willis) + +Changes in 1.0.8 (27 Jan 1998) +- fixed offsets in contrib/asm386/gvmat32.asm (Gilles Vollant) +- fix gzgetc and gzputc for big endian systems (Markus Oberhumer) +- added compress2() to allow setting the compression level +- include sys/types.h to get off_t on some systems (Marc Lehmann & QingLong) +- use constant arrays for the static trees in trees.c instead of computing + them at run time (thanks to Ken Raeburn for this suggestion). To create + trees.h, compile with GEN_TREES_H and run "make test". +- check return code of example in "make test" and display result +- pass minigzip command line options to file_compress +- simplifying code of inflateSync to avoid gcc 2.8 bug + +- support CC="gcc -Wall" in configure -s (QingLong) +- avoid a flush caused by ftell in gzopen for write mode (Ken Raeburn) +- fix test for shared library support to avoid compiler warnings +- zlib.lib -> zlib.dll in msdos/zlib.rc (Gilles Vollant) +- check for TARGET_OS_MAC in addition to MACOS (Brad Pettit) +- do not use fdopen for Metrowerks on Mac (Brad Pettit)) +- add checks for gzputc and gzputc in example.c +- avoid warnings in gzio.c and deflate.c (Andreas Kleinert) +- use const for the CRC table (Ken Raeburn) +- fixed "make uninstall" for shared libraries +- use Tracev instead of Trace in infblock.c +- in example.c use correct compressed length for test_sync +- suppress +vnocompatwarnings in configure for HPUX (not always supported) + +Changes in 1.0.7 (20 Jan 1998) +- fix gzseek which was broken in write mode +- return error for gzseek to negative absolute position +- fix configure for Linux (Chun-Chung Chen) +- increase stack space for MSC (Tim Wegner) +- get_crc_table and inflateSyncPoint are EXPORTed (Gilles Vollant) +- define EXPORTVA for gzprintf (Gilles Vollant) +- added man page zlib.3 (Rick Rodgers) +- for contrib/untgz, fix makedir() and improve Makefile + +- check gzseek in write mode in example.c +- allocate extra buffer for seeks only if gzseek is actually called +- avoid signed/unsigned comparisons (Tim Wegner, Gilles Vollant) +- add inflateSyncPoint in zconf.h +- fix list of exported functions in nt/zlib.dnt and mdsos/zlib.def + +Changes in 1.0.6 (19 Jan 1998) +- add functions gzprintf, gzputc, gzgetc, gztell, gzeof, gzseek, gzrewind and + gzsetparams (thanks to Roland Giersig and Kevin Ruland for some of this code) +- Fix a deflate bug occurring only with compression level 0 (thanks to + Andy Buckler for finding this one). +- In minigzip, pass transparently also the first byte for .Z files. +- return Z_BUF_ERROR instead of Z_OK if output buffer full in uncompress() +- check Z_FINISH in inflate (thanks to Marc Schluper) +- Implement deflateCopy (thanks to Adam Costello) +- make static libraries by default in configure, add --shared option. +- move MSDOS or Windows specific files to directory msdos +- suppress the notion of partial flush to simplify the interface + (but the symbol Z_PARTIAL_FLUSH is kept for compatibility with 1.0.4) +- suppress history buffer provided by application to simplify the interface + (this feature was not implemented anyway in 1.0.4) +- next_in and avail_in must be initialized before calling inflateInit or + inflateInit2 +- add EXPORT in all exported functions (for Windows DLL) +- added Makefile.nt (thanks to Stephen Williams) +- added the unsupported "contrib" directory: + contrib/asm386/ by Gilles Vollant + 386 asm code replacing longest_match(). + contrib/iostream/ by Kevin Ruland + A C++ I/O streams interface to the zlib gz* functions + contrib/iostream2/ by Tyge Løvset + Another C++ I/O streams interface + contrib/untgz/ by "Pedro A. Aranda Guti\irrez" + A very simple tar.gz file extractor using zlib + contrib/visual-basic.txt by Carlos Rios + How to use compress(), uncompress() and the gz* functions from VB. +- pass params -f (filtered data), -h (huffman only), -1 to -9 (compression + level) in minigzip (thanks to Tom Lane) + +- use const for rommable constants in deflate +- added test for gzseek and gztell in example.c +- add undocumented function inflateSyncPoint() (hack for Paul Mackerras) +- add undocumented function zError to convert error code to string + (for Tim Smithers) +- Allow compilation of gzio with -DNO_DEFLATE to avoid the compression code. +- Use default memcpy for Symantec MSDOS compiler. +- Add EXPORT keyword for check_func (needed for Windows DLL) +- add current directory to LD_LIBRARY_PATH for "make test" +- create also a link for libz.so.1 +- added support for FUJITSU UXP/DS (thanks to Toshiaki Nomura) +- use $(SHAREDLIB) instead of libz.so in Makefile.in (for HPUX) +- added -soname for Linux in configure (Chun-Chung Chen, +- assign numbers to the exported functions in zlib.def (for Windows DLL) +- add advice in zlib.h for best usage of deflateSetDictionary +- work around compiler bug on Atari (cast Z_NULL in call of s->checkfn) +- allow compilation with ANSI keywords only enabled for TurboC in large model +- avoid "versionString"[0] (Borland bug) +- add NEED_DUMMY_RETURN for Borland +- use variable z_verbose for tracing in debug mode (L. Peter Deutsch). +- allow compilation with CC +- defined STDC for OS/2 (David Charlap) +- limit external names to 8 chars for MVS (Thomas Lund) +- in minigzip.c, use static buffers only for 16-bit systems +- fix suffix check for "minigzip -d foo.gz" +- do not return an error for the 2nd of two consecutive gzflush() (Felix Lee) +- use _fdopen instead of fdopen for MSC >= 6.0 (Thomas Fanslau) +- added makelcc.bat for lcc-win32 (Tom St Denis) +- in Makefile.dj2, use copy and del instead of install and rm (Frank Donahoe) +- Avoid expanded $Id$. Use "rcs -kb" or "cvs admin -kb" to avoid Id expansion. +- check for unistd.h in configure (for off_t) +- remove useless check parameter in inflate_blocks_free +- avoid useless assignment of s->check to itself in inflate_blocks_new +- do not flush twice in gzclose (thanks to Ken Raeburn) +- rename FOPEN as F_OPEN to avoid clash with /usr/include/sys/file.h +- use NO_ERRNO_H instead of enumeration of operating systems with errno.h +- work around buggy fclose on pipes for HP/UX +- support zlib DLL with BORLAND C++ 5.0 (thanks to Glenn Randers-Pehrson) +- fix configure if CC is already equal to gcc + +Changes in 1.0.5 (3 Jan 98) +- Fix inflate to terminate gracefully when fed corrupted or invalid data +- Use const for rommable constants in inflate +- Eliminate memory leaks on error conditions in inflate +- Removed some vestigial code in inflate +- Update web address in README + +Changes in 1.0.4 (24 Jul 96) +- In very rare conditions, deflate(s, Z_FINISH) could fail to produce an EOF + bit, so the decompressor could decompress all the correct data but went + on to attempt decompressing extra garbage data. This affected minigzip too. +- zlibVersion and gzerror return const char* (needed for DLL) +- port to RISCOS (no fdopen, no multiple dots, no unlink, no fileno) +- use z_error only for DEBUG (avoid problem with DLLs) + +Changes in 1.0.3 (2 Jul 96) +- use z_streamp instead of z_stream *, which is now a far pointer in MSDOS + small and medium models; this makes the library incompatible with previous + versions for these models. (No effect in large model or on other systems.) +- return OK instead of BUF_ERROR if previous deflate call returned with + avail_out as zero but there is nothing to do +- added memcmp for non STDC compilers +- define NO_DUMMY_DECL for more Mac compilers (.h files merged incorrectly) +- define __32BIT__ if __386__ or i386 is defined (pb. with Watcom and SCO) +- better check for 16-bit mode MSC (avoids problem with Symantec) + +Changes in 1.0.2 (23 May 96) +- added Windows DLL support +- added a function zlibVersion (for the DLL support) +- fixed declarations using Bytef in infutil.c (pb with MSDOS medium model) +- Bytef is define's instead of typedef'd only for Borland C +- avoid reading uninitialized memory in example.c +- mention in README that the zlib format is now RFC1950 +- updated Makefile.dj2 +- added algorithm.doc + +Changes in 1.0.1 (20 May 96) [1.0 skipped to avoid confusion] +- fix array overlay in deflate.c which sometimes caused bad compressed data +- fix inflate bug with empty stored block +- fix MSDOS medium model which was broken in 0.99 +- fix deflateParams() which could generated bad compressed data. +- Bytef is define'd instead of typedef'ed (work around Borland bug) +- added an INDEX file +- new makefiles for DJGPP (Makefile.dj2), 32-bit Borland (Makefile.b32), + Watcom (Makefile.wat), Amiga SAS/C (Makefile.sas) +- speed up adler32 for modern machines without auto-increment +- added -ansi for IRIX in configure +- static_init_done in trees.c is an int +- define unlink as delete for VMS +- fix configure for QNX +- add configure branch for SCO and HPUX +- avoid many warnings (unused variables, dead assignments, etc...) +- no fdopen for BeOS +- fix the Watcom fix for 32 bit mode (define FAR as empty) +- removed redefinition of Byte for MKWERKS +- work around an MWKERKS bug (incorrect merge of all .h files) + +Changes in 0.99 (27 Jan 96) +- allow preset dictionary shared between compressor and decompressor +- allow compression level 0 (no compression) +- add deflateParams in zlib.h: allow dynamic change of compression level + and compression strategy. +- test large buffers and deflateParams in example.c +- add optional "configure" to build zlib as a shared library +- suppress Makefile.qnx, use configure instead +- fixed deflate for 64-bit systems (detected on Cray) +- fixed inflate_blocks for 64-bit systems (detected on Alpha) +- declare Z_DEFLATED in zlib.h (possible parameter for deflateInit2) +- always return Z_BUF_ERROR when deflate() has nothing to do +- deflateInit and inflateInit are now macros to allow version checking +- prefix all global functions and types with z_ with -DZ_PREFIX +- make falloc completely reentrant (inftrees.c) +- fixed very unlikely race condition in ct_static_init +- free in reverse order of allocation to help memory manager +- use zlib-1.0/* instead of zlib/* inside the tar.gz +- make zlib warning-free with "gcc -O3 -Wall -Wwrite-strings -Wpointer-arith + -Wconversion -Wstrict-prototypes -Wmissing-prototypes" +- allow gzread on concatenated .gz files +- deflateEnd now returns Z_DATA_ERROR if it was premature +- deflate is finally (?) fully deterministic (no matches beyond end of input) +- Document Z_SYNC_FLUSH +- add uninstall in Makefile +- Check for __cpluplus in zlib.h +- Better test in ct_align for partial flush +- avoid harmless warnings for Borland C++ +- initialize hash_head in deflate.c +- avoid warning on fdopen (gzio.c) for HP cc -Aa +- include stdlib.h for STDC compilers +- include errno.h for Cray +- ignore error if ranlib doesn't exist +- call ranlib twice for NeXTSTEP +- use exec_prefix instead of prefix for libz.a +- renamed ct_* as _tr_* to avoid conflict with applications +- clear z->msg in inflateInit2 before any error return +- initialize opaque in example.c, gzio.c, deflate.c and inflate.c +- fixed typo in zconf.h (_GNUC__ => __GNUC__) +- check for WIN32 in zconf.h and zutil.c (avoid farmalloc in 32-bit mode) +- fix typo in Make_vms.com (f$trnlnm -> f$getsyi) +- in fcalloc, normalize pointer if size > 65520 bytes +- don't use special fcalloc for 32 bit Borland C++ +- use STDC instead of __GO32__ to avoid redeclaring exit, calloc, etc... +- use Z_BINARY instead of BINARY +- document that gzclose after gzdopen will close the file +- allow "a" as mode in gzopen. +- fix error checking in gzread +- allow skipping .gz extra-field on pipes +- added reference to Perl interface in README +- put the crc table in FAR data (I dislike more and more the medium model :) +- added get_crc_table +- added a dimension to all arrays (Borland C can't count). +- workaround Borland C bug in declaration of inflate_codes_new & inflate_fast +- guard against multiple inclusion of *.h (for precompiled header on Mac) +- Watcom C pretends to be Microsoft C small model even in 32 bit mode. +- don't use unsized arrays to avoid silly warnings by Visual C++: + warning C4746: 'inflate_mask' : unsized array treated as '__far' + (what's wrong with far data in far model?). +- define enum out of inflate_blocks_state to allow compilation with C++ + +Changes in 0.95 (16 Aug 95) +- fix MSDOS small and medium model (now easier to adapt to any compiler) +- inlined send_bits +- fix the final (:-) bug for deflate with flush (output was correct but + not completely flushed in rare occasions). +- default window size is same for compression and decompression + (it's now sufficient to set MAX_WBITS in zconf.h). +- voidp -> voidpf and voidnp -> voidp (for consistency with other + typedefs and because voidnp was not near in large model). + +Changes in 0.94 (13 Aug 95) +- support MSDOS medium model +- fix deflate with flush (could sometimes generate bad output) +- fix deflateReset (zlib header was incorrectly suppressed) +- added support for VMS +- allow a compression level in gzopen() +- gzflush now calls fflush +- For deflate with flush, flush even if no more input is provided. +- rename libgz.a as libz.a +- avoid complex expression in infcodes.c triggering Turbo C bug +- work around a problem with gcc on Alpha (in INSERT_STRING) +- don't use inline functions (problem with some gcc versions) +- allow renaming of Byte, uInt, etc... with #define. +- avoid warning about (unused) pointer before start of array in deflate.c +- avoid various warnings in gzio.c, example.c, infblock.c, adler32.c, zutil.c +- avoid reserved word 'new' in trees.c + +Changes in 0.93 (25 June 95) +- temporarily disable inline functions +- make deflate deterministic +- give enough lookahead for PARTIAL_FLUSH +- Set binary mode for stdin/stdout in minigzip.c for OS/2 +- don't even use signed char in inflate (not portable enough) +- fix inflate memory leak for segmented architectures + +Changes in 0.92 (3 May 95) +- don't assume that char is signed (problem on SGI) +- Clear bit buffer when starting a stored block +- no memcpy on Pyramid +- suppressed inftest.c +- optimized fill_window, put longest_match inline for gcc +- optimized inflate on stored blocks. +- untabify all sources to simplify patches + +Changes in 0.91 (2 May 95) +- Default MEM_LEVEL is 8 (not 9 for Unix) as documented in zlib.h +- Document the memory requirements in zconf.h +- added "make install" +- fix sync search logic in inflateSync +- deflate(Z_FULL_FLUSH) now works even if output buffer too short +- after inflateSync, don't scare people with just "lo world" +- added support for DJGPP + +Changes in 0.9 (1 May 95) +- don't assume that zalloc clears the allocated memory (the TurboC bug + was Mark's bug after all :) +- let again gzread copy uncompressed data unchanged (was working in 0.71) +- deflate(Z_FULL_FLUSH), inflateReset and inflateSync are now fully implemented +- added a test of inflateSync in example.c +- moved MAX_WBITS to zconf.h because users might want to change that. +- document explicitly that zalloc(64K) on MSDOS must return a normalized + pointer (zero offset) +- added Makefiles for Microsoft C, Turbo C, Borland C++ +- faster crc32() + +Changes in 0.8 (29 April 95) +- added fast inflate (inffast.c) +- deflate(Z_FINISH) now returns Z_STREAM_END when done. Warning: this + is incompatible with previous versions of zlib which returned Z_OK. +- work around a TurboC compiler bug (bad code for b << 0, see infutil.h) + (actually that was not a compiler bug, see 0.81 above) +- gzread no longer reads one extra byte in certain cases +- In gzio destroy(), don't reference a freed structure +- avoid many warnings for MSDOS +- avoid the ERROR symbol which is used by MS Windows + +Changes in 0.71 (14 April 95) +- Fixed more MSDOS compilation problems :( There is still a bug with + TurboC large model. + +Changes in 0.7 (14 April 95) +- Added full inflate support. +- Simplified the crc32() interface. The pre- and post-conditioning + (one's complement) is now done inside crc32(). WARNING: this is + incompatible with previous versions; see zlib.h for the new usage. + +Changes in 0.61 (12 April 95) +- workaround for a bug in TurboC. example and minigzip now work on MSDOS. + +Changes in 0.6 (11 April 95) +- added minigzip.c +- added gzdopen to reopen a file descriptor as gzFile +- added transparent reading of non-gziped files in gzread. +- fixed bug in gzread (don't read crc as data) +- fixed bug in destroy (gzio.c) (don't return Z_STREAM_END for gzclose). +- don't allocate big arrays in the stack (for MSDOS) +- fix some MSDOS compilation problems + +Changes in 0.5: +- do real compression in deflate.c. Z_PARTIAL_FLUSH is supported but + not yet Z_FULL_FLUSH. +- support decompression but only in a single step (forced Z_FINISH) +- added opaque object for zalloc and zfree. +- added deflateReset and inflateReset +- added a variable zlib_version for consistency checking. +- renamed the 'filter' parameter of deflateInit2 as 'strategy'. + Added Z_FILTERED and Z_HUFFMAN_ONLY constants. + +Changes in 0.4: +- avoid "zip" everywhere, use zlib instead of ziplib. +- suppress Z_BLOCK_FLUSH, interpret Z_PARTIAL_FLUSH as block flush + if compression method == 8. +- added adler32 and crc32 +- renamed deflateOptions as deflateInit2, call one or the other but not both +- added the method parameter for deflateInit2. +- added inflateInit2 +- simplied considerably deflateInit and inflateInit by not supporting + user-provided history buffer. This is supported only in deflateInit2 + and inflateInit2. + +Changes in 0.3: +- prefix all macro names with Z_ +- use Z_FINISH instead of deflateEnd to finish compression. +- added Z_HUFFMAN_ONLY +- added gzerror() diff --git a/libs/zlib/FAQ b/libs/zlib/FAQ new file mode 100644 index 000000000..99b7cf92e --- /dev/null +++ b/libs/zlib/FAQ @@ -0,0 +1,368 @@ + + Frequently Asked Questions about zlib + + +If your question is not there, please check the zlib home page +http://zlib.net/ which may have more recent information. +The lastest zlib FAQ is at http://zlib.net/zlib_faq.html + + + 1. Is zlib Y2K-compliant? + + Yes. zlib doesn't handle dates. + + 2. Where can I get a Windows DLL version? + + The zlib sources can be compiled without change to produce a DLL. See the + file win32/DLL_FAQ.txt in the zlib distribution. Pointers to the + precompiled DLL are found in the zlib web site at http://zlib.net/ . + + 3. Where can I get a Visual Basic interface to zlib? + + See + * http://marknelson.us/1997/01/01/zlib-engine/ + * win32/DLL_FAQ.txt in the zlib distribution + + 4. compress() returns Z_BUF_ERROR. + + Make sure that before the call of compress(), the length of the compressed + buffer is equal to the available size of the compressed buffer and not + zero. For Visual Basic, check that this parameter is passed by reference + ("as any"), not by value ("as long"). + + 5. deflate() or inflate() returns Z_BUF_ERROR. + + Before making the call, make sure that avail_in and avail_out are not zero. + When setting the parameter flush equal to Z_FINISH, also make sure that + avail_out is big enough to allow processing all pending input. Note that a + Z_BUF_ERROR is not fatal--another call to deflate() or inflate() can be + made with more input or output space. A Z_BUF_ERROR may in fact be + unavoidable depending on how the functions are used, since it is not + possible to tell whether or not there is more output pending when + strm.avail_out returns with zero. See http://zlib.net/zlib_how.html for a + heavily annotated example. + + 6. Where's the zlib documentation (man pages, etc.)? + + It's in zlib.h . Examples of zlib usage are in the files test/example.c + and test/minigzip.c, with more in examples/ . + + 7. Why don't you use GNU autoconf or libtool or ...? + + Because we would like to keep zlib as a very small and simple package. + zlib is rather portable and doesn't need much configuration. + + 8. I found a bug in zlib. + + Most of the time, such problems are due to an incorrect usage of zlib. + Please try to reproduce the problem with a small program and send the + corresponding source to us at zlib@gzip.org . Do not send multi-megabyte + data files without prior agreement. + + 9. Why do I get "undefined reference to gzputc"? + + If "make test" produces something like + + example.o(.text+0x154): undefined reference to `gzputc' + + check that you don't have old files libz.* in /usr/lib, /usr/local/lib or + /usr/X11R6/lib. Remove any old versions, then do "make install". + +10. I need a Delphi interface to zlib. + + See the contrib/delphi directory in the zlib distribution. + +11. Can zlib handle .zip archives? + + Not by itself, no. See the directory contrib/minizip in the zlib + distribution. + +12. Can zlib handle .Z files? + + No, sorry. You have to spawn an uncompress or gunzip subprocess, or adapt + the code of uncompress on your own. + +13. How can I make a Unix shared library? + + By default a shared (and a static) library is built for Unix. So: + + make distclean + ./configure + make + +14. How do I install a shared zlib library on Unix? + + After the above, then: + + make install + + However, many flavors of Unix come with a shared zlib already installed. + Before going to the trouble of compiling a shared version of zlib and + trying to install it, you may want to check if it's already there! If you + can #include , it's there. The -lz option will probably link to + it. You can check the version at the top of zlib.h or with the + ZLIB_VERSION symbol defined in zlib.h . + +15. I have a question about OttoPDF. + + We are not the authors of OttoPDF. The real author is on the OttoPDF web + site: Joel Hainley, jhainley@myndkryme.com. + +16. Can zlib decode Flate data in an Adobe PDF file? + + Yes. See http://www.pdflib.com/ . To modify PDF forms, see + http://sourceforge.net/projects/acroformtool/ . + +17. Why am I getting this "register_frame_info not found" error on Solaris? + + After installing zlib 1.1.4 on Solaris 2.6, running applications using zlib + generates an error such as: + + ld.so.1: rpm: fatal: relocation error: file /usr/local/lib/libz.so: + symbol __register_frame_info: referenced symbol not found + + The symbol __register_frame_info is not part of zlib, it is generated by + the C compiler (cc or gcc). You must recompile applications using zlib + which have this problem. This problem is specific to Solaris. See + http://www.sunfreeware.com for Solaris versions of zlib and applications + using zlib. + +18. Why does gzip give an error on a file I make with compress/deflate? + + The compress and deflate functions produce data in the zlib format, which + is different and incompatible with the gzip format. The gz* functions in + zlib on the other hand use the gzip format. Both the zlib and gzip formats + use the same compressed data format internally, but have different headers + and trailers around the compressed data. + +19. Ok, so why are there two different formats? + + The gzip format was designed to retain the directory information about a + single file, such as the name and last modification date. The zlib format + on the other hand was designed for in-memory and communication channel + applications, and has a much more compact header and trailer and uses a + faster integrity check than gzip. + +20. Well that's nice, but how do I make a gzip file in memory? + + You can request that deflate write the gzip format instead of the zlib + format using deflateInit2(). You can also request that inflate decode the + gzip format using inflateInit2(). Read zlib.h for more details. + +21. Is zlib thread-safe? + + Yes. However any library routines that zlib uses and any application- + provided memory allocation routines must also be thread-safe. zlib's gz* + functions use stdio library routines, and most of zlib's functions use the + library memory allocation routines by default. zlib's *Init* functions + allow for the application to provide custom memory allocation routines. + + Of course, you should only operate on any given zlib or gzip stream from a + single thread at a time. + +22. Can I use zlib in my commercial application? + + Yes. Please read the license in zlib.h. + +23. Is zlib under the GNU license? + + No. Please read the license in zlib.h. + +24. The license says that altered source versions must be "plainly marked". So + what exactly do I need to do to meet that requirement? + + You need to change the ZLIB_VERSION and ZLIB_VERNUM #defines in zlib.h. In + particular, the final version number needs to be changed to "f", and an + identification string should be appended to ZLIB_VERSION. Version numbers + x.x.x.f are reserved for modifications to zlib by others than the zlib + maintainers. For example, if the version of the base zlib you are altering + is "1.2.3.4", then in zlib.h you should change ZLIB_VERNUM to 0x123f, and + ZLIB_VERSION to something like "1.2.3.f-zachary-mods-v3". You can also + update the version strings in deflate.c and inftrees.c. + + For altered source distributions, you should also note the origin and + nature of the changes in zlib.h, as well as in ChangeLog and README, along + with the dates of the alterations. The origin should include at least your + name (or your company's name), and an email address to contact for help or + issues with the library. + + Note that distributing a compiled zlib library along with zlib.h and + zconf.h is also a source distribution, and so you should change + ZLIB_VERSION and ZLIB_VERNUM and note the origin and nature of the changes + in zlib.h as you would for a full source distribution. + +25. Will zlib work on a big-endian or little-endian architecture, and can I + exchange compressed data between them? + + Yes and yes. + +26. Will zlib work on a 64-bit machine? + + Yes. It has been tested on 64-bit machines, and has no dependence on any + data types being limited to 32-bits in length. If you have any + difficulties, please provide a complete problem report to zlib@gzip.org + +27. Will zlib decompress data from the PKWare Data Compression Library? + + No. The PKWare DCL uses a completely different compressed data format than + does PKZIP and zlib. However, you can look in zlib's contrib/blast + directory for a possible solution to your problem. + +28. Can I access data randomly in a compressed stream? + + No, not without some preparation. If when compressing you periodically use + Z_FULL_FLUSH, carefully write all the pending data at those points, and + keep an index of those locations, then you can start decompression at those + points. You have to be careful to not use Z_FULL_FLUSH too often, since it + can significantly degrade compression. Alternatively, you can scan a + deflate stream once to generate an index, and then use that index for + random access. See examples/zran.c . + +29. Does zlib work on MVS, OS/390, CICS, etc.? + + It has in the past, but we have not heard of any recent evidence. There + were working ports of zlib 1.1.4 to MVS, but those links no longer work. + If you know of recent, successful applications of zlib on these operating + systems, please let us know. Thanks. + +30. Is there some simpler, easier to read version of inflate I can look at to + understand the deflate format? + + First off, you should read RFC 1951. Second, yes. Look in zlib's + contrib/puff directory. + +31. Does zlib infringe on any patents? + + As far as we know, no. In fact, that was originally the whole point behind + zlib. Look here for some more information: + + http://www.gzip.org/#faq11 + +32. Can zlib work with greater than 4 GB of data? + + Yes. inflate() and deflate() will process any amount of data correctly. + Each call of inflate() or deflate() is limited to input and output chunks + of the maximum value that can be stored in the compiler's "unsigned int" + type, but there is no limit to the number of chunks. Note however that the + strm.total_in and strm_total_out counters may be limited to 4 GB. These + counters are provided as a convenience and are not used internally by + inflate() or deflate(). The application can easily set up its own counters + updated after each call of inflate() or deflate() to count beyond 4 GB. + compress() and uncompress() may be limited to 4 GB, since they operate in a + single call. gzseek() and gztell() may be limited to 4 GB depending on how + zlib is compiled. See the zlibCompileFlags() function in zlib.h. + + The word "may" appears several times above since there is a 4 GB limit only + if the compiler's "long" type is 32 bits. If the compiler's "long" type is + 64 bits, then the limit is 16 exabytes. + +33. Does zlib have any security vulnerabilities? + + The only one that we are aware of is potentially in gzprintf(). If zlib is + compiled to use sprintf() or vsprintf(), then there is no protection + against a buffer overflow of an 8K string space (or other value as set by + gzbuffer()), other than the caller of gzprintf() assuring that the output + will not exceed 8K. On the other hand, if zlib is compiled to use + snprintf() or vsnprintf(), which should normally be the case, then there is + no vulnerability. The ./configure script will display warnings if an + insecure variation of sprintf() will be used by gzprintf(). Also the + zlibCompileFlags() function will return information on what variant of + sprintf() is used by gzprintf(). + + If you don't have snprintf() or vsnprintf() and would like one, you can + find a portable implementation here: + + http://www.ijs.si/software/snprintf/ + + Note that you should be using the most recent version of zlib. Versions + 1.1.3 and before were subject to a double-free vulnerability, and versions + 1.2.1 and 1.2.2 were subject to an access exception when decompressing + invalid compressed data. + +34. Is there a Java version of zlib? + + Probably what you want is to use zlib in Java. zlib is already included + as part of the Java SDK in the java.util.zip package. If you really want + a version of zlib written in the Java language, look on the zlib home + page for links: http://zlib.net/ . + +35. I get this or that compiler or source-code scanner warning when I crank it + up to maximally-pedantic. Can't you guys write proper code? + + Many years ago, we gave up attempting to avoid warnings on every compiler + in the universe. It just got to be a waste of time, and some compilers + were downright silly as well as contradicted each other. So now, we simply + make sure that the code always works. + +36. Valgrind (or some similar memory access checker) says that deflate is + performing a conditional jump that depends on an uninitialized value. + Isn't that a bug? + + No. That is intentional for performance reasons, and the output of deflate + is not affected. This only started showing up recently since zlib 1.2.x + uses malloc() by default for allocations, whereas earlier versions used + calloc(), which zeros out the allocated memory. Even though the code was + correct, versions 1.2.4 and later was changed to not stimulate these + checkers. + +37. Will zlib read the (insert any ancient or arcane format here) compressed + data format? + + Probably not. Look in the comp.compression FAQ for pointers to various + formats and associated software. + +38. How can I encrypt/decrypt zip files with zlib? + + zlib doesn't support encryption. The original PKZIP encryption is very + weak and can be broken with freely available programs. To get strong + encryption, use GnuPG, http://www.gnupg.org/ , which already includes zlib + compression. For PKZIP compatible "encryption", look at + http://www.info-zip.org/ + +39. What's the difference between the "gzip" and "deflate" HTTP 1.1 encodings? + + "gzip" is the gzip format, and "deflate" is the zlib format. They should + probably have called the second one "zlib" instead to avoid confusion with + the raw deflate compressed data format. While the HTTP 1.1 RFC 2616 + correctly points to the zlib specification in RFC 1950 for the "deflate" + transfer encoding, there have been reports of servers and browsers that + incorrectly produce or expect raw deflate data per the deflate + specification in RFC 1951, most notably Microsoft. So even though the + "deflate" transfer encoding using the zlib format would be the more + efficient approach (and in fact exactly what the zlib format was designed + for), using the "gzip" transfer encoding is probably more reliable due to + an unfortunate choice of name on the part of the HTTP 1.1 authors. + + Bottom line: use the gzip format for HTTP 1.1 encoding. + +40. Does zlib support the new "Deflate64" format introduced by PKWare? + + No. PKWare has apparently decided to keep that format proprietary, since + they have not documented it as they have previous compression formats. In + any case, the compression improvements are so modest compared to other more + modern approaches, that it's not worth the effort to implement. + +41. I'm having a problem with the zip functions in zlib, can you help? + + There are no zip functions in zlib. You are probably using minizip by + Giles Vollant, which is found in the contrib directory of zlib. It is not + part of zlib. In fact none of the stuff in contrib is part of zlib. The + files in there are not supported by the zlib authors. You need to contact + the authors of the respective contribution for help. + +42. The match.asm code in contrib is under the GNU General Public License. + Since it's part of zlib, doesn't that mean that all of zlib falls under the + GNU GPL? + + No. The files in contrib are not part of zlib. They were contributed by + other authors and are provided as a convenience to the user within the zlib + distribution. Each item in contrib has its own license. + +43. Is zlib subject to export controls? What is its ECCN? + + zlib is not subject to export controls, and so is classified as EAR99. + +44. Can you please sign these lengthy legal documents and fax them back to us + so that we can use your software in our product? + + No. Go away. Shoo. diff --git a/libs/zlib/INDEX b/libs/zlib/INDEX new file mode 100644 index 000000000..246f5f478 --- /dev/null +++ b/libs/zlib/INDEX @@ -0,0 +1,67 @@ +CMakeLists.txt cmake build file +ChangeLog history of changes +FAQ Frequently Asked Questions about zlib +INDEX this file +Makefile dummy Makefile that tells you to ./configure +Makefile.in template for Unix Makefile +README guess what +configure configure script for Unix +make_vms.com makefile for VMS +test/example.c zlib usages examples for build testing +test/minigzip.c minimal gzip-like functionality for build testing +test/infcover.c inf*.c code coverage for build coverage testing +treebuild.xml XML description of source file dependencies +zconf.h.cmakein zconf.h template for cmake +zconf.h.in zconf.h template for configure +zlib.3 Man page for zlib +zlib.3.pdf Man page in PDF format +zlib.map Linux symbol information +zlib.pc.in Template for pkg-config descriptor +zlib2ansi perl script to convert source files for C++ compilation + +amiga/ makefiles for Amiga SAS C +as400/ makefiles for AS/400 +doc/ documentation for formats and algorithms +msdos/ makefiles for MSDOS +nintendods/ makefile for Nintendo DS +old/ makefiles for various architectures and zlib documentation + files that have not yet been updated for zlib 1.2.x +qnx/ makefiles for QNX +watcom/ makefiles for OpenWatcom +win32/ makefiles for Windows + + zlib public header files (required for library use): +zconf.h +zlib.h + + private source files used to build the zlib library: +adler32.c +compress.c +crc32.c +crc32.h +deflate.c +deflate.h +gzclose.c +gzguts.h +gzlib.c +gzread.c +gzwrite.c +infback.c +inffast.c +inffast.h +inffixed.h +inflate.c +inflate.h +inftrees.c +inftrees.h +trees.c +trees.h +uncompr.c +zutil.c +zutil.h + + source files for sample programs +See examples/README.examples + + unsupported contributions by third parties +See contrib/README.contrib diff --git a/libs/zlib/Makefile b/libs/zlib/Makefile new file mode 100644 index 000000000..6bba86c73 --- /dev/null +++ b/libs/zlib/Makefile @@ -0,0 +1,5 @@ +all: + -@echo "Please use ./configure first. Thank you." + +distclean: + make -f Makefile.in distclean diff --git a/libs/zlib/Makefile.in b/libs/zlib/Makefile.in new file mode 100644 index 000000000..ea430bf20 --- /dev/null +++ b/libs/zlib/Makefile.in @@ -0,0 +1,285 @@ +# Makefile for zlib +# Copyright (C) 1995-2011 Jean-loup Gailly. +# For conditions of distribution and use, see copyright notice in zlib.h + +# To compile and test, type: +# ./configure; make test +# Normally configure builds both a static and a shared library. +# If you want to build just a static library, use: ./configure --static + +# To use the asm code, type: +# cp contrib/asm?86/match.S ./match.S +# make LOC=-DASMV OBJA=match.o + +# To install /usr/local/lib/libz.* and /usr/local/include/zlib.h, type: +# make install +# To install in $HOME instead of /usr/local, use: +# make install prefix=$HOME + +CC=cc + +CFLAGS=-O +#CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7 +#CFLAGS=-g -DDEBUG +#CFLAGS=-O3 -Wall -Wwrite-strings -Wpointer-arith -Wconversion \ +# -Wstrict-prototypes -Wmissing-prototypes + +SFLAGS=-O +LDFLAGS= +TEST_LDFLAGS=-L. libz.a +LDSHARED=$(CC) +CPP=$(CC) -E + +STATICLIB=libz.a +SHAREDLIB=libz.so +SHAREDLIBV=libz.so.1.2.6 +SHAREDLIBM=libz.so.1 +LIBS=$(STATICLIB) $(SHAREDLIBV) + +AR=ar +ARFLAGS=rc +RANLIB=ranlib +LDCONFIG=ldconfig +LDSHAREDLIBC=-lc +TAR=tar +SHELL=/bin/sh +EXE= + +prefix = /usr/local +exec_prefix = ${prefix} +libdir = ${exec_prefix}/lib +sharedlibdir = ${libdir} +includedir = ${prefix}/include +mandir = ${prefix}/share/man +man3dir = ${mandir}/man3 +pkgconfigdir = ${libdir}/pkgconfig +tempfile := $(shell mktemp -u __XXXXXX) + +OBJZ = adler32.o crc32.o deflate.o infback.o inffast.o inflate.o inftrees.o trees.o zutil.o +OBJG = compress.o uncompr.o gzclose.o gzlib.o gzread.o gzwrite.o +OBJC = $(OBJZ) $(OBJG) + +PIC_OBJZ = adler32.lo crc32.lo deflate.lo infback.lo inffast.lo inflate.lo inftrees.lo trees.lo zutil.lo +PIC_OBJG = compress.lo uncompr.lo gzclose.lo gzlib.lo gzread.lo gzwrite.lo +PIC_OBJC = $(PIC_OBJZ) $(PIC_OBJG) + +# to use the asm code: make OBJA=match.o, PIC_OBJA=match.lo +OBJA = +PIC_OBJA = + +OBJS = $(OBJC) $(OBJA) + +PIC_OBJS = $(PIC_OBJC) $(PIC_OBJA) + +all: static shared + +static: example$(EXE) minigzip$(EXE) + +shared: examplesh$(EXE) minigzipsh$(EXE) + +all64: example64$(EXE) minigzip64$(EXE) + +check: test + +test: all teststatic testshared + +teststatic: static + @if echo hello world | ./minigzip | ./minigzip -d && ./example; then \ + echo ' *** zlib test OK ***'; \ + else \ + echo ' *** zlib test FAILED ***'; false; \ + fi + -@rm -f foo.gz + +testshared: shared + @LD_LIBRARY_PATH=`pwd`:$(LD_LIBRARY_PATH) ; export LD_LIBRARY_PATH; \ + LD_LIBRARYN32_PATH=`pwd`:$(LD_LIBRARYN32_PATH) ; export LD_LIBRARYN32_PATH; \ + DYLD_LIBRARY_PATH=`pwd`:$(DYLD_LIBRARY_PATH) ; export DYLD_LIBRARY_PATH; \ + SHLIB_PATH=`pwd`:$(SHLIB_PATH) ; export SHLIB_PATH; \ + if echo hello world | ./minigzipsh | ./minigzipsh -d && ./examplesh; then \ + echo ' *** zlib shared test OK ***'; \ + else \ + echo ' *** zlib shared test FAILED ***'; false; \ + fi + -@rm -f foo.gz + +test64: all64 + @if echo hello world | ./minigzip64 | ./minigzip64 -d && ./example64; then \ + echo ' *** zlib 64-bit test OK ***'; \ + else \ + echo ' *** zlib 64-bit test FAILED ***'; false; \ + fi + -@rm -f foo.gz + +infcover.o: test/infcover.c zlib.h zconf.h + $(CC) $(CFLAGS) -I. -c -o $@ test/infcover.c + +infcover: infcover.o libz.a + $(CC) $(CFLAGS) -o $@ infcover.o libz.a + +cover: infcover + rm -f *.gcda + ./infcover + gcov inf*.c + +libz.a: $(OBJS) + $(AR) $(ARFLAGS) $@ $(OBJS) + -@ ($(RANLIB) $@ || true) >/dev/null 2>&1 + +match.o: match.S + $(CPP) match.S > _match.s + $(CC) -c _match.s + mv _match.o match.o + rm -f _match.s + +match.lo: match.S + $(CPP) match.S > _match.s + $(CC) -c -fPIC _match.s + mv _match.o match.lo + rm -f _match.s + +example.o: test/example.c zlib.h zconf.h + $(CC) $(CFLAGS) -I. -c -o $@ test/example.c + +minigzip.o: test/minigzip.c zlib.h zconf.h + $(CC) $(CFLAGS) -I. -c -o $@ test/minigzip.c + +example64.o: test/example.c zlib.h zconf.h + $(CC) $(CFLAGS) -I. -D_FILE_OFFSET_BITS=64 -c -o $@ test/example.c + +minigzip64.o: test/minigzip.c zlib.h zconf.h + $(CC) $(CFLAGS) -I. -D_FILE_OFFSET_BITS=64 -c -o $@ test/minigzip.c + +.SUFFIXES: .lo + +.c.lo: + -@mkdir objs 2>/dev/null || test -d objs + $(CC) $(SFLAGS) -DPIC -c -o objs/$*.o $< + -@mv objs/$*.o $@ + +placebo $(SHAREDLIBV): $(PIC_OBJS) libz.a + $(LDSHARED) $(SFLAGS) -o $@ $(PIC_OBJS) $(LDSHAREDLIBC) $(LDFLAGS) + rm -f $(SHAREDLIB) $(SHAREDLIBM) + ln -s $@ $(SHAREDLIB) + ln -s $@ $(SHAREDLIBM) + -@rmdir objs + +example$(EXE): example.o $(STATICLIB) + $(CC) $(CFLAGS) -o $@ example.o $(TEST_LDFLAGS) + +minigzip$(EXE): minigzip.o $(STATICLIB) + $(CC) $(CFLAGS) -o $@ minigzip.o $(TEST_LDFLAGS) + +examplesh$(EXE): example.o $(SHAREDLIBV) + $(CC) $(CFLAGS) -o $@ example.o -L. $(SHAREDLIBV) + +minigzipsh$(EXE): minigzip.o $(SHAREDLIBV) + $(CC) $(CFLAGS) -o $@ minigzip.o -L. $(SHAREDLIBV) + +example64$(EXE): example64.o $(STATICLIB) + $(CC) $(CFLAGS) -o $@ example64.o $(TEST_LDFLAGS) + +minigzip64$(EXE): minigzip64.o $(STATICLIB) + $(CC) $(CFLAGS) -o $@ minigzip64.o $(TEST_LDFLAGS) + +install-libs: $(LIBS) + -@if [ ! -d $(DESTDIR)$(exec_prefix) ]; then mkdir -p $(DESTDIR)$(exec_prefix); fi + -@if [ ! -d $(DESTDIR)$(libdir) ]; then mkdir -p $(DESTDIR)$(libdir); fi + -@if [ ! -d $(DESTDIR)$(sharedlibdir) ]; then mkdir -p $(DESTDIR)$(sharedlibdir); fi + -@if [ ! -d $(DESTDIR)$(man3dir) ]; then mkdir -p $(DESTDIR)$(man3dir); fi + -@if [ ! -d $(DESTDIR)$(pkgconfigdir) ]; then mkdir -p $(DESTDIR)$(pkgconfigdir); fi + cp $(STATICLIB) $(DESTDIR)$(libdir) + chmod 644 $(DESTDIR)$(libdir)/$(STATICLIB) + -@($(RANLIB) $(DESTDIR)$(libdir)/libz.a || true) >/dev/null 2>&1 + -@if test -n "$(SHAREDLIBV)"; then \ + cp $(SHAREDLIBV) $(DESTDIR)$(sharedlibdir); \ + echo "cp $(SHAREDLIBV) $(DESTDIR)$(sharedlibdir)"; \ + chmod 755 $(DESTDIR)$(sharedlibdir)/$(SHAREDLIBV); \ + echo "chmod 755 $(DESTDIR)$(sharedlibdir)/$(SHAREDLIBV)"; \ + rm -f $(DESTDIR)$(sharedlibdir)/$(SHAREDLIB) $(DESTDIR)$(sharedlibdir)/$(SHAREDLIBM); \ + ln -s $(SHAREDLIBV) $(DESTDIR)$(sharedlibdir)/$(SHAREDLIB); \ + ln -s $(SHAREDLIBV) $(DESTDIR)$(sharedlibdir)/$(SHAREDLIBM); \ + ($(LDCONFIG) || true) >/dev/null 2>&1; \ + fi + cp zlib.3 $(DESTDIR)$(man3dir) + chmod 644 $(DESTDIR)$(man3dir)/zlib.3 + cp zlib.pc $(DESTDIR)$(pkgconfigdir) + chmod 644 $(DESTDIR)$(pkgconfigdir)/zlib.pc +# The ranlib in install is needed on NeXTSTEP which checks file times +# ldconfig is for Linux + +install: install-libs + -@if [ ! -d $(DESTDIR)$(includedir) ]; then mkdir -p $(DESTDIR)$(includedir); fi + cp zlib.h zconf.h $(DESTDIR)$(includedir) + chmod 644 $(DESTDIR)$(includedir)/zlib.h $(DESTDIR)$(includedir)/zconf.h + +uninstall: + cd $(DESTDIR)$(includedir); rm -f zlib.h zconf.h + cd $(DESTDIR)$(libdir); rm -f libz.a; \ + if test -n "$(SHAREDLIBV)" -a -f $(SHAREDLIBV); then \ + rm -f $(SHAREDLIBV) $(SHAREDLIB) $(SHAREDLIBM); \ + fi + cd $(DESTDIR)$(man3dir); rm -f zlib.3 + cd $(DESTDIR)$(pkgconfigdir); rm -f zlib.pc + +docs: zlib.3.pdf + +zlib.3.pdf: zlib.3 + groff -mandoc -f H -T ps zlib.3 | ps2pdf - zlib.3.pdf + +zconf.h.cmakein: zconf.h.in + -@echo "/#define ZCONF_H/ a\\\\\n#cmakedefine Z_PREFIX\\\\\n#cmakedefine Z_HAVE_UNISTD_H\n" > $(tempfile) + -@sed -f $(tempfile) zconf.h.in > zconf.h.cmakein + -@touch -r zconf.h.in zconf.h.cmakein + -@rm $(tempfile) + +zconf: zconf.h.in + cp -p zconf.h.in zconf.h + +mostlyclean: clean +clean: + rm -f *.o *.lo *~ \ + example$(EXE) minigzip$(EXE) examplesh$(EXE) minigzipsh$(EXE) \ + example64$(EXE) minigzip64$(EXE) \ + infcover \ + libz.* foo.gz so_locations \ + _match.s maketree contrib/infback9/*.o + rm -rf objs + rm -f *.gcda *.gcno *.gcov + rm -f contrib/infback9/*.gcda contrib/infback9/*.gcno contrib/infback9/*.gcov + +maintainer-clean: distclean +distclean: clean zconf zconf.h.cmakein docs + rm -f Makefile zlib.pc configure.log + -@rm -f .DS_Store + -@printf 'all:\n\t-@echo "Please use ./configure first. Thank you."\n' > Makefile + -@printf '\ndistclean:\n\tmake -f Makefile.in distclean\n' >> Makefile + -@touch -r Makefile.in Makefile + +tags: + etags *.[ch] + +depend: + makedepend -- $(CFLAGS) -- *.[ch] + +# DO NOT DELETE THIS LINE -- make depend depends on it. + +adler32.o zutil.o: zutil.h zlib.h zconf.h +gzclose.o gzlib.o gzread.o gzwrite.o: zlib.h zconf.h gzguts.h +compress.o example.o minigzip.o uncompr.o: zlib.h zconf.h +crc32.o: zutil.h zlib.h zconf.h crc32.h +deflate.o: deflate.h zutil.h zlib.h zconf.h +infback.o inflate.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h inffixed.h +inffast.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h +inftrees.o: zutil.h zlib.h zconf.h inftrees.h +trees.o: deflate.h zutil.h zlib.h zconf.h trees.h + +adler32.lo zutil.lo: zutil.h zlib.h zconf.h +gzclose.lo gzlib.lo gzread.lo gzwrite.lo: zlib.h zconf.h gzguts.h +compress.lo example.lo minigzip.lo uncompr.lo: zlib.h zconf.h +crc32.lo: zutil.h zlib.h zconf.h crc32.h +deflate.lo: deflate.h zutil.h zlib.h zconf.h +infback.lo inflate.lo: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h inffixed.h +inffast.lo: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h +inftrees.lo: zutil.h zlib.h zconf.h inftrees.h +trees.lo: deflate.h zutil.h zlib.h zconf.h trees.h diff --git a/libs/zlib/README b/libs/zlib/README new file mode 100644 index 000000000..09070e2c0 --- /dev/null +++ b/libs/zlib/README @@ -0,0 +1,115 @@ +ZLIB DATA COMPRESSION LIBRARY + +zlib 1.2.6 is a general purpose data compression library. All the code is +thread safe. The data format used by the zlib library is described by RFCs +(Request for Comments) 1950 to 1952 in the files +http://tools.ietf.org/html/rfc1950 (zlib format), rfc1951 (deflate format) and +rfc1952 (gzip format). + +All functions of the compression library are documented in the file zlib.h +(volunteer to write man pages welcome, contact zlib@gzip.org). A usage example +of the library is given in the file test/example.c which also tests that +the library is working correctly. Another example is given in the file +test/minigzip.c. The compression library itself is composed of all source +files in the root directory. + +To compile all files and run the test program, follow the instructions given at +the top of Makefile.in. In short "./configure; make test", and if that goes +well, "make install" should work for most flavors of Unix. For Windows, use +one of the special makefiles in win32/ or contrib/vstudio/ . For VMS, use +make_vms.com. + +Questions about zlib should be sent to , or to Gilles Vollant + for the Windows DLL version. The zlib home page is +http://zlib.net/ . Before reporting a problem, please check this site to +verify that you have the latest version of zlib; otherwise get the latest +version and check whether the problem still exists or not. + +PLEASE read the zlib FAQ http://zlib.net/zlib_faq.html before asking for help. + +Mark Nelson wrote an article about zlib for the Jan. 1997 +issue of Dr. Dobb's Journal; a copy of the article is available at +http://marknelson.us/1997/01/01/zlib-engine/ . + +The changes made in version 1.2.6 are documented in the file ChangeLog. + +Unsupported third party contributions are provided in directory contrib/ . + +zlib is available in Java using the java.util.zip package, documented at +http://java.sun.com/developer/technicalArticles/Programming/compression/ . + +A Perl interface to zlib written by Paul Marquess is available +at CPAN (Comprehensive Perl Archive Network) sites, including +http://search.cpan.org/~pmqs/IO-Compress-Zlib/ . + +A Python interface to zlib written by A.M. Kuchling is +available in Python 1.5 and later versions, see +http://docs.python.org/library/zlib.html . + +zlib is built into tcl: http://wiki.tcl.tk/4610 . + +An experimental package to read and write files in .zip format, written on top +of zlib by Gilles Vollant , is available in the +contrib/minizip directory of zlib. + + +Notes for some targets: + +- For Windows DLL versions, please see win32/DLL_FAQ.txt + +- For 64-bit Irix, deflate.c must be compiled without any optimization. With + -O, one libpng test fails. The test works in 32 bit mode (with the -n32 + compiler flag). The compiler bug has been reported to SGI. + +- zlib doesn't work with gcc 2.6.3 on a DEC 3000/300LX under OSF/1 2.1 it works + when compiled with cc. + +- On Digital Unix 4.0D (formely OSF/1) on AlphaServer, the cc option -std1 is + necessary to get gzprintf working correctly. This is done by configure. + +- zlib doesn't work on HP-UX 9.05 with some versions of /bin/cc. It works with + other compilers. Use "make test" to check your compiler. + +- gzdopen is not supported on RISCOS or BEOS. + +- For PalmOs, see http://palmzlib.sourceforge.net/ + + +Acknowledgments: + + The deflate format used by zlib was defined by Phil Katz. The deflate and + zlib specifications were written by L. Peter Deutsch. Thanks to all the + people who reported problems and suggested various improvements in zlib; they + are too numerous to cite here. + +Copyright notice: + + (C) 1995-2012 Jean-loup Gailly and Mark Adler + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Jean-loup Gailly Mark Adler + jloup@gzip.org madler@alumni.caltech.edu + +If you use the zlib library in a product, we would appreciate *not* receiving +lengthy legal documents to sign. The sources are provided for free but without +warranty of any kind. The library has been entirely written by Jean-loup +Gailly and Mark Adler; it does not include third-party code. + +If you redistribute modified sources, we would appreciate that you include in +the file ChangeLog history information documenting your changes. Please read +the FAQ for more information on the distribution of modified source versions. diff --git a/libs/zlib/adler32.c b/libs/zlib/adler32.c new file mode 100644 index 000000000..a868f073d --- /dev/null +++ b/libs/zlib/adler32.c @@ -0,0 +1,179 @@ +/* adler32.c -- compute the Adler-32 checksum of a data stream + * Copyright (C) 1995-2011 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* @(#) $Id$ */ + +#include "zutil.h" + +#define local static + +local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2)); + +#define BASE 65521 /* largest prime smaller than 65536 */ +#define NMAX 5552 +/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */ + +#define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;} +#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1); +#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2); +#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4); +#define DO16(buf) DO8(buf,0); DO8(buf,8); + +/* use NO_DIVIDE if your processor does not do division in hardware -- + try it both ways to see which is faster */ +#ifdef NO_DIVIDE +/* note that this assumes BASE is 65521, where 65536 % 65521 == 15 + (thank you to John Reiser for pointing this out) */ +# define CHOP(a) \ + do { \ + unsigned long tmp = a >> 16; \ + a &= 0xffffUL; \ + a += (tmp << 4) - tmp; \ + } while (0) +# define MOD28(a) \ + do { \ + CHOP(a); \ + if (a >= BASE) a -= BASE; \ + } while (0) +# define MOD(a) \ + do { \ + CHOP(a); \ + MOD28(a); \ + } while (0) +# define MOD63(a) \ + do { /* this assumes a is not negative */ \ + z_off64_t tmp = a >> 32; \ + a &= 0xffffffffL; \ + a += (tmp << 8) - (tmp << 5) + tmp; \ + tmp = a >> 16; \ + a &= 0xffffL; \ + a += (tmp << 4) - tmp; \ + tmp = a >> 16; \ + a &= 0xffffL; \ + a += (tmp << 4) - tmp; \ + if (a >= BASE) a -= BASE; \ + } while (0) +#else +# define MOD(a) a %= BASE +# define MOD28(a) a %= BASE +# define MOD63(a) a %= BASE +#endif + +/* ========================================================================= */ +uLong ZEXPORT adler32(adler, buf, len) + uLong adler; + const Bytef *buf; + uInt len; +{ + unsigned long sum2; + unsigned n; + + /* split Adler-32 into component sums */ + sum2 = (adler >> 16) & 0xffff; + adler &= 0xffff; + + /* in case user likes doing a byte at a time, keep it fast */ + if (len == 1) { + adler += buf[0]; + if (adler >= BASE) + adler -= BASE; + sum2 += adler; + if (sum2 >= BASE) + sum2 -= BASE; + return adler | (sum2 << 16); + } + + /* initial Adler-32 value (deferred check for len == 1 speed) */ + if (buf == Z_NULL) + return 1L; + + /* in case short lengths are provided, keep it somewhat fast */ + if (len < 16) { + while (len--) { + adler += *buf++; + sum2 += adler; + } + if (adler >= BASE) + adler -= BASE; + MOD28(sum2); /* only added so many BASE's */ + return adler | (sum2 << 16); + } + + /* do length NMAX blocks -- requires just one modulo operation */ + while (len >= NMAX) { + len -= NMAX; + n = NMAX / 16; /* NMAX is divisible by 16 */ + do { + DO16(buf); /* 16 sums unrolled */ + buf += 16; + } while (--n); + MOD(adler); + MOD(sum2); + } + + /* do remaining bytes (less than NMAX, still just one modulo) */ + if (len) { /* avoid modulos if none remaining */ + while (len >= 16) { + len -= 16; + DO16(buf); + buf += 16; + } + while (len--) { + adler += *buf++; + sum2 += adler; + } + MOD(adler); + MOD(sum2); + } + + /* return recombined sums */ + return adler | (sum2 << 16); +} + +/* ========================================================================= */ +local uLong adler32_combine_(adler1, adler2, len2) + uLong adler1; + uLong adler2; + z_off64_t len2; +{ + unsigned long sum1; + unsigned long sum2; + unsigned rem; + + /* for negative len, return invalid adler32 as a clue for debugging */ + if (len2 < 0) + return 0xffffffffUL; + + /* the derivation of this formula is left as an exercise for the reader */ + MOD63(len2); /* assumes len2 >= 0 */ + rem = (unsigned)len2; + sum1 = adler1 & 0xffff; + sum2 = rem * sum1; + MOD(sum2); + sum1 += (adler2 & 0xffff) + BASE - 1; + sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem; + if (sum1 >= BASE) sum1 -= BASE; + if (sum1 >= BASE) sum1 -= BASE; + if (sum2 >= (BASE << 1)) sum2 -= (BASE << 1); + if (sum2 >= BASE) sum2 -= BASE; + return sum1 | (sum2 << 16); +} + +/* ========================================================================= */ +uLong ZEXPORT adler32_combine(adler1, adler2, len2) + uLong adler1; + uLong adler2; + z_off_t len2; +{ + return adler32_combine_(adler1, adler2, len2); +} + +uLong ZEXPORT adler32_combine64(adler1, adler2, len2) + uLong adler1; + uLong adler2; + z_off64_t len2; +{ + return adler32_combine_(adler1, adler2, len2); +} diff --git a/libs/zlib/amiga/Makefile.pup b/libs/zlib/amiga/Makefile.pup new file mode 100644 index 000000000..8940c120f --- /dev/null +++ b/libs/zlib/amiga/Makefile.pup @@ -0,0 +1,69 @@ +# Amiga powerUP (TM) Makefile +# makefile for libpng and SAS C V6.58/7.00 PPC compiler +# Copyright (C) 1998 by Andreas R. Kleinert + +LIBNAME = libzip.a + +CC = scppc +CFLAGS = NOSTKCHK NOSINT OPTIMIZE OPTGO OPTPEEP OPTINLOCAL OPTINL \ + OPTLOOP OPTRDEP=8 OPTDEP=8 OPTCOMP=8 NOVER +AR = ppc-amigaos-ar cr +RANLIB = ppc-amigaos-ranlib +LD = ppc-amigaos-ld -r +LDFLAGS = -o +LDLIBS = LIB:scppc.a LIB:end.o +RM = delete quiet + +OBJS = adler32.o compress.o crc32.o gzclose.o gzlib.o gzread.o gzwrite.o \ + uncompr.o deflate.o trees.o zutil.o inflate.o infback.o inftrees.o inffast.o + +TEST_OBJS = example.o minigzip.o + +all: example minigzip + +check: test +test: all + example + echo hello world | minigzip | minigzip -d + +$(LIBNAME): $(OBJS) + $(AR) $@ $(OBJS) + -$(RANLIB) $@ + +example: example.o $(LIBNAME) + $(LD) $(LDFLAGS) $@ LIB:c_ppc.o $@.o $(LIBNAME) $(LDLIBS) + +minigzip: minigzip.o $(LIBNAME) + $(LD) $(LDFLAGS) $@ LIB:c_ppc.o $@.o $(LIBNAME) $(LDLIBS) + +mostlyclean: clean +clean: + $(RM) *.o example minigzip $(LIBNAME) foo.gz + +zip: + zip -ul9 zlib README ChangeLog Makefile Make????.??? Makefile.?? \ + descrip.mms *.[ch] + +tgz: + cd ..; tar cfz zlib/zlib.tgz zlib/README zlib/ChangeLog zlib/Makefile \ + zlib/Make????.??? zlib/Makefile.?? zlib/descrip.mms zlib/*.[ch] + +# DO NOT DELETE THIS LINE -- make depend depends on it. + +adler32.o: zlib.h zconf.h +compress.o: zlib.h zconf.h +crc32.o: crc32.h zlib.h zconf.h +deflate.o: deflate.h zutil.h zlib.h zconf.h +example.o: zlib.h zconf.h +gzclose.o: zlib.h zconf.h gzguts.h +gzlib.o: zlib.h zconf.h gzguts.h +gzread.o: zlib.h zconf.h gzguts.h +gzwrite.o: zlib.h zconf.h gzguts.h +inffast.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h +inflate.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h +infback.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h +inftrees.o: zutil.h zlib.h zconf.h inftrees.h +minigzip.o: zlib.h zconf.h +trees.o: deflate.h zutil.h zlib.h zconf.h trees.h +uncompr.o: zlib.h zconf.h +zutil.o: zutil.h zlib.h zconf.h diff --git a/libs/zlib/amiga/Makefile.sas b/libs/zlib/amiga/Makefile.sas new file mode 100644 index 000000000..749e29152 --- /dev/null +++ b/libs/zlib/amiga/Makefile.sas @@ -0,0 +1,68 @@ +# SMakefile for zlib +# Modified from the standard UNIX Makefile Copyright Jean-loup Gailly +# Osma Ahvenlampi +# Amiga, SAS/C 6.56 & Smake + +CC=sc +CFLAGS=OPT +#CFLAGS=OPT CPU=68030 +#CFLAGS=DEBUG=LINE +LDFLAGS=LIB z.lib + +SCOPTIONS=OPTSCHED OPTINLINE OPTALIAS OPTTIME OPTINLOCAL STRMERGE \ + NOICONS PARMS=BOTH NOSTACKCHECK UTILLIB NOVERSION ERRORREXX \ + DEF=POSTINC + +OBJS = adler32.o compress.o crc32.o gzclose.o gzlib.o gzread.o gzwrite.o \ + uncompr.o deflate.o trees.o zutil.o inflate.o infback.o inftrees.o inffast.o + +TEST_OBJS = example.o minigzip.o + +all: SCOPTIONS example minigzip + +check: test +test: all + example + echo hello world | minigzip | minigzip -d + +install: z.lib + copy clone zlib.h zconf.h INCLUDE: + copy clone z.lib LIB: + +z.lib: $(OBJS) + oml z.lib r $(OBJS) + +example: example.o z.lib + $(CC) $(CFLAGS) LINK TO $@ example.o $(LDFLAGS) + +minigzip: minigzip.o z.lib + $(CC) $(CFLAGS) LINK TO $@ minigzip.o $(LDFLAGS) + +mostlyclean: clean +clean: + -delete force quiet example minigzip *.o z.lib foo.gz *.lnk SCOPTIONS + +SCOPTIONS: Makefile.sas + copy to $@ 64K on 16-bit machine: */ + if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; +#endif + stream.next_out = dest; + stream.avail_out = (uInt)*destLen; + if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; + + stream.zalloc = (alloc_func)0; + stream.zfree = (free_func)0; + stream.opaque = (voidpf)0; + + err = deflateInit(&stream, level); + if (err != Z_OK) return err; + + err = deflate(&stream, Z_FINISH); + if (err != Z_STREAM_END) { + deflateEnd(&stream); + return err == Z_OK ? Z_BUF_ERROR : err; + } + *destLen = stream.total_out; + + err = deflateEnd(&stream); + return err; +} + +/* =========================================================================== + */ +int ZEXPORT compress (dest, destLen, source, sourceLen) + Bytef *dest; + uLongf *destLen; + const Bytef *source; + uLong sourceLen; +{ + return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION); +} + +/* =========================================================================== + If the default memLevel or windowBits for deflateInit() is changed, then + this function needs to be updated. + */ +uLong ZEXPORT compressBound (sourceLen) + uLong sourceLen; +{ + return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + + (sourceLen >> 25) + 13; +} diff --git a/libs/zlib/configure b/libs/zlib/configure new file mode 100755 index 000000000..780317ce4 --- /dev/null +++ b/libs/zlib/configure @@ -0,0 +1,720 @@ +#!/bin/sh +# configure script for zlib. +# +# Normally configure builds both a static and a shared library. +# If you want to build just a static library, use: ./configure --static +# +# To impose specific compiler or flags or install directory, use for example: +# prefix=$HOME CC=cc CFLAGS="-O4" ./configure +# or for csh/tcsh users: +# (setenv prefix $HOME; setenv CC cc; setenv CFLAGS "-O4"; ./configure) + +# Incorrect settings of CC or CFLAGS may prevent creating a shared library. +# If you have problems, try without defining CC and CFLAGS before reporting +# an error. + +echo -------------------- >> configure.log +echo $0 $* >> configure.log +date >> configure.log + +if [ -n "${CHOST}" ]; then + uname="`echo "${CHOST}" | sed -e 's/^[^-]*-\([^-]*\)$/\1/' -e 's/^[^-]*-[^-]*-\([^-]*\)$/\1/' -e 's/^[^-]*-[^-]*-\([^-]*\)-.*$/\1/'`" + CROSS_PREFIX="${CHOST}-" +fi + +STATICLIB=libz.a +VER=`sed -n -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h` +VER3=`sed -n -e '/VERSION "/s/.*"\([0-9]*\\.[0-9]*\\.[0-9]*\).*/\1/p' < zlib.h` +VER2=`sed -n -e '/VERSION "/s/.*"\([0-9]*\\.[0-9]*\)\\..*/\1/p' < zlib.h` +VER1=`sed -n -e '/VERSION "/s/.*"\([0-9]*\)\\..*/\1/p' < zlib.h` +if "${CROSS_PREFIX}ar" --version >/dev/null 2>/dev/null || test $? -lt 126; then + AR=${AR-"${CROSS_PREFIX}ar"} + test -n "${CROSS_PREFIX}" && echo Using ${AR} | tee -a configure.log +else + AR=${AR-"ar"} + test -n "${CROSS_PREFIX}" && echo Using ${AR} | tee -a configure.log +fi +ARFLAGS=${ARFLAGS-"rc"} +if "${CROSS_PREFIX}ranlib" --version >/dev/null 2>/dev/null || test $? -lt 126; then + RANLIB=${RANLIB-"${CROSS_PREFIX}ranlib"} + test -n "${CROSS_PREFIX}" && echo Using ${RANLIB} | tee -a configure.log +else + RANLIB=${RANLIB-"ranlib"} +fi +if "${CROSS_PREFIX}nm" --version >/dev/null 2>/dev/null || test $? -lt 126; then + NM=${NM-"${CROSS_PREFIX}nm"} + test -n "${CROSS_PREFIX}" && echo Using ${NM} | tee -a configure.log +else + NM=${NM-"nm"} +fi +LDCONFIG=${LDCONFIG-"ldconfig"} +LDSHAREDLIBC="${LDSHAREDLIBC--lc}" +ARCHS= +prefix=${prefix-/usr/local} +exec_prefix=${exec_prefix-'${prefix}'} +libdir=${libdir-'${exec_prefix}/lib'} +sharedlibdir=${sharedlibdir-'${libdir}'} +includedir=${includedir-'${prefix}/include'} +mandir=${mandir-'${prefix}/share/man'} +shared_ext='.so' +shared=1 +solo=0 +cover=0 +zprefix=0 +build64=0 +gcc=0 +old_cc="$CC" +old_cflags="$CFLAGS" +OBJC='$(OBJZ) $(OBJG)' +PIC_OBJC='$(PIC_OBJZ) $(PIC_OBJG)' + +while test $# -ge 1 +do +case "$1" in + -h* | --help) + echo 'usage:' | tee -a configure.log + echo ' configure [--zprefix] [--prefix=PREFIX] [--eprefix=EXPREFIX]' | tee -a configure.log + echo ' [--static] [--64] [--libdir=LIBDIR] [--sharedlibdir=LIBDIR]' | tee -a configure.log + echo ' [--includedir=INCLUDEDIR] [--archs="-arch i386 -arch x86_64"]' | tee -a configure.log + exit 0 ;; + -p*=* | --prefix=*) prefix=`echo $1 | sed 's/.*=//'`; shift ;; + -e*=* | --eprefix=*) exec_prefix=`echo $1 | sed 's/.*=//'`; shift ;; + -l*=* | --libdir=*) libdir=`echo $1 | sed 's/.*=//'`; shift ;; + --sharedlibdir=*) sharedlibdir=`echo $1 | sed 's/.*=//'`; shift ;; + -i*=* | --includedir=*) includedir=`echo $1 | sed 's/.*=//'`;shift ;; + -u*=* | --uname=*) uname=`echo $1 | sed 's/.*=//'`;shift ;; + -p* | --prefix) prefix="$2"; shift; shift ;; + -e* | --eprefix) exec_prefix="$2"; shift; shift ;; + -l* | --libdir) libdir="$2"; shift; shift ;; + -i* | --includedir) includedir="$2"; shift; shift ;; + -s* | --shared | --enable-shared) shared=1; shift ;; + -t | --static) shared=0; shift ;; + --solo) solo=1; shift ;; + --cover) cover=1; shift ;; + -z* | --zprefix) zprefix=1; shift ;; + -6* | --64) build64=1; shift ;; + -a*=* | --archs=*) ARCHS=`echo $1 | sed 's/.*=//'`; shift ;; + --sysconfdir=*) echo "ignored option: --sysconfdir" | tee -a configure.log; shift ;; + --localstatedir=*) echo "ignored option: --localstatedir" | tee -a configure.log; shift ;; + *) echo "unknown option: $1"; echo "$0 --help for help" | tee -a configure.log; exit 1 ;; + esac +done + +test=ztest$$ + +show() +{ + case "$*" in + *$test.c*) + echo === $test.c === >> configure.log + cat $test.c >> configure.log + echo === >> configure.log;; + esac + echo $* >> configure.log +} + +cat > $test.c </dev/null; then + try() + { + show $* + test "`( $* ) 2>&1 | tee -a configure.log`" = "" + } + echo - using any output from compiler to indicate an error >> configure.log +else + try() + { + show $* + ( $* ) >> configure.log 2>&1 + ret=$? + if test $ret -ne 0; then + echo "(exit code "$ret")" >> configure.log + fi + return $ret + } +fi + +echo >> configure.log + +cat > $test.c <&1` in + *gcc*) gcc=1 ;; +esac + +show $cc -c $cflags $test.c +if test "$gcc" -eq 1 && ($cc -c $cflags $test.c) >> configure.log 2>&1; then + echo ... using gcc >> configure.log + CC="$cc" + CFLAGS="${CFLAGS--O3} ${ARCHS}" + SFLAGS="${CFLAGS--O3} -fPIC" + LDFLAGS="${LDFLAGS} ${ARCHS}" + if test $build64 -eq 1; then + CFLAGS="${CFLAGS} -m64" + SFLAGS="${SFLAGS} -m64" + fi + if test "${ZLIBGCCWARN}" = "YES"; then + CFLAGS="${CFLAGS} -Wall -Wextra -pedantic" + fi + if test -z "$uname"; then + uname=`(uname -s || echo unknown) 2>/dev/null` + fi + case "$uname" in + Linux* | linux* | GNU | GNU/* | solaris*) + LDSHARED=${LDSHARED-"$cc -shared -Wl,-soname,libz.so.1,--version-script,zlib.map"} ;; + *BSD | *bsd* | DragonFly) + LDSHARED=${LDSHARED-"$cc -shared -Wl,-soname,libz.so.1,--version-script,zlib.map"} + LDCONFIG="ldconfig -m" ;; + CYGWIN* | Cygwin* | cygwin* | OS/2*) + EXE='.exe' ;; + MINGW* | mingw*) +# temporary bypass + rm -f $test.[co] $test $test$shared_ext + echo "Please use win32/Makefile.gcc instead." | tee -a configure.log + exit 1 + LDSHARED=${LDSHARED-"$cc -shared"} + LDSHAREDLIBC="" + EXE='.exe' ;; + QNX*) # This is for QNX6. I suppose that the QNX rule below is for QNX2,QNX4 + # (alain.bonnefoy@icbt.com) + LDSHARED=${LDSHARED-"$cc -shared -Wl,-hlibz.so.1"} ;; + HP-UX*) + LDSHARED=${LDSHARED-"$cc -shared $SFLAGS"} + case `(uname -m || echo unknown) 2>/dev/null` in + ia64) + shared_ext='.so' + SHAREDLIB='libz.so' ;; + *) + shared_ext='.sl' + SHAREDLIB='libz.sl' ;; + esac ;; + Darwin* | darwin*) + shared_ext='.dylib' + SHAREDLIB=libz$shared_ext + SHAREDLIBV=libz.$VER$shared_ext + SHAREDLIBM=libz.$VER1$shared_ext + LDSHARED=${LDSHARED-"$cc -dynamiclib -install_name $libdir/$SHAREDLIBM -compatibility_version $VER1 -current_version $VER3"} + AR="libtool" + ARFLAGS="-o" ;; + *) LDSHARED=${LDSHARED-"$cc -shared"} ;; + esac +else + # find system name and corresponding cc options + CC=${CC-cc} + gcc=0 + echo ... using $CC >> configure.log + if test -z "$uname"; then + uname=`(uname -sr || echo unknown) 2>/dev/null` + fi + case "$uname" in + HP-UX*) SFLAGS=${CFLAGS-"-O +z"} + CFLAGS=${CFLAGS-"-O"} +# LDSHARED=${LDSHARED-"ld -b +vnocompatwarnings"} + LDSHARED=${LDSHARED-"ld -b"} + case `(uname -m || echo unknown) 2>/dev/null` in + ia64) + shared_ext='.so' + SHAREDLIB='libz.so' ;; + *) + shared_ext='.sl' + SHAREDLIB='libz.sl' ;; + esac ;; + IRIX*) SFLAGS=${CFLAGS-"-ansi -O2 -rpath ."} + CFLAGS=${CFLAGS-"-ansi -O2"} + LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so.1"} ;; + OSF1\ V4*) SFLAGS=${CFLAGS-"-O -std1"} + CFLAGS=${CFLAGS-"-O -std1"} + LDFLAGS="${LDFLAGS} -Wl,-rpath,." + LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so -Wl,-msym -Wl,-rpath,$(libdir) -Wl,-set_version,${VER}:1.0"} ;; + OSF1*) SFLAGS=${CFLAGS-"-O -std1"} + CFLAGS=${CFLAGS-"-O -std1"} + LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so.1"} ;; + QNX*) SFLAGS=${CFLAGS-"-4 -O"} + CFLAGS=${CFLAGS-"-4 -O"} + LDSHARED=${LDSHARED-"cc"} + RANLIB=${RANLIB-"true"} + AR="cc" + ARFLAGS="-A" ;; + SCO_SV\ 3.2*) SFLAGS=${CFLAGS-"-O3 -dy -KPIC "} + CFLAGS=${CFLAGS-"-O3"} + LDSHARED=${LDSHARED-"cc -dy -KPIC -G"} ;; + SunOS\ 5* | solaris*) + LDSHARED=${LDSHARED-"cc -G"} + case `(uname -m || echo unknown) 2>/dev/null` in + i86*) + SFLAGS=${CFLAGS-"-xpentium -fast -KPIC -R."} + CFLAGS=${CFLAGS-"-xpentium -fast"} ;; + *) + SFLAGS=${CFLAGS-"-fast -xcg92 -KPIC -R."} + CFLAGS=${CFLAGS-"-fast -xcg92"} ;; + esac ;; + SunOS\ 4*) SFLAGS=${CFLAGS-"-O2 -PIC"} + CFLAGS=${CFLAGS-"-O2"} + LDSHARED=${LDSHARED-"ld"} ;; + SunStudio\ 9*) SFLAGS=${CFLAGS-"-fast -xcode=pic32 -xtarget=ultra3 -xarch=v9b"} + CFLAGS=${CFLAGS-"-fast -xtarget=ultra3 -xarch=v9b"} + LDSHARED=${LDSHARED-"cc -xarch=v9b"} ;; + UNIX_System_V\ 4.2.0) + SFLAGS=${CFLAGS-"-KPIC -O"} + CFLAGS=${CFLAGS-"-O"} + LDSHARED=${LDSHARED-"cc -G"} ;; + UNIX_SV\ 4.2MP) + SFLAGS=${CFLAGS-"-Kconform_pic -O"} + CFLAGS=${CFLAGS-"-O"} + LDSHARED=${LDSHARED-"cc -G"} ;; + OpenUNIX\ 5) + SFLAGS=${CFLAGS-"-KPIC -O"} + CFLAGS=${CFLAGS-"-O"} + LDSHARED=${LDSHARED-"cc -G"} ;; + AIX*) # Courtesy of dbakker@arrayasolutions.com + SFLAGS=${CFLAGS-"-O -qmaxmem=8192"} + CFLAGS=${CFLAGS-"-O -qmaxmem=8192"} + LDSHARED=${LDSHARED-"xlc -G"} ;; + # send working options for other systems to zlib@gzip.org + *) SFLAGS=${CFLAGS-"-O"} + CFLAGS=${CFLAGS-"-O"} + LDSHARED=${LDSHARED-"cc -shared"} ;; + esac +fi + +SHAREDLIB=${SHAREDLIB-"libz$shared_ext"} +SHAREDLIBV=${SHAREDLIBV-"libz$shared_ext.$VER"} +SHAREDLIBM=${SHAREDLIBM-"libz$shared_ext.$VER1"} + +echo >> configure.log + +if test $shared -eq 1; then + echo Checking for shared library support... | tee -a configure.log + # we must test in two steps (cc then ld), required at least on SunOS 4.x + if try $CC -w -c $SFLAGS $test.c && + try $LDSHARED $SFLAGS -o $test$shared_ext $test.o; then + echo Building shared library $SHAREDLIBV with $CC. | tee -a configure.log + elif test -z "$old_cc" -a -z "$old_cflags"; then + echo No shared library support. | tee -a configure.log + shared=0; + else + echo 'No shared library support; try without defining CC and CFLAGS' | tee -a configure.log + shared=0; + fi +fi +if test $shared -eq 0; then + LDSHARED="$CC" + ALL="static" + TEST="all teststatic" + SHAREDLIB="" + SHAREDLIBV="" + SHAREDLIBM="" + echo Building static library $STATICLIB version $VER with $CC. | tee -a configure.log +else + ALL="static shared" + TEST="all teststatic testshared" +fi + +CPP=${CPP-"$CC -E"} +case $CFLAGS in + *ASMV*) + echo >> configure.log + show "$NM $test.o | grep _hello" + if test "`$NM $test.o | grep _hello | tee -a configure.log`" = ""; then + CPP="$CPP -DNO_UNDERLINE" + echo Checking for underline in external names... No. | tee -a configure.log + else + echo Checking for underline in external names... Yes. | tee -a configure.log + fi ;; +esac + +echo >> configure.log + +cat > $test.c < +off64_t dummy = 0; +EOF +if try $CC -c $CFLAGS -D_LARGEFILE64_SOURCE=1 $test.c; then + CFLAGS="${CFLAGS} -D_LARGEFILE64_SOURCE=1" + SFLAGS="${SFLAGS} -D_LARGEFILE64_SOURCE=1" + ALL="${ALL} all64" + TEST="${TEST} test64" + echo "Checking for off64_t... Yes." | tee -a configure.log + echo "Checking for fseeko... Yes." | tee -a configure.log +else + echo "Checking for off64_t... No." | tee -a configure.log + echo >> configure.log + cat > $test.c < +int main(void) { + fseeko(NULL, 0, 0); + return 0; +} +EOF + if try $CC $CFLAGS -o $test $test.c; then + echo "Checking for fseeko... Yes." | tee -a configure.log + else + CFLAGS="${CFLAGS} -DNO_FSEEKO" + SFLAGS="${SFLAGS} -DNO_FSEEKO" + echo "Checking for fseeko... No." | tee -a configure.log + fi +fi + +cp -p zconf.h.in zconf.h + +echo >> configure.log + +cat > $test.c < +int main() { return 0; } +EOF +if try $CC -c $CFLAGS $test.c; then + sed < zconf.h "/^#ifdef HAVE_UNISTD_H.* may be/s/def HAVE_UNISTD_H\(.*\) may be/ 1\1 was/" > zconf.temp.h + mv zconf.temp.h zconf.h + echo "Checking for unistd.h... Yes." | tee -a configure.log +else + echo "Checking for unistd.h... No." | tee -a configure.log +fi + +echo >> configure.log + +cat > $test.c < +int main() { return 0; } +EOF +if try $CC -c $CFLAGS $test.c; then + sed < zconf.h "/^#ifdef HAVE_STDARG_H.* may be/s/def HAVE_STDARG_H\(.*\) may be/ 1\1 was/" > zconf.temp.h + mv zconf.temp.h zconf.h + echo "Checking for stdarg.h... Yes." | tee -a configure.log +else + echo "Checking for stdarg.h... No." | tee -a configure.log +fi + +if test $zprefix -eq 1; then + sed < zconf.h "/#ifdef Z_PREFIX.* may be/s/def Z_PREFIX\(.*\) may be/ 1\1 was/" > zconf.temp.h + mv zconf.temp.h zconf.h + echo >> configure.log + echo "Using z_ prefix on all symbols." | tee -a configure.log +fi + +if test $solo -eq 1; then + sed '/#define ZCONF_H/a\ +#define Z_SOLO + +' < zconf.h > zconf.temp.h + mv zconf.temp.h zconf.h +OBJC='$(OBJZ)' +PIC_OBJC='$(PIC_OBJZ)' +fi + +if test $cover -eq 1; then + CFLAGS="${CFLAGS} -fprofile-arcs -ftest-coverage" +fi + +echo >> configure.log + +cat > $test.c < +#include +#include "zconf.h" +int main() +{ +#ifndef STDC + choke me +#endif + return 0; +} +EOF + +if try $CC -c $CFLAGS $test.c; then + echo "Checking whether to use vs[n]printf() or s[n]printf()... using vs[n]printf()." | tee -a configure.log + + echo >> configure.log + cat > $test.c < +#include +int mytest(const char *fmt, ...) +{ + char buf[20]; + va_list ap; + va_start(ap, fmt); + vsnprintf(buf, sizeof(buf), fmt, ap); + va_end(ap); + return 0; +} +int main() +{ + return (mytest("Hello%d\n", 1)); +} +EOF + if try $CC $CFLAGS -o $test $test.c; then + echo "Checking for vsnprintf() in stdio.h... Yes." | tee -a configure.log + + echo >> configure.log + cat >$test.c < +#include +int mytest(const char *fmt, ...) +{ + int n; + char buf[20]; + va_list ap; + va_start(ap, fmt); + n = vsnprintf(buf, sizeof(buf), fmt, ap); + va_end(ap); + return n; +} +int main() +{ + return (mytest("Hello%d\n", 1)); +} +EOF + + if try $CC -c $CFLAGS $test.c; then + echo "Checking for return value of vsnprintf()... Yes." | tee -a configure.log + else + CFLAGS="$CFLAGS -DHAS_vsnprintf_void" + SFLAGS="$SFLAGS -DHAS_vsnprintf_void" + echo "Checking for return value of vsnprintf()... No." | tee -a configure.log + echo " WARNING: apparently vsnprintf() does not return a value. zlib" | tee -a configure.log + echo " can build but will be open to possible string-format security" | tee -a configure.log + echo " vulnerabilities." | tee -a configure.log + fi + else + CFLAGS="$CFLAGS -DNO_vsnprintf" + SFLAGS="$SFLAGS -DNO_vsnprintf" + echo "Checking for vsnprintf() in stdio.h... No." | tee -a configure.log + echo " WARNING: vsnprintf() not found, falling back to vsprintf(). zlib" | tee -a configure.log + echo " can build but will be open to possible buffer-overflow security" | tee -a configure.log + echo " vulnerabilities." | tee -a configure.log + + echo >> configure.log + cat >$test.c < +#include +int mytest(const char *fmt, ...) +{ + int n; + char buf[20]; + va_list ap; + va_start(ap, fmt); + n = vsprintf(buf, fmt, ap); + va_end(ap); + return n; +} +int main() +{ + return (mytest("Hello%d\n", 1)); +} +EOF + + if try $CC -c $CFLAGS $test.c; then + echo "Checking for return value of vsprintf()... Yes." | tee -a configure.log + else + CFLAGS="$CFLAGS -DHAS_vsprintf_void" + SFLAGS="$SFLAGS -DHAS_vsprintf_void" + echo "Checking for return value of vsprintf()... No." | tee -a configure.log + echo " WARNING: apparently vsprintf() does not return a value. zlib" | tee -a configure.log + echo " can build but will be open to possible string-format security" | tee -a configure.log + echo " vulnerabilities." | tee -a configure.log + fi + fi +else + echo "Checking whether to use vs[n]printf() or s[n]printf()... using s[n]printf()." | tee -a configure.log + + echo >> configure.log + cat >$test.c < +int mytest() +{ + char buf[20]; + snprintf(buf, sizeof(buf), "%s", "foo"); + return 0; +} +int main() +{ + return (mytest()); +} +EOF + + if try $CC $CFLAGS -o $test $test.c; then + echo "Checking for snprintf() in stdio.h... Yes." | tee -a configure.log + + echo >> configure.log + cat >$test.c < +int mytest() +{ + char buf[20]; + return snprintf(buf, sizeof(buf), "%s", "foo"); +} +int main() +{ + return (mytest()); +} +EOF + + if try $CC -c $CFLAGS $test.c; then + echo "Checking for return value of snprintf()... Yes." | tee -a configure.log + else + CFLAGS="$CFLAGS -DHAS_snprintf_void" + SFLAGS="$SFLAGS -DHAS_snprintf_void" + echo "Checking for return value of snprintf()... No." | tee -a configure.log + echo " WARNING: apparently snprintf() does not return a value. zlib" | tee -a configure.log + echo " can build but will be open to possible string-format security" | tee -a configure.log + echo " vulnerabilities." | tee -a configure.log + fi + else + CFLAGS="$CFLAGS -DNO_snprintf" + SFLAGS="$SFLAGS -DNO_snprintf" + echo "Checking for snprintf() in stdio.h... No." | tee -a configure.log + echo " WARNING: snprintf() not found, falling back to sprintf(). zlib" | tee -a configure.log + echo " can build but will be open to possible buffer-overflow security" | tee -a configure.log + echo " vulnerabilities." | tee -a configure.log + + echo >> configure.log + cat >$test.c < +int mytest() +{ + char buf[20]; + return sprintf(buf, "%s", "foo"); +} +int main() +{ + return (mytest()); +} +EOF + + if try $CC -c $CFLAGS $test.c; then + echo "Checking for return value of sprintf()... Yes." | tee -a configure.log + else + CFLAGS="$CFLAGS -DHAS_sprintf_void" + SFLAGS="$SFLAGS -DHAS_sprintf_void" + echo "Checking for return value of sprintf()... No." | tee -a configure.log + echo " WARNING: apparently sprintf() does not return a value. zlib" | tee -a configure.log + echo " can build but will be open to possible string-format security" | tee -a configure.log + echo " vulnerabilities." | tee -a configure.log + fi + fi +fi + +if test "$gcc" -eq 1; then + echo >> configure.log + cat > $test.c <= 33) +# define ZLIB_INTERNAL __attribute__((visibility ("hidden"))) +#else +# define ZLIB_INTERNAL +#endif +int ZLIB_INTERNAL foo; +int main() +{ + return 0; +} +EOF + if try $CC -c $CFLAGS $test.c; then + echo "Checking for attribute(visibility) support... Yes." | tee -a configure.log + else + CFLAGS="$CFLAGS -DNO_VIZ" + SFLAGS="$SFLAGS -DNO_VIZ" + echo "Checking for attribute(visibility) support... No." | tee -a configure.log + fi +fi + +rm -f $test.[co] $test $test$shared_ext $test.gcno + +# show the results in the log +echo >> configure.log +echo ALL = $ALL >> configure.log +echo AR = $AR >> configure.log +echo ARFLAGS = $ARFLAGS >> configure.log +echo CC = $CC >> configure.log +echo CFLAGS = $CFLAGS >> configure.log +echo CPP = $CPP >> configure.log +echo EXE = $EXE >> configure.log +echo LDCONFIG = $LDCONFIG >> configure.log +echo LDFLAGS = $LDFLAGS >> configure.log +echo LDSHARED = $LDSHARED >> configure.log +echo LDSHAREDLIBC = $LDSHAREDLIBC >> configure.log +echo OBJC = $OBJC >> configure.log +echo PIC_OBJC = $PIC_OBJC >> configure.log +echo RANLIB = $RANLIB >> configure.log +echo SFLAGS = $SFLAGS >> configure.log +echo SHAREDLIB = $SHAREDLIB >> configure.log +echo SHAREDLIBM = $SHAREDLIBM >> configure.log +echo SHAREDLIBV = $SHAREDLIBV >> configure.log +echo STATICLIB = $STATICLIB >> configure.log +echo TEST = $TEST >> configure.log +echo VER = $VER >> configure.log +echo exec_prefix = $exec_prefix >> configure.log +echo includedir = $includedir >> configure.log +echo libdir = $libdir >> configure.log +echo mandir = $mandir >> configure.log +echo prefix = $prefix >> configure.log +echo sharedlibdir = $sharedlibdir >> configure.log +echo uname = $uname >> configure.log +echo -------------------- >> configure.log +echo >> configure.log +echo >> configure.log + +# udpate Makefile +sed < Makefile.in " +/^CC *=/s#=.*#=$CC# +/^CFLAGS *=/s#=.*#=$CFLAGS# +/^SFLAGS *=/s#=.*#=$SFLAGS# +/^LDFLAGS *=/s#=.*#=$LDFLAGS# +/^LDSHARED *=/s#=.*#=$LDSHARED# +/^CPP *=/s#=.*#=$CPP# +/^STATICLIB *=/s#=.*#=$STATICLIB# +/^SHAREDLIB *=/s#=.*#=$SHAREDLIB# +/^SHAREDLIBV *=/s#=.*#=$SHAREDLIBV# +/^SHAREDLIBM *=/s#=.*#=$SHAREDLIBM# +/^AR *=/s#=.*#=$AR# +/^ARFLAGS *=/s#=.*#=$ARFLAGS# +/^RANLIB *=/s#=.*#=$RANLIB# +/^LDCONFIG *=/s#=.*#=$LDCONFIG# +/^LDSHAREDLIBC *=/s#=.*#=$LDSHAREDLIBC# +/^EXE *=/s#=.*#=$EXE# +/^prefix *=/s#=.*#=$prefix# +/^exec_prefix *=/s#=.*#=$exec_prefix# +/^libdir *=/s#=.*#=$libdir# +/^sharedlibdir *=/s#=.*#=$sharedlibdir# +/^includedir *=/s#=.*#=$includedir# +/^mandir *=/s#=.*#=$mandir# +/^OBJC *=/s#=.*#= $OBJC# +/^PIC_OBJC *=/s#=.*#= $PIC_OBJC# +/^all: */s#:.*#: $ALL# +/^test: */s#:.*#: $TEST# +" > Makefile + +sed < zlib.pc.in " +/^CC *=/s#=.*#=$CC# +/^CFLAGS *=/s#=.*#=$CFLAGS# +/^CPP *=/s#=.*#=$CPP# +/^LDSHARED *=/s#=.*#=$LDSHARED# +/^STATICLIB *=/s#=.*#=$STATICLIB# +/^SHAREDLIB *=/s#=.*#=$SHAREDLIB# +/^SHAREDLIBV *=/s#=.*#=$SHAREDLIBV# +/^SHAREDLIBM *=/s#=.*#=$SHAREDLIBM# +/^AR *=/s#=.*#=$AR# +/^ARFLAGS *=/s#=.*#=$ARFLAGS# +/^RANLIB *=/s#=.*#=$RANLIB# +/^EXE *=/s#=.*#=$EXE# +/^prefix *=/s#=.*#=$prefix# +/^exec_prefix *=/s#=.*#=$exec_prefix# +/^libdir *=/s#=.*#=$libdir# +/^sharedlibdir *=/s#=.*#=$sharedlibdir# +/^includedir *=/s#=.*#=$includedir# +/^mandir *=/s#=.*#=$mandir# +/^LDFLAGS *=/s#=.*#=$LDFLAGS# +" | sed -e " +s/\@VERSION\@/$VER/g; +" > zlib.pc diff --git a/libs/zlib/contrib/README.contrib b/libs/zlib/contrib/README.contrib new file mode 100644 index 000000000..dd2285d96 --- /dev/null +++ b/libs/zlib/contrib/README.contrib @@ -0,0 +1,77 @@ +All files under this contrib directory are UNSUPPORTED. There were +provided by users of zlib and were not tested by the authors of zlib. +Use at your own risk. Please contact the authors of the contributions +for help about these, not the zlib authors. Thanks. + + +ada/ by Dmitriy Anisimkov + Support for Ada + See http://zlib-ada.sourceforge.net/ + +amd64/ by Mikhail Teterin + asm code for AMD64 + See patch at http://www.freebsd.org/cgi/query-pr.cgi?pr=bin/96393 + +asm686/ by Brian Raiter + asm code for Pentium and PPro/PII, using the AT&T (GNU as) syntax + See http://www.muppetlabs.com/~breadbox/software/assembly.html + +blast/ by Mark Adler + Decompressor for output of PKWare Data Compression Library (DCL) + +delphi/ by Cosmin Truta + Support for Delphi and C++ Builder + +dotzlib/ by Henrik Ravn + Support for Microsoft .Net and Visual C++ .Net + +gcc_gvmat64/by Gilles Vollant + GCC Version of x86 64-bit (AMD64 and Intel EM64t) code for x64 + assembler to replace longest_match() and inflate_fast() + +infback9/ by Mark Adler + Unsupported diffs to infback to decode the deflate64 format + +inflate86/ by Chris Anderson + Tuned x86 gcc asm code to replace inflate_fast() + +iostream/ by Kevin Ruland + A C++ I/O streams interface to the zlib gz* functions + +iostream2/ by Tyge Løvset + Another C++ I/O streams interface + +iostream3/ by Ludwig Schwardt + and Kevin Ruland + Yet another C++ I/O streams interface + +masmx64/ by Gilles Vollant + x86 64-bit (AMD64 and Intel EM64t) code for x64 assembler to + replace longest_match() and inflate_fast(), also masm x86 + 64-bits translation of Chris Anderson inflate_fast() + +masmx86/ by Gilles Vollant + x86 asm code to replace longest_match() and inflate_fast(), + for Visual C++ and MASM (32 bits). + Based on Brian Raiter (asm686) and Chris Anderson (inflate86) + +minizip/ by Gilles Vollant + Mini zip and unzip based on zlib + Includes Zip64 support by Mathias Svensson + See http://www.winimage.com/zLibDll/unzip.html + +pascal/ by Bob Dellaca et al. + Support for Pascal + +puff/ by Mark Adler + Small, low memory usage inflate. Also serves to provide an + unambiguous description of the deflate format. + +testzlib/ by Gilles Vollant + Example of the use of zlib + +untgz/ by Pedro A. Aranda Gutierrez + A very simple tar.gz file extractor using zlib + +vstudio/ by Gilles Vollant + Building a minizip-enhanced zlib with Microsoft Visual Studio diff --git a/libs/zlib/contrib/ada/buffer_demo.adb b/libs/zlib/contrib/ada/buffer_demo.adb new file mode 100644 index 000000000..46b863810 --- /dev/null +++ b/libs/zlib/contrib/ada/buffer_demo.adb @@ -0,0 +1,106 @@ +---------------------------------------------------------------- +-- ZLib for Ada thick binding. -- +-- -- +-- Copyright (C) 2002-2004 Dmitriy Anisimkov -- +-- -- +-- Open source license information is in the zlib.ads file. -- +---------------------------------------------------------------- +-- +-- $Id: buffer_demo.adb,v 1.3 2004/09/06 06:55:35 vagul Exp $ + +-- This demo program provided by Dr Steve Sangwine +-- +-- Demonstration of a problem with Zlib-Ada (already fixed) when a buffer +-- of exactly the correct size is used for decompressed data, and the last +-- few bytes passed in to Zlib are checksum bytes. + +-- This program compresses a string of text, and then decompresses the +-- compressed text into a buffer of the same size as the original text. + +with Ada.Streams; use Ada.Streams; +with Ada.Text_IO; + +with ZLib; use ZLib; + +procedure Buffer_Demo is + EOL : Character renames ASCII.LF; + Text : constant String + := "Four score and seven years ago our fathers brought forth," & EOL & + "upon this continent, a new nation, conceived in liberty," & EOL & + "and dedicated to the proposition that `all men are created equal'."; + + Source : Stream_Element_Array (1 .. Text'Length); + for Source'Address use Text'Address; + +begin + Ada.Text_IO.Put (Text); + Ada.Text_IO.New_Line; + Ada.Text_IO.Put_Line + ("Uncompressed size : " & Positive'Image (Text'Length) & " bytes"); + + declare + Compressed_Data : Stream_Element_Array (1 .. Text'Length); + L : Stream_Element_Offset; + begin + Compress : declare + Compressor : Filter_Type; + I : Stream_Element_Offset; + begin + Deflate_Init (Compressor); + + -- Compress the whole of T at once. + + Translate (Compressor, Source, I, Compressed_Data, L, Finish); + pragma Assert (I = Source'Last); + + Close (Compressor); + + Ada.Text_IO.Put_Line + ("Compressed size : " + & Stream_Element_Offset'Image (L) & " bytes"); + end Compress; + + -- Now we decompress the data, passing short blocks of data to Zlib + -- (because this demonstrates the problem - the last block passed will + -- contain checksum information and there will be no output, only a + -- check inside Zlib that the checksum is correct). + + Decompress : declare + Decompressor : Filter_Type; + + Uncompressed_Data : Stream_Element_Array (1 .. Text'Length); + + Block_Size : constant := 4; + -- This makes sure that the last block contains + -- only Adler checksum data. + + P : Stream_Element_Offset := Compressed_Data'First - 1; + O : Stream_Element_Offset; + begin + Inflate_Init (Decompressor); + + loop + Translate + (Decompressor, + Compressed_Data + (P + 1 .. Stream_Element_Offset'Min (P + Block_Size, L)), + P, + Uncompressed_Data + (Total_Out (Decompressor) + 1 .. Uncompressed_Data'Last), + O, + No_Flush); + + Ada.Text_IO.Put_Line + ("Total in : " & Count'Image (Total_In (Decompressor)) & + ", out : " & Count'Image (Total_Out (Decompressor))); + + exit when P = L; + end loop; + + Ada.Text_IO.New_Line; + Ada.Text_IO.Put_Line + ("Decompressed text matches original text : " + & Boolean'Image (Uncompressed_Data = Source)); + end Decompress; + end; +end Buffer_Demo; diff --git a/libs/zlib/contrib/ada/mtest.adb b/libs/zlib/contrib/ada/mtest.adb new file mode 100644 index 000000000..c4dfd080f --- /dev/null +++ b/libs/zlib/contrib/ada/mtest.adb @@ -0,0 +1,156 @@ +---------------------------------------------------------------- +-- ZLib for Ada thick binding. -- +-- -- +-- Copyright (C) 2002-2003 Dmitriy Anisimkov -- +-- -- +-- Open source license information is in the zlib.ads file. -- +---------------------------------------------------------------- +-- Continuous test for ZLib multithreading. If the test would fail +-- we should provide thread safe allocation routines for the Z_Stream. +-- +-- $Id: mtest.adb,v 1.4 2004/07/23 07:49:54 vagul Exp $ + +with ZLib; +with Ada.Streams; +with Ada.Numerics.Discrete_Random; +with Ada.Text_IO; +with Ada.Exceptions; +with Ada.Task_Identification; + +procedure MTest is + use Ada.Streams; + use ZLib; + + Stop : Boolean := False; + + pragma Atomic (Stop); + + subtype Visible_Symbols is Stream_Element range 16#20# .. 16#7E#; + + package Random_Elements is + new Ada.Numerics.Discrete_Random (Visible_Symbols); + + task type Test_Task; + + task body Test_Task is + Buffer : Stream_Element_Array (1 .. 100_000); + Gen : Random_Elements.Generator; + + Buffer_First : Stream_Element_Offset; + Compare_First : Stream_Element_Offset; + + Deflate : Filter_Type; + Inflate : Filter_Type; + + procedure Further (Item : in Stream_Element_Array); + + procedure Read_Buffer + (Item : out Ada.Streams.Stream_Element_Array; + Last : out Ada.Streams.Stream_Element_Offset); + + ------------- + -- Further -- + ------------- + + procedure Further (Item : in Stream_Element_Array) is + + procedure Compare (Item : in Stream_Element_Array); + + ------------- + -- Compare -- + ------------- + + procedure Compare (Item : in Stream_Element_Array) is + Next_First : Stream_Element_Offset := Compare_First + Item'Length; + begin + if Buffer (Compare_First .. Next_First - 1) /= Item then + raise Program_Error; + end if; + + Compare_First := Next_First; + end Compare; + + procedure Compare_Write is new ZLib.Write (Write => Compare); + begin + Compare_Write (Inflate, Item, No_Flush); + end Further; + + ----------------- + -- Read_Buffer -- + ----------------- + + procedure Read_Buffer + (Item : out Ada.Streams.Stream_Element_Array; + Last : out Ada.Streams.Stream_Element_Offset) + is + Buff_Diff : Stream_Element_Offset := Buffer'Last - Buffer_First; + Next_First : Stream_Element_Offset; + begin + if Item'Length <= Buff_Diff then + Last := Item'Last; + + Next_First := Buffer_First + Item'Length; + + Item := Buffer (Buffer_First .. Next_First - 1); + + Buffer_First := Next_First; + else + Last := Item'First + Buff_Diff; + Item (Item'First .. Last) := Buffer (Buffer_First .. Buffer'Last); + Buffer_First := Buffer'Last + 1; + end if; + end Read_Buffer; + + procedure Translate is new Generic_Translate + (Data_In => Read_Buffer, + Data_Out => Further); + + begin + Random_Elements.Reset (Gen); + + Buffer := (others => 20); + + Main : loop + for J in Buffer'Range loop + Buffer (J) := Random_Elements.Random (Gen); + + Deflate_Init (Deflate); + Inflate_Init (Inflate); + + Buffer_First := Buffer'First; + Compare_First := Buffer'First; + + Translate (Deflate); + + if Compare_First /= Buffer'Last + 1 then + raise Program_Error; + end if; + + Ada.Text_IO.Put_Line + (Ada.Task_Identification.Image + (Ada.Task_Identification.Current_Task) + & Stream_Element_Offset'Image (J) + & ZLib.Count'Image (Total_Out (Deflate))); + + Close (Deflate); + Close (Inflate); + + exit Main when Stop; + end loop; + end loop Main; + exception + when E : others => + Ada.Text_IO.Put_Line (Ada.Exceptions.Exception_Information (E)); + Stop := True; + end Test_Task; + + Test : array (1 .. 4) of Test_Task; + + pragma Unreferenced (Test); + + Dummy : Character; + +begin + Ada.Text_IO.Get_Immediate (Dummy); + Stop := True; +end MTest; diff --git a/libs/zlib/contrib/ada/read.adb b/libs/zlib/contrib/ada/read.adb new file mode 100644 index 000000000..1f2efbfeb --- /dev/null +++ b/libs/zlib/contrib/ada/read.adb @@ -0,0 +1,156 @@ +---------------------------------------------------------------- +-- ZLib for Ada thick binding. -- +-- -- +-- Copyright (C) 2002-2003 Dmitriy Anisimkov -- +-- -- +-- Open source license information is in the zlib.ads file. -- +---------------------------------------------------------------- + +-- $Id: read.adb,v 1.8 2004/05/31 10:53:40 vagul Exp $ + +-- Test/demo program for the generic read interface. + +with Ada.Numerics.Discrete_Random; +with Ada.Streams; +with Ada.Text_IO; + +with ZLib; + +procedure Read is + + use Ada.Streams; + + ------------------------------------ + -- Test configuration parameters -- + ------------------------------------ + + File_Size : Stream_Element_Offset := 100_000; + + Continuous : constant Boolean := False; + -- If this constant is True, the test would be repeated again and again, + -- with increment File_Size for every iteration. + + Header : constant ZLib.Header_Type := ZLib.Default; + -- Do not use Header other than Default in ZLib versions 1.1.4 and older. + + Init_Random : constant := 8; + -- We are using the same random sequence, in case of we catch bug, + -- so we would be able to reproduce it. + + -- End -- + + Pack_Size : Stream_Element_Offset; + Offset : Stream_Element_Offset; + + Filter : ZLib.Filter_Type; + + subtype Visible_Symbols + is Stream_Element range 16#20# .. 16#7E#; + + package Random_Elements is new + Ada.Numerics.Discrete_Random (Visible_Symbols); + + Gen : Random_Elements.Generator; + Period : constant Stream_Element_Offset := 200; + -- Period constant variable for random generator not to be very random. + -- Bigger period, harder random. + + Read_Buffer : Stream_Element_Array (1 .. 2048); + Read_First : Stream_Element_Offset; + Read_Last : Stream_Element_Offset; + + procedure Reset; + + procedure Read + (Item : out Stream_Element_Array; + Last : out Stream_Element_Offset); + -- this procedure is for generic instantiation of + -- ZLib.Read + -- reading data from the File_In. + + procedure Read is new ZLib.Read + (Read, + Read_Buffer, + Rest_First => Read_First, + Rest_Last => Read_Last); + + ---------- + -- Read -- + ---------- + + procedure Read + (Item : out Stream_Element_Array; + Last : out Stream_Element_Offset) is + begin + Last := Stream_Element_Offset'Min + (Item'Last, + Item'First + File_Size - Offset); + + for J in Item'First .. Last loop + if J < Item'First + Period then + Item (J) := Random_Elements.Random (Gen); + else + Item (J) := Item (J - Period); + end if; + + Offset := Offset + 1; + end loop; + end Read; + + ----------- + -- Reset -- + ----------- + + procedure Reset is + begin + Random_Elements.Reset (Gen, Init_Random); + Pack_Size := 0; + Offset := 1; + Read_First := Read_Buffer'Last + 1; + Read_Last := Read_Buffer'Last; + end Reset; + +begin + Ada.Text_IO.Put_Line ("ZLib " & ZLib.Version); + + loop + for Level in ZLib.Compression_Level'Range loop + + Ada.Text_IO.Put ("Level =" + & ZLib.Compression_Level'Image (Level)); + + -- Deflate using generic instantiation. + + ZLib.Deflate_Init + (Filter, + Level, + Header => Header); + + Reset; + + Ada.Text_IO.Put + (Stream_Element_Offset'Image (File_Size) & " ->"); + + loop + declare + Buffer : Stream_Element_Array (1 .. 1024); + Last : Stream_Element_Offset; + begin + Read (Filter, Buffer, Last); + + Pack_Size := Pack_Size + Last - Buffer'First + 1; + + exit when Last < Buffer'Last; + end; + end loop; + + Ada.Text_IO.Put_Line (Stream_Element_Offset'Image (Pack_Size)); + + ZLib.Close (Filter); + end loop; + + exit when not Continuous; + + File_Size := File_Size + 1; + end loop; +end Read; diff --git a/libs/zlib/contrib/ada/readme.txt b/libs/zlib/contrib/ada/readme.txt new file mode 100644 index 000000000..ce4d2cadf --- /dev/null +++ b/libs/zlib/contrib/ada/readme.txt @@ -0,0 +1,65 @@ + ZLib for Ada thick binding (ZLib.Ada) + Release 1.3 + +ZLib.Ada is a thick binding interface to the popular ZLib data +compression library, available at http://www.gzip.org/zlib/. +It provides Ada-style access to the ZLib C library. + + + Here are the main changes since ZLib.Ada 1.2: + +- Attension: ZLib.Read generic routine have a initialization requirement + for Read_Last parameter now. It is a bit incompartible with previous version, + but extends functionality, we could use new parameters Allow_Read_Some and + Flush now. + +- Added Is_Open routines to ZLib and ZLib.Streams packages. + +- Add pragma Assert to check Stream_Element is 8 bit. + +- Fix extraction to buffer with exact known decompressed size. Error reported by + Steve Sangwine. + +- Fix definition of ULong (changed to unsigned_long), fix regression on 64 bits + computers. Patch provided by Pascal Obry. + +- Add Status_Error exception definition. + +- Add pragma Assertion that Ada.Streams.Stream_Element size is 8 bit. + + + How to build ZLib.Ada under GNAT + +You should have the ZLib library already build on your computer, before +building ZLib.Ada. Make the directory of ZLib.Ada sources current and +issue the command: + + gnatmake test -largs -L -lz + +Or use the GNAT project file build for GNAT 3.15 or later: + + gnatmake -Pzlib.gpr -L + + + How to build ZLib.Ada under Aonix ObjectAda for Win32 7.2.2 + +1. Make a project with all *.ads and *.adb files from the distribution. +2. Build the libz.a library from the ZLib C sources. +3. Rename libz.a to z.lib. +4. Add the library z.lib to the project. +5. Add the libc.lib library from the ObjectAda distribution to the project. +6. Build the executable using test.adb as a main procedure. + + + How to use ZLib.Ada + +The source files test.adb and read.adb are small demo programs that show +the main functionality of ZLib.Ada. + +The routines from the package specifications are commented. + + +Homepage: http://zlib-ada.sourceforge.net/ +Author: Dmitriy Anisimkov + +Contributors: Pascal Obry , Steve Sangwine diff --git a/libs/zlib/contrib/ada/test.adb b/libs/zlib/contrib/ada/test.adb new file mode 100644 index 000000000..90773acfa --- /dev/null +++ b/libs/zlib/contrib/ada/test.adb @@ -0,0 +1,463 @@ +---------------------------------------------------------------- +-- ZLib for Ada thick binding. -- +-- -- +-- Copyright (C) 2002-2003 Dmitriy Anisimkov -- +-- -- +-- Open source license information is in the zlib.ads file. -- +---------------------------------------------------------------- + +-- $Id: test.adb,v 1.17 2003/08/12 12:13:30 vagul Exp $ + +-- The program has a few aims. +-- 1. Test ZLib.Ada95 thick binding functionality. +-- 2. Show the example of use main functionality of the ZLib.Ada95 binding. +-- 3. Build this program automatically compile all ZLib.Ada95 packages under +-- GNAT Ada95 compiler. + +with ZLib.Streams; +with Ada.Streams.Stream_IO; +with Ada.Numerics.Discrete_Random; + +with Ada.Text_IO; + +with Ada.Calendar; + +procedure Test is + + use Ada.Streams; + use Stream_IO; + + ------------------------------------ + -- Test configuration parameters -- + ------------------------------------ + + File_Size : Count := 100_000; + Continuous : constant Boolean := False; + + Header : constant ZLib.Header_Type := ZLib.Default; + -- ZLib.None; + -- ZLib.Auto; + -- ZLib.GZip; + -- Do not use Header other then Default in ZLib versions 1.1.4 + -- and older. + + Strategy : constant ZLib.Strategy_Type := ZLib.Default_Strategy; + Init_Random : constant := 10; + + -- End -- + + In_File_Name : constant String := "testzlib.in"; + -- Name of the input file + + Z_File_Name : constant String := "testzlib.zlb"; + -- Name of the compressed file. + + Out_File_Name : constant String := "testzlib.out"; + -- Name of the decompressed file. + + File_In : File_Type; + File_Out : File_Type; + File_Back : File_Type; + File_Z : ZLib.Streams.Stream_Type; + + Filter : ZLib.Filter_Type; + + Time_Stamp : Ada.Calendar.Time; + + procedure Generate_File; + -- Generate file of spetsified size with some random data. + -- The random data is repeatable, for the good compression. + + procedure Compare_Streams + (Left, Right : in out Root_Stream_Type'Class); + -- The procedure compearing data in 2 streams. + -- It is for compare data before and after compression/decompression. + + procedure Compare_Files (Left, Right : String); + -- Compare files. Based on the Compare_Streams. + + procedure Copy_Streams + (Source, Target : in out Root_Stream_Type'Class; + Buffer_Size : in Stream_Element_Offset := 1024); + -- Copying data from one stream to another. It is for test stream + -- interface of the library. + + procedure Data_In + (Item : out Stream_Element_Array; + Last : out Stream_Element_Offset); + -- this procedure is for generic instantiation of + -- ZLib.Generic_Translate. + -- reading data from the File_In. + + procedure Data_Out (Item : in Stream_Element_Array); + -- this procedure is for generic instantiation of + -- ZLib.Generic_Translate. + -- writing data to the File_Out. + + procedure Stamp; + -- Store the timestamp to the local variable. + + procedure Print_Statistic (Msg : String; Data_Size : ZLib.Count); + -- Print the time statistic with the message. + + procedure Translate is new ZLib.Generic_Translate + (Data_In => Data_In, + Data_Out => Data_Out); + -- This procedure is moving data from File_In to File_Out + -- with compression or decompression, depend on initialization of + -- Filter parameter. + + ------------------- + -- Compare_Files -- + ------------------- + + procedure Compare_Files (Left, Right : String) is + Left_File, Right_File : File_Type; + begin + Open (Left_File, In_File, Left); + Open (Right_File, In_File, Right); + Compare_Streams (Stream (Left_File).all, Stream (Right_File).all); + Close (Left_File); + Close (Right_File); + end Compare_Files; + + --------------------- + -- Compare_Streams -- + --------------------- + + procedure Compare_Streams + (Left, Right : in out Ada.Streams.Root_Stream_Type'Class) + is + Left_Buffer, Right_Buffer : Stream_Element_Array (0 .. 16#FFF#); + Left_Last, Right_Last : Stream_Element_Offset; + begin + loop + Read (Left, Left_Buffer, Left_Last); + Read (Right, Right_Buffer, Right_Last); + + if Left_Last /= Right_Last then + Ada.Text_IO.Put_Line ("Compare error :" + & Stream_Element_Offset'Image (Left_Last) + & " /= " + & Stream_Element_Offset'Image (Right_Last)); + + raise Constraint_Error; + + elsif Left_Buffer (0 .. Left_Last) + /= Right_Buffer (0 .. Right_Last) + then + Ada.Text_IO.Put_Line ("ERROR: IN and OUT files is not equal."); + raise Constraint_Error; + + end if; + + exit when Left_Last < Left_Buffer'Last; + end loop; + end Compare_Streams; + + ------------------ + -- Copy_Streams -- + ------------------ + + procedure Copy_Streams + (Source, Target : in out Ada.Streams.Root_Stream_Type'Class; + Buffer_Size : in Stream_Element_Offset := 1024) + is + Buffer : Stream_Element_Array (1 .. Buffer_Size); + Last : Stream_Element_Offset; + begin + loop + Read (Source, Buffer, Last); + Write (Target, Buffer (1 .. Last)); + + exit when Last < Buffer'Last; + end loop; + end Copy_Streams; + + ------------- + -- Data_In -- + ------------- + + procedure Data_In + (Item : out Stream_Element_Array; + Last : out Stream_Element_Offset) is + begin + Read (File_In, Item, Last); + end Data_In; + + -------------- + -- Data_Out -- + -------------- + + procedure Data_Out (Item : in Stream_Element_Array) is + begin + Write (File_Out, Item); + end Data_Out; + + ------------------- + -- Generate_File -- + ------------------- + + procedure Generate_File is + subtype Visible_Symbols is Stream_Element range 16#20# .. 16#7E#; + + package Random_Elements is + new Ada.Numerics.Discrete_Random (Visible_Symbols); + + Gen : Random_Elements.Generator; + Buffer : Stream_Element_Array := (1 .. 77 => 16#20#) & 10; + + Buffer_Count : constant Count := File_Size / Buffer'Length; + -- Number of same buffers in the packet. + + Density : constant Count := 30; -- from 0 to Buffer'Length - 2; + + procedure Fill_Buffer (J, D : in Count); + -- Change the part of the buffer. + + ----------------- + -- Fill_Buffer -- + ----------------- + + procedure Fill_Buffer (J, D : in Count) is + begin + for K in 0 .. D loop + Buffer + (Stream_Element_Offset ((J + K) mod (Buffer'Length - 1) + 1)) + := Random_Elements.Random (Gen); + + end loop; + end Fill_Buffer; + + begin + Random_Elements.Reset (Gen, Init_Random); + + Create (File_In, Out_File, In_File_Name); + + Fill_Buffer (1, Buffer'Length - 2); + + for J in 1 .. Buffer_Count loop + Write (File_In, Buffer); + + Fill_Buffer (J, Density); + end loop; + + -- fill remain size. + + Write + (File_In, + Buffer + (1 .. Stream_Element_Offset + (File_Size - Buffer'Length * Buffer_Count))); + + Flush (File_In); + Close (File_In); + end Generate_File; + + --------------------- + -- Print_Statistic -- + --------------------- + + procedure Print_Statistic (Msg : String; Data_Size : ZLib.Count) is + use Ada.Calendar; + use Ada.Text_IO; + + package Count_IO is new Integer_IO (ZLib.Count); + + Curr_Dur : Duration := Clock - Time_Stamp; + begin + Put (Msg); + + Set_Col (20); + Ada.Text_IO.Put ("size ="); + + Count_IO.Put + (Data_Size, + Width => Stream_IO.Count'Image (File_Size)'Length); + + Put_Line (" duration =" & Duration'Image (Curr_Dur)); + end Print_Statistic; + + ----------- + -- Stamp -- + ----------- + + procedure Stamp is + begin + Time_Stamp := Ada.Calendar.Clock; + end Stamp; + +begin + Ada.Text_IO.Put_Line ("ZLib " & ZLib.Version); + + loop + Generate_File; + + for Level in ZLib.Compression_Level'Range loop + + Ada.Text_IO.Put_Line ("Level =" + & ZLib.Compression_Level'Image (Level)); + + -- Test generic interface. + Open (File_In, In_File, In_File_Name); + Create (File_Out, Out_File, Z_File_Name); + + Stamp; + + -- Deflate using generic instantiation. + + ZLib.Deflate_Init + (Filter => Filter, + Level => Level, + Strategy => Strategy, + Header => Header); + + Translate (Filter); + Print_Statistic ("Generic compress", ZLib.Total_Out (Filter)); + ZLib.Close (Filter); + + Close (File_In); + Close (File_Out); + + Open (File_In, In_File, Z_File_Name); + Create (File_Out, Out_File, Out_File_Name); + + Stamp; + + -- Inflate using generic instantiation. + + ZLib.Inflate_Init (Filter, Header => Header); + + Translate (Filter); + Print_Statistic ("Generic decompress", ZLib.Total_Out (Filter)); + + ZLib.Close (Filter); + + Close (File_In); + Close (File_Out); + + Compare_Files (In_File_Name, Out_File_Name); + + -- Test stream interface. + + -- Compress to the back stream. + + Open (File_In, In_File, In_File_Name); + Create (File_Back, Out_File, Z_File_Name); + + Stamp; + + ZLib.Streams.Create + (Stream => File_Z, + Mode => ZLib.Streams.Out_Stream, + Back => ZLib.Streams.Stream_Access + (Stream (File_Back)), + Back_Compressed => True, + Level => Level, + Strategy => Strategy, + Header => Header); + + Copy_Streams + (Source => Stream (File_In).all, + Target => File_Z); + + -- Flushing internal buffers to the back stream. + + ZLib.Streams.Flush (File_Z, ZLib.Finish); + + Print_Statistic ("Write compress", + ZLib.Streams.Write_Total_Out (File_Z)); + + ZLib.Streams.Close (File_Z); + + Close (File_In); + Close (File_Back); + + -- Compare reading from original file and from + -- decompression stream. + + Open (File_In, In_File, In_File_Name); + Open (File_Back, In_File, Z_File_Name); + + ZLib.Streams.Create + (Stream => File_Z, + Mode => ZLib.Streams.In_Stream, + Back => ZLib.Streams.Stream_Access + (Stream (File_Back)), + Back_Compressed => True, + Header => Header); + + Stamp; + Compare_Streams (Stream (File_In).all, File_Z); + + Print_Statistic ("Read decompress", + ZLib.Streams.Read_Total_Out (File_Z)); + + ZLib.Streams.Close (File_Z); + Close (File_In); + Close (File_Back); + + -- Compress by reading from compression stream. + + Open (File_Back, In_File, In_File_Name); + Create (File_Out, Out_File, Z_File_Name); + + ZLib.Streams.Create + (Stream => File_Z, + Mode => ZLib.Streams.In_Stream, + Back => ZLib.Streams.Stream_Access + (Stream (File_Back)), + Back_Compressed => False, + Level => Level, + Strategy => Strategy, + Header => Header); + + Stamp; + Copy_Streams + (Source => File_Z, + Target => Stream (File_Out).all); + + Print_Statistic ("Read compress", + ZLib.Streams.Read_Total_Out (File_Z)); + + ZLib.Streams.Close (File_Z); + + Close (File_Out); + Close (File_Back); + + -- Decompress to decompression stream. + + Open (File_In, In_File, Z_File_Name); + Create (File_Back, Out_File, Out_File_Name); + + ZLib.Streams.Create + (Stream => File_Z, + Mode => ZLib.Streams.Out_Stream, + Back => ZLib.Streams.Stream_Access + (Stream (File_Back)), + Back_Compressed => False, + Header => Header); + + Stamp; + + Copy_Streams + (Source => Stream (File_In).all, + Target => File_Z); + + Print_Statistic ("Write decompress", + ZLib.Streams.Write_Total_Out (File_Z)); + + ZLib.Streams.Close (File_Z); + Close (File_In); + Close (File_Back); + + Compare_Files (In_File_Name, Out_File_Name); + end loop; + + Ada.Text_IO.Put_Line (Count'Image (File_Size) & " Ok."); + + exit when not Continuous; + + File_Size := File_Size + 1; + end loop; +end Test; diff --git a/libs/zlib/contrib/ada/zlib-streams.adb b/libs/zlib/contrib/ada/zlib-streams.adb new file mode 100644 index 000000000..b6497bae2 --- /dev/null +++ b/libs/zlib/contrib/ada/zlib-streams.adb @@ -0,0 +1,225 @@ +---------------------------------------------------------------- +-- ZLib for Ada thick binding. -- +-- -- +-- Copyright (C) 2002-2003 Dmitriy Anisimkov -- +-- -- +-- Open source license information is in the zlib.ads file. -- +---------------------------------------------------------------- + +-- $Id: zlib-streams.adb,v 1.10 2004/05/31 10:53:40 vagul Exp $ + +with Ada.Unchecked_Deallocation; + +package body ZLib.Streams is + + ----------- + -- Close -- + ----------- + + procedure Close (Stream : in out Stream_Type) is + procedure Free is new Ada.Unchecked_Deallocation + (Stream_Element_Array, Buffer_Access); + begin + if Stream.Mode = Out_Stream or Stream.Mode = Duplex then + -- We should flush the data written by the writer. + + Flush (Stream, Finish); + + Close (Stream.Writer); + end if; + + if Stream.Mode = In_Stream or Stream.Mode = Duplex then + Close (Stream.Reader); + Free (Stream.Buffer); + end if; + end Close; + + ------------ + -- Create -- + ------------ + + procedure Create + (Stream : out Stream_Type; + Mode : in Stream_Mode; + Back : in Stream_Access; + Back_Compressed : in Boolean; + Level : in Compression_Level := Default_Compression; + Strategy : in Strategy_Type := Default_Strategy; + Header : in Header_Type := Default; + Read_Buffer_Size : in Ada.Streams.Stream_Element_Offset + := Default_Buffer_Size; + Write_Buffer_Size : in Ada.Streams.Stream_Element_Offset + := Default_Buffer_Size) + is + + subtype Buffer_Subtype is Stream_Element_Array (1 .. Read_Buffer_Size); + + procedure Init_Filter + (Filter : in out Filter_Type; + Compress : in Boolean); + + ----------------- + -- Init_Filter -- + ----------------- + + procedure Init_Filter + (Filter : in out Filter_Type; + Compress : in Boolean) is + begin + if Compress then + Deflate_Init + (Filter, Level, Strategy, Header => Header); + else + Inflate_Init (Filter, Header => Header); + end if; + end Init_Filter; + + begin + Stream.Back := Back; + Stream.Mode := Mode; + + if Mode = Out_Stream or Mode = Duplex then + Init_Filter (Stream.Writer, Back_Compressed); + Stream.Buffer_Size := Write_Buffer_Size; + else + Stream.Buffer_Size := 0; + end if; + + if Mode = In_Stream or Mode = Duplex then + Init_Filter (Stream.Reader, not Back_Compressed); + + Stream.Buffer := new Buffer_Subtype; + Stream.Rest_First := Stream.Buffer'Last + 1; + Stream.Rest_Last := Stream.Buffer'Last; + end if; + end Create; + + ----------- + -- Flush -- + ----------- + + procedure Flush + (Stream : in out Stream_Type; + Mode : in Flush_Mode := Sync_Flush) + is + Buffer : Stream_Element_Array (1 .. Stream.Buffer_Size); + Last : Stream_Element_Offset; + begin + loop + Flush (Stream.Writer, Buffer, Last, Mode); + + Ada.Streams.Write (Stream.Back.all, Buffer (1 .. Last)); + + exit when Last < Buffer'Last; + end loop; + end Flush; + + ------------- + -- Is_Open -- + ------------- + + function Is_Open (Stream : Stream_Type) return Boolean is + begin + return Is_Open (Stream.Reader) or else Is_Open (Stream.Writer); + end Is_Open; + + ---------- + -- Read -- + ---------- + + procedure Read + (Stream : in out Stream_Type; + Item : out Stream_Element_Array; + Last : out Stream_Element_Offset) + is + + procedure Read + (Item : out Stream_Element_Array; + Last : out Stream_Element_Offset); + + ---------- + -- Read -- + ---------- + + procedure Read + (Item : out Stream_Element_Array; + Last : out Stream_Element_Offset) is + begin + Ada.Streams.Read (Stream.Back.all, Item, Last); + end Read; + + procedure Read is new ZLib.Read + (Read => Read, + Buffer => Stream.Buffer.all, + Rest_First => Stream.Rest_First, + Rest_Last => Stream.Rest_Last); + + begin + Read (Stream.Reader, Item, Last); + end Read; + + ------------------- + -- Read_Total_In -- + ------------------- + + function Read_Total_In (Stream : in Stream_Type) return Count is + begin + return Total_In (Stream.Reader); + end Read_Total_In; + + -------------------- + -- Read_Total_Out -- + -------------------- + + function Read_Total_Out (Stream : in Stream_Type) return Count is + begin + return Total_Out (Stream.Reader); + end Read_Total_Out; + + ----------- + -- Write -- + ----------- + + procedure Write + (Stream : in out Stream_Type; + Item : in Stream_Element_Array) + is + + procedure Write (Item : in Stream_Element_Array); + + ----------- + -- Write -- + ----------- + + procedure Write (Item : in Stream_Element_Array) is + begin + Ada.Streams.Write (Stream.Back.all, Item); + end Write; + + procedure Write is new ZLib.Write + (Write => Write, + Buffer_Size => Stream.Buffer_Size); + + begin + Write (Stream.Writer, Item, No_Flush); + end Write; + + -------------------- + -- Write_Total_In -- + -------------------- + + function Write_Total_In (Stream : in Stream_Type) return Count is + begin + return Total_In (Stream.Writer); + end Write_Total_In; + + --------------------- + -- Write_Total_Out -- + --------------------- + + function Write_Total_Out (Stream : in Stream_Type) return Count is + begin + return Total_Out (Stream.Writer); + end Write_Total_Out; + +end ZLib.Streams; diff --git a/libs/zlib/contrib/ada/zlib-streams.ads b/libs/zlib/contrib/ada/zlib-streams.ads new file mode 100644 index 000000000..f0193c6ba --- /dev/null +++ b/libs/zlib/contrib/ada/zlib-streams.ads @@ -0,0 +1,114 @@ +---------------------------------------------------------------- +-- ZLib for Ada thick binding. -- +-- -- +-- Copyright (C) 2002-2003 Dmitriy Anisimkov -- +-- -- +-- Open source license information is in the zlib.ads file. -- +---------------------------------------------------------------- + +-- $Id: zlib-streams.ads,v 1.12 2004/05/31 10:53:40 vagul Exp $ + +package ZLib.Streams is + + type Stream_Mode is (In_Stream, Out_Stream, Duplex); + + type Stream_Access is access all Ada.Streams.Root_Stream_Type'Class; + + type Stream_Type is + new Ada.Streams.Root_Stream_Type with private; + + procedure Read + (Stream : in out Stream_Type; + Item : out Ada.Streams.Stream_Element_Array; + Last : out Ada.Streams.Stream_Element_Offset); + + procedure Write + (Stream : in out Stream_Type; + Item : in Ada.Streams.Stream_Element_Array); + + procedure Flush + (Stream : in out Stream_Type; + Mode : in Flush_Mode := Sync_Flush); + -- Flush the written data to the back stream, + -- all data placed to the compressor is flushing to the Back stream. + -- Should not be used untill necessary, becouse it is decreasing + -- compression. + + function Read_Total_In (Stream : in Stream_Type) return Count; + pragma Inline (Read_Total_In); + -- Return total number of bytes read from back stream so far. + + function Read_Total_Out (Stream : in Stream_Type) return Count; + pragma Inline (Read_Total_Out); + -- Return total number of bytes read so far. + + function Write_Total_In (Stream : in Stream_Type) return Count; + pragma Inline (Write_Total_In); + -- Return total number of bytes written so far. + + function Write_Total_Out (Stream : in Stream_Type) return Count; + pragma Inline (Write_Total_Out); + -- Return total number of bytes written to the back stream. + + procedure Create + (Stream : out Stream_Type; + Mode : in Stream_Mode; + Back : in Stream_Access; + Back_Compressed : in Boolean; + Level : in Compression_Level := Default_Compression; + Strategy : in Strategy_Type := Default_Strategy; + Header : in Header_Type := Default; + Read_Buffer_Size : in Ada.Streams.Stream_Element_Offset + := Default_Buffer_Size; + Write_Buffer_Size : in Ada.Streams.Stream_Element_Offset + := Default_Buffer_Size); + -- Create the Comression/Decompression stream. + -- If mode is In_Stream then Write operation is disabled. + -- If mode is Out_Stream then Read operation is disabled. + + -- If Back_Compressed is true then + -- Data written to the Stream is compressing to the Back stream + -- and data read from the Stream is decompressed data from the Back stream. + + -- If Back_Compressed is false then + -- Data written to the Stream is decompressing to the Back stream + -- and data read from the Stream is compressed data from the Back stream. + + -- !!! When the Need_Header is False ZLib-Ada is using undocumented + -- ZLib 1.1.4 functionality to do not create/wait for ZLib headers. + + function Is_Open (Stream : Stream_Type) return Boolean; + + procedure Close (Stream : in out Stream_Type); + +private + + use Ada.Streams; + + type Buffer_Access is access all Stream_Element_Array; + + type Stream_Type + is new Root_Stream_Type with + record + Mode : Stream_Mode; + + Buffer : Buffer_Access; + Rest_First : Stream_Element_Offset; + Rest_Last : Stream_Element_Offset; + -- Buffer for Read operation. + -- We need to have this buffer in the record + -- becouse not all read data from back stream + -- could be processed during the read operation. + + Buffer_Size : Stream_Element_Offset; + -- Buffer size for write operation. + -- We do not need to have this buffer + -- in the record becouse all data could be + -- processed in the write operation. + + Back : Stream_Access; + Reader : Filter_Type; + Writer : Filter_Type; + end record; + +end ZLib.Streams; diff --git a/libs/zlib/contrib/ada/zlib-thin.adb b/libs/zlib/contrib/ada/zlib-thin.adb new file mode 100644 index 000000000..0ca4a7120 --- /dev/null +++ b/libs/zlib/contrib/ada/zlib-thin.adb @@ -0,0 +1,141 @@ +---------------------------------------------------------------- +-- ZLib for Ada thick binding. -- +-- -- +-- Copyright (C) 2002-2003 Dmitriy Anisimkov -- +-- -- +-- Open source license information is in the zlib.ads file. -- +---------------------------------------------------------------- + +-- $Id: zlib-thin.adb,v 1.8 2003/12/14 18:27:31 vagul Exp $ + +package body ZLib.Thin is + + ZLIB_VERSION : constant Chars_Ptr := zlibVersion; + + Z_Stream_Size : constant Int := Z_Stream'Size / System.Storage_Unit; + + -------------- + -- Avail_In -- + -------------- + + function Avail_In (Strm : in Z_Stream) return UInt is + begin + return Strm.Avail_In; + end Avail_In; + + --------------- + -- Avail_Out -- + --------------- + + function Avail_Out (Strm : in Z_Stream) return UInt is + begin + return Strm.Avail_Out; + end Avail_Out; + + ------------------ + -- Deflate_Init -- + ------------------ + + function Deflate_Init + (strm : Z_Streamp; + level : Int; + method : Int; + windowBits : Int; + memLevel : Int; + strategy : Int) + return Int is + begin + return deflateInit2 + (strm, + level, + method, + windowBits, + memLevel, + strategy, + ZLIB_VERSION, + Z_Stream_Size); + end Deflate_Init; + + ------------------ + -- Inflate_Init -- + ------------------ + + function Inflate_Init (strm : Z_Streamp; windowBits : Int) return Int is + begin + return inflateInit2 (strm, windowBits, ZLIB_VERSION, Z_Stream_Size); + end Inflate_Init; + + ------------------------ + -- Last_Error_Message -- + ------------------------ + + function Last_Error_Message (Strm : in Z_Stream) return String is + use Interfaces.C.Strings; + begin + if Strm.msg = Null_Ptr then + return ""; + else + return Value (Strm.msg); + end if; + end Last_Error_Message; + + ------------ + -- Set_In -- + ------------ + + procedure Set_In + (Strm : in out Z_Stream; + Buffer : in Voidp; + Size : in UInt) is + begin + Strm.Next_In := Buffer; + Strm.Avail_In := Size; + end Set_In; + + ------------------ + -- Set_Mem_Func -- + ------------------ + + procedure Set_Mem_Func + (Strm : in out Z_Stream; + Opaque : in Voidp; + Alloc : in alloc_func; + Free : in free_func) is + begin + Strm.opaque := Opaque; + Strm.zalloc := Alloc; + Strm.zfree := Free; + end Set_Mem_Func; + + ------------- + -- Set_Out -- + ------------- + + procedure Set_Out + (Strm : in out Z_Stream; + Buffer : in Voidp; + Size : in UInt) is + begin + Strm.Next_Out := Buffer; + Strm.Avail_Out := Size; + end Set_Out; + + -------------- + -- Total_In -- + -------------- + + function Total_In (Strm : in Z_Stream) return ULong is + begin + return Strm.Total_In; + end Total_In; + + --------------- + -- Total_Out -- + --------------- + + function Total_Out (Strm : in Z_Stream) return ULong is + begin + return Strm.Total_Out; + end Total_Out; + +end ZLib.Thin; diff --git a/libs/zlib/contrib/ada/zlib-thin.ads b/libs/zlib/contrib/ada/zlib-thin.ads new file mode 100644 index 000000000..d4407eb80 --- /dev/null +++ b/libs/zlib/contrib/ada/zlib-thin.ads @@ -0,0 +1,450 @@ +---------------------------------------------------------------- +-- ZLib for Ada thick binding. -- +-- -- +-- Copyright (C) 2002-2003 Dmitriy Anisimkov -- +-- -- +-- Open source license information is in the zlib.ads file. -- +---------------------------------------------------------------- + +-- $Id: zlib-thin.ads,v 1.11 2004/07/23 06:33:11 vagul Exp $ + +with Interfaces.C.Strings; + +with System; + +private package ZLib.Thin is + + -- From zconf.h + + MAX_MEM_LEVEL : constant := 9; -- zconf.h:105 + -- zconf.h:105 + MAX_WBITS : constant := 15; -- zconf.h:115 + -- 32K LZ77 window + -- zconf.h:115 + SEEK_SET : constant := 8#0000#; -- zconf.h:244 + -- Seek from beginning of file. + -- zconf.h:244 + SEEK_CUR : constant := 1; -- zconf.h:245 + -- Seek from current position. + -- zconf.h:245 + SEEK_END : constant := 2; -- zconf.h:246 + -- Set file pointer to EOF plus "offset" + -- zconf.h:246 + + type Byte is new Interfaces.C.unsigned_char; -- 8 bits + -- zconf.h:214 + type UInt is new Interfaces.C.unsigned; -- 16 bits or more + -- zconf.h:216 + type Int is new Interfaces.C.int; + + type ULong is new Interfaces.C.unsigned_long; -- 32 bits or more + -- zconf.h:217 + subtype Chars_Ptr is Interfaces.C.Strings.chars_ptr; + + type ULong_Access is access ULong; + type Int_Access is access Int; + + subtype Voidp is System.Address; -- zconf.h:232 + + subtype Byte_Access is Voidp; + + Nul : constant Voidp := System.Null_Address; + -- end from zconf + + Z_NO_FLUSH : constant := 8#0000#; -- zlib.h:125 + -- zlib.h:125 + Z_PARTIAL_FLUSH : constant := 1; -- zlib.h:126 + -- will be removed, use + -- Z_SYNC_FLUSH instead + -- zlib.h:126 + Z_SYNC_FLUSH : constant := 2; -- zlib.h:127 + -- zlib.h:127 + Z_FULL_FLUSH : constant := 3; -- zlib.h:128 + -- zlib.h:128 + Z_FINISH : constant := 4; -- zlib.h:129 + -- zlib.h:129 + Z_OK : constant := 8#0000#; -- zlib.h:132 + -- zlib.h:132 + Z_STREAM_END : constant := 1; -- zlib.h:133 + -- zlib.h:133 + Z_NEED_DICT : constant := 2; -- zlib.h:134 + -- zlib.h:134 + Z_ERRNO : constant := -1; -- zlib.h:135 + -- zlib.h:135 + Z_STREAM_ERROR : constant := -2; -- zlib.h:136 + -- zlib.h:136 + Z_DATA_ERROR : constant := -3; -- zlib.h:137 + -- zlib.h:137 + Z_MEM_ERROR : constant := -4; -- zlib.h:138 + -- zlib.h:138 + Z_BUF_ERROR : constant := -5; -- zlib.h:139 + -- zlib.h:139 + Z_VERSION_ERROR : constant := -6; -- zlib.h:140 + -- zlib.h:140 + Z_NO_COMPRESSION : constant := 8#0000#; -- zlib.h:145 + -- zlib.h:145 + Z_BEST_SPEED : constant := 1; -- zlib.h:146 + -- zlib.h:146 + Z_BEST_COMPRESSION : constant := 9; -- zlib.h:147 + -- zlib.h:147 + Z_DEFAULT_COMPRESSION : constant := -1; -- zlib.h:148 + -- zlib.h:148 + Z_FILTERED : constant := 1; -- zlib.h:151 + -- zlib.h:151 + Z_HUFFMAN_ONLY : constant := 2; -- zlib.h:152 + -- zlib.h:152 + Z_DEFAULT_STRATEGY : constant := 8#0000#; -- zlib.h:153 + -- zlib.h:153 + Z_BINARY : constant := 8#0000#; -- zlib.h:156 + -- zlib.h:156 + Z_ASCII : constant := 1; -- zlib.h:157 + -- zlib.h:157 + Z_UNKNOWN : constant := 2; -- zlib.h:158 + -- zlib.h:158 + Z_DEFLATED : constant := 8; -- zlib.h:161 + -- zlib.h:161 + Z_NULL : constant := 8#0000#; -- zlib.h:164 + -- for initializing zalloc, zfree, opaque + -- zlib.h:164 + type gzFile is new Voidp; -- zlib.h:646 + + type Z_Stream is private; + + type Z_Streamp is access all Z_Stream; -- zlib.h:89 + + type alloc_func is access function + (Opaque : Voidp; + Items : UInt; + Size : UInt) + return Voidp; -- zlib.h:63 + + type free_func is access procedure (opaque : Voidp; address : Voidp); + + function zlibVersion return Chars_Ptr; + + function Deflate (strm : Z_Streamp; flush : Int) return Int; + + function DeflateEnd (strm : Z_Streamp) return Int; + + function Inflate (strm : Z_Streamp; flush : Int) return Int; + + function InflateEnd (strm : Z_Streamp) return Int; + + function deflateSetDictionary + (strm : Z_Streamp; + dictionary : Byte_Access; + dictLength : UInt) + return Int; + + function deflateCopy (dest : Z_Streamp; source : Z_Streamp) return Int; + -- zlib.h:478 + + function deflateReset (strm : Z_Streamp) return Int; -- zlib.h:495 + + function deflateParams + (strm : Z_Streamp; + level : Int; + strategy : Int) + return Int; -- zlib.h:506 + + function inflateSetDictionary + (strm : Z_Streamp; + dictionary : Byte_Access; + dictLength : UInt) + return Int; -- zlib.h:548 + + function inflateSync (strm : Z_Streamp) return Int; -- zlib.h:565 + + function inflateReset (strm : Z_Streamp) return Int; -- zlib.h:580 + + function compress + (dest : Byte_Access; + destLen : ULong_Access; + source : Byte_Access; + sourceLen : ULong) + return Int; -- zlib.h:601 + + function compress2 + (dest : Byte_Access; + destLen : ULong_Access; + source : Byte_Access; + sourceLen : ULong; + level : Int) + return Int; -- zlib.h:615 + + function uncompress + (dest : Byte_Access; + destLen : ULong_Access; + source : Byte_Access; + sourceLen : ULong) + return Int; + + function gzopen (path : Chars_Ptr; mode : Chars_Ptr) return gzFile; + + function gzdopen (fd : Int; mode : Chars_Ptr) return gzFile; + + function gzsetparams + (file : gzFile; + level : Int; + strategy : Int) + return Int; + + function gzread + (file : gzFile; + buf : Voidp; + len : UInt) + return Int; + + function gzwrite + (file : in gzFile; + buf : in Voidp; + len : in UInt) + return Int; + + function gzprintf (file : in gzFile; format : in Chars_Ptr) return Int; + + function gzputs (file : in gzFile; s : in Chars_Ptr) return Int; + + function gzgets + (file : gzFile; + buf : Chars_Ptr; + len : Int) + return Chars_Ptr; + + function gzputc (file : gzFile; char : Int) return Int; + + function gzgetc (file : gzFile) return Int; + + function gzflush (file : gzFile; flush : Int) return Int; + + function gzseek + (file : gzFile; + offset : Int; + whence : Int) + return Int; + + function gzrewind (file : gzFile) return Int; + + function gztell (file : gzFile) return Int; + + function gzeof (file : gzFile) return Int; + + function gzclose (file : gzFile) return Int; + + function gzerror (file : gzFile; errnum : Int_Access) return Chars_Ptr; + + function adler32 + (adler : ULong; + buf : Byte_Access; + len : UInt) + return ULong; + + function crc32 + (crc : ULong; + buf : Byte_Access; + len : UInt) + return ULong; + + function deflateInit + (strm : Z_Streamp; + level : Int; + version : Chars_Ptr; + stream_size : Int) + return Int; + + function deflateInit2 + (strm : Z_Streamp; + level : Int; + method : Int; + windowBits : Int; + memLevel : Int; + strategy : Int; + version : Chars_Ptr; + stream_size : Int) + return Int; + + function Deflate_Init + (strm : Z_Streamp; + level : Int; + method : Int; + windowBits : Int; + memLevel : Int; + strategy : Int) + return Int; + pragma Inline (Deflate_Init); + + function inflateInit + (strm : Z_Streamp; + version : Chars_Ptr; + stream_size : Int) + return Int; + + function inflateInit2 + (strm : in Z_Streamp; + windowBits : in Int; + version : in Chars_Ptr; + stream_size : in Int) + return Int; + + function inflateBackInit + (strm : in Z_Streamp; + windowBits : in Int; + window : in Byte_Access; + version : in Chars_Ptr; + stream_size : in Int) + return Int; + -- Size of window have to be 2**windowBits. + + function Inflate_Init (strm : Z_Streamp; windowBits : Int) return Int; + pragma Inline (Inflate_Init); + + function zError (err : Int) return Chars_Ptr; + + function inflateSyncPoint (z : Z_Streamp) return Int; + + function get_crc_table return ULong_Access; + + -- Interface to the available fields of the z_stream structure. + -- The application must update next_in and avail_in when avail_in has + -- dropped to zero. It must update next_out and avail_out when avail_out + -- has dropped to zero. The application must initialize zalloc, zfree and + -- opaque before calling the init function. + + procedure Set_In + (Strm : in out Z_Stream; + Buffer : in Voidp; + Size : in UInt); + pragma Inline (Set_In); + + procedure Set_Out + (Strm : in out Z_Stream; + Buffer : in Voidp; + Size : in UInt); + pragma Inline (Set_Out); + + procedure Set_Mem_Func + (Strm : in out Z_Stream; + Opaque : in Voidp; + Alloc : in alloc_func; + Free : in free_func); + pragma Inline (Set_Mem_Func); + + function Last_Error_Message (Strm : in Z_Stream) return String; + pragma Inline (Last_Error_Message); + + function Avail_Out (Strm : in Z_Stream) return UInt; + pragma Inline (Avail_Out); + + function Avail_In (Strm : in Z_Stream) return UInt; + pragma Inline (Avail_In); + + function Total_In (Strm : in Z_Stream) return ULong; + pragma Inline (Total_In); + + function Total_Out (Strm : in Z_Stream) return ULong; + pragma Inline (Total_Out); + + function inflateCopy + (dest : in Z_Streamp; + Source : in Z_Streamp) + return Int; + + function compressBound (Source_Len : in ULong) return ULong; + + function deflateBound + (Strm : in Z_Streamp; + Source_Len : in ULong) + return ULong; + + function gzungetc (C : in Int; File : in gzFile) return Int; + + function zlibCompileFlags return ULong; + +private + + type Z_Stream is record -- zlib.h:68 + Next_In : Voidp := Nul; -- next input byte + Avail_In : UInt := 0; -- number of bytes available at next_in + Total_In : ULong := 0; -- total nb of input bytes read so far + Next_Out : Voidp := Nul; -- next output byte should be put there + Avail_Out : UInt := 0; -- remaining free space at next_out + Total_Out : ULong := 0; -- total nb of bytes output so far + msg : Chars_Ptr; -- last error message, NULL if no error + state : Voidp; -- not visible by applications + zalloc : alloc_func := null; -- used to allocate the internal state + zfree : free_func := null; -- used to free the internal state + opaque : Voidp; -- private data object passed to + -- zalloc and zfree + data_type : Int; -- best guess about the data type: + -- ascii or binary + adler : ULong; -- adler32 value of the uncompressed + -- data + reserved : ULong; -- reserved for future use + end record; + + pragma Convention (C, Z_Stream); + + pragma Import (C, zlibVersion, "zlibVersion"); + pragma Import (C, Deflate, "deflate"); + pragma Import (C, DeflateEnd, "deflateEnd"); + pragma Import (C, Inflate, "inflate"); + pragma Import (C, InflateEnd, "inflateEnd"); + pragma Import (C, deflateSetDictionary, "deflateSetDictionary"); + pragma Import (C, deflateCopy, "deflateCopy"); + pragma Import (C, deflateReset, "deflateReset"); + pragma Import (C, deflateParams, "deflateParams"); + pragma Import (C, inflateSetDictionary, "inflateSetDictionary"); + pragma Import (C, inflateSync, "inflateSync"); + pragma Import (C, inflateReset, "inflateReset"); + pragma Import (C, compress, "compress"); + pragma Import (C, compress2, "compress2"); + pragma Import (C, uncompress, "uncompress"); + pragma Import (C, gzopen, "gzopen"); + pragma Import (C, gzdopen, "gzdopen"); + pragma Import (C, gzsetparams, "gzsetparams"); + pragma Import (C, gzread, "gzread"); + pragma Import (C, gzwrite, "gzwrite"); + pragma Import (C, gzprintf, "gzprintf"); + pragma Import (C, gzputs, "gzputs"); + pragma Import (C, gzgets, "gzgets"); + pragma Import (C, gzputc, "gzputc"); + pragma Import (C, gzgetc, "gzgetc"); + pragma Import (C, gzflush, "gzflush"); + pragma Import (C, gzseek, "gzseek"); + pragma Import (C, gzrewind, "gzrewind"); + pragma Import (C, gztell, "gztell"); + pragma Import (C, gzeof, "gzeof"); + pragma Import (C, gzclose, "gzclose"); + pragma Import (C, gzerror, "gzerror"); + pragma Import (C, adler32, "adler32"); + pragma Import (C, crc32, "crc32"); + pragma Import (C, deflateInit, "deflateInit_"); + pragma Import (C, inflateInit, "inflateInit_"); + pragma Import (C, deflateInit2, "deflateInit2_"); + pragma Import (C, inflateInit2, "inflateInit2_"); + pragma Import (C, zError, "zError"); + pragma Import (C, inflateSyncPoint, "inflateSyncPoint"); + pragma Import (C, get_crc_table, "get_crc_table"); + + -- since zlib 1.2.0: + + pragma Import (C, inflateCopy, "inflateCopy"); + pragma Import (C, compressBound, "compressBound"); + pragma Import (C, deflateBound, "deflateBound"); + pragma Import (C, gzungetc, "gzungetc"); + pragma Import (C, zlibCompileFlags, "zlibCompileFlags"); + + pragma Import (C, inflateBackInit, "inflateBackInit_"); + + -- I stopped binding the inflateBack routines, becouse realize that + -- it does not support zlib and gzip headers for now, and have no + -- symmetric deflateBack routines. + -- ZLib-Ada is symmetric regarding deflate/inflate data transformation + -- and has a similar generic callback interface for the + -- deflate/inflate transformation based on the regular Deflate/Inflate + -- routines. + + -- pragma Import (C, inflateBack, "inflateBack"); + -- pragma Import (C, inflateBackEnd, "inflateBackEnd"); + +end ZLib.Thin; diff --git a/libs/zlib/contrib/ada/zlib.adb b/libs/zlib/contrib/ada/zlib.adb new file mode 100644 index 000000000..8b6fd686a --- /dev/null +++ b/libs/zlib/contrib/ada/zlib.adb @@ -0,0 +1,701 @@ +---------------------------------------------------------------- +-- ZLib for Ada thick binding. -- +-- -- +-- Copyright (C) 2002-2004 Dmitriy Anisimkov -- +-- -- +-- Open source license information is in the zlib.ads file. -- +---------------------------------------------------------------- + +-- $Id: zlib.adb,v 1.31 2004/09/06 06:53:19 vagul Exp $ + +with Ada.Exceptions; +with Ada.Unchecked_Conversion; +with Ada.Unchecked_Deallocation; + +with Interfaces.C.Strings; + +with ZLib.Thin; + +package body ZLib is + + use type Thin.Int; + + type Z_Stream is new Thin.Z_Stream; + + type Return_Code_Enum is + (OK, + STREAM_END, + NEED_DICT, + ERRNO, + STREAM_ERROR, + DATA_ERROR, + MEM_ERROR, + BUF_ERROR, + VERSION_ERROR); + + type Flate_Step_Function is access + function (Strm : in Thin.Z_Streamp; Flush : in Thin.Int) return Thin.Int; + pragma Convention (C, Flate_Step_Function); + + type Flate_End_Function is access + function (Ctrm : in Thin.Z_Streamp) return Thin.Int; + pragma Convention (C, Flate_End_Function); + + type Flate_Type is record + Step : Flate_Step_Function; + Done : Flate_End_Function; + end record; + + subtype Footer_Array is Stream_Element_Array (1 .. 8); + + Simple_GZip_Header : constant Stream_Element_Array (1 .. 10) + := (16#1f#, 16#8b#, -- Magic header + 16#08#, -- Z_DEFLATED + 16#00#, -- Flags + 16#00#, 16#00#, 16#00#, 16#00#, -- Time + 16#00#, -- XFlags + 16#03# -- OS code + ); + -- The simplest gzip header is not for informational, but just for + -- gzip format compatibility. + -- Note that some code below is using assumption + -- Simple_GZip_Header'Last > Footer_Array'Last, so do not make + -- Simple_GZip_Header'Last <= Footer_Array'Last. + + Return_Code : constant array (Thin.Int range <>) of Return_Code_Enum + := (0 => OK, + 1 => STREAM_END, + 2 => NEED_DICT, + -1 => ERRNO, + -2 => STREAM_ERROR, + -3 => DATA_ERROR, + -4 => MEM_ERROR, + -5 => BUF_ERROR, + -6 => VERSION_ERROR); + + Flate : constant array (Boolean) of Flate_Type + := (True => (Step => Thin.Deflate'Access, + Done => Thin.DeflateEnd'Access), + False => (Step => Thin.Inflate'Access, + Done => Thin.InflateEnd'Access)); + + Flush_Finish : constant array (Boolean) of Flush_Mode + := (True => Finish, False => No_Flush); + + procedure Raise_Error (Stream : in Z_Stream); + pragma Inline (Raise_Error); + + procedure Raise_Error (Message : in String); + pragma Inline (Raise_Error); + + procedure Check_Error (Stream : in Z_Stream; Code : in Thin.Int); + + procedure Free is new Ada.Unchecked_Deallocation + (Z_Stream, Z_Stream_Access); + + function To_Thin_Access is new Ada.Unchecked_Conversion + (Z_Stream_Access, Thin.Z_Streamp); + + procedure Translate_GZip + (Filter : in out Filter_Type; + In_Data : in Ada.Streams.Stream_Element_Array; + In_Last : out Ada.Streams.Stream_Element_Offset; + Out_Data : out Ada.Streams.Stream_Element_Array; + Out_Last : out Ada.Streams.Stream_Element_Offset; + Flush : in Flush_Mode); + -- Separate translate routine for make gzip header. + + procedure Translate_Auto + (Filter : in out Filter_Type; + In_Data : in Ada.Streams.Stream_Element_Array; + In_Last : out Ada.Streams.Stream_Element_Offset; + Out_Data : out Ada.Streams.Stream_Element_Array; + Out_Last : out Ada.Streams.Stream_Element_Offset; + Flush : in Flush_Mode); + -- translate routine without additional headers. + + ----------------- + -- Check_Error -- + ----------------- + + procedure Check_Error (Stream : in Z_Stream; Code : in Thin.Int) is + use type Thin.Int; + begin + if Code /= Thin.Z_OK then + Raise_Error + (Return_Code_Enum'Image (Return_Code (Code)) + & ": " & Last_Error_Message (Stream)); + end if; + end Check_Error; + + ----------- + -- Close -- + ----------- + + procedure Close + (Filter : in out Filter_Type; + Ignore_Error : in Boolean := False) + is + Code : Thin.Int; + begin + if not Ignore_Error and then not Is_Open (Filter) then + raise Status_Error; + end if; + + Code := Flate (Filter.Compression).Done (To_Thin_Access (Filter.Strm)); + + if Ignore_Error or else Code = Thin.Z_OK then + Free (Filter.Strm); + else + declare + Error_Message : constant String + := Last_Error_Message (Filter.Strm.all); + begin + Free (Filter.Strm); + Ada.Exceptions.Raise_Exception + (ZLib_Error'Identity, + Return_Code_Enum'Image (Return_Code (Code)) + & ": " & Error_Message); + end; + end if; + end Close; + + ----------- + -- CRC32 -- + ----------- + + function CRC32 + (CRC : in Unsigned_32; + Data : in Ada.Streams.Stream_Element_Array) + return Unsigned_32 + is + use Thin; + begin + return Unsigned_32 (crc32 (ULong (CRC), + Data'Address, + Data'Length)); + end CRC32; + + procedure CRC32 + (CRC : in out Unsigned_32; + Data : in Ada.Streams.Stream_Element_Array) is + begin + CRC := CRC32 (CRC, Data); + end CRC32; + + ------------------ + -- Deflate_Init -- + ------------------ + + procedure Deflate_Init + (Filter : in out Filter_Type; + Level : in Compression_Level := Default_Compression; + Strategy : in Strategy_Type := Default_Strategy; + Method : in Compression_Method := Deflated; + Window_Bits : in Window_Bits_Type := Default_Window_Bits; + Memory_Level : in Memory_Level_Type := Default_Memory_Level; + Header : in Header_Type := Default) + is + use type Thin.Int; + Win_Bits : Thin.Int := Thin.Int (Window_Bits); + begin + if Is_Open (Filter) then + raise Status_Error; + end if; + + -- We allow ZLib to make header only in case of default header type. + -- Otherwise we would either do header by ourselfs, or do not do + -- header at all. + + if Header = None or else Header = GZip then + Win_Bits := -Win_Bits; + end if; + + -- For the GZip CRC calculation and make headers. + + if Header = GZip then + Filter.CRC := 0; + Filter.Offset := Simple_GZip_Header'First; + else + Filter.Offset := Simple_GZip_Header'Last + 1; + end if; + + Filter.Strm := new Z_Stream; + Filter.Compression := True; + Filter.Stream_End := False; + Filter.Header := Header; + + if Thin.Deflate_Init + (To_Thin_Access (Filter.Strm), + Level => Thin.Int (Level), + method => Thin.Int (Method), + windowBits => Win_Bits, + memLevel => Thin.Int (Memory_Level), + strategy => Thin.Int (Strategy)) /= Thin.Z_OK + then + Raise_Error (Filter.Strm.all); + end if; + end Deflate_Init; + + ----------- + -- Flush -- + ----------- + + procedure Flush + (Filter : in out Filter_Type; + Out_Data : out Ada.Streams.Stream_Element_Array; + Out_Last : out Ada.Streams.Stream_Element_Offset; + Flush : in Flush_Mode) + is + No_Data : Stream_Element_Array := (1 .. 0 => 0); + Last : Stream_Element_Offset; + begin + Translate (Filter, No_Data, Last, Out_Data, Out_Last, Flush); + end Flush; + + ----------------------- + -- Generic_Translate -- + ----------------------- + + procedure Generic_Translate + (Filter : in out ZLib.Filter_Type; + In_Buffer_Size : in Integer := Default_Buffer_Size; + Out_Buffer_Size : in Integer := Default_Buffer_Size) + is + In_Buffer : Stream_Element_Array + (1 .. Stream_Element_Offset (In_Buffer_Size)); + Out_Buffer : Stream_Element_Array + (1 .. Stream_Element_Offset (Out_Buffer_Size)); + Last : Stream_Element_Offset; + In_Last : Stream_Element_Offset; + In_First : Stream_Element_Offset; + Out_Last : Stream_Element_Offset; + begin + Main : loop + Data_In (In_Buffer, Last); + + In_First := In_Buffer'First; + + loop + Translate + (Filter => Filter, + In_Data => In_Buffer (In_First .. Last), + In_Last => In_Last, + Out_Data => Out_Buffer, + Out_Last => Out_Last, + Flush => Flush_Finish (Last < In_Buffer'First)); + + if Out_Buffer'First <= Out_Last then + Data_Out (Out_Buffer (Out_Buffer'First .. Out_Last)); + end if; + + exit Main when Stream_End (Filter); + + -- The end of in buffer. + + exit when In_Last = Last; + + In_First := In_Last + 1; + end loop; + end loop Main; + + end Generic_Translate; + + ------------------ + -- Inflate_Init -- + ------------------ + + procedure Inflate_Init + (Filter : in out Filter_Type; + Window_Bits : in Window_Bits_Type := Default_Window_Bits; + Header : in Header_Type := Default) + is + use type Thin.Int; + Win_Bits : Thin.Int := Thin.Int (Window_Bits); + + procedure Check_Version; + -- Check the latest header types compatibility. + + procedure Check_Version is + begin + if Version <= "1.1.4" then + Raise_Error + ("Inflate header type " & Header_Type'Image (Header) + & " incompatible with ZLib version " & Version); + end if; + end Check_Version; + + begin + if Is_Open (Filter) then + raise Status_Error; + end if; + + case Header is + when None => + Check_Version; + + -- Inflate data without headers determined + -- by negative Win_Bits. + + Win_Bits := -Win_Bits; + when GZip => + Check_Version; + + -- Inflate gzip data defined by flag 16. + + Win_Bits := Win_Bits + 16; + when Auto => + Check_Version; + + -- Inflate with automatic detection + -- of gzip or native header defined by flag 32. + + Win_Bits := Win_Bits + 32; + when Default => null; + end case; + + Filter.Strm := new Z_Stream; + Filter.Compression := False; + Filter.Stream_End := False; + Filter.Header := Header; + + if Thin.Inflate_Init + (To_Thin_Access (Filter.Strm), Win_Bits) /= Thin.Z_OK + then + Raise_Error (Filter.Strm.all); + end if; + end Inflate_Init; + + ------------- + -- Is_Open -- + ------------- + + function Is_Open (Filter : in Filter_Type) return Boolean is + begin + return Filter.Strm /= null; + end Is_Open; + + ----------------- + -- Raise_Error -- + ----------------- + + procedure Raise_Error (Message : in String) is + begin + Ada.Exceptions.Raise_Exception (ZLib_Error'Identity, Message); + end Raise_Error; + + procedure Raise_Error (Stream : in Z_Stream) is + begin + Raise_Error (Last_Error_Message (Stream)); + end Raise_Error; + + ---------- + -- Read -- + ---------- + + procedure Read + (Filter : in out Filter_Type; + Item : out Ada.Streams.Stream_Element_Array; + Last : out Ada.Streams.Stream_Element_Offset; + Flush : in Flush_Mode := No_Flush) + is + In_Last : Stream_Element_Offset; + Item_First : Ada.Streams.Stream_Element_Offset := Item'First; + V_Flush : Flush_Mode := Flush; + + begin + pragma Assert (Rest_First in Buffer'First .. Buffer'Last + 1); + pragma Assert (Rest_Last in Buffer'First - 1 .. Buffer'Last); + + loop + if Rest_Last = Buffer'First - 1 then + V_Flush := Finish; + + elsif Rest_First > Rest_Last then + Read (Buffer, Rest_Last); + Rest_First := Buffer'First; + + if Rest_Last < Buffer'First then + V_Flush := Finish; + end if; + end if; + + Translate + (Filter => Filter, + In_Data => Buffer (Rest_First .. Rest_Last), + In_Last => In_Last, + Out_Data => Item (Item_First .. Item'Last), + Out_Last => Last, + Flush => V_Flush); + + Rest_First := In_Last + 1; + + exit when Stream_End (Filter) + or else Last = Item'Last + or else (Last >= Item'First and then Allow_Read_Some); + + Item_First := Last + 1; + end loop; + end Read; + + ---------------- + -- Stream_End -- + ---------------- + + function Stream_End (Filter : in Filter_Type) return Boolean is + begin + if Filter.Header = GZip and Filter.Compression then + return Filter.Stream_End + and then Filter.Offset = Footer_Array'Last + 1; + else + return Filter.Stream_End; + end if; + end Stream_End; + + -------------- + -- Total_In -- + -------------- + + function Total_In (Filter : in Filter_Type) return Count is + begin + return Count (Thin.Total_In (To_Thin_Access (Filter.Strm).all)); + end Total_In; + + --------------- + -- Total_Out -- + --------------- + + function Total_Out (Filter : in Filter_Type) return Count is + begin + return Count (Thin.Total_Out (To_Thin_Access (Filter.Strm).all)); + end Total_Out; + + --------------- + -- Translate -- + --------------- + + procedure Translate + (Filter : in out Filter_Type; + In_Data : in Ada.Streams.Stream_Element_Array; + In_Last : out Ada.Streams.Stream_Element_Offset; + Out_Data : out Ada.Streams.Stream_Element_Array; + Out_Last : out Ada.Streams.Stream_Element_Offset; + Flush : in Flush_Mode) is + begin + if Filter.Header = GZip and then Filter.Compression then + Translate_GZip + (Filter => Filter, + In_Data => In_Data, + In_Last => In_Last, + Out_Data => Out_Data, + Out_Last => Out_Last, + Flush => Flush); + else + Translate_Auto + (Filter => Filter, + In_Data => In_Data, + In_Last => In_Last, + Out_Data => Out_Data, + Out_Last => Out_Last, + Flush => Flush); + end if; + end Translate; + + -------------------- + -- Translate_Auto -- + -------------------- + + procedure Translate_Auto + (Filter : in out Filter_Type; + In_Data : in Ada.Streams.Stream_Element_Array; + In_Last : out Ada.Streams.Stream_Element_Offset; + Out_Data : out Ada.Streams.Stream_Element_Array; + Out_Last : out Ada.Streams.Stream_Element_Offset; + Flush : in Flush_Mode) + is + use type Thin.Int; + Code : Thin.Int; + + begin + if not Is_Open (Filter) then + raise Status_Error; + end if; + + if Out_Data'Length = 0 and then In_Data'Length = 0 then + raise Constraint_Error; + end if; + + Set_Out (Filter.Strm.all, Out_Data'Address, Out_Data'Length); + Set_In (Filter.Strm.all, In_Data'Address, In_Data'Length); + + Code := Flate (Filter.Compression).Step + (To_Thin_Access (Filter.Strm), + Thin.Int (Flush)); + + if Code = Thin.Z_STREAM_END then + Filter.Stream_End := True; + else + Check_Error (Filter.Strm.all, Code); + end if; + + In_Last := In_Data'Last + - Stream_Element_Offset (Avail_In (Filter.Strm.all)); + Out_Last := Out_Data'Last + - Stream_Element_Offset (Avail_Out (Filter.Strm.all)); + end Translate_Auto; + + -------------------- + -- Translate_GZip -- + -------------------- + + procedure Translate_GZip + (Filter : in out Filter_Type; + In_Data : in Ada.Streams.Stream_Element_Array; + In_Last : out Ada.Streams.Stream_Element_Offset; + Out_Data : out Ada.Streams.Stream_Element_Array; + Out_Last : out Ada.Streams.Stream_Element_Offset; + Flush : in Flush_Mode) + is + Out_First : Stream_Element_Offset; + + procedure Add_Data (Data : in Stream_Element_Array); + -- Add data to stream from the Filter.Offset till necessary, + -- used for add gzip headr/footer. + + procedure Put_32 + (Item : in out Stream_Element_Array; + Data : in Unsigned_32); + pragma Inline (Put_32); + + -------------- + -- Add_Data -- + -------------- + + procedure Add_Data (Data : in Stream_Element_Array) is + Data_First : Stream_Element_Offset renames Filter.Offset; + Data_Last : Stream_Element_Offset; + Data_Len : Stream_Element_Offset; -- -1 + Out_Len : Stream_Element_Offset; -- -1 + begin + Out_First := Out_Last + 1; + + if Data_First > Data'Last then + return; + end if; + + Data_Len := Data'Last - Data_First; + Out_Len := Out_Data'Last - Out_First; + + if Data_Len <= Out_Len then + Out_Last := Out_First + Data_Len; + Data_Last := Data'Last; + else + Out_Last := Out_Data'Last; + Data_Last := Data_First + Out_Len; + end if; + + Out_Data (Out_First .. Out_Last) := Data (Data_First .. Data_Last); + + Data_First := Data_Last + 1; + Out_First := Out_Last + 1; + end Add_Data; + + ------------ + -- Put_32 -- + ------------ + + procedure Put_32 + (Item : in out Stream_Element_Array; + Data : in Unsigned_32) + is + D : Unsigned_32 := Data; + begin + for J in Item'First .. Item'First + 3 loop + Item (J) := Stream_Element (D and 16#FF#); + D := Shift_Right (D, 8); + end loop; + end Put_32; + + begin + Out_Last := Out_Data'First - 1; + + if not Filter.Stream_End then + Add_Data (Simple_GZip_Header); + + Translate_Auto + (Filter => Filter, + In_Data => In_Data, + In_Last => In_Last, + Out_Data => Out_Data (Out_First .. Out_Data'Last), + Out_Last => Out_Last, + Flush => Flush); + + CRC32 (Filter.CRC, In_Data (In_Data'First .. In_Last)); + end if; + + if Filter.Stream_End and then Out_Last <= Out_Data'Last then + -- This detection method would work only when + -- Simple_GZip_Header'Last > Footer_Array'Last + + if Filter.Offset = Simple_GZip_Header'Last + 1 then + Filter.Offset := Footer_Array'First; + end if; + + declare + Footer : Footer_Array; + begin + Put_32 (Footer, Filter.CRC); + Put_32 (Footer (Footer'First + 4 .. Footer'Last), + Unsigned_32 (Total_In (Filter))); + Add_Data (Footer); + end; + end if; + end Translate_GZip; + + ------------- + -- Version -- + ------------- + + function Version return String is + begin + return Interfaces.C.Strings.Value (Thin.zlibVersion); + end Version; + + ----------- + -- Write -- + ----------- + + procedure Write + (Filter : in out Filter_Type; + Item : in Ada.Streams.Stream_Element_Array; + Flush : in Flush_Mode := No_Flush) + is + Buffer : Stream_Element_Array (1 .. Buffer_Size); + In_Last : Stream_Element_Offset; + Out_Last : Stream_Element_Offset; + In_First : Stream_Element_Offset := Item'First; + begin + if Item'Length = 0 and Flush = No_Flush then + return; + end if; + + loop + Translate + (Filter => Filter, + In_Data => Item (In_First .. Item'Last), + In_Last => In_Last, + Out_Data => Buffer, + Out_Last => Out_Last, + Flush => Flush); + + if Out_Last >= Buffer'First then + Write (Buffer (1 .. Out_Last)); + end if; + + exit when In_Last = Item'Last or Stream_End (Filter); + + In_First := In_Last + 1; + end loop; + end Write; + +end ZLib; diff --git a/libs/zlib/contrib/ada/zlib.ads b/libs/zlib/contrib/ada/zlib.ads new file mode 100644 index 000000000..79ffc4095 --- /dev/null +++ b/libs/zlib/contrib/ada/zlib.ads @@ -0,0 +1,328 @@ +------------------------------------------------------------------------------ +-- ZLib for Ada thick binding. -- +-- -- +-- Copyright (C) 2002-2004 Dmitriy Anisimkov -- +-- -- +-- This library is free software; you can redistribute it and/or modify -- +-- it under the terms of the GNU General Public License as published by -- +-- the Free Software Foundation; either version 2 of the License, or (at -- +-- your option) any later version. -- +-- -- +-- This 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 -- +-- General Public License for more details. -- +-- -- +-- You should have received a copy of the GNU 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. -- +-- -- +-- As a special exception, if other files instantiate generics from this -- +-- unit, or you link this unit with other files to produce an executable, -- +-- this unit does not by itself cause the resulting executable to be -- +-- covered by the GNU General Public License. This exception does not -- +-- however invalidate any other reasons why the executable file might be -- +-- covered by the GNU Public License. -- +------------------------------------------------------------------------------ + +-- $Id: zlib.ads,v 1.26 2004/09/06 06:53:19 vagul Exp $ + +with Ada.Streams; + +with Interfaces; + +package ZLib is + + ZLib_Error : exception; + Status_Error : exception; + + type Compression_Level is new Integer range -1 .. 9; + + type Flush_Mode is private; + + type Compression_Method is private; + + type Window_Bits_Type is new Integer range 8 .. 15; + + type Memory_Level_Type is new Integer range 1 .. 9; + + type Unsigned_32 is new Interfaces.Unsigned_32; + + type Strategy_Type is private; + + type Header_Type is (None, Auto, Default, GZip); + -- Header type usage have a some limitation for inflate. + -- See comment for Inflate_Init. + + subtype Count is Ada.Streams.Stream_Element_Count; + + Default_Memory_Level : constant Memory_Level_Type := 8; + Default_Window_Bits : constant Window_Bits_Type := 15; + + ---------------------------------- + -- Compression method constants -- + ---------------------------------- + + Deflated : constant Compression_Method; + -- Only one method allowed in this ZLib version + + --------------------------------- + -- Compression level constants -- + --------------------------------- + + No_Compression : constant Compression_Level := 0; + Best_Speed : constant Compression_Level := 1; + Best_Compression : constant Compression_Level := 9; + Default_Compression : constant Compression_Level := -1; + + -------------------------- + -- Flush mode constants -- + -------------------------- + + No_Flush : constant Flush_Mode; + -- Regular way for compression, no flush + + Partial_Flush : constant Flush_Mode; + -- Will be removed, use Z_SYNC_FLUSH instead + + Sync_Flush : constant Flush_Mode; + -- All pending output is flushed to the output buffer and the output + -- is aligned on a byte boundary, so that the decompressor can get all + -- input data available so far. (In particular avail_in is zero after the + -- call if enough output space has been provided before the call.) + -- Flushing may degrade compression for some compression algorithms and so + -- it should be used only when necessary. + + Block_Flush : constant Flush_Mode; + -- Z_BLOCK requests that inflate() stop + -- if and when it get to the next deflate block boundary. When decoding the + -- zlib or gzip format, this will cause inflate() to return immediately + -- after the header and before the first block. When doing a raw inflate, + -- inflate() will go ahead and process the first block, and will return + -- when it gets to the end of that block, or when it runs out of data. + + Full_Flush : constant Flush_Mode; + -- All output is flushed as with SYNC_FLUSH, and the compression state + -- is reset so that decompression can restart from this point if previous + -- compressed data has been damaged or if random access is desired. Using + -- Full_Flush too often can seriously degrade the compression. + + Finish : constant Flush_Mode; + -- Just for tell the compressor that input data is complete. + + ------------------------------------ + -- Compression strategy constants -- + ------------------------------------ + + -- RLE stategy could be used only in version 1.2.0 and later. + + Filtered : constant Strategy_Type; + Huffman_Only : constant Strategy_Type; + RLE : constant Strategy_Type; + Default_Strategy : constant Strategy_Type; + + Default_Buffer_Size : constant := 4096; + + type Filter_Type is tagged limited private; + -- The filter is for compression and for decompression. + -- The usage of the type is depend of its initialization. + + function Version return String; + pragma Inline (Version); + -- Return string representation of the ZLib version. + + procedure Deflate_Init + (Filter : in out Filter_Type; + Level : in Compression_Level := Default_Compression; + Strategy : in Strategy_Type := Default_Strategy; + Method : in Compression_Method := Deflated; + Window_Bits : in Window_Bits_Type := Default_Window_Bits; + Memory_Level : in Memory_Level_Type := Default_Memory_Level; + Header : in Header_Type := Default); + -- Compressor initialization. + -- When Header parameter is Auto or Default, then default zlib header + -- would be provided for compressed data. + -- When Header is GZip, then gzip header would be set instead of + -- default header. + -- When Header is None, no header would be set for compressed data. + + procedure Inflate_Init + (Filter : in out Filter_Type; + Window_Bits : in Window_Bits_Type := Default_Window_Bits; + Header : in Header_Type := Default); + -- Decompressor initialization. + -- Default header type mean that ZLib default header is expecting in the + -- input compressed stream. + -- Header type None mean that no header is expecting in the input stream. + -- GZip header type mean that GZip header is expecting in the + -- input compressed stream. + -- Auto header type mean that header type (GZip or Native) would be + -- detected automatically in the input stream. + -- Note that header types parameter values None, GZip and Auto are + -- supported for inflate routine only in ZLib versions 1.2.0.2 and later. + -- Deflate_Init is supporting all header types. + + function Is_Open (Filter : in Filter_Type) return Boolean; + pragma Inline (Is_Open); + -- Is the filter opened for compression or decompression. + + procedure Close + (Filter : in out Filter_Type; + Ignore_Error : in Boolean := False); + -- Closing the compression or decompressor. + -- If stream is closing before the complete and Ignore_Error is False, + -- The exception would be raised. + + generic + with procedure Data_In + (Item : out Ada.Streams.Stream_Element_Array; + Last : out Ada.Streams.Stream_Element_Offset); + with procedure Data_Out + (Item : in Ada.Streams.Stream_Element_Array); + procedure Generic_Translate + (Filter : in out Filter_Type; + In_Buffer_Size : in Integer := Default_Buffer_Size; + Out_Buffer_Size : in Integer := Default_Buffer_Size); + -- Compress/decompress data fetch from Data_In routine and pass the result + -- to the Data_Out routine. User should provide Data_In and Data_Out + -- for compression/decompression data flow. + -- Compression or decompression depend on Filter initialization. + + function Total_In (Filter : in Filter_Type) return Count; + pragma Inline (Total_In); + -- Returns total number of input bytes read so far + + function Total_Out (Filter : in Filter_Type) return Count; + pragma Inline (Total_Out); + -- Returns total number of bytes output so far + + function CRC32 + (CRC : in Unsigned_32; + Data : in Ada.Streams.Stream_Element_Array) + return Unsigned_32; + pragma Inline (CRC32); + -- Compute CRC32, it could be necessary for make gzip format + + procedure CRC32 + (CRC : in out Unsigned_32; + Data : in Ada.Streams.Stream_Element_Array); + pragma Inline (CRC32); + -- Compute CRC32, it could be necessary for make gzip format + + ------------------------------------------------- + -- Below is more complex low level routines. -- + ------------------------------------------------- + + procedure Translate + (Filter : in out Filter_Type; + In_Data : in Ada.Streams.Stream_Element_Array; + In_Last : out Ada.Streams.Stream_Element_Offset; + Out_Data : out Ada.Streams.Stream_Element_Array; + Out_Last : out Ada.Streams.Stream_Element_Offset; + Flush : in Flush_Mode); + -- Compress/decompress the In_Data buffer and place the result into + -- Out_Data. In_Last is the index of last element from In_Data accepted by + -- the Filter. Out_Last is the last element of the received data from + -- Filter. To tell the filter that incoming data are complete put the + -- Flush parameter to Finish. + + function Stream_End (Filter : in Filter_Type) return Boolean; + pragma Inline (Stream_End); + -- Return the true when the stream is complete. + + procedure Flush + (Filter : in out Filter_Type; + Out_Data : out Ada.Streams.Stream_Element_Array; + Out_Last : out Ada.Streams.Stream_Element_Offset; + Flush : in Flush_Mode); + pragma Inline (Flush); + -- Flushing the data from the compressor. + + generic + with procedure Write + (Item : in Ada.Streams.Stream_Element_Array); + -- User should provide this routine for accept + -- compressed/decompressed data. + + Buffer_Size : in Ada.Streams.Stream_Element_Offset + := Default_Buffer_Size; + -- Buffer size for Write user routine. + + procedure Write + (Filter : in out Filter_Type; + Item : in Ada.Streams.Stream_Element_Array; + Flush : in Flush_Mode := No_Flush); + -- Compress/Decompress data from Item to the generic parameter procedure + -- Write. Output buffer size could be set in Buffer_Size generic parameter. + + generic + with procedure Read + (Item : out Ada.Streams.Stream_Element_Array; + Last : out Ada.Streams.Stream_Element_Offset); + -- User should provide data for compression/decompression + -- thru this routine. + + Buffer : in out Ada.Streams.Stream_Element_Array; + -- Buffer for keep remaining data from the previous + -- back read. + + Rest_First, Rest_Last : in out Ada.Streams.Stream_Element_Offset; + -- Rest_First have to be initialized to Buffer'Last + 1 + -- Rest_Last have to be initialized to Buffer'Last + -- before usage. + + Allow_Read_Some : in Boolean := False; + -- Is it allowed to return Last < Item'Last before end of data. + + procedure Read + (Filter : in out Filter_Type; + Item : out Ada.Streams.Stream_Element_Array; + Last : out Ada.Streams.Stream_Element_Offset; + Flush : in Flush_Mode := No_Flush); + -- Compress/Decompress data from generic parameter procedure Read to the + -- Item. User should provide Buffer and initialized Rest_First, Rest_Last + -- indicators. If Allow_Read_Some is True, Read routines could return + -- Last < Item'Last only at end of stream. + +private + + use Ada.Streams; + + pragma Assert (Ada.Streams.Stream_Element'Size = 8); + pragma Assert (Ada.Streams.Stream_Element'Modulus = 2**8); + + type Flush_Mode is new Integer range 0 .. 5; + + type Compression_Method is new Integer range 8 .. 8; + + type Strategy_Type is new Integer range 0 .. 3; + + No_Flush : constant Flush_Mode := 0; + Partial_Flush : constant Flush_Mode := 1; + Sync_Flush : constant Flush_Mode := 2; + Full_Flush : constant Flush_Mode := 3; + Finish : constant Flush_Mode := 4; + Block_Flush : constant Flush_Mode := 5; + + Filtered : constant Strategy_Type := 1; + Huffman_Only : constant Strategy_Type := 2; + RLE : constant Strategy_Type := 3; + Default_Strategy : constant Strategy_Type := 0; + + Deflated : constant Compression_Method := 8; + + type Z_Stream; + + type Z_Stream_Access is access all Z_Stream; + + type Filter_Type is tagged limited record + Strm : Z_Stream_Access; + Compression : Boolean; + Stream_End : Boolean; + Header : Header_Type; + CRC : Unsigned_32; + Offset : Stream_Element_Offset; + -- Offset for gzip header/footer output. + end record; + +end ZLib; diff --git a/libs/zlib/contrib/ada/zlib.gpr b/libs/zlib/contrib/ada/zlib.gpr new file mode 100644 index 000000000..296b22aa9 --- /dev/null +++ b/libs/zlib/contrib/ada/zlib.gpr @@ -0,0 +1,20 @@ +project Zlib is + + for Languages use ("Ada"); + for Source_Dirs use ("."); + for Object_Dir use "."; + for Main use ("test.adb", "mtest.adb", "read.adb", "buffer_demo"); + + package Compiler is + for Default_Switches ("ada") use ("-gnatwcfilopru", "-gnatVcdfimorst", "-gnatyabcefhiklmnoprst"); + end Compiler; + + package Linker is + for Default_Switches ("ada") use ("-lz"); + end Linker; + + package Builder is + for Default_Switches ("ada") use ("-s", "-gnatQ"); + end Builder; + +end Zlib; diff --git a/libs/zlib/contrib/amd64/amd64-match.S b/libs/zlib/contrib/amd64/amd64-match.S new file mode 100644 index 000000000..81d4a1c94 --- /dev/null +++ b/libs/zlib/contrib/amd64/amd64-match.S @@ -0,0 +1,452 @@ +/* + * match.S -- optimized version of longest_match() + * based on the similar work by Gilles Vollant, and Brian Raiter, written 1998 + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the BSD License. Use by owners of Che Guevarra + * parafernalia is prohibited, where possible, and highly discouraged + * elsewhere. + */ + +#ifndef NO_UNDERLINE +# define match_init _match_init +# define longest_match _longest_match +#endif + +#define scanend ebx +#define scanendw bx +#define chainlenwmask edx /* high word: current chain len low word: s->wmask */ +#define curmatch rsi +#define curmatchd esi +#define windowbestlen r8 +#define scanalign r9 +#define scanalignd r9d +#define window r10 +#define bestlen r11 +#define bestlend r11d +#define scanstart r12d +#define scanstartw r12w +#define scan r13 +#define nicematch r14d +#define limit r15 +#define limitd r15d +#define prev rcx + +/* + * The 258 is a "magic number, not a parameter -- changing it + * breaks the hell loose + */ +#define MAX_MATCH (258) +#define MIN_MATCH (3) +#define MIN_LOOKAHEAD (MAX_MATCH + MIN_MATCH + 1) +#define MAX_MATCH_8 ((MAX_MATCH + 7) & ~7) + +/* stack frame offsets */ +#define LocalVarsSize (112) +#define _chainlenwmask ( 8-LocalVarsSize)(%rsp) +#define _windowbestlen (16-LocalVarsSize)(%rsp) +#define save_r14 (24-LocalVarsSize)(%rsp) +#define save_rsi (32-LocalVarsSize)(%rsp) +#define save_rbx (40-LocalVarsSize)(%rsp) +#define save_r12 (56-LocalVarsSize)(%rsp) +#define save_r13 (64-LocalVarsSize)(%rsp) +#define save_r15 (80-LocalVarsSize)(%rsp) + + +.globl match_init, longest_match + +/* + * On AMD64 the first argument of a function (in our case -- the pointer to + * deflate_state structure) is passed in %rdi, hence our offsets below are + * all off of that. + */ + +/* you can check the structure offset by running + +#include +#include +#include "deflate.h" + +void print_depl() +{ +deflate_state ds; +deflate_state *s=&ds; +printf("size pointer=%u\n",(int)sizeof(void*)); + +printf("#define dsWSize (%3u)(%%rdi)\n",(int)(((char*)&(s->w_size))-((char*)s))); +printf("#define dsWMask (%3u)(%%rdi)\n",(int)(((char*)&(s->w_mask))-((char*)s))); +printf("#define dsWindow (%3u)(%%rdi)\n",(int)(((char*)&(s->window))-((char*)s))); +printf("#define dsPrev (%3u)(%%rdi)\n",(int)(((char*)&(s->prev))-((char*)s))); +printf("#define dsMatchLen (%3u)(%%rdi)\n",(int)(((char*)&(s->match_length))-((char*)s))); +printf("#define dsPrevMatch (%3u)(%%rdi)\n",(int)(((char*)&(s->prev_match))-((char*)s))); +printf("#define dsStrStart (%3u)(%%rdi)\n",(int)(((char*)&(s->strstart))-((char*)s))); +printf("#define dsMatchStart (%3u)(%%rdi)\n",(int)(((char*)&(s->match_start))-((char*)s))); +printf("#define dsLookahead (%3u)(%%rdi)\n",(int)(((char*)&(s->lookahead))-((char*)s))); +printf("#define dsPrevLen (%3u)(%%rdi)\n",(int)(((char*)&(s->prev_length))-((char*)s))); +printf("#define dsMaxChainLen (%3u)(%%rdi)\n",(int)(((char*)&(s->max_chain_length))-((char*)s))); +printf("#define dsGoodMatch (%3u)(%%rdi)\n",(int)(((char*)&(s->good_match))-((char*)s))); +printf("#define dsNiceMatch (%3u)(%%rdi)\n",(int)(((char*)&(s->nice_match))-((char*)s))); +} + +*/ + + +/* + to compile for XCode 3.2 on MacOSX x86_64 + - run "gcc -g -c -DXCODE_MAC_X64_STRUCTURE amd64-match.S" + */ + + +#ifndef CURRENT_LINX_XCODE_MAC_X64_STRUCTURE +#define dsWSize ( 68)(%rdi) +#define dsWMask ( 76)(%rdi) +#define dsWindow ( 80)(%rdi) +#define dsPrev ( 96)(%rdi) +#define dsMatchLen (144)(%rdi) +#define dsPrevMatch (148)(%rdi) +#define dsStrStart (156)(%rdi) +#define dsMatchStart (160)(%rdi) +#define dsLookahead (164)(%rdi) +#define dsPrevLen (168)(%rdi) +#define dsMaxChainLen (172)(%rdi) +#define dsGoodMatch (188)(%rdi) +#define dsNiceMatch (192)(%rdi) + +#else + +#ifndef STRUCT_OFFSET +# define STRUCT_OFFSET (0) +#endif + + +#define dsWSize ( 56 + STRUCT_OFFSET)(%rdi) +#define dsWMask ( 64 + STRUCT_OFFSET)(%rdi) +#define dsWindow ( 72 + STRUCT_OFFSET)(%rdi) +#define dsPrev ( 88 + STRUCT_OFFSET)(%rdi) +#define dsMatchLen (136 + STRUCT_OFFSET)(%rdi) +#define dsPrevMatch (140 + STRUCT_OFFSET)(%rdi) +#define dsStrStart (148 + STRUCT_OFFSET)(%rdi) +#define dsMatchStart (152 + STRUCT_OFFSET)(%rdi) +#define dsLookahead (156 + STRUCT_OFFSET)(%rdi) +#define dsPrevLen (160 + STRUCT_OFFSET)(%rdi) +#define dsMaxChainLen (164 + STRUCT_OFFSET)(%rdi) +#define dsGoodMatch (180 + STRUCT_OFFSET)(%rdi) +#define dsNiceMatch (184 + STRUCT_OFFSET)(%rdi) + +#endif + + + + +.text + +/* uInt longest_match(deflate_state *deflatestate, IPos curmatch) */ + +longest_match: +/* + * Retrieve the function arguments. %curmatch will hold cur_match + * throughout the entire function (passed via rsi on amd64). + * rdi will hold the pointer to the deflate_state (first arg on amd64) + */ + mov %rsi, save_rsi + mov %rbx, save_rbx + mov %r12, save_r12 + mov %r13, save_r13 + mov %r14, save_r14 + mov %r15, save_r15 + +/* uInt wmask = s->w_mask; */ +/* unsigned chain_length = s->max_chain_length; */ +/* if (s->prev_length >= s->good_match) { */ +/* chain_length >>= 2; */ +/* } */ + + movl dsPrevLen, %eax + movl dsGoodMatch, %ebx + cmpl %ebx, %eax + movl dsWMask, %eax + movl dsMaxChainLen, %chainlenwmask + jl LastMatchGood + shrl $2, %chainlenwmask +LastMatchGood: + +/* chainlen is decremented once beforehand so that the function can */ +/* use the sign flag instead of the zero flag for the exit test. */ +/* It is then shifted into the high word, to make room for the wmask */ +/* value, which it will always accompany. */ + + decl %chainlenwmask + shll $16, %chainlenwmask + orl %eax, %chainlenwmask + +/* if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead; */ + + movl dsNiceMatch, %eax + movl dsLookahead, %ebx + cmpl %eax, %ebx + jl LookaheadLess + movl %eax, %ebx +LookaheadLess: movl %ebx, %nicematch + +/* register Bytef *scan = s->window + s->strstart; */ + + mov dsWindow, %window + movl dsStrStart, %limitd + lea (%limit, %window), %scan + +/* Determine how many bytes the scan ptr is off from being */ +/* dword-aligned. */ + + mov %scan, %scanalign + negl %scanalignd + andl $3, %scanalignd + +/* IPos limit = s->strstart > (IPos)MAX_DIST(s) ? */ +/* s->strstart - (IPos)MAX_DIST(s) : NIL; */ + + movl dsWSize, %eax + subl $MIN_LOOKAHEAD, %eax + xorl %ecx, %ecx + subl %eax, %limitd + cmovng %ecx, %limitd + +/* int best_len = s->prev_length; */ + + movl dsPrevLen, %bestlend + +/* Store the sum of s->window + best_len in %windowbestlen locally, and in memory. */ + + lea (%window, %bestlen), %windowbestlen + mov %windowbestlen, _windowbestlen + +/* register ush scan_start = *(ushf*)scan; */ +/* register ush scan_end = *(ushf*)(scan+best_len-1); */ +/* Posf *prev = s->prev; */ + + movzwl (%scan), %scanstart + movzwl -1(%scan, %bestlen), %scanend + mov dsPrev, %prev + +/* Jump into the main loop. */ + + movl %chainlenwmask, _chainlenwmask + jmp LoopEntry + +.balign 16 + +/* do { + * match = s->window + cur_match; + * if (*(ushf*)(match+best_len-1) != scan_end || + * *(ushf*)match != scan_start) continue; + * [...] + * } while ((cur_match = prev[cur_match & wmask]) > limit + * && --chain_length != 0); + * + * Here is the inner loop of the function. The function will spend the + * majority of its time in this loop, and majority of that time will + * be spent in the first ten instructions. + */ +LookupLoop: + andl %chainlenwmask, %curmatchd + movzwl (%prev, %curmatch, 2), %curmatchd + cmpl %limitd, %curmatchd + jbe LeaveNow + subl $0x00010000, %chainlenwmask + js LeaveNow +LoopEntry: cmpw -1(%windowbestlen, %curmatch), %scanendw + jne LookupLoop + cmpw %scanstartw, (%window, %curmatch) + jne LookupLoop + +/* Store the current value of chainlen. */ + movl %chainlenwmask, _chainlenwmask + +/* %scan is the string under scrutiny, and %prev to the string we */ +/* are hoping to match it up with. In actuality, %esi and %edi are */ +/* both pointed (MAX_MATCH_8 - scanalign) bytes ahead, and %edx is */ +/* initialized to -(MAX_MATCH_8 - scanalign). */ + + mov $(-MAX_MATCH_8), %rdx + lea (%curmatch, %window), %windowbestlen + lea MAX_MATCH_8(%windowbestlen, %scanalign), %windowbestlen + lea MAX_MATCH_8(%scan, %scanalign), %prev + +/* the prefetching below makes very little difference... */ + prefetcht1 (%windowbestlen, %rdx) + prefetcht1 (%prev, %rdx) + +/* + * Test the strings for equality, 8 bytes at a time. At the end, + * adjust %rdx so that it is offset to the exact byte that mismatched. + * + * It should be confessed that this loop usually does not represent + * much of the total running time. Replacing it with a more + * straightforward "rep cmpsb" would not drastically degrade + * performance -- unrolling it, for example, makes no difference. + */ + +#undef USE_SSE /* works, but is 6-7% slower, than non-SSE... */ + +LoopCmps: +#ifdef USE_SSE + /* Preload the SSE registers */ + movdqu (%windowbestlen, %rdx), %xmm1 + movdqu (%prev, %rdx), %xmm2 + pcmpeqb %xmm2, %xmm1 + movdqu 16(%windowbestlen, %rdx), %xmm3 + movdqu 16(%prev, %rdx), %xmm4 + pcmpeqb %xmm4, %xmm3 + movdqu 32(%windowbestlen, %rdx), %xmm5 + movdqu 32(%prev, %rdx), %xmm6 + pcmpeqb %xmm6, %xmm5 + movdqu 48(%windowbestlen, %rdx), %xmm7 + movdqu 48(%prev, %rdx), %xmm8 + pcmpeqb %xmm8, %xmm7 + + /* Check the comparisions' results */ + pmovmskb %xmm1, %rax + notw %ax + bsfw %ax, %ax + jnz LeaveLoopCmps + + /* this is the only iteration of the loop with a possibility of having + incremented rdx by 0x108 (each loop iteration add 16*4 = 0x40 + and (0x40*4)+8=0x108 */ + add $8, %rdx + jz LenMaximum + add $8, %rdx + + + pmovmskb %xmm3, %rax + notw %ax + bsfw %ax, %ax + jnz LeaveLoopCmps + + + add $16, %rdx + + + pmovmskb %xmm5, %rax + notw %ax + bsfw %ax, %ax + jnz LeaveLoopCmps + + add $16, %rdx + + + pmovmskb %xmm7, %rax + notw %ax + bsfw %ax, %ax + jnz LeaveLoopCmps + + add $16, %rdx + + jmp LoopCmps +LeaveLoopCmps: add %rax, %rdx +#else + mov (%windowbestlen, %rdx), %rax + xor (%prev, %rdx), %rax + jnz LeaveLoopCmps + + mov 8(%windowbestlen, %rdx), %rax + xor 8(%prev, %rdx), %rax + jnz LeaveLoopCmps8 + + mov 16(%windowbestlen, %rdx), %rax + xor 16(%prev, %rdx), %rax + jnz LeaveLoopCmps16 + + add $24, %rdx + jnz LoopCmps + jmp LenMaximum +# if 0 +/* + * This three-liner is tantalizingly simple, but bsf is a slow instruction, + * and the complicated alternative down below is quite a bit faster. Sad... + */ + +LeaveLoopCmps: bsf %rax, %rax /* find the first non-zero bit */ + shrl $3, %eax /* divide by 8 to get the byte */ + add %rax, %rdx +# else +LeaveLoopCmps16: + add $8, %rdx +LeaveLoopCmps8: + add $8, %rdx +LeaveLoopCmps: testl $0xFFFFFFFF, %eax /* Check the first 4 bytes */ + jnz Check16 + add $4, %rdx + shr $32, %rax +Check16: testw $0xFFFF, %ax + jnz LenLower + add $2, %rdx + shrl $16, %eax +LenLower: subb $1, %al + adc $0, %rdx +# endif +#endif + +/* Calculate the length of the match. If it is longer than MAX_MATCH, */ +/* then automatically accept it as the best possible match and leave. */ + + lea (%prev, %rdx), %rax + sub %scan, %rax + cmpl $MAX_MATCH, %eax + jge LenMaximum + +/* If the length of the match is not longer than the best match we */ +/* have so far, then forget it and return to the lookup loop. */ + + cmpl %bestlend, %eax + jg LongerMatch + mov _windowbestlen, %windowbestlen + mov dsPrev, %prev + movl _chainlenwmask, %edx + jmp LookupLoop + +/* s->match_start = cur_match; */ +/* best_len = len; */ +/* if (len >= nice_match) break; */ +/* scan_end = *(ushf*)(scan+best_len-1); */ + +LongerMatch: + movl %eax, %bestlend + movl %curmatchd, dsMatchStart + cmpl %nicematch, %eax + jge LeaveNow + + lea (%window, %bestlen), %windowbestlen + mov %windowbestlen, _windowbestlen + + movzwl -1(%scan, %rax), %scanend + mov dsPrev, %prev + movl _chainlenwmask, %chainlenwmask + jmp LookupLoop + +/* Accept the current string, with the maximum possible length. */ + +LenMaximum: + movl $MAX_MATCH, %bestlend + movl %curmatchd, dsMatchStart + +/* if ((uInt)best_len <= s->lookahead) return (uInt)best_len; */ +/* return s->lookahead; */ + +LeaveNow: + movl dsLookahead, %eax + cmpl %eax, %bestlend + cmovngl %bestlend, %eax +LookaheadRet: + +/* Restore the registers and return from whence we came. */ + + mov save_rsi, %rsi + mov save_rbx, %rbx + mov save_r12, %r12 + mov save_r13, %r13 + mov save_r14, %r14 + mov save_r15, %r15 + + ret + +match_init: ret diff --git a/libs/zlib/contrib/asm686/README.686 b/libs/zlib/contrib/asm686/README.686 new file mode 100644 index 000000000..a0bf3bea4 --- /dev/null +++ b/libs/zlib/contrib/asm686/README.686 @@ -0,0 +1,51 @@ +This is a patched version of zlib, modified to use +Pentium-Pro-optimized assembly code in the deflation algorithm. The +files changed/added by this patch are: + +README.686 +match.S + +The speedup that this patch provides varies, depending on whether the +compiler used to build the original version of zlib falls afoul of the +PPro's speed traps. My own tests show a speedup of around 10-20% at +the default compression level, and 20-30% using -9, against a version +compiled using gcc 2.7.2.3. Your mileage may vary. + +Note that this code has been tailored for the PPro/PII in particular, +and will not perform particuarly well on a Pentium. + +If you are using an assembler other than GNU as, you will have to +translate match.S to use your assembler's syntax. (Have fun.) + +Brian Raiter +breadbox@muppetlabs.com +April, 1998 + + +Added for zlib 1.1.3: + +The patches come from +http://www.muppetlabs.com/~breadbox/software/assembly.html + +To compile zlib with this asm file, copy match.S to the zlib directory +then do: + +CFLAGS="-O3 -DASMV" ./configure +make OBJA=match.o + + +Update: + +I've been ignoring these assembly routines for years, believing that +gcc's generated code had caught up with it sometime around gcc 2.95 +and the major rearchitecting of the Pentium 4. However, I recently +learned that, despite what I believed, this code still has some life +in it. On the Pentium 4 and AMD64 chips, it continues to run about 8% +faster than the code produced by gcc 4.1. + +In acknowledgement of its continuing usefulness, I've altered the +license to match that of the rest of zlib. Share and Enjoy! + +Brian Raiter +breadbox@muppetlabs.com +April, 2007 diff --git a/libs/zlib/contrib/asm686/match.S b/libs/zlib/contrib/asm686/match.S new file mode 100644 index 000000000..06817e1dd --- /dev/null +++ b/libs/zlib/contrib/asm686/match.S @@ -0,0 +1,343 @@ +/* match.S -- x86 assembly version of the zlib longest_match() function. + * Optimized for the Intel 686 chips (PPro and later). + * + * Copyright (C) 1998, 2007 Brian Raiter + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the author be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. + */ + +#ifndef NO_UNDERLINE +#define match_init _match_init +#define longest_match _longest_match +#endif + +#define MAX_MATCH (258) +#define MIN_MATCH (3) +#define MIN_LOOKAHEAD (MAX_MATCH + MIN_MATCH + 1) +#define MAX_MATCH_8 ((MAX_MATCH + 7) & ~7) + +/* stack frame offsets */ + +#define chainlenwmask 0 /* high word: current chain len */ + /* low word: s->wmask */ +#define window 4 /* local copy of s->window */ +#define windowbestlen 8 /* s->window + bestlen */ +#define scanstart 16 /* first two bytes of string */ +#define scanend 12 /* last two bytes of string */ +#define scanalign 20 /* dword-misalignment of string */ +#define nicematch 24 /* a good enough match size */ +#define bestlen 28 /* size of best match so far */ +#define scan 32 /* ptr to string wanting match */ + +#define LocalVarsSize (36) +/* saved ebx 36 */ +/* saved edi 40 */ +/* saved esi 44 */ +/* saved ebp 48 */ +/* return address 52 */ +#define deflatestate 56 /* the function arguments */ +#define curmatch 60 + +/* All the +zlib1222add offsets are due to the addition of fields + * in zlib in the deflate_state structure since the asm code was first written + * (if you compile with zlib 1.0.4 or older, use "zlib1222add equ (-4)"). + * (if you compile with zlib between 1.0.5 and 1.2.2.1, use "zlib1222add equ 0"). + * if you compile with zlib 1.2.2.2 or later , use "zlib1222add equ 8"). + */ + +#define zlib1222add (8) + +#define dsWSize (36+zlib1222add) +#define dsWMask (44+zlib1222add) +#define dsWindow (48+zlib1222add) +#define dsPrev (56+zlib1222add) +#define dsMatchLen (88+zlib1222add) +#define dsPrevMatch (92+zlib1222add) +#define dsStrStart (100+zlib1222add) +#define dsMatchStart (104+zlib1222add) +#define dsLookahead (108+zlib1222add) +#define dsPrevLen (112+zlib1222add) +#define dsMaxChainLen (116+zlib1222add) +#define dsGoodMatch (132+zlib1222add) +#define dsNiceMatch (136+zlib1222add) + + +.file "match.S" + +.globl match_init, longest_match + +.text + +/* uInt longest_match(deflate_state *deflatestate, IPos curmatch) */ + +longest_match: + +/* Save registers that the compiler may be using, and adjust %esp to */ +/* make room for our stack frame. */ + + pushl %ebp + pushl %edi + pushl %esi + pushl %ebx + subl $LocalVarsSize, %esp + +/* Retrieve the function arguments. %ecx will hold cur_match */ +/* throughout the entire function. %edx will hold the pointer to the */ +/* deflate_state structure during the function's setup (before */ +/* entering the main loop). */ + + movl deflatestate(%esp), %edx + movl curmatch(%esp), %ecx + +/* uInt wmask = s->w_mask; */ +/* unsigned chain_length = s->max_chain_length; */ +/* if (s->prev_length >= s->good_match) { */ +/* chain_length >>= 2; */ +/* } */ + + movl dsPrevLen(%edx), %eax + movl dsGoodMatch(%edx), %ebx + cmpl %ebx, %eax + movl dsWMask(%edx), %eax + movl dsMaxChainLen(%edx), %ebx + jl LastMatchGood + shrl $2, %ebx +LastMatchGood: + +/* chainlen is decremented once beforehand so that the function can */ +/* use the sign flag instead of the zero flag for the exit test. */ +/* It is then shifted into the high word, to make room for the wmask */ +/* value, which it will always accompany. */ + + decl %ebx + shll $16, %ebx + orl %eax, %ebx + movl %ebx, chainlenwmask(%esp) + +/* if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead; */ + + movl dsNiceMatch(%edx), %eax + movl dsLookahead(%edx), %ebx + cmpl %eax, %ebx + jl LookaheadLess + movl %eax, %ebx +LookaheadLess: movl %ebx, nicematch(%esp) + +/* register Bytef *scan = s->window + s->strstart; */ + + movl dsWindow(%edx), %esi + movl %esi, window(%esp) + movl dsStrStart(%edx), %ebp + lea (%esi,%ebp), %edi + movl %edi, scan(%esp) + +/* Determine how many bytes the scan ptr is off from being */ +/* dword-aligned. */ + + movl %edi, %eax + negl %eax + andl $3, %eax + movl %eax, scanalign(%esp) + +/* IPos limit = s->strstart > (IPos)MAX_DIST(s) ? */ +/* s->strstart - (IPos)MAX_DIST(s) : NIL; */ + + movl dsWSize(%edx), %eax + subl $MIN_LOOKAHEAD, %eax + subl %eax, %ebp + jg LimitPositive + xorl %ebp, %ebp +LimitPositive: + +/* int best_len = s->prev_length; */ + + movl dsPrevLen(%edx), %eax + movl %eax, bestlen(%esp) + +/* Store the sum of s->window + best_len in %esi locally, and in %esi. */ + + addl %eax, %esi + movl %esi, windowbestlen(%esp) + +/* register ush scan_start = *(ushf*)scan; */ +/* register ush scan_end = *(ushf*)(scan+best_len-1); */ +/* Posf *prev = s->prev; */ + + movzwl (%edi), %ebx + movl %ebx, scanstart(%esp) + movzwl -1(%edi,%eax), %ebx + movl %ebx, scanend(%esp) + movl dsPrev(%edx), %edi + +/* Jump into the main loop. */ + + movl chainlenwmask(%esp), %edx + jmp LoopEntry + +.balign 16 + +/* do { + * match = s->window + cur_match; + * if (*(ushf*)(match+best_len-1) != scan_end || + * *(ushf*)match != scan_start) continue; + * [...] + * } while ((cur_match = prev[cur_match & wmask]) > limit + * && --chain_length != 0); + * + * Here is the inner loop of the function. The function will spend the + * majority of its time in this loop, and majority of that time will + * be spent in the first ten instructions. + * + * Within this loop: + * %ebx = scanend + * %ecx = curmatch + * %edx = chainlenwmask - i.e., ((chainlen << 16) | wmask) + * %esi = windowbestlen - i.e., (window + bestlen) + * %edi = prev + * %ebp = limit + */ +LookupLoop: + andl %edx, %ecx + movzwl (%edi,%ecx,2), %ecx + cmpl %ebp, %ecx + jbe LeaveNow + subl $0x00010000, %edx + js LeaveNow +LoopEntry: movzwl -1(%esi,%ecx), %eax + cmpl %ebx, %eax + jnz LookupLoop + movl window(%esp), %eax + movzwl (%eax,%ecx), %eax + cmpl scanstart(%esp), %eax + jnz LookupLoop + +/* Store the current value of chainlen. */ + + movl %edx, chainlenwmask(%esp) + +/* Point %edi to the string under scrutiny, and %esi to the string we */ +/* are hoping to match it up with. In actuality, %esi and %edi are */ +/* both pointed (MAX_MATCH_8 - scanalign) bytes ahead, and %edx is */ +/* initialized to -(MAX_MATCH_8 - scanalign). */ + + movl window(%esp), %esi + movl scan(%esp), %edi + addl %ecx, %esi + movl scanalign(%esp), %eax + movl $(-MAX_MATCH_8), %edx + lea MAX_MATCH_8(%edi,%eax), %edi + lea MAX_MATCH_8(%esi,%eax), %esi + +/* Test the strings for equality, 8 bytes at a time. At the end, + * adjust %edx so that it is offset to the exact byte that mismatched. + * + * We already know at this point that the first three bytes of the + * strings match each other, and they can be safely passed over before + * starting the compare loop. So what this code does is skip over 0-3 + * bytes, as much as necessary in order to dword-align the %edi + * pointer. (%esi will still be misaligned three times out of four.) + * + * It should be confessed that this loop usually does not represent + * much of the total running time. Replacing it with a more + * straightforward "rep cmpsb" would not drastically degrade + * performance. + */ +LoopCmps: + movl (%esi,%edx), %eax + xorl (%edi,%edx), %eax + jnz LeaveLoopCmps + movl 4(%esi,%edx), %eax + xorl 4(%edi,%edx), %eax + jnz LeaveLoopCmps4 + addl $8, %edx + jnz LoopCmps + jmp LenMaximum +LeaveLoopCmps4: addl $4, %edx +LeaveLoopCmps: testl $0x0000FFFF, %eax + jnz LenLower + addl $2, %edx + shrl $16, %eax +LenLower: subb $1, %al + adcl $0, %edx + +/* Calculate the length of the match. If it is longer than MAX_MATCH, */ +/* then automatically accept it as the best possible match and leave. */ + + lea (%edi,%edx), %eax + movl scan(%esp), %edi + subl %edi, %eax + cmpl $MAX_MATCH, %eax + jge LenMaximum + +/* If the length of the match is not longer than the best match we */ +/* have so far, then forget it and return to the lookup loop. */ + + movl deflatestate(%esp), %edx + movl bestlen(%esp), %ebx + cmpl %ebx, %eax + jg LongerMatch + movl windowbestlen(%esp), %esi + movl dsPrev(%edx), %edi + movl scanend(%esp), %ebx + movl chainlenwmask(%esp), %edx + jmp LookupLoop + +/* s->match_start = cur_match; */ +/* best_len = len; */ +/* if (len >= nice_match) break; */ +/* scan_end = *(ushf*)(scan+best_len-1); */ + +LongerMatch: movl nicematch(%esp), %ebx + movl %eax, bestlen(%esp) + movl %ecx, dsMatchStart(%edx) + cmpl %ebx, %eax + jge LeaveNow + movl window(%esp), %esi + addl %eax, %esi + movl %esi, windowbestlen(%esp) + movzwl -1(%edi,%eax), %ebx + movl dsPrev(%edx), %edi + movl %ebx, scanend(%esp) + movl chainlenwmask(%esp), %edx + jmp LookupLoop + +/* Accept the current string, with the maximum possible length. */ + +LenMaximum: movl deflatestate(%esp), %edx + movl $MAX_MATCH, bestlen(%esp) + movl %ecx, dsMatchStart(%edx) + +/* if ((uInt)best_len <= s->lookahead) return (uInt)best_len; */ +/* return s->lookahead; */ + +LeaveNow: + movl deflatestate(%esp), %edx + movl bestlen(%esp), %ebx + movl dsLookahead(%edx), %eax + cmpl %eax, %ebx + jg LookaheadRet + movl %ebx, %eax +LookaheadRet: + +/* Restore the stack and return from whence we came. */ + + addl $LocalVarsSize, %esp + popl %ebx + popl %esi + popl %edi + popl %ebp +match_init: ret diff --git a/libs/zlib/contrib/blast/Makefile b/libs/zlib/contrib/blast/Makefile new file mode 100644 index 000000000..9be80bafe --- /dev/null +++ b/libs/zlib/contrib/blast/Makefile @@ -0,0 +1,8 @@ +blast: blast.c blast.h + cc -DTEST -o blast blast.c + +test: blast + blast < test.pk | cmp - test.txt + +clean: + rm -f blast blast.o diff --git a/libs/zlib/contrib/blast/README b/libs/zlib/contrib/blast/README new file mode 100644 index 000000000..e3a60b3f5 --- /dev/null +++ b/libs/zlib/contrib/blast/README @@ -0,0 +1,4 @@ +Read blast.h for purpose and usage. + +Mark Adler +madler@alumni.caltech.edu diff --git a/libs/zlib/contrib/blast/blast.c b/libs/zlib/contrib/blast/blast.c new file mode 100644 index 000000000..4ce697a41 --- /dev/null +++ b/libs/zlib/contrib/blast/blast.c @@ -0,0 +1,444 @@ +/* blast.c + * Copyright (C) 2003 Mark Adler + * For conditions of distribution and use, see copyright notice in blast.h + * version 1.1, 16 Feb 2003 + * + * blast.c decompresses data compressed by the PKWare Compression Library. + * This function provides functionality similar to the explode() function of + * the PKWare library, hence the name "blast". + * + * This decompressor is based on the excellent format description provided by + * Ben Rudiak-Gould in comp.compression on August 13, 2001. Interestingly, the + * example Ben provided in the post is incorrect. The distance 110001 should + * instead be 111000. When corrected, the example byte stream becomes: + * + * 00 04 82 24 25 8f 80 7f + * + * which decompresses to "AIAIAIAIAIAIA" (without the quotes). + */ + +/* + * Change history: + * + * 1.0 12 Feb 2003 - First version + * 1.1 16 Feb 2003 - Fixed distance check for > 4 GB uncompressed data + */ + +#include /* for setjmp(), longjmp(), and jmp_buf */ +#include "blast.h" /* prototype for blast() */ + +#define local static /* for local function definitions */ +#define MAXBITS 13 /* maximum code length */ +#define MAXWIN 4096 /* maximum window size */ + +/* input and output state */ +struct state { + /* input state */ + blast_in infun; /* input function provided by user */ + void *inhow; /* opaque information passed to infun() */ + unsigned char *in; /* next input location */ + unsigned left; /* available input at in */ + int bitbuf; /* bit buffer */ + int bitcnt; /* number of bits in bit buffer */ + + /* input limit error return state for bits() and decode() */ + jmp_buf env; + + /* output state */ + blast_out outfun; /* output function provided by user */ + void *outhow; /* opaque information passed to outfun() */ + unsigned next; /* index of next write location in out[] */ + int first; /* true to check distances (for first 4K) */ + unsigned char out[MAXWIN]; /* output buffer and sliding window */ +}; + +/* + * Return need bits from the input stream. This always leaves less than + * eight bits in the buffer. bits() works properly for need == 0. + * + * Format notes: + * + * - Bits are stored in bytes from the least significant bit to the most + * significant bit. Therefore bits are dropped from the bottom of the bit + * buffer, using shift right, and new bytes are appended to the top of the + * bit buffer, using shift left. + */ +local int bits(struct state *s, int need) +{ + int val; /* bit accumulator */ + + /* load at least need bits into val */ + val = s->bitbuf; + while (s->bitcnt < need) { + if (s->left == 0) { + s->left = s->infun(s->inhow, &(s->in)); + if (s->left == 0) longjmp(s->env, 1); /* out of input */ + } + val |= (int)(*(s->in)++) << s->bitcnt; /* load eight bits */ + s->left--; + s->bitcnt += 8; + } + + /* drop need bits and update buffer, always zero to seven bits left */ + s->bitbuf = val >> need; + s->bitcnt -= need; + + /* return need bits, zeroing the bits above that */ + return val & ((1 << need) - 1); +} + +/* + * Huffman code decoding tables. count[1..MAXBITS] is the number of symbols of + * each length, which for a canonical code are stepped through in order. + * symbol[] are the symbol values in canonical order, where the number of + * entries is the sum of the counts in count[]. The decoding process can be + * seen in the function decode() below. + */ +struct huffman { + short *count; /* number of symbols of each length */ + short *symbol; /* canonically ordered symbols */ +}; + +/* + * Decode a code from the stream s using huffman table h. Return the symbol or + * a negative value if there is an error. If all of the lengths are zero, i.e. + * an empty code, or if the code is incomplete and an invalid code is received, + * then -9 is returned after reading MAXBITS bits. + * + * Format notes: + * + * - The codes as stored in the compressed data are bit-reversed relative to + * a simple integer ordering of codes of the same lengths. Hence below the + * bits are pulled from the compressed data one at a time and used to + * build the code value reversed from what is in the stream in order to + * permit simple integer comparisons for decoding. + * + * - The first code for the shortest length is all ones. Subsequent codes of + * the same length are simply integer decrements of the previous code. When + * moving up a length, a one bit is appended to the code. For a complete + * code, the last code of the longest length will be all zeros. To support + * this ordering, the bits pulled during decoding are inverted to apply the + * more "natural" ordering starting with all zeros and incrementing. + */ +local int decode(struct state *s, struct huffman *h) +{ + int len; /* current number of bits in code */ + int code; /* len bits being decoded */ + int first; /* first code of length len */ + int count; /* number of codes of length len */ + int index; /* index of first code of length len in symbol table */ + int bitbuf; /* bits from stream */ + int left; /* bits left in next or left to process */ + short *next; /* next number of codes */ + + bitbuf = s->bitbuf; + left = s->bitcnt; + code = first = index = 0; + len = 1; + next = h->count + 1; + while (1) { + while (left--) { + code |= (bitbuf & 1) ^ 1; /* invert code */ + bitbuf >>= 1; + count = *next++; + if (code < first + count) { /* if length len, return symbol */ + s->bitbuf = bitbuf; + s->bitcnt = (s->bitcnt - len) & 7; + return h->symbol[index + (code - first)]; + } + index += count; /* else update for next length */ + first += count; + first <<= 1; + code <<= 1; + len++; + } + left = (MAXBITS+1) - len; + if (left == 0) break; + if (s->left == 0) { + s->left = s->infun(s->inhow, &(s->in)); + if (s->left == 0) longjmp(s->env, 1); /* out of input */ + } + bitbuf = *(s->in)++; + s->left--; + if (left > 8) left = 8; + } + return -9; /* ran out of codes */ +} + +/* + * Given a list of repeated code lengths rep[0..n-1], where each byte is a + * count (high four bits + 1) and a code length (low four bits), generate the + * list of code lengths. This compaction reduces the size of the object code. + * Then given the list of code lengths length[0..n-1] representing a canonical + * Huffman code for n symbols, construct the tables required to decode those + * codes. Those tables are the number of codes of each length, and the symbols + * sorted by length, retaining their original order within each length. The + * return value is zero for a complete code set, negative for an over- + * subscribed code set, and positive for an incomplete code set. The tables + * can be used if the return value is zero or positive, but they cannot be used + * if the return value is negative. If the return value is zero, it is not + * possible for decode() using that table to return an error--any stream of + * enough bits will resolve to a symbol. If the return value is positive, then + * it is possible for decode() using that table to return an error for received + * codes past the end of the incomplete lengths. + */ +local int construct(struct huffman *h, const unsigned char *rep, int n) +{ + int symbol; /* current symbol when stepping through length[] */ + int len; /* current length when stepping through h->count[] */ + int left; /* number of possible codes left of current length */ + short offs[MAXBITS+1]; /* offsets in symbol table for each length */ + short length[256]; /* code lengths */ + + /* convert compact repeat counts into symbol bit length list */ + symbol = 0; + do { + len = *rep++; + left = (len >> 4) + 1; + len &= 15; + do { + length[symbol++] = len; + } while (--left); + } while (--n); + n = symbol; + + /* count number of codes of each length */ + for (len = 0; len <= MAXBITS; len++) + h->count[len] = 0; + for (symbol = 0; symbol < n; symbol++) + (h->count[length[symbol]])++; /* assumes lengths are within bounds */ + if (h->count[0] == n) /* no codes! */ + return 0; /* complete, but decode() will fail */ + + /* check for an over-subscribed or incomplete set of lengths */ + left = 1; /* one possible code of zero length */ + for (len = 1; len <= MAXBITS; len++) { + left <<= 1; /* one more bit, double codes left */ + left -= h->count[len]; /* deduct count from possible codes */ + if (left < 0) return left; /* over-subscribed--return negative */ + } /* left > 0 means incomplete */ + + /* generate offsets into symbol table for each length for sorting */ + offs[1] = 0; + for (len = 1; len < MAXBITS; len++) + offs[len + 1] = offs[len] + h->count[len]; + + /* + * put symbols in table sorted by length, by symbol order within each + * length + */ + for (symbol = 0; symbol < n; symbol++) + if (length[symbol] != 0) + h->symbol[offs[length[symbol]]++] = symbol; + + /* return zero for complete set, positive for incomplete set */ + return left; +} + +/* + * Decode PKWare Compression Library stream. + * + * Format notes: + * + * - First byte is 0 if literals are uncoded or 1 if they are coded. Second + * byte is 4, 5, or 6 for the number of extra bits in the distance code. + * This is the base-2 logarithm of the dictionary size minus six. + * + * - Compressed data is a combination of literals and length/distance pairs + * terminated by an end code. Literals are either Huffman coded or + * uncoded bytes. A length/distance pair is a coded length followed by a + * coded distance to represent a string that occurs earlier in the + * uncompressed data that occurs again at the current location. + * + * - A bit preceding a literal or length/distance pair indicates which comes + * next, 0 for literals, 1 for length/distance. + * + * - If literals are uncoded, then the next eight bits are the literal, in the + * normal bit order in th stream, i.e. no bit-reversal is needed. Similarly, + * no bit reversal is needed for either the length extra bits or the distance + * extra bits. + * + * - Literal bytes are simply written to the output. A length/distance pair is + * an instruction to copy previously uncompressed bytes to the output. The + * copy is from distance bytes back in the output stream, copying for length + * bytes. + * + * - Distances pointing before the beginning of the output data are not + * permitted. + * + * - Overlapped copies, where the length is greater than the distance, are + * allowed and common. For example, a distance of one and a length of 518 + * simply copies the last byte 518 times. A distance of four and a length of + * twelve copies the last four bytes three times. A simple forward copy + * ignoring whether the length is greater than the distance or not implements + * this correctly. + */ +local int decomp(struct state *s) +{ + int lit; /* true if literals are coded */ + int dict; /* log2(dictionary size) - 6 */ + int symbol; /* decoded symbol, extra bits for distance */ + int len; /* length for copy */ + int dist; /* distance for copy */ + int copy; /* copy counter */ + unsigned char *from, *to; /* copy pointers */ + static int virgin = 1; /* build tables once */ + static short litcnt[MAXBITS+1], litsym[256]; /* litcode memory */ + static short lencnt[MAXBITS+1], lensym[16]; /* lencode memory */ + static short distcnt[MAXBITS+1], distsym[64]; /* distcode memory */ + static struct huffman litcode = {litcnt, litsym}; /* length code */ + static struct huffman lencode = {lencnt, lensym}; /* length code */ + static struct huffman distcode = {distcnt, distsym};/* distance code */ + /* bit lengths of literal codes */ + static const unsigned char litlen[] = { + 11, 124, 8, 7, 28, 7, 188, 13, 76, 4, 10, 8, 12, 10, 12, 10, 8, 23, 8, + 9, 7, 6, 7, 8, 7, 6, 55, 8, 23, 24, 12, 11, 7, 9, 11, 12, 6, 7, 22, 5, + 7, 24, 6, 11, 9, 6, 7, 22, 7, 11, 38, 7, 9, 8, 25, 11, 8, 11, 9, 12, + 8, 12, 5, 38, 5, 38, 5, 11, 7, 5, 6, 21, 6, 10, 53, 8, 7, 24, 10, 27, + 44, 253, 253, 253, 252, 252, 252, 13, 12, 45, 12, 45, 12, 61, 12, 45, + 44, 173}; + /* bit lengths of length codes 0..15 */ + static const unsigned char lenlen[] = {2, 35, 36, 53, 38, 23}; + /* bit lengths of distance codes 0..63 */ + static const unsigned char distlen[] = {2, 20, 53, 230, 247, 151, 248}; + static const short base[16] = { /* base for length codes */ + 3, 2, 4, 5, 6, 7, 8, 9, 10, 12, 16, 24, 40, 72, 136, 264}; + static const char extra[16] = { /* extra bits for length codes */ + 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8}; + + /* set up decoding tables (once--might not be thread-safe) */ + if (virgin) { + construct(&litcode, litlen, sizeof(litlen)); + construct(&lencode, lenlen, sizeof(lenlen)); + construct(&distcode, distlen, sizeof(distlen)); + virgin = 0; + } + + /* read header */ + lit = bits(s, 8); + if (lit > 1) return -1; + dict = bits(s, 8); + if (dict < 4 || dict > 6) return -2; + + /* decode literals and length/distance pairs */ + do { + if (bits(s, 1)) { + /* get length */ + symbol = decode(s, &lencode); + len = base[symbol] + bits(s, extra[symbol]); + if (len == 519) break; /* end code */ + + /* get distance */ + symbol = len == 2 ? 2 : dict; + dist = decode(s, &distcode) << symbol; + dist += bits(s, symbol); + dist++; + if (s->first && dist > s->next) + return -3; /* distance too far back */ + + /* copy length bytes from distance bytes back */ + do { + to = s->out + s->next; + from = to - dist; + copy = MAXWIN; + if (s->next < dist) { + from += copy; + copy = dist; + } + copy -= s->next; + if (copy > len) copy = len; + len -= copy; + s->next += copy; + do { + *to++ = *from++; + } while (--copy); + if (s->next == MAXWIN) { + if (s->outfun(s->outhow, s->out, s->next)) return 1; + s->next = 0; + s->first = 0; + } + } while (len != 0); + } + else { + /* get literal and write it */ + symbol = lit ? decode(s, &litcode) : bits(s, 8); + s->out[s->next++] = symbol; + if (s->next == MAXWIN) { + if (s->outfun(s->outhow, s->out, s->next)) return 1; + s->next = 0; + s->first = 0; + } + } + } while (1); + return 0; +} + +/* See comments in blast.h */ +int blast(blast_in infun, void *inhow, blast_out outfun, void *outhow) +{ + struct state s; /* input/output state */ + int err; /* return value */ + + /* initialize input state */ + s.infun = infun; + s.inhow = inhow; + s.left = 0; + s.bitbuf = 0; + s.bitcnt = 0; + + /* initialize output state */ + s.outfun = outfun; + s.outhow = outhow; + s.next = 0; + s.first = 1; + + /* return if bits() or decode() tries to read past available input */ + if (setjmp(s.env) != 0) /* if came back here via longjmp(), */ + err = 2; /* then skip decomp(), return error */ + else + err = decomp(&s); /* decompress */ + + /* write any leftover output and update the error code if needed */ + if (err != 1 && s.next && s.outfun(s.outhow, s.out, s.next) && err == 0) + err = 1; + return err; +} + +#ifdef TEST +/* Example of how to use blast() */ +#include +#include + +#define CHUNK 16384 + +local unsigned inf(void *how, unsigned char **buf) +{ + static unsigned char hold[CHUNK]; + + *buf = hold; + return fread(hold, 1, CHUNK, (FILE *)how); +} + +local int outf(void *how, unsigned char *buf, unsigned len) +{ + return fwrite(buf, 1, len, (FILE *)how) != len; +} + +/* Decompress a PKWare Compression Library stream from stdin to stdout */ +int main(void) +{ + int ret, n; + + /* decompress to stdout */ + ret = blast(inf, stdin, outf, stdout); + if (ret != 0) fprintf(stderr, "blast error: %d\n", ret); + + /* see if there are any leftover bytes */ + n = 0; + while (getchar() != EOF) n++; + if (n) fprintf(stderr, "blast warning: %d unused bytes of input\n", n); + + /* return blast() error code */ + return ret; +} +#endif diff --git a/libs/zlib/contrib/blast/blast.h b/libs/zlib/contrib/blast/blast.h new file mode 100644 index 000000000..ce9e5410f --- /dev/null +++ b/libs/zlib/contrib/blast/blast.h @@ -0,0 +1,71 @@ +/* blast.h -- interface for blast.c + Copyright (C) 2003 Mark Adler + version 1.1, 16 Feb 2003 + + This software is provided 'as-is', without any express or implied + warranty. In no event will the author be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Mark Adler madler@alumni.caltech.edu + */ + + +/* + * blast() decompresses the PKWare Data Compression Library (DCL) compressed + * format. It provides the same functionality as the explode() function in + * that library. (Note: PKWare overused the "implode" verb, and the format + * used by their library implode() function is completely different and + * incompatible with the implode compression method supported by PKZIP.) + */ + + +typedef unsigned (*blast_in)(void *how, unsigned char **buf); +typedef int (*blast_out)(void *how, unsigned char *buf, unsigned len); +/* Definitions for input/output functions passed to blast(). See below for + * what the provided functions need to do. + */ + + +int blast(blast_in infun, void *inhow, blast_out outfun, void *outhow); +/* Decompress input to output using the provided infun() and outfun() calls. + * On success, the return value of blast() is zero. If there is an error in + * the source data, i.e. it is not in the proper format, then a negative value + * is returned. If there is not enough input available or there is not enough + * output space, then a positive error is returned. + * + * The input function is invoked: len = infun(how, &buf), where buf is set by + * infun() to point to the input buffer, and infun() returns the number of + * available bytes there. If infun() returns zero, then blast() returns with + * an input error. (blast() only asks for input if it needs it.) inhow is for + * use by the application to pass an input descriptor to infun(), if desired. + * + * The output function is invoked: err = outfun(how, buf, len), where the bytes + * to be written are buf[0..len-1]. If err is not zero, then blast() returns + * with an output error. outfun() is always called with len <= 4096. outhow + * is for use by the application to pass an output descriptor to outfun(), if + * desired. + * + * The return codes are: + * + * 2: ran out of input before completing decompression + * 1: output error before completing decompression + * 0: successful decompression + * -1: literal flag not zero or one + * -2: dictionary size not in 4..6 + * -3: distance is too far back + * + * At the bottom of blast.c is an example program that uses blast() that can be + * compiled to produce a command-line decompression filter by defining TEST. + */ diff --git a/libs/zlib/contrib/blast/test.pk b/libs/zlib/contrib/blast/test.pk new file mode 100644 index 000000000..be10b2bbb Binary files /dev/null and b/libs/zlib/contrib/blast/test.pk differ diff --git a/libs/zlib/contrib/blast/test.txt b/libs/zlib/contrib/blast/test.txt new file mode 100644 index 000000000..bfdf1c5dc --- /dev/null +++ b/libs/zlib/contrib/blast/test.txt @@ -0,0 +1 @@ +AIAIAIAIAIAIA \ No newline at end of file diff --git a/libs/zlib/contrib/delphi/ZLib.pas b/libs/zlib/contrib/delphi/ZLib.pas new file mode 100644 index 000000000..0d86fb52f --- /dev/null +++ b/libs/zlib/contrib/delphi/ZLib.pas @@ -0,0 +1,557 @@ +{*******************************************************} +{ } +{ Borland Delphi Supplemental Components } +{ ZLIB Data Compression Interface Unit } +{ } +{ Copyright (c) 1997,99 Borland Corporation } +{ } +{*******************************************************} + +{ Updated for zlib 1.2.x by Cosmin Truta } + +unit ZLib; + +interface + +uses SysUtils, Classes; + +type + TAlloc = function (AppData: Pointer; Items, Size: Integer): Pointer; cdecl; + TFree = procedure (AppData, Block: Pointer); cdecl; + + // Internal structure. Ignore. + TZStreamRec = packed record + next_in: PChar; // next input byte + avail_in: Integer; // number of bytes available at next_in + total_in: Longint; // total nb of input bytes read so far + + next_out: PChar; // next output byte should be put here + avail_out: Integer; // remaining free space at next_out + total_out: Longint; // total nb of bytes output so far + + msg: PChar; // last error message, NULL if no error + internal: Pointer; // not visible by applications + + zalloc: TAlloc; // used to allocate the internal state + zfree: TFree; // used to free the internal state + AppData: Pointer; // private data object passed to zalloc and zfree + + data_type: Integer; // best guess about the data type: ascii or binary + adler: Longint; // adler32 value of the uncompressed data + reserved: Longint; // reserved for future use + end; + + // Abstract ancestor class + TCustomZlibStream = class(TStream) + private + FStrm: TStream; + FStrmPos: Integer; + FOnProgress: TNotifyEvent; + FZRec: TZStreamRec; + FBuffer: array [Word] of Char; + protected + procedure Progress(Sender: TObject); dynamic; + property OnProgress: TNotifyEvent read FOnProgress write FOnProgress; + constructor Create(Strm: TStream); + end; + +{ TCompressionStream compresses data on the fly as data is written to it, and + stores the compressed data to another stream. + + TCompressionStream is write-only and strictly sequential. Reading from the + stream will raise an exception. Using Seek to move the stream pointer + will raise an exception. + + Output data is cached internally, written to the output stream only when + the internal output buffer is full. All pending output data is flushed + when the stream is destroyed. + + The Position property returns the number of uncompressed bytes of + data that have been written to the stream so far. + + CompressionRate returns the on-the-fly percentage by which the original + data has been compressed: (1 - (CompressedBytes / UncompressedBytes)) * 100 + If raw data size = 100 and compressed data size = 25, the CompressionRate + is 75% + + The OnProgress event is called each time the output buffer is filled and + written to the output stream. This is useful for updating a progress + indicator when you are writing a large chunk of data to the compression + stream in a single call.} + + + TCompressionLevel = (clNone, clFastest, clDefault, clMax); + + TCompressionStream = class(TCustomZlibStream) + private + function GetCompressionRate: Single; + public + constructor Create(CompressionLevel: TCompressionLevel; Dest: TStream); + destructor Destroy; override; + function Read(var Buffer; Count: Longint): Longint; override; + function Write(const Buffer; Count: Longint): Longint; override; + function Seek(Offset: Longint; Origin: Word): Longint; override; + property CompressionRate: Single read GetCompressionRate; + property OnProgress; + end; + +{ TDecompressionStream decompresses data on the fly as data is read from it. + + Compressed data comes from a separate source stream. TDecompressionStream + is read-only and unidirectional; you can seek forward in the stream, but not + backwards. The special case of setting the stream position to zero is + allowed. Seeking forward decompresses data until the requested position in + the uncompressed data has been reached. Seeking backwards, seeking relative + to the end of the stream, requesting the size of the stream, and writing to + the stream will raise an exception. + + The Position property returns the number of bytes of uncompressed data that + have been read from the stream so far. + + The OnProgress event is called each time the internal input buffer of + compressed data is exhausted and the next block is read from the input stream. + This is useful for updating a progress indicator when you are reading a + large chunk of data from the decompression stream in a single call.} + + TDecompressionStream = class(TCustomZlibStream) + public + constructor Create(Source: TStream); + destructor Destroy; override; + function Read(var Buffer; Count: Longint): Longint; override; + function Write(const Buffer; Count: Longint): Longint; override; + function Seek(Offset: Longint; Origin: Word): Longint; override; + property OnProgress; + end; + + + +{ CompressBuf compresses data, buffer to buffer, in one call. + In: InBuf = ptr to compressed data + InBytes = number of bytes in InBuf + Out: OutBuf = ptr to newly allocated buffer containing decompressed data + OutBytes = number of bytes in OutBuf } +procedure CompressBuf(const InBuf: Pointer; InBytes: Integer; + out OutBuf: Pointer; out OutBytes: Integer); + + +{ DecompressBuf decompresses data, buffer to buffer, in one call. + In: InBuf = ptr to compressed data + InBytes = number of bytes in InBuf + OutEstimate = zero, or est. size of the decompressed data + Out: OutBuf = ptr to newly allocated buffer containing decompressed data + OutBytes = number of bytes in OutBuf } +procedure DecompressBuf(const InBuf: Pointer; InBytes: Integer; + OutEstimate: Integer; out OutBuf: Pointer; out OutBytes: Integer); + +{ DecompressToUserBuf decompresses data, buffer to buffer, in one call. + In: InBuf = ptr to compressed data + InBytes = number of bytes in InBuf + Out: OutBuf = ptr to user-allocated buffer to contain decompressed data + BufSize = number of bytes in OutBuf } +procedure DecompressToUserBuf(const InBuf: Pointer; InBytes: Integer; + const OutBuf: Pointer; BufSize: Integer); + +const + zlib_version = '1.2.5'; + +type + EZlibError = class(Exception); + ECompressionError = class(EZlibError); + EDecompressionError = class(EZlibError); + +implementation + +uses ZLibConst; + +const + Z_NO_FLUSH = 0; + Z_PARTIAL_FLUSH = 1; + Z_SYNC_FLUSH = 2; + Z_FULL_FLUSH = 3; + Z_FINISH = 4; + + Z_OK = 0; + Z_STREAM_END = 1; + Z_NEED_DICT = 2; + Z_ERRNO = (-1); + Z_STREAM_ERROR = (-2); + Z_DATA_ERROR = (-3); + Z_MEM_ERROR = (-4); + Z_BUF_ERROR = (-5); + Z_VERSION_ERROR = (-6); + + Z_NO_COMPRESSION = 0; + Z_BEST_SPEED = 1; + Z_BEST_COMPRESSION = 9; + Z_DEFAULT_COMPRESSION = (-1); + + Z_FILTERED = 1; + Z_HUFFMAN_ONLY = 2; + Z_RLE = 3; + Z_DEFAULT_STRATEGY = 0; + + Z_BINARY = 0; + Z_ASCII = 1; + Z_UNKNOWN = 2; + + Z_DEFLATED = 8; + + +{$L adler32.obj} +{$L compress.obj} +{$L crc32.obj} +{$L deflate.obj} +{$L infback.obj} +{$L inffast.obj} +{$L inflate.obj} +{$L inftrees.obj} +{$L trees.obj} +{$L uncompr.obj} +{$L zutil.obj} + +procedure adler32; external; +procedure compressBound; external; +procedure crc32; external; +procedure deflateInit2_; external; +procedure deflateParams; external; + +function _malloc(Size: Integer): Pointer; cdecl; +begin + Result := AllocMem(Size); +end; + +procedure _free(Block: Pointer); cdecl; +begin + FreeMem(Block); +end; + +procedure _memset(P: Pointer; B: Byte; count: Integer); cdecl; +begin + FillChar(P^, count, B); +end; + +procedure _memcpy(dest, source: Pointer; count: Integer); cdecl; +begin + Move(source^, dest^, count); +end; + + + +// deflate compresses data +function deflateInit_(var strm: TZStreamRec; level: Integer; version: PChar; + recsize: Integer): Integer; external; +function deflate(var strm: TZStreamRec; flush: Integer): Integer; external; +function deflateEnd(var strm: TZStreamRec): Integer; external; + +// inflate decompresses data +function inflateInit_(var strm: TZStreamRec; version: PChar; + recsize: Integer): Integer; external; +function inflate(var strm: TZStreamRec; flush: Integer): Integer; external; +function inflateEnd(var strm: TZStreamRec): Integer; external; +function inflateReset(var strm: TZStreamRec): Integer; external; + + +function zlibAllocMem(AppData: Pointer; Items, Size: Integer): Pointer; cdecl; +begin +// GetMem(Result, Items*Size); + Result := AllocMem(Items * Size); +end; + +procedure zlibFreeMem(AppData, Block: Pointer); cdecl; +begin + FreeMem(Block); +end; + +{function zlibCheck(code: Integer): Integer; +begin + Result := code; + if code < 0 then + raise EZlibError.Create('error'); //!! +end;} + +function CCheck(code: Integer): Integer; +begin + Result := code; + if code < 0 then + raise ECompressionError.Create('error'); //!! +end; + +function DCheck(code: Integer): Integer; +begin + Result := code; + if code < 0 then + raise EDecompressionError.Create('error'); //!! +end; + +procedure CompressBuf(const InBuf: Pointer; InBytes: Integer; + out OutBuf: Pointer; out OutBytes: Integer); +var + strm: TZStreamRec; + P: Pointer; +begin + FillChar(strm, sizeof(strm), 0); + strm.zalloc := zlibAllocMem; + strm.zfree := zlibFreeMem; + OutBytes := ((InBytes + (InBytes div 10) + 12) + 255) and not 255; + GetMem(OutBuf, OutBytes); + try + strm.next_in := InBuf; + strm.avail_in := InBytes; + strm.next_out := OutBuf; + strm.avail_out := OutBytes; + CCheck(deflateInit_(strm, Z_BEST_COMPRESSION, zlib_version, sizeof(strm))); + try + while CCheck(deflate(strm, Z_FINISH)) <> Z_STREAM_END do + begin + P := OutBuf; + Inc(OutBytes, 256); + ReallocMem(OutBuf, OutBytes); + strm.next_out := PChar(Integer(OutBuf) + (Integer(strm.next_out) - Integer(P))); + strm.avail_out := 256; + end; + finally + CCheck(deflateEnd(strm)); + end; + ReallocMem(OutBuf, strm.total_out); + OutBytes := strm.total_out; + except + FreeMem(OutBuf); + raise + end; +end; + + +procedure DecompressBuf(const InBuf: Pointer; InBytes: Integer; + OutEstimate: Integer; out OutBuf: Pointer; out OutBytes: Integer); +var + strm: TZStreamRec; + P: Pointer; + BufInc: Integer; +begin + FillChar(strm, sizeof(strm), 0); + strm.zalloc := zlibAllocMem; + strm.zfree := zlibFreeMem; + BufInc := (InBytes + 255) and not 255; + if OutEstimate = 0 then + OutBytes := BufInc + else + OutBytes := OutEstimate; + GetMem(OutBuf, OutBytes); + try + strm.next_in := InBuf; + strm.avail_in := InBytes; + strm.next_out := OutBuf; + strm.avail_out := OutBytes; + DCheck(inflateInit_(strm, zlib_version, sizeof(strm))); + try + while DCheck(inflate(strm, Z_NO_FLUSH)) <> Z_STREAM_END do + begin + P := OutBuf; + Inc(OutBytes, BufInc); + ReallocMem(OutBuf, OutBytes); + strm.next_out := PChar(Integer(OutBuf) + (Integer(strm.next_out) - Integer(P))); + strm.avail_out := BufInc; + end; + finally + DCheck(inflateEnd(strm)); + end; + ReallocMem(OutBuf, strm.total_out); + OutBytes := strm.total_out; + except + FreeMem(OutBuf); + raise + end; +end; + +procedure DecompressToUserBuf(const InBuf: Pointer; InBytes: Integer; + const OutBuf: Pointer; BufSize: Integer); +var + strm: TZStreamRec; +begin + FillChar(strm, sizeof(strm), 0); + strm.zalloc := zlibAllocMem; + strm.zfree := zlibFreeMem; + strm.next_in := InBuf; + strm.avail_in := InBytes; + strm.next_out := OutBuf; + strm.avail_out := BufSize; + DCheck(inflateInit_(strm, zlib_version, sizeof(strm))); + try + if DCheck(inflate(strm, Z_FINISH)) <> Z_STREAM_END then + raise EZlibError.CreateRes(@sTargetBufferTooSmall); + finally + DCheck(inflateEnd(strm)); + end; +end; + +// TCustomZlibStream + +constructor TCustomZLibStream.Create(Strm: TStream); +begin + inherited Create; + FStrm := Strm; + FStrmPos := Strm.Position; + FZRec.zalloc := zlibAllocMem; + FZRec.zfree := zlibFreeMem; +end; + +procedure TCustomZLibStream.Progress(Sender: TObject); +begin + if Assigned(FOnProgress) then FOnProgress(Sender); +end; + + +// TCompressionStream + +constructor TCompressionStream.Create(CompressionLevel: TCompressionLevel; + Dest: TStream); +const + Levels: array [TCompressionLevel] of ShortInt = + (Z_NO_COMPRESSION, Z_BEST_SPEED, Z_DEFAULT_COMPRESSION, Z_BEST_COMPRESSION); +begin + inherited Create(Dest); + FZRec.next_out := FBuffer; + FZRec.avail_out := sizeof(FBuffer); + CCheck(deflateInit_(FZRec, Levels[CompressionLevel], zlib_version, sizeof(FZRec))); +end; + +destructor TCompressionStream.Destroy; +begin + FZRec.next_in := nil; + FZRec.avail_in := 0; + try + if FStrm.Position <> FStrmPos then FStrm.Position := FStrmPos; + while (CCheck(deflate(FZRec, Z_FINISH)) <> Z_STREAM_END) + and (FZRec.avail_out = 0) do + begin + FStrm.WriteBuffer(FBuffer, sizeof(FBuffer)); + FZRec.next_out := FBuffer; + FZRec.avail_out := sizeof(FBuffer); + end; + if FZRec.avail_out < sizeof(FBuffer) then + FStrm.WriteBuffer(FBuffer, sizeof(FBuffer) - FZRec.avail_out); + finally + deflateEnd(FZRec); + end; + inherited Destroy; +end; + +function TCompressionStream.Read(var Buffer; Count: Longint): Longint; +begin + raise ECompressionError.CreateRes(@sInvalidStreamOp); +end; + +function TCompressionStream.Write(const Buffer; Count: Longint): Longint; +begin + FZRec.next_in := @Buffer; + FZRec.avail_in := Count; + if FStrm.Position <> FStrmPos then FStrm.Position := FStrmPos; + while (FZRec.avail_in > 0) do + begin + CCheck(deflate(FZRec, 0)); + if FZRec.avail_out = 0 then + begin + FStrm.WriteBuffer(FBuffer, sizeof(FBuffer)); + FZRec.next_out := FBuffer; + FZRec.avail_out := sizeof(FBuffer); + FStrmPos := FStrm.Position; + Progress(Self); + end; + end; + Result := Count; +end; + +function TCompressionStream.Seek(Offset: Longint; Origin: Word): Longint; +begin + if (Offset = 0) and (Origin = soFromCurrent) then + Result := FZRec.total_in + else + raise ECompressionError.CreateRes(@sInvalidStreamOp); +end; + +function TCompressionStream.GetCompressionRate: Single; +begin + if FZRec.total_in = 0 then + Result := 0 + else + Result := (1.0 - (FZRec.total_out / FZRec.total_in)) * 100.0; +end; + + +// TDecompressionStream + +constructor TDecompressionStream.Create(Source: TStream); +begin + inherited Create(Source); + FZRec.next_in := FBuffer; + FZRec.avail_in := 0; + DCheck(inflateInit_(FZRec, zlib_version, sizeof(FZRec))); +end; + +destructor TDecompressionStream.Destroy; +begin + FStrm.Seek(-FZRec.avail_in, 1); + inflateEnd(FZRec); + inherited Destroy; +end; + +function TDecompressionStream.Read(var Buffer; Count: Longint): Longint; +begin + FZRec.next_out := @Buffer; + FZRec.avail_out := Count; + if FStrm.Position <> FStrmPos then FStrm.Position := FStrmPos; + while (FZRec.avail_out > 0) do + begin + if FZRec.avail_in = 0 then + begin + FZRec.avail_in := FStrm.Read(FBuffer, sizeof(FBuffer)); + if FZRec.avail_in = 0 then + begin + Result := Count - FZRec.avail_out; + Exit; + end; + FZRec.next_in := FBuffer; + FStrmPos := FStrm.Position; + Progress(Self); + end; + CCheck(inflate(FZRec, 0)); + end; + Result := Count; +end; + +function TDecompressionStream.Write(const Buffer; Count: Longint): Longint; +begin + raise EDecompressionError.CreateRes(@sInvalidStreamOp); +end; + +function TDecompressionStream.Seek(Offset: Longint; Origin: Word): Longint; +var + I: Integer; + Buf: array [0..4095] of Char; +begin + if (Offset = 0) and (Origin = soFromBeginning) then + begin + DCheck(inflateReset(FZRec)); + FZRec.next_in := FBuffer; + FZRec.avail_in := 0; + FStrm.Position := 0; + FStrmPos := 0; + end + else if ( (Offset >= 0) and (Origin = soFromCurrent)) or + ( ((Offset - FZRec.total_out) > 0) and (Origin = soFromBeginning)) then + begin + if Origin = soFromBeginning then Dec(Offset, FZRec.total_out); + if Offset > 0 then + begin + for I := 1 to Offset div sizeof(Buf) do + ReadBuffer(Buf, sizeof(Buf)); + ReadBuffer(Buf, Offset mod sizeof(Buf)); + end; + end + else + raise EDecompressionError.CreateRes(@sInvalidStreamOp); + Result := FZRec.total_out; +end; + + +end. diff --git a/libs/zlib/contrib/delphi/ZLibConst.pas b/libs/zlib/contrib/delphi/ZLibConst.pas new file mode 100644 index 000000000..cdfe13671 --- /dev/null +++ b/libs/zlib/contrib/delphi/ZLibConst.pas @@ -0,0 +1,11 @@ +unit ZLibConst; + +interface + +resourcestring + sTargetBufferTooSmall = 'ZLib error: target buffer may be too small'; + sInvalidStreamOp = 'Invalid stream operation'; + +implementation + +end. diff --git a/libs/zlib/contrib/delphi/readme.txt b/libs/zlib/contrib/delphi/readme.txt new file mode 100644 index 000000000..2dc9a8bba --- /dev/null +++ b/libs/zlib/contrib/delphi/readme.txt @@ -0,0 +1,76 @@ + +Overview +======== + +This directory contains an update to the ZLib interface unit, +distributed by Borland as a Delphi supplemental component. + +The original ZLib unit is Copyright (c) 1997,99 Borland Corp., +and is based on zlib version 1.0.4. There are a series of bugs +and security problems associated with that old zlib version, and +we recommend the users to update their ZLib unit. + + +Summary of modifications +======================== + +- Improved makefile, adapted to zlib version 1.2.1. + +- Some field types from TZStreamRec are changed from Integer to + Longint, for consistency with the zlib.h header, and for 64-bit + readiness. + +- The zlib_version constant is updated. + +- The new Z_RLE strategy has its corresponding symbolic constant. + +- The allocation and deallocation functions and function types + (TAlloc, TFree, zlibAllocMem and zlibFreeMem) are now cdecl, + and _malloc and _free are added as C RTL stubs. As a result, + the original C sources of zlib can be compiled out of the box, + and linked to the ZLib unit. + + +Suggestions for improvements +============================ + +Currently, the ZLib unit provides only a limited wrapper around +the zlib library, and much of the original zlib functionality is +missing. Handling compressed file formats like ZIP/GZIP or PNG +cannot be implemented without having this functionality. +Applications that handle these formats are either using their own, +duplicated code, or not using the ZLib unit at all. + +Here are a few suggestions: + +- Checksum class wrappers around adler32() and crc32(), similar + to the Java classes that implement the java.util.zip.Checksum + interface. + +- The ability to read and write raw deflate streams, without the + zlib stream header and trailer. Raw deflate streams are used + in the ZIP file format. + +- The ability to read and write gzip streams, used in the GZIP + file format, and normally produced by the gzip program. + +- The ability to select a different compression strategy, useful + to PNG and MNG image compression, and to multimedia compression + in general. Besides the compression level + + TCompressionLevel = (clNone, clFastest, clDefault, clMax); + + which, in fact, could have used the 'z' prefix and avoided + TColor-like symbols + + TCompressionLevel = (zcNone, zcFastest, zcDefault, zcMax); + + there could be a compression strategy + + TCompressionStrategy = (zsDefault, zsFiltered, zsHuffmanOnly, zsRle); + +- ZIP and GZIP stream handling via TStreams. + + +-- +Cosmin Truta diff --git a/libs/zlib/contrib/delphi/zlibd32.mak b/libs/zlib/contrib/delphi/zlibd32.mak new file mode 100644 index 000000000..d65ab4dab --- /dev/null +++ b/libs/zlib/contrib/delphi/zlibd32.mak @@ -0,0 +1,99 @@ +# Makefile for zlib +# For use with Delphi and C++ Builder under Win32 +# Updated for zlib 1.2.x by Cosmin Truta + +# ------------ Borland C++ ------------ + +# This project uses the Delphi (fastcall/register) calling convention: +LOC = -DZEXPORT=__fastcall -DZEXPORTVA=__cdecl + +CC = bcc32 +LD = bcc32 +AR = tlib +# do not use "-pr" in CFLAGS +CFLAGS = -a -d -k- -O2 $(LOC) +LDFLAGS = + + +# variables +ZLIB_LIB = zlib.lib + +OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzclose.obj gzlib.obj gzread.obj +OBJ2 = gzwrite.obj infback.obj inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj +OBJP1 = +adler32.obj+compress.obj+crc32.obj+deflate.obj+gzclose.obj+gzlib.obj+gzread.obj +OBJP2 = +gzwrite.obj+infback.obj+inffast.obj+inflate.obj+inftrees.obj+trees.obj+uncompr.obj+zutil.obj + + +# targets +all: $(ZLIB_LIB) example.exe minigzip.exe + +.c.obj: + $(CC) -c $(CFLAGS) $*.c + +adler32.obj: adler32.c zlib.h zconf.h + +compress.obj: compress.c zlib.h zconf.h + +crc32.obj: crc32.c zlib.h zconf.h crc32.h + +deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h + +gzclose.obj: gzclose.c zlib.h zconf.h gzguts.h + +gzlib.obj: gzlib.c zlib.h zconf.h gzguts.h + +gzread.obj: gzread.c zlib.h zconf.h gzguts.h + +gzwrite.obj: gzwrite.c zlib.h zconf.h gzguts.h + +infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ + inffast.h inffixed.h + +inffast.obj: inffast.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ + inffast.h + +inflate.obj: inflate.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ + inffast.h inffixed.h + +inftrees.obj: inftrees.c zutil.h zlib.h zconf.h inftrees.h + +trees.obj: trees.c zutil.h zlib.h zconf.h deflate.h trees.h + +uncompr.obj: uncompr.c zlib.h zconf.h + +zutil.obj: zutil.c zutil.h zlib.h zconf.h + +example.obj: example.c zlib.h zconf.h + +minigzip.obj: minigzip.c zlib.h zconf.h + + +# For the sake of the old Borland make, +# the command line is cut to fit in the MS-DOS 128 byte limit: +$(ZLIB_LIB): $(OBJ1) $(OBJ2) + -del $(ZLIB_LIB) + $(AR) $(ZLIB_LIB) $(OBJP1) + $(AR) $(ZLIB_LIB) $(OBJP2) + + +# testing +test: example.exe minigzip.exe + example + echo hello world | minigzip | minigzip -d + +example.exe: example.obj $(ZLIB_LIB) + $(LD) $(LDFLAGS) example.obj $(ZLIB_LIB) + +minigzip.exe: minigzip.obj $(ZLIB_LIB) + $(LD) $(LDFLAGS) minigzip.obj $(ZLIB_LIB) + + +# cleanup +clean: + -del *.obj + -del *.exe + -del *.lib + -del *.tds + -del zlib.bak + -del foo.gz + diff --git a/libs/zlib/contrib/dotzlib/DotZLib.build b/libs/zlib/contrib/dotzlib/DotZLib.build new file mode 100644 index 000000000..e69630cec --- /dev/null +++ b/libs/zlib/contrib/dotzlib/DotZLib.build @@ -0,0 +1,33 @@ + + + A .Net wrapper library around ZLib1.dll + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/libs/zlib/contrib/dotzlib/DotZLib.chm b/libs/zlib/contrib/dotzlib/DotZLib.chm new file mode 100644 index 000000000..f214a444a Binary files /dev/null and b/libs/zlib/contrib/dotzlib/DotZLib.chm differ diff --git a/libs/zlib/contrib/dotzlib/DotZLib.sln b/libs/zlib/contrib/dotzlib/DotZLib.sln new file mode 100644 index 000000000..ac45ca048 --- /dev/null +++ b/libs/zlib/contrib/dotzlib/DotZLib.sln @@ -0,0 +1,21 @@ +Microsoft Visual Studio Solution File, Format Version 8.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotZLib", "DotZLib\DotZLib.csproj", "{BB1EE0B1-1808-46CB-B786-949D91117FC5}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfiguration) = preSolution + Debug = Debug + Release = Release + EndGlobalSection + GlobalSection(ProjectConfiguration) = postSolution + {BB1EE0B1-1808-46CB-B786-949D91117FC5}.Debug.ActiveCfg = Debug|.NET + {BB1EE0B1-1808-46CB-B786-949D91117FC5}.Debug.Build.0 = Debug|.NET + {BB1EE0B1-1808-46CB-B786-949D91117FC5}.Release.ActiveCfg = Release|.NET + {BB1EE0B1-1808-46CB-B786-949D91117FC5}.Release.Build.0 = Release|.NET + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + EndGlobalSection + GlobalSection(ExtensibilityAddIns) = postSolution + EndGlobalSection +EndGlobal diff --git a/libs/zlib/contrib/dotzlib/DotZLib/AssemblyInfo.cs b/libs/zlib/contrib/dotzlib/DotZLib/AssemblyInfo.cs new file mode 100644 index 000000000..0491bfc2b --- /dev/null +++ b/libs/zlib/contrib/dotzlib/DotZLib/AssemblyInfo.cs @@ -0,0 +1,58 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly: AssemblyTitle("DotZLib")] +[assembly: AssemblyDescription(".Net bindings for ZLib compression dll 1.2.x")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Henrik Ravn")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("(c) 2004 by Henrik Ravn")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly: AssemblyVersion("1.0.*")] + +// +// In order to sign your assembly you must specify a key to use. Refer to the +// Microsoft .NET Framework documentation for more information on assembly signing. +// +// Use the attributes below to control which key is used for signing. +// +// Notes: +// (*) If no key is specified, the assembly is not signed. +// (*) KeyName refers to a key that has been installed in the Crypto Service +// Provider (CSP) on your machine. KeyFile refers to a file which contains +// a key. +// (*) If the KeyFile and the KeyName values are both specified, the +// following processing occurs: +// (1) If the KeyName can be found in the CSP, that key is used. +// (2) If the KeyName does not exist and the KeyFile does exist, the key +// in the KeyFile is installed into the CSP and used. +// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. +// When specifying the KeyFile, the location of the KeyFile should be +// relative to the project output directory which is +// %Project Directory%\obj\. For example, if your KeyFile is +// located in the project directory, you would specify the AssemblyKeyFile +// attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")] +// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework +// documentation for more information on this. +// +[assembly: AssemblyDelaySign(false)] +[assembly: AssemblyKeyFile("")] +[assembly: AssemblyKeyName("")] diff --git a/libs/zlib/contrib/dotzlib/DotZLib/ChecksumImpl.cs b/libs/zlib/contrib/dotzlib/DotZLib/ChecksumImpl.cs new file mode 100644 index 000000000..788b2fcec --- /dev/null +++ b/libs/zlib/contrib/dotzlib/DotZLib/ChecksumImpl.cs @@ -0,0 +1,202 @@ +// +// © Copyright Henrik Ravn 2004 +// +// Use, modification and distribution are subject to the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +using System; +using System.Runtime.InteropServices; +using System.Text; + + +namespace DotZLib +{ + #region ChecksumGeneratorBase + /// + /// Implements the common functionality needed for all s + /// + /// + public abstract class ChecksumGeneratorBase : ChecksumGenerator + { + /// + /// The value of the current checksum + /// + protected uint _current; + + /// + /// Initializes a new instance of the checksum generator base - the current checksum is + /// set to zero + /// + public ChecksumGeneratorBase() + { + _current = 0; + } + + /// + /// Initializes a new instance of the checksum generator basewith a specified value + /// + /// The value to set the current checksum to + public ChecksumGeneratorBase(uint initialValue) + { + _current = initialValue; + } + + /// + /// Resets the current checksum to zero + /// + public void Reset() { _current = 0; } + + /// + /// Gets the current checksum value + /// + public uint Value { get { return _current; } } + + /// + /// Updates the current checksum with part of an array of bytes + /// + /// The data to update the checksum with + /// Where in data to start updating + /// The number of bytes from data to use + /// The sum of offset and count is larger than the length of data + /// data is a null reference + /// Offset or count is negative. + /// All the other Update methods are implmeneted in terms of this one. + /// This is therefore the only method a derived class has to implement + public abstract void Update(byte[] data, int offset, int count); + + /// + /// Updates the current checksum with an array of bytes. + /// + /// The data to update the checksum with + public void Update(byte[] data) + { + Update(data, 0, data.Length); + } + + /// + /// Updates the current checksum with the data from a string + /// + /// The string to update the checksum with + /// The characters in the string are converted by the UTF-8 encoding + public void Update(string data) + { + Update(Encoding.UTF8.GetBytes(data)); + } + + /// + /// Updates the current checksum with the data from a string, using a specific encoding + /// + /// The string to update the checksum with + /// The encoding to use + public void Update(string data, Encoding encoding) + { + Update(encoding.GetBytes(data)); + } + + } + #endregion + + #region CRC32 + /// + /// Implements a CRC32 checksum generator + /// + public sealed class CRC32Checksum : ChecksumGeneratorBase + { + #region DLL imports + + [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)] + private static extern uint crc32(uint crc, int data, uint length); + + #endregion + + /// + /// Initializes a new instance of the CRC32 checksum generator + /// + public CRC32Checksum() : base() {} + + /// + /// Initializes a new instance of the CRC32 checksum generator with a specified value + /// + /// The value to set the current checksum to + public CRC32Checksum(uint initialValue) : base(initialValue) {} + + /// + /// Updates the current checksum with part of an array of bytes + /// + /// The data to update the checksum with + /// Where in data to start updating + /// The number of bytes from data to use + /// The sum of offset and count is larger than the length of data + /// data is a null reference + /// Offset or count is negative. + public override void Update(byte[] data, int offset, int count) + { + if (offset < 0 || count < 0) throw new ArgumentOutOfRangeException(); + if ((offset+count) > data.Length) throw new ArgumentException(); + GCHandle hData = GCHandle.Alloc(data, GCHandleType.Pinned); + try + { + _current = crc32(_current, hData.AddrOfPinnedObject().ToInt32()+offset, (uint)count); + } + finally + { + hData.Free(); + } + } + + } + #endregion + + #region Adler + /// + /// Implements a checksum generator that computes the Adler checksum on data + /// + public sealed class AdlerChecksum : ChecksumGeneratorBase + { + #region DLL imports + + [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)] + private static extern uint adler32(uint adler, int data, uint length); + + #endregion + + /// + /// Initializes a new instance of the Adler checksum generator + /// + public AdlerChecksum() : base() {} + + /// + /// Initializes a new instance of the Adler checksum generator with a specified value + /// + /// The value to set the current checksum to + public AdlerChecksum(uint initialValue) : base(initialValue) {} + + /// + /// Updates the current checksum with part of an array of bytes + /// + /// The data to update the checksum with + /// Where in data to start updating + /// The number of bytes from data to use + /// The sum of offset and count is larger than the length of data + /// data is a null reference + /// Offset or count is negative. + public override void Update(byte[] data, int offset, int count) + { + if (offset < 0 || count < 0) throw new ArgumentOutOfRangeException(); + if ((offset+count) > data.Length) throw new ArgumentException(); + GCHandle hData = GCHandle.Alloc(data, GCHandleType.Pinned); + try + { + _current = adler32(_current, hData.AddrOfPinnedObject().ToInt32()+offset, (uint)count); + } + finally + { + hData.Free(); + } + } + + } + #endregion + +} \ No newline at end of file diff --git a/libs/zlib/contrib/dotzlib/DotZLib/CircularBuffer.cs b/libs/zlib/contrib/dotzlib/DotZLib/CircularBuffer.cs new file mode 100644 index 000000000..c1cab3a02 --- /dev/null +++ b/libs/zlib/contrib/dotzlib/DotZLib/CircularBuffer.cs @@ -0,0 +1,83 @@ +// +// © Copyright Henrik Ravn 2004 +// +// Use, modification and distribution are subject to the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +using System; +using System.Diagnostics; + +namespace DotZLib +{ + + /// + /// This class implements a circular buffer + /// + internal class CircularBuffer + { + #region Private data + private int _capacity; + private int _head; + private int _tail; + private int _size; + private byte[] _buffer; + #endregion + + public CircularBuffer(int capacity) + { + Debug.Assert( capacity > 0 ); + _buffer = new byte[capacity]; + _capacity = capacity; + _head = 0; + _tail = 0; + _size = 0; + } + + public int Size { get { return _size; } } + + public int Put(byte[] source, int offset, int count) + { + Debug.Assert( count > 0 ); + int trueCount = Math.Min(count, _capacity - Size); + for (int i = 0; i < trueCount; ++i) + _buffer[(_tail+i) % _capacity] = source[offset+i]; + _tail += trueCount; + _tail %= _capacity; + _size += trueCount; + return trueCount; + } + + public bool Put(byte b) + { + if (Size == _capacity) // no room + return false; + _buffer[_tail++] = b; + _tail %= _capacity; + ++_size; + return true; + } + + public int Get(byte[] destination, int offset, int count) + { + int trueCount = Math.Min(count,Size); + for (int i = 0; i < trueCount; ++i) + destination[offset + i] = _buffer[(_head+i) % _capacity]; + _head += trueCount; + _head %= _capacity; + _size -= trueCount; + return trueCount; + } + + public int Get() + { + if (Size == 0) + return -1; + + int result = (int)_buffer[_head++ % _capacity]; + --_size; + return result; + } + + } +} diff --git a/libs/zlib/contrib/dotzlib/DotZLib/CodecBase.cs b/libs/zlib/contrib/dotzlib/DotZLib/CodecBase.cs new file mode 100644 index 000000000..42e6da3a5 --- /dev/null +++ b/libs/zlib/contrib/dotzlib/DotZLib/CodecBase.cs @@ -0,0 +1,198 @@ +// +// © Copyright Henrik Ravn 2004 +// +// Use, modification and distribution are subject to the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +using System; +using System.Runtime.InteropServices; + +namespace DotZLib +{ + /// + /// Implements the common functionality needed for all s + /// + public abstract class CodecBase : Codec, IDisposable + { + + #region Data members + + /// + /// Instance of the internal zlib buffer structure that is + /// passed to all functions in the zlib dll + /// + internal ZStream _ztream = new ZStream(); + + /// + /// True if the object instance has been disposed, false otherwise + /// + protected bool _isDisposed = false; + + /// + /// The size of the internal buffers + /// + protected const int kBufferSize = 16384; + + private byte[] _outBuffer = new byte[kBufferSize]; + private byte[] _inBuffer = new byte[kBufferSize]; + + private GCHandle _hInput; + private GCHandle _hOutput; + + private uint _checksum = 0; + + #endregion + + /// + /// Initializes a new instance of the CodeBase class. + /// + public CodecBase() + { + try + { + _hInput = GCHandle.Alloc(_inBuffer, GCHandleType.Pinned); + _hOutput = GCHandle.Alloc(_outBuffer, GCHandleType.Pinned); + } + catch (Exception) + { + CleanUp(false); + throw; + } + } + + + #region Codec Members + + /// + /// Occurs when more processed data are available. + /// + public event DataAvailableHandler DataAvailable; + + /// + /// Fires the event + /// + protected void OnDataAvailable() + { + if (_ztream.total_out > 0) + { + if (DataAvailable != null) + DataAvailable( _outBuffer, 0, (int)_ztream.total_out); + resetOutput(); + } + } + + /// + /// Adds more data to the codec to be processed. + /// + /// Byte array containing the data to be added to the codec + /// Adding data may, or may not, raise the DataAvailable event + public void Add(byte[] data) + { + Add(data,0,data.Length); + } + + /// + /// Adds more data to the codec to be processed. + /// + /// Byte array containing the data to be added to the codec + /// The index of the first byte to add from data + /// The number of bytes to add + /// Adding data may, or may not, raise the DataAvailable event + /// This must be implemented by a derived class + public abstract void Add(byte[] data, int offset, int count); + + /// + /// Finishes up any pending data that needs to be processed and handled. + /// + /// This must be implemented by a derived class + public abstract void Finish(); + + /// + /// Gets the checksum of the data that has been added so far + /// + public uint Checksum { get { return _checksum; } } + + #endregion + + #region Destructor & IDisposable stuff + + /// + /// Destroys this instance + /// + ~CodecBase() + { + CleanUp(false); + } + + /// + /// Releases any unmanaged resources and calls the method of the derived class + /// + public void Dispose() + { + CleanUp(true); + } + + /// + /// Performs any codec specific cleanup + /// + /// This must be implemented by a derived class + protected abstract void CleanUp(); + + // performs the release of the handles and calls the dereived CleanUp() + private void CleanUp(bool isDisposing) + { + if (!_isDisposed) + { + CleanUp(); + if (_hInput.IsAllocated) + _hInput.Free(); + if (_hOutput.IsAllocated) + _hOutput.Free(); + + _isDisposed = true; + } + } + + + #endregion + + #region Helper methods + + /// + /// Copies a number of bytes to the internal codec buffer - ready for proccesing + /// + /// The byte array that contains the data to copy + /// The index of the first byte to copy + /// The number of bytes to copy from data + protected void copyInput(byte[] data, int startIndex, int count) + { + Array.Copy(data, startIndex, _inBuffer,0, count); + _ztream.next_in = _hInput.AddrOfPinnedObject(); + _ztream.total_in = 0; + _ztream.avail_in = (uint)count; + + } + + /// + /// Resets the internal output buffers to a known state - ready for processing + /// + protected void resetOutput() + { + _ztream.total_out = 0; + _ztream.avail_out = kBufferSize; + _ztream.next_out = _hOutput.AddrOfPinnedObject(); + } + + /// + /// Updates the running checksum property + /// + /// The new checksum value + protected void setChecksum(uint newSum) + { + _checksum = newSum; + } + #endregion + + } +} diff --git a/libs/zlib/contrib/dotzlib/DotZLib/Deflater.cs b/libs/zlib/contrib/dotzlib/DotZLib/Deflater.cs new file mode 100644 index 000000000..c2477925b --- /dev/null +++ b/libs/zlib/contrib/dotzlib/DotZLib/Deflater.cs @@ -0,0 +1,106 @@ +// +// © Copyright Henrik Ravn 2004 +// +// Use, modification and distribution are subject to the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +using System; +using System.Diagnostics; +using System.Runtime.InteropServices; + +namespace DotZLib +{ + + /// + /// Implements a data compressor, using the deflate algorithm in the ZLib dll + /// + public sealed class Deflater : CodecBase + { + #region Dll imports + [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl, CharSet=CharSet.Ansi)] + private static extern int deflateInit_(ref ZStream sz, int level, string vs, int size); + + [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)] + private static extern int deflate(ref ZStream sz, int flush); + + [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)] + private static extern int deflateReset(ref ZStream sz); + + [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)] + private static extern int deflateEnd(ref ZStream sz); + #endregion + + /// + /// Constructs an new instance of the Deflater + /// + /// The compression level to use for this Deflater + public Deflater(CompressLevel level) : base() + { + int retval = deflateInit_(ref _ztream, (int)level, Info.Version, Marshal.SizeOf(_ztream)); + if (retval != 0) + throw new ZLibException(retval, "Could not initialize deflater"); + + resetOutput(); + } + + /// + /// Adds more data to the codec to be processed. + /// + /// Byte array containing the data to be added to the codec + /// The index of the first byte to add from data + /// The number of bytes to add + /// Adding data may, or may not, raise the DataAvailable event + public override void Add(byte[] data, int offset, int count) + { + if (data == null) throw new ArgumentNullException(); + if (offset < 0 || count < 0) throw new ArgumentOutOfRangeException(); + if ((offset+count) > data.Length) throw new ArgumentException(); + + int total = count; + int inputIndex = offset; + int err = 0; + + while (err >= 0 && inputIndex < total) + { + copyInput(data, inputIndex, Math.Min(total - inputIndex, kBufferSize)); + while (err >= 0 && _ztream.avail_in > 0) + { + err = deflate(ref _ztream, (int)FlushTypes.None); + if (err == 0) + while (_ztream.avail_out == 0) + { + OnDataAvailable(); + err = deflate(ref _ztream, (int)FlushTypes.None); + } + inputIndex += (int)_ztream.total_in; + } + } + setChecksum( _ztream.adler ); + } + + + /// + /// Finishes up any pending data that needs to be processed and handled. + /// + public override void Finish() + { + int err; + do + { + err = deflate(ref _ztream, (int)FlushTypes.Finish); + OnDataAvailable(); + } + while (err == 0); + setChecksum( _ztream.adler ); + deflateReset(ref _ztream); + resetOutput(); + } + + /// + /// Closes the internal zlib deflate stream + /// + protected override void CleanUp() { deflateEnd(ref _ztream); } + + } +} diff --git a/libs/zlib/contrib/dotzlib/DotZLib/DotZLib.cs b/libs/zlib/contrib/dotzlib/DotZLib/DotZLib.cs new file mode 100644 index 000000000..be184b4c7 --- /dev/null +++ b/libs/zlib/contrib/dotzlib/DotZLib/DotZLib.cs @@ -0,0 +1,288 @@ +// +// © Copyright Henrik Ravn 2004 +// +// Use, modification and distribution are subject to the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +using System; +using System.IO; +using System.Runtime.InteropServices; +using System.Text; + + +namespace DotZLib +{ + + #region Internal types + + /// + /// Defines constants for the various flush types used with zlib + /// + internal enum FlushTypes + { + None, Partial, Sync, Full, Finish, Block + } + + #region ZStream structure + // internal mapping of the zlib zstream structure for marshalling + [StructLayoutAttribute(LayoutKind.Sequential, Pack=4, Size=0, CharSet=CharSet.Ansi)] + internal struct ZStream + { + public IntPtr next_in; + public uint avail_in; + public uint total_in; + + public IntPtr next_out; + public uint avail_out; + public uint total_out; + + [MarshalAs(UnmanagedType.LPStr)] + string msg; + uint state; + + uint zalloc; + uint zfree; + uint opaque; + + int data_type; + public uint adler; + uint reserved; + } + + #endregion + + #endregion + + #region Public enums + /// + /// Defines constants for the available compression levels in zlib + /// + public enum CompressLevel : int + { + /// + /// The default compression level with a reasonable compromise between compression and speed + /// + Default = -1, + /// + /// No compression at all. The data are passed straight through. + /// + None = 0, + /// + /// The maximum compression rate available. + /// + Best = 9, + /// + /// The fastest available compression level. + /// + Fastest = 1 + } + #endregion + + #region Exception classes + /// + /// The exception that is thrown when an error occurs on the zlib dll + /// + public class ZLibException : ApplicationException + { + /// + /// Initializes a new instance of the class with a specified + /// error message and error code + /// + /// The zlib error code that caused the exception + /// A message that (hopefully) describes the error + public ZLibException(int errorCode, string msg) : base(String.Format("ZLib error {0} {1}", errorCode, msg)) + { + } + + /// + /// Initializes a new instance of the class with a specified + /// error code + /// + /// The zlib error code that caused the exception + public ZLibException(int errorCode) : base(String.Format("ZLib error {0}", errorCode)) + { + } + } + #endregion + + #region Interfaces + + /// + /// Declares methods and properties that enables a running checksum to be calculated + /// + public interface ChecksumGenerator + { + /// + /// Gets the current value of the checksum + /// + uint Value { get; } + + /// + /// Clears the current checksum to 0 + /// + void Reset(); + + /// + /// Updates the current checksum with an array of bytes + /// + /// The data to update the checksum with + void Update(byte[] data); + + /// + /// Updates the current checksum with part of an array of bytes + /// + /// The data to update the checksum with + /// Where in data to start updating + /// The number of bytes from data to use + /// The sum of offset and count is larger than the length of data + /// data is a null reference + /// Offset or count is negative. + void Update(byte[] data, int offset, int count); + + /// + /// Updates the current checksum with the data from a string + /// + /// The string to update the checksum with + /// The characters in the string are converted by the UTF-8 encoding + void Update(string data); + + /// + /// Updates the current checksum with the data from a string, using a specific encoding + /// + /// The string to update the checksum with + /// The encoding to use + void Update(string data, Encoding encoding); + } + + + /// + /// Represents the method that will be called from a codec when new data + /// are available. + /// + /// The byte array containing the processed data + /// The index of the first processed byte in data + /// The number of processed bytes available + /// On return from this method, the data may be overwritten, so grab it while you can. + /// You cannot assume that startIndex will be zero. + /// + public delegate void DataAvailableHandler(byte[] data, int startIndex, int count); + + /// + /// Declares methods and events for implementing compressors/decompressors + /// + public interface Codec + { + /// + /// Occurs when more processed data are available. + /// + event DataAvailableHandler DataAvailable; + + /// + /// Adds more data to the codec to be processed. + /// + /// Byte array containing the data to be added to the codec + /// Adding data may, or may not, raise the DataAvailable event + void Add(byte[] data); + + /// + /// Adds more data to the codec to be processed. + /// + /// Byte array containing the data to be added to the codec + /// The index of the first byte to add from data + /// The number of bytes to add + /// Adding data may, or may not, raise the DataAvailable event + void Add(byte[] data, int offset, int count); + + /// + /// Finishes up any pending data that needs to be processed and handled. + /// + void Finish(); + + /// + /// Gets the checksum of the data that has been added so far + /// + uint Checksum { get; } + + + } + + #endregion + + #region Classes + /// + /// Encapsulates general information about the ZLib library + /// + public class Info + { + #region DLL imports + [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)] + private static extern uint zlibCompileFlags(); + + [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)] + private static extern string zlibVersion(); + #endregion + + #region Private stuff + private uint _flags; + + // helper function that unpacks a bitsize mask + private static int bitSize(uint bits) + { + switch (bits) + { + case 0: return 16; + case 1: return 32; + case 2: return 64; + } + return -1; + } + #endregion + + /// + /// Constructs an instance of the Info class. + /// + public Info() + { + _flags = zlibCompileFlags(); + } + + /// + /// True if the library is compiled with debug info + /// + public bool HasDebugInfo { get { return 0 != (_flags & 0x100); } } + + /// + /// True if the library is compiled with assembly optimizations + /// + public bool UsesAssemblyCode { get { return 0 != (_flags & 0x200); } } + + /// + /// Gets the size of the unsigned int that was compiled into Zlib + /// + public int SizeOfUInt { get { return bitSize(_flags & 3); } } + + /// + /// Gets the size of the unsigned long that was compiled into Zlib + /// + public int SizeOfULong { get { return bitSize((_flags >> 2) & 3); } } + + /// + /// Gets the size of the pointers that were compiled into Zlib + /// + public int SizeOfPointer { get { return bitSize((_flags >> 4) & 3); } } + + /// + /// Gets the size of the z_off_t type that was compiled into Zlib + /// + public int SizeOfOffset { get { return bitSize((_flags >> 6) & 3); } } + + /// + /// Gets the version of ZLib as a string, e.g. "1.2.1" + /// + public static string Version { get { return zlibVersion(); } } + } + + #endregion + +} diff --git a/libs/zlib/contrib/dotzlib/DotZLib/DotZLib.csproj b/libs/zlib/contrib/dotzlib/DotZLib/DotZLib.csproj new file mode 100644 index 000000000..71eeb8590 --- /dev/null +++ b/libs/zlib/contrib/dotzlib/DotZLib/DotZLib.csproj @@ -0,0 +1,141 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/zlib/contrib/dotzlib/DotZLib/GZipStream.cs b/libs/zlib/contrib/dotzlib/DotZLib/GZipStream.cs new file mode 100644 index 000000000..b161300b1 --- /dev/null +++ b/libs/zlib/contrib/dotzlib/DotZLib/GZipStream.cs @@ -0,0 +1,301 @@ +// +// © Copyright Henrik Ravn 2004 +// +// Use, modification and distribution are subject to the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +using System; +using System.IO; +using System.Runtime.InteropServices; + +namespace DotZLib +{ + /// + /// Implements a compressed , in GZip (.gz) format. + /// + public class GZipStream : Stream, IDisposable + { + #region Dll Imports + [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl, CharSet=CharSet.Ansi)] + private static extern IntPtr gzopen(string name, string mode); + + [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)] + private static extern int gzclose(IntPtr gzFile); + + [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)] + private static extern int gzwrite(IntPtr gzFile, int data, int length); + + [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)] + private static extern int gzread(IntPtr gzFile, int data, int length); + + [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)] + private static extern int gzgetc(IntPtr gzFile); + + [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)] + private static extern int gzputc(IntPtr gzFile, int c); + + #endregion + + #region Private data + private IntPtr _gzFile; + private bool _isDisposed = false; + private bool _isWriting; + #endregion + + #region Constructors + /// + /// Creates a new file as a writeable GZipStream + /// + /// The name of the compressed file to create + /// The compression level to use when adding data + /// If an error occurred in the internal zlib function + public GZipStream(string fileName, CompressLevel level) + { + _isWriting = true; + _gzFile = gzopen(fileName, String.Format("wb{0}", (int)level)); + if (_gzFile == IntPtr.Zero) + throw new ZLibException(-1, "Could not open " + fileName); + } + + /// + /// Opens an existing file as a readable GZipStream + /// + /// The name of the file to open + /// If an error occurred in the internal zlib function + public GZipStream(string fileName) + { + _isWriting = false; + _gzFile = gzopen(fileName, "rb"); + if (_gzFile == IntPtr.Zero) + throw new ZLibException(-1, "Could not open " + fileName); + + } + #endregion + + #region Access properties + /// + /// Returns true of this stream can be read from, false otherwise + /// + public override bool CanRead + { + get + { + return !_isWriting; + } + } + + + /// + /// Returns false. + /// + public override bool CanSeek + { + get + { + return false; + } + } + + /// + /// Returns true if this tsream is writeable, false otherwise + /// + public override bool CanWrite + { + get + { + return _isWriting; + } + } + #endregion + + #region Destructor & IDispose stuff + + /// + /// Destroys this instance + /// + ~GZipStream() + { + cleanUp(false); + } + + /// + /// Closes the external file handle + /// + public void Dispose() + { + cleanUp(true); + } + + // Does the actual closing of the file handle. + private void cleanUp(bool isDisposing) + { + if (!_isDisposed) + { + gzclose(_gzFile); + _isDisposed = true; + } + } + #endregion + + #region Basic reading and writing + /// + /// Attempts to read a number of bytes from the stream. + /// + /// The destination data buffer + /// The index of the first destination byte in buffer + /// The number of bytes requested + /// The number of bytes read + /// If buffer is null + /// If count or offset are negative + /// If offset + count is > buffer.Length + /// If this stream is not readable. + /// If this stream has been disposed. + public override int Read(byte[] buffer, int offset, int count) + { + if (!CanRead) throw new NotSupportedException(); + if (buffer == null) throw new ArgumentNullException(); + if (offset < 0 || count < 0) throw new ArgumentOutOfRangeException(); + if ((offset+count) > buffer.Length) throw new ArgumentException(); + if (_isDisposed) throw new ObjectDisposedException("GZipStream"); + + GCHandle h = GCHandle.Alloc(buffer, GCHandleType.Pinned); + int result; + try + { + result = gzread(_gzFile, h.AddrOfPinnedObject().ToInt32() + offset, count); + if (result < 0) + throw new IOException(); + } + finally + { + h.Free(); + } + return result; + } + + /// + /// Attempts to read a single byte from the stream. + /// + /// The byte that was read, or -1 in case of error or End-Of-File + public override int ReadByte() + { + if (!CanRead) throw new NotSupportedException(); + if (_isDisposed) throw new ObjectDisposedException("GZipStream"); + return gzgetc(_gzFile); + } + + /// + /// Writes a number of bytes to the stream + /// + /// + /// + /// + /// If buffer is null + /// If count or offset are negative + /// If offset + count is > buffer.Length + /// If this stream is not writeable. + /// If this stream has been disposed. + public override void Write(byte[] buffer, int offset, int count) + { + if (!CanWrite) throw new NotSupportedException(); + if (buffer == null) throw new ArgumentNullException(); + if (offset < 0 || count < 0) throw new ArgumentOutOfRangeException(); + if ((offset+count) > buffer.Length) throw new ArgumentException(); + if (_isDisposed) throw new ObjectDisposedException("GZipStream"); + + GCHandle h = GCHandle.Alloc(buffer, GCHandleType.Pinned); + try + { + int result = gzwrite(_gzFile, h.AddrOfPinnedObject().ToInt32() + offset, count); + if (result < 0) + throw new IOException(); + } + finally + { + h.Free(); + } + } + + /// + /// Writes a single byte to the stream + /// + /// The byte to add to the stream. + /// If this stream is not writeable. + /// If this stream has been disposed. + public override void WriteByte(byte value) + { + if (!CanWrite) throw new NotSupportedException(); + if (_isDisposed) throw new ObjectDisposedException("GZipStream"); + + int result = gzputc(_gzFile, (int)value); + if (result < 0) + throw new IOException(); + } + #endregion + + #region Position & length stuff + /// + /// Not supported. + /// + /// + /// Always thrown + public override void SetLength(long value) + { + throw new NotSupportedException(); + } + + /// + /// Not suppported. + /// + /// + /// + /// + /// Always thrown + public override long Seek(long offset, SeekOrigin origin) + { + throw new NotSupportedException(); + } + + /// + /// Flushes the GZipStream. + /// + /// In this implementation, this method does nothing. This is because excessive + /// flushing may degrade the achievable compression rates. + public override void Flush() + { + // left empty on purpose + } + + /// + /// Gets/sets the current position in the GZipStream. Not suppported. + /// + /// In this implementation this property is not supported + /// Always thrown + public override long Position + { + get + { + throw new NotSupportedException(); + } + set + { + throw new NotSupportedException(); + } + } + + /// + /// Gets the size of the stream. Not suppported. + /// + /// In this implementation this property is not supported + /// Always thrown + public override long Length + { + get + { + throw new NotSupportedException(); + } + } + #endregion + } +} diff --git a/libs/zlib/contrib/dotzlib/DotZLib/Inflater.cs b/libs/zlib/contrib/dotzlib/DotZLib/Inflater.cs new file mode 100644 index 000000000..8ed5451d6 --- /dev/null +++ b/libs/zlib/contrib/dotzlib/DotZLib/Inflater.cs @@ -0,0 +1,105 @@ +// +// © Copyright Henrik Ravn 2004 +// +// Use, modification and distribution are subject to the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +using System; +using System.Diagnostics; +using System.Runtime.InteropServices; + +namespace DotZLib +{ + + /// + /// Implements a data decompressor, using the inflate algorithm in the ZLib dll + /// + public class Inflater : CodecBase + { + #region Dll imports + [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl, CharSet=CharSet.Ansi)] + private static extern int inflateInit_(ref ZStream sz, string vs, int size); + + [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)] + private static extern int inflate(ref ZStream sz, int flush); + + [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)] + private static extern int inflateReset(ref ZStream sz); + + [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)] + private static extern int inflateEnd(ref ZStream sz); + #endregion + + /// + /// Constructs an new instance of the Inflater + /// + public Inflater() : base() + { + int retval = inflateInit_(ref _ztream, Info.Version, Marshal.SizeOf(_ztream)); + if (retval != 0) + throw new ZLibException(retval, "Could not initialize inflater"); + + resetOutput(); + } + + + /// + /// Adds more data to the codec to be processed. + /// + /// Byte array containing the data to be added to the codec + /// The index of the first byte to add from data + /// The number of bytes to add + /// Adding data may, or may not, raise the DataAvailable event + public override void Add(byte[] data, int offset, int count) + { + if (data == null) throw new ArgumentNullException(); + if (offset < 0 || count < 0) throw new ArgumentOutOfRangeException(); + if ((offset+count) > data.Length) throw new ArgumentException(); + + int total = count; + int inputIndex = offset; + int err = 0; + + while (err >= 0 && inputIndex < total) + { + copyInput(data, inputIndex, Math.Min(total - inputIndex, kBufferSize)); + err = inflate(ref _ztream, (int)FlushTypes.None); + if (err == 0) + while (_ztream.avail_out == 0) + { + OnDataAvailable(); + err = inflate(ref _ztream, (int)FlushTypes.None); + } + + inputIndex += (int)_ztream.total_in; + } + setChecksum( _ztream.adler ); + } + + + /// + /// Finishes up any pending data that needs to be processed and handled. + /// + public override void Finish() + { + int err; + do + { + err = inflate(ref _ztream, (int)FlushTypes.Finish); + OnDataAvailable(); + } + while (err == 0); + setChecksum( _ztream.adler ); + inflateReset(ref _ztream); + resetOutput(); + } + + /// + /// Closes the internal zlib inflate stream + /// + protected override void CleanUp() { inflateEnd(ref _ztream); } + + + } +} diff --git a/libs/zlib/contrib/dotzlib/DotZLib/UnitTests.cs b/libs/zlib/contrib/dotzlib/DotZLib/UnitTests.cs new file mode 100644 index 000000000..b079a0cd6 --- /dev/null +++ b/libs/zlib/contrib/dotzlib/DotZLib/UnitTests.cs @@ -0,0 +1,274 @@ +// +// � Copyright Henrik Ravn 2004 +// +// Use, modification and distribution are subject to the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +using System; +using System.Collections; +using System.IO; + +// uncomment the define below to include unit tests +//#define nunit +#if nunit +using NUnit.Framework; + +// Unit tests for the DotZLib class library +// ---------------------------------------- +// +// Use this with NUnit 2 from http://www.nunit.org +// + +namespace DotZLibTests +{ + using DotZLib; + + // helper methods + internal class Utils + { + public static bool byteArrEqual( byte[] lhs, byte[] rhs ) + { + if (lhs.Length != rhs.Length) + return false; + for (int i = lhs.Length-1; i >= 0; --i) + if (lhs[i] != rhs[i]) + return false; + return true; + } + + } + + + [TestFixture] + public class CircBufferTests + { + #region Circular buffer tests + [Test] + public void SinglePutGet() + { + CircularBuffer buf = new CircularBuffer(10); + Assert.AreEqual( 0, buf.Size ); + Assert.AreEqual( -1, buf.Get() ); + + Assert.IsTrue(buf.Put( 1 )); + Assert.AreEqual( 1, buf.Size ); + Assert.AreEqual( 1, buf.Get() ); + Assert.AreEqual( 0, buf.Size ); + Assert.AreEqual( -1, buf.Get() ); + } + + [Test] + public void BlockPutGet() + { + CircularBuffer buf = new CircularBuffer(10); + byte[] arr = {1,2,3,4,5,6,7,8,9,10}; + Assert.AreEqual( 10, buf.Put(arr,0,10) ); + Assert.AreEqual( 10, buf.Size ); + Assert.IsFalse( buf.Put(11) ); + Assert.AreEqual( 1, buf.Get() ); + Assert.IsTrue( buf.Put(11) ); + + byte[] arr2 = (byte[])arr.Clone(); + Assert.AreEqual( 9, buf.Get(arr2,1,9) ); + Assert.IsTrue( Utils.byteArrEqual(arr,arr2) ); + } + + #endregion + } + + [TestFixture] + public class ChecksumTests + { + #region CRC32 Tests + [Test] + public void CRC32_Null() + { + CRC32Checksum crc32 = new CRC32Checksum(); + Assert.AreEqual( 0, crc32.Value ); + + crc32 = new CRC32Checksum(1); + Assert.AreEqual( 1, crc32.Value ); + + crc32 = new CRC32Checksum(556); + Assert.AreEqual( 556, crc32.Value ); + } + + [Test] + public void CRC32_Data() + { + CRC32Checksum crc32 = new CRC32Checksum(); + byte[] data = { 1,2,3,4,5,6,7 }; + crc32.Update(data); + Assert.AreEqual( 0x70e46888, crc32.Value ); + + crc32 = new CRC32Checksum(); + crc32.Update("penguin"); + Assert.AreEqual( 0x0e5c1a120, crc32.Value ); + + crc32 = new CRC32Checksum(1); + crc32.Update("penguin"); + Assert.AreEqual(0x43b6aa94, crc32.Value); + + } + #endregion + + #region Adler tests + + [Test] + public void Adler_Null() + { + AdlerChecksum adler = new AdlerChecksum(); + Assert.AreEqual(0, adler.Value); + + adler = new AdlerChecksum(1); + Assert.AreEqual( 1, adler.Value ); + + adler = new AdlerChecksum(556); + Assert.AreEqual( 556, adler.Value ); + } + + [Test] + public void Adler_Data() + { + AdlerChecksum adler = new AdlerChecksum(1); + byte[] data = { 1,2,3,4,5,6,7 }; + adler.Update(data); + Assert.AreEqual( 0x5b001d, adler.Value ); + + adler = new AdlerChecksum(); + adler.Update("penguin"); + Assert.AreEqual(0x0bcf02f6, adler.Value ); + + adler = new AdlerChecksum(1); + adler.Update("penguin"); + Assert.AreEqual(0x0bd602f7, adler.Value); + + } + #endregion + } + + [TestFixture] + public class InfoTests + { + #region Info tests + [Test] + public void Info_Version() + { + Info info = new Info(); + Assert.AreEqual("1.2.5", Info.Version); + Assert.AreEqual(32, info.SizeOfUInt); + Assert.AreEqual(32, info.SizeOfULong); + Assert.AreEqual(32, info.SizeOfPointer); + Assert.AreEqual(32, info.SizeOfOffset); + } + #endregion + } + + [TestFixture] + public class DeflateInflateTests + { + #region Deflate tests + [Test] + public void Deflate_Init() + { + using (Deflater def = new Deflater(CompressLevel.Default)) + { + } + } + + private ArrayList compressedData = new ArrayList(); + private uint adler1; + + private ArrayList uncompressedData = new ArrayList(); + private uint adler2; + + public void CDataAvail(byte[] data, int startIndex, int count) + { + for (int i = 0; i < count; ++i) + compressedData.Add(data[i+startIndex]); + } + + [Test] + public void Deflate_Compress() + { + compressedData.Clear(); + + byte[] testData = new byte[35000]; + for (int i = 0; i < testData.Length; ++i) + testData[i] = 5; + + using (Deflater def = new Deflater((CompressLevel)5)) + { + def.DataAvailable += new DataAvailableHandler(CDataAvail); + def.Add(testData); + def.Finish(); + adler1 = def.Checksum; + } + } + #endregion + + #region Inflate tests + [Test] + public void Inflate_Init() + { + using (Inflater inf = new Inflater()) + { + } + } + + private void DDataAvail(byte[] data, int startIndex, int count) + { + for (int i = 0; i < count; ++i) + uncompressedData.Add(data[i+startIndex]); + } + + [Test] + public void Inflate_Expand() + { + uncompressedData.Clear(); + + using (Inflater inf = new Inflater()) + { + inf.DataAvailable += new DataAvailableHandler(DDataAvail); + inf.Add((byte[])compressedData.ToArray(typeof(byte))); + inf.Finish(); + adler2 = inf.Checksum; + } + Assert.AreEqual( adler1, adler2 ); + } + #endregion + } + + [TestFixture] + public class GZipStreamTests + { + #region GZipStream test + [Test] + public void GZipStream_WriteRead() + { + using (GZipStream gzOut = new GZipStream("gzstream.gz", CompressLevel.Best)) + { + BinaryWriter writer = new BinaryWriter(gzOut); + writer.Write("hi there"); + writer.Write(Math.PI); + writer.Write(42); + } + + using (GZipStream gzIn = new GZipStream("gzstream.gz")) + { + BinaryReader reader = new BinaryReader(gzIn); + string s = reader.ReadString(); + Assert.AreEqual("hi there",s); + double d = reader.ReadDouble(); + Assert.AreEqual(Math.PI, d); + int i = reader.ReadInt32(); + Assert.AreEqual(42,i); + } + + } + #endregion + } +} + +#endif diff --git a/libs/zlib/contrib/dotzlib/LICENSE_1_0.txt b/libs/zlib/contrib/dotzlib/LICENSE_1_0.txt new file mode 100644 index 000000000..127a5bc39 --- /dev/null +++ b/libs/zlib/contrib/dotzlib/LICENSE_1_0.txt @@ -0,0 +1,23 @@ +Boost Software License - Version 1.0 - August 17th, 2003 + +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by +this license (the "Software") to use, reproduce, display, distribute, +execute, and transmit the Software, and to prepare derivative works of the +Software, and to permit third-parties to whom the Software is furnished to +do so, all subject to the following: + +The copyright notices in the Software and this entire statement, including +the above license grant, this restriction and the following disclaimer, +must be included in all copies of the Software, in whole or in part, and +all derivative works of the Software, unless such copies or derivative +works are solely in the form of machine-executable object code generated by +a source language processor. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/libs/zlib/contrib/dotzlib/readme.txt b/libs/zlib/contrib/dotzlib/readme.txt new file mode 100644 index 000000000..4d8c2dd93 --- /dev/null +++ b/libs/zlib/contrib/dotzlib/readme.txt @@ -0,0 +1,58 @@ +This directory contains a .Net wrapper class library for the ZLib1.dll + +The wrapper includes support for inflating/deflating memory buffers, +.Net streaming wrappers for the gz streams part of zlib, and wrappers +for the checksum parts of zlib. See DotZLib/UnitTests.cs for examples. + +Directory structure: +-------------------- + +LICENSE_1_0.txt - License file. +readme.txt - This file. +DotZLib.chm - Class library documentation +DotZLib.build - NAnt build file +DotZLib.sln - Microsoft Visual Studio 2003 solution file + +DotZLib\*.cs - Source files for the class library + +Unit tests: +----------- +The file DotZLib/UnitTests.cs contains unit tests for use with NUnit 2.1 or higher. +To include unit tests in the build, define nunit before building. + + +Build instructions: +------------------- + +1. Using Visual Studio.Net 2003: + Open DotZLib.sln in VS.Net and build from there. Output file (DotZLib.dll) + will be found ./DotZLib/bin/release or ./DotZLib/bin/debug, depending on + you are building the release or debug version of the library. Check + DotZLib/UnitTests.cs for instructions on how to include unit tests in the + build. + +2. Using NAnt: + Open a command prompt with access to the build environment and run nant + in the same directory as the DotZLib.build file. + You can define 2 properties on the nant command-line to control the build: + debug={true|false} to toggle between release/debug builds (default=true). + nunit={true|false} to include or esclude unit tests (default=true). + Also the target clean will remove binaries. + Output file (DotZLib.dll) will be found in either ./DotZLib/bin/release + or ./DotZLib/bin/debug, depending on whether you are building the release + or debug version of the library. + + Examples: + nant -D:debug=false -D:nunit=false + will build a release mode version of the library without unit tests. + nant + will build a debug version of the library with unit tests + nant clean + will remove all previously built files. + + +--------------------------------- +Copyright (c) Henrik Ravn 2004 + +Use, modification and distribution are subject to the Boost Software License, Version 1.0. +(See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/libs/zlib/contrib/gcc_gvmat64/gvmat64.S b/libs/zlib/contrib/gcc_gvmat64/gvmat64.S new file mode 100644 index 000000000..23309fa28 --- /dev/null +++ b/libs/zlib/contrib/gcc_gvmat64/gvmat64.S @@ -0,0 +1,574 @@ +/* +;uInt longest_match_x64( +; deflate_state *s, +; IPos cur_match); // current match + +; gvmat64.S -- Asm portion of the optimized longest_match for 32 bits x86_64 +; (AMD64 on Athlon 64, Opteron, Phenom +; and Intel EM64T on Pentium 4 with EM64T, Pentium D, Core 2 Duo, Core I5/I7) +; this file is translation from gvmat64.asm to GCC 4.x (for Linux, Mac XCode) +; Copyright (C) 1995-2010 Jean-loup Gailly, Brian Raiter and Gilles Vollant. +; +; File written by Gilles Vollant, by converting to assembly the longest_match +; from Jean-loup Gailly in deflate.c of zLib and infoZip zip. +; and by taking inspiration on asm686 with masm, optimised assembly code +; from Brian Raiter, written 1998 +; +; This software is provided 'as-is', without any express or implied +; warranty. In no event will the authors be held liable for any damages +; arising from the use of this software. +; +; Permission is granted to anyone to use this software for any purpose, +; including commercial applications, and to alter it and redistribute it +; freely, subject to the following restrictions: +; +; 1. The origin of this software must not be misrepresented; you must not +; claim that you wrote the original software. If you use this software +; in a product, an acknowledgment in the product documentation would be +; appreciated but is not required. +; 2. Altered source versions must be plainly marked as such, and must not be +; misrepresented as being the original software +; 3. This notice may not be removed or altered from any source distribution. +; +; http://www.zlib.net +; http://www.winimage.com/zLibDll +; http://www.muppetlabs.com/~breadbox/software/assembly.html +; +; to compile this file for zLib, I use option: +; gcc -c -arch x86_64 gvmat64.S + + +;uInt longest_match(s, cur_match) +; deflate_state *s; +; IPos cur_match; // current match / +; +; with XCode for Mac, I had strange error with some jump on intel syntax +; this is why BEFORE_JMP and AFTER_JMP are used + */ + + +#define BEFORE_JMP .att_syntax +#define AFTER_JMP .intel_syntax noprefix + +#ifndef NO_UNDERLINE +# define match_init _match_init +# define longest_match _longest_match +#endif + +.intel_syntax noprefix + +.globl match_init, longest_match +.text +longest_match: + + + +#define LocalVarsSize 96 +/* +; register used : rax,rbx,rcx,rdx,rsi,rdi,r8,r9,r10,r11,r12 +; free register : r14,r15 +; register can be saved : rsp +*/ + +#define chainlenwmask (rsp + 8 - LocalVarsSize) +#define nicematch (rsp + 16 - LocalVarsSize) + +#define save_rdi (rsp + 24 - LocalVarsSize) +#define save_rsi (rsp + 32 - LocalVarsSize) +#define save_rbx (rsp + 40 - LocalVarsSize) +#define save_rbp (rsp + 48 - LocalVarsSize) +#define save_r12 (rsp + 56 - LocalVarsSize) +#define save_r13 (rsp + 64 - LocalVarsSize) +#define save_r14 (rsp + 72 - LocalVarsSize) +#define save_r15 (rsp + 80 - LocalVarsSize) + + +/* +; all the +4 offsets are due to the addition of pending_buf_size (in zlib +; in the deflate_state structure since the asm code was first written +; (if you compile with zlib 1.0.4 or older, remove the +4). +; Note : these value are good with a 8 bytes boundary pack structure +*/ + +#define MAX_MATCH 258 +#define MIN_MATCH 3 +#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1) + +/* +;;; Offsets for fields in the deflate_state structure. These numbers +;;; are calculated from the definition of deflate_state, with the +;;; assumption that the compiler will dword-align the fields. (Thus, +;;; changing the definition of deflate_state could easily cause this +;;; program to crash horribly, without so much as a warning at +;;; compile time. Sigh.) + +; all the +zlib1222add offsets are due to the addition of fields +; in zlib in the deflate_state structure since the asm code was first written +; (if you compile with zlib 1.0.4 or older, use "zlib1222add equ (-4)"). +; (if you compile with zlib between 1.0.5 and 1.2.2.1, use "zlib1222add equ 0"). +; if you compile with zlib 1.2.2.2 or later , use "zlib1222add equ 8"). +*/ + + + +/* you can check the structure offset by running + +#include +#include +#include "deflate.h" + +void print_depl() +{ +deflate_state ds; +deflate_state *s=&ds; +printf("size pointer=%u\n",(int)sizeof(void*)); + +printf("#define dsWSize %u\n",(int)(((char*)&(s->w_size))-((char*)s))); +printf("#define dsWMask %u\n",(int)(((char*)&(s->w_mask))-((char*)s))); +printf("#define dsWindow %u\n",(int)(((char*)&(s->window))-((char*)s))); +printf("#define dsPrev %u\n",(int)(((char*)&(s->prev))-((char*)s))); +printf("#define dsMatchLen %u\n",(int)(((char*)&(s->match_length))-((char*)s))); +printf("#define dsPrevMatch %u\n",(int)(((char*)&(s->prev_match))-((char*)s))); +printf("#define dsStrStart %u\n",(int)(((char*)&(s->strstart))-((char*)s))); +printf("#define dsMatchStart %u\n",(int)(((char*)&(s->match_start))-((char*)s))); +printf("#define dsLookahead %u\n",(int)(((char*)&(s->lookahead))-((char*)s))); +printf("#define dsPrevLen %u\n",(int)(((char*)&(s->prev_length))-((char*)s))); +printf("#define dsMaxChainLen %u\n",(int)(((char*)&(s->max_chain_length))-((char*)s))); +printf("#define dsGoodMatch %u\n",(int)(((char*)&(s->good_match))-((char*)s))); +printf("#define dsNiceMatch %u\n",(int)(((char*)&(s->nice_match))-((char*)s))); +} +*/ + +#define dsWSize 68 +#define dsWMask 76 +#define dsWindow 80 +#define dsPrev 96 +#define dsMatchLen 144 +#define dsPrevMatch 148 +#define dsStrStart 156 +#define dsMatchStart 160 +#define dsLookahead 164 +#define dsPrevLen 168 +#define dsMaxChainLen 172 +#define dsGoodMatch 188 +#define dsNiceMatch 192 + +#define window_size [ rcx + dsWSize] +#define WMask [ rcx + dsWMask] +#define window_ad [ rcx + dsWindow] +#define prev_ad [ rcx + dsPrev] +#define strstart [ rcx + dsStrStart] +#define match_start [ rcx + dsMatchStart] +#define Lookahead [ rcx + dsLookahead] //; 0ffffffffh on infozip +#define prev_length [ rcx + dsPrevLen] +#define max_chain_length [ rcx + dsMaxChainLen] +#define good_match [ rcx + dsGoodMatch] +#define nice_match [ rcx + dsNiceMatch] + +/* +; windows: +; parameter 1 in rcx(deflate state s), param 2 in rdx (cur match) + +; see http://weblogs.asp.net/oldnewthing/archive/2004/01/14/58579.aspx and +; http://msdn.microsoft.com/library/en-us/kmarch/hh/kmarch/64bitAMD_8e951dd2-ee77-4728-8702-55ce4b5dd24a.xml.asp +; +; All registers must be preserved across the call, except for +; rax, rcx, rdx, r8, r9, r10, and r11, which are scratch. + +; +; gcc on macosx-linux: +; see http://www.x86-64.org/documentation/abi-0.99.pdf +; param 1 in rdi, param 2 in rsi +; rbx, rsp, rbp, r12 to r15 must be preserved + +;;; Save registers that the compiler may be using, and adjust esp to +;;; make room for our stack frame. + + +;;; Retrieve the function arguments. r8d will hold cur_match +;;; throughout the entire function. edx will hold the pointer to the +;;; deflate_state structure during the function's setup (before +;;; entering the main loop. + +; ms: parameter 1 in rcx (deflate_state* s), param 2 in edx -> r8 (cur match) +; mac: param 1 in rdi, param 2 rsi +; this clear high 32 bits of r8, which can be garbage in both r8 and rdx +*/ + mov [save_rbx],rbx + mov [save_rbp],rbp + + + mov rcx,rdi + + mov r8d,esi + + + mov [save_r12],r12 + mov [save_r13],r13 + mov [save_r14],r14 + mov [save_r15],r15 + + +//;;; uInt wmask = s->w_mask; +//;;; unsigned chain_length = s->max_chain_length; +//;;; if (s->prev_length >= s->good_match) { +//;;; chain_length >>= 2; +//;;; } + + + mov edi, prev_length + mov esi, good_match + mov eax, WMask + mov ebx, max_chain_length + cmp edi, esi + jl LastMatchGood + shr ebx, 2 +LastMatchGood: + +//;;; chainlen is decremented once beforehand so that the function can +//;;; use the sign flag instead of the zero flag for the exit test. +//;;; It is then shifted into the high word, to make room for the wmask +//;;; value, which it will always accompany. + + dec ebx + shl ebx, 16 + or ebx, eax + +//;;; on zlib only +//;;; if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead; + + + + mov eax, nice_match + mov [chainlenwmask], ebx + mov r10d, Lookahead + cmp r10d, eax + cmovnl r10d, eax + mov [nicematch],r10d + + + +//;;; register Bytef *scan = s->window + s->strstart; + mov r10, window_ad + mov ebp, strstart + lea r13, [r10 + rbp] + +//;;; Determine how many bytes the scan ptr is off from being +//;;; dword-aligned. + + mov r9,r13 + neg r13 + and r13,3 + +//;;; IPos limit = s->strstart > (IPos)MAX_DIST(s) ? +//;;; s->strstart - (IPos)MAX_DIST(s) : NIL; + + + mov eax, window_size + sub eax, MIN_LOOKAHEAD + + + xor edi,edi + sub ebp, eax + + mov r11d, prev_length + + cmovng ebp,edi + +//;;; int best_len = s->prev_length; + + +//;;; Store the sum of s->window + best_len in esi locally, and in esi. + + lea rsi,[r10+r11] + +//;;; register ush scan_start = *(ushf*)scan; +//;;; register ush scan_end = *(ushf*)(scan+best_len-1); +//;;; Posf *prev = s->prev; + + movzx r12d,word ptr [r9] + movzx ebx, word ptr [r9 + r11 - 1] + + mov rdi, prev_ad + +//;;; Jump into the main loop. + + mov edx, [chainlenwmask] + + cmp bx,word ptr [rsi + r8 - 1] + jz LookupLoopIsZero + + + +LookupLoop1: + and r8d, edx + + movzx r8d, word ptr [rdi + r8*2] + cmp r8d, ebp + jbe LeaveNow + + + + sub edx, 0x00010000 + BEFORE_JMP + js LeaveNow + AFTER_JMP + +LoopEntry1: + cmp bx,word ptr [rsi + r8 - 1] + BEFORE_JMP + jz LookupLoopIsZero + AFTER_JMP + +LookupLoop2: + and r8d, edx + + movzx r8d, word ptr [rdi + r8*2] + cmp r8d, ebp + BEFORE_JMP + jbe LeaveNow + AFTER_JMP + sub edx, 0x00010000 + BEFORE_JMP + js LeaveNow + AFTER_JMP + +LoopEntry2: + cmp bx,word ptr [rsi + r8 - 1] + BEFORE_JMP + jz LookupLoopIsZero + AFTER_JMP + +LookupLoop4: + and r8d, edx + + movzx r8d, word ptr [rdi + r8*2] + cmp r8d, ebp + BEFORE_JMP + jbe LeaveNow + AFTER_JMP + sub edx, 0x00010000 + BEFORE_JMP + js LeaveNow + AFTER_JMP + +LoopEntry4: + + cmp bx,word ptr [rsi + r8 - 1] + BEFORE_JMP + jnz LookupLoop1 + jmp LookupLoopIsZero + AFTER_JMP +/* +;;; do { +;;; match = s->window + cur_match; +;;; if (*(ushf*)(match+best_len-1) != scan_end || +;;; *(ushf*)match != scan_start) continue; +;;; [...] +;;; } while ((cur_match = prev[cur_match & wmask]) > limit +;;; && --chain_length != 0); +;;; +;;; Here is the inner loop of the function. The function will spend the +;;; majority of its time in this loop, and majority of that time will +;;; be spent in the first ten instructions. +;;; +;;; Within this loop: +;;; ebx = scanend +;;; r8d = curmatch +;;; edx = chainlenwmask - i.e., ((chainlen << 16) | wmask) +;;; esi = windowbestlen - i.e., (window + bestlen) +;;; edi = prev +;;; ebp = limit +*/ +.balign 16 +LookupLoop: + and r8d, edx + + movzx r8d, word ptr [rdi + r8*2] + cmp r8d, ebp + BEFORE_JMP + jbe LeaveNow + AFTER_JMP + sub edx, 0x00010000 + BEFORE_JMP + js LeaveNow + AFTER_JMP + +LoopEntry: + + cmp bx,word ptr [rsi + r8 - 1] + BEFORE_JMP + jnz LookupLoop1 + AFTER_JMP +LookupLoopIsZero: + cmp r12w, word ptr [r10 + r8] + BEFORE_JMP + jnz LookupLoop1 + AFTER_JMP + + +//;;; Store the current value of chainlen. + mov [chainlenwmask], edx +/* +;;; Point edi to the string under scrutiny, and esi to the string we +;;; are hoping to match it up with. In actuality, esi and edi are +;;; both pointed (MAX_MATCH_8 - scanalign) bytes ahead, and edx is +;;; initialized to -(MAX_MATCH_8 - scanalign). +*/ + lea rsi,[r8+r10] + mov rdx, 0xfffffffffffffef8 //; -(MAX_MATCH_8) + lea rsi, [rsi + r13 + 0x0108] //;MAX_MATCH_8] + lea rdi, [r9 + r13 + 0x0108] //;MAX_MATCH_8] + + prefetcht1 [rsi+rdx] + prefetcht1 [rdi+rdx] + +/* +;;; Test the strings for equality, 8 bytes at a time. At the end, +;;; adjust rdx so that it is offset to the exact byte that mismatched. +;;; +;;; We already know at this point that the first three bytes of the +;;; strings match each other, and they can be safely passed over before +;;; starting the compare loop. So what this code does is skip over 0-3 +;;; bytes, as much as necessary in order to dword-align the edi +;;; pointer. (rsi will still be misaligned three times out of four.) +;;; +;;; It should be confessed that this loop usually does not represent +;;; much of the total running time. Replacing it with a more +;;; straightforward "rep cmpsb" would not drastically degrade +;;; performance. +*/ + +LoopCmps: + mov rax, [rsi + rdx] + xor rax, [rdi + rdx] + jnz LeaveLoopCmps + + mov rax, [rsi + rdx + 8] + xor rax, [rdi + rdx + 8] + jnz LeaveLoopCmps8 + + + mov rax, [rsi + rdx + 8+8] + xor rax, [rdi + rdx + 8+8] + jnz LeaveLoopCmps16 + + add rdx,8+8+8 + + BEFORE_JMP + jnz LoopCmps + jmp LenMaximum + AFTER_JMP + +LeaveLoopCmps16: add rdx,8 +LeaveLoopCmps8: add rdx,8 +LeaveLoopCmps: + + test eax, 0x0000FFFF + jnz LenLower + + test eax,0xffffffff + + jnz LenLower32 + + add rdx,4 + shr rax,32 + or ax,ax + BEFORE_JMP + jnz LenLower + AFTER_JMP + +LenLower32: + shr eax,16 + add rdx,2 + +LenLower: + sub al, 1 + adc rdx, 0 +//;;; Calculate the length of the match. If it is longer than MAX_MATCH, +//;;; then automatically accept it as the best possible match and leave. + + lea rax, [rdi + rdx] + sub rax, r9 + cmp eax, MAX_MATCH + BEFORE_JMP + jge LenMaximum + AFTER_JMP +/* +;;; If the length of the match is not longer than the best match we +;;; have so far, then forget it and return to the lookup loop. +;/////////////////////////////////// +*/ + cmp eax, r11d + jg LongerMatch + + lea rsi,[r10+r11] + + mov rdi, prev_ad + mov edx, [chainlenwmask] + BEFORE_JMP + jmp LookupLoop + AFTER_JMP +/* +;;; s->match_start = cur_match; +;;; best_len = len; +;;; if (len >= nice_match) break; +;;; scan_end = *(ushf*)(scan+best_len-1); +*/ +LongerMatch: + mov r11d, eax + mov match_start, r8d + cmp eax, [nicematch] + BEFORE_JMP + jge LeaveNow + AFTER_JMP + + lea rsi,[r10+rax] + + movzx ebx, word ptr [r9 + rax - 1] + mov rdi, prev_ad + mov edx, [chainlenwmask] + BEFORE_JMP + jmp LookupLoop + AFTER_JMP + +//;;; Accept the current string, with the maximum possible length. + +LenMaximum: + mov r11d,MAX_MATCH + mov match_start, r8d + +//;;; if ((uInt)best_len <= s->lookahead) return (uInt)best_len; +//;;; return s->lookahead; + +LeaveNow: + mov eax, Lookahead + cmp r11d, eax + cmovng eax, r11d + + + +//;;; Restore the stack and return from whence we came. + + +// mov rsi,[save_rsi] +// mov rdi,[save_rdi] + mov rbx,[save_rbx] + mov rbp,[save_rbp] + mov r12,[save_r12] + mov r13,[save_r13] + mov r14,[save_r14] + mov r15,[save_r15] + + + ret 0 +//; please don't remove this string ! +//; Your can freely use gvmat64 in any free or commercial app +//; but it is far better don't remove the string in the binary! + // db 0dh,0ah,"asm686 with masm, optimised assembly code from Brian Raiter, written 1998, converted to amd 64 by Gilles Vollant 2005",0dh,0ah,0 + + +match_init: + ret 0 + + diff --git a/libs/zlib/contrib/infback9/README b/libs/zlib/contrib/infback9/README new file mode 100644 index 000000000..e75ed1329 --- /dev/null +++ b/libs/zlib/contrib/infback9/README @@ -0,0 +1 @@ +See infback9.h for what this is and how to use it. diff --git a/libs/zlib/contrib/infback9/infback9.c b/libs/zlib/contrib/infback9/infback9.c new file mode 100644 index 000000000..7bbe90ced --- /dev/null +++ b/libs/zlib/contrib/infback9/infback9.c @@ -0,0 +1,617 @@ +/* infback9.c -- inflate deflate64 data using a call-back interface + * Copyright (C) 1995-2008 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +#include "zutil.h" +#include "infback9.h" +#include "inftree9.h" +#include "inflate9.h" + +#define WSIZE 65536UL + +/* + strm provides memory allocation functions in zalloc and zfree, or + Z_NULL to use the library memory allocation functions. + + window is a user-supplied window and output buffer that is 64K bytes. + */ +int ZEXPORT inflateBack9Init_(strm, window, version, stream_size) +z_stream FAR *strm; +unsigned char FAR *window; +const char *version; +int stream_size; +{ + struct inflate_state FAR *state; + + if (version == Z_NULL || version[0] != ZLIB_VERSION[0] || + stream_size != (int)(sizeof(z_stream))) + return Z_VERSION_ERROR; + if (strm == Z_NULL || window == Z_NULL) + return Z_STREAM_ERROR; + strm->msg = Z_NULL; /* in case we return an error */ + if (strm->zalloc == (alloc_func)0) { + strm->zalloc = zcalloc; + strm->opaque = (voidpf)0; + } + if (strm->zfree == (free_func)0) strm->zfree = zcfree; + state = (struct inflate_state FAR *)ZALLOC(strm, 1, + sizeof(struct inflate_state)); + if (state == Z_NULL) return Z_MEM_ERROR; + Tracev((stderr, "inflate: allocated\n")); + strm->state = (voidpf)state; + state->window = window; + return Z_OK; +} + +/* + Build and output length and distance decoding tables for fixed code + decoding. + */ +#ifdef MAKEFIXED +#include + +void makefixed9(void) +{ + unsigned sym, bits, low, size; + code *next, *lenfix, *distfix; + struct inflate_state state; + code fixed[544]; + + /* literal/length table */ + sym = 0; + while (sym < 144) state.lens[sym++] = 8; + while (sym < 256) state.lens[sym++] = 9; + while (sym < 280) state.lens[sym++] = 7; + while (sym < 288) state.lens[sym++] = 8; + next = fixed; + lenfix = next; + bits = 9; + inflate_table9(LENS, state.lens, 288, &(next), &(bits), state.work); + + /* distance table */ + sym = 0; + while (sym < 32) state.lens[sym++] = 5; + distfix = next; + bits = 5; + inflate_table9(DISTS, state.lens, 32, &(next), &(bits), state.work); + + /* write tables */ + puts(" /* inffix9.h -- table for decoding deflate64 fixed codes"); + puts(" * Generated automatically by makefixed9()."); + puts(" */"); + puts(""); + puts(" /* WARNING: this file should *not* be used by applications."); + puts(" It is part of the implementation of this library and is"); + puts(" subject to change. Applications should only use zlib.h."); + puts(" */"); + puts(""); + size = 1U << 9; + printf(" static const code lenfix[%u] = {", size); + low = 0; + for (;;) { + if ((low % 6) == 0) printf("\n "); + printf("{%u,%u,%d}", lenfix[low].op, lenfix[low].bits, + lenfix[low].val); + if (++low == size) break; + putchar(','); + } + puts("\n };"); + size = 1U << 5; + printf("\n static const code distfix[%u] = {", size); + low = 0; + for (;;) { + if ((low % 5) == 0) printf("\n "); + printf("{%u,%u,%d}", distfix[low].op, distfix[low].bits, + distfix[low].val); + if (++low == size) break; + putchar(','); + } + puts("\n };"); +} +#endif /* MAKEFIXED */ + +/* Macros for inflateBack(): */ + +/* Clear the input bit accumulator */ +#define INITBITS() \ + do { \ + hold = 0; \ + bits = 0; \ + } while (0) + +/* Assure that some input is available. If input is requested, but denied, + then return a Z_BUF_ERROR from inflateBack(). */ +#define PULL() \ + do { \ + if (have == 0) { \ + have = in(in_desc, &next); \ + if (have == 0) { \ + next = Z_NULL; \ + ret = Z_BUF_ERROR; \ + goto inf_leave; \ + } \ + } \ + } while (0) + +/* Get a byte of input into the bit accumulator, or return from inflateBack() + with an error if there is no input available. */ +#define PULLBYTE() \ + do { \ + PULL(); \ + have--; \ + hold += (unsigned long)(*next++) << bits; \ + bits += 8; \ + } while (0) + +/* Assure that there are at least n bits in the bit accumulator. If there is + not enough available input to do that, then return from inflateBack() with + an error. */ +#define NEEDBITS(n) \ + do { \ + while (bits < (unsigned)(n)) \ + PULLBYTE(); \ + } while (0) + +/* Return the low n bits of the bit accumulator (n <= 16) */ +#define BITS(n) \ + ((unsigned)hold & ((1U << (n)) - 1)) + +/* Remove n bits from the bit accumulator */ +#define DROPBITS(n) \ + do { \ + hold >>= (n); \ + bits -= (unsigned)(n); \ + } while (0) + +/* Remove zero to seven bits as needed to go to a byte boundary */ +#define BYTEBITS() \ + do { \ + hold >>= bits & 7; \ + bits -= bits & 7; \ + } while (0) + +/* Assure that some output space is available, by writing out the window + if it's full. If the write fails, return from inflateBack() with a + Z_BUF_ERROR. */ +#define ROOM() \ + do { \ + if (left == 0) { \ + put = window; \ + left = WSIZE; \ + wrap = 1; \ + if (out(out_desc, put, (unsigned)left)) { \ + ret = Z_BUF_ERROR; \ + goto inf_leave; \ + } \ + } \ + } while (0) + +/* + strm provides the memory allocation functions and window buffer on input, + and provides information on the unused input on return. For Z_DATA_ERROR + returns, strm will also provide an error message. + + in() and out() are the call-back input and output functions. When + inflateBack() needs more input, it calls in(). When inflateBack() has + filled the window with output, or when it completes with data in the + window, it calls out() to write out the data. The application must not + change the provided input until in() is called again or inflateBack() + returns. The application must not change the window/output buffer until + inflateBack() returns. + + in() and out() are called with a descriptor parameter provided in the + inflateBack() call. This parameter can be a structure that provides the + information required to do the read or write, as well as accumulated + information on the input and output such as totals and check values. + + in() should return zero on failure. out() should return non-zero on + failure. If either in() or out() fails, than inflateBack() returns a + Z_BUF_ERROR. strm->next_in can be checked for Z_NULL to see whether it + was in() or out() that caused in the error. Otherwise, inflateBack() + returns Z_STREAM_END on success, Z_DATA_ERROR for an deflate format + error, or Z_MEM_ERROR if it could not allocate memory for the state. + inflateBack() can also return Z_STREAM_ERROR if the input parameters + are not correct, i.e. strm is Z_NULL or the state was not initialized. + */ +int ZEXPORT inflateBack9(strm, in, in_desc, out, out_desc) +z_stream FAR *strm; +in_func in; +void FAR *in_desc; +out_func out; +void FAR *out_desc; +{ + struct inflate_state FAR *state; + unsigned char FAR *next; /* next input */ + unsigned char FAR *put; /* next output */ + unsigned have; /* available input */ + unsigned long left; /* available output */ + inflate_mode mode; /* current inflate mode */ + int lastblock; /* true if processing last block */ + int wrap; /* true if the window has wrapped */ + unsigned long write; /* window write index */ + unsigned char FAR *window; /* allocated sliding window, if needed */ + unsigned long hold; /* bit buffer */ + unsigned bits; /* bits in bit buffer */ + unsigned extra; /* extra bits needed */ + unsigned long length; /* literal or length of data to copy */ + unsigned long offset; /* distance back to copy string from */ + unsigned long copy; /* number of stored or match bytes to copy */ + unsigned char FAR *from; /* where to copy match bytes from */ + code const FAR *lencode; /* starting table for length/literal codes */ + code const FAR *distcode; /* starting table for distance codes */ + unsigned lenbits; /* index bits for lencode */ + unsigned distbits; /* index bits for distcode */ + code here; /* current decoding table entry */ + code last; /* parent table entry */ + unsigned len; /* length to copy for repeats, bits to drop */ + int ret; /* return code */ + static const unsigned short order[19] = /* permutation of code lengths */ + {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; +#include "inffix9.h" + + /* Check that the strm exists and that the state was initialized */ + if (strm == Z_NULL || strm->state == Z_NULL) + return Z_STREAM_ERROR; + state = (struct inflate_state FAR *)strm->state; + + /* Reset the state */ + strm->msg = Z_NULL; + mode = TYPE; + lastblock = 0; + write = 0; + wrap = 0; + window = state->window; + next = strm->next_in; + have = next != Z_NULL ? strm->avail_in : 0; + hold = 0; + bits = 0; + put = window; + left = WSIZE; + lencode = Z_NULL; + distcode = Z_NULL; + + /* Inflate until end of block marked as last */ + for (;;) + switch (mode) { + case TYPE: + /* determine and dispatch block type */ + if (lastblock) { + BYTEBITS(); + mode = DONE; + break; + } + NEEDBITS(3); + lastblock = BITS(1); + DROPBITS(1); + switch (BITS(2)) { + case 0: /* stored block */ + Tracev((stderr, "inflate: stored block%s\n", + lastblock ? " (last)" : "")); + mode = STORED; + break; + case 1: /* fixed block */ + lencode = lenfix; + lenbits = 9; + distcode = distfix; + distbits = 5; + Tracev((stderr, "inflate: fixed codes block%s\n", + lastblock ? " (last)" : "")); + mode = LEN; /* decode codes */ + break; + case 2: /* dynamic block */ + Tracev((stderr, "inflate: dynamic codes block%s\n", + lastblock ? " (last)" : "")); + mode = TABLE; + break; + case 3: + strm->msg = (char *)"invalid block type"; + mode = BAD; + } + DROPBITS(2); + break; + + case STORED: + /* get and verify stored block length */ + BYTEBITS(); /* go to byte boundary */ + NEEDBITS(32); + if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) { + strm->msg = (char *)"invalid stored block lengths"; + mode = BAD; + break; + } + length = (unsigned)hold & 0xffff; + Tracev((stderr, "inflate: stored length %lu\n", + length)); + INITBITS(); + + /* copy stored block from input to output */ + while (length != 0) { + copy = length; + PULL(); + ROOM(); + if (copy > have) copy = have; + if (copy > left) copy = left; + zmemcpy(put, next, copy); + have -= copy; + next += copy; + left -= copy; + put += copy; + length -= copy; + } + Tracev((stderr, "inflate: stored end\n")); + mode = TYPE; + break; + + case TABLE: + /* get dynamic table entries descriptor */ + NEEDBITS(14); + state->nlen = BITS(5) + 257; + DROPBITS(5); + state->ndist = BITS(5) + 1; + DROPBITS(5); + state->ncode = BITS(4) + 4; + DROPBITS(4); + if (state->nlen > 286) { + strm->msg = (char *)"too many length symbols"; + mode = BAD; + break; + } + Tracev((stderr, "inflate: table sizes ok\n")); + + /* get code length code lengths (not a typo) */ + state->have = 0; + while (state->have < state->ncode) { + NEEDBITS(3); + state->lens[order[state->have++]] = (unsigned short)BITS(3); + DROPBITS(3); + } + while (state->have < 19) + state->lens[order[state->have++]] = 0; + state->next = state->codes; + lencode = (code const FAR *)(state->next); + lenbits = 7; + ret = inflate_table9(CODES, state->lens, 19, &(state->next), + &(lenbits), state->work); + if (ret) { + strm->msg = (char *)"invalid code lengths set"; + mode = BAD; + break; + } + Tracev((stderr, "inflate: code lengths ok\n")); + + /* get length and distance code code lengths */ + state->have = 0; + while (state->have < state->nlen + state->ndist) { + for (;;) { + here = lencode[BITS(lenbits)]; + if ((unsigned)(here.bits) <= bits) break; + PULLBYTE(); + } + if (here.val < 16) { + NEEDBITS(here.bits); + DROPBITS(here.bits); + state->lens[state->have++] = here.val; + } + else { + if (here.val == 16) { + NEEDBITS(here.bits + 2); + DROPBITS(here.bits); + if (state->have == 0) { + strm->msg = (char *)"invalid bit length repeat"; + mode = BAD; + break; + } + len = (unsigned)(state->lens[state->have - 1]); + copy = 3 + BITS(2); + DROPBITS(2); + } + else if (here.val == 17) { + NEEDBITS(here.bits + 3); + DROPBITS(here.bits); + len = 0; + copy = 3 + BITS(3); + DROPBITS(3); + } + else { + NEEDBITS(here.bits + 7); + DROPBITS(here.bits); + len = 0; + copy = 11 + BITS(7); + DROPBITS(7); + } + if (state->have + copy > state->nlen + state->ndist) { + strm->msg = (char *)"invalid bit length repeat"; + mode = BAD; + break; + } + while (copy--) + state->lens[state->have++] = (unsigned short)len; + } + } + + /* handle error breaks in while */ + if (mode == BAD) break; + + /* check for end-of-block code (better have one) */ + if (state->lens[256] == 0) { + strm->msg = (char *)"invalid code -- missing end-of-block"; + mode = BAD; + break; + } + + /* build code tables -- note: do not change the lenbits or distbits + values here (9 and 6) without reading the comments in inftree9.h + concerning the ENOUGH constants, which depend on those values */ + state->next = state->codes; + lencode = (code const FAR *)(state->next); + lenbits = 9; + ret = inflate_table9(LENS, state->lens, state->nlen, + &(state->next), &(lenbits), state->work); + if (ret) { + strm->msg = (char *)"invalid literal/lengths set"; + mode = BAD; + break; + } + distcode = (code const FAR *)(state->next); + distbits = 6; + ret = inflate_table9(DISTS, state->lens + state->nlen, + state->ndist, &(state->next), &(distbits), + state->work); + if (ret) { + strm->msg = (char *)"invalid distances set"; + mode = BAD; + break; + } + Tracev((stderr, "inflate: codes ok\n")); + mode = LEN; + + case LEN: + /* get a literal, length, or end-of-block code */ + for (;;) { + here = lencode[BITS(lenbits)]; + if ((unsigned)(here.bits) <= bits) break; + PULLBYTE(); + } + if (here.op && (here.op & 0xf0) == 0) { + last = here; + for (;;) { + here = lencode[last.val + + (BITS(last.bits + last.op) >> last.bits)]; + if ((unsigned)(last.bits + here.bits) <= bits) break; + PULLBYTE(); + } + DROPBITS(last.bits); + } + DROPBITS(here.bits); + length = (unsigned)here.val; + + /* process literal */ + if (here.op == 0) { + Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ? + "inflate: literal '%c'\n" : + "inflate: literal 0x%02x\n", here.val)); + ROOM(); + *put++ = (unsigned char)(length); + left--; + mode = LEN; + break; + } + + /* process end of block */ + if (here.op & 32) { + Tracevv((stderr, "inflate: end of block\n")); + mode = TYPE; + break; + } + + /* invalid code */ + if (here.op & 64) { + strm->msg = (char *)"invalid literal/length code"; + mode = BAD; + break; + } + + /* length code -- get extra bits, if any */ + extra = (unsigned)(here.op) & 31; + if (extra != 0) { + NEEDBITS(extra); + length += BITS(extra); + DROPBITS(extra); + } + Tracevv((stderr, "inflate: length %lu\n", length)); + + /* get distance code */ + for (;;) { + here = distcode[BITS(distbits)]; + if ((unsigned)(here.bits) <= bits) break; + PULLBYTE(); + } + if ((here.op & 0xf0) == 0) { + last = here; + for (;;) { + here = distcode[last.val + + (BITS(last.bits + last.op) >> last.bits)]; + if ((unsigned)(last.bits + here.bits) <= bits) break; + PULLBYTE(); + } + DROPBITS(last.bits); + } + DROPBITS(here.bits); + if (here.op & 64) { + strm->msg = (char *)"invalid distance code"; + mode = BAD; + break; + } + offset = (unsigned)here.val; + + /* get distance extra bits, if any */ + extra = (unsigned)(here.op) & 15; + if (extra != 0) { + NEEDBITS(extra); + offset += BITS(extra); + DROPBITS(extra); + } + if (offset > WSIZE - (wrap ? 0: left)) { + strm->msg = (char *)"invalid distance too far back"; + mode = BAD; + break; + } + Tracevv((stderr, "inflate: distance %lu\n", offset)); + + /* copy match from window to output */ + do { + ROOM(); + copy = WSIZE - offset; + if (copy < left) { + from = put + copy; + copy = left - copy; + } + else { + from = put - offset; + copy = left; + } + if (copy > length) copy = length; + length -= copy; + left -= copy; + do { + *put++ = *from++; + } while (--copy); + } while (length != 0); + break; + + case DONE: + /* inflate stream terminated properly -- write leftover output */ + ret = Z_STREAM_END; + if (left < WSIZE) { + if (out(out_desc, window, (unsigned)(WSIZE - left))) + ret = Z_BUF_ERROR; + } + goto inf_leave; + + case BAD: + ret = Z_DATA_ERROR; + goto inf_leave; + + default: /* can't happen, but makes compilers happy */ + ret = Z_STREAM_ERROR; + goto inf_leave; + } + + /* Return unused input */ + inf_leave: + strm->next_in = next; + strm->avail_in = have; + return ret; +} + +int ZEXPORT inflateBack9End(strm) +z_stream FAR *strm; +{ + if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0) + return Z_STREAM_ERROR; + ZFREE(strm, strm->state); + strm->state = Z_NULL; + Tracev((stderr, "inflate: end\n")); + return Z_OK; +} diff --git a/libs/zlib/contrib/infback9/infback9.h b/libs/zlib/contrib/infback9/infback9.h new file mode 100644 index 000000000..1073c0a38 --- /dev/null +++ b/libs/zlib/contrib/infback9/infback9.h @@ -0,0 +1,37 @@ +/* infback9.h -- header for using inflateBack9 functions + * Copyright (C) 2003 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* + * This header file and associated patches provide a decoder for PKWare's + * undocumented deflate64 compression method (method 9). Use with infback9.c, + * inftree9.h, inftree9.c, and inffix9.h. These patches are not supported. + * This should be compiled with zlib, since it uses zutil.h and zutil.o. + * This code has not yet been tested on 16-bit architectures. See the + * comments in zlib.h for inflateBack() usage. These functions are used + * identically, except that there is no windowBits parameter, and a 64K + * window must be provided. Also if int's are 16 bits, then a zero for + * the third parameter of the "out" function actually means 65536UL. + * zlib.h must be included before this header file. + */ + +#ifdef __cplusplus +extern "C" { +#endif + +ZEXTERN int ZEXPORT inflateBack9 OF((z_stream FAR *strm, + in_func in, void FAR *in_desc, + out_func out, void FAR *out_desc)); +ZEXTERN int ZEXPORT inflateBack9End OF((z_stream FAR *strm)); +ZEXTERN int ZEXPORT inflateBack9Init_ OF((z_stream FAR *strm, + unsigned char FAR *window, + const char *version, + int stream_size)); +#define inflateBack9Init(strm, window) \ + inflateBack9Init_((strm), (window), \ + ZLIB_VERSION, sizeof(z_stream)) + +#ifdef __cplusplus +} +#endif diff --git a/libs/zlib/contrib/infback9/inffix9.h b/libs/zlib/contrib/infback9/inffix9.h new file mode 100644 index 000000000..ee5671d2d --- /dev/null +++ b/libs/zlib/contrib/infback9/inffix9.h @@ -0,0 +1,107 @@ + /* inffix9.h -- table for decoding deflate64 fixed codes + * Generated automatically by makefixed9(). + */ + + /* WARNING: this file should *not* be used by applications. + It is part of the implementation of this library and is + subject to change. Applications should only use zlib.h. + */ + + static const code lenfix[512] = { + {96,7,0},{0,8,80},{0,8,16},{132,8,115},{130,7,31},{0,8,112}, + {0,8,48},{0,9,192},{128,7,10},{0,8,96},{0,8,32},{0,9,160}, + {0,8,0},{0,8,128},{0,8,64},{0,9,224},{128,7,6},{0,8,88}, + {0,8,24},{0,9,144},{131,7,59},{0,8,120},{0,8,56},{0,9,208}, + {129,7,17},{0,8,104},{0,8,40},{0,9,176},{0,8,8},{0,8,136}, + {0,8,72},{0,9,240},{128,7,4},{0,8,84},{0,8,20},{133,8,227}, + {131,7,43},{0,8,116},{0,8,52},{0,9,200},{129,7,13},{0,8,100}, + {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232}, + {128,7,8},{0,8,92},{0,8,28},{0,9,152},{132,7,83},{0,8,124}, + {0,8,60},{0,9,216},{130,7,23},{0,8,108},{0,8,44},{0,9,184}, + {0,8,12},{0,8,140},{0,8,76},{0,9,248},{128,7,3},{0,8,82}, + {0,8,18},{133,8,163},{131,7,35},{0,8,114},{0,8,50},{0,9,196}, + {129,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2},{0,8,130}, + {0,8,66},{0,9,228},{128,7,7},{0,8,90},{0,8,26},{0,9,148}, + {132,7,67},{0,8,122},{0,8,58},{0,9,212},{130,7,19},{0,8,106}, + {0,8,42},{0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244}, + {128,7,5},{0,8,86},{0,8,22},{65,8,0},{131,7,51},{0,8,118}, + {0,8,54},{0,9,204},{129,7,15},{0,8,102},{0,8,38},{0,9,172}, + {0,8,6},{0,8,134},{0,8,70},{0,9,236},{128,7,9},{0,8,94}, + {0,8,30},{0,9,156},{132,7,99},{0,8,126},{0,8,62},{0,9,220}, + {130,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142}, + {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{133,8,131}, + {130,7,31},{0,8,113},{0,8,49},{0,9,194},{128,7,10},{0,8,97}, + {0,8,33},{0,9,162},{0,8,1},{0,8,129},{0,8,65},{0,9,226}, + {128,7,6},{0,8,89},{0,8,25},{0,9,146},{131,7,59},{0,8,121}, + {0,8,57},{0,9,210},{129,7,17},{0,8,105},{0,8,41},{0,9,178}, + {0,8,9},{0,8,137},{0,8,73},{0,9,242},{128,7,4},{0,8,85}, + {0,8,21},{144,8,3},{131,7,43},{0,8,117},{0,8,53},{0,9,202}, + {129,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133}, + {0,8,69},{0,9,234},{128,7,8},{0,8,93},{0,8,29},{0,9,154}, + {132,7,83},{0,8,125},{0,8,61},{0,9,218},{130,7,23},{0,8,109}, + {0,8,45},{0,9,186},{0,8,13},{0,8,141},{0,8,77},{0,9,250}, + {128,7,3},{0,8,83},{0,8,19},{133,8,195},{131,7,35},{0,8,115}, + {0,8,51},{0,9,198},{129,7,11},{0,8,99},{0,8,35},{0,9,166}, + {0,8,3},{0,8,131},{0,8,67},{0,9,230},{128,7,7},{0,8,91}, + {0,8,27},{0,9,150},{132,7,67},{0,8,123},{0,8,59},{0,9,214}, + {130,7,19},{0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139}, + {0,8,75},{0,9,246},{128,7,5},{0,8,87},{0,8,23},{77,8,0}, + {131,7,51},{0,8,119},{0,8,55},{0,9,206},{129,7,15},{0,8,103}, + {0,8,39},{0,9,174},{0,8,7},{0,8,135},{0,8,71},{0,9,238}, + {128,7,9},{0,8,95},{0,8,31},{0,9,158},{132,7,99},{0,8,127}, + {0,8,63},{0,9,222},{130,7,27},{0,8,111},{0,8,47},{0,9,190}, + {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80}, + {0,8,16},{132,8,115},{130,7,31},{0,8,112},{0,8,48},{0,9,193}, + {128,7,10},{0,8,96},{0,8,32},{0,9,161},{0,8,0},{0,8,128}, + {0,8,64},{0,9,225},{128,7,6},{0,8,88},{0,8,24},{0,9,145}, + {131,7,59},{0,8,120},{0,8,56},{0,9,209},{129,7,17},{0,8,104}, + {0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72},{0,9,241}, + {128,7,4},{0,8,84},{0,8,20},{133,8,227},{131,7,43},{0,8,116}, + {0,8,52},{0,9,201},{129,7,13},{0,8,100},{0,8,36},{0,9,169}, + {0,8,4},{0,8,132},{0,8,68},{0,9,233},{128,7,8},{0,8,92}, + {0,8,28},{0,9,153},{132,7,83},{0,8,124},{0,8,60},{0,9,217}, + {130,7,23},{0,8,108},{0,8,44},{0,9,185},{0,8,12},{0,8,140}, + {0,8,76},{0,9,249},{128,7,3},{0,8,82},{0,8,18},{133,8,163}, + {131,7,35},{0,8,114},{0,8,50},{0,9,197},{129,7,11},{0,8,98}, + {0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229}, + {128,7,7},{0,8,90},{0,8,26},{0,9,149},{132,7,67},{0,8,122}, + {0,8,58},{0,9,213},{130,7,19},{0,8,106},{0,8,42},{0,9,181}, + {0,8,10},{0,8,138},{0,8,74},{0,9,245},{128,7,5},{0,8,86}, + {0,8,22},{65,8,0},{131,7,51},{0,8,118},{0,8,54},{0,9,205}, + {129,7,15},{0,8,102},{0,8,38},{0,9,173},{0,8,6},{0,8,134}, + {0,8,70},{0,9,237},{128,7,9},{0,8,94},{0,8,30},{0,9,157}, + {132,7,99},{0,8,126},{0,8,62},{0,9,221},{130,7,27},{0,8,110}, + {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253}, + {96,7,0},{0,8,81},{0,8,17},{133,8,131},{130,7,31},{0,8,113}, + {0,8,49},{0,9,195},{128,7,10},{0,8,97},{0,8,33},{0,9,163}, + {0,8,1},{0,8,129},{0,8,65},{0,9,227},{128,7,6},{0,8,89}, + {0,8,25},{0,9,147},{131,7,59},{0,8,121},{0,8,57},{0,9,211}, + {129,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9},{0,8,137}, + {0,8,73},{0,9,243},{128,7,4},{0,8,85},{0,8,21},{144,8,3}, + {131,7,43},{0,8,117},{0,8,53},{0,9,203},{129,7,13},{0,8,101}, + {0,8,37},{0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235}, + {128,7,8},{0,8,93},{0,8,29},{0,9,155},{132,7,83},{0,8,125}, + {0,8,61},{0,9,219},{130,7,23},{0,8,109},{0,8,45},{0,9,187}, + {0,8,13},{0,8,141},{0,8,77},{0,9,251},{128,7,3},{0,8,83}, + {0,8,19},{133,8,195},{131,7,35},{0,8,115},{0,8,51},{0,9,199}, + {129,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131}, + {0,8,67},{0,9,231},{128,7,7},{0,8,91},{0,8,27},{0,9,151}, + {132,7,67},{0,8,123},{0,8,59},{0,9,215},{130,7,19},{0,8,107}, + {0,8,43},{0,9,183},{0,8,11},{0,8,139},{0,8,75},{0,9,247}, + {128,7,5},{0,8,87},{0,8,23},{77,8,0},{131,7,51},{0,8,119}, + {0,8,55},{0,9,207},{129,7,15},{0,8,103},{0,8,39},{0,9,175}, + {0,8,7},{0,8,135},{0,8,71},{0,9,239},{128,7,9},{0,8,95}, + {0,8,31},{0,9,159},{132,7,99},{0,8,127},{0,8,63},{0,9,223}, + {130,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143}, + {0,8,79},{0,9,255} + }; + + static const code distfix[32] = { + {128,5,1},{135,5,257},{131,5,17},{139,5,4097},{129,5,5}, + {137,5,1025},{133,5,65},{141,5,16385},{128,5,3},{136,5,513}, + {132,5,33},{140,5,8193},{130,5,9},{138,5,2049},{134,5,129}, + {142,5,32769},{128,5,2},{135,5,385},{131,5,25},{139,5,6145}, + {129,5,7},{137,5,1537},{133,5,97},{141,5,24577},{128,5,4}, + {136,5,769},{132,5,49},{140,5,12289},{130,5,13},{138,5,3073}, + {134,5,193},{142,5,49153} + }; diff --git a/libs/zlib/contrib/infback9/inflate9.h b/libs/zlib/contrib/infback9/inflate9.h new file mode 100644 index 000000000..ee9a79394 --- /dev/null +++ b/libs/zlib/contrib/infback9/inflate9.h @@ -0,0 +1,47 @@ +/* inflate9.h -- internal inflate state definition + * Copyright (C) 1995-2003 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* WARNING: this file should *not* be used by applications. It is + part of the implementation of the compression library and is + subject to change. Applications should only use zlib.h. + */ + +/* Possible inflate modes between inflate() calls */ +typedef enum { + TYPE, /* i: waiting for type bits, including last-flag bit */ + STORED, /* i: waiting for stored size (length and complement) */ + TABLE, /* i: waiting for dynamic block table lengths */ + LEN, /* i: waiting for length/lit code */ + DONE, /* finished check, done -- remain here until reset */ + BAD /* got a data error -- remain here until reset */ +} inflate_mode; + +/* + State transitions between above modes - + + (most modes can go to the BAD mode -- not shown for clarity) + + Read deflate blocks: + TYPE -> STORED or TABLE or LEN or DONE + STORED -> TYPE + TABLE -> LENLENS -> CODELENS -> LEN + Read deflate codes: + LEN -> LEN or TYPE + */ + +/* state maintained between inflate() calls. Approximately 7K bytes. */ +struct inflate_state { + /* sliding window */ + unsigned char FAR *window; /* allocated sliding window, if needed */ + /* dynamic table building */ + unsigned ncode; /* number of code length code lengths */ + unsigned nlen; /* number of length code lengths */ + unsigned ndist; /* number of distance code lengths */ + unsigned have; /* number of code lengths in lens[] */ + code FAR *next; /* next available space in codes[] */ + unsigned short lens[320]; /* temporary storage for code lengths */ + unsigned short work[288]; /* work area for code table building */ + code codes[ENOUGH]; /* space for code tables */ +}; diff --git a/libs/zlib/contrib/infback9/inftree9.c b/libs/zlib/contrib/infback9/inftree9.c new file mode 100644 index 000000000..306c5f1b1 --- /dev/null +++ b/libs/zlib/contrib/infback9/inftree9.c @@ -0,0 +1,324 @@ +/* inftree9.c -- generate Huffman trees for efficient decoding + * Copyright (C) 1995-2010 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +#include "zutil.h" +#include "inftree9.h" + +#define MAXBITS 15 + +const char inflate9_copyright[] = + " inflate9 1.2.5 Copyright 1995-2010 Mark Adler "; +/* + If you use the zlib library in a product, an acknowledgment is welcome + in the documentation of your product. If for some reason you cannot + include such an acknowledgment, I would appreciate that you keep this + copyright string in the executable of your product. + */ + +/* + Build a set of tables to decode the provided canonical Huffman code. + The code lengths are lens[0..codes-1]. The result starts at *table, + whose indices are 0..2^bits-1. work is a writable array of at least + lens shorts, which is used as a work area. type is the type of code + to be generated, CODES, LENS, or DISTS. On return, zero is success, + -1 is an invalid code, and +1 means that ENOUGH isn't enough. table + on return points to the next available entry's address. bits is the + requested root table index bits, and on return it is the actual root + table index bits. It will differ if the request is greater than the + longest code or if it is less than the shortest code. + */ +int inflate_table9(type, lens, codes, table, bits, work) +codetype type; +unsigned short FAR *lens; +unsigned codes; +code FAR * FAR *table; +unsigned FAR *bits; +unsigned short FAR *work; +{ + unsigned len; /* a code's length in bits */ + unsigned sym; /* index of code symbols */ + unsigned min, max; /* minimum and maximum code lengths */ + unsigned root; /* number of index bits for root table */ + unsigned curr; /* number of index bits for current table */ + unsigned drop; /* code bits to drop for sub-table */ + int left; /* number of prefix codes available */ + unsigned used; /* code entries in table used */ + unsigned huff; /* Huffman code */ + unsigned incr; /* for incrementing code, index */ + unsigned fill; /* index for replicating entries */ + unsigned low; /* low bits for current root entry */ + unsigned mask; /* mask for low root bits */ + code this; /* table entry for duplication */ + code FAR *next; /* next available space in table */ + const unsigned short FAR *base; /* base value table to use */ + const unsigned short FAR *extra; /* extra bits table to use */ + int end; /* use base and extra for symbol > end */ + unsigned short count[MAXBITS+1]; /* number of codes of each length */ + unsigned short offs[MAXBITS+1]; /* offsets in table for each length */ + static const unsigned short lbase[31] = { /* Length codes 257..285 base */ + 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, + 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, + 131, 163, 195, 227, 3, 0, 0}; + static const unsigned short lext[31] = { /* Length codes 257..285 extra */ + 128, 128, 128, 128, 128, 128, 128, 128, 129, 129, 129, 129, + 130, 130, 130, 130, 131, 131, 131, 131, 132, 132, 132, 132, + 133, 133, 133, 133, 144, 73, 195}; + static const unsigned short dbase[32] = { /* Distance codes 0..31 base */ + 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, + 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, + 4097, 6145, 8193, 12289, 16385, 24577, 32769, 49153}; + static const unsigned short dext[32] = { /* Distance codes 0..31 extra */ + 128, 128, 128, 128, 129, 129, 130, 130, 131, 131, 132, 132, + 133, 133, 134, 134, 135, 135, 136, 136, 137, 137, 138, 138, + 139, 139, 140, 140, 141, 141, 142, 142}; + + /* + Process a set of code lengths to create a canonical Huffman code. The + code lengths are lens[0..codes-1]. Each length corresponds to the + symbols 0..codes-1. The Huffman code is generated by first sorting the + symbols by length from short to long, and retaining the symbol order + for codes with equal lengths. Then the code starts with all zero bits + for the first code of the shortest length, and the codes are integer + increments for the same length, and zeros are appended as the length + increases. For the deflate format, these bits are stored backwards + from their more natural integer increment ordering, and so when the + decoding tables are built in the large loop below, the integer codes + are incremented backwards. + + This routine assumes, but does not check, that all of the entries in + lens[] are in the range 0..MAXBITS. The caller must assure this. + 1..MAXBITS is interpreted as that code length. zero means that that + symbol does not occur in this code. + + The codes are sorted by computing a count of codes for each length, + creating from that a table of starting indices for each length in the + sorted table, and then entering the symbols in order in the sorted + table. The sorted table is work[], with that space being provided by + the caller. + + The length counts are used for other purposes as well, i.e. finding + the minimum and maximum length codes, determining if there are any + codes at all, checking for a valid set of lengths, and looking ahead + at length counts to determine sub-table sizes when building the + decoding tables. + */ + + /* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */ + for (len = 0; len <= MAXBITS; len++) + count[len] = 0; + for (sym = 0; sym < codes; sym++) + count[lens[sym]]++; + + /* bound code lengths, force root to be within code lengths */ + root = *bits; + for (max = MAXBITS; max >= 1; max--) + if (count[max] != 0) break; + if (root > max) root = max; + if (max == 0) return -1; /* no codes! */ + for (min = 1; min <= MAXBITS; min++) + if (count[min] != 0) break; + if (root < min) root = min; + + /* check for an over-subscribed or incomplete set of lengths */ + left = 1; + for (len = 1; len <= MAXBITS; len++) { + left <<= 1; + left -= count[len]; + if (left < 0) return -1; /* over-subscribed */ + } + if (left > 0 && (type == CODES || max != 1)) + return -1; /* incomplete set */ + + /* generate offsets into symbol table for each length for sorting */ + offs[1] = 0; + for (len = 1; len < MAXBITS; len++) + offs[len + 1] = offs[len] + count[len]; + + /* sort symbols by length, by symbol order within each length */ + for (sym = 0; sym < codes; sym++) + if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym; + + /* + Create and fill in decoding tables. In this loop, the table being + filled is at next and has curr index bits. The code being used is huff + with length len. That code is converted to an index by dropping drop + bits off of the bottom. For codes where len is less than drop + curr, + those top drop + curr - len bits are incremented through all values to + fill the table with replicated entries. + + root is the number of index bits for the root table. When len exceeds + root, sub-tables are created pointed to by the root entry with an index + of the low root bits of huff. This is saved in low to check for when a + new sub-table should be started. drop is zero when the root table is + being filled, and drop is root when sub-tables are being filled. + + When a new sub-table is needed, it is necessary to look ahead in the + code lengths to determine what size sub-table is needed. The length + counts are used for this, and so count[] is decremented as codes are + entered in the tables. + + used keeps track of how many table entries have been allocated from the + provided *table space. It is checked for LENS and DIST tables against + the constants ENOUGH_LENS and ENOUGH_DISTS to guard against changes in + the initial root table size constants. See the comments in inftree9.h + for more information. + + sym increments through all symbols, and the loop terminates when + all codes of length max, i.e. all codes, have been processed. This + routine permits incomplete codes, so another loop after this one fills + in the rest of the decoding tables with invalid code markers. + */ + + /* set up for code type */ + switch (type) { + case CODES: + base = extra = work; /* dummy value--not used */ + end = 19; + break; + case LENS: + base = lbase; + base -= 257; + extra = lext; + extra -= 257; + end = 256; + break; + default: /* DISTS */ + base = dbase; + extra = dext; + end = -1; + } + + /* initialize state for loop */ + huff = 0; /* starting code */ + sym = 0; /* starting code symbol */ + len = min; /* starting code length */ + next = *table; /* current table to fill in */ + curr = root; /* current table index bits */ + drop = 0; /* current bits to drop from code for index */ + low = (unsigned)(-1); /* trigger new sub-table when len > root */ + used = 1U << root; /* use root table entries */ + mask = used - 1; /* mask for comparing low */ + + /* check available table space */ + if ((type == LENS && used >= ENOUGH_LENS) || + (type == DISTS && used >= ENOUGH_DISTS)) + return 1; + + /* process all codes and make table entries */ + for (;;) { + /* create table entry */ + this.bits = (unsigned char)(len - drop); + if ((int)(work[sym]) < end) { + this.op = (unsigned char)0; + this.val = work[sym]; + } + else if ((int)(work[sym]) > end) { + this.op = (unsigned char)(extra[work[sym]]); + this.val = base[work[sym]]; + } + else { + this.op = (unsigned char)(32 + 64); /* end of block */ + this.val = 0; + } + + /* replicate for those indices with low len bits equal to huff */ + incr = 1U << (len - drop); + fill = 1U << curr; + do { + fill -= incr; + next[(huff >> drop) + fill] = this; + } while (fill != 0); + + /* backwards increment the len-bit code huff */ + incr = 1U << (len - 1); + while (huff & incr) + incr >>= 1; + if (incr != 0) { + huff &= incr - 1; + huff += incr; + } + else + huff = 0; + + /* go to next symbol, update count, len */ + sym++; + if (--(count[len]) == 0) { + if (len == max) break; + len = lens[work[sym]]; + } + + /* create new sub-table if needed */ + if (len > root && (huff & mask) != low) { + /* if first time, transition to sub-tables */ + if (drop == 0) + drop = root; + + /* increment past last table */ + next += 1U << curr; + + /* determine length of next table */ + curr = len - drop; + left = (int)(1 << curr); + while (curr + drop < max) { + left -= count[curr + drop]; + if (left <= 0) break; + curr++; + left <<= 1; + } + + /* check for enough space */ + used += 1U << curr; + if ((type == LENS && used >= ENOUGH_LENS) || + (type == DISTS && used >= ENOUGH_DISTS)) + return 1; + + /* point entry in root table to sub-table */ + low = huff & mask; + (*table)[low].op = (unsigned char)curr; + (*table)[low].bits = (unsigned char)root; + (*table)[low].val = (unsigned short)(next - *table); + } + } + + /* + Fill in rest of table for incomplete codes. This loop is similar to the + loop above in incrementing huff for table indices. It is assumed that + len is equal to curr + drop, so there is no loop needed to increment + through high index bits. When the current sub-table is filled, the loop + drops back to the root table to fill in any remaining entries there. + */ + this.op = (unsigned char)64; /* invalid code marker */ + this.bits = (unsigned char)(len - drop); + this.val = (unsigned short)0; + while (huff != 0) { + /* when done with sub-table, drop back to root table */ + if (drop != 0 && (huff & mask) != low) { + drop = 0; + len = root; + next = *table; + curr = root; + this.bits = (unsigned char)len; + } + + /* put invalid code marker in table */ + next[huff >> drop] = this; + + /* backwards increment the len-bit code huff */ + incr = 1U << (len - 1); + while (huff & incr) + incr >>= 1; + if (incr != 0) { + huff &= incr - 1; + huff += incr; + } + else + huff = 0; + } + + /* set return parameters */ + *table += used; + *bits = root; + return 0; +} diff --git a/libs/zlib/contrib/infback9/inftree9.h b/libs/zlib/contrib/infback9/inftree9.h new file mode 100644 index 000000000..5ab21f0c6 --- /dev/null +++ b/libs/zlib/contrib/infback9/inftree9.h @@ -0,0 +1,61 @@ +/* inftree9.h -- header to use inftree9.c + * Copyright (C) 1995-2008 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* WARNING: this file should *not* be used by applications. It is + part of the implementation of the compression library and is + subject to change. Applications should only use zlib.h. + */ + +/* Structure for decoding tables. Each entry provides either the + information needed to do the operation requested by the code that + indexed that table entry, or it provides a pointer to another + table that indexes more bits of the code. op indicates whether + the entry is a pointer to another table, a literal, a length or + distance, an end-of-block, or an invalid code. For a table + pointer, the low four bits of op is the number of index bits of + that table. For a length or distance, the low four bits of op + is the number of extra bits to get after the code. bits is + the number of bits in this code or part of the code to drop off + of the bit buffer. val is the actual byte to output in the case + of a literal, the base length or distance, or the offset from + the current table to the next table. Each entry is four bytes. */ +typedef struct { + unsigned char op; /* operation, extra bits, table bits */ + unsigned char bits; /* bits in this part of the code */ + unsigned short val; /* offset in table or code value */ +} code; + +/* op values as set by inflate_table(): + 00000000 - literal + 0000tttt - table link, tttt != 0 is the number of table index bits + 100eeeee - length or distance, eeee is the number of extra bits + 01100000 - end of block + 01000000 - invalid code + */ + +/* Maximum size of the dynamic table. The maximum number of code structures is + 1446, which is the sum of 852 for literal/length codes and 594 for distance + codes. These values were found by exhaustive searches using the program + examples/enough.c found in the zlib distribtution. The arguments to that + program are the number of symbols, the initial root table size, and the + maximum bit length of a code. "enough 286 9 15" for literal/length codes + returns returns 852, and "enough 32 6 15" for distance codes returns 594. + The initial root table size (9 or 6) is found in the fifth argument of the + inflate_table() calls in infback9.c. If the root table size is changed, + then these maximum sizes would be need to be recalculated and updated. */ +#define ENOUGH_LENS 852 +#define ENOUGH_DISTS 594 +#define ENOUGH (ENOUGH_LENS+ENOUGH_DISTS) + +/* Type of code to build for inflate_table9() */ +typedef enum { + CODES, + LENS, + DISTS +} codetype; + +extern int inflate_table9 OF((codetype type, unsigned short FAR *lens, + unsigned codes, code FAR * FAR *table, + unsigned FAR *bits, unsigned short FAR *work)); diff --git a/libs/zlib/contrib/inflate86/inffas86.c b/libs/zlib/contrib/inflate86/inffas86.c new file mode 100644 index 000000000..7292f67b7 --- /dev/null +++ b/libs/zlib/contrib/inflate86/inffas86.c @@ -0,0 +1,1157 @@ +/* inffas86.c is a hand tuned assembler version of + * + * inffast.c -- fast decoding + * Copyright (C) 1995-2003 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + * + * Copyright (C) 2003 Chris Anderson + * Please use the copyright conditions above. + * + * Dec-29-2003 -- I added AMD64 inflate asm support. This version is also + * slightly quicker on x86 systems because, instead of using rep movsb to copy + * data, it uses rep movsw, which moves data in 2-byte chunks instead of single + * bytes. I've tested the AMD64 code on a Fedora Core 1 + the x86_64 updates + * from http://fedora.linux.duke.edu/fc1_x86_64 + * which is running on an Athlon 64 3000+ / Gigabyte GA-K8VT800M system with + * 1GB ram. The 64-bit version is about 4% faster than the 32-bit version, + * when decompressing mozilla-source-1.3.tar.gz. + * + * Mar-13-2003 -- Most of this is derived from inffast.S which is derived from + * the gcc -S output of zlib-1.2.0/inffast.c. Zlib-1.2.0 is in beta release at + * the moment. I have successfully compiled and tested this code with gcc2.96, + * gcc3.2, icc5.0, msvc6.0. It is very close to the speed of inffast.S + * compiled with gcc -DNO_MMX, but inffast.S is still faster on the P3 with MMX + * enabled. I will attempt to merge the MMX code into this version. Newer + * versions of this and inffast.S can be found at + * http://www.eetbeetee.com/zlib/ and http://www.charm.net/~christop/zlib/ + */ + +#include "zutil.h" +#include "inftrees.h" +#include "inflate.h" +#include "inffast.h" + +/* Mark Adler's comments from inffast.c: */ + +/* + Decode literal, length, and distance codes and write out the resulting + literal and match bytes until either not enough input or output is + available, an end-of-block is encountered, or a data error is encountered. + When large enough input and output buffers are supplied to inflate(), for + example, a 16K input buffer and a 64K output buffer, more than 95% of the + inflate execution time is spent in this routine. + + Entry assumptions: + + state->mode == LEN + strm->avail_in >= 6 + strm->avail_out >= 258 + start >= strm->avail_out + state->bits < 8 + + On return, state->mode is one of: + + LEN -- ran out of enough output space or enough available input + TYPE -- reached end of block code, inflate() to interpret next block + BAD -- error in block data + + Notes: + + - The maximum input bits used by a length/distance pair is 15 bits for the + length code, 5 bits for the length extra, 15 bits for the distance code, + and 13 bits for the distance extra. This totals 48 bits, or six bytes. + Therefore if strm->avail_in >= 6, then there is enough input to avoid + checking for available input while decoding. + + - The maximum bytes that a single length/distance pair can output is 258 + bytes, which is the maximum length that can be coded. inflate_fast() + requires strm->avail_out >= 258 for each loop to avoid checking for + output space. + */ +void inflate_fast(strm, start) +z_streamp strm; +unsigned start; /* inflate()'s starting value for strm->avail_out */ +{ + struct inflate_state FAR *state; + struct inffast_ar { +/* 64 32 x86 x86_64 */ +/* ar offset register */ +/* 0 0 */ void *esp; /* esp save */ +/* 8 4 */ void *ebp; /* ebp save */ +/* 16 8 */ unsigned char FAR *in; /* esi rsi local strm->next_in */ +/* 24 12 */ unsigned char FAR *last; /* r9 while in < last */ +/* 32 16 */ unsigned char FAR *out; /* edi rdi local strm->next_out */ +/* 40 20 */ unsigned char FAR *beg; /* inflate()'s init next_out */ +/* 48 24 */ unsigned char FAR *end; /* r10 while out < end */ +/* 56 28 */ unsigned char FAR *window;/* size of window, wsize!=0 */ +/* 64 32 */ code const FAR *lcode; /* ebp rbp local strm->lencode */ +/* 72 36 */ code const FAR *dcode; /* r11 local strm->distcode */ +/* 80 40 */ unsigned long hold; /* edx rdx local strm->hold */ +/* 88 44 */ unsigned bits; /* ebx rbx local strm->bits */ +/* 92 48 */ unsigned wsize; /* window size */ +/* 96 52 */ unsigned write; /* window write index */ +/*100 56 */ unsigned lmask; /* r12 mask for lcode */ +/*104 60 */ unsigned dmask; /* r13 mask for dcode */ +/*108 64 */ unsigned len; /* r14 match length */ +/*112 68 */ unsigned dist; /* r15 match distance */ +/*116 72 */ unsigned status; /* set when state chng*/ + } ar; + +#if defined( __GNUC__ ) && defined( __amd64__ ) && ! defined( __i386 ) +#define PAD_AVAIL_IN 6 +#define PAD_AVAIL_OUT 258 +#else +#define PAD_AVAIL_IN 5 +#define PAD_AVAIL_OUT 257 +#endif + + /* copy state to local variables */ + state = (struct inflate_state FAR *)strm->state; + ar.in = strm->next_in; + ar.last = ar.in + (strm->avail_in - PAD_AVAIL_IN); + ar.out = strm->next_out; + ar.beg = ar.out - (start - strm->avail_out); + ar.end = ar.out + (strm->avail_out - PAD_AVAIL_OUT); + ar.wsize = state->wsize; + ar.write = state->wnext; + ar.window = state->window; + ar.hold = state->hold; + ar.bits = state->bits; + ar.lcode = state->lencode; + ar.dcode = state->distcode; + ar.lmask = (1U << state->lenbits) - 1; + ar.dmask = (1U << state->distbits) - 1; + + /* decode literals and length/distances until end-of-block or not enough + input data or output space */ + + /* align in on 1/2 hold size boundary */ + while (((unsigned long)(void *)ar.in & (sizeof(ar.hold) / 2 - 1)) != 0) { + ar.hold += (unsigned long)*ar.in++ << ar.bits; + ar.bits += 8; + } + +#if defined( __GNUC__ ) && defined( __amd64__ ) && ! defined( __i386 ) + __asm__ __volatile__ ( +" leaq %0, %%rax\n" +" movq %%rbp, 8(%%rax)\n" /* save regs rbp and rsp */ +" movq %%rsp, (%%rax)\n" +" movq %%rax, %%rsp\n" /* make rsp point to &ar */ +" movq 16(%%rsp), %%rsi\n" /* rsi = in */ +" movq 32(%%rsp), %%rdi\n" /* rdi = out */ +" movq 24(%%rsp), %%r9\n" /* r9 = last */ +" movq 48(%%rsp), %%r10\n" /* r10 = end */ +" movq 64(%%rsp), %%rbp\n" /* rbp = lcode */ +" movq 72(%%rsp), %%r11\n" /* r11 = dcode */ +" movq 80(%%rsp), %%rdx\n" /* rdx = hold */ +" movl 88(%%rsp), %%ebx\n" /* ebx = bits */ +" movl 100(%%rsp), %%r12d\n" /* r12d = lmask */ +" movl 104(%%rsp), %%r13d\n" /* r13d = dmask */ + /* r14d = len */ + /* r15d = dist */ +" cld\n" +" cmpq %%rdi, %%r10\n" +" je .L_one_time\n" /* if only one decode left */ +" cmpq %%rsi, %%r9\n" +" je .L_one_time\n" +" jmp .L_do_loop\n" + +".L_one_time:\n" +" movq %%r12, %%r8\n" /* r8 = lmask */ +" cmpb $32, %%bl\n" +" ja .L_get_length_code_one_time\n" + +" lodsl\n" /* eax = *(uint *)in++ */ +" movb %%bl, %%cl\n" /* cl = bits, needs it for shifting */ +" addb $32, %%bl\n" /* bits += 32 */ +" shlq %%cl, %%rax\n" +" orq %%rax, %%rdx\n" /* hold |= *((uint *)in)++ << bits */ +" jmp .L_get_length_code_one_time\n" + +".align 32,0x90\n" +".L_while_test:\n" +" cmpq %%rdi, %%r10\n" +" jbe .L_break_loop\n" +" cmpq %%rsi, %%r9\n" +" jbe .L_break_loop\n" + +".L_do_loop:\n" +" movq %%r12, %%r8\n" /* r8 = lmask */ +" cmpb $32, %%bl\n" +" ja .L_get_length_code\n" /* if (32 < bits) */ + +" lodsl\n" /* eax = *(uint *)in++ */ +" movb %%bl, %%cl\n" /* cl = bits, needs it for shifting */ +" addb $32, %%bl\n" /* bits += 32 */ +" shlq %%cl, %%rax\n" +" orq %%rax, %%rdx\n" /* hold |= *((uint *)in)++ << bits */ + +".L_get_length_code:\n" +" andq %%rdx, %%r8\n" /* r8 &= hold */ +" movl (%%rbp,%%r8,4), %%eax\n" /* eax = lcode[hold & lmask] */ + +" movb %%ah, %%cl\n" /* cl = this.bits */ +" subb %%ah, %%bl\n" /* bits -= this.bits */ +" shrq %%cl, %%rdx\n" /* hold >>= this.bits */ + +" testb %%al, %%al\n" +" jnz .L_test_for_length_base\n" /* if (op != 0) 45.7% */ + +" movq %%r12, %%r8\n" /* r8 = lmask */ +" shrl $16, %%eax\n" /* output this.val char */ +" stosb\n" + +".L_get_length_code_one_time:\n" +" andq %%rdx, %%r8\n" /* r8 &= hold */ +" movl (%%rbp,%%r8,4), %%eax\n" /* eax = lcode[hold & lmask] */ + +".L_dolen:\n" +" movb %%ah, %%cl\n" /* cl = this.bits */ +" subb %%ah, %%bl\n" /* bits -= this.bits */ +" shrq %%cl, %%rdx\n" /* hold >>= this.bits */ + +" testb %%al, %%al\n" +" jnz .L_test_for_length_base\n" /* if (op != 0) 45.7% */ + +" shrl $16, %%eax\n" /* output this.val char */ +" stosb\n" +" jmp .L_while_test\n" + +".align 32,0x90\n" +".L_test_for_length_base:\n" +" movl %%eax, %%r14d\n" /* len = this */ +" shrl $16, %%r14d\n" /* len = this.val */ +" movb %%al, %%cl\n" + +" testb $16, %%al\n" +" jz .L_test_for_second_level_length\n" /* if ((op & 16) == 0) 8% */ +" andb $15, %%cl\n" /* op &= 15 */ +" jz .L_decode_distance\n" /* if (!op) */ + +".L_add_bits_to_len:\n" +" subb %%cl, %%bl\n" +" xorl %%eax, %%eax\n" +" incl %%eax\n" +" shll %%cl, %%eax\n" +" decl %%eax\n" +" andl %%edx, %%eax\n" /* eax &= hold */ +" shrq %%cl, %%rdx\n" +" addl %%eax, %%r14d\n" /* len += hold & mask[op] */ + +".L_decode_distance:\n" +" movq %%r13, %%r8\n" /* r8 = dmask */ +" cmpb $32, %%bl\n" +" ja .L_get_distance_code\n" /* if (32 < bits) */ + +" lodsl\n" /* eax = *(uint *)in++ */ +" movb %%bl, %%cl\n" /* cl = bits, needs it for shifting */ +" addb $32, %%bl\n" /* bits += 32 */ +" shlq %%cl, %%rax\n" +" orq %%rax, %%rdx\n" /* hold |= *((uint *)in)++ << bits */ + +".L_get_distance_code:\n" +" andq %%rdx, %%r8\n" /* r8 &= hold */ +" movl (%%r11,%%r8,4), %%eax\n" /* eax = dcode[hold & dmask] */ + +".L_dodist:\n" +" movl %%eax, %%r15d\n" /* dist = this */ +" shrl $16, %%r15d\n" /* dist = this.val */ +" movb %%ah, %%cl\n" +" subb %%ah, %%bl\n" /* bits -= this.bits */ +" shrq %%cl, %%rdx\n" /* hold >>= this.bits */ +" movb %%al, %%cl\n" /* cl = this.op */ + +" testb $16, %%al\n" /* if ((op & 16) == 0) */ +" jz .L_test_for_second_level_dist\n" +" andb $15, %%cl\n" /* op &= 15 */ +" jz .L_check_dist_one\n" + +".L_add_bits_to_dist:\n" +" subb %%cl, %%bl\n" +" xorl %%eax, %%eax\n" +" incl %%eax\n" +" shll %%cl, %%eax\n" +" decl %%eax\n" /* (1 << op) - 1 */ +" andl %%edx, %%eax\n" /* eax &= hold */ +" shrq %%cl, %%rdx\n" +" addl %%eax, %%r15d\n" /* dist += hold & ((1 << op) - 1) */ + +".L_check_window:\n" +" movq %%rsi, %%r8\n" /* save in so from can use it's reg */ +" movq %%rdi, %%rax\n" +" subq 40(%%rsp), %%rax\n" /* nbytes = out - beg */ + +" cmpl %%r15d, %%eax\n" +" jb .L_clip_window\n" /* if (dist > nbytes) 4.2% */ + +" movl %%r14d, %%ecx\n" /* ecx = len */ +" movq %%rdi, %%rsi\n" +" subq %%r15, %%rsi\n" /* from = out - dist */ + +" sarl %%ecx\n" +" jnc .L_copy_two\n" /* if len % 2 == 0 */ + +" rep movsw\n" +" movb (%%rsi), %%al\n" +" movb %%al, (%%rdi)\n" +" incq %%rdi\n" + +" movq %%r8, %%rsi\n" /* move in back to %rsi, toss from */ +" jmp .L_while_test\n" + +".L_copy_two:\n" +" rep movsw\n" +" movq %%r8, %%rsi\n" /* move in back to %rsi, toss from */ +" jmp .L_while_test\n" + +".align 32,0x90\n" +".L_check_dist_one:\n" +" cmpl $1, %%r15d\n" /* if dist 1, is a memset */ +" jne .L_check_window\n" +" cmpq %%rdi, 40(%%rsp)\n" /* if out == beg, outside window */ +" je .L_check_window\n" + +" movl %%r14d, %%ecx\n" /* ecx = len */ +" movb -1(%%rdi), %%al\n" +" movb %%al, %%ah\n" + +" sarl %%ecx\n" +" jnc .L_set_two\n" +" movb %%al, (%%rdi)\n" +" incq %%rdi\n" + +".L_set_two:\n" +" rep stosw\n" +" jmp .L_while_test\n" + +".align 32,0x90\n" +".L_test_for_second_level_length:\n" +" testb $64, %%al\n" +" jnz .L_test_for_end_of_block\n" /* if ((op & 64) != 0) */ + +" xorl %%eax, %%eax\n" +" incl %%eax\n" +" shll %%cl, %%eax\n" +" decl %%eax\n" +" andl %%edx, %%eax\n" /* eax &= hold */ +" addl %%r14d, %%eax\n" /* eax += len */ +" movl (%%rbp,%%rax,4), %%eax\n" /* eax = lcode[val+(hold&mask[op])]*/ +" jmp .L_dolen\n" + +".align 32,0x90\n" +".L_test_for_second_level_dist:\n" +" testb $64, %%al\n" +" jnz .L_invalid_distance_code\n" /* if ((op & 64) != 0) */ + +" xorl %%eax, %%eax\n" +" incl %%eax\n" +" shll %%cl, %%eax\n" +" decl %%eax\n" +" andl %%edx, %%eax\n" /* eax &= hold */ +" addl %%r15d, %%eax\n" /* eax += dist */ +" movl (%%r11,%%rax,4), %%eax\n" /* eax = dcode[val+(hold&mask[op])]*/ +" jmp .L_dodist\n" + +".align 32,0x90\n" +".L_clip_window:\n" +" movl %%eax, %%ecx\n" /* ecx = nbytes */ +" movl 92(%%rsp), %%eax\n" /* eax = wsize, prepare for dist cmp */ +" negl %%ecx\n" /* nbytes = -nbytes */ + +" cmpl %%r15d, %%eax\n" +" jb .L_invalid_distance_too_far\n" /* if (dist > wsize) */ + +" addl %%r15d, %%ecx\n" /* nbytes = dist - nbytes */ +" cmpl $0, 96(%%rsp)\n" +" jne .L_wrap_around_window\n" /* if (write != 0) */ + +" movq 56(%%rsp), %%rsi\n" /* from = window */ +" subl %%ecx, %%eax\n" /* eax -= nbytes */ +" addq %%rax, %%rsi\n" /* from += wsize - nbytes */ + +" movl %%r14d, %%eax\n" /* eax = len */ +" cmpl %%ecx, %%r14d\n" +" jbe .L_do_copy\n" /* if (nbytes >= len) */ + +" subl %%ecx, %%eax\n" /* eax -= nbytes */ +" rep movsb\n" +" movq %%rdi, %%rsi\n" +" subq %%r15, %%rsi\n" /* from = &out[ -dist ] */ +" jmp .L_do_copy\n" + +".align 32,0x90\n" +".L_wrap_around_window:\n" +" movl 96(%%rsp), %%eax\n" /* eax = write */ +" cmpl %%eax, %%ecx\n" +" jbe .L_contiguous_in_window\n" /* if (write >= nbytes) */ + +" movl 92(%%rsp), %%esi\n" /* from = wsize */ +" addq 56(%%rsp), %%rsi\n" /* from += window */ +" addq %%rax, %%rsi\n" /* from += write */ +" subq %%rcx, %%rsi\n" /* from -= nbytes */ +" subl %%eax, %%ecx\n" /* nbytes -= write */ + +" movl %%r14d, %%eax\n" /* eax = len */ +" cmpl %%ecx, %%eax\n" +" jbe .L_do_copy\n" /* if (nbytes >= len) */ + +" subl %%ecx, %%eax\n" /* len -= nbytes */ +" rep movsb\n" +" movq 56(%%rsp), %%rsi\n" /* from = window */ +" movl 96(%%rsp), %%ecx\n" /* nbytes = write */ +" cmpl %%ecx, %%eax\n" +" jbe .L_do_copy\n" /* if (nbytes >= len) */ + +" subl %%ecx, %%eax\n" /* len -= nbytes */ +" rep movsb\n" +" movq %%rdi, %%rsi\n" +" subq %%r15, %%rsi\n" /* from = out - dist */ +" jmp .L_do_copy\n" + +".align 32,0x90\n" +".L_contiguous_in_window:\n" +" movq 56(%%rsp), %%rsi\n" /* rsi = window */ +" addq %%rax, %%rsi\n" +" subq %%rcx, %%rsi\n" /* from += write - nbytes */ + +" movl %%r14d, %%eax\n" /* eax = len */ +" cmpl %%ecx, %%eax\n" +" jbe .L_do_copy\n" /* if (nbytes >= len) */ + +" subl %%ecx, %%eax\n" /* len -= nbytes */ +" rep movsb\n" +" movq %%rdi, %%rsi\n" +" subq %%r15, %%rsi\n" /* from = out - dist */ +" jmp .L_do_copy\n" /* if (nbytes >= len) */ + +".align 32,0x90\n" +".L_do_copy:\n" +" movl %%eax, %%ecx\n" /* ecx = len */ +" rep movsb\n" + +" movq %%r8, %%rsi\n" /* move in back to %esi, toss from */ +" jmp .L_while_test\n" + +".L_test_for_end_of_block:\n" +" testb $32, %%al\n" +" jz .L_invalid_literal_length_code\n" +" movl $1, 116(%%rsp)\n" +" jmp .L_break_loop_with_status\n" + +".L_invalid_literal_length_code:\n" +" movl $2, 116(%%rsp)\n" +" jmp .L_break_loop_with_status\n" + +".L_invalid_distance_code:\n" +" movl $3, 116(%%rsp)\n" +" jmp .L_break_loop_with_status\n" + +".L_invalid_distance_too_far:\n" +" movl $4, 116(%%rsp)\n" +" jmp .L_break_loop_with_status\n" + +".L_break_loop:\n" +" movl $0, 116(%%rsp)\n" + +".L_break_loop_with_status:\n" +/* put in, out, bits, and hold back into ar and pop esp */ +" movq %%rsi, 16(%%rsp)\n" /* in */ +" movq %%rdi, 32(%%rsp)\n" /* out */ +" movl %%ebx, 88(%%rsp)\n" /* bits */ +" movq %%rdx, 80(%%rsp)\n" /* hold */ +" movq (%%rsp), %%rax\n" /* restore rbp and rsp */ +" movq 8(%%rsp), %%rbp\n" +" movq %%rax, %%rsp\n" + : + : "m" (ar) + : "memory", "%rax", "%rbx", "%rcx", "%rdx", "%rsi", "%rdi", + "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15" + ); +#elif ( defined( __GNUC__ ) || defined( __ICC ) ) && defined( __i386 ) + __asm__ __volatile__ ( +" leal %0, %%eax\n" +" movl %%esp, (%%eax)\n" /* save esp, ebp */ +" movl %%ebp, 4(%%eax)\n" +" movl %%eax, %%esp\n" +" movl 8(%%esp), %%esi\n" /* esi = in */ +" movl 16(%%esp), %%edi\n" /* edi = out */ +" movl 40(%%esp), %%edx\n" /* edx = hold */ +" movl 44(%%esp), %%ebx\n" /* ebx = bits */ +" movl 32(%%esp), %%ebp\n" /* ebp = lcode */ + +" cld\n" +" jmp .L_do_loop\n" + +".align 32,0x90\n" +".L_while_test:\n" +" cmpl %%edi, 24(%%esp)\n" /* out < end */ +" jbe .L_break_loop\n" +" cmpl %%esi, 12(%%esp)\n" /* in < last */ +" jbe .L_break_loop\n" + +".L_do_loop:\n" +" cmpb $15, %%bl\n" +" ja .L_get_length_code\n" /* if (15 < bits) */ + +" xorl %%eax, %%eax\n" +" lodsw\n" /* al = *(ushort *)in++ */ +" movb %%bl, %%cl\n" /* cl = bits, needs it for shifting */ +" addb $16, %%bl\n" /* bits += 16 */ +" shll %%cl, %%eax\n" +" orl %%eax, %%edx\n" /* hold |= *((ushort *)in)++ << bits */ + +".L_get_length_code:\n" +" movl 56(%%esp), %%eax\n" /* eax = lmask */ +" andl %%edx, %%eax\n" /* eax &= hold */ +" movl (%%ebp,%%eax,4), %%eax\n" /* eax = lcode[hold & lmask] */ + +".L_dolen:\n" +" movb %%ah, %%cl\n" /* cl = this.bits */ +" subb %%ah, %%bl\n" /* bits -= this.bits */ +" shrl %%cl, %%edx\n" /* hold >>= this.bits */ + +" testb %%al, %%al\n" +" jnz .L_test_for_length_base\n" /* if (op != 0) 45.7% */ + +" shrl $16, %%eax\n" /* output this.val char */ +" stosb\n" +" jmp .L_while_test\n" + +".align 32,0x90\n" +".L_test_for_length_base:\n" +" movl %%eax, %%ecx\n" /* len = this */ +" shrl $16, %%ecx\n" /* len = this.val */ +" movl %%ecx, 64(%%esp)\n" /* save len */ +" movb %%al, %%cl\n" + +" testb $16, %%al\n" +" jz .L_test_for_second_level_length\n" /* if ((op & 16) == 0) 8% */ +" andb $15, %%cl\n" /* op &= 15 */ +" jz .L_decode_distance\n" /* if (!op) */ +" cmpb %%cl, %%bl\n" +" jae .L_add_bits_to_len\n" /* if (op <= bits) */ + +" movb %%cl, %%ch\n" /* stash op in ch, freeing cl */ +" xorl %%eax, %%eax\n" +" lodsw\n" /* al = *(ushort *)in++ */ +" movb %%bl, %%cl\n" /* cl = bits, needs it for shifting */ +" addb $16, %%bl\n" /* bits += 16 */ +" shll %%cl, %%eax\n" +" orl %%eax, %%edx\n" /* hold |= *((ushort *)in)++ << bits */ +" movb %%ch, %%cl\n" /* move op back to ecx */ + +".L_add_bits_to_len:\n" +" subb %%cl, %%bl\n" +" xorl %%eax, %%eax\n" +" incl %%eax\n" +" shll %%cl, %%eax\n" +" decl %%eax\n" +" andl %%edx, %%eax\n" /* eax &= hold */ +" shrl %%cl, %%edx\n" +" addl %%eax, 64(%%esp)\n" /* len += hold & mask[op] */ + +".L_decode_distance:\n" +" cmpb $15, %%bl\n" +" ja .L_get_distance_code\n" /* if (15 < bits) */ + +" xorl %%eax, %%eax\n" +" lodsw\n" /* al = *(ushort *)in++ */ +" movb %%bl, %%cl\n" /* cl = bits, needs it for shifting */ +" addb $16, %%bl\n" /* bits += 16 */ +" shll %%cl, %%eax\n" +" orl %%eax, %%edx\n" /* hold |= *((ushort *)in)++ << bits */ + +".L_get_distance_code:\n" +" movl 60(%%esp), %%eax\n" /* eax = dmask */ +" movl 36(%%esp), %%ecx\n" /* ecx = dcode */ +" andl %%edx, %%eax\n" /* eax &= hold */ +" movl (%%ecx,%%eax,4), %%eax\n"/* eax = dcode[hold & dmask] */ + +".L_dodist:\n" +" movl %%eax, %%ebp\n" /* dist = this */ +" shrl $16, %%ebp\n" /* dist = this.val */ +" movb %%ah, %%cl\n" +" subb %%ah, %%bl\n" /* bits -= this.bits */ +" shrl %%cl, %%edx\n" /* hold >>= this.bits */ +" movb %%al, %%cl\n" /* cl = this.op */ + +" testb $16, %%al\n" /* if ((op & 16) == 0) */ +" jz .L_test_for_second_level_dist\n" +" andb $15, %%cl\n" /* op &= 15 */ +" jz .L_check_dist_one\n" +" cmpb %%cl, %%bl\n" +" jae .L_add_bits_to_dist\n" /* if (op <= bits) 97.6% */ + +" movb %%cl, %%ch\n" /* stash op in ch, freeing cl */ +" xorl %%eax, %%eax\n" +" lodsw\n" /* al = *(ushort *)in++ */ +" movb %%bl, %%cl\n" /* cl = bits, needs it for shifting */ +" addb $16, %%bl\n" /* bits += 16 */ +" shll %%cl, %%eax\n" +" orl %%eax, %%edx\n" /* hold |= *((ushort *)in)++ << bits */ +" movb %%ch, %%cl\n" /* move op back to ecx */ + +".L_add_bits_to_dist:\n" +" subb %%cl, %%bl\n" +" xorl %%eax, %%eax\n" +" incl %%eax\n" +" shll %%cl, %%eax\n" +" decl %%eax\n" /* (1 << op) - 1 */ +" andl %%edx, %%eax\n" /* eax &= hold */ +" shrl %%cl, %%edx\n" +" addl %%eax, %%ebp\n" /* dist += hold & ((1 << op) - 1) */ + +".L_check_window:\n" +" movl %%esi, 8(%%esp)\n" /* save in so from can use it's reg */ +" movl %%edi, %%eax\n" +" subl 20(%%esp), %%eax\n" /* nbytes = out - beg */ + +" cmpl %%ebp, %%eax\n" +" jb .L_clip_window\n" /* if (dist > nbytes) 4.2% */ + +" movl 64(%%esp), %%ecx\n" /* ecx = len */ +" movl %%edi, %%esi\n" +" subl %%ebp, %%esi\n" /* from = out - dist */ + +" sarl %%ecx\n" +" jnc .L_copy_two\n" /* if len % 2 == 0 */ + +" rep movsw\n" +" movb (%%esi), %%al\n" +" movb %%al, (%%edi)\n" +" incl %%edi\n" + +" movl 8(%%esp), %%esi\n" /* move in back to %esi, toss from */ +" movl 32(%%esp), %%ebp\n" /* ebp = lcode */ +" jmp .L_while_test\n" + +".L_copy_two:\n" +" rep movsw\n" +" movl 8(%%esp), %%esi\n" /* move in back to %esi, toss from */ +" movl 32(%%esp), %%ebp\n" /* ebp = lcode */ +" jmp .L_while_test\n" + +".align 32,0x90\n" +".L_check_dist_one:\n" +" cmpl $1, %%ebp\n" /* if dist 1, is a memset */ +" jne .L_check_window\n" +" cmpl %%edi, 20(%%esp)\n" +" je .L_check_window\n" /* out == beg, if outside window */ + +" movl 64(%%esp), %%ecx\n" /* ecx = len */ +" movb -1(%%edi), %%al\n" +" movb %%al, %%ah\n" + +" sarl %%ecx\n" +" jnc .L_set_two\n" +" movb %%al, (%%edi)\n" +" incl %%edi\n" + +".L_set_two:\n" +" rep stosw\n" +" movl 32(%%esp), %%ebp\n" /* ebp = lcode */ +" jmp .L_while_test\n" + +".align 32,0x90\n" +".L_test_for_second_level_length:\n" +" testb $64, %%al\n" +" jnz .L_test_for_end_of_block\n" /* if ((op & 64) != 0) */ + +" xorl %%eax, %%eax\n" +" incl %%eax\n" +" shll %%cl, %%eax\n" +" decl %%eax\n" +" andl %%edx, %%eax\n" /* eax &= hold */ +" addl 64(%%esp), %%eax\n" /* eax += len */ +" movl (%%ebp,%%eax,4), %%eax\n" /* eax = lcode[val+(hold&mask[op])]*/ +" jmp .L_dolen\n" + +".align 32,0x90\n" +".L_test_for_second_level_dist:\n" +" testb $64, %%al\n" +" jnz .L_invalid_distance_code\n" /* if ((op & 64) != 0) */ + +" xorl %%eax, %%eax\n" +" incl %%eax\n" +" shll %%cl, %%eax\n" +" decl %%eax\n" +" andl %%edx, %%eax\n" /* eax &= hold */ +" addl %%ebp, %%eax\n" /* eax += dist */ +" movl 36(%%esp), %%ecx\n" /* ecx = dcode */ +" movl (%%ecx,%%eax,4), %%eax\n" /* eax = dcode[val+(hold&mask[op])]*/ +" jmp .L_dodist\n" + +".align 32,0x90\n" +".L_clip_window:\n" +" movl %%eax, %%ecx\n" +" movl 48(%%esp), %%eax\n" /* eax = wsize */ +" negl %%ecx\n" /* nbytes = -nbytes */ +" movl 28(%%esp), %%esi\n" /* from = window */ + +" cmpl %%ebp, %%eax\n" +" jb .L_invalid_distance_too_far\n" /* if (dist > wsize) */ + +" addl %%ebp, %%ecx\n" /* nbytes = dist - nbytes */ +" cmpl $0, 52(%%esp)\n" +" jne .L_wrap_around_window\n" /* if (write != 0) */ + +" subl %%ecx, %%eax\n" +" addl %%eax, %%esi\n" /* from += wsize - nbytes */ + +" movl 64(%%esp), %%eax\n" /* eax = len */ +" cmpl %%ecx, %%eax\n" +" jbe .L_do_copy\n" /* if (nbytes >= len) */ + +" subl %%ecx, %%eax\n" /* len -= nbytes */ +" rep movsb\n" +" movl %%edi, %%esi\n" +" subl %%ebp, %%esi\n" /* from = out - dist */ +" jmp .L_do_copy\n" + +".align 32,0x90\n" +".L_wrap_around_window:\n" +" movl 52(%%esp), %%eax\n" /* eax = write */ +" cmpl %%eax, %%ecx\n" +" jbe .L_contiguous_in_window\n" /* if (write >= nbytes) */ + +" addl 48(%%esp), %%esi\n" /* from += wsize */ +" addl %%eax, %%esi\n" /* from += write */ +" subl %%ecx, %%esi\n" /* from -= nbytes */ +" subl %%eax, %%ecx\n" /* nbytes -= write */ + +" movl 64(%%esp), %%eax\n" /* eax = len */ +" cmpl %%ecx, %%eax\n" +" jbe .L_do_copy\n" /* if (nbytes >= len) */ + +" subl %%ecx, %%eax\n" /* len -= nbytes */ +" rep movsb\n" +" movl 28(%%esp), %%esi\n" /* from = window */ +" movl 52(%%esp), %%ecx\n" /* nbytes = write */ +" cmpl %%ecx, %%eax\n" +" jbe .L_do_copy\n" /* if (nbytes >= len) */ + +" subl %%ecx, %%eax\n" /* len -= nbytes */ +" rep movsb\n" +" movl %%edi, %%esi\n" +" subl %%ebp, %%esi\n" /* from = out - dist */ +" jmp .L_do_copy\n" + +".align 32,0x90\n" +".L_contiguous_in_window:\n" +" addl %%eax, %%esi\n" +" subl %%ecx, %%esi\n" /* from += write - nbytes */ + +" movl 64(%%esp), %%eax\n" /* eax = len */ +" cmpl %%ecx, %%eax\n" +" jbe .L_do_copy\n" /* if (nbytes >= len) */ + +" subl %%ecx, %%eax\n" /* len -= nbytes */ +" rep movsb\n" +" movl %%edi, %%esi\n" +" subl %%ebp, %%esi\n" /* from = out - dist */ +" jmp .L_do_copy\n" /* if (nbytes >= len) */ + +".align 32,0x90\n" +".L_do_copy:\n" +" movl %%eax, %%ecx\n" +" rep movsb\n" + +" movl 8(%%esp), %%esi\n" /* move in back to %esi, toss from */ +" movl 32(%%esp), %%ebp\n" /* ebp = lcode */ +" jmp .L_while_test\n" + +".L_test_for_end_of_block:\n" +" testb $32, %%al\n" +" jz .L_invalid_literal_length_code\n" +" movl $1, 72(%%esp)\n" +" jmp .L_break_loop_with_status\n" + +".L_invalid_literal_length_code:\n" +" movl $2, 72(%%esp)\n" +" jmp .L_break_loop_with_status\n" + +".L_invalid_distance_code:\n" +" movl $3, 72(%%esp)\n" +" jmp .L_break_loop_with_status\n" + +".L_invalid_distance_too_far:\n" +" movl 8(%%esp), %%esi\n" +" movl $4, 72(%%esp)\n" +" jmp .L_break_loop_with_status\n" + +".L_break_loop:\n" +" movl $0, 72(%%esp)\n" + +".L_break_loop_with_status:\n" +/* put in, out, bits, and hold back into ar and pop esp */ +" movl %%esi, 8(%%esp)\n" /* save in */ +" movl %%edi, 16(%%esp)\n" /* save out */ +" movl %%ebx, 44(%%esp)\n" /* save bits */ +" movl %%edx, 40(%%esp)\n" /* save hold */ +" movl 4(%%esp), %%ebp\n" /* restore esp, ebp */ +" movl (%%esp), %%esp\n" + : + : "m" (ar) + : "memory", "%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi" + ); +#elif defined( _MSC_VER ) && ! defined( _M_AMD64 ) + __asm { + lea eax, ar + mov [eax], esp /* save esp, ebp */ + mov [eax+4], ebp + mov esp, eax + mov esi, [esp+8] /* esi = in */ + mov edi, [esp+16] /* edi = out */ + mov edx, [esp+40] /* edx = hold */ + mov ebx, [esp+44] /* ebx = bits */ + mov ebp, [esp+32] /* ebp = lcode */ + + cld + jmp L_do_loop + +ALIGN 4 +L_while_test: + cmp [esp+24], edi + jbe L_break_loop + cmp [esp+12], esi + jbe L_break_loop + +L_do_loop: + cmp bl, 15 + ja L_get_length_code /* if (15 < bits) */ + + xor eax, eax + lodsw /* al = *(ushort *)in++ */ + mov cl, bl /* cl = bits, needs it for shifting */ + add bl, 16 /* bits += 16 */ + shl eax, cl + or edx, eax /* hold |= *((ushort *)in)++ << bits */ + +L_get_length_code: + mov eax, [esp+56] /* eax = lmask */ + and eax, edx /* eax &= hold */ + mov eax, [ebp+eax*4] /* eax = lcode[hold & lmask] */ + +L_dolen: + mov cl, ah /* cl = this.bits */ + sub bl, ah /* bits -= this.bits */ + shr edx, cl /* hold >>= this.bits */ + + test al, al + jnz L_test_for_length_base /* if (op != 0) 45.7% */ + + shr eax, 16 /* output this.val char */ + stosb + jmp L_while_test + +ALIGN 4 +L_test_for_length_base: + mov ecx, eax /* len = this */ + shr ecx, 16 /* len = this.val */ + mov [esp+64], ecx /* save len */ + mov cl, al + + test al, 16 + jz L_test_for_second_level_length /* if ((op & 16) == 0) 8% */ + and cl, 15 /* op &= 15 */ + jz L_decode_distance /* if (!op) */ + cmp bl, cl + jae L_add_bits_to_len /* if (op <= bits) */ + + mov ch, cl /* stash op in ch, freeing cl */ + xor eax, eax + lodsw /* al = *(ushort *)in++ */ + mov cl, bl /* cl = bits, needs it for shifting */ + add bl, 16 /* bits += 16 */ + shl eax, cl + or edx, eax /* hold |= *((ushort *)in)++ << bits */ + mov cl, ch /* move op back to ecx */ + +L_add_bits_to_len: + sub bl, cl + xor eax, eax + inc eax + shl eax, cl + dec eax + and eax, edx /* eax &= hold */ + shr edx, cl + add [esp+64], eax /* len += hold & mask[op] */ + +L_decode_distance: + cmp bl, 15 + ja L_get_distance_code /* if (15 < bits) */ + + xor eax, eax + lodsw /* al = *(ushort *)in++ */ + mov cl, bl /* cl = bits, needs it for shifting */ + add bl, 16 /* bits += 16 */ + shl eax, cl + or edx, eax /* hold |= *((ushort *)in)++ << bits */ + +L_get_distance_code: + mov eax, [esp+60] /* eax = dmask */ + mov ecx, [esp+36] /* ecx = dcode */ + and eax, edx /* eax &= hold */ + mov eax, [ecx+eax*4]/* eax = dcode[hold & dmask] */ + +L_dodist: + mov ebp, eax /* dist = this */ + shr ebp, 16 /* dist = this.val */ + mov cl, ah + sub bl, ah /* bits -= this.bits */ + shr edx, cl /* hold >>= this.bits */ + mov cl, al /* cl = this.op */ + + test al, 16 /* if ((op & 16) == 0) */ + jz L_test_for_second_level_dist + and cl, 15 /* op &= 15 */ + jz L_check_dist_one + cmp bl, cl + jae L_add_bits_to_dist /* if (op <= bits) 97.6% */ + + mov ch, cl /* stash op in ch, freeing cl */ + xor eax, eax + lodsw /* al = *(ushort *)in++ */ + mov cl, bl /* cl = bits, needs it for shifting */ + add bl, 16 /* bits += 16 */ + shl eax, cl + or edx, eax /* hold |= *((ushort *)in)++ << bits */ + mov cl, ch /* move op back to ecx */ + +L_add_bits_to_dist: + sub bl, cl + xor eax, eax + inc eax + shl eax, cl + dec eax /* (1 << op) - 1 */ + and eax, edx /* eax &= hold */ + shr edx, cl + add ebp, eax /* dist += hold & ((1 << op) - 1) */ + +L_check_window: + mov [esp+8], esi /* save in so from can use it's reg */ + mov eax, edi + sub eax, [esp+20] /* nbytes = out - beg */ + + cmp eax, ebp + jb L_clip_window /* if (dist > nbytes) 4.2% */ + + mov ecx, [esp+64] /* ecx = len */ + mov esi, edi + sub esi, ebp /* from = out - dist */ + + sar ecx, 1 + jnc L_copy_two + + rep movsw + mov al, [esi] + mov [edi], al + inc edi + + mov esi, [esp+8] /* move in back to %esi, toss from */ + mov ebp, [esp+32] /* ebp = lcode */ + jmp L_while_test + +L_copy_two: + rep movsw + mov esi, [esp+8] /* move in back to %esi, toss from */ + mov ebp, [esp+32] /* ebp = lcode */ + jmp L_while_test + +ALIGN 4 +L_check_dist_one: + cmp ebp, 1 /* if dist 1, is a memset */ + jne L_check_window + cmp [esp+20], edi + je L_check_window /* out == beg, if outside window */ + + mov ecx, [esp+64] /* ecx = len */ + mov al, [edi-1] + mov ah, al + + sar ecx, 1 + jnc L_set_two + mov [edi], al /* memset out with from[-1] */ + inc edi + +L_set_two: + rep stosw + mov ebp, [esp+32] /* ebp = lcode */ + jmp L_while_test + +ALIGN 4 +L_test_for_second_level_length: + test al, 64 + jnz L_test_for_end_of_block /* if ((op & 64) != 0) */ + + xor eax, eax + inc eax + shl eax, cl + dec eax + and eax, edx /* eax &= hold */ + add eax, [esp+64] /* eax += len */ + mov eax, [ebp+eax*4] /* eax = lcode[val+(hold&mask[op])]*/ + jmp L_dolen + +ALIGN 4 +L_test_for_second_level_dist: + test al, 64 + jnz L_invalid_distance_code /* if ((op & 64) != 0) */ + + xor eax, eax + inc eax + shl eax, cl + dec eax + and eax, edx /* eax &= hold */ + add eax, ebp /* eax += dist */ + mov ecx, [esp+36] /* ecx = dcode */ + mov eax, [ecx+eax*4] /* eax = dcode[val+(hold&mask[op])]*/ + jmp L_dodist + +ALIGN 4 +L_clip_window: + mov ecx, eax + mov eax, [esp+48] /* eax = wsize */ + neg ecx /* nbytes = -nbytes */ + mov esi, [esp+28] /* from = window */ + + cmp eax, ebp + jb L_invalid_distance_too_far /* if (dist > wsize) */ + + add ecx, ebp /* nbytes = dist - nbytes */ + cmp dword ptr [esp+52], 0 + jne L_wrap_around_window /* if (write != 0) */ + + sub eax, ecx + add esi, eax /* from += wsize - nbytes */ + + mov eax, [esp+64] /* eax = len */ + cmp eax, ecx + jbe L_do_copy /* if (nbytes >= len) */ + + sub eax, ecx /* len -= nbytes */ + rep movsb + mov esi, edi + sub esi, ebp /* from = out - dist */ + jmp L_do_copy + +ALIGN 4 +L_wrap_around_window: + mov eax, [esp+52] /* eax = write */ + cmp ecx, eax + jbe L_contiguous_in_window /* if (write >= nbytes) */ + + add esi, [esp+48] /* from += wsize */ + add esi, eax /* from += write */ + sub esi, ecx /* from -= nbytes */ + sub ecx, eax /* nbytes -= write */ + + mov eax, [esp+64] /* eax = len */ + cmp eax, ecx + jbe L_do_copy /* if (nbytes >= len) */ + + sub eax, ecx /* len -= nbytes */ + rep movsb + mov esi, [esp+28] /* from = window */ + mov ecx, [esp+52] /* nbytes = write */ + cmp eax, ecx + jbe L_do_copy /* if (nbytes >= len) */ + + sub eax, ecx /* len -= nbytes */ + rep movsb + mov esi, edi + sub esi, ebp /* from = out - dist */ + jmp L_do_copy + +ALIGN 4 +L_contiguous_in_window: + add esi, eax + sub esi, ecx /* from += write - nbytes */ + + mov eax, [esp+64] /* eax = len */ + cmp eax, ecx + jbe L_do_copy /* if (nbytes >= len) */ + + sub eax, ecx /* len -= nbytes */ + rep movsb + mov esi, edi + sub esi, ebp /* from = out - dist */ + jmp L_do_copy + +ALIGN 4 +L_do_copy: + mov ecx, eax + rep movsb + + mov esi, [esp+8] /* move in back to %esi, toss from */ + mov ebp, [esp+32] /* ebp = lcode */ + jmp L_while_test + +L_test_for_end_of_block: + test al, 32 + jz L_invalid_literal_length_code + mov dword ptr [esp+72], 1 + jmp L_break_loop_with_status + +L_invalid_literal_length_code: + mov dword ptr [esp+72], 2 + jmp L_break_loop_with_status + +L_invalid_distance_code: + mov dword ptr [esp+72], 3 + jmp L_break_loop_with_status + +L_invalid_distance_too_far: + mov esi, [esp+4] + mov dword ptr [esp+72], 4 + jmp L_break_loop_with_status + +L_break_loop: + mov dword ptr [esp+72], 0 + +L_break_loop_with_status: +/* put in, out, bits, and hold back into ar and pop esp */ + mov [esp+8], esi /* save in */ + mov [esp+16], edi /* save out */ + mov [esp+44], ebx /* save bits */ + mov [esp+40], edx /* save hold */ + mov ebp, [esp+4] /* restore esp, ebp */ + mov esp, [esp] + } +#else +#error "x86 architecture not defined" +#endif + + if (ar.status > 1) { + if (ar.status == 2) + strm->msg = "invalid literal/length code"; + else if (ar.status == 3) + strm->msg = "invalid distance code"; + else + strm->msg = "invalid distance too far back"; + state->mode = BAD; + } + else if ( ar.status == 1 ) { + state->mode = TYPE; + } + + /* return unused bytes (on entry, bits < 8, so in won't go too far back) */ + ar.len = ar.bits >> 3; + ar.in -= ar.len; + ar.bits -= ar.len << 3; + ar.hold &= (1U << ar.bits) - 1; + + /* update state and return */ + strm->next_in = ar.in; + strm->next_out = ar.out; + strm->avail_in = (unsigned)(ar.in < ar.last ? + PAD_AVAIL_IN + (ar.last - ar.in) : + PAD_AVAIL_IN - (ar.in - ar.last)); + strm->avail_out = (unsigned)(ar.out < ar.end ? + PAD_AVAIL_OUT + (ar.end - ar.out) : + PAD_AVAIL_OUT - (ar.out - ar.end)); + state->hold = ar.hold; + state->bits = ar.bits; + return; +} + diff --git a/libs/zlib/contrib/inflate86/inffast.S b/libs/zlib/contrib/inflate86/inffast.S new file mode 100644 index 000000000..2245a2905 --- /dev/null +++ b/libs/zlib/contrib/inflate86/inffast.S @@ -0,0 +1,1368 @@ +/* + * inffast.S is a hand tuned assembler version of: + * + * inffast.c -- fast decoding + * Copyright (C) 1995-2003 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + * + * Copyright (C) 2003 Chris Anderson + * Please use the copyright conditions above. + * + * This version (Jan-23-2003) of inflate_fast was coded and tested under + * GNU/Linux on a pentium 3, using the gcc-3.2 compiler distribution. On that + * machine, I found that gzip style archives decompressed about 20% faster than + * the gcc-3.2 -O3 -fomit-frame-pointer compiled version. Your results will + * depend on how large of a buffer is used for z_stream.next_in & next_out + * (8K-32K worked best for my 256K cpu cache) and how much overhead there is in + * stream processing I/O and crc32/addler32. In my case, this routine used + * 70% of the cpu time and crc32 used 20%. + * + * I am confident that this version will work in the general case, but I have + * not tested a wide variety of datasets or a wide variety of platforms. + * + * Jan-24-2003 -- Added -DUSE_MMX define for slightly faster inflating. + * It should be a runtime flag instead of compile time flag... + * + * Jan-26-2003 -- Added runtime check for MMX support with cpuid instruction. + * With -DUSE_MMX, only MMX code is compiled. With -DNO_MMX, only non-MMX code + * is compiled. Without either option, runtime detection is enabled. Runtime + * detection should work on all modern cpus and the recomended algorithm (flip + * ID bit on eflags and then use the cpuid instruction) is used in many + * multimedia applications. Tested under win2k with gcc-2.95 and gas-2.12 + * distributed with cygwin3. Compiling with gcc-2.95 -c inffast.S -o + * inffast.obj generates a COFF object which can then be linked with MSVC++ + * compiled code. Tested under FreeBSD 4.7 with gcc-2.95. + * + * Jan-28-2003 -- Tested Athlon XP... MMX mode is slower than no MMX (and + * slower than compiler generated code). Adjusted cpuid check to use the MMX + * code only for Pentiums < P4 until I have more data on the P4. Speed + * improvment is only about 15% on the Athlon when compared with code generated + * with MSVC++. Not sure yet, but I think the P4 will also be slower using the + * MMX mode because many of it's x86 ALU instructions execute in .5 cycles and + * have less latency than MMX ops. Added code to buffer the last 11 bytes of + * the input stream since the MMX code grabs bits in chunks of 32, which + * differs from the inffast.c algorithm. I don't think there would have been + * read overruns where a page boundary was crossed (a segfault), but there + * could have been overruns when next_in ends on unaligned memory (unintialized + * memory read). + * + * Mar-13-2003 -- P4 MMX is slightly slower than P4 NO_MMX. I created a C + * version of the non-MMX code so that it doesn't depend on zstrm and zstate + * structure offsets which are hard coded in this file. This was last tested + * with zlib-1.2.0 which is currently in beta testing, newer versions of this + * and inffas86.c can be found at http://www.eetbeetee.com/zlib/ and + * http://www.charm.net/~christop/zlib/ + */ + + +/* + * if you have underscore linking problems (_inflate_fast undefined), try + * using -DGAS_COFF + */ +#if ! defined( GAS_COFF ) && ! defined( GAS_ELF ) + +#if defined( WIN32 ) || defined( __CYGWIN__ ) +#define GAS_COFF /* windows object format */ +#else +#define GAS_ELF +#endif + +#endif /* ! GAS_COFF && ! GAS_ELF */ + + +#if defined( GAS_COFF ) + +/* coff externals have underscores */ +#define inflate_fast _inflate_fast +#define inflate_fast_use_mmx _inflate_fast_use_mmx + +#endif /* GAS_COFF */ + + +.file "inffast.S" + +.globl inflate_fast + +.text +.align 4,0 +.L_invalid_literal_length_code_msg: +.string "invalid literal/length code" + +.align 4,0 +.L_invalid_distance_code_msg: +.string "invalid distance code" + +.align 4,0 +.L_invalid_distance_too_far_msg: +.string "invalid distance too far back" + +#if ! defined( NO_MMX ) +.align 4,0 +.L_mask: /* mask[N] = ( 1 << N ) - 1 */ +.long 0 +.long 1 +.long 3 +.long 7 +.long 15 +.long 31 +.long 63 +.long 127 +.long 255 +.long 511 +.long 1023 +.long 2047 +.long 4095 +.long 8191 +.long 16383 +.long 32767 +.long 65535 +.long 131071 +.long 262143 +.long 524287 +.long 1048575 +.long 2097151 +.long 4194303 +.long 8388607 +.long 16777215 +.long 33554431 +.long 67108863 +.long 134217727 +.long 268435455 +.long 536870911 +.long 1073741823 +.long 2147483647 +.long 4294967295 +#endif /* NO_MMX */ + +.text + +/* + * struct z_stream offsets, in zlib.h + */ +#define next_in_strm 0 /* strm->next_in */ +#define avail_in_strm 4 /* strm->avail_in */ +#define next_out_strm 12 /* strm->next_out */ +#define avail_out_strm 16 /* strm->avail_out */ +#define msg_strm 24 /* strm->msg */ +#define state_strm 28 /* strm->state */ + +/* + * struct inflate_state offsets, in inflate.h + */ +#define mode_state 0 /* state->mode */ +#define wsize_state 32 /* state->wsize */ +#define write_state 40 /* state->write */ +#define window_state 44 /* state->window */ +#define hold_state 48 /* state->hold */ +#define bits_state 52 /* state->bits */ +#define lencode_state 68 /* state->lencode */ +#define distcode_state 72 /* state->distcode */ +#define lenbits_state 76 /* state->lenbits */ +#define distbits_state 80 /* state->distbits */ + +/* + * inflate_fast's activation record + */ +#define local_var_size 64 /* how much local space for vars */ +#define strm_sp 88 /* first arg: z_stream * (local_var_size + 24) */ +#define start_sp 92 /* second arg: unsigned int (local_var_size + 28) */ + +/* + * offsets for local vars on stack + */ +#define out 60 /* unsigned char* */ +#define window 56 /* unsigned char* */ +#define wsize 52 /* unsigned int */ +#define write 48 /* unsigned int */ +#define in 44 /* unsigned char* */ +#define beg 40 /* unsigned char* */ +#define buf 28 /* char[ 12 ] */ +#define len 24 /* unsigned int */ +#define last 20 /* unsigned char* */ +#define end 16 /* unsigned char* */ +#define dcode 12 /* code* */ +#define lcode 8 /* code* */ +#define dmask 4 /* unsigned int */ +#define lmask 0 /* unsigned int */ + +/* + * typedef enum inflate_mode consts, in inflate.h + */ +#define INFLATE_MODE_TYPE 11 /* state->mode flags enum-ed in inflate.h */ +#define INFLATE_MODE_BAD 26 + + +#if ! defined( USE_MMX ) && ! defined( NO_MMX ) + +#define RUN_TIME_MMX + +#define CHECK_MMX 1 +#define DO_USE_MMX 2 +#define DONT_USE_MMX 3 + +.globl inflate_fast_use_mmx + +.data + +.align 4,0 +inflate_fast_use_mmx: /* integer flag for run time control 1=check,2=mmx,3=no */ +.long CHECK_MMX + +#if defined( GAS_ELF ) +/* elf info */ +.type inflate_fast_use_mmx,@object +.size inflate_fast_use_mmx,4 +#endif + +#endif /* RUN_TIME_MMX */ + +#if defined( GAS_COFF ) +/* coff info: scl 2 = extern, type 32 = function */ +.def inflate_fast; .scl 2; .type 32; .endef +#endif + +.text + +.align 32,0x90 +inflate_fast: + pushl %edi + pushl %esi + pushl %ebp + pushl %ebx + pushf /* save eflags (strm_sp, state_sp assumes this is 32 bits) */ + subl $local_var_size, %esp + cld + +#define strm_r %esi +#define state_r %edi + + movl strm_sp(%esp), strm_r + movl state_strm(strm_r), state_r + + /* in = strm->next_in; + * out = strm->next_out; + * last = in + strm->avail_in - 11; + * beg = out - (start - strm->avail_out); + * end = out + (strm->avail_out - 257); + */ + movl avail_in_strm(strm_r), %edx + movl next_in_strm(strm_r), %eax + + addl %eax, %edx /* avail_in += next_in */ + subl $11, %edx /* avail_in -= 11 */ + + movl %eax, in(%esp) + movl %edx, last(%esp) + + movl start_sp(%esp), %ebp + movl avail_out_strm(strm_r), %ecx + movl next_out_strm(strm_r), %ebx + + subl %ecx, %ebp /* start -= avail_out */ + negl %ebp /* start = -start */ + addl %ebx, %ebp /* start += next_out */ + + subl $257, %ecx /* avail_out -= 257 */ + addl %ebx, %ecx /* avail_out += out */ + + movl %ebx, out(%esp) + movl %ebp, beg(%esp) + movl %ecx, end(%esp) + + /* wsize = state->wsize; + * write = state->write; + * window = state->window; + * hold = state->hold; + * bits = state->bits; + * lcode = state->lencode; + * dcode = state->distcode; + * lmask = ( 1 << state->lenbits ) - 1; + * dmask = ( 1 << state->distbits ) - 1; + */ + + movl lencode_state(state_r), %eax + movl distcode_state(state_r), %ecx + + movl %eax, lcode(%esp) + movl %ecx, dcode(%esp) + + movl $1, %eax + movl lenbits_state(state_r), %ecx + shll %cl, %eax + decl %eax + movl %eax, lmask(%esp) + + movl $1, %eax + movl distbits_state(state_r), %ecx + shll %cl, %eax + decl %eax + movl %eax, dmask(%esp) + + movl wsize_state(state_r), %eax + movl write_state(state_r), %ecx + movl window_state(state_r), %edx + + movl %eax, wsize(%esp) + movl %ecx, write(%esp) + movl %edx, window(%esp) + + movl hold_state(state_r), %ebp + movl bits_state(state_r), %ebx + +#undef strm_r +#undef state_r + +#define in_r %esi +#define from_r %esi +#define out_r %edi + + movl in(%esp), in_r + movl last(%esp), %ecx + cmpl in_r, %ecx + ja .L_align_long /* if in < last */ + + addl $11, %ecx /* ecx = &in[ avail_in ] */ + subl in_r, %ecx /* ecx = avail_in */ + movl $12, %eax + subl %ecx, %eax /* eax = 12 - avail_in */ + leal buf(%esp), %edi + rep movsb /* memcpy( buf, in, avail_in ) */ + movl %eax, %ecx + xorl %eax, %eax + rep stosb /* memset( &buf[ avail_in ], 0, 12 - avail_in ) */ + leal buf(%esp), in_r /* in = buf */ + movl in_r, last(%esp) /* last = in, do just one iteration */ + jmp .L_is_aligned + + /* align in_r on long boundary */ +.L_align_long: + testl $3, in_r + jz .L_is_aligned + xorl %eax, %eax + movb (in_r), %al + incl in_r + movl %ebx, %ecx + addl $8, %ebx + shll %cl, %eax + orl %eax, %ebp + jmp .L_align_long + +.L_is_aligned: + movl out(%esp), out_r + +#if defined( NO_MMX ) + jmp .L_do_loop +#endif + +#if defined( USE_MMX ) + jmp .L_init_mmx +#endif + +/*** Runtime MMX check ***/ + +#if defined( RUN_TIME_MMX ) +.L_check_mmx: + cmpl $DO_USE_MMX, inflate_fast_use_mmx + je .L_init_mmx + ja .L_do_loop /* > 2 */ + + pushl %eax + pushl %ebx + pushl %ecx + pushl %edx + pushf + movl (%esp), %eax /* copy eflags to eax */ + xorl $0x200000, (%esp) /* try toggling ID bit of eflags (bit 21) + * to see if cpu supports cpuid... + * ID bit method not supported by NexGen but + * bios may load a cpuid instruction and + * cpuid may be disabled on Cyrix 5-6x86 */ + popf + pushf + popl %edx /* copy new eflags to edx */ + xorl %eax, %edx /* test if ID bit is flipped */ + jz .L_dont_use_mmx /* not flipped if zero */ + xorl %eax, %eax + cpuid + cmpl $0x756e6547, %ebx /* check for GenuineIntel in ebx,ecx,edx */ + jne .L_dont_use_mmx + cmpl $0x6c65746e, %ecx + jne .L_dont_use_mmx + cmpl $0x49656e69, %edx + jne .L_dont_use_mmx + movl $1, %eax + cpuid /* get cpu features */ + shrl $8, %eax + andl $15, %eax + cmpl $6, %eax /* check for Pentium family, is 0xf for P4 */ + jne .L_dont_use_mmx + testl $0x800000, %edx /* test if MMX feature is set (bit 23) */ + jnz .L_use_mmx + jmp .L_dont_use_mmx +.L_use_mmx: + movl $DO_USE_MMX, inflate_fast_use_mmx + jmp .L_check_mmx_pop +.L_dont_use_mmx: + movl $DONT_USE_MMX, inflate_fast_use_mmx +.L_check_mmx_pop: + popl %edx + popl %ecx + popl %ebx + popl %eax + jmp .L_check_mmx +#endif + + +/*** Non-MMX code ***/ + +#if defined ( NO_MMX ) || defined( RUN_TIME_MMX ) + +#define hold_r %ebp +#define bits_r %bl +#define bitslong_r %ebx + +.align 32,0x90 +.L_while_test: + /* while (in < last && out < end) + */ + cmpl out_r, end(%esp) + jbe .L_break_loop /* if (out >= end) */ + + cmpl in_r, last(%esp) + jbe .L_break_loop + +.L_do_loop: + /* regs: %esi = in, %ebp = hold, %bl = bits, %edi = out + * + * do { + * if (bits < 15) { + * hold |= *((unsigned short *)in)++ << bits; + * bits += 16 + * } + * this = lcode[hold & lmask] + */ + cmpb $15, bits_r + ja .L_get_length_code /* if (15 < bits) */ + + xorl %eax, %eax + lodsw /* al = *(ushort *)in++ */ + movb bits_r, %cl /* cl = bits, needs it for shifting */ + addb $16, bits_r /* bits += 16 */ + shll %cl, %eax + orl %eax, hold_r /* hold |= *((ushort *)in)++ << bits */ + +.L_get_length_code: + movl lmask(%esp), %edx /* edx = lmask */ + movl lcode(%esp), %ecx /* ecx = lcode */ + andl hold_r, %edx /* edx &= hold */ + movl (%ecx,%edx,4), %eax /* eax = lcode[hold & lmask] */ + +.L_dolen: + /* regs: %esi = in, %ebp = hold, %bl = bits, %edi = out + * + * dolen: + * bits -= this.bits; + * hold >>= this.bits + */ + movb %ah, %cl /* cl = this.bits */ + subb %ah, bits_r /* bits -= this.bits */ + shrl %cl, hold_r /* hold >>= this.bits */ + + /* check if op is a literal + * if (op == 0) { + * PUP(out) = this.val; + * } + */ + testb %al, %al + jnz .L_test_for_length_base /* if (op != 0) 45.7% */ + + shrl $16, %eax /* output this.val char */ + stosb + jmp .L_while_test + +.L_test_for_length_base: + /* regs: %esi = in, %ebp = hold, %bl = bits, %edi = out, %edx = len + * + * else if (op & 16) { + * len = this.val + * op &= 15 + * if (op) { + * if (op > bits) { + * hold |= *((unsigned short *)in)++ << bits; + * bits += 16 + * } + * len += hold & mask[op]; + * bits -= op; + * hold >>= op; + * } + */ +#define len_r %edx + movl %eax, len_r /* len = this */ + shrl $16, len_r /* len = this.val */ + movb %al, %cl + + testb $16, %al + jz .L_test_for_second_level_length /* if ((op & 16) == 0) 8% */ + andb $15, %cl /* op &= 15 */ + jz .L_save_len /* if (!op) */ + cmpb %cl, bits_r + jae .L_add_bits_to_len /* if (op <= bits) */ + + movb %cl, %ch /* stash op in ch, freeing cl */ + xorl %eax, %eax + lodsw /* al = *(ushort *)in++ */ + movb bits_r, %cl /* cl = bits, needs it for shifting */ + addb $16, bits_r /* bits += 16 */ + shll %cl, %eax + orl %eax, hold_r /* hold |= *((ushort *)in)++ << bits */ + movb %ch, %cl /* move op back to ecx */ + +.L_add_bits_to_len: + movl $1, %eax + shll %cl, %eax + decl %eax + subb %cl, bits_r + andl hold_r, %eax /* eax &= hold */ + shrl %cl, hold_r + addl %eax, len_r /* len += hold & mask[op] */ + +.L_save_len: + movl len_r, len(%esp) /* save len */ +#undef len_r + +.L_decode_distance: + /* regs: %esi = in, %ebp = hold, %bl = bits, %edi = out, %edx = dist + * + * if (bits < 15) { + * hold |= *((unsigned short *)in)++ << bits; + * bits += 16 + * } + * this = dcode[hold & dmask]; + * dodist: + * bits -= this.bits; + * hold >>= this.bits; + * op = this.op; + */ + + cmpb $15, bits_r + ja .L_get_distance_code /* if (15 < bits) */ + + xorl %eax, %eax + lodsw /* al = *(ushort *)in++ */ + movb bits_r, %cl /* cl = bits, needs it for shifting */ + addb $16, bits_r /* bits += 16 */ + shll %cl, %eax + orl %eax, hold_r /* hold |= *((ushort *)in)++ << bits */ + +.L_get_distance_code: + movl dmask(%esp), %edx /* edx = dmask */ + movl dcode(%esp), %ecx /* ecx = dcode */ + andl hold_r, %edx /* edx &= hold */ + movl (%ecx,%edx,4), %eax /* eax = dcode[hold & dmask] */ + +#define dist_r %edx +.L_dodist: + movl %eax, dist_r /* dist = this */ + shrl $16, dist_r /* dist = this.val */ + movb %ah, %cl + subb %ah, bits_r /* bits -= this.bits */ + shrl %cl, hold_r /* hold >>= this.bits */ + + /* if (op & 16) { + * dist = this.val + * op &= 15 + * if (op > bits) { + * hold |= *((unsigned short *)in)++ << bits; + * bits += 16 + * } + * dist += hold & mask[op]; + * bits -= op; + * hold >>= op; + */ + movb %al, %cl /* cl = this.op */ + + testb $16, %al /* if ((op & 16) == 0) */ + jz .L_test_for_second_level_dist + andb $15, %cl /* op &= 15 */ + jz .L_check_dist_one + cmpb %cl, bits_r + jae .L_add_bits_to_dist /* if (op <= bits) 97.6% */ + + movb %cl, %ch /* stash op in ch, freeing cl */ + xorl %eax, %eax + lodsw /* al = *(ushort *)in++ */ + movb bits_r, %cl /* cl = bits, needs it for shifting */ + addb $16, bits_r /* bits += 16 */ + shll %cl, %eax + orl %eax, hold_r /* hold |= *((ushort *)in)++ << bits */ + movb %ch, %cl /* move op back to ecx */ + +.L_add_bits_to_dist: + movl $1, %eax + shll %cl, %eax + decl %eax /* (1 << op) - 1 */ + subb %cl, bits_r + andl hold_r, %eax /* eax &= hold */ + shrl %cl, hold_r + addl %eax, dist_r /* dist += hold & ((1 << op) - 1) */ + jmp .L_check_window + +.L_check_window: + /* regs: %esi = from, %ebp = hold, %bl = bits, %edi = out, %edx = dist + * %ecx = nbytes + * + * nbytes = out - beg; + * if (dist <= nbytes) { + * from = out - dist; + * do { + * PUP(out) = PUP(from); + * } while (--len > 0) { + * } + */ + + movl in_r, in(%esp) /* save in so from can use it's reg */ + movl out_r, %eax + subl beg(%esp), %eax /* nbytes = out - beg */ + + cmpl dist_r, %eax + jb .L_clip_window /* if (dist > nbytes) 4.2% */ + + movl len(%esp), %ecx + movl out_r, from_r + subl dist_r, from_r /* from = out - dist */ + + subl $3, %ecx + movb (from_r), %al + movb %al, (out_r) + movb 1(from_r), %al + movb 2(from_r), %dl + addl $3, from_r + movb %al, 1(out_r) + movb %dl, 2(out_r) + addl $3, out_r + rep movsb + + movl in(%esp), in_r /* move in back to %esi, toss from */ + jmp .L_while_test + +.align 16,0x90 +.L_check_dist_one: + cmpl $1, dist_r + jne .L_check_window + cmpl out_r, beg(%esp) + je .L_check_window + + decl out_r + movl len(%esp), %ecx + movb (out_r), %al + subl $3, %ecx + + movb %al, 1(out_r) + movb %al, 2(out_r) + movb %al, 3(out_r) + addl $4, out_r + rep stosb + + jmp .L_while_test + +.align 16,0x90 +.L_test_for_second_level_length: + /* else if ((op & 64) == 0) { + * this = lcode[this.val + (hold & mask[op])]; + * } + */ + testb $64, %al + jnz .L_test_for_end_of_block /* if ((op & 64) != 0) */ + + movl $1, %eax + shll %cl, %eax + decl %eax + andl hold_r, %eax /* eax &= hold */ + addl %edx, %eax /* eax += this.val */ + movl lcode(%esp), %edx /* edx = lcode */ + movl (%edx,%eax,4), %eax /* eax = lcode[val + (hold&mask[op])] */ + jmp .L_dolen + +.align 16,0x90 +.L_test_for_second_level_dist: + /* else if ((op & 64) == 0) { + * this = dcode[this.val + (hold & mask[op])]; + * } + */ + testb $64, %al + jnz .L_invalid_distance_code /* if ((op & 64) != 0) */ + + movl $1, %eax + shll %cl, %eax + decl %eax + andl hold_r, %eax /* eax &= hold */ + addl %edx, %eax /* eax += this.val */ + movl dcode(%esp), %edx /* edx = dcode */ + movl (%edx,%eax,4), %eax /* eax = dcode[val + (hold&mask[op])] */ + jmp .L_dodist + +.align 16,0x90 +.L_clip_window: + /* regs: %esi = from, %ebp = hold, %bl = bits, %edi = out, %edx = dist + * %ecx = nbytes + * + * else { + * if (dist > wsize) { + * invalid distance + * } + * from = window; + * nbytes = dist - nbytes; + * if (write == 0) { + * from += wsize - nbytes; + */ +#define nbytes_r %ecx + movl %eax, nbytes_r + movl wsize(%esp), %eax /* prepare for dist compare */ + negl nbytes_r /* nbytes = -nbytes */ + movl window(%esp), from_r /* from = window */ + + cmpl dist_r, %eax + jb .L_invalid_distance_too_far /* if (dist > wsize) */ + + addl dist_r, nbytes_r /* nbytes = dist - nbytes */ + cmpl $0, write(%esp) + jne .L_wrap_around_window /* if (write != 0) */ + + subl nbytes_r, %eax + addl %eax, from_r /* from += wsize - nbytes */ + + /* regs: %esi = from, %ebp = hold, %bl = bits, %edi = out, %edx = dist + * %ecx = nbytes, %eax = len + * + * if (nbytes < len) { + * len -= nbytes; + * do { + * PUP(out) = PUP(from); + * } while (--nbytes); + * from = out - dist; + * } + * } + */ +#define len_r %eax + movl len(%esp), len_r + cmpl nbytes_r, len_r + jbe .L_do_copy1 /* if (nbytes >= len) */ + + subl nbytes_r, len_r /* len -= nbytes */ + rep movsb + movl out_r, from_r + subl dist_r, from_r /* from = out - dist */ + jmp .L_do_copy1 + + cmpl nbytes_r, len_r + jbe .L_do_copy1 /* if (nbytes >= len) */ + + subl nbytes_r, len_r /* len -= nbytes */ + rep movsb + movl out_r, from_r + subl dist_r, from_r /* from = out - dist */ + jmp .L_do_copy1 + +.L_wrap_around_window: + /* regs: %esi = from, %ebp = hold, %bl = bits, %edi = out, %edx = dist + * %ecx = nbytes, %eax = write, %eax = len + * + * else if (write < nbytes) { + * from += wsize + write - nbytes; + * nbytes -= write; + * if (nbytes < len) { + * len -= nbytes; + * do { + * PUP(out) = PUP(from); + * } while (--nbytes); + * from = window; + * nbytes = write; + * if (nbytes < len) { + * len -= nbytes; + * do { + * PUP(out) = PUP(from); + * } while(--nbytes); + * from = out - dist; + * } + * } + * } + */ +#define write_r %eax + movl write(%esp), write_r + cmpl write_r, nbytes_r + jbe .L_contiguous_in_window /* if (write >= nbytes) */ + + addl wsize(%esp), from_r + addl write_r, from_r + subl nbytes_r, from_r /* from += wsize + write - nbytes */ + subl write_r, nbytes_r /* nbytes -= write */ +#undef write_r + + movl len(%esp), len_r + cmpl nbytes_r, len_r + jbe .L_do_copy1 /* if (nbytes >= len) */ + + subl nbytes_r, len_r /* len -= nbytes */ + rep movsb + movl window(%esp), from_r /* from = window */ + movl write(%esp), nbytes_r /* nbytes = write */ + cmpl nbytes_r, len_r + jbe .L_do_copy1 /* if (nbytes >= len) */ + + subl nbytes_r, len_r /* len -= nbytes */ + rep movsb + movl out_r, from_r + subl dist_r, from_r /* from = out - dist */ + jmp .L_do_copy1 + +.L_contiguous_in_window: + /* regs: %esi = from, %ebp = hold, %bl = bits, %edi = out, %edx = dist + * %ecx = nbytes, %eax = write, %eax = len + * + * else { + * from += write - nbytes; + * if (nbytes < len) { + * len -= nbytes; + * do { + * PUP(out) = PUP(from); + * } while (--nbytes); + * from = out - dist; + * } + * } + */ +#define write_r %eax + addl write_r, from_r + subl nbytes_r, from_r /* from += write - nbytes */ +#undef write_r + + movl len(%esp), len_r + cmpl nbytes_r, len_r + jbe .L_do_copy1 /* if (nbytes >= len) */ + + subl nbytes_r, len_r /* len -= nbytes */ + rep movsb + movl out_r, from_r + subl dist_r, from_r /* from = out - dist */ + +.L_do_copy1: + /* regs: %esi = from, %esi = in, %ebp = hold, %bl = bits, %edi = out + * %eax = len + * + * while (len > 0) { + * PUP(out) = PUP(from); + * len--; + * } + * } + * } while (in < last && out < end); + */ +#undef nbytes_r +#define in_r %esi + movl len_r, %ecx + rep movsb + + movl in(%esp), in_r /* move in back to %esi, toss from */ + jmp .L_while_test + +#undef len_r +#undef dist_r + +#endif /* NO_MMX || RUN_TIME_MMX */ + + +/*** MMX code ***/ + +#if defined( USE_MMX ) || defined( RUN_TIME_MMX ) + +.align 32,0x90 +.L_init_mmx: + emms + +#undef bits_r +#undef bitslong_r +#define bitslong_r %ebp +#define hold_mm %mm0 + movd %ebp, hold_mm + movl %ebx, bitslong_r + +#define used_mm %mm1 +#define dmask2_mm %mm2 +#define lmask2_mm %mm3 +#define lmask_mm %mm4 +#define dmask_mm %mm5 +#define tmp_mm %mm6 + + movd lmask(%esp), lmask_mm + movq lmask_mm, lmask2_mm + movd dmask(%esp), dmask_mm + movq dmask_mm, dmask2_mm + pxor used_mm, used_mm + movl lcode(%esp), %ebx /* ebx = lcode */ + jmp .L_do_loop_mmx + +.align 32,0x90 +.L_while_test_mmx: + /* while (in < last && out < end) + */ + cmpl out_r, end(%esp) + jbe .L_break_loop /* if (out >= end) */ + + cmpl in_r, last(%esp) + jbe .L_break_loop + +.L_do_loop_mmx: + psrlq used_mm, hold_mm /* hold_mm >>= last bit length */ + + cmpl $32, bitslong_r + ja .L_get_length_code_mmx /* if (32 < bits) */ + + movd bitslong_r, tmp_mm + movd (in_r), %mm7 + addl $4, in_r + psllq tmp_mm, %mm7 + addl $32, bitslong_r + por %mm7, hold_mm /* hold_mm |= *((uint *)in)++ << bits */ + +.L_get_length_code_mmx: + pand hold_mm, lmask_mm + movd lmask_mm, %eax + movq lmask2_mm, lmask_mm + movl (%ebx,%eax,4), %eax /* eax = lcode[hold & lmask] */ + +.L_dolen_mmx: + movzbl %ah, %ecx /* ecx = this.bits */ + movd %ecx, used_mm + subl %ecx, bitslong_r /* bits -= this.bits */ + + testb %al, %al + jnz .L_test_for_length_base_mmx /* if (op != 0) 45.7% */ + + shrl $16, %eax /* output this.val char */ + stosb + jmp .L_while_test_mmx + +.L_test_for_length_base_mmx: +#define len_r %edx + movl %eax, len_r /* len = this */ + shrl $16, len_r /* len = this.val */ + + testb $16, %al + jz .L_test_for_second_level_length_mmx /* if ((op & 16) == 0) 8% */ + andl $15, %eax /* op &= 15 */ + jz .L_decode_distance_mmx /* if (!op) */ + + psrlq used_mm, hold_mm /* hold_mm >>= last bit length */ + movd %eax, used_mm + movd hold_mm, %ecx + subl %eax, bitslong_r + andl .L_mask(,%eax,4), %ecx + addl %ecx, len_r /* len += hold & mask[op] */ + +.L_decode_distance_mmx: + psrlq used_mm, hold_mm /* hold_mm >>= last bit length */ + + cmpl $32, bitslong_r + ja .L_get_dist_code_mmx /* if (32 < bits) */ + + movd bitslong_r, tmp_mm + movd (in_r), %mm7 + addl $4, in_r + psllq tmp_mm, %mm7 + addl $32, bitslong_r + por %mm7, hold_mm /* hold_mm |= *((uint *)in)++ << bits */ + +.L_get_dist_code_mmx: + movl dcode(%esp), %ebx /* ebx = dcode */ + pand hold_mm, dmask_mm + movd dmask_mm, %eax + movq dmask2_mm, dmask_mm + movl (%ebx,%eax,4), %eax /* eax = dcode[hold & lmask] */ + +.L_dodist_mmx: +#define dist_r %ebx + movzbl %ah, %ecx /* ecx = this.bits */ + movl %eax, dist_r + shrl $16, dist_r /* dist = this.val */ + subl %ecx, bitslong_r /* bits -= this.bits */ + movd %ecx, used_mm + + testb $16, %al /* if ((op & 16) == 0) */ + jz .L_test_for_second_level_dist_mmx + andl $15, %eax /* op &= 15 */ + jz .L_check_dist_one_mmx + +.L_add_bits_to_dist_mmx: + psrlq used_mm, hold_mm /* hold_mm >>= last bit length */ + movd %eax, used_mm /* save bit length of current op */ + movd hold_mm, %ecx /* get the next bits on input stream */ + subl %eax, bitslong_r /* bits -= op bits */ + andl .L_mask(,%eax,4), %ecx /* ecx = hold & mask[op] */ + addl %ecx, dist_r /* dist += hold & mask[op] */ + +.L_check_window_mmx: + movl in_r, in(%esp) /* save in so from can use it's reg */ + movl out_r, %eax + subl beg(%esp), %eax /* nbytes = out - beg */ + + cmpl dist_r, %eax + jb .L_clip_window_mmx /* if (dist > nbytes) 4.2% */ + + movl len_r, %ecx + movl out_r, from_r + subl dist_r, from_r /* from = out - dist */ + + subl $3, %ecx + movb (from_r), %al + movb %al, (out_r) + movb 1(from_r), %al + movb 2(from_r), %dl + addl $3, from_r + movb %al, 1(out_r) + movb %dl, 2(out_r) + addl $3, out_r + rep movsb + + movl in(%esp), in_r /* move in back to %esi, toss from */ + movl lcode(%esp), %ebx /* move lcode back to %ebx, toss dist */ + jmp .L_while_test_mmx + +.align 16,0x90 +.L_check_dist_one_mmx: + cmpl $1, dist_r + jne .L_check_window_mmx + cmpl out_r, beg(%esp) + je .L_check_window_mmx + + decl out_r + movl len_r, %ecx + movb (out_r), %al + subl $3, %ecx + + movb %al, 1(out_r) + movb %al, 2(out_r) + movb %al, 3(out_r) + addl $4, out_r + rep stosb + + movl lcode(%esp), %ebx /* move lcode back to %ebx, toss dist */ + jmp .L_while_test_mmx + +.align 16,0x90 +.L_test_for_second_level_length_mmx: + testb $64, %al + jnz .L_test_for_end_of_block /* if ((op & 64) != 0) */ + + andl $15, %eax + psrlq used_mm, hold_mm /* hold_mm >>= last bit length */ + movd hold_mm, %ecx + andl .L_mask(,%eax,4), %ecx + addl len_r, %ecx + movl (%ebx,%ecx,4), %eax /* eax = lcode[hold & lmask] */ + jmp .L_dolen_mmx + +.align 16,0x90 +.L_test_for_second_level_dist_mmx: + testb $64, %al + jnz .L_invalid_distance_code /* if ((op & 64) != 0) */ + + andl $15, %eax + psrlq used_mm, hold_mm /* hold_mm >>= last bit length */ + movd hold_mm, %ecx + andl .L_mask(,%eax,4), %ecx + movl dcode(%esp), %eax /* ecx = dcode */ + addl dist_r, %ecx + movl (%eax,%ecx,4), %eax /* eax = lcode[hold & lmask] */ + jmp .L_dodist_mmx + +.align 16,0x90 +.L_clip_window_mmx: +#define nbytes_r %ecx + movl %eax, nbytes_r + movl wsize(%esp), %eax /* prepare for dist compare */ + negl nbytes_r /* nbytes = -nbytes */ + movl window(%esp), from_r /* from = window */ + + cmpl dist_r, %eax + jb .L_invalid_distance_too_far /* if (dist > wsize) */ + + addl dist_r, nbytes_r /* nbytes = dist - nbytes */ + cmpl $0, write(%esp) + jne .L_wrap_around_window_mmx /* if (write != 0) */ + + subl nbytes_r, %eax + addl %eax, from_r /* from += wsize - nbytes */ + + cmpl nbytes_r, len_r + jbe .L_do_copy1_mmx /* if (nbytes >= len) */ + + subl nbytes_r, len_r /* len -= nbytes */ + rep movsb + movl out_r, from_r + subl dist_r, from_r /* from = out - dist */ + jmp .L_do_copy1_mmx + + cmpl nbytes_r, len_r + jbe .L_do_copy1_mmx /* if (nbytes >= len) */ + + subl nbytes_r, len_r /* len -= nbytes */ + rep movsb + movl out_r, from_r + subl dist_r, from_r /* from = out - dist */ + jmp .L_do_copy1_mmx + +.L_wrap_around_window_mmx: +#define write_r %eax + movl write(%esp), write_r + cmpl write_r, nbytes_r + jbe .L_contiguous_in_window_mmx /* if (write >= nbytes) */ + + addl wsize(%esp), from_r + addl write_r, from_r + subl nbytes_r, from_r /* from += wsize + write - nbytes */ + subl write_r, nbytes_r /* nbytes -= write */ +#undef write_r + + cmpl nbytes_r, len_r + jbe .L_do_copy1_mmx /* if (nbytes >= len) */ + + subl nbytes_r, len_r /* len -= nbytes */ + rep movsb + movl window(%esp), from_r /* from = window */ + movl write(%esp), nbytes_r /* nbytes = write */ + cmpl nbytes_r, len_r + jbe .L_do_copy1_mmx /* if (nbytes >= len) */ + + subl nbytes_r, len_r /* len -= nbytes */ + rep movsb + movl out_r, from_r + subl dist_r, from_r /* from = out - dist */ + jmp .L_do_copy1_mmx + +.L_contiguous_in_window_mmx: +#define write_r %eax + addl write_r, from_r + subl nbytes_r, from_r /* from += write - nbytes */ +#undef write_r + + cmpl nbytes_r, len_r + jbe .L_do_copy1_mmx /* if (nbytes >= len) */ + + subl nbytes_r, len_r /* len -= nbytes */ + rep movsb + movl out_r, from_r + subl dist_r, from_r /* from = out - dist */ + +.L_do_copy1_mmx: +#undef nbytes_r +#define in_r %esi + movl len_r, %ecx + rep movsb + + movl in(%esp), in_r /* move in back to %esi, toss from */ + movl lcode(%esp), %ebx /* move lcode back to %ebx, toss dist */ + jmp .L_while_test_mmx + +#undef hold_r +#undef bitslong_r + +#endif /* USE_MMX || RUN_TIME_MMX */ + + +/*** USE_MMX, NO_MMX, and RUNTIME_MMX from here on ***/ + +.L_invalid_distance_code: + /* else { + * strm->msg = "invalid distance code"; + * state->mode = BAD; + * } + */ + movl $.L_invalid_distance_code_msg, %ecx + movl $INFLATE_MODE_BAD, %edx + jmp .L_update_stream_state + +.L_test_for_end_of_block: + /* else if (op & 32) { + * state->mode = TYPE; + * break; + * } + */ + testb $32, %al + jz .L_invalid_literal_length_code /* if ((op & 32) == 0) */ + + movl $0, %ecx + movl $INFLATE_MODE_TYPE, %edx + jmp .L_update_stream_state + +.L_invalid_literal_length_code: + /* else { + * strm->msg = "invalid literal/length code"; + * state->mode = BAD; + * } + */ + movl $.L_invalid_literal_length_code_msg, %ecx + movl $INFLATE_MODE_BAD, %edx + jmp .L_update_stream_state + +.L_invalid_distance_too_far: + /* strm->msg = "invalid distance too far back"; + * state->mode = BAD; + */ + movl in(%esp), in_r /* from_r has in's reg, put in back */ + movl $.L_invalid_distance_too_far_msg, %ecx + movl $INFLATE_MODE_BAD, %edx + jmp .L_update_stream_state + +.L_update_stream_state: + /* set strm->msg = %ecx, strm->state->mode = %edx */ + movl strm_sp(%esp), %eax + testl %ecx, %ecx /* if (msg != NULL) */ + jz .L_skip_msg + movl %ecx, msg_strm(%eax) /* strm->msg = msg */ +.L_skip_msg: + movl state_strm(%eax), %eax /* state = strm->state */ + movl %edx, mode_state(%eax) /* state->mode = edx (BAD | TYPE) */ + jmp .L_break_loop + +.align 32,0x90 +.L_break_loop: + +/* + * Regs: + * + * bits = %ebp when mmx, and in %ebx when non-mmx + * hold = %hold_mm when mmx, and in %ebp when non-mmx + * in = %esi + * out = %edi + */ + +#if defined( USE_MMX ) || defined( RUN_TIME_MMX ) + +#if defined( RUN_TIME_MMX ) + + cmpl $DO_USE_MMX, inflate_fast_use_mmx + jne .L_update_next_in + +#endif /* RUN_TIME_MMX */ + + movl %ebp, %ebx + +.L_update_next_in: + +#endif + +#define strm_r %eax +#define state_r %edx + + /* len = bits >> 3; + * in -= len; + * bits -= len << 3; + * hold &= (1U << bits) - 1; + * state->hold = hold; + * state->bits = bits; + * strm->next_in = in; + * strm->next_out = out; + */ + movl strm_sp(%esp), strm_r + movl %ebx, %ecx + movl state_strm(strm_r), state_r + shrl $3, %ecx + subl %ecx, in_r + shll $3, %ecx + subl %ecx, %ebx + movl out_r, next_out_strm(strm_r) + movl %ebx, bits_state(state_r) + movl %ebx, %ecx + + leal buf(%esp), %ebx + cmpl %ebx, last(%esp) + jne .L_buf_not_used /* if buf != last */ + + subl %ebx, in_r /* in -= buf */ + movl next_in_strm(strm_r), %ebx + movl %ebx, last(%esp) /* last = strm->next_in */ + addl %ebx, in_r /* in += strm->next_in */ + movl avail_in_strm(strm_r), %ebx + subl $11, %ebx + addl %ebx, last(%esp) /* last = &strm->next_in[ avail_in - 11 ] */ + +.L_buf_not_used: + movl in_r, next_in_strm(strm_r) + + movl $1, %ebx + shll %cl, %ebx + decl %ebx + +#if defined( USE_MMX ) || defined( RUN_TIME_MMX ) + +#if defined( RUN_TIME_MMX ) + + cmpl $DO_USE_MMX, inflate_fast_use_mmx + jne .L_update_hold + +#endif /* RUN_TIME_MMX */ + + psrlq used_mm, hold_mm /* hold_mm >>= last bit length */ + movd hold_mm, %ebp + + emms + +.L_update_hold: + +#endif /* USE_MMX || RUN_TIME_MMX */ + + andl %ebx, %ebp + movl %ebp, hold_state(state_r) + +#define last_r %ebx + + /* strm->avail_in = in < last ? 11 + (last - in) : 11 - (in - last) */ + movl last(%esp), last_r + cmpl in_r, last_r + jbe .L_last_is_smaller /* if (in >= last) */ + + subl in_r, last_r /* last -= in */ + addl $11, last_r /* last += 11 */ + movl last_r, avail_in_strm(strm_r) + jmp .L_fixup_out +.L_last_is_smaller: + subl last_r, in_r /* in -= last */ + negl in_r /* in = -in */ + addl $11, in_r /* in += 11 */ + movl in_r, avail_in_strm(strm_r) + +#undef last_r +#define end_r %ebx + +.L_fixup_out: + /* strm->avail_out = out < end ? 257 + (end - out) : 257 - (out - end)*/ + movl end(%esp), end_r + cmpl out_r, end_r + jbe .L_end_is_smaller /* if (out >= end) */ + + subl out_r, end_r /* end -= out */ + addl $257, end_r /* end += 257 */ + movl end_r, avail_out_strm(strm_r) + jmp .L_done +.L_end_is_smaller: + subl end_r, out_r /* out -= end */ + negl out_r /* out = -out */ + addl $257, out_r /* out += 257 */ + movl out_r, avail_out_strm(strm_r) + +#undef end_r +#undef strm_r +#undef state_r + +.L_done: + addl $local_var_size, %esp + popf + popl %ebx + popl %ebp + popl %esi + popl %edi + ret + +#if defined( GAS_ELF ) +/* elf info */ +.type inflate_fast,@function +.size inflate_fast,.-inflate_fast +#endif diff --git a/libs/zlib/contrib/iostream/test.cpp b/libs/zlib/contrib/iostream/test.cpp new file mode 100644 index 000000000..7d265b3b5 --- /dev/null +++ b/libs/zlib/contrib/iostream/test.cpp @@ -0,0 +1,24 @@ + +#include "zfstream.h" + +int main() { + + // Construct a stream object with this filebuffer. Anything sent + // to this stream will go to standard out. + gzofstream os( 1, ios::out ); + + // This text is getting compressed and sent to stdout. + // To prove this, run 'test | zcat'. + os << "Hello, Mommy" << endl; + + os << setcompressionlevel( Z_NO_COMPRESSION ); + os << "hello, hello, hi, ho!" << endl; + + setcompressionlevel( os, Z_DEFAULT_COMPRESSION ) + << "I'm compressing again" << endl; + + os.close(); + + return 0; + +} diff --git a/libs/zlib/contrib/iostream/zfstream.cpp b/libs/zlib/contrib/iostream/zfstream.cpp new file mode 100644 index 000000000..d0cd85faa --- /dev/null +++ b/libs/zlib/contrib/iostream/zfstream.cpp @@ -0,0 +1,329 @@ + +#include "zfstream.h" + +gzfilebuf::gzfilebuf() : + file(NULL), + mode(0), + own_file_descriptor(0) +{ } + +gzfilebuf::~gzfilebuf() { + + sync(); + if ( own_file_descriptor ) + close(); + +} + +gzfilebuf *gzfilebuf::open( const char *name, + int io_mode ) { + + if ( is_open() ) + return NULL; + + char char_mode[10]; + char *p = char_mode; + + if ( io_mode & ios::in ) { + mode = ios::in; + *p++ = 'r'; + } else if ( io_mode & ios::app ) { + mode = ios::app; + *p++ = 'a'; + } else { + mode = ios::out; + *p++ = 'w'; + } + + if ( io_mode & ios::binary ) { + mode |= ios::binary; + *p++ = 'b'; + } + + // Hard code the compression level + if ( io_mode & (ios::out|ios::app )) { + *p++ = '9'; + } + + // Put the end-of-string indicator + *p = '\0'; + + if ( (file = gzopen(name, char_mode)) == NULL ) + return NULL; + + own_file_descriptor = 1; + + return this; + +} + +gzfilebuf *gzfilebuf::attach( int file_descriptor, + int io_mode ) { + + if ( is_open() ) + return NULL; + + char char_mode[10]; + char *p = char_mode; + + if ( io_mode & ios::in ) { + mode = ios::in; + *p++ = 'r'; + } else if ( io_mode & ios::app ) { + mode = ios::app; + *p++ = 'a'; + } else { + mode = ios::out; + *p++ = 'w'; + } + + if ( io_mode & ios::binary ) { + mode |= ios::binary; + *p++ = 'b'; + } + + // Hard code the compression level + if ( io_mode & (ios::out|ios::app )) { + *p++ = '9'; + } + + // Put the end-of-string indicator + *p = '\0'; + + if ( (file = gzdopen(file_descriptor, char_mode)) == NULL ) + return NULL; + + own_file_descriptor = 0; + + return this; + +} + +gzfilebuf *gzfilebuf::close() { + + if ( is_open() ) { + + sync(); + gzclose( file ); + file = NULL; + + } + + return this; + +} + +int gzfilebuf::setcompressionlevel( int comp_level ) { + + return gzsetparams(file, comp_level, -2); + +} + +int gzfilebuf::setcompressionstrategy( int comp_strategy ) { + + return gzsetparams(file, -2, comp_strategy); + +} + + +streampos gzfilebuf::seekoff( streamoff off, ios::seek_dir dir, int which ) { + + return streampos(EOF); + +} + +int gzfilebuf::underflow() { + + // If the file hasn't been opened for reading, error. + if ( !is_open() || !(mode & ios::in) ) + return EOF; + + // if a buffer doesn't exists, allocate one. + if ( !base() ) { + + if ( (allocate()) == EOF ) + return EOF; + setp(0,0); + + } else { + + if ( in_avail() ) + return (unsigned char) *gptr(); + + if ( out_waiting() ) { + if ( flushbuf() == EOF ) + return EOF; + } + + } + + // Attempt to fill the buffer. + + int result = fillbuf(); + if ( result == EOF ) { + // disable get area + setg(0,0,0); + return EOF; + } + + return (unsigned char) *gptr(); + +} + +int gzfilebuf::overflow( int c ) { + + if ( !is_open() || !(mode & ios::out) ) + return EOF; + + if ( !base() ) { + if ( allocate() == EOF ) + return EOF; + setg(0,0,0); + } else { + if (in_avail()) { + return EOF; + } + if (out_waiting()) { + if (flushbuf() == EOF) + return EOF; + } + } + + int bl = blen(); + setp( base(), base() + bl); + + if ( c != EOF ) { + + *pptr() = c; + pbump(1); + + } + + return 0; + +} + +int gzfilebuf::sync() { + + if ( !is_open() ) + return EOF; + + if ( out_waiting() ) + return flushbuf(); + + return 0; + +} + +int gzfilebuf::flushbuf() { + + int n; + char *q; + + q = pbase(); + n = pptr() - q; + + if ( gzwrite( file, q, n) < n ) + return EOF; + + setp(0,0); + + return 0; + +} + +int gzfilebuf::fillbuf() { + + int required; + char *p; + + p = base(); + + required = blen(); + + int t = gzread( file, p, required ); + + if ( t <= 0) return EOF; + + setg( base(), base(), base()+t); + + return t; + +} + +gzfilestream_common::gzfilestream_common() : + ios( gzfilestream_common::rdbuf() ) +{ } + +gzfilestream_common::~gzfilestream_common() +{ } + +void gzfilestream_common::attach( int fd, int io_mode ) { + + if ( !buffer.attach( fd, io_mode) ) + clear( ios::failbit | ios::badbit ); + else + clear(); + +} + +void gzfilestream_common::open( const char *name, int io_mode ) { + + if ( !buffer.open( name, io_mode ) ) + clear( ios::failbit | ios::badbit ); + else + clear(); + +} + +void gzfilestream_common::close() { + + if ( !buffer.close() ) + clear( ios::failbit | ios::badbit ); + +} + +gzfilebuf *gzfilestream_common::rdbuf() +{ + return &buffer; +} + +gzifstream::gzifstream() : + ios( gzfilestream_common::rdbuf() ) +{ + clear( ios::badbit ); +} + +gzifstream::gzifstream( const char *name, int io_mode ) : + ios( gzfilestream_common::rdbuf() ) +{ + gzfilestream_common::open( name, io_mode ); +} + +gzifstream::gzifstream( int fd, int io_mode ) : + ios( gzfilestream_common::rdbuf() ) +{ + gzfilestream_common::attach( fd, io_mode ); +} + +gzifstream::~gzifstream() { } + +gzofstream::gzofstream() : + ios( gzfilestream_common::rdbuf() ) +{ + clear( ios::badbit ); +} + +gzofstream::gzofstream( const char *name, int io_mode ) : + ios( gzfilestream_common::rdbuf() ) +{ + gzfilestream_common::open( name, io_mode ); +} + +gzofstream::gzofstream( int fd, int io_mode ) : + ios( gzfilestream_common::rdbuf() ) +{ + gzfilestream_common::attach( fd, io_mode ); +} + +gzofstream::~gzofstream() { } diff --git a/libs/zlib/contrib/iostream/zfstream.h b/libs/zlib/contrib/iostream/zfstream.h new file mode 100644 index 000000000..ed79098a3 --- /dev/null +++ b/libs/zlib/contrib/iostream/zfstream.h @@ -0,0 +1,128 @@ + +#ifndef zfstream_h +#define zfstream_h + +#include +#include "zlib.h" + +class gzfilebuf : public streambuf { + +public: + + gzfilebuf( ); + virtual ~gzfilebuf(); + + gzfilebuf *open( const char *name, int io_mode ); + gzfilebuf *attach( int file_descriptor, int io_mode ); + gzfilebuf *close(); + + int setcompressionlevel( int comp_level ); + int setcompressionstrategy( int comp_strategy ); + + inline int is_open() const { return (file !=NULL); } + + virtual streampos seekoff( streamoff, ios::seek_dir, int ); + + virtual int sync(); + +protected: + + virtual int underflow(); + virtual int overflow( int = EOF ); + +private: + + gzFile file; + short mode; + short own_file_descriptor; + + int flushbuf(); + int fillbuf(); + +}; + +class gzfilestream_common : virtual public ios { + + friend class gzifstream; + friend class gzofstream; + friend gzofstream &setcompressionlevel( gzofstream &, int ); + friend gzofstream &setcompressionstrategy( gzofstream &, int ); + +public: + virtual ~gzfilestream_common(); + + void attach( int fd, int io_mode ); + void open( const char *name, int io_mode ); + void close(); + +protected: + gzfilestream_common(); + +private: + gzfilebuf *rdbuf(); + + gzfilebuf buffer; + +}; + +class gzifstream : public gzfilestream_common, public istream { + +public: + + gzifstream(); + gzifstream( const char *name, int io_mode = ios::in ); + gzifstream( int fd, int io_mode = ios::in ); + + virtual ~gzifstream(); + +}; + +class gzofstream : public gzfilestream_common, public ostream { + +public: + + gzofstream(); + gzofstream( const char *name, int io_mode = ios::out ); + gzofstream( int fd, int io_mode = ios::out ); + + virtual ~gzofstream(); + +}; + +template class gzomanip { + friend gzofstream &operator<<(gzofstream &, const gzomanip &); +public: + gzomanip(gzofstream &(*f)(gzofstream &, T), T v) : func(f), val(v) { } +private: + gzofstream &(*func)(gzofstream &, T); + T val; +}; + +template gzofstream &operator<<(gzofstream &s, const gzomanip &m) +{ + return (*m.func)(s, m.val); +} + +inline gzofstream &setcompressionlevel( gzofstream &s, int l ) +{ + (s.rdbuf())->setcompressionlevel(l); + return s; +} + +inline gzofstream &setcompressionstrategy( gzofstream &s, int l ) +{ + (s.rdbuf())->setcompressionstrategy(l); + return s; +} + +inline gzomanip setcompressionlevel(int l) +{ + return gzomanip(&setcompressionlevel,l); +} + +inline gzomanip setcompressionstrategy(int l) +{ + return gzomanip(&setcompressionstrategy,l); +} + +#endif diff --git a/libs/zlib/contrib/iostream2/zstream.h b/libs/zlib/contrib/iostream2/zstream.h new file mode 100644 index 000000000..43d2332b7 --- /dev/null +++ b/libs/zlib/contrib/iostream2/zstream.h @@ -0,0 +1,307 @@ +/* + * + * Copyright (c) 1997 + * Christian Michelsen Research AS + * Advanced Computing + * Fantoftvegen 38, 5036 BERGEN, Norway + * http://www.cmr.no + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. Christian Michelsen Research AS makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + * + */ + +#ifndef ZSTREAM__H +#define ZSTREAM__H + +/* + * zstream.h - C++ interface to the 'zlib' general purpose compression library + * $Id: zstream.h 1.1 1997-06-25 12:00:56+02 tyge Exp tyge $ + */ + +#include +#include +#include +#include "zlib.h" + +#if defined(_WIN32) +# include +# include +# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY) +#else +# define SET_BINARY_MODE(file) +#endif + +class zstringlen { +public: + zstringlen(class izstream&); + zstringlen(class ozstream&, const char*); + size_t value() const { return val.word; } +private: + struct Val { unsigned char byte; size_t word; } val; +}; + +// ----------------------------- izstream ----------------------------- + +class izstream +{ + public: + izstream() : m_fp(0) {} + izstream(FILE* fp) : m_fp(0) { open(fp); } + izstream(const char* name) : m_fp(0) { open(name); } + ~izstream() { close(); } + + /* Opens a gzip (.gz) file for reading. + * open() can be used to read a file which is not in gzip format; + * in this case read() will directly read from the file without + * decompression. errno can be checked to distinguish two error + * cases (if errno is zero, the zlib error is Z_MEM_ERROR). + */ + void open(const char* name) { + if (m_fp) close(); + m_fp = ::gzopen(name, "rb"); + } + + void open(FILE* fp) { + SET_BINARY_MODE(fp); + if (m_fp) close(); + m_fp = ::gzdopen(fileno(fp), "rb"); + } + + /* Flushes all pending input if necessary, closes the compressed file + * and deallocates all the (de)compression state. The return value is + * the zlib error number (see function error() below). + */ + int close() { + int r = ::gzclose(m_fp); + m_fp = 0; return r; + } + + /* Binary read the given number of bytes from the compressed file. + */ + int read(void* buf, size_t len) { + return ::gzread(m_fp, buf, len); + } + + /* Returns the error message for the last error which occurred on the + * given compressed file. errnum is set to zlib error number. If an + * error occurred in the file system and not in the compression library, + * errnum is set to Z_ERRNO and the application may consult errno + * to get the exact error code. + */ + const char* error(int* errnum) { + return ::gzerror(m_fp, errnum); + } + + gzFile fp() { return m_fp; } + + private: + gzFile m_fp; +}; + +/* + * Binary read the given (array of) object(s) from the compressed file. + * If the input file was not in gzip format, read() copies the objects number + * of bytes into the buffer. + * returns the number of uncompressed bytes actually read + * (0 for end of file, -1 for error). + */ +template +inline int read(izstream& zs, T* x, Items items) { + return ::gzread(zs.fp(), x, items*sizeof(T)); +} + +/* + * Binary input with the '>' operator. + */ +template +inline izstream& operator>(izstream& zs, T& x) { + ::gzread(zs.fp(), &x, sizeof(T)); + return zs; +} + + +inline zstringlen::zstringlen(izstream& zs) { + zs > val.byte; + if (val.byte == 255) zs > val.word; + else val.word = val.byte; +} + +/* + * Read length of string + the string with the '>' operator. + */ +inline izstream& operator>(izstream& zs, char* x) { + zstringlen len(zs); + ::gzread(zs.fp(), x, len.value()); + x[len.value()] = '\0'; + return zs; +} + +inline char* read_string(izstream& zs) { + zstringlen len(zs); + char* x = new char[len.value()+1]; + ::gzread(zs.fp(), x, len.value()); + x[len.value()] = '\0'; + return x; +} + +// ----------------------------- ozstream ----------------------------- + +class ozstream +{ + public: + ozstream() : m_fp(0), m_os(0) { + } + ozstream(FILE* fp, int level = Z_DEFAULT_COMPRESSION) + : m_fp(0), m_os(0) { + open(fp, level); + } + ozstream(const char* name, int level = Z_DEFAULT_COMPRESSION) + : m_fp(0), m_os(0) { + open(name, level); + } + ~ozstream() { + close(); + } + + /* Opens a gzip (.gz) file for writing. + * The compression level parameter should be in 0..9 + * errno can be checked to distinguish two error cases + * (if errno is zero, the zlib error is Z_MEM_ERROR). + */ + void open(const char* name, int level = Z_DEFAULT_COMPRESSION) { + char mode[4] = "wb\0"; + if (level != Z_DEFAULT_COMPRESSION) mode[2] = '0'+level; + if (m_fp) close(); + m_fp = ::gzopen(name, mode); + } + + /* open from a FILE pointer. + */ + void open(FILE* fp, int level = Z_DEFAULT_COMPRESSION) { + SET_BINARY_MODE(fp); + char mode[4] = "wb\0"; + if (level != Z_DEFAULT_COMPRESSION) mode[2] = '0'+level; + if (m_fp) close(); + m_fp = ::gzdopen(fileno(fp), mode); + } + + /* Flushes all pending output if necessary, closes the compressed file + * and deallocates all the (de)compression state. The return value is + * the zlib error number (see function error() below). + */ + int close() { + if (m_os) { + ::gzwrite(m_fp, m_os->str(), m_os->pcount()); + delete[] m_os->str(); delete m_os; m_os = 0; + } + int r = ::gzclose(m_fp); m_fp = 0; return r; + } + + /* Binary write the given number of bytes into the compressed file. + */ + int write(const void* buf, size_t len) { + return ::gzwrite(m_fp, (voidp) buf, len); + } + + /* Flushes all pending output into the compressed file. The parameter + * _flush is as in the deflate() function. The return value is the zlib + * error number (see function gzerror below). flush() returns Z_OK if + * the flush_ parameter is Z_FINISH and all output could be flushed. + * flush() should be called only when strictly necessary because it can + * degrade compression. + */ + int flush(int _flush) { + os_flush(); + return ::gzflush(m_fp, _flush); + } + + /* Returns the error message for the last error which occurred on the + * given compressed file. errnum is set to zlib error number. If an + * error occurred in the file system and not in the compression library, + * errnum is set to Z_ERRNO and the application may consult errno + * to get the exact error code. + */ + const char* error(int* errnum) { + return ::gzerror(m_fp, errnum); + } + + gzFile fp() { return m_fp; } + + ostream& os() { + if (m_os == 0) m_os = new ostrstream; + return *m_os; + } + + void os_flush() { + if (m_os && m_os->pcount()>0) { + ostrstream* oss = new ostrstream; + oss->fill(m_os->fill()); + oss->flags(m_os->flags()); + oss->precision(m_os->precision()); + oss->width(m_os->width()); + ::gzwrite(m_fp, m_os->str(), m_os->pcount()); + delete[] m_os->str(); delete m_os; m_os = oss; + } + } + + private: + gzFile m_fp; + ostrstream* m_os; +}; + +/* + * Binary write the given (array of) object(s) into the compressed file. + * returns the number of uncompressed bytes actually written + * (0 in case of error). + */ +template +inline int write(ozstream& zs, const T* x, Items items) { + return ::gzwrite(zs.fp(), (voidp) x, items*sizeof(T)); +} + +/* + * Binary output with the '<' operator. + */ +template +inline ozstream& operator<(ozstream& zs, const T& x) { + ::gzwrite(zs.fp(), (voidp) &x, sizeof(T)); + return zs; +} + +inline zstringlen::zstringlen(ozstream& zs, const char* x) { + val.byte = 255; val.word = ::strlen(x); + if (val.word < 255) zs < (val.byte = val.word); + else zs < val; +} + +/* + * Write length of string + the string with the '<' operator. + */ +inline ozstream& operator<(ozstream& zs, const char* x) { + zstringlen len(zs, x); + ::gzwrite(zs.fp(), (voidp) x, len.value()); + return zs; +} + +#ifdef _MSC_VER +inline ozstream& operator<(ozstream& zs, char* const& x) { + return zs < (const char*) x; +} +#endif + +/* + * Ascii write with the << operator; + */ +template +inline ostream& operator<<(ozstream& zs, const T& x) { + zs.os_flush(); + return zs.os() << x; +} + +#endif diff --git a/libs/zlib/contrib/iostream2/zstream_test.cpp b/libs/zlib/contrib/iostream2/zstream_test.cpp new file mode 100644 index 000000000..6273f62d6 --- /dev/null +++ b/libs/zlib/contrib/iostream2/zstream_test.cpp @@ -0,0 +1,25 @@ +#include "zstream.h" +#include +#include +#include + +void main() { + char h[256] = "Hello"; + char* g = "Goodbye"; + ozstream out("temp.gz"); + out < "This works well" < h < g; + out.close(); + + izstream in("temp.gz"); // read it back + char *x = read_string(in), *y = new char[256], z[256]; + in > y > z; + in.close(); + cout << x << endl << y << endl << z << endl; + + out.open("temp.gz"); // try ascii output; zcat temp.gz to see the results + out << setw(50) << setfill('#') << setprecision(20) << x << endl << y << endl << z << endl; + out << z << endl << y << endl << x << endl; + out << 1.1234567890123456789 << endl; + + delete[] x; delete[] y; +} diff --git a/libs/zlib/contrib/iostream3/README b/libs/zlib/contrib/iostream3/README new file mode 100644 index 000000000..f7b319ab9 --- /dev/null +++ b/libs/zlib/contrib/iostream3/README @@ -0,0 +1,35 @@ +These classes provide a C++ stream interface to the zlib library. It allows you +to do things like: + + gzofstream outf("blah.gz"); + outf << "These go into the gzip file " << 123 << endl; + +It does this by deriving a specialized stream buffer for gzipped files, which is +the way Stroustrup would have done it. :-> + +The gzifstream and gzofstream classes were originally written by Kevin Ruland +and made available in the zlib contrib/iostream directory. The older version still +compiles under gcc 2.xx, but not under gcc 3.xx, which sparked the development of +this version. + +The new classes are as standard-compliant as possible, closely following the +approach of the standard library's fstream classes. It compiles under gcc versions +3.2 and 3.3, but not under gcc 2.xx. This is mainly due to changes in the standard +library naming scheme. The new version of gzifstream/gzofstream/gzfilebuf differs +from the previous one in the following respects: +- added showmanyc +- added setbuf, with support for unbuffered output via setbuf(0,0) +- a few bug fixes of stream behavior +- gzipped output file opened with default compression level instead of maximum level +- setcompressionlevel()/strategy() members replaced by single setcompression() + +The code is provided "as is", with the permission to use, copy, modify, distribute +and sell it for any purpose without fee. + +Ludwig Schwardt + + +DSP Lab +Electrical & Electronic Engineering Department +University of Stellenbosch +South Africa diff --git a/libs/zlib/contrib/iostream3/TODO b/libs/zlib/contrib/iostream3/TODO new file mode 100644 index 000000000..7032f97be --- /dev/null +++ b/libs/zlib/contrib/iostream3/TODO @@ -0,0 +1,17 @@ +Possible upgrades to gzfilebuf: + +- The ability to do putback (e.g. putbackfail) + +- The ability to seek (zlib supports this, but could be slow/tricky) + +- Simultaneous read/write access (does it make sense?) + +- Support for ios_base::ate open mode + +- Locale support? + +- Check public interface to see which calls give problems + (due to dependence on library internals) + +- Override operator<<(ostream&, gzfilebuf*) to allow direct copying + of stream buffer to stream ( i.e. os << is.rdbuf(); ) diff --git a/libs/zlib/contrib/iostream3/test.cc b/libs/zlib/contrib/iostream3/test.cc new file mode 100644 index 000000000..94235334f --- /dev/null +++ b/libs/zlib/contrib/iostream3/test.cc @@ -0,0 +1,50 @@ +/* + * Test program for gzifstream and gzofstream + * + * by Ludwig Schwardt + * original version by Kevin Ruland + */ + +#include "zfstream.h" +#include // for cout + +int main() { + + gzofstream outf; + gzifstream inf; + char buf[80]; + + outf.open("test1.txt.gz"); + outf << "The quick brown fox sidestepped the lazy canine\n" + << 1.3 << "\nPlan " << 9 << std::endl; + outf.close(); + std::cout << "Wrote the following message to 'test1.txt.gz' (check with zcat or zless):\n" + << "The quick brown fox sidestepped the lazy canine\n" + << 1.3 << "\nPlan " << 9 << std::endl; + + std::cout << "\nReading 'test1.txt.gz' (buffered) produces:\n"; + inf.open("test1.txt.gz"); + while (inf.getline(buf,80,'\n')) { + std::cout << buf << "\t(" << inf.rdbuf()->in_avail() << " chars left in buffer)\n"; + } + inf.close(); + + outf.rdbuf()->pubsetbuf(0,0); + outf.open("test2.txt.gz"); + outf << setcompression(Z_NO_COMPRESSION) + << "The quick brown fox sidestepped the lazy canine\n" + << 1.3 << "\nPlan " << 9 << std::endl; + outf.close(); + std::cout << "\nWrote the same message to 'test2.txt.gz' in uncompressed form"; + + std::cout << "\nReading 'test2.txt.gz' (unbuffered) produces:\n"; + inf.rdbuf()->pubsetbuf(0,0); + inf.open("test2.txt.gz"); + while (inf.getline(buf,80,'\n')) { + std::cout << buf << "\t(" << inf.rdbuf()->in_avail() << " chars left in buffer)\n"; + } + inf.close(); + + return 0; + +} diff --git a/libs/zlib/contrib/iostream3/zfstream.cc b/libs/zlib/contrib/iostream3/zfstream.cc new file mode 100644 index 000000000..94eb93344 --- /dev/null +++ b/libs/zlib/contrib/iostream3/zfstream.cc @@ -0,0 +1,479 @@ +/* + * A C++ I/O streams interface to the zlib gz* functions + * + * by Ludwig Schwardt + * original version by Kevin Ruland + * + * This version is standard-compliant and compatible with gcc 3.x. + */ + +#include "zfstream.h" +#include // for strcpy, strcat, strlen (mode strings) +#include // for BUFSIZ + +// Internal buffer sizes (default and "unbuffered" versions) +#define BIGBUFSIZE BUFSIZ +#define SMALLBUFSIZE 1 + +/*****************************************************************************/ + +// Default constructor +gzfilebuf::gzfilebuf() +: file(NULL), io_mode(std::ios_base::openmode(0)), own_fd(false), + buffer(NULL), buffer_size(BIGBUFSIZE), own_buffer(true) +{ + // No buffers to start with + this->disable_buffer(); +} + +// Destructor +gzfilebuf::~gzfilebuf() +{ + // Sync output buffer and close only if responsible for file + // (i.e. attached streams should be left open at this stage) + this->sync(); + if (own_fd) + this->close(); + // Make sure internal buffer is deallocated + this->disable_buffer(); +} + +// Set compression level and strategy +int +gzfilebuf::setcompression(int comp_level, + int comp_strategy) +{ + return gzsetparams(file, comp_level, comp_strategy); +} + +// Open gzipped file +gzfilebuf* +gzfilebuf::open(const char *name, + std::ios_base::openmode mode) +{ + // Fail if file already open + if (this->is_open()) + return NULL; + // Don't support simultaneous read/write access (yet) + if ((mode & std::ios_base::in) && (mode & std::ios_base::out)) + return NULL; + + // Build mode string for gzopen and check it [27.8.1.3.2] + char char_mode[6] = "\0\0\0\0\0"; + if (!this->open_mode(mode, char_mode)) + return NULL; + + // Attempt to open file + if ((file = gzopen(name, char_mode)) == NULL) + return NULL; + + // On success, allocate internal buffer and set flags + this->enable_buffer(); + io_mode = mode; + own_fd = true; + return this; +} + +// Attach to gzipped file +gzfilebuf* +gzfilebuf::attach(int fd, + std::ios_base::openmode mode) +{ + // Fail if file already open + if (this->is_open()) + return NULL; + // Don't support simultaneous read/write access (yet) + if ((mode & std::ios_base::in) && (mode & std::ios_base::out)) + return NULL; + + // Build mode string for gzdopen and check it [27.8.1.3.2] + char char_mode[6] = "\0\0\0\0\0"; + if (!this->open_mode(mode, char_mode)) + return NULL; + + // Attempt to attach to file + if ((file = gzdopen(fd, char_mode)) == NULL) + return NULL; + + // On success, allocate internal buffer and set flags + this->enable_buffer(); + io_mode = mode; + own_fd = false; + return this; +} + +// Close gzipped file +gzfilebuf* +gzfilebuf::close() +{ + // Fail immediately if no file is open + if (!this->is_open()) + return NULL; + // Assume success + gzfilebuf* retval = this; + // Attempt to sync and close gzipped file + if (this->sync() == -1) + retval = NULL; + if (gzclose(file) < 0) + retval = NULL; + // File is now gone anyway (postcondition [27.8.1.3.8]) + file = NULL; + own_fd = false; + // Destroy internal buffer if it exists + this->disable_buffer(); + return retval; +} + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +// Convert int open mode to mode string +bool +gzfilebuf::open_mode(std::ios_base::openmode mode, + char* c_mode) const +{ + bool testb = mode & std::ios_base::binary; + bool testi = mode & std::ios_base::in; + bool testo = mode & std::ios_base::out; + bool testt = mode & std::ios_base::trunc; + bool testa = mode & std::ios_base::app; + + // Check for valid flag combinations - see [27.8.1.3.2] (Table 92) + // Original zfstream hardcoded the compression level to maximum here... + // Double the time for less than 1% size improvement seems + // excessive though - keeping it at the default level + // To change back, just append "9" to the next three mode strings + if (!testi && testo && !testt && !testa) + strcpy(c_mode, "w"); + if (!testi && testo && !testt && testa) + strcpy(c_mode, "a"); + if (!testi && testo && testt && !testa) + strcpy(c_mode, "w"); + if (testi && !testo && !testt && !testa) + strcpy(c_mode, "r"); + // No read/write mode yet +// if (testi && testo && !testt && !testa) +// strcpy(c_mode, "r+"); +// if (testi && testo && testt && !testa) +// strcpy(c_mode, "w+"); + + // Mode string should be empty for invalid combination of flags + if (strlen(c_mode) == 0) + return false; + if (testb) + strcat(c_mode, "b"); + return true; +} + +// Determine number of characters in internal get buffer +std::streamsize +gzfilebuf::showmanyc() +{ + // Calls to underflow will fail if file not opened for reading + if (!this->is_open() || !(io_mode & std::ios_base::in)) + return -1; + // Make sure get area is in use + if (this->gptr() && (this->gptr() < this->egptr())) + return std::streamsize(this->egptr() - this->gptr()); + else + return 0; +} + +// Fill get area from gzipped file +gzfilebuf::int_type +gzfilebuf::underflow() +{ + // If something is left in the get area by chance, return it + // (this shouldn't normally happen, as underflow is only supposed + // to be called when gptr >= egptr, but it serves as error check) + if (this->gptr() && (this->gptr() < this->egptr())) + return traits_type::to_int_type(*(this->gptr())); + + // If the file hasn't been opened for reading, produce error + if (!this->is_open() || !(io_mode & std::ios_base::in)) + return traits_type::eof(); + + // Attempt to fill internal buffer from gzipped file + // (buffer must be guaranteed to exist...) + int bytes_read = gzread(file, buffer, buffer_size); + // Indicates error or EOF + if (bytes_read <= 0) + { + // Reset get area + this->setg(buffer, buffer, buffer); + return traits_type::eof(); + } + // Make all bytes read from file available as get area + this->setg(buffer, buffer, buffer + bytes_read); + + // Return next character in get area + return traits_type::to_int_type(*(this->gptr())); +} + +// Write put area to gzipped file +gzfilebuf::int_type +gzfilebuf::overflow(int_type c) +{ + // Determine whether put area is in use + if (this->pbase()) + { + // Double-check pointer range + if (this->pptr() > this->epptr() || this->pptr() < this->pbase()) + return traits_type::eof(); + // Add extra character to buffer if not EOF + if (!traits_type::eq_int_type(c, traits_type::eof())) + { + *(this->pptr()) = traits_type::to_char_type(c); + this->pbump(1); + } + // Number of characters to write to file + int bytes_to_write = this->pptr() - this->pbase(); + // Overflow doesn't fail if nothing is to be written + if (bytes_to_write > 0) + { + // If the file hasn't been opened for writing, produce error + if (!this->is_open() || !(io_mode & std::ios_base::out)) + return traits_type::eof(); + // If gzipped file won't accept all bytes written to it, fail + if (gzwrite(file, this->pbase(), bytes_to_write) != bytes_to_write) + return traits_type::eof(); + // Reset next pointer to point to pbase on success + this->pbump(-bytes_to_write); + } + } + // Write extra character to file if not EOF + else if (!traits_type::eq_int_type(c, traits_type::eof())) + { + // If the file hasn't been opened for writing, produce error + if (!this->is_open() || !(io_mode & std::ios_base::out)) + return traits_type::eof(); + // Impromptu char buffer (allows "unbuffered" output) + char_type last_char = traits_type::to_char_type(c); + // If gzipped file won't accept this character, fail + if (gzwrite(file, &last_char, 1) != 1) + return traits_type::eof(); + } + + // If you got here, you have succeeded (even if c was EOF) + // The return value should therefore be non-EOF + if (traits_type::eq_int_type(c, traits_type::eof())) + return traits_type::not_eof(c); + else + return c; +} + +// Assign new buffer +std::streambuf* +gzfilebuf::setbuf(char_type* p, + std::streamsize n) +{ + // First make sure stuff is sync'ed, for safety + if (this->sync() == -1) + return NULL; + // If buffering is turned off on purpose via setbuf(0,0), still allocate one... + // "Unbuffered" only really refers to put [27.8.1.4.10], while get needs at + // least a buffer of size 1 (very inefficient though, therefore make it bigger?) + // This follows from [27.5.2.4.3]/12 (gptr needs to point at something, it seems) + if (!p || !n) + { + // Replace existing buffer (if any) with small internal buffer + this->disable_buffer(); + buffer = NULL; + buffer_size = 0; + own_buffer = true; + this->enable_buffer(); + } + else + { + // Replace existing buffer (if any) with external buffer + this->disable_buffer(); + buffer = p; + buffer_size = n; + own_buffer = false; + this->enable_buffer(); + } + return this; +} + +// Write put area to gzipped file (i.e. ensures that put area is empty) +int +gzfilebuf::sync() +{ + return traits_type::eq_int_type(this->overflow(), traits_type::eof()) ? -1 : 0; +} + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +// Allocate internal buffer +void +gzfilebuf::enable_buffer() +{ + // If internal buffer required, allocate one + if (own_buffer && !buffer) + { + // Check for buffered vs. "unbuffered" + if (buffer_size > 0) + { + // Allocate internal buffer + buffer = new char_type[buffer_size]; + // Get area starts empty and will be expanded by underflow as need arises + this->setg(buffer, buffer, buffer); + // Setup entire internal buffer as put area. + // The one-past-end pointer actually points to the last element of the buffer, + // so that overflow(c) can safely add the extra character c to the sequence. + // These pointers remain in place for the duration of the buffer + this->setp(buffer, buffer + buffer_size - 1); + } + else + { + // Even in "unbuffered" case, (small?) get buffer is still required + buffer_size = SMALLBUFSIZE; + buffer = new char_type[buffer_size]; + this->setg(buffer, buffer, buffer); + // "Unbuffered" means no put buffer + this->setp(0, 0); + } + } + else + { + // If buffer already allocated, reset buffer pointers just to make sure no + // stale chars are lying around + this->setg(buffer, buffer, buffer); + this->setp(buffer, buffer + buffer_size - 1); + } +} + +// Destroy internal buffer +void +gzfilebuf::disable_buffer() +{ + // If internal buffer exists, deallocate it + if (own_buffer && buffer) + { + // Preserve unbuffered status by zeroing size + if (!this->pbase()) + buffer_size = 0; + delete[] buffer; + buffer = NULL; + this->setg(0, 0, 0); + this->setp(0, 0); + } + else + { + // Reset buffer pointers to initial state if external buffer exists + this->setg(buffer, buffer, buffer); + if (buffer) + this->setp(buffer, buffer + buffer_size - 1); + else + this->setp(0, 0); + } +} + +/*****************************************************************************/ + +// Default constructor initializes stream buffer +gzifstream::gzifstream() +: std::istream(NULL), sb() +{ this->init(&sb); } + +// Initialize stream buffer and open file +gzifstream::gzifstream(const char* name, + std::ios_base::openmode mode) +: std::istream(NULL), sb() +{ + this->init(&sb); + this->open(name, mode); +} + +// Initialize stream buffer and attach to file +gzifstream::gzifstream(int fd, + std::ios_base::openmode mode) +: std::istream(NULL), sb() +{ + this->init(&sb); + this->attach(fd, mode); +} + +// Open file and go into fail() state if unsuccessful +void +gzifstream::open(const char* name, + std::ios_base::openmode mode) +{ + if (!sb.open(name, mode | std::ios_base::in)) + this->setstate(std::ios_base::failbit); + else + this->clear(); +} + +// Attach to file and go into fail() state if unsuccessful +void +gzifstream::attach(int fd, + std::ios_base::openmode mode) +{ + if (!sb.attach(fd, mode | std::ios_base::in)) + this->setstate(std::ios_base::failbit); + else + this->clear(); +} + +// Close file +void +gzifstream::close() +{ + if (!sb.close()) + this->setstate(std::ios_base::failbit); +} + +/*****************************************************************************/ + +// Default constructor initializes stream buffer +gzofstream::gzofstream() +: std::ostream(NULL), sb() +{ this->init(&sb); } + +// Initialize stream buffer and open file +gzofstream::gzofstream(const char* name, + std::ios_base::openmode mode) +: std::ostream(NULL), sb() +{ + this->init(&sb); + this->open(name, mode); +} + +// Initialize stream buffer and attach to file +gzofstream::gzofstream(int fd, + std::ios_base::openmode mode) +: std::ostream(NULL), sb() +{ + this->init(&sb); + this->attach(fd, mode); +} + +// Open file and go into fail() state if unsuccessful +void +gzofstream::open(const char* name, + std::ios_base::openmode mode) +{ + if (!sb.open(name, mode | std::ios_base::out)) + this->setstate(std::ios_base::failbit); + else + this->clear(); +} + +// Attach to file and go into fail() state if unsuccessful +void +gzofstream::attach(int fd, + std::ios_base::openmode mode) +{ + if (!sb.attach(fd, mode | std::ios_base::out)) + this->setstate(std::ios_base::failbit); + else + this->clear(); +} + +// Close file +void +gzofstream::close() +{ + if (!sb.close()) + this->setstate(std::ios_base::failbit); +} diff --git a/libs/zlib/contrib/iostream3/zfstream.h b/libs/zlib/contrib/iostream3/zfstream.h new file mode 100644 index 000000000..8574479ae --- /dev/null +++ b/libs/zlib/contrib/iostream3/zfstream.h @@ -0,0 +1,466 @@ +/* + * A C++ I/O streams interface to the zlib gz* functions + * + * by Ludwig Schwardt + * original version by Kevin Ruland + * + * This version is standard-compliant and compatible with gcc 3.x. + */ + +#ifndef ZFSTREAM_H +#define ZFSTREAM_H + +#include // not iostream, since we don't need cin/cout +#include +#include "zlib.h" + +/*****************************************************************************/ + +/** + * @brief Gzipped file stream buffer class. + * + * This class implements basic_filebuf for gzipped files. It doesn't yet support + * seeking (allowed by zlib but slow/limited), putback and read/write access + * (tricky). Otherwise, it attempts to be a drop-in replacement for the standard + * file streambuf. +*/ +class gzfilebuf : public std::streambuf +{ +public: + // Default constructor. + gzfilebuf(); + + // Destructor. + virtual + ~gzfilebuf(); + + /** + * @brief Set compression level and strategy on the fly. + * @param comp_level Compression level (see zlib.h for allowed values) + * @param comp_strategy Compression strategy (see zlib.h for allowed values) + * @return Z_OK on success, Z_STREAM_ERROR otherwise. + * + * Unfortunately, these parameters cannot be modified separately, as the + * previous zfstream version assumed. Since the strategy is seldom changed, + * it can default and setcompression(level) then becomes like the old + * setcompressionlevel(level). + */ + int + setcompression(int comp_level, + int comp_strategy = Z_DEFAULT_STRATEGY); + + /** + * @brief Check if file is open. + * @return True if file is open. + */ + bool + is_open() const { return (file != NULL); } + + /** + * @brief Open gzipped file. + * @param name File name. + * @param mode Open mode flags. + * @return @c this on success, NULL on failure. + */ + gzfilebuf* + open(const char* name, + std::ios_base::openmode mode); + + /** + * @brief Attach to already open gzipped file. + * @param fd File descriptor. + * @param mode Open mode flags. + * @return @c this on success, NULL on failure. + */ + gzfilebuf* + attach(int fd, + std::ios_base::openmode mode); + + /** + * @brief Close gzipped file. + * @return @c this on success, NULL on failure. + */ + gzfilebuf* + close(); + +protected: + /** + * @brief Convert ios open mode int to mode string used by zlib. + * @return True if valid mode flag combination. + */ + bool + open_mode(std::ios_base::openmode mode, + char* c_mode) const; + + /** + * @brief Number of characters available in stream buffer. + * @return Number of characters. + * + * This indicates number of characters in get area of stream buffer. + * These characters can be read without accessing the gzipped file. + */ + virtual std::streamsize + showmanyc(); + + /** + * @brief Fill get area from gzipped file. + * @return First character in get area on success, EOF on error. + * + * This actually reads characters from gzipped file to stream + * buffer. Always buffered. + */ + virtual int_type + underflow(); + + /** + * @brief Write put area to gzipped file. + * @param c Extra character to add to buffer contents. + * @return Non-EOF on success, EOF on error. + * + * This actually writes characters in stream buffer to + * gzipped file. With unbuffered output this is done one + * character at a time. + */ + virtual int_type + overflow(int_type c = traits_type::eof()); + + /** + * @brief Installs external stream buffer. + * @param p Pointer to char buffer. + * @param n Size of external buffer. + * @return @c this on success, NULL on failure. + * + * Call setbuf(0,0) to enable unbuffered output. + */ + virtual std::streambuf* + setbuf(char_type* p, + std::streamsize n); + + /** + * @brief Flush stream buffer to file. + * @return 0 on success, -1 on error. + * + * This calls underflow(EOF) to do the job. + */ + virtual int + sync(); + +// +// Some future enhancements +// +// virtual int_type uflow(); +// virtual int_type pbackfail(int_type c = traits_type::eof()); +// virtual pos_type +// seekoff(off_type off, +// std::ios_base::seekdir way, +// std::ios_base::openmode mode = std::ios_base::in|std::ios_base::out); +// virtual pos_type +// seekpos(pos_type sp, +// std::ios_base::openmode mode = std::ios_base::in|std::ios_base::out); + +private: + /** + * @brief Allocate internal buffer. + * + * This function is safe to call multiple times. It will ensure + * that a proper internal buffer exists if it is required. If the + * buffer already exists or is external, the buffer pointers will be + * reset to their original state. + */ + void + enable_buffer(); + + /** + * @brief Destroy internal buffer. + * + * This function is safe to call multiple times. It will ensure + * that the internal buffer is deallocated if it exists. In any + * case, it will also reset the buffer pointers. + */ + void + disable_buffer(); + + /** + * Underlying file pointer. + */ + gzFile file; + + /** + * Mode in which file was opened. + */ + std::ios_base::openmode io_mode; + + /** + * @brief True if this object owns file descriptor. + * + * This makes the class responsible for closing the file + * upon destruction. + */ + bool own_fd; + + /** + * @brief Stream buffer. + * + * For simplicity this remains allocated on the free store for the + * entire life span of the gzfilebuf object, unless replaced by setbuf. + */ + char_type* buffer; + + /** + * @brief Stream buffer size. + * + * Defaults to system default buffer size (typically 8192 bytes). + * Modified by setbuf. + */ + std::streamsize buffer_size; + + /** + * @brief True if this object owns stream buffer. + * + * This makes the class responsible for deleting the buffer + * upon destruction. + */ + bool own_buffer; +}; + +/*****************************************************************************/ + +/** + * @brief Gzipped file input stream class. + * + * This class implements ifstream for gzipped files. Seeking and putback + * is not supported yet. +*/ +class gzifstream : public std::istream +{ +public: + // Default constructor + gzifstream(); + + /** + * @brief Construct stream on gzipped file to be opened. + * @param name File name. + * @param mode Open mode flags (forced to contain ios::in). + */ + explicit + gzifstream(const char* name, + std::ios_base::openmode mode = std::ios_base::in); + + /** + * @brief Construct stream on already open gzipped file. + * @param fd File descriptor. + * @param mode Open mode flags (forced to contain ios::in). + */ + explicit + gzifstream(int fd, + std::ios_base::openmode mode = std::ios_base::in); + + /** + * Obtain underlying stream buffer. + */ + gzfilebuf* + rdbuf() const + { return const_cast(&sb); } + + /** + * @brief Check if file is open. + * @return True if file is open. + */ + bool + is_open() { return sb.is_open(); } + + /** + * @brief Open gzipped file. + * @param name File name. + * @param mode Open mode flags (forced to contain ios::in). + * + * Stream will be in state good() if file opens successfully; + * otherwise in state fail(). This differs from the behavior of + * ifstream, which never sets the state to good() and therefore + * won't allow you to reuse the stream for a second file unless + * you manually clear() the state. The choice is a matter of + * convenience. + */ + void + open(const char* name, + std::ios_base::openmode mode = std::ios_base::in); + + /** + * @brief Attach to already open gzipped file. + * @param fd File descriptor. + * @param mode Open mode flags (forced to contain ios::in). + * + * Stream will be in state good() if attach succeeded; otherwise + * in state fail(). + */ + void + attach(int fd, + std::ios_base::openmode mode = std::ios_base::in); + + /** + * @brief Close gzipped file. + * + * Stream will be in state fail() if close failed. + */ + void + close(); + +private: + /** + * Underlying stream buffer. + */ + gzfilebuf sb; +}; + +/*****************************************************************************/ + +/** + * @brief Gzipped file output stream class. + * + * This class implements ofstream for gzipped files. Seeking and putback + * is not supported yet. +*/ +class gzofstream : public std::ostream +{ +public: + // Default constructor + gzofstream(); + + /** + * @brief Construct stream on gzipped file to be opened. + * @param name File name. + * @param mode Open mode flags (forced to contain ios::out). + */ + explicit + gzofstream(const char* name, + std::ios_base::openmode mode = std::ios_base::out); + + /** + * @brief Construct stream on already open gzipped file. + * @param fd File descriptor. + * @param mode Open mode flags (forced to contain ios::out). + */ + explicit + gzofstream(int fd, + std::ios_base::openmode mode = std::ios_base::out); + + /** + * Obtain underlying stream buffer. + */ + gzfilebuf* + rdbuf() const + { return const_cast(&sb); } + + /** + * @brief Check if file is open. + * @return True if file is open. + */ + bool + is_open() { return sb.is_open(); } + + /** + * @brief Open gzipped file. + * @param name File name. + * @param mode Open mode flags (forced to contain ios::out). + * + * Stream will be in state good() if file opens successfully; + * otherwise in state fail(). This differs from the behavior of + * ofstream, which never sets the state to good() and therefore + * won't allow you to reuse the stream for a second file unless + * you manually clear() the state. The choice is a matter of + * convenience. + */ + void + open(const char* name, + std::ios_base::openmode mode = std::ios_base::out); + + /** + * @brief Attach to already open gzipped file. + * @param fd File descriptor. + * @param mode Open mode flags (forced to contain ios::out). + * + * Stream will be in state good() if attach succeeded; otherwise + * in state fail(). + */ + void + attach(int fd, + std::ios_base::openmode mode = std::ios_base::out); + + /** + * @brief Close gzipped file. + * + * Stream will be in state fail() if close failed. + */ + void + close(); + +private: + /** + * Underlying stream buffer. + */ + gzfilebuf sb; +}; + +/*****************************************************************************/ + +/** + * @brief Gzipped file output stream manipulator class. + * + * This class defines a two-argument manipulator for gzofstream. It is used + * as base for the setcompression(int,int) manipulator. +*/ +template + class gzomanip2 + { + public: + // Allows insertor to peek at internals + template + friend gzofstream& + operator<<(gzofstream&, + const gzomanip2&); + + // Constructor + gzomanip2(gzofstream& (*f)(gzofstream&, T1, T2), + T1 v1, + T2 v2); + private: + // Underlying manipulator function + gzofstream& + (*func)(gzofstream&, T1, T2); + + // Arguments for manipulator function + T1 val1; + T2 val2; + }; + +/*****************************************************************************/ + +// Manipulator function thunks through to stream buffer +inline gzofstream& +setcompression(gzofstream &gzs, int l, int s = Z_DEFAULT_STRATEGY) +{ + (gzs.rdbuf())->setcompression(l, s); + return gzs; +} + +// Manipulator constructor stores arguments +template + inline + gzomanip2::gzomanip2(gzofstream &(*f)(gzofstream &, T1, T2), + T1 v1, + T2 v2) + : func(f), val1(v1), val2(v2) + { } + +// Insertor applies underlying manipulator function to stream +template + inline gzofstream& + operator<<(gzofstream& s, const gzomanip2& m) + { return (*m.func)(s, m.val1, m.val2); } + +// Insert this onto stream to simplify setting of compression level +inline gzomanip2 +setcompression(int l, int s = Z_DEFAULT_STRATEGY) +{ return gzomanip2(&setcompression, l, s); } + +#endif // ZFSTREAM_H diff --git a/libs/zlib/contrib/masmx64/bld_ml64.bat b/libs/zlib/contrib/masmx64/bld_ml64.bat new file mode 100644 index 000000000..8f9343d0a --- /dev/null +++ b/libs/zlib/contrib/masmx64/bld_ml64.bat @@ -0,0 +1,2 @@ +ml64.exe /Flinffasx64 /c /Zi inffasx64.asm +ml64.exe /Flgvmat64 /c /Zi gvmat64.asm diff --git a/libs/zlib/contrib/masmx64/gvmat64.asm b/libs/zlib/contrib/masmx64/gvmat64.asm new file mode 100644 index 000000000..c1817f1be --- /dev/null +++ b/libs/zlib/contrib/masmx64/gvmat64.asm @@ -0,0 +1,553 @@ +;uInt longest_match_x64( +; deflate_state *s, +; IPos cur_match); /* current match */ + +; gvmat64.asm -- Asm portion of the optimized longest_match for 32 bits x86_64 +; (AMD64 on Athlon 64, Opteron, Phenom +; and Intel EM64T on Pentium 4 with EM64T, Pentium D, Core 2 Duo, Core I5/I7) +; Copyright (C) 1995-2010 Jean-loup Gailly, Brian Raiter and Gilles Vollant. +; +; File written by Gilles Vollant, by converting to assembly the longest_match +; from Jean-loup Gailly in deflate.c of zLib and infoZip zip. +; +; and by taking inspiration on asm686 with masm, optimised assembly code +; from Brian Raiter, written 1998 +; +; This software is provided 'as-is', without any express or implied +; warranty. In no event will the authors be held liable for any damages +; arising from the use of this software. +; +; Permission is granted to anyone to use this software for any purpose, +; including commercial applications, and to alter it and redistribute it +; freely, subject to the following restrictions: +; +; 1. The origin of this software must not be misrepresented; you must not +; claim that you wrote the original software. If you use this software +; in a product, an acknowledgment in the product documentation would be +; appreciated but is not required. +; 2. Altered source versions must be plainly marked as such, and must not be +; misrepresented as being the original software +; 3. This notice may not be removed or altered from any source distribution. +; +; +; +; http://www.zlib.net +; http://www.winimage.com/zLibDll +; http://www.muppetlabs.com/~breadbox/software/assembly.html +; +; to compile this file for infozip Zip, I use option: +; ml64.exe /Flgvmat64 /c /Zi /DINFOZIP gvmat64.asm +; +; to compile this file for zLib, I use option: +; ml64.exe /Flgvmat64 /c /Zi gvmat64.asm +; Be carrefull to adapt zlib1222add below to your version of zLib +; (if you use a version of zLib before 1.0.4 or after 1.2.2.2, change +; value of zlib1222add later) +; +; This file compile with Microsoft Macro Assembler (x64) for AMD64 +; +; ml64.exe is given with Visual Studio 2005/2008/2010 and Windows WDK +; +; (you can get Windows WDK with ml64 for AMD64 from +; http://www.microsoft.com/whdc/Devtools/wdk/default.mspx for low price) +; + + +;uInt longest_match(s, cur_match) +; deflate_state *s; +; IPos cur_match; /* current match */ +.code +longest_match PROC + + +;LocalVarsSize equ 88 + LocalVarsSize equ 72 + +; register used : rax,rbx,rcx,rdx,rsi,rdi,r8,r9,r10,r11,r12 +; free register : r14,r15 +; register can be saved : rsp + + chainlenwmask equ rsp + 8 - LocalVarsSize ; high word: current chain len + ; low word: s->wmask +;window equ rsp + xx - LocalVarsSize ; local copy of s->window ; stored in r10 +;windowbestlen equ rsp + xx - LocalVarsSize ; s->window + bestlen , use r10+r11 +;scanstart equ rsp + xx - LocalVarsSize ; first two bytes of string ; stored in r12w +;scanend equ rsp + xx - LocalVarsSize ; last two bytes of string use ebx +;scanalign equ rsp + xx - LocalVarsSize ; dword-misalignment of string r13 +;bestlen equ rsp + xx - LocalVarsSize ; size of best match so far -> r11d +;scan equ rsp + xx - LocalVarsSize ; ptr to string wanting match -> r9 +IFDEF INFOZIP +ELSE + nicematch equ (rsp + 16 - LocalVarsSize) ; a good enough match size +ENDIF + +save_rdi equ rsp + 24 - LocalVarsSize +save_rsi equ rsp + 32 - LocalVarsSize +save_rbx equ rsp + 40 - LocalVarsSize +save_rbp equ rsp + 48 - LocalVarsSize +save_r12 equ rsp + 56 - LocalVarsSize +save_r13 equ rsp + 64 - LocalVarsSize +;save_r14 equ rsp + 72 - LocalVarsSize +;save_r15 equ rsp + 80 - LocalVarsSize + + +; summary of register usage +; scanend ebx +; scanendw bx +; chainlenwmask edx +; curmatch rsi +; curmatchd esi +; windowbestlen r8 +; scanalign r9 +; scanalignd r9d +; window r10 +; bestlen r11 +; bestlend r11d +; scanstart r12d +; scanstartw r12w +; scan r13 +; nicematch r14d +; limit r15 +; limitd r15d +; prev rcx + +; all the +4 offsets are due to the addition of pending_buf_size (in zlib +; in the deflate_state structure since the asm code was first written +; (if you compile with zlib 1.0.4 or older, remove the +4). +; Note : these value are good with a 8 bytes boundary pack structure + + + MAX_MATCH equ 258 + MIN_MATCH equ 3 + MIN_LOOKAHEAD equ (MAX_MATCH+MIN_MATCH+1) + + +;;; Offsets for fields in the deflate_state structure. These numbers +;;; are calculated from the definition of deflate_state, with the +;;; assumption that the compiler will dword-align the fields. (Thus, +;;; changing the definition of deflate_state could easily cause this +;;; program to crash horribly, without so much as a warning at +;;; compile time. Sigh.) + +; all the +zlib1222add offsets are due to the addition of fields +; in zlib in the deflate_state structure since the asm code was first written +; (if you compile with zlib 1.0.4 or older, use "zlib1222add equ (-4)"). +; (if you compile with zlib between 1.0.5 and 1.2.2.1, use "zlib1222add equ 0"). +; if you compile with zlib 1.2.2.2 or later , use "zlib1222add equ 8"). + + +IFDEF INFOZIP + +_DATA SEGMENT +COMM window_size:DWORD +; WMask ; 7fff +COMM window:BYTE:010040H +COMM prev:WORD:08000H +; MatchLen : unused +; PrevMatch : unused +COMM strstart:DWORD +COMM match_start:DWORD +; Lookahead : ignore +COMM prev_length:DWORD ; PrevLen +COMM max_chain_length:DWORD +COMM good_match:DWORD +COMM nice_match:DWORD +prev_ad equ OFFSET prev +window_ad equ OFFSET window +nicematch equ nice_match +_DATA ENDS +WMask equ 07fffh + +ELSE + + IFNDEF zlib1222add + zlib1222add equ 8 + ENDIF +dsWSize equ 56+zlib1222add+(zlib1222add/2) +dsWMask equ 64+zlib1222add+(zlib1222add/2) +dsWindow equ 72+zlib1222add +dsPrev equ 88+zlib1222add +dsMatchLen equ 128+zlib1222add +dsPrevMatch equ 132+zlib1222add +dsStrStart equ 140+zlib1222add +dsMatchStart equ 144+zlib1222add +dsLookahead equ 148+zlib1222add +dsPrevLen equ 152+zlib1222add +dsMaxChainLen equ 156+zlib1222add +dsGoodMatch equ 172+zlib1222add +dsNiceMatch equ 176+zlib1222add + +window_size equ [ rcx + dsWSize] +WMask equ [ rcx + dsWMask] +window_ad equ [ rcx + dsWindow] +prev_ad equ [ rcx + dsPrev] +strstart equ [ rcx + dsStrStart] +match_start equ [ rcx + dsMatchStart] +Lookahead equ [ rcx + dsLookahead] ; 0ffffffffh on infozip +prev_length equ [ rcx + dsPrevLen] +max_chain_length equ [ rcx + dsMaxChainLen] +good_match equ [ rcx + dsGoodMatch] +nice_match equ [ rcx + dsNiceMatch] +ENDIF + +; parameter 1 in r8(deflate state s), param 2 in rdx (cur match) + +; see http://weblogs.asp.net/oldnewthing/archive/2004/01/14/58579.aspx and +; http://msdn.microsoft.com/library/en-us/kmarch/hh/kmarch/64bitAMD_8e951dd2-ee77-4728-8702-55ce4b5dd24a.xml.asp +; +; All registers must be preserved across the call, except for +; rax, rcx, rdx, r8, r9, r10, and r11, which are scratch. + + + +;;; Save registers that the compiler may be using, and adjust esp to +;;; make room for our stack frame. + + +;;; Retrieve the function arguments. r8d will hold cur_match +;;; throughout the entire function. edx will hold the pointer to the +;;; deflate_state structure during the function's setup (before +;;; entering the main loop. + +; parameter 1 in rcx (deflate_state* s), param 2 in edx -> r8 (cur match) + +; this clear high 32 bits of r8, which can be garbage in both r8 and rdx + + mov [save_rdi],rdi + mov [save_rsi],rsi + mov [save_rbx],rbx + mov [save_rbp],rbp +IFDEF INFOZIP + mov r8d,ecx +ELSE + mov r8d,edx +ENDIF + mov [save_r12],r12 + mov [save_r13],r13 +; mov [save_r14],r14 +; mov [save_r15],r15 + + +;;; uInt wmask = s->w_mask; +;;; unsigned chain_length = s->max_chain_length; +;;; if (s->prev_length >= s->good_match) { +;;; chain_length >>= 2; +;;; } + + mov edi, prev_length + mov esi, good_match + mov eax, WMask + mov ebx, max_chain_length + cmp edi, esi + jl LastMatchGood + shr ebx, 2 +LastMatchGood: + +;;; chainlen is decremented once beforehand so that the function can +;;; use the sign flag instead of the zero flag for the exit test. +;;; It is then shifted into the high word, to make room for the wmask +;;; value, which it will always accompany. + + dec ebx + shl ebx, 16 + or ebx, eax + +;;; on zlib only +;;; if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead; + +IFDEF INFOZIP + mov [chainlenwmask], ebx +; on infozip nice_match = [nice_match] +ELSE + mov eax, nice_match + mov [chainlenwmask], ebx + mov r10d, Lookahead + cmp r10d, eax + cmovnl r10d, eax + mov [nicematch],r10d +ENDIF + +;;; register Bytef *scan = s->window + s->strstart; + mov r10, window_ad + mov ebp, strstart + lea r13, [r10 + rbp] + +;;; Determine how many bytes the scan ptr is off from being +;;; dword-aligned. + + mov r9,r13 + neg r13 + and r13,3 + +;;; IPos limit = s->strstart > (IPos)MAX_DIST(s) ? +;;; s->strstart - (IPos)MAX_DIST(s) : NIL; +IFDEF INFOZIP + mov eax,07efah ; MAX_DIST = (WSIZE-MIN_LOOKAHEAD) (0x8000-(3+8+1)) +ELSE + mov eax, window_size + sub eax, MIN_LOOKAHEAD +ENDIF + xor edi,edi + sub ebp, eax + + mov r11d, prev_length + + cmovng ebp,edi + +;;; int best_len = s->prev_length; + + +;;; Store the sum of s->window + best_len in esi locally, and in esi. + + lea rsi,[r10+r11] + +;;; register ush scan_start = *(ushf*)scan; +;;; register ush scan_end = *(ushf*)(scan+best_len-1); +;;; Posf *prev = s->prev; + + movzx r12d,word ptr [r9] + movzx ebx, word ptr [r9 + r11 - 1] + + mov rdi, prev_ad + +;;; Jump into the main loop. + + mov edx, [chainlenwmask] + + cmp bx,word ptr [rsi + r8 - 1] + jz LookupLoopIsZero + +LookupLoop1: + and r8d, edx + + movzx r8d, word ptr [rdi + r8*2] + cmp r8d, ebp + jbe LeaveNow + sub edx, 00010000h + js LeaveNow + +LoopEntry1: + cmp bx,word ptr [rsi + r8 - 1] + jz LookupLoopIsZero + +LookupLoop2: + and r8d, edx + + movzx r8d, word ptr [rdi + r8*2] + cmp r8d, ebp + jbe LeaveNow + sub edx, 00010000h + js LeaveNow + +LoopEntry2: + cmp bx,word ptr [rsi + r8 - 1] + jz LookupLoopIsZero + +LookupLoop4: + and r8d, edx + + movzx r8d, word ptr [rdi + r8*2] + cmp r8d, ebp + jbe LeaveNow + sub edx, 00010000h + js LeaveNow + +LoopEntry4: + + cmp bx,word ptr [rsi + r8 - 1] + jnz LookupLoop1 + jmp LookupLoopIsZero + + +;;; do { +;;; match = s->window + cur_match; +;;; if (*(ushf*)(match+best_len-1) != scan_end || +;;; *(ushf*)match != scan_start) continue; +;;; [...] +;;; } while ((cur_match = prev[cur_match & wmask]) > limit +;;; && --chain_length != 0); +;;; +;;; Here is the inner loop of the function. The function will spend the +;;; majority of its time in this loop, and majority of that time will +;;; be spent in the first ten instructions. +;;; +;;; Within this loop: +;;; ebx = scanend +;;; r8d = curmatch +;;; edx = chainlenwmask - i.e., ((chainlen << 16) | wmask) +;;; esi = windowbestlen - i.e., (window + bestlen) +;;; edi = prev +;;; ebp = limit + +LookupLoop: + and r8d, edx + + movzx r8d, word ptr [rdi + r8*2] + cmp r8d, ebp + jbe LeaveNow + sub edx, 00010000h + js LeaveNow + +LoopEntry: + + cmp bx,word ptr [rsi + r8 - 1] + jnz LookupLoop1 +LookupLoopIsZero: + cmp r12w, word ptr [r10 + r8] + jnz LookupLoop1 + + +;;; Store the current value of chainlen. + mov [chainlenwmask], edx + +;;; Point edi to the string under scrutiny, and esi to the string we +;;; are hoping to match it up with. In actuality, esi and edi are +;;; both pointed (MAX_MATCH_8 - scanalign) bytes ahead, and edx is +;;; initialized to -(MAX_MATCH_8 - scanalign). + + lea rsi,[r8+r10] + mov rdx, 0fffffffffffffef8h; -(MAX_MATCH_8) + lea rsi, [rsi + r13 + 0108h] ;MAX_MATCH_8] + lea rdi, [r9 + r13 + 0108h] ;MAX_MATCH_8] + + prefetcht1 [rsi+rdx] + prefetcht1 [rdi+rdx] + + +;;; Test the strings for equality, 8 bytes at a time. At the end, +;;; adjust rdx so that it is offset to the exact byte that mismatched. +;;; +;;; We already know at this point that the first three bytes of the +;;; strings match each other, and they can be safely passed over before +;;; starting the compare loop. So what this code does is skip over 0-3 +;;; bytes, as much as necessary in order to dword-align the edi +;;; pointer. (rsi will still be misaligned three times out of four.) +;;; +;;; It should be confessed that this loop usually does not represent +;;; much of the total running time. Replacing it with a more +;;; straightforward "rep cmpsb" would not drastically degrade +;;; performance. + + +LoopCmps: + mov rax, [rsi + rdx] + xor rax, [rdi + rdx] + jnz LeaveLoopCmps + + mov rax, [rsi + rdx + 8] + xor rax, [rdi + rdx + 8] + jnz LeaveLoopCmps8 + + + mov rax, [rsi + rdx + 8+8] + xor rax, [rdi + rdx + 8+8] + jnz LeaveLoopCmps16 + + add rdx,8+8+8 + + jnz short LoopCmps + jmp short LenMaximum +LeaveLoopCmps16: add rdx,8 +LeaveLoopCmps8: add rdx,8 +LeaveLoopCmps: + + test eax, 0000FFFFh + jnz LenLower + + test eax,0ffffffffh + + jnz LenLower32 + + add rdx,4 + shr rax,32 + or ax,ax + jnz LenLower + +LenLower32: + shr eax,16 + add rdx,2 +LenLower: sub al, 1 + adc rdx, 0 +;;; Calculate the length of the match. If it is longer than MAX_MATCH, +;;; then automatically accept it as the best possible match and leave. + + lea rax, [rdi + rdx] + sub rax, r9 + cmp eax, MAX_MATCH + jge LenMaximum + +;;; If the length of the match is not longer than the best match we +;;; have so far, then forget it and return to the lookup loop. +;/////////////////////////////////// + + cmp eax, r11d + jg LongerMatch + + lea rsi,[r10+r11] + + mov rdi, prev_ad + mov edx, [chainlenwmask] + jmp LookupLoop + +;;; s->match_start = cur_match; +;;; best_len = len; +;;; if (len >= nice_match) break; +;;; scan_end = *(ushf*)(scan+best_len-1); + +LongerMatch: + mov r11d, eax + mov match_start, r8d + cmp eax, [nicematch] + jge LeaveNow + + lea rsi,[r10+rax] + + movzx ebx, word ptr [r9 + rax - 1] + mov rdi, prev_ad + mov edx, [chainlenwmask] + jmp LookupLoop + +;;; Accept the current string, with the maximum possible length. + +LenMaximum: + mov r11d,MAX_MATCH + mov match_start, r8d + +;;; if ((uInt)best_len <= s->lookahead) return (uInt)best_len; +;;; return s->lookahead; + +LeaveNow: +IFDEF INFOZIP + mov eax,r11d +ELSE + mov eax, Lookahead + cmp r11d, eax + cmovng eax, r11d +ENDIF + +;;; Restore the stack and return from whence we came. + + + mov rsi,[save_rsi] + mov rdi,[save_rdi] + mov rbx,[save_rbx] + mov rbp,[save_rbp] + mov r12,[save_r12] + mov r13,[save_r13] +; mov r14,[save_r14] +; mov r15,[save_r15] + + + ret 0 +; please don't remove this string ! +; Your can freely use gvmat64 in any free or commercial app +; but it is far better don't remove the string in the binary! + db 0dh,0ah,"asm686 with masm, optimised assembly code from Brian Raiter, written 1998, converted to amd 64 by Gilles Vollant 2005",0dh,0ah,0 +longest_match ENDP + +match_init PROC + ret 0 +match_init ENDP + + +END diff --git a/libs/zlib/contrib/masmx64/inffas8664.c b/libs/zlib/contrib/masmx64/inffas8664.c new file mode 100644 index 000000000..aa861a333 --- /dev/null +++ b/libs/zlib/contrib/masmx64/inffas8664.c @@ -0,0 +1,186 @@ +/* inffas8664.c is a hand tuned assembler version of inffast.c - fast decoding + * version for AMD64 on Windows using Microsoft C compiler + * + * Copyright (C) 1995-2003 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + * + * Copyright (C) 2003 Chris Anderson + * Please use the copyright conditions above. + * + * 2005 - Adaptation to Microsoft C Compiler for AMD64 by Gilles Vollant + * + * inffas8664.c call function inffas8664fnc in inffasx64.asm + * inffasx64.asm is automatically convert from AMD64 portion of inffas86.c + * + * Dec-29-2003 -- I added AMD64 inflate asm support. This version is also + * slightly quicker on x86 systems because, instead of using rep movsb to copy + * data, it uses rep movsw, which moves data in 2-byte chunks instead of single + * bytes. I've tested the AMD64 code on a Fedora Core 1 + the x86_64 updates + * from http://fedora.linux.duke.edu/fc1_x86_64 + * which is running on an Athlon 64 3000+ / Gigabyte GA-K8VT800M system with + * 1GB ram. The 64-bit version is about 4% faster than the 32-bit version, + * when decompressing mozilla-source-1.3.tar.gz. + * + * Mar-13-2003 -- Most of this is derived from inffast.S which is derived from + * the gcc -S output of zlib-1.2.0/inffast.c. Zlib-1.2.0 is in beta release at + * the moment. I have successfully compiled and tested this code with gcc2.96, + * gcc3.2, icc5.0, msvc6.0. It is very close to the speed of inffast.S + * compiled with gcc -DNO_MMX, but inffast.S is still faster on the P3 with MMX + * enabled. I will attempt to merge the MMX code into this version. Newer + * versions of this and inffast.S can be found at + * http://www.eetbeetee.com/zlib/ and http://www.charm.net/~christop/zlib/ + * + */ + +#include +#include "zutil.h" +#include "inftrees.h" +#include "inflate.h" +#include "inffast.h" + +/* Mark Adler's comments from inffast.c: */ + +/* + Decode literal, length, and distance codes and write out the resulting + literal and match bytes until either not enough input or output is + available, an end-of-block is encountered, or a data error is encountered. + When large enough input and output buffers are supplied to inflate(), for + example, a 16K input buffer and a 64K output buffer, more than 95% of the + inflate execution time is spent in this routine. + + Entry assumptions: + + state->mode == LEN + strm->avail_in >= 6 + strm->avail_out >= 258 + start >= strm->avail_out + state->bits < 8 + + On return, state->mode is one of: + + LEN -- ran out of enough output space or enough available input + TYPE -- reached end of block code, inflate() to interpret next block + BAD -- error in block data + + Notes: + + - The maximum input bits used by a length/distance pair is 15 bits for the + length code, 5 bits for the length extra, 15 bits for the distance code, + and 13 bits for the distance extra. This totals 48 bits, or six bytes. + Therefore if strm->avail_in >= 6, then there is enough input to avoid + checking for available input while decoding. + + - The maximum bytes that a single length/distance pair can output is 258 + bytes, which is the maximum length that can be coded. inflate_fast() + requires strm->avail_out >= 258 for each loop to avoid checking for + output space. + */ + + + + typedef struct inffast_ar { +/* 64 32 x86 x86_64 */ +/* ar offset register */ +/* 0 0 */ void *esp; /* esp save */ +/* 8 4 */ void *ebp; /* ebp save */ +/* 16 8 */ unsigned char FAR *in; /* esi rsi local strm->next_in */ +/* 24 12 */ unsigned char FAR *last; /* r9 while in < last */ +/* 32 16 */ unsigned char FAR *out; /* edi rdi local strm->next_out */ +/* 40 20 */ unsigned char FAR *beg; /* inflate()'s init next_out */ +/* 48 24 */ unsigned char FAR *end; /* r10 while out < end */ +/* 56 28 */ unsigned char FAR *window;/* size of window, wsize!=0 */ +/* 64 32 */ code const FAR *lcode; /* ebp rbp local strm->lencode */ +/* 72 36 */ code const FAR *dcode; /* r11 local strm->distcode */ +/* 80 40 */ size_t /*unsigned long */hold; /* edx rdx local strm->hold */ +/* 88 44 */ unsigned bits; /* ebx rbx local strm->bits */ +/* 92 48 */ unsigned wsize; /* window size */ +/* 96 52 */ unsigned write; /* window write index */ +/*100 56 */ unsigned lmask; /* r12 mask for lcode */ +/*104 60 */ unsigned dmask; /* r13 mask for dcode */ +/*108 64 */ unsigned len; /* r14 match length */ +/*112 68 */ unsigned dist; /* r15 match distance */ +/*116 72 */ unsigned status; /* set when state chng*/ + } type_ar; +#ifdef ASMINF + +void inflate_fast(strm, start) +z_streamp strm; +unsigned start; /* inflate()'s starting value for strm->avail_out */ +{ + struct inflate_state FAR *state; + type_ar ar; + void inffas8664fnc(struct inffast_ar * par); + + + +#if (defined( __GNUC__ ) && defined( __amd64__ ) && ! defined( __i386 )) || (defined(_MSC_VER) && defined(_M_AMD64)) +#define PAD_AVAIL_IN 6 +#define PAD_AVAIL_OUT 258 +#else +#define PAD_AVAIL_IN 5 +#define PAD_AVAIL_OUT 257 +#endif + + /* copy state to local variables */ + state = (struct inflate_state FAR *)strm->state; + + ar.in = strm->next_in; + ar.last = ar.in + (strm->avail_in - PAD_AVAIL_IN); + ar.out = strm->next_out; + ar.beg = ar.out - (start - strm->avail_out); + ar.end = ar.out + (strm->avail_out - PAD_AVAIL_OUT); + ar.wsize = state->wsize; + ar.write = state->wnext; + ar.window = state->window; + ar.hold = state->hold; + ar.bits = state->bits; + ar.lcode = state->lencode; + ar.dcode = state->distcode; + ar.lmask = (1U << state->lenbits) - 1; + ar.dmask = (1U << state->distbits) - 1; + + /* decode literals and length/distances until end-of-block or not enough + input data or output space */ + + /* align in on 1/2 hold size boundary */ + while (((size_t)(void *)ar.in & (sizeof(ar.hold) / 2 - 1)) != 0) { + ar.hold += (unsigned long)*ar.in++ << ar.bits; + ar.bits += 8; + } + + inffas8664fnc(&ar); + + if (ar.status > 1) { + if (ar.status == 2) + strm->msg = "invalid literal/length code"; + else if (ar.status == 3) + strm->msg = "invalid distance code"; + else + strm->msg = "invalid distance too far back"; + state->mode = BAD; + } + else if ( ar.status == 1 ) { + state->mode = TYPE; + } + + /* return unused bytes (on entry, bits < 8, so in won't go too far back) */ + ar.len = ar.bits >> 3; + ar.in -= ar.len; + ar.bits -= ar.len << 3; + ar.hold &= (1U << ar.bits) - 1; + + /* update state and return */ + strm->next_in = ar.in; + strm->next_out = ar.out; + strm->avail_in = (unsigned)(ar.in < ar.last ? + PAD_AVAIL_IN + (ar.last - ar.in) : + PAD_AVAIL_IN - (ar.in - ar.last)); + strm->avail_out = (unsigned)(ar.out < ar.end ? + PAD_AVAIL_OUT + (ar.end - ar.out) : + PAD_AVAIL_OUT - (ar.out - ar.end)); + state->hold = (unsigned long)ar.hold; + state->bits = ar.bits; + return; +} + +#endif diff --git a/libs/zlib/contrib/masmx64/inffasx64.asm b/libs/zlib/contrib/masmx64/inffasx64.asm new file mode 100644 index 000000000..41ec82392 --- /dev/null +++ b/libs/zlib/contrib/masmx64/inffasx64.asm @@ -0,0 +1,396 @@ +; inffasx64.asm is a hand tuned assembler version of inffast.c - fast decoding +; version for AMD64 on Windows using Microsoft C compiler +; +; inffasx64.asm is automatically convert from AMD64 portion of inffas86.c +; inffasx64.asm is called by inffas8664.c, which contain more info. + + +; to compile this file, I use option +; ml64.exe /Flinffasx64 /c /Zi inffasx64.asm +; with Microsoft Macro Assembler (x64) for AMD64 +; + +; This file compile with Microsoft Macro Assembler (x64) for AMD64 +; +; ml64.exe is given with Visual Studio 2005/2008/2010 and Windows WDK +; +; (you can get Windows WDK with ml64 for AMD64 from +; http://www.microsoft.com/whdc/Devtools/wdk/default.mspx for low price) +; + + +.code +inffas8664fnc PROC + +; see http://weblogs.asp.net/oldnewthing/archive/2004/01/14/58579.aspx and +; http://msdn.microsoft.com/library/en-us/kmarch/hh/kmarch/64bitAMD_8e951dd2-ee77-4728-8702-55ce4b5dd24a.xml.asp +; +; All registers must be preserved across the call, except for +; rax, rcx, rdx, r8, r-9, r10, and r11, which are scratch. + + + mov [rsp-8],rsi + mov [rsp-16],rdi + mov [rsp-24],r12 + mov [rsp-32],r13 + mov [rsp-40],r14 + mov [rsp-48],r15 + mov [rsp-56],rbx + + mov rax,rcx + + mov [rax+8], rbp ; /* save regs rbp and rsp */ + mov [rax], rsp + + mov rsp, rax ; /* make rsp point to &ar */ + + mov rsi, [rsp+16] ; /* rsi = in */ + mov rdi, [rsp+32] ; /* rdi = out */ + mov r9, [rsp+24] ; /* r9 = last */ + mov r10, [rsp+48] ; /* r10 = end */ + mov rbp, [rsp+64] ; /* rbp = lcode */ + mov r11, [rsp+72] ; /* r11 = dcode */ + mov rdx, [rsp+80] ; /* rdx = hold */ + mov ebx, [rsp+88] ; /* ebx = bits */ + mov r12d, [rsp+100] ; /* r12d = lmask */ + mov r13d, [rsp+104] ; /* r13d = dmask */ + ; /* r14d = len */ + ; /* r15d = dist */ + + + cld + cmp r10, rdi + je L_one_time ; /* if only one decode left */ + cmp r9, rsi + + jne L_do_loop + + +L_one_time: + mov r8, r12 ; /* r8 = lmask */ + cmp bl, 32 + ja L_get_length_code_one_time + + lodsd ; /* eax = *(uint *)in++ */ + mov cl, bl ; /* cl = bits, needs it for shifting */ + add bl, 32 ; /* bits += 32 */ + shl rax, cl + or rdx, rax ; /* hold |= *((uint *)in)++ << bits */ + jmp L_get_length_code_one_time + +ALIGN 4 +L_while_test: + cmp r10, rdi + jbe L_break_loop + cmp r9, rsi + jbe L_break_loop + +L_do_loop: + mov r8, r12 ; /* r8 = lmask */ + cmp bl, 32 + ja L_get_length_code ; /* if (32 < bits) */ + + lodsd ; /* eax = *(uint *)in++ */ + mov cl, bl ; /* cl = bits, needs it for shifting */ + add bl, 32 ; /* bits += 32 */ + shl rax, cl + or rdx, rax ; /* hold |= *((uint *)in)++ << bits */ + +L_get_length_code: + and r8, rdx ; /* r8 &= hold */ + mov eax, [rbp+r8*4] ; /* eax = lcode[hold & lmask] */ + + mov cl, ah ; /* cl = this.bits */ + sub bl, ah ; /* bits -= this.bits */ + shr rdx, cl ; /* hold >>= this.bits */ + + test al, al + jnz L_test_for_length_base ; /* if (op != 0) 45.7% */ + + mov r8, r12 ; /* r8 = lmask */ + shr eax, 16 ; /* output this.val char */ + stosb + +L_get_length_code_one_time: + and r8, rdx ; /* r8 &= hold */ + mov eax, [rbp+r8*4] ; /* eax = lcode[hold & lmask] */ + +L_dolen: + mov cl, ah ; /* cl = this.bits */ + sub bl, ah ; /* bits -= this.bits */ + shr rdx, cl ; /* hold >>= this.bits */ + + test al, al + jnz L_test_for_length_base ; /* if (op != 0) 45.7% */ + + shr eax, 16 ; /* output this.val char */ + stosb + jmp L_while_test + +ALIGN 4 +L_test_for_length_base: + mov r14d, eax ; /* len = this */ + shr r14d, 16 ; /* len = this.val */ + mov cl, al + + test al, 16 + jz L_test_for_second_level_length ; /* if ((op & 16) == 0) 8% */ + and cl, 15 ; /* op &= 15 */ + jz L_decode_distance ; /* if (!op) */ + +L_add_bits_to_len: + sub bl, cl + xor eax, eax + inc eax + shl eax, cl + dec eax + and eax, edx ; /* eax &= hold */ + shr rdx, cl + add r14d, eax ; /* len += hold & mask[op] */ + +L_decode_distance: + mov r8, r13 ; /* r8 = dmask */ + cmp bl, 32 + ja L_get_distance_code ; /* if (32 < bits) */ + + lodsd ; /* eax = *(uint *)in++ */ + mov cl, bl ; /* cl = bits, needs it for shifting */ + add bl, 32 ; /* bits += 32 */ + shl rax, cl + or rdx, rax ; /* hold |= *((uint *)in)++ << bits */ + +L_get_distance_code: + and r8, rdx ; /* r8 &= hold */ + mov eax, [r11+r8*4] ; /* eax = dcode[hold & dmask] */ + +L_dodist: + mov r15d, eax ; /* dist = this */ + shr r15d, 16 ; /* dist = this.val */ + mov cl, ah + sub bl, ah ; /* bits -= this.bits */ + shr rdx, cl ; /* hold >>= this.bits */ + mov cl, al ; /* cl = this.op */ + + test al, 16 ; /* if ((op & 16) == 0) */ + jz L_test_for_second_level_dist + and cl, 15 ; /* op &= 15 */ + jz L_check_dist_one + +L_add_bits_to_dist: + sub bl, cl + xor eax, eax + inc eax + shl eax, cl + dec eax ; /* (1 << op) - 1 */ + and eax, edx ; /* eax &= hold */ + shr rdx, cl + add r15d, eax ; /* dist += hold & ((1 << op) - 1) */ + +L_check_window: + mov r8, rsi ; /* save in so from can use it's reg */ + mov rax, rdi + sub rax, [rsp+40] ; /* nbytes = out - beg */ + + cmp eax, r15d + jb L_clip_window ; /* if (dist > nbytes) 4.2% */ + + mov ecx, r14d ; /* ecx = len */ + mov rsi, rdi + sub rsi, r15 ; /* from = out - dist */ + + sar ecx, 1 + jnc L_copy_two ; /* if len % 2 == 0 */ + + rep movsw + mov al, [rsi] + mov [rdi], al + inc rdi + + mov rsi, r8 ; /* move in back to %rsi, toss from */ + jmp L_while_test + +L_copy_two: + rep movsw + mov rsi, r8 ; /* move in back to %rsi, toss from */ + jmp L_while_test + +ALIGN 4 +L_check_dist_one: + cmp r15d, 1 ; /* if dist 1, is a memset */ + jne L_check_window + cmp [rsp+40], rdi ; /* if out == beg, outside window */ + je L_check_window + + mov ecx, r14d ; /* ecx = len */ + mov al, [rdi-1] + mov ah, al + + sar ecx, 1 + jnc L_set_two + mov [rdi], al + inc rdi + +L_set_two: + rep stosw + jmp L_while_test + +ALIGN 4 +L_test_for_second_level_length: + test al, 64 + jnz L_test_for_end_of_block ; /* if ((op & 64) != 0) */ + + xor eax, eax + inc eax + shl eax, cl + dec eax + and eax, edx ; /* eax &= hold */ + add eax, r14d ; /* eax += len */ + mov eax, [rbp+rax*4] ; /* eax = lcode[val+(hold&mask[op])]*/ + jmp L_dolen + +ALIGN 4 +L_test_for_second_level_dist: + test al, 64 + jnz L_invalid_distance_code ; /* if ((op & 64) != 0) */ + + xor eax, eax + inc eax + shl eax, cl + dec eax + and eax, edx ; /* eax &= hold */ + add eax, r15d ; /* eax += dist */ + mov eax, [r11+rax*4] ; /* eax = dcode[val+(hold&mask[op])]*/ + jmp L_dodist + +ALIGN 4 +L_clip_window: + mov ecx, eax ; /* ecx = nbytes */ + mov eax, [rsp+92] ; /* eax = wsize, prepare for dist cmp */ + neg ecx ; /* nbytes = -nbytes */ + + cmp eax, r15d + jb L_invalid_distance_too_far ; /* if (dist > wsize) */ + + add ecx, r15d ; /* nbytes = dist - nbytes */ + cmp dword ptr [rsp+96], 0 + jne L_wrap_around_window ; /* if (write != 0) */ + + mov rsi, [rsp+56] ; /* from = window */ + sub eax, ecx ; /* eax -= nbytes */ + add rsi, rax ; /* from += wsize - nbytes */ + + mov eax, r14d ; /* eax = len */ + cmp r14d, ecx + jbe L_do_copy ; /* if (nbytes >= len) */ + + sub eax, ecx ; /* eax -= nbytes */ + rep movsb + mov rsi, rdi + sub rsi, r15 ; /* from = &out[ -dist ] */ + jmp L_do_copy + +ALIGN 4 +L_wrap_around_window: + mov eax, [rsp+96] ; /* eax = write */ + cmp ecx, eax + jbe L_contiguous_in_window ; /* if (write >= nbytes) */ + + mov esi, [rsp+92] ; /* from = wsize */ + add rsi, [rsp+56] ; /* from += window */ + add rsi, rax ; /* from += write */ + sub rsi, rcx ; /* from -= nbytes */ + sub ecx, eax ; /* nbytes -= write */ + + mov eax, r14d ; /* eax = len */ + cmp eax, ecx + jbe L_do_copy ; /* if (nbytes >= len) */ + + sub eax, ecx ; /* len -= nbytes */ + rep movsb + mov rsi, [rsp+56] ; /* from = window */ + mov ecx, [rsp+96] ; /* nbytes = write */ + cmp eax, ecx + jbe L_do_copy ; /* if (nbytes >= len) */ + + sub eax, ecx ; /* len -= nbytes */ + rep movsb + mov rsi, rdi + sub rsi, r15 ; /* from = out - dist */ + jmp L_do_copy + +ALIGN 4 +L_contiguous_in_window: + mov rsi, [rsp+56] ; /* rsi = window */ + add rsi, rax + sub rsi, rcx ; /* from += write - nbytes */ + + mov eax, r14d ; /* eax = len */ + cmp eax, ecx + jbe L_do_copy ; /* if (nbytes >= len) */ + + sub eax, ecx ; /* len -= nbytes */ + rep movsb + mov rsi, rdi + sub rsi, r15 ; /* from = out - dist */ + jmp L_do_copy ; /* if (nbytes >= len) */ + +ALIGN 4 +L_do_copy: + mov ecx, eax ; /* ecx = len */ + rep movsb + + mov rsi, r8 ; /* move in back to %esi, toss from */ + jmp L_while_test + +L_test_for_end_of_block: + test al, 32 + jz L_invalid_literal_length_code + mov dword ptr [rsp+116], 1 + jmp L_break_loop_with_status + +L_invalid_literal_length_code: + mov dword ptr [rsp+116], 2 + jmp L_break_loop_with_status + +L_invalid_distance_code: + mov dword ptr [rsp+116], 3 + jmp L_break_loop_with_status + +L_invalid_distance_too_far: + mov dword ptr [rsp+116], 4 + jmp L_break_loop_with_status + +L_break_loop: + mov dword ptr [rsp+116], 0 + +L_break_loop_with_status: +; /* put in, out, bits, and hold back into ar and pop esp */ + mov [rsp+16], rsi ; /* in */ + mov [rsp+32], rdi ; /* out */ + mov [rsp+88], ebx ; /* bits */ + mov [rsp+80], rdx ; /* hold */ + + mov rax, [rsp] ; /* restore rbp and rsp */ + mov rbp, [rsp+8] + mov rsp, rax + + + + mov rsi,[rsp-8] + mov rdi,[rsp-16] + mov r12,[rsp-24] + mov r13,[rsp-32] + mov r14,[rsp-40] + mov r15,[rsp-48] + mov rbx,[rsp-56] + + ret 0 +; : +; : "m" (ar) +; : "memory", "%rax", "%rbx", "%rcx", "%rdx", "%rsi", "%rdi", +; "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15" +; ); + +inffas8664fnc ENDP +;_TEXT ENDS +END diff --git a/libs/zlib/contrib/masmx64/readme.txt b/libs/zlib/contrib/masmx64/readme.txt new file mode 100644 index 000000000..652571c7a --- /dev/null +++ b/libs/zlib/contrib/masmx64/readme.txt @@ -0,0 +1,31 @@ +Summary +------- +This directory contains ASM implementations of the functions +longest_match() and inflate_fast(), for 64 bits x86 (both AMD64 and Intel EM64t), +for use with Microsoft Macro Assembler (x64) for AMD64 and Microsoft C++ 64 bits. + +gvmat64.asm is written by Gilles Vollant (2005), by using Brian Raiter 686/32 bits + assembly optimized version from Jean-loup Gailly original longest_match function + +inffasx64.asm and inffas8664.c were written by Chris Anderson, by optimizing + original function from Mark Adler + +Use instructions +---------------- +Assemble the .asm files using MASM and put the object files into the zlib source +directory. You can also get object files here: + + http://www.winimage.com/zLibDll/zlib124_masm_obj.zip + +define ASMV and ASMINF in your project. Include inffas8664.c in your source tree, +and inffasx64.obj and gvmat64.obj as object to link. + + +Build instructions +------------------ +run bld_64.bat with Microsoft Macro Assembler (x64) for AMD64 (ml64.exe) + +ml64.exe is given with Visual Studio 2005, Windows 2003 server DDK + +You can get Windows 2003 server DDK with ml64 and cl for AMD64 from + http://www.microsoft.com/whdc/devtools/ddk/default.mspx for low price) diff --git a/libs/zlib/contrib/masmx86/bld_ml32.bat b/libs/zlib/contrib/masmx86/bld_ml32.bat new file mode 100644 index 000000000..e1b86bf68 --- /dev/null +++ b/libs/zlib/contrib/masmx86/bld_ml32.bat @@ -0,0 +1,2 @@ +ml /coff /Zi /c /Flmatch686.lst match686.asm +ml /coff /Zi /c /Flinffas32.lst inffas32.asm diff --git a/libs/zlib/contrib/masmx86/inffas32.asm b/libs/zlib/contrib/masmx86/inffas32.asm new file mode 100644 index 000000000..14f9d3514 --- /dev/null +++ b/libs/zlib/contrib/masmx86/inffas32.asm @@ -0,0 +1,1083 @@ +;/* inffas32.asm is a hand tuned assembler version of inffast.c -- fast decoding +; * +; * inffas32.asm is derivated from inffas86.c, with translation of assembly code +; * +; * Copyright (C) 1995-2003 Mark Adler +; * For conditions of distribution and use, see copyright notice in zlib.h +; * +; * Copyright (C) 2003 Chris Anderson +; * Please use the copyright conditions above. +; * +; * Mar-13-2003 -- Most of this is derived from inffast.S which is derived from +; * the gcc -S output of zlib-1.2.0/inffast.c. Zlib-1.2.0 is in beta release at +; * the moment. I have successfully compiled and tested this code with gcc2.96, +; * gcc3.2, icc5.0, msvc6.0. It is very close to the speed of inffast.S +; * compiled with gcc -DNO_MMX, but inffast.S is still faster on the P3 with MMX +; * enabled. I will attempt to merge the MMX code into this version. Newer +; * versions of this and inffast.S can be found at +; * http://www.eetbeetee.com/zlib/ and http://www.charm.net/~christop/zlib/ +; * +; * 2005 : modification by Gilles Vollant +; */ +; For Visual C++ 4.x and higher and ML 6.x and higher +; ml.exe is in directory \MASM611C of Win95 DDK +; ml.exe is also distributed in http://www.masm32.com/masmdl.htm +; and in VC++2003 toolkit at http://msdn.microsoft.com/visualc/vctoolkit2003/ +; +; +; compile with command line option +; ml /coff /Zi /c /Flinffas32.lst inffas32.asm + +; if you define NO_GZIP (see inflate.h), compile with +; ml /coff /Zi /c /Flinffas32.lst /DNO_GUNZIP inffas32.asm + + +; zlib122sup is 0 fort zlib 1.2.2.1 and lower +; zlib122sup is 8 fort zlib 1.2.2.2 and more (with addition of dmax and head +; in inflate_state in inflate.h) +zlib1222sup equ 8 + + +IFDEF GUNZIP + INFLATE_MODE_TYPE equ 11 + INFLATE_MODE_BAD equ 26 +ELSE + IFNDEF NO_GUNZIP + INFLATE_MODE_TYPE equ 11 + INFLATE_MODE_BAD equ 26 + ELSE + INFLATE_MODE_TYPE equ 3 + INFLATE_MODE_BAD equ 17 + ENDIF +ENDIF + + +; 75 "inffast.S" +;FILE "inffast.S" + +;;;GLOBAL _inflate_fast + +;;;SECTION .text + + + + .586p + .mmx + + name inflate_fast_x86 + .MODEL FLAT + +_DATA segment +inflate_fast_use_mmx: + dd 1 + + +_TEXT segment +PUBLIC _inflate_fast + +ALIGN 4 +_inflate_fast: + jmp inflate_fast_entry + + + +ALIGN 4 + db 'Fast decoding Code from Chris Anderson' + db 0 + +ALIGN 4 +invalid_literal_length_code_msg: + db 'invalid literal/length code' + db 0 + +ALIGN 4 +invalid_distance_code_msg: + db 'invalid distance code' + db 0 + +ALIGN 4 +invalid_distance_too_far_msg: + db 'invalid distance too far back' + db 0 + + +ALIGN 4 +inflate_fast_mask: +dd 0 +dd 1 +dd 3 +dd 7 +dd 15 +dd 31 +dd 63 +dd 127 +dd 255 +dd 511 +dd 1023 +dd 2047 +dd 4095 +dd 8191 +dd 16383 +dd 32767 +dd 65535 +dd 131071 +dd 262143 +dd 524287 +dd 1048575 +dd 2097151 +dd 4194303 +dd 8388607 +dd 16777215 +dd 33554431 +dd 67108863 +dd 134217727 +dd 268435455 +dd 536870911 +dd 1073741823 +dd 2147483647 +dd 4294967295 + + +mode_state equ 0 ;/* state->mode */ +wsize_state equ (32+zlib1222sup) ;/* state->wsize */ +write_state equ (36+4+zlib1222sup) ;/* state->write */ +window_state equ (40+4+zlib1222sup) ;/* state->window */ +hold_state equ (44+4+zlib1222sup) ;/* state->hold */ +bits_state equ (48+4+zlib1222sup) ;/* state->bits */ +lencode_state equ (64+4+zlib1222sup) ;/* state->lencode */ +distcode_state equ (68+4+zlib1222sup) ;/* state->distcode */ +lenbits_state equ (72+4+zlib1222sup) ;/* state->lenbits */ +distbits_state equ (76+4+zlib1222sup) ;/* state->distbits */ + + +;;SECTION .text +; 205 "inffast.S" +;GLOBAL inflate_fast_use_mmx + +;SECTION .data + + +; GLOBAL inflate_fast_use_mmx:object +;.size inflate_fast_use_mmx, 4 +; 226 "inffast.S" +;SECTION .text + +ALIGN 4 +inflate_fast_entry: + push edi + push esi + push ebp + push ebx + pushfd + sub esp,64 + cld + + + + + mov esi, [esp+88] + mov edi, [esi+28] + + + + + + + + mov edx, [esi+4] + mov eax, [esi+0] + + add edx,eax + sub edx,11 + + mov [esp+44],eax + mov [esp+20],edx + + mov ebp, [esp+92] + mov ecx, [esi+16] + mov ebx, [esi+12] + + sub ebp,ecx + neg ebp + add ebp,ebx + + sub ecx,257 + add ecx,ebx + + mov [esp+60],ebx + mov [esp+40],ebp + mov [esp+16],ecx +; 285 "inffast.S" + mov eax, [edi+lencode_state] + mov ecx, [edi+distcode_state] + + mov [esp+8],eax + mov [esp+12],ecx + + mov eax,1 + mov ecx, [edi+lenbits_state] + shl eax,cl + dec eax + mov [esp+0],eax + + mov eax,1 + mov ecx, [edi+distbits_state] + shl eax,cl + dec eax + mov [esp+4],eax + + mov eax, [edi+wsize_state] + mov ecx, [edi+write_state] + mov edx, [edi+window_state] + + mov [esp+52],eax + mov [esp+48],ecx + mov [esp+56],edx + + mov ebp, [edi+hold_state] + mov ebx, [edi+bits_state] +; 321 "inffast.S" + mov esi, [esp+44] + mov ecx, [esp+20] + cmp ecx,esi + ja L_align_long + + add ecx,11 + sub ecx,esi + mov eax,12 + sub eax,ecx + lea edi, [esp+28] + rep movsb + mov ecx,eax + xor eax,eax + rep stosb + lea esi, [esp+28] + mov [esp+20],esi + jmp L_is_aligned + + +L_align_long: + test esi,3 + jz L_is_aligned + xor eax,eax + mov al, [esi] + inc esi + mov ecx,ebx + add ebx,8 + shl eax,cl + or ebp,eax + jmp L_align_long + +L_is_aligned: + mov edi, [esp+60] +; 366 "inffast.S" +L_check_mmx: + cmp dword ptr [inflate_fast_use_mmx],2 + je L_init_mmx + ja L_do_loop + + push eax + push ebx + push ecx + push edx + pushfd + mov eax, [esp] + xor dword ptr [esp],0200000h + + + + + popfd + pushfd + pop edx + xor edx,eax + jz L_dont_use_mmx + xor eax,eax + cpuid + cmp ebx,0756e6547h + jne L_dont_use_mmx + cmp ecx,06c65746eh + jne L_dont_use_mmx + cmp edx,049656e69h + jne L_dont_use_mmx + mov eax,1 + cpuid + shr eax,8 + and eax,15 + cmp eax,6 + jne L_dont_use_mmx + test edx,0800000h + jnz L_use_mmx + jmp L_dont_use_mmx +L_use_mmx: + mov dword ptr [inflate_fast_use_mmx],2 + jmp L_check_mmx_pop +L_dont_use_mmx: + mov dword ptr [inflate_fast_use_mmx],3 +L_check_mmx_pop: + pop edx + pop ecx + pop ebx + pop eax + jmp L_check_mmx +; 426 "inffast.S" +ALIGN 4 +L_do_loop: +; 437 "inffast.S" + cmp bl,15 + ja L_get_length_code + + xor eax,eax + lodsw + mov cl,bl + add bl,16 + shl eax,cl + or ebp,eax + +L_get_length_code: + mov edx, [esp+0] + mov ecx, [esp+8] + and edx,ebp + mov eax, [ecx+edx*4] + +L_dolen: + + + + + + + mov cl,ah + sub bl,ah + shr ebp,cl + + + + + + + test al,al + jnz L_test_for_length_base + + shr eax,16 + stosb + +L_while_test: + + + cmp [esp+16],edi + jbe L_break_loop + + cmp [esp+20],esi + ja L_do_loop + jmp L_break_loop + +L_test_for_length_base: +; 502 "inffast.S" + mov edx,eax + shr edx,16 + mov cl,al + + test al,16 + jz L_test_for_second_level_length + and cl,15 + jz L_save_len + cmp bl,cl + jae L_add_bits_to_len + + mov ch,cl + xor eax,eax + lodsw + mov cl,bl + add bl,16 + shl eax,cl + or ebp,eax + mov cl,ch + +L_add_bits_to_len: + mov eax,1 + shl eax,cl + dec eax + sub bl,cl + and eax,ebp + shr ebp,cl + add edx,eax + +L_save_len: + mov [esp+24],edx + + +L_decode_distance: +; 549 "inffast.S" + cmp bl,15 + ja L_get_distance_code + + xor eax,eax + lodsw + mov cl,bl + add bl,16 + shl eax,cl + or ebp,eax + +L_get_distance_code: + mov edx, [esp+4] + mov ecx, [esp+12] + and edx,ebp + mov eax, [ecx+edx*4] + + +L_dodist: + mov edx,eax + shr edx,16 + mov cl,ah + sub bl,ah + shr ebp,cl +; 584 "inffast.S" + mov cl,al + + test al,16 + jz L_test_for_second_level_dist + and cl,15 + jz L_check_dist_one + cmp bl,cl + jae L_add_bits_to_dist + + mov ch,cl + xor eax,eax + lodsw + mov cl,bl + add bl,16 + shl eax,cl + or ebp,eax + mov cl,ch + +L_add_bits_to_dist: + mov eax,1 + shl eax,cl + dec eax + sub bl,cl + and eax,ebp + shr ebp,cl + add edx,eax + jmp L_check_window + +L_check_window: +; 625 "inffast.S" + mov [esp+44],esi + mov eax,edi + sub eax, [esp+40] + + cmp eax,edx + jb L_clip_window + + mov ecx, [esp+24] + mov esi,edi + sub esi,edx + + sub ecx,3 + mov al, [esi] + mov [edi],al + mov al, [esi+1] + mov dl, [esi+2] + add esi,3 + mov [edi+1],al + mov [edi+2],dl + add edi,3 + rep movsb + + mov esi, [esp+44] + jmp L_while_test + +ALIGN 4 +L_check_dist_one: + cmp edx,1 + jne L_check_window + cmp [esp+40],edi + je L_check_window + + dec edi + mov ecx, [esp+24] + mov al, [edi] + sub ecx,3 + + mov [edi+1],al + mov [edi+2],al + mov [edi+3],al + add edi,4 + rep stosb + + jmp L_while_test + +ALIGN 4 +L_test_for_second_level_length: + + + + + test al,64 + jnz L_test_for_end_of_block + + mov eax,1 + shl eax,cl + dec eax + and eax,ebp + add eax,edx + mov edx, [esp+8] + mov eax, [edx+eax*4] + jmp L_dolen + +ALIGN 4 +L_test_for_second_level_dist: + + + + + test al,64 + jnz L_invalid_distance_code + + mov eax,1 + shl eax,cl + dec eax + and eax,ebp + add eax,edx + mov edx, [esp+12] + mov eax, [edx+eax*4] + jmp L_dodist + +ALIGN 4 +L_clip_window: +; 721 "inffast.S" + mov ecx,eax + mov eax, [esp+52] + neg ecx + mov esi, [esp+56] + + cmp eax,edx + jb L_invalid_distance_too_far + + add ecx,edx + cmp dword ptr [esp+48],0 + jne L_wrap_around_window + + sub eax,ecx + add esi,eax +; 749 "inffast.S" + mov eax, [esp+24] + cmp eax,ecx + jbe L_do_copy1 + + sub eax,ecx + rep movsb + mov esi,edi + sub esi,edx + jmp L_do_copy1 + + cmp eax,ecx + jbe L_do_copy1 + + sub eax,ecx + rep movsb + mov esi,edi + sub esi,edx + jmp L_do_copy1 + +L_wrap_around_window: +; 793 "inffast.S" + mov eax, [esp+48] + cmp ecx,eax + jbe L_contiguous_in_window + + add esi, [esp+52] + add esi,eax + sub esi,ecx + sub ecx,eax + + + mov eax, [esp+24] + cmp eax,ecx + jbe L_do_copy1 + + sub eax,ecx + rep movsb + mov esi, [esp+56] + mov ecx, [esp+48] + cmp eax,ecx + jbe L_do_copy1 + + sub eax,ecx + rep movsb + mov esi,edi + sub esi,edx + jmp L_do_copy1 + +L_contiguous_in_window: +; 836 "inffast.S" + add esi,eax + sub esi,ecx + + + mov eax, [esp+24] + cmp eax,ecx + jbe L_do_copy1 + + sub eax,ecx + rep movsb + mov esi,edi + sub esi,edx + +L_do_copy1: +; 862 "inffast.S" + mov ecx,eax + rep movsb + + mov esi, [esp+44] + jmp L_while_test +; 878 "inffast.S" +ALIGN 4 +L_init_mmx: + emms + + + + + + movd mm0,ebp + mov ebp,ebx +; 896 "inffast.S" + movd mm4,dword ptr [esp+0] + movq mm3,mm4 + movd mm5,dword ptr [esp+4] + movq mm2,mm5 + pxor mm1,mm1 + mov ebx, [esp+8] + jmp L_do_loop_mmx + +ALIGN 4 +L_do_loop_mmx: + psrlq mm0,mm1 + + cmp ebp,32 + ja L_get_length_code_mmx + + movd mm6,ebp + movd mm7,dword ptr [esi] + add esi,4 + psllq mm7,mm6 + add ebp,32 + por mm0,mm7 + +L_get_length_code_mmx: + pand mm4,mm0 + movd eax,mm4 + movq mm4,mm3 + mov eax, [ebx+eax*4] + +L_dolen_mmx: + movzx ecx,ah + movd mm1,ecx + sub ebp,ecx + + test al,al + jnz L_test_for_length_base_mmx + + shr eax,16 + stosb + +L_while_test_mmx: + + + cmp [esp+16],edi + jbe L_break_loop + + cmp [esp+20],esi + ja L_do_loop_mmx + jmp L_break_loop + +L_test_for_length_base_mmx: + + mov edx,eax + shr edx,16 + + test al,16 + jz L_test_for_second_level_length_mmx + and eax,15 + jz L_decode_distance_mmx + + psrlq mm0,mm1 + movd mm1,eax + movd ecx,mm0 + sub ebp,eax + and ecx, [inflate_fast_mask+eax*4] + add edx,ecx + +L_decode_distance_mmx: + psrlq mm0,mm1 + + cmp ebp,32 + ja L_get_dist_code_mmx + + movd mm6,ebp + movd mm7,dword ptr [esi] + add esi,4 + psllq mm7,mm6 + add ebp,32 + por mm0,mm7 + +L_get_dist_code_mmx: + mov ebx, [esp+12] + pand mm5,mm0 + movd eax,mm5 + movq mm5,mm2 + mov eax, [ebx+eax*4] + +L_dodist_mmx: + + movzx ecx,ah + mov ebx,eax + shr ebx,16 + sub ebp,ecx + movd mm1,ecx + + test al,16 + jz L_test_for_second_level_dist_mmx + and eax,15 + jz L_check_dist_one_mmx + +L_add_bits_to_dist_mmx: + psrlq mm0,mm1 + movd mm1,eax + movd ecx,mm0 + sub ebp,eax + and ecx, [inflate_fast_mask+eax*4] + add ebx,ecx + +L_check_window_mmx: + mov [esp+44],esi + mov eax,edi + sub eax, [esp+40] + + cmp eax,ebx + jb L_clip_window_mmx + + mov ecx,edx + mov esi,edi + sub esi,ebx + + sub ecx,3 + mov al, [esi] + mov [edi],al + mov al, [esi+1] + mov dl, [esi+2] + add esi,3 + mov [edi+1],al + mov [edi+2],dl + add edi,3 + rep movsb + + mov esi, [esp+44] + mov ebx, [esp+8] + jmp L_while_test_mmx + +ALIGN 4 +L_check_dist_one_mmx: + cmp ebx,1 + jne L_check_window_mmx + cmp [esp+40],edi + je L_check_window_mmx + + dec edi + mov ecx,edx + mov al, [edi] + sub ecx,3 + + mov [edi+1],al + mov [edi+2],al + mov [edi+3],al + add edi,4 + rep stosb + + mov ebx, [esp+8] + jmp L_while_test_mmx + +ALIGN 4 +L_test_for_second_level_length_mmx: + test al,64 + jnz L_test_for_end_of_block + + and eax,15 + psrlq mm0,mm1 + movd ecx,mm0 + and ecx, [inflate_fast_mask+eax*4] + add ecx,edx + mov eax, [ebx+ecx*4] + jmp L_dolen_mmx + +ALIGN 4 +L_test_for_second_level_dist_mmx: + test al,64 + jnz L_invalid_distance_code + + and eax,15 + psrlq mm0,mm1 + movd ecx,mm0 + and ecx, [inflate_fast_mask+eax*4] + mov eax, [esp+12] + add ecx,ebx + mov eax, [eax+ecx*4] + jmp L_dodist_mmx + +ALIGN 4 +L_clip_window_mmx: + + mov ecx,eax + mov eax, [esp+52] + neg ecx + mov esi, [esp+56] + + cmp eax,ebx + jb L_invalid_distance_too_far + + add ecx,ebx + cmp dword ptr [esp+48],0 + jne L_wrap_around_window_mmx + + sub eax,ecx + add esi,eax + + cmp edx,ecx + jbe L_do_copy1_mmx + + sub edx,ecx + rep movsb + mov esi,edi + sub esi,ebx + jmp L_do_copy1_mmx + + cmp edx,ecx + jbe L_do_copy1_mmx + + sub edx,ecx + rep movsb + mov esi,edi + sub esi,ebx + jmp L_do_copy1_mmx + +L_wrap_around_window_mmx: + + mov eax, [esp+48] + cmp ecx,eax + jbe L_contiguous_in_window_mmx + + add esi, [esp+52] + add esi,eax + sub esi,ecx + sub ecx,eax + + + cmp edx,ecx + jbe L_do_copy1_mmx + + sub edx,ecx + rep movsb + mov esi, [esp+56] + mov ecx, [esp+48] + cmp edx,ecx + jbe L_do_copy1_mmx + + sub edx,ecx + rep movsb + mov esi,edi + sub esi,ebx + jmp L_do_copy1_mmx + +L_contiguous_in_window_mmx: + + add esi,eax + sub esi,ecx + + + cmp edx,ecx + jbe L_do_copy1_mmx + + sub edx,ecx + rep movsb + mov esi,edi + sub esi,ebx + +L_do_copy1_mmx: + + + mov ecx,edx + rep movsb + + mov esi, [esp+44] + mov ebx, [esp+8] + jmp L_while_test_mmx +; 1174 "inffast.S" +L_invalid_distance_code: + + + + + + mov ecx, invalid_distance_code_msg + mov edx,INFLATE_MODE_BAD + jmp L_update_stream_state + +L_test_for_end_of_block: + + + + + + test al,32 + jz L_invalid_literal_length_code + + mov ecx,0 + mov edx,INFLATE_MODE_TYPE + jmp L_update_stream_state + +L_invalid_literal_length_code: + + + + + + mov ecx, invalid_literal_length_code_msg + mov edx,INFLATE_MODE_BAD + jmp L_update_stream_state + +L_invalid_distance_too_far: + + + + mov esi, [esp+44] + mov ecx, invalid_distance_too_far_msg + mov edx,INFLATE_MODE_BAD + jmp L_update_stream_state + +L_update_stream_state: + + mov eax, [esp+88] + test ecx,ecx + jz L_skip_msg + mov [eax+24],ecx +L_skip_msg: + mov eax, [eax+28] + mov [eax+mode_state],edx + jmp L_break_loop + +ALIGN 4 +L_break_loop: +; 1243 "inffast.S" + cmp dword ptr [inflate_fast_use_mmx],2 + jne L_update_next_in + + + + mov ebx,ebp + +L_update_next_in: +; 1266 "inffast.S" + mov eax, [esp+88] + mov ecx,ebx + mov edx, [eax+28] + shr ecx,3 + sub esi,ecx + shl ecx,3 + sub ebx,ecx + mov [eax+12],edi + mov [edx+bits_state],ebx + mov ecx,ebx + + lea ebx, [esp+28] + cmp [esp+20],ebx + jne L_buf_not_used + + sub esi,ebx + mov ebx, [eax+0] + mov [esp+20],ebx + add esi,ebx + mov ebx, [eax+4] + sub ebx,11 + add [esp+20],ebx + +L_buf_not_used: + mov [eax+0],esi + + mov ebx,1 + shl ebx,cl + dec ebx + + + + + + cmp dword ptr [inflate_fast_use_mmx],2 + jne L_update_hold + + + + psrlq mm0,mm1 + movd ebp,mm0 + + emms + +L_update_hold: + + + + and ebp,ebx + mov [edx+hold_state],ebp + + + + + mov ebx, [esp+20] + cmp ebx,esi + jbe L_last_is_smaller + + sub ebx,esi + add ebx,11 + mov [eax+4],ebx + jmp L_fixup_out +L_last_is_smaller: + sub esi,ebx + neg esi + add esi,11 + mov [eax+4],esi + + + + +L_fixup_out: + + mov ebx, [esp+16] + cmp ebx,edi + jbe L_end_is_smaller + + sub ebx,edi + add ebx,257 + mov [eax+16],ebx + jmp L_done +L_end_is_smaller: + sub edi,ebx + neg edi + add edi,257 + mov [eax+16],edi + + + + + +L_done: + add esp,64 + popfd + pop ebx + pop ebp + pop esi + pop edi + ret + +_TEXT ends +end diff --git a/libs/zlib/contrib/masmx86/match686.asm b/libs/zlib/contrib/masmx86/match686.asm new file mode 100644 index 000000000..21ae7041b --- /dev/null +++ b/libs/zlib/contrib/masmx86/match686.asm @@ -0,0 +1,478 @@ +; match686.asm -- Asm portion of the optimized longest_match for 32 bits x86 +; Copyright (C) 1995-1996 Jean-loup Gailly, Brian Raiter and Gilles Vollant. +; File written by Gilles Vollant, by converting match686.S from Brian Raiter +; for MASM. This is as assembly version of longest_match +; from Jean-loup Gailly in deflate.c +; +; http://www.zlib.net +; http://www.winimage.com/zLibDll +; http://www.muppetlabs.com/~breadbox/software/assembly.html +; +; For Visual C++ 4.x and higher and ML 6.x and higher +; ml.exe is distributed in +; http://www.microsoft.com/downloads/details.aspx?FamilyID=7a1c9da0-0510-44a2-b042-7ef370530c64 +; +; this file contain two implementation of longest_match +; +; this longest_match was written by Brian raiter (1998), optimized for Pentium Pro +; (and the faster known version of match_init on modern Core 2 Duo and AMD Phenom) +; +; for using an assembly version of longest_match, you need define ASMV in project +; +; compile the asm file running +; ml /coff /Zi /c /Flmatch686.lst match686.asm +; and do not include match686.obj in your project +; +; note: contrib of zLib 1.2.3 and earlier contained both a deprecated version for +; Pentium (prior Pentium Pro) and this version for Pentium Pro and modern processor +; with autoselect (with cpu detection code) +; if you want support the old pentium optimization, you can still use these version +; +; this file is not optimized for old pentium, but it compatible with all x86 32 bits +; processor (starting 80386) +; +; +; see below : zlib1222add must be adjuster if you use a zlib version < 1.2.2.2 + +;uInt longest_match(s, cur_match) +; deflate_state *s; +; IPos cur_match; /* current match */ + + NbStack equ 76 + cur_match equ dword ptr[esp+NbStack-0] + str_s equ dword ptr[esp+NbStack-4] +; 5 dword on top (ret,ebp,esi,edi,ebx) + adrret equ dword ptr[esp+NbStack-8] + pushebp equ dword ptr[esp+NbStack-12] + pushedi equ dword ptr[esp+NbStack-16] + pushesi equ dword ptr[esp+NbStack-20] + pushebx equ dword ptr[esp+NbStack-24] + + chain_length equ dword ptr [esp+NbStack-28] + limit equ dword ptr [esp+NbStack-32] + best_len equ dword ptr [esp+NbStack-36] + window equ dword ptr [esp+NbStack-40] + prev equ dword ptr [esp+NbStack-44] + scan_start equ word ptr [esp+NbStack-48] + wmask equ dword ptr [esp+NbStack-52] + match_start_ptr equ dword ptr [esp+NbStack-56] + nice_match equ dword ptr [esp+NbStack-60] + scan equ dword ptr [esp+NbStack-64] + + windowlen equ dword ptr [esp+NbStack-68] + match_start equ dword ptr [esp+NbStack-72] + strend equ dword ptr [esp+NbStack-76] + NbStackAdd equ (NbStack-24) + + .386p + + name gvmatch + .MODEL FLAT + + + +; all the +zlib1222add offsets are due to the addition of fields +; in zlib in the deflate_state structure since the asm code was first written +; (if you compile with zlib 1.0.4 or older, use "zlib1222add equ (-4)"). +; (if you compile with zlib between 1.0.5 and 1.2.2.1, use "zlib1222add equ 0"). +; if you compile with zlib 1.2.2.2 or later , use "zlib1222add equ 8"). + + zlib1222add equ 8 + +; Note : these value are good with a 8 bytes boundary pack structure + dep_chain_length equ 74h+zlib1222add + dep_window equ 30h+zlib1222add + dep_strstart equ 64h+zlib1222add + dep_prev_length equ 70h+zlib1222add + dep_nice_match equ 88h+zlib1222add + dep_w_size equ 24h+zlib1222add + dep_prev equ 38h+zlib1222add + dep_w_mask equ 2ch+zlib1222add + dep_good_match equ 84h+zlib1222add + dep_match_start equ 68h+zlib1222add + dep_lookahead equ 6ch+zlib1222add + + +_TEXT segment + +IFDEF NOUNDERLINE + public longest_match + public match_init +ELSE + public _longest_match + public _match_init +ENDIF + + MAX_MATCH equ 258 + MIN_MATCH equ 3 + MIN_LOOKAHEAD equ (MAX_MATCH+MIN_MATCH+1) + + + +MAX_MATCH equ 258 +MIN_MATCH equ 3 +MIN_LOOKAHEAD equ (MAX_MATCH + MIN_MATCH + 1) +MAX_MATCH_8_ equ ((MAX_MATCH + 7) AND 0FFF0h) + + +;;; stack frame offsets + +chainlenwmask equ esp + 0 ; high word: current chain len + ; low word: s->wmask +window equ esp + 4 ; local copy of s->window +windowbestlen equ esp + 8 ; s->window + bestlen +scanstart equ esp + 16 ; first two bytes of string +scanend equ esp + 12 ; last two bytes of string +scanalign equ esp + 20 ; dword-misalignment of string +nicematch equ esp + 24 ; a good enough match size +bestlen equ esp + 28 ; size of best match so far +scan equ esp + 32 ; ptr to string wanting match + +LocalVarsSize equ 36 +; saved ebx byte esp + 36 +; saved edi byte esp + 40 +; saved esi byte esp + 44 +; saved ebp byte esp + 48 +; return address byte esp + 52 +deflatestate equ esp + 56 ; the function arguments +curmatch equ esp + 60 + +;;; Offsets for fields in the deflate_state structure. These numbers +;;; are calculated from the definition of deflate_state, with the +;;; assumption that the compiler will dword-align the fields. (Thus, +;;; changing the definition of deflate_state could easily cause this +;;; program to crash horribly, without so much as a warning at +;;; compile time. Sigh.) + +dsWSize equ 36+zlib1222add +dsWMask equ 44+zlib1222add +dsWindow equ 48+zlib1222add +dsPrev equ 56+zlib1222add +dsMatchLen equ 88+zlib1222add +dsPrevMatch equ 92+zlib1222add +dsStrStart equ 100+zlib1222add +dsMatchStart equ 104+zlib1222add +dsLookahead equ 108+zlib1222add +dsPrevLen equ 112+zlib1222add +dsMaxChainLen equ 116+zlib1222add +dsGoodMatch equ 132+zlib1222add +dsNiceMatch equ 136+zlib1222add + + +;;; match686.asm -- Pentium-Pro-optimized version of longest_match() +;;; Written for zlib 1.1.2 +;;; Copyright (C) 1998 Brian Raiter +;;; You can look at http://www.muppetlabs.com/~breadbox/software/assembly.html +;;; +;; +;; This software is provided 'as-is', without any express or implied +;; warranty. In no event will the authors be held liable for any damages +;; arising from the use of this software. +;; +;; Permission is granted to anyone to use this software for any purpose, +;; including commercial applications, and to alter it and redistribute it +;; freely, subject to the following restrictions: +;; +;; 1. The origin of this software must not be misrepresented; you must not +;; claim that you wrote the original software. If you use this software +;; in a product, an acknowledgment in the product documentation would be +;; appreciated but is not required. +;; 2. Altered source versions must be plainly marked as such, and must not be +;; misrepresented as being the original software +;; 3. This notice may not be removed or altered from any source distribution. +;; + +;GLOBAL _longest_match, _match_init + + +;SECTION .text + +;;; uInt longest_match(deflate_state *deflatestate, IPos curmatch) + +;_longest_match: + IFDEF NOUNDERLINE + longest_match proc near + ELSE + _longest_match proc near + ENDIF + +;;; Save registers that the compiler may be using, and adjust esp to +;;; make room for our stack frame. + + push ebp + push edi + push esi + push ebx + sub esp, LocalVarsSize + +;;; Retrieve the function arguments. ecx will hold cur_match +;;; throughout the entire function. edx will hold the pointer to the +;;; deflate_state structure during the function's setup (before +;;; entering the main loop. + + mov edx, [deflatestate] + mov ecx, [curmatch] + +;;; uInt wmask = s->w_mask; +;;; unsigned chain_length = s->max_chain_length; +;;; if (s->prev_length >= s->good_match) { +;;; chain_length >>= 2; +;;; } + + mov eax, [edx + dsPrevLen] + mov ebx, [edx + dsGoodMatch] + cmp eax, ebx + mov eax, [edx + dsWMask] + mov ebx, [edx + dsMaxChainLen] + jl LastMatchGood + shr ebx, 2 +LastMatchGood: + +;;; chainlen is decremented once beforehand so that the function can +;;; use the sign flag instead of the zero flag for the exit test. +;;; It is then shifted into the high word, to make room for the wmask +;;; value, which it will always accompany. + + dec ebx + shl ebx, 16 + or ebx, eax + mov [chainlenwmask], ebx + +;;; if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead; + + mov eax, [edx + dsNiceMatch] + mov ebx, [edx + dsLookahead] + cmp ebx, eax + jl LookaheadLess + mov ebx, eax +LookaheadLess: mov [nicematch], ebx + +;;; register Bytef *scan = s->window + s->strstart; + + mov esi, [edx + dsWindow] + mov [window], esi + mov ebp, [edx + dsStrStart] + lea edi, [esi + ebp] + mov [scan], edi + +;;; Determine how many bytes the scan ptr is off from being +;;; dword-aligned. + + mov eax, edi + neg eax + and eax, 3 + mov [scanalign], eax + +;;; IPos limit = s->strstart > (IPos)MAX_DIST(s) ? +;;; s->strstart - (IPos)MAX_DIST(s) : NIL; + + mov eax, [edx + dsWSize] + sub eax, MIN_LOOKAHEAD + sub ebp, eax + jg LimitPositive + xor ebp, ebp +LimitPositive: + +;;; int best_len = s->prev_length; + + mov eax, [edx + dsPrevLen] + mov [bestlen], eax + +;;; Store the sum of s->window + best_len in esi locally, and in esi. + + add esi, eax + mov [windowbestlen], esi + +;;; register ush scan_start = *(ushf*)scan; +;;; register ush scan_end = *(ushf*)(scan+best_len-1); +;;; Posf *prev = s->prev; + + movzx ebx, word ptr [edi] + mov [scanstart], ebx + movzx ebx, word ptr [edi + eax - 1] + mov [scanend], ebx + mov edi, [edx + dsPrev] + +;;; Jump into the main loop. + + mov edx, [chainlenwmask] + jmp short LoopEntry + +align 4 + +;;; do { +;;; match = s->window + cur_match; +;;; if (*(ushf*)(match+best_len-1) != scan_end || +;;; *(ushf*)match != scan_start) continue; +;;; [...] +;;; } while ((cur_match = prev[cur_match & wmask]) > limit +;;; && --chain_length != 0); +;;; +;;; Here is the inner loop of the function. The function will spend the +;;; majority of its time in this loop, and majority of that time will +;;; be spent in the first ten instructions. +;;; +;;; Within this loop: +;;; ebx = scanend +;;; ecx = curmatch +;;; edx = chainlenwmask - i.e., ((chainlen << 16) | wmask) +;;; esi = windowbestlen - i.e., (window + bestlen) +;;; edi = prev +;;; ebp = limit + +LookupLoop: + and ecx, edx + movzx ecx, word ptr [edi + ecx*2] + cmp ecx, ebp + jbe LeaveNow + sub edx, 00010000h + js LeaveNow +LoopEntry: movzx eax, word ptr [esi + ecx - 1] + cmp eax, ebx + jnz LookupLoop + mov eax, [window] + movzx eax, word ptr [eax + ecx] + cmp eax, [scanstart] + jnz LookupLoop + +;;; Store the current value of chainlen. + + mov [chainlenwmask], edx + +;;; Point edi to the string under scrutiny, and esi to the string we +;;; are hoping to match it up with. In actuality, esi and edi are +;;; both pointed (MAX_MATCH_8 - scanalign) bytes ahead, and edx is +;;; initialized to -(MAX_MATCH_8 - scanalign). + + mov esi, [window] + mov edi, [scan] + add esi, ecx + mov eax, [scanalign] + mov edx, 0fffffef8h; -(MAX_MATCH_8) + lea edi, [edi + eax + 0108h] ;MAX_MATCH_8] + lea esi, [esi + eax + 0108h] ;MAX_MATCH_8] + +;;; Test the strings for equality, 8 bytes at a time. At the end, +;;; adjust edx so that it is offset to the exact byte that mismatched. +;;; +;;; We already know at this point that the first three bytes of the +;;; strings match each other, and they can be safely passed over before +;;; starting the compare loop. So what this code does is skip over 0-3 +;;; bytes, as much as necessary in order to dword-align the edi +;;; pointer. (esi will still be misaligned three times out of four.) +;;; +;;; It should be confessed that this loop usually does not represent +;;; much of the total running time. Replacing it with a more +;;; straightforward "rep cmpsb" would not drastically degrade +;;; performance. + +LoopCmps: + mov eax, [esi + edx] + xor eax, [edi + edx] + jnz LeaveLoopCmps + mov eax, [esi + edx + 4] + xor eax, [edi + edx + 4] + jnz LeaveLoopCmps4 + add edx, 8 + jnz LoopCmps + jmp short LenMaximum +LeaveLoopCmps4: add edx, 4 +LeaveLoopCmps: test eax, 0000FFFFh + jnz LenLower + add edx, 2 + shr eax, 16 +LenLower: sub al, 1 + adc edx, 0 + +;;; Calculate the length of the match. If it is longer than MAX_MATCH, +;;; then automatically accept it as the best possible match and leave. + + lea eax, [edi + edx] + mov edi, [scan] + sub eax, edi + cmp eax, MAX_MATCH + jge LenMaximum + +;;; If the length of the match is not longer than the best match we +;;; have so far, then forget it and return to the lookup loop. + + mov edx, [deflatestate] + mov ebx, [bestlen] + cmp eax, ebx + jg LongerMatch + mov esi, [windowbestlen] + mov edi, [edx + dsPrev] + mov ebx, [scanend] + mov edx, [chainlenwmask] + jmp LookupLoop + +;;; s->match_start = cur_match; +;;; best_len = len; +;;; if (len >= nice_match) break; +;;; scan_end = *(ushf*)(scan+best_len-1); + +LongerMatch: mov ebx, [nicematch] + mov [bestlen], eax + mov [edx + dsMatchStart], ecx + cmp eax, ebx + jge LeaveNow + mov esi, [window] + add esi, eax + mov [windowbestlen], esi + movzx ebx, word ptr [edi + eax - 1] + mov edi, [edx + dsPrev] + mov [scanend], ebx + mov edx, [chainlenwmask] + jmp LookupLoop + +;;; Accept the current string, with the maximum possible length. + +LenMaximum: mov edx, [deflatestate] + mov dword ptr [bestlen], MAX_MATCH + mov [edx + dsMatchStart], ecx + +;;; if ((uInt)best_len <= s->lookahead) return (uInt)best_len; +;;; return s->lookahead; + +LeaveNow: + mov edx, [deflatestate] + mov ebx, [bestlen] + mov eax, [edx + dsLookahead] + cmp ebx, eax + jg LookaheadRet + mov eax, ebx +LookaheadRet: + +;;; Restore the stack and return from whence we came. + + add esp, LocalVarsSize + pop ebx + pop esi + pop edi + pop ebp + + ret +; please don't remove this string ! +; Your can freely use match686 in any free or commercial app if you don't remove the string in the binary! + db 0dh,0ah,"asm686 with masm, optimised assembly code from Brian Raiter, written 1998",0dh,0ah + + + IFDEF NOUNDERLINE + longest_match endp + ELSE + _longest_match endp + ENDIF + + IFDEF NOUNDERLINE + match_init proc near + ret + match_init endp + ELSE + _match_init proc near + ret + _match_init endp + ENDIF + + +_TEXT ends +end diff --git a/libs/zlib/contrib/masmx86/readme.txt b/libs/zlib/contrib/masmx86/readme.txt new file mode 100644 index 000000000..3f8888679 --- /dev/null +++ b/libs/zlib/contrib/masmx86/readme.txt @@ -0,0 +1,27 @@ + +Summary +------- +This directory contains ASM implementations of the functions +longest_match() and inflate_fast(). + + +Use instructions +---------------- +Assemble using MASM, and copy the object files into the zlib source +directory, then run the appropriate makefile, as suggested below. You can +donwload MASM from here: + + http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=7a1c9da0-0510-44a2-b042-7ef370530c64 + +You can also get objects files here: + + http://www.winimage.com/zLibDll/zlib124_masm_obj.zip + +Build instructions +------------------ +* With Microsoft C and MASM: +nmake -f win32/Makefile.msc LOC="-DASMV -DASMINF" OBJA="match686.obj inffas32.obj" + +* With Borland C and TASM: +make -f win32/Makefile.bor LOCAL_ZLIB="-DASMV -DASMINF" OBJA="match686.obj inffas32.obj" OBJPA="+match686c.obj+match686.obj+inffas32.obj" + diff --git a/libs/zlib/contrib/minizip/Makefile b/libs/zlib/contrib/minizip/Makefile new file mode 100644 index 000000000..84eaad20d --- /dev/null +++ b/libs/zlib/contrib/minizip/Makefile @@ -0,0 +1,25 @@ +CC=cc +CFLAGS=-O -I../.. + +UNZ_OBJS = miniunz.o unzip.o ioapi.o ../../libz.a +ZIP_OBJS = minizip.o zip.o ioapi.o ../../libz.a + +.c.o: + $(CC) -c $(CFLAGS) $*.c + +all: miniunz minizip + +miniunz: $(UNZ_OBJS) + $(CC) $(CFLAGS) -o $@ $(UNZ_OBJS) + +minizip: $(ZIP_OBJS) + $(CC) $(CFLAGS) -o $@ $(ZIP_OBJS) + +test: miniunz minizip + ./minizip test readme.txt + ./miniunz -l test.zip + mv readme.txt readme.old + ./miniunz test.zip + +clean: + /bin/rm -f *.o *~ minizip miniunz diff --git a/libs/zlib/contrib/minizip/MiniZip64_Changes.txt b/libs/zlib/contrib/minizip/MiniZip64_Changes.txt new file mode 100644 index 000000000..13a1bd91a --- /dev/null +++ b/libs/zlib/contrib/minizip/MiniZip64_Changes.txt @@ -0,0 +1,6 @@ + +MiniZip 1.1 was derrived from MiniZip at version 1.01f + +Change in 1.0 (Okt 2009) + - **TODO - Add history** + diff --git a/libs/zlib/contrib/minizip/MiniZip64_info.txt b/libs/zlib/contrib/minizip/MiniZip64_info.txt new file mode 100644 index 000000000..57d715242 --- /dev/null +++ b/libs/zlib/contrib/minizip/MiniZip64_info.txt @@ -0,0 +1,74 @@ +MiniZip - Copyright (c) 1998-2010 - by Gilles Vollant - version 1.1 64 bits from Mathias Svensson + +Introduction +--------------------- +MiniZip 1.1 is built from MiniZip 1.0 by Gilles Vollant ( http://www.winimage.com/zLibDll/minizip.html ) + +When adding ZIP64 support into minizip it would result into risk of breaking compatibility with minizip 1.0. +All possible work was done for compatibility. + + +Background +--------------------- +When adding ZIP64 support Mathias Svensson found that Even Rouault have added ZIP64 +support for unzip.c into minizip for a open source project called gdal ( http://www.gdal.org/ ) + +That was used as a starting point. And after that ZIP64 support was added to zip.c +some refactoring and code cleanup was also done. + + +Changed from MiniZip 1.0 to MiniZip 1.1 +--------------------------------------- +* Added ZIP64 support for unzip ( by Even Rouault ) +* Added ZIP64 support for zip ( by Mathias Svensson ) +* Reverted some changed that Even Rouault did. +* Bunch of patches received from Gulles Vollant that he received for MiniZip from various users. +* Added unzip patch for BZIP Compression method (patch create by Daniel Borca) +* Added BZIP Compress method for zip +* Did some refactoring and code cleanup + + +Credits + + Gilles Vollant - Original MiniZip author + Even Rouault - ZIP64 unzip Support + Daniel Borca - BZip Compression method support in unzip + Mathias Svensson - ZIP64 zip support + Mathias Svensson - BZip Compression method support in zip + + Resources + + ZipLayout http://result42.com/projects/ZipFileLayout + Command line tool for Windows that shows the layout and information of the headers in a zip archive. + Used when debugging and validating the creation of zip files using MiniZip64 + + + ZIP App Note http://www.pkware.com/documents/casestudies/APPNOTE.TXT + Zip File specification + + +Notes. + * To be able to use BZip compression method in zip64.c or unzip64.c the BZIP2 lib is needed and HAVE_BZIP2 need to be defined. + +License +---------------------------------------------------------- + Condition of use and distribution are the same than zlib : + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + +---------------------------------------------------------- + diff --git a/libs/zlib/contrib/minizip/crypt.h b/libs/zlib/contrib/minizip/crypt.h new file mode 100644 index 000000000..a01d08d93 --- /dev/null +++ b/libs/zlib/contrib/minizip/crypt.h @@ -0,0 +1,131 @@ +/* crypt.h -- base code for crypt/uncrypt ZIPfile + + + Version 1.01e, February 12th, 2005 + + Copyright (C) 1998-2005 Gilles Vollant + + This code is a modified version of crypting code in Infozip distribution + + The encryption/decryption parts of this source code (as opposed to the + non-echoing password parts) were originally written in Europe. The + whole source package can be freely distributed, including from the USA. + (Prior to January 2000, re-export from the US was a violation of US law.) + + This encryption code is a direct transcription of the algorithm from + Roger Schlafly, described by Phil Katz in the file appnote.txt. This + file (appnote.txt) is distributed with the PKZIP program (even in the + version without encryption capabilities). + + If you don't need crypting in your application, just define symbols + NOCRYPT and NOUNCRYPT. + + This code support the "Traditional PKWARE Encryption". + + The new AES encryption added on Zip format by Winzip (see the page + http://www.winzip.com/aes_info.htm ) and PKWare PKZip 5.x Strong + Encryption is not supported. +*/ + +#define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8)) + +/*********************************************************************** + * Return the next byte in the pseudo-random sequence + */ +static int decrypt_byte(unsigned long* pkeys, const unsigned long* pcrc_32_tab) +{ + unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an + * unpredictable manner on 16-bit systems; not a problem + * with any known compiler so far, though */ + + temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2; + return (int)(((temp * (temp ^ 1)) >> 8) & 0xff); +} + +/*********************************************************************** + * Update the encryption keys with the next byte of plain text + */ +static int update_keys(unsigned long* pkeys,const unsigned long* pcrc_32_tab,int c) +{ + (*(pkeys+0)) = CRC32((*(pkeys+0)), c); + (*(pkeys+1)) += (*(pkeys+0)) & 0xff; + (*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1; + { + register int keyshift = (int)((*(pkeys+1)) >> 24); + (*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift); + } + return c; +} + + +/*********************************************************************** + * Initialize the encryption keys and the random header according to + * the given password. + */ +static void init_keys(const char* passwd,unsigned long* pkeys,const unsigned long* pcrc_32_tab) +{ + *(pkeys+0) = 305419896L; + *(pkeys+1) = 591751049L; + *(pkeys+2) = 878082192L; + while (*passwd != '\0') { + update_keys(pkeys,pcrc_32_tab,(int)*passwd); + passwd++; + } +} + +#define zdecode(pkeys,pcrc_32_tab,c) \ + (update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab))) + +#define zencode(pkeys,pcrc_32_tab,c,t) \ + (t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c)) + +#ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED + +#define RAND_HEAD_LEN 12 + /* "last resort" source for second part of crypt seed pattern */ +# ifndef ZCR_SEED2 +# define ZCR_SEED2 3141592654UL /* use PI as default pattern */ +# endif + +static int crypthead(const char* passwd, /* password string */ + unsigned char* buf, /* where to write header */ + int bufSize, + unsigned long* pkeys, + const unsigned long* pcrc_32_tab, + unsigned long crcForCrypting) +{ + int n; /* index in random header */ + int t; /* temporary */ + int c; /* random byte */ + unsigned char header[RAND_HEAD_LEN-2]; /* random header */ + static unsigned calls = 0; /* ensure different random header each time */ + + if (bufSize> 7) & 0xff; + header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t); + } + /* Encrypt random header (last two bytes is high word of crc) */ + init_keys(passwd, pkeys, pcrc_32_tab); + for (n = 0; n < RAND_HEAD_LEN-2; n++) + { + buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t); + } + buf[n++] = (unsigned char)zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t); + buf[n++] = (unsigned char)zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t); + return n; +} + +#endif diff --git a/libs/zlib/contrib/minizip/ioapi.c b/libs/zlib/contrib/minizip/ioapi.c new file mode 100644 index 000000000..49958f61f --- /dev/null +++ b/libs/zlib/contrib/minizip/ioapi.c @@ -0,0 +1,235 @@ +/* ioapi.h -- IO base function header for compress/uncompress .zip + part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) + + Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) + + Modifications for Zip64 support + Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) + + For more info read MiniZip_info.txt + +*/ + +#if (defined(_WIN32)) + #define _CRT_SECURE_NO_WARNINGS +#endif + +#include "ioapi.h" + +voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode) +{ + if (pfilefunc->zfile_func64.zopen64_file != NULL) + return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func64.opaque,filename,mode); + else + { + return (*(pfilefunc->zopen32_file))(pfilefunc->zfile_func64.opaque,(const char*)filename,mode); + } +} + +long call_zseek64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin) +{ + if (pfilefunc->zfile_func64.zseek64_file != NULL) + return (*(pfilefunc->zfile_func64.zseek64_file)) (pfilefunc->zfile_func64.opaque,filestream,offset,origin); + else + { + uLong offsetTruncated = (uLong)offset; + if (offsetTruncated != offset) + return -1; + else + return (*(pfilefunc->zseek32_file))(pfilefunc->zfile_func64.opaque,filestream,offsetTruncated,origin); + } +} + +ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream) +{ + if (pfilefunc->zfile_func64.zseek64_file != NULL) + return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func64.opaque,filestream); + else + { + uLong tell_uLong = (*(pfilefunc->ztell32_file))(pfilefunc->zfile_func64.opaque,filestream); + if ((tell_uLong) == ((uLong)-1)) + return (ZPOS64_T)-1; + else + return tell_uLong; + } +} + +void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32) +{ + p_filefunc64_32->zfile_func64.zopen64_file = NULL; + p_filefunc64_32->zopen32_file = p_filefunc32->zopen_file; + p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file; + p_filefunc64_32->zfile_func64.zread_file = p_filefunc32->zread_file; + p_filefunc64_32->zfile_func64.zwrite_file = p_filefunc32->zwrite_file; + p_filefunc64_32->zfile_func64.ztell64_file = NULL; + p_filefunc64_32->zfile_func64.zseek64_file = NULL; + p_filefunc64_32->zfile_func64.zclose_file = p_filefunc32->zclose_file; + p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file; + p_filefunc64_32->zfile_func64.opaque = p_filefunc32->opaque; + p_filefunc64_32->zseek32_file = p_filefunc32->zseek_file; + p_filefunc64_32->ztell32_file = p_filefunc32->ztell_file; +} + + + +static voidpf ZCALLBACK fopen_file_func OF((voidpf opaque, const char* filename, int mode)); +static uLong ZCALLBACK fread_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size)); +static uLong ZCALLBACK fwrite_file_func OF((voidpf opaque, voidpf stream, const void* buf,uLong size)); +static ZPOS64_T ZCALLBACK ftell64_file_func OF((voidpf opaque, voidpf stream)); +static long ZCALLBACK fseek64_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)); +static int ZCALLBACK fclose_file_func OF((voidpf opaque, voidpf stream)); +static int ZCALLBACK ferror_file_func OF((voidpf opaque, voidpf stream)); + +static voidpf ZCALLBACK fopen_file_func (voidpf opaque, const char* filename, int mode) +{ + FILE* file = NULL; + const char* mode_fopen = NULL; + if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) + mode_fopen = "rb"; + else + if (mode & ZLIB_FILEFUNC_MODE_EXISTING) + mode_fopen = "r+b"; + else + if (mode & ZLIB_FILEFUNC_MODE_CREATE) + mode_fopen = "wb"; + + if ((filename!=NULL) && (mode_fopen != NULL)) + file = fopen(filename, mode_fopen); + return file; +} + +static voidpf ZCALLBACK fopen64_file_func (voidpf opaque, const void* filename, int mode) +{ + FILE* file = NULL; + const char* mode_fopen = NULL; + if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) + mode_fopen = "rb"; + else + if (mode & ZLIB_FILEFUNC_MODE_EXISTING) + mode_fopen = "r+b"; + else + if (mode & ZLIB_FILEFUNC_MODE_CREATE) + mode_fopen = "wb"; + + if ((filename!=NULL) && (mode_fopen != NULL)) + file = fopen64((const char*)filename, mode_fopen); + return file; +} + + +static uLong ZCALLBACK fread_file_func (voidpf opaque, voidpf stream, void* buf, uLong size) +{ + uLong ret; + ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream); + return ret; +} + +static uLong ZCALLBACK fwrite_file_func (voidpf opaque, voidpf stream, const void* buf, uLong size) +{ + uLong ret; + ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream); + return ret; +} + +static long ZCALLBACK ftell_file_func (voidpf opaque, voidpf stream) +{ + long ret; + ret = ftell((FILE *)stream); + return ret; +} + + +static ZPOS64_T ZCALLBACK ftell64_file_func (voidpf opaque, voidpf stream) +{ + ZPOS64_T ret; + ret = ftello64((FILE *)stream); + return ret; +} + +static long ZCALLBACK fseek_file_func (voidpf opaque, voidpf stream, uLong offset, int origin) +{ + int fseek_origin=0; + long ret; + switch (origin) + { + case ZLIB_FILEFUNC_SEEK_CUR : + fseek_origin = SEEK_CUR; + break; + case ZLIB_FILEFUNC_SEEK_END : + fseek_origin = SEEK_END; + break; + case ZLIB_FILEFUNC_SEEK_SET : + fseek_origin = SEEK_SET; + break; + default: return -1; + } + ret = 0; + if (fseek((FILE *)stream, offset, fseek_origin) != 0) + ret = -1; + return ret; +} + +static long ZCALLBACK fseek64_file_func (voidpf opaque, voidpf stream, ZPOS64_T offset, int origin) +{ + int fseek_origin=0; + long ret; + switch (origin) + { + case ZLIB_FILEFUNC_SEEK_CUR : + fseek_origin = SEEK_CUR; + break; + case ZLIB_FILEFUNC_SEEK_END : + fseek_origin = SEEK_END; + break; + case ZLIB_FILEFUNC_SEEK_SET : + fseek_origin = SEEK_SET; + break; + default: return -1; + } + ret = 0; + + if(fseeko64((FILE *)stream, offset, fseek_origin) != 0) + ret = -1; + + return ret; +} + + +static int ZCALLBACK fclose_file_func (voidpf opaque, voidpf stream) +{ + int ret; + ret = fclose((FILE *)stream); + return ret; +} + +static int ZCALLBACK ferror_file_func (voidpf opaque, voidpf stream) +{ + int ret; + ret = ferror((FILE *)stream); + return ret; +} + +void fill_fopen_filefunc (pzlib_filefunc_def) + zlib_filefunc_def* pzlib_filefunc_def; +{ + pzlib_filefunc_def->zopen_file = fopen_file_func; + pzlib_filefunc_def->zread_file = fread_file_func; + pzlib_filefunc_def->zwrite_file = fwrite_file_func; + pzlib_filefunc_def->ztell_file = ftell_file_func; + pzlib_filefunc_def->zseek_file = fseek_file_func; + pzlib_filefunc_def->zclose_file = fclose_file_func; + pzlib_filefunc_def->zerror_file = ferror_file_func; + pzlib_filefunc_def->opaque = NULL; +} + +void fill_fopen64_filefunc (zlib_filefunc64_def* pzlib_filefunc_def) +{ + pzlib_filefunc_def->zopen64_file = fopen64_file_func; + pzlib_filefunc_def->zread_file = fread_file_func; + pzlib_filefunc_def->zwrite_file = fwrite_file_func; + pzlib_filefunc_def->ztell64_file = ftell64_file_func; + pzlib_filefunc_def->zseek64_file = fseek64_file_func; + pzlib_filefunc_def->zclose_file = fclose_file_func; + pzlib_filefunc_def->zerror_file = ferror_file_func; + pzlib_filefunc_def->opaque = NULL; +} diff --git a/libs/zlib/contrib/minizip/ioapi.h b/libs/zlib/contrib/minizip/ioapi.h new file mode 100644 index 000000000..8309c4cf8 --- /dev/null +++ b/libs/zlib/contrib/minizip/ioapi.h @@ -0,0 +1,200 @@ +/* ioapi.h -- IO base function header for compress/uncompress .zip + part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) + + Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) + + Modifications for Zip64 support + Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) + + For more info read MiniZip_info.txt + + Changes + + Oct-2009 - Defined ZPOS64_T to fpos_t on windows and u_int64_t on linux. (might need to find a better why for this) + Oct-2009 - Change to fseeko64, ftello64 and fopen64 so large files would work on linux. + More if/def section may be needed to support other platforms + Oct-2009 - Defined fxxxx64 calls to normal fopen/ftell/fseek so they would compile on windows. + (but you should use iowin32.c for windows instead) + +*/ + +#ifndef _ZLIBIOAPI64_H +#define _ZLIBIOAPI64_H + +#if (!defined(_WIN32)) && (!defined(WIN32)) + + // Linux needs this to support file operation on files larger then 4+GB + // But might need better if/def to select just the platforms that needs them. + + #ifndef __USE_FILE_OFFSET64 + #define __USE_FILE_OFFSET64 + #endif + #ifndef __USE_LARGEFILE64 + #define __USE_LARGEFILE64 + #endif + #ifndef _LARGEFILE64_SOURCE + #define _LARGEFILE64_SOURCE + #endif + #ifndef _FILE_OFFSET_BIT + #define _FILE_OFFSET_BIT 64 + #endif +#endif + +#include +#include +#include "zlib.h" + +#if defined(USE_FILE32API) +#define fopen64 fopen +#define ftello64 ftell +#define fseeko64 fseek +#else +#ifdef _MSC_VER + #define fopen64 fopen + #if (_MSC_VER >= 1400) && (!(defined(NO_MSCVER_FILE64_FUNC))) + #define ftello64 _ftelli64 + #define fseeko64 _fseeki64 + #else // old MSC + #define ftello64 ftell + #define fseeko64 fseek + #endif +#endif +#endif + +/* +#ifndef ZPOS64_T + #ifdef _WIN32 + #define ZPOS64_T fpos_t + #else + #include + #define ZPOS64_T uint64_t + #endif +#endif +*/ + +#ifdef HAVE_MINIZIP64_CONF_H +#include "mz64conf.h" +#endif + +/* a type choosen by DEFINE */ +#ifdef HAVE_64BIT_INT_CUSTOM +typedef 64BIT_INT_CUSTOM_TYPE ZPOS64_T; +#else +#ifdef HAS_STDINT_H +#include "stdint.h" +typedef uint64_t ZPOS64_T; +#else + + +#if defined(_MSC_VER) || defined(__BORLANDC__) +typedef unsigned __int64 ZPOS64_T; +#else +typedef unsigned long long int ZPOS64_T; +#endif +#endif +#endif + + + +#ifdef __cplusplus +extern "C" { +#endif + + +#define ZLIB_FILEFUNC_SEEK_CUR (1) +#define ZLIB_FILEFUNC_SEEK_END (2) +#define ZLIB_FILEFUNC_SEEK_SET (0) + +#define ZLIB_FILEFUNC_MODE_READ (1) +#define ZLIB_FILEFUNC_MODE_WRITE (2) +#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3) + +#define ZLIB_FILEFUNC_MODE_EXISTING (4) +#define ZLIB_FILEFUNC_MODE_CREATE (8) + + +#ifndef ZCALLBACK + #if (defined(WIN32) || defined(_WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK) + #define ZCALLBACK CALLBACK + #else + #define ZCALLBACK + #endif +#endif + + + + +typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode)); +typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size)); +typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size)); +typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream)); +typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream)); + +typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream)); +typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin)); + + +/* here is the "old" 32 bits structure structure */ +typedef struct zlib_filefunc_def_s +{ + open_file_func zopen_file; + read_file_func zread_file; + write_file_func zwrite_file; + tell_file_func ztell_file; + seek_file_func zseek_file; + close_file_func zclose_file; + testerror_file_func zerror_file; + voidpf opaque; +} zlib_filefunc_def; + +typedef ZPOS64_T (ZCALLBACK *tell64_file_func) OF((voidpf opaque, voidpf stream)); +typedef long (ZCALLBACK *seek64_file_func) OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)); +typedef voidpf (ZCALLBACK *open64_file_func) OF((voidpf opaque, const void* filename, int mode)); + +typedef struct zlib_filefunc64_def_s +{ + open64_file_func zopen64_file; + read_file_func zread_file; + write_file_func zwrite_file; + tell64_file_func ztell64_file; + seek64_file_func zseek64_file; + close_file_func zclose_file; + testerror_file_func zerror_file; + voidpf opaque; +} zlib_filefunc64_def; + +void fill_fopen64_filefunc OF((zlib_filefunc64_def* pzlib_filefunc_def)); +void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def)); + +/* now internal definition, only for zip.c and unzip.h */ +typedef struct zlib_filefunc64_32_def_s +{ + zlib_filefunc64_def zfile_func64; + open_file_func zopen32_file; + tell_file_func ztell32_file; + seek_file_func zseek32_file; +} zlib_filefunc64_32_def; + + +#define ZREAD64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zread_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size)) +#define ZWRITE64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zwrite_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size)) +//#define ZTELL64(filefunc,filestream) ((*((filefunc).ztell64_file)) ((filefunc).opaque,filestream)) +//#define ZSEEK64(filefunc,filestream,pos,mode) ((*((filefunc).zseek64_file)) ((filefunc).opaque,filestream,pos,mode)) +#define ZCLOSE64(filefunc,filestream) ((*((filefunc).zfile_func64.zclose_file)) ((filefunc).zfile_func64.opaque,filestream)) +#define ZERROR64(filefunc,filestream) ((*((filefunc).zfile_func64.zerror_file)) ((filefunc).zfile_func64.opaque,filestream)) + +voidpf call_zopen64 OF((const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode)); +long call_zseek64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin)); +ZPOS64_T call_ztell64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream)); + +void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32); + +#define ZOPEN64(filefunc,filename,mode) (call_zopen64((&(filefunc)),(filename),(mode))) +#define ZTELL64(filefunc,filestream) (call_ztell64((&(filefunc)),(filestream))) +#define ZSEEK64(filefunc,filestream,pos,mode) (call_zseek64((&(filefunc)),(filestream),(pos),(mode))) + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libs/zlib/contrib/minizip/iowin32.c b/libs/zlib/contrib/minizip/iowin32.c new file mode 100644 index 000000000..6a2a883be --- /dev/null +++ b/libs/zlib/contrib/minizip/iowin32.c @@ -0,0 +1,389 @@ +/* iowin32.c -- IO base function header for compress/uncompress .zip + Version 1.1, February 14h, 2010 + part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) + + Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) + + Modifications for Zip64 support + Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) + + For more info read MiniZip_info.txt + +*/ + +#include + +#include "zlib.h" +#include "ioapi.h" +#include "iowin32.h" + +#ifndef INVALID_HANDLE_VALUE +#define INVALID_HANDLE_VALUE (0xFFFFFFFF) +#endif + +#ifndef INVALID_SET_FILE_POINTER +#define INVALID_SET_FILE_POINTER ((DWORD)-1) +#endif + +voidpf ZCALLBACK win32_open_file_func OF((voidpf opaque, const char* filename, int mode)); +uLong ZCALLBACK win32_read_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size)); +uLong ZCALLBACK win32_write_file_func OF((voidpf opaque, voidpf stream, const void* buf, uLong size)); +ZPOS64_T ZCALLBACK win32_tell64_file_func OF((voidpf opaque, voidpf stream)); +long ZCALLBACK win32_seek64_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)); +int ZCALLBACK win32_close_file_func OF((voidpf opaque, voidpf stream)); +int ZCALLBACK win32_error_file_func OF((voidpf opaque, voidpf stream)); + +typedef struct +{ + HANDLE hf; + int error; +} WIN32FILE_IOWIN; + + +static void win32_translate_open_mode(int mode, + DWORD* lpdwDesiredAccess, + DWORD* lpdwCreationDisposition, + DWORD* lpdwShareMode, + DWORD* lpdwFlagsAndAttributes) +{ + *lpdwDesiredAccess = *lpdwShareMode = *lpdwFlagsAndAttributes = *lpdwCreationDisposition = 0; + + if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) + { + *lpdwDesiredAccess = GENERIC_READ; + *lpdwCreationDisposition = OPEN_EXISTING; + *lpdwShareMode = FILE_SHARE_READ; + } + else if (mode & ZLIB_FILEFUNC_MODE_EXISTING) + { + *lpdwDesiredAccess = GENERIC_WRITE | GENERIC_READ; + *lpdwCreationDisposition = OPEN_EXISTING; + } + else if (mode & ZLIB_FILEFUNC_MODE_CREATE) + { + *lpdwDesiredAccess = GENERIC_WRITE | GENERIC_READ; + *lpdwCreationDisposition = CREATE_ALWAYS; + } +} + +static voidpf win32_build_iowin(HANDLE hFile) +{ + voidpf ret=NULL; + + if ((hFile != NULL) && (hFile != INVALID_HANDLE_VALUE)) + { + WIN32FILE_IOWIN w32fiow; + w32fiow.hf = hFile; + w32fiow.error = 0; + ret = malloc(sizeof(WIN32FILE_IOWIN)); + + if (ret==NULL) + CloseHandle(hFile); + else + *((WIN32FILE_IOWIN*)ret) = w32fiow; + } + return ret; +} + +voidpf ZCALLBACK win32_open64_file_func (voidpf opaque,const void* filename,int mode) +{ + const char* mode_fopen = NULL; + DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ; + HANDLE hFile = NULL; + + win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes); + + if ((filename!=NULL) && (dwDesiredAccess != 0)) + hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL); + + return win32_build_iowin(hFile); +} + + +voidpf ZCALLBACK win32_open64_file_funcA (voidpf opaque,const void* filename,int mode) +{ + const char* mode_fopen = NULL; + DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ; + HANDLE hFile = NULL; + + win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes); + + if ((filename!=NULL) && (dwDesiredAccess != 0)) + hFile = CreateFileA((LPCSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL); + + return win32_build_iowin(hFile); +} + + +voidpf ZCALLBACK win32_open64_file_funcW (voidpf opaque,const void* filename,int mode) +{ + const char* mode_fopen = NULL; + DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ; + HANDLE hFile = NULL; + + win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes); + + if ((filename!=NULL) && (dwDesiredAccess != 0)) + hFile = CreateFileW((LPCWSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL); + + return win32_build_iowin(hFile); +} + + +voidpf ZCALLBACK win32_open_file_func (voidpf opaque,const char* filename,int mode) +{ + const char* mode_fopen = NULL; + DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ; + HANDLE hFile = NULL; + + win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes); + + if ((filename!=NULL) && (dwDesiredAccess != 0)) + hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL); + + return win32_build_iowin(hFile); +} + + +uLong ZCALLBACK win32_read_file_func (voidpf opaque, voidpf stream, void* buf,uLong size) +{ + uLong ret=0; + HANDLE hFile = NULL; + if (stream!=NULL) + hFile = ((WIN32FILE_IOWIN*)stream) -> hf; + + if (hFile != NULL) + { + if (!ReadFile(hFile, buf, size, &ret, NULL)) + { + DWORD dwErr = GetLastError(); + if (dwErr == ERROR_HANDLE_EOF) + dwErr = 0; + ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; + } + } + + return ret; +} + + +uLong ZCALLBACK win32_write_file_func (voidpf opaque,voidpf stream,const void* buf,uLong size) +{ + uLong ret=0; + HANDLE hFile = NULL; + if (stream!=NULL) + hFile = ((WIN32FILE_IOWIN*)stream) -> hf; + + if (hFile != NULL) + { + if (!WriteFile(hFile, buf, size, &ret, NULL)) + { + DWORD dwErr = GetLastError(); + if (dwErr == ERROR_HANDLE_EOF) + dwErr = 0; + ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; + } + } + + return ret; +} + +long ZCALLBACK win32_tell_file_func (voidpf opaque,voidpf stream) +{ + long ret=-1; + HANDLE hFile = NULL; + if (stream!=NULL) + hFile = ((WIN32FILE_IOWIN*)stream) -> hf; + if (hFile != NULL) + { + DWORD dwSet = SetFilePointer(hFile, 0, NULL, FILE_CURRENT); + if (dwSet == INVALID_SET_FILE_POINTER) + { + DWORD dwErr = GetLastError(); + ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; + ret = -1; + } + else + ret=(long)dwSet; + } + return ret; +} + +ZPOS64_T ZCALLBACK win32_tell64_file_func (voidpf opaque, voidpf stream) +{ + ZPOS64_T ret= (ZPOS64_T)-1; + HANDLE hFile = NULL; + if (stream!=NULL) + hFile = ((WIN32FILE_IOWIN*)stream)->hf; + + if (hFile) + { + LARGE_INTEGER li; + li.QuadPart = 0; + li.u.LowPart = SetFilePointer(hFile, li.u.LowPart, &li.u.HighPart, FILE_CURRENT); + if ( (li.LowPart == 0xFFFFFFFF) && (GetLastError() != NO_ERROR)) + { + DWORD dwErr = GetLastError(); + ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; + ret = (ZPOS64_T)-1; + } + else + ret=li.QuadPart; + } + return ret; +} + + +long ZCALLBACK win32_seek_file_func (voidpf opaque,voidpf stream,uLong offset,int origin) +{ + DWORD dwMoveMethod=0xFFFFFFFF; + HANDLE hFile = NULL; + + long ret=-1; + if (stream!=NULL) + hFile = ((WIN32FILE_IOWIN*)stream) -> hf; + switch (origin) + { + case ZLIB_FILEFUNC_SEEK_CUR : + dwMoveMethod = FILE_CURRENT; + break; + case ZLIB_FILEFUNC_SEEK_END : + dwMoveMethod = FILE_END; + break; + case ZLIB_FILEFUNC_SEEK_SET : + dwMoveMethod = FILE_BEGIN; + break; + default: return -1; + } + + if (hFile != NULL) + { + DWORD dwSet = SetFilePointer(hFile, offset, NULL, dwMoveMethod); + if (dwSet == INVALID_SET_FILE_POINTER) + { + DWORD dwErr = GetLastError(); + ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; + ret = -1; + } + else + ret=0; + } + return ret; +} + +long ZCALLBACK win32_seek64_file_func (voidpf opaque, voidpf stream,ZPOS64_T offset,int origin) +{ + DWORD dwMoveMethod=0xFFFFFFFF; + HANDLE hFile = NULL; + long ret=-1; + + if (stream!=NULL) + hFile = ((WIN32FILE_IOWIN*)stream)->hf; + + switch (origin) + { + case ZLIB_FILEFUNC_SEEK_CUR : + dwMoveMethod = FILE_CURRENT; + break; + case ZLIB_FILEFUNC_SEEK_END : + dwMoveMethod = FILE_END; + break; + case ZLIB_FILEFUNC_SEEK_SET : + dwMoveMethod = FILE_BEGIN; + break; + default: return -1; + } + + if (hFile) + { + LARGE_INTEGER* li = (LARGE_INTEGER*)&offset; + DWORD dwSet = SetFilePointer(hFile, li->u.LowPart, &li->u.HighPart, dwMoveMethod); + if (dwSet == INVALID_SET_FILE_POINTER) + { + DWORD dwErr = GetLastError(); + ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; + ret = -1; + } + else + ret=0; + } + return ret; +} + +int ZCALLBACK win32_close_file_func (voidpf opaque, voidpf stream) +{ + int ret=-1; + + if (stream!=NULL) + { + HANDLE hFile; + hFile = ((WIN32FILE_IOWIN*)stream) -> hf; + if (hFile != NULL) + { + CloseHandle(hFile); + ret=0; + } + free(stream); + } + return ret; +} + +int ZCALLBACK win32_error_file_func (voidpf opaque,voidpf stream) +{ + int ret=-1; + if (stream!=NULL) + { + ret = ((WIN32FILE_IOWIN*)stream) -> error; + } + return ret; +} + +void fill_win32_filefunc (zlib_filefunc_def* pzlib_filefunc_def) +{ + pzlib_filefunc_def->zopen_file = win32_open_file_func; + pzlib_filefunc_def->zread_file = win32_read_file_func; + pzlib_filefunc_def->zwrite_file = win32_write_file_func; + pzlib_filefunc_def->ztell_file = win32_tell_file_func; + pzlib_filefunc_def->zseek_file = win32_seek_file_func; + pzlib_filefunc_def->zclose_file = win32_close_file_func; + pzlib_filefunc_def->zerror_file = win32_error_file_func; + pzlib_filefunc_def->opaque = NULL; +} + +void fill_win32_filefunc64(zlib_filefunc64_def* pzlib_filefunc_def) +{ + pzlib_filefunc_def->zopen64_file = win32_open64_file_func; + pzlib_filefunc_def->zread_file = win32_read_file_func; + pzlib_filefunc_def->zwrite_file = win32_write_file_func; + pzlib_filefunc_def->ztell64_file = win32_tell64_file_func; + pzlib_filefunc_def->zseek64_file = win32_seek64_file_func; + pzlib_filefunc_def->zclose_file = win32_close_file_func; + pzlib_filefunc_def->zerror_file = win32_error_file_func; + pzlib_filefunc_def->opaque = NULL; +} + + +void fill_win32_filefunc64A(zlib_filefunc64_def* pzlib_filefunc_def) +{ + pzlib_filefunc_def->zopen64_file = win32_open64_file_funcA; + pzlib_filefunc_def->zread_file = win32_read_file_func; + pzlib_filefunc_def->zwrite_file = win32_write_file_func; + pzlib_filefunc_def->ztell64_file = win32_tell64_file_func; + pzlib_filefunc_def->zseek64_file = win32_seek64_file_func; + pzlib_filefunc_def->zclose_file = win32_close_file_func; + pzlib_filefunc_def->zerror_file = win32_error_file_func; + pzlib_filefunc_def->opaque = NULL; +} + + +void fill_win32_filefunc64W(zlib_filefunc64_def* pzlib_filefunc_def) +{ + pzlib_filefunc_def->zopen64_file = win32_open64_file_funcW; + pzlib_filefunc_def->zread_file = win32_read_file_func; + pzlib_filefunc_def->zwrite_file = win32_write_file_func; + pzlib_filefunc_def->ztell64_file = win32_tell64_file_func; + pzlib_filefunc_def->zseek64_file = win32_seek64_file_func; + pzlib_filefunc_def->zclose_file = win32_close_file_func; + pzlib_filefunc_def->zerror_file = win32_error_file_func; + pzlib_filefunc_def->opaque = NULL; +} diff --git a/libs/zlib/contrib/minizip/iowin32.h b/libs/zlib/contrib/minizip/iowin32.h new file mode 100644 index 000000000..0ca0969a7 --- /dev/null +++ b/libs/zlib/contrib/minizip/iowin32.h @@ -0,0 +1,28 @@ +/* iowin32.h -- IO base function header for compress/uncompress .zip + Version 1.1, February 14h, 2010 + part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) + + Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) + + Modifications for Zip64 support + Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) + + For more info read MiniZip_info.txt + +*/ + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +void fill_win32_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def)); +void fill_win32_filefunc64 OF((zlib_filefunc64_def* pzlib_filefunc_def)); +void fill_win32_filefunc64A OF((zlib_filefunc64_def* pzlib_filefunc_def)); +void fill_win32_filefunc64W OF((zlib_filefunc64_def* pzlib_filefunc_def)); + +#ifdef __cplusplus +} +#endif diff --git a/libs/zlib/contrib/minizip/make_vms.com b/libs/zlib/contrib/minizip/make_vms.com new file mode 100644 index 000000000..9ac13a98f --- /dev/null +++ b/libs/zlib/contrib/minizip/make_vms.com @@ -0,0 +1,25 @@ +$ if f$search("ioapi.h_orig") .eqs. "" then copy ioapi.h ioapi.h_orig +$ open/write zdef vmsdefs.h +$ copy sys$input: zdef +$ deck +#define unix +#define fill_zlib_filefunc64_32_def_from_filefunc32 fillzffunc64from +#define Write_Zip64EndOfCentralDirectoryLocator Write_Zip64EoDLocator +#define Write_Zip64EndOfCentralDirectoryRecord Write_Zip64EoDRecord +#define Write_EndOfCentralDirectoryRecord Write_EoDRecord +$ eod +$ close zdef +$ copy vmsdefs.h,ioapi.h_orig ioapi.h +$ cc/include=[--]/prefix=all ioapi.c +$ cc/include=[--]/prefix=all miniunz.c +$ cc/include=[--]/prefix=all unzip.c +$ cc/include=[--]/prefix=all minizip.c +$ cc/include=[--]/prefix=all zip.c +$ link miniunz,unzip,ioapi,[--]libz.olb/lib +$ link minizip,zip,ioapi,[--]libz.olb/lib +$ mcr []minizip test minizip_info.txt +$ mcr []miniunz -l test.zip +$ rename minizip_info.txt; minizip_info.txt_old +$ mcr []miniunz test.zip +$ delete test.zip;* +$exit diff --git a/libs/zlib/contrib/minizip/miniunz.c b/libs/zlib/contrib/minizip/miniunz.c new file mode 100644 index 000000000..9ed009fbd --- /dev/null +++ b/libs/zlib/contrib/minizip/miniunz.c @@ -0,0 +1,648 @@ +/* + miniunz.c + Version 1.1, February 14h, 2010 + sample part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) + + Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) + + Modifications of Unzip for Zip64 + Copyright (C) 2007-2008 Even Rouault + + Modifications for Zip64 support on both zip and unzip + Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) +*/ + +#ifndef _WIN32 + #ifndef __USE_FILE_OFFSET64 + #define __USE_FILE_OFFSET64 + #endif + #ifndef __USE_LARGEFILE64 + #define __USE_LARGEFILE64 + #endif + #ifndef _LARGEFILE64_SOURCE + #define _LARGEFILE64_SOURCE + #endif + #ifndef _FILE_OFFSET_BIT + #define _FILE_OFFSET_BIT 64 + #endif +#endif + +#include +#include +#include +#include +#include +#include + +#ifdef unix +# include +# include +#else +# include +# include +#endif + +#include "unzip.h" + +#define CASESENSITIVITY (0) +#define WRITEBUFFERSIZE (8192) +#define MAXFILENAME (256) + +#ifdef _WIN32 +#define USEWIN32IOAPI +#include "iowin32.h" +#endif +/* + mini unzip, demo of unzip package + + usage : + Usage : miniunz [-exvlo] file.zip [file_to_extract] [-d extractdir] + + list the file in the zipfile, and print the content of FILE_ID.ZIP or README.TXT + if it exists +*/ + + +/* change_file_date : change the date/time of a file + filename : the filename of the file where date/time must be modified + dosdate : the new date at the MSDos format (4 bytes) + tmu_date : the SAME new date at the tm_unz format */ +void change_file_date(filename,dosdate,tmu_date) + const char *filename; + uLong dosdate; + tm_unz tmu_date; +{ +#ifdef _WIN32 + HANDLE hFile; + FILETIME ftm,ftLocal,ftCreate,ftLastAcc,ftLastWrite; + + hFile = CreateFileA(filename,GENERIC_READ | GENERIC_WRITE, + 0,NULL,OPEN_EXISTING,0,NULL); + GetFileTime(hFile,&ftCreate,&ftLastAcc,&ftLastWrite); + DosDateTimeToFileTime((WORD)(dosdate>>16),(WORD)dosdate,&ftLocal); + LocalFileTimeToFileTime(&ftLocal,&ftm); + SetFileTime(hFile,&ftm,&ftLastAcc,&ftm); + CloseHandle(hFile); +#else +#ifdef unix + struct utimbuf ut; + struct tm newdate; + newdate.tm_sec = tmu_date.tm_sec; + newdate.tm_min=tmu_date.tm_min; + newdate.tm_hour=tmu_date.tm_hour; + newdate.tm_mday=tmu_date.tm_mday; + newdate.tm_mon=tmu_date.tm_mon; + if (tmu_date.tm_year > 1900) + newdate.tm_year=tmu_date.tm_year - 1900; + else + newdate.tm_year=tmu_date.tm_year ; + newdate.tm_isdst=-1; + + ut.actime=ut.modtime=mktime(&newdate); + utime(filename,&ut); +#endif +#endif +} + + +/* mymkdir and change_file_date are not 100 % portable + As I don't know well Unix, I wait feedback for the unix portion */ + +int mymkdir(dirname) + const char* dirname; +{ + int ret=0; +#ifdef _WIN32 + ret = _mkdir(dirname); +#else +#ifdef unix + ret = mkdir (dirname,0775); +#endif +#endif + return ret; +} + +int makedir (newdir) + char *newdir; +{ + char *buffer ; + char *p; + int len = (int)strlen(newdir); + + if (len <= 0) + return 0; + + buffer = (char*)malloc(len+1); + if (buffer==NULL) + { + printf("Error allocating memory\n"); + return UNZ_INTERNALERROR; + } + strcpy(buffer,newdir); + + if (buffer[len-1] == '/') { + buffer[len-1] = '\0'; + } + if (mymkdir(buffer) == 0) + { + free(buffer); + return 1; + } + + p = buffer+1; + while (1) + { + char hold; + + while(*p && *p != '\\' && *p != '/') + p++; + hold = *p; + *p = 0; + if ((mymkdir(buffer) == -1) && (errno == ENOENT)) + { + printf("couldn't create directory %s\n",buffer); + free(buffer); + return 0; + } + if (hold == 0) + break; + *p++ = hold; + } + free(buffer); + return 1; +} + +void do_banner() +{ + printf("MiniUnz 1.01b, demo of zLib + Unz package written by Gilles Vollant\n"); + printf("more info at http://www.winimage.com/zLibDll/unzip.html\n\n"); +} + +void do_help() +{ + printf("Usage : miniunz [-e] [-x] [-v] [-l] [-o] [-p password] file.zip [file_to_extr.] [-d extractdir]\n\n" \ + " -e Extract without pathname (junk paths)\n" \ + " -x Extract with pathname\n" \ + " -v list files\n" \ + " -l list files\n" \ + " -d directory to extract into\n" \ + " -o overwrite files without prompting\n" \ + " -p extract crypted file using password\n\n"); +} + +void Display64BitsSize(ZPOS64_T n, int size_char) +{ + /* to avoid compatibility problem , we do here the conversion */ + char number[21]; + int offset=19; + int pos_string = 19; + number[20]=0; + for (;;) { + number[offset]=(char)((n%10)+'0'); + if (number[offset] != '0') + pos_string=offset; + n/=10; + if (offset==0) + break; + offset--; + } + { + int size_display_string = 19-pos_string; + while (size_char > size_display_string) + { + size_char--; + printf(" "); + } + } + + printf("%s",&number[pos_string]); +} + +int do_list(uf) + unzFile uf; +{ + uLong i; + unz_global_info64 gi; + int err; + + err = unzGetGlobalInfo64(uf,&gi); + if (err!=UNZ_OK) + printf("error %d with zipfile in unzGetGlobalInfo \n",err); + printf(" Length Method Size Ratio Date Time CRC-32 Name\n"); + printf(" ------ ------ ---- ----- ---- ---- ------ ----\n"); + for (i=0;i0) + ratio = (uLong)((file_info.compressed_size*100)/file_info.uncompressed_size); + + /* display a '*' if the file is crypted */ + if ((file_info.flag & 1) != 0) + charCrypt='*'; + + if (file_info.compression_method==0) + string_method="Stored"; + else + if (file_info.compression_method==Z_DEFLATED) + { + uInt iLevel=(uInt)((file_info.flag & 0x6)/2); + if (iLevel==0) + string_method="Defl:N"; + else if (iLevel==1) + string_method="Defl:X"; + else if ((iLevel==2) || (iLevel==3)) + string_method="Defl:F"; /* 2:fast , 3 : extra fast*/ + } + else + if (file_info.compression_method==Z_BZIP2ED) + { + string_method="BZip2 "; + } + else + string_method="Unkn. "; + + Display64BitsSize(file_info.uncompressed_size,7); + printf(" %6s%c",string_method,charCrypt); + Display64BitsSize(file_info.compressed_size,7); + printf(" %3lu%% %2.2lu-%2.2lu-%2.2lu %2.2lu:%2.2lu %8.8lx %s\n", + ratio, + (uLong)file_info.tmu_date.tm_mon + 1, + (uLong)file_info.tmu_date.tm_mday, + (uLong)file_info.tmu_date.tm_year % 100, + (uLong)file_info.tmu_date.tm_hour,(uLong)file_info.tmu_date.tm_min, + (uLong)file_info.crc,filename_inzip); + if ((i+1)='a') && (rep<='z')) + rep -= 0x20; + } + while ((rep!='Y') && (rep!='N') && (rep!='A')); + } + + if (rep == 'N') + skip = 1; + + if (rep == 'A') + *popt_overwrite=1; + } + + if ((skip==0) && (err==UNZ_OK)) + { + fout=fopen64(write_filename,"wb"); + + /* some zipfile don't contain directory alone before file */ + if ((fout==NULL) && ((*popt_extract_without_path)==0) && + (filename_withoutpath!=(char*)filename_inzip)) + { + char c=*(filename_withoutpath-1); + *(filename_withoutpath-1)='\0'; + makedir(write_filename); + *(filename_withoutpath-1)=c; + fout=fopen64(write_filename,"wb"); + } + + if (fout==NULL) + { + printf("error opening %s\n",write_filename); + } + } + + if (fout!=NULL) + { + printf(" extracting: %s\n",write_filename); + + do + { + err = unzReadCurrentFile(uf,buf,size_buf); + if (err<0) + { + printf("error %d with zipfile in unzReadCurrentFile\n",err); + break; + } + if (err>0) + if (fwrite(buf,err,1,fout)!=1) + { + printf("error in writing extracted file\n"); + err=UNZ_ERRNO; + break; + } + } + while (err>0); + if (fout) + fclose(fout); + + if (err==0) + change_file_date(write_filename,file_info.dosDate, + file_info.tmu_date); + } + + if (err==UNZ_OK) + { + err = unzCloseCurrentFile (uf); + if (err!=UNZ_OK) + { + printf("error %d with zipfile in unzCloseCurrentFile\n",err); + } + } + else + unzCloseCurrentFile(uf); /* don't lose the error */ + } + + free(buf); + return err; +} + + +int do_extract(uf,opt_extract_without_path,opt_overwrite,password) + unzFile uf; + int opt_extract_without_path; + int opt_overwrite; + const char* password; +{ + uLong i; + unz_global_info64 gi; + int err; + FILE* fout=NULL; + + err = unzGetGlobalInfo64(uf,&gi); + if (err!=UNZ_OK) + printf("error %d with zipfile in unzGetGlobalInfo \n",err); + + for (i=0;i +#include +#include +#include +#include +#include + +#ifdef unix +# include +# include +# include +# include +#else +# include +# include +#endif + +#include "zip.h" + +#ifdef _WIN32 + #define USEWIN32IOAPI + #include "iowin32.h" +#endif + + + +#define WRITEBUFFERSIZE (16384) +#define MAXFILENAME (256) + +#ifdef _WIN32 +uLong filetime(f, tmzip, dt) + char *f; /* name of file to get info on */ + tm_zip *tmzip; /* return value: access, modific. and creation times */ + uLong *dt; /* dostime */ +{ + int ret = 0; + { + FILETIME ftLocal; + HANDLE hFind; + WIN32_FIND_DATAA ff32; + + hFind = FindFirstFileA(f,&ff32); + if (hFind != INVALID_HANDLE_VALUE) + { + FileTimeToLocalFileTime(&(ff32.ftLastWriteTime),&ftLocal); + FileTimeToDosDateTime(&ftLocal,((LPWORD)dt)+1,((LPWORD)dt)+0); + FindClose(hFind); + ret = 1; + } + } + return ret; +} +#else +#ifdef unix +uLong filetime(f, tmzip, dt) + char *f; /* name of file to get info on */ + tm_zip *tmzip; /* return value: access, modific. and creation times */ + uLong *dt; /* dostime */ +{ + int ret=0; + struct stat s; /* results of stat() */ + struct tm* filedate; + time_t tm_t=0; + + if (strcmp(f,"-")!=0) + { + char name[MAXFILENAME+1]; + int len = strlen(f); + if (len > MAXFILENAME) + len = MAXFILENAME; + + strncpy(name, f,MAXFILENAME-1); + /* strncpy doesnt append the trailing NULL, of the string is too long. */ + name[ MAXFILENAME ] = '\0'; + + if (name[len - 1] == '/') + name[len - 1] = '\0'; + /* not all systems allow stat'ing a file with / appended */ + if (stat(name,&s)==0) + { + tm_t = s.st_mtime; + ret = 1; + } + } + filedate = localtime(&tm_t); + + tmzip->tm_sec = filedate->tm_sec; + tmzip->tm_min = filedate->tm_min; + tmzip->tm_hour = filedate->tm_hour; + tmzip->tm_mday = filedate->tm_mday; + tmzip->tm_mon = filedate->tm_mon ; + tmzip->tm_year = filedate->tm_year; + + return ret; +} +#else +uLong filetime(f, tmzip, dt) + char *f; /* name of file to get info on */ + tm_zip *tmzip; /* return value: access, modific. and creation times */ + uLong *dt; /* dostime */ +{ + return 0; +} +#endif +#endif + + + + +int check_exist_file(filename) + const char* filename; +{ + FILE* ftestexist; + int ret = 1; + ftestexist = fopen64(filename,"rb"); + if (ftestexist==NULL) + ret = 0; + else + fclose(ftestexist); + return ret; +} + +void do_banner() +{ + printf("MiniZip 1.1, demo of zLib + MiniZip64 package, written by Gilles Vollant\n"); + printf("more info on MiniZip at http://www.winimage.com/zLibDll/minizip.html\n\n"); +} + +void do_help() +{ + printf("Usage : minizip [-o] [-a] [-0 to -9] [-p password] [-j] file.zip [files_to_add]\n\n" \ + " -o Overwrite existing file.zip\n" \ + " -a Append to existing file.zip\n" \ + " -0 Store only\n" \ + " -1 Compress faster\n" \ + " -9 Compress better\n\n" \ + " -j exclude path. store only the file name.\n\n"); +} + +/* calculate the CRC32 of a file, + because to encrypt a file, we need known the CRC32 of the file before */ +int getFileCrc(const char* filenameinzip,void*buf,unsigned long size_buf,unsigned long* result_crc) +{ + unsigned long calculate_crc=0; + int err=ZIP_OK; + FILE * fin = fopen64(filenameinzip,"rb"); + unsigned long size_read = 0; + unsigned long total_read = 0; + if (fin==NULL) + { + err = ZIP_ERRNO; + } + + if (err == ZIP_OK) + do + { + err = ZIP_OK; + size_read = (int)fread(buf,1,size_buf,fin); + if (size_read < size_buf) + if (feof(fin)==0) + { + printf("error in reading %s\n",filenameinzip); + err = ZIP_ERRNO; + } + + if (size_read>0) + calculate_crc = crc32(calculate_crc,buf,size_read); + total_read += size_read; + + } while ((err == ZIP_OK) && (size_read>0)); + + if (fin) + fclose(fin); + + *result_crc=calculate_crc; + printf("file %s crc %lx\n", filenameinzip, calculate_crc); + return err; +} + +int isLargeFile(const char* filename) +{ + int largeFile = 0; + ZPOS64_T pos = 0; + FILE* pFile = fopen64(filename, "rb"); + + if(pFile != NULL) + { + int n = fseeko64(pFile, 0, SEEK_END); + + pos = ftello64(pFile); + + printf("File : %s is %lld bytes\n", filename, pos); + + if(pos >= 0xffffffff) + largeFile = 1; + + fclose(pFile); + } + + return largeFile; +} + +int main(argc,argv) + int argc; + char *argv[]; +{ + int i; + int opt_overwrite=0; + int opt_compress_level=Z_DEFAULT_COMPRESSION; + int opt_exclude_path=0; + int zipfilenamearg = 0; + char filename_try[MAXFILENAME+16]; + int zipok; + int err=0; + int size_buf=0; + void* buf=NULL; + const char* password=NULL; + + + do_banner(); + if (argc==1) + { + do_help(); + return 0; + } + else + { + for (i=1;i='0') && (c<='9')) + opt_compress_level = c-'0'; + if ((c=='j') || (c=='J')) + opt_exclude_path = 1; + + if (((c=='p') || (c=='P')) && (i+1='a') && (rep<='z')) + rep -= 0x20; + } + while ((rep!='Y') && (rep!='N') && (rep!='A')); + if (rep=='N') + zipok = 0; + if (rep=='A') + opt_overwrite = 2; + } + } + + if (zipok==1) + { + zipFile zf; + int errclose; +# ifdef USEWIN32IOAPI + zlib_filefunc64_def ffunc; + fill_win32_filefunc64A(&ffunc); + zf = zipOpen2_64(filename_try,(opt_overwrite==2) ? 2 : 0,NULL,&ffunc); +# else + zf = zipOpen64(filename_try,(opt_overwrite==2) ? 2 : 0); +# endif + + if (zf == NULL) + { + printf("error opening %s\n",filename_try); + err= ZIP_ERRNO; + } + else + printf("creating %s\n",filename_try); + + for (i=zipfilenamearg+1;(i='0') || (argv[i][1]<='9'))) && + (strlen(argv[i]) == 2))) + { + FILE * fin; + int size_read; + const char* filenameinzip = argv[i]; + const char *savefilenameinzip; + zip_fileinfo zi; + unsigned long crcFile=0; + int zip64 = 0; + + zi.tmz_date.tm_sec = zi.tmz_date.tm_min = zi.tmz_date.tm_hour = + zi.tmz_date.tm_mday = zi.tmz_date.tm_mon = zi.tmz_date.tm_year = 0; + zi.dosDate = 0; + zi.internal_fa = 0; + zi.external_fa = 0; + filetime(filenameinzip,&zi.tmz_date,&zi.dosDate); + +/* + err = zipOpenNewFileInZip(zf,filenameinzip,&zi, + NULL,0,NULL,0,NULL / * comment * /, + (opt_compress_level != 0) ? Z_DEFLATED : 0, + opt_compress_level); +*/ + if ((password != NULL) && (err==ZIP_OK)) + err = getFileCrc(filenameinzip,buf,size_buf,&crcFile); + + zip64 = isLargeFile(filenameinzip); + + /* The path name saved, should not include a leading slash. */ + /*if it did, windows/xp and dynazip couldn't read the zip file. */ + savefilenameinzip = filenameinzip; + while( savefilenameinzip[0] == '\\' || savefilenameinzip[0] == '/' ) + { + savefilenameinzip++; + } + + /*should the zip file contain any path at all?*/ + if( opt_exclude_path ) + { + const char *tmpptr; + const char *lastslash = 0; + for( tmpptr = savefilenameinzip; *tmpptr; tmpptr++) + { + if( *tmpptr == '\\' || *tmpptr == '/') + { + lastslash = tmpptr; + } + } + if( lastslash != NULL ) + { + savefilenameinzip = lastslash+1; // base filename follows last slash. + } + } + + /**/ + err = zipOpenNewFileInZip3_64(zf,savefilenameinzip,&zi, + NULL,0,NULL,0,NULL /* comment*/, + (opt_compress_level != 0) ? Z_DEFLATED : 0, + opt_compress_level,0, + /* -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, */ + -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, + password,crcFile, zip64); + + if (err != ZIP_OK) + printf("error in opening %s in zipfile\n",filenameinzip); + else + { + fin = fopen64(filenameinzip,"rb"); + if (fin==NULL) + { + err=ZIP_ERRNO; + printf("error in opening %s for reading\n",filenameinzip); + } + } + + if (err == ZIP_OK) + do + { + err = ZIP_OK; + size_read = (int)fread(buf,1,size_buf,fin); + if (size_read < size_buf) + if (feof(fin)==0) + { + printf("error in reading %s\n",filenameinzip); + err = ZIP_ERRNO; + } + + if (size_read>0) + { + err = zipWriteInFileInZip (zf,buf,size_read); + if (err<0) + { + printf("error in writing %s in the zipfile\n", + filenameinzip); + } + + } + } while ((err == ZIP_OK) && (size_read>0)); + + if (fin) + fclose(fin); + + if (err<0) + err=ZIP_ERRNO; + else + { + err = zipCloseFileInZip(zf); + if (err!=ZIP_OK) + printf("error in closing %s in the zipfile\n", + filenameinzip); + } + } + } + errclose = zipClose(zf,NULL); + if (errclose != ZIP_OK) + printf("error in closing %s\n",filename_try); + } + else + { + do_help(); + } + + free(buf); + return 0; +} diff --git a/libs/zlib/contrib/minizip/mztools.c b/libs/zlib/contrib/minizip/mztools.c new file mode 100644 index 000000000..f9092e65a --- /dev/null +++ b/libs/zlib/contrib/minizip/mztools.c @@ -0,0 +1,281 @@ +/* + Additional tools for Minizip + Code: Xavier Roche '2004 + License: Same as ZLIB (www.gzip.org) +*/ + +/* Code */ +#include +#include +#include +#include "zlib.h" +#include "unzip.h" + +#define READ_8(adr) ((unsigned char)*(adr)) +#define READ_16(adr) ( READ_8(adr) | (READ_8(adr+1) << 8) ) +#define READ_32(adr) ( READ_16(adr) | (READ_16((adr)+2) << 16) ) + +#define WRITE_8(buff, n) do { \ + *((unsigned char*)(buff)) = (unsigned char) ((n) & 0xff); \ +} while(0) +#define WRITE_16(buff, n) do { \ + WRITE_8((unsigned char*)(buff), n); \ + WRITE_8(((unsigned char*)(buff)) + 1, (n) >> 8); \ +} while(0) +#define WRITE_32(buff, n) do { \ + WRITE_16((unsigned char*)(buff), (n) & 0xffff); \ + WRITE_16((unsigned char*)(buff) + 2, (n) >> 16); \ +} while(0) + +extern int ZEXPORT unzRepair(file, fileOut, fileOutTmp, nRecovered, bytesRecovered) +const char* file; +const char* fileOut; +const char* fileOutTmp; +uLong* nRecovered; +uLong* bytesRecovered; +{ + int err = Z_OK; + FILE* fpZip = fopen(file, "rb"); + FILE* fpOut = fopen(fileOut, "wb"); + FILE* fpOutCD = fopen(fileOutTmp, "wb"); + if (fpZip != NULL && fpOut != NULL) { + int entries = 0; + uLong totalBytes = 0; + char header[30]; + char filename[256]; + char extra[1024]; + int offset = 0; + int offsetCD = 0; + while ( fread(header, 1, 30, fpZip) == 30 ) { + int currentOffset = offset; + + /* File entry */ + if (READ_32(header) == 0x04034b50) { + unsigned int version = READ_16(header + 4); + unsigned int gpflag = READ_16(header + 6); + unsigned int method = READ_16(header + 8); + unsigned int filetime = READ_16(header + 10); + unsigned int filedate = READ_16(header + 12); + unsigned int crc = READ_32(header + 14); /* crc */ + unsigned int cpsize = READ_32(header + 18); /* compressed size */ + unsigned int uncpsize = READ_32(header + 22); /* uncompressed sz */ + unsigned int fnsize = READ_16(header + 26); /* file name length */ + unsigned int extsize = READ_16(header + 28); /* extra field length */ + filename[0] = extra[0] = '\0'; + + /* Header */ + if (fwrite(header, 1, 30, fpOut) == 30) { + offset += 30; + } else { + err = Z_ERRNO; + break; + } + + /* Filename */ + if (fnsize > 0) { + if (fread(filename, 1, fnsize, fpZip) == fnsize) { + if (fwrite(filename, 1, fnsize, fpOut) == fnsize) { + offset += fnsize; + } else { + err = Z_ERRNO; + break; + } + } else { + err = Z_ERRNO; + break; + } + } else { + err = Z_STREAM_ERROR; + break; + } + + /* Extra field */ + if (extsize > 0) { + if (fread(extra, 1, extsize, fpZip) == extsize) { + if (fwrite(extra, 1, extsize, fpOut) == extsize) { + offset += extsize; + } else { + err = Z_ERRNO; + break; + } + } else { + err = Z_ERRNO; + break; + } + } + + /* Data */ + { + int dataSize = cpsize; + if (dataSize == 0) { + dataSize = uncpsize; + } + if (dataSize > 0) { + char* data = malloc(dataSize); + if (data != NULL) { + if ((int)fread(data, 1, dataSize, fpZip) == dataSize) { + if ((int)fwrite(data, 1, dataSize, fpOut) == dataSize) { + offset += dataSize; + totalBytes += dataSize; + } else { + err = Z_ERRNO; + } + } else { + err = Z_ERRNO; + } + free(data); + if (err != Z_OK) { + break; + } + } else { + err = Z_MEM_ERROR; + break; + } + } + } + + /* Central directory entry */ + { + char header[46]; + char* comment = ""; + int comsize = (int) strlen(comment); + WRITE_32(header, 0x02014b50); + WRITE_16(header + 4, version); + WRITE_16(header + 6, version); + WRITE_16(header + 8, gpflag); + WRITE_16(header + 10, method); + WRITE_16(header + 12, filetime); + WRITE_16(header + 14, filedate); + WRITE_32(header + 16, crc); + WRITE_32(header + 20, cpsize); + WRITE_32(header + 24, uncpsize); + WRITE_16(header + 28, fnsize); + WRITE_16(header + 30, extsize); + WRITE_16(header + 32, comsize); + WRITE_16(header + 34, 0); /* disk # */ + WRITE_16(header + 36, 0); /* int attrb */ + WRITE_32(header + 38, 0); /* ext attrb */ + WRITE_32(header + 42, currentOffset); + /* Header */ + if (fwrite(header, 1, 46, fpOutCD) == 46) { + offsetCD += 46; + + /* Filename */ + if (fnsize > 0) { + if (fwrite(filename, 1, fnsize, fpOutCD) == fnsize) { + offsetCD += fnsize; + } else { + err = Z_ERRNO; + break; + } + } else { + err = Z_STREAM_ERROR; + break; + } + + /* Extra field */ + if (extsize > 0) { + if (fwrite(extra, 1, extsize, fpOutCD) == extsize) { + offsetCD += extsize; + } else { + err = Z_ERRNO; + break; + } + } + + /* Comment field */ + if (comsize > 0) { + if ((int)fwrite(comment, 1, comsize, fpOutCD) == comsize) { + offsetCD += comsize; + } else { + err = Z_ERRNO; + break; + } + } + + + } else { + err = Z_ERRNO; + break; + } + } + + /* Success */ + entries++; + + } else { + break; + } + } + + /* Final central directory */ + { + int entriesZip = entries; + char header[22]; + char* comment = ""; // "ZIP File recovered by zlib/minizip/mztools"; + int comsize = (int) strlen(comment); + if (entriesZip > 0xffff) { + entriesZip = 0xffff; + } + WRITE_32(header, 0x06054b50); + WRITE_16(header + 4, 0); /* disk # */ + WRITE_16(header + 6, 0); /* disk # */ + WRITE_16(header + 8, entriesZip); /* hack */ + WRITE_16(header + 10, entriesZip); /* hack */ + WRITE_32(header + 12, offsetCD); /* size of CD */ + WRITE_32(header + 16, offset); /* offset to CD */ + WRITE_16(header + 20, comsize); /* comment */ + + /* Header */ + if (fwrite(header, 1, 22, fpOutCD) == 22) { + + /* Comment field */ + if (comsize > 0) { + if ((int)fwrite(comment, 1, comsize, fpOutCD) != comsize) { + err = Z_ERRNO; + } + } + + } else { + err = Z_ERRNO; + } + } + + /* Final merge (file + central directory) */ + fclose(fpOutCD); + if (err == Z_OK) { + fpOutCD = fopen(fileOutTmp, "rb"); + if (fpOutCD != NULL) { + int nRead; + char buffer[8192]; + while ( (nRead = (int)fread(buffer, 1, sizeof(buffer), fpOutCD)) > 0) { + if ((int)fwrite(buffer, 1, nRead, fpOut) != nRead) { + err = Z_ERRNO; + break; + } + } + fclose(fpOutCD); + } + } + + /* Close */ + fclose(fpZip); + fclose(fpOut); + + /* Wipe temporary file */ + (void)remove(fileOutTmp); + + /* Number of recovered entries */ + if (err == Z_OK) { + if (nRecovered != NULL) { + *nRecovered = entries; + } + if (bytesRecovered != NULL) { + *bytesRecovered = totalBytes; + } + } + } else { + err = Z_STREAM_ERROR; + } + return err; +} diff --git a/libs/zlib/contrib/minizip/mztools.h b/libs/zlib/contrib/minizip/mztools.h new file mode 100644 index 000000000..88b34592b --- /dev/null +++ b/libs/zlib/contrib/minizip/mztools.h @@ -0,0 +1,31 @@ +/* + Additional tools for Minizip + Code: Xavier Roche '2004 + License: Same as ZLIB (www.gzip.org) +*/ + +#ifndef _zip_tools_H +#define _zip_tools_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _ZLIB_H +#include "zlib.h" +#endif + +#include "unzip.h" + +/* Repair a ZIP file (missing central directory) + file: file to recover + fileOut: output file after recovery + fileOutTmp: temporary file name used for recovery +*/ +extern int ZEXPORT unzRepair(const char* file, + const char* fileOut, + const char* fileOutTmp, + uLong* nRecovered, + uLong* bytesRecovered); + +#endif diff --git a/libs/zlib/contrib/minizip/unzip.c b/libs/zlib/contrib/minizip/unzip.c new file mode 100644 index 000000000..7617f41f1 --- /dev/null +++ b/libs/zlib/contrib/minizip/unzip.c @@ -0,0 +1,2125 @@ +/* unzip.c -- IO for uncompress .zip files using zlib + Version 1.1, February 14h, 2010 + part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) + + Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) + + Modifications of Unzip for Zip64 + Copyright (C) 2007-2008 Even Rouault + + Modifications for Zip64 support on both zip and unzip + Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) + + For more info read MiniZip_info.txt + + + ------------------------------------------------------------------------------------ + Decryption code comes from crypt.c by Info-ZIP but has been greatly reduced in terms of + compatibility with older software. The following is from the original crypt.c. + Code woven in by Terry Thorsen 1/2003. + + Copyright (c) 1990-2000 Info-ZIP. All rights reserved. + + See the accompanying file LICENSE, version 2000-Apr-09 or later + (the contents of which are also included in zip.h) for terms of use. + If, for some reason, all these files are missing, the Info-ZIP license + also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html + + crypt.c (full version) by Info-ZIP. Last revised: [see crypt.h] + + The encryption/decryption parts of this source code (as opposed to the + non-echoing password parts) were originally written in Europe. The + whole source package can be freely distributed, including from the USA. + (Prior to January 2000, re-export from the US was a violation of US law.) + + This encryption code is a direct transcription of the algorithm from + Roger Schlafly, described by Phil Katz in the file appnote.txt. This + file (appnote.txt) is distributed with the PKZIP program (even in the + version without encryption capabilities). + + ------------------------------------------------------------------------------------ + + Changes in unzip.c + + 2007-2008 - Even Rouault - Addition of cpl_unzGetCurrentFileZStreamPos + 2007-2008 - Even Rouault - Decoration of symbol names unz* -> cpl_unz* + 2007-2008 - Even Rouault - Remove old C style function prototypes + 2007-2008 - Even Rouault - Add unzip support for ZIP64 + + Copyright (C) 2007-2008 Even Rouault + + + Oct-2009 - Mathias Svensson - Removed cpl_* from symbol names (Even Rouault added them but since this is now moved to a new project (minizip64) I renamed them again). + Oct-2009 - Mathias Svensson - Fixed problem if uncompressed size was > 4G and compressed size was <4G + should only read the compressed/uncompressed size from the Zip64 format if + the size from normal header was 0xFFFFFFFF + Oct-2009 - Mathias Svensson - Applied some bug fixes from paches recived from Gilles Vollant + Oct-2009 - Mathias Svensson - Applied support to unzip files with compression mathod BZIP2 (bzip2 lib is required) + Patch created by Daniel Borca + + Jan-2010 - back to unzip and minizip 1.0 name scheme, with compatibility layer + + Copyright (C) 1998 - 2010 Gilles Vollant, Even Rouault, Mathias Svensson + +*/ + + +#include +#include +#include + +#ifndef NOUNCRYPT + #define NOUNCRYPT +#endif + +#include "zlib.h" +#include "unzip.h" + +#ifdef STDC +# include +# include +# include +#endif +#ifdef NO_ERRNO_H + extern int errno; +#else +# include +#endif + + +#ifndef local +# define local static +#endif +/* compile with -Dlocal if your debugger can't find static symbols */ + + +#ifndef CASESENSITIVITYDEFAULT_NO +# if !defined(unix) && !defined(CASESENSITIVITYDEFAULT_YES) +# define CASESENSITIVITYDEFAULT_NO +# endif +#endif + + +#ifndef UNZ_BUFSIZE +#define UNZ_BUFSIZE (16384) +#endif + +#ifndef UNZ_MAXFILENAMEINZIP +#define UNZ_MAXFILENAMEINZIP (256) +#endif + +#ifndef ALLOC +# define ALLOC(size) (malloc(size)) +#endif +#ifndef TRYFREE +# define TRYFREE(p) {if (p) free(p);} +#endif + +#define SIZECENTRALDIRITEM (0x2e) +#define SIZEZIPLOCALHEADER (0x1e) + + +const char unz_copyright[] = + " unzip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll"; + +/* unz_file_info_interntal contain internal info about a file in zipfile*/ +typedef struct unz_file_info64_internal_s +{ + ZPOS64_T offset_curfile;/* relative offset of local header 8 bytes */ +} unz_file_info64_internal; + + +/* file_in_zip_read_info_s contain internal information about a file in zipfile, + when reading and decompress it */ +typedef struct +{ + char *read_buffer; /* internal buffer for compressed data */ + z_stream stream; /* zLib stream structure for inflate */ + +#ifdef HAVE_BZIP2 + bz_stream bstream; /* bzLib stream structure for bziped */ +#endif + + ZPOS64_T pos_in_zipfile; /* position in byte on the zipfile, for fseek*/ + uLong stream_initialised; /* flag set if stream structure is initialised*/ + + ZPOS64_T offset_local_extrafield;/* offset of the local extra field */ + uInt size_local_extrafield;/* size of the local extra field */ + ZPOS64_T pos_local_extrafield; /* position in the local extra field in read*/ + ZPOS64_T total_out_64; + + uLong crc32; /* crc32 of all data uncompressed */ + uLong crc32_wait; /* crc32 we must obtain after decompress all */ + ZPOS64_T rest_read_compressed; /* number of byte to be decompressed */ + ZPOS64_T rest_read_uncompressed;/*number of byte to be obtained after decomp*/ + zlib_filefunc64_32_def z_filefunc; + voidpf filestream; /* io structore of the zipfile */ + uLong compression_method; /* compression method (0==store) */ + ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ + int raw; +} file_in_zip64_read_info_s; + + +/* unz64_s contain internal information about the zipfile +*/ +typedef struct +{ + zlib_filefunc64_32_def z_filefunc; + int is64bitOpenFunction; + voidpf filestream; /* io structore of the zipfile */ + unz_global_info64 gi; /* public global information */ + ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ + ZPOS64_T num_file; /* number of the current file in the zipfile*/ + ZPOS64_T pos_in_central_dir; /* pos of the current file in the central dir*/ + ZPOS64_T current_file_ok; /* flag about the usability of the current file*/ + ZPOS64_T central_pos; /* position of the beginning of the central dir*/ + + ZPOS64_T size_central_dir; /* size of the central directory */ + ZPOS64_T offset_central_dir; /* offset of start of central directory with + respect to the starting disk number */ + + unz_file_info64 cur_file_info; /* public info about the current file in zip*/ + unz_file_info64_internal cur_file_info_internal; /* private info about it*/ + file_in_zip64_read_info_s* pfile_in_zip_read; /* structure about the current + file if we are decompressing it */ + int encrypted; + + int isZip64; + +# ifndef NOUNCRYPT + unsigned long keys[3]; /* keys defining the pseudo-random sequence */ + const unsigned long* pcrc_32_tab; +# endif +} unz64_s; + + +#ifndef NOUNCRYPT +#include "crypt.h" +#endif + +/* =========================================================================== + Read a byte from a gz_stream; update next_in and avail_in. Return EOF + for end of file. + IN assertion: the stream s has been sucessfully opened for reading. +*/ + + +local int unz64local_getByte OF(( + const zlib_filefunc64_32_def* pzlib_filefunc_def, + voidpf filestream, + int *pi)); + +local int unz64local_getByte(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, int *pi) +{ + unsigned char c; + int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,&c,1); + if (err==1) + { + *pi = (int)c; + return UNZ_OK; + } + else + { + if (ZERROR64(*pzlib_filefunc_def,filestream)) + return UNZ_ERRNO; + else + return UNZ_EOF; + } +} + + +/* =========================================================================== + Reads a long in LSB order from the given gz_stream. Sets +*/ +local int unz64local_getShort OF(( + const zlib_filefunc64_32_def* pzlib_filefunc_def, + voidpf filestream, + uLong *pX)); + +local int unz64local_getShort (const zlib_filefunc64_32_def* pzlib_filefunc_def, + voidpf filestream, + uLong *pX) +{ + uLong x ; + int i = 0; + int err; + + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); + x = (uLong)i; + + if (err==UNZ_OK) + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); + x |= ((uLong)i)<<8; + + if (err==UNZ_OK) + *pX = x; + else + *pX = 0; + return err; +} + +local int unz64local_getLong OF(( + const zlib_filefunc64_32_def* pzlib_filefunc_def, + voidpf filestream, + uLong *pX)); + +local int unz64local_getLong (const zlib_filefunc64_32_def* pzlib_filefunc_def, + voidpf filestream, + uLong *pX) +{ + uLong x ; + int i = 0; + int err; + + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); + x = (uLong)i; + + if (err==UNZ_OK) + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); + x |= ((uLong)i)<<8; + + if (err==UNZ_OK) + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); + x |= ((uLong)i)<<16; + + if (err==UNZ_OK) + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); + x += ((uLong)i)<<24; + + if (err==UNZ_OK) + *pX = x; + else + *pX = 0; + return err; +} + +local int unz64local_getLong64 OF(( + const zlib_filefunc64_32_def* pzlib_filefunc_def, + voidpf filestream, + ZPOS64_T *pX)); + + +local int unz64local_getLong64 (const zlib_filefunc64_32_def* pzlib_filefunc_def, + voidpf filestream, + ZPOS64_T *pX) +{ + ZPOS64_T x ; + int i = 0; + int err; + + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); + x = (ZPOS64_T)i; + + if (err==UNZ_OK) + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); + x |= ((ZPOS64_T)i)<<8; + + if (err==UNZ_OK) + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); + x |= ((ZPOS64_T)i)<<16; + + if (err==UNZ_OK) + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); + x |= ((ZPOS64_T)i)<<24; + + if (err==UNZ_OK) + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); + x |= ((ZPOS64_T)i)<<32; + + if (err==UNZ_OK) + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); + x |= ((ZPOS64_T)i)<<40; + + if (err==UNZ_OK) + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); + x |= ((ZPOS64_T)i)<<48; + + if (err==UNZ_OK) + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); + x |= ((ZPOS64_T)i)<<56; + + if (err==UNZ_OK) + *pX = x; + else + *pX = 0; + return err; +} + +/* My own strcmpi / strcasecmp */ +local int strcmpcasenosensitive_internal (const char* fileName1, const char* fileName2) +{ + for (;;) + { + char c1=*(fileName1++); + char c2=*(fileName2++); + if ((c1>='a') && (c1<='z')) + c1 -= 0x20; + if ((c2>='a') && (c2<='z')) + c2 -= 0x20; + if (c1=='\0') + return ((c2=='\0') ? 0 : -1); + if (c2=='\0') + return 1; + if (c1c2) + return 1; + } +} + + +#ifdef CASESENSITIVITYDEFAULT_NO +#define CASESENSITIVITYDEFAULTVALUE 2 +#else +#define CASESENSITIVITYDEFAULTVALUE 1 +#endif + +#ifndef STRCMPCASENOSENTIVEFUNCTION +#define STRCMPCASENOSENTIVEFUNCTION strcmpcasenosensitive_internal +#endif + +/* + Compare two filename (fileName1,fileName2). + If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) + If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi + or strcasecmp) + If iCaseSenisivity = 0, case sensitivity is defaut of your operating system + (like 1 on Unix, 2 on Windows) + +*/ +extern int ZEXPORT unzStringFileNameCompare (const char* fileName1, + const char* fileName2, + int iCaseSensitivity) + +{ + if (iCaseSensitivity==0) + iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE; + + if (iCaseSensitivity==1) + return strcmp(fileName1,fileName2); + + return STRCMPCASENOSENTIVEFUNCTION(fileName1,fileName2); +} + +#ifndef BUFREADCOMMENT +#define BUFREADCOMMENT (0x400) +#endif + +/* + Locate the Central directory of a zipfile (at the end, just before + the global comment) +*/ +local ZPOS64_T unz64local_SearchCentralDir OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)); +local ZPOS64_T unz64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream) +{ + unsigned char* buf; + ZPOS64_T uSizeFile; + ZPOS64_T uBackRead; + ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */ + ZPOS64_T uPosFound=0; + + if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0) + return 0; + + + uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream); + + if (uMaxBack>uSizeFile) + uMaxBack = uSizeFile; + + buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); + if (buf==NULL) + return 0; + + uBackRead = 4; + while (uBackReaduMaxBack) + uBackRead = uMaxBack; + else + uBackRead+=BUFREADCOMMENT; + uReadPos = uSizeFile-uBackRead ; + + uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? + (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos); + if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0) + break; + + if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize) + break; + + for (i=(int)uReadSize-3; (i--)>0;) + if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && + ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06)) + { + uPosFound = uReadPos+i; + break; + } + + if (uPosFound!=0) + break; + } + TRYFREE(buf); + return uPosFound; +} + + +/* + Locate the Central directory 64 of a zipfile (at the end, just before + the global comment) +*/ +local ZPOS64_T unz64local_SearchCentralDir64 OF(( + const zlib_filefunc64_32_def* pzlib_filefunc_def, + voidpf filestream)); + +local ZPOS64_T unz64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib_filefunc_def, + voidpf filestream) +{ + unsigned char* buf; + ZPOS64_T uSizeFile; + ZPOS64_T uBackRead; + ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */ + ZPOS64_T uPosFound=0; + uLong uL; + ZPOS64_T relativeOffset; + + if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0) + return 0; + + + uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream); + + if (uMaxBack>uSizeFile) + uMaxBack = uSizeFile; + + buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); + if (buf==NULL) + return 0; + + uBackRead = 4; + while (uBackReaduMaxBack) + uBackRead = uMaxBack; + else + uBackRead+=BUFREADCOMMENT; + uReadPos = uSizeFile-uBackRead ; + + uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? + (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos); + if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0) + break; + + if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize) + break; + + for (i=(int)uReadSize-3; (i--)>0;) + if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && + ((*(buf+i+2))==0x06) && ((*(buf+i+3))==0x07)) + { + uPosFound = uReadPos+i; + break; + } + + if (uPosFound!=0) + break; + } + TRYFREE(buf); + if (uPosFound == 0) + return 0; + + /* Zip64 end of central directory locator */ + if (ZSEEK64(*pzlib_filefunc_def,filestream, uPosFound,ZLIB_FILEFUNC_SEEK_SET)!=0) + return 0; + + /* the signature, already checked */ + if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK) + return 0; + + /* number of the disk with the start of the zip64 end of central directory */ + if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK) + return 0; + if (uL != 0) + return 0; + + /* relative offset of the zip64 end of central directory record */ + if (unz64local_getLong64(pzlib_filefunc_def,filestream,&relativeOffset)!=UNZ_OK) + return 0; + + /* total number of disks */ + if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK) + return 0; + if (uL != 1) + return 0; + + /* Goto end of central directory record */ + if (ZSEEK64(*pzlib_filefunc_def,filestream, relativeOffset,ZLIB_FILEFUNC_SEEK_SET)!=0) + return 0; + + /* the signature */ + if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK) + return 0; + + if (uL != 0x06064b50) + return 0; + + return relativeOffset; +} + +/* + Open a Zip file. path contain the full pathname (by example, + on a Windows NT computer "c:\\test\\zlib114.zip" or on an Unix computer + "zlib/zlib114.zip". + If the zipfile cannot be opened (file doesn't exist or in not valid), the + return value is NULL. + Else, the return value is a unzFile Handle, usable with other function + of this unzip package. +*/ +local unzFile unzOpenInternal (const void *path, + zlib_filefunc64_32_def* pzlib_filefunc64_32_def, + int is64bitOpenFunction) +{ + unz64_s us; + unz64_s *s; + ZPOS64_T central_pos; + uLong uL; + + uLong number_disk; /* number of the current dist, used for + spaning ZIP, unsupported, always 0*/ + uLong number_disk_with_CD; /* number the the disk with central dir, used + for spaning ZIP, unsupported, always 0*/ + ZPOS64_T number_entry_CD; /* total number of entries in + the central dir + (same than number_entry on nospan) */ + + int err=UNZ_OK; + + if (unz_copyright[0]!=' ') + return NULL; + + us.z_filefunc.zseek32_file = NULL; + us.z_filefunc.ztell32_file = NULL; + if (pzlib_filefunc64_32_def==NULL) + fill_fopen64_filefunc(&us.z_filefunc.zfile_func64); + else + us.z_filefunc = *pzlib_filefunc64_32_def; + us.is64bitOpenFunction = is64bitOpenFunction; + + + + us.filestream = ZOPEN64(us.z_filefunc, + path, + ZLIB_FILEFUNC_MODE_READ | + ZLIB_FILEFUNC_MODE_EXISTING); + if (us.filestream==NULL) + return NULL; + + central_pos = unz64local_SearchCentralDir64(&us.z_filefunc,us.filestream); + if (central_pos) + { + uLong uS; + ZPOS64_T uL64; + + us.isZip64 = 1; + + if (ZSEEK64(us.z_filefunc, us.filestream, + central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0) + err=UNZ_ERRNO; + + /* the signature, already checked */ + if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) + err=UNZ_ERRNO; + + /* size of zip64 end of central directory record */ + if (unz64local_getLong64(&us.z_filefunc, us.filestream,&uL64)!=UNZ_OK) + err=UNZ_ERRNO; + + /* version made by */ + if (unz64local_getShort(&us.z_filefunc, us.filestream,&uS)!=UNZ_OK) + err=UNZ_ERRNO; + + /* version needed to extract */ + if (unz64local_getShort(&us.z_filefunc, us.filestream,&uS)!=UNZ_OK) + err=UNZ_ERRNO; + + /* number of this disk */ + if (unz64local_getLong(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK) + err=UNZ_ERRNO; + + /* number of the disk with the start of the central directory */ + if (unz64local_getLong(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK) + err=UNZ_ERRNO; + + /* total number of entries in the central directory on this disk */ + if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.gi.number_entry)!=UNZ_OK) + err=UNZ_ERRNO; + + /* total number of entries in the central directory */ + if (unz64local_getLong64(&us.z_filefunc, us.filestream,&number_entry_CD)!=UNZ_OK) + err=UNZ_ERRNO; + + if ((number_entry_CD!=us.gi.number_entry) || + (number_disk_with_CD!=0) || + (number_disk!=0)) + err=UNZ_BADZIPFILE; + + /* size of the central directory */ + if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.size_central_dir)!=UNZ_OK) + err=UNZ_ERRNO; + + /* offset of start of central directory with respect to the + starting disk number */ + if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.offset_central_dir)!=UNZ_OK) + err=UNZ_ERRNO; + + us.gi.size_comment = 0; + } + else + { + central_pos = unz64local_SearchCentralDir(&us.z_filefunc,us.filestream); + if (central_pos==0) + err=UNZ_ERRNO; + + us.isZip64 = 0; + + if (ZSEEK64(us.z_filefunc, us.filestream, + central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0) + err=UNZ_ERRNO; + + /* the signature, already checked */ + if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) + err=UNZ_ERRNO; + + /* number of this disk */ + if (unz64local_getShort(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK) + err=UNZ_ERRNO; + + /* number of the disk with the start of the central directory */ + if (unz64local_getShort(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK) + err=UNZ_ERRNO; + + /* total number of entries in the central dir on this disk */ + if (unz64local_getShort(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) + err=UNZ_ERRNO; + us.gi.number_entry = uL; + + /* total number of entries in the central dir */ + if (unz64local_getShort(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) + err=UNZ_ERRNO; + number_entry_CD = uL; + + if ((number_entry_CD!=us.gi.number_entry) || + (number_disk_with_CD!=0) || + (number_disk!=0)) + err=UNZ_BADZIPFILE; + + /* size of the central directory */ + if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) + err=UNZ_ERRNO; + us.size_central_dir = uL; + + /* offset of start of central directory with respect to the + starting disk number */ + if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) + err=UNZ_ERRNO; + us.offset_central_dir = uL; + + /* zipfile comment length */ + if (unz64local_getShort(&us.z_filefunc, us.filestream,&us.gi.size_comment)!=UNZ_OK) + err=UNZ_ERRNO; + } + + if ((central_pospfile_in_zip_read!=NULL) + unzCloseCurrentFile(file); + + ZCLOSE64(s->z_filefunc, s->filestream); + TRYFREE(s); + return UNZ_OK; +} + + +/* + Write info about the ZipFile in the *pglobal_info structure. + No preparation of the structure is needed + return UNZ_OK if there is no problem. */ +extern int ZEXPORT unzGetGlobalInfo64 (unzFile file, unz_global_info64* pglobal_info) +{ + unz64_s* s; + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz64_s*)file; + *pglobal_info=s->gi; + return UNZ_OK; +} + +extern int ZEXPORT unzGetGlobalInfo (unzFile file, unz_global_info* pglobal_info32) +{ + unz64_s* s; + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz64_s*)file; + /* to do : check if number_entry is not truncated */ + pglobal_info32->number_entry = (uLong)s->gi.number_entry; + pglobal_info32->size_comment = s->gi.size_comment; + return UNZ_OK; +} +/* + Translate date/time from Dos format to tm_unz (readable more easilty) +*/ +local void unz64local_DosDateToTmuDate (ZPOS64_T ulDosDate, tm_unz* ptm) +{ + ZPOS64_T uDate; + uDate = (ZPOS64_T)(ulDosDate>>16); + ptm->tm_mday = (uInt)(uDate&0x1f) ; + ptm->tm_mon = (uInt)((((uDate)&0x1E0)/0x20)-1) ; + ptm->tm_year = (uInt)(((uDate&0x0FE00)/0x0200)+1980) ; + + ptm->tm_hour = (uInt) ((ulDosDate &0xF800)/0x800); + ptm->tm_min = (uInt) ((ulDosDate&0x7E0)/0x20) ; + ptm->tm_sec = (uInt) (2*(ulDosDate&0x1f)) ; +} + +/* + Get Info about the current file in the zipfile, with internal only info +*/ +local int unz64local_GetCurrentFileInfoInternal OF((unzFile file, + unz_file_info64 *pfile_info, + unz_file_info64_internal + *pfile_info_internal, + char *szFileName, + uLong fileNameBufferSize, + void *extraField, + uLong extraFieldBufferSize, + char *szComment, + uLong commentBufferSize)); + +local int unz64local_GetCurrentFileInfoInternal (unzFile file, + unz_file_info64 *pfile_info, + unz_file_info64_internal + *pfile_info_internal, + char *szFileName, + uLong fileNameBufferSize, + void *extraField, + uLong extraFieldBufferSize, + char *szComment, + uLong commentBufferSize) +{ + unz64_s* s; + unz_file_info64 file_info; + unz_file_info64_internal file_info_internal; + int err=UNZ_OK; + uLong uMagic; + long lSeek=0; + uLong uL; + + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz64_s*)file; + if (ZSEEK64(s->z_filefunc, s->filestream, + s->pos_in_central_dir+s->byte_before_the_zipfile, + ZLIB_FILEFUNC_SEEK_SET)!=0) + err=UNZ_ERRNO; + + + /* we check the magic */ + if (err==UNZ_OK) + { + if (unz64local_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK) + err=UNZ_ERRNO; + else if (uMagic!=0x02014b50) + err=UNZ_BADZIPFILE; + } + + if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.version) != UNZ_OK) + err=UNZ_ERRNO; + + if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.version_needed) != UNZ_OK) + err=UNZ_ERRNO; + + if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.flag) != UNZ_OK) + err=UNZ_ERRNO; + + if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.compression_method) != UNZ_OK) + err=UNZ_ERRNO; + + if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.dosDate) != UNZ_OK) + err=UNZ_ERRNO; + + unz64local_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date); + + if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.crc) != UNZ_OK) + err=UNZ_ERRNO; + + if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK) + err=UNZ_ERRNO; + file_info.compressed_size = uL; + + if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK) + err=UNZ_ERRNO; + file_info.uncompressed_size = uL; + + if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_filename) != UNZ_OK) + err=UNZ_ERRNO; + + if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_extra) != UNZ_OK) + err=UNZ_ERRNO; + + if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_comment) != UNZ_OK) + err=UNZ_ERRNO; + + if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.disk_num_start) != UNZ_OK) + err=UNZ_ERRNO; + + if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.internal_fa) != UNZ_OK) + err=UNZ_ERRNO; + + if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.external_fa) != UNZ_OK) + err=UNZ_ERRNO; + + // relative offset of local header + if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK) + err=UNZ_ERRNO; + file_info_internal.offset_curfile = uL; + + lSeek+=file_info.size_filename; + if ((err==UNZ_OK) && (szFileName!=NULL)) + { + uLong uSizeRead ; + if (file_info.size_filename0) && (fileNameBufferSize>0)) + if (ZREAD64(s->z_filefunc, s->filestream,szFileName,uSizeRead)!=uSizeRead) + err=UNZ_ERRNO; + lSeek -= uSizeRead; + } + + // Read extrafield + if ((err==UNZ_OK) && (extraField!=NULL)) + { + ZPOS64_T uSizeRead ; + if (file_info.size_file_extraz_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0) + lSeek=0; + else + err=UNZ_ERRNO; + } + + if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0)) + if (ZREAD64(s->z_filefunc, s->filestream,extraField,(uLong)uSizeRead)!=uSizeRead) + err=UNZ_ERRNO; + + lSeek += file_info.size_file_extra - (uLong)uSizeRead; + } + else + lSeek += file_info.size_file_extra; + + + if ((err==UNZ_OK) && (file_info.size_file_extra != 0)) + { + uLong acc = 0; + + // since lSeek now points to after the extra field we need to move back + lSeek -= file_info.size_file_extra; + + if (lSeek!=0) + { + if (ZSEEK64(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0) + lSeek=0; + else + err=UNZ_ERRNO; + } + + while(acc < file_info.size_file_extra) + { + uLong headerId; + uLong dataSize; + + if (unz64local_getShort(&s->z_filefunc, s->filestream,&headerId) != UNZ_OK) + err=UNZ_ERRNO; + + if (unz64local_getShort(&s->z_filefunc, s->filestream,&dataSize) != UNZ_OK) + err=UNZ_ERRNO; + + /* ZIP64 extra fields */ + if (headerId == 0x0001) + { + uLong uL; + + if(file_info.uncompressed_size == (ZPOS64_T)(unsigned long)-1) + { + if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK) + err=UNZ_ERRNO; + } + + if(file_info.compressed_size == (ZPOS64_T)(unsigned long)-1) + { + if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UNZ_OK) + err=UNZ_ERRNO; + } + + if(file_info_internal.offset_curfile == (ZPOS64_T)(unsigned long)-1) + { + /* Relative Header offset */ + if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfile) != UNZ_OK) + err=UNZ_ERRNO; + } + + if(file_info.disk_num_start == (unsigned long)-1) + { + /* Disk Start Number */ + if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK) + err=UNZ_ERRNO; + } + + } + else + { + if (ZSEEK64(s->z_filefunc, s->filestream,dataSize,ZLIB_FILEFUNC_SEEK_CUR)!=0) + err=UNZ_ERRNO; + } + + acc += 2 + 2 + dataSize; + } + } + + if ((err==UNZ_OK) && (szComment!=NULL)) + { + uLong uSizeRead ; + if (file_info.size_file_commentz_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0) + lSeek=0; + else + err=UNZ_ERRNO; + } + + if ((file_info.size_file_comment>0) && (commentBufferSize>0)) + if (ZREAD64(s->z_filefunc, s->filestream,szComment,uSizeRead)!=uSizeRead) + err=UNZ_ERRNO; + lSeek+=file_info.size_file_comment - uSizeRead; + } + else + lSeek+=file_info.size_file_comment; + + + if ((err==UNZ_OK) && (pfile_info!=NULL)) + *pfile_info=file_info; + + if ((err==UNZ_OK) && (pfile_info_internal!=NULL)) + *pfile_info_internal=file_info_internal; + + return err; +} + + + +/* + Write info about the ZipFile in the *pglobal_info structure. + No preparation of the structure is needed + return UNZ_OK if there is no problem. +*/ +extern int ZEXPORT unzGetCurrentFileInfo64 (unzFile file, + unz_file_info64 * pfile_info, + char * szFileName, uLong fileNameBufferSize, + void *extraField, uLong extraFieldBufferSize, + char* szComment, uLong commentBufferSize) +{ + return unz64local_GetCurrentFileInfoInternal(file,pfile_info,NULL, + szFileName,fileNameBufferSize, + extraField,extraFieldBufferSize, + szComment,commentBufferSize); +} + +extern int ZEXPORT unzGetCurrentFileInfo (unzFile file, + unz_file_info * pfile_info, + char * szFileName, uLong fileNameBufferSize, + void *extraField, uLong extraFieldBufferSize, + char* szComment, uLong commentBufferSize) +{ + int err; + unz_file_info64 file_info64; + err = unz64local_GetCurrentFileInfoInternal(file,&file_info64,NULL, + szFileName,fileNameBufferSize, + extraField,extraFieldBufferSize, + szComment,commentBufferSize); + if (err==UNZ_OK) + { + pfile_info->version = file_info64.version; + pfile_info->version_needed = file_info64.version_needed; + pfile_info->flag = file_info64.flag; + pfile_info->compression_method = file_info64.compression_method; + pfile_info->dosDate = file_info64.dosDate; + pfile_info->crc = file_info64.crc; + + pfile_info->size_filename = file_info64.size_filename; + pfile_info->size_file_extra = file_info64.size_file_extra; + pfile_info->size_file_comment = file_info64.size_file_comment; + + pfile_info->disk_num_start = file_info64.disk_num_start; + pfile_info->internal_fa = file_info64.internal_fa; + pfile_info->external_fa = file_info64.external_fa; + + pfile_info->tmu_date = file_info64.tmu_date, + + + pfile_info->compressed_size = (uLong)file_info64.compressed_size; + pfile_info->uncompressed_size = (uLong)file_info64.uncompressed_size; + + } + return err; +} +/* + Set the current file of the zipfile to the first file. + return UNZ_OK if there is no problem +*/ +extern int ZEXPORT unzGoToFirstFile (unzFile file) +{ + int err=UNZ_OK; + unz64_s* s; + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz64_s*)file; + s->pos_in_central_dir=s->offset_central_dir; + s->num_file=0; + err=unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info, + &s->cur_file_info_internal, + NULL,0,NULL,0,NULL,0); + s->current_file_ok = (err == UNZ_OK); + return err; +} + +/* + Set the current file of the zipfile to the next file. + return UNZ_OK if there is no problem + return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. +*/ +extern int ZEXPORT unzGoToNextFile (unzFile file) +{ + unz64_s* s; + int err; + + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz64_s*)file; + if (!s->current_file_ok) + return UNZ_END_OF_LIST_OF_FILE; + if (s->gi.number_entry != 0xffff) /* 2^16 files overflow hack */ + if (s->num_file+1==s->gi.number_entry) + return UNZ_END_OF_LIST_OF_FILE; + + s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename + + s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ; + s->num_file++; + err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info, + &s->cur_file_info_internal, + NULL,0,NULL,0,NULL,0); + s->current_file_ok = (err == UNZ_OK); + return err; +} + + +/* + Try locate the file szFileName in the zipfile. + For the iCaseSensitivity signification, see unzipStringFileNameCompare + + return value : + UNZ_OK if the file is found. It becomes the current file. + UNZ_END_OF_LIST_OF_FILE if the file is not found +*/ +extern int ZEXPORT unzLocateFile (unzFile file, const char *szFileName, int iCaseSensitivity) +{ + unz64_s* s; + int err; + + /* We remember the 'current' position in the file so that we can jump + * back there if we fail. + */ + unz_file_info64 cur_file_infoSaved; + unz_file_info64_internal cur_file_info_internalSaved; + ZPOS64_T num_fileSaved; + ZPOS64_T pos_in_central_dirSaved; + + + if (file==NULL) + return UNZ_PARAMERROR; + + if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP) + return UNZ_PARAMERROR; + + s=(unz64_s*)file; + if (!s->current_file_ok) + return UNZ_END_OF_LIST_OF_FILE; + + /* Save the current state */ + num_fileSaved = s->num_file; + pos_in_central_dirSaved = s->pos_in_central_dir; + cur_file_infoSaved = s->cur_file_info; + cur_file_info_internalSaved = s->cur_file_info_internal; + + err = unzGoToFirstFile(file); + + while (err == UNZ_OK) + { + char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1]; + err = unzGetCurrentFileInfo64(file,NULL, + szCurrentFileName,sizeof(szCurrentFileName)-1, + NULL,0,NULL,0); + if (err == UNZ_OK) + { + if (unzStringFileNameCompare(szCurrentFileName, + szFileName,iCaseSensitivity)==0) + return UNZ_OK; + err = unzGoToNextFile(file); + } + } + + /* We failed, so restore the state of the 'current file' to where we + * were. + */ + s->num_file = num_fileSaved ; + s->pos_in_central_dir = pos_in_central_dirSaved ; + s->cur_file_info = cur_file_infoSaved; + s->cur_file_info_internal = cur_file_info_internalSaved; + return err; +} + + +/* +/////////////////////////////////////////// +// Contributed by Ryan Haksi (mailto://cryogen@infoserve.net) +// I need random access +// +// Further optimization could be realized by adding an ability +// to cache the directory in memory. The goal being a single +// comprehensive file read to put the file I need in a memory. +*/ + +/* +typedef struct unz_file_pos_s +{ + ZPOS64_T pos_in_zip_directory; // offset in file + ZPOS64_T num_of_file; // # of file +} unz_file_pos; +*/ + +extern int ZEXPORT unzGetFilePos64(unzFile file, unz64_file_pos* file_pos) +{ + unz64_s* s; + + if (file==NULL || file_pos==NULL) + return UNZ_PARAMERROR; + s=(unz64_s*)file; + if (!s->current_file_ok) + return UNZ_END_OF_LIST_OF_FILE; + + file_pos->pos_in_zip_directory = s->pos_in_central_dir; + file_pos->num_of_file = s->num_file; + + return UNZ_OK; +} + +extern int ZEXPORT unzGetFilePos( + unzFile file, + unz_file_pos* file_pos) +{ + unz64_file_pos file_pos64; + int err = unzGetFilePos64(file,&file_pos64); + if (err==UNZ_OK) + { + file_pos->pos_in_zip_directory = (uLong)file_pos64.pos_in_zip_directory; + file_pos->num_of_file = (uLong)file_pos64.num_of_file; + } + return err; +} + +extern int ZEXPORT unzGoToFilePos64(unzFile file, const unz64_file_pos* file_pos) +{ + unz64_s* s; + int err; + + if (file==NULL || file_pos==NULL) + return UNZ_PARAMERROR; + s=(unz64_s*)file; + + /* jump to the right spot */ + s->pos_in_central_dir = file_pos->pos_in_zip_directory; + s->num_file = file_pos->num_of_file; + + /* set the current file */ + err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info, + &s->cur_file_info_internal, + NULL,0,NULL,0,NULL,0); + /* return results */ + s->current_file_ok = (err == UNZ_OK); + return err; +} + +extern int ZEXPORT unzGoToFilePos( + unzFile file, + unz_file_pos* file_pos) +{ + unz64_file_pos file_pos64; + if (file_pos == NULL) + return UNZ_PARAMERROR; + + file_pos64.pos_in_zip_directory = file_pos->pos_in_zip_directory; + file_pos64.num_of_file = file_pos->num_of_file; + return unzGoToFilePos64(file,&file_pos64); +} + +/* +// Unzip Helper Functions - should be here? +/////////////////////////////////////////// +*/ + +/* + Read the local header of the current zipfile + Check the coherency of the local header and info in the end of central + directory about this file + store in *piSizeVar the size of extra info in local header + (filename and size of extra field data) +*/ +local int unz64local_CheckCurrentFileCoherencyHeader (unz64_s* s, uInt* piSizeVar, + ZPOS64_T * poffset_local_extrafield, + uInt * psize_local_extrafield) +{ + uLong uMagic,uData,uFlags; + uLong size_filename; + uLong size_extra_field; + int err=UNZ_OK; + + *piSizeVar = 0; + *poffset_local_extrafield = 0; + *psize_local_extrafield = 0; + + if (ZSEEK64(s->z_filefunc, s->filestream,s->cur_file_info_internal.offset_curfile + + s->byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0) + return UNZ_ERRNO; + + + if (err==UNZ_OK) + { + if (unz64local_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK) + err=UNZ_ERRNO; + else if (uMagic!=0x04034b50) + err=UNZ_BADZIPFILE; + } + + if (unz64local_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) + err=UNZ_ERRNO; +/* + else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion)) + err=UNZ_BADZIPFILE; +*/ + if (unz64local_getShort(&s->z_filefunc, s->filestream,&uFlags) != UNZ_OK) + err=UNZ_ERRNO; + + if (unz64local_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) + err=UNZ_ERRNO; + else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method)) + err=UNZ_BADZIPFILE; + + if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) && +/* #ifdef HAVE_BZIP2 */ + (s->cur_file_info.compression_method!=Z_BZIP2ED) && +/* #endif */ + (s->cur_file_info.compression_method!=Z_DEFLATED)) + err=UNZ_BADZIPFILE; + + if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* date/time */ + err=UNZ_ERRNO; + + if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* crc */ + err=UNZ_ERRNO; + else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) && ((uFlags & 8)==0)) + err=UNZ_BADZIPFILE; + + if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size compr */ + err=UNZ_ERRNO; + else if (uData != 0xFFFFFFFF && (err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) && ((uFlags & 8)==0)) + err=UNZ_BADZIPFILE; + + if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size uncompr */ + err=UNZ_ERRNO; + else if (uData != 0xFFFFFFFF && (err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) && ((uFlags & 8)==0)) + err=UNZ_BADZIPFILE; + + if (unz64local_getShort(&s->z_filefunc, s->filestream,&size_filename) != UNZ_OK) + err=UNZ_ERRNO; + else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename)) + err=UNZ_BADZIPFILE; + + *piSizeVar += (uInt)size_filename; + + if (unz64local_getShort(&s->z_filefunc, s->filestream,&size_extra_field) != UNZ_OK) + err=UNZ_ERRNO; + *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile + + SIZEZIPLOCALHEADER + size_filename; + *psize_local_extrafield = (uInt)size_extra_field; + + *piSizeVar += (uInt)size_extra_field; + + return err; +} + +/* + Open for reading data the current file in the zipfile. + If there is no error and the file is opened, the return value is UNZ_OK. +*/ +extern int ZEXPORT unzOpenCurrentFile3 (unzFile file, int* method, + int* level, int raw, const char* password) +{ + int err=UNZ_OK; + uInt iSizeVar; + unz64_s* s; + file_in_zip64_read_info_s* pfile_in_zip_read_info; + ZPOS64_T offset_local_extrafield; /* offset of the local extra field */ + uInt size_local_extrafield; /* size of the local extra field */ +# ifndef NOUNCRYPT + char source[12]; +# else + if (password != NULL) + return UNZ_PARAMERROR; +# endif + + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz64_s*)file; + if (!s->current_file_ok) + return UNZ_PARAMERROR; + + if (s->pfile_in_zip_read != NULL) + unzCloseCurrentFile(file); + + if (unz64local_CheckCurrentFileCoherencyHeader(s,&iSizeVar, &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK) + return UNZ_BADZIPFILE; + + pfile_in_zip_read_info = (file_in_zip64_read_info_s*)ALLOC(sizeof(file_in_zip64_read_info_s)); + if (pfile_in_zip_read_info==NULL) + return UNZ_INTERNALERROR; + + pfile_in_zip_read_info->read_buffer=(char*)ALLOC(UNZ_BUFSIZE); + pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield; + pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield; + pfile_in_zip_read_info->pos_local_extrafield=0; + pfile_in_zip_read_info->raw=raw; + + if (pfile_in_zip_read_info->read_buffer==NULL) + { + TRYFREE(pfile_in_zip_read_info); + return UNZ_INTERNALERROR; + } + + pfile_in_zip_read_info->stream_initialised=0; + + if (method!=NULL) + *method = (int)s->cur_file_info.compression_method; + + if (level!=NULL) + { + *level = 6; + switch (s->cur_file_info.flag & 0x06) + { + case 6 : *level = 1; break; + case 4 : *level = 2; break; + case 2 : *level = 9; break; + } + } + + if ((s->cur_file_info.compression_method!=0) && +/* #ifdef HAVE_BZIP2 */ + (s->cur_file_info.compression_method!=Z_BZIP2ED) && +/* #endif */ + (s->cur_file_info.compression_method!=Z_DEFLATED)) + + err=UNZ_BADZIPFILE; + + pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc; + pfile_in_zip_read_info->crc32=0; + pfile_in_zip_read_info->total_out_64=0; + pfile_in_zip_read_info->compression_method = s->cur_file_info.compression_method; + pfile_in_zip_read_info->filestream=s->filestream; + pfile_in_zip_read_info->z_filefunc=s->z_filefunc; + pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile; + + pfile_in_zip_read_info->stream.total_out = 0; + + if ((s->cur_file_info.compression_method==Z_BZIP2ED) && (!raw)) + { +#ifdef HAVE_BZIP2 + pfile_in_zip_read_info->bstream.bzalloc = (void *(*) (void *, int, int))0; + pfile_in_zip_read_info->bstream.bzfree = (free_func)0; + pfile_in_zip_read_info->bstream.opaque = (voidpf)0; + pfile_in_zip_read_info->bstream.state = (voidpf)0; + + pfile_in_zip_read_info->stream.zalloc = (alloc_func)0; + pfile_in_zip_read_info->stream.zfree = (free_func)0; + pfile_in_zip_read_info->stream.opaque = (voidpf)0; + pfile_in_zip_read_info->stream.next_in = (voidpf)0; + pfile_in_zip_read_info->stream.avail_in = 0; + + err=BZ2_bzDecompressInit(&pfile_in_zip_read_info->bstream, 0, 0); + if (err == Z_OK) + pfile_in_zip_read_info->stream_initialised=Z_BZIP2ED; + else + { + TRYFREE(pfile_in_zip_read_info); + return err; + } +#else + pfile_in_zip_read_info->raw=1; +#endif + } + else if ((s->cur_file_info.compression_method==Z_DEFLATED) && (!raw)) + { + pfile_in_zip_read_info->stream.zalloc = (alloc_func)0; + pfile_in_zip_read_info->stream.zfree = (free_func)0; + pfile_in_zip_read_info->stream.opaque = (voidpf)0; + pfile_in_zip_read_info->stream.next_in = 0; + pfile_in_zip_read_info->stream.avail_in = 0; + + err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS); + if (err == Z_OK) + pfile_in_zip_read_info->stream_initialised=Z_DEFLATED; + else + { + TRYFREE(pfile_in_zip_read_info); + return err; + } + /* windowBits is passed < 0 to tell that there is no zlib header. + * Note that in this case inflate *requires* an extra "dummy" byte + * after the compressed stream in order to complete decompression and + * return Z_STREAM_END. + * In unzip, i don't wait absolutely Z_STREAM_END because I known the + * size of both compressed and uncompressed data + */ + } + pfile_in_zip_read_info->rest_read_compressed = + s->cur_file_info.compressed_size ; + pfile_in_zip_read_info->rest_read_uncompressed = + s->cur_file_info.uncompressed_size ; + + + pfile_in_zip_read_info->pos_in_zipfile = + s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER + + iSizeVar; + + pfile_in_zip_read_info->stream.avail_in = (uInt)0; + + s->pfile_in_zip_read = pfile_in_zip_read_info; + s->encrypted = 0; + +# ifndef NOUNCRYPT + if (password != NULL) + { + int i; + s->pcrc_32_tab = get_crc_table(); + init_keys(password,s->keys,s->pcrc_32_tab); + if (ZSEEK64(s->z_filefunc, s->filestream, + s->pfile_in_zip_read->pos_in_zipfile + + s->pfile_in_zip_read->byte_before_the_zipfile, + SEEK_SET)!=0) + return UNZ_INTERNALERROR; + if(ZREAD64(s->z_filefunc, s->filestream,source, 12)<12) + return UNZ_INTERNALERROR; + + for (i = 0; i<12; i++) + zdecode(s->keys,s->pcrc_32_tab,source[i]); + + s->pfile_in_zip_read->pos_in_zipfile+=12; + s->encrypted=1; + } +# endif + + + return UNZ_OK; +} + +extern int ZEXPORT unzOpenCurrentFile (unzFile file) +{ + return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL); +} + +extern int ZEXPORT unzOpenCurrentFilePassword (unzFile file, const char* password) +{ + return unzOpenCurrentFile3(file, NULL, NULL, 0, password); +} + +extern int ZEXPORT unzOpenCurrentFile2 (unzFile file, int* method, int* level, int raw) +{ + return unzOpenCurrentFile3(file, method, level, raw, NULL); +} + +/** Addition for GDAL : START */ + +extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64( unzFile file) +{ + unz64_s* s; + file_in_zip64_read_info_s* pfile_in_zip_read_info; + s=(unz64_s*)file; + if (file==NULL) + return 0; //UNZ_PARAMERROR; + pfile_in_zip_read_info=s->pfile_in_zip_read; + if (pfile_in_zip_read_info==NULL) + return 0; //UNZ_PARAMERROR; + return pfile_in_zip_read_info->pos_in_zipfile + + pfile_in_zip_read_info->byte_before_the_zipfile; +} + +/** Addition for GDAL : END */ + +/* + Read bytes from the current file. + buf contain buffer where data must be copied + len the size of buf. + + return the number of byte copied if somes bytes are copied + return 0 if the end of file was reached + return <0 with error code if there is an error + (UNZ_ERRNO for IO error, or zLib error for uncompress error) +*/ +extern int ZEXPORT unzReadCurrentFile (unzFile file, voidp buf, unsigned len) +{ + int err=UNZ_OK; + uInt iRead = 0; + unz64_s* s; + file_in_zip64_read_info_s* pfile_in_zip_read_info; + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz64_s*)file; + pfile_in_zip_read_info=s->pfile_in_zip_read; + + if (pfile_in_zip_read_info==NULL) + return UNZ_PARAMERROR; + + + if ((pfile_in_zip_read_info->read_buffer == NULL)) + return UNZ_END_OF_LIST_OF_FILE; + if (len==0) + return 0; + + pfile_in_zip_read_info->stream.next_out = (Bytef*)buf; + + pfile_in_zip_read_info->stream.avail_out = (uInt)len; + + if ((len>pfile_in_zip_read_info->rest_read_uncompressed) && + (!(pfile_in_zip_read_info->raw))) + pfile_in_zip_read_info->stream.avail_out = + (uInt)pfile_in_zip_read_info->rest_read_uncompressed; + + if ((len>pfile_in_zip_read_info->rest_read_compressed+ + pfile_in_zip_read_info->stream.avail_in) && + (pfile_in_zip_read_info->raw)) + pfile_in_zip_read_info->stream.avail_out = + (uInt)pfile_in_zip_read_info->rest_read_compressed+ + pfile_in_zip_read_info->stream.avail_in; + + while (pfile_in_zip_read_info->stream.avail_out>0) + { + if ((pfile_in_zip_read_info->stream.avail_in==0) && + (pfile_in_zip_read_info->rest_read_compressed>0)) + { + uInt uReadThis = UNZ_BUFSIZE; + if (pfile_in_zip_read_info->rest_read_compressedrest_read_compressed; + if (uReadThis == 0) + return UNZ_EOF; + if (ZSEEK64(pfile_in_zip_read_info->z_filefunc, + pfile_in_zip_read_info->filestream, + pfile_in_zip_read_info->pos_in_zipfile + + pfile_in_zip_read_info->byte_before_the_zipfile, + ZLIB_FILEFUNC_SEEK_SET)!=0) + return UNZ_ERRNO; + if (ZREAD64(pfile_in_zip_read_info->z_filefunc, + pfile_in_zip_read_info->filestream, + pfile_in_zip_read_info->read_buffer, + uReadThis)!=uReadThis) + return UNZ_ERRNO; + + +# ifndef NOUNCRYPT + if(s->encrypted) + { + uInt i; + for(i=0;iread_buffer[i] = + zdecode(s->keys,s->pcrc_32_tab, + pfile_in_zip_read_info->read_buffer[i]); + } +# endif + + + pfile_in_zip_read_info->pos_in_zipfile += uReadThis; + + pfile_in_zip_read_info->rest_read_compressed-=uReadThis; + + pfile_in_zip_read_info->stream.next_in = + (Bytef*)pfile_in_zip_read_info->read_buffer; + pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis; + } + + if ((pfile_in_zip_read_info->compression_method==0) || (pfile_in_zip_read_info->raw)) + { + uInt uDoCopy,i ; + + if ((pfile_in_zip_read_info->stream.avail_in == 0) && + (pfile_in_zip_read_info->rest_read_compressed == 0)) + return (iRead==0) ? UNZ_EOF : iRead; + + if (pfile_in_zip_read_info->stream.avail_out < + pfile_in_zip_read_info->stream.avail_in) + uDoCopy = pfile_in_zip_read_info->stream.avail_out ; + else + uDoCopy = pfile_in_zip_read_info->stream.avail_in ; + + for (i=0;istream.next_out+i) = + *(pfile_in_zip_read_info->stream.next_in+i); + + pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uDoCopy; + + pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32, + pfile_in_zip_read_info->stream.next_out, + uDoCopy); + pfile_in_zip_read_info->rest_read_uncompressed-=uDoCopy; + pfile_in_zip_read_info->stream.avail_in -= uDoCopy; + pfile_in_zip_read_info->stream.avail_out -= uDoCopy; + pfile_in_zip_read_info->stream.next_out += uDoCopy; + pfile_in_zip_read_info->stream.next_in += uDoCopy; + pfile_in_zip_read_info->stream.total_out += uDoCopy; + iRead += uDoCopy; + } + else if (pfile_in_zip_read_info->compression_method==Z_BZIP2ED) + { +#ifdef HAVE_BZIP2 + uLong uTotalOutBefore,uTotalOutAfter; + const Bytef *bufBefore; + uLong uOutThis; + + pfile_in_zip_read_info->bstream.next_in = (char*)pfile_in_zip_read_info->stream.next_in; + pfile_in_zip_read_info->bstream.avail_in = pfile_in_zip_read_info->stream.avail_in; + pfile_in_zip_read_info->bstream.total_in_lo32 = pfile_in_zip_read_info->stream.total_in; + pfile_in_zip_read_info->bstream.total_in_hi32 = 0; + pfile_in_zip_read_info->bstream.next_out = (char*)pfile_in_zip_read_info->stream.next_out; + pfile_in_zip_read_info->bstream.avail_out = pfile_in_zip_read_info->stream.avail_out; + pfile_in_zip_read_info->bstream.total_out_lo32 = pfile_in_zip_read_info->stream.total_out; + pfile_in_zip_read_info->bstream.total_out_hi32 = 0; + + uTotalOutBefore = pfile_in_zip_read_info->bstream.total_out_lo32; + bufBefore = (const Bytef *)pfile_in_zip_read_info->bstream.next_out; + + err=BZ2_bzDecompress(&pfile_in_zip_read_info->bstream); + + uTotalOutAfter = pfile_in_zip_read_info->bstream.total_out_lo32; + uOutThis = uTotalOutAfter-uTotalOutBefore; + + pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uOutThis; + + pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,bufBefore, (uInt)(uOutThis)); + pfile_in_zip_read_info->rest_read_uncompressed -= uOutThis; + iRead += (uInt)(uTotalOutAfter - uTotalOutBefore); + + pfile_in_zip_read_info->stream.next_in = (Bytef*)pfile_in_zip_read_info->bstream.next_in; + pfile_in_zip_read_info->stream.avail_in = pfile_in_zip_read_info->bstream.avail_in; + pfile_in_zip_read_info->stream.total_in = pfile_in_zip_read_info->bstream.total_in_lo32; + pfile_in_zip_read_info->stream.next_out = (Bytef*)pfile_in_zip_read_info->bstream.next_out; + pfile_in_zip_read_info->stream.avail_out = pfile_in_zip_read_info->bstream.avail_out; + pfile_in_zip_read_info->stream.total_out = pfile_in_zip_read_info->bstream.total_out_lo32; + + if (err==BZ_STREAM_END) + return (iRead==0) ? UNZ_EOF : iRead; + if (err!=BZ_OK) + break; +#endif + } // end Z_BZIP2ED + else + { + ZPOS64_T uTotalOutBefore,uTotalOutAfter; + const Bytef *bufBefore; + ZPOS64_T uOutThis; + int flush=Z_SYNC_FLUSH; + + uTotalOutBefore = pfile_in_zip_read_info->stream.total_out; + bufBefore = pfile_in_zip_read_info->stream.next_out; + + /* + if ((pfile_in_zip_read_info->rest_read_uncompressed == + pfile_in_zip_read_info->stream.avail_out) && + (pfile_in_zip_read_info->rest_read_compressed == 0)) + flush = Z_FINISH; + */ + err=inflate(&pfile_in_zip_read_info->stream,flush); + + if ((err>=0) && (pfile_in_zip_read_info->stream.msg!=NULL)) + err = Z_DATA_ERROR; + + uTotalOutAfter = pfile_in_zip_read_info->stream.total_out; + uOutThis = uTotalOutAfter-uTotalOutBefore; + + pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uOutThis; + + pfile_in_zip_read_info->crc32 = + crc32(pfile_in_zip_read_info->crc32,bufBefore, + (uInt)(uOutThis)); + + pfile_in_zip_read_info->rest_read_uncompressed -= + uOutThis; + + iRead += (uInt)(uTotalOutAfter - uTotalOutBefore); + + if (err==Z_STREAM_END) + return (iRead==0) ? UNZ_EOF : iRead; + if (err!=Z_OK) + break; + } + } + + if (err==Z_OK) + return iRead; + return err; +} + + +/* + Give the current position in uncompressed data +*/ +extern z_off_t ZEXPORT unztell (unzFile file) +{ + unz64_s* s; + file_in_zip64_read_info_s* pfile_in_zip_read_info; + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz64_s*)file; + pfile_in_zip_read_info=s->pfile_in_zip_read; + + if (pfile_in_zip_read_info==NULL) + return UNZ_PARAMERROR; + + return (z_off_t)pfile_in_zip_read_info->stream.total_out; +} + +extern ZPOS64_T ZEXPORT unztell64 (unzFile file) +{ + + unz64_s* s; + file_in_zip64_read_info_s* pfile_in_zip_read_info; + if (file==NULL) + return (ZPOS64_T)-1; + s=(unz64_s*)file; + pfile_in_zip_read_info=s->pfile_in_zip_read; + + if (pfile_in_zip_read_info==NULL) + return (ZPOS64_T)-1; + + return pfile_in_zip_read_info->total_out_64; +} + + +/* + return 1 if the end of file was reached, 0 elsewhere +*/ +extern int ZEXPORT unzeof (unzFile file) +{ + unz64_s* s; + file_in_zip64_read_info_s* pfile_in_zip_read_info; + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz64_s*)file; + pfile_in_zip_read_info=s->pfile_in_zip_read; + + if (pfile_in_zip_read_info==NULL) + return UNZ_PARAMERROR; + + if (pfile_in_zip_read_info->rest_read_uncompressed == 0) + return 1; + else + return 0; +} + + + +/* +Read extra field from the current file (opened by unzOpenCurrentFile) +This is the local-header version of the extra field (sometimes, there is +more info in the local-header version than in the central-header) + + if buf==NULL, it return the size of the local extra field that can be read + + if buf!=NULL, len is the size of the buffer, the extra header is copied in + buf. + the return value is the number of bytes copied in buf, or (if <0) + the error code +*/ +extern int ZEXPORT unzGetLocalExtrafield (unzFile file, voidp buf, unsigned len) +{ + unz64_s* s; + file_in_zip64_read_info_s* pfile_in_zip_read_info; + uInt read_now; + ZPOS64_T size_to_read; + + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz64_s*)file; + pfile_in_zip_read_info=s->pfile_in_zip_read; + + if (pfile_in_zip_read_info==NULL) + return UNZ_PARAMERROR; + + size_to_read = (pfile_in_zip_read_info->size_local_extrafield - + pfile_in_zip_read_info->pos_local_extrafield); + + if (buf==NULL) + return (int)size_to_read; + + if (len>size_to_read) + read_now = (uInt)size_to_read; + else + read_now = (uInt)len ; + + if (read_now==0) + return 0; + + if (ZSEEK64(pfile_in_zip_read_info->z_filefunc, + pfile_in_zip_read_info->filestream, + pfile_in_zip_read_info->offset_local_extrafield + + pfile_in_zip_read_info->pos_local_extrafield, + ZLIB_FILEFUNC_SEEK_SET)!=0) + return UNZ_ERRNO; + + if (ZREAD64(pfile_in_zip_read_info->z_filefunc, + pfile_in_zip_read_info->filestream, + buf,read_now)!=read_now) + return UNZ_ERRNO; + + return (int)read_now; +} + +/* + Close the file in zip opened with unzipOpenCurrentFile + Return UNZ_CRCERROR if all the file was read but the CRC is not good +*/ +extern int ZEXPORT unzCloseCurrentFile (unzFile file) +{ + int err=UNZ_OK; + + unz64_s* s; + file_in_zip64_read_info_s* pfile_in_zip_read_info; + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz64_s*)file; + pfile_in_zip_read_info=s->pfile_in_zip_read; + + if (pfile_in_zip_read_info==NULL) + return UNZ_PARAMERROR; + + + if ((pfile_in_zip_read_info->rest_read_uncompressed == 0) && + (!pfile_in_zip_read_info->raw)) + { + if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait) + err=UNZ_CRCERROR; + } + + + TRYFREE(pfile_in_zip_read_info->read_buffer); + pfile_in_zip_read_info->read_buffer = NULL; + if (pfile_in_zip_read_info->stream_initialised == Z_DEFLATED) + inflateEnd(&pfile_in_zip_read_info->stream); +#ifdef HAVE_BZIP2 + else if (pfile_in_zip_read_info->stream_initialised == Z_BZIP2ED) + BZ2_bzDecompressEnd(&pfile_in_zip_read_info->bstream); +#endif + + + pfile_in_zip_read_info->stream_initialised = 0; + TRYFREE(pfile_in_zip_read_info); + + s->pfile_in_zip_read=NULL; + + return err; +} + + +/* + Get the global comment string of the ZipFile, in the szComment buffer. + uSizeBuf is the size of the szComment buffer. + return the number of byte copied or an error code <0 +*/ +extern int ZEXPORT unzGetGlobalComment (unzFile file, char * szComment, uLong uSizeBuf) +{ + unz64_s* s; + uLong uReadThis ; + if (file==NULL) + return (int)UNZ_PARAMERROR; + s=(unz64_s*)file; + + uReadThis = uSizeBuf; + if (uReadThis>s->gi.size_comment) + uReadThis = s->gi.size_comment; + + if (ZSEEK64(s->z_filefunc,s->filestream,s->central_pos+22,ZLIB_FILEFUNC_SEEK_SET)!=0) + return UNZ_ERRNO; + + if (uReadThis>0) + { + *szComment='\0'; + if (ZREAD64(s->z_filefunc,s->filestream,szComment,uReadThis)!=uReadThis) + return UNZ_ERRNO; + } + + if ((szComment != NULL) && (uSizeBuf > s->gi.size_comment)) + *(szComment+s->gi.size_comment)='\0'; + return (int)uReadThis; +} + +/* Additions by RX '2004 */ +extern ZPOS64_T ZEXPORT unzGetOffset64(unzFile file) +{ + unz64_s* s; + + if (file==NULL) + return 0; //UNZ_PARAMERROR; + s=(unz64_s*)file; + if (!s->current_file_ok) + return 0; + if (s->gi.number_entry != 0 && s->gi.number_entry != 0xffff) + if (s->num_file==s->gi.number_entry) + return 0; + return s->pos_in_central_dir; +} + +extern uLong ZEXPORT unzGetOffset (unzFile file) +{ + ZPOS64_T offset64; + + if (file==NULL) + return 0; //UNZ_PARAMERROR; + offset64 = unzGetOffset64(file); + return (uLong)offset64; +} + +extern int ZEXPORT unzSetOffset64(unzFile file, ZPOS64_T pos) +{ + unz64_s* s; + int err; + + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz64_s*)file; + + s->pos_in_central_dir = pos; + s->num_file = s->gi.number_entry; /* hack */ + err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info, + &s->cur_file_info_internal, + NULL,0,NULL,0,NULL,0); + s->current_file_ok = (err == UNZ_OK); + return err; +} + +extern int ZEXPORT unzSetOffset (unzFile file, uLong pos) +{ + return unzSetOffset64(file,pos); +} diff --git a/libs/zlib/contrib/minizip/unzip.h b/libs/zlib/contrib/minizip/unzip.h new file mode 100644 index 000000000..3183968b7 --- /dev/null +++ b/libs/zlib/contrib/minizip/unzip.h @@ -0,0 +1,437 @@ +/* unzip.h -- IO for uncompress .zip files using zlib + Version 1.1, February 14h, 2010 + part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) + + Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) + + Modifications of Unzip for Zip64 + Copyright (C) 2007-2008 Even Rouault + + Modifications for Zip64 support on both zip and unzip + Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) + + For more info read MiniZip_info.txt + + --------------------------------------------------------------------------------- + + Condition of use and distribution are the same than zlib : + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + --------------------------------------------------------------------------------- + + Changes + + See header of unzip64.c + +*/ + +#ifndef _unz64_H +#define _unz64_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _ZLIB_H +#include "zlib.h" +#endif + +#ifndef _ZLIBIOAPI_H +#include "ioapi.h" +#endif + +#ifdef HAVE_BZIP2 +#include "bzlib.h" +#endif + +#define Z_BZIP2ED 12 + +#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP) +/* like the STRICT of WIN32, we define a pointer that cannot be converted + from (void*) without cast */ +typedef struct TagunzFile__ { int unused; } unzFile__; +typedef unzFile__ *unzFile; +#else +typedef voidp unzFile; +#endif + + +#define UNZ_OK (0) +#define UNZ_END_OF_LIST_OF_FILE (-100) +#define UNZ_ERRNO (Z_ERRNO) +#define UNZ_EOF (0) +#define UNZ_PARAMERROR (-102) +#define UNZ_BADZIPFILE (-103) +#define UNZ_INTERNALERROR (-104) +#define UNZ_CRCERROR (-105) + +/* tm_unz contain date/time info */ +typedef struct tm_unz_s +{ + uInt tm_sec; /* seconds after the minute - [0,59] */ + uInt tm_min; /* minutes after the hour - [0,59] */ + uInt tm_hour; /* hours since midnight - [0,23] */ + uInt tm_mday; /* day of the month - [1,31] */ + uInt tm_mon; /* months since January - [0,11] */ + uInt tm_year; /* years - [1980..2044] */ +} tm_unz; + +/* unz_global_info structure contain global data about the ZIPfile + These data comes from the end of central dir */ +typedef struct unz_global_info64_s +{ + ZPOS64_T number_entry; /* total number of entries in + the central dir on this disk */ + uLong size_comment; /* size of the global comment of the zipfile */ +} unz_global_info64; + +typedef struct unz_global_info_s +{ + uLong number_entry; /* total number of entries in + the central dir on this disk */ + uLong size_comment; /* size of the global comment of the zipfile */ +} unz_global_info; + +/* unz_file_info contain information about a file in the zipfile */ +typedef struct unz_file_info64_s +{ + uLong version; /* version made by 2 bytes */ + uLong version_needed; /* version needed to extract 2 bytes */ + uLong flag; /* general purpose bit flag 2 bytes */ + uLong compression_method; /* compression method 2 bytes */ + uLong dosDate; /* last mod file date in Dos fmt 4 bytes */ + uLong crc; /* crc-32 4 bytes */ + ZPOS64_T compressed_size; /* compressed size 8 bytes */ + ZPOS64_T uncompressed_size; /* uncompressed size 8 bytes */ + uLong size_filename; /* filename length 2 bytes */ + uLong size_file_extra; /* extra field length 2 bytes */ + uLong size_file_comment; /* file comment length 2 bytes */ + + uLong disk_num_start; /* disk number start 2 bytes */ + uLong internal_fa; /* internal file attributes 2 bytes */ + uLong external_fa; /* external file attributes 4 bytes */ + + tm_unz tmu_date; +} unz_file_info64; + +typedef struct unz_file_info_s +{ + uLong version; /* version made by 2 bytes */ + uLong version_needed; /* version needed to extract 2 bytes */ + uLong flag; /* general purpose bit flag 2 bytes */ + uLong compression_method; /* compression method 2 bytes */ + uLong dosDate; /* last mod file date in Dos fmt 4 bytes */ + uLong crc; /* crc-32 4 bytes */ + uLong compressed_size; /* compressed size 4 bytes */ + uLong uncompressed_size; /* uncompressed size 4 bytes */ + uLong size_filename; /* filename length 2 bytes */ + uLong size_file_extra; /* extra field length 2 bytes */ + uLong size_file_comment; /* file comment length 2 bytes */ + + uLong disk_num_start; /* disk number start 2 bytes */ + uLong internal_fa; /* internal file attributes 2 bytes */ + uLong external_fa; /* external file attributes 4 bytes */ + + tm_unz tmu_date; +} unz_file_info; + +extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1, + const char* fileName2, + int iCaseSensitivity)); +/* + Compare two filename (fileName1,fileName2). + If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) + If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi + or strcasecmp) + If iCaseSenisivity = 0, case sensitivity is defaut of your operating system + (like 1 on Unix, 2 on Windows) +*/ + + +extern unzFile ZEXPORT unzOpen OF((const char *path)); +extern unzFile ZEXPORT unzOpen64 OF((const void *path)); +/* + Open a Zip file. path contain the full pathname (by example, + on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer + "zlib/zlib113.zip". + If the zipfile cannot be opened (file don't exist or in not valid), the + return value is NULL. + Else, the return value is a unzFile Handle, usable with other function + of this unzip package. + the "64" function take a const void* pointer, because the path is just the + value passed to the open64_file_func callback. + Under Windows, if UNICODE is defined, using fill_fopen64_filefunc, the path + is a pointer to a wide unicode string (LPCTSTR is LPCWSTR), so const char* + does not describe the reality +*/ + + +extern unzFile ZEXPORT unzOpen2 OF((const char *path, + zlib_filefunc_def* pzlib_filefunc_def)); +/* + Open a Zip file, like unzOpen, but provide a set of file low level API + for read/write the zip file (see ioapi.h) +*/ + +extern unzFile ZEXPORT unzOpen2_64 OF((const void *path, + zlib_filefunc64_def* pzlib_filefunc_def)); +/* + Open a Zip file, like unz64Open, but provide a set of file low level API + for read/write the zip file (see ioapi.h) +*/ + +extern int ZEXPORT unzClose OF((unzFile file)); +/* + Close a ZipFile opened with unzipOpen. + If there is files inside the .Zip opened with unzOpenCurrentFile (see later), + these files MUST be closed with unzipCloseCurrentFile before call unzipClose. + return UNZ_OK if there is no problem. */ + +extern int ZEXPORT unzGetGlobalInfo OF((unzFile file, + unz_global_info *pglobal_info)); + +extern int ZEXPORT unzGetGlobalInfo64 OF((unzFile file, + unz_global_info64 *pglobal_info)); +/* + Write info about the ZipFile in the *pglobal_info structure. + No preparation of the structure is needed + return UNZ_OK if there is no problem. */ + + +extern int ZEXPORT unzGetGlobalComment OF((unzFile file, + char *szComment, + uLong uSizeBuf)); +/* + Get the global comment string of the ZipFile, in the szComment buffer. + uSizeBuf is the size of the szComment buffer. + return the number of byte copied or an error code <0 +*/ + + +/***************************************************************************/ +/* Unzip package allow you browse the directory of the zipfile */ + +extern int ZEXPORT unzGoToFirstFile OF((unzFile file)); +/* + Set the current file of the zipfile to the first file. + return UNZ_OK if there is no problem +*/ + +extern int ZEXPORT unzGoToNextFile OF((unzFile file)); +/* + Set the current file of the zipfile to the next file. + return UNZ_OK if there is no problem + return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. +*/ + +extern int ZEXPORT unzLocateFile OF((unzFile file, + const char *szFileName, + int iCaseSensitivity)); +/* + Try locate the file szFileName in the zipfile. + For the iCaseSensitivity signification, see unzStringFileNameCompare + + return value : + UNZ_OK if the file is found. It becomes the current file. + UNZ_END_OF_LIST_OF_FILE if the file is not found +*/ + + +/* ****************************************** */ +/* Ryan supplied functions */ +/* unz_file_info contain information about a file in the zipfile */ +typedef struct unz_file_pos_s +{ + uLong pos_in_zip_directory; /* offset in zip file directory */ + uLong num_of_file; /* # of file */ +} unz_file_pos; + +extern int ZEXPORT unzGetFilePos( + unzFile file, + unz_file_pos* file_pos); + +extern int ZEXPORT unzGoToFilePos( + unzFile file, + unz_file_pos* file_pos); + +typedef struct unz64_file_pos_s +{ + ZPOS64_T pos_in_zip_directory; /* offset in zip file directory */ + ZPOS64_T num_of_file; /* # of file */ +} unz64_file_pos; + +extern int ZEXPORT unzGetFilePos64( + unzFile file, + unz64_file_pos* file_pos); + +extern int ZEXPORT unzGoToFilePos64( + unzFile file, + const unz64_file_pos* file_pos); + +/* ****************************************** */ + +extern int ZEXPORT unzGetCurrentFileInfo64 OF((unzFile file, + unz_file_info64 *pfile_info, + char *szFileName, + uLong fileNameBufferSize, + void *extraField, + uLong extraFieldBufferSize, + char *szComment, + uLong commentBufferSize)); + +extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file, + unz_file_info *pfile_info, + char *szFileName, + uLong fileNameBufferSize, + void *extraField, + uLong extraFieldBufferSize, + char *szComment, + uLong commentBufferSize)); +/* + Get Info about the current file + if pfile_info!=NULL, the *pfile_info structure will contain somes info about + the current file + if szFileName!=NULL, the filemane string will be copied in szFileName + (fileNameBufferSize is the size of the buffer) + if extraField!=NULL, the extra field information will be copied in extraField + (extraFieldBufferSize is the size of the buffer). + This is the Central-header version of the extra field + if szComment!=NULL, the comment string of the file will be copied in szComment + (commentBufferSize is the size of the buffer) +*/ + + +/** Addition for GDAL : START */ + +extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64 OF((unzFile file)); + +/** Addition for GDAL : END */ + + +/***************************************************************************/ +/* for reading the content of the current zipfile, you can open it, read data + from it, and close it (you can close it before reading all the file) + */ + +extern int ZEXPORT unzOpenCurrentFile OF((unzFile file)); +/* + Open for reading data the current file in the zipfile. + If there is no error, the return value is UNZ_OK. +*/ + +extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file, + const char* password)); +/* + Open for reading data the current file in the zipfile. + password is a crypting password + If there is no error, the return value is UNZ_OK. +*/ + +extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file, + int* method, + int* level, + int raw)); +/* + Same than unzOpenCurrentFile, but open for read raw the file (not uncompress) + if raw==1 + *method will receive method of compression, *level will receive level of + compression + note : you can set level parameter as NULL (if you did not want known level, + but you CANNOT set method parameter as NULL +*/ + +extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file, + int* method, + int* level, + int raw, + const char* password)); +/* + Same than unzOpenCurrentFile, but open for read raw the file (not uncompress) + if raw==1 + *method will receive method of compression, *level will receive level of + compression + note : you can set level parameter as NULL (if you did not want known level, + but you CANNOT set method parameter as NULL +*/ + + +extern int ZEXPORT unzCloseCurrentFile OF((unzFile file)); +/* + Close the file in zip opened with unzOpenCurrentFile + Return UNZ_CRCERROR if all the file was read but the CRC is not good +*/ + +extern int ZEXPORT unzReadCurrentFile OF((unzFile file, + voidp buf, + unsigned len)); +/* + Read bytes from the current file (opened by unzOpenCurrentFile) + buf contain buffer where data must be copied + len the size of buf. + + return the number of byte copied if somes bytes are copied + return 0 if the end of file was reached + return <0 with error code if there is an error + (UNZ_ERRNO for IO error, or zLib error for uncompress error) +*/ + +extern z_off_t ZEXPORT unztell OF((unzFile file)); + +extern ZPOS64_T ZEXPORT unztell64 OF((unzFile file)); +/* + Give the current position in uncompressed data +*/ + +extern int ZEXPORT unzeof OF((unzFile file)); +/* + return 1 if the end of file was reached, 0 elsewhere +*/ + +extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file, + voidp buf, + unsigned len)); +/* + Read extra field from the current file (opened by unzOpenCurrentFile) + This is the local-header version of the extra field (sometimes, there is + more info in the local-header version than in the central-header) + + if buf==NULL, it return the size of the local extra field + + if buf!=NULL, len is the size of the buffer, the extra header is copied in + buf. + the return value is the number of bytes copied in buf, or (if <0) + the error code +*/ + +/***************************************************************************/ + +/* Get the current file offset */ +extern ZPOS64_T ZEXPORT unzGetOffset64 (unzFile file); +extern uLong ZEXPORT unzGetOffset (unzFile file); + +/* Set the current file offset */ +extern int ZEXPORT unzSetOffset64 (unzFile file, ZPOS64_T pos); +extern int ZEXPORT unzSetOffset (unzFile file, uLong pos); + + + +#ifdef __cplusplus +} +#endif + +#endif /* _unz64_H */ diff --git a/libs/zlib/contrib/minizip/zip.c b/libs/zlib/contrib/minizip/zip.c new file mode 100644 index 000000000..3c34fc8bd --- /dev/null +++ b/libs/zlib/contrib/minizip/zip.c @@ -0,0 +1,2004 @@ +/* zip.c -- IO on .zip files using zlib + Version 1.1, February 14h, 2010 + part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) + + Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) + + Modifications for Zip64 support + Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) + + For more info read MiniZip_info.txt + + Changes + Oct-2009 - Mathias Svensson - Remove old C style function prototypes + Oct-2009 - Mathias Svensson - Added Zip64 Support when creating new file archives + Oct-2009 - Mathias Svensson - Did some code cleanup and refactoring to get better overview of some functions. + Oct-2009 - Mathias Svensson - Added zipRemoveExtraInfoBlock to strip extra field data from its ZIP64 data + It is used when recreting zip archive with RAW when deleting items from a zip. + ZIP64 data is automaticly added to items that needs it, and existing ZIP64 data need to be removed. + Oct-2009 - Mathias Svensson - Added support for BZIP2 as compression mode (bzip2 lib is required) + Jan-2010 - back to unzip and minizip 1.0 name scheme, with compatibility layer + +*/ + + +#include +#include +#include +#include +#include "zlib.h" +#include "zip.h" + +#ifdef STDC +# include +# include +# include +#endif +#ifdef NO_ERRNO_H + extern int errno; +#else +# include +#endif + + +#ifndef local +# define local static +#endif +/* compile with -Dlocal if your debugger can't find static symbols */ + +#ifndef VERSIONMADEBY +# define VERSIONMADEBY (0x0) /* platform depedent */ +#endif + +#ifndef Z_BUFSIZE +#define Z_BUFSIZE (64*1024) //(16384) +#endif + +#ifndef Z_MAXFILENAMEINZIP +#define Z_MAXFILENAMEINZIP (256) +#endif + +#ifndef ALLOC +# define ALLOC(size) (malloc(size)) +#endif +#ifndef TRYFREE +# define TRYFREE(p) {if (p) free(p);} +#endif + +/* +#define SIZECENTRALDIRITEM (0x2e) +#define SIZEZIPLOCALHEADER (0x1e) +*/ + +/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */ + + +// NOT sure that this work on ALL platform +#define MAKEULONG64(a, b) ((ZPOS64_T)(((unsigned long)(a)) | ((ZPOS64_T)((unsigned long)(b))) << 32)) + +#ifndef SEEK_CUR +#define SEEK_CUR 1 +#endif + +#ifndef SEEK_END +#define SEEK_END 2 +#endif + +#ifndef SEEK_SET +#define SEEK_SET 0 +#endif + +#ifndef DEF_MEM_LEVEL +#if MAX_MEM_LEVEL >= 8 +# define DEF_MEM_LEVEL 8 +#else +# define DEF_MEM_LEVEL MAX_MEM_LEVEL +#endif +#endif +const char zip_copyright[] =" zip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll"; + + +#define SIZEDATA_INDATABLOCK (4096-(4*4)) + +#define LOCALHEADERMAGIC (0x04034b50) +#define CENTRALHEADERMAGIC (0x02014b50) +#define ENDHEADERMAGIC (0x06054b50) +#define ZIP64ENDHEADERMAGIC (0x6064b50) +#define ZIP64ENDLOCHEADERMAGIC (0x7064b50) + +#define FLAG_LOCALHEADER_OFFSET (0x06) +#define CRC_LOCALHEADER_OFFSET (0x0e) + +#define SIZECENTRALHEADER (0x2e) /* 46 */ + +typedef struct linkedlist_datablock_internal_s +{ + struct linkedlist_datablock_internal_s* next_datablock; + uLong avail_in_this_block; + uLong filled_in_this_block; + uLong unused; /* for future use and alignement */ + unsigned char data[SIZEDATA_INDATABLOCK]; +} linkedlist_datablock_internal; + +typedef struct linkedlist_data_s +{ + linkedlist_datablock_internal* first_block; + linkedlist_datablock_internal* last_block; +} linkedlist_data; + + +typedef struct +{ + z_stream stream; /* zLib stream structure for inflate */ +#ifdef HAVE_BZIP2 + bz_stream bstream; /* bzLib stream structure for bziped */ +#endif + + int stream_initialised; /* 1 is stream is initialised */ + uInt pos_in_buffered_data; /* last written byte in buffered_data */ + + ZPOS64_T pos_local_header; /* offset of the local header of the file + currenty writing */ + char* central_header; /* central header data for the current file */ + uLong size_centralExtra; + uLong size_centralheader; /* size of the central header for cur file */ + uLong size_centralExtraFree; /* Extra bytes allocated to the centralheader but that are not used */ + uLong flag; /* flag of the file currently writing */ + + int method; /* compression method of file currenty wr.*/ + int raw; /* 1 for directly writing raw data */ + Byte buffered_data[Z_BUFSIZE];/* buffer contain compressed data to be writ*/ + uLong dosDate; + uLong crc32; + int encrypt; + int zip64; /* Add ZIP64 extened information in the extra field */ + ZPOS64_T pos_zip64extrainfo; + ZPOS64_T totalCompressedData; + ZPOS64_T totalUncompressedData; +#ifndef NOCRYPT + unsigned long keys[3]; /* keys defining the pseudo-random sequence */ + const unsigned long* pcrc_32_tab; + int crypt_header_size; +#endif +} curfile64_info; + +typedef struct +{ + zlib_filefunc64_32_def z_filefunc; + voidpf filestream; /* io structore of the zipfile */ + linkedlist_data central_dir;/* datablock with central dir in construction*/ + int in_opened_file_inzip; /* 1 if a file in the zip is currently writ.*/ + curfile64_info ci; /* info on the file curretly writing */ + + ZPOS64_T begin_pos; /* position of the beginning of the zipfile */ + ZPOS64_T add_position_when_writting_offset; + ZPOS64_T number_entry; + +#ifndef NO_ADDFILEINEXISTINGZIP + char *globalcomment; +#endif + +} zip64_internal; + + +#ifndef NOCRYPT +#define INCLUDECRYPTINGCODE_IFCRYPTALLOWED +#include "crypt.h" +#endif + +local linkedlist_datablock_internal* allocate_new_datablock() +{ + linkedlist_datablock_internal* ldi; + ldi = (linkedlist_datablock_internal*) + ALLOC(sizeof(linkedlist_datablock_internal)); + if (ldi!=NULL) + { + ldi->next_datablock = NULL ; + ldi->filled_in_this_block = 0 ; + ldi->avail_in_this_block = SIZEDATA_INDATABLOCK ; + } + return ldi; +} + +local void free_datablock(linkedlist_datablock_internal* ldi) +{ + while (ldi!=NULL) + { + linkedlist_datablock_internal* ldinext = ldi->next_datablock; + TRYFREE(ldi); + ldi = ldinext; + } +} + +local void init_linkedlist(linkedlist_data* ll) +{ + ll->first_block = ll->last_block = NULL; +} + +local void free_linkedlist(linkedlist_data* ll) +{ + free_datablock(ll->first_block); + ll->first_block = ll->last_block = NULL; +} + + +local int add_data_in_datablock(linkedlist_data* ll, const void* buf, uLong len) +{ + linkedlist_datablock_internal* ldi; + const unsigned char* from_copy; + + if (ll==NULL) + return ZIP_INTERNALERROR; + + if (ll->last_block == NULL) + { + ll->first_block = ll->last_block = allocate_new_datablock(); + if (ll->first_block == NULL) + return ZIP_INTERNALERROR; + } + + ldi = ll->last_block; + from_copy = (unsigned char*)buf; + + while (len>0) + { + uInt copy_this; + uInt i; + unsigned char* to_copy; + + if (ldi->avail_in_this_block==0) + { + ldi->next_datablock = allocate_new_datablock(); + if (ldi->next_datablock == NULL) + return ZIP_INTERNALERROR; + ldi = ldi->next_datablock ; + ll->last_block = ldi; + } + + if (ldi->avail_in_this_block < len) + copy_this = (uInt)ldi->avail_in_this_block; + else + copy_this = (uInt)len; + + to_copy = &(ldi->data[ldi->filled_in_this_block]); + + for (i=0;ifilled_in_this_block += copy_this; + ldi->avail_in_this_block -= copy_this; + from_copy += copy_this ; + len -= copy_this; + } + return ZIP_OK; +} + + + +/****************************************************************************/ + +#ifndef NO_ADDFILEINEXISTINGZIP +/* =========================================================================== + Inputs a long in LSB order to the given file + nbByte == 1, 2 ,4 or 8 (byte, short or long, ZPOS64_T) +*/ + +local int zip64local_putValue OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T x, int nbByte)); +local int zip64local_putValue (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T x, int nbByte) +{ + unsigned char buf[8]; + int n; + for (n = 0; n < nbByte; n++) + { + buf[n] = (unsigned char)(x & 0xff); + x >>= 8; + } + if (x != 0) + { /* data overflow - hack for ZIP64 (X Roche) */ + for (n = 0; n < nbByte; n++) + { + buf[n] = 0xff; + } + } + + if (ZWRITE64(*pzlib_filefunc_def,filestream,buf,nbByte)!=(uLong)nbByte) + return ZIP_ERRNO; + else + return ZIP_OK; +} + +local void zip64local_putValue_inmemory OF((void* dest, ZPOS64_T x, int nbByte)); +local void zip64local_putValue_inmemory (void* dest, ZPOS64_T x, int nbByte) +{ + unsigned char* buf=(unsigned char*)dest; + int n; + for (n = 0; n < nbByte; n++) { + buf[n] = (unsigned char)(x & 0xff); + x >>= 8; + } + + if (x != 0) + { /* data overflow - hack for ZIP64 */ + for (n = 0; n < nbByte; n++) + { + buf[n] = 0xff; + } + } +} + +/****************************************************************************/ + + +local uLong zip64local_TmzDateToDosDate(const tm_zip* ptm) +{ + uLong year = (uLong)ptm->tm_year; + if (year>=1980) + year-=1980; + else if (year>=80) + year-=80; + return + (uLong) (((ptm->tm_mday) + (32 * (ptm->tm_mon+1)) + (512 * year)) << 16) | + ((ptm->tm_sec/2) + (32* ptm->tm_min) + (2048 * (uLong)ptm->tm_hour)); +} + + +/****************************************************************************/ + +local int zip64local_getByte OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, int *pi)); + +local int zip64local_getByte(const zlib_filefunc64_32_def* pzlib_filefunc_def,voidpf filestream,int* pi) +{ + unsigned char c; + int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,&c,1); + if (err==1) + { + *pi = (int)c; + return ZIP_OK; + } + else + { + if (ZERROR64(*pzlib_filefunc_def,filestream)) + return ZIP_ERRNO; + else + return ZIP_EOF; + } +} + + +/* =========================================================================== + Reads a long in LSB order from the given gz_stream. Sets +*/ +local int zip64local_getShort OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong *pX)); + +local int zip64local_getShort (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong* pX) +{ + uLong x ; + int i = 0; + int err; + + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); + x = (uLong)i; + + if (err==ZIP_OK) + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); + x += ((uLong)i)<<8; + + if (err==ZIP_OK) + *pX = x; + else + *pX = 0; + return err; +} + +local int zip64local_getLong OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong *pX)); + +local int zip64local_getLong (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong* pX) +{ + uLong x ; + int i = 0; + int err; + + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); + x = (uLong)i; + + if (err==ZIP_OK) + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); + x += ((uLong)i)<<8; + + if (err==ZIP_OK) + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); + x += ((uLong)i)<<16; + + if (err==ZIP_OK) + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); + x += ((uLong)i)<<24; + + if (err==ZIP_OK) + *pX = x; + else + *pX = 0; + return err; +} + +local int zip64local_getLong64 OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX)); + + +local int zip64local_getLong64 (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX) +{ + ZPOS64_T x; + int i = 0; + int err; + + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); + x = (ZPOS64_T)i; + + if (err==ZIP_OK) + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); + x += ((ZPOS64_T)i)<<8; + + if (err==ZIP_OK) + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); + x += ((ZPOS64_T)i)<<16; + + if (err==ZIP_OK) + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); + x += ((ZPOS64_T)i)<<24; + + if (err==ZIP_OK) + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); + x += ((ZPOS64_T)i)<<32; + + if (err==ZIP_OK) + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); + x += ((ZPOS64_T)i)<<40; + + if (err==ZIP_OK) + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); + x += ((ZPOS64_T)i)<<48; + + if (err==ZIP_OK) + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); + x += ((ZPOS64_T)i)<<56; + + if (err==ZIP_OK) + *pX = x; + else + *pX = 0; + + return err; +} + +#ifndef BUFREADCOMMENT +#define BUFREADCOMMENT (0x400) +#endif +/* + Locate the Central directory of a zipfile (at the end, just before + the global comment) +*/ +local ZPOS64_T zip64local_SearchCentralDir OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)); + +local ZPOS64_T zip64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream) +{ + unsigned char* buf; + ZPOS64_T uSizeFile; + ZPOS64_T uBackRead; + ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */ + ZPOS64_T uPosFound=0; + + if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0) + return 0; + + + uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream); + + if (uMaxBack>uSizeFile) + uMaxBack = uSizeFile; + + buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); + if (buf==NULL) + return 0; + + uBackRead = 4; + while (uBackReaduMaxBack) + uBackRead = uMaxBack; + else + uBackRead+=BUFREADCOMMENT; + uReadPos = uSizeFile-uBackRead ; + + uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? + (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos); + if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0) + break; + + if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize) + break; + + for (i=(int)uReadSize-3; (i--)>0;) + if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && + ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06)) + { + uPosFound = uReadPos+i; + break; + } + + if (uPosFound!=0) + break; + } + TRYFREE(buf); + return uPosFound; +} + +/* +Locate the End of Zip64 Central directory locator and from there find the CD of a zipfile (at the end, just before +the global comment) +*/ +local ZPOS64_T zip64local_SearchCentralDir64 OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)); + +local ZPOS64_T zip64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream) +{ + unsigned char* buf; + ZPOS64_T uSizeFile; + ZPOS64_T uBackRead; + ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */ + ZPOS64_T uPosFound=0; + uLong uL; + ZPOS64_T relativeOffset; + + if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0) + return 0; + + uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream); + + if (uMaxBack>uSizeFile) + uMaxBack = uSizeFile; + + buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); + if (buf==NULL) + return 0; + + uBackRead = 4; + while (uBackReaduMaxBack) + uBackRead = uMaxBack; + else + uBackRead+=BUFREADCOMMENT; + uReadPos = uSizeFile-uBackRead ; + + uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? + (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos); + if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0) + break; + + if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize) + break; + + for (i=(int)uReadSize-3; (i--)>0;) + { + // Signature "0x07064b50" Zip64 end of central directory locater + if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && ((*(buf+i+2))==0x06) && ((*(buf+i+3))==0x07)) + { + uPosFound = uReadPos+i; + break; + } + } + + if (uPosFound!=0) + break; + } + + TRYFREE(buf); + if (uPosFound == 0) + return 0; + + /* Zip64 end of central directory locator */ + if (ZSEEK64(*pzlib_filefunc_def,filestream, uPosFound,ZLIB_FILEFUNC_SEEK_SET)!=0) + return 0; + + /* the signature, already checked */ + if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK) + return 0; + + /* number of the disk with the start of the zip64 end of central directory */ + if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK) + return 0; + if (uL != 0) + return 0; + + /* relative offset of the zip64 end of central directory record */ + if (zip64local_getLong64(pzlib_filefunc_def,filestream,&relativeOffset)!=ZIP_OK) + return 0; + + /* total number of disks */ + if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK) + return 0; + if (uL != 1) + return 0; + + /* Goto Zip64 end of central directory record */ + if (ZSEEK64(*pzlib_filefunc_def,filestream, relativeOffset,ZLIB_FILEFUNC_SEEK_SET)!=0) + return 0; + + /* the signature */ + if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK) + return 0; + + if (uL != 0x06064b50) // signature of 'Zip64 end of central directory' + return 0; + + return relativeOffset; +} + +int LoadCentralDirectoryRecord(zip64_internal* pziinit) +{ + int err=ZIP_OK; + ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ + + ZPOS64_T size_central_dir; /* size of the central directory */ + ZPOS64_T offset_central_dir; /* offset of start of central directory */ + ZPOS64_T central_pos; + uLong uL; + + uLong number_disk; /* number of the current dist, used for + spaning ZIP, unsupported, always 0*/ + uLong number_disk_with_CD; /* number the the disk with central dir, used + for spaning ZIP, unsupported, always 0*/ + ZPOS64_T number_entry; + ZPOS64_T number_entry_CD; /* total number of entries in + the central dir + (same than number_entry on nospan) */ + uLong VersionMadeBy; + uLong VersionNeeded; + uLong size_comment; + + int hasZIP64Record = 0; + + // check first if we find a ZIP64 record + central_pos = zip64local_SearchCentralDir64(&pziinit->z_filefunc,pziinit->filestream); + if(central_pos > 0) + { + hasZIP64Record = 1; + } + else if(central_pos == 0) + { + central_pos = zip64local_SearchCentralDir(&pziinit->z_filefunc,pziinit->filestream); + } + +/* disable to allow appending to empty ZIP archive + if (central_pos==0) + err=ZIP_ERRNO; +*/ + + if(hasZIP64Record) + { + ZPOS64_T sizeEndOfCentralDirectory; + if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, central_pos, ZLIB_FILEFUNC_SEEK_SET) != 0) + err=ZIP_ERRNO; + + /* the signature, already checked */ + if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&uL)!=ZIP_OK) + err=ZIP_ERRNO; + + /* size of zip64 end of central directory record */ + if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream, &sizeEndOfCentralDirectory)!=ZIP_OK) + err=ZIP_ERRNO; + + /* version made by */ + if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &VersionMadeBy)!=ZIP_OK) + err=ZIP_ERRNO; + + /* version needed to extract */ + if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &VersionNeeded)!=ZIP_OK) + err=ZIP_ERRNO; + + /* number of this disk */ + if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&number_disk)!=ZIP_OK) + err=ZIP_ERRNO; + + /* number of the disk with the start of the central directory */ + if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&number_disk_with_CD)!=ZIP_OK) + err=ZIP_ERRNO; + + /* total number of entries in the central directory on this disk */ + if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream, &number_entry)!=ZIP_OK) + err=ZIP_ERRNO; + + /* total number of entries in the central directory */ + if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream,&number_entry_CD)!=ZIP_OK) + err=ZIP_ERRNO; + + if ((number_entry_CD!=number_entry) || (number_disk_with_CD!=0) || (number_disk!=0)) + err=ZIP_BADZIPFILE; + + /* size of the central directory */ + if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream,&size_central_dir)!=ZIP_OK) + err=ZIP_ERRNO; + + /* offset of start of central directory with respect to the + starting disk number */ + if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream,&offset_central_dir)!=ZIP_OK) + err=ZIP_ERRNO; + + // TODO.. + // read the comment from the standard central header. + size_comment = 0; + } + else + { + // Read End of central Directory info + if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0) + err=ZIP_ERRNO; + + /* the signature, already checked */ + if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&uL)!=ZIP_OK) + err=ZIP_ERRNO; + + /* number of this disk */ + if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream,&number_disk)!=ZIP_OK) + err=ZIP_ERRNO; + + /* number of the disk with the start of the central directory */ + if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream,&number_disk_with_CD)!=ZIP_OK) + err=ZIP_ERRNO; + + /* total number of entries in the central dir on this disk */ + number_entry = 0; + if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK) + err=ZIP_ERRNO; + else + number_entry = uL; + + /* total number of entries in the central dir */ + number_entry_CD = 0; + if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK) + err=ZIP_ERRNO; + else + number_entry_CD = uL; + + if ((number_entry_CD!=number_entry) || (number_disk_with_CD!=0) || (number_disk!=0)) + err=ZIP_BADZIPFILE; + + /* size of the central directory */ + size_central_dir = 0; + if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK) + err=ZIP_ERRNO; + else + size_central_dir = uL; + + /* offset of start of central directory with respect to the starting disk number */ + offset_central_dir = 0; + if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK) + err=ZIP_ERRNO; + else + offset_central_dir = uL; + + + /* zipfile global comment length */ + if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &size_comment)!=ZIP_OK) + err=ZIP_ERRNO; + } + + if ((central_posz_filefunc, pziinit->filestream); + return ZIP_ERRNO; + } + + if (size_comment>0) + { + pziinit->globalcomment = (char*)ALLOC(size_comment+1); + if (pziinit->globalcomment) + { + size_comment = ZREAD64(pziinit->z_filefunc, pziinit->filestream, pziinit->globalcomment,size_comment); + pziinit->globalcomment[size_comment]=0; + } + } + + byte_before_the_zipfile = central_pos - (offset_central_dir+size_central_dir); + pziinit->add_position_when_writting_offset = byte_before_the_zipfile; + + { + ZPOS64_T size_central_dir_to_read = size_central_dir; + size_t buf_size = SIZEDATA_INDATABLOCK; + void* buf_read = (void*)ALLOC(buf_size); + if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, offset_central_dir + byte_before_the_zipfile, ZLIB_FILEFUNC_SEEK_SET) != 0) + err=ZIP_ERRNO; + + while ((size_central_dir_to_read>0) && (err==ZIP_OK)) + { + ZPOS64_T read_this = SIZEDATA_INDATABLOCK; + if (read_this > size_central_dir_to_read) + read_this = size_central_dir_to_read; + + if (ZREAD64(pziinit->z_filefunc, pziinit->filestream,buf_read,(uLong)read_this) != read_this) + err=ZIP_ERRNO; + + if (err==ZIP_OK) + err = add_data_in_datablock(&pziinit->central_dir,buf_read, (uLong)read_this); + + size_central_dir_to_read-=read_this; + } + TRYFREE(buf_read); + } + pziinit->begin_pos = byte_before_the_zipfile; + pziinit->number_entry = number_entry_CD; + + if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, offset_central_dir+byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET) != 0) + err=ZIP_ERRNO; + + return err; +} + + +#endif /* !NO_ADDFILEINEXISTINGZIP*/ + + +/************************************************************/ +extern zipFile ZEXPORT zipOpen3 (const void *pathname, int append, zipcharpc* globalcomment, zlib_filefunc64_32_def* pzlib_filefunc64_32_def) +{ + zip64_internal ziinit; + zip64_internal* zi; + int err=ZIP_OK; + + ziinit.z_filefunc.zseek32_file = NULL; + ziinit.z_filefunc.ztell32_file = NULL; + if (pzlib_filefunc64_32_def==NULL) + fill_fopen64_filefunc(&ziinit.z_filefunc.zfile_func64); + else + ziinit.z_filefunc = *pzlib_filefunc64_32_def; + + ziinit.filestream = ZOPEN64(ziinit.z_filefunc, + pathname, + (append == APPEND_STATUS_CREATE) ? + (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_CREATE) : + (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_EXISTING)); + + if (ziinit.filestream == NULL) + return NULL; + + if (append == APPEND_STATUS_CREATEAFTER) + ZSEEK64(ziinit.z_filefunc,ziinit.filestream,0,SEEK_END); + + ziinit.begin_pos = ZTELL64(ziinit.z_filefunc,ziinit.filestream); + ziinit.in_opened_file_inzip = 0; + ziinit.ci.stream_initialised = 0; + ziinit.number_entry = 0; + ziinit.add_position_when_writting_offset = 0; + init_linkedlist(&(ziinit.central_dir)); + + + + zi = (zip64_internal*)ALLOC(sizeof(zip64_internal)); + if (zi==NULL) + { + ZCLOSE64(ziinit.z_filefunc,ziinit.filestream); + return NULL; + } + + /* now we add file in a zipfile */ +# ifndef NO_ADDFILEINEXISTINGZIP + ziinit.globalcomment = NULL; + if (append == APPEND_STATUS_ADDINZIP) + { + // Read and Cache Central Directory Records + err = LoadCentralDirectoryRecord(&ziinit); + } + + if (globalcomment) + { + *globalcomment = ziinit.globalcomment; + } +# endif /* !NO_ADDFILEINEXISTINGZIP*/ + + if (err != ZIP_OK) + { +# ifndef NO_ADDFILEINEXISTINGZIP + TRYFREE(ziinit.globalcomment); +# endif /* !NO_ADDFILEINEXISTINGZIP*/ + TRYFREE(zi); + return NULL; + } + else + { + *zi = ziinit; + return (zipFile)zi; + } +} + +extern zipFile ZEXPORT zipOpen2 (const char *pathname, int append, zipcharpc* globalcomment, zlib_filefunc_def* pzlib_filefunc32_def) +{ + if (pzlib_filefunc32_def != NULL) + { + zlib_filefunc64_32_def zlib_filefunc64_32_def_fill; + fill_zlib_filefunc64_32_def_from_filefunc32(&zlib_filefunc64_32_def_fill,pzlib_filefunc32_def); + return zipOpen3(pathname, append, globalcomment, &zlib_filefunc64_32_def_fill); + } + else + return zipOpen3(pathname, append, globalcomment, NULL); +} + +extern zipFile ZEXPORT zipOpen2_64 (const void *pathname, int append, zipcharpc* globalcomment, zlib_filefunc64_def* pzlib_filefunc_def) +{ + if (pzlib_filefunc_def != NULL) + { + zlib_filefunc64_32_def zlib_filefunc64_32_def_fill; + zlib_filefunc64_32_def_fill.zfile_func64 = *pzlib_filefunc_def; + zlib_filefunc64_32_def_fill.ztell32_file = NULL; + zlib_filefunc64_32_def_fill.zseek32_file = NULL; + return zipOpen3(pathname, append, globalcomment, &zlib_filefunc64_32_def_fill); + } + else + return zipOpen3(pathname, append, globalcomment, NULL); +} + + + +extern zipFile ZEXPORT zipOpen (const char* pathname, int append) +{ + return zipOpen3((const void*)pathname,append,NULL,NULL); +} + +extern zipFile ZEXPORT zipOpen64 (const void* pathname, int append) +{ + return zipOpen3(pathname,append,NULL,NULL); +} + +int Write_LocalFileHeader(zip64_internal* zi, const char* filename, uInt size_extrafield_local, const void* extrafield_local) +{ + /* write the local header */ + int err; + uInt size_filename = (uInt)strlen(filename); + uInt size_extrafield = size_extrafield_local; + + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)LOCALHEADERMAGIC, 4); + + if (err==ZIP_OK) + { + if(zi->ci.zip64) + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)45,2);/* version needed to extract */ + else + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)20,2);/* version needed to extract */ + } + + if (err==ZIP_OK) + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.flag,2); + + if (err==ZIP_OK) + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.method,2); + + if (err==ZIP_OK) + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.dosDate,4); + + // CRC / Compressed size / Uncompressed size will be filled in later and rewritten later + if (err==ZIP_OK) + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* crc 32, unknown */ + if (err==ZIP_OK) + { + if(zi->ci.zip64) + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xFFFFFFFF,4); /* compressed size, unknown */ + else + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* compressed size, unknown */ + } + if (err==ZIP_OK) + { + if(zi->ci.zip64) + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xFFFFFFFF,4); /* uncompressed size, unknown */ + else + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* uncompressed size, unknown */ + } + + if (err==ZIP_OK) + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_filename,2); + + if(zi->ci.zip64) + { + size_extrafield += 20; + } + + if (err==ZIP_OK) + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_extrafield,2); + + if ((err==ZIP_OK) && (size_filename > 0)) + { + if (ZWRITE64(zi->z_filefunc,zi->filestream,filename,size_filename)!=size_filename) + err = ZIP_ERRNO; + } + + if ((err==ZIP_OK) && (size_extrafield_local > 0)) + { + if (ZWRITE64(zi->z_filefunc, zi->filestream, extrafield_local, size_extrafield_local) != size_extrafield_local) + err = ZIP_ERRNO; + } + + + if ((err==ZIP_OK) && (zi->ci.zip64)) + { + // write the Zip64 extended info + short HeaderID = 1; + short DataSize = 16; + ZPOS64_T CompressedSize = 0; + ZPOS64_T UncompressedSize = 0; + + // Remember position of Zip64 extended info for the local file header. (needed when we update size after done with file) + zi->ci.pos_zip64extrainfo = ZTELL64(zi->z_filefunc,zi->filestream); + + err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (short)HeaderID,2); + err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (short)DataSize,2); + + err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (ZPOS64_T)UncompressedSize,8); + err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (ZPOS64_T)CompressedSize,8); + } + + return err; +} + +/* + NOTE. + When writing RAW the ZIP64 extended information in extrafield_local and extrafield_global needs to be stripped + before calling this function it can be done with zipRemoveExtraInfoBlock + + It is not done here because then we need to realloc a new buffer since parameters are 'const' and I want to minimize + unnecessary allocations. + */ +extern int ZEXPORT zipOpenNewFileInZip4_64 (zipFile file, const char* filename, const zip_fileinfo* zipfi, + const void* extrafield_local, uInt size_extrafield_local, + const void* extrafield_global, uInt size_extrafield_global, + const char* comment, int method, int level, int raw, + int windowBits,int memLevel, int strategy, + const char* password, uLong crcForCrypting, + uLong versionMadeBy, uLong flagBase, int zip64) +{ + zip64_internal* zi; + uInt size_filename; + uInt size_comment; + uInt i; + int err = ZIP_OK; + +# ifdef NOCRYPT + if (password != NULL) + return ZIP_PARAMERROR; +# endif + + if (file == NULL) + return ZIP_PARAMERROR; + +#ifdef HAVE_BZIP2 + if ((method!=0) && (method!=Z_DEFLATED) && (method!=Z_BZIP2ED)) + return ZIP_PARAMERROR; +#else + if ((method!=0) && (method!=Z_DEFLATED)) + return ZIP_PARAMERROR; +#endif + + zi = (zip64_internal*)file; + + if (zi->in_opened_file_inzip == 1) + { + err = zipCloseFileInZip (file); + if (err != ZIP_OK) + return err; + } + + if (filename==NULL) + filename="-"; + + if (comment==NULL) + size_comment = 0; + else + size_comment = (uInt)strlen(comment); + + size_filename = (uInt)strlen(filename); + + if (zipfi == NULL) + zi->ci.dosDate = 0; + else + { + if (zipfi->dosDate != 0) + zi->ci.dosDate = zipfi->dosDate; + else + zi->ci.dosDate = zip64local_TmzDateToDosDate(&zipfi->tmz_date); + } + + zi->ci.flag = flagBase; + if ((level==8) || (level==9)) + zi->ci.flag |= 2; + if ((level==2)) + zi->ci.flag |= 4; + if ((level==1)) + zi->ci.flag |= 6; + if (password != NULL) + zi->ci.flag |= 1; + + zi->ci.crc32 = 0; + zi->ci.method = method; + zi->ci.encrypt = 0; + zi->ci.stream_initialised = 0; + zi->ci.pos_in_buffered_data = 0; + zi->ci.raw = raw; + zi->ci.pos_local_header = ZTELL64(zi->z_filefunc,zi->filestream); + + zi->ci.size_centralheader = SIZECENTRALHEADER + size_filename + size_extrafield_global + size_comment; + zi->ci.size_centralExtraFree = 32; // Extra space we have reserved in case we need to add ZIP64 extra info data + + zi->ci.central_header = (char*)ALLOC((uInt)zi->ci.size_centralheader + zi->ci.size_centralExtraFree); + + zi->ci.size_centralExtra = size_extrafield_global; + zip64local_putValue_inmemory(zi->ci.central_header,(uLong)CENTRALHEADERMAGIC,4); + /* version info */ + zip64local_putValue_inmemory(zi->ci.central_header+4,(uLong)versionMadeBy,2); + zip64local_putValue_inmemory(zi->ci.central_header+6,(uLong)20,2); + zip64local_putValue_inmemory(zi->ci.central_header+8,(uLong)zi->ci.flag,2); + zip64local_putValue_inmemory(zi->ci.central_header+10,(uLong)zi->ci.method,2); + zip64local_putValue_inmemory(zi->ci.central_header+12,(uLong)zi->ci.dosDate,4); + zip64local_putValue_inmemory(zi->ci.central_header+16,(uLong)0,4); /*crc*/ + zip64local_putValue_inmemory(zi->ci.central_header+20,(uLong)0,4); /*compr size*/ + zip64local_putValue_inmemory(zi->ci.central_header+24,(uLong)0,4); /*uncompr size*/ + zip64local_putValue_inmemory(zi->ci.central_header+28,(uLong)size_filename,2); + zip64local_putValue_inmemory(zi->ci.central_header+30,(uLong)size_extrafield_global,2); + zip64local_putValue_inmemory(zi->ci.central_header+32,(uLong)size_comment,2); + zip64local_putValue_inmemory(zi->ci.central_header+34,(uLong)0,2); /*disk nm start*/ + + if (zipfi==NULL) + zip64local_putValue_inmemory(zi->ci.central_header+36,(uLong)0,2); + else + zip64local_putValue_inmemory(zi->ci.central_header+36,(uLong)zipfi->internal_fa,2); + + if (zipfi==NULL) + zip64local_putValue_inmemory(zi->ci.central_header+38,(uLong)0,4); + else + zip64local_putValue_inmemory(zi->ci.central_header+38,(uLong)zipfi->external_fa,4); + + if(zi->ci.pos_local_header >= 0xffffffff) + zip64local_putValue_inmemory(zi->ci.central_header+42,(uLong)0xffffffff,4); + else + zip64local_putValue_inmemory(zi->ci.central_header+42,(uLong)zi->ci.pos_local_header - zi->add_position_when_writting_offset,4); + + for (i=0;ici.central_header+SIZECENTRALHEADER+i) = *(filename+i); + + for (i=0;ici.central_header+SIZECENTRALHEADER+size_filename+i) = + *(((const char*)extrafield_global)+i); + + for (i=0;ici.central_header+SIZECENTRALHEADER+size_filename+ + size_extrafield_global+i) = *(comment+i); + if (zi->ci.central_header == NULL) + return ZIP_INTERNALERROR; + + zi->ci.zip64 = zip64; + zi->ci.totalCompressedData = 0; + zi->ci.totalUncompressedData = 0; + zi->ci.pos_zip64extrainfo = 0; + + err = Write_LocalFileHeader(zi, filename, size_extrafield_local, extrafield_local); + +#ifdef HAVE_BZIP2 + zi->ci.bstream.avail_in = (uInt)0; + zi->ci.bstream.avail_out = (uInt)Z_BUFSIZE; + zi->ci.bstream.next_out = (char*)zi->ci.buffered_data; + zi->ci.bstream.total_in_hi32 = 0; + zi->ci.bstream.total_in_lo32 = 0; + zi->ci.bstream.total_out_hi32 = 0; + zi->ci.bstream.total_out_lo32 = 0; +#endif + + zi->ci.stream.avail_in = (uInt)0; + zi->ci.stream.avail_out = (uInt)Z_BUFSIZE; + zi->ci.stream.next_out = zi->ci.buffered_data; + zi->ci.stream.total_in = 0; + zi->ci.stream.total_out = 0; + zi->ci.stream.data_type = Z_BINARY; + +#ifdef HAVE_BZIP2 + if ((err==ZIP_OK) && (zi->ci.method == Z_DEFLATED || zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw)) +#else + if ((err==ZIP_OK) && (zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) +#endif + { + if(zi->ci.method == Z_DEFLATED) + { + zi->ci.stream.zalloc = (alloc_func)0; + zi->ci.stream.zfree = (free_func)0; + zi->ci.stream.opaque = (voidpf)0; + + if (windowBits>0) + windowBits = -windowBits; + + err = deflateInit2(&zi->ci.stream, level, Z_DEFLATED, windowBits, memLevel, strategy); + + if (err==Z_OK) + zi->ci.stream_initialised = Z_DEFLATED; + } + else if(zi->ci.method == Z_BZIP2ED) + { +#ifdef HAVE_BZIP2 + // Init BZip stuff here + zi->ci.bstream.bzalloc = 0; + zi->ci.bstream.bzfree = 0; + zi->ci.bstream.opaque = (voidpf)0; + + err = BZ2_bzCompressInit(&zi->ci.bstream, level, 0,35); + if(err == BZ_OK) + zi->ci.stream_initialised = Z_BZIP2ED; +#endif + } + + } + +# ifndef NOCRYPT + zi->ci.crypt_header_size = 0; + if ((err==Z_OK) && (password != NULL)) + { + unsigned char bufHead[RAND_HEAD_LEN]; + unsigned int sizeHead; + zi->ci.encrypt = 1; + zi->ci.pcrc_32_tab = get_crc_table(); + /*init_keys(password,zi->ci.keys,zi->ci.pcrc_32_tab);*/ + + sizeHead=crypthead(password,bufHead,RAND_HEAD_LEN,zi->ci.keys,zi->ci.pcrc_32_tab,crcForCrypting); + zi->ci.crypt_header_size = sizeHead; + + if (ZWRITE64(zi->z_filefunc,zi->filestream,bufHead,sizeHead) != sizeHead) + err = ZIP_ERRNO; + } +# endif + + if (err==Z_OK) + zi->in_opened_file_inzip = 1; + return err; +} + +extern int ZEXPORT zipOpenNewFileInZip4 (zipFile file, const char* filename, const zip_fileinfo* zipfi, + const void* extrafield_local, uInt size_extrafield_local, + const void* extrafield_global, uInt size_extrafield_global, + const char* comment, int method, int level, int raw, + int windowBits,int memLevel, int strategy, + const char* password, uLong crcForCrypting, + uLong versionMadeBy, uLong flagBase) +{ + return zipOpenNewFileInZip4_64 (file, filename, zipfi, + extrafield_local, size_extrafield_local, + extrafield_global, size_extrafield_global, + comment, method, level, raw, + windowBits, memLevel, strategy, + password, crcForCrypting, versionMadeBy, flagBase, 0); +} + +extern int ZEXPORT zipOpenNewFileInZip3 (zipFile file, const char* filename, const zip_fileinfo* zipfi, + const void* extrafield_local, uInt size_extrafield_local, + const void* extrafield_global, uInt size_extrafield_global, + const char* comment, int method, int level, int raw, + int windowBits,int memLevel, int strategy, + const char* password, uLong crcForCrypting) +{ + return zipOpenNewFileInZip4_64 (file, filename, zipfi, + extrafield_local, size_extrafield_local, + extrafield_global, size_extrafield_global, + comment, method, level, raw, + windowBits, memLevel, strategy, + password, crcForCrypting, VERSIONMADEBY, 0, 0); +} + +extern int ZEXPORT zipOpenNewFileInZip3_64(zipFile file, const char* filename, const zip_fileinfo* zipfi, + const void* extrafield_local, uInt size_extrafield_local, + const void* extrafield_global, uInt size_extrafield_global, + const char* comment, int method, int level, int raw, + int windowBits,int memLevel, int strategy, + const char* password, uLong crcForCrypting, int zip64) +{ + return zipOpenNewFileInZip4_64 (file, filename, zipfi, + extrafield_local, size_extrafield_local, + extrafield_global, size_extrafield_global, + comment, method, level, raw, + windowBits, memLevel, strategy, + password, crcForCrypting, VERSIONMADEBY, 0, zip64); +} + +extern int ZEXPORT zipOpenNewFileInZip2(zipFile file, const char* filename, const zip_fileinfo* zipfi, + const void* extrafield_local, uInt size_extrafield_local, + const void* extrafield_global, uInt size_extrafield_global, + const char* comment, int method, int level, int raw) +{ + return zipOpenNewFileInZip4_64 (file, filename, zipfi, + extrafield_local, size_extrafield_local, + extrafield_global, size_extrafield_global, + comment, method, level, raw, + -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, + NULL, 0, VERSIONMADEBY, 0, 0); +} + +extern int ZEXPORT zipOpenNewFileInZip2_64(zipFile file, const char* filename, const zip_fileinfo* zipfi, + const void* extrafield_local, uInt size_extrafield_local, + const void* extrafield_global, uInt size_extrafield_global, + const char* comment, int method, int level, int raw, int zip64) +{ + return zipOpenNewFileInZip4_64 (file, filename, zipfi, + extrafield_local, size_extrafield_local, + extrafield_global, size_extrafield_global, + comment, method, level, raw, + -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, + NULL, 0, VERSIONMADEBY, 0, zip64); +} + +extern int ZEXPORT zipOpenNewFileInZip64 (zipFile file, const char* filename, const zip_fileinfo* zipfi, + const void* extrafield_local, uInt size_extrafield_local, + const void*extrafield_global, uInt size_extrafield_global, + const char* comment, int method, int level, int zip64) +{ + return zipOpenNewFileInZip4_64 (file, filename, zipfi, + extrafield_local, size_extrafield_local, + extrafield_global, size_extrafield_global, + comment, method, level, 0, + -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, + NULL, 0, VERSIONMADEBY, 0, zip64); +} + +extern int ZEXPORT zipOpenNewFileInZip (zipFile file, const char* filename, const zip_fileinfo* zipfi, + const void* extrafield_local, uInt size_extrafield_local, + const void*extrafield_global, uInt size_extrafield_global, + const char* comment, int method, int level) +{ + return zipOpenNewFileInZip4_64 (file, filename, zipfi, + extrafield_local, size_extrafield_local, + extrafield_global, size_extrafield_global, + comment, method, level, 0, + -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, + NULL, 0, VERSIONMADEBY, 0, 0); +} + +local int zip64FlushWriteBuffer(zip64_internal* zi) +{ + int err=ZIP_OK; + + if (zi->ci.encrypt != 0) + { +#ifndef NOCRYPT + uInt i; + int t; + for (i=0;ici.pos_in_buffered_data;i++) + zi->ci.buffered_data[i] = zencode(zi->ci.keys, zi->ci.pcrc_32_tab, zi->ci.buffered_data[i],t); +#endif + } + + if (ZWRITE64(zi->z_filefunc,zi->filestream,zi->ci.buffered_data,zi->ci.pos_in_buffered_data) != zi->ci.pos_in_buffered_data) + err = ZIP_ERRNO; + + zi->ci.totalCompressedData += zi->ci.pos_in_buffered_data; + +#ifdef HAVE_BZIP2 + if(zi->ci.method == Z_BZIP2ED) + { + zi->ci.totalUncompressedData += zi->ci.bstream.total_in_lo32; + zi->ci.bstream.total_in_lo32 = 0; + zi->ci.bstream.total_in_hi32 = 0; + } + else +#endif + { + zi->ci.totalUncompressedData += zi->ci.stream.total_in; + zi->ci.stream.total_in = 0; + } + + + zi->ci.pos_in_buffered_data = 0; + + return err; +} + +extern int ZEXPORT zipWriteInFileInZip (zipFile file,const void* buf,unsigned int len) +{ + zip64_internal* zi; + int err=ZIP_OK; + + if (file == NULL) + return ZIP_PARAMERROR; + zi = (zip64_internal*)file; + + if (zi->in_opened_file_inzip == 0) + return ZIP_PARAMERROR; + + zi->ci.crc32 = crc32(zi->ci.crc32,buf,(uInt)len); + +#ifdef HAVE_BZIP2 + if(zi->ci.method == Z_BZIP2ED && (!zi->ci.raw)) + { + zi->ci.bstream.next_in = (void*)buf; + zi->ci.bstream.avail_in = len; + err = BZ_RUN_OK; + + while ((err==BZ_RUN_OK) && (zi->ci.bstream.avail_in>0)) + { + if (zi->ci.bstream.avail_out == 0) + { + if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO) + err = ZIP_ERRNO; + zi->ci.bstream.avail_out = (uInt)Z_BUFSIZE; + zi->ci.bstream.next_out = (char*)zi->ci.buffered_data; + } + + + if(err != BZ_RUN_OK) + break; + + if ((zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw)) + { + uLong uTotalOutBefore_lo = zi->ci.bstream.total_out_lo32; +// uLong uTotalOutBefore_hi = zi->ci.bstream.total_out_hi32; + err=BZ2_bzCompress(&zi->ci.bstream, BZ_RUN); + + zi->ci.pos_in_buffered_data += (uInt)(zi->ci.bstream.total_out_lo32 - uTotalOutBefore_lo) ; + } + } + + if(err == BZ_RUN_OK) + err = ZIP_OK; + } + else +#endif + { + zi->ci.stream.next_in = (Bytef*)buf; + zi->ci.stream.avail_in = len; + + while ((err==ZIP_OK) && (zi->ci.stream.avail_in>0)) + { + if (zi->ci.stream.avail_out == 0) + { + if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO) + err = ZIP_ERRNO; + zi->ci.stream.avail_out = (uInt)Z_BUFSIZE; + zi->ci.stream.next_out = zi->ci.buffered_data; + } + + + if(err != ZIP_OK) + break; + + if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) + { + uLong uTotalOutBefore = zi->ci.stream.total_out; + err=deflate(&zi->ci.stream, Z_NO_FLUSH); + if(uTotalOutBefore > zi->ci.stream.total_out) + { + int bBreak = 0; + bBreak++; + } + + zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ; + } + else + { + uInt copy_this,i; + if (zi->ci.stream.avail_in < zi->ci.stream.avail_out) + copy_this = zi->ci.stream.avail_in; + else + copy_this = zi->ci.stream.avail_out; + + for (i = 0; i < copy_this; i++) + *(((char*)zi->ci.stream.next_out)+i) = + *(((const char*)zi->ci.stream.next_in)+i); + { + zi->ci.stream.avail_in -= copy_this; + zi->ci.stream.avail_out-= copy_this; + zi->ci.stream.next_in+= copy_this; + zi->ci.stream.next_out+= copy_this; + zi->ci.stream.total_in+= copy_this; + zi->ci.stream.total_out+= copy_this; + zi->ci.pos_in_buffered_data += copy_this; + } + } + }// while(...) + } + + return err; +} + +extern int ZEXPORT zipCloseFileInZipRaw (zipFile file, uLong uncompressed_size, uLong crc32) +{ + return zipCloseFileInZipRaw64 (file, uncompressed_size, crc32); +} + +extern int ZEXPORT zipCloseFileInZipRaw64 (zipFile file, ZPOS64_T uncompressed_size, uLong crc32) +{ + zip64_internal* zi; + ZPOS64_T compressed_size; + uLong invalidValue = 0xffffffff; + short datasize = 0; + int err=ZIP_OK; + + if (file == NULL) + return ZIP_PARAMERROR; + zi = (zip64_internal*)file; + + if (zi->in_opened_file_inzip == 0) + return ZIP_PARAMERROR; + zi->ci.stream.avail_in = 0; + + if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) + { + while (err==ZIP_OK) + { + uLong uTotalOutBefore; + if (zi->ci.stream.avail_out == 0) + { + if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO) + err = ZIP_ERRNO; + zi->ci.stream.avail_out = (uInt)Z_BUFSIZE; + zi->ci.stream.next_out = zi->ci.buffered_data; + } + uTotalOutBefore = zi->ci.stream.total_out; + err=deflate(&zi->ci.stream, Z_FINISH); + zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ; + } + } + else if ((zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw)) + { +#ifdef HAVE_BZIP2 + err = BZ_FINISH_OK; + while (err==BZ_FINISH_OK) + { + uLong uTotalOutBefore; + if (zi->ci.bstream.avail_out == 0) + { + if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO) + err = ZIP_ERRNO; + zi->ci.bstream.avail_out = (uInt)Z_BUFSIZE; + zi->ci.bstream.next_out = (char*)zi->ci.buffered_data; + } + uTotalOutBefore = zi->ci.bstream.total_out_lo32; + err=BZ2_bzCompress(&zi->ci.bstream, BZ_FINISH); + if(err == BZ_STREAM_END) + err = Z_STREAM_END; + + zi->ci.pos_in_buffered_data += (uInt)(zi->ci.bstream.total_out_lo32 - uTotalOutBefore); + } + + if(err == BZ_FINISH_OK) + err = ZIP_OK; +#endif + } + + if (err==Z_STREAM_END) + err=ZIP_OK; /* this is normal */ + + if ((zi->ci.pos_in_buffered_data>0) && (err==ZIP_OK)) + { + if (zip64FlushWriteBuffer(zi)==ZIP_ERRNO) + err = ZIP_ERRNO; + } + + if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) + { + int tmp_err = deflateEnd(&zi->ci.stream); + if (err == ZIP_OK) + err = tmp_err; + zi->ci.stream_initialised = 0; + } +#ifdef HAVE_BZIP2 + else if((zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw)) + { + int tmperr = BZ2_bzCompressEnd(&zi->ci.bstream); + if (err==ZIP_OK) + err = tmperr; + zi->ci.stream_initialised = 0; + } +#endif + + if (!zi->ci.raw) + { + crc32 = (uLong)zi->ci.crc32; + uncompressed_size = zi->ci.totalUncompressedData; + } + compressed_size = zi->ci.totalCompressedData; + +# ifndef NOCRYPT + compressed_size += zi->ci.crypt_header_size; +# endif + + // update Current Item crc and sizes, + if(compressed_size >= 0xffffffff || uncompressed_size >= 0xffffffff || zi->ci.pos_local_header >= 0xffffffff) + { + /*version Made by*/ + zip64local_putValue_inmemory(zi->ci.central_header+4,(uLong)45,2); + /*version needed*/ + zip64local_putValue_inmemory(zi->ci.central_header+6,(uLong)45,2); + + } + + zip64local_putValue_inmemory(zi->ci.central_header+16,crc32,4); /*crc*/ + + + if(compressed_size >= 0xffffffff) + zip64local_putValue_inmemory(zi->ci.central_header+20, invalidValue,4); /*compr size*/ + else + zip64local_putValue_inmemory(zi->ci.central_header+20, compressed_size,4); /*compr size*/ + + /// set internal file attributes field + if (zi->ci.stream.data_type == Z_ASCII) + zip64local_putValue_inmemory(zi->ci.central_header+36,(uLong)Z_ASCII,2); + + if(uncompressed_size >= 0xffffffff) + zip64local_putValue_inmemory(zi->ci.central_header+24, invalidValue,4); /*uncompr size*/ + else + zip64local_putValue_inmemory(zi->ci.central_header+24, uncompressed_size,4); /*uncompr size*/ + + // Add ZIP64 extra info field for uncompressed size + if(uncompressed_size >= 0xffffffff) + datasize += 8; + + // Add ZIP64 extra info field for compressed size + if(compressed_size >= 0xffffffff) + datasize += 8; + + // Add ZIP64 extra info field for relative offset to local file header of current file + if(zi->ci.pos_local_header >= 0xffffffff) + datasize += 8; + + if(datasize > 0) + { + char* p = NULL; + + if((uLong)(datasize + 4) > zi->ci.size_centralExtraFree) + { + // we can not write more data to the buffer that we have room for. + return ZIP_BADZIPFILE; + } + + p = zi->ci.central_header + zi->ci.size_centralheader; + + // Add Extra Information Header for 'ZIP64 information' + zip64local_putValue_inmemory(p, 0x0001, 2); // HeaderID + p += 2; + zip64local_putValue_inmemory(p, datasize, 2); // DataSize + p += 2; + + if(uncompressed_size >= 0xffffffff) + { + zip64local_putValue_inmemory(p, uncompressed_size, 8); + p += 8; + } + + if(compressed_size >= 0xffffffff) + { + zip64local_putValue_inmemory(p, compressed_size, 8); + p += 8; + } + + if(zi->ci.pos_local_header >= 0xffffffff) + { + zip64local_putValue_inmemory(p, zi->ci.pos_local_header, 8); + p += 8; + } + + // Update how much extra free space we got in the memory buffer + // and increase the centralheader size so the new ZIP64 fields are included + // ( 4 below is the size of HeaderID and DataSize field ) + zi->ci.size_centralExtraFree -= datasize + 4; + zi->ci.size_centralheader += datasize + 4; + + // Update the extra info size field + zi->ci.size_centralExtra += datasize + 4; + zip64local_putValue_inmemory(zi->ci.central_header+30,(uLong)zi->ci.size_centralExtra,2); + } + + if (err==ZIP_OK) + err = add_data_in_datablock(&zi->central_dir, zi->ci.central_header, (uLong)zi->ci.size_centralheader); + + free(zi->ci.central_header); + + if (err==ZIP_OK) + { + // Update the LocalFileHeader with the new values. + + ZPOS64_T cur_pos_inzip = ZTELL64(zi->z_filefunc,zi->filestream); + + if (ZSEEK64(zi->z_filefunc,zi->filestream, zi->ci.pos_local_header + 14,ZLIB_FILEFUNC_SEEK_SET)!=0) + err = ZIP_ERRNO; + + if (err==ZIP_OK) + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,crc32,4); /* crc 32, unknown */ + + if(uncompressed_size >= 0xffffffff) + { + if(zi->ci.pos_zip64extrainfo > 0) + { + // Update the size in the ZIP64 extended field. + if (ZSEEK64(zi->z_filefunc,zi->filestream, zi->ci.pos_zip64extrainfo + 4,ZLIB_FILEFUNC_SEEK_SET)!=0) + err = ZIP_ERRNO; + + if (err==ZIP_OK) /* compressed size, unknown */ + err = zip64local_putValue(&zi->z_filefunc, zi->filestream, uncompressed_size, 8); + + if (err==ZIP_OK) /* uncompressed size, unknown */ + err = zip64local_putValue(&zi->z_filefunc, zi->filestream, compressed_size, 8); + } + } + else + { + if (err==ZIP_OK) /* compressed size, unknown */ + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,compressed_size,4); + + if (err==ZIP_OK) /* uncompressed size, unknown */ + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,uncompressed_size,4); + } + + if (ZSEEK64(zi->z_filefunc,zi->filestream, cur_pos_inzip,ZLIB_FILEFUNC_SEEK_SET)!=0) + err = ZIP_ERRNO; + } + + zi->number_entry ++; + zi->in_opened_file_inzip = 0; + + return err; +} + +extern int ZEXPORT zipCloseFileInZip (zipFile file) +{ + return zipCloseFileInZipRaw (file,0,0); +} + +int Write_Zip64EndOfCentralDirectoryLocator(zip64_internal* zi, ZPOS64_T zip64eocd_pos_inzip) +{ + int err = ZIP_OK; + ZPOS64_T pos = zip64eocd_pos_inzip - zi->add_position_when_writting_offset; + + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)ZIP64ENDLOCHEADERMAGIC,4); + + /*num disks*/ + if (err==ZIP_OK) /* number of the disk with the start of the central directory */ + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); + + /*relative offset*/ + if (err==ZIP_OK) /* Relative offset to the Zip64EndOfCentralDirectory */ + err = zip64local_putValue(&zi->z_filefunc,zi->filestream, pos,8); + + /*total disks*/ /* Do not support spawning of disk so always say 1 here*/ + if (err==ZIP_OK) /* number of the disk with the start of the central directory */ + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)1,4); + + return err; +} + +int Write_Zip64EndOfCentralDirectoryRecord(zip64_internal* zi, uLong size_centraldir, ZPOS64_T centraldir_pos_inzip) +{ + int err = ZIP_OK; + + uLong Zip64DataSize = 44; + + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)ZIP64ENDHEADERMAGIC,4); + + if (err==ZIP_OK) /* size of this 'zip64 end of central directory' */ + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(ZPOS64_T)Zip64DataSize,8); // why ZPOS64_T of this ? + + if (err==ZIP_OK) /* version made by */ + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)45,2); + + if (err==ZIP_OK) /* version needed */ + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)45,2); + + if (err==ZIP_OK) /* number of this disk */ + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); + + if (err==ZIP_OK) /* number of the disk with the start of the central directory */ + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); + + if (err==ZIP_OK) /* total number of entries in the central dir on this disk */ + err = zip64local_putValue(&zi->z_filefunc, zi->filestream, zi->number_entry, 8); + + if (err==ZIP_OK) /* total number of entries in the central dir */ + err = zip64local_putValue(&zi->z_filefunc, zi->filestream, zi->number_entry, 8); + + if (err==ZIP_OK) /* size of the central directory */ + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(ZPOS64_T)size_centraldir,8); + + if (err==ZIP_OK) /* offset of start of central directory with respect to the starting disk number */ + { + ZPOS64_T pos = centraldir_pos_inzip - zi->add_position_when_writting_offset; + err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (ZPOS64_T)pos,8); + } + return err; +} +int Write_EndOfCentralDirectoryRecord(zip64_internal* zi, uLong size_centraldir, ZPOS64_T centraldir_pos_inzip) +{ + int err = ZIP_OK; + + /*signature*/ + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)ENDHEADERMAGIC,4); + + if (err==ZIP_OK) /* number of this disk */ + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2); + + if (err==ZIP_OK) /* number of the disk with the start of the central directory */ + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2); + + if (err==ZIP_OK) /* total number of entries in the central dir on this disk */ + { + { + if(zi->number_entry >= 0xFFFF) + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xffff,2); // use value in ZIP64 record + else + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2); + } + } + + if (err==ZIP_OK) /* total number of entries in the central dir */ + { + if(zi->number_entry >= 0xFFFF) + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xffff,2); // use value in ZIP64 record + else + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2); + } + + if (err==ZIP_OK) /* size of the central directory */ + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_centraldir,4); + + if (err==ZIP_OK) /* offset of start of central directory with respect to the starting disk number */ + { + ZPOS64_T pos = centraldir_pos_inzip - zi->add_position_when_writting_offset; + if(pos >= 0xffffffff) + { + err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (uLong)0xffffffff,4); + } + else + err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (uLong)(centraldir_pos_inzip - zi->add_position_when_writting_offset),4); + } + + return err; +} + +int Write_GlobalComment(zip64_internal* zi, const char* global_comment) +{ + int err = ZIP_OK; + uInt size_global_comment = 0; + + if(global_comment != NULL) + size_global_comment = (uInt)strlen(global_comment); + + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_global_comment,2); + + if (err == ZIP_OK && size_global_comment > 0) + { + if (ZWRITE64(zi->z_filefunc,zi->filestream, global_comment, size_global_comment) != size_global_comment) + err = ZIP_ERRNO; + } + return err; +} + +extern int ZEXPORT zipClose (zipFile file, const char* global_comment) +{ + zip64_internal* zi; + int err = 0; + uLong size_centraldir = 0; + ZPOS64_T centraldir_pos_inzip; + ZPOS64_T pos; + + if (file == NULL) + return ZIP_PARAMERROR; + + zi = (zip64_internal*)file; + + if (zi->in_opened_file_inzip == 1) + { + err = zipCloseFileInZip (file); + } + +#ifndef NO_ADDFILEINEXISTINGZIP + if (global_comment==NULL) + global_comment = zi->globalcomment; +#endif + + centraldir_pos_inzip = ZTELL64(zi->z_filefunc,zi->filestream); + + if (err==ZIP_OK) + { + linkedlist_datablock_internal* ldi = zi->central_dir.first_block; + while (ldi!=NULL) + { + if ((err==ZIP_OK) && (ldi->filled_in_this_block>0)) + { + if (ZWRITE64(zi->z_filefunc,zi->filestream, ldi->data, ldi->filled_in_this_block) != ldi->filled_in_this_block) + err = ZIP_ERRNO; + } + + size_centraldir += ldi->filled_in_this_block; + ldi = ldi->next_datablock; + } + } + free_linkedlist(&(zi->central_dir)); + + pos = centraldir_pos_inzip - zi->add_position_when_writting_offset; + if(pos >= 0xffffffff) + { + ZPOS64_T Zip64EOCDpos = ZTELL64(zi->z_filefunc,zi->filestream); + Write_Zip64EndOfCentralDirectoryRecord(zi, size_centraldir, centraldir_pos_inzip); + + Write_Zip64EndOfCentralDirectoryLocator(zi, Zip64EOCDpos); + } + + if (err==ZIP_OK) + err = Write_EndOfCentralDirectoryRecord(zi, size_centraldir, centraldir_pos_inzip); + + if(err == ZIP_OK) + err = Write_GlobalComment(zi, global_comment); + + if (ZCLOSE64(zi->z_filefunc,zi->filestream) != 0) + if (err == ZIP_OK) + err = ZIP_ERRNO; + +#ifndef NO_ADDFILEINEXISTINGZIP + TRYFREE(zi->globalcomment); +#endif + TRYFREE(zi); + + return err; +} + +extern int ZEXPORT zipRemoveExtraInfoBlock (char* pData, int* dataLen, short sHeader) +{ + char* p = pData; + int size = 0; + char* pNewHeader; + char* pTmp; + short header; + short dataSize; + + int retVal = ZIP_OK; + + if(pData == NULL || *dataLen < 4) + return ZIP_PARAMERROR; + + pNewHeader = (char*)ALLOC(*dataLen); + pTmp = pNewHeader; + + while(p < (pData + *dataLen)) + { + header = *(short*)p; + dataSize = *(((short*)p)+1); + + if( header == sHeader ) // Header found. + { + p += dataSize + 4; // skip it. do not copy to temp buffer + } + else + { + // Extra Info block should not be removed, So copy it to the temp buffer. + memcpy(pTmp, p, dataSize + 4); + p += dataSize + 4; + size += dataSize + 4; + } + + } + + if(size < *dataLen) + { + // clean old extra info block. + memset(pData,0, *dataLen); + + // copy the new extra info block over the old + if(size > 0) + memcpy(pData, pNewHeader, size); + + // set the new extra info size + *dataLen = size; + + retVal = ZIP_OK; + } + else + retVal = ZIP_ERRNO; + + TRYFREE(pNewHeader); + + return retVal; +} diff --git a/libs/zlib/contrib/minizip/zip.h b/libs/zlib/contrib/minizip/zip.h new file mode 100644 index 000000000..8aaebb623 --- /dev/null +++ b/libs/zlib/contrib/minizip/zip.h @@ -0,0 +1,362 @@ +/* zip.h -- IO on .zip files using zlib + Version 1.1, February 14h, 2010 + part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) + + Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) + + Modifications for Zip64 support + Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) + + For more info read MiniZip_info.txt + + --------------------------------------------------------------------------- + + Condition of use and distribution are the same than zlib : + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + --------------------------------------------------------------------------- + + Changes + + See header of zip.h + +*/ + +#ifndef _zip12_H +#define _zip12_H + +#ifdef __cplusplus +extern "C" { +#endif + +//#define HAVE_BZIP2 + +#ifndef _ZLIB_H +#include "zlib.h" +#endif + +#ifndef _ZLIBIOAPI_H +#include "ioapi.h" +#endif + +#ifdef HAVE_BZIP2 +#include "bzlib.h" +#endif + +#define Z_BZIP2ED 12 + +#if defined(STRICTZIP) || defined(STRICTZIPUNZIP) +/* like the STRICT of WIN32, we define a pointer that cannot be converted + from (void*) without cast */ +typedef struct TagzipFile__ { int unused; } zipFile__; +typedef zipFile__ *zipFile; +#else +typedef voidp zipFile; +#endif + +#define ZIP_OK (0) +#define ZIP_EOF (0) +#define ZIP_ERRNO (Z_ERRNO) +#define ZIP_PARAMERROR (-102) +#define ZIP_BADZIPFILE (-103) +#define ZIP_INTERNALERROR (-104) + +#ifndef DEF_MEM_LEVEL +# if MAX_MEM_LEVEL >= 8 +# define DEF_MEM_LEVEL 8 +# else +# define DEF_MEM_LEVEL MAX_MEM_LEVEL +# endif +#endif +/* default memLevel */ + +/* tm_zip contain date/time info */ +typedef struct tm_zip_s +{ + uInt tm_sec; /* seconds after the minute - [0,59] */ + uInt tm_min; /* minutes after the hour - [0,59] */ + uInt tm_hour; /* hours since midnight - [0,23] */ + uInt tm_mday; /* day of the month - [1,31] */ + uInt tm_mon; /* months since January - [0,11] */ + uInt tm_year; /* years - [1980..2044] */ +} tm_zip; + +typedef struct +{ + tm_zip tmz_date; /* date in understandable format */ + uLong dosDate; /* if dos_date == 0, tmu_date is used */ +/* uLong flag; */ /* general purpose bit flag 2 bytes */ + + uLong internal_fa; /* internal file attributes 2 bytes */ + uLong external_fa; /* external file attributes 4 bytes */ +} zip_fileinfo; + +typedef const char* zipcharpc; + + +#define APPEND_STATUS_CREATE (0) +#define APPEND_STATUS_CREATEAFTER (1) +#define APPEND_STATUS_ADDINZIP (2) + +extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append)); +extern zipFile ZEXPORT zipOpen64 OF((const void *pathname, int append)); +/* + Create a zipfile. + pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on + an Unix computer "zlib/zlib113.zip". + if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip + will be created at the end of the file. + (useful if the file contain a self extractor code) + if the file pathname exist and append==APPEND_STATUS_ADDINZIP, we will + add files in existing zip (be sure you don't add file that doesn't exist) + If the zipfile cannot be opened, the return value is NULL. + Else, the return value is a zipFile Handle, usable with other function + of this zip package. +*/ + +/* Note : there is no delete function into a zipfile. + If you want delete file into a zipfile, you must open a zipfile, and create another + Of couse, you can use RAW reading and writing to copy the file you did not want delte +*/ + +extern zipFile ZEXPORT zipOpen2 OF((const char *pathname, + int append, + zipcharpc* globalcomment, + zlib_filefunc_def* pzlib_filefunc_def)); + +extern zipFile ZEXPORT zipOpen2_64 OF((const void *pathname, + int append, + zipcharpc* globalcomment, + zlib_filefunc64_def* pzlib_filefunc_def)); + +extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file, + const char* filename, + const zip_fileinfo* zipfi, + const void* extrafield_local, + uInt size_extrafield_local, + const void* extrafield_global, + uInt size_extrafield_global, + const char* comment, + int method, + int level)); + +extern int ZEXPORT zipOpenNewFileInZip64 OF((zipFile file, + const char* filename, + const zip_fileinfo* zipfi, + const void* extrafield_local, + uInt size_extrafield_local, + const void* extrafield_global, + uInt size_extrafield_global, + const char* comment, + int method, + int level, + int zip64)); + +/* + Open a file in the ZIP for writing. + filename : the filename in zip (if NULL, '-' without quote will be used + *zipfi contain supplemental information + if extrafield_local!=NULL and size_extrafield_local>0, extrafield_local + contains the extrafield data the the local header + if extrafield_global!=NULL and size_extrafield_global>0, extrafield_global + contains the extrafield data the the local header + if comment != NULL, comment contain the comment string + method contain the compression method (0 for store, Z_DEFLATED for deflate) + level contain the level of compression (can be Z_DEFAULT_COMPRESSION) + zip64 is set to 1 if a zip64 extended information block should be added to the local file header. + this MUST be '1' if the uncompressed size is >= 0xffffffff. + +*/ + + +extern int ZEXPORT zipOpenNewFileInZip2 OF((zipFile file, + const char* filename, + const zip_fileinfo* zipfi, + const void* extrafield_local, + uInt size_extrafield_local, + const void* extrafield_global, + uInt size_extrafield_global, + const char* comment, + int method, + int level, + int raw)); + + +extern int ZEXPORT zipOpenNewFileInZip2_64 OF((zipFile file, + const char* filename, + const zip_fileinfo* zipfi, + const void* extrafield_local, + uInt size_extrafield_local, + const void* extrafield_global, + uInt size_extrafield_global, + const char* comment, + int method, + int level, + int raw, + int zip64)); +/* + Same than zipOpenNewFileInZip, except if raw=1, we write raw file + */ + +extern int ZEXPORT zipOpenNewFileInZip3 OF((zipFile file, + const char* filename, + const zip_fileinfo* zipfi, + const void* extrafield_local, + uInt size_extrafield_local, + const void* extrafield_global, + uInt size_extrafield_global, + const char* comment, + int method, + int level, + int raw, + int windowBits, + int memLevel, + int strategy, + const char* password, + uLong crcForCrypting)); + +extern int ZEXPORT zipOpenNewFileInZip3_64 OF((zipFile file, + const char* filename, + const zip_fileinfo* zipfi, + const void* extrafield_local, + uInt size_extrafield_local, + const void* extrafield_global, + uInt size_extrafield_global, + const char* comment, + int method, + int level, + int raw, + int windowBits, + int memLevel, + int strategy, + const char* password, + uLong crcForCrypting, + int zip64 + )); + +/* + Same than zipOpenNewFileInZip2, except + windowBits,memLevel,,strategy : see parameter strategy in deflateInit2 + password : crypting password (NULL for no crypting) + crcForCrypting : crc of file to compress (needed for crypting) + */ + +extern int ZEXPORT zipOpenNewFileInZip4 OF((zipFile file, + const char* filename, + const zip_fileinfo* zipfi, + const void* extrafield_local, + uInt size_extrafield_local, + const void* extrafield_global, + uInt size_extrafield_global, + const char* comment, + int method, + int level, + int raw, + int windowBits, + int memLevel, + int strategy, + const char* password, + uLong crcForCrypting, + uLong versionMadeBy, + uLong flagBase + )); + + +extern int ZEXPORT zipOpenNewFileInZip4_64 OF((zipFile file, + const char* filename, + const zip_fileinfo* zipfi, + const void* extrafield_local, + uInt size_extrafield_local, + const void* extrafield_global, + uInt size_extrafield_global, + const char* comment, + int method, + int level, + int raw, + int windowBits, + int memLevel, + int strategy, + const char* password, + uLong crcForCrypting, + uLong versionMadeBy, + uLong flagBase, + int zip64 + )); +/* + Same than zipOpenNewFileInZip4, except + versionMadeBy : value for Version made by field + flag : value for flag field (compression level info will be added) + */ + + +extern int ZEXPORT zipWriteInFileInZip OF((zipFile file, + const void* buf, + unsigned len)); +/* + Write data in the zipfile +*/ + +extern int ZEXPORT zipCloseFileInZip OF((zipFile file)); +/* + Close the current file in the zipfile +*/ + +extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file, + uLong uncompressed_size, + uLong crc32)); + +extern int ZEXPORT zipCloseFileInZipRaw64 OF((zipFile file, + ZPOS64_T uncompressed_size, + uLong crc32)); + +/* + Close the current file in the zipfile, for file opened with + parameter raw=1 in zipOpenNewFileInZip2 + uncompressed_size and crc32 are value for the uncompressed size +*/ + +extern int ZEXPORT zipClose OF((zipFile file, + const char* global_comment)); +/* + Close the zipfile +*/ + + +extern int ZEXPORT zipRemoveExtraInfoBlock OF((char* pData, int* dataLen, short sHeader)); +/* + zipRemoveExtraInfoBlock - Added by Mathias Svensson + + Remove extra information block from a extra information data for the local file header or central directory header + + It is needed to remove ZIP64 extra information blocks when before data is written if using RAW mode. + + 0x0001 is the signature header for the ZIP64 extra information blocks + + usage. + Remove ZIP64 Extra information from a central director extra field data + zipRemoveExtraInfoBlock(pCenDirExtraFieldData, &nCenDirExtraFieldDataLen, 0x0001); + + Remove ZIP64 Extra information from a Local File Header extra field data + zipRemoveExtraInfoBlock(pLocalHeaderExtraFieldData, &nLocalHeaderExtraFieldDataLen, 0x0001); +*/ + +#ifdef __cplusplus +} +#endif + +#endif /* _zip64_H */ diff --git a/libs/zlib/contrib/pascal/example.pas b/libs/zlib/contrib/pascal/example.pas new file mode 100644 index 000000000..5518b36a7 --- /dev/null +++ b/libs/zlib/contrib/pascal/example.pas @@ -0,0 +1,599 @@ +(* example.c -- usage example of the zlib compression library + * Copyright (C) 1995-2003 Jean-loup Gailly. + * For conditions of distribution and use, see copyright notice in zlib.h + * + * Pascal translation + * Copyright (C) 1998 by Jacques Nomssi Nzali. + * For conditions of distribution and use, see copyright notice in readme.txt + * + * Adaptation to the zlibpas interface + * Copyright (C) 2003 by Cosmin Truta. + * For conditions of distribution and use, see copyright notice in readme.txt + *) + +program example; + +{$DEFINE TEST_COMPRESS} +{DO NOT $DEFINE TEST_GZIO} +{$DEFINE TEST_DEFLATE} +{$DEFINE TEST_INFLATE} +{$DEFINE TEST_FLUSH} +{$DEFINE TEST_SYNC} +{$DEFINE TEST_DICT} + +uses SysUtils, zlibpas; + +const TESTFILE = 'foo.gz'; + +(* "hello world" would be more standard, but the repeated "hello" + * stresses the compression code better, sorry... + *) +const hello: PChar = 'hello, hello!'; + +const dictionary: PChar = 'hello'; + +var dictId: LongInt; (* Adler32 value of the dictionary *) + +procedure CHECK_ERR(err: Integer; msg: String); +begin + if err <> Z_OK then + begin + WriteLn(msg, ' error: ', err); + Halt(1); + end; +end; + +procedure EXIT_ERR(const msg: String); +begin + WriteLn('Error: ', msg); + Halt(1); +end; + +(* =========================================================================== + * Test compress and uncompress + *) +{$IFDEF TEST_COMPRESS} +procedure test_compress(compr: Pointer; comprLen: LongInt; + uncompr: Pointer; uncomprLen: LongInt); +var err: Integer; + len: LongInt; +begin + len := StrLen(hello)+1; + + err := compress(compr, comprLen, hello, len); + CHECK_ERR(err, 'compress'); + + StrCopy(PChar(uncompr), 'garbage'); + + err := uncompress(uncompr, uncomprLen, compr, comprLen); + CHECK_ERR(err, 'uncompress'); + + if StrComp(PChar(uncompr), hello) <> 0 then + EXIT_ERR('bad uncompress') + else + WriteLn('uncompress(): ', PChar(uncompr)); +end; +{$ENDIF} + +(* =========================================================================== + * Test read/write of .gz files + *) +{$IFDEF TEST_GZIO} +procedure test_gzio(const fname: PChar; (* compressed file name *) + uncompr: Pointer; + uncomprLen: LongInt); +var err: Integer; + len: Integer; + zfile: gzFile; + pos: LongInt; +begin + len := StrLen(hello)+1; + + zfile := gzopen(fname, 'wb'); + if zfile = NIL then + begin + WriteLn('gzopen error'); + Halt(1); + end; + gzputc(zfile, 'h'); + if gzputs(zfile, 'ello') <> 4 then + begin + WriteLn('gzputs err: ', gzerror(zfile, err)); + Halt(1); + end; + {$IFDEF GZ_FORMAT_STRING} + if gzprintf(zfile, ', %s!', 'hello') <> 8 then + begin + WriteLn('gzprintf err: ', gzerror(zfile, err)); + Halt(1); + end; + {$ELSE} + if gzputs(zfile, ', hello!') <> 8 then + begin + WriteLn('gzputs err: ', gzerror(zfile, err)); + Halt(1); + end; + {$ENDIF} + gzseek(zfile, 1, SEEK_CUR); (* add one zero byte *) + gzclose(zfile); + + zfile := gzopen(fname, 'rb'); + if zfile = NIL then + begin + WriteLn('gzopen error'); + Halt(1); + end; + + StrCopy(PChar(uncompr), 'garbage'); + + if gzread(zfile, uncompr, uncomprLen) <> len then + begin + WriteLn('gzread err: ', gzerror(zfile, err)); + Halt(1); + end; + if StrComp(PChar(uncompr), hello) <> 0 then + begin + WriteLn('bad gzread: ', PChar(uncompr)); + Halt(1); + end + else + WriteLn('gzread(): ', PChar(uncompr)); + + pos := gzseek(zfile, -8, SEEK_CUR); + if (pos <> 6) or (gztell(zfile) <> pos) then + begin + WriteLn('gzseek error, pos=', pos, ', gztell=', gztell(zfile)); + Halt(1); + end; + + if gzgetc(zfile) <> ' ' then + begin + WriteLn('gzgetc error'); + Halt(1); + end; + + if gzungetc(' ', zfile) <> ' ' then + begin + WriteLn('gzungetc error'); + Halt(1); + end; + + gzgets(zfile, PChar(uncompr), uncomprLen); + uncomprLen := StrLen(PChar(uncompr)); + if uncomprLen <> 7 then (* " hello!" *) + begin + WriteLn('gzgets err after gzseek: ', gzerror(zfile, err)); + Halt(1); + end; + if StrComp(PChar(uncompr), hello + 6) <> 0 then + begin + WriteLn('bad gzgets after gzseek'); + Halt(1); + end + else + WriteLn('gzgets() after gzseek: ', PChar(uncompr)); + + gzclose(zfile); +end; +{$ENDIF} + +(* =========================================================================== + * Test deflate with small buffers + *) +{$IFDEF TEST_DEFLATE} +procedure test_deflate(compr: Pointer; comprLen: LongInt); +var c_stream: z_stream; (* compression stream *) + err: Integer; + len: LongInt; +begin + len := StrLen(hello)+1; + + c_stream.zalloc := NIL; + c_stream.zfree := NIL; + c_stream.opaque := NIL; + + err := deflateInit(c_stream, Z_DEFAULT_COMPRESSION); + CHECK_ERR(err, 'deflateInit'); + + c_stream.next_in := hello; + c_stream.next_out := compr; + + while (c_stream.total_in <> len) and + (c_stream.total_out < comprLen) do + begin + c_stream.avail_out := 1; { force small buffers } + c_stream.avail_in := 1; + err := deflate(c_stream, Z_NO_FLUSH); + CHECK_ERR(err, 'deflate'); + end; + + (* Finish the stream, still forcing small buffers: *) + while TRUE do + begin + c_stream.avail_out := 1; + err := deflate(c_stream, Z_FINISH); + if err = Z_STREAM_END then + break; + CHECK_ERR(err, 'deflate'); + end; + + err := deflateEnd(c_stream); + CHECK_ERR(err, 'deflateEnd'); +end; +{$ENDIF} + +(* =========================================================================== + * Test inflate with small buffers + *) +{$IFDEF TEST_INFLATE} +procedure test_inflate(compr: Pointer; comprLen : LongInt; + uncompr: Pointer; uncomprLen : LongInt); +var err: Integer; + d_stream: z_stream; (* decompression stream *) +begin + StrCopy(PChar(uncompr), 'garbage'); + + d_stream.zalloc := NIL; + d_stream.zfree := NIL; + d_stream.opaque := NIL; + + d_stream.next_in := compr; + d_stream.avail_in := 0; + d_stream.next_out := uncompr; + + err := inflateInit(d_stream); + CHECK_ERR(err, 'inflateInit'); + + while (d_stream.total_out < uncomprLen) and + (d_stream.total_in < comprLen) do + begin + d_stream.avail_out := 1; (* force small buffers *) + d_stream.avail_in := 1; + err := inflate(d_stream, Z_NO_FLUSH); + if err = Z_STREAM_END then + break; + CHECK_ERR(err, 'inflate'); + end; + + err := inflateEnd(d_stream); + CHECK_ERR(err, 'inflateEnd'); + + if StrComp(PChar(uncompr), hello) <> 0 then + EXIT_ERR('bad inflate') + else + WriteLn('inflate(): ', PChar(uncompr)); +end; +{$ENDIF} + +(* =========================================================================== + * Test deflate with large buffers and dynamic change of compression level + *) +{$IFDEF TEST_DEFLATE} +procedure test_large_deflate(compr: Pointer; comprLen: LongInt; + uncompr: Pointer; uncomprLen: LongInt); +var c_stream: z_stream; (* compression stream *) + err: Integer; +begin + c_stream.zalloc := NIL; + c_stream.zfree := NIL; + c_stream.opaque := NIL; + + err := deflateInit(c_stream, Z_BEST_SPEED); + CHECK_ERR(err, 'deflateInit'); + + c_stream.next_out := compr; + c_stream.avail_out := Integer(comprLen); + + (* At this point, uncompr is still mostly zeroes, so it should compress + * very well: + *) + c_stream.next_in := uncompr; + c_stream.avail_in := Integer(uncomprLen); + err := deflate(c_stream, Z_NO_FLUSH); + CHECK_ERR(err, 'deflate'); + if c_stream.avail_in <> 0 then + EXIT_ERR('deflate not greedy'); + + (* Feed in already compressed data and switch to no compression: *) + deflateParams(c_stream, Z_NO_COMPRESSION, Z_DEFAULT_STRATEGY); + c_stream.next_in := compr; + c_stream.avail_in := Integer(comprLen div 2); + err := deflate(c_stream, Z_NO_FLUSH); + CHECK_ERR(err, 'deflate'); + + (* Switch back to compressing mode: *) + deflateParams(c_stream, Z_BEST_COMPRESSION, Z_FILTERED); + c_stream.next_in := uncompr; + c_stream.avail_in := Integer(uncomprLen); + err := deflate(c_stream, Z_NO_FLUSH); + CHECK_ERR(err, 'deflate'); + + err := deflate(c_stream, Z_FINISH); + if err <> Z_STREAM_END then + EXIT_ERR('deflate should report Z_STREAM_END'); + + err := deflateEnd(c_stream); + CHECK_ERR(err, 'deflateEnd'); +end; +{$ENDIF} + +(* =========================================================================== + * Test inflate with large buffers + *) +{$IFDEF TEST_INFLATE} +procedure test_large_inflate(compr: Pointer; comprLen: LongInt; + uncompr: Pointer; uncomprLen: LongInt); +var err: Integer; + d_stream: z_stream; (* decompression stream *) +begin + StrCopy(PChar(uncompr), 'garbage'); + + d_stream.zalloc := NIL; + d_stream.zfree := NIL; + d_stream.opaque := NIL; + + d_stream.next_in := compr; + d_stream.avail_in := Integer(comprLen); + + err := inflateInit(d_stream); + CHECK_ERR(err, 'inflateInit'); + + while TRUE do + begin + d_stream.next_out := uncompr; (* discard the output *) + d_stream.avail_out := Integer(uncomprLen); + err := inflate(d_stream, Z_NO_FLUSH); + if err = Z_STREAM_END then + break; + CHECK_ERR(err, 'large inflate'); + end; + + err := inflateEnd(d_stream); + CHECK_ERR(err, 'inflateEnd'); + + if d_stream.total_out <> 2 * uncomprLen + comprLen div 2 then + begin + WriteLn('bad large inflate: ', d_stream.total_out); + Halt(1); + end + else + WriteLn('large_inflate(): OK'); +end; +{$ENDIF} + +(* =========================================================================== + * Test deflate with full flush + *) +{$IFDEF TEST_FLUSH} +procedure test_flush(compr: Pointer; var comprLen : LongInt); +var c_stream: z_stream; (* compression stream *) + err: Integer; + len: Integer; +begin + len := StrLen(hello)+1; + + c_stream.zalloc := NIL; + c_stream.zfree := NIL; + c_stream.opaque := NIL; + + err := deflateInit(c_stream, Z_DEFAULT_COMPRESSION); + CHECK_ERR(err, 'deflateInit'); + + c_stream.next_in := hello; + c_stream.next_out := compr; + c_stream.avail_in := 3; + c_stream.avail_out := Integer(comprLen); + err := deflate(c_stream, Z_FULL_FLUSH); + CHECK_ERR(err, 'deflate'); + + Inc(PByteArray(compr)^[3]); (* force an error in first compressed block *) + c_stream.avail_in := len - 3; + + err := deflate(c_stream, Z_FINISH); + if err <> Z_STREAM_END then + CHECK_ERR(err, 'deflate'); + + err := deflateEnd(c_stream); + CHECK_ERR(err, 'deflateEnd'); + + comprLen := c_stream.total_out; +end; +{$ENDIF} + +(* =========================================================================== + * Test inflateSync() + *) +{$IFDEF TEST_SYNC} +procedure test_sync(compr: Pointer; comprLen: LongInt; + uncompr: Pointer; uncomprLen : LongInt); +var err: Integer; + d_stream: z_stream; (* decompression stream *) +begin + StrCopy(PChar(uncompr), 'garbage'); + + d_stream.zalloc := NIL; + d_stream.zfree := NIL; + d_stream.opaque := NIL; + + d_stream.next_in := compr; + d_stream.avail_in := 2; (* just read the zlib header *) + + err := inflateInit(d_stream); + CHECK_ERR(err, 'inflateInit'); + + d_stream.next_out := uncompr; + d_stream.avail_out := Integer(uncomprLen); + + inflate(d_stream, Z_NO_FLUSH); + CHECK_ERR(err, 'inflate'); + + d_stream.avail_in := Integer(comprLen-2); (* read all compressed data *) + err := inflateSync(d_stream); (* but skip the damaged part *) + CHECK_ERR(err, 'inflateSync'); + + err := inflate(d_stream, Z_FINISH); + if err <> Z_DATA_ERROR then + EXIT_ERR('inflate should report DATA_ERROR'); + (* Because of incorrect adler32 *) + + err := inflateEnd(d_stream); + CHECK_ERR(err, 'inflateEnd'); + + WriteLn('after inflateSync(): hel', PChar(uncompr)); +end; +{$ENDIF} + +(* =========================================================================== + * Test deflate with preset dictionary + *) +{$IFDEF TEST_DICT} +procedure test_dict_deflate(compr: Pointer; comprLen: LongInt); +var c_stream: z_stream; (* compression stream *) + err: Integer; +begin + c_stream.zalloc := NIL; + c_stream.zfree := NIL; + c_stream.opaque := NIL; + + err := deflateInit(c_stream, Z_BEST_COMPRESSION); + CHECK_ERR(err, 'deflateInit'); + + err := deflateSetDictionary(c_stream, dictionary, StrLen(dictionary)); + CHECK_ERR(err, 'deflateSetDictionary'); + + dictId := c_stream.adler; + c_stream.next_out := compr; + c_stream.avail_out := Integer(comprLen); + + c_stream.next_in := hello; + c_stream.avail_in := StrLen(hello)+1; + + err := deflate(c_stream, Z_FINISH); + if err <> Z_STREAM_END then + EXIT_ERR('deflate should report Z_STREAM_END'); + + err := deflateEnd(c_stream); + CHECK_ERR(err, 'deflateEnd'); +end; +{$ENDIF} + +(* =========================================================================== + * Test inflate with a preset dictionary + *) +{$IFDEF TEST_DICT} +procedure test_dict_inflate(compr: Pointer; comprLen: LongInt; + uncompr: Pointer; uncomprLen: LongInt); +var err: Integer; + d_stream: z_stream; (* decompression stream *) +begin + StrCopy(PChar(uncompr), 'garbage'); + + d_stream.zalloc := NIL; + d_stream.zfree := NIL; + d_stream.opaque := NIL; + + d_stream.next_in := compr; + d_stream.avail_in := Integer(comprLen); + + err := inflateInit(d_stream); + CHECK_ERR(err, 'inflateInit'); + + d_stream.next_out := uncompr; + d_stream.avail_out := Integer(uncomprLen); + + while TRUE do + begin + err := inflate(d_stream, Z_NO_FLUSH); + if err = Z_STREAM_END then + break; + if err = Z_NEED_DICT then + begin + if d_stream.adler <> dictId then + EXIT_ERR('unexpected dictionary'); + err := inflateSetDictionary(d_stream, dictionary, StrLen(dictionary)); + end; + CHECK_ERR(err, 'inflate with dict'); + end; + + err := inflateEnd(d_stream); + CHECK_ERR(err, 'inflateEnd'); + + if StrComp(PChar(uncompr), hello) <> 0 then + EXIT_ERR('bad inflate with dict') + else + WriteLn('inflate with dictionary: ', PChar(uncompr)); +end; +{$ENDIF} + +var compr, uncompr: Pointer; + comprLen, uncomprLen: LongInt; + +begin + if zlibVersion^ <> ZLIB_VERSION[1] then + EXIT_ERR('Incompatible zlib version'); + + WriteLn('zlib version: ', zlibVersion); + WriteLn('zlib compile flags: ', Format('0x%x', [zlibCompileFlags])); + + comprLen := 10000 * SizeOf(Integer); (* don't overflow on MSDOS *) + uncomprLen := comprLen; + GetMem(compr, comprLen); + GetMem(uncompr, uncomprLen); + if (compr = NIL) or (uncompr = NIL) then + EXIT_ERR('Out of memory'); + (* compr and uncompr are cleared to avoid reading uninitialized + * data and to ensure that uncompr compresses well. + *) + FillChar(compr^, comprLen, 0); + FillChar(uncompr^, uncomprLen, 0); + + {$IFDEF TEST_COMPRESS} + WriteLn('** Testing compress'); + test_compress(compr, comprLen, uncompr, uncomprLen); + {$ENDIF} + + {$IFDEF TEST_GZIO} + WriteLn('** Testing gzio'); + if ParamCount >= 1 then + test_gzio(ParamStr(1), uncompr, uncomprLen) + else + test_gzio(TESTFILE, uncompr, uncomprLen); + {$ENDIF} + + {$IFDEF TEST_DEFLATE} + WriteLn('** Testing deflate with small buffers'); + test_deflate(compr, comprLen); + {$ENDIF} + {$IFDEF TEST_INFLATE} + WriteLn('** Testing inflate with small buffers'); + test_inflate(compr, comprLen, uncompr, uncomprLen); + {$ENDIF} + + {$IFDEF TEST_DEFLATE} + WriteLn('** Testing deflate with large buffers'); + test_large_deflate(compr, comprLen, uncompr, uncomprLen); + {$ENDIF} + {$IFDEF TEST_INFLATE} + WriteLn('** Testing inflate with large buffers'); + test_large_inflate(compr, comprLen, uncompr, uncomprLen); + {$ENDIF} + + {$IFDEF TEST_FLUSH} + WriteLn('** Testing deflate with full flush'); + test_flush(compr, comprLen); + {$ENDIF} + {$IFDEF TEST_SYNC} + WriteLn('** Testing inflateSync'); + test_sync(compr, comprLen, uncompr, uncomprLen); + {$ENDIF} + comprLen := uncomprLen; + + {$IFDEF TEST_DICT} + WriteLn('** Testing deflate and inflate with preset dictionary'); + test_dict_deflate(compr, comprLen); + test_dict_inflate(compr, comprLen, uncompr, uncomprLen); + {$ENDIF} + + FreeMem(compr, comprLen); + FreeMem(uncompr, uncomprLen); +end. diff --git a/libs/zlib/contrib/pascal/readme.txt b/libs/zlib/contrib/pascal/readme.txt new file mode 100644 index 000000000..60e87c8a3 --- /dev/null +++ b/libs/zlib/contrib/pascal/readme.txt @@ -0,0 +1,76 @@ + +This directory contains a Pascal (Delphi, Kylix) interface to the +zlib data compression library. + + +Directory listing +================= + +zlibd32.mak makefile for Borland C++ +example.pas usage example of zlib +zlibpas.pas the Pascal interface to zlib +readme.txt this file + + +Compatibility notes +=================== + +- Although the name "zlib" would have been more normal for the + zlibpas unit, this name is already taken by Borland's ZLib unit. + This is somehow unfortunate, because that unit is not a genuine + interface to the full-fledged zlib functionality, but a suite of + class wrappers around zlib streams. Other essential features, + such as checksums, are missing. + It would have been more appropriate for that unit to have a name + like "ZStreams", or something similar. + +- The C and zlib-supplied types int, uInt, long, uLong, etc. are + translated directly into Pascal types of similar sizes (Integer, + LongInt, etc.), to avoid namespace pollution. In particular, + there is no conversion of unsigned int into a Pascal unsigned + integer. The Word type is non-portable and has the same size + (16 bits) both in a 16-bit and in a 32-bit environment, unlike + Integer. Even if there is a 32-bit Cardinal type, there is no + real need for unsigned int in zlib under a 32-bit environment. + +- Except for the callbacks, the zlib function interfaces are + assuming the calling convention normally used in Pascal + (__pascal for DOS and Windows16, __fastcall for Windows32). + Since the cdecl keyword is used, the old Turbo Pascal does + not work with this interface. + +- The gz* function interfaces are not translated, to avoid + interfacing problems with the C runtime library. Besides, + gzprintf(gzFile file, const char *format, ...) + cannot be translated into Pascal. + + +Legal issues +============ + +The zlibpas interface is: + Copyright (C) 1995-2003 Jean-loup Gailly and Mark Adler. + Copyright (C) 1998 by Bob Dellaca. + Copyright (C) 2003 by Cosmin Truta. + +The example program is: + Copyright (C) 1995-2003 by Jean-loup Gailly. + Copyright (C) 1998,1999,2000 by Jacques Nomssi Nzali. + Copyright (C) 2003 by Cosmin Truta. + + This software is provided 'as-is', without any express or implied + warranty. In no event will the author be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + diff --git a/libs/zlib/contrib/pascal/zlibd32.mak b/libs/zlib/contrib/pascal/zlibd32.mak new file mode 100644 index 000000000..d65ab4dab --- /dev/null +++ b/libs/zlib/contrib/pascal/zlibd32.mak @@ -0,0 +1,99 @@ +# Makefile for zlib +# For use with Delphi and C++ Builder under Win32 +# Updated for zlib 1.2.x by Cosmin Truta + +# ------------ Borland C++ ------------ + +# This project uses the Delphi (fastcall/register) calling convention: +LOC = -DZEXPORT=__fastcall -DZEXPORTVA=__cdecl + +CC = bcc32 +LD = bcc32 +AR = tlib +# do not use "-pr" in CFLAGS +CFLAGS = -a -d -k- -O2 $(LOC) +LDFLAGS = + + +# variables +ZLIB_LIB = zlib.lib + +OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzclose.obj gzlib.obj gzread.obj +OBJ2 = gzwrite.obj infback.obj inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj +OBJP1 = +adler32.obj+compress.obj+crc32.obj+deflate.obj+gzclose.obj+gzlib.obj+gzread.obj +OBJP2 = +gzwrite.obj+infback.obj+inffast.obj+inflate.obj+inftrees.obj+trees.obj+uncompr.obj+zutil.obj + + +# targets +all: $(ZLIB_LIB) example.exe minigzip.exe + +.c.obj: + $(CC) -c $(CFLAGS) $*.c + +adler32.obj: adler32.c zlib.h zconf.h + +compress.obj: compress.c zlib.h zconf.h + +crc32.obj: crc32.c zlib.h zconf.h crc32.h + +deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h + +gzclose.obj: gzclose.c zlib.h zconf.h gzguts.h + +gzlib.obj: gzlib.c zlib.h zconf.h gzguts.h + +gzread.obj: gzread.c zlib.h zconf.h gzguts.h + +gzwrite.obj: gzwrite.c zlib.h zconf.h gzguts.h + +infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ + inffast.h inffixed.h + +inffast.obj: inffast.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ + inffast.h + +inflate.obj: inflate.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ + inffast.h inffixed.h + +inftrees.obj: inftrees.c zutil.h zlib.h zconf.h inftrees.h + +trees.obj: trees.c zutil.h zlib.h zconf.h deflate.h trees.h + +uncompr.obj: uncompr.c zlib.h zconf.h + +zutil.obj: zutil.c zutil.h zlib.h zconf.h + +example.obj: example.c zlib.h zconf.h + +minigzip.obj: minigzip.c zlib.h zconf.h + + +# For the sake of the old Borland make, +# the command line is cut to fit in the MS-DOS 128 byte limit: +$(ZLIB_LIB): $(OBJ1) $(OBJ2) + -del $(ZLIB_LIB) + $(AR) $(ZLIB_LIB) $(OBJP1) + $(AR) $(ZLIB_LIB) $(OBJP2) + + +# testing +test: example.exe minigzip.exe + example + echo hello world | minigzip | minigzip -d + +example.exe: example.obj $(ZLIB_LIB) + $(LD) $(LDFLAGS) example.obj $(ZLIB_LIB) + +minigzip.exe: minigzip.obj $(ZLIB_LIB) + $(LD) $(LDFLAGS) minigzip.obj $(ZLIB_LIB) + + +# cleanup +clean: + -del *.obj + -del *.exe + -del *.lib + -del *.tds + -del zlib.bak + -del foo.gz + diff --git a/libs/zlib/contrib/pascal/zlibpas.pas b/libs/zlib/contrib/pascal/zlibpas.pas new file mode 100644 index 000000000..637ae3a3f --- /dev/null +++ b/libs/zlib/contrib/pascal/zlibpas.pas @@ -0,0 +1,236 @@ +(* zlibpas -- Pascal interface to the zlib data compression library + * + * Copyright (C) 2003 Cosmin Truta. + * Derived from original sources by Bob Dellaca. + * For conditions of distribution and use, see copyright notice in readme.txt + *) + +unit zlibpas; + +interface + +const + ZLIB_VERSION = '1.2.5'; + +type + alloc_func = function(opaque: Pointer; items, size: Integer): Pointer; + cdecl; + free_func = procedure(opaque, address: Pointer); + cdecl; + + in_func = function(opaque: Pointer; var buf: PByte): Integer; + cdecl; + out_func = function(opaque: Pointer; buf: PByte; size: Integer): Integer; + cdecl; + + z_streamp = ^z_stream; + z_stream = packed record + next_in: PChar; (* next input byte *) + avail_in: Integer; (* number of bytes available at next_in *) + total_in: LongInt; (* total nb of input bytes read so far *) + + next_out: PChar; (* next output byte should be put there *) + avail_out: Integer; (* remaining free space at next_out *) + total_out: LongInt; (* total nb of bytes output so far *) + + msg: PChar; (* last error message, NULL if no error *) + state: Pointer; (* not visible by applications *) + + zalloc: alloc_func; (* used to allocate the internal state *) + zfree: free_func; (* used to free the internal state *) + opaque: Pointer; (* private data object passed to zalloc and zfree *) + + data_type: Integer; (* best guess about the data type: ascii or binary *) + adler: LongInt; (* adler32 value of the uncompressed data *) + reserved: LongInt; (* reserved for future use *) + end; + +(* constants *) +const + Z_NO_FLUSH = 0; + Z_PARTIAL_FLUSH = 1; + Z_SYNC_FLUSH = 2; + Z_FULL_FLUSH = 3; + Z_FINISH = 4; + + Z_OK = 0; + Z_STREAM_END = 1; + Z_NEED_DICT = 2; + Z_ERRNO = -1; + Z_STREAM_ERROR = -2; + Z_DATA_ERROR = -3; + Z_MEM_ERROR = -4; + Z_BUF_ERROR = -5; + Z_VERSION_ERROR = -6; + + Z_NO_COMPRESSION = 0; + Z_BEST_SPEED = 1; + Z_BEST_COMPRESSION = 9; + Z_DEFAULT_COMPRESSION = -1; + + Z_FILTERED = 1; + Z_HUFFMAN_ONLY = 2; + Z_RLE = 3; + Z_DEFAULT_STRATEGY = 0; + + Z_BINARY = 0; + Z_ASCII = 1; + Z_UNKNOWN = 2; + + Z_DEFLATED = 8; + +(* basic functions *) +function zlibVersion: PChar; +function deflateInit(var strm: z_stream; level: Integer): Integer; +function deflate(var strm: z_stream; flush: Integer): Integer; +function deflateEnd(var strm: z_stream): Integer; +function inflateInit(var strm: z_stream): Integer; +function inflate(var strm: z_stream; flush: Integer): Integer; +function inflateEnd(var strm: z_stream): Integer; + +(* advanced functions *) +function deflateInit2(var strm: z_stream; level, method, windowBits, + memLevel, strategy: Integer): Integer; +function deflateSetDictionary(var strm: z_stream; const dictionary: PChar; + dictLength: Integer): Integer; +function deflateCopy(var dest, source: z_stream): Integer; +function deflateReset(var strm: z_stream): Integer; +function deflateParams(var strm: z_stream; level, strategy: Integer): Integer; +function deflateBound(var strm: z_stream; sourceLen: LongInt): LongInt; +function deflatePrime(var strm: z_stream; bits, value: Integer): Integer; +function inflateInit2(var strm: z_stream; windowBits: Integer): Integer; +function inflateSetDictionary(var strm: z_stream; const dictionary: PChar; + dictLength: Integer): Integer; +function inflateSync(var strm: z_stream): Integer; +function inflateCopy(var dest, source: z_stream): Integer; +function inflateReset(var strm: z_stream): Integer; +function inflateBackInit(var strm: z_stream; + windowBits: Integer; window: PChar): Integer; +function inflateBack(var strm: z_stream; in_fn: in_func; in_desc: Pointer; + out_fn: out_func; out_desc: Pointer): Integer; +function inflateBackEnd(var strm: z_stream): Integer; +function zlibCompileFlags: LongInt; + +(* utility functions *) +function compress(dest: PChar; var destLen: LongInt; + const source: PChar; sourceLen: LongInt): Integer; +function compress2(dest: PChar; var destLen: LongInt; + const source: PChar; sourceLen: LongInt; + level: Integer): Integer; +function compressBound(sourceLen: LongInt): LongInt; +function uncompress(dest: PChar; var destLen: LongInt; + const source: PChar; sourceLen: LongInt): Integer; + +(* checksum functions *) +function adler32(adler: LongInt; const buf: PChar; len: Integer): LongInt; +function crc32(crc: LongInt; const buf: PChar; len: Integer): LongInt; + +(* various hacks, don't look :) *) +function deflateInit_(var strm: z_stream; level: Integer; + const version: PChar; stream_size: Integer): Integer; +function inflateInit_(var strm: z_stream; const version: PChar; + stream_size: Integer): Integer; +function deflateInit2_(var strm: z_stream; + level, method, windowBits, memLevel, strategy: Integer; + const version: PChar; stream_size: Integer): Integer; +function inflateInit2_(var strm: z_stream; windowBits: Integer; + const version: PChar; stream_size: Integer): Integer; +function inflateBackInit_(var strm: z_stream; + windowBits: Integer; window: PChar; + const version: PChar; stream_size: Integer): Integer; + + +implementation + +{$L adler32.obj} +{$L compress.obj} +{$L crc32.obj} +{$L deflate.obj} +{$L infback.obj} +{$L inffast.obj} +{$L inflate.obj} +{$L inftrees.obj} +{$L trees.obj} +{$L uncompr.obj} +{$L zutil.obj} + +function adler32; external; +function compress; external; +function compress2; external; +function compressBound; external; +function crc32; external; +function deflate; external; +function deflateBound; external; +function deflateCopy; external; +function deflateEnd; external; +function deflateInit_; external; +function deflateInit2_; external; +function deflateParams; external; +function deflatePrime; external; +function deflateReset; external; +function deflateSetDictionary; external; +function inflate; external; +function inflateBack; external; +function inflateBackEnd; external; +function inflateBackInit_; external; +function inflateCopy; external; +function inflateEnd; external; +function inflateInit_; external; +function inflateInit2_; external; +function inflateReset; external; +function inflateSetDictionary; external; +function inflateSync; external; +function uncompress; external; +function zlibCompileFlags; external; +function zlibVersion; external; + +function deflateInit(var strm: z_stream; level: Integer): Integer; +begin + Result := deflateInit_(strm, level, ZLIB_VERSION, sizeof(z_stream)); +end; + +function deflateInit2(var strm: z_stream; level, method, windowBits, memLevel, + strategy: Integer): Integer; +begin + Result := deflateInit2_(strm, level, method, windowBits, memLevel, strategy, + ZLIB_VERSION, sizeof(z_stream)); +end; + +function inflateInit(var strm: z_stream): Integer; +begin + Result := inflateInit_(strm, ZLIB_VERSION, sizeof(z_stream)); +end; + +function inflateInit2(var strm: z_stream; windowBits: Integer): Integer; +begin + Result := inflateInit2_(strm, windowBits, ZLIB_VERSION, sizeof(z_stream)); +end; + +function inflateBackInit(var strm: z_stream; + windowBits: Integer; window: PChar): Integer; +begin + Result := inflateBackInit_(strm, windowBits, window, + ZLIB_VERSION, sizeof(z_stream)); +end; + +function _malloc(Size: Integer): Pointer; cdecl; +begin + GetMem(Result, Size); +end; + +procedure _free(Block: Pointer); cdecl; +begin + FreeMem(Block); +end; + +procedure _memset(P: Pointer; B: Byte; count: Integer); cdecl; +begin + FillChar(P^, count, B); +end; + +procedure _memcpy(dest, source: Pointer; count: Integer); cdecl; +begin + Move(source^, dest^, count); +end; + +end. diff --git a/libs/zlib/contrib/puff/Makefile b/libs/zlib/contrib/puff/Makefile new file mode 100644 index 000000000..b6b69404c --- /dev/null +++ b/libs/zlib/contrib/puff/Makefile @@ -0,0 +1,8 @@ +puff: puff.c puff.h + cc -DTEST -o puff puff.c + +test: puff + puff zeros.raw + +clean: + rm -f puff puff.o diff --git a/libs/zlib/contrib/puff/README b/libs/zlib/contrib/puff/README new file mode 100644 index 000000000..bbc4cb595 --- /dev/null +++ b/libs/zlib/contrib/puff/README @@ -0,0 +1,63 @@ +Puff -- A Simple Inflate +3 Mar 2003 +Mark Adler +madler@alumni.caltech.edu + +What this is -- + +puff.c provides the routine puff() to decompress the deflate data format. It +does so more slowly than zlib, but the code is about one-fifth the size of the +inflate code in zlib, and written to be very easy to read. + +Why I wrote this -- + +puff.c was written to document the deflate format unambiguously, by virtue of +being working C code. It is meant to supplement RFC 1951, which formally +describes the deflate format. I have received many questions on details of the +deflate format, and I hope that reading this code will answer those questions. +puff.c is heavily commented with details of the deflate format, especially +those little nooks and cranies of the format that might not be obvious from a +specification. + +puff.c may also be useful in applications where code size or memory usage is a +very limited resource, and speed is not as important. + +How to use it -- + +Well, most likely you should just be reading puff.c and using zlib for actual +applications, but if you must ... + +Include puff.h in your code, which provides this prototype: + +int puff(unsigned char *dest, /* pointer to destination pointer */ + unsigned long *destlen, /* amount of output space */ + unsigned char *source, /* pointer to source data pointer */ + unsigned long *sourcelen); /* amount of input available */ + +Then you can call puff() to decompress a deflate stream that is in memory in +its entirety at source, to a sufficiently sized block of memory for the +decompressed data at dest. puff() is the only external symbol in puff.c The +only C library functions that puff.c needs are setjmp() and longjmp(), which +are used to simplify error checking in the code to improve readabilty. puff.c +does no memory allocation, and uses less than 2K bytes off of the stack. + +If destlen is not enough space for the uncompressed data, then inflate will +return an error without writing more than destlen bytes. Note that this means +that in order to decompress the deflate data successfully, you need to know +the size of the uncompressed data ahead of time. + +If needed, puff() can determine the size of the uncompressed data with no +output space. This is done by passing dest equal to (unsigned char *)0. Then +the initial value of *destlen is ignored and *destlen is set to the length of +the uncompressed data. So if the size of the uncompressed data is not known, +then two passes of puff() can be used--first to determine the size, and second +to do the actual inflation after allocating the appropriate memory. Not +pretty, but it works. (This is one of the reasons you should be using zlib.) + +The deflate format is self-terminating. If the deflate stream does not end +in *sourcelen bytes, puff() will return an error without reading at or past +endsource. + +On return, *sourcelen is updated to the amount of input data consumed, and +*destlen is updated to the size of the uncompressed data. See the comments +in puff.c for the possible return codes for puff(). diff --git a/libs/zlib/contrib/puff/puff.c b/libs/zlib/contrib/puff/puff.c new file mode 100644 index 000000000..650694e9e --- /dev/null +++ b/libs/zlib/contrib/puff/puff.c @@ -0,0 +1,955 @@ +/* + * puff.c + * Copyright (C) 2002-2010 Mark Adler + * For conditions of distribution and use, see copyright notice in puff.h + * version 2.1, 4 Apr 2010 + * + * puff.c is a simple inflate written to be an unambiguous way to specify the + * deflate format. It is not written for speed but rather simplicity. As a + * side benefit, this code might actually be useful when small code is more + * important than speed, such as bootstrap applications. For typical deflate + * data, zlib's inflate() is about four times as fast as puff(). zlib's + * inflate compiles to around 20K on my machine, whereas puff.c compiles to + * around 4K on my machine (a PowerPC using GNU cc). If the faster decode() + * function here is used, then puff() is only twice as slow as zlib's + * inflate(). + * + * All dynamically allocated memory comes from the stack. The stack required + * is less than 2K bytes. This code is compatible with 16-bit int's and + * assumes that long's are at least 32 bits. puff.c uses the short data type, + * assumed to be 16 bits, for arrays in order to to conserve memory. The code + * works whether integers are stored big endian or little endian. + * + * In the comments below are "Format notes" that describe the inflate process + * and document some of the less obvious aspects of the format. This source + * code is meant to supplement RFC 1951, which formally describes the deflate + * format: + * + * http://www.zlib.org/rfc-deflate.html + */ + +/* + * Change history: + * + * 1.0 10 Feb 2002 - First version + * 1.1 17 Feb 2002 - Clarifications of some comments and notes + * - Update puff() dest and source pointers on negative + * errors to facilitate debugging deflators + * - Remove longest from struct huffman -- not needed + * - Simplify offs[] index in construct() + * - Add input size and checking, using longjmp() to + * maintain easy readability + * - Use short data type for large arrays + * - Use pointers instead of long to specify source and + * destination sizes to avoid arbitrary 4 GB limits + * 1.2 17 Mar 2002 - Add faster version of decode(), doubles speed (!), + * but leave simple version for readabilty + * - Make sure invalid distances detected if pointers + * are 16 bits + * - Fix fixed codes table error + * - Provide a scanning mode for determining size of + * uncompressed data + * 1.3 20 Mar 2002 - Go back to lengths for puff() parameters [Jean-loup] + * - Add a puff.h file for the interface + * - Add braces in puff() for else do [Jean-loup] + * - Use indexes instead of pointers for readability + * 1.4 31 Mar 2002 - Simplify construct() code set check + * - Fix some comments + * - Add FIXLCODES #define + * 1.5 6 Apr 2002 - Minor comment fixes + * 1.6 7 Aug 2002 - Minor format changes + * 1.7 3 Mar 2003 - Added test code for distribution + * - Added zlib-like license + * 1.8 9 Jan 2004 - Added some comments on no distance codes case + * 1.9 21 Feb 2008 - Fix bug on 16-bit integer architectures [Pohland] + * - Catch missing end-of-block symbol error + * 2.0 25 Jul 2008 - Add #define to permit distance too far back + * - Add option in TEST code for puff to write the data + * - Add option in TEST code to skip input bytes + * - Allow TEST code to read from piped stdin + * 2.1 4 Apr 2010 - Avoid variable initialization for happier compilers + * - Avoid unsigned comparisons for even happier compilers + */ + +#include /* for setjmp(), longjmp(), and jmp_buf */ +#include "puff.h" /* prototype for puff() */ + +#define local static /* for local function definitions */ +#define NIL ((unsigned char *)0) /* for no output option */ + +/* + * Maximums for allocations and loops. It is not useful to change these -- + * they are fixed by the deflate format. + */ +#define MAXBITS 15 /* maximum bits in a code */ +#define MAXLCODES 286 /* maximum number of literal/length codes */ +#define MAXDCODES 30 /* maximum number of distance codes */ +#define MAXCODES (MAXLCODES+MAXDCODES) /* maximum codes lengths to read */ +#define FIXLCODES 288 /* number of fixed literal/length codes */ + +/* input and output state */ +struct state { + /* output state */ + unsigned char *out; /* output buffer */ + unsigned long outlen; /* available space at out */ + unsigned long outcnt; /* bytes written to out so far */ + + /* input state */ + unsigned char *in; /* input buffer */ + unsigned long inlen; /* available input at in */ + unsigned long incnt; /* bytes read so far */ + int bitbuf; /* bit buffer */ + int bitcnt; /* number of bits in bit buffer */ + + /* input limit error return state for bits() and decode() */ + jmp_buf env; +}; + +/* + * Return need bits from the input stream. This always leaves less than + * eight bits in the buffer. bits() works properly for need == 0. + * + * Format notes: + * + * - Bits are stored in bytes from the least significant bit to the most + * significant bit. Therefore bits are dropped from the bottom of the bit + * buffer, using shift right, and new bytes are appended to the top of the + * bit buffer, using shift left. + */ +local int bits(struct state *s, int need) +{ + long val; /* bit accumulator (can use up to 20 bits) */ + + /* load at least need bits into val */ + val = s->bitbuf; + while (s->bitcnt < need) { + if (s->incnt == s->inlen) longjmp(s->env, 1); /* out of input */ + val |= (long)(s->in[s->incnt++]) << s->bitcnt; /* load eight bits */ + s->bitcnt += 8; + } + + /* drop need bits and update buffer, always zero to seven bits left */ + s->bitbuf = (int)(val >> need); + s->bitcnt -= need; + + /* return need bits, zeroing the bits above that */ + return (int)(val & ((1L << need) - 1)); +} + +/* + * Process a stored block. + * + * Format notes: + * + * - After the two-bit stored block type (00), the stored block length and + * stored bytes are byte-aligned for fast copying. Therefore any leftover + * bits in the byte that has the last bit of the type, as many as seven, are + * discarded. The value of the discarded bits are not defined and should not + * be checked against any expectation. + * + * - The second inverted copy of the stored block length does not have to be + * checked, but it's probably a good idea to do so anyway. + * + * - A stored block can have zero length. This is sometimes used to byte-align + * subsets of the compressed data for random access or partial recovery. + */ +local int stored(struct state *s) +{ + unsigned len; /* length of stored block */ + + /* discard leftover bits from current byte (assumes s->bitcnt < 8) */ + s->bitbuf = 0; + s->bitcnt = 0; + + /* get length and check against its one's complement */ + if (s->incnt + 4 > s->inlen) return 2; /* not enough input */ + len = s->in[s->incnt++]; + len |= s->in[s->incnt++] << 8; + if (s->in[s->incnt++] != (~len & 0xff) || + s->in[s->incnt++] != ((~len >> 8) & 0xff)) + return -2; /* didn't match complement! */ + + /* copy len bytes from in to out */ + if (s->incnt + len > s->inlen) return 2; /* not enough input */ + if (s->out != NIL) { + if (s->outcnt + len > s->outlen) + return 1; /* not enough output space */ + while (len--) + s->out[s->outcnt++] = s->in[s->incnt++]; + } + else { /* just scanning */ + s->outcnt += len; + s->incnt += len; + } + + /* done with a valid stored block */ + return 0; +} + +/* + * Huffman code decoding tables. count[1..MAXBITS] is the number of symbols of + * each length, which for a canonical code are stepped through in order. + * symbol[] are the symbol values in canonical order, where the number of + * entries is the sum of the counts in count[]. The decoding process can be + * seen in the function decode() below. + */ +struct huffman { + short *count; /* number of symbols of each length */ + short *symbol; /* canonically ordered symbols */ +}; + +/* + * Decode a code from the stream s using huffman table h. Return the symbol or + * a negative value if there is an error. If all of the lengths are zero, i.e. + * an empty code, or if the code is incomplete and an invalid code is received, + * then -10 is returned after reading MAXBITS bits. + * + * Format notes: + * + * - The codes as stored in the compressed data are bit-reversed relative to + * a simple integer ordering of codes of the same lengths. Hence below the + * bits are pulled from the compressed data one at a time and used to + * build the code value reversed from what is in the stream in order to + * permit simple integer comparisons for decoding. A table-based decoding + * scheme (as used in zlib) does not need to do this reversal. + * + * - The first code for the shortest length is all zeros. Subsequent codes of + * the same length are simply integer increments of the previous code. When + * moving up a length, a zero bit is appended to the code. For a complete + * code, the last code of the longest length will be all ones. + * + * - Incomplete codes are handled by this decoder, since they are permitted + * in the deflate format. See the format notes for fixed() and dynamic(). + */ +#ifdef SLOW +local int decode(struct state *s, struct huffman *h) +{ + int len; /* current number of bits in code */ + int code; /* len bits being decoded */ + int first; /* first code of length len */ + int count; /* number of codes of length len */ + int index; /* index of first code of length len in symbol table */ + + code = first = index = 0; + for (len = 1; len <= MAXBITS; len++) { + code |= bits(s, 1); /* get next bit */ + count = h->count[len]; + if (code - count < first) /* if length len, return symbol */ + return h->symbol[index + (code - first)]; + index += count; /* else update for next length */ + first += count; + first <<= 1; + code <<= 1; + } + return -10; /* ran out of codes */ +} + +/* + * A faster version of decode() for real applications of this code. It's not + * as readable, but it makes puff() twice as fast. And it only makes the code + * a few percent larger. + */ +#else /* !SLOW */ +local int decode(struct state *s, struct huffman *h) +{ + int len; /* current number of bits in code */ + int code; /* len bits being decoded */ + int first; /* first code of length len */ + int count; /* number of codes of length len */ + int index; /* index of first code of length len in symbol table */ + int bitbuf; /* bits from stream */ + int left; /* bits left in next or left to process */ + short *next; /* next number of codes */ + + bitbuf = s->bitbuf; + left = s->bitcnt; + code = first = index = 0; + len = 1; + next = h->count + 1; + while (1) { + while (left--) { + code |= bitbuf & 1; + bitbuf >>= 1; + count = *next++; + if (code - count < first) { /* if length len, return symbol */ + s->bitbuf = bitbuf; + s->bitcnt = (s->bitcnt - len) & 7; + return h->symbol[index + (code - first)]; + } + index += count; /* else update for next length */ + first += count; + first <<= 1; + code <<= 1; + len++; + } + left = (MAXBITS+1) - len; + if (left == 0) break; + if (s->incnt == s->inlen) longjmp(s->env, 1); /* out of input */ + bitbuf = s->in[s->incnt++]; + if (left > 8) left = 8; + } + return -10; /* ran out of codes */ +} +#endif /* SLOW */ + +/* + * Given the list of code lengths length[0..n-1] representing a canonical + * Huffman code for n symbols, construct the tables required to decode those + * codes. Those tables are the number of codes of each length, and the symbols + * sorted by length, retaining their original order within each length. The + * return value is zero for a complete code set, negative for an over- + * subscribed code set, and positive for an incomplete code set. The tables + * can be used if the return value is zero or positive, but they cannot be used + * if the return value is negative. If the return value is zero, it is not + * possible for decode() using that table to return an error--any stream of + * enough bits will resolve to a symbol. If the return value is positive, then + * it is possible for decode() using that table to return an error for received + * codes past the end of the incomplete lengths. + * + * Not used by decode(), but used for error checking, h->count[0] is the number + * of the n symbols not in the code. So n - h->count[0] is the number of + * codes. This is useful for checking for incomplete codes that have more than + * one symbol, which is an error in a dynamic block. + * + * Assumption: for all i in 0..n-1, 0 <= length[i] <= MAXBITS + * This is assured by the construction of the length arrays in dynamic() and + * fixed() and is not verified by construct(). + * + * Format notes: + * + * - Permitted and expected examples of incomplete codes are one of the fixed + * codes and any code with a single symbol which in deflate is coded as one + * bit instead of zero bits. See the format notes for fixed() and dynamic(). + * + * - Within a given code length, the symbols are kept in ascending order for + * the code bits definition. + */ +local int construct(struct huffman *h, short *length, int n) +{ + int symbol; /* current symbol when stepping through length[] */ + int len; /* current length when stepping through h->count[] */ + int left; /* number of possible codes left of current length */ + short offs[MAXBITS+1]; /* offsets in symbol table for each length */ + + /* count number of codes of each length */ + for (len = 0; len <= MAXBITS; len++) + h->count[len] = 0; + for (symbol = 0; symbol < n; symbol++) + (h->count[length[symbol]])++; /* assumes lengths are within bounds */ + if (h->count[0] == n) /* no codes! */ + return 0; /* complete, but decode() will fail */ + + /* check for an over-subscribed or incomplete set of lengths */ + left = 1; /* one possible code of zero length */ + for (len = 1; len <= MAXBITS; len++) { + left <<= 1; /* one more bit, double codes left */ + left -= h->count[len]; /* deduct count from possible codes */ + if (left < 0) return left; /* over-subscribed--return negative */ + } /* left > 0 means incomplete */ + + /* generate offsets into symbol table for each length for sorting */ + offs[1] = 0; + for (len = 1; len < MAXBITS; len++) + offs[len + 1] = offs[len] + h->count[len]; + + /* + * put symbols in table sorted by length, by symbol order within each + * length + */ + for (symbol = 0; symbol < n; symbol++) + if (length[symbol] != 0) + h->symbol[offs[length[symbol]]++] = symbol; + + /* return zero for complete set, positive for incomplete set */ + return left; +} + +/* + * Decode literal/length and distance codes until an end-of-block code. + * + * Format notes: + * + * - Compressed data that is after the block type if fixed or after the code + * description if dynamic is a combination of literals and length/distance + * pairs terminated by and end-of-block code. Literals are simply Huffman + * coded bytes. A length/distance pair is a coded length followed by a + * coded distance to represent a string that occurs earlier in the + * uncompressed data that occurs again at the current location. + * + * - Literals, lengths, and the end-of-block code are combined into a single + * code of up to 286 symbols. They are 256 literals (0..255), 29 length + * symbols (257..285), and the end-of-block symbol (256). + * + * - There are 256 possible lengths (3..258), and so 29 symbols are not enough + * to represent all of those. Lengths 3..10 and 258 are in fact represented + * by just a length symbol. Lengths 11..257 are represented as a symbol and + * some number of extra bits that are added as an integer to the base length + * of the length symbol. The number of extra bits is determined by the base + * length symbol. These are in the static arrays below, lens[] for the base + * lengths and lext[] for the corresponding number of extra bits. + * + * - The reason that 258 gets its own symbol is that the longest length is used + * often in highly redundant files. Note that 258 can also be coded as the + * base value 227 plus the maximum extra value of 31. While a good deflate + * should never do this, it is not an error, and should be decoded properly. + * + * - If a length is decoded, including its extra bits if any, then it is + * followed a distance code. There are up to 30 distance symbols. Again + * there are many more possible distances (1..32768), so extra bits are added + * to a base value represented by the symbol. The distances 1..4 get their + * own symbol, but the rest require extra bits. The base distances and + * corresponding number of extra bits are below in the static arrays dist[] + * and dext[]. + * + * - Literal bytes are simply written to the output. A length/distance pair is + * an instruction to copy previously uncompressed bytes to the output. The + * copy is from distance bytes back in the output stream, copying for length + * bytes. + * + * - Distances pointing before the beginning of the output data are not + * permitted. + * + * - Overlapped copies, where the length is greater than the distance, are + * allowed and common. For example, a distance of one and a length of 258 + * simply copies the last byte 258 times. A distance of four and a length of + * twelve copies the last four bytes three times. A simple forward copy + * ignoring whether the length is greater than the distance or not implements + * this correctly. You should not use memcpy() since its behavior is not + * defined for overlapped arrays. You should not use memmove() or bcopy() + * since though their behavior -is- defined for overlapping arrays, it is + * defined to do the wrong thing in this case. + */ +local int codes(struct state *s, + struct huffman *lencode, + struct huffman *distcode) +{ + int symbol; /* decoded symbol */ + int len; /* length for copy */ + unsigned dist; /* distance for copy */ + static const short lens[29] = { /* Size base for length codes 257..285 */ + 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, + 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258}; + static const short lext[29] = { /* Extra bits for length codes 257..285 */ + 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, + 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0}; + static const short dists[30] = { /* Offset base for distance codes 0..29 */ + 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, + 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, + 8193, 12289, 16385, 24577}; + static const short dext[30] = { /* Extra bits for distance codes 0..29 */ + 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, + 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, + 12, 12, 13, 13}; + + /* decode literals and length/distance pairs */ + do { + symbol = decode(s, lencode); + if (symbol < 0) return symbol; /* invalid symbol */ + if (symbol < 256) { /* literal: symbol is the byte */ + /* write out the literal */ + if (s->out != NIL) { + if (s->outcnt == s->outlen) return 1; + s->out[s->outcnt] = symbol; + } + s->outcnt++; + } + else if (symbol > 256) { /* length */ + /* get and compute length */ + symbol -= 257; + if (symbol >= 29) return -10; /* invalid fixed code */ + len = lens[symbol] + bits(s, lext[symbol]); + + /* get and check distance */ + symbol = decode(s, distcode); + if (symbol < 0) return symbol; /* invalid symbol */ + dist = dists[symbol] + bits(s, dext[symbol]); +#ifndef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR + if (dist > s->outcnt) + return -11; /* distance too far back */ +#endif + + /* copy length bytes from distance bytes back */ + if (s->out != NIL) { + if (s->outcnt + len > s->outlen) return 1; + while (len--) { + s->out[s->outcnt] = +#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR + dist > s->outcnt ? 0 : +#endif + s->out[s->outcnt - dist]; + s->outcnt++; + } + } + else + s->outcnt += len; + } + } while (symbol != 256); /* end of block symbol */ + + /* done with a valid fixed or dynamic block */ + return 0; +} + +/* + * Process a fixed codes block. + * + * Format notes: + * + * - This block type can be useful for compressing small amounts of data for + * which the size of the code descriptions in a dynamic block exceeds the + * benefit of custom codes for that block. For fixed codes, no bits are + * spent on code descriptions. Instead the code lengths for literal/length + * codes and distance codes are fixed. The specific lengths for each symbol + * can be seen in the "for" loops below. + * + * - The literal/length code is complete, but has two symbols that are invalid + * and should result in an error if received. This cannot be implemented + * simply as an incomplete code since those two symbols are in the "middle" + * of the code. They are eight bits long and the longest literal/length\ + * code is nine bits. Therefore the code must be constructed with those + * symbols, and the invalid symbols must be detected after decoding. + * + * - The fixed distance codes also have two invalid symbols that should result + * in an error if received. Since all of the distance codes are the same + * length, this can be implemented as an incomplete code. Then the invalid + * codes are detected while decoding. + */ +local int fixed(struct state *s) +{ + static int virgin = 1; + static short lencnt[MAXBITS+1], lensym[FIXLCODES]; + static short distcnt[MAXBITS+1], distsym[MAXDCODES]; + static struct huffman lencode, distcode; + + /* build fixed huffman tables if first call (may not be thread safe) */ + if (virgin) { + int symbol; + short lengths[FIXLCODES]; + + /* literal/length table */ + for (symbol = 0; symbol < 144; symbol++) + lengths[symbol] = 8; + for (; symbol < 256; symbol++) + lengths[symbol] = 9; + for (; symbol < 280; symbol++) + lengths[symbol] = 7; + for (; symbol < FIXLCODES; symbol++) + lengths[symbol] = 8; + construct(&lencode, lengths, FIXLCODES); + + /* distance table */ + for (symbol = 0; symbol < MAXDCODES; symbol++) + lengths[symbol] = 5; + construct(&distcode, lengths, MAXDCODES); + + /* construct lencode and distcode */ + lencode.count = lencnt; + lencode.symbol = lensym; + distcode.count = distcnt; + distcode.symbol = distsym; + + /* do this just once */ + virgin = 0; + } + + /* decode data until end-of-block code */ + return codes(s, &lencode, &distcode); +} + +/* + * Process a dynamic codes block. + * + * Format notes: + * + * - A dynamic block starts with a description of the literal/length and + * distance codes for that block. New dynamic blocks allow the compressor to + * rapidly adapt to changing data with new codes optimized for that data. + * + * - The codes used by the deflate format are "canonical", which means that + * the actual bits of the codes are generated in an unambiguous way simply + * from the number of bits in each code. Therefore the code descriptions + * are simply a list of code lengths for each symbol. + * + * - The code lengths are stored in order for the symbols, so lengths are + * provided for each of the literal/length symbols, and for each of the + * distance symbols. + * + * - If a symbol is not used in the block, this is represented by a zero as + * as the code length. This does not mean a zero-length code, but rather + * that no code should be created for this symbol. There is no way in the + * deflate format to represent a zero-length code. + * + * - The maximum number of bits in a code is 15, so the possible lengths for + * any code are 1..15. + * + * - The fact that a length of zero is not permitted for a code has an + * interesting consequence. Normally if only one symbol is used for a given + * code, then in fact that code could be represented with zero bits. However + * in deflate, that code has to be at least one bit. So for example, if + * only a single distance base symbol appears in a block, then it will be + * represented by a single code of length one, in particular one 0 bit. This + * is an incomplete code, since if a 1 bit is received, it has no meaning, + * and should result in an error. So incomplete distance codes of one symbol + * should be permitted, and the receipt of invalid codes should be handled. + * + * - It is also possible to have a single literal/length code, but that code + * must be the end-of-block code, since every dynamic block has one. This + * is not the most efficient way to create an empty block (an empty fixed + * block is fewer bits), but it is allowed by the format. So incomplete + * literal/length codes of one symbol should also be permitted. + * + * - If there are only literal codes and no lengths, then there are no distance + * codes. This is represented by one distance code with zero bits. + * + * - The list of up to 286 length/literal lengths and up to 30 distance lengths + * are themselves compressed using Huffman codes and run-length encoding. In + * the list of code lengths, a 0 symbol means no code, a 1..15 symbol means + * that length, and the symbols 16, 17, and 18 are run-length instructions. + * Each of 16, 17, and 18 are follwed by extra bits to define the length of + * the run. 16 copies the last length 3 to 6 times. 17 represents 3 to 10 + * zero lengths, and 18 represents 11 to 138 zero lengths. Unused symbols + * are common, hence the special coding for zero lengths. + * + * - The symbols for 0..18 are Huffman coded, and so that code must be + * described first. This is simply a sequence of up to 19 three-bit values + * representing no code (0) or the code length for that symbol (1..7). + * + * - A dynamic block starts with three fixed-size counts from which is computed + * the number of literal/length code lengths, the number of distance code + * lengths, and the number of code length code lengths (ok, you come up with + * a better name!) in the code descriptions. For the literal/length and + * distance codes, lengths after those provided are considered zero, i.e. no + * code. The code length code lengths are received in a permuted order (see + * the order[] array below) to make a short code length code length list more + * likely. As it turns out, very short and very long codes are less likely + * to be seen in a dynamic code description, hence what may appear initially + * to be a peculiar ordering. + * + * - Given the number of literal/length code lengths (nlen) and distance code + * lengths (ndist), then they are treated as one long list of nlen + ndist + * code lengths. Therefore run-length coding can and often does cross the + * boundary between the two sets of lengths. + * + * - So to summarize, the code description at the start of a dynamic block is + * three counts for the number of code lengths for the literal/length codes, + * the distance codes, and the code length codes. This is followed by the + * code length code lengths, three bits each. This is used to construct the + * code length code which is used to read the remainder of the lengths. Then + * the literal/length code lengths and distance lengths are read as a single + * set of lengths using the code length codes. Codes are constructed from + * the resulting two sets of lengths, and then finally you can start + * decoding actual compressed data in the block. + * + * - For reference, a "typical" size for the code description in a dynamic + * block is around 80 bytes. + */ +local int dynamic(struct state *s) +{ + int nlen, ndist, ncode; /* number of lengths in descriptor */ + int index; /* index of lengths[] */ + int err; /* construct() return value */ + short lengths[MAXCODES]; /* descriptor code lengths */ + short lencnt[MAXBITS+1], lensym[MAXLCODES]; /* lencode memory */ + short distcnt[MAXBITS+1], distsym[MAXDCODES]; /* distcode memory */ + struct huffman lencode, distcode; /* length and distance codes */ + static const short order[19] = /* permutation of code length codes */ + {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; + + /* construct lencode and distcode */ + lencode.count = lencnt; + lencode.symbol = lensym; + distcode.count = distcnt; + distcode.symbol = distsym; + + /* get number of lengths in each table, check lengths */ + nlen = bits(s, 5) + 257; + ndist = bits(s, 5) + 1; + ncode = bits(s, 4) + 4; + if (nlen > MAXLCODES || ndist > MAXDCODES) + return -3; /* bad counts */ + + /* read code length code lengths (really), missing lengths are zero */ + for (index = 0; index < ncode; index++) + lengths[order[index]] = bits(s, 3); + for (; index < 19; index++) + lengths[order[index]] = 0; + + /* build huffman table for code lengths codes (use lencode temporarily) */ + err = construct(&lencode, lengths, 19); + if (err != 0) return -4; /* require complete code set here */ + + /* read length/literal and distance code length tables */ + index = 0; + while (index < nlen + ndist) { + int symbol; /* decoded value */ + int len; /* last length to repeat */ + + symbol = decode(s, &lencode); + if (symbol < 16) /* length in 0..15 */ + lengths[index++] = symbol; + else { /* repeat instruction */ + len = 0; /* assume repeating zeros */ + if (symbol == 16) { /* repeat last length 3..6 times */ + if (index == 0) return -5; /* no last length! */ + len = lengths[index - 1]; /* last length */ + symbol = 3 + bits(s, 2); + } + else if (symbol == 17) /* repeat zero 3..10 times */ + symbol = 3 + bits(s, 3); + else /* == 18, repeat zero 11..138 times */ + symbol = 11 + bits(s, 7); + if (index + symbol > nlen + ndist) + return -6; /* too many lengths! */ + while (symbol--) /* repeat last or zero symbol times */ + lengths[index++] = len; + } + } + + /* check for end-of-block code -- there better be one! */ + if (lengths[256] == 0) + return -9; + + /* build huffman table for literal/length codes */ + err = construct(&lencode, lengths, nlen); + if (err < 0 || (err > 0 && nlen - lencode.count[0] != 1)) + return -7; /* only allow incomplete codes if just one code */ + + /* build huffman table for distance codes */ + err = construct(&distcode, lengths + nlen, ndist); + if (err < 0 || (err > 0 && ndist - distcode.count[0] != 1)) + return -8; /* only allow incomplete codes if just one code */ + + /* decode data until end-of-block code */ + return codes(s, &lencode, &distcode); +} + +/* + * Inflate source to dest. On return, destlen and sourcelen are updated to the + * size of the uncompressed data and the size of the deflate data respectively. + * On success, the return value of puff() is zero. If there is an error in the + * source data, i.e. it is not in the deflate format, then a negative value is + * returned. If there is not enough input available or there is not enough + * output space, then a positive error is returned. In that case, destlen and + * sourcelen are not updated to facilitate retrying from the beginning with the + * provision of more input data or more output space. In the case of invalid + * inflate data (a negative error), the dest and source pointers are updated to + * facilitate the debugging of deflators. + * + * puff() also has a mode to determine the size of the uncompressed output with + * no output written. For this dest must be (unsigned char *)0. In this case, + * the input value of *destlen is ignored, and on return *destlen is set to the + * size of the uncompressed output. + * + * The return codes are: + * + * 2: available inflate data did not terminate + * 1: output space exhausted before completing inflate + * 0: successful inflate + * -1: invalid block type (type == 3) + * -2: stored block length did not match one's complement + * -3: dynamic block code description: too many length or distance codes + * -4: dynamic block code description: code lengths codes incomplete + * -5: dynamic block code description: repeat lengths with no first length + * -6: dynamic block code description: repeat more than specified lengths + * -7: dynamic block code description: invalid literal/length code lengths + * -8: dynamic block code description: invalid distance code lengths + * -9: dynamic block code description: missing end-of-block code + * -10: invalid literal/length or distance code in fixed or dynamic block + * -11: distance is too far back in fixed or dynamic block + * + * Format notes: + * + * - Three bits are read for each block to determine the kind of block and + * whether or not it is the last block. Then the block is decoded and the + * process repeated if it was not the last block. + * + * - The leftover bits in the last byte of the deflate data after the last + * block (if it was a fixed or dynamic block) are undefined and have no + * expected values to check. + */ +int puff(unsigned char *dest, /* pointer to destination pointer */ + unsigned long *destlen, /* amount of output space */ + unsigned char *source, /* pointer to source data pointer */ + unsigned long *sourcelen) /* amount of input available */ +{ + struct state s; /* input/output state */ + int last, type; /* block information */ + int err; /* return value */ + + /* initialize output state */ + s.out = dest; + s.outlen = *destlen; /* ignored if dest is NIL */ + s.outcnt = 0; + + /* initialize input state */ + s.in = source; + s.inlen = *sourcelen; + s.incnt = 0; + s.bitbuf = 0; + s.bitcnt = 0; + + /* return if bits() or decode() tries to read past available input */ + if (setjmp(s.env) != 0) /* if came back here via longjmp() */ + err = 2; /* then skip do-loop, return error */ + else { + /* process blocks until last block or error */ + do { + last = bits(&s, 1); /* one if last block */ + type = bits(&s, 2); /* block type 0..3 */ + err = type == 0 ? stored(&s) : + (type == 1 ? fixed(&s) : + (type == 2 ? dynamic(&s) : + -1)); /* type == 3, invalid */ + if (err != 0) break; /* return with error */ + } while (!last); + } + + /* update the lengths and return */ + if (err <= 0) { + *destlen = s.outcnt; + *sourcelen = s.incnt; + } + return err; +} + +#ifdef TEST +/* Examples of how to use puff(). + + Usage: puff [-w] [-nnn] file + ... | puff [-w] [-nnn] + + where file is the input file with deflate data, nnn is the number of bytes + of input to skip before inflating (e.g. to skip a zlib or gzip header), and + -w is used to write the decompressed data to stdout */ + +#include +#include + +/* Return size times approximately the cube root of 2, keeping the result as 1, + 3, or 5 times a power of 2 -- the result is always > size, until the result + is the maximum value of an unsigned long, where it remains. This is useful + to keep reallocations less than ~33% over the actual data. */ +local size_t bythirds(size_t size) +{ + int n; + size_t m; + + m = size; + for (n = 0; m; n++) + m >>= 1; + if (n < 3) + return size + 1; + n -= 3; + m = size >> n; + m += m == 6 ? 2 : 1; + m <<= n; + return m > size ? m : (size_t)(-1); +} + +/* Read the input file *name, or stdin if name is NULL, into allocated memory. + Reallocate to larger buffers until the entire file is read in. Return a + pointer to the allocated data, or NULL if there was a memory allocation + failure. *len is the number of bytes of data read from the input file (even + if load() returns NULL). If the input file was empty or could not be opened + or read, *len is zero. */ +local void *load(char *name, size_t *len) +{ + size_t size; + void *buf, *swap; + FILE *in; + + *len = 0; + buf = malloc(size = 4096); + if (buf == NULL) + return NULL; + in = name == NULL ? stdin : fopen(name, "rb"); + if (in != NULL) { + for (;;) { + *len += fread((char *)buf + *len, 1, size - *len, in); + if (*len < size) break; + size = bythirds(size); + if (size == *len || (swap = realloc(buf, size)) == NULL) { + free(buf); + buf = NULL; + break; + } + buf = swap; + } + fclose(in); + } + return buf; +} + +int main(int argc, char **argv) +{ + int ret, put = 0; + unsigned skip = 0; + char *arg, *name = NULL; + unsigned char *source = NULL, *dest; + size_t len = 0; + unsigned long sourcelen, destlen; + + /* process arguments */ + while (arg = *++argv, --argc) + if (arg[0] == '-') { + if (arg[1] == 'w' && arg[2] == 0) + put = 1; + else if (arg[1] >= '0' && arg[1] <= '9') + skip = (unsigned)atoi(arg + 1); + else { + fprintf(stderr, "invalid option %s\n", arg); + return 3; + } + } + else if (name != NULL) { + fprintf(stderr, "only one file name allowed\n"); + return 3; + } + else + name = arg; + source = load(name, &len); + if (source == NULL) { + fprintf(stderr, "memory allocation failure\n"); + return 4; + } + if (len == 0) { + fprintf(stderr, "could not read %s, or it was empty\n", + name == NULL ? "" : name); + free(source); + return 3; + } + if (skip >= len) { + fprintf(stderr, "skip request of %d leaves no input\n", skip); + free(source); + return 3; + } + + /* test inflate data with offset skip */ + len -= skip; + sourcelen = (unsigned long)len; + ret = puff(NIL, &destlen, source + skip, &sourcelen); + if (ret) + fprintf(stderr, "puff() failed with return code %d\n", ret); + else { + fprintf(stderr, "puff() succeeded uncompressing %lu bytes\n", destlen); + if (sourcelen < len) fprintf(stderr, "%lu compressed bytes unused\n", + len - sourcelen); + } + + /* if requested, inflate again and write decompressd data to stdout */ + if (put) { + dest = malloc(destlen); + if (dest == NULL) { + fprintf(stderr, "memory allocation failure\n"); + free(source); + return 4; + } + puff(dest, &destlen, source + skip, &sourcelen); + fwrite(dest, 1, destlen, stdout); + free(dest); + } + + /* clean up */ + free(source); + return ret; +} +#endif diff --git a/libs/zlib/contrib/puff/puff.h b/libs/zlib/contrib/puff/puff.h new file mode 100644 index 000000000..88d1b3844 --- /dev/null +++ b/libs/zlib/contrib/puff/puff.h @@ -0,0 +1,31 @@ +/* puff.h + Copyright (C) 2002-2010 Mark Adler, all rights reserved + version 2.1, 4 Apr 2010 + + This software is provided 'as-is', without any express or implied + warranty. In no event will the author be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Mark Adler madler@alumni.caltech.edu + */ + + +/* + * See puff.c for purpose and usage. + */ +int puff(unsigned char *dest, /* pointer to destination pointer */ + unsigned long *destlen, /* amount of output space */ + unsigned char *source, /* pointer to source data pointer */ + unsigned long *sourcelen); /* amount of input available */ diff --git a/libs/zlib/contrib/puff/zeros.raw b/libs/zlib/contrib/puff/zeros.raw new file mode 100644 index 000000000..637b7be6f Binary files /dev/null and b/libs/zlib/contrib/puff/zeros.raw differ diff --git a/libs/zlib/contrib/testzlib/testzlib.c b/libs/zlib/contrib/testzlib/testzlib.c new file mode 100644 index 000000000..f559a3646 --- /dev/null +++ b/libs/zlib/contrib/testzlib/testzlib.c @@ -0,0 +1,275 @@ +#include +#include +#include + +#include "zlib.h" + + +void MyDoMinus64(LARGE_INTEGER *R,LARGE_INTEGER A,LARGE_INTEGER B) +{ + R->HighPart = A.HighPart - B.HighPart; + if (A.LowPart >= B.LowPart) + R->LowPart = A.LowPart - B.LowPart; + else + { + R->LowPart = A.LowPart - B.LowPart; + R->HighPart --; + } +} + +#ifdef _M_X64 +// see http://msdn2.microsoft.com/library/twchhe95(en-us,vs.80).aspx for __rdtsc +unsigned __int64 __rdtsc(void); +void BeginCountRdtsc(LARGE_INTEGER * pbeginTime64) +{ + // printf("rdtsc = %I64x\n",__rdtsc()); + pbeginTime64->QuadPart=__rdtsc(); +} + +LARGE_INTEGER GetResRdtsc(LARGE_INTEGER beginTime64,BOOL fComputeTimeQueryPerf) +{ + LARGE_INTEGER LIres; + unsigned _int64 res=__rdtsc()-((unsigned _int64)(beginTime64.QuadPart)); + LIres.QuadPart=res; + // printf("rdtsc = %I64x\n",__rdtsc()); + return LIres; +} +#else +#ifdef _M_IX86 +void myGetRDTSC32(LARGE_INTEGER * pbeginTime64) +{ + DWORD dwEdx,dwEax; + _asm + { + rdtsc + mov dwEax,eax + mov dwEdx,edx + } + pbeginTime64->LowPart=dwEax; + pbeginTime64->HighPart=dwEdx; +} + +void BeginCountRdtsc(LARGE_INTEGER * pbeginTime64) +{ + myGetRDTSC32(pbeginTime64); +} + +LARGE_INTEGER GetResRdtsc(LARGE_INTEGER beginTime64,BOOL fComputeTimeQueryPerf) +{ + LARGE_INTEGER LIres,endTime64; + myGetRDTSC32(&endTime64); + + LIres.LowPart=LIres.HighPart=0; + MyDoMinus64(&LIres,endTime64,beginTime64); + return LIres; +} +#else +void myGetRDTSC32(LARGE_INTEGER * pbeginTime64) +{ +} + +void BeginCountRdtsc(LARGE_INTEGER * pbeginTime64) +{ +} + +LARGE_INTEGER GetResRdtsc(LARGE_INTEGER beginTime64,BOOL fComputeTimeQueryPerf) +{ + LARGE_INTEGER lr; + lr.QuadPart=0; + return lr; +} +#endif +#endif + +void BeginCountPerfCounter(LARGE_INTEGER * pbeginTime64,BOOL fComputeTimeQueryPerf) +{ + if ((!fComputeTimeQueryPerf) || (!QueryPerformanceCounter(pbeginTime64))) + { + pbeginTime64->LowPart = GetTickCount(); + pbeginTime64->HighPart = 0; + } +} + +DWORD GetMsecSincePerfCounter(LARGE_INTEGER beginTime64,BOOL fComputeTimeQueryPerf) +{ + LARGE_INTEGER endTime64,ticksPerSecond,ticks; + DWORDLONG ticksShifted,tickSecShifted; + DWORD dwLog=16+0; + DWORD dwRet; + if ((!fComputeTimeQueryPerf) || (!QueryPerformanceCounter(&endTime64))) + dwRet = (GetTickCount() - beginTime64.LowPart)*1; + else + { + MyDoMinus64(&ticks,endTime64,beginTime64); + QueryPerformanceFrequency(&ticksPerSecond); + + + { + ticksShifted = Int64ShrlMod32(*(DWORDLONG*)&ticks,dwLog); + tickSecShifted = Int64ShrlMod32(*(DWORDLONG*)&ticksPerSecond,dwLog); + + } + + dwRet = (DWORD)((((DWORD)ticksShifted)*1000)/(DWORD)(tickSecShifted)); + dwRet *=1; + } + return dwRet; +} + +int ReadFileMemory(const char* filename,long* plFileSize,void** pFilePtr) +{ + FILE* stream; + void* ptr; + int retVal=1; + stream=fopen(filename, "rb"); + if (stream==NULL) + return 0; + + fseek(stream,0,SEEK_END); + + *plFileSize=ftell(stream); + fseek(stream,0,SEEK_SET); + ptr=malloc((*plFileSize)+1); + if (ptr==NULL) + retVal=0; + else + { + if (fread(ptr, 1, *plFileSize,stream) != (*plFileSize)) + retVal=0; + } + fclose(stream); + *pFilePtr=ptr; + return retVal; +} + +int main(int argc, char *argv[]) +{ + int BlockSizeCompress=0x8000; + int BlockSizeUncompress=0x8000; + int cprLevel=Z_DEFAULT_COMPRESSION ; + long lFileSize; + unsigned char* FilePtr; + long lBufferSizeCpr; + long lBufferSizeUncpr; + long lCompressedSize=0; + unsigned char* CprPtr; + unsigned char* UncprPtr; + long lSizeCpr,lSizeUncpr; + DWORD dwGetTick,dwMsecQP; + LARGE_INTEGER li_qp,li_rdtsc,dwResRdtsc; + + if (argc<=1) + { + printf("run TestZlib [BlockSizeCompress] [BlockSizeUncompress] [compres. level]\n"); + return 0; + } + + if (ReadFileMemory(argv[1],&lFileSize,&FilePtr)==0) + { + printf("error reading %s\n",argv[1]); + return 1; + } + else printf("file %s read, %u bytes\n",argv[1],lFileSize); + + if (argc>=3) + BlockSizeCompress=atol(argv[2]); + + if (argc>=4) + BlockSizeUncompress=atol(argv[3]); + + if (argc>=5) + cprLevel=(int)atol(argv[4]); + + lBufferSizeCpr = lFileSize + (lFileSize/0x10) + 0x200; + lBufferSizeUncpr = lBufferSizeCpr; + + CprPtr=(unsigned char*)malloc(lBufferSizeCpr + BlockSizeCompress); + + BeginCountPerfCounter(&li_qp,TRUE); + dwGetTick=GetTickCount(); + BeginCountRdtsc(&li_rdtsc); + { + z_stream zcpr; + int ret=Z_OK; + long lOrigToDo = lFileSize; + long lOrigDone = 0; + int step=0; + memset(&zcpr,0,sizeof(z_stream)); + deflateInit(&zcpr,cprLevel); + + zcpr.next_in = FilePtr; + zcpr.next_out = CprPtr; + + + do + { + long all_read_before = zcpr.total_in; + zcpr.avail_in = min(lOrigToDo,BlockSizeCompress); + zcpr.avail_out = BlockSizeCompress; + ret=deflate(&zcpr,(zcpr.avail_in==lOrigToDo) ? Z_FINISH : Z_SYNC_FLUSH); + lOrigDone += (zcpr.total_in-all_read_before); + lOrigToDo -= (zcpr.total_in-all_read_before); + step++; + } while (ret==Z_OK); + + lSizeCpr=zcpr.total_out; + deflateEnd(&zcpr); + dwGetTick=GetTickCount()-dwGetTick; + dwMsecQP=GetMsecSincePerfCounter(li_qp,TRUE); + dwResRdtsc=GetResRdtsc(li_rdtsc,TRUE); + printf("total compress size = %u, in %u step\n",lSizeCpr,step); + printf("time = %u msec = %f sec\n",dwGetTick,dwGetTick/(double)1000.); + printf("defcpr time QP = %u msec = %f sec\n",dwMsecQP,dwMsecQP/(double)1000.); + printf("defcpr result rdtsc = %I64x\n\n",dwResRdtsc.QuadPart); + } + + CprPtr=(unsigned char*)realloc(CprPtr,lSizeCpr); + UncprPtr=(unsigned char*)malloc(lBufferSizeUncpr + BlockSizeUncompress); + + BeginCountPerfCounter(&li_qp,TRUE); + dwGetTick=GetTickCount(); + BeginCountRdtsc(&li_rdtsc); + { + z_stream zcpr; + int ret=Z_OK; + long lOrigToDo = lSizeCpr; + long lOrigDone = 0; + int step=0; + memset(&zcpr,0,sizeof(z_stream)); + inflateInit(&zcpr); + + zcpr.next_in = CprPtr; + zcpr.next_out = UncprPtr; + + + do + { + long all_read_before = zcpr.total_in; + zcpr.avail_in = min(lOrigToDo,BlockSizeUncompress); + zcpr.avail_out = BlockSizeUncompress; + ret=inflate(&zcpr,Z_SYNC_FLUSH); + lOrigDone += (zcpr.total_in-all_read_before); + lOrigToDo -= (zcpr.total_in-all_read_before); + step++; + } while (ret==Z_OK); + + lSizeUncpr=zcpr.total_out; + inflateEnd(&zcpr); + dwGetTick=GetTickCount()-dwGetTick; + dwMsecQP=GetMsecSincePerfCounter(li_qp,TRUE); + dwResRdtsc=GetResRdtsc(li_rdtsc,TRUE); + printf("total uncompress size = %u, in %u step\n",lSizeUncpr,step); + printf("time = %u msec = %f sec\n",dwGetTick,dwGetTick/(double)1000.); + printf("uncpr time QP = %u msec = %f sec\n",dwMsecQP,dwMsecQP/(double)1000.); + printf("uncpr result rdtsc = %I64x\n\n",dwResRdtsc.QuadPart); + } + + if (lSizeUncpr==lFileSize) + { + if (memcmp(FilePtr,UncprPtr,lFileSize)==0) + printf("compare ok\n"); + + } + + return 0; +} diff --git a/libs/zlib/contrib/testzlib/testzlib.txt b/libs/zlib/contrib/testzlib/testzlib.txt new file mode 100644 index 000000000..e508bb22f --- /dev/null +++ b/libs/zlib/contrib/testzlib/testzlib.txt @@ -0,0 +1,10 @@ +To build testzLib with Visual Studio 2005: + +copy to a directory file from : +- root of zLib tree +- contrib/testzlib +- contrib/masmx86 +- contrib/masmx64 +- contrib/vstudio/vc7 + +and open testzlib8.sln \ No newline at end of file diff --git a/libs/zlib/contrib/untgz/Makefile b/libs/zlib/contrib/untgz/Makefile new file mode 100644 index 000000000..b54266fba --- /dev/null +++ b/libs/zlib/contrib/untgz/Makefile @@ -0,0 +1,14 @@ +CC=cc +CFLAGS=-g + +untgz: untgz.o ../../libz.a + $(CC) $(CFLAGS) -o untgz untgz.o -L../.. -lz + +untgz.o: untgz.c ../../zlib.h + $(CC) $(CFLAGS) -c -I../.. untgz.c + +../../libz.a: + cd ../..; ./configure; make + +clean: + rm -f untgz untgz.o *~ diff --git a/libs/zlib/contrib/untgz/Makefile.msc b/libs/zlib/contrib/untgz/Makefile.msc new file mode 100644 index 000000000..77b860221 --- /dev/null +++ b/libs/zlib/contrib/untgz/Makefile.msc @@ -0,0 +1,17 @@ +CC=cl +CFLAGS=-MD + +untgz.exe: untgz.obj ..\..\zlib.lib + $(CC) $(CFLAGS) untgz.obj ..\..\zlib.lib + +untgz.obj: untgz.c ..\..\zlib.h + $(CC) $(CFLAGS) -c -I..\.. untgz.c + +..\..\zlib.lib: + cd ..\.. + $(MAKE) -f win32\makefile.msc + cd contrib\untgz + +clean: + -del untgz.obj + -del untgz.exe diff --git a/libs/zlib/contrib/untgz/untgz.c b/libs/zlib/contrib/untgz/untgz.c new file mode 100644 index 000000000..2c391e598 --- /dev/null +++ b/libs/zlib/contrib/untgz/untgz.c @@ -0,0 +1,674 @@ +/* + * untgz.c -- Display contents and extract files from a gzip'd TAR file + * + * written by Pedro A. Aranda Gutierrez + * adaptation to Unix by Jean-loup Gailly + * various fixes by Cosmin Truta + */ + +#include +#include +#include +#include +#include + +#include "zlib.h" + +#ifdef unix +# include +#else +# include +# include +#endif + +#ifdef WIN32 +#include +# ifndef F_OK +# define F_OK 0 +# endif +# define mkdir(dirname,mode) _mkdir(dirname) +# ifdef _MSC_VER +# define access(path,mode) _access(path,mode) +# define chmod(path,mode) _chmod(path,mode) +# define strdup(str) _strdup(str) +# endif +#else +# include +#endif + + +/* values used in typeflag field */ + +#define REGTYPE '0' /* regular file */ +#define AREGTYPE '\0' /* regular file */ +#define LNKTYPE '1' /* link */ +#define SYMTYPE '2' /* reserved */ +#define CHRTYPE '3' /* character special */ +#define BLKTYPE '4' /* block special */ +#define DIRTYPE '5' /* directory */ +#define FIFOTYPE '6' /* FIFO special */ +#define CONTTYPE '7' /* reserved */ + +/* GNU tar extensions */ + +#define GNUTYPE_DUMPDIR 'D' /* file names from dumped directory */ +#define GNUTYPE_LONGLINK 'K' /* long link name */ +#define GNUTYPE_LONGNAME 'L' /* long file name */ +#define GNUTYPE_MULTIVOL 'M' /* continuation of file from another volume */ +#define GNUTYPE_NAMES 'N' /* file name that does not fit into main hdr */ +#define GNUTYPE_SPARSE 'S' /* sparse file */ +#define GNUTYPE_VOLHDR 'V' /* tape/volume header */ + + +/* tar header */ + +#define BLOCKSIZE 512 +#define SHORTNAMESIZE 100 + +struct tar_header +{ /* byte offset */ + char name[100]; /* 0 */ + char mode[8]; /* 100 */ + char uid[8]; /* 108 */ + char gid[8]; /* 116 */ + char size[12]; /* 124 */ + char mtime[12]; /* 136 */ + char chksum[8]; /* 148 */ + char typeflag; /* 156 */ + char linkname[100]; /* 157 */ + char magic[6]; /* 257 */ + char version[2]; /* 263 */ + char uname[32]; /* 265 */ + char gname[32]; /* 297 */ + char devmajor[8]; /* 329 */ + char devminor[8]; /* 337 */ + char prefix[155]; /* 345 */ + /* 500 */ +}; + +union tar_buffer +{ + char buffer[BLOCKSIZE]; + struct tar_header header; +}; + +struct attr_item +{ + struct attr_item *next; + char *fname; + int mode; + time_t time; +}; + +enum { TGZ_EXTRACT, TGZ_LIST, TGZ_INVALID }; + +char *TGZfname OF((const char *)); +void TGZnotfound OF((const char *)); + +int getoct OF((char *, int)); +char *strtime OF((time_t *)); +int setfiletime OF((char *, time_t)); +void push_attr OF((struct attr_item **, char *, int, time_t)); +void restore_attr OF((struct attr_item **)); + +int ExprMatch OF((char *, char *)); + +int makedir OF((char *)); +int matchname OF((int, int, char **, char *)); + +void error OF((const char *)); +int tar OF((gzFile, int, int, int, char **)); + +void help OF((int)); +int main OF((int, char **)); + +char *prog; + +const char *TGZsuffix[] = { "\0", ".tar", ".tar.gz", ".taz", ".tgz", NULL }; + +/* return the file name of the TGZ archive */ +/* or NULL if it does not exist */ + +char *TGZfname (const char *arcname) +{ + static char buffer[1024]; + int origlen,i; + + strcpy(buffer,arcname); + origlen = strlen(buffer); + + for (i=0; TGZsuffix[i]; i++) + { + strcpy(buffer+origlen,TGZsuffix[i]); + if (access(buffer,F_OK) == 0) + return buffer; + } + return NULL; +} + + +/* error message for the filename */ + +void TGZnotfound (const char *arcname) +{ + int i; + + fprintf(stderr,"%s: Couldn't find ",prog); + for (i=0;TGZsuffix[i];i++) + fprintf(stderr,(TGZsuffix[i+1]) ? "%s%s, " : "or %s%s\n", + arcname, + TGZsuffix[i]); + exit(1); +} + + +/* convert octal digits to int */ +/* on error return -1 */ + +int getoct (char *p,int width) +{ + int result = 0; + char c; + + while (width--) + { + c = *p++; + if (c == 0) + break; + if (c == ' ') + continue; + if (c < '0' || c > '7') + return -1; + result = result * 8 + (c - '0'); + } + return result; +} + + +/* convert time_t to string */ +/* use the "YYYY/MM/DD hh:mm:ss" format */ + +char *strtime (time_t *t) +{ + struct tm *local; + static char result[32]; + + local = localtime(t); + sprintf(result,"%4d/%02d/%02d %02d:%02d:%02d", + local->tm_year+1900, local->tm_mon+1, local->tm_mday, + local->tm_hour, local->tm_min, local->tm_sec); + return result; +} + + +/* set file time */ + +int setfiletime (char *fname,time_t ftime) +{ +#ifdef WIN32 + static int isWinNT = -1; + SYSTEMTIME st; + FILETIME locft, modft; + struct tm *loctm; + HANDLE hFile; + int result; + + loctm = localtime(&ftime); + if (loctm == NULL) + return -1; + + st.wYear = (WORD)loctm->tm_year + 1900; + st.wMonth = (WORD)loctm->tm_mon + 1; + st.wDayOfWeek = (WORD)loctm->tm_wday; + st.wDay = (WORD)loctm->tm_mday; + st.wHour = (WORD)loctm->tm_hour; + st.wMinute = (WORD)loctm->tm_min; + st.wSecond = (WORD)loctm->tm_sec; + st.wMilliseconds = 0; + if (!SystemTimeToFileTime(&st, &locft) || + !LocalFileTimeToFileTime(&locft, &modft)) + return -1; + + if (isWinNT < 0) + isWinNT = (GetVersion() < 0x80000000) ? 1 : 0; + hFile = CreateFile(fname, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, + (isWinNT ? FILE_FLAG_BACKUP_SEMANTICS : 0), + NULL); + if (hFile == INVALID_HANDLE_VALUE) + return -1; + result = SetFileTime(hFile, NULL, NULL, &modft) ? 0 : -1; + CloseHandle(hFile); + return result; +#else + struct utimbuf settime; + + settime.actime = settime.modtime = ftime; + return utime(fname,&settime); +#endif +} + + +/* push file attributes */ + +void push_attr(struct attr_item **list,char *fname,int mode,time_t time) +{ + struct attr_item *item; + + item = (struct attr_item *)malloc(sizeof(struct attr_item)); + if (item == NULL) + error("Out of memory"); + item->fname = strdup(fname); + item->mode = mode; + item->time = time; + item->next = *list; + *list = item; +} + + +/* restore file attributes */ + +void restore_attr(struct attr_item **list) +{ + struct attr_item *item, *prev; + + for (item = *list; item != NULL; ) + { + setfiletime(item->fname,item->time); + chmod(item->fname,item->mode); + prev = item; + item = item->next; + free(prev); + } + *list = NULL; +} + + +/* match regular expression */ + +#define ISSPECIAL(c) (((c) == '*') || ((c) == '/')) + +int ExprMatch (char *string,char *expr) +{ + while (1) + { + if (ISSPECIAL(*expr)) + { + if (*expr == '/') + { + if (*string != '\\' && *string != '/') + return 0; + string ++; expr++; + } + else if (*expr == '*') + { + if (*expr ++ == 0) + return 1; + while (*++string != *expr) + if (*string == 0) + return 0; + } + } + else + { + if (*string != *expr) + return 0; + if (*expr++ == 0) + return 1; + string++; + } + } +} + + +/* recursive mkdir */ +/* abort on ENOENT; ignore other errors like "directory already exists" */ +/* return 1 if OK */ +/* 0 on error */ + +int makedir (char *newdir) +{ + char *buffer = strdup(newdir); + char *p; + int len = strlen(buffer); + + if (len <= 0) { + free(buffer); + return 0; + } + if (buffer[len-1] == '/') { + buffer[len-1] = '\0'; + } + if (mkdir(buffer, 0755) == 0) + { + free(buffer); + return 1; + } + + p = buffer+1; + while (1) + { + char hold; + + while(*p && *p != '\\' && *p != '/') + p++; + hold = *p; + *p = 0; + if ((mkdir(buffer, 0755) == -1) && (errno == ENOENT)) + { + fprintf(stderr,"%s: Couldn't create directory %s\n",prog,buffer); + free(buffer); + return 0; + } + if (hold == 0) + break; + *p++ = hold; + } + free(buffer); + return 1; +} + + +int matchname (int arg,int argc,char **argv,char *fname) +{ + if (arg == argc) /* no arguments given (untgz tgzarchive) */ + return 1; + + while (arg < argc) + if (ExprMatch(fname,argv[arg++])) + return 1; + + return 0; /* ignore this for the moment being */ +} + + +/* tar file list or extract */ + +int tar (gzFile in,int action,int arg,int argc,char **argv) +{ + union tar_buffer buffer; + int len; + int err; + int getheader = 1; + int remaining = 0; + FILE *outfile = NULL; + char fname[BLOCKSIZE]; + int tarmode; + time_t tartime; + struct attr_item *attributes = NULL; + + if (action == TGZ_LIST) + printf(" date time size file\n" + " ---------- -------- --------- -------------------------------------\n"); + while (1) + { + len = gzread(in, &buffer, BLOCKSIZE); + if (len < 0) + error(gzerror(in, &err)); + /* + * Always expect complete blocks to process + * the tar information. + */ + if (len != BLOCKSIZE) + { + action = TGZ_INVALID; /* force error exit */ + remaining = 0; /* force I/O cleanup */ + } + + /* + * If we have to get a tar header + */ + if (getheader >= 1) + { + /* + * if we met the end of the tar + * or the end-of-tar block, + * we are done + */ + if (len == 0 || buffer.header.name[0] == 0) + break; + + tarmode = getoct(buffer.header.mode,8); + tartime = (time_t)getoct(buffer.header.mtime,12); + if (tarmode == -1 || tartime == (time_t)-1) + { + buffer.header.name[0] = 0; + action = TGZ_INVALID; + } + + if (getheader == 1) + { + strncpy(fname,buffer.header.name,SHORTNAMESIZE); + if (fname[SHORTNAMESIZE-1] != 0) + fname[SHORTNAMESIZE] = 0; + } + else + { + /* + * The file name is longer than SHORTNAMESIZE + */ + if (strncmp(fname,buffer.header.name,SHORTNAMESIZE-1) != 0) + error("bad long name"); + getheader = 1; + } + + /* + * Act according to the type flag + */ + switch (buffer.header.typeflag) + { + case DIRTYPE: + if (action == TGZ_LIST) + printf(" %s %s\n",strtime(&tartime),fname); + if (action == TGZ_EXTRACT) + { + makedir(fname); + push_attr(&attributes,fname,tarmode,tartime); + } + break; + case REGTYPE: + case AREGTYPE: + remaining = getoct(buffer.header.size,12); + if (remaining == -1) + { + action = TGZ_INVALID; + break; + } + if (action == TGZ_LIST) + printf(" %s %9d %s\n",strtime(&tartime),remaining,fname); + else if (action == TGZ_EXTRACT) + { + if (matchname(arg,argc,argv,fname)) + { + outfile = fopen(fname,"wb"); + if (outfile == NULL) { + /* try creating directory */ + char *p = strrchr(fname, '/'); + if (p != NULL) { + *p = '\0'; + makedir(fname); + *p = '/'; + outfile = fopen(fname,"wb"); + } + } + if (outfile != NULL) + printf("Extracting %s\n",fname); + else + fprintf(stderr, "%s: Couldn't create %s",prog,fname); + } + else + outfile = NULL; + } + getheader = 0; + break; + case GNUTYPE_LONGLINK: + case GNUTYPE_LONGNAME: + remaining = getoct(buffer.header.size,12); + if (remaining < 0 || remaining >= BLOCKSIZE) + { + action = TGZ_INVALID; + break; + } + len = gzread(in, fname, BLOCKSIZE); + if (len < 0) + error(gzerror(in, &err)); + if (fname[BLOCKSIZE-1] != 0 || (int)strlen(fname) > remaining) + { + action = TGZ_INVALID; + break; + } + getheader = 2; + break; + default: + if (action == TGZ_LIST) + printf(" %s <---> %s\n",strtime(&tartime),fname); + break; + } + } + else + { + unsigned int bytes = (remaining > BLOCKSIZE) ? BLOCKSIZE : remaining; + + if (outfile != NULL) + { + if (fwrite(&buffer,sizeof(char),bytes,outfile) != bytes) + { + fprintf(stderr, + "%s: Error writing %s -- skipping\n",prog,fname); + fclose(outfile); + outfile = NULL; + remove(fname); + } + } + remaining -= bytes; + } + + if (remaining == 0) + { + getheader = 1; + if (outfile != NULL) + { + fclose(outfile); + outfile = NULL; + if (action != TGZ_INVALID) + push_attr(&attributes,fname,tarmode,tartime); + } + } + + /* + * Abandon if errors are found + */ + if (action == TGZ_INVALID) + { + error("broken archive"); + break; + } + } + + /* + * Restore file modes and time stamps + */ + restore_attr(&attributes); + + if (gzclose(in) != Z_OK) + error("failed gzclose"); + + return 0; +} + + +/* ============================================================ */ + +void help(int exitval) +{ + printf("untgz version 0.2.1\n" + " using zlib version %s\n\n", + zlibVersion()); + printf("Usage: untgz file.tgz extract all files\n" + " untgz file.tgz fname ... extract selected files\n" + " untgz -l file.tgz list archive contents\n" + " untgz -h display this help\n"); + exit(exitval); +} + +void error(const char *msg) +{ + fprintf(stderr, "%s: %s\n", prog, msg); + exit(1); +} + + +/* ============================================================ */ + +#if defined(WIN32) && defined(__GNUC__) +int _CRT_glob = 0; /* disable argument globbing in MinGW */ +#endif + +int main(int argc,char **argv) +{ + int action = TGZ_EXTRACT; + int arg = 1; + char *TGZfile; + gzFile *f; + + prog = strrchr(argv[0],'\\'); + if (prog == NULL) + { + prog = strrchr(argv[0],'/'); + if (prog == NULL) + { + prog = strrchr(argv[0],':'); + if (prog == NULL) + prog = argv[0]; + else + prog++; + } + else + prog++; + } + else + prog++; + + if (argc == 1) + help(0); + + if (strcmp(argv[arg],"-l") == 0) + { + action = TGZ_LIST; + if (argc == ++arg) + help(0); + } + else if (strcmp(argv[arg],"-h") == 0) + { + help(0); + } + + if ((TGZfile = TGZfname(argv[arg])) == NULL) + TGZnotfound(argv[arg]); + + ++arg; + if ((action == TGZ_LIST) && (arg != argc)) + help(1); + +/* + * Process the TGZ file + */ + switch(action) + { + case TGZ_LIST: + case TGZ_EXTRACT: + f = gzopen(TGZfile,"rb"); + if (f == NULL) + { + fprintf(stderr,"%s: Couldn't gzopen %s\n",prog,TGZfile); + return 1; + } + exit(tar(f, action, arg, argc, argv)); + break; + + default: + error("Unknown option"); + exit(1); + } + + return 0; +} diff --git a/libs/zlib/contrib/vstudio/readme.txt b/libs/zlib/contrib/vstudio/readme.txt new file mode 100644 index 000000000..9d931f930 --- /dev/null +++ b/libs/zlib/contrib/vstudio/readme.txt @@ -0,0 +1,73 @@ +Building instructions for the DLL versions of Zlib 1.2.3 +======================================================== + +This directory contains projects that build zlib and minizip using +Microsoft Visual C++ 7.0/7.1, and Visual C++ . + +You don't need to build these projects yourself. You can download the +binaries from: + http://www.winimage.com/zLibDll + +More information can be found at this site. + + +Build instructions for Visual Studio 7.x (32 bits) +-------------------------------------------------- +- Uncompress current zlib, including all contrib/* files +- Download the crtdll library from + http://www.winimage.com/zLibDll/crtdll.zip + Unzip crtdll.zip to extract crtdll.lib on contrib\vstudio\vc7. +- Open contrib\vstudio\vc7\zlibvc.sln with Microsoft Visual C++ 7.x + (Visual Studio .Net 2002 or 2003). + +Build instructions for Visual Studio 2005 (32 bits or 64 bits) +-------------------------------------------------------------- +- Uncompress current zlib, including all contrib/* files +- For 32 bits only: download the crtdll library from + http://www.winimage.com/zLibDll/crtdll.zip + Unzip crtdll.zip to extract crtdll.lib on contrib\vstudio\vc8. +- Open contrib\vstudio\vc8\zlibvc.sln with Microsoft Visual C++ 8.0 + +Build instructions for Visual Studio 2005 64 bits, PSDK compiler +---------------------------------------------------------------- +at the time of writing this text file, Visual Studio 2005 (and + Microsoft Visual C++ 8.0) is on the beta 2 stage. +Using you can get the free 64 bits compiler from Platform SDK, + which is NOT a beta, and compile using the Visual studio 2005 IDE +see http://www.winimage.com/misc/sdk64onvs2005/ for instruction + +- Uncompress current zlib, including all contrib/* files +- start Visual Studio 2005 from a platform SDK command prompt, using + the /useenv switch +- Open contrib\vstudio\vc8\zlibvc.sln with Microsoft Visual C++ 8.0 + + +Important +--------- +- To use zlibwapi.dll in your application, you must define the + macro ZLIB_WINAPI when compiling your application's source files. + + +Additional notes +---------------- +- This DLL, named zlibwapi.dll, is compatible to the old zlib.dll built + by Gilles Vollant from the zlib 1.1.x sources, and distributed at + http://www.winimage.com/zLibDll + It uses the WINAPI calling convention for the exported functions, and + includes the minizip functionality. If your application needs that + particular build of zlib.dll, you can rename zlibwapi.dll to zlib.dll. + +- The new DLL was renamed because there exist several incompatible + versions of zlib.dll on the Internet. + +- There is also an official DLL build of zlib, named zlib1.dll. This one + is exporting the functions using the CDECL convention. See the file + win32\DLL_FAQ.txt found in this zlib distribution. + +- There used to be a ZLIB_DLL macro in zlib 1.1.x, but now this symbol + has a slightly different effect. To avoid compatibility problems, do + not define it here. + + +Gilles Vollant +info@winimage.com diff --git a/libs/zlib/contrib/vstudio/vc10/miniunz.vcxproj b/libs/zlib/contrib/vstudio/vc10/miniunz.vcxproj new file mode 100644 index 000000000..74e15c90d --- /dev/null +++ b/libs/zlib/contrib/vstudio/vc10/miniunz.vcxproj @@ -0,0 +1,310 @@ + + + + + Debug + Itanium + + + Debug + Win32 + + + Debug + x64 + + + Release + Itanium + + + Release + Win32 + + + Release + x64 + + + + {C52F9E7B-498A-42BE-8DB4-85A15694382A} + Win32Proj + + + + Application + MultiByte + + + Application + MultiByte + + + Application + MultiByte + + + Application + MultiByte + + + Application + MultiByte + + + Application + MultiByte + + + + + + + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>10.0.30128.1 + x86\MiniUnzip$(Configuration)\ + x86\MiniUnzip$(Configuration)\Tmp\ + true + false + x86\MiniUnzip$(Configuration)\ + x86\MiniUnzip$(Configuration)\Tmp\ + false + false + x64\MiniUnzip$(Configuration)\ + x64\MiniUnzip$(Configuration)\Tmp\ + true + false + ia64\MiniUnzip$(Configuration)\ + ia64\MiniUnzip$(Configuration)\Tmp\ + true + false + x64\MiniUnzip$(Configuration)\ + x64\MiniUnzip$(Configuration)\Tmp\ + false + false + ia64\MiniUnzip$(Configuration)\ + ia64\MiniUnzip$(Configuration)\Tmp\ + false + false + AllRules.ruleset + + + AllRules.ruleset + + + AllRules.ruleset + + + AllRules.ruleset + + + AllRules.ruleset + + + AllRules.ruleset + + + + + + Disabled + ..\..\..;..\..\minizip;%(AdditionalIncludeDirectories) + WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + Default + MultiThreadedDebug + false + + + $(IntDir) + Level3 + EditAndContinue + + + x86\ZlibDllDebug\zlibwapi.lib;%(AdditionalDependencies) + $(OutDir)miniunz.exe + true + $(OutDir)miniunz.pdb + Console + false + + + MachineX86 + + + + + MaxSpeed + OnlyExplicitInline + true + ..\..\..;..\..\minizip;%(AdditionalIncludeDirectories) + WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + Default + MultiThreaded + false + true + + + $(IntDir) + Level3 + ProgramDatabase + + + x86\ZlibDllRelease\zlibwapi.lib;%(AdditionalDependencies) + $(OutDir)miniunz.exe + true + Console + true + true + false + + + MachineX86 + + + + + X64 + + + Disabled + ..\..\..;..\..\minizip;%(AdditionalIncludeDirectories) + _CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_CONSOLE;WIN64;%(PreprocessorDefinitions) + true + Default + MultiThreadedDebugDLL + false + + + $(IntDir) + Level3 + ProgramDatabase + + + x64\ZlibDllDebug\zlibwapi.lib;%(AdditionalDependencies) + $(OutDir)miniunz.exe + true + $(OutDir)miniunz.pdb + Console + MachineX64 + + + + + Itanium + + + Disabled + ..\..\..;..\..\minizip;%(AdditionalIncludeDirectories) + _CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_CONSOLE;WIN64;%(PreprocessorDefinitions) + true + Default + MultiThreadedDebugDLL + false + + + $(IntDir) + Level3 + ProgramDatabase + + + ia64\ZlibDllDebug\zlibwapi.lib;%(AdditionalDependencies) + $(OutDir)miniunz.exe + true + $(OutDir)miniunz.pdb + Console + MachineIA64 + + + + + X64 + + + MaxSpeed + OnlyExplicitInline + true + ..\..\..;..\..\minizip;%(AdditionalIncludeDirectories) + _CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;NDEBUG;_CONSOLE;WIN64;%(PreprocessorDefinitions) + true + Default + MultiThreadedDLL + false + true + + + $(IntDir) + Level3 + ProgramDatabase + + + x64\ZlibDllRelease\zlibwapi.lib;%(AdditionalDependencies) + $(OutDir)miniunz.exe + true + Console + true + true + MachineX64 + + + + + Itanium + + + MaxSpeed + OnlyExplicitInline + true + ..\..\..;..\..\minizip;%(AdditionalIncludeDirectories) + _CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;NDEBUG;_CONSOLE;WIN64;%(PreprocessorDefinitions) + true + Default + MultiThreadedDLL + false + true + + + $(IntDir) + Level3 + ProgramDatabase + + + ia64\ZlibDllRelease\zlibwapi.lib;%(AdditionalDependencies) + $(OutDir)miniunz.exe + true + Console + true + true + MachineIA64 + + + + + + + + {8fd826f8-3739-44e6-8cc8-997122e53b8d} + + + + + + \ No newline at end of file diff --git a/libs/zlib/contrib/vstudio/vc10/miniunz.vcxproj.filters b/libs/zlib/contrib/vstudio/vc10/miniunz.vcxproj.filters new file mode 100644 index 000000000..0b2a3de2d --- /dev/null +++ b/libs/zlib/contrib/vstudio/vc10/miniunz.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {048af943-022b-4db6-beeb-a54c34774ee2} + cpp;c;cxx;def;odl;idl;hpj;bat;asm + + + {c1d600d2-888f-4aea-b73e-8b0dd9befa0c} + h;hpp;hxx;hm;inl;inc + + + {0844199a-966b-4f19-81db-1e0125e141b9} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe + + + + + Source Files + + + \ No newline at end of file diff --git a/libs/zlib/contrib/vstudio/vc10/miniunz.vcxproj.user b/libs/zlib/contrib/vstudio/vc10/miniunz.vcxproj.user new file mode 100644 index 000000000..695b5c78b --- /dev/null +++ b/libs/zlib/contrib/vstudio/vc10/miniunz.vcxproj.user @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/libs/zlib/contrib/vstudio/vc10/minizip.vcxproj b/libs/zlib/contrib/vstudio/vc10/minizip.vcxproj new file mode 100644 index 000000000..917e15652 --- /dev/null +++ b/libs/zlib/contrib/vstudio/vc10/minizip.vcxproj @@ -0,0 +1,307 @@ + + + + + Debug + Itanium + + + Debug + Win32 + + + Debug + x64 + + + Release + Itanium + + + Release + Win32 + + + Release + x64 + + + + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B} + Win32Proj + + + + Application + MultiByte + + + Application + MultiByte + + + Application + MultiByte + + + Application + MultiByte + + + Application + MultiByte + + + Application + MultiByte + + + + + + + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>10.0.30128.1 + x86\MiniZip$(Configuration)\ + x86\MiniZip$(Configuration)\Tmp\ + true + false + x86\MiniZip$(Configuration)\ + x86\MiniZip$(Configuration)\Tmp\ + false + x64\$(Configuration)\ + x64\$(Configuration)\ + true + false + ia64\$(Configuration)\ + ia64\$(Configuration)\ + true + false + x64\$(Configuration)\ + x64\$(Configuration)\ + false + ia64\$(Configuration)\ + ia64\$(Configuration)\ + false + AllRules.ruleset + + + AllRules.ruleset + + + AllRules.ruleset + + + AllRules.ruleset + + + AllRules.ruleset + + + AllRules.ruleset + + + + + + Disabled + ..\..\..;..\..\minizip;%(AdditionalIncludeDirectories) + WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + Default + MultiThreadedDebug + false + + + $(IntDir) + Level3 + EditAndContinue + + + x86\ZlibDllDebug\zlibwapi.lib;%(AdditionalDependencies) + $(OutDir)minizip.exe + true + $(OutDir)minizip.pdb + Console + false + + + MachineX86 + + + + + MaxSpeed + OnlyExplicitInline + true + ..\..\..;..\..\minizip;%(AdditionalIncludeDirectories) + WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + Default + MultiThreaded + false + true + + + $(IntDir) + Level3 + ProgramDatabase + + + x86\ZlibDllRelease\zlibwapi.lib;%(AdditionalDependencies) + $(OutDir)minizip.exe + true + Console + true + true + false + + + MachineX86 + + + + + X64 + + + Disabled + ..\..\..;..\..\minizip;%(AdditionalIncludeDirectories) + _CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_CONSOLE;WIN64;%(PreprocessorDefinitions) + true + Default + MultiThreadedDebugDLL + false + + + $(IntDir) + Level3 + ProgramDatabase + + + x64\ZlibDllDebug\zlibwapi.lib;%(AdditionalDependencies) + $(OutDir)minizip.exe + true + $(OutDir)minizip.pdb + Console + MachineX64 + + + + + Itanium + + + Disabled + ..\..\..;..\..\minizip;%(AdditionalIncludeDirectories) + _CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_CONSOLE;WIN64;%(PreprocessorDefinitions) + true + Default + MultiThreadedDebugDLL + false + + + $(IntDir) + Level3 + ProgramDatabase + + + ia64\ZlibDllDebug\zlibwapi.lib;%(AdditionalDependencies) + $(OutDir)minizip.exe + true + $(OutDir)minizip.pdb + Console + MachineIA64 + + + + + X64 + + + MaxSpeed + OnlyExplicitInline + true + ..\..\..;..\..\minizip;%(AdditionalIncludeDirectories) + _CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;NDEBUG;_CONSOLE;WIN64;%(PreprocessorDefinitions) + true + Default + MultiThreadedDLL + false + true + + + $(IntDir) + Level3 + ProgramDatabase + + + x64\ZlibDllRelease\zlibwapi.lib;%(AdditionalDependencies) + $(OutDir)minizip.exe + true + Console + true + true + MachineX64 + + + + + Itanium + + + MaxSpeed + OnlyExplicitInline + true + ..\..\..;..\..\minizip;%(AdditionalIncludeDirectories) + _CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;NDEBUG;_CONSOLE;WIN64;%(PreprocessorDefinitions) + true + Default + MultiThreadedDLL + false + true + + + $(IntDir) + Level3 + ProgramDatabase + + + ia64\ZlibDllRelease\zlibwapi.lib;%(AdditionalDependencies) + $(OutDir)minizip.exe + true + Console + true + true + MachineIA64 + + + + + + + + {8fd826f8-3739-44e6-8cc8-997122e53b8d} + + + + + + \ No newline at end of file diff --git a/libs/zlib/contrib/vstudio/vc10/minizip.vcxproj.filters b/libs/zlib/contrib/vstudio/vc10/minizip.vcxproj.filters new file mode 100644 index 000000000..dd73cd313 --- /dev/null +++ b/libs/zlib/contrib/vstudio/vc10/minizip.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {c0419b40-bf50-40da-b153-ff74215b79de} + cpp;c;cxx;def;odl;idl;hpj;bat;asm + + + {bb87b070-735b-478e-92ce-7383abb2f36c} + h;hpp;hxx;hm;inl;inc + + + {f46ab6a6-548f-43cb-ae96-681abb5bd5db} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe + + + + + Source Files + + + \ No newline at end of file diff --git a/libs/zlib/contrib/vstudio/vc10/minizip.vcxproj.user b/libs/zlib/contrib/vstudio/vc10/minizip.vcxproj.user new file mode 100644 index 000000000..695b5c78b --- /dev/null +++ b/libs/zlib/contrib/vstudio/vc10/minizip.vcxproj.user @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/libs/zlib/contrib/vstudio/vc10/testzlib.vcxproj b/libs/zlib/contrib/vstudio/vc10/testzlib.vcxproj new file mode 100644 index 000000000..9088d176f --- /dev/null +++ b/libs/zlib/contrib/vstudio/vc10/testzlib.vcxproj @@ -0,0 +1,420 @@ + + + + + Debug + Itanium + + + Debug + Win32 + + + Debug + x64 + + + ReleaseWithoutAsm + Itanium + + + ReleaseWithoutAsm + Win32 + + + ReleaseWithoutAsm + x64 + + + Release + Itanium + + + Release + Win32 + + + Release + x64 + + + + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B} + testzlib + Win32Proj + + + + Application + MultiByte + true + + + Application + MultiByte + true + + + Application + MultiByte + + + Application + MultiByte + true + + + Application + MultiByte + true + + + Application + MultiByte + + + Application + true + + + Application + true + + + Application + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>10.0.30128.1 + x86\TestZlib$(Configuration)\ + x86\TestZlib$(Configuration)\Tmp\ + true + false + x86\TestZlib$(Configuration)\ + x86\TestZlib$(Configuration)\Tmp\ + false + false + x86\TestZlib$(Configuration)\ + x86\TestZlib$(Configuration)\Tmp\ + false + false + x64\TestZlib$(Configuration)\ + x64\TestZlib$(Configuration)\Tmp\ + false + ia64\TestZlib$(Configuration)\ + ia64\TestZlib$(Configuration)\Tmp\ + true + false + x64\TestZlib$(Configuration)\ + x64\TestZlib$(Configuration)\Tmp\ + false + ia64\TestZlib$(Configuration)\ + ia64\TestZlib$(Configuration)\Tmp\ + false + false + x64\TestZlib$(Configuration)\ + x64\TestZlib$(Configuration)\Tmp\ + false + ia64\TestZlib$(Configuration)\ + ia64\TestZlib$(Configuration)\Tmp\ + false + false + AllRules.ruleset + + + AllRules.ruleset + + + AllRules.ruleset + + + AllRules.ruleset + + + AllRules.ruleset + + + AllRules.ruleset + + + AllRules.ruleset + + + AllRules.ruleset + + + AllRules.ruleset + + + + + + Disabled + ..\..\..;%(AdditionalIncludeDirectories) + ASMV;ASMINF;WIN32;ZLIB_WINAPI;_DEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;%(PreprocessorDefinitions) + true + Default + MultiThreadedDebug + false + + + AssemblyAndSourceCode + $(IntDir) + Level3 + EditAndContinue + + + ..\..\masmx86\match686.obj;..\..\masmx86\inffas32.obj;%(AdditionalDependencies) + $(OutDir)testzlib.exe + true + $(OutDir)testzlib.pdb + Console + false + + + MachineX86 + + + + + MaxSpeed + OnlyExplicitInline + true + ..\..\..;%(AdditionalIncludeDirectories) + WIN32;ZLIB_WINAPI;NDEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;%(PreprocessorDefinitions) + true + Default + MultiThreaded + false + true + + + $(IntDir) + Level3 + ProgramDatabase + + + $(OutDir)testzlib.exe + true + Console + true + true + false + + + MachineX86 + + + + + MaxSpeed + OnlyExplicitInline + true + ..\..\..;%(AdditionalIncludeDirectories) + ASMV;ASMINF;WIN32;ZLIB_WINAPI;NDEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;%(PreprocessorDefinitions) + true + Default + MultiThreaded + false + true + + + $(IntDir) + Level3 + ProgramDatabase + + + ..\..\masmx86\match686.obj;..\..\masmx86\inffas32.obj;%(AdditionalDependencies) + $(OutDir)testzlib.exe + true + Console + true + true + false + + + MachineX86 + + + + + ..\..\..;%(AdditionalIncludeDirectories) + ASMV;ASMINF;WIN32;ZLIB_WINAPI;_DEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;%(PreprocessorDefinitions) + Default + MultiThreadedDebugDLL + false + $(IntDir) + + + ..\..\masmx64\gvmat64.obj;..\..\masmx64\inffasx64.obj;%(AdditionalDependencies) + + + + + Itanium + + + Disabled + ..\..\..;%(AdditionalIncludeDirectories) + ZLIB_WINAPI;_DEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;WIN64;%(PreprocessorDefinitions) + true + Default + MultiThreadedDebugDLL + false + + + AssemblyAndSourceCode + $(IntDir) + Level3 + ProgramDatabase + + + $(OutDir)testzlib.exe + true + $(OutDir)testzlib.pdb + Console + MachineIA64 + + + + + ..\..\..;%(AdditionalIncludeDirectories) + WIN32;ZLIB_WINAPI;NDEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;%(PreprocessorDefinitions) + Default + MultiThreadedDLL + false + $(IntDir) + + + %(AdditionalDependencies) + + + + + Itanium + + + MaxSpeed + OnlyExplicitInline + true + ..\..\..;%(AdditionalIncludeDirectories) + ZLIB_WINAPI;NDEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;WIN64;%(PreprocessorDefinitions) + true + Default + MultiThreadedDLL + false + true + + + $(IntDir) + Level3 + ProgramDatabase + + + $(OutDir)testzlib.exe + true + Console + true + true + MachineIA64 + + + + + ..\..\..;%(AdditionalIncludeDirectories) + ASMV;ASMINF;WIN32;ZLIB_WINAPI;NDEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;%(PreprocessorDefinitions) + Default + MultiThreadedDLL + false + $(IntDir) + + + ..\..\masmx64\gvmat64.obj;..\..\masmx64\inffasx64.obj;%(AdditionalDependencies) + + + + + Itanium + + + MaxSpeed + OnlyExplicitInline + true + ..\..\..;%(AdditionalIncludeDirectories) + ZLIB_WINAPI;NDEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;WIN64;%(PreprocessorDefinitions) + true + Default + MultiThreadedDLL + false + true + + + $(IntDir) + Level3 + ProgramDatabase + + + $(OutDir)testzlib.exe + true + Console + true + true + MachineIA64 + + + + + + + + + + true + true + true + true + true + true + + + + + + + + + + + + + \ No newline at end of file diff --git a/libs/zlib/contrib/vstudio/vc10/testzlib.vcxproj.filters b/libs/zlib/contrib/vstudio/vc10/testzlib.vcxproj.filters new file mode 100644 index 000000000..249daa89c --- /dev/null +++ b/libs/zlib/contrib/vstudio/vc10/testzlib.vcxproj.filters @@ -0,0 +1,58 @@ + + + + + {c1f6a2e3-5da5-4955-8653-310d3efe05a9} + cpp;c;cxx;def;odl;idl;hpj;bat;asm + + + {c2aaffdc-2c95-4d6f-8466-4bec5890af2c} + h;hpp;hxx;hm;inl;inc + + + {c274fe07-05f2-461c-964b-f6341e4e7eb5} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + \ No newline at end of file diff --git a/libs/zlib/contrib/vstudio/vc10/testzlib.vcxproj.user b/libs/zlib/contrib/vstudio/vc10/testzlib.vcxproj.user new file mode 100644 index 000000000..695b5c78b --- /dev/null +++ b/libs/zlib/contrib/vstudio/vc10/testzlib.vcxproj.user @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/libs/zlib/contrib/vstudio/vc10/testzlibdll.vcxproj b/libs/zlib/contrib/vstudio/vc10/testzlibdll.vcxproj new file mode 100644 index 000000000..2d628158b --- /dev/null +++ b/libs/zlib/contrib/vstudio/vc10/testzlibdll.vcxproj @@ -0,0 +1,310 @@ + + + + + Debug + Itanium + + + Debug + Win32 + + + Debug + x64 + + + Release + Itanium + + + Release + Win32 + + + Release + x64 + + + + {C52F9E7B-498A-42BE-8DB4-85A15694366A} + Win32Proj + + + + Application + MultiByte + + + Application + MultiByte + + + Application + MultiByte + + + Application + MultiByte + + + Application + MultiByte + + + Application + MultiByte + + + + + + + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>10.0.30128.1 + x86\TestZlibDll$(Configuration)\ + x86\TestZlibDll$(Configuration)\Tmp\ + true + false + x86\TestZlibDll$(Configuration)\ + x86\TestZlibDll$(Configuration)\Tmp\ + false + false + x64\TestZlibDll$(Configuration)\ + x64\TestZlibDll$(Configuration)\Tmp\ + true + false + ia64\TestZlibDll$(Configuration)\ + ia64\TestZlibDll$(Configuration)\Tmp\ + true + false + x64\TestZlibDll$(Configuration)\ + x64\TestZlibDll$(Configuration)\Tmp\ + false + false + ia64\TestZlibDll$(Configuration)\ + ia64\TestZlibDll$(Configuration)\Tmp\ + false + false + AllRules.ruleset + + + AllRules.ruleset + + + AllRules.ruleset + + + AllRules.ruleset + + + AllRules.ruleset + + + AllRules.ruleset + + + + + + Disabled + ..\..\..;..\..\minizip;%(AdditionalIncludeDirectories) + WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + Default + MultiThreadedDebug + false + + + $(IntDir) + Level3 + EditAndContinue + + + x86\ZlibDllDebug\zlibwapi.lib;%(AdditionalDependencies) + $(OutDir)testzlib.exe + true + $(OutDir)testzlib.pdb + Console + false + + + MachineX86 + + + + + MaxSpeed + OnlyExplicitInline + true + ..\..\..;..\..\minizip;%(AdditionalIncludeDirectories) + WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + Default + MultiThreaded + false + true + + + $(IntDir) + Level3 + ProgramDatabase + + + x86\ZlibDllRelease\zlibwapi.lib;%(AdditionalDependencies) + $(OutDir)testzlib.exe + true + Console + true + true + false + + + MachineX86 + + + + + X64 + + + Disabled + ..\..\..;..\..\minizip;%(AdditionalIncludeDirectories) + _CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_CONSOLE;WIN64;%(PreprocessorDefinitions) + true + Default + MultiThreadedDebugDLL + false + + + $(IntDir) + Level3 + ProgramDatabase + + + x64\ZlibDllDebug\zlibwapi.lib;%(AdditionalDependencies) + $(OutDir)testzlib.exe + true + $(OutDir)testzlib.pdb + Console + MachineX64 + + + + + Itanium + + + Disabled + ..\..\..;..\..\minizip;%(AdditionalIncludeDirectories) + _CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_CONSOLE;WIN64;%(PreprocessorDefinitions) + true + Default + MultiThreadedDebugDLL + false + + + $(IntDir) + Level3 + ProgramDatabase + + + ia64\ZlibDllDebug\zlibwapi.lib;%(AdditionalDependencies) + $(OutDir)testzlib.exe + true + $(OutDir)testzlib.pdb + Console + MachineIA64 + + + + + X64 + + + MaxSpeed + OnlyExplicitInline + true + ..\..\..;..\..\minizip;%(AdditionalIncludeDirectories) + _CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;NDEBUG;_CONSOLE;WIN64;%(PreprocessorDefinitions) + true + Default + MultiThreadedDLL + false + true + + + $(IntDir) + Level3 + ProgramDatabase + + + x64\ZlibDllRelease\zlibwapi.lib;%(AdditionalDependencies) + $(OutDir)testzlib.exe + true + Console + true + true + MachineX64 + + + + + Itanium + + + MaxSpeed + OnlyExplicitInline + true + ..\..\..;..\..\minizip;%(AdditionalIncludeDirectories) + _CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;NDEBUG;_CONSOLE;WIN64;%(PreprocessorDefinitions) + true + Default + MultiThreadedDLL + false + true + + + $(IntDir) + Level3 + ProgramDatabase + + + ia64\ZlibDllRelease\zlibwapi.lib;%(AdditionalDependencies) + $(OutDir)testzlib.exe + true + Console + true + true + MachineIA64 + + + + + + + + {8fd826f8-3739-44e6-8cc8-997122e53b8d} + + + + + + \ No newline at end of file diff --git a/libs/zlib/contrib/vstudio/vc10/testzlibdll.vcxproj.filters b/libs/zlib/contrib/vstudio/vc10/testzlibdll.vcxproj.filters new file mode 100644 index 000000000..53a8693bb --- /dev/null +++ b/libs/zlib/contrib/vstudio/vc10/testzlibdll.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {fa61a89f-93fc-4c89-b29e-36224b7592f4} + cpp;c;cxx;def;odl;idl;hpj;bat;asm + + + {d4b85da0-2ba2-4934-b57f-e2584e3848ee} + h;hpp;hxx;hm;inl;inc + + + {e573e075-00bd-4a7d-bd67-a8cc9bfc5aca} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe + + + + + Source Files + + + \ No newline at end of file diff --git a/libs/zlib/contrib/vstudio/vc10/testzlibdll.vcxproj.user b/libs/zlib/contrib/vstudio/vc10/testzlibdll.vcxproj.user new file mode 100644 index 000000000..695b5c78b --- /dev/null +++ b/libs/zlib/contrib/vstudio/vc10/testzlibdll.vcxproj.user @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/libs/zlib/contrib/vstudio/vc10/zlib.rc b/libs/zlib/contrib/vstudio/vc10/zlib.rc new file mode 100644 index 000000000..863b59c78 --- /dev/null +++ b/libs/zlib/contrib/vstudio/vc10/zlib.rc @@ -0,0 +1,32 @@ +#include + +#define IDR_VERSION1 1 +IDR_VERSION1 VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE + FILEVERSION 1,2,5,0 + PRODUCTVERSION 1,2,5,0 + FILEFLAGSMASK VS_FFI_FILEFLAGSMASK + FILEFLAGS 0 + FILEOS VOS_DOS_WINDOWS32 + FILETYPE VFT_DLL + FILESUBTYPE 0 // not used +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904E4" + //language ID = U.S. English, char set = Windows, Multilingual + + BEGIN + VALUE "FileDescription", "zlib data compression and ZIP file I/O library\0" + VALUE "FileVersion", "1.2.5.0\0" + VALUE "InternalName", "zlib\0" + VALUE "OriginalFilename", "zlib.dll\0" + VALUE "ProductName", "ZLib.DLL\0" + VALUE "Comments","DLL support by Alessandro Iacopetti & Gilles Vollant\0" + VALUE "LegalCopyright", "(C) 1995-2010 Jean-loup Gailly & Mark Adler\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x0409, 1252 + END +END diff --git a/libs/zlib/contrib/vstudio/vc10/zlibstat.vcxproj b/libs/zlib/contrib/vstudio/vc10/zlibstat.vcxproj new file mode 100644 index 000000000..2682fca24 --- /dev/null +++ b/libs/zlib/contrib/vstudio/vc10/zlibstat.vcxproj @@ -0,0 +1,457 @@ + + + + + Debug + Itanium + + + Debug + Win32 + + + Debug + x64 + + + ReleaseWithoutAsm + Itanium + + + ReleaseWithoutAsm + Win32 + + + ReleaseWithoutAsm + x64 + + + Release + Itanium + + + Release + Win32 + + + Release + x64 + + + + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8} + + + + StaticLibrary + false + + + StaticLibrary + false + + + StaticLibrary + false + + + StaticLibrary + false + + + StaticLibrary + false + + + StaticLibrary + false + + + StaticLibrary + false + + + StaticLibrary + false + + + StaticLibrary + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>10.0.30128.1 + x86\ZlibStat$(Configuration)\ + x86\ZlibStat$(Configuration)\Tmp\ + x86\ZlibStat$(Configuration)\ + x86\ZlibStat$(Configuration)\Tmp\ + x86\ZlibStat$(Configuration)\ + x86\ZlibStat$(Configuration)\Tmp\ + x64\ZlibStat$(Configuration)\ + x64\ZlibStat$(Configuration)\Tmp\ + ia64\ZlibStat$(Configuration)\ + ia64\ZlibStat$(Configuration)\Tmp\ + x64\ZlibStat$(Configuration)\ + x64\ZlibStat$(Configuration)\Tmp\ + ia64\ZlibStat$(Configuration)\ + ia64\ZlibStat$(Configuration)\Tmp\ + x64\ZlibStat$(Configuration)\ + x64\ZlibStat$(Configuration)\Tmp\ + ia64\ZlibStat$(Configuration)\ + ia64\ZlibStat$(Configuration)\Tmp\ + AllRules.ruleset + + + AllRules.ruleset + + + AllRules.ruleset + + + AllRules.ruleset + + + AllRules.ruleset + + + AllRules.ruleset + + + AllRules.ruleset + + + AllRules.ruleset + + + AllRules.ruleset + + + + + + Disabled + ..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories) + WIN32;ZLIB_WINAPI;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;%(PreprocessorDefinitions) + + + MultiThreadedDebug + false + $(IntDir)zlibstat.pch + $(IntDir) + $(IntDir) + $(OutDir) + Level3 + true + OldStyle + + + 0x040c + + + /MACHINE:X86 /NODEFAULTLIB %(AdditionalOptions) + $(OutDir)zlibstat.lib + true + + + + + OnlyExplicitInline + ..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories) + WIN32;ZLIB_WINAPI;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ASMV;ASMINF;%(PreprocessorDefinitions) + true + + + MultiThreaded + false + true + $(IntDir)zlibstat.pch + $(IntDir) + $(IntDir) + $(OutDir) + Level3 + true + + + 0x040c + + + /MACHINE:X86 /NODEFAULTLIB %(AdditionalOptions) + ..\..\masmx86\match686.obj;..\..\masmx86\inffas32.obj;%(AdditionalDependencies) + $(OutDir)zlibstat.lib + true + + + + + OnlyExplicitInline + ..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories) + WIN32;ZLIB_WINAPI;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;%(PreprocessorDefinitions) + true + + + MultiThreaded + false + true + $(IntDir)zlibstat.pch + $(IntDir) + $(IntDir) + $(OutDir) + Level3 + true + + + 0x040c + + + /MACHINE:X86 /NODEFAULTLIB %(AdditionalOptions) + $(OutDir)zlibstat.lib + true + + + + + X64 + + + Disabled + ..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories) + ZLIB_WINAPI;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;WIN64;%(PreprocessorDefinitions) + + + MultiThreadedDebugDLL + false + $(IntDir)zlibstat.pch + $(IntDir) + $(IntDir) + $(OutDir) + Level3 + true + OldStyle + + + 0x040c + + + /MACHINE:AMD64 /NODEFAULTLIB %(AdditionalOptions) + $(OutDir)zlibstat.lib + true + + + + + Itanium + + + Disabled + ..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories) + ZLIB_WINAPI;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;WIN64;%(PreprocessorDefinitions) + + + MultiThreadedDebugDLL + false + $(IntDir)zlibstat.pch + $(IntDir) + $(IntDir) + $(OutDir) + Level3 + true + OldStyle + + + 0x040c + + + /MACHINE:IA64 /NODEFAULTLIB %(AdditionalOptions) + $(OutDir)zlibstat.lib + true + + + + + X64 + + + OnlyExplicitInline + ..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories) + ZLIB_WINAPI;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ASMV;ASMINF;WIN64;%(PreprocessorDefinitions) + true + + + MultiThreadedDLL + false + true + $(IntDir)zlibstat.pch + $(IntDir) + $(IntDir) + $(OutDir) + Level3 + true + + + 0x040c + + + /MACHINE:AMD64 /NODEFAULTLIB %(AdditionalOptions) + ..\..\masmx64\gvmat64.obj;..\..\masmx64\inffasx64.obj;%(AdditionalDependencies) + $(OutDir)zlibstat.lib + true + + + + + Itanium + + + OnlyExplicitInline + ..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories) + ZLIB_WINAPI;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;WIN64;%(PreprocessorDefinitions) + true + + + MultiThreadedDLL + false + true + $(IntDir)zlibstat.pch + $(IntDir) + $(IntDir) + $(OutDir) + Level3 + true + + + 0x040c + + + /MACHINE:IA64 /NODEFAULTLIB %(AdditionalOptions) + $(OutDir)zlibstat.lib + true + + + + + X64 + + + OnlyExplicitInline + ..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories) + ZLIB_WINAPI;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;WIN64;%(PreprocessorDefinitions) + true + + + MultiThreadedDLL + false + true + $(IntDir)zlibstat.pch + $(IntDir) + $(IntDir) + $(OutDir) + Level3 + true + + + 0x040c + + + /MACHINE:AMD64 /NODEFAULTLIB %(AdditionalOptions) + $(OutDir)zlibstat.lib + true + + + + + Itanium + + + OnlyExplicitInline + ..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories) + ZLIB_WINAPI;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;WIN64;%(PreprocessorDefinitions) + true + + + MultiThreadedDLL + false + true + $(IntDir)zlibstat.pch + $(IntDir) + $(IntDir) + $(OutDir) + Level3 + true + + + 0x040c + + + /MACHINE:IA64 /NODEFAULTLIB %(AdditionalOptions) + $(OutDir)zlibstat.lib + true + + + + + + + + + + + + + + true + true + true + true + true + true + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/libs/zlib/contrib/vstudio/vc10/zlibstat.vcxproj.filters b/libs/zlib/contrib/vstudio/vc10/zlibstat.vcxproj.filters new file mode 100644 index 000000000..c8c7f7ea3 --- /dev/null +++ b/libs/zlib/contrib/vstudio/vc10/zlibstat.vcxproj.filters @@ -0,0 +1,77 @@ + + + + + {174213f6-7f66-4ae8-a3a8-a1e0a1e6ffdd} + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + + + Source Files + + + + + Source Files + + + \ No newline at end of file diff --git a/libs/zlib/contrib/vstudio/vc10/zlibstat.vcxproj.user b/libs/zlib/contrib/vstudio/vc10/zlibstat.vcxproj.user new file mode 100644 index 000000000..695b5c78b --- /dev/null +++ b/libs/zlib/contrib/vstudio/vc10/zlibstat.vcxproj.user @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/libs/zlib/contrib/vstudio/vc10/zlibvc.def b/libs/zlib/contrib/vstudio/vc10/zlibvc.def new file mode 100644 index 000000000..fa171ae92 --- /dev/null +++ b/libs/zlib/contrib/vstudio/vc10/zlibvc.def @@ -0,0 +1,130 @@ +LIBRARY +; zlib data compression and ZIP file I/O library + +VERSION 1.24 + +EXPORTS + adler32 @1 + compress @2 + crc32 @3 + deflate @4 + deflateCopy @5 + deflateEnd @6 + deflateInit2_ @7 + deflateInit_ @8 + deflateParams @9 + deflateReset @10 + deflateSetDictionary @11 + gzclose @12 + gzdopen @13 + gzerror @14 + gzflush @15 + gzopen @16 + gzread @17 + gzwrite @18 + inflate @19 + inflateEnd @20 + inflateInit2_ @21 + inflateInit_ @22 + inflateReset @23 + inflateSetDictionary @24 + inflateSync @25 + uncompress @26 + zlibVersion @27 + gzprintf @28 + gzputc @29 + gzgetc @30 + gzseek @31 + gzrewind @32 + gztell @33 + gzeof @34 + gzsetparams @35 + zError @36 + inflateSyncPoint @37 + get_crc_table @38 + compress2 @39 + gzputs @40 + gzgets @41 + inflateCopy @42 + inflateBackInit_ @43 + inflateBack @44 + inflateBackEnd @45 + compressBound @46 + deflateBound @47 + gzclearerr @48 + gzungetc @49 + zlibCompileFlags @50 + deflatePrime @51 + + unzOpen @61 + unzClose @62 + unzGetGlobalInfo @63 + unzGetCurrentFileInfo @64 + unzGoToFirstFile @65 + unzGoToNextFile @66 + unzOpenCurrentFile @67 + unzReadCurrentFile @68 + unzOpenCurrentFile3 @69 + unztell @70 + unzeof @71 + unzCloseCurrentFile @72 + unzGetGlobalComment @73 + unzStringFileNameCompare @74 + unzLocateFile @75 + unzGetLocalExtrafield @76 + unzOpen2 @77 + unzOpenCurrentFile2 @78 + unzOpenCurrentFilePassword @79 + + zipOpen @80 + zipOpenNewFileInZip @81 + zipWriteInFileInZip @82 + zipCloseFileInZip @83 + zipClose @84 + zipOpenNewFileInZip2 @86 + zipCloseFileInZipRaw @87 + zipOpen2 @88 + zipOpenNewFileInZip3 @89 + + unzGetFilePos @100 + unzGoToFilePos @101 + + fill_win32_filefunc @110 + +; zlibwapi v1.2.4 added: + fill_win32_filefunc64 @111 + fill_win32_filefunc64A @112 + fill_win32_filefunc64W @113 + + unzOpen64 @120 + unzOpen2_64 @121 + unzGetGlobalInfo64 @122 + unzGetCurrentFileInfo64 @124 + unzGetCurrentFileZStreamPos64 @125 + unztell64 @126 + unzGetFilePos64 @127 + unzGoToFilePos64 @128 + + zipOpen64 @130 + zipOpen2_64 @131 + zipOpenNewFileInZip64 @132 + zipOpenNewFileInZip2_64 @133 + zipOpenNewFileInZip3_64 @134 + zipOpenNewFileInZip4_64 @135 + zipCloseFileInZipRaw64 @136 + +; zlib1 v1.2.4 added: + adler32_combine @140 + crc32_combine @142 + deflateSetHeader @144 + deflateTune @145 + gzbuffer @146 + gzclose_r @147 + gzclose_w @148 + gzdirect @149 + gzoffset @150 + inflateGetHeader @156 + inflateMark @157 + inflatePrime @158 + inflateReset2 @159 + inflateUndermine @160 diff --git a/libs/zlib/contrib/vstudio/vc10/zlibvc.sln b/libs/zlib/contrib/vstudio/vc10/zlibvc.sln new file mode 100644 index 000000000..6f6ffd5ee --- /dev/null +++ b/libs/zlib/contrib/vstudio/vc10/zlibvc.sln @@ -0,0 +1,135 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlibvc", "zlibvc.vcxproj", "{8FD826F8-3739-44E6-8CC8-997122E53B8D}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlibstat", "zlibstat.vcxproj", "{745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testzlib", "testzlib.vcxproj", "{AA6666AA-E09F-4135-9C0C-4FE50C3C654B}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testzlibdll", "testzlibdll.vcxproj", "{C52F9E7B-498A-42BE-8DB4-85A15694366A}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "minizip", "minizip.vcxproj", "{48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "miniunz", "miniunz.vcxproj", "{C52F9E7B-498A-42BE-8DB4-85A15694382A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Itanium = Debug|Itanium + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Itanium = Release|Itanium + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + ReleaseWithoutAsm|Itanium = ReleaseWithoutAsm|Itanium + ReleaseWithoutAsm|Win32 = ReleaseWithoutAsm|Win32 + ReleaseWithoutAsm|x64 = ReleaseWithoutAsm|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug|Itanium.ActiveCfg = Debug|Itanium + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug|Itanium.Build.0 = Debug|Itanium + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug|Win32.ActiveCfg = Debug|Win32 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug|Win32.Build.0 = Debug|Win32 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug|x64.ActiveCfg = Debug|x64 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug|x64.Build.0 = Debug|x64 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release|Itanium.ActiveCfg = Release|Itanium + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release|Itanium.Build.0 = Release|Itanium + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release|Win32.ActiveCfg = Release|Win32 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release|Win32.Build.0 = Release|Win32 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release|x64.ActiveCfg = Release|x64 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release|x64.Build.0 = Release|x64 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm|Itanium.ActiveCfg = ReleaseWithoutAsm|Itanium + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm|Itanium.Build.0 = ReleaseWithoutAsm|Itanium + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm|Win32.ActiveCfg = ReleaseWithoutAsm|Win32 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm|Win32.Build.0 = ReleaseWithoutAsm|Win32 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm|x64.ActiveCfg = ReleaseWithoutAsm|x64 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm|x64.Build.0 = ReleaseWithoutAsm|x64 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug|Itanium.ActiveCfg = Debug|Itanium + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug|Itanium.Build.0 = Debug|Itanium + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug|Win32.ActiveCfg = Debug|Win32 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug|Win32.Build.0 = Debug|Win32 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug|x64.ActiveCfg = Debug|x64 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug|x64.Build.0 = Debug|x64 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release|Itanium.ActiveCfg = Release|Itanium + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release|Itanium.Build.0 = Release|Itanium + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release|Win32.ActiveCfg = Release|Win32 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release|Win32.Build.0 = Release|Win32 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release|x64.ActiveCfg = Release|x64 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release|x64.Build.0 = Release|x64 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm|Itanium.ActiveCfg = ReleaseWithoutAsm|Itanium + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm|Itanium.Build.0 = ReleaseWithoutAsm|Itanium + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm|Win32.ActiveCfg = ReleaseWithoutAsm|Win32 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm|Win32.Build.0 = ReleaseWithoutAsm|Win32 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm|x64.ActiveCfg = ReleaseWithoutAsm|x64 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm|x64.Build.0 = ReleaseWithoutAsm|x64 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug|Itanium.ActiveCfg = Debug|Itanium + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug|Itanium.Build.0 = Debug|Itanium + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug|Win32.ActiveCfg = Debug|Win32 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug|Win32.Build.0 = Debug|Win32 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug|x64.ActiveCfg = Debug|x64 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug|x64.Build.0 = Debug|x64 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release|Itanium.ActiveCfg = Release|Itanium + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release|Itanium.Build.0 = Release|Itanium + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release|Win32.ActiveCfg = Release|Win32 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release|Win32.Build.0 = Release|Win32 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release|x64.ActiveCfg = Release|x64 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release|x64.Build.0 = Release|x64 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Itanium.ActiveCfg = ReleaseWithoutAsm|Itanium + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Itanium.Build.0 = ReleaseWithoutAsm|Itanium + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Win32.ActiveCfg = ReleaseWithoutAsm|Win32 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Win32.Build.0 = ReleaseWithoutAsm|Win32 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|x64.ActiveCfg = ReleaseWithoutAsm|x64 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|x64.Build.0 = ReleaseWithoutAsm|x64 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Debug|Itanium.ActiveCfg = Debug|Itanium + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Debug|Itanium.Build.0 = Debug|Itanium + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Debug|Win32.ActiveCfg = Debug|Win32 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Debug|Win32.Build.0 = Debug|Win32 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Debug|x64.ActiveCfg = Debug|x64 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Debug|x64.Build.0 = Debug|x64 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Release|Itanium.ActiveCfg = Release|Itanium + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Release|Itanium.Build.0 = Release|Itanium + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Release|Win32.ActiveCfg = Release|Win32 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Release|Win32.Build.0 = Release|Win32 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Release|x64.ActiveCfg = Release|x64 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Release|x64.Build.0 = Release|x64 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.ReleaseWithoutAsm|Itanium.ActiveCfg = Release|Itanium + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.ReleaseWithoutAsm|Itanium.Build.0 = Release|Itanium + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.ReleaseWithoutAsm|Win32.ActiveCfg = Release|Win32 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.ReleaseWithoutAsm|x64.ActiveCfg = Release|x64 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug|Itanium.ActiveCfg = Debug|Itanium + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug|Itanium.Build.0 = Debug|Itanium + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug|Win32.ActiveCfg = Debug|Win32 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug|Win32.Build.0 = Debug|Win32 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug|x64.ActiveCfg = Debug|x64 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug|x64.Build.0 = Debug|x64 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release|Itanium.ActiveCfg = Release|Itanium + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release|Itanium.Build.0 = Release|Itanium + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release|Win32.ActiveCfg = Release|Win32 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release|Win32.Build.0 = Release|Win32 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release|x64.ActiveCfg = Release|x64 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release|x64.Build.0 = Release|x64 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Itanium.ActiveCfg = Release|Itanium + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Itanium.Build.0 = Release|Itanium + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Win32.ActiveCfg = Release|Win32 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|x64.ActiveCfg = Release|x64 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug|Itanium.ActiveCfg = Debug|Itanium + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug|Itanium.Build.0 = Debug|Itanium + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug|Win32.ActiveCfg = Debug|Win32 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug|Win32.Build.0 = Debug|Win32 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug|x64.ActiveCfg = Debug|x64 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug|x64.Build.0 = Debug|x64 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release|Itanium.ActiveCfg = Release|Itanium + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release|Itanium.Build.0 = Release|Itanium + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release|Win32.ActiveCfg = Release|Win32 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release|Win32.Build.0 = Release|Win32 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release|x64.ActiveCfg = Release|x64 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release|x64.Build.0 = Release|x64 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseWithoutAsm|Itanium.ActiveCfg = Release|Itanium + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseWithoutAsm|Itanium.Build.0 = Release|Itanium + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseWithoutAsm|Win32.ActiveCfg = Release|Win32 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseWithoutAsm|x64.ActiveCfg = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/libs/zlib/contrib/vstudio/vc10/zlibvc.vcxproj b/libs/zlib/contrib/vstudio/vc10/zlibvc.vcxproj new file mode 100644 index 000000000..986239893 --- /dev/null +++ b/libs/zlib/contrib/vstudio/vc10/zlibvc.vcxproj @@ -0,0 +1,659 @@ + + + + + Debug + Itanium + + + Debug + Win32 + + + Debug + x64 + + + ReleaseWithoutAsm + Itanium + + + ReleaseWithoutAsm + Win32 + + + ReleaseWithoutAsm + x64 + + + Release + Itanium + + + Release + Win32 + + + Release + x64 + + + + {8FD826F8-3739-44E6-8CC8-997122E53B8D} + + + + DynamicLibrary + false + true + + + DynamicLibrary + false + true + + + DynamicLibrary + false + + + DynamicLibrary + false + true + + + DynamicLibrary + false + true + + + DynamicLibrary + false + + + DynamicLibrary + false + true + + + DynamicLibrary + false + true + + + DynamicLibrary + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>10.0.30128.1 + x86\ZlibDll$(Configuration)\ + x86\ZlibDll$(Configuration)\Tmp\ + true + false + x86\ZlibDll$(Configuration)\ + x86\ZlibDll$(Configuration)\Tmp\ + false + false + x86\ZlibDll$(Configuration)\ + x86\ZlibDll$(Configuration)\Tmp\ + false + false + x64\ZlibDll$(Configuration)\ + x64\ZlibDll$(Configuration)\Tmp\ + true + false + ia64\ZlibDll$(Configuration)\ + ia64\ZlibDll$(Configuration)\Tmp\ + true + false + x64\ZlibDll$(Configuration)\ + x64\ZlibDll$(Configuration)\Tmp\ + false + false + ia64\ZlibDll$(Configuration)\ + ia64\ZlibDll$(Configuration)\Tmp\ + false + false + x64\ZlibDll$(Configuration)\ + x64\ZlibDll$(Configuration)\Tmp\ + false + false + ia64\ZlibDll$(Configuration)\ + ia64\ZlibDll$(Configuration)\Tmp\ + false + false + AllRules.ruleset + + + AllRules.ruleset + + + AllRules.ruleset + + + AllRules.ruleset + + + AllRules.ruleset + + + AllRules.ruleset + + + AllRules.ruleset + + + AllRules.ruleset + + + AllRules.ruleset + + + + + + _DEBUG;%(PreprocessorDefinitions) + true + true + Win32 + $(OutDir)zlibvc.tlb + + + Disabled + ..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories) + WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ZLIB_WINAPI;ASMV;ASMINF;%(PreprocessorDefinitions) + + + MultiThreadedDebug + false + $(IntDir)zlibvc.pch + $(IntDir) + $(IntDir) + $(OutDir) + + + Level3 + true + EditAndContinue + + + _DEBUG;%(PreprocessorDefinitions) + 0x040c + + + /MACHINE:I386 %(AdditionalOptions) + ..\..\masmx86\match686.obj;..\..\masmx86\inffas32.obj;%(AdditionalDependencies) + $(OutDir)zlibwapi.dll + true + .\zlibvc.def + true + $(OutDir)zlibwapi.pdb + true + $(OutDir)zlibwapi.map + Windows + false + + + $(OutDir)zlibwapi.lib + + + + + NDEBUG;%(PreprocessorDefinitions) + true + true + Win32 + $(OutDir)zlibvc.tlb + + + OnlyExplicitInline + ..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories) + WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ZLIB_WINAPI;%(PreprocessorDefinitions) + true + + + MultiThreadedDLL + false + true + $(IntDir)zlibvc.pch + All + $(IntDir) + $(IntDir) + $(OutDir) + + + Level3 + true + + + NDEBUG;%(PreprocessorDefinitions) + 0x040c + + + /MACHINE:I386 %(AdditionalOptions) + $(OutDir)zlibwapi.dll + true + false + .\zlibvc.def + $(OutDir)zlibwapi.pdb + true + $(OutDir)zlibwapi.map + Windows + false + + + $(OutDir)zlibwapi.lib + + + + + NDEBUG;%(PreprocessorDefinitions) + true + true + Win32 + $(OutDir)zlibvc.tlb + + + OnlyExplicitInline + ..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories) + WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ZLIB_WINAPI;ASMV;ASMINF;%(PreprocessorDefinitions) + true + + + MultiThreaded + false + true + $(IntDir)zlibvc.pch + All + $(IntDir) + $(IntDir) + $(OutDir) + + + Level3 + true + + + NDEBUG;%(PreprocessorDefinitions) + 0x040c + + + /MACHINE:I386 %(AdditionalOptions) + ..\..\masmx86\match686.obj;..\..\masmx86\inffas32.obj;%(AdditionalDependencies) + $(OutDir)zlibwapi.dll + true + false + .\zlibvc.def + $(OutDir)zlibwapi.pdb + true + $(OutDir)zlibwapi.map + Windows + false + + + $(OutDir)zlibwapi.lib + + + + + _DEBUG;%(PreprocessorDefinitions) + true + true + X64 + $(OutDir)zlibvc.tlb + + + Disabled + ..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories) + WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ZLIB_WINAPI;ASMV;ASMINF;WIN64;%(PreprocessorDefinitions) + + + MultiThreadedDebugDLL + false + $(IntDir)zlibvc.pch + $(IntDir) + $(IntDir) + $(OutDir) + + + Level3 + true + ProgramDatabase + + + _DEBUG;%(PreprocessorDefinitions) + 0x040c + + + ..\..\masmx64\gvmat64.obj;..\..\masmx64\inffasx64.obj;%(AdditionalDependencies) + $(OutDir)zlibwapi.dll + true + .\zlibvc.def + true + $(OutDir)zlibwapi.pdb + true + $(OutDir)zlibwapi.map + Windows + $(OutDir)zlibwapi.lib + MachineX64 + + + + + _DEBUG;%(PreprocessorDefinitions) + true + true + Itanium + $(OutDir)zlibvc.tlb + + + Disabled + ..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories) + WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ZLIB_WINAPI;WIN64;%(PreprocessorDefinitions) + + + MultiThreadedDebugDLL + false + $(IntDir)zlibvc.pch + $(IntDir) + $(IntDir) + $(OutDir) + + + Level3 + true + ProgramDatabase + + + _DEBUG;%(PreprocessorDefinitions) + 0x040c + + + $(OutDir)zlibwapi.dll + true + .\zlibvc.def + true + $(OutDir)zlibwapi.pdb + true + $(OutDir)zlibwapi.map + Windows + $(OutDir)zlibwapi.lib + MachineIA64 + + + + + NDEBUG;%(PreprocessorDefinitions) + true + true + X64 + $(OutDir)zlibvc.tlb + + + OnlyExplicitInline + ..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories) + WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ZLIB_WINAPI;WIN64;%(PreprocessorDefinitions) + true + + + MultiThreadedDLL + false + true + $(IntDir)zlibvc.pch + All + $(IntDir) + $(IntDir) + $(OutDir) + + + Level3 + true + + + NDEBUG;%(PreprocessorDefinitions) + 0x040c + + + $(OutDir)zlibwapi.dll + true + false + .\zlibvc.def + $(OutDir)zlibwapi.pdb + true + $(OutDir)zlibwapi.map + Windows + $(OutDir)zlibwapi.lib + MachineX64 + + + + + NDEBUG;%(PreprocessorDefinitions) + true + true + Itanium + $(OutDir)zlibvc.tlb + + + OnlyExplicitInline + ..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories) + WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ZLIB_WINAPI;WIN64;%(PreprocessorDefinitions) + true + + + MultiThreadedDLL + false + true + $(IntDir)zlibvc.pch + All + $(IntDir) + $(IntDir) + $(OutDir) + + + Level3 + true + + + NDEBUG;%(PreprocessorDefinitions) + 0x040c + + + $(OutDir)zlibwapi.dll + true + false + .\zlibvc.def + $(OutDir)zlibwapi.pdb + true + $(OutDir)zlibwapi.map + Windows + $(OutDir)zlibwapi.lib + MachineIA64 + + + + + NDEBUG;%(PreprocessorDefinitions) + true + true + X64 + $(OutDir)zlibvc.tlb + + + OnlyExplicitInline + ..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories) + _CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ZLIB_WINAPI;ASMV;ASMINF;WIN64;%(PreprocessorDefinitions) + true + + + MultiThreadedDLL + false + true + $(IntDir)zlibvc.pch + All + $(IntDir) + $(IntDir) + $(OutDir) + + + Level3 + true + + + NDEBUG;%(PreprocessorDefinitions) + 0x040c + + + ..\..\masmx64\gvmat64.obj;..\..\masmx64\inffasx64.obj;%(AdditionalDependencies) + $(OutDir)zlibwapi.dll + true + false + .\zlibvc.def + $(OutDir)zlibwapi.pdb + true + $(OutDir)zlibwapi.map + Windows + $(OutDir)zlibwapi.lib + MachineX64 + + + + + NDEBUG;%(PreprocessorDefinitions) + true + true + Itanium + $(OutDir)zlibvc.tlb + + + OnlyExplicitInline + ..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories) + _CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ZLIB_WINAPI;WIN64;%(PreprocessorDefinitions) + true + + + MultiThreadedDLL + false + true + $(IntDir)zlibvc.pch + All + $(IntDir) + $(IntDir) + $(OutDir) + + + Level3 + true + + + NDEBUG;%(PreprocessorDefinitions) + 0x040c + + + $(OutDir)zlibwapi.dll + true + false + .\zlibvc.def + $(OutDir)zlibwapi.pdb + true + $(OutDir)zlibwapi.map + Windows + $(OutDir)zlibwapi.lib + MachineIA64 + + + + + + + + + + + + + + true + true + true + true + true + true + + + + + + + + + + %(AdditionalIncludeDirectories) + ZLIB_INTERNAL;%(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + ZLIB_INTERNAL;%(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + ZLIB_INTERNAL;%(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + ZLIB_INTERNAL;%(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + ZLIB_INTERNAL;%(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + ZLIB_INTERNAL;%(PreprocessorDefinitions) + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/libs/zlib/contrib/vstudio/vc10/zlibvc.vcxproj.filters b/libs/zlib/contrib/vstudio/vc10/zlibvc.vcxproj.filters new file mode 100644 index 000000000..180b71cd6 --- /dev/null +++ b/libs/zlib/contrib/vstudio/vc10/zlibvc.vcxproj.filters @@ -0,0 +1,118 @@ + + + + + {07934a85-8b61-443d-a0ee-b2eedb74f3cd} + cpp;c;cxx;rc;def;r;odl;hpj;bat;for;f90 + + + {1d99675b-433d-4a21-9e50-ed4ab8b19762} + h;hpp;hxx;hm;inl;fi;fd + + + {431c0958-fa71-44d0-9084-2d19d100c0cc} + ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + + + Source Files + + + + + Source Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + \ No newline at end of file diff --git a/libs/zlib/contrib/vstudio/vc10/zlibvc.vcxproj.user b/libs/zlib/contrib/vstudio/vc10/zlibvc.vcxproj.user new file mode 100644 index 000000000..695b5c78b --- /dev/null +++ b/libs/zlib/contrib/vstudio/vc10/zlibvc.vcxproj.user @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/libs/zlib/contrib/vstudio/vc7/miniunz.vcproj b/libs/zlib/contrib/vstudio/vc7/miniunz.vcproj new file mode 100644 index 000000000..ad5117c84 --- /dev/null +++ b/libs/zlib/contrib/vstudio/vc7/miniunz.vcproj @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/zlib/contrib/vstudio/vc7/minizip.vcproj b/libs/zlib/contrib/vstudio/vc7/minizip.vcproj new file mode 100644 index 000000000..fb5b6320d --- /dev/null +++ b/libs/zlib/contrib/vstudio/vc7/minizip.vcproj @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/zlib/contrib/vstudio/vc7/testzlib.vcproj b/libs/zlib/contrib/vstudio/vc7/testzlib.vcproj new file mode 100644 index 000000000..97bc3e8c8 --- /dev/null +++ b/libs/zlib/contrib/vstudio/vc7/testzlib.vcproj @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/zlib/contrib/vstudio/vc7/zlib.rc b/libs/zlib/contrib/vstudio/vc7/zlib.rc new file mode 100644 index 000000000..58f756722 --- /dev/null +++ b/libs/zlib/contrib/vstudio/vc7/zlib.rc @@ -0,0 +1,32 @@ +#include + +#define IDR_VERSION1 1 +IDR_VERSION1 VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE + FILEVERSION 1,2,3,0 + PRODUCTVERSION 1,2,3,0 + FILEFLAGSMASK VS_FFI_FILEFLAGSMASK + FILEFLAGS 0 + FILEOS VOS_DOS_WINDOWS32 + FILETYPE VFT_DLL + FILESUBTYPE 0 // not used +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904E4" + //language ID = U.S. English, char set = Windows, Multilingual + + BEGIN + VALUE "FileDescription", "zlib data compression library\0" + VALUE "FileVersion", "1.2.3.0\0" + VALUE "InternalName", "zlib\0" + VALUE "OriginalFilename", "zlib.dll\0" + VALUE "ProductName", "ZLib.DLL\0" + VALUE "Comments","DLL support by Alessandro Iacopetti & Gilles Vollant\0" + VALUE "LegalCopyright", "(C) 1995-2003 Jean-loup Gailly & Mark Adler\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x0409, 1252 + END +END diff --git a/libs/zlib/contrib/vstudio/vc7/zlibstat.vcproj b/libs/zlib/contrib/vstudio/vc7/zlibstat.vcproj new file mode 100644 index 000000000..766d7a4d6 --- /dev/null +++ b/libs/zlib/contrib/vstudio/vc7/zlibstat.vcproj @@ -0,0 +1,246 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/zlib/contrib/vstudio/vc7/zlibvc.def b/libs/zlib/contrib/vstudio/vc7/zlibvc.def new file mode 100644 index 000000000..74dfdb8af --- /dev/null +++ b/libs/zlib/contrib/vstudio/vc7/zlibvc.def @@ -0,0 +1,92 @@ + +VERSION 1.23 + +HEAPSIZE 1048576,8192 + +EXPORTS + adler32 @1 + compress @2 + crc32 @3 + deflate @4 + deflateCopy @5 + deflateEnd @6 + deflateInit2_ @7 + deflateInit_ @8 + deflateParams @9 + deflateReset @10 + deflateSetDictionary @11 + gzclose @12 + gzdopen @13 + gzerror @14 + gzflush @15 + gzopen @16 + gzread @17 + gzwrite @18 + inflate @19 + inflateEnd @20 + inflateInit2_ @21 + inflateInit_ @22 + inflateReset @23 + inflateSetDictionary @24 + inflateSync @25 + uncompress @26 + zlibVersion @27 + gzprintf @28 + gzputc @29 + gzgetc @30 + gzseek @31 + gzrewind @32 + gztell @33 + gzeof @34 + gzsetparams @35 + zError @36 + inflateSyncPoint @37 + get_crc_table @38 + compress2 @39 + gzputs @40 + gzgets @41 + inflateCopy @42 + inflateBackInit_ @43 + inflateBack @44 + inflateBackEnd @45 + compressBound @46 + deflateBound @47 + gzclearerr @48 + gzungetc @49 + zlibCompileFlags @50 + deflatePrime @51 + + unzOpen @61 + unzClose @62 + unzGetGlobalInfo @63 + unzGetCurrentFileInfo @64 + unzGoToFirstFile @65 + unzGoToNextFile @66 + unzOpenCurrentFile @67 + unzReadCurrentFile @68 + unzOpenCurrentFile3 @69 + unztell @70 + unzeof @71 + unzCloseCurrentFile @72 + unzGetGlobalComment @73 + unzStringFileNameCompare @74 + unzLocateFile @75 + unzGetLocalExtrafield @76 + unzOpen2 @77 + unzOpenCurrentFile2 @78 + unzOpenCurrentFilePassword @79 + + zipOpen @80 + zipOpenNewFileInZip @81 + zipWriteInFileInZip @82 + zipCloseFileInZip @83 + zipClose @84 + zipOpenNewFileInZip2 @86 + zipCloseFileInZipRaw @87 + zipOpen2 @88 + zipOpenNewFileInZip3 @89 + + unzGetFilePos @100 + unzGoToFilePos @101 + + fill_win32_filefunc @110 diff --git a/libs/zlib/contrib/vstudio/vc7/zlibvc.sln b/libs/zlib/contrib/vstudio/vc7/zlibvc.sln new file mode 100644 index 000000000..927b42b7b --- /dev/null +++ b/libs/zlib/contrib/vstudio/vc7/zlibvc.sln @@ -0,0 +1,78 @@ +Microsoft Visual Studio Solution File, Format Version 7.00 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlibstat", "zlibstat.vcproj", "{745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlibvc", "zlibvc.vcproj", "{8FD826F8-3739-44E6-8CC8-997122E53B8D}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "minizip", "minizip.vcproj", "{48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "miniunz", "miniunz.vcproj", "{C52F9E7B-498A-42BE-8DB4-85A15694382A}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testZlibDll", "testzlib.vcproj", "{AA6666AA-E09F-4135-9C0C-4FE50C3C654C}" +EndProject +Global + GlobalSection(SolutionConfiguration) = preSolution + ConfigName.0 = Debug + ConfigName.1 = Release + ConfigName.2 = ReleaseAxp + ConfigName.3 = ReleaseWithoutAsm + ConfigName.4 = ReleaseWithoutCrtdll + EndGlobalSection + GlobalSection(ProjectDependencies) = postSolution + EndGlobalSection + GlobalSection(ProjectConfiguration) = postSolution + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug.ActiveCfg = Debug|Win32 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug.Build.0 = Debug|Win32 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release.ActiveCfg = Release|Win32 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release.Build.0 = Release|Win32 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseAxp.ActiveCfg = ReleaseAxp|Win32 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseAxp.Build.0 = ReleaseAxp|Win32 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm.ActiveCfg = ReleaseWithoutAsm|Win32 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm.Build.0 = ReleaseWithoutAsm|Win32 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutCrtdll.ActiveCfg = ReleaseAxp|Win32 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutCrtdll.Build.0 = ReleaseAxp|Win32 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug.ActiveCfg = Debug|Win32 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug.Build.0 = Debug|Win32 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release.ActiveCfg = Release|Win32 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release.Build.0 = Release|Win32 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseAxp.ActiveCfg = ReleaseAxp|Win32 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseAxp.Build.0 = ReleaseAxp|Win32 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm.ActiveCfg = ReleaseWithoutAsm|Win32 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm.Build.0 = ReleaseWithoutAsm|Win32 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutCrtdll.ActiveCfg = ReleaseWithoutCrtdll|Win32 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutCrtdll.Build.0 = ReleaseWithoutCrtdll|Win32 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug.ActiveCfg = Debug|Win32 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug.Build.0 = Debug|Win32 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release.ActiveCfg = Release|Win32 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release.Build.0 = Release|Win32 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseAxp.ActiveCfg = Release|Win32 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseAxp.Build.0 = Release|Win32 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm.ActiveCfg = Release|Win32 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm.Build.0 = Release|Win32 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutCrtdll.ActiveCfg = Release|Win32 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutCrtdll.Build.0 = Release|Win32 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug.ActiveCfg = Debug|Win32 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug.Build.0 = Debug|Win32 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release.ActiveCfg = Release|Win32 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release.Build.0 = Release|Win32 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseAxp.ActiveCfg = Release|Win32 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseAxp.Build.0 = Release|Win32 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseWithoutAsm.ActiveCfg = Release|Win32 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseWithoutAsm.Build.0 = Release|Win32 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseWithoutCrtdll.ActiveCfg = Release|Win32 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseWithoutCrtdll.Build.0 = Release|Win32 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654C}.Debug.ActiveCfg = Debug|Win32 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654C}.Debug.Build.0 = Debug|Win32 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654C}.Release.ActiveCfg = Release|Win32 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654C}.Release.Build.0 = Release|Win32 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654C}.ReleaseAxp.ActiveCfg = Release|Win32 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654C}.ReleaseAxp.Build.0 = Release|Win32 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654C}.ReleaseWithoutAsm.ActiveCfg = Release|Win32 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654C}.ReleaseWithoutAsm.Build.0 = Release|Win32 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654C}.ReleaseWithoutCrtdll.ActiveCfg = Release|Win32 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654C}.ReleaseWithoutCrtdll.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + EndGlobalSection + GlobalSection(ExtensibilityAddIns) = postSolution + EndGlobalSection +EndGlobal diff --git a/libs/zlib/contrib/vstudio/vc7/zlibvc.vcproj b/libs/zlib/contrib/vstudio/vc7/zlibvc.vcproj new file mode 100644 index 000000000..8533b4947 --- /dev/null +++ b/libs/zlib/contrib/vstudio/vc7/zlibvc.vcproj @@ -0,0 +1,445 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/zlib/contrib/vstudio/vc8/miniunz.vcproj b/libs/zlib/contrib/vstudio/vc8/miniunz.vcproj new file mode 100644 index 000000000..4af53e8a3 --- /dev/null +++ b/libs/zlib/contrib/vstudio/vc8/miniunz.vcproj @@ -0,0 +1,566 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/zlib/contrib/vstudio/vc8/minizip.vcproj b/libs/zlib/contrib/vstudio/vc8/minizip.vcproj new file mode 100644 index 000000000..85f64c4d2 --- /dev/null +++ b/libs/zlib/contrib/vstudio/vc8/minizip.vcproj @@ -0,0 +1,563 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/zlib/contrib/vstudio/vc8/testzlib.vcproj b/libs/zlib/contrib/vstudio/vc8/testzlib.vcproj new file mode 100644 index 000000000..68c353991 --- /dev/null +++ b/libs/zlib/contrib/vstudio/vc8/testzlib.vcproj @@ -0,0 +1,948 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/zlib/contrib/vstudio/vc8/testzlibdll.vcproj b/libs/zlib/contrib/vstudio/vc8/testzlibdll.vcproj new file mode 100644 index 000000000..f38ab5e08 --- /dev/null +++ b/libs/zlib/contrib/vstudio/vc8/testzlibdll.vcproj @@ -0,0 +1,567 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/zlib/contrib/vstudio/vc8/zlib.rc b/libs/zlib/contrib/vstudio/vc8/zlib.rc new file mode 100644 index 000000000..58f756722 --- /dev/null +++ b/libs/zlib/contrib/vstudio/vc8/zlib.rc @@ -0,0 +1,32 @@ +#include + +#define IDR_VERSION1 1 +IDR_VERSION1 VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE + FILEVERSION 1,2,3,0 + PRODUCTVERSION 1,2,3,0 + FILEFLAGSMASK VS_FFI_FILEFLAGSMASK + FILEFLAGS 0 + FILEOS VOS_DOS_WINDOWS32 + FILETYPE VFT_DLL + FILESUBTYPE 0 // not used +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904E4" + //language ID = U.S. English, char set = Windows, Multilingual + + BEGIN + VALUE "FileDescription", "zlib data compression library\0" + VALUE "FileVersion", "1.2.3.0\0" + VALUE "InternalName", "zlib\0" + VALUE "OriginalFilename", "zlib.dll\0" + VALUE "ProductName", "ZLib.DLL\0" + VALUE "Comments","DLL support by Alessandro Iacopetti & Gilles Vollant\0" + VALUE "LegalCopyright", "(C) 1995-2003 Jean-loup Gailly & Mark Adler\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x0409, 1252 + END +END diff --git a/libs/zlib/contrib/vstudio/vc8/zlibstat.vcproj b/libs/zlib/contrib/vstudio/vc8/zlibstat.vcproj new file mode 100644 index 000000000..fb97037ac --- /dev/null +++ b/libs/zlib/contrib/vstudio/vc8/zlibstat.vcproj @@ -0,0 +1,870 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/zlib/contrib/vstudio/vc8/zlibvc.def b/libs/zlib/contrib/vstudio/vc8/zlibvc.def new file mode 100644 index 000000000..74dfdb8af --- /dev/null +++ b/libs/zlib/contrib/vstudio/vc8/zlibvc.def @@ -0,0 +1,92 @@ + +VERSION 1.23 + +HEAPSIZE 1048576,8192 + +EXPORTS + adler32 @1 + compress @2 + crc32 @3 + deflate @4 + deflateCopy @5 + deflateEnd @6 + deflateInit2_ @7 + deflateInit_ @8 + deflateParams @9 + deflateReset @10 + deflateSetDictionary @11 + gzclose @12 + gzdopen @13 + gzerror @14 + gzflush @15 + gzopen @16 + gzread @17 + gzwrite @18 + inflate @19 + inflateEnd @20 + inflateInit2_ @21 + inflateInit_ @22 + inflateReset @23 + inflateSetDictionary @24 + inflateSync @25 + uncompress @26 + zlibVersion @27 + gzprintf @28 + gzputc @29 + gzgetc @30 + gzseek @31 + gzrewind @32 + gztell @33 + gzeof @34 + gzsetparams @35 + zError @36 + inflateSyncPoint @37 + get_crc_table @38 + compress2 @39 + gzputs @40 + gzgets @41 + inflateCopy @42 + inflateBackInit_ @43 + inflateBack @44 + inflateBackEnd @45 + compressBound @46 + deflateBound @47 + gzclearerr @48 + gzungetc @49 + zlibCompileFlags @50 + deflatePrime @51 + + unzOpen @61 + unzClose @62 + unzGetGlobalInfo @63 + unzGetCurrentFileInfo @64 + unzGoToFirstFile @65 + unzGoToNextFile @66 + unzOpenCurrentFile @67 + unzReadCurrentFile @68 + unzOpenCurrentFile3 @69 + unztell @70 + unzeof @71 + unzCloseCurrentFile @72 + unzGetGlobalComment @73 + unzStringFileNameCompare @74 + unzLocateFile @75 + unzGetLocalExtrafield @76 + unzOpen2 @77 + unzOpenCurrentFile2 @78 + unzOpenCurrentFilePassword @79 + + zipOpen @80 + zipOpenNewFileInZip @81 + zipWriteInFileInZip @82 + zipCloseFileInZip @83 + zipClose @84 + zipOpenNewFileInZip2 @86 + zipCloseFileInZipRaw @87 + zipOpen2 @88 + zipOpenNewFileInZip3 @89 + + unzGetFilePos @100 + unzGoToFilePos @101 + + fill_win32_filefunc @110 diff --git a/libs/zlib/contrib/vstudio/vc8/zlibvc.sln b/libs/zlib/contrib/vstudio/vc8/zlibvc.sln new file mode 100644 index 000000000..a815a5549 --- /dev/null +++ b/libs/zlib/contrib/vstudio/vc8/zlibvc.sln @@ -0,0 +1,144 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlibvc", "zlibvc.vcproj", "{8FD826F8-3739-44E6-8CC8-997122E53B8D}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlibstat", "zlibstat.vcproj", "{745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testzlib", "testzlib.vcproj", "{AA6666AA-E09F-4135-9C0C-4FE50C3C654B}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestZlibDll", "testzlibdll.vcproj", "{C52F9E7B-498A-42BE-8DB4-85A15694366A}" + ProjectSection(ProjectDependencies) = postProject + {8FD826F8-3739-44E6-8CC8-997122E53B8D} = {8FD826F8-3739-44E6-8CC8-997122E53B8D} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "minizip", "minizip.vcproj", "{48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}" + ProjectSection(ProjectDependencies) = postProject + {8FD826F8-3739-44E6-8CC8-997122E53B8D} = {8FD826F8-3739-44E6-8CC8-997122E53B8D} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "miniunz", "miniunz.vcproj", "{C52F9E7B-498A-42BE-8DB4-85A15694382A}" + ProjectSection(ProjectDependencies) = postProject + {8FD826F8-3739-44E6-8CC8-997122E53B8D} = {8FD826F8-3739-44E6-8CC8-997122E53B8D} + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Itanium = Debug|Itanium + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Itanium = Release|Itanium + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + ReleaseWithoutAsm|Itanium = ReleaseWithoutAsm|Itanium + ReleaseWithoutAsm|Win32 = ReleaseWithoutAsm|Win32 + ReleaseWithoutAsm|x64 = ReleaseWithoutAsm|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug|Itanium.ActiveCfg = Debug|Itanium + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug|Itanium.Build.0 = Debug|Itanium + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug|Win32.ActiveCfg = Debug|Win32 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug|Win32.Build.0 = Debug|Win32 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug|x64.ActiveCfg = Debug|x64 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug|x64.Build.0 = Debug|x64 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release|Itanium.ActiveCfg = Release|Itanium + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release|Itanium.Build.0 = Release|Itanium + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release|Win32.ActiveCfg = Release|Win32 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release|Win32.Build.0 = Release|Win32 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release|x64.ActiveCfg = ReleaseWithoutAsm|x64 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release|x64.Build.0 = ReleaseWithoutAsm|x64 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm|Itanium.ActiveCfg = ReleaseWithoutAsm|Itanium + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm|Itanium.Build.0 = ReleaseWithoutAsm|Itanium + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm|Win32.ActiveCfg = ReleaseWithoutAsm|Win32 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm|Win32.Build.0 = ReleaseWithoutAsm|Win32 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm|x64.ActiveCfg = ReleaseWithoutAsm|x64 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm|x64.Build.0 = ReleaseWithoutAsm|x64 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug|Itanium.ActiveCfg = Debug|Itanium + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug|Itanium.Build.0 = Debug|Itanium + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug|Win32.ActiveCfg = Debug|Win32 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug|Win32.Build.0 = Debug|Win32 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug|x64.ActiveCfg = Debug|x64 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug|x64.Build.0 = Debug|x64 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release|Itanium.ActiveCfg = Release|Itanium + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release|Itanium.Build.0 = Release|Itanium + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release|Win32.ActiveCfg = Release|Win32 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release|Win32.Build.0 = Release|Win32 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release|x64.ActiveCfg = Release|x64 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release|x64.Build.0 = Release|x64 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm|Itanium.ActiveCfg = ReleaseWithoutAsm|Itanium + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm|Itanium.Build.0 = ReleaseWithoutAsm|Itanium + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm|Win32.ActiveCfg = ReleaseWithoutAsm|Win32 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm|Win32.Build.0 = ReleaseWithoutAsm|Win32 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm|x64.ActiveCfg = ReleaseWithoutAsm|x64 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm|x64.Build.0 = ReleaseWithoutAsm|x64 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug|Itanium.ActiveCfg = Debug|Itanium + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug|Itanium.Build.0 = Debug|Itanium + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug|Win32.ActiveCfg = Debug|Win32 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug|Win32.Build.0 = Debug|Win32 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug|x64.ActiveCfg = Debug|x64 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug|x64.Build.0 = Debug|x64 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release|Itanium.ActiveCfg = Release|Itanium + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release|Itanium.Build.0 = Release|Itanium + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release|Win32.ActiveCfg = Release|Win32 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release|Win32.Build.0 = Release|Win32 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release|x64.ActiveCfg = Release|x64 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release|x64.Build.0 = Release|x64 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Itanium.ActiveCfg = ReleaseWithoutAsm|Itanium + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Itanium.Build.0 = ReleaseWithoutAsm|Itanium + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Win32.ActiveCfg = ReleaseWithoutAsm|Win32 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Win32.Build.0 = ReleaseWithoutAsm|Win32 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|x64.ActiveCfg = ReleaseWithoutAsm|x64 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|x64.Build.0 = ReleaseWithoutAsm|x64 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Debug|Itanium.ActiveCfg = Debug|Itanium + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Debug|Itanium.Build.0 = Debug|Itanium + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Debug|Win32.ActiveCfg = Debug|Win32 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Debug|Win32.Build.0 = Debug|Win32 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Debug|x64.ActiveCfg = Debug|x64 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Debug|x64.Build.0 = Debug|x64 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Release|Itanium.ActiveCfg = Release|Itanium + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Release|Itanium.Build.0 = Release|Itanium + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Release|Win32.ActiveCfg = Release|Win32 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Release|Win32.Build.0 = Release|Win32 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Release|x64.ActiveCfg = Release|x64 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Release|x64.Build.0 = Release|x64 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.ReleaseWithoutAsm|Itanium.ActiveCfg = Release|Itanium + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.ReleaseWithoutAsm|Itanium.Build.0 = Release|Itanium + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.ReleaseWithoutAsm|Win32.ActiveCfg = Release|Itanium + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.ReleaseWithoutAsm|x64.ActiveCfg = Release|Itanium + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug|Itanium.ActiveCfg = Debug|Itanium + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug|Itanium.Build.0 = Debug|Itanium + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug|Win32.ActiveCfg = Debug|Win32 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug|Win32.Build.0 = Debug|Win32 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug|x64.ActiveCfg = Debug|x64 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug|x64.Build.0 = Debug|x64 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release|Itanium.ActiveCfg = Release|Itanium + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release|Itanium.Build.0 = Release|Itanium + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release|Win32.ActiveCfg = Release|Win32 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release|Win32.Build.0 = Release|Win32 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release|x64.ActiveCfg = Release|x64 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release|x64.Build.0 = Release|x64 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Itanium.ActiveCfg = Release|Itanium + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Itanium.Build.0 = Release|Itanium + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Win32.ActiveCfg = Release|Itanium + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|x64.ActiveCfg = Release|Itanium + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug|Itanium.ActiveCfg = Debug|Itanium + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug|Itanium.Build.0 = Debug|Itanium + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug|Win32.ActiveCfg = Debug|Win32 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug|Win32.Build.0 = Debug|Win32 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug|x64.ActiveCfg = Debug|x64 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug|x64.Build.0 = Debug|x64 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release|Itanium.ActiveCfg = Release|Itanium + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release|Itanium.Build.0 = Release|Itanium + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release|Win32.ActiveCfg = Release|Win32 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release|Win32.Build.0 = Release|Win32 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release|x64.ActiveCfg = Release|x64 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release|x64.Build.0 = Release|x64 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseWithoutAsm|Itanium.ActiveCfg = Release|Itanium + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseWithoutAsm|Itanium.Build.0 = Release|Itanium + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseWithoutAsm|Win32.ActiveCfg = Release|Itanium + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseWithoutAsm|x64.ActiveCfg = Release|Itanium + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/libs/zlib/contrib/vstudio/vc8/zlibvc.vcproj b/libs/zlib/contrib/vstudio/vc8/zlibvc.vcproj new file mode 100644 index 000000000..e717011df --- /dev/null +++ b/libs/zlib/contrib/vstudio/vc8/zlibvc.vcproj @@ -0,0 +1,1219 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/zlib/contrib/vstudio/vc9/miniunz.vcproj b/libs/zlib/contrib/vstudio/vc9/miniunz.vcproj new file mode 100644 index 000000000..7da32b91e --- /dev/null +++ b/libs/zlib/contrib/vstudio/vc9/miniunz.vcproj @@ -0,0 +1,565 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/zlib/contrib/vstudio/vc9/minizip.vcproj b/libs/zlib/contrib/vstudio/vc9/minizip.vcproj new file mode 100644 index 000000000..e57e07d90 --- /dev/null +++ b/libs/zlib/contrib/vstudio/vc9/minizip.vcproj @@ -0,0 +1,562 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/zlib/contrib/vstudio/vc9/testzlib.vcproj b/libs/zlib/contrib/vstudio/vc9/testzlib.vcproj new file mode 100644 index 000000000..9cb0bf877 --- /dev/null +++ b/libs/zlib/contrib/vstudio/vc9/testzlib.vcproj @@ -0,0 +1,852 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/zlib/contrib/vstudio/vc9/testzlibdll.vcproj b/libs/zlib/contrib/vstudio/vc9/testzlibdll.vcproj new file mode 100644 index 000000000..b1ddde05f --- /dev/null +++ b/libs/zlib/contrib/vstudio/vc9/testzlibdll.vcproj @@ -0,0 +1,565 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/zlib/contrib/vstudio/vc9/zlib.rc b/libs/zlib/contrib/vstudio/vc9/zlib.rc new file mode 100644 index 000000000..863b59c78 --- /dev/null +++ b/libs/zlib/contrib/vstudio/vc9/zlib.rc @@ -0,0 +1,32 @@ +#include + +#define IDR_VERSION1 1 +IDR_VERSION1 VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE + FILEVERSION 1,2,5,0 + PRODUCTVERSION 1,2,5,0 + FILEFLAGSMASK VS_FFI_FILEFLAGSMASK + FILEFLAGS 0 + FILEOS VOS_DOS_WINDOWS32 + FILETYPE VFT_DLL + FILESUBTYPE 0 // not used +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904E4" + //language ID = U.S. English, char set = Windows, Multilingual + + BEGIN + VALUE "FileDescription", "zlib data compression and ZIP file I/O library\0" + VALUE "FileVersion", "1.2.5.0\0" + VALUE "InternalName", "zlib\0" + VALUE "OriginalFilename", "zlib.dll\0" + VALUE "ProductName", "ZLib.DLL\0" + VALUE "Comments","DLL support by Alessandro Iacopetti & Gilles Vollant\0" + VALUE "LegalCopyright", "(C) 1995-2010 Jean-loup Gailly & Mark Adler\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x0409, 1252 + END +END diff --git a/libs/zlib/contrib/vstudio/vc9/zlibstat.vcproj b/libs/zlib/contrib/vstudio/vc9/zlibstat.vcproj new file mode 100644 index 000000000..61c76c7c5 --- /dev/null +++ b/libs/zlib/contrib/vstudio/vc9/zlibstat.vcproj @@ -0,0 +1,835 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/zlib/contrib/vstudio/vc9/zlibvc.def b/libs/zlib/contrib/vstudio/vc9/zlibvc.def new file mode 100644 index 000000000..fa171ae92 --- /dev/null +++ b/libs/zlib/contrib/vstudio/vc9/zlibvc.def @@ -0,0 +1,130 @@ +LIBRARY +; zlib data compression and ZIP file I/O library + +VERSION 1.24 + +EXPORTS + adler32 @1 + compress @2 + crc32 @3 + deflate @4 + deflateCopy @5 + deflateEnd @6 + deflateInit2_ @7 + deflateInit_ @8 + deflateParams @9 + deflateReset @10 + deflateSetDictionary @11 + gzclose @12 + gzdopen @13 + gzerror @14 + gzflush @15 + gzopen @16 + gzread @17 + gzwrite @18 + inflate @19 + inflateEnd @20 + inflateInit2_ @21 + inflateInit_ @22 + inflateReset @23 + inflateSetDictionary @24 + inflateSync @25 + uncompress @26 + zlibVersion @27 + gzprintf @28 + gzputc @29 + gzgetc @30 + gzseek @31 + gzrewind @32 + gztell @33 + gzeof @34 + gzsetparams @35 + zError @36 + inflateSyncPoint @37 + get_crc_table @38 + compress2 @39 + gzputs @40 + gzgets @41 + inflateCopy @42 + inflateBackInit_ @43 + inflateBack @44 + inflateBackEnd @45 + compressBound @46 + deflateBound @47 + gzclearerr @48 + gzungetc @49 + zlibCompileFlags @50 + deflatePrime @51 + + unzOpen @61 + unzClose @62 + unzGetGlobalInfo @63 + unzGetCurrentFileInfo @64 + unzGoToFirstFile @65 + unzGoToNextFile @66 + unzOpenCurrentFile @67 + unzReadCurrentFile @68 + unzOpenCurrentFile3 @69 + unztell @70 + unzeof @71 + unzCloseCurrentFile @72 + unzGetGlobalComment @73 + unzStringFileNameCompare @74 + unzLocateFile @75 + unzGetLocalExtrafield @76 + unzOpen2 @77 + unzOpenCurrentFile2 @78 + unzOpenCurrentFilePassword @79 + + zipOpen @80 + zipOpenNewFileInZip @81 + zipWriteInFileInZip @82 + zipCloseFileInZip @83 + zipClose @84 + zipOpenNewFileInZip2 @86 + zipCloseFileInZipRaw @87 + zipOpen2 @88 + zipOpenNewFileInZip3 @89 + + unzGetFilePos @100 + unzGoToFilePos @101 + + fill_win32_filefunc @110 + +; zlibwapi v1.2.4 added: + fill_win32_filefunc64 @111 + fill_win32_filefunc64A @112 + fill_win32_filefunc64W @113 + + unzOpen64 @120 + unzOpen2_64 @121 + unzGetGlobalInfo64 @122 + unzGetCurrentFileInfo64 @124 + unzGetCurrentFileZStreamPos64 @125 + unztell64 @126 + unzGetFilePos64 @127 + unzGoToFilePos64 @128 + + zipOpen64 @130 + zipOpen2_64 @131 + zipOpenNewFileInZip64 @132 + zipOpenNewFileInZip2_64 @133 + zipOpenNewFileInZip3_64 @134 + zipOpenNewFileInZip4_64 @135 + zipCloseFileInZipRaw64 @136 + +; zlib1 v1.2.4 added: + adler32_combine @140 + crc32_combine @142 + deflateSetHeader @144 + deflateTune @145 + gzbuffer @146 + gzclose_r @147 + gzclose_w @148 + gzdirect @149 + gzoffset @150 + inflateGetHeader @156 + inflateMark @157 + inflatePrime @158 + inflateReset2 @159 + inflateUndermine @160 diff --git a/libs/zlib/contrib/vstudio/vc9/zlibvc.sln b/libs/zlib/contrib/vstudio/vc9/zlibvc.sln new file mode 100644 index 000000000..b4829671f --- /dev/null +++ b/libs/zlib/contrib/vstudio/vc9/zlibvc.sln @@ -0,0 +1,144 @@ + +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual Studio 2008 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlibvc", "zlibvc.vcproj", "{8FD826F8-3739-44E6-8CC8-997122E53B8D}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlibstat", "zlibstat.vcproj", "{745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testzlib", "testzlib.vcproj", "{AA6666AA-E09F-4135-9C0C-4FE50C3C654B}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestZlibDll", "testzlibdll.vcproj", "{C52F9E7B-498A-42BE-8DB4-85A15694366A}" + ProjectSection(ProjectDependencies) = postProject + {8FD826F8-3739-44E6-8CC8-997122E53B8D} = {8FD826F8-3739-44E6-8CC8-997122E53B8D} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "minizip", "minizip.vcproj", "{48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}" + ProjectSection(ProjectDependencies) = postProject + {8FD826F8-3739-44E6-8CC8-997122E53B8D} = {8FD826F8-3739-44E6-8CC8-997122E53B8D} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "miniunz", "miniunz.vcproj", "{C52F9E7B-498A-42BE-8DB4-85A15694382A}" + ProjectSection(ProjectDependencies) = postProject + {8FD826F8-3739-44E6-8CC8-997122E53B8D} = {8FD826F8-3739-44E6-8CC8-997122E53B8D} + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Itanium = Debug|Itanium + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Itanium = Release|Itanium + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + ReleaseWithoutAsm|Itanium = ReleaseWithoutAsm|Itanium + ReleaseWithoutAsm|Win32 = ReleaseWithoutAsm|Win32 + ReleaseWithoutAsm|x64 = ReleaseWithoutAsm|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug|Itanium.ActiveCfg = Debug|Itanium + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug|Itanium.Build.0 = Debug|Itanium + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug|Win32.ActiveCfg = Debug|Win32 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug|Win32.Build.0 = Debug|Win32 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug|x64.ActiveCfg = Debug|x64 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug|x64.Build.0 = Debug|x64 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release|Itanium.ActiveCfg = Release|Itanium + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release|Itanium.Build.0 = Release|Itanium + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release|Win32.ActiveCfg = Release|Win32 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release|Win32.Build.0 = Release|Win32 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release|x64.ActiveCfg = Release|x64 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release|x64.Build.0 = Release|x64 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm|Itanium.ActiveCfg = ReleaseWithoutAsm|Itanium + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm|Itanium.Build.0 = ReleaseWithoutAsm|Itanium + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm|Win32.ActiveCfg = ReleaseWithoutAsm|Win32 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm|Win32.Build.0 = ReleaseWithoutAsm|Win32 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm|x64.ActiveCfg = ReleaseWithoutAsm|x64 + {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm|x64.Build.0 = ReleaseWithoutAsm|x64 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug|Itanium.ActiveCfg = Debug|Itanium + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug|Itanium.Build.0 = Debug|Itanium + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug|Win32.ActiveCfg = Debug|Win32 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug|Win32.Build.0 = Debug|Win32 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug|x64.ActiveCfg = Debug|x64 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug|x64.Build.0 = Debug|x64 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release|Itanium.ActiveCfg = Release|Itanium + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release|Itanium.Build.0 = Release|Itanium + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release|Win32.ActiveCfg = Release|Win32 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release|Win32.Build.0 = Release|Win32 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release|x64.ActiveCfg = Release|x64 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release|x64.Build.0 = Release|x64 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm|Itanium.ActiveCfg = ReleaseWithoutAsm|Itanium + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm|Itanium.Build.0 = ReleaseWithoutAsm|Itanium + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm|Win32.ActiveCfg = ReleaseWithoutAsm|Win32 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm|Win32.Build.0 = ReleaseWithoutAsm|Win32 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm|x64.ActiveCfg = ReleaseWithoutAsm|x64 + {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm|x64.Build.0 = ReleaseWithoutAsm|x64 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug|Itanium.ActiveCfg = Debug|Itanium + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug|Itanium.Build.0 = Debug|Itanium + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug|Win32.ActiveCfg = Debug|Win32 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug|Win32.Build.0 = Debug|Win32 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug|x64.ActiveCfg = Debug|x64 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug|x64.Build.0 = Debug|x64 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release|Itanium.ActiveCfg = Release|Itanium + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release|Itanium.Build.0 = Release|Itanium + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release|Win32.ActiveCfg = Release|Win32 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release|Win32.Build.0 = Release|Win32 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release|x64.ActiveCfg = Release|x64 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release|x64.Build.0 = Release|x64 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Itanium.ActiveCfg = ReleaseWithoutAsm|Itanium + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Itanium.Build.0 = ReleaseWithoutAsm|Itanium + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Win32.ActiveCfg = ReleaseWithoutAsm|Win32 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Win32.Build.0 = ReleaseWithoutAsm|Win32 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|x64.ActiveCfg = ReleaseWithoutAsm|x64 + {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|x64.Build.0 = ReleaseWithoutAsm|x64 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Debug|Itanium.ActiveCfg = Debug|Itanium + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Debug|Itanium.Build.0 = Debug|Itanium + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Debug|Win32.ActiveCfg = Debug|Win32 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Debug|Win32.Build.0 = Debug|Win32 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Debug|x64.ActiveCfg = Debug|x64 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Debug|x64.Build.0 = Debug|x64 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Release|Itanium.ActiveCfg = Release|Itanium + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Release|Itanium.Build.0 = Release|Itanium + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Release|Win32.ActiveCfg = Release|Win32 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Release|Win32.Build.0 = Release|Win32 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Release|x64.ActiveCfg = Release|x64 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Release|x64.Build.0 = Release|x64 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.ReleaseWithoutAsm|Itanium.ActiveCfg = Release|Itanium + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.ReleaseWithoutAsm|Itanium.Build.0 = Release|Itanium + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.ReleaseWithoutAsm|Win32.ActiveCfg = Release|Win32 + {C52F9E7B-498A-42BE-8DB4-85A15694366A}.ReleaseWithoutAsm|x64.ActiveCfg = Release|x64 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug|Itanium.ActiveCfg = Debug|Itanium + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug|Itanium.Build.0 = Debug|Itanium + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug|Win32.ActiveCfg = Debug|Win32 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug|Win32.Build.0 = Debug|Win32 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug|x64.ActiveCfg = Debug|x64 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug|x64.Build.0 = Debug|x64 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release|Itanium.ActiveCfg = Release|Itanium + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release|Itanium.Build.0 = Release|Itanium + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release|Win32.ActiveCfg = Release|Win32 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release|Win32.Build.0 = Release|Win32 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release|x64.ActiveCfg = Release|x64 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release|x64.Build.0 = Release|x64 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Itanium.ActiveCfg = Release|Itanium + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Itanium.Build.0 = Release|Itanium + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Win32.ActiveCfg = Release|Win32 + {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|x64.ActiveCfg = Release|x64 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug|Itanium.ActiveCfg = Debug|Itanium + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug|Itanium.Build.0 = Debug|Itanium + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug|Win32.ActiveCfg = Debug|Win32 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug|Win32.Build.0 = Debug|Win32 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug|x64.ActiveCfg = Debug|x64 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug|x64.Build.0 = Debug|x64 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release|Itanium.ActiveCfg = Release|Itanium + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release|Itanium.Build.0 = Release|Itanium + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release|Win32.ActiveCfg = Release|Win32 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release|Win32.Build.0 = Release|Win32 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release|x64.ActiveCfg = Release|x64 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release|x64.Build.0 = Release|x64 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseWithoutAsm|Itanium.ActiveCfg = Release|Itanium + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseWithoutAsm|Itanium.Build.0 = Release|Itanium + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseWithoutAsm|Win32.ActiveCfg = Release|Win32 + {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseWithoutAsm|x64.ActiveCfg = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/libs/zlib/contrib/vstudio/vc9/zlibvc.vcproj b/libs/zlib/contrib/vstudio/vc9/zlibvc.vcproj new file mode 100644 index 000000000..c9a89471e --- /dev/null +++ b/libs/zlib/contrib/vstudio/vc9/zlibvc.vcproj @@ -0,0 +1,1156 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/zlib/crc32.c b/libs/zlib/crc32.c new file mode 100644 index 000000000..c12471e61 --- /dev/null +++ b/libs/zlib/crc32.c @@ -0,0 +1,447 @@ +/* crc32.c -- compute the CRC-32 of a data stream + * Copyright (C) 1995-2006, 2010, 2011 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + * + * Thanks to Rodney Brown for his contribution of faster + * CRC methods: exclusive-oring 32 bits of data at a time, and pre-computing + * tables for updating the shift register in one step with three exclusive-ors + * instead of four steps with four exclusive-ors. This results in about a + * factor of two increase in speed on a Power PC G4 (PPC7455) using gcc -O3. + */ + +/* @(#) $Id$ */ + +/* + Note on the use of DYNAMIC_CRC_TABLE: there is no mutex or semaphore + protection on the static variables used to control the first-use generation + of the crc tables. Therefore, if you #define DYNAMIC_CRC_TABLE, you should + first call get_crc_table() to initialize the tables before allowing more than + one thread to use crc32(). + + DYNAMIC_CRC_TABLE and MAKECRCH can be #defined to write out crc32.h. + */ + +#ifdef MAKECRCH +# include +# ifndef DYNAMIC_CRC_TABLE +# define DYNAMIC_CRC_TABLE +# endif /* !DYNAMIC_CRC_TABLE */ +#endif /* MAKECRCH */ + +#include "zutil.h" /* for STDC and FAR definitions */ + +#define local static + +/* Find a four-byte integer type for crc32_little() and crc32_big(). */ +#ifndef NOBYFOUR +# ifdef STDC /* need ANSI C limits.h to determine sizes */ +# include +# define BYFOUR +# if (UINT_MAX == 0xffffffffUL) + typedef unsigned int u4; +# else +# if (ULONG_MAX == 0xffffffffUL) + typedef unsigned long u4; +# else +# if (USHRT_MAX == 0xffffffffUL) + typedef unsigned short u4; +# else +# undef BYFOUR /* can't find a four-byte integer type! */ +# endif +# endif +# endif +# endif /* STDC */ +#endif /* !NOBYFOUR */ + +/* Definitions for doing the crc four data bytes at a time. */ +#ifdef BYFOUR + typedef u4 crc_table_t; +# define REV(w) ((((w)>>24)&0xff)+(((w)>>8)&0xff00)+ \ + (((w)&0xff00)<<8)+(((w)&0xff)<<24)) + local unsigned long crc32_little OF((unsigned long, + const unsigned char FAR *, unsigned)); + local unsigned long crc32_big OF((unsigned long, + const unsigned char FAR *, unsigned)); +# define TBLS 8 +#else + typedef unsigned long crc_table_t; +# define TBLS 1 +#endif /* BYFOUR */ + +/* Local functions for crc concatenation */ +local unsigned long gf2_matrix_times OF((unsigned long *mat, + unsigned long vec)); +local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat)); +local uLong crc32_combine_ OF((uLong crc1, uLong crc2, z_off64_t len2)); + + +#ifdef DYNAMIC_CRC_TABLE + +local volatile int crc_table_empty = 1; +local crc_table_t FAR crc_table[TBLS][256]; +local void make_crc_table OF((void)); +#ifdef MAKECRCH + local void write_table OF((FILE *, const crc_table_t FAR *)); +#endif /* MAKECRCH */ +/* + Generate tables for a byte-wise 32-bit CRC calculation on the polynomial: + x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1. + + Polynomials over GF(2) are represented in binary, one bit per coefficient, + with the lowest powers in the most significant bit. Then adding polynomials + is just exclusive-or, and multiplying a polynomial by x is a right shift by + one. If we call the above polynomial p, and represent a byte as the + polynomial q, also with the lowest power in the most significant bit (so the + byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p, + where a mod b means the remainder after dividing a by b. + + This calculation is done using the shift-register method of multiplying and + taking the remainder. The register is initialized to zero, and for each + incoming bit, x^32 is added mod p to the register if the bit is a one (where + x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by + x (which is shifting right by one and adding x^32 mod p if the bit shifted + out is a one). We start with the highest power (least significant bit) of + q and repeat for all eight bits of q. + + The first table is simply the CRC of all possible eight bit values. This is + all the information needed to generate CRCs on data a byte at a time for all + combinations of CRC register values and incoming bytes. The remaining tables + allow for word-at-a-time CRC calculation for both big-endian and little- + endian machines, where a word is four bytes. +*/ +local void make_crc_table() +{ + crc_table_t c; + int n, k; + crc_table_t poly; /* polynomial exclusive-or pattern */ + /* terms of polynomial defining this crc (except x^32): */ + static volatile int first = 1; /* flag to limit concurrent making */ + static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26}; + + /* See if another task is already doing this (not thread-safe, but better + than nothing -- significantly reduces duration of vulnerability in + case the advice about DYNAMIC_CRC_TABLE is ignored) */ + if (first) { + first = 0; + + /* make exclusive-or pattern from polynomial (0xedb88320UL) */ + poly = 0; + for (n = 0; n < (int)(sizeof(p)/sizeof(unsigned char)); n++) + poly |= (crc_table_t)1 << (31 - p[n]); + + /* generate a crc for every 8-bit value */ + for (n = 0; n < 256; n++) { + c = (crc_table_t)n; + for (k = 0; k < 8; k++) + c = c & 1 ? poly ^ (c >> 1) : c >> 1; + crc_table[0][n] = c; + } + +#ifdef BYFOUR + /* generate crc for each value followed by one, two, and three zeros, + and then the byte reversal of those as well as the first table */ + for (n = 0; n < 256; n++) { + c = crc_table[0][n]; + crc_table[4][n] = REV(c); + for (k = 1; k < 4; k++) { + c = crc_table[0][c & 0xff] ^ (c >> 8); + crc_table[k][n] = c; + crc_table[k + 4][n] = REV(c); + } + } +#endif /* BYFOUR */ + + crc_table_empty = 0; + } + else { /* not first */ + /* wait for the other guy to finish (not efficient, but rare) */ + while (crc_table_empty) + ; + } + +#ifdef MAKECRCH + /* write out CRC tables to crc32.h */ + { + FILE *out; + + out = fopen("crc32.h", "w"); + if (out == NULL) return; + fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n"); + fprintf(out, " * Generated automatically by crc32.c\n */\n\n"); + fprintf(out, "local const crc_table_t FAR "); + fprintf(out, "crc_table[TBLS][256] =\n{\n {\n"); + write_table(out, crc_table[0]); +# ifdef BYFOUR + fprintf(out, "#ifdef BYFOUR\n"); + for (k = 1; k < 8; k++) { + fprintf(out, " },\n {\n"); + write_table(out, crc_table[k]); + } + fprintf(out, "#endif\n"); +# endif /* BYFOUR */ + fprintf(out, " }\n};\n"); + fclose(out); + } +#endif /* MAKECRCH */ +} + +#ifdef MAKECRCH +local void write_table(out, table) + FILE *out; + const crc_table_t FAR *table; +{ + int n; + + for (n = 0; n < 256; n++) + fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", + (unsigned long)(table[n]), + n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", ")); +} +#endif /* MAKECRCH */ + +#else /* !DYNAMIC_CRC_TABLE */ +/* ======================================================================== + * Tables of CRC-32s of all single-byte values, made by make_crc_table(). + */ +#include "crc32.h" +#endif /* DYNAMIC_CRC_TABLE */ + +/* ========================================================================= + * This function can be used by asm versions of crc32() + */ +const unsigned long FAR * ZEXPORT get_crc_table() +{ +#ifdef DYNAMIC_CRC_TABLE + if (crc_table_empty) + make_crc_table(); +#endif /* DYNAMIC_CRC_TABLE */ + return (const unsigned long FAR *)crc_table; +} + +/* ========================================================================= */ +#define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8) +#define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1 + +/* ========================================================================= */ +unsigned long ZEXPORT crc32(crc, buf, len) + unsigned long crc; + const unsigned char FAR *buf; + uInt len; +{ + if (buf == Z_NULL) return 0UL; + +#ifdef DYNAMIC_CRC_TABLE + if (crc_table_empty) + make_crc_table(); +#endif /* DYNAMIC_CRC_TABLE */ + +#ifdef BYFOUR + if (sizeof(void *) == sizeof(ptrdiff_t)) { + u4 endian; + + endian = 1; + if (*((unsigned char *)(&endian))) + return crc32_little(crc, buf, len); + else + return crc32_big(crc, buf, len); + } +#endif /* BYFOUR */ + crc = crc ^ 0xffffffffUL; + while (len >= 8) { + DO8; + len -= 8; + } + if (len) do { + DO1; + } while (--len); + return crc ^ 0xffffffffUL; +} + +#ifdef BYFOUR + +/* ========================================================================= */ +#define DOLIT4 c ^= *buf4++; \ + c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \ + crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24] +#define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4 + +/* ========================================================================= */ +local unsigned long crc32_little(crc, buf, len) + unsigned long crc; + const unsigned char FAR *buf; + unsigned len; +{ + register u4 c; + register const u4 FAR *buf4; + + c = (u4)crc; + c = ~c; + while (len && ((ptrdiff_t)buf & 3)) { + c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8); + len--; + } + + buf4 = (const u4 FAR *)(const void FAR *)buf; + while (len >= 32) { + DOLIT32; + len -= 32; + } + while (len >= 4) { + DOLIT4; + len -= 4; + } + buf = (const unsigned char FAR *)buf4; + + if (len) do { + c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8); + } while (--len); + c = ~c; + return (unsigned long)c; +} + +/* ========================================================================= */ +#define DOBIG4 c ^= *++buf4; \ + c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \ + crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24] +#define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4 + +/* ========================================================================= */ +local unsigned long crc32_big(crc, buf, len) + unsigned long crc; + const unsigned char FAR *buf; + unsigned len; +{ + register u4 c; + register const u4 FAR *buf4; + + c = REV((u4)crc); + c = ~c; + while (len && ((ptrdiff_t)buf & 3)) { + c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8); + len--; + } + + buf4 = (const u4 FAR *)(const void FAR *)buf; + buf4--; + while (len >= 32) { + DOBIG32; + len -= 32; + } + while (len >= 4) { + DOBIG4; + len -= 4; + } + buf4++; + buf = (const unsigned char FAR *)buf4; + + if (len) do { + c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8); + } while (--len); + c = ~c; + return (unsigned long)(REV(c)); +} + +#endif /* BYFOUR */ + +#define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */ + +/* ========================================================================= */ +local unsigned long gf2_matrix_times(mat, vec) + unsigned long *mat; + unsigned long vec; +{ + unsigned long sum; + + sum = 0; + while (vec) { + if (vec & 1) + sum ^= *mat; + vec >>= 1; + mat++; + } + return sum; +} + +/* ========================================================================= */ +local void gf2_matrix_square(square, mat) + unsigned long *square; + unsigned long *mat; +{ + int n; + + for (n = 0; n < GF2_DIM; n++) + square[n] = gf2_matrix_times(mat, mat[n]); +} + +/* ========================================================================= */ +local uLong crc32_combine_(crc1, crc2, len2) + uLong crc1; + uLong crc2; + z_off64_t len2; +{ + int n; + unsigned long row; + unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */ + unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */ + + /* degenerate case (also disallow negative lengths) */ + if (len2 <= 0) + return crc1; + + /* put operator for one zero bit in odd */ + odd[0] = 0xedb88320UL; /* CRC-32 polynomial */ + row = 1; + for (n = 1; n < GF2_DIM; n++) { + odd[n] = row; + row <<= 1; + } + + /* put operator for two zero bits in even */ + gf2_matrix_square(even, odd); + + /* put operator for four zero bits in odd */ + gf2_matrix_square(odd, even); + + /* apply len2 zeros to crc1 (first square will put the operator for one + zero byte, eight zero bits, in even) */ + do { + /* apply zeros operator for this bit of len2 */ + gf2_matrix_square(even, odd); + if (len2 & 1) + crc1 = gf2_matrix_times(even, crc1); + len2 >>= 1; + + /* if no more bits set, then done */ + if (len2 == 0) + break; + + /* another iteration of the loop with odd and even swapped */ + gf2_matrix_square(odd, even); + if (len2 & 1) + crc1 = gf2_matrix_times(odd, crc1); + len2 >>= 1; + + /* if no more bits set, then done */ + } while (len2 != 0); + + /* return combined crc */ + crc1 ^= crc2; + return crc1; +} + +/* ========================================================================= */ +uLong ZEXPORT crc32_combine(crc1, crc2, len2) + uLong crc1; + uLong crc2; + z_off_t len2; +{ + return crc32_combine_(crc1, crc2, len2); +} + +uLong ZEXPORT crc32_combine64(crc1, crc2, len2) + uLong crc1; + uLong crc2; + z_off64_t len2; +{ + return crc32_combine_(crc1, crc2, len2); +} diff --git a/libs/zlib/crc32.h b/libs/zlib/crc32.h new file mode 100644 index 000000000..c3e7171c5 --- /dev/null +++ b/libs/zlib/crc32.h @@ -0,0 +1,441 @@ +/* crc32.h -- tables for rapid CRC calculation + * Generated automatically by crc32.c + */ + +local const crc_table_t FAR crc_table[TBLS][256] = +{ + { + 0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL, + 0x706af48fUL, 0xe963a535UL, 0x9e6495a3UL, 0x0edb8832UL, 0x79dcb8a4UL, + 0xe0d5e91eUL, 0x97d2d988UL, 0x09b64c2bUL, 0x7eb17cbdUL, 0xe7b82d07UL, + 0x90bf1d91UL, 0x1db71064UL, 0x6ab020f2UL, 0xf3b97148UL, 0x84be41deUL, + 0x1adad47dUL, 0x6ddde4ebUL, 0xf4d4b551UL, 0x83d385c7UL, 0x136c9856UL, + 0x646ba8c0UL, 0xfd62f97aUL, 0x8a65c9ecUL, 0x14015c4fUL, 0x63066cd9UL, + 0xfa0f3d63UL, 0x8d080df5UL, 0x3b6e20c8UL, 0x4c69105eUL, 0xd56041e4UL, + 0xa2677172UL, 0x3c03e4d1UL, 0x4b04d447UL, 0xd20d85fdUL, 0xa50ab56bUL, + 0x35b5a8faUL, 0x42b2986cUL, 0xdbbbc9d6UL, 0xacbcf940UL, 0x32d86ce3UL, + 0x45df5c75UL, 0xdcd60dcfUL, 0xabd13d59UL, 0x26d930acUL, 0x51de003aUL, + 0xc8d75180UL, 0xbfd06116UL, 0x21b4f4b5UL, 0x56b3c423UL, 0xcfba9599UL, + 0xb8bda50fUL, 0x2802b89eUL, 0x5f058808UL, 0xc60cd9b2UL, 0xb10be924UL, + 0x2f6f7c87UL, 0x58684c11UL, 0xc1611dabUL, 0xb6662d3dUL, 0x76dc4190UL, + 0x01db7106UL, 0x98d220bcUL, 0xefd5102aUL, 0x71b18589UL, 0x06b6b51fUL, + 0x9fbfe4a5UL, 0xe8b8d433UL, 0x7807c9a2UL, 0x0f00f934UL, 0x9609a88eUL, + 0xe10e9818UL, 0x7f6a0dbbUL, 0x086d3d2dUL, 0x91646c97UL, 0xe6635c01UL, + 0x6b6b51f4UL, 0x1c6c6162UL, 0x856530d8UL, 0xf262004eUL, 0x6c0695edUL, + 0x1b01a57bUL, 0x8208f4c1UL, 0xf50fc457UL, 0x65b0d9c6UL, 0x12b7e950UL, + 0x8bbeb8eaUL, 0xfcb9887cUL, 0x62dd1ddfUL, 0x15da2d49UL, 0x8cd37cf3UL, + 0xfbd44c65UL, 0x4db26158UL, 0x3ab551ceUL, 0xa3bc0074UL, 0xd4bb30e2UL, + 0x4adfa541UL, 0x3dd895d7UL, 0xa4d1c46dUL, 0xd3d6f4fbUL, 0x4369e96aUL, + 0x346ed9fcUL, 0xad678846UL, 0xda60b8d0UL, 0x44042d73UL, 0x33031de5UL, + 0xaa0a4c5fUL, 0xdd0d7cc9UL, 0x5005713cUL, 0x270241aaUL, 0xbe0b1010UL, + 0xc90c2086UL, 0x5768b525UL, 0x206f85b3UL, 0xb966d409UL, 0xce61e49fUL, + 0x5edef90eUL, 0x29d9c998UL, 0xb0d09822UL, 0xc7d7a8b4UL, 0x59b33d17UL, + 0x2eb40d81UL, 0xb7bd5c3bUL, 0xc0ba6cadUL, 0xedb88320UL, 0x9abfb3b6UL, + 0x03b6e20cUL, 0x74b1d29aUL, 0xead54739UL, 0x9dd277afUL, 0x04db2615UL, + 0x73dc1683UL, 0xe3630b12UL, 0x94643b84UL, 0x0d6d6a3eUL, 0x7a6a5aa8UL, + 0xe40ecf0bUL, 0x9309ff9dUL, 0x0a00ae27UL, 0x7d079eb1UL, 0xf00f9344UL, + 0x8708a3d2UL, 0x1e01f268UL, 0x6906c2feUL, 0xf762575dUL, 0x806567cbUL, + 0x196c3671UL, 0x6e6b06e7UL, 0xfed41b76UL, 0x89d32be0UL, 0x10da7a5aUL, + 0x67dd4accUL, 0xf9b9df6fUL, 0x8ebeeff9UL, 0x17b7be43UL, 0x60b08ed5UL, + 0xd6d6a3e8UL, 0xa1d1937eUL, 0x38d8c2c4UL, 0x4fdff252UL, 0xd1bb67f1UL, + 0xa6bc5767UL, 0x3fb506ddUL, 0x48b2364bUL, 0xd80d2bdaUL, 0xaf0a1b4cUL, + 0x36034af6UL, 0x41047a60UL, 0xdf60efc3UL, 0xa867df55UL, 0x316e8eefUL, + 0x4669be79UL, 0xcb61b38cUL, 0xbc66831aUL, 0x256fd2a0UL, 0x5268e236UL, + 0xcc0c7795UL, 0xbb0b4703UL, 0x220216b9UL, 0x5505262fUL, 0xc5ba3bbeUL, + 0xb2bd0b28UL, 0x2bb45a92UL, 0x5cb36a04UL, 0xc2d7ffa7UL, 0xb5d0cf31UL, + 0x2cd99e8bUL, 0x5bdeae1dUL, 0x9b64c2b0UL, 0xec63f226UL, 0x756aa39cUL, + 0x026d930aUL, 0x9c0906a9UL, 0xeb0e363fUL, 0x72076785UL, 0x05005713UL, + 0x95bf4a82UL, 0xe2b87a14UL, 0x7bb12baeUL, 0x0cb61b38UL, 0x92d28e9bUL, + 0xe5d5be0dUL, 0x7cdcefb7UL, 0x0bdbdf21UL, 0x86d3d2d4UL, 0xf1d4e242UL, + 0x68ddb3f8UL, 0x1fda836eUL, 0x81be16cdUL, 0xf6b9265bUL, 0x6fb077e1UL, + 0x18b74777UL, 0x88085ae6UL, 0xff0f6a70UL, 0x66063bcaUL, 0x11010b5cUL, + 0x8f659effUL, 0xf862ae69UL, 0x616bffd3UL, 0x166ccf45UL, 0xa00ae278UL, + 0xd70dd2eeUL, 0x4e048354UL, 0x3903b3c2UL, 0xa7672661UL, 0xd06016f7UL, + 0x4969474dUL, 0x3e6e77dbUL, 0xaed16a4aUL, 0xd9d65adcUL, 0x40df0b66UL, + 0x37d83bf0UL, 0xa9bcae53UL, 0xdebb9ec5UL, 0x47b2cf7fUL, 0x30b5ffe9UL, + 0xbdbdf21cUL, 0xcabac28aUL, 0x53b39330UL, 0x24b4a3a6UL, 0xbad03605UL, + 0xcdd70693UL, 0x54de5729UL, 0x23d967bfUL, 0xb3667a2eUL, 0xc4614ab8UL, + 0x5d681b02UL, 0x2a6f2b94UL, 0xb40bbe37UL, 0xc30c8ea1UL, 0x5a05df1bUL, + 0x2d02ef8dUL +#ifdef BYFOUR + }, + { + 0x00000000UL, 0x191b3141UL, 0x32366282UL, 0x2b2d53c3UL, 0x646cc504UL, + 0x7d77f445UL, 0x565aa786UL, 0x4f4196c7UL, 0xc8d98a08UL, 0xd1c2bb49UL, + 0xfaefe88aUL, 0xe3f4d9cbUL, 0xacb54f0cUL, 0xb5ae7e4dUL, 0x9e832d8eUL, + 0x87981ccfUL, 0x4ac21251UL, 0x53d92310UL, 0x78f470d3UL, 0x61ef4192UL, + 0x2eaed755UL, 0x37b5e614UL, 0x1c98b5d7UL, 0x05838496UL, 0x821b9859UL, + 0x9b00a918UL, 0xb02dfadbUL, 0xa936cb9aUL, 0xe6775d5dUL, 0xff6c6c1cUL, + 0xd4413fdfUL, 0xcd5a0e9eUL, 0x958424a2UL, 0x8c9f15e3UL, 0xa7b24620UL, + 0xbea97761UL, 0xf1e8e1a6UL, 0xe8f3d0e7UL, 0xc3de8324UL, 0xdac5b265UL, + 0x5d5daeaaUL, 0x44469febUL, 0x6f6bcc28UL, 0x7670fd69UL, 0x39316baeUL, + 0x202a5aefUL, 0x0b07092cUL, 0x121c386dUL, 0xdf4636f3UL, 0xc65d07b2UL, + 0xed705471UL, 0xf46b6530UL, 0xbb2af3f7UL, 0xa231c2b6UL, 0x891c9175UL, + 0x9007a034UL, 0x179fbcfbUL, 0x0e848dbaUL, 0x25a9de79UL, 0x3cb2ef38UL, + 0x73f379ffUL, 0x6ae848beUL, 0x41c51b7dUL, 0x58de2a3cUL, 0xf0794f05UL, + 0xe9627e44UL, 0xc24f2d87UL, 0xdb541cc6UL, 0x94158a01UL, 0x8d0ebb40UL, + 0xa623e883UL, 0xbf38d9c2UL, 0x38a0c50dUL, 0x21bbf44cUL, 0x0a96a78fUL, + 0x138d96ceUL, 0x5ccc0009UL, 0x45d73148UL, 0x6efa628bUL, 0x77e153caUL, + 0xbabb5d54UL, 0xa3a06c15UL, 0x888d3fd6UL, 0x91960e97UL, 0xded79850UL, + 0xc7cca911UL, 0xece1fad2UL, 0xf5facb93UL, 0x7262d75cUL, 0x6b79e61dUL, + 0x4054b5deUL, 0x594f849fUL, 0x160e1258UL, 0x0f152319UL, 0x243870daUL, + 0x3d23419bUL, 0x65fd6ba7UL, 0x7ce65ae6UL, 0x57cb0925UL, 0x4ed03864UL, + 0x0191aea3UL, 0x188a9fe2UL, 0x33a7cc21UL, 0x2abcfd60UL, 0xad24e1afUL, + 0xb43fd0eeUL, 0x9f12832dUL, 0x8609b26cUL, 0xc94824abUL, 0xd05315eaUL, + 0xfb7e4629UL, 0xe2657768UL, 0x2f3f79f6UL, 0x362448b7UL, 0x1d091b74UL, + 0x04122a35UL, 0x4b53bcf2UL, 0x52488db3UL, 0x7965de70UL, 0x607eef31UL, + 0xe7e6f3feUL, 0xfefdc2bfUL, 0xd5d0917cUL, 0xcccba03dUL, 0x838a36faUL, + 0x9a9107bbUL, 0xb1bc5478UL, 0xa8a76539UL, 0x3b83984bUL, 0x2298a90aUL, + 0x09b5fac9UL, 0x10aecb88UL, 0x5fef5d4fUL, 0x46f46c0eUL, 0x6dd93fcdUL, + 0x74c20e8cUL, 0xf35a1243UL, 0xea412302UL, 0xc16c70c1UL, 0xd8774180UL, + 0x9736d747UL, 0x8e2de606UL, 0xa500b5c5UL, 0xbc1b8484UL, 0x71418a1aUL, + 0x685abb5bUL, 0x4377e898UL, 0x5a6cd9d9UL, 0x152d4f1eUL, 0x0c367e5fUL, + 0x271b2d9cUL, 0x3e001cddUL, 0xb9980012UL, 0xa0833153UL, 0x8bae6290UL, + 0x92b553d1UL, 0xddf4c516UL, 0xc4eff457UL, 0xefc2a794UL, 0xf6d996d5UL, + 0xae07bce9UL, 0xb71c8da8UL, 0x9c31de6bUL, 0x852aef2aUL, 0xca6b79edUL, + 0xd37048acUL, 0xf85d1b6fUL, 0xe1462a2eUL, 0x66de36e1UL, 0x7fc507a0UL, + 0x54e85463UL, 0x4df36522UL, 0x02b2f3e5UL, 0x1ba9c2a4UL, 0x30849167UL, + 0x299fa026UL, 0xe4c5aeb8UL, 0xfdde9ff9UL, 0xd6f3cc3aUL, 0xcfe8fd7bUL, + 0x80a96bbcUL, 0x99b25afdUL, 0xb29f093eUL, 0xab84387fUL, 0x2c1c24b0UL, + 0x350715f1UL, 0x1e2a4632UL, 0x07317773UL, 0x4870e1b4UL, 0x516bd0f5UL, + 0x7a468336UL, 0x635db277UL, 0xcbfad74eUL, 0xd2e1e60fUL, 0xf9ccb5ccUL, + 0xe0d7848dUL, 0xaf96124aUL, 0xb68d230bUL, 0x9da070c8UL, 0x84bb4189UL, + 0x03235d46UL, 0x1a386c07UL, 0x31153fc4UL, 0x280e0e85UL, 0x674f9842UL, + 0x7e54a903UL, 0x5579fac0UL, 0x4c62cb81UL, 0x8138c51fUL, 0x9823f45eUL, + 0xb30ea79dUL, 0xaa1596dcUL, 0xe554001bUL, 0xfc4f315aUL, 0xd7626299UL, + 0xce7953d8UL, 0x49e14f17UL, 0x50fa7e56UL, 0x7bd72d95UL, 0x62cc1cd4UL, + 0x2d8d8a13UL, 0x3496bb52UL, 0x1fbbe891UL, 0x06a0d9d0UL, 0x5e7ef3ecUL, + 0x4765c2adUL, 0x6c48916eUL, 0x7553a02fUL, 0x3a1236e8UL, 0x230907a9UL, + 0x0824546aUL, 0x113f652bUL, 0x96a779e4UL, 0x8fbc48a5UL, 0xa4911b66UL, + 0xbd8a2a27UL, 0xf2cbbce0UL, 0xebd08da1UL, 0xc0fdde62UL, 0xd9e6ef23UL, + 0x14bce1bdUL, 0x0da7d0fcUL, 0x268a833fUL, 0x3f91b27eUL, 0x70d024b9UL, + 0x69cb15f8UL, 0x42e6463bUL, 0x5bfd777aUL, 0xdc656bb5UL, 0xc57e5af4UL, + 0xee530937UL, 0xf7483876UL, 0xb809aeb1UL, 0xa1129ff0UL, 0x8a3fcc33UL, + 0x9324fd72UL + }, + { + 0x00000000UL, 0x01c26a37UL, 0x0384d46eUL, 0x0246be59UL, 0x0709a8dcUL, + 0x06cbc2ebUL, 0x048d7cb2UL, 0x054f1685UL, 0x0e1351b8UL, 0x0fd13b8fUL, + 0x0d9785d6UL, 0x0c55efe1UL, 0x091af964UL, 0x08d89353UL, 0x0a9e2d0aUL, + 0x0b5c473dUL, 0x1c26a370UL, 0x1de4c947UL, 0x1fa2771eUL, 0x1e601d29UL, + 0x1b2f0bacUL, 0x1aed619bUL, 0x18abdfc2UL, 0x1969b5f5UL, 0x1235f2c8UL, + 0x13f798ffUL, 0x11b126a6UL, 0x10734c91UL, 0x153c5a14UL, 0x14fe3023UL, + 0x16b88e7aUL, 0x177ae44dUL, 0x384d46e0UL, 0x398f2cd7UL, 0x3bc9928eUL, + 0x3a0bf8b9UL, 0x3f44ee3cUL, 0x3e86840bUL, 0x3cc03a52UL, 0x3d025065UL, + 0x365e1758UL, 0x379c7d6fUL, 0x35dac336UL, 0x3418a901UL, 0x3157bf84UL, + 0x3095d5b3UL, 0x32d36beaUL, 0x331101ddUL, 0x246be590UL, 0x25a98fa7UL, + 0x27ef31feUL, 0x262d5bc9UL, 0x23624d4cUL, 0x22a0277bUL, 0x20e69922UL, + 0x2124f315UL, 0x2a78b428UL, 0x2bbade1fUL, 0x29fc6046UL, 0x283e0a71UL, + 0x2d711cf4UL, 0x2cb376c3UL, 0x2ef5c89aUL, 0x2f37a2adUL, 0x709a8dc0UL, + 0x7158e7f7UL, 0x731e59aeUL, 0x72dc3399UL, 0x7793251cUL, 0x76514f2bUL, + 0x7417f172UL, 0x75d59b45UL, 0x7e89dc78UL, 0x7f4bb64fUL, 0x7d0d0816UL, + 0x7ccf6221UL, 0x798074a4UL, 0x78421e93UL, 0x7a04a0caUL, 0x7bc6cafdUL, + 0x6cbc2eb0UL, 0x6d7e4487UL, 0x6f38fadeUL, 0x6efa90e9UL, 0x6bb5866cUL, + 0x6a77ec5bUL, 0x68315202UL, 0x69f33835UL, 0x62af7f08UL, 0x636d153fUL, + 0x612bab66UL, 0x60e9c151UL, 0x65a6d7d4UL, 0x6464bde3UL, 0x662203baUL, + 0x67e0698dUL, 0x48d7cb20UL, 0x4915a117UL, 0x4b531f4eUL, 0x4a917579UL, + 0x4fde63fcUL, 0x4e1c09cbUL, 0x4c5ab792UL, 0x4d98dda5UL, 0x46c49a98UL, + 0x4706f0afUL, 0x45404ef6UL, 0x448224c1UL, 0x41cd3244UL, 0x400f5873UL, + 0x4249e62aUL, 0x438b8c1dUL, 0x54f16850UL, 0x55330267UL, 0x5775bc3eUL, + 0x56b7d609UL, 0x53f8c08cUL, 0x523aaabbUL, 0x507c14e2UL, 0x51be7ed5UL, + 0x5ae239e8UL, 0x5b2053dfUL, 0x5966ed86UL, 0x58a487b1UL, 0x5deb9134UL, + 0x5c29fb03UL, 0x5e6f455aUL, 0x5fad2f6dUL, 0xe1351b80UL, 0xe0f771b7UL, + 0xe2b1cfeeUL, 0xe373a5d9UL, 0xe63cb35cUL, 0xe7fed96bUL, 0xe5b86732UL, + 0xe47a0d05UL, 0xef264a38UL, 0xeee4200fUL, 0xeca29e56UL, 0xed60f461UL, + 0xe82fe2e4UL, 0xe9ed88d3UL, 0xebab368aUL, 0xea695cbdUL, 0xfd13b8f0UL, + 0xfcd1d2c7UL, 0xfe976c9eUL, 0xff5506a9UL, 0xfa1a102cUL, 0xfbd87a1bUL, + 0xf99ec442UL, 0xf85cae75UL, 0xf300e948UL, 0xf2c2837fUL, 0xf0843d26UL, + 0xf1465711UL, 0xf4094194UL, 0xf5cb2ba3UL, 0xf78d95faUL, 0xf64fffcdUL, + 0xd9785d60UL, 0xd8ba3757UL, 0xdafc890eUL, 0xdb3ee339UL, 0xde71f5bcUL, + 0xdfb39f8bUL, 0xddf521d2UL, 0xdc374be5UL, 0xd76b0cd8UL, 0xd6a966efUL, + 0xd4efd8b6UL, 0xd52db281UL, 0xd062a404UL, 0xd1a0ce33UL, 0xd3e6706aUL, + 0xd2241a5dUL, 0xc55efe10UL, 0xc49c9427UL, 0xc6da2a7eUL, 0xc7184049UL, + 0xc25756ccUL, 0xc3953cfbUL, 0xc1d382a2UL, 0xc011e895UL, 0xcb4dafa8UL, + 0xca8fc59fUL, 0xc8c97bc6UL, 0xc90b11f1UL, 0xcc440774UL, 0xcd866d43UL, + 0xcfc0d31aUL, 0xce02b92dUL, 0x91af9640UL, 0x906dfc77UL, 0x922b422eUL, + 0x93e92819UL, 0x96a63e9cUL, 0x976454abUL, 0x9522eaf2UL, 0x94e080c5UL, + 0x9fbcc7f8UL, 0x9e7eadcfUL, 0x9c381396UL, 0x9dfa79a1UL, 0x98b56f24UL, + 0x99770513UL, 0x9b31bb4aUL, 0x9af3d17dUL, 0x8d893530UL, 0x8c4b5f07UL, + 0x8e0de15eUL, 0x8fcf8b69UL, 0x8a809decUL, 0x8b42f7dbUL, 0x89044982UL, + 0x88c623b5UL, 0x839a6488UL, 0x82580ebfUL, 0x801eb0e6UL, 0x81dcdad1UL, + 0x8493cc54UL, 0x8551a663UL, 0x8717183aUL, 0x86d5720dUL, 0xa9e2d0a0UL, + 0xa820ba97UL, 0xaa6604ceUL, 0xaba46ef9UL, 0xaeeb787cUL, 0xaf29124bUL, + 0xad6fac12UL, 0xacadc625UL, 0xa7f18118UL, 0xa633eb2fUL, 0xa4755576UL, + 0xa5b73f41UL, 0xa0f829c4UL, 0xa13a43f3UL, 0xa37cfdaaUL, 0xa2be979dUL, + 0xb5c473d0UL, 0xb40619e7UL, 0xb640a7beUL, 0xb782cd89UL, 0xb2cddb0cUL, + 0xb30fb13bUL, 0xb1490f62UL, 0xb08b6555UL, 0xbbd72268UL, 0xba15485fUL, + 0xb853f606UL, 0xb9919c31UL, 0xbcde8ab4UL, 0xbd1ce083UL, 0xbf5a5edaUL, + 0xbe9834edUL + }, + { + 0x00000000UL, 0xb8bc6765UL, 0xaa09c88bUL, 0x12b5afeeUL, 0x8f629757UL, + 0x37def032UL, 0x256b5fdcUL, 0x9dd738b9UL, 0xc5b428efUL, 0x7d084f8aUL, + 0x6fbde064UL, 0xd7018701UL, 0x4ad6bfb8UL, 0xf26ad8ddUL, 0xe0df7733UL, + 0x58631056UL, 0x5019579fUL, 0xe8a530faUL, 0xfa109f14UL, 0x42acf871UL, + 0xdf7bc0c8UL, 0x67c7a7adUL, 0x75720843UL, 0xcdce6f26UL, 0x95ad7f70UL, + 0x2d111815UL, 0x3fa4b7fbUL, 0x8718d09eUL, 0x1acfe827UL, 0xa2738f42UL, + 0xb0c620acUL, 0x087a47c9UL, 0xa032af3eUL, 0x188ec85bUL, 0x0a3b67b5UL, + 0xb28700d0UL, 0x2f503869UL, 0x97ec5f0cUL, 0x8559f0e2UL, 0x3de59787UL, + 0x658687d1UL, 0xdd3ae0b4UL, 0xcf8f4f5aUL, 0x7733283fUL, 0xeae41086UL, + 0x525877e3UL, 0x40edd80dUL, 0xf851bf68UL, 0xf02bf8a1UL, 0x48979fc4UL, + 0x5a22302aUL, 0xe29e574fUL, 0x7f496ff6UL, 0xc7f50893UL, 0xd540a77dUL, + 0x6dfcc018UL, 0x359fd04eUL, 0x8d23b72bUL, 0x9f9618c5UL, 0x272a7fa0UL, + 0xbafd4719UL, 0x0241207cUL, 0x10f48f92UL, 0xa848e8f7UL, 0x9b14583dUL, + 0x23a83f58UL, 0x311d90b6UL, 0x89a1f7d3UL, 0x1476cf6aUL, 0xaccaa80fUL, + 0xbe7f07e1UL, 0x06c36084UL, 0x5ea070d2UL, 0xe61c17b7UL, 0xf4a9b859UL, + 0x4c15df3cUL, 0xd1c2e785UL, 0x697e80e0UL, 0x7bcb2f0eUL, 0xc377486bUL, + 0xcb0d0fa2UL, 0x73b168c7UL, 0x6104c729UL, 0xd9b8a04cUL, 0x446f98f5UL, + 0xfcd3ff90UL, 0xee66507eUL, 0x56da371bUL, 0x0eb9274dUL, 0xb6054028UL, + 0xa4b0efc6UL, 0x1c0c88a3UL, 0x81dbb01aUL, 0x3967d77fUL, 0x2bd27891UL, + 0x936e1ff4UL, 0x3b26f703UL, 0x839a9066UL, 0x912f3f88UL, 0x299358edUL, + 0xb4446054UL, 0x0cf80731UL, 0x1e4da8dfUL, 0xa6f1cfbaUL, 0xfe92dfecUL, + 0x462eb889UL, 0x549b1767UL, 0xec277002UL, 0x71f048bbUL, 0xc94c2fdeUL, + 0xdbf98030UL, 0x6345e755UL, 0x6b3fa09cUL, 0xd383c7f9UL, 0xc1366817UL, + 0x798a0f72UL, 0xe45d37cbUL, 0x5ce150aeUL, 0x4e54ff40UL, 0xf6e89825UL, + 0xae8b8873UL, 0x1637ef16UL, 0x048240f8UL, 0xbc3e279dUL, 0x21e91f24UL, + 0x99557841UL, 0x8be0d7afUL, 0x335cb0caUL, 0xed59b63bUL, 0x55e5d15eUL, + 0x47507eb0UL, 0xffec19d5UL, 0x623b216cUL, 0xda874609UL, 0xc832e9e7UL, + 0x708e8e82UL, 0x28ed9ed4UL, 0x9051f9b1UL, 0x82e4565fUL, 0x3a58313aUL, + 0xa78f0983UL, 0x1f336ee6UL, 0x0d86c108UL, 0xb53aa66dUL, 0xbd40e1a4UL, + 0x05fc86c1UL, 0x1749292fUL, 0xaff54e4aUL, 0x322276f3UL, 0x8a9e1196UL, + 0x982bbe78UL, 0x2097d91dUL, 0x78f4c94bUL, 0xc048ae2eUL, 0xd2fd01c0UL, + 0x6a4166a5UL, 0xf7965e1cUL, 0x4f2a3979UL, 0x5d9f9697UL, 0xe523f1f2UL, + 0x4d6b1905UL, 0xf5d77e60UL, 0xe762d18eUL, 0x5fdeb6ebUL, 0xc2098e52UL, + 0x7ab5e937UL, 0x680046d9UL, 0xd0bc21bcUL, 0x88df31eaUL, 0x3063568fUL, + 0x22d6f961UL, 0x9a6a9e04UL, 0x07bda6bdUL, 0xbf01c1d8UL, 0xadb46e36UL, + 0x15080953UL, 0x1d724e9aUL, 0xa5ce29ffUL, 0xb77b8611UL, 0x0fc7e174UL, + 0x9210d9cdUL, 0x2aacbea8UL, 0x38191146UL, 0x80a57623UL, 0xd8c66675UL, + 0x607a0110UL, 0x72cfaefeUL, 0xca73c99bUL, 0x57a4f122UL, 0xef189647UL, + 0xfdad39a9UL, 0x45115eccUL, 0x764dee06UL, 0xcef18963UL, 0xdc44268dUL, + 0x64f841e8UL, 0xf92f7951UL, 0x41931e34UL, 0x5326b1daUL, 0xeb9ad6bfUL, + 0xb3f9c6e9UL, 0x0b45a18cUL, 0x19f00e62UL, 0xa14c6907UL, 0x3c9b51beUL, + 0x842736dbUL, 0x96929935UL, 0x2e2efe50UL, 0x2654b999UL, 0x9ee8defcUL, + 0x8c5d7112UL, 0x34e11677UL, 0xa9362eceUL, 0x118a49abUL, 0x033fe645UL, + 0xbb838120UL, 0xe3e09176UL, 0x5b5cf613UL, 0x49e959fdUL, 0xf1553e98UL, + 0x6c820621UL, 0xd43e6144UL, 0xc68bceaaUL, 0x7e37a9cfUL, 0xd67f4138UL, + 0x6ec3265dUL, 0x7c7689b3UL, 0xc4caeed6UL, 0x591dd66fUL, 0xe1a1b10aUL, + 0xf3141ee4UL, 0x4ba87981UL, 0x13cb69d7UL, 0xab770eb2UL, 0xb9c2a15cUL, + 0x017ec639UL, 0x9ca9fe80UL, 0x241599e5UL, 0x36a0360bUL, 0x8e1c516eUL, + 0x866616a7UL, 0x3eda71c2UL, 0x2c6fde2cUL, 0x94d3b949UL, 0x090481f0UL, + 0xb1b8e695UL, 0xa30d497bUL, 0x1bb12e1eUL, 0x43d23e48UL, 0xfb6e592dUL, + 0xe9dbf6c3UL, 0x516791a6UL, 0xccb0a91fUL, 0x740cce7aUL, 0x66b96194UL, + 0xde0506f1UL + }, + { + 0x00000000UL, 0x96300777UL, 0x2c610eeeUL, 0xba510999UL, 0x19c46d07UL, + 0x8ff46a70UL, 0x35a563e9UL, 0xa395649eUL, 0x3288db0eUL, 0xa4b8dc79UL, + 0x1ee9d5e0UL, 0x88d9d297UL, 0x2b4cb609UL, 0xbd7cb17eUL, 0x072db8e7UL, + 0x911dbf90UL, 0x6410b71dUL, 0xf220b06aUL, 0x4871b9f3UL, 0xde41be84UL, + 0x7dd4da1aUL, 0xebe4dd6dUL, 0x51b5d4f4UL, 0xc785d383UL, 0x56986c13UL, + 0xc0a86b64UL, 0x7af962fdUL, 0xecc9658aUL, 0x4f5c0114UL, 0xd96c0663UL, + 0x633d0ffaUL, 0xf50d088dUL, 0xc8206e3bUL, 0x5e10694cUL, 0xe44160d5UL, + 0x727167a2UL, 0xd1e4033cUL, 0x47d4044bUL, 0xfd850dd2UL, 0x6bb50aa5UL, + 0xfaa8b535UL, 0x6c98b242UL, 0xd6c9bbdbUL, 0x40f9bcacUL, 0xe36cd832UL, + 0x755cdf45UL, 0xcf0dd6dcUL, 0x593dd1abUL, 0xac30d926UL, 0x3a00de51UL, + 0x8051d7c8UL, 0x1661d0bfUL, 0xb5f4b421UL, 0x23c4b356UL, 0x9995bacfUL, + 0x0fa5bdb8UL, 0x9eb80228UL, 0x0888055fUL, 0xb2d90cc6UL, 0x24e90bb1UL, + 0x877c6f2fUL, 0x114c6858UL, 0xab1d61c1UL, 0x3d2d66b6UL, 0x9041dc76UL, + 0x0671db01UL, 0xbc20d298UL, 0x2a10d5efUL, 0x8985b171UL, 0x1fb5b606UL, + 0xa5e4bf9fUL, 0x33d4b8e8UL, 0xa2c90778UL, 0x34f9000fUL, 0x8ea80996UL, + 0x18980ee1UL, 0xbb0d6a7fUL, 0x2d3d6d08UL, 0x976c6491UL, 0x015c63e6UL, + 0xf4516b6bUL, 0x62616c1cUL, 0xd8306585UL, 0x4e0062f2UL, 0xed95066cUL, + 0x7ba5011bUL, 0xc1f40882UL, 0x57c40ff5UL, 0xc6d9b065UL, 0x50e9b712UL, + 0xeab8be8bUL, 0x7c88b9fcUL, 0xdf1ddd62UL, 0x492dda15UL, 0xf37cd38cUL, + 0x654cd4fbUL, 0x5861b24dUL, 0xce51b53aUL, 0x7400bca3UL, 0xe230bbd4UL, + 0x41a5df4aUL, 0xd795d83dUL, 0x6dc4d1a4UL, 0xfbf4d6d3UL, 0x6ae96943UL, + 0xfcd96e34UL, 0x468867adUL, 0xd0b860daUL, 0x732d0444UL, 0xe51d0333UL, + 0x5f4c0aaaUL, 0xc97c0dddUL, 0x3c710550UL, 0xaa410227UL, 0x10100bbeUL, + 0x86200cc9UL, 0x25b56857UL, 0xb3856f20UL, 0x09d466b9UL, 0x9fe461ceUL, + 0x0ef9de5eUL, 0x98c9d929UL, 0x2298d0b0UL, 0xb4a8d7c7UL, 0x173db359UL, + 0x810db42eUL, 0x3b5cbdb7UL, 0xad6cbac0UL, 0x2083b8edUL, 0xb6b3bf9aUL, + 0x0ce2b603UL, 0x9ad2b174UL, 0x3947d5eaUL, 0xaf77d29dUL, 0x1526db04UL, + 0x8316dc73UL, 0x120b63e3UL, 0x843b6494UL, 0x3e6a6d0dUL, 0xa85a6a7aUL, + 0x0bcf0ee4UL, 0x9dff0993UL, 0x27ae000aUL, 0xb19e077dUL, 0x44930ff0UL, + 0xd2a30887UL, 0x68f2011eUL, 0xfec20669UL, 0x5d5762f7UL, 0xcb676580UL, + 0x71366c19UL, 0xe7066b6eUL, 0x761bd4feUL, 0xe02bd389UL, 0x5a7ada10UL, + 0xcc4add67UL, 0x6fdfb9f9UL, 0xf9efbe8eUL, 0x43beb717UL, 0xd58eb060UL, + 0xe8a3d6d6UL, 0x7e93d1a1UL, 0xc4c2d838UL, 0x52f2df4fUL, 0xf167bbd1UL, + 0x6757bca6UL, 0xdd06b53fUL, 0x4b36b248UL, 0xda2b0dd8UL, 0x4c1b0aafUL, + 0xf64a0336UL, 0x607a0441UL, 0xc3ef60dfUL, 0x55df67a8UL, 0xef8e6e31UL, + 0x79be6946UL, 0x8cb361cbUL, 0x1a8366bcUL, 0xa0d26f25UL, 0x36e26852UL, + 0x95770cccUL, 0x03470bbbUL, 0xb9160222UL, 0x2f260555UL, 0xbe3bbac5UL, + 0x280bbdb2UL, 0x925ab42bUL, 0x046ab35cUL, 0xa7ffd7c2UL, 0x31cfd0b5UL, + 0x8b9ed92cUL, 0x1daede5bUL, 0xb0c2649bUL, 0x26f263ecUL, 0x9ca36a75UL, + 0x0a936d02UL, 0xa906099cUL, 0x3f360eebUL, 0x85670772UL, 0x13570005UL, + 0x824abf95UL, 0x147ab8e2UL, 0xae2bb17bUL, 0x381bb60cUL, 0x9b8ed292UL, + 0x0dbed5e5UL, 0xb7efdc7cUL, 0x21dfdb0bUL, 0xd4d2d386UL, 0x42e2d4f1UL, + 0xf8b3dd68UL, 0x6e83da1fUL, 0xcd16be81UL, 0x5b26b9f6UL, 0xe177b06fUL, + 0x7747b718UL, 0xe65a0888UL, 0x706a0fffUL, 0xca3b0666UL, 0x5c0b0111UL, + 0xff9e658fUL, 0x69ae62f8UL, 0xd3ff6b61UL, 0x45cf6c16UL, 0x78e20aa0UL, + 0xeed20dd7UL, 0x5483044eUL, 0xc2b30339UL, 0x612667a7UL, 0xf71660d0UL, + 0x4d476949UL, 0xdb776e3eUL, 0x4a6ad1aeUL, 0xdc5ad6d9UL, 0x660bdf40UL, + 0xf03bd837UL, 0x53aebca9UL, 0xc59ebbdeUL, 0x7fcfb247UL, 0xe9ffb530UL, + 0x1cf2bdbdUL, 0x8ac2bacaUL, 0x3093b353UL, 0xa6a3b424UL, 0x0536d0baUL, + 0x9306d7cdUL, 0x2957de54UL, 0xbf67d923UL, 0x2e7a66b3UL, 0xb84a61c4UL, + 0x021b685dUL, 0x942b6f2aUL, 0x37be0bb4UL, 0xa18e0cc3UL, 0x1bdf055aUL, + 0x8def022dUL + }, + { + 0x00000000UL, 0x41311b19UL, 0x82623632UL, 0xc3532d2bUL, 0x04c56c64UL, + 0x45f4777dUL, 0x86a75a56UL, 0xc796414fUL, 0x088ad9c8UL, 0x49bbc2d1UL, + 0x8ae8effaUL, 0xcbd9f4e3UL, 0x0c4fb5acUL, 0x4d7eaeb5UL, 0x8e2d839eUL, + 0xcf1c9887UL, 0x5112c24aUL, 0x1023d953UL, 0xd370f478UL, 0x9241ef61UL, + 0x55d7ae2eUL, 0x14e6b537UL, 0xd7b5981cUL, 0x96848305UL, 0x59981b82UL, + 0x18a9009bUL, 0xdbfa2db0UL, 0x9acb36a9UL, 0x5d5d77e6UL, 0x1c6c6cffUL, + 0xdf3f41d4UL, 0x9e0e5acdUL, 0xa2248495UL, 0xe3159f8cUL, 0x2046b2a7UL, + 0x6177a9beUL, 0xa6e1e8f1UL, 0xe7d0f3e8UL, 0x2483dec3UL, 0x65b2c5daUL, + 0xaaae5d5dUL, 0xeb9f4644UL, 0x28cc6b6fUL, 0x69fd7076UL, 0xae6b3139UL, + 0xef5a2a20UL, 0x2c09070bUL, 0x6d381c12UL, 0xf33646dfUL, 0xb2075dc6UL, + 0x715470edUL, 0x30656bf4UL, 0xf7f32abbUL, 0xb6c231a2UL, 0x75911c89UL, + 0x34a00790UL, 0xfbbc9f17UL, 0xba8d840eUL, 0x79dea925UL, 0x38efb23cUL, + 0xff79f373UL, 0xbe48e86aUL, 0x7d1bc541UL, 0x3c2ade58UL, 0x054f79f0UL, + 0x447e62e9UL, 0x872d4fc2UL, 0xc61c54dbUL, 0x018a1594UL, 0x40bb0e8dUL, + 0x83e823a6UL, 0xc2d938bfUL, 0x0dc5a038UL, 0x4cf4bb21UL, 0x8fa7960aUL, + 0xce968d13UL, 0x0900cc5cUL, 0x4831d745UL, 0x8b62fa6eUL, 0xca53e177UL, + 0x545dbbbaUL, 0x156ca0a3UL, 0xd63f8d88UL, 0x970e9691UL, 0x5098d7deUL, + 0x11a9ccc7UL, 0xd2fae1ecUL, 0x93cbfaf5UL, 0x5cd76272UL, 0x1de6796bUL, + 0xdeb55440UL, 0x9f844f59UL, 0x58120e16UL, 0x1923150fUL, 0xda703824UL, + 0x9b41233dUL, 0xa76bfd65UL, 0xe65ae67cUL, 0x2509cb57UL, 0x6438d04eUL, + 0xa3ae9101UL, 0xe29f8a18UL, 0x21cca733UL, 0x60fdbc2aUL, 0xafe124adUL, + 0xeed03fb4UL, 0x2d83129fUL, 0x6cb20986UL, 0xab2448c9UL, 0xea1553d0UL, + 0x29467efbUL, 0x687765e2UL, 0xf6793f2fUL, 0xb7482436UL, 0x741b091dUL, + 0x352a1204UL, 0xf2bc534bUL, 0xb38d4852UL, 0x70de6579UL, 0x31ef7e60UL, + 0xfef3e6e7UL, 0xbfc2fdfeUL, 0x7c91d0d5UL, 0x3da0cbccUL, 0xfa368a83UL, + 0xbb07919aUL, 0x7854bcb1UL, 0x3965a7a8UL, 0x4b98833bUL, 0x0aa99822UL, + 0xc9fab509UL, 0x88cbae10UL, 0x4f5def5fUL, 0x0e6cf446UL, 0xcd3fd96dUL, + 0x8c0ec274UL, 0x43125af3UL, 0x022341eaUL, 0xc1706cc1UL, 0x804177d8UL, + 0x47d73697UL, 0x06e62d8eUL, 0xc5b500a5UL, 0x84841bbcUL, 0x1a8a4171UL, + 0x5bbb5a68UL, 0x98e87743UL, 0xd9d96c5aUL, 0x1e4f2d15UL, 0x5f7e360cUL, + 0x9c2d1b27UL, 0xdd1c003eUL, 0x120098b9UL, 0x533183a0UL, 0x9062ae8bUL, + 0xd153b592UL, 0x16c5f4ddUL, 0x57f4efc4UL, 0x94a7c2efUL, 0xd596d9f6UL, + 0xe9bc07aeUL, 0xa88d1cb7UL, 0x6bde319cUL, 0x2aef2a85UL, 0xed796bcaUL, + 0xac4870d3UL, 0x6f1b5df8UL, 0x2e2a46e1UL, 0xe136de66UL, 0xa007c57fUL, + 0x6354e854UL, 0x2265f34dUL, 0xe5f3b202UL, 0xa4c2a91bUL, 0x67918430UL, + 0x26a09f29UL, 0xb8aec5e4UL, 0xf99fdefdUL, 0x3accf3d6UL, 0x7bfde8cfUL, + 0xbc6ba980UL, 0xfd5ab299UL, 0x3e099fb2UL, 0x7f3884abUL, 0xb0241c2cUL, + 0xf1150735UL, 0x32462a1eUL, 0x73773107UL, 0xb4e17048UL, 0xf5d06b51UL, + 0x3683467aUL, 0x77b25d63UL, 0x4ed7facbUL, 0x0fe6e1d2UL, 0xccb5ccf9UL, + 0x8d84d7e0UL, 0x4a1296afUL, 0x0b238db6UL, 0xc870a09dUL, 0x8941bb84UL, + 0x465d2303UL, 0x076c381aUL, 0xc43f1531UL, 0x850e0e28UL, 0x42984f67UL, + 0x03a9547eUL, 0xc0fa7955UL, 0x81cb624cUL, 0x1fc53881UL, 0x5ef42398UL, + 0x9da70eb3UL, 0xdc9615aaUL, 0x1b0054e5UL, 0x5a314ffcUL, 0x996262d7UL, + 0xd85379ceUL, 0x174fe149UL, 0x567efa50UL, 0x952dd77bUL, 0xd41ccc62UL, + 0x138a8d2dUL, 0x52bb9634UL, 0x91e8bb1fUL, 0xd0d9a006UL, 0xecf37e5eUL, + 0xadc26547UL, 0x6e91486cUL, 0x2fa05375UL, 0xe836123aUL, 0xa9070923UL, + 0x6a542408UL, 0x2b653f11UL, 0xe479a796UL, 0xa548bc8fUL, 0x661b91a4UL, + 0x272a8abdUL, 0xe0bccbf2UL, 0xa18dd0ebUL, 0x62defdc0UL, 0x23efe6d9UL, + 0xbde1bc14UL, 0xfcd0a70dUL, 0x3f838a26UL, 0x7eb2913fUL, 0xb924d070UL, + 0xf815cb69UL, 0x3b46e642UL, 0x7a77fd5bUL, 0xb56b65dcUL, 0xf45a7ec5UL, + 0x370953eeUL, 0x763848f7UL, 0xb1ae09b8UL, 0xf09f12a1UL, 0x33cc3f8aUL, + 0x72fd2493UL + }, + { + 0x00000000UL, 0x376ac201UL, 0x6ed48403UL, 0x59be4602UL, 0xdca80907UL, + 0xebc2cb06UL, 0xb27c8d04UL, 0x85164f05UL, 0xb851130eUL, 0x8f3bd10fUL, + 0xd685970dUL, 0xe1ef550cUL, 0x64f91a09UL, 0x5393d808UL, 0x0a2d9e0aUL, + 0x3d475c0bUL, 0x70a3261cUL, 0x47c9e41dUL, 0x1e77a21fUL, 0x291d601eUL, + 0xac0b2f1bUL, 0x9b61ed1aUL, 0xc2dfab18UL, 0xf5b56919UL, 0xc8f23512UL, + 0xff98f713UL, 0xa626b111UL, 0x914c7310UL, 0x145a3c15UL, 0x2330fe14UL, + 0x7a8eb816UL, 0x4de47a17UL, 0xe0464d38UL, 0xd72c8f39UL, 0x8e92c93bUL, + 0xb9f80b3aUL, 0x3cee443fUL, 0x0b84863eUL, 0x523ac03cUL, 0x6550023dUL, + 0x58175e36UL, 0x6f7d9c37UL, 0x36c3da35UL, 0x01a91834UL, 0x84bf5731UL, + 0xb3d59530UL, 0xea6bd332UL, 0xdd011133UL, 0x90e56b24UL, 0xa78fa925UL, + 0xfe31ef27UL, 0xc95b2d26UL, 0x4c4d6223UL, 0x7b27a022UL, 0x2299e620UL, + 0x15f32421UL, 0x28b4782aUL, 0x1fdeba2bUL, 0x4660fc29UL, 0x710a3e28UL, + 0xf41c712dUL, 0xc376b32cUL, 0x9ac8f52eUL, 0xada2372fUL, 0xc08d9a70UL, + 0xf7e75871UL, 0xae591e73UL, 0x9933dc72UL, 0x1c259377UL, 0x2b4f5176UL, + 0x72f11774UL, 0x459bd575UL, 0x78dc897eUL, 0x4fb64b7fUL, 0x16080d7dUL, + 0x2162cf7cUL, 0xa4748079UL, 0x931e4278UL, 0xcaa0047aUL, 0xfdcac67bUL, + 0xb02ebc6cUL, 0x87447e6dUL, 0xdefa386fUL, 0xe990fa6eUL, 0x6c86b56bUL, + 0x5bec776aUL, 0x02523168UL, 0x3538f369UL, 0x087faf62UL, 0x3f156d63UL, + 0x66ab2b61UL, 0x51c1e960UL, 0xd4d7a665UL, 0xe3bd6464UL, 0xba032266UL, + 0x8d69e067UL, 0x20cbd748UL, 0x17a11549UL, 0x4e1f534bUL, 0x7975914aUL, + 0xfc63de4fUL, 0xcb091c4eUL, 0x92b75a4cUL, 0xa5dd984dUL, 0x989ac446UL, + 0xaff00647UL, 0xf64e4045UL, 0xc1248244UL, 0x4432cd41UL, 0x73580f40UL, + 0x2ae64942UL, 0x1d8c8b43UL, 0x5068f154UL, 0x67023355UL, 0x3ebc7557UL, + 0x09d6b756UL, 0x8cc0f853UL, 0xbbaa3a52UL, 0xe2147c50UL, 0xd57ebe51UL, + 0xe839e25aUL, 0xdf53205bUL, 0x86ed6659UL, 0xb187a458UL, 0x3491eb5dUL, + 0x03fb295cUL, 0x5a456f5eUL, 0x6d2fad5fUL, 0x801b35e1UL, 0xb771f7e0UL, + 0xeecfb1e2UL, 0xd9a573e3UL, 0x5cb33ce6UL, 0x6bd9fee7UL, 0x3267b8e5UL, + 0x050d7ae4UL, 0x384a26efUL, 0x0f20e4eeUL, 0x569ea2ecUL, 0x61f460edUL, + 0xe4e22fe8UL, 0xd388ede9UL, 0x8a36abebUL, 0xbd5c69eaUL, 0xf0b813fdUL, + 0xc7d2d1fcUL, 0x9e6c97feUL, 0xa90655ffUL, 0x2c101afaUL, 0x1b7ad8fbUL, + 0x42c49ef9UL, 0x75ae5cf8UL, 0x48e900f3UL, 0x7f83c2f2UL, 0x263d84f0UL, + 0x115746f1UL, 0x944109f4UL, 0xa32bcbf5UL, 0xfa958df7UL, 0xcdff4ff6UL, + 0x605d78d9UL, 0x5737bad8UL, 0x0e89fcdaUL, 0x39e33edbUL, 0xbcf571deUL, + 0x8b9fb3dfUL, 0xd221f5ddUL, 0xe54b37dcUL, 0xd80c6bd7UL, 0xef66a9d6UL, + 0xb6d8efd4UL, 0x81b22dd5UL, 0x04a462d0UL, 0x33cea0d1UL, 0x6a70e6d3UL, + 0x5d1a24d2UL, 0x10fe5ec5UL, 0x27949cc4UL, 0x7e2adac6UL, 0x494018c7UL, + 0xcc5657c2UL, 0xfb3c95c3UL, 0xa282d3c1UL, 0x95e811c0UL, 0xa8af4dcbUL, + 0x9fc58fcaUL, 0xc67bc9c8UL, 0xf1110bc9UL, 0x740744ccUL, 0x436d86cdUL, + 0x1ad3c0cfUL, 0x2db902ceUL, 0x4096af91UL, 0x77fc6d90UL, 0x2e422b92UL, + 0x1928e993UL, 0x9c3ea696UL, 0xab546497UL, 0xf2ea2295UL, 0xc580e094UL, + 0xf8c7bc9fUL, 0xcfad7e9eUL, 0x9613389cUL, 0xa179fa9dUL, 0x246fb598UL, + 0x13057799UL, 0x4abb319bUL, 0x7dd1f39aUL, 0x3035898dUL, 0x075f4b8cUL, + 0x5ee10d8eUL, 0x698bcf8fUL, 0xec9d808aUL, 0xdbf7428bUL, 0x82490489UL, + 0xb523c688UL, 0x88649a83UL, 0xbf0e5882UL, 0xe6b01e80UL, 0xd1dadc81UL, + 0x54cc9384UL, 0x63a65185UL, 0x3a181787UL, 0x0d72d586UL, 0xa0d0e2a9UL, + 0x97ba20a8UL, 0xce0466aaUL, 0xf96ea4abUL, 0x7c78ebaeUL, 0x4b1229afUL, + 0x12ac6fadUL, 0x25c6adacUL, 0x1881f1a7UL, 0x2feb33a6UL, 0x765575a4UL, + 0x413fb7a5UL, 0xc429f8a0UL, 0xf3433aa1UL, 0xaafd7ca3UL, 0x9d97bea2UL, + 0xd073c4b5UL, 0xe71906b4UL, 0xbea740b6UL, 0x89cd82b7UL, 0x0cdbcdb2UL, + 0x3bb10fb3UL, 0x620f49b1UL, 0x55658bb0UL, 0x6822d7bbUL, 0x5f4815baUL, + 0x06f653b8UL, 0x319c91b9UL, 0xb48adebcUL, 0x83e01cbdUL, 0xda5e5abfUL, + 0xed3498beUL + }, + { + 0x00000000UL, 0x6567bcb8UL, 0x8bc809aaUL, 0xeeafb512UL, 0x5797628fUL, + 0x32f0de37UL, 0xdc5f6b25UL, 0xb938d79dUL, 0xef28b4c5UL, 0x8a4f087dUL, + 0x64e0bd6fUL, 0x018701d7UL, 0xb8bfd64aUL, 0xddd86af2UL, 0x3377dfe0UL, + 0x56106358UL, 0x9f571950UL, 0xfa30a5e8UL, 0x149f10faUL, 0x71f8ac42UL, + 0xc8c07bdfUL, 0xada7c767UL, 0x43087275UL, 0x266fcecdUL, 0x707fad95UL, + 0x1518112dUL, 0xfbb7a43fUL, 0x9ed01887UL, 0x27e8cf1aUL, 0x428f73a2UL, + 0xac20c6b0UL, 0xc9477a08UL, 0x3eaf32a0UL, 0x5bc88e18UL, 0xb5673b0aUL, + 0xd00087b2UL, 0x6938502fUL, 0x0c5fec97UL, 0xe2f05985UL, 0x8797e53dUL, + 0xd1878665UL, 0xb4e03addUL, 0x5a4f8fcfUL, 0x3f283377UL, 0x8610e4eaUL, + 0xe3775852UL, 0x0dd8ed40UL, 0x68bf51f8UL, 0xa1f82bf0UL, 0xc49f9748UL, + 0x2a30225aUL, 0x4f579ee2UL, 0xf66f497fUL, 0x9308f5c7UL, 0x7da740d5UL, + 0x18c0fc6dUL, 0x4ed09f35UL, 0x2bb7238dUL, 0xc518969fUL, 0xa07f2a27UL, + 0x1947fdbaUL, 0x7c204102UL, 0x928ff410UL, 0xf7e848a8UL, 0x3d58149bUL, + 0x583fa823UL, 0xb6901d31UL, 0xd3f7a189UL, 0x6acf7614UL, 0x0fa8caacUL, + 0xe1077fbeUL, 0x8460c306UL, 0xd270a05eUL, 0xb7171ce6UL, 0x59b8a9f4UL, + 0x3cdf154cUL, 0x85e7c2d1UL, 0xe0807e69UL, 0x0e2fcb7bUL, 0x6b4877c3UL, + 0xa20f0dcbUL, 0xc768b173UL, 0x29c70461UL, 0x4ca0b8d9UL, 0xf5986f44UL, + 0x90ffd3fcUL, 0x7e5066eeUL, 0x1b37da56UL, 0x4d27b90eUL, 0x284005b6UL, + 0xc6efb0a4UL, 0xa3880c1cUL, 0x1ab0db81UL, 0x7fd76739UL, 0x9178d22bUL, + 0xf41f6e93UL, 0x03f7263bUL, 0x66909a83UL, 0x883f2f91UL, 0xed589329UL, + 0x546044b4UL, 0x3107f80cUL, 0xdfa84d1eUL, 0xbacff1a6UL, 0xecdf92feUL, + 0x89b82e46UL, 0x67179b54UL, 0x027027ecUL, 0xbb48f071UL, 0xde2f4cc9UL, + 0x3080f9dbUL, 0x55e74563UL, 0x9ca03f6bUL, 0xf9c783d3UL, 0x176836c1UL, + 0x720f8a79UL, 0xcb375de4UL, 0xae50e15cUL, 0x40ff544eUL, 0x2598e8f6UL, + 0x73888baeUL, 0x16ef3716UL, 0xf8408204UL, 0x9d273ebcUL, 0x241fe921UL, + 0x41785599UL, 0xafd7e08bUL, 0xcab05c33UL, 0x3bb659edUL, 0x5ed1e555UL, + 0xb07e5047UL, 0xd519ecffUL, 0x6c213b62UL, 0x094687daUL, 0xe7e932c8UL, + 0x828e8e70UL, 0xd49eed28UL, 0xb1f95190UL, 0x5f56e482UL, 0x3a31583aUL, + 0x83098fa7UL, 0xe66e331fUL, 0x08c1860dUL, 0x6da63ab5UL, 0xa4e140bdUL, + 0xc186fc05UL, 0x2f294917UL, 0x4a4ef5afUL, 0xf3762232UL, 0x96119e8aUL, + 0x78be2b98UL, 0x1dd99720UL, 0x4bc9f478UL, 0x2eae48c0UL, 0xc001fdd2UL, + 0xa566416aUL, 0x1c5e96f7UL, 0x79392a4fUL, 0x97969f5dUL, 0xf2f123e5UL, + 0x05196b4dUL, 0x607ed7f5UL, 0x8ed162e7UL, 0xebb6de5fUL, 0x528e09c2UL, + 0x37e9b57aUL, 0xd9460068UL, 0xbc21bcd0UL, 0xea31df88UL, 0x8f566330UL, + 0x61f9d622UL, 0x049e6a9aUL, 0xbda6bd07UL, 0xd8c101bfUL, 0x366eb4adUL, + 0x53090815UL, 0x9a4e721dUL, 0xff29cea5UL, 0x11867bb7UL, 0x74e1c70fUL, + 0xcdd91092UL, 0xa8beac2aUL, 0x46111938UL, 0x2376a580UL, 0x7566c6d8UL, + 0x10017a60UL, 0xfeaecf72UL, 0x9bc973caUL, 0x22f1a457UL, 0x479618efUL, + 0xa939adfdUL, 0xcc5e1145UL, 0x06ee4d76UL, 0x6389f1ceUL, 0x8d2644dcUL, + 0xe841f864UL, 0x51792ff9UL, 0x341e9341UL, 0xdab12653UL, 0xbfd69aebUL, + 0xe9c6f9b3UL, 0x8ca1450bUL, 0x620ef019UL, 0x07694ca1UL, 0xbe519b3cUL, + 0xdb362784UL, 0x35999296UL, 0x50fe2e2eUL, 0x99b95426UL, 0xfcdee89eUL, + 0x12715d8cUL, 0x7716e134UL, 0xce2e36a9UL, 0xab498a11UL, 0x45e63f03UL, + 0x208183bbUL, 0x7691e0e3UL, 0x13f65c5bUL, 0xfd59e949UL, 0x983e55f1UL, + 0x2106826cUL, 0x44613ed4UL, 0xaace8bc6UL, 0xcfa9377eUL, 0x38417fd6UL, + 0x5d26c36eUL, 0xb389767cUL, 0xd6eecac4UL, 0x6fd61d59UL, 0x0ab1a1e1UL, + 0xe41e14f3UL, 0x8179a84bUL, 0xd769cb13UL, 0xb20e77abUL, 0x5ca1c2b9UL, + 0x39c67e01UL, 0x80fea99cUL, 0xe5991524UL, 0x0b36a036UL, 0x6e511c8eUL, + 0xa7166686UL, 0xc271da3eUL, 0x2cde6f2cUL, 0x49b9d394UL, 0xf0810409UL, + 0x95e6b8b1UL, 0x7b490da3UL, 0x1e2eb11bUL, 0x483ed243UL, 0x2d596efbUL, + 0xc3f6dbe9UL, 0xa6916751UL, 0x1fa9b0ccUL, 0x7ace0c74UL, 0x9461b966UL, + 0xf10605deUL +#endif + } +}; diff --git a/libs/zlib/deflate.c b/libs/zlib/deflate.c new file mode 100644 index 000000000..8bd480eb6 --- /dev/null +++ b/libs/zlib/deflate.c @@ -0,0 +1,1965 @@ +/* deflate.c -- compress data using the deflation algorithm + * Copyright (C) 1995-2012 Jean-loup Gailly and Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* + * ALGORITHM + * + * The "deflation" process depends on being able to identify portions + * of the input text which are identical to earlier input (within a + * sliding window trailing behind the input currently being processed). + * + * The most straightforward technique turns out to be the fastest for + * most input files: try all possible matches and select the longest. + * The key feature of this algorithm is that insertions into the string + * dictionary are very simple and thus fast, and deletions are avoided + * completely. Insertions are performed at each input character, whereas + * string matches are performed only when the previous match ends. So it + * is preferable to spend more time in matches to allow very fast string + * insertions and avoid deletions. The matching algorithm for small + * strings is inspired from that of Rabin & Karp. A brute force approach + * is used to find longer strings when a small match has been found. + * A similar algorithm is used in comic (by Jan-Mark Wams) and freeze + * (by Leonid Broukhis). + * A previous version of this file used a more sophisticated algorithm + * (by Fiala and Greene) which is guaranteed to run in linear amortized + * time, but has a larger average cost, uses more memory and is patented. + * However the F&G algorithm may be faster for some highly redundant + * files if the parameter max_chain_length (described below) is too large. + * + * ACKNOWLEDGEMENTS + * + * The idea of lazy evaluation of matches is due to Jan-Mark Wams, and + * I found it in 'freeze' written by Leonid Broukhis. + * Thanks to many people for bug reports and testing. + * + * REFERENCES + * + * Deutsch, L.P.,"DEFLATE Compressed Data Format Specification". + * Available in http://tools.ietf.org/html/rfc1951 + * + * A description of the Rabin and Karp algorithm is given in the book + * "Algorithms" by R. Sedgewick, Addison-Wesley, p252. + * + * Fiala,E.R., and Greene,D.H. + * Data Compression with Finite Windows, Comm.ACM, 32,4 (1989) 490-595 + * + */ + +/* @(#) $Id$ */ + +#include "deflate.h" + +const char deflate_copyright[] = + " deflate 1.2.6 Copyright 1995-2012 Jean-loup Gailly and Mark Adler "; +/* + If you use the zlib library in a product, an acknowledgment is welcome + in the documentation of your product. If for some reason you cannot + include such an acknowledgment, I would appreciate that you keep this + copyright string in the executable of your product. + */ + +/* =========================================================================== + * Function prototypes. + */ +typedef enum { + need_more, /* block not completed, need more input or more output */ + block_done, /* block flush performed */ + finish_started, /* finish started, need only more output at next deflate */ + finish_done /* finish done, accept no more input or output */ +} block_state; + +typedef block_state (*compress_func) OF((deflate_state *s, int flush)); +/* Compression function. Returns the block state after the call. */ + +local void fill_window OF((deflate_state *s)); +local block_state deflate_stored OF((deflate_state *s, int flush)); +local block_state deflate_fast OF((deflate_state *s, int flush)); +#ifndef FASTEST +local block_state deflate_slow OF((deflate_state *s, int flush)); +#endif +local block_state deflate_rle OF((deflate_state *s, int flush)); +local block_state deflate_huff OF((deflate_state *s, int flush)); +local void lm_init OF((deflate_state *s)); +local void putShortMSB OF((deflate_state *s, uInt b)); +local void flush_pending OF((z_streamp strm)); +local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size)); +#ifdef ASMV + void match_init OF((void)); /* asm code initialization */ + uInt longest_match OF((deflate_state *s, IPos cur_match)); +#else +local uInt longest_match OF((deflate_state *s, IPos cur_match)); +#endif + +#ifdef DEBUG +local void check_match OF((deflate_state *s, IPos start, IPos match, + int length)); +#endif + +/* =========================================================================== + * Local data + */ + +#define NIL 0 +/* Tail of hash chains */ + +#ifndef TOO_FAR +# define TOO_FAR 4096 +#endif +/* Matches of length 3 are discarded if their distance exceeds TOO_FAR */ + +/* Values for max_lazy_match, good_match and max_chain_length, depending on + * the desired pack level (0..9). The values given below have been tuned to + * exclude worst case performance for pathological files. Better values may be + * found for specific files. + */ +typedef struct config_s { + ush good_length; /* reduce lazy search above this match length */ + ush max_lazy; /* do not perform lazy search above this match length */ + ush nice_length; /* quit search above this match length */ + ush max_chain; + compress_func func; +} config; + +#ifdef FASTEST +local const config configuration_table[2] = { +/* good lazy nice chain */ +/* 0 */ {0, 0, 0, 0, deflate_stored}, /* store only */ +/* 1 */ {4, 4, 8, 4, deflate_fast}}; /* max speed, no lazy matches */ +#else +local const config configuration_table[10] = { +/* good lazy nice chain */ +/* 0 */ {0, 0, 0, 0, deflate_stored}, /* store only */ +/* 1 */ {4, 4, 8, 4, deflate_fast}, /* max speed, no lazy matches */ +/* 2 */ {4, 5, 16, 8, deflate_fast}, +/* 3 */ {4, 6, 32, 32, deflate_fast}, + +/* 4 */ {4, 4, 16, 16, deflate_slow}, /* lazy matches */ +/* 5 */ {8, 16, 32, 32, deflate_slow}, +/* 6 */ {8, 16, 128, 128, deflate_slow}, +/* 7 */ {8, 32, 128, 256, deflate_slow}, +/* 8 */ {32, 128, 258, 1024, deflate_slow}, +/* 9 */ {32, 258, 258, 4096, deflate_slow}}; /* max compression */ +#endif + +/* Note: the deflate() code requires max_lazy >= MIN_MATCH and max_chain >= 4 + * For deflate_fast() (levels <= 3) good is ignored and lazy has a different + * meaning. + */ + +#define EQUAL 0 +/* result of memcmp for equal strings */ + +#ifndef NO_DUMMY_DECL +struct static_tree_desc_s {int dummy;}; /* for buggy compilers */ +#endif + +/* rank Z_BLOCK between Z_NO_FLUSH and Z_PARTIAL_FLUSH */ +#define RANK(f) (((f) << 1) - ((f) > 4 ? 9 : 0)) + +/* =========================================================================== + * Update a hash value with the given input byte + * IN assertion: all calls to to UPDATE_HASH are made with consecutive + * input characters, so that a running hash key can be computed from the + * previous key instead of complete recalculation each time. + */ +#define UPDATE_HASH(s,h,c) (h = (((h)<hash_shift) ^ (c)) & s->hash_mask) + + +/* =========================================================================== + * Insert string str in the dictionary and set match_head to the previous head + * of the hash chain (the most recent string with same hash key). Return + * the previous length of the hash chain. + * If this file is compiled with -DFASTEST, the compression level is forced + * to 1, and no hash chains are maintained. + * IN assertion: all calls to to INSERT_STRING are made with consecutive + * input characters and the first MIN_MATCH bytes of str are valid + * (except for the last MIN_MATCH-1 bytes of the input file). + */ +#ifdef FASTEST +#define INSERT_STRING(s, str, match_head) \ + (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \ + match_head = s->head[s->ins_h], \ + s->head[s->ins_h] = (Pos)(str)) +#else +#define INSERT_STRING(s, str, match_head) \ + (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \ + match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \ + s->head[s->ins_h] = (Pos)(str)) +#endif + +/* =========================================================================== + * Initialize the hash table (avoiding 64K overflow for 16 bit systems). + * prev[] will be initialized on the fly. + */ +#define CLEAR_HASH(s) \ + s->head[s->hash_size-1] = NIL; \ + zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head)); + +/* ========================================================================= */ +int ZEXPORT deflateInit_(strm, level, version, stream_size) + z_streamp strm; + int level; + const char *version; + int stream_size; +{ + return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL, + Z_DEFAULT_STRATEGY, version, stream_size); + /* To do: ignore strm->next_in if we use it as window */ +} + +/* ========================================================================= */ +int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy, + version, stream_size) + z_streamp strm; + int level; + int method; + int windowBits; + int memLevel; + int strategy; + const char *version; + int stream_size; +{ + deflate_state *s; + int wrap = 1; + static const char my_version[] = ZLIB_VERSION; + + ushf *overlay; + /* We overlay pending_buf and d_buf+l_buf. This works since the average + * output size for (length,distance) codes is <= 24 bits. + */ + + if (version == Z_NULL || version[0] != my_version[0] || + stream_size != sizeof(z_stream)) { + return Z_VERSION_ERROR; + } + if (strm == Z_NULL) return Z_STREAM_ERROR; + + strm->msg = Z_NULL; + if (strm->zalloc == (alloc_func)0) { +#ifdef Z_SOLO + return Z_STREAM_ERROR; +#else + strm->zalloc = zcalloc; + strm->opaque = (voidpf)0; +#endif + } + if (strm->zfree == (free_func)0) +#ifdef Z_SOLO + return Z_STREAM_ERROR; +#else + strm->zfree = zcfree; +#endif + +#ifdef FASTEST + if (level != 0) level = 1; +#else + if (level == Z_DEFAULT_COMPRESSION) level = 6; +#endif + + if (windowBits < 0) { /* suppress zlib wrapper */ + wrap = 0; + windowBits = -windowBits; + } +#ifdef GZIP + else if (windowBits > 15) { + wrap = 2; /* write gzip wrapper instead */ + windowBits -= 16; + } +#endif + if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED || + windowBits < 8 || windowBits > 15 || level < 0 || level > 9 || + strategy < 0 || strategy > Z_FIXED) { + return Z_STREAM_ERROR; + } + if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */ + s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state)); + if (s == Z_NULL) return Z_MEM_ERROR; + strm->state = (struct internal_state FAR *)s; + s->strm = strm; + + s->wrap = wrap; + s->gzhead = Z_NULL; + s->w_bits = windowBits; + s->w_size = 1 << s->w_bits; + s->w_mask = s->w_size - 1; + + s->hash_bits = memLevel + 7; + s->hash_size = 1 << s->hash_bits; + s->hash_mask = s->hash_size - 1; + s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH); + + s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte)); + s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos)); + s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos)); + + s->high_water = 0; /* nothing written to s->window yet */ + + s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */ + + overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2); + s->pending_buf = (uchf *) overlay; + s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L); + + if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL || + s->pending_buf == Z_NULL) { + s->status = FINISH_STATE; + strm->msg = (char*)ERR_MSG(Z_MEM_ERROR); + deflateEnd (strm); + return Z_MEM_ERROR; + } + s->d_buf = overlay + s->lit_bufsize/sizeof(ush); + s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize; + + s->level = level; + s->strategy = strategy; + s->method = (Byte)method; + + return deflateReset(strm); +} + +/* ========================================================================= */ +int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength) + z_streamp strm; + const Bytef *dictionary; + uInt dictLength; +{ + deflate_state *s; + uInt str, n; + int wrap; + unsigned avail; + unsigned char *next; + + if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL) + return Z_STREAM_ERROR; + s = strm->state; + wrap = s->wrap; + if (wrap == 2 || (wrap == 1 && s->status != INIT_STATE) || s->lookahead) + return Z_STREAM_ERROR; + + /* when using zlib wrappers, compute Adler-32 for provided dictionary */ + if (wrap == 1) + strm->adler = adler32(strm->adler, dictionary, dictLength); + s->wrap = 0; /* avoid computing Adler-32 in read_buf */ + + /* if dictionary would fill window, just replace the history */ + if (dictLength >= s->w_size) { + if (wrap == 0) { /* already empty otherwise */ + CLEAR_HASH(s); + s->strstart = 0; + s->block_start = 0L; + s->insert = 0; + } + dictionary += dictLength - s->w_size; /* use the tail */ + dictLength = s->w_size; + } + + /* insert dictionary into window and hash */ + avail = strm->avail_in; + next = strm->next_in; + strm->avail_in = dictLength; + strm->next_in = (Bytef *)dictionary; + fill_window(s); + while (s->lookahead >= MIN_MATCH) { + str = s->strstart; + n = s->lookahead - (MIN_MATCH-1); + do { + UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); +#ifndef FASTEST + s->prev[str & s->w_mask] = s->head[s->ins_h]; +#endif + s->head[s->ins_h] = (Pos)str; + str++; + } while (--n); + s->strstart = str; + s->lookahead = MIN_MATCH-1; + fill_window(s); + } + s->strstart += s->lookahead; + s->block_start = (long)s->strstart; + s->insert = s->lookahead; + s->lookahead = 0; + s->match_length = s->prev_length = MIN_MATCH-1; + s->match_available = 0; + strm->next_in = next; + strm->avail_in = avail; + s->wrap = wrap; + return Z_OK; +} + +/* ========================================================================= */ +int ZEXPORT deflateResetKeep (strm) + z_streamp strm; +{ + deflate_state *s; + + if (strm == Z_NULL || strm->state == Z_NULL || + strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) { + return Z_STREAM_ERROR; + } + + strm->total_in = strm->total_out = 0; + strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */ + strm->data_type = Z_UNKNOWN; + + s = (deflate_state *)strm->state; + s->pending = 0; + s->pending_out = s->pending_buf; + + if (s->wrap < 0) { + s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */ + } + s->status = s->wrap ? INIT_STATE : BUSY_STATE; + strm->adler = +#ifdef GZIP + s->wrap == 2 ? crc32(0L, Z_NULL, 0) : +#endif + adler32(0L, Z_NULL, 0); + s->last_flush = Z_NO_FLUSH; + + _tr_init(s); + + return Z_OK; +} + +/* ========================================================================= */ +int ZEXPORT deflateReset (strm) + z_streamp strm; +{ + int ret; + + ret = deflateResetKeep(strm); + if (ret == Z_OK) + lm_init(strm->state); + return ret; +} + +/* ========================================================================= */ +int ZEXPORT deflateSetHeader (strm, head) + z_streamp strm; + gz_headerp head; +{ + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; + if (strm->state->wrap != 2) return Z_STREAM_ERROR; + strm->state->gzhead = head; + return Z_OK; +} + +/* ========================================================================= */ +int ZEXPORT deflatePending (strm, pending, bits) + unsigned *pending; + int *bits; + z_streamp strm; +{ + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; + if (pending != Z_NULL) + *pending = strm->state->pending; + if (bits != Z_NULL) + *bits = strm->state->bi_valid; + return Z_OK; +} + +/* ========================================================================= */ +int ZEXPORT deflatePrime (strm, bits, value) + z_streamp strm; + int bits; + int value; +{ + deflate_state *s; + int put; + + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; + s = strm->state; + if ((Bytef *)(s->d_buf) < s->pending_out + ((Buf_size + 7) >> 3)) + return Z_BUF_ERROR; + do { + put = Buf_size - s->bi_valid; + if (put > bits) + put = bits; + s->bi_buf |= (ush)((value & ((1 << put) - 1)) << s->bi_valid); + s->bi_valid += put; + _tr_flush_bits(s); + value >>= put; + bits -= put; + } while (bits); + return Z_OK; +} + +/* ========================================================================= */ +int ZEXPORT deflateParams(strm, level, strategy) + z_streamp strm; + int level; + int strategy; +{ + deflate_state *s; + compress_func func; + int err = Z_OK; + + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; + s = strm->state; + +#ifdef FASTEST + if (level != 0) level = 1; +#else + if (level == Z_DEFAULT_COMPRESSION) level = 6; +#endif + if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) { + return Z_STREAM_ERROR; + } + func = configuration_table[s->level].func; + + if ((strategy != s->strategy || func != configuration_table[level].func) && + strm->total_in != 0) { + /* Flush the last buffer: */ + err = deflate(strm, Z_BLOCK); + } + if (s->level != level) { + s->level = level; + s->max_lazy_match = configuration_table[level].max_lazy; + s->good_match = configuration_table[level].good_length; + s->nice_match = configuration_table[level].nice_length; + s->max_chain_length = configuration_table[level].max_chain; + } + s->strategy = strategy; + return err; +} + +/* ========================================================================= */ +int ZEXPORT deflateTune(strm, good_length, max_lazy, nice_length, max_chain) + z_streamp strm; + int good_length; + int max_lazy; + int nice_length; + int max_chain; +{ + deflate_state *s; + + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; + s = strm->state; + s->good_match = good_length; + s->max_lazy_match = max_lazy; + s->nice_match = nice_length; + s->max_chain_length = max_chain; + return Z_OK; +} + +/* ========================================================================= + * For the default windowBits of 15 and memLevel of 8, this function returns + * a close to exact, as well as small, upper bound on the compressed size. + * They are coded as constants here for a reason--if the #define's are + * changed, then this function needs to be changed as well. The return + * value for 15 and 8 only works for those exact settings. + * + * For any setting other than those defaults for windowBits and memLevel, + * the value returned is a conservative worst case for the maximum expansion + * resulting from using fixed blocks instead of stored blocks, which deflate + * can emit on compressed data for some combinations of the parameters. + * + * This function could be more sophisticated to provide closer upper bounds for + * every combination of windowBits and memLevel. But even the conservative + * upper bound of about 14% expansion does not seem onerous for output buffer + * allocation. + */ +uLong ZEXPORT deflateBound(strm, sourceLen) + z_streamp strm; + uLong sourceLen; +{ + deflate_state *s; + uLong complen, wraplen; + Bytef *str; + + /* conservative upper bound for compressed data */ + complen = sourceLen + + ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 5; + + /* if can't get parameters, return conservative bound plus zlib wrapper */ + if (strm == Z_NULL || strm->state == Z_NULL) + return complen + 6; + + /* compute wrapper length */ + s = strm->state; + switch (s->wrap) { + case 0: /* raw deflate */ + wraplen = 0; + break; + case 1: /* zlib wrapper */ + wraplen = 6 + (s->strstart ? 4 : 0); + break; + case 2: /* gzip wrapper */ + wraplen = 18; + if (s->gzhead != Z_NULL) { /* user-supplied gzip header */ + if (s->gzhead->extra != Z_NULL) + wraplen += 2 + s->gzhead->extra_len; + str = s->gzhead->name; + if (str != Z_NULL) + do { + wraplen++; + } while (*str++); + str = s->gzhead->comment; + if (str != Z_NULL) + do { + wraplen++; + } while (*str++); + if (s->gzhead->hcrc) + wraplen += 2; + } + break; + default: /* for compiler happiness */ + wraplen = 6; + } + + /* if not default parameters, return conservative bound */ + if (s->w_bits != 15 || s->hash_bits != 8 + 7) + return complen + wraplen; + + /* default settings: return tight bound for that case */ + return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + + (sourceLen >> 25) + 13 - 6 + wraplen; +} + +/* ========================================================================= + * Put a short in the pending buffer. The 16-bit value is put in MSB order. + * IN assertion: the stream state is correct and there is enough room in + * pending_buf. + */ +local void putShortMSB (s, b) + deflate_state *s; + uInt b; +{ + put_byte(s, (Byte)(b >> 8)); + put_byte(s, (Byte)(b & 0xff)); +} + +/* ========================================================================= + * Flush as much pending output as possible. All deflate() output goes + * through this function so some applications may wish to modify it + * to avoid allocating a large strm->next_out buffer and copying into it. + * (See also read_buf()). + */ +local void flush_pending(strm) + z_streamp strm; +{ + unsigned len; + deflate_state *s = strm->state; + + _tr_flush_bits(s); + len = s->pending; + if (len > strm->avail_out) len = strm->avail_out; + if (len == 0) return; + + zmemcpy(strm->next_out, s->pending_out, len); + strm->next_out += len; + s->pending_out += len; + strm->total_out += len; + strm->avail_out -= len; + s->pending -= len; + if (s->pending == 0) { + s->pending_out = s->pending_buf; + } +} + +/* ========================================================================= */ +int ZEXPORT deflate (strm, flush) + z_streamp strm; + int flush; +{ + int old_flush; /* value of flush param for previous deflate call */ + deflate_state *s; + + if (strm == Z_NULL || strm->state == Z_NULL || + flush > Z_BLOCK || flush < 0) { + return Z_STREAM_ERROR; + } + s = strm->state; + + if (strm->next_out == Z_NULL || + (strm->next_in == Z_NULL && strm->avail_in != 0) || + (s->status == FINISH_STATE && flush != Z_FINISH)) { + ERR_RETURN(strm, Z_STREAM_ERROR); + } + if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR); + + s->strm = strm; /* just in case */ + old_flush = s->last_flush; + s->last_flush = flush; + + /* Write the header */ + if (s->status == INIT_STATE) { +#ifdef GZIP + if (s->wrap == 2) { + strm->adler = crc32(0L, Z_NULL, 0); + put_byte(s, 31); + put_byte(s, 139); + put_byte(s, 8); + if (s->gzhead == Z_NULL) { + put_byte(s, 0); + put_byte(s, 0); + put_byte(s, 0); + put_byte(s, 0); + put_byte(s, 0); + put_byte(s, s->level == 9 ? 2 : + (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ? + 4 : 0)); + put_byte(s, OS_CODE); + s->status = BUSY_STATE; + } + else { + put_byte(s, (s->gzhead->text ? 1 : 0) + + (s->gzhead->hcrc ? 2 : 0) + + (s->gzhead->extra == Z_NULL ? 0 : 4) + + (s->gzhead->name == Z_NULL ? 0 : 8) + + (s->gzhead->comment == Z_NULL ? 0 : 16) + ); + put_byte(s, (Byte)(s->gzhead->time & 0xff)); + put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff)); + put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff)); + put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff)); + put_byte(s, s->level == 9 ? 2 : + (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ? + 4 : 0)); + put_byte(s, s->gzhead->os & 0xff); + if (s->gzhead->extra != Z_NULL) { + put_byte(s, s->gzhead->extra_len & 0xff); + put_byte(s, (s->gzhead->extra_len >> 8) & 0xff); + } + if (s->gzhead->hcrc) + strm->adler = crc32(strm->adler, s->pending_buf, + s->pending); + s->gzindex = 0; + s->status = EXTRA_STATE; + } + } + else +#endif + { + uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8; + uInt level_flags; + + if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2) + level_flags = 0; + else if (s->level < 6) + level_flags = 1; + else if (s->level == 6) + level_flags = 2; + else + level_flags = 3; + header |= (level_flags << 6); + if (s->strstart != 0) header |= PRESET_DICT; + header += 31 - (header % 31); + + s->status = BUSY_STATE; + putShortMSB(s, header); + + /* Save the adler32 of the preset dictionary: */ + if (s->strstart != 0) { + putShortMSB(s, (uInt)(strm->adler >> 16)); + putShortMSB(s, (uInt)(strm->adler & 0xffff)); + } + strm->adler = adler32(0L, Z_NULL, 0); + } + } +#ifdef GZIP + if (s->status == EXTRA_STATE) { + if (s->gzhead->extra != Z_NULL) { + uInt beg = s->pending; /* start of bytes to update crc */ + + while (s->gzindex < (s->gzhead->extra_len & 0xffff)) { + if (s->pending == s->pending_buf_size) { + if (s->gzhead->hcrc && s->pending > beg) + strm->adler = crc32(strm->adler, s->pending_buf + beg, + s->pending - beg); + flush_pending(strm); + beg = s->pending; + if (s->pending == s->pending_buf_size) + break; + } + put_byte(s, s->gzhead->extra[s->gzindex]); + s->gzindex++; + } + if (s->gzhead->hcrc && s->pending > beg) + strm->adler = crc32(strm->adler, s->pending_buf + beg, + s->pending - beg); + if (s->gzindex == s->gzhead->extra_len) { + s->gzindex = 0; + s->status = NAME_STATE; + } + } + else + s->status = NAME_STATE; + } + if (s->status == NAME_STATE) { + if (s->gzhead->name != Z_NULL) { + uInt beg = s->pending; /* start of bytes to update crc */ + int val; + + do { + if (s->pending == s->pending_buf_size) { + if (s->gzhead->hcrc && s->pending > beg) + strm->adler = crc32(strm->adler, s->pending_buf + beg, + s->pending - beg); + flush_pending(strm); + beg = s->pending; + if (s->pending == s->pending_buf_size) { + val = 1; + break; + } + } + val = s->gzhead->name[s->gzindex++]; + put_byte(s, val); + } while (val != 0); + if (s->gzhead->hcrc && s->pending > beg) + strm->adler = crc32(strm->adler, s->pending_buf + beg, + s->pending - beg); + if (val == 0) { + s->gzindex = 0; + s->status = COMMENT_STATE; + } + } + else + s->status = COMMENT_STATE; + } + if (s->status == COMMENT_STATE) { + if (s->gzhead->comment != Z_NULL) { + uInt beg = s->pending; /* start of bytes to update crc */ + int val; + + do { + if (s->pending == s->pending_buf_size) { + if (s->gzhead->hcrc && s->pending > beg) + strm->adler = crc32(strm->adler, s->pending_buf + beg, + s->pending - beg); + flush_pending(strm); + beg = s->pending; + if (s->pending == s->pending_buf_size) { + val = 1; + break; + } + } + val = s->gzhead->comment[s->gzindex++]; + put_byte(s, val); + } while (val != 0); + if (s->gzhead->hcrc && s->pending > beg) + strm->adler = crc32(strm->adler, s->pending_buf + beg, + s->pending - beg); + if (val == 0) + s->status = HCRC_STATE; + } + else + s->status = HCRC_STATE; + } + if (s->status == HCRC_STATE) { + if (s->gzhead->hcrc) { + if (s->pending + 2 > s->pending_buf_size) + flush_pending(strm); + if (s->pending + 2 <= s->pending_buf_size) { + put_byte(s, (Byte)(strm->adler & 0xff)); + put_byte(s, (Byte)((strm->adler >> 8) & 0xff)); + strm->adler = crc32(0L, Z_NULL, 0); + s->status = BUSY_STATE; + } + } + else + s->status = BUSY_STATE; + } +#endif + + /* Flush as much pending output as possible */ + if (s->pending != 0) { + flush_pending(strm); + if (strm->avail_out == 0) { + /* Since avail_out is 0, deflate will be called again with + * more output space, but possibly with both pending and + * avail_in equal to zero. There won't be anything to do, + * but this is not an error situation so make sure we + * return OK instead of BUF_ERROR at next call of deflate: + */ + s->last_flush = -1; + return Z_OK; + } + + /* Make sure there is something to do and avoid duplicate consecutive + * flushes. For repeated and useless calls with Z_FINISH, we keep + * returning Z_STREAM_END instead of Z_BUF_ERROR. + */ + } else if (strm->avail_in == 0 && RANK(flush) <= RANK(old_flush) && + flush != Z_FINISH) { + ERR_RETURN(strm, Z_BUF_ERROR); + } + + /* User must not provide more input after the first FINISH: */ + if (s->status == FINISH_STATE && strm->avail_in != 0) { + ERR_RETURN(strm, Z_BUF_ERROR); + } + + /* Start a new block or continue the current one. + */ + if (strm->avail_in != 0 || s->lookahead != 0 || + (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) { + block_state bstate; + + bstate = s->strategy == Z_HUFFMAN_ONLY ? deflate_huff(s, flush) : + (s->strategy == Z_RLE ? deflate_rle(s, flush) : + (*(configuration_table[s->level].func))(s, flush)); + + if (bstate == finish_started || bstate == finish_done) { + s->status = FINISH_STATE; + } + if (bstate == need_more || bstate == finish_started) { + if (strm->avail_out == 0) { + s->last_flush = -1; /* avoid BUF_ERROR next call, see above */ + } + return Z_OK; + /* If flush != Z_NO_FLUSH && avail_out == 0, the next call + * of deflate should use the same flush parameter to make sure + * that the flush is complete. So we don't have to output an + * empty block here, this will be done at next call. This also + * ensures that for a very small output buffer, we emit at most + * one empty block. + */ + } + if (bstate == block_done) { + if (flush == Z_PARTIAL_FLUSH) { + _tr_align(s); + } else if (flush != Z_BLOCK) { /* FULL_FLUSH or SYNC_FLUSH */ + _tr_stored_block(s, (char*)0, 0L, 0); + /* For a full flush, this empty block will be recognized + * as a special marker by inflate_sync(). + */ + if (flush == Z_FULL_FLUSH) { + CLEAR_HASH(s); /* forget history */ + if (s->lookahead == 0) { + s->strstart = 0; + s->block_start = 0L; + s->insert = 0; + } + } + } + flush_pending(strm); + if (strm->avail_out == 0) { + s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */ + return Z_OK; + } + } + } + Assert(strm->avail_out > 0, "bug2"); + + if (flush != Z_FINISH) return Z_OK; + if (s->wrap <= 0) return Z_STREAM_END; + + /* Write the trailer */ +#ifdef GZIP + if (s->wrap == 2) { + put_byte(s, (Byte)(strm->adler & 0xff)); + put_byte(s, (Byte)((strm->adler >> 8) & 0xff)); + put_byte(s, (Byte)((strm->adler >> 16) & 0xff)); + put_byte(s, (Byte)((strm->adler >> 24) & 0xff)); + put_byte(s, (Byte)(strm->total_in & 0xff)); + put_byte(s, (Byte)((strm->total_in >> 8) & 0xff)); + put_byte(s, (Byte)((strm->total_in >> 16) & 0xff)); + put_byte(s, (Byte)((strm->total_in >> 24) & 0xff)); + } + else +#endif + { + putShortMSB(s, (uInt)(strm->adler >> 16)); + putShortMSB(s, (uInt)(strm->adler & 0xffff)); + } + flush_pending(strm); + /* If avail_out is zero, the application will call deflate again + * to flush the rest. + */ + if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */ + return s->pending != 0 ? Z_OK : Z_STREAM_END; +} + +/* ========================================================================= */ +int ZEXPORT deflateEnd (strm) + z_streamp strm; +{ + int status; + + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; + + status = strm->state->status; + if (status != INIT_STATE && + status != EXTRA_STATE && + status != NAME_STATE && + status != COMMENT_STATE && + status != HCRC_STATE && + status != BUSY_STATE && + status != FINISH_STATE) { + return Z_STREAM_ERROR; + } + + /* Deallocate in reverse order of allocations: */ + TRY_FREE(strm, strm->state->pending_buf); + TRY_FREE(strm, strm->state->head); + TRY_FREE(strm, strm->state->prev); + TRY_FREE(strm, strm->state->window); + + ZFREE(strm, strm->state); + strm->state = Z_NULL; + + return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK; +} + +/* ========================================================================= + * Copy the source state to the destination state. + * To simplify the source, this is not supported for 16-bit MSDOS (which + * doesn't have enough memory anyway to duplicate compression states). + */ +int ZEXPORT deflateCopy (dest, source) + z_streamp dest; + z_streamp source; +{ +#ifdef MAXSEG_64K + return Z_STREAM_ERROR; +#else + deflate_state *ds; + deflate_state *ss; + ushf *overlay; + + + if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) { + return Z_STREAM_ERROR; + } + + ss = source->state; + + zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream)); + + ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state)); + if (ds == Z_NULL) return Z_MEM_ERROR; + dest->state = (struct internal_state FAR *) ds; + zmemcpy((voidpf)ds, (voidpf)ss, sizeof(deflate_state)); + ds->strm = dest; + + ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte)); + ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos)); + ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos)); + overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2); + ds->pending_buf = (uchf *) overlay; + + if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL || + ds->pending_buf == Z_NULL) { + deflateEnd (dest); + return Z_MEM_ERROR; + } + /* following zmemcpy do not work for 16-bit MSDOS */ + zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte)); + zmemcpy((voidpf)ds->prev, (voidpf)ss->prev, ds->w_size * sizeof(Pos)); + zmemcpy((voidpf)ds->head, (voidpf)ss->head, ds->hash_size * sizeof(Pos)); + zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size); + + ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf); + ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush); + ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize; + + ds->l_desc.dyn_tree = ds->dyn_ltree; + ds->d_desc.dyn_tree = ds->dyn_dtree; + ds->bl_desc.dyn_tree = ds->bl_tree; + + return Z_OK; +#endif /* MAXSEG_64K */ +} + +/* =========================================================================== + * Read a new buffer from the current input stream, update the adler32 + * and total number of bytes read. All deflate() input goes through + * this function so some applications may wish to modify it to avoid + * allocating a large strm->next_in buffer and copying from it. + * (See also flush_pending()). + */ +local int read_buf(strm, buf, size) + z_streamp strm; + Bytef *buf; + unsigned size; +{ + unsigned len = strm->avail_in; + + if (len > size) len = size; + if (len == 0) return 0; + + strm->avail_in -= len; + + zmemcpy(buf, strm->next_in, len); + if (strm->state->wrap == 1) { + strm->adler = adler32(strm->adler, buf, len); + } +#ifdef GZIP + else if (strm->state->wrap == 2) { + strm->adler = crc32(strm->adler, buf, len); + } +#endif + strm->next_in += len; + strm->total_in += len; + + return (int)len; +} + +/* =========================================================================== + * Initialize the "longest match" routines for a new zlib stream + */ +local void lm_init (s) + deflate_state *s; +{ + s->window_size = (ulg)2L*s->w_size; + + CLEAR_HASH(s); + + /* Set the default configuration parameters: + */ + s->max_lazy_match = configuration_table[s->level].max_lazy; + s->good_match = configuration_table[s->level].good_length; + s->nice_match = configuration_table[s->level].nice_length; + s->max_chain_length = configuration_table[s->level].max_chain; + + s->strstart = 0; + s->block_start = 0L; + s->lookahead = 0; + s->insert = 0; + s->match_length = s->prev_length = MIN_MATCH-1; + s->match_available = 0; + s->ins_h = 0; +#ifndef FASTEST +#ifdef ASMV + match_init(); /* initialize the asm code */ +#endif +#endif +} + +#ifndef FASTEST +/* =========================================================================== + * Set match_start to the longest match starting at the given string and + * return its length. Matches shorter or equal to prev_length are discarded, + * in which case the result is equal to prev_length and match_start is + * garbage. + * IN assertions: cur_match is the head of the hash chain for the current + * string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1 + * OUT assertion: the match length is not greater than s->lookahead. + */ +#ifndef ASMV +/* For 80x86 and 680x0, an optimized version will be provided in match.asm or + * match.S. The code will be functionally equivalent. + */ +local uInt longest_match(s, cur_match) + deflate_state *s; + IPos cur_match; /* current match */ +{ + unsigned chain_length = s->max_chain_length;/* max hash chain length */ + register Bytef *scan = s->window + s->strstart; /* current string */ + register Bytef *match; /* matched string */ + register int len; /* length of current match */ + int best_len = s->prev_length; /* best match length so far */ + int nice_match = s->nice_match; /* stop if match long enough */ + IPos limit = s->strstart > (IPos)MAX_DIST(s) ? + s->strstart - (IPos)MAX_DIST(s) : NIL; + /* Stop when cur_match becomes <= limit. To simplify the code, + * we prevent matches with the string of window index 0. + */ + Posf *prev = s->prev; + uInt wmask = s->w_mask; + +#ifdef UNALIGNED_OK + /* Compare two bytes at a time. Note: this is not always beneficial. + * Try with and without -DUNALIGNED_OK to check. + */ + register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1; + register ush scan_start = *(ushf*)scan; + register ush scan_end = *(ushf*)(scan+best_len-1); +#else + register Bytef *strend = s->window + s->strstart + MAX_MATCH; + register Byte scan_end1 = scan[best_len-1]; + register Byte scan_end = scan[best_len]; +#endif + + /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16. + * It is easy to get rid of this optimization if necessary. + */ + Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever"); + + /* Do not waste too much time if we already have a good match: */ + if (s->prev_length >= s->good_match) { + chain_length >>= 2; + } + /* Do not look for matches beyond the end of the input. This is necessary + * to make deflate deterministic. + */ + if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead; + + Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead"); + + do { + Assert(cur_match < s->strstart, "no future"); + match = s->window + cur_match; + + /* Skip to next match if the match length cannot increase + * or if the match length is less than 2. Note that the checks below + * for insufficient lookahead only occur occasionally for performance + * reasons. Therefore uninitialized memory will be accessed, and + * conditional jumps will be made that depend on those values. + * However the length of the match is limited to the lookahead, so + * the output of deflate is not affected by the uninitialized values. + */ +#if (defined(UNALIGNED_OK) && MAX_MATCH == 258) + /* This code assumes sizeof(unsigned short) == 2. Do not use + * UNALIGNED_OK if your compiler uses a different size. + */ + if (*(ushf*)(match+best_len-1) != scan_end || + *(ushf*)match != scan_start) continue; + + /* It is not necessary to compare scan[2] and match[2] since they are + * always equal when the other bytes match, given that the hash keys + * are equal and that HASH_BITS >= 8. Compare 2 bytes at a time at + * strstart+3, +5, ... up to strstart+257. We check for insufficient + * lookahead only every 4th comparison; the 128th check will be made + * at strstart+257. If MAX_MATCH-2 is not a multiple of 8, it is + * necessary to put more guard bytes at the end of the window, or + * to check more often for insufficient lookahead. + */ + Assert(scan[2] == match[2], "scan[2]?"); + scan++, match++; + do { + } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) && + *(ushf*)(scan+=2) == *(ushf*)(match+=2) && + *(ushf*)(scan+=2) == *(ushf*)(match+=2) && + *(ushf*)(scan+=2) == *(ushf*)(match+=2) && + scan < strend); + /* The funny "do {}" generates better code on most compilers */ + + /* Here, scan <= window+strstart+257 */ + Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); + if (*scan == *match) scan++; + + len = (MAX_MATCH - 1) - (int)(strend-scan); + scan = strend - (MAX_MATCH-1); + +#else /* UNALIGNED_OK */ + + if (match[best_len] != scan_end || + match[best_len-1] != scan_end1 || + *match != *scan || + *++match != scan[1]) continue; + + /* The check at best_len-1 can be removed because it will be made + * again later. (This heuristic is not always a win.) + * It is not necessary to compare scan[2] and match[2] since they + * are always equal when the other bytes match, given that + * the hash keys are equal and that HASH_BITS >= 8. + */ + scan += 2, match++; + Assert(*scan == *match, "match[2]?"); + + /* We check for insufficient lookahead only every 8th comparison; + * the 256th check will be made at strstart+258. + */ + do { + } while (*++scan == *++match && *++scan == *++match && + *++scan == *++match && *++scan == *++match && + *++scan == *++match && *++scan == *++match && + *++scan == *++match && *++scan == *++match && + scan < strend); + + Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); + + len = MAX_MATCH - (int)(strend - scan); + scan = strend - MAX_MATCH; + +#endif /* UNALIGNED_OK */ + + if (len > best_len) { + s->match_start = cur_match; + best_len = len; + if (len >= nice_match) break; +#ifdef UNALIGNED_OK + scan_end = *(ushf*)(scan+best_len-1); +#else + scan_end1 = scan[best_len-1]; + scan_end = scan[best_len]; +#endif + } + } while ((cur_match = prev[cur_match & wmask]) > limit + && --chain_length != 0); + + if ((uInt)best_len <= s->lookahead) return (uInt)best_len; + return s->lookahead; +} +#endif /* ASMV */ + +#else /* FASTEST */ + +/* --------------------------------------------------------------------------- + * Optimized version for FASTEST only + */ +local uInt longest_match(s, cur_match) + deflate_state *s; + IPos cur_match; /* current match */ +{ + register Bytef *scan = s->window + s->strstart; /* current string */ + register Bytef *match; /* matched string */ + register int len; /* length of current match */ + register Bytef *strend = s->window + s->strstart + MAX_MATCH; + + /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16. + * It is easy to get rid of this optimization if necessary. + */ + Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever"); + + Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead"); + + Assert(cur_match < s->strstart, "no future"); + + match = s->window + cur_match; + + /* Return failure if the match length is less than 2: + */ + if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1; + + /* The check at best_len-1 can be removed because it will be made + * again later. (This heuristic is not always a win.) + * It is not necessary to compare scan[2] and match[2] since they + * are always equal when the other bytes match, given that + * the hash keys are equal and that HASH_BITS >= 8. + */ + scan += 2, match += 2; + Assert(*scan == *match, "match[2]?"); + + /* We check for insufficient lookahead only every 8th comparison; + * the 256th check will be made at strstart+258. + */ + do { + } while (*++scan == *++match && *++scan == *++match && + *++scan == *++match && *++scan == *++match && + *++scan == *++match && *++scan == *++match && + *++scan == *++match && *++scan == *++match && + scan < strend); + + Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); + + len = MAX_MATCH - (int)(strend - scan); + + if (len < MIN_MATCH) return MIN_MATCH - 1; + + s->match_start = cur_match; + return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead; +} + +#endif /* FASTEST */ + +#ifdef DEBUG +/* =========================================================================== + * Check that the match at match_start is indeed a match. + */ +local void check_match(s, start, match, length) + deflate_state *s; + IPos start, match; + int length; +{ + /* check that the match is indeed a match */ + if (zmemcmp(s->window + match, + s->window + start, length) != EQUAL) { + fprintf(stderr, " start %u, match %u, length %d\n", + start, match, length); + do { + fprintf(stderr, "%c%c", s->window[match++], s->window[start++]); + } while (--length != 0); + z_error("invalid match"); + } + if (z_verbose > 1) { + fprintf(stderr,"\\[%d,%d]", start-match, length); + do { putc(s->window[start++], stderr); } while (--length != 0); + } +} +#else +# define check_match(s, start, match, length) +#endif /* DEBUG */ + +/* =========================================================================== + * Fill the window when the lookahead becomes insufficient. + * Updates strstart and lookahead. + * + * IN assertion: lookahead < MIN_LOOKAHEAD + * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD + * At least one byte has been read, or avail_in == 0; reads are + * performed for at least two bytes (required for the zip translate_eol + * option -- not supported here). + */ +local void fill_window(s) + deflate_state *s; +{ + register unsigned n, m; + register Posf *p; + unsigned more; /* Amount of free space at the end of the window. */ + uInt wsize = s->w_size; + + Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead"); + + do { + more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart); + + /* Deal with !@#$% 64K limit: */ + if (sizeof(int) <= 2) { + if (more == 0 && s->strstart == 0 && s->lookahead == 0) { + more = wsize; + + } else if (more == (unsigned)(-1)) { + /* Very unlikely, but possible on 16 bit machine if + * strstart == 0 && lookahead == 1 (input done a byte at time) + */ + more--; + } + } + + /* If the window is almost full and there is insufficient lookahead, + * move the upper half to the lower one to make room in the upper half. + */ + if (s->strstart >= wsize+MAX_DIST(s)) { + + zmemcpy(s->window, s->window+wsize, (unsigned)wsize); + s->match_start -= wsize; + s->strstart -= wsize; /* we now have strstart >= MAX_DIST */ + s->block_start -= (long) wsize; + + /* Slide the hash table (could be avoided with 32 bit values + at the expense of memory usage). We slide even when level == 0 + to keep the hash table consistent if we switch back to level > 0 + later. (Using level 0 permanently is not an optimal usage of + zlib, so we don't care about this pathological case.) + */ + n = s->hash_size; + p = &s->head[n]; + do { + m = *--p; + *p = (Pos)(m >= wsize ? m-wsize : NIL); + } while (--n); + + n = wsize; +#ifndef FASTEST + p = &s->prev[n]; + do { + m = *--p; + *p = (Pos)(m >= wsize ? m-wsize : NIL); + /* If n is not on any hash chain, prev[n] is garbage but + * its value will never be used. + */ + } while (--n); +#endif + more += wsize; + } + if (s->strm->avail_in == 0) break; + + /* If there was no sliding: + * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 && + * more == window_size - lookahead - strstart + * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1) + * => more >= window_size - 2*WSIZE + 2 + * In the BIG_MEM or MMAP case (not yet supported), + * window_size == input_size + MIN_LOOKAHEAD && + * strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD. + * Otherwise, window_size == 2*WSIZE so more >= 2. + * If there was sliding, more >= WSIZE. So in all cases, more >= 2. + */ + Assert(more >= 2, "more < 2"); + + n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more); + s->lookahead += n; + + /* Initialize the hash value now that we have some input: */ + if (s->lookahead + s->insert >= MIN_MATCH) { + uInt str = s->strstart - s->insert; + s->ins_h = s->window[str]; + UPDATE_HASH(s, s->ins_h, s->window[str + 1]); +#if MIN_MATCH != 3 + Call UPDATE_HASH() MIN_MATCH-3 more times +#endif + while (s->insert) { + UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); +#ifndef FASTEST + s->prev[str & s->w_mask] = s->head[s->ins_h]; +#endif + s->head[s->ins_h] = (Pos)str; + str++; + s->insert--; + if (s->lookahead + s->insert < MIN_MATCH) + break; + } + } + /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage, + * but this is not important since only literal bytes will be emitted. + */ + + } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0); + + /* If the WIN_INIT bytes after the end of the current data have never been + * written, then zero those bytes in order to avoid memory check reports of + * the use of uninitialized (or uninitialised as Julian writes) bytes by + * the longest match routines. Update the high water mark for the next + * time through here. WIN_INIT is set to MAX_MATCH since the longest match + * routines allow scanning to strstart + MAX_MATCH, ignoring lookahead. + */ + if (s->high_water < s->window_size) { + ulg curr = s->strstart + (ulg)(s->lookahead); + ulg init; + + if (s->high_water < curr) { + /* Previous high water mark below current data -- zero WIN_INIT + * bytes or up to end of window, whichever is less. + */ + init = s->window_size - curr; + if (init > WIN_INIT) + init = WIN_INIT; + zmemzero(s->window + curr, (unsigned)init); + s->high_water = curr + init; + } + else if (s->high_water < (ulg)curr + WIN_INIT) { + /* High water mark at or above current data, but below current data + * plus WIN_INIT -- zero out to current data plus WIN_INIT, or up + * to end of window, whichever is less. + */ + init = (ulg)curr + WIN_INIT - s->high_water; + if (init > s->window_size - s->high_water) + init = s->window_size - s->high_water; + zmemzero(s->window + s->high_water, (unsigned)init); + s->high_water += init; + } + } + + Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD, + "not enough room for search"); +} + +/* =========================================================================== + * Flush the current block, with given end-of-file flag. + * IN assertion: strstart is set to the end of the current match. + */ +#define FLUSH_BLOCK_ONLY(s, last) { \ + _tr_flush_block(s, (s->block_start >= 0L ? \ + (charf *)&s->window[(unsigned)s->block_start] : \ + (charf *)Z_NULL), \ + (ulg)((long)s->strstart - s->block_start), \ + (last)); \ + s->block_start = s->strstart; \ + flush_pending(s->strm); \ + Tracev((stderr,"[FLUSH]")); \ +} + +/* Same but force premature exit if necessary. */ +#define FLUSH_BLOCK(s, last) { \ + FLUSH_BLOCK_ONLY(s, last); \ + if (s->strm->avail_out == 0) return (last) ? finish_started : need_more; \ +} + +/* =========================================================================== + * Copy without compression as much as possible from the input stream, return + * the current block state. + * This function does not insert new strings in the dictionary since + * uncompressible data is probably not useful. This function is used + * only for the level=0 compression option. + * NOTE: this function should be optimized to avoid extra copying from + * window to pending_buf. + */ +local block_state deflate_stored(s, flush) + deflate_state *s; + int flush; +{ + /* Stored blocks are limited to 0xffff bytes, pending_buf is limited + * to pending_buf_size, and each stored block has a 5 byte header: + */ + ulg max_block_size = 0xffff; + ulg max_start; + + if (max_block_size > s->pending_buf_size - 5) { + max_block_size = s->pending_buf_size - 5; + } + + /* Copy as much as possible from input to output: */ + for (;;) { + /* Fill the window as much as possible: */ + if (s->lookahead <= 1) { + + Assert(s->strstart < s->w_size+MAX_DIST(s) || + s->block_start >= (long)s->w_size, "slide too late"); + + fill_window(s); + if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more; + + if (s->lookahead == 0) break; /* flush the current block */ + } + Assert(s->block_start >= 0L, "block gone"); + + s->strstart += s->lookahead; + s->lookahead = 0; + + /* Emit a stored block if pending_buf will be full: */ + max_start = s->block_start + max_block_size; + if (s->strstart == 0 || (ulg)s->strstart >= max_start) { + /* strstart == 0 is possible when wraparound on 16-bit machine */ + s->lookahead = (uInt)(s->strstart - max_start); + s->strstart = (uInt)max_start; + FLUSH_BLOCK(s, 0); + } + /* Flush if we may have to slide, otherwise block_start may become + * negative and the data will be gone: + */ + if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) { + FLUSH_BLOCK(s, 0); + } + } + s->insert = 0; + if (flush == Z_FINISH) { + FLUSH_BLOCK(s, 1); + return finish_done; + } + if ((long)s->strstart > s->block_start) + FLUSH_BLOCK(s, 0); + return block_done; +} + +/* =========================================================================== + * Compress as much as possible from the input stream, return the current + * block state. + * This function does not perform lazy evaluation of matches and inserts + * new strings in the dictionary only for unmatched strings or for short + * matches. It is used only for the fast compression options. + */ +local block_state deflate_fast(s, flush) + deflate_state *s; + int flush; +{ + IPos hash_head; /* head of the hash chain */ + int bflush; /* set if current block must be flushed */ + + for (;;) { + /* Make sure that we always have enough lookahead, except + * at the end of the input file. We need MAX_MATCH bytes + * for the next match, plus MIN_MATCH bytes to insert the + * string following the next match. + */ + if (s->lookahead < MIN_LOOKAHEAD) { + fill_window(s); + if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) { + return need_more; + } + if (s->lookahead == 0) break; /* flush the current block */ + } + + /* Insert the string window[strstart .. strstart+2] in the + * dictionary, and set hash_head to the head of the hash chain: + */ + hash_head = NIL; + if (s->lookahead >= MIN_MATCH) { + INSERT_STRING(s, s->strstart, hash_head); + } + + /* Find the longest match, discarding those <= prev_length. + * At this point we have always match_length < MIN_MATCH + */ + if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) { + /* To simplify the code, we prevent matches with the string + * of window index 0 (in particular we have to avoid a match + * of the string with itself at the start of the input file). + */ + s->match_length = longest_match (s, hash_head); + /* longest_match() sets match_start */ + } + if (s->match_length >= MIN_MATCH) { + check_match(s, s->strstart, s->match_start, s->match_length); + + _tr_tally_dist(s, s->strstart - s->match_start, + s->match_length - MIN_MATCH, bflush); + + s->lookahead -= s->match_length; + + /* Insert new strings in the hash table only if the match length + * is not too large. This saves time but degrades compression. + */ +#ifndef FASTEST + if (s->match_length <= s->max_insert_length && + s->lookahead >= MIN_MATCH) { + s->match_length--; /* string at strstart already in table */ + do { + s->strstart++; + INSERT_STRING(s, s->strstart, hash_head); + /* strstart never exceeds WSIZE-MAX_MATCH, so there are + * always MIN_MATCH bytes ahead. + */ + } while (--s->match_length != 0); + s->strstart++; + } else +#endif + { + s->strstart += s->match_length; + s->match_length = 0; + s->ins_h = s->window[s->strstart]; + UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]); +#if MIN_MATCH != 3 + Call UPDATE_HASH() MIN_MATCH-3 more times +#endif + /* If lookahead < MIN_MATCH, ins_h is garbage, but it does not + * matter since it will be recomputed at next deflate call. + */ + } + } else { + /* No match, output a literal byte */ + Tracevv((stderr,"%c", s->window[s->strstart])); + _tr_tally_lit (s, s->window[s->strstart], bflush); + s->lookahead--; + s->strstart++; + } + if (bflush) FLUSH_BLOCK(s, 0); + } + s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1; + if (flush == Z_FINISH) { + FLUSH_BLOCK(s, 1); + return finish_done; + } + if (s->last_lit) + FLUSH_BLOCK(s, 0); + return block_done; +} + +#ifndef FASTEST +/* =========================================================================== + * Same as above, but achieves better compression. We use a lazy + * evaluation for matches: a match is finally adopted only if there is + * no better match at the next window position. + */ +local block_state deflate_slow(s, flush) + deflate_state *s; + int flush; +{ + IPos hash_head; /* head of hash chain */ + int bflush; /* set if current block must be flushed */ + + /* Process the input block. */ + for (;;) { + /* Make sure that we always have enough lookahead, except + * at the end of the input file. We need MAX_MATCH bytes + * for the next match, plus MIN_MATCH bytes to insert the + * string following the next match. + */ + if (s->lookahead < MIN_LOOKAHEAD) { + fill_window(s); + if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) { + return need_more; + } + if (s->lookahead == 0) break; /* flush the current block */ + } + + /* Insert the string window[strstart .. strstart+2] in the + * dictionary, and set hash_head to the head of the hash chain: + */ + hash_head = NIL; + if (s->lookahead >= MIN_MATCH) { + INSERT_STRING(s, s->strstart, hash_head); + } + + /* Find the longest match, discarding those <= prev_length. + */ + s->prev_length = s->match_length, s->prev_match = s->match_start; + s->match_length = MIN_MATCH-1; + + if (hash_head != NIL && s->prev_length < s->max_lazy_match && + s->strstart - hash_head <= MAX_DIST(s)) { + /* To simplify the code, we prevent matches with the string + * of window index 0 (in particular we have to avoid a match + * of the string with itself at the start of the input file). + */ + s->match_length = longest_match (s, hash_head); + /* longest_match() sets match_start */ + + if (s->match_length <= 5 && (s->strategy == Z_FILTERED +#if TOO_FAR <= 32767 + || (s->match_length == MIN_MATCH && + s->strstart - s->match_start > TOO_FAR) +#endif + )) { + + /* If prev_match is also MIN_MATCH, match_start is garbage + * but we will ignore the current match anyway. + */ + s->match_length = MIN_MATCH-1; + } + } + /* If there was a match at the previous step and the current + * match is not better, output the previous match: + */ + if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) { + uInt max_insert = s->strstart + s->lookahead - MIN_MATCH; + /* Do not insert strings in hash table beyond this. */ + + check_match(s, s->strstart-1, s->prev_match, s->prev_length); + + _tr_tally_dist(s, s->strstart -1 - s->prev_match, + s->prev_length - MIN_MATCH, bflush); + + /* Insert in hash table all strings up to the end of the match. + * strstart-1 and strstart are already inserted. If there is not + * enough lookahead, the last two strings are not inserted in + * the hash table. + */ + s->lookahead -= s->prev_length-1; + s->prev_length -= 2; + do { + if (++s->strstart <= max_insert) { + INSERT_STRING(s, s->strstart, hash_head); + } + } while (--s->prev_length != 0); + s->match_available = 0; + s->match_length = MIN_MATCH-1; + s->strstart++; + + if (bflush) FLUSH_BLOCK(s, 0); + + } else if (s->match_available) { + /* If there was no match at the previous position, output a + * single literal. If there was a match but the current match + * is longer, truncate the previous match to a single literal. + */ + Tracevv((stderr,"%c", s->window[s->strstart-1])); + _tr_tally_lit(s, s->window[s->strstart-1], bflush); + if (bflush) { + FLUSH_BLOCK_ONLY(s, 0); + } + s->strstart++; + s->lookahead--; + if (s->strm->avail_out == 0) return need_more; + } else { + /* There is no previous match to compare with, wait for + * the next step to decide. + */ + s->match_available = 1; + s->strstart++; + s->lookahead--; + } + } + Assert (flush != Z_NO_FLUSH, "no flush?"); + if (s->match_available) { + Tracevv((stderr,"%c", s->window[s->strstart-1])); + _tr_tally_lit(s, s->window[s->strstart-1], bflush); + s->match_available = 0; + } + s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1; + if (flush == Z_FINISH) { + FLUSH_BLOCK(s, 1); + return finish_done; + } + if (s->last_lit) + FLUSH_BLOCK(s, 0); + return block_done; +} +#endif /* FASTEST */ + +/* =========================================================================== + * For Z_RLE, simply look for runs of bytes, generate matches only of distance + * one. Do not maintain a hash table. (It will be regenerated if this run of + * deflate switches away from Z_RLE.) + */ +local block_state deflate_rle(s, flush) + deflate_state *s; + int flush; +{ + int bflush; /* set if current block must be flushed */ + uInt prev; /* byte at distance one to match */ + Bytef *scan, *strend; /* scan goes up to strend for length of run */ + + for (;;) { + /* Make sure that we always have enough lookahead, except + * at the end of the input file. We need MAX_MATCH bytes + * for the longest run, plus one for the unrolled loop. + */ + if (s->lookahead <= MAX_MATCH) { + fill_window(s); + if (s->lookahead <= MAX_MATCH && flush == Z_NO_FLUSH) { + return need_more; + } + if (s->lookahead == 0) break; /* flush the current block */ + } + + /* See how many times the previous byte repeats */ + s->match_length = 0; + if (s->lookahead >= MIN_MATCH && s->strstart > 0) { + scan = s->window + s->strstart - 1; + prev = *scan; + if (prev == *++scan && prev == *++scan && prev == *++scan) { + strend = s->window + s->strstart + MAX_MATCH; + do { + } while (prev == *++scan && prev == *++scan && + prev == *++scan && prev == *++scan && + prev == *++scan && prev == *++scan && + prev == *++scan && prev == *++scan && + scan < strend); + s->match_length = MAX_MATCH - (int)(strend - scan); + if (s->match_length > s->lookahead) + s->match_length = s->lookahead; + } + Assert(scan <= s->window+(uInt)(s->window_size-1), "wild scan"); + } + + /* Emit match if have run of MIN_MATCH or longer, else emit literal */ + if (s->match_length >= MIN_MATCH) { + check_match(s, s->strstart, s->strstart - 1, s->match_length); + + _tr_tally_dist(s, 1, s->match_length - MIN_MATCH, bflush); + + s->lookahead -= s->match_length; + s->strstart += s->match_length; + s->match_length = 0; + } else { + /* No match, output a literal byte */ + Tracevv((stderr,"%c", s->window[s->strstart])); + _tr_tally_lit (s, s->window[s->strstart], bflush); + s->lookahead--; + s->strstart++; + } + if (bflush) FLUSH_BLOCK(s, 0); + } + s->insert = 0; + if (flush == Z_FINISH) { + FLUSH_BLOCK(s, 1); + return finish_done; + } + if (s->last_lit) + FLUSH_BLOCK(s, 0); + return block_done; +} + +/* =========================================================================== + * For Z_HUFFMAN_ONLY, do not look for matches. Do not maintain a hash table. + * (It will be regenerated if this run of deflate switches away from Huffman.) + */ +local block_state deflate_huff(s, flush) + deflate_state *s; + int flush; +{ + int bflush; /* set if current block must be flushed */ + + for (;;) { + /* Make sure that we have a literal to write. */ + if (s->lookahead == 0) { + fill_window(s); + if (s->lookahead == 0) { + if (flush == Z_NO_FLUSH) + return need_more; + break; /* flush the current block */ + } + } + + /* Output a literal byte */ + s->match_length = 0; + Tracevv((stderr,"%c", s->window[s->strstart])); + _tr_tally_lit (s, s->window[s->strstart], bflush); + s->lookahead--; + s->strstart++; + if (bflush) FLUSH_BLOCK(s, 0); + } + s->insert = 0; + if (flush == Z_FINISH) { + FLUSH_BLOCK(s, 1); + return finish_done; + } + if (s->last_lit) + FLUSH_BLOCK(s, 0); + return block_done; +} diff --git a/libs/zlib/deflate.h b/libs/zlib/deflate.h new file mode 100644 index 000000000..fbac44d90 --- /dev/null +++ b/libs/zlib/deflate.h @@ -0,0 +1,346 @@ +/* deflate.h -- internal compression state + * Copyright (C) 1995-2012 Jean-loup Gailly + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* WARNING: this file should *not* be used by applications. It is + part of the implementation of the compression library and is + subject to change. Applications should only use zlib.h. + */ + +/* @(#) $Id$ */ + +#ifndef DEFLATE_H +#define DEFLATE_H + +#include "zutil.h" + +/* define NO_GZIP when compiling if you want to disable gzip header and + trailer creation by deflate(). NO_GZIP would be used to avoid linking in + the crc code when it is not needed. For shared libraries, gzip encoding + should be left enabled. */ +#ifndef NO_GZIP +# define GZIP +#endif + +/* =========================================================================== + * Internal compression state. + */ + +#define LENGTH_CODES 29 +/* number of length codes, not counting the special END_BLOCK code */ + +#define LITERALS 256 +/* number of literal bytes 0..255 */ + +#define L_CODES (LITERALS+1+LENGTH_CODES) +/* number of Literal or Length codes, including the END_BLOCK code */ + +#define D_CODES 30 +/* number of distance codes */ + +#define BL_CODES 19 +/* number of codes used to transfer the bit lengths */ + +#define HEAP_SIZE (2*L_CODES+1) +/* maximum heap size */ + +#define MAX_BITS 15 +/* All codes must not exceed MAX_BITS bits */ + +#define Buf_size 16 +/* size of bit buffer in bi_buf */ + +#define INIT_STATE 42 +#define EXTRA_STATE 69 +#define NAME_STATE 73 +#define COMMENT_STATE 91 +#define HCRC_STATE 103 +#define BUSY_STATE 113 +#define FINISH_STATE 666 +/* Stream status */ + + +/* Data structure describing a single value and its code string. */ +typedef struct ct_data_s { + union { + ush freq; /* frequency count */ + ush code; /* bit string */ + } fc; + union { + ush dad; /* father node in Huffman tree */ + ush len; /* length of bit string */ + } dl; +} FAR ct_data; + +#define Freq fc.freq +#define Code fc.code +#define Dad dl.dad +#define Len dl.len + +typedef struct static_tree_desc_s static_tree_desc; + +typedef struct tree_desc_s { + ct_data *dyn_tree; /* the dynamic tree */ + int max_code; /* largest code with non zero frequency */ + static_tree_desc *stat_desc; /* the corresponding static tree */ +} FAR tree_desc; + +typedef ush Pos; +typedef Pos FAR Posf; +typedef unsigned IPos; + +/* A Pos is an index in the character window. We use short instead of int to + * save space in the various tables. IPos is used only for parameter passing. + */ + +typedef struct internal_state { + z_streamp strm; /* pointer back to this zlib stream */ + int status; /* as the name implies */ + Bytef *pending_buf; /* output still pending */ + ulg pending_buf_size; /* size of pending_buf */ + Bytef *pending_out; /* next pending byte to output to the stream */ + uInt pending; /* nb of bytes in the pending buffer */ + int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ + gz_headerp gzhead; /* gzip header information to write */ + uInt gzindex; /* where in extra, name, or comment */ + Byte method; /* STORED (for zip only) or DEFLATED */ + int last_flush; /* value of flush param for previous deflate call */ + + /* used by deflate.c: */ + + uInt w_size; /* LZ77 window size (32K by default) */ + uInt w_bits; /* log2(w_size) (8..16) */ + uInt w_mask; /* w_size - 1 */ + + Bytef *window; + /* Sliding window. Input bytes are read into the second half of the window, + * and move to the first half later to keep a dictionary of at least wSize + * bytes. With this organization, matches are limited to a distance of + * wSize-MAX_MATCH bytes, but this ensures that IO is always + * performed with a length multiple of the block size. Also, it limits + * the window size to 64K, which is quite useful on MSDOS. + * To do: use the user input buffer as sliding window. + */ + + ulg window_size; + /* Actual size of window: 2*wSize, except when the user input buffer + * is directly used as sliding window. + */ + + Posf *prev; + /* Link to older string with same hash index. To limit the size of this + * array to 64K, this link is maintained only for the last 32K strings. + * An index in this array is thus a window index modulo 32K. + */ + + Posf *head; /* Heads of the hash chains or NIL. */ + + uInt ins_h; /* hash index of string to be inserted */ + uInt hash_size; /* number of elements in hash table */ + uInt hash_bits; /* log2(hash_size) */ + uInt hash_mask; /* hash_size-1 */ + + uInt hash_shift; + /* Number of bits by which ins_h must be shifted at each input + * step. It must be such that after MIN_MATCH steps, the oldest + * byte no longer takes part in the hash key, that is: + * hash_shift * MIN_MATCH >= hash_bits + */ + + long block_start; + /* Window position at the beginning of the current output block. Gets + * negative when the window is moved backwards. + */ + + uInt match_length; /* length of best match */ + IPos prev_match; /* previous match */ + int match_available; /* set if previous match exists */ + uInt strstart; /* start of string to insert */ + uInt match_start; /* start of matching string */ + uInt lookahead; /* number of valid bytes ahead in window */ + + uInt prev_length; + /* Length of the best match at previous step. Matches not greater than this + * are discarded. This is used in the lazy match evaluation. + */ + + uInt max_chain_length; + /* To speed up deflation, hash chains are never searched beyond this + * length. A higher limit improves compression ratio but degrades the + * speed. + */ + + uInt max_lazy_match; + /* Attempt to find a better match only when the current match is strictly + * smaller than this value. This mechanism is used only for compression + * levels >= 4. + */ +# define max_insert_length max_lazy_match + /* Insert new strings in the hash table only if the match length is not + * greater than this length. This saves time but degrades compression. + * max_insert_length is used only for compression levels <= 3. + */ + + int level; /* compression level (1..9) */ + int strategy; /* favor or force Huffman coding*/ + + uInt good_match; + /* Use a faster search when the previous match is longer than this */ + + int nice_match; /* Stop searching when current match exceeds this */ + + /* used by trees.c: */ + /* Didn't use ct_data typedef below to suppress compiler warning */ + struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */ + struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */ + struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */ + + struct tree_desc_s l_desc; /* desc. for literal tree */ + struct tree_desc_s d_desc; /* desc. for distance tree */ + struct tree_desc_s bl_desc; /* desc. for bit length tree */ + + ush bl_count[MAX_BITS+1]; + /* number of codes at each bit length for an optimal tree */ + + int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */ + int heap_len; /* number of elements in the heap */ + int heap_max; /* element of largest frequency */ + /* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used. + * The same heap array is used to build all trees. + */ + + uch depth[2*L_CODES+1]; + /* Depth of each subtree used as tie breaker for trees of equal frequency + */ + + uchf *l_buf; /* buffer for literals or lengths */ + + uInt lit_bufsize; + /* Size of match buffer for literals/lengths. There are 4 reasons for + * limiting lit_bufsize to 64K: + * - frequencies can be kept in 16 bit counters + * - if compression is not successful for the first block, all input + * data is still in the window so we can still emit a stored block even + * when input comes from standard input. (This can also be done for + * all blocks if lit_bufsize is not greater than 32K.) + * - if compression is not successful for a file smaller than 64K, we can + * even emit a stored file instead of a stored block (saving 5 bytes). + * This is applicable only for zip (not gzip or zlib). + * - creating new Huffman trees less frequently may not provide fast + * adaptation to changes in the input data statistics. (Take for + * example a binary file with poorly compressible code followed by + * a highly compressible string table.) Smaller buffer sizes give + * fast adaptation but have of course the overhead of transmitting + * trees more frequently. + * - I can't count above 4 + */ + + uInt last_lit; /* running index in l_buf */ + + ushf *d_buf; + /* Buffer for distances. To simplify the code, d_buf and l_buf have + * the same number of elements. To use different lengths, an extra flag + * array would be necessary. + */ + + ulg opt_len; /* bit length of current block with optimal trees */ + ulg static_len; /* bit length of current block with static trees */ + uInt matches; /* number of string matches in current block */ + uInt insert; /* bytes at end of window left to insert */ + +#ifdef DEBUG + ulg compressed_len; /* total bit length of compressed file mod 2^32 */ + ulg bits_sent; /* bit length of compressed data sent mod 2^32 */ +#endif + + ush bi_buf; + /* Output buffer. bits are inserted starting at the bottom (least + * significant bits). + */ + int bi_valid; + /* Number of valid bits in bi_buf. All bits above the last valid bit + * are always zero. + */ + + ulg high_water; + /* High water mark offset in window for initialized bytes -- bytes above + * this are set to zero in order to avoid memory check warnings when + * longest match routines access bytes past the input. This is then + * updated to the new high water mark. + */ + +} FAR deflate_state; + +/* Output a byte on the stream. + * IN assertion: there is enough room in pending_buf. + */ +#define put_byte(s, c) {s->pending_buf[s->pending++] = (c);} + + +#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1) +/* Minimum amount of lookahead, except at the end of the input file. + * See deflate.c for comments about the MIN_MATCH+1. + */ + +#define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD) +/* In order to simplify the code, particularly on 16 bit machines, match + * distances are limited to MAX_DIST instead of WSIZE. + */ + +#define WIN_INIT MAX_MATCH +/* Number of bytes after end of data in window to initialize in order to avoid + memory checker errors from longest match routines */ + + /* in trees.c */ +void ZLIB_INTERNAL _tr_init OF((deflate_state *s)); +int ZLIB_INTERNAL _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc)); +void ZLIB_INTERNAL _tr_flush_block OF((deflate_state *s, charf *buf, + ulg stored_len, int last)); +void ZLIB_INTERNAL _tr_flush_bits OF((deflate_state *s)); +void ZLIB_INTERNAL _tr_align OF((deflate_state *s)); +void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf, + ulg stored_len, int last)); + +#define d_code(dist) \ + ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)]) +/* Mapping from a distance to a distance code. dist is the distance - 1 and + * must not have side effects. _dist_code[256] and _dist_code[257] are never + * used. + */ + +#ifndef DEBUG +/* Inline versions of _tr_tally for speed: */ + +#if defined(GEN_TREES_H) || !defined(STDC) + extern uch ZLIB_INTERNAL _length_code[]; + extern uch ZLIB_INTERNAL _dist_code[]; +#else + extern const uch ZLIB_INTERNAL _length_code[]; + extern const uch ZLIB_INTERNAL _dist_code[]; +#endif + +# define _tr_tally_lit(s, c, flush) \ + { uch cc = (c); \ + s->d_buf[s->last_lit] = 0; \ + s->l_buf[s->last_lit++] = cc; \ + s->dyn_ltree[cc].Freq++; \ + flush = (s->last_lit == s->lit_bufsize-1); \ + } +# define _tr_tally_dist(s, distance, length, flush) \ + { uch len = (length); \ + ush dist = (distance); \ + s->d_buf[s->last_lit] = dist; \ + s->l_buf[s->last_lit++] = len; \ + dist--; \ + s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \ + s->dyn_dtree[d_code(dist)].Freq++; \ + flush = (s->last_lit == s->lit_bufsize-1); \ + } +#else +# define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c) +# define _tr_tally_dist(s, distance, length, flush) \ + flush = _tr_tally(s, distance, length) +#endif + +#endif /* DEFLATE_H */ diff --git a/libs/zlib/doc/algorithm.txt b/libs/zlib/doc/algorithm.txt new file mode 100644 index 000000000..34960bdda --- /dev/null +++ b/libs/zlib/doc/algorithm.txt @@ -0,0 +1,209 @@ +1. Compression algorithm (deflate) + +The deflation algorithm used by gzip (also zip and zlib) is a variation of +LZ77 (Lempel-Ziv 1977, see reference below). It finds duplicated strings in +the input data. The second occurrence of a string is replaced by a +pointer to the previous string, in the form of a pair (distance, +length). Distances are limited to 32K bytes, and lengths are limited +to 258 bytes. When a string does not occur anywhere in the previous +32K bytes, it is emitted as a sequence of literal bytes. (In this +description, `string' must be taken as an arbitrary sequence of bytes, +and is not restricted to printable characters.) + +Literals or match lengths are compressed with one Huffman tree, and +match distances are compressed with another tree. The trees are stored +in a compact form at the start of each block. The blocks can have any +size (except that the compressed data for one block must fit in +available memory). A block is terminated when deflate() determines that +it would be useful to start another block with fresh trees. (This is +somewhat similar to the behavior of LZW-based _compress_.) + +Duplicated strings are found using a hash table. All input strings of +length 3 are inserted in the hash table. A hash index is computed for +the next 3 bytes. If the hash chain for this index is not empty, all +strings in the chain are compared with the current input string, and +the longest match is selected. + +The hash chains are searched starting with the most recent strings, to +favor small distances and thus take advantage of the Huffman encoding. +The hash chains are singly linked. There are no deletions from the +hash chains, the algorithm simply discards matches that are too old. + +To avoid a worst-case situation, very long hash chains are arbitrarily +truncated at a certain length, determined by a runtime option (level +parameter of deflateInit). So deflate() does not always find the longest +possible match but generally finds a match which is long enough. + +deflate() also defers the selection of matches with a lazy evaluation +mechanism. After a match of length N has been found, deflate() searches for +a longer match at the next input byte. If a longer match is found, the +previous match is truncated to a length of one (thus producing a single +literal byte) and the process of lazy evaluation begins again. Otherwise, +the original match is kept, and the next match search is attempted only N +steps later. + +The lazy match evaluation is also subject to a runtime parameter. If +the current match is long enough, deflate() reduces the search for a longer +match, thus speeding up the whole process. If compression ratio is more +important than speed, deflate() attempts a complete second search even if +the first match is already long enough. + +The lazy match evaluation is not performed for the fastest compression +modes (level parameter 1 to 3). For these fast modes, new strings +are inserted in the hash table only when no match was found, or +when the match is not too long. This degrades the compression ratio +but saves time since there are both fewer insertions and fewer searches. + + +2. Decompression algorithm (inflate) + +2.1 Introduction + +The key question is how to represent a Huffman code (or any prefix code) so +that you can decode fast. The most important characteristic is that shorter +codes are much more common than longer codes, so pay attention to decoding the +short codes fast, and let the long codes take longer to decode. + +inflate() sets up a first level table that covers some number of bits of +input less than the length of longest code. It gets that many bits from the +stream, and looks it up in the table. The table will tell if the next +code is that many bits or less and how many, and if it is, it will tell +the value, else it will point to the next level table for which inflate() +grabs more bits and tries to decode a longer code. + +How many bits to make the first lookup is a tradeoff between the time it +takes to decode and the time it takes to build the table. If building the +table took no time (and if you had infinite memory), then there would only +be a first level table to cover all the way to the longest code. However, +building the table ends up taking a lot longer for more bits since short +codes are replicated many times in such a table. What inflate() does is +simply to make the number of bits in the first table a variable, and then +to set that variable for the maximum speed. + +For inflate, which has 286 possible codes for the literal/length tree, the size +of the first table is nine bits. Also the distance trees have 30 possible +values, and the size of the first table is six bits. Note that for each of +those cases, the table ended up one bit longer than the ``average'' code +length, i.e. the code length of an approximately flat code which would be a +little more than eight bits for 286 symbols and a little less than five bits +for 30 symbols. + + +2.2 More details on the inflate table lookup + +Ok, you want to know what this cleverly obfuscated inflate tree actually +looks like. You are correct that it's not a Huffman tree. It is simply a +lookup table for the first, let's say, nine bits of a Huffman symbol. The +symbol could be as short as one bit or as long as 15 bits. If a particular +symbol is shorter than nine bits, then that symbol's translation is duplicated +in all those entries that start with that symbol's bits. For example, if the +symbol is four bits, then it's duplicated 32 times in a nine-bit table. If a +symbol is nine bits long, it appears in the table once. + +If the symbol is longer than nine bits, then that entry in the table points +to another similar table for the remaining bits. Again, there are duplicated +entries as needed. The idea is that most of the time the symbol will be short +and there will only be one table look up. (That's whole idea behind data +compression in the first place.) For the less frequent long symbols, there +will be two lookups. If you had a compression method with really long +symbols, you could have as many levels of lookups as is efficient. For +inflate, two is enough. + +So a table entry either points to another table (in which case nine bits in +the above example are gobbled), or it contains the translation for the symbol +and the number of bits to gobble. Then you start again with the next +ungobbled bit. + +You may wonder: why not just have one lookup table for how ever many bits the +longest symbol is? The reason is that if you do that, you end up spending +more time filling in duplicate symbol entries than you do actually decoding. +At least for deflate's output that generates new trees every several 10's of +kbytes. You can imagine that filling in a 2^15 entry table for a 15-bit code +would take too long if you're only decoding several thousand symbols. At the +other extreme, you could make a new table for every bit in the code. In fact, +that's essentially a Huffman tree. But then you spend too much time +traversing the tree while decoding, even for short symbols. + +So the number of bits for the first lookup table is a trade of the time to +fill out the table vs. the time spent looking at the second level and above of +the table. + +Here is an example, scaled down: + +The code being decoded, with 10 symbols, from 1 to 6 bits long: + +A: 0 +B: 10 +C: 1100 +D: 11010 +E: 11011 +F: 11100 +G: 11101 +H: 11110 +I: 111110 +J: 111111 + +Let's make the first table three bits long (eight entries): + +000: A,1 +001: A,1 +010: A,1 +011: A,1 +100: B,2 +101: B,2 +110: -> table X (gobble 3 bits) +111: -> table Y (gobble 3 bits) + +Each entry is what the bits decode as and how many bits that is, i.e. how +many bits to gobble. Or the entry points to another table, with the number of +bits to gobble implicit in the size of the table. + +Table X is two bits long since the longest code starting with 110 is five bits +long: + +00: C,1 +01: C,1 +10: D,2 +11: E,2 + +Table Y is three bits long since the longest code starting with 111 is six +bits long: + +000: F,2 +001: F,2 +010: G,2 +011: G,2 +100: H,2 +101: H,2 +110: I,3 +111: J,3 + +So what we have here are three tables with a total of 20 entries that had to +be constructed. That's compared to 64 entries for a single table. Or +compared to 16 entries for a Huffman tree (six two entry tables and one four +entry table). Assuming that the code ideally represents the probability of +the symbols, it takes on the average 1.25 lookups per symbol. That's compared +to one lookup for the single table, or 1.66 lookups per symbol for the +Huffman tree. + +There, I think that gives you a picture of what's going on. For inflate, the +meaning of a particular symbol is often more than just a letter. It can be a +byte (a "literal"), or it can be either a length or a distance which +indicates a base value and a number of bits to fetch after the code that is +added to the base value. Or it might be the special end-of-block code. The +data structures created in inftrees.c try to encode all that information +compactly in the tables. + + +Jean-loup Gailly Mark Adler +jloup@gzip.org madler@alumni.caltech.edu + + +References: + +[LZ77] Ziv J., Lempel A., ``A Universal Algorithm for Sequential Data +Compression,'' IEEE Transactions on Information Theory, Vol. 23, No. 3, +pp. 337-343. + +``DEFLATE Compressed Data Format Specification'' available in +http://www.ietf.org/rfc/rfc1951.txt diff --git a/libs/zlib/doc/rfc1950.txt b/libs/zlib/doc/rfc1950.txt new file mode 100644 index 000000000..ce6428a0f --- /dev/null +++ b/libs/zlib/doc/rfc1950.txt @@ -0,0 +1,619 @@ + + + + + + +Network Working Group P. Deutsch +Request for Comments: 1950 Aladdin Enterprises +Category: Informational J-L. Gailly + Info-ZIP + May 1996 + + + ZLIB Compressed Data Format Specification version 3.3 + +Status of This Memo + + This memo provides information for the Internet community. This memo + does not specify an Internet standard of any kind. Distribution of + this memo is unlimited. + +IESG Note: + + The IESG takes no position on the validity of any Intellectual + Property Rights statements contained in this document. + +Notices + + Copyright (c) 1996 L. Peter Deutsch and Jean-Loup Gailly + + Permission is granted to copy and distribute this document for any + purpose and without charge, including translations into other + languages and incorporation into compilations, provided that the + copyright notice and this notice are preserved, and that any + substantive changes or deletions from the original are clearly + marked. + + A pointer to the latest version of this and related documentation in + HTML format can be found at the URL + . + +Abstract + + This specification defines a lossless compressed data format. The + data can be produced or consumed, even for an arbitrarily long + sequentially presented input data stream, using only an a priori + bounded amount of intermediate storage. The format presently uses + the DEFLATE compression method but can be easily extended to use + other compression methods. It can be implemented readily in a manner + not covered by patents. This specification also defines the ADLER-32 + checksum (an extension and improvement of the Fletcher checksum), + used for detection of data corruption, and provides an algorithm for + computing it. + + + + +Deutsch & Gailly Informational [Page 1] + +RFC 1950 ZLIB Compressed Data Format Specification May 1996 + + +Table of Contents + + 1. Introduction ................................................... 2 + 1.1. Purpose ................................................... 2 + 1.2. Intended audience ......................................... 3 + 1.3. Scope ..................................................... 3 + 1.4. Compliance ................................................ 3 + 1.5. Definitions of terms and conventions used ................ 3 + 1.6. Changes from previous versions ............................ 3 + 2. Detailed specification ......................................... 3 + 2.1. Overall conventions ....................................... 3 + 2.2. Data format ............................................... 4 + 2.3. Compliance ................................................ 7 + 3. References ..................................................... 7 + 4. Source code .................................................... 8 + 5. Security Considerations ........................................ 8 + 6. Acknowledgements ............................................... 8 + 7. Authors' Addresses ............................................. 8 + 8. Appendix: Rationale ............................................ 9 + 9. Appendix: Sample code ..........................................10 + +1. Introduction + + 1.1. Purpose + + The purpose of this specification is to define a lossless + compressed data format that: + + * Is independent of CPU type, operating system, file system, + and character set, and hence can be used for interchange; + + * Can be produced or consumed, even for an arbitrarily long + sequentially presented input data stream, using only an a + priori bounded amount of intermediate storage, and hence can + be used in data communications or similar structures such as + Unix filters; + + * Can use a number of different compression methods; + + * Can be implemented readily in a manner not covered by + patents, and hence can be practiced freely. + + The data format defined by this specification does not attempt to + allow random access to compressed data. + + + + + + + +Deutsch & Gailly Informational [Page 2] + +RFC 1950 ZLIB Compressed Data Format Specification May 1996 + + + 1.2. Intended audience + + This specification is intended for use by implementors of software + to compress data into zlib format and/or decompress data from zlib + format. + + The text of the specification assumes a basic background in + programming at the level of bits and other primitive data + representations. + + 1.3. Scope + + The specification specifies a compressed data format that can be + used for in-memory compression of a sequence of arbitrary bytes. + + 1.4. Compliance + + Unless otherwise indicated below, a compliant decompressor must be + able to accept and decompress any data set that conforms to all + the specifications presented here; a compliant compressor must + produce data sets that conform to all the specifications presented + here. + + 1.5. Definitions of terms and conventions used + + byte: 8 bits stored or transmitted as a unit (same as an octet). + (For this specification, a byte is exactly 8 bits, even on + machines which store a character on a number of bits different + from 8.) See below, for the numbering of bits within a byte. + + 1.6. Changes from previous versions + + Version 3.1 was the first public release of this specification. + In version 3.2, some terminology was changed and the Adler-32 + sample code was rewritten for clarity. In version 3.3, the + support for a preset dictionary was introduced, and the + specification was converted to RFC style. + +2. Detailed specification + + 2.1. Overall conventions + + In the diagrams below, a box like this: + + +---+ + | | <-- the vertical bars might be missing + +---+ + + + + +Deutsch & Gailly Informational [Page 3] + +RFC 1950 ZLIB Compressed Data Format Specification May 1996 + + + represents one byte; a box like this: + + +==============+ + | | + +==============+ + + represents a variable number of bytes. + + Bytes stored within a computer do not have a "bit order", since + they are always treated as a unit. However, a byte considered as + an integer between 0 and 255 does have a most- and least- + significant bit, and since we write numbers with the most- + significant digit on the left, we also write bytes with the most- + significant bit on the left. In the diagrams below, we number the + bits of a byte so that bit 0 is the least-significant bit, i.e., + the bits are numbered: + + +--------+ + |76543210| + +--------+ + + Within a computer, a number may occupy multiple bytes. All + multi-byte numbers in the format described here are stored with + the MOST-significant byte first (at the lower memory address). + For example, the decimal number 520 is stored as: + + 0 1 + +--------+--------+ + |00000010|00001000| + +--------+--------+ + ^ ^ + | | + | + less significant byte = 8 + + more significant byte = 2 x 256 + + 2.2. Data format + + A zlib stream has the following structure: + + 0 1 + +---+---+ + |CMF|FLG| (more-->) + +---+---+ + + + + + + + + +Deutsch & Gailly Informational [Page 4] + +RFC 1950 ZLIB Compressed Data Format Specification May 1996 + + + (if FLG.FDICT set) + + 0 1 2 3 + +---+---+---+---+ + | DICTID | (more-->) + +---+---+---+---+ + + +=====================+---+---+---+---+ + |...compressed data...| ADLER32 | + +=====================+---+---+---+---+ + + Any data which may appear after ADLER32 are not part of the zlib + stream. + + CMF (Compression Method and flags) + This byte is divided into a 4-bit compression method and a 4- + bit information field depending on the compression method. + + bits 0 to 3 CM Compression method + bits 4 to 7 CINFO Compression info + + CM (Compression method) + This identifies the compression method used in the file. CM = 8 + denotes the "deflate" compression method with a window size up + to 32K. This is the method used by gzip and PNG (see + references [1] and [2] in Chapter 3, below, for the reference + documents). CM = 15 is reserved. It might be used in a future + version of this specification to indicate the presence of an + extra field before the compressed data. + + CINFO (Compression info) + For CM = 8, CINFO is the base-2 logarithm of the LZ77 window + size, minus eight (CINFO=7 indicates a 32K window size). Values + of CINFO above 7 are not allowed in this version of the + specification. CINFO is not defined in this specification for + CM not equal to 8. + + FLG (FLaGs) + This flag byte is divided as follows: + + bits 0 to 4 FCHECK (check bits for CMF and FLG) + bit 5 FDICT (preset dictionary) + bits 6 to 7 FLEVEL (compression level) + + The FCHECK value must be such that CMF and FLG, when viewed as + a 16-bit unsigned integer stored in MSB order (CMF*256 + FLG), + is a multiple of 31. + + + + +Deutsch & Gailly Informational [Page 5] + +RFC 1950 ZLIB Compressed Data Format Specification May 1996 + + + FDICT (Preset dictionary) + If FDICT is set, a DICT dictionary identifier is present + immediately after the FLG byte. The dictionary is a sequence of + bytes which are initially fed to the compressor without + producing any compressed output. DICT is the Adler-32 checksum + of this sequence of bytes (see the definition of ADLER32 + below). The decompressor can use this identifier to determine + which dictionary has been used by the compressor. + + FLEVEL (Compression level) + These flags are available for use by specific compression + methods. The "deflate" method (CM = 8) sets these flags as + follows: + + 0 - compressor used fastest algorithm + 1 - compressor used fast algorithm + 2 - compressor used default algorithm + 3 - compressor used maximum compression, slowest algorithm + + The information in FLEVEL is not needed for decompression; it + is there to indicate if recompression might be worthwhile. + + compressed data + For compression method 8, the compressed data is stored in the + deflate compressed data format as described in the document + "DEFLATE Compressed Data Format Specification" by L. Peter + Deutsch. (See reference [3] in Chapter 3, below) + + Other compressed data formats are not specified in this version + of the zlib specification. + + ADLER32 (Adler-32 checksum) + This contains a checksum value of the uncompressed data + (excluding any dictionary data) computed according to Adler-32 + algorithm. This algorithm is a 32-bit extension and improvement + of the Fletcher algorithm, used in the ITU-T X.224 / ISO 8073 + standard. See references [4] and [5] in Chapter 3, below) + + Adler-32 is composed of two sums accumulated per byte: s1 is + the sum of all bytes, s2 is the sum of all s1 values. Both sums + are done modulo 65521. s1 is initialized to 1, s2 to zero. The + Adler-32 checksum is stored as s2*65536 + s1 in most- + significant-byte first (network) order. + + + + + + + + +Deutsch & Gailly Informational [Page 6] + +RFC 1950 ZLIB Compressed Data Format Specification May 1996 + + + 2.3. Compliance + + A compliant compressor must produce streams with correct CMF, FLG + and ADLER32, but need not support preset dictionaries. When the + zlib data format is used as part of another standard data format, + the compressor may use only preset dictionaries that are specified + by this other data format. If this other format does not use the + preset dictionary feature, the compressor must not set the FDICT + flag. + + A compliant decompressor must check CMF, FLG, and ADLER32, and + provide an error indication if any of these have incorrect values. + A compliant decompressor must give an error indication if CM is + not one of the values defined in this specification (only the + value 8 is permitted in this version), since another value could + indicate the presence of new features that would cause subsequent + data to be interpreted incorrectly. A compliant decompressor must + give an error indication if FDICT is set and DICTID is not the + identifier of a known preset dictionary. A decompressor may + ignore FLEVEL and still be compliant. When the zlib data format + is being used as a part of another standard format, a compliant + decompressor must support all the preset dictionaries specified by + the other format. When the other format does not use the preset + dictionary feature, a compliant decompressor must reject any + stream in which the FDICT flag is set. + +3. References + + [1] Deutsch, L.P.,"GZIP Compressed Data Format Specification", + available in ftp://ftp.uu.net/pub/archiving/zip/doc/ + + [2] Thomas Boutell, "PNG (Portable Network Graphics) specification", + available in ftp://ftp.uu.net/graphics/png/documents/ + + [3] Deutsch, L.P.,"DEFLATE Compressed Data Format Specification", + available in ftp://ftp.uu.net/pub/archiving/zip/doc/ + + [4] Fletcher, J. G., "An Arithmetic Checksum for Serial + Transmissions," IEEE Transactions on Communications, Vol. COM-30, + No. 1, January 1982, pp. 247-252. + + [5] ITU-T Recommendation X.224, Annex D, "Checksum Algorithms," + November, 1993, pp. 144, 145. (Available from + gopher://info.itu.ch). ITU-T X.244 is also the same as ISO 8073. + + + + + + + +Deutsch & Gailly Informational [Page 7] + +RFC 1950 ZLIB Compressed Data Format Specification May 1996 + + +4. Source code + + Source code for a C language implementation of a "zlib" compliant + library is available at ftp://ftp.uu.net/pub/archiving/zip/zlib/. + +5. Security Considerations + + A decoder that fails to check the ADLER32 checksum value may be + subject to undetected data corruption. + +6. Acknowledgements + + Trademarks cited in this document are the property of their + respective owners. + + Jean-Loup Gailly and Mark Adler designed the zlib format and wrote + the related software described in this specification. Glenn + Randers-Pehrson converted this document to RFC and HTML format. + +7. Authors' Addresses + + L. Peter Deutsch + Aladdin Enterprises + 203 Santa Margarita Ave. + Menlo Park, CA 94025 + + Phone: (415) 322-0103 (AM only) + FAX: (415) 322-1734 + EMail: + + + Jean-Loup Gailly + + EMail: + + Questions about the technical content of this specification can be + sent by email to + + Jean-Loup Gailly and + Mark Adler + + Editorial comments on this specification can be sent by email to + + L. Peter Deutsch and + Glenn Randers-Pehrson + + + + + + +Deutsch & Gailly Informational [Page 8] + +RFC 1950 ZLIB Compressed Data Format Specification May 1996 + + +8. Appendix: Rationale + + 8.1. Preset dictionaries + + A preset dictionary is specially useful to compress short input + sequences. The compressor can take advantage of the dictionary + context to encode the input in a more compact manner. The + decompressor can be initialized with the appropriate context by + virtually decompressing a compressed version of the dictionary + without producing any output. However for certain compression + algorithms such as the deflate algorithm this operation can be + achieved without actually performing any decompression. + + The compressor and the decompressor must use exactly the same + dictionary. The dictionary may be fixed or may be chosen among a + certain number of predefined dictionaries, according to the kind + of input data. The decompressor can determine which dictionary has + been chosen by the compressor by checking the dictionary + identifier. This document does not specify the contents of + predefined dictionaries, since the optimal dictionaries are + application specific. Standard data formats using this feature of + the zlib specification must precisely define the allowed + dictionaries. + + 8.2. The Adler-32 algorithm + + The Adler-32 algorithm is much faster than the CRC32 algorithm yet + still provides an extremely low probability of undetected errors. + + The modulo on unsigned long accumulators can be delayed for 5552 + bytes, so the modulo operation time is negligible. If the bytes + are a, b, c, the second sum is 3a + 2b + c + 3, and so is position + and order sensitive, unlike the first sum, which is just a + checksum. That 65521 is prime is important to avoid a possible + large class of two-byte errors that leave the check unchanged. + (The Fletcher checksum uses 255, which is not prime and which also + makes the Fletcher check insensitive to single byte changes 0 <-> + 255.) + + The sum s1 is initialized to 1 instead of zero to make the length + of the sequence part of s2, so that the length does not have to be + checked separately. (Any sequence of zeroes has a Fletcher + checksum of zero.) + + + + + + + + +Deutsch & Gailly Informational [Page 9] + +RFC 1950 ZLIB Compressed Data Format Specification May 1996 + + +9. Appendix: Sample code + + The following C code computes the Adler-32 checksum of a data buffer. + It is written for clarity, not for speed. The sample code is in the + ANSI C programming language. Non C users may find it easier to read + with these hints: + + & Bitwise AND operator. + >> Bitwise right shift operator. When applied to an + unsigned quantity, as here, right shift inserts zero bit(s) + at the left. + << Bitwise left shift operator. Left shift inserts zero + bit(s) at the right. + ++ "n++" increments the variable n. + % modulo operator: a % b is the remainder of a divided by b. + + #define BASE 65521 /* largest prime smaller than 65536 */ + + /* + Update a running Adler-32 checksum with the bytes buf[0..len-1] + and return the updated checksum. The Adler-32 checksum should be + initialized to 1. + + Usage example: + + unsigned long adler = 1L; + + while (read_buffer(buffer, length) != EOF) { + adler = update_adler32(adler, buffer, length); + } + if (adler != original_adler) error(); + */ + unsigned long update_adler32(unsigned long adler, + unsigned char *buf, int len) + { + unsigned long s1 = adler & 0xffff; + unsigned long s2 = (adler >> 16) & 0xffff; + int n; + + for (n = 0; n < len; n++) { + s1 = (s1 + buf[n]) % BASE; + s2 = (s2 + s1) % BASE; + } + return (s2 << 16) + s1; + } + + /* Return the adler32 of the bytes buf[0..len-1] */ + + + + +Deutsch & Gailly Informational [Page 10] + +RFC 1950 ZLIB Compressed Data Format Specification May 1996 + + + unsigned long adler32(unsigned char *buf, int len) + { + return update_adler32(1L, buf, len); + } + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Deutsch & Gailly Informational [Page 11] + diff --git a/libs/zlib/doc/rfc1951.txt b/libs/zlib/doc/rfc1951.txt new file mode 100644 index 000000000..403c8c722 --- /dev/null +++ b/libs/zlib/doc/rfc1951.txt @@ -0,0 +1,955 @@ + + + + + + +Network Working Group P. Deutsch +Request for Comments: 1951 Aladdin Enterprises +Category: Informational May 1996 + + + DEFLATE Compressed Data Format Specification version 1.3 + +Status of This Memo + + This memo provides information for the Internet community. This memo + does not specify an Internet standard of any kind. Distribution of + this memo is unlimited. + +IESG Note: + + The IESG takes no position on the validity of any Intellectual + Property Rights statements contained in this document. + +Notices + + Copyright (c) 1996 L. Peter Deutsch + + Permission is granted to copy and distribute this document for any + purpose and without charge, including translations into other + languages and incorporation into compilations, provided that the + copyright notice and this notice are preserved, and that any + substantive changes or deletions from the original are clearly + marked. + + A pointer to the latest version of this and related documentation in + HTML format can be found at the URL + . + +Abstract + + This specification defines a lossless compressed data format that + compresses data using a combination of the LZ77 algorithm and Huffman + coding, with efficiency comparable to the best currently available + general-purpose compression methods. The data can be produced or + consumed, even for an arbitrarily long sequentially presented input + data stream, using only an a priori bounded amount of intermediate + storage. The format can be implemented readily in a manner not + covered by patents. + + + + + + + + +Deutsch Informational [Page 1] + +RFC 1951 DEFLATE Compressed Data Format Specification May 1996 + + +Table of Contents + + 1. Introduction ................................................... 2 + 1.1. Purpose ................................................... 2 + 1.2. Intended audience ......................................... 3 + 1.3. Scope ..................................................... 3 + 1.4. Compliance ................................................ 3 + 1.5. Definitions of terms and conventions used ................ 3 + 1.6. Changes from previous versions ............................ 4 + 2. Compressed representation overview ............................. 4 + 3. Detailed specification ......................................... 5 + 3.1. Overall conventions ....................................... 5 + 3.1.1. Packing into bytes .................................. 5 + 3.2. Compressed block format ................................... 6 + 3.2.1. Synopsis of prefix and Huffman coding ............... 6 + 3.2.2. Use of Huffman coding in the "deflate" format ....... 7 + 3.2.3. Details of block format ............................. 9 + 3.2.4. Non-compressed blocks (BTYPE=00) ................... 11 + 3.2.5. Compressed blocks (length and distance codes) ...... 11 + 3.2.6. Compression with fixed Huffman codes (BTYPE=01) .... 12 + 3.2.7. Compression with dynamic Huffman codes (BTYPE=10) .. 13 + 3.3. Compliance ............................................... 14 + 4. Compression algorithm details ................................. 14 + 5. References .................................................... 16 + 6. Security Considerations ....................................... 16 + 7. Source code ................................................... 16 + 8. Acknowledgements .............................................. 16 + 9. Author's Address .............................................. 17 + +1. Introduction + + 1.1. Purpose + + The purpose of this specification is to define a lossless + compressed data format that: + * Is independent of CPU type, operating system, file system, + and character set, and hence can be used for interchange; + * Can be produced or consumed, even for an arbitrarily long + sequentially presented input data stream, using only an a + priori bounded amount of intermediate storage, and hence + can be used in data communications or similar structures + such as Unix filters; + * Compresses data with efficiency comparable to the best + currently available general-purpose compression methods, + and in particular considerably better than the "compress" + program; + * Can be implemented readily in a manner not covered by + patents, and hence can be practiced freely; + + + +Deutsch Informational [Page 2] + +RFC 1951 DEFLATE Compressed Data Format Specification May 1996 + + + * Is compatible with the file format produced by the current + widely used gzip utility, in that conforming decompressors + will be able to read data produced by the existing gzip + compressor. + + The data format defined by this specification does not attempt to: + + * Allow random access to compressed data; + * Compress specialized data (e.g., raster graphics) as well + as the best currently available specialized algorithms. + + A simple counting argument shows that no lossless compression + algorithm can compress every possible input data set. For the + format defined here, the worst case expansion is 5 bytes per 32K- + byte block, i.e., a size increase of 0.015% for large data sets. + English text usually compresses by a factor of 2.5 to 3; + executable files usually compress somewhat less; graphical data + such as raster images may compress much more. + + 1.2. Intended audience + + This specification is intended for use by implementors of software + to compress data into "deflate" format and/or decompress data from + "deflate" format. + + The text of the specification assumes a basic background in + programming at the level of bits and other primitive data + representations. Familiarity with the technique of Huffman coding + is helpful but not required. + + 1.3. Scope + + The specification specifies a method for representing a sequence + of bytes as a (usually shorter) sequence of bits, and a method for + packing the latter bit sequence into bytes. + + 1.4. Compliance + + Unless otherwise indicated below, a compliant decompressor must be + able to accept and decompress any data set that conforms to all + the specifications presented here; a compliant compressor must + produce data sets that conform to all the specifications presented + here. + + 1.5. Definitions of terms and conventions used + + Byte: 8 bits stored or transmitted as a unit (same as an octet). + For this specification, a byte is exactly 8 bits, even on machines + + + +Deutsch Informational [Page 3] + +RFC 1951 DEFLATE Compressed Data Format Specification May 1996 + + + which store a character on a number of bits different from eight. + See below, for the numbering of bits within a byte. + + String: a sequence of arbitrary bytes. + + 1.6. Changes from previous versions + + There have been no technical changes to the deflate format since + version 1.1 of this specification. In version 1.2, some + terminology was changed. Version 1.3 is a conversion of the + specification to RFC style. + +2. Compressed representation overview + + A compressed data set consists of a series of blocks, corresponding + to successive blocks of input data. The block sizes are arbitrary, + except that non-compressible blocks are limited to 65,535 bytes. + + Each block is compressed using a combination of the LZ77 algorithm + and Huffman coding. The Huffman trees for each block are independent + of those for previous or subsequent blocks; the LZ77 algorithm may + use a reference to a duplicated string occurring in a previous block, + up to 32K input bytes before. + + Each block consists of two parts: a pair of Huffman code trees that + describe the representation of the compressed data part, and a + compressed data part. (The Huffman trees themselves are compressed + using Huffman encoding.) The compressed data consists of a series of + elements of two types: literal bytes (of strings that have not been + detected as duplicated within the previous 32K input bytes), and + pointers to duplicated strings, where a pointer is represented as a + pair . The representation used in the + "deflate" format limits distances to 32K bytes and lengths to 258 + bytes, but does not limit the size of a block, except for + uncompressible blocks, which are limited as noted above. + + Each type of value (literals, distances, and lengths) in the + compressed data is represented using a Huffman code, using one code + tree for literals and lengths and a separate code tree for distances. + The code trees for each block appear in a compact form just before + the compressed data for that block. + + + + + + + + + + +Deutsch Informational [Page 4] + +RFC 1951 DEFLATE Compressed Data Format Specification May 1996 + + +3. Detailed specification + + 3.1. Overall conventions In the diagrams below, a box like this: + + +---+ + | | <-- the vertical bars might be missing + +---+ + + represents one byte; a box like this: + + +==============+ + | | + +==============+ + + represents a variable number of bytes. + + Bytes stored within a computer do not have a "bit order", since + they are always treated as a unit. However, a byte considered as + an integer between 0 and 255 does have a most- and least- + significant bit, and since we write numbers with the most- + significant digit on the left, we also write bytes with the most- + significant bit on the left. In the diagrams below, we number the + bits of a byte so that bit 0 is the least-significant bit, i.e., + the bits are numbered: + + +--------+ + |76543210| + +--------+ + + Within a computer, a number may occupy multiple bytes. All + multi-byte numbers in the format described here are stored with + the least-significant byte first (at the lower memory address). + For example, the decimal number 520 is stored as: + + 0 1 + +--------+--------+ + |00001000|00000010| + +--------+--------+ + ^ ^ + | | + | + more significant byte = 2 x 256 + + less significant byte = 8 + + 3.1.1. Packing into bytes + + This document does not address the issue of the order in which + bits of a byte are transmitted on a bit-sequential medium, + since the final data format described here is byte- rather than + + + +Deutsch Informational [Page 5] + +RFC 1951 DEFLATE Compressed Data Format Specification May 1996 + + + bit-oriented. However, we describe the compressed block format + in below, as a sequence of data elements of various bit + lengths, not a sequence of bytes. We must therefore specify + how to pack these data elements into bytes to form the final + compressed byte sequence: + + * Data elements are packed into bytes in order of + increasing bit number within the byte, i.e., starting + with the least-significant bit of the byte. + * Data elements other than Huffman codes are packed + starting with the least-significant bit of the data + element. + * Huffman codes are packed starting with the most- + significant bit of the code. + + In other words, if one were to print out the compressed data as + a sequence of bytes, starting with the first byte at the + *right* margin and proceeding to the *left*, with the most- + significant bit of each byte on the left as usual, one would be + able to parse the result from right to left, with fixed-width + elements in the correct MSB-to-LSB order and Huffman codes in + bit-reversed order (i.e., with the first bit of the code in the + relative LSB position). + + 3.2. Compressed block format + + 3.2.1. Synopsis of prefix and Huffman coding + + Prefix coding represents symbols from an a priori known + alphabet by bit sequences (codes), one code for each symbol, in + a manner such that different symbols may be represented by bit + sequences of different lengths, but a parser can always parse + an encoded string unambiguously symbol-by-symbol. + + We define a prefix code in terms of a binary tree in which the + two edges descending from each non-leaf node are labeled 0 and + 1 and in which the leaf nodes correspond one-for-one with (are + labeled with) the symbols of the alphabet; then the code for a + symbol is the sequence of 0's and 1's on the edges leading from + the root to the leaf labeled with that symbol. For example: + + + + + + + + + + + +Deutsch Informational [Page 6] + +RFC 1951 DEFLATE Compressed Data Format Specification May 1996 + + + /\ Symbol Code + 0 1 ------ ---- + / \ A 00 + /\ B B 1 + 0 1 C 011 + / \ D 010 + A /\ + 0 1 + / \ + D C + + A parser can decode the next symbol from an encoded input + stream by walking down the tree from the root, at each step + choosing the edge corresponding to the next input bit. + + Given an alphabet with known symbol frequencies, the Huffman + algorithm allows the construction of an optimal prefix code + (one which represents strings with those symbol frequencies + using the fewest bits of any possible prefix codes for that + alphabet). Such a code is called a Huffman code. (See + reference [1] in Chapter 5, references for additional + information on Huffman codes.) + + Note that in the "deflate" format, the Huffman codes for the + various alphabets must not exceed certain maximum code lengths. + This constraint complicates the algorithm for computing code + lengths from symbol frequencies. Again, see Chapter 5, + references for details. + + 3.2.2. Use of Huffman coding in the "deflate" format + + The Huffman codes used for each alphabet in the "deflate" + format have two additional rules: + + * All codes of a given bit length have lexicographically + consecutive values, in the same order as the symbols + they represent; + + * Shorter codes lexicographically precede longer codes. + + + + + + + + + + + + +Deutsch Informational [Page 7] + +RFC 1951 DEFLATE Compressed Data Format Specification May 1996 + + + We could recode the example above to follow this rule as + follows, assuming that the order of the alphabet is ABCD: + + Symbol Code + ------ ---- + A 10 + B 0 + C 110 + D 111 + + I.e., 0 precedes 10 which precedes 11x, and 110 and 111 are + lexicographically consecutive. + + Given this rule, we can define the Huffman code for an alphabet + just by giving the bit lengths of the codes for each symbol of + the alphabet in order; this is sufficient to determine the + actual codes. In our example, the code is completely defined + by the sequence of bit lengths (2, 1, 3, 3). The following + algorithm generates the codes as integers, intended to be read + from most- to least-significant bit. The code lengths are + initially in tree[I].Len; the codes are produced in + tree[I].Code. + + 1) Count the number of codes for each code length. Let + bl_count[N] be the number of codes of length N, N >= 1. + + 2) Find the numerical value of the smallest code for each + code length: + + code = 0; + bl_count[0] = 0; + for (bits = 1; bits <= MAX_BITS; bits++) { + code = (code + bl_count[bits-1]) << 1; + next_code[bits] = code; + } + + 3) Assign numerical values to all codes, using consecutive + values for all codes of the same length with the base + values determined at step 2. Codes that are never used + (which have a bit length of zero) must not be assigned a + value. + + for (n = 0; n <= max_code; n++) { + len = tree[n].Len; + if (len != 0) { + tree[n].Code = next_code[len]; + next_code[len]++; + } + + + +Deutsch Informational [Page 8] + +RFC 1951 DEFLATE Compressed Data Format Specification May 1996 + + + } + + Example: + + Consider the alphabet ABCDEFGH, with bit lengths (3, 3, 3, 3, + 3, 2, 4, 4). After step 1, we have: + + N bl_count[N] + - ----------- + 2 1 + 3 5 + 4 2 + + Step 2 computes the following next_code values: + + N next_code[N] + - ------------ + 1 0 + 2 0 + 3 2 + 4 14 + + Step 3 produces the following code values: + + Symbol Length Code + ------ ------ ---- + A 3 010 + B 3 011 + C 3 100 + D 3 101 + E 3 110 + F 2 00 + G 4 1110 + H 4 1111 + + 3.2.3. Details of block format + + Each block of compressed data begins with 3 header bits + containing the following data: + + first bit BFINAL + next 2 bits BTYPE + + Note that the header bits do not necessarily begin on a byte + boundary, since a block does not necessarily occupy an integral + number of bytes. + + + + + +Deutsch Informational [Page 9] + +RFC 1951 DEFLATE Compressed Data Format Specification May 1996 + + + BFINAL is set if and only if this is the last block of the data + set. + + BTYPE specifies how the data are compressed, as follows: + + 00 - no compression + 01 - compressed with fixed Huffman codes + 10 - compressed with dynamic Huffman codes + 11 - reserved (error) + + The only difference between the two compressed cases is how the + Huffman codes for the literal/length and distance alphabets are + defined. + + In all cases, the decoding algorithm for the actual data is as + follows: + + do + read block header from input stream. + if stored with no compression + skip any remaining bits in current partially + processed byte + read LEN and NLEN (see next section) + copy LEN bytes of data to output + otherwise + if compressed with dynamic Huffman codes + read representation of code trees (see + subsection below) + loop (until end of block code recognized) + decode literal/length value from input stream + if value < 256 + copy value (literal byte) to output stream + otherwise + if value = end of block (256) + break from loop + otherwise (value = 257..285) + decode distance from input stream + + move backwards distance bytes in the output + stream, and copy length bytes from this + position to the output stream. + end loop + while not last block + + Note that a duplicated string reference may refer to a string + in a previous block; i.e., the backward distance may cross one + or more block boundaries. However a distance cannot refer past + the beginning of the output stream. (An application using a + + + +Deutsch Informational [Page 10] + +RFC 1951 DEFLATE Compressed Data Format Specification May 1996 + + + preset dictionary might discard part of the output stream; a + distance can refer to that part of the output stream anyway) + Note also that the referenced string may overlap the current + position; for example, if the last 2 bytes decoded have values + X and Y, a string reference with + adds X,Y,X,Y,X to the output stream. + + We now specify each compression method in turn. + + 3.2.4. Non-compressed blocks (BTYPE=00) + + Any bits of input up to the next byte boundary are ignored. + The rest of the block consists of the following information: + + 0 1 2 3 4... + +---+---+---+---+================================+ + | LEN | NLEN |... LEN bytes of literal data...| + +---+---+---+---+================================+ + + LEN is the number of data bytes in the block. NLEN is the + one's complement of LEN. + + 3.2.5. Compressed blocks (length and distance codes) + + As noted above, encoded data blocks in the "deflate" format + consist of sequences of symbols drawn from three conceptually + distinct alphabets: either literal bytes, from the alphabet of + byte values (0..255), or pairs, + where the length is drawn from (3..258) and the distance is + drawn from (1..32,768). In fact, the literal and length + alphabets are merged into a single alphabet (0..285), where + values 0..255 represent literal bytes, the value 256 indicates + end-of-block, and values 257..285 represent length codes + (possibly in conjunction with extra bits following the symbol + code) as follows: + + + + + + + + + + + + + + + + +Deutsch Informational [Page 11] + +RFC 1951 DEFLATE Compressed Data Format Specification May 1996 + + + Extra Extra Extra + Code Bits Length(s) Code Bits Lengths Code Bits Length(s) + ---- ---- ------ ---- ---- ------- ---- ---- ------- + 257 0 3 267 1 15,16 277 4 67-82 + 258 0 4 268 1 17,18 278 4 83-98 + 259 0 5 269 2 19-22 279 4 99-114 + 260 0 6 270 2 23-26 280 4 115-130 + 261 0 7 271 2 27-30 281 5 131-162 + 262 0 8 272 2 31-34 282 5 163-194 + 263 0 9 273 3 35-42 283 5 195-226 + 264 0 10 274 3 43-50 284 5 227-257 + 265 1 11,12 275 3 51-58 285 0 258 + 266 1 13,14 276 3 59-66 + + The extra bits should be interpreted as a machine integer + stored with the most-significant bit first, e.g., bits 1110 + represent the value 14. + + Extra Extra Extra + Code Bits Dist Code Bits Dist Code Bits Distance + ---- ---- ---- ---- ---- ------ ---- ---- -------- + 0 0 1 10 4 33-48 20 9 1025-1536 + 1 0 2 11 4 49-64 21 9 1537-2048 + 2 0 3 12 5 65-96 22 10 2049-3072 + 3 0 4 13 5 97-128 23 10 3073-4096 + 4 1 5,6 14 6 129-192 24 11 4097-6144 + 5 1 7,8 15 6 193-256 25 11 6145-8192 + 6 2 9-12 16 7 257-384 26 12 8193-12288 + 7 2 13-16 17 7 385-512 27 12 12289-16384 + 8 3 17-24 18 8 513-768 28 13 16385-24576 + 9 3 25-32 19 8 769-1024 29 13 24577-32768 + + 3.2.6. Compression with fixed Huffman codes (BTYPE=01) + + The Huffman codes for the two alphabets are fixed, and are not + represented explicitly in the data. The Huffman code lengths + for the literal/length alphabet are: + + Lit Value Bits Codes + --------- ---- ----- + 0 - 143 8 00110000 through + 10111111 + 144 - 255 9 110010000 through + 111111111 + 256 - 279 7 0000000 through + 0010111 + 280 - 287 8 11000000 through + 11000111 + + + +Deutsch Informational [Page 12] + +RFC 1951 DEFLATE Compressed Data Format Specification May 1996 + + + The code lengths are sufficient to generate the actual codes, + as described above; we show the codes in the table for added + clarity. Literal/length values 286-287 will never actually + occur in the compressed data, but participate in the code + construction. + + Distance codes 0-31 are represented by (fixed-length) 5-bit + codes, with possible additional bits as shown in the table + shown in Paragraph 3.2.5, above. Note that distance codes 30- + 31 will never actually occur in the compressed data. + + 3.2.7. Compression with dynamic Huffman codes (BTYPE=10) + + The Huffman codes for the two alphabets appear in the block + immediately after the header bits and before the actual + compressed data, first the literal/length code and then the + distance code. Each code is defined by a sequence of code + lengths, as discussed in Paragraph 3.2.2, above. For even + greater compactness, the code length sequences themselves are + compressed using a Huffman code. The alphabet for code lengths + is as follows: + + 0 - 15: Represent code lengths of 0 - 15 + 16: Copy the previous code length 3 - 6 times. + The next 2 bits indicate repeat length + (0 = 3, ... , 3 = 6) + Example: Codes 8, 16 (+2 bits 11), + 16 (+2 bits 10) will expand to + 12 code lengths of 8 (1 + 6 + 5) + 17: Repeat a code length of 0 for 3 - 10 times. + (3 bits of length) + 18: Repeat a code length of 0 for 11 - 138 times + (7 bits of length) + + A code length of 0 indicates that the corresponding symbol in + the literal/length or distance alphabet will not occur in the + block, and should not participate in the Huffman code + construction algorithm given earlier. If only one distance + code is used, it is encoded using one bit, not zero bits; in + this case there is a single code length of one, with one unused + code. One distance code of zero bits means that there are no + distance codes used at all (the data is all literals). + + We can now define the format of the block: + + 5 Bits: HLIT, # of Literal/Length codes - 257 (257 - 286) + 5 Bits: HDIST, # of Distance codes - 1 (1 - 32) + 4 Bits: HCLEN, # of Code Length codes - 4 (4 - 19) + + + +Deutsch Informational [Page 13] + +RFC 1951 DEFLATE Compressed Data Format Specification May 1996 + + + (HCLEN + 4) x 3 bits: code lengths for the code length + alphabet given just above, in the order: 16, 17, 18, + 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 + + These code lengths are interpreted as 3-bit integers + (0-7); as above, a code length of 0 means the + corresponding symbol (literal/length or distance code + length) is not used. + + HLIT + 257 code lengths for the literal/length alphabet, + encoded using the code length Huffman code + + HDIST + 1 code lengths for the distance alphabet, + encoded using the code length Huffman code + + The actual compressed data of the block, + encoded using the literal/length and distance Huffman + codes + + The literal/length symbol 256 (end of data), + encoded using the literal/length Huffman code + + The code length repeat codes can cross from HLIT + 257 to the + HDIST + 1 code lengths. In other words, all code lengths form + a single sequence of HLIT + HDIST + 258 values. + + 3.3. Compliance + + A compressor may limit further the ranges of values specified in + the previous section and still be compliant; for example, it may + limit the range of backward pointers to some value smaller than + 32K. Similarly, a compressor may limit the size of blocks so that + a compressible block fits in memory. + + A compliant decompressor must accept the full range of possible + values defined in the previous section, and must accept blocks of + arbitrary size. + +4. Compression algorithm details + + While it is the intent of this document to define the "deflate" + compressed data format without reference to any particular + compression algorithm, the format is related to the compressed + formats produced by LZ77 (Lempel-Ziv 1977, see reference [2] below); + since many variations of LZ77 are patented, it is strongly + recommended that the implementor of a compressor follow the general + algorithm presented here, which is known not to be patented per se. + The material in this section is not part of the definition of the + + + +Deutsch Informational [Page 14] + +RFC 1951 DEFLATE Compressed Data Format Specification May 1996 + + + specification per se, and a compressor need not follow it in order to + be compliant. + + The compressor terminates a block when it determines that starting a + new block with fresh trees would be useful, or when the block size + fills up the compressor's block buffer. + + The compressor uses a chained hash table to find duplicated strings, + using a hash function that operates on 3-byte sequences. At any + given point during compression, let XYZ be the next 3 input bytes to + be examined (not necessarily all different, of course). First, the + compressor examines the hash chain for XYZ. If the chain is empty, + the compressor simply writes out X as a literal byte and advances one + byte in the input. If the hash chain is not empty, indicating that + the sequence XYZ (or, if we are unlucky, some other 3 bytes with the + same hash function value) has occurred recently, the compressor + compares all strings on the XYZ hash chain with the actual input data + sequence starting at the current point, and selects the longest + match. + + The compressor searches the hash chains starting with the most recent + strings, to favor small distances and thus take advantage of the + Huffman encoding. The hash chains are singly linked. There are no + deletions from the hash chains; the algorithm simply discards matches + that are too old. To avoid a worst-case situation, very long hash + chains are arbitrarily truncated at a certain length, determined by a + run-time parameter. + + To improve overall compression, the compressor optionally defers the + selection of matches ("lazy matching"): after a match of length N has + been found, the compressor searches for a longer match starting at + the next input byte. If it finds a longer match, it truncates the + previous match to a length of one (thus producing a single literal + byte) and then emits the longer match. Otherwise, it emits the + original match, and, as described above, advances N bytes before + continuing. + + Run-time parameters also control this "lazy match" procedure. If + compression ratio is most important, the compressor attempts a + complete second search regardless of the length of the first match. + In the normal case, if the current match is "long enough", the + compressor reduces the search for a longer match, thus speeding up + the process. If speed is most important, the compressor inserts new + strings in the hash table only when no match was found, or when the + match is not "too long". This degrades the compression ratio but + saves time since there are both fewer insertions and fewer searches. + + + + + +Deutsch Informational [Page 15] + +RFC 1951 DEFLATE Compressed Data Format Specification May 1996 + + +5. References + + [1] Huffman, D. A., "A Method for the Construction of Minimum + Redundancy Codes", Proceedings of the Institute of Radio + Engineers, September 1952, Volume 40, Number 9, pp. 1098-1101. + + [2] Ziv J., Lempel A., "A Universal Algorithm for Sequential Data + Compression", IEEE Transactions on Information Theory, Vol. 23, + No. 3, pp. 337-343. + + [3] Gailly, J.-L., and Adler, M., ZLIB documentation and sources, + available in ftp://ftp.uu.net/pub/archiving/zip/doc/ + + [4] Gailly, J.-L., and Adler, M., GZIP documentation and sources, + available as gzip-*.tar in ftp://prep.ai.mit.edu/pub/gnu/ + + [5] Schwartz, E. S., and Kallick, B. "Generating a canonical prefix + encoding." Comm. ACM, 7,3 (Mar. 1964), pp. 166-169. + + [6] Hirschberg and Lelewer, "Efficient decoding of prefix codes," + Comm. ACM, 33,4, April 1990, pp. 449-459. + +6. Security Considerations + + Any data compression method involves the reduction of redundancy in + the data. Consequently, any corruption of the data is likely to have + severe effects and be difficult to correct. Uncompressed text, on + the other hand, will probably still be readable despite the presence + of some corrupted bytes. + + It is recommended that systems using this data format provide some + means of validating the integrity of the compressed data. See + reference [3], for example. + +7. Source code + + Source code for a C language implementation of a "deflate" compliant + compressor and decompressor is available within the zlib package at + ftp://ftp.uu.net/pub/archiving/zip/zlib/. + +8. Acknowledgements + + Trademarks cited in this document are the property of their + respective owners. + + Phil Katz designed the deflate format. Jean-Loup Gailly and Mark + Adler wrote the related software described in this specification. + Glenn Randers-Pehrson converted this document to RFC and HTML format. + + + +Deutsch Informational [Page 16] + +RFC 1951 DEFLATE Compressed Data Format Specification May 1996 + + +9. Author's Address + + L. Peter Deutsch + Aladdin Enterprises + 203 Santa Margarita Ave. + Menlo Park, CA 94025 + + Phone: (415) 322-0103 (AM only) + FAX: (415) 322-1734 + EMail: + + Questions about the technical content of this specification can be + sent by email to: + + Jean-Loup Gailly and + Mark Adler + + Editorial comments on this specification can be sent by email to: + + L. Peter Deutsch and + Glenn Randers-Pehrson + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Deutsch Informational [Page 17] + diff --git a/libs/zlib/doc/rfc1952.txt b/libs/zlib/doc/rfc1952.txt new file mode 100644 index 000000000..a8e51b456 --- /dev/null +++ b/libs/zlib/doc/rfc1952.txt @@ -0,0 +1,675 @@ + + + + + + +Network Working Group P. Deutsch +Request for Comments: 1952 Aladdin Enterprises +Category: Informational May 1996 + + + GZIP file format specification version 4.3 + +Status of This Memo + + This memo provides information for the Internet community. This memo + does not specify an Internet standard of any kind. Distribution of + this memo is unlimited. + +IESG Note: + + The IESG takes no position on the validity of any Intellectual + Property Rights statements contained in this document. + +Notices + + Copyright (c) 1996 L. Peter Deutsch + + Permission is granted to copy and distribute this document for any + purpose and without charge, including translations into other + languages and incorporation into compilations, provided that the + copyright notice and this notice are preserved, and that any + substantive changes or deletions from the original are clearly + marked. + + A pointer to the latest version of this and related documentation in + HTML format can be found at the URL + . + +Abstract + + This specification defines a lossless compressed data format that is + compatible with the widely used GZIP utility. The format includes a + cyclic redundancy check value for detecting data corruption. The + format presently uses the DEFLATE method of compression but can be + easily extended to use other compression methods. The format can be + implemented readily in a manner not covered by patents. + + + + + + + + + + +Deutsch Informational [Page 1] + +RFC 1952 GZIP File Format Specification May 1996 + + +Table of Contents + + 1. Introduction ................................................... 2 + 1.1. Purpose ................................................... 2 + 1.2. Intended audience ......................................... 3 + 1.3. Scope ..................................................... 3 + 1.4. Compliance ................................................ 3 + 1.5. Definitions of terms and conventions used ................. 3 + 1.6. Changes from previous versions ............................ 3 + 2. Detailed specification ......................................... 4 + 2.1. Overall conventions ....................................... 4 + 2.2. File format ............................................... 5 + 2.3. Member format ............................................. 5 + 2.3.1. Member header and trailer ........................... 6 + 2.3.1.1. Extra field ................................... 8 + 2.3.1.2. Compliance .................................... 9 + 3. References .................................................. 9 + 4. Security Considerations .................................... 10 + 5. Acknowledgements ........................................... 10 + 6. Author's Address ........................................... 10 + 7. Appendix: Jean-Loup Gailly's gzip utility .................. 11 + 8. Appendix: Sample CRC Code .................................. 11 + +1. Introduction + + 1.1. Purpose + + The purpose of this specification is to define a lossless + compressed data format that: + + * Is independent of CPU type, operating system, file system, + and character set, and hence can be used for interchange; + * Can compress or decompress a data stream (as opposed to a + randomly accessible file) to produce another data stream, + using only an a priori bounded amount of intermediate + storage, and hence can be used in data communications or + similar structures such as Unix filters; + * Compresses data with efficiency comparable to the best + currently available general-purpose compression methods, + and in particular considerably better than the "compress" + program; + * Can be implemented readily in a manner not covered by + patents, and hence can be practiced freely; + * Is compatible with the file format produced by the current + widely used gzip utility, in that conforming decompressors + will be able to read data produced by the existing gzip + compressor. + + + + +Deutsch Informational [Page 2] + +RFC 1952 GZIP File Format Specification May 1996 + + + The data format defined by this specification does not attempt to: + + * Provide random access to compressed data; + * Compress specialized data (e.g., raster graphics) as well as + the best currently available specialized algorithms. + + 1.2. Intended audience + + This specification is intended for use by implementors of software + to compress data into gzip format and/or decompress data from gzip + format. + + The text of the specification assumes a basic background in + programming at the level of bits and other primitive data + representations. + + 1.3. Scope + + The specification specifies a compression method and a file format + (the latter assuming only that a file can store a sequence of + arbitrary bytes). It does not specify any particular interface to + a file system or anything about character sets or encodings + (except for file names and comments, which are optional). + + 1.4. Compliance + + Unless otherwise indicated below, a compliant decompressor must be + able to accept and decompress any file that conforms to all the + specifications presented here; a compliant compressor must produce + files that conform to all the specifications presented here. The + material in the appendices is not part of the specification per se + and is not relevant to compliance. + + 1.5. Definitions of terms and conventions used + + byte: 8 bits stored or transmitted as a unit (same as an octet). + (For this specification, a byte is exactly 8 bits, even on + machines which store a character on a number of bits different + from 8.) See below for the numbering of bits within a byte. + + 1.6. Changes from previous versions + + There have been no technical changes to the gzip format since + version 4.1 of this specification. In version 4.2, some + terminology was changed, and the sample CRC code was rewritten for + clarity and to eliminate the requirement for the caller to do pre- + and post-conditioning. Version 4.3 is a conversion of the + specification to RFC style. + + + +Deutsch Informational [Page 3] + +RFC 1952 GZIP File Format Specification May 1996 + + +2. Detailed specification + + 2.1. Overall conventions + + In the diagrams below, a box like this: + + +---+ + | | <-- the vertical bars might be missing + +---+ + + represents one byte; a box like this: + + +==============+ + | | + +==============+ + + represents a variable number of bytes. + + Bytes stored within a computer do not have a "bit order", since + they are always treated as a unit. However, a byte considered as + an integer between 0 and 255 does have a most- and least- + significant bit, and since we write numbers with the most- + significant digit on the left, we also write bytes with the most- + significant bit on the left. In the diagrams below, we number the + bits of a byte so that bit 0 is the least-significant bit, i.e., + the bits are numbered: + + +--------+ + |76543210| + +--------+ + + This document does not address the issue of the order in which + bits of a byte are transmitted on a bit-sequential medium, since + the data format described here is byte- rather than bit-oriented. + + Within a computer, a number may occupy multiple bytes. All + multi-byte numbers in the format described here are stored with + the least-significant byte first (at the lower memory address). + For example, the decimal number 520 is stored as: + + 0 1 + +--------+--------+ + |00001000|00000010| + +--------+--------+ + ^ ^ + | | + | + more significant byte = 2 x 256 + + less significant byte = 8 + + + +Deutsch Informational [Page 4] + +RFC 1952 GZIP File Format Specification May 1996 + + + 2.2. File format + + A gzip file consists of a series of "members" (compressed data + sets). The format of each member is specified in the following + section. The members simply appear one after another in the file, + with no additional information before, between, or after them. + + 2.3. Member format + + Each member has the following structure: + + +---+---+---+---+---+---+---+---+---+---+ + |ID1|ID2|CM |FLG| MTIME |XFL|OS | (more-->) + +---+---+---+---+---+---+---+---+---+---+ + + (if FLG.FEXTRA set) + + +---+---+=================================+ + | XLEN |...XLEN bytes of "extra field"...| (more-->) + +---+---+=================================+ + + (if FLG.FNAME set) + + +=========================================+ + |...original file name, zero-terminated...| (more-->) + +=========================================+ + + (if FLG.FCOMMENT set) + + +===================================+ + |...file comment, zero-terminated...| (more-->) + +===================================+ + + (if FLG.FHCRC set) + + +---+---+ + | CRC16 | + +---+---+ + + +=======================+ + |...compressed blocks...| (more-->) + +=======================+ + + 0 1 2 3 4 5 6 7 + +---+---+---+---+---+---+---+---+ + | CRC32 | ISIZE | + +---+---+---+---+---+---+---+---+ + + + + +Deutsch Informational [Page 5] + +RFC 1952 GZIP File Format Specification May 1996 + + + 2.3.1. Member header and trailer + + ID1 (IDentification 1) + ID2 (IDentification 2) + These have the fixed values ID1 = 31 (0x1f, \037), ID2 = 139 + (0x8b, \213), to identify the file as being in gzip format. + + CM (Compression Method) + This identifies the compression method used in the file. CM + = 0-7 are reserved. CM = 8 denotes the "deflate" + compression method, which is the one customarily used by + gzip and which is documented elsewhere. + + FLG (FLaGs) + This flag byte is divided into individual bits as follows: + + bit 0 FTEXT + bit 1 FHCRC + bit 2 FEXTRA + bit 3 FNAME + bit 4 FCOMMENT + bit 5 reserved + bit 6 reserved + bit 7 reserved + + If FTEXT is set, the file is probably ASCII text. This is + an optional indication, which the compressor may set by + checking a small amount of the input data to see whether any + non-ASCII characters are present. In case of doubt, FTEXT + is cleared, indicating binary data. For systems which have + different file formats for ascii text and binary data, the + decompressor can use FTEXT to choose the appropriate format. + We deliberately do not specify the algorithm used to set + this bit, since a compressor always has the option of + leaving it cleared and a decompressor always has the option + of ignoring it and letting some other program handle issues + of data conversion. + + If FHCRC is set, a CRC16 for the gzip header is present, + immediately before the compressed data. The CRC16 consists + of the two least significant bytes of the CRC32 for all + bytes of the gzip header up to and not including the CRC16. + [The FHCRC bit was never set by versions of gzip up to + 1.2.4, even though it was documented with a different + meaning in gzip 1.2.4.] + + If FEXTRA is set, optional extra fields are present, as + described in a following section. + + + +Deutsch Informational [Page 6] + +RFC 1952 GZIP File Format Specification May 1996 + + + If FNAME is set, an original file name is present, + terminated by a zero byte. The name must consist of ISO + 8859-1 (LATIN-1) characters; on operating systems using + EBCDIC or any other character set for file names, the name + must be translated to the ISO LATIN-1 character set. This + is the original name of the file being compressed, with any + directory components removed, and, if the file being + compressed is on a file system with case insensitive names, + forced to lower case. There is no original file name if the + data was compressed from a source other than a named file; + for example, if the source was stdin on a Unix system, there + is no file name. + + If FCOMMENT is set, a zero-terminated file comment is + present. This comment is not interpreted; it is only + intended for human consumption. The comment must consist of + ISO 8859-1 (LATIN-1) characters. Line breaks should be + denoted by a single line feed character (10 decimal). + + Reserved FLG bits must be zero. + + MTIME (Modification TIME) + This gives the most recent modification time of the original + file being compressed. The time is in Unix format, i.e., + seconds since 00:00:00 GMT, Jan. 1, 1970. (Note that this + may cause problems for MS-DOS and other systems that use + local rather than Universal time.) If the compressed data + did not come from a file, MTIME is set to the time at which + compression started. MTIME = 0 means no time stamp is + available. + + XFL (eXtra FLags) + These flags are available for use by specific compression + methods. The "deflate" method (CM = 8) sets these flags as + follows: + + XFL = 2 - compressor used maximum compression, + slowest algorithm + XFL = 4 - compressor used fastest algorithm + + OS (Operating System) + This identifies the type of file system on which compression + took place. This may be useful in determining end-of-line + convention for text files. The currently defined values are + as follows: + + + + + + +Deutsch Informational [Page 7] + +RFC 1952 GZIP File Format Specification May 1996 + + + 0 - FAT filesystem (MS-DOS, OS/2, NT/Win32) + 1 - Amiga + 2 - VMS (or OpenVMS) + 3 - Unix + 4 - VM/CMS + 5 - Atari TOS + 6 - HPFS filesystem (OS/2, NT) + 7 - Macintosh + 8 - Z-System + 9 - CP/M + 10 - TOPS-20 + 11 - NTFS filesystem (NT) + 12 - QDOS + 13 - Acorn RISCOS + 255 - unknown + + XLEN (eXtra LENgth) + If FLG.FEXTRA is set, this gives the length of the optional + extra field. See below for details. + + CRC32 (CRC-32) + This contains a Cyclic Redundancy Check value of the + uncompressed data computed according to CRC-32 algorithm + used in the ISO 3309 standard and in section 8.1.1.6.2 of + ITU-T recommendation V.42. (See http://www.iso.ch for + ordering ISO documents. See gopher://info.itu.ch for an + online version of ITU-T V.42.) + + ISIZE (Input SIZE) + This contains the size of the original (uncompressed) input + data modulo 2^32. + + 2.3.1.1. Extra field + + If the FLG.FEXTRA bit is set, an "extra field" is present in + the header, with total length XLEN bytes. It consists of a + series of subfields, each of the form: + + +---+---+---+---+==================================+ + |SI1|SI2| LEN |... LEN bytes of subfield data ...| + +---+---+---+---+==================================+ + + SI1 and SI2 provide a subfield ID, typically two ASCII letters + with some mnemonic value. Jean-Loup Gailly + is maintaining a registry of subfield + IDs; please send him any subfield ID you wish to use. Subfield + IDs with SI2 = 0 are reserved for future use. The following + IDs are currently defined: + + + +Deutsch Informational [Page 8] + +RFC 1952 GZIP File Format Specification May 1996 + + + SI1 SI2 Data + ---------- ---------- ---- + 0x41 ('A') 0x70 ('P') Apollo file type information + + LEN gives the length of the subfield data, excluding the 4 + initial bytes. + + 2.3.1.2. Compliance + + A compliant compressor must produce files with correct ID1, + ID2, CM, CRC32, and ISIZE, but may set all the other fields in + the fixed-length part of the header to default values (255 for + OS, 0 for all others). The compressor must set all reserved + bits to zero. + + A compliant decompressor must check ID1, ID2, and CM, and + provide an error indication if any of these have incorrect + values. It must examine FEXTRA/XLEN, FNAME, FCOMMENT and FHCRC + at least so it can skip over the optional fields if they are + present. It need not examine any other part of the header or + trailer; in particular, a decompressor may ignore FTEXT and OS + and always produce binary output, and still be compliant. A + compliant decompressor must give an error indication if any + reserved bit is non-zero, since such a bit could indicate the + presence of a new field that would cause subsequent data to be + interpreted incorrectly. + +3. References + + [1] "Information Processing - 8-bit single-byte coded graphic + character sets - Part 1: Latin alphabet No.1" (ISO 8859-1:1987). + The ISO 8859-1 (Latin-1) character set is a superset of 7-bit + ASCII. Files defining this character set are available as + iso_8859-1.* in ftp://ftp.uu.net/graphics/png/documents/ + + [2] ISO 3309 + + [3] ITU-T recommendation V.42 + + [4] Deutsch, L.P.,"DEFLATE Compressed Data Format Specification", + available in ftp://ftp.uu.net/pub/archiving/zip/doc/ + + [5] Gailly, J.-L., GZIP documentation, available as gzip-*.tar in + ftp://prep.ai.mit.edu/pub/gnu/ + + [6] Sarwate, D.V., "Computation of Cyclic Redundancy Checks via Table + Look-Up", Communications of the ACM, 31(8), pp.1008-1013. + + + + +Deutsch Informational [Page 9] + +RFC 1952 GZIP File Format Specification May 1996 + + + [7] Schwaderer, W.D., "CRC Calculation", April 85 PC Tech Journal, + pp.118-133. + + [8] ftp://ftp.adelaide.edu.au/pub/rocksoft/papers/crc_v3.txt, + describing the CRC concept. + +4. Security Considerations + + Any data compression method involves the reduction of redundancy in + the data. Consequently, any corruption of the data is likely to have + severe effects and be difficult to correct. Uncompressed text, on + the other hand, will probably still be readable despite the presence + of some corrupted bytes. + + It is recommended that systems using this data format provide some + means of validating the integrity of the compressed data, such as by + setting and checking the CRC-32 check value. + +5. Acknowledgements + + Trademarks cited in this document are the property of their + respective owners. + + Jean-Loup Gailly designed the gzip format and wrote, with Mark Adler, + the related software described in this specification. Glenn + Randers-Pehrson converted this document to RFC and HTML format. + +6. Author's Address + + L. Peter Deutsch + Aladdin Enterprises + 203 Santa Margarita Ave. + Menlo Park, CA 94025 + + Phone: (415) 322-0103 (AM only) + FAX: (415) 322-1734 + EMail: + + Questions about the technical content of this specification can be + sent by email to: + + Jean-Loup Gailly and + Mark Adler + + Editorial comments on this specification can be sent by email to: + + L. Peter Deutsch and + Glenn Randers-Pehrson + + + +Deutsch Informational [Page 10] + +RFC 1952 GZIP File Format Specification May 1996 + + +7. Appendix: Jean-Loup Gailly's gzip utility + + The most widely used implementation of gzip compression, and the + original documentation on which this specification is based, were + created by Jean-Loup Gailly . Since this + implementation is a de facto standard, we mention some more of its + features here. Again, the material in this section is not part of + the specification per se, and implementations need not follow it to + be compliant. + + When compressing or decompressing a file, gzip preserves the + protection, ownership, and modification time attributes on the local + file system, since there is no provision for representing protection + attributes in the gzip file format itself. Since the file format + includes a modification time, the gzip decompressor provides a + command line switch that assigns the modification time from the file, + rather than the local modification time of the compressed input, to + the decompressed output. + +8. Appendix: Sample CRC Code + + The following sample code represents a practical implementation of + the CRC (Cyclic Redundancy Check). (See also ISO 3309 and ITU-T V.42 + for a formal specification.) + + The sample code is in the ANSI C programming language. Non C users + may find it easier to read with these hints: + + & Bitwise AND operator. + ^ Bitwise exclusive-OR operator. + >> Bitwise right shift operator. When applied to an + unsigned quantity, as here, right shift inserts zero + bit(s) at the left. + ! Logical NOT operator. + ++ "n++" increments the variable n. + 0xNNN 0x introduces a hexadecimal (base 16) constant. + Suffix L indicates a long value (at least 32 bits). + + /* Table of CRCs of all 8-bit messages. */ + unsigned long crc_table[256]; + + /* Flag: has the table been computed? Initially false. */ + int crc_table_computed = 0; + + /* Make the table for a fast CRC. */ + void make_crc_table(void) + { + unsigned long c; + + + +Deutsch Informational [Page 11] + +RFC 1952 GZIP File Format Specification May 1996 + + + int n, k; + for (n = 0; n < 256; n++) { + c = (unsigned long) n; + for (k = 0; k < 8; k++) { + if (c & 1) { + c = 0xedb88320L ^ (c >> 1); + } else { + c = c >> 1; + } + } + crc_table[n] = c; + } + crc_table_computed = 1; + } + + /* + Update a running crc with the bytes buf[0..len-1] and return + the updated crc. The crc should be initialized to zero. Pre- and + post-conditioning (one's complement) is performed within this + function so it shouldn't be done by the caller. Usage example: + + unsigned long crc = 0L; + + while (read_buffer(buffer, length) != EOF) { + crc = update_crc(crc, buffer, length); + } + if (crc != original_crc) error(); + */ + unsigned long update_crc(unsigned long crc, + unsigned char *buf, int len) + { + unsigned long c = crc ^ 0xffffffffL; + int n; + + if (!crc_table_computed) + make_crc_table(); + for (n = 0; n < len; n++) { + c = crc_table[(c ^ buf[n]) & 0xff] ^ (c >> 8); + } + return c ^ 0xffffffffL; + } + + /* Return the CRC of the bytes buf[0..len-1]. */ + unsigned long crc(unsigned char *buf, int len) + { + return update_crc(0L, buf, len); + } + + + + +Deutsch Informational [Page 12] + diff --git a/libs/zlib/doc/txtvsbin.txt b/libs/zlib/doc/txtvsbin.txt new file mode 100644 index 000000000..3d0f0634f --- /dev/null +++ b/libs/zlib/doc/txtvsbin.txt @@ -0,0 +1,107 @@ +A Fast Method for Identifying Plain Text Files +============================================== + + +Introduction +------------ + +Given a file coming from an unknown source, it is sometimes desirable +to find out whether the format of that file is plain text. Although +this may appear like a simple task, a fully accurate detection of the +file type requires heavy-duty semantic analysis on the file contents. +It is, however, possible to obtain satisfactory results by employing +various heuristics. + +Previous versions of PKZip and other zip-compatible compression tools +were using a crude detection scheme: if more than 80% (4/5) of the bytes +found in a certain buffer are within the range [7..127], the file is +labeled as plain text, otherwise it is labeled as binary. A prominent +limitation of this scheme is the restriction to Latin-based alphabets. +Other alphabets, like Greek, Cyrillic or Asian, make extensive use of +the bytes within the range [128..255], and texts using these alphabets +are most often misidentified by this scheme; in other words, the rate +of false negatives is sometimes too high, which means that the recall +is low. Another weakness of this scheme is a reduced precision, due to +the false positives that may occur when binary files containing large +amounts of textual characters are misidentified as plain text. + +In this article we propose a new, simple detection scheme that features +a much increased precision and a near-100% recall. This scheme is +designed to work on ASCII, Unicode and other ASCII-derived alphabets, +and it handles single-byte encodings (ISO-8859, MacRoman, KOI8, etc.) +and variable-sized encodings (ISO-2022, UTF-8, etc.). Wider encodings +(UCS-2/UTF-16 and UCS-4/UTF-32) are not handled, however. + + +The Algorithm +------------- + +The algorithm works by dividing the set of bytecodes [0..255] into three +categories: +- The white list of textual bytecodes: + 9 (TAB), 10 (LF), 13 (CR), 32 (SPACE) to 255. +- The gray list of tolerated bytecodes: + 7 (BEL), 8 (BS), 11 (VT), 12 (FF), 26 (SUB), 27 (ESC). +- The black list of undesired, non-textual bytecodes: + 0 (NUL) to 6, 14 to 31. + +If a file contains at least one byte that belongs to the white list and +no byte that belongs to the black list, then the file is categorized as +plain text; otherwise, it is categorized as binary. (The boundary case, +when the file is empty, automatically falls into the latter category.) + + +Rationale +--------- + +The idea behind this algorithm relies on two observations. + +The first observation is that, although the full range of 7-bit codes +[0..127] is properly specified by the ASCII standard, most control +characters in the range [0..31] are not used in practice. The only +widely-used, almost universally-portable control codes are 9 (TAB), +10 (LF) and 13 (CR). There are a few more control codes that are +recognized on a reduced range of platforms and text viewers/editors: +7 (BEL), 8 (BS), 11 (VT), 12 (FF), 26 (SUB) and 27 (ESC); but these +codes are rarely (if ever) used alone, without being accompanied by +some printable text. Even the newer, portable text formats such as +XML avoid using control characters outside the list mentioned here. + +The second observation is that most of the binary files tend to contain +control characters, especially 0 (NUL). Even though the older text +detection schemes observe the presence of non-ASCII codes from the range +[128..255], the precision rarely has to suffer if this upper range is +labeled as textual, because the files that are genuinely binary tend to +contain both control characters and codes from the upper range. On the +other hand, the upper range needs to be labeled as textual, because it +is used by virtually all ASCII extensions. In particular, this range is +used for encoding non-Latin scripts. + +Since there is no counting involved, other than simply observing the +presence or the absence of some byte values, the algorithm produces +consistent results, regardless what alphabet encoding is being used. +(If counting were involved, it could be possible to obtain different +results on a text encoded, say, using ISO-8859-16 versus UTF-8.) + +There is an extra category of plain text files that are "polluted" with +one or more black-listed codes, either by mistake or by peculiar design +considerations. In such cases, a scheme that tolerates a small fraction +of black-listed codes would provide an increased recall (i.e. more true +positives). This, however, incurs a reduced precision overall, since +false positives are more likely to appear in binary files that contain +large chunks of textual data. Furthermore, "polluted" plain text should +be regarded as binary by general-purpose text detection schemes, because +general-purpose text processing algorithms might not be applicable. +Under this premise, it is safe to say that our detection method provides +a near-100% recall. + +Experiments have been run on many files coming from various platforms +and applications. We tried plain text files, system logs, source code, +formatted office documents, compiled object code, etc. The results +confirm the optimistic assumptions about the capabilities of this +algorithm. + + +-- +Cosmin Truta +Last updated: 2006-May-28 diff --git a/libs/zlib/examples/README.examples b/libs/zlib/examples/README.examples new file mode 100644 index 000000000..56a31714e --- /dev/null +++ b/libs/zlib/examples/README.examples @@ -0,0 +1,49 @@ +This directory contains examples of the use of zlib and other relevant +programs and documentation. + +enough.c + calculation and justification of ENOUGH parameter in inftrees.h + - calculates the maximum table space used in inflate tree + construction over all possible Huffman codes + +fitblk.c + compress just enough input to nearly fill a requested output size + - zlib isn't designed to do this, but fitblk does it anyway + +gun.c + uncompress a gzip file + - illustrates the use of inflateBack() for high speed file-to-file + decompression using call-back functions + - is approximately twice as fast as gzip -d + - also provides Unix uncompress functionality, again twice as fast + +gzappend.c + append to a gzip file + - illustrates the use of the Z_BLOCK flush parameter for inflate() + - illustrates the use of deflatePrime() to start at any bit + +gzjoin.c + join gzip files without recalculating the crc or recompressing + - illustrates the use of the Z_BLOCK flush parameter for inflate() + - illustrates the use of crc32_combine() + +gzlog.c +gzlog.h + efficiently and robustly maintain a message log file in gzip format + - illustrates use of raw deflate, Z_PARTIAL_FLUSH, deflatePrime(), + and deflateSetDictionary() + - illustrates use of a gzip header extra field + +zlib_how.html + painfully comprehensive description of zpipe.c (see below) + - describes in excruciating detail the use of deflate() and inflate() + +zpipe.c + reads and writes zlib streams from stdin to stdout + - illustrates the proper use of deflate() and inflate() + - deeply commented in zlib_how.html (see above) + +zran.c + index a zlib or gzip stream and randomly access it + - illustrates the use of Z_BLOCK, inflatePrime(), and + inflateSetDictionary() to provide random access diff --git a/libs/zlib/examples/enough.c b/libs/zlib/examples/enough.c new file mode 100644 index 000000000..c40410bad --- /dev/null +++ b/libs/zlib/examples/enough.c @@ -0,0 +1,569 @@ +/* enough.c -- determine the maximum size of inflate's Huffman code tables over + * all possible valid and complete Huffman codes, subject to a length limit. + * Copyright (C) 2007, 2008 Mark Adler + * Version 1.3 17 February 2008 Mark Adler + */ + +/* Version history: + 1.0 3 Jan 2007 First version (derived from codecount.c version 1.4) + 1.1 4 Jan 2007 Use faster incremental table usage computation + Prune examine() search on previously visited states + 1.2 5 Jan 2007 Comments clean up + As inflate does, decrease root for short codes + Refuse cases where inflate would increase root + 1.3 17 Feb 2008 Add argument for initial root table size + Fix bug for initial root table size == max - 1 + Use a macro to compute the history index + */ + +/* + Examine all possible Huffman codes for a given number of symbols and a + maximum code length in bits to determine the maximum table size for zilb's + inflate. Only complete Huffman codes are counted. + + Two codes are considered distinct if the vectors of the number of codes per + length are not identical. So permutations of the symbol assignments result + in the same code for the counting, as do permutations of the assignments of + the bit values to the codes (i.e. only canonical codes are counted). + + We build a code from shorter to longer lengths, determining how many symbols + are coded at each length. At each step, we have how many symbols remain to + be coded, what the last code length used was, and how many bit patterns of + that length remain unused. Then we add one to the code length and double the + number of unused patterns to graduate to the next code length. We then + assign all portions of the remaining symbols to that code length that + preserve the properties of a correct and eventually complete code. Those + properties are: we cannot use more bit patterns than are available; and when + all the symbols are used, there are exactly zero possible bit patterns + remaining. + + The inflate Huffman decoding algorithm uses two-level lookup tables for + speed. There is a single first-level table to decode codes up to root bits + in length (root == 9 in the current inflate implementation). The table + has 1 << root entries and is indexed by the next root bits of input. Codes + shorter than root bits have replicated table entries, so that the correct + entry is pointed to regardless of the bits that follow the short code. If + the code is longer than root bits, then the table entry points to a second- + level table. The size of that table is determined by the longest code with + that root-bit prefix. If that longest code has length len, then the table + has size 1 << (len - root), to index the remaining bits in that set of + codes. Each subsequent root-bit prefix then has its own sub-table. The + total number of table entries required by the code is calculated + incrementally as the number of codes at each bit length is populated. When + all of the codes are shorter than root bits, then root is reduced to the + longest code length, resulting in a single, smaller, one-level table. + + The inflate algorithm also provides for small values of root (relative to + the log2 of the number of symbols), where the shortest code has more bits + than root. In that case, root is increased to the length of the shortest + code. This program, by design, does not handle that case, so it is verified + that the number of symbols is less than 2^(root + 1). + + In order to speed up the examination (by about ten orders of magnitude for + the default arguments), the intermediate states in the build-up of a code + are remembered and previously visited branches are pruned. The memory + required for this will increase rapidly with the total number of symbols and + the maximum code length in bits. However this is a very small price to pay + for the vast speedup. + + First, all of the possible Huffman codes are counted, and reachable + intermediate states are noted by a non-zero count in a saved-results array. + Second, the intermediate states that lead to (root + 1) bit or longer codes + are used to look at all sub-codes from those junctures for their inflate + memory usage. (The amount of memory used is not affected by the number of + codes of root bits or less in length.) Third, the visited states in the + construction of those sub-codes and the associated calculation of the table + size is recalled in order to avoid recalculating from the same juncture. + Beginning the code examination at (root + 1) bit codes, which is enabled by + identifying the reachable nodes, accounts for about six of the orders of + magnitude of improvement for the default arguments. About another four + orders of magnitude come from not revisiting previous states. Out of + approximately 2x10^16 possible Huffman codes, only about 2x10^6 sub-codes + need to be examined to cover all of the possible table memory usage cases + for the default arguments of 286 symbols limited to 15-bit codes. + + Note that an unsigned long long type is used for counting. It is quite easy + to exceed the capacity of an eight-byte integer with a large number of + symbols and a large maximum code length, so multiple-precision arithmetic + would need to replace the unsigned long long arithmetic in that case. This + program will abort if an overflow occurs. The big_t type identifies where + the counting takes place. + + An unsigned long long type is also used for calculating the number of + possible codes remaining at the maximum length. This limits the maximum + code length to the number of bits in a long long minus the number of bits + needed to represent the symbols in a flat code. The code_t type identifies + where the bit pattern counting takes place. + */ + +#include +#include +#include +#include + +#define local static + +/* special data types */ +typedef unsigned long long big_t; /* type for code counting */ +typedef unsigned long long code_t; /* type for bit pattern counting */ +struct tab { /* type for been here check */ + size_t len; /* length of bit vector in char's */ + char *vec; /* allocated bit vector */ +}; + +/* The array for saving results, num[], is indexed with this triplet: + + syms: number of symbols remaining to code + left: number of available bit patterns at length len + len: number of bits in the codes currently being assigned + + Those indices are constrained thusly when saving results: + + syms: 3..totsym (totsym == total symbols to code) + left: 2..syms - 1, but only the evens (so syms == 8 -> 2, 4, 6) + len: 1..max - 1 (max == maximum code length in bits) + + syms == 2 is not saved since that immediately leads to a single code. left + must be even, since it represents the number of available bit patterns at + the current length, which is double the number at the previous length. + left ends at syms-1 since left == syms immediately results in a single code. + (left > sym is not allowed since that would result in an incomplete code.) + len is less than max, since the code completes immediately when len == max. + + The offset into the array is calculated for the three indices with the + first one (syms) being outermost, and the last one (len) being innermost. + We build the array with length max-1 lists for the len index, with syms-3 + of those for each symbol. There are totsym-2 of those, with each one + varying in length as a function of sym. See the calculation of index in + count() for the index, and the calculation of size in main() for the size + of the array. + + For the deflate example of 286 symbols limited to 15-bit codes, the array + has 284,284 entries, taking up 2.17 MB for an 8-byte big_t. More than + half of the space allocated for saved results is actually used -- not all + possible triplets are reached in the generation of valid Huffman codes. + */ + +/* The array for tracking visited states, done[], is itself indexed identically + to the num[] array as described above for the (syms, left, len) triplet. + Each element in the array is further indexed by the (mem, rem) doublet, + where mem is the amount of inflate table space used so far, and rem is the + remaining unused entries in the current inflate sub-table. Each indexed + element is simply one bit indicating whether the state has been visited or + not. Since the ranges for mem and rem are not known a priori, each bit + vector is of a variable size, and grows as needed to accommodate the visited + states. mem and rem are used to calculate a single index in a triangular + array. Since the range of mem is expected in the default case to be about + ten times larger than the range of rem, the array is skewed to reduce the + memory usage, with eight times the range for mem than for rem. See the + calculations for offset and bit in beenhere() for the details. + + For the deflate example of 286 symbols limited to 15-bit codes, the bit + vectors grow to total approximately 21 MB, in addition to the 4.3 MB done[] + array itself. + */ + +/* Globals to avoid propagating constants or constant pointers recursively */ +local int max; /* maximum allowed bit length for the codes */ +local int root; /* size of base code table in bits */ +local int large; /* largest code table so far */ +local size_t size; /* number of elements in num and done */ +local int *code; /* number of symbols assigned to each bit length */ +local big_t *num; /* saved results array for code counting */ +local struct tab *done; /* states already evaluated array */ + +/* Index function for num[] and done[] */ +#define INDEX(i,j,k) (((size_t)((i-1)>>1)*((i-2)>>1)+(j>>1)-1)*(max-1)+k-1) + +/* Free allocated space. Uses globals code, num, and done. */ +local void cleanup(void) +{ + size_t n; + + if (done != NULL) { + for (n = 0; n < size; n++) + if (done[n].len) + free(done[n].vec); + free(done); + } + if (num != NULL) + free(num); + if (code != NULL) + free(code); +} + +/* Return the number of possible Huffman codes using bit patterns of lengths + len through max inclusive, coding syms symbols, with left bit patterns of + length len unused -- return -1 if there is an overflow in the counting. + Keep a record of previous results in num to prevent repeating the same + calculation. Uses the globals max and num. */ +local big_t count(int syms, int len, int left) +{ + big_t sum; /* number of possible codes from this juncture */ + big_t got; /* value returned from count() */ + int least; /* least number of syms to use at this juncture */ + int most; /* most number of syms to use at this juncture */ + int use; /* number of bit patterns to use in next call */ + size_t index; /* index of this case in *num */ + + /* see if only one possible code */ + if (syms == left) + return 1; + + /* note and verify the expected state */ + assert(syms > left && left > 0 && len < max); + + /* see if we've done this one already */ + index = INDEX(syms, left, len); + got = num[index]; + if (got) + return got; /* we have -- return the saved result */ + + /* we need to use at least this many bit patterns so that the code won't be + incomplete at the next length (more bit patterns than symbols) */ + least = (left << 1) - syms; + if (least < 0) + least = 0; + + /* we can use at most this many bit patterns, lest there not be enough + available for the remaining symbols at the maximum length (if there were + no limit to the code length, this would become: most = left - 1) */ + most = (((code_t)left << (max - len)) - syms) / + (((code_t)1 << (max - len)) - 1); + + /* count all possible codes from this juncture and add them up */ + sum = 0; + for (use = least; use <= most; use++) { + got = count(syms - use, len + 1, (left - use) << 1); + sum += got; + if (got == -1 || sum < got) /* overflow */ + return -1; + } + + /* verify that all recursive calls are productive */ + assert(sum != 0); + + /* save the result and return it */ + num[index] = sum; + return sum; +} + +/* Return true if we've been here before, set to true if not. Set a bit in a + bit vector to indicate visiting this state. Each (syms,len,left) state + has a variable size bit vector indexed by (mem,rem). The bit vector is + lengthened if needed to allow setting the (mem,rem) bit. */ +local int beenhere(int syms, int len, int left, int mem, int rem) +{ + size_t index; /* index for this state's bit vector */ + size_t offset; /* offset in this state's bit vector */ + int bit; /* mask for this state's bit */ + size_t length; /* length of the bit vector in bytes */ + char *vector; /* new or enlarged bit vector */ + + /* point to vector for (syms,left,len), bit in vector for (mem,rem) */ + index = INDEX(syms, left, len); + mem -= 1 << root; + offset = (mem >> 3) + rem; + offset = ((offset * (offset + 1)) >> 1) + rem; + bit = 1 << (mem & 7); + + /* see if we've been here */ + length = done[index].len; + if (offset < length && (done[index].vec[offset] & bit) != 0) + return 1; /* done this! */ + + /* we haven't been here before -- set the bit to show we have now */ + + /* see if we need to lengthen the vector in order to set the bit */ + if (length <= offset) { + /* if we have one already, enlarge it, zero out the appended space */ + if (length) { + do { + length <<= 1; + } while (length <= offset); + vector = realloc(done[index].vec, length); + if (vector != NULL) + memset(vector + done[index].len, 0, length - done[index].len); + } + + /* otherwise we need to make a new vector and zero it out */ + else { + length = 1 << (len - root); + while (length <= offset) + length <<= 1; + vector = calloc(length, sizeof(char)); + } + + /* in either case, bail if we can't get the memory */ + if (vector == NULL) { + fputs("abort: unable to allocate enough memory\n", stderr); + cleanup(); + exit(1); + } + + /* install the new vector */ + done[index].len = length; + done[index].vec = vector; + } + + /* set the bit */ + done[index].vec[offset] |= bit; + return 0; +} + +/* Examine all possible codes from the given node (syms, len, left). Compute + the amount of memory required to build inflate's decoding tables, where the + number of code structures used so far is mem, and the number remaining in + the current sub-table is rem. Uses the globals max, code, root, large, and + done. */ +local void examine(int syms, int len, int left, int mem, int rem) +{ + int least; /* least number of syms to use at this juncture */ + int most; /* most number of syms to use at this juncture */ + int use; /* number of bit patterns to use in next call */ + + /* see if we have a complete code */ + if (syms == left) { + /* set the last code entry */ + code[len] = left; + + /* complete computation of memory used by this code */ + while (rem < left) { + left -= rem; + rem = 1 << (len - root); + mem += rem; + } + assert(rem == left); + + /* if this is a new maximum, show the entries used and the sub-code */ + if (mem > large) { + large = mem; + printf("max %d: ", mem); + for (use = root + 1; use <= max; use++) + if (code[use]) + printf("%d[%d] ", code[use], use); + putchar('\n'); + fflush(stdout); + } + + /* remove entries as we drop back down in the recursion */ + code[len] = 0; + return; + } + + /* prune the tree if we can */ + if (beenhere(syms, len, left, mem, rem)) + return; + + /* we need to use at least this many bit patterns so that the code won't be + incomplete at the next length (more bit patterns than symbols) */ + least = (left << 1) - syms; + if (least < 0) + least = 0; + + /* we can use at most this many bit patterns, lest there not be enough + available for the remaining symbols at the maximum length (if there were + no limit to the code length, this would become: most = left - 1) */ + most = (((code_t)left << (max - len)) - syms) / + (((code_t)1 << (max - len)) - 1); + + /* occupy least table spaces, creating new sub-tables as needed */ + use = least; + while (rem < use) { + use -= rem; + rem = 1 << (len - root); + mem += rem; + } + rem -= use; + + /* examine codes from here, updating table space as we go */ + for (use = least; use <= most; use++) { + code[len] = use; + examine(syms - use, len + 1, (left - use) << 1, + mem + (rem ? 1 << (len - root) : 0), rem << 1); + if (rem == 0) { + rem = 1 << (len - root); + mem += rem; + } + rem--; + } + + /* remove entries as we drop back down in the recursion */ + code[len] = 0; +} + +/* Look at all sub-codes starting with root + 1 bits. Look at only the valid + intermediate code states (syms, left, len). For each completed code, + calculate the amount of memory required by inflate to build the decoding + tables. Find the maximum amount of memory required and show the code that + requires that maximum. Uses the globals max, root, and num. */ +local void enough(int syms) +{ + int n; /* number of remaing symbols for this node */ + int left; /* number of unused bit patterns at this length */ + size_t index; /* index of this case in *num */ + + /* clear code */ + for (n = 0; n <= max; n++) + code[n] = 0; + + /* look at all (root + 1) bit and longer codes */ + large = 1 << root; /* base table */ + if (root < max) /* otherwise, there's only a base table */ + for (n = 3; n <= syms; n++) + for (left = 2; left < n; left += 2) + { + /* look at all reachable (root + 1) bit nodes, and the + resulting codes (complete at root + 2 or more) */ + index = INDEX(n, left, root + 1); + if (root + 1 < max && num[index]) /* reachable node */ + examine(n, root + 1, left, 1 << root, 0); + + /* also look at root bit codes with completions at root + 1 + bits (not saved in num, since complete), just in case */ + if (num[index - 1] && n <= left << 1) + examine((n - left) << 1, root + 1, (n - left) << 1, + 1 << root, 0); + } + + /* done */ + printf("done: maximum of %d table entries\n", large); +} + +/* + Examine and show the total number of possible Huffman codes for a given + maximum number of symbols, initial root table size, and maximum code length + in bits -- those are the command arguments in that order. The default + values are 286, 9, and 15 respectively, for the deflate literal/length code. + The possible codes are counted for each number of coded symbols from two to + the maximum. The counts for each of those and the total number of codes are + shown. The maximum number of inflate table entires is then calculated + across all possible codes. Each new maximum number of table entries and the + associated sub-code (starting at root + 1 == 10 bits) is shown. + + To count and examine Huffman codes that are not length-limited, provide a + maximum length equal to the number of symbols minus one. + + For the deflate literal/length code, use "enough". For the deflate distance + code, use "enough 30 6". + + This uses the %llu printf format to print big_t numbers, which assumes that + big_t is an unsigned long long. If the big_t type is changed (for example + to a multiple precision type), the method of printing will also need to be + updated. + */ +int main(int argc, char **argv) +{ + int syms; /* total number of symbols to code */ + int n; /* number of symbols to code for this run */ + big_t got; /* return value of count() */ + big_t sum; /* accumulated number of codes over n */ + + /* set up globals for cleanup() */ + code = NULL; + num = NULL; + done = NULL; + + /* get arguments -- default to the deflate literal/length code */ + syms = 286; + root = 9; + max = 15; + if (argc > 1) { + syms = atoi(argv[1]); + if (argc > 2) { + root = atoi(argv[2]); + if (argc > 3) + max = atoi(argv[3]); + } + } + if (argc > 4 || syms < 2 || root < 1 || max < 1) { + fputs("invalid arguments, need: [sym >= 2 [root >= 1 [max >= 1]]]\n", + stderr); + return 1; + } + + /* if not restricting the code length, the longest is syms - 1 */ + if (max > syms - 1) + max = syms - 1; + + /* determine the number of bits in a code_t */ + n = 0; + while (((code_t)1 << n) != 0) + n++; + + /* make sure that the calculation of most will not overflow */ + if (max > n || syms - 2 >= (((code_t)0 - 1) >> (max - 1))) { + fputs("abort: code length too long for internal types\n", stderr); + return 1; + } + + /* reject impossible code requests */ + if (syms - 1 > ((code_t)1 << max) - 1) { + fprintf(stderr, "%d symbols cannot be coded in %d bits\n", + syms, max); + return 1; + } + + /* allocate code vector */ + code = calloc(max + 1, sizeof(int)); + if (code == NULL) { + fputs("abort: unable to allocate enough memory\n", stderr); + return 1; + } + + /* determine size of saved results array, checking for overflows, + allocate and clear the array (set all to zero with calloc()) */ + if (syms == 2) /* iff max == 1 */ + num = NULL; /* won't be saving any results */ + else { + size = syms >> 1; + if (size > ((size_t)0 - 1) / (n = (syms - 1) >> 1) || + (size *= n, size > ((size_t)0 - 1) / (n = max - 1)) || + (size *= n, size > ((size_t)0 - 1) / sizeof(big_t)) || + (num = calloc(size, sizeof(big_t))) == NULL) { + fputs("abort: unable to allocate enough memory\n", stderr); + cleanup(); + return 1; + } + } + + /* count possible codes for all numbers of symbols, add up counts */ + sum = 0; + for (n = 2; n <= syms; n++) { + got = count(n, 1, 2); + sum += got; + if (got == -1 || sum < got) { /* overflow */ + fputs("abort: can't count that high!\n", stderr); + cleanup(); + return 1; + } + printf("%llu %d-codes\n", got, n); + } + printf("%llu total codes for 2 to %d symbols", sum, syms); + if (max < syms - 1) + printf(" (%d-bit length limit)\n", max); + else + puts(" (no length limit)"); + + /* allocate and clear done array for beenhere() */ + if (syms == 2) + done = NULL; + else if (size > ((size_t)0 - 1) / sizeof(struct tab) || + (done = calloc(size, sizeof(struct tab))) == NULL) { + fputs("abort: unable to allocate enough memory\n", stderr); + cleanup(); + return 1; + } + + /* find and show maximum inflate table usage */ + if (root > max) /* reduce root to max length */ + root = max; + if (syms < ((code_t)1 << (root + 1))) + enough(syms); + else + puts("cannot handle minimum code lengths > root"); + + /* done */ + cleanup(); + return 0; +} diff --git a/libs/zlib/examples/fitblk.c b/libs/zlib/examples/fitblk.c new file mode 100644 index 000000000..c61de5c99 --- /dev/null +++ b/libs/zlib/examples/fitblk.c @@ -0,0 +1,233 @@ +/* fitblk.c: example of fitting compressed output to a specified size + Not copyrighted -- provided to the public domain + Version 1.1 25 November 2004 Mark Adler */ + +/* Version history: + 1.0 24 Nov 2004 First version + 1.1 25 Nov 2004 Change deflateInit2() to deflateInit() + Use fixed-size, stack-allocated raw buffers + Simplify code moving compression to subroutines + Use assert() for internal errors + Add detailed description of approach + */ + +/* Approach to just fitting a requested compressed size: + + fitblk performs three compression passes on a portion of the input + data in order to determine how much of that input will compress to + nearly the requested output block size. The first pass generates + enough deflate blocks to produce output to fill the requested + output size plus a specfied excess amount (see the EXCESS define + below). The last deflate block may go quite a bit past that, but + is discarded. The second pass decompresses and recompresses just + the compressed data that fit in the requested plus excess sized + buffer. The deflate process is terminated after that amount of + input, which is less than the amount consumed on the first pass. + The last deflate block of the result will be of a comparable size + to the final product, so that the header for that deflate block and + the compression ratio for that block will be about the same as in + the final product. The third compression pass decompresses the + result of the second step, but only the compressed data up to the + requested size minus an amount to allow the compressed stream to + complete (see the MARGIN define below). That will result in a + final compressed stream whose length is less than or equal to the + requested size. Assuming sufficient input and a requested size + greater than a few hundred bytes, the shortfall will typically be + less than ten bytes. + + If the input is short enough that the first compression completes + before filling the requested output size, then that compressed + stream is return with no recompression. + + EXCESS is chosen to be just greater than the shortfall seen in a + two pass approach similar to the above. That shortfall is due to + the last deflate block compressing more efficiently with a smaller + header on the second pass. EXCESS is set to be large enough so + that there is enough uncompressed data for the second pass to fill + out the requested size, and small enough so that the final deflate + block of the second pass will be close in size to the final deflate + block of the third and final pass. MARGIN is chosen to be just + large enough to assure that the final compression has enough room + to complete in all cases. + */ + +#include +#include +#include +#include "zlib.h" + +#define local static + +/* print nastygram and leave */ +local void quit(char *why) +{ + fprintf(stderr, "fitblk abort: %s\n", why); + exit(1); +} + +#define RAWLEN 4096 /* intermediate uncompressed buffer size */ + +/* compress from file to def until provided buffer is full or end of + input reached; return last deflate() return value, or Z_ERRNO if + there was read error on the file */ +local int partcompress(FILE *in, z_streamp def) +{ + int ret, flush; + unsigned char raw[RAWLEN]; + + flush = Z_NO_FLUSH; + do { + def->avail_in = fread(raw, 1, RAWLEN, in); + if (ferror(in)) + return Z_ERRNO; + def->next_in = raw; + if (feof(in)) + flush = Z_FINISH; + ret = deflate(def, flush); + assert(ret != Z_STREAM_ERROR); + } while (def->avail_out != 0 && flush == Z_NO_FLUSH); + return ret; +} + +/* recompress from inf's input to def's output; the input for inf and + the output for def are set in those structures before calling; + return last deflate() return value, or Z_MEM_ERROR if inflate() + was not able to allocate enough memory when it needed to */ +local int recompress(z_streamp inf, z_streamp def) +{ + int ret, flush; + unsigned char raw[RAWLEN]; + + flush = Z_NO_FLUSH; + do { + /* decompress */ + inf->avail_out = RAWLEN; + inf->next_out = raw; + ret = inflate(inf, Z_NO_FLUSH); + assert(ret != Z_STREAM_ERROR && ret != Z_DATA_ERROR && + ret != Z_NEED_DICT); + if (ret == Z_MEM_ERROR) + return ret; + + /* compress what was decompresed until done or no room */ + def->avail_in = RAWLEN - inf->avail_out; + def->next_in = raw; + if (inf->avail_out != 0) + flush = Z_FINISH; + ret = deflate(def, flush); + assert(ret != Z_STREAM_ERROR); + } while (ret != Z_STREAM_END && def->avail_out != 0); + return ret; +} + +#define EXCESS 256 /* empirically determined stream overage */ +#define MARGIN 8 /* amount to back off for completion */ + +/* compress from stdin to fixed-size block on stdout */ +int main(int argc, char **argv) +{ + int ret; /* return code */ + unsigned size; /* requested fixed output block size */ + unsigned have; /* bytes written by deflate() call */ + unsigned char *blk; /* intermediate and final stream */ + unsigned char *tmp; /* close to desired size stream */ + z_stream def, inf; /* zlib deflate and inflate states */ + + /* get requested output size */ + if (argc != 2) + quit("need one argument: size of output block"); + ret = strtol(argv[1], argv + 1, 10); + if (argv[1][0] != 0) + quit("argument must be a number"); + if (ret < 8) /* 8 is minimum zlib stream size */ + quit("need positive size of 8 or greater"); + size = (unsigned)ret; + + /* allocate memory for buffers and compression engine */ + blk = malloc(size + EXCESS); + def.zalloc = Z_NULL; + def.zfree = Z_NULL; + def.opaque = Z_NULL; + ret = deflateInit(&def, Z_DEFAULT_COMPRESSION); + if (ret != Z_OK || blk == NULL) + quit("out of memory"); + + /* compress from stdin until output full, or no more input */ + def.avail_out = size + EXCESS; + def.next_out = blk; + ret = partcompress(stdin, &def); + if (ret == Z_ERRNO) + quit("error reading input"); + + /* if it all fit, then size was undersubscribed -- done! */ + if (ret == Z_STREAM_END && def.avail_out >= EXCESS) { + /* write block to stdout */ + have = size + EXCESS - def.avail_out; + if (fwrite(blk, 1, have, stdout) != have || ferror(stdout)) + quit("error writing output"); + + /* clean up and print results to stderr */ + ret = deflateEnd(&def); + assert(ret != Z_STREAM_ERROR); + free(blk); + fprintf(stderr, + "%u bytes unused out of %u requested (all input)\n", + size - have, size); + return 0; + } + + /* it didn't all fit -- set up for recompression */ + inf.zalloc = Z_NULL; + inf.zfree = Z_NULL; + inf.opaque = Z_NULL; + inf.avail_in = 0; + inf.next_in = Z_NULL; + ret = inflateInit(&inf); + tmp = malloc(size + EXCESS); + if (ret != Z_OK || tmp == NULL) + quit("out of memory"); + ret = deflateReset(&def); + assert(ret != Z_STREAM_ERROR); + + /* do first recompression close to the right amount */ + inf.avail_in = size + EXCESS; + inf.next_in = blk; + def.avail_out = size + EXCESS; + def.next_out = tmp; + ret = recompress(&inf, &def); + if (ret == Z_MEM_ERROR) + quit("out of memory"); + + /* set up for next reocmpression */ + ret = inflateReset(&inf); + assert(ret != Z_STREAM_ERROR); + ret = deflateReset(&def); + assert(ret != Z_STREAM_ERROR); + + /* do second and final recompression (third compression) */ + inf.avail_in = size - MARGIN; /* assure stream will complete */ + inf.next_in = tmp; + def.avail_out = size; + def.next_out = blk; + ret = recompress(&inf, &def); + if (ret == Z_MEM_ERROR) + quit("out of memory"); + assert(ret == Z_STREAM_END); /* otherwise MARGIN too small */ + + /* done -- write block to stdout */ + have = size - def.avail_out; + if (fwrite(blk, 1, have, stdout) != have || ferror(stdout)) + quit("error writing output"); + + /* clean up and print results to stderr */ + free(tmp); + ret = inflateEnd(&inf); + assert(ret != Z_STREAM_ERROR); + ret = deflateEnd(&def); + assert(ret != Z_STREAM_ERROR); + free(blk); + fprintf(stderr, + "%u bytes unused out of %u requested (%lu input)\n", + size - have, size, def.total_in); + return 0; +} diff --git a/libs/zlib/examples/gun.c b/libs/zlib/examples/gun.c new file mode 100644 index 000000000..72b0882ab --- /dev/null +++ b/libs/zlib/examples/gun.c @@ -0,0 +1,701 @@ +/* gun.c -- simple gunzip to give an example of the use of inflateBack() + * Copyright (C) 2003, 2005, 2008, 2010 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + Version 1.6 17 January 2010 Mark Adler */ + +/* Version history: + 1.0 16 Feb 2003 First version for testing of inflateBack() + 1.1 21 Feb 2005 Decompress concatenated gzip streams + Remove use of "this" variable (C++ keyword) + Fix return value for in() + Improve allocation failure checking + Add typecasting for void * structures + Add -h option for command version and usage + Add a bunch of comments + 1.2 20 Mar 2005 Add Unix compress (LZW) decompression + Copy file attributes from input file to output file + 1.3 12 Jun 2005 Add casts for error messages [Oberhumer] + 1.4 8 Dec 2006 LZW decompression speed improvements + 1.5 9 Feb 2008 Avoid warning in latest version of gcc + 1.6 17 Jan 2010 Avoid signed/unsigned comparison warnings + */ + +/* + gun [ -t ] [ name ... ] + + decompresses the data in the named gzip files. If no arguments are given, + gun will decompress from stdin to stdout. The names must end in .gz, -gz, + .z, -z, _z, or .Z. The uncompressed data will be written to a file name + with the suffix stripped. On success, the original file is deleted. On + failure, the output file is deleted. For most failures, the command will + continue to process the remaining names on the command line. A memory + allocation failure will abort the command. If -t is specified, then the + listed files or stdin will be tested as gzip files for integrity (without + checking for a proper suffix), no output will be written, and no files + will be deleted. + + Like gzip, gun allows concatenated gzip streams and will decompress them, + writing all of the uncompressed data to the output. Unlike gzip, gun allows + an empty file on input, and will produce no error writing an empty output + file. + + gun will also decompress files made by Unix compress, which uses LZW + compression. These files are automatically detected by virtue of their + magic header bytes. Since the end of Unix compress stream is marked by the + end-of-file, they cannot be concantenated. If a Unix compress stream is + encountered in an input file, it is the last stream in that file. + + Like gunzip and uncompress, the file attributes of the orignal compressed + file are maintained in the final uncompressed file, to the extent that the + user permissions allow it. + + On my Mac OS X PowerPC G4, gun is almost twice as fast as gunzip (version + 1.2.4) is on the same file, when gun is linked with zlib 1.2.2. Also the + LZW decompression provided by gun is about twice as fast as the standard + Unix uncompress command. + */ + +/* external functions and related types and constants */ +#include /* fprintf() */ +#include /* malloc(), free() */ +#include /* strerror(), strcmp(), strlen(), memcpy() */ +#include /* errno */ +#include /* open() */ +#include /* read(), write(), close(), chown(), unlink() */ +#include +#include /* stat(), chmod() */ +#include /* utime() */ +#include "zlib.h" /* inflateBackInit(), inflateBack(), */ + /* inflateBackEnd(), crc32() */ + +/* function declaration */ +#define local static + +/* buffer constants */ +#define SIZE 32768U /* input and output buffer sizes */ +#define PIECE 16384 /* limits i/o chunks for 16-bit int case */ + +/* structure for infback() to pass to input function in() -- it maintains the + input file and a buffer of size SIZE */ +struct ind { + int infile; + unsigned char *inbuf; +}; + +/* Load input buffer, assumed to be empty, and return bytes loaded and a + pointer to them. read() is called until the buffer is full, or until it + returns end-of-file or error. Return 0 on error. */ +local unsigned in(void *in_desc, unsigned char **buf) +{ + int ret; + unsigned len; + unsigned char *next; + struct ind *me = (struct ind *)in_desc; + + next = me->inbuf; + *buf = next; + len = 0; + do { + ret = PIECE; + if ((unsigned)ret > SIZE - len) + ret = (int)(SIZE - len); + ret = (int)read(me->infile, next, ret); + if (ret == -1) { + len = 0; + break; + } + next += ret; + len += ret; + } while (ret != 0 && len < SIZE); + return len; +} + +/* structure for infback() to pass to output function out() -- it maintains the + output file, a running CRC-32 check on the output and the total number of + bytes output, both for checking against the gzip trailer. (The length in + the gzip trailer is stored modulo 2^32, so it's ok if a long is 32 bits and + the output is greater than 4 GB.) */ +struct outd { + int outfile; + int check; /* true if checking crc and total */ + unsigned long crc; + unsigned long total; +}; + +/* Write output buffer and update the CRC-32 and total bytes written. write() + is called until all of the output is written or an error is encountered. + On success out() returns 0. For a write failure, out() returns 1. If the + output file descriptor is -1, then nothing is written. + */ +local int out(void *out_desc, unsigned char *buf, unsigned len) +{ + int ret; + struct outd *me = (struct outd *)out_desc; + + if (me->check) { + me->crc = crc32(me->crc, buf, len); + me->total += len; + } + if (me->outfile != -1) + do { + ret = PIECE; + if ((unsigned)ret > len) + ret = (int)len; + ret = (int)write(me->outfile, buf, ret); + if (ret == -1) + return 1; + buf += ret; + len -= ret; + } while (len != 0); + return 0; +} + +/* next input byte macro for use inside lunpipe() and gunpipe() */ +#define NEXT() (have ? 0 : (have = in(indp, &next)), \ + last = have ? (have--, (int)(*next++)) : -1) + +/* memory for gunpipe() and lunpipe() -- + the first 256 entries of prefix[] and suffix[] are never used, could + have offset the index, but it's faster to waste the memory */ +unsigned char inbuf[SIZE]; /* input buffer */ +unsigned char outbuf[SIZE]; /* output buffer */ +unsigned short prefix[65536]; /* index to LZW prefix string */ +unsigned char suffix[65536]; /* one-character LZW suffix */ +unsigned char match[65280 + 2]; /* buffer for reversed match or gzip + 32K sliding window */ + +/* throw out what's left in the current bits byte buffer (this is a vestigial + aspect of the compressed data format derived from an implementation that + made use of a special VAX machine instruction!) */ +#define FLUSHCODE() \ + do { \ + left = 0; \ + rem = 0; \ + if (chunk > have) { \ + chunk -= have; \ + have = 0; \ + if (NEXT() == -1) \ + break; \ + chunk--; \ + if (chunk > have) { \ + chunk = have = 0; \ + break; \ + } \ + } \ + have -= chunk; \ + next += chunk; \ + chunk = 0; \ + } while (0) + +/* Decompress a compress (LZW) file from indp to outfile. The compress magic + header (two bytes) has already been read and verified. There are have bytes + of buffered input at next. strm is used for passing error information back + to gunpipe(). + + lunpipe() will return Z_OK on success, Z_BUF_ERROR for an unexpected end of + file, read error, or write error (a write error indicated by strm->next_in + not equal to Z_NULL), or Z_DATA_ERROR for invalid input. + */ +local int lunpipe(unsigned have, unsigned char *next, struct ind *indp, + int outfile, z_stream *strm) +{ + int last; /* last byte read by NEXT(), or -1 if EOF */ + unsigned chunk; /* bytes left in current chunk */ + int left; /* bits left in rem */ + unsigned rem; /* unused bits from input */ + int bits; /* current bits per code */ + unsigned code; /* code, table traversal index */ + unsigned mask; /* mask for current bits codes */ + int max; /* maximum bits per code for this stream */ + unsigned flags; /* compress flags, then block compress flag */ + unsigned end; /* last valid entry in prefix/suffix tables */ + unsigned temp; /* current code */ + unsigned prev; /* previous code */ + unsigned final; /* last character written for previous code */ + unsigned stack; /* next position for reversed string */ + unsigned outcnt; /* bytes in output buffer */ + struct outd outd; /* output structure */ + unsigned char *p; + + /* set up output */ + outd.outfile = outfile; + outd.check = 0; + + /* process remainder of compress header -- a flags byte */ + flags = NEXT(); + if (last == -1) + return Z_BUF_ERROR; + if (flags & 0x60) { + strm->msg = (char *)"unknown lzw flags set"; + return Z_DATA_ERROR; + } + max = flags & 0x1f; + if (max < 9 || max > 16) { + strm->msg = (char *)"lzw bits out of range"; + return Z_DATA_ERROR; + } + if (max == 9) /* 9 doesn't really mean 9 */ + max = 10; + flags &= 0x80; /* true if block compress */ + + /* clear table */ + bits = 9; + mask = 0x1ff; + end = flags ? 256 : 255; + + /* set up: get first 9-bit code, which is the first decompressed byte, but + don't create a table entry until the next code */ + if (NEXT() == -1) /* no compressed data is ok */ + return Z_OK; + final = prev = (unsigned)last; /* low 8 bits of code */ + if (NEXT() == -1) /* missing a bit */ + return Z_BUF_ERROR; + if (last & 1) { /* code must be < 256 */ + strm->msg = (char *)"invalid lzw code"; + return Z_DATA_ERROR; + } + rem = (unsigned)last >> 1; /* remaining 7 bits */ + left = 7; + chunk = bits - 2; /* 7 bytes left in this chunk */ + outbuf[0] = (unsigned char)final; /* write first decompressed byte */ + outcnt = 1; + + /* decode codes */ + stack = 0; + for (;;) { + /* if the table will be full after this, increment the code size */ + if (end >= mask && bits < max) { + FLUSHCODE(); + bits++; + mask <<= 1; + mask++; + } + + /* get a code of length bits */ + if (chunk == 0) /* decrement chunk modulo bits */ + chunk = bits; + code = rem; /* low bits of code */ + if (NEXT() == -1) { /* EOF is end of compressed data */ + /* write remaining buffered output */ + if (outcnt && out(&outd, outbuf, outcnt)) { + strm->next_in = outbuf; /* signal write error */ + return Z_BUF_ERROR; + } + return Z_OK; + } + code += (unsigned)last << left; /* middle (or high) bits of code */ + left += 8; + chunk--; + if (bits > left) { /* need more bits */ + if (NEXT() == -1) /* can't end in middle of code */ + return Z_BUF_ERROR; + code += (unsigned)last << left; /* high bits of code */ + left += 8; + chunk--; + } + code &= mask; /* mask to current code length */ + left -= bits; /* number of unused bits */ + rem = (unsigned)last >> (8 - left); /* unused bits from last byte */ + + /* process clear code (256) */ + if (code == 256 && flags) { + FLUSHCODE(); + bits = 9; /* initialize bits and mask */ + mask = 0x1ff; + end = 255; /* empty table */ + continue; /* get next code */ + } + + /* special code to reuse last match */ + temp = code; /* save the current code */ + if (code > end) { + /* Be picky on the allowed code here, and make sure that the code + we drop through (prev) will be a valid index so that random + input does not cause an exception. The code != end + 1 check is + empirically derived, and not checked in the original uncompress + code. If this ever causes a problem, that check could be safely + removed. Leaving this check in greatly improves gun's ability + to detect random or corrupted input after a compress header. + In any case, the prev > end check must be retained. */ + if (code != end + 1 || prev > end) { + strm->msg = (char *)"invalid lzw code"; + return Z_DATA_ERROR; + } + match[stack++] = (unsigned char)final; + code = prev; + } + + /* walk through linked list to generate output in reverse order */ + p = match + stack; + while (code >= 256) { + *p++ = suffix[code]; + code = prefix[code]; + } + stack = p - match; + match[stack++] = (unsigned char)code; + final = code; + + /* link new table entry */ + if (end < mask) { + end++; + prefix[end] = (unsigned short)prev; + suffix[end] = (unsigned char)final; + } + + /* set previous code for next iteration */ + prev = temp; + + /* write output in forward order */ + while (stack > SIZE - outcnt) { + while (outcnt < SIZE) + outbuf[outcnt++] = match[--stack]; + if (out(&outd, outbuf, outcnt)) { + strm->next_in = outbuf; /* signal write error */ + return Z_BUF_ERROR; + } + outcnt = 0; + } + p = match + stack; + do { + outbuf[outcnt++] = *--p; + } while (p > match); + stack = 0; + + /* loop for next code with final and prev as the last match, rem and + left provide the first 0..7 bits of the next code, end is the last + valid table entry */ + } +} + +/* Decompress a gzip file from infile to outfile. strm is assumed to have been + successfully initialized with inflateBackInit(). The input file may consist + of a series of gzip streams, in which case all of them will be decompressed + to the output file. If outfile is -1, then the gzip stream(s) integrity is + checked and nothing is written. + + The return value is a zlib error code: Z_MEM_ERROR if out of memory, + Z_DATA_ERROR if the header or the compressed data is invalid, or if the + trailer CRC-32 check or length doesn't match, Z_BUF_ERROR if the input ends + prematurely or a write error occurs, or Z_ERRNO if junk (not a another gzip + stream) follows a valid gzip stream. + */ +local int gunpipe(z_stream *strm, int infile, int outfile) +{ + int ret, first, last; + unsigned have, flags, len; + unsigned char *next = NULL; + struct ind ind, *indp; + struct outd outd; + + /* setup input buffer */ + ind.infile = infile; + ind.inbuf = inbuf; + indp = &ind; + + /* decompress concatenated gzip streams */ + have = 0; /* no input data read in yet */ + first = 1; /* looking for first gzip header */ + strm->next_in = Z_NULL; /* so Z_BUF_ERROR means EOF */ + for (;;) { + /* look for the two magic header bytes for a gzip stream */ + if (NEXT() == -1) { + ret = Z_OK; + break; /* empty gzip stream is ok */ + } + if (last != 31 || (NEXT() != 139 && last != 157)) { + strm->msg = (char *)"incorrect header check"; + ret = first ? Z_DATA_ERROR : Z_ERRNO; + break; /* not a gzip or compress header */ + } + first = 0; /* next non-header is junk */ + + /* process a compress (LZW) file -- can't be concatenated after this */ + if (last == 157) { + ret = lunpipe(have, next, indp, outfile, strm); + break; + } + + /* process remainder of gzip header */ + ret = Z_BUF_ERROR; + if (NEXT() != 8) { /* only deflate method allowed */ + if (last == -1) break; + strm->msg = (char *)"unknown compression method"; + ret = Z_DATA_ERROR; + break; + } + flags = NEXT(); /* header flags */ + NEXT(); /* discard mod time, xflgs, os */ + NEXT(); + NEXT(); + NEXT(); + NEXT(); + NEXT(); + if (last == -1) break; + if (flags & 0xe0) { + strm->msg = (char *)"unknown header flags set"; + ret = Z_DATA_ERROR; + break; + } + if (flags & 4) { /* extra field */ + len = NEXT(); + len += (unsigned)(NEXT()) << 8; + if (last == -1) break; + while (len > have) { + len -= have; + have = 0; + if (NEXT() == -1) break; + len--; + } + if (last == -1) break; + have -= len; + next += len; + } + if (flags & 8) /* file name */ + while (NEXT() != 0 && last != -1) + ; + if (flags & 16) /* comment */ + while (NEXT() != 0 && last != -1) + ; + if (flags & 2) { /* header crc */ + NEXT(); + NEXT(); + } + if (last == -1) break; + + /* set up output */ + outd.outfile = outfile; + outd.check = 1; + outd.crc = crc32(0L, Z_NULL, 0); + outd.total = 0; + + /* decompress data to output */ + strm->next_in = next; + strm->avail_in = have; + ret = inflateBack(strm, in, indp, out, &outd); + if (ret != Z_STREAM_END) break; + next = strm->next_in; + have = strm->avail_in; + strm->next_in = Z_NULL; /* so Z_BUF_ERROR means EOF */ + + /* check trailer */ + ret = Z_BUF_ERROR; + if (NEXT() != (int)(outd.crc & 0xff) || + NEXT() != (int)((outd.crc >> 8) & 0xff) || + NEXT() != (int)((outd.crc >> 16) & 0xff) || + NEXT() != (int)((outd.crc >> 24) & 0xff)) { + /* crc error */ + if (last != -1) { + strm->msg = (char *)"incorrect data check"; + ret = Z_DATA_ERROR; + } + break; + } + if (NEXT() != (int)(outd.total & 0xff) || + NEXT() != (int)((outd.total >> 8) & 0xff) || + NEXT() != (int)((outd.total >> 16) & 0xff) || + NEXT() != (int)((outd.total >> 24) & 0xff)) { + /* length error */ + if (last != -1) { + strm->msg = (char *)"incorrect length check"; + ret = Z_DATA_ERROR; + } + break; + } + + /* go back and look for another gzip stream */ + } + + /* clean up and return */ + return ret; +} + +/* Copy file attributes, from -> to, as best we can. This is best effort, so + no errors are reported. The mode bits, including suid, sgid, and the sticky + bit are copied (if allowed), the owner's user id and group id are copied + (again if allowed), and the access and modify times are copied. */ +local void copymeta(char *from, char *to) +{ + struct stat was; + struct utimbuf when; + + /* get all of from's Unix meta data, return if not a regular file */ + if (stat(from, &was) != 0 || (was.st_mode & S_IFMT) != S_IFREG) + return; + + /* set to's mode bits, ignore errors */ + (void)chmod(to, was.st_mode & 07777); + + /* copy owner's user and group, ignore errors */ + (void)chown(to, was.st_uid, was.st_gid); + + /* copy access and modify times, ignore errors */ + when.actime = was.st_atime; + when.modtime = was.st_mtime; + (void)utime(to, &when); +} + +/* Decompress the file inname to the file outnname, of if test is true, just + decompress without writing and check the gzip trailer for integrity. If + inname is NULL or an empty string, read from stdin. If outname is NULL or + an empty string, write to stdout. strm is a pre-initialized inflateBack + structure. When appropriate, copy the file attributes from inname to + outname. + + gunzip() returns 1 if there is an out-of-memory error or an unexpected + return code from gunpipe(). Otherwise it returns 0. + */ +local int gunzip(z_stream *strm, char *inname, char *outname, int test) +{ + int ret; + int infile, outfile; + + /* open files */ + if (inname == NULL || *inname == 0) { + inname = "-"; + infile = 0; /* stdin */ + } + else { + infile = open(inname, O_RDONLY, 0); + if (infile == -1) { + fprintf(stderr, "gun cannot open %s\n", inname); + return 0; + } + } + if (test) + outfile = -1; + else if (outname == NULL || *outname == 0) { + outname = "-"; + outfile = 1; /* stdout */ + } + else { + outfile = open(outname, O_CREAT | O_TRUNC | O_WRONLY, 0666); + if (outfile == -1) { + close(infile); + fprintf(stderr, "gun cannot create %s\n", outname); + return 0; + } + } + errno = 0; + + /* decompress */ + ret = gunpipe(strm, infile, outfile); + if (outfile > 2) close(outfile); + if (infile > 2) close(infile); + + /* interpret result */ + switch (ret) { + case Z_OK: + case Z_ERRNO: + if (infile > 2 && outfile > 2) { + copymeta(inname, outname); /* copy attributes */ + unlink(inname); + } + if (ret == Z_ERRNO) + fprintf(stderr, "gun warning: trailing garbage ignored in %s\n", + inname); + break; + case Z_DATA_ERROR: + if (outfile > 2) unlink(outname); + fprintf(stderr, "gun data error on %s: %s\n", inname, strm->msg); + break; + case Z_MEM_ERROR: + if (outfile > 2) unlink(outname); + fprintf(stderr, "gun out of memory error--aborting\n"); + return 1; + case Z_BUF_ERROR: + if (outfile > 2) unlink(outname); + if (strm->next_in != Z_NULL) { + fprintf(stderr, "gun write error on %s: %s\n", + outname, strerror(errno)); + } + else if (errno) { + fprintf(stderr, "gun read error on %s: %s\n", + inname, strerror(errno)); + } + else { + fprintf(stderr, "gun unexpected end of file on %s\n", + inname); + } + break; + default: + if (outfile > 2) unlink(outname); + fprintf(stderr, "gun internal error--aborting\n"); + return 1; + } + return 0; +} + +/* Process the gun command line arguments. See the command syntax near the + beginning of this source file. */ +int main(int argc, char **argv) +{ + int ret, len, test; + char *outname; + unsigned char *window; + z_stream strm; + + /* initialize inflateBack state for repeated use */ + window = match; /* reuse LZW match buffer */ + strm.zalloc = Z_NULL; + strm.zfree = Z_NULL; + strm.opaque = Z_NULL; + ret = inflateBackInit(&strm, 15, window); + if (ret != Z_OK) { + fprintf(stderr, "gun out of memory error--aborting\n"); + return 1; + } + + /* decompress each file to the same name with the suffix removed */ + argc--; + argv++; + test = 0; + if (argc && strcmp(*argv, "-h") == 0) { + fprintf(stderr, "gun 1.6 (17 Jan 2010)\n"); + fprintf(stderr, "Copyright (C) 2003-2010 Mark Adler\n"); + fprintf(stderr, "usage: gun [-t] [file1.gz [file2.Z ...]]\n"); + return 0; + } + if (argc && strcmp(*argv, "-t") == 0) { + test = 1; + argc--; + argv++; + } + if (argc) + do { + if (test) + outname = NULL; + else { + len = (int)strlen(*argv); + if (strcmp(*argv + len - 3, ".gz") == 0 || + strcmp(*argv + len - 3, "-gz") == 0) + len -= 3; + else if (strcmp(*argv + len - 2, ".z") == 0 || + strcmp(*argv + len - 2, "-z") == 0 || + strcmp(*argv + len - 2, "_z") == 0 || + strcmp(*argv + len - 2, ".Z") == 0) + len -= 2; + else { + fprintf(stderr, "gun error: no gz type on %s--skipping\n", + *argv); + continue; + } + outname = malloc(len + 1); + if (outname == NULL) { + fprintf(stderr, "gun out of memory error--aborting\n"); + ret = 1; + break; + } + memcpy(outname, *argv, len); + outname[len] = 0; + } + ret = gunzip(&strm, *argv, outname, test); + if (outname != NULL) free(outname); + if (ret) break; + } while (argv++, --argc); + else + ret = gunzip(&strm, NULL, NULL, test); + + /* clean up */ + inflateBackEnd(&strm); + return ret; +} diff --git a/libs/zlib/examples/gzappend.c b/libs/zlib/examples/gzappend.c new file mode 100644 index 000000000..e9e878e11 --- /dev/null +++ b/libs/zlib/examples/gzappend.c @@ -0,0 +1,500 @@ +/* gzappend -- command to append to a gzip file + + Copyright (C) 2003 Mark Adler, all rights reserved + version 1.1, 4 Nov 2003 + + This software is provided 'as-is', without any express or implied + warranty. In no event will the author be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Mark Adler madler@alumni.caltech.edu + */ + +/* + * Change history: + * + * 1.0 19 Oct 2003 - First version + * 1.1 4 Nov 2003 - Expand and clarify some comments and notes + * - Add version and copyright to help + * - Send help to stdout instead of stderr + * - Add some preemptive typecasts + * - Add L to constants in lseek() calls + * - Remove some debugging information in error messages + * - Use new data_type definition for zlib 1.2.1 + * - Simplfy and unify file operations + * - Finish off gzip file in gztack() + * - Use deflatePrime() instead of adding empty blocks + * - Keep gzip file clean on appended file read errors + * - Use in-place rotate instead of auxiliary buffer + * (Why you ask? Because it was fun to write!) + */ + +/* + gzappend takes a gzip file and appends to it, compressing files from the + command line or data from stdin. The gzip file is written to directly, to + avoid copying that file, in case it's large. Note that this results in the + unfriendly behavior that if gzappend fails, the gzip file is corrupted. + + This program was written to illustrate the use of the new Z_BLOCK option of + zlib 1.2.x's inflate() function. This option returns from inflate() at each + block boundary to facilitate locating and modifying the last block bit at + the start of the final deflate block. Also whether using Z_BLOCK or not, + another required feature of zlib 1.2.x is that inflate() now provides the + number of unusued bits in the last input byte used. gzappend will not work + with versions of zlib earlier than 1.2.1. + + gzappend first decompresses the gzip file internally, discarding all but + the last 32K of uncompressed data, and noting the location of the last block + bit and the number of unused bits in the last byte of the compressed data. + The gzip trailer containing the CRC-32 and length of the uncompressed data + is verified. This trailer will be later overwritten. + + Then the last block bit is cleared by seeking back in the file and rewriting + the byte that contains it. Seeking forward, the last byte of the compressed + data is saved along with the number of unused bits to initialize deflate. + + A deflate process is initialized, using the last 32K of the uncompressed + data from the gzip file to initialize the dictionary. If the total + uncompressed data was less than 32K, then all of it is used to initialize + the dictionary. The deflate output bit buffer is also initialized with the + last bits from the original deflate stream. From here on, the data to + append is simply compressed using deflate, and written to the gzip file. + When that is complete, the new CRC-32 and uncompressed length are written + as the trailer of the gzip file. + */ + +#include +#include +#include +#include +#include +#include "zlib.h" + +#define local static +#define LGCHUNK 14 +#define CHUNK (1U << LGCHUNK) +#define DSIZE 32768U + +/* print an error message and terminate with extreme prejudice */ +local void bye(char *msg1, char *msg2) +{ + fprintf(stderr, "gzappend error: %s%s\n", msg1, msg2); + exit(1); +} + +/* return the greatest common divisor of a and b using Euclid's algorithm, + modified to be fast when one argument much greater than the other, and + coded to avoid unnecessary swapping */ +local unsigned gcd(unsigned a, unsigned b) +{ + unsigned c; + + while (a && b) + if (a > b) { + c = b; + while (a - c >= c) + c <<= 1; + a -= c; + } + else { + c = a; + while (b - c >= c) + c <<= 1; + b -= c; + } + return a + b; +} + +/* rotate list[0..len-1] left by rot positions, in place */ +local void rotate(unsigned char *list, unsigned len, unsigned rot) +{ + unsigned char tmp; + unsigned cycles; + unsigned char *start, *last, *to, *from; + + /* normalize rot and handle degenerate cases */ + if (len < 2) return; + if (rot >= len) rot %= len; + if (rot == 0) return; + + /* pointer to last entry in list */ + last = list + (len - 1); + + /* do simple left shift by one */ + if (rot == 1) { + tmp = *list; + memcpy(list, list + 1, len - 1); + *last = tmp; + return; + } + + /* do simple right shift by one */ + if (rot == len - 1) { + tmp = *last; + memmove(list + 1, list, len - 1); + *list = tmp; + return; + } + + /* otherwise do rotate as a set of cycles in place */ + cycles = gcd(len, rot); /* number of cycles */ + do { + start = from = list + cycles; /* start index is arbitrary */ + tmp = *from; /* save entry to be overwritten */ + for (;;) { + to = from; /* next step in cycle */ + from += rot; /* go right rot positions */ + if (from > last) from -= len; /* (pointer better not wrap) */ + if (from == start) break; /* all but one shifted */ + *to = *from; /* shift left */ + } + *to = tmp; /* complete the circle */ + } while (--cycles); +} + +/* structure for gzip file read operations */ +typedef struct { + int fd; /* file descriptor */ + int size; /* 1 << size is bytes in buf */ + unsigned left; /* bytes available at next */ + unsigned char *buf; /* buffer */ + unsigned char *next; /* next byte in buffer */ + char *name; /* file name for error messages */ +} file; + +/* reload buffer */ +local int readin(file *in) +{ + int len; + + len = read(in->fd, in->buf, 1 << in->size); + if (len == -1) bye("error reading ", in->name); + in->left = (unsigned)len; + in->next = in->buf; + return len; +} + +/* read from file in, exit if end-of-file */ +local int readmore(file *in) +{ + if (readin(in) == 0) bye("unexpected end of ", in->name); + return 0; +} + +#define read1(in) (in->left == 0 ? readmore(in) : 0, \ + in->left--, *(in->next)++) + +/* skip over n bytes of in */ +local void skip(file *in, unsigned n) +{ + unsigned bypass; + + if (n > in->left) { + n -= in->left; + bypass = n & ~((1U << in->size) - 1); + if (bypass) { + if (lseek(in->fd, (off_t)bypass, SEEK_CUR) == -1) + bye("seeking ", in->name); + n -= bypass; + } + readmore(in); + if (n > in->left) + bye("unexpected end of ", in->name); + } + in->left -= n; + in->next += n; +} + +/* read a four-byte unsigned integer, little-endian, from in */ +unsigned long read4(file *in) +{ + unsigned long val; + + val = read1(in); + val += (unsigned)read1(in) << 8; + val += (unsigned long)read1(in) << 16; + val += (unsigned long)read1(in) << 24; + return val; +} + +/* skip over gzip header */ +local void gzheader(file *in) +{ + int flags; + unsigned n; + + if (read1(in) != 31 || read1(in) != 139) bye(in->name, " not a gzip file"); + if (read1(in) != 8) bye("unknown compression method in", in->name); + flags = read1(in); + if (flags & 0xe0) bye("unknown header flags set in", in->name); + skip(in, 6); + if (flags & 4) { + n = read1(in); + n += (unsigned)(read1(in)) << 8; + skip(in, n); + } + if (flags & 8) while (read1(in) != 0) ; + if (flags & 16) while (read1(in) != 0) ; + if (flags & 2) skip(in, 2); +} + +/* decompress gzip file "name", return strm with a deflate stream ready to + continue compression of the data in the gzip file, and return a file + descriptor pointing to where to write the compressed data -- the deflate + stream is initialized to compress using level "level" */ +local int gzscan(char *name, z_stream *strm, int level) +{ + int ret, lastbit, left, full; + unsigned have; + unsigned long crc, tot; + unsigned char *window; + off_t lastoff, end; + file gz; + + /* open gzip file */ + gz.name = name; + gz.fd = open(name, O_RDWR, 0); + if (gz.fd == -1) bye("cannot open ", name); + gz.buf = malloc(CHUNK); + if (gz.buf == NULL) bye("out of memory", ""); + gz.size = LGCHUNK; + gz.left = 0; + + /* skip gzip header */ + gzheader(&gz); + + /* prepare to decompress */ + window = malloc(DSIZE); + if (window == NULL) bye("out of memory", ""); + strm->zalloc = Z_NULL; + strm->zfree = Z_NULL; + strm->opaque = Z_NULL; + ret = inflateInit2(strm, -15); + if (ret != Z_OK) bye("out of memory", " or library mismatch"); + + /* decompress the deflate stream, saving append information */ + lastbit = 0; + lastoff = lseek(gz.fd, 0L, SEEK_CUR) - gz.left; + left = 0; + strm->avail_in = gz.left; + strm->next_in = gz.next; + crc = crc32(0L, Z_NULL, 0); + have = full = 0; + do { + /* if needed, get more input */ + if (strm->avail_in == 0) { + readmore(&gz); + strm->avail_in = gz.left; + strm->next_in = gz.next; + } + + /* set up output to next available section of sliding window */ + strm->avail_out = DSIZE - have; + strm->next_out = window + have; + + /* inflate and check for errors */ + ret = inflate(strm, Z_BLOCK); + if (ret == Z_STREAM_ERROR) bye("internal stream error!", ""); + if (ret == Z_MEM_ERROR) bye("out of memory", ""); + if (ret == Z_DATA_ERROR) + bye("invalid compressed data--format violated in", name); + + /* update crc and sliding window pointer */ + crc = crc32(crc, window + have, DSIZE - have - strm->avail_out); + if (strm->avail_out) + have = DSIZE - strm->avail_out; + else { + have = 0; + full = 1; + } + + /* process end of block */ + if (strm->data_type & 128) { + if (strm->data_type & 64) + left = strm->data_type & 0x1f; + else { + lastbit = strm->data_type & 0x1f; + lastoff = lseek(gz.fd, 0L, SEEK_CUR) - strm->avail_in; + } + } + } while (ret != Z_STREAM_END); + inflateEnd(strm); + gz.left = strm->avail_in; + gz.next = strm->next_in; + + /* save the location of the end of the compressed data */ + end = lseek(gz.fd, 0L, SEEK_CUR) - gz.left; + + /* check gzip trailer and save total for deflate */ + if (crc != read4(&gz)) + bye("invalid compressed data--crc mismatch in ", name); + tot = strm->total_out; + if ((tot & 0xffffffffUL) != read4(&gz)) + bye("invalid compressed data--length mismatch in", name); + + /* if not at end of file, warn */ + if (gz.left || readin(&gz)) + fprintf(stderr, + "gzappend warning: junk at end of gzip file overwritten\n"); + + /* clear last block bit */ + lseek(gz.fd, lastoff - (lastbit != 0), SEEK_SET); + if (read(gz.fd, gz.buf, 1) != 1) bye("reading after seek on ", name); + *gz.buf = (unsigned char)(*gz.buf ^ (1 << ((8 - lastbit) & 7))); + lseek(gz.fd, -1L, SEEK_CUR); + if (write(gz.fd, gz.buf, 1) != 1) bye("writing after seek to ", name); + + /* if window wrapped, build dictionary from window by rotating */ + if (full) { + rotate(window, DSIZE, have); + have = DSIZE; + } + + /* set up deflate stream with window, crc, total_in, and leftover bits */ + ret = deflateInit2(strm, level, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY); + if (ret != Z_OK) bye("out of memory", ""); + deflateSetDictionary(strm, window, have); + strm->adler = crc; + strm->total_in = tot; + if (left) { + lseek(gz.fd, --end, SEEK_SET); + if (read(gz.fd, gz.buf, 1) != 1) bye("reading after seek on ", name); + deflatePrime(strm, 8 - left, *gz.buf); + } + lseek(gz.fd, end, SEEK_SET); + + /* clean up and return */ + free(window); + free(gz.buf); + return gz.fd; +} + +/* append file "name" to gzip file gd using deflate stream strm -- if last + is true, then finish off the deflate stream at the end */ +local void gztack(char *name, int gd, z_stream *strm, int last) +{ + int fd, len, ret; + unsigned left; + unsigned char *in, *out; + + /* open file to compress and append */ + fd = 0; + if (name != NULL) { + fd = open(name, O_RDONLY, 0); + if (fd == -1) + fprintf(stderr, "gzappend warning: %s not found, skipping ...\n", + name); + } + + /* allocate buffers */ + in = fd == -1 ? NULL : malloc(CHUNK); + out = malloc(CHUNK); + if (out == NULL) bye("out of memory", ""); + + /* compress input file and append to gzip file */ + do { + /* get more input */ + len = fd == -1 ? 0 : read(fd, in, CHUNK); + if (len == -1) { + fprintf(stderr, + "gzappend warning: error reading %s, skipping rest ...\n", + name); + len = 0; + } + strm->avail_in = (unsigned)len; + strm->next_in = in; + if (len) strm->adler = crc32(strm->adler, in, (unsigned)len); + + /* compress and write all available output */ + do { + strm->avail_out = CHUNK; + strm->next_out = out; + ret = deflate(strm, last && len == 0 ? Z_FINISH : Z_NO_FLUSH); + left = CHUNK - strm->avail_out; + while (left) { + len = write(gd, out + CHUNK - strm->avail_out - left, left); + if (len == -1) bye("writing gzip file", ""); + left -= (unsigned)len; + } + } while (strm->avail_out == 0 && ret != Z_STREAM_END); + } while (len != 0); + + /* write trailer after last entry */ + if (last) { + deflateEnd(strm); + out[0] = (unsigned char)(strm->adler); + out[1] = (unsigned char)(strm->adler >> 8); + out[2] = (unsigned char)(strm->adler >> 16); + out[3] = (unsigned char)(strm->adler >> 24); + out[4] = (unsigned char)(strm->total_in); + out[5] = (unsigned char)(strm->total_in >> 8); + out[6] = (unsigned char)(strm->total_in >> 16); + out[7] = (unsigned char)(strm->total_in >> 24); + len = 8; + do { + ret = write(gd, out + 8 - len, len); + if (ret == -1) bye("writing gzip file", ""); + len -= ret; + } while (len); + close(gd); + } + + /* clean up and return */ + free(out); + if (in != NULL) free(in); + if (fd > 0) close(fd); +} + +/* process the compression level option if present, scan the gzip file, and + append the specified files, or append the data from stdin if no other file + names are provided on the command line -- the gzip file must be writable + and seekable */ +int main(int argc, char **argv) +{ + int gd, level; + z_stream strm; + + /* ignore command name */ + argv++; + + /* provide usage if no arguments */ + if (*argv == NULL) { + printf("gzappend 1.1 (4 Nov 2003) Copyright (C) 2003 Mark Adler\n"); + printf( + "usage: gzappend [-level] file.gz [ addthis [ andthis ... ]]\n"); + return 0; + } + + /* set compression level */ + level = Z_DEFAULT_COMPRESSION; + if (argv[0][0] == '-') { + if (argv[0][1] < '0' || argv[0][1] > '9' || argv[0][2] != 0) + bye("invalid compression level", ""); + level = argv[0][1] - '0'; + if (*++argv == NULL) bye("no gzip file name after options", ""); + } + + /* prepare to append to gzip file */ + gd = gzscan(*argv++, &strm, level); + + /* append files on command line, or from stdin if none */ + if (*argv == NULL) + gztack(NULL, gd, &strm, 1); + else + do { + gztack(*argv, gd, &strm, argv[1] == NULL); + } while (*++argv != NULL); + return 0; +} diff --git a/libs/zlib/examples/gzjoin.c b/libs/zlib/examples/gzjoin.c new file mode 100644 index 000000000..129347ce3 --- /dev/null +++ b/libs/zlib/examples/gzjoin.c @@ -0,0 +1,448 @@ +/* gzjoin -- command to join gzip files into one gzip file + + Copyright (C) 2004 Mark Adler, all rights reserved + version 1.0, 11 Dec 2004 + + This software is provided 'as-is', without any express or implied + warranty. In no event will the author be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Mark Adler madler@alumni.caltech.edu + */ + +/* + * Change history: + * + * 1.0 11 Dec 2004 - First version + * 1.1 12 Jun 2005 - Changed ssize_t to long for portability + */ + +/* + gzjoin takes one or more gzip files on the command line and writes out a + single gzip file that will uncompress to the concatenation of the + uncompressed data from the individual gzip files. gzjoin does this without + having to recompress any of the data and without having to calculate a new + crc32 for the concatenated uncompressed data. gzjoin does however have to + decompress all of the input data in order to find the bits in the compressed + data that need to be modified to concatenate the streams. + + gzjoin does not do an integrity check on the input gzip files other than + checking the gzip header and decompressing the compressed data. They are + otherwise assumed to be complete and correct. + + Each joint between gzip files removes at least 18 bytes of previous trailer + and subsequent header, and inserts an average of about three bytes to the + compressed data in order to connect the streams. The output gzip file + has a minimal ten-byte gzip header with no file name or modification time. + + This program was written to illustrate the use of the Z_BLOCK option of + inflate() and the crc32_combine() function. gzjoin will not compile with + versions of zlib earlier than 1.2.3. + */ + +#include /* fputs(), fprintf(), fwrite(), putc() */ +#include /* exit(), malloc(), free() */ +#include /* open() */ +#include /* close(), read(), lseek() */ +#include "zlib.h" + /* crc32(), crc32_combine(), inflateInit2(), inflate(), inflateEnd() */ + +#define local static + +/* exit with an error (return a value to allow use in an expression) */ +local int bail(char *why1, char *why2) +{ + fprintf(stderr, "gzjoin error: %s%s, output incomplete\n", why1, why2); + exit(1); + return 0; +} + +/* -- simple buffered file input with access to the buffer -- */ + +#define CHUNK 32768 /* must be a power of two and fit in unsigned */ + +/* bin buffered input file type */ +typedef struct { + char *name; /* name of file for error messages */ + int fd; /* file descriptor */ + unsigned left; /* bytes remaining at next */ + unsigned char *next; /* next byte to read */ + unsigned char *buf; /* allocated buffer of length CHUNK */ +} bin; + +/* close a buffered file and free allocated memory */ +local void bclose(bin *in) +{ + if (in != NULL) { + if (in->fd != -1) + close(in->fd); + if (in->buf != NULL) + free(in->buf); + free(in); + } +} + +/* open a buffered file for input, return a pointer to type bin, or NULL on + failure */ +local bin *bopen(char *name) +{ + bin *in; + + in = malloc(sizeof(bin)); + if (in == NULL) + return NULL; + in->buf = malloc(CHUNK); + in->fd = open(name, O_RDONLY, 0); + if (in->buf == NULL || in->fd == -1) { + bclose(in); + return NULL; + } + in->left = 0; + in->next = in->buf; + in->name = name; + return in; +} + +/* load buffer from file, return -1 on read error, 0 or 1 on success, with + 1 indicating that end-of-file was reached */ +local int bload(bin *in) +{ + long len; + + if (in == NULL) + return -1; + if (in->left != 0) + return 0; + in->next = in->buf; + do { + len = (long)read(in->fd, in->buf + in->left, CHUNK - in->left); + if (len < 0) + return -1; + in->left += (unsigned)len; + } while (len != 0 && in->left < CHUNK); + return len == 0 ? 1 : 0; +} + +/* get a byte from the file, bail if end of file */ +#define bget(in) (in->left ? 0 : bload(in), \ + in->left ? (in->left--, *(in->next)++) : \ + bail("unexpected end of file on ", in->name)) + +/* get a four-byte little-endian unsigned integer from file */ +local unsigned long bget4(bin *in) +{ + unsigned long val; + + val = bget(in); + val += (unsigned long)(bget(in)) << 8; + val += (unsigned long)(bget(in)) << 16; + val += (unsigned long)(bget(in)) << 24; + return val; +} + +/* skip bytes in file */ +local void bskip(bin *in, unsigned skip) +{ + /* check pointer */ + if (in == NULL) + return; + + /* easy case -- skip bytes in buffer */ + if (skip <= in->left) { + in->left -= skip; + in->next += skip; + return; + } + + /* skip what's in buffer, discard buffer contents */ + skip -= in->left; + in->left = 0; + + /* seek past multiples of CHUNK bytes */ + if (skip > CHUNK) { + unsigned left; + + left = skip & (CHUNK - 1); + if (left == 0) { + /* exact number of chunks: seek all the way minus one byte to check + for end-of-file with a read */ + lseek(in->fd, skip - 1, SEEK_CUR); + if (read(in->fd, in->buf, 1) != 1) + bail("unexpected end of file on ", in->name); + return; + } + + /* skip the integral chunks, update skip with remainder */ + lseek(in->fd, skip - left, SEEK_CUR); + skip = left; + } + + /* read more input and skip remainder */ + bload(in); + if (skip > in->left) + bail("unexpected end of file on ", in->name); + in->left -= skip; + in->next += skip; +} + +/* -- end of buffered input functions -- */ + +/* skip the gzip header from file in */ +local void gzhead(bin *in) +{ + int flags; + + /* verify gzip magic header and compression method */ + if (bget(in) != 0x1f || bget(in) != 0x8b || bget(in) != 8) + bail(in->name, " is not a valid gzip file"); + + /* get and verify flags */ + flags = bget(in); + if ((flags & 0xe0) != 0) + bail("unknown reserved bits set in ", in->name); + + /* skip modification time, extra flags, and os */ + bskip(in, 6); + + /* skip extra field if present */ + if (flags & 4) { + unsigned len; + + len = bget(in); + len += (unsigned)(bget(in)) << 8; + bskip(in, len); + } + + /* skip file name if present */ + if (flags & 8) + while (bget(in) != 0) + ; + + /* skip comment if present */ + if (flags & 16) + while (bget(in) != 0) + ; + + /* skip header crc if present */ + if (flags & 2) + bskip(in, 2); +} + +/* write a four-byte little-endian unsigned integer to out */ +local void put4(unsigned long val, FILE *out) +{ + putc(val & 0xff, out); + putc((val >> 8) & 0xff, out); + putc((val >> 16) & 0xff, out); + putc((val >> 24) & 0xff, out); +} + +/* Load up zlib stream from buffered input, bail if end of file */ +local void zpull(z_streamp strm, bin *in) +{ + if (in->left == 0) + bload(in); + if (in->left == 0) + bail("unexpected end of file on ", in->name); + strm->avail_in = in->left; + strm->next_in = in->next; +} + +/* Write header for gzip file to out and initialize trailer. */ +local void gzinit(unsigned long *crc, unsigned long *tot, FILE *out) +{ + fwrite("\x1f\x8b\x08\0\0\0\0\0\0\xff", 1, 10, out); + *crc = crc32(0L, Z_NULL, 0); + *tot = 0; +} + +/* Copy the compressed data from name, zeroing the last block bit of the last + block if clr is true, and adding empty blocks as needed to get to a byte + boundary. If clr is false, then the last block becomes the last block of + the output, and the gzip trailer is written. crc and tot maintains the + crc and length (modulo 2^32) of the output for the trailer. The resulting + gzip file is written to out. gzinit() must be called before the first call + of gzcopy() to write the gzip header and to initialize crc and tot. */ +local void gzcopy(char *name, int clr, unsigned long *crc, unsigned long *tot, + FILE *out) +{ + int ret; /* return value from zlib functions */ + int pos; /* where the "last block" bit is in byte */ + int last; /* true if processing the last block */ + bin *in; /* buffered input file */ + unsigned char *start; /* start of compressed data in buffer */ + unsigned char *junk; /* buffer for uncompressed data -- discarded */ + z_off_t len; /* length of uncompressed data (support > 4 GB) */ + z_stream strm; /* zlib inflate stream */ + + /* open gzip file and skip header */ + in = bopen(name); + if (in == NULL) + bail("could not open ", name); + gzhead(in); + + /* allocate buffer for uncompressed data and initialize raw inflate + stream */ + junk = malloc(CHUNK); + strm.zalloc = Z_NULL; + strm.zfree = Z_NULL; + strm.opaque = Z_NULL; + strm.avail_in = 0; + strm.next_in = Z_NULL; + ret = inflateInit2(&strm, -15); + if (junk == NULL || ret != Z_OK) + bail("out of memory", ""); + + /* inflate and copy compressed data, clear last-block bit if requested */ + len = 0; + zpull(&strm, in); + start = strm.next_in; + last = start[0] & 1; + if (last && clr) + start[0] &= ~1; + strm.avail_out = 0; + for (;;) { + /* if input used and output done, write used input and get more */ + if (strm.avail_in == 0 && strm.avail_out != 0) { + fwrite(start, 1, strm.next_in - start, out); + start = in->buf; + in->left = 0; + zpull(&strm, in); + } + + /* decompress -- return early when end-of-block reached */ + strm.avail_out = CHUNK; + strm.next_out = junk; + ret = inflate(&strm, Z_BLOCK); + switch (ret) { + case Z_MEM_ERROR: + bail("out of memory", ""); + case Z_DATA_ERROR: + bail("invalid compressed data in ", in->name); + } + + /* update length of uncompressed data */ + len += CHUNK - strm.avail_out; + + /* check for block boundary (only get this when block copied out) */ + if (strm.data_type & 128) { + /* if that was the last block, then done */ + if (last) + break; + + /* number of unused bits in last byte */ + pos = strm.data_type & 7; + + /* find the next last-block bit */ + if (pos != 0) { + /* next last-block bit is in last used byte */ + pos = 0x100 >> pos; + last = strm.next_in[-1] & pos; + if (last && clr) + strm.next_in[-1] &= ~pos; + } + else { + /* next last-block bit is in next unused byte */ + if (strm.avail_in == 0) { + /* don't have that byte yet -- get it */ + fwrite(start, 1, strm.next_in - start, out); + start = in->buf; + in->left = 0; + zpull(&strm, in); + } + last = strm.next_in[0] & 1; + if (last && clr) + strm.next_in[0] &= ~1; + } + } + } + + /* update buffer with unused input */ + in->left = strm.avail_in; + in->next = strm.next_in; + + /* copy used input, write empty blocks to get to byte boundary */ + pos = strm.data_type & 7; + fwrite(start, 1, in->next - start - 1, out); + last = in->next[-1]; + if (pos == 0 || !clr) + /* already at byte boundary, or last file: write last byte */ + putc(last, out); + else { + /* append empty blocks to last byte */ + last &= ((0x100 >> pos) - 1); /* assure unused bits are zero */ + if (pos & 1) { + /* odd -- append an empty stored block */ + putc(last, out); + if (pos == 1) + putc(0, out); /* two more bits in block header */ + fwrite("\0\0\xff\xff", 1, 4, out); + } + else { + /* even -- append 1, 2, or 3 empty fixed blocks */ + switch (pos) { + case 6: + putc(last | 8, out); + last = 0; + case 4: + putc(last | 0x20, out); + last = 0; + case 2: + putc(last | 0x80, out); + putc(0, out); + } + } + } + + /* update crc and tot */ + *crc = crc32_combine(*crc, bget4(in), len); + *tot += (unsigned long)len; + + /* clean up */ + inflateEnd(&strm); + free(junk); + bclose(in); + + /* write trailer if this is the last gzip file */ + if (!clr) { + put4(*crc, out); + put4(*tot, out); + } +} + +/* join the gzip files on the command line, write result to stdout */ +int main(int argc, char **argv) +{ + unsigned long crc, tot; /* running crc and total uncompressed length */ + + /* skip command name */ + argc--; + argv++; + + /* show usage if no arguments */ + if (argc == 0) { + fputs("gzjoin usage: gzjoin f1.gz [f2.gz [f3.gz ...]] > fjoin.gz\n", + stderr); + return 0; + } + + /* join gzip files on command line and write to stdout */ + gzinit(&crc, &tot, stdout); + while (argc--) + gzcopy(*argv++, argc, &crc, &tot, stdout); + + /* done */ + return 0; +} diff --git a/libs/zlib/examples/gzlog.c b/libs/zlib/examples/gzlog.c new file mode 100644 index 000000000..d70aacaba --- /dev/null +++ b/libs/zlib/examples/gzlog.c @@ -0,0 +1,1058 @@ +/* + * gzlog.c + * Copyright (C) 2004, 2008 Mark Adler, all rights reserved + * For conditions of distribution and use, see copyright notice in gzlog.h + * version 2.0, 25 Apr 2008 + */ + +/* + gzlog provides a mechanism for frequently appending short strings to a gzip + file that is efficient both in execution time and compression ratio. The + strategy is to write the short strings in an uncompressed form to the end of + the gzip file, only compressing when the amount of uncompressed data has + reached a given threshold. + + gzlog also provides protection against interruptions in the process due to + system crashes. The status of the operation is recorded in an extra field + in the gzip file, and is only updated once the gzip file is brought to a + valid state. The last data to be appended or compressed is saved in an + auxiliary file, so that if the operation is interrupted, it can be completed + the next time an append operation is attempted. + + gzlog maintains another auxiliary file with the last 32K of data from the + compressed portion, which is preloaded for the compression of the subsequent + data. This minimizes the impact to the compression ratio of appending. + */ + +/* + Operations Concept: + + Files (log name "foo"): + foo.gz -- gzip file with the complete log + foo.add -- last message to append or last data to compress + foo.dict -- dictionary of the last 32K of data for next compression + foo.temp -- temporary dictionary file for compression after this one + foo.lock -- lock file for reading and writing the other files + foo.repairs -- log file for log file recovery operations (not compressed) + + gzip file structure: + - fixed-length (no file name) header with extra field (see below) + - compressed data ending initially with empty stored block + - uncompressed data filling out originally empty stored block and + subsequent stored blocks as needed (16K max each) + - gzip trailer + - no junk at end (no other gzip streams) + + When appending data, the information in the first three items above plus the + foo.add file are sufficient to recover an interrupted append operation. The + extra field has the necessary information to restore the start of the last + stored block and determine where to append the data in the foo.add file, as + well as the crc and length of the gzip data before the append operation. + + The foo.add file is created before the gzip file is marked for append, and + deleted after the gzip file is marked as complete. So if the append + operation is interrupted, the data to add will still be there. If due to + some external force, the foo.add file gets deleted between when the append + operation was interrupted and when recovery is attempted, the gzip file will + still be restored, but without the appended data. + + When compressing data, the information in the first two items above plus the + foo.add file are sufficient to recover an interrupted compress operation. + The extra field has the necessary information to find the end of the + compressed data, and contains both the crc and length of just the compressed + data and of the complete set of data including the contents of the foo.add + file. + + Again, the foo.add file is maintained during the compress operation in case + of an interruption. If in the unlikely event the foo.add file with the data + to be compressed is missing due to some external force, a gzip file with + just the previous compressed data will be reconstructed. In this case, all + of the data that was to be compressed is lost (approximately one megabyte). + This will not occur if all that happened was an interruption of the compress + operation. + + The third state that is marked is the replacement of the old dictionary with + the new dictionary after a compress operation. Once compression is + complete, the gzip file is marked as being in the replace state. This + completes the gzip file, so an interrupt after being so marked does not + result in recompression. Then the dictionary file is replaced, and the gzip + file is marked as completed. This state prevents the possibility of + restarting compression with the wrong dictionary file. + + All three operations are wrapped by a lock/unlock procedure. In order to + gain exclusive access to the log files, first a foo.lock file must be + exclusively created. When all operations are complete, the lock is + released by deleting the foo.lock file. If when attempting to create the + lock file, it already exists and the modify time of the lock file is more + than five minutes old (set by the PATIENCE define below), then the old + lock file is considered stale and deleted, and the exclusive creation of + the lock file is retried. To assure that there are no false assessments + of the staleness of the lock file, the operations periodically touch the + lock file to update the modified date. + + Following is the definition of the extra field with all of the information + required to enable the above append and compress operations and their + recovery if interrupted. Multi-byte values are stored little endian + (consistent with the gzip format). File pointers are eight bytes long. + The crc's and lengths for the gzip trailer are four bytes long. (Note that + the length at the end of a gzip file is used for error checking only, and + for large files is actually the length modulo 2^32.) The stored block + length is two bytes long. The gzip extra field two-byte identification is + "ap" for append. It is assumed that writing the extra field to the file is + an "atomic" operation. That is, either all of the extra field is written + to the file, or none of it is, if the operation is interrupted right at the + point of updating the extra field. This is a reasonable assumption, since + the extra field is within the first 52 bytes of the file, which is smaller + than any expected block size for a mass storage device (usually 512 bytes or + larger). + + Extra field (35 bytes): + - Pointer to first stored block length -- this points to the two-byte length + of the first stored block, which is followed by the two-byte, one's + complement of that length. The stored block length is preceded by the + three-bit header of the stored block, which is the actual start of the + stored block in the deflate format. See the bit offset field below. + - Pointer to the last stored block length. This is the same as above, but + for the last stored block of the uncompressed data in the gzip file. + Initially this is the same as the first stored block length pointer. + When the stored block gets to 16K (see the MAX_STORE define), then a new + stored block as added, at which point the last stored block length pointer + is different from the first stored block length pointer. When they are + different, the first bit of the last stored block header is eight bits, or + one byte back from the block length. + - Compressed data crc and length. This is the crc and length of the data + that is in the compressed portion of the deflate stream. These are used + only in the event that the foo.add file containing the data to compress is + lost after a compress operation is interrupted. + - Total data crc and length. This is the crc and length of all of the data + stored in the gzip file, compressed and uncompressed. It is used to + reconstruct the gzip trailer when compressing, as well as when recovering + interrupted operations. + - Final stored block length. This is used to quickly find where to append, + and allows the restoration of the original final stored block state when + an append operation is interrupted. + - First stored block start as the number of bits back from the final stored + block first length byte. This value is in the range of 3..10, and is + stored as the low three bits of the final byte of the extra field after + subtracting three (0..7). This allows the last-block bit of the stored + block header to be updated when a new stored block is added, for the case + when the first stored block and the last stored block are the same. (When + they are different, the numbers of bits back is known to be eight.) This + also allows for new compressed data to be appended to the old compressed + data in the compress operation, overwriting the previous first stored + block, or for the compressed data to be terminated and a valid gzip file + reconstructed on the off chance that a compression operation was + interrupted and the data to compress in the foo.add file was deleted. + - The operation in process. This is the next two bits in the last byte (the + bits under the mask 0x18). The are interpreted as 0: nothing in process, + 1: append in process, 2: compress in process, 3: replace in process. + - The top three bits of the last byte in the extra field are reserved and + are currently set to zero. + + Main procedure: + - Exclusively create the foo.lock file using the O_CREAT and O_EXCL modes of + the system open() call. If the modify time of an existing lock file is + more than PATIENCE seconds old, then the lock file is deleted and the + exclusive create is retried. + - Load the extra field from the foo.gz file, and see if an operation was in + progress but not completed. If so, apply the recovery procedure below. + - Perform the append procedure with the provided data. + - If the uncompressed data in the foo.gz file is 1MB or more, apply the + compress procedure. + - Delete the foo.lock file. + + Append procedure: + - Put what to append in the foo.add file so that the operation can be + restarted if this procedure is interrupted. + - Mark the foo.gz extra field with the append operation in progress. + + Restore the original last-block bit and stored block length of the last + stored block from the information in the extra field, in case a previous + append operation was interrupted. + - Append the provided data to the last stored block, creating new stored + blocks as needed and updating the stored blocks last-block bits and + lengths. + - Update the crc and length with the new data, and write the gzip trailer. + - Write over the extra field (with a single write operation) with the new + pointers, lengths, and crc's, and mark the gzip file as not in process. + Though there is still a foo.add file, it will be ignored since nothing + is in process. If a foo.add file is leftover from a previously + completed operation, it is truncated when writing new data to it. + - Delete the foo.add file. + + Compress and replace procedures: + - Read all of the uncompressed data in the stored blocks in foo.gz and write + it to foo.add. Also write foo.temp with the last 32K of that data to + provide a dictionary for the next invocation of this procedure. + - Rewrite the extra field marking foo.gz with a compression in process. + * If there is no data provided to compress (due to a missing foo.add file + when recovering), reconstruct and truncate the foo.gz file to contain + only the previous compressed data and proceed to the step after the next + one. Otherwise ... + - Compress the data with the dictionary in foo.dict, and write to the + foo.gz file starting at the bit immediately following the last previously + compressed block. If there is no foo.dict, proceed anyway with the + compression at slightly reduced efficiency. (For the foo.dict file to be + missing requires some external failure beyond simply the interruption of + a compress operation.) During this process, the foo.lock file is + periodically touched to assure that that file is not considered stale by + another process before we're done. The deflation is terminated with a + non-last empty static block (10 bits long), that is then located and + written over by a last-bit-set empty stored block. + - Append the crc and length of the data in the gzip file (previously + calculated during the append operations). + - Write over the extra field with the updated stored block offsets, bits + back, crc's, and lengths, and mark foo.gz as in process for a replacement + of the dictionary. + @ Delete the foo.add file. + - Replace foo.dict with foo.temp. + - Write over the extra field, marking foo.gz as complete. + + Recovery procedure: + - If not a replace recovery, read in the foo.add file, and provide that data + to the appropriate recovery below. If there is no foo.add file, provide + a zero data length to the recovery. In that case, the append recovery + restores the foo.gz to the previous compressed + uncompressed data state. + For the the compress recovery, a missing foo.add file results in foo.gz + being restored to the previous compressed-only data state. + - Append recovery: + - Pick up append at + step above + - Compress recovery: + - Pick up compress at * step above + - Replace recovery: + - Pick up compress at @ step above + - Log the repair with a date stamp in foo.repairs + */ + +#include +#include /* rename, fopen, fprintf, fclose */ +#include /* malloc, free */ +#include /* strlen, strrchr, strcpy, strncpy, strcmp */ +#include /* open */ +#include /* lseek, read, write, close, unlink, sleep, */ + /* ftruncate, fsync */ +#include /* errno */ +#include /* time, ctime */ +#include /* stat */ +#include /* utimes */ +#include "zlib.h" /* crc32 */ + +#include "gzlog.h" /* header for external access */ + +#define local static +typedef unsigned int uint; +typedef unsigned long ulong; + +/* Macro for debugging to deterministically force recovery operations */ +#ifdef DEBUG + #include /* longjmp */ + jmp_buf gzlog_jump; /* where to go back to */ + int gzlog_bail = 0; /* which point to bail at (1..8) */ + int gzlog_count = -1; /* number of times through to wait */ +# define BAIL(n) do { if (n == gzlog_bail && gzlog_count-- == 0) \ + longjmp(gzlog_jump, gzlog_bail); } while (0) +#else +# define BAIL(n) +#endif + +/* how old the lock file can be in seconds before considering it stale */ +#define PATIENCE 300 + +/* maximum stored block size in Kbytes -- must be in 1..63 */ +#define MAX_STORE 16 + +/* number of stored Kbytes to trigger compression (must be >= 32 to allow + dictionary construction, and <= 204 * MAX_STORE, in order for >> 10 to + discard the stored block headers contribution of five bytes each) */ +#define TRIGGER 1024 + +/* size of a deflate dictionary (this cannot be changed) */ +#define DICT 32768U + +/* values for the operation (2 bits) */ +#define NO_OP 0 +#define APPEND_OP 1 +#define COMPRESS_OP 2 +#define REPLACE_OP 3 + +/* macros to extract little-endian integers from an unsigned byte buffer */ +#define PULL2(p) ((p)[0]+((uint)((p)[1])<<8)) +#define PULL4(p) (PULL2(p)+((ulong)PULL2(p+2)<<16)) +#define PULL8(p) (PULL4(p)+((off_t)PULL4(p+4)<<32)) + +/* macros to store integers into a byte buffer in little-endian order */ +#define PUT2(p,a) do {(p)[0]=a;(p)[1]=(a)>>8;} while(0) +#define PUT4(p,a) do {PUT2(p,a);PUT2(p+2,a>>16);} while(0) +#define PUT8(p,a) do {PUT4(p,a);PUT4(p+4,a>>32);} while(0) + +/* internal structure for log information */ +#define LOGID "\106\035\172" /* should be three non-zero characters */ +struct log { + char id[4]; /* contains LOGID to detect inadvertent overwrites */ + int fd; /* file descriptor for .gz file, opened read/write */ + char *path; /* allocated path, e.g. "/var/log/foo" or "foo" */ + char *end; /* end of path, for appending suffices such as ".gz" */ + off_t first; /* offset of first stored block first length byte */ + int back; /* location of first block id in bits back from first */ + uint stored; /* bytes currently in last stored block */ + off_t last; /* offset of last stored block first length byte */ + ulong ccrc; /* crc of compressed data */ + ulong clen; /* length (modulo 2^32) of compressed data */ + ulong tcrc; /* crc of total data */ + ulong tlen; /* length (modulo 2^32) of total data */ + time_t lock; /* last modify time of our lock file */ +}; + +/* gzip header for gzlog */ +local unsigned char log_gzhead[] = { + 0x1f, 0x8b, /* magic gzip id */ + 8, /* compression method is deflate */ + 4, /* there is an extra field (no file name) */ + 0, 0, 0, 0, /* no modification time provided */ + 0, 0xff, /* no extra flags, no OS specified */ + 39, 0, 'a', 'p', 35, 0 /* extra field with "ap" subfield */ + /* 35 is EXTRA, 39 is EXTRA + 4 */ +}; + +#define HEAD sizeof(log_gzhead) /* should be 16 */ + +/* initial gzip extra field content (52 == HEAD + EXTRA + 1) */ +local unsigned char log_gzext[] = { + 52, 0, 0, 0, 0, 0, 0, 0, /* offset of first stored block length */ + 52, 0, 0, 0, 0, 0, 0, 0, /* offset of last stored block length */ + 0, 0, 0, 0, 0, 0, 0, 0, /* compressed data crc and length */ + 0, 0, 0, 0, 0, 0, 0, 0, /* total data crc and length */ + 0, 0, /* final stored block data length */ + 5 /* op is NO_OP, last bit 8 bits back */ +}; + +#define EXTRA sizeof(log_gzext) /* should be 35 */ + +/* initial gzip data and trailer */ +local unsigned char log_gzbody[] = { + 1, 0, 0, 0xff, 0xff, /* empty stored block (last) */ + 0, 0, 0, 0, /* crc */ + 0, 0, 0, 0 /* uncompressed length */ +}; + +#define BODY sizeof(log_gzbody) + +/* Exclusively create foo.lock in order to negotiate exclusive access to the + foo.* files. If the modify time of an existing lock file is greater than + PATIENCE seconds in the past, then consider the lock file to have been + abandoned, delete it, and try the exclusive create again. Save the lock + file modify time for verification of ownership. Return 0 on success, or -1 + on failure, usually due to an access restriction or invalid path. Note that + if stat() or unlink() fails, it may be due to another process noticing the + abandoned lock file a smidge sooner and deleting it, so those are not + flagged as an error. */ +local int log_lock(struct log *log) +{ + int fd; + struct stat st; + + strcpy(log->end, ".lock"); + while ((fd = open(log->path, O_CREAT | O_EXCL, 0644)) < 0) { + if (errno != EEXIST) + return -1; + if (stat(log->path, &st) == 0 && time(NULL) - st.st_mtime > PATIENCE) { + unlink(log->path); + continue; + } + sleep(2); /* relinquish the CPU for two seconds while waiting */ + } + close(fd); + if (stat(log->path, &st) == 0) + log->lock = st.st_mtime; + return 0; +} + +/* Update the modify time of the lock file to now, in order to prevent another + task from thinking that the lock is stale. Save the lock file modify time + for verification of ownership. */ +local void log_touch(struct log *log) +{ + struct stat st; + + strcpy(log->end, ".lock"); + utimes(log->path, NULL); + if (stat(log->path, &st) == 0) + log->lock = st.st_mtime; +} + +/* Check the log file modify time against what is expected. Return true if + this is not our lock. If it is our lock, touch it to keep it. */ +local int log_check(struct log *log) +{ + struct stat st; + + strcpy(log->end, ".lock"); + if (stat(log->path, &st) || st.st_mtime != log->lock) + return 1; + log_touch(log); + return 0; +} + +/* Unlock a previously acquired lock, but only if it's ours. */ +local void log_unlock(struct log *log) +{ + if (log_check(log)) + return; + strcpy(log->end, ".lock"); + unlink(log->path); + log->lock = 0; +} + +/* Check the gzip header and read in the extra field, filling in the values in + the log structure. Return op on success or -1 if the gzip header was not as + expected. op is the current operation in progress last written to the extra + field. This assumes that the gzip file has already been opened, with the + file descriptor log->fd. */ +local int log_head(struct log *log) +{ + int op; + unsigned char buf[HEAD + EXTRA]; + + if (lseek(log->fd, 0, SEEK_SET) < 0 || + read(log->fd, buf, HEAD + EXTRA) != HEAD + EXTRA || + memcmp(buf, log_gzhead, HEAD)) { + return -1; + } + log->first = PULL8(buf + HEAD); + log->last = PULL8(buf + HEAD + 8); + log->ccrc = PULL4(buf + HEAD + 16); + log->clen = PULL4(buf + HEAD + 20); + log->tcrc = PULL4(buf + HEAD + 24); + log->tlen = PULL4(buf + HEAD + 28); + log->stored = PULL2(buf + HEAD + 32); + log->back = 3 + (buf[HEAD + 34] & 7); + op = (buf[HEAD + 34] >> 3) & 3; + return op; +} + +/* Write over the extra field contents, marking the operation as op. Use fsync + to assure that the device is written to, and in the requested order. This + operation, and only this operation, is assumed to be atomic in order to + assure that the log is recoverable in the event of an interruption at any + point in the process. Return -1 if the write to foo.gz failed. */ +local int log_mark(struct log *log, int op) +{ + int ret; + unsigned char ext[EXTRA]; + + PUT8(ext, log->first); + PUT8(ext + 8, log->last); + PUT4(ext + 16, log->ccrc); + PUT4(ext + 20, log->clen); + PUT4(ext + 24, log->tcrc); + PUT4(ext + 28, log->tlen); + PUT2(ext + 32, log->stored); + ext[34] = log->back - 3 + (op << 3); + fsync(log->fd); + ret = lseek(log->fd, HEAD, SEEK_SET) < 0 || + write(log->fd, ext, EXTRA) != EXTRA ? -1 : 0; + fsync(log->fd); + return ret; +} + +/* Rewrite the last block header bits and subsequent zero bits to get to a byte + boundary, setting the last block bit if last is true, and then write the + remainder of the stored block header (length and one's complement). Leave + the file pointer after the end of the last stored block data. Return -1 if + there is a read or write failure on the foo.gz file */ +local int log_last(struct log *log, int last) +{ + int back, len, mask; + unsigned char buf[6]; + + /* determine the locations of the bytes and bits to modify */ + back = log->last == log->first ? log->back : 8; + len = back > 8 ? 2 : 1; /* bytes back from log->last */ + mask = 0x80 >> ((back - 1) & 7); /* mask for block last-bit */ + + /* get the byte to modify (one or two back) into buf[0] -- don't need to + read the byte if the last-bit is eight bits back, since in that case + the entire byte will be modified */ + buf[0] = 0; + if (back != 8 && (lseek(log->fd, log->last - len, SEEK_SET) < 0 || + read(log->fd, buf, 1) != 1)) + return -1; + + /* change the last-bit of the last stored block as requested -- note + that all bits above the last-bit are set to zero, per the type bits + of a stored block being 00 and per the convention that the bits to + bring the stream to a byte boundary are also zeros */ + buf[1] = 0; + buf[2 - len] = (*buf & (mask - 1)) + (last ? mask : 0); + + /* write the modified stored block header and lengths, move the file + pointer to after the last stored block data */ + PUT2(buf + 2, log->stored); + PUT2(buf + 4, log->stored ^ 0xffff); + return lseek(log->fd, log->last - len, SEEK_SET) < 0 || + write(log->fd, buf + 2 - len, len + 4) != len + 4 || + lseek(log->fd, log->stored, SEEK_CUR) < 0 ? -1 : 0; +} + +/* Append len bytes from data to the locked and open log file. len may be zero + if recovering and no .add file was found. In that case, the previous state + of the foo.gz file is restored. The data is appended uncompressed in + deflate stored blocks. Return -1 if there was an error reading or writing + the foo.gz file. */ +local int log_append(struct log *log, unsigned char *data, size_t len) +{ + uint put; + off_t end; + unsigned char buf[8]; + + /* set the last block last-bit and length, in case recovering an + interrupted append, then position the file pointer to append to the + block */ + if (log_last(log, 1)) + return -1; + + /* append, adding stored blocks and updating the offset of the last stored + block as needed, and update the total crc and length */ + while (len) { + /* append as much as we can to the last block */ + put = (MAX_STORE << 10) - log->stored; + if (put > len) + put = (uint)len; + if (put) { + if (write(log->fd, data, put) != put) + return -1; + BAIL(1); + log->tcrc = crc32(log->tcrc, data, put); + log->tlen += put; + log->stored += put; + data += put; + len -= put; + } + + /* if we need to, add a new empty stored block */ + if (len) { + /* mark current block as not last */ + if (log_last(log, 0)) + return -1; + + /* point to new, empty stored block */ + log->last += 4 + log->stored + 1; + log->stored = 0; + } + + /* mark last block as last, update its length */ + if (log_last(log, 1)) + return -1; + BAIL(2); + } + + /* write the new crc and length trailer, and truncate just in case (could + be recovering from partial append with a missing foo.add file) */ + PUT4(buf, log->tcrc); + PUT4(buf + 4, log->tlen); + if (write(log->fd, buf, 8) != 8 || + (end = lseek(log->fd, 0, SEEK_CUR)) < 0 || ftruncate(log->fd, end)) + return -1; + + /* write the extra field, marking the log file as done, delete .add file */ + if (log_mark(log, NO_OP)) + return -1; + strcpy(log->end, ".add"); + unlink(log->path); /* ignore error, since may not exist */ + return 0; +} + +/* Replace the foo.dict file with the foo.temp file. Also delete the foo.add + file, since the compress operation may have been interrupted before that was + done. Returns 1 if memory could not be allocated, or -1 if reading or + writing foo.gz fails, or if the rename fails for some reason other than + foo.temp not existing. foo.temp not existing is a permitted error, since + the replace operation may have been interrupted after the rename is done, + but before foo.gz is marked as complete. */ +local int log_replace(struct log *log) +{ + int ret; + char *dest; + + /* delete foo.add file */ + strcpy(log->end, ".add"); + unlink(log->path); /* ignore error, since may not exist */ + BAIL(3); + + /* rename foo.name to foo.dict, replacing foo.dict if it exists */ + strcpy(log->end, ".dict"); + dest = malloc(strlen(log->path) + 1); + if (dest == NULL) + return -2; + strcpy(dest, log->path); + strcpy(log->end, ".temp"); + ret = rename(log->path, dest); + free(dest); + if (ret && errno != ENOENT) + return -1; + BAIL(4); + + /* mark the foo.gz file as done */ + return log_mark(log, NO_OP); +} + +/* Compress the len bytes at data and append the compressed data to the + foo.gz deflate data immediately after the previous compressed data. This + overwrites the previous uncompressed data, which was stored in foo.add + and is the data provided in data[0..len-1]. If this operation is + interrupted, it picks up at the start of this routine, with the foo.add + file read in again. If there is no data to compress (len == 0), then we + simply terminate the foo.gz file after the previously compressed data, + appending a final empty stored block and the gzip trailer. Return -1 if + reading or writing the log.gz file failed, or -2 if there was a memory + allocation failure. */ +local int log_compress(struct log *log, unsigned char *data, size_t len) +{ + int fd; + uint got, max; + ssize_t dict; + off_t end; + z_stream strm; + unsigned char buf[DICT]; + + /* compress and append compressed data */ + if (len) { + /* set up for deflate, allocating memory */ + strm.zalloc = Z_NULL; + strm.zfree = Z_NULL; + strm.opaque = Z_NULL; + if (deflateInit2(&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, -15, 8, + Z_DEFAULT_STRATEGY) != Z_OK) + return -2; + + /* read in dictionary (last 32K of data that was compressed) */ + strcpy(log->end, ".dict"); + fd = open(log->path, O_RDONLY, 0); + if (fd >= 0) { + dict = read(fd, buf, DICT); + close(fd); + if (dict < 0) { + deflateEnd(&strm); + return -1; + } + if (dict) + deflateSetDictionary(&strm, buf, (uint)dict); + } + log_touch(log); + + /* prime deflate with last bits of previous block, position write + pointer to write those bits and overwrite what follows */ + if (lseek(log->fd, log->first - (log->back > 8 ? 2 : 1), + SEEK_SET) < 0 || + read(log->fd, buf, 1) != 1 || lseek(log->fd, -1, SEEK_CUR) < 0) { + deflateEnd(&strm); + return -1; + } + deflatePrime(&strm, (8 - log->back) & 7, *buf); + + /* compress, finishing with a partial non-last empty static block */ + strm.next_in = data; + max = (((uint)0 - 1) >> 1) + 1; /* in case int smaller than size_t */ + do { + strm.avail_in = len > max ? max : (uint)len; + len -= strm.avail_in; + do { + strm.avail_out = DICT; + strm.next_out = buf; + deflate(&strm, len ? Z_NO_FLUSH : Z_PARTIAL_FLUSH); + got = DICT - strm.avail_out; + if (got && write(log->fd, buf, got) != got) { + deflateEnd(&strm); + return -1; + } + log_touch(log); + } while (strm.avail_out == 0); + } while (len); + deflateEnd(&strm); + BAIL(5); + + /* find start of empty static block -- scanning backwards the first one + bit is the second bit of the block, if the last byte is zero, then + we know the byte before that has a one in the top bit, since an + empty static block is ten bits long */ + if ((log->first = lseek(log->fd, -1, SEEK_CUR)) < 0 || + read(log->fd, buf, 1) != 1) + return -1; + log->first++; + if (*buf) { + log->back = 1; + while ((*buf & ((uint)1 << (8 - log->back++))) == 0) + ; /* guaranteed to terminate, since *buf != 0 */ + } + else + log->back = 10; + + /* update compressed crc and length */ + log->ccrc = log->tcrc; + log->clen = log->tlen; + } + else { + /* no data to compress -- fix up existing gzip stream */ + log->tcrc = log->ccrc; + log->tlen = log->clen; + } + + /* complete and truncate gzip stream */ + log->last = log->first; + log->stored = 0; + PUT4(buf, log->tcrc); + PUT4(buf + 4, log->tlen); + if (log_last(log, 1) || write(log->fd, buf, 8) != 8 || + (end = lseek(log->fd, 0, SEEK_CUR)) < 0 || ftruncate(log->fd, end)) + return -1; + BAIL(6); + + /* mark as being in the replace operation */ + if (log_mark(log, REPLACE_OP)) + return -1; + + /* execute the replace operation and mark the file as done */ + return log_replace(log); +} + +/* log a repair record to the .repairs file */ +local void log_log(struct log *log, int op, char *record) +{ + time_t now; + FILE *rec; + + now = time(NULL); + strcpy(log->end, ".repairs"); + rec = fopen(log->path, "a"); + if (rec == NULL) + return; + fprintf(rec, "%.24s %s recovery: %s\n", ctime(&now), op == APPEND_OP ? + "append" : (op == COMPRESS_OP ? "compress" : "replace"), record); + fclose(rec); + return; +} + +/* Recover the interrupted operation op. First read foo.add for recovering an + append or compress operation. Return -1 if there was an error reading or + writing foo.gz or reading an existing foo.add, or -2 if there was a memory + allocation failure. */ +local int log_recover(struct log *log, int op) +{ + int fd, ret = 0; + unsigned char *data = NULL; + size_t len = 0; + struct stat st; + + /* log recovery */ + log_log(log, op, "start"); + + /* load foo.add file if expected and present */ + if (op == APPEND_OP || op == COMPRESS_OP) { + strcpy(log->end, ".add"); + if (stat(log->path, &st) == 0 && st.st_size) { + len = (size_t)(st.st_size); + if (len != st.st_size || (data = malloc(st.st_size)) == NULL) { + log_log(log, op, "allocation failure"); + return -2; + } + if ((fd = open(log->path, O_RDONLY, 0)) < 0) { + log_log(log, op, ".add file read failure"); + return -1; + } + ret = read(fd, data, len) != len; + close(fd); + if (ret) { + log_log(log, op, ".add file read failure"); + return -1; + } + log_log(log, op, "loaded .add file"); + } + else + log_log(log, op, "missing .add file!"); + } + + /* recover the interrupted operation */ + switch (op) { + case APPEND_OP: + ret = log_append(log, data, len); + break; + case COMPRESS_OP: + ret = log_compress(log, data, len); + break; + case REPLACE_OP: + ret = log_replace(log); + } + + /* log status */ + log_log(log, op, ret ? "failure" : "complete"); + + /* clean up */ + if (data != NULL) + free(data); + return ret; +} + +/* Close the foo.gz file (if open) and release the lock. */ +local void log_close(struct log *log) +{ + if (log->fd >= 0) + close(log->fd); + log->fd = -1; + log_unlock(log); +} + +/* Open foo.gz, verify the header, and load the extra field contents, after + first creating the foo.lock file to gain exclusive access to the foo.* + files. If foo.gz does not exist or is empty, then write the initial header, + extra, and body content of an empty foo.gz log file. If there is an error + creating the lock file due to access restrictions, or an error reading or + writing the foo.gz file, or if the foo.gz file is not a proper log file for + this object (e.g. not a gzip file or does not contain the expected extra + field), then return true. If there is an error, the lock is released. + Otherwise, the lock is left in place. */ +local int log_open(struct log *log) +{ + int op; + + /* release open file resource if left over -- can occur if lock lost + between gzlog_open() and gzlog_write() */ + if (log->fd >= 0) + close(log->fd); + log->fd = -1; + + /* negotiate exclusive access */ + if (log_lock(log) < 0) + return -1; + + /* open the log file, foo.gz */ + strcpy(log->end, ".gz"); + log->fd = open(log->path, O_RDWR | O_CREAT, 0644); + if (log->fd < 0) { + log_close(log); + return -1; + } + + /* if new, initialize foo.gz with an empty log, delete old dictionary */ + if (lseek(log->fd, 0, SEEK_END) == 0) { + if (write(log->fd, log_gzhead, HEAD) != HEAD || + write(log->fd, log_gzext, EXTRA) != EXTRA || + write(log->fd, log_gzbody, BODY) != BODY) { + log_close(log); + return -1; + } + strcpy(log->end, ".dict"); + unlink(log->path); + } + + /* verify log file and load extra field information */ + if ((op = log_head(log)) < 0) { + log_close(log); + return -1; + } + + /* check for interrupted process and if so, recover */ + if (op != NO_OP && log_recover(log, op)) { + log_close(log); + return -1; + } + + /* touch the lock file to prevent another process from grabbing it */ + log_touch(log); + return 0; +} + +/* See gzlog.h for the description of the external methods below */ +gzlog *gzlog_open(char *path) +{ + size_t n; + struct log *log; + + /* check arguments */ + if (path == NULL || *path == 0) + return NULL; + + /* allocate and initialize log structure */ + log = malloc(sizeof(struct log)); + if (log == NULL) + return NULL; + strcpy(log->id, LOGID); + log->fd = -1; + + /* save path and end of path for name construction */ + n = strlen(path); + log->path = malloc(n + 9); /* allow for ".repairs" */ + if (log->path == NULL) { + free(log); + return NULL; + } + strcpy(log->path, path); + log->end = log->path + n; + + /* gain exclusive access and verify log file -- may perform a + recovery operation if needed */ + if (log_open(log)) { + free(log->path); + free(log); + return NULL; + } + + /* return pointer to log structure */ + return log; +} + +/* gzlog_compress() return values: + 0: all good + -1: file i/o error (usually access issue) + -2: memory allocation failure + -3: invalid log pointer argument */ +int gzlog_compress(gzlog *logd) +{ + int fd, ret; + uint block; + size_t len, next; + unsigned char *data, buf[5]; + struct log *log = logd; + + /* check arguments */ + if (log == NULL || strcmp(log->id, LOGID) || len < 0) + return -3; + + /* see if we lost the lock -- if so get it again and reload the extra + field information (it probably changed), recover last operation if + necessary */ + if (log_check(log) && log_open(log)) + return -1; + + /* create space for uncompressed data */ + len = ((size_t)(log->last - log->first) & ~(((size_t)1 << 10) - 1)) + + log->stored; + if ((data = malloc(len)) == NULL) + return -2; + + /* do statement here is just a cheap trick for error handling */ + do { + /* read in the uncompressed data */ + if (lseek(log->fd, log->first - 1, SEEK_SET) < 0) + break; + next = 0; + while (next < len) { + if (read(log->fd, buf, 5) != 5) + break; + block = PULL2(buf + 1); + if (next + block > len || + read(log->fd, (char *)data + next, block) != block) + break; + next += block; + } + if (lseek(log->fd, 0, SEEK_CUR) != log->last + 4 + log->stored) + break; + log_touch(log); + + /* write the uncompressed data to the .add file */ + strcpy(log->end, ".add"); + fd = open(log->path, O_WRONLY | O_CREAT | O_TRUNC, 0644); + if (fd < 0) + break; + ret = write(fd, data, len) != len; + if (ret | close(fd)) + break; + log_touch(log); + + /* write the dictionary for the next compress to the .temp file */ + strcpy(log->end, ".temp"); + fd = open(log->path, O_WRONLY | O_CREAT | O_TRUNC, 0644); + if (fd < 0) + break; + next = DICT > len ? len : DICT; + ret = write(fd, (char *)data + len - next, next) != next; + if (ret | close(fd)) + break; + log_touch(log); + + /* roll back to compressed data, mark the compress in progress */ + log->last = log->first; + log->stored = 0; + if (log_mark(log, COMPRESS_OP)) + break; + BAIL(7); + + /* compress and append the data (clears mark) */ + ret = log_compress(log, data, len); + free(data); + return ret; + } while (0); + + /* broke out of do above on i/o error */ + free(data); + return -1; +} + +/* gzlog_write() return values: + 0: all good + -1: file i/o error (usually access issue) + -2: memory allocation failure + -3: invalid log pointer argument */ +int gzlog_write(gzlog *logd, void *data, size_t len) +{ + int fd, ret; + struct log *log = logd; + + /* check arguments */ + if (log == NULL || strcmp(log->id, LOGID) || len < 0) + return -3; + if (data == NULL || len == 0) + return 0; + + /* see if we lost the lock -- if so get it again and reload the extra + field information (it probably changed), recover last operation if + necessary */ + if (log_check(log) && log_open(log)) + return -1; + + /* create and write .add file */ + strcpy(log->end, ".add"); + fd = open(log->path, O_WRONLY | O_CREAT | O_TRUNC, 0644); + if (fd < 0) + return -1; + ret = write(fd, data, len) != len; + if (ret | close(fd)) + return -1; + log_touch(log); + + /* mark log file with append in progress */ + if (log_mark(log, APPEND_OP)) + return -1; + BAIL(8); + + /* append data (clears mark) */ + if (log_append(log, data, len)) + return -1; + + /* check to see if it's time to compress -- if not, then done */ + if (((log->last - log->first) >> 10) + (log->stored >> 10) < TRIGGER) + return 0; + + /* time to compress */ + return gzlog_compress(log); +} + +/* gzlog_close() return values: + 0: ok + -3: invalid log pointer argument */ +int gzlog_close(gzlog *logd) +{ + struct log *log = logd; + + /* check arguments */ + if (log == NULL || strcmp(log->id, LOGID)) + return -3; + + /* close the log file and release the lock */ + log_close(log); + + /* free structure and return */ + if (log->path != NULL) + free(log->path); + strcpy(log->id, "bad"); + free(log); + return 0; +} diff --git a/libs/zlib/examples/gzlog.h b/libs/zlib/examples/gzlog.h new file mode 100644 index 000000000..c46142673 --- /dev/null +++ b/libs/zlib/examples/gzlog.h @@ -0,0 +1,89 @@ +/* gzlog.h + Copyright (C) 2004, 2008 Mark Adler, all rights reserved + version 2.0, 25 Apr 2008 + + This software is provided 'as-is', without any express or implied + warranty. In no event will the author be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Mark Adler madler@alumni.caltech.edu + */ + +/* Version History: + 1.0 26 Nov 2004 First version + 2.0 25 Apr 2008 Complete redesign for recovery of interrupted operations + Interface changed slightly in that now path is a prefix + Compression now occurs as needed during gzlog_write() + gzlog_write() now always leaves the log file as valid gzip + */ + +/* + The gzlog object allows writing short messages to a gzipped log file, + opening the log file locked for small bursts, and then closing it. The log + object works by appending stored (uncompressed) data to the gzip file until + 1 MB has been accumulated. At that time, the stored data is compressed, and + replaces the uncompressed data in the file. The log file is truncated to + its new size at that time. After each write operation, the log file is a + valid gzip file that can decompressed to recover what was written. + + The gzlog operations can be interupted at any point due to an application or + system crash, and the log file will be recovered the next time the log is + opened with gzlog_open(). + */ + +#ifndef GZLOG_H +#define GZLOG_H + +/* gzlog object type */ +typedef void gzlog; + +/* Open a gzlog object, creating the log file if it does not exist. Return + NULL on error. Note that gzlog_open() could take a while to complete if it + has to wait to verify that a lock is stale (possibly for five minutes), or + if there is significant contention with other instantiations of this object + when locking the resource. path is the prefix of the file names created by + this object. If path is "foo", then the log file will be "foo.gz", and + other auxiliary files will be created and destroyed during the process: + "foo.dict" for a compression dictionary, "foo.temp" for a temporary (next) + dictionary, "foo.add" for data being added or compressed, "foo.lock" for the + lock file, and "foo.repairs" to log recovery operations performed due to + interrupted gzlog operations. A gzlog_open() followed by a gzlog_close() + will recover a previously interrupted operation, if any. */ +gzlog *gzlog_open(char *path); + +/* Write to a gzlog object. Return zero on success, -1 if there is a file i/o + error on any of the gzlog files (this should not happen if gzlog_open() + succeeded, unless the device has run out of space or leftover auxiliary + files have permissions or ownership that prevent their use), -2 if there is + a memory allocation failure, or -3 if the log argument is invalid (e.g. if + it was not created by gzlog_open()). This function will write data to the + file uncompressed, until 1 MB has been accumulated, at which time that data + will be compressed. The log file will be a valid gzip file upon successful + return. */ +int gzlog_write(gzlog *log, void *data, size_t len); + +/* Force compression of any uncompressed data in the log. This should be used + sparingly, if at all. The main application would be when a log file will + not be appended to again. If this is used to compress frequently while + appending, it will both significantly increase the execution time and + reduce the compression ratio. The return codes are the same as for + gzlog_write(). */ +int gzlog_compress(gzlog *log); + +/* Close a gzlog object. Return zero on success, -3 if the log argument is + invalid. The log object is freed, and so cannot be referenced again. */ +int gzlog_close(gzlog *log); + +#endif diff --git a/libs/zlib/examples/zlib_how.html b/libs/zlib/examples/zlib_how.html new file mode 100644 index 000000000..444ff1c9a --- /dev/null +++ b/libs/zlib/examples/zlib_how.html @@ -0,0 +1,545 @@ + + + + +zlib Usage Example + + + +

zlib Usage Example

+We often get questions about how the deflate() and inflate() functions should be used. +Users wonder when they should provide more input, when they should use more output, +what to do with a Z_BUF_ERROR, how to make sure the process terminates properly, and +so on. So for those who have read zlib.h (a few times), and +would like further edification, below is an annotated example in C of simple routines to compress and decompress +from an input file to an output file using deflate() and inflate() respectively. The +annotations are interspersed between lines of the code. So please read between the lines. +We hope this helps explain some of the intricacies of zlib. +

+Without further adieu, here is the program zpipe.c: +


+/* zpipe.c: example of proper use of zlib's inflate() and deflate()
+   Not copyrighted -- provided to the public domain
+   Version 1.4  11 December 2005  Mark Adler */
+
+/* Version history:
+   1.0  30 Oct 2004  First version
+   1.1   8 Nov 2004  Add void casting for unused return values
+                     Use switch statement for inflate() return values
+   1.2   9 Nov 2004  Add assertions to document zlib guarantees
+   1.3   6 Apr 2005  Remove incorrect assertion in inf()
+   1.4  11 Dec 2005  Add hack to avoid MSDOS end-of-line conversions
+                     Avoid some compiler warnings for input and output buffers
+ */
+
+We now include the header files for the required definitions. From +stdio.h we use fopen(), fread(), fwrite(), +feof(), ferror(), and fclose() for file i/o, and +fputs() for error messages. From string.h we use +strcmp() for command line argument processing. +From assert.h we use the assert() macro. +From zlib.h +we use the basic compression functions deflateInit(), +deflate(), and deflateEnd(), and the basic decompression +functions inflateInit(), inflate(), and +inflateEnd(). +

+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+#include "zlib.h"
+
+This is an ugly hack required to avoid corruption of the input and output data on +Windows/MS-DOS systems. Without this, those systems would assume that the input and output +files are text, and try to convert the end-of-line characters from one standard to +another. That would corrupt binary data, and in particular would render the compressed data unusable. +This sets the input and output to binary which suppresses the end-of-line conversions. +SET_BINARY_MODE() will be used later on stdin and stdout, at the beginning of main(). +

+#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
+#  include <fcntl.h>
+#  include <io.h>
+#  define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
+#else
+#  define SET_BINARY_MODE(file)
+#endif
+
+CHUNK is simply the buffer size for feeding data to and pulling data +from the zlib routines. Larger buffer sizes would be more efficient, +especially for inflate(). If the memory is available, buffers sizes +on the order of 128K or 256K bytes should be used. +

+#define CHUNK 16384
+
+The def() routine compresses data from an input file to an output file. The output data +will be in the zlib format, which is different from the gzip or zip +formats. The zlib format has a very small header of only two bytes to identify it as +a zlib stream and to provide decoding information, and a four-byte trailer with a fast +check value to verify the integrity of the uncompressed data after decoding. +

+/* Compress from file source to file dest until EOF on source.
+   def() returns Z_OK on success, Z_MEM_ERROR if memory could not be
+   allocated for processing, Z_STREAM_ERROR if an invalid compression
+   level is supplied, Z_VERSION_ERROR if the version of zlib.h and the
+   version of the library linked do not match, or Z_ERRNO if there is
+   an error reading or writing the files. */
+int def(FILE *source, FILE *dest, int level)
+{
+
+Here are the local variables for def(). ret will be used for zlib +return codes. flush will keep track of the current flushing state for deflate(), +which is either no flushing, or flush to completion after the end of the input file is reached. +have is the amount of data returned from deflate(). The strm structure +is used to pass information to and from the zlib routines, and to maintain the +deflate() state. in and out are the input and output buffers for +deflate(). +

+    int ret, flush;
+    unsigned have;
+    z_stream strm;
+    unsigned char in[CHUNK];
+    unsigned char out[CHUNK];
+
+The first thing we do is to initialize the zlib state for compression using +deflateInit(). This must be done before the first use of deflate(). +The zalloc, zfree, and opaque fields in the strm +structure must be initialized before calling deflateInit(). Here they are +set to the zlib constant Z_NULL to request that zlib use +the default memory allocation routines. An application may also choose to provide +custom memory allocation routines here. deflateInit() will allocate on the +order of 256K bytes for the internal state. +(See zlib Technical Details.) +

+deflateInit() is called with a pointer to the structure to be initialized and +the compression level, which is an integer in the range of -1 to 9. Lower compression +levels result in faster execution, but less compression. Higher levels result in +greater compression, but slower execution. The zlib constant Z_DEFAULT_COMPRESSION, +equal to -1, +provides a good compromise between compression and speed and is equivalent to level 6. +Level 0 actually does no compression at all, and in fact expands the data slightly to produce +the zlib format (it is not a byte-for-byte copy of the input). +More advanced applications of zlib +may use deflateInit2() here instead. Such an application may want to reduce how +much memory will be used, at some price in compression. Or it may need to request a +gzip header and trailer instead of a zlib header and trailer, or raw +encoding with no header or trailer at all. +

+We must check the return value of deflateInit() against the zlib constant +Z_OK to make sure that it was able to +allocate memory for the internal state, and that the provided arguments were valid. +deflateInit() will also check that the version of zlib that the zlib.h +file came from matches the version of zlib actually linked with the program. This +is especially important for environments in which zlib is a shared library. +

+Note that an application can initialize multiple, independent zlib streams, which can +operate in parallel. The state information maintained in the structure allows the zlib +routines to be reentrant. +


+    /* allocate deflate state */
+    strm.zalloc = Z_NULL;
+    strm.zfree = Z_NULL;
+    strm.opaque = Z_NULL;
+    ret = deflateInit(&strm, level);
+    if (ret != Z_OK)
+        return ret;
+
+With the pleasantries out of the way, now we can get down to business. The outer do-loop +reads all of the input file and exits at the bottom of the loop once end-of-file is reached. +This loop contains the only call of deflate(). So we must make sure that all of the +input data has been processed and that all of the output data has been generated and consumed +before we fall out of the loop at the bottom. +

+    /* compress until end of file */
+    do {
+
+We start off by reading data from the input file. The number of bytes read is put directly +into avail_in, and a pointer to those bytes is put into next_in. We also +check to see if end-of-file on the input has been reached. If we are at the end of file, then flush is set to the +zlib constant Z_FINISH, which is later passed to deflate() to +indicate that this is the last chunk of input data to compress. We need to use feof() +to check for end-of-file as opposed to seeing if fewer than CHUNK bytes have been read. The +reason is that if the input file length is an exact multiple of CHUNK, we will miss +the fact that we got to the end-of-file, and not know to tell deflate() to finish +up the compressed stream. If we are not yet at the end of the input, then the zlib +constant Z_NO_FLUSH will be passed to deflate to indicate that we are still +in the middle of the uncompressed data. +

+If there is an error in reading from the input file, the process is aborted with +deflateEnd() being called to free the allocated zlib state before returning +the error. We wouldn't want a memory leak, now would we? deflateEnd() can be called +at any time after the state has been initialized. Once that's done, deflateInit() (or +deflateInit2()) would have to be called to start a new compression process. There is +no point here in checking the deflateEnd() return code. The deallocation can't fail. +


+        strm.avail_in = fread(in, 1, CHUNK, source);
+        if (ferror(source)) {
+            (void)deflateEnd(&strm);
+            return Z_ERRNO;
+        }
+        flush = feof(source) ? Z_FINISH : Z_NO_FLUSH;
+        strm.next_in = in;
+
+The inner do-loop passes our chunk of input data to deflate(), and then +keeps calling deflate() until it is done producing output. Once there is no more +new output, deflate() is guaranteed to have consumed all of the input, i.e., +avail_in will be zero. +

+        /* run deflate() on input until output buffer not full, finish
+           compression if all of source has been read in */
+        do {
+
+Output space is provided to deflate() by setting avail_out to the number +of available output bytes and next_out to a pointer to that space. +

+            strm.avail_out = CHUNK;
+            strm.next_out = out;
+
+Now we call the compression engine itself, deflate(). It takes as many of the +avail_in bytes at next_in as it can process, and writes as many as +avail_out bytes to next_out. Those counters and pointers are then +updated past the input data consumed and the output data written. It is the amount of +output space available that may limit how much input is consumed. +Hence the inner loop to make sure that +all of the input is consumed by providing more output space each time. Since avail_in +and next_in are updated by deflate(), we don't have to mess with those +between deflate() calls until it's all used up. +

+The parameters to deflate() are a pointer to the strm structure containing +the input and output information and the internal compression engine state, and a parameter +indicating whether and how to flush data to the output. Normally deflate will consume +several K bytes of input data before producing any output (except for the header), in order +to accumulate statistics on the data for optimum compression. It will then put out a burst of +compressed data, and proceed to consume more input before the next burst. Eventually, +deflate() +must be told to terminate the stream, complete the compression with provided input data, and +write out the trailer check value. deflate() will continue to compress normally as long +as the flush parameter is Z_NO_FLUSH. Once the Z_FINISH parameter is provided, +deflate() will begin to complete the compressed output stream. However depending on how +much output space is provided, deflate() may have to be called several times until it +has provided the complete compressed stream, even after it has consumed all of the input. The flush +parameter must continue to be Z_FINISH for those subsequent calls. +

+There are other values of the flush parameter that are used in more advanced applications. You can +force deflate() to produce a burst of output that encodes all of the input data provided +so far, even if it wouldn't have otherwise, for example to control data latency on a link with +compressed data. You can also ask that deflate() do that as well as erase any history up to +that point so that what follows can be decompressed independently, for example for random access +applications. Both requests will degrade compression by an amount depending on how often such +requests are made. +

+deflate() has a return value that can indicate errors, yet we do not check it here. Why +not? Well, it turns out that deflate() can do no wrong here. Let's go through +deflate()'s return values and dispense with them one by one. The possible values are +Z_OK, Z_STREAM_END, Z_STREAM_ERROR, or Z_BUF_ERROR. Z_OK +is, well, ok. Z_STREAM_END is also ok and will be returned for the last call of +deflate(). This is already guaranteed by calling deflate() with Z_FINISH +until it has no more output. Z_STREAM_ERROR is only possible if the stream is not +initialized properly, but we did initialize it properly. There is no harm in checking for +Z_STREAM_ERROR here, for example to check for the possibility that some +other part of the application inadvertently clobbered the memory containing the zlib state. +Z_BUF_ERROR will be explained further below, but +suffice it to say that this is simply an indication that deflate() could not consume +more input or produce more output. deflate() can be called again with more output space +or more available input, which it will be in this code. +


+            ret = deflate(&strm, flush);    /* no bad return value */
+            assert(ret != Z_STREAM_ERROR);  /* state not clobbered */
+
+Now we compute how much output deflate() provided on the last call, which is the +difference between how much space was provided before the call, and how much output space +is still available after the call. Then that data, if any, is written to the output file. +We can then reuse the output buffer for the next call of deflate(). Again if there +is a file i/o error, we call deflateEnd() before returning to avoid a memory leak. +

+            have = CHUNK - strm.avail_out;
+            if (fwrite(out, 1, have, dest) != have || ferror(dest)) {
+                (void)deflateEnd(&strm);
+                return Z_ERRNO;
+            }
+
+The inner do-loop is repeated until the last deflate() call fails to fill the +provided output buffer. Then we know that deflate() has done as much as it can with +the provided input, and that all of that input has been consumed. We can then fall out of this +loop and reuse the input buffer. +

+The way we tell that deflate() has no more output is by seeing that it did not fill +the output buffer, leaving avail_out greater than zero. However suppose that +deflate() has no more output, but just so happened to exactly fill the output buffer! +avail_out is zero, and we can't tell that deflate() has done all it can. +As far as we know, deflate() +has more output for us. So we call it again. But now deflate() produces no output +at all, and avail_out remains unchanged as CHUNK. That deflate() call +wasn't able to do anything, either consume input or produce output, and so it returns +Z_BUF_ERROR. (See, I told you I'd cover this later.) However this is not a problem at +all. Now we finally have the desired indication that deflate() is really done, +and so we drop out of the inner loop to provide more input to deflate(). +

+With flush set to Z_FINISH, this final set of deflate() calls will +complete the output stream. Once that is done, subsequent calls of deflate() would return +Z_STREAM_ERROR if the flush parameter is not Z_FINISH, and do no more processing +until the state is reinitialized. +

+Some applications of zlib have two loops that call deflate() +instead of the single inner loop we have here. The first loop would call +without flushing and feed all of the data to deflate(). The second loop would call +deflate() with no more +data and the Z_FINISH parameter to complete the process. As you can see from this +example, that can be avoided by simply keeping track of the current flush state. +


+        } while (strm.avail_out == 0);
+        assert(strm.avail_in == 0);     /* all input will be used */
+
+Now we check to see if we have already processed all of the input file. That information was +saved in the flush variable, so we see if that was set to Z_FINISH. If so, +then we're done and we fall out of the outer loop. We're guaranteed to get Z_STREAM_END +from the last deflate() call, since we ran it until the last chunk of input was +consumed and all of the output was generated. +

+        /* done when last data in file processed */
+    } while (flush != Z_FINISH);
+    assert(ret == Z_STREAM_END);        /* stream will be complete */
+
+The process is complete, but we still need to deallocate the state to avoid a memory leak +(or rather more like a memory hemorrhage if you didn't do this). Then +finally we can return with a happy return value. +

+    /* clean up and return */
+    (void)deflateEnd(&strm);
+    return Z_OK;
+}
+
+Now we do the same thing for decompression in the inf() routine. inf() +decompresses what is hopefully a valid zlib stream from the input file and writes the +uncompressed data to the output file. Much of the discussion above for def() +applies to inf() as well, so the discussion here will focus on the differences between +the two. +

+/* Decompress from file source to file dest until stream ends or EOF.
+   inf() returns Z_OK on success, Z_MEM_ERROR if memory could not be
+   allocated for processing, Z_DATA_ERROR if the deflate data is
+   invalid or incomplete, Z_VERSION_ERROR if the version of zlib.h and
+   the version of the library linked do not match, or Z_ERRNO if there
+   is an error reading or writing the files. */
+int inf(FILE *source, FILE *dest)
+{
+
+The local variables have the same functionality as they do for def(). The +only difference is that there is no flush variable, since inflate() +can tell from the zlib stream itself when the stream is complete. +

+    int ret;
+    unsigned have;
+    z_stream strm;
+    unsigned char in[CHUNK];
+    unsigned char out[CHUNK];
+
+The initialization of the state is the same, except that there is no compression level, +of course, and two more elements of the structure are initialized. avail_in +and next_in must be initialized before calling inflateInit(). This +is because the application has the option to provide the start of the zlib stream in +order for inflateInit() to have access to information about the compression +method to aid in memory allocation. In the current implementation of zlib +(up through versions 1.2.x), the method-dependent memory allocations are deferred to the first call of +inflate() anyway. However those fields must be initialized since later versions +of zlib that provide more compression methods may take advantage of this interface. +In any case, no decompression is performed by inflateInit(), so the +avail_out and next_out fields do not need to be initialized before calling. +

+Here avail_in is set to zero and next_in is set to Z_NULL to +indicate that no input data is being provided. +


+    /* allocate inflate state */
+    strm.zalloc = Z_NULL;
+    strm.zfree = Z_NULL;
+    strm.opaque = Z_NULL;
+    strm.avail_in = 0;
+    strm.next_in = Z_NULL;
+    ret = inflateInit(&strm);
+    if (ret != Z_OK)
+        return ret;
+
+The outer do-loop decompresses input until inflate() indicates +that it has reached the end of the compressed data and has produced all of the uncompressed +output. This is in contrast to def() which processes all of the input file. +If end-of-file is reached before the compressed data self-terminates, then the compressed +data is incomplete and an error is returned. +

+    /* decompress until deflate stream ends or end of file */
+    do {
+
+We read input data and set the strm structure accordingly. If we've reached the +end of the input file, then we leave the outer loop and report an error, since the +compressed data is incomplete. Note that we may read more data than is eventually consumed +by inflate(), if the input file continues past the zlib stream. +For applications where zlib streams are embedded in other data, this routine would +need to be modified to return the unused data, or at least indicate how much of the input +data was not used, so the application would know where to pick up after the zlib stream. +

+        strm.avail_in = fread(in, 1, CHUNK, source);
+        if (ferror(source)) {
+            (void)inflateEnd(&strm);
+            return Z_ERRNO;
+        }
+        if (strm.avail_in == 0)
+            break;
+        strm.next_in = in;
+
+The inner do-loop has the same function it did in def(), which is to +keep calling inflate() until has generated all of the output it can with the +provided input. +

+        /* run inflate() on input until output buffer not full */
+        do {
+
+Just like in def(), the same output space is provided for each call of inflate(). +

+            strm.avail_out = CHUNK;
+            strm.next_out = out;
+
+Now we run the decompression engine itself. There is no need to adjust the flush parameter, since +the zlib format is self-terminating. The main difference here is that there are +return values that we need to pay attention to. Z_DATA_ERROR +indicates that inflate() detected an error in the zlib compressed data format, +which means that either the data is not a zlib stream to begin with, or that the data was +corrupted somewhere along the way since it was compressed. The other error to be processed is +Z_MEM_ERROR, which can occur since memory allocation is deferred until inflate() +needs it, unlike deflate(), whose memory is allocated at the start by deflateInit(). +

+Advanced applications may use +deflateSetDictionary() to prime deflate() with a set of likely data to improve the +first 32K or so of compression. This is noted in the zlib header, so inflate() +requests that that dictionary be provided before it can start to decompress. Without the dictionary, +correct decompression is not possible. For this routine, we have no idea what the dictionary is, +so the Z_NEED_DICT indication is converted to a Z_DATA_ERROR. +

+inflate() can also return Z_STREAM_ERROR, which should not be possible here, +but could be checked for as noted above for def(). Z_BUF_ERROR does not need to be +checked for here, for the same reasons noted for def(). Z_STREAM_END will be +checked for later. +


+            ret = inflate(&strm, Z_NO_FLUSH);
+            assert(ret != Z_STREAM_ERROR);  /* state not clobbered */
+            switch (ret) {
+            case Z_NEED_DICT:
+                ret = Z_DATA_ERROR;     /* and fall through */
+            case Z_DATA_ERROR:
+            case Z_MEM_ERROR:
+                (void)inflateEnd(&strm);
+                return ret;
+            }
+
+The output of inflate() is handled identically to that of deflate(). +

+            have = CHUNK - strm.avail_out;
+            if (fwrite(out, 1, have, dest) != have || ferror(dest)) {
+                (void)inflateEnd(&strm);
+                return Z_ERRNO;
+            }
+
+The inner do-loop ends when inflate() has no more output as indicated +by not filling the output buffer, just as for deflate(). In this case, we cannot +assert that strm.avail_in will be zero, since the deflate stream may end before the file +does. +

+        } while (strm.avail_out == 0);
+
+The outer do-loop ends when inflate() reports that it has reached the +end of the input zlib stream, has completed the decompression and integrity +check, and has provided all of the output. This is indicated by the inflate() +return value Z_STREAM_END. The inner loop is guaranteed to leave ret +equal to Z_STREAM_END if the last chunk of the input file read contained the end +of the zlib stream. So if the return value is not Z_STREAM_END, the +loop continues to read more input. +

+        /* done when inflate() says it's done */
+    } while (ret != Z_STREAM_END);
+
+At this point, decompression successfully completed, or we broke out of the loop due to no +more data being available from the input file. If the last inflate() return value +is not Z_STREAM_END, then the zlib stream was incomplete and a data error +is returned. Otherwise, we return with a happy return value. Of course, inflateEnd() +is called first to avoid a memory leak. +

+    /* clean up and return */
+    (void)inflateEnd(&strm);
+    return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR;
+}
+
+That ends the routines that directly use zlib. The following routines make this +a command-line program by running data through the above routines from stdin to +stdout, and handling any errors reported by def() or inf(). +

+zerr() is used to interpret the possible error codes from def() +and inf(), as detailed in their comments above, and print out an error message. +Note that these are only a subset of the possible return values from deflate() +and inflate(). +


+/* report a zlib or i/o error */
+void zerr(int ret)
+{
+    fputs("zpipe: ", stderr);
+    switch (ret) {
+    case Z_ERRNO:
+        if (ferror(stdin))
+            fputs("error reading stdin\n", stderr);
+        if (ferror(stdout))
+            fputs("error writing stdout\n", stderr);
+        break;
+    case Z_STREAM_ERROR:
+        fputs("invalid compression level\n", stderr);
+        break;
+    case Z_DATA_ERROR:
+        fputs("invalid or incomplete deflate data\n", stderr);
+        break;
+    case Z_MEM_ERROR:
+        fputs("out of memory\n", stderr);
+        break;
+    case Z_VERSION_ERROR:
+        fputs("zlib version mismatch!\n", stderr);
+    }
+}
+
+Here is the main() routine used to test def() and inf(). The +zpipe command is simply a compression pipe from stdin to stdout, if +no arguments are given, or it is a decompression pipe if zpipe -d is used. If any other +arguments are provided, no compression or decompression is performed. Instead a usage +message is displayed. Examples are zpipe < foo.txt > foo.txt.z to compress, and +zpipe -d < foo.txt.z > foo.txt to decompress. +

+/* compress or decompress from stdin to stdout */
+int main(int argc, char **argv)
+{
+    int ret;
+
+    /* avoid end-of-line conversions */
+    SET_BINARY_MODE(stdin);
+    SET_BINARY_MODE(stdout);
+
+    /* do compression if no arguments */
+    if (argc == 1) {
+        ret = def(stdin, stdout, Z_DEFAULT_COMPRESSION);
+        if (ret != Z_OK)
+            zerr(ret);
+        return ret;
+    }
+
+    /* do decompression if -d specified */
+    else if (argc == 2 && strcmp(argv[1], "-d") == 0) {
+        ret = inf(stdin, stdout);
+        if (ret != Z_OK)
+            zerr(ret);
+        return ret;
+    }
+
+    /* otherwise, report usage */
+    else {
+        fputs("zpipe usage: zpipe [-d] < source > dest\n", stderr);
+        return 1;
+    }
+}
+
+
+Copyright (c) 2004, 2005 by Mark Adler
Last modified 11 December 2005
+ + diff --git a/libs/zlib/examples/zpipe.c b/libs/zlib/examples/zpipe.c new file mode 100644 index 000000000..83535d169 --- /dev/null +++ b/libs/zlib/examples/zpipe.c @@ -0,0 +1,205 @@ +/* zpipe.c: example of proper use of zlib's inflate() and deflate() + Not copyrighted -- provided to the public domain + Version 1.4 11 December 2005 Mark Adler */ + +/* Version history: + 1.0 30 Oct 2004 First version + 1.1 8 Nov 2004 Add void casting for unused return values + Use switch statement for inflate() return values + 1.2 9 Nov 2004 Add assertions to document zlib guarantees + 1.3 6 Apr 2005 Remove incorrect assertion in inf() + 1.4 11 Dec 2005 Add hack to avoid MSDOS end-of-line conversions + Avoid some compiler warnings for input and output buffers + */ + +#include +#include +#include +#include "zlib.h" + +#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__) +# include +# include +# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY) +#else +# define SET_BINARY_MODE(file) +#endif + +#define CHUNK 16384 + +/* Compress from file source to file dest until EOF on source. + def() returns Z_OK on success, Z_MEM_ERROR if memory could not be + allocated for processing, Z_STREAM_ERROR if an invalid compression + level is supplied, Z_VERSION_ERROR if the version of zlib.h and the + version of the library linked do not match, or Z_ERRNO if there is + an error reading or writing the files. */ +int def(FILE *source, FILE *dest, int level) +{ + int ret, flush; + unsigned have; + z_stream strm; + unsigned char in[CHUNK]; + unsigned char out[CHUNK]; + + /* allocate deflate state */ + strm.zalloc = Z_NULL; + strm.zfree = Z_NULL; + strm.opaque = Z_NULL; + ret = deflateInit(&strm, level); + if (ret != Z_OK) + return ret; + + /* compress until end of file */ + do { + strm.avail_in = fread(in, 1, CHUNK, source); + if (ferror(source)) { + (void)deflateEnd(&strm); + return Z_ERRNO; + } + flush = feof(source) ? Z_FINISH : Z_NO_FLUSH; + strm.next_in = in; + + /* run deflate() on input until output buffer not full, finish + compression if all of source has been read in */ + do { + strm.avail_out = CHUNK; + strm.next_out = out; + ret = deflate(&strm, flush); /* no bad return value */ + assert(ret != Z_STREAM_ERROR); /* state not clobbered */ + have = CHUNK - strm.avail_out; + if (fwrite(out, 1, have, dest) != have || ferror(dest)) { + (void)deflateEnd(&strm); + return Z_ERRNO; + } + } while (strm.avail_out == 0); + assert(strm.avail_in == 0); /* all input will be used */ + + /* done when last data in file processed */ + } while (flush != Z_FINISH); + assert(ret == Z_STREAM_END); /* stream will be complete */ + + /* clean up and return */ + (void)deflateEnd(&strm); + return Z_OK; +} + +/* Decompress from file source to file dest until stream ends or EOF. + inf() returns Z_OK on success, Z_MEM_ERROR if memory could not be + allocated for processing, Z_DATA_ERROR if the deflate data is + invalid or incomplete, Z_VERSION_ERROR if the version of zlib.h and + the version of the library linked do not match, or Z_ERRNO if there + is an error reading or writing the files. */ +int inf(FILE *source, FILE *dest) +{ + int ret; + unsigned have; + z_stream strm; + unsigned char in[CHUNK]; + unsigned char out[CHUNK]; + + /* allocate inflate state */ + strm.zalloc = Z_NULL; + strm.zfree = Z_NULL; + strm.opaque = Z_NULL; + strm.avail_in = 0; + strm.next_in = Z_NULL; + ret = inflateInit(&strm); + if (ret != Z_OK) + return ret; + + /* decompress until deflate stream ends or end of file */ + do { + strm.avail_in = fread(in, 1, CHUNK, source); + if (ferror(source)) { + (void)inflateEnd(&strm); + return Z_ERRNO; + } + if (strm.avail_in == 0) + break; + strm.next_in = in; + + /* run inflate() on input until output buffer not full */ + do { + strm.avail_out = CHUNK; + strm.next_out = out; + ret = inflate(&strm, Z_NO_FLUSH); + assert(ret != Z_STREAM_ERROR); /* state not clobbered */ + switch (ret) { + case Z_NEED_DICT: + ret = Z_DATA_ERROR; /* and fall through */ + case Z_DATA_ERROR: + case Z_MEM_ERROR: + (void)inflateEnd(&strm); + return ret; + } + have = CHUNK - strm.avail_out; + if (fwrite(out, 1, have, dest) != have || ferror(dest)) { + (void)inflateEnd(&strm); + return Z_ERRNO; + } + } while (strm.avail_out == 0); + + /* done when inflate() says it's done */ + } while (ret != Z_STREAM_END); + + /* clean up and return */ + (void)inflateEnd(&strm); + return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR; +} + +/* report a zlib or i/o error */ +void zerr(int ret) +{ + fputs("zpipe: ", stderr); + switch (ret) { + case Z_ERRNO: + if (ferror(stdin)) + fputs("error reading stdin\n", stderr); + if (ferror(stdout)) + fputs("error writing stdout\n", stderr); + break; + case Z_STREAM_ERROR: + fputs("invalid compression level\n", stderr); + break; + case Z_DATA_ERROR: + fputs("invalid or incomplete deflate data\n", stderr); + break; + case Z_MEM_ERROR: + fputs("out of memory\n", stderr); + break; + case Z_VERSION_ERROR: + fputs("zlib version mismatch!\n", stderr); + } +} + +/* compress or decompress from stdin to stdout */ +int main(int argc, char **argv) +{ + int ret; + + /* avoid end-of-line conversions */ + SET_BINARY_MODE(stdin); + SET_BINARY_MODE(stdout); + + /* do compression if no arguments */ + if (argc == 1) { + ret = def(stdin, stdout, Z_DEFAULT_COMPRESSION); + if (ret != Z_OK) + zerr(ret); + return ret; + } + + /* do decompression if -d specified */ + else if (argc == 2 && strcmp(argv[1], "-d") == 0) { + ret = inf(stdin, stdout); + if (ret != Z_OK) + zerr(ret); + return ret; + } + + /* otherwise, report usage */ + else { + fputs("zpipe usage: zpipe [-d] < source > dest\n", stderr); + return 1; + } +} diff --git a/libs/zlib/examples/zran.c b/libs/zlib/examples/zran.c new file mode 100644 index 000000000..617a13086 --- /dev/null +++ b/libs/zlib/examples/zran.c @@ -0,0 +1,404 @@ +/* zran.c -- example of zlib/gzip stream indexing and random access + * Copyright (C) 2005 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + Version 1.0 29 May 2005 Mark Adler */ + +/* Illustrate the use of Z_BLOCK, inflatePrime(), and inflateSetDictionary() + for random access of a compressed file. A file containing a zlib or gzip + stream is provided on the command line. The compressed stream is decoded in + its entirety, and an index built with access points about every SPAN bytes + in the uncompressed output. The compressed file is left open, and can then + be read randomly, having to decompress on the average SPAN/2 uncompressed + bytes before getting to the desired block of data. + + An access point can be created at the start of any deflate block, by saving + the starting file offset and bit of that block, and the 32K bytes of + uncompressed data that precede that block. Also the uncompressed offset of + that block is saved to provide a referece for locating a desired starting + point in the uncompressed stream. build_index() works by decompressing the + input zlib or gzip stream a block at a time, and at the end of each block + deciding if enough uncompressed data has gone by to justify the creation of + a new access point. If so, that point is saved in a data structure that + grows as needed to accommodate the points. + + To use the index, an offset in the uncompressed data is provided, for which + the latest accees point at or preceding that offset is located in the index. + The input file is positioned to the specified location in the index, and if + necessary the first few bits of the compressed data is read from the file. + inflate is initialized with those bits and the 32K of uncompressed data, and + the decompression then proceeds until the desired offset in the file is + reached. Then the decompression continues to read the desired uncompressed + data from the file. + + Another approach would be to generate the index on demand. In that case, + requests for random access reads from the compressed data would try to use + the index, but if a read far enough past the end of the index is required, + then further index entries would be generated and added. + + There is some fair bit of overhead to starting inflation for the random + access, mainly copying the 32K byte dictionary. So if small pieces of the + file are being accessed, it would make sense to implement a cache to hold + some lookahead and avoid many calls to extract() for small lengths. + + Another way to build an index would be to use inflateCopy(). That would + not be constrained to have access points at block boundaries, but requires + more memory per access point, and also cannot be saved to file due to the + use of pointers in the state. The approach here allows for storage of the + index in a file. + */ + +#include +#include +#include +#include "zlib.h" + +#define local static + +#define SPAN 1048576L /* desired distance between access points */ +#define WINSIZE 32768U /* sliding window size */ +#define CHUNK 16384 /* file input buffer size */ + +/* access point entry */ +struct point { + off_t out; /* corresponding offset in uncompressed data */ + off_t in; /* offset in input file of first full byte */ + int bits; /* number of bits (1-7) from byte at in - 1, or 0 */ + unsigned char window[WINSIZE]; /* preceding 32K of uncompressed data */ +}; + +/* access point list */ +struct access { + int have; /* number of list entries filled in */ + int size; /* number of list entries allocated */ + struct point *list; /* allocated list */ +}; + +/* Deallocate an index built by build_index() */ +local void free_index(struct access *index) +{ + if (index != NULL) { + free(index->list); + free(index); + } +} + +/* Add an entry to the access point list. If out of memory, deallocate the + existing list and return NULL. */ +local struct access *addpoint(struct access *index, int bits, + off_t in, off_t out, unsigned left, unsigned char *window) +{ + struct point *next; + + /* if list is empty, create it (start with eight points) */ + if (index == NULL) { + index = malloc(sizeof(struct access)); + if (index == NULL) return NULL; + index->list = malloc(sizeof(struct point) << 3); + if (index->list == NULL) { + free(index); + return NULL; + } + index->size = 8; + index->have = 0; + } + + /* if list is full, make it bigger */ + else if (index->have == index->size) { + index->size <<= 1; + next = realloc(index->list, sizeof(struct point) * index->size); + if (next == NULL) { + free_index(index); + return NULL; + } + index->list = next; + } + + /* fill in entry and increment how many we have */ + next = index->list + index->have; + next->bits = bits; + next->in = in; + next->out = out; + if (left) + memcpy(next->window, window + WINSIZE - left, left); + if (left < WINSIZE) + memcpy(next->window + left, window, WINSIZE - left); + index->have++; + + /* return list, possibly reallocated */ + return index; +} + +/* Make one entire pass through the compressed stream and build an index, with + access points about every span bytes of uncompressed output -- span is + chosen to balance the speed of random access against the memory requirements + of the list, about 32K bytes per access point. Note that data after the end + of the first zlib or gzip stream in the file is ignored. build_index() + returns the number of access points on success (>= 1), Z_MEM_ERROR for out + of memory, Z_DATA_ERROR for an error in the input file, or Z_ERRNO for a + file read error. On success, *built points to the resulting index. */ +local int build_index(FILE *in, off_t span, struct access **built) +{ + int ret; + off_t totin, totout; /* our own total counters to avoid 4GB limit */ + off_t last; /* totout value of last access point */ + struct access *index; /* access points being generated */ + z_stream strm; + unsigned char input[CHUNK]; + unsigned char window[WINSIZE]; + + /* initialize inflate */ + strm.zalloc = Z_NULL; + strm.zfree = Z_NULL; + strm.opaque = Z_NULL; + strm.avail_in = 0; + strm.next_in = Z_NULL; + ret = inflateInit2(&strm, 47); /* automatic zlib or gzip decoding */ + if (ret != Z_OK) + return ret; + + /* inflate the input, maintain a sliding window, and build an index -- this + also validates the integrity of the compressed data using the check + information at the end of the gzip or zlib stream */ + totin = totout = last = 0; + index = NULL; /* will be allocated by first addpoint() */ + strm.avail_out = 0; + do { + /* get some compressed data from input file */ + strm.avail_in = fread(input, 1, CHUNK, in); + if (ferror(in)) { + ret = Z_ERRNO; + goto build_index_error; + } + if (strm.avail_in == 0) { + ret = Z_DATA_ERROR; + goto build_index_error; + } + strm.next_in = input; + + /* process all of that, or until end of stream */ + do { + /* reset sliding window if necessary */ + if (strm.avail_out == 0) { + strm.avail_out = WINSIZE; + strm.next_out = window; + } + + /* inflate until out of input, output, or at end of block -- + update the total input and output counters */ + totin += strm.avail_in; + totout += strm.avail_out; + ret = inflate(&strm, Z_BLOCK); /* return at end of block */ + totin -= strm.avail_in; + totout -= strm.avail_out; + if (ret == Z_NEED_DICT) + ret = Z_DATA_ERROR; + if (ret == Z_MEM_ERROR || ret == Z_DATA_ERROR) + goto build_index_error; + if (ret == Z_STREAM_END) + break; + + /* if at end of block, consider adding an index entry (note that if + data_type indicates an end-of-block, then all of the + uncompressed data from that block has been delivered, and none + of the compressed data after that block has been consumed, + except for up to seven bits) -- the totout == 0 provides an + entry point after the zlib or gzip header, and assures that the + index always has at least one access point; we avoid creating an + access point after the last block by checking bit 6 of data_type + */ + if ((strm.data_type & 128) && !(strm.data_type & 64) && + (totout == 0 || totout - last > span)) { + index = addpoint(index, strm.data_type & 7, totin, + totout, strm.avail_out, window); + if (index == NULL) { + ret = Z_MEM_ERROR; + goto build_index_error; + } + last = totout; + } + } while (strm.avail_in != 0); + } while (ret != Z_STREAM_END); + + /* clean up and return index (release unused entries in list) */ + (void)inflateEnd(&strm); + index = realloc(index, sizeof(struct point) * index->have); + index->size = index->have; + *built = index; + return index->size; + + /* return error */ + build_index_error: + (void)inflateEnd(&strm); + if (index != NULL) + free_index(index); + return ret; +} + +/* Use the index to read len bytes from offset into buf, return bytes read or + negative for error (Z_DATA_ERROR or Z_MEM_ERROR). If data is requested past + the end of the uncompressed data, then extract() will return a value less + than len, indicating how much as actually read into buf. This function + should not return a data error unless the file was modified since the index + was generated. extract() may also return Z_ERRNO if there is an error on + reading or seeking the input file. */ +local int extract(FILE *in, struct access *index, off_t offset, + unsigned char *buf, int len) +{ + int ret, skip; + z_stream strm; + struct point *here; + unsigned char input[CHUNK]; + unsigned char discard[WINSIZE]; + + /* proceed only if something reasonable to do */ + if (len < 0) + return 0; + + /* find where in stream to start */ + here = index->list; + ret = index->have; + while (--ret && here[1].out <= offset) + here++; + + /* initialize file and inflate state to start there */ + strm.zalloc = Z_NULL; + strm.zfree = Z_NULL; + strm.opaque = Z_NULL; + strm.avail_in = 0; + strm.next_in = Z_NULL; + ret = inflateInit2(&strm, -15); /* raw inflate */ + if (ret != Z_OK) + return ret; + ret = fseeko(in, here->in - (here->bits ? 1 : 0), SEEK_SET); + if (ret == -1) + goto extract_ret; + if (here->bits) { + ret = getc(in); + if (ret == -1) { + ret = ferror(in) ? Z_ERRNO : Z_DATA_ERROR; + goto extract_ret; + } + (void)inflatePrime(&strm, here->bits, ret >> (8 - here->bits)); + } + (void)inflateSetDictionary(&strm, here->window, WINSIZE); + + /* skip uncompressed bytes until offset reached, then satisfy request */ + offset -= here->out; + strm.avail_in = 0; + skip = 1; /* while skipping to offset */ + do { + /* define where to put uncompressed data, and how much */ + if (offset == 0 && skip) { /* at offset now */ + strm.avail_out = len; + strm.next_out = buf; + skip = 0; /* only do this once */ + } + if (offset > WINSIZE) { /* skip WINSIZE bytes */ + strm.avail_out = WINSIZE; + strm.next_out = discard; + offset -= WINSIZE; + } + else if (offset != 0) { /* last skip */ + strm.avail_out = (unsigned)offset; + strm.next_out = discard; + offset = 0; + } + + /* uncompress until avail_out filled, or end of stream */ + do { + if (strm.avail_in == 0) { + strm.avail_in = fread(input, 1, CHUNK, in); + if (ferror(in)) { + ret = Z_ERRNO; + goto extract_ret; + } + if (strm.avail_in == 0) { + ret = Z_DATA_ERROR; + goto extract_ret; + } + strm.next_in = input; + } + ret = inflate(&strm, Z_NO_FLUSH); /* normal inflate */ + if (ret == Z_NEED_DICT) + ret = Z_DATA_ERROR; + if (ret == Z_MEM_ERROR || ret == Z_DATA_ERROR) + goto extract_ret; + if (ret == Z_STREAM_END) + break; + } while (strm.avail_out != 0); + + /* if reach end of stream, then don't keep trying to get more */ + if (ret == Z_STREAM_END) + break; + + /* do until offset reached and requested data read, or stream ends */ + } while (skip); + + /* compute number of uncompressed bytes read after offset */ + ret = skip ? 0 : len - strm.avail_out; + + /* clean up and return bytes read or error */ + extract_ret: + (void)inflateEnd(&strm); + return ret; +} + +/* Demonstrate the use of build_index() and extract() by processing the file + provided on the command line, and the extracting 16K from about 2/3rds of + the way through the uncompressed output, and writing that to stdout. */ +int main(int argc, char **argv) +{ + int len; + off_t offset; + FILE *in; + struct access *index = NULL; + unsigned char buf[CHUNK]; + + /* open input file */ + if (argc != 2) { + fprintf(stderr, "usage: zran file.gz\n"); + return 1; + } + in = fopen(argv[1], "rb"); + if (in == NULL) { + fprintf(stderr, "zran: could not open %s for reading\n", argv[1]); + return 1; + } + + /* build index */ + len = build_index(in, SPAN, &index); + if (len < 0) { + fclose(in); + switch (len) { + case Z_MEM_ERROR: + fprintf(stderr, "zran: out of memory\n"); + break; + case Z_DATA_ERROR: + fprintf(stderr, "zran: compressed data error in %s\n", argv[1]); + break; + case Z_ERRNO: + fprintf(stderr, "zran: read error on %s\n", argv[1]); + break; + default: + fprintf(stderr, "zran: error %d while building index\n", len); + } + return 1; + } + fprintf(stderr, "zran: built index with %d access points\n", len); + + /* use index by reading some bytes from an arbitrary offset */ + offset = (index->list[index->have - 1].out << 1) / 3; + len = extract(in, index, offset, buf, CHUNK); + if (len < 0) + fprintf(stderr, "zran: extraction failed: %s error\n", + len == Z_MEM_ERROR ? "out of memory" : "input corrupted"); + else { + fwrite(buf, 1, len, stdout); + fprintf(stderr, "zran: extracted %d bytes at %llu\n", len, offset); + } + + /* clean up and exit */ + free_index(index); + fclose(in); + return 0; +} diff --git a/libs/zlib/gzclose.c b/libs/zlib/gzclose.c new file mode 100644 index 000000000..caeb99a31 --- /dev/null +++ b/libs/zlib/gzclose.c @@ -0,0 +1,25 @@ +/* gzclose.c -- zlib gzclose() function + * Copyright (C) 2004, 2010 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +#include "gzguts.h" + +/* gzclose() is in a separate file so that it is linked in only if it is used. + That way the other gzclose functions can be used instead to avoid linking in + unneeded compression or decompression routines. */ +int ZEXPORT gzclose(file) + gzFile file; +{ +#ifndef NO_GZCOMPRESS + gz_statep state; + + if (file == NULL) + return Z_STREAM_ERROR; + state = (gz_statep)file; + + return state->mode == GZ_READ ? gzclose_r(file) : gzclose_w(file); +#else + return gzclose_r(file); +#endif +} diff --git a/libs/zlib/gzguts.h b/libs/zlib/gzguts.h new file mode 100644 index 000000000..6154b062c --- /dev/null +++ b/libs/zlib/gzguts.h @@ -0,0 +1,192 @@ +/* gzguts.h -- zlib internal header definitions for gz* operations + * Copyright (C) 2004, 2005, 2010, 2011, 2012 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +#ifdef _LARGEFILE64_SOURCE +# ifndef _LARGEFILE_SOURCE +# define _LARGEFILE_SOURCE 1 +# endif +# ifdef _FILE_OFFSET_BITS +# undef _FILE_OFFSET_BITS +# endif +#endif + +#if ((__GNUC__-0) * 10 + __GNUC_MINOR__-0 >= 33) && !defined(NO_VIZ) +# define ZLIB_INTERNAL __attribute__((visibility ("hidden"))) +#else +# define ZLIB_INTERNAL +#endif + +#include +#include "zlib.h" +#ifdef STDC +# include +# include +# include +#endif +#ifdef _MSC_VER +#include +#endif +#include + +#ifdef __TURBOC__ +# include +#endif + +#ifdef NO_DEFLATE /* for compatibility with old definition */ +# define NO_GZCOMPRESS +#endif + +#if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550) +# ifndef HAVE_VSNPRINTF +# define HAVE_VSNPRINTF +# endif +#endif + +#if defined(__CYGWIN__) +# ifndef HAVE_VSNPRINTF +# define HAVE_VSNPRINTF +# endif +#endif + +#if defined(MSDOS) && defined(__BORLANDC__) && (BORLANDC > 0x410) +# ifndef HAVE_VSNPRINTF +# define HAVE_VSNPRINTF +# endif +#endif + +#ifndef HAVE_VSNPRINTF +# ifdef MSDOS +/* vsnprintf may exist on some MS-DOS compilers (DJGPP?), + but for now we just assume it doesn't. */ +# define NO_vsnprintf +# endif +# ifdef __TURBOC__ +# define NO_vsnprintf +# endif +# ifdef WIN32 +/* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */ +# if !defined(vsnprintf) && !defined(NO_vsnprintf) +# if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 ) +# define vsnprintf _vsnprintf +# endif +# endif +# endif +# ifdef __SASC +# define NO_vsnprintf +# endif +# ifdef VMS +# define NO_vsnprintf +# endif +# ifdef __OS400__ +# define NO_vsnprintf +# endif +# ifdef __MVS__ +# define NO_vsnprintf +# endif +#endif + +#ifndef local +# define local static +#endif +/* compile with -Dlocal if your debugger can't find static symbols */ + +/* gz* functions always use library allocation functions */ +#ifndef STDC + extern voidp malloc OF((uInt size)); + extern void free OF((voidpf ptr)); +#endif + +/* get errno and strerror definition */ +#if defined UNDER_CE +# include +# define zstrerror() gz_strwinerror((DWORD)GetLastError()) +#else +# ifdef STDC +# include +# define zstrerror() strerror(errno) +# else +# define zstrerror() "stdio error (consult errno)" +# endif +#endif + +/* provide prototypes for these when building zlib without LFS */ +#if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0 + ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); + ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int)); + ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile)); + ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile)); +#endif + +/* default memLevel */ +#if MAX_MEM_LEVEL >= 8 +# define DEF_MEM_LEVEL 8 +#else +# define DEF_MEM_LEVEL MAX_MEM_LEVEL +#endif + +/* default i/o buffer size -- double this for output when reading */ +#define GZBUFSIZE 8192 + +/* gzip modes, also provide a little integrity check on the passed structure */ +#define GZ_NONE 0 +#define GZ_READ 7247 +#define GZ_WRITE 31153 +#define GZ_APPEND 1 /* mode set to GZ_WRITE after the file is opened */ + +/* values for gz_state how */ +#define LOOK 0 /* look for a gzip header */ +#define COPY 1 /* copy input directly */ +#define GZIP 2 /* decompress a gzip stream */ + +/* internal gzip file state data structure */ +typedef struct { + /* exposed contents for gzgetc() macro */ + struct gzFile_s x; /* "x" for exposed */ + /* x.have: number of bytes available at x.next */ + /* x.next: next output data to deliver or write */ + /* x.pos: current position in uncompressed data */ + /* used for both reading and writing */ + int mode; /* see gzip modes above */ + int fd; /* file descriptor */ + char *path; /* path or fd for error messages */ + unsigned size; /* buffer size, zero if not allocated yet */ + unsigned want; /* requested buffer size, default is GZBUFSIZE */ + unsigned char *in; /* input buffer */ + unsigned char *out; /* output buffer (double-sized when reading) */ + int direct; /* 0 if processing gzip, 1 if transparent */ + /* just for reading */ + int how; /* 0: get header, 1: copy, 2: decompress */ + z_off64_t start; /* where the gzip data started, for rewinding */ + int eof; /* true if end of input file reached */ + int past; /* true if read requested past end */ + /* just for writing */ + int level; /* compression level */ + int strategy; /* compression strategy */ + /* seek request */ + z_off64_t skip; /* amount to skip (already rewound if backwards) */ + int seek; /* true if seek request pending */ + /* error information */ + int err; /* error code */ + char *msg; /* error message */ + /* zlib inflate or deflate stream */ + z_stream strm; /* stream structure in-place (not a pointer) */ +} gz_state; +typedef gz_state FAR *gz_statep; + +/* shared functions */ +void ZLIB_INTERNAL gz_error OF((gz_statep, int, const char *)); +#if defined UNDER_CE +char ZLIB_INTERNAL *gz_strwinerror OF((DWORD error)); +#endif + +/* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t + value -- needed when comparing unsigned to z_off64_t, which is signed + (possible z_off64_t types off_t, off64_t, and long are all signed) */ +#ifdef INT_MAX +# define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX) +#else +unsigned ZLIB_INTERNAL gz_intmax OF((void)); +# define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax()) +#endif diff --git a/libs/zlib/gzlib.c b/libs/zlib/gzlib.c new file mode 100644 index 000000000..7aedab8e2 --- /dev/null +++ b/libs/zlib/gzlib.c @@ -0,0 +1,564 @@ +/* gzlib.c -- zlib functions common to reading and writing gzip files + * Copyright (C) 2004, 2010, 2011 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +#include "gzguts.h" + +#if defined(_WIN32) && !defined(__BORLANDC__) +# define LSEEK _lseeki64 +#else +#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0 +# define LSEEK lseek64 +#else +# define LSEEK lseek +#endif +#endif + +/* Local functions */ +local void gz_reset OF((gz_statep)); +local gzFile gz_open OF((const char *, int, const char *)); + +#if defined UNDER_CE + +/* Map the Windows error number in ERROR to a locale-dependent error message + string and return a pointer to it. Typically, the values for ERROR come + from GetLastError. + + The string pointed to shall not be modified by the application, but may be + overwritten by a subsequent call to gz_strwinerror + + The gz_strwinerror function does not change the current setting of + GetLastError. */ +char ZLIB_INTERNAL *gz_strwinerror (error) + DWORD error; +{ + static char buf[1024]; + + wchar_t *msgbuf; + DWORD lasterr = GetLastError(); + DWORD chars = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM + | FORMAT_MESSAGE_ALLOCATE_BUFFER, + NULL, + error, + 0, /* Default language */ + (LPVOID)&msgbuf, + 0, + NULL); + if (chars != 0) { + /* If there is an \r\n appended, zap it. */ + if (chars >= 2 + && msgbuf[chars - 2] == '\r' && msgbuf[chars - 1] == '\n') { + chars -= 2; + msgbuf[chars] = 0; + } + + if (chars > sizeof (buf) - 1) { + chars = sizeof (buf) - 1; + msgbuf[chars] = 0; + } + + wcstombs(buf, msgbuf, chars + 1); + LocalFree(msgbuf); + } + else { + sprintf(buf, "unknown win32 error (%ld)", error); + } + + SetLastError(lasterr); + return buf; +} + +#endif /* UNDER_CE */ + +/* Reset gzip file state */ +local void gz_reset(state) + gz_statep state; +{ + state->x.have = 0; /* no output data available */ + if (state->mode == GZ_READ) { /* for reading ... */ + state->eof = 0; /* not at end of file */ + state->past = 0; /* have not read past end yet */ + state->how = LOOK; /* look for gzip header */ + } + state->seek = 0; /* no seek request pending */ + gz_error(state, Z_OK, NULL); /* clear error */ + state->x.pos = 0; /* no uncompressed data yet */ + state->strm.avail_in = 0; /* no input data yet */ +} + +/* Open a gzip file either by name or file descriptor. */ +local gzFile gz_open(path, fd, mode) + const char *path; + int fd; + const char *mode; +{ + gz_statep state; + + /* check input */ + if (path == NULL) + return NULL; + + /* allocate gzFile structure to return */ + state = malloc(sizeof(gz_state)); + if (state == NULL) + return NULL; + state->size = 0; /* no buffers allocated yet */ + state->want = GZBUFSIZE; /* requested buffer size */ + state->msg = NULL; /* no error message yet */ + + /* interpret mode */ + state->mode = GZ_NONE; + state->level = Z_DEFAULT_COMPRESSION; + state->strategy = Z_DEFAULT_STRATEGY; + state->direct = 0; + while (*mode) { + if (*mode >= '0' && *mode <= '9') + state->level = *mode - '0'; + else + switch (*mode) { + case 'r': + state->mode = GZ_READ; + break; +#ifndef NO_GZCOMPRESS + case 'w': + state->mode = GZ_WRITE; + break; + case 'a': + state->mode = GZ_APPEND; + break; +#endif + case '+': /* can't read and write at the same time */ + free(state); + return NULL; + case 'b': /* ignore -- will request binary anyway */ + break; + case 'f': + state->strategy = Z_FILTERED; + break; + case 'h': + state->strategy = Z_HUFFMAN_ONLY; + break; + case 'R': + state->strategy = Z_RLE; + break; + case 'F': + state->strategy = Z_FIXED; + case 'T': + state->direct = 1; + default: /* could consider as an error, but just ignore */ + ; + } + mode++; + } + + /* must provide an "r", "w", or "a" */ + if (state->mode == GZ_NONE) { + free(state); + return NULL; + } + + /* can't force transparent read */ + if (state->mode == GZ_READ) { + if (state->direct) { + free(state); + return NULL; + } + state->direct = 1; /* for empty file */ + } + + /* save the path name for error messages */ + state->path = malloc(strlen(path) + 1); + if (state->path == NULL) { + free(state); + return NULL; + } + strcpy(state->path, path); + + /* open the file with the appropriate mode (or just use fd) */ + state->fd = fd != -1 ? fd : + open(path, +#ifdef O_LARGEFILE + O_LARGEFILE | +#endif +#ifdef O_BINARY + O_BINARY | +#endif + (state->mode == GZ_READ ? + O_RDONLY : + (O_WRONLY | O_CREAT | ( + state->mode == GZ_WRITE ? + O_TRUNC : + O_APPEND))), + 0666); + if (state->fd == -1) { + free(state->path); + free(state); + return NULL; + } + if (state->mode == GZ_APPEND) + state->mode = GZ_WRITE; /* simplify later checks */ + + /* save the current position for rewinding (only if reading) */ + if (state->mode == GZ_READ) { + state->start = LSEEK(state->fd, 0, SEEK_CUR); + if (state->start == -1) state->start = 0; + } + + /* initialize stream */ + gz_reset(state); + + /* return stream */ + return (gzFile)state; +} + +/* -- see zlib.h -- */ +gzFile ZEXPORT gzopen(path, mode) + const char *path; + const char *mode; +{ + return gz_open(path, -1, mode); +} + +/* -- see zlib.h -- */ +gzFile ZEXPORT gzopen64(path, mode) + const char *path; + const char *mode; +{ + return gz_open(path, -1, mode); +} + +/* -- see zlib.h -- */ +gzFile ZEXPORT gzdopen(fd, mode) + int fd; + const char *mode; +{ + char *path; /* identifier for error messages */ + gzFile gz; + + if (fd == -1 || (path = malloc(7 + 3 * sizeof(int))) == NULL) + return NULL; + sprintf(path, "", fd); /* for debugging */ + gz = gz_open(path, fd, mode); + free(path); + return gz; +} + +/* -- see zlib.h -- */ +int ZEXPORT gzbuffer(file, size) + gzFile file; + unsigned size; +{ + gz_statep state; + + /* get internal structure and check integrity */ + if (file == NULL) + return -1; + state = (gz_statep)file; + if (state->mode != GZ_READ && state->mode != GZ_WRITE) + return -1; + + /* make sure we haven't already allocated memory */ + if (state->size != 0) + return -1; + + /* check and set requested size */ + if (size < 2) + size = 2; /* need two bytes to check magic header */ + state->want = size; + return 0; +} + +/* -- see zlib.h -- */ +int ZEXPORT gzrewind(file) + gzFile file; +{ + gz_statep state; + + /* get internal structure */ + if (file == NULL) + return -1; + state = (gz_statep)file; + + /* check that we're reading and that there's no error */ + if (state->mode != GZ_READ || + (state->err != Z_OK && state->err != Z_BUF_ERROR)) + return -1; + + /* back up and start over */ + if (LSEEK(state->fd, state->start, SEEK_SET) == -1) + return -1; + gz_reset(state); + return 0; +} + +/* -- see zlib.h -- */ +z_off64_t ZEXPORT gzseek64(file, offset, whence) + gzFile file; + z_off64_t offset; + int whence; +{ + unsigned n; + z_off64_t ret; + gz_statep state; + + /* get internal structure and check integrity */ + if (file == NULL) + return -1; + state = (gz_statep)file; + if (state->mode != GZ_READ && state->mode != GZ_WRITE) + return -1; + + /* check that there's no error */ + if (state->err != Z_OK && state->err != Z_BUF_ERROR) + return -1; + + /* can only seek from start or relative to current position */ + if (whence != SEEK_SET && whence != SEEK_CUR) + return -1; + + /* normalize offset to a SEEK_CUR specification */ + if (whence == SEEK_SET) + offset -= state->x.pos; + else if (state->seek) + offset += state->skip; + state->seek = 0; + + /* if within raw area while reading, just go there */ + if (state->mode == GZ_READ && state->how == COPY && + state->x.pos + offset >= 0) { + ret = LSEEK(state->fd, offset - state->x.have, SEEK_CUR); + if (ret == -1) + return -1; + state->x.have = 0; + state->eof = 0; + state->past = 0; + state->seek = 0; + gz_error(state, Z_OK, NULL); + state->strm.avail_in = 0; + state->x.pos += offset; + return state->x.pos; + } + + /* calculate skip amount, rewinding if needed for back seek when reading */ + if (offset < 0) { + if (state->mode != GZ_READ) /* writing -- can't go backwards */ + return -1; + offset += state->x.pos; + if (offset < 0) /* before start of file! */ + return -1; + if (gzrewind(file) == -1) /* rewind, then skip to offset */ + return -1; + } + + /* if reading, skip what's in output buffer (one less gzgetc() check) */ + if (state->mode == GZ_READ) { + n = GT_OFF(state->x.have) || (z_off64_t)state->x.have > offset ? + (unsigned)offset : state->x.have; + state->x.have -= n; + state->x.next += n; + state->x.pos += n; + offset -= n; + } + + /* request skip (if not zero) */ + if (offset) { + state->seek = 1; + state->skip = offset; + } + return state->x.pos + offset; +} + +/* -- see zlib.h -- */ +z_off_t ZEXPORT gzseek(file, offset, whence) + gzFile file; + z_off_t offset; + int whence; +{ + z_off64_t ret; + + ret = gzseek64(file, (z_off64_t)offset, whence); + return ret == (z_off_t)ret ? (z_off_t)ret : -1; +} + +/* -- see zlib.h -- */ +z_off64_t ZEXPORT gztell64(file) + gzFile file; +{ + gz_statep state; + + /* get internal structure and check integrity */ + if (file == NULL) + return -1; + state = (gz_statep)file; + if (state->mode != GZ_READ && state->mode != GZ_WRITE) + return -1; + + /* return position */ + return state->x.pos + (state->seek ? state->skip : 0); +} + +/* -- see zlib.h -- */ +z_off_t ZEXPORT gztell(file) + gzFile file; +{ + z_off64_t ret; + + ret = gztell64(file); + return ret == (z_off_t)ret ? (z_off_t)ret : -1; +} + +/* -- see zlib.h -- */ +z_off64_t ZEXPORT gzoffset64(file) + gzFile file; +{ + z_off64_t offset; + gz_statep state; + + /* get internal structure and check integrity */ + if (file == NULL) + return -1; + state = (gz_statep)file; + if (state->mode != GZ_READ && state->mode != GZ_WRITE) + return -1; + + /* compute and return effective offset in file */ + offset = LSEEK(state->fd, 0, SEEK_CUR); + if (offset == -1) + return -1; + if (state->mode == GZ_READ) /* reading */ + offset -= state->strm.avail_in; /* don't count buffered input */ + return offset; +} + +/* -- see zlib.h -- */ +z_off_t ZEXPORT gzoffset(file) + gzFile file; +{ + z_off64_t ret; + + ret = gzoffset64(file); + return ret == (z_off_t)ret ? (z_off_t)ret : -1; +} + +/* -- see zlib.h -- */ +int ZEXPORT gzeof(file) + gzFile file; +{ + gz_statep state; + + /* get internal structure and check integrity */ + if (file == NULL) + return 0; + state = (gz_statep)file; + if (state->mode != GZ_READ && state->mode != GZ_WRITE) + return 0; + + /* return end-of-file state */ + return state->mode == GZ_READ ? state->past : 0; +} + +/* -- see zlib.h -- */ +const char * ZEXPORT gzerror(file, errnum) + gzFile file; + int *errnum; +{ + gz_statep state; + + /* get internal structure and check integrity */ + if (file == NULL) + return NULL; + state = (gz_statep)file; + if (state->mode != GZ_READ && state->mode != GZ_WRITE) + return NULL; + + /* return error information */ + if (errnum != NULL) + *errnum = state->err; + return state->msg == NULL ? "" : state->msg; +} + +/* -- see zlib.h -- */ +void ZEXPORT gzclearerr(file) + gzFile file; +{ + gz_statep state; + + /* get internal structure and check integrity */ + if (file == NULL) + return; + state = (gz_statep)file; + if (state->mode != GZ_READ && state->mode != GZ_WRITE) + return; + + /* clear error and end-of-file */ + if (state->mode == GZ_READ) { + state->eof = 0; + state->past = 0; + } + gz_error(state, Z_OK, NULL); +} + +/* Create an error message in allocated memory and set state->err and + state->msg accordingly. Free any previous error message already there. Do + not try to free or allocate space if the error is Z_MEM_ERROR (out of + memory). Simply save the error message as a static string. If there is an + allocation failure constructing the error message, then convert the error to + out of memory. */ +void ZLIB_INTERNAL gz_error(state, err, msg) + gz_statep state; + int err; + const char *msg; +{ + /* free previously allocated message and clear */ + if (state->msg != NULL) { + if (state->err != Z_MEM_ERROR) + free(state->msg); + state->msg = NULL; + } + + /* if fatal, set state->x.have to 0 so that the gzgetc() macro fails */ + if (err != Z_OK && err != Z_BUF_ERROR) + state->x.have = 0; + + /* set error code, and if no message, then done */ + state->err = err; + if (msg == NULL) + return; + + /* for an out of memory error, save as static string */ + if (err == Z_MEM_ERROR) { + state->msg = (char *)msg; + return; + } + + /* construct error message with path */ + if ((state->msg = malloc(strlen(state->path) + strlen(msg) + 3)) == NULL) { + state->err = Z_MEM_ERROR; + state->msg = (char *)"out of memory"; + return; + } + strcpy(state->msg, state->path); + strcat(state->msg, ": "); + strcat(state->msg, msg); + return; +} + +#ifndef INT_MAX +/* portably return maximum value for an int (when limits.h presumed not + available) -- we need to do this to cover cases where 2's complement not + used, since C standard permits 1's complement and sign-bit representations, + otherwise we could just use ((unsigned)-1) >> 1 */ +unsigned ZLIB_INTERNAL gz_intmax() +{ + unsigned p, q; + + p = 1; + do { + q = p; + p <<= 1; + p++; + } while (p > q); + return q >> 1; +} +#endif diff --git a/libs/zlib/gzread.c b/libs/zlib/gzread.c new file mode 100644 index 000000000..46d40e0bb --- /dev/null +++ b/libs/zlib/gzread.c @@ -0,0 +1,584 @@ +/* gzread.c -- zlib functions for reading gzip files + * Copyright (C) 2004, 2005, 2010, 2011 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +#include "gzguts.h" + +/* Local functions */ +local int gz_load OF((gz_statep, unsigned char *, unsigned, unsigned *)); +local int gz_avail OF((gz_statep)); +local int gz_look OF((gz_statep)); +local int gz_decomp OF((gz_statep)); +local int gz_fetch OF((gz_statep)); +local int gz_skip OF((gz_statep, z_off64_t)); + +/* Use read() to load a buffer -- return -1 on error, otherwise 0. Read from + state->fd, and update state->eof, state->err, and state->msg as appropriate. + This function needs to loop on read(), since read() is not guaranteed to + read the number of bytes requested, depending on the type of descriptor. */ +local int gz_load(state, buf, len, have) + gz_statep state; + unsigned char *buf; + unsigned len; + unsigned *have; +{ + int ret; + + *have = 0; + do { + ret = read(state->fd, buf + *have, len - *have); + if (ret <= 0) + break; + *have += ret; + } while (*have < len); + if (ret < 0) { + gz_error(state, Z_ERRNO, zstrerror()); + return -1; + } + if (ret == 0) + state->eof = 1; + return 0; +} + +/* Load up input buffer and set eof flag if last data loaded -- return -1 on + error, 0 otherwise. Note that the eof flag is set when the end of the input + file is reached, even though there may be unused data in the buffer. Once + that data has been used, no more attempts will be made to read the file. + If strm->avail_in != 0, then the current data is moved to the beginning of + the input buffer, and then the remainder of the buffer is loaded with the + available data from the input file. */ +local int gz_avail(state) + gz_statep state; +{ + unsigned got; + z_streamp strm = &(state->strm); + + if (state->err != Z_OK && state->err != Z_BUF_ERROR) + return -1; + if (state->eof == 0) { + if (strm->avail_in) + memmove(state->in, strm->next_in, strm->avail_in); + if (gz_load(state, state->in + strm->avail_in, + state->size - strm->avail_in, &got) == -1) + return -1; + strm->avail_in += got; + strm->next_in = state->in; + } + return 0; +} + +/* Look for gzip header, set up for inflate or copy. state->x.have must be 0. + If this is the first time in, allocate required memory. state->how will be + left unchanged if there is no more input data available, will be set to COPY + if there is no gzip header and direct copying will be performed, or it will + be set to GZIP for decompression. If direct copying, then leftover input + data from the input buffer will be copied to the output buffer. In that + case, all further file reads will be directly to either the output buffer or + a user buffer. If decompressing, the inflate state will be initialized. + gz_look() will return 0 on success or -1 on failure. */ +local int gz_look(state) + gz_statep state; +{ + z_streamp strm = &(state->strm); + + /* allocate read buffers and inflate memory */ + if (state->size == 0) { + /* allocate buffers */ + state->in = malloc(state->want); + state->out = malloc(state->want << 1); + if (state->in == NULL || state->out == NULL) { + if (state->out != NULL) + free(state->out); + if (state->in != NULL) + free(state->in); + gz_error(state, Z_MEM_ERROR, "out of memory"); + return -1; + } + state->size = state->want; + + /* allocate inflate memory */ + state->strm.zalloc = Z_NULL; + state->strm.zfree = Z_NULL; + state->strm.opaque = Z_NULL; + state->strm.avail_in = 0; + state->strm.next_in = Z_NULL; + if (inflateInit2(&(state->strm), 15 + 16) != Z_OK) { /* gunzip */ + free(state->out); + free(state->in); + state->size = 0; + gz_error(state, Z_MEM_ERROR, "out of memory"); + return -1; + } + } + + /* get at least the magic bytes in the input buffer */ + if (strm->avail_in < 2) { + if (gz_avail(state) == -1) + return -1; + if (strm->avail_in == 0) + return 0; + } + + /* look for gzip magic bytes -- if there, do gzip decoding (note: there is + a logical dilemma here when considering the case of a partially written + gzip file, to wit, if a single 31 byte is written, then we cannot tell + whether this is a single-byte file, or just a partially written gzip + file -- for here we assume that if a gzip file is being written, then + the header will be written in a single operation, so that reading a + single byte is sufficient indication that it is not a gzip file) */ + if (strm->avail_in > 1 && + strm->next_in[0] == 31 && strm->next_in[1] == 139) { + inflateReset(strm); + state->how = GZIP; + state->direct = 0; + return 0; + } + + /* no gzip header -- if we were decoding gzip before, then this is trailing + garbage. Ignore the trailing garbage and finish. */ + if (state->direct == 0) { + strm->avail_in = 0; + state->eof = 1; + state->x.have = 0; + return 0; + } + + /* doing raw i/o, copy any leftover input to output -- this assumes that + the output buffer is larger than the input buffer, which also assures + space for gzungetc() */ + state->x.next = state->out; + if (strm->avail_in) { + memcpy(state->x.next, strm->next_in, strm->avail_in); + state->x.have = strm->avail_in; + strm->avail_in = 0; + } + state->how = COPY; + state->direct = 1; + return 0; +} + +/* Decompress from input to the provided next_out and avail_out in the state. + On return, state->x.have and state->x.next point to the just decompressed + data. If the gzip stream completes, state->how is reset to LOOK to look for + the next gzip stream or raw data, once state->x.have is depleted. Returns 0 + on success, -1 on failure. */ +local int gz_decomp(state) + gz_statep state; +{ + int ret = Z_OK; + unsigned had; + z_streamp strm = &(state->strm); + + /* fill output buffer up to end of deflate stream */ + had = strm->avail_out; + do { + /* get more input for inflate() */ + if (strm->avail_in == 0 && gz_avail(state) == -1) + return -1; + if (strm->avail_in == 0) { + gz_error(state, Z_BUF_ERROR, "unexpected end of file"); + break; + } + + /* decompress and handle errors */ + ret = inflate(strm, Z_NO_FLUSH); + if (ret == Z_STREAM_ERROR || ret == Z_NEED_DICT) { + gz_error(state, Z_STREAM_ERROR, + "internal error: inflate stream corrupt"); + return -1; + } + if (ret == Z_MEM_ERROR) { + gz_error(state, Z_MEM_ERROR, "out of memory"); + return -1; + } + if (ret == Z_DATA_ERROR) { /* deflate stream invalid */ + gz_error(state, Z_DATA_ERROR, + strm->msg == NULL ? "compressed data error" : strm->msg); + return -1; + } + } while (strm->avail_out && ret != Z_STREAM_END); + + /* update available output */ + state->x.have = had - strm->avail_out; + state->x.next = strm->next_out - state->x.have; + + /* if the gzip stream completed successfully, look for another */ + if (ret == Z_STREAM_END) + state->how = LOOK; + + /* good decompression */ + return 0; +} + +/* Fetch data and put it in the output buffer. Assumes state->x.have is 0. + Data is either copied from the input file or decompressed from the input + file depending on state->how. If state->how is LOOK, then a gzip header is + looked for to determine whether to copy or decompress. Returns -1 on error, + otherwise 0. gz_fetch() will leave state->how as COPY or GZIP unless the + end of the input file has been reached and all data has been processed. */ +local int gz_fetch(state) + gz_statep state; +{ + z_streamp strm = &(state->strm); + + do { + switch(state->how) { + case LOOK: /* -> LOOK, COPY (only if never GZIP), or GZIP */ + if (gz_look(state) == -1) + return -1; + if (state->how == LOOK) + return 0; + break; + case COPY: /* -> COPY */ + if (gz_load(state, state->out, state->size << 1, &(state->x.have)) + == -1) + return -1; + state->x.next = state->out; + return 0; + case GZIP: /* -> GZIP or LOOK (if end of gzip stream) */ + strm->avail_out = state->size << 1; + strm->next_out = state->out; + if (gz_decomp(state) == -1) + return -1; + } + } while (state->x.have == 0 && (!state->eof || strm->avail_in)); + return 0; +} + +/* Skip len uncompressed bytes of output. Return -1 on error, 0 on success. */ +local int gz_skip(state, len) + gz_statep state; + z_off64_t len; +{ + unsigned n; + + /* skip over len bytes or reach end-of-file, whichever comes first */ + while (len) + /* skip over whatever is in output buffer */ + if (state->x.have) { + n = GT_OFF(state->x.have) || (z_off64_t)state->x.have > len ? + (unsigned)len : state->x.have; + state->x.have -= n; + state->x.next += n; + state->x.pos += n; + len -= n; + } + + /* output buffer empty -- return if we're at the end of the input */ + else if (state->eof && state->strm.avail_in == 0) + break; + + /* need more data to skip -- load up output buffer */ + else { + /* get more output, looking for header if required */ + if (gz_fetch(state) == -1) + return -1; + } + return 0; +} + +/* -- see zlib.h -- */ +int ZEXPORT gzread(file, buf, len) + gzFile file; + voidp buf; + unsigned len; +{ + unsigned got, n; + gz_statep state; + z_streamp strm; + + /* get internal structure */ + if (file == NULL) + return -1; + state = (gz_statep)file; + strm = &(state->strm); + + /* check that we're reading and that there's no (serious) error */ + if (state->mode != GZ_READ || + (state->err != Z_OK && state->err != Z_BUF_ERROR)) + return -1; + + /* since an int is returned, make sure len fits in one, otherwise return + with an error (this avoids the flaw in the interface) */ + if ((int)len < 0) { + gz_error(state, Z_DATA_ERROR, "requested length does not fit in int"); + return -1; + } + + /* if len is zero, avoid unnecessary operations */ + if (len == 0) + return 0; + + /* process a skip request */ + if (state->seek) { + state->seek = 0; + if (gz_skip(state, state->skip) == -1) + return -1; + } + + /* get len bytes to buf, or less than len if at the end */ + got = 0; + do { + /* first just try copying data from the output buffer */ + if (state->x.have) { + n = state->x.have > len ? len : state->x.have; + memcpy(buf, state->x.next, n); + state->x.next += n; + state->x.have -= n; + } + + /* output buffer empty -- return if we're at the end of the input */ + else if (state->eof && strm->avail_in == 0) { + state->past = 1; /* tried to read past end */ + break; + } + + /* need output data -- for small len or new stream load up our output + buffer */ + else if (state->how == LOOK || len < (state->size << 1)) { + /* get more output, looking for header if required */ + if (gz_fetch(state) == -1) + return -1; + continue; /* no progress yet -- go back to memcpy() above */ + /* the copy above assures that we will leave with space in the + output buffer, allowing at least one gzungetc() to succeed */ + } + + /* large len -- read directly into user buffer */ + else if (state->how == COPY) { /* read directly */ + if (gz_load(state, buf, len, &n) == -1) + return -1; + } + + /* large len -- decompress directly into user buffer */ + else { /* state->how == GZIP */ + strm->avail_out = len; + strm->next_out = buf; + if (gz_decomp(state) == -1) + return -1; + n = state->x.have; + state->x.have = 0; + } + + /* update progress */ + len -= n; + buf = (char *)buf + n; + got += n; + state->x.pos += n; + } while (len); + + /* return number of bytes read into user buffer (will fit in int) */ + return (int)got; +} + +/* -- see zlib.h -- */ +int ZEXPORT gzgetc_(file) + gzFile file; +{ + int ret; + unsigned char buf[1]; + gz_statep state; + + /* get internal structure */ + if (file == NULL) + return -1; + state = (gz_statep)file; + + /* check that we're reading and that there's no (serious) error */ + if (state->mode != GZ_READ || + (state->err != Z_OK && state->err != Z_BUF_ERROR)) + return -1; + + /* try output buffer (no need to check for skip request) */ + if (state->x.have) { + state->x.have--; + state->x.pos++; + return *(state->x.next)++; + } + + /* nothing there -- try gzread() */ + ret = gzread(file, buf, 1); + return ret < 1 ? -1 : buf[0]; +} + +#undef gzgetc +int ZEXPORT gzgetc(file) +gzFile file; +{ + return gzgetc_(file); +} + +/* -- see zlib.h -- */ +int ZEXPORT gzungetc(c, file) + int c; + gzFile file; +{ + gz_statep state; + + /* get internal structure */ + if (file == NULL) + return -1; + state = (gz_statep)file; + + /* check that we're reading and that there's no (serious) error */ + if (state->mode != GZ_READ || + (state->err != Z_OK && state->err != Z_BUF_ERROR)) + return -1; + + /* process a skip request */ + if (state->seek) { + state->seek = 0; + if (gz_skip(state, state->skip) == -1) + return -1; + } + + /* can't push EOF */ + if (c < 0) + return -1; + + /* if output buffer empty, put byte at end (allows more pushing) */ + if (state->x.have == 0) { + state->x.have = 1; + state->x.next = state->out + (state->size << 1) - 1; + state->x.next[0] = c; + state->x.pos--; + state->past = 0; + return c; + } + + /* if no room, give up (must have already done a gzungetc()) */ + if (state->x.have == (state->size << 1)) { + gz_error(state, Z_DATA_ERROR, "out of room to push characters"); + return -1; + } + + /* slide output data if needed and insert byte before existing data */ + if (state->x.next == state->out) { + unsigned char *src = state->out + state->x.have; + unsigned char *dest = state->out + (state->size << 1); + while (src > state->out) + *--dest = *--src; + state->x.next = dest; + } + state->x.have++; + state->x.next--; + state->x.next[0] = c; + state->x.pos--; + state->past = 0; + return c; +} + +/* -- see zlib.h -- */ +char * ZEXPORT gzgets(file, buf, len) + gzFile file; + char *buf; + int len; +{ + unsigned left, n; + char *str; + unsigned char *eol; + gz_statep state; + + /* check parameters and get internal structure */ + if (file == NULL || buf == NULL || len < 1) + return NULL; + state = (gz_statep)file; + + /* check that we're reading and that there's no (serious) error */ + if (state->mode != GZ_READ || + (state->err != Z_OK && state->err != Z_BUF_ERROR)) + return NULL; + + /* process a skip request */ + if (state->seek) { + state->seek = 0; + if (gz_skip(state, state->skip) == -1) + return NULL; + } + + /* copy output bytes up to new line or len - 1, whichever comes first -- + append a terminating zero to the string (we don't check for a zero in + the contents, let the user worry about that) */ + str = buf; + left = (unsigned)len - 1; + if (left) do { + /* assure that something is in the output buffer */ + if (state->x.have == 0 && gz_fetch(state) == -1) + return NULL; /* error */ + if (state->x.have == 0) { /* end of file */ + state->past = 1; /* read past end */ + break; /* return what we have */ + } + + /* look for end-of-line in current output buffer */ + n = state->x.have > left ? left : state->x.have; + eol = memchr(state->x.next, '\n', n); + if (eol != NULL) + n = (unsigned)(eol - state->x.next) + 1; + + /* copy through end-of-line, or remainder if not found */ + memcpy(buf, state->x.next, n); + state->x.have -= n; + state->x.next += n; + state->x.pos += n; + left -= n; + buf += n; + } while (left && eol == NULL); + + /* return terminated string, or if nothing, end of file */ + if (buf == str) + return NULL; + buf[0] = 0; + return str; +} + +/* -- see zlib.h -- */ +int ZEXPORT gzdirect(file) + gzFile file; +{ + gz_statep state; + + /* get internal structure */ + if (file == NULL) + return 0; + state = (gz_statep)file; + + /* if the state is not known, but we can find out, then do so (this is + mainly for right after a gzopen() or gzdopen()) */ + if (state->mode == GZ_READ && state->how == LOOK && state->x.have == 0) + (void)gz_look(state); + + /* return 1 if transparent, 0 if processing a gzip stream */ + return state->direct; +} + +/* -- see zlib.h -- */ +int ZEXPORT gzclose_r(file) + gzFile file; +{ + int ret, err; + gz_statep state; + + /* get internal structure */ + if (file == NULL) + return Z_STREAM_ERROR; + state = (gz_statep)file; + + /* check that we're reading */ + if (state->mode != GZ_READ) + return Z_STREAM_ERROR; + + /* free memory and close file */ + if (state->size) { + inflateEnd(&(state->strm)); + free(state->out); + free(state->in); + } + err = state->err == Z_BUF_ERROR ? Z_BUF_ERROR : Z_OK; + gz_error(state, Z_OK, NULL); + free(state->path); + ret = close(state->fd); + free(state); + return ret ? Z_ERRNO : err; +} diff --git a/libs/zlib/gzwrite.c b/libs/zlib/gzwrite.c new file mode 100644 index 000000000..caa35b61a --- /dev/null +++ b/libs/zlib/gzwrite.c @@ -0,0 +1,593 @@ +/* gzwrite.c -- zlib functions for writing gzip files + * Copyright (C) 2004, 2005, 2010, 2011, 2012 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +#include "gzguts.h" + +/* Local functions */ +local int gz_init OF((gz_statep)); +local int gz_comp OF((gz_statep, int)); +local int gz_zero OF((gz_statep, z_off64_t)); + +/* Initialize state for writing a gzip file. Mark initialization by setting + state->size to non-zero. Return -1 on failure or 0 on success. */ +local int gz_init(state) + gz_statep state; +{ + int ret; + z_streamp strm = &(state->strm); + + /* allocate input buffer */ + state->in = malloc(state->want); + if (state->in == NULL) { + gz_error(state, Z_MEM_ERROR, "out of memory"); + return -1; + } + + /* only need output buffer and deflate state if compressing */ + if (!state->direct) { + /* allocate output buffer */ + state->out = malloc(state->want); + if (state->out == NULL) { + free(state->in); + gz_error(state, Z_MEM_ERROR, "out of memory"); + return -1; + } + + /* allocate deflate memory, set up for gzip compression */ + strm->zalloc = Z_NULL; + strm->zfree = Z_NULL; + strm->opaque = Z_NULL; + ret = deflateInit2(strm, state->level, Z_DEFLATED, + MAX_WBITS + 16, DEF_MEM_LEVEL, state->strategy); + if (ret != Z_OK) { + free(state->out); + free(state->in); + gz_error(state, Z_MEM_ERROR, "out of memory"); + return -1; + } + } + + /* mark state as initialized */ + state->size = state->want; + + /* initialize write buffer if compressing */ + if (!state->direct) { + strm->avail_out = state->size; + strm->next_out = state->out; + state->x.next = strm->next_out; + } + return 0; +} + +/* Compress whatever is at avail_in and next_in and write to the output file. + Return -1 if there is an error writing to the output file, otherwise 0. + flush is assumed to be a valid deflate() flush value. If flush is Z_FINISH, + then the deflate() state is reset to start a new gzip stream. If gz->direct + is true, then simply write to the output file without compressing, and + ignore flush. */ +local int gz_comp(state, flush) + gz_statep state; + int flush; +{ + int ret, got; + unsigned have; + z_streamp strm = &(state->strm); + + /* allocate memory if this is the first time through */ + if (state->size == 0 && gz_init(state) == -1) + return -1; + + /* write directly if requested */ + if (state->direct) { + got = write(state->fd, strm->next_in, strm->avail_in); + if (got < 0 || (unsigned)got != strm->avail_in) { + gz_error(state, Z_ERRNO, zstrerror()); + return -1; + } + strm->avail_in = 0; + return 0; + } + + /* run deflate() on provided input until it produces no more output */ + ret = Z_OK; + do { + /* write out current buffer contents if full, or if flushing, but if + doing Z_FINISH then don't write until we get to Z_STREAM_END */ + if (strm->avail_out == 0 || (flush != Z_NO_FLUSH && + (flush != Z_FINISH || ret == Z_STREAM_END))) { + have = (unsigned)(strm->next_out - state->x.next); + if (have && ((got = write(state->fd, state->x.next, have)) < 0 || + (unsigned)got != have)) { + gz_error(state, Z_ERRNO, zstrerror()); + return -1; + } + if (strm->avail_out == 0) { + strm->avail_out = state->size; + strm->next_out = state->out; + } + state->x.next = strm->next_out; + } + + /* compress */ + have = strm->avail_out; + ret = deflate(strm, flush); + if (ret == Z_STREAM_ERROR) { + gz_error(state, Z_STREAM_ERROR, + "internal error: deflate stream corrupt"); + return -1; + } + have -= strm->avail_out; + } while (have); + + /* if that completed a deflate stream, allow another to start */ + if (flush == Z_FINISH) + deflateReset(strm); + + /* all done, no errors */ + return 0; +} + +/* Compress len zeros to output. Return -1 on error, 0 on success. */ +local int gz_zero(state, len) + gz_statep state; + z_off64_t len; +{ + int first; + unsigned n; + z_streamp strm = &(state->strm); + + /* consume whatever's left in the input buffer */ + if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1) + return -1; + + /* compress len zeros (len guaranteed > 0) */ + first = 1; + while (len) { + n = GT_OFF(state->size) || (z_off64_t)state->size > len ? + (unsigned)len : state->size; + if (first) { + memset(state->in, 0, n); + first = 0; + } + strm->avail_in = n; + strm->next_in = state->in; + state->x.pos += n; + if (gz_comp(state, Z_NO_FLUSH) == -1) + return -1; + len -= n; + } + return 0; +} + +/* -- see zlib.h -- */ +int ZEXPORT gzwrite(file, buf, len) + gzFile file; + voidpc buf; + unsigned len; +{ + unsigned put = len; + unsigned n; + gz_statep state; + z_streamp strm; + + /* get internal structure */ + if (file == NULL) + return 0; + state = (gz_statep)file; + strm = &(state->strm); + + /* check that we're writing and that there's no error */ + if (state->mode != GZ_WRITE || state->err != Z_OK) + return 0; + + /* since an int is returned, make sure len fits in one, otherwise return + with an error (this avoids the flaw in the interface) */ + if ((int)len < 0) { + gz_error(state, Z_DATA_ERROR, "requested length does not fit in int"); + return 0; + } + + /* if len is zero, avoid unnecessary operations */ + if (len == 0) + return 0; + + /* allocate memory if this is the first time through */ + if (state->size == 0 && gz_init(state) == -1) + return 0; + + /* check for seek request */ + if (state->seek) { + state->seek = 0; + if (gz_zero(state, state->skip) == -1) + return 0; + } + + /* for small len, copy to input buffer, otherwise compress directly */ + if (len < state->size) { + /* copy to input buffer, compress when full */ + do { + if (strm->avail_in == 0) + strm->next_in = state->in; + n = state->size - strm->avail_in; + if (n > len) + n = len; + memcpy(strm->next_in + strm->avail_in, buf, n); + strm->avail_in += n; + state->x.pos += n; + buf = (char *)buf + n; + len -= n; + if (len && gz_comp(state, Z_NO_FLUSH) == -1) + return 0; + } while (len); + } + else { + /* consume whatever's left in the input buffer */ + if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1) + return 0; + + /* directly compress user buffer to file */ + strm->avail_in = len; + strm->next_in = (voidp)buf; + state->x.pos += len; + if (gz_comp(state, Z_NO_FLUSH) == -1) + return 0; + } + + /* input was all buffered or compressed (put will fit in int) */ + return (int)put; +} + +/* -- see zlib.h -- */ +int ZEXPORT gzputc(file, c) + gzFile file; + int c; +{ + unsigned char buf[1]; + gz_statep state; + z_streamp strm; + + /* get internal structure */ + if (file == NULL) + return -1; + state = (gz_statep)file; + strm = &(state->strm); + + /* check that we're writing and that there's no error */ + if (state->mode != GZ_WRITE || state->err != Z_OK) + return -1; + + /* check for seek request */ + if (state->seek) { + state->seek = 0; + if (gz_zero(state, state->skip) == -1) + return -1; + } + + /* try writing to input buffer for speed (state->size == 0 if buffer not + initialized) */ + if (strm->avail_in < state->size) { + if (strm->avail_in == 0) + strm->next_in = state->in; + strm->next_in[strm->avail_in++] = c; + state->x.pos++; + return c & 0xff; + } + + /* no room in buffer or not initialized, use gz_write() */ + buf[0] = c; + if (gzwrite(file, buf, 1) != 1) + return -1; + return c & 0xff; +} + +/* -- see zlib.h -- */ +int ZEXPORT gzputs(file, str) + gzFile file; + const char *str; +{ + int ret; + unsigned len; + + /* write string */ + len = (unsigned)strlen(str); + ret = gzwrite(file, str, len); + return ret == 0 && len != 0 ? -1 : ret; +} + +#if defined(STDC) || defined(Z_HAVE_STDARG_H) +#include + +/* -- see zlib.h -- */ +int ZEXPORTVA gzprintf (gzFile file, const char *format, ...) +{ + int size, len; + gz_statep state; + z_streamp strm; + va_list va; + + /* get internal structure */ + if (file == NULL) + return -1; + state = (gz_statep)file; + strm = &(state->strm); + + /* check that we're writing and that there's no error */ + if (state->mode != GZ_WRITE || state->err != Z_OK) + return 0; + + /* make sure we have some buffer space */ + if (state->size == 0 && gz_init(state) == -1) + return 0; + + /* check for seek request */ + if (state->seek) { + state->seek = 0; + if (gz_zero(state, state->skip) == -1) + return 0; + } + + /* consume whatever's left in the input buffer */ + if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1) + return 0; + + /* do the printf() into the input buffer, put length in len */ + size = (int)(state->size); + state->in[size - 1] = 0; + va_start(va, format); +#ifdef NO_vsnprintf +# ifdef HAS_vsprintf_void + (void)vsprintf(state->in, format, va); + va_end(va); + for (len = 0; len < size; len++) + if (state->in[len] == 0) break; +# else + len = vsprintf(state->in, format, va); + va_end(va); +# endif +#else +# ifdef HAS_vsnprintf_void + (void)vsnprintf(state->in, size, format, va); + va_end(va); + len = strlen(state->in); +# else + len = vsnprintf((char *)(state->in), size, format, va); + va_end(va); +# endif +#endif + + /* check that printf() results fit in buffer */ + if (len <= 0 || len >= (int)size || state->in[size - 1] != 0) + return 0; + + /* update buffer and position, defer compression until needed */ + strm->avail_in = (unsigned)len; + strm->next_in = state->in; + state->x.pos += len; + return len; +} + +#else /* !STDC && !Z_HAVE_STDARG_H */ + +/* -- see zlib.h -- */ +int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, + a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) + gzFile file; + const char *format; + int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, + a11, a12, a13, a14, a15, a16, a17, a18, a19, a20; +{ + int size, len; + gz_statep state; + z_streamp strm; + + /* get internal structure */ + if (file == NULL) + return -1; + state = (gz_statep)file; + strm = &(state->strm); + + /* check that can really pass pointer in ints */ + if (sizeof(int) != sizeof(void *)) + return 0; + + /* check that we're writing and that there's no error */ + if (state->mode != GZ_WRITE || state->err != Z_OK) + return 0; + + /* make sure we have some buffer space */ + if (state->size == 0 && gz_init(state) == -1) + return 0; + + /* check for seek request */ + if (state->seek) { + state->seek = 0; + if (gz_zero(state, state->skip) == -1) + return 0; + } + + /* consume whatever's left in the input buffer */ + if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1) + return 0; + + /* do the printf() into the input buffer, put length in len */ + size = (int)(state->size); + state->in[size - 1] = 0; +#ifdef NO_snprintf +# ifdef HAS_sprintf_void + sprintf(state->in, format, a1, a2, a3, a4, a5, a6, a7, a8, + a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); + for (len = 0; len < size; len++) + if (state->in[len] == 0) break; +# else + len = sprintf(state->in, format, a1, a2, a3, a4, a5, a6, a7, a8, + a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); +# endif +#else +# ifdef HAS_snprintf_void + snprintf(state->in, size, format, a1, a2, a3, a4, a5, a6, a7, a8, + a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); + len = strlen(state->in); +# else + len = snprintf(state->in, size, format, a1, a2, a3, a4, a5, a6, a7, a8, + a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); +# endif +#endif + + /* check that printf() results fit in buffer */ + if (len <= 0 || len >= (int)size || state->in[size - 1] != 0) + return 0; + + /* update buffer and position, defer compression until needed */ + strm->avail_in = (unsigned)len; + strm->next_in = state->in; + state->x.pos += len; + return len; +} + +#endif + +/* -- see zlib.h -- */ +int ZEXPORT gzflush(file, flush) + gzFile file; + int flush; +{ + gz_statep state; + + /* get internal structure */ + if (file == NULL) + return -1; + state = (gz_statep)file; + + /* check that we're writing and that there's no error */ + if (state->mode != GZ_WRITE || state->err != Z_OK) + return Z_STREAM_ERROR; + + /* check flush parameter */ + if (flush < 0 || flush > Z_FINISH) + return Z_STREAM_ERROR; + + /* check for seek request */ + if (state->seek) { + state->seek = 0; + if (gz_zero(state, state->skip) == -1) + return -1; + } + + /* compress remaining data with requested flush */ + gz_comp(state, flush); + return state->err; +} + +/* -- see zlib.h -- */ +int ZEXPORT gzsetparams(file, level, strategy) + gzFile file; + int level; + int strategy; +{ + gz_statep state; + z_streamp strm; + + /* get internal structure */ + if (file == NULL) + return Z_STREAM_ERROR; + state = (gz_statep)file; + strm = &(state->strm); + + /* check that we're writing and that there's no error */ + if (state->mode != GZ_WRITE || state->err != Z_OK) + return Z_STREAM_ERROR; + + /* if no change is requested, then do nothing */ + if (level == state->level && strategy == state->strategy) + return Z_OK; + + /* check for seek request */ + if (state->seek) { + state->seek = 0; + if (gz_zero(state, state->skip) == -1) + return -1; + } + + /* change compression parameters for subsequent input */ + if (state->size) { + /* flush previous input with previous parameters before changing */ + if (strm->avail_in && gz_comp(state, Z_PARTIAL_FLUSH) == -1) + return state->err; + deflateParams(strm, level, strategy); + } + state->level = level; + state->strategy = strategy; + return Z_OK; +} + +/* -- see zlib.h -- */ +int ZEXPORT gzclose_w(file) + gzFile file; +{ + int ret = Z_OK; + gz_statep state; + + /* get internal structure */ + if (file == NULL) + return Z_STREAM_ERROR; + state = (gz_statep)file; + + /* check that we're writing */ + if (state->mode != GZ_WRITE) + return Z_STREAM_ERROR; + + /* check for seek request */ + if (state->seek) { + state->seek = 0; + if (gz_zero(state, state->skip) == -1) + ret = state->err; + } + + /* flush, free memory, and close file */ + if (gz_comp(state, Z_FINISH) == -1) + ret = state->err; + if (!state->direct) { + (void)deflateEnd(&(state->strm)); + free(state->out); + } + free(state->in); + gz_error(state, Z_OK, NULL); + free(state->path); + if (close(state->fd) == -1) + ret = Z_ERRNO; + free(state); + return ret; +} + +/* used by zlibVersion() to get the vsnprintf story from the horse's mouth */ +unsigned long ZEXPORT gzflags() +{ + unsigned long flags = 0; +#if defined(STDC) || defined(Z_HAVE_STDARG_H) +# ifdef NO_vsnprintf + flags += 1L << 25; +# ifdef HAS_vsprintf_void + flags += 1L << 26; +# endif +# else +# ifdef HAS_vsnprintf_void + flags += 1L << 26; +# endif +# endif +#else + flags += 1L << 24; +# ifdef NO_snprintf + flags += 1L << 25; +# ifdef HAS_sprintf_void + flags += 1L << 26; +# endif +# else +# ifdef HAS_snprintf_void + flags += 1L << 26; +# endif +# endif +#endif + return flags; +} diff --git a/libs/zlib/infback.c b/libs/zlib/infback.c new file mode 100644 index 000000000..981aff17c --- /dev/null +++ b/libs/zlib/infback.c @@ -0,0 +1,640 @@ +/* infback.c -- inflate using a call-back interface + * Copyright (C) 1995-2011 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* + This code is largely copied from inflate.c. Normally either infback.o or + inflate.o would be linked into an application--not both. The interface + with inffast.c is retained so that optimized assembler-coded versions of + inflate_fast() can be used with either inflate.c or infback.c. + */ + +#include "zutil.h" +#include "inftrees.h" +#include "inflate.h" +#include "inffast.h" + +/* function prototypes */ +local void fixedtables OF((struct inflate_state FAR *state)); + +/* + strm provides memory allocation functions in zalloc and zfree, or + Z_NULL to use the library memory allocation functions. + + windowBits is in the range 8..15, and window is a user-supplied + window and output buffer that is 2**windowBits bytes. + */ +int ZEXPORT inflateBackInit_(strm, windowBits, window, version, stream_size) +z_streamp strm; +int windowBits; +unsigned char FAR *window; +const char *version; +int stream_size; +{ + struct inflate_state FAR *state; + + if (version == Z_NULL || version[0] != ZLIB_VERSION[0] || + stream_size != (int)(sizeof(z_stream))) + return Z_VERSION_ERROR; + if (strm == Z_NULL || window == Z_NULL || + windowBits < 8 || windowBits > 15) + return Z_STREAM_ERROR; + strm->msg = Z_NULL; /* in case we return an error */ + if (strm->zalloc == (alloc_func)0) { +#ifdef Z_SOLO + return Z_STREAM_ERROR; +#else + strm->zalloc = zcalloc; + strm->opaque = (voidpf)0; +#endif + } + if (strm->zfree == (free_func)0) +#ifdef Z_SOLO + return Z_STREAM_ERROR; +#else + strm->zfree = zcfree; +#endif + state = (struct inflate_state FAR *)ZALLOC(strm, 1, + sizeof(struct inflate_state)); + if (state == Z_NULL) return Z_MEM_ERROR; + Tracev((stderr, "inflate: allocated\n")); + strm->state = (struct internal_state FAR *)state; + state->dmax = 32768U; + state->wbits = windowBits; + state->wsize = 1U << windowBits; + state->window = window; + state->wnext = 0; + state->whave = 0; + return Z_OK; +} + +/* + Return state with length and distance decoding tables and index sizes set to + fixed code decoding. Normally this returns fixed tables from inffixed.h. + If BUILDFIXED is defined, then instead this routine builds the tables the + first time it's called, and returns those tables the first time and + thereafter. This reduces the size of the code by about 2K bytes, in + exchange for a little execution time. However, BUILDFIXED should not be + used for threaded applications, since the rewriting of the tables and virgin + may not be thread-safe. + */ +local void fixedtables(state) +struct inflate_state FAR *state; +{ +#ifdef BUILDFIXED + static int virgin = 1; + static code *lenfix, *distfix; + static code fixed[544]; + + /* build fixed huffman tables if first call (may not be thread safe) */ + if (virgin) { + unsigned sym, bits; + static code *next; + + /* literal/length table */ + sym = 0; + while (sym < 144) state->lens[sym++] = 8; + while (sym < 256) state->lens[sym++] = 9; + while (sym < 280) state->lens[sym++] = 7; + while (sym < 288) state->lens[sym++] = 8; + next = fixed; + lenfix = next; + bits = 9; + inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work); + + /* distance table */ + sym = 0; + while (sym < 32) state->lens[sym++] = 5; + distfix = next; + bits = 5; + inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work); + + /* do this just once */ + virgin = 0; + } +#else /* !BUILDFIXED */ +# include "inffixed.h" +#endif /* BUILDFIXED */ + state->lencode = lenfix; + state->lenbits = 9; + state->distcode = distfix; + state->distbits = 5; +} + +/* Macros for inflateBack(): */ + +/* Load returned state from inflate_fast() */ +#define LOAD() \ + do { \ + put = strm->next_out; \ + left = strm->avail_out; \ + next = strm->next_in; \ + have = strm->avail_in; \ + hold = state->hold; \ + bits = state->bits; \ + } while (0) + +/* Set state from registers for inflate_fast() */ +#define RESTORE() \ + do { \ + strm->next_out = put; \ + strm->avail_out = left; \ + strm->next_in = next; \ + strm->avail_in = have; \ + state->hold = hold; \ + state->bits = bits; \ + } while (0) + +/* Clear the input bit accumulator */ +#define INITBITS() \ + do { \ + hold = 0; \ + bits = 0; \ + } while (0) + +/* Assure that some input is available. If input is requested, but denied, + then return a Z_BUF_ERROR from inflateBack(). */ +#define PULL() \ + do { \ + if (have == 0) { \ + have = in(in_desc, &next); \ + if (have == 0) { \ + next = Z_NULL; \ + ret = Z_BUF_ERROR; \ + goto inf_leave; \ + } \ + } \ + } while (0) + +/* Get a byte of input into the bit accumulator, or return from inflateBack() + with an error if there is no input available. */ +#define PULLBYTE() \ + do { \ + PULL(); \ + have--; \ + hold += (unsigned long)(*next++) << bits; \ + bits += 8; \ + } while (0) + +/* Assure that there are at least n bits in the bit accumulator. If there is + not enough available input to do that, then return from inflateBack() with + an error. */ +#define NEEDBITS(n) \ + do { \ + while (bits < (unsigned)(n)) \ + PULLBYTE(); \ + } while (0) + +/* Return the low n bits of the bit accumulator (n < 16) */ +#define BITS(n) \ + ((unsigned)hold & ((1U << (n)) - 1)) + +/* Remove n bits from the bit accumulator */ +#define DROPBITS(n) \ + do { \ + hold >>= (n); \ + bits -= (unsigned)(n); \ + } while (0) + +/* Remove zero to seven bits as needed to go to a byte boundary */ +#define BYTEBITS() \ + do { \ + hold >>= bits & 7; \ + bits -= bits & 7; \ + } while (0) + +/* Assure that some output space is available, by writing out the window + if it's full. If the write fails, return from inflateBack() with a + Z_BUF_ERROR. */ +#define ROOM() \ + do { \ + if (left == 0) { \ + put = state->window; \ + left = state->wsize; \ + state->whave = left; \ + if (out(out_desc, put, left)) { \ + ret = Z_BUF_ERROR; \ + goto inf_leave; \ + } \ + } \ + } while (0) + +/* + strm provides the memory allocation functions and window buffer on input, + and provides information on the unused input on return. For Z_DATA_ERROR + returns, strm will also provide an error message. + + in() and out() are the call-back input and output functions. When + inflateBack() needs more input, it calls in(). When inflateBack() has + filled the window with output, or when it completes with data in the + window, it calls out() to write out the data. The application must not + change the provided input until in() is called again or inflateBack() + returns. The application must not change the window/output buffer until + inflateBack() returns. + + in() and out() are called with a descriptor parameter provided in the + inflateBack() call. This parameter can be a structure that provides the + information required to do the read or write, as well as accumulated + information on the input and output such as totals and check values. + + in() should return zero on failure. out() should return non-zero on + failure. If either in() or out() fails, than inflateBack() returns a + Z_BUF_ERROR. strm->next_in can be checked for Z_NULL to see whether it + was in() or out() that caused in the error. Otherwise, inflateBack() + returns Z_STREAM_END on success, Z_DATA_ERROR for an deflate format + error, or Z_MEM_ERROR if it could not allocate memory for the state. + inflateBack() can also return Z_STREAM_ERROR if the input parameters + are not correct, i.e. strm is Z_NULL or the state was not initialized. + */ +int ZEXPORT inflateBack(strm, in, in_desc, out, out_desc) +z_streamp strm; +in_func in; +void FAR *in_desc; +out_func out; +void FAR *out_desc; +{ + struct inflate_state FAR *state; + unsigned char FAR *next; /* next input */ + unsigned char FAR *put; /* next output */ + unsigned have, left; /* available input and output */ + unsigned long hold; /* bit buffer */ + unsigned bits; /* bits in bit buffer */ + unsigned copy; /* number of stored or match bytes to copy */ + unsigned char FAR *from; /* where to copy match bytes from */ + code here; /* current decoding table entry */ + code last; /* parent table entry */ + unsigned len; /* length to copy for repeats, bits to drop */ + int ret; /* return code */ + static const unsigned short order[19] = /* permutation of code lengths */ + {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; + + /* Check that the strm exists and that the state was initialized */ + if (strm == Z_NULL || strm->state == Z_NULL) + return Z_STREAM_ERROR; + state = (struct inflate_state FAR *)strm->state; + + /* Reset the state */ + strm->msg = Z_NULL; + state->mode = TYPE; + state->last = 0; + state->whave = 0; + next = strm->next_in; + have = next != Z_NULL ? strm->avail_in : 0; + hold = 0; + bits = 0; + put = state->window; + left = state->wsize; + + /* Inflate until end of block marked as last */ + for (;;) + switch (state->mode) { + case TYPE: + /* determine and dispatch block type */ + if (state->last) { + BYTEBITS(); + state->mode = DONE; + break; + } + NEEDBITS(3); + state->last = BITS(1); + DROPBITS(1); + switch (BITS(2)) { + case 0: /* stored block */ + Tracev((stderr, "inflate: stored block%s\n", + state->last ? " (last)" : "")); + state->mode = STORED; + break; + case 1: /* fixed block */ + fixedtables(state); + Tracev((stderr, "inflate: fixed codes block%s\n", + state->last ? " (last)" : "")); + state->mode = LEN; /* decode codes */ + break; + case 2: /* dynamic block */ + Tracev((stderr, "inflate: dynamic codes block%s\n", + state->last ? " (last)" : "")); + state->mode = TABLE; + break; + case 3: + strm->msg = (char *)"invalid block type"; + state->mode = BAD; + } + DROPBITS(2); + break; + + case STORED: + /* get and verify stored block length */ + BYTEBITS(); /* go to byte boundary */ + NEEDBITS(32); + if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) { + strm->msg = (char *)"invalid stored block lengths"; + state->mode = BAD; + break; + } + state->length = (unsigned)hold & 0xffff; + Tracev((stderr, "inflate: stored length %u\n", + state->length)); + INITBITS(); + + /* copy stored block from input to output */ + while (state->length != 0) { + copy = state->length; + PULL(); + ROOM(); + if (copy > have) copy = have; + if (copy > left) copy = left; + zmemcpy(put, next, copy); + have -= copy; + next += copy; + left -= copy; + put += copy; + state->length -= copy; + } + Tracev((stderr, "inflate: stored end\n")); + state->mode = TYPE; + break; + + case TABLE: + /* get dynamic table entries descriptor */ + NEEDBITS(14); + state->nlen = BITS(5) + 257; + DROPBITS(5); + state->ndist = BITS(5) + 1; + DROPBITS(5); + state->ncode = BITS(4) + 4; + DROPBITS(4); +#ifndef PKZIP_BUG_WORKAROUND + if (state->nlen > 286 || state->ndist > 30) { + strm->msg = (char *)"too many length or distance symbols"; + state->mode = BAD; + break; + } +#endif + Tracev((stderr, "inflate: table sizes ok\n")); + + /* get code length code lengths (not a typo) */ + state->have = 0; + while (state->have < state->ncode) { + NEEDBITS(3); + state->lens[order[state->have++]] = (unsigned short)BITS(3); + DROPBITS(3); + } + while (state->have < 19) + state->lens[order[state->have++]] = 0; + state->next = state->codes; + state->lencode = (code const FAR *)(state->next); + state->lenbits = 7; + ret = inflate_table(CODES, state->lens, 19, &(state->next), + &(state->lenbits), state->work); + if (ret) { + strm->msg = (char *)"invalid code lengths set"; + state->mode = BAD; + break; + } + Tracev((stderr, "inflate: code lengths ok\n")); + + /* get length and distance code code lengths */ + state->have = 0; + while (state->have < state->nlen + state->ndist) { + for (;;) { + here = state->lencode[BITS(state->lenbits)]; + if ((unsigned)(here.bits) <= bits) break; + PULLBYTE(); + } + if (here.val < 16) { + DROPBITS(here.bits); + state->lens[state->have++] = here.val; + } + else { + if (here.val == 16) { + NEEDBITS(here.bits + 2); + DROPBITS(here.bits); + if (state->have == 0) { + strm->msg = (char *)"invalid bit length repeat"; + state->mode = BAD; + break; + } + len = (unsigned)(state->lens[state->have - 1]); + copy = 3 + BITS(2); + DROPBITS(2); + } + else if (here.val == 17) { + NEEDBITS(here.bits + 3); + DROPBITS(here.bits); + len = 0; + copy = 3 + BITS(3); + DROPBITS(3); + } + else { + NEEDBITS(here.bits + 7); + DROPBITS(here.bits); + len = 0; + copy = 11 + BITS(7); + DROPBITS(7); + } + if (state->have + copy > state->nlen + state->ndist) { + strm->msg = (char *)"invalid bit length repeat"; + state->mode = BAD; + break; + } + while (copy--) + state->lens[state->have++] = (unsigned short)len; + } + } + + /* handle error breaks in while */ + if (state->mode == BAD) break; + + /* check for end-of-block code (better have one) */ + if (state->lens[256] == 0) { + strm->msg = (char *)"invalid code -- missing end-of-block"; + state->mode = BAD; + break; + } + + /* build code tables -- note: do not change the lenbits or distbits + values here (9 and 6) without reading the comments in inftrees.h + concerning the ENOUGH constants, which depend on those values */ + state->next = state->codes; + state->lencode = (code const FAR *)(state->next); + state->lenbits = 9; + ret = inflate_table(LENS, state->lens, state->nlen, &(state->next), + &(state->lenbits), state->work); + if (ret) { + strm->msg = (char *)"invalid literal/lengths set"; + state->mode = BAD; + break; + } + state->distcode = (code const FAR *)(state->next); + state->distbits = 6; + ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist, + &(state->next), &(state->distbits), state->work); + if (ret) { + strm->msg = (char *)"invalid distances set"; + state->mode = BAD; + break; + } + Tracev((stderr, "inflate: codes ok\n")); + state->mode = LEN; + + case LEN: + /* use inflate_fast() if we have enough input and output */ + if (have >= 6 && left >= 258) { + RESTORE(); + if (state->whave < state->wsize) + state->whave = state->wsize - left; + inflate_fast(strm, state->wsize); + LOAD(); + break; + } + + /* get a literal, length, or end-of-block code */ + for (;;) { + here = state->lencode[BITS(state->lenbits)]; + if ((unsigned)(here.bits) <= bits) break; + PULLBYTE(); + } + if (here.op && (here.op & 0xf0) == 0) { + last = here; + for (;;) { + here = state->lencode[last.val + + (BITS(last.bits + last.op) >> last.bits)]; + if ((unsigned)(last.bits + here.bits) <= bits) break; + PULLBYTE(); + } + DROPBITS(last.bits); + } + DROPBITS(here.bits); + state->length = (unsigned)here.val; + + /* process literal */ + if (here.op == 0) { + Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ? + "inflate: literal '%c'\n" : + "inflate: literal 0x%02x\n", here.val)); + ROOM(); + *put++ = (unsigned char)(state->length); + left--; + state->mode = LEN; + break; + } + + /* process end of block */ + if (here.op & 32) { + Tracevv((stderr, "inflate: end of block\n")); + state->mode = TYPE; + break; + } + + /* invalid code */ + if (here.op & 64) { + strm->msg = (char *)"invalid literal/length code"; + state->mode = BAD; + break; + } + + /* length code -- get extra bits, if any */ + state->extra = (unsigned)(here.op) & 15; + if (state->extra != 0) { + NEEDBITS(state->extra); + state->length += BITS(state->extra); + DROPBITS(state->extra); + } + Tracevv((stderr, "inflate: length %u\n", state->length)); + + /* get distance code */ + for (;;) { + here = state->distcode[BITS(state->distbits)]; + if ((unsigned)(here.bits) <= bits) break; + PULLBYTE(); + } + if ((here.op & 0xf0) == 0) { + last = here; + for (;;) { + here = state->distcode[last.val + + (BITS(last.bits + last.op) >> last.bits)]; + if ((unsigned)(last.bits + here.bits) <= bits) break; + PULLBYTE(); + } + DROPBITS(last.bits); + } + DROPBITS(here.bits); + if (here.op & 64) { + strm->msg = (char *)"invalid distance code"; + state->mode = BAD; + break; + } + state->offset = (unsigned)here.val; + + /* get distance extra bits, if any */ + state->extra = (unsigned)(here.op) & 15; + if (state->extra != 0) { + NEEDBITS(state->extra); + state->offset += BITS(state->extra); + DROPBITS(state->extra); + } + if (state->offset > state->wsize - (state->whave < state->wsize ? + left : 0)) { + strm->msg = (char *)"invalid distance too far back"; + state->mode = BAD; + break; + } + Tracevv((stderr, "inflate: distance %u\n", state->offset)); + + /* copy match from window to output */ + do { + ROOM(); + copy = state->wsize - state->offset; + if (copy < left) { + from = put + copy; + copy = left - copy; + } + else { + from = put - state->offset; + copy = left; + } + if (copy > state->length) copy = state->length; + state->length -= copy; + left -= copy; + do { + *put++ = *from++; + } while (--copy); + } while (state->length != 0); + break; + + case DONE: + /* inflate stream terminated properly -- write leftover output */ + ret = Z_STREAM_END; + if (left < state->wsize) { + if (out(out_desc, state->window, state->wsize - left)) + ret = Z_BUF_ERROR; + } + goto inf_leave; + + case BAD: + ret = Z_DATA_ERROR; + goto inf_leave; + + default: /* can't happen, but makes compilers happy */ + ret = Z_STREAM_ERROR; + goto inf_leave; + } + + /* Return unused input */ + inf_leave: + strm->next_in = next; + strm->avail_in = have; + return ret; +} + +int ZEXPORT inflateBackEnd(strm) +z_streamp strm; +{ + if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0) + return Z_STREAM_ERROR; + ZFREE(strm, strm->state); + strm->state = Z_NULL; + Tracev((stderr, "inflate: end\n")); + return Z_OK; +} diff --git a/libs/zlib/inffast.c b/libs/zlib/inffast.c new file mode 100644 index 000000000..2f1d60b43 --- /dev/null +++ b/libs/zlib/inffast.c @@ -0,0 +1,340 @@ +/* inffast.c -- fast decoding + * Copyright (C) 1995-2008, 2010 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +#include "zutil.h" +#include "inftrees.h" +#include "inflate.h" +#include "inffast.h" + +#ifndef ASMINF + +/* Allow machine dependent optimization for post-increment or pre-increment. + Based on testing to date, + Pre-increment preferred for: + - PowerPC G3 (Adler) + - MIPS R5000 (Randers-Pehrson) + Post-increment preferred for: + - none + No measurable difference: + - Pentium III (Anderson) + - M68060 (Nikl) + */ +#ifdef POSTINC +# define OFF 0 +# define PUP(a) *(a)++ +#else +# define OFF 1 +# define PUP(a) *++(a) +#endif + +/* + Decode literal, length, and distance codes and write out the resulting + literal and match bytes until either not enough input or output is + available, an end-of-block is encountered, or a data error is encountered. + When large enough input and output buffers are supplied to inflate(), for + example, a 16K input buffer and a 64K output buffer, more than 95% of the + inflate execution time is spent in this routine. + + Entry assumptions: + + state->mode == LEN + strm->avail_in >= 6 + strm->avail_out >= 258 + start >= strm->avail_out + state->bits < 8 + + On return, state->mode is one of: + + LEN -- ran out of enough output space or enough available input + TYPE -- reached end of block code, inflate() to interpret next block + BAD -- error in block data + + Notes: + + - The maximum input bits used by a length/distance pair is 15 bits for the + length code, 5 bits for the length extra, 15 bits for the distance code, + and 13 bits for the distance extra. This totals 48 bits, or six bytes. + Therefore if strm->avail_in >= 6, then there is enough input to avoid + checking for available input while decoding. + + - The maximum bytes that a single length/distance pair can output is 258 + bytes, which is the maximum length that can be coded. inflate_fast() + requires strm->avail_out >= 258 for each loop to avoid checking for + output space. + */ +void ZLIB_INTERNAL inflate_fast(strm, start) +z_streamp strm; +unsigned start; /* inflate()'s starting value for strm->avail_out */ +{ + struct inflate_state FAR *state; + unsigned char FAR *in; /* local strm->next_in */ + unsigned char FAR *last; /* while in < last, enough input available */ + unsigned char FAR *out; /* local strm->next_out */ + unsigned char FAR *beg; /* inflate()'s initial strm->next_out */ + unsigned char FAR *end; /* while out < end, enough space available */ +#ifdef INFLATE_STRICT + unsigned dmax; /* maximum distance from zlib header */ +#endif + unsigned wsize; /* window size or zero if not using window */ + unsigned whave; /* valid bytes in the window */ + unsigned wnext; /* window write index */ + unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */ + unsigned long hold; /* local strm->hold */ + unsigned bits; /* local strm->bits */ + code const FAR *lcode; /* local strm->lencode */ + code const FAR *dcode; /* local strm->distcode */ + unsigned lmask; /* mask for first level of length codes */ + unsigned dmask; /* mask for first level of distance codes */ + code here; /* retrieved table entry */ + unsigned op; /* code bits, operation, extra bits, or */ + /* window position, window bytes to copy */ + unsigned len; /* match length, unused bytes */ + unsigned dist; /* match distance */ + unsigned char FAR *from; /* where to copy match from */ + + /* copy state to local variables */ + state = (struct inflate_state FAR *)strm->state; + in = strm->next_in - OFF; + last = in + (strm->avail_in - 5); + out = strm->next_out - OFF; + beg = out - (start - strm->avail_out); + end = out + (strm->avail_out - 257); +#ifdef INFLATE_STRICT + dmax = state->dmax; +#endif + wsize = state->wsize; + whave = state->whave; + wnext = state->wnext; + window = state->window; + hold = state->hold; + bits = state->bits; + lcode = state->lencode; + dcode = state->distcode; + lmask = (1U << state->lenbits) - 1; + dmask = (1U << state->distbits) - 1; + + /* decode literals and length/distances until end-of-block or not enough + input data or output space */ + do { + if (bits < 15) { + hold += (unsigned long)(PUP(in)) << bits; + bits += 8; + hold += (unsigned long)(PUP(in)) << bits; + bits += 8; + } + here = lcode[hold & lmask]; + dolen: + op = (unsigned)(here.bits); + hold >>= op; + bits -= op; + op = (unsigned)(here.op); + if (op == 0) { /* literal */ + Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ? + "inflate: literal '%c'\n" : + "inflate: literal 0x%02x\n", here.val)); + PUP(out) = (unsigned char)(here.val); + } + else if (op & 16) { /* length base */ + len = (unsigned)(here.val); + op &= 15; /* number of extra bits */ + if (op) { + if (bits < op) { + hold += (unsigned long)(PUP(in)) << bits; + bits += 8; + } + len += (unsigned)hold & ((1U << op) - 1); + hold >>= op; + bits -= op; + } + Tracevv((stderr, "inflate: length %u\n", len)); + if (bits < 15) { + hold += (unsigned long)(PUP(in)) << bits; + bits += 8; + hold += (unsigned long)(PUP(in)) << bits; + bits += 8; + } + here = dcode[hold & dmask]; + dodist: + op = (unsigned)(here.bits); + hold >>= op; + bits -= op; + op = (unsigned)(here.op); + if (op & 16) { /* distance base */ + dist = (unsigned)(here.val); + op &= 15; /* number of extra bits */ + if (bits < op) { + hold += (unsigned long)(PUP(in)) << bits; + bits += 8; + if (bits < op) { + hold += (unsigned long)(PUP(in)) << bits; + bits += 8; + } + } + dist += (unsigned)hold & ((1U << op) - 1); +#ifdef INFLATE_STRICT + if (dist > dmax) { + strm->msg = (char *)"invalid distance too far back"; + state->mode = BAD; + break; + } +#endif + hold >>= op; + bits -= op; + Tracevv((stderr, "inflate: distance %u\n", dist)); + op = (unsigned)(out - beg); /* max distance in output */ + if (dist > op) { /* see if copy from window */ + op = dist - op; /* distance back in window */ + if (op > whave) { + if (state->sane) { + strm->msg = + (char *)"invalid distance too far back"; + state->mode = BAD; + break; + } +#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR + if (len <= op - whave) { + do { + PUP(out) = 0; + } while (--len); + continue; + } + len -= op - whave; + do { + PUP(out) = 0; + } while (--op > whave); + if (op == 0) { + from = out - dist; + do { + PUP(out) = PUP(from); + } while (--len); + continue; + } +#endif + } + from = window - OFF; + if (wnext == 0) { /* very common case */ + from += wsize - op; + if (op < len) { /* some from window */ + len -= op; + do { + PUP(out) = PUP(from); + } while (--op); + from = out - dist; /* rest from output */ + } + } + else if (wnext < op) { /* wrap around window */ + from += wsize + wnext - op; + op -= wnext; + if (op < len) { /* some from end of window */ + len -= op; + do { + PUP(out) = PUP(from); + } while (--op); + from = window - OFF; + if (wnext < len) { /* some from start of window */ + op = wnext; + len -= op; + do { + PUP(out) = PUP(from); + } while (--op); + from = out - dist; /* rest from output */ + } + } + } + else { /* contiguous in window */ + from += wnext - op; + if (op < len) { /* some from window */ + len -= op; + do { + PUP(out) = PUP(from); + } while (--op); + from = out - dist; /* rest from output */ + } + } + while (len > 2) { + PUP(out) = PUP(from); + PUP(out) = PUP(from); + PUP(out) = PUP(from); + len -= 3; + } + if (len) { + PUP(out) = PUP(from); + if (len > 1) + PUP(out) = PUP(from); + } + } + else { + from = out - dist; /* copy direct from output */ + do { /* minimum length is three */ + PUP(out) = PUP(from); + PUP(out) = PUP(from); + PUP(out) = PUP(from); + len -= 3; + } while (len > 2); + if (len) { + PUP(out) = PUP(from); + if (len > 1) + PUP(out) = PUP(from); + } + } + } + else if ((op & 64) == 0) { /* 2nd level distance code */ + here = dcode[here.val + (hold & ((1U << op) - 1))]; + goto dodist; + } + else { + strm->msg = (char *)"invalid distance code"; + state->mode = BAD; + break; + } + } + else if ((op & 64) == 0) { /* 2nd level length code */ + here = lcode[here.val + (hold & ((1U << op) - 1))]; + goto dolen; + } + else if (op & 32) { /* end-of-block */ + Tracevv((stderr, "inflate: end of block\n")); + state->mode = TYPE; + break; + } + else { + strm->msg = (char *)"invalid literal/length code"; + state->mode = BAD; + break; + } + } while (in < last && out < end); + + /* return unused bytes (on entry, bits < 8, so in won't go too far back) */ + len = bits >> 3; + in -= len; + bits -= len << 3; + hold &= (1U << bits) - 1; + + /* update state and return */ + strm->next_in = in + OFF; + strm->next_out = out + OFF; + strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last)); + strm->avail_out = (unsigned)(out < end ? + 257 + (end - out) : 257 - (out - end)); + state->hold = hold; + state->bits = bits; + return; +} + +/* + inflate_fast() speedups that turned out slower (on a PowerPC G3 750CXe): + - Using bit fields for code structure + - Different op definition to avoid & for extra bits (do & for table bits) + - Three separate decoding do-loops for direct, window, and wnext == 0 + - Special case for distance > 1 copies to do overlapped load and store copy + - Explicit branch predictions (based on measured branch probabilities) + - Deferring match copy and interspersed it with decoding subsequent codes + - Swapping literal/length else + - Swapping window/direct else + - Larger unrolled copy loops (three is about right) + - Moving len -= 3 statement into middle of loop + */ + +#endif /* !ASMINF */ diff --git a/libs/zlib/inffast.h b/libs/zlib/inffast.h new file mode 100644 index 000000000..e5c1aa4ca --- /dev/null +++ b/libs/zlib/inffast.h @@ -0,0 +1,11 @@ +/* inffast.h -- header to use inffast.c + * Copyright (C) 1995-2003, 2010 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* WARNING: this file should *not* be used by applications. It is + part of the implementation of the compression library and is + subject to change. Applications should only use zlib.h. + */ + +void ZLIB_INTERNAL inflate_fast OF((z_streamp strm, unsigned start)); diff --git a/libs/zlib/inffixed.h b/libs/zlib/inffixed.h new file mode 100644 index 000000000..d62832776 --- /dev/null +++ b/libs/zlib/inffixed.h @@ -0,0 +1,94 @@ + /* inffixed.h -- table for decoding fixed codes + * Generated automatically by makefixed(). + */ + + /* WARNING: this file should *not* be used by applications. + It is part of the implementation of this library and is + subject to change. Applications should only use zlib.h. + */ + + static const code lenfix[512] = { + {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48}, + {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128}, + {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59}, + {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176}, + {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20}, + {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100}, + {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8}, + {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216}, + {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76}, + {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114}, + {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2}, + {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148}, + {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42}, + {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86}, + {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15}, + {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236}, + {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62}, + {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142}, + {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31}, + {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162}, + {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25}, + {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105}, + {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4}, + {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202}, + {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69}, + {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125}, + {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13}, + {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195}, + {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35}, + {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91}, + {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19}, + {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246}, + {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55}, + {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135}, + {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99}, + {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190}, + {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16}, + {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96}, + {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6}, + {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209}, + {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72}, + {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116}, + {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4}, + {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153}, + {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44}, + {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82}, + {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11}, + {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229}, + {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58}, + {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138}, + {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51}, + {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173}, + {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30}, + {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110}, + {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0}, + {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195}, + {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65}, + {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121}, + {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9}, + {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258}, + {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37}, + {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93}, + {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23}, + {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251}, + {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51}, + {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131}, + {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67}, + {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183}, + {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23}, + {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103}, + {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9}, + {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223}, + {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79}, + {0,9,255} + }; + + static const code distfix[32] = { + {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025}, + {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193}, + {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385}, + {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577}, + {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073}, + {22,5,193},{64,5,0} + }; diff --git a/libs/zlib/inflate.c b/libs/zlib/inflate.c new file mode 100644 index 000000000..cc89517bc --- /dev/null +++ b/libs/zlib/inflate.c @@ -0,0 +1,1501 @@ +/* inflate.c -- zlib decompression + * Copyright (C) 1995-2011 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* + * Change history: + * + * 1.2.beta0 24 Nov 2002 + * - First version -- complete rewrite of inflate to simplify code, avoid + * creation of window when not needed, minimize use of window when it is + * needed, make inffast.c even faster, implement gzip decoding, and to + * improve code readability and style over the previous zlib inflate code + * + * 1.2.beta1 25 Nov 2002 + * - Use pointers for available input and output checking in inffast.c + * - Remove input and output counters in inffast.c + * - Change inffast.c entry and loop from avail_in >= 7 to >= 6 + * - Remove unnecessary second byte pull from length extra in inffast.c + * - Unroll direct copy to three copies per loop in inffast.c + * + * 1.2.beta2 4 Dec 2002 + * - Change external routine names to reduce potential conflicts + * - Correct filename to inffixed.h for fixed tables in inflate.c + * - Make hbuf[] unsigned char to match parameter type in inflate.c + * - Change strm->next_out[-state->offset] to *(strm->next_out - state->offset) + * to avoid negation problem on Alphas (64 bit) in inflate.c + * + * 1.2.beta3 22 Dec 2002 + * - Add comments on state->bits assertion in inffast.c + * - Add comments on op field in inftrees.h + * - Fix bug in reuse of allocated window after inflateReset() + * - Remove bit fields--back to byte structure for speed + * - Remove distance extra == 0 check in inflate_fast()--only helps for lengths + * - Change post-increments to pre-increments in inflate_fast(), PPC biased? + * - Add compile time option, POSTINC, to use post-increments instead (Intel?) + * - Make MATCH copy in inflate() much faster for when inflate_fast() not used + * - Use local copies of stream next and avail values, as well as local bit + * buffer and bit count in inflate()--for speed when inflate_fast() not used + * + * 1.2.beta4 1 Jan 2003 + * - Split ptr - 257 statements in inflate_table() to avoid compiler warnings + * - Move a comment on output buffer sizes from inffast.c to inflate.c + * - Add comments in inffast.c to introduce the inflate_fast() routine + * - Rearrange window copies in inflate_fast() for speed and simplification + * - Unroll last copy for window match in inflate_fast() + * - Use local copies of window variables in inflate_fast() for speed + * - Pull out common wnext == 0 case for speed in inflate_fast() + * - Make op and len in inflate_fast() unsigned for consistency + * - Add FAR to lcode and dcode declarations in inflate_fast() + * - Simplified bad distance check in inflate_fast() + * - Added inflateBackInit(), inflateBack(), and inflateBackEnd() in new + * source file infback.c to provide a call-back interface to inflate for + * programs like gzip and unzip -- uses window as output buffer to avoid + * window copying + * + * 1.2.beta5 1 Jan 2003 + * - Improved inflateBack() interface to allow the caller to provide initial + * input in strm. + * - Fixed stored blocks bug in inflateBack() + * + * 1.2.beta6 4 Jan 2003 + * - Added comments in inffast.c on effectiveness of POSTINC + * - Typecasting all around to reduce compiler warnings + * - Changed loops from while (1) or do {} while (1) to for (;;), again to + * make compilers happy + * - Changed type of window in inflateBackInit() to unsigned char * + * + * 1.2.beta7 27 Jan 2003 + * - Changed many types to unsigned or unsigned short to avoid warnings + * - Added inflateCopy() function + * + * 1.2.0 9 Mar 2003 + * - Changed inflateBack() interface to provide separate opaque descriptors + * for the in() and out() functions + * - Changed inflateBack() argument and in_func typedef to swap the length + * and buffer address return values for the input function + * - Check next_in and next_out for Z_NULL on entry to inflate() + * + * The history for versions after 1.2.0 are in ChangeLog in zlib distribution. + */ + +#include "zutil.h" +#include "inftrees.h" +#include "inflate.h" +#include "inffast.h" + +#ifdef MAKEFIXED +# ifndef BUILDFIXED +# define BUILDFIXED +# endif +#endif + +/* function prototypes */ +local void fixedtables OF((struct inflate_state FAR *state)); +local int updatewindow OF((z_streamp strm, unsigned out)); +#ifdef BUILDFIXED + void makefixed OF((void)); +#endif +local unsigned syncsearch OF((unsigned FAR *have, unsigned char FAR *buf, + unsigned len)); + +int ZEXPORT inflateResetKeep(strm) +z_streamp strm; +{ + struct inflate_state FAR *state; + + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; + state = (struct inflate_state FAR *)strm->state; + strm->total_in = strm->total_out = state->total = 0; + strm->msg = Z_NULL; + if (state->wrap) /* to support ill-conceived Java test suite */ + strm->adler = state->wrap & 1; + state->mode = HEAD; + state->last = 0; + state->havedict = 0; + state->dmax = 32768U; + state->head = Z_NULL; + state->hold = 0; + state->bits = 0; + state->lencode = state->distcode = state->next = state->codes; + state->sane = 1; + state->back = -1; + Tracev((stderr, "inflate: reset\n")); + return Z_OK; +} + +int ZEXPORT inflateReset(strm) +z_streamp strm; +{ + struct inflate_state FAR *state; + + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; + state = (struct inflate_state FAR *)strm->state; + state->wsize = 0; + state->whave = 0; + state->wnext = 0; + return inflateResetKeep(strm); +} + +int ZEXPORT inflateReset2(strm, windowBits) +z_streamp strm; +int windowBits; +{ + int wrap; + struct inflate_state FAR *state; + + /* get the state */ + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; + state = (struct inflate_state FAR *)strm->state; + + /* extract wrap request from windowBits parameter */ + if (windowBits < 0) { + wrap = 0; + windowBits = -windowBits; + } + else { + wrap = (windowBits >> 4) + 1; +#ifdef GUNZIP + if (windowBits < 48) + windowBits &= 15; +#endif + } + + /* set number of window bits, free window if different */ + if (windowBits && (windowBits < 8 || windowBits > 15)) + return Z_STREAM_ERROR; + if (state->window != Z_NULL && state->wbits != (unsigned)windowBits) { + ZFREE(strm, state->window); + state->window = Z_NULL; + } + + /* update state and reset the rest of it */ + state->wrap = wrap; + state->wbits = (unsigned)windowBits; + return inflateReset(strm); +} + +int ZEXPORT inflateInit2_(strm, windowBits, version, stream_size) +z_streamp strm; +int windowBits; +const char *version; +int stream_size; +{ + int ret; + struct inflate_state FAR *state; + + if (version == Z_NULL || version[0] != ZLIB_VERSION[0] || + stream_size != (int)(sizeof(z_stream))) + return Z_VERSION_ERROR; + if (strm == Z_NULL) return Z_STREAM_ERROR; + strm->msg = Z_NULL; /* in case we return an error */ + if (strm->zalloc == (alloc_func)0) { +#ifdef Z_SOLO + return Z_STREAM_ERROR; +#else + strm->zalloc = zcalloc; + strm->opaque = (voidpf)0; +#endif + } + if (strm->zfree == (free_func)0) +#ifdef Z_SOLO + return Z_STREAM_ERROR; +#else + strm->zfree = zcfree; +#endif + state = (struct inflate_state FAR *) + ZALLOC(strm, 1, sizeof(struct inflate_state)); + if (state == Z_NULL) return Z_MEM_ERROR; + Tracev((stderr, "inflate: allocated\n")); + strm->state = (struct internal_state FAR *)state; + state->window = Z_NULL; + ret = inflateReset2(strm, windowBits); + if (ret != Z_OK) { + ZFREE(strm, state); + strm->state = Z_NULL; + } + return ret; +} + +int ZEXPORT inflateInit_(strm, version, stream_size) +z_streamp strm; +const char *version; +int stream_size; +{ + return inflateInit2_(strm, DEF_WBITS, version, stream_size); +} + +int ZEXPORT inflatePrime(strm, bits, value) +z_streamp strm; +int bits; +int value; +{ + struct inflate_state FAR *state; + + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; + state = (struct inflate_state FAR *)strm->state; + if (bits < 0) { + state->hold = 0; + state->bits = 0; + return Z_OK; + } + if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR; + value &= (1L << bits) - 1; + state->hold += value << state->bits; + state->bits += bits; + return Z_OK; +} + +/* + Return state with length and distance decoding tables and index sizes set to + fixed code decoding. Normally this returns fixed tables from inffixed.h. + If BUILDFIXED is defined, then instead this routine builds the tables the + first time it's called, and returns those tables the first time and + thereafter. This reduces the size of the code by about 2K bytes, in + exchange for a little execution time. However, BUILDFIXED should not be + used for threaded applications, since the rewriting of the tables and virgin + may not be thread-safe. + */ +local void fixedtables(state) +struct inflate_state FAR *state; +{ +#ifdef BUILDFIXED + static int virgin = 1; + static code *lenfix, *distfix; + static code fixed[544]; + + /* build fixed huffman tables if first call (may not be thread safe) */ + if (virgin) { + unsigned sym, bits; + static code *next; + + /* literal/length table */ + sym = 0; + while (sym < 144) state->lens[sym++] = 8; + while (sym < 256) state->lens[sym++] = 9; + while (sym < 280) state->lens[sym++] = 7; + while (sym < 288) state->lens[sym++] = 8; + next = fixed; + lenfix = next; + bits = 9; + inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work); + + /* distance table */ + sym = 0; + while (sym < 32) state->lens[sym++] = 5; + distfix = next; + bits = 5; + inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work); + + /* do this just once */ + virgin = 0; + } +#else /* !BUILDFIXED */ +# include "inffixed.h" +#endif /* BUILDFIXED */ + state->lencode = lenfix; + state->lenbits = 9; + state->distcode = distfix; + state->distbits = 5; +} + +#ifdef MAKEFIXED +#include + +/* + Write out the inffixed.h that is #include'd above. Defining MAKEFIXED also + defines BUILDFIXED, so the tables are built on the fly. makefixed() writes + those tables to stdout, which would be piped to inffixed.h. A small program + can simply call makefixed to do this: + + void makefixed(void); + + int main(void) + { + makefixed(); + return 0; + } + + Then that can be linked with zlib built with MAKEFIXED defined and run: + + a.out > inffixed.h + */ +void makefixed() +{ + unsigned low, size; + struct inflate_state state; + + fixedtables(&state); + puts(" /* inffixed.h -- table for decoding fixed codes"); + puts(" * Generated automatically by makefixed()."); + puts(" */"); + puts(""); + puts(" /* WARNING: this file should *not* be used by applications."); + puts(" It is part of the implementation of this library and is"); + puts(" subject to change. Applications should only use zlib.h."); + puts(" */"); + puts(""); + size = 1U << 9; + printf(" static const code lenfix[%u] = {", size); + low = 0; + for (;;) { + if ((low % 7) == 0) printf("\n "); + printf("{%u,%u,%d}", (low & 127) == 99 ? 64 : state.lencode[low].op, + state.lencode[low].bits, state.lencode[low].val); + if (++low == size) break; + putchar(','); + } + puts("\n };"); + size = 1U << 5; + printf("\n static const code distfix[%u] = {", size); + low = 0; + for (;;) { + if ((low % 6) == 0) printf("\n "); + printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits, + state.distcode[low].val); + if (++low == size) break; + putchar(','); + } + puts("\n };"); +} +#endif /* MAKEFIXED */ + +/* + Update the window with the last wsize (normally 32K) bytes written before + returning. If window does not exist yet, create it. This is only called + when a window is already in use, or when output has been written during this + inflate call, but the end of the deflate stream has not been reached yet. + It is also called to create a window for dictionary data when a dictionary + is loaded. + + Providing output buffers larger than 32K to inflate() should provide a speed + advantage, since only the last 32K of output is copied to the sliding window + upon return from inflate(), and since all distances after the first 32K of + output will fall in the output data, making match copies simpler and faster. + The advantage may be dependent on the size of the processor's data caches. + */ +local int updatewindow(strm, out) +z_streamp strm; +unsigned out; +{ + struct inflate_state FAR *state; + unsigned copy, dist; + + state = (struct inflate_state FAR *)strm->state; + + /* if it hasn't been done already, allocate space for the window */ + if (state->window == Z_NULL) { + state->window = (unsigned char FAR *) + ZALLOC(strm, 1U << state->wbits, + sizeof(unsigned char)); + if (state->window == Z_NULL) return 1; + } + + /* if window not in use yet, initialize */ + if (state->wsize == 0) { + state->wsize = 1U << state->wbits; + state->wnext = 0; + state->whave = 0; + } + + /* copy state->wsize or less output bytes into the circular window */ + copy = out - strm->avail_out; + if (copy >= state->wsize) { + zmemcpy(state->window, strm->next_out - state->wsize, state->wsize); + state->wnext = 0; + state->whave = state->wsize; + } + else { + dist = state->wsize - state->wnext; + if (dist > copy) dist = copy; + zmemcpy(state->window + state->wnext, strm->next_out - copy, dist); + copy -= dist; + if (copy) { + zmemcpy(state->window, strm->next_out - copy, copy); + state->wnext = copy; + state->whave = state->wsize; + } + else { + state->wnext += dist; + if (state->wnext == state->wsize) state->wnext = 0; + if (state->whave < state->wsize) state->whave += dist; + } + } + return 0; +} + +/* Macros for inflate(): */ + +/* check function to use adler32() for zlib or crc32() for gzip */ +#ifdef GUNZIP +# define UPDATE(check, buf, len) \ + (state->flags ? crc32(check, buf, len) : adler32(check, buf, len)) +#else +# define UPDATE(check, buf, len) adler32(check, buf, len) +#endif + +/* check macros for header crc */ +#ifdef GUNZIP +# define CRC2(check, word) \ + do { \ + hbuf[0] = (unsigned char)(word); \ + hbuf[1] = (unsigned char)((word) >> 8); \ + check = crc32(check, hbuf, 2); \ + } while (0) + +# define CRC4(check, word) \ + do { \ + hbuf[0] = (unsigned char)(word); \ + hbuf[1] = (unsigned char)((word) >> 8); \ + hbuf[2] = (unsigned char)((word) >> 16); \ + hbuf[3] = (unsigned char)((word) >> 24); \ + check = crc32(check, hbuf, 4); \ + } while (0) +#endif + +/* Load registers with state in inflate() for speed */ +#define LOAD() \ + do { \ + put = strm->next_out; \ + left = strm->avail_out; \ + next = strm->next_in; \ + have = strm->avail_in; \ + hold = state->hold; \ + bits = state->bits; \ + } while (0) + +/* Restore state from registers in inflate() */ +#define RESTORE() \ + do { \ + strm->next_out = put; \ + strm->avail_out = left; \ + strm->next_in = next; \ + strm->avail_in = have; \ + state->hold = hold; \ + state->bits = bits; \ + } while (0) + +/* Clear the input bit accumulator */ +#define INITBITS() \ + do { \ + hold = 0; \ + bits = 0; \ + } while (0) + +/* Get a byte of input into the bit accumulator, or return from inflate() + if there is no input available. */ +#define PULLBYTE() \ + do { \ + if (have == 0) goto inf_leave; \ + have--; \ + hold += (unsigned long)(*next++) << bits; \ + bits += 8; \ + } while (0) + +/* Assure that there are at least n bits in the bit accumulator. If there is + not enough available input to do that, then return from inflate(). */ +#define NEEDBITS(n) \ + do { \ + while (bits < (unsigned)(n)) \ + PULLBYTE(); \ + } while (0) + +/* Return the low n bits of the bit accumulator (n < 16) */ +#define BITS(n) \ + ((unsigned)hold & ((1U << (n)) - 1)) + +/* Remove n bits from the bit accumulator */ +#define DROPBITS(n) \ + do { \ + hold >>= (n); \ + bits -= (unsigned)(n); \ + } while (0) + +/* Remove zero to seven bits as needed to go to a byte boundary */ +#define BYTEBITS() \ + do { \ + hold >>= bits & 7; \ + bits -= bits & 7; \ + } while (0) + +/* Reverse the bytes in a 32-bit value */ +#define REVERSE(q) \ + ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \ + (((q) & 0xff00) << 8) + (((q) & 0xff) << 24)) + +/* + inflate() uses a state machine to process as much input data and generate as + much output data as possible before returning. The state machine is + structured roughly as follows: + + for (;;) switch (state) { + ... + case STATEn: + if (not enough input data or output space to make progress) + return; + ... make progress ... + state = STATEm; + break; + ... + } + + so when inflate() is called again, the same case is attempted again, and + if the appropriate resources are provided, the machine proceeds to the + next state. The NEEDBITS() macro is usually the way the state evaluates + whether it can proceed or should return. NEEDBITS() does the return if + the requested bits are not available. The typical use of the BITS macros + is: + + NEEDBITS(n); + ... do something with BITS(n) ... + DROPBITS(n); + + where NEEDBITS(n) either returns from inflate() if there isn't enough + input left to load n bits into the accumulator, or it continues. BITS(n) + gives the low n bits in the accumulator. When done, DROPBITS(n) drops + the low n bits off the accumulator. INITBITS() clears the accumulator + and sets the number of available bits to zero. BYTEBITS() discards just + enough bits to put the accumulator on a byte boundary. After BYTEBITS() + and a NEEDBITS(8), then BITS(8) would return the next byte in the stream. + + NEEDBITS(n) uses PULLBYTE() to get an available byte of input, or to return + if there is no input available. The decoding of variable length codes uses + PULLBYTE() directly in order to pull just enough bytes to decode the next + code, and no more. + + Some states loop until they get enough input, making sure that enough + state information is maintained to continue the loop where it left off + if NEEDBITS() returns in the loop. For example, want, need, and keep + would all have to actually be part of the saved state in case NEEDBITS() + returns: + + case STATEw: + while (want < need) { + NEEDBITS(n); + keep[want++] = BITS(n); + DROPBITS(n); + } + state = STATEx; + case STATEx: + + As shown above, if the next state is also the next case, then the break + is omitted. + + A state may also return if there is not enough output space available to + complete that state. Those states are copying stored data, writing a + literal byte, and copying a matching string. + + When returning, a "goto inf_leave" is used to update the total counters, + update the check value, and determine whether any progress has been made + during that inflate() call in order to return the proper return code. + Progress is defined as a change in either strm->avail_in or strm->avail_out. + When there is a window, goto inf_leave will update the window with the last + output written. If a goto inf_leave occurs in the middle of decompression + and there is no window currently, goto inf_leave will create one and copy + output to the window for the next call of inflate(). + + In this implementation, the flush parameter of inflate() only affects the + return code (per zlib.h). inflate() always writes as much as possible to + strm->next_out, given the space available and the provided input--the effect + documented in zlib.h of Z_SYNC_FLUSH. Furthermore, inflate() always defers + the allocation of and copying into a sliding window until necessary, which + provides the effect documented in zlib.h for Z_FINISH when the entire input + stream available. So the only thing the flush parameter actually does is: + when flush is set to Z_FINISH, inflate() cannot return Z_OK. Instead it + will return Z_BUF_ERROR if it has not reached the end of the stream. + */ + +int ZEXPORT inflate(strm, flush) +z_streamp strm; +int flush; +{ + struct inflate_state FAR *state; + unsigned char FAR *next; /* next input */ + unsigned char FAR *put; /* next output */ + unsigned have, left; /* available input and output */ + unsigned long hold; /* bit buffer */ + unsigned bits; /* bits in bit buffer */ + unsigned in, out; /* save starting available input and output */ + unsigned copy; /* number of stored or match bytes to copy */ + unsigned char FAR *from; /* where to copy match bytes from */ + code here; /* current decoding table entry */ + code last; /* parent table entry */ + unsigned len; /* length to copy for repeats, bits to drop */ + int ret; /* return code */ +#ifdef GUNZIP + unsigned char hbuf[4]; /* buffer for gzip header crc calculation */ +#endif + static const unsigned short order[19] = /* permutation of code lengths */ + {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; + + if (strm == Z_NULL || strm->state == Z_NULL || strm->next_out == Z_NULL || + (strm->next_in == Z_NULL && strm->avail_in != 0)) + return Z_STREAM_ERROR; + + state = (struct inflate_state FAR *)strm->state; + if (state->mode == TYPE) state->mode = TYPEDO; /* skip check */ + LOAD(); + in = have; + out = left; + ret = Z_OK; + for (;;) + switch (state->mode) { + case HEAD: + if (state->wrap == 0) { + state->mode = TYPEDO; + break; + } + NEEDBITS(16); +#ifdef GUNZIP + if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */ + state->check = crc32(0L, Z_NULL, 0); + CRC2(state->check, hold); + INITBITS(); + state->mode = FLAGS; + break; + } + state->flags = 0; /* expect zlib header */ + if (state->head != Z_NULL) + state->head->done = -1; + if (!(state->wrap & 1) || /* check if zlib header allowed */ +#else + if ( +#endif + ((BITS(8) << 8) + (hold >> 8)) % 31) { + strm->msg = (char *)"incorrect header check"; + state->mode = BAD; + break; + } + if (BITS(4) != Z_DEFLATED) { + strm->msg = (char *)"unknown compression method"; + state->mode = BAD; + break; + } + DROPBITS(4); + len = BITS(4) + 8; + if (state->wbits == 0) + state->wbits = len; + else if (len > state->wbits) { + strm->msg = (char *)"invalid window size"; + state->mode = BAD; + break; + } + state->dmax = 1U << len; + Tracev((stderr, "inflate: zlib header ok\n")); + strm->adler = state->check = adler32(0L, Z_NULL, 0); + state->mode = hold & 0x200 ? DICTID : TYPE; + INITBITS(); + break; +#ifdef GUNZIP + case FLAGS: + NEEDBITS(16); + state->flags = (int)(hold); + if ((state->flags & 0xff) != Z_DEFLATED) { + strm->msg = (char *)"unknown compression method"; + state->mode = BAD; + break; + } + if (state->flags & 0xe000) { + strm->msg = (char *)"unknown header flags set"; + state->mode = BAD; + break; + } + if (state->head != Z_NULL) + state->head->text = (int)((hold >> 8) & 1); + if (state->flags & 0x0200) CRC2(state->check, hold); + INITBITS(); + state->mode = TIME; + case TIME: + NEEDBITS(32); + if (state->head != Z_NULL) + state->head->time = hold; + if (state->flags & 0x0200) CRC4(state->check, hold); + INITBITS(); + state->mode = OS; + case OS: + NEEDBITS(16); + if (state->head != Z_NULL) { + state->head->xflags = (int)(hold & 0xff); + state->head->os = (int)(hold >> 8); + } + if (state->flags & 0x0200) CRC2(state->check, hold); + INITBITS(); + state->mode = EXLEN; + case EXLEN: + if (state->flags & 0x0400) { + NEEDBITS(16); + state->length = (unsigned)(hold); + if (state->head != Z_NULL) + state->head->extra_len = (unsigned)hold; + if (state->flags & 0x0200) CRC2(state->check, hold); + INITBITS(); + } + else if (state->head != Z_NULL) + state->head->extra = Z_NULL; + state->mode = EXTRA; + case EXTRA: + if (state->flags & 0x0400) { + copy = state->length; + if (copy > have) copy = have; + if (copy) { + if (state->head != Z_NULL && + state->head->extra != Z_NULL) { + len = state->head->extra_len - state->length; + zmemcpy(state->head->extra + len, next, + len + copy > state->head->extra_max ? + state->head->extra_max - len : copy); + } + if (state->flags & 0x0200) + state->check = crc32(state->check, next, copy); + have -= copy; + next += copy; + state->length -= copy; + } + if (state->length) goto inf_leave; + } + state->length = 0; + state->mode = NAME; + case NAME: + if (state->flags & 0x0800) { + if (have == 0) goto inf_leave; + copy = 0; + do { + len = (unsigned)(next[copy++]); + if (state->head != Z_NULL && + state->head->name != Z_NULL && + state->length < state->head->name_max) + state->head->name[state->length++] = len; + } while (len && copy < have); + if (state->flags & 0x0200) + state->check = crc32(state->check, next, copy); + have -= copy; + next += copy; + if (len) goto inf_leave; + } + else if (state->head != Z_NULL) + state->head->name = Z_NULL; + state->length = 0; + state->mode = COMMENT; + case COMMENT: + if (state->flags & 0x1000) { + if (have == 0) goto inf_leave; + copy = 0; + do { + len = (unsigned)(next[copy++]); + if (state->head != Z_NULL && + state->head->comment != Z_NULL && + state->length < state->head->comm_max) + state->head->comment[state->length++] = len; + } while (len && copy < have); + if (state->flags & 0x0200) + state->check = crc32(state->check, next, copy); + have -= copy; + next += copy; + if (len) goto inf_leave; + } + else if (state->head != Z_NULL) + state->head->comment = Z_NULL; + state->mode = HCRC; + case HCRC: + if (state->flags & 0x0200) { + NEEDBITS(16); + if (hold != (state->check & 0xffff)) { + strm->msg = (char *)"header crc mismatch"; + state->mode = BAD; + break; + } + INITBITS(); + } + if (state->head != Z_NULL) { + state->head->hcrc = (int)((state->flags >> 9) & 1); + state->head->done = 1; + } + strm->adler = state->check = crc32(0L, Z_NULL, 0); + state->mode = TYPE; + break; +#endif + case DICTID: + NEEDBITS(32); + strm->adler = state->check = REVERSE(hold); + INITBITS(); + state->mode = DICT; + case DICT: + if (state->havedict == 0) { + RESTORE(); + return Z_NEED_DICT; + } + strm->adler = state->check = adler32(0L, Z_NULL, 0); + state->mode = TYPE; + case TYPE: + if (flush == Z_BLOCK || flush == Z_TREES) goto inf_leave; + case TYPEDO: + if (state->last) { + BYTEBITS(); + state->mode = CHECK; + break; + } + NEEDBITS(3); + state->last = BITS(1); + DROPBITS(1); + switch (BITS(2)) { + case 0: /* stored block */ + Tracev((stderr, "inflate: stored block%s\n", + state->last ? " (last)" : "")); + state->mode = STORED; + break; + case 1: /* fixed block */ + fixedtables(state); + Tracev((stderr, "inflate: fixed codes block%s\n", + state->last ? " (last)" : "")); + state->mode = LEN_; /* decode codes */ + if (flush == Z_TREES) { + DROPBITS(2); + goto inf_leave; + } + break; + case 2: /* dynamic block */ + Tracev((stderr, "inflate: dynamic codes block%s\n", + state->last ? " (last)" : "")); + state->mode = TABLE; + break; + case 3: + strm->msg = (char *)"invalid block type"; + state->mode = BAD; + } + DROPBITS(2); + break; + case STORED: + BYTEBITS(); /* go to byte boundary */ + NEEDBITS(32); + if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) { + strm->msg = (char *)"invalid stored block lengths"; + state->mode = BAD; + break; + } + state->length = (unsigned)hold & 0xffff; + Tracev((stderr, "inflate: stored length %u\n", + state->length)); + INITBITS(); + state->mode = COPY_; + if (flush == Z_TREES) goto inf_leave; + case COPY_: + state->mode = COPY; + case COPY: + copy = state->length; + if (copy) { + if (copy > have) copy = have; + if (copy > left) copy = left; + if (copy == 0) goto inf_leave; + zmemcpy(put, next, copy); + have -= copy; + next += copy; + left -= copy; + put += copy; + state->length -= copy; + break; + } + Tracev((stderr, "inflate: stored end\n")); + state->mode = TYPE; + break; + case TABLE: + NEEDBITS(14); + state->nlen = BITS(5) + 257; + DROPBITS(5); + state->ndist = BITS(5) + 1; + DROPBITS(5); + state->ncode = BITS(4) + 4; + DROPBITS(4); +#ifndef PKZIP_BUG_WORKAROUND + if (state->nlen > 286 || state->ndist > 30) { + strm->msg = (char *)"too many length or distance symbols"; + state->mode = BAD; + break; + } +#endif + Tracev((stderr, "inflate: table sizes ok\n")); + state->have = 0; + state->mode = LENLENS; + case LENLENS: + while (state->have < state->ncode) { + NEEDBITS(3); + state->lens[order[state->have++]] = (unsigned short)BITS(3); + DROPBITS(3); + } + while (state->have < 19) + state->lens[order[state->have++]] = 0; + state->next = state->codes; + state->lencode = (code const FAR *)(state->next); + state->lenbits = 7; + ret = inflate_table(CODES, state->lens, 19, &(state->next), + &(state->lenbits), state->work); + if (ret) { + strm->msg = (char *)"invalid code lengths set"; + state->mode = BAD; + break; + } + Tracev((stderr, "inflate: code lengths ok\n")); + state->have = 0; + state->mode = CODELENS; + case CODELENS: + while (state->have < state->nlen + state->ndist) { + for (;;) { + here = state->lencode[BITS(state->lenbits)]; + if ((unsigned)(here.bits) <= bits) break; + PULLBYTE(); + } + if (here.val < 16) { + DROPBITS(here.bits); + state->lens[state->have++] = here.val; + } + else { + if (here.val == 16) { + NEEDBITS(here.bits + 2); + DROPBITS(here.bits); + if (state->have == 0) { + strm->msg = (char *)"invalid bit length repeat"; + state->mode = BAD; + break; + } + len = state->lens[state->have - 1]; + copy = 3 + BITS(2); + DROPBITS(2); + } + else if (here.val == 17) { + NEEDBITS(here.bits + 3); + DROPBITS(here.bits); + len = 0; + copy = 3 + BITS(3); + DROPBITS(3); + } + else { + NEEDBITS(here.bits + 7); + DROPBITS(here.bits); + len = 0; + copy = 11 + BITS(7); + DROPBITS(7); + } + if (state->have + copy > state->nlen + state->ndist) { + strm->msg = (char *)"invalid bit length repeat"; + state->mode = BAD; + break; + } + while (copy--) + state->lens[state->have++] = (unsigned short)len; + } + } + + /* handle error breaks in while */ + if (state->mode == BAD) break; + + /* check for end-of-block code (better have one) */ + if (state->lens[256] == 0) { + strm->msg = (char *)"invalid code -- missing end-of-block"; + state->mode = BAD; + break; + } + + /* build code tables -- note: do not change the lenbits or distbits + values here (9 and 6) without reading the comments in inftrees.h + concerning the ENOUGH constants, which depend on those values */ + state->next = state->codes; + state->lencode = (code const FAR *)(state->next); + state->lenbits = 9; + ret = inflate_table(LENS, state->lens, state->nlen, &(state->next), + &(state->lenbits), state->work); + if (ret) { + strm->msg = (char *)"invalid literal/lengths set"; + state->mode = BAD; + break; + } + state->distcode = (code const FAR *)(state->next); + state->distbits = 6; + ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist, + &(state->next), &(state->distbits), state->work); + if (ret) { + strm->msg = (char *)"invalid distances set"; + state->mode = BAD; + break; + } + Tracev((stderr, "inflate: codes ok\n")); + state->mode = LEN_; + if (flush == Z_TREES) goto inf_leave; + case LEN_: + state->mode = LEN; + case LEN: + if (have >= 6 && left >= 258) { + RESTORE(); + inflate_fast(strm, out); + LOAD(); + if (state->mode == TYPE) + state->back = -1; + break; + } + state->back = 0; + for (;;) { + here = state->lencode[BITS(state->lenbits)]; + if ((unsigned)(here.bits) <= bits) break; + PULLBYTE(); + } + if (here.op && (here.op & 0xf0) == 0) { + last = here; + for (;;) { + here = state->lencode[last.val + + (BITS(last.bits + last.op) >> last.bits)]; + if ((unsigned)(last.bits + here.bits) <= bits) break; + PULLBYTE(); + } + DROPBITS(last.bits); + state->back += last.bits; + } + DROPBITS(here.bits); + state->back += here.bits; + state->length = (unsigned)here.val; + if ((int)(here.op) == 0) { + Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ? + "inflate: literal '%c'\n" : + "inflate: literal 0x%02x\n", here.val)); + state->mode = LIT; + break; + } + if (here.op & 32) { + Tracevv((stderr, "inflate: end of block\n")); + state->back = -1; + state->mode = TYPE; + break; + } + if (here.op & 64) { + strm->msg = (char *)"invalid literal/length code"; + state->mode = BAD; + break; + } + state->extra = (unsigned)(here.op) & 15; + state->mode = LENEXT; + case LENEXT: + if (state->extra) { + NEEDBITS(state->extra); + state->length += BITS(state->extra); + DROPBITS(state->extra); + state->back += state->extra; + } + Tracevv((stderr, "inflate: length %u\n", state->length)); + state->was = state->length; + state->mode = DIST; + case DIST: + for (;;) { + here = state->distcode[BITS(state->distbits)]; + if ((unsigned)(here.bits) <= bits) break; + PULLBYTE(); + } + if ((here.op & 0xf0) == 0) { + last = here; + for (;;) { + here = state->distcode[last.val + + (BITS(last.bits + last.op) >> last.bits)]; + if ((unsigned)(last.bits + here.bits) <= bits) break; + PULLBYTE(); + } + DROPBITS(last.bits); + state->back += last.bits; + } + DROPBITS(here.bits); + state->back += here.bits; + if (here.op & 64) { + strm->msg = (char *)"invalid distance code"; + state->mode = BAD; + break; + } + state->offset = (unsigned)here.val; + state->extra = (unsigned)(here.op) & 15; + state->mode = DISTEXT; + case DISTEXT: + if (state->extra) { + NEEDBITS(state->extra); + state->offset += BITS(state->extra); + DROPBITS(state->extra); + state->back += state->extra; + } +#ifdef INFLATE_STRICT + if (state->offset > state->dmax) { + strm->msg = (char *)"invalid distance too far back"; + state->mode = BAD; + break; + } +#endif + Tracevv((stderr, "inflate: distance %u\n", state->offset)); + state->mode = MATCH; + case MATCH: + if (left == 0) goto inf_leave; + copy = out - left; + if (state->offset > copy) { /* copy from window */ + copy = state->offset - copy; + if (copy > state->whave) { + if (state->sane) { + strm->msg = (char *)"invalid distance too far back"; + state->mode = BAD; + break; + } +#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR + Trace((stderr, "inflate.c too far\n")); + copy -= state->whave; + if (copy > state->length) copy = state->length; + if (copy > left) copy = left; + left -= copy; + state->length -= copy; + do { + *put++ = 0; + } while (--copy); + if (state->length == 0) state->mode = LEN; + break; +#endif + } + if (copy > state->wnext) { + copy -= state->wnext; + from = state->window + (state->wsize - copy); + } + else + from = state->window + (state->wnext - copy); + if (copy > state->length) copy = state->length; + } + else { /* copy from output */ + from = put - state->offset; + copy = state->length; + } + if (copy > left) copy = left; + left -= copy; + state->length -= copy; + do { + *put++ = *from++; + } while (--copy); + if (state->length == 0) state->mode = LEN; + break; + case LIT: + if (left == 0) goto inf_leave; + *put++ = (unsigned char)(state->length); + left--; + state->mode = LEN; + break; + case CHECK: + if (state->wrap) { + NEEDBITS(32); + out -= left; + strm->total_out += out; + state->total += out; + if (out) + strm->adler = state->check = + UPDATE(state->check, put - out, out); + out = left; + if (( +#ifdef GUNZIP + state->flags ? hold : +#endif + REVERSE(hold)) != state->check) { + strm->msg = (char *)"incorrect data check"; + state->mode = BAD; + break; + } + INITBITS(); + Tracev((stderr, "inflate: check matches trailer\n")); + } +#ifdef GUNZIP + state->mode = LENGTH; + case LENGTH: + if (state->wrap && state->flags) { + NEEDBITS(32); + if (hold != (state->total & 0xffffffffUL)) { + strm->msg = (char *)"incorrect length check"; + state->mode = BAD; + break; + } + INITBITS(); + Tracev((stderr, "inflate: length matches trailer\n")); + } +#endif + state->mode = DONE; + case DONE: + ret = Z_STREAM_END; + goto inf_leave; + case BAD: + ret = Z_DATA_ERROR; + goto inf_leave; + case MEM: + return Z_MEM_ERROR; + case SYNC: + default: + return Z_STREAM_ERROR; + } + + /* + Return from inflate(), updating the total counts and the check value. + If there was no progress during the inflate() call, return a buffer + error. Call updatewindow() to create and/or update the window state. + Note: a memory error from inflate() is non-recoverable. + */ + inf_leave: + RESTORE(); + if (state->wsize || (out != strm->avail_out && state->mode < BAD && + (state->mode < CHECK || flush != Z_FINISH))) + if (updatewindow(strm, out)) { + state->mode = MEM; + return Z_MEM_ERROR; + } + in -= strm->avail_in; + out -= strm->avail_out; + strm->total_in += in; + strm->total_out += out; + state->total += out; + if (state->wrap && out) + strm->adler = state->check = + UPDATE(state->check, strm->next_out - out, out); + strm->data_type = state->bits + (state->last ? 64 : 0) + + (state->mode == TYPE ? 128 : 0) + + (state->mode == LEN_ || state->mode == COPY_ ? 256 : 0); + if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK) + ret = Z_BUF_ERROR; + return ret; +} + +int ZEXPORT inflateEnd(strm) +z_streamp strm; +{ + struct inflate_state FAR *state; + if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0) + return Z_STREAM_ERROR; + state = (struct inflate_state FAR *)strm->state; + if (state->window != Z_NULL) ZFREE(strm, state->window); + ZFREE(strm, strm->state); + strm->state = Z_NULL; + Tracev((stderr, "inflate: end\n")); + return Z_OK; +} + +int ZEXPORT inflateSetDictionary(strm, dictionary, dictLength) +z_streamp strm; +const Bytef *dictionary; +uInt dictLength; +{ + struct inflate_state FAR *state; + unsigned long id; + unsigned char *next; + unsigned avail; + int ret; + + /* check state */ + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; + state = (struct inflate_state FAR *)strm->state; + if (state->wrap != 0 && state->mode != DICT) + return Z_STREAM_ERROR; + + /* check for correct dictionary id */ + if (state->mode == DICT) { + id = adler32(0L, Z_NULL, 0); + id = adler32(id, dictionary, dictLength); + if (id != state->check) + return Z_DATA_ERROR; + } + + /* copy dictionary to window using updatewindow(), which will amend the + existing dictionary if appropriate */ + next = strm->next_out; + avail = strm->avail_out; + strm->next_out = (Bytef *)dictionary + dictLength; + strm->avail_out = 0; + ret = updatewindow(strm, dictLength); + strm->avail_out = avail; + strm->next_out = next; + if (ret) { + state->mode = MEM; + return Z_MEM_ERROR; + } + state->havedict = 1; + Tracev((stderr, "inflate: dictionary set\n")); + return Z_OK; +} + +int ZEXPORT inflateGetHeader(strm, head) +z_streamp strm; +gz_headerp head; +{ + struct inflate_state FAR *state; + + /* check state */ + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; + state = (struct inflate_state FAR *)strm->state; + if ((state->wrap & 2) == 0) return Z_STREAM_ERROR; + + /* save header structure */ + state->head = head; + head->done = 0; + return Z_OK; +} + +/* + Search buf[0..len-1] for the pattern: 0, 0, 0xff, 0xff. Return when found + or when out of input. When called, *have is the number of pattern bytes + found in order so far, in 0..3. On return *have is updated to the new + state. If on return *have equals four, then the pattern was found and the + return value is how many bytes were read including the last byte of the + pattern. If *have is less than four, then the pattern has not been found + yet and the return value is len. In the latter case, syncsearch() can be + called again with more data and the *have state. *have is initialized to + zero for the first call. + */ +local unsigned syncsearch(have, buf, len) +unsigned FAR *have; +unsigned char FAR *buf; +unsigned len; +{ + unsigned got; + unsigned next; + + got = *have; + next = 0; + while (next < len && got < 4) { + if ((int)(buf[next]) == (got < 2 ? 0 : 0xff)) + got++; + else if (buf[next]) + got = 0; + else + got = 4 - got; + next++; + } + *have = got; + return next; +} + +int ZEXPORT inflateSync(strm) +z_streamp strm; +{ + unsigned len; /* number of bytes to look at or looked at */ + unsigned long in, out; /* temporary to save total_in and total_out */ + unsigned char buf[4]; /* to restore bit buffer to byte string */ + struct inflate_state FAR *state; + + /* check parameters */ + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; + state = (struct inflate_state FAR *)strm->state; + if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR; + + /* if first time, start search in bit buffer */ + if (state->mode != SYNC) { + state->mode = SYNC; + state->hold <<= state->bits & 7; + state->bits -= state->bits & 7; + len = 0; + while (state->bits >= 8) { + buf[len++] = (unsigned char)(state->hold); + state->hold >>= 8; + state->bits -= 8; + } + state->have = 0; + syncsearch(&(state->have), buf, len); + } + + /* search available input */ + len = syncsearch(&(state->have), strm->next_in, strm->avail_in); + strm->avail_in -= len; + strm->next_in += len; + strm->total_in += len; + + /* return no joy or set up to restart inflate() on a new block */ + if (state->have != 4) return Z_DATA_ERROR; + in = strm->total_in; out = strm->total_out; + inflateReset(strm); + strm->total_in = in; strm->total_out = out; + state->mode = TYPE; + return Z_OK; +} + +/* + Returns true if inflate is currently at the end of a block generated by + Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP + implementation to provide an additional safety check. PPP uses + Z_SYNC_FLUSH but removes the length bytes of the resulting empty stored + block. When decompressing, PPP checks that at the end of input packet, + inflate is waiting for these length bytes. + */ +int ZEXPORT inflateSyncPoint(strm) +z_streamp strm; +{ + struct inflate_state FAR *state; + + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; + state = (struct inflate_state FAR *)strm->state; + return state->mode == STORED && state->bits == 0; +} + +int ZEXPORT inflateCopy(dest, source) +z_streamp dest; +z_streamp source; +{ + struct inflate_state FAR *state; + struct inflate_state FAR *copy; + unsigned char FAR *window; + unsigned wsize; + + /* check input */ + if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL || + source->zalloc == (alloc_func)0 || source->zfree == (free_func)0) + return Z_STREAM_ERROR; + state = (struct inflate_state FAR *)source->state; + + /* allocate space */ + copy = (struct inflate_state FAR *) + ZALLOC(source, 1, sizeof(struct inflate_state)); + if (copy == Z_NULL) return Z_MEM_ERROR; + window = Z_NULL; + if (state->window != Z_NULL) { + window = (unsigned char FAR *) + ZALLOC(source, 1U << state->wbits, sizeof(unsigned char)); + if (window == Z_NULL) { + ZFREE(source, copy); + return Z_MEM_ERROR; + } + } + + /* copy state */ + zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream)); + zmemcpy((voidpf)copy, (voidpf)state, sizeof(struct inflate_state)); + if (state->lencode >= state->codes && + state->lencode <= state->codes + ENOUGH - 1) { + copy->lencode = copy->codes + (state->lencode - state->codes); + copy->distcode = copy->codes + (state->distcode - state->codes); + } + copy->next = copy->codes + (state->next - state->codes); + if (window != Z_NULL) { + wsize = 1U << state->wbits; + zmemcpy(window, state->window, wsize); + } + copy->window = window; + dest->state = (struct internal_state FAR *)copy; + return Z_OK; +} + +int ZEXPORT inflateUndermine(strm, subvert) +z_streamp strm; +int subvert; +{ + struct inflate_state FAR *state; + + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; + state = (struct inflate_state FAR *)strm->state; + state->sane = !subvert; +#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR + return Z_OK; +#else + state->sane = 1; + return Z_DATA_ERROR; +#endif +} + +long ZEXPORT inflateMark(strm) +z_streamp strm; +{ + struct inflate_state FAR *state; + + if (strm == Z_NULL || strm->state == Z_NULL) return -1L << 16; + state = (struct inflate_state FAR *)strm->state; + return ((long)(state->back) << 16) + + (state->mode == COPY ? state->length : + (state->mode == MATCH ? state->was - state->length : 0)); +} diff --git a/libs/zlib/inflate.h b/libs/zlib/inflate.h new file mode 100644 index 000000000..95f4986d4 --- /dev/null +++ b/libs/zlib/inflate.h @@ -0,0 +1,122 @@ +/* inflate.h -- internal inflate state definition + * Copyright (C) 1995-2009 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* WARNING: this file should *not* be used by applications. It is + part of the implementation of the compression library and is + subject to change. Applications should only use zlib.h. + */ + +/* define NO_GZIP when compiling if you want to disable gzip header and + trailer decoding by inflate(). NO_GZIP would be used to avoid linking in + the crc code when it is not needed. For shared libraries, gzip decoding + should be left enabled. */ +#ifndef NO_GZIP +# define GUNZIP +#endif + +/* Possible inflate modes between inflate() calls */ +typedef enum { + HEAD, /* i: waiting for magic header */ + FLAGS, /* i: waiting for method and flags (gzip) */ + TIME, /* i: waiting for modification time (gzip) */ + OS, /* i: waiting for extra flags and operating system (gzip) */ + EXLEN, /* i: waiting for extra length (gzip) */ + EXTRA, /* i: waiting for extra bytes (gzip) */ + NAME, /* i: waiting for end of file name (gzip) */ + COMMENT, /* i: waiting for end of comment (gzip) */ + HCRC, /* i: waiting for header crc (gzip) */ + DICTID, /* i: waiting for dictionary check value */ + DICT, /* waiting for inflateSetDictionary() call */ + TYPE, /* i: waiting for type bits, including last-flag bit */ + TYPEDO, /* i: same, but skip check to exit inflate on new block */ + STORED, /* i: waiting for stored size (length and complement) */ + COPY_, /* i/o: same as COPY below, but only first time in */ + COPY, /* i/o: waiting for input or output to copy stored block */ + TABLE, /* i: waiting for dynamic block table lengths */ + LENLENS, /* i: waiting for code length code lengths */ + CODELENS, /* i: waiting for length/lit and distance code lengths */ + LEN_, /* i: same as LEN below, but only first time in */ + LEN, /* i: waiting for length/lit/eob code */ + LENEXT, /* i: waiting for length extra bits */ + DIST, /* i: waiting for distance code */ + DISTEXT, /* i: waiting for distance extra bits */ + MATCH, /* o: waiting for output space to copy string */ + LIT, /* o: waiting for output space to write literal */ + CHECK, /* i: waiting for 32-bit check value */ + LENGTH, /* i: waiting for 32-bit length (gzip) */ + DONE, /* finished check, done -- remain here until reset */ + BAD, /* got a data error -- remain here until reset */ + MEM, /* got an inflate() memory error -- remain here until reset */ + SYNC /* looking for synchronization bytes to restart inflate() */ +} inflate_mode; + +/* + State transitions between above modes - + + (most modes can go to BAD or MEM on error -- not shown for clarity) + + Process header: + HEAD -> (gzip) or (zlib) or (raw) + (gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME -> COMMENT -> + HCRC -> TYPE + (zlib) -> DICTID or TYPE + DICTID -> DICT -> TYPE + (raw) -> TYPEDO + Read deflate blocks: + TYPE -> TYPEDO -> STORED or TABLE or LEN_ or CHECK + STORED -> COPY_ -> COPY -> TYPE + TABLE -> LENLENS -> CODELENS -> LEN_ + LEN_ -> LEN + Read deflate codes in fixed or dynamic block: + LEN -> LENEXT or LIT or TYPE + LENEXT -> DIST -> DISTEXT -> MATCH -> LEN + LIT -> LEN + Process trailer: + CHECK -> LENGTH -> DONE + */ + +/* state maintained between inflate() calls. Approximately 10K bytes. */ +struct inflate_state { + inflate_mode mode; /* current inflate mode */ + int last; /* true if processing last block */ + int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ + int havedict; /* true if dictionary provided */ + int flags; /* gzip header method and flags (0 if zlib) */ + unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */ + unsigned long check; /* protected copy of check value */ + unsigned long total; /* protected copy of output count */ + gz_headerp head; /* where to save gzip header information */ + /* sliding window */ + unsigned wbits; /* log base 2 of requested window size */ + unsigned wsize; /* window size or zero if not using window */ + unsigned whave; /* valid bytes in the window */ + unsigned wnext; /* window write index */ + unsigned char FAR *window; /* allocated sliding window, if needed */ + /* bit accumulator */ + unsigned long hold; /* input bit accumulator */ + unsigned bits; /* number of bits in "in" */ + /* for string and stored block copying */ + unsigned length; /* literal or length of data to copy */ + unsigned offset; /* distance back to copy string from */ + /* for table and code decoding */ + unsigned extra; /* extra bits needed */ + /* fixed and dynamic code tables */ + code const FAR *lencode; /* starting table for length/literal codes */ + code const FAR *distcode; /* starting table for distance codes */ + unsigned lenbits; /* index bits for lencode */ + unsigned distbits; /* index bits for distcode */ + /* dynamic table building */ + unsigned ncode; /* number of code length code lengths */ + unsigned nlen; /* number of length code lengths */ + unsigned ndist; /* number of distance code lengths */ + unsigned have; /* number of code lengths in lens[] */ + code FAR *next; /* next available space in codes[] */ + unsigned short lens[320]; /* temporary storage for code lengths */ + unsigned short work[288]; /* work area for code table building */ + code codes[ENOUGH]; /* space for code tables */ + int sane; /* if false, allow invalid distance too far */ + int back; /* bits back of last unprocessed length/lit */ + unsigned was; /* initial length of match */ +}; diff --git a/libs/zlib/inftrees.c b/libs/zlib/inftrees.c new file mode 100644 index 000000000..60bbd58bf --- /dev/null +++ b/libs/zlib/inftrees.c @@ -0,0 +1,306 @@ +/* inftrees.c -- generate Huffman trees for efficient decoding + * Copyright (C) 1995-2012 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +#include "zutil.h" +#include "inftrees.h" + +#define MAXBITS 15 + +const char inflate_copyright[] = + " inflate 1.2.6 Copyright 1995-2012 Mark Adler "; +/* + If you use the zlib library in a product, an acknowledgment is welcome + in the documentation of your product. If for some reason you cannot + include such an acknowledgment, I would appreciate that you keep this + copyright string in the executable of your product. + */ + +/* + Build a set of tables to decode the provided canonical Huffman code. + The code lengths are lens[0..codes-1]. The result starts at *table, + whose indices are 0..2^bits-1. work is a writable array of at least + lens shorts, which is used as a work area. type is the type of code + to be generated, CODES, LENS, or DISTS. On return, zero is success, + -1 is an invalid code, and +1 means that ENOUGH isn't enough. table + on return points to the next available entry's address. bits is the + requested root table index bits, and on return it is the actual root + table index bits. It will differ if the request is greater than the + longest code or if it is less than the shortest code. + */ +int ZLIB_INTERNAL inflate_table(type, lens, codes, table, bits, work) +codetype type; +unsigned short FAR *lens; +unsigned codes; +code FAR * FAR *table; +unsigned FAR *bits; +unsigned short FAR *work; +{ + unsigned len; /* a code's length in bits */ + unsigned sym; /* index of code symbols */ + unsigned min, max; /* minimum and maximum code lengths */ + unsigned root; /* number of index bits for root table */ + unsigned curr; /* number of index bits for current table */ + unsigned drop; /* code bits to drop for sub-table */ + int left; /* number of prefix codes available */ + unsigned used; /* code entries in table used */ + unsigned huff; /* Huffman code */ + unsigned incr; /* for incrementing code, index */ + unsigned fill; /* index for replicating entries */ + unsigned low; /* low bits for current root entry */ + unsigned mask; /* mask for low root bits */ + code here; /* table entry for duplication */ + code FAR *next; /* next available space in table */ + const unsigned short FAR *base; /* base value table to use */ + const unsigned short FAR *extra; /* extra bits table to use */ + int end; /* use base and extra for symbol > end */ + unsigned short count[MAXBITS+1]; /* number of codes of each length */ + unsigned short offs[MAXBITS+1]; /* offsets in table for each length */ + static const unsigned short lbase[31] = { /* Length codes 257..285 base */ + 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, + 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; + static const unsigned short lext[31] = { /* Length codes 257..285 extra */ + 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, + 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 203, 69}; + static const unsigned short dbase[32] = { /* Distance codes 0..29 base */ + 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, + 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, + 8193, 12289, 16385, 24577, 0, 0}; + static const unsigned short dext[32] = { /* Distance codes 0..29 extra */ + 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, + 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, + 28, 28, 29, 29, 64, 64}; + + /* + Process a set of code lengths to create a canonical Huffman code. The + code lengths are lens[0..codes-1]. Each length corresponds to the + symbols 0..codes-1. The Huffman code is generated by first sorting the + symbols by length from short to long, and retaining the symbol order + for codes with equal lengths. Then the code starts with all zero bits + for the first code of the shortest length, and the codes are integer + increments for the same length, and zeros are appended as the length + increases. For the deflate format, these bits are stored backwards + from their more natural integer increment ordering, and so when the + decoding tables are built in the large loop below, the integer codes + are incremented backwards. + + This routine assumes, but does not check, that all of the entries in + lens[] are in the range 0..MAXBITS. The caller must assure this. + 1..MAXBITS is interpreted as that code length. zero means that that + symbol does not occur in this code. + + The codes are sorted by computing a count of codes for each length, + creating from that a table of starting indices for each length in the + sorted table, and then entering the symbols in order in the sorted + table. The sorted table is work[], with that space being provided by + the caller. + + The length counts are used for other purposes as well, i.e. finding + the minimum and maximum length codes, determining if there are any + codes at all, checking for a valid set of lengths, and looking ahead + at length counts to determine sub-table sizes when building the + decoding tables. + */ + + /* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */ + for (len = 0; len <= MAXBITS; len++) + count[len] = 0; + for (sym = 0; sym < codes; sym++) + count[lens[sym]]++; + + /* bound code lengths, force root to be within code lengths */ + root = *bits; + for (max = MAXBITS; max >= 1; max--) + if (count[max] != 0) break; + if (root > max) root = max; + if (max == 0) { /* no symbols to code at all */ + here.op = (unsigned char)64; /* invalid code marker */ + here.bits = (unsigned char)1; + here.val = (unsigned short)0; + *(*table)++ = here; /* make a table to force an error */ + *(*table)++ = here; + *bits = 1; + return 0; /* no symbols, but wait for decoding to report error */ + } + for (min = 1; min < max; min++) + if (count[min] != 0) break; + if (root < min) root = min; + + /* check for an over-subscribed or incomplete set of lengths */ + left = 1; + for (len = 1; len <= MAXBITS; len++) { + left <<= 1; + left -= count[len]; + if (left < 0) return -1; /* over-subscribed */ + } + if (left > 0 && (type == CODES || max != 1)) + return -1; /* incomplete set */ + + /* generate offsets into symbol table for each length for sorting */ + offs[1] = 0; + for (len = 1; len < MAXBITS; len++) + offs[len + 1] = offs[len] + count[len]; + + /* sort symbols by length, by symbol order within each length */ + for (sym = 0; sym < codes; sym++) + if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym; + + /* + Create and fill in decoding tables. In this loop, the table being + filled is at next and has curr index bits. The code being used is huff + with length len. That code is converted to an index by dropping drop + bits off of the bottom. For codes where len is less than drop + curr, + those top drop + curr - len bits are incremented through all values to + fill the table with replicated entries. + + root is the number of index bits for the root table. When len exceeds + root, sub-tables are created pointed to by the root entry with an index + of the low root bits of huff. This is saved in low to check for when a + new sub-table should be started. drop is zero when the root table is + being filled, and drop is root when sub-tables are being filled. + + When a new sub-table is needed, it is necessary to look ahead in the + code lengths to determine what size sub-table is needed. The length + counts are used for this, and so count[] is decremented as codes are + entered in the tables. + + used keeps track of how many table entries have been allocated from the + provided *table space. It is checked for LENS and DIST tables against + the constants ENOUGH_LENS and ENOUGH_DISTS to guard against changes in + the initial root table size constants. See the comments in inftrees.h + for more information. + + sym increments through all symbols, and the loop terminates when + all codes of length max, i.e. all codes, have been processed. This + routine permits incomplete codes, so another loop after this one fills + in the rest of the decoding tables with invalid code markers. + */ + + /* set up for code type */ + switch (type) { + case CODES: + base = extra = work; /* dummy value--not used */ + end = 19; + break; + case LENS: + base = lbase; + base -= 257; + extra = lext; + extra -= 257; + end = 256; + break; + default: /* DISTS */ + base = dbase; + extra = dext; + end = -1; + } + + /* initialize state for loop */ + huff = 0; /* starting code */ + sym = 0; /* starting code symbol */ + len = min; /* starting code length */ + next = *table; /* current table to fill in */ + curr = root; /* current table index bits */ + drop = 0; /* current bits to drop from code for index */ + low = (unsigned)(-1); /* trigger new sub-table when len > root */ + used = 1U << root; /* use root table entries */ + mask = used - 1; /* mask for comparing low */ + + /* check available table space */ + if ((type == LENS && used >= ENOUGH_LENS) || + (type == DISTS && used >= ENOUGH_DISTS)) + return 1; + + /* process all codes and make table entries */ + for (;;) { + /* create table entry */ + here.bits = (unsigned char)(len - drop); + if ((int)(work[sym]) < end) { + here.op = (unsigned char)0; + here.val = work[sym]; + } + else if ((int)(work[sym]) > end) { + here.op = (unsigned char)(extra[work[sym]]); + here.val = base[work[sym]]; + } + else { + here.op = (unsigned char)(32 + 64); /* end of block */ + here.val = 0; + } + + /* replicate for those indices with low len bits equal to huff */ + incr = 1U << (len - drop); + fill = 1U << curr; + min = fill; /* save offset to next table */ + do { + fill -= incr; + next[(huff >> drop) + fill] = here; + } while (fill != 0); + + /* backwards increment the len-bit code huff */ + incr = 1U << (len - 1); + while (huff & incr) + incr >>= 1; + if (incr != 0) { + huff &= incr - 1; + huff += incr; + } + else + huff = 0; + + /* go to next symbol, update count, len */ + sym++; + if (--(count[len]) == 0) { + if (len == max) break; + len = lens[work[sym]]; + } + + /* create new sub-table if needed */ + if (len > root && (huff & mask) != low) { + /* if first time, transition to sub-tables */ + if (drop == 0) + drop = root; + + /* increment past last table */ + next += min; /* here min is 1 << curr */ + + /* determine length of next table */ + curr = len - drop; + left = (int)(1 << curr); + while (curr + drop < max) { + left -= count[curr + drop]; + if (left <= 0) break; + curr++; + left <<= 1; + } + + /* check for enough space */ + used += 1U << curr; + if ((type == LENS && used >= ENOUGH_LENS) || + (type == DISTS && used >= ENOUGH_DISTS)) + return 1; + + /* point entry in root table to sub-table */ + low = huff & mask; + (*table)[low].op = (unsigned char)curr; + (*table)[low].bits = (unsigned char)root; + (*table)[low].val = (unsigned short)(next - *table); + } + } + + /* fill in remaining table entry if code is incomplete (guaranteed to have + at most one remaining entry, since if the code is incomplete, the + maximum code length that was allowed to get this far is one bit) */ + if (huff != 0) { + here.op = (unsigned char)64; /* invalid code marker */ + here.bits = (unsigned char)(len - drop); + here.val = (unsigned short)0; + next[huff] = here; + } + + /* set return parameters */ + *table += used; + *bits = root; + return 0; +} diff --git a/libs/zlib/inftrees.h b/libs/zlib/inftrees.h new file mode 100644 index 000000000..baa53a0b1 --- /dev/null +++ b/libs/zlib/inftrees.h @@ -0,0 +1,62 @@ +/* inftrees.h -- header to use inftrees.c + * Copyright (C) 1995-2005, 2010 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* WARNING: this file should *not* be used by applications. It is + part of the implementation of the compression library and is + subject to change. Applications should only use zlib.h. + */ + +/* Structure for decoding tables. Each entry provides either the + information needed to do the operation requested by the code that + indexed that table entry, or it provides a pointer to another + table that indexes more bits of the code. op indicates whether + the entry is a pointer to another table, a literal, a length or + distance, an end-of-block, or an invalid code. For a table + pointer, the low four bits of op is the number of index bits of + that table. For a length or distance, the low four bits of op + is the number of extra bits to get after the code. bits is + the number of bits in this code or part of the code to drop off + of the bit buffer. val is the actual byte to output in the case + of a literal, the base length or distance, or the offset from + the current table to the next table. Each entry is four bytes. */ +typedef struct { + unsigned char op; /* operation, extra bits, table bits */ + unsigned char bits; /* bits in this part of the code */ + unsigned short val; /* offset in table or code value */ +} code; + +/* op values as set by inflate_table(): + 00000000 - literal + 0000tttt - table link, tttt != 0 is the number of table index bits + 0001eeee - length or distance, eeee is the number of extra bits + 01100000 - end of block + 01000000 - invalid code + */ + +/* Maximum size of the dynamic table. The maximum number of code structures is + 1444, which is the sum of 852 for literal/length codes and 592 for distance + codes. These values were found by exhaustive searches using the program + examples/enough.c found in the zlib distribtution. The arguments to that + program are the number of symbols, the initial root table size, and the + maximum bit length of a code. "enough 286 9 15" for literal/length codes + returns returns 852, and "enough 30 6 15" for distance codes returns 592. + The initial root table size (9 or 6) is found in the fifth argument of the + inflate_table() calls in inflate.c and infback.c. If the root table size is + changed, then these maximum sizes would be need to be recalculated and + updated. */ +#define ENOUGH_LENS 852 +#define ENOUGH_DISTS 592 +#define ENOUGH (ENOUGH_LENS+ENOUGH_DISTS) + +/* Type of code to build for inflate_table() */ +typedef enum { + CODES, + LENS, + DISTS +} codetype; + +int ZLIB_INTERNAL inflate_table OF((codetype type, unsigned short FAR *lens, + unsigned codes, code FAR * FAR *table, + unsigned FAR *bits, unsigned short FAR *work)); diff --git a/libs/zlib/make_vms.com b/libs/zlib/make_vms.com new file mode 100644 index 000000000..11be527f0 --- /dev/null +++ b/libs/zlib/make_vms.com @@ -0,0 +1,804 @@ +$! make libz under VMS written by +$! Martin P.J. Zinser +$! +$! In case of problems with the install you might contact me at +$! zinser@zinser.no-ip.info(preferred) or +$! zinser@sysdev.deutsche-boerse.com (work) +$! +$! Make procedure history for Zlib +$! +$!------------------------------------------------------------------------------ +$! Version history +$! 0.01 20060120 First version to receive a number +$! 0.02 20061008 Adapt to new Makefile.in +$! 0.03 20091224 Add support for large file check +$! 0.04 20100110 Add new gzclose, gzlib, gzread, gzwrite +$! 0.05 20100221 Exchange zlibdefs.h by zconf.h.in +$! +$ on error then goto err_exit +$ set proc/parse=ext +$! +$ true = 1 +$ false = 0 +$ tmpnam = "temp_" + f$getjpi("","pid") +$ tt = tmpnam + ".txt" +$ tc = tmpnam + ".c" +$ th = tmpnam + ".h" +$ define/nolog tconfig 'th' +$ its_decc = false +$ its_vaxc = false +$ its_gnuc = false +$ s_case = False +$! +$! Setup variables holding "config" information +$! +$ Make = "" +$ name = "Zlib" +$ version = "?.?.?" +$ v_string = "ZLIB_VERSION" +$ v_file = "zlib.h" +$ ccopt = "" +$ lopts = "" +$ dnsrl = "" +$ aconf_in_file = "zconf.h.in#zconf.h_in" +$ conf_check_string = "" +$ linkonly = false +$ optfile = name + ".opt" +$ libdefs = "" +$ axp = f$getsyi("HW_MODEL").ge.1024 .and. f$getsyi("HW_MODEL").lt.4096 +$! +$ whoami = f$parse(f$enviornment("Procedure"),,,,"NO_CONCEAL") +$ mydef = F$parse(whoami,,,"DEVICE") +$ mydir = f$parse(whoami,,,"DIRECTORY") - "][" +$ myproc = f$parse(whoami,,,"Name") + f$parse(whoami,,,"type") +$! +$! Check for MMK/MMS +$! +$ If F$Search ("Sys$System:MMS.EXE") .nes. "" Then Make = "MMS" +$ If F$Type (MMK) .eqs. "STRING" Then Make = "MMK" +$! +$! +$ gosub find_version +$! +$ open/write topt tmp.opt +$ open/write optf 'optfile' +$! +$ gosub check_opts +$! +$! Look for the compiler used +$! +$ gosub check_compiler +$ close topt +$! +$ if its_decc +$ then +$ ccopt = "/prefix=all" + ccopt +$ if f$trnlnm("SYS") .eqs. "" +$ then +$ if axp +$ then +$ define sys sys$library: +$ else +$ ccopt = "/decc" + ccopt +$ define sys decc$library_include: +$ endif +$ endif +$ endif +$ if its_vaxc .or. its_gnuc +$ then +$ if f$trnlnm("SYS").eqs."" then define sys sys$library: +$ endif +$! +$! Build a fake configure input header +$! +$ open/write conf_hin config.hin +$ write conf_hin "#undef _LARGEFILE64_SOURCE" +$ close conf_hin +$! +$! +$ i = 0 +$FIND_ACONF: +$ fname = f$element(i,"#",aconf_in_file) +$ if fname .eqs. "#" then goto AMISS_ERR +$ if f$search(fname) .eqs. "" +$ then +$ i = i + 1 +$ goto find_aconf +$ endif +$ open/read/err=aconf_err aconf_in 'fname' +$ open/write aconf zconf.h +$ACONF_LOOP: +$ read/end_of_file=aconf_exit aconf_in line +$ work = f$edit(line, "compress,trim") +$ if f$extract(0,6,work) .nes. "#undef" +$ then +$ if f$extract(0,12,work) .nes. "#cmakedefine" +$ then +$ write aconf line +$ endif +$ else +$ cdef = f$element(1," ",work) +$ gosub check_config +$ endif +$ goto aconf_loop +$ACONF_EXIT: +$ write aconf "#define VMS 1" +$ write aconf "#include " +$ write aconf "#include " +$ write aconf "#ifdef _LARGEFILE" +$ write aconf "#define off64_t __off64_t" +$ write aconf "#define fopen64 fopen" +$ write aconf "#define fseeko64 fseeko" +$ write aconf "#define lseek64 lseek" +$ write aconf "#define ftello64 ftell" +$ write aconf "#endif" +$ close aconf_in +$ close aconf +$ if f$search("''th'") .nes. "" then delete 'th';* +$! Build the thing plain or with mms +$! +$ write sys$output "Compiling Zlib sources ..." +$ if make.eqs."" +$ then +$ dele example.obj;*,minigzip.obj;* +$ CALL MAKE adler32.OBJ "CC ''CCOPT' adler32" - + adler32.c zlib.h zconf.h +$ CALL MAKE compress.OBJ "CC ''CCOPT' compress" - + compress.c zlib.h zconf.h +$ CALL MAKE crc32.OBJ "CC ''CCOPT' crc32" - + crc32.c zlib.h zconf.h +$ CALL MAKE deflate.OBJ "CC ''CCOPT' deflate" - + deflate.c deflate.h zutil.h zlib.h zconf.h +$ CALL MAKE gzclose.OBJ "CC ''CCOPT' gzclose" - + gzclose.c zutil.h zlib.h zconf.h +$ CALL MAKE gzlib.OBJ "CC ''CCOPT' gzlib" - + gzlib.c zutil.h zlib.h zconf.h +$ CALL MAKE gzread.OBJ "CC ''CCOPT' gzread" - + gzread.c zutil.h zlib.h zconf.h +$ CALL MAKE gzwrite.OBJ "CC ''CCOPT' gzwrite" - + gzwrite.c zutil.h zlib.h zconf.h +$ CALL MAKE infback.OBJ "CC ''CCOPT' infback" - + infback.c zutil.h inftrees.h inflate.h inffast.h inffixed.h +$ CALL MAKE inffast.OBJ "CC ''CCOPT' inffast" - + inffast.c zutil.h zlib.h zconf.h inffast.h +$ CALL MAKE inflate.OBJ "CC ''CCOPT' inflate" - + inflate.c zutil.h zlib.h zconf.h infblock.h +$ CALL MAKE inftrees.OBJ "CC ''CCOPT' inftrees" - + inftrees.c zutil.h zlib.h zconf.h inftrees.h +$ CALL MAKE trees.OBJ "CC ''CCOPT' trees" - + trees.c deflate.h zutil.h zlib.h zconf.h +$ CALL MAKE uncompr.OBJ "CC ''CCOPT' uncompr" - + uncompr.c zlib.h zconf.h +$ CALL MAKE zutil.OBJ "CC ''CCOPT' zutil" - + zutil.c zutil.h zlib.h zconf.h +$ write sys$output "Building Zlib ..." +$ CALL MAKE libz.OLB "lib/crea libz.olb *.obj" *.OBJ +$ write sys$output "Building example..." +$ CALL MAKE example.OBJ "CC ''CCOPT' example" - + test/example.c zlib.h zconf.h +$ call make example.exe "LINK example,libz.olb/lib" example.obj libz.olb +$ if f$search("x11vms:xvmsutils.olb") .nes. "" +$ then +$ write sys$output "Building minigzip..." +$ CALL MAKE minigzip.OBJ "CC ''CCOPT' minigzip" - + test/minigzip.c zlib.h zconf.h +$ call make minigzip.exe - + "LINK minigzip,libz.olb/lib,x11vms:xvmsutils.olb/lib" - + minigzip.obj libz.olb +$ endif +$ else +$ gosub crea_mms +$ write sys$output "Make ''name' ''version' with ''Make' " +$ 'make' +$ endif +$! +$! Alpha gets a shareable image +$! +$ If axp +$ Then +$ gosub crea_olist +$ write sys$output "Creating libzshr.exe" +$ call anal_obj_axp modules.opt _link.opt +$ if s_case +$ then +$ open/append optf modules.opt +$ write optf "case_sensitive=YES" +$ close optf +$ endif +$ LINK_'lopts'/SHARE=libzshr.exe modules.opt/opt,_link.opt/opt +$ endif +$ write sys$output "Zlib build completed" +$ exit +$CC_ERR: +$ write sys$output "C compiler required to build ''name'" +$ goto err_exit +$ERR_EXIT: +$ set message/facil/ident/sever/text +$ close/nolog optf +$ close/nolog topt +$ close/nolog conf_hin +$ close/nolog aconf_in +$ close/nolog aconf +$ close/nolog out +$ close/nolog min +$ close/nolog mod +$ close/nolog h_in +$ write sys$output "Exiting..." +$ exit 2 +$! +$! +$MAKE: SUBROUTINE !SUBROUTINE TO CHECK DEPENDENCIES +$ V = 'F$Verify(0) +$! P1 = What we are trying to make +$! P2 = Command to make it +$! P3 - P8 What it depends on +$ +$ If F$Search(P1) .Eqs. "" Then Goto Makeit +$ Time = F$CvTime(F$File(P1,"RDT")) +$arg=3 +$Loop: +$ Argument = P'arg +$ If Argument .Eqs. "" Then Goto Exit +$ El=0 +$Loop2: +$ File = F$Element(El," ",Argument) +$ If File .Eqs. " " Then Goto Endl +$ AFile = "" +$Loop3: +$ OFile = AFile +$ AFile = F$Search(File) +$ If AFile .Eqs. "" .Or. AFile .Eqs. OFile Then Goto NextEl +$ If F$CvTime(F$File(AFile,"RDT")) .Ges. Time Then Goto Makeit +$ Goto Loop3 +$NextEL: +$ El = El + 1 +$ Goto Loop2 +$EndL: +$ arg=arg+1 +$ If arg .Le. 8 Then Goto Loop +$ Goto Exit +$ +$Makeit: +$ VV=F$VERIFY(0) +$ write sys$output P2 +$ 'P2 +$ VV='F$Verify(VV) +$Exit: +$ If V Then Set Verify +$ENDSUBROUTINE +$!------------------------------------------------------------------------------ +$! +$! Check command line options and set symbols accordingly +$! +$!------------------------------------------------------------------------------ +$! Version history +$! 0.01 20041206 First version to receive a number +$! 0.02 20060126 Add new "HELP" target +$ CHECK_OPTS: +$ i = 1 +$ OPT_LOOP: +$ if i .lt. 9 +$ then +$ cparm = f$edit(p'i',"upcase") +$! +$! Check if parameter actually contains something +$! +$ if f$edit(cparm,"trim") .nes. "" +$ then +$ if cparm .eqs. "DEBUG" +$ then +$ ccopt = ccopt + "/noopt/deb" +$ lopts = lopts + "/deb" +$ endif +$ if f$locate("CCOPT=",cparm) .lt. f$length(cparm) +$ then +$ start = f$locate("=",cparm) + 1 +$ len = f$length(cparm) - start +$ ccopt = ccopt + f$extract(start,len,cparm) +$ if f$locate("AS_IS",f$edit(ccopt,"UPCASE")) .lt. f$length(ccopt) - + then s_case = true +$ endif +$ if cparm .eqs. "LINK" then linkonly = true +$ if f$locate("LOPTS=",cparm) .lt. f$length(cparm) +$ then +$ start = f$locate("=",cparm) + 1 +$ len = f$length(cparm) - start +$ lopts = lopts + f$extract(start,len,cparm) +$ endif +$ if f$locate("CC=",cparm) .lt. f$length(cparm) +$ then +$ start = f$locate("=",cparm) + 1 +$ len = f$length(cparm) - start +$ cc_com = f$extract(start,len,cparm) + if (cc_com .nes. "DECC") .and. - + (cc_com .nes. "VAXC") .and. - + (cc_com .nes. "GNUC") +$ then +$ write sys$output "Unsupported compiler choice ''cc_com' ignored" +$ write sys$output "Use DECC, VAXC, or GNUC instead" +$ else +$ if cc_com .eqs. "DECC" then its_decc = true +$ if cc_com .eqs. "VAXC" then its_vaxc = true +$ if cc_com .eqs. "GNUC" then its_gnuc = true +$ endif +$ endif +$ if f$locate("MAKE=",cparm) .lt. f$length(cparm) +$ then +$ start = f$locate("=",cparm) + 1 +$ len = f$length(cparm) - start +$ mmks = f$extract(start,len,cparm) +$ if (mmks .eqs. "MMK") .or. (mmks .eqs. "MMS") +$ then +$ make = mmks +$ else +$ write sys$output "Unsupported make choice ''mmks' ignored" +$ write sys$output "Use MMK or MMS instead" +$ endif +$ endif +$ if cparm .eqs. "HELP" then gosub bhelp +$ endif +$ i = i + 1 +$ goto opt_loop +$ endif +$ return +$!------------------------------------------------------------------------------ +$! +$! Look for the compiler used +$! +$! Version history +$! 0.01 20040223 First version to receive a number +$! 0.02 20040229 Save/set value of decc$no_rooted_search_lists +$! 0.03 20060202 Extend handling of GNU C +$! 0.04 20090402 Compaq -> hp +$CHECK_COMPILER: +$ if (.not. (its_decc .or. its_vaxc .or. its_gnuc)) +$ then +$ its_decc = (f$search("SYS$SYSTEM:DECC$COMPILER.EXE") .nes. "") +$ its_vaxc = .not. its_decc .and. (F$Search("SYS$System:VAXC.Exe") .nes. "") +$ its_gnuc = .not. (its_decc .or. its_vaxc) .and. (f$trnlnm("gnu_cc") .nes. "") +$ endif +$! +$! Exit if no compiler available +$! +$ if (.not. (its_decc .or. its_vaxc .or. its_gnuc)) +$ then goto CC_ERR +$ else +$ if its_decc +$ then +$ write sys$output "CC compiler check ... hp C" +$ if f$trnlnm("decc$no_rooted_search_lists") .nes. "" +$ then +$ dnrsl = f$trnlnm("decc$no_rooted_search_lists") +$ endif +$ define/nolog decc$no_rooted_search_lists 1 +$ else +$ if its_vaxc then write sys$output "CC compiler check ... VAX C" +$ if its_gnuc +$ then +$ write sys$output "CC compiler check ... GNU C" +$ if f$trnlnm(topt) then write topt "gnu_cc:[000000]gcclib.olb/lib" +$ if f$trnlnm(optf) then write optf "gnu_cc:[000000]gcclib.olb/lib" +$ cc = "gcc" +$ endif +$ if f$trnlnm(topt) then write topt "sys$share:vaxcrtl.exe/share" +$ if f$trnlnm(optf) then write optf "sys$share:vaxcrtl.exe/share" +$ endif +$ endif +$ return +$!------------------------------------------------------------------------------ +$! +$! If MMS/MMK are available dump out the descrip.mms if required +$! +$CREA_MMS: +$ write sys$output "Creating descrip.mms..." +$ create descrip.mms +$ open/append out descrip.mms +$ copy sys$input: out +$ deck +# descrip.mms: MMS description file for building zlib on VMS +# written by Martin P.J. Zinser +# + +OBJS = adler32.obj, compress.obj, crc32.obj, gzclose.obj, gzlib.obj\ + gzread.obj, gzwrite.obj, uncompr.obj, infback.obj\ + deflate.obj, trees.obj, zutil.obj, inflate.obj, \ + inftrees.obj, inffast.obj + +$ eod +$ write out "CFLAGS=", ccopt +$ write out "LOPTS=", lopts +$ copy sys$input: out +$ deck + +all : example.exe minigzip.exe libz.olb + @ write sys$output " Example applications available" + +libz.olb : libz.olb($(OBJS)) + @ write sys$output " libz available" + +example.exe : example.obj libz.olb + link $(LOPTS) example,libz.olb/lib + +minigzip.exe : minigzip.obj libz.olb + link $(LOPTS) minigzip,libz.olb/lib,x11vms:xvmsutils.olb/lib + +clean : + delete *.obj;*,libz.olb;*,*.opt;*,*.exe;* + + +# Other dependencies. +adler32.obj : adler32.c zutil.h zlib.h zconf.h +compress.obj : compress.c zlib.h zconf.h +crc32.obj : crc32.c zutil.h zlib.h zconf.h +deflate.obj : deflate.c deflate.h zutil.h zlib.h zconf.h +example.obj : test/example.c zlib.h zconf.h +gzclose.obj : gzclose.c zutil.h zlib.h zconf.h +gzlib.obj : gzlib.c zutil.h zlib.h zconf.h +gzread.obj : gzread.c zutil.h zlib.h zconf.h +gzwrite.obj : gzwrite.c zutil.h zlib.h zconf.h +inffast.obj : inffast.c zutil.h zlib.h zconf.h inftrees.h inffast.h +inflate.obj : inflate.c zutil.h zlib.h zconf.h +inftrees.obj : inftrees.c zutil.h zlib.h zconf.h inftrees.h +minigzip.obj : test/minigzip.c zlib.h zconf.h +trees.obj : trees.c deflate.h zutil.h zlib.h zconf.h +uncompr.obj : uncompr.c zlib.h zconf.h +zutil.obj : zutil.c zutil.h zlib.h zconf.h +infback.obj : infback.c zutil.h inftrees.h inflate.h inffast.h inffixed.h +$ eod +$ close out +$ return +$!------------------------------------------------------------------------------ +$! +$! Read list of core library sources from makefile.in and create options +$! needed to build shareable image +$! +$CREA_OLIST: +$ open/read min makefile.in +$ open/write mod modules.opt +$ src_check = "OBJC =" +$MRLOOP: +$ read/end=mrdone min rec +$ if (f$extract(0,6,rec) .nes. src_check) then goto mrloop +$ rec = rec - src_check +$ gosub extra_filnam +$ if (f$element(1,"\",rec) .eqs. "\") then goto mrdone +$MRSLOOP: +$ read/end=mrdone min rec +$ gosub extra_filnam +$ if (f$element(1,"\",rec) .nes. "\") then goto mrsloop +$MRDONE: +$ close min +$ close mod +$ return +$!------------------------------------------------------------------------------ +$! +$! Take record extracted in crea_olist and split it into single filenames +$! +$EXTRA_FILNAM: +$ myrec = f$edit(rec - "\", "trim,compress") +$ i = 0 +$FELOOP: +$ srcfil = f$element(i," ", myrec) +$ if (srcfil .nes. " ") +$ then +$ write mod f$parse(srcfil,,,"NAME"), ".obj" +$ i = i + 1 +$ goto feloop +$ endif +$ return +$!------------------------------------------------------------------------------ +$! +$! Find current Zlib version number +$! +$FIND_VERSION: +$ open/read h_in 'v_file' +$hloop: +$ read/end=hdone h_in rec +$ rec = f$edit(rec,"TRIM") +$ if (f$extract(0,1,rec) .nes. "#") then goto hloop +$ rec = f$edit(rec - "#", "TRIM") +$ if f$element(0," ",rec) .nes. "define" then goto hloop +$ if f$element(1," ",rec) .eqs. v_string +$ then +$ version = 'f$element(2," ",rec)' +$ goto hdone +$ endif +$ goto hloop +$hdone: +$ close h_in +$ return +$!------------------------------------------------------------------------------ +$! +$CHECK_CONFIG: +$! +$ in_ldef = f$locate(cdef,libdefs) +$ if (in_ldef .lt. f$length(libdefs)) +$ then +$ write aconf "#define ''cdef' 1" +$ libdefs = f$extract(0,in_ldef,libdefs) + - + f$extract(in_ldef + f$length(cdef) + 1, - + f$length(libdefs) - in_ldef - f$length(cdef) - 1, - + libdefs) +$ else +$ if (f$type('cdef') .eqs. "INTEGER") +$ then +$ write aconf "#define ''cdef' ", 'cdef' +$ else +$ if (f$type('cdef') .eqs. "STRING") +$ then +$ write aconf "#define ''cdef' ", """", '''cdef'', """" +$ else +$ gosub check_cc_def +$ endif +$ endif +$ endif +$ return +$!------------------------------------------------------------------------------ +$! +$! Check if this is a define relating to the properties of the C/C++ +$! compiler +$! +$ CHECK_CC_DEF: +$ if (cdef .eqs. "_LARGEFILE64_SOURCE") +$ then +$ copy sys$input: 'tc' +$ deck +#include "tconfig" +#define _LARGEFILE +#include + +int main(){ +FILE *fp; + fp = fopen("temp.txt","r"); + fseeko(fp,1,SEEK_SET); + fclose(fp); +} + +$ eod +$ test_inv = false +$ comm_h = false +$ gosub cc_prop_check +$ return +$ endif +$ write aconf "/* ", line, " */" +$ return +$!------------------------------------------------------------------------------ +$! +$! Check for properties of C/C++ compiler +$! +$! Version history +$! 0.01 20031020 First version to receive a number +$! 0.02 20031022 Added logic for defines with value +$! 0.03 20040309 Make sure local config file gets not deleted +$! 0.04 20041230 Also write include for configure run +$! 0.05 20050103 Add processing of "comment defines" +$CC_PROP_CHECK: +$ cc_prop = true +$ is_need = false +$ is_need = (f$extract(0,4,cdef) .eqs. "NEED") .or. (test_inv .eq. true) +$ if f$search(th) .eqs. "" then create 'th' +$ set message/nofac/noident/nosever/notext +$ on error then continue +$ cc 'tmpnam' +$ if .not. ($status) then cc_prop = false +$ on error then continue +$! The headers might lie about the capabilities of the RTL +$ link 'tmpnam',tmp.opt/opt +$ if .not. ($status) then cc_prop = false +$ set message/fac/ident/sever/text +$ on error then goto err_exit +$ delete/nolog 'tmpnam'.*;*/exclude='th' +$ if (cc_prop .and. .not. is_need) .or. - + (.not. cc_prop .and. is_need) +$ then +$ write sys$output "Checking for ''cdef'... yes" +$ if f$type('cdef_val'_yes) .nes. "" +$ then +$ if f$type('cdef_val'_yes) .eqs. "INTEGER" - + then call write_config f$fao("#define !AS !UL",cdef,'cdef_val'_yes) +$ if f$type('cdef_val'_yes) .eqs. "STRING" - + then call write_config f$fao("#define !AS !AS",cdef,'cdef_val'_yes) +$ else +$ call write_config f$fao("#define !AS 1",cdef) +$ endif +$ if (cdef .eqs. "HAVE_FSEEKO") .or. (cdef .eqs. "_LARGE_FILES") .or. - + (cdef .eqs. "_LARGEFILE64_SOURCE") then - + call write_config f$string("#define _LARGEFILE 1") +$ else +$ write sys$output "Checking for ''cdef'... no" +$ if (comm_h) +$ then + call write_config f$fao("/* !AS */",line) +$ else +$ if f$type('cdef_val'_no) .nes. "" +$ then +$ if f$type('cdef_val'_no) .eqs. "INTEGER" - + then call write_config f$fao("#define !AS !UL",cdef,'cdef_val'_no) +$ if f$type('cdef_val'_no) .eqs. "STRING" - + then call write_config f$fao("#define !AS !AS",cdef,'cdef_val'_no) +$ else +$ call write_config f$fao("#undef !AS",cdef) +$ endif +$ endif +$ endif +$ return +$!------------------------------------------------------------------------------ +$! +$! Check for properties of C/C++ compiler with multiple result values +$! +$! Version history +$! 0.01 20040127 First version +$! 0.02 20050103 Reconcile changes from cc_prop up to version 0.05 +$CC_MPROP_CHECK: +$ cc_prop = true +$ i = 1 +$ idel = 1 +$ MT_LOOP: +$ if f$type(result_'i') .eqs. "STRING" +$ then +$ set message/nofac/noident/nosever/notext +$ on error then continue +$ cc 'tmpnam'_'i' +$ if .not. ($status) then cc_prop = false +$ on error then continue +$! The headers might lie about the capabilities of the RTL +$ link 'tmpnam'_'i',tmp.opt/opt +$ if .not. ($status) then cc_prop = false +$ set message/fac/ident/sever/text +$ on error then goto err_exit +$ delete/nolog 'tmpnam'_'i'.*;* +$ if (cc_prop) +$ then +$ write sys$output "Checking for ''cdef'... ", mdef_'i' +$ if f$type(mdef_'i') .eqs. "INTEGER" - + then call write_config f$fao("#define !AS !UL",cdef,mdef_'i') +$ if f$type('cdef_val'_yes) .eqs. "STRING" - + then call write_config f$fao("#define !AS !AS",cdef,mdef_'i') +$ goto msym_clean +$ else +$ i = i + 1 +$ goto mt_loop +$ endif +$ endif +$ write sys$output "Checking for ''cdef'... no" +$ call write_config f$fao("#undef !AS",cdef) +$ MSYM_CLEAN: +$ if (idel .le. msym_max) +$ then +$ delete/sym mdef_'idel' +$ idel = idel + 1 +$ goto msym_clean +$ endif +$ return +$!------------------------------------------------------------------------------ +$! +$! Analyze Object files for OpenVMS AXP to extract Procedure and Data +$! information to build a symbol vector for a shareable image +$! All the "brains" of this logic was suggested by Hartmut Becker +$! (Hartmut.Becker@compaq.com). All the bugs were introduced by me +$! (zinser@zinser.no-ip.info), so if you do have problem reports please do not +$! bother Hartmut/HP, but get in touch with me +$! +$! Version history +$! 0.01 20040406 Skip over shareable images in option file +$! 0.02 20041109 Fix option file for shareable images with case_sensitive=YES +$! 0.03 20050107 Skip over Identification labels in option file +$! 0.04 20060117 Add uppercase alias to code compiled with /name=as_is +$! +$ ANAL_OBJ_AXP: Subroutine +$ V = 'F$Verify(0) +$ SAY := "WRITE_ SYS$OUTPUT" +$ +$ IF F$SEARCH("''P1'") .EQS. "" +$ THEN +$ SAY "ANAL_OBJ_AXP-E-NOSUCHFILE: Error, inputfile ''p1' not available" +$ goto exit_aa +$ ENDIF +$ IF "''P2'" .EQS. "" +$ THEN +$ SAY "ANAL_OBJ_AXP: Error, no output file provided" +$ goto exit_aa +$ ENDIF +$ +$ open/read in 'p1 +$ create a.tmp +$ open/append atmp a.tmp +$ loop: +$ read/end=end_loop in line +$ if f$locate("/SHARE",f$edit(line,"upcase")) .lt. f$length(line) +$ then +$ write sys$output "ANAL_SKP_SHR-i-skipshare, ''line'" +$ goto loop +$ endif +$ if f$locate("IDENTIFICATION=",f$edit(line,"upcase")) .lt. f$length(line) +$ then +$ write sys$output "ANAL_OBJ_AXP-i-ident: Identification ", - + f$element(1,"=",line) +$ goto loop +$ endif +$ f= f$search(line) +$ if f .eqs. "" +$ then +$ write sys$output "ANAL_OBJ_AXP-w-nosuchfile, ''line'" +$ goto loop +$ endif +$ define/user sys$output nl: +$ define/user sys$error nl: +$ anal/obj/gsd 'f /out=x.tmp +$ open/read xtmp x.tmp +$ XLOOP: +$ read/end=end_xloop xtmp xline +$ xline = f$edit(xline,"compress") +$ write atmp xline +$ goto xloop +$ END_XLOOP: +$ close xtmp +$ goto loop +$ end_loop: +$ close in +$ close atmp +$ if f$search("a.tmp") .eqs. "" - + then $ exit +$ ! all global definitions +$ search a.tmp "symbol:","EGSY$V_DEF 1","EGSY$V_NORM 1"/out=b.tmp +$ ! all procedures +$ search b.tmp "EGSY$V_NORM 1"/wind=(0,1) /out=c.tmp +$ search c.tmp "symbol:"/out=d.tmp +$ define/user sys$output nl: +$ edito/edt/command=sys$input d.tmp +sub/symbol: "/symbol_vector=(/whole +sub/"/=PROCEDURE)/whole +exit +$ ! all data +$ search b.tmp "EGSY$V_DEF 1"/wind=(0,1) /out=e.tmp +$ search e.tmp "symbol:"/out=f.tmp +$ define/user sys$output nl: +$ edito/edt/command=sys$input f.tmp +sub/symbol: "/symbol_vector=(/whole +sub/"/=DATA)/whole +exit +$ sort/nodupl d.tmp,f.tmp g.tmp +$ open/read raw_vector g.tmp +$ open/write case_vector 'p2' +$ RAWLOOP: +$ read/end=end_rawloop raw_vector raw_element +$ write case_vector raw_element +$ if f$locate("=PROCEDURE)",raw_element) .lt. f$length(raw_element) +$ then +$ name = f$element(1,"=",raw_element) - "(" +$ if f$edit(name,"UPCASE") .nes. name then - + write case_vector f$fao(" symbol_vector=(!AS/!AS=PROCEDURE)", - + f$edit(name,"UPCASE"), name) +$ endif +$ if f$locate("=DATA)",raw_element) .lt. f$length(raw_element) +$ then +$ name = f$element(1,"=",raw_element) - "(" +$ if f$edit(name,"UPCASE") .nes. name then - + write case_vector f$fao(" symbol_vector=(!AS/!AS=DATA)", - + f$edit(name,"UPCASE"), name) +$ endif +$ goto rawloop +$ END_RAWLOOP: +$ close raw_vector +$ close case_vector +$ delete a.tmp;*,b.tmp;*,c.tmp;*,d.tmp;*,e.tmp;*,f.tmp;*,g.tmp;* +$ if f$search("x.tmp") .nes. "" - + then $ delete x.tmp;* +$! +$ EXIT_AA: +$ if V then set verify +$ endsubroutine +$!------------------------------------------------------------------------------ +$! +$! Write configuration to both permanent and temporary config file +$! +$! Version history +$! 0.01 20031029 First version to receive a number +$! +$WRITE_CONFIG: SUBROUTINE +$ write aconf 'p1' +$ open/append confh 'th' +$ write confh 'p1' +$ close confh +$ENDSUBROUTINE +$!------------------------------------------------------------------------------ diff --git a/libs/zlib/msdos/Makefile.bor b/libs/zlib/msdos/Makefile.bor new file mode 100644 index 000000000..0c1b99c9b --- /dev/null +++ b/libs/zlib/msdos/Makefile.bor @@ -0,0 +1,115 @@ +# Makefile for zlib +# Borland C++ +# Last updated: 15-Mar-2003 + +# To use, do "make -fmakefile.bor" +# To compile in small model, set below: MODEL=s + +# WARNING: the small model is supported but only for small values of +# MAX_WBITS and MAX_MEM_LEVEL. For example: +# -DMAX_WBITS=11 -DDEF_WBITS=11 -DMAX_MEM_LEVEL=3 +# If you wish to reduce the memory requirements (default 256K for big +# objects plus a few K), you can add to the LOC macro below: +# -DMAX_MEM_LEVEL=7 -DMAX_WBITS=14 +# See zconf.h for details about the memory requirements. + +# ------------ Turbo C++, Borland C++ ------------ + +# Optional nonstandard preprocessor flags (e.g. -DMAX_MEM_LEVEL=7) +# should be added to the environment via "set LOCAL_ZLIB=-DFOO" or added +# to the declaration of LOC here: +LOC = $(LOCAL_ZLIB) + +# type for CPU required: 0: 8086, 1: 80186, 2: 80286, 3: 80386, etc. +CPU_TYP = 0 + +# memory model: one of s, m, c, l (small, medium, compact, large) +MODEL=l + +# replace bcc with tcc for Turbo C++ 1.0, with bcc32 for the 32 bit version +CC=bcc +LD=bcc +AR=tlib + +# compiler flags +# replace "-O2" by "-O -G -a -d" for Turbo C++ 1.0 +CFLAGS=-O2 -Z -m$(MODEL) $(LOC) + +LDFLAGS=-m$(MODEL) -f- + + +# variables +ZLIB_LIB = zlib_$(MODEL).lib + +OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzclose.obj gzlib.obj gzread.obj +OBJ2 = gzwrite.obj infback.obj inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj +OBJP1 = +adler32.obj+compress.obj+crc32.obj+deflate.obj+gzclose.obj+gzlib.obj+gzread.obj +OBJP2 = +gzwrite.obj+infback.obj+inffast.obj+inflate.obj+inftrees.obj+trees.obj+uncompr.obj+zutil.obj + + +# targets +all: $(ZLIB_LIB) example.exe minigzip.exe + +.c.obj: + $(CC) -c $(CFLAGS) $*.c + +adler32.obj: adler32.c zlib.h zconf.h + +compress.obj: compress.c zlib.h zconf.h + +crc32.obj: crc32.c zlib.h zconf.h crc32.h + +deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h + +gzclose.obj: gzclose.c zlib.h zconf.h gzguts.h + +gzlib.obj: gzlib.c zlib.h zconf.h gzguts.h + +gzread.obj: gzread.c zlib.h zconf.h gzguts.h + +gzwrite.obj: gzwrite.c zlib.h zconf.h gzguts.h + +infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ + inffast.h inffixed.h + +inffast.obj: inffast.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ + inffast.h + +inflate.obj: inflate.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ + inffast.h inffixed.h + +inftrees.obj: inftrees.c zutil.h zlib.h zconf.h inftrees.h + +trees.obj: trees.c zutil.h zlib.h zconf.h deflate.h trees.h + +uncompr.obj: uncompr.c zlib.h zconf.h + +zutil.obj: zutil.c zutil.h zlib.h zconf.h + +example.obj: example.c zlib.h zconf.h + +minigzip.obj: minigzip.c zlib.h zconf.h + + +# the command line is cut to fit in the MS-DOS 128 byte limit: +$(ZLIB_LIB): $(OBJ1) $(OBJ2) + -del $(ZLIB_LIB) + $(AR) $(ZLIB_LIB) $(OBJP1) + $(AR) $(ZLIB_LIB) $(OBJP2) + +example.exe: example.obj $(ZLIB_LIB) + $(LD) $(LDFLAGS) example.obj $(ZLIB_LIB) + +minigzip.exe: minigzip.obj $(ZLIB_LIB) + $(LD) $(LDFLAGS) minigzip.obj $(ZLIB_LIB) + +test: example.exe minigzip.exe + example + echo hello world | minigzip | minigzip -d + +clean: + -del *.obj + -del *.lib + -del *.exe + -del zlib_*.bak + -del foo.gz diff --git a/libs/zlib/msdos/Makefile.dj2 b/libs/zlib/msdos/Makefile.dj2 new file mode 100644 index 000000000..29b03954d --- /dev/null +++ b/libs/zlib/msdos/Makefile.dj2 @@ -0,0 +1,104 @@ +# Makefile for zlib. Modified for djgpp v2.0 by F. J. Donahoe, 3/15/96. +# Copyright (C) 1995-1998 Jean-loup Gailly. +# For conditions of distribution and use, see copyright notice in zlib.h + +# To compile, or to compile and test, type: +# +# make -fmakefile.dj2; make test -fmakefile.dj2 +# +# To install libz.a, zconf.h and zlib.h in the djgpp directories, type: +# +# make install -fmakefile.dj2 +# +# after first defining LIBRARY_PATH and INCLUDE_PATH in djgpp.env as +# in the sample below if the pattern of the DJGPP distribution is to +# be followed. Remember that, while 'es around <=> are ignored in +# makefiles, they are *not* in batch files or in djgpp.env. +# - - - - - +# [make] +# INCLUDE_PATH=%\>;INCLUDE_PATH%%\DJDIR%\include +# LIBRARY_PATH=%\>;LIBRARY_PATH%%\DJDIR%\lib +# BUTT=-m486 +# - - - - - +# Alternately, these variables may be defined below, overriding the values +# in djgpp.env, as +# INCLUDE_PATH=c:\usr\include +# LIBRARY_PATH=c:\usr\lib + +CC=gcc + +#CFLAGS=-MMD -O +#CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7 +#CFLAGS=-MMD -g -DDEBUG +CFLAGS=-MMD -O3 $(BUTT) -Wall -Wwrite-strings -Wpointer-arith -Wconversion \ + -Wstrict-prototypes -Wmissing-prototypes + +# If cp.exe is available, replace "copy /Y" with "cp -fp" . +CP=copy /Y +# If gnu install.exe is available, replace $(CP) with ginstall. +INSTALL=$(CP) +# The default value of RM is "rm -f." If "rm.exe" is found, comment out: +RM=del +LDLIBS=-L. -lz +LD=$(CC) -s -o +LDSHARED=$(CC) + +INCL=zlib.h zconf.h +LIBS=libz.a + +AR=ar rcs + +prefix=/usr/local +exec_prefix = $(prefix) + +OBJS = adler32.o compress.o crc32.o gzclose.o gzlib.o gzread.o gzwrite.o \ + uncompr.o deflate.o trees.o zutil.o inflate.o infback.o inftrees.o inffast.o + +OBJA = +# to use the asm code: make OBJA=match.o + +TEST_OBJS = example.o minigzip.o + +all: example.exe minigzip.exe + +check: test +test: all + ./example + echo hello world | .\minigzip | .\minigzip -d + +%.o : %.c + $(CC) $(CFLAGS) -c $< -o $@ + +libz.a: $(OBJS) $(OBJA) + $(AR) $@ $(OBJS) $(OBJA) + +%.exe : %.o $(LIBS) + $(LD) $@ $< $(LDLIBS) + +# INCLUDE_PATH and LIBRARY_PATH were set for [make] in djgpp.env . + +.PHONY : uninstall clean + +install: $(INCL) $(LIBS) + -@if not exist $(INCLUDE_PATH)\nul mkdir $(INCLUDE_PATH) + -@if not exist $(LIBRARY_PATH)\nul mkdir $(LIBRARY_PATH) + $(INSTALL) zlib.h $(INCLUDE_PATH) + $(INSTALL) zconf.h $(INCLUDE_PATH) + $(INSTALL) libz.a $(LIBRARY_PATH) + +uninstall: + $(RM) $(INCLUDE_PATH)\zlib.h + $(RM) $(INCLUDE_PATH)\zconf.h + $(RM) $(LIBRARY_PATH)\libz.a + +clean: + $(RM) *.d + $(RM) *.o + $(RM) *.exe + $(RM) libz.a + $(RM) foo.gz + +DEPS := $(wildcard *.d) +ifneq ($(DEPS),) +include $(DEPS) +endif diff --git a/libs/zlib/msdos/Makefile.emx b/libs/zlib/msdos/Makefile.emx new file mode 100644 index 000000000..9c1b57a58 --- /dev/null +++ b/libs/zlib/msdos/Makefile.emx @@ -0,0 +1,69 @@ +# Makefile for zlib. Modified for emx 0.9c by Chr. Spieler, 6/17/98. +# Copyright (C) 1995-1998 Jean-loup Gailly. +# For conditions of distribution and use, see copyright notice in zlib.h + +# To compile, or to compile and test, type: +# +# make -fmakefile.emx; make test -fmakefile.emx +# + +CC=gcc + +#CFLAGS=-MMD -O +#CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7 +#CFLAGS=-MMD -g -DDEBUG +CFLAGS=-MMD -O3 $(BUTT) -Wall -Wwrite-strings -Wpointer-arith -Wconversion \ + -Wstrict-prototypes -Wmissing-prototypes + +# If cp.exe is available, replace "copy /Y" with "cp -fp" . +CP=copy /Y +# If gnu install.exe is available, replace $(CP) with ginstall. +INSTALL=$(CP) +# The default value of RM is "rm -f." If "rm.exe" is found, comment out: +RM=del +LDLIBS=-L. -lzlib +LD=$(CC) -s -o +LDSHARED=$(CC) + +INCL=zlib.h zconf.h +LIBS=zlib.a + +AR=ar rcs + +prefix=/usr/local +exec_prefix = $(prefix) + +OBJS = adler32.o compress.o crc32.o gzclose.o gzlib.o gzread.o gzwrite.o \ + uncompr.o deflate.o trees.o zutil.o inflate.o infback.o inftrees.o inffast.o + +TEST_OBJS = example.o minigzip.o + +all: example.exe minigzip.exe + +test: all + ./example + echo hello world | .\minigzip | .\minigzip -d + +%.o : %.c + $(CC) $(CFLAGS) -c $< -o $@ + +zlib.a: $(OBJS) + $(AR) $@ $(OBJS) + +%.exe : %.o $(LIBS) + $(LD) $@ $< $(LDLIBS) + + +.PHONY : clean + +clean: + $(RM) *.d + $(RM) *.o + $(RM) *.exe + $(RM) zlib.a + $(RM) foo.gz + +DEPS := $(wildcard *.d) +ifneq ($(DEPS),) +include $(DEPS) +endif diff --git a/libs/zlib/msdos/Makefile.msc b/libs/zlib/msdos/Makefile.msc new file mode 100644 index 000000000..cd2816fbf --- /dev/null +++ b/libs/zlib/msdos/Makefile.msc @@ -0,0 +1,112 @@ +# Makefile for zlib +# Microsoft C 5.1 or later +# Last updated: 19-Mar-2003 + +# To use, do "make makefile.msc" +# To compile in small model, set below: MODEL=S + +# If you wish to reduce the memory requirements (default 256K for big +# objects plus a few K), you can add to the LOC macro below: +# -DMAX_MEM_LEVEL=7 -DMAX_WBITS=14 +# See zconf.h for details about the memory requirements. + +# ------------- Microsoft C 5.1 and later ------------- + +# Optional nonstandard preprocessor flags (e.g. -DMAX_MEM_LEVEL=7) +# should be added to the environment via "set LOCAL_ZLIB=-DFOO" or added +# to the declaration of LOC here: +LOC = $(LOCAL_ZLIB) + +# Type for CPU required: 0: 8086, 1: 80186, 2: 80286, 3: 80386, etc. +CPU_TYP = 0 + +# Memory model: one of S, M, C, L (small, medium, compact, large) +MODEL=L + +CC=cl +CFLAGS=-nologo -A$(MODEL) -G$(CPU_TYP) -W3 -Oait -Gs $(LOC) +#-Ox generates bad code with MSC 5.1 +LIB_CFLAGS=-Zl $(CFLAGS) + +LD=link +LDFLAGS=/noi/e/st:0x1500/noe/farcall/packcode +# "/farcall/packcode" are only useful for `large code' memory models +# but should be a "no-op" for small code models. + + +# variables +ZLIB_LIB = zlib_$(MODEL).lib + +OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzclose.obj gzlib.obj gzread.obj +OBJ2 = gzwrite.obj infback.obj inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj + + +# targets +all: $(ZLIB_LIB) example.exe minigzip.exe + +.c.obj: + $(CC) -c $(LIB_CFLAGS) $*.c + +adler32.obj: adler32.c zlib.h zconf.h + +compress.obj: compress.c zlib.h zconf.h + +crc32.obj: crc32.c zlib.h zconf.h crc32.h + +deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h + +gzclose.obj: gzclose.c zlib.h zconf.h gzguts.h + +gzlib.obj: gzlib.c zlib.h zconf.h gzguts.h + +gzread.obj: gzread.c zlib.h zconf.h gzguts.h + +gzwrite.obj: gzwrite.c zlib.h zconf.h gzguts.h + +infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ + inffast.h inffixed.h + +inffast.obj: inffast.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ + inffast.h + +inflate.obj: inflate.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ + inffast.h inffixed.h + +inftrees.obj: inftrees.c zutil.h zlib.h zconf.h inftrees.h + +trees.obj: trees.c zutil.h zlib.h zconf.h deflate.h trees.h + +uncompr.obj: uncompr.c zlib.h zconf.h + +zutil.obj: zutil.c zutil.h zlib.h zconf.h + +example.obj: example.c zlib.h zconf.h + $(CC) -c $(CFLAGS) $*.c + +minigzip.obj: minigzip.c zlib.h zconf.h + $(CC) -c $(CFLAGS) $*.c + + +# the command line is cut to fit in the MS-DOS 128 byte limit: +$(ZLIB_LIB): $(OBJ1) $(OBJ2) + if exist $(ZLIB_LIB) del $(ZLIB_LIB) + lib $(ZLIB_LIB) $(OBJ1); + lib $(ZLIB_LIB) $(OBJ2); + +example.exe: example.obj $(ZLIB_LIB) + $(LD) $(LDFLAGS) example.obj,,,$(ZLIB_LIB); + +minigzip.exe: minigzip.obj $(ZLIB_LIB) + $(LD) $(LDFLAGS) minigzip.obj,,,$(ZLIB_LIB); + +test: example.exe minigzip.exe + example + echo hello world | minigzip | minigzip -d + +clean: + -del *.obj + -del *.lib + -del *.exe + -del *.map + -del zlib_*.bak + -del foo.gz diff --git a/libs/zlib/msdos/Makefile.tc b/libs/zlib/msdos/Makefile.tc new file mode 100644 index 000000000..bcd0d1889 --- /dev/null +++ b/libs/zlib/msdos/Makefile.tc @@ -0,0 +1,100 @@ +# Makefile for zlib +# Turbo C 2.01, Turbo C++ 1.01 +# Last updated: 15-Mar-2003 + +# To use, do "make -fmakefile.tc" +# To compile in small model, set below: MODEL=s + +# WARNING: the small model is supported but only for small values of +# MAX_WBITS and MAX_MEM_LEVEL. For example: +# -DMAX_WBITS=11 -DMAX_MEM_LEVEL=3 +# If you wish to reduce the memory requirements (default 256K for big +# objects plus a few K), you can add to CFLAGS below: +# -DMAX_MEM_LEVEL=7 -DMAX_WBITS=14 +# See zconf.h for details about the memory requirements. + +# ------------ Turbo C 2.01, Turbo C++ 1.01 ------------ +MODEL=l +CC=tcc +LD=tcc +AR=tlib +# CFLAGS=-O2 -G -Z -m$(MODEL) -DMAX_WBITS=11 -DMAX_MEM_LEVEL=3 +CFLAGS=-O2 -G -Z -m$(MODEL) +LDFLAGS=-m$(MODEL) -f- + + +# variables +ZLIB_LIB = zlib_$(MODEL).lib + +OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzclose.obj gzlib.obj gzread.obj +OBJ2 = gzwrite.obj infback.obj inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj +OBJP1 = +adler32.obj+compress.obj+crc32.obj+deflate.obj+gzclose.obj+gzlib.obj+gzread.obj +OBJP2 = +gzwrite.obj+infback.obj+inffast.obj+inflate.obj+inftrees.obj+trees.obj+uncompr.obj+zutil.obj + + +# targets +all: $(ZLIB_LIB) example.exe minigzip.exe + +.c.obj: + $(CC) -c $(CFLAGS) $*.c + +adler32.obj: adler32.c zlib.h zconf.h + +compress.obj: compress.c zlib.h zconf.h + +crc32.obj: crc32.c zlib.h zconf.h crc32.h + +deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h + +gzclose.obj: gzclose.c zlib.h zconf.h gzguts.h + +gzlib.obj: gzlib.c zlib.h zconf.h gzguts.h + +gzread.obj: gzread.c zlib.h zconf.h gzguts.h + +gzwrite.obj: gzwrite.c zlib.h zconf.h gzguts.h + +infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ + inffast.h inffixed.h + +inffast.obj: inffast.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ + inffast.h + +inflate.obj: inflate.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ + inffast.h inffixed.h + +inftrees.obj: inftrees.c zutil.h zlib.h zconf.h inftrees.h + +trees.obj: trees.c zutil.h zlib.h zconf.h deflate.h trees.h + +uncompr.obj: uncompr.c zlib.h zconf.h + +zutil.obj: zutil.c zutil.h zlib.h zconf.h + +example.obj: example.c zlib.h zconf.h + +minigzip.obj: minigzip.c zlib.h zconf.h + + +# the command line is cut to fit in the MS-DOS 128 byte limit: +$(ZLIB_LIB): $(OBJ1) $(OBJ2) + -del $(ZLIB_LIB) + $(AR) $(ZLIB_LIB) $(OBJP1) + $(AR) $(ZLIB_LIB) $(OBJP2) + +example.exe: example.obj $(ZLIB_LIB) + $(LD) $(LDFLAGS) example.obj $(ZLIB_LIB) + +minigzip.exe: minigzip.obj $(ZLIB_LIB) + $(LD) $(LDFLAGS) minigzip.obj $(ZLIB_LIB) + +test: example.exe minigzip.exe + example + echo hello world | minigzip | minigzip -d + +clean: + -del *.obj + -del *.lib + -del *.exe + -del zlib_*.bak + -del foo.gz diff --git a/libs/zlib/nintendods/Makefile b/libs/zlib/nintendods/Makefile new file mode 100644 index 000000000..21337d01a --- /dev/null +++ b/libs/zlib/nintendods/Makefile @@ -0,0 +1,126 @@ +#--------------------------------------------------------------------------------- +.SUFFIXES: +#--------------------------------------------------------------------------------- + +ifeq ($(strip $(DEVKITARM)),) +$(error "Please set DEVKITARM in your environment. export DEVKITARM=devkitARM") +endif + +include $(DEVKITARM)/ds_rules + +#--------------------------------------------------------------------------------- +# TARGET is the name of the output +# BUILD is the directory where object files & intermediate files will be placed +# SOURCES is a list of directories containing source code +# DATA is a list of directories containing data files +# INCLUDES is a list of directories containing header files +#--------------------------------------------------------------------------------- +TARGET := $(shell basename $(CURDIR)) +BUILD := build +SOURCES := ../../ +DATA := data +INCLUDES := include + +#--------------------------------------------------------------------------------- +# options for code generation +#--------------------------------------------------------------------------------- +ARCH := -mthumb -mthumb-interwork + +CFLAGS := -Wall -O2\ + -march=armv5te -mtune=arm946e-s \ + -fomit-frame-pointer -ffast-math \ + $(ARCH) + +CFLAGS += $(INCLUDE) -DARM9 +CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions + +ASFLAGS := $(ARCH) -march=armv5te -mtune=arm946e-s +LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) + +#--------------------------------------------------------------------------------- +# list of directories containing libraries, this must be the top level containing +# include and lib +#--------------------------------------------------------------------------------- +LIBDIRS := $(LIBNDS) + +#--------------------------------------------------------------------------------- +# no real need to edit anything past this point unless you need to add additional +# rules for different file extensions +#--------------------------------------------------------------------------------- +ifneq ($(BUILD),$(notdir $(CURDIR))) +#--------------------------------------------------------------------------------- + +export OUTPUT := $(CURDIR)/lib/libz.a + +export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ + $(foreach dir,$(DATA),$(CURDIR)/$(dir)) + +export DEPSDIR := $(CURDIR)/$(BUILD) + +CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) +CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) +SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) +BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) + +#--------------------------------------------------------------------------------- +# use CXX for linking C++ projects, CC for standard C +#--------------------------------------------------------------------------------- +ifeq ($(strip $(CPPFILES)),) +#--------------------------------------------------------------------------------- + export LD := $(CC) +#--------------------------------------------------------------------------------- +else +#--------------------------------------------------------------------------------- + export LD := $(CXX) +#--------------------------------------------------------------------------------- +endif +#--------------------------------------------------------------------------------- + +export OFILES := $(addsuffix .o,$(BINFILES)) \ + $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) + +export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ + -I$(CURDIR)/$(BUILD) + +.PHONY: $(BUILD) clean all + +#--------------------------------------------------------------------------------- +all: $(BUILD) + @[ -d $@ ] || mkdir -p include + @cp ../../*.h include + +lib: + @[ -d $@ ] || mkdir -p $@ + +$(BUILD): lib + @[ -d $@ ] || mkdir -p $@ + @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile + +#--------------------------------------------------------------------------------- +clean: + @echo clean ... + @rm -fr $(BUILD) lib + +#--------------------------------------------------------------------------------- +else + +DEPENDS := $(OFILES:.o=.d) + +#--------------------------------------------------------------------------------- +# main targets +#--------------------------------------------------------------------------------- +$(OUTPUT) : $(OFILES) + +#--------------------------------------------------------------------------------- +%.bin.o : %.bin +#--------------------------------------------------------------------------------- + @echo $(notdir $<) + @$(bin2o) + + +-include $(DEPENDS) + +#--------------------------------------------------------------------------------------- +endif +#--------------------------------------------------------------------------------------- diff --git a/libs/zlib/nintendods/README b/libs/zlib/nintendods/README new file mode 100644 index 000000000..ba7a37dbe --- /dev/null +++ b/libs/zlib/nintendods/README @@ -0,0 +1,5 @@ +This Makefile requires devkitARM (http://www.devkitpro.org/category/devkitarm/) and works inside "contrib/nds". It is based on a devkitARM template. + +Eduardo Costa +January 3, 2009 + diff --git a/libs/zlib/old/Makefile.riscos b/libs/zlib/old/Makefile.riscos new file mode 100644 index 000000000..57e29d3fb --- /dev/null +++ b/libs/zlib/old/Makefile.riscos @@ -0,0 +1,151 @@ +# Project: zlib_1_03 +# Patched for zlib 1.1.2 rw@shadow.org.uk 19980430 +# test works out-of-the-box, installs `somewhere' on demand + +# Toolflags: +CCflags = -c -depend !Depend -IC: -g -throwback -DRISCOS -fah +C++flags = -c -depend !Depend -IC: -throwback +Linkflags = -aif -c++ -o $@ +ObjAsmflags = -throwback -NoCache -depend !Depend +CMHGflags = +LibFileflags = -c -l -o $@ +Squeezeflags = -o $@ + +# change the line below to where _you_ want the library installed. +libdest = lib:zlib + +# Final targets: +@.lib: @.o.adler32 @.o.compress @.o.crc32 @.o.deflate @.o.gzio \ + @.o.infblock @.o.infcodes @.o.inffast @.o.inflate @.o.inftrees @.o.infutil @.o.trees \ + @.o.uncompr @.o.zutil + LibFile $(LibFileflags) @.o.adler32 @.o.compress @.o.crc32 @.o.deflate \ + @.o.gzio @.o.infblock @.o.infcodes @.o.inffast @.o.inflate @.o.inftrees @.o.infutil \ + @.o.trees @.o.uncompr @.o.zutil +test: @.minigzip @.example @.lib + @copy @.lib @.libc A~C~DF~L~N~P~Q~RS~TV + @echo running tests: hang on. + @/@.minigzip -f -9 libc + @/@.minigzip -d libc-gz + @/@.minigzip -f -1 libc + @/@.minigzip -d libc-gz + @/@.minigzip -h -9 libc + @/@.minigzip -d libc-gz + @/@.minigzip -h -1 libc + @/@.minigzip -d libc-gz + @/@.minigzip -9 libc + @/@.minigzip -d libc-gz + @/@.minigzip -1 libc + @/@.minigzip -d libc-gz + @diff @.lib @.libc + @echo that should have reported '@.lib and @.libc identical' if you have diff. + @/@.example @.fred @.fred + @echo that will have given lots of hello!'s. + +@.minigzip: @.o.minigzip @.lib C:o.Stubs + Link $(Linkflags) @.o.minigzip @.lib C:o.Stubs +@.example: @.o.example @.lib C:o.Stubs + Link $(Linkflags) @.o.example @.lib C:o.Stubs + +install: @.lib + cdir $(libdest) + cdir $(libdest).h + @copy @.h.zlib $(libdest).h.zlib A~C~DF~L~N~P~Q~RS~TV + @copy @.h.zconf $(libdest).h.zconf A~C~DF~L~N~P~Q~RS~TV + @copy @.lib $(libdest).lib A~C~DF~L~N~P~Q~RS~TV + @echo okay, installed zlib in $(libdest) + +clean:; remove @.minigzip + remove @.example + remove @.libc + -wipe @.o.* F~r~cV + remove @.fred + +# User-editable dependencies: +.c.o: + cc $(ccflags) -o $@ $< + +# Static dependencies: + +# Dynamic dependencies: +o.example: c.example +o.example: h.zlib +o.example: h.zconf +o.minigzip: c.minigzip +o.minigzip: h.zlib +o.minigzip: h.zconf +o.adler32: c.adler32 +o.adler32: h.zlib +o.adler32: h.zconf +o.compress: c.compress +o.compress: h.zlib +o.compress: h.zconf +o.crc32: c.crc32 +o.crc32: h.zlib +o.crc32: h.zconf +o.deflate: c.deflate +o.deflate: h.deflate +o.deflate: h.zutil +o.deflate: h.zlib +o.deflate: h.zconf +o.gzio: c.gzio +o.gzio: h.zutil +o.gzio: h.zlib +o.gzio: h.zconf +o.infblock: c.infblock +o.infblock: h.zutil +o.infblock: h.zlib +o.infblock: h.zconf +o.infblock: h.infblock +o.infblock: h.inftrees +o.infblock: h.infcodes +o.infblock: h.infutil +o.infcodes: c.infcodes +o.infcodes: h.zutil +o.infcodes: h.zlib +o.infcodes: h.zconf +o.infcodes: h.inftrees +o.infcodes: h.infblock +o.infcodes: h.infcodes +o.infcodes: h.infutil +o.infcodes: h.inffast +o.inffast: c.inffast +o.inffast: h.zutil +o.inffast: h.zlib +o.inffast: h.zconf +o.inffast: h.inftrees +o.inffast: h.infblock +o.inffast: h.infcodes +o.inffast: h.infutil +o.inffast: h.inffast +o.inflate: c.inflate +o.inflate: h.zutil +o.inflate: h.zlib +o.inflate: h.zconf +o.inflate: h.infblock +o.inftrees: c.inftrees +o.inftrees: h.zutil +o.inftrees: h.zlib +o.inftrees: h.zconf +o.inftrees: h.inftrees +o.inftrees: h.inffixed +o.infutil: c.infutil +o.infutil: h.zutil +o.infutil: h.zlib +o.infutil: h.zconf +o.infutil: h.infblock +o.infutil: h.inftrees +o.infutil: h.infcodes +o.infutil: h.infutil +o.trees: c.trees +o.trees: h.deflate +o.trees: h.zutil +o.trees: h.zlib +o.trees: h.zconf +o.trees: h.trees +o.uncompr: c.uncompr +o.uncompr: h.zlib +o.uncompr: h.zconf +o.zutil: c.zutil +o.zutil: h.zutil +o.zutil: h.zlib +o.zutil: h.zconf diff --git a/libs/zlib/old/README b/libs/zlib/old/README new file mode 100644 index 000000000..800bf0798 --- /dev/null +++ b/libs/zlib/old/README @@ -0,0 +1,3 @@ +This directory contains files that have not been updated for zlib 1.2.x + +(Volunteers are encouraged to help clean this up. Thanks.) diff --git a/libs/zlib/old/as400/bndsrc b/libs/zlib/old/as400/bndsrc new file mode 100644 index 000000000..9cf94bb35 --- /dev/null +++ b/libs/zlib/old/as400/bndsrc @@ -0,0 +1,132 @@ +STRPGMEXP PGMLVL(*CURRENT) SIGNATURE('ZLIB') + +/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/ +/* Version 1.1.3 entry points. */ +/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/ + +/********************************************************************/ +/* *MODULE ADLER32 ZLIB 01/02/01 00:15:09 */ +/********************************************************************/ + + EXPORT SYMBOL("adler32") + +/********************************************************************/ +/* *MODULE COMPRESS ZLIB 01/02/01 00:15:09 */ +/********************************************************************/ + + EXPORT SYMBOL("compress") + EXPORT SYMBOL("compress2") + +/********************************************************************/ +/* *MODULE CRC32 ZLIB 01/02/01 00:15:09 */ +/********************************************************************/ + + EXPORT SYMBOL("crc32") + EXPORT SYMBOL("get_crc_table") + +/********************************************************************/ +/* *MODULE DEFLATE ZLIB 01/02/01 00:15:09 */ +/********************************************************************/ + + EXPORT SYMBOL("deflate") + EXPORT SYMBOL("deflateEnd") + EXPORT SYMBOL("deflateSetDictionary") + EXPORT SYMBOL("deflateCopy") + EXPORT SYMBOL("deflateReset") + EXPORT SYMBOL("deflateParams") + EXPORT SYMBOL("deflatePrime") + EXPORT SYMBOL("deflateInit_") + EXPORT SYMBOL("deflateInit2_") + +/********************************************************************/ +/* *MODULE GZIO ZLIB 01/02/01 00:15:09 */ +/********************************************************************/ + + EXPORT SYMBOL("gzopen") + EXPORT SYMBOL("gzdopen") + EXPORT SYMBOL("gzsetparams") + EXPORT SYMBOL("gzread") + EXPORT SYMBOL("gzwrite") + EXPORT SYMBOL("gzprintf") + EXPORT SYMBOL("gzputs") + EXPORT SYMBOL("gzgets") + EXPORT SYMBOL("gzputc") + EXPORT SYMBOL("gzgetc") + EXPORT SYMBOL("gzflush") + EXPORT SYMBOL("gzseek") + EXPORT SYMBOL("gzrewind") + EXPORT SYMBOL("gztell") + EXPORT SYMBOL("gzeof") + EXPORT SYMBOL("gzclose") + EXPORT SYMBOL("gzerror") + +/********************************************************************/ +/* *MODULE INFLATE ZLIB 01/02/01 00:15:09 */ +/********************************************************************/ + + EXPORT SYMBOL("inflate") + EXPORT SYMBOL("inflateEnd") + EXPORT SYMBOL("inflateSetDictionary") + EXPORT SYMBOL("inflateSync") + EXPORT SYMBOL("inflateReset") + EXPORT SYMBOL("inflateInit_") + EXPORT SYMBOL("inflateInit2_") + EXPORT SYMBOL("inflateSyncPoint") + +/********************************************************************/ +/* *MODULE UNCOMPR ZLIB 01/02/01 00:15:09 */ +/********************************************************************/ + + EXPORT SYMBOL("uncompress") + +/********************************************************************/ +/* *MODULE ZUTIL ZLIB 01/02/01 00:15:09 */ +/********************************************************************/ + + EXPORT SYMBOL("zlibVersion") + EXPORT SYMBOL("zError") + +/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/ +/* Version 1.2.1 additional entry points. */ +/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/ + +/********************************************************************/ +/* *MODULE COMPRESS ZLIB 01/02/01 00:15:09 */ +/********************************************************************/ + + EXPORT SYMBOL("compressBound") + +/********************************************************************/ +/* *MODULE DEFLATE ZLIB 01/02/01 00:15:09 */ +/********************************************************************/ + + EXPORT SYMBOL("deflateBound") + +/********************************************************************/ +/* *MODULE GZIO ZLIB 01/02/01 00:15:09 */ +/********************************************************************/ + + EXPORT SYMBOL("gzungetc") + EXPORT SYMBOL("gzclearerr") + +/********************************************************************/ +/* *MODULE INFBACK ZLIB 01/02/01 00:15:09 */ +/********************************************************************/ + + EXPORT SYMBOL("inflateBack") + EXPORT SYMBOL("inflateBackEnd") + EXPORT SYMBOL("inflateBackInit_") + +/********************************************************************/ +/* *MODULE INFLATE ZLIB 01/02/01 00:15:09 */ +/********************************************************************/ + + EXPORT SYMBOL("inflateCopy") + +/********************************************************************/ +/* *MODULE ZUTIL ZLIB 01/02/01 00:15:09 */ +/********************************************************************/ + + EXPORT SYMBOL("zlibCompileFlags") + +ENDPGMEXP diff --git a/libs/zlib/old/as400/compile.clp b/libs/zlib/old/as400/compile.clp new file mode 100644 index 000000000..855495150 --- /dev/null +++ b/libs/zlib/old/as400/compile.clp @@ -0,0 +1,123 @@ +/******************************************************************************/ +/* */ +/* ZLIB */ +/* */ +/* Compile sources into modules and link them into a service program. */ +/* */ +/******************************************************************************/ + + PGM + +/* Configuration adjustable parameters. */ + + DCL VAR(&SRCLIB) TYPE(*CHAR) LEN(10) + + VALUE('ZLIB') /* Source library. */ + DCL VAR(&SRCFILE) TYPE(*CHAR) LEN(10) + + VALUE('SOURCES') /* Source member file. */ + DCL VAR(&CTLFILE) TYPE(*CHAR) LEN(10) + + VALUE('TOOLS') /* Control member file. */ + + DCL VAR(&MODLIB) TYPE(*CHAR) LEN(10) + + VALUE('ZLIB') /* Module library. */ + + DCL VAR(&SRVLIB) TYPE(*CHAR) LEN(10) + + VALUE('LGPL') /* Service program library. */ + + DCL VAR(&CFLAGS) TYPE(*CHAR) + + VALUE('OPTIMIZE(40)') /* Compile options. */ + + +/* Working storage. */ + + DCL VAR(&CMDLEN) TYPE(*DEC) LEN(15 5) VALUE(300) /* Command length. */ + DCL VAR(&CMD) TYPE(*CHAR) LEN(512) + + +/* Compile sources into modules. */ + + CHGVAR VAR(&CMD) VALUE('CRTCMOD MODULE(' *TCAT &MODLIB *TCAT + + '/ADLER32) SRCFILE(' *TCAT + + &SRCLIB *TCAT '/' *TCAT &SRCFILE *TCAT + + ') SYSIFCOPT(*IFSIO)' *BCAT &CFLAGS) + CALL PGM(QCMDEXC) PARM(&CMD &CMDLEN) + + CHGVAR VAR(&CMD) VALUE('CRTCMOD MODULE(' *TCAT &MODLIB *TCAT + + '/COMPRESS) SRCFILE(' *TCAT + + &SRCLIB *TCAT '/' *TCAT &SRCFILE *TCAT + + ') SYSIFCOPT(*IFSIO)' *BCAT &CFLAGS) + CALL PGM(QCMDEXC) PARM(&CMD &CMDLEN) + + CHGVAR VAR(&CMD) VALUE('CRTCMOD MODULE(' *TCAT &MODLIB *TCAT + + '/CRC32) SRCFILE(' *TCAT + + &SRCLIB *TCAT '/' *TCAT &SRCFILE *TCAT + + ') SYSIFCOPT(*IFSIO)' *BCAT &CFLAGS) + CALL PGM(QCMDEXC) PARM(&CMD &CMDLEN) + + CHGVAR VAR(&CMD) VALUE('CRTCMOD MODULE(' *TCAT &MODLIB *TCAT + + '/DEFLATE) SRCFILE(' *TCAT + + &SRCLIB *TCAT '/' *TCAT &SRCFILE *TCAT + + ') SYSIFCOPT(*IFSIO)' *BCAT &CFLAGS) + CALL PGM(QCMDEXC) PARM(&CMD &CMDLEN) + + CHGVAR VAR(&CMD) VALUE('CRTCMOD MODULE(' *TCAT &MODLIB *TCAT + + '/GZIO) SRCFILE(' *TCAT + + &SRCLIB *TCAT '/' *TCAT &SRCFILE *TCAT + + ') SYSIFCOPT(*IFSIO)' *BCAT &CFLAGS) + CALL PGM(QCMDEXC) PARM(&CMD &CMDLEN) + + CHGVAR VAR(&CMD) VALUE('CRTCMOD MODULE(' *TCAT &MODLIB *TCAT + + '/INFBACK) SRCFILE(' *TCAT + + &SRCLIB *TCAT '/' *TCAT &SRCFILE *TCAT + + ') SYSIFCOPT(*IFSIO)' *BCAT &CFLAGS) + CALL PGM(QCMDEXC) PARM(&CMD &CMDLEN) + + CHGVAR VAR(&CMD) VALUE('CRTCMOD MODULE(' *TCAT &MODLIB *TCAT + + '/INFFAST) SRCFILE(' *TCAT + + &SRCLIB *TCAT '/' *TCAT &SRCFILE *TCAT + + ') SYSIFCOPT(*IFSIO)' *BCAT &CFLAGS) + CALL PGM(QCMDEXC) PARM(&CMD &CMDLEN) + + CHGVAR VAR(&CMD) VALUE('CRTCMOD MODULE(' *TCAT &MODLIB *TCAT + + '/INFLATE) SRCFILE(' *TCAT + + &SRCLIB *TCAT '/' *TCAT &SRCFILE *TCAT + + ') SYSIFCOPT(*IFSIO)' *BCAT &CFLAGS) + CALL PGM(QCMDEXC) PARM(&CMD &CMDLEN) + + CHGVAR VAR(&CMD) VALUE('CRTCMOD MODULE(' *TCAT &MODLIB *TCAT + + '/INFTREES) SRCFILE(' *TCAT + + &SRCLIB *TCAT '/' *TCAT &SRCFILE *TCAT + + ') SYSIFCOPT(*IFSIO)' *BCAT &CFLAGS) + CALL PGM(QCMDEXC) PARM(&CMD &CMDLEN) + + CHGVAR VAR(&CMD) VALUE('CRTCMOD MODULE(' *TCAT &MODLIB *TCAT + + '/TREES) SRCFILE(' *TCAT + + &SRCLIB *TCAT '/' *TCAT &SRCFILE *TCAT + + ') SYSIFCOPT(*IFSIO)' *BCAT &CFLAGS) + CALL PGM(QCMDEXC) PARM(&CMD &CMDLEN) + + CHGVAR VAR(&CMD) VALUE('CRTCMOD MODULE(' *TCAT &MODLIB *TCAT + + '/UNCOMPR) SRCFILE(' *TCAT + + &SRCLIB *TCAT '/' *TCAT &SRCFILE *TCAT + + ') SYSIFCOPT(*IFSIO)' *BCAT &CFLAGS) + CALL PGM(QCMDEXC) PARM(&CMD &CMDLEN) + + CHGVAR VAR(&CMD) VALUE('CRTCMOD MODULE(' *TCAT &MODLIB *TCAT + + '/ZUTIL) SRCFILE(' *TCAT + + &SRCLIB *TCAT '/' *TCAT &SRCFILE *TCAT + + ') SYSIFCOPT(*IFSIO)' *BCAT &CFLAGS) + CALL PGM(QCMDEXC) PARM(&CMD &CMDLEN) + + +/* Link modules into a service program. */ + + CRTSRVPGM SRVPGM(&SRVLIB/ZLIB) + + MODULE(&MODLIB/ADLER32 &MODLIB/COMPRESS + + &MODLIB/CRC32 &MODLIB/DEFLATE + + &MODLIB/GZIO &MODLIB/INFBACK + + &MODLIB/INFFAST &MODLIB/INFLATE + + &MODLIB/INFTREES &MODLIB/TREES + + &MODLIB/UNCOMPR &MODLIB/ZUTIL) + + SRCFILE(&SRCLIB/&CTLFILE) SRCMBR(BNDSRC) + + TEXT('ZLIB 1.2.3') TGTRLS(V4R4M0) + + ENDPGM diff --git a/libs/zlib/old/as400/readme.txt b/libs/zlib/old/as400/readme.txt new file mode 100644 index 000000000..beae13f56 --- /dev/null +++ b/libs/zlib/old/as400/readme.txt @@ -0,0 +1,111 @@ + ZLIB version 1.2.3 for AS400 installation instructions + +I) From an AS400 *SAVF file: + +1) Unpacking archive to an AS400 save file + +On the AS400: + +_ Create the ZLIB AS400 library: + + CRTLIB LIB(ZLIB) TYPE(PROD) TEXT('ZLIB compression API library') + +_ Create a work save file, for example: + + CRTSAVF FILE(ZLIB/ZLIBSAVF) + +On a PC connected to the target AS400: + +_ Unpack the save file image to a PC file "ZLIBSAVF" +_ Upload this file into the save file on the AS400, for example + using ftp in BINARY mode. + + +2) Populating the ZLIB AS400 source library + +On the AS400: + +_ Extract the saved objects into the ZLIB AS400 library using: + +RSTOBJ OBJ(*ALL) SAVLIB(ZLIB) DEV(*SAVF) SAVF(ZLIB/ZLIBSAVF) RSTLIB(ZLIB) + + +3) Customize installation: + +_ Edit CL member ZLIB/TOOLS(COMPILE) and change parameters if needed, + according to the comments. + +_ Compile this member with: + + CRTCLPGM PGM(ZLIB/COMPILE) SRCFILE(ZLIB/TOOLS) SRCMBR(COMPILE) + + +4) Compile and generate the service program: + +_ This can now be done by executing: + + CALL PGM(ZLIB/COMPILE) + + + +II) From the original source distribution: + +1) On the AS400, create the source library: + + CRTLIB LIB(ZLIB) TYPE(PROD) TEXT('ZLIB compression API library') + +2) Create the source files: + + CRTSRCPF FILE(ZLIB/SOURCES) RCDLEN(112) TEXT('ZLIB library modules') + CRTSRCPF FILE(ZLIB/H) RCDLEN(112) TEXT('ZLIB library includes') + CRTSRCPF FILE(ZLIB/TOOLS) RCDLEN(112) TEXT('ZLIB library control utilities') + +3) From the machine hosting the distribution files, upload them (with + FTP in text mode, for example) according to the following table: + + Original AS400 AS400 AS400 AS400 + file file member type description + SOURCES Original ZLIB C subprogram sources + adler32.c ADLER32 C ZLIB - Compute the Adler-32 checksum of a dta strm + compress.c COMPRESS C ZLIB - Compress a memory buffer + crc32.c CRC32 C ZLIB - Compute the CRC-32 of a data stream + deflate.c DEFLATE C ZLIB - Compress data using the deflation algorithm + gzio.c GZIO C ZLIB - IO on .gz files + infback.c INFBACK C ZLIB - Inflate using a callback interface + inffast.c INFFAST C ZLIB - Fast proc. literals & length/distance pairs + inflate.c INFLATE C ZLIB - Interface to inflate modules + inftrees.c INFTREES C ZLIB - Generate Huffman trees for efficient decode + trees.c TREES C ZLIB - Output deflated data using Huffman coding + uncompr.c UNCOMPR C ZLIB - Decompress a memory buffer + zutil.c ZUTIL C ZLIB - Target dependent utility functions + H Original ZLIB C and ILE/RPG include files + crc32.h CRC32 C ZLIB - CRC32 tables + deflate.h DEFLATE C ZLIB - Internal compression state + inffast.h INFFAST C ZLIB - Header to use inffast.c + inffixed.h INFFIXED C ZLIB - Table for decoding fixed codes + inflate.h INFLATE C ZLIB - Internal inflate state definitions + inftrees.h INFTREES C ZLIB - Header to use inftrees.c + trees.h TREES C ZLIB - Created automatically with -DGEN_TREES_H + zconf.h ZCONF C ZLIB - Compression library configuration + zlib.h ZLIB C ZLIB - Compression library C user interface + as400/zlib.inc ZLIB.INC RPGLE ZLIB - Compression library ILE RPG user interface + zutil.h ZUTIL C ZLIB - Internal interface and configuration + TOOLS Building source software & AS/400 README + as400/bndsrc BNDSRC Entry point exportation list + as400/compile.clp COMPILE CLP Compile sources & generate service program + as400/readme.txt README TXT Installation instructions + +4) Continue as in I)3). + + + + +Notes: For AS400 ILE RPG programmers, a /copy member defining the ZLIB + API prototypes for ILE RPG can be found in ZLIB/H(ZLIB.INC). + Please read comments in this member for more information. + + Remember that most foreign textual data are ASCII coded: this + implementation does not handle conversion from/to ASCII, so + text data code conversions must be done explicitely. + + Always open zipped files in binary mode. diff --git a/libs/zlib/old/as400/zlib.inc b/libs/zlib/old/as400/zlib.inc new file mode 100644 index 000000000..a9a4f5cf4 --- /dev/null +++ b/libs/zlib/old/as400/zlib.inc @@ -0,0 +1,331 @@ + * ZLIB.INC - Interface to the general purpose compression library + * + * ILE RPG400 version by Patrick Monnerat, DATASPHERE. + * Version 1.2.3.9 + * + * + * WARNING: + * Procedures inflateInit(), inflateInit2(), deflateInit(), + * deflateInit2() and inflateBackInit() need to be called with + * two additional arguments: + * the package version string and the stream control structure. + * size. This is needed because RPG lacks some macro feature. + * Call these procedures as: + * inflateInit(...: ZLIB_VERSION: %size(z_stream)) + * + /if not defined(ZLIB_H_) + /define ZLIB_H_ + * + ************************************************************************** + * Constants + ************************************************************************** + * + * Versioning information. + * + D ZLIB_VERSION C '1.2.3.9' + D ZLIB_VERNUM C X'1239' + * + * Other equates. + * + D Z_NO_FLUSH C 0 + D Z_SYNC_FLUSH C 2 + D Z_FULL_FLUSH C 3 + D Z_FINISH C 4 + D Z_BLOCK C 5 + * + D Z_OK C 0 + D Z_STREAM_END C 1 + D Z_NEED_DICT C 2 + D Z_ERRNO C -1 + D Z_STREAM_ERROR C -2 + D Z_DATA_ERROR C -3 + D Z_MEM_ERROR C -4 + D Z_BUF_ERROR C -5 + DZ_VERSION_ERROR C -6 + * + D Z_NO_COMPRESSION... + D C 0 + D Z_BEST_SPEED C 1 + D Z_BEST_COMPRESSION... + D C 9 + D Z_DEFAULT_COMPRESSION... + D C -1 + * + D Z_FILTERED C 1 + D Z_HUFFMAN_ONLY C 2 + D Z_RLE C 3 + D Z_DEFAULT_STRATEGY... + D C 0 + * + D Z_BINARY C 0 + D Z_ASCII C 1 + D Z_UNKNOWN C 2 + * + D Z_DEFLATED C 8 + * + D Z_NULL C 0 + * + ************************************************************************** + * Types + ************************************************************************** + * + D z_streamp S * Stream struct ptr + D gzFile S * File pointer + D z_off_t S 10i 0 Stream offsets + * + ************************************************************************** + * Structures + ************************************************************************** + * + * The GZIP encode/decode stream support structure. + * + D z_stream DS align based(z_streamp) + D zs_next_in * Next input byte + D zs_avail_in 10U 0 Byte cnt at next_in + D zs_total_in 10U 0 Total bytes read + D zs_next_out * Output buffer ptr + D zs_avail_out 10U 0 Room left @ next_out + D zs_total_out 10U 0 Total bytes written + D zs_msg * Last errmsg or null + D zs_state * Internal state + D zs_zalloc * procptr Int. state allocator + D zs_free * procptr Int. state dealloc. + D zs_opaque * Private alloc. data + D zs_data_type 10i 0 ASC/BIN best guess + D zs_adler 10u 0 Uncompr. adler32 val + D 10U 0 Reserved + D 10U 0 Ptr. alignment + * + ************************************************************************** + * Utility function prototypes + ************************************************************************** + * + D compress PR 10I 0 extproc('compress') + D dest 32767 options(*varsize) Destination buffer + D destLen 10U 0 Destination length + D source 32767 const options(*varsize) Source buffer + D sourceLen 10u 0 value Source length + * + D compress2 PR 10I 0 extproc('compress2') + D dest 32767 options(*varsize) Destination buffer + D destLen 10U 0 Destination length + D source 32767 const options(*varsize) Source buffer + D sourceLen 10U 0 value Source length + D level 10I 0 value Compression level + * + D compressBound PR 10U 0 extproc('compressBound') + D sourceLen 10U 0 value + * + D uncompress PR 10I 0 extproc('uncompress') + D dest 32767 options(*varsize) Destination buffer + D destLen 10U 0 Destination length + D source 32767 const options(*varsize) Source buffer + D sourceLen 10U 0 value Source length + * + D gzopen PR extproc('gzopen') + D like(gzFile) + D path * value options(*string) File pathname + D mode * value options(*string) Open mode + * + D gzdopen PR extproc('gzdopen') + D like(gzFile) + D fd 10i 0 value File descriptor + D mode * value options(*string) Open mode + * + D gzsetparams PR 10I 0 extproc('gzsetparams') + D file value like(gzFile) File pointer + D level 10I 0 value + D strategy 10i 0 value + * + D gzread PR 10I 0 extproc('gzread') + D file value like(gzFile) File pointer + D buf 32767 options(*varsize) Buffer + D len 10u 0 value Buffer length + * + D gzwrite PR 10I 0 extproc('gzwrite') + D file value like(gzFile) File pointer + D buf 32767 const options(*varsize) Buffer + D len 10u 0 value Buffer length + * + D gzputs PR 10I 0 extproc('gzputs') + D file value like(gzFile) File pointer + D s * value options(*string) String to output + * + D gzgets PR * extproc('gzgets') + D file value like(gzFile) File pointer + D buf 32767 options(*varsize) Read buffer + D len 10i 0 value Buffer length + * + D gzflush PR 10i 0 extproc('gzflush') + D file value like(gzFile) File pointer + D flush 10I 0 value Type of flush + * + D gzseek PR extproc('gzseek') + D like(z_off_t) + D file value like(gzFile) File pointer + D offset value like(z_off_t) Offset + D whence 10i 0 value Origin + * + D gzrewind PR 10i 0 extproc('gzrewind') + D file value like(gzFile) File pointer + * + D gztell PR extproc('gztell') + D like(z_off_t) + D file value like(gzFile) File pointer + * + D gzeof PR 10i 0 extproc('gzeof') + D file value like(gzFile) File pointer + * + D gzclose PR 10i 0 extproc('gzclose') + D file value like(gzFile) File pointer + * + D gzerror PR * extproc('gzerror') Error string + D file value like(gzFile) File pointer + D errnum 10I 0 Error code + * + D gzclearerr PR extproc('gzclearerr') + D file value like(gzFile) File pointer + * + ************************************************************************** + * Basic function prototypes + ************************************************************************** + * + D zlibVersion PR * extproc('zlibVersion') Version string + * + D deflateInit PR 10I 0 extproc('deflateInit_') Init. compression + D strm like(z_stream) Compression stream + D level 10I 0 value Compression level + D version * value options(*string) Version string + D stream_size 10i 0 value Stream struct. size + * + D deflate PR 10I 0 extproc('deflate') Compress data + D strm like(z_stream) Compression stream + D flush 10I 0 value Flush type required + * + D deflateEnd PR 10I 0 extproc('deflateEnd') Termin. compression + D strm like(z_stream) Compression stream + * + D inflateInit PR 10I 0 extproc('inflateInit_') Init. expansion + D strm like(z_stream) Expansion stream + D version * value options(*string) Version string + D stream_size 10i 0 value Stream struct. size + * + D inflate PR 10I 0 extproc('inflate') Expand data + D strm like(z_stream) Expansion stream + D flush 10I 0 value Flush type required + * + D inflateEnd PR 10I 0 extproc('inflateEnd') Termin. expansion + D strm like(z_stream) Expansion stream + * + ************************************************************************** + * Advanced function prototypes + ************************************************************************** + * + D deflateInit2 PR 10I 0 extproc('deflateInit2_') Init. compression + D strm like(z_stream) Compression stream + D level 10I 0 value Compression level + D method 10I 0 value Compression method + D windowBits 10I 0 value log2(window size) + D memLevel 10I 0 value Mem/cmpress tradeoff + D strategy 10I 0 value Compression stategy + D version * value options(*string) Version string + D stream_size 10i 0 value Stream struct. size + * + D deflateSetDictionary... + D PR 10I 0 extproc('deflateSetDictionary') Init. dictionary + D strm like(z_stream) Compression stream + D dictionary 32767 const options(*varsize) Dictionary bytes + D dictLength 10U 0 value Dictionary length + * + D deflateCopy PR 10I 0 extproc('deflateCopy') Compress strm 2 strm + D dest like(z_stream) Destination stream + D source like(z_stream) Source stream + * + D deflateReset PR 10I 0 extproc('deflateReset') End and init. stream + D strm like(z_stream) Compression stream + * + D deflateParams PR 10I 0 extproc('deflateParams') Change level & strat + D strm like(z_stream) Compression stream + D level 10I 0 value Compression level + D strategy 10I 0 value Compression stategy + * + D deflateBound PR 10U 0 extproc('deflateBound') Change level & strat + D strm like(z_stream) Compression stream + D sourcelen 10U 0 value Compression level + * + D deflatePrime PR 10I 0 extproc('deflatePrime') Change level & strat + D strm like(z_stream) Compression stream + D bits 10I 0 value Number of bits to insert + D value 10I 0 value Bits to insert + * + D inflateInit2 PR 10I 0 extproc('inflateInit2_') Init. expansion + D strm like(z_stream) Expansion stream + D windowBits 10I 0 value log2(window size) + D version * value options(*string) Version string + D stream_size 10i 0 value Stream struct. size + * + D inflateSetDictionary... + D PR 10I 0 extproc('inflateSetDictionary') Init. dictionary + D strm like(z_stream) Expansion stream + D dictionary 32767 const options(*varsize) Dictionary bytes + D dictLength 10U 0 value Dictionary length + * + D inflateSync PR 10I 0 extproc('inflateSync') Sync. expansion + D strm like(z_stream) Expansion stream + * + D inflateCopy PR 10I 0 extproc('inflateCopy') + D dest like(z_stream) Destination stream + D source like(z_stream) Source stream + * + D inflateReset PR 10I 0 extproc('inflateReset') End and init. stream + D strm like(z_stream) Expansion stream + * + D inflateBackInit... + D PR 10I 0 extproc('inflateBackInit_') + D strm like(z_stream) Expansion stream + D windowBits 10I 0 value Log2(buffer size) + D window 32767 options(*varsize) Buffer + D version * value options(*string) Version string + D stream_size 10i 0 value Stream struct. size + * + D inflateBack PR 10I 0 extproc('inflateBack') + D strm like(z_stream) Expansion stream + D in * value procptr Input function + D in_desc * value Input descriptor + D out * value procptr Output function + D out_desc * value Output descriptor + * + D inflateBackEnd PR 10I 0 extproc('inflateBackEnd') + D strm like(z_stream) Expansion stream + * + D zlibCompileFlags... + D PR 10U 0 extproc('zlibCompileFlags') + * + ************************************************************************** + * Checksum function prototypes + ************************************************************************** + * + D adler32 PR 10U 0 extproc('adler32') New checksum + D adler 10U 0 value Old checksum + D buf 32767 const options(*varsize) Bytes to accumulate + D len 10U 0 value Buffer length + * + D crc32 PR 10U 0 extproc('crc32') New checksum + D crc 10U 0 value Old checksum + D buf 32767 const options(*varsize) Bytes to accumulate + D len 10U 0 value Buffer length + * + ************************************************************************** + * Miscellaneous function prototypes + ************************************************************************** + * + D zError PR * extproc('zError') Error string + D err 10I 0 value Error code + * + D inflateSyncPoint... + D PR 10I 0 extproc('inflateSyncPoint') + D strm like(z_stream) Expansion stream + * + D get_crc_table PR * extproc('get_crc_table') Ptr to ulongs + * + /endif diff --git a/libs/zlib/old/descrip.mms b/libs/zlib/old/descrip.mms new file mode 100644 index 000000000..7066da5b5 --- /dev/null +++ b/libs/zlib/old/descrip.mms @@ -0,0 +1,48 @@ +# descrip.mms: MMS description file for building zlib on VMS +# written by Martin P.J. Zinser + +cc_defs = +c_deb = + +.ifdef __DECC__ +pref = /prefix=all +.endif + +OBJS = adler32.obj, compress.obj, crc32.obj, gzio.obj, uncompr.obj,\ + deflate.obj, trees.obj, zutil.obj, inflate.obj, infblock.obj,\ + inftrees.obj, infcodes.obj, infutil.obj, inffast.obj + +CFLAGS= $(C_DEB) $(CC_DEFS) $(PREF) + +all : example.exe minigzip.exe + @ write sys$output " Example applications available" +libz.olb : libz.olb($(OBJS)) + @ write sys$output " libz available" + +example.exe : example.obj libz.olb + link example,libz.olb/lib + +minigzip.exe : minigzip.obj libz.olb + link minigzip,libz.olb/lib,x11vms:xvmsutils.olb/lib + +clean : + delete *.obj;*,libz.olb;* + + +# Other dependencies. +adler32.obj : zutil.h zlib.h zconf.h +compress.obj : zlib.h zconf.h +crc32.obj : zutil.h zlib.h zconf.h +deflate.obj : deflate.h zutil.h zlib.h zconf.h +example.obj : zlib.h zconf.h +gzio.obj : zutil.h zlib.h zconf.h +infblock.obj : zutil.h zlib.h zconf.h infblock.h inftrees.h infcodes.h infutil.h +infcodes.obj : zutil.h zlib.h zconf.h inftrees.h infutil.h infcodes.h inffast.h +inffast.obj : zutil.h zlib.h zconf.h inftrees.h infutil.h inffast.h +inflate.obj : zutil.h zlib.h zconf.h infblock.h +inftrees.obj : zutil.h zlib.h zconf.h inftrees.h +infutil.obj : zutil.h zlib.h zconf.h inftrees.h infutil.h +minigzip.obj : zlib.h zconf.h +trees.obj : deflate.h zutil.h zlib.h zconf.h +uncompr.obj : zlib.h zconf.h +zutil.obj : zutil.h zlib.h zconf.h diff --git a/libs/zlib/old/os2/Makefile.os2 b/libs/zlib/old/os2/Makefile.os2 new file mode 100644 index 000000000..a105aaa5b --- /dev/null +++ b/libs/zlib/old/os2/Makefile.os2 @@ -0,0 +1,136 @@ +# Makefile for zlib under OS/2 using GCC (PGCC) +# For conditions of distribution and use, see copyright notice in zlib.h + +# To compile and test, type: +# cp Makefile.os2 .. +# cd .. +# make -f Makefile.os2 test + +# This makefile will build a static library z.lib, a shared library +# z.dll and a import library zdll.lib. You can use either z.lib or +# zdll.lib by specifying either -lz or -lzdll on gcc's command line + +CC=gcc -Zomf -s + +CFLAGS=-O6 -Wall +#CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7 +#CFLAGS=-g -DDEBUG +#CFLAGS=-O3 -Wall -Wwrite-strings -Wpointer-arith -Wconversion \ +# -Wstrict-prototypes -Wmissing-prototypes + +#################### BUG WARNING: ##################### +## infcodes.c hits a bug in pgcc-1.0, so you have to use either +## -O# where # <= 4 or one of (-fno-ommit-frame-pointer or -fno-force-mem) +## This bug is reportedly fixed in pgcc >1.0, but this was not tested +CFLAGS+=-fno-force-mem + +LDFLAGS=-s -L. -lzdll -Zcrtdll +LDSHARED=$(CC) -s -Zomf -Zdll -Zcrtdll + +VER=1.1.0 +ZLIB=z.lib +SHAREDLIB=z.dll +SHAREDLIBIMP=zdll.lib +LIBS=$(ZLIB) $(SHAREDLIB) $(SHAREDLIBIMP) + +AR=emxomfar cr +IMPLIB=emximp +RANLIB=echo +TAR=tar +SHELL=bash + +prefix=/usr/local +exec_prefix = $(prefix) + +OBJS = adler32.o compress.o crc32.o gzio.o uncompr.o deflate.o trees.o \ + zutil.o inflate.o infblock.o inftrees.o infcodes.o infutil.o inffast.o + +TEST_OBJS = example.o minigzip.o + +DISTFILES = README INDEX ChangeLog configure Make*[a-z0-9] *.[ch] descrip.mms \ + algorithm.txt zlib.3 msdos/Make*[a-z0-9] msdos/zlib.def msdos/zlib.rc \ + nt/Makefile.nt nt/zlib.dnt contrib/README.contrib contrib/*.txt \ + contrib/asm386/*.asm contrib/asm386/*.c \ + contrib/asm386/*.bat contrib/asm386/zlibvc.d?? contrib/iostream/*.cpp \ + contrib/iostream/*.h contrib/iostream2/*.h contrib/iostream2/*.cpp \ + contrib/untgz/Makefile contrib/untgz/*.c contrib/untgz/*.w32 + +all: example.exe minigzip.exe + +test: all + @LD_LIBRARY_PATH=.:$(LD_LIBRARY_PATH) ; export LD_LIBRARY_PATH; \ + echo hello world | ./minigzip | ./minigzip -d || \ + echo ' *** minigzip test FAILED ***' ; \ + if ./example; then \ + echo ' *** zlib test OK ***'; \ + else \ + echo ' *** zlib test FAILED ***'; \ + fi + +$(ZLIB): $(OBJS) + $(AR) $@ $(OBJS) + -@ ($(RANLIB) $@ || true) >/dev/null 2>&1 + +$(SHAREDLIB): $(OBJS) os2/z.def + $(LDSHARED) -o $@ $^ + +$(SHAREDLIBIMP): os2/z.def + $(IMPLIB) -o $@ $^ + +example.exe: example.o $(LIBS) + $(CC) $(CFLAGS) -o $@ example.o $(LDFLAGS) + +minigzip.exe: minigzip.o $(LIBS) + $(CC) $(CFLAGS) -o $@ minigzip.o $(LDFLAGS) + +clean: + rm -f *.o *~ example minigzip libz.a libz.so* foo.gz + +distclean: clean + +zip: + mv Makefile Makefile~; cp -p Makefile.in Makefile + rm -f test.c ztest*.c + v=`sed -n -e 's/\.//g' -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h`;\ + zip -ul9 zlib$$v $(DISTFILES) + mv Makefile~ Makefile + +dist: + mv Makefile Makefile~; cp -p Makefile.in Makefile + rm -f test.c ztest*.c + d=zlib-`sed -n '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h`;\ + rm -f $$d.tar.gz; \ + if test ! -d ../$$d; then rm -f ../$$d; ln -s `pwd` ../$$d; fi; \ + files=""; \ + for f in $(DISTFILES); do files="$$files $$d/$$f"; done; \ + cd ..; \ + GZIP=-9 $(TAR) chofz $$d/$$d.tar.gz $$files; \ + if test ! -d $$d; then rm -f $$d; fi + mv Makefile~ Makefile + +tags: + etags *.[ch] + +depend: + makedepend -- $(CFLAGS) -- *.[ch] + +# DO NOT DELETE THIS LINE -- make depend depends on it. + +adler32.o: zlib.h zconf.h +compress.o: zlib.h zconf.h +crc32.o: zlib.h zconf.h +deflate.o: deflate.h zutil.h zlib.h zconf.h +example.o: zlib.h zconf.h +gzio.o: zutil.h zlib.h zconf.h +infblock.o: infblock.h inftrees.h infcodes.h infutil.h zutil.h zlib.h zconf.h +infcodes.o: zutil.h zlib.h zconf.h +infcodes.o: inftrees.h infblock.h infcodes.h infutil.h inffast.h +inffast.o: zutil.h zlib.h zconf.h inftrees.h +inffast.o: infblock.h infcodes.h infutil.h inffast.h +inflate.o: zutil.h zlib.h zconf.h infblock.h +inftrees.o: zutil.h zlib.h zconf.h inftrees.h +infutil.o: zutil.h zlib.h zconf.h infblock.h inftrees.h infcodes.h infutil.h +minigzip.o: zlib.h zconf.h +trees.o: deflate.h zutil.h zlib.h zconf.h trees.h +uncompr.o: zlib.h zconf.h +zutil.o: zutil.h zlib.h zconf.h diff --git a/libs/zlib/old/os2/zlib.def b/libs/zlib/old/os2/zlib.def new file mode 100644 index 000000000..4c753f1a3 --- /dev/null +++ b/libs/zlib/old/os2/zlib.def @@ -0,0 +1,51 @@ +; +; Slightly modified version of ../nt/zlib.dnt :-) +; + +LIBRARY Z +DESCRIPTION "Zlib compression library for OS/2" +CODE PRELOAD MOVEABLE DISCARDABLE +DATA PRELOAD MOVEABLE MULTIPLE + +EXPORTS + adler32 + compress + crc32 + deflate + deflateCopy + deflateEnd + deflateInit2_ + deflateInit_ + deflateParams + deflateReset + deflateSetDictionary + gzclose + gzdopen + gzerror + gzflush + gzopen + gzread + gzwrite + inflate + inflateEnd + inflateInit2_ + inflateInit_ + inflateReset + inflateSetDictionary + inflateSync + uncompress + zlibVersion + gzprintf + gzputc + gzgetc + gzseek + gzrewind + gztell + gzeof + gzsetparams + zError + inflateSyncPoint + get_crc_table + compress2 + gzputs + gzgets diff --git a/libs/zlib/old/visual-basic.txt b/libs/zlib/old/visual-basic.txt new file mode 100644 index 000000000..57efe5812 --- /dev/null +++ b/libs/zlib/old/visual-basic.txt @@ -0,0 +1,160 @@ +See below some functions declarations for Visual Basic. + +Frequently Asked Question: + +Q: Each time I use the compress function I get the -5 error (not enough + room in the output buffer). + +A: Make sure that the length of the compressed buffer is passed by + reference ("as any"), not by value ("as long"). Also check that + before the call of compress this length is equal to the total size of + the compressed buffer and not zero. + + +From: "Jon Caruana" +Subject: Re: How to port zlib declares to vb? +Date: Mon, 28 Oct 1996 18:33:03 -0600 + +Got the answer! (I haven't had time to check this but it's what I got, and +looks correct): + +He has the following routines working: + compress + uncompress + gzopen + gzwrite + gzread + gzclose + +Declares follow: (Quoted from Carlos Rios , in Vb4 form) + +#If Win16 Then 'Use Win16 calls. +Declare Function compress Lib "ZLIB.DLL" (ByVal compr As + String, comprLen As Any, ByVal buf As String, ByVal buflen + As Long) As Integer +Declare Function uncompress Lib "ZLIB.DLL" (ByVal uncompr + As String, uncomprLen As Any, ByVal compr As String, ByVal + lcompr As Long) As Integer +Declare Function gzopen Lib "ZLIB.DLL" (ByVal filePath As + String, ByVal mode As String) As Long +Declare Function gzread Lib "ZLIB.DLL" (ByVal file As + Long, ByVal uncompr As String, ByVal uncomprLen As Integer) + As Integer +Declare Function gzwrite Lib "ZLIB.DLL" (ByVal file As + Long, ByVal uncompr As String, ByVal uncomprLen As Integer) + As Integer +Declare Function gzclose Lib "ZLIB.DLL" (ByVal file As + Long) As Integer +#Else +Declare Function compress Lib "ZLIB32.DLL" + (ByVal compr As String, comprLen As Any, ByVal buf As + String, ByVal buflen As Long) As Integer +Declare Function uncompress Lib "ZLIB32.DLL" + (ByVal uncompr As String, uncomprLen As Any, ByVal compr As + String, ByVal lcompr As Long) As Long +Declare Function gzopen Lib "ZLIB32.DLL" + (ByVal file As String, ByVal mode As String) As Long +Declare Function gzread Lib "ZLIB32.DLL" + (ByVal file As Long, ByVal uncompr As String, ByVal + uncomprLen As Long) As Long +Declare Function gzwrite Lib "ZLIB32.DLL" + (ByVal file As Long, ByVal uncompr As String, ByVal + uncomprLen As Long) As Long +Declare Function gzclose Lib "ZLIB32.DLL" + (ByVal file As Long) As Long +#End If + +-Jon Caruana +jon-net@usa.net +Microsoft Sitebuilder Network Level 1 Member - HTML Writer's Guild Member + + +Here is another example from Michael that he +says conforms to the VB guidelines, and that solves the problem of not +knowing the uncompressed size by storing it at the end of the file: + +'Calling the functions: +'bracket meaning: [optional] {Range of possible values} +'Call subCompressFile( [, , [level of compression {1..9}]]) +'Call subUncompressFile() + +Option Explicit +Private lngpvtPcnSml As Long 'Stores value for 'lngPercentSmaller' +Private Const SUCCESS As Long = 0 +Private Const strFilExt As String = ".cpr" +Private Declare Function lngfncCpr Lib "zlib.dll" Alias "compress2" (ByRef +dest As Any, ByRef destLen As Any, ByRef src As Any, ByVal srcLen As Long, +ByVal level As Integer) As Long +Private Declare Function lngfncUcp Lib "zlib.dll" Alias "uncompress" (ByRef +dest As Any, ByRef destLen As Any, ByRef src As Any, ByVal srcLen As Long) +As Long + +Public Sub subCompressFile(ByVal strargOriFilPth As String, Optional ByVal +strargCprFilPth As String, Optional ByVal intLvl As Integer = 9) + Dim strCprPth As String + Dim lngOriSiz As Long + Dim lngCprSiz As Long + Dim bytaryOri() As Byte + Dim bytaryCpr() As Byte + lngOriSiz = FileLen(strargOriFilPth) + ReDim bytaryOri(lngOriSiz - 1) + Open strargOriFilPth For Binary Access Read As #1 + Get #1, , bytaryOri() + Close #1 + strCprPth = IIf(strargCprFilPth = "", strargOriFilPth, strargCprFilPth) +'Select file path and name + strCprPth = strCprPth & IIf(Right(strCprPth, Len(strFilExt)) = +strFilExt, "", strFilExt) 'Add file extension if not exists + lngCprSiz = (lngOriSiz * 1.01) + 12 'Compression needs temporary a bit +more space then original file size + ReDim bytaryCpr(lngCprSiz - 1) + If lngfncCpr(bytaryCpr(0), lngCprSiz, bytaryOri(0), lngOriSiz, intLvl) = +SUCCESS Then + lngpvtPcnSml = (1# - (lngCprSiz / lngOriSiz)) * 100 + ReDim Preserve bytaryCpr(lngCprSiz - 1) + Open strCprPth For Binary Access Write As #1 + Put #1, , bytaryCpr() + Put #1, , lngOriSiz 'Add the the original size value to the end +(last 4 bytes) + Close #1 + Else + MsgBox "Compression error" + End If + Erase bytaryCpr + Erase bytaryOri +End Sub + +Public Sub subUncompressFile(ByVal strargFilPth As String) + Dim bytaryCpr() As Byte + Dim bytaryOri() As Byte + Dim lngOriSiz As Long + Dim lngCprSiz As Long + Dim strOriPth As String + lngCprSiz = FileLen(strargFilPth) + ReDim bytaryCpr(lngCprSiz - 1) + Open strargFilPth For Binary Access Read As #1 + Get #1, , bytaryCpr() + Close #1 + 'Read the original file size value: + lngOriSiz = bytaryCpr(lngCprSiz - 1) * (2 ^ 24) _ + + bytaryCpr(lngCprSiz - 2) * (2 ^ 16) _ + + bytaryCpr(lngCprSiz - 3) * (2 ^ 8) _ + + bytaryCpr(lngCprSiz - 4) + ReDim Preserve bytaryCpr(lngCprSiz - 5) 'Cut of the original size value + ReDim bytaryOri(lngOriSiz - 1) + If lngfncUcp(bytaryOri(0), lngOriSiz, bytaryCpr(0), lngCprSiz) = SUCCESS +Then + strOriPth = Left(strargFilPth, Len(strargFilPth) - Len(strFilExt)) + Open strOriPth For Binary Access Write As #1 + Put #1, , bytaryOri() + Close #1 + Else + MsgBox "Uncompression error" + End If + Erase bytaryCpr + Erase bytaryOri +End Sub +Public Property Get lngPercentSmaller() As Long + lngPercentSmaller = lngpvtPcnSml +End Property diff --git a/libs/zlib/old/visualc6/README.txt b/libs/zlib/old/visualc6/README.txt new file mode 100644 index 000000000..3d0aef0a1 --- /dev/null +++ b/libs/zlib/old/visualc6/README.txt @@ -0,0 +1,73 @@ +Microsoft Developer Studio Project Files, Format Version 6.00 for zlib. + +Copyright (C) 2000-2004 Simon-Pierre Cadieux. +Copyright (C) 2004 Cosmin Truta. +For conditions of distribution and use, see copyright notice in zlib.h. + + +This project builds the zlib binaries as follows: + +* Win32_DLL_Release\zlib1.dll DLL build +* Win32_DLL_Debug\zlib1d.dll DLL build (debug version) +* Win32_DLL_ASM_Release\zlib1.dll DLL build using ASM code +* Win32_DLL_ASM_Debug\zlib1d.dll DLL build using ASM code (debug version) +* Win32_LIB_Release\zlib.lib static build +* Win32_LIB_Debug\zlibd.lib static build (debug version) +* Win32_LIB_ASM_Release\zlib.lib static build using ASM code +* Win32_LIB_ASM_Debug\zlibd.lib static build using ASM code (debug version) + + +For more information regarding the DLL builds, please see the DLL FAQ +in ..\..\win32\DLL_FAQ.txt. + + +To build and test: + +1) On the main menu, select "File | Open Workspace". + Open "zlib.dsw". + +2) Select "Build | Set Active Configuration". + Choose the configuration you wish to build. + +3) Select "Build | Clean". + +4) Select "Build | Build ... (F7)". Ignore warning messages about + not being able to find certain include files (e.g. alloc.h). + +5) If you built one of the sample programs (example or minigzip), + select "Build | Execute ... (Ctrl+F5)". + + +To use: + +1) Select "Project | Settings (Alt+F7)". + Make note of the configuration names used in your project. + Usually, these names are "Win32 Release" and "Win32 Debug". + +2) In the Workspace window, select the "FileView" tab. + Right-click on the root item "Workspace '...'". + Select "Insert Project into Workspace". + Switch on the checkbox "Dependency of:", and select the name + of your project. Open "zlib.dsp". + +3) Select "Build | Configurations". + For each configuration of your project: + 3.1) Choose the zlib configuration you wish to use. + 3.2) Click on "Add". + 3.3) Set the new zlib configuration name to the name used by + the configuration from the current iteration. + +4) Select "Build | Set Active Configuration". + Choose the configuration you wish to build. + +5) Select "Build | Build ... (F7)". + +6) If you built an executable program, select + "Build | Execute ... (Ctrl+F5)". + + +Note: + +To build the ASM-enabled code, you need Microsoft Assembler +(ML.EXE). You can get it by downloading and installing the +latest Processor Pack for Visual C++ 6.0. diff --git a/libs/zlib/old/visualc6/example.dsp b/libs/zlib/old/visualc6/example.dsp new file mode 100644 index 000000000..d3580525b --- /dev/null +++ b/libs/zlib/old/visualc6/example.dsp @@ -0,0 +1,278 @@ +# Microsoft Developer Studio Project File - Name="example" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=example - Win32 LIB Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "example.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "example.mak" CFG="example - Win32 LIB Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "example - Win32 DLL ASM Release" (based on "Win32 (x86) Console Application") +!MESSAGE "example - Win32 DLL ASM Debug" (based on "Win32 (x86) Console Application") +!MESSAGE "example - Win32 DLL Release" (based on "Win32 (x86) Console Application") +!MESSAGE "example - Win32 DLL Debug" (based on "Win32 (x86) Console Application") +!MESSAGE "example - Win32 LIB ASM Release" (based on "Win32 (x86) Console Application") +!MESSAGE "example - Win32 LIB ASM Debug" (based on "Win32 (x86) Console Application") +!MESSAGE "example - Win32 LIB Release" (based on "Win32 (x86) Console Application") +!MESSAGE "example - Win32 LIB Debug" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "example - Win32 DLL ASM Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "example___Win32_DLL_ASM_Release" +# PROP BASE Intermediate_Dir "example___Win32_DLL_ASM_Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Win32_DLL_ASM_Release" +# PROP Intermediate_Dir "Win32_DLL_ASM_Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c +# SUBTRACT BASE CPP /YX +# ADD CPP /nologo /MD /W3 /O2 /D "WIN32" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "NDEBUG" /FD /c +# SUBTRACT CPP /YX +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 /nologo /subsystem:console /machine:I386 + +!ELSEIF "$(CFG)" == "example - Win32 DLL ASM Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "example___Win32_DLL_ASM_Debug" +# PROP BASE Intermediate_Dir "example___Win32_DLL_ASM_Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Win32_DLL_ASM_Debug" +# PROP Intermediate_Dir "Win32_DLL_ASM_Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c +# SUBTRACT BASE CPP /YX +# ADD CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "_DEBUG" /FR /FD /GZ /c +# SUBTRACT CPP /YX +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept + +!ELSEIF "$(CFG)" == "example - Win32 DLL Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "example___Win32_DLL_Release" +# PROP BASE Intermediate_Dir "example___Win32_DLL_Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Win32_DLL_Release" +# PROP Intermediate_Dir "Win32_DLL_Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c +# SUBTRACT BASE CPP /YX +# ADD CPP /nologo /MD /W3 /O2 /D "WIN32" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "NDEBUG" /FD /c +# SUBTRACT CPP /YX +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 /nologo /subsystem:console /machine:I386 + +!ELSEIF "$(CFG)" == "example - Win32 DLL Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "example___Win32_DLL_Debug" +# PROP BASE Intermediate_Dir "example___Win32_DLL_Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Win32_DLL_Debug" +# PROP Intermediate_Dir "Win32_DLL_Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c +# SUBTRACT BASE CPP /YX +# ADD CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "_DEBUG" /FR /FD /GZ /c +# SUBTRACT CPP /YX +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept + +!ELSEIF "$(CFG)" == "example - Win32 LIB ASM Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "example___Win32_LIB_ASM_Release" +# PROP BASE Intermediate_Dir "example___Win32_LIB_ASM_Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Win32_LIB_ASM_Release" +# PROP Intermediate_Dir "Win32_LIB_ASM_Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c +# SUBTRACT BASE CPP /YX +# ADD CPP /nologo /MD /W3 /O2 /D "WIN32" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "NDEBUG" /FD /c +# SUBTRACT CPP /YX +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 /nologo /subsystem:console /machine:I386 + +!ELSEIF "$(CFG)" == "example - Win32 LIB ASM Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "example___Win32_LIB_ASM_Debug" +# PROP BASE Intermediate_Dir "example___Win32_LIB_ASM_Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Win32_LIB_ASM_Debug" +# PROP Intermediate_Dir "Win32_LIB_ASM_Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c +# SUBTRACT BASE CPP /YX +# ADD CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "_DEBUG" /FR /FD /GZ /c +# SUBTRACT CPP /YX +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept + +!ELSEIF "$(CFG)" == "example - Win32 LIB Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "example___Win32_LIB_Release" +# PROP BASE Intermediate_Dir "example___Win32_LIB_Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Win32_LIB_Release" +# PROP Intermediate_Dir "Win32_LIB_Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c +# SUBTRACT BASE CPP /YX +# ADD CPP /nologo /MD /W3 /O2 /D "WIN32" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "NDEBUG" /FD /c +# SUBTRACT CPP /YX +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 /nologo /subsystem:console /machine:I386 + +!ELSEIF "$(CFG)" == "example - Win32 LIB Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "example___Win32_LIB_Debug" +# PROP BASE Intermediate_Dir "example___Win32_LIB_Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Win32_LIB_Debug" +# PROP Intermediate_Dir "Win32_LIB_Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c +# SUBTRACT BASE CPP /YX +# ADD CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "_DEBUG" /FR /FD /GZ /c +# SUBTRACT CPP /YX +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept + +!ENDIF + +# Begin Target + +# Name "example - Win32 DLL ASM Release" +# Name "example - Win32 DLL ASM Debug" +# Name "example - Win32 DLL Release" +# Name "example - Win32 DLL Debug" +# Name "example - Win32 LIB ASM Release" +# Name "example - Win32 LIB ASM Debug" +# Name "example - Win32 LIB Release" +# Name "example - Win32 LIB Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=..\..\example.c +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# Begin Source File + +SOURCE=..\..\zconf.h +# End Source File +# Begin Source File + +SOURCE=..\..\zlib.h +# End Source File +# End Group +# End Target +# End Project diff --git a/libs/zlib/old/visualc6/minigzip.dsp b/libs/zlib/old/visualc6/minigzip.dsp new file mode 100644 index 000000000..71034684d --- /dev/null +++ b/libs/zlib/old/visualc6/minigzip.dsp @@ -0,0 +1,278 @@ +# Microsoft Developer Studio Project File - Name="minigzip" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=minigzip - Win32 LIB Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "minigzip.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "minigzip.mak" CFG="minigzip - Win32 LIB Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "minigzip - Win32 DLL ASM Release" (based on "Win32 (x86) Console Application") +!MESSAGE "minigzip - Win32 DLL ASM Debug" (based on "Win32 (x86) Console Application") +!MESSAGE "minigzip - Win32 DLL Release" (based on "Win32 (x86) Console Application") +!MESSAGE "minigzip - Win32 DLL Debug" (based on "Win32 (x86) Console Application") +!MESSAGE "minigzip - Win32 LIB ASM Release" (based on "Win32 (x86) Console Application") +!MESSAGE "minigzip - Win32 LIB ASM Debug" (based on "Win32 (x86) Console Application") +!MESSAGE "minigzip - Win32 LIB Release" (based on "Win32 (x86) Console Application") +!MESSAGE "minigzip - Win32 LIB Debug" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "minigzip - Win32 DLL ASM Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "minigzip___Win32_DLL_ASM_Release" +# PROP BASE Intermediate_Dir "minigzip___Win32_DLL_ASM_Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Win32_DLL_ASM_Release" +# PROP Intermediate_Dir "Win32_DLL_ASM_Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c +# SUBTRACT BASE CPP /YX +# ADD CPP /nologo /MD /W3 /O2 /D "WIN32" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "NDEBUG" /FD /c +# SUBTRACT CPP /YX +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 /nologo /subsystem:console /machine:I386 + +!ELSEIF "$(CFG)" == "minigzip - Win32 DLL ASM Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "minigzip___Win32_DLL_ASM_Debug" +# PROP BASE Intermediate_Dir "minigzip___Win32_DLL_ASM_Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Win32_DLL_ASM_Debug" +# PROP Intermediate_Dir "Win32_DLL_ASM_Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c +# SUBTRACT BASE CPP /YX +# ADD CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "_DEBUG" /FR /FD /GZ /c +# SUBTRACT CPP /YX +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept + +!ELSEIF "$(CFG)" == "minigzip - Win32 DLL Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "minigzip___Win32_DLL_Release" +# PROP BASE Intermediate_Dir "minigzip___Win32_DLL_Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Win32_DLL_Release" +# PROP Intermediate_Dir "Win32_DLL_Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c +# SUBTRACT BASE CPP /YX +# ADD CPP /nologo /MD /W3 /O2 /D "WIN32" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "NDEBUG" /FD /c +# SUBTRACT CPP /YX +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 /nologo /subsystem:console /machine:I386 + +!ELSEIF "$(CFG)" == "minigzip - Win32 DLL Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "minigzip___Win32_DLL_Debug" +# PROP BASE Intermediate_Dir "minigzip___Win32_DLL_Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Win32_DLL_Debug" +# PROP Intermediate_Dir "Win32_DLL_Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c +# SUBTRACT BASE CPP /YX +# ADD CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "_DEBUG" /FR /FD /GZ /c +# SUBTRACT CPP /YX +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept + +!ELSEIF "$(CFG)" == "minigzip - Win32 LIB ASM Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "minigzip___Win32_LIB_ASM_Release" +# PROP BASE Intermediate_Dir "minigzip___Win32_LIB_ASM_Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Win32_LIB_ASM_Release" +# PROP Intermediate_Dir "Win32_LIB_ASM_Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c +# SUBTRACT BASE CPP /YX +# ADD CPP /nologo /MD /W3 /O2 /D "WIN32" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "NDEBUG" /FD /c +# SUBTRACT CPP /YX +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 /nologo /subsystem:console /machine:I386 + +!ELSEIF "$(CFG)" == "minigzip - Win32 LIB ASM Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "minigzip___Win32_LIB_ASM_Debug" +# PROP BASE Intermediate_Dir "minigzip___Win32_LIB_ASM_Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Win32_LIB_ASM_Debug" +# PROP Intermediate_Dir "Win32_LIB_ASM_Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c +# SUBTRACT BASE CPP /YX +# ADD CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "_DEBUG" /FR /FD /GZ /c +# SUBTRACT CPP /YX +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept + +!ELSEIF "$(CFG)" == "minigzip - Win32 LIB Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "minigzip___Win32_LIB_Release" +# PROP BASE Intermediate_Dir "minigzip___Win32_LIB_Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Win32_LIB_Release" +# PROP Intermediate_Dir "Win32_LIB_Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c +# SUBTRACT BASE CPP /YX +# ADD CPP /nologo /MD /W3 /O2 /D "WIN32" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "NDEBUG" /FD /c +# SUBTRACT CPP /YX +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 /nologo /subsystem:console /machine:I386 + +!ELSEIF "$(CFG)" == "minigzip - Win32 LIB Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "minigzip___Win32_LIB_Debug" +# PROP BASE Intermediate_Dir "minigzip___Win32_LIB_Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Win32_LIB_Debug" +# PROP Intermediate_Dir "Win32_LIB_Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c +# SUBTRACT BASE CPP /YX +# ADD CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "_DEBUG" /FR /FD /GZ /c +# SUBTRACT CPP /YX +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept + +!ENDIF + +# Begin Target + +# Name "minigzip - Win32 DLL ASM Release" +# Name "minigzip - Win32 DLL ASM Debug" +# Name "minigzip - Win32 DLL Release" +# Name "minigzip - Win32 DLL Debug" +# Name "minigzip - Win32 LIB ASM Release" +# Name "minigzip - Win32 LIB ASM Debug" +# Name "minigzip - Win32 LIB Release" +# Name "minigzip - Win32 LIB Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=..\..\minigzip.c +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# Begin Source File + +SOURCE=..\..\zconf.h +# End Source File +# Begin Source File + +SOURCE=..\..\zlib.h +# End Source File +# End Group +# End Target +# End Project diff --git a/libs/zlib/old/visualc6/zlib.dsp b/libs/zlib/old/visualc6/zlib.dsp new file mode 100644 index 000000000..00f54ea42 --- /dev/null +++ b/libs/zlib/old/visualc6/zlib.dsp @@ -0,0 +1,621 @@ +# Microsoft Developer Studio Project File - Name="zlib" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 +# TARGTYPE "Win32 (x86) Static Library" 0x0104 + +CFG=zlib - Win32 LIB Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "zlib.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "zlib.mak" CFG="zlib - Win32 LIB Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "zlib - Win32 DLL ASM Release" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "zlib - Win32 DLL ASM Debug" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "zlib - Win32 DLL Release" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "zlib - Win32 DLL Debug" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "zlib - Win32 LIB ASM Release" (based on "Win32 (x86) Static Library") +!MESSAGE "zlib - Win32 LIB ASM Debug" (based on "Win32 (x86) Static Library") +!MESSAGE "zlib - Win32 LIB Release" (based on "Win32 (x86) Static Library") +!MESSAGE "zlib - Win32 LIB Debug" (based on "Win32 (x86) Static Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" + +!IF "$(CFG)" == "zlib - Win32 DLL ASM Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "zlib___Win32_DLL_ASM_Release" +# PROP BASE Intermediate_Dir "zlib___Win32_DLL_ASM_Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Win32_DLL_ASM_Release" +# PROP Intermediate_Dir "Win32_DLL_ASM_Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +CPP=cl.exe +# ADD BASE CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c +# SUBTRACT BASE CPP /YX /Yc /Yu +# ADD CPP /nologo /MD /W3 /O2 /D "WIN32" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "NDEBUG" /D "ASMV" /D "ASMINF" /FD /c +# SUBTRACT CPP /YX /Yc /Yu +MTL=midl.exe +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +RSC=rc.exe +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 +# ADD LINK32 /nologo /dll /machine:I386 /out:"Win32_DLL_ASM_Release\zlib1.dll" + +!ELSEIF "$(CFG)" == "zlib - Win32 DLL ASM Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "zlib___Win32_DLL_ASM_Debug" +# PROP BASE Intermediate_Dir "zlib___Win32_DLL_ASM_Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Win32_DLL_ASM_Debug" +# PROP Intermediate_Dir "Win32_DLL_ASM_Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +CPP=cl.exe +# ADD BASE CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c +# SUBTRACT BASE CPP /YX /Yc /Yu +# ADD CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "_DEBUG" /D "ASMV" /D "ASMINF" /FR /FD /GZ /c +# SUBTRACT CPP /YX /Yc /Yu +MTL=midl.exe +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +RSC=rc.exe +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 /nologo /dll /debug /machine:I386 /out:"Win32_DLL_ASM_Debug\zlib1d.dll" /pdbtype:sept + +!ELSEIF "$(CFG)" == "zlib - Win32 DLL Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "zlib___Win32_DLL_Release" +# PROP BASE Intermediate_Dir "zlib___Win32_DLL_Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Win32_DLL_Release" +# PROP Intermediate_Dir "Win32_DLL_Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +CPP=cl.exe +# ADD BASE CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c +# SUBTRACT BASE CPP /YX /Yc /Yu +# ADD CPP /nologo /MD /W3 /O2 /D "WIN32" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "NDEBUG" /FD /c +# SUBTRACT CPP /YX /Yc /Yu +MTL=midl.exe +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +RSC=rc.exe +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 +# ADD LINK32 /nologo /dll /machine:I386 /out:"Win32_DLL_Release\zlib1.dll" + +!ELSEIF "$(CFG)" == "zlib - Win32 DLL Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "zlib___Win32_DLL_Debug" +# PROP BASE Intermediate_Dir "zlib___Win32_DLL_Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Win32_DLL_Debug" +# PROP Intermediate_Dir "Win32_DLL_Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +CPP=cl.exe +# ADD BASE CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c +# SUBTRACT BASE CPP /YX /Yc /Yu +# ADD CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "_DEBUG" /FR /FD /GZ /c +# SUBTRACT CPP /YX /Yc /Yu +MTL=midl.exe +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +RSC=rc.exe +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 /nologo /dll /debug /machine:I386 /out:"Win32_DLL_Debug\zlib1d.dll" /pdbtype:sept + +!ELSEIF "$(CFG)" == "zlib - Win32 LIB ASM Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "zlib___Win32_LIB_ASM_Release" +# PROP BASE Intermediate_Dir "zlib___Win32_LIB_ASM_Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Win32_LIB_ASM_Release" +# PROP Intermediate_Dir "Win32_LIB_ASM_Release" +# PROP Target_Dir "" +CPP=cl.exe +# ADD BASE CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c +# SUBTRACT BASE CPP /YX /Yc /Yu +# ADD CPP /nologo /MD /W3 /O2 /D "WIN32" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "NDEBUG" /D "ASMV" /D "ASMINF" /FD /c +# SUBTRACT CPP /YX /Yc /Yu +RSC=rc.exe +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LIB32=link.exe -lib +# ADD BASE LIB32 /nologo +# ADD LIB32 /nologo + +!ELSEIF "$(CFG)" == "zlib - Win32 LIB ASM Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "zlib___Win32_LIB_ASM_Debug" +# PROP BASE Intermediate_Dir "zlib___Win32_LIB_ASM_Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Win32_LIB_ASM_Debug" +# PROP Intermediate_Dir "Win32_LIB_ASM_Debug" +# PROP Target_Dir "" +CPP=cl.exe +# ADD BASE CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c +# SUBTRACT BASE CPP /YX /Yc /Yu +# ADD CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "_DEBUG" /D "ASMV" /D "ASMINF" /FR /FD /GZ /c +# SUBTRACT CPP /YX /Yc /Yu +RSC=rc.exe +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LIB32=link.exe -lib +# ADD BASE LIB32 /nologo +# ADD LIB32 /nologo /out:"Win32_LIB_ASM_Debug\zlibd.lib" + +!ELSEIF "$(CFG)" == "zlib - Win32 LIB Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "zlib___Win32_LIB_Release" +# PROP BASE Intermediate_Dir "zlib___Win32_LIB_Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Win32_LIB_Release" +# PROP Intermediate_Dir "Win32_LIB_Release" +# PROP Target_Dir "" +CPP=cl.exe +# ADD BASE CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c +# SUBTRACT BASE CPP /YX /Yc /Yu +# ADD CPP /nologo /MD /W3 /O2 /D "WIN32" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "NDEBUG" /FD /c +# SUBTRACT CPP /YX /Yc /Yu +RSC=rc.exe +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LIB32=link.exe -lib +# ADD BASE LIB32 /nologo +# ADD LIB32 /nologo + +!ELSEIF "$(CFG)" == "zlib - Win32 LIB Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "zlib___Win32_LIB_Debug" +# PROP BASE Intermediate_Dir "zlib___Win32_LIB_Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Win32_LIB_Debug" +# PROP Intermediate_Dir "Win32_LIB_Debug" +# PROP Target_Dir "" +CPP=cl.exe +# ADD BASE CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c +# SUBTRACT BASE CPP /YX /Yc /Yu +# ADD CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "_DEBUG" /FR /FD /GZ /c +# SUBTRACT CPP /YX /Yc /Yu +RSC=rc.exe +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LIB32=link.exe -lib +# ADD BASE LIB32 /nologo +# ADD LIB32 /nologo /out:"Win32_LIB_Debug\zlibd.lib" + +!ENDIF + +# Begin Target + +# Name "zlib - Win32 DLL ASM Release" +# Name "zlib - Win32 DLL ASM Debug" +# Name "zlib - Win32 DLL Release" +# Name "zlib - Win32 DLL Debug" +# Name "zlib - Win32 LIB ASM Release" +# Name "zlib - Win32 LIB ASM Debug" +# Name "zlib - Win32 LIB Release" +# Name "zlib - Win32 LIB Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=..\..\adler32.c +# End Source File +# Begin Source File + +SOURCE=..\..\compress.c +# End Source File +# Begin Source File + +SOURCE=..\..\crc32.c +# End Source File +# Begin Source File + +SOURCE=..\..\deflate.c +# End Source File +# Begin Source File + +SOURCE=..\..\gzclose.c +# End Source File +# Begin Source File + +SOURCE=..\..\gzlib.c +# End Source File +# Begin Source File + +SOURCE=..\..\gzread.c +# End Source File +# Begin Source File + +SOURCE=..\..\gzwrite.c +# End Source File +# Begin Source File + +SOURCE=..\..\infback.c +# End Source File +# Begin Source File + +SOURCE=..\..\inffast.c +# End Source File +# Begin Source File + +SOURCE=..\..\inflate.c +# End Source File +# Begin Source File + +SOURCE=..\..\inftrees.c +# End Source File +# Begin Source File + +SOURCE=..\..\trees.c +# End Source File +# Begin Source File + +SOURCE=..\..\uncompr.c +# End Source File +# Begin Source File + +SOURCE=..\..\win32\zlib.def + +!IF "$(CFG)" == "zlib - Win32 DLL ASM Release" + +!ELSEIF "$(CFG)" == "zlib - Win32 DLL ASM Debug" + +!ELSEIF "$(CFG)" == "zlib - Win32 DLL Release" + +!ELSEIF "$(CFG)" == "zlib - Win32 DLL Debug" + +!ELSEIF "$(CFG)" == "zlib - Win32 LIB ASM Release" + +# PROP Exclude_From_Build 1 + +!ELSEIF "$(CFG)" == "zlib - Win32 LIB ASM Debug" + +# PROP Exclude_From_Build 1 + +!ELSEIF "$(CFG)" == "zlib - Win32 LIB Release" + +# PROP Exclude_From_Build 1 + +!ELSEIF "$(CFG)" == "zlib - Win32 LIB Debug" + +# PROP Exclude_From_Build 1 + +!ENDIF + +# End Source File +# Begin Source File + +SOURCE=..\..\zutil.c +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# Begin Source File + +SOURCE=..\..\crc32.h +# End Source File +# Begin Source File + +SOURCE=..\..\deflate.h +# End Source File +# Begin Source File + +SOURCE=..\..\inffast.h +# End Source File +# Begin Source File + +SOURCE=..\..\inffixed.h +# End Source File +# Begin Source File + +SOURCE=..\..\inflate.h +# End Source File +# Begin Source File + +SOURCE=..\..\inftrees.h +# End Source File +# Begin Source File + +SOURCE=..\..\trees.h +# End Source File +# Begin Source File + +SOURCE=..\..\zconf.h +# End Source File +# Begin Source File + +SOURCE=..\..\zlib.h +# End Source File +# Begin Source File + +SOURCE=..\..\zutil.h +# End Source File +# End Group +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# Begin Source File + +SOURCE=..\..\win32\zlib1.rc +# End Source File +# End Group +# Begin Group "Assembler Files (Unsupported)" + +# PROP Default_Filter "asm;obj;c;cpp;cxx;h;hpp;hxx" +# Begin Source File + +SOURCE=..\..\contrib\masmx86\gvmat32.asm + +!IF "$(CFG)" == "zlib - Win32 DLL ASM Release" + +# Begin Custom Build - Assembling... +IntDir=.\Win32_DLL_ASM_Release +InputPath=..\..\contrib\masmx86\gvmat32.asm +InputName=gvmat32 + +"$(IntDir)\$(InputName).obj" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + ml.exe /nologo /c /coff /Cx /Fo"$(IntDir)\$(InputName).obj" "$(InputPath)" + +# End Custom Build + +!ELSEIF "$(CFG)" == "zlib - Win32 DLL ASM Debug" + +# Begin Custom Build - Assembling... +IntDir=.\Win32_DLL_ASM_Debug +InputPath=..\..\contrib\masmx86\gvmat32.asm +InputName=gvmat32 + +"$(IntDir)\$(InputName).obj" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + ml.exe /nologo /c /coff /Cx /Zi /Fo"$(IntDir)\$(InputName).obj" "$(InputPath)" + +# End Custom Build + +!ELSEIF "$(CFG)" == "zlib - Win32 DLL Release" + +# PROP Exclude_From_Build 1 + +!ELSEIF "$(CFG)" == "zlib - Win32 DLL Debug" + +# PROP Exclude_From_Build 1 + +!ELSEIF "$(CFG)" == "zlib - Win32 LIB ASM Release" + +# Begin Custom Build - Assembling... +IntDir=.\Win32_LIB_ASM_Release +InputPath=..\..\contrib\masmx86\gvmat32.asm +InputName=gvmat32 + +"$(IntDir)\$(InputName).obj" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + ml.exe /nologo /c /coff /Cx /Fo"$(IntDir)\$(InputName).obj" "$(InputPath)" + +# End Custom Build + +!ELSEIF "$(CFG)" == "zlib - Win32 LIB ASM Debug" + +# Begin Custom Build - Assembling... +IntDir=.\Win32_LIB_ASM_Debug +InputPath=..\..\contrib\masmx86\gvmat32.asm +InputName=gvmat32 + +"$(IntDir)\$(InputName).obj" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + ml.exe /nologo /c /coff /Cx /Zi /Fo"$(IntDir)\$(InputName).obj" "$(InputPath)" + +# End Custom Build + +!ELSEIF "$(CFG)" == "zlib - Win32 LIB Release" + +# PROP Exclude_From_Build 1 + +!ELSEIF "$(CFG)" == "zlib - Win32 LIB Debug" + +# PROP Exclude_From_Build 1 + +!ENDIF + +# End Source File +# Begin Source File + +SOURCE=..\..\contrib\masmx86\gvmat32c.c + +!IF "$(CFG)" == "zlib - Win32 DLL ASM Release" + +# ADD CPP /I "..\.." + +!ELSEIF "$(CFG)" == "zlib - Win32 DLL ASM Debug" + +# ADD CPP /I "..\.." + +!ELSEIF "$(CFG)" == "zlib - Win32 DLL Release" + +# PROP Exclude_From_Build 1 +# ADD CPP /I "..\.." + +!ELSEIF "$(CFG)" == "zlib - Win32 DLL Debug" + +# PROP Exclude_From_Build 1 +# ADD CPP /I "..\.." + +!ELSEIF "$(CFG)" == "zlib - Win32 LIB ASM Release" + +# ADD CPP /I "..\.." + +!ELSEIF "$(CFG)" == "zlib - Win32 LIB ASM Debug" + +# ADD CPP /I "..\.." + +!ELSEIF "$(CFG)" == "zlib - Win32 LIB Release" + +# PROP Exclude_From_Build 1 +# ADD CPP /I "..\.." + +!ELSEIF "$(CFG)" == "zlib - Win32 LIB Debug" + +# PROP Exclude_From_Build 1 +# ADD CPP /I "..\.." + +!ENDIF + +# End Source File +# Begin Source File + +SOURCE=..\..\contrib\masmx86\inffas32.asm + +!IF "$(CFG)" == "zlib - Win32 DLL ASM Release" + +# Begin Custom Build - Assembling... +IntDir=.\Win32_DLL_ASM_Release +InputPath=..\..\contrib\masmx86\inffas32.asm +InputName=inffas32 + +"$(IntDir)\$(InputName).obj" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + ml.exe /nologo /c /coff /Cx /Fo"$(IntDir)\$(InputName).obj" "$(InputPath)" + +# End Custom Build + +!ELSEIF "$(CFG)" == "zlib - Win32 DLL ASM Debug" + +# Begin Custom Build - Assembling... +IntDir=.\Win32_DLL_ASM_Debug +InputPath=..\..\contrib\masmx86\inffas32.asm +InputName=inffas32 + +"$(IntDir)\$(InputName).obj" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + ml.exe /nologo /c /coff /Cx /Zi /Fo"$(IntDir)\$(InputName).obj" "$(InputPath)" + +# End Custom Build + +!ELSEIF "$(CFG)" == "zlib - Win32 DLL Release" + +# PROP Exclude_From_Build 1 + +!ELSEIF "$(CFG)" == "zlib - Win32 DLL Debug" + +# PROP Exclude_From_Build 1 + +!ELSEIF "$(CFG)" == "zlib - Win32 LIB ASM Release" + +# Begin Custom Build - Assembling... +IntDir=.\Win32_LIB_ASM_Release +InputPath=..\..\contrib\masmx86\inffas32.asm +InputName=inffas32 + +"$(IntDir)\$(InputName).obj" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + ml.exe /nologo /c /coff /Cx /Fo"$(IntDir)\$(InputName).obj" "$(InputPath)" + +# End Custom Build + +!ELSEIF "$(CFG)" == "zlib - Win32 LIB ASM Debug" + +# Begin Custom Build - Assembling... +IntDir=.\Win32_LIB_ASM_Debug +InputPath=..\..\contrib\masmx86\inffas32.asm +InputName=inffas32 + +"$(IntDir)\$(InputName).obj" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + ml.exe /nologo /c /coff /Cx /Zi /Fo"$(IntDir)\$(InputName).obj" "$(InputPath)" + +# End Custom Build + +!ELSEIF "$(CFG)" == "zlib - Win32 LIB Release" + +# PROP Exclude_From_Build 1 + +!ELSEIF "$(CFG)" == "zlib - Win32 LIB Debug" + +# PROP Exclude_From_Build 1 + +!ENDIF + +# End Source File +# End Group +# Begin Source File + +SOURCE=.\README.txt +# End Source File +# End Target +# End Project diff --git a/libs/zlib/old/visualc6/zlib.dsw b/libs/zlib/old/visualc6/zlib.dsw new file mode 100644 index 000000000..3a771fce0 --- /dev/null +++ b/libs/zlib/old/visualc6/zlib.dsw @@ -0,0 +1,59 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00 +# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! + +############################################################################### + +Project: "example"=.\example.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ + Begin Project Dependency + Project_Dep_Name zlib + End Project Dependency +}}} + +############################################################################### + +Project: "minigzip"=.\minigzip.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ + Begin Project Dependency + Project_Dep_Name zlib + End Project Dependency +}}} + +############################################################################### + +Project: "zlib"=.\zlib.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/libs/zlib/projects/README.projects b/libs/zlib/projects/README.projects new file mode 100644 index 000000000..1c029e4a3 --- /dev/null +++ b/libs/zlib/projects/README.projects @@ -0,0 +1,41 @@ +This directory contains project files for building zlib under various +Integrated Development Environments (IDE). + +If you wish to submit a new project to this directory, you should comply +to the following requirements. Otherwise (e.g. if you wish to integrate +a custom piece of code that changes the zlib interface or its behavior), +please consider submitting the project to the contrib directory. + + +Requirements +============ + +- The project must build zlib using the source files from the official + zlib source distribution, exclusively. + +- If the project produces redistributable builds (e.g. shared objects + or DLL files), these builds must be compatible to those produced by + makefiles, if such makefiles exist in the zlib distribution. + In particular, if the project produces a DLL build for the Win32 + platform, this build must comply to the officially-ammended Win32 DLL + Application Binary Interface (ABI), described in win32/DLL_FAQ.txt. + +- The project may provide additional build targets, which depend on + 3rd-party (unofficially-supported) software, present in the contrib + directory. For example, it is possible to provide an "ASM build", + besides the officially-supported build, and have ASM source files + among its dependencies. + +- If there are significant differences between the project files created + by different versions of an IDE (e.g. Visual C++ 6.0 vs. 7.0), the name + of the project directory should contain the version number of the IDE + for which the project is intended (e.g. "visualc6" for Visual C++ 6.0, + or "visualc7" for Visual C++ 7.0 and 7.1). + + +Current projects +================ + +visualc6/ by Simon-Pierre Cadieux + and Cosmin Truta + Project for Microsoft Visual C++ 6.0 diff --git a/libs/zlib/projects/visualc10/.gitignore b/libs/zlib/projects/visualc10/.gitignore new file mode 100644 index 000000000..488a5428b --- /dev/null +++ b/libs/zlib/projects/visualc10/.gitignore @@ -0,0 +1,3 @@ +/Win32 +/x64 +/zlib.vcproj.*.*.user diff --git a/libs/zlib/projects/visualc10/zlib.vcxproj b/libs/zlib/projects/visualc10/zlib.vcxproj new file mode 100644 index 000000000..4f0a16f30 --- /dev/null +++ b/libs/zlib/projects/visualc10/zlib.vcxproj @@ -0,0 +1,343 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {73A5729C-7323-41D4-AB48-8A03C9F81603} + zlib + + + + StaticLibrary + false + + + StaticLibrary + false + + + StaticLibrary + false + + + StaticLibrary + false + + + + + + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>10.0.30319.1 + $(ProjectDir)$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + + + + Disabled + WIN32;_DEBUG;ASMV;ASMINF;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;%(PreprocessorDefinitions) + true + EnableFastChecks + MultiThreadedDebug + $(ProjectDir)$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + Level3 + true + EditAndContinue + CompileAsC + false + + + _DEBUG;%(PreprocessorDefinitions) + 0x0409 + + + $(ProjectDir)$(Platform)\$(Configuration)\zlib.lib + true + MachineX86 + + + true + $(ProjectDir)$(PlatformName)\$(ConfigurationName)\zlib.bsc + + + + + X64 + + + Disabled + WIN32;_DEBUG;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;%(PreprocessorDefinitions) + true + EnableFastChecks + MultiThreadedDebug + $(ProjectDir)$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + Level3 + true + ProgramDatabase + CompileAsC + false + + + _DEBUG;%(PreprocessorDefinitions) + 0x0409 + + + $(ProjectDir)$(Platform)\$(Configuration)\zlib.lib + true + MachineX64 + + + true + $(ProjectDir)$(PlatformName)\$(ConfigurationName)\zlib.bsc + + + + + MaxSpeed + OnlyExplicitInline + WIN32;NDEBUG;ASMV;ASMINF;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;%(PreprocessorDefinitions) + true + MultiThreaded + true + $(ProjectDir)$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + Level3 + true + CompileAsC + true + + + NDEBUG;%(PreprocessorDefinitions) + 0x0409 + + + $(ProjectDir)$(Platform)\$(Configuration)\zlib.lib + true + MachineX86 + + + true + $(ProjectDir)$(PlatformName)\$(ConfigurationName)\zlib.bsc + + + + + X64 + + + MaxSpeed + OnlyExplicitInline + WIN32;NDEBUG;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;%(PreprocessorDefinitions) + true + MultiThreaded + true + $(ProjectDir)$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + $(ProjectDir)$(Platform)\$(Configuration)\ + Level3 + true + CompileAsC + true + + + NDEBUG;%(PreprocessorDefinitions) + 0x0409 + + + $(ProjectDir)$(Platform)\$(Configuration)\zlib.lib + true + MachineX64 + + + true + $(ProjectDir)$(PlatformName)\$(ConfigurationName)\zlib.bsc + + + + + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + + + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + + + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + + + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + + + + + + + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + + + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + + + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + + + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + + + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + + + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + + + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + + + true + ../;%(AdditionalIncludeDirectories) + ../..;%(AdditionalIncludeDirectories) + true + ../..;%(AdditionalIncludeDirectories) + + + + + true + true + true + true + + + + + + + + + + + + + + + + + + + %(PreprocessorDefinitions) + \Oogaland\Projects\orospakr.ca\srb2\tools\zlib\win32;%(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + \Oogaland\Projects\orospakr.ca\srb2\tools\zlib\win32;%(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + \Oogaland\Projects\orospakr.ca\srb2\tools\zlib\win32;%(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + \Oogaland\Projects\orospakr.ca\srb2\tools\zlib\win32;%(AdditionalIncludeDirectories) + + + + + true + true + + + true + true + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + + + + + \ No newline at end of file diff --git a/libs/zlib/projects/visualc6/README.txt b/libs/zlib/projects/visualc6/README.txt new file mode 100644 index 000000000..3d0aef0a1 --- /dev/null +++ b/libs/zlib/projects/visualc6/README.txt @@ -0,0 +1,73 @@ +Microsoft Developer Studio Project Files, Format Version 6.00 for zlib. + +Copyright (C) 2000-2004 Simon-Pierre Cadieux. +Copyright (C) 2004 Cosmin Truta. +For conditions of distribution and use, see copyright notice in zlib.h. + + +This project builds the zlib binaries as follows: + +* Win32_DLL_Release\zlib1.dll DLL build +* Win32_DLL_Debug\zlib1d.dll DLL build (debug version) +* Win32_DLL_ASM_Release\zlib1.dll DLL build using ASM code +* Win32_DLL_ASM_Debug\zlib1d.dll DLL build using ASM code (debug version) +* Win32_LIB_Release\zlib.lib static build +* Win32_LIB_Debug\zlibd.lib static build (debug version) +* Win32_LIB_ASM_Release\zlib.lib static build using ASM code +* Win32_LIB_ASM_Debug\zlibd.lib static build using ASM code (debug version) + + +For more information regarding the DLL builds, please see the DLL FAQ +in ..\..\win32\DLL_FAQ.txt. + + +To build and test: + +1) On the main menu, select "File | Open Workspace". + Open "zlib.dsw". + +2) Select "Build | Set Active Configuration". + Choose the configuration you wish to build. + +3) Select "Build | Clean". + +4) Select "Build | Build ... (F7)". Ignore warning messages about + not being able to find certain include files (e.g. alloc.h). + +5) If you built one of the sample programs (example or minigzip), + select "Build | Execute ... (Ctrl+F5)". + + +To use: + +1) Select "Project | Settings (Alt+F7)". + Make note of the configuration names used in your project. + Usually, these names are "Win32 Release" and "Win32 Debug". + +2) In the Workspace window, select the "FileView" tab. + Right-click on the root item "Workspace '...'". + Select "Insert Project into Workspace". + Switch on the checkbox "Dependency of:", and select the name + of your project. Open "zlib.dsp". + +3) Select "Build | Configurations". + For each configuration of your project: + 3.1) Choose the zlib configuration you wish to use. + 3.2) Click on "Add". + 3.3) Set the new zlib configuration name to the name used by + the configuration from the current iteration. + +4) Select "Build | Set Active Configuration". + Choose the configuration you wish to build. + +5) Select "Build | Build ... (F7)". + +6) If you built an executable program, select + "Build | Execute ... (Ctrl+F5)". + + +Note: + +To build the ASM-enabled code, you need Microsoft Assembler +(ML.EXE). You can get it by downloading and installing the +latest Processor Pack for Visual C++ 6.0. diff --git a/libs/zlib/projects/visualc6/example.dsp b/libs/zlib/projects/visualc6/example.dsp new file mode 100644 index 000000000..e072a37ff --- /dev/null +++ b/libs/zlib/projects/visualc6/example.dsp @@ -0,0 +1,278 @@ +# Microsoft Developer Studio Project File - Name="example" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=example - Win32 LIB Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "example.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "example.mak" CFG="example - Win32 LIB Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "example - Win32 DLL Release" (based on "Win32 (x86) Console Application") +!MESSAGE "example - Win32 DLL Debug" (based on "Win32 (x86) Console Application") +!MESSAGE "example - Win32 DLL ASM Release" (based on "Win32 (x86) Console Application") +!MESSAGE "example - Win32 DLL ASM Debug" (based on "Win32 (x86) Console Application") +!MESSAGE "example - Win32 LIB Release" (based on "Win32 (x86) Console Application") +!MESSAGE "example - Win32 LIB Debug" (based on "Win32 (x86) Console Application") +!MESSAGE "example - Win32 LIB ASM Release" (based on "Win32 (x86) Console Application") +!MESSAGE "example - Win32 LIB ASM Debug" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "example - Win32 DLL Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "example___Win32_DLL_Release" +# PROP BASE Intermediate_Dir "example___Win32_DLL_Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Win32_DLL_Release" +# PROP Intermediate_Dir "Win32_DLL_Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c +# SUBTRACT BASE CPP /YX +# ADD CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c +# SUBTRACT CPP /YX +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 /nologo /subsystem:console /machine:I386 + +!ELSEIF "$(CFG)" == "example - Win32 DLL Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "example___Win32_DLL_Debug" +# PROP BASE Intermediate_Dir "example___Win32_DLL_Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Win32_DLL_Debug" +# PROP Intermediate_Dir "Win32_DLL_Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c +# SUBTRACT BASE CPP /YX +# ADD CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c +# SUBTRACT CPP /YX +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept + +!ELSEIF "$(CFG)" == "example - Win32 DLL ASM Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "example___Win32_DLL_ASM_Release" +# PROP BASE Intermediate_Dir "example___Win32_DLL_ASM_Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Win32_DLL_ASM_Release" +# PROP Intermediate_Dir "Win32_DLL_ASM_Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c +# SUBTRACT BASE CPP /YX +# ADD CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c +# SUBTRACT CPP /YX +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 /nologo /subsystem:console /machine:I386 + +!ELSEIF "$(CFG)" == "example - Win32 DLL ASM Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "example___Win32_DLL_ASM_Debug" +# PROP BASE Intermediate_Dir "example___Win32_DLL_ASM_Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Win32_DLL_ASM_Debug" +# PROP Intermediate_Dir "Win32_DLL_ASM_Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c +# SUBTRACT BASE CPP /YX +# ADD CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c +# SUBTRACT CPP /YX +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept + +!ELSEIF "$(CFG)" == "example - Win32 LIB Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "example___Win32_LIB_Release" +# PROP BASE Intermediate_Dir "example___Win32_LIB_Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Win32_LIB_Release" +# PROP Intermediate_Dir "Win32_LIB_Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c +# SUBTRACT BASE CPP /YX +# ADD CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c +# SUBTRACT CPP /YX +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 /nologo /subsystem:console /machine:I386 + +!ELSEIF "$(CFG)" == "example - Win32 LIB Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "example___Win32_LIB_Debug" +# PROP BASE Intermediate_Dir "example___Win32_LIB_Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Win32_LIB_Debug" +# PROP Intermediate_Dir "Win32_LIB_Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c +# SUBTRACT BASE CPP /YX +# ADD CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c +# SUBTRACT CPP /YX +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept + +!ELSEIF "$(CFG)" == "example - Win32 LIB ASM Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "example___Win32_LIB_ASM_Release" +# PROP BASE Intermediate_Dir "example___Win32_LIB_ASM_Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Win32_LIB_ASM_Release" +# PROP Intermediate_Dir "Win32_LIB_ASM_Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c +# SUBTRACT BASE CPP /YX +# ADD CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c +# SUBTRACT CPP /YX +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 /nologo /subsystem:console /machine:I386 + +!ELSEIF "$(CFG)" == "example - Win32 LIB ASM Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "example___Win32_LIB_ASM_Debug" +# PROP BASE Intermediate_Dir "example___Win32_LIB_ASM_Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Win32_LIB_ASM_Debug" +# PROP Intermediate_Dir "Win32_LIB_ASM_Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c +# SUBTRACT BASE CPP /YX +# ADD CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c +# SUBTRACT CPP /YX +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept + +!ENDIF + +# Begin Target + +# Name "example - Win32 DLL Release" +# Name "example - Win32 DLL Debug" +# Name "example - Win32 DLL ASM Release" +# Name "example - Win32 DLL ASM Debug" +# Name "example - Win32 LIB Release" +# Name "example - Win32 LIB Debug" +# Name "example - Win32 LIB ASM Release" +# Name "example - Win32 LIB ASM Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=..\..\example.c +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# Begin Source File + +SOURCE=..\..\zconf.h +# End Source File +# Begin Source File + +SOURCE=..\..\zlib.h +# End Source File +# End Group +# End Target +# End Project diff --git a/libs/zlib/projects/visualc6/minigzip.dsp b/libs/zlib/projects/visualc6/minigzip.dsp new file mode 100644 index 000000000..f32024eaf --- /dev/null +++ b/libs/zlib/projects/visualc6/minigzip.dsp @@ -0,0 +1,278 @@ +# Microsoft Developer Studio Project File - Name="minigzip" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=minigzip - Win32 LIB Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "minigzip.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "minigzip.mak" CFG="minigzip - Win32 LIB Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "minigzip - Win32 DLL Release" (based on "Win32 (x86) Console Application") +!MESSAGE "minigzip - Win32 DLL Debug" (based on "Win32 (x86) Console Application") +!MESSAGE "minigzip - Win32 DLL ASM Release" (based on "Win32 (x86) Console Application") +!MESSAGE "minigzip - Win32 DLL ASM Debug" (based on "Win32 (x86) Console Application") +!MESSAGE "minigzip - Win32 LIB Release" (based on "Win32 (x86) Console Application") +!MESSAGE "minigzip - Win32 LIB Debug" (based on "Win32 (x86) Console Application") +!MESSAGE "minigzip - Win32 LIB ASM Release" (based on "Win32 (x86) Console Application") +!MESSAGE "minigzip - Win32 LIB ASM Debug" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "minigzip - Win32 DLL Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "minigzip___Win32_DLL_Release" +# PROP BASE Intermediate_Dir "minigzip___Win32_DLL_Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Win32_DLL_Release" +# PROP Intermediate_Dir "Win32_DLL_Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c +# SUBTRACT BASE CPP /YX +# ADD CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c +# SUBTRACT CPP /YX +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 /nologo /subsystem:console /machine:I386 + +!ELSEIF "$(CFG)" == "minigzip - Win32 DLL Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "minigzip___Win32_DLL_Debug" +# PROP BASE Intermediate_Dir "minigzip___Win32_DLL_Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Win32_DLL_Debug" +# PROP Intermediate_Dir "Win32_DLL_Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c +# SUBTRACT BASE CPP /YX +# ADD CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c +# SUBTRACT CPP /YX +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept + +!ELSEIF "$(CFG)" == "minigzip - Win32 DLL ASM Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "minigzip___Win32_DLL_ASM_Release" +# PROP BASE Intermediate_Dir "minigzip___Win32_DLL_ASM_Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Win32_DLL_ASM_Release" +# PROP Intermediate_Dir "Win32_DLL_ASM_Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c +# SUBTRACT BASE CPP /YX +# ADD CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c +# SUBTRACT CPP /YX +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 /nologo /subsystem:console /machine:I386 + +!ELSEIF "$(CFG)" == "minigzip - Win32 DLL ASM Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "minigzip___Win32_DLL_ASM_Debug" +# PROP BASE Intermediate_Dir "minigzip___Win32_DLL_ASM_Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Win32_DLL_ASM_Debug" +# PROP Intermediate_Dir "Win32_DLL_ASM_Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c +# SUBTRACT BASE CPP /YX +# ADD CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c +# SUBTRACT CPP /YX +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept + +!ELSEIF "$(CFG)" == "minigzip - Win32 LIB Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "minigzip___Win32_LIB_Release" +# PROP BASE Intermediate_Dir "minigzip___Win32_LIB_Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Win32_LIB_Release" +# PROP Intermediate_Dir "Win32_LIB_Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c +# SUBTRACT BASE CPP /YX +# ADD CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c +# SUBTRACT CPP /YX +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 /nologo /subsystem:console /machine:I386 + +!ELSEIF "$(CFG)" == "minigzip - Win32 LIB Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "minigzip___Win32_LIB_Debug" +# PROP BASE Intermediate_Dir "minigzip___Win32_LIB_Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Win32_LIB_Debug" +# PROP Intermediate_Dir "Win32_LIB_Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c +# SUBTRACT BASE CPP /YX +# ADD CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c +# SUBTRACT CPP /YX +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept + +!ELSEIF "$(CFG)" == "minigzip - Win32 LIB ASM Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "minigzip___Win32_LIB_ASM_Release" +# PROP BASE Intermediate_Dir "minigzip___Win32_LIB_ASM_Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Win32_LIB_ASM_Release" +# PROP Intermediate_Dir "Win32_LIB_ASM_Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c +# SUBTRACT BASE CPP /YX +# ADD CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c +# SUBTRACT CPP /YX +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 /nologo /subsystem:console /machine:I386 + +!ELSEIF "$(CFG)" == "minigzip - Win32 LIB ASM Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "minigzip___Win32_LIB_ASM_Debug" +# PROP BASE Intermediate_Dir "minigzip___Win32_LIB_ASM_Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Win32_LIB_ASM_Debug" +# PROP Intermediate_Dir "Win32_LIB_ASM_Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c +# SUBTRACT BASE CPP /YX +# ADD CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c +# SUBTRACT CPP /YX +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept + +!ENDIF + +# Begin Target + +# Name "minigzip - Win32 DLL Release" +# Name "minigzip - Win32 DLL Debug" +# Name "minigzip - Win32 DLL ASM Release" +# Name "minigzip - Win32 DLL ASM Debug" +# Name "minigzip - Win32 LIB Release" +# Name "minigzip - Win32 LIB Debug" +# Name "minigzip - Win32 LIB ASM Release" +# Name "minigzip - Win32 LIB ASM Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=..\..\minigzip.c +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# Begin Source File + +SOURCE=..\..\zconf.h +# End Source File +# Begin Source File + +SOURCE=..\..\zlib.h +# End Source File +# End Group +# End Target +# End Project diff --git a/libs/zlib/projects/visualc6/zlib.dsp b/libs/zlib/projects/visualc6/zlib.dsp new file mode 100644 index 000000000..ec69eae83 --- /dev/null +++ b/libs/zlib/projects/visualc6/zlib.dsp @@ -0,0 +1,283 @@ +# Microsoft Developer Studio Project File - Name="zlib" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Static Library" 0x0104 + +CFG=zlib - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "zlib.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "zlib.mak" CFG="zlib - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "zlib - Win32 Release" (based on "Win32 (x86) Static Library") +!MESSAGE "zlib - Win32 Debug" (based on "Win32 (x86) Static Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "zlib - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "zlib___Win32_LIB_ASM_Release" +# PROP BASE Intermediate_Dir "zlib___Win32_LIB_ASM_Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Win32_LIB_ASM_Release" +# PROP Intermediate_Dir "Win32_LIB_ASM_Release" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c +# SUBTRACT BASE CPP /YX /Yc /Yu +# ADD CPP /nologo /W3 /O2 /D "WIN32" /D "NDEBUG" /D "ASMV" /D "ASMINF" /FD /c +# SUBTRACT CPP /YX /Yc /Yu +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LIB32=link.exe -lib +# ADD BASE LIB32 /nologo +# ADD LIB32 /nologo + +!ELSEIF "$(CFG)" == "zlib - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "zlib___Win32_LIB_ASM_Debug" +# PROP BASE Intermediate_Dir "zlib___Win32_LIB_ASM_Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Win32_LIB_ASM_Debug" +# PROP Intermediate_Dir "Win32_LIB_ASM_Debug" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c +# SUBTRACT BASE CPP /YX /Yc /Yu +# ADD CPP /nologo /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /D "ASMV" /D "ASMINF" /FD /GZ /c +# SUBTRACT CPP /YX /Yc /Yu +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LIB32=link.exe -lib +# ADD BASE LIB32 /nologo +# ADD LIB32 /nologo + +!ENDIF + +# Begin Target + +# Name "zlib - Win32 Release" +# Name "zlib - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=..\..\adler32.c +# End Source File +# Begin Source File + +SOURCE=..\..\compress.c +# End Source File +# Begin Source File + +SOURCE=..\..\crc32.c +# End Source File +# Begin Source File + +SOURCE=..\..\deflate.c +# End Source File +# Begin Source File + +SOURCE=..\..\gzclose.c +# End Source File +# Begin Source File + +SOURCE=..\..\gzlib.c +# End Source File +# Begin Source File + +SOURCE=..\..\gzread.c +# End Source File +# Begin Source File + +SOURCE=..\..\gzwrite.c +# End Source File +# Begin Source File + +SOURCE=..\..\infback.c +# End Source File +# Begin Source File + +SOURCE=..\..\inffast.c +# End Source File +# Begin Source File + +SOURCE=..\..\inflate.c +# End Source File +# Begin Source File + +SOURCE=..\..\inftrees.c +# End Source File +# Begin Source File + +SOURCE=..\..\trees.c +# End Source File +# Begin Source File + +SOURCE=..\..\uncompr.c +# End Source File +# Begin Source File + +SOURCE=..\..\win32\zlib.def +# PROP Exclude_From_Build 1 +# End Source File +# Begin Source File + +SOURCE=..\..\zutil.c +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# Begin Source File + +SOURCE=..\..\crc32.h +# End Source File +# Begin Source File + +SOURCE=..\..\deflate.h +# End Source File +# Begin Source File + +SOURCE=..\..\gzguts.h +# End Source File +# Begin Source File + +SOURCE=..\..\inffast.h +# End Source File +# Begin Source File + +SOURCE=..\..\inffixed.h +# End Source File +# Begin Source File + +SOURCE=..\..\inflate.h +# End Source File +# Begin Source File + +SOURCE=..\..\inftrees.h +# End Source File +# Begin Source File + +SOURCE=..\..\trees.h +# End Source File +# Begin Source File + +SOURCE=..\..\zconf.h +# End Source File +# Begin Source File + +SOURCE=..\..\zlib.h +# End Source File +# Begin Source File + +SOURCE=..\..\zutil.h +# End Source File +# End Group +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# Begin Source File + +SOURCE=..\..\win32\zlib1.rc +# End Source File +# End Group +# Begin Group "Assembler Files (Unsupported)" + +# PROP Default_Filter "asm;obj;c;cpp;cxx;h;hpp;hxx" +# Begin Source File + +SOURCE=..\..\contrib\masmx86\match686.asm + +!IF "$(CFG)" == "zlib - Win32 Release" + +# Begin Custom Build - Assembling... +IntDir=.\Win32_LIB_ASM_Release +InputPath=..\..\contrib\masmx86\match686.asm +InputName=gvmat32 + +"$(IntDir)\$(InputName).obj" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + ml.exe /nologo /c /coff /Cx /Fo"$(IntDir)\$(InputName).obj" "$(InputPath)" + +# End Custom Build + +!ELSEIF "$(CFG)" == "zlib - Win32 Debug" + +# Begin Custom Build - Assembling... +IntDir=.\Win32_LIB_ASM_Debug +InputPath=..\..\contrib\masmx86\match686.asm +InputName=gvmat32 + +"$(IntDir)\$(InputName).obj" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + ml.exe /nologo /c /coff /Cx /Zi /Fo"$(IntDir)\$(InputName).obj" "$(InputPath)" + +# End Custom Build + +!ENDIF + +# End Source File +# Begin Source File + +SOURCE=..\..\contrib\masmx86\inffas32.asm + +!IF "$(CFG)" == "zlib - Win32 Release" + +# Begin Custom Build - Assembling... +IntDir=.\Win32_LIB_ASM_Release +InputPath=..\..\contrib\masmx86\inffas32.asm +InputName=inffas32 + +"$(IntDir)\$(InputName).obj" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + ml.exe /nologo /c /coff /Cx /Fo"$(IntDir)\$(InputName).obj" "$(InputPath)" + +# End Custom Build + +!ELSEIF "$(CFG)" == "zlib - Win32 Debug" + +# Begin Custom Build - Assembling... +IntDir=.\Win32_LIB_ASM_Debug +InputPath=..\..\contrib\masmx86\inffas32.asm +InputName=inffas32 + +"$(IntDir)\$(InputName).obj" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + ml.exe /nologo /c /coff /Cx /Zi /Fo"$(IntDir)\$(InputName).obj" "$(InputPath)" + +# End Custom Build + +!ENDIF + +# End Source File +# End Group +# Begin Source File + +SOURCE=.\README.txt +# End Source File +# End Target +# End Project diff --git a/libs/zlib/projects/visualc6/zlib.dsw b/libs/zlib/projects/visualc6/zlib.dsw new file mode 100644 index 000000000..3a771fce0 --- /dev/null +++ b/libs/zlib/projects/visualc6/zlib.dsw @@ -0,0 +1,59 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00 +# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! + +############################################################################### + +Project: "example"=.\example.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ + Begin Project Dependency + Project_Dep_Name zlib + End Project Dependency +}}} + +############################################################################### + +Project: "minigzip"=.\minigzip.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ + Begin Project Dependency + Project_Dep_Name zlib + End Project Dependency +}}} + +############################################################################### + +Project: "zlib"=.\zlib.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/libs/zlib/projects/visualc9/.gitignore b/libs/zlib/projects/visualc9/.gitignore new file mode 100644 index 000000000..488a5428b --- /dev/null +++ b/libs/zlib/projects/visualc9/.gitignore @@ -0,0 +1,3 @@ +/Win32 +/x64 +/zlib.vcproj.*.*.user diff --git a/libs/zlib/projects/visualc9/zlib.vcproj b/libs/zlib/projects/visualc9/zlib.vcproj new file mode 100644 index 000000000..cb1cb119d --- /dev/null +++ b/libs/zlib/projects/visualc9/zlib.vcproj @@ -0,0 +1,1056 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/zlib/qnx/package.qpg b/libs/zlib/qnx/package.qpg new file mode 100644 index 000000000..2bc63b21a --- /dev/null +++ b/libs/zlib/qnx/package.qpg @@ -0,0 +1,141 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Library + + Medium + + 2.0 + + + + zlib + zlib + alain.bonnefoy@icbt.com + Public + public + www.gzip.org/zlib + + + Jean-Loup Gailly,Mark Adler + www.gzip.org/zlib + + zlib@gzip.org + + + A massively spiffy yet delicately unobtrusive compression library. + zlib is designed to be a free, general-purpose, legally unencumbered, lossless data compression library for use on virtually any computer hardware and operating system. + http://www.gzip.org/zlib + + + + + 1.2.5 + Medium + Stable + + + + + + + No License + + + + Software Development/Libraries and Extensions/C Libraries + zlib,compression + qnx6 + qnx6 + None + Developer + + + + + + + + + + + + + + Install + Post + No + Ignore + + No + Optional + + + + + + + + + + + + + InstallOver + zlib + + + + + + + + + + + + + InstallOver + zlib-dev + + + + + + + + + diff --git a/libs/zlib/treebuild.xml b/libs/zlib/treebuild.xml new file mode 100644 index 000000000..89963a0ce --- /dev/null +++ b/libs/zlib/treebuild.xml @@ -0,0 +1,116 @@ + + + + zip compression library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/zlib/trees.c b/libs/zlib/trees.c new file mode 100644 index 000000000..8c32b214b --- /dev/null +++ b/libs/zlib/trees.c @@ -0,0 +1,1224 @@ +/* trees.c -- output deflated data using Huffman coding + * Copyright (C) 1995-2012 Jean-loup Gailly + * detect_data_type() function provided freely by Cosmin Truta, 2006 + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* + * ALGORITHM + * + * The "deflation" process uses several Huffman trees. The more + * common source values are represented by shorter bit sequences. + * + * Each code tree is stored in a compressed form which is itself + * a Huffman encoding of the lengths of all the code strings (in + * ascending order by source values). The actual code strings are + * reconstructed from the lengths in the inflate process, as described + * in the deflate specification. + * + * REFERENCES + * + * Deutsch, L.P.,"'Deflate' Compressed Data Format Specification". + * Available in ftp.uu.net:/pub/archiving/zip/doc/deflate-1.1.doc + * + * Storer, James A. + * Data Compression: Methods and Theory, pp. 49-50. + * Computer Science Press, 1988. ISBN 0-7167-8156-5. + * + * Sedgewick, R. + * Algorithms, p290. + * Addison-Wesley, 1983. ISBN 0-201-06672-6. + */ + +/* @(#) $Id$ */ + +/* #define GEN_TREES_H */ + +#include "deflate.h" + +#ifdef DEBUG +# include +#endif + +/* =========================================================================== + * Constants + */ + +#define MAX_BL_BITS 7 +/* Bit length codes must not exceed MAX_BL_BITS bits */ + +#define END_BLOCK 256 +/* end of block literal code */ + +#define REP_3_6 16 +/* repeat previous bit length 3-6 times (2 bits of repeat count) */ + +#define REPZ_3_10 17 +/* repeat a zero length 3-10 times (3 bits of repeat count) */ + +#define REPZ_11_138 18 +/* repeat a zero length 11-138 times (7 bits of repeat count) */ + +local const int extra_lbits[LENGTH_CODES] /* extra bits for each length code */ + = {0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0}; + +local const int extra_dbits[D_CODES] /* extra bits for each distance code */ + = {0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13}; + +local const int extra_blbits[BL_CODES]/* extra bits for each bit length code */ + = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7}; + +local const uch bl_order[BL_CODES] + = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15}; +/* The lengths of the bit length codes are sent in order of decreasing + * probability, to avoid transmitting the lengths for unused bit length codes. + */ + +/* =========================================================================== + * Local data. These are initialized only once. + */ + +#define DIST_CODE_LEN 512 /* see definition of array dist_code below */ + +#if defined(GEN_TREES_H) || !defined(STDC) +/* non ANSI compilers may not accept trees.h */ + +local ct_data static_ltree[L_CODES+2]; +/* The static literal tree. Since the bit lengths are imposed, there is no + * need for the L_CODES extra codes used during heap construction. However + * The codes 286 and 287 are needed to build a canonical tree (see _tr_init + * below). + */ + +local ct_data static_dtree[D_CODES]; +/* The static distance tree. (Actually a trivial tree since all codes use + * 5 bits.) + */ + +uch _dist_code[DIST_CODE_LEN]; +/* Distance codes. The first 256 values correspond to the distances + * 3 .. 258, the last 256 values correspond to the top 8 bits of + * the 15 bit distances. + */ + +uch _length_code[MAX_MATCH-MIN_MATCH+1]; +/* length code for each normalized match length (0 == MIN_MATCH) */ + +local int base_length[LENGTH_CODES]; +/* First normalized length for each code (0 = MIN_MATCH) */ + +local int base_dist[D_CODES]; +/* First normalized distance for each code (0 = distance of 1) */ + +#else +# include "trees.h" +#endif /* GEN_TREES_H */ + +struct static_tree_desc_s { + const ct_data *static_tree; /* static tree or NULL */ + const intf *extra_bits; /* extra bits for each code or NULL */ + int extra_base; /* base index for extra_bits */ + int elems; /* max number of elements in the tree */ + int max_length; /* max bit length for the codes */ +}; + +local static_tree_desc static_l_desc = +{static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS}; + +local static_tree_desc static_d_desc = +{static_dtree, extra_dbits, 0, D_CODES, MAX_BITS}; + +local static_tree_desc static_bl_desc = +{(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS}; + +/* =========================================================================== + * Local (static) routines in this file. + */ + +local void tr_static_init OF((void)); +local void init_block OF((deflate_state *s)); +local void pqdownheap OF((deflate_state *s, ct_data *tree, int k)); +local void gen_bitlen OF((deflate_state *s, tree_desc *desc)); +local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count)); +local void build_tree OF((deflate_state *s, tree_desc *desc)); +local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code)); +local void send_tree OF((deflate_state *s, ct_data *tree, int max_code)); +local int build_bl_tree OF((deflate_state *s)); +local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes, + int blcodes)); +local void compress_block OF((deflate_state *s, ct_data *ltree, + ct_data *dtree)); +local int detect_data_type OF((deflate_state *s)); +local unsigned bi_reverse OF((unsigned value, int length)); +local void bi_windup OF((deflate_state *s)); +local void bi_flush OF((deflate_state *s)); +local void copy_block OF((deflate_state *s, charf *buf, unsigned len, + int header)); + +#ifdef GEN_TREES_H +local void gen_trees_header OF((void)); +#endif + +#ifndef DEBUG +# define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len) + /* Send a code of the given tree. c and tree must not have side effects */ + +#else /* DEBUG */ +# define send_code(s, c, tree) \ + { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \ + send_bits(s, tree[c].Code, tree[c].Len); } +#endif + +/* =========================================================================== + * Output a short LSB first on the stream. + * IN assertion: there is enough room in pendingBuf. + */ +#define put_short(s, w) { \ + put_byte(s, (uch)((w) & 0xff)); \ + put_byte(s, (uch)((ush)(w) >> 8)); \ +} + +/* =========================================================================== + * Send a value on a given number of bits. + * IN assertion: length <= 16 and value fits in length bits. + */ +#ifdef DEBUG +local void send_bits OF((deflate_state *s, int value, int length)); + +local void send_bits(s, value, length) + deflate_state *s; + int value; /* value to send */ + int length; /* number of bits */ +{ + Tracevv((stderr," l %2d v %4x ", length, value)); + Assert(length > 0 && length <= 15, "invalid length"); + s->bits_sent += (ulg)length; + + /* If not enough room in bi_buf, use (valid) bits from bi_buf and + * (16 - bi_valid) bits from value, leaving (width - (16-bi_valid)) + * unused bits in value. + */ + if (s->bi_valid > (int)Buf_size - length) { + s->bi_buf |= (ush)value << s->bi_valid; + put_short(s, s->bi_buf); + s->bi_buf = (ush)value >> (Buf_size - s->bi_valid); + s->bi_valid += length - Buf_size; + } else { + s->bi_buf |= (ush)value << s->bi_valid; + s->bi_valid += length; + } +} +#else /* !DEBUG */ + +#define send_bits(s, value, length) \ +{ int len = length;\ + if (s->bi_valid > (int)Buf_size - len) {\ + int val = value;\ + s->bi_buf |= (ush)val << s->bi_valid;\ + put_short(s, s->bi_buf);\ + s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\ + s->bi_valid += len - Buf_size;\ + } else {\ + s->bi_buf |= (ush)(value) << s->bi_valid;\ + s->bi_valid += len;\ + }\ +} +#endif /* DEBUG */ + + +/* the arguments must not have side effects */ + +/* =========================================================================== + * Initialize the various 'constant' tables. + */ +local void tr_static_init() +{ +#if defined(GEN_TREES_H) || !defined(STDC) + static int static_init_done = 0; + int n; /* iterates over tree elements */ + int bits; /* bit counter */ + int length; /* length value */ + int code; /* code value */ + int dist; /* distance index */ + ush bl_count[MAX_BITS+1]; + /* number of codes at each bit length for an optimal tree */ + + if (static_init_done) return; + + /* For some embedded targets, global variables are not initialized: */ +#ifdef NO_INIT_GLOBAL_POINTERS + static_l_desc.static_tree = static_ltree; + static_l_desc.extra_bits = extra_lbits; + static_d_desc.static_tree = static_dtree; + static_d_desc.extra_bits = extra_dbits; + static_bl_desc.extra_bits = extra_blbits; +#endif + + /* Initialize the mapping length (0..255) -> length code (0..28) */ + length = 0; + for (code = 0; code < LENGTH_CODES-1; code++) { + base_length[code] = length; + for (n = 0; n < (1< dist code (0..29) */ + dist = 0; + for (code = 0 ; code < 16; code++) { + base_dist[code] = dist; + for (n = 0; n < (1<>= 7; /* from now on, all distances are divided by 128 */ + for ( ; code < D_CODES; code++) { + base_dist[code] = dist << 7; + for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) { + _dist_code[256 + dist++] = (uch)code; + } + } + Assert (dist == 256, "tr_static_init: 256+dist != 512"); + + /* Construct the codes of the static literal tree */ + for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0; + n = 0; + while (n <= 143) static_ltree[n++].Len = 8, bl_count[8]++; + while (n <= 255) static_ltree[n++].Len = 9, bl_count[9]++; + while (n <= 279) static_ltree[n++].Len = 7, bl_count[7]++; + while (n <= 287) static_ltree[n++].Len = 8, bl_count[8]++; + /* Codes 286 and 287 do not exist, but we must include them in the + * tree construction to get a canonical Huffman tree (longest code + * all ones) + */ + gen_codes((ct_data *)static_ltree, L_CODES+1, bl_count); + + /* The static distance tree is trivial: */ + for (n = 0; n < D_CODES; n++) { + static_dtree[n].Len = 5; + static_dtree[n].Code = bi_reverse((unsigned)n, 5); + } + static_init_done = 1; + +# ifdef GEN_TREES_H + gen_trees_header(); +# endif +#endif /* defined(GEN_TREES_H) || !defined(STDC) */ +} + +/* =========================================================================== + * Genererate the file trees.h describing the static trees. + */ +#ifdef GEN_TREES_H +# ifndef DEBUG +# include +# endif + +# define SEPARATOR(i, last, width) \ + ((i) == (last)? "\n};\n\n" : \ + ((i) % (width) == (width)-1 ? ",\n" : ", ")) + +void gen_trees_header() +{ + FILE *header = fopen("trees.h", "w"); + int i; + + Assert (header != NULL, "Can't open trees.h"); + fprintf(header, + "/* header created automatically with -DGEN_TREES_H */\n\n"); + + fprintf(header, "local const ct_data static_ltree[L_CODES+2] = {\n"); + for (i = 0; i < L_CODES+2; i++) { + fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code, + static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5)); + } + + fprintf(header, "local const ct_data static_dtree[D_CODES] = {\n"); + for (i = 0; i < D_CODES; i++) { + fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code, + static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5)); + } + + fprintf(header, "const uch ZLIB_INTERNAL _dist_code[DIST_CODE_LEN] = {\n"); + for (i = 0; i < DIST_CODE_LEN; i++) { + fprintf(header, "%2u%s", _dist_code[i], + SEPARATOR(i, DIST_CODE_LEN-1, 20)); + } + + fprintf(header, + "const uch ZLIB_INTERNAL _length_code[MAX_MATCH-MIN_MATCH+1]= {\n"); + for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) { + fprintf(header, "%2u%s", _length_code[i], + SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20)); + } + + fprintf(header, "local const int base_length[LENGTH_CODES] = {\n"); + for (i = 0; i < LENGTH_CODES; i++) { + fprintf(header, "%1u%s", base_length[i], + SEPARATOR(i, LENGTH_CODES-1, 20)); + } + + fprintf(header, "local const int base_dist[D_CODES] = {\n"); + for (i = 0; i < D_CODES; i++) { + fprintf(header, "%5u%s", base_dist[i], + SEPARATOR(i, D_CODES-1, 10)); + } + + fclose(header); +} +#endif /* GEN_TREES_H */ + +/* =========================================================================== + * Initialize the tree data structures for a new zlib stream. + */ +void ZLIB_INTERNAL _tr_init(s) + deflate_state *s; +{ + tr_static_init(); + + s->l_desc.dyn_tree = s->dyn_ltree; + s->l_desc.stat_desc = &static_l_desc; + + s->d_desc.dyn_tree = s->dyn_dtree; + s->d_desc.stat_desc = &static_d_desc; + + s->bl_desc.dyn_tree = s->bl_tree; + s->bl_desc.stat_desc = &static_bl_desc; + + s->bi_buf = 0; + s->bi_valid = 0; +#ifdef DEBUG + s->compressed_len = 0L; + s->bits_sent = 0L; +#endif + + /* Initialize the first block of the first file: */ + init_block(s); +} + +/* =========================================================================== + * Initialize a new block. + */ +local void init_block(s) + deflate_state *s; +{ + int n; /* iterates over tree elements */ + + /* Initialize the trees. */ + for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0; + for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0; + for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0; + + s->dyn_ltree[END_BLOCK].Freq = 1; + s->opt_len = s->static_len = 0L; + s->last_lit = s->matches = 0; +} + +#define SMALLEST 1 +/* Index within the heap array of least frequent node in the Huffman tree */ + + +/* =========================================================================== + * Remove the smallest element from the heap and recreate the heap with + * one less element. Updates heap and heap_len. + */ +#define pqremove(s, tree, top) \ +{\ + top = s->heap[SMALLEST]; \ + s->heap[SMALLEST] = s->heap[s->heap_len--]; \ + pqdownheap(s, tree, SMALLEST); \ +} + +/* =========================================================================== + * Compares to subtrees, using the tree depth as tie breaker when + * the subtrees have equal frequency. This minimizes the worst case length. + */ +#define smaller(tree, n, m, depth) \ + (tree[n].Freq < tree[m].Freq || \ + (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m])) + +/* =========================================================================== + * Restore the heap property by moving down the tree starting at node k, + * exchanging a node with the smallest of its two sons if necessary, stopping + * when the heap property is re-established (each father smaller than its + * two sons). + */ +local void pqdownheap(s, tree, k) + deflate_state *s; + ct_data *tree; /* the tree to restore */ + int k; /* node to move down */ +{ + int v = s->heap[k]; + int j = k << 1; /* left son of k */ + while (j <= s->heap_len) { + /* Set j to the smallest of the two sons: */ + if (j < s->heap_len && + smaller(tree, s->heap[j+1], s->heap[j], s->depth)) { + j++; + } + /* Exit if v is smaller than both sons */ + if (smaller(tree, v, s->heap[j], s->depth)) break; + + /* Exchange v with the smallest son */ + s->heap[k] = s->heap[j]; k = j; + + /* And continue down the tree, setting j to the left son of k */ + j <<= 1; + } + s->heap[k] = v; +} + +/* =========================================================================== + * Compute the optimal bit lengths for a tree and update the total bit length + * for the current block. + * IN assertion: the fields freq and dad are set, heap[heap_max] and + * above are the tree nodes sorted by increasing frequency. + * OUT assertions: the field len is set to the optimal bit length, the + * array bl_count contains the frequencies for each bit length. + * The length opt_len is updated; static_len is also updated if stree is + * not null. + */ +local void gen_bitlen(s, desc) + deflate_state *s; + tree_desc *desc; /* the tree descriptor */ +{ + ct_data *tree = desc->dyn_tree; + int max_code = desc->max_code; + const ct_data *stree = desc->stat_desc->static_tree; + const intf *extra = desc->stat_desc->extra_bits; + int base = desc->stat_desc->extra_base; + int max_length = desc->stat_desc->max_length; + int h; /* heap index */ + int n, m; /* iterate over the tree elements */ + int bits; /* bit length */ + int xbits; /* extra bits */ + ush f; /* frequency */ + int overflow = 0; /* number of elements with bit length too large */ + + for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0; + + /* In a first pass, compute the optimal bit lengths (which may + * overflow in the case of the bit length tree). + */ + tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */ + + for (h = s->heap_max+1; h < HEAP_SIZE; h++) { + n = s->heap[h]; + bits = tree[tree[n].Dad].Len + 1; + if (bits > max_length) bits = max_length, overflow++; + tree[n].Len = (ush)bits; + /* We overwrite tree[n].Dad which is no longer needed */ + + if (n > max_code) continue; /* not a leaf node */ + + s->bl_count[bits]++; + xbits = 0; + if (n >= base) xbits = extra[n-base]; + f = tree[n].Freq; + s->opt_len += (ulg)f * (bits + xbits); + if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits); + } + if (overflow == 0) return; + + Trace((stderr,"\nbit length overflow\n")); + /* This happens for example on obj2 and pic of the Calgary corpus */ + + /* Find the first bit length which could increase: */ + do { + bits = max_length-1; + while (s->bl_count[bits] == 0) bits--; + s->bl_count[bits]--; /* move one leaf down the tree */ + s->bl_count[bits+1] += 2; /* move one overflow item as its brother */ + s->bl_count[max_length]--; + /* The brother of the overflow item also moves one step up, + * but this does not affect bl_count[max_length] + */ + overflow -= 2; + } while (overflow > 0); + + /* Now recompute all bit lengths, scanning in increasing frequency. + * h is still equal to HEAP_SIZE. (It is simpler to reconstruct all + * lengths instead of fixing only the wrong ones. This idea is taken + * from 'ar' written by Haruhiko Okumura.) + */ + for (bits = max_length; bits != 0; bits--) { + n = s->bl_count[bits]; + while (n != 0) { + m = s->heap[--h]; + if (m > max_code) continue; + if ((unsigned) tree[m].Len != (unsigned) bits) { + Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits)); + s->opt_len += ((long)bits - (long)tree[m].Len) + *(long)tree[m].Freq; + tree[m].Len = (ush)bits; + } + n--; + } + } +} + +/* =========================================================================== + * Generate the codes for a given tree and bit counts (which need not be + * optimal). + * IN assertion: the array bl_count contains the bit length statistics for + * the given tree and the field len is set for all tree elements. + * OUT assertion: the field code is set for all tree elements of non + * zero code length. + */ +local void gen_codes (tree, max_code, bl_count) + ct_data *tree; /* the tree to decorate */ + int max_code; /* largest code with non zero frequency */ + ushf *bl_count; /* number of codes at each bit length */ +{ + ush next_code[MAX_BITS+1]; /* next code value for each bit length */ + ush code = 0; /* running code value */ + int bits; /* bit index */ + int n; /* code index */ + + /* The distribution counts are first used to generate the code values + * without bit reversal. + */ + for (bits = 1; bits <= MAX_BITS; bits++) { + next_code[bits] = code = (code + bl_count[bits-1]) << 1; + } + /* Check that the bit counts in bl_count are consistent. The last code + * must be all ones. + */ + Assert (code + bl_count[MAX_BITS]-1 == (1<dyn_tree; + const ct_data *stree = desc->stat_desc->static_tree; + int elems = desc->stat_desc->elems; + int n, m; /* iterate over heap elements */ + int max_code = -1; /* largest code with non zero frequency */ + int node; /* new node being created */ + + /* Construct the initial heap, with least frequent element in + * heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n+1]. + * heap[0] is not used. + */ + s->heap_len = 0, s->heap_max = HEAP_SIZE; + + for (n = 0; n < elems; n++) { + if (tree[n].Freq != 0) { + s->heap[++(s->heap_len)] = max_code = n; + s->depth[n] = 0; + } else { + tree[n].Len = 0; + } + } + + /* The pkzip format requires that at least one distance code exists, + * and that at least one bit should be sent even if there is only one + * possible code. So to avoid special checks later on we force at least + * two codes of non zero frequency. + */ + while (s->heap_len < 2) { + node = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0); + tree[node].Freq = 1; + s->depth[node] = 0; + s->opt_len--; if (stree) s->static_len -= stree[node].Len; + /* node is 0 or 1 so it does not have extra bits */ + } + desc->max_code = max_code; + + /* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree, + * establish sub-heaps of increasing lengths: + */ + for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n); + + /* Construct the Huffman tree by repeatedly combining the least two + * frequent nodes. + */ + node = elems; /* next internal node of the tree */ + do { + pqremove(s, tree, n); /* n = node of least frequency */ + m = s->heap[SMALLEST]; /* m = node of next least frequency */ + + s->heap[--(s->heap_max)] = n; /* keep the nodes sorted by frequency */ + s->heap[--(s->heap_max)] = m; + + /* Create a new node father of n and m */ + tree[node].Freq = tree[n].Freq + tree[m].Freq; + s->depth[node] = (uch)((s->depth[n] >= s->depth[m] ? + s->depth[n] : s->depth[m]) + 1); + tree[n].Dad = tree[m].Dad = (ush)node; +#ifdef DUMP_BL_TREE + if (tree == s->bl_tree) { + fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)", + node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq); + } +#endif + /* and insert the new node in the heap */ + s->heap[SMALLEST] = node++; + pqdownheap(s, tree, SMALLEST); + + } while (s->heap_len >= 2); + + s->heap[--(s->heap_max)] = s->heap[SMALLEST]; + + /* At this point, the fields freq and dad are set. We can now + * generate the bit lengths. + */ + gen_bitlen(s, (tree_desc *)desc); + + /* The field len is now set, we can generate the bit codes */ + gen_codes ((ct_data *)tree, max_code, s->bl_count); +} + +/* =========================================================================== + * Scan a literal or distance tree to determine the frequencies of the codes + * in the bit length tree. + */ +local void scan_tree (s, tree, max_code) + deflate_state *s; + ct_data *tree; /* the tree to be scanned */ + int max_code; /* and its largest code of non zero frequency */ +{ + int n; /* iterates over all tree elements */ + int prevlen = -1; /* last emitted length */ + int curlen; /* length of current code */ + int nextlen = tree[0].Len; /* length of next code */ + int count = 0; /* repeat count of the current code */ + int max_count = 7; /* max repeat count */ + int min_count = 4; /* min repeat count */ + + if (nextlen == 0) max_count = 138, min_count = 3; + tree[max_code+1].Len = (ush)0xffff; /* guard */ + + for (n = 0; n <= max_code; n++) { + curlen = nextlen; nextlen = tree[n+1].Len; + if (++count < max_count && curlen == nextlen) { + continue; + } else if (count < min_count) { + s->bl_tree[curlen].Freq += count; + } else if (curlen != 0) { + if (curlen != prevlen) s->bl_tree[curlen].Freq++; + s->bl_tree[REP_3_6].Freq++; + } else if (count <= 10) { + s->bl_tree[REPZ_3_10].Freq++; + } else { + s->bl_tree[REPZ_11_138].Freq++; + } + count = 0; prevlen = curlen; + if (nextlen == 0) { + max_count = 138, min_count = 3; + } else if (curlen == nextlen) { + max_count = 6, min_count = 3; + } else { + max_count = 7, min_count = 4; + } + } +} + +/* =========================================================================== + * Send a literal or distance tree in compressed form, using the codes in + * bl_tree. + */ +local void send_tree (s, tree, max_code) + deflate_state *s; + ct_data *tree; /* the tree to be scanned */ + int max_code; /* and its largest code of non zero frequency */ +{ + int n; /* iterates over all tree elements */ + int prevlen = -1; /* last emitted length */ + int curlen; /* length of current code */ + int nextlen = tree[0].Len; /* length of next code */ + int count = 0; /* repeat count of the current code */ + int max_count = 7; /* max repeat count */ + int min_count = 4; /* min repeat count */ + + /* tree[max_code+1].Len = -1; */ /* guard already set */ + if (nextlen == 0) max_count = 138, min_count = 3; + + for (n = 0; n <= max_code; n++) { + curlen = nextlen; nextlen = tree[n+1].Len; + if (++count < max_count && curlen == nextlen) { + continue; + } else if (count < min_count) { + do { send_code(s, curlen, s->bl_tree); } while (--count != 0); + + } else if (curlen != 0) { + if (curlen != prevlen) { + send_code(s, curlen, s->bl_tree); count--; + } + Assert(count >= 3 && count <= 6, " 3_6?"); + send_code(s, REP_3_6, s->bl_tree); send_bits(s, count-3, 2); + + } else if (count <= 10) { + send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count-3, 3); + + } else { + send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count-11, 7); + } + count = 0; prevlen = curlen; + if (nextlen == 0) { + max_count = 138, min_count = 3; + } else if (curlen == nextlen) { + max_count = 6, min_count = 3; + } else { + max_count = 7, min_count = 4; + } + } +} + +/* =========================================================================== + * Construct the Huffman tree for the bit lengths and return the index in + * bl_order of the last bit length code to send. + */ +local int build_bl_tree(s) + deflate_state *s; +{ + int max_blindex; /* index of last bit length code of non zero freq */ + + /* Determine the bit length frequencies for literal and distance trees */ + scan_tree(s, (ct_data *)s->dyn_ltree, s->l_desc.max_code); + scan_tree(s, (ct_data *)s->dyn_dtree, s->d_desc.max_code); + + /* Build the bit length tree: */ + build_tree(s, (tree_desc *)(&(s->bl_desc))); + /* opt_len now includes the length of the tree representations, except + * the lengths of the bit lengths codes and the 5+5+4 bits for the counts. + */ + + /* Determine the number of bit length codes to send. The pkzip format + * requires that at least 4 bit length codes be sent. (appnote.txt says + * 3 but the actual value used is 4.) + */ + for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) { + if (s->bl_tree[bl_order[max_blindex]].Len != 0) break; + } + /* Update opt_len to include the bit length tree and counts */ + s->opt_len += 3*(max_blindex+1) + 5+5+4; + Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld", + s->opt_len, s->static_len)); + + return max_blindex; +} + +/* =========================================================================== + * Send the header for a block using dynamic Huffman trees: the counts, the + * lengths of the bit length codes, the literal tree and the distance tree. + * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4. + */ +local void send_all_trees(s, lcodes, dcodes, blcodes) + deflate_state *s; + int lcodes, dcodes, blcodes; /* number of codes for each tree */ +{ + int rank; /* index in bl_order */ + + Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes"); + Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES, + "too many codes"); + Tracev((stderr, "\nbl counts: ")); + send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */ + send_bits(s, dcodes-1, 5); + send_bits(s, blcodes-4, 4); /* not -3 as stated in appnote.txt */ + for (rank = 0; rank < blcodes; rank++) { + Tracev((stderr, "\nbl code %2d ", bl_order[rank])); + send_bits(s, s->bl_tree[bl_order[rank]].Len, 3); + } + Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent)); + + send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */ + Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent)); + + send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */ + Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent)); +} + +/* =========================================================================== + * Send a stored block + */ +void ZLIB_INTERNAL _tr_stored_block(s, buf, stored_len, last) + deflate_state *s; + charf *buf; /* input block */ + ulg stored_len; /* length of input block */ + int last; /* one if this is the last block for a file */ +{ + send_bits(s, (STORED_BLOCK<<1)+last, 3); /* send block type */ +#ifdef DEBUG + s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L; + s->compressed_len += (stored_len + 4) << 3; +#endif + copy_block(s, buf, (unsigned)stored_len, 1); /* with header */ +} + +/* =========================================================================== + * Flush the bits in the bit buffer to pending output (leaves at most 7 bits) + */ +void ZLIB_INTERNAL _tr_flush_bits(s) + deflate_state *s; +{ + bi_flush(s); +} + +/* =========================================================================== + * Send one empty static block to give enough lookahead for inflate. + * This takes 10 bits, of which 7 may remain in the bit buffer. + */ +void ZLIB_INTERNAL _tr_align(s) + deflate_state *s; +{ + send_bits(s, STATIC_TREES<<1, 3); + send_code(s, END_BLOCK, static_ltree); +#ifdef DEBUG + s->compressed_len += 10L; /* 3 for block type, 7 for EOB */ +#endif + bi_flush(s); +} + +/* =========================================================================== + * Determine the best encoding for the current block: dynamic trees, static + * trees or store, and output the encoded block to the zip file. + */ +void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last) + deflate_state *s; + charf *buf; /* input block, or NULL if too old */ + ulg stored_len; /* length of input block */ + int last; /* one if this is the last block for a file */ +{ + ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */ + int max_blindex = 0; /* index of last bit length code of non zero freq */ + + /* Build the Huffman trees unless a stored block is forced */ + if (s->level > 0) { + + /* Check if the file is binary or text */ + if (s->strm->data_type == Z_UNKNOWN) + s->strm->data_type = detect_data_type(s); + + /* Construct the literal and distance trees */ + build_tree(s, (tree_desc *)(&(s->l_desc))); + Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len, + s->static_len)); + + build_tree(s, (tree_desc *)(&(s->d_desc))); + Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len, + s->static_len)); + /* At this point, opt_len and static_len are the total bit lengths of + * the compressed block data, excluding the tree representations. + */ + + /* Build the bit length tree for the above two trees, and get the index + * in bl_order of the last bit length code to send. + */ + max_blindex = build_bl_tree(s); + + /* Determine the best encoding. Compute the block lengths in bytes. */ + opt_lenb = (s->opt_len+3+7)>>3; + static_lenb = (s->static_len+3+7)>>3; + + Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ", + opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len, + s->last_lit)); + + if (static_lenb <= opt_lenb) opt_lenb = static_lenb; + + } else { + Assert(buf != (char*)0, "lost buf"); + opt_lenb = static_lenb = stored_len + 5; /* force a stored block */ + } + +#ifdef FORCE_STORED + if (buf != (char*)0) { /* force stored block */ +#else + if (stored_len+4 <= opt_lenb && buf != (char*)0) { + /* 4: two words for the lengths */ +#endif + /* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE. + * Otherwise we can't have processed more than WSIZE input bytes since + * the last block flush, because compression would have been + * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to + * transform a block into a stored block. + */ + _tr_stored_block(s, buf, stored_len, last); + +#ifdef FORCE_STATIC + } else if (static_lenb >= 0) { /* force static trees */ +#else + } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) { +#endif + send_bits(s, (STATIC_TREES<<1)+last, 3); + compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree); +#ifdef DEBUG + s->compressed_len += 3 + s->static_len; +#endif + } else { + send_bits(s, (DYN_TREES<<1)+last, 3); + send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1, + max_blindex+1); + compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree); +#ifdef DEBUG + s->compressed_len += 3 + s->opt_len; +#endif + } + Assert (s->compressed_len == s->bits_sent, "bad compressed size"); + /* The above check is made mod 2^32, for files larger than 512 MB + * and uLong implemented on 32 bits. + */ + init_block(s); + + if (last) { + bi_windup(s); +#ifdef DEBUG + s->compressed_len += 7; /* align on byte boundary */ +#endif + } + Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3, + s->compressed_len-7*last)); +} + +/* =========================================================================== + * Save the match info and tally the frequency counts. Return true if + * the current block must be flushed. + */ +int ZLIB_INTERNAL _tr_tally (s, dist, lc) + deflate_state *s; + unsigned dist; /* distance of matched string */ + unsigned lc; /* match length-MIN_MATCH or unmatched char (if dist==0) */ +{ + s->d_buf[s->last_lit] = (ush)dist; + s->l_buf[s->last_lit++] = (uch)lc; + if (dist == 0) { + /* lc is the unmatched char */ + s->dyn_ltree[lc].Freq++; + } else { + s->matches++; + /* Here, lc is the match length - MIN_MATCH */ + dist--; /* dist = match distance - 1 */ + Assert((ush)dist < (ush)MAX_DIST(s) && + (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) && + (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match"); + + s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++; + s->dyn_dtree[d_code(dist)].Freq++; + } + +#ifdef TRUNCATE_BLOCK + /* Try to guess if it is profitable to stop the current block here */ + if ((s->last_lit & 0x1fff) == 0 && s->level > 2) { + /* Compute an upper bound for the compressed length */ + ulg out_length = (ulg)s->last_lit*8L; + ulg in_length = (ulg)((long)s->strstart - s->block_start); + int dcode; + for (dcode = 0; dcode < D_CODES; dcode++) { + out_length += (ulg)s->dyn_dtree[dcode].Freq * + (5L+extra_dbits[dcode]); + } + out_length >>= 3; + Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ", + s->last_lit, in_length, out_length, + 100L - out_length*100L/in_length)); + if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1; + } +#endif + return (s->last_lit == s->lit_bufsize-1); + /* We avoid equality with lit_bufsize because of wraparound at 64K + * on 16 bit machines and because stored blocks are restricted to + * 64K-1 bytes. + */ +} + +/* =========================================================================== + * Send the block data compressed using the given Huffman trees + */ +local void compress_block(s, ltree, dtree) + deflate_state *s; + ct_data *ltree; /* literal tree */ + ct_data *dtree; /* distance tree */ +{ + unsigned dist; /* distance of matched string */ + int lc; /* match length or unmatched char (if dist == 0) */ + unsigned lx = 0; /* running index in l_buf */ + unsigned code; /* the code to send */ + int extra; /* number of extra bits to send */ + + if (s->last_lit != 0) do { + dist = s->d_buf[lx]; + lc = s->l_buf[lx++]; + if (dist == 0) { + send_code(s, lc, ltree); /* send a literal byte */ + Tracecv(isgraph(lc), (stderr," '%c' ", lc)); + } else { + /* Here, lc is the match length - MIN_MATCH */ + code = _length_code[lc]; + send_code(s, code+LITERALS+1, ltree); /* send the length code */ + extra = extra_lbits[code]; + if (extra != 0) { + lc -= base_length[code]; + send_bits(s, lc, extra); /* send the extra length bits */ + } + dist--; /* dist is now the match distance - 1 */ + code = d_code(dist); + Assert (code < D_CODES, "bad d_code"); + + send_code(s, code, dtree); /* send the distance code */ + extra = extra_dbits[code]; + if (extra != 0) { + dist -= base_dist[code]; + send_bits(s, dist, extra); /* send the extra distance bits */ + } + } /* literal or match pair ? */ + + /* Check that the overlay between pending_buf and d_buf+l_buf is ok: */ + Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx, + "pendingBuf overflow"); + + } while (lx < s->last_lit); + + send_code(s, END_BLOCK, ltree); +} + +/* =========================================================================== + * Check if the data type is TEXT or BINARY, using the following algorithm: + * - TEXT if the two conditions below are satisfied: + * a) There are no non-portable control characters belonging to the + * "black list" (0..6, 14..25, 28..31). + * b) There is at least one printable character belonging to the + * "white list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255). + * - BINARY otherwise. + * - The following partially-portable control characters form a + * "gray list" that is ignored in this detection algorithm: + * (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}). + * IN assertion: the fields Freq of dyn_ltree are set. + */ +local int detect_data_type(s) + deflate_state *s; +{ + /* black_mask is the bit mask of black-listed bytes + * set bits 0..6, 14..25, and 28..31 + * 0xf3ffc07f = binary 11110011111111111100000001111111 + */ + unsigned long black_mask = 0xf3ffc07fUL; + int n; + + /* Check for non-textual ("black-listed") bytes. */ + for (n = 0; n <= 31; n++, black_mask >>= 1) + if ((black_mask & 1) && (s->dyn_ltree[n].Freq != 0)) + return Z_BINARY; + + /* Check for textual ("white-listed") bytes. */ + if (s->dyn_ltree[9].Freq != 0 || s->dyn_ltree[10].Freq != 0 + || s->dyn_ltree[13].Freq != 0) + return Z_TEXT; + for (n = 32; n < LITERALS; n++) + if (s->dyn_ltree[n].Freq != 0) + return Z_TEXT; + + /* There are no "black-listed" or "white-listed" bytes: + * this stream either is empty or has tolerated ("gray-listed") bytes only. + */ + return Z_BINARY; +} + +/* =========================================================================== + * Reverse the first len bits of a code, using straightforward code (a faster + * method would use a table) + * IN assertion: 1 <= len <= 15 + */ +local unsigned bi_reverse(code, len) + unsigned code; /* the value to invert */ + int len; /* its bit length */ +{ + register unsigned res = 0; + do { + res |= code & 1; + code >>= 1, res <<= 1; + } while (--len > 0); + return res >> 1; +} + +/* =========================================================================== + * Flush the bit buffer, keeping at most 7 bits in it. + */ +local void bi_flush(s) + deflate_state *s; +{ + if (s->bi_valid == 16) { + put_short(s, s->bi_buf); + s->bi_buf = 0; + s->bi_valid = 0; + } else if (s->bi_valid >= 8) { + put_byte(s, (Byte)s->bi_buf); + s->bi_buf >>= 8; + s->bi_valid -= 8; + } +} + +/* =========================================================================== + * Flush the bit buffer and align the output on a byte boundary + */ +local void bi_windup(s) + deflate_state *s; +{ + if (s->bi_valid > 8) { + put_short(s, s->bi_buf); + } else if (s->bi_valid > 0) { + put_byte(s, (Byte)s->bi_buf); + } + s->bi_buf = 0; + s->bi_valid = 0; +#ifdef DEBUG + s->bits_sent = (s->bits_sent+7) & ~7; +#endif +} + +/* =========================================================================== + * Copy a stored block, storing first the length and its + * one's complement if requested. + */ +local void copy_block(s, buf, len, header) + deflate_state *s; + charf *buf; /* the input data */ + unsigned len; /* its length */ + int header; /* true if block header must be written */ +{ + bi_windup(s); /* align on byte boundary */ + + if (header) { + put_short(s, (ush)len); + put_short(s, (ush)~len); +#ifdef DEBUG + s->bits_sent += 2*16; +#endif + } +#ifdef DEBUG + s->bits_sent += (ulg)len<<3; +#endif + while (len--) { + put_byte(s, *buf++); + } +} diff --git a/libs/zlib/trees.h b/libs/zlib/trees.h new file mode 100644 index 000000000..d35639d82 --- /dev/null +++ b/libs/zlib/trees.h @@ -0,0 +1,128 @@ +/* header created automatically with -DGEN_TREES_H */ + +local const ct_data static_ltree[L_CODES+2] = { +{{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}}, +{{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}}, +{{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}}, +{{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}}, +{{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}}, +{{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}}, +{{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}}, +{{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}}, +{{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}}, +{{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}}, +{{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}}, +{{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}}, +{{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}}, +{{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}}, +{{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}}, +{{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}}, +{{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}}, +{{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}}, +{{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}}, +{{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}}, +{{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}}, +{{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}}, +{{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}}, +{{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}}, +{{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}}, +{{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}}, +{{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}}, +{{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}}, +{{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}}, +{{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}}, +{{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}}, +{{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}}, +{{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}}, +{{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}}, +{{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}}, +{{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}}, +{{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}}, +{{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}}, +{{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}}, +{{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}}, +{{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}}, +{{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}}, +{{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}}, +{{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}}, +{{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}}, +{{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}}, +{{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}}, +{{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}}, +{{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}}, +{{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}}, +{{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}}, +{{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}}, +{{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}}, +{{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}}, +{{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}}, +{{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}}, +{{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}}, +{{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}} +}; + +local const ct_data static_dtree[D_CODES] = { +{{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}}, +{{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}}, +{{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}}, +{{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}}, +{{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}}, +{{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}} +}; + +const uch ZLIB_INTERNAL _dist_code[DIST_CODE_LEN] = { + 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, + 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, +10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, +11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, +12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, +13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, +13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, +14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, +14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, +14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, +15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, +15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, +15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17, +18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, +23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, +24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, +26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, +26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, +27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, +27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, +28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, +28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, +28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, +29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, +29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, +29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29 +}; + +const uch ZLIB_INTERNAL _length_code[MAX_MATCH-MIN_MATCH+1]= { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12, +13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, +17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, +19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, +21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22, +22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23, +23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, +24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, +25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, +25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26, +26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, +26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, +27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28 +}; + +local const int base_length[LENGTH_CODES] = { +0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56, +64, 80, 96, 112, 128, 160, 192, 224, 0 +}; + +local const int base_dist[D_CODES] = { + 0, 1, 2, 3, 4, 6, 8, 12, 16, 24, + 32, 48, 64, 96, 128, 192, 256, 384, 512, 768, + 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576 +}; + diff --git a/libs/zlib/uncompr.c b/libs/zlib/uncompr.c new file mode 100644 index 000000000..ad98be3a5 --- /dev/null +++ b/libs/zlib/uncompr.c @@ -0,0 +1,59 @@ +/* uncompr.c -- decompress a memory buffer + * Copyright (C) 1995-2003, 2010 Jean-loup Gailly. + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* @(#) $Id$ */ + +#define ZLIB_INTERNAL +#include "zlib.h" + +/* =========================================================================== + Decompresses the source buffer into the destination buffer. sourceLen is + the byte length of the source buffer. Upon entry, destLen is the total + size of the destination buffer, which must be large enough to hold the + entire uncompressed data. (The size of the uncompressed data must have + been saved previously by the compressor and transmitted to the decompressor + by some mechanism outside the scope of this compression library.) + Upon exit, destLen is the actual size of the compressed buffer. + + uncompress returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_BUF_ERROR if there was not enough room in the output + buffer, or Z_DATA_ERROR if the input data was corrupted. +*/ +int ZEXPORT uncompress (dest, destLen, source, sourceLen) + Bytef *dest; + uLongf *destLen; + const Bytef *source; + uLong sourceLen; +{ + z_stream stream; + int err; + + stream.next_in = (Bytef*)source; + stream.avail_in = (uInt)sourceLen; + /* Check for source > 64K on 16-bit machine: */ + if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; + + stream.next_out = dest; + stream.avail_out = (uInt)*destLen; + if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; + + stream.zalloc = (alloc_func)0; + stream.zfree = (free_func)0; + + err = inflateInit(&stream); + if (err != Z_OK) return err; + + err = inflate(&stream, Z_FINISH); + if (err != Z_STREAM_END) { + inflateEnd(&stream); + if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0)) + return Z_DATA_ERROR; + return err; + } + *destLen = stream.total_out; + + err = inflateEnd(&stream); + return err; +} diff --git a/libs/zlib/watcom/watcom_f.mak b/libs/zlib/watcom/watcom_f.mak new file mode 100644 index 000000000..a6289f0a7 --- /dev/null +++ b/libs/zlib/watcom/watcom_f.mak @@ -0,0 +1,43 @@ +# Makefile for zlib +# OpenWatcom flat model +# Last updated: 28-Dec-2005 + +# To use, do "wmake -f watcom_f.mak" + +C_SOURCE = adler32.c compress.c crc32.c deflate.c & + gzclose.c gzlib.c gzread.c gzwrite.c & + infback.c inffast.c inflate.c inftrees.c & + trees.c uncompr.c zutil.c + +OBJS = adler32.obj compress.obj crc32.obj deflate.obj & + gzclose.obj gzlib.obj gzread.obj gzwrite.obj & + infback.obj inffast.obj inflate.obj inftrees.obj & + trees.obj uncompr.obj zutil.obj + +CC = wcc386 +LINKER = wcl386 +CFLAGS = -zq -mf -3r -fp3 -s -bt=dos -oilrtfm -fr=nul -wx +ZLIB_LIB = zlib_f.lib + +.C.OBJ: + $(CC) $(CFLAGS) $[@ + +all: $(ZLIB_LIB) example.exe minigzip.exe + +$(ZLIB_LIB): $(OBJS) + wlib -b -c $(ZLIB_LIB) -+adler32.obj -+compress.obj -+crc32.obj + wlib -b -c $(ZLIB_LIB) -+gzclose.obj -+gzlib.obj -+gzread.obj -+gzwrite.obj + wlib -b -c $(ZLIB_LIB) -+deflate.obj -+infback.obj + wlib -b -c $(ZLIB_LIB) -+inffast.obj -+inflate.obj -+inftrees.obj + wlib -b -c $(ZLIB_LIB) -+trees.obj -+uncompr.obj -+zutil.obj + +example.exe: $(ZLIB_LIB) example.obj + $(LINKER) -ldos32a -fe=example.exe example.obj $(ZLIB_LIB) + +minigzip.exe: $(ZLIB_LIB) minigzip.obj + $(LINKER) -ldos32a -fe=minigzip.exe minigzip.obj $(ZLIB_LIB) + +clean: .SYMBOLIC + del *.obj + del $(ZLIB_LIB) + @echo Cleaning done diff --git a/libs/zlib/watcom/watcom_l.mak b/libs/zlib/watcom/watcom_l.mak new file mode 100644 index 000000000..e0cc74ee3 --- /dev/null +++ b/libs/zlib/watcom/watcom_l.mak @@ -0,0 +1,43 @@ +# Makefile for zlib +# OpenWatcom large model +# Last updated: 28-Dec-2005 + +# To use, do "wmake -f watcom_l.mak" + +C_SOURCE = adler32.c compress.c crc32.c deflate.c & + gzclose.c gzlib.c gzread.c gzwrite.c & + infback.c inffast.c inflate.c inftrees.c & + trees.c uncompr.c zutil.c + +OBJS = adler32.obj compress.obj crc32.obj deflate.obj & + gzclose.obj gzlib.obj gzread.obj gzwrite.obj & + infback.obj inffast.obj inflate.obj inftrees.obj & + trees.obj uncompr.obj zutil.obj + +CC = wcc +LINKER = wcl +CFLAGS = -zq -ml -s -bt=dos -oilrtfm -fr=nul -wx +ZLIB_LIB = zlib_l.lib + +.C.OBJ: + $(CC) $(CFLAGS) $[@ + +all: $(ZLIB_LIB) example.exe minigzip.exe + +$(ZLIB_LIB): $(OBJS) + wlib -b -c $(ZLIB_LIB) -+adler32.obj -+compress.obj -+crc32.obj + wlib -b -c $(ZLIB_LIB) -+gzclose.obj -+gzlib.obj -+gzread.obj -+gzwrite.obj + wlib -b -c $(ZLIB_LIB) -+deflate.obj -+infback.obj + wlib -b -c $(ZLIB_LIB) -+inffast.obj -+inflate.obj -+inftrees.obj + wlib -b -c $(ZLIB_LIB) -+trees.obj -+uncompr.obj -+zutil.obj + +example.exe: $(ZLIB_LIB) example.obj + $(LINKER) -fe=example.exe example.obj $(ZLIB_LIB) + +minigzip.exe: $(ZLIB_LIB) minigzip.obj + $(LINKER) -fe=minigzip.exe minigzip.obj $(ZLIB_LIB) + +clean: .SYMBOLIC + del *.obj + del $(ZLIB_LIB) + @echo Cleaning done diff --git a/libs/zlib/win32/DLL_FAQ.txt b/libs/zlib/win32/DLL_FAQ.txt new file mode 100644 index 000000000..12c009018 --- /dev/null +++ b/libs/zlib/win32/DLL_FAQ.txt @@ -0,0 +1,397 @@ + + Frequently Asked Questions about ZLIB1.DLL + + +This document describes the design, the rationale, and the usage +of the official DLL build of zlib, named ZLIB1.DLL. If you have +general questions about zlib, you should see the file "FAQ" found +in the zlib distribution, or at the following location: + http://www.gzip.org/zlib/zlib_faq.html + + + 1. What is ZLIB1.DLL, and how can I get it? + + - ZLIB1.DLL is the official build of zlib as a DLL. + (Please remark the character '1' in the name.) + + Pointers to a precompiled ZLIB1.DLL can be found in the zlib + web site at: + http://www.zlib.net/ + + Applications that link to ZLIB1.DLL can rely on the following + specification: + + * The exported symbols are exclusively defined in the source + files "zlib.h" and "zlib.def", found in an official zlib + source distribution. + * The symbols are exported by name, not by ordinal. + * The exported names are undecorated. + * The calling convention of functions is "C" (CDECL). + * The ZLIB1.DLL binary is linked to MSVCRT.DLL. + + The archive in which ZLIB1.DLL is bundled contains compiled + test programs that must run with a valid build of ZLIB1.DLL. + It is recommended to download the prebuilt DLL from the zlib + web site, instead of building it yourself, to avoid potential + incompatibilities that could be introduced by your compiler + and build settings. If you do build the DLL yourself, please + make sure that it complies with all the above requirements, + and it runs with the precompiled test programs, bundled with + the original ZLIB1.DLL distribution. + + If, for any reason, you need to build an incompatible DLL, + please use a different file name. + + + 2. Why did you change the name of the DLL to ZLIB1.DLL? + What happened to the old ZLIB.DLL? + + - The old ZLIB.DLL, built from zlib-1.1.4 or earlier, required + compilation settings that were incompatible to those used by + a static build. The DLL settings were supposed to be enabled + by defining the macro ZLIB_DLL, before including "zlib.h". + Incorrect handling of this macro was silently accepted at + build time, resulting in two major problems: + + * ZLIB_DLL was missing from the old makefile. When building + the DLL, not all people added it to the build options. In + consequence, incompatible incarnations of ZLIB.DLL started + to circulate around the net. + + * When switching from using the static library to using the + DLL, applications had to define the ZLIB_DLL macro and + to recompile all the sources that contained calls to zlib + functions. Failure to do so resulted in creating binaries + that were unable to run with the official ZLIB.DLL build. + + The only possible solution that we could foresee was to make + a binary-incompatible change in the DLL interface, in order to + remove the dependency on the ZLIB_DLL macro, and to release + the new DLL under a different name. + + We chose the name ZLIB1.DLL, where '1' indicates the major + zlib version number. We hope that we will not have to break + the binary compatibility again, at least not as long as the + zlib-1.x series will last. + + There is still a ZLIB_DLL macro, that can trigger a more + efficient build and use of the DLL, but compatibility no + longer dependents on it. + + + 3. Can I build ZLIB.DLL from the new zlib sources, and replace + an old ZLIB.DLL, that was built from zlib-1.1.4 or earlier? + + - In principle, you can do it by assigning calling convention + keywords to the macros ZEXPORT and ZEXPORTVA. In practice, + it depends on what you mean by "an old ZLIB.DLL", because the + old DLL exists in several mutually-incompatible versions. + You have to find out first what kind of calling convention is + being used in your particular ZLIB.DLL build, and to use the + same one in the new build. If you don't know what this is all + about, you might be better off if you would just leave the old + DLL intact. + + + 4. Can I compile my application using the new zlib interface, and + link it to an old ZLIB.DLL, that was built from zlib-1.1.4 or + earlier? + + - The official answer is "no"; the real answer depends again on + what kind of ZLIB.DLL you have. Even if you are lucky, this + course of action is unreliable. + + If you rebuild your application and you intend to use a newer + version of zlib (post- 1.1.4), it is strongly recommended to + link it to the new ZLIB1.DLL. + + + 5. Why are the zlib symbols exported by name, and not by ordinal? + + - Although exporting symbols by ordinal is a little faster, it + is risky. Any single glitch in the maintenance or use of the + DEF file that contains the ordinals can result in incompatible + builds and frustrating crashes. Simply put, the benefits of + exporting symbols by ordinal do not justify the risks. + + Technically, it should be possible to maintain ordinals in + the DEF file, and still export the symbols by name. Ordinals + exist in every DLL, and even if the dynamic linking performed + at the DLL startup is searching for names, ordinals serve as + hints, for a faster name lookup. However, if the DEF file + contains ordinals, the Microsoft linker automatically builds + an implib that will cause the executables linked to it to use + those ordinals, and not the names. It is interesting to + notice that the GNU linker for Win32 does not suffer from this + problem. + + It is possible to avoid the DEF file if the exported symbols + are accompanied by a "__declspec(dllexport)" attribute in the + source files. You can do this in zlib by predefining the + ZLIB_DLL macro. + + + 6. I see that the ZLIB1.DLL functions use the "C" (CDECL) calling + convention. Why not use the STDCALL convention? + STDCALL is the standard convention in Win32, and I need it in + my Visual Basic project! + + (For readability, we use CDECL to refer to the convention + triggered by the "__cdecl" keyword, STDCALL to refer to + the convention triggered by "__stdcall", and FASTCALL to + refer to the convention triggered by "__fastcall".) + + - Most of the native Windows API functions (without varargs) use + indeed the WINAPI convention (which translates to STDCALL in + Win32), but the standard C functions use CDECL. If a user + application is intrinsically tied to the Windows API (e.g. + it calls native Windows API functions such as CreateFile()), + sometimes it makes sense to decorate its own functions with + WINAPI. But if ANSI C or POSIX portability is a goal (e.g. + it calls standard C functions such as fopen()), it is not a + sound decision to request the inclusion of , or to + use non-ANSI constructs, for the sole purpose to make the user + functions STDCALL-able. + + The functionality offered by zlib is not in the category of + "Windows functionality", but is more like "C functionality". + + Technically, STDCALL is not bad; in fact, it is slightly + faster than CDECL, and it works with variable-argument + functions, just like CDECL. It is unfortunate that, in spite + of using STDCALL in the Windows API, it is not the default + convention used by the C compilers that run under Windows. + The roots of the problem reside deep inside the unsafety of + the K&R-style function prototypes, where the argument types + are not specified; but that is another story for another day. + + The remaining fact is that CDECL is the default convention. + Even if an explicit convention is hard-coded into the function + prototypes inside C headers, problems may appear. The + necessity to expose the convention in users' callbacks is one + of these problems. + + The calling convention issues are also important when using + zlib in other programming languages. Some of them, like Ada + (GNAT) and Fortran (GNU G77), have C bindings implemented + initially on Unix, and relying on the C calling convention. + On the other hand, the pre- .NET versions of Microsoft Visual + Basic require STDCALL, while Borland Delphi prefers, although + it does not require, FASTCALL. + + In fairness to all possible uses of zlib outside the C + programming language, we choose the default "C" convention. + Anyone interested in different bindings or conventions is + encouraged to maintain specialized projects. The "contrib/" + directory from the zlib distribution already holds a couple + of foreign bindings, such as Ada, C++, and Delphi. + + + 7. I need a DLL for my Visual Basic project. What can I do? + + - Define the ZLIB_WINAPI macro before including "zlib.h", when + building both the DLL and the user application (except that + you don't need to define anything when using the DLL in Visual + Basic). The ZLIB_WINAPI macro will switch on the WINAPI + (STDCALL) convention. The name of this DLL must be different + than the official ZLIB1.DLL. + + Gilles Vollant has contributed a build named ZLIBWAPI.DLL, + with the ZLIB_WINAPI macro turned on, and with the minizip + functionality built in. For more information, please read + the notes inside "contrib/vstudio/readme.txt", found in the + zlib distribution. + + + 8. I need to use zlib in my Microsoft .NET project. What can I + do? + + - Henrik Ravn has contributed a .NET wrapper around zlib. Look + into contrib/dotzlib/, inside the zlib distribution. + + + 9. If my application uses ZLIB1.DLL, should I link it to + MSVCRT.DLL? Why? + + - It is not required, but it is recommended to link your + application to MSVCRT.DLL, if it uses ZLIB1.DLL. + + The executables (.EXE, .DLL, etc.) that are involved in the + same process and are using the C run-time library (i.e. they + are calling standard C functions), must link to the same + library. There are several libraries in the Win32 system: + CRTDLL.DLL, MSVCRT.DLL, the static C libraries, etc. + Since ZLIB1.DLL is linked to MSVCRT.DLL, the executables that + depend on it should also be linked to MSVCRT.DLL. + + +10. Why are you saying that ZLIB1.DLL and my application should + be linked to the same C run-time (CRT) library? I linked my + application and my DLLs to different C libraries (e.g. my + application to a static library, and my DLLs to MSVCRT.DLL), + and everything works fine. + + - If a user library invokes only pure Win32 API (accessible via + and the related headers), its DLL build will work + in any context. But if this library invokes standard C API, + things get more complicated. + + There is a single Win32 library in a Win32 system. Every + function in this library resides in a single DLL module, that + is safe to call from anywhere. On the other hand, there are + multiple versions of the C library, and each of them has its + own separate internal state. Standalone executables and user + DLLs that call standard C functions must link to a C run-time + (CRT) library, be it static or shared (DLL). Intermixing + occurs when an executable (not necessarily standalone) and a + DLL are linked to different CRTs, and both are running in the + same process. + + Intermixing multiple CRTs is possible, as long as their + internal states are kept intact. The Microsoft Knowledge Base + articles KB94248 "HOWTO: Use the C Run-Time" and KB140584 + "HOWTO: Link with the Correct C Run-Time (CRT) Library" + mention the potential problems raised by intermixing. + + If intermixing works for you, it's because your application + and DLLs are avoiding the corruption of each of the CRTs' + internal states, maybe by careful design, or maybe by fortune. + + Also note that linking ZLIB1.DLL to non-Microsoft CRTs, such + as those provided by Borland, raises similar problems. + + +11. Why are you linking ZLIB1.DLL to MSVCRT.DLL? + + - MSVCRT.DLL exists on every Windows 95 with a new service pack + installed, or with Microsoft Internet Explorer 4 or later, and + on all other Windows 4.x or later (Windows 98, Windows NT 4, + or later). It is freely distributable; if not present in the + system, it can be downloaded from Microsoft or from other + software provider for free. + + The fact that MSVCRT.DLL does not exist on a virgin Windows 95 + is not so problematic. Windows 95 is scarcely found nowadays, + Microsoft ended its support a long time ago, and many recent + applications from various vendors, including Microsoft, do not + even run on it. Furthermore, no serious user should run + Windows 95 without a proper update installed. + + +12. Why are you not linking ZLIB1.DLL to + <> ? + + - We considered and abandoned the following alternatives: + + * Linking ZLIB1.DLL to a static C library (LIBC.LIB, or + LIBCMT.LIB) is not a good option. People are using the DLL + mainly to save disk space. If you are linking your program + to a static C library, you may as well consider linking zlib + in statically, too. + + * Linking ZLIB1.DLL to CRTDLL.DLL looks appealing, because + CRTDLL.DLL is present on every Win32 installation. + Unfortunately, it has a series of problems: it does not + work properly with Microsoft's C++ libraries, it does not + provide support for 64-bit file offsets, (and so on...), + and Microsoft discontinued its support a long time ago. + + * Linking ZLIB1.DLL to MSVCR70.DLL or MSVCR71.DLL, supplied + with the Microsoft .NET platform, and Visual C++ 7.0/7.1, + raises problems related to the status of ZLIB1.DLL as a + system component. According to the Microsoft Knowledge Base + article KB326922 "INFO: Redistribution of the Shared C + Runtime Component in Visual C++ .NET", MSVCR70.DLL and + MSVCR71.DLL are not supposed to function as system DLLs, + because they may clash with MSVCRT.DLL. Instead, the + application's installer is supposed to put these DLLs + (if needed) in the application's private directory. + If ZLIB1.DLL depends on a non-system runtime, it cannot + function as a redistributable system component. + + * Linking ZLIB1.DLL to non-Microsoft runtimes, such as + Borland's, or Cygwin's, raises problems related to the + reliable presence of these runtimes on Win32 systems. + It's easier to let the DLL build of zlib up to the people + who distribute these runtimes, and who may proceed as + explained in the answer to Question 14. + + +13. If ZLIB1.DLL cannot be linked to MSVCR70.DLL or MSVCR71.DLL, + how can I build/use ZLIB1.DLL in Microsoft Visual C++ 7.0 + (Visual Studio .NET) or newer? + + - Due to the problems explained in the Microsoft Knowledge Base + article KB326922 (see the previous answer), the C runtime that + comes with the VC7 environment is no longer considered a + system component. That is, it should not be assumed that this + runtime exists, or may be installed in a system directory. + Since ZLIB1.DLL is supposed to be a system component, it may + not depend on a non-system component. + + In order to link ZLIB1.DLL and your application to MSVCRT.DLL + in VC7, you need the library of Visual C++ 6.0 or older. If + you don't have this library at hand, it's probably best not to + use ZLIB1.DLL. + + We are hoping that, in the future, Microsoft will provide a + way to build applications linked to a proper system runtime, + from the Visual C++ environment. Until then, you have a + couple of alternatives, such as linking zlib in statically. + If your application requires dynamic linking, you may proceed + as explained in the answer to Question 14. + + +14. I need to link my own DLL build to a CRT different than + MSVCRT.DLL. What can I do? + + - Feel free to rebuild the DLL from the zlib sources, and link + it the way you want. You should, however, clearly state that + your build is unofficial. You should give it a different file + name, and/or install it in a private directory that can be + accessed by your application only, and is not visible to the + others (i.e. it's neither in the PATH, nor in the SYSTEM or + SYSTEM32 directories). Otherwise, your build may clash with + applications that link to the official build. + + For example, in Cygwin, zlib is linked to the Cygwin runtime + CYGWIN1.DLL, and it is distributed under the name CYGZ.DLL. + + +15. May I include additional pieces of code that I find useful, + link them in ZLIB1.DLL, and export them? + + - No. A legitimate build of ZLIB1.DLL must not include code + that does not originate from the official zlib source code. + But you can make your own private DLL build, under a different + file name, as suggested in the previous answer. + + For example, zlib is a part of the VCL library, distributed + with Borland Delphi and C++ Builder. The DLL build of VCL + is a redistributable file, named VCLxx.DLL. + + +16. May I remove some functionality out of ZLIB1.DLL, by enabling + macros like NO_GZCOMPRESS or NO_GZIP at compile time? + + - No. A legitimate build of ZLIB1.DLL must provide the complete + zlib functionality, as implemented in the official zlib source + code. But you can make your own private DLL build, under a + different file name, as suggested in the previous answer. + + +17. I made my own ZLIB1.DLL build. Can I test it for compliance? + + - We prefer that you download the official DLL from the zlib + web site. If you need something peculiar from this DLL, you + can send your suggestion to the zlib mailing list. + + However, in case you do rebuild the DLL yourself, you can run + it with the test programs found in the DLL distribution. + Running these test programs is not a guarantee of compliance, + but a failure can imply a detected problem. + +** + +This document is written and maintained by +Cosmin Truta diff --git a/libs/zlib/win32/Makefile.bor b/libs/zlib/win32/Makefile.bor new file mode 100644 index 000000000..3981d4246 --- /dev/null +++ b/libs/zlib/win32/Makefile.bor @@ -0,0 +1,110 @@ +# Makefile for zlib +# Borland C++ for Win32 +# +# Usage: +# make -f win32/Makefile.bor +# make -f win32/Makefile.bor LOCAL_ZLIB=-DASMV OBJA=match.obj OBJPA=+match.obj + +# ------------ Borland C++ ------------ + +# Optional nonstandard preprocessor flags (e.g. -DMAX_MEM_LEVEL=7) +# should be added to the environment via "set LOCAL_ZLIB=-DFOO" or +# added to the declaration of LOC here: +LOC = $(LOCAL_ZLIB) + +CC = bcc32 +AS = bcc32 +LD = bcc32 +AR = tlib +CFLAGS = -a -d -k- -O2 $(LOC) +ASFLAGS = $(LOC) +LDFLAGS = $(LOC) + + +# variables +ZLIB_LIB = zlib.lib + +OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzclose.obj gzlib.obj gzread.obj +OBJ2 = gzwrite.obj infback.obj inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj +#OBJA = +OBJP1 = +adler32.obj+compress.obj+crc32.obj+deflate.obj+gzclose.obj+gzlib.obj+gzread.obj +OBJP2 = +gzwrite.obj+infback.obj+inffast.obj+inflate.obj+inftrees.obj+trees.obj+uncompr.obj+zutil.obj +#OBJPA= + + +# targets +all: $(ZLIB_LIB) example.exe minigzip.exe + +.c.obj: + $(CC) -c $(CFLAGS) $< + +.asm.obj: + $(AS) -c $(ASFLAGS) $< + +adler32.obj: adler32.c zlib.h zconf.h + +compress.obj: compress.c zlib.h zconf.h + +crc32.obj: crc32.c zlib.h zconf.h crc32.h + +deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h + +gzclose.obj: gzclose.c zlib.h zconf.h gzguts.h + +gzlib.obj: gzlib.c zlib.h zconf.h gzguts.h + +gzread.obj: gzread.c zlib.h zconf.h gzguts.h + +gzwrite.obj: gzwrite.c zlib.h zconf.h gzguts.h + +infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ + inffast.h inffixed.h + +inffast.obj: inffast.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ + inffast.h + +inflate.obj: inflate.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ + inffast.h inffixed.h + +inftrees.obj: inftrees.c zutil.h zlib.h zconf.h inftrees.h + +trees.obj: trees.c zutil.h zlib.h zconf.h deflate.h trees.h + +uncompr.obj: uncompr.c zlib.h zconf.h + +zutil.obj: zutil.c zutil.h zlib.h zconf.h + +example.obj: example.c zlib.h zconf.h + +minigzip.obj: minigzip.c zlib.h zconf.h + + +# For the sake of the old Borland make, +# the command line is cut to fit in the MS-DOS 128 byte limit: +$(ZLIB_LIB): $(OBJ1) $(OBJ2) $(OBJA) + -del $(ZLIB_LIB) + $(AR) $(ZLIB_LIB) $(OBJP1) + $(AR) $(ZLIB_LIB) $(OBJP2) + $(AR) $(ZLIB_LIB) $(OBJPA) + + +# testing +test: example.exe minigzip.exe + example + echo hello world | minigzip | minigzip -d + +example.exe: example.obj $(ZLIB_LIB) + $(LD) $(LDFLAGS) example.obj $(ZLIB_LIB) + +minigzip.exe: minigzip.obj $(ZLIB_LIB) + $(LD) $(LDFLAGS) minigzip.obj $(ZLIB_LIB) + + +# cleanup +clean: + -del $(ZLIB_LIB) + -del *.obj + -del *.exe + -del *.tds + -del zlib.bak + -del foo.gz diff --git a/libs/zlib/win32/Makefile.emx b/libs/zlib/win32/Makefile.emx new file mode 100644 index 000000000..4d6ab0efa --- /dev/null +++ b/libs/zlib/win32/Makefile.emx @@ -0,0 +1,69 @@ +# Makefile for zlib. Modified for emx/rsxnt by Chr. Spieler, 6/16/98. +# Copyright (C) 1995-1998 Jean-loup Gailly. +# For conditions of distribution and use, see copyright notice in zlib.h + +# To compile, or to compile and test, type: +# +# make -fmakefile.emx; make test -fmakefile.emx +# + +CC=gcc -Zwin32 + +#CFLAGS=-MMD -O +#CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7 +#CFLAGS=-MMD -g -DDEBUG +CFLAGS=-MMD -O3 $(BUTT) -Wall -Wwrite-strings -Wpointer-arith -Wconversion \ + -Wstrict-prototypes -Wmissing-prototypes + +# If cp.exe is available, replace "copy /Y" with "cp -fp" . +CP=copy /Y +# If gnu install.exe is available, replace $(CP) with ginstall. +INSTALL=$(CP) +# The default value of RM is "rm -f." If "rm.exe" is found, comment out: +RM=del +LDLIBS=-L. -lzlib +LD=$(CC) -s -o +LDSHARED=$(CC) + +INCL=zlib.h zconf.h +LIBS=zlib.a + +AR=ar rcs + +prefix=/usr/local +exec_prefix = $(prefix) + +OBJS = adler32.o compress.o crc32.o deflate.o gzclose.o gzlib.o gzread.o \ + gzwrite.o infback.o inffast.o inflate.o inftrees.o trees.o uncompr.o zutil.o + +TEST_OBJS = example.o minigzip.o + +all: example.exe minigzip.exe + +test: all + ./example + echo hello world | .\minigzip | .\minigzip -d + +%.o : %.c + $(CC) $(CFLAGS) -c $< -o $@ + +zlib.a: $(OBJS) + $(AR) $@ $(OBJS) + +%.exe : %.o $(LIBS) + $(LD) $@ $< $(LDLIBS) + + +.PHONY : clean + +clean: + $(RM) *.d + $(RM) *.o + $(RM) *.exe + $(RM) zlib.a + $(RM) foo.gz + +DEPS := $(wildcard *.d) +ifneq ($(DEPS),) +include $(DEPS) +endif diff --git a/libs/zlib/win32/Makefile.gcc b/libs/zlib/win32/Makefile.gcc new file mode 100644 index 000000000..44eaa93e3 --- /dev/null +++ b/libs/zlib/win32/Makefile.gcc @@ -0,0 +1,168 @@ +# Makefile for zlib, derived from Makefile.dj2. +# Modified for mingw32 by C. Spieler, 6/16/98. +# Updated for zlib 1.2.x by Christian Spieler and Cosmin Truta, Mar-2003. +# Last updated: 1-Aug-2003. +# Tested under Cygwin and MinGW. + +# Copyright (C) 1995-2003 Jean-loup Gailly. +# For conditions of distribution and use, see copyright notice in zlib.h + +# To compile, or to compile and test, type: +# +# make -fmakefile.gcc; make test testdll -fmakefile.gcc +# +# To use the asm code, type: +# cp contrib/asm?86/match.S ./match.S +# make LOC=-DASMV OBJA=match.o -fmakefile.gcc +# +# To install libz.a, zconf.h and zlib.h in the system directories, type: +# +# make install -fmakefile.gcc + +# Note: +# If the platform is *not* MinGW (e.g. it is Cygwin or UWIN), +# the DLL name should be changed from "zlib1.dll". + +STATICLIB = libz.a +SHAREDLIB = zlib1.dll +IMPLIB = libzdll.a + +# +# Set to 1 if shared object needs to be installed +# +SHARED_MODE=0 + +#LOC = -DASMV +#LOC = -DDEBUG -g +LOC = -pipe -g + +PREFIX = +CC = $(PREFIX)gcc +CFLAGS = $(LOC) -O3 -Wall +EXTRA_CFLAGS = -DNO_VIZ + +AS = $(CC) +ASFLAGS = $(LOC) -Wall + +LD = $(CC) +LDFLAGS = $(LOC) + +AR = $(PREFIX)ar +ARFLAGS = rcs + +RANLIB = $(PREFIX)ranlib + +RC = $(PREFIX)windres +RCFLAGS = --define GCC_WINDRES + +STRIP = $(PREFIX)strip + +CP = cp -fp +# If GNU install is available, replace $(CP) with install. +INSTALL = $(CP) +RM = rm -f + +prefix = /usr/local +exec_prefix = $(prefix) + +OBJS = adler32.o compress.o crc32.o deflate.o gzclose.o gzlib.o gzread.o \ + gzwrite.o infback.o inffast.o inflate.o inftrees.o trees.o uncompr.o zutil.o +OBJA = + +all: $(STATICLIB) $(SHAREDLIB) $(IMPLIB) example.exe minigzip.exe example_d.exe minigzip_d.exe + +test: example.exe minigzip.exe + ./example + echo hello world | ./minigzip | ./minigzip -d + +testdll: example_d.exe minigzip_d.exe + ./example_d + echo hello world | ./minigzip_d | ./minigzip_d -d + +.c.o: + $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $< + +.S.o: + $(AS) $(ASFLAGS) -c -o $@ $< + +$(STATICLIB): $(OBJS) $(OBJA) + $(AR) $(ARFLAGS) $@ $(OBJS) $(OBJA) + $(RANLIB) $(STATICLIB) + +$(IMPLIB): $(SHAREDLIB) + +$(SHAREDLIB): win32/zlib.def $(OBJS) $(OBJA) zlibrc.o + $(CC) -shared -Wl,--out-implib,$(IMPLIB) $(LDFLAGS) \ + -o $@ win32/zlib.def $(OBJS) $(OBJA) zlibrc.o + $(STRIP) $@ + +example.exe: example.o $(STATICLIB) + $(LD) $(LDFLAGS) -o $@ example.o $(STATICLIB) + $(STRIP) $@ + +minigzip.exe: minigzip.o $(STATICLIB) + $(LD) $(LDFLAGS) -o $@ minigzip.o $(STATICLIB) + $(STRIP) $@ + +example_d.exe: example.o $(IMPLIB) + $(LD) $(LDFLAGS) -o $@ example.o $(IMPLIB) + $(STRIP) $@ + +minigzip_d.exe: minigzip.o $(IMPLIB) + $(LD) $(LDFLAGS) -o $@ minigzip.o $(IMPLIB) + $(STRIP) $@ + +zlibrc.o: win32/zlib1.rc + $(RC) $(RCFLAGS) -o $@ win32/zlib1.rc + + +# BINARY_PATH, INCLUDE_PATH and LIBRARY_PATH must be set. + +.PHONY: install uninstall clean + +install: zlib.h zconf.h $(STATICLIB) $(IMPLIB) + -@mkdir -p $(INCLUDE_PATH) + -@mkdir -p $(LIBRARY_PATH) + -if [ "$(SHARED_MODE)" = "1" ]; then \ + mkdir -p $(BINARY_PATH); \ + $(INSTALL) $(SHAREDLIB) $(BINARY_PATH); \ + $(INSTALL) $(IMPLIB) $(LIBRARY_PATH); \ + fi + -$(INSTALL) zlib.h $(INCLUDE_PATH) + -$(INSTALL) zconf.h $(INCLUDE_PATH) + -$(INSTALL) $(STATICLIB) $(LIBRARY_PATH) + +uninstall: + -if [ "$(SHARED_MODE)" = "1" ]; then \ + $(RM) $(BINARY_PATH)/$(SHAREDLIB); \ + $(RM) $(LIBRARY_PATH)/$(IMPLIB); \ + fi + -$(RM) $(INCLUDE_PATH)/zlib.h + -$(RM) $(INCLUDE_PATH)/zconf.h + -$(RM) $(LIBRARY_PATH)/$(STATICLIB) + +clean: + -$(RM) $(STATICLIB) + -$(RM) $(SHAREDLIB) + -$(RM) $(IMPLIB) + -$(RM) *.o + -$(RM) *.exe + -$(RM) foo.gz + +adler32.o: zlib.h zconf.h +compress.o: zlib.h zconf.h +crc32.o: crc32.h zlib.h zconf.h +deflate.o: deflate.h zutil.h zlib.h zconf.h +example.o: zlib.h zconf.h +gzclose.o: zlib.h zconf.h gzguts.h +gzlib.o: zlib.h zconf.h gzguts.h +gzread.o: zlib.h zconf.h gzguts.h +gzwrite.o: zlib.h zconf.h gzguts.h +inffast.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h +inflate.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h +infback.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h +inftrees.o: zutil.h zlib.h zconf.h inftrees.h +minigzip.o: zlib.h zconf.h +trees.o: deflate.h zutil.h zlib.h zconf.h trees.h +uncompr.o: zlib.h zconf.h +zutil.o: zutil.h zlib.h zconf.h diff --git a/libs/zlib/win32/Makefile.msc b/libs/zlib/win32/Makefile.msc new file mode 100644 index 000000000..fa10a1aa5 --- /dev/null +++ b/libs/zlib/win32/Makefile.msc @@ -0,0 +1,157 @@ +# Makefile for zlib using Microsoft (Visual) C +# zlib is copyright (C) 1995-2006 Jean-loup Gailly and Mark Adler +# +# Usage: +# nmake -f win32/Makefile.msc (standard build) +# nmake -f win32/Makefile.msc LOC=-DFOO (nonstandard build) +# nmake -f win32/Makefile.msc LOC="-DASMV -DASMINF" \ +# OBJA="inffas32.obj match686.obj" (use ASM code, x86) +# nmake -f win32/Makefile.msc AS=ml64 LOC="-DASMV -DASMINF" \ +# OBJA="inffasx64.obj gvmat64.obj inffas8664.c" (use ASM code, x64) + +# optional build flags +LOC = + +# variables +STATICLIB = zlib.lib +SHAREDLIB = zlib1.dll +IMPLIB = zdll.lib + +CC = cl +AS = ml +LD = link +AR = lib +RC = rc +CFLAGS = -nologo -MD -W3 -O2 -Oy- -Zi -Fd"zlib" $(LOC) +WFLAGS = -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE +ASFLAGS = -coff -Zi $(LOC) +LDFLAGS = -nologo -debug -incremental:no -opt:ref +ARFLAGS = -nologo +RCFLAGS = /dWIN32 /r + +OBJS = adler32.obj compress.obj crc32.obj deflate.obj gzclose.obj gzlib.obj gzread.obj \ + gzwrite.obj infback.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj +OBJA = + + +# targets +all: $(STATICLIB) $(SHAREDLIB) $(IMPLIB) \ + example.exe minigzip.exe example_d.exe minigzip_d.exe + +$(STATICLIB): $(OBJS) $(OBJA) + $(AR) $(ARFLAGS) -out:$@ $(OBJS) $(OBJA) + +$(IMPLIB): $(SHAREDLIB) + +$(SHAREDLIB): win32/zlib.def $(OBJS) $(OBJA) zlib1.res + $(LD) $(LDFLAGS) -def:win32/zlib.def -dll -implib:$(IMPLIB) \ + -out:$@ -base:0x5A4C0000 $(OBJS) $(OBJA) zlib1.res + if exist $@.manifest \ + mt -nologo -manifest $@.manifest -outputresource:$@;2 + +example.exe: example.obj $(STATICLIB) + $(LD) $(LDFLAGS) example.obj $(STATICLIB) + if exist $@.manifest \ + mt -nologo -manifest $@.manifest -outputresource:$@;1 + +minigzip.exe: minigzip.obj $(STATICLIB) + $(LD) $(LDFLAGS) minigzip.obj $(STATICLIB) + if exist $@.manifest \ + mt -nologo -manifest $@.manifest -outputresource:$@;1 + +example_d.exe: example.obj $(IMPLIB) + $(LD) $(LDFLAGS) -out:$@ example.obj $(IMPLIB) + if exist $@.manifest \ + mt -nologo -manifest $@.manifest -outputresource:$@;1 + +minigzip_d.exe: minigzip.obj $(IMPLIB) + $(LD) $(LDFLAGS) -out:$@ minigzip.obj $(IMPLIB) + if exist $@.manifest \ + mt -nologo -manifest $@.manifest -outputresource:$@;1 + +.c.obj: + $(CC) -c $(WFLAGS) $(CFLAGS) $< + +{contrib/masmx64}.c.obj: + $(CC) -c $(WFLAGS) $(CFLAGS) $< + +{contrib/masmx64}.asm.obj: + $(AS) -c $(ASFLAGS) $< + +{contrib/masmx86}.asm.obj: + $(AS) -c $(ASFLAGS) $< + +adler32.obj: adler32.c zlib.h zconf.h + +compress.obj: compress.c zlib.h zconf.h + +crc32.obj: crc32.c zlib.h zconf.h crc32.h + +deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h + +gzclose.obj: gzclose.c zlib.h zconf.h gzguts.h + +gzlib.obj: gzlib.c zlib.h zconf.h gzguts.h + +gzread.obj: gzread.c zlib.h zconf.h gzguts.h + +gzwrite.obj: gzwrite.c zlib.h zconf.h gzguts.h + +infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ + inffast.h inffixed.h + +inffast.obj: inffast.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ + inffast.h + +inflate.obj: inflate.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ + inffast.h inffixed.h + +inftrees.obj: inftrees.c zutil.h zlib.h zconf.h inftrees.h + +trees.obj: trees.c zutil.h zlib.h zconf.h deflate.h trees.h + +uncompr.obj: uncompr.c zlib.h zconf.h + +zutil.obj: zutil.c zutil.h zlib.h zconf.h + +gvmat64.obj: contrib\masmx64\gvmat64.asm + +inffasx64.obj: contrib\masmx64\inffasx64.asm + +inffas8664.obj: contrib\masmx64\inffas8664.c zutil.h zlib.h zconf.h \ + inftrees.h inflate.h inffast.h + +inffas32.obj: contrib\masmx86\inffas32.asm + +match686.obj: contrib\masmx86\match686.asm + +example.obj: example.c zlib.h zconf.h + +minigzip.obj: minigzip.c zlib.h zconf.h + +zlib1.res: win32/zlib1.rc + $(RC) $(RCFLAGS) /fo$@ win32/zlib1.rc + + +# testing +test: example.exe minigzip.exe + example + echo hello world | minigzip | minigzip -d + +testdll: example_d.exe minigzip_d.exe + example_d + echo hello world | minigzip_d | minigzip_d -d + + +# cleanup +clean: + -del $(STATICLIB) + -del $(SHAREDLIB) + -del $(IMPLIB) + -del *.obj + -del *.res + -del *.exp + -del *.exe + -del *.pdb + -del *.manifest + -del foo.gz diff --git a/libs/zlib/win32/README-WIN32.txt b/libs/zlib/win32/README-WIN32.txt new file mode 100644 index 000000000..1e4c093c5 --- /dev/null +++ b/libs/zlib/win32/README-WIN32.txt @@ -0,0 +1,103 @@ +ZLIB DATA COMPRESSION LIBRARY + +zlib 1.2.4 is a general purpose data compression library. All the code is +thread safe. The data format used by the zlib library is described by RFCs +(Request for Comments) 1950 to 1952 in the files +http://www.ietf.org/rfc/rfc1950.txt (zlib format), rfc1951.txt (deflate format) +and rfc1952.txt (gzip format). + +All functions of the compression library are documented in the file zlib.h +(volunteer to write man pages welcome, contact zlib@gzip.org). Two compiled +examples are distributed in this package, example and minigzip. The example_d +and minigzip_d flavors validate that the zlib1.dll file is working correctly. + +Questions about zlib should be sent to . The zlib home page +is http://zlib.net/ . Before reporting a problem, please check this site to +verify that you have the latest version of zlib; otherwise get the latest +version and check whether the problem still exists or not. + +PLEASE read DLL_FAQ.txt, and the the zlib FAQ http://zlib.net/zlib_faq.html +before asking for help. + + +Manifest: + +The package zlib-1.2.4-win32-x86.zip contains the following files: + + README-WIN32.txt This document + ChangeLog Changes since previous zlib packages + DLL_FAQ.txt Frequently asked questions about zlib1.dll + zlib.3.pdf Documentation of this library in Adobe Acrobat format + + example.exe A statically-bound example (using zlib.lib, not the dll) + example.pdb Symbolic information for debugging example.exe + + example_d.exe A zlib1.dll bound example (using zdll.lib) + example_d.pdb Symbolic information for debugging example_d.exe + + minigzip.exe A statically-bound test program (using zlib.lib, not the dll) + minigzip.pdb Symbolic information for debugging minigzip.exe + + minigzip_d.exe A zlib1.dll bound test program (using zdll.lib) + minigzip_d.pdb Symbolic information for debugging minigzip_d.exe + + zlib.h Install these files into the compilers' INCLUDE path to + zconf.h compile programs which use zlib.lib or zdll.lib + + zdll.lib Install these files into the compilers' LIB path if linking + zdll.exp a compiled program to the zlib1.dll binary + + zlib.lib Install these files into the compilers' LIB path to link zlib + zlib.pdb into compiled programs, without zlib1.dll runtime dependency + (zlib.pdb provides debugging info to the compile time linker) + + zlib1.dll Install this binary shared library into the system PATH, or + the program's runtime directory (where the .exe resides) + zlib1.pdb Install in the same directory as zlib1.dll, in order to debug + an application crash using WinDbg or similar tools. + +All .pdb files above are entirely optional, but are very useful to a developer +attempting to diagnose program misbehavior or a crash. Many additional +important files for developers can be found in the zlib124.zip source package +available from http://zlib.net/ - review that package's README file for details. + + +Acknowledgments: + +The deflate format used by zlib was defined by Phil Katz. The deflate and +zlib specifications were written by L. Peter Deutsch. Thanks to all the +people who reported problems and suggested various improvements in zlib; they +are too numerous to cite here. + + +Copyright notice: + + (C) 1995-2010 Jean-loup Gailly and Mark Adler + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Jean-loup Gailly Mark Adler + jloup@gzip.org madler@alumni.caltech.edu + +If you use the zlib library in a product, we would appreciate *not* receiving +lengthy legal documents to sign. The sources are provided for free but without +warranty of any kind. The library has been entirely written by Jean-loup +Gailly and Mark Adler; it does not include third-party code. + +If you redistribute modified sources, we would appreciate that you include in +the file ChangeLog history information documenting your changes. Please read +the FAQ for more information on the distribution of modified source versions. diff --git a/libs/zlib/win32/VisualC.txt b/libs/zlib/win32/VisualC.txt new file mode 100644 index 000000000..579a5fc9e --- /dev/null +++ b/libs/zlib/win32/VisualC.txt @@ -0,0 +1,3 @@ + +To build zlib using the Microsoft Visual C++ environment, +use the appropriate project from the projects/ directory. diff --git a/libs/zlib/win32/libz32.a b/libs/zlib/win32/libz32.a new file mode 100644 index 000000000..9d2fd3610 Binary files /dev/null and b/libs/zlib/win32/libz32.a differ diff --git a/libs/zlib/win32/libz64.a b/libs/zlib/win32/libz64.a new file mode 100644 index 000000000..c3a5462ba Binary files /dev/null and b/libs/zlib/win32/libz64.a differ diff --git a/libs/zlib/win32/zlib.def b/libs/zlib/win32/zlib.def new file mode 100644 index 000000000..03df8bf82 --- /dev/null +++ b/libs/zlib/win32/zlib.def @@ -0,0 +1,74 @@ +LIBRARY +; zlib data compression library + +EXPORTS +; basic functions + zlibVersion + deflate + deflateEnd + inflate + inflateEnd +; advanced functions + deflateSetDictionary + deflateCopy + deflateReset + deflateParams + deflateTune + deflateBound + deflatePrime + deflateSetHeader + inflateSetDictionary + inflateSync + inflateCopy + inflateReset + inflateReset2 + inflatePrime + inflateMark + inflateGetHeader + inflateBack + inflateBackEnd + zlibCompileFlags +; utility functions + compress + compress2 + compressBound + uncompress + gzopen + gzdopen + gzbuffer + gzsetparams + gzread + gzwrite + gzprintf + gzputs + gzgets + gzputc + gzgetc + gzungetc + gzflush + gzseek + gzrewind + gztell + gzoffset + gzeof + gzdirect + gzclose + gzclose_r + gzclose_w + gzerror + gzclearerr +; checksum functions + adler32 + crc32 + adler32_combine + crc32_combine +; various hacks, don't look :) + deflateInit_ + deflateInit2_ + inflateInit_ + inflateInit2_ + inflateBackInit_ + zError + inflateSyncPoint + get_crc_table + inflateUndermine diff --git a/libs/zlib/win32/zlib1.rc b/libs/zlib/win32/zlib1.rc new file mode 100644 index 000000000..0d1d7ffcf --- /dev/null +++ b/libs/zlib/win32/zlib1.rc @@ -0,0 +1,40 @@ +#include +#include "../zlib.h" + +#ifdef GCC_WINDRES +VS_VERSION_INFO VERSIONINFO +#else +VS_VERSION_INFO VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE +#endif + FILEVERSION ZLIB_VER_MAJOR,ZLIB_VER_MINOR,ZLIB_VER_REVISION,0 + PRODUCTVERSION ZLIB_VER_MAJOR,ZLIB_VER_MINOR,ZLIB_VER_REVISION,0 + FILEFLAGSMASK VS_FFI_FILEFLAGSMASK +#ifdef _DEBUG + FILEFLAGS 1 +#else + FILEFLAGS 0 +#endif + FILEOS VOS__WINDOWS32 + FILETYPE VFT_DLL + FILESUBTYPE 0 // not used +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904E4" + //language ID = U.S. English, char set = Windows, Multilingual + BEGIN + VALUE "FileDescription", "zlib data compression library\0" + VALUE "FileVersion", ZLIB_VERSION "\0" + VALUE "InternalName", "zlib1.dll\0" + VALUE "LegalCopyright", "(C) 1995-2006 Jean-loup Gailly & Mark Adler\0" + VALUE "OriginalFilename", "zlib1.dll\0" + VALUE "ProductName", "zlib\0" + VALUE "ProductVersion", ZLIB_VERSION "\0" + VALUE "Comments", "For more information visit http://www.zlib.net/\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x0409, 1252 + END +END diff --git a/libs/zlib/zconf.h b/libs/zlib/zconf.h new file mode 100644 index 000000000..51c80ac14 --- /dev/null +++ b/libs/zlib/zconf.h @@ -0,0 +1,466 @@ +/* zconf.h -- configuration of the zlib compression library + * Copyright (C) 1995-2011 Jean-loup Gailly. + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* @(#) $Id$ */ + +#ifndef ZCONF_H +#define ZCONF_H + +/* + * If you *really* need a unique prefix for all types and library functions, + * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it. + * Even better than compiling with -DZ_PREFIX would be to use configure to set + * this permanently in zconf.h using "./configure --zprefix". + */ +#ifdef Z_PREFIX /* may be set to #if 1 by ./configure */ +# define Z_PREFIX_SET + +/* all linked symbols */ +# define _dist_code z__dist_code +# define _length_code z__length_code +# define _tr_align z__tr_align +# define _tr_flush_block z__tr_flush_block +# define _tr_init z__tr_init +# define _tr_stored_block z__tr_stored_block +# define _tr_tally z__tr_tally +# define adler32 z_adler32 +# define adler32_combine z_adler32_combine +# define adler32_combine64 z_adler32_combine64 +# ifndef Z_SOLO +# define compress z_compress +# define compress2 z_compress2 +# define compressBound z_compressBound +# endif +# define crc32 z_crc32 +# define crc32_combine z_crc32_combine +# define crc32_combine64 z_crc32_combine64 +# define deflate z_deflate +# define deflateBound z_deflateBound +# define deflateCopy z_deflateCopy +# define deflateEnd z_deflateEnd +# define deflateInit2_ z_deflateInit2_ +# define deflateInit_ z_deflateInit_ +# define deflateParams z_deflateParams +# define deflatePending z_deflatePending +# define deflatePrime z_deflatePrime +# define deflateReset z_deflateReset +# define deflateResetKeep z_deflateResetKeep +# define deflateSetDictionary z_deflateSetDictionary +# define deflateSetHeader z_deflateSetHeader +# define deflateTune z_deflateTune +# define deflate_copyright z_deflate_copyright +# define get_crc_table z_get_crc_table +# ifndef Z_SOLO +# define gz_error z_gz_error +# define gz_intmax z_gz_intmax +# define gz_strwinerror z_gz_strwinerror +# define gzbuffer z_gzbuffer +# define gzclearerr z_gzclearerr +# define gzclose z_gzclose +# define gzclose_r z_gzclose_r +# define gzclose_w z_gzclose_w +# define gzdirect z_gzdirect +# define gzdopen z_gzdopen +# define gzeof z_gzeof +# define gzerror z_gzerror +# define gzflags z_gzflags +# define gzflush z_gzflush +# define gzgetc z_gzgetc +# define gzgetc_ z_gzgetc_ +# define gzgets z_gzgets +# define gzoffset z_gzoffset +# define gzoffset64 z_gzoffset64 +# define gzopen z_gzopen +# define gzopen64 z_gzopen64 +# define gzprintf z_gzprintf +# define gzputc z_gzputc +# define gzputs z_gzputs +# define gzread z_gzread +# define gzrewind z_gzrewind +# define gzseek z_gzseek +# define gzseek64 z_gzseek64 +# define gzsetparams z_gzsetparams +# define gztell z_gztell +# define gztell64 z_gztell64 +# define gzungetc z_gzungetc +# define gzwrite z_gzwrite +# endif +# define inflate z_inflate +# define inflateBack z_inflateBack +# define inflateBackEnd z_inflateBackEnd +# define inflateBackInit_ z_inflateBackInit_ +# define inflateCopy z_inflateCopy +# define inflateEnd z_inflateEnd +# define inflateGetHeader z_inflateGetHeader +# define inflateInit2_ z_inflateInit2_ +# define inflateInit_ z_inflateInit_ +# define inflateMark z_inflateMark +# define inflatePrime z_inflatePrime +# define inflateReset z_inflateReset +# define inflateReset2 z_inflateReset2 +# define inflateSetDictionary z_inflateSetDictionary +# define inflateSync z_inflateSync +# define inflateSyncPoint z_inflateSyncPoint +# define inflateUndermine z_inflateUndermine +# define inflateResetKeep z_inflateResetKeep +# define inflate_copyright z_inflate_copyright +# define inflate_fast z_inflate_fast +# define inflate_table z_inflate_table +# ifndef Z_SOLO +# define uncompress z_uncompress +# endif +# define zError z_zError +# ifndef Z_SOLO +# define zcalloc z_zcalloc +# define zcfree z_zcfree +# endif +# define zlibCompileFlags z_zlibCompileFlags +# define zlibVersion z_zlibVersion + +/* all zlib typedefs in zlib.h and zconf.h */ +# define Byte z_Byte +# define Bytef z_Bytef +# define alloc_func z_alloc_func +# define charf z_charf +# define free_func z_free_func +# ifndef Z_SOLO +# define gzFile z_gzFile +# define gz_header z_gz_header +# define gz_headerp z_gz_headerp +# endif +# define in_func z_in_func +# define intf z_intf +# define out_func z_out_func +# define uInt z_uInt +# define uIntf z_uIntf +# define uLong z_uLong +# define uLongf z_uLongf +# define voidp z_voidp +# define voidpc z_voidpc +# define voidpf z_voidpf + +/* all zlib structs in zlib.h and zconf.h */ +# ifndef Z_SOLO +# define gz_header_s z_gz_header_s +# endif +# define internal_state z_internal_state + +#endif + +#if defined(__MSDOS__) && !defined(MSDOS) +# define MSDOS +#endif +#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2) +# define OS2 +#endif +#if defined(_WINDOWS) && !defined(WINDOWS) +# define WINDOWS +#endif +#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__) +# ifndef WIN32 +# define WIN32 +# endif +#endif +#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32) +# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__) +# ifndef SYS16BIT +# define SYS16BIT +# endif +# endif +#endif + +/* + * Compile with -DMAXSEG_64K if the alloc function cannot allocate more + * than 64k bytes at a time (needed on systems with 16-bit int). + */ +#ifdef SYS16BIT +# define MAXSEG_64K +#endif +#ifdef MSDOS +# define UNALIGNED_OK +#endif + +#ifdef __STDC_VERSION__ +# ifndef STDC +# define STDC +# endif +# if __STDC_VERSION__ >= 199901L +# ifndef STDC99 +# define STDC99 +# endif +# endif +#endif +#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus)) +# define STDC +#endif +#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__)) +# define STDC +#endif +#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32)) +# define STDC +#endif +#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__)) +# define STDC +#endif + +#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */ +# define STDC +#endif + +#ifndef STDC +# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ +# define const /* note: need a more gentle solution here */ +# endif +#endif + +#if defined(ZLIB_CONST) && !defined(z_const) +# define z_const const +#else +# define z_const +#endif + +/* Some Mac compilers merge all .h files incorrectly: */ +#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__) +# define NO_DUMMY_DECL +#endif + +/* Maximum value for memLevel in deflateInit2 */ +#ifndef MAX_MEM_LEVEL +# ifdef MAXSEG_64K +# define MAX_MEM_LEVEL 8 +# else +# define MAX_MEM_LEVEL 9 +# endif +#endif + +/* Maximum value for windowBits in deflateInit2 and inflateInit2. + * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files + * created by gzip. (Files created by minigzip can still be extracted by + * gzip.) + */ +#ifndef MAX_WBITS +# define MAX_WBITS 15 /* 32K LZ77 window */ +#endif + +/* The memory requirements for deflate are (in bytes): + (1 << (windowBits+2)) + (1 << (memLevel+9)) + that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) + plus a few kilobytes for small objects. For example, if you want to reduce + the default memory requirements from 256K to 128K, compile with + make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" + Of course this will generally degrade compression (there's no free lunch). + + The memory requirements for inflate are (in bytes) 1 << windowBits + that is, 32K for windowBits=15 (default value) plus a few kilobytes + for small objects. +*/ + + /* Type declarations */ + +#ifndef OF /* function prototypes */ +# ifdef STDC +# define OF(args) args +# else +# define OF(args) () +# endif +#endif + +#ifndef Z_ARG /* function prototypes for stdarg */ +# if defined(STDC) || defined(Z_HAVE_STDARG_H) +# define Z_ARG(args) args +# else +# define Z_ARG(args) () +# endif +#endif + +/* The following definitions for FAR are needed only for MSDOS mixed + * model programming (small or medium model with some far allocations). + * This was tested only with MSC; for other MSDOS compilers you may have + * to define NO_MEMCPY in zutil.h. If you don't need the mixed model, + * just define FAR to be empty. + */ +#ifdef SYS16BIT +# if defined(M_I86SM) || defined(M_I86MM) + /* MSC small or medium model */ +# define SMALL_MEDIUM +# ifdef _MSC_VER +# define FAR _far +# else +# define FAR far +# endif +# endif +# if (defined(__SMALL__) || defined(__MEDIUM__)) + /* Turbo C small or medium model */ +# define SMALL_MEDIUM +# ifdef __BORLANDC__ +# define FAR _far +# else +# define FAR far +# endif +# endif +#endif + +#if defined(WINDOWS) || defined(WIN32) + /* If building or using zlib as a DLL, define ZLIB_DLL. + * This is not mandatory, but it offers a little performance increase. + */ +# ifdef ZLIB_DLL +# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500)) +# ifdef ZLIB_INTERNAL +# define ZEXTERN extern __declspec(dllexport) +# else +# define ZEXTERN extern __declspec(dllimport) +# endif +# endif +# endif /* ZLIB_DLL */ + /* If building or using zlib with the WINAPI/WINAPIV calling convention, + * define ZLIB_WINAPI. + * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI. + */ +# ifdef ZLIB_WINAPI +# ifdef FAR +# undef FAR +# endif +# include + /* No need for _export, use ZLIB.DEF instead. */ + /* For complete Windows compatibility, use WINAPI, not __stdcall. */ +# define ZEXPORT WINAPI +# ifdef WIN32 +# define ZEXPORTVA WINAPIV +# else +# define ZEXPORTVA FAR CDECL +# endif +# endif +#endif + +#if defined (__BEOS__) +# ifdef ZLIB_DLL +# ifdef ZLIB_INTERNAL +# define ZEXPORT __declspec(dllexport) +# define ZEXPORTVA __declspec(dllexport) +# else +# define ZEXPORT __declspec(dllimport) +# define ZEXPORTVA __declspec(dllimport) +# endif +# endif +#endif + +#ifndef ZEXTERN +# define ZEXTERN extern +#endif +#ifndef ZEXPORT +# define ZEXPORT +#endif +#ifndef ZEXPORTVA +# define ZEXPORTVA +#endif + +#ifndef FAR +# define FAR +#endif + +#if !defined(__MACTYPES__) +typedef unsigned char Byte; /* 8 bits */ +#endif +typedef unsigned int uInt; /* 16 bits or more */ +typedef unsigned long uLong; /* 32 bits or more */ + +#ifdef SMALL_MEDIUM + /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */ +# define Bytef Byte FAR +#else + typedef Byte FAR Bytef; +#endif +typedef char FAR charf; +typedef int FAR intf; +typedef uInt FAR uIntf; +typedef uLong FAR uLongf; + +#ifdef STDC + typedef void const *voidpc; + typedef void FAR *voidpf; + typedef void *voidp; +#else + typedef Byte const *voidpc; + typedef Byte FAR *voidpf; + typedef Byte *voidp; +#endif + +#ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */ +# define Z_HAVE_UNISTD_H +#endif + +#ifdef HAVE_STDARG_H /* may be set to #if 1 by ./configure */ +# define Z_HAVE_STDARG_H +#endif + +#ifdef STDC +# ifndef Z_SOLO +# include /* for off_t */ +# endif +#endif + +/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and + * "#define _LARGEFILE64_SOURCE 1" as requesting 64-bit operations, (even + * though the former does not conform to the LFS document), but considering + * both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as + * equivalently requesting no 64-bit operations + */ +#if -_LARGEFILE64_SOURCE - -1 == 1 +# undef _LARGEFILE64_SOURCE +#endif + +#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0 +# define Z_LARGE +#endif + +#if (defined(Z_HAVE_UNISTD_H) || defined(Z_LARGE)) && !defined(Z_SOLO) +# include /* for SEEK_* and off_t */ +# ifdef VMS +# include /* for off_t */ +# endif +# ifndef z_off_t +# define z_off_t off_t +# endif +#endif + +#if !defined(SEEK_SET) && !defined(Z_SOLO) +# define SEEK_SET 0 /* Seek from beginning of file. */ +# define SEEK_CUR 1 /* Seek from current position. */ +# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ +#endif + +#ifndef z_off_t +# define z_off_t long +#endif + +#if !defined(_WIN32) && (defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0) +# define z_off64_t off64_t +#else +# if defined(_WIN32) +# define z_off64_t __int64 +# else +# define z_off64_t z_off_t +#endif +#endif + +/* MVS linker does not support external names larger than 8 bytes */ +#if defined(__MVS__) + #pragma map(deflateInit_,"DEIN") + #pragma map(deflateInit2_,"DEIN2") + #pragma map(deflateEnd,"DEEND") + #pragma map(deflateBound,"DEBND") + #pragma map(inflateInit_,"ININ") + #pragma map(inflateInit2_,"ININ2") + #pragma map(inflateEnd,"INEND") + #pragma map(inflateSync,"INSY") + #pragma map(inflateSetDictionary,"INSEDI") + #pragma map(compressBound,"CMBND") + #pragma map(inflate_table,"INTABL") + #pragma map(inflate_fast,"INFA") + #pragma map(inflate_copyright,"INCOPY") +#endif + +#endif /* ZCONF_H */ diff --git a/libs/zlib/zconf.h.cmakein b/libs/zlib/zconf.h.cmakein new file mode 100644 index 000000000..3ea5531d5 --- /dev/null +++ b/libs/zlib/zconf.h.cmakein @@ -0,0 +1,468 @@ +/* zconf.h -- configuration of the zlib compression library + * Copyright (C) 1995-2011 Jean-loup Gailly. + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* @(#) $Id$ */ + +#ifndef ZCONF_H +#define ZCONF_H +#cmakedefine Z_PREFIX +#cmakedefine Z_HAVE_UNISTD_H + +/* + * If you *really* need a unique prefix for all types and library functions, + * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it. + * Even better than compiling with -DZ_PREFIX would be to use configure to set + * this permanently in zconf.h using "./configure --zprefix". + */ +#ifdef Z_PREFIX /* may be set to #if 1 by ./configure */ +# define Z_PREFIX_SET + +/* all linked symbols */ +# define _dist_code z__dist_code +# define _length_code z__length_code +# define _tr_align z__tr_align +# define _tr_flush_block z__tr_flush_block +# define _tr_init z__tr_init +# define _tr_stored_block z__tr_stored_block +# define _tr_tally z__tr_tally +# define adler32 z_adler32 +# define adler32_combine z_adler32_combine +# define adler32_combine64 z_adler32_combine64 +# ifndef Z_SOLO +# define compress z_compress +# define compress2 z_compress2 +# define compressBound z_compressBound +# endif +# define crc32 z_crc32 +# define crc32_combine z_crc32_combine +# define crc32_combine64 z_crc32_combine64 +# define deflate z_deflate +# define deflateBound z_deflateBound +# define deflateCopy z_deflateCopy +# define deflateEnd z_deflateEnd +# define deflateInit2_ z_deflateInit2_ +# define deflateInit_ z_deflateInit_ +# define deflateParams z_deflateParams +# define deflatePending z_deflatePending +# define deflatePrime z_deflatePrime +# define deflateReset z_deflateReset +# define deflateResetKeep z_deflateResetKeep +# define deflateSetDictionary z_deflateSetDictionary +# define deflateSetHeader z_deflateSetHeader +# define deflateTune z_deflateTune +# define deflate_copyright z_deflate_copyright +# define get_crc_table z_get_crc_table +# ifndef Z_SOLO +# define gz_error z_gz_error +# define gz_intmax z_gz_intmax +# define gz_strwinerror z_gz_strwinerror +# define gzbuffer z_gzbuffer +# define gzclearerr z_gzclearerr +# define gzclose z_gzclose +# define gzclose_r z_gzclose_r +# define gzclose_w z_gzclose_w +# define gzdirect z_gzdirect +# define gzdopen z_gzdopen +# define gzeof z_gzeof +# define gzerror z_gzerror +# define gzflags z_gzflags +# define gzflush z_gzflush +# define gzgetc z_gzgetc +# define gzgetc_ z_gzgetc_ +# define gzgets z_gzgets +# define gzoffset z_gzoffset +# define gzoffset64 z_gzoffset64 +# define gzopen z_gzopen +# define gzopen64 z_gzopen64 +# define gzprintf z_gzprintf +# define gzputc z_gzputc +# define gzputs z_gzputs +# define gzread z_gzread +# define gzrewind z_gzrewind +# define gzseek z_gzseek +# define gzseek64 z_gzseek64 +# define gzsetparams z_gzsetparams +# define gztell z_gztell +# define gztell64 z_gztell64 +# define gzungetc z_gzungetc +# define gzwrite z_gzwrite +# endif +# define inflate z_inflate +# define inflateBack z_inflateBack +# define inflateBackEnd z_inflateBackEnd +# define inflateBackInit_ z_inflateBackInit_ +# define inflateCopy z_inflateCopy +# define inflateEnd z_inflateEnd +# define inflateGetHeader z_inflateGetHeader +# define inflateInit2_ z_inflateInit2_ +# define inflateInit_ z_inflateInit_ +# define inflateMark z_inflateMark +# define inflatePrime z_inflatePrime +# define inflateReset z_inflateReset +# define inflateReset2 z_inflateReset2 +# define inflateSetDictionary z_inflateSetDictionary +# define inflateSync z_inflateSync +# define inflateSyncPoint z_inflateSyncPoint +# define inflateUndermine z_inflateUndermine +# define inflateResetKeep z_inflateResetKeep +# define inflate_copyright z_inflate_copyright +# define inflate_fast z_inflate_fast +# define inflate_table z_inflate_table +# ifndef Z_SOLO +# define uncompress z_uncompress +# endif +# define zError z_zError +# ifndef Z_SOLO +# define zcalloc z_zcalloc +# define zcfree z_zcfree +# endif +# define zlibCompileFlags z_zlibCompileFlags +# define zlibVersion z_zlibVersion + +/* all zlib typedefs in zlib.h and zconf.h */ +# define Byte z_Byte +# define Bytef z_Bytef +# define alloc_func z_alloc_func +# define charf z_charf +# define free_func z_free_func +# ifndef Z_SOLO +# define gzFile z_gzFile +# define gz_header z_gz_header +# define gz_headerp z_gz_headerp +# endif +# define in_func z_in_func +# define intf z_intf +# define out_func z_out_func +# define uInt z_uInt +# define uIntf z_uIntf +# define uLong z_uLong +# define uLongf z_uLongf +# define voidp z_voidp +# define voidpc z_voidpc +# define voidpf z_voidpf + +/* all zlib structs in zlib.h and zconf.h */ +# ifndef Z_SOLO +# define gz_header_s z_gz_header_s +# endif +# define internal_state z_internal_state + +#endif + +#if defined(__MSDOS__) && !defined(MSDOS) +# define MSDOS +#endif +#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2) +# define OS2 +#endif +#if defined(_WINDOWS) && !defined(WINDOWS) +# define WINDOWS +#endif +#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__) +# ifndef WIN32 +# define WIN32 +# endif +#endif +#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32) +# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__) +# ifndef SYS16BIT +# define SYS16BIT +# endif +# endif +#endif + +/* + * Compile with -DMAXSEG_64K if the alloc function cannot allocate more + * than 64k bytes at a time (needed on systems with 16-bit int). + */ +#ifdef SYS16BIT +# define MAXSEG_64K +#endif +#ifdef MSDOS +# define UNALIGNED_OK +#endif + +#ifdef __STDC_VERSION__ +# ifndef STDC +# define STDC +# endif +# if __STDC_VERSION__ >= 199901L +# ifndef STDC99 +# define STDC99 +# endif +# endif +#endif +#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus)) +# define STDC +#endif +#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__)) +# define STDC +#endif +#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32)) +# define STDC +#endif +#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__)) +# define STDC +#endif + +#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */ +# define STDC +#endif + +#ifndef STDC +# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ +# define const /* note: need a more gentle solution here */ +# endif +#endif + +#if defined(ZLIB_CONST) && !defined(z_const) +# define z_const const +#else +# define z_const +#endif + +/* Some Mac compilers merge all .h files incorrectly: */ +#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__) +# define NO_DUMMY_DECL +#endif + +/* Maximum value for memLevel in deflateInit2 */ +#ifndef MAX_MEM_LEVEL +# ifdef MAXSEG_64K +# define MAX_MEM_LEVEL 8 +# else +# define MAX_MEM_LEVEL 9 +# endif +#endif + +/* Maximum value for windowBits in deflateInit2 and inflateInit2. + * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files + * created by gzip. (Files created by minigzip can still be extracted by + * gzip.) + */ +#ifndef MAX_WBITS +# define MAX_WBITS 15 /* 32K LZ77 window */ +#endif + +/* The memory requirements for deflate are (in bytes): + (1 << (windowBits+2)) + (1 << (memLevel+9)) + that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) + plus a few kilobytes for small objects. For example, if you want to reduce + the default memory requirements from 256K to 128K, compile with + make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" + Of course this will generally degrade compression (there's no free lunch). + + The memory requirements for inflate are (in bytes) 1 << windowBits + that is, 32K for windowBits=15 (default value) plus a few kilobytes + for small objects. +*/ + + /* Type declarations */ + +#ifndef OF /* function prototypes */ +# ifdef STDC +# define OF(args) args +# else +# define OF(args) () +# endif +#endif + +#ifndef Z_ARG /* function prototypes for stdarg */ +# if defined(STDC) || defined(Z_HAVE_STDARG_H) +# define Z_ARG(args) args +# else +# define Z_ARG(args) () +# endif +#endif + +/* The following definitions for FAR are needed only for MSDOS mixed + * model programming (small or medium model with some far allocations). + * This was tested only with MSC; for other MSDOS compilers you may have + * to define NO_MEMCPY in zutil.h. If you don't need the mixed model, + * just define FAR to be empty. + */ +#ifdef SYS16BIT +# if defined(M_I86SM) || defined(M_I86MM) + /* MSC small or medium model */ +# define SMALL_MEDIUM +# ifdef _MSC_VER +# define FAR _far +# else +# define FAR far +# endif +# endif +# if (defined(__SMALL__) || defined(__MEDIUM__)) + /* Turbo C small or medium model */ +# define SMALL_MEDIUM +# ifdef __BORLANDC__ +# define FAR _far +# else +# define FAR far +# endif +# endif +#endif + +#if defined(WINDOWS) || defined(WIN32) + /* If building or using zlib as a DLL, define ZLIB_DLL. + * This is not mandatory, but it offers a little performance increase. + */ +# ifdef ZLIB_DLL +# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500)) +# ifdef ZLIB_INTERNAL +# define ZEXTERN extern __declspec(dllexport) +# else +# define ZEXTERN extern __declspec(dllimport) +# endif +# endif +# endif /* ZLIB_DLL */ + /* If building or using zlib with the WINAPI/WINAPIV calling convention, + * define ZLIB_WINAPI. + * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI. + */ +# ifdef ZLIB_WINAPI +# ifdef FAR +# undef FAR +# endif +# include + /* No need for _export, use ZLIB.DEF instead. */ + /* For complete Windows compatibility, use WINAPI, not __stdcall. */ +# define ZEXPORT WINAPI +# ifdef WIN32 +# define ZEXPORTVA WINAPIV +# else +# define ZEXPORTVA FAR CDECL +# endif +# endif +#endif + +#if defined (__BEOS__) +# ifdef ZLIB_DLL +# ifdef ZLIB_INTERNAL +# define ZEXPORT __declspec(dllexport) +# define ZEXPORTVA __declspec(dllexport) +# else +# define ZEXPORT __declspec(dllimport) +# define ZEXPORTVA __declspec(dllimport) +# endif +# endif +#endif + +#ifndef ZEXTERN +# define ZEXTERN extern +#endif +#ifndef ZEXPORT +# define ZEXPORT +#endif +#ifndef ZEXPORTVA +# define ZEXPORTVA +#endif + +#ifndef FAR +# define FAR +#endif + +#if !defined(__MACTYPES__) +typedef unsigned char Byte; /* 8 bits */ +#endif +typedef unsigned int uInt; /* 16 bits or more */ +typedef unsigned long uLong; /* 32 bits or more */ + +#ifdef SMALL_MEDIUM + /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */ +# define Bytef Byte FAR +#else + typedef Byte FAR Bytef; +#endif +typedef char FAR charf; +typedef int FAR intf; +typedef uInt FAR uIntf; +typedef uLong FAR uLongf; + +#ifdef STDC + typedef void const *voidpc; + typedef void FAR *voidpf; + typedef void *voidp; +#else + typedef Byte const *voidpc; + typedef Byte FAR *voidpf; + typedef Byte *voidp; +#endif + +#ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */ +# define Z_HAVE_UNISTD_H +#endif + +#ifdef HAVE_STDARG_H /* may be set to #if 1 by ./configure */ +# define Z_HAVE_STDARG_H +#endif + +#ifdef STDC +# ifndef Z_SOLO +# include /* for off_t */ +# endif +#endif + +/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and + * "#define _LARGEFILE64_SOURCE 1" as requesting 64-bit operations, (even + * though the former does not conform to the LFS document), but considering + * both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as + * equivalently requesting no 64-bit operations + */ +#if -_LARGEFILE64_SOURCE - -1 == 1 +# undef _LARGEFILE64_SOURCE +#endif + +#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0 +# define Z_LARGE +#endif + +#if (defined(Z_HAVE_UNISTD_H) || defined(Z_LARGE)) && !defined(Z_SOLO) +# include /* for SEEK_* and off_t */ +# ifdef VMS +# include /* for off_t */ +# endif +# ifndef z_off_t +# define z_off_t off_t +# endif +#endif + +#if !defined(SEEK_SET) && !defined(Z_SOLO) +# define SEEK_SET 0 /* Seek from beginning of file. */ +# define SEEK_CUR 1 /* Seek from current position. */ +# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ +#endif + +#ifndef z_off_t +# define z_off_t long +#endif + +#if !defined(_WIN32) && (defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0) +# define z_off64_t off64_t +#else +# if defined(_WIN32) +# define z_off64_t __int64 +# else +# define z_off64_t z_off_t +#endif +#endif + +/* MVS linker does not support external names larger than 8 bytes */ +#if defined(__MVS__) + #pragma map(deflateInit_,"DEIN") + #pragma map(deflateInit2_,"DEIN2") + #pragma map(deflateEnd,"DEEND") + #pragma map(deflateBound,"DEBND") + #pragma map(inflateInit_,"ININ") + #pragma map(inflateInit2_,"ININ2") + #pragma map(inflateEnd,"INEND") + #pragma map(inflateSync,"INSY") + #pragma map(inflateSetDictionary,"INSEDI") + #pragma map(compressBound,"CMBND") + #pragma map(inflate_table,"INTABL") + #pragma map(inflate_fast,"INFA") + #pragma map(inflate_copyright,"INCOPY") +#endif + +#endif /* ZCONF_H */ diff --git a/libs/zlib/zconf.h.in b/libs/zlib/zconf.h.in new file mode 100644 index 000000000..51c80ac14 --- /dev/null +++ b/libs/zlib/zconf.h.in @@ -0,0 +1,466 @@ +/* zconf.h -- configuration of the zlib compression library + * Copyright (C) 1995-2011 Jean-loup Gailly. + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* @(#) $Id$ */ + +#ifndef ZCONF_H +#define ZCONF_H + +/* + * If you *really* need a unique prefix for all types and library functions, + * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it. + * Even better than compiling with -DZ_PREFIX would be to use configure to set + * this permanently in zconf.h using "./configure --zprefix". + */ +#ifdef Z_PREFIX /* may be set to #if 1 by ./configure */ +# define Z_PREFIX_SET + +/* all linked symbols */ +# define _dist_code z__dist_code +# define _length_code z__length_code +# define _tr_align z__tr_align +# define _tr_flush_block z__tr_flush_block +# define _tr_init z__tr_init +# define _tr_stored_block z__tr_stored_block +# define _tr_tally z__tr_tally +# define adler32 z_adler32 +# define adler32_combine z_adler32_combine +# define adler32_combine64 z_adler32_combine64 +# ifndef Z_SOLO +# define compress z_compress +# define compress2 z_compress2 +# define compressBound z_compressBound +# endif +# define crc32 z_crc32 +# define crc32_combine z_crc32_combine +# define crc32_combine64 z_crc32_combine64 +# define deflate z_deflate +# define deflateBound z_deflateBound +# define deflateCopy z_deflateCopy +# define deflateEnd z_deflateEnd +# define deflateInit2_ z_deflateInit2_ +# define deflateInit_ z_deflateInit_ +# define deflateParams z_deflateParams +# define deflatePending z_deflatePending +# define deflatePrime z_deflatePrime +# define deflateReset z_deflateReset +# define deflateResetKeep z_deflateResetKeep +# define deflateSetDictionary z_deflateSetDictionary +# define deflateSetHeader z_deflateSetHeader +# define deflateTune z_deflateTune +# define deflate_copyright z_deflate_copyright +# define get_crc_table z_get_crc_table +# ifndef Z_SOLO +# define gz_error z_gz_error +# define gz_intmax z_gz_intmax +# define gz_strwinerror z_gz_strwinerror +# define gzbuffer z_gzbuffer +# define gzclearerr z_gzclearerr +# define gzclose z_gzclose +# define gzclose_r z_gzclose_r +# define gzclose_w z_gzclose_w +# define gzdirect z_gzdirect +# define gzdopen z_gzdopen +# define gzeof z_gzeof +# define gzerror z_gzerror +# define gzflags z_gzflags +# define gzflush z_gzflush +# define gzgetc z_gzgetc +# define gzgetc_ z_gzgetc_ +# define gzgets z_gzgets +# define gzoffset z_gzoffset +# define gzoffset64 z_gzoffset64 +# define gzopen z_gzopen +# define gzopen64 z_gzopen64 +# define gzprintf z_gzprintf +# define gzputc z_gzputc +# define gzputs z_gzputs +# define gzread z_gzread +# define gzrewind z_gzrewind +# define gzseek z_gzseek +# define gzseek64 z_gzseek64 +# define gzsetparams z_gzsetparams +# define gztell z_gztell +# define gztell64 z_gztell64 +# define gzungetc z_gzungetc +# define gzwrite z_gzwrite +# endif +# define inflate z_inflate +# define inflateBack z_inflateBack +# define inflateBackEnd z_inflateBackEnd +# define inflateBackInit_ z_inflateBackInit_ +# define inflateCopy z_inflateCopy +# define inflateEnd z_inflateEnd +# define inflateGetHeader z_inflateGetHeader +# define inflateInit2_ z_inflateInit2_ +# define inflateInit_ z_inflateInit_ +# define inflateMark z_inflateMark +# define inflatePrime z_inflatePrime +# define inflateReset z_inflateReset +# define inflateReset2 z_inflateReset2 +# define inflateSetDictionary z_inflateSetDictionary +# define inflateSync z_inflateSync +# define inflateSyncPoint z_inflateSyncPoint +# define inflateUndermine z_inflateUndermine +# define inflateResetKeep z_inflateResetKeep +# define inflate_copyright z_inflate_copyright +# define inflate_fast z_inflate_fast +# define inflate_table z_inflate_table +# ifndef Z_SOLO +# define uncompress z_uncompress +# endif +# define zError z_zError +# ifndef Z_SOLO +# define zcalloc z_zcalloc +# define zcfree z_zcfree +# endif +# define zlibCompileFlags z_zlibCompileFlags +# define zlibVersion z_zlibVersion + +/* all zlib typedefs in zlib.h and zconf.h */ +# define Byte z_Byte +# define Bytef z_Bytef +# define alloc_func z_alloc_func +# define charf z_charf +# define free_func z_free_func +# ifndef Z_SOLO +# define gzFile z_gzFile +# define gz_header z_gz_header +# define gz_headerp z_gz_headerp +# endif +# define in_func z_in_func +# define intf z_intf +# define out_func z_out_func +# define uInt z_uInt +# define uIntf z_uIntf +# define uLong z_uLong +# define uLongf z_uLongf +# define voidp z_voidp +# define voidpc z_voidpc +# define voidpf z_voidpf + +/* all zlib structs in zlib.h and zconf.h */ +# ifndef Z_SOLO +# define gz_header_s z_gz_header_s +# endif +# define internal_state z_internal_state + +#endif + +#if defined(__MSDOS__) && !defined(MSDOS) +# define MSDOS +#endif +#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2) +# define OS2 +#endif +#if defined(_WINDOWS) && !defined(WINDOWS) +# define WINDOWS +#endif +#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__) +# ifndef WIN32 +# define WIN32 +# endif +#endif +#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32) +# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__) +# ifndef SYS16BIT +# define SYS16BIT +# endif +# endif +#endif + +/* + * Compile with -DMAXSEG_64K if the alloc function cannot allocate more + * than 64k bytes at a time (needed on systems with 16-bit int). + */ +#ifdef SYS16BIT +# define MAXSEG_64K +#endif +#ifdef MSDOS +# define UNALIGNED_OK +#endif + +#ifdef __STDC_VERSION__ +# ifndef STDC +# define STDC +# endif +# if __STDC_VERSION__ >= 199901L +# ifndef STDC99 +# define STDC99 +# endif +# endif +#endif +#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus)) +# define STDC +#endif +#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__)) +# define STDC +#endif +#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32)) +# define STDC +#endif +#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__)) +# define STDC +#endif + +#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */ +# define STDC +#endif + +#ifndef STDC +# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ +# define const /* note: need a more gentle solution here */ +# endif +#endif + +#if defined(ZLIB_CONST) && !defined(z_const) +# define z_const const +#else +# define z_const +#endif + +/* Some Mac compilers merge all .h files incorrectly: */ +#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__) +# define NO_DUMMY_DECL +#endif + +/* Maximum value for memLevel in deflateInit2 */ +#ifndef MAX_MEM_LEVEL +# ifdef MAXSEG_64K +# define MAX_MEM_LEVEL 8 +# else +# define MAX_MEM_LEVEL 9 +# endif +#endif + +/* Maximum value for windowBits in deflateInit2 and inflateInit2. + * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files + * created by gzip. (Files created by minigzip can still be extracted by + * gzip.) + */ +#ifndef MAX_WBITS +# define MAX_WBITS 15 /* 32K LZ77 window */ +#endif + +/* The memory requirements for deflate are (in bytes): + (1 << (windowBits+2)) + (1 << (memLevel+9)) + that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) + plus a few kilobytes for small objects. For example, if you want to reduce + the default memory requirements from 256K to 128K, compile with + make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" + Of course this will generally degrade compression (there's no free lunch). + + The memory requirements for inflate are (in bytes) 1 << windowBits + that is, 32K for windowBits=15 (default value) plus a few kilobytes + for small objects. +*/ + + /* Type declarations */ + +#ifndef OF /* function prototypes */ +# ifdef STDC +# define OF(args) args +# else +# define OF(args) () +# endif +#endif + +#ifndef Z_ARG /* function prototypes for stdarg */ +# if defined(STDC) || defined(Z_HAVE_STDARG_H) +# define Z_ARG(args) args +# else +# define Z_ARG(args) () +# endif +#endif + +/* The following definitions for FAR are needed only for MSDOS mixed + * model programming (small or medium model with some far allocations). + * This was tested only with MSC; for other MSDOS compilers you may have + * to define NO_MEMCPY in zutil.h. If you don't need the mixed model, + * just define FAR to be empty. + */ +#ifdef SYS16BIT +# if defined(M_I86SM) || defined(M_I86MM) + /* MSC small or medium model */ +# define SMALL_MEDIUM +# ifdef _MSC_VER +# define FAR _far +# else +# define FAR far +# endif +# endif +# if (defined(__SMALL__) || defined(__MEDIUM__)) + /* Turbo C small or medium model */ +# define SMALL_MEDIUM +# ifdef __BORLANDC__ +# define FAR _far +# else +# define FAR far +# endif +# endif +#endif + +#if defined(WINDOWS) || defined(WIN32) + /* If building or using zlib as a DLL, define ZLIB_DLL. + * This is not mandatory, but it offers a little performance increase. + */ +# ifdef ZLIB_DLL +# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500)) +# ifdef ZLIB_INTERNAL +# define ZEXTERN extern __declspec(dllexport) +# else +# define ZEXTERN extern __declspec(dllimport) +# endif +# endif +# endif /* ZLIB_DLL */ + /* If building or using zlib with the WINAPI/WINAPIV calling convention, + * define ZLIB_WINAPI. + * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI. + */ +# ifdef ZLIB_WINAPI +# ifdef FAR +# undef FAR +# endif +# include + /* No need for _export, use ZLIB.DEF instead. */ + /* For complete Windows compatibility, use WINAPI, not __stdcall. */ +# define ZEXPORT WINAPI +# ifdef WIN32 +# define ZEXPORTVA WINAPIV +# else +# define ZEXPORTVA FAR CDECL +# endif +# endif +#endif + +#if defined (__BEOS__) +# ifdef ZLIB_DLL +# ifdef ZLIB_INTERNAL +# define ZEXPORT __declspec(dllexport) +# define ZEXPORTVA __declspec(dllexport) +# else +# define ZEXPORT __declspec(dllimport) +# define ZEXPORTVA __declspec(dllimport) +# endif +# endif +#endif + +#ifndef ZEXTERN +# define ZEXTERN extern +#endif +#ifndef ZEXPORT +# define ZEXPORT +#endif +#ifndef ZEXPORTVA +# define ZEXPORTVA +#endif + +#ifndef FAR +# define FAR +#endif + +#if !defined(__MACTYPES__) +typedef unsigned char Byte; /* 8 bits */ +#endif +typedef unsigned int uInt; /* 16 bits or more */ +typedef unsigned long uLong; /* 32 bits or more */ + +#ifdef SMALL_MEDIUM + /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */ +# define Bytef Byte FAR +#else + typedef Byte FAR Bytef; +#endif +typedef char FAR charf; +typedef int FAR intf; +typedef uInt FAR uIntf; +typedef uLong FAR uLongf; + +#ifdef STDC + typedef void const *voidpc; + typedef void FAR *voidpf; + typedef void *voidp; +#else + typedef Byte const *voidpc; + typedef Byte FAR *voidpf; + typedef Byte *voidp; +#endif + +#ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */ +# define Z_HAVE_UNISTD_H +#endif + +#ifdef HAVE_STDARG_H /* may be set to #if 1 by ./configure */ +# define Z_HAVE_STDARG_H +#endif + +#ifdef STDC +# ifndef Z_SOLO +# include /* for off_t */ +# endif +#endif + +/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and + * "#define _LARGEFILE64_SOURCE 1" as requesting 64-bit operations, (even + * though the former does not conform to the LFS document), but considering + * both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as + * equivalently requesting no 64-bit operations + */ +#if -_LARGEFILE64_SOURCE - -1 == 1 +# undef _LARGEFILE64_SOURCE +#endif + +#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0 +# define Z_LARGE +#endif + +#if (defined(Z_HAVE_UNISTD_H) || defined(Z_LARGE)) && !defined(Z_SOLO) +# include /* for SEEK_* and off_t */ +# ifdef VMS +# include /* for off_t */ +# endif +# ifndef z_off_t +# define z_off_t off_t +# endif +#endif + +#if !defined(SEEK_SET) && !defined(Z_SOLO) +# define SEEK_SET 0 /* Seek from beginning of file. */ +# define SEEK_CUR 1 /* Seek from current position. */ +# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ +#endif + +#ifndef z_off_t +# define z_off_t long +#endif + +#if !defined(_WIN32) && (defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0) +# define z_off64_t off64_t +#else +# if defined(_WIN32) +# define z_off64_t __int64 +# else +# define z_off64_t z_off_t +#endif +#endif + +/* MVS linker does not support external names larger than 8 bytes */ +#if defined(__MVS__) + #pragma map(deflateInit_,"DEIN") + #pragma map(deflateInit2_,"DEIN2") + #pragma map(deflateEnd,"DEEND") + #pragma map(deflateBound,"DEBND") + #pragma map(inflateInit_,"ININ") + #pragma map(inflateInit2_,"ININ2") + #pragma map(inflateEnd,"INEND") + #pragma map(inflateSync,"INSY") + #pragma map(inflateSetDictionary,"INSEDI") + #pragma map(compressBound,"CMBND") + #pragma map(inflate_table,"INTABL") + #pragma map(inflate_fast,"INFA") + #pragma map(inflate_copyright,"INCOPY") +#endif + +#endif /* ZCONF_H */ diff --git a/libs/zlib/zlib.3 b/libs/zlib/zlib.3 new file mode 100644 index 000000000..d051c79b5 --- /dev/null +++ b/libs/zlib/zlib.3 @@ -0,0 +1,151 @@ +.TH ZLIB 3 "29 Jan 2012" +.SH NAME +zlib \- compression/decompression library +.SH SYNOPSIS +[see +.I zlib.h +for full description] +.SH DESCRIPTION +The +.I zlib +library is a general purpose data compression library. +The code is thread safe, assuming that the standard library functions +used are thread safe, such as memory allocation routines. +It provides in-memory compression and decompression functions, +including integrity checks of the uncompressed data. +This version of the library supports only one compression method (deflation) +but other algorithms may be added later +with the same stream interface. +.LP +Compression can be done in a single step if the buffers are large enough +or can be done by repeated calls of the compression function. +In the latter case, +the application must provide more input and/or consume the output +(providing more output space) before each call. +.LP +The library also supports reading and writing files in +.IR gzip (1) +(.gz) format +with an interface similar to that of stdio. +.LP +The library does not install any signal handler. +The decoder checks the consistency of the compressed data, +so the library should never crash even in the case of corrupted input. +.LP +All functions of the compression library are documented in the file +.IR zlib.h . +The distribution source includes examples of use of the library +in the files +.I test/example.c +and +.IR test/minigzip.c, +as well as other examples in the +.IR examples/ +directory. +.LP +Changes to this version are documented in the file +.I ChangeLog +that accompanies the source. +.LP +.I zlib +is available in Java using the java.util.zip package: +.IP +http://java.sun.com/developer/technicalArticles/Programming/compression/ +.LP +A Perl interface to +.IR zlib , +written by Paul Marquess (pmqs@cpan.org), +is available at CPAN (Comprehensive Perl Archive Network) sites, +including: +.IP +http://search.cpan.org/~pmqs/IO-Compress-Zlib/ +.LP +A Python interface to +.IR zlib , +written by A.M. Kuchling (amk@magnet.com), +is available in Python 1.5 and later versions: +.IP +http://docs.python.org/library/zlib.html +.LP +.I zlib +is built into +.IR tcl: +.IP +http://wiki.tcl.tk/4610 +.LP +An experimental package to read and write files in .zip format, +written on top of +.I zlib +by Gilles Vollant (info@winimage.com), +is available at: +.IP +http://www.winimage.com/zLibDll/minizip.html +and also in the +.I contrib/minizip +directory of the main +.I zlib +source distribution. +.SH "SEE ALSO" +The +.I zlib +web site can be found at: +.IP +http://zlib.net/ +.LP +The data format used by the zlib library is described by RFC +(Request for Comments) 1950 to 1952 in the files: +.IP +http://tools.ietf.org/html/rfc1950 (for the zlib header and trailer format) +.br +http://tools.ietf.org/html/rfc1951 (for the deflate compressed data format) +.br +http://tools.ietf.org/html/rfc1952 (for the gzip header and trailer format) +.LP +Mark Nelson wrote an article about +.I zlib +for the Jan. 1997 issue of Dr. Dobb's Journal; +a copy of the article is available at: +.IP +http://marknelson.us/1997/01/01/zlib-engine/ +.SH "REPORTING PROBLEMS" +Before reporting a problem, +please check the +.I zlib +web site to verify that you have the latest version of +.IR zlib ; +otherwise, +obtain the latest version and see if the problem still exists. +Please read the +.I zlib +FAQ at: +.IP +http://zlib.net/zlib_faq.html +.LP +before asking for help. +Send questions and/or comments to zlib@gzip.org, +or (for the Windows DLL version) to Gilles Vollant (info@winimage.com). +.SH AUTHORS +Version 1.2.6 +Copyright (C) 1995-2012 Jean-loup Gailly (jloup@gzip.org) +and Mark Adler (madler@alumni.caltech.edu). +.LP +This software is provided "as-is," +without any express or implied warranty. +In no event will the authors be held liable for any damages +arising from the use of this software. +See the distribution directory with respect to requirements +governing redistribution. +The deflate format used by +.I zlib +was defined by Phil Katz. +The deflate and +.I zlib +specifications were written by L. Peter Deutsch. +Thanks to all the people who reported problems and suggested various +improvements in +.IR zlib ; +who are too numerous to cite here. +.LP +UNIX manual page by R. P. C. Rodgers, +U.S. National Library of Medicine (rodgers@nlm.nih.gov). +.\" end of man page diff --git a/libs/zlib/zlib.3.pdf b/libs/zlib/zlib.3.pdf new file mode 100644 index 000000000..9f8a2c399 Binary files /dev/null and b/libs/zlib/zlib.3.pdf differ diff --git a/libs/zlib/zlib.h b/libs/zlib/zlib.h new file mode 100644 index 000000000..79142d117 --- /dev/null +++ b/libs/zlib/zlib.h @@ -0,0 +1,1732 @@ +/* zlib.h -- interface of the 'zlib' general purpose compression library + version 1.2.6, January 29th, 2012 + + Copyright (C) 1995-2012 Jean-loup Gailly and Mark Adler + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Jean-loup Gailly Mark Adler + jloup@gzip.org madler@alumni.caltech.edu + + + The data format used by the zlib library is described by RFCs (Request for + Comments) 1950 to 1952 in the files http://tools.ietf.org/html/rfc1950 + (zlib format), rfc1951 (deflate format) and rfc1952 (gzip format). +*/ + +#ifndef ZLIB_H +#define ZLIB_H + +#include "zconf.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define ZLIB_VERSION "1.2.6" +#define ZLIB_VERNUM 0x1260 +#define ZLIB_VER_MAJOR 1 +#define ZLIB_VER_MINOR 2 +#define ZLIB_VER_REVISION 6 +#define ZLIB_VER_SUBREVISION 0 + +/* + The 'zlib' compression library provides in-memory compression and + decompression functions, including integrity checks of the uncompressed data. + This version of the library supports only one compression method (deflation) + but other algorithms will be added later and will have the same stream + interface. + + Compression can be done in a single step if the buffers are large enough, + or can be done by repeated calls of the compression function. In the latter + case, the application must provide more input and/or consume the output + (providing more output space) before each call. + + The compressed data format used by default by the in-memory functions is + the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped + around a deflate stream, which is itself documented in RFC 1951. + + The library also supports reading and writing files in gzip (.gz) format + with an interface similar to that of stdio using the functions that start + with "gz". The gzip format is different from the zlib format. gzip is a + gzip wrapper, documented in RFC 1952, wrapped around a deflate stream. + + This library can optionally read and write gzip streams in memory as well. + + The zlib format was designed to be compact and fast for use in memory + and on communications channels. The gzip format was designed for single- + file compression on file systems, has a larger header than zlib to maintain + directory information, and uses a different, slower check method than zlib. + + The library does not install any signal handler. The decoder checks + the consistency of the compressed data, so the library should never crash + even in case of corrupted input. +*/ + +typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); +typedef void (*free_func) OF((voidpf opaque, voidpf address)); + +struct internal_state; + +typedef struct z_stream_s { + z_const Bytef *next_in; /* next input byte */ + uInt avail_in; /* number of bytes available at next_in */ + uLong total_in; /* total number of input bytes read so far */ + + Bytef *next_out; /* next output byte should be put there */ + uInt avail_out; /* remaining free space at next_out */ + uLong total_out; /* total number of bytes output so far */ + + z_const char *msg; /* last error message, NULL if no error */ + struct internal_state FAR *state; /* not visible by applications */ + + alloc_func zalloc; /* used to allocate the internal state */ + free_func zfree; /* used to free the internal state */ + voidpf opaque; /* private data object passed to zalloc and zfree */ + + int data_type; /* best guess about the data type: binary or text */ + uLong adler; /* adler32 value of the uncompressed data */ + uLong reserved; /* reserved for future use */ +} z_stream; + +typedef z_stream FAR *z_streamp; + +/* + gzip header information passed to and from zlib routines. See RFC 1952 + for more details on the meanings of these fields. +*/ +typedef struct gz_header_s { + int text; /* true if compressed data believed to be text */ + uLong time; /* modification time */ + int xflags; /* extra flags (not used when writing a gzip file) */ + int os; /* operating system */ + Bytef *extra; /* pointer to extra field or Z_NULL if none */ + uInt extra_len; /* extra field length (valid if extra != Z_NULL) */ + uInt extra_max; /* space at extra (only when reading header) */ + Bytef *name; /* pointer to zero-terminated file name or Z_NULL */ + uInt name_max; /* space at name (only when reading header) */ + Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */ + uInt comm_max; /* space at comment (only when reading header) */ + int hcrc; /* true if there was or will be a header crc */ + int done; /* true when done reading gzip header (not used + when writing a gzip file) */ +} gz_header; + +typedef gz_header FAR *gz_headerp; + +/* + The application must update next_in and avail_in when avail_in has dropped + to zero. It must update next_out and avail_out when avail_out has dropped + to zero. The application must initialize zalloc, zfree and opaque before + calling the init function. All other fields are set by the compression + library and must not be updated by the application. + + The opaque value provided by the application will be passed as the first + parameter for calls of zalloc and zfree. This can be useful for custom + memory management. The compression library attaches no meaning to the + opaque value. + + zalloc must return Z_NULL if there is not enough memory for the object. + If zlib is used in a multi-threaded application, zalloc and zfree must be + thread safe. + + On 16-bit systems, the functions zalloc and zfree must be able to allocate + exactly 65536 bytes, but will not be required to allocate more than this if + the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, pointers + returned by zalloc for objects of exactly 65536 bytes *must* have their + offset normalized to zero. The default allocation function provided by this + library ensures this (see zutil.c). To reduce memory requirements and avoid + any allocation of 64K objects, at the expense of compression ratio, compile + the library with -DMAX_WBITS=14 (see zconf.h). + + The fields total_in and total_out can be used for statistics or progress + reports. After compression, total_in holds the total size of the + uncompressed data and may be saved for use in the decompressor (particularly + if the decompressor wants to decompress everything in a single step). +*/ + + /* constants */ + +#define Z_NO_FLUSH 0 +#define Z_PARTIAL_FLUSH 1 +#define Z_SYNC_FLUSH 2 +#define Z_FULL_FLUSH 3 +#define Z_FINISH 4 +#define Z_BLOCK 5 +#define Z_TREES 6 +/* Allowed flush values; see deflate() and inflate() below for details */ + +#define Z_OK 0 +#define Z_STREAM_END 1 +#define Z_NEED_DICT 2 +#define Z_ERRNO (-1) +#define Z_STREAM_ERROR (-2) +#define Z_DATA_ERROR (-3) +#define Z_MEM_ERROR (-4) +#define Z_BUF_ERROR (-5) +#define Z_VERSION_ERROR (-6) +/* Return codes for the compression/decompression functions. Negative values + * are errors, positive values are used for special but normal events. + */ + +#define Z_NO_COMPRESSION 0 +#define Z_BEST_SPEED 1 +#define Z_BEST_COMPRESSION 9 +#define Z_DEFAULT_COMPRESSION (-1) +/* compression levels */ + +#define Z_FILTERED 1 +#define Z_HUFFMAN_ONLY 2 +#define Z_RLE 3 +#define Z_FIXED 4 +#define Z_DEFAULT_STRATEGY 0 +/* compression strategy; see deflateInit2() below for details */ + +#define Z_BINARY 0 +#define Z_TEXT 1 +#define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */ +#define Z_UNKNOWN 2 +/* Possible values of the data_type field (though see inflate()) */ + +#define Z_DEFLATED 8 +/* The deflate compression method (the only one supported in this version) */ + +#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ + +#define zlib_version zlibVersion() +/* for compatibility with versions < 1.0.2 */ + + + /* basic functions */ + +ZEXTERN const char * ZEXPORT zlibVersion OF((void)); +/* The application can compare zlibVersion and ZLIB_VERSION for consistency. + If the first character differs, the library code actually used is not + compatible with the zlib.h header file used by the application. This check + is automatically made by deflateInit and inflateInit. + */ + +/* +ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level)); + + Initializes the internal stream state for compression. The fields + zalloc, zfree and opaque must be initialized before by the caller. If + zalloc and zfree are set to Z_NULL, deflateInit updates them to use default + allocation functions. + + The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: + 1 gives best speed, 9 gives best compression, 0 gives no compression at all + (the input data is simply copied a block at a time). Z_DEFAULT_COMPRESSION + requests a default compromise between speed and compression (currently + equivalent to level 6). + + deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_STREAM_ERROR if level is not a valid compression level, or + Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible + with the version assumed by the caller (ZLIB_VERSION). msg is set to null + if there is no error message. deflateInit does not perform any compression: + this will be done by deflate(). +*/ + + +ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); +/* + deflate compresses as much data as possible, and stops when the input + buffer becomes empty or the output buffer becomes full. It may introduce + some output latency (reading input without producing any output) except when + forced to flush. + + The detailed semantics are as follows. deflate performs one or both of the + following actions: + + - Compress more input starting at next_in and update next_in and avail_in + accordingly. If not all input can be processed (because there is not + enough room in the output buffer), next_in and avail_in are updated and + processing will resume at this point for the next call of deflate(). + + - Provide more output starting at next_out and update next_out and avail_out + accordingly. This action is forced if the parameter flush is non zero. + Forcing flush frequently degrades the compression ratio, so this parameter + should be set only when necessary (in interactive applications). Some + output may be provided even if flush is not set. + + Before the call of deflate(), the application should ensure that at least + one of the actions is possible, by providing more input and/or consuming more + output, and updating avail_in or avail_out accordingly; avail_out should + never be zero before the call. The application can consume the compressed + output when it wants, for example when the output buffer is full (avail_out + == 0), or after each call of deflate(). If deflate returns Z_OK and with + zero avail_out, it must be called again after making room in the output + buffer because there might be more output pending. + + Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to + decide how much data to accumulate before producing output, in order to + maximize compression. + + If the parameter flush is set to Z_SYNC_FLUSH, all pending output is + flushed to the output buffer and the output is aligned on a byte boundary, so + that the decompressor can get all input data available so far. (In + particular avail_in is zero after the call if enough output space has been + provided before the call.) Flushing may degrade compression for some + compression algorithms and so it should be used only when necessary. This + completes the current deflate block and follows it with an empty stored block + that is three bits plus filler bits to the next byte, followed by four bytes + (00 00 ff ff). + + If flush is set to Z_PARTIAL_FLUSH, all pending output is flushed to the + output buffer, but the output is not aligned to a byte boundary. All of the + input data so far will be available to the decompressor, as for Z_SYNC_FLUSH. + This completes the current deflate block and follows it with an empty fixed + codes block that is 10 bits long. This assures that enough bytes are output + in order for the decompressor to finish the block before the empty fixed code + block. + + If flush is set to Z_BLOCK, a deflate block is completed and emitted, as + for Z_SYNC_FLUSH, but the output is not aligned on a byte boundary, and up to + seven bits of the current block are held to be written as the next byte after + the next deflate block is completed. In this case, the decompressor may not + be provided enough bits at this point in order to complete decompression of + the data provided so far to the compressor. It may need to wait for the next + block to be emitted. This is for advanced applications that need to control + the emission of deflate blocks. + + If flush is set to Z_FULL_FLUSH, all output is flushed as with + Z_SYNC_FLUSH, and the compression state is reset so that decompression can + restart from this point if previous compressed data has been damaged or if + random access is desired. Using Z_FULL_FLUSH too often can seriously degrade + compression. + + If deflate returns with avail_out == 0, this function must be called again + with the same value of the flush parameter and more output space (updated + avail_out), until the flush is complete (deflate returns with non-zero + avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that + avail_out is greater than six to avoid repeated flush markers due to + avail_out == 0 on return. + + If the parameter flush is set to Z_FINISH, pending input is processed, + pending output is flushed and deflate returns with Z_STREAM_END if there was + enough output space; if deflate returns with Z_OK, this function must be + called again with Z_FINISH and more output space (updated avail_out) but no + more input data, until it returns with Z_STREAM_END or an error. After + deflate has returned Z_STREAM_END, the only possible operations on the stream + are deflateReset or deflateEnd. + + Z_FINISH can be used immediately after deflateInit if all the compression + is to be done in a single step. In this case, avail_out must be at least the + value returned by deflateBound (see below). Then deflate is guaranteed to + return Z_STREAM_END. If not enough output space is provided, deflate will + not return Z_STREAM_END, and it must be called again as described above. + + deflate() sets strm->adler to the adler32 checksum of all input read + so far (that is, total_in bytes). + + deflate() may update strm->data_type if it can make a good guess about + the input data type (Z_BINARY or Z_TEXT). In doubt, the data is considered + binary. This field is only for information purposes and does not affect the + compression algorithm in any manner. + + deflate() returns Z_OK if some progress has been made (more input + processed or more output produced), Z_STREAM_END if all input has been + consumed and all output has been produced (only when flush is set to + Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example + if next_in or next_out was Z_NULL), Z_BUF_ERROR if no progress is possible + (for example avail_in or avail_out was zero). Note that Z_BUF_ERROR is not + fatal, and deflate() can be called again with more input and more output + space to continue compressing. +*/ + + +ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); +/* + All dynamically allocated data structures for this stream are freed. + This function discards any unprocessed input and does not flush any pending + output. + + deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the + stream state was inconsistent, Z_DATA_ERROR if the stream was freed + prematurely (some input or output was discarded). In the error case, msg + may be set but then points to a static string (which must not be + deallocated). +*/ + + +/* +ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm)); + + Initializes the internal stream state for decompression. The fields + next_in, avail_in, zalloc, zfree and opaque must be initialized before by + the caller. If next_in is not Z_NULL and avail_in is large enough (the + exact value depends on the compression method), inflateInit determines the + compression method from the zlib header and allocates all data structures + accordingly; otherwise the allocation will be deferred to the first call of + inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to + use default allocation functions. + + inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_VERSION_ERROR if the zlib library version is incompatible with the + version assumed by the caller, or Z_STREAM_ERROR if the parameters are + invalid, such as a null pointer to the structure. msg is set to null if + there is no error message. inflateInit does not perform any decompression + apart from possibly reading the zlib header if present: actual decompression + will be done by inflate(). (So next_in and avail_in may be modified, but + next_out and avail_out are unused and unchanged.) The current implementation + of inflateInit() does not process any header information -- that is deferred + until inflate() is called. +*/ + + +ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); +/* + inflate decompresses as much data as possible, and stops when the input + buffer becomes empty or the output buffer becomes full. It may introduce + some output latency (reading input without producing any output) except when + forced to flush. + + The detailed semantics are as follows. inflate performs one or both of the + following actions: + + - Decompress more input starting at next_in and update next_in and avail_in + accordingly. If not all input can be processed (because there is not + enough room in the output buffer), next_in is updated and processing will + resume at this point for the next call of inflate(). + + - Provide more output starting at next_out and update next_out and avail_out + accordingly. inflate() provides as much output as possible, until there is + no more input data or no more space in the output buffer (see below about + the flush parameter). + + Before the call of inflate(), the application should ensure that at least + one of the actions is possible, by providing more input and/or consuming more + output, and updating the next_* and avail_* values accordingly. The + application can consume the uncompressed output when it wants, for example + when the output buffer is full (avail_out == 0), or after each call of + inflate(). If inflate returns Z_OK and with zero avail_out, it must be + called again after making room in the output buffer because there might be + more output pending. + + The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH, Z_FINISH, + Z_BLOCK, or Z_TREES. Z_SYNC_FLUSH requests that inflate() flush as much + output as possible to the output buffer. Z_BLOCK requests that inflate() + stop if and when it gets to the next deflate block boundary. When decoding + the zlib or gzip format, this will cause inflate() to return immediately + after the header and before the first block. When doing a raw inflate, + inflate() will go ahead and process the first block, and will return when it + gets to the end of that block, or when it runs out of data. + + The Z_BLOCK option assists in appending to or combining deflate streams. + Also to assist in this, on return inflate() will set strm->data_type to the + number of unused bits in the last byte taken from strm->next_in, plus 64 if + inflate() is currently decoding the last block in the deflate stream, plus + 128 if inflate() returned immediately after decoding an end-of-block code or + decoding the complete header up to just before the first byte of the deflate + stream. The end-of-block will not be indicated until all of the uncompressed + data from that block has been written to strm->next_out. The number of + unused bits may in general be greater than seven, except when bit 7 of + data_type is set, in which case the number of unused bits will be less than + eight. data_type is set as noted here every time inflate() returns for all + flush options, and so can be used to determine the amount of currently + consumed input in bits. + + The Z_TREES option behaves as Z_BLOCK does, but it also returns when the + end of each deflate block header is reached, before any actual data in that + block is decoded. This allows the caller to determine the length of the + deflate block header for later use in random access within a deflate block. + 256 is added to the value of strm->data_type when inflate() returns + immediately after reaching the end of the deflate block header. + + inflate() should normally be called until it returns Z_STREAM_END or an + error. However if all decompression is to be performed in a single step (a + single call of inflate), the parameter flush should be set to Z_FINISH. In + this case all pending input is processed and all pending output is flushed; + avail_out must be large enough to hold all the uncompressed data. (The size + of the uncompressed data may have been saved by the compressor for this + purpose.) The next operation on this stream must be inflateEnd to deallocate + the decompression state. The use of Z_FINISH is not required to perform an + inflation in one step. However it may be used to inform inflate that a + faster approach can be used for the single inflate() call. Z_FINISH also + informs inflate to not maintain a sliding window if the stream completes, + which reduces inflate's memory footprint. + + In this implementation, inflate() always flushes as much output as + possible to the output buffer, and always uses the faster approach on the + first call. So the effects of the flush parameter in this implementation are + on the return value of inflate() as noted below, when inflate() returns early + when Z_BLOCK or Z_TREES is used, and when inflate() avoids the allocation of + memory for a sliding window when Z_FINISH is used. + + If a preset dictionary is needed after this call (see inflateSetDictionary + below), inflate sets strm->adler to the Adler-32 checksum of the dictionary + chosen by the compressor and returns Z_NEED_DICT; otherwise it sets + strm->adler to the Adler-32 checksum of all output produced so far (that is, + total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described + below. At the end of the stream, inflate() checks that its computed adler32 + checksum is equal to that saved by the compressor and returns Z_STREAM_END + only if the checksum is correct. + + inflate() can decompress and check either zlib-wrapped or gzip-wrapped + deflate data. The header type is detected automatically, if requested when + initializing with inflateInit2(). Any information contained in the gzip + header is not retained, so applications that need that information should + instead use raw inflate, see inflateInit2() below, or inflateBack() and + perform their own processing of the gzip header and trailer. When processing + gzip-wrapped deflate data, strm->adler32 is set to the CRC-32 of the output + producted so far. The CRC-32 is checked against the gzip trailer. + + inflate() returns Z_OK if some progress has been made (more input processed + or more output produced), Z_STREAM_END if the end of the compressed data has + been reached and all uncompressed output has been produced, Z_NEED_DICT if a + preset dictionary is needed at this point, Z_DATA_ERROR if the input data was + corrupted (input stream not conforming to the zlib format or incorrect check + value), Z_STREAM_ERROR if the stream structure was inconsistent (for example + next_in or next_out was Z_NULL), Z_MEM_ERROR if there was not enough memory, + Z_BUF_ERROR if no progress is possible or if there was not enough room in the + output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and + inflate() can be called again with more input and more output space to + continue decompressing. If Z_DATA_ERROR is returned, the application may + then call inflateSync() to look for a good compression block if a partial + recovery of the data is desired. +*/ + + +ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)); +/* + All dynamically allocated data structures for this stream are freed. + This function discards any unprocessed input and does not flush any pending + output. + + inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state + was inconsistent. In the error case, msg may be set but then points to a + static string (which must not be deallocated). +*/ + + + /* Advanced functions */ + +/* + The following functions are needed only in some special applications. +*/ + +/* +ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm, + int level, + int method, + int windowBits, + int memLevel, + int strategy)); + + This is another version of deflateInit with more compression options. The + fields next_in, zalloc, zfree and opaque must be initialized before by the + caller. + + The method parameter is the compression method. It must be Z_DEFLATED in + this version of the library. + + The windowBits parameter is the base two logarithm of the window size + (the size of the history buffer). It should be in the range 8..15 for this + version of the library. Larger values of this parameter result in better + compression at the expense of memory usage. The default value is 15 if + deflateInit is used instead. + + windowBits can also be -8..-15 for raw deflate. In this case, -windowBits + determines the window size. deflate() will then generate raw deflate data + with no zlib header or trailer, and will not compute an adler32 check value. + + windowBits can also be greater than 15 for optional gzip encoding. Add + 16 to windowBits to write a simple gzip header and trailer around the + compressed data instead of a zlib wrapper. The gzip header will have no + file name, no extra data, no comment, no modification time (set to zero), no + header crc, and the operating system will be set to 255 (unknown). If a + gzip stream is being written, strm->adler is a crc32 instead of an adler32. + + The memLevel parameter specifies how much memory should be allocated + for the internal compression state. memLevel=1 uses minimum memory but is + slow and reduces compression ratio; memLevel=9 uses maximum memory for + optimal speed. The default value is 8. See zconf.h for total memory usage + as a function of windowBits and memLevel. + + The strategy parameter is used to tune the compression algorithm. Use the + value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a + filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no + string match), or Z_RLE to limit match distances to one (run-length + encoding). Filtered data consists mostly of small values with a somewhat + random distribution. In this case, the compression algorithm is tuned to + compress them better. The effect of Z_FILTERED is to force more Huffman + coding and less string matching; it is somewhat intermediate between + Z_DEFAULT_STRATEGY and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as + fast as Z_HUFFMAN_ONLY, but give better compression for PNG image data. The + strategy parameter only affects the compression ratio but not the + correctness of the compressed output even if it is not set appropriately. + Z_FIXED prevents the use of dynamic Huffman codes, allowing for a simpler + decoder for special applications. + + deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_STREAM_ERROR if any parameter is invalid (such as an invalid + method), or Z_VERSION_ERROR if the zlib library version (zlib_version) is + incompatible with the version assumed by the caller (ZLIB_VERSION). msg is + set to null if there is no error message. deflateInit2 does not perform any + compression: this will be done by deflate(). +*/ + +ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, + const Bytef *dictionary, + uInt dictLength)); +/* + Initializes the compression dictionary from the given byte sequence + without producing any compressed output. When using the zlib format, this + function must be called immediately after deflateInit, deflateInit2 or + deflateReset, and before any call of deflate. When doing raw deflate, this + function must be called either before any call of deflate, or immediately + after the completion of a deflate block, i.e. after all input has been + consumed and all output has been delivered when using any of the flush + options Z_BLOCK, Z_PARTIAL_FLUSH, Z_SYNC_FLUSH, or Z_FULL_FLUSH. The + compressor and decompressor must use exactly the same dictionary (see + inflateSetDictionary). + + The dictionary should consist of strings (byte sequences) that are likely + to be encountered later in the data to be compressed, with the most commonly + used strings preferably put towards the end of the dictionary. Using a + dictionary is most useful when the data to be compressed is short and can be + predicted with good accuracy; the data can then be compressed better than + with the default empty dictionary. + + Depending on the size of the compression data structures selected by + deflateInit or deflateInit2, a part of the dictionary may in effect be + discarded, for example if the dictionary is larger than the window size + provided in deflateInit or deflateInit2. Thus the strings most likely to be + useful should be put at the end of the dictionary, not at the front. In + addition, the current implementation of deflate will use at most the window + size minus 262 bytes of the provided dictionary. + + Upon return of this function, strm->adler is set to the adler32 value + of the dictionary; the decompressor may later use this value to determine + which dictionary has been used by the compressor. (The adler32 value + applies to the whole dictionary even if only a subset of the dictionary is + actually used by the compressor.) If a raw deflate was requested, then the + adler32 value is not computed and strm->adler is not set. + + deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a + parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is + inconsistent (for example if deflate has already been called for this stream + or if not at a block boundary for raw deflate). deflateSetDictionary does + not perform any compression: this will be done by deflate(). +*/ + +ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest, + z_streamp source)); +/* + Sets the destination stream as a complete copy of the source stream. + + This function can be useful when several compression strategies will be + tried, for example when there are several ways of pre-processing the input + data with a filter. The streams that will be discarded should then be freed + by calling deflateEnd. Note that deflateCopy duplicates the internal + compression state which can be quite large, so this strategy is slow and can + consume lots of memory. + + deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_STREAM_ERROR if the source stream state was inconsistent + (such as zalloc being Z_NULL). msg is left unchanged in both source and + destination. +*/ + +ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm)); +/* + This function is equivalent to deflateEnd followed by deflateInit, + but does not free and reallocate all the internal compression state. The + stream will keep the same compression level and any other attributes that + may have been set by deflateInit2. + + deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent (such as zalloc or state being Z_NULL). +*/ + +ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, + int level, + int strategy)); +/* + Dynamically update the compression level and compression strategy. The + interpretation of level and strategy is as in deflateInit2. This can be + used to switch between compression and straight copy of the input data, or + to switch to a different kind of input data requiring a different strategy. + If the compression level is changed, the input available so far is + compressed with the old level (and may be flushed); the new level will take + effect only at the next call of deflate(). + + Before the call of deflateParams, the stream state must be set as for + a call of deflate(), since the currently available input may have to be + compressed and flushed. In particular, strm->avail_out must be non-zero. + + deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source + stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR if + strm->avail_out was zero. +*/ + +ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm, + int good_length, + int max_lazy, + int nice_length, + int max_chain)); +/* + Fine tune deflate's internal compression parameters. This should only be + used by someone who understands the algorithm used by zlib's deflate for + searching for the best matching string, and even then only by the most + fanatic optimizer trying to squeeze out the last compressed bit for their + specific input data. Read the deflate.c source code for the meaning of the + max_lazy, good_length, nice_length, and max_chain parameters. + + deflateTune() can be called after deflateInit() or deflateInit2(), and + returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream. + */ + +ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm, + uLong sourceLen)); +/* + deflateBound() returns an upper bound on the compressed size after + deflation of sourceLen bytes. It must be called after deflateInit() or + deflateInit2(), and after deflateSetHeader(), if used. This would be used + to allocate an output buffer for deflation in a single pass, and so would be + called before deflate(). If that first deflate() call is provided the + sourceLen input bytes, an output buffer allocated to the size returned by + deflateBound(), and the flush value Z_FINISH, then deflate() is guaranteed + to return Z_STREAM_END. Note that it is possible for the compressed size to + be larger than the value returned by deflateBound() if flush options other + than Z_FINISH or Z_NO_FLUSH are used. +*/ + +ZEXTERN int ZEXPORT deflatePending OF((z_streamp strm, + unsigned *pending, + int *bits)); +/* + deflatePending() returns the number of bytes and bits of output that have + been generated, but not yet provided in the available output. The bytes not + provided would be due to the available output space having being consumed. + The number of bits of output not provided are between 0 and 7, where they + await more bits to join them in order to fill out a full byte. If pending + or bits are Z_NULL, then those values are not set. + + deflatePending returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent. + */ + +ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm, + int bits, + int value)); +/* + deflatePrime() inserts bits in the deflate output stream. The intent + is that this function is used to start off the deflate output with the bits + leftover from a previous deflate stream when appending to it. As such, this + function can only be used for raw deflate, and must be used before the first + deflate() call after a deflateInit2() or deflateReset(). bits must be less + than or equal to 16, and that many of the least significant bits of value + will be inserted in the output. + + deflatePrime returns Z_OK if success, Z_BUF_ERROR if there was not enough + room in the internal buffer to insert the bits, or Z_STREAM_ERROR if the + source stream state was inconsistent. +*/ + +ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm, + gz_headerp head)); +/* + deflateSetHeader() provides gzip header information for when a gzip + stream is requested by deflateInit2(). deflateSetHeader() may be called + after deflateInit2() or deflateReset() and before the first call of + deflate(). The text, time, os, extra field, name, and comment information + in the provided gz_header structure are written to the gzip header (xflag is + ignored -- the extra flags are set according to the compression level). The + caller must assure that, if not Z_NULL, name and comment are terminated with + a zero byte, and that if extra is not Z_NULL, that extra_len bytes are + available there. If hcrc is true, a gzip header crc is included. Note that + the current versions of the command-line version of gzip (up through version + 1.3.x) do not support header crc's, and will report that it is a "multi-part + gzip file" and give up. + + If deflateSetHeader is not used, the default gzip header has text false, + the time set to zero, and os set to 255, with no extra, name, or comment + fields. The gzip header is returned to the default state by deflateReset(). + + deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent. +*/ + +/* +ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, + int windowBits)); + + This is another version of inflateInit with an extra parameter. The + fields next_in, avail_in, zalloc, zfree and opaque must be initialized + before by the caller. + + The windowBits parameter is the base two logarithm of the maximum window + size (the size of the history buffer). It should be in the range 8..15 for + this version of the library. The default value is 15 if inflateInit is used + instead. windowBits must be greater than or equal to the windowBits value + provided to deflateInit2() while compressing, or it must be equal to 15 if + deflateInit2() was not used. If a compressed stream with a larger window + size is given as input, inflate() will return with the error code + Z_DATA_ERROR instead of trying to allocate a larger window. + + windowBits can also be zero to request that inflate use the window size in + the zlib header of the compressed stream. + + windowBits can also be -8..-15 for raw inflate. In this case, -windowBits + determines the window size. inflate() will then process raw deflate data, + not looking for a zlib or gzip header, not generating a check value, and not + looking for any check values for comparison at the end of the stream. This + is for use with other formats that use the deflate compressed data format + such as zip. Those formats provide their own check values. If a custom + format is developed using the raw deflate format for compressed data, it is + recommended that a check value such as an adler32 or a crc32 be applied to + the uncompressed data as is done in the zlib, gzip, and zip formats. For + most applications, the zlib format should be used as is. Note that comments + above on the use in deflateInit2() applies to the magnitude of windowBits. + + windowBits can also be greater than 15 for optional gzip decoding. Add + 32 to windowBits to enable zlib and gzip decoding with automatic header + detection, or add 16 to decode only the gzip format (the zlib format will + return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is a + crc32 instead of an adler32. + + inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_VERSION_ERROR if the zlib library version is incompatible with the + version assumed by the caller, or Z_STREAM_ERROR if the parameters are + invalid, such as a null pointer to the structure. msg is set to null if + there is no error message. inflateInit2 does not perform any decompression + apart from possibly reading the zlib header if present: actual decompression + will be done by inflate(). (So next_in and avail_in may be modified, but + next_out and avail_out are unused and unchanged.) The current implementation + of inflateInit2() does not process any header information -- that is + deferred until inflate() is called. +*/ + +ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, + const Bytef *dictionary, + uInt dictLength)); +/* + Initializes the decompression dictionary from the given uncompressed byte + sequence. This function must be called immediately after a call of inflate, + if that call returned Z_NEED_DICT. The dictionary chosen by the compressor + can be determined from the adler32 value returned by that call of inflate. + The compressor and decompressor must use exactly the same dictionary (see + deflateSetDictionary). For raw inflate, this function can be called at any + time to set the dictionary. If the provided dictionary is smaller than the + window and there is already data in the window, then the provided dictionary + will amend what's there. The application must insure that the dictionary + that was used for compression is provided. + + inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a + parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is + inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the + expected one (incorrect adler32 value). inflateSetDictionary does not + perform any decompression: this will be done by subsequent calls of + inflate(). +*/ + +ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm)); +/* + Skips invalid compressed data until a possible full flush point (see above + for the description of deflate with Z_FULL_FLUSH) can be found, or until all + available input is skipped. No output is provided. + + inflateSync searches for a 00 00 FF FF pattern in the compressed data. + All full flush points have this pattern, but not all occurences of this + pattern are full flush points. + + inflateSync returns Z_OK if a possible full flush point has been found, + Z_BUF_ERROR if no more input was provided, Z_DATA_ERROR if no flush point + has been found, or Z_STREAM_ERROR if the stream structure was inconsistent. + In the success case, the application may save the current current value of + total_in which indicates where valid compressed data was found. In the + error case, the application may repeatedly call inflateSync, providing more + input each time, until success or end of the input data. +*/ + +ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest, + z_streamp source)); +/* + Sets the destination stream as a complete copy of the source stream. + + This function can be useful when randomly accessing a large stream. The + first pass through the stream can periodically record the inflate state, + allowing restarting inflate at those points when randomly accessing the + stream. + + inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_STREAM_ERROR if the source stream state was inconsistent + (such as zalloc being Z_NULL). msg is left unchanged in both source and + destination. +*/ + +ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); +/* + This function is equivalent to inflateEnd followed by inflateInit, + but does not free and reallocate all the internal decompression state. The + stream will keep attributes that may have been set by inflateInit2. + + inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent (such as zalloc or state being Z_NULL). +*/ + +ZEXTERN int ZEXPORT inflateReset2 OF((z_streamp strm, + int windowBits)); +/* + This function is the same as inflateReset, but it also permits changing + the wrap and window size requests. The windowBits parameter is interpreted + the same as it is for inflateInit2. + + inflateReset2 returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent (such as zalloc or state being Z_NULL), or if + the windowBits parameter is invalid. +*/ + +ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm, + int bits, + int value)); +/* + This function inserts bits in the inflate input stream. The intent is + that this function is used to start inflating at a bit position in the + middle of a byte. The provided bits will be used before any bytes are used + from next_in. This function should only be used with raw inflate, and + should be used before the first inflate() call after inflateInit2() or + inflateReset(). bits must be less than or equal to 16, and that many of the + least significant bits of value will be inserted in the input. + + If bits is negative, then the input stream bit buffer is emptied. Then + inflatePrime() can be called again to put bits in the buffer. This is used + to clear out bits leftover after feeding inflate a block description prior + to feeding inflate codes. + + inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent. +*/ + +ZEXTERN long ZEXPORT inflateMark OF((z_streamp strm)); +/* + This function returns two values, one in the lower 16 bits of the return + value, and the other in the remaining upper bits, obtained by shifting the + return value down 16 bits. If the upper value is -1 and the lower value is + zero, then inflate() is currently decoding information outside of a block. + If the upper value is -1 and the lower value is non-zero, then inflate is in + the middle of a stored block, with the lower value equaling the number of + bytes from the input remaining to copy. If the upper value is not -1, then + it is the number of bits back from the current bit position in the input of + the code (literal or length/distance pair) currently being processed. In + that case the lower value is the number of bytes already emitted for that + code. + + A code is being processed if inflate is waiting for more input to complete + decoding of the code, or if it has completed decoding but is waiting for + more output space to write the literal or match data. + + inflateMark() is used to mark locations in the input data for random + access, which may be at bit positions, and to note those cases where the + output of a code may span boundaries of random access blocks. The current + location in the input stream can be determined from avail_in and data_type + as noted in the description for the Z_BLOCK flush parameter for inflate. + + inflateMark returns the value noted above or -1 << 16 if the provided + source stream state was inconsistent. +*/ + +ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm, + gz_headerp head)); +/* + inflateGetHeader() requests that gzip header information be stored in the + provided gz_header structure. inflateGetHeader() may be called after + inflateInit2() or inflateReset(), and before the first call of inflate(). + As inflate() processes the gzip stream, head->done is zero until the header + is completed, at which time head->done is set to one. If a zlib stream is + being decoded, then head->done is set to -1 to indicate that there will be + no gzip header information forthcoming. Note that Z_BLOCK or Z_TREES can be + used to force inflate() to return immediately after header processing is + complete and before any actual data is decompressed. + + The text, time, xflags, and os fields are filled in with the gzip header + contents. hcrc is set to true if there is a header CRC. (The header CRC + was valid if done is set to one.) If extra is not Z_NULL, then extra_max + contains the maximum number of bytes to write to extra. Once done is true, + extra_len contains the actual extra field length, and extra contains the + extra field, or that field truncated if extra_max is less than extra_len. + If name is not Z_NULL, then up to name_max characters are written there, + terminated with a zero unless the length is greater than name_max. If + comment is not Z_NULL, then up to comm_max characters are written there, + terminated with a zero unless the length is greater than comm_max. When any + of extra, name, or comment are not Z_NULL and the respective field is not + present in the header, then that field is set to Z_NULL to signal its + absence. This allows the use of deflateSetHeader() with the returned + structure to duplicate the header. However if those fields are set to + allocated memory, then the application will need to save those pointers + elsewhere so that they can be eventually freed. + + If inflateGetHeader is not used, then the header information is simply + discarded. The header is always checked for validity, including the header + CRC if present. inflateReset() will reset the process to discard the header + information. The application would need to call inflateGetHeader() again to + retrieve the header from the next gzip stream. + + inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent. +*/ + +/* +ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits, + unsigned char FAR *window)); + + Initialize the internal stream state for decompression using inflateBack() + calls. The fields zalloc, zfree and opaque in strm must be initialized + before the call. If zalloc and zfree are Z_NULL, then the default library- + derived memory allocation routines are used. windowBits is the base two + logarithm of the window size, in the range 8..15. window is a caller + supplied buffer of that size. Except for special applications where it is + assured that deflate was used with small window sizes, windowBits must be 15 + and a 32K byte window must be supplied to be able to decompress general + deflate streams. + + See inflateBack() for the usage of these routines. + + inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of + the parameters are invalid, Z_MEM_ERROR if the internal state could not be + allocated, or Z_VERSION_ERROR if the version of the library does not match + the version of the header file. +*/ + +typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *)); +typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned)); + +ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm, + in_func in, void FAR *in_desc, + out_func out, void FAR *out_desc)); +/* + inflateBack() does a raw inflate with a single call using a call-back + interface for input and output. This is more efficient than inflate() for + file i/o applications in that it avoids copying between the output and the + sliding window by simply making the window itself the output buffer. This + function trusts the application to not change the output buffer passed by + the output function, at least until inflateBack() returns. + + inflateBackInit() must be called first to allocate the internal state + and to initialize the state with the user-provided window buffer. + inflateBack() may then be used multiple times to inflate a complete, raw + deflate stream with each call. inflateBackEnd() is then called to free the + allocated state. + + A raw deflate stream is one with no zlib or gzip header or trailer. + This routine would normally be used in a utility that reads zip or gzip + files and writes out uncompressed files. The utility would decode the + header and process the trailer on its own, hence this routine expects only + the raw deflate stream to decompress. This is different from the normal + behavior of inflate(), which expects either a zlib or gzip header and + trailer around the deflate stream. + + inflateBack() uses two subroutines supplied by the caller that are then + called by inflateBack() for input and output. inflateBack() calls those + routines until it reads a complete deflate stream and writes out all of the + uncompressed data, or until it encounters an error. The function's + parameters and return types are defined above in the in_func and out_func + typedefs. inflateBack() will call in(in_desc, &buf) which should return the + number of bytes of provided input, and a pointer to that input in buf. If + there is no input available, in() must return zero--buf is ignored in that + case--and inflateBack() will return a buffer error. inflateBack() will call + out(out_desc, buf, len) to write the uncompressed data buf[0..len-1]. out() + should return zero on success, or non-zero on failure. If out() returns + non-zero, inflateBack() will return with an error. Neither in() nor out() + are permitted to change the contents of the window provided to + inflateBackInit(), which is also the buffer that out() uses to write from. + The length written by out() will be at most the window size. Any non-zero + amount of input may be provided by in(). + + For convenience, inflateBack() can be provided input on the first call by + setting strm->next_in and strm->avail_in. If that input is exhausted, then + in() will be called. Therefore strm->next_in must be initialized before + calling inflateBack(). If strm->next_in is Z_NULL, then in() will be called + immediately for input. If strm->next_in is not Z_NULL, then strm->avail_in + must also be initialized, and then if strm->avail_in is not zero, input will + initially be taken from strm->next_in[0 .. strm->avail_in - 1]. + + The in_desc and out_desc parameters of inflateBack() is passed as the + first parameter of in() and out() respectively when they are called. These + descriptors can be optionally used to pass any information that the caller- + supplied in() and out() functions need to do their job. + + On return, inflateBack() will set strm->next_in and strm->avail_in to + pass back any unused input that was provided by the last in() call. The + return values of inflateBack() can be Z_STREAM_END on success, Z_BUF_ERROR + if in() or out() returned an error, Z_DATA_ERROR if there was a format error + in the deflate stream (in which case strm->msg is set to indicate the nature + of the error), or Z_STREAM_ERROR if the stream was not properly initialized. + In the case of Z_BUF_ERROR, an input or output error can be distinguished + using strm->next_in which will be Z_NULL only if in() returned an error. If + strm->next_in is not Z_NULL, then the Z_BUF_ERROR was due to out() returning + non-zero. (in() will always be called before out(), so strm->next_in is + assured to be defined if out() returns non-zero.) Note that inflateBack() + cannot return Z_OK. +*/ + +ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm)); +/* + All memory allocated by inflateBackInit() is freed. + + inflateBackEnd() returns Z_OK on success, or Z_STREAM_ERROR if the stream + state was inconsistent. +*/ + +ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void)); +/* Return flags indicating compile-time options. + + Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other: + 1.0: size of uInt + 3.2: size of uLong + 5.4: size of voidpf (pointer) + 7.6: size of z_off_t + + Compiler, assembler, and debug options: + 8: DEBUG + 9: ASMV or ASMINF -- use ASM code + 10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention + 11: 0 (reserved) + + One-time table building (smaller code, but not thread-safe if true): + 12: BUILDFIXED -- build static block decoding tables when needed + 13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed + 14,15: 0 (reserved) + + Library content (indicates missing functionality): + 16: NO_GZCOMPRESS -- gz* functions cannot compress (to avoid linking + deflate code when not needed) + 17: NO_GZIP -- deflate can't write gzip streams, and inflate can't detect + and decode gzip streams (to avoid linking crc code) + 18-19: 0 (reserved) + + Operation variations (changes in library functionality): + 20: PKZIP_BUG_WORKAROUND -- slightly more permissive inflate + 21: FASTEST -- deflate algorithm with only one, lowest compression level + 22,23: 0 (reserved) + + The sprintf variant used by gzprintf (zero is best): + 24: 0 = vs*, 1 = s* -- 1 means limited to 20 arguments after the format + 25: 0 = *nprintf, 1 = *printf -- 1 means gzprintf() not secure! + 26: 0 = returns value, 1 = void -- 1 means inferred string length returned + + Remainder: + 27-31: 0 (reserved) + */ + +#ifndef Z_SOLO + + /* utility functions */ + +/* + The following utility functions are implemented on top of the basic + stream-oriented functions. To simplify the interface, some default options + are assumed (compression level and memory usage, standard memory allocation + functions). The source code of these utility functions can be modified if + you need special options. +*/ + +ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen)); +/* + Compresses the source buffer into the destination buffer. sourceLen is + the byte length of the source buffer. Upon entry, destLen is the total size + of the destination buffer, which must be at least the value returned by + compressBound(sourceLen). Upon exit, destLen is the actual size of the + compressed buffer. + + compress returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_BUF_ERROR if there was not enough room in the output + buffer. +*/ + +ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen, + int level)); +/* + Compresses the source buffer into the destination buffer. The level + parameter has the same meaning as in deflateInit. sourceLen is the byte + length of the source buffer. Upon entry, destLen is the total size of the + destination buffer, which must be at least the value returned by + compressBound(sourceLen). Upon exit, destLen is the actual size of the + compressed buffer. + + compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_BUF_ERROR if there was not enough room in the output buffer, + Z_STREAM_ERROR if the level parameter is invalid. +*/ + +ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen)); +/* + compressBound() returns an upper bound on the compressed size after + compress() or compress2() on sourceLen bytes. It would be used before a + compress() or compress2() call to allocate the destination buffer. +*/ + +ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen)); +/* + Decompresses the source buffer into the destination buffer. sourceLen is + the byte length of the source buffer. Upon entry, destLen is the total size + of the destination buffer, which must be large enough to hold the entire + uncompressed data. (The size of the uncompressed data must have been saved + previously by the compressor and transmitted to the decompressor by some + mechanism outside the scope of this compression library.) Upon exit, destLen + is the actual size of the uncompressed buffer. + + uncompress returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_BUF_ERROR if there was not enough room in the output + buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. In + the case where there is not enough room, uncompress() will fill the output + buffer with the uncompressed data up to that point. +*/ + + /* gzip file access functions */ + +/* + This library supports reading and writing files in gzip (.gz) format with + an interface similar to that of stdio, using the functions that start with + "gz". The gzip format is different from the zlib format. gzip is a gzip + wrapper, documented in RFC 1952, wrapped around a deflate stream. +*/ + +typedef struct gzFile_s *gzFile; /* semi-opaque gzip file descriptor */ + +/* +ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); + + Opens a gzip (.gz) file for reading or writing. The mode parameter is as + in fopen ("rb" or "wb") but can also include a compression level ("wb9") or + a strategy: 'f' for filtered data as in "wb6f", 'h' for Huffman-only + compression as in "wb1h", 'R' for run-length encoding as in "wb1R", or 'F' + for fixed code compression as in "wb9F". (See the description of + deflateInit2 for more information about the strategy parameter.) 'T' will + request transparent writing or appending with no compression and not using + the gzip format. + + "a" can be used instead of "w" to request that the gzip stream that will + be written be appended to the file. "+" will result in an error, since + reading and writing to the same gzip file is not supported. + + These functions, as well as gzip, will read and decode a sequence of gzip + streams in a file. The append function of gzopen() can be used to create + such a file. (Also see gzflush() for another way to do this.) When + appending, gzopen does not test whether the file begins with a gzip stream, + nor does it look for the end of the gzip streams to begin appending. gzopen + will simply append a gzip stream to the existing file. + + gzopen can be used to read a file which is not in gzip format; in this + case gzread will directly read from the file without decompression. When + reading, this will be detected automatically by looking for the magic two- + byte gzip header. + + gzopen returns NULL if the file could not be opened, if there was + insufficient memory to allocate the gzFile state, or if an invalid mode was + specified (an 'r', 'w', or 'a' was not provided, or '+' was provided). + errno can be checked to determine if the reason gzopen failed was that the + file could not be opened. +*/ + +ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); +/* + gzdopen associates a gzFile with the file descriptor fd. File descriptors + are obtained from calls like open, dup, creat, pipe or fileno (if the file + has been previously opened with fopen). The mode parameter is as in gzopen. + + The next call of gzclose on the returned gzFile will also close the file + descriptor fd, just like fclose(fdopen(fd, mode)) closes the file descriptor + fd. If you want to keep fd open, use fd = dup(fd_keep); gz = gzdopen(fd, + mode);. The duplicated descriptor should be saved to avoid a leak, since + gzdopen does not close fd if it fails. If you are using fileno() to get the + file descriptor from a FILE *, then you will have to use dup() to avoid + double-close()ing the file descriptor. Both gzclose() and fclose() will + close the associated file descriptor, so they need to have different file + descriptors. + + gzdopen returns NULL if there was insufficient memory to allocate the + gzFile state, if an invalid mode was specified (an 'r', 'w', or 'a' was not + provided, or '+' was provided), or if fd is -1. The file descriptor is not + used until the next gz* read, write, seek, or close operation, so gzdopen + will not detect if fd is invalid (unless fd is -1). +*/ + +ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size)); +/* + Set the internal buffer size used by this library's functions. The + default buffer size is 8192 bytes. This function must be called after + gzopen() or gzdopen(), and before any other calls that read or write the + file. The buffer memory allocation is always deferred to the first read or + write. Two buffers are allocated, either both of the specified size when + writing, or one of the specified size and the other twice that size when + reading. A larger buffer size of, for example, 64K or 128K bytes will + noticeably increase the speed of decompression (reading). + + The new buffer size also affects the maximum length for gzprintf(). + + gzbuffer() returns 0 on success, or -1 on failure, such as being called + too late. +*/ + +ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); +/* + Dynamically update the compression level or strategy. See the description + of deflateInit2 for the meaning of these parameters. + + gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not + opened for writing. +*/ + +ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); +/* + Reads the given number of uncompressed bytes from the compressed file. If + the input file is not in gzip format, gzread copies the given number of + bytes into the buffer directly from the file. + + After reaching the end of a gzip stream in the input, gzread will continue + to read, looking for another gzip stream. Any number of gzip streams may be + concatenated in the input file, and will all be decompressed by gzread(). + If something other than a gzip stream is encountered after a gzip stream, + that remaining trailing garbage is ignored (and no error is returned). + + gzread can be used to read a gzip file that is being concurrently written. + Upon reaching the end of the input, gzread will return with the available + data. If the error code returned by gzerror is Z_OK or Z_BUF_ERROR, then + gzclearerr can be used to clear the end of file indicator in order to permit + gzread to be tried again. Z_OK indicates that a gzip stream was completed + on the last gzread. Z_BUF_ERROR indicates that the input file ended in the + middle of a gzip stream. Note that gzread does not return -1 in the event + of an incomplete gzip stream. This error is deferred until gzclose(), which + will return Z_BUF_ERROR if the last gzread ended in the middle of a gzip + stream. Alternatively, gzerror can be used before gzclose to detect this + case. + + gzread returns the number of uncompressed bytes actually read, less than + len for end of file, or -1 for error. +*/ + +ZEXTERN int ZEXPORT gzwrite OF((gzFile file, + voidpc buf, unsigned len)); +/* + Writes the given number of uncompressed bytes into the compressed file. + gzwrite returns the number of uncompressed bytes written or 0 in case of + error. +*/ + +ZEXTERN int ZEXPORTVA gzprintf Z_ARG((gzFile file, const char *format, ...)); +/* + Converts, formats, and writes the arguments to the compressed file under + control of the format string, as in fprintf. gzprintf returns the number of + uncompressed bytes actually written, or 0 in case of error. The number of + uncompressed bytes written is limited to 8191, or one less than the buffer + size given to gzbuffer(). The caller should assure that this limit is not + exceeded. If it is exceeded, then gzprintf() will return an error (0) with + nothing written. In this case, there may also be a buffer overflow with + unpredictable consequences, which is possible only if zlib was compiled with + the insecure functions sprintf() or vsprintf() because the secure snprintf() + or vsnprintf() functions were not available. This can be determined using + zlibCompileFlags(). +*/ + +ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); +/* + Writes the given null-terminated string to the compressed file, excluding + the terminating null character. + + gzputs returns the number of characters written, or -1 in case of error. +*/ + +ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len)); +/* + Reads bytes from the compressed file until len-1 characters are read, or a + newline character is read and transferred to buf, or an end-of-file + condition is encountered. If any characters are read or if len == 1, the + string is terminated with a null character. If no characters are read due + to an end-of-file or len < 1, then the buffer is left untouched. + + gzgets returns buf which is a null-terminated string, or it returns NULL + for end-of-file or in case of error. If there was an error, the contents at + buf are indeterminate. +*/ + +ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c)); +/* + Writes c, converted to an unsigned char, into the compressed file. gzputc + returns the value that was written, or -1 in case of error. +*/ + +ZEXTERN int ZEXPORT gzgetc OF((gzFile file)); +/* + Reads one byte from the compressed file. gzgetc returns this byte or -1 + in case of end of file or error. This is implemented as a macro for speed. + As such, it does not do all of the checking the other functions do. I.e. + it does not check to see if file is NULL, nor whether the structure file + points to has been clobbered or not. +*/ + +ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file)); +/* + Push one character back onto the stream to be read as the first character + on the next read. At least one character of push-back is allowed. + gzungetc() returns the character pushed, or -1 on failure. gzungetc() will + fail if c is -1, and may fail if a character has been pushed but not read + yet. If gzungetc is used immediately after gzopen or gzdopen, at least the + output buffer size of pushed characters is allowed. (See gzbuffer above.) + The pushed character will be discarded if the stream is repositioned with + gzseek() or gzrewind(). +*/ + +ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); +/* + Flushes all pending output into the compressed file. The parameter flush + is as in the deflate() function. The return value is the zlib error number + (see function gzerror below). gzflush is only permitted when writing. + + If the flush parameter is Z_FINISH, the remaining data is written and the + gzip stream is completed in the output. If gzwrite() is called again, a new + gzip stream will be started in the output. gzread() is able to read such + concatented gzip streams. + + gzflush should be called only when strictly necessary because it will + degrade compression if called too often. +*/ + +/* +ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, + z_off_t offset, int whence)); + + Sets the starting position for the next gzread or gzwrite on the given + compressed file. The offset represents a number of bytes in the + uncompressed data stream. The whence parameter is defined as in lseek(2); + the value SEEK_END is not supported. + + If the file is opened for reading, this function is emulated but can be + extremely slow. If the file is opened for writing, only forward seeks are + supported; gzseek then compresses a sequence of zeroes up to the new + starting position. + + gzseek returns the resulting offset location as measured in bytes from + the beginning of the uncompressed stream, or -1 in case of error, in + particular if the file is opened for writing and the new starting position + would be before the current position. +*/ + +ZEXTERN int ZEXPORT gzrewind OF((gzFile file)); +/* + Rewinds the given file. This function is supported only for reading. + + gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET) +*/ + +/* +ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file)); + + Returns the starting position for the next gzread or gzwrite on the given + compressed file. This position represents a number of bytes in the + uncompressed data stream, and is zero when starting, even if appending or + reading a gzip stream from the middle of a file using gzdopen(). + + gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR) +*/ + +/* +ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile file)); + + Returns the current offset in the file being read or written. This offset + includes the count of bytes that precede the gzip stream, for example when + appending or when using gzdopen() for reading. When reading, the offset + does not include as yet unused buffered input. This information can be used + for a progress indicator. On error, gzoffset() returns -1. +*/ + +ZEXTERN int ZEXPORT gzeof OF((gzFile file)); +/* + Returns true (1) if the end-of-file indicator has been set while reading, + false (0) otherwise. Note that the end-of-file indicator is set only if the + read tried to go past the end of the input, but came up short. Therefore, + just like feof(), gzeof() may return false even if there is no more data to + read, in the event that the last read request was for the exact number of + bytes remaining in the input file. This will happen if the input file size + is an exact multiple of the buffer size. + + If gzeof() returns true, then the read functions will return no more data, + unless the end-of-file indicator is reset by gzclearerr() and the input file + has grown since the previous end of file was detected. +*/ + +ZEXTERN int ZEXPORT gzdirect OF((gzFile file)); +/* + Returns true (1) if file is being copied directly while reading, or false + (0) if file is a gzip stream being decompressed. + + If the input file is empty, gzdirect() will return true, since the input + does not contain a gzip stream. + + If gzdirect() is used immediately after gzopen() or gzdopen() it will + cause buffers to be allocated to allow reading the file to determine if it + is a gzip file. Therefore if gzbuffer() is used, it should be called before + gzdirect(). + + When writing, gzdirect() returns true (1) if transparent writing was + requested ("wT" for the gzopen() mode), or false (0) otherwise. (Note: + gzdirect() is not needed when writing. Transparent writing must be + explicitly requested, so the application already knows the answer. When + linking statically, using gzdirect() will include all of the zlib code for + gzip file reading and decompression, which may not be desired.) +*/ + +ZEXTERN int ZEXPORT gzclose OF((gzFile file)); +/* + Flushes all pending output if necessary, closes the compressed file and + deallocates the (de)compression state. Note that once file is closed, you + cannot call gzerror with file, since its structures have been deallocated. + gzclose must not be called more than once on the same file, just as free + must not be called more than once on the same allocation. + + gzclose will return Z_STREAM_ERROR if file is not valid, Z_ERRNO on a + file operation error, Z_MEM_ERROR if out of memory, Z_BUF_ERROR if the + last read ended in the middle of a gzip stream, or Z_OK on success. +*/ + +ZEXTERN int ZEXPORT gzclose_r OF((gzFile file)); +ZEXTERN int ZEXPORT gzclose_w OF((gzFile file)); +/* + Same as gzclose(), but gzclose_r() is only for use when reading, and + gzclose_w() is only for use when writing or appending. The advantage to + using these instead of gzclose() is that they avoid linking in zlib + compression or decompression code that is not used when only reading or only + writing respectively. If gzclose() is used, then both compression and + decompression code will be included the application when linking to a static + zlib library. +*/ + +ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)); +/* + Returns the error message for the last error which occurred on the given + compressed file. errnum is set to zlib error number. If an error occurred + in the file system and not in the compression library, errnum is set to + Z_ERRNO and the application may consult errno to get the exact error code. + + The application must not modify the returned string. Future calls to + this function may invalidate the previously returned string. If file is + closed, then the string previously returned by gzerror will no longer be + available. + + gzerror() should be used to distinguish errors from end-of-file for those + functions above that do not distinguish those cases in their return values. +*/ + +ZEXTERN void ZEXPORT gzclearerr OF((gzFile file)); +/* + Clears the error and end-of-file flags for file. This is analogous to the + clearerr() function in stdio. This is useful for continuing to read a gzip + file that is being written concurrently. +*/ + +#endif /* !Z_SOLO */ + + /* checksum functions */ + +/* + These functions are not related to compression but are exported + anyway because they might be useful in applications using the compression + library. +*/ + +ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); +/* + Update a running Adler-32 checksum with the bytes buf[0..len-1] and + return the updated checksum. If buf is Z_NULL, this function returns the + required initial value for the checksum. + + An Adler-32 checksum is almost as reliable as a CRC32 but can be computed + much faster. + + Usage example: + + uLong adler = adler32(0L, Z_NULL, 0); + + while (read_buffer(buffer, length) != EOF) { + adler = adler32(adler, buffer, length); + } + if (adler != original_adler) error(); +*/ + +/* +ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2, + z_off_t len2)); + + Combine two Adler-32 checksums into one. For two sequences of bytes, seq1 + and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for + each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of + seq1 and seq2 concatenated, requiring only adler1, adler2, and len2. Note + that the z_off_t type (like off_t) is a signed integer. If len2 is + negative, the result has no meaning or utility. +*/ + +ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); +/* + Update a running CRC-32 with the bytes buf[0..len-1] and return the + updated CRC-32. If buf is Z_NULL, this function returns the required + initial value for the for the crc. Pre- and post-conditioning (one's + complement) is performed within this function so it shouldn't be done by the + application. + + Usage example: + + uLong crc = crc32(0L, Z_NULL, 0); + + while (read_buffer(buffer, length) != EOF) { + crc = crc32(crc, buffer, length); + } + if (crc != original_crc) error(); +*/ + +/* +ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2)); + + Combine two CRC-32 check values into one. For two sequences of bytes, + seq1 and seq2 with lengths len1 and len2, CRC-32 check values were + calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32 + check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and + len2. +*/ + + + /* various hacks, don't look :) */ + +/* deflateInit and inflateInit are macros to allow checking the zlib version + * and the compiler's view of z_stream: + */ +ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level, + const char *version, int stream_size)); +ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm, + const char *version, int stream_size)); +ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method, + int windowBits, int memLevel, + int strategy, const char *version, + int stream_size)); +ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, + const char *version, int stream_size)); +ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits, + unsigned char FAR *window, + const char *version, + int stream_size)); +#define deflateInit(strm, level) \ + deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream)) +#define inflateInit(strm) \ + inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream)) +#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ + deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ + (strategy), ZLIB_VERSION, (int)sizeof(z_stream)) +#define inflateInit2(strm, windowBits) \ + inflateInit2_((strm), (windowBits), ZLIB_VERSION, \ + (int)sizeof(z_stream)) +#define inflateBackInit(strm, windowBits, window) \ + inflateBackInit_((strm), (windowBits), (window), \ + ZLIB_VERSION, (int)sizeof(z_stream)) + +#ifndef Z_SOLO + +/* gzgetc() macro and its supporting function and exposed data structure. Note + * that the real internal state is much larger than the exposed structure. + * This abbreviated structure exposes just enough for the gzgetc() macro. The + * user should not mess with these exposed elements, since their names or + * behavior could change in the future, perhaps even capriciously. They can + * only be used by the gzgetc() macro. You have been warned. + */ +struct gzFile_s { + unsigned have; + unsigned char *next; + z_off64_t pos; +}; +ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); +#define gzgetc(g) \ + ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc_(g)) + +/* provide 64-bit offset functions if _LARGEFILE64_SOURCE defined, and/or + * change the regular functions to 64 bits if _FILE_OFFSET_BITS is 64 (if + * both are true, the application gets the *64 functions, and the regular + * functions are changed to 64 bits) -- in case these are set on systems + * without large file support, _LFS64_LARGEFILE must also be true + */ +#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0 + ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); + ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int)); + ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile)); + ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile)); + ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off64_t)); + ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off64_t)); +#endif + +#if !defined(ZLIB_INTERNAL) && _FILE_OFFSET_BITS-0 == 64 && _LFS64_LARGEFILE-0 +# ifdef Z_PREFIX_SET +# define z_gzopen z_gzopen64 +# define z_gzseek z_gzseek64 +# define z_gztell z_gztell64 +# define z_gzoffset z_gzoffset64 +# define z_adler32_combine z_adler32_combine64 +# define z_crc32_combine z_crc32_combine64 +# else +# define gzopen gzopen64 +# define gzseek gzseek64 +# define gztell gztell64 +# define gzoffset gzoffset64 +# define adler32_combine adler32_combine64 +# define crc32_combine crc32_combine64 +# endif +# ifndef _LARGEFILE64_SOURCE + ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); + ZEXTERN z_off_t ZEXPORT gzseek64 OF((gzFile, z_off_t, int)); + ZEXTERN z_off_t ZEXPORT gztell64 OF((gzFile)); + ZEXTERN z_off_t ZEXPORT gzoffset64 OF((gzFile)); + ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t)); + ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t)); +# endif +#else + ZEXTERN gzFile ZEXPORT gzopen OF((const char *, const char *)); + ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile, z_off_t, int)); + ZEXTERN z_off_t ZEXPORT gztell OF((gzFile)); + ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile)); + ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t)); + ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t)); +#endif + +#else /* Z_SOLO */ + + ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t)); + ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t)); + +#endif /* !Z_SOLO */ + +/* hack for buggy compilers */ +#if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL) + struct internal_state {int dummy;}; +#endif + +/* undocumented functions */ +ZEXTERN const char * ZEXPORT zError OF((int)); +ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp)); +ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void)); +ZEXTERN int ZEXPORT inflateUndermine OF((z_streamp, int)); +ZEXTERN int ZEXPORT inflateResetKeep OF((z_streamp)); +ZEXTERN int ZEXPORT deflateResetKeep OF((z_streamp)); +#ifndef Z_SOLO + ZEXTERN unsigned long ZEXPORT gzflags OF((void)); +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* ZLIB_H */ diff --git a/libs/zlib/zlib.map b/libs/zlib/zlib.map new file mode 100644 index 000000000..54fa5538a --- /dev/null +++ b/libs/zlib/zlib.map @@ -0,0 +1,79 @@ +ZLIB_1.2.0 { + global: + compressBound; + deflateBound; + inflateBack; + inflateBackEnd; + inflateBackInit_; + inflateCopy; + local: + deflate_copyright; + inflate_copyright; + inflate_fast; + inflate_table; + zcalloc; + zcfree; + z_errmsg; + gz_error; + gz_intmax; + _*; +}; + +ZLIB_1.2.0.2 { + gzclearerr; + gzungetc; + zlibCompileFlags; +} ZLIB_1.2.0; + +ZLIB_1.2.0.8 { + deflatePrime; +} ZLIB_1.2.0.2; + +ZLIB_1.2.2 { + adler32_combine; + crc32_combine; + deflateSetHeader; + inflateGetHeader; +} ZLIB_1.2.0.8; + +ZLIB_1.2.2.3 { + deflateTune; + gzdirect; +} ZLIB_1.2.2; + +ZLIB_1.2.2.4 { + inflatePrime; +} ZLIB_1.2.2.3; + +ZLIB_1.2.3.3 { + adler32_combine64; + crc32_combine64; + gzopen64; + gzseek64; + gztell64; + inflateUndermine; +} ZLIB_1.2.2.4; + +ZLIB_1.2.3.4 { + inflateReset2; + inflateMark; +} ZLIB_1.2.3.3; + +ZLIB_1.2.3.5 { + gzbuffer; + gzoffset; + gzoffset64; + gzclose_r; + gzclose_w; +} ZLIB_1.2.3.4; + +ZLIB_1.2.5.1 { + deflatePending; +} ZLIB_1.2.3.5; + +ZLIB_1.2.5.2 { + deflateResetKeep; + gzflags; + gzgetc_; + inflateResetKeep; +} ZLIB_1.2.5.1; diff --git a/libs/zlib/zlib.pc.in b/libs/zlib/zlib.pc.in new file mode 100644 index 000000000..7e5acf9c7 --- /dev/null +++ b/libs/zlib/zlib.pc.in @@ -0,0 +1,13 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +sharedlibdir=@sharedlibdir@ +includedir=@includedir@ + +Name: zlib +Description: zlib compression library +Version: @VERSION@ + +Requires: +Libs: -L${libdir} -L${sharedlibdir} -lz +Cflags: -I${includedir} diff --git a/libs/zlib/zlib2ansi b/libs/zlib/zlib2ansi new file mode 100755 index 000000000..15e3e165f --- /dev/null +++ b/libs/zlib/zlib2ansi @@ -0,0 +1,152 @@ +#!/usr/bin/perl + +# Transform K&R C function definitions into ANSI equivalent. +# +# Author: Paul Marquess +# Version: 1.0 +# Date: 3 October 2006 + +# TODO +# +# Asumes no function pointer parameters. unless they are typedefed. +# Assumes no literal strings that look like function definitions +# Assumes functions start at the beginning of a line + +use strict; +use warnings; + +local $/; +$_ = <>; + +my $sp = qr{ \s* (?: /\* .*? \*/ )? \s* }x; # assume no nested comments + +my $d1 = qr{ $sp (?: [\w\*\s]+ $sp)* $sp \w+ $sp [\[\]\s]* $sp }x ; +my $decl = qr{ $sp (?: \w+ $sp )+ $d1 }xo ; +my $dList = qr{ $sp $decl (?: $sp , $d1 )* $sp ; $sp }xo ; + + +while (s/^ + ( # Start $1 + ( # Start $2 + .*? # Minimal eat content + ( ^ \w [\w\s\*]+ ) # $3 -- function name + \s* # optional whitespace + ) # $2 - Matched up to before parameter list + + \( \s* # Literal "(" + optional whitespace + ( [^\)]+ ) # $4 - one or more anythings except ")" + \s* \) # optional whitespace surrounding a Literal ")" + + ( (?: $dList )+ ) # $5 + + $sp ^ { # literal "{" at start of line + ) # Remember to $1 + //xsom + ) +{ + my $all = $1 ; + my $prefix = $2; + my $param_list = $4 ; + my $params = $5; + + StripComments($params); + StripComments($param_list); + $param_list =~ s/^\s+//; + $param_list =~ s/\s+$//; + + my $i = 0 ; + my %pList = map { $_ => $i++ } + split /\s*,\s*/, $param_list; + my $pMatch = '(\b' . join('|', keys %pList) . '\b)\W*$' ; + + my @params = split /\s*;\s*/, $params; + my @outParams = (); + foreach my $p (@params) + { + if ($p =~ /,/) + { + my @bits = split /\s*,\s*/, $p; + my $first = shift @bits; + $first =~ s/^\s*//; + push @outParams, $first; + $first =~ /^(\w+\s*)/; + my $type = $1 ; + push @outParams, map { $type . $_ } @bits; + } + else + { + $p =~ s/^\s+//; + push @outParams, $p; + } + } + + + my %tmp = map { /$pMatch/; $_ => $pList{$1} } + @outParams ; + + @outParams = map { " $_" } + sort { $tmp{$a} <=> $tmp{$b} } + @outParams ; + + print $prefix ; + print "(\n" . join(",\n", @outParams) . ")\n"; + print "{" ; + +} + +# Output any trailing code. +print ; +exit 0; + + +sub StripComments +{ + + no warnings; + + # Strip C & C++ coments + # From the perlfaq + $_[0] =~ + + s{ + /\* ## Start of /* ... */ comment + [^*]*\*+ ## Non-* followed by 1-or-more *'s + ( + [^/*][^*]*\*+ + )* ## 0-or-more things which don't start with / + ## but do end with '*' + / ## End of /* ... */ comment + + | ## OR C++ Comment + // ## Start of C++ comment // + [^\n]* ## followed by 0-or-more non end of line characters + + | ## OR various things which aren't comments: + + ( + " ## Start of " ... " string + ( + \\. ## Escaped char + | ## OR + [^"\\] ## Non "\ + )* + " ## End of " ... " string + + | ## OR + + ' ## Start of ' ... ' string + ( + \\. ## Escaped char + | ## OR + [^'\\] ## Non '\ + )* + ' ## End of ' ... ' string + + | ## OR + + . ## Anything other char + [^/"'\\]* ## Chars which doesn't start a comment, string or escape + ) + }{$2}gxs; + +} diff --git a/libs/zlib/zutil.c b/libs/zlib/zutil.c new file mode 100644 index 000000000..8a1d24209 --- /dev/null +++ b/libs/zlib/zutil.c @@ -0,0 +1,301 @@ +/* zutil.c -- target dependent utility functions for the compression library + * Copyright (C) 1995-2005, 2010, 2011 Jean-loup Gailly. + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* @(#) $Id$ */ + +#include "zutil.h" + +#ifndef NO_DUMMY_DECL +struct internal_state {int dummy;}; /* for buggy compilers */ +#endif + +const char * const z_errmsg[10] = { +"need dictionary", /* Z_NEED_DICT 2 */ +"stream end", /* Z_STREAM_END 1 */ +"", /* Z_OK 0 */ +"file error", /* Z_ERRNO (-1) */ +"stream error", /* Z_STREAM_ERROR (-2) */ +"data error", /* Z_DATA_ERROR (-3) */ +"insufficient memory", /* Z_MEM_ERROR (-4) */ +"buffer error", /* Z_BUF_ERROR (-5) */ +"incompatible version",/* Z_VERSION_ERROR (-6) */ +""}; + + +const char * ZEXPORT zlibVersion() +{ + return ZLIB_VERSION; +} + +uLong ZEXPORT zlibCompileFlags() +{ + uLong flags; + + flags = 0; + switch ((int)(sizeof(uInt))) { + case 2: break; + case 4: flags += 1; break; + case 8: flags += 2; break; + default: flags += 3; + } + switch ((int)(sizeof(uLong))) { + case 2: break; + case 4: flags += 1 << 2; break; + case 8: flags += 2 << 2; break; + default: flags += 3 << 2; + } + switch ((int)(sizeof(voidpf))) { + case 2: break; + case 4: flags += 1 << 4; break; + case 8: flags += 2 << 4; break; + default: flags += 3 << 4; + } + switch ((int)(sizeof(z_off_t))) { + case 2: break; + case 4: flags += 1 << 6; break; + case 8: flags += 2 << 6; break; + default: flags += 3 << 6; + } +#ifdef DEBUG + flags += 1 << 8; +#endif +#if defined(ASMV) || defined(ASMINF) + flags += 1 << 9; +#endif +#ifdef ZLIB_WINAPI + flags += 1 << 10; +#endif +#ifdef BUILDFIXED + flags += 1 << 12; +#endif +#ifdef DYNAMIC_CRC_TABLE + flags += 1 << 13; +#endif +#ifdef NO_GZCOMPRESS + flags += 1L << 16; +#endif +#ifdef NO_GZIP + flags += 1L << 17; +#endif +#ifdef PKZIP_BUG_WORKAROUND + flags += 1L << 20; +#endif +#ifdef FASTEST + flags += 1L << 21; +#endif +#ifdef Z_SOLO + return flags; +#else + return flags + gzflags(); +#endif +} + +#ifdef DEBUG + +# ifndef verbose +# define verbose 0 +# endif +int ZLIB_INTERNAL z_verbose = verbose; + +void ZLIB_INTERNAL z_error (m) + char *m; +{ + fprintf(stderr, "%s\n", m); + exit(1); +} +#endif + +/* exported to allow conversion of error code to string for compress() and + * uncompress() + */ +const char * ZEXPORT zError(err) + int err; +{ + return ERR_MSG(err); +} + +#if defined(_WIN32_WCE) + /* The Microsoft C Run-Time Library for Windows CE doesn't have + * errno. We define it as a global variable to simplify porting. + * Its value is always 0 and should not be used. + */ + int errno = 0; +#endif + +#ifndef HAVE_MEMCPY + +void ZLIB_INTERNAL zmemcpy(dest, source, len) + Bytef* dest; + const Bytef* source; + uInt len; +{ + if (len == 0) return; + do { + *dest++ = *source++; /* ??? to be unrolled */ + } while (--len != 0); +} + +int ZLIB_INTERNAL zmemcmp(s1, s2, len) + const Bytef* s1; + const Bytef* s2; + uInt len; +{ + uInt j; + + for (j = 0; j < len; j++) { + if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1; + } + return 0; +} + +void ZLIB_INTERNAL zmemzero(dest, len) + Bytef* dest; + uInt len; +{ + if (len == 0) return; + do { + *dest++ = 0; /* ??? to be unrolled */ + } while (--len != 0); +} +#endif + +#ifndef Z_SOLO + +#ifdef SYS16BIT + +#ifdef __TURBOC__ +/* Turbo C in 16-bit mode */ + +# define MY_ZCALLOC + +/* Turbo C malloc() does not allow dynamic allocation of 64K bytes + * and farmalloc(64K) returns a pointer with an offset of 8, so we + * must fix the pointer. Warning: the pointer must be put back to its + * original form in order to free it, use zcfree(). + */ + +#define MAX_PTR 10 +/* 10*64K = 640K */ + +local int next_ptr = 0; + +typedef struct ptr_table_s { + voidpf org_ptr; + voidpf new_ptr; +} ptr_table; + +local ptr_table table[MAX_PTR]; +/* This table is used to remember the original form of pointers + * to large buffers (64K). Such pointers are normalized with a zero offset. + * Since MSDOS is not a preemptive multitasking OS, this table is not + * protected from concurrent access. This hack doesn't work anyway on + * a protected system like OS/2. Use Microsoft C instead. + */ + +voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size) +{ + voidpf buf = opaque; /* just to make some compilers happy */ + ulg bsize = (ulg)items*size; + + /* If we allocate less than 65520 bytes, we assume that farmalloc + * will return a usable pointer which doesn't have to be normalized. + */ + if (bsize < 65520L) { + buf = farmalloc(bsize); + if (*(ush*)&buf != 0) return buf; + } else { + buf = farmalloc(bsize + 16L); + } + if (buf == NULL || next_ptr >= MAX_PTR) return NULL; + table[next_ptr].org_ptr = buf; + + /* Normalize the pointer to seg:0 */ + *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4; + *(ush*)&buf = 0; + table[next_ptr++].new_ptr = buf; + return buf; +} + +void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) +{ + int n; + if (*(ush*)&ptr != 0) { /* object < 64K */ + farfree(ptr); + return; + } + /* Find the original pointer */ + for (n = 0; n < next_ptr; n++) { + if (ptr != table[n].new_ptr) continue; + + farfree(table[n].org_ptr); + while (++n < next_ptr) { + table[n-1] = table[n]; + } + next_ptr--; + return; + } + ptr = opaque; /* just to make some compilers happy */ + Assert(0, "zcfree: ptr not found"); +} + +#endif /* __TURBOC__ */ + + +#ifdef M_I86 +/* Microsoft C in 16-bit mode */ + +# define MY_ZCALLOC + +#if (!defined(_MSC_VER) || (_MSC_VER <= 600)) +# define _halloc halloc +# define _hfree hfree +#endif + +voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, uInt items, uInt size) +{ + if (opaque) opaque = 0; /* to make compiler happy */ + return _halloc((long)items, size); +} + +void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) +{ + if (opaque) opaque = 0; /* to make compiler happy */ + _hfree(ptr); +} + +#endif /* M_I86 */ + +#endif /* SYS16BIT */ + + +#ifndef MY_ZCALLOC /* Any system without a special alloc function */ + +#ifndef STDC +extern voidp malloc OF((uInt size)); +extern voidp calloc OF((uInt items, uInt size)); +extern void free OF((voidpf ptr)); +#endif + +voidpf ZLIB_INTERNAL zcalloc (opaque, items, size) + voidpf opaque; + unsigned items; + unsigned size; +{ + if (opaque) items += size - size; /* make compiler happy */ + return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) : + (voidpf)calloc(items, size); +} + +void ZLIB_INTERNAL zcfree (opaque, ptr) + voidpf opaque; + voidpf ptr; +{ + free(ptr); + if (opaque) return; /* make compiler happy */ +} + +#endif /* MY_ZCALLOC */ + +#endif /* !Z_SOLO */ diff --git a/libs/zlib/zutil.h b/libs/zlib/zutil.h new file mode 100644 index 000000000..dff1112fe --- /dev/null +++ b/libs/zlib/zutil.h @@ -0,0 +1,248 @@ +/* zutil.h -- internal interface and configuration of the compression library + * Copyright (C) 1995-2011 Jean-loup Gailly. + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* WARNING: this file should *not* be used by applications. It is + part of the implementation of the compression library and is + subject to change. Applications should only use zlib.h. + */ + +/* @(#) $Id$ */ + +#ifndef ZUTIL_H +#define ZUTIL_H + +#if ((__GNUC__-0) * 10 + __GNUC_MINOR__-0 >= 33) && !defined(NO_VIZ) +# define ZLIB_INTERNAL __attribute__((visibility ("hidden"))) +#else +# define ZLIB_INTERNAL +#endif + +#include "zlib.h" + +#if defined(STDC) && !defined(Z_SOLO) +# if !(defined(_WIN32_WCE) && defined(_MSC_VER)) +# include +# endif +# include +# include +#endif + +#ifdef Z_SOLO + typedef long ptrdiff_t; /* guess -- will be caught if guess is wrong */ +#endif + +#ifndef local +# define local static +#endif +/* compile with -Dlocal if your debugger can't find static symbols */ + +typedef unsigned char uch; +typedef uch FAR uchf; +typedef unsigned short ush; +typedef ush FAR ushf; +typedef unsigned long ulg; + +extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ +/* (size given to avoid silly warnings with Visual C++) */ + +#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)] + +#define ERR_RETURN(strm,err) \ + return (strm->msg = (char*)ERR_MSG(err), (err)) +/* To be used only when the state is known to be valid */ + + /* common constants */ + +#ifndef DEF_WBITS +# define DEF_WBITS MAX_WBITS +#endif +/* default windowBits for decompression. MAX_WBITS is for compression only */ + +#if MAX_MEM_LEVEL >= 8 +# define DEF_MEM_LEVEL 8 +#else +# define DEF_MEM_LEVEL MAX_MEM_LEVEL +#endif +/* default memLevel */ + +#define STORED_BLOCK 0 +#define STATIC_TREES 1 +#define DYN_TREES 2 +/* The three kinds of block type */ + +#define MIN_MATCH 3 +#define MAX_MATCH 258 +/* The minimum and maximum match lengths */ + +#define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */ + + /* target dependencies */ + +#if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32)) +# define OS_CODE 0x00 +# ifndef Z_SOLO +# if defined(__TURBOC__) || defined(__BORLANDC__) +# if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__)) + /* Allow compilation with ANSI keywords only enabled */ + void _Cdecl farfree( void *block ); + void *_Cdecl farmalloc( unsigned long nbytes ); +# else +# include +# endif +# else /* MSC or DJGPP */ +# include +# endif +# endif +#endif + +#ifdef AMIGA +# define OS_CODE 0x01 +#endif + +#if defined(VAXC) || defined(VMS) +# define OS_CODE 0x02 +# define F_OPEN(name, mode) \ + fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512") +#endif + +#if defined(ATARI) || defined(atarist) +# define OS_CODE 0x05 +#endif + +#ifdef OS2 +# define OS_CODE 0x06 +# if defined(M_I86) && !defined(Z_SOLO) +# include +# endif +#endif + +#if defined(MACOS) || defined(TARGET_OS_MAC) +# define OS_CODE 0x07 +# ifndef Z_SOLO +# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os +# include /* for fdopen */ +# else +# ifndef fdopen +# define fdopen(fd,mode) NULL /* No fdopen() */ +# endif +# endif +# endif +#endif + +#ifdef TOPS20 +# define OS_CODE 0x0a +#endif + +#ifdef WIN32 +# ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */ +# define OS_CODE 0x0b +# endif +#endif + +#ifdef __50SERIES /* Prime/PRIMOS */ +# define OS_CODE 0x0f +#endif + +#if defined(_BEOS_) || defined(RISCOS) +# define fdopen(fd,mode) NULL /* No fdopen() */ +#endif + +#if (defined(_MSC_VER) && (_MSC_VER > 600)) && !defined __INTERIX +# if defined(_WIN32_WCE) +# define fdopen(fd,mode) NULL /* No fdopen() */ +# ifndef _PTRDIFF_T_DEFINED + typedef int ptrdiff_t; +# define _PTRDIFF_T_DEFINED +# endif +# else +# define fdopen(fd,type) _fdopen(fd,type) +# endif +#endif + +#if defined(__BORLANDC__) && !defined(MSDOS) + #pragma warn -8004 + #pragma warn -8008 + #pragma warn -8066 +#endif + +/* provide prototypes for these when building zlib without LFS */ +#if !defined(_WIN32) && (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0) + ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t)); + ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t)); +#endif + + /* common defaults */ + +#ifndef OS_CODE +# define OS_CODE 0x03 /* assume Unix */ +#endif + +#ifndef F_OPEN +# define F_OPEN(name, mode) fopen((name), (mode)) +#endif + + /* functions */ + +#if defined(pyr) || defined(Z_SOLO) +# define NO_MEMCPY +#endif +#if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__) + /* Use our own functions for small and medium model with MSC <= 5.0. + * You may have to use the same strategy for Borland C (untested). + * The __SC__ check is for Symantec. + */ +# define NO_MEMCPY +#endif +#if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY) +# define HAVE_MEMCPY +#endif +#ifdef HAVE_MEMCPY +# ifdef SMALL_MEDIUM /* MSDOS small or medium model */ +# define zmemcpy _fmemcpy +# define zmemcmp _fmemcmp +# define zmemzero(dest, len) _fmemset(dest, 0, len) +# else +# define zmemcpy memcpy +# define zmemcmp memcmp +# define zmemzero(dest, len) memset(dest, 0, len) +# endif +#else + void ZLIB_INTERNAL zmemcpy OF((Bytef* dest, const Bytef* source, uInt len)); + int ZLIB_INTERNAL zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len)); + void ZLIB_INTERNAL zmemzero OF((Bytef* dest, uInt len)); +#endif + +/* Diagnostic functions */ +#ifdef DEBUG +# include + extern int ZLIB_INTERNAL z_verbose; + extern void ZLIB_INTERNAL z_error OF((char *m)); +# define Assert(cond,msg) {if(!(cond)) z_error(msg);} +# define Trace(x) {if (z_verbose>=0) fprintf x ;} +# define Tracev(x) {if (z_verbose>0) fprintf x ;} +# define Tracevv(x) {if (z_verbose>1) fprintf x ;} +# define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;} +# define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;} +#else +# define Assert(cond,msg) +# define Trace(x) +# define Tracev(x) +# define Tracevv(x) +# define Tracec(c,x) +# define Tracecv(c,x) +#endif + +#ifndef Z_SOLO + voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items, + unsigned size)); + void ZLIB_INTERNAL zcfree OF((voidpf opaque, voidpf ptr)); +#endif + +#define ZALLOC(strm, items, size) \ + (*((strm)->zalloc))((strm)->opaque, (items), (size)) +#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr)) +#define TRY_FREE(s, p) {if (p) ZFREE(s, p);} + +#endif /* ZUTIL_H */ diff --git a/libs/zlibVC6.diff b/libs/zlibVC6.diff new file mode 100644 index 000000000..fbe70a396 --- /dev/null +++ b/libs/zlibVC6.diff @@ -0,0 +1,11 @@ +--- zconf.h Wed Jul 20 17:40:26 2005 ++++ zconf.h Sun May 21 14:38:10 2006 +@@ -284,7 +284,7 @@ + typedef Byte *voidp; + #endif + +-#if 1 /* HAVE_UNISTD_H -- this line is updated by ./configure */ ++#if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */ + # include /* for off_t */ + # include /* for SEEK_* and off_t */ + # ifdef VMS diff --git a/objs/DC/SDL/Debug/.gitignore b/objs/DC/SDL/Debug/.gitignore new file mode 100644 index 000000000..867fcb4e0 --- /dev/null +++ b/objs/DC/SDL/Debug/.gitignore @@ -0,0 +1 @@ +/depend.dep diff --git a/objs/DC/SDL/Release/.gitignore b/objs/DC/SDL/Release/.gitignore new file mode 100644 index 000000000..867fcb4e0 --- /dev/null +++ b/objs/DC/SDL/Release/.gitignore @@ -0,0 +1 @@ +/depend.dep diff --git a/objs/Linux/SDL/Debug/.gitignore b/objs/Linux/SDL/Debug/.gitignore new file mode 100644 index 000000000..8f6d0bdcd --- /dev/null +++ b/objs/Linux/SDL/Debug/.gitignore @@ -0,0 +1,2 @@ +/depend.dep +/*.o diff --git a/objs/Linux/SDL/Release/.gitignore b/objs/Linux/SDL/Release/.gitignore new file mode 100644 index 000000000..8f6d0bdcd --- /dev/null +++ b/objs/Linux/SDL/Release/.gitignore @@ -0,0 +1,2 @@ +/depend.dep +/*.o diff --git a/objs/Linux64/SDL/Debug/.gitignore b/objs/Linux64/SDL/Debug/.gitignore new file mode 100644 index 000000000..8f6d0bdcd --- /dev/null +++ b/objs/Linux64/SDL/Debug/.gitignore @@ -0,0 +1,2 @@ +/depend.dep +/*.o diff --git a/objs/Linux64/SDL/Release/.gitignore b/objs/Linux64/SDL/Release/.gitignore new file mode 100644 index 000000000..8f6d0bdcd --- /dev/null +++ b/objs/Linux64/SDL/Release/.gitignore @@ -0,0 +1,2 @@ +/depend.dep +/*.o diff --git a/objs/Mingw/Debug/.gitignore b/objs/Mingw/Debug/.gitignore new file mode 100644 index 000000000..da4b3e912 --- /dev/null +++ b/objs/Mingw/Debug/.gitignore @@ -0,0 +1,3 @@ +/SRB2.res +/depend.dep +/*.o diff --git a/objs/Mingw/Release/.gitignore b/objs/Mingw/Release/.gitignore new file mode 100644 index 000000000..da4b3e912 --- /dev/null +++ b/objs/Mingw/Release/.gitignore @@ -0,0 +1,3 @@ +/SRB2.res +/depend.dep +/*.o diff --git a/objs/Mingw/SDL/Debug/.gitignore b/objs/Mingw/SDL/Debug/.gitignore new file mode 100644 index 000000000..da4b3e912 --- /dev/null +++ b/objs/Mingw/SDL/Debug/.gitignore @@ -0,0 +1,3 @@ +/SRB2.res +/depend.dep +/*.o diff --git a/objs/Mingw/SDL/Release/.gitignore b/objs/Mingw/SDL/Release/.gitignore new file mode 100644 index 000000000..da4b3e912 --- /dev/null +++ b/objs/Mingw/SDL/Release/.gitignore @@ -0,0 +1,3 @@ +/SRB2.res +/depend.dep +/*.o diff --git a/objs/Mingw64/Debug/.gitignore b/objs/Mingw64/Debug/.gitignore new file mode 100644 index 000000000..da4b3e912 --- /dev/null +++ b/objs/Mingw64/Debug/.gitignore @@ -0,0 +1,3 @@ +/SRB2.res +/depend.dep +/*.o diff --git a/objs/Mingw64/Release/.gitignore b/objs/Mingw64/Release/.gitignore new file mode 100644 index 000000000..da4b3e912 --- /dev/null +++ b/objs/Mingw64/Release/.gitignore @@ -0,0 +1,3 @@ +/SRB2.res +/depend.dep +/*.o diff --git a/objs/Mingw64/SDL/Debug/.gitignore b/objs/Mingw64/SDL/Debug/.gitignore new file mode 100644 index 000000000..da4b3e912 --- /dev/null +++ b/objs/Mingw64/SDL/Debug/.gitignore @@ -0,0 +1,3 @@ +/SRB2.res +/depend.dep +/*.o diff --git a/objs/Mingw64/SDL/Release/.gitignore b/objs/Mingw64/SDL/Release/.gitignore new file mode 100644 index 000000000..da4b3e912 --- /dev/null +++ b/objs/Mingw64/SDL/Release/.gitignore @@ -0,0 +1,3 @@ +/SRB2.res +/depend.dep +/*.o diff --git a/objs/PS3/SDL/Debug/.gitignore b/objs/PS3/SDL/Debug/.gitignore new file mode 100644 index 000000000..8f6d0bdcd --- /dev/null +++ b/objs/PS3/SDL/Debug/.gitignore @@ -0,0 +1,2 @@ +/depend.dep +/*.o diff --git a/objs/PS3/SDL/Release/.gitignore b/objs/PS3/SDL/Release/.gitignore new file mode 100644 index 000000000..8f6d0bdcd --- /dev/null +++ b/objs/PS3/SDL/Release/.gitignore @@ -0,0 +1,2 @@ +/depend.dep +/*.o diff --git a/objs/PSP/SDL/Release/.gitignore b/objs/PSP/SDL/Release/.gitignore new file mode 100644 index 000000000..867fcb4e0 --- /dev/null +++ b/objs/PSP/SDL/Release/.gitignore @@ -0,0 +1 @@ +/depend.dep diff --git a/objs/SDL/Release/.gitignore b/objs/SDL/Release/.gitignore new file mode 100644 index 000000000..4a262f94f --- /dev/null +++ b/objs/SDL/Release/.gitignore @@ -0,0 +1 @@ +/depend.ped diff --git a/objs/VC/.gitignore b/objs/VC/.gitignore new file mode 100644 index 000000000..e69de29bb diff --git a/objs/VC9/.gitignore b/objs/VC9/.gitignore new file mode 100644 index 000000000..205fe45de --- /dev/null +++ b/objs/VC9/.gitignore @@ -0,0 +1,2 @@ +/Win32 +/x64 diff --git a/objs/Wii/SDL/Debug/.gitignore b/objs/Wii/SDL/Debug/.gitignore new file mode 100644 index 000000000..8f6d0bdcd --- /dev/null +++ b/objs/Wii/SDL/Debug/.gitignore @@ -0,0 +1,2 @@ +/depend.dep +/*.o diff --git a/objs/Wii/SDL/Release/.gitignore b/objs/Wii/SDL/Release/.gitignore new file mode 100644 index 000000000..8f6d0bdcd --- /dev/null +++ b/objs/Wii/SDL/Release/.gitignore @@ -0,0 +1,2 @@ +/depend.dep +/*.o diff --git a/objs/WinCE/SDL/Release/.gitignore b/objs/WinCE/SDL/Release/.gitignore new file mode 100644 index 000000000..867fcb4e0 --- /dev/null +++ b/objs/WinCE/SDL/Release/.gitignore @@ -0,0 +1 @@ +/depend.dep diff --git a/objs/djgppdos/Debug/.gitignore b/objs/djgppdos/Debug/.gitignore new file mode 100644 index 000000000..867fcb4e0 --- /dev/null +++ b/objs/djgppdos/Debug/.gitignore @@ -0,0 +1 @@ +/depend.dep diff --git a/objs/djgppdos/Release/.gitignore b/objs/djgppdos/Release/.gitignore new file mode 100644 index 000000000..867fcb4e0 --- /dev/null +++ b/objs/djgppdos/Release/.gitignore @@ -0,0 +1 @@ +/depend.dep diff --git a/objs/nds/Debug/.gitignore b/objs/nds/Debug/.gitignore new file mode 100644 index 000000000..8f6d0bdcd --- /dev/null +++ b/objs/nds/Debug/.gitignore @@ -0,0 +1,2 @@ +/depend.dep +/*.o diff --git a/objs/nds/Release/.gitignore b/objs/nds/Release/.gitignore new file mode 100644 index 000000000..8f6d0bdcd --- /dev/null +++ b/objs/nds/Release/.gitignore @@ -0,0 +1,2 @@ +/depend.dep +/*.o diff --git a/readme.txt b/readme.txt new file mode 100644 index 000000000..f60648a51 --- /dev/null +++ b/readme.txt @@ -0,0 +1,148 @@ +Here it is! SRB2 v2.0 source code! + + +Win32 with Visual C (6SP6+Processor Pack OR 7) +~~~ + +2 VC++ 6.0 project files are included: + +Win32/DirectX/FMOD +src\win32\wLegacy.dsw +You'll need FMOD to compile this version (www.fmod.org) +or +Win32/SDL/SDL_mixer +src\sdl\Win32SDL.dsp +You'll need SDL and SDL_mixer for this version (www.libsdl.org) + +Both needs NASM (http://sourceforge.net/projects/nasm) +For PNG screenshot, libPNG, and Zlib (from http://gnuwin32.sourceforge.net/) + +No warranty, support, etc. of any kind is offered, +just plain old as is. +Some bits of code are still really scary. +Go nuts! + + +Win32 with Dev-C++ (http://bloodshed.net/ free!) +~~~ +2 Dev-C++ project files are included: + +Win32/DirectX/FMOD +src\win32\SRB2.dev +or +Win32/SDL/SDL_mixer +src\sdl\Win32SDL.dev +You'll need SDL and SDL_mixer for this version (www.libsdl.org) +libPNG and Zlib (from http://gnuwin32.sourceforge.net/) +Note there are precompiled libpng.a and libz.a for Mingw + +you will need NASM for both SDL/SDL_mixer and DirectX/FMOD +and you need DirectX 6 (or up) Dev-Paks to compile DirectX version + +GNU/Linux +~~~ + +Dependencies: + SDL 1.2.7 or better (from libsdl.org) + SDL_Mixer 1.2.2(.7 for file-less music playback) (from libsdl.org) + Nasm (use NOASM=1 if you don't have it or have an non-i386 system, I think) + libPNG 1.2.7 + Zlib 1.2.3 + The Xiph.org libogg and libvorbis libraries + The OpenGL headers (from Mesa, usually shipped with your X.org or XFree + installation, so you needn't worry, most likely) + GCC 3.x toolchain and binutils + GNU Make + +Build instructions: + +make -C src LINUX=1 + +Build instructions to build for Wii Linux/SRB2Wii on a PowerPC system, +follow cross-compiling instructions for cross-compiling on a x86 system: + +make -C src LINUX=1 WIILINUX=1 + +Build instructions to build for Pandora (Linux) on a ARM system, +follow cross-compiling instructions for cross-compiling on a x86 system: + +make -C src PANDORA=1 + +Solaris +~~~ + +Dependencies: + SDL 1.2.5 or better (from libsdl.org) + SDL_Mixer 1.2.2(.7 for file-less music playback) (from libsdl.org) + libPNG 1.2.7 + Zlib 1.2.3 + The Xiph.org libogg and libvorbis libraries + The OpenGL headers (from Mesa, usually shipped with your X.org or XFree + installation, so you needn't worry, most likely) + GCC 3.x toolchain and binutils + GNU Make + + You can get all these programs/libraries from the Companion CD (except SDL_mixer and OpenGL) + +Build instructions: + +gmake -C src SOLARIS=1 + +FreeBSD +~~~ + +Dependencies: + SDL 1.2.7 or better (from libsdl.org) + SDL_Mixer 1.2.2(.7 for file-less music playback) (from libsdl.org) + Nasm (use NOASM=1 if you don't have it or have an non-i386 system, I think) + libPNG 1.2.7 + Zlib 1.2.3 + The Xiph.org libogg and libvorbis libraries + The OpenGL headers (from Mesa, usually shipped with your X.org or XFree + installation, so you needn't worry, most likely) + GCC 3.x toolchain and binutils + GNU Make + +Build instructions: + +gmake -C src FREEBSD=1 + +DJGPP/DOS +~~~ + +Dependencies: + Allegro 3.12 game programming library, (from + http://alleg.sourceforge.net/index.html) + Nasm (use NOASM=1 if you don't have it) + libsocket (from http://homepages.nildram.co.uk/~phekda/richdawe/lsck/) or + Watt-32 (from http://www.bgnett.no/~giva/) + GCC 3.x toolchain and binutils + GNU Make + +Build instructions: + +make -C src # to link with Watt-32, add WATTCP=1 + # for remote debugging over the COM port, add RDB=1 + +Notes: + use tools\djgpp\all313.diff to update Allegro to a "more usable" version ;) + Example: E:\djgpp\allegro>patch -p# < D:\SRB2Code\1.1\srb2\tools\djgpp\all313.diff + +Windows CE +~~~ + +Dependencies: + SDL 1.27 + +Build instructions: + +use src\SDL\WinCE\SRB2CE.vcw + +------------------------------------------------------------------------------- + +binaries will turn in up in bin/ + +note: read the src/makefile for more options + +- Sonic Team Junior +http://www.srb2.org diff --git a/srb2-vc10.sln b/srb2-vc10.sln new file mode 100644 index 000000000..e208a83e9 --- /dev/null +++ b/srb2-vc10.sln @@ -0,0 +1,72 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual C++ Express 2010 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Srb2win", "src\win32\Srb2win-vc10.vcxproj", "{0F554F1D-ED49-4D65-A9A7-F63C57F277BE}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libpng", "libs\libpng-src\projects\visualc10\libpng.vcxproj", "{72B01ACA-7A1A-4F7B-ACEF-2607299CF052}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "r_opengl", "src\hardware\r_opengl\r_opengl-vc10.vcxproj", "{51137D5C-4E81-4955-AACF-EA3092006051}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlib", "libs\zlib\projects\visualc10\zlib.vcxproj", "{73A5729C-7323-41D4-AB48-8A03C9F81603}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "s_openal", "src\hardware\s_openal\s_openal-vc10.vcxproj", "{E662D0B3-412D-4D55-A5EC-8CBD680DDCBE}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Srb2SDL", "src\sdl\Srb2SDL-vc10.vcxproj", "{61BA7D3C-F77D-4D31-B718-1177FE482CF2}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {0F554F1D-ED49-4D65-A9A7-F63C57F277BE}.Debug|Win32.ActiveCfg = Debug|Win32 + {0F554F1D-ED49-4D65-A9A7-F63C57F277BE}.Debug|Win32.Build.0 = Debug|Win32 + {0F554F1D-ED49-4D65-A9A7-F63C57F277BE}.Debug|x64.ActiveCfg = Debug|x64 + {0F554F1D-ED49-4D65-A9A7-F63C57F277BE}.Debug|x64.Build.0 = Debug|x64 + {0F554F1D-ED49-4D65-A9A7-F63C57F277BE}.Release|Win32.ActiveCfg = Release|Win32 + {0F554F1D-ED49-4D65-A9A7-F63C57F277BE}.Release|Win32.Build.0 = Release|Win32 + {0F554F1D-ED49-4D65-A9A7-F63C57F277BE}.Release|x64.ActiveCfg = Release|x64 + {0F554F1D-ED49-4D65-A9A7-F63C57F277BE}.Release|x64.Build.0 = Release|x64 + {72B01ACA-7A1A-4F7B-ACEF-2607299CF052}.Debug|Win32.ActiveCfg = Debug|Win32 + {72B01ACA-7A1A-4F7B-ACEF-2607299CF052}.Debug|Win32.Build.0 = Debug|Win32 + {72B01ACA-7A1A-4F7B-ACEF-2607299CF052}.Debug|x64.ActiveCfg = Debug|x64 + {72B01ACA-7A1A-4F7B-ACEF-2607299CF052}.Debug|x64.Build.0 = Debug|x64 + {72B01ACA-7A1A-4F7B-ACEF-2607299CF052}.Release|Win32.ActiveCfg = Release|Win32 + {72B01ACA-7A1A-4F7B-ACEF-2607299CF052}.Release|Win32.Build.0 = Release|Win32 + {72B01ACA-7A1A-4F7B-ACEF-2607299CF052}.Release|x64.ActiveCfg = Release|x64 + {72B01ACA-7A1A-4F7B-ACEF-2607299CF052}.Release|x64.Build.0 = Release|x64 + {51137D5C-4E81-4955-AACF-EA3092006051}.Debug|Win32.ActiveCfg = Debug|Win32 + {51137D5C-4E81-4955-AACF-EA3092006051}.Debug|Win32.Build.0 = Debug|Win32 + {51137D5C-4E81-4955-AACF-EA3092006051}.Debug|x64.ActiveCfg = Debug|x64 + {51137D5C-4E81-4955-AACF-EA3092006051}.Debug|x64.Build.0 = Debug|x64 + {51137D5C-4E81-4955-AACF-EA3092006051}.Release|Win32.ActiveCfg = Release|Win32 + {51137D5C-4E81-4955-AACF-EA3092006051}.Release|Win32.Build.0 = Release|Win32 + {51137D5C-4E81-4955-AACF-EA3092006051}.Release|x64.ActiveCfg = Release|x64 + {51137D5C-4E81-4955-AACF-EA3092006051}.Release|x64.Build.0 = Release|x64 + {73A5729C-7323-41D4-AB48-8A03C9F81603}.Debug|Win32.ActiveCfg = Debug|Win32 + {73A5729C-7323-41D4-AB48-8A03C9F81603}.Debug|Win32.Build.0 = Debug|Win32 + {73A5729C-7323-41D4-AB48-8A03C9F81603}.Debug|x64.ActiveCfg = Debug|x64 + {73A5729C-7323-41D4-AB48-8A03C9F81603}.Debug|x64.Build.0 = Debug|x64 + {73A5729C-7323-41D4-AB48-8A03C9F81603}.Release|Win32.ActiveCfg = Release|Win32 + {73A5729C-7323-41D4-AB48-8A03C9F81603}.Release|Win32.Build.0 = Release|Win32 + {73A5729C-7323-41D4-AB48-8A03C9F81603}.Release|x64.ActiveCfg = Release|x64 + {73A5729C-7323-41D4-AB48-8A03C9F81603}.Release|x64.Build.0 = Release|x64 + {E662D0B3-412D-4D55-A5EC-8CBD680DDCBE}.Debug|Win32.ActiveCfg = Debug|Win32 + {E662D0B3-412D-4D55-A5EC-8CBD680DDCBE}.Debug|x64.ActiveCfg = Debug|x64 + {E662D0B3-412D-4D55-A5EC-8CBD680DDCBE}.Release|Win32.ActiveCfg = Release|Win32 + {E662D0B3-412D-4D55-A5EC-8CBD680DDCBE}.Release|x64.ActiveCfg = Release|x64 + {61BA7D3C-F77D-4D31-B718-1177FE482CF2}.Debug|Win32.ActiveCfg = Debug|Win32 + {61BA7D3C-F77D-4D31-B718-1177FE482CF2}.Debug|Win32.Build.0 = Debug|Win32 + {61BA7D3C-F77D-4D31-B718-1177FE482CF2}.Debug|x64.ActiveCfg = Debug|x64 + {61BA7D3C-F77D-4D31-B718-1177FE482CF2}.Debug|x64.Build.0 = Debug|x64 + {61BA7D3C-F77D-4D31-B718-1177FE482CF2}.Release|Win32.ActiveCfg = Release|Win32 + {61BA7D3C-F77D-4D31-B718-1177FE482CF2}.Release|Win32.Build.0 = Release|Win32 + {61BA7D3C-F77D-4D31-B718-1177FE482CF2}.Release|x64.ActiveCfg = Release|x64 + {61BA7D3C-F77D-4D31-B718-1177FE482CF2}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/srb2-vc9.sln b/srb2-vc9.sln new file mode 100644 index 000000000..bbfcf0e77 --- /dev/null +++ b/srb2-vc9.sln @@ -0,0 +1,89 @@ + +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual C++ Express 2008 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Srb2win", "src\win32\Srb2win-vc9.vcproj", "{0F554F1D-ED49-4D65-A9A7-F63C57F277BE}" + ProjectSection(ProjectDependencies) = postProject + {73A5729C-7323-41D4-AB48-8A03C9F81603} = {73A5729C-7323-41D4-AB48-8A03C9F81603} + {72B01ACA-7A1A-4F7B-ACEF-2607299CF052} = {72B01ACA-7A1A-4F7B-ACEF-2607299CF052} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libpng", "libs\libpng-src\projects\visualc9\libpng.vcproj", "{72B01ACA-7A1A-4F7B-ACEF-2607299CF052}" + ProjectSection(ProjectDependencies) = postProject + {73A5729C-7323-41D4-AB48-8A03C9F81603} = {73A5729C-7323-41D4-AB48-8A03C9F81603} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "r_opengl", "src\hardware\r_opengl\r_opengl-vc9.vcproj", "{51137D5C-4E81-4955-AACF-EA3092006051}" + ProjectSection(ProjectDependencies) = postProject + {0F554F1D-ED49-4D65-A9A7-F63C57F277BE} = {0F554F1D-ED49-4D65-A9A7-F63C57F277BE} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlib", "libs\zlib\projects\visualc9\zlib.vcproj", "{73A5729C-7323-41D4-AB48-8A03C9F81603}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "s_openal", "src\hardware\s_openal\s_openal-vc9.vcproj", "{E662D0B3-412D-4D55-A5EC-8CBD680DDCBE}" + ProjectSection(ProjectDependencies) = postProject + {0F554F1D-ED49-4D65-A9A7-F63C57F277BE} = {0F554F1D-ED49-4D65-A9A7-F63C57F277BE} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Srb2SDL", "src\sdl\Srb2SDL-vc9.vcproj", "{61BA7D3C-F77D-4D31-B718-1177FE482CF2}" + ProjectSection(ProjectDependencies) = postProject + {73A5729C-7323-41D4-AB48-8A03C9F81603} = {73A5729C-7323-41D4-AB48-8A03C9F81603} + {72B01ACA-7A1A-4F7B-ACEF-2607299CF052} = {72B01ACA-7A1A-4F7B-ACEF-2607299CF052} + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {0F554F1D-ED49-4D65-A9A7-F63C57F277BE}.Debug|Win32.ActiveCfg = Debug|Win32 + {0F554F1D-ED49-4D65-A9A7-F63C57F277BE}.Debug|Win32.Build.0 = Debug|Win32 + {0F554F1D-ED49-4D65-A9A7-F63C57F277BE}.Debug|x64.ActiveCfg = Debug|x64 + {0F554F1D-ED49-4D65-A9A7-F63C57F277BE}.Debug|x64.Build.0 = Debug|x64 + {0F554F1D-ED49-4D65-A9A7-F63C57F277BE}.Release|Win32.ActiveCfg = Release|Win32 + {0F554F1D-ED49-4D65-A9A7-F63C57F277BE}.Release|Win32.Build.0 = Release|Win32 + {0F554F1D-ED49-4D65-A9A7-F63C57F277BE}.Release|x64.ActiveCfg = Release|x64 + {0F554F1D-ED49-4D65-A9A7-F63C57F277BE}.Release|x64.Build.0 = Release|x64 + {72B01ACA-7A1A-4F7B-ACEF-2607299CF052}.Debug|Win32.ActiveCfg = Debug|Win32 + {72B01ACA-7A1A-4F7B-ACEF-2607299CF052}.Debug|Win32.Build.0 = Debug|Win32 + {72B01ACA-7A1A-4F7B-ACEF-2607299CF052}.Debug|x64.ActiveCfg = Debug|x64 + {72B01ACA-7A1A-4F7B-ACEF-2607299CF052}.Debug|x64.Build.0 = Debug|x64 + {72B01ACA-7A1A-4F7B-ACEF-2607299CF052}.Release|Win32.ActiveCfg = Release|Win32 + {72B01ACA-7A1A-4F7B-ACEF-2607299CF052}.Release|Win32.Build.0 = Release|Win32 + {72B01ACA-7A1A-4F7B-ACEF-2607299CF052}.Release|x64.ActiveCfg = Release|x64 + {72B01ACA-7A1A-4F7B-ACEF-2607299CF052}.Release|x64.Build.0 = Release|x64 + {51137D5C-4E81-4955-AACF-EA3092006051}.Debug|Win32.ActiveCfg = Debug|Win32 + {51137D5C-4E81-4955-AACF-EA3092006051}.Debug|Win32.Build.0 = Debug|Win32 + {51137D5C-4E81-4955-AACF-EA3092006051}.Debug|x64.ActiveCfg = Debug|x64 + {51137D5C-4E81-4955-AACF-EA3092006051}.Debug|x64.Build.0 = Debug|x64 + {51137D5C-4E81-4955-AACF-EA3092006051}.Release|Win32.ActiveCfg = Release|Win32 + {51137D5C-4E81-4955-AACF-EA3092006051}.Release|Win32.Build.0 = Release|Win32 + {51137D5C-4E81-4955-AACF-EA3092006051}.Release|x64.ActiveCfg = Release|x64 + {51137D5C-4E81-4955-AACF-EA3092006051}.Release|x64.Build.0 = Release|x64 + {73A5729C-7323-41D4-AB48-8A03C9F81603}.Debug|Win32.ActiveCfg = Debug|Win32 + {73A5729C-7323-41D4-AB48-8A03C9F81603}.Debug|Win32.Build.0 = Debug|Win32 + {73A5729C-7323-41D4-AB48-8A03C9F81603}.Debug|x64.ActiveCfg = Debug|x64 + {73A5729C-7323-41D4-AB48-8A03C9F81603}.Debug|x64.Build.0 = Debug|x64 + {73A5729C-7323-41D4-AB48-8A03C9F81603}.Release|Win32.ActiveCfg = Release|Win32 + {73A5729C-7323-41D4-AB48-8A03C9F81603}.Release|Win32.Build.0 = Release|Win32 + {73A5729C-7323-41D4-AB48-8A03C9F81603}.Release|x64.ActiveCfg = Release|x64 + {73A5729C-7323-41D4-AB48-8A03C9F81603}.Release|x64.Build.0 = Release|x64 + {E662D0B3-412D-4D55-A5EC-8CBD680DDCBE}.Debug|Win32.ActiveCfg = Debug|Win32 + {E662D0B3-412D-4D55-A5EC-8CBD680DDCBE}.Debug|x64.ActiveCfg = Debug|x64 + {E662D0B3-412D-4D55-A5EC-8CBD680DDCBE}.Release|Win32.ActiveCfg = Release|Win32 + {E662D0B3-412D-4D55-A5EC-8CBD680DDCBE}.Release|x64.ActiveCfg = Release|x64 + {61BA7D3C-F77D-4D31-B718-1177FE482CF2}.Debug|Win32.ActiveCfg = Debug|Win32 + {61BA7D3C-F77D-4D31-B718-1177FE482CF2}.Debug|Win32.Build.0 = Debug|Win32 + {61BA7D3C-F77D-4D31-B718-1177FE482CF2}.Debug|x64.ActiveCfg = Debug|x64 + {61BA7D3C-F77D-4D31-B718-1177FE482CF2}.Debug|x64.Build.0 = Debug|x64 + {61BA7D3C-F77D-4D31-B718-1177FE482CF2}.Release|Win32.ActiveCfg = Release|Win32 + {61BA7D3C-F77D-4D31-B718-1177FE482CF2}.Release|Win32.Build.0 = Release|Win32 + {61BA7D3C-F77D-4D31-B718-1177FE482CF2}.Release|x64.ActiveCfg = Release|x64 + {61BA7D3C-F77D-4D31-B718-1177FE482CF2}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/src/.gitignore b/src/.gitignore new file mode 100644 index 000000000..da5a1fff2 --- /dev/null +++ b/src/.gitignore @@ -0,0 +1,2 @@ +/cscope.out +/srb2wii diff --git a/src/Android.mk b/src/Android.mk new file mode 100644 index 000000000..a461da224 --- /dev/null +++ b/src/Android.mk @@ -0,0 +1,90 @@ +LOCAL_PATH := $(call my-dir) + +srb_module_tags := eng user + +include $(CLEAR_VARS) + +LOCAL_SRC_FILES := am_map.c \ + command.c \ + comptime.c \ + console.c \ + d_clisrv.c \ + d_main.c \ + d_net.c \ + d_netcmd.c \ + d_netfil.c \ + dehacked.c \ + f_finale.c \ + f_wipe.c \ + filesrch.c \ + g_game.c \ + g_input.c \ + hu_stuff.c \ + i_tcp.c \ + info.c \ + lzf.c \ + m_argv.c \ + m_bbox.c \ + m_cheat.c \ + m_fixed.c \ + m_menu.c \ + m_misc.c \ + m_queue.c \ + m_random.c \ + md5.c \ + mserv.c \ + p_ceilng.c \ + p_enemy.c \ + p_fab.c \ + p_floor.c \ + p_inter.c \ + p_lights.c \ + p_map.c \ + p_maputl.c \ + p_mobj.c \ + p_polyobj.c \ + p_saveg.c \ + p_setup.c \ + p_sight.c \ + p_spec.c \ + p_telept.c \ + p_tick.c \ + p_user.c \ + r_bsp.c \ + r_data.c \ + r_draw.c \ + r_main.c \ + r_plane.c \ + r_segs.c \ + r_sky.c \ + r_splats.c \ + r_things.c \ + s_sound.c \ + screen.c \ + sounds.c \ + st_stuff.c \ + string.c \ + tables.c \ + v_video.c \ + w_wad.c \ + y_inter.c \ + z_zone.c \ + android/i_cdmus.c \ + android/i_main.c \ + android/i_net.c \ + android/i_sound.c \ + android/i_system.c \ + android/i_video.c + +LOCAL_CFLAGS += -DPLATFORM_ANDROID -DNONX86 -DLINUX -DDEBUGMODE -DNOASM -DNOPIX -DUNIXCOMMON -DNOTERMIOS + +LOCAL_MODULE := libsrb2 + +# we live in an APK, so no prelink for us! +LOCAL_PRELINK_MODULE := false + +LOCAL_SHARED_LIBRARIES += liblog libdl + +LOCAL_CFLAGS += -Idalvik/libnativehelper/include/nativehelper + +include $(BUILD_SHARED_LIBRARY) diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 000000000..a5d5dc191 --- /dev/null +++ b/src/Makefile @@ -0,0 +1,922 @@ +# GNU Make makefile for SRB2 +############################################################################# +# Copyright (C) 1998-2000 by DooM Legacy Team. +# Copyright (C) 2003-2014 by Sonic Team Junior. +# +# This program is free software distributed under the +# terms of the GNU General Public License, version 2. +# See the 'LICENSE' file for more details. +# +# -DPC_DOS -> use DOS specific code (eg:textmode stuff)... +# -DLINUX -> use for the GNU/Linux specific +# -D_WINDOWS -> use for the Win32/DirectX specific +# -DSDL -> use for the SDL interface +# +# Sets: +# Compile the DGJPP/DOS version with 'make WATTCP=1' +# Compile the DirectX/Mingw version with 'make MINGW=1' +# Compile the SDL/Mingw version with 'make MINGW=1 SDL=1' +# Compile the SDL/Linux version with 'make LINUX=1' +# Compile the SDL/Solaris version with 'make SOLARIS=1' +# Compile the SDL/FreeBSD version with 'gmake FREEBSD=1' +# Compile the SDL/Cygwin version with 'make CYGWIN32=1' +# Compile the SDL/other version try with 'make SDL=1' +# +# 'Targets': +# clean +# Remove all object files +# cleandep +# Remove depend.dep +# dll +# compile primary HW render DLL/SO +# all_dll +# compile all HW render and 3D sound DLLs for the set +# opengl_dll +# Pure Mingw only, compile OpenGL HW render DLL +# minigl_dll +# Pure Mingw only, compile MiniGL HW render DLL +# ds3d_dll +# Pure Mingw only, compile DirectX DirectSound HW sound DLL +# fmod_dll +# Pure Mingw only, compile FMOD HW sound DLL +# openal_dll +# Pure Mingw only, compile OpenAL HW sound DLL +# fmod_so +# Non-Mingw, compile FMOD HW sound SO +# openal_so +# Non-Mingw, compile OpenAL HW sound SO +# +# +# Addon: +# To Cross-Compile, CC=gcc-version make * PREFIX= +# Compile with GCC 2.97 version, add 'GCC29=1' +# Compile with GCC 4.0x version, add 'GCC40=1' +# Compile with GCC 4.1x version, add 'GCC41=1' +# Compile with GCC 4.2x version, add 'GCC42=1' +# Compile with GCC 4.3x version, add 'GCC43=1' +# Compile with GCC 4.4x version, add 'GCC44=1' +# Compile with GCC 4.5x version, add 'GCC45=1' +# Compile with GCC 4.6x version, add 'GCC46=1' +# Compile a profile version, add 'PROFILEMODE=1' +# Compile a debug version, add 'DEBUGMODE=1' +# Compile with extra warnings, add 'WARNINGMODE=1' +# Compile without NASM's tmap.nas, add 'NOASM=1' +# Compile without 3D hardware support, add 'NOHW=1' +# Compile without 3D sound support, add 'NOHS=1' +# Compile with GDBstubs, add 'RDB=1' +# Compile without PNG, add 'NOPNG=1' +# +# Addon for SDL: +# To Cross-Compile, add 'SDL_CONFIG=/usr/*/bin/sdl-config' +# Compile without SDL_Mixer, add 'NOMIXER=1' +# Compile without BSD API, add 'NONET=1' +# Compile without IPX/SPX, add 'NOIPX=1' +# Compile Mingw/SDL with S_DS3S, add 'DS3D=1' +# Compile with S_FMOD3D, add 'FMOD=1' (WIP) +# Compile with S_OPENAL, add 'OPENAL=1' (WIP) +# To link with the whole SDL_Image lib to load Icons, add 'SDL_IMAGE=1' but it isn't not realy needed +# To link with SDLMain to hide console or make on a console-less binary, add 'SDLMAIN=1' +# +############################################################################# + +# SRB2 data files +D_DIR?=../bin/Resources +D_FILES=$(D_DIR)/srb2.srb \ + $(D_DIR)/player.dta \ + $(D_DIR)/rings.wpn \ + $(D_DIR)/drill.dta \ + $(D_DIR)/soar.dta \ + $(D_DIR)/zones.dta \ + $(D_DIR)/music.dta \ + +PKG_CONFIG?=pkg-config + +ifdef WIILINUX +LINUX=1 +endif + +ifdef PANDORA +LINUX=1 +endif + +ifdef LINUX64 +LINUX=1 +NONX86=1 +endif + +ifdef HAIKU +SDL=1 +endif + +ifdef NDS +# Include this before the main Makefile.cfg +EXENAME?=srb2.elf +include nds/Makefile.cfg +endif + +include Makefile.cfg + +ifdef DUMMY +NOPNG=1 +NONET=1 +NOHW=1 +NOHS=1 +NOASM=1 +NOIPX=1 +EXENAME?=srb2dummy +OBJS=$(OBJDIR)/i_video.o +LIBS=-lm +endif + +ifdef HAIKU +NOIPX=1 +NOASM=1 +ifndef NONET +LIBS=-lnetwork +endif +CFLAGS+=-DUNIXCOMMON +PNG_CFLAGS?= +PNG_LDFLAGS?=-lpng +endif + +ifdef WIILINUX +NONX86=1 +NOTERMIOS=1 +NOHW=1 +CFLAGS+=-DWMINPUT +NOTERMIOS=1 +NOPOSTPROCESSING=1 +endif + +ifdef PANDORA +NONX86=1 +NOHW=1 +NOHS=1 +endif + +ifdef WII +NONX86=1 +NOHW=1 +NOPOSTPROCESSING=1 +endif + +ifdef PS3N +NONX86=1 +NOHW=1 +endif + +ifdef DJGPPDOS +include djgppdos/Makefile.cfg +endif + +ifdef MINGW +include win32/Makefile.cfg +endif #ifdef MINGW + +ifdef UNIX +UNIXCOMMON=1 +endif + +ifdef LINUX +UNIXCOMMON=1 +endif + +ifdef SOLARIS +UNIXCOMMON=1 +endif + +ifdef FREEBSD +UNIXCOMMON=1 +endif + +ifdef NDS +NOPNG=1 +NONET=1 +#NOHW=1 +NOHS=1 +NOASM=1 +NOIPX=1 +NONX86=1 +OBJS+=$(OBJDIR)/i_video.o +LIBS+=-lm +endif + +ifdef SDL +include sdl/Makefile.cfg +endif #ifdef SDL + +ifdef DISTCC + CC:=distcc $(CC) +endif + +ifdef CCACHE + CC:=ccache $(CC) +endif + +MSGFMT?=msgfmt + +ifndef ECHO + NASM:=@$(NASM) + REMOVE:=@$(REMOVE) + CC:=@$(CC) + CXX:=@$(CXX) + OBJCOPY:=@$(OBJCOPY) + OBJDUMP:=@$(OBJDUMP) + STRIP:=@$(STRIP) + WINDRES:=@$(WINDRES) + CP:=@$(CP) + MKDIR:=@$(MKDIR) + MKISOFS:=@$(MKISOFS) + DD:=@$(DD) + NDSTOOL:=@$(NDSTOOL) + GZIP:=@$(GZIP) + MSGFMT:=@$(MSGFMT) + UPX:=@$(UPX) + UPX_OPTS+=-q +endif + +ifdef NONET + OPTS+=-DNONET +else +ifdef NO_IPV6 + OPTS+=-DNO_IPV6 +endif +endif + +ifdef NOHW + OPTS+=-DNOHW +else +ifndef DC + #Hurdler: not really supported and not tested recently + #OPTS+=-DUSE_PALETTED_TEXTURE +endif + OPTS+=-DHWRENDER + OBJS+=$(OBJDIR)/hw_bsp.o $(OBJDIR)/hw_draw.o $(OBJDIR)/hw_light.o \ + $(OBJDIR)/hw_main.o $(OBJDIR)/hw_md2.o $(OBJDIR)/hw_cache.o $(OBJDIR)/hw_trick.o +endif + +ifdef NOHS + OPTS+=-DNOHS +else + OPTS+=-DHW3SOUND + OBJS+=$(OBJDIR)/hw3sound.o +endif + +ifndef NOVERSION +OPTS += -DCOMPVERSION +endif + +ifndef NONX86 +ifndef GCC29 + M5=-march=pentium + M4=-march=i486 +else + M5=-mpentium + M4=-m486 +endif +endif + +ifndef NOASM +ifndef NONX86 + OBJS+=$(OBJDIR)/tmap.o $(OBJDIR)/tmap_mmx.o + OPTS+=-DUSEASM +endif +endif + +ifndef NOPNG +OPTS+=-DHAVE_PNG + +ifdef PNG_PKGCONFIG +PNG_CFLAGS?=$(shell $(PKG_CONFIG) $(PNG_PKGCONFIG) --cflags) +PNG_LDFLAGS?=$(shell $(PKG_CONFIG) $(PNG_PKGCONFIG) --libs) +else +ifdef PREFIX +PNG_CONFIG?=$(PREFIX)-libpng-config +else +PNG_CONFIG?=libpng-config +endif + +ifdef PNG_STATIC +PNG_CFLAGS?=$(shell $(PNG_CONFIG) --static --cflags) +PNG_LDFLAGS?=$(shell $(PNG_CONFIG) --static --ldflags) +else +PNG_CFLAGS?=$(shell $(PNG_CONFIG) --cflags) +PNG_LDFLAGS?=$(shell $(PNG_CONFIG) --ldflags) +endif +endif + +LIBS+=$(PNG_LDFLAGS) +CFLAGS+=$(PNG_CFLAGS) +endif + +ifdef HAVE_LIBGME +OPTS+=-DHAVE_LIBGME + +LIBGME_PKGCONFIG?=libgme +LIBGME_CFLAGS?=$(shell $(PKG_CONFIG) $(LIBGME_PKGCONFIG) --cflags) +LIBGME_LDFLAGS?=$(shell $(PKG_CONFIG) $(LIBGME_PKGCONFIG) --libs) + +LIBS+=$(LIBGME_LDFLAGS) +CFLAGS+=$(LIBGME_CFLAGS) +endif + +ifdef STATIC +LIBS:=-static $(LIBS) +endif + +ifdef HAVE_MINIUPNPC +ifdef NONET +HAVE_MINIUPNPC='' +else +LIBS+=-lminiupnpc +ifdef MINGW +LIBS+=-lws2_32 -liphlpapi +endif +CFLAGS+=-DHAVE_MINIUPNPC +endif +endif + +ifndef NO_LUA + include blua/Makefile.cfg +endif + +ifdef NOMD5 + OPTS+=-DNOMD5 +else + OBJS:=$(OBJDIR)/md5.o $(OBJS) +endif + +ifdef FAKEDC + OPTS+=-DDC +endif + +ifdef FAKEPSP + OPTS+=-DPSP +endif + +ifdef NOPOSTPROCESSING + OPTS+=-DNOPOSTPROCESSING +endif + + OPTS:=-fno-exceptions $(OPTS) + +ifdef DEBUGMODE + + # build with debugging information + WINDRESFLAGS = -D_DEBUG + CFLAGS+=-O0 -Wall -DPARANOIA -DRANGECHECK +else + + + # build a normal optimised version + WINDRESFLAGS = -DNDEBUG + CFLAGS+=-O2 +endif + CFLAGS+=-g $(OPTS) $(M5) $(WINDRESFLAGS) + +ifdef YASM +ifdef STABS + NASMOPTS?= -g stabs +else + NASMOPTS?= -g dwarf2 +endif +else + NASMOPTS?= -g +endif + +ifdef PROFILEMODE + # build with profiling information + CFLAGS:=-pg $(CFLAGS) +endif + +ifdef ZDEBUG + CPPFLAGS+=-DZDEBUG +endif + +OPTS+=$(CPPFLAGS) + +# default EXENAME if all else fails +EXENAME?=srb2 +DBGNAME?=$(EXENAME).debug + +# $(OBJDIR)/dstrings.o \ + +# not too sophisticated dependency +OBJS:=$(i_main_o) \ + $(OBJDIR)/comptime.o \ + $(OBJDIR)/string.o \ + $(OBJDIR)/d_main.o \ + $(OBJDIR)/d_clisrv.o \ + $(OBJDIR)/d_net.o \ + $(OBJDIR)/d_netfil.o \ + $(OBJDIR)/d_netcmd.o \ + $(OBJDIR)/dehacked.o \ + $(OBJDIR)/z_zone.o \ + $(OBJDIR)/f_finale.o \ + $(OBJDIR)/f_wipe.o \ + $(OBJDIR)/g_game.o \ + $(OBJDIR)/g_input.o \ + $(OBJDIR)/am_map.o \ + $(OBJDIR)/command.o \ + $(OBJDIR)/console.o \ + $(OBJDIR)/hu_stuff.o \ + $(OBJDIR)/y_inter.o \ + $(OBJDIR)/st_stuff.o \ + $(OBJDIR)/m_anigif.o \ + $(OBJDIR)/m_argv.o \ + $(OBJDIR)/m_bbox.o \ + $(OBJDIR)/m_cheat.o \ + $(OBJDIR)/m_cond.o \ + $(OBJDIR)/m_fixed.o \ + $(OBJDIR)/m_menu.o \ + $(OBJDIR)/m_misc.o \ + $(OBJDIR)/m_random.o \ + $(OBJDIR)/m_queue.o \ + $(OBJDIR)/info.o \ + $(OBJDIR)/p_ceilng.o \ + $(OBJDIR)/p_enemy.o \ + $(OBJDIR)/p_fab.o \ + $(OBJDIR)/p_floor.o \ + $(OBJDIR)/p_inter.o \ + $(OBJDIR)/p_lights.o \ + $(OBJDIR)/p_map.o \ + $(OBJDIR)/p_maputl.o \ + $(OBJDIR)/p_mobj.o \ + $(OBJDIR)/p_polyobj.o\ + $(OBJDIR)/p_saveg.o \ + $(OBJDIR)/p_setup.o \ + $(OBJDIR)/p_sight.o \ + $(OBJDIR)/p_spec.o \ + $(OBJDIR)/p_telept.o \ + $(OBJDIR)/p_tick.o \ + $(OBJDIR)/p_user.o \ + $(OBJDIR)/tables.o \ + $(OBJDIR)/r_bsp.o \ + $(OBJDIR)/r_data.o \ + $(OBJDIR)/r_draw.o \ + $(OBJDIR)/r_main.o \ + $(OBJDIR)/r_plane.o \ + $(OBJDIR)/r_segs.o \ + $(OBJDIR)/r_sky.o \ + $(OBJDIR)/r_splats.o \ + $(OBJDIR)/r_things.o \ + $(OBJDIR)/screen.o \ + $(OBJDIR)/v_video.o \ + $(OBJDIR)/s_sound.o \ + $(OBJDIR)/sounds.o \ + $(OBJDIR)/w_wad.o \ + $(OBJDIR)/filesrch.o \ + $(OBJDIR)/mserv.o \ + $(OBJDIR)/i_tcp.o \ + $(OBJDIR)/lzf.o \ + $(OBJDIR)/vid_copy.o \ + $(OBJDIR)/b_bot.o \ + $(i_cdmus_o) \ + $(i_net_o) \ + $(i_system_o) \ + $(i_sound_o) \ + $(OBJS) + +# List of languages to compile. +# For reference, this is the command I use to build a srb2.pot file from the source code. +# (The listed source files are the ones containing translated strings). +# FILES=""; for file in `find ./ | grep "\.c" | grep -v svn`; do [ "`grep "M_GetText(" $file`" ] && FILES="$FILES $file"; done; xgettext -d srb2 -o locale/srb2.pot -kM_GetText -F --no-wrap $FILES +ifndef NOGETTEXT +ifdef GETTEXT +POS:=$(BIN)/en.mo + +OPTS+=-DGETTEXT +endif +endif + +ifdef DJGPPDOS +all: pre-build $(BIN)/$(EXENAME) +endif + +ifdef XBOX +all: pre-build $(BIN)/$(BINNAME) +endif + +ifdef PS3N +all: pre-build $(BIN)/$(PKGNAME) +endif + +ifdef WII +all: pre-build $(BIN)/$(DOLNAME) +endif + +ifdef PANDORA +all: pre-build $(BIN)/$(PNDNAME) +endif + +ifdef PSP +all: pre-build $(BIN)/$(BINNAME) post-build +endif + +ifdef DC +all: pre-build $(BIN)/$(BINNAME) post-build +endif + +ifndef DC +ifndef PSP +ifndef XBOX +ifdef MINGW +ifndef SDL +all: pre-build $(BIN)/$(EXENAME) dll +endif +endif +endif +endif + +ifdef SDL +all: pre-build $(BIN)/$(EXENAME) +endif +endif + +ifdef NDS +all: $(BIN)/$(EXENAME:.elf=.nds) +endif + +ifdef DUMMY +all: $(BIN)/$(EXENAME) +endif + +cleandep: + $(REMOVE) $(OBJDIR)/depend.dep + $(REMOVE) comptime.h + +pre-build: +ifdef NOVERSION + -@touch comptime.c +else +ifdef WINDOWSHELL + -..\comptime.bat . +else + -@../comptime.sh . +endif +endif + +clean: + $(REMOVE) *~ *.flc + $(REMOVE) $(OBJDIR)/*.o + +ifdef MINGW + $(REMOVE) $(OBJDIR)/*.res +endif + +ifdef CYGWIN32 + $(REMOVE) $(OBJDIR)/*.res +endif + +#make a big srb2.s that is the disasm of the exe (dos only ?) +asm: + $(CC) $(LDFLAGS) $(OBJS) -o $(OBJDIR)/tmp.exe $(LIBS) + $(OBJDUMP) -d $(OBJDIR)/tmp.exe --no-show-raw-insn > srb2.s + $(REMOVE) $(OBJDIR)/tmp.exe + +# executable +# NOTE: DJGPP's objcopy do not have --add-gnu-debuglink + +$(BIN)/$(EXENAME): $(POS) $(OBJS) + -$(MKDIR) $(BIN) + @echo Linking $(EXENAME)... + $(LD) $(LDFLAGS) $(OBJS) -o $(BIN)/$(EXENAME) $(LIBS) +ifndef VALGRIND +ifndef NOOBJDUMP + @echo Dumping debugging info + $(OBJDUMP) $(OBJDUMP_OPTS) $(BIN)/$(EXENAME) > $(BIN)/$(DBGNAME).txt + -$(GZIP) $(GZIP_OPTS) $(BIN)/$(DBGNAME).txt +ifndef WINDOWSHELL + -$(GZIP) $(GZIP_OPT2) $(BIN)/$(DBGNAME).txt +endif +endif +ifndef PSP + $(OBJCOPY) $(BIN)/$(EXENAME) $(BIN)/$(DBGNAME) + $(OBJCOPY) --strip-debug $(BIN)/$(EXENAME) + -$(OBJCOPY) --add-gnu-debuglink=$(BIN)/$(DBGNAME) $(BIN)/$(EXENAME) +endif +ifndef NOUPX + -$(UPX) $(UPX_OPTS) $(BIN)/$(EXENAME) +endif +endif + +reobjdump: + @echo Redumping debugging info + $(OBJDUMP) $(OBJDUMP_OPTS) $(BIN)/$(DBGNAME) > $(BIN)/$(DBGNAME).txt + -$(GZIP) $(GZIP_OPTS) $(BIN)/$(DBGNAME).txt +ifndef WINDOWSHELL + -$(GZIP) $(GZIP_OPT2) $(BIN)/$(DBGNAME).txt +endif + +$(OBJDIR): + -$(MKDIR) $(OBJDIR) + +ifndef SDL +ifdef NOHW +dll : +else +dll : opengl_dll +endif +ifdef MINGW +all_dll: opengl_dll minigl_dll ds3d_dll fmod_dll openal_dll + +opengl_dll: $(BIN)/r_opengl.dll +$(BIN)/r_opengl.dll: $(OBJDIR)/ogl_win.o $(OBJDIR)/r_opengl.o + -$(MKDIR) $(BIN) + @echo Linking R_OpenGL.dll... + $(CC) --shared $^ -o $@ -g -Wl,--add-stdcall-alias -lgdi32 + +minigl_dll: $(BIN)/r_minigl.dll +$(BIN)/r_minigl.dll: $(OBJDIR)/r_minigl.o + -$(MKDIR) $(BIN) + @echo Linking R_MiniGL.dll... + $(CC) --shared $^ -o $@ -g -Wl,--add-stdcall-alias -lgdi32 + +ds3d_dll: $(BIN)/s_ds3d.dll +$(BIN)/s_ds3d.dll: $(OBJDIR)/s_ds3d.o + @echo Linking S_DS3d.dll... + $(CC) --shared $^ -o $@ -g -Wl,--add-stdcall-alias -ldsound -luuid + +fmod_dll: $(BIN)/s_fmod.dll +$(BIN)/s_fmod.dll: $(OBJDIR)/s_fmod.o + -$(MKDIR) $(BIN) + @echo Linking S_FMOD.dll... + $(CC) --shared $^ -o $@ -g -Wl,--add-stdcall-alias -lfmod + +openal_dll: $(BIN)/s_openal.dll +$(BIN)/s_openal.dll: $(OBJDIR)/s_openal.o + -$(MKDIR) $(BIN) + @echo Linking S_OpenAL.dll... + $(CC) --shared $^ -o $@ -g -Wl,--add-stdcall-alias -lopenal32 +else +all_dll: fmod_so openal_so + +fmod_so: $(BIN)/s_fmod.so +$(BIN)/s_fmod.so: $(OBJDIR)/s_fmod.o + -$(MKDIR) $(BIN) + @echo Linking S_FMOD.so... + $(CC) --shared $^ -o $@ -g --nostartfiles -lm -lfmod + +openal_so: $(BIN)/s_openal.so +$(BIN)/s_openal.so: $(OBJDIR)/s_openal.o + -$(MKDIR) $(BIN) + @echo Linking S_OpenAL.so... + $(CC) --shared $^ -o $@ -g --nostartfiles -lm -lopenal + +endif + +else +ifdef SDL +ifdef MINGW +$(OBJDIR)/r_opengl.o: hardware/r_opengl/r_opengl.c hardware/r_opengl/r_opengl.h \ + doomdef.h doomtype.h g_state.h m_swap.h hardware/hw_drv.h screen.h \ + command.h hardware/hw_data.h hardware/hw_glide.h hardware/hw_defs.h \ + hardware/hw_md2.h hardware/hw_glob.h hardware/hw_main.h am_map.h \ + d_event.h d_player.h p_pspr.h m_fixed.h tables.h info.h d_think.h \ + p_mobj.h doomdata.h d_ticcmd.h r_defs.h hardware/hw_dll.h + $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@ +else +$(OBJDIR)/r_opengl.o: hardware/r_opengl/r_opengl.c hardware/r_opengl/r_opengl.h \ + doomdef.h doomtype.h g_state.h m_swap.h hardware/hw_drv.h screen.h \ + command.h hardware/hw_data.h hardware/hw_glide.h hardware/hw_defs.h \ + hardware/hw_md2.h hardware/hw_glob.h hardware/hw_main.h am_map.h \ + d_event.h d_player.h p_pspr.h m_fixed.h tables.h info.h d_think.h \ + p_mobj.h doomdata.h d_ticcmd.h r_defs.h hardware/hw_dll.h + $(CC) $(CFLAGS) $(WFLAGS) -I/usr/X11R6/include -c $< -o $@ +endif +endif + +endif + +#dependecy made by gcc itself ! +$(OBJS): +ifndef DUMMY +-include $(OBJDIR)/depend.dep +endif + +$(OBJDIR)/depend.dep: + @echo "Creating dependency file, depend.dep" + @echo > comptime.h + -$(MKDIR) $(OBJDIR) + $(CC) $(CFLAGS) -MM *.c > $(OBJDIR)/depend.ped + $(CC) $(CFLAGS) -MM $(INTERFACE)/*.c >> $(OBJDIR)/depend.ped +ifndef NOHW + $(CC) $(CFLAGS) -MM hardware/*.c >> $(OBJDIR)/depend.ped +endif +ifndef NO_LUA + $(CC) $(CFLAGS) -MM blua/*.c >> $(OBJDIR)/depend.ped +endif + @sed -e 's,\(.*\)\.o: ,$(subst /,\/,$(OBJDIR))\/&,g' < $(OBJDIR)/depend.ped > $(OBJDIR)/depend.dep + $(REMOVE) $(OBJDIR)/depend.ped + @echo "Created dependency file, depend.dep" + +ifdef DC +$(OBJDIR)/v_video.o: v_video.c doomdef.h doomtype.h g_state.h m_swap.h r_local.h \ + tables.h m_fixed.h screen.h command.h m_bbox.h r_main.h d_player.h \ + p_pspr.h info.h d_think.h sounds.h p_mobj.h doomdata.h d_ticcmd.h \ + r_data.h r_defs.h r_state.h r_bsp.h r_segs.h r_plane.h r_sky.h \ + r_things.h r_draw.h v_video.h hu_stuff.h d_event.h w_wad.h console.h \ + i_video.h z_zone.h doomstat.h d_clisrv.h d_netcmd.h + $(CC) $(CFLAGS) -fno-omit-frame-pointer $(WFLAGS) -c $< -o $@ +endif + +ifdef VALGRIND +$(OBJDIR)/z_zone.o: z_zone.c + $(CC) $(CFLAGS) $(WFLAGS) -DHAVE_VALGRIND $(VALGRIND_CFLAGS) -c $< -o $@ +endif + +$(OBJDIR)/comptime.o: comptime.c pre-build + $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@ + +$(BIN)/%.mo: locale/%.po + -$(MKDIR) $(BIN) + $(MSGFMT) -f -o $@ $< + +$(OBJDIR)/%.o: %.c + $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@ + +$(OBJDIR)/%.o: $(INTERFACE)/%.c + $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@ + +$(OBJDIR)/%.o: hardware/%.c + $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@ + +$(OBJDIR)/%.o: blua/%.c + $(CC) $(CFLAGS) $(LUA_CFLAGS) $(WFLAGS) -c $< -o $@ + +$(OBJDIR)/%.o: %.nas + $(NASM) $(NASMOPTS) -o $@ -f $(NASMFORMAT) $< + +$(OBJDIR)/vid_copy.o: vid_copy.s asm_defs.inc + $(CC) $(OPTS) $(ASFLAGS) -x assembler-with-cpp -c $< -o $@ + +$(OBJDIR)/%.o: %.s + $(CC) $(OPTS) -x assembler-with-cpp -c $< -o $@ + +$(OBJDIR)/SRB2.res: win32/Srb2win.rc win32/afxres.h win32/resource.h + $(WINDRES) -i $< -O rc $(WINDRESFLAGS) --include-dir=win32 -o $@ -O coff + +ifdef DC +$(OBJDIR)/romdisk.img: + $(KOS_GENROMFS) -f romdisk.img -d ../data -v + +$(OBJDIR)/romdisk.o: romdisk.img + $(KOS_BASE)/utils/bin2o/bin2o romdisk.img romdisk romdisk.o + +$(OBJDIR)/dchelp.o: $(INTERFACE)/SRB2DC/dchelp.c + $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@ + +$(OBJDIR)/i_udp.o: $(INTERFACE)/SRB2DC/i_udp.c + $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@ + +$(BIN)/IP.BIN: $(INTERFACE)/SRB2DC/IP.BIN + $(CP) $< $@ + +$(BIN)/SRB2DC.cdi.pass1: $(INTERFACE)/SRB2DC/SELFBOOT.BIN + $(CP) $< $@ + +$(BIN)/$(BINNAME): $(BIN)/$(EXENAME) + $(KOS_OBJCOPY) -R .stack -O binary $< $@ + +$(BIN)/1ST_READ.BIN: $(BIN)/$(BINNAME) $(BIN)/scramble + $(BIN)/scramble $< $@ + +$(BIN)/scramble: $(INTERFACE)/SRB2DC/scramble.c + -$(MKDIR) $(BIN) + $(HOSTCC) $< -o $@ + +iso: $(BIN)/SRB2DC.iso +cdi: $(BIN)/SRB2DC.cdi + +$(BIN)/SRB2DC.iso.pass1: $(BIN)/1ST_READ.BIN $(BIN)/IP.BIN + -$(MKDIR) $(BIN)/cdrom + $(CP) $(BIN)/1ST_READ.BIN $(D_FILES) $(BIN)/cdrom + $(MKISOFS) -l -r -o $@ $(BIN)/cdrom + +$(BIN)/SRB2DC.iso.pass2: $(BIN)/SRB2DC.iso.pass1 + $(DD) if=$< of=$@ bs=2048 skip=16 status=noxfer + +$(BIN)/SRB2DC.iso: $(BIN)/SRB2DC.iso.pass2 $(BIN)/IP.BIN + @cat $(BIN)/IP.BIN $(BIN)/SRB2DC.iso.pass2 > $@ + +$(BIN)/SRB2DC.cdi: $(BIN)/SRB2DC.iso.pass2 $(BIN)/SRB2DC.cdi.pass1 $(BIN)/IP.BIN + @cat $(BIN)/SRB2DC.cdi.pass1 $(BIN)/IP.BIN $(BIN)/SRB2DC.iso.pass2 > $@ + +post-build: $(BIN)/1ST_READ.BIN +endif + +ifdef XBOX +$(OBJDIR)/xboxhelp.o: $(INTERFACE)/SRB2XBOX/xboxhelp.c + $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@ + +$(BIN)/$(BINNAME): $(BIN)/$(EXENAME) + $(CXBE) -OUT:"$@" -DUMPINFO:"$(BIN)/SRB2XBOX.cxbe" -TITLE:"Sonic Robo Blast 2" $< +endif + +ifdef NDS +$(BIN)/$(EXENAME:.elf=.nds): $(BIN)/$(EXENAME:.elf=.arm9) + $(NDSTOOL) -c $@ -9 $(BIN)/$(EXENAME:.elf=.arm9) + +%.arm9: %.elf + $(OBJCOPY) -O binary $< $@ +endif + +ifdef MINGW +ifndef SDL +ifndef NOHW +$(OBJDIR)/r_opengl.o: hardware/r_opengl/r_opengl.c hardware/r_opengl/r_opengl.h \ + doomdef.h doomtype.h g_state.h m_swap.h hardware/hw_drv.h screen.h \ + command.h hardware/hw_data.h hardware/hw_glide.h hardware/hw_defs.h \ + hardware/hw_md2.h hardware/hw_glob.h hardware/hw_main.h am_map.h \ + d_event.h d_player.h p_pspr.h m_fixed.h tables.h info.h d_think.h \ + p_mobj.h doomdata.h d_ticcmd.h r_defs.h hardware/hw_dll.h + $(CC) $(CFLAGS) $(WFLAGS) -D_WINDOWS -mwindows -c $< -o $@ + +$(OBJDIR)/ogl_win.o: hardware/r_opengl/ogl_win.c hardware/r_opengl/r_opengl.h \ + doomdef.h doomtype.h g_state.h m_swap.h hardware/hw_drv.h screen.h \ + command.h hardware/hw_data.h hardware/hw_glide.h hardware/hw_defs.h \ + hardware/hw_md2.h hardware/hw_glob.h hardware/hw_main.h am_map.h \ + d_event.h d_player.h p_pspr.h m_fixed.h tables.h info.h d_think.h \ + p_mobj.h doomdata.h d_ticcmd.h r_defs.h hardware/hw_dll.h + $(CC) $(CFLAGS) $(WFLAGS) -D_WINDOWS -mwindows -c $< -o $@ + +$(OBJDIR)/r_minigl.o: hardware/r_minigl/r_minigl.c hardware/r_opengl/r_opengl.h \ + doomdef.h doomtype.h g_state.h m_swap.h hardware/hw_drv.h screen.h \ + command.h hardware/hw_data.h hardware/hw_glide.h hardware/hw_defs.h \ + hardware/hw_md2.h hardware/hw_glob.h hardware/hw_main.h am_map.h \ + d_event.h d_player.h p_pspr.h m_fixed.h tables.h info.h d_think.h \ + p_mobj.h doomdata.h d_ticcmd.h r_defs.h hardware/hw_dll.h + $(CC) $(CFLAGS) $(WFLAGS) -D_WINDOWS -mwindows -c $< -o $@ +endif + +ifndef NOHS +$(OBJDIR)/s_ds3d.o: hardware/s_ds3d/s_ds3d.c hardware/hw3dsdrv.h \ + hardware/hw_dll.h + $(CC) $(M5) -Os -o $(OBJDIR)/s_ds3d.o $(WFLAGS) -D_WINDOWS -mwindows -c hardware/s_ds3d/s_ds3d.c + +$(OBJDIR)/s_fmod.o: hardware/s_openal/s_openal.c hardware/hw3dsdrv.h \ + hardware/hw_dll.h + $(CC) $(M5) -Os -o $(OBJDIR)/s_fmod.o $(WFLAGS) -D_WINDOWS -mwindows -c hardware/s_fmod/s_fmod.c + +$(OBJDIR)/s_openal.o: hardware/s_openal/s_openal.c hardware/hw3dsdrv.h \ + hardware/hw_dll.h + $(CC) $(M5) -Os -o $(OBJDIR)/s_openal.o $(WFLAGS) -D_WINDOWS -mwindows -c hardware/s_openal/s_openal.c +endif +endif +endif + +ifdef SDL + +ifdef MINGW +$(OBJDIR)/win_dbg.o: win32/win_dbg.c + $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@ +endif + +ifdef STATICHS +$(OBJDIR)/s_openal.o: hardware/s_openal/s_openal.c hardware/hw3dsdrv.h \ + hardware/hw_dll.h + $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@ + +$(OBJDIR)/s_fmod.o: hardware/s_fmod/s_fmod.c hardware/hw3dsdrv.h \ + hardware/hw_dll.h + $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@ + +ifdef MINGW +$(OBJDIR)/s_ds3d.o: hardware/s_ds3d/s_ds3d.c hardware/hw3dsdrv.h \ + hardware/hw_dll.h + $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@ +endif +else + +$(OBJDIR)/s_fmod.o: hardware/s_fmod/s_fmod.c hardware/hw3dsdrv.h \ + hardware/hw_dll.h + $(CC) $(M5) -Os -o $(OBJDIR)/s_fmod.o -DHW3SOUND -DUNIXCOMMON -shared -nostartfiles -c hardware/s_fmod/s_fmod.c + +$(OBJDIR)/s_openal.o: hardware/s_openal/s_openal.c hardware/hw3dsdrv.h \ + hardware/hw_dll.h + $(CC) $(M5) -Os -o $(OBJDIR)/s_openal.o -DHW3SOUND -DUNIXCOMMON -shared -nostartfiles -c hardware/s_openal/s_openal.c +endif + +ifdef FILTERS +$(OBJDIR)/%.o: $(INTERFACE)/filter/%.c + @echo $< needs deps + $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@ + +$(OBJDIR)/filters.o: $(INTERFACE)/filter/filters.c $(INTERFACE)/filter/filters.c \ + $(INTERFACE)/filter/filters.h + $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@ + +$(OBJDIR)/hq2x.o: $(INTERFACE)/filter/hq2x.c $(INTERFACE)/filter/hq2x.c \ + $(INTERFACE)/filter/filters.h + $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@ + +$(OBJDIR)/lq2x.o: $(INTERFACE)/filter/lq2x.c $(INTERFACE)/filter/lq2x.c \ + $(INTERFACE)/filter/filters.h $(INTERFACE)/filter/interp.h \ + $(INTERFACE)/filter/hq2x.h $(INTERFACE)/filter/lq2x.h + $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@ +endif +endif + +############################################################# +# +############################################################# diff --git a/src/Makefile.cfg b/src/Makefile.cfg new file mode 100644 index 000000000..ccf84165f --- /dev/null +++ b/src/Makefile.cfg @@ -0,0 +1,402 @@ +# +# Makefile.cfg for SRB2 +# + +# +# GNU compiler & tools' flags +# and other things +# + +ifdef GCC48 +GCC47=1 +endif + +ifdef GCC47 +GCC46=1 +endif + +ifdef GCC46 +GCC45=1 +endif + +ifdef GCC45 +GCC44=1 +endif + +ifdef GCC44 +GCC43=1 +endif + +ifdef GCC43 +GCC42=1 +endif + +ifdef GCC42 +GCC41=1 +endif + +ifdef GCC41 +GCC40=1 +VCHELP=1 +endif + +ifdef GCC295 +GCC29=1 +endif + +ifdef DC +NOCASTALIGNWARN=1 +endif + +OLDWFLAGS:=$(WFLAGS) +# -W -Wno-unused +WFLAGS=-Wall +ifndef GCC295 +#WFLAGS+=-Wno-packed +endif +ifdef ERRORMODE +WARNINGMODE=1 +endif +ifdef WARNINGMODE + WFLAGS+=-W +#WFLAGS+=-Wno-sign-compare +ifndef GCC295 + WFLAGS+=-Wno-div-by-zero +endif +#WFLAGS+=-Wsystem-headers +ifndef ERRORMODE +#WFLAGS+=-Wfloat-equal +endif +#WFLAGS+=-Wtraditional +ifdef VCHELP + WFLAGS+=-Wdeclaration-after-statement +endif + WFLAGS+=-Wundef +ifndef GCC295 + WFLAGS+=-Wendif-labels +endif +ifdef GCC41 + WFLAGS+=-Wshadow +endif +#WFLAGS+=-Wlarger-than-%len% + WFLAGS+=-Wpointer-arith -Wbad-function-cast +ifdef GCC45 +#WFLAGS+=-Wc++-compat +endif + WFLAGS+=-Wcast-qual +ifndef NOCASTALIGNWARN + WFLAGS+=-Wcast-align +endif + WFLAGS+=-Wwrite-strings +ifndef ERRORMODE +#WFLAGS+=-Wconversion +ifdef GCC43 + #WFLAGS+=-Wno-sign-conversion +endif +endif + WFLAGS+=-Wsign-compare +ifdef GCC45 + WFLAGS+=-Wlogical-op +endif + WFLAGS+=-Waggregate-return +ifdef HAIKU +ifdef GCC41 + #WFLAGS+=-Wno-attributes +endif +endif +#WFLAGS+=-Wstrict-prototypes +ifdef GCC40 + WFLAGS+=-Wold-style-definition +endif +ifndef XBOX + WFLAGS+=-Wmissing-prototypes -Wmissing-declarations +endif +ifdef GCC40 + WFLAGS+=-Wmissing-field-initializers +endif +ifndef XBOX + WFLAGS+=-Wmissing-noreturn +endif +#WFLAGS+=-Wmissing-format-attribute +#WFLAGS+=-Wno-multichar +#WFLAGS+=-Wno-deprecated-declarations +#WFLAGS+=-Wpacked +#WFLAGS+=-Wpadded +#WFLAGS+=-Wredundant-decls + WFLAGS+=-Wnested-externs +#WFLAGS+=-Wunreachable-code + WFLAGS+=-Winline +ifdef GCC43 + WFLAGS+=-funit-at-a-time + WFLAGS+=-Wlogical-op +endif +ifndef GCC295 + WFLAGS+=-Wdisabled-optimization +endif +endif +WFLAGS+=-Wformat-y2k +WFLAGS+=-Wformat-security +ifndef GCC29 +#WFLAGS+=-Winit-self +endif +ifndef MINGW +ifdef GCC45 +WFLAGS+=-Wunsuffixed-float-constants +endif +endif +ifdef NOLDWARNING +LDFLAGS+=-Wl,--as-needed +endif +ifdef ERRORMODE +WFLAGS+=-Werror +endif +ifdef GCC43 + #WFLAGS+=-Wno-error=clobbered +endif +WFLAGS+=$(OLDWFLAGS) + +#indicate platform and what interface use with +ifndef WINCE +ifndef XBOX +ifndef PSP +ifndef DC +ifndef WII +ifndef PS3N +ifndef LINUX +ifndef FREEBSD +ifndef CYGWIN32 +ifndef MINGW +ifndef SDL +ifndef NDS +ifndef DUMMY + DJGPPDOS=1 +endif +endif +endif +endif +endif +endif +endif +endif +endif +endif +endif +endif +endif + +#determine the interface directory (where you put all i_*.c) +i_cdmus_o=$(OBJDIR)/i_cdmus.o +i_net_o=$(OBJDIR)/i_net.o +i_system_o=$(OBJDIR)/i_system.o +i_sound_o=$(OBJDIR)/i_sound.o +i_main_o=$(OBJDIR)/i_main.o +#set OBJDIR and BIN's starting place +OBJDIR=../objs +BIN=../bin +#Nasm ASM and rm +ifdef YASM +NASM?=yasm +else +NASM?=nasm +endif +REMOVE?=rm -f +CP?=cp +MKDIR?=mkdir -p +MKISOFS?=mkisofs +DD?=dd +GZIP?=gzip +GZIP_OPTS?=-9 -f -n +GZIP_OPT2=$(GZIP_OPTS) --rsyncable +UPX?=upx +UPX_OPTS?=--best --preserve-build-id +ifndef ECHO +UPX_OPTS+=-q +endif + +#Interface Setup +ifdef DJGPPDOS + INTERFACE=djgppdos + NASMFORMAT=coff + OBJDIR:=$(OBJDIR)/djgppdos +ifdef WATTCP + OBJDIR:=$(OBJDIR)/wattcp +endif + WFLAGS+=-Wno-format + BIN:=$(BIN)/Dos +else +ifdef DUMMY + INTERFACE=dummy + OBJDIR:=$(OBJDIR)/dummy + BIN:=$(BIN)/dummy +else +ifdef LINUX + INTERFACE=sdl + NASMFORMAT=elf -DLINUX + SDL=1 +ifndef NOGETTEXT + GETTEXT=1 +endif +ifdef LINUX64 + OBJDIR:=$(OBJDIR)/Linux64 + BIN:=$(BIN)/Linux64 +else + OBJDIR:=$(OBJDIR)/Linux + BIN:=$(BIN)/Linux +endif +else +ifdef FREEBSD + INTERFACE=sdl + NASMFORMAT=elf -DLINUX + SDL=1 + + OBJDIR:=$(OBJDIR)/FreeBSD + BIN:=$(BIN)/FreeBSD +else +ifdef SOLARIS + INTERFACE=sdl + NASMFORMAT=elf -DLINUX + SDL=1 + + OBJDIR:=$(OBJDIR)/Solaris + BIN:=$(BIN)/Solaris +else +ifdef CYGWIN32 + INTERFACE=sdl + NASMFORMAT=win32 + SDL=1 + + OBJDIR:=$(OBJDIR)/cygwin + BIN:=$(BIN)/Cygwin +else +ifdef MINGW64 + INTERFACE=win32 + #NASMFORMAT=win64 +ifndef NOGETTEXT + #GETTEXT=1 +endif + OBJDIR:=$(OBJDIR)/Mingw64 + BIN:=$(BIN)/Mingw64 +else +ifdef WII + INTERFACE=sdl + NONX86=1 + STATIC=1 + PREFIX?=powerpc-eabi + SDL=1 + SDLMAIN=1 + OBJDIR:=$(OBJDIR)/Wii + BIN:=$(BIN)/Wii + NOUPX=1 +else +ifdef PS3N + INTERFACE=sdl + NONX86=1 + STATIC=1 + PREFIX?=ppu + SDL=1 + # unsure? + #SDLMAIN=1 + # can't compile SDL_mixer for ps3... + NOMIXER=1 + OBJDIR:=$(OBJDIR)/PS3 + BIN:=$(BIN)/PS3 +else +ifdef MINGW + INTERFACE=win32 + NASMFORMAT=win32 +ifndef NOGETTEXT + GETTEXT=1 +endif + OBJDIR:=$(OBJDIR)/Mingw + BIN:=$(BIN)/Mingw +else +ifdef XBOX + INTERFACE=sdl + NASMFORMAT=win32 + PREFIX?=/usr/local/openxdk/bin/i386-pc-xbox + SDL=1 + OBJDIR:=$(OBJDIR)/XBOX + BIN:=$(BIN)/XBOX +else +ifdef PSP + INTERFACE=sdl + NONX86=1 + SDL=1 + OBJDIR:=$(OBJDIR)/PSP + BIN:=$(BIN)/PSP + NOUPX=1 +else +ifdef DC + INTERFACE=sdl + NONX86=1 + SDL=1 + OBJDIR:=$(OBJDIR)/DC + BIN:=$(BIN)/DC + NOUPX=1 +else +ifdef WINCE + INTERFACE=sdl + NONX86=1 + PREFIX?=arm-wince-pe + SDL=1 + OBJDIR:=$(OBJDIR)/WinCE + BIN:=$(BIN)/WinCE +else +ifdef NDS + INTERFACE=nds + OBJDIR:=$(OBJDIR)/nds + BIN:=$(BIN)/nds + NOUPX=1 +endif +endif +endif +endif +endif +endif +endif +endif +endif +endif +endif +endif +endif +endif +endif + +ifdef ARCHNAME + OBJDIR:=$(OBJDIR)/$(ARCHNAME) + BIN:=$(BIN)/$(ARCHNAME) +endif + +# gcc or g++ +ifdef PREFIX + CC=$(PREFIX)-gcc + CXX=$(PREFIX)-g++ + OBJCOPY=$(PREFIX)-objcopy + OBJDUMP=$(PREFIX)-objdump + STRIP=$(PREFIX)-strip + WINDRES=$(PREFIX)-windres +else + OBJCOPY=objcopy + OBJDUMP=objdump + STRIP=strip + WINDRES=windres +endif + +OBJDUMP_OPTS?=--wide --source --line-numbers +LD=$(CC) + +ifdef SDL + INTERFACE=sdl + OBJDIR:=$(OBJDIR)/SDL +endif + +ifndef DUMMY +ifdef DEBUGMODE + OBJDIR:=$(OBJDIR)/Debug + BIN:=$(BIN)/Debug +else + OBJDIR:=$(OBJDIR)/Release + BIN:=$(BIN)/Release +endif +endif diff --git a/src/am_map.c b/src/am_map.c new file mode 100644 index 000000000..9c2aee2c3 --- /dev/null +++ b/src/am_map.c @@ -0,0 +1,1175 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 1993-1996 by id Software, Inc. +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Copyright (C) 1999-2014 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file am_map.c +/// \brief the automap code + +#include "g_game.h" +#include "am_map.h" +#include "g_input.h" +#include "p_local.h" +#include "v_video.h" +#include "i_video.h" +#include "r_state.h" +#include "r_draw.h" + +#ifdef HWRENDER +#include "hardware/hw_main.h" +#endif + +// For use if I do walls with outsides/insides +static const UINT8 GREENS = (10*16); +static const UINT8 GREENRANGE = 16; +static const UINT8 GRAYS = (0*16); +static const UINT8 GRAYSRANGE = 16; +static const UINT8 DBLACK = 31; +static const UINT8 DWHITE = 0; + +#ifdef _NDS +#undef BACKGROUND +#endif + +// Automap colors +#define BACKGROUND DBLACK +#define YOURCOLORS DWHITE +#define YOURRANGE 0 +#define WALLCOLORS REDS +#define WALLRANGE REDRANGE +#define TSWALLCOLORS GRAYS +#define TSWALLRANGE GRAYSRANGE +#define FDWALLCOLORS BROWNS +#define FDWALLRANGE BROWNRANGE +#define CDWALLCOLORS YELLOWS +#define CDWALLRANGE YELLOWRANGE +#define THINGCOLORS GREENS +#define THINGRANGE GREENRANGE +#define SECRETWALLCOLORS WALLCOLORS +#define SECRETWALLRANGE WALLRANGE +#define GRIDCOLORS (GRAYS + GRAYSRANGE/2) +#define GRIDRANGE 0 +#define XHAIRCOLORS GRAYS + +// drawing stuff +#define FB 0 + +#define AM_PANDOWNKEY KEY_DOWNARROW +#define AM_PANUPKEY KEY_UPARROW +#define AM_PANRIGHTKEY KEY_RIGHTARROW +#define AM_PANLEFTKEY KEY_LEFTARROW +#define AM_ZOOMINKEY '=' +#define AM_ZOOMOUTKEY '-' +#define AM_STARTKEY KEY_TAB +#define AM_ENDKEY KEY_TAB +#define AM_GOBIGKEY '0' +#define AM_FOLLOWKEY 'f' +#define AM_GRIDKEY 'g' +#define AM_MARKKEY 'm' +#define AM_CLEARMARKKEY 'c' + +#define AM_NUMMARKPOINTS 10 + +// scale on entry +#define INITSCALEMTOF (FRACUNIT/5) +// how much the automap moves window per tic in frame-buffer coordinates +// moves 140 pixels in 1 second +#define F_PANINC 4 +// how much zoom-in per tic +// goes to 2x in 1 second +#define M_ZOOMIN ((51*FRACUNIT)/50) +// how much zoom-out per tic +// pulls out to 0.5x in 1 second +#define M_ZOOMOUT ((50*FRACUNIT)/51) + +// translates between frame-buffer and map distances +#define FTOM(x) FixedMul(((x)<>FRACBITS) +// translates between frame-buffer and map coordinates +#define CXMTOF(x) (f_x + MTOF((x)-m_x)) +#define CYMTOF(y) (f_y + (f_h - MTOF((y)-m_y))) + +typedef struct +{ + fixed_t x, y; +} mpoint_t; + +typedef struct +{ + mpoint_t a, b; +} mline_t; + +typedef struct +{ + fixed_t slp, islp; +} islope_t; + +// +// The vector graphics for the automap. +// A line drawing of the player pointing right, +// starting from the middle. +// +#define R ((8*PLAYERRADIUS)/7) +static const mline_t player_arrow[] = { + { { -R+R/8, 0 }, { R, 0 } }, // ----- + { { R, 0 }, { R-R/2, R/4 } }, // -----> + { { R, 0 }, { R-R/2, -R/4 } }, + { { -R+R/8, 0 }, { -R-R/8, R/4 } }, // >----> + { { -R+R/8, 0 }, { -R-R/8, -R/4 } }, + { { -R+3*R/8, 0 }, { -R+R/8, R/4 } }, // >>---> + { { -R+3*R/8, 0 }, { -R+R/8, -R/4 } } +}; +#undef R +#define NUMPLYRLINES (sizeof (player_arrow)/sizeof (mline_t)) + +#if 0 +#define R (FRACUNIT) +static mline_t triangle_guy[] = { + { { (fixed_t)-.867f*R, (fixed_t)-.5f*R }, { (fixed_t) .867f*R, (fixed_t)-.5f*R } }, + { { (fixed_t) .867f*R, (fixed_t)-.5f*R }, { (fixed_t) 0, (fixed_t) R } }, + { { (fixed_t) 0, (fixed_t) R }, { (fixed_t)-.867f*R, (fixed_t)-.5f*R } } +}; +#undef R +#define NUMTRIANGLEGUYLINES (sizeof (triangle_guy)/sizeof (mline_t)) +#endif + +#define R (FRACUNIT) +static const mline_t thintriangle_guy[] = { + { { (-1*R)/2, (-7*R)/10 }, { R, 0 } }, + { { R, 0 }, { (-1*R)/2, (7*R)/10 } }, + { { (-1*R)/2, (7*R)/10 }, { (-1*R)/2, (-7*R)/10 } } +}; +#undef R +#define NUMTHINTRIANGLEGUYLINES (sizeof (thintriangle_guy)/sizeof (mline_t)) + +static INT32 bigstate; //added : 24-01-98 : moved here, toggle between + // user view and large view (full map view) + +static INT32 grid = 0; + +static INT32 leveljuststarted = 1; // kluge until AM_LevelInit() is called + +boolean automapactive = false; +boolean am_recalc = false; //added : 05-02-98 : true when screen size changes + +// location of window on screen +static INT32 f_x; +static INT32 f_y; + +// size of window on screen +static INT32 f_w; +static INT32 f_h; + +static INT32 lightlev; // used for funky strobing effect +static UINT8 *fb; // pseudo-frame buffer +static INT32 amclock; + +static mpoint_t m_paninc; // how far the window pans each tic (map coords) +static fixed_t mtof_zoommul; // how far the window zooms in each tic (map coords) +static fixed_t ftom_zoommul; // how far the window zooms in each tic (fb coords) + +static fixed_t m_x, m_y; // LL x,y where the window is on the map (map coords) +static fixed_t m_x2, m_y2; // UR x,y where the window is on the map (map coords) + +// +// width/height of window on map (map coords) +// +static fixed_t m_w; +static fixed_t m_h; + +// based on level size +static fixed_t min_x; +static fixed_t min_y; +static fixed_t max_x; +static fixed_t max_y; + +static fixed_t max_w; // max_x-min_x, +static fixed_t max_h; // max_y-min_y + +// based on player size +static fixed_t min_w; +static fixed_t min_h; + + +static fixed_t min_scale_mtof; // used to tell when to stop zooming out +static fixed_t max_scale_mtof; // used to tell when to stop zooming in + +// old stuff for recovery later +static fixed_t old_m_w, old_m_h; +static fixed_t old_m_x, old_m_y; + +// old location used by the Follower routine +static mpoint_t f_oldloc; + +// used by MTOF to scale from map-to-frame-buffer coords +static fixed_t scale_mtof = (fixed_t)INITSCALEMTOF; +// used by FTOM to scale from frame-buffer-to-map coords (=1/scale_mtof) +static fixed_t scale_ftom; + +static player_t *plr; // the player represented by an arrow + +static patch_t *marknums[10]; // numbers used for marking by the automap +static mpoint_t markpoints[AM_NUMMARKPOINTS]; // where the points are +static INT32 markpointnum = 0; // next point to be assigned + +static INT32 followplayer = 1; // specifies whether to follow the player around + +static boolean stopped = true; + +// function for drawing lines, depends on rendermode +typedef void (*AMDRAWFLINEFUNC) (const fline_t *fl, INT32 color); +static AMDRAWFLINEFUNC AM_drawFline; + +static void AM_drawFline_soft(const fline_t *fl, INT32 color); + +/** Calculates the slope and slope according to the x-axis of a line + * segment in map coordinates (with the upright y-axis and all) so + * that it can be used with the braindead drawing stuff. + * + * \param ml The line segment. + * \param is Holds the result. + */ +static inline void AM_getIslope(const mline_t *ml, islope_t *is) +{ + INT32 dx, dy; + + dy = ml->a.y - ml->b.y; + dx = ml->b.x - ml->a.x; + if (!dy) + is->islp = (dx < 0 ? -INT32_MAX : INT32_MAX); + else + is->islp = FixedDiv(dx, dy); + if (!dx) + is->slp = (dy < 0 ? -INT32_MAX : INT32_MAX); + else + is->slp = FixedDiv(dy, dx); +} + +static void AM_activateNewScale(void) +{ + m_x += m_w/2; + m_y += m_h/2; + m_w = FTOM(f_w); + m_h = FTOM(f_h); + m_x -= m_w/2; + m_y -= m_h/2; + m_x2 = m_x + m_w; + m_y2 = m_y + m_h; +} + +static inline void AM_saveScaleAndLoc(void) +{ + old_m_x = m_x; + old_m_y = m_y; + old_m_w = m_w; + old_m_h = m_h; +} + +static inline void AM_restoreScaleAndLoc(void) +{ + m_w = old_m_w; + m_h = old_m_h; + if (!followplayer) + { + m_x = old_m_x; + m_y = old_m_y; + } + else + { + m_x = plr->mo->x - m_w/2; + m_y = plr->mo->y - m_h/2; + } + m_x2 = m_x + m_w; + m_y2 = m_y + m_h; + + // Change the scaling multipliers + scale_mtof = FixedDiv(f_w< max_x) + max_x = vertexes[i].x; + + if (vertexes[i].y < min_y) + min_y = vertexes[i].y; + else if (vertexes[i].y > max_y) + max_y = vertexes[i].y; + } + + max_w = max_x - min_x; + max_h = max_y - min_y; + + min_w = 2*PLAYERRADIUS; // const? never changed? + min_h = 2*PLAYERRADIUS; + + a = FixedDiv(f_w< max_x) + m_x = max_x - m_w/2; + else if (m_x + m_w/2 < min_x) + m_x = min_x - m_w/2; + + if (m_y + m_h/2 > max_y) + m_y = max_y - m_h/2; + else if (m_y + m_h/2 < min_y) + m_y = min_y - m_h/2; + + m_x2 = m_x + m_w; + m_y2 = m_y + m_h; +} + +static void AM_initVariables(void) +{ + INT32 pnum; + + automapactive = true; + fb = screens[0]; + + f_oldloc.x = INT32_MAX; + amclock = 0; + lightlev = 0; + + m_paninc.x = m_paninc.y = 0; + ftom_zoommul = FRACUNIT; + mtof_zoommul = FRACUNIT; + + m_w = FTOM(f_w); + m_h = FTOM(f_h); + + // find player to center on initially + if (!playeringame[pnum = consoleplayer]) + for (pnum = 0; pnum < MAXPLAYERS; pnum++) + if (playeringame[pnum]) + break; + + plr = &players[pnum]; + m_x = plr->mo->x - m_w/2; + m_y = plr->mo->y - m_h/2; + AM_changeWindowLoc(); + + // for saving & restoring + old_m_x = m_x; + old_m_y = m_y; + old_m_w = m_w; + old_m_h = m_h; +} + +static const UINT8 *maplump; // pointer to the raw data for the automap background. + +/** Clears all map markers. + */ +static void AM_clearMarks(void) +{ + INT32 i; + + for (i = 0; i < AM_NUMMARKPOINTS; i++) + markpoints[i].x = -1; // means empty + markpointnum = 0; +} + +// +// should be called at the start of every level +// right now, i figure it out myself +// +static void AM_LevelInit(void) +{ + leveljuststarted = 0; + + f_x = f_y = 0; + f_w = vid.width; + f_h = vid.height; + + if (rendermode == render_soft) + AM_drawFline = AM_drawFline_soft; +#ifdef HWRENDER // not win32 only 19990829 by Kin + else if (rendermode != render_none) + AM_drawFline = HWR_drawAMline; +#endif + else + I_Error("Automap can't run without a render system"); + + AM_clearMarks(); + + AM_findMinMaxBoundaries(); + scale_mtof = FixedDiv(min_scale_mtof*10, 7*FRACUNIT); + if (scale_mtof > max_scale_mtof) + scale_mtof = min_scale_mtof; + scale_ftom = FixedDiv(FRACUNIT, scale_mtof); +} + +/** Disables automap. + * + * \sa AM_Start + */ +void AM_Stop(void) +{ + automapactive = false; + stopped = true; +} + +/** Enables automap. + * + * \sa AM_Stop + */ +static inline void AM_Start(void) +{ + static INT32 lastlevel = -1; + + if (!stopped) + AM_Stop(); + stopped = false; + if (lastlevel != gamemap || am_recalc) // screen size changed + { + am_recalc = false; + + AM_LevelInit(); + lastlevel = gamemap; + } + AM_initVariables(); +} + +// +// set the window scale to the maximum size +// +static void AM_minOutWindowScale(void) +{ + scale_mtof = min_scale_mtof; + scale_ftom = FixedDiv(FRACUNIT, scale_mtof); + AM_activateNewScale(); +} + +// +// set the window scale to the minimum size +// +static void AM_maxOutWindowScale(void) +{ + scale_mtof = max_scale_mtof; + scale_ftom = FixedDiv(FRACUNIT, scale_mtof); + AM_activateNewScale(); +} + +/** Responds to user inputs in automap mode. + * + * \param ev Event to possibly respond to. + * \return True if the automap responder ate the event. + */ +boolean AM_Responder(event_t *ev) +{ + INT32 rc = false; + + if (devparm || cv_debug) // only automap in Debug Tails 01-19-2001 + { + if (!automapactive) + { + if (ev->type == ev_keydown && ev->data1 == AM_STARTKEY) + { + //faB: prevent alt-tab in win32 version to activate automap just before + // minimizing the app; doesn't do any harm to the DOS version + if (!gamekeydown[KEY_LALT] && !gamekeydown[KEY_RALT]) + { + bigstate = 0; //added : 24-01-98 : toggle off large view + AM_Start(); + rc = true; + } + } + } + + else if (ev->type == ev_keydown) + { + + rc = true; + switch (ev->data1) + { + case AM_PANRIGHTKEY: // pan right + if (!followplayer) + m_paninc.x = FTOM(F_PANINC); + else + rc = false; + break; + case AM_PANLEFTKEY: // pan left + if (!followplayer) + m_paninc.x = -FTOM(F_PANINC); + else + rc = false; + break; + case AM_PANUPKEY: // pan up + if (!followplayer) + m_paninc.y = FTOM(F_PANINC); + else + rc = false; + break; + case AM_PANDOWNKEY: // pan down + if (!followplayer) + m_paninc.y = -FTOM(F_PANINC); + else + rc = false; + break; + case AM_ZOOMOUTKEY: // zoom out + mtof_zoommul = M_ZOOMOUT; + ftom_zoommul = M_ZOOMIN; + break; + case AM_ZOOMINKEY: // zoom in + mtof_zoommul = M_ZOOMIN; + ftom_zoommul = M_ZOOMOUT; + break; + case AM_ENDKEY: + AM_Stop(); + break; + case AM_GOBIGKEY: + bigstate = !bigstate; + if (bigstate) + { + AM_saveScaleAndLoc(); + AM_minOutWindowScale(); + } + else + AM_restoreScaleAndLoc(); + break; + case AM_FOLLOWKEY: + followplayer = !followplayer; + f_oldloc.x = INT32_MAX; + break; + case AM_GRIDKEY: + grid = !grid; + break; + case AM_MARKKEY: + AM_addMark(); + break; + case AM_CLEARMARKKEY: + AM_clearMarks(); + break; + default: + rc = false; + } + } + + else if (ev->type == ev_keyup) + { + rc = false; + switch (ev->data1) + { + case AM_PANRIGHTKEY: + case AM_PANLEFTKEY: + if (!followplayer) + m_paninc.x = 0; + break; + case AM_PANUPKEY: + case AM_PANDOWNKEY: + if (!followplayer) + m_paninc.y = 0; + break; + case AM_ZOOMOUTKEY: + case AM_ZOOMINKEY: + mtof_zoommul = FRACUNIT; + ftom_zoommul = FRACUNIT; + break; + } + } + } + + return rc; +} + +/** Makes a zooming change take effect. + */ +static inline void AM_changeWindowScale(void) +{ + // Change the scaling multipliers + scale_mtof = FixedMul(scale_mtof, mtof_zoommul); + scale_ftom = FixedDiv(FRACUNIT, scale_mtof); + + if (scale_mtof < min_scale_mtof) + AM_minOutWindowScale(); + else if (scale_mtof > max_scale_mtof) + AM_maxOutWindowScale(); + else + AM_activateNewScale(); +} + +static inline void AM_doFollowPlayer(void) +{ + if (f_oldloc.x != plr->mo->x || f_oldloc.y != plr->mo->y) + { + m_x = FTOM(MTOF(plr->mo->x)) - m_w/2; + m_y = FTOM(MTOF(plr->mo->y)) - m_h/2; + m_x2 = m_x + m_w; + m_y2 = m_y + m_h; + f_oldloc.x = plr->mo->x; + f_oldloc.y = plr->mo->y; + } +} + +/** Updates automap on a game tic, while the automap is enabled. + */ +void AM_Ticker(void) +{ + if (!cv_debug) + AM_Stop(); + + if (dedicated || !automapactive) + return; + + amclock++; + + if (followplayer) + AM_doFollowPlayer(); + + // Change the zoom if necessary + if (ftom_zoommul != FRACUNIT) + AM_changeWindowScale(); + + // Change x,y location + if (m_paninc.x || m_paninc.y) + AM_changeWindowLoc(); +} + +/** Clears the automap framebuffer. + * + * \param color Color to erase to. + */ +static void AM_clearFB(INT32 color) +{ +#ifdef HWRENDER + if (rendermode != render_soft && rendermode != render_none) + { + HWR_clearAutomap(); + return; + } +#endif + + if (!maplump) + memset(fb, color, f_w*f_h*vid.bpp); + else + { + INT32 dmapx, dmapy, i, y; + static INT32 mapxstart, mapystart; + UINT8 *dest = screens[0]; + const UINT8 *src; +#define MAPLUMPHEIGHT (200 - 42) + + if (followplayer) + { + static vertex_t oldplr; + + dmapx = MTOF(plr->mo->x) - MTOF(oldplr.x); //fixed point + dmapy = MTOF(oldplr.y) - MTOF(plr->mo->y); + + oldplr.x = plr->mo->x; + oldplr.y = plr->mo->y; + mapxstart += dmapx>>1; + mapystart += dmapy>>1; + + while (mapxstart >= BASEVIDWIDTH) + mapxstart -= BASEVIDWIDTH; + while (mapxstart < 0) + mapxstart += BASEVIDWIDTH; + while (mapystart >= MAPLUMPHEIGHT) + mapystart -= MAPLUMPHEIGHT; + while (mapystart < 0) + mapystart += MAPLUMPHEIGHT; + } + else + { + mapxstart += (MTOF(m_paninc.x)>>1); + mapystart -= (MTOF(m_paninc.y)>>1); + if (mapxstart >= BASEVIDWIDTH) + mapxstart -= BASEVIDWIDTH; + if (mapxstart < 0) + mapxstart += BASEVIDWIDTH; + if (mapystart >= MAPLUMPHEIGHT) + mapystart -= MAPLUMPHEIGHT; + if (mapystart < 0) + mapystart += MAPLUMPHEIGHT; + } + + //blit the automap background to the screen. + for (y = 0; y < f_h; y++) + { + src = maplump + mapxstart + (y + mapystart)*BASEVIDWIDTH; + for (i = 0; i < BASEVIDWIDTH*vid.dupx; i++) + { + while (src > maplump + BASEVIDWIDTH*MAPLUMPHEIGHT) + src -= BASEVIDWIDTH*MAPLUMPHEIGHT; + *dest++ = *src++; + } + dest += vid.width - vid.dupx*BASEVIDWIDTH; + } + } +} + +/** Performs automap clipping of lines. + * Based on Cohen-Sutherland clipping algorithm but with a slightly + * faster reject and precalculated slopes. If the speed is needed, + * use a hash algorithm to handle the common cases. + * + * \param ml Line to clip. + * \param fl Resulting framebuffer coordinates? + * \return True if the line is inside the boundaries. + */ +static boolean AM_clipMline(const mline_t *ml, fline_t *fl) +{ + enum + { + LEFT = 1, + RIGHT = 2, + BOTTOM = 4, + TOP = 8 + }; + + register INT32 outcode1 = 0, outcode2 = 0, outside; + fpoint_t tmp ={0,0}; + INT32 dx, dy; + +#define DOOUTCODE(oc, mx, my) \ + (oc) = 0; \ + if ((my) < 0) (oc) |= TOP; \ + else if ((my) >= f_h) (oc) |= BOTTOM; \ + if ((mx) < 0) (oc) |= LEFT; \ + else if ((mx) >= f_w) (oc) |= RIGHT; + + // do trivial rejects and outcodes + if (ml->a.y > m_y2) + outcode1 = TOP; + else if (ml->a.y < m_y) + outcode1 = BOTTOM; + + if (ml->b.y > m_y2) + outcode2 = TOP; + else if (ml->b.y < m_y) + outcode2 = BOTTOM; + + if (outcode1 & outcode2) + return false; // trivially outside + + if (ml->a.x < m_x) + outcode1 |= LEFT; + else if (ml->a.x > m_x2) + outcode1 |= RIGHT; + + if (ml->b.x < m_x) + outcode2 |= LEFT; + else if (ml->b.x > m_x2) + outcode2 |= RIGHT; + + if (outcode1 & outcode2) + return false; // trivially outside + + // transform to frame-buffer coordinates. + fl->a.x = CXMTOF(ml->a.x); + fl->a.y = CYMTOF(ml->a.y); + fl->b.x = CXMTOF(ml->b.x); + fl->b.y = CYMTOF(ml->b.y); + + DOOUTCODE(outcode1, fl->a.x, fl->a.y); + DOOUTCODE(outcode2, fl->b.x, fl->b.y); + + if (outcode1 & outcode2) + return false; + + while (outcode1 | outcode2) + { + // may be partially inside box + // find an outside point + if (outcode1) + outside = outcode1; + else + outside = outcode2; + + // clip to each side + if (outside & TOP) + { + dy = fl->a.y - fl->b.y; + dx = fl->b.x - fl->a.x; + tmp.x = fl->a.x + (dx*(fl->a.y))/dy; + tmp.y = 0; + } + else if (outside & BOTTOM) + { + dy = fl->a.y - fl->b.y; + dx = fl->b.x - fl->a.x; + tmp.x = fl->a.x + (dx*(fl->a.y-f_h))/dy; + tmp.y = f_h-1; + } + else if (outside & RIGHT) + { + dy = fl->b.y - fl->a.y; + dx = fl->b.x - fl->a.x; + tmp.y = fl->a.y + (dy*(f_w-1 - fl->a.x))/dx; + tmp.x = f_w-1; + } + else if (outside & LEFT) + { + dy = fl->b.y - fl->a.y; + dx = fl->b.x - fl->a.x; + tmp.y = fl->a.y + (dy*(-fl->a.x))/dx; + tmp.x = 0; + } + + if (outside == outcode1) + { + fl->a = tmp; + DOOUTCODE(outcode1, fl->a.x, fl->a.y); + } + else + { + fl->b = tmp; + DOOUTCODE(outcode2, fl->b.x, fl->b.y); + } + + if (outcode1 & outcode2) + return false; // trivially outside + } + + return true; +} +#undef DOOUTCODE + +// +// Classic Bresenham w/ whatever optimizations needed for speed +// +static void AM_drawFline_soft(const fline_t *fl, INT32 color) +{ + register INT32 x, y, dx, dy, sx, sy, ax, ay, d; + +#ifdef _DEBUG + static INT32 num = 0; + + // For debugging only + if (fl->a.x < 0 || fl->a.x >= f_w + || fl->a.y < 0 || fl->a.y >= f_h + || fl->b.x < 0 || fl->b.x >= f_w + || fl->b.y < 0 || fl->b.y >= f_h) + { + CONS_Debug(DBG_RENDER, "line clipping problem %d\n", num++); + return; + } +#endif + +#define PUTDOT(xx,yy,cc) fb[(yy)*f_w + (xx)]=(UINT8)(cc) + + dx = fl->b.x - fl->a.x; + ax = 2 * (dx < 0 ? -dx : dx); + sx = dx < 0 ? -1 : 1; + + dy = fl->b.y - fl->a.y; + ay = 2 * (dy < 0 ? -dy : dy); + sy = dy < 0 ? -1 : 1; + + x = fl->a.x; + y = fl->a.y; + + if (ax > ay) + { + d = ay - ax/2; + for (;;) + { + PUTDOT(x, y, color); + if (x == fl->b.x) + return; + if (d >= 0) + { + y += sy; + d -= ax; + } + x += sx; + d += ay; + } + } + else + { + d = ax - ay/2; + for (;;) + { + PUTDOT(x, y, color); + if (y == fl->b.y) + return; + if (d >= 0) + { + x += sx; + d -= ay; + } + y += sy; + d += ax; + } + } +} + +// +// Clip lines, draw visible parts of lines. +// +static void AM_drawMline(const mline_t *ml, INT32 color) +{ + static fline_t fl; + + if (AM_clipMline(ml, &fl)) + AM_drawFline(&fl, color); // draws it on frame buffer using fb coords +} + +// +// Draws flat (floor/ceiling tile) aligned grid lines. +// +static void AM_drawGrid(INT32 color) +{ + fixed_t x, y; + fixed_t start, end; + mline_t ml; + + // Figure out start of vertical gridlines + start = m_x; + if ((start - bmaporgx) % (MAPBLOCKUNITS<x; + l.a.y = lines[i].v1->y; + l.b.x = lines[i].v2->x; + l.b.y = lines[i].v2->y; + + AM_drawMline(&l, GRAYS + 3); + } +} + +// +// Rotation in 2D. +// Used to rotate player arrow line character. +// +static void AM_rotate(fixed_t *x, fixed_t *y, angle_t a) +{ + fixed_t tmpx; + + tmpx = FixedMul(*x, FINECOSINE(a>>ANGLETOFINESHIFT)) + - FixedMul(*y, FINESINE(a>>ANGLETOFINESHIFT)); + + *y = FixedMul(*x, FINESINE(a>>ANGLETOFINESHIFT)) + + FixedMul(*y, FINECOSINE(a>>ANGLETOFINESHIFT)); + + *x = tmpx; +} + +static void AM_drawLineCharacter(const mline_t *lineguy, size_t lineguylines, fixed_t scale, angle_t angle, + INT32 color, fixed_t x, fixed_t y) +{ + size_t i; + mline_t l; + + for (i = 0; i < lineguylines; i++) + { + l.a.x = lineguy[i].a.x; + l.a.y = lineguy[i].a.y; + + if (scale) + { + l.a.x = FixedMul(scale, l.a.x); + l.a.y = FixedMul(scale, l.a.y); + } + + if (angle) + AM_rotate(&l.a.x, &l.a.y, angle); + + l.a.x += x; + l.a.y += y; + + l.b.x = lineguy[i].b.x; + l.b.y = lineguy[i].b.y; + + if (scale) + { + l.b.x = FixedMul(scale, l.b.x); + l.b.y = FixedMul(scale, l.b.y); + } + + if (angle) + AM_rotate(&l.b.x, &l.b.y, angle); + + l.b.x += x; + l.b.y += y; + + AM_drawMline(&l, color); + } +} + +static inline void AM_drawPlayers(void) +{ + INT32 i; + player_t *p; + INT32 color; + + if (!multiplayer) + { + AM_drawLineCharacter(player_arrow, NUMPLYRLINES, 0, + plr->mo->angle, DWHITE, plr->mo->x, plr->mo->y); + return; + } + + // multiplayer + for (i = 0; i < MAXPLAYERS; i++) + { + if (!playeringame[i] || players[i].spectator) + continue; + + p = &players[i]; + if (p->skincolor == 0) + color = GREENS; + else + color = R_GetTranslationColormap(TC_DEFAULT, p->skincolor, GTC_CACHE)[GREENS + 8]; + + AM_drawLineCharacter(player_arrow, NUMPLYRLINES, 0, p->mo->angle, + color, p->mo->x, p->mo->y); + } +} + +static inline void AM_drawThings(INT32 colors, INT32 colorrange) +{ + size_t i; + mobj_t *t; + + (void)colorrange; + for (i = 0; i < numsectors; i++) + { + t = sectors[i].thinglist; + while (t) + { + AM_drawLineCharacter(thintriangle_guy, NUMTHINTRIANGLEGUYLINES, + 16<angle, colors + lightlev, t->x, t->y); + t = t->snext; + } + } +} + +static inline void AM_drawMarks(void) +{ + INT32 i, fx, fy, w, h; + + for (i = 0; i < AM_NUMMARKPOINTS; i++) + { + if (markpoints[i].x != -1 && marknums[i]) + { + // w = SHORT(marknums[i]->width); + // h = SHORT(marknums[i]->height); + w = 5; // because something's wrong with the wad, i guess + h = 6; // because something's wrong with the wad, i guess + fx = CXMTOF(markpoints[i].x); + fy = CYMTOF(markpoints[i].y); + if (fx >= f_x && fx <= f_w - w && fy >= f_y && fy <= f_h - h) + V_DrawPatch(fx, fy, FB, marknums[i]); + } + } +} + +/** Draws the crosshair, actually just a dot in software mode. + * + * \param color Color for the crosshair. + */ +static inline void AM_drawCrosshair(INT32 color) +{ + if (rendermode != render_soft) + return; // BP: should be putpixel here + + if (scr_bpp == 1) + fb[(f_w*(f_h + 1))/2] = (UINT8)color; // single point for now + else + *((INT16 *)(void *)fb + (f_w*(f_h + 1))/2) = (INT16)color; +} + +/** Draws the automap. + */ +void AM_Drawer(void) +{ + if (!automapactive) + return; + + AM_clearFB(BACKGROUND); + if (grid) + AM_drawGrid(GRIDCOLORS); + AM_drawWalls(); + AM_drawPlayers(); + AM_drawThings(THINGCOLORS, THINGRANGE); + + AM_drawCrosshair(XHAIRCOLORS); + + AM_drawMarks(); +} diff --git a/src/am_map.h b/src/am_map.h new file mode 100644 index 000000000..009a10e76 --- /dev/null +++ b/src/am_map.h @@ -0,0 +1,49 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 1993-1996 by id Software, Inc. +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Copyright (C) 1999-2014 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file am_map.h +/// \brief AutoMap module + +#ifndef __AMMAP_H__ +#define __AMMAP_H__ + +#include "d_event.h" + +typedef struct +{ + INT32 x, y; +} fpoint_t; + +typedef struct +{ + fpoint_t a, b; +} fline_t; + +// Used by ST StatusBar stuff. +#define AM_MSGHEADER (('a'<<24)+('m'<<16)) +#define AM_MSGENTERED (AM_MSGHEADER | ('e'<<8)) +#define AM_MSGEXITED (AM_MSGHEADER | ('x'<<8)) + +extern boolean am_recalc; // true if screen size changes +extern boolean automapactive; // In AutoMap mode? + +// Called by main loop. +boolean AM_Responder(event_t *ev); + +// Called by main loop. +void AM_Ticker(void); + +// Called by main loop, instead of view drawer if automap is active. +void AM_Drawer(void); + +// Called to force the automap to quit if the level is completed while it is up. +void AM_Stop(void); + +#endif diff --git a/src/android/README b/src/android/README new file mode 100644 index 000000000..a8d35b598 --- /dev/null +++ b/src/android/README @@ -0,0 +1,43 @@ +SRB2 for Google Android! + +SYNOPSIS + +Port of SRB2 to Android, tested against version 1.6 (donut). + +I did this with a full Android tree, rather than the NDK thing. + +BUILDING + +Assuming a pretty standard Android tree, at $REPO, and the SRB2 +tree at $REPO/packages/apps/srb2 (that is, the *whole* SRB2 +tree, not just this android/ directory): + + cd $REPO + source build/envsetup.sh # this gives us the mm command, + # which is useful for selectively + # building only one component. + cd packages/apps/srb2 + mm + +An APK is dumped out at (or similar): +out/target/product/generic/system/app/SRB2.apk + +Naturally, an SRB2 APK is architecture specific. Since most +Android devices are currently ARMEL, this is pretty okay. + +NB. It appears that the Java app (the thing that becomes the APK) +is *not* rebuilt if changes are only made to libsrb2. Grr. + +REGENERATION OF JNI HEADERS + +Whenever the Java classes in org.srb2.nativecode change, +the C header files that describe the JNI interface to them +need to be regnererated. Make sure you have the project +built (so that the jar files are up to date), and then: + + cd $REPO/out/target/common/obj/APPS/SRB2_intermediates + + javah -classpath classes.jar -o $REPO/packages/apps/srb2/src/android/jni_main.h org.srb2.nativecode.Main + +# ... and no, I don't know how to mash all that into the +# Android.mk build system... diff --git a/src/android/i_cdmus.c b/src/android/i_cdmus.c new file mode 100644 index 000000000..c5aac8f18 --- /dev/null +++ b/src/android/i_cdmus.c @@ -0,0 +1,37 @@ +#include "../command.h" +#include "../s_sound.h" +#include "../i_sound.h" + +// +// CD MUSIC I/O +// + +UINT8 cdaudio_started = 0; + +consvar_t cd_volume = {"cd_volume","31",CV_SAVE,soundvolume_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cdUpdate = {"cd_update","1",CV_SAVE, NULL, NULL, 0, NULL, NULL, 0, 0, NULL}; + + +void I_InitCD(void){} + +void I_StopCD(void){} + +void I_PauseCD(void){} + +void I_ResumeCD(void){} + +void I_ShutdownCD(void){} + +void I_UpdateCD(void){} + +void I_PlayCD(UINT8 track, UINT8 looping) +{ + (void)track; + (void)looping; +} + +boolean I_SetVolumeCD(INT32 volume) +{ + (void)volume; + return false; +} diff --git a/src/android/i_main.c b/src/android/i_main.c new file mode 100644 index 000000000..7595668cb --- /dev/null +++ b/src/android/i_main.c @@ -0,0 +1,53 @@ +#define LOG_TAG "SRB2-main" +#include "utils/Log.h" + +#include "../doomdef.h" +#include "../d_main.h" +#include "../m_argv.h" + +#include "i_video.h" + +#include "jni_main.h" + +int srb2_main() +{ + // startup SRB2 + CONS_Printf ("Setting up SRB2 (fo' real)..."); + D_SRB2Main(); + CONS_Printf ("Entering main game loop..."); + // never return + D_SRB2Loop(); + LOGD("Control left SRB2. Good bye."); + + // return to OS + return 0; +} + +JNIEXPORT jint JNICALL Java_org_srb2_nativecode_Main_main +(JNIEnv * env, jobject self, jobject video) { + jobject fbBuf; + jfieldID fbBufField; + + // a global reference to JNI Env, so my callbacks can use it: + jni_env = env; + androidVideo = video; + + jclass videoClass = (*env)->FindClass(env, "org/srb2/nativecode/Video"); + if(videoClass == NULL) { + LOGE("Could not find Video class from JNI!"); + return -1; + } + fbBufField = (*env)->GetFieldID(env, videoClass, "fb", "Ljava/nio/ByteBuffer;"); + fbBuf = (*env)->GetObjectField(env, video, fbBufField); + if(fbBuf == NULL) { + LOGE("Couldn't get Video object from JNI!"); + return -1; + } + videoFrameCB = (*env)->GetMethodID(env, videoClass, "gotFrame", "()V"); + if(videoFrameCB == NULL) { + LOGE("Couldn't get method ID of Video#gotFrame() callback!"); + return -1; + } + android_surface = (UINT8*) (*env)->GetDirectBufferAddress(env, fbBuf); + return srb2_main(); +} diff --git a/src/android/i_net.c b/src/android/i_net.c new file mode 100644 index 000000000..f6e642022 --- /dev/null +++ b/src/android/i_net.c @@ -0,0 +1,6 @@ +#include "../i_net.h" + +boolean I_InitNetwork(void) +{ + return false; +} diff --git a/src/android/i_sound.c b/src/android/i_sound.c new file mode 100644 index 000000000..ecf96f2f0 --- /dev/null +++ b/src/android/i_sound.c @@ -0,0 +1,144 @@ +#include "../i_sound.h" + +UINT8 sound_started = 0; + +void *I_GetSfx(sfxinfo_t *sfx) +{ + (void)sfx; + return NULL; +} + +void I_FreeSfx(sfxinfo_t *sfx) +{ + (void)sfx; +} + +void I_StartupSound(void){} + +void I_ShutdownSound(void){} + +// +// SFX I/O +// + +INT32 I_StartSound(sfxenum_t id, INT32 vol, INT32 sep, INT32 pitch, INT32 priority) +{ + (void)id; + (void)vol; + (void)sep; + (void)pitch; + (void)priority; + return -1; +} + +void I_StopSound(INT32 handle) +{ + (void)handle; +} + +INT32 I_SoundIsPlaying(INT32 handle) +{ + (void)handle; + return false; +} + +void I_UpdateSoundParams(INT32 handle, INT32 vol, INT32 sep, INT32 pitch) +{ + (void)handle; + (void)vol; + (void)sep; + (void)pitch; +} + +void I_SetSfxVolume(INT32 volume) +{ + (void)volume; +} + +// +// MUSIC I/O +// +UINT8 music_started = 0; + +void I_InitMusic(void){} + +void I_ShutdownMusic(void){} + +void I_PauseSong(INT32 handle) +{ + (void)handle; +} + +void I_ResumeSong(INT32 handle) +{ + (void)handle; +} + +// +// MIDI I/O +// + +UINT8 midimusic_started = 0; + +void I_InitMIDIMusic(void){} + +void I_ShutdownMIDIMusic(void){} + +void I_SetMIDIMusicVolume(INT32 volume) +{ + (void)volume; +} + +INT32 I_RegisterSong(void *data, size_t len) +{ + (void)data; + (void)len; + return -1; +} + +boolean I_PlaySong(INT32 handle, INT32 looping) +{ + (void)handle; + (void)looping; + return false; +} + +void I_StopSong(INT32 handle) +{ + (void)handle; +} + +void I_UnRegisterSong(INT32 handle) +{ + (void)handle; +} + +// +// DIGMUSIC I/O +// + +UINT8 digmusic_started = 0; + +void I_InitDigMusic(void){} + +void I_ShutdownDigMusic(void){} + +boolean I_StartDigSong(const char *musicname, INT32 looping) +{ + (void)musicname; + (void)looping; + return false; +} + +void I_StopDigSong(void){} + +void I_SetDigMusicVolume(INT32 volume) +{ + (void)volume; +} + +boolean I_SetSongSpeed(float speed) +{ + (void)speed; + return false; +} diff --git a/src/android/i_system.c b/src/android/i_system.c new file mode 100644 index 000000000..0eacc4282 --- /dev/null +++ b/src/android/i_system.c @@ -0,0 +1,260 @@ +#define LOG_TAG "SRB2" + +#include "../doomdef.h" +#include "../i_system.h" + +#include +#include +#include +#include +#include +#include + +#include + +#define MEMINFO_FILE "/proc/meminfo" +#define MEMTOTAL "MemTotal:" +#define MEMFREE "MemFree:" + +UINT8 graphics_started = 0; + +UINT8 keyboard_started = 0; + +static INT64 start_time; // as microseconds since the epoch + +// I should probably return how much memory is remaining +// for this process, considering Android's process memory limit. +UINT32 I_GetFreeMem(UINT32 *total) +{ + // what the heck? sysinfo() is partially missing in bionic? + /* struct sysinfo si; */ + /* if(sysinfo(&si) != 0) { */ + /* I_Error("Couldn't invoke sysinfo()...?"); */ + /* } */ + /* return si.freeram; */ + char buf[1024]; + char *memTag; + UINT32 freeKBytes; + UINT32 totalKBytes; + INT32 n; + INT32 meminfo_fd = -1; + + meminfo_fd = open(MEMINFO_FILE, O_RDONLY); + n = read(meminfo_fd, buf, 1023); + close(meminfo_fd); + + if (n < 0) + { + // Error + *total = 0L; + return 0; + } + + buf[n] = '\0'; + if (NULL == (memTag = strstr(buf, MEMTOTAL))) + { + // Error + *total = 0L; + return 0; + } + + memTag += sizeof (MEMTOTAL); + totalKBytes = atoi(memTag); + + if (NULL == (memTag = strstr(buf, MEMFREE))) + { + // Error + *total = 0L; + return 0; + } + + memTag += sizeof (MEMFREE); + freeKBytes = atoi(memTag); + + if (total) + *total = totalKBytes << 10; + return freeKBytes << 10; +} + +INT64 current_time_in_ps() { + struct timeval t; + gettimeofday(&t, NULL); + return (t.tv_sec * (INT64)1000000) + t.tv_usec; +} + +tic_t I_GetTime(void) +{ + INT64 since_start = current_time_in_ps() - start_time; + return (since_start*TICRATE)/1000000; +} + +void I_Sleep(void){} + +void I_GetEvent(void){} + +void I_OsPolling(void){} + +ticcmd_t *I_BaseTiccmd(void) +{ + return NULL; +} + +ticcmd_t *I_BaseTiccmd2(void) +{ + return NULL; +} + +void I_Quit(void) +{ + LOGD("SRB2 quitting!"); + exit(0); +} + +void I_Error(const char *error, ...) +{ + va_list argptr; + char logbuf[8192]; + + va_start(argptr, error); + vsprintf(logbuf, error, argptr); + va_end(argptr); + + LOGE(logbuf); + exit(-1); +} + +void I_Tactile(FFType Type, const JoyFF_t *Effect) +{ + (void)Type; + (void)Effect; +} + +void I_Tactile2(FFType Type, const JoyFF_t *Effect) +{ + (void)Type; + (void)Effect; +} + +void I_JoyScale(void){} + +void I_JoyScale2(void){} + +void I_InitJoystick(void){} + +void I_InitJoystick2(void){} + +INT32 I_NumJoys(void) +{ + return 0; +} + +const char *I_GetJoyName(INT32 joyindex) +{ + (void)joyindex; + return NULL; +} + +void I_SetupMumble(void) +{ +} + +void I_UpdateMumble(const MumblePos_t *MPos) +{ + (void)MPos; +} + +void I_OutputMsg(const char *fmt, ...) +{ + va_list argptr; + char logbuf[8192]; + + va_start(argptr, fmt); + vsprintf(logbuf, fmt, argptr); + va_end(argptr); + + LOGD(logbuf); +} + +void I_StartupMouse(void){} + +void I_StartupMouse2(void){} + +void I_StartupKeyboard(void){} + +INT32 I_GetKey(void) +{ + return 0; +} + +void I_StartupTimer(void) { + struct timeval t; + gettimeofday(&t, NULL); + start_time = (t.tv_sec * 1000000) + t.tv_usec; +} + +void I_AddExitFunc(void (*func)()) +{ + (void)func; +} + +void I_RemoveExitFunc(void (*func)()) +{ + (void)func; +} + +INT32 I_StartupSystem(void) +{ + return -1; +} + +void I_ShutdownSystem(void){} + +void I_GetDiskFreeSpace(INT64* freespace) +{ + *freespace = 0; +} + +char *I_GetUserName(void) +{ + return "Android"; +} + +INT32 I_mkdir(const char *dirname, INT32 unixright) +{ + (void)dirname; + (void)unixright; + return -1; +} + +const CPUInfoFlags *I_CPUInfo(void) +{ + return NULL; +} + +const char *I_LocateWad(void) +{ + return "/sdcard/srb2"; +} + +void I_GetJoystickEvents(void){} + +void I_GetJoystick2Events(void){} + +void I_GetMouseEvents(void){} + +char *I_GetEnv(const char *name) +{ + LOGW("I_GetEnv() called?!"); + (void)name; + return NULL; +} + +INT32 I_PutEnv(char *variable) +{ + (void)variable; + return -1; +} + +void I_RegisterSysCommands(void) {} + +#include "../sdl/dosstr.c" diff --git a/src/android/i_video.c b/src/android/i_video.c new file mode 100644 index 000000000..2d0151f5e --- /dev/null +++ b/src/android/i_video.c @@ -0,0 +1,80 @@ +#include "../doomdef.h" +#include "../command.h" +#include "../i_video.h" +#include "../v_video.h" +#include "../screen.h" + +#include "i_video.h" + +#include "utils/Log.h" + +rendermode_t rendermode = render_soft; + +boolean highcolor = false; + +boolean allow_fullscreen = false; + + + +consvar_t cv_vidwait = {"vid_wait", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + +void I_StartupGraphics(void){} + +void I_ShutdownGraphics(void){} + +void I_SetPalette(RGBA_t *palette) +{ + (void)palette; +} + +INT32 VID_NumModes(void) +{ + return 1; +} + +INT32 VID_GetModeForSize(INT32 w, INT32 h) +{ + (void)w; + (void)h; + return 0; +} + +void VID_PrepareModeList(void){} + +INT32 VID_SetMode(INT32 modenum) +{ + vid.modenum = 0; + vid.width = 320; + vid.height = 240; + vid.bpp = 1; + vid.buffer = android_surface; + return 0; +} + +const char *VID_GetModeName(INT32 modenum) +{ + return "A320x240"; +} + +void I_UpdateNoBlit(void){} + +void I_FinishUpdate(void) { + LOGD("FRAME!"); + (*jni_env)->CallVoidMethod(jni_env, androidVideo, videoFrameCB); +} + +void I_UpdateNoVsync(void) {} + +void I_WaitVBL(INT32 count) +{ + (void)count; +} + +void I_ReadScreen(UINT8 *scr) +{ + (void)scr; +} + +void I_BeginRead(void){} + +void I_EndRead(void){} diff --git a/src/android/i_video.h b/src/android/i_video.h new file mode 100644 index 000000000..62fec6654 --- /dev/null +++ b/src/android/i_video.h @@ -0,0 +1,12 @@ +#ifndef _SRB2_ANDROID_VIDEO_ +#define _SRB2_ANDROID_VIDEO_ + +#include + +UINT8 *android_surface; + +JNIEnv* jni_env; +jobject androidVideo; +jmethodID videoFrameCB; + +#endif diff --git a/src/android/jni_main.h b/src/android/jni_main.h new file mode 100644 index 000000000..da7f70331 --- /dev/null +++ b/src/android/jni_main.h @@ -0,0 +1,21 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class org_srb2_nativecode_Main */ + +#ifndef _Included_org_srb2_nativecode_Main +#define _Included_org_srb2_nativecode_Main +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: org_srb2_nativecode_Main + * Method: main + * Signature: (Lorg/srb2/nativecode/Video;)I + */ +JNIEXPORT jint JNICALL Java_org_srb2_nativecode_Main_main + (JNIEnv *, jobject, jobject); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/src/asm_defs.inc b/src/asm_defs.inc new file mode 100644 index 000000000..db59d2c69 --- /dev/null +++ b/src/asm_defs.inc @@ -0,0 +1,43 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Copyright (C) 1999-2014 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file asm_defs.inc +/// \brief must match the C structures + +#ifndef __ASM_DEFS__ +#define __ASM_DEFS__ + +// this makes variables more noticable, +// and make the label match with C code + +// Linux, unlike DOS, has no "_" 19990119 by Kin +// and nasm needs .data code segs under linux 20010210 by metzgermeister +// FIXME: nasm ignores these settings, so I put the macros into the makefile +#ifdef __ELF__ +#define C(label) label +#define CODE_SEG .data +#else +#define C(label) _##label +#define CODE_SEG .text +#endif + +/* This is a more readable way to access the arguments passed from C code */ +/* PLEASE NOTE: it is supposed that all arguments passed from C code are */ +/* 32bit integer (INT32, long, and most *pointers) */ +#define ARG1 8(%ebp) +#define ARG2 12(%ebp) +#define ARG3 16(%ebp) +#define ARG4 20(%ebp) +#define ARG5 24(%ebp) +#define ARG6 28(%ebp) +#define ARG7 32(%ebp) +#define ARG8 36(%ebp) +#define ARG9 40(%ebp) //(c)tm ... Allegro by Shawn Hargreaves. + +#endif diff --git a/src/b_bot.c b/src/b_bot.c new file mode 100644 index 000000000..5e62e58e6 --- /dev/null +++ b/src/b_bot.c @@ -0,0 +1,283 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 2007-2014 by John "JTE" Muniz. +// Copyright (C) 2011-2014 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file b_bot.c +/// \brief Basic bot handling + +#include "doomdef.h" +#include "d_player.h" +#include "g_game.h" +#include "r_main.h" +#include "p_local.h" +#include "b_bot.h" +#include "lua_hook.h" + +// If you want multiple bots, variables like this will +// have to be stuffed in something accessible through player_t. +static boolean lastForward = false; +static boolean lastBlocked = false; +static boolean blocked = false; + +static inline void B_BuildTailsTiccmd(mobj_t *sonic, mobj_t *tails, ticcmd_t *cmd) +{ + boolean forward=false, backward=false, left=false, right=false, jump=false, spin=false; + angle_t angle; + INT16 rangle; + fixed_t dist; + + // We can't follow Sonic if he's not around! + if (!sonic || sonic->health <= 0) + return; + +#ifdef HAVE_BLUA + // Lua can handle it! + if (LUAh_BotAI(sonic, tails, cmd)) + return; +#endif + + if (tails->player->pflags & (PF_MACESPIN|PF_ITEMHANG)) + { + dist = P_AproxDistance(tails->x-sonic->x, tails->y-sonic->y); + if (sonic->player->cmd.buttons & BT_JUMP && sonic->player->pflags & (PF_JUMPED|PF_MACESPIN|PF_ITEMHANG)) + cmd->buttons |= BT_JUMP; + if (sonic->player->pflags & (PF_MACESPIN|PF_ITEMHANG)) + { + cmd->forwardmove = sonic->player->cmd.forwardmove; + cmd->angleturn = abs(tails->angle - sonic->angle)>>16; + if (sonic->angle < tails->angle) + cmd->angleturn = -cmd->angleturn; + } else if (dist > FixedMul(512*FRACUNIT, tails->scale)) + cmd->buttons |= BT_JUMP; + return; + } + + // Gather data about the environment + dist = P_AproxDistance(tails->x-sonic->x, tails->y-sonic->y); + if (tails->player->pflags & PF_STARTDASH) + angle = sonic->angle; + else + angle = R_PointToAngle2(tails->x, tails->y, sonic->x, sonic->y); + + // Decide which direction to turn + angle = (tails->angle - angle); + if (angle < ANGLE_180) { + right = true; // We need to turn right + rangle = AngleFixed(angle)>>FRACBITS; + } else { + left = true; // We need to turn left + rangle = 360-(AngleFixed(angle)>>FRACBITS); + } + + // Decide to move forward if you're finished turning + if (abs(rangle) < 10) { // We're facing the right way? + left = right = false; // Stop turning + forward = true; // and walk forward instead. + } + if (dist < (sonic->radius+tails->radius)*3) // We're close enough? + forward = false; // Stop walking. + + // Decide when to jump + if (!(tails->player->pflags & (PF_JUMPED|PF_JUMPDOWN))) { // We're not jumping yet... + if (forward && lastForward && blocked && lastBlocked) // We've been stopped by a wall or something + jump = true; // Try to jump up + } else if ((tails->player->pflags & (PF_JUMPDOWN|PF_JUMPED)) == (PF_JUMPDOWN|PF_JUMPED)) { // When we're already jumping... + if (lastForward && blocked) // We're still stuck on something? + jump = true; + if (sonic->floorz > tails->floorz) // He's still above us? Jump HIGHER, then! + jump = true; + } + + // Decide when to spin + if (sonic->player->pflags & PF_STARTDASH + && (tails->player->pflags & PF_STARTDASH || (P_AproxDistance(tails->momx, tails->momy) < 2*FRACUNIT && !forward))) + spin = true; + + // Turn the virtual keypresses into ticcmd_t. + B_KeysToTiccmd(tails, cmd, forward, backward, left, right, false, false, jump, spin); + + // Update our status + lastForward = forward; + lastBlocked = blocked; + blocked = false; +} + +void B_BuildTiccmd(player_t *player, ticcmd_t *cmd) +{ + // Can't build a ticcmd if we aren't spawned... + if (!player->mo) + return; + + if (player->playerstate == PST_DEAD) + { + if (B_CheckRespawn(player)) + cmd->buttons |= BT_JUMP; + return; + } + + // Bot AI isn't programmed in analog. + CV_SetValue(&cv_analog2, false); + +#ifdef HAVE_BLUA + // Let Lua scripts build ticcmds + if (LUAh_BotTiccmd(player, cmd)) + return; +#endif + + // We don't have any main character AI, sorry. D: + if (player-players == consoleplayer) + return; + + // Basic Tails AI + B_BuildTailsTiccmd(players[consoleplayer].mo, player->mo, cmd); +} + +void B_KeysToTiccmd(mobj_t *mo, ticcmd_t *cmd, boolean forward, boolean backward, boolean left, boolean right, boolean strafeleft, boolean straferight, boolean jump, boolean spin) +{ + // Turn the virtual keypresses into ticcmd_t. + if (twodlevel || mo->flags2 & MF2_TWOD) { + if (players[consoleplayer].climbing + || mo->player->pflags & PF_GLIDING) { + // Don't mess with bot inputs during these unhandled movement conditions. + // The normal AI doesn't use abilities, so custom AI should be sending us exactly what it wants anyway. + if (forward) + cmd->forwardmove += MAXPLMOVE<>16; + if (backward) + cmd->forwardmove -= MAXPLMOVE<>16; + if (left || strafeleft) + cmd->sidemove -= MAXPLMOVE<>16; + if (right || straferight) + cmd->sidemove += MAXPLMOVE<>16; + } else { + // In standard 2D mode, interpret "forward" as "the way you're facing" and everything else as "the way you're not facing" + if (left || right) + backward = true; + left = right = false; + if (forward) { + if (mo->angle < ANGLE_90 || mo->angle > ANGLE_270) + right = true; + else + left = true; + } else if (backward) { + if (mo->angle < ANGLE_90 || mo->angle > ANGLE_270) + left = true; + else + right = true; + } + if (left || strafeleft) + cmd->sidemove -= MAXPLMOVE<>16; + if (right || straferight) + cmd->sidemove += MAXPLMOVE<>16; + } + } else { + if (forward) + cmd->forwardmove += MAXPLMOVE<>16; + if (backward) + cmd->forwardmove -= MAXPLMOVE<>16; + if (left) + cmd->angleturn += 1280; + if (right) + cmd->angleturn -= 1280; + if (strafeleft) + cmd->sidemove -= MAXPLMOVE<>16; + if (straferight) + cmd->sidemove += MAXPLMOVE<>16; + } + if (jump) + cmd->buttons |= BT_JUMP; + if (spin) + cmd->buttons |= BT_USE; +} + +void B_MoveBlocked(player_t *player) +{ + (void)player; + blocked = true; +} + +boolean B_CheckRespawn(player_t *player) +{ + mobj_t *sonic = players[consoleplayer].mo; + mobj_t *tails = player->mo; + + // We can't follow Sonic if he's not around! + if (!sonic || sonic->health <= 0) + return false; + + // Check if Sonic is busy first. + // If he's doing any of these things, he probably doesn't want to see us. + if (sonic->player->pflags & (PF_ROPEHANG|PF_GLIDING|PF_CARRIED|PF_SLIDING|PF_ITEMHANG|PF_MACESPIN|PF_NIGHTSMODE) + || (sonic->player->panim != PA_IDLE && sonic->player->panim != PA_WALK)) + return false; + + // Low ceiling, do not want! + if (sonic->ceilingz - sonic->z < 2*sonic->height) + return false; + + // If you're dead, wait a few seconds to respawn. + if (player->playerstate == PST_DEAD) { + if (player->deadtimer > 4*TICRATE) + return true; + return false; + } + + // If you can't see Sonic, I guess we should? + if (!P_CheckSight(sonic, tails) && P_AproxDistance(P_AproxDistance(tails->x-sonic->x, tails->y-sonic->y), tails->z-sonic->z) > FixedMul(1024*FRACUNIT, tails->scale)) + return true; + return false; +} + +void B_RespawnBot(INT32 playernum) +{ + player_t *player = &players[playernum]; + fixed_t x,y,z; + mobj_t *sonic = players[consoleplayer].mo; + mobj_t *tails; + + if (!sonic || sonic->health <= 0) + return; + + player->bot = 1; + P_SpawnPlayer(playernum); + tails = player->mo; + + x = sonic->x; + y = sonic->y; + if (sonic->eflags & MFE_VERTICALFLIP) { + tails->eflags |= MFE_VERTICALFLIP; + z = sonic->z - FixedMul(512*FRACUNIT,sonic->scale); + if (z < sonic->floorz) + z = sonic->floorz; + } else { + z = sonic->z + sonic->height + FixedMul(512*FRACUNIT,sonic->scale); + if (z > sonic->ceilingz - sonic->height) + z = sonic->ceilingz - sonic->height; + } + + if (sonic->flags2 & MF2_OBJECTFLIP) + tails->flags2 |= MF2_OBJECTFLIP; + if (sonic->flags2 & MF2_TWOD) + tails->flags2 |= MF2_TWOD; + if (sonic->eflags & MFE_UNDERWATER) + tails->eflags |= MFE_UNDERWATER; + player->powers[pw_underwater] = sonic->player->powers[pw_underwater]; + player->powers[pw_spacetime] = sonic->player->powers[pw_spacetime]; + player->powers[pw_gravityboots] = sonic->player->powers[pw_gravityboots]; + player->powers[pw_nocontrol] = sonic->player->powers[pw_nocontrol]; + + P_TeleportMove(tails, x, y, z); + if (player->charability == CA_FLY) + { + P_SetPlayerMobjState(tails, S_PLAY_ABL1); + tails->player->powers[pw_tailsfly] = (UINT16)-1; + } + else + P_SetPlayerMobjState(tails, S_PLAY_FALL1); + P_SetScale(tails, sonic->scale); + tails->destscale = sonic->destscale; +} diff --git a/src/b_bot.h b/src/b_bot.h new file mode 100644 index 000000000..1bb546ec3 --- /dev/null +++ b/src/b_bot.h @@ -0,0 +1,17 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 2007-2014 by John "JTE" Muniz. +// Copyright (C) 2012-2014 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file b_bot.h +/// \brief Basic bot handling + +void B_BuildTiccmd(player_t *player, ticcmd_t *cmd); +void B_KeysToTiccmd(mobj_t *mo, ticcmd_t *cmd, boolean forward, boolean backward, boolean left, boolean right, boolean strafeleft, boolean straferight, boolean jump, boolean spin); +boolean B_CheckRespawn(player_t *player); +void B_MoveBlocked(player_t *player); +void B_RespawnBot(INT32 playernum); diff --git a/src/blua/BLUA.htm b/src/blua/BLUA.htm new file mode 100644 index 000000000..69321c865 --- /dev/null +++ b/src/blua/BLUA.htm @@ -0,0 +1,35 @@ + + +BLUA: bastardized lua + + +

BLUA: bastardized lua #5

+
+

+Welcome to my personal lua bastardization - an effort to make lua syntax as bloated and useless like perl's or pythons. There are currently 13 +patches, available either as separate or one big un-#ifdefable patch, depending on your needs. +


+NEW: Lua 5.1.4 port over here
+All of the following patches merged (without #ifdefs): merged.diff
+All of the following patches merged (with #ifdefs unifdef friendly): blua5.diff
+ +
Name/ifdef Description syntax compatible bytecode compatible author +
ALTCMP_PATCH != equals to ~= yep yep kt +
BITOPS_PATCH and,or,xor,shl,shr,not => &,|,^^,<<,>>,~ yep nope kt (orig. by RISClua) +
BREAKN_PATCH php-like break N (multiscope break)yep yep kt +
CONTINUE_PATCH continue statement yep yep AKa +
DO_PATCH do ... end equals to function() .. endyepyepAKa +
LITERALS_PATCH hex(\xABCD) unicode(\uXXXX) literalsyep yep AKa +
OPTDO_PATCH optional 'do' after for/whileyep yep kt (orig. by Eric Tetz) +
OPTTHEN_PATCH optional 'then' after ifyep yep kt (orig. by Eric Tetz) +
PSEUDO_PATCH x.y,a.b = $2+1,$1+1 equals to x.y,a.b = a.b+1,x.y+1 etcyep yep rici +
PUDATA_PATCH lua_pushuserdata()yep yep kt +
REFSTR_PATCH print("Hello from \$_LUA_VERSION\ ..") equals print("Hello from ".._LUA_VERSION.." ..")yep yep kt +
STRHOOK_PATCH Ever wanted to get mmap()ed memory from lua_tolstring()?yep yep kt +
USEDINDEX_PATCH __usedindex, like __newindex but for existing keysyepyep kt (orig. by Christopher Dunn) +
+USEDINDEX_PATCH has been reported to be broken with LuaJIT. BITOPS_PATCH, PSEUDO_PATCH, REFSTR_PATCH, OPTDO_PATCH, OPTTHEN_PATCH reported to work with LuaJIT. +
+Found a bug or have some cool patches? http://leet.cz + + diff --git a/src/blua/Makefile.cfg b/src/blua/Makefile.cfg new file mode 100644 index 000000000..e3fb3df46 --- /dev/null +++ b/src/blua/Makefile.cfg @@ -0,0 +1,51 @@ +ifdef UNIXCOMMON +LUA_CFLAGS+=-DLUA_USE_POSIX +endif +ifdef LINUX +LUA_CFLAGS+=-DLUA_USE_POSIX +endif +ifdef GCC43 +ifndef GCC44 +WFLAGS+=-Wno-logical-op +endif +endif + +OPTS+=-DHAVE_BLUA + +OBJS:=$(OBJS) \ + $(OBJDIR)/lapi.o \ + $(OBJDIR)/lbaselib.o \ + $(OBJDIR)/ldo.o \ + $(OBJDIR)/lfunc.o \ + $(OBJDIR)/linit.o \ + $(OBJDIR)/llex.o \ + $(OBJDIR)/lmem.o \ + $(OBJDIR)/lobject.o \ + $(OBJDIR)/lstate.o \ + $(OBJDIR)/lstrlib.o \ + $(OBJDIR)/ltablib.o \ + $(OBJDIR)/lundump.o \ + $(OBJDIR)/lzio.o \ + $(OBJDIR)/lauxlib.o \ + $(OBJDIR)/lcode.o \ + $(OBJDIR)/ldebug.o \ + $(OBJDIR)/ldump.o \ + $(OBJDIR)/lgc.o \ + $(OBJDIR)/lopcodes.o \ + $(OBJDIR)/lparser.o \ + $(OBJDIR)/lstring.o \ + $(OBJDIR)/ltable.o \ + $(OBJDIR)/ltm.o \ + $(OBJDIR)/lvm.o \ + $(OBJDIR)/lua_script.o \ + $(OBJDIR)/lua_baselib.o \ + $(OBJDIR)/lua_mathlib.o \ + $(OBJDIR)/lua_hooklib.o \ + $(OBJDIR)/lua_consolelib.o \ + $(OBJDIR)/lua_infolib.o \ + $(OBJDIR)/lua_mobjlib.o \ + $(OBJDIR)/lua_playerlib.o \ + $(OBJDIR)/lua_skinlib.o \ + $(OBJDIR)/lua_thinkerlib.o \ + $(OBJDIR)/lua_maplib.o \ + $(OBJDIR)/lua_hudlib.o diff --git a/src/blua/lapi.c b/src/blua/lapi.c new file mode 100644 index 000000000..2d837057c --- /dev/null +++ b/src/blua/lapi.c @@ -0,0 +1,1110 @@ +/* +** $Id: lapi.c,v 2.55.1.5 2008/07/04 18:41:18 roberto Exp $ +** Lua API +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include +#include + +#define lapi_c +#define LUA_CORE + +#include "lua.h" + +#include "lapi.h" +#include "ldebug.h" +#include "ldo.h" +#include "lfunc.h" +#include "lgc.h" +#include "lmem.h" +#include "lobject.h" +#include "lstate.h" +#include "lstring.h" +#include "ltable.h" +#include "ltm.h" +#include "lundump.h" +#include "lvm.h" + + + +const char lua_ident[] = + "$Lua: " LUA_RELEASE " " LUA_COPYRIGHT " $\n" + "$Authors: " LUA_AUTHORS " $\n" + "$URL: www.lua.org $\n"; + + + +#define api_checknelems(L, n) api_check(L, (n) <= (L->top - L->base)) + +#define api_checkvalidindex(L, i) api_check(L, (i) != luaO_nilobject) + +#define api_incr_top(L) {api_check(L, L->top < L->ci->top); L->top++;} + + + +static TValue *index2adr (lua_State *L, int idx) { + if (idx > 0) { + TValue *o = L->base + (idx - 1); + api_check(L, idx <= L->ci->top - L->base); + if (o >= L->top) return cast(TValue *, luaO_nilobject); + else return o; + } + else if (idx > LUA_REGISTRYINDEX) { + api_check(L, idx != 0 && -idx <= L->top - L->base); + return L->top + idx; + } + else switch (idx) { /* pseudo-indices */ + case LUA_REGISTRYINDEX: return registry(L); + case LUA_ENVIRONINDEX: { + Closure *func = curr_func(L); + sethvalue(L, &L->env, func->c.env); + return &L->env; + } + case LUA_GLOBALSINDEX: return gt(L); + default: { + Closure *func = curr_func(L); + idx = LUA_GLOBALSINDEX - idx; + return (idx <= func->c.nupvalues) + ? &func->c.upvalue[idx-1] + : cast(TValue *, luaO_nilobject); + } + } +} + + +static Table *getcurrenv (lua_State *L) { + if (L->ci == L->base_ci) /* no enclosing function? */ + return hvalue(gt(L)); /* use global table as environment */ + else { + Closure *func = curr_func(L); + return func->c.env; + } +} + + +void luaA_pushobject (lua_State *L, const TValue *o) { + setobj2s(L, L->top, o); + api_incr_top(L); +} + + +LUA_API int lua_checkstack (lua_State *L, int size) { + int res = 1; + lua_lock(L); + if (size > LUAI_MAXCSTACK || (L->top - L->base + size) > LUAI_MAXCSTACK) + res = 0; /* stack overflow */ + else if (size > 0) { + luaD_checkstack(L, size); + if (L->ci->top < L->top + size) + L->ci->top = L->top + size; + } + lua_unlock(L); + return res; +} + + +LUA_API void lua_xmove (lua_State *from, lua_State *to, int n) { + int i; + if (from == to) return; + lua_lock(to); + api_checknelems(from, n); + api_check(from, G(from) == G(to)); + api_check(from, to->ci->top - to->top >= n); + from->top -= n; + for (i = 0; i < n; i++) { + setobj2s(to, to->top++, from->top + i); + } + lua_unlock(to); +} + + +LUA_API void lua_setlevel (lua_State *from, lua_State *to) { + to->nCcalls = from->nCcalls; +} + + +LUA_API lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf) { + lua_CFunction old; + lua_lock(L); + old = G(L)->panic; + G(L)->panic = panicf; + lua_unlock(L); + return old; +} + + +LUA_API lua_State *lua_newthread (lua_State *L) { + lua_State *L1; + lua_lock(L); + luaC_checkGC(L); + L1 = luaE_newthread(L); + setthvalue(L, L->top, L1); + api_incr_top(L); + lua_unlock(L); + luai_userstatethread(L, L1); + return L1; +} + + + +/* +** basic stack manipulation +*/ + + +LUA_API int lua_gettop (lua_State *L) { + return cast_int(L->top - L->base); +} + + +LUA_API void lua_settop (lua_State *L, int idx) { + lua_lock(L); + if (idx >= 0) { + api_check(L, idx <= L->stack_last - L->base); + while (L->top < L->base + idx) + setnilvalue(L->top++); + L->top = L->base + idx; + } + else { + api_check(L, -(idx+1) <= (L->top - L->base)); + L->top += idx+1; /* `subtract' index (index is negative) */ + } + lua_unlock(L); +} + + +LUA_API void lua_remove (lua_State *L, int idx) { + StkId p; + lua_lock(L); + p = index2adr(L, idx); + api_checkvalidindex(L, p); + while (++p < L->top) setobjs2s(L, p-1, p); + L->top--; + lua_unlock(L); +} + + +LUA_API void lua_insert (lua_State *L, int idx) { + StkId p; + StkId q; + lua_lock(L); + p = index2adr(L, idx); + api_checkvalidindex(L, p); + for (q = L->top; q>p; q--) setobjs2s(L, q, q-1); + setobjs2s(L, p, L->top); + lua_unlock(L); +} + + +LUA_API void lua_replace (lua_State *L, int idx) { + StkId o; + lua_lock(L); + /* explicit test for incompatible code */ + if (idx == LUA_ENVIRONINDEX && L->ci == L->base_ci) + luaG_runerror(L, "no calling environment"); + api_checknelems(L, 1); + o = index2adr(L, idx); + api_checkvalidindex(L, o); + if (idx == LUA_ENVIRONINDEX) { + Closure *func = curr_func(L); + api_check(L, ttistable(L->top - 1)); + func->c.env = hvalue(L->top - 1); + luaC_barrier(L, func, L->top - 1); + } + else { + setobj(L, o, L->top - 1); + if (idx < LUA_GLOBALSINDEX) /* function upvalue? */ + luaC_barrier(L, curr_func(L), L->top - 1); + } + L->top--; + lua_unlock(L); +} + + +LUA_API void lua_pushvalue (lua_State *L, int idx) { + lua_lock(L); + setobj2s(L, L->top, index2adr(L, idx)); + api_incr_top(L); + lua_unlock(L); +} + + + +/* +** access functions (stack -> C) +*/ + + +LUA_API int lua_type (lua_State *L, int idx) { + StkId o = index2adr(L, idx); + return (o == luaO_nilobject) ? LUA_TNONE : ttype(o); +} + + +LUA_API const char *lua_typename (lua_State *L, int t) { + UNUSED(L); + return (t == LUA_TNONE) ? "no value" : luaT_typenames[t]; +} + + +LUA_API int lua_iscfunction (lua_State *L, int idx) { + StkId o = index2adr(L, idx); + return iscfunction(o); +} + + +LUA_API int lua_isnumber (lua_State *L, int idx) { + TValue n; + const TValue *o = index2adr(L, idx); + return tonumber(o, &n); +} + + +LUA_API int lua_isstring (lua_State *L, int idx) { + int t = lua_type(L, idx); + return (t == LUA_TSTRING || t == LUA_TNUMBER); +} + + +LUA_API int lua_isuserdata (lua_State *L, int idx) { + const TValue *o = index2adr(L, idx); + return (ttisuserdata(o) || ttislightuserdata(o)); +} + + +LUA_API int lua_rawequal (lua_State *L, int index1, int index2) { + StkId o1 = index2adr(L, index1); + StkId o2 = index2adr(L, index2); + return (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0 + : luaO_rawequalObj(o1, o2); +} + + +LUA_API int lua_equal (lua_State *L, int index1, int index2) { + StkId o1, o2; + int i; + lua_lock(L); /* may call tag method */ + o1 = index2adr(L, index1); + o2 = index2adr(L, index2); + i = (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0 : equalobj(L, o1, o2); + lua_unlock(L); + return i; +} + + +LUA_API int lua_lessthan (lua_State *L, int index1, int index2) { + StkId o1, o2; + int i; + lua_lock(L); /* may call tag method */ + o1 = index2adr(L, index1); + o2 = index2adr(L, index2); + i = (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0 + : luaV_lessthan(L, o1, o2); + lua_unlock(L); + return i; +} + + + +LUA_API lua_Number lua_tonumber (lua_State *L, int idx) { + TValue n; + const TValue *o = index2adr(L, idx); + if (tonumber(o, &n)) + return nvalue(o); + else + return 0; +} + + +LUA_API lua_Integer lua_tointeger (lua_State *L, int idx) { + TValue n; + const TValue *o = index2adr(L, idx); + if (tonumber(o, &n)) { + lua_Integer res; + lua_Number num = nvalue(o); + lua_number2integer(res, num); + return res; + } + else + return 0; +} + + +LUA_API int lua_toboolean (lua_State *L, int idx) { + const TValue *o = index2adr(L, idx); + return !l_isfalse(o); +} + +typedef const char* (*Pshook) (lua_State *L, int, size_t *); + +struct PshookS { /* data to `shook' */ + Pshook func; + void *ud; +}; + + +LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) { + StkId o = index2adr(L, idx); + if (!ttisstring(o)) { + const TValue *t; + if ((ttisuserdata(o)) && ((t = luaT_gettmbyobj(L, o, TM_STRHOOK)) != NULL) && (ttislightuserdata(t))) { + struct PshookS *shook = cast(struct PshookS *, pvalue(t)); + return shook->func(L, idx, len); + } + lua_lock(L); /* `luaV_tostring' may create a new string */ + if (!luaV_tostring(L, o)) { /* conversion failed? */ + if (len != NULL) *len = 0; + lua_unlock(L); + return NULL; + } + luaC_checkGC(L); + o = index2adr(L, idx); /* previous call may reallocate the stack */ + lua_unlock(L); + } + if (len != NULL) *len = tsvalue(o)->len; + return svalue(o); +} + + +LUA_API size_t lua_objlen (lua_State *L, int idx) { + StkId o = index2adr(L, idx); + switch (ttype(o)) { + case LUA_TSTRING: return tsvalue(o)->len; + case LUA_TUSERDATA: return uvalue(o)->len; + case LUA_TTABLE: return luaH_getn(hvalue(o)); + case LUA_TNUMBER: { + size_t l; + lua_lock(L); /* `luaV_tostring' may create a new string */ + l = (luaV_tostring(L, o) ? tsvalue(o)->len : 0); + lua_unlock(L); + return l; + } + default: return 0; + } +} + + +LUA_API lua_CFunction lua_tocfunction (lua_State *L, int idx) { + StkId o = index2adr(L, idx); + return (!iscfunction(o)) ? NULL : clvalue(o)->c.f; +} + + +LUA_API void *lua_touserdata (lua_State *L, int idx) { + StkId o = index2adr(L, idx); + switch (ttype(o)) { + case LUA_TUSERDATA: return (rawuvalue(o) + 1); + case LUA_TLIGHTUSERDATA: return pvalue(o); + default: return NULL; + } +} + + +LUA_API lua_State *lua_tothread (lua_State *L, int idx) { + StkId o = index2adr(L, idx); + return (!ttisthread(o)) ? NULL : thvalue(o); +} + + +LUA_API const void *lua_topointer (lua_State *L, int idx) { + StkId o = index2adr(L, idx); + switch (ttype(o)) { + case LUA_TTABLE: return hvalue(o); + case LUA_TFUNCTION: return clvalue(o); + case LUA_TTHREAD: return thvalue(o); + case LUA_TUSERDATA: + case LUA_TLIGHTUSERDATA: + return lua_touserdata(L, idx); + default: return NULL; + } +} + + + +/* +** push functions (C -> stack) +*/ + + +LUA_API void lua_pushnil (lua_State *L) { + lua_lock(L); + setnilvalue(L->top); + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API void lua_pushnumber (lua_State *L, lua_Number n) { + lua_lock(L); + setnvalue(L->top, n); + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) { + lua_lock(L); + setnvalue(L->top, cast_num(n)); + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len) { + lua_lock(L); + luaC_checkGC(L); + setsvalue2s(L, L->top, luaS_newlstr(L, s, len)); + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API void lua_pushstring (lua_State *L, const char *s) { + if (s == NULL) + lua_pushnil(L); + else + lua_pushlstring(L, s, strlen(s)); +} + + +LUA_API const char *lua_pushvfstring (lua_State *L, const char *fmt, + va_list argp) { + const char *ret; + lua_lock(L); + luaC_checkGC(L); + ret = luaO_pushvfstring(L, fmt, argp); + lua_unlock(L); + return ret; +} + + +LUA_API const char *lua_pushfstring (lua_State *L, const char *fmt, ...) { + const char *ret; + va_list argp; + lua_lock(L); + luaC_checkGC(L); + va_start(argp, fmt); + ret = luaO_pushvfstring(L, fmt, argp); + va_end(argp); + lua_unlock(L); + return ret; +} + + +LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) { + Closure *cl; + lua_lock(L); + luaC_checkGC(L); + api_checknelems(L, n); + cl = luaF_newCclosure(L, n, getcurrenv(L)); + cl->c.f = fn; + L->top -= n; + while (n--) + setobj2n(L, &cl->c.upvalue[n], L->top+n); + setclvalue(L, L->top, cl); + lua_assert(iswhite(obj2gco(cl))); + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API void lua_pushboolean (lua_State *L, int b) { + lua_lock(L); + setbvalue(L->top, (b != 0)); /* ensure that true is 1 */ + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API void lua_pushlightuserdata (lua_State *L, void *p) { + lua_lock(L); + setpvalue(L->top, p); + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API int lua_pushthread (lua_State *L) { + lua_lock(L); + setthvalue(L, L->top, L); + api_incr_top(L); + lua_unlock(L); + return (G(L)->mainthread == L); +} + + + +/* +** get functions (Lua -> stack) +*/ + + +LUA_API void lua_gettable (lua_State *L, int idx) { + StkId t; + lua_lock(L); + t = index2adr(L, idx); + api_checkvalidindex(L, t); + luaV_gettable(L, t, L->top - 1, L->top - 1); + lua_unlock(L); +} + + +LUA_API void lua_getfield (lua_State *L, int idx, const char *k) { + StkId t; + TValue key; + lua_lock(L); + t = index2adr(L, idx); + api_checkvalidindex(L, t); + setsvalue(L, &key, luaS_new(L, k)); + luaV_gettable(L, t, &key, L->top); + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API void lua_rawget (lua_State *L, int idx) { + StkId t; + lua_lock(L); + t = index2adr(L, idx); + api_check(L, ttistable(t)); + setobj2s(L, L->top - 1, luaH_get(hvalue(t), L->top - 1)); + lua_unlock(L); +} + + +LUA_API void lua_rawgeti (lua_State *L, int idx, int n) { + StkId o; + lua_lock(L); + o = index2adr(L, idx); + api_check(L, ttistable(o)); + setobj2s(L, L->top, luaH_getnum(hvalue(o), n)); + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API void lua_createtable (lua_State *L, int narray, int nrec) { + lua_lock(L); + luaC_checkGC(L); + sethvalue(L, L->top, luaH_new(L, narray, nrec)); + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API int lua_getmetatable (lua_State *L, int objindex) { + const TValue *obj; + Table *mt = NULL; + int res; + lua_lock(L); + obj = index2adr(L, objindex); + switch (ttype(obj)) { + case LUA_TTABLE: + mt = hvalue(obj)->metatable; + break; + case LUA_TUSERDATA: + mt = uvalue(obj)->metatable; + break; + default: + mt = G(L)->mt[ttype(obj)]; + break; + } + if (mt == NULL) + res = 0; + else { + sethvalue(L, L->top, mt); + api_incr_top(L); + res = 1; + } + lua_unlock(L); + return res; +} + + +LUA_API void lua_getfenv (lua_State *L, int idx) { + StkId o; + lua_lock(L); + o = index2adr(L, idx); + api_checkvalidindex(L, o); + switch (ttype(o)) { + case LUA_TFUNCTION: + sethvalue(L, L->top, clvalue(o)->c.env); + break; + case LUA_TUSERDATA: + sethvalue(L, L->top, uvalue(o)->env); + break; + case LUA_TTHREAD: + setobj2s(L, L->top, gt(thvalue(o))); + break; + default: + setnilvalue(L->top); + break; + } + api_incr_top(L); + lua_unlock(L); +} + + +/* +** set functions (stack -> Lua) +*/ + + +LUA_API void lua_settable (lua_State *L, int idx) { + StkId t; + lua_lock(L); + api_checknelems(L, 2); + t = index2adr(L, idx); + api_checkvalidindex(L, t); + luaV_settable(L, t, L->top - 2, L->top - 1); + L->top -= 2; /* pop index and value */ + lua_unlock(L); +} + + +LUA_API void lua_setfield (lua_State *L, int idx, const char *k) { + StkId t; + TValue key; + lua_lock(L); + api_checknelems(L, 1); + t = index2adr(L, idx); + api_checkvalidindex(L, t); + setsvalue(L, &key, luaS_new(L, k)); + luaV_settable(L, t, &key, L->top - 1); + L->top--; /* pop value */ + lua_unlock(L); +} + + +LUA_API void lua_rawset (lua_State *L, int idx) { + StkId t; + lua_lock(L); + api_checknelems(L, 2); + t = index2adr(L, idx); + api_check(L, ttistable(t)); + setobj2t(L, luaH_set(L, hvalue(t), L->top-2), L->top-1); + luaC_barriert(L, hvalue(t), L->top-1); + L->top -= 2; + lua_unlock(L); +} + + +LUA_API void lua_rawseti (lua_State *L, int idx, int n) { + StkId o; + lua_lock(L); + api_checknelems(L, 1); + o = index2adr(L, idx); + api_check(L, ttistable(o)); + setobj2t(L, luaH_setnum(L, hvalue(o), n), L->top-1); + luaC_barriert(L, hvalue(o), L->top-1); + L->top--; + lua_unlock(L); +} + + +LUA_API int lua_setmetatable (lua_State *L, int objindex) { + TValue *obj; + Table *mt; + lua_lock(L); + api_checknelems(L, 1); + obj = index2adr(L, objindex); + api_checkvalidindex(L, obj); + if (ttisnil(L->top - 1)) + mt = NULL; + else { + api_check(L, ttistable(L->top - 1)); + mt = hvalue(L->top - 1); + } + switch (ttype(obj)) { + case LUA_TTABLE: { + hvalue(obj)->metatable = mt; + if (mt) + luaC_objbarriert(L, hvalue(obj), mt); + break; + } + case LUA_TUSERDATA: { + uvalue(obj)->metatable = mt; + if (mt) + luaC_objbarrier(L, rawuvalue(obj), mt); + break; + } + default: { + G(L)->mt[ttype(obj)] = mt; + break; + } + } + L->top--; + lua_unlock(L); + return 1; +} + + +LUA_API int lua_setfenv (lua_State *L, int idx) { + StkId o; + int res = 1; + lua_lock(L); + api_checknelems(L, 1); + o = index2adr(L, idx); + api_checkvalidindex(L, o); + api_check(L, ttistable(L->top - 1)); + switch (ttype(o)) { + case LUA_TFUNCTION: + clvalue(o)->c.env = hvalue(L->top - 1); + break; + case LUA_TUSERDATA: + uvalue(o)->env = hvalue(L->top - 1); + break; + case LUA_TTHREAD: + sethvalue(L, gt(thvalue(o)), hvalue(L->top - 1)); + break; + default: + res = 0; + break; + } + if (res) luaC_objbarrier(L, gcvalue(o), hvalue(L->top - 1)); + L->top--; + lua_unlock(L); + return res; +} + + +/* +** `load' and `call' functions (run Lua code) +*/ + + +#define adjustresults(L,nres) \ + { if (nres == LUA_MULTRET && L->top >= L->ci->top) L->ci->top = L->top; } + + +#define checkresults(L,na,nr) \ + api_check(L, (nr) == LUA_MULTRET || (L->ci->top - L->top >= (nr) - (na))) + + +LUA_API void lua_call (lua_State *L, int nargs, int nresults) { + StkId func; + lua_lock(L); + api_checknelems(L, nargs+1); + checkresults(L, nargs, nresults); + func = L->top - (nargs+1); + luaD_call(L, func, nresults); + adjustresults(L, nresults); + lua_unlock(L); +} + + + +/* +** Execute a protected call. +*/ +struct CallS { /* data to `f_call' */ + StkId func; + int nresults; +}; + + +static void f_call (lua_State *L, void *ud) { + struct CallS *c = cast(struct CallS *, ud); + luaD_call(L, c->func, c->nresults); +} + + + +LUA_API int lua_pcall (lua_State *L, int nargs, int nresults, int errfunc) { + struct CallS c; + int status; + ptrdiff_t func; + lua_lock(L); + api_checknelems(L, nargs+1); + checkresults(L, nargs, nresults); + if (errfunc == 0) + func = 0; + else { + StkId o = index2adr(L, errfunc); + api_checkvalidindex(L, o); + func = savestack(L, o); + } + c.func = L->top - (nargs+1); /* function to be called */ + c.nresults = nresults; + status = luaD_pcall(L, f_call, &c, savestack(L, c.func), func); + adjustresults(L, nresults); + lua_unlock(L); + return status; +} + + +/* +** Execute a protected C call. +*/ +struct CCallS { /* data to `f_Ccall' */ + lua_CFunction func; + void *ud; +}; + + +static void f_Ccall (lua_State *L, void *ud) { + struct CCallS *c = cast(struct CCallS *, ud); + Closure *cl; + cl = luaF_newCclosure(L, 0, getcurrenv(L)); + cl->c.f = c->func; + setclvalue(L, L->top, cl); /* push function */ + api_incr_top(L); + setpvalue(L->top, c->ud); /* push only argument */ + api_incr_top(L); + luaD_call(L, L->top - 2, 0); +} + + +LUA_API int lua_cpcall (lua_State *L, lua_CFunction func, void *ud) { + struct CCallS c; + int status; + lua_lock(L); + c.func = func; + c.ud = ud; + status = luaD_pcall(L, f_Ccall, &c, savestack(L, L->top), 0); + lua_unlock(L); + return status; +} + + +LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data, + const char *chunkname) { + ZIO z; + int status; + lua_lock(L); + if (!chunkname) chunkname = "?"; + luaZ_init(L, &z, reader, data); + status = luaD_protectedparser(L, &z, chunkname); + lua_unlock(L); + return status; +} + + +#ifndef LUA_STRIPPING +#define LUA_STRIPPING 0 +#endif +LUA_API int lua_dump (lua_State *L, lua_Writer writer, void *data) { + int status; + TValue *o; + lua_lock(L); + api_checknelems(L, 1); + o = L->top - 1; + if (isLfunction(o)) + status = luaU_dump(L, clvalue(o)->l.p, writer, data, LUA_STRIPPING); + else + status = 1; + lua_unlock(L); + return status; +} +#undef LUA_STRIPPING + + +LUA_API int lua_status (lua_State *L) { + return L->status; +} + + +/* +** Garbage-collection function +*/ + +LUA_API int lua_gc (lua_State *L, int what, int data) { + int res = 0; + global_State *g; + lua_lock(L); + g = G(L); + switch (what) { + case LUA_GCSTOP: { + g->GCthreshold = MAX_LUMEM; + break; + } + case LUA_GCRESTART: { + g->GCthreshold = g->totalbytes; + break; + } + case LUA_GCCOLLECT: { + luaC_fullgc(L); + break; + } + case LUA_GCCOUNT: { + /* GC values are expressed in Kbytes: #bytes/2^10 */ + res = cast_int(g->totalbytes >> 10); + break; + } + case LUA_GCCOUNTB: { + res = cast_int(g->totalbytes & 0x3ff); + break; + } + case LUA_GCSTEP: { + lu_mem a = (cast(lu_mem, data) << 10); + if (a <= g->totalbytes) + g->GCthreshold = g->totalbytes - a; + else + g->GCthreshold = 0; + while (g->GCthreshold <= g->totalbytes) { + luaC_step(L); + if (g->gcstate == GCSpause) { /* end of cycle? */ + res = 1; /* signal it */ + break; + } + } + break; + } + case LUA_GCSETPAUSE: { + res = g->gcpause; + g->gcpause = data; + break; + } + case LUA_GCSETSTEPMUL: { + res = g->gcstepmul; + g->gcstepmul = data; + break; + } + default: res = -1; /* invalid option */ + } + lua_unlock(L); + return res; +} + + + +/* +** miscellaneous functions +*/ + + +LUA_API int lua_error (lua_State *L) { + lua_lock(L); + api_checknelems(L, 1); + luaG_errormsg(L); + lua_unlock(L); + return 0; /* to avoid warnings */ +} + + +LUA_API int lua_next (lua_State *L, int idx) { + StkId t; + int more; + lua_lock(L); + t = index2adr(L, idx); + api_check(L, ttistable(t)); + more = luaH_next(L, hvalue(t), L->top - 1); + if (more) { + api_incr_top(L); + } + else /* no more elements */ + L->top -= 1; /* remove key */ + lua_unlock(L); + return more; +} + + +LUA_API void lua_concat (lua_State *L, int n) { + lua_lock(L); + api_checknelems(L, n); + if (n >= 2) { + luaC_checkGC(L); + luaV_concat(L, n, cast_int(L->top - L->base) - 1); + L->top -= (n-1); + } + else if (n == 0) { /* push empty string */ + setsvalue2s(L, L->top, luaS_newlstr(L, "", 0)); + api_incr_top(L); + } + /* else n == 1; nothing to do */ + lua_unlock(L); +} + + +LUA_API lua_Alloc lua_getallocf (lua_State *L, void **ud) { + lua_Alloc f; + lua_lock(L); + if (ud) *ud = G(L)->ud; + f = G(L)->frealloc; + lua_unlock(L); + return f; +} + + +LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud) { + lua_lock(L); + G(L)->ud = ud; + G(L)->frealloc = f; + lua_unlock(L); +} + + +LUA_API void *lua_newuserdata (lua_State *L, size_t size) { + Udata *u; + lua_lock(L); + luaC_checkGC(L); + u = luaS_newudata(L, size, getcurrenv(L)); + setuvalue(L, L->top, u); + api_incr_top(L); + lua_unlock(L); + return u + 1; +} + + + +LUA_API void lua_pushuserdata(lua_State *L, void *p) +{ + lua_lock(L); + luaC_checkGC(L); + setuvalue(L, L->top, ((Udata *)(p))-1); + api_incr_top(L); + lua_unlock(L); +} + +static const char *aux_upvalue (StkId fi, int n, TValue **val) { + Closure *f; + if (!ttisfunction(fi)) return NULL; + f = clvalue(fi); + if (f->c.isC) { + if (!(1 <= n && n <= f->c.nupvalues)) return NULL; + *val = &f->c.upvalue[n-1]; + return ""; + } + else { + Proto *p = f->l.p; + if (!(1 <= n && n <= p->sizeupvalues)) return NULL; + *val = f->l.upvals[n-1]->v; + return getstr(p->upvalues[n-1]); + } +} + + +LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n) { + const char *name; + TValue *val; + lua_lock(L); + name = aux_upvalue(index2adr(L, funcindex), n, &val); + if (name) { + setobj2s(L, L->top, val); + api_incr_top(L); + } + lua_unlock(L); + return name; +} + + +LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) { + const char *name; + TValue *val; + StkId fi; + lua_lock(L); + fi = index2adr(L, funcindex); + api_checknelems(L, 1); + name = aux_upvalue(fi, n, &val); + if (name) { + L->top--; + setobj(L, val, L->top); + luaC_barrier(L, clvalue(fi), L->top); + } + lua_unlock(L); + return name; +} diff --git a/src/blua/lapi.h b/src/blua/lapi.h new file mode 100644 index 000000000..2c3fab244 --- /dev/null +++ b/src/blua/lapi.h @@ -0,0 +1,16 @@ +/* +** $Id: lapi.h,v 2.2.1.1 2007/12/27 13:02:25 roberto Exp $ +** Auxiliary functions from Lua API +** See Copyright Notice in lua.h +*/ + +#ifndef lapi_h +#define lapi_h + + +#include "lobject.h" + + +LUAI_FUNC void luaA_pushobject (lua_State *L, const TValue *o); + +#endif diff --git a/src/blua/lauxlib.c b/src/blua/lauxlib.c new file mode 100644 index 000000000..c43cefd1e --- /dev/null +++ b/src/blua/lauxlib.c @@ -0,0 +1,657 @@ +/* +** $Id: lauxlib.c,v 1.159.1.3 2008/01/21 13:20:51 roberto Exp $ +** Auxiliary functions for building Lua libraries +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include +#include +#include +#include + + +/* This file uses only the official API of Lua. +** Any function declared here could be written as an application function. +*/ + +#define lauxlib_c +#define LUA_LIB + +#include "lua.h" + +#include "lauxlib.h" + + +#define FREELIST_REF 0 /* free list of references */ + + +/* convert a stack index to positive */ +#define abs_index(L, i) ((i) > 0 || (i) <= LUA_REGISTRYINDEX ? (i) : \ + lua_gettop(L) + (i) + 1) + + +/* +** {====================================================== +** Error-report functions +** ======================================================= +*/ + + +LUALIB_API int luaL_argerror (lua_State *L, int narg, const char *extramsg) { + lua_Debug ar; + if (!lua_getstack(L, 0, &ar)) /* no stack frame? */ + return luaL_error(L, "bad argument #%d (%s)", narg, extramsg); + lua_getinfo(L, "n", &ar); + if (strcmp(ar.namewhat, "method") == 0) { + narg--; /* do not count `self' */ + if (narg == 0) /* error is in the self argument itself? */ + return luaL_error(L, "calling " LUA_QS " on bad self (%s)", + ar.name, extramsg); + } + if (ar.name == NULL) + ar.name = "?"; + return luaL_error(L, "bad argument #%d to " LUA_QS " (%s)", + narg, ar.name, extramsg); +} + + +LUALIB_API int luaL_typerror (lua_State *L, int narg, const char *tname) { + const char *msg = lua_pushfstring(L, "%s expected, got %s", + tname, luaL_typename(L, narg)); + return luaL_argerror(L, narg, msg); +} + + +static void tag_error (lua_State *L, int narg, int tag) { + luaL_typerror(L, narg, lua_typename(L, tag)); +} + + +LUALIB_API void luaL_where (lua_State *L, int level) { + lua_Debug ar; + if (lua_getstack(L, level, &ar)) { /* check function at level */ + lua_getinfo(L, "Sl", &ar); /* get info about it */ + if (ar.currentline > 0) { /* is there info? */ + lua_pushfstring(L, "%s:%d: ", ar.short_src, ar.currentline); + return; + } + } + lua_pushliteral(L, ""); /* else, no information available... */ +} + + +LUALIB_API int luaL_error (lua_State *L, const char *fmt, ...) { + va_list argp; + va_start(argp, fmt); + luaL_where(L, 1); + lua_pushvfstring(L, fmt, argp); + va_end(argp); + lua_concat(L, 2); + return lua_error(L); +} + +/* }====================================================== */ + + +LUALIB_API int luaL_checkoption (lua_State *L, int narg, const char *def, + const char *const lst[]) { + const char *name = (def) ? luaL_optstring(L, narg, def) : + luaL_checkstring(L, narg); + int i; + for (i=0; lst[i]; i++) + if (strcmp(lst[i], name) == 0) + return i; + return luaL_argerror(L, narg, + lua_pushfstring(L, "invalid option " LUA_QS, name)); +} + + +LUALIB_API int luaL_newmetatable (lua_State *L, const char *tname) { + lua_getfield(L, LUA_REGISTRYINDEX, tname); /* get registry.name */ + if (!lua_isnil(L, -1)) /* name already in use? */ + return 0; /* leave previous value on top, but return 0 */ + lua_pop(L, 1); + lua_newtable(L); /* create metatable */ + lua_pushvalue(L, -1); + lua_setfield(L, LUA_REGISTRYINDEX, tname); /* registry.name = metatable */ + return 1; +} + + +LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) { + void *p = lua_touserdata(L, ud); + if (p != NULL) { /* value is a userdata? */ + if (lua_getmetatable(L, ud)) { /* does it have a metatable? */ + lua_getfield(L, LUA_REGISTRYINDEX, tname); /* get correct metatable */ + if (lua_rawequal(L, -1, -2)) { /* does it have the correct mt? */ + lua_pop(L, 2); /* remove both metatables */ + return p; + } + } + } + luaL_typerror(L, ud, tname); /* else error */ + return NULL; /* to avoid warnings */ +} + + +LUALIB_API void luaL_checkstack (lua_State *L, int space, const char *mes) { + if (!lua_checkstack(L, space)) + luaL_error(L, "stack overflow (%s)", mes); +} + + +LUALIB_API void luaL_checktype (lua_State *L, int narg, int t) { + if (lua_type(L, narg) != t) + tag_error(L, narg, t); +} + + +LUALIB_API void luaL_checkany (lua_State *L, int narg) { + if (lua_type(L, narg) == LUA_TNONE) + luaL_argerror(L, narg, "value expected"); +} + + +LUALIB_API const char *luaL_checklstring (lua_State *L, int narg, size_t *len) { + const char *s = lua_tolstring(L, narg, len); + if (!s) tag_error(L, narg, LUA_TSTRING); + return s; +} + + +LUALIB_API const char *luaL_optlstring (lua_State *L, int narg, + const char *def, size_t *len) { + if (lua_isnoneornil(L, narg)) { + if (len) + *len = (def ? strlen(def) : 0); + return def; + } + else return luaL_checklstring(L, narg, len); +} + + +LUALIB_API lua_Number luaL_checknumber (lua_State *L, int narg) { + lua_Number d = lua_tonumber(L, narg); + if (d == 0 && !lua_isnumber(L, narg)) /* avoid extra test when d is not 0 */ + tag_error(L, narg, LUA_TNUMBER); + return d; +} + + +LUALIB_API lua_Number luaL_optnumber (lua_State *L, int narg, lua_Number def) { + return luaL_opt(L, luaL_checknumber, narg, def); +} + + +LUALIB_API lua_Integer luaL_checkinteger (lua_State *L, int narg) { + lua_Integer d = lua_tointeger(L, narg); + if (d == 0 && !lua_isnumber(L, narg)) /* avoid extra test when d is not 0 */ + tag_error(L, narg, LUA_TNUMBER); + return d; +} + + +LUALIB_API lua_Integer luaL_optinteger (lua_State *L, int narg, + lua_Integer def) { + return luaL_opt(L, luaL_checkinteger, narg, def); +} + + +LUALIB_API int luaL_getmetafield (lua_State *L, int obj, const char *event) { + if (!lua_getmetatable(L, obj)) /* no metatable? */ + return 0; + lua_pushstring(L, event); + lua_rawget(L, -2); + if (lua_isnil(L, -1)) { + lua_pop(L, 2); /* remove metatable and metafield */ + return 0; + } + else { + lua_remove(L, -2); /* remove only metatable */ + return 1; + } +} + + +LUALIB_API int luaL_callmeta (lua_State *L, int obj, const char *event) { + obj = abs_index(L, obj); + if (!luaL_getmetafield(L, obj, event)) /* no metafield? */ + return 0; + lua_pushvalue(L, obj); + lua_call(L, 1, 1); + return 1; +} + + +LUALIB_API void (luaL_register) (lua_State *L, const char *libname, + const luaL_Reg *l) { + luaI_openlib(L, libname, l, 0); +} + + +static int libsize (const luaL_Reg *l) { + int size = 0; + for (; l->name; l++) size++; + return size; +} + + +LUALIB_API void luaI_openlib (lua_State *L, const char *libname, + const luaL_Reg *l, int nup) { + if (libname) { + int size = libsize(l); + /* check whether lib already exists */ + luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 1); + lua_getfield(L, -1, libname); /* get _LOADED[libname] */ + if (!lua_istable(L, -1)) { /* not found? */ + lua_pop(L, 1); /* remove previous result */ + /* try global variable (and create one if it does not exist) */ + if (luaL_findtable(L, LUA_GLOBALSINDEX, libname, size) != NULL) + luaL_error(L, "name conflict for module " LUA_QS, libname); + lua_pushvalue(L, -1); + lua_setfield(L, -3, libname); /* _LOADED[libname] = new table */ + } + lua_remove(L, -2); /* remove _LOADED table */ + lua_insert(L, -(nup+1)); /* move library table to below upvalues */ + } + for (; l->name; l++) { + int i; + for (i=0; ifunc, nup); + lua_setfield(L, -(nup+2), l->name); + } + lua_pop(L, nup); /* remove upvalues */ +} + + + +/* +** {====================================================== +** getn-setn: size for arrays +** ======================================================= +*/ + +#if defined(LUA_COMPAT_GETN) + +static int checkint (lua_State *L, int topop) { + int n = (lua_type(L, -1) == LUA_TNUMBER) ? lua_tointeger(L, -1) : -1; + lua_pop(L, topop); + return n; +} + + +static void getsizes (lua_State *L) { + lua_getfield(L, LUA_REGISTRYINDEX, "LUA_SIZES"); + if (lua_isnil(L, -1)) { /* no `size' table? */ + lua_pop(L, 1); /* remove nil */ + lua_newtable(L); /* create it */ + lua_pushvalue(L, -1); /* `size' will be its own metatable */ + lua_setmetatable(L, -2); + lua_pushliteral(L, "kv"); + lua_setfield(L, -2, "__mode"); /* metatable(N).__mode = "kv" */ + lua_pushvalue(L, -1); + lua_setfield(L, LUA_REGISTRYINDEX, "LUA_SIZES"); /* store in register */ + } +} + + +LUALIB_API void luaL_setn (lua_State *L, int t, int n) { + t = abs_index(L, t); + lua_pushliteral(L, "n"); + lua_rawget(L, t); + if (checkint(L, 1) >= 0) { /* is there a numeric field `n'? */ + lua_pushliteral(L, "n"); /* use it */ + lua_pushinteger(L, n); + lua_rawset(L, t); + } + else { /* use `sizes' */ + getsizes(L); + lua_pushvalue(L, t); + lua_pushinteger(L, n); + lua_rawset(L, -3); /* sizes[t] = n */ + lua_pop(L, 1); /* remove `sizes' */ + } +} + + +LUALIB_API int luaL_getn (lua_State *L, int t) { + int n; + t = abs_index(L, t); + lua_pushliteral(L, "n"); /* try t.n */ + lua_rawget(L, t); + if ((n = checkint(L, 1)) >= 0) return n; + getsizes(L); /* else try sizes[t] */ + lua_pushvalue(L, t); + lua_rawget(L, -2); + if ((n = checkint(L, 2)) >= 0) return n; + return (int)lua_objlen(L, t); +} + +#endif + +/* }====================================================== */ + + + +LUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p, + const char *r) { + const char *wild; + size_t l = strlen(p); + luaL_Buffer b; + luaL_buffinit(L, &b); + while ((wild = strstr(s, p)) != NULL) { + luaL_addlstring(&b, s, wild - s); /* push prefix */ + luaL_addstring(&b, r); /* push replacement in place of pattern */ + s = wild + l; /* continue after `p' */ + } + luaL_addstring(&b, s); /* push last suffix */ + luaL_pushresult(&b); + return lua_tostring(L, -1); +} + + +LUALIB_API const char *luaL_findtable (lua_State *L, int idx, + const char *fname, int szhint) { + const char *e; + lua_pushvalue(L, idx); + do { + e = strchr(fname, '.'); + if (e == NULL) e = fname + strlen(fname); + lua_pushlstring(L, fname, e - fname); + lua_rawget(L, -2); + if (lua_isnil(L, -1)) { /* no such field? */ + lua_pop(L, 1); /* remove this nil */ + lua_createtable(L, 0, (*e == '.' ? 1 : szhint)); /* new table for field */ + lua_pushlstring(L, fname, e - fname); + lua_pushvalue(L, -2); + lua_settable(L, -4); /* set new table into field */ + } + else if (!lua_istable(L, -1)) { /* field has a non-table value? */ + lua_pop(L, 2); /* remove table and value */ + return fname; /* return problematic part of the name */ + } + lua_remove(L, -2); /* remove previous table */ + fname = e + 1; + } while (*e == '.'); + return NULL; +} + + + +/* +** {====================================================== +** Generic Buffer manipulation +** ======================================================= +*/ + + +#define bufflen(B) ((B)->p - (B)->buffer) +#define bufffree(B) ((size_t)(LUAL_BUFFERSIZE - bufflen(B))) + +#define LIMIT (LUA_MINSTACK/2) + + +static int emptybuffer (luaL_Buffer *B) { + size_t l = bufflen(B); + if (l == 0) return 0; /* put nothing on stack */ + else { + lua_pushlstring(B->L, B->buffer, l); + B->p = B->buffer; + B->lvl++; + return 1; + } +} + + +static void adjuststack (luaL_Buffer *B) { + if (B->lvl > 1) { + lua_State *L = B->L; + int toget = 1; /* number of levels to concat */ + size_t toplen = lua_strlen(L, -1); + do { + size_t l = lua_strlen(L, -(toget+1)); + if (B->lvl - toget + 1 >= LIMIT || toplen > l) { + toplen += l; + toget++; + } + else break; + } while (toget < B->lvl); + lua_concat(L, toget); + B->lvl = B->lvl - toget + 1; + } +} + + +LUALIB_API char *luaL_prepbuffer (luaL_Buffer *B) { + if (emptybuffer(B)) + adjuststack(B); + return B->buffer; +} + + +LUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l) { + while (l--) + luaL_addchar(B, *s++); +} + + +LUALIB_API void luaL_addstring (luaL_Buffer *B, const char *s) { + luaL_addlstring(B, s, strlen(s)); +} + + +LUALIB_API void luaL_pushresult (luaL_Buffer *B) { + emptybuffer(B); + lua_concat(B->L, B->lvl); + B->lvl = 1; +} + + +LUALIB_API void luaL_addvalue (luaL_Buffer *B) { + lua_State *L = B->L; + size_t vl; + const char *s = lua_tolstring(L, -1, &vl); + if (vl <= bufffree(B)) { /* fit into buffer? */ + memcpy(B->p, s, vl); /* put it there */ + B->p += vl; + lua_pop(L, 1); /* remove from stack */ + } + else { + if (emptybuffer(B)) + lua_insert(L, -2); /* put buffer before new value */ + B->lvl++; /* add new value into B stack */ + adjuststack(B); + } +} + + +LUALIB_API void luaL_buffinit (lua_State *L, luaL_Buffer *B) { + B->L = L; + B->p = B->buffer; + B->lvl = 0; +} + +/* }====================================================== */ + + +LUALIB_API int luaL_ref (lua_State *L, int t) { + int ref; + t = abs_index(L, t); + if (lua_isnil(L, -1)) { + lua_pop(L, 1); /* remove from stack */ + return LUA_REFNIL; /* `nil' has a unique fixed reference */ + } + lua_rawgeti(L, t, FREELIST_REF); /* get first free element */ + ref = (int)lua_tointeger(L, -1); /* ref = t[FREELIST_REF] */ + lua_pop(L, 1); /* remove it from stack */ + if (ref != 0) { /* any free element? */ + lua_rawgeti(L, t, ref); /* remove it from list */ + lua_rawseti(L, t, FREELIST_REF); /* (t[FREELIST_REF] = t[ref]) */ + } + else { /* no free elements */ + ref = (int)lua_objlen(L, t); + ref++; /* create new reference */ + } + lua_rawseti(L, t, ref); + return ref; +} + + +LUALIB_API void luaL_unref (lua_State *L, int t, int ref) { + if (ref >= 0) { + t = abs_index(L, t); + lua_rawgeti(L, t, FREELIST_REF); + lua_rawseti(L, t, ref); /* t[ref] = t[FREELIST_REF] */ + lua_pushinteger(L, ref); + lua_rawseti(L, t, FREELIST_REF); /* t[FREELIST_REF] = ref */ + } +} + + + +/* +** {====================================================== +** Load functions +** ======================================================= +*/ + +typedef struct LoadF { + int extraline; + FILE *f; + char buff[LUAL_BUFFERSIZE]; +} LoadF; + + +static const char *getF (lua_State *L, void *ud, size_t *size) { + LoadF *lf = (LoadF *)ud; + (void)L; + if (lf->extraline) { + lf->extraline = 0; + *size = 1; + return "\n"; + } + if (feof(lf->f)) return NULL; + *size = fread(lf->buff, 1, sizeof(lf->buff), lf->f); + return (*size > 0) ? lf->buff : NULL; +} + + +static int errfile (lua_State *L, const char *what, int fnameindex) { + const char *serr = strerror(errno); + const char *filename = lua_tostring(L, fnameindex) + 1; + lua_pushfstring(L, "cannot %s %s: %s", what, filename, serr); + lua_remove(L, fnameindex); + return LUA_ERRFILE; +} + + +LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) { + LoadF lf; + int status, readstatus; + int c; + int fnameindex = lua_gettop(L) + 1; /* index of filename on the stack */ + lf.extraline = 0; + if (filename == NULL) { + lua_pushliteral(L, "=stdin"); + lf.f = stdin; + } + else { + lua_pushfstring(L, "@%s", filename); + lf.f = fopen(filename, "r"); + if (lf.f == NULL) return errfile(L, "open", fnameindex); + } + c = getc(lf.f); + if (c == '#') { /* Unix exec. file? */ + lf.extraline = 1; + while ((c = getc(lf.f)) != EOF && c != '\n') ; /* skip first line */ + if (c == '\n') c = getc(lf.f); + } + if (c == LUA_SIGNATURE[0] && filename) { /* binary file? */ +#ifdef LUA_ALLOW_BYTECODE + lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */ + if (lf.f == NULL) return errfile(L, "reopen", fnameindex); + /* skip eventual `#!...' */ + while ((c = getc(lf.f)) != EOF && c != LUA_SIGNATURE[0]) + ; + lf.extraline = 0; +#else + fclose(lf.f); + return errfile(L, "handle binary", fnameindex); +#endif + } + ungetc(c, lf.f); + status = lua_load(L, getF, &lf, lua_tostring(L, -1)); + readstatus = ferror(lf.f); + if (filename) fclose(lf.f); /* close file (even in case of errors) */ + if (readstatus) { + lua_settop(L, fnameindex); /* ignore results from `lua_load' */ + return errfile(L, "read", fnameindex); + } + lua_remove(L, fnameindex); + return status; +} + + +typedef struct LoadS { + const char *s; + size_t size; +} LoadS; + + +static const char *getS (lua_State *L, void *ud, size_t *size) { + LoadS *ls = (LoadS *)ud; + (void)L; + if (ls->size == 0) return NULL; + *size = ls->size; + ls->size = 0; + return ls->s; +} + + +LUALIB_API int luaL_loadbuffer (lua_State *L, const char *buff, size_t size, + const char *name) { + LoadS ls; + ls.s = buff; + ls.size = size; + return lua_load(L, getS, &ls, name); +} + + +LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s) { + return luaL_loadbuffer(L, s, strlen(s), s); +} + + + +/* }====================================================== */ + + +static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) { + (void)ud; + (void)osize; + if (nsize == 0) { + free(ptr); + return NULL; + } + else + return realloc(ptr, nsize); +} + + +static int panic (lua_State *L) { + (void)L; /* to avoid warnings */ + fprintf(stderr, "PANIC: unprotected error in call to Lua API (%s)\n", + lua_tostring(L, -1)); + return 0; +} + + +LUALIB_API lua_State *luaL_newstate (void) { + lua_State *L = lua_newstate(l_alloc, NULL); + if (L) lua_atpanic(L, &panic); + return L; +} diff --git a/src/blua/lauxlib.h b/src/blua/lauxlib.h new file mode 100644 index 000000000..032041052 --- /dev/null +++ b/src/blua/lauxlib.h @@ -0,0 +1,172 @@ +/* +** $Id: lauxlib.h,v 1.88.1.1 2007/12/27 13:02:25 roberto Exp $ +** Auxiliary functions for building Lua libraries +** See Copyright Notice in lua.h +*/ + + +#ifndef lauxlib_h +#define lauxlib_h + + +#include +#include + +#include "lua.h" + + +#if defined(LUA_COMPAT_GETN) +LUALIB_API int (luaL_getn) (lua_State *L, int t); +LUALIB_API void (luaL_setn) (lua_State *L, int t, int n); +#else +#define luaL_getn(L,i) ((int)lua_objlen(L, i)) +#define luaL_setn(L,i,j) ((void)0) /* no op! */ +#endif + +#if defined(LUA_COMPAT_OPENLIB) +#define luaI_openlib luaL_openlib +#endif + + +/* extra error code for `luaL_load' */ +#define LUA_ERRFILE (LUA_ERRERR+1) + + +typedef struct luaL_Reg { + const char *name; + lua_CFunction func; +} luaL_Reg; + + + +LUALIB_API void (luaI_openlib) (lua_State *L, const char *libname, + const luaL_Reg *l, int nup); +LUALIB_API void (luaL_register) (lua_State *L, const char *libname, + const luaL_Reg *l); +LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e); +LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e); +LUALIB_API int (luaL_typerror) (lua_State *L, int narg, const char *tname); +LUALIB_API int (luaL_argerror) (lua_State *L, int numarg, const char *extramsg); +LUALIB_API const char *(luaL_checklstring) (lua_State *L, int numArg, + size_t *l); +LUALIB_API const char *(luaL_optlstring) (lua_State *L, int numArg, + const char *def, size_t *l); +LUALIB_API lua_Number (luaL_checknumber) (lua_State *L, int numArg); +LUALIB_API lua_Number (luaL_optnumber) (lua_State *L, int nArg, lua_Number def); + +LUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int numArg); +LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int nArg, + lua_Integer def); + +LUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg); +LUALIB_API void (luaL_checktype) (lua_State *L, int narg, int t); +LUALIB_API void (luaL_checkany) (lua_State *L, int narg); + +LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname); +LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname); + +LUALIB_API void (luaL_where) (lua_State *L, int lvl); +LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...); + +LUALIB_API int (luaL_checkoption) (lua_State *L, int narg, const char *def, + const char *const lst[]); + +LUALIB_API int (luaL_ref) (lua_State *L, int t); +LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref); + +LUALIB_API int (luaL_loadfile) (lua_State *L, const char *filename); +LUALIB_API int (luaL_loadbuffer) (lua_State *L, const char *buff, size_t sz, + const char *name); +LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s); + +LUALIB_API lua_State *(luaL_newstate) (void); + + +LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p, + const char *r); + +LUALIB_API const char *(luaL_findtable) (lua_State *L, int idx, + const char *fname, int szhint); + + + + +/* +** =============================================================== +** some useful macros +** =============================================================== +*/ + +#define luaL_argcheck(L, cond,numarg,extramsg) \ + ((void)((cond) || luaL_argerror(L, (numarg), (extramsg)))) +#define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL)) +#define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL)) +#define luaL_checkint(L,n) ((int)luaL_checkinteger(L, (n))) +#define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d))) +#define luaL_checklong(L,n) ((long)luaL_checkinteger(L, (n))) +#define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, (n), (d))) + +#define luaL_typename(L,i) lua_typename(L, lua_type(L,(i))) + +#define luaL_dofile(L, fn) \ + (luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0)) + +#define luaL_dostring(L, s) \ + (luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0)) + +#define luaL_getmetatable(L,n) (lua_getfield(L, LUA_REGISTRYINDEX, (n))) + +#define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n))) + +/* +** {====================================================== +** Generic Buffer manipulation +** ======================================================= +*/ + + + +typedef struct luaL_Buffer { + char *p; /* current position in buffer */ + int lvl; /* number of strings in the stack (level) */ + lua_State *L; + char buffer[LUAL_BUFFERSIZE]; +} luaL_Buffer; + +#define luaL_addchar(B,c) \ + ((void)((B)->p < ((B)->buffer+LUAL_BUFFERSIZE) || luaL_prepbuffer(B)), \ + (*(B)->p++ = (char)(c))) + +/* compatibility only */ +#define luaL_putchar(B,c) luaL_addchar(B,c) + +#define luaL_addsize(B,n) ((B)->p += (n)) + +LUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B); +LUALIB_API char *(luaL_prepbuffer) (luaL_Buffer *B); +LUALIB_API void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l); +LUALIB_API void (luaL_addstring) (luaL_Buffer *B, const char *s); +LUALIB_API void (luaL_addvalue) (luaL_Buffer *B); +LUALIB_API void (luaL_pushresult) (luaL_Buffer *B); + + +/* }====================================================== */ + + +/* compatibility with ref system */ + +/* pre-defined references */ +#define LUA_NOREF (-2) +#define LUA_REFNIL (-1) + +#define lua_ref(L,lock) ((lock) ? luaL_ref(L, LUA_REGISTRYINDEX) : \ + (lua_pushstring(L, "unlocked references are obsolete"), lua_error(L), 0)) + +#define lua_unref(L,ref) luaL_unref(L, LUA_REGISTRYINDEX, (ref)) + +#define lua_getref(L,ref) lua_rawgeti(L, LUA_REGISTRYINDEX, (ref)) + + +#define luaL_reg luaL_Reg + +#endif diff --git a/src/blua/lbaselib.c b/src/blua/lbaselib.c new file mode 100644 index 000000000..3c919cb64 --- /dev/null +++ b/src/blua/lbaselib.c @@ -0,0 +1,580 @@ +/* +** $Id: lbaselib.c,v 1.191.1.6 2008/02/14 16:46:22 roberto Exp $ +** Basic library +** See Copyright Notice in lua.h +*/ + + + +#include +#include +#include +#include + +#define lbaselib_c +#define LUA_LIB + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + + + + +/* +** If your system does not support `stdout', you can just remove this function. +** If you need, you can define your own `print' function, following this +** model but changing `fputs' to put the strings at a proper place +** (a console window or a log file, for instance). +*/ +static int luaB_print (lua_State *L) { + int n = lua_gettop(L); /* number of arguments */ + int i; + lua_getglobal(L, "tostring"); + for (i=1; i<=n; i++) { + const char *s; + lua_pushvalue(L, -1); /* function to be called */ + lua_pushvalue(L, i); /* value to print */ + lua_call(L, 1, 1); + s = lua_tostring(L, -1); /* get result */ + if (s == NULL) + return luaL_error(L, LUA_QL("tostring") " must return a string to " + LUA_QL("print")); + if (i>1) fputs("\t", stdout); + fputs(s, stdout); + lua_pop(L, 1); /* pop result */ + } + fputs("\n", stdout); + return 0; +} + + +static int luaB_tonumber (lua_State *L) { + int base = luaL_optint(L, 2, 10); + if (base == 10) { /* standard conversion */ + luaL_checkany(L, 1); + if (lua_isnumber(L, 1)) { + lua_pushnumber(L, lua_tonumber(L, 1)); + return 1; + } + } + else { + const char *s1 = luaL_checkstring(L, 1); + char *s2; + unsigned long n; + luaL_argcheck(L, 2 <= base && base <= 36, 2, "base out of range"); + n = strtoul(s1, &s2, base); + if (s1 != s2) { /* at least one valid digit? */ + while (isspace((unsigned char)(*s2))) s2++; /* skip trailing spaces */ + if (*s2 == '\0') { /* no invalid trailing characters? */ + lua_pushnumber(L, (lua_Number)n); + return 1; + } + } + } + lua_pushnil(L); /* else not a number */ + return 1; +} + + +static int luaB_error (lua_State *L) { + int level = luaL_optint(L, 2, 1); + lua_settop(L, 1); + if (lua_isstring(L, 1) && level > 0) { /* add extra information? */ + luaL_where(L, level); + lua_pushvalue(L, 1); + lua_concat(L, 2); + } + return lua_error(L); +} + + +static int luaB_getmetatable (lua_State *L) { + luaL_checkany(L, 1); + if (!lua_getmetatable(L, 1)) { + lua_pushnil(L); + return 1; /* no metatable */ + } + luaL_getmetafield(L, 1, "__metatable"); + return 1; /* returns either __metatable field (if present) or metatable */ +} + + +static int luaB_setmetatable (lua_State *L) { + int t = lua_type(L, 2); + luaL_checktype(L, 1, LUA_TTABLE); + luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2, + "nil or table expected"); + if (luaL_getmetafield(L, 1, "__metatable")) + luaL_error(L, "cannot change a protected metatable"); + lua_settop(L, 2); + lua_setmetatable(L, 1); + return 1; +} + + +static void getfunc (lua_State *L, int opt) { + if (lua_isfunction(L, 1)) lua_pushvalue(L, 1); + else { + lua_Debug ar; + int level = opt ? luaL_optint(L, 1, 1) : luaL_checkint(L, 1); + luaL_argcheck(L, level >= 0, 1, "level must be non-negative"); + if (lua_getstack(L, level, &ar) == 0) + luaL_argerror(L, 1, "invalid level"); + lua_getinfo(L, "f", &ar); + if (lua_isnil(L, -1)) + luaL_error(L, "no function environment for tail call at level %d", + level); + } +} + + +static int luaB_getfenv (lua_State *L) { + getfunc(L, 1); + if (lua_iscfunction(L, -1)) /* is a C function? */ + lua_pushvalue(L, LUA_GLOBALSINDEX); /* return the thread's global env. */ + else + lua_getfenv(L, -1); + return 1; +} + + +static int luaB_setfenv (lua_State *L) { + luaL_checktype(L, 2, LUA_TTABLE); + getfunc(L, 0); + lua_pushvalue(L, 2); + if (lua_isnumber(L, 1) && lua_tonumber(L, 1) == 0) { + /* change environment of current thread */ + lua_pushthread(L); + lua_insert(L, -2); + lua_setfenv(L, -2); + return 0; + } + else if (lua_iscfunction(L, -2) || lua_setfenv(L, -2) == 0) + luaL_error(L, + LUA_QL("setfenv") " cannot change environment of given object"); + return 1; +} + + +static int luaB_rawequal (lua_State *L) { + luaL_checkany(L, 1); + luaL_checkany(L, 2); + lua_pushboolean(L, lua_rawequal(L, 1, 2)); + return 1; +} + + +static int luaB_rawget (lua_State *L) { + luaL_checktype(L, 1, LUA_TTABLE); + luaL_checkany(L, 2); + lua_settop(L, 2); + lua_rawget(L, 1); + return 1; +} + +static int luaB_rawset (lua_State *L) { + luaL_checktype(L, 1, LUA_TTABLE); + luaL_checkany(L, 2); + luaL_checkany(L, 3); + lua_settop(L, 3); + lua_rawset(L, 1); + return 1; +} + + +static int luaB_gcinfo (lua_State *L) { + lua_pushinteger(L, lua_getgccount(L)); + return 1; +} + + +static int luaB_collectgarbage (lua_State *L) { + static const char *const opts[] = {"stop", "restart", "collect", + "count", "step", "setpause", "setstepmul", NULL}; + static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT, + LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETPAUSE, LUA_GCSETSTEPMUL}; + int o = luaL_checkoption(L, 1, "collect", opts); + int ex = luaL_optint(L, 2, 0); + int res = lua_gc(L, optsnum[o], ex); + switch (optsnum[o]) { + case LUA_GCCOUNT: { + int b = lua_gc(L, LUA_GCCOUNTB, 0); + lua_pushnumber(L, res + ((lua_Number)b/1024)); + return 1; + } + case LUA_GCSTEP: { + lua_pushboolean(L, res); + return 1; + } + default: { + lua_pushnumber(L, res); + return 1; + } + } +} + + +static int luaB_type (lua_State *L) { + luaL_checkany(L, 1); + lua_pushstring(L, luaL_typename(L, 1)); + return 1; +} + + +static int luaB_next (lua_State *L) { + luaL_checktype(L, 1, LUA_TTABLE); + lua_settop(L, 2); /* create a 2nd argument if there isn't one */ + if (lua_next(L, 1)) + return 2; + else { + lua_pushnil(L); + return 1; + } +} + + +static int luaB_pairs (lua_State *L) { + luaL_checktype(L, 1, LUA_TTABLE); + lua_pushvalue(L, lua_upvalueindex(1)); /* return generator, */ + lua_pushvalue(L, 1); /* state, */ + lua_pushnil(L); /* and initial value */ + return 3; +} + + +static int ipairsaux (lua_State *L) { + int i = luaL_checkint(L, 2); + luaL_checktype(L, 1, LUA_TTABLE); + i++; /* next value */ + lua_pushinteger(L, i); + lua_rawgeti(L, 1, i); + return (lua_isnil(L, -1)) ? 0 : 2; +} + + +static int luaB_ipairs (lua_State *L) { + luaL_checktype(L, 1, LUA_TTABLE); + lua_pushvalue(L, lua_upvalueindex(1)); /* return generator, */ + lua_pushvalue(L, 1); /* state, */ + lua_pushinteger(L, 0); /* and initial value */ + return 3; +} + + +static int luaB_assert (lua_State *L) { + luaL_checkany(L, 1); + if (!lua_toboolean(L, 1)) + return luaL_error(L, "%s", luaL_optstring(L, 2, "assertion failed!")); + return lua_gettop(L); +} + + +static int luaB_unpack (lua_State *L) { + int i, e, n; + luaL_checktype(L, 1, LUA_TTABLE); + i = luaL_optint(L, 2, 1); + e = luaL_opt(L, luaL_checkint, 3, luaL_getn(L, 1)); + if (i > e) return 0; /* empty range */ + n = e - i + 1; /* number of elements */ + if (n <= 0 || !lua_checkstack(L, n)) /* n <= 0 means arith. overflow */ + return luaL_error(L, "too many results to unpack"); + lua_rawgeti(L, 1, i); /* push arg[i] (avoiding overflow problems) */ + while (i++ < e) /* push arg[i + 1...e] */ + lua_rawgeti(L, 1, i); + return n; +} + + +static int luaB_select (lua_State *L) { + int n = lua_gettop(L); + if (lua_type(L, 1) == LUA_TSTRING && *lua_tostring(L, 1) == '#') { + lua_pushinteger(L, n-1); + return 1; + } + else { + int i = luaL_checkint(L, 1); + if (i < 0) i = n + i; + else if (i > n) i = n; + luaL_argcheck(L, 1 <= i, 1, "index out of range"); + return n - i; + } +} + + +static int luaB_pcall (lua_State *L) { + int status; + luaL_checkany(L, 1); + status = lua_pcall(L, lua_gettop(L) - 1, LUA_MULTRET, 0); + lua_pushboolean(L, (status == 0)); + lua_insert(L, 1); + return lua_gettop(L); /* return status + all results */ +} + + +static int luaB_xpcall (lua_State *L) { + int status; + luaL_checkany(L, 2); + lua_settop(L, 2); + lua_insert(L, 1); /* put error function under function to be called */ + status = lua_pcall(L, 0, LUA_MULTRET, 1); + lua_pushboolean(L, (status == 0)); + lua_replace(L, 1); + return lua_gettop(L); /* return status + all results */ +} + + +static int luaB_tostring (lua_State *L) { + luaL_checkany(L, 1); + if (luaL_callmeta(L, 1, "__tostring")) /* is there a metafield? */ + return 1; /* use its value */ + switch (lua_type(L, 1)) { + case LUA_TNUMBER: + lua_pushstring(L, lua_tostring(L, 1)); + break; + case LUA_TSTRING: + lua_pushvalue(L, 1); + break; + case LUA_TBOOLEAN: + lua_pushstring(L, (lua_toboolean(L, 1) ? "true" : "false")); + break; + case LUA_TNIL: + lua_pushliteral(L, "nil"); + break; + default: + lua_pushfstring(L, "%s: %p", luaL_typename(L, 1), lua_topointer(L, 1)); + break; + } + return 1; +} + + +static int luaB_newproxy (lua_State *L) { + lua_settop(L, 1); + lua_newuserdata(L, 0); /* create proxy */ + if (lua_toboolean(L, 1) == 0) + return 1; /* no metatable */ + else if (lua_isboolean(L, 1)) { + lua_newtable(L); /* create a new metatable `m' ... */ + lua_pushvalue(L, -1); /* ... and mark `m' as a valid metatable */ + lua_pushboolean(L, 1); + lua_rawset(L, lua_upvalueindex(1)); /* weaktable[m] = true */ + } + else { + int validproxy = 0; /* to check if weaktable[metatable(u)] == true */ + if (lua_getmetatable(L, 1)) { + lua_rawget(L, lua_upvalueindex(1)); + validproxy = lua_toboolean(L, -1); + lua_pop(L, 1); /* remove value */ + } + luaL_argcheck(L, validproxy, 1, "boolean or proxy expected"); + lua_getmetatable(L, 1); /* metatable is valid; get it */ + } + lua_setmetatable(L, 2); + return 1; +} + + +static const luaL_Reg base_funcs[] = { + {"assert", luaB_assert}, + {"collectgarbage", luaB_collectgarbage}, + {"error", luaB_error}, + {"gcinfo", luaB_gcinfo}, + {"getfenv", luaB_getfenv}, + {"getmetatable", luaB_getmetatable}, + {"next", luaB_next}, + {"pcall", luaB_pcall}, + {"print", luaB_print}, + {"rawequal", luaB_rawequal}, + {"rawget", luaB_rawget}, + {"rawset", luaB_rawset}, + {"select", luaB_select}, + {"setfenv", luaB_setfenv}, + {"setmetatable", luaB_setmetatable}, + {"tonumber", luaB_tonumber}, + {"tostring", luaB_tostring}, + {"type", luaB_type}, + {"unpack", luaB_unpack}, + {"xpcall", luaB_xpcall}, + {NULL, NULL} +}; + + +/* +** {====================================================== +** Coroutine library +** ======================================================= +*/ + +#define CO_RUN 0 /* running */ +#define CO_SUS 1 /* suspended */ +#define CO_NOR 2 /* 'normal' (it resumed another coroutine) */ +#define CO_DEAD 3 + +static const char *const statnames[] = + {"running", "suspended", "normal", "dead"}; + +static int costatus (lua_State *L, lua_State *co) { + if (L == co) return CO_RUN; + switch (lua_status(co)) { + case LUA_YIELD: + return CO_SUS; + case 0: { + lua_Debug ar; + if (lua_getstack(co, 0, &ar) > 0) /* does it have frames? */ + return CO_NOR; /* it is running */ + else if (lua_gettop(co) == 0) + return CO_DEAD; + else + return CO_SUS; /* initial state */ + } + default: /* some error occured */ + return CO_DEAD; + } +} + + +static int luaB_costatus (lua_State *L) { + lua_State *co = lua_tothread(L, 1); + luaL_argcheck(L, co, 1, "coroutine expected"); + lua_pushstring(L, statnames[costatus(L, co)]); + return 1; +} + + +static int auxresume (lua_State *L, lua_State *co, int narg) { + int status = costatus(L, co); + if (!lua_checkstack(co, narg)) + luaL_error(L, "too many arguments to resume"); + if (status != CO_SUS) { + lua_pushfstring(L, "cannot resume %s coroutine", statnames[status]); + return -1; /* error flag */ + } + lua_xmove(L, co, narg); + lua_setlevel(L, co); + status = lua_resume(co, narg); + if (status == 0 || status == LUA_YIELD) { + int nres = lua_gettop(co); + if (!lua_checkstack(L, nres + 1)) + luaL_error(L, "too many results to resume"); + lua_xmove(co, L, nres); /* move yielded values */ + return nres; + } + else { + lua_xmove(co, L, 1); /* move error message */ + return -1; /* error flag */ + } +} + + +static int luaB_coresume (lua_State *L) { + lua_State *co = lua_tothread(L, 1); + int r; + luaL_argcheck(L, co, 1, "coroutine expected"); + r = auxresume(L, co, lua_gettop(L) - 1); + if (r < 0) { + lua_pushboolean(L, 0); + lua_insert(L, -2); + return 2; /* return false + error message */ + } + else { + lua_pushboolean(L, 1); + lua_insert(L, -(r + 1)); + return r + 1; /* return true + `resume' returns */ + } +} + + +static int luaB_auxwrap (lua_State *L) { + lua_State *co = lua_tothread(L, lua_upvalueindex(1)); + int r = auxresume(L, co, lua_gettop(L)); + if (r < 0) { + if (lua_isstring(L, -1)) { /* error object is a string? */ + luaL_where(L, 1); /* add extra info */ + lua_insert(L, -2); + lua_concat(L, 2); + } + lua_error(L); /* propagate error */ + } + return r; +} + + +static int luaB_cocreate (lua_State *L) { + lua_State *NL = lua_newthread(L); + luaL_argcheck(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), 1, + "Lua function expected"); + lua_pushvalue(L, 1); /* move function to top */ + lua_xmove(L, NL, 1); /* move function from L to NL */ + return 1; +} + + +static int luaB_cowrap (lua_State *L) { + luaB_cocreate(L); + lua_pushcclosure(L, luaB_auxwrap, 1); + return 1; +} + + +static int luaB_yield (lua_State *L) { + return lua_yield(L, lua_gettop(L)); +} + + +static int luaB_corunning (lua_State *L) { + if (lua_pushthread(L)) + lua_pushnil(L); /* main thread is not a coroutine */ + return 1; +} + + +static const luaL_Reg co_funcs[] = { + {"create", luaB_cocreate}, + {"resume", luaB_coresume}, + {"running", luaB_corunning}, + {"status", luaB_costatus}, + {"wrap", luaB_cowrap}, + {"yield", luaB_yield}, + {NULL, NULL} +}; + +/* }====================================================== */ + + +static void auxopen (lua_State *L, const char *name, + lua_CFunction f, lua_CFunction u) { + lua_pushcfunction(L, u); + lua_pushcclosure(L, f, 1); + lua_setfield(L, -2, name); +} + + +static void base_open (lua_State *L) { + /* set global _G */ + lua_pushvalue(L, LUA_GLOBALSINDEX); + lua_setglobal(L, "_G"); + /* open lib into global table */ + luaL_register(L, "_G", base_funcs); + lua_pushliteral(L, LUA_VERSION); + lua_setglobal(L, "_VERSION"); /* set global _VERSION */ + /* `ipairs' and `pairs' need auxliliary functions as upvalues */ + auxopen(L, "ipairs", luaB_ipairs, ipairsaux); + auxopen(L, "pairs", luaB_pairs, luaB_next); + /* `newproxy' needs a weaktable as upvalue */ + lua_createtable(L, 0, 1); /* new table `w' */ + lua_pushvalue(L, -1); /* `w' will be its own metatable */ + lua_setmetatable(L, -2); + lua_pushliteral(L, "kv"); + lua_setfield(L, -2, "__mode"); /* metatable(w).__mode = "kv" */ + lua_pushcclosure(L, luaB_newproxy, 1); + lua_setglobal(L, "newproxy"); /* set global `newproxy' */ +} + + +LUALIB_API int luaopen_base (lua_State *L) { + base_open(L); + luaL_register(L, LUA_COLIBNAME, co_funcs); + return 2; +} diff --git a/src/blua/lcode.c b/src/blua/lcode.c new file mode 100644 index 000000000..743a094a8 --- /dev/null +++ b/src/blua/lcode.c @@ -0,0 +1,856 @@ +/* +** $Id: lcode.c,v 2.25.1.3 2007/12/28 15:32:23 roberto Exp $ +** Code generator for Lua +** See Copyright Notice in lua.h +*/ + + +#include + +#define lcode_c +#define LUA_CORE + +#include "lua.h" + +#include "lcode.h" +#include "ldebug.h" +#include "ldo.h" +#include "lgc.h" +#include "llex.h" +#include "lmem.h" +#include "lobject.h" +#include "lopcodes.h" +#include "lparser.h" +#include "ltable.h" + + +#define hasjumps(e) ((e)->t != (e)->f) + + +static int isnumeral(expdesc *e) { + return (e->k == VKNUM && e->t == NO_JUMP && e->f == NO_JUMP); +} + + +void luaK_nil (FuncState *fs, int from, int n) { + Instruction *previous; + if (fs->pc > fs->lasttarget) { /* no jumps to current position? */ + if (fs->pc == 0) { /* function start? */ + if (from >= fs->nactvar) + return; /* positions are already clean */ + } + else { + previous = &fs->f->code[fs->pc-1]; + if (GET_OPCODE(*previous) == OP_LOADNIL) { + int pfrom = GETARG_A(*previous); + int pto = GETARG_B(*previous); + if (pfrom <= from && from <= pto+1) { /* can connect both? */ + if (from+n-1 > pto) + SETARG_B(*previous, from+n-1); + return; + } + } + } + } + luaK_codeABC(fs, OP_LOADNIL, from, from+n-1, 0); /* else no optimization */ +} + + +int luaK_jump (FuncState *fs) { + int jpc = fs->jpc; /* save list of jumps to here */ + int j; + fs->jpc = NO_JUMP; + j = luaK_codeAsBx(fs, OP_JMP, 0, NO_JUMP); + luaK_concat(fs, &j, jpc); /* keep them on hold */ + return j; +} + + +void luaK_ret (FuncState *fs, int first, int nret) { + luaK_codeABC(fs, OP_RETURN, first, nret+1, 0); +} + + +static int condjump (FuncState *fs, OpCode op, int A, int B, int C) { + luaK_codeABC(fs, op, A, B, C); + return luaK_jump(fs); +} + + +static void fixjump (FuncState *fs, int pc, int dest) { + Instruction *jmp = &fs->f->code[pc]; + int offset = dest-(pc+1); + lua_assert(dest != NO_JUMP); + if (abs(offset) > MAXARG_sBx) + luaX_syntaxerror(fs->ls, "control structure too long"); + SETARG_sBx(*jmp, offset); +} + + +/* +** returns current `pc' and marks it as a jump target (to avoid wrong +** optimizations with consecutive instructions not in the same basic block). +*/ +int luaK_getlabel (FuncState *fs) { + fs->lasttarget = fs->pc; + return fs->pc; +} + + +static int getjump (FuncState *fs, int pc) { + int offset = GETARG_sBx(fs->f->code[pc]); + if (offset == NO_JUMP) /* point to itself represents end of list */ + return NO_JUMP; /* end of list */ + else + return (pc+1)+offset; /* turn offset into absolute position */ +} + + +static Instruction *getjumpcontrol (FuncState *fs, int pc) { + Instruction *pi = &fs->f->code[pc]; + if (pc >= 1 && testTMode(GET_OPCODE(*(pi-1)))) + return pi-1; + else + return pi; +} + + +/* +** check whether list has any jump that do not produce a value +** (or produce an inverted value) +*/ +static int need_value (FuncState *fs, int list) { + for (; list != NO_JUMP; list = getjump(fs, list)) { + Instruction i = *getjumpcontrol(fs, list); + if (GET_OPCODE(i) != OP_TESTSET) return 1; + } + return 0; /* not found */ +} + + +static int patchtestreg (FuncState *fs, int node, int reg) { + Instruction *i = getjumpcontrol(fs, node); + if (GET_OPCODE(*i) != OP_TESTSET) + return 0; /* cannot patch other instructions */ + if (reg != NO_REG && reg != GETARG_B(*i)) + SETARG_A(*i, reg); + else /* no register to put value or register already has the value */ + *i = CREATE_ABC(OP_TEST, GETARG_B(*i), 0, GETARG_C(*i)); + + return 1; +} + + +static void removevalues (FuncState *fs, int list) { + for (; list != NO_JUMP; list = getjump(fs, list)) + patchtestreg(fs, list, NO_REG); +} + + +static void patchlistaux (FuncState *fs, int list, int vtarget, int reg, + int dtarget) { + while (list != NO_JUMP) { + int next = getjump(fs, list); + if (patchtestreg(fs, list, reg)) + fixjump(fs, list, vtarget); + else + fixjump(fs, list, dtarget); /* jump to default target */ + list = next; + } +} + + +static void dischargejpc (FuncState *fs) { + patchlistaux(fs, fs->jpc, fs->pc, NO_REG, fs->pc); + fs->jpc = NO_JUMP; +} + + +void luaK_patchlist (FuncState *fs, int list, int target) { + if (target == fs->pc) + luaK_patchtohere(fs, list); + else { + lua_assert(target < fs->pc); + patchlistaux(fs, list, target, NO_REG, target); + } +} + + +void luaK_patchtohere (FuncState *fs, int list) { + luaK_getlabel(fs); + luaK_concat(fs, &fs->jpc, list); +} + + +void luaK_concat (FuncState *fs, int *l1, int l2) { + if (l2 == NO_JUMP) return; + else if (*l1 == NO_JUMP) + *l1 = l2; + else { + int list = *l1; + int next; + while ((next = getjump(fs, list)) != NO_JUMP) /* find last element */ + list = next; + fixjump(fs, list, l2); + } +} + + +void luaK_checkstack (FuncState *fs, int n) { + int newstack = fs->freereg + n; + if (newstack > fs->f->maxstacksize) { + if (newstack >= MAXSTACK) + luaX_syntaxerror(fs->ls, "function or expression too complex"); + fs->f->maxstacksize = cast_byte(newstack); + } +} + + +void luaK_reserveregs (FuncState *fs, int n) { + luaK_checkstack(fs, n); + fs->freereg += n; +} + + +static void freereg (FuncState *fs, int reg) { + if (!ISK(reg) && reg >= fs->nactvar) { + fs->freereg--; + lua_assert(reg == fs->freereg); + } +} + + +static void freeexp (FuncState *fs, expdesc *e) { + if (e->k == VNONRELOC) + freereg(fs, e->u.s.info); +} + + +static int addk (FuncState *fs, TValue *k, TValue *v) { + lua_State *L = fs->L; + TValue *idx = luaH_set(L, fs->h, k); + Proto *f = fs->f; + int oldsize = f->sizek; + if (ttisnumber(idx)) { + lua_assert(luaO_rawequalObj(&fs->f->k[cast_int(nvalue(idx))], v)); + return cast_int(nvalue(idx)); + } + else { /* constant not found; create a new entry */ + setnvalue(idx, cast_num(fs->nk)); + luaM_growvector(L, f->k, fs->nk, f->sizek, TValue, + MAXARG_Bx, "constant table overflow"); + while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]); + setobj(L, &f->k[fs->nk], v); + luaC_barrier(L, f, v); + return fs->nk++; + } +} + + +int luaK_stringK (FuncState *fs, TString *s) { + TValue o; + setsvalue(fs->L, &o, s); + return addk(fs, &o, &o); +} + + +int luaK_numberK (FuncState *fs, lua_Number r) { + TValue o; + setnvalue(&o, r); + return addk(fs, &o, &o); +} + + +static int boolK (FuncState *fs, int b) { + TValue o; + setbvalue(&o, b); + return addk(fs, &o, &o); +} + + +static int nilK (FuncState *fs) { + TValue k, v; + setnilvalue(&v); + /* cannot use nil as key; instead use table itself to represent nil */ + sethvalue(fs->L, &k, fs->h); + return addk(fs, &k, &v); +} + + +void luaK_setreturns (FuncState *fs, expdesc *e, int nresults) { + if (e->k == VCALL) { /* expression is an open function call? */ + SETARG_C(getcode(fs, e), nresults+1); + } + else if (e->k == VVARARG) { + SETARG_B(getcode(fs, e), nresults+1); + SETARG_A(getcode(fs, e), fs->freereg); + luaK_reserveregs(fs, 1); + } +} + + +void luaK_setoneret (FuncState *fs, expdesc *e) { + if (e->k == VCALL) { /* expression is an open function call? */ + e->k = VNONRELOC; + e->u.s.info = GETARG_A(getcode(fs, e)); + } + else if (e->k == VVARARG) { + SETARG_B(getcode(fs, e), 2); + e->k = VRELOCABLE; /* can relocate its simple result */ + } +} + + +void luaK_dischargevars (FuncState *fs, expdesc *e) { + switch (e->k) { + case VLOCAL: { + e->k = VNONRELOC; + break; + } + case VUPVAL: { + e->u.s.info = luaK_codeABC(fs, OP_GETUPVAL, 0, e->u.s.info, 0); + e->k = VRELOCABLE; + break; + } + case VGLOBAL: { + e->u.s.info = luaK_codeABx(fs, OP_GETGLOBAL, 0, e->u.s.info); + e->k = VRELOCABLE; + break; + } + case VINDEXED: { + freereg(fs, e->u.s.aux); + freereg(fs, e->u.s.info); + e->u.s.info = luaK_codeABC(fs, OP_GETTABLE, 0, e->u.s.info, e->u.s.aux); + e->k = VRELOCABLE; + break; + } + case VVARARG: + case VCALL: { + luaK_setoneret(fs, e); + break; + } + default: break; /* there is one value available (somewhere) */ + } +} + + +static int code_label (FuncState *fs, int A, int b, int jump) { + luaK_getlabel(fs); /* those instructions may be jump targets */ + return luaK_codeABC(fs, OP_LOADBOOL, A, b, jump); +} + + +static void discharge2reg (FuncState *fs, expdesc *e, int reg) { + luaK_dischargevars(fs, e); + switch (e->k) { + case VNIL: { + luaK_nil(fs, reg, 1); + break; + } + case VFALSE: case VTRUE: { + luaK_codeABC(fs, OP_LOADBOOL, reg, e->k == VTRUE, 0); + break; + } + case VK: { + luaK_codeABx(fs, OP_LOADK, reg, e->u.s.info); + break; + } + case VKNUM: { + luaK_codeABx(fs, OP_LOADK, reg, luaK_numberK(fs, e->u.nval)); + break; + } + case VRELOCABLE: { + Instruction *pc = &getcode(fs, e); + SETARG_A(*pc, reg); + break; + } + case VNONRELOC: { + if (reg != e->u.s.info) + luaK_codeABC(fs, OP_MOVE, reg, e->u.s.info, 0); + break; + } + default: { + lua_assert(e->k == VVOID || e->k == VJMP); + return; /* nothing to do... */ + } + } + e->u.s.info = reg; + e->k = VNONRELOC; +} + + +static void discharge2anyreg (FuncState *fs, expdesc *e) { + if (e->k != VNONRELOC) { + luaK_reserveregs(fs, 1); + discharge2reg(fs, e, fs->freereg-1); + } +} + + +static void exp2reg (FuncState *fs, expdesc *e, int reg) { + discharge2reg(fs, e, reg); + if (e->k == VJMP) + luaK_concat(fs, &e->t, e->u.s.info); /* put this jump in `t' list */ + if (hasjumps(e)) { + int final; /* position after whole expression */ + int p_f = NO_JUMP; /* position of an eventual LOAD false */ + int p_t = NO_JUMP; /* position of an eventual LOAD true */ + if (need_value(fs, e->t) || need_value(fs, e->f)) { + int fj = (e->k == VJMP) ? NO_JUMP : luaK_jump(fs); + p_f = code_label(fs, reg, 0, 1); + p_t = code_label(fs, reg, 1, 0); + luaK_patchtohere(fs, fj); + } + final = luaK_getlabel(fs); + patchlistaux(fs, e->f, final, reg, p_f); + patchlistaux(fs, e->t, final, reg, p_t); + } + e->f = e->t = NO_JUMP; + e->u.s.info = reg; + e->k = VNONRELOC; +} + + +void luaK_exp2nextreg (FuncState *fs, expdesc *e) { + luaK_dischargevars(fs, e); + freeexp(fs, e); + luaK_reserveregs(fs, 1); + exp2reg(fs, e, fs->freereg - 1); +} + + +int luaK_exp2anyreg (FuncState *fs, expdesc *e) { + luaK_dischargevars(fs, e); + if (e->k == VNONRELOC) { + if (!hasjumps(e)) return e->u.s.info; /* exp is already in a register */ + if (e->u.s.info >= fs->nactvar) { /* reg. is not a local? */ + exp2reg(fs, e, e->u.s.info); /* put value on it */ + return e->u.s.info; + } + } + luaK_exp2nextreg(fs, e); /* default */ + return e->u.s.info; +} + + +void luaK_exp2val (FuncState *fs, expdesc *e) { + if (hasjumps(e)) + luaK_exp2anyreg(fs, e); + else + luaK_dischargevars(fs, e); +} + + +int luaK_exp2RK (FuncState *fs, expdesc *e) { + luaK_exp2val(fs, e); + switch (e->k) { + case VKNUM: + case VTRUE: + case VFALSE: + case VNIL: { + if (fs->nk <= MAXINDEXRK) { /* constant fit in RK operand? */ + e->u.s.info = (e->k == VNIL) ? nilK(fs) : + (e->k == VKNUM) ? luaK_numberK(fs, e->u.nval) : + boolK(fs, (e->k == VTRUE)); + e->k = VK; + return RKASK(e->u.s.info); + } + else break; + } + case VK: { + if (e->u.s.info <= MAXINDEXRK) /* constant fit in argC? */ + return RKASK(e->u.s.info); + else break; + } + default: break; + } + /* not a constant in the right range: put it in a register */ + return luaK_exp2anyreg(fs, e); +} + + +void luaK_storevar (FuncState *fs, expdesc *var, expdesc *ex) { + switch (var->k) { + case VLOCAL: { + freeexp(fs, ex); + exp2reg(fs, ex, var->u.s.info); + return; + } + case VUPVAL: { + int e = luaK_exp2anyreg(fs, ex); + luaK_codeABC(fs, OP_SETUPVAL, e, var->u.s.info, 0); + break; + } + case VGLOBAL: { + int e = luaK_exp2anyreg(fs, ex); + luaK_codeABx(fs, OP_SETGLOBAL, e, var->u.s.info); + break; + } + case VINDEXED: { + int e = luaK_exp2RK(fs, ex); + luaK_codeABC(fs, OP_SETTABLE, var->u.s.info, var->u.s.aux, e); + break; + } + default: { + lua_assert(0); /* invalid var kind to store */ + break; + } + } + freeexp(fs, ex); +} + + +void luaK_self (FuncState *fs, expdesc *e, expdesc *key) { + int func; + luaK_exp2anyreg(fs, e); + freeexp(fs, e); + func = fs->freereg; + luaK_reserveregs(fs, 2); + luaK_codeABC(fs, OP_SELF, func, e->u.s.info, luaK_exp2RK(fs, key)); + freeexp(fs, key); + e->u.s.info = func; + e->k = VNONRELOC; +} + + +static void invertjump (FuncState *fs, expdesc *e) { + Instruction *pc = getjumpcontrol(fs, e->u.s.info); + lua_assert(testTMode(GET_OPCODE(*pc)) && GET_OPCODE(*pc) != OP_TESTSET && + GET_OPCODE(*pc) != OP_TEST); + SETARG_A(*pc, !(GETARG_A(*pc))); +} + + +static int jumponcond (FuncState *fs, expdesc *e, int cond) { + if (e->k == VRELOCABLE) { + Instruction ie = getcode(fs, e); + if (GET_OPCODE(ie) == OP_NOT) { + fs->pc--; /* remove previous OP_NOT */ + return condjump(fs, OP_TEST, GETARG_B(ie), 0, !cond); + } + /* else go through */ + } + discharge2anyreg(fs, e); + freeexp(fs, e); + return condjump(fs, OP_TESTSET, NO_REG, e->u.s.info, cond); +} + + +void luaK_goiftrue (FuncState *fs, expdesc *e) { + int pc; /* pc of last jump */ + luaK_dischargevars(fs, e); + switch (e->k) { + case VK: case VKNUM: case VTRUE: { + pc = NO_JUMP; /* always true; do nothing */ + break; + } + case VFALSE: { + pc = luaK_jump(fs); /* always jump */ + break; + } + case VJMP: { + invertjump(fs, e); + pc = e->u.s.info; + break; + } + default: { + pc = jumponcond(fs, e, 0); + break; + } + } + luaK_concat(fs, &e->f, pc); /* insert last jump in `f' list */ + luaK_patchtohere(fs, e->t); + e->t = NO_JUMP; +} + + +static void luaK_goiffalse (FuncState *fs, expdesc *e) { + int pc; /* pc of last jump */ + luaK_dischargevars(fs, e); + switch (e->k) { + case VNIL: case VFALSE: { + pc = NO_JUMP; /* always false; do nothing */ + break; + } + case VTRUE: { + pc = luaK_jump(fs); /* always jump */ + break; + } + case VJMP: { + pc = e->u.s.info; + break; + } + default: { + pc = jumponcond(fs, e, 1); + break; + } + } + luaK_concat(fs, &e->t, pc); /* insert last jump in `t' list */ + luaK_patchtohere(fs, e->f); + e->f = NO_JUMP; +} + + +static void codenot (FuncState *fs, expdesc *e) { + luaK_dischargevars(fs, e); + switch (e->k) { + case VNIL: case VFALSE: { + e->k = VTRUE; + break; + } + case VK: case VKNUM: case VTRUE: { + e->k = VFALSE; + break; + } + case VJMP: { + invertjump(fs, e); + break; + } + case VRELOCABLE: + case VNONRELOC: { + discharge2anyreg(fs, e); + freeexp(fs, e); + e->u.s.info = luaK_codeABC(fs, OP_NOT, 0, e->u.s.info, 0); + e->k = VRELOCABLE; + break; + } + default: { + lua_assert(0); /* cannot happen */ + break; + } + } + /* interchange true and false lists */ + { int temp = e->f; e->f = e->t; e->t = temp; } + removevalues(fs, e->f); + removevalues(fs, e->t); +} + + +void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) { + t->u.s.aux = luaK_exp2RK(fs, k); + t->k = VINDEXED; +} + + +static int constfolding (OpCode op, expdesc *e1, expdesc *e2) { + lua_Number v1, v2, r; + double d; + if (!isnumeral(e1) || !isnumeral(e2)) return 0; + v1 = e1->u.nval; + v2 = e2->u.nval; + switch (op) { + case OP_BAND: r = luai_numand(v1, v2); break; + case OP_BOR: r = luai_numor(v1, v2); break; + case OP_BXOR: r = luai_numxor(v1, v2); break; + case OP_BSHL: r = luai_numshl(v1, v2); break; + case OP_BSHR: r = luai_numshr(v1, v2); break; + case OP_BNOT: r = luai_numnot(v1); break; + case OP_ADD: r = luai_numadd(v1, v2); break; + case OP_SUB: r = luai_numsub(v1, v2); break; + case OP_MUL: r = luai_nummul(v1, v2); break; + case OP_DIV: + if (v2 == 0) return 0; /* do not attempt to divide by 0 */ + r = luai_numdiv(v1, v2); break; + case OP_MOD: + if (v2 == 0) return 0; /* do not attempt to divide by 0 */ + r = luai_nummod(v1, v2); break; + case OP_POW: d = luai_numpow(v1, v2); r = (lua_Number)d; break; + case OP_UNM: r = luai_numunm(v1); break; + case OP_LEN: return 0; /* no constant folding for 'len' */ + default: lua_assert(0); r = 0; break; + } + if (luai_numisnan(r)) return 0; /* do not attempt to produce NaN */ + e1->u.nval = r; + return 1; +} + + +static void codearith (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2) { + if (constfolding(op, e1, e2)) + return; + else { + int o2 = (op != OP_UNM && op != OP_LEN) ? luaK_exp2RK(fs, e2) : 0; + int o1 = luaK_exp2RK(fs, e1); + if (o1 > o2) { + freeexp(fs, e1); + freeexp(fs, e2); + } + else { + freeexp(fs, e2); + freeexp(fs, e1); + } + e1->u.s.info = luaK_codeABC(fs, op, 0, o1, o2); + e1->k = VRELOCABLE; + } +} + + +static void codecomp (FuncState *fs, OpCode op, int cond, expdesc *e1, + expdesc *e2) { + int o1 = luaK_exp2RK(fs, e1); + int o2 = luaK_exp2RK(fs, e2); + freeexp(fs, e2); + freeexp(fs, e1); + if (cond == 0 && op != OP_EQ) { + int temp; /* exchange args to replace by `<' or `<=' */ + temp = o1; o1 = o2; o2 = temp; /* o1 <==> o2 */ + cond = 1; + } + e1->u.s.info = condjump(fs, op, cond, o1, o2); + e1->k = VJMP; +} + + +void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e) { + expdesc e2; + e2.t = e2.f = NO_JUMP; e2.k = VKNUM; e2.u.nval = 0; + switch (op) { + case OPR_MINUS: { + if (!isnumeral(e)) + luaK_exp2anyreg(fs, e); /* cannot operate on non-numeric constants */ + codearith(fs, OP_UNM, e, &e2); + break; + } + case OPR_BNOT: { + if (e->k == VK) + luaK_exp2anyreg(fs, e); /* cannot operate on non-numeric constants */ + codearith(fs, OP_BNOT, e, &e2); + break; + } + case OPR_NOT: codenot(fs, e); break; + case OPR_LEN: { + luaK_exp2anyreg(fs, e); /* cannot operate on constants */ + codearith(fs, OP_LEN, e, &e2); + break; + } + default: lua_assert(0); + } +} + + +void luaK_infix (FuncState *fs, BinOpr op, expdesc *v) { + switch (op) { + case OPR_AND: { + luaK_goiftrue(fs, v); + break; + } + case OPR_OR: { + luaK_goiffalse(fs, v); + break; + } + case OPR_CONCAT: { + luaK_exp2nextreg(fs, v); /* operand must be on the `stack' */ + break; + } + case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV: + case OPR_MOD: case OPR_POW: { + if (!isnumeral(v)) luaK_exp2RK(fs, v); + break; + } + default: { + luaK_exp2RK(fs, v); + break; + } + } +} + + +void luaK_posfix (FuncState *fs, BinOpr op, expdesc *e1, expdesc *e2) { + switch (op) { + case OPR_AND: { + lua_assert(e1->t == NO_JUMP); /* list must be closed */ + luaK_dischargevars(fs, e2); + luaK_concat(fs, &e2->f, e1->f); + *e1 = *e2; + break; + } + case OPR_OR: { + lua_assert(e1->f == NO_JUMP); /* list must be closed */ + luaK_dischargevars(fs, e2); + luaK_concat(fs, &e2->t, e1->t); + *e1 = *e2; + break; + } + case OPR_CONCAT: { + luaK_exp2val(fs, e2); + if (e2->k == VRELOCABLE && GET_OPCODE(getcode(fs, e2)) == OP_CONCAT) { + lua_assert(e1->u.s.info == GETARG_B(getcode(fs, e2))-1); + freeexp(fs, e1); + SETARG_B(getcode(fs, e2), e1->u.s.info); + e1->k = VRELOCABLE; e1->u.s.info = e2->u.s.info; + } + else { + luaK_exp2nextreg(fs, e2); /* operand must be on the 'stack' */ + codearith(fs, OP_CONCAT, e1, e2); + } + break; + } + case OPR_BAND: codearith(fs, OP_BAND, e1, e2); break; + case OPR_BOR: codearith(fs, OP_BOR, e1, e2); break; + case OPR_BXOR: codearith(fs, OP_BXOR, e1, e2); break; + case OPR_BSHL: codearith(fs, OP_BSHL, e1, e2); break; + case OPR_BSHR: codearith(fs, OP_BSHR, e1, e2); break; + case OPR_ADD: codearith(fs, OP_ADD, e1, e2); break; + case OPR_SUB: codearith(fs, OP_SUB, e1, e2); break; + case OPR_MUL: codearith(fs, OP_MUL, e1, e2); break; + case OPR_DIV: codearith(fs, OP_DIV, e1, e2); break; + case OPR_MOD: codearith(fs, OP_MOD, e1, e2); break; + case OPR_POW: codearith(fs, OP_POW, e1, e2); break; + case OPR_EQ: codecomp(fs, OP_EQ, 1, e1, e2); break; + case OPR_NE: codecomp(fs, OP_EQ, 0, e1, e2); break; + case OPR_LT: codecomp(fs, OP_LT, 1, e1, e2); break; + case OPR_LE: codecomp(fs, OP_LE, 1, e1, e2); break; + case OPR_GT: codecomp(fs, OP_LT, 0, e1, e2); break; + case OPR_GE: codecomp(fs, OP_LE, 0, e1, e2); break; + default: lua_assert(0); + } +} + + +void luaK_fixline (FuncState *fs, int line) { + fs->f->lineinfo[fs->pc - 1] = line; +} + + +static int luaK_code (FuncState *fs, Instruction i, int line) { + Proto *f = fs->f; + dischargejpc(fs); /* `pc' will change */ + /* put new instruction in code array */ + luaM_growvector(fs->L, f->code, fs->pc, f->sizecode, Instruction, + MAX_INT, "code size overflow"); + f->code[fs->pc] = i; + /* save corresponding line information */ + luaM_growvector(fs->L, f->lineinfo, fs->pc, f->sizelineinfo, int, + MAX_INT, "code size overflow"); + f->lineinfo[fs->pc] = line; + return fs->pc++; +} + + +int luaK_codeABC (FuncState *fs, OpCode o, int a, int b, int c) { + lua_assert(getOpMode(o) == iABC); + lua_assert(getBMode(o) != OpArgN || b == 0); + lua_assert(getCMode(o) != OpArgN || c == 0); + return luaK_code(fs, CREATE_ABC(o, a, b, c), fs->ls->lastline); +} + + +int luaK_codeABx (FuncState *fs, OpCode o, int a, unsigned int bc) { + lua_assert(getOpMode(o) == iABx || getOpMode(o) == iAsBx); + lua_assert(getCMode(o) == OpArgN); + return luaK_code(fs, CREATE_ABx(o, a, bc), fs->ls->lastline); +} + + +void luaK_setlist (FuncState *fs, int base, int nelems, int tostore) { + int c = (nelems - 1)/LFIELDS_PER_FLUSH + 1; + int b = (tostore == LUA_MULTRET) ? 0 : tostore; + lua_assert(tostore != 0); + if (c <= MAXARG_C) + luaK_codeABC(fs, OP_SETLIST, base, b, c); + else { + luaK_codeABC(fs, OP_SETLIST, base, b, 0); + luaK_code(fs, cast(Instruction, c), fs->ls->lastline); + } + fs->freereg = base + 1; /* free registers with list values */ +} diff --git a/src/blua/lcode.h b/src/blua/lcode.h new file mode 100644 index 000000000..5b8009472 --- /dev/null +++ b/src/blua/lcode.h @@ -0,0 +1,78 @@ +/* +** $Id: lcode.h,v 1.48.1.1 2007/12/27 13:02:25 roberto Exp $ +** Code generator for Lua +** See Copyright Notice in lua.h +*/ + +#ifndef lcode_h +#define lcode_h + +#include "llex.h" +#include "lobject.h" +#include "lopcodes.h" +#include "lparser.h" + + +/* +** Marks the end of a patch list. It is an invalid value both as an absolute +** address, and as a list link (would link an element to itself). +*/ +#define NO_JUMP (-1) + + +/* +** grep "ORDER OPR" if you change these enums +*/ +typedef enum BinOpr { + OPR_ADD, OPR_SUB, OPR_MUL, OPR_DIV, OPR_MOD, OPR_POW, + OPR_CONCAT, + OPR_NE, OPR_EQ, + OPR_LT, OPR_LE, OPR_GT, OPR_GE, + OPR_AND, OPR_OR, + OPR_BAND, OPR_BOR, OPR_BXOR, + OPR_BSHL, OPR_BSHR, + OPR_NOBINOPR +} BinOpr; + + +typedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_LEN, OPR_NOUNOPR, OPR_BNOT } UnOpr; + + +#define getcode(fs,e) ((fs)->f->code[(e)->u.s.info]) + +#define luaK_codeAsBx(fs,o,A,sBx) luaK_codeABx(fs,o,A,(sBx)+MAXARG_sBx) + +#define luaK_setmultret(fs,e) luaK_setreturns(fs, e, LUA_MULTRET) + +LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx); +LUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C); +LUAI_FUNC void luaK_fixline (FuncState *fs, int line); +LUAI_FUNC void luaK_nil (FuncState *fs, int from, int n); +LUAI_FUNC void luaK_reserveregs (FuncState *fs, int n); +LUAI_FUNC void luaK_checkstack (FuncState *fs, int n); +LUAI_FUNC int luaK_stringK (FuncState *fs, TString *s); +LUAI_FUNC int luaK_numberK (FuncState *fs, lua_Number r); +LUAI_FUNC void luaK_dischargevars (FuncState *fs, expdesc *e); +LUAI_FUNC int luaK_exp2anyreg (FuncState *fs, expdesc *e); +LUAI_FUNC void luaK_exp2nextreg (FuncState *fs, expdesc *e); +LUAI_FUNC void luaK_exp2val (FuncState *fs, expdesc *e); +LUAI_FUNC int luaK_exp2RK (FuncState *fs, expdesc *e); +LUAI_FUNC void luaK_self (FuncState *fs, expdesc *e, expdesc *key); +LUAI_FUNC void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k); +LUAI_FUNC void luaK_goiftrue (FuncState *fs, expdesc *e); +LUAI_FUNC void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e); +LUAI_FUNC void luaK_setreturns (FuncState *fs, expdesc *e, int nresults); +LUAI_FUNC void luaK_setoneret (FuncState *fs, expdesc *e); +LUAI_FUNC int luaK_jump (FuncState *fs); +LUAI_FUNC void luaK_ret (FuncState *fs, int first, int nret); +LUAI_FUNC void luaK_patchlist (FuncState *fs, int list, int target); +LUAI_FUNC void luaK_patchtohere (FuncState *fs, int list); +LUAI_FUNC void luaK_concat (FuncState *fs, int *l1, int l2); +LUAI_FUNC int luaK_getlabel (FuncState *fs); +LUAI_FUNC void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v); +LUAI_FUNC void luaK_infix (FuncState *fs, BinOpr op, expdesc *v); +LUAI_FUNC void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1, expdesc *v2); +LUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore); + + +#endif diff --git a/src/blua/ldebug.c b/src/blua/ldebug.c new file mode 100644 index 000000000..497d54980 --- /dev/null +++ b/src/blua/ldebug.c @@ -0,0 +1,637 @@ +/* +** $Id: ldebug.c,v 2.29.1.6 2008/05/08 16:56:26 roberto Exp $ +** Debug Interface +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include + + +#define ldebug_c +#define LUA_CORE + +#include "lua.h" + +#include "lapi.h" +#include "lcode.h" +#include "ldebug.h" +#include "ldo.h" +#include "lfunc.h" +#include "lobject.h" +#include "lopcodes.h" +#include "lstate.h" +#include "lstring.h" +#include "ltable.h" +#include "ltm.h" +#include "lvm.h" + + + +static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name); + + +static int currentpc (lua_State *L, CallInfo *ci) { + if (!isLua(ci)) return -1; /* function is not a Lua function? */ + if (ci == L->ci) + ci->savedpc = L->savedpc; + return pcRel(ci->savedpc, ci_func(ci)->l.p); +} + + +static int currentline (lua_State *L, CallInfo *ci) { + int pc = currentpc(L, ci); + if (pc < 0) + return -1; /* only active lua functions have current-line information */ + else + return getline(ci_func(ci)->l.p, pc); +} + + +/* +** this function can be called asynchronous (e.g. during a signal) +*/ +LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count) { + if (func == NULL || mask == 0) { /* turn off hooks? */ + mask = 0; + func = NULL; + } + L->hook = func; + L->basehookcount = count; + resethookcount(L); + L->hookmask = cast_byte(mask); + return 1; +} + + +LUA_API lua_Hook lua_gethook (lua_State *L) { + return L->hook; +} + + +LUA_API int lua_gethookmask (lua_State *L) { + return L->hookmask; +} + + +LUA_API int lua_gethookcount (lua_State *L) { + return L->basehookcount; +} + + +LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) { + int status; + CallInfo *ci; + lua_lock(L); + for (ci = L->ci; level > 0 && ci > L->base_ci; ci--) { + level--; + if (f_isLua(ci)) /* Lua function? */ + level -= ci->tailcalls; /* skip lost tail calls */ + } + if (level == 0 && ci > L->base_ci) { /* level found? */ + status = 1; + ar->i_ci = cast_int(ci - L->base_ci); + } + else if (level < 0) { /* level is of a lost tail call? */ + status = 1; + ar->i_ci = 0; + } + else status = 0; /* no such level */ + lua_unlock(L); + return status; +} + + +static Proto *getluaproto (CallInfo *ci) { + return (isLua(ci) ? ci_func(ci)->l.p : NULL); +} + + +static const char *findlocal (lua_State *L, CallInfo *ci, int n) { + const char *name; + Proto *fp = getluaproto(ci); + if (fp && (name = luaF_getlocalname(fp, n, currentpc(L, ci))) != NULL) + return name; /* is a local variable in a Lua function */ + else { + StkId limit = (ci == L->ci) ? L->top : (ci+1)->func; + if (limit - ci->base >= n && n > 0) /* is 'n' inside 'ci' stack? */ + return "(*temporary)"; + else + return NULL; + } +} + + +LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) { + CallInfo *ci = L->base_ci + ar->i_ci; + const char *name = findlocal(L, ci, n); + lua_lock(L); + if (name) + luaA_pushobject(L, ci->base + (n - 1)); + lua_unlock(L); + return name; +} + + +LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) { + CallInfo *ci = L->base_ci + ar->i_ci; + const char *name = findlocal(L, ci, n); + lua_lock(L); + if (name) + setobjs2s(L, ci->base + (n - 1), L->top - 1); + L->top--; /* pop value */ + lua_unlock(L); + return name; +} + + +static void funcinfo (lua_Debug *ar, Closure *cl) { + if (cl->c.isC) { + ar->source = "=[C]"; + ar->linedefined = -1; + ar->lastlinedefined = -1; + ar->what = "C"; + } + else { + ar->source = getstr(cl->l.p->source); + ar->linedefined = cl->l.p->linedefined; + ar->lastlinedefined = cl->l.p->lastlinedefined; + ar->what = (ar->linedefined == 0) ? "main" : "Lua"; + } + luaO_chunkid(ar->short_src, ar->source, LUA_IDSIZE); +} + + +static void info_tailcall (lua_Debug *ar) { + ar->name = ar->namewhat = ""; + ar->what = "tail"; + ar->lastlinedefined = ar->linedefined = ar->currentline = -1; + ar->source = "=(tail call)"; + luaO_chunkid(ar->short_src, ar->source, LUA_IDSIZE); + ar->nups = 0; +} + + +static void collectvalidlines (lua_State *L, Closure *f) { + if (f == NULL || f->c.isC) { + setnilvalue(L->top); + } + else { + Table *t = luaH_new(L, 0, 0); + int *lineinfo = f->l.p->lineinfo; + int i; + for (i=0; il.p->sizelineinfo; i++) + setbvalue(luaH_setnum(L, t, lineinfo[i]), 1); + sethvalue(L, L->top, t); + } + incr_top(L); +} + + +static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar, + Closure *f, CallInfo *ci) { + int status = 1; + if (f == NULL) { + info_tailcall(ar); + return status; + } + for (; *what; what++) { + switch (*what) { + case 'S': { + funcinfo(ar, f); + break; + } + case 'l': { + ar->currentline = (ci) ? currentline(L, ci) : -1; + break; + } + case 'u': { + ar->nups = f->c.nupvalues; + break; + } + case 'n': { + ar->namewhat = (ci) ? getfuncname(L, ci, &ar->name) : NULL; + if (ar->namewhat == NULL) { + ar->namewhat = ""; /* not found */ + ar->name = NULL; + } + break; + } + case 'L': + case 'f': /* handled by lua_getinfo */ + break; + default: status = 0; /* invalid option */ + } + } + return status; +} + + +LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { + int status; + Closure *f = NULL; + CallInfo *ci = NULL; + lua_lock(L); + if (*what == '>') { + StkId func = L->top - 1; + luai_apicheck(L, ttisfunction(func)); + what++; /* skip the '>' */ + f = clvalue(func); + L->top--; /* pop function */ + } + else if (ar->i_ci != 0) { /* no tail call? */ + ci = L->base_ci + ar->i_ci; + lua_assert(ttisfunction(ci->func)); + f = clvalue(ci->func); + } + status = auxgetinfo(L, what, ar, f, ci); + if (strchr(what, 'f')) { + if (f == NULL) setnilvalue(L->top); + else setclvalue(L, L->top, f); + incr_top(L); + } + if (strchr(what, 'L')) + collectvalidlines(L, f); + lua_unlock(L); + return status; +} + + +/* +** {====================================================== +** Symbolic Execution and code checker +** ======================================================= +*/ + +#define check(x) if (!(x)) return 0; + +#define checkjump(pt,pc) check(0 <= pc && pc < pt->sizecode) + +#define checkreg(pt,reg) check((reg) < (pt)->maxstacksize) + + + +static int precheck (const Proto *pt) { + check(pt->maxstacksize <= MAXSTACK); + check(pt->numparams+(pt->is_vararg & VARARG_HASARG) <= pt->maxstacksize); + check(!(pt->is_vararg & VARARG_NEEDSARG) || + (pt->is_vararg & VARARG_HASARG)); + check(pt->sizeupvalues <= pt->nups); + check(pt->sizelineinfo == pt->sizecode || pt->sizelineinfo == 0); + check(pt->sizecode > 0 && GET_OPCODE(pt->code[pt->sizecode-1]) == OP_RETURN); + return 1; +} + + +#define checkopenop(pt,pc) luaG_checkopenop((pt)->code[(pc)+1]) + +int luaG_checkopenop (Instruction i) { + switch (GET_OPCODE(i)) { + case OP_CALL: + case OP_TAILCALL: + case OP_RETURN: + case OP_SETLIST: { + check(GETARG_B(i) == 0); + return 1; + } + default: return 0; /* invalid instruction after an open call */ + } +} + + +static int checkArgMode (const Proto *pt, int r, enum OpArgMask mode) { + switch (mode) { + case OpArgN: check(r == 0); break; + case OpArgU: break; + case OpArgR: checkreg(pt, r); break; + case OpArgK: + check(ISK(r) ? INDEXK(r) < pt->sizek : r < pt->maxstacksize); + break; + } + return 1; +} + + +static Instruction symbexec (const Proto *pt, int lastpc, int reg) { + int pc; + int last; /* stores position of last instruction that changed `reg' */ + last = pt->sizecode-1; /* points to final return (a `neutral' instruction) */ + check(precheck(pt)); + for (pc = 0; pc < lastpc; pc++) { + Instruction i = pt->code[pc]; + OpCode op = GET_OPCODE(i); + int a = GETARG_A(i); + int b = 0; + int c = 0; + check(op < NUM_OPCODES); + checkreg(pt, a); + switch (getOpMode(op)) { + case iABC: { + b = GETARG_B(i); + c = GETARG_C(i); + check(checkArgMode(pt, b, getBMode(op))); + check(checkArgMode(pt, c, getCMode(op))); + break; + } + case iABx: { + b = GETARG_Bx(i); + if (getBMode(op) == OpArgK) check(b < pt->sizek); + break; + } + case iAsBx: { + b = GETARG_sBx(i); + if (getBMode(op) == OpArgR) { + int dest = pc+1+b; + check(0 <= dest && dest < pt->sizecode); + if (dest > 0) { + int j; + /* check that it does not jump to a setlist count; this + is tricky, because the count from a previous setlist may + have the same value of an invalid setlist; so, we must + go all the way back to the first of them (if any) */ + for (j = 0; j < dest; j++) { + Instruction d = pt->code[dest-1-j]; + if (!(GET_OPCODE(d) == OP_SETLIST && GETARG_C(d) == 0)) break; + } + /* if 'j' is even, previous value is not a setlist (even if + it looks like one) */ + check((j&1) == 0); + } + } + break; + } + } + if (testAMode(op)) { + if (a == reg) last = pc; /* change register `a' */ + } + if (testTMode(op)) { + check(pc+2 < pt->sizecode); /* check skip */ + check(GET_OPCODE(pt->code[pc+1]) == OP_JMP); + } + switch (op) { + case OP_LOADBOOL: { + if (c == 1) { /* does it jump? */ + check(pc+2 < pt->sizecode); /* check its jump */ + check(GET_OPCODE(pt->code[pc+1]) != OP_SETLIST || + GETARG_C(pt->code[pc+1]) != 0); + } + break; + } + case OP_LOADNIL: { + if (a <= reg && reg <= b) + last = pc; /* set registers from `a' to `b' */ + break; + } + case OP_GETUPVAL: + case OP_SETUPVAL: { + check(b < pt->nups); + break; + } + case OP_GETGLOBAL: + case OP_SETGLOBAL: { + check(ttisstring(&pt->k[b])); + break; + } + case OP_SELF: { + checkreg(pt, a+1); + if (reg == a+1) last = pc; + break; + } + case OP_CONCAT: { + check(b < c); /* at least two operands */ + break; + } + case OP_TFORLOOP: { + check(c >= 1); /* at least one result (control variable) */ + checkreg(pt, a+2+c); /* space for results */ + if (reg >= a+2) last = pc; /* affect all regs above its base */ + break; + } + case OP_FORLOOP: + case OP_FORPREP: + checkreg(pt, a+3); + /* go through */ + case OP_JMP: { + int dest = pc+1+b; + /* not full check and jump is forward and do not skip `lastpc'? */ + if (reg != NO_REG && pc < dest && dest <= lastpc) + pc += b; /* do the jump */ + break; + } + case OP_CALL: + case OP_TAILCALL: { + if (b != 0) { + checkreg(pt, a+b-1); + } + c--; /* c = num. returns */ + if (c == LUA_MULTRET) { + check(checkopenop(pt, pc)); + } + else if (c != 0) + checkreg(pt, a+c-1); + if (reg >= a) last = pc; /* affect all registers above base */ + break; + } + case OP_RETURN: { + b--; /* b = num. returns */ + if (b > 0) checkreg(pt, a+b-1); + break; + } + case OP_SETLIST: { + if (b > 0) checkreg(pt, a + b); + if (c == 0) { + pc++; + check(pc < pt->sizecode - 1); + } + break; + } + case OP_CLOSURE: { + int nup, j; + check(b < pt->sizep); + nup = pt->p[b]->nups; + check(pc + nup < pt->sizecode); + for (j = 1; j <= nup; j++) { + OpCode op1 = GET_OPCODE(pt->code[pc + j]); + check(op1 == OP_GETUPVAL || op1 == OP_MOVE); + } + if (reg != NO_REG) /* tracing? */ + pc += nup; /* do not 'execute' these pseudo-instructions */ + break; + } + case OP_VARARG: { + check((pt->is_vararg & VARARG_ISVARARG) && + !(pt->is_vararg & VARARG_NEEDSARG)); + b--; + if (b == LUA_MULTRET) check(checkopenop(pt, pc)); + checkreg(pt, a+b-1); + break; + } + default: break; + } + } + return pt->code[last]; +} + +#undef check +#undef checkjump +#undef checkreg + +/* }====================================================== */ + + +int luaG_checkcode (const Proto *pt) { + return (symbexec(pt, pt->sizecode, NO_REG) != 0); +} + + +static const char *kname (Proto *p, int c) { + if (ISK(c) && ttisstring(&p->k[INDEXK(c)])) + return svalue(&p->k[INDEXK(c)]); + else + return "?"; +} + + +static const char *getobjname (lua_State *L, CallInfo *ci, int stackpos, + const char **name) { + if (isLua(ci)) { /* a Lua function? */ + Proto *p = ci_func(ci)->l.p; + int pc = currentpc(L, ci); + Instruction i; + *name = luaF_getlocalname(p, stackpos+1, pc); + if (*name) /* is a local? */ + return "local"; + i = symbexec(p, pc, stackpos); /* try symbolic execution */ + lua_assert(pc != -1); + switch (GET_OPCODE(i)) { + case OP_GETGLOBAL: { + int g = GETARG_Bx(i); /* global index */ + lua_assert(ttisstring(&p->k[g])); + *name = svalue(&p->k[g]); + return "global"; + } + case OP_MOVE: { + int a = GETARG_A(i); + int b = GETARG_B(i); /* move from `b' to `a' */ + if (b < a) + return getobjname(L, ci, b, name); /* get name for `b' */ + break; + } + case OP_GETTABLE: { + int k = GETARG_C(i); /* key index */ + *name = kname(p, k); + return "field"; + } + case OP_GETUPVAL: { + int u = GETARG_B(i); /* upvalue index */ + *name = p->upvalues ? getstr(p->upvalues[u]) : "?"; + return "upvalue"; + } + case OP_SELF: { + int k = GETARG_C(i); /* key index */ + *name = kname(p, k); + return "method"; + } + default: break; + } + } + return NULL; /* no useful name found */ +} + + +static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) { + Instruction i; + if ((isLua(ci) && ci->tailcalls > 0) || !isLua(ci - 1)) + return NULL; /* calling function is not Lua (or is unknown) */ + ci--; /* calling function */ + i = ci_func(ci)->l.p->code[currentpc(L, ci)]; + if (GET_OPCODE(i) == OP_CALL || GET_OPCODE(i) == OP_TAILCALL || + GET_OPCODE(i) == OP_TFORLOOP) + return getobjname(L, ci, GETARG_A(i), name); + else + return NULL; /* no useful name can be found */ +} + + +/* only ANSI way to check whether a pointer points to an array */ +static int isinstack (CallInfo *ci, const TValue *o) { + StkId p; + for (p = ci->base; p < ci->top; p++) + if (o == p) return 1; + return 0; +} + + +void luaG_typeerror (lua_State *L, const TValue *o, const char *op) { + const char *name = NULL; + const char *t = luaT_typenames[ttype(o)]; + const char *kind = (isinstack(L->ci, o)) ? + getobjname(L, L->ci, cast_int(o - L->base), &name) : + NULL; + if (kind) + luaG_runerror(L, "attempt to %s %s " LUA_QS " (a %s value)", + op, kind, name, t); + else + luaG_runerror(L, "attempt to %s a %s value", op, t); +} + + +void luaG_concaterror (lua_State *L, StkId p1, StkId p2) { + if (ttisstring(p1) || ttisnumber(p1)) p1 = p2; + lua_assert(!ttisstring(p1) && !ttisnumber(p1)); + luaG_typeerror(L, p1, "concatenate"); +} + + +void luaG_aritherror (lua_State *L, const TValue *p1, const TValue *p2) { + TValue temp; + if (luaV_tonumber(p1, &temp) == NULL) + p2 = p1; /* first operand is wrong */ + luaG_typeerror(L, p2, "perform arithmetic on"); +} + + +int luaG_ordererror (lua_State *L, const TValue *p1, const TValue *p2) { + const char *t1 = luaT_typenames[ttype(p1)]; + const char *t2 = luaT_typenames[ttype(p2)]; + if (t1[2] == t2[2]) + luaG_runerror(L, "attempt to compare two %s values", t1); + else + luaG_runerror(L, "attempt to compare %s with %s", t1, t2); + return 0; +} + + +static void addinfo (lua_State *L, const char *msg) { + CallInfo *ci = L->ci; + if (isLua(ci)) { /* is Lua code? */ + char buff[LUA_IDSIZE]; /* add file:line information */ + int line = currentline(L, ci); + luaO_chunkid(buff, getstr(getluaproto(ci)->source), LUA_IDSIZE); + luaO_pushfstring(L, "%s:%d: %s", buff, line, msg); + } +} + + +void luaG_errormsg (lua_State *L) { + if (L->errfunc != 0) { /* is there an error handling function? */ + StkId errfunc = restorestack(L, L->errfunc); + if (!ttisfunction(errfunc)) luaD_throw(L, LUA_ERRERR); + setobjs2s(L, L->top, L->top - 1); /* move argument */ + setobjs2s(L, L->top - 1, errfunc); /* push function */ + incr_top(L); + luaD_call(L, L->top - 2, 1); /* call it */ + } + luaD_throw(L, LUA_ERRRUN); +} + + +void luaG_runerror (lua_State *L, const char *fmt, ...) { + va_list argp; + va_start(argp, fmt); + addinfo(L, luaO_pushvfstring(L, fmt, argp)); + va_end(argp); + luaG_errormsg(L); +} diff --git a/src/blua/ldebug.h b/src/blua/ldebug.h new file mode 100644 index 000000000..ba28a9724 --- /dev/null +++ b/src/blua/ldebug.h @@ -0,0 +1,33 @@ +/* +** $Id: ldebug.h,v 2.3.1.1 2007/12/27 13:02:25 roberto Exp $ +** Auxiliary functions from Debug Interface module +** See Copyright Notice in lua.h +*/ + +#ifndef ldebug_h +#define ldebug_h + + +#include "lstate.h" + + +#define pcRel(pc, p) (cast(int, (pc) - (p)->code) - 1) + +#define getline(f,pc) (((f)->lineinfo) ? (f)->lineinfo[pc] : 0) + +#define resethookcount(L) (L->hookcount = L->basehookcount) + + +LUAI_FUNC void luaG_typeerror (lua_State *L, const TValue *o, + const char *opname); +LUAI_FUNC void luaG_concaterror (lua_State *L, StkId p1, StkId p2); +LUAI_FUNC void luaG_aritherror (lua_State *L, const TValue *p1, + const TValue *p2); +LUAI_FUNC int luaG_ordererror (lua_State *L, const TValue *p1, + const TValue *p2); +LUAI_FUNC void luaG_runerror (lua_State *L, const char *fmt, ...); +LUAI_FUNC void luaG_errormsg (lua_State *L); +LUAI_FUNC int luaG_checkcode (const Proto *pt); +LUAI_FUNC int luaG_checkopenop (Instruction i); + +#endif diff --git a/src/blua/ldo.c b/src/blua/ldo.c new file mode 100644 index 000000000..7470a79b7 --- /dev/null +++ b/src/blua/ldo.c @@ -0,0 +1,535 @@ +/* +** $Id: ldo.c,v 2.38.1.3 2008/01/18 22:31:22 roberto Exp $ +** Stack and Call structure of Lua +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include + +#define ldo_c +#define LUA_CORE + +#include "lua.h" + +#include "ldebug.h" +#include "ldo.h" +#include "lfunc.h" +#include "lgc.h" +#include "lmem.h" +#include "lobject.h" +#include "lopcodes.h" +#include "lparser.h" +#include "lstate.h" +#include "lstring.h" +#include "ltable.h" +#include "ltm.h" +#include "lundump.h" +#include "lvm.h" +#include "lzio.h" + +#ifdef __GNUC__ + #ifndef FUNCNORETURN + #define FUNCNORETURN __attribute__ ((noreturn)) + #endif + #endif + +#ifndef FUNCNORETURN +#define FUNCNORETURN +#endif + +/* +** {====================================================== +** Error-recovery functions +** ======================================================= +*/ + +#ifdef _MSC_VER +#pragma warning(disable : 4324) +#endif + +/* chain list of long jump buffers */ +struct lua_longjmp { + struct lua_longjmp *previous; + luai_jmpbuf b; + volatile int status; /* error code */ +}; + +#ifdef _MSC_VER +#pragma warning(default : 4324) +#endif + +void luaD_seterrorobj (lua_State *L, int lerrcode, StkId oldtop) { + switch (lerrcode) { + case LUA_ERRMEM: { + setsvalue2s(L, oldtop, luaS_newliteral(L, MEMERRMSG)); + break; + } + case LUA_ERRERR: { + setsvalue2s(L, oldtop, luaS_newliteral(L, "error in error handling")); + break; + } + case LUA_ERRSYNTAX: + case LUA_ERRRUN: { + setobjs2s(L, oldtop, L->top - 1); /* error message on current top */ + break; + } + } + L->top = oldtop + 1; +} + + +static void restore_stack_limit (lua_State *L) { + lua_assert(L->stack_last - L->stack == L->stacksize - EXTRA_STACK - 1); + if (L->size_ci > LUAI_MAXCALLS) { /* there was an overflow? */ + int inuse = cast_int(L->ci - L->base_ci); + if (inuse + 1 < LUAI_MAXCALLS) /* can `undo' overflow? */ + luaD_reallocCI(L, LUAI_MAXCALLS); + } +} + + +static void resetstack (lua_State *L, int status) { + L->ci = L->base_ci; + L->base = L->ci->base; + luaF_close(L, L->base); /* close eventual pending closures */ + luaD_seterrorobj(L, status, L->base); + L->nCcalls = L->baseCcalls; + L->allowhook = 1; + restore_stack_limit(L); + L->errfunc = 0; + L->errorJmp = NULL; +} + + +FUNCNORETURN void luaD_throw (lua_State *L, int lerrcode) { + if (L->errorJmp) { + L->errorJmp->status = lerrcode; + LUAI_THROW(L, L->errorJmp); + } + else { + L->status = cast_byte(lerrcode); + if (G(L)->panic) { + resetstack(L, lerrcode); + lua_unlock(L); + G(L)->panic(L); + } + exit(EXIT_FAILURE); + } +} + + +int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) { + struct lua_longjmp lj; + lj.status = 0; + lj.previous = L->errorJmp; /* chain new error handler */ + L->errorJmp = &lj; + LUAI_TRY(L, &lj, + (*f)(L, ud); + ); + L->errorJmp = lj.previous; /* restore old error handler */ + return lj.status; +} + +/* }====================================================== */ + + +static void correctstack (lua_State *L, TValue *oldstack) { + CallInfo *ci; + GCObject *up; + L->top = (L->top - oldstack) + L->stack; + for (up = L->openupval; up != NULL; up = up->gch.next) + gco2uv(up)->v = (gco2uv(up)->v - oldstack) + L->stack; + for (ci = L->base_ci; ci <= L->ci; ci++) { + ci->top = (ci->top - oldstack) + L->stack; + ci->base = (ci->base - oldstack) + L->stack; + ci->func = (ci->func - oldstack) + L->stack; + } + L->base = (L->base - oldstack) + L->stack; +} + + +void luaD_reallocstack (lua_State *L, int newsize) { + TValue *oldstack = L->stack; + int realsize = newsize + 1 + EXTRA_STACK; + lua_assert(L->stack_last - L->stack == L->stacksize - EXTRA_STACK - 1); + luaM_reallocvector(L, L->stack, L->stacksize, realsize, TValue); + L->stacksize = realsize; + L->stack_last = L->stack+newsize; + correctstack(L, oldstack); +} + + +void luaD_reallocCI (lua_State *L, int newsize) { + CallInfo *oldci = L->base_ci; + luaM_reallocvector(L, L->base_ci, L->size_ci, newsize, CallInfo); + L->size_ci = newsize; + L->ci = (L->ci - oldci) + L->base_ci; + L->end_ci = L->base_ci + L->size_ci - 1; +} + + +void luaD_growstack (lua_State *L, int n) { + if (n <= L->stacksize) /* double size is enough? */ + luaD_reallocstack(L, 2*L->stacksize); + else + luaD_reallocstack(L, L->stacksize + n); +} + + +static CallInfo *growCI (lua_State *L) { + if (L->size_ci > LUAI_MAXCALLS) /* overflow while handling overflow? */ + luaD_throw(L, LUA_ERRERR); + else { + luaD_reallocCI(L, 2*L->size_ci); + if (L->size_ci > LUAI_MAXCALLS) + luaG_runerror(L, "stack overflow"); + } + return ++L->ci; +} + + +void luaD_callhook (lua_State *L, int event, int line) { + lua_Hook hook = L->hook; + if (hook && L->allowhook) { + ptrdiff_t top = savestack(L, L->top); + ptrdiff_t ci_top = savestack(L, L->ci->top); + lua_Debug ar; + ar.event = event; + ar.currentline = line; + if (event == LUA_HOOKTAILRET) + ar.i_ci = 0; /* tail call; no debug information about it */ + else + ar.i_ci = cast_int(L->ci - L->base_ci); + luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ + L->ci->top = L->top + LUA_MINSTACK; + lua_assert(L->ci->top <= L->stack_last); + L->allowhook = 0; /* cannot call hooks inside a hook */ + lua_unlock(L); + (*hook)(L, &ar); + lua_lock(L); + lua_assert(!L->allowhook); + L->allowhook = 1; + L->ci->top = restorestack(L, ci_top); + L->top = restorestack(L, top); + } +} + + +static StkId adjust_varargs (lua_State *L, Proto *p, int actual) { + int i; + int nfixargs = p->numparams; + Table *htab = NULL; + StkId base, fixed; + for (; actual < nfixargs; ++actual) + setnilvalue(L->top++); +#if defined(LUA_COMPAT_VARARG) + if (p->is_vararg & VARARG_NEEDSARG) { /* compat. with old-style vararg? */ + int nvar = actual - nfixargs; /* number of extra arguments */ + lua_assert(p->is_vararg & VARARG_HASARG); + luaC_checkGC(L); + htab = luaH_new(L, nvar, 1); /* create `arg' table */ + for (i=0; itop - nvar + i); + /* store counter in field `n' */ + setnvalue(luaH_setstr(L, htab, luaS_newliteral(L, "n")), cast_num(nvar)); + } +#endif + /* move fixed parameters to final position */ + fixed = L->top - actual; /* first fixed argument */ + base = L->top; /* final position of first argument */ + for (i=0; itop++, fixed+i); + setnilvalue(fixed+i); + } + /* add `arg' parameter */ + if (htab) { + sethvalue(L, L->top++, htab); + lua_assert(iswhite(obj2gco(htab))); + } + return base; +} + + +static StkId tryfuncTM (lua_State *L, StkId func) { + const TValue *tm = luaT_gettmbyobj(L, func, TM_CALL); + StkId p; + ptrdiff_t funcr = savestack(L, func); + if (!ttisfunction(tm)) + luaG_typeerror(L, func, "call"); + /* Open a hole inside the stack at `func' */ + for (p = L->top; p > func; p--) setobjs2s(L, p, p-1); + incr_top(L); + func = restorestack(L, funcr); /* previous call may change stack */ + setobj2s(L, func, tm); /* tag method is the new function to be called */ + return func; +} + + + +#define inc_ci(L) \ + ((L->ci == L->end_ci) ? growCI(L) : \ + (condhardstacktests(luaD_reallocCI(L, L->size_ci)), ++L->ci)) + + +int luaD_precall (lua_State *L, StkId func, int nresults) { + LClosure *cl; + ptrdiff_t funcr; + if (!ttisfunction(func)) /* `func' is not a function? */ + func = tryfuncTM(L, func); /* check the `function' tag method */ + funcr = savestack(L, func); + cl = &clvalue(func)->l; + L->ci->savedpc = L->savedpc; + if (!cl->isC) { /* Lua function? prepare its call */ + CallInfo *ci; + StkId st, base; + Proto *p = cl->p; + luaD_checkstack(L, p->maxstacksize); + func = restorestack(L, funcr); + if (!p->is_vararg) { /* no varargs? */ + base = func + 1; + if (L->top > base + p->numparams) + L->top = base + p->numparams; + } + else { /* vararg function */ + int nargs = cast_int(L->top - func) - 1; + base = adjust_varargs(L, p, nargs); + func = restorestack(L, funcr); /* previous call may change the stack */ + } + ci = inc_ci(L); /* now `enter' new function */ + ci->func = func; + L->base = ci->base = base; + ci->top = L->base + p->maxstacksize; + lua_assert(ci->top <= L->stack_last); + L->savedpc = p->code; /* starting point */ + ci->tailcalls = 0; + ci->nresults = nresults; + for (st = L->top; st < ci->top; st++) + setnilvalue(st); + L->top = ci->top; + if (L->hookmask & LUA_MASKCALL) { + L->savedpc++; /* hooks assume 'pc' is already incremented */ + luaD_callhook(L, LUA_HOOKCALL, -1); + L->savedpc--; /* correct 'pc' */ + } + return PCRLUA; + } + else { /* if is a C function, call it */ + CallInfo *ci; + int n; + luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ + ci = inc_ci(L); /* now `enter' new function */ + ci->func = restorestack(L, funcr); + L->base = ci->base = ci->func + 1; + ci->top = L->top + LUA_MINSTACK; + lua_assert(ci->top <= L->stack_last); + ci->nresults = nresults; + if (L->hookmask & LUA_MASKCALL) + luaD_callhook(L, LUA_HOOKCALL, -1); + lua_unlock(L); + n = (*curr_func(L)->c.f)(L); /* do the actual call */ + lua_lock(L); + if (n < 0) /* yielding? */ + return PCRYIELD; + else { + luaD_poscall(L, L->top - n); + return PCRC; + } + } +} + + +static StkId callrethooks (lua_State *L, StkId firstResult) { + ptrdiff_t fr = savestack(L, firstResult); /* next call may change stack */ + luaD_callhook(L, LUA_HOOKRET, -1); + if (f_isLua(L->ci)) { /* Lua function? */ + while ((L->hookmask & LUA_MASKRET) && L->ci->tailcalls--) /* tail calls */ + luaD_callhook(L, LUA_HOOKTAILRET, -1); + } + return restorestack(L, fr); +} + + +int luaD_poscall (lua_State *L, StkId firstResult) { + StkId res; + int wanted, i; + CallInfo *ci; + if (L->hookmask & LUA_MASKRET) + firstResult = callrethooks(L, firstResult); + ci = L->ci--; + res = ci->func; /* res == final position of 1st result */ + wanted = ci->nresults; + L->base = (ci - 1)->base; /* restore base */ + L->savedpc = (ci - 1)->savedpc; /* restore savedpc */ + /* move results to correct place */ + for (i = wanted; i != 0 && firstResult < L->top; i--) + setobjs2s(L, res++, firstResult++); + while (i-- > 0) + setnilvalue(res++); + L->top = res; + return (wanted - LUA_MULTRET); /* 0 iff wanted == LUA_MULTRET */ +} + + +/* +** Call a function (C or Lua). The function to be called is at *func. +** The arguments are on the stack, right after the function. +** When returns, all the results are on the stack, starting at the original +** function position. +*/ +void luaD_call (lua_State *L, StkId func, int nResults) { + if (++L->nCcalls >= LUAI_MAXCCALLS) { + if (L->nCcalls == LUAI_MAXCCALLS) + luaG_runerror(L, "C stack overflow"); + else if (L->nCcalls >= (LUAI_MAXCCALLS + (LUAI_MAXCCALLS>>3))) + luaD_throw(L, LUA_ERRERR); /* error while handing stack error */ + } + if (luaD_precall(L, func, nResults) == PCRLUA) /* is a Lua function? */ + luaV_execute(L, 1); /* call it */ + L->nCcalls--; + luaC_checkGC(L); +} + + +static void resume (lua_State *L, void *ud) { + StkId firstArg = cast(StkId, ud); + CallInfo *ci = L->ci; + if (L->status == 0) { /* start coroutine? */ + lua_assert(ci == L->base_ci && firstArg > L->base); + if (luaD_precall(L, firstArg - 1, LUA_MULTRET) != PCRLUA) + return; + } + else { /* resuming from previous yield */ + lua_assert(L->status == LUA_YIELD); + L->status = 0; + if (!f_isLua(ci)) { /* `common' yield? */ + /* finish interrupted execution of `OP_CALL' */ + lua_assert(GET_OPCODE(*((ci-1)->savedpc - 1)) == OP_CALL || + GET_OPCODE(*((ci-1)->savedpc - 1)) == OP_TAILCALL); + if (luaD_poscall(L, firstArg)) /* complete it... */ + L->top = L->ci->top; /* and correct top if not multiple results */ + } + else /* yielded inside a hook: just continue its execution */ + L->base = L->ci->base; + } + luaV_execute(L, cast_int(L->ci - L->base_ci)); +} + + +static int resume_error (lua_State *L, const char *msg) { + L->top = L->ci->base; + setsvalue2s(L, L->top, luaS_new(L, msg)); + incr_top(L); + lua_unlock(L); + return LUA_ERRRUN; +} + + +LUA_API int lua_resume (lua_State *L, int nargs) { + int status; + lua_lock(L); + if (L->status != LUA_YIELD && (L->status != 0 || L->ci != L->base_ci)) + return resume_error(L, "cannot resume non-suspended coroutine"); + if (L->nCcalls >= LUAI_MAXCCALLS) + return resume_error(L, "C stack overflow"); + luai_userstateresume(L, nargs); + lua_assert(L->errfunc == 0); + L->baseCcalls = ++L->nCcalls; + status = luaD_rawrunprotected(L, resume, L->top - nargs); + if (status != 0) { /* error? */ + L->status = cast_byte(status); /* mark thread as `dead' */ + luaD_seterrorobj(L, status, L->top); + L->ci->top = L->top; + } + else { + lua_assert(L->nCcalls == L->baseCcalls); + status = L->status; + } + --L->nCcalls; + lua_unlock(L); + return status; +} + + +LUA_API int lua_yield (lua_State *L, int nresults) { + luai_userstateyield(L, nresults); + lua_lock(L); + if (L->nCcalls > L->baseCcalls) + luaG_runerror(L, "attempt to yield across metamethod/C-call boundary"); + L->base = L->top - nresults; /* protect stack slots below */ + L->status = LUA_YIELD; + lua_unlock(L); + return -1; +} + + +int luaD_pcall (lua_State *L, Pfunc func, void *u, + ptrdiff_t old_top, ptrdiff_t ef) { + int status; + unsigned short oldnCcalls = L->nCcalls; + ptrdiff_t old_ci = saveci(L, L->ci); + lu_byte old_allowhooks = L->allowhook; + ptrdiff_t old_errfunc = L->errfunc; + L->errfunc = ef; + status = luaD_rawrunprotected(L, func, u); + if (status != 0) { /* an error occurred? */ + StkId oldtop = restorestack(L, old_top); + luaF_close(L, oldtop); /* close eventual pending closures */ + luaD_seterrorobj(L, status, oldtop); + L->nCcalls = oldnCcalls; + L->ci = restoreci(L, old_ci); + L->base = L->ci->base; + L->savedpc = L->ci->savedpc; + L->allowhook = old_allowhooks; + restore_stack_limit(L); + } + L->errfunc = old_errfunc; + return status; +} + + + +/* +** Execute a protected parser. +*/ +struct SParser { /* data to `f_parser' */ + ZIO *z; + Mbuffer buff; /* buffer to be used by the scanner */ + const char *name; +}; + +static void f_parser (lua_State *L, void *ud) { + int i; + Proto *tf; + Closure *cl; + struct SParser *p = cast(struct SParser *, ud); + int c = luaZ_lookahead(p->z); + luaC_checkGC(L); +#ifdef LUA_ALLOW_BYTECODE + tf = ((c == LUA_SIGNATURE[0]) ? luaU_undump : luaY_parser)(L, p->z, + &p->buff, p->name); +#else + if (c == LUA_SIGNATURE[0]) + luaG_runerror(L, "invalid format, cannot load bytecode scripts"); + tf = luaY_parser(L, p->z, &p->buff, p->name); +#endif + cl = luaF_newLclosure(L, tf->nups, hvalue(gt(L))); + cl->l.p = tf; + for (i = 0; i < tf->nups; i++) /* initialize eventual upvalues */ + cl->l.upvals[i] = luaF_newupval(L); + setclvalue(L, L->top, cl); + incr_top(L); +} + + +int luaD_protectedparser (lua_State *L, ZIO *z, const char *name) { + struct SParser p; + int status; + p.z = z; p.name = name; + luaZ_initbuffer(L, &p.buff); + status = luaD_pcall(L, f_parser, &p, savestack(L, L->top), L->errfunc); + luaZ_freebuffer(L, &p.buff); + return status; +} diff --git a/src/blua/ldo.h b/src/blua/ldo.h new file mode 100644 index 000000000..29364965f --- /dev/null +++ b/src/blua/ldo.h @@ -0,0 +1,66 @@ +/* +** $Id: ldo.h,v 2.7.1.1 2007/12/27 13:02:25 roberto Exp $ +** Stack and Call structure of Lua +** See Copyright Notice in lua.h +*/ + +#ifndef ldo_h +#define ldo_h + + +#include "lobject.h" +#include "lstate.h" +#include "lzio.h" + + +#define luaD_checkstack(L,n) \ + if ((char *)L->stack_last - (char *)L->top <= (n)*(int)sizeof(TValue)) \ + luaD_growstack(L, n); \ + else condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK - 1)); + + +#define incr_top(L) {luaD_checkstack(L,1); L->top++;} + +#define savestack(L,p) ((char *)(p) - (char *)L->stack) +#define restorestack(L,n) ((TValue *)(void *)((char *)L->stack + (n))) + +#define saveci(L,p) ((char *)(p) - (char *)L->base_ci) +#define restoreci(L,n) ((CallInfo *)(void *)((char *)L->base_ci + (n))) + + +/* results from luaD_precall */ +#define PCRLUA 0 /* initiated a call to a Lua function */ +#define PCRC 1 /* did a call to a C function */ +#define PCRYIELD 2 /* C funtion yielded */ + + +/* type of protected functions, to be ran by `runprotected' */ +typedef void (*Pfunc) (lua_State *L, void *ud); + +LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name); +LUAI_FUNC void luaD_callhook (lua_State *L, int event, int line); +LUAI_FUNC int luaD_precall (lua_State *L, StkId func, int nresults); +LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults); +LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u, + ptrdiff_t oldtop, ptrdiff_t ef); +LUAI_FUNC int luaD_poscall (lua_State *L, StkId firstResult); +LUAI_FUNC void luaD_reallocCI (lua_State *L, int newsize); +LUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize); +LUAI_FUNC void luaD_growstack (lua_State *L, int n); + +#ifdef _MSC_VER + #ifndef ATTRNORETURN + #define ATTRNORETURN __declspec(noreturn) + #endif +#endif + +#ifndef ATTRNORETURN +#define ATTRNORETURN +#endif + +LUAI_FUNC void ATTRNORETURN luaD_throw (lua_State *L, int errcode); +LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud); + +LUAI_FUNC void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop); + +#endif diff --git a/src/blua/ldump.c b/src/blua/ldump.c new file mode 100644 index 000000000..c9d3d4870 --- /dev/null +++ b/src/blua/ldump.c @@ -0,0 +1,164 @@ +/* +** $Id: ldump.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $ +** save precompiled Lua chunks +** See Copyright Notice in lua.h +*/ + +#include + +#define ldump_c +#define LUA_CORE + +#include "lua.h" + +#include "lobject.h" +#include "lstate.h" +#include "lundump.h" + +typedef struct { + lua_State* L; + lua_Writer writer; + void* data; + int strip; + int status; +} DumpState; + +#define DumpMem(b,n,size,D) DumpBlock(b,(n)*(size),D) +#define DumpVar(x,D) DumpMem(&x,1,sizeof(x),D) + +static void DumpBlock(const void* b, size_t size, DumpState* D) +{ + if (D->status==0) + { + lua_unlock(D->L); + D->status=(*D->writer)(D->L,b,size,D->data); + lua_lock(D->L); + } +} + +static void DumpChar(int y, DumpState* D) +{ + char x=(char)y; + DumpVar(x,D); +} + +static void DumpInt(int x, DumpState* D) +{ + DumpVar(x,D); +} + +static void DumpNumber(lua_Number x, DumpState* D) +{ + DumpVar(x,D); +} + +static void DumpVector(const void* b, int n, size_t size, DumpState* D) +{ + DumpInt(n,D); + DumpMem(b,n,size,D); +} + +static void DumpString(const TString* s, DumpState* D) +{ + if (s==NULL || getstr(s)==NULL) + { + size_t size=0; + DumpVar(size,D); + } + else + { + size_t size=s->tsv.len+1; /* include trailing '\0' */ + DumpVar(size,D); + DumpBlock(getstr(s),size,D); + } +} + +#define DumpCode(f,D) DumpVector(f->code,f->sizecode,sizeof(Instruction),D) + +static void DumpFunction(const Proto* f, const TString* p, DumpState* D); + +static void DumpConstants(const Proto* f, DumpState* D) +{ + int i,n=f->sizek; + DumpInt(n,D); + for (i=0; ik[i]; + DumpChar(ttype(o),D); + switch (ttype(o)) + { + case LUA_TNIL: + break; + case LUA_TBOOLEAN: + DumpChar(bvalue(o),D); + break; + case LUA_TNUMBER: + DumpNumber(nvalue(o),D); + break; + case LUA_TSTRING: + DumpString(rawtsvalue(o),D); + break; + default: + lua_assert(0); /* cannot happen */ + break; + } + } + n=f->sizep; + DumpInt(n,D); + for (i=0; ip[i],f->source,D); +} + +static void DumpDebug(const Proto* f, DumpState* D) +{ + int i,n; + n= (D->strip) ? 0 : f->sizelineinfo; + DumpVector(f->lineinfo,n,sizeof(int),D); + n= (D->strip) ? 0 : f->sizelocvars; + DumpInt(n,D); + for (i=0; ilocvars[i].varname,D); + DumpInt(f->locvars[i].startpc,D); + DumpInt(f->locvars[i].endpc,D); + } + n= (D->strip) ? 0 : f->sizeupvalues; + DumpInt(n,D); + for (i=0; iupvalues[i],D); +} + +static void DumpFunction(const Proto* f, const TString* p, DumpState* D) +{ + DumpString((f->source==p || D->strip) ? NULL : f->source,D); + DumpInt(f->linedefined,D); + DumpInt(f->lastlinedefined,D); + DumpChar(f->nups,D); + DumpChar(f->numparams,D); + DumpChar(f->is_vararg,D); + DumpChar(f->maxstacksize,D); + DumpCode(f,D); + DumpConstants(f,D); + DumpDebug(f,D); +} + +static void DumpHeader(DumpState* D) +{ + char h[LUAC_HEADERSIZE]; + luaU_header(h); + DumpBlock(h,LUAC_HEADERSIZE,D); +} + +/* +** dump Lua function as precompiled chunk +*/ +int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip) +{ + DumpState D; + D.L=L; + D.writer=w; + D.data=data; + D.strip=strip; + D.status=0; + DumpHeader(&D); + DumpFunction(f,NULL,&D); + return D.status; +} diff --git a/src/blua/lfunc.c b/src/blua/lfunc.c new file mode 100644 index 000000000..22f670e67 --- /dev/null +++ b/src/blua/lfunc.c @@ -0,0 +1,173 @@ +/* +** $Id: lfunc.c,v 2.12.1.2 2007/12/28 14:58:43 roberto Exp $ +** Auxiliary functions to manipulate prototypes and closures +** See Copyright Notice in lua.h +*/ + + +#include + +#define lfunc_c +#define LUA_CORE + +#include "lua.h" + +#include "lfunc.h" +#include "lgc.h" +#include "lmem.h" +#include "lobject.h" +#include "lstate.h" + + + +Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e) { + Closure *c = cast(Closure *, luaM_malloc(L, sizeCclosure(nelems))); + luaC_link(L, obj2gco(c), LUA_TFUNCTION); + c->c.isC = 1; + c->c.env = e; + c->c.nupvalues = cast_byte(nelems); + return c; +} + + +Closure *luaF_newLclosure (lua_State *L, int nelems, Table *e) { + Closure *c = cast(Closure *, luaM_malloc(L, sizeLclosure(nelems))); + luaC_link(L, obj2gco(c), LUA_TFUNCTION); + c->l.isC = 0; + c->l.env = e; + c->l.nupvalues = cast_byte(nelems); + while (nelems--) c->l.upvals[nelems] = NULL; + return c; +} + + +UpVal *luaF_newupval (lua_State *L) { + UpVal *uv = luaM_new(L, UpVal); + luaC_link(L, obj2gco(uv), LUA_TUPVAL); + uv->v = &uv->u.value; + setnilvalue(uv->v); + return uv; +} + + +UpVal *luaF_findupval (lua_State *L, StkId level) { + global_State *g = G(L); + GCObject **pp = &L->openupval; + UpVal *p; + UpVal *uv; + while (*pp != NULL && (p = ngcotouv(*pp))->v >= level) { + lua_assert(p->v != &p->u.value); + if (p->v == level) { /* found a corresponding upvalue? */ + if (isdead(g, obj2gco(p))) /* is it dead? */ + changewhite(obj2gco(p)); /* ressurect it */ + return p; + } + pp = &p->next; + } + uv = luaM_new(L, UpVal); /* not found: create a new one */ + uv->tt = LUA_TUPVAL; + uv->marked = luaC_white(g); + uv->v = level; /* current value lives in the stack */ + uv->next = *pp; /* chain it in the proper position */ + *pp = obj2gco(uv); + uv->u.l.prev = &g->uvhead; /* double link it in `uvhead' list */ + uv->u.l.next = g->uvhead.u.l.next; + uv->u.l.next->u.l.prev = uv; + g->uvhead.u.l.next = uv; + lua_assert(uv->u.l.next->u.l.prev == uv && uv->u.l.prev->u.l.next == uv); + return uv; +} + + +static void unlinkupval (UpVal *uv) { + lua_assert(uv->u.l.next->u.l.prev == uv && uv->u.l.prev->u.l.next == uv); + uv->u.l.next->u.l.prev = uv->u.l.prev; /* remove from `uvhead' list */ + uv->u.l.prev->u.l.next = uv->u.l.next; +} + + +void luaF_freeupval (lua_State *L, UpVal *uv) { + if (uv->v != &uv->u.value) /* is it open? */ + unlinkupval(uv); /* remove from open list */ + luaM_free(L, uv); /* free upvalue */ +} + + +void luaF_close (lua_State *L, StkId level) { + UpVal *uv; + global_State *g = G(L); + while (L->openupval != NULL && (uv = ngcotouv(L->openupval))->v >= level) { + GCObject *o = obj2gco(uv); + lua_assert(!isblack(o) && uv->v != &uv->u.value); + L->openupval = uv->next; /* remove from `open' list */ + if (isdead(g, o)) + luaF_freeupval(L, uv); /* free upvalue */ + else { + unlinkupval(uv); + setobj(L, &uv->u.value, uv->v); + uv->v = &uv->u.value; /* now current value lives here */ + luaC_linkupval(L, uv); /* link upvalue into `gcroot' list */ + } + } +} + + +Proto *luaF_newproto (lua_State *L) { + Proto *f = luaM_new(L, Proto); + luaC_link(L, obj2gco(f), LUA_TPROTO); + f->k = NULL; + f->sizek = 0; + f->p = NULL; + f->sizep = 0; + f->code = NULL; + f->sizecode = 0; + f->sizelineinfo = 0; + f->sizeupvalues = 0; + f->nups = 0; + f->upvalues = NULL; + f->numparams = 0; + f->is_vararg = 0; + f->maxstacksize = 0; + f->lineinfo = NULL; + f->sizelocvars = 0; + f->locvars = NULL; + f->linedefined = 0; + f->lastlinedefined = 0; + f->source = NULL; + return f; +} + + +void luaF_freeproto (lua_State *L, Proto *f) { + luaM_freearray(L, f->code, f->sizecode, Instruction); + luaM_freearray(L, f->p, f->sizep, Proto *); + luaM_freearray(L, f->k, f->sizek, TValue); + luaM_freearray(L, f->lineinfo, f->sizelineinfo, int); + luaM_freearray(L, f->locvars, f->sizelocvars, struct LocVar); + luaM_freearray(L, f->upvalues, f->sizeupvalues, TString *); + luaM_free(L, f); +} + + +void luaF_freeclosure (lua_State *L, Closure *c) { + int size = (c->c.isC) ? sizeCclosure(c->c.nupvalues) : + sizeLclosure(c->l.nupvalues); + luaM_freemem(L, c, size); +} + + +/* +** Look for n-th local variable at line `line' in function `func'. +** Returns NULL if not found. +*/ +const char *luaF_getlocalname (const Proto *f, int local_number, int pc) { + int i; + for (i = 0; isizelocvars && f->locvars[i].startpc <= pc; i++) { + if (pc < f->locvars[i].endpc) { /* is variable active? */ + local_number--; + if (local_number == 0) + return getstr(f->locvars[i].varname); + } + } + return NULL; /* not found */ +} diff --git a/src/blua/lfunc.h b/src/blua/lfunc.h new file mode 100644 index 000000000..a68cf5151 --- /dev/null +++ b/src/blua/lfunc.h @@ -0,0 +1,34 @@ +/* +** $Id: lfunc.h,v 2.4.1.1 2007/12/27 13:02:25 roberto Exp $ +** Auxiliary functions to manipulate prototypes and closures +** See Copyright Notice in lua.h +*/ + +#ifndef lfunc_h +#define lfunc_h + + +#include "lobject.h" + + +#define sizeCclosure(n) (cast(int, sizeof(CClosure)) + \ + cast(int, sizeof(TValue)*((n)-1))) + +#define sizeLclosure(n) (cast(int, sizeof(LClosure)) + \ + cast(int, sizeof(TValue *)*((n)-1))) + + +LUAI_FUNC Proto *luaF_newproto (lua_State *L); +LUAI_FUNC Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e); +LUAI_FUNC Closure *luaF_newLclosure (lua_State *L, int nelems, Table *e); +LUAI_FUNC UpVal *luaF_newupval (lua_State *L); +LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level); +LUAI_FUNC void luaF_close (lua_State *L, StkId level); +LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); +LUAI_FUNC void luaF_freeclosure (lua_State *L, Closure *c); +LUAI_FUNC void luaF_freeupval (lua_State *L, UpVal *uv); +LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number, + int pc); + + +#endif diff --git a/src/blua/lgc.c b/src/blua/lgc.c new file mode 100644 index 000000000..1d1087e5b --- /dev/null +++ b/src/blua/lgc.c @@ -0,0 +1,710 @@ +/* +** $Id: lgc.c,v 2.38.1.1 2007/12/27 13:02:25 roberto Exp $ +** Garbage Collector +** See Copyright Notice in lua.h +*/ + +#include + +#define lgc_c +#define LUA_CORE + +#include "lua.h" + +#include "ldebug.h" +#include "ldo.h" +#include "lfunc.h" +#include "lgc.h" +#include "lmem.h" +#include "lobject.h" +#include "lstate.h" +#include "lstring.h" +#include "ltable.h" +#include "ltm.h" + + +#define GCSTEPSIZE 1024u +#define GCSWEEPMAX 40 +#define GCSWEEPCOST 10 +#define GCFINALIZECOST 100 + + +#define maskmarks cast_byte(~(bitmask(BLACKBIT)|WHITEBITS)) + +#define makewhite(g,x) \ + ((x)->gch.marked = cast_byte(((x)->gch.marked & maskmarks) | luaC_white(g))) + +#define white2gray(x) reset2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT) +#define black2gray(x) resetbit((x)->gch.marked, BLACKBIT) + +#define stringmark(s) reset2bits((s)->tsv.marked, WHITE0BIT, WHITE1BIT) + + +#define isfinalized(u) testbit((u)->marked, FINALIZEDBIT) +#define markfinalized(u) l_setbit((u)->marked, FINALIZEDBIT) + + +#define KEYWEAK bitmask(KEYWEAKBIT) +#define VALUEWEAK bitmask(VALUEWEAKBIT) + + + +#define markvalue(g,o) { checkconsistency(o); \ + if (iscollectable(o) && iswhite(gcvalue(o))) reallymarkobject(g,gcvalue(o)); } + +#define markobject(g,t) { if (iswhite(obj2gco(t))) \ + reallymarkobject(g, obj2gco(t)); } + + +#define setthreshold(g) (g->GCthreshold = (g->estimate/100) * g->gcpause) + + +static void removeentry (Node *n) { + lua_assert(ttisnil(gval(n))); + if (iscollectable(gkey(n))) + setttype(gkey(n), LUA_TDEADKEY); /* dead key; remove it */ +} + + +static void reallymarkobject (global_State *g, GCObject *o) { + lua_assert(iswhite(o) && !isdead(g, o)); + white2gray(o); + switch (o->gch.tt) { + case LUA_TSTRING: { + return; + } + case LUA_TUSERDATA: { + Table *mt = gco2u(o)->metatable; + gray2black(o); /* udata are never gray */ + if (mt) markobject(g, mt); + markobject(g, gco2u(o)->env); + return; + } + case LUA_TUPVAL: { + UpVal *uv = gco2uv(o); + markvalue(g, uv->v); + if (uv->v == &uv->u.value) /* closed? */ + gray2black(o); /* open upvalues are never black */ + return; + } + case LUA_TFUNCTION: { + gco2cl(o)->c.gclist = g->gray; + g->gray = o; + break; + } + case LUA_TTABLE: { + gco2h(o)->gclist = g->gray; + g->gray = o; + break; + } + case LUA_TTHREAD: { + gco2th(o)->gclist = g->gray; + g->gray = o; + break; + } + case LUA_TPROTO: { + gco2p(o)->gclist = g->gray; + g->gray = o; + break; + } + default: lua_assert(0); + } +} + + +static void marktmu (global_State *g) { + GCObject *u = g->tmudata; + if (u) { + do { + u = u->gch.next; + makewhite(g, u); /* may be marked, if left from previous GC */ + reallymarkobject(g, u); + } while (u != g->tmudata); + } +} + + +/* move `dead' udata that need finalization to list `tmudata' */ +size_t luaC_separateudata (lua_State *L, int all) { + global_State *g = G(L); + size_t deadmem = 0; + GCObject **p = &g->mainthread->next; + GCObject *curr; + while ((curr = *p) != NULL) { + if (!(iswhite(curr) || all) || isfinalized(gco2u(curr))) + p = &curr->gch.next; /* don't bother with them */ + else if (fasttm(L, gco2u(curr)->metatable, TM_GC) == NULL) { + markfinalized(gco2u(curr)); /* don't need finalization */ + p = &curr->gch.next; + } + else { /* must call its gc method */ + deadmem += sizeudata(gco2u(curr)); + markfinalized(gco2u(curr)); + *p = curr->gch.next; + /* link `curr' at the end of `tmudata' list */ + if (g->tmudata == NULL) /* list is empty? */ + g->tmudata = curr->gch.next = curr; /* creates a circular list */ + else { + curr->gch.next = g->tmudata->gch.next; + g->tmudata->gch.next = curr; + g->tmudata = curr; + } + } + } + return deadmem; +} + + +static int traversetable (global_State *g, Table *h) { + int i; + int weakkey = 0; + int weakvalue = 0; + const TValue *mode; + if (h->metatable) + markobject(g, h->metatable); + mode = gfasttm(g, h->metatable, TM_MODE); + if (mode && ttisstring(mode)) { /* is there a weak mode? */ + weakkey = (strchr(svalue(mode), 'k') != NULL); + weakvalue = (strchr(svalue(mode), 'v') != NULL); + if (weakkey || weakvalue) { /* is really weak? */ + h->marked &= ~(KEYWEAK | VALUEWEAK); /* clear bits */ + h->marked |= cast_byte((weakkey << KEYWEAKBIT) | + (weakvalue << VALUEWEAKBIT)); + h->gclist = g->weak; /* must be cleared after GC, ... */ + g->weak = obj2gco(h); /* ... so put in the appropriate list */ + } + } + if (weakkey && weakvalue) return 1; + if (!weakvalue) { + i = h->sizearray; + while (i--) + markvalue(g, &h->array[i]); + } + i = sizenode(h); + while (i--) { + Node *n = gnode(h, i); + lua_assert(ttype(gkey(n)) != LUA_TDEADKEY || ttisnil(gval(n))); + if (ttisnil(gval(n))) + removeentry(n); /* remove empty entries */ + else { + lua_assert(!ttisnil(gkey(n))); + if (!weakkey) markvalue(g, gkey(n)); + if (!weakvalue) markvalue(g, gval(n)); + } + } + return weakkey || weakvalue; +} + + +/* +** All marks are conditional because a GC may happen while the +** prototype is still being created +*/ +static void traverseproto (global_State *g, Proto *f) { + int i; + if (f->source) stringmark(f->source); + for (i=0; isizek; i++) /* mark literals */ + markvalue(g, &f->k[i]); + for (i=0; isizeupvalues; i++) { /* mark upvalue names */ + if (f->upvalues[i]) + stringmark(f->upvalues[i]); + } + for (i=0; isizep; i++) { /* mark nested protos */ + if (f->p[i]) + markobject(g, f->p[i]); + } + for (i=0; isizelocvars; i++) { /* mark local-variable names */ + if (f->locvars[i].varname) + stringmark(f->locvars[i].varname); + } +} + + + +static void traverseclosure (global_State *g, Closure *cl) { + markobject(g, cl->c.env); + if (cl->c.isC) { + int i; + for (i=0; ic.nupvalues; i++) /* mark its upvalues */ + markvalue(g, &cl->c.upvalue[i]); + } + else { + int i; + lua_assert(cl->l.nupvalues == cl->l.p->nups); + markobject(g, cl->l.p); + for (i=0; il.nupvalues; i++) /* mark its upvalues */ + markobject(g, cl->l.upvals[i]); + } +} + + +static void checkstacksizes (lua_State *L, StkId max) { + int ci_used = cast_int(L->ci - L->base_ci); /* number of `ci' in use */ + int s_used = cast_int(max - L->stack); /* part of stack in use */ + if (L->size_ci > LUAI_MAXCALLS) /* handling overflow? */ + return; /* do not touch the stacks */ + if (4*ci_used < L->size_ci && 2*BASIC_CI_SIZE < L->size_ci) + luaD_reallocCI(L, L->size_ci/2); /* still big enough... */ + condhardstacktests(luaD_reallocCI(L, ci_used + 1)); + if (4*s_used < L->stacksize && + 2*(BASIC_STACK_SIZE+EXTRA_STACK) < L->stacksize) + luaD_reallocstack(L, L->stacksize/2); /* still big enough... */ + condhardstacktests(luaD_reallocstack(L, s_used)); +} + + +static void traversestack (global_State *g, lua_State *l) { + StkId o, lim; + CallInfo *ci; + markvalue(g, gt(l)); + lim = l->top; + for (ci = l->base_ci; ci <= l->ci; ci++) { + lua_assert(ci->top <= l->stack_last); + if (lim < ci->top) lim = ci->top; + } + for (o = l->stack; o < l->top; o++) + markvalue(g, o); + for (; o <= lim; o++) + setnilvalue(o); + checkstacksizes(l, lim); +} + + +/* +** traverse one gray object, turning it to black. +** Returns `quantity' traversed. +*/ +static l_mem propagatemark (global_State *g) { + GCObject *o = g->gray; + lua_assert(isgray(o)); + gray2black(o); + switch (o->gch.tt) { + case LUA_TTABLE: { + Table *h = gco2h(o); + g->gray = h->gclist; + if (traversetable(g, h)) /* table is weak? */ + black2gray(o); /* keep it gray */ + return sizeof(Table) + sizeof(TValue) * h->sizearray + + sizeof(Node) * sizenode(h); + } + case LUA_TFUNCTION: { + Closure *cl = gco2cl(o); + g->gray = cl->c.gclist; + traverseclosure(g, cl); + return (cl->c.isC) ? sizeCclosure(cl->c.nupvalues) : + sizeLclosure(cl->l.nupvalues); + } + case LUA_TTHREAD: { + lua_State *th = gco2th(o); + g->gray = th->gclist; + th->gclist = g->grayagain; + g->grayagain = o; + black2gray(o); + traversestack(g, th); + return sizeof(lua_State) + sizeof(TValue) * th->stacksize + + sizeof(CallInfo) * th->size_ci; + } + case LUA_TPROTO: { + Proto *p = gco2p(o); + g->gray = p->gclist; + traverseproto(g, p); + return sizeof(Proto) + sizeof(Instruction) * p->sizecode + + sizeof(Proto *) * p->sizep + + sizeof(TValue) * p->sizek + + sizeof(int) * p->sizelineinfo + + sizeof(LocVar) * p->sizelocvars + + sizeof(TString *) * p->sizeupvalues; + } + default: lua_assert(0); return 0; + } +} + + +static size_t propagateall (global_State *g) { + size_t m = 0; + while (g->gray) m += propagatemark(g); + return m; +} + + +/* +** The next function tells whether a key or value can be cleared from +** a weak table. Non-collectable objects are never removed from weak +** tables. Strings behave as `values', so are never removed too. for +** other objects: if really collected, cannot keep them; for userdata +** being finalized, keep them in keys, but not in values +*/ +static int iscleared (const TValue *o, int iskey) { + if (!iscollectable(o)) return 0; + if (ttisstring(o)) { + stringmark(rawtsvalue(o)); /* strings are `values', so are never weak */ + return 0; + } + return iswhite(gcvalue(o)) || + (ttisuserdata(o) && (!iskey && isfinalized(uvalue(o)))); +} + + +/* +** clear collected entries from weaktables +*/ +static void cleartable (GCObject *l) { + while (l) { + Table *h = gco2h(l); + int i = h->sizearray; + lua_assert(testbit(h->marked, VALUEWEAKBIT) || + testbit(h->marked, KEYWEAKBIT)); + if (testbit(h->marked, VALUEWEAKBIT)) { + while (i--) { + TValue *o = &h->array[i]; + if (iscleared(o, 0)) /* value was collected? */ + setnilvalue(o); /* remove value */ + } + } + i = sizenode(h); + while (i--) { + Node *n = gnode(h, i); + if (!ttisnil(gval(n)) && /* non-empty entry? */ + (iscleared(key2tval(n), 1) || iscleared(gval(n), 0))) { + setnilvalue(gval(n)); /* remove value ... */ + removeentry(n); /* remove entry from table */ + } + } + l = h->gclist; + } +} + + +static void freeobj (lua_State *L, GCObject *o) { + switch (o->gch.tt) { + case LUA_TPROTO: luaF_freeproto(L, gco2p(o)); break; + case LUA_TFUNCTION: luaF_freeclosure(L, gco2cl(o)); break; + case LUA_TUPVAL: luaF_freeupval(L, gco2uv(o)); break; + case LUA_TTABLE: luaH_free(L, gco2h(o)); break; + case LUA_TTHREAD: { + lua_assert(gco2th(o) != L && gco2th(o) != G(L)->mainthread); + luaE_freethread(L, gco2th(o)); + break; + } + case LUA_TSTRING: { + G(L)->strt.nuse--; + luaM_freemem(L, o, sizestring(gco2ts(o))); + break; + } + case LUA_TUSERDATA: { + luaM_freemem(L, o, sizeudata(gco2u(o))); + break; + } + default: lua_assert(0); + } +} + + + +#define sweepwholelist(L,p) sweeplist(L,p,MAX_LUMEM) + + +static GCObject **sweeplist (lua_State *L, GCObject **p, lu_mem count) { + GCObject *curr; + global_State *g = G(L); + int deadmask = otherwhite(g); + while ((curr = *p) != NULL && count-- > 0) { + if (curr->gch.tt == LUA_TTHREAD) /* sweep open upvalues of each thread */ + sweepwholelist(L, &gco2th(curr)->openupval); + if ((curr->gch.marked ^ WHITEBITS) & deadmask) { /* not dead? */ + lua_assert(!isdead(g, curr) || testbit(curr->gch.marked, FIXEDBIT)); + makewhite(g, curr); /* make it white (for next cycle) */ + p = &curr->gch.next; + } + else { /* must erase `curr' */ + lua_assert(isdead(g, curr) || deadmask == bitmask(SFIXEDBIT)); + *p = curr->gch.next; + if (curr == g->rootgc) /* is the first element of the list? */ + g->rootgc = curr->gch.next; /* adjust first */ + freeobj(L, curr); + } + } + return p; +} + + +static void checkSizes (lua_State *L) { + global_State *g = G(L); + /* check size of string hash */ + if (g->strt.nuse < cast(lu_int32, g->strt.size/4) && + g->strt.size > MINSTRTABSIZE*2) + luaS_resize(L, g->strt.size/2); /* table is too big */ + /* check size of buffer */ + if (luaZ_sizebuffer(&g->buff) > LUA_MINBUFFER*2) { /* buffer too big? */ + size_t newsize = luaZ_sizebuffer(&g->buff) / 2; + luaZ_resizebuffer(L, &g->buff, newsize); + } +} + + +static void GCTM (lua_State *L) { + global_State *g = G(L); + GCObject *o = g->tmudata->gch.next; /* get first element */ + Udata *udata = rawgco2u(o); + const TValue *tm; + /* remove udata from `tmudata' */ + if (o == g->tmudata) /* last element? */ + g->tmudata = NULL; + else + g->tmudata->gch.next = udata->uv.next; + udata->uv.next = g->mainthread->next; /* return it to `root' list */ + g->mainthread->next = o; + makewhite(g, o); + tm = fasttm(L, udata->uv.metatable, TM_GC); + if (tm != NULL) { + lu_byte oldah = L->allowhook; + lu_mem oldt = g->GCthreshold; + L->allowhook = 0; /* stop debug hooks during GC tag method */ + g->GCthreshold = 2*g->totalbytes; /* avoid GC steps */ + setobj2s(L, L->top, tm); + setuvalue(L, L->top+1, udata); + L->top += 2; + luaD_call(L, L->top - 2, 0); + L->allowhook = oldah; /* restore hooks */ + g->GCthreshold = oldt; /* restore threshold */ + } +} + + +/* +** Call all GC tag methods +*/ +void luaC_callGCTM (lua_State *L) { + while (G(L)->tmudata) + GCTM(L); +} + + +void luaC_freeall (lua_State *L) { + global_State *g = G(L); + int i; + g->currentwhite = WHITEBITS | bitmask(SFIXEDBIT); /* mask to collect all elements */ + sweepwholelist(L, &g->rootgc); + for (i = 0; i < g->strt.size; i++) /* free all string lists */ + sweepwholelist(L, &g->strt.hash[i]); +} + + +static void markmt (global_State *g) { + int i; + for (i=0; imt[i]) markobject(g, g->mt[i]); +} + + +/* mark root set */ +static void markroot (lua_State *L) { + global_State *g = G(L); + g->gray = NULL; + g->grayagain = NULL; + g->weak = NULL; + markobject(g, g->mainthread); + /* make global table be traversed before main stack */ + markvalue(g, gt(g->mainthread)); + markvalue(g, registry(L)); + markmt(g); + g->gcstate = GCSpropagate; +} + + +static void remarkupvals (global_State *g) { + UpVal *uv; + for (uv = g->uvhead.u.l.next; uv != &g->uvhead; uv = uv->u.l.next) { + lua_assert(uv->u.l.next->u.l.prev == uv && uv->u.l.prev->u.l.next == uv); + if (isgray(obj2gco(uv))) + markvalue(g, uv->v); + } +} + + +static void atomic (lua_State *L) { + global_State *g = G(L); + size_t udsize; /* total size of userdata to be finalized */ + /* remark occasional upvalues of (maybe) dead threads */ + remarkupvals(g); + /* traverse objects cautch by write barrier and by 'remarkupvals' */ + propagateall(g); + /* remark weak tables */ + g->gray = g->weak; + g->weak = NULL; + lua_assert(!iswhite(obj2gco(g->mainthread))); + markobject(g, L); /* mark running thread */ + markmt(g); /* mark basic metatables (again) */ + propagateall(g); + /* remark gray again */ + g->gray = g->grayagain; + g->grayagain = NULL; + propagateall(g); + udsize = luaC_separateudata(L, 0); /* separate userdata to be finalized */ + marktmu(g); /* mark `preserved' userdata */ + udsize += propagateall(g); /* remark, to propagate `preserveness' */ + cleartable(g->weak); /* remove collected objects from weak tables */ + /* flip current white */ + g->currentwhite = cast_byte(otherwhite(g)); + g->sweepstrgc = 0; + g->sweepgc = &g->rootgc; + g->gcstate = GCSsweepstring; + g->estimate = g->totalbytes - udsize; /* first estimate */ +} + + +static l_mem singlestep (lua_State *L) { + global_State *g = G(L); + /*lua_checkmemory(L);*/ + switch (g->gcstate) { + case GCSpause: { + markroot(L); /* start a new collection */ + return 0; + } + case GCSpropagate: { + if (g->gray) + return propagatemark(g); + else { /* no more `gray' objects */ + atomic(L); /* finish mark phase */ + return 0; + } + } + case GCSsweepstring: { + lu_mem old = g->totalbytes; + sweepwholelist(L, &g->strt.hash[g->sweepstrgc++]); + if (g->sweepstrgc >= g->strt.size) /* nothing more to sweep? */ + g->gcstate = GCSsweep; /* end sweep-string phase */ + lua_assert(old >= g->totalbytes); + g->estimate -= old - g->totalbytes; + return GCSWEEPCOST; + } + case GCSsweep: { + lu_mem old = g->totalbytes; + g->sweepgc = sweeplist(L, g->sweepgc, GCSWEEPMAX); + if (*g->sweepgc == NULL) { /* nothing more to sweep? */ + checkSizes(L); + g->gcstate = GCSfinalize; /* end sweep phase */ + } + lua_assert(old >= g->totalbytes); + g->estimate -= old - g->totalbytes; + return GCSWEEPMAX*GCSWEEPCOST; + } + case GCSfinalize: { + if (g->tmudata) { + GCTM(L); + if (g->estimate > GCFINALIZECOST) + g->estimate -= GCFINALIZECOST; + return GCFINALIZECOST; + } + else { + g->gcstate = GCSpause; /* end collection */ + g->gcdept = 0; + return 0; + } + } + default: lua_assert(0); return 0; + } +} + + +void luaC_step (lua_State *L) { + global_State *g = G(L); + l_mem lim = (GCSTEPSIZE/100) * g->gcstepmul; + if (lim == 0) + lim = (MAX_LUMEM-1)/2; /* no limit */ + g->gcdept += g->totalbytes - g->GCthreshold; + do { + lim -= singlestep(L); + if (g->gcstate == GCSpause) + break; + } while (lim > 0); + if (g->gcstate != GCSpause) { + if (g->gcdept < GCSTEPSIZE) + g->GCthreshold = g->totalbytes + GCSTEPSIZE; /* - lim/g->gcstepmul;*/ + else { + g->gcdept -= GCSTEPSIZE; + g->GCthreshold = g->totalbytes; + } + } + else { + lua_assert(g->totalbytes >= g->estimate); + setthreshold(g); + } +} + + +void luaC_fullgc (lua_State *L) { + global_State *g = G(L); + if (g->gcstate <= GCSpropagate) { + /* reset sweep marks to sweep all elements (returning them to white) */ + g->sweepstrgc = 0; + g->sweepgc = &g->rootgc; + /* reset other collector lists */ + g->gray = NULL; + g->grayagain = NULL; + g->weak = NULL; + g->gcstate = GCSsweepstring; + } + lua_assert(g->gcstate != GCSpause && g->gcstate != GCSpropagate); + /* finish any pending sweep phase */ + while (g->gcstate != GCSfinalize) { + lua_assert(g->gcstate == GCSsweepstring || g->gcstate == GCSsweep); + singlestep(L); + } + markroot(L); + while (g->gcstate != GCSpause) { + singlestep(L); + } + setthreshold(g); +} + + +void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v) { + global_State *g = G(L); + lua_assert(isblack(o) && iswhite(v) && !isdead(g, v) && !isdead(g, o)); + lua_assert(g->gcstate != GCSfinalize && g->gcstate != GCSpause); + lua_assert(ttype(&o->gch) != LUA_TTABLE); + /* must keep invariant? */ + if (g->gcstate == GCSpropagate) + reallymarkobject(g, v); /* restore invariant */ + else /* don't mind */ + makewhite(g, o); /* mark as white just to avoid other barriers */ +} + + +void luaC_barrierback (lua_State *L, Table *t) { + global_State *g = G(L); + GCObject *o = obj2gco(t); + lua_assert(isblack(o) && !isdead(g, o)); + lua_assert(g->gcstate != GCSfinalize && g->gcstate != GCSpause); + black2gray(o); /* make table gray (again) */ + t->gclist = g->grayagain; + g->grayagain = o; +} + + +void luaC_link (lua_State *L, GCObject *o, lu_byte tt) { + global_State *g = G(L); + o->gch.next = g->rootgc; + g->rootgc = o; + o->gch.marked = luaC_white(g); + o->gch.tt = tt; +} + + +void luaC_linkupval (lua_State *L, UpVal *uv) { + global_State *g = G(L); + GCObject *o = obj2gco(uv); + o->gch.next = g->rootgc; /* link upvalue into `rootgc' list */ + g->rootgc = o; + if (isgray(o)) { + if (g->gcstate == GCSpropagate) { + gray2black(o); /* closed upvalues need barrier */ + luaC_barrier(L, uv, uv->v); + } + else { /* sweep phase: sweep it (turning it into white) */ + makewhite(g, o); + lua_assert(g->gcstate != GCSfinalize && g->gcstate != GCSpause); + } + } +} diff --git a/src/blua/lgc.h b/src/blua/lgc.h new file mode 100644 index 000000000..5a8dc605b --- /dev/null +++ b/src/blua/lgc.h @@ -0,0 +1,110 @@ +/* +** $Id: lgc.h,v 2.15.1.1 2007/12/27 13:02:25 roberto Exp $ +** Garbage Collector +** See Copyright Notice in lua.h +*/ + +#ifndef lgc_h +#define lgc_h + + +#include "lobject.h" + + +/* +** Possible states of the Garbage Collector +*/ +#define GCSpause 0 +#define GCSpropagate 1 +#define GCSsweepstring 2 +#define GCSsweep 3 +#define GCSfinalize 4 + + +/* +** some userful bit tricks +*/ +#define resetbits(x,m) ((x) &= cast(lu_byte, ~(m))) +#define setbits(x,m) ((x) |= (m)) +#define testbits(x,m) ((x) & (m)) +#define bitmask(b) (1<<(b)) +#define bit2mask(b1,b2) (bitmask(b1) | bitmask(b2)) +#define l_setbit(x,b) setbits(x, bitmask(b)) +#define resetbit(x,b) resetbits(x, bitmask(b)) +#define testbit(x,b) testbits(x, bitmask(b)) +#define set2bits(x,b1,b2) setbits(x, (bit2mask(b1, b2))) +#define reset2bits(x,b1,b2) resetbits(x, (bit2mask(b1, b2))) +#define test2bits(x,b1,b2) testbits(x, (bit2mask(b1, b2))) + + + +/* +** Layout for bit use in `marked' field: +** bit 0 - object is white (type 0) +** bit 1 - object is white (type 1) +** bit 2 - object is black +** bit 3 - for userdata: has been finalized +** bit 3 - for tables: has weak keys +** bit 4 - for tables: has weak values +** bit 5 - object is fixed (should not be collected) +** bit 6 - object is "super" fixed (only the main thread) +*/ + + +#define WHITE0BIT 0 +#define WHITE1BIT 1 +#define BLACKBIT 2 +#define FINALIZEDBIT 3 +#define KEYWEAKBIT 3 +#define VALUEWEAKBIT 4 +#define FIXEDBIT 5 +#define SFIXEDBIT 6 +#define WHITEBITS bit2mask(WHITE0BIT, WHITE1BIT) + + +#define iswhite(x) test2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT) +#define isblack(x) testbit((x)->gch.marked, BLACKBIT) +#define isgray(x) (!isblack(x) && !iswhite(x)) + +#define otherwhite(g) (g->currentwhite ^ WHITEBITS) +#define isdead(g,v) ((v)->gch.marked & otherwhite(g) & WHITEBITS) + +#define changewhite(x) ((x)->gch.marked ^= WHITEBITS) +#define gray2black(x) l_setbit((x)->gch.marked, BLACKBIT) + +#define valiswhite(x) (iscollectable(x) && iswhite(gcvalue(x))) + +#define luaC_white(g) cast(lu_byte, (g)->currentwhite & WHITEBITS) + + +#define luaC_checkGC(L) { \ + condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK - 1)); \ + if (G(L)->totalbytes >= G(L)->GCthreshold) \ + luaC_step(L); } + + +#define luaC_barrier(L,p,v) { if (valiswhite(v) && isblack(obj2gco(p))) \ + luaC_barrierf(L,obj2gco(p),gcvalue(v)); } + +#define luaC_barriert(L,t,v) { if (valiswhite(v) && isblack(obj2gco(t))) \ + luaC_barrierback(L,t); } + +#define luaC_objbarrier(L,p,o) \ + { if (iswhite(obj2gco(o)) && isblack(obj2gco(p))) \ + luaC_barrierf(L,obj2gco(p),obj2gco(o)); } + +#define luaC_objbarriert(L,t,o) \ + { if (iswhite(obj2gco(o)) && isblack(obj2gco(t))) luaC_barrierback(L,t); } + +LUAI_FUNC size_t luaC_separateudata (lua_State *L, int all); +LUAI_FUNC void luaC_callGCTM (lua_State *L); +LUAI_FUNC void luaC_freeall (lua_State *L); +LUAI_FUNC void luaC_step (lua_State *L); +LUAI_FUNC void luaC_fullgc (lua_State *L); +LUAI_FUNC void luaC_link (lua_State *L, GCObject *o, lu_byte tt); +LUAI_FUNC void luaC_linkupval (lua_State *L, UpVal *uv); +LUAI_FUNC void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v); +LUAI_FUNC void luaC_barrierback (lua_State *L, Table *t); + + +#endif diff --git a/src/blua/linit.c b/src/blua/linit.c new file mode 100644 index 000000000..52b02dbe7 --- /dev/null +++ b/src/blua/linit.c @@ -0,0 +1,32 @@ +/* +** $Id: linit.c,v 1.14.1.1 2007/12/27 13:02:25 roberto Exp $ +** Initialization of libraries for lua.c +** See Copyright Notice in lua.h +*/ + + +#define linit_c +#define LUA_LIB + +#include "lua.h" + +#include "lualib.h" +#include "lauxlib.h" + + +static const luaL_Reg lualibs[] = { + {"", luaopen_base}, + {LUA_TABLIBNAME, luaopen_table}, + {LUA_STRLIBNAME, luaopen_string}, + {NULL, NULL} +}; + + +LUALIB_API void luaL_openlibs (lua_State *L) { + const luaL_Reg *lib = lualibs; + for (; lib->func; lib++) { + lua_pushcfunction(L, lib->func); + lua_pushstring(L, lib->name); + lua_call(L, 1, 0); + } +} diff --git a/src/blua/llex.c b/src/blua/llex.c new file mode 100644 index 000000000..0b328dcad --- /dev/null +++ b/src/blua/llex.c @@ -0,0 +1,603 @@ +/* +** $Id: llex.c,v 2.20.1.1 2007/12/27 13:02:25 roberto Exp $ +** Lexical Analyzer +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include + +#define llex_c +#define LUA_CORE + +#include "lua.h" + +#include "ldo.h" +#include "llex.h" +#include "lobject.h" +#include "lparser.h" +#include "lstate.h" +#include "lstring.h" +#include "ltable.h" +#include "lzio.h" + +#define _HEX2INT_(v) ( (v) <= '9' ? (v)-'0' : tolower(v)-'a'+10 ) + + +#define next(ls) (ls->current = zgetc(ls->z)) + + + + +#define currIsNewline(ls) (ls->current == '\n' || ls->current == '\r') + + +/* ORDER RESERVED */ +const char *const luaX_tokens [] = { + "and", "break", "continue", "do", "else", "elseif", + "end", "false", "for", "function", "if", + "in", "local", "nil", "not", "or", "repeat", + "return", "then", "true", "until", "while", + "..", "...", "==", ">=", "<=", "~=", + "", "", "", "", + "<<", ">>", "^^", + NULL +}; + + +#define save_and_next(ls) (save(ls, ls->current), next(ls)) + + +static void save (LexState *ls, int c) { + Mbuffer *b = ls->buff; + if (b->n + 1 > b->buffsize) { + size_t newsize; + if (b->buffsize >= MAX_SIZET/2) + luaX_lexerror(ls, "lexical element too long", 0); + newsize = b->buffsize * 2; + luaZ_resizebuffer(ls->L, b, newsize); + } + b->buffer[b->n++] = cast(char, c); +} + + +void luaX_init (lua_State *L) { + int i; + for (i=0; itsv.reserved = cast_byte(i+1); /* reserved word */ + } +} + + +#define MAXSRC 80 + + +const char *luaX_token2str (LexState *ls, int token) { + if (token < FIRST_RESERVED) { + lua_assert(token == cast(unsigned char, token)); + return (iscntrl(token)) ? luaO_pushfstring(ls->L, "char(%d)", token) : + luaO_pushfstring(ls->L, "%c", token); + } + else + return luaX_tokens[token-FIRST_RESERVED]; +} + + +static const char *txtToken (LexState *ls, int token) { + switch (token) { + case TK_NAME: + case TK_STRING: + case TK_NUMBER: + save(ls, '\0'); + return luaZ_buffer(ls->buff); + default: + return luaX_token2str(ls, token); + } +} + + +void luaX_lexerror (LexState *ls, const char *msg, int token) { + char buff[MAXSRC]; + luaO_chunkid(buff, getstr(ls->source), MAXSRC); + msg = luaO_pushfstring(ls->L, "%s:%d: %s", buff, ls->linenumber, msg); + if (token) + luaO_pushfstring(ls->L, "%s near " LUA_QS, msg, txtToken(ls, token)); + luaD_throw(ls->L, LUA_ERRSYNTAX); +} + + +void luaX_syntaxerror (LexState *ls, const char *msg) { + luaX_lexerror(ls, msg, ls->t.token); +} + + +TString *luaX_newstring (LexState *ls, const char *str, size_t l) { + lua_State *L = ls->L; + TString *ts = luaS_newlstr(L, str, l); + TValue *o = luaH_setstr(L, ls->fs->h, ts); /* entry for `str' */ + if (ttisnil(o)) + setbvalue(o, 1); /* make sure `str' will not be collected */ + return ts; +} + + +static void inclinenumber (LexState *ls) { + int old = ls->current; + lua_assert(currIsNewline(ls)); + next(ls); /* skip `\n' or `\r' */ + if (currIsNewline(ls) && ls->current != old) + next(ls); /* skip `\n\r' or `\r\n' */ + if (++ls->linenumber >= MAX_INT) + luaX_syntaxerror(ls, "chunk has too many lines"); +} + + +void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source) { + ls->decpoint = '.'; + ls->L = L; + ls->lookahead.token = TK_EOS; /* no look-ahead token */ + ls->z = z; + ls->fs = NULL; + ls->linenumber = 1; + ls->lastline = 1; + ls->source = source; + ls->refstr = 0; + luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER); /* initialize buffer */ + next(ls); /* read first char */ +} + + + +/* +** ======================================================= +** LEXICAL ANALYZER +** ======================================================= +*/ + + + +static int check_next (LexState *ls, const char *set) { + if (!strchr(set, ls->current)) + return 0; + save_and_next(ls); + return 1; +} + + +static void buffreplace (LexState *ls, char from, char to) { + size_t n = luaZ_bufflen(ls->buff); + char *p = luaZ_buffer(ls->buff); + while (n--) + if (p[n] == from) p[n] = to; +} + + +static void trydecpoint (LexState *ls, SemInfo *seminfo) { + /* format error: try to update decimal point separator */ + struct lconv *cv = localeconv(); + char old = ls->decpoint; + ls->decpoint = (cv ? cv->decimal_point[0] : '.'); + buffreplace(ls, old, ls->decpoint); /* try updated decimal separator */ + if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r)) { + /* format error with correct decimal point: no more options */ + buffreplace(ls, ls->decpoint, '.'); /* undo change (for error message) */ + luaX_lexerror(ls, "malformed number", TK_NUMBER); + } +} + + +/* LUA_NUMBER */ +static void read_numeral (LexState *ls, SemInfo *seminfo) { + lua_assert(isdigit(ls->current)); + do { + save_and_next(ls); + } while (isdigit(ls->current) || ls->current == '.'); + if (check_next(ls, "Ee")) /* `E'? */ + check_next(ls, "+-"); /* optional exponent sign */ + while (isalnum(ls->current) || ls->current == '_') + save_and_next(ls); + save(ls, '\0'); + buffreplace(ls, '.', ls->decpoint); /* follow locale for decimal point */ + if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r)) /* format error? */ + trydecpoint(ls, seminfo); /* try to update decimal point separator */ +} + + +static int skip_sep (LexState *ls) { + int count = 0; + int s = ls->current; + lua_assert(s == '[' || s == ']'); + save_and_next(ls); + while (ls->current == '=') { + save_and_next(ls); + count++; + } + return (ls->current == s) ? count : (-count) - 1; +} + + +static void read_long_string (LexState *ls, SemInfo *seminfo, int sep) { + int cont = 0; + (void)(cont); /* avoid warnings when `cont' is not used */ + save_and_next(ls); /* skip 2nd `[' */ + if (currIsNewline(ls)) /* string starts with a newline? */ + inclinenumber(ls); /* skip it */ + for (;;) { + switch (ls->current) { + case EOZ: + luaX_lexerror(ls, (seminfo) ? "unfinished long string" : + "unfinished long comment", TK_EOS); + break; /* to avoid warnings */ +#if defined(LUA_COMPAT_LSTR) + case '[': { + if (skip_sep(ls) == sep) { + save_and_next(ls); /* skip 2nd `[' */ + cont++; +#if LUA_COMPAT_LSTR == 1 + if (sep == 0) + luaX_lexerror(ls, "nesting of [[...]] is deprecated", '['); +#endif + } + break; + } +#endif + case ']': { + if (skip_sep(ls) == sep) { + save_and_next(ls); /* skip 2nd `]' */ +#if defined(LUA_COMPAT_LSTR) && LUA_COMPAT_LSTR == 2 + cont--; + if (sep == 0 && cont >= 0) break; +#endif + goto endloop; + } + break; + } + case '\n': + case '\r': { + save(ls, '\n'); + inclinenumber(ls); + if (!seminfo) luaZ_resetbuffer(ls->buff); /* avoid wasting space */ + break; + } + default: { + if (seminfo) save_and_next(ls); + else next(ls); + } + } + } endloop: + if (seminfo) + seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + (2 + sep), + luaZ_bufflen(ls->buff) - 2*(2 + sep)); +} + + +static void read_string (LexState *ls, int del, SemInfo *seminfo) { + save_and_next(ls); + while (ls->current != del) { + switch (ls->current) { + case EOZ: + luaX_lexerror(ls, "unfinished string", TK_EOS); + continue; /* to avoid warnings */ + case '\n': + case '\r': + luaX_lexerror(ls, "unfinished string", TK_STRING); + continue; /* to avoid warnings */ + case '\\': { + int c; + next(ls); /* do not save the `\' */ + switch (ls->current) { + case 'a': c = '\a'; break; + case 'b': c = '\b'; break; + case 'f': c = '\f'; break; + case 'n': c = '\n'; break; + case 'r': c = '\r'; break; + case 't': c = '\t'; break; + case 'v': c = '\v'; break; + case '\n': /* go through */ + case '\r': save(ls, '\n'); inclinenumber(ls); continue; + case EOZ: continue; /* will raise an error next loop */ + case '$': + if (del == '"') { + save_and_next(ls); /* skip $ */ + seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + 1, + luaZ_bufflen(ls->buff) - 2); + ls->refstr++; /* expect '\' anytime soon */ + lua_assert(ls->lookahead.token == TK_EOS); + ls->lookahead.token = TK_CONCAT; + return; + } + default: { + if (!isdigit(ls->current)) + save_and_next(ls); /* handles \\, \", \', and \? */ + else { /* \xxx */ + int i = 0; + c = 0; + do { + c = 10*c + (ls->current-'0'); + next(ls); + } while (++i<3 && isdigit(ls->current)); + if (c > UCHAR_MAX) + luaX_lexerror(ls, "escape sequence too large", TK_STRING); + save(ls, c); + } + continue; + } + // "\x00".."\xFFFF": raw hex literals + // + case 'x': { + int i; + c = 0; + next(ls); // skip 'x' + + for( i=0; i<5 && isxdigit(ls->current); i++ ) { + c = (c<<4) | _HEX2INT_(ls->current); + next(ls); + }; + + switch (i) { + case 4: save( ls, (c>>8) & 0xff ); // pass-through.. + case 2: save( ls, c&0xff ); + break; + case 5: + default: + luaX_lexerror(ls, "escape sequence wrong size (2 or 4 digits)", TK_STRING); + } + } + continue; + + // "\u0000".."\x10FFFF": UTF-8 encoded Unicode + // + // Note that although codes are entered like this (must have min. four digit, + // just to tease you!) the actual outcome in the string will vary between + // 1..4 bytes, depending on the value range. + // + case 'u': { + int i; + c = 0; + next(ls); // skip 'x' + + for ( i=0; i<7 && isxdigit(ls->current); i++ ) { + c = (c<<4) | _HEX2INT_(ls->current); + next(ls); + }; + + if ((i!=4) && (i!=6)) { + luaX_lexerror(ls, "escape sequence wrong size (4 or 6 digits)", TK_STRING); + } + + /* http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 + U-00000000 - U-0000007F: 0xxxxxxx + U-00000080 - U-000007FF: 110xxxxx 10xxxxxx + U-00000800 - U-0000FFFF: 1110xxxx 10xxxxxx 10xxxxxx + U-00010000 - U-001FFFFF: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx + (U-00200000 - U-03FFFFFF: 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx) + (U-04000000 - U-7FFFFFFF: 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx) + */ + if ( c <= 0x007f ) { // 1-byte + save( ls, c ); + } else if ( c <= 0x000007ff ) { // 2-byte + save( ls, 0xc0 | ((c>>6)&0x1f) ); + save( ls, 0x80 | (c&0x3f) ); + } else if ( c <= 0x0000ffff ) { // 3-byte + save( ls, 0xe0 | ((c>>12)&0x0f) ); + save( ls, 0x80 | ((c>>6)&0x3f) ); + save( ls, 0x80 | (c&0x3f) ); + } else if ( c <= 0x001fffff ) { // 4-byte + save( ls, 0xf0 | ((c>>18)&0x07) ); + save( ls, 0x80 | ((c>>12)&0x3f) ); + save( ls, 0x80 | ((c>>6)&0x3f) ); + save( ls, 0x80 | (c&0x3f) ); + } else { + luaX_lexerror(ls, "escape sequence too large", TK_STRING); + } + } + continue; + } + save(ls, c); + next(ls); + continue; + } + default: + save_and_next(ls); + } + } + save_and_next(ls); /* skip delimiter */ + seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + 1, + luaZ_bufflen(ls->buff) - 2); +} + + +static int llex (LexState *ls, SemInfo *seminfo) { + luaZ_resetbuffer(ls->buff); + for (;;) { + switch (ls->current) { + case '\n': + case '\r': { + inclinenumber(ls); + continue; + } + case '-': { + next(ls); + if (ls->current != '-') return '-'; + /* else is a comment */ + next(ls); + if (ls->current == '[') { + int sep = skip_sep(ls); + luaZ_resetbuffer(ls->buff); /* `skip_sep' may dirty the buffer */ + if (sep >= 0) { + read_long_string(ls, NULL, sep); /* long comment */ + luaZ_resetbuffer(ls->buff); + continue; + } + } + /* else short comment */ + while (!currIsNewline(ls) && ls->current != EOZ) + next(ls); + continue; + } + case '/': { + next(ls); + if (ls->current != '/' && ls->current != '*') return '/'; + /* else is a comment */ + if (ls->current == '*') { + char last = '\n'; /* don't remember the first asterisk, we need a different one. */ + next(ls); + if (currIsNewline(ls)) /* comment starts with a newline? */ + inclinenumber(ls); /* skip it */ + while(last != '*' || ls->current != '/') { + switch (ls->current) { + case EOZ: + luaX_lexerror(ls, "unterminated long comment", TK_EOS); + break; + case '\n': + case '\r': + last = '\n'; /* remember the newline */ + inclinenumber(ls); + break; + default: + last = ls->current; + next(ls); + break; + } + } + next(ls); + continue; + } + /* else short comment */ + while (!currIsNewline(ls) && ls->current != EOZ) + next(ls); + continue; + } + case '[': { + int sep = skip_sep(ls); + if (sep >= 0) { + read_long_string(ls, seminfo, sep); + return TK_STRING; + } + else if (sep == -1) return '['; + else luaX_lexerror(ls, "invalid long string delimiter", TK_STRING); + } + case '=': { + next(ls); + if (ls->current != '=') return '='; + else { next(ls); return TK_EQ; } + } + case '<': { + next(ls); + if (ls->current == '<') { next(ls); return TK_SHL; } + if (ls->current != '=') return '<'; + else { next(ls); return TK_LE; } + } + case '>': { + next(ls); + if (ls->current == '>') { next(ls); return TK_SHR; } + if (ls->current != '=') return '>'; + else { next(ls); return TK_GE; } + } + case '^': { + next(ls); + if (ls->current == '^') { next(ls); return TK_XOR; } + else { return '^'; } + } + case '!': { + next(ls); + if (ls->current != '=') return '~'; + else { next(ls); return TK_NE; } + } + case '~': { + next(ls); + if (ls->current != '=') return '~'; + else { next(ls); return TK_NE; } + } + case '"': + case '\'': { + read_string(ls, ls->current, seminfo); + return TK_STRING; + } + case '.': { + save_and_next(ls); + if (check_next(ls, ".")) { + if (check_next(ls, ".")) + return TK_DOTS; /* ... */ + else return TK_CONCAT; /* .. */ + } + else if (!isdigit(ls->current)) return '.'; + else { + read_numeral(ls, seminfo); + return TK_NUMBER; + } + } + case '$': { + int i = 0; + next(ls); + while (isdigit(ls->current)) { + i = 10*i + (ls->current-'0'); + next(ls); + } + seminfo->r = i; + return '$'; + } + case EOZ: { + return TK_EOS; + } + case '\\': if (ls->refstr) { + ls->refstr--; + ls->current = '"'; /* whacky! */ + return TK_CONCAT; + } + default: { + if (isspace(ls->current)) { + lua_assert(!currIsNewline(ls)); + next(ls); + continue; + } + else if (isdigit(ls->current)) { + read_numeral(ls, seminfo); + return TK_NUMBER; + } + else if (isalpha(ls->current) || ls->current == '_') { + /* identifier or reserved word */ + TString *ts; + do { + save_and_next(ls); + } while (isalnum(ls->current) || ls->current == '_'); + ts = luaX_newstring(ls, luaZ_buffer(ls->buff), + luaZ_bufflen(ls->buff)); + if (ts->tsv.reserved > 0) /* reserved word? */ + return ts->tsv.reserved - 1 + FIRST_RESERVED; + else { + seminfo->ts = ts; + return TK_NAME; + } + } + else { + int c = ls->current; + next(ls); + return c; /* single-char tokens (+ - / ...) */ + } + } + } + } +} + + +void luaX_next (LexState *ls) { + ls->lastline = ls->linenumber; + if (ls->lookahead.token != TK_EOS) { /* is there a look-ahead token? */ + ls->t = ls->lookahead; /* use this one */ + ls->lookahead.token = TK_EOS; /* and discharge it */ + } + else + ls->t.token = llex(ls, &ls->t.seminfo); /* read next token */ +} + + +void luaX_lookahead (LexState *ls) { + lua_assert(ls->lookahead.token == TK_EOS); + ls->lookahead.token = llex(ls, &ls->lookahead.seminfo); +} diff --git a/src/blua/llex.h b/src/blua/llex.h new file mode 100644 index 000000000..3f55c75cd --- /dev/null +++ b/src/blua/llex.h @@ -0,0 +1,83 @@ +/* +** $Id: llex.h,v 1.58.1.1 2007/12/27 13:02:25 roberto Exp $ +** Lexical Analyzer +** See Copyright Notice in lua.h +*/ + +#ifndef llex_h +#define llex_h + +#include "lobject.h" +#include "lzio.h" + + +#define FIRST_RESERVED 257 + +/* maximum length of a reserved word */ +#define TOKEN_LEN (sizeof("function")/sizeof(char)) + + +/* +* WARNING: if you change the order of this enumeration, +* grep "ORDER RESERVED" +*/ +enum RESERVED { + /* terminal symbols denoted by reserved words */ + TK_AND = FIRST_RESERVED, TK_BREAK, TK_CONTINUE, + TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION, + TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT, + TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE, + /* other terminal symbols */ + TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_NUMBER, + TK_NAME, TK_STRING, TK_EOS + ,TK_SHL, TK_SHR, TK_XOR, +}; + +/* number of reserved words */ +#define NUM_RESERVED (cast(int, TK_WHILE-FIRST_RESERVED+1)) + + +/* array with token `names' */ +LUAI_DATA const char *const luaX_tokens []; + + +typedef union { + lua_Number r; + TString *ts; +} SemInfo; /* semantics information */ + + +typedef struct Token { + int token; + SemInfo seminfo; +} Token; + + +typedef struct LexState { + int current; /* current character (charint) */ + int linenumber; /* input line counter */ + int lastline; /* line of last token `consumed' */ + Token t; /* current token */ + Token lookahead; /* look ahead token */ + struct FuncState *fs; /* `FuncState' is private to the parser */ + struct lua_State *L; + ZIO *z; /* input stream */ + Mbuffer *buff; /* buffer for tokens */ + TString *source; /* current source name */ + char decpoint; /* locale decimal point */ + int refstr; +} LexState; + + +LUAI_FUNC void luaX_init (lua_State *L); +LUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, + TString *source); +LUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l); +LUAI_FUNC void luaX_next (LexState *ls); +LUAI_FUNC void luaX_lookahead (LexState *ls); +LUAI_FUNC void luaX_lexerror (LexState *ls, const char *msg, int token); +LUAI_FUNC void luaX_syntaxerror (LexState *ls, const char *s); +LUAI_FUNC const char *luaX_token2str (LexState *ls, int token); + + +#endif diff --git a/src/blua/llimits.h b/src/blua/llimits.h new file mode 100644 index 000000000..20475d41f --- /dev/null +++ b/src/blua/llimits.h @@ -0,0 +1,128 @@ +/* +** $Id: llimits.h,v 1.69.1.1 2007/12/27 13:02:25 roberto Exp $ +** Limits, basic types, and some other `installation-dependent' definitions +** See Copyright Notice in lua.h +*/ + +#ifndef llimits_h +#define llimits_h + + +#include +#include + + +#include "lua.h" + + +typedef LUAI_UINT32 lu_int32; + +typedef LUAI_UMEM lu_mem; + +typedef LUAI_MEM l_mem; + + + +/* chars used as small naturals (so that `char' is reserved for characters) */ +typedef unsigned char lu_byte; + + +#define MAX_SIZET ((size_t)(~(size_t)0)-2) + +#define MAX_LUMEM ((lu_mem)(~(lu_mem)0)-2) + + +#define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */ + +/* +** conversion of pointer to integer +** this is for hashing only; there is no problem if the integer +** cannot hold the whole pointer value +*/ +#define IntPoint(p) ((unsigned int)(lu_mem)(p)) + + + +/* type to ensure maximum alignment */ +typedef LUAI_USER_ALIGNMENT_T L_Umaxalign; + + +/* result of a `usual argument conversion' over lua_Number */ +typedef LUAI_UACNUMBER l_uacNumber; + + +/* internal assertions for in-house debugging */ +#ifdef lua_assert + +#define check_exp(c,e) (lua_assert(c), (e)) +#define api_check(l,e) lua_assert(e) + +#else + +#define lua_assert(c) ((void)0) +#define check_exp(c,e) (e) +#define api_check luai_apicheck + +#endif + + +#ifndef UNUSED +#define UNUSED(x) ((void)(x)) /* to avoid warnings */ +#endif + + +#ifndef cast +#define cast(t, exp) ((t)(exp)) +#endif + +#define cast_byte(i) cast(lu_byte, (i)) +#define cast_num(i) cast(lua_Number, (i)) +#define cast_int(i) cast(int, (i)) + + + +/* +** type for virtual-machine instructions +** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h) +*/ +typedef lu_int32 Instruction; + + + +/* maximum stack for a Lua function */ +#define MAXSTACK 250 + + + +/* minimum size for the string table (must be power of 2) */ +#ifndef MINSTRTABSIZE +#define MINSTRTABSIZE 32 +#endif + + +/* minimum size for string buffer */ +#ifndef LUA_MINBUFFER +#define LUA_MINBUFFER 32 +#endif + + +#ifndef lua_lock +#define lua_lock(L) ((void) 0) +#define lua_unlock(L) ((void) 0) +#endif + +#ifndef luai_threadyield +#define luai_threadyield(L) {lua_unlock(L); lua_lock(L);} +#endif + + +/* +** macro to control inclusion of some hard tests on stack reallocation +*/ +#ifndef HARDSTACKTESTS +#define condhardstacktests(x) ((void)0) +#else +#define condhardstacktests(x) x +#endif + +#endif diff --git a/src/blua/lmem.c b/src/blua/lmem.c new file mode 100644 index 000000000..1b9bed658 --- /dev/null +++ b/src/blua/lmem.c @@ -0,0 +1,85 @@ +/* +** $Id: lmem.c,v 1.70.1.1 2007/12/27 13:02:25 roberto Exp $ +** Interface to Memory Manager +** See Copyright Notice in lua.h +*/ + + +#include + +#define lmem_c +#define LUA_CORE + +#include "lua.h" + +#include "ldebug.h" +#include "ldo.h" +#include "lmem.h" +#include "lobject.h" +#include "lstate.h" + + + +/* +** About the realloc function: +** void * frealloc (void *ud, void *ptr, size_t osize, size_t nsize); +** (`osize' is the old size, `nsize' is the new size) +** +** Lua ensures that (ptr == NULL) iff (osize == 0). +** +** * frealloc(ud, NULL, 0, x) creates a new block of size `x' +** +** * frealloc(ud, p, x, 0) frees the block `p' +** (in this specific case, frealloc must return NULL). +** particularly, frealloc(ud, NULL, 0, 0) does nothing +** (which is equivalent to free(NULL) in ANSI C) +** +** frealloc returns NULL if it cannot create or reallocate the area +** (any reallocation to an equal or smaller size cannot fail!) +*/ + + + +#define MINSIZEARRAY 4 + + +void *luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elems, + int limit, const char *errormsg) { + void *newblock; + int newsize; + if (*size >= limit/2) { /* cannot double it? */ + if (*size >= limit) /* cannot grow even a little? */ + luaG_runerror(L, errormsg); + newsize = limit; /* still have at least one free place */ + } + else { + newsize = (*size)*2; + if (newsize < MINSIZEARRAY) + newsize = MINSIZEARRAY; /* minimum size */ + } + newblock = luaM_reallocv(L, block, *size, newsize, size_elems); + *size = newsize; /* update only when everything else is OK */ + return newblock; +} + + +void *luaM_toobig (lua_State *L) { + luaG_runerror(L, "memory allocation error: block too big"); + return NULL; /* to avoid warnings */ +} + + + +/* +** generic allocation routine. +*/ +void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) { + global_State *g = G(L); + lua_assert((osize == 0) == (block == NULL)); + block = (*g->frealloc)(g->ud, block, osize, nsize); + if (block == NULL && nsize > 0) + luaD_throw(L, LUA_ERRMEM); + lua_assert((nsize == 0) == (block == NULL)); + g->totalbytes = (g->totalbytes - osize) + nsize; + return block; +} diff --git a/src/blua/lmem.h b/src/blua/lmem.h new file mode 100644 index 000000000..ebfc22747 --- /dev/null +++ b/src/blua/lmem.h @@ -0,0 +1,48 @@ +/* +** $Id: lmem.h,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $ +** Interface to Memory Manager +** See Copyright Notice in lua.h +*/ + +#ifndef lmem_h +#define lmem_h + + +#include + +#include "llimits.h" +#include "lua.h" + +#define MEMERRMSG "not enough memory" + + +#define luaM_reallocv(L,b,on,n,e) \ + ((cast(size_t, (n)+1) <= MAX_SIZET/(e)) ? /* +1 to avoid warnings */ \ + luaM_realloc_(L, (b), (on)*(e), (n)*(e)) : \ + luaM_toobig(L)) + +#define luaM_freemem(L, b, s) luaM_realloc_(L, (b), (s), 0) +#define luaM_free(L, b) luaM_realloc_(L, (b), sizeof(*(b)), 0) +#define luaM_freearray(L, b, n, t) luaM_reallocv(L, (b), n, 0, sizeof(t)) + +#define luaM_malloc(L,t) luaM_realloc_(L, NULL, 0, (t)) +#define luaM_new(L,t) cast(t *, luaM_malloc(L, sizeof(t))) +#define luaM_newvector(L,n,t) \ + cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t))) + +#define luaM_growvector(L,v,nelems,size,t,limit,e) \ + if ((nelems)+1 > (size)) \ + ((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e))) + +#define luaM_reallocvector(L, v,oldn,n,t) \ + ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t)))) + + +LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize, + size_t size); +LUAI_FUNC void *luaM_toobig (lua_State *L); +LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size, + size_t size_elem, int limit, + const char *errormsg); + +#endif diff --git a/src/blua/lobject.c b/src/blua/lobject.c new file mode 100644 index 000000000..0250de21d --- /dev/null +++ b/src/blua/lobject.c @@ -0,0 +1,215 @@ +/* +** $Id: lobject.c,v 2.22.1.1 2007/12/27 13:02:25 roberto Exp $ +** Some generic functions over Lua objects +** See Copyright Notice in lua.h +*/ + +#include +#include +#include +#include +#include + +#define lobject_c +#define LUA_CORE + +#include "lua.h" + +#include "ldo.h" +#include "lmem.h" +#include "lobject.h" +#include "lstate.h" +#include "lstring.h" +#include "lvm.h" + + + +/*const*/ TValue luaO_nilobject_ = {{NULL}, LUA_TNIL}; + + +/* +** converts an integer to a "floating point byte", represented as +** (eeeeexxx), where the real value is (1xxx) * 2^(eeeee - 1) if +** eeeee != 0 and (xxx) otherwise. +*/ +int luaO_int2fb (unsigned int x) { + int e = 0; /* expoent */ + while (x >= 16) { + x = (x+1) >> 1; + e++; + } + if (x < 8) return x; + else return ((e+1) << 3) | (cast_int(x) - 8); +} + + +/* converts back */ +int luaO_fb2int (int x) { + int e = (x >> 3) & 31; + if (e == 0) return x; + else return ((x & 7)+8) << (e - 1); +} + + +int luaO_log2 (unsigned int x) { + static const lu_byte log_2[256] = { + 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, + 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8 + }; + int l = -1; + while (x >= 256) { l += 8; x >>= 8; } + return l + log_2[x]; + +} + + +int luaO_rawequalObj (const TValue *t1, const TValue *t2) { + if (ttype(t1) != ttype(t2)) return 0; + else switch (ttype(t1)) { + case LUA_TNIL: + return 1; + case LUA_TNUMBER: + return luai_numeq(nvalue(t1), nvalue(t2)); + case LUA_TBOOLEAN: + return bvalue(t1) == bvalue(t2); /* boolean true must be 1 !! */ + case LUA_TLIGHTUSERDATA: + return pvalue(t1) == pvalue(t2); + default: + lua_assert(iscollectable(t1)); + return gcvalue(t1) == gcvalue(t2); + } +} + + +int luaO_str2d (const char *s, lua_Number *result) { + char *endptr; + double r = lua_str2number(s, &endptr); + *result = (lua_Number)r; + if (endptr == s) return 0; /* conversion failed */ + if (*endptr == 'x' || *endptr == 'X') /* maybe an hexadecimal constant? */ + *result = cast_num(strtoul(s, &endptr, 16)); + if (*endptr == '\0') return 1; /* most common case */ + while (isspace(cast(unsigned char, *endptr))) endptr++; + if (*endptr != '\0') return 0; /* invalid trailing characters? */ + return 1; +} + + + +static void pushstr (lua_State *L, const char *str) { + setsvalue2s(L, L->top, luaS_new(L, str)); + incr_top(L); +} + + +/* this function handles only `%d', `%c', %f, %p, and `%s' formats */ +const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) { + int n = 1; + pushstr(L, ""); + for (;;) { + const char *e = strchr(fmt, '%'); + if (e == NULL) break; + setsvalue2s(L, L->top, luaS_newlstr(L, fmt, e-fmt)); + incr_top(L); + switch (*(e+1)) { + case 's': { + const char *s = va_arg(argp, char *); + if (s == NULL) s = "(null)"; + pushstr(L, s); + break; + } + case 'c': { + char buff[2]; + buff[0] = cast(char, va_arg(argp, int)); + buff[1] = '\0'; + pushstr(L, buff); + break; + } + case 'd': { + setnvalue(L->top, cast_num(va_arg(argp, int))); + incr_top(L); + break; + } + case 'f': { + setnvalue(L->top, cast_num(va_arg(argp, l_uacNumber))); + incr_top(L); + break; + } + case 'p': { + char buff[4*sizeof(void *) + 8]; /* should be enough space for a `%p' */ + sprintf(buff, "%p", va_arg(argp, void *)); + pushstr(L, buff); + break; + } + case '%': { + pushstr(L, "%"); + break; + } + default: { + char buff[3]; + buff[0] = '%'; + buff[1] = *(e+1); + buff[2] = '\0'; + pushstr(L, buff); + break; + } + } + n += 2; + fmt = e+2; + } + pushstr(L, fmt); + luaV_concat(L, n+1, cast_int(L->top - L->base) - 1); + L->top -= n; + return svalue(L->top - 1); +} + + +const char *luaO_pushfstring (lua_State *L, const char *fmt, ...) { + const char *msg; + va_list argp; + va_start(argp, fmt); + msg = luaO_pushvfstring(L, fmt, argp); + va_end(argp); + return msg; +} + + +void luaO_chunkid (char *out, const char *source, size_t bufflen) { + if (*source == '=') { + strncpy(out, source+1, bufflen); /* remove first char */ + out[bufflen-1] = '\0'; /* ensures null termination */ + } + else { /* out = "source", or "...source" */ + if (*source == '@') { + size_t l; + source++; /* skip the `@' */ + bufflen -= sizeof(" '...' "); + l = strlen(source); + strcpy(out, ""); + if (l > bufflen) { + source += (l-bufflen); /* get last part of file name */ + strcat(out, "..."); + } + strcat(out, source); + } + else { /* out = [string "string"] */ + size_t len = strcspn(source, "\n\r"); /* stop at first newline */ + bufflen -= sizeof(" [string \"...\"] "); + if (len > bufflen) len = bufflen; + strcpy(out, "[string \""); + if (source[len] != '\0') { /* must truncate? */ + strncat(out, source, len); + strcat(out, "..."); + } + else + strcat(out, source); + strcat(out, "\"]"); + } + } +} diff --git a/src/blua/lobject.h b/src/blua/lobject.h new file mode 100644 index 000000000..24309a1ec --- /dev/null +++ b/src/blua/lobject.h @@ -0,0 +1,380 @@ +/* +** $Id: lobject.h,v 2.20.1.2 2008/08/06 13:29:48 roberto Exp $ +** Type definitions for Lua objects +** See Copyright Notice in lua.h +*/ + + +#ifndef lobject_h +#define lobject_h + + +#include + + +#include "llimits.h" +#include "lua.h" + + +/* tags for values visible from Lua */ +#define LAST_TAG LUA_TTHREAD + +#define NUM_TAGS (LAST_TAG+1) + + +/* +** Extra tags for non-values +*/ +#define LUA_TPROTO (LAST_TAG+1) +#define LUA_TUPVAL (LAST_TAG+2) +#define LUA_TDEADKEY (LAST_TAG+3) + + +/* +** Union of all collectable objects +*/ +typedef union GCObject GCObject; + + +/* +** Common Header for all collectable objects (in macro form, to be +** included in other objects) +*/ +#define CommonHeader GCObject *next; lu_byte tt; lu_byte marked + + +/* +** Common header in struct form +*/ +typedef struct GCheader { + CommonHeader; +} GCheader; + + + + +/* +** Union of all Lua values +*/ +typedef union { + GCObject *gc; + void *p; + lua_Number n; + int b; +} Value; + + +/* +** Tagged Values +*/ + +#define TValuefields Value value; int tt + +typedef struct lua_TValue { + TValuefields; +} TValue; + + +/* Macros to test type */ +#define ttisnil(o) (ttype(o) == LUA_TNIL) +#define ttisnumber(o) (ttype(o) == LUA_TNUMBER) +#define ttisstring(o) (ttype(o) == LUA_TSTRING) +#define ttistable(o) (ttype(o) == LUA_TTABLE) +#define ttisfunction(o) (ttype(o) == LUA_TFUNCTION) +#define ttisboolean(o) (ttype(o) == LUA_TBOOLEAN) +#define ttisuserdata(o) (ttype(o) == LUA_TUSERDATA) +#define ttisthread(o) (ttype(o) == LUA_TTHREAD) +#define ttislightuserdata(o) (ttype(o) == LUA_TLIGHTUSERDATA) + +/* Macros to access values */ +#define ttype(o) ((o)->tt) +#define gcvalue(o) check_exp(iscollectable(o), (o)->value.gc) +#define pvalue(o) check_exp(ttislightuserdata(o), (o)->value.p) +#define nvalue(o) check_exp(ttisnumber(o), (o)->value.n) +#define rawtsvalue(o) check_exp(ttisstring(o), &(o)->value.gc->ts) +#define tsvalue(o) (&rawtsvalue(o)->tsv) +#define rawuvalue(o) check_exp(ttisuserdata(o), &(o)->value.gc->u) +#define uvalue(o) (&rawuvalue(o)->uv) +#define clvalue(o) check_exp(ttisfunction(o), &(o)->value.gc->cl) +#define hvalue(o) check_exp(ttistable(o), &(o)->value.gc->h) +#define bvalue(o) check_exp(ttisboolean(o), (o)->value.b) +#define thvalue(o) check_exp(ttisthread(o), &(o)->value.gc->th) + +#define l_isfalse(o) (ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0) || (ttisnumber(o) && nvalue(o) == 0)) + +/* +** for internal debug only +*/ +#define checkconsistency(obj) \ + lua_assert(!iscollectable(obj) || (ttype(obj) == (obj)->value.gc->gch.tt)) + +#define checkliveness(g,obj) \ + lua_assert(!iscollectable(obj) || \ + ((ttype(obj) == (obj)->value.gc->gch.tt) && !isdead(g, (obj)->value.gc))) + + +/* Macros to set values */ +#define setnilvalue(obj) ((obj)->tt=LUA_TNIL) + +#define setnvalue(obj,x) \ + { TValue *i_o=(obj); i_o->value.n=(x); i_o->tt=LUA_TNUMBER; } + +#define setpvalue(obj,x) \ + { TValue *i_o=(obj); i_o->value.p=(x); i_o->tt=LUA_TLIGHTUSERDATA; } + +#define setbvalue(obj,x) \ + { TValue *i_o=(obj); i_o->value.b=(x); i_o->tt=LUA_TBOOLEAN; } + +#define setsvalue(L,obj,x) \ + { TValue *i_o=(obj); \ + i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TSTRING; \ + checkliveness(G(L),i_o); } + +#define setuvalue(L,obj,x) \ + { TValue *i_o=(obj); \ + i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TUSERDATA; \ + checkliveness(G(L),i_o); } + +#define setthvalue(L,obj,x) \ + { TValue *i_o=(obj); \ + i_o->value.gc=cast(GCObject *, (void *)(x)); i_o->tt=LUA_TTHREAD; \ + checkliveness(G(L),i_o); } + +#define setclvalue(L,obj,x) \ + { TValue *i_o=(obj); \ + i_o->value.gc=cast(GCObject *, (void *)(x)); i_o->tt=LUA_TFUNCTION; \ + checkliveness(G(L),i_o); } + +#define sethvalue(L,obj,x) \ + { TValue *i_o=(obj); \ + i_o->value.gc=cast(GCObject *, (void *)(x)); i_o->tt=LUA_TTABLE; \ + checkliveness(G(L),i_o); } + +#define setptvalue(L,obj,x) \ + { TValue *i_o=(obj); \ + i_o->value.gc=cast(GCObject *, (void *)(x)); i_o->tt=LUA_TPROTO; \ + checkliveness(G(L),i_o); } + + + + +#define setobj(L,obj1,obj2) \ + { const TValue *o2=(obj2); TValue *o1=(obj1); \ + o1->value = o2->value; o1->tt=o2->tt; \ + checkliveness(G(L),o1); } + + +/* +** different types of sets, according to destination +*/ + +/* from stack to (same) stack */ +#define setobjs2s setobj +/* to stack (not from same stack) */ +#define setobj2s setobj +#define setsvalue2s setsvalue +#define sethvalue2s sethvalue +#define setptvalue2s setptvalue +/* from table to same table */ +#define setobjt2t setobj +/* to table */ +#define setobj2t setobj +/* to new object */ +#define setobj2n setobj +#define setsvalue2n setsvalue + +#define setttype(obj, tt) (ttype(obj) = (tt)) + + +#define iscollectable(o) (ttype(o) >= LUA_TSTRING) + + + +typedef TValue *StkId; /* index to stack elements */ + + +/* +** String headers for string table +*/ +typedef union TString { + L_Umaxalign dummy; /* ensures maximum alignment for strings */ + struct { + CommonHeader; + lu_byte reserved; + unsigned int hash; + size_t len; + } tsv; +} TString; + + +#define getstr(ts) cast(const char *, (ts) + 1) +#define svalue(o) getstr(rawtsvalue(o)) + + + +typedef union Udata { + L_Umaxalign dummy; /* ensures maximum alignment for `local' udata */ + struct { + CommonHeader; + struct Table *metatable; + struct Table *env; + size_t len; + } uv; +} Udata; + + + + +/* +** Function Prototypes +*/ +typedef struct Proto { + CommonHeader; + TValue *k; /* constants used by the function */ + Instruction *code; + struct Proto **p; /* functions defined inside the function */ + int *lineinfo; /* map from opcodes to source lines */ + struct LocVar *locvars; /* information about local variables */ + TString **upvalues; /* upvalue names */ + TString *source; + int sizeupvalues; + int sizek; /* size of `k' */ + int sizecode; + int sizelineinfo; + int sizep; /* size of `p' */ + int sizelocvars; + int linedefined; + int lastlinedefined; + GCObject *gclist; + lu_byte nups; /* number of upvalues */ + lu_byte numparams; + lu_byte is_vararg; + lu_byte maxstacksize; +} Proto; + + +/* masks for new-style vararg */ +#define VARARG_HASARG 1 +#define VARARG_ISVARARG 2 +#define VARARG_NEEDSARG 4 + + +typedef struct LocVar { + TString *varname; + int startpc; /* first point where variable is active */ + int endpc; /* first point where variable is dead */ +} LocVar; + + + +/* +** Upvalues +*/ + +typedef struct UpVal { + CommonHeader; + TValue *v; /* points to stack or to its own value */ + union { + TValue value; /* the value (when closed) */ + struct { /* double linked list (when open) */ + struct UpVal *prev; + struct UpVal *next; + } l; + } u; +} UpVal; + + +/* +** Closures +*/ + +#define ClosureHeader \ + CommonHeader; lu_byte isC; lu_byte nupvalues; GCObject *gclist; \ + struct Table *env + +typedef struct CClosure { + ClosureHeader; + lua_CFunction f; + TValue upvalue[1]; +} CClosure; + + +typedef struct LClosure { + ClosureHeader; + struct Proto *p; + UpVal *upvals[1]; +} LClosure; + + +typedef union Closure { + CClosure c; + LClosure l; +} Closure; + + +#define iscfunction(o) (ttype(o) == LUA_TFUNCTION && clvalue(o)->c.isC) +#define isLfunction(o) (ttype(o) == LUA_TFUNCTION && !clvalue(o)->c.isC) + + +/* +** Tables +*/ + +typedef union TKey { + struct { + TValuefields; + struct Node *next; /* for chaining */ + } nk; + TValue tvk; +} TKey; + + +typedef struct Node { + TValue i_val; + TKey i_key; +} Node; + + +typedef struct Table { + CommonHeader; + lu_byte flags; /* 1<

lsizenode)) + + +#define luaO_nilobject (&luaO_nilobject_) + +LUAI_DATA /*const*/ TValue luaO_nilobject_; + +#define ceillog2(x) (luaO_log2((x)-1) + 1) + +LUAI_FUNC int luaO_log2 (unsigned int x); +LUAI_FUNC int luaO_int2fb (unsigned int x); +LUAI_FUNC int luaO_fb2int (int x); +LUAI_FUNC int luaO_rawequalObj (const TValue *t1, const TValue *t2); +LUAI_FUNC int luaO_str2d (const char *s, lua_Number *result); +LUAI_FUNC const char *luaO_pushvfstring (lua_State *L, const char *fmt, + va_list argp); +LUAI_FUNC const char *luaO_pushfstring (lua_State *L, const char *fmt, ...); +LUAI_FUNC void luaO_chunkid (char *out, const char *source, size_t len); + + +#endif diff --git a/src/blua/lopcodes.c b/src/blua/lopcodes.c new file mode 100644 index 000000000..b5bd4d857 --- /dev/null +++ b/src/blua/lopcodes.c @@ -0,0 +1,113 @@ +/* +** $Id: lopcodes.c,v 1.37.1.1 2007/12/27 13:02:25 roberto Exp $ +** See Copyright Notice in lua.h +*/ + + +#define lopcodes_c +#define LUA_CORE + + +#include "lopcodes.h" + + +/* ORDER OP */ + +const char *const luaP_opnames[NUM_OPCODES+1] = { + "MOVE", + "LOADK", + "LOADBOOL", + "LOADNIL", + "GETUPVAL", + "GETGLOBAL", + "GETTABLE", + "SETGLOBAL", + "SETUPVAL", + "SETTABLE", + "NEWTABLE", + "SELF", + "ADD", + "SUB", + "MUL", + "DIV", + "MOD", + "POW", + "UNM", + "NOT", + "LEN", + "CONCAT", + "JMP", + "EQ", + "LT", + "LE", + "TEST", + "TESTSET", + "CALL", + "TAILCALL", + "RETURN", + "FORLOOP", + "FORPREP", + "TFORLOOP", + "SETLIST", + "CLOSE", + "CLOSURE", + "BITAND", + "BITOR", + "BITXOR", + "BITSHL", + "BITSHR", + "BITNOT", + "VARARG", + NULL +}; + + +#define opmode(t,a,b,c,m) (((t)<<7) | ((a)<<6) | ((b)<<4) | ((c)<<2) | (m)) + +const lu_byte luaP_opmodes[NUM_OPCODES] = { +/* T A B C mode opcode */ + opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_MOVE */ + ,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_LOADK */ + ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_LOADBOOL */ + ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_LOADNIL */ + ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_GETUPVAL */ + ,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_GETGLOBAL */ + ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_GETTABLE */ + ,opmode(0, 0, OpArgK, OpArgN, iABx) /* OP_SETGLOBAL */ + ,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_SETUPVAL */ + ,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_SETTABLE */ + ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_NEWTABLE */ + ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_SELF */ + ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_ADD */ + ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_SUB */ + ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MUL */ + ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_DIV */ + ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MOD */ + ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_POW */ + ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_UNM */ + ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_NOT */ + ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_LEN */ + ,opmode(0, 1, OpArgR, OpArgR, iABC) /* OP_CONCAT */ + ,opmode(0, 0, OpArgR, OpArgN, iAsBx) /* OP_JMP */ + ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_EQ */ + ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LT */ + ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LE */ + ,opmode(1, 1, OpArgR, OpArgU, iABC) /* OP_TEST */ + ,opmode(1, 1, OpArgR, OpArgU, iABC) /* OP_TESTSET */ + ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_CALL */ + ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_TAILCALL */ + ,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_RETURN */ + ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORLOOP */ + ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORPREP */ + ,opmode(1, 0, OpArgN, OpArgU, iABC) /* OP_TFORLOOP */ + ,opmode(0, 0, OpArgU, OpArgU, iABC) /* OP_SETLIST */ + ,opmode(0, 0, OpArgN, OpArgN, iABC) /* OP_CLOSE */ + ,opmode(0, 1, OpArgU, OpArgN, iABx) /* OP_CLOSURE */ + ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_BAND */ + ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_BOR */ + ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_BXOR */ + ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_BSHL */ + ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_BSHR */ + ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_BNOT */ + ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_VARARG */ +}; diff --git a/src/blua/lopcodes.h b/src/blua/lopcodes.h new file mode 100644 index 000000000..8b08b04e0 --- /dev/null +++ b/src/blua/lopcodes.h @@ -0,0 +1,274 @@ +/* +** $Id: lopcodes.h,v 1.125.1.1 2007/12/27 13:02:25 roberto Exp $ +** Opcodes for Lua virtual machine +** See Copyright Notice in lua.h +*/ + +#ifndef lopcodes_h +#define lopcodes_h + +#include "llimits.h" + + +/*=========================================================================== + We assume that instructions are unsigned numbers. + All instructions have an opcode in the first 6 bits. + Instructions can have the following fields: + `A' : 8 bits + `B' : 9 bits + `C' : 9 bits + `Bx' : 18 bits (`B' and `C' together) + `sBx' : signed Bx + + A signed argument is represented in excess K; that is, the number + value is the unsigned value minus K. K is exactly the maximum value + for that argument (so that -max is represented by 0, and +max is + represented by 2*max), which is half the maximum for the corresponding + unsigned argument. +===========================================================================*/ + + +enum OpMode {iABC, iABx, iAsBx}; /* basic instruction format */ + + +/* +** size and position of opcode arguments. +*/ +#define SIZE_C 9 +#define SIZE_B 9 +#define SIZE_Bx (SIZE_C + SIZE_B) +#define SIZE_A 8 + +#define SIZE_OP 6 + +#define POS_OP 0 +#define POS_A (POS_OP + SIZE_OP) +#define POS_C (POS_A + SIZE_A) +#define POS_B (POS_C + SIZE_C) +#define POS_Bx POS_C + + +/* +** limits for opcode arguments. +** we use (signed) int to manipulate most arguments, +** so they must fit in LUAI_BITSINT-1 bits (-1 for sign) +*/ +#if SIZE_Bx < LUAI_BITSINT-1 +#define MAXARG_Bx ((1<>1) /* `sBx' is signed */ +#else +#define MAXARG_Bx MAX_INT +#define MAXARG_sBx MAX_INT +#endif + + +#define MAXARG_A ((1<>POS_OP) & MASK1(SIZE_OP,0))) +#define SET_OPCODE(i,o) ((i) = (((i)&MASK0(SIZE_OP,POS_OP)) | \ + ((cast(Instruction, o)<>POS_A) & MASK1(SIZE_A,0))) +#define SETARG_A(i,u) ((i) = (((i)&MASK0(SIZE_A,POS_A)) | \ + ((cast(Instruction, u)<>POS_B) & MASK1(SIZE_B,0))) +#define SETARG_B(i,b) ((i) = (((i)&MASK0(SIZE_B,POS_B)) | \ + ((cast(Instruction, b)<>POS_C) & MASK1(SIZE_C,0))) +#define SETARG_C(i,b) ((i) = (((i)&MASK0(SIZE_C,POS_C)) | \ + ((cast(Instruction, b)<>POS_Bx) & MASK1(SIZE_Bx,0))) +#define SETARG_Bx(i,b) ((i) = (((i)&MASK0(SIZE_Bx,POS_Bx)) | \ + ((cast(Instruction, b)< C) then pc++ */ +OP_TESTSET,/* A B C if (R(B) <=> C) then R(A) := R(B) else pc++ */ + +OP_CALL,/* A B C R(A), ... ,R(A+C-2) := R(A)(R(A+1), ... ,R(A+B-1)) */ +OP_TAILCALL,/* A B C return R(A)(R(A+1), ... ,R(A+B-1)) */ +OP_RETURN,/* A B return R(A), ... ,R(A+B-2) (see note) */ + +OP_FORLOOP,/* A sBx R(A)+=R(A+2); + if R(A) =) R(A)*/ +OP_CLOSURE,/* A Bx R(A) := closure(KPROTO[Bx], R(A), ... ,R(A+n)) */ + +OP_BAND, +OP_BOR, +OP_BXOR, +OP_BSHL, +OP_BSHR, +OP_BNOT, +OP_VARARG/* A B R(A), R(A+1), ..., R(A+B-1) = vararg */ +} OpCode; + + +#define NUM_OPCODES (cast(int, OP_VARARG) + 1) + + + +/*=========================================================================== + Notes: + (*) In OP_CALL, if (B == 0) then B = top. C is the number of returns - 1, + and can be 0: OP_CALL then sets `top' to last_result+1, so + next open instruction (OP_CALL, OP_RETURN, OP_SETLIST) may use `top'. + + (*) In OP_VARARG, if (B == 0) then use actual number of varargs and + set top (like in OP_CALL with C == 0). + + (*) In OP_RETURN, if (B == 0) then return up to `top' + + (*) In OP_SETLIST, if (B == 0) then B = `top'; + if (C == 0) then next `instruction' is real C + + (*) For comparisons, A specifies what condition the test should accept + (true or false). + + (*) All `skips' (pc++) assume that next instruction is a jump +===========================================================================*/ + + +/* +** masks for instruction properties. The format is: +** bits 0-1: op mode +** bits 2-3: C arg mode +** bits 4-5: B arg mode +** bit 6: instruction set register A +** bit 7: operator is a test +*/ + +enum OpArgMask { + OpArgN, /* argument is not used */ + OpArgU, /* argument is used */ + OpArgR, /* argument is a register or a jump offset */ + OpArgK /* argument is a constant or register/constant */ +}; + +LUAI_DATA const lu_byte luaP_opmodes[NUM_OPCODES]; + +#define getOpMode(m) (cast(enum OpMode, luaP_opmodes[m] & 3)) +#define getBMode(m) (cast(enum OpArgMask, (luaP_opmodes[m] >> 4) & 3)) +#define getCMode(m) (cast(enum OpArgMask, (luaP_opmodes[m] >> 2) & 3)) +#define testAMode(m) (luaP_opmodes[m] & (1 << 6)) +#define testTMode(m) (luaP_opmodes[m] & (1 << 7)) + + +LUAI_DATA const char *const luaP_opnames[NUM_OPCODES+1]; /* opcode names */ + + +/* number of list items to accumulate before a SETLIST instruction */ +#define LFIELDS_PER_FLUSH 50 + + +#endif diff --git a/src/blua/lparser.c b/src/blua/lparser.c new file mode 100644 index 000000000..3f392ae7b --- /dev/null +++ b/src/blua/lparser.c @@ -0,0 +1,1500 @@ +/* +** $Id: lparser.c,v 2.42.1.3 2007/12/28 15:32:23 roberto Exp $ +** Lua Parser +** See Copyright Notice in lua.h +*/ + + +#include + +#define lparser_c +#define LUA_CORE + +#include "lua.h" + +#include "lcode.h" +#include "ldebug.h" +#include "ldo.h" +#include "lfunc.h" +#include "llex.h" +#include "lmem.h" +#include "lobject.h" +#include "lopcodes.h" +#include "lparser.h" +#include "lstate.h" +#include "lstring.h" +#include "ltable.h" + + + +#define hasmultret(k) ((k) == VCALL || (k) == VVARARG) + +#define getlocvar(fs, i) ((fs)->f->locvars[(fs)->actvar[i]]) + +#define luaY_checklimit(fs,v,l,m) if ((v)>(l)) errorlimit(fs,l,m) + + +/* +** nodes for block list (list of active blocks) +*/ +typedef struct BlockCnt { + struct BlockCnt *previous; /* chain */ + int breaklist; /* list of jumps out of this loop */ + int continuelist; + lu_byte nactvar; /* # active locals outside the breakable structure */ + lu_byte upval; /* true if some variable in the block is an upvalue */ + lu_byte isbreakable; /* true if `block' is a loop */ +} BlockCnt; + + + +/* +** prototypes for recursive non-terminal functions +*/ +static void chunk (LexState *ls); +static void expr (LexState *ls, expdesc *v); + + +static void anchor_token (LexState *ls) { + if (ls->t.token == TK_NAME || ls->t.token == TK_STRING) { + TString *ts = ls->t.seminfo.ts; + luaX_newstring(ls, getstr(ts), ts->tsv.len); + } +} + + +static void error_expected (LexState *ls, int token) { + luaX_syntaxerror(ls, + luaO_pushfstring(ls->L, LUA_QS " expected", luaX_token2str(ls, token))); +} + + +static void errorlimit (FuncState *fs, int limit, const char *what) { + const char *msg = (fs->f->linedefined == 0) ? + luaO_pushfstring(fs->L, "main function has more than %d %s", limit, what) : + luaO_pushfstring(fs->L, "function at line %d has more than %d %s", + fs->f->linedefined, limit, what); + luaX_lexerror(fs->ls, msg, 0); +} + + +static int testnext (LexState *ls, int c) { + if (ls->t.token == c) { + luaX_next(ls); + return 1; + } + else return 0; +} + + +static void check (LexState *ls, int c) { + if (ls->t.token != c) + error_expected(ls, c); +} + +static void checknext (LexState *ls, int c) { + check(ls, c); + luaX_next(ls); +} + + +#define check_condition(ls,c,msg) { if (!(c)) luaX_syntaxerror(ls, msg); } + + + +static void check_match (LexState *ls, int what, int who, int where) { + if (!testnext(ls, what)) { + if (where == ls->linenumber) + error_expected(ls, what); + else { + luaX_syntaxerror(ls, luaO_pushfstring(ls->L, + LUA_QS " expected (to close " LUA_QS " at line %d)", + luaX_token2str(ls, what), luaX_token2str(ls, who), where)); + } + } +} + + +static TString *str_checkname (LexState *ls) { + TString *ts; + check(ls, TK_NAME); + ts = ls->t.seminfo.ts; + luaX_next(ls); + return ts; +} + + +static void init_exp (expdesc *e, expkind k, int i) { + e->f = e->t = NO_JUMP; + e->k = k; + e->u.s.info = i; +} + + +static void codestring (LexState *ls, expdesc *e, TString *s) { + init_exp(e, VK, luaK_stringK(ls->fs, s)); +} + + +static void checkname(LexState *ls, expdesc *e) { + codestring(ls, e, str_checkname(ls)); +} + + +static int registerlocalvar (LexState *ls, TString *varname) { + FuncState *fs = ls->fs; + Proto *f = fs->f; + int oldsize = f->sizelocvars; + luaM_growvector(ls->L, f->locvars, fs->nlocvars, f->sizelocvars, + LocVar, SHRT_MAX, "too many local variables"); + while (oldsize < f->sizelocvars) f->locvars[oldsize++].varname = NULL; + f->locvars[fs->nlocvars].varname = varname; + luaC_objbarrier(ls->L, f, varname); + return fs->nlocvars++; +} + + +#define new_localvarliteral(ls,v,n) \ + new_localvar(ls, luaX_newstring(ls, "" v, (sizeof(v)/sizeof(char))-1), n) + + +static void new_localvar (LexState *ls, TString *name, int n) { + FuncState *fs = ls->fs; + luaY_checklimit(fs, fs->nactvar+n+1, LUAI_MAXVARS, "local variables"); + fs->actvar[fs->nactvar+n] = cast(unsigned short, registerlocalvar(ls, name)); +} + + +static void adjustlocalvars (LexState *ls, int nvars) { + FuncState *fs = ls->fs; + fs->nactvar = cast_byte(fs->nactvar + nvars); + for (; nvars; nvars--) { + getlocvar(fs, fs->nactvar - nvars).startpc = fs->pc; + } +} + + +static void removevars (LexState *ls, int tolevel) { + FuncState *fs = ls->fs; + while (fs->nactvar > tolevel) + getlocvar(fs, --fs->nactvar).endpc = fs->pc; +} + + +static int indexupvalue (FuncState *fs, TString *name, expdesc *v) { + int i; + Proto *f = fs->f; + int oldsize = f->sizeupvalues; + for (i=0; inups; i++) { + if (fs->upvalues[i].k == v->k && fs->upvalues[i].info == v->u.s.info) { + lua_assert(f->upvalues[i] == name); + return i; + } + } + /* new one */ + luaY_checklimit(fs, f->nups + 1, LUAI_MAXUPVALUES, "upvalues"); + luaM_growvector(fs->L, f->upvalues, f->nups, f->sizeupvalues, + TString *, MAX_INT, ""); + while (oldsize < f->sizeupvalues) f->upvalues[oldsize++] = NULL; + f->upvalues[f->nups] = name; + luaC_objbarrier(fs->L, f, name); + lua_assert(v->k == VLOCAL || v->k == VUPVAL); + fs->upvalues[f->nups].k = cast_byte(v->k); + fs->upvalues[f->nups].info = cast_byte(v->u.s.info); + return f->nups++; +} + + +static int searchvar (FuncState *fs, TString *n) { + int i; + for (i=fs->nactvar-1; i >= 0; i--) { + if (n == getlocvar(fs, i).varname) + return i; + } + return -1; /* not found */ +} + + +static void markupval (FuncState *fs, int level) { + BlockCnt *bl = fs->bl; + while (bl && bl->nactvar > level) bl = bl->previous; + if (bl) bl->upval = 1; +} + + +static int singlevaraux (FuncState *fs, TString *n, expdesc *var, int base) { + if (fs == NULL) { /* no more levels? */ + init_exp(var, VGLOBAL, NO_REG); /* default is global variable */ + return VGLOBAL; + } + else { + int v = searchvar(fs, n); /* look up at current level */ + if (v >= 0) { + init_exp(var, VLOCAL, v); + if (!base) + markupval(fs, v); /* local will be used as an upval */ + return VLOCAL; + } + else { /* not found at current level; try upper one */ + if (singlevaraux(fs->prev, n, var, 0) == VGLOBAL) + return VGLOBAL; + var->u.s.info = indexupvalue(fs, n, var); /* else was LOCAL or UPVAL */ + var->k = VUPVAL; /* upvalue in this level */ + return VUPVAL; + } + } +} + + +static void singlevar (LexState *ls, expdesc *var) { + TString *varname = str_checkname(ls); + FuncState *fs = ls->fs; + if (singlevaraux(fs, varname, var, 1) == VGLOBAL) + var->u.s.info = luaK_stringK(fs, varname); /* info points to global name */ +} + + +static void adjust_assign (LexState *ls, int nvars, int nexps, expdesc *e) { + FuncState *fs = ls->fs; + int extra = nvars - nexps; + if (hasmultret(e->k)) { + extra++; /* includes call itself */ + if (extra < 0) extra = 0; + luaK_setreturns(fs, e, extra); /* last exp. provides the difference */ + if (extra > 1) luaK_reserveregs(fs, extra-1); + } + else { + if (e->k != VVOID) luaK_exp2nextreg(fs, e); /* close last expression */ + if (extra > 0) { + int reg = fs->freereg; + luaK_reserveregs(fs, extra); + luaK_nil(fs, reg, extra); + } + } +} + + +static void enterlevel (LexState *ls) { + if (++ls->L->nCcalls > LUAI_MAXCCALLS) + luaX_lexerror(ls, "chunk has too many syntax levels", 0); +} + + +#define leavelevel(ls) ((ls)->L->nCcalls--) + + +static void enterblock (FuncState *fs, BlockCnt *bl, lu_byte isbreakable) { + bl->breaklist = NO_JUMP; + bl->continuelist = NO_JUMP; + bl->isbreakable = isbreakable; + bl->nactvar = fs->nactvar; + bl->upval = 0; + bl->previous = fs->bl; + fs->bl = bl; + lua_assert(fs->freereg == fs->nactvar); +} + + +static void leaveblock (FuncState *fs) { + BlockCnt *bl = fs->bl; + fs->bl = bl->previous; + removevars(fs->ls, bl->nactvar); + if (bl->upval) + luaK_codeABC(fs, OP_CLOSE, bl->nactvar, 0, 0); + /* a block either controls scope or breaks (never both) */ + lua_assert(!bl->isbreakable || !bl->upval); + lua_assert(bl->nactvar == fs->nactvar); + fs->freereg = fs->nactvar; /* free registers */ + luaK_patchtohere(fs, bl->breaklist); +} + + +static void pushclosure (LexState *ls, FuncState *func, expdesc *v) { + FuncState *fs = ls->fs; + Proto *f = fs->f; + int oldsize = f->sizep; + int i; + luaM_growvector(ls->L, f->p, fs->np, f->sizep, Proto *, + MAXARG_Bx, "constant table overflow"); + while (oldsize < f->sizep) f->p[oldsize++] = NULL; + f->p[fs->np++] = func->f; + luaC_objbarrier(ls->L, f, func->f); + init_exp(v, VRELOCABLE, luaK_codeABx(fs, OP_CLOSURE, 0, fs->np-1)); + for (i=0; if->nups; i++) { + OpCode o = (func->upvalues[i].k == VLOCAL) ? OP_MOVE : OP_GETUPVAL; + luaK_codeABC(fs, o, 0, func->upvalues[i].info, 0); + } +} + + +static void open_func (LexState *ls, FuncState *fs) { + lua_State *L = ls->L; + Proto *f = luaF_newproto(L); + fs->f = f; + fs->prev = ls->fs; /* linked list of funcstates */ + fs->ls = ls; + fs->L = L; + ls->fs = fs; + fs->lhs = NULL; + fs->nlhs = 0; + fs->nrhs = 0; + fs->pc = 0; + fs->lasttarget = -1; + fs->jpc = NO_JUMP; + fs->freereg = 0; + fs->nk = 0; + fs->np = 0; + fs->nlocvars = 0; + fs->nactvar = 0; + fs->bl = NULL; + f->source = ls->source; + f->maxstacksize = 2; /* registers 0/1 are always valid */ + fs->h = luaH_new(L, 0, 0); + /* anchor table of constants and prototype (to avoid being collected) */ + sethvalue2s(L, L->top, fs->h); + incr_top(L); + setptvalue2s(L, L->top, f); + incr_top(L); +} + + +static void close_func (LexState *ls) { + lua_State *L = ls->L; + FuncState *fs = ls->fs; + Proto *f = fs->f; + removevars(ls, 0); + luaK_ret(fs, 0, 0); /* final return */ + luaM_reallocvector(L, f->code, f->sizecode, fs->pc, Instruction); + f->sizecode = fs->pc; + luaM_reallocvector(L, f->lineinfo, f->sizelineinfo, fs->pc, int); + f->sizelineinfo = fs->pc; + luaM_reallocvector(L, f->k, f->sizek, fs->nk, TValue); + f->sizek = fs->nk; + luaM_reallocvector(L, f->p, f->sizep, fs->np, Proto *); + f->sizep = fs->np; + luaM_reallocvector(L, f->locvars, f->sizelocvars, fs->nlocvars, LocVar); + f->sizelocvars = fs->nlocvars; + luaM_reallocvector(L, f->upvalues, f->sizeupvalues, f->nups, TString *); + f->sizeupvalues = f->nups; + lua_assert(luaG_checkcode(f)); + lua_assert(fs->bl == NULL); + ls->fs = fs->prev; + L->top -= 2; /* remove table and prototype from the stack */ + /* last token read was anchored in defunct function; must reanchor it */ + if (fs) anchor_token(ls); +} + + +Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) { + struct LexState lexstate; + struct FuncState funcstate; + lexstate.buff = buff; + luaX_setinput(L, &lexstate, z, luaS_new(L, name)); + open_func(&lexstate, &funcstate); + funcstate.f->is_vararg = VARARG_ISVARARG; /* main func. is always vararg */ + luaX_next(&lexstate); /* read first token */ + chunk(&lexstate); + check(&lexstate, TK_EOS); + close_func(&lexstate); + lua_assert(funcstate.prev == NULL); + lua_assert(funcstate.f->nups == 0); + lua_assert(lexstate.fs == NULL); + return funcstate.f; +} + + + +/*============================================================*/ +/* GRAMMAR RULES */ +/*============================================================*/ + + +static void field (LexState *ls, expdesc *v) { + /* field -> ['.' | ':'] NAME */ + FuncState *fs = ls->fs; + expdesc key; + luaK_exp2anyreg(fs, v); + luaX_next(ls); /* skip the dot or colon */ + checkname(ls, &key); + luaK_indexed(fs, v, &key); +} + + +static void yindex (LexState *ls, expdesc *v) { + /* index -> '[' expr ']' */ + luaX_next(ls); /* skip the '[' */ + expr(ls, v); + luaK_exp2val(ls->fs, v); + checknext(ls, ']'); +} + + +/* +** {====================================================================== +** Rules for Constructors +** ======================================================================= +*/ + + +struct ConsControl { + expdesc v; /* last list item read */ + expdesc *t; /* table descriptor */ + int nh; /* total number of `record' elements */ + int na; /* total number of array elements */ + int tostore; /* number of array elements pending to be stored */ +}; + + +static void recfield (LexState *ls, struct ConsControl *cc) { + /* recfield -> (NAME | `['exp1`]') = exp1 */ + FuncState *fs = ls->fs; + int reg = ls->fs->freereg; + expdesc key, val; + int rkkey; + if (ls->t.token == TK_NAME) { + luaY_checklimit(fs, cc->nh, MAX_INT, "items in a constructor"); + checkname(ls, &key); + } + else /* ls->t.token == '[' */ + yindex(ls, &key); + cc->nh++; + checknext(ls, '='); + rkkey = luaK_exp2RK(fs, &key); + expr(ls, &val); + luaK_codeABC(fs, OP_SETTABLE, cc->t->u.s.info, rkkey, luaK_exp2RK(fs, &val)); + fs->freereg = reg; /* free registers */ +} + + +static void closelistfield (FuncState *fs, struct ConsControl *cc) { + if (cc->v.k == VVOID) return; /* there is no list item */ + luaK_exp2nextreg(fs, &cc->v); + cc->v.k = VVOID; + if (cc->tostore == LFIELDS_PER_FLUSH) { + luaK_setlist(fs, cc->t->u.s.info, cc->na, cc->tostore); /* flush */ + cc->tostore = 0; /* no more items pending */ + } +} + + +static void lastlistfield (FuncState *fs, struct ConsControl *cc) { + if (cc->tostore == 0) return; + if (hasmultret(cc->v.k)) { + luaK_setmultret(fs, &cc->v); + luaK_setlist(fs, cc->t->u.s.info, cc->na, LUA_MULTRET); + cc->na--; /* do not count last expression (unknown number of elements) */ + } + else { + if (cc->v.k != VVOID) + luaK_exp2nextreg(fs, &cc->v); + luaK_setlist(fs, cc->t->u.s.info, cc->na, cc->tostore); + } +} + + +static void listfield (LexState *ls, struct ConsControl *cc) { + expr(ls, &cc->v); + luaY_checklimit(ls->fs, cc->na, MAX_INT, "items in a constructor"); + cc->na++; + cc->tostore++; +} + + +static void constructor (LexState *ls, expdesc *t) { + /* constructor -> ?? */ + FuncState *fs = ls->fs; + int line = ls->linenumber; + int pc = luaK_codeABC(fs, OP_NEWTABLE, 0, 0, 0); + struct ConsControl cc; + cc.na = cc.nh = cc.tostore = 0; + cc.t = t; + init_exp(t, VRELOCABLE, pc); + init_exp(&cc.v, VVOID, 0); /* no value (yet) */ + luaK_exp2nextreg(ls->fs, t); /* fix it at stack top (for gc) */ + checknext(ls, '{'); + do { + lua_assert(cc.v.k == VVOID || cc.tostore > 0); + if (ls->t.token == '}') break; + closelistfield(fs, &cc); + switch(ls->t.token) { + case TK_NAME: { /* may be listfields or recfields */ + luaX_lookahead(ls); + if (ls->lookahead.token != '=') /* expression? */ + listfield(ls, &cc); + else + recfield(ls, &cc); + break; + } + case '[': { /* constructor_item -> recfield */ + recfield(ls, &cc); + break; + } + default: { /* constructor_part -> listfield */ + listfield(ls, &cc); + break; + } + } + } while (testnext(ls, ',') || testnext(ls, ';')); + check_match(ls, '}', '{', line); + lastlistfield(fs, &cc); + SETARG_B(fs->f->code[pc], luaO_int2fb(cc.na)); /* set initial array size */ + SETARG_C(fs->f->code[pc], luaO_int2fb(cc.nh)); /* set initial table size */ +} + +/* }====================================================================== */ + + + +static void parlist (LexState *ls) { + /* parlist -> [ param { `,' param } ] */ + FuncState *fs = ls->fs; + Proto *f = fs->f; + int nparams = 0; + f->is_vararg = 0; + if (ls->t.token != ')') { /* is `parlist' not empty? */ + do { + switch (ls->t.token) { + case TK_NAME: { /* param -> NAME */ + new_localvar(ls, str_checkname(ls), nparams++); + break; + } + case TK_DOTS: { /* param -> `...' */ + luaX_next(ls); +#if defined(LUA_COMPAT_VARARG) + /* use `arg' as default name */ + new_localvarliteral(ls, "arg", nparams++); + f->is_vararg = VARARG_HASARG | VARARG_NEEDSARG; +#endif + f->is_vararg |= VARARG_ISVARARG; + break; + } + default: luaX_syntaxerror(ls, " or " LUA_QL("...") " expected"); + } + } while (!f->is_vararg && testnext(ls, ',')); + } + adjustlocalvars(ls, nparams); + f->numparams = cast_byte(fs->nactvar - (f->is_vararg & VARARG_HASARG)); + luaK_reserveregs(fs, fs->nactvar); /* reserve register for parameters */ +} + + +/*AK(12-Jan-06): DO_PATCH "do .. end" same as "function() ... end" +* +* The following functions are shortened versions of 'parlist()' and +* 'body()', please compare with them if there's issues. +*/ +static void parlist_empty (LexState *ls) { + FuncState *fs = ls->fs; + Proto *f = fs->f; + f->is_vararg = 0; + adjustlocalvars(ls, 0 /*nparams*/); + f->numparams = cast_byte(fs->nactvar); + luaK_reserveregs(fs, fs->nactvar); /* reserve register for parameters */ + } +static void body_noparms (LexState *ls, expdesc *e, int line) { + /* body -> chunk END */ + FuncState new_fs; + open_func(ls, &new_fs); + new_fs.f->linedefined = line; + parlist_empty(ls); + chunk(ls); + new_fs.f->lastlinedefined = ls->linenumber; + check_match(ls, TK_END, TK_DO /*TK_FUNCTION*/, line); + close_func(ls); + pushclosure(ls, &new_fs, e); +} +static void body (LexState *ls, expdesc *e, int needself, int line) { + /* body -> `(' parlist `)' chunk END */ + FuncState new_fs; + open_func(ls, &new_fs); + new_fs.f->linedefined = line; + checknext(ls, '('); + if (needself) { + new_localvarliteral(ls, "self", 0); + adjustlocalvars(ls, 1); + } + parlist(ls); + checknext(ls, ')'); + chunk(ls); + new_fs.f->lastlinedefined = ls->linenumber; + check_match(ls, TK_END, TK_FUNCTION, line); + close_func(ls); + pushclosure(ls, &new_fs, e); +} + + +static int explist1 (LexState *ls, expdesc *v) { + /* explist1 -> expr { `,' expr } */ + int n = 1; /* at least one expression */ + expr(ls, v); + while (testnext(ls, ',')) { + luaK_exp2nextreg(ls->fs, v); + expr(ls, v); + n++; + } + return n; +} + + +static void funcargs (LexState *ls, expdesc *f) { + FuncState *fs = ls->fs; + expdesc args; + int base, nparams; + int line = ls->linenumber; + switch (ls->t.token) { + case '(': { /* funcargs -> `(' [ explist1 ] `)' */ + if (line != ls->lastline) + luaX_syntaxerror(ls,"ambiguous syntax (function call x new statement)"); + luaX_next(ls); + if (ls->t.token == ')') /* arg list is empty? */ + args.k = VVOID; + else { + explist1(ls, &args); + luaK_setmultret(fs, &args); + } + check_match(ls, ')', '(', line); + break; + } + case '{': { /* funcargs -> constructor */ + constructor(ls, &args); + break; + } + case TK_STRING: { /* funcargs -> STRING */ + codestring(ls, &args, ls->t.seminfo.ts); + luaX_next(ls); /* must use `seminfo' before `next' */ + break; + } + default: { + luaX_syntaxerror(ls, "function arguments expected"); + return; + } + } + lua_assert(f->k == VNONRELOC); + base = f->u.s.info; /* base register for call */ + if (hasmultret(args.k)) + nparams = LUA_MULTRET; /* open call */ + else { + if (args.k != VVOID) + luaK_exp2nextreg(fs, &args); /* close last argument */ + nparams = fs->freereg - (base+1); + } + init_exp(f, VCALL, luaK_codeABC(fs, OP_CALL, base, nparams+1, 2)); + luaK_fixline(fs, line); + fs->freereg = base+1; /* call remove function and arguments and leaves + (unless changed) one result */ +} + + + + +/* +** {====================================================================== +** Expression parsing +** ======================================================================= +*/ + + +static void prefixexp (LexState *ls, expdesc *v) { + /* prefixexp -> NAME | '(' expr ')' */ + switch (ls->t.token) { + case '(': { + int line = ls->linenumber; + luaX_next(ls); + expr(ls, v); + check_match(ls, ')', '(', line); + luaK_dischargevars(ls->fs, v); + return; + } + case TK_NAME: { + singlevar(ls, v); + return; + } + case '$': { + lua_Number i = ls->t.seminfo.r; + if (i == 0) i = ls->fs->nrhs; + if (i <= 0 || i > ls->fs->nlhs) + luaX_syntaxerror(ls, "pseudo-variable out of range or not in assignment"); + else { + expdesc_list *lhs = ls->fs->lhs; + i = ls->fs->nlhs - i; + while (i--) lhs = lhs->prev; + *v = lhs->v; + /* If this is a VINDEXED, we need to stash the result in a temporary without + * freereg'ing the index locals. Really, it would be better to keep the value + * in case we repeat the $, but there's no way to do that without shifting all + * the temps up one slot to create room for the value. It would be semantically + * correct to also do that for globals, in case I ever get around to importing + * the shift mechanism from comprehensions. + */ + if (v->k == VINDEXED) { + int extra = ls->fs->freereg; + luaK_codeABC(ls->fs, OP_GETTABLE, extra, v->u.s.info, v->u.s.aux); + v->k = VNONRELOC; + v->u.s.info = extra; + luaK_reserveregs(ls->fs, 1); + } + } + luaX_next(ls); + return; + } + default: { + luaX_syntaxerror(ls, "unexpected symbol"); + return; + } + } +} + + +static void primaryexp (LexState *ls, expdesc *v) { + /* primaryexp -> + prefixexp { `.' NAME | `[' exp `]' | `:' NAME funcargs | funcargs } */ + FuncState *fs = ls->fs; + prefixexp(ls, v); + for (;;) { + switch (ls->t.token) { + case '.': { /* field */ + field(ls, v); + break; + } + case '[': { /* `[' exp1 `]' */ + expdesc key; + luaK_exp2anyreg(fs, v); + yindex(ls, &key); + luaK_indexed(fs, v, &key); + break; + } + case ':': { /* `:' NAME funcargs */ + expdesc key; + luaX_next(ls); + checkname(ls, &key); + luaK_self(fs, v, &key); + funcargs(ls, v); + break; + } + case '(': case TK_STRING: case '{': { /* funcargs */ + luaK_exp2nextreg(fs, v); + funcargs(ls, v); + break; + } + default: return; + } + } +} + + +static void simpleexp (LexState *ls, expdesc *v) { + /* simpleexp -> NUMBER | STRING | NIL | true | false | ... | + constructor | FUNCTION body | primaryexp */ + switch (ls->t.token) { + case TK_NUMBER: { + init_exp(v, VKNUM, 0); + v->u.nval = ls->t.seminfo.r; + break; + } + case TK_STRING: { + codestring(ls, v, ls->t.seminfo.ts); + break; + } + case TK_NIL: { + init_exp(v, VNIL, 0); + break; + } + case TK_TRUE: { + init_exp(v, VTRUE, 0); + break; + } + case TK_FALSE: { + init_exp(v, VFALSE, 0); + break; + } + case TK_DOTS: { /* vararg */ + FuncState *fs = ls->fs; + check_condition(ls, fs->f->is_vararg, + "cannot use " LUA_QL("...") " outside a vararg function"); + fs->f->is_vararg &= ~VARARG_NEEDSARG; /* don't need 'arg' */ + init_exp(v, VVARARG, luaK_codeABC(fs, OP_VARARG, 0, 1, 0)); + break; + } + case '{': { /* constructor */ + constructor(ls, v); + return; + } + case TK_DO: { /* "do .. end" same as "function() .. end" */ + luaX_next(ls); /* skip 'do' */ + body_noparms(ls, v, ls->linenumber); + return; + } + case TK_FUNCTION: { + luaX_next(ls); + body(ls, v, 0, ls->linenumber); + return; + } + default: { + primaryexp(ls, v); + return; + } + } + luaX_next(ls); +} + + +static UnOpr getunopr (int op) { + switch (op) { + case TK_NOT: return OPR_NOT; + case '-': return OPR_MINUS; + case '#': return OPR_LEN; + case '~': return OPR_BNOT; + default: return OPR_NOUNOPR; + } +} + + +static BinOpr getbinopr (int op) { + switch (op) { + case '+': return OPR_ADD; + case '-': return OPR_SUB; + case '*': return OPR_MUL; + case '/': return OPR_DIV; + case '%': return OPR_MOD; + case '^': return OPR_POW; + case TK_CONCAT: return OPR_CONCAT; + case TK_NE: return OPR_NE; + case TK_EQ: return OPR_EQ; + case '<': return OPR_LT; + case TK_LE: return OPR_LE; + case '>': return OPR_GT; + case TK_GE: return OPR_GE; + case TK_AND: return OPR_AND; + case TK_OR: return OPR_OR; + case '&': return OPR_BAND; + case '|': return OPR_BOR; + case TK_XOR: return OPR_BXOR; + case TK_SHL: return OPR_BSHL; + case TK_SHR: return OPR_BSHR; + default: return OPR_NOBINOPR; + } +} + + +static const struct { + lu_byte left; /* left priority for each binary operator */ + lu_byte right; /* right priority */ +} priority[] = { /* ORDER OPR */ + {6, 6}, {6, 6}, {7, 7}, {7, 7}, {7, 7}, /* `+' `-' `/' `%' */ + {10, 9}, {5, 4}, /* power and concat (right associative) */ + {3, 3}, {3, 3}, /* equality and inequality */ + {3, 3}, {3, 3}, {3, 3}, {3, 3}, /* order */ + {2, 2}, {1, 1} /* logical (and/or) */ + ,{6, 6}, {6, 6}, {6, 6}, /* bit-wise (band/bor/bxor) */ + {7, 7}, {7, 7} /* shl/shr */ +}; + +#define UNARY_PRIORITY 8 /* priority for unary operators */ + + +/* +** subexpr -> (simpleexp | unop subexpr) { binop subexpr } +** where `binop' is any binary operator with a priority higher than `limit' +*/ +static BinOpr subexpr (LexState *ls, expdesc *v, unsigned int limit) { + BinOpr op; + UnOpr uop; + enterlevel(ls); + uop = getunopr(ls->t.token); + if (uop != OPR_NOUNOPR) { + luaX_next(ls); + subexpr(ls, v, UNARY_PRIORITY); + luaK_prefix(ls->fs, uop, v); + } + else simpleexp(ls, v); + /* expand while operators have priorities higher than `limit' */ + op = getbinopr(ls->t.token); + while (op != OPR_NOBINOPR && priority[op].left > limit) { + expdesc v2; + BinOpr nextop; + luaX_next(ls); + luaK_infix(ls->fs, op, v); + /* read sub-expression with higher priority */ + nextop = subexpr(ls, &v2, priority[op].right); + luaK_posfix(ls->fs, op, v, &v2); + op = nextop; + } + leavelevel(ls); + return op; /* return first untreated operator */ +} + + +static void expr (LexState *ls, expdesc *v) { + subexpr(ls, v, 0); +} + +/* }==================================================================== */ + + + +/* +** {====================================================================== +** Rules for Statements +** ======================================================================= +*/ + + +static int block_follow (int token) { + switch (token) { + case TK_ELSE: case TK_ELSEIF: case TK_END: + case TK_UNTIL: case TK_EOS: + return 1; + default: return 0; + } +} + + +static void block (LexState *ls) { + /* block -> chunk */ + FuncState *fs = ls->fs; + BlockCnt bl; + enterblock(fs, &bl, 0); + chunk(ls); + lua_assert(bl.breaklist == NO_JUMP); + leaveblock(fs); +} + + +/* +** structure to chain all variables in the left-hand side of an +** assignment +*/ + + +/* +** check whether, in an assignment to a local variable, the local variable +** is needed in a previous assignment (to a table). If so, save original +** local value in a safe place and use this safe copy in the previous +** assignment. +*/ +static void check_conflict (LexState *ls, expdesc_list *lh, expdesc *v) { + FuncState *fs = ls->fs; + int extra = fs->freereg; /* eventual position to save local variable */ + int conflict = 0; + for (; lh; lh = lh->prev) { + if (lh->v.k == VINDEXED) { + if (lh->v.u.s.info == v->u.s.info) { /* conflict? */ + conflict = 1; + lh->v.u.s.info = extra; /* previous assignment will use safe copy */ + } + if (lh->v.u.s.aux == v->u.s.info) { /* conflict? */ + conflict = 1; + lh->v.u.s.aux = extra; /* previous assignment will use safe copy */ + } + } + } + if (conflict) { + luaK_codeABC(fs, OP_MOVE, fs->freereg, v->u.s.info, 0); /* make copy */ + luaK_reserveregs(fs, 1); + } +} +static void pushlhs (FuncState *fs, expdesc_list *v) { + fs->lhs = v; + fs->nlhs++; + fs->nrhs++; +} + +static void poplhs (FuncState *fs) { + lua_assert(fs->lhs != NULL); + fs->lhs = fs->lhs->prev; + fs->nlhs--; +} + + +static void assignment (LexState *ls) { + expdesc e; + expdesc_list *lh = ls->fs->lhs; + check_condition(ls, VLOCAL <= lh->v.k && lh->v.k <= VINDEXED, + "syntax error"); + if (testnext(ls, ',')) { /* assignment -> `,' primaryexp assignment */ + expdesc_list nv; + nv.prev = lh; + primaryexp(ls, &nv.v); + if (nv.v.k == VLOCAL) + check_conflict(ls, lh, &nv.v); + luaY_checklimit(ls->fs, ls->fs->nrhs, LUAI_MAXCCALLS - ls->L->nCcalls, + "variables in assignment"); + pushlhs(ls->fs, &nv); + assignment(ls); + poplhs(ls->fs); + } + else { /* assignment -> `=' explist1 */ +// int nexps; + checknext(ls, '='); + ls->fs->nrhs = 1; + expr(ls, &e); + while (testnext(ls, ',')) { + luaK_exp2nextreg(ls->fs, &e); + ls->fs->nrhs++; + expr(ls, &e); + } + if (ls->fs->nrhs != ls->fs->nlhs) { + adjust_assign(ls, ls->fs->nlhs, ls->fs->nrhs, &e); + if (ls->fs->nrhs > ls->fs->nlhs) + ls->fs->freereg -= ls->fs->nrhs - ls->fs->nlhs; /* remove extra values */ + } + else { + luaK_setoneret(ls->fs, &e); /* close last expression */ + luaK_storevar(ls->fs, &lh->v, &e); + return; /* avoid default */ + } + } + init_exp(&e, VNONRELOC, ls->fs->freereg-1); /* default assignment */ + luaK_storevar(ls->fs, &lh->v, &e); +} + +#if 0 + +static void assignment (LexState *ls, struct LHS_assign *lh, int nvars) { + expdesc e; + check_condition(ls, VLOCAL <= lh->v.k && lh->v.k <= VINDEXED, + "syntax error"); + if (testnext(ls, ',')) { /* assignment -> `,' primaryexp assignment */ + expdesc_list nv; + nv.prev = lh; + primaryexp(ls, &nv.v); + if (nv.v.k == VLOCAL) + check_conflict(ls, lh, &nv.v); + luaY_checklimit(ls->fs, nvars, LUAI_MAXCCALLS - ls->L->nCcalls, + "variables in assignment"); + pushlhs(ls->fs, &nv); + assignment(ls); + poplhs(ls->fs); + assignment(ls, &nv, nvars+1); + } + else { /* assignment -> `=' explist1 */ + int nexps; + checknext(ls, '='); + nexps = explist1(ls, &e); + if (nexps != nvars) { + adjust_assign(ls, nvars, nexps, &e); + if (nexps > nvars) + ls->fs->freereg -= nexps - nvars; /* remove extra values */ + } + else { + luaK_setoneret(ls->fs, &e); /* close last expression */ + luaK_storevar(ls->fs, &lh->v, &e); + return; /* avoid default */ + } + } + init_exp(&e, VNONRELOC, ls->fs->freereg-1); /* default assignment */ + luaK_storevar(ls->fs, &lh->v, &e); +} +#endif + +static int cond (LexState *ls) { + /* cond -> exp */ + expdesc v; + expr(ls, &v); /* read condition */ + if (v.k == VNIL) v.k = VFALSE; /* `falses' are all equal here */ + luaK_goiftrue(ls->fs, &v); + return v.f; +} + + +static void breakstat (LexState *ls, lua_Number n) { + FuncState *fs = ls->fs; + BlockCnt *bl = fs->bl; + int upval = 0; + while (bl && (!bl->isbreakable || --n)) { + upval |= bl->upval; + bl = bl->previous; + } + if (!bl) + luaX_syntaxerror(ls, "no loop to break"); + if (upval) + luaK_codeABC(fs, OP_CLOSE, bl->nactvar, 0, 0); + luaK_concat(fs, &bl->breaklist, luaK_jump(fs)); +} + + +static void continuestat (LexState *ls) { + /* stat -> CONTINUE */ + FuncState *fs = ls->fs; + BlockCnt *bl = fs->bl; + // TBD: Not sure if also continue should have the upvalue check? Original patch had not. + //int upval = 0; + luaX_next(ls); /* skip CONTINUE */ + while (bl && !bl->isbreakable) { + //upval |= bl->upval; // AK: ADDITION (would this fix forbody probs?) + bl = bl->previous; + } + if (!bl) + luaX_syntaxerror(ls, "no loop to continue"); + + //if (upval) //AK: experimental + // luaK_codeABC(fs, OP_CLOSE, bl->nactvar, 0, 0); + + luaK_concat(fs, &bl->continuelist, luaK_jump(fs)); + +//fprintf( stderr, "continue: bl->continuelist=%d %p %p\n", bl->continuelist, bl, bl->previous ); +} +static void whilestat (LexState *ls, int line) { + /* whilestat -> WHILE cond DO block END */ + FuncState *fs = ls->fs; + int whileinit; + int condexit; + BlockCnt bl; + luaX_next(ls); /* skip WHILE */ + whileinit = luaK_getlabel(fs); + condexit = cond(ls); + enterblock(fs, &bl, 1); + testnext(ls, TK_DO); + block(ls); +// luaK_patchlist(fs, luaK_jump(fs), bl.continuelist); -- bug rendering 'continue' useless in 'while', asko? + luaK_patchtohere(fs, bl.continuelist); // this one works for me --kt + luaK_patchlist(fs, luaK_jump(fs), whileinit); + check_match(ls, TK_END, TK_WHILE, line); + leaveblock(fs); + luaK_patchtohere(fs, condexit); /* false conditions finish the loop */ +} + + +static void repeatstat (LexState *ls, int line) { + /* repeatstat -> REPEAT block UNTIL cond */ + int condexit; + FuncState *fs = ls->fs; + int repeat_init = luaK_getlabel(fs); + BlockCnt bl1, bl2; + enterblock(fs, &bl1, 1); /* loop block */ + enterblock(fs, &bl2, 0); /* scope block */ + luaX_next(ls); /* skip REPEAT */ + chunk(ls); + luaK_patchtohere(fs, bl1.continuelist); + check_match(ls, TK_UNTIL, TK_REPEAT, line); + condexit = cond(ls); /* read condition (inside scope block) */ + if (!bl2.upval) { /* no upvalues? */ + leaveblock(fs); /* finish scope */ + luaK_patchlist(ls->fs, condexit, repeat_init); /* close the loop */ + } + else { /* complete semantics when there are upvalues */ + breakstat(ls, 1); /* if condition then break */ + luaK_patchtohere(ls->fs, condexit); /* else... */ + leaveblock(fs); /* finish scope... */ + luaK_patchlist(ls->fs, luaK_jump(fs), repeat_init); /* and repeat */ + } + leaveblock(fs); /* finish loop */ +} + + +static int exp1 (LexState *ls) { + expdesc e; + int k; + expr(ls, &e); + k = e.k; + luaK_exp2nextreg(ls->fs, &e); + return k; +} + + +static void forbody (LexState *ls, int base, int line, int nvars, int isnum) { + /* forbody -> DO block */ + BlockCnt bl; + FuncState *fs = ls->fs; + int prep, endfor; + adjustlocalvars(ls, 3); /* control variables */ + testnext(ls, TK_DO); + prep = isnum ? luaK_codeAsBx(fs, OP_FORPREP, base, NO_JUMP) : luaK_jump(fs); + enterblock(fs, &bl, 0); /* scope for declared variables */ + adjustlocalvars(ls, nvars); + luaK_reserveregs(fs, nvars); + block(ls); + luaK_patchtohere(fs, bl.previous->continuelist); + leaveblock(fs); /* end of scope for declared variables */ + luaK_patchtohere(fs, prep); + endfor = (isnum) ? luaK_codeAsBx(fs, OP_FORLOOP, base, NO_JUMP) : + luaK_codeABC(fs, OP_TFORLOOP, base, 0, nvars); + luaK_fixline(fs, line); /* pretend that `OP_FOR' starts the loop */ + luaK_patchlist(fs, (isnum ? endfor : luaK_jump(fs)), prep + 1); +} + + +static void fornum (LexState *ls, TString *varname, int line) { + /* fornum -> NAME = exp1,exp1[,exp1] forbody */ + FuncState *fs = ls->fs; + int base = fs->freereg; + new_localvarliteral(ls, "(for index)", 0); + new_localvarliteral(ls, "(for limit)", 1); + new_localvarliteral(ls, "(for step)", 2); + new_localvar(ls, varname, 3); + checknext(ls, '='); + exp1(ls); /* initial value */ + checknext(ls, ','); + exp1(ls); /* limit */ + if (testnext(ls, ',')) + exp1(ls); /* optional step */ + else { /* default step = 1 */ + luaK_codeABx(fs, OP_LOADK, fs->freereg, luaK_numberK(fs, 1)); + luaK_reserveregs(fs, 1); + } + forbody(ls, base, line, 1, 1); +} + + +static void forlist (LexState *ls, TString *indexname) { + /* forlist -> NAME {,NAME} IN explist1 forbody */ + FuncState *fs = ls->fs; + expdesc e; + int nvars = 0; + int line; + int base = fs->freereg; + /* create control variables */ + new_localvarliteral(ls, "(for generator)", nvars++); + new_localvarliteral(ls, "(for state)", nvars++); + new_localvarliteral(ls, "(for control)", nvars++); + /* create declared variables */ + new_localvar(ls, indexname, nvars++); + while (testnext(ls, ',')) + new_localvar(ls, str_checkname(ls), nvars++); + checknext(ls, TK_IN); + line = ls->linenumber; + adjust_assign(ls, 3, explist1(ls, &e), &e); + luaK_checkstack(fs, 3); /* extra space to call generator */ + forbody(ls, base, line, nvars - 3, 0); +} + + +static void forstat (LexState *ls, int line) { + /* forstat -> FOR (fornum | forlist) END */ + FuncState *fs = ls->fs; + TString *varname; + BlockCnt bl; + enterblock(fs, &bl, 1); /* scope for loop and control variables */ + luaX_next(ls); /* skip `for' */ + varname = str_checkname(ls); /* first variable name */ + switch (ls->t.token) { + case '=': fornum(ls, varname, line); break; + case ',': case TK_IN: forlist(ls, varname); break; + default: luaX_syntaxerror(ls, LUA_QL("=") " or " LUA_QL("in") " expected"); + } + check_match(ls, TK_END, TK_FOR, line); + leaveblock(fs); /* loop scope (`break' jumps to this point) */ +} + + +static int test_then_block (LexState *ls) { + /* test_then_block -> [IF | ELSEIF] cond THEN block */ + int condexit; + luaX_next(ls); /* skip IF or ELSEIF */ + condexit = cond(ls); + testnext(ls, TK_THEN); + block(ls); /* `then' part */ + return condexit; +} + + +static void ifstat (LexState *ls, int line) { + /* ifstat -> IF cond THEN block {ELSEIF cond THEN block} [ELSE block] END */ + FuncState *fs = ls->fs; + int flist; + int escapelist = NO_JUMP; + flist = test_then_block(ls); /* IF cond THEN block */ + while (ls->t.token == TK_ELSEIF) { + luaK_concat(fs, &escapelist, luaK_jump(fs)); + luaK_patchtohere(fs, flist); + flist = test_then_block(ls); /* ELSEIF cond THEN block */ + } + if (ls->t.token == TK_ELSE) { + luaK_concat(fs, &escapelist, luaK_jump(fs)); + luaK_patchtohere(fs, flist); + luaX_next(ls); /* skip ELSE (after patch, for correct line info) */ + block(ls); /* `else' part */ + } + else + luaK_concat(fs, &escapelist, flist); + luaK_patchtohere(fs, escapelist); + check_match(ls, TK_END, TK_IF, line); +} + + +static void localfunc (LexState *ls) { + expdesc v, b; + FuncState *fs = ls->fs; + new_localvar(ls, str_checkname(ls), 0); + init_exp(&v, VLOCAL, fs->freereg); + luaK_reserveregs(fs, 1); + adjustlocalvars(ls, 1); + body(ls, &b, 0, ls->linenumber); + luaK_storevar(fs, &v, &b); + /* debug information will only see the variable after this point! */ + getlocvar(fs, fs->nactvar - 1).startpc = fs->pc; +} + + +static void localstat (LexState *ls) { + /* stat -> LOCAL NAME {`,' NAME} [`=' explist1] */ + int nvars = 0; + int nexps; + expdesc e; + do { + new_localvar(ls, str_checkname(ls), nvars++); + } while (testnext(ls, ',')); + if (testnext(ls, '=')) + nexps = explist1(ls, &e); + else { + e.k = VVOID; + nexps = 0; + } + adjust_assign(ls, nvars, nexps, &e); + adjustlocalvars(ls, nvars); +} + + +static int funcname (LexState *ls, expdesc *v) { + /* funcname -> NAME {field} [`:' NAME] */ + int needself = 0; + singlevar(ls, v); + while (ls->t.token == '.') + field(ls, v); + if (ls->t.token == ':') { + needself = 1; + field(ls, v); + } + return needself; +} + + +static void funcstat (LexState *ls, int line) { + /* funcstat -> FUNCTION funcname body */ + int needself; + expdesc v, b; + luaX_next(ls); /* skip FUNCTION */ + needself = funcname(ls, &v); + body(ls, &b, needself, line); + luaK_storevar(ls->fs, &v, &b); + luaK_fixline(ls->fs, line); /* definition `happens' in the first line */ +} + + +static void exprstat (LexState *ls) { + /* stat -> func | assignment */ + FuncState *fs = ls->fs; + expdesc_list v; + primaryexp(ls, &v.v); + if (v.v.k == VCALL) /* stat -> func */ + SETARG_C(getcode(fs, &v.v), 1); /* call statement uses no results */ + else { /* stat -> assignment */ + v.prev = NULL; + lua_assert(ls->fs->lhs == NULL && ls->fs->nlhs == 0 && ls->fs->nrhs == 0); + pushlhs(ls->fs, &v); + assignment(ls); + poplhs(ls->fs); + ls->fs->nrhs = 0; + lua_assert(ls->fs->lhs == NULL && ls->fs->nlhs == 0); + } +} + + +static void retstat (LexState *ls) { + /* stat -> RETURN explist */ + FuncState *fs = ls->fs; + expdesc e; + int first, nret; /* registers with returned values */ + luaX_next(ls); /* skip RETURN */ + if (block_follow(ls->t.token) || ls->t.token == ';') + first = nret = 0; /* return no values */ + else { + nret = explist1(ls, &e); /* optional return values */ + if (hasmultret(e.k)) { + luaK_setmultret(fs, &e); + if (e.k == VCALL && nret == 1) { /* tail call? */ + SET_OPCODE(getcode(fs,&e), OP_TAILCALL); + lua_assert(GETARG_A(getcode(fs,&e)) == fs->nactvar); + } + first = fs->nactvar; + nret = LUA_MULTRET; /* return all values */ + } + else { + if (nret == 1) /* only one single value? */ + first = luaK_exp2anyreg(fs, &e); + else { + luaK_exp2nextreg(fs, &e); /* values must go to the `stack' */ + first = fs->nactvar; /* return all `active' values */ + lua_assert(nret == fs->freereg - first); + } + } + } + luaK_ret(fs, first, nret); +} + + +static int statement (LexState *ls) { + int line = ls->linenumber; /* may be needed for error messages */ + switch (ls->t.token) { + case TK_IF: { /* stat -> ifstat */ + ifstat(ls, line); + return 0; + } + case TK_WHILE: { /* stat -> whilestat */ + whilestat(ls, line); + return 0; + } + case TK_DO: { /* stat -> DO block END */ + luaX_next(ls); /* skip DO */ + block(ls); + check_match(ls, TK_END, TK_DO, line); + return 0; + } + case TK_FOR: { /* stat -> forstat */ + forstat(ls, line); + return 0; + } + case TK_REPEAT: { /* stat -> repeatstat */ + repeatstat(ls, line); + return 0; + } + case TK_FUNCTION: { + funcstat(ls, line); /* stat -> funcstat */ + return 0; + } + case TK_LOCAL: { /* stat -> localstat */ + luaX_next(ls); /* skip LOCAL */ + if (testnext(ls, TK_FUNCTION)) /* local function? */ + localfunc(ls); + else + localstat(ls); + return 0; + } + case TK_RETURN: { /* stat -> retstat */ + retstat(ls); + return 1; /* must be last statement */ + } + case TK_BREAK: { /* stat -> breakstat */ + luaX_next(ls); /* skip BREAK */ + if (testnext(ls, TK_NUMBER)) { /* multi scope 'break n' */ + breakstat(ls, ls->t.seminfo.r); + } else breakstat(ls, 1); + return 1; /* must be last statement */ + } + case TK_CONTINUE: { /* stat -> continuestat */ + continuestat(ls); + return 1; /* must be last statement */ + } + default: { + exprstat(ls); + return 0; /* to avoid warnings */ + } + } +} + + +static void chunk (LexState *ls) { + /* chunk -> { stat [`;'] } */ + int islast = 0; + enterlevel(ls); + while (!islast && !block_follow(ls->t.token)) { + islast = statement(ls); + testnext(ls, ';'); + lua_assert(ls->fs->f->maxstacksize >= ls->fs->freereg && + ls->fs->freereg >= ls->fs->nactvar); + ls->fs->freereg = ls->fs->nactvar; /* free registers */ + } + leavelevel(ls); +} + +/* }====================================================================== */ diff --git a/src/blua/lparser.h b/src/blua/lparser.h new file mode 100644 index 000000000..4f9cffb1d --- /dev/null +++ b/src/blua/lparser.h @@ -0,0 +1,89 @@ +/* +** $Id: lparser.h,v 1.57.1.1 2007/12/27 13:02:25 roberto Exp $ +** Lua Parser +** See Copyright Notice in lua.h +*/ + +#ifndef lparser_h +#define lparser_h + +#include "llimits.h" +#include "lobject.h" +#include "lzio.h" + + +/* +** Expression descriptor +*/ + +typedef enum { + VVOID, /* no value */ + VNIL, + VTRUE, + VFALSE, + VK, /* info = index of constant in `k' */ + VKNUM, /* nval = numerical value */ + VLOCAL, /* info = local register */ + VUPVAL, /* info = index of upvalue in `upvalues' */ + VGLOBAL, /* info = index of table; aux = index of global name in `k' */ + VINDEXED, /* info = table register; aux = index register (or `k') */ + VJMP, /* info = instruction pc */ + VRELOCABLE, /* info = instruction pc */ + VNONRELOC, /* info = result register */ + VCALL, /* info = instruction pc */ + VVARARG /* info = instruction pc */ +} expkind; + +typedef struct expdesc { + expkind k; + union { + struct { int info, aux; } s; + lua_Number nval; + } u; + int t; /* patch list of `exit when true' */ + int f; /* patch list of `exit when false' */ +} expdesc; + +typedef struct expdesc_list { + struct expdesc_list *prev; + expdesc v; /* variable (global, local, upvalue, or indexed) */ +} expdesc_list; + +typedef struct upvaldesc { + lu_byte k; + lu_byte info; +} upvaldesc; + + +struct BlockCnt; /* defined in lparser.c */ + + +/* state needed to generate code for a given function */ +typedef struct FuncState { + Proto *f; /* current function header */ + Table *h; /* table to find (and reuse) elements in `k' */ + struct FuncState *prev; /* enclosing function */ + struct LexState *ls; /* lexical state */ + struct lua_State *L; /* copy of the Lua state */ + struct BlockCnt *bl; /* chain of current blocks */ + expdesc_list *lhs; /* chain of left hand sides during assign */ + short nlhs; /* number of lhs in chain */ + short nrhs; /* number of rhs in assignment */ + int pc; /* next position to code (equivalent to `ncode') */ + int lasttarget; /* `pc' of last `jump target' */ + int jpc; /* list of pending jumps to `pc' */ + int freereg; /* first free register */ + int nk; /* number of elements in `k' */ + int np; /* number of elements in `p' */ + short nlocvars; /* number of elements in `locvars' */ + lu_byte nactvar; /* number of active local variables */ + upvaldesc upvalues[LUAI_MAXUPVALUES]; /* upvalues */ + unsigned short actvar[LUAI_MAXVARS]; /* declared-variable stack */ +} FuncState; + + +LUAI_FUNC Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, + const char *name); + + +#endif diff --git a/src/blua/lstate.c b/src/blua/lstate.c new file mode 100644 index 000000000..f6265768b --- /dev/null +++ b/src/blua/lstate.c @@ -0,0 +1,213 @@ +/* +** $Id: lstate.c,v 2.36.1.2 2008/01/03 15:20:39 roberto Exp $ +** Global State +** See Copyright Notice in lua.h +*/ + + +#include + +#define lstate_c +#define LUA_CORE + +#include "lua.h" + +#include "ldebug.h" +#include "ldo.h" +#include "lfunc.h" +#include "lgc.h" +#include "llex.h" +#include "lmem.h" +#include "lstate.h" +#include "lstring.h" +#include "ltable.h" +#include "ltm.h" + + +#define state_size(x) (sizeof(x) + LUAI_EXTRASPACE) +#define fromstate(l) (cast(lu_byte *, (l)) - LUAI_EXTRASPACE) +#define tostate(l) (cast(lua_State *, (void *)(cast(lu_byte *, l) + LUAI_EXTRASPACE))) + + +/* +** Main thread combines a thread state and the global state +*/ +typedef struct LG { + lua_State l; + global_State g; +} LG; + + + +static void stack_init (lua_State *L1, lua_State *L) { + /* initialize CallInfo array */ + L1->base_ci = luaM_newvector(L, BASIC_CI_SIZE, CallInfo); + L1->ci = L1->base_ci; + L1->size_ci = BASIC_CI_SIZE; + L1->end_ci = L1->base_ci + L1->size_ci - 1; + /* initialize stack array */ + L1->stack = luaM_newvector(L, BASIC_STACK_SIZE + EXTRA_STACK, TValue); + L1->stacksize = BASIC_STACK_SIZE + EXTRA_STACK; + L1->top = L1->stack; + L1->stack_last = L1->stack+(L1->stacksize - EXTRA_STACK)-1; + /* initialize first ci */ + L1->ci->func = L1->top; + setnilvalue(L1->top++); /* `function' entry for this `ci' */ + L1->base = L1->ci->base = L1->top; + L1->ci->top = L1->top + LUA_MINSTACK; +} + + +static void freestack (lua_State *L, lua_State *L1) { + luaM_freearray(L, L1->base_ci, L1->size_ci, CallInfo); + luaM_freearray(L, L1->stack, L1->stacksize, TValue); +} + + +/* +** open parts that may cause memory-allocation errors +*/ +static void f_luaopen (lua_State *L, void *ud) { + global_State *g = G(L); + UNUSED(ud); + stack_init(L, L); /* init stack */ + sethvalue(L, gt(L), luaH_new(L, 0, 2)); /* table of globals */ + sethvalue(L, registry(L), luaH_new(L, 0, 2)); /* registry */ + luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */ + luaT_init(L); + luaX_init(L); + luaS_fix(luaS_newliteral(L, MEMERRMSG)); + g->GCthreshold = 4*g->totalbytes; +} + + +static void preinit_state (lua_State *L, global_State *g) { + G(L) = g; + L->stack = NULL; + L->stacksize = 0; + L->errorJmp = NULL; + L->hook = NULL; + L->hookmask = 0; + L->basehookcount = 0; + L->allowhook = 1; + resethookcount(L); + L->openupval = NULL; + L->size_ci = 0; + L->nCcalls = L->baseCcalls = 0; + L->status = 0; + L->base_ci = L->ci = NULL; + L->savedpc = NULL; + L->errfunc = 0; + setnilvalue(gt(L)); +} + + +static void close_state (lua_State *L) { + global_State *g = G(L); + luaF_close(L, L->stack); /* close all upvalues for this thread */ + luaC_freeall(L); /* collect all objects */ + lua_assert(g->rootgc == obj2gco(L)); + lua_assert(g->strt.nuse == 0); + luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size, TString *); + luaZ_freebuffer(L, &g->buff); + freestack(L, L); + lua_assert(g->totalbytes == sizeof(LG)); + (*g->frealloc)(g->ud, fromstate(L), state_size(LG), 0); +} + + +lua_State *luaE_newthread (lua_State *L) { + lua_State *L1 = tostate(luaM_malloc(L, state_size(lua_State))); + luaC_link(L, obj2gco(L1), LUA_TTHREAD); + preinit_state(L1, G(L)); + stack_init(L1, L); /* init stack */ + setobj2n(L, gt(L1), gt(L)); /* share table of globals */ + L1->hookmask = L->hookmask; + L1->basehookcount = L->basehookcount; + L1->hook = L->hook; + resethookcount(L1); + lua_assert(iswhite(obj2gco(L1))); + return L1; +} + + +void luaE_freethread (lua_State *L, lua_State *L1) { + luaF_close(L1, L1->stack); /* close all upvalues for this thread */ + lua_assert(L1->openupval == NULL); + luai_userstatefree(L1); + freestack(L, L1); + luaM_freemem(L, fromstate(L1), state_size(lua_State)); +} + + +LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { + int i; + lua_State *L; + global_State *g; + void *l = (*f)(ud, NULL, 0, state_size(LG)); + if (l == NULL) return NULL; + L = tostate(l); + g = &((LG *)L)->g; + L->next = NULL; + L->tt = LUA_TTHREAD; + g->currentwhite = bit2mask(WHITE0BIT, FIXEDBIT); + L->marked = luaC_white(g); + set2bits(L->marked, FIXEDBIT, SFIXEDBIT); + preinit_state(L, g); + g->frealloc = f; + g->ud = ud; + g->mainthread = L; + g->uvhead.u.l.prev = &g->uvhead; + g->uvhead.u.l.next = &g->uvhead; + g->GCthreshold = 0; /* mark it as unfinished state */ + g->strt.size = 0; + g->strt.nuse = 0; + g->strt.hash = NULL; + setnilvalue(registry(L)); + luaZ_initbuffer(L, &g->buff); + g->panic = NULL; + g->gcstate = GCSpause; + g->rootgc = obj2gco(L); + g->sweepstrgc = 0; + g->sweepgc = &g->rootgc; + g->gray = NULL; + g->grayagain = NULL; + g->weak = NULL; + g->tmudata = NULL; + g->totalbytes = sizeof(LG); + g->gcpause = LUAI_GCPAUSE; + g->gcstepmul = LUAI_GCMUL; + g->gcdept = 0; + for (i=0; imt[i] = NULL; + if (luaD_rawrunprotected(L, f_luaopen, NULL) != 0) { + /* memory allocation error: free partial state */ + close_state(L); + L = NULL; + } + else + luai_userstateopen(L); + return L; +} + + +static void callallgcTM (lua_State *L, void *ud) { + UNUSED(ud); + luaC_callGCTM(L); /* call GC metamethods for all udata */ +} + + +LUA_API void lua_close (lua_State *L) { + L = G(L)->mainthread; /* only the main thread can be closed */ + lua_lock(L); + luaF_close(L, L->stack); /* close all upvalues for this thread */ + luaC_separateudata(L, 1); /* separate udata that have GC metamethods */ + L->errfunc = 0; /* no error function during GC metamethods */ + do { /* repeat until no more errors */ + L->ci = L->base_ci; + L->base = L->top = L->ci->base; + L->nCcalls = L->baseCcalls = 0; + } while (luaD_rawrunprotected(L, callallgcTM, NULL) != 0); + lua_assert(G(L)->tmudata == NULL); + luai_userstateclose(L); + close_state(L); +} diff --git a/src/blua/lstate.h b/src/blua/lstate.h new file mode 100644 index 000000000..2d97fe30a --- /dev/null +++ b/src/blua/lstate.h @@ -0,0 +1,168 @@ +/* +** $Id: lstate.h,v 2.24.1.2 2008/01/03 15:20:39 roberto Exp $ +** Global State +** See Copyright Notice in lua.h +*/ + +#ifndef lstate_h +#define lstate_h + +#include "lua.h" + +#include "lobject.h" +#include "ltm.h" +#include "lzio.h" + + + +struct lua_longjmp; /* defined in ldo.c */ + + +/* table of globals */ +#define gt(L) (&L->l_gt) + +/* registry */ +#define registry(L) (&G(L)->l_registry) + + +/* extra stack space to handle TM calls and some other extras */ +#define EXTRA_STACK 5 + + +#define BASIC_CI_SIZE 8 + +#define BASIC_STACK_SIZE (2*LUA_MINSTACK) + + + +typedef struct stringtable { + GCObject **hash; + lu_int32 nuse; /* number of elements */ + int size; +} stringtable; + + +/* +** informations about a call +*/ +typedef struct CallInfo { + StkId base; /* base for this function */ + StkId func; /* function index in the stack */ + StkId top; /* top for this function */ + const Instruction *savedpc; + int nresults; /* expected number of results from this function */ + int tailcalls; /* number of tail calls lost under this entry */ +} CallInfo; + + + +#define curr_func(L) (clvalue(L->ci->func)) +#define ci_func(ci) (clvalue((ci)->func)) +#define f_isLua(ci) (!ci_func(ci)->c.isC) +#define isLua(ci) (ttisfunction((ci)->func) && f_isLua(ci)) + + +/* +** `global state', shared by all threads of this state +*/ +typedef struct global_State { + stringtable strt; /* hash table for strings */ + lua_Alloc frealloc; /* function to reallocate memory */ + void *ud; /* auxiliary data to `frealloc' */ + lu_byte currentwhite; + lu_byte gcstate; /* state of garbage collector */ + int sweepstrgc; /* position of sweep in `strt' */ + GCObject *rootgc; /* list of all collectable objects */ + GCObject **sweepgc; /* position of sweep in `rootgc' */ + GCObject *gray; /* list of gray objects */ + GCObject *grayagain; /* list of objects to be traversed atomically */ + GCObject *weak; /* list of weak tables (to be cleared) */ + GCObject *tmudata; /* last element of list of userdata to be GC */ + Mbuffer buff; /* temporary buffer for string concatentation */ + lu_mem GCthreshold; + lu_mem totalbytes; /* number of bytes currently allocated */ + lu_mem estimate; /* an estimate of number of bytes actually in use */ + lu_mem gcdept; /* how much GC is `behind schedule' */ + int gcpause; /* size of pause between successive GCs */ + int gcstepmul; /* GC `granularity' */ + lua_CFunction panic; /* to be called in unprotected errors */ + TValue l_registry; + struct lua_State *mainthread; + UpVal uvhead; /* head of double-linked list of all open upvalues */ + struct Table *mt[NUM_TAGS]; /* metatables for basic types */ + TString *tmname[TM_N]; /* array with tag-method names */ +} global_State; + + +/* +** `per thread' state +*/ +struct lua_State { + CommonHeader; + lu_byte status; + StkId top; /* first free slot in the stack */ + StkId base; /* base of current function */ + global_State *l_G; + CallInfo *ci; /* call info for current function */ + const Instruction *savedpc; /* `savedpc' of current function */ + StkId stack_last; /* last free slot in the stack */ + StkId stack; /* stack base */ + CallInfo *end_ci; /* points after end of ci array*/ + CallInfo *base_ci; /* array of CallInfo's */ + int stacksize; + int size_ci; /* size of array `base_ci' */ + unsigned short nCcalls; /* number of nested C calls */ + unsigned short baseCcalls; /* nested C calls when resuming coroutine */ + lu_byte hookmask; + lu_byte allowhook; + int basehookcount; + int hookcount; + lua_Hook hook; + TValue l_gt; /* table of globals */ + TValue env; /* temporary place for environments */ + GCObject *openupval; /* list of open upvalues in this stack */ + GCObject *gclist; + struct lua_longjmp *errorJmp; /* current error recover point */ + ptrdiff_t errfunc; /* current error handling function (stack index) */ +}; + + +#define G(L) (L->l_G) + + +/* +** Union of all collectable objects +*/ +union GCObject { + GCheader gch; + union TString ts; + union Udata u; + union Closure cl; + struct Table h; + struct Proto p; + struct UpVal uv; + struct lua_State th; /* thread */ +}; + + +/* macros to convert a GCObject into a specific value */ +#define rawgco2ts(o) check_exp((o)->gch.tt == LUA_TSTRING, &((o)->ts)) +#define gco2ts(o) (&rawgco2ts(o)->tsv) +#define rawgco2u(o) check_exp((o)->gch.tt == LUA_TUSERDATA, &((o)->u)) +#define gco2u(o) (&rawgco2u(o)->uv) +#define gco2cl(o) check_exp((o)->gch.tt == LUA_TFUNCTION, &((o)->cl)) +#define gco2h(o) check_exp((o)->gch.tt == LUA_TTABLE, &((o)->h)) +#define gco2p(o) check_exp((o)->gch.tt == LUA_TPROTO, &((o)->p)) +#define gco2uv(o) check_exp((o)->gch.tt == LUA_TUPVAL, &((o)->uv)) +#define ngcotouv(o) \ + check_exp((o) == NULL || (o)->gch.tt == LUA_TUPVAL, &((o)->uv)) +#define gco2th(o) check_exp((o)->gch.tt == LUA_TTHREAD, &((o)->th)) + +/* macro to convert any Lua object into a GCObject */ +#define obj2gco(v) (cast(GCObject *, (void *)(v))) + + +LUAI_FUNC lua_State *luaE_newthread (lua_State *L); +LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1); + +#endif diff --git a/src/blua/lstring.c b/src/blua/lstring.c new file mode 100644 index 000000000..afc851d0c --- /dev/null +++ b/src/blua/lstring.c @@ -0,0 +1,110 @@ +/* +** $Id: lstring.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $ +** String table (keeps all strings handled by Lua) +** See Copyright Notice in lua.h +*/ + + +#include + +#define lstring_c +#define LUA_CORE + +#include "lua.h" + +#include "lmem.h" +#include "lobject.h" +#include "lstate.h" +#include "lstring.h" + + + +void luaS_resize (lua_State *L, int newsize) { + GCObject **newhash; + stringtable *tb; + int i; + if (G(L)->gcstate == GCSsweepstring) + return; /* cannot resize during GC traverse */ + newhash = luaM_newvector(L, newsize, GCObject *); + tb = &G(L)->strt; + for (i=0; isize; i++) { + GCObject *p = tb->hash[i]; + while (p) { /* for each node in the list */ + GCObject *next = p->gch.next; /* save next */ + unsigned int h = gco2ts(p)->hash; + int h1 = lmod(h, newsize); /* new position */ + lua_assert(cast_int(h%newsize) == lmod(h, newsize)); + p->gch.next = newhash[h1]; /* chain it */ + newhash[h1] = p; + p = next; + } + } + luaM_freearray(L, tb->hash, tb->size, TString *); + tb->size = newsize; + tb->hash = newhash; +} + + +static TString *newlstr (lua_State *L, const char *str, size_t l, + unsigned int h) { + TString *ts; + stringtable *tb; + if (l+1 > (MAX_SIZET - sizeof(TString))/sizeof(char)) + luaM_toobig(L); + ts = cast(TString *, luaM_malloc(L, (l+1)*sizeof(char)+sizeof(TString))); + ts->tsv.len = l; + ts->tsv.hash = h; + ts->tsv.marked = luaC_white(G(L)); + ts->tsv.tt = LUA_TSTRING; + ts->tsv.reserved = 0; + memcpy(ts+1, str, l*sizeof(char)); + ((char *)(ts+1))[l] = '\0'; /* ending 0 */ + tb = &G(L)->strt; + h = lmod(h, tb->size); + ts->tsv.next = tb->hash[h]; /* chain new entry */ + tb->hash[h] = obj2gco(ts); + tb->nuse++; + if (tb->nuse > cast(lu_int32, tb->size) && tb->size <= MAX_INT/2) + luaS_resize(L, tb->size*2); /* too crowded */ + return ts; +} + + +TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { + GCObject *o; + unsigned int h = cast(unsigned int, l); /* seed */ + size_t step = (l>>5)+1; /* if string is too long, don't hash all its chars */ + size_t l1; + for (l1=l; l1>=step; l1-=step) /* compute hash */ + h = h ^ ((h<<5)+(h>>2)+cast(unsigned char, str[l1-1])); + for (o = G(L)->strt.hash[lmod(h, G(L)->strt.size)]; + o != NULL; + o = o->gch.next) { + TString *ts = rawgco2ts(o); + if (ts->tsv.len == l && (memcmp(str, getstr(ts), l) == 0)) { + /* string may be dead */ + if (isdead(G(L), o)) changewhite(o); + return ts; + } + } + return newlstr(L, str, l, h); /* not found */ +} + + +Udata *luaS_newudata (lua_State *L, size_t s, Table *e) { + Udata *u; + if (s > MAX_SIZET - sizeof(Udata)) + luaM_toobig(L); + u = cast(Udata *, luaM_malloc(L, s + sizeof(Udata))); + u->uv.marked = luaC_white(G(L)); /* is not finalized */ + u->uv.tt = LUA_TUSERDATA; + u->uv.len = s; + u->uv.metatable = NULL; + u->uv.env = e; + /* chain it on udata list (after main thread) */ + u->uv.next = G(L)->mainthread->next; + G(L)->mainthread->next = obj2gco(u); + return u; +} diff --git a/src/blua/lstring.h b/src/blua/lstring.h new file mode 100644 index 000000000..73a2ff8b3 --- /dev/null +++ b/src/blua/lstring.h @@ -0,0 +1,31 @@ +/* +** $Id: lstring.h,v 1.43.1.1 2007/12/27 13:02:25 roberto Exp $ +** String table (keep all strings handled by Lua) +** See Copyright Notice in lua.h +*/ + +#ifndef lstring_h +#define lstring_h + + +#include "lgc.h" +#include "lobject.h" +#include "lstate.h" + + +#define sizestring(s) (sizeof(union TString)+((s)->len+1)*sizeof(char)) + +#define sizeudata(u) (sizeof(union Udata)+(u)->len) + +#define luaS_new(L, s) (luaS_newlstr(L, s, strlen(s))) +#define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ + (sizeof(s)/sizeof(char))-1)) + +#define luaS_fix(s) l_setbit((s)->tsv.marked, FIXEDBIT) + +LUAI_FUNC void luaS_resize (lua_State *L, int newsize); +LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, Table *e); +LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l); + + +#endif diff --git a/src/blua/lstrlib.c b/src/blua/lstrlib.c new file mode 100644 index 000000000..297504e95 --- /dev/null +++ b/src/blua/lstrlib.c @@ -0,0 +1,873 @@ +/* +** $Id: lstrlib.c,v 1.132.1.4 2008/07/11 17:27:21 roberto Exp $ +** Standard library for string operations and pattern-matching +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include +#include +#include + +#define lstrlib_c +#define LUA_LIB + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + + +/* macro to `unsign' a character */ +#define uchar(c) ((unsigned char)(c)) + + + +static int str_len (lua_State *L) { + size_t l; + luaL_checklstring(L, 1, &l); + lua_pushinteger(L, l); + return 1; +} + + +static ptrdiff_t posrelat (ptrdiff_t pos, size_t len) { + /* relative string position: negative means back from end */ + if (pos < 0) pos += (ptrdiff_t)len + 1; + return (pos >= 0) ? pos : 0; +} + + +static int str_sub (lua_State *L) { + size_t l; + const char *s = luaL_checklstring(L, 1, &l); + ptrdiff_t start = posrelat(luaL_checkinteger(L, 2), l); + ptrdiff_t end = posrelat(luaL_optinteger(L, 3, -1), l); + if (start < 1) start = 1; + if (end > (ptrdiff_t)l) end = (ptrdiff_t)l; + if (start <= end) + lua_pushlstring(L, s+start-1, end-start+1); + else lua_pushliteral(L, ""); + return 1; +} + + +static int str_reverse (lua_State *L) { + size_t l; + luaL_Buffer b; + const char *s = luaL_checklstring(L, 1, &l); + luaL_buffinit(L, &b); + while (l--) luaL_addchar(&b, s[l]); + luaL_pushresult(&b); + return 1; +} + + +static int str_lower (lua_State *L) { + size_t l; + size_t i; + luaL_Buffer b; + const char *s = luaL_checklstring(L, 1, &l); + luaL_buffinit(L, &b); + for (i=0; i 0) + luaL_addlstring(&b, s, l); + luaL_pushresult(&b); + return 1; +} + + +static int str_byte (lua_State *L) { + size_t l; + const char *s = luaL_checklstring(L, 1, &l); + ptrdiff_t posi = posrelat(luaL_optinteger(L, 2, 1), l); + ptrdiff_t pose = posrelat(luaL_optinteger(L, 3, posi), l); + int n, i; + if (posi <= 0) posi = 1; + if ((size_t)pose > l) pose = l; + if (posi > pose) return 0; /* empty interval; return no values */ + n = (int)(pose - posi + 1); + if (posi + n <= pose) /* overflow? */ + luaL_error(L, "string slice too long"); + luaL_checkstack(L, n, "string slice too long"); + for (i=0; i= ms->level || ms->capture[l].len == CAP_UNFINISHED) + return luaL_error(ms->L, "invalid capture index"); + return l; +} + + +static int capture_to_close (MatchState *ms) { + int level = ms->level; + for (level--; level>=0; level--) + if (ms->capture[level].len == CAP_UNFINISHED) return level; + return luaL_error(ms->L, "invalid pattern capture"); +} + + +static const char *classend (MatchState *ms, const char *p) { + switch (*p++) { + case L_ESC: { + if (*p == '\0') + luaL_error(ms->L, "malformed pattern (ends with " LUA_QL("%%") ")"); + return p+1; + } + case '[': { + if (*p == '^') p++; + do { /* look for a `]' */ + if (*p == '\0') + luaL_error(ms->L, "malformed pattern (missing " LUA_QL("]") ")"); + if (*(p++) == L_ESC && *p != '\0') + p++; /* skip escapes (e.g. `%]') */ + } while (*p != ']'); + return p+1; + } + default: { + return p; + } + } +} + + +static int match_class (int c, int cl) { + int res; + switch (tolower(cl)) { + case 'a' : res = isalpha(c); break; + case 'c' : res = iscntrl(c); break; + case 'd' : res = isdigit(c); break; + case 'l' : res = islower(c); break; + case 'p' : res = ispunct(c); break; + case 's' : res = isspace(c); break; + case 'u' : res = isupper(c); break; + case 'w' : res = isalnum(c); break; + case 'x' : res = isxdigit(c); break; + case 'z' : res = (c == 0); break; + default: return (cl == c); + } + return (islower(cl) ? res : !res); +} + + +static int matchbracketclass (int c, const char *p, const char *ec) { + int sig = 1; + if (*(p+1) == '^') { + sig = 0; + p++; /* skip the `^' */ + } + while (++p < ec) { + if (*p == L_ESC) { + p++; + if (match_class(c, uchar(*p))) + return sig; + } + else if ((*(p+1) == '-') && (p+2 < ec)) { + p+=2; + if (uchar(*(p-2)) <= c && c <= uchar(*p)) + return sig; + } + else if (uchar(*p) == c) return sig; + } + return !sig; +} + + +static int singlematch (int c, const char *p, const char *ep) { + switch (*p) { + case '.': return 1; /* matches any char */ + case L_ESC: return match_class(c, uchar(*(p+1))); + case '[': return matchbracketclass(c, p, ep-1); + default: return (uchar(*p) == c); + } +} + + +static const char *match (MatchState *ms, const char *s, const char *p); + + +static const char *matchbalance (MatchState *ms, const char *s, + const char *p) { + if (*p == 0 || *(p+1) == 0) + luaL_error(ms->L, "unbalanced pattern"); + if (*s != *p) return NULL; + else { + int b = *p; + int e = *(p+1); + int cont = 1; + while (++s < ms->src_end) { + if (*s == e) { + if (--cont == 0) return s+1; + } + else if (*s == b) cont++; + } + } + return NULL; /* string ends out of balance */ +} + + +static const char *max_expand (MatchState *ms, const char *s, + const char *p, const char *ep) { + ptrdiff_t i = 0; /* counts maximum expand for item */ + while ((s+i)src_end && singlematch(uchar(*(s+i)), p, ep)) + i++; + /* keeps trying to match with the maximum repetitions */ + while (i>=0) { + const char *res = match(ms, (s+i), ep+1); + if (res) return res; + i--; /* else didn't match; reduce 1 repetition to try again */ + } + return NULL; +} + + +static const char *min_expand (MatchState *ms, const char *s, + const char *p, const char *ep) { + for (;;) { + const char *res = match(ms, s, ep+1); + if (res != NULL) + return res; + else if (ssrc_end && singlematch(uchar(*s), p, ep)) + s++; /* try with one more repetition */ + else return NULL; + } +} + + +static const char *start_capture (MatchState *ms, const char *s, + const char *p, int what) { + const char *res; + int level = ms->level; + if (level >= LUA_MAXCAPTURES) luaL_error(ms->L, "too many captures"); + ms->capture[level].init = s; + ms->capture[level].len = what; + ms->level = level+1; + if ((res=match(ms, s, p)) == NULL) /* match failed? */ + ms->level--; /* undo capture */ + return res; +} + + +static const char *end_capture (MatchState *ms, const char *s, + const char *p) { + int l = capture_to_close(ms); + const char *res; + ms->capture[l].len = s - ms->capture[l].init; /* close capture */ + if ((res = match(ms, s, p)) == NULL) /* match failed? */ + ms->capture[l].len = CAP_UNFINISHED; /* undo capture */ + return res; +} + + +static const char *match_capture (MatchState *ms, const char *s, int l) { + size_t len; + l = check_capture(ms, l); + len = ms->capture[l].len; + if ((size_t)(ms->src_end-s) >= len && + memcmp(ms->capture[l].init, s, len) == 0) + return s+len; + else return NULL; +} + + +static const char *match (MatchState *ms, const char *s, const char *p) { + init: /* using goto's to optimize tail recursion */ + switch (*p) { + case '(': { /* start capture */ + if (*(p+1) == ')') /* position capture? */ + return start_capture(ms, s, p+2, CAP_POSITION); + else + return start_capture(ms, s, p+1, CAP_UNFINISHED); + } + case ')': { /* end capture */ + return end_capture(ms, s, p+1); + } + case L_ESC: { + switch (*(p+1)) { + case 'b': { /* balanced string? */ + s = matchbalance(ms, s, p+2); + if (s == NULL) return NULL; + p+=4; goto init; /* else return match(ms, s, p+4); */ + } + case 'f': { /* frontier? */ + const char *ep; char previous; + p += 2; + if (*p != '[') + luaL_error(ms->L, "missing " LUA_QL("[") " after " + LUA_QL("%%f") " in pattern"); + ep = classend(ms, p); /* points to what is next */ + previous = (s == ms->src_init) ? '\0' : *(s-1); + if (matchbracketclass(uchar(previous), p, ep-1) || + !matchbracketclass(uchar(*s), p, ep-1)) return NULL; + p=ep; goto init; /* else return match(ms, s, ep); */ + } + default: { + if (isdigit(uchar(*(p+1)))) { /* capture results (%0-%9)? */ + s = match_capture(ms, s, uchar(*(p+1))); + if (s == NULL) return NULL; + p+=2; goto init; /* else return match(ms, s, p+2) */ + } + goto dflt; /* case default */ + } + } + } + case '\0': { /* end of pattern */ + return s; /* match succeeded */ + } + case '$': { + if (*(p+1) == '\0') /* is the `$' the last char in pattern? */ + return (s == ms->src_end) ? s : NULL; /* check end of string */ + else goto dflt; + } + default: dflt: { /* it is a pattern item */ + const char *ep = classend(ms, p); /* points to what is next */ + int m = ssrc_end && singlematch(uchar(*s), p, ep); + switch (*ep) { + case '?': { /* optional */ + const char *res; + if (m && ((res=match(ms, s+1, ep+1)) != NULL)) + return res; + p=ep+1; goto init; /* else return match(ms, s, ep+1); */ + } + case '*': { /* 0 or more repetitions */ + return max_expand(ms, s, p, ep); + } + case '+': { /* 1 or more repetitions */ + return (m ? max_expand(ms, s+1, p, ep) : NULL); + } + case '-': { /* 0 or more repetitions (minimum) */ + return min_expand(ms, s, p, ep); + } + default: { + if (!m) return NULL; + s++; p=ep; goto init; /* else return match(ms, s+1, ep); */ + } + } + } + } +} + + + +static const char *lmemfind (const char *s1, size_t l1, + const char *s2, size_t l2) { + if (l2 == 0) return s1; /* empty strings are everywhere */ + else if (l2 > l1) return NULL; /* avoids a negative `l1' */ + else { + const char *init; /* to search for a `*s2' inside `s1' */ + l2--; /* 1st char will be checked by `memchr' */ + l1 = l1-l2; /* `s2' cannot be found after that */ + while (l1 > 0 && (init = (const char *)memchr(s1, *s2, l1)) != NULL) { + init++; /* 1st char is already checked */ + if (memcmp(init, s2+1, l2) == 0) + return init-1; + else { /* correct `l1' and `s1' to try again */ + l1 -= init-s1; + s1 = init; + } + } + return NULL; /* not found */ + } +} + + +static void push_onecapture (MatchState *ms, int i, const char *s, + const char *e) { + if (i >= ms->level) { + if (i == 0) /* ms->level == 0, too */ + lua_pushlstring(ms->L, s, e - s); /* add whole match */ + else + luaL_error(ms->L, "invalid capture index"); + } + else { + ptrdiff_t l = ms->capture[i].len; + if (l == CAP_UNFINISHED) luaL_error(ms->L, "unfinished capture"); + if (l == CAP_POSITION) + lua_pushinteger(ms->L, ms->capture[i].init - ms->src_init + 1); + else + lua_pushlstring(ms->L, ms->capture[i].init, l); + } +} + + +static int push_captures (MatchState *ms, const char *s, const char *e) { + int i; + int nlevels = (ms->level == 0 && s) ? 1 : ms->level; + luaL_checkstack(ms->L, nlevels, "too many captures"); + for (i = 0; i < nlevels; i++) + push_onecapture(ms, i, s, e); + return nlevels; /* number of strings pushed */ +} + + +static int str_find_aux (lua_State *L, int find) { + size_t l1, l2; + const char *s = luaL_checklstring(L, 1, &l1); + const char *p = luaL_checklstring(L, 2, &l2); + ptrdiff_t init = posrelat(luaL_optinteger(L, 3, 1), l1) - 1; + if (init < 0) init = 0; + else if ((size_t)(init) > l1) init = (ptrdiff_t)l1; + if (find && (lua_toboolean(L, 4) || /* explicit request? */ + strpbrk(p, SPECIALS) == NULL)) { /* or no special characters? */ + /* do a plain search */ + const char *s2 = lmemfind(s+init, l1-init, p, l2); + if (s2) { + lua_pushinteger(L, s2-s+1); + lua_pushinteger(L, s2-s+l2); + return 2; + } + } + else { + MatchState ms; + int anchor = (*p == '^') ? (p++, 1) : 0; + const char *s1=s+init; + ms.L = L; + ms.src_init = s; + ms.src_end = s+l1; + do { + const char *res; + ms.level = 0; + if ((res=match(&ms, s1, p)) != NULL) { + if (find) { + lua_pushinteger(L, s1-s+1); /* start */ + lua_pushinteger(L, res-s); /* end */ + return push_captures(&ms, NULL, 0) + 2; + } + else + return push_captures(&ms, s1, res); + } + } while (s1++ < ms.src_end && !anchor); + } + lua_pushnil(L); /* not found */ + return 1; +} + + +static int str_find (lua_State *L) { + return str_find_aux(L, 1); +} + + +static int str_match (lua_State *L) { + return str_find_aux(L, 0); +} + + +static int gmatch_aux (lua_State *L) { + MatchState ms; + size_t ls; + const char *s = lua_tolstring(L, lua_upvalueindex(1), &ls); + const char *p = lua_tostring(L, lua_upvalueindex(2)); + const char *src; + ms.L = L; + ms.src_init = s; + ms.src_end = s+ls; + for (src = s + (size_t)lua_tointeger(L, lua_upvalueindex(3)); + src <= ms.src_end; + src++) { + const char *e; + ms.level = 0; + if ((e = match(&ms, src, p)) != NULL) { + lua_Integer newstart = e-s; + if (e == src) newstart++; /* empty match? go at least one position */ + lua_pushinteger(L, newstart); + lua_replace(L, lua_upvalueindex(3)); + return push_captures(&ms, src, e); + } + } + return 0; /* not found */ +} + + +static int gmatch (lua_State *L) { + luaL_checkstring(L, 1); + luaL_checkstring(L, 2); + lua_settop(L, 2); + lua_pushinteger(L, 0); + lua_pushcclosure(L, gmatch_aux, 3); + return 1; +} + + +static int gfind_nodef (lua_State *L) { + return luaL_error(L, LUA_QL("string.gfind") " was renamed to " + LUA_QL("string.gmatch")); +} + + +static void add_s (MatchState *ms, luaL_Buffer *b, const char *s, + const char *e) { + size_t l, i; + const char *news = lua_tolstring(ms->L, 3, &l); + for (i = 0; i < l; i++) { + if (news[i] != L_ESC) + luaL_addchar(b, news[i]); + else { + i++; /* skip ESC */ + if (!isdigit(uchar(news[i]))) + luaL_addchar(b, news[i]); + else if (news[i] == '0') + luaL_addlstring(b, s, e - s); + else { + push_onecapture(ms, news[i] - '1', s, e); + luaL_addvalue(b); /* add capture to accumulated result */ + } + } + } +} + + +static void add_value (MatchState *ms, luaL_Buffer *b, const char *s, + const char *e) { + lua_State *L = ms->L; + switch (lua_type(L, 3)) { + case LUA_TNUMBER: + case LUA_TSTRING: { + add_s(ms, b, s, e); + return; + } + case LUA_TFUNCTION: { + int n; + lua_pushvalue(L, 3); + n = push_captures(ms, s, e); + lua_call(L, n, 1); + break; + } + case LUA_TTABLE: { + push_onecapture(ms, 0, s, e); + lua_gettable(L, 3); + break; + } + } + if (!lua_toboolean(L, -1)) { /* nil or false? */ + lua_pop(L, 1); + lua_pushlstring(L, s, e - s); /* keep original text */ + } + else if (!lua_isstring(L, -1)) + luaL_error(L, "invalid replacement value (a %s)", luaL_typename(L, -1)); + luaL_addvalue(b); /* add result to accumulator */ +} + + +static int str_gsub (lua_State *L) { + size_t srcl; + const char *src = luaL_checklstring(L, 1, &srcl); + const char *p = luaL_checkstring(L, 2); + int tr = lua_type(L, 3); + int max_s = luaL_optint(L, 4, srcl+1); + int anchor = (*p == '^') ? (p++, 1) : 0; + int n = 0; + MatchState ms; + luaL_Buffer b; + luaL_argcheck(L, tr == LUA_TNUMBER || tr == LUA_TSTRING || + tr == LUA_TFUNCTION || tr == LUA_TTABLE, 3, + "string/function/table expected"); + luaL_buffinit(L, &b); + ms.L = L; + ms.src_init = src; + ms.src_end = src+srcl; + while (n < max_s) { + const char *e; + ms.level = 0; + e = match(&ms, src, p); + if (e) { + n++; + add_value(&ms, &b, src, e); + } + if (e && e>src) /* non empty match? */ + src = e; /* skip it */ + else if (src < ms.src_end) + luaL_addchar(&b, *src++); + else break; + if (anchor) break; + } + luaL_addlstring(&b, src, ms.src_end-src); + luaL_pushresult(&b); + lua_pushinteger(L, n); /* number of substitutions */ + return 2; +} + +/* }====================================================== */ + + +/* maximum size of each formatted item (> len(format('%99.99f', -1e308))) */ +#define MAX_ITEM 512 +/* valid flags in a format specification */ +#define FLAGS "-+ #0" +/* +** maximum size of each format specification (such as '%-099.99d') +** (+10 accounts for %99.99x plus margin of error) +*/ +#define MAX_FORMAT (sizeof(FLAGS) + sizeof(LUA_INTFRMLEN) + 10) + + +static void addquoted (lua_State *L, luaL_Buffer *b, int arg) { + size_t l; + const char *s = luaL_checklstring(L, arg, &l); + luaL_addchar(b, '"'); + while (l--) { + switch (*s) { + case '"': case '\\': case '\n': { + luaL_addchar(b, '\\'); + luaL_addchar(b, *s); + break; + } + case '\r': { + luaL_addlstring(b, "\\r", 2); + break; + } + case '\0': { + luaL_addlstring(b, "\\000", 4); + break; + } + default: { + luaL_addchar(b, *s); + break; + } + } + s++; + } + luaL_addchar(b, '"'); +} + +static const char *scanformat (lua_State *L, const char *strfrmt, char *form) { + const char *p = strfrmt; + while (*p != '\0' && strchr(FLAGS, *p) != NULL) p++; /* skip flags */ + if ((size_t)(p - strfrmt) >= sizeof(FLAGS)) + luaL_error(L, "invalid format (repeated flags)"); + if (isdigit(uchar(*p))) p++; /* skip width */ + if (isdigit(uchar(*p))) p++; /* (2 digits at most) */ + if (*p == '.') { + p++; + if (isdigit(uchar(*p))) p++; /* skip precision */ + if (isdigit(uchar(*p))) p++; /* (2 digits at most) */ + } + if (isdigit(uchar(*p))) + luaL_error(L, "invalid format (width or precision too long)"); + *(form++) = '%'; + strncpy(form, strfrmt, p - strfrmt + 1); + form += p - strfrmt + 1; + *form = '\0'; + return p; +} + + +static void addintlen (char *form) { + size_t l = strlen(form); + char spec = form[l - 1]; + strcpy(form + l - 1, LUA_INTFRMLEN); + form[l + sizeof(LUA_INTFRMLEN) - 2] = spec; + form[l + sizeof(LUA_INTFRMLEN) - 1] = '\0'; +} + + +static int str_format (lua_State *L) { + int arg = 1; + size_t sfl; + const char *strfrmt = luaL_checklstring(L, arg, &sfl); + const char *strfrmt_end = strfrmt+sfl; + luaL_Buffer b; + luaL_buffinit(L, &b); + while (strfrmt < strfrmt_end) { + if (*strfrmt != L_ESC) + luaL_addchar(&b, *strfrmt++); + else if (*++strfrmt == L_ESC) + luaL_addchar(&b, *strfrmt++); /* %% */ + else { /* format item */ + char form[MAX_FORMAT]; /* to store the format (`%...') */ + char buff[MAX_ITEM]; /* to store the formatted item */ + arg++; + strfrmt = scanformat(L, strfrmt, form); + switch (*strfrmt++) { + case 'c': { + sprintf(buff, form, (int)luaL_checknumber(L, arg)); + break; + } + case 'd': case 'i': { + addintlen(form); + sprintf(buff, form, (LUA_INTFRM_T)luaL_checknumber(L, arg)); + break; + } + case 'o': case 'u': case 'x': case 'X': { + addintlen(form); + sprintf(buff, form, (unsigned LUA_INTFRM_T)luaL_checknumber(L, arg)); + break; + } + case 'e': case 'E': case 'f': + case 'g': case 'G': { + lua_Number n = luaL_checknumber(L, arg); + sprintf(buff, form, (double)n); + break; + } + case 'q': { + addquoted(L, &b, arg); + continue; /* skip the 'addsize' at the end */ + } + case 's': { + size_t l; + const char *s = luaL_checklstring(L, arg, &l); + if (!strchr(form, '.') && l >= 100) { + /* no precision and string is too long to be formatted; + keep original string */ + lua_pushvalue(L, arg); + luaL_addvalue(&b); + continue; /* skip the `addsize' at the end */ + } + else { + sprintf(buff, form, s); + break; + } + } + default: { /* also treat cases `pnLlh' */ + return luaL_error(L, "invalid option " LUA_QL("%%%c") " to " + LUA_QL("format"), *(strfrmt - 1)); + } + } + luaL_addlstring(&b, buff, strlen(buff)); + } + } + luaL_pushresult(&b); + return 1; +} + + +static const luaL_Reg strlib[] = { + {"byte", str_byte}, + {"char", str_char}, +#ifdef LUA_ALLOW_BYTECODE + {"dump", str_dump}, +#endif + {"find", str_find}, + {"format", str_format}, + {"gfind", gfind_nodef}, + {"gmatch", gmatch}, + {"gsub", str_gsub}, + {"len", str_len}, + {"lower", str_lower}, + {"match", str_match}, + {"rep", str_rep}, + {"reverse", str_reverse}, + {"sub", str_sub}, + {"upper", str_upper}, + {NULL, NULL} +}; + + +static void createmetatable (lua_State *L) { + lua_createtable(L, 0, 1); /* create metatable for strings */ + lua_pushliteral(L, ""); /* dummy string */ + lua_pushvalue(L, -2); + lua_setmetatable(L, -2); /* set string metatable */ + lua_pop(L, 1); /* pop dummy string */ + lua_pushvalue(L, -2); /* string library... */ + lua_setfield(L, -2, "__index"); /* ...is the __index metamethod */ + lua_pop(L, 1); /* pop metatable */ +} + + +/* +** Open string library +*/ +LUALIB_API int luaopen_string (lua_State *L) { + luaL_register(L, LUA_STRLIBNAME, strlib); +#if defined(LUA_COMPAT_GFIND) + lua_getfield(L, -1, "gmatch"); + lua_setfield(L, -2, "gfind"); +#endif + createmetatable(L); + return 1; +} diff --git a/src/blua/ltable.c b/src/blua/ltable.c new file mode 100644 index 000000000..9f4d91ff2 --- /dev/null +++ b/src/blua/ltable.c @@ -0,0 +1,588 @@ +/* +** $Id: ltable.c,v 2.32.1.2 2007/12/28 15:32:23 roberto Exp $ +** Lua tables (hash) +** See Copyright Notice in lua.h +*/ + + +/* +** Implementation of tables (aka arrays, objects, or hash tables). +** Tables keep its elements in two parts: an array part and a hash part. +** Non-negative integer keys are all candidates to be kept in the array +** part. The actual size of the array is the largest `n' such that at +** least half the slots between 0 and n are in use. +** Hash uses a mix of chained scatter table with Brent's variation. +** A main invariant of these tables is that, if an element is not +** in its main position (i.e. the `original' position that its hash gives +** to it), then the colliding element is in its own main position. +** Hence even when the load factor reaches 100%, performance remains good. +*/ + +#include +#include + +#define ltable_c +#define LUA_CORE + +#include "lua.h" + +#include "ldebug.h" +#include "ldo.h" +#include "lgc.h" +#include "lmem.h" +#include "lobject.h" +#include "lstate.h" +#include "ltable.h" + + +/* +** max size of array part is 2^MAXBITS +*/ +#if LUAI_BITSINT > 26 +#define MAXBITS 26 +#else +#define MAXBITS (LUAI_BITSINT-2) +#endif + +#define MAXASIZE (1 << MAXBITS) + + +#define hashpow2(t,n) (gnode(t, lmod((n), sizenode(t)))) + +#define hashstr(t,str) hashpow2(t, (str)->tsv.hash) +#define hashboolean(t,p) hashpow2(t, p) + + +/* +** for some types, it is better to avoid modulus by power of 2, as +** they tend to have many 2 factors. +*/ +#define hashmod(t,n) (gnode(t, ((n) % ((sizenode(t)-1)|1)))) + + +#define hashpointer(t,p) hashmod(t, IntPoint(p)) + + +/* +** number of ints inside a lua_Number +*/ +#define numints cast_int(sizeof(lua_Number)/sizeof(int)) + + + +#define dummynode (&dummynode_) + +static /*const*/ Node dummynode_ = { + {{NULL}, LUA_TNIL}, /* value */ + {{{NULL}, LUA_TNIL, NULL}} /* key */ +}; + + +/* +** hash for lua_Numbers +*/ +static Node *hashnum (const Table *t, lua_Number n) { + unsigned int a[numints]; + int i; + if (luai_numeq(n, 0)) /* avoid problems with -0 */ + return gnode(t, 0); + memcpy(a, &n, sizeof(a)); + for (i = 1; i < numints; i++) a[0] += a[i]; + return hashmod(t, a[0]); +} + + + +/* +** returns the `main' position of an element in a table (that is, the index +** of its hash value) +*/ +static Node *mainposition (const Table *t, const TValue *key) { + switch (ttype(key)) { + case LUA_TNUMBER: + return hashnum(t, nvalue(key)); + case LUA_TSTRING: + return hashstr(t, rawtsvalue(key)); + case LUA_TBOOLEAN: + return hashboolean(t, bvalue(key)); + case LUA_TLIGHTUSERDATA: + return hashpointer(t, pvalue(key)); + default: + return hashpointer(t, gcvalue(key)); + } +} + + +/* +** returns the index for `key' if `key' is an appropriate key to live in +** the array part of the table, -1 otherwise. +*/ +static int arrayindex (const TValue *key) { + if (ttisnumber(key)) { + lua_Number n = nvalue(key); + int k; + lua_number2int(k, n); + if (luai_numeq(cast_num(k), n)) + return k; + } + return -1; /* `key' did not match some condition */ +} + + +/* +** returns the index of a `key' for table traversals. First goes all +** elements in the array part, then elements in the hash part. The +** beginning of a traversal is signalled by -1. +*/ +static int findindex (lua_State *L, Table *t, StkId key) { + int i; + if (ttisnil(key)) return -1; /* first iteration */ + i = arrayindex(key); + if (0 < i && i <= t->sizearray) /* is `key' inside array part? */ + return i-1; /* yes; that's the index (corrected to C) */ + else { + Node *n = mainposition(t, key); + do { /* check whether `key' is somewhere in the chain */ + /* key may be dead already, but it is ok to use it in `next' */ + if (luaO_rawequalObj(key2tval(n), key) || + (ttype(gkey(n)) == LUA_TDEADKEY && iscollectable(key) && + gcvalue(gkey(n)) == gcvalue(key))) { + i = cast_int(n - gnode(t, 0)); /* key index in hash table */ + /* hash elements are numbered after array ones */ + return i + t->sizearray; + } + else n = gnext(n); + } while (n); + luaG_runerror(L, "invalid key to " LUA_QL("next")); /* key not found */ + return 0; /* to avoid warnings */ + } +} + + +int luaH_next (lua_State *L, Table *t, StkId key) { + int i = findindex(L, t, key); /* find original element */ + for (i++; i < t->sizearray; i++) { /* try first array part */ + if (!ttisnil(&t->array[i])) { /* a non-nil value? */ + setnvalue(key, cast_num(i+1)); + setobj2s(L, key+1, &t->array[i]); + return 1; + } + } + for (i -= t->sizearray; i < sizenode(t); i++) { /* then hash part */ + if (!ttisnil(gval(gnode(t, i)))) { /* a non-nil value? */ + setobj2s(L, key, key2tval(gnode(t, i))); + setobj2s(L, key+1, gval(gnode(t, i))); + return 1; + } + } + return 0; /* no more elements */ +} + + +/* +** {============================================================= +** Rehash +** ============================================================== +*/ + + +static int computesizes (int nums[], int *narray) { + int i; + int twotoi; /* 2^i */ + int a = 0; /* number of elements smaller than 2^i */ + int na = 0; /* number of elements to go to array part */ + int n = 0; /* optimal size for array part */ + for (i = 0, twotoi = 1; twotoi/2 < *narray; i++, twotoi *= 2) { + if (nums[i] > 0) { + a += nums[i]; + if (a > twotoi/2) { /* more than half elements present? */ + n = twotoi; /* optimal size (till now) */ + na = a; /* all elements smaller than n will go to array part */ + } + } + if (a == *narray) break; /* all elements already counted */ + } + *narray = n; + lua_assert(*narray/2 <= na && na <= *narray); + return na; +} + + +static int countint (const TValue *key, int *nums) { + int k = arrayindex(key); + if (0 < k && k <= MAXASIZE) { /* is `key' an appropriate array index? */ + nums[ceillog2(k)]++; /* count as such */ + return 1; + } + else + return 0; +} + + +static int numusearray (const Table *t, int *nums) { + int lg; + int ttlg; /* 2^lg */ + int ause = 0; /* summation of `nums' */ + int i = 1; /* count to traverse all array keys */ + for (lg=0, ttlg=1; lg<=MAXBITS; lg++, ttlg*=2) { /* for each slice */ + int lc = 0; /* counter */ + int lim = ttlg; + if (lim > t->sizearray) { + lim = t->sizearray; /* adjust upper limit */ + if (i > lim) + break; /* no more elements to count */ + } + /* count elements in range (2^(lg-1), 2^lg] */ + for (; i <= lim; i++) { + if (!ttisnil(&t->array[i-1])) + lc++; + } + nums[lg] += lc; + ause += lc; + } + return ause; +} + + +static int numusehash (const Table *t, int *nums, int *pnasize) { + int totaluse = 0; /* total number of elements */ + int ause = 0; /* summation of `nums' */ + int i = sizenode(t); + while (i--) { + Node *n = &t->node[i]; + if (!ttisnil(gval(n))) { + ause += countint(key2tval(n), nums); + totaluse++; + } + } + *pnasize += ause; + return totaluse; +} + + +static void setarrayvector (lua_State *L, Table *t, int size) { + int i; + luaM_reallocvector(L, t->array, t->sizearray, size, TValue); + for (i=t->sizearray; iarray[i]); + t->sizearray = size; +} + + +static void setnodevector (lua_State *L, Table *t, int size) { + int lsize; + if (size == 0) { /* no elements to hash part? */ + t->node = cast(Node *, dummynode); /* use common `dummynode' */ + lsize = 0; + } + else { + int i; + lsize = ceillog2(size); + if (lsize > MAXBITS) + luaG_runerror(L, "table overflow"); + size = twoto(lsize); + t->node = luaM_newvector(L, size, Node); + for (i=0; ilsizenode = cast_byte(lsize); + t->lastfree = gnode(t, size); /* all positions are free */ +} + + +static void resize (lua_State *L, Table *t, int nasize, int nhsize) { + int i; + int oldasize = t->sizearray; + int oldhsize = t->lsizenode; + Node *nold = t->node; /* save old hash ... */ + if (nasize > oldasize) /* array part must grow? */ + setarrayvector(L, t, nasize); + /* create new hash part with appropriate size */ + setnodevector(L, t, nhsize); + if (nasize < oldasize) { /* array part must shrink? */ + t->sizearray = nasize; + /* re-insert elements from vanishing slice */ + for (i=nasize; iarray[i])) + setobjt2t(L, luaH_setnum(L, t, i+1), &t->array[i]); + } + /* shrink array */ + luaM_reallocvector(L, t->array, oldasize, nasize, TValue); + } + /* re-insert elements from hash part */ + for (i = twoto(oldhsize) - 1; i >= 0; i--) { + Node *old = nold+i; + if (!ttisnil(gval(old))) + setobjt2t(L, luaH_set(L, t, key2tval(old)), gval(old)); + } + if (nold != dummynode) + luaM_freearray(L, nold, twoto(oldhsize), Node); /* free old array */ +} + + +void luaH_resizearray (lua_State *L, Table *t, int nasize) { + int nsize = (t->node == dummynode) ? 0 : sizenode(t); + resize(L, t, nasize, nsize); +} + + +static void rehash (lua_State *L, Table *t, const TValue *ek) { + int nasize, na; + int nums[MAXBITS+1]; /* nums[i] = number of keys between 2^(i-1) and 2^i */ + int i; + int totaluse; + for (i=0; i<=MAXBITS; i++) nums[i] = 0; /* reset counts */ + nasize = numusearray(t, nums); /* count keys in array part */ + totaluse = nasize; /* all those keys are integer keys */ + totaluse += numusehash(t, nums, &nasize); /* count keys in hash part */ + /* count extra key */ + nasize += countint(ek, nums); + totaluse++; + /* compute new size for array part */ + na = computesizes(nums, &nasize); + /* resize the table to new computed sizes */ + resize(L, t, nasize, totaluse - na); +} + + + +/* +** }============================================================= +*/ + + +Table *luaH_new (lua_State *L, int narray, int nhash) { + Table *t = luaM_new(L, Table); + luaC_link(L, obj2gco(t), LUA_TTABLE); + t->metatable = NULL; + t->flags = cast_byte(~0); + /* temporary values (kept only if some malloc fails) */ + t->array = NULL; + t->sizearray = 0; + t->lsizenode = 0; + t->node = cast(Node *, dummynode); + setarrayvector(L, t, narray); + setnodevector(L, t, nhash); + return t; +} + + +void luaH_free (lua_State *L, Table *t) { + if (t->node != dummynode) + luaM_freearray(L, t->node, sizenode(t), Node); + luaM_freearray(L, t->array, t->sizearray, TValue); + luaM_free(L, t); +} + + +static Node *getfreepos (Table *t) { + while (t->lastfree-- > t->node) { + if (ttisnil(gkey(t->lastfree))) + return t->lastfree; + } + return NULL; /* could not find a free place */ +} + + + +/* +** inserts a new key into a hash table; first, check whether key's main +** position is free. If not, check whether colliding node is in its main +** position or not: if it is not, move colliding node to an empty place and +** put new key in its main position; otherwise (colliding node is in its main +** position), new key goes to an empty position. +*/ +static TValue *newkey (lua_State *L, Table *t, const TValue *key) { + Node *mp = mainposition(t, key); + if (!ttisnil(gval(mp)) || mp == dummynode) { + Node *othern; + Node *n = getfreepos(t); /* get a free place */ + if (n == NULL) { /* cannot find a free place? */ + rehash(L, t, key); /* grow table */ + return luaH_set(L, t, key); /* re-insert key into grown table */ + } + lua_assert(n != dummynode); + othern = mainposition(t, key2tval(mp)); + if (othern != mp) { /* is colliding node out of its main position? */ + /* yes; move colliding node into free position */ + while (gnext(othern) != mp) othern = gnext(othern); /* find previous */ + gnext(othern) = n; /* redo the chain with `n' in place of `mp' */ + *n = *mp; /* copy colliding node into free pos. (mp->next also goes) */ + gnext(mp) = NULL; /* now `mp' is free */ + setnilvalue(gval(mp)); + } + else { /* colliding node is in its own main position */ + /* new node will go into free position */ + gnext(n) = gnext(mp); /* chain new position */ + gnext(mp) = n; + mp = n; + } + } + gkey(mp)->value = key->value; gkey(mp)->tt = key->tt; + luaC_barriert(L, t, key); + lua_assert(ttisnil(gval(mp))); + return gval(mp); +} + + +/* +** search function for integers +*/ +/*const*/ TValue *luaH_getnum (Table *t, int key) { + /* (1 <= key && key <= t->sizearray) */ + if (cast(unsigned int, key-1) < cast(unsigned int, t->sizearray)) + return &t->array[key-1]; + else { + lua_Number nk = cast_num(key); + Node *n = hashnum(t, nk); + do { /* check whether `key' is somewhere in the chain */ + if (ttisnumber(gkey(n)) && luai_numeq(nvalue(gkey(n)), nk)) + return gval(n); /* that's it */ + else n = gnext(n); + } while (n); + return luaO_nilobject; + } +} + + +/* +** search function for strings +*/ +/*const*/ TValue *luaH_getstr (Table *t, TString *key) { + Node *n = hashstr(t, key); + do { /* check whether `key' is somewhere in the chain */ + if (ttisstring(gkey(n)) && rawtsvalue(gkey(n)) == key) + return gval(n); /* that's it */ + else n = gnext(n); + } while (n); + return luaO_nilobject; +} + + +/* +** main search function +*/ +/*const*/ TValue *luaH_get (Table *t, const TValue *key) { + switch (ttype(key)) { + case LUA_TNIL: return luaO_nilobject; + case LUA_TSTRING: return luaH_getstr(t, rawtsvalue(key)); + case LUA_TNUMBER: { + int k; + lua_Number n = nvalue(key); + lua_number2int(k, n); + if (luai_numeq(cast_num(k), nvalue(key))) /* index is int? */ + return luaH_getnum(t, k); /* use specialized version */ + /* else go through */ + } + default: { + Node *n = mainposition(t, key); + do { /* check whether `key' is somewhere in the chain */ + if (luaO_rawequalObj(key2tval(n), key)) + return gval(n); /* that's it */ + else n = gnext(n); + } while (n); + return luaO_nilobject; + } + } +} + + +TValue *luaH_set (lua_State *L, Table *t, const TValue *key) { + /*const*/ TValue *p = luaH_get(t, key); + t->flags = 0; + if (p != luaO_nilobject) + return cast(TValue *, p); + else { + if (ttisnil(key)) luaG_runerror(L, "table index is nil"); + else if (ttisnumber(key) && luai_numisnan(nvalue(key))) + luaG_runerror(L, "table index is NaN"); + return newkey(L, t, key); + } +} + + +TValue *luaH_setnum (lua_State *L, Table *t, int key) { + /*const*/ TValue *p = luaH_getnum(t, key); + if (p != luaO_nilobject) + return cast(TValue *, p); + else { + TValue k; + setnvalue(&k, cast_num(key)); + return newkey(L, t, &k); + } +} + + +TValue *luaH_setstr (lua_State *L, Table *t, TString *key) { + /*const*/ TValue *p = luaH_getstr(t, key); + if (p != luaO_nilobject) + return cast(TValue *, p); + else { + TValue k; + setsvalue(L, &k, key); + return newkey(L, t, &k); + } +} + + +static int unbound_search (Table *t, unsigned int j) { + unsigned int i = j; /* i is zero or a present index */ + j++; + /* find `i' and `j' such that i is present and j is not */ + while (!ttisnil(luaH_getnum(t, j))) { + i = j; + j *= 2; + if (j > cast(unsigned int, MAX_INT)) { /* overflow? */ + /* table was built with bad purposes: resort to linear search */ + i = 1; + while (!ttisnil(luaH_getnum(t, i))) i++; + return i - 1; + } + } + /* now do a binary search between them */ + while (j - i > 1) { + unsigned int m = (i+j)/2; + if (ttisnil(luaH_getnum(t, m))) j = m; + else i = m; + } + return i; +} + + +/* +** Try to find a boundary in table `t'. A `boundary' is an integer index +** such that t[i] is non-nil and t[i+1] is nil (and 0 if t[1] is nil). +*/ +int luaH_getn (Table *t) { + unsigned int j = t->sizearray; + if (j > 0 && ttisnil(&t->array[j - 1])) { + /* there is a boundary in the array part: (binary) search for it */ + unsigned int i = 0; + while (j - i > 1) { + unsigned int m = (i+j)/2; + if (ttisnil(&t->array[m - 1])) j = m; + else i = m; + } + return i; + } + /* else must find a boundary in hash part */ + else if (t->node == dummynode) /* hash part is empty? */ + return j; /* that is easy... */ + else return unbound_search(t, j); +} + + + +#if defined(LUA_DEBUG) + +Node *luaH_mainposition (const Table *t, const TValue *key) { + return mainposition(t, key); +} + +int luaH_isdummy (Node *n) { return n == dummynode; } + +#endif diff --git a/src/blua/ltable.h b/src/blua/ltable.h new file mode 100644 index 000000000..9340305ff --- /dev/null +++ b/src/blua/ltable.h @@ -0,0 +1,40 @@ +/* +** $Id: ltable.h,v 2.10.1.1 2007/12/27 13:02:25 roberto Exp $ +** Lua tables (hash) +** See Copyright Notice in lua.h +*/ + +#ifndef ltable_h +#define ltable_h + +#include "lobject.h" + + +#define gnode(t,i) (&(t)->node[i]) +#define gkey(n) (&(n)->i_key.nk) +#define gval(n) (&(n)->i_val) +#define gnext(n) ((n)->i_key.nk.next) + +#define key2tval(n) (&(n)->i_key.tvk) + + +LUAI_FUNC /*const*/ TValue *luaH_getnum (Table *t, int key); +LUAI_FUNC TValue *luaH_setnum (lua_State *L, Table *t, int key); +LUAI_FUNC /*const*/ TValue *luaH_getstr (Table *t, TString *key); +LUAI_FUNC TValue *luaH_setstr (lua_State *L, Table *t, TString *key); +LUAI_FUNC /*const*/ TValue *luaH_get (Table *t, const TValue *key); +LUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key); +LUAI_FUNC Table *luaH_new (lua_State *L, int narray, int lnhash); +LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, int nasize); +LUAI_FUNC void luaH_free (lua_State *L, Table *t); +LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key); +LUAI_FUNC int luaH_getn (Table *t); + + +#if defined(LUA_DEBUG) +LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key); +LUAI_FUNC int luaH_isdummy (Node *n); +#endif + + +#endif diff --git a/src/blua/ltablib.c b/src/blua/ltablib.c new file mode 100644 index 000000000..2e50ce0ae --- /dev/null +++ b/src/blua/ltablib.c @@ -0,0 +1,286 @@ +/* +** $Id: ltablib.c,v 1.38.1.3 2008/02/14 16:46:58 roberto Exp $ +** Library for Table Manipulation +** See Copyright Notice in lua.h +*/ + + +#include + +#define ltablib_c +#define LUA_LIB + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + + +#define aux_getn(L,n) (luaL_checktype(L, n, LUA_TTABLE), luaL_getn(L, n)) + + +static int foreachi (lua_State *L) { + int i; + int n = aux_getn(L, 1); + luaL_checktype(L, 2, LUA_TFUNCTION); + for (i=1; i <= n; i++) { + lua_pushvalue(L, 2); /* function */ + lua_pushinteger(L, i); /* 1st argument */ + lua_rawgeti(L, 1, i); /* 2nd argument */ + lua_call(L, 2, 1); + if (!lua_isnil(L, -1)) + return 1; + lua_pop(L, 1); /* remove nil result */ + } + return 0; +} + + +static int foreach (lua_State *L) { + luaL_checktype(L, 1, LUA_TTABLE); + luaL_checktype(L, 2, LUA_TFUNCTION); + lua_pushnil(L); /* first key */ + while (lua_next(L, 1)) { + lua_pushvalue(L, 2); /* function */ + lua_pushvalue(L, -3); /* key */ + lua_pushvalue(L, -3); /* value */ + lua_call(L, 2, 1); + if (!lua_isnil(L, -1)) + return 1; + lua_pop(L, 2); /* remove value and result */ + } + return 0; +} + + +static int maxn (lua_State *L) { + lua_Number max = 0; + luaL_checktype(L, 1, LUA_TTABLE); + lua_pushnil(L); /* first key */ + while (lua_next(L, 1)) { + lua_pop(L, 1); /* remove value */ + if (lua_type(L, -1) == LUA_TNUMBER) { + lua_Number v = lua_tonumber(L, -1); + if (v > max) max = v; + } + } + lua_pushnumber(L, max); + return 1; +} + + +static int getn (lua_State *L) { + lua_pushinteger(L, aux_getn(L, 1)); + return 1; +} + + +static int setn (lua_State *L) { + luaL_checktype(L, 1, LUA_TTABLE); +#ifndef luaL_setn + luaL_setn(L, 1, luaL_checkint(L, 2)); +#else + luaL_error(L, LUA_QL("setn") " is obsolete"); +#endif + lua_pushvalue(L, 1); + return 1; +} + + +static int tinsert (lua_State *L) { + int e = aux_getn(L, 1) + 1; /* first empty element */ + int pos; /* where to insert new element */ + switch (lua_gettop(L)) { + case 2: { /* called with only 2 arguments */ + pos = e; /* insert new element at the end */ + break; + } + case 3: { + int i; + pos = luaL_checkint(L, 2); /* 2nd argument is the position */ + if (pos > e) e = pos; /* `grow' array if necessary */ + for (i = e; i > pos; i--) { /* move up elements */ + lua_rawgeti(L, 1, i-1); + lua_rawseti(L, 1, i); /* t[i] = t[i-1] */ + } + break; + } + default: { + return luaL_error(L, "wrong number of arguments to " LUA_QL("insert")); + } + } + luaL_setn(L, 1, e); /* new size */ + lua_rawseti(L, 1, pos); /* t[pos] = v */ + return 0; +} + + +static int tremove (lua_State *L) { + int e = aux_getn(L, 1); + int pos = luaL_optint(L, 2, e); + if (!(1 <= pos && pos <= e)) /* position is outside bounds? */ + return 0; /* nothing to remove */ + luaL_setn(L, 1, e - 1); /* t.n = n-1 */ + lua_rawgeti(L, 1, pos); /* result = t[pos] */ + for ( ;pos= P */ + while (lua_rawgeti(L, 1, ++i), sort_comp(L, -1, -2)) { + if (i>u) luaL_error(L, "invalid order function for sorting"); + lua_pop(L, 1); /* remove a[i] */ + } + /* repeat --j until a[j] <= P */ + while (lua_rawgeti(L, 1, --j), sort_comp(L, -3, -1)) { + if (j + +#define ltm_c +#define LUA_CORE + +#include "lua.h" + +#include "lobject.h" +#include "lstate.h" +#include "lstring.h" +#include "ltable.h" +#include "ltm.h" + + + +const char *const luaT_typenames[] = { + "nil", "boolean", "userdata", "number", + "string", "table", "function", "userdata", "thread", + "proto", "upval" +}; + + +void luaT_init (lua_State *L) { + static const char *const luaT_eventname[] = { /* ORDER TM */ + "__index", "__newindex", + "__usedindex", + "__gc", "__mode", "__eq", + "__add", "__sub", "__mul", "__div", "__mod", + "__pow", "__unm", "__len", "__lt", "__le", + "__concat", "__call" + ,"__strhook" + ,"__and", "__or", "__xor", "__shl", "__shr", "__not" + }; + int i; + for (i=0; itmname[i] = luaS_new(L, luaT_eventname[i]); + luaS_fix(G(L)->tmname[i]); /* never collect these names */ + } +} + + +/* +** function to be used with macro "fasttm": optimized for absence of +** tag methods +*/ +TValue *luaT_gettm (Table *events, TMS event, TString *ename) { + TValue *tm = luaH_getstr(events, ename); + lua_assert(event <= TM_EQ); + if (ttisnil(tm)) { /* no tag method? */ + events->flags |= cast_byte(1u<metatable; + break; + case LUA_TUSERDATA: + mt = uvalue(o)->metatable; + break; + default: + mt = G(L)->mt[ttype(o)]; + } + return (mt ? luaH_getstr(mt, G(L)->tmname[event]) : luaO_nilobject); +} diff --git a/src/blua/ltm.h b/src/blua/ltm.h new file mode 100644 index 000000000..3d4ac8c0e --- /dev/null +++ b/src/blua/ltm.h @@ -0,0 +1,61 @@ +/* +** $Id: ltm.h,v 2.6.1.1 2007/12/27 13:02:25 roberto Exp $ +** Tag methods +** See Copyright Notice in lua.h +*/ + +#ifndef ltm_h +#define ltm_h + + +#include "lobject.h" + + +/* +* WARNING: if you change the order of this enumeration, +* grep "ORDER TM" +*/ +typedef enum { + TM_INDEX, + TM_NEWINDEX, + TM_USEDINDEX, + TM_GC, + TM_MODE, + TM_EQ, /* last tag method with `fast' access */ + TM_ADD, + TM_SUB, + TM_MUL, + TM_DIV, + TM_MOD, + TM_POW, + TM_UNM, + TM_LEN, + TM_LT, + TM_LE, + TM_CONCAT, + TM_CALL, + TM_STRHOOK, + TM_AND, + TM_OR, + TM_XOR, + TM_SHL, + TM_SHR, + TM_NOT, + TM_N /* number of elements in the enum */ +} TMS; + + + +#define gfasttm(g,et,e) ((et) == NULL ? NULL : \ + ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e])) + +#define fasttm(l,et,e) gfasttm(G(l), et, e) + +LUAI_DATA const char *const luaT_typenames[]; + + +LUAI_FUNC TValue *luaT_gettm (Table *events, TMS event, TString *ename); +LUAI_FUNC TValue *luaT_gettmbyobj (lua_State *L, TValue *o, TMS event); +LUAI_FUNC void luaT_init (lua_State *L); + +#endif diff --git a/src/blua/lua.h b/src/blua/lua.h new file mode 100644 index 000000000..a945fcb5c --- /dev/null +++ b/src/blua/lua.h @@ -0,0 +1,389 @@ +/* +** $Id: lua.h,v 1.218.1.5 2008/08/06 13:30:12 roberto Exp $ +** Lua - An Extensible Extension Language +** Lua.org, PUC-Rio, Brazil (http://www.lua.org) +** See Copyright Notice at the end of this file +*/ + + +#ifndef lua_h +#define lua_h + +#include +#include + + +#include "luaconf.h" + + +#define LUA_VERSION "Lua 5.1" +#define LUA_RELEASE "Lua 5.1.4" +#define LUA_VERSION_NUM 501 +#define LUA_COPYRIGHT "Copyright (C) 1994-2008 Lua.org, PUC-Rio" +#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes" + + +/* mark for precompiled code (`Lua') */ +#define LUA_SIGNATURE "\033Lua" + +/* option for multiple returns in `lua_pcall' and `lua_call' */ +#define LUA_MULTRET (-1) + + +/* +** pseudo-indices +*/ +#define LUA_REGISTRYINDEX (-10000) +#define LUA_ENVIRONINDEX (-10001) +#define LUA_GLOBALSINDEX (-10002) +#define lua_upvalueindex(i) (LUA_GLOBALSINDEX-(i)) + + +/* thread status; 0 is OK */ +#define LUA_YIELD 1 +#define LUA_ERRRUN 2 +#define LUA_ERRSYNTAX 3 +#define LUA_ERRMEM 4 +#define LUA_ERRERR 5 + + +typedef struct lua_State lua_State; + +typedef int (*lua_CFunction) (lua_State *L); + + +/* +** functions that read/write blocks when loading/dumping Lua chunks +*/ +typedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz); + +typedef int (*lua_Writer) (lua_State *L, const void* p, size_t sz, void* ud); + + +/* +** prototype for memory-allocation functions +*/ +typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize); + + +/* +** basic types +*/ +#define LUA_TNONE (-1) + +#define LUA_TNIL 0 +#define LUA_TBOOLEAN 1 +#define LUA_TLIGHTUSERDATA 2 +#define LUA_TNUMBER 3 +#define LUA_TSTRING 4 +#define LUA_TTABLE 5 +#define LUA_TFUNCTION 6 +#define LUA_TUSERDATA 7 +#define LUA_TTHREAD 8 + + + +/* minimum Lua stack available to a C function */ +#define LUA_MINSTACK 20 + + +/* +** generic extra include file +*/ +#if defined(LUA_USER_H) +#include LUA_USER_H +#endif + + +/* type of numbers in Lua */ +typedef LUA_NUMBER lua_Number; + + +/* type for integer functions */ +typedef LUA_INTEGER lua_Integer; + + + +/* +** state manipulation +*/ +LUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud); +LUA_API void (lua_close) (lua_State *L); +LUA_API lua_State *(lua_newthread) (lua_State *L); + +LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf); + + +/* +** basic stack manipulation +*/ +LUA_API int (lua_gettop) (lua_State *L); +LUA_API void (lua_settop) (lua_State *L, int idx); +LUA_API void (lua_pushvalue) (lua_State *L, int idx); +LUA_API void (lua_remove) (lua_State *L, int idx); +LUA_API void (lua_insert) (lua_State *L, int idx); +LUA_API void (lua_replace) (lua_State *L, int idx); +LUA_API int (lua_checkstack) (lua_State *L, int sz); + +LUA_API void (lua_xmove) (lua_State *from, lua_State *to, int n); + + +/* +** access functions (stack -> C) +*/ + +LUA_API int (lua_isnumber) (lua_State *L, int idx); +LUA_API int (lua_isstring) (lua_State *L, int idx); +LUA_API int (lua_iscfunction) (lua_State *L, int idx); +LUA_API int (lua_isuserdata) (lua_State *L, int idx); +LUA_API int (lua_type) (lua_State *L, int idx); +LUA_API const char *(lua_typename) (lua_State *L, int tp); + +LUA_API int (lua_equal) (lua_State *L, int idx1, int idx2); +LUA_API int (lua_rawequal) (lua_State *L, int idx1, int idx2); +LUA_API int (lua_lessthan) (lua_State *L, int idx1, int idx2); + +LUA_API lua_Number (lua_tonumber) (lua_State *L, int idx); +LUA_API lua_Integer (lua_tointeger) (lua_State *L, int idx); +LUA_API int (lua_toboolean) (lua_State *L, int idx); +LUA_API const char *(lua_tolstring) (lua_State *L, int idx, size_t *len); +LUA_API size_t (lua_objlen) (lua_State *L, int idx); +LUA_API lua_CFunction (lua_tocfunction) (lua_State *L, int idx); +LUA_API void *(lua_touserdata) (lua_State *L, int idx); +LUA_API lua_State *(lua_tothread) (lua_State *L, int idx); +LUA_API const void *(lua_topointer) (lua_State *L, int idx); + + +/* +** push functions (C -> stack) +*/ +LUA_API void (lua_pushnil) (lua_State *L); +LUA_API void (lua_pushnumber) (lua_State *L, lua_Number n); +LUA_API void (lua_pushinteger) (lua_State *L, lua_Integer n); +LUA_API void (lua_pushlstring) (lua_State *L, const char *s, size_t l); +LUA_API void (lua_pushstring) (lua_State *L, const char *s); +LUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt, + va_list argp); +LUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...); +LUA_API void (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n); +LUA_API void (lua_pushboolean) (lua_State *L, int b); +LUA_API void (lua_pushlightuserdata) (lua_State *L, void *p); +LUA_API void (lua_pushuserdata) (lua_State *L, void *p); +LUA_API int (lua_pushthread) (lua_State *L); + + +/* +** get functions (Lua -> stack) +*/ +LUA_API void (lua_gettable) (lua_State *L, int idx); +LUA_API void (lua_getfield) (lua_State *L, int idx, const char *k); +LUA_API void (lua_rawget) (lua_State *L, int idx); +LUA_API void (lua_rawgeti) (lua_State *L, int idx, int n); +LUA_API void (lua_createtable) (lua_State *L, int narr, int nrec); +LUA_API void *(lua_newuserdata) (lua_State *L, size_t sz); +LUA_API int (lua_getmetatable) (lua_State *L, int objindex); +LUA_API void (lua_getfenv) (lua_State *L, int idx); + + +/* +** set functions (stack -> Lua) +*/ +LUA_API void (lua_settable) (lua_State *L, int idx); +LUA_API void (lua_setfield) (lua_State *L, int idx, const char *k); +LUA_API void (lua_rawset) (lua_State *L, int idx); +LUA_API void (lua_rawseti) (lua_State *L, int idx, int n); +LUA_API int (lua_setmetatable) (lua_State *L, int objindex); +LUA_API int (lua_setfenv) (lua_State *L, int idx); + + +/* +** `load' and `call' functions (load and run Lua code) +*/ +LUA_API void (lua_call) (lua_State *L, int nargs, int nresults); +LUA_API int (lua_pcall) (lua_State *L, int nargs, int nresults, int errfunc); +LUA_API int (lua_cpcall) (lua_State *L, lua_CFunction func, void *ud); +LUA_API int (lua_load) (lua_State *L, lua_Reader reader, void *dt, + const char *chunkname); + +LUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data); + + +/* +** coroutine functions +*/ +LUA_API int (lua_yield) (lua_State *L, int nresults); +LUA_API int (lua_resume) (lua_State *L, int narg); +LUA_API int (lua_status) (lua_State *L); + +/* +** garbage-collection function and options +*/ + +#define LUA_GCSTOP 0 +#define LUA_GCRESTART 1 +#define LUA_GCCOLLECT 2 +#define LUA_GCCOUNT 3 +#define LUA_GCCOUNTB 4 +#define LUA_GCSTEP 5 +#define LUA_GCSETPAUSE 6 +#define LUA_GCSETSTEPMUL 7 + +LUA_API int (lua_gc) (lua_State *L, int what, int data); + + +/* +** miscellaneous functions +*/ + +LUA_API int (lua_error) (lua_State *L); + +LUA_API int (lua_next) (lua_State *L, int idx); + +LUA_API void (lua_concat) (lua_State *L, int n); + +LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud); +LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud); + + + +/* +** =============================================================== +** some useful macros +** =============================================================== +*/ + +#define lua_pop(L,n) lua_settop(L, -(n)-1) + +#define lua_newtable(L) lua_createtable(L, 0, 0) + +#define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n))) + +#define lua_pushcfunction(L,f) lua_pushcclosure(L, (f), 0) + +#define lua_strlen(L,i) lua_objlen(L, (i)) + +#define lua_isfunction(L,n) (lua_type(L, (n)) == LUA_TFUNCTION) +#define lua_istable(L,n) (lua_type(L, (n)) == LUA_TTABLE) +#define lua_islightuserdata(L,n) (lua_type(L, (n)) == LUA_TLIGHTUSERDATA) +#define lua_isnil(L,n) (lua_type(L, (n)) == LUA_TNIL) +#define lua_isboolean(L,n) (lua_type(L, (n)) == LUA_TBOOLEAN) +#define lua_isthread(L,n) (lua_type(L, (n)) == LUA_TTHREAD) +#define lua_isnone(L,n) (lua_type(L, (n)) == LUA_TNONE) +#define lua_isnoneornil(L, n) (lua_type(L, (n)) <= 0) + +#define lua_pushliteral(L, s) \ + lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1) + +#define lua_setglobal(L,s) lua_setfield(L, LUA_GLOBALSINDEX, (s)) +#define lua_getglobal(L,s) lua_getfield(L, LUA_GLOBALSINDEX, (s)) + +#define lua_tostring(L,i) lua_tolstring(L, (i), NULL) + + + +/* +** compatibility macros and functions +*/ + +#define lua_open() luaL_newstate() + +#define lua_getregistry(L) lua_pushvalue(L, LUA_REGISTRYINDEX) + +#define lua_getgccount(L) lua_gc(L, LUA_GCCOUNT, 0) + +#define lua_Chunkreader lua_Reader +#define lua_Chunkwriter lua_Writer + + +/* hack */ +LUA_API void lua_setlevel (lua_State *from, lua_State *to); + + +/* +** {====================================================================== +** Debug API +** ======================================================================= +*/ + + +/* +** Event codes +*/ +#define LUA_HOOKCALL 0 +#define LUA_HOOKRET 1 +#define LUA_HOOKLINE 2 +#define LUA_HOOKCOUNT 3 +#define LUA_HOOKTAILRET 4 + + +/* +** Event masks +*/ +#define LUA_MASKCALL (1 << LUA_HOOKCALL) +#define LUA_MASKRET (1 << LUA_HOOKRET) +#define LUA_MASKLINE (1 << LUA_HOOKLINE) +#define LUA_MASKCOUNT (1 << LUA_HOOKCOUNT) + +typedef struct lua_Debug lua_Debug; /* activation record */ + + +/* Functions to be called by the debuger in specific events */ +typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar); + + +LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar); +LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar); +LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n); +LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n); +LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n); +LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n); + +LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count); +LUA_API lua_Hook lua_gethook (lua_State *L); +LUA_API int lua_gethookmask (lua_State *L); +LUA_API int lua_gethookcount (lua_State *L); + + +struct lua_Debug { + int event; + const char *name; /* (n) */ + const char *namewhat; /* (n) `global', `local', `field', `method' */ + const char *what; /* (S) `Lua', `C', `main', `tail' */ + const char *source; /* (S) */ + int currentline; /* (l) */ + int nups; /* (u) number of upvalues */ + int linedefined; /* (S) */ + int lastlinedefined; /* (S) */ + char short_src[LUA_IDSIZE]; /* (S) */ + /* private part */ + int i_ci; /* active function */ +}; + +/* }====================================================================== */ + + +/****************************************************************************** +* Copyright (C) 1994-2008 Lua.org, PUC-Rio. All rights reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining +* a copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sublicense, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice shall be +* included in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +******************************************************************************/ + + +#endif diff --git a/src/blua/luaconf.h b/src/blua/luaconf.h new file mode 100644 index 000000000..4fb940799 --- /dev/null +++ b/src/blua/luaconf.h @@ -0,0 +1,776 @@ +/* +** $Id: luaconf.h,v 1.82.1.7 2008/02/11 16:25:08 roberto Exp $ +** Configuration file for Lua +** See Copyright Notice in lua.h +*/ + + +#ifndef lconfig_h +#define lconfig_h + +#include +#include + + +/* +** ================================================================== +** Search for "@@" to find all configurable definitions. +** =================================================================== +*/ + + +/* +@@ LUA_ANSI controls the use of non-ansi features. +** CHANGE it (define it) if you want Lua to avoid the use of any +** non-ansi feature or library. +*/ +#if defined(__STRICT_ANSI__) +#define LUA_ANSI +#endif + + +#if !defined(LUA_ANSI) && defined(_WIN32) +#define LUA_WIN +#endif + +#if defined(LUA_USE_LINUX) +#define LUA_USE_POSIX +#define LUA_USE_DLOPEN /* needs an extra library: -ldl */ +#define LUA_USE_READLINE /* needs some extra libraries */ +#endif + +#if defined(LUA_USE_MACOSX) +#define LUA_USE_POSIX +#define LUA_DL_DYLD /* does not need extra library */ +#endif + + + +/* +@@ LUA_USE_POSIX includes all functionallity listed as X/Open System +@* Interfaces Extension (XSI). +** CHANGE it (define it) if your system is XSI compatible. +*/ +#if defined(LUA_USE_POSIX) +#define LUA_USE_MKSTEMP +#define LUA_USE_ISATTY +#define LUA_USE_POPEN +#define LUA_USE_ULONGJMP +#endif + + +/* +@@ LUA_PATH and LUA_CPATH are the names of the environment variables that +@* Lua check to set its paths. +@@ LUA_INIT is the name of the environment variable that Lua +@* checks for initialization code. +** CHANGE them if you want different names. +*/ +#define LUA_PATH "LUA_PATH" +#define LUA_CPATH "LUA_CPATH" +#define LUA_INIT "LUA_INIT" + + +/* +@@ LUA_PATH_DEFAULT is the default path that Lua uses to look for +@* Lua libraries. +@@ LUA_CPATH_DEFAULT is the default path that Lua uses to look for +@* C libraries. +** CHANGE them if your machine has a non-conventional directory +** hierarchy or if you want to install your libraries in +** non-conventional directories. +*/ +#if defined(_WIN32) +/* +** In Windows, any exclamation mark ('!') in the path is replaced by the +** path of the directory of the executable file of the current process. +*/ +#define LUA_LDIR "!\\lua\\" +#define LUA_CDIR "!\\" +#define LUA_PATH_DEFAULT \ + ".\\?.lua;" LUA_LDIR"?.lua;" LUA_LDIR"?\\init.lua;" \ + LUA_CDIR"?.lua;" LUA_CDIR"?\\init.lua" +#define LUA_CPATH_DEFAULT \ + ".\\?.dll;" LUA_CDIR"?.dll;" LUA_CDIR"loadall.dll" + +#else +#define LUA_ROOT "/usr/local/" +#define LUA_LDIR LUA_ROOT "share/lua/5.1/" +#define LUA_CDIR LUA_ROOT "lib/lua/5.1/" +#define LUA_PATH_DEFAULT \ + "./?.lua;" LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua;" \ + LUA_CDIR"?.lua;" LUA_CDIR"?/init.lua" +#define LUA_CPATH_DEFAULT \ + "./?.so;" LUA_CDIR"?.so;" LUA_CDIR"loadall.so" +#endif + + +/* +@@ LUA_DIRSEP is the directory separator (for submodules). +** CHANGE it if your machine does not use "/" as the directory separator +** and is not Windows. (On Windows Lua automatically uses "\".) +*/ +#if defined(_WIN32) +#define LUA_DIRSEP "\\" +#else +#define LUA_DIRSEP "/" +#endif + + +/* +@@ LUA_PATHSEP is the character that separates templates in a path. +@@ LUA_PATH_MARK is the string that marks the substitution points in a +@* template. +@@ LUA_EXECDIR in a Windows path is replaced by the executable's +@* directory. +@@ LUA_IGMARK is a mark to ignore all before it when bulding the +@* luaopen_ function name. +** CHANGE them if for some reason your system cannot use those +** characters. (E.g., if one of those characters is a common character +** in file/directory names.) Probably you do not need to change them. +*/ +#define LUA_PATHSEP ";" +#define LUA_PATH_MARK "?" +#define LUA_EXECDIR "!" +#define LUA_IGMARK "-" + + +/* +@@ LUA_INTEGER is the integral type used by lua_pushinteger/lua_tointeger. +** CHANGE that if ptrdiff_t is not adequate on your machine. (On most +** machines, ptrdiff_t gives a good choice between int or long.) +*/ +#define LUA_INTEGER ptrdiff_t + + +/* +@@ LUA_API is a mark for all core API functions. +@@ LUALIB_API is a mark for all standard library functions. +** CHANGE them if you need to define those functions in some special way. +** For instance, if you want to create one Windows DLL with the core and +** the libraries, you may want to use the following definition (define +** LUA_BUILD_AS_DLL to get it). +*/ +#if defined(LUA_BUILD_AS_DLL) + +#if defined(LUA_CORE) || defined(LUA_LIB) +#define LUA_API __declspec(dllexport) +#else +#define LUA_API __declspec(dllimport) +#endif + +#else + +#define LUA_API extern + +#endif + +/* more often than not the libs go together with the core */ +#define LUALIB_API LUA_API + + +/* +@@ LUAI_FUNC is a mark for all extern functions that are not to be +@* exported to outside modules. +@@ LUAI_DATA is a mark for all extern (const) variables that are not to +@* be exported to outside modules. +** CHANGE them if you need to mark them in some special way. Elf/gcc +** (versions 3.2 and later) mark them as "hidden" to optimize access +** when Lua is compiled as a shared library. +*/ +#if defined(luaall_c) +#define LUAI_FUNC static +#define LUAI_DATA /* empty */ + +#elif defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \ + defined(__ELF__) +#define LUAI_FUNC __attribute__((visibility("hidden"))) extern +#define LUAI_DATA LUAI_FUNC + +#else +#define LUAI_FUNC extern +#define LUAI_DATA extern +#endif + + + +/* +@@ LUA_QL describes how error messages quote program elements. +** CHANGE it if you want a different appearance. +*/ +#define LUA_QL(x) "'" x "'" +#define LUA_QS LUA_QL("%s") + + +/* +@@ LUA_IDSIZE gives the maximum size for the description of the source +@* of a function in debug information. +** CHANGE it if you want a different size. +*/ +#define LUA_IDSIZE 60 + + +/* +** {================================================================== +** Stand-alone configuration +** =================================================================== +*/ + +#if defined(lua_c) || defined(luaall_c) + +/* +@@ lua_stdin_is_tty detects whether the standard input is a 'tty' (that +@* is, whether we're running lua interactively). +** CHANGE it if you have a better definition for non-POSIX/non-Windows +** systems. +*/ +#if defined(LUA_USE_ISATTY) +#include +#define lua_stdin_is_tty() isatty(0) +#elif defined(LUA_WIN) +#include +#include +#define lua_stdin_is_tty() _isatty(_fileno(stdin)) +#else +#define lua_stdin_is_tty() 1 /* assume stdin is a tty */ +#endif + + +/* +@@ LUA_PROMPT is the default prompt used by stand-alone Lua. +@@ LUA_PROMPT2 is the default continuation prompt used by stand-alone Lua. +** CHANGE them if you want different prompts. (You can also change the +** prompts dynamically, assigning to globals _PROMPT/_PROMPT2.) +*/ +#define LUA_PROMPT "> " +#define LUA_PROMPT2 ">> " + + +/* +@@ LUA_PROGNAME is the default name for the stand-alone Lua program. +** CHANGE it if your stand-alone interpreter has a different name and +** your system is not able to detect that name automatically. +*/ +#define LUA_PROGNAME "lua" + + +/* +@@ LUA_MAXINPUT is the maximum length for an input line in the +@* stand-alone interpreter. +** CHANGE it if you need longer lines. +*/ +#define LUA_MAXINPUT 512 + + +/* +@@ lua_readline defines how to show a prompt and then read a line from +@* the standard input. +@@ lua_saveline defines how to "save" a read line in a "history". +@@ lua_freeline defines how to free a line read by lua_readline. +** CHANGE them if you want to improve this functionality (e.g., by using +** GNU readline and history facilities). +*/ +#if defined(LUA_USE_READLINE) +#include +#include +#include +#define lua_readline(L,b,p) ((void)L, ((b)=readline(p)) != NULL) +#define lua_saveline(L,idx) \ + if (lua_strlen(L,idx) > 0) /* non-empty line? */ \ + add_history(lua_tostring(L, idx)); /* add it to history */ +#define lua_freeline(L,b) ((void)L, free(b)) +#else +#define lua_readline(L,b,p) \ + ((void)L, fputs(p, stdout), fflush(stdout), /* show prompt */ \ + fgets(b, LUA_MAXINPUT, stdin) != NULL) /* get line */ +#define lua_saveline(L,idx) { (void)L; (void)idx; } +#define lua_freeline(L,b) { (void)L; (void)b; } +#endif + +#endif + +/* }================================================================== */ + + +/* +@@ LUAI_GCPAUSE defines the default pause between garbage-collector cycles +@* as a percentage. +** CHANGE it if you want the GC to run faster or slower (higher values +** mean larger pauses which mean slower collection.) You can also change +** this value dynamically. +*/ +#define LUAI_GCPAUSE 200 /* 200% (wait memory to double before next GC) */ + + +/* +@@ LUAI_GCMUL defines the default speed of garbage collection relative to +@* memory allocation as a percentage. +** CHANGE it if you want to change the granularity of the garbage +** collection. (Higher values mean coarser collections. 0 represents +** infinity, where each step performs a full collection.) You can also +** change this value dynamically. +*/ +#define LUAI_GCMUL 200 /* GC runs 'twice the speed' of memory allocation */ + + + +/* +@@ LUA_COMPAT_GETN controls compatibility with old getn behavior. +** CHANGE it (define it) if you want exact compatibility with the +** behavior of setn/getn in Lua 5.0. +*/ +#undef LUA_COMPAT_GETN + +/* +@@ LUA_COMPAT_LOADLIB controls compatibility about global loadlib. +** CHANGE it to undefined as soon as you do not need a global 'loadlib' +** function (the function is still available as 'package.loadlib'). +*/ +#undef LUA_COMPAT_LOADLIB + +/* +@@ LUA_COMPAT_VARARG controls compatibility with old vararg feature. +** CHANGE it to undefined as soon as your programs use only '...' to +** access vararg parameters (instead of the old 'arg' table). +*/ +#undef LUA_COMPAT_VARARG + +/* +@@ LUA_COMPAT_MOD controls compatibility with old math.mod function. +** CHANGE it to undefined as soon as your programs use 'math.fmod' or +** the new '%' operator instead of 'math.mod'. +*/ +#undef LUA_COMPAT_MOD + +/* +@@ LUA_COMPAT_LSTR controls compatibility with old long string nesting +@* facility. +** CHANGE it to 2 if you want the old behaviour, or undefine it to turn +** off the advisory error when nesting [[...]]. +*/ +#define LUA_COMPAT_LSTR 1 + +/* +@@ LUA_COMPAT_GFIND controls compatibility with old 'string.gfind' name. +** CHANGE it to undefined as soon as you rename 'string.gfind' to +** 'string.gmatch'. +*/ +#undef LUA_COMPAT_GFIND + +/* +@@ LUA_COMPAT_OPENLIB controls compatibility with old 'luaL_openlib' +@* behavior. +** CHANGE it to undefined as soon as you replace to 'luaL_register' +** your uses of 'luaL_openlib' +*/ +#undef LUA_COMPAT_OPENLIB + + + +/* +@@ luai_apicheck is the assert macro used by the Lua-C API. +** CHANGE luai_apicheck if you want Lua to perform some checks in the +** parameters it gets from API calls. This may slow down the interpreter +** a bit, but may be quite useful when debugging C code that interfaces +** with Lua. A useful redefinition is to use assert.h. +*/ +#if defined(LUA_USE_APICHECK) +#include +#define luai_apicheck(L,o) { (void)L; assert(o); } +#else +#define luai_apicheck(L,o) { (void)L; } +#endif + + +/* +@@ LUAI_BITSINT defines the number of bits in an int. +** CHANGE here if Lua cannot automatically detect the number of bits of +** your machine. Probably you do not need to change this. +*/ +/* avoid overflows in comparison */ +#if INT_MAX-20 < 32760 +#define LUAI_BITSINT 16 +#elif INT_MAX > 2147483640L +/* int has at least 32 bits */ +#define LUAI_BITSINT 32 +#else +#error "you must define LUA_BITSINT with number of bits in an integer" +#endif + + +/* +@@ LUAI_UINT32 is an unsigned integer with at least 32 bits. +@@ LUAI_INT32 is an signed integer with at least 32 bits. +@@ LUAI_UMEM is an unsigned integer big enough to count the total +@* memory used by Lua. +@@ LUAI_MEM is a signed integer big enough to count the total memory +@* used by Lua. +** CHANGE here if for some weird reason the default definitions are not +** good enough for your machine. (The definitions in the 'else' +** part always works, but may waste space on machines with 64-bit +** longs.) Probably you do not need to change this. +*/ +#if LUAI_BITSINT >= 32 +#define LUAI_UINT32 unsigned int +#define LUAI_INT32 int +#define LUAI_MAXINT32 INT_MAX +#define LUAI_UMEM size_t +#define LUAI_MEM ptrdiff_t +#else +/* 16-bit ints */ +#define LUAI_UINT32 unsigned long +#define LUAI_INT32 long +#define LUAI_MAXINT32 LONG_MAX +#define LUAI_UMEM unsigned long +#define LUAI_MEM long +#endif + + +/* +@@ LUAI_MAXCALLS limits the number of nested calls. +** CHANGE it if you need really deep recursive calls. This limit is +** arbitrary; its only purpose is to stop infinite recursion before +** exhausting memory. +*/ +#define LUAI_MAXCALLS 20000 + + +/* +@@ LUAI_MAXCSTACK limits the number of Lua stack slots that a C function +@* can use. +** CHANGE it if you need lots of (Lua) stack space for your C +** functions. This limit is arbitrary; its only purpose is to stop C +** functions to consume unlimited stack space. (must be smaller than +** -LUA_REGISTRYINDEX) +*/ +#define LUAI_MAXCSTACK 8000 + + + +/* +** {================================================================== +** CHANGE (to smaller values) the following definitions if your system +** has a small C stack. (Or you may want to change them to larger +** values if your system has a large C stack and these limits are +** too rigid for you.) Some of these constants control the size of +** stack-allocated arrays used by the compiler or the interpreter, while +** others limit the maximum number of recursive calls that the compiler +** or the interpreter can perform. Values too large may cause a C stack +** overflow for some forms of deep constructs. +** =================================================================== +*/ + + +/* +@@ LUAI_MAXCCALLS is the maximum depth for nested C calls (short) and +@* syntactical nested non-terminals in a program. +*/ +#define LUAI_MAXCCALLS 200 + + +/* +@@ LUAI_MAXVARS is the maximum number of local variables per function +@* (must be smaller than 250). +*/ +#define LUAI_MAXVARS 200 + + +/* +@@ LUAI_MAXUPVALUES is the maximum number of upvalues per function +@* (must be smaller than 250). +*/ +#define LUAI_MAXUPVALUES 60 + + +/* +@@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system. +*/ +#define LUAL_BUFFERSIZE BUFSIZ + +/* }================================================================== */ + + + + +/* +** {================================================================== +@@ LUA_NUMBER is the type of numbers in Lua. +** CHANGE the following definitions only if you want to build Lua +** with a number type different from double. You may also need to +** change lua_number2int & lua_number2integer. +** =================================================================== +*/ + +//#define LUA_NUMBER_DOUBLE +#define LUA_NUMBER ptrdiff_t + +/* +@@ LUAI_UACNUMBER is the result of an 'usual argument conversion' +@* over a number. +*/ +#define LUAI_UACNUMBER ptrdiff_t + + +/* +@@ LUA_NUMBER_SCAN is the format for reading numbers. +@@ LUA_NUMBER_FMT is the format for writing numbers. +@@ lua_number2str converts a number to a string. +@@ LUAI_MAXNUMBER2STR is maximum size of previous conversion. +@@ lua_str2number converts a string to a number. +*/ +#ifdef LUA_WIN + #define LUA_NUMBER_SCAN "%Ii" + #define LUA_NUMBER_FMT "%Ii" +#else + #define LUA_NUMBER_SCAN "%ti" + #define LUA_NUMBER_FMT "%ti" +#endif +#define lua_number2str(s,n) sprintf((s), LUA_NUMBER_FMT, (n)) +#define LUAI_MAXNUMBER2STR 32 /* 16 digits, sign, point, and \0 */ +#define lua_str2number(s,p) strtol((s), (p), 10) + + +/* +@@ The luai_num* macros define the primitive operations over numbers. +*/ +#if defined(LUA_CORE) +#include +#define luai_numadd(a,b) ((a)+(b)) +#define luai_numsub(a,b) ((a)-(b)) +#define luai_nummul(a,b) ((a)*(b)) +#define luai_numdiv(a,b) ((a)/(b)) +#define luai_nummod(a,b) (lua_Number)((a)%(b)) +#define luai_numpow(a,b) (float)(pow((double)(a),(double)(b))) +#define luai_numunm(a) (-(a)) +#define luai_numeq(a,b) ((a)==(b)) +#define luai_numlt(a,b) ((a)<(b)) +#define luai_numle(a,b) ((a)<=(b)) +#define luai_numisnan(a) (!luai_numeq((a), (a))) +#define luai_numand(a,b) ((unsigned)(a)&(unsigned)(b)) +#define luai_numor(a,b) ((unsigned)(a)|(unsigned)(b)) +#define luai_numxor(a,b) (((unsigned)(a))^((unsigned)(b))) +#define luai_numshl(a,b) ((unsigned)(a)<<(unsigned)(b)) +#define luai_numshr(a,b) ((unsigned)(a)>>(unsigned)(b)) +#define luai_numnot(a) (~((unsigned)(a))) +#ifdef _MSC_VER +#pragma warning(disable : 4244) +#endif +#endif + + +/* +@@ lua_number2int is a macro to convert lua_Number to int. +@@ lua_number2integer is a macro to convert lua_Number to lua_Integer. +** CHANGE them if you know a faster way to convert a lua_Number to +** int (with any rounding method and without throwing errors) in your +** system. In Pentium machines, a naive typecast from double to int +** in C is extremely slow, so any alternative is worth trying. +*/ + +/* On a Pentium, resort to a trick */ +#if defined(LUA_NUMBER_DOUBLE) && !defined(LUA_ANSI) && !defined(__SSE2__) && \ + (defined(__i386) || defined (_M_IX86) || defined(__i386__)) + +/* On a Microsoft compiler, use assembler */ +#if defined(_MSC_VER) + +#define lua_number2int(i,d) __asm fld d __asm fistp i +#define lua_number2integer(i,n) lua_number2int(i, n) + +/* the next trick should work on any Pentium, but sometimes clashes + with a DirectX idiosyncrasy */ +#else + +union luai_Cast { double l_d; long l_l; }; +#define lua_number2int(i,d) \ + { volatile union luai_Cast u; u.l_d = (d) + 6755399441055744.0; (i) = u.l_l; } +#define lua_number2integer(i,n) lua_number2int(i, n) + +#endif + + +/* this option always works, but may be slow */ +#else +#define lua_number2int(i,d) ((i)=(int)(d)) +#define lua_number2integer(i,d) ((i)=(lua_Integer)(d)) + +#endif + +/* }================================================================== */ + + +/* +@@ LUAI_USER_ALIGNMENT_T is a type that requires maximum alignment. +** CHANGE it if your system requires alignments larger than double. (For +** instance, if your system supports long doubles and they must be +** aligned in 16-byte boundaries, then you should add long double in the +** union.) Probably you do not need to change this. +*/ +#define LUAI_USER_ALIGNMENT_T union { double u; void *s; long l; } + + +/* +@@ LUAI_THROW/LUAI_TRY define how Lua does exception handling. +** CHANGE them if you prefer to use longjmp/setjmp even with C++ +** or if want/don't to use _longjmp/_setjmp instead of regular +** longjmp/setjmp. By default, Lua handles errors with exceptions when +** compiling as C++ code, with _longjmp/_setjmp when asked to use them, +** and with longjmp/setjmp otherwise. +*/ +#if defined(__cplusplus) +/* C++ exceptions */ +#define LUAI_THROW(L,c) throw(c) +#define LUAI_TRY(L,c,a) try { a } catch(...) \ + { if ((c)->status == 0) (c)->status = -1; } +#define luai_jmpbuf int /* dummy variable */ + +#elif defined(LUA_USE_ULONGJMP) +/* in Unix, try _longjmp/_setjmp (more efficient) */ +#define LUAI_THROW(L,c) _longjmp((c)->b, 1) +#define LUAI_TRY(L,c,a) if (_setjmp((c)->b) == 0) { a } +#define luai_jmpbuf jmp_buf + +#else +/* default handling with long jumps */ +#define LUAI_THROW(L,c) longjmp((c)->b, 1) +#define LUAI_TRY(L,c,a) if (setjmp((c)->b) == 0) { a } +#define luai_jmpbuf jmp_buf + +#endif + + +/* +@@ LUA_MAXCAPTURES is the maximum number of captures that a pattern +@* can do during pattern-matching. +** CHANGE it if you need more captures. This limit is arbitrary. +*/ +#define LUA_MAXCAPTURES 32 + + +/* +@@ lua_tmpnam is the function that the OS library uses to create a +@* temporary name. +@@ LUA_TMPNAMBUFSIZE is the maximum size of a name created by lua_tmpnam. +** CHANGE them if you have an alternative to tmpnam (which is considered +** insecure) or if you want the original tmpnam anyway. By default, Lua +** uses tmpnam except when POSIX is available, where it uses mkstemp. +*/ +#if defined(loslib_c) || defined(luaall_c) + +#if defined(LUA_USE_MKSTEMP) +#include +#define LUA_TMPNAMBUFSIZE 32 +#define lua_tmpnam(b,e) { \ + strcpy(b, "/tmp/lua_XXXXXX"); \ + e = mkstemp(b); \ + if (e != -1) close(e); \ + e = (e == -1); } + +#else +#define LUA_TMPNAMBUFSIZE L_tmpnam +#define lua_tmpnam(b,e) { e = (tmpnam(b) == NULL); } +#endif + +#endif + + +/* +@@ lua_popen spawns a new process connected to the current one through +@* the file streams. +** CHANGE it if you have a way to implement it in your system. +*/ +#if defined(LUA_USE_POPEN) + +#define lua_popen(L,c,m) ((void)L, fflush(NULL), popen(c,m)) +#define lua_pclose(L,file) ((void)L, (pclose(file) != -1)) + +#elif defined(LUA_WIN) + +#define lua_popen(L,c,m) ((void)L, _popen(c,m)) +#define lua_pclose(L,file) ((void)L, (_pclose(file) != -1)) + +#else + +#define lua_popen(L,c,m) ((void)((void)c, m), \ + luaL_error(L, LUA_QL("popen") " not supported"), (FILE*)0) +#define lua_pclose(L,file) ((void)((void)L, file), 0) + +#endif + +/* +@@ LUA_DL_* define which dynamic-library system Lua should use. +** CHANGE here if Lua has problems choosing the appropriate +** dynamic-library system for your platform (either Windows' DLL, Mac's +** dyld, or Unix's dlopen). If your system is some kind of Unix, there +** is a good chance that it has dlopen, so LUA_DL_DLOPEN will work for +** it. To use dlopen you also need to adapt the src/Makefile (probably +** adding -ldl to the linker options), so Lua does not select it +** automatically. (When you change the makefile to add -ldl, you must +** also add -DLUA_USE_DLOPEN.) +** If you do not want any kind of dynamic library, undefine all these +** options. +** By default, _WIN32 gets LUA_DL_DLL and MAC OS X gets LUA_DL_DYLD. +*/ +#if defined(LUA_USE_DLOPEN) +#define LUA_DL_DLOPEN +#endif + +#if defined(LUA_WIN) +#define LUA_DL_DLL +#endif + + +/* +@@ LUAI_EXTRASPACE allows you to add user-specific data in a lua_State +@* (the data goes just *before* the lua_State pointer). +** CHANGE (define) this if you really need that. This value must be +** a multiple of the maximum alignment required for your machine. +*/ +#define LUAI_EXTRASPACE 0 + + +/* +@@ luai_userstate* allow user-specific actions on threads. +** CHANGE them if you defined LUAI_EXTRASPACE and need to do something +** extra when a thread is created/deleted/resumed/yielded. +*/ +#define luai_userstateopen(L) ((void)L) +#define luai_userstateclose(L) ((void)L) +#define luai_userstatethread(L,L1) ((void)L) +#define luai_userstatefree(L) ((void)L) +#define luai_userstateresume(L,n) ((void)L) +#define luai_userstateyield(L,n) ((void)L) + + +/* +@@ LUA_INTFRMLEN is the length modifier for integer conversions +@* in 'string.format'. +@@ LUA_INTFRM_T is the integer type correspoding to the previous length +@* modifier. +** CHANGE them if your system supports long long or does not support long. +*/ + +#if defined(LUA_USELONGLONG) + +#define LUA_INTFRMLEN "ll" +#define LUA_INTFRM_T long long + +#else + +#define LUA_INTFRMLEN "l" +#define LUA_INTFRM_T long + +#endif + + + +/* =================================================================== */ + +/* +** Local configuration. You can use this space to add your redefinitions +** without modifying the main part of the file. +*/ + + + +#endif diff --git a/src/blua/lualib.h b/src/blua/lualib.h new file mode 100644 index 000000000..6ebe27287 --- /dev/null +++ b/src/blua/lualib.h @@ -0,0 +1,38 @@ +/* +** $Id: lualib.h,v 1.36.1.1 2007/12/27 13:02:25 roberto Exp $ +** Lua standard libraries +** See Copyright Notice in lua.h +*/ + + +#ifndef lualib_h +#define lualib_h + +#include "lua.h" + + +/* Key to file-handle type */ +#define LUA_FILEHANDLE "FILE*" + + +#define LUA_COLIBNAME "coroutine" +LUALIB_API int (luaopen_base) (lua_State *L); + +#define LUA_TABLIBNAME "table" +LUALIB_API int (luaopen_table) (lua_State *L); + +#define LUA_STRLIBNAME "string" +LUALIB_API int (luaopen_string) (lua_State *L); + + +/* open all previous libraries */ +LUALIB_API void (luaL_openlibs) (lua_State *L); + + + +#ifndef lua_assert +#define lua_assert(x) ((void)0) +#endif + + +#endif diff --git a/src/blua/lundump.c b/src/blua/lundump.c new file mode 100644 index 000000000..0b7ca0e36 --- /dev/null +++ b/src/blua/lundump.c @@ -0,0 +1,229 @@ +/* +** $Id: lundump.c,v 2.7.1.4 2008/04/04 19:51:41 roberto Exp $ +** load precompiled Lua chunks +** See Copyright Notice in lua.h +*/ + +#include + +#define lundump_c +#define LUA_CORE + +#include "lua.h" + +#include "ldebug.h" +#include "ldo.h" +#include "lfunc.h" +#include "lmem.h" +#include "lobject.h" +#include "lstring.h" +#include "lundump.h" +#include "lzio.h" + +typedef struct { + lua_State* L; + ZIO* Z; + Mbuffer* b; + const char* name; +} LoadState; + +#ifdef LUAC_TRUST_BINARIES +#define IF(c,s) +#define error(S,s) +#else +#define IF(c,s) if (c) error(S,s) + +static void error(LoadState* S, const char* why) +{ + luaO_pushfstring(S->L,"%s: %s in precompiled chunk",S->name,why); + luaD_throw(S->L,LUA_ERRSYNTAX); +} +#endif + +#define LoadMem(S,b,n,size) LoadBlock(S,b,(n)*(size)) +#define LoadByte(S) (lu_byte)LoadChar(S) +#define LoadVar(S,x) LoadMem(S,&x,1,sizeof(x)) +#define LoadVector(S,b,n,size) LoadMem(S,b,n,size) + +static void LoadBlock(LoadState* S, void* b, size_t size) +{ + size_t r=luaZ_read(S->Z,b,size); + IF (r!=0, "unexpected end"); +} + +static int LoadChar(LoadState* S) +{ + char x; + LoadVar(S,x); + return x; +} + +static int LoadInt(LoadState* S) +{ + int x; + LoadVar(S,x); + IF (x<0, "bad integer"); + return x; +} + +static lua_Number LoadNumber(LoadState* S) +{ + lua_Number x; + LoadVar(S,x); + return x; +} + +static TString* LoadString(LoadState* S) +{ + size_t size; + LoadVar(S,size); + if (size==0) + return NULL; + else + { + char* s=luaZ_openspace(S->L,S->b,size); + LoadBlock(S,s,size); + return luaS_newlstr(S->L,s,size-1); /* remove trailing '\0' */ + } +} + +static void LoadCode(LoadState* S, Proto* f) +{ + int n=LoadInt(S); + f->code=luaM_newvector(S->L,n,Instruction); + f->sizecode=n; + LoadVector(S,f->code,n,sizeof(Instruction)); +} + +static Proto* LoadFunction(LoadState* S, TString* p); + +static void LoadConstants(LoadState* S, Proto* f) +{ + int i,n; + n=LoadInt(S); + f->k=luaM_newvector(S->L,n,TValue); + f->sizek=n; + for (i=0; ik[i]); + for (i=0; ik[i]; + int t=LoadChar(S); + switch (t) + { + case LUA_TNIL: + setnilvalue(o); + break; + case LUA_TBOOLEAN: + setbvalue(o,LoadChar(S)!=0); + break; + case LUA_TNUMBER: + setnvalue(o,LoadNumber(S)); + break; + case LUA_TSTRING: + setsvalue2n(S->L,o,LoadString(S)); + break; + default: + error(S,"bad constant"); + break; + } + } + n=LoadInt(S); + f->p=luaM_newvector(S->L,n,Proto*); + f->sizep=n; + for (i=0; ip[i]=NULL; + for (i=0; ip[i]=LoadFunction(S,f->source); +} + +static void LoadDebug(LoadState* S, Proto* f) +{ + int i,n; + n=LoadInt(S); + f->lineinfo=luaM_newvector(S->L,n,int); + f->sizelineinfo=n; + LoadVector(S,f->lineinfo,n,sizeof(int)); + n=LoadInt(S); + f->locvars=luaM_newvector(S->L,n,LocVar); + f->sizelocvars=n; + for (i=0; ilocvars[i].varname=NULL; + for (i=0; ilocvars[i].varname=LoadString(S); + f->locvars[i].startpc=LoadInt(S); + f->locvars[i].endpc=LoadInt(S); + } + n=LoadInt(S); + f->upvalues=luaM_newvector(S->L,n,TString*); + f->sizeupvalues=n; + for (i=0; iupvalues[i]=NULL; + for (i=0; iupvalues[i]=LoadString(S); +} + +static Proto* LoadFunction(LoadState* S, TString* p) +{ + Proto* f; + if (++S->L->nCcalls > LUAI_MAXCCALLS) error(S,"code too deep"); + f=luaF_newproto(S->L); + setptvalue2s(S->L,S->L->top,f); incr_top(S->L); + f->source=LoadString(S); if (f->source==NULL) f->source=p; + f->linedefined=LoadInt(S); + f->lastlinedefined=LoadInt(S); + f->nups=LoadByte(S); + f->numparams=LoadByte(S); + f->is_vararg=LoadByte(S); + f->maxstacksize=LoadByte(S); + LoadCode(S,f); + LoadConstants(S,f); + LoadDebug(S,f); + IF (!luaG_checkcode(f), "bad code"); + S->L->top--; + S->L->nCcalls--; + return f; +} + +#ifdef LUA_ALLOW_BYTECODE +static void LoadHeader(LoadState* S) +{ + char h[LUAC_HEADERSIZE]; + char s[LUAC_HEADERSIZE]; + luaU_header(h); + LoadBlock(S,s,LUAC_HEADERSIZE); + IF (memcmp(h,s,LUAC_HEADERSIZE)!=0, "bad header"); +} + +/* +** load precompiled chunk +*/ +Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name) +{ + LoadState S; + if (*name=='@' || *name=='=') + S.name=name+1; + else if (*name==LUA_SIGNATURE[0]) + S.name="binary string"; + else + S.name=name; + S.L=L; + S.Z=Z; + S.b=buff; + LoadHeader(&S); + return LoadFunction(&S,luaS_newliteral(L,"=?")); +} +#endif + +/* +* make header +*/ +void luaU_header (char* h) +{ + int x=1; + memcpy(h,LUA_SIGNATURE,sizeof(LUA_SIGNATURE)-1); + h+=sizeof(LUA_SIGNATURE)-1; + *h++=(char)LUAC_VERSION; + *h++=(char)LUAC_FORMAT; + *h++=(char)*(char*)&x; /* endianness */ + *h++=(char)sizeof(int); + *h++=(char)sizeof(size_t); + *h++=(char)sizeof(Instruction); + *h++=(char)sizeof(lua_Number); + *h++=(char)(((lua_Number)0.5L)==0); /* is lua_Number integral? */ +} diff --git a/src/blua/lundump.h b/src/blua/lundump.h new file mode 100644 index 000000000..54a7b1a78 --- /dev/null +++ b/src/blua/lundump.h @@ -0,0 +1,38 @@ +/* +** $Id: lundump.h,v 1.37.1.1 2007/12/27 13:02:25 roberto Exp $ +** load precompiled Lua chunks +** See Copyright Notice in lua.h +*/ + +#ifndef lundump_h +#define lundump_h + +#include "lobject.h" +#include "lzio.h" + +#ifdef LUA_ALLOW_BYTECODE +/* load one chunk; from lundump.c */ +LUAI_FUNC Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name); +#endif + +/* make header; from lundump.c */ +LUAI_FUNC void luaU_header (char* h); + +/* dump one chunk; from ldump.c */ +LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip); + +#ifdef luac_c +/* print one chunk; from print.c */ +LUAI_FUNC void luaU_print (const Proto* f, int full); +#endif + +/* for header of binary files -- this is Lua 5.1 */ +#define LUAC_VERSION 0x51 + +/* for header of binary files -- this is the official format */ +#define LUAC_FORMAT 0 + +/* size of header of binary files */ +#define LUAC_HEADERSIZE 12 + +#endif diff --git a/src/blua/lvm.c b/src/blua/lvm.c new file mode 100644 index 000000000..17764846e --- /dev/null +++ b/src/blua/lvm.c @@ -0,0 +1,812 @@ +/* +** $Id: lvm.c,v 2.63.1.3 2007/12/28 15:32:23 roberto Exp $ +** Lua virtual machine +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include + +#define lvm_c +#define LUA_CORE + +#include "lua.h" + +#include "ldebug.h" +#include "ldo.h" +#include "lfunc.h" +#include "lgc.h" +#include "lobject.h" +#include "lopcodes.h" +#include "lstate.h" +#include "lstring.h" +#include "ltable.h" +#include "ltm.h" +#include "lvm.h" + + + +/* limit for table tag-method chains (to avoid loops) */ +#define MAXTAGLOOP 100 + + +const TValue *luaV_tonumber (const TValue *obj, TValue *n) { + lua_Number num; + if (ttisnumber(obj)) return obj; + if (ttisstring(obj) && luaO_str2d(svalue(obj), &num)) { + setnvalue(n, num); + return n; + } + else + return NULL; +} + + +int luaV_tostring (lua_State *L, StkId obj) { + if (!ttisnumber(obj)) + return 0; + else { + char s[LUAI_MAXNUMBER2STR]; + lua_Number n = nvalue(obj); + lua_number2str(s, n); + setsvalue2s(L, obj, luaS_new(L, s)); + return 1; + } +} + + +static void traceexec (lua_State *L, const Instruction *pc) { + lu_byte mask = L->hookmask; + const Instruction *oldpc = L->savedpc; + L->savedpc = pc; + if ((mask & LUA_MASKCOUNT) && L->hookcount == 0) { + resethookcount(L); + luaD_callhook(L, LUA_HOOKCOUNT, -1); + } + if (mask & LUA_MASKLINE) { + Proto *p = ci_func(L->ci)->l.p; + int npc = pcRel(pc, p); + int newline = getline(p, npc); + /* call linehook when enter a new function, when jump back (loop), + or when enter a new line */ + if (npc == 0 || pc <= oldpc || newline != getline(p, pcRel(oldpc, p))) + luaD_callhook(L, LUA_HOOKLINE, newline); + } +} + + +static void callTMres (lua_State *L, StkId res, const TValue *f, + const TValue *p1, const TValue *p2) { + ptrdiff_t result = savestack(L, res); + setobj2s(L, L->top, f); /* push function */ + setobj2s(L, L->top+1, p1); /* 1st argument */ + setobj2s(L, L->top+2, p2); /* 2nd argument */ + luaD_checkstack(L, 3); + L->top += 3; + luaD_call(L, L->top - 3, 1); + res = restorestack(L, result); + L->top--; + setobjs2s(L, res, L->top); +} + + + +static void callTM (lua_State *L, const TValue *f, const TValue *p1, + const TValue *p2, const TValue *p3) { + setobj2s(L, L->top, f); /* push function */ + setobj2s(L, L->top+1, p1); /* 1st argument */ + setobj2s(L, L->top+2, p2); /* 2nd argument */ + setobj2s(L, L->top+3, p3); /* 3th argument */ + luaD_checkstack(L, 4); + L->top += 4; + luaD_call(L, L->top - 4, 0); +} + + +void luaV_gettable (lua_State *L, TValue *t, TValue *key, StkId val) { + int loop; + for (loop = 0; loop < MAXTAGLOOP; loop++) { + TValue *tm; + if (ttistable(t)) { /* `t' is a table? */ + Table *h = hvalue(t); + const TValue *res = luaH_get(h, key); /* do a primitive get */ + if (!ttisnil(res) || /* result is no nil? */ + (tm = fasttm(L, h->metatable, TM_INDEX)) == NULL) { /* or no TM? */ + setobj2s(L, val, res); + return; + } + /* else will try the tag method */ + } + else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_INDEX))) + luaG_typeerror(L, t, "index"); + if (ttisfunction(tm)) { + callTMres(L, val, tm, t, key); + return; + } + t = tm; /* else repeat with `tm' */ + } + luaG_runerror(L, "loop in gettable"); +} + + +void luaV_settable (lua_State *L, TValue *t, TValue *key, StkId val) { + int loop; + for (loop = 0; loop < MAXTAGLOOP; loop++) { + TValue *tm; + if (ttistable(t)) { /* `t' is a table? */ + Table *h = hvalue(t); + TValue *oldval = luaH_set(L, h, key); /* do a primitive set */ + /* oldval is nil=> look for newindex, oldval is not nil => look for usedindex */ + if (!((ttisnil(oldval) && ((tm = fasttm(L, h->metatable, TM_NEWINDEX)) != NULL)) || + ((!ttisnil(oldval)) && ((tm = fasttm(L, h->metatable, TM_USEDINDEX)) != NULL)))) { + setobj2t(L, oldval, val); + luaC_barriert(L, h, val); + return; + } + /* else will try the tag method */ + } + else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_NEWINDEX))) + luaG_typeerror(L, t, "index"); + if (ttisfunction(tm)) { + callTM(L, tm, t, key, val); + return; + } + t = tm; /* else repeat with `tm' */ + } + luaG_runerror(L, "loop in settable"); +} + + +static int call_binTM (lua_State *L, TValue *p1, TValue *p2, + StkId res, TMS event) { + const TValue *tm = luaT_gettmbyobj(L, p1, event); /* try first operand */ + if (ttisnil(tm)) + tm = luaT_gettmbyobj(L, p2, event); /* try second operand */ + if (ttisnil(tm)) return 0; + callTMres(L, res, tm, p1, p2); + return 1; +} + + +static const TValue *get_compTM (lua_State *L, Table *mt1, Table *mt2, + TMS event) { + const TValue *tm1 = fasttm(L, mt1, event); + const TValue *tm2; + if (tm1 == NULL) return NULL; /* no metamethod */ + if (mt1 == mt2) return tm1; /* same metatables => same metamethods */ + tm2 = fasttm(L, mt2, event); + if (tm2 == NULL) return NULL; /* no metamethod */ + if (luaO_rawequalObj(tm1, tm2)) /* same metamethods? */ + return tm1; + return NULL; +} + + +static int call_orderTM (lua_State *L, TValue *p1, TValue *p2, + TMS event) { + const TValue *tm1 = luaT_gettmbyobj(L, p1, event); + const TValue *tm2; + if (ttisnil(tm1)) return -1; /* no metamethod? */ + tm2 = luaT_gettmbyobj(L, p2, event); + if (!luaO_rawequalObj(tm1, tm2)) /* different metamethods? */ + return -1; + callTMres(L, L->top, tm1, p1, p2); + return !l_isfalse(L->top); +} + + +static int l_strcmp (const TString *ls, const TString *rs) { + const char *l = getstr(ls); + size_t ll = ls->tsv.len; + const char *r = getstr(rs); + size_t lr = rs->tsv.len; + for (;;) { + int temp = strcoll(l, r); + if (temp != 0) return temp; + else { /* strings are equal up to a `\0' */ + size_t len = strlen(l); /* index of first `\0' in both strings */ + if (len == lr) /* r is finished? */ + return (len == ll) ? 0 : 1; + else if (len == ll) /* l is finished? */ + return -1; /* l is smaller than r (because r is not finished) */ + /* both strings longer than `len'; go on comparing (after the `\0') */ + len++; + l += len; ll -= len; r += len; lr -= len; + } + } +} + + +int luaV_lessthan (lua_State *L, TValue *l, TValue *r) { + int res; + if (ttype(l) != ttype(r)) + return luaG_ordererror(L, l, r); + else if (ttisnumber(l)) + return luai_numlt(nvalue(l), nvalue(r)); + else if (ttisstring(l)) + return l_strcmp(rawtsvalue(l), rawtsvalue(r)) < 0; + else if ((res = call_orderTM(L, l, r, TM_LT)) != -1) + return res; + return luaG_ordererror(L, l, r); +} + + +static int lessequal (lua_State *L, TValue *l, TValue *r) { + int res; + if (ttype(l) != ttype(r)) + return luaG_ordererror(L, l, r); + else if (ttisnumber(l)) + return luai_numle(nvalue(l), nvalue(r)); + else if (ttisstring(l)) + return l_strcmp(rawtsvalue(l), rawtsvalue(r)) <= 0; + else if ((res = call_orderTM(L, l, r, TM_LE)) != -1) /* first try `le' */ + return res; + else if ((res = call_orderTM(L, r, l, TM_LT)) != -1) /* else try `lt' */ + return !res; + return luaG_ordererror(L, l, r); +} + + +int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2) { + const TValue *tm; + lua_assert(ttype(t1) == ttype(t2)); + switch (ttype(t1)) { + case LUA_TNIL: return 1; + case LUA_TNUMBER: return luai_numeq(nvalue(t1), nvalue(t2)); + case LUA_TBOOLEAN: return bvalue(t1) == bvalue(t2); /* true must be 1 !! */ + case LUA_TLIGHTUSERDATA: return pvalue(t1) == pvalue(t2); + case LUA_TUSERDATA: { + if (uvalue(t1) == uvalue(t2)) return 1; + tm = get_compTM(L, uvalue(t1)->metatable, uvalue(t2)->metatable, + TM_EQ); + break; /* will try TM */ + } + case LUA_TTABLE: { + if (hvalue(t1) == hvalue(t2)) return 1; + tm = get_compTM(L, hvalue(t1)->metatable, hvalue(t2)->metatable, TM_EQ); + break; /* will try TM */ + } + default: return gcvalue(t1) == gcvalue(t2); + } + if (tm == NULL) return 0; /* no TM? */ + callTMres(L, L->top, tm, t1, t2); /* call TM */ + return !l_isfalse(L->top); +} + + +void luaV_concat (lua_State *L, int total, int last) { + do { + StkId top = L->base + last + 1; + int n = 2; /* number of elements handled in this pass (at least 2) */ + if (!(ttisstring(top-2) || ttisnumber(top-2)) || !tostring(L, top-1)) { + if (!call_binTM(L, top-2, top-1, top-2, TM_CONCAT)) + luaG_concaterror(L, top-2, top-1); + } else if (tsvalue(top-1)->len == 0) /* second op is empty? */ + (void)tostring(L, top - 2); /* result is first op (as string) */ + else { + /* at least two string values; get as many as possible */ + size_t tl = tsvalue(top-1)->len; + char *buffer; + int i; + /* collect total length */ + for (n = 1; n < total && tostring(L, top-n-1); n++) { + size_t l = tsvalue(top-n-1)->len; + if (l >= MAX_SIZET - tl) luaG_runerror(L, "string length overflow"); + tl += l; + } + buffer = luaZ_openspace(L, &G(L)->buff, tl); + tl = 0; + for (i=n; i>0; i--) { /* concat all strings */ + size_t l = tsvalue(top-i)->len; + memcpy(buffer+tl, svalue(top-i), l); + tl += l; + } + setsvalue2s(L, top-n, luaS_newlstr(L, buffer, tl)); + } + total -= n-1; /* got `n' strings to create 1 new */ + last -= n-1; + } while (total > 1); /* repeat until only 1 result left */ +} + + +static void Arith (lua_State *L, StkId ra, TValue *rb, + TValue *rc, TMS op) { + TValue tempb, tempc; + const TValue *b, *c; + if ((b = luaV_tonumber(rb, &tempb)) != NULL && + (c = luaV_tonumber(rc, &tempc)) != NULL) { + lua_Number nb = nvalue(b), nc = nvalue(c); + switch (op) { + case TM_ADD: setnvalue(ra, luai_numadd(nb, nc)); break; + case TM_SUB: setnvalue(ra, luai_numsub(nb, nc)); break; + case TM_MUL: setnvalue(ra, luai_nummul(nb, nc)); break; + case TM_DIV: if (nc == 0) { lua_pushliteral(L, "divide by zero error"); lua_error(L); } else setnvalue(ra, luai_numdiv(nb, nc)); break; + case TM_MOD: setnvalue(ra, luai_nummod(nb, nc)); break; + case TM_POW: setnvalue(ra, luai_numpow(nb, nc)); break; + case TM_UNM: setnvalue(ra, luai_numunm(nb)); break; + case TM_AND: setnvalue(ra, luai_numand(nb, nc)); break; + case TM_OR: setnvalue(ra, luai_numor(nb, nc)); break; + case TM_XOR: setnvalue(ra, luai_numxor(nb, nc)); break; + case TM_SHL: setnvalue(ra, luai_numshl(nb, nc)); break; + case TM_SHR: setnvalue(ra, luai_numshr(nb, nc)); break; + case TM_NOT: setnvalue(ra, luai_numnot(nb)); break; + default: lua_assert(0); break; + } + } + else if (!call_binTM(L, rb, rc, ra, op)) + luaG_aritherror(L, rb, rc); +} + + + +/* +** some macros for common tasks in `luaV_execute' +*/ + +#define runtime_check(L, c) { if (!(c)) break; } + +#define RA(i) (base+GETARG_A(i)) +/* to be used after possible stack reallocation */ +#define RB(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgR, base+GETARG_B(i)) +#define RC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgR, base+GETARG_C(i)) +#define RKB(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgK, \ + ISK(GETARG_B(i)) ? k+INDEXK(GETARG_B(i)) : base+GETARG_B(i)) +#define RKC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgK, \ + ISK(GETARG_C(i)) ? k+INDEXK(GETARG_C(i)) : base+GETARG_C(i)) +#define KBx(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgK, k+GETARG_Bx(i)) + + +#define dojump(L,pc,i) {(pc) += (i); luai_threadyield(L);} + + +#define Protect(x) { L->savedpc = pc; {x;}; base = L->base; } + + +#define arith_op(op,tm) { \ + TValue *rb = RKB(i); \ + TValue *rc = RKC(i); \ + if (ttisnumber(rb) && ttisnumber(rc)) { \ + lua_Number nb = nvalue(rb), nc = nvalue(rc); \ + setnvalue(ra, op(nb, nc)); \ + } \ + else \ + Protect(Arith(L, ra, rb, rc, tm)); \ + } + + + +void luaV_execute (lua_State *L, int nexeccalls) { + LClosure *cl; + StkId base; + TValue *k; + const Instruction *pc; + reentry: /* entry point */ + lua_assert(isLua(L->ci)); + pc = L->savedpc; + cl = &clvalue(L->ci->func)->l; + base = L->base; + k = cl->p->k; + /* main loop of interpreter */ + for (;;) { + const Instruction i = *pc++; + StkId ra; + if ((L->hookmask & (LUA_MASKLINE | LUA_MASKCOUNT)) && + (--L->hookcount == 0 || L->hookmask & LUA_MASKLINE)) { + traceexec(L, pc); + if (L->status == LUA_YIELD) { /* did hook yield? */ + L->savedpc = pc - 1; + return; + } + base = L->base; + } + /* warning!! several calls may realloc the stack and invalidate `ra' */ + ra = RA(i); + lua_assert(base == L->base && L->base == L->ci->base); + lua_assert(base <= L->top && L->top <= L->stack + L->stacksize); + lua_assert(L->top == L->ci->top || luaG_checkopenop(i)); + switch (GET_OPCODE(i)) { + case OP_MOVE: { + setobjs2s(L, ra, RB(i)); + continue; + } + case OP_LOADK: { + setobj2s(L, ra, KBx(i)); + continue; + } + case OP_LOADBOOL: { + setbvalue(ra, GETARG_B(i)); + if (GETARG_C(i)) pc++; /* skip next instruction (if C) */ + continue; + } + case OP_LOADNIL: { + TValue *rb = RB(i); + do { + setnilvalue(rb--); + } while (rb >= ra); + continue; + } + case OP_GETUPVAL: { + int b = GETARG_B(i); + setobj2s(L, ra, cl->upvals[b]->v); + continue; + } + case OP_GETGLOBAL: { + TValue g; + TValue *rb = KBx(i); + sethvalue(L, &g, cl->env); + lua_assert(ttisstring(rb)); + Protect(luaV_gettable(L, &g, rb, ra)); + continue; + } + case OP_GETTABLE: { + Protect(luaV_gettable(L, RB(i), RKC(i), ra)); + continue; + } + case OP_SETGLOBAL: { + TValue g; + sethvalue(L, &g, cl->env); + lua_assert(ttisstring(KBx(i))); + Protect(luaV_settable(L, &g, KBx(i), ra)); + continue; + } + case OP_SETUPVAL: { + UpVal *uv = cl->upvals[GETARG_B(i)]; + setobj(L, uv->v, ra); + luaC_barrier(L, uv, ra); + continue; + } + case OP_SETTABLE: { + Protect(luaV_settable(L, ra, RKB(i), RKC(i))); + continue; + } + case OP_NEWTABLE: { + int b = GETARG_B(i); + int c = GETARG_C(i); + sethvalue(L, ra, luaH_new(L, luaO_fb2int(b), luaO_fb2int(c))); + Protect(luaC_checkGC(L)); + continue; + } + case OP_SELF: { + StkId rb = RB(i); + setobjs2s(L, ra+1, rb); + Protect(luaV_gettable(L, rb, RKC(i), ra)); + continue; + } + case OP_ADD: { + arith_op(luai_numadd, TM_ADD); + continue; + } + case OP_SUB: { + arith_op(luai_numsub, TM_SUB); + continue; + } + case OP_MUL: { + arith_op(luai_nummul, TM_MUL); + continue; + } + case OP_DIV: { + TValue *rb = RKB(i); + TValue *rc = RKC(i); + if (ttisnumber(rb) && ttisnumber(rc)) { + lua_Number nb = nvalue(rb), nc = nvalue(rc); + if (nc == 0) { + lua_pushliteral(L, "divide by zero error"); + lua_error(L); + } + else + setnvalue(ra, luai_numdiv(nb, nc)); + } + else + Protect(Arith(L, ra, rb, rc, TM_DIV)); + continue; + } + case OP_MOD: { + arith_op(luai_nummod, TM_MOD); + continue; + } + case OP_POW: { + arith_op(luai_numpow, TM_POW); + continue; + } + case OP_BAND: { + arith_op(luai_numand, TM_AND); + continue; + } + case OP_BOR: { + arith_op(luai_numor, TM_OR); + continue; + } + case OP_BXOR: { + arith_op(luai_numxor, TM_XOR); + continue; + } + case OP_BSHL: { + arith_op(luai_numshl, TM_SHL); + continue; + } + case OP_BSHR: { + arith_op(luai_numshr, TM_SHR); + continue; + } + case OP_BNOT: { + TValue *rb = RB(i); + if (ttisnumber(rb)) { + lua_Number nb = nvalue(rb); + setnvalue(ra, luai_numnot(nb)); + } + else { + Protect(Arith(L, ra, rb, rb, TM_NOT)); + } + continue; + } + case OP_UNM: { + TValue *rb = RB(i); + if (ttisnumber(rb)) { + lua_Number nb = nvalue(rb); + setnvalue(ra, luai_numunm(nb)); + } + else { + Protect(Arith(L, ra, rb, rb, TM_UNM)); + } + continue; + } + case OP_NOT: { + int res = l_isfalse(RB(i)); /* next assignment may change this value */ + setbvalue(ra, res); + continue; + } + case OP_LEN: { + TValue *rb = RB(i); + switch (ttype(rb)) { + case LUA_TTABLE: { + setnvalue(ra, cast_num(luaH_getn(hvalue(rb)))); + break; + } + case LUA_TSTRING: { + setnvalue(ra, cast_num(tsvalue(rb)->len)); + break; + } + default: { /* try metamethod */ + Protect( + if (!call_binTM(L, rb, luaO_nilobject, ra, TM_LEN)) + luaG_typeerror(L, rb, "get length of"); + ) + } + } + continue; + } + case OP_CONCAT: { + int b = GETARG_B(i); + int c = GETARG_C(i); + Protect(luaV_concat(L, c-b+1, c); luaC_checkGC(L)); + setobjs2s(L, RA(i), base+b); + continue; + } + case OP_JMP: { + dojump(L, pc, GETARG_sBx(i)); + continue; + } + case OP_EQ: { + TValue *rb = RKB(i); + TValue *rc = RKC(i); + Protect( + if (equalobj(L, rb, rc) == GETARG_A(i)) + dojump(L, pc, GETARG_sBx(*pc)); + ) + pc++; + continue; + } + case OP_LT: { + Protect( + if (luaV_lessthan(L, RKB(i), RKC(i)) == GETARG_A(i)) + dojump(L, pc, GETARG_sBx(*pc)); + ) + pc++; + continue; + } + case OP_LE: { + Protect( + if (lessequal(L, RKB(i), RKC(i)) == GETARG_A(i)) + dojump(L, pc, GETARG_sBx(*pc)); + ) + pc++; + continue; + } + case OP_TEST: { + if (l_isfalse(ra) != GETARG_C(i)) + dojump(L, pc, GETARG_sBx(*pc)); + pc++; + continue; + } + case OP_TESTSET: { + TValue *rb = RB(i); + if (l_isfalse(rb) != GETARG_C(i)) { + setobjs2s(L, ra, rb); + dojump(L, pc, GETARG_sBx(*pc)); + } + pc++; + continue; + } + case OP_CALL: { + int b = GETARG_B(i); + int nresults = GETARG_C(i) - 1; + if (b != 0) L->top = ra+b; /* else previous instruction set top */ + L->savedpc = pc; + switch (luaD_precall(L, ra, nresults)) { + case PCRLUA: { + nexeccalls++; + goto reentry; /* restart luaV_execute over new Lua function */ + } + case PCRC: { + /* it was a C function (`precall' called it); adjust results */ + if (nresults >= 0) L->top = L->ci->top; + base = L->base; + continue; + } + default: { + return; /* yield */ + } + } + } + case OP_TAILCALL: { + int b = GETARG_B(i); + if (b != 0) L->top = ra+b; /* else previous instruction set top */ + L->savedpc = pc; + lua_assert(GETARG_C(i) - 1 == LUA_MULTRET); + switch (luaD_precall(L, ra, LUA_MULTRET)) { + case PCRLUA: { + /* tail call: put new frame in place of previous one */ + CallInfo *ci = L->ci - 1; /* previous frame */ + int aux; + StkId func = ci->func; + StkId pfunc = (ci+1)->func; /* previous function index */ + if (L->openupval) luaF_close(L, ci->base); + L->base = ci->base = ci->func + ((ci+1)->base - pfunc); + for (aux = 0; pfunc+aux < L->top; aux++) /* move frame down */ + setobjs2s(L, func+aux, pfunc+aux); + ci->top = L->top = func+aux; /* correct top */ + lua_assert(L->top == L->base + clvalue(func)->l.p->maxstacksize); + ci->savedpc = L->savedpc; + ci->tailcalls++; /* one more call lost */ + L->ci--; /* remove new frame */ + goto reentry; + } + case PCRC: { /* it was a C function (`precall' called it) */ + base = L->base; + continue; + } + default: { + return; /* yield */ + } + } + } + case OP_RETURN: { + int b = GETARG_B(i); + if (b != 0) L->top = ra+b-1; + if (L->openupval) luaF_close(L, base); + L->savedpc = pc; + b = luaD_poscall(L, ra); + if (--nexeccalls == 0) /* was previous function running `here'? */ + return; /* no: return */ + else { /* yes: continue its execution */ + if (b) L->top = L->ci->top; + lua_assert(isLua(L->ci)); + lua_assert(GET_OPCODE(*((L->ci)->savedpc - 1)) == OP_CALL); + goto reentry; + } + } + case OP_FORLOOP: { + lua_Number step = nvalue(ra+2); + lua_Number idx = luai_numadd(nvalue(ra), step); /* increment index */ + lua_Number limit = nvalue(ra+1); + if (luai_numlt(0, step) ? luai_numle(idx, limit) + : luai_numle(limit, idx)) { + dojump(L, pc, GETARG_sBx(i)); /* jump back */ + setnvalue(ra, idx); /* update internal index... */ + setnvalue(ra+3, idx); /* ...and external index */ + } + continue; + } + case OP_FORPREP: { + const TValue *init = ra; + const TValue *plimit = ra+1; + const TValue *pstep = ra+2; + L->savedpc = pc; /* next steps may throw errors */ + if (!tonumber(init, ra)) + luaG_runerror(L, LUA_QL("for") " initial value must be a number"); + else if (!tonumber(plimit, ra+1)) + luaG_runerror(L, LUA_QL("for") " limit must be a number"); + else if (!tonumber(pstep, ra+2)) + luaG_runerror(L, LUA_QL("for") " step must be a number"); + setnvalue(ra, luai_numsub(nvalue(ra), nvalue(pstep))); + dojump(L, pc, GETARG_sBx(i)); + continue; + } + case OP_TFORLOOP: { + StkId cb = ra + 3; /* call base */ + setobjs2s(L, cb+2, ra+2); + setobjs2s(L, cb+1, ra+1); + setobjs2s(L, cb, ra); + L->top = cb+3; /* func. + 2 args (state and index) */ + Protect(luaD_call(L, cb, GETARG_C(i))); + L->top = L->ci->top; + cb = RA(i) + 3; /* previous call may change the stack */ + if (!ttisnil(cb)) { /* continue loop? */ + setobjs2s(L, cb-1, cb); /* save control variable */ + dojump(L, pc, GETARG_sBx(*pc)); /* jump back */ + } + pc++; + continue; + } + case OP_SETLIST: { + int n = GETARG_B(i); + int c = GETARG_C(i); + int last; + Table *h; + if (n == 0) { + n = cast_int(L->top - ra) - 1; + L->top = L->ci->top; + } + if (c == 0) c = cast_int(*pc++); + runtime_check(L, ttistable(ra)); + h = hvalue(ra); + last = ((c-1)*LFIELDS_PER_FLUSH) + n; + if (last > h->sizearray) /* needs more space? */ + luaH_resizearray(L, h, last); /* pre-alloc it at once */ + for (; n > 0; n--) { + TValue *val = ra+n; + setobj2t(L, luaH_setnum(L, h, last--), val); + luaC_barriert(L, h, val); + } + continue; + } + case OP_CLOSE: { + luaF_close(L, ra); + continue; + } + case OP_CLOSURE: { + Proto *p; + Closure *ncl; + int nup, j; + p = cl->p->p[GETARG_Bx(i)]; + nup = p->nups; + ncl = luaF_newLclosure(L, nup, cl->env); + ncl->l.p = p; + for (j=0; jl.upvals[j] = cl->upvals[GETARG_B(*pc)]; + else { + lua_assert(GET_OPCODE(*pc) == OP_MOVE); + ncl->l.upvals[j] = luaF_findupval(L, base + GETARG_B(*pc)); + } + } + setclvalue(L, ra, ncl); + Protect(luaC_checkGC(L)); + continue; + } + case OP_VARARG: { + int b = GETARG_B(i) - 1; + int j; + CallInfo *ci = L->ci; + int n = cast_int(ci->base - ci->func) - cl->p->numparams - 1; + if (b == LUA_MULTRET) { + Protect(luaD_checkstack(L, n)); + ra = RA(i); /* previous call may change the stack */ + b = n; + L->top = ra + n; + } + for (j = 0; j < b; j++) { + if (j < n) { + setobjs2s(L, ra + j, ci->base - n + j); + } + else { + setnilvalue(ra + j); + } + } + continue; + } + } + } +} diff --git a/src/blua/lvm.h b/src/blua/lvm.h new file mode 100644 index 000000000..f9226ee5d --- /dev/null +++ b/src/blua/lvm.h @@ -0,0 +1,36 @@ +/* +** $Id: lvm.h,v 2.5.1.1 2007/12/27 13:02:25 roberto Exp $ +** Lua virtual machine +** See Copyright Notice in lua.h +*/ + +#ifndef lvm_h +#define lvm_h + + +#include "ldo.h" +#include "lobject.h" +#include "ltm.h" + + +#define tostring(L,o) ((ttype(o) == LUA_TSTRING) || (luaV_tostring(L, o))) + +#define tonumber(o,n) (ttype(o) == LUA_TNUMBER || \ + (((o) = luaV_tonumber(o,n)) != NULL)) + +#define equalobj(L,o1,o2) \ + (ttype(o1) == ttype(o2) && luaV_equalval(L, o1, o2)) + + +LUAI_FUNC int luaV_lessthan (lua_State *L, TValue *l, TValue *r); +LUAI_FUNC int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2); +LUAI_FUNC const TValue *luaV_tonumber (const TValue *obj, TValue *n); +LUAI_FUNC int luaV_tostring (lua_State *L, StkId obj); +LUAI_FUNC void luaV_gettable (lua_State *L, TValue *t, TValue *key, + StkId val); +LUAI_FUNC void luaV_settable (lua_State *L, TValue *t, TValue *key, + StkId val); +LUAI_FUNC void luaV_execute (lua_State *L, int nexeccalls); +LUAI_FUNC void luaV_concat (lua_State *L, int total, int last); + +#endif diff --git a/src/blua/lzio.c b/src/blua/lzio.c new file mode 100644 index 000000000..4c6f8908d --- /dev/null +++ b/src/blua/lzio.c @@ -0,0 +1,80 @@ +/* +** $Id: lzio.c,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $ +** a generic input stream interface +** See Copyright Notice in lua.h +*/ + + +#include + +#define lzio_c +#define LUA_CORE + +#include "lua.h" + +#include "llimits.h" +#include "lmem.h" +#include "lstate.h" +#include "lzio.h" + + +int luaZ_fill (ZIO *z) { + size_t size; + lua_State *L = z->L; + const char *buff; + lua_unlock(L); + buff = z->reader(L, z->data, &size); + lua_lock(L); + if (buff == NULL || size == 0) return EOZ; + z->n = size - 1; + z->p = buff; + return char2int(*(z->p++)); +} + + +int luaZ_lookahead (ZIO *z) { + if (z->n == 0) { + if (luaZ_fill(z) == EOZ) + return EOZ; + else { + z->n++; /* luaZ_fill removed first byte; put back it */ + z->p--; + } + } + return char2int(*z->p); +} + + +void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) { + z->L = L; + z->reader = reader; + z->data = data; + z->n = 0; + z->p = NULL; +} + + +/* --------------------------------------------------------------- read --- */ +size_t luaZ_read (ZIO *z, void *b, size_t n) { + while (n) { + size_t m; + if (luaZ_lookahead(z) == EOZ) + return n; /* return number of missing bytes */ + m = (n <= z->n) ? n : z->n; /* min. between n and z->n */ + memcpy(b, z->p, m); + z->n -= m; + z->p += m; + b = (char *)b + m; + n -= m; + } + return 0; +} + +/* ------------------------------------------------------------------------ */ +char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n) { + if (n > buff->buffsize) { + if (n < LUA_MINBUFFER) n = LUA_MINBUFFER; + luaZ_resizebuffer(L, buff, n); + } + return buff->buffer; +} diff --git a/src/blua/lzio.h b/src/blua/lzio.h new file mode 100644 index 000000000..51d695d8c --- /dev/null +++ b/src/blua/lzio.h @@ -0,0 +1,67 @@ +/* +** $Id: lzio.h,v 1.21.1.1 2007/12/27 13:02:25 roberto Exp $ +** Buffered streams +** See Copyright Notice in lua.h +*/ + + +#ifndef lzio_h +#define lzio_h + +#include "lua.h" + +#include "lmem.h" + + +#define EOZ (-1) /* end of stream */ + +typedef struct Zio ZIO; + +#define char2int(c) cast(int, cast(unsigned char, (c))) + +#define zgetc(z) (((z)->n--)>0 ? char2int(*(z)->p++) : luaZ_fill(z)) + +typedef struct Mbuffer { + char *buffer; + size_t n; + size_t buffsize; +} Mbuffer; + +#define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0) + +#define luaZ_buffer(buff) ((buff)->buffer) +#define luaZ_sizebuffer(buff) ((buff)->buffsize) +#define luaZ_bufflen(buff) ((buff)->n) + +#define luaZ_resetbuffer(buff) ((buff)->n = 0) + + +#define luaZ_resizebuffer(L, buff, size) \ + (luaM_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), \ + (buff)->buffsize = size) + +#define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0) + + +LUAI_FUNC char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n); +LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, + void *data); +LUAI_FUNC size_t luaZ_read (ZIO* z, void* b, size_t n); /* read next n bytes */ +LUAI_FUNC int luaZ_lookahead (ZIO *z); + + + +/* --------- Private Part ------------------ */ + +struct Zio { + size_t n; /* bytes still unread */ + const char *p; /* current position in buffer */ + lua_Reader reader; + void* data; /* additional data */ + lua_State *L; /* Lua state (for reader) */ +}; + + +LUAI_FUNC int luaZ_fill (ZIO *z); + +#endif diff --git a/src/byteptr.h b/src/byteptr.h new file mode 100644 index 000000000..352c4d7b9 --- /dev/null +++ b/src/byteptr.h @@ -0,0 +1,173 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Copyright (C) 1999-2014 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file byteptr.h +/// \brief Macros to read/write from/to a UINT8 *, +/// used for packet creation and such + +#if defined (__alpha__) || defined (__arm__) || defined (__mips__) || defined (__ia64__) || defined (__clang__) +#define DEALIGNED +#endif + +#ifndef _BIG_ENDIAN +// +// Little-endian machines +// +#ifdef DEALIGNED +#define WRITEUINT8(p,b) do { UINT8 *p_tmp = (void *)p; const UINT8 tv = ( UINT8)(b); memcpy(p, &tv, sizeof( UINT8)); p_tmp++; p = (void *)p_tmp; } while (0) +#define WRITESINT8(p,b) do { SINT8 *p_tmp = (void *)p; const SINT8 tv = ( UINT8)(b); memcpy(p, &tv, sizeof( UINT8)); p_tmp++; p = (void *)p_tmp; } while (0) +#define WRITEINT16(p,b) do { INT16 *p_tmp = (void *)p; const INT16 tv = ( INT16)(b); memcpy(p, &tv, sizeof( INT16)); p_tmp++; p = (void *)p_tmp; } while (0) +#define WRITEUINT16(p,b) do { UINT16 *p_tmp = (void *)p; const UINT16 tv = ( UINT16)(b); memcpy(p, &tv, sizeof( UINT16)); p_tmp++; p = (void *)p_tmp; } while (0) +#define WRITEINT32(p,b) do { INT32 *p_tmp = (void *)p; const INT32 tv = ( INT32)(b); memcpy(p, &tv, sizeof( INT32)); p_tmp++; p = (void *)p_tmp; } while (0) +#define WRITEUINT32(p,b) do { UINT32 *p_tmp = (void *)p; const UINT32 tv = ( UINT32)(b); memcpy(p, &tv, sizeof( UINT32)); p_tmp++; p = (void *)p_tmp; } while (0) +#define WRITECHAR(p,b) do { char *p_tmp = (void *)p; const char tv = ( char)(b); memcpy(p, &tv, sizeof( char)); p_tmp++; p = (void *)p_tmp; } while (0) +#define WRITEFIXED(p,b) do { fixed_t *p_tmp = (void *)p; const fixed_t tv = (fixed_t)(b); memcpy(p, &tv, sizeof(fixed_t)); p_tmp++; p = (void *)p_tmp; } while (0) +#define WRITEANGLE(p,b) do { angle_t *p_tmp = (void *)p; const angle_t tv = (angle_t)(b); memcpy(p, &tv, sizeof(angle_t)); p_tmp++; p = (void *)p_tmp; } while (0) +#else +#define WRITEUINT8(p,b) do { UINT8 *p_tmp = ( UINT8 *)p; *p_tmp = ( UINT8)(b); p_tmp++; p = (void *)p_tmp; } while (0) +#define WRITESINT8(p,b) do { SINT8 *p_tmp = ( SINT8 *)p; *p_tmp = ( SINT8)(b); p_tmp++; p = (void *)p_tmp; } while (0) +#define WRITEINT16(p,b) do { INT16 *p_tmp = ( INT16 *)p; *p_tmp = ( INT16)(b); p_tmp++; p = (void *)p_tmp; } while (0) +#define WRITEUINT16(p,b) do { UINT16 *p_tmp = ( UINT16 *)p; *p_tmp = ( UINT16)(b); p_tmp++; p = (void *)p_tmp; } while (0) +#define WRITEINT32(p,b) do { INT32 *p_tmp = ( INT32 *)p; *p_tmp = ( INT32)(b); p_tmp++; p = (void *)p_tmp; } while (0) +#define WRITEUINT32(p,b) do { UINT32 *p_tmp = ( UINT32 *)p; *p_tmp = ( UINT32)(b); p_tmp++; p = (void *)p_tmp; } while (0) +#define WRITECHAR(p,b) do { char *p_tmp = ( char *)p; *p_tmp = ( char)(b); p_tmp++; p = (void *)p_tmp; } while (0) +#define WRITEFIXED(p,b) do { fixed_t *p_tmp = (fixed_t *)p; *p_tmp = (fixed_t)(b); p_tmp++; p = (void *)p_tmp; } while (0) +#define WRITEANGLE(p,b) do { angle_t *p_tmp = (angle_t *)p; *p_tmp = (angle_t)(b); p_tmp++; p = (void *)p_tmp; } while (0) +#endif + +#ifdef __GNUC__ +#ifdef DEALIGNED +#define READUINT8(p) ({ UINT8 *p_tmp = (void *)p; UINT8 b; memcpy(&b, p, sizeof( UINT8)); p_tmp++; p = (void *)p_tmp; b; }) +#define READSINT8(p) ({ SINT8 *p_tmp = (void *)p; SINT8 b; memcpy(&b, p, sizeof( SINT8)); p_tmp++; p = (void *)p_tmp; b; }) +#define READINT16(p) ({ INT16 *p_tmp = (void *)p; INT16 b; memcpy(&b, p, sizeof( INT16)); p_tmp++; p = (void *)p_tmp; b; }) +#define READUINT16(p) ({ UINT16 *p_tmp = (void *)p; UINT16 b; memcpy(&b, p, sizeof( UINT16)); p_tmp++; p = (void *)p_tmp; b; }) +#define READINT32(p) ({ INT32 *p_tmp = (void *)p; INT32 b; memcpy(&b, p, sizeof( INT32)); p_tmp++; p = (void *)p_tmp; b; }) +#define READUINT32(p) ({ UINT32 *p_tmp = (void *)p; UINT32 b; memcpy(&b, p, sizeof( UINT32)); p_tmp++; p = (void *)p_tmp; b; }) +#define READCHAR(p) ({ char *p_tmp = (void *)p; char b; memcpy(&b, p, sizeof( char)); p_tmp++; p = (void *)p_tmp; b; }) +#define READFIXED(p) ({ fixed_t *p_tmp = (void *)p; fixed_t b; memcpy(&b, p, sizeof(fixed_t)); p_tmp++; p = (void *)p_tmp; b; }) +#define READANGLE(p) ({ angle_t *p_tmp = (void *)p; angle_t b; memcpy(&b, p, sizeof(angle_t)); p_tmp++; p = (void *)p_tmp; b; }) +#else +#define READUINT8(p) ({ UINT8 *p_tmp = ( UINT8 *)p; UINT8 b = *p_tmp; p_tmp++; p = (void *)p_tmp; b; }) +#define READSINT8(p) ({ SINT8 *p_tmp = ( SINT8 *)p; SINT8 b = *p_tmp; p_tmp++; p = (void *)p_tmp; b; }) +#define READINT16(p) ({ INT16 *p_tmp = ( INT16 *)p; INT16 b = *p_tmp; p_tmp++; p = (void *)p_tmp; b; }) +#define READUINT16(p) ({ UINT16 *p_tmp = ( UINT16 *)p; UINT16 b = *p_tmp; p_tmp++; p = (void *)p_tmp; b; }) +#define READINT32(p) ({ INT32 *p_tmp = ( INT32 *)p; INT32 b = *p_tmp; p_tmp++; p = (void *)p_tmp; b; }) +#define READUINT32(p) ({ UINT32 *p_tmp = ( UINT32 *)p; UINT32 b = *p_tmp; p_tmp++; p = (void *)p_tmp; b; }) +#define READCHAR(p) ({ char *p_tmp = ( char *)p; char b = *p_tmp; p_tmp++; p = (void *)p_tmp; b; }) +#define READFIXED(p) ({ fixed_t *p_tmp = (fixed_t *)p; fixed_t b = *p_tmp; p_tmp++; p = (void *)p_tmp; b; }) +#define READANGLE(p) ({ angle_t *p_tmp = (angle_t *)p; angle_t b = *p_tmp; p_tmp++; p = (void *)p_tmp; b; }) +#endif +#else +#define READUINT8(p) *(( UINT8 *)p)++ +#define READSINT8(p) *(( SINT8 *)p)++ +#define READINT16(p) *(( INT16 *)p)++ +#define READUINT16(p) *(( UINT16 *)p)++ +#define READINT32(p) *(( INT32 *)p)++ +#define READUINT32(p) *(( UINT32 *)p)++ +#define READCHAR(p) *(( char *)p)++ +#define READFIXED(p) *((fixed_t *)p)++ +#define READANGLE(p) *((angle_t *)p)++ +#endif + +#else //_BIG_ENDIAN +// +// definitions for big-endian machines with alignment constraints. +// +// Write a value to a little-endian, unaligned destination. +// +FUNCINLINE static ATTRINLINE void writeshort(void *ptr, INT32 val) +{ + SINT8 *cp = ptr; + cp[0] = val; val >>= 8; + cp[1] = val; +} + +FUNCINLINE static ATTRINLINE void writelong(void *ptr, INT32 val) +{ + SINT8 *cp = ptr; + cp[0] = val; val >>= 8; + cp[1] = val; val >>= 8; + cp[2] = val; val >>= 8; + cp[3] = val; +} + +#define WRITEUINT8(p,b) do { UINT8 *p_tmp = ( UINT8 *)p; *p_tmp = ( UINT8)(b) ; p_tmp++; p = (void *)p_tmp;} while (0) +#define WRITESINT8(p,b) do { SINT8 *p_tmp = ( SINT8 *)p; *p_tmp = ( SINT8)(b) ; p_tmp++; p = (void *)p_tmp;} while (0) +#define WRITEINT16(p,b) do { INT16 *p_tmp = ( INT16 *)p; writeshort (p, ( INT16)(b)); p_tmp++; p = (void *)p_tmp;} while (0) +#define WRITEUINT16(p,b) do { UINT16 *p_tmp = ( UINT16 *)p; writeshort (p, ( UINT16)(b)); p_tmp++; p = (void *)p_tmp;} while (0) +#define WRITEINT32(p,b) do { INT32 *p_tmp = ( INT32 *)p; writelong (p, ( INT32)(b)); p_tmp++; p = (void *)p_tmp;} while (0) +#define WRITEUINT32(p,b) do { UINT32 *p_tmp = ( UINT32 *)p; writelong (p, ( UINT32)(b)); p_tmp++; p = (void *)p_tmp;} while (0) +#define WRITECHAR(p,b) do { char *p_tmp = ( char *)p; *p_tmp = ( char)(b) ; p_tmp++; p = (void *)p_tmp;} while (0) +#define WRITEFIXED(p,b) do {fixed_t *p_tmp = (fixed_t *)p; writelong (p, (fixed_t)(b)); p_tmp++; p = (void *)p_tmp;} while (0) +#define WRITEANGLE(p,b) do {angle_t *p_tmp = (angle_t *)p; writelong (p, (angle_t)(b)); p_tmp++; p = (void *)p_tmp;} while (0) + +// Read a signed quantity from little-endian, unaligned data. +// +FUNCINLINE static ATTRINLINE INT16 readshort(void *ptr) +{ + SINT8 *cp = ptr; + UINT8 *ucp = ptr; + return (cp[1] << 8) | ucp[0]; +} + +FUNCINLINE static ATTRINLINE UINT16 readushort(void *ptr) +{ + UINT8 *ucp = ptr; + return (ucp[1] << 8) | ucp[0]; +} + +FUNCINLINE static ATTRINLINE INT32 readlong(void *ptr) +{ + SINT8 *cp = ptr; + UINT8 *ucp = ptr; + return (cp[3] << 24) | (ucp[2] << 16) | (ucp[1] << 8) | ucp[0]; +} + +FUNCINLINE static ATTRINLINE UINT32 readulong(void *ptr) +{ + UINT8 *ucp = ptr; + return (ucp[3] << 24) | (ucp[2] << 16) | (ucp[1] << 8) | ucp[0]; +} + +#define READUINT8(p) ({ UINT8 *p_tmp = ( UINT8 *)p; UINT8 b = *p_tmp; p_tmp++; p = (void *)p_tmp; b; }) +#define READSINT8(p) ({ SINT8 *p_tmp = ( SINT8 *)p; SINT8 b = *p_tmp; p_tmp++; p = (void *)p_tmp; b; }) +#define READINT16(p) ({ INT16 *p_tmp = ( INT16 *)p; INT16 b = readshort(p); p_tmp++; p = (void *)p_tmp; b; }) +#define READUINT16(p) ({ UINT16 *p_tmp = ( UINT16 *)p; UINT16 b = readushort(p); p_tmp++; p = (void *)p_tmp; b; }) +#define READINT32(p) ({ INT32 *p_tmp = ( INT32 *)p; INT32 b = readlong(p); p_tmp++; p = (void *)p_tmp; b; }) +#define READUINT32(p) ({ UINT32 *p_tmp = ( UINT32 *)p; UINT32 b = readulong(p); p_tmp++; p = (void *)p_tmp; b; }) +#define READCHAR(p) ({ char *p_tmp = ( char *)p; char b = *p_tmp; p_tmp++; p = (void *)p_tmp; b; }) +#define READFIXED(p) ({ fixed_t *p_tmp = (fixed_t *)p; fixed_t b = readlong(p); p_tmp++; p = (void *)p_tmp; b; }) +#define READANGLE(p) ({ angle_t *p_tmp = (angle_t *)p; angle_t b = readulong(p); p_tmp++; p = (void *)p_tmp; b; }) +#endif //_BIG_ENDIAN + +#undef DEALIGNED + +#define WRITESTRINGN(p,s,n) { size_t tmp_i = 0; for (; tmp_i < n && s[tmp_i] != '\0'; tmp_i++) WRITECHAR(p, s[tmp_i]); if (tmp_i < n) WRITECHAR(p, '\0');} +#define WRITESTRING(p,s) { size_t tmp_i = 0; for (; s[tmp_i] != '\0'; tmp_i++) WRITECHAR(p, s[tmp_i]); WRITECHAR(p, '\0');} +#define WRITEMEM(p,s,n) { memcpy(p, s, n); p += n; } + +#define SKIPSTRING(p) while (READCHAR(p) != '\0') + +#define READSTRINGN(p,s,n) { size_t tmp_i = 0; for (; tmp_i < n && (s[tmp_i] = READCHAR(p)) != '\0'; tmp_i++); s[tmp_i] = '\0';} +#define READSTRING(p,s) { size_t tmp_i = 0; for (; (s[tmp_i] = READCHAR(p)) != '\0'; tmp_i++); s[tmp_i] = '\0';} +#define READMEM(p,s,n) { memcpy(s, p, n); p += n; } + +#if 0 // old names +#define WRITEBYTE(p,b) WRITEUINT8(p,b) +#define WRITESHORT(p,b) WRITEINT16(p,b) +#define WRITEUSHORT(p,b) WRITEUINT16(p,b) +#define WRITELONG(p,b) WRITEINT32(p,b) +#define WRITEULONG(p,b) WRITEUINT32(p,b) + +#define READBYTE(p) READUINT8(p) +#define READSHORT(p) READINT16(p) +#define READUSHORT(p) READUINT16(p) +#define READLONG(p) READINT32(p) +#define READULONG(p) READUINT32(p) +#endif diff --git a/src/command.c b/src/command.c new file mode 100644 index 000000000..42cabe1b5 --- /dev/null +++ b/src/command.c @@ -0,0 +1,1649 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Copyright (C) 1999-2014 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file command.c +/// \brief Parse and execute commands from console input/scripts and remote server +/// +/// Handles console variables, which is a simplified version +/// of commands, each consvar can have a function called when +/// it is modified.. thus it acts nearly as commands. +/// +/// code shamelessly inspired by the QuakeC sources, thanks Id :) + +#include "doomdef.h" +#include "doomstat.h" +#include "command.h" +#include "console.h" +#include "z_zone.h" +#include "m_menu.h" +#include "m_misc.h" +#include "m_fixed.h" +#include "m_argv.h" +#include "byteptr.h" +#include "p_saveg.h" +#include "g_game.h" // for player_names +#include "d_netcmd.h" +#include "hu_stuff.h" +#include "p_setup.h" +#include "lua_script.h" + +//======== +// protos. +//======== +static boolean COM_Exists(const char *com_name); +static void COM_ExecuteString(char *com_text); + +static void COM_Alias_f(void); +static void COM_Echo_f(void); +static void COM_CEcho_f(void); +static void COM_CEchoFlags_f(void); +static void COM_CEchoDuration_f(void); +static void COM_Exec_f(void); +static void COM_Wait_f(void); +static void COM_Help_f(void); +static void COM_Toggle_f(void); + +static boolean CV_Command(void); +static consvar_t *CV_FindVar(const char *name); +static const char *CV_StringValue(const char *var_name); +static consvar_t *consvar_vars; // list of registered console variables + +static char com_token[1024]; +static char *COM_Parse(char *data); + +CV_PossibleValue_t CV_OnOff[] = {{0, "Off"}, {1, "On"}, {0, NULL}}; +CV_PossibleValue_t CV_YesNo[] = {{0, "No"}, {1, "Yes"}, {0, NULL}}; +CV_PossibleValue_t CV_Unsigned[] = {{0, "MIN"}, {999999999, "MAX"}, {0, NULL}}; +CV_PossibleValue_t CV_Natural[] = {{1, "MIN"}, {999999999, "MAX"}, {0, NULL}}; + +#define COM_BUF_SIZE 8192 // command buffer size + +static INT32 com_wait; // one command per frame (for cmd sequences) + +// command aliases +// +typedef struct cmdalias_s +{ + struct cmdalias_s *next; + char *name; + char *value; // the command string to replace the alias +} cmdalias_t; + +static cmdalias_t *com_alias; // aliases list + +// ========================================================================= +// COMMAND BUFFER +// ========================================================================= + +static vsbuf_t com_text; // variable sized buffer + +/** Adds text into the command buffer for later execution. + * + * \param ptext The text to add. + * \sa COM_BufInsertText + */ +void COM_BufAddText(const char *ptext) +{ + size_t l; + + l = strlen(ptext); + + if (com_text.cursize + l >= com_text.maxsize) + { + CONS_Alert(CONS_WARNING, M_GetText("Command buffer full!\n")); + return; + } + VS_Write(&com_text, ptext, l); +} + +/** Adds command text and executes it immediately. + * + * \param ptext The text to execute. A newline is automatically added. + * \sa COM_BufAddText + */ +void COM_BufInsertText(const char *ptext) +{ + char *temp = NULL; + size_t templen; + + // copy off any commands still remaining in the exec buffer + templen = com_text.cursize; + if (templen) + { + temp = M_Memcpy(ZZ_Alloc(templen), com_text.data, templen); + VS_Clear(&com_text); + } + + // add the entire text of the file (or alias) + COM_BufAddText(ptext); + COM_BufExecute(); // do it right away + + // add the copied off data + if (templen) + { + VS_Write(&com_text, temp, templen); + Z_Free(temp); + } +} + +/** Flushes (executes) console commands in the buffer. + */ +void COM_BufExecute(void) +{ + size_t i; + char *ptext; + char line[1024] = ""; + INT32 quotes; + + if (com_wait) + { + com_wait--; + return; + } + + while (com_text.cursize) + { + // find a '\n' or; line break + ptext = (char *)com_text.data; + + quotes = 0; + for (i = 0; i < com_text.cursize; i++) + { + if (ptext[i] == '\"' && !quotes && i > 0 && ptext[i-1] != ' ') // Malformed command + break; + if (ptext[i] == '\"') + quotes++; + if (!(quotes & 1) && ptext[i] == ';') + break; // don't break if inside a quoted string + if (ptext[i] == '\n' || ptext[i] == '\r') + break; + } + + M_Memcpy(line, ptext, i); + line[i] = 0; + + // flush the command text from the command buffer, _BEFORE_ + // executing, to avoid that 'recursive' aliases overflow the + // command text buffer, in that case, new commands are inserted + // at the beginning, in place of the actual, so it doesn't + // overflow + if (i == com_text.cursize) + // the last command was just flushed + com_text.cursize = 0; + else + { + i++; + com_text.cursize -= i; + //memcpy(ptext, ptext+i, com_text.cursize); // Use memmove if the memory areas do overlap. + memmove(ptext, ptext+i, com_text.cursize); + } + + // execute the command line + COM_ExecuteString(line); + + // delay following commands if a wait was encountered + if (com_wait) + { + com_wait--; + break; + } + } +} + +/** Executes a string immediately. Used for skirting around WAIT commands. + */ +void COM_ImmedExecute(const char *ptext) +{ + size_t i = 0, j = 0; + char line[1024] = ""; + INT32 quotes; + + while (i < strlen(ptext)) + { + + quotes = 0; + for (j = 0; i < strlen(ptext); i++,j++) + { + if (ptext[i] == '\"' && !quotes && i > 0 && ptext[i-1] != ' ') // Malformed command + return; + if (ptext[i] == '\"') + quotes++; + // don't break if inside a quoted string + if ((!(quotes & 1) && ptext[i] == ';') || ptext[i] == '\n' || ptext[i] == '\r') + break; + } + + memcpy(line, ptext+(i-j), j); + line[j] = 0; + + // execute the command line + COM_ExecuteString(line); + + i++; // move to next character + } +} + +// ========================================================================= +// COMMAND EXECUTION +// ========================================================================= + +typedef struct xcommand_s +{ + const char *name; + struct xcommand_s *next; + com_func_t function; +} xcommand_t; + +static xcommand_t *com_commands = NULL; // current commands + +#define MAX_ARGS 80 +static size_t com_argc; +static char *com_argv[MAX_ARGS]; +static const char *com_null_string = ""; +static char *com_args = NULL; // current command args or NULL + +static void Got_NetVar(UINT8 **p, INT32 playernum); + +/** Initializes command buffer and adds basic commands. + */ +void COM_Init(void) +{ + // allocate command buffer + VS_Alloc(&com_text, COM_BUF_SIZE); + + // add standard commands + COM_AddCommand("alias", COM_Alias_f); + COM_AddCommand("echo", COM_Echo_f); + COM_AddCommand("cecho", COM_CEcho_f); + COM_AddCommand("cechoflags", COM_CEchoFlags_f); + COM_AddCommand("cechoduration", COM_CEchoDuration_f); + COM_AddCommand("exec", COM_Exec_f); + COM_AddCommand("wait", COM_Wait_f); + COM_AddCommand("help", COM_Help_f); + COM_AddCommand("toggle", COM_Toggle_f); + RegisterNetXCmd(XD_NETVAR, Got_NetVar); +} + +/** Gets a console command argument count. + * + * \return Number of arguments for the last command. + * \sa COM_Argv + */ +size_t COM_Argc(void) +{ + return com_argc; +} + +/** Gets a console command argument. + * + * \param arg Index of the argument (0 to COM_Argc() - 1). + * \return String pointer to the indicated argument. + * \sa COM_Argc, COM_Args + */ +const char *COM_Argv(size_t arg) +{ + if (arg >= com_argc || (signed)arg < 0) + return com_null_string; + return com_argv[arg]; +} + +/** Gets all console command arguments. + * + * \return String pointer to all arguments for the last command. + * \sa COM_Argv + */ +char *COM_Args(void) +{ + return com_args; +} + +/** Checks if a parameter was passed to a console command. + * + * \param check The parameter to look for, e.g. "-noerror". + * \return The index of the argument containing the parameter, + * or 0 if the parameter was not found. + */ +size_t COM_CheckParm(const char *check) +{ + size_t i; + + for (i = 1; i < com_argc; i++) + if (!strcasecmp(check, com_argv[i])) + return i; + return 0; +} + +/** Parses a string into command-line tokens. + * + * \param ptext A null-terminated string. Does not need to be + * newline-terminated. + */ +static void COM_TokenizeString(char *ptext) +{ + size_t i; + + // Clear the args from the last string. + for (i = 0; i < com_argc; i++) + Z_Free(com_argv[i]); + + com_argc = 0; + com_args = NULL; + + while (com_argc < MAX_ARGS) + { + // Skip whitespace up to a newline. + while (*ptext != '\0' && *ptext <= ' ' && *ptext != '\n') + ptext++; + + // A newline means end of command in buffer, + // thus end of this command's args too. + if (*ptext == '\n' || *ptext == '\0') + break; + + if (com_argc == 1) + com_args = ptext; + + ptext = COM_Parse(ptext); + if (ptext == NULL) + break; + + com_argv[com_argc] = Z_StrDup(com_token); + com_argc++; + } +} + +/** Adds a console command. + * + * \param name Name of the command. + * \param func Function called when the command is run. + */ +void COM_AddCommand(const char *name, com_func_t func) +{ + xcommand_t *cmd; + + // fail if the command is a variable name + if (CV_StringValue(name)[0] != '\0') + { + I_Error("%s is a variable name\n", name); + return; + } + + // fail if the command already exists + for (cmd = com_commands; cmd; cmd = cmd->next) + { + if (!stricmp(name, cmd->name)) //case insensitive now that we have lower and uppercase! + { + I_Error("Command %s already exists\n", name); + return; + } + } + + cmd = ZZ_Alloc(sizeof *cmd); + cmd->name = name; + cmd->function = func; + cmd->next = com_commands; + com_commands = cmd; +} + +/** Tests if a command exists. + * + * \param com_name Name to test for. + * \return True if a command by the given name exists. + */ +static boolean COM_Exists(const char *com_name) +{ + xcommand_t *cmd; + + for (cmd = com_commands; cmd; cmd = cmd->next) + if (!stricmp(com_name, cmd->name)) + return true; + + return false; +} + +/** Does command completion for the console. + * + * \param partial The partial name of the command (potentially). + * \param skips Number of commands to skip. + * \return The complete command name, or NULL. + * \sa CV_CompleteVar + */ +const char *COM_CompleteCommand(const char *partial, INT32 skips) +{ + xcommand_t *cmd; + size_t len; + + len = strlen(partial); + + if (!len) + return NULL; + + // check functions + for (cmd = com_commands; cmd; cmd = cmd->next) + if (!strncmp(partial, cmd->name, len)) + if (!skips--) + return cmd->name; + + return NULL; +} + +/** Parses a single line of text into arguments and tries to execute it. + * The text can come from the command buffer, a remote client, or stdin. + * + * \param ptext A single line of text. + */ +static void COM_ExecuteString(char *ptext) +{ + xcommand_t *cmd; + cmdalias_t *a; + + COM_TokenizeString(ptext); + + // execute the command line + if (COM_Argc() == 0) + return; // no tokens + + // check functions + for (cmd = com_commands; cmd; cmd = cmd->next) + { + if (!stricmp(com_argv[0], cmd->name)) //case insensitive now that we have lower and uppercase! + { + cmd->function(); + return; + } + } + + // check aliases + for (a = com_alias; a; a = a->next) + { + if (!stricmp(com_argv[0], a->name)) + { + COM_BufInsertText(a->value); + return; + } + } + + // check cvars + // Hurdler: added at Ebola's request ;) + // (don't flood the console in software mode with bad gr_xxx command) + if (!CV_Command() && con_destlines) + CONS_Printf(M_GetText("Unknown command '%s'\n"), COM_Argv(0)); +} + +// ========================================================================= +// SCRIPT COMMANDS +// ========================================================================= + +/** Creates a command name that replaces another command. + */ +static void COM_Alias_f(void) +{ + cmdalias_t *a; + char cmd[1024]; + size_t i, c; + + if (COM_Argc() < 3) + { + CONS_Printf(M_GetText("alias : create a shortcut command that executes other command(s)\n")); + return; + } + + a = ZZ_Alloc(sizeof *a); + a->next = com_alias; + com_alias = a; + + a->name = Z_StrDup(COM_Argv(1)); + + // copy the rest of the command line + cmd[0] = 0; // start out with a null string + c = COM_Argc(); + for (i = 2; i < c; i++) + { + strcat(cmd, COM_Argv(i)); + if (i != c) + strcat(cmd, " "); + } + strcat(cmd, "\n"); + + a->value = Z_StrDup(cmd); +} + +/** Prints a line of text to the console. + */ +static void COM_Echo_f(void) +{ + size_t i; + + for (i = 1; i < COM_Argc(); i++) + CONS_Printf("%s ", COM_Argv(i)); + CONS_Printf("\n"); +} + +/** Displays text on the center of the screen for a short time. + */ +static void COM_CEcho_f(void) +{ + size_t i; + char cechotext[1024] = ""; + + for (i = 1; i < COM_Argc(); i++) + { + strncat(cechotext, COM_Argv(i), sizeof(cechotext)-1); + strncat(cechotext, " ", sizeof(cechotext)-1); + } + + cechotext[sizeof(cechotext) - 1] = '\0'; + + HU_DoCEcho(cechotext); +} + +/** Sets drawing flags for the CECHO command. + */ +static void COM_CEchoFlags_f(void) +{ + if (COM_Argc() > 1) + { + const char *arg = COM_Argv(1); + + if (arg[0] && arg[0] == '0' && + arg[1] && arg[1] == 'x') // Use hexadecimal! + HU_SetCEchoFlags(axtoi(arg+2)); + else + HU_SetCEchoFlags(atoi(arg)); + } + else + CONS_Printf(M_GetText("cechoflags : set CEcho flags, prepend with 0x to use hexadecimal")); +} + +/** Sets the duration for CECHO commands to stay on the screen + */ +static void COM_CEchoDuration_f(void) +{ + if (COM_Argc() > 1) + HU_SetCEchoDuration(atoi(COM_Argv(1))); +} + +/** Executes a script file. + */ +static void COM_Exec_f(void) +{ + UINT8 *buf = NULL; + + if (COM_Argc() < 2 || COM_Argc() > 3) + { + CONS_Printf(M_GetText("exec : run a script file\n")); + return; + } + + // load file + FIL_ReadFile(COM_Argv(1), &buf); + + if (!buf) + { + if (!COM_CheckParm("-noerror")) + CONS_Printf(M_GetText("couldn't execute file %s\n"), COM_Argv(1)); + return; + } + + if (!COM_CheckParm("-silent")) + CONS_Printf(M_GetText("executing %s\n"), COM_Argv(1)); + + // insert text file into the command buffer + COM_BufAddText((char *)buf); + COM_BufAddText("\n"); + + // free buffer + Z_Free(buf); +} + +/** Delays execution of the rest of the commands until the next frame. + * Allows sequences of commands like "jump; fire; backward". + */ +static void COM_Wait_f(void) +{ + if (COM_Argc() > 1) + com_wait = atoi(COM_Argv(1)); + else + com_wait = 1; // 1 frame +} + +/** Prints help on variables and commands. + */ +static void COM_Help_f(void) +{ + xcommand_t *cmd; + consvar_t *cvar; + INT32 i = 0; + + if (COM_Argc() > 1) + { + cvar = CV_FindVar(COM_Argv(1)); + if (cvar) + { + CONS_Printf(M_GetText("Variable %s:\n"), cvar->name); + CONS_Printf(M_GetText(" flags :")); + if (cvar->flags & CV_SAVE) + CONS_Printf("AUTOSAVE "); + if (cvar->flags & CV_FLOAT) + CONS_Printf("FLOAT "); + if (cvar->flags & CV_NETVAR) + CONS_Printf("NETVAR "); + if (cvar->flags & CV_CALL) + CONS_Printf("ACTION "); + if (cvar->flags & CV_CHEAT) + CONS_Printf("CHEAT "); + CONS_Printf("\n"); + if (cvar->PossibleValue) + { + if (stricmp(cvar->PossibleValue[0].strvalue, "MIN") == 0) + { + for (i = 1; cvar->PossibleValue[i].strvalue != NULL; i++) + if (!stricmp(cvar->PossibleValue[i].strvalue, "MAX")) + break; + CONS_Printf(M_GetText(" range from %d to %d\n"), cvar->PossibleValue[0].value, + cvar->PossibleValue[i].value); + CONS_Printf(M_GetText(" Current value: %d\n"), cvar->value); + } + else + { + const char *cvalue = NULL; + CONS_Printf(M_GetText(" possible value : %s\n"), cvar->name); + while (cvar->PossibleValue[i].strvalue) + { + CONS_Printf(" %-2d : %s\n", cvar->PossibleValue[i].value, + cvar->PossibleValue[i].strvalue); + if (cvar->PossibleValue[i].value == cvar->value) + cvalue = cvar->PossibleValue[i].strvalue; + i++; + } + if (cvalue) + CONS_Printf(M_GetText(" Current value: %s\n"), cvalue); + else + CONS_Printf(M_GetText(" Current value: %d\n"), cvar->value); + } + } + else + CONS_Printf(M_GetText(" Current value: %d\n"), cvar->value); + } + else + CONS_Printf(M_GetText("No help for this command/variable\n")); + } + else + { + // commands + CONS_Printf("\x82%s", M_GetText("Commands\n")); + for (cmd = com_commands; cmd; cmd = cmd->next) + { + CONS_Printf("%s ",cmd->name); + i++; + } + + // variables + CONS_Printf("\n\x82%s", M_GetText("Variables\n")); + for (cvar = consvar_vars; cvar; cvar = cvar->next) + { + if (!(cvar->flags & CV_NOSHOWHELP)) + CONS_Printf("%s ", cvar->name); + i++; + } + + CONS_Printf("\n\x82%s", M_GetText("Read help file for more or type help \n")); + + CONS_Debug(DBG_GAMELOGIC, "\x82Total : %d\n", i); + } +} + +/** Toggles a console variable. Useful for on/off values. + * + * This works on on/off, yes/no values only + */ +static void COM_Toggle_f(void) +{ + consvar_t *cvar; + + if (COM_Argc() != 2) + { + CONS_Printf(M_GetText("Toggle : Toggle the value of a cvar\n")); + return; + } + cvar = CV_FindVar(COM_Argv(1)); + if (!cvar) + { + CONS_Alert(CONS_NOTICE, M_GetText("%s is not a cvar\n"), COM_Argv(1)); + return; + } + + if (!(cvar->PossibleValue == CV_YesNo || cvar->PossibleValue == CV_OnOff)) + { + CONS_Alert(CONS_NOTICE, M_GetText("%s is not a boolean value\n"), COM_Argv(1)); + return; + } + + // netcvar don't change imediately + cvar->flags |= CV_SHOWMODIFONETIME; + CV_AddValue(cvar, +1); +} + +// ========================================================================= +// VARIABLE SIZE BUFFERS +// ========================================================================= + +/** Initializes a variable size buffer. + * + * \param buf Buffer to initialize. + * \param initsize Initial size for the buffer. + */ +void VS_Alloc(vsbuf_t *buf, size_t initsize) +{ +#define VSBUFMINSIZE 256 + if (initsize < VSBUFMINSIZE) + initsize = VSBUFMINSIZE; + buf->data = Z_Malloc(initsize, PU_STATIC, NULL); + buf->maxsize = initsize; + buf->cursize = 0; +#undef VSBUFMINSIZE +} + +/** Frees a variable size buffer. + * + * \param buf Buffer to free. + */ +void VS_Free(vsbuf_t *buf) +{ + buf->cursize = 0; +} + +/** Clears a variable size buffer. + * + * \param buf Buffer to clear. + */ +void VS_Clear(vsbuf_t *buf) +{ + buf->cursize = 0; +} + +/** Makes sure a variable size buffer has enough space for data of a + * certain length. + * + * \param buf The buffer. It is enlarged if necessary. + * \param length The length of data we need to add. + * \return Pointer to where the new data can go. + */ +void *VS_GetSpace(vsbuf_t *buf, size_t length) +{ + void *data; + + if (buf->cursize + length > buf->maxsize) + { + if (!buf->allowoverflow) + I_Error("overflow 111"); + + if (length > buf->maxsize) + I_Error("overflow l%s 112", sizeu1(length)); + + buf->overflowed = true; + CONS_Printf("VS buffer overflow"); + VS_Clear(buf); + } + + data = buf->data + buf->cursize; + buf->cursize += length; + + return data; +} + +/** Copies data to the end of a variable size buffer. + * + * \param buf The buffer. + * \param data The data to copy. + * \param length The length of the data. + * \sa VS_Print + */ +void VS_Write(vsbuf_t *buf, const void *data, size_t length) +{ + M_Memcpy(VS_GetSpace(buf, length), data, length); +} + +/** Prints text in a variable buffer. Like VS_Write() plus a + * trailing NUL. + * + * \param buf The buffer. + * \param data The NUL-terminated string. + * \sa VS_Write + */ +void VS_Print(vsbuf_t *buf, const char *data) +{ + size_t len; + + len = strlen(data) + 1; + + if (buf->data[buf->cursize-1]) + M_Memcpy((UINT8 *)VS_GetSpace(buf, len), data, len); // no trailing 0 + else + M_Memcpy((UINT8 *)VS_GetSpace(buf, len-1) - 1, data, len); // write over trailing 0 +} + +// ========================================================================= +// +// CONSOLE VARIABLES +// +// console variables are a simple way of changing variables of the game +// through the console or code, at run time. +// +// console vars acts like simplified commands, because a function can be +// attached to them, and called whenever a console var is modified +// +// ========================================================================= + +static const char *cv_null_string = ""; + +/** Searches if a variable has been registered. + * + * \param name Variable to search for. + * \return Pointer to the variable if found, or NULL. + * \sa CV_FindNetVar + */ +static consvar_t *CV_FindVar(const char *name) +{ + consvar_t *cvar; + + for (cvar = consvar_vars; cvar; cvar = cvar->next) + if (!stricmp(name,cvar->name)) + return cvar; + + return NULL; +} + +/** Builds a unique Net Variable identifier number, which is used + * in network packets instead of the full name. + * + * \param s Name of the variable. + * \return A new unique identifier. + * \sa CV_FindNetVar + */ +static inline UINT16 CV_ComputeNetid(const char *s) +{ + UINT16 ret = 0, i = 0; + static UINT16 premiers[16] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53}; + + while (*s) + { + ret = (UINT16)(ret + (*s)*premiers[i]); + s++; + i = (UINT16)((i+1) % 16); + } + return ret; +} + +/** Finds a net variable based on its identifier number. + * + * \param netid The variable's identifier number. + * \return A pointer to the variable itself if found, or NULL. + * \sa CV_ComputeNetid + */ +static consvar_t *CV_FindNetVar(UINT16 netid) +{ + consvar_t *cvar; + + for (cvar = consvar_vars; cvar; cvar = cvar->next) + if (cvar->netid == netid) + return cvar; + + return NULL; +} + +static void Setvalue(consvar_t *var, const char *valstr, boolean stealth); + +/** Registers a variable for later use from the console. + * + * \param variable The variable to register. + */ +void CV_RegisterVar(consvar_t *variable) +{ + // first check to see if it has already been defined + if (CV_FindVar(variable->name)) + { + CONS_Printf(M_GetText("Variable %s is already defined\n"), variable->name); + return; + } + + // check for overlap with a command + if (COM_Exists(variable->name)) + { + CONS_Printf(M_GetText("%s is a command name\n"), variable->name); + return; + } + + // check net variables + if (variable->flags & CV_NETVAR) + { + variable->netid = CV_ComputeNetid(variable->name); + if (CV_FindNetVar(variable->netid)) + I_Error("Variables %s and %s have same netid\n", variable->name, CV_FindNetVar(variable->netid)->name); + } + + // link the variable in + if (!(variable->flags & CV_HIDEN)) + { + variable->next = consvar_vars; + consvar_vars = variable; + } + variable->string = variable->zstring = NULL; + variable->changed = 0; // new variable has not been modified by the user + +#ifdef PARANOIA + if ((variable->flags & CV_NOINIT) && !(variable->flags & CV_CALL)) + I_Error("variable %s has CV_NOINIT without CV_CALL\n", variable->name); + if ((variable->flags & CV_CALL) && !variable->func) + I_Error("variable %s has CV_CALL without a function\n", variable->name); +#endif + + if (variable->flags & CV_NOINIT) + variable->flags &= ~CV_CALL; + + Setvalue(variable, variable->defaultvalue, false); + + if (variable->flags & CV_NOINIT) + variable->flags |= CV_CALL; + + // the SetValue will set this bit + variable->flags &= ~CV_MODIFIED; +} + +/** Finds the string value of a console variable. + * + * \param var_name The variable's name. + * \return The string value or "" if the variable is not found. + */ +static const char *CV_StringValue(const char *var_name) +{ + consvar_t *var; + + var = CV_FindVar(var_name); + if (!var) + return cv_null_string; + return var->string; +} + +/** Completes the name of a console variable. + * + * \param partial The partial name of the variable (potentially). + * \param skips Number of variables to skip. + * \return The complete variable name, or NULL. + * \sa COM_CompleteCommand + */ +const char *CV_CompleteVar(char *partial, INT32 skips) +{ + consvar_t *cvar; + size_t len; + + len = strlen(partial); + + if (!len) + return NULL; + + // check variables + for (cvar = consvar_vars; cvar; cvar = cvar->next) + if (!strncmp(partial, cvar->name, len)) + if (!skips--) + return cvar->name; + + return NULL; +} + +/** Sets a value to a variable with less checking. Only for internal use. + * + * \param var Variable to set. + * \param valstr String value for the variable. + */ +static void Setvalue(consvar_t *var, const char *valstr, boolean stealth) +{ + boolean override = false; + INT32 overrideval = 0; + + // If we want messages informing us if cheats have been enabled or disabled, + // we need to rework the consvars a little bit. This call crashes the game + // on load because not all variables will be registered at that time. +/* boolean prevcheats = false; + if (var->flags & CV_CHEAT) + prevcheats = CV_CheatsEnabled(); */ + + if (var->PossibleValue) + { + INT32 v = atoi(valstr); + + if (var->PossibleValue[0].strvalue && !stricmp(var->PossibleValue[0].strvalue, "MIN")) // bounded cvar + { + INT32 i; + // search for maximum + for (i = 1; var->PossibleValue[i].strvalue; i++) + if (!stricmp(var->PossibleValue[i].strvalue, "MAX")) + break; +#ifdef PARANOIA + if (!var->PossibleValue[i].strvalue) + I_Error("Bounded cvar \"%s\" without maximum!\n", var->name); +#endif + if (v < var->PossibleValue[0].value || !stricmp(valstr, "MIN")) + { + v = var->PossibleValue[0].value; + valstr = var->PossibleValue[0].strvalue; + override = true; + overrideval = v; + } + if (v > var->PossibleValue[i].value || !stricmp(valstr, "MAX")) + { + v = var->PossibleValue[i].value; + valstr = var->PossibleValue[i].strvalue; + override = true; + overrideval = v; + } + } + else + { + INT32 i; + + // check first strings + for (i = 0; var->PossibleValue[i].strvalue; i++) + if (!stricmp(var->PossibleValue[i].strvalue, valstr)) + goto found; + if (!v) + if (strcmp(valstr, "0")) + goto error; + // check INT32 now + for (i = 0; var->PossibleValue[i].strvalue; i++) + if (v == var->PossibleValue[i].value) + goto found; + +error: + // not found + + // But wait, there's hope! + if (var->PossibleValue == CV_OnOff + || var->PossibleValue == CV_YesNo) + { + INT32 hopevalue = -1; + + if (!stricmp(valstr, "on")) + hopevalue = 1; + else if (!stricmp(valstr, "off")) + hopevalue = 0; + else if (!stricmp(valstr, "yes")) + hopevalue = 1; + else if (!stricmp(valstr, "no")) + hopevalue = 0; + + if (hopevalue != -1) + { + for (i = 0; var->PossibleValue[i].strvalue; i++) + if (hopevalue == var->PossibleValue[i].value) + goto found; + } + } + + // ...or not. + if (var != &cv_nextmap) // Suppress errors for cv_nextmap + CONS_Printf(M_GetText("\"%s\" is not a possible value for \"%s\"\n"), valstr, var->name); + + if (var->defaultvalue == valstr) + I_Error("Variable %s default value \"%s\" is not a possible value\n", + var->name, var->defaultvalue); + return; +found: + var->value = var->PossibleValue[i].value; + var->string = var->PossibleValue[i].strvalue; + goto finish; + } + } + + // free the old value string + Z_Free(var->zstring); + + var->string = var->zstring = Z_StrDup(valstr); + + if (var->flags & CV_FLOAT) + { + double d = atof(var->string); + var->value = (INT32)(d * FRACUNIT); + } + else if (override) + var->value = overrideval; + else + var->value = atoi(var->string); + +finish: + // See the note above. +/* if (var->flags & CV_CHEAT) + { + boolean newcheats = CV_CheatsEnabled(); + + if (!prevcheats && newcheats) + CONS_Printf(M_GetText("Cheats have been enabled.\n")); + else if (prevcheats && !newcheats) + CONS_Printf(M_GetText("Cheats have been disabled.\n")); + } */ + + if (var->flags & CV_SHOWMODIFONETIME || var->flags & CV_SHOWMODIF) + { + CONS_Printf(M_GetText("%s set to %s\n"), var->name, var->string); + var->flags &= ~CV_SHOWMODIFONETIME; + } + DEBFILE(va("%s set to %s\n", var->name, var->string)); + var->flags |= CV_MODIFIED; + // raise 'on change' code +#ifdef HAVE_BLUA + LUA_CVarChanged(var->name); // let consolelib know what cvar this is. +#endif + if (var->flags & CV_CALL && !stealth) + var->func(); +} + +// +// Use XD_NETVAR argument: +// 2 byte for variable identification +// then the value of the variable followed with a 0 byte (like str) +// + +static boolean serverloading = false; + +static void Got_NetVar(UINT8 **p, INT32 playernum) +{ + consvar_t *cvar; + UINT16 netid; + char *svalue; + UINT8 stealth = false; + + if (playernum != serverplayer && playernum != adminplayer && !serverloading) + { + // not from server or remote admin, must be hacked/buggy client + CONS_Alert(CONS_WARNING, M_GetText("Illegal netvar command received from %s\n"), player_names[playernum]); + + if (server) + { + XBOXSTATIC UINT8 buf[2]; + + buf[0] = (UINT8)playernum; + buf[1] = KICK_MSG_CON_FAIL; + SendNetXCmd(XD_KICK, &buf, 2); + } + return; + } + netid = READUINT16(*p); + cvar = CV_FindNetVar(netid); + svalue = (char *)*p; + SKIPSTRING(*p); + stealth = READUINT8(*p); + + if (!cvar) + { + CONS_Alert(CONS_WARNING, "Netvar not found with netid %hu\n", netid); + return; + } +#if 0 //defined (GP2X) || defined (PSP) + CONS_Printf("Netvar received: %s [netid=%d] value %s\n", cvar->name, netid, svalue); +#endif + DEBFILE(va("Netvar received: %s [netid=%d] value %s\n", cvar->name, netid, svalue)); + + Setvalue(cvar, svalue, stealth); +} + +void CV_SaveNetVars(UINT8 **p) +{ + consvar_t *cvar; + UINT8 *count_p = *p; + UINT16 count = 0; + + // send only changed cvars ... + // the client will reset all netvars to default before loading + WRITEUINT16(*p, 0x0000); + for (cvar = consvar_vars; cvar; cvar = cvar->next) + if ((cvar->flags & CV_NETVAR) && !CV_IsSetToDefault(cvar)) + { + WRITEUINT16(*p, cvar->netid); + WRITESTRING(*p, cvar->string); + WRITEUINT8(*p, false); + ++count; + } + WRITEUINT16(count_p, count); +} + +void CV_LoadNetVars(UINT8 **p) +{ + consvar_t *cvar; + UINT16 count; + + // prevent "invalid command received" + serverloading = true; + + for (cvar = consvar_vars; cvar; cvar = cvar->next) + if (cvar->flags & CV_NETVAR) + Setvalue(cvar, cvar->defaultvalue, true); + + count = READUINT16(*p); + while (count--) + Got_NetVar(p, 0); + + serverloading = false; +} + +void CV_ResetCheatNetVars(void) +{ + consvar_t *cvar; + + // Stealthset everything back to default. + for (cvar = consvar_vars; cvar; cvar = cvar->next) + if (cvar->flags & CV_CHEAT) + Setvalue(cvar, cvar->defaultvalue, true); +} + +// Returns true if the variable's current value is its default value +boolean CV_IsSetToDefault(consvar_t *v) +{ + return (!(strcmp(v->defaultvalue, v->string))); +} + +// If any cheats CVars are not at their default settings, return true. +// Else return false. +// This returns a UINT8 because I'm too lazy to deal with the packet structure. +// Deal with it. =P +UINT8 CV_CheatsEnabled(void) +{ + consvar_t *cvar; + + for (cvar = consvar_vars; cvar; cvar = cvar->next) + if ((cvar->flags & CV_CHEAT) && strcmp(cvar->defaultvalue, cvar->string)) + return 1; + return 0; +} + +/** Sets a value to a variable, performing some checks and calling the + * callback function if there is one. + * Does as if " " is entered at the console. + * + * \param var The variable. + * \param value The string value. + * \sa CV_StealthSet, CV_SetValue + */ +static void CV_SetCVar(consvar_t *var, const char *value, boolean stealth) +{ +#ifdef PARANOIA + if (!var) + I_Error("CV_Set: no variable\n"); + if (!var->string) + I_Error("CV_Set: %s no string set!\n", var->name); +#endif + if (!var || !var->string || !value || !stricmp(var->string, value)) + return; // no changes + + // Don't allow skin/color changes in single player + if ((var == &cv_skin || var == &cv_playercolor) && + !(cv_debug || devparm) && !(multiplayer || netgame) + && (gamestate == GS_LEVEL || gamestate == GS_INTERMISSION)) + { + return; + } + + if (var->flags & CV_NETVAR) + { + // send the value of the variable + XBOXSTATIC UINT8 buf[128]; + UINT8 *p = buf; + if (!(server || (adminplayer == consoleplayer))) + { + CONS_Printf(M_GetText("Only the server or admin can change: %s %s\n"), var->name, var->string); + return; + } + + // Only add to netcmd buffer if in a netgame, otherwise, just change it. + if (netgame || multiplayer) + { + WRITEUINT16(p, var->netid); + WRITESTRING(p, value); + WRITEUINT8(p, stealth); + + SendNetXCmd(XD_NETVAR, buf, p-buf); + } + else + Setvalue(var, value, stealth); + } + else + if ((var->flags & CV_NOTINNET) && netgame) + { + CONS_Printf(M_GetText("This variable can't be changed while in netgame: %s %s\n"), var->name, var->string); + return; + } + else + Setvalue(var, value, stealth); +} + +/** Sets a value to a variable without calling its callback function. + * + * \param var The variable. + * \param value The string value. + * \sa CV_Set, CV_StealthSetValue + */ +void CV_StealthSet(consvar_t *var, const char *value) +{ + CV_SetCVar(var, value, true); +} + +/** Sets a numeric value to a variable without calling its callback + * function. + * + * \param var The variable. + * \param value The numeric value, converted to a string before setting. + * \sa CV_SetValue, CV_StealthSet + */ +void CV_StealthSetValue(consvar_t *var, INT32 value) +{ + char val[32]; + + sprintf(val, "%d", value); + CV_SetCVar(var, val, true); +} + +// New wrapper for what used to be CV_Set() +void CV_Set(consvar_t *var, const char *value) +{ + CV_SetCVar(var, value, false); +} + +/** Sets a numeric value to a variable, performing some checks and + * calling the callback function if there is one. + * + * \param var The variable. + * \param value The numeric value, converted to a string before setting. + * \sa CV_Set, CV_StealthSetValue + */ +void CV_SetValue(consvar_t *var, INT32 value) +{ + char val[32]; + + sprintf(val, "%d", value); + CV_SetCVar(var, val, false); +} + +/** Adds a value to a console variable. + * Used to increment and decrement variables from the menu. + * Contains special cases to handle pointlimit in some multiplayer modes, + * map number for game hosting, etc. + * + * \param var The variable to add to. + * \param increment The change in the variable; can be negative for a + * decrement. + * \sa CV_SetValue + */ +void CV_AddValue(consvar_t *var, INT32 increment) +{ + INT32 newvalue, max; + + // count pointlimit better + if (var == &cv_pointlimit && (gametype == GT_MATCH +#ifdef CHAOSISNOTDEADYET + || gametype == GT_CHAOS +#endif + )) + increment *= 50; + newvalue = var->value + increment; + + if (var->PossibleValue) + { +#define MINVAL 0 + if (var == &cv_nextmap) + { + // Special case for the nextmap variable, used only directly from the menu + INT32 oldvalue = var->value - 1, gt; + gt = cv_newgametype.value; + if (increment != 0) // Going up! + { + newvalue = var->value - 1; + do + { + if(increment > 0) // Going up! + { + newvalue++; + if (newvalue == NUMMAPS) + newvalue = 0; + } + else // Going down! + { + newvalue--; + if (newvalue == -1) + newvalue = NUMMAPS-1; + } + + if (newvalue == oldvalue) + gt = -1; // don't loop forever if there's none of a certain gametype + + if(!mapheaderinfo[newvalue]) + continue; // Don't allocate the header. That just makes memory usage skyrocket. + + } while (newvalue != oldvalue && !M_CanShowLevelInList(newvalue, gt)); + + var->value = newvalue + 1; + var->func(); + return; + } + } + else if (var->PossibleValue[MINVAL].strvalue && !strcmp(var->PossibleValue[MINVAL].strvalue, "MIN")) + { + // search the next to last + for (max = 0; var->PossibleValue[max+1].strvalue; max++) + ; + + if (newvalue < var->PossibleValue[MINVAL].value) // add the max+1 + newvalue += var->PossibleValue[max].value - var->PossibleValue[MINVAL].value + 1; + + newvalue = var->PossibleValue[MINVAL].value + (newvalue - var->PossibleValue[MINVAL].value) + % (var->PossibleValue[max].value - var->PossibleValue[MINVAL].value + 1); + + CV_SetValue(var, newvalue); +#undef MINVAL + } + else + { + INT32 currentindice = -1, newindice; + + // this code do not support more than same value for differant PossibleValue + for (max = 0; var->PossibleValue[max].strvalue; max++) + if (var->PossibleValue[max].value == var->value) + currentindice = max; + + max--; + + if (var == &cv_chooseskin) + { + // Special case for the chooseskin variable, used only directly from the menu + if (increment > 0) // Going up! + { + newvalue = var->value - 1; + do + { + newvalue++; + if (newvalue == MAXSKINS) + newvalue = 0; + } while (var->PossibleValue[newvalue].strvalue == NULL); + var->value = newvalue + 1; + var->string = var->PossibleValue[newvalue].strvalue; + var->func(); + return; + } + else if (increment < 0) // Going down! + { + newvalue = var->value - 1; + do + { + newvalue--; + if (newvalue == -1) + newvalue = MAXSKINS-1; + } while (var->PossibleValue[newvalue].strvalue == NULL); + var->value = newvalue + 1; + var->string = var->PossibleValue[newvalue].strvalue; + var->func(); + return; + } + } +#ifdef PARANOIA + if (currentindice == -1) + I_Error("CV_AddValue: current value %d not found in possible value\n", + var->value); +#endif + + newindice = (currentindice + increment + max + 1) % (max+1); + CV_Set(var, var->PossibleValue[newindice].strvalue); + } + } + else + CV_SetValue(var, newvalue); + + var->changed = 1; // user has changed it now +} + +/** Displays or changes a variable from the console. + * Since the user is presumed to have been directly responsible + * for this change, the variable is marked as changed this game. + * + * \return False if passed command was not recognized as a console + * variable, otherwise true. + * \sa CV_ClearChangedFlags + */ +static boolean CV_Command(void) +{ + consvar_t *v; + + // check variables + v = CV_FindVar(COM_Argv(0)); + if (!v) + return false; + + // perform a variable print or set + if (COM_Argc() == 1) + { + CONS_Printf(M_GetText("\"%s\" is \"%s\" default is \"%s\"\n"), v->name, v->string, v->defaultvalue); + return true; + } + + CV_Set(v, COM_Argv(1)); + v->changed = 1; // now it's been changed by (presumably) the user + return true; +} + +/** Marks all variables as unchanged, indicating they've not been changed + * by the user this game. + * + * \sa CV_Command + * \author Graue + */ +void CV_ClearChangedFlags(void) +{ + consvar_t *cvar; + + for (cvar = consvar_vars; cvar; cvar = cvar->next) + cvar->changed = 0; +} + +/** Saves console variables to a file if they have the ::CV_SAVE + * flag set. + * + * \param f File to save to. + */ +void CV_SaveVariables(FILE *f) +{ + consvar_t *cvar; + + for (cvar = consvar_vars; cvar; cvar = cvar->next) + if (cvar->flags & CV_SAVE) + { + char stringtowrite[MAXTEXTCMD+1]; + + // Silly hack for Min/Max vars + if (!strcmp(cvar->string, "MAX") || !strcmp(cvar->string, "MIN")) + sprintf(stringtowrite, "%d", cvar->value); + else + strcpy(stringtowrite, cvar->string); + + fprintf(f, "%s \"%s\"\n", cvar->name, stringtowrite); + } +} + +//============================================================================ +// SCRIPT PARSE +//============================================================================ + +/** Parses a token out of a string. Handles script files too. + * + * \param data String to parse. + * \return The data pointer after the token. NULL if no token found. + */ +static char *COM_Parse(char *data) +{ + char c; + size_t len = 0; + + com_token[0] = 0; + + if (data == NULL) + return NULL; + + // skip whitespace +skipwhite: + while ((c = *data) <= ' ') + { + if (c == '\0') + return NULL; // end of file; + data++; + } + + // skip // comments + if (c == '/' && data[1] == '/') + { + while (*data && *data != '\n') + data++; + goto skipwhite; + } + + // handle quoted strings specially + if (c == '\"') + { + data++; + for (;;) + { + c = *data++; + if (c == '\"' || c == '\0') + { + com_token[len] = 0; + return data; + } + com_token[len] = c; + len++; + } + } + + // parse single characters + if (c == '{' || c == '}' || c == ')' || c == '(' || c == '\'') + { + com_token[len] = c; + len++; + com_token[len] = 0; + return data + 1; + } + + // parse a regular word + do + { + com_token[len] = c; + data++; + len++; + c = *data; + if (c == '{' || c == '}' || c == ')'|| c == '(' || c == '\'') + break; + } while (c > 32); + + com_token[len] = 0; + return data; +} diff --git a/src/command.h b/src/command.h new file mode 100644 index 000000000..c7962faf6 --- /dev/null +++ b/src/command.h @@ -0,0 +1,162 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Copyright (C) 1999-2014 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file command.h +/// \brief Deals with commands from console input, scripts, and remote server + +#ifndef __COMMAND_H__ +#define __COMMAND_H__ + +#include +#include "doomdef.h" + +//=================================== +// Command buffer & command execution +//=================================== + +typedef void (*com_func_t)(void); + +void COM_AddCommand(const char *name, com_func_t func); + +size_t COM_Argc(void); +const char *COM_Argv(size_t arg); // if argv > argc, returns empty string +char *COM_Args(void); +size_t COM_CheckParm(const char *check); // like M_CheckParm :) + +// match existing command or NULL +const char *COM_CompleteCommand(const char *partial, INT32 skips); + +// insert at queu (at end of other command) +void COM_BufAddText(const char *btext); + +// insert in head (before other command) +void COM_BufInsertText(const char *btext); + +// don't bother inserting, just do immediately +void COM_ImmedExecute(const char *ptext); + +// Execute commands in buffer, flush them +void COM_BufExecute(void); + +// setup command buffer, at game tartup +void COM_Init(void); + +// ====================== +// Variable sized buffers +// ====================== + +typedef struct vsbuf_s +{ + boolean allowoverflow; // if false, do a I_Error + boolean overflowed; // set to true if the buffer size failed + UINT8 *data; + size_t maxsize; + size_t cursize; +} vsbuf_t; + +void VS_Alloc(vsbuf_t *buf, size_t initsize); +void VS_Free(vsbuf_t *buf); +void VS_Clear(vsbuf_t *buf); +void *VS_GetSpace(vsbuf_t *buf, size_t length); +void VS_Write(vsbuf_t *buf, const void *data, size_t length); +void VS_Print(vsbuf_t *buf, const char *data); // strcats onto the sizebuf + +//================== +// Console variables +//================== +// console vars are variables that can be changed through code or console, +// at RUN TIME. They can also act as simplified commands, because a func- +// tion can be attached to a console var, which is called whenever the +// variable is modified (using flag CV_CALL). + +// flags for console vars + +typedef enum +{ + CV_SAVE = 1, // save to config when quit game + CV_CALL = 2, // call function on change + CV_NETVAR = 4, // send it when change (see logboris.txt at 12-4-2000) + CV_NOINIT = 8, // dont call function when var is registered (1st set) + CV_FLOAT = 16, // the value is fixed 16 : 16, where unit is FRACUNIT + // (allow user to enter 0.45 for ex) + // WARNING: currently only supports set with CV_Set() + CV_NOTINNET = 32, // some varaiable can't be changed in network but is not netvar (ex: splitscreen) + CV_MODIFIED = 64, // this bit is set when cvar is modified + CV_SHOWMODIF = 128, // say something when modified + CV_SHOWMODIFONETIME = 256, // same but will be reset to 0 when modified, set in toggle + CV_NOSHOWHELP = 512, // Don't show variable in the HELP list Tails 08-13-2002 + CV_HIDEN = 1024, // variable is not part of the cvar list so cannot be accessed by the console + // can only be set when we have the pointer to it + // used on menus + CV_CHEAT = 2048 // Don't let this be used in multiplayer unless cheats are on. +} cvflags_t; + +typedef struct CV_PossibleValue_s +{ + INT32 value; + const char *strvalue; +} CV_PossibleValue_t; + +typedef struct consvar_s //NULL, NULL, 0, NULL, NULL |, 0, NULL, NULL, 0, 0, NULL +{ + const char *name; + const char *defaultvalue; + INT32 flags; // flags see cvflags_t above + CV_PossibleValue_t *PossibleValue; // table of possible values + void (*func)(void); // called on change, if CV_CALL set + INT32 value; // for INT32 and fixed_t + const char *string; // value in string + char *zstring; // Either NULL or same as string. + // If non-NULL, must be Z_Free'd later. + UINT16 netid; // used internaly : netid for send end receive + // used only with CV_NETVAR + char changed; // has variable been changed by the user? 0 = no, 1 = yes + struct consvar_s *next; +} consvar_t; + +extern CV_PossibleValue_t CV_OnOff[]; +extern CV_PossibleValue_t CV_YesNo[]; +extern CV_PossibleValue_t CV_Unsigned[]; +extern CV_PossibleValue_t CV_Natural[]; +// register a variable for use at the console +void CV_RegisterVar(consvar_t *variable); + +// sets changed to 0 for every console variable +void CV_ClearChangedFlags(void); + +// returns the name of the nearest console variable name found +const char *CV_CompleteVar(char *partial, INT32 skips); + +// equivalent to " " typed at the console +void CV_Set(consvar_t *var, const char *value); + +// expands value to a string and calls CV_Set +void CV_SetValue(consvar_t *var, INT32 value); + +// avoids calling the function if it is CV_CALL +void CV_StealthSetValue(consvar_t *var, INT32 value); +void CV_StealthSet(consvar_t *var, const char *value); + +// it a setvalue but with a modulo at the maximum +void CV_AddValue(consvar_t *var, INT32 increment); + +// write all CV_SAVE variables to config file +void CV_SaveVariables(FILE *f); + +// load/save gamesate (load and save option and for network join in game) +void CV_SaveNetVars(UINT8 **p); +void CV_LoadNetVars(UINT8 **p); + +// reset cheat netvars after cheats is deactivated +void CV_ResetCheatNetVars(void); + +boolean CV_IsSetToDefault(consvar_t *v); +UINT8 CV_CheatsEnabled(void); + +#endif // __COMMAND_H__ diff --git a/src/comptime.c b/src/comptime.c new file mode 100644 index 000000000..cd6bfd9bb --- /dev/null +++ b/src/comptime.c @@ -0,0 +1,17 @@ +/* + * Compiles date and time. + * + * Kalaron: Can't this be somewhere else instead of in an extra c file? + * Alam: Code::Block, XCode and the Makefile touch this file to update + * the timestamp + * + */ + +#ifdef COMPVERSION +#include "comptime.h" +#else +const char *comprevision = "illegal"; +#endif + +const char *compdate = __DATE__; +const char *comptime = __TIME__; diff --git a/src/console.c b/src/console.c new file mode 100644 index 000000000..f8d31a698 --- /dev/null +++ b/src/console.c @@ -0,0 +1,1475 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Copyright (C) 1999-2014 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file console.c +/// \brief Console drawing and input + +#ifdef __GNUC__ +#include +#ifdef _XBOX +#include +#endif +#endif + +#include "doomdef.h" +#include "console.h" +#include "g_game.h" +#include "g_input.h" +#include "hu_stuff.h" +#include "keys.h" +#include "r_defs.h" +#include "sounds.h" +#include "st_stuff.h" +#include "s_sound.h" +#include "v_video.h" +#include "i_video.h" +#include "z_zone.h" +#include "i_system.h" +#include "d_main.h" +#include "m_menu.h" + +#ifdef _WINDOWS +#include "win32/win_main.h" +#endif + +#ifdef HWRENDER +#include "hardware/hw_main.h" +#endif + +#define MAXHUDLINES 20 + +static boolean con_started = false; // console has been initialised + boolean con_startup = false; // true at game startup, screen need refreshing +static boolean con_forcepic = true; // at startup toggle console translucency when first off + boolean con_recalc; // set true when screen size has changed + +static tic_t con_tick; // console ticker for anim or blinking prompt cursor + // con_scrollup should use time (currenttime - lasttime).. + +static boolean consoletoggle; // true when console key pushed, ticker will handle +static boolean consoleready; // console prompt is ready + + INT32 con_destlines; // vid lines used by console at final position +static INT32 con_curlines; // vid lines currently used by console + + INT32 con_clipviewtop; // clip value for planes & sprites, so that the + // part of the view covered by the console is not + // drawn when not needed, this must be -1 when + // console is off + +static INT32 con_hudlines; // number of console heads up message lines +static INT32 con_hudtime[MAXHUDLINES]; // remaining time of display for hud msg lines + + INT32 con_clearlines; // top screen lines to refresh when view reduced + boolean con_hudupdate; // when messages scroll, we need a backgrnd refresh + +// console text output +static char *con_line; // console text output current line +static size_t con_cx; // cursor position in current line +static size_t con_cy; // cursor line number in con_buffer, is always + // increasing, and wrapped around in the text + // buffer using modulo. + +static size_t con_totallines; // lines of console text into the console buffer +static size_t con_width; // columns of chars, depend on vid mode width + +static size_t con_scrollup; // how many rows of text to scroll up (pgup/pgdn) +UINT32 con_scalefactor; // text size scale factor + +// hold 32 last lines of input for history +#define CON_MAXPROMPTCHARS 256 +#define CON_PROMPTCHAR '>' + +static char inputlines[32][CON_MAXPROMPTCHARS]; // hold last 32 prompt lines + +static INT32 inputline; // current input line number +static INT32 inputhist; // line number of history input line to restore +static size_t input_cx; // position in current input line + +// protos. +static void CON_InputInit(void); +static void CON_RecalcSize(void); + +static void CONS_hudlines_Change(void); +static void CON_DrawBackpic(patch_t *pic, INT32 startx, INT32 destwidth); +//static void CON_DrawBackpic2(pic_t *pic, INT32 startx, INT32 destwidth); + +//====================================================================== +// CONSOLE VARS AND COMMANDS +//====================================================================== +#ifdef macintosh +#define CON_BUFFERSIZE 4096 // my compiler can't handle local vars >32k +#else +#define CON_BUFFERSIZE 16384 +#endif + +static char con_buffer[CON_BUFFERSIZE]; + +// how many seconds the hud messages lasts on the screen +static consvar_t cons_msgtimeout = {"con_hudtime", "5", CV_SAVE, CV_Unsigned, NULL, 0, NULL, NULL, 0, 0, NULL}; + +// number of lines displayed on the HUD +static consvar_t cons_hudlines = {"con_hudlines", "5", CV_CALL|CV_SAVE, CV_Unsigned, CONS_hudlines_Change, 0, NULL, NULL, 0, 0, NULL}; + +// number of lines console move per frame +// (con_speed needs a limit, apparently) +static CV_PossibleValue_t speed_cons_t[] = {{0, "MIN"}, {64, "MAX"}, {0, NULL}}; +static consvar_t cons_speed = {"con_speed", "8", CV_SAVE, speed_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; + +// percentage of screen height to use for console +static consvar_t cons_height = {"con_height", "50", CV_SAVE, CV_Unsigned, NULL, 0, NULL, NULL, 0, 0, NULL}; + +static CV_PossibleValue_t backpic_cons_t[] = {{0, "translucent"}, {1, "picture"}, {0, NULL}}; +// whether to use console background picture, or translucent mode +static consvar_t cons_backpic = {"con_backpic", "translucent", CV_SAVE, backpic_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; + +static CV_PossibleValue_t backcolor_cons_t[] = {{0, "White"}, {1, "Orange"}, + {2, "Blue"}, {3, "Green"}, {4, "Gray"}, + {5, "Red"}, {0, NULL}}; +consvar_t cons_backcolor = {"con_backcolor", "3", CV_SAVE, backcolor_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; + +static void CON_Print(char *msg); + +// +// +static void CONS_hudlines_Change(void) +{ + INT32 i; + + // Clear the currently displayed lines + for (i = 0; i < con_hudlines; i++) + con_hudtime[i] = 0; + + if (cons_hudlines.value < 1) + cons_hudlines.value = 1; + else if (cons_hudlines.value > MAXHUDLINES) + cons_hudlines.value = MAXHUDLINES; + + con_hudlines = cons_hudlines.value; + + CONS_Printf(M_GetText("Number of console HUD lines is now %d\n"), con_hudlines); +} + +// Clear console text buffer +// +static void CONS_Clear_f(void) +{ + memset(con_buffer, 0, CON_BUFFERSIZE); + + con_cx = 0; + con_cy = con_totallines-1; + con_line = &con_buffer[con_cy*con_width]; + con_scrollup = 0; +} + +// Choose english keymap +// +static void CONS_English_f(void) +{ + shiftxform = english_shiftxform; + CONS_Printf(M_GetText("%s keymap.\n"), M_GetText("English")); +} + +static char *bindtable[NUMINPUTS]; + +static void CONS_Bind_f(void) +{ + size_t na; + INT32 key; + + na = COM_Argc(); + + if (na != 2 && na != 3) + { + CONS_Printf(M_GetText("bind []: create shortcut keys to command(s)\n")); + CONS_Printf("\x82%s", M_GetText("Bind table :\n")); + na = 0; + for (key = 0; key < NUMINPUTS; key++) + if (bindtable[key]) + { + CONS_Printf("%s : \"%s\"\n", G_KeynumToString(key), bindtable[key]); + na = 1; + } + if (!na) + CONS_Printf(M_GetText("(empty)\n")); + return; + } + + key = G_KeyStringtoNum(COM_Argv(1)); + if (!key) + { + CONS_Alert(CONS_NOTICE, M_GetText("Invalid key name\n")); + return; + } + + Z_Free(bindtable[key]); + bindtable[key] = NULL; + + if (na == 3) + bindtable[key] = Z_StrDup(COM_Argv(2)); +} + +//====================================================================== +// CONSOLE SETUP +//====================================================================== + +// Prepare a colormap for GREEN ONLY translucency over background +// +UINT8 *yellowmap; +UINT8 *purplemap; +UINT8 *lgreenmap; +UINT8 *bluemap; +UINT8 *graymap; +UINT8 *redmap; +UINT8 *orangemap; + +// Console BG colors +UINT8 *cwhitemap; +UINT8 *corangemap; +UINT8 *cbluemap; +UINT8 *cgreenmap; +UINT8 *cgraymap; +UINT8 *credmap; + +void CON_ReSetupBackColormap(UINT16 num) +{ + UINT16 i, j; + UINT8 k; + UINT8 *pal = W_CacheLumpName(R_GetPalname(num), PU_CACHE); + + // setup the green translucent background colormaps + for (i = 0, k = 0; i < 768; i += 3, k++) + { + j = pal[i] + pal[i+1] + pal[i+2]; + cwhitemap[k] = (UINT8)(15 - (j>>6)); + corangemap[k] = (UINT8)(95 - (j>>6)); + cbluemap[k] = (UINT8)(239 - (j>>6)); + cgreenmap[k] = (UINT8)(175 - (j>>6)); + cgraymap[k] = (UINT8)(31 - (j>>6)); + credmap[k] = (UINT8)(143 - (j>>6)); + } +} + +static void CON_SetupBackColormap(void) +{ + INT32 i, j, k; + UINT8 *pal; + + cwhitemap = (UINT8 *)Z_Malloc(256, PU_STATIC, NULL); + corangemap = (UINT8 *)Z_Malloc(256, PU_STATIC, NULL); + cbluemap = (UINT8 *)Z_Malloc(256, PU_STATIC, NULL); + cgreenmap = (UINT8 *)Z_Malloc(256, PU_STATIC, NULL); + cgraymap = (UINT8 *)Z_Malloc(256, PU_STATIC, NULL); + credmap = (UINT8 *)Z_Malloc(256, PU_STATIC, NULL); + + yellowmap = (UINT8 *)Z_Malloc(256, PU_STATIC, NULL); + graymap = (UINT8 *)Z_Malloc(256, PU_STATIC, NULL); + purplemap = (UINT8 *)Z_Malloc(256, PU_STATIC, NULL); + lgreenmap = (UINT8 *)Z_Malloc(256, PU_STATIC, NULL); + bluemap = (UINT8 *)Z_Malloc(256, PU_STATIC, NULL); + redmap = (UINT8 *)Z_Malloc(256, PU_STATIC, NULL); + orangemap = (UINT8 *)Z_Malloc(256, PU_STATIC, NULL); + + pal = W_CacheLumpName("PLAYPAL", PU_CACHE); + + // setup the green translucent background colormaps + for (i = 0, k = 0; i < 768; i += 3, k++) + { + j = pal[i] + pal[i+1] + pal[i+2]; + cwhitemap[k] = (UINT8)(15 - (j>>6)); + corangemap[k] = (UINT8)(95 - (j>>6)); + cbluemap[k] = (UINT8)(239 - (j>>6)); + cgreenmap[k] = (UINT8)(175 - (j>>6)); + cgraymap[k] = (UINT8)(31 - (j>>6)); + credmap[k] = (UINT8)(143 - (j>>6)); + } + + // setup the other colormaps, for console text + + // these don't need to be aligned, unless you convert the + // V_DrawMappedPatch() into optimised asm. + + for (i = 0; i < 256; i++) + { + yellowmap[i] = (UINT8)i; // remap each color to itself... + graymap[i] = (UINT8)i; + purplemap[i] = (UINT8)i; + lgreenmap[i] = (UINT8)i; + bluemap[i] = (UINT8)i; + redmap[i] = (UINT8)i; + orangemap[i] = (UINT8)i; + } + + yellowmap[3] = (UINT8)103; + yellowmap[9] = (UINT8)115; + purplemap[3] = (UINT8)195; + purplemap[9] = (UINT8)198; + lgreenmap[3] = (UINT8)162; + lgreenmap[9] = (UINT8)170; + bluemap[3] = (UINT8)228; + bluemap[9] = (UINT8)238; + graymap[3] = (UINT8)10; + graymap[9] = (UINT8)15; + redmap[3] = (UINT8)124; + redmap[9] = (UINT8)127; + orangemap[3] = (UINT8)85; + orangemap[9] = (UINT8)90; +} + +// Setup the console text buffer +// +// for WII, libogc already has a CON_Init function, we must rename it here +#ifdef _WII +void CON_InitWii(void) +#else +void CON_Init(void) +#endif +{ + INT32 i; + + for (i = 0; i < NUMINPUTS; i++) + bindtable[i] = NULL; + + // clear all lines + memset(con_buffer, 0, CON_BUFFERSIZE); + + // make sure it is ready for the loading screen + con_width = 0; + CON_RecalcSize(); + + CON_SetupBackColormap(); + + //note: CON_Ticker should always execute at least once before D_Display() + con_clipviewtop = -1; // -1 does not clip + + con_hudlines = atoi(cons_hudlines.defaultvalue); + + // setup console input filtering + CON_InputInit(); + + // register our commands + // + COM_AddCommand("cls", CONS_Clear_f); + COM_AddCommand("english", CONS_English_f); + // set console full screen for game startup MAKE SURE VID_Init() done !!! + con_destlines = vid.height; + con_curlines = vid.height; + + + if (!dedicated) + { + con_started = true; + con_startup = true; // need explicit screen refresh until we are in Doom loop + consoletoggle = false; + CV_RegisterVar(&cons_msgtimeout); + CV_RegisterVar(&cons_hudlines); + CV_RegisterVar(&cons_speed); + CV_RegisterVar(&cons_height); + CV_RegisterVar(&cons_backpic); + CV_RegisterVar(&cons_backcolor); + COM_AddCommand("bind", CONS_Bind_f); + } + else + { + con_started = true; + con_startup = false; // need explicit screen refresh until we are in Doom loop + consoletoggle = true; + } +} +// Console input initialization +// +static void CON_InputInit(void) +{ + INT32 i; + + // prepare the first prompt line + memset(inputlines, 0, sizeof (inputlines)); + for (i = 0; i < 32; i++) + inputlines[i][0] = CON_PROMPTCHAR; + inputline = 0; + input_cx = 1; +} + +//====================================================================== +// CONSOLE EXECUTION +//====================================================================== + +// Called at screen size change to set the rows and line size of the +// console text buffer. +// +static void CON_RecalcSize(void) +{ + size_t conw, oldcon_width, oldnumlines, i, oldcon_cy; + char *tmp_buffer; + char *string; + + switch (cv_constextsize.value) + { + case V_NOSCALEPATCH: + con_scalefactor = 1; + break; + case V_SMALLSCALEPATCH: + con_scalefactor = vid.smalldupx; + break; + case V_MEDSCALEPATCH: + con_scalefactor = vid.meddupx; + break; + default: // Full scaling + con_scalefactor = vid.dupx; + break; + } + + con_recalc = false; + + if (dedicated) + conw = 1; + else + conw = (vid.width>>3) / con_scalefactor - 2; + + if (con_curlines == vid.height) // first init + { + con_curlines = vid.height; + con_destlines = vid.height; + } + + // check for change of video width + if (conw == con_width) + return; // didn't change + + tmp_buffer = Z_Malloc(CON_BUFFERSIZE, PU_STATIC, NULL); + string = Z_Malloc(CON_BUFFERSIZE, PU_STATIC, NULL); // BP: it is a line but who know + + oldcon_width = con_width; + oldnumlines = con_totallines; + oldcon_cy = con_cy; + M_Memcpy(tmp_buffer, con_buffer, CON_BUFFERSIZE); + + if (conw < 1) + con_width = (BASEVIDWIDTH>>3) - 2; + else + con_width = conw; + + con_width += 11; // Graue 06-19-2004 up to 11 control chars per line + + con_totallines = CON_BUFFERSIZE / con_width; + memset(con_buffer, ' ', CON_BUFFERSIZE); + + con_cx = 0; + con_cy = con_totallines-1; + con_line = &con_buffer[con_cy*con_width]; + con_scrollup = 0; + + // re-arrange console text buffer to keep text + if (oldcon_width) // not the first time + { + for (i = oldcon_cy + 1; i < oldcon_cy + oldnumlines; i++) + { + if (tmp_buffer[(i%oldnumlines)*oldcon_width]) + { + M_Memcpy(string, &tmp_buffer[(i%oldnumlines)*oldcon_width], oldcon_width); + conw = oldcon_width - 1; + while (string[conw] == ' ' && conw) + conw--; + string[conw+1] = '\n'; + string[conw+2] = '\0'; + CON_Print(string); + } + } + } + + Z_Free(string); + Z_Free(tmp_buffer); +} + +// Handles Console moves in/out of screen (per frame) +// +static void CON_MoveConsole(void) +{ + const fixed_t conspeed = FixedDiv(cons_speed.value*vid.fdupy, FRACUNIT); + + // instant + if (!cons_speed.value) + { + con_curlines = con_destlines; + return; + } + + // up/down move to dest + if (con_curlines < con_destlines) + { + con_curlines += FixedInt(conspeed); + if (con_curlines > con_destlines) + con_curlines = con_destlines; + } + else if (con_curlines > con_destlines) + { + con_curlines -= FixedInt(conspeed); + if (con_curlines < con_destlines) + con_curlines = con_destlines; + } +} + +// Clear time of console heads up messages +// +void CON_ClearHUD(void) +{ + INT32 i; + + for (i = 0; i < con_hudlines; i++) + con_hudtime[i] = 0; +} + +// Force console to move out immediately +// note: con_ticker will set consoleready false +void CON_ToggleOff(void) +{ + if (!con_destlines) + return; + + con_destlines = 0; + con_curlines = 0; + CON_ClearHUD(); + con_forcepic = 0; + con_clipviewtop = -1; // remove console clipping of view +} + +boolean CON_Ready(void) +{ + return consoleready; +} + +// Console ticker: handles console move in/out, cursor blinking +// +void CON_Ticker(void) +{ + INT32 i; + INT32 minheight = 20 * con_scalefactor; // 20 = 8+8+4 + + // cursor blinking + con_tick++; + con_tick &= 7; + + // if the menu is open then close the console. + if (menuactive && con_destlines) + { + consoletoggle = false; + con_destlines = 0; + CON_ClearHUD(); + } + + // console key was pushed + if (consoletoggle) + { + consoletoggle = false; + + // toggle off console + if (con_destlines > 0) + { + con_destlines = 0; + CON_ClearHUD(); + } + else + { + // toggle console in + con_destlines = (cons_height.value*vid.height)/100; + if (con_destlines < minheight) + con_destlines = minheight; + else if (con_destlines > vid.height) + con_destlines = vid.height; + + con_destlines &= ~0x3; // multiple of text row height + } + } + + // console movement + if (con_destlines != con_curlines) + CON_MoveConsole(); + + // clip the view, so that the part under the console is not drawn + con_clipviewtop = -1; + if (cons_backpic.value) // clip only when using an opaque background + { + if (con_curlines > 0) + con_clipviewtop = con_curlines - viewwindowy - 1 - 10; + // NOTE: BIG HACK::SUBTRACT 10, SO THAT WATER DON'T COPY LINES OF THE CONSOLE + // WINDOW!!! (draw some more lines behind the bottom of the console) + if (con_clipviewtop < 0) + con_clipviewtop = -1; // maybe not necessary, provided it's < 0 + } + + // check if console ready for prompt + if (con_destlines >= minheight) + consoleready = true; + else + consoleready = false; + + // make overlay messages disappear after a while + for (i = 0; i < con_hudlines; i++) + { + con_hudtime[i]--; + if (con_hudtime[i] < 0) + con_hudtime[i] = 0; + } +} + +// Handles console key input +// +boolean CON_Responder(event_t *ev) +{ + static boolean consdown; + static boolean shiftdown; + static boolean ctrldown; + + // sequential completions a la 4dos + static char completion[80]; + static INT32 comskips, varskips; + + const char *cmd = ""; + INT32 key; + + if (chat_on) + return false; + + // let go keyup events, don't eat them + if (ev->type != ev_keydown && ev->type != ev_console) + { + if (ev->data1 == KEY_LSHIFT || ev->data1 == KEY_RSHIFT) + shiftdown = false; + else if (ev->data1 == KEY_LCTRL || ev->data1 == KEY_RCTRL) + ctrldown = false; + else if (ev->data1 == gamecontrol[gc_console][0] || ev->data1 == gamecontrol[gc_console][1]) + consdown = false; + + return false; + } + + key = ev->data1; + + // check for console toggle key + if (ev->type != ev_console) + { + if (modeattacking || metalrecording) + return false; + + if (key == gamecontrol[gc_console][0] || key == gamecontrol[gc_console][1]) + { + if (consdown) // ignore repeat + return true; + consoletoggle = true; + consdown = true; + return true; + } + + // check other keys only if console prompt is active + if (!consoleready && key < NUMINPUTS) // metzgermeister: boundary check!! + { + if (bindtable[key]) + { + COM_BufAddText(bindtable[key]); + COM_BufAddText("\n"); + return true; + } + return false; + } + + // escape key toggle off console + if (key == KEY_ESCAPE) + { + consoletoggle = true; + return true; + } + + } + + // eat shift only if console active + if (key == KEY_LSHIFT || key == KEY_RSHIFT) + { + shiftdown = true; + return true; + } + + // same for ctrl + if (key == KEY_LCTRL || key == KEY_RCTRL) + { + ctrldown = true; + return true; + } + + // command completion forward (tab) and backward (shift-tab) + if (key == KEY_TAB) + { + // show all cvars/commands that match what we have inputted + if (ctrldown) + { + UINT32 i; + size_t stop = input_cx - 1; + char nameremainder[255]; + + if (input_cx < 2 || strlen(inputlines[inputline]+1) >= 80) + return true; + + strcpy(completion, inputlines[inputline]+1); + + // trimming: stop at the first newline + for (i = 0; i < input_cx - 1; ++i) + { + if (completion[i] == ' ') + { + completion[i] = '\0'; + stop = i; + break; + } + } + + i = 0; + + //first check commands + CONS_Printf("\nCommands:\n"); + + for (cmd = COM_CompleteCommand(completion, i); cmd; cmd = COM_CompleteCommand(completion, i)) + { + strncpy(nameremainder, cmd+(stop), strlen(cmd)-(stop)); + nameremainder[strlen(cmd)-(stop)] = '\0'; + + CONS_Printf(" \x83" "%s" "\x80" "%s\n", completion, nameremainder); + ++i; + } + if (i == 0) + CONS_Printf(" (none)\n"); + + i = 0; + + //now we move on to CVARs + CONS_Printf("Variables:\n"); + + for (cmd = CV_CompleteVar(completion, i); cmd; cmd = CV_CompleteVar(completion, i)) + { + strncpy(nameremainder, cmd+(stop), strlen(cmd)-(stop)); + nameremainder[strlen(cmd)-(stop)] = '\0'; + + CONS_Printf(" \x83" "%s" "\x80" "%s\n", completion, nameremainder); + ++i; + } + if (i == 0) + CONS_Printf(" (none)\n"); + + return true; + } + + // sequential command completion forward and backward + + // remember typing for several completions (a-la-4dos) + if (inputlines[inputline][input_cx-1] != ' ') + { + if (strlen(inputlines[inputline]+1) < 80) + strcpy(completion, inputlines[inputline]+1); + else + completion[0] = 0; + + comskips = varskips = 0; + } + else + { + if (shiftdown) + { + if (comskips < 0) + { + if (--varskips < 0) + comskips = -comskips - 2; + } + else if (comskips > 0) + comskips--; + } + else + { + if (comskips < 0) + varskips++; + else + comskips++; + } + } + + if (comskips >= 0) + { + cmd = COM_CompleteCommand(completion, comskips); + if (!cmd) + // dirty: make sure if comskips is zero, to have a neg value + comskips = -comskips - 1; + } + if (comskips < 0) + cmd = CV_CompleteVar(completion, varskips); + + if (cmd) + { + memset(inputlines[inputline]+1, 0, CON_MAXPROMPTCHARS-1); + strcpy(inputlines[inputline]+1, cmd); + input_cx = strlen(cmd) + 1; + inputlines[inputline][input_cx] = ' '; + input_cx++; + inputlines[inputline][input_cx] = 0; + } + else + { + if (comskips > 0) + comskips--; + else if (varskips > 0) + varskips--; + } + + return true; + } + + // move up (backward) in console textbuffer + if (key == KEY_PGUP) + { + if (con_scrollup < (con_totallines-((con_curlines-16)>>3))) + con_scrollup++; + return true; + } + else if (key == KEY_PGDN) + { + if (con_scrollup > 0) + con_scrollup--; + return true; + } + + if (key == KEY_HOME) // oldest text in buffer + { + con_scrollup = (con_totallines-((con_curlines-16)>>3)); + return true; + } + else if (key == KEY_END) // most recent text in buffer + { + con_scrollup = 0; + return true; + } + + // command enter + if (key == KEY_ENTER) + { + if (input_cx < 2) + return true; + + // push the command + COM_BufAddText(inputlines[inputline]+1); + COM_BufAddText("\n"); + + CONS_Printf("%s\n", inputlines[inputline]); + + inputline = (inputline+1) & 31; + inputhist = inputline; + + memset(inputlines[inputline], 0, CON_MAXPROMPTCHARS); + inputlines[inputline][0] = CON_PROMPTCHAR; + input_cx = 1; + + return true; + } + + // backspace command prompt + if (key == KEY_BACKSPACE) + { + if (input_cx > 1) + { + input_cx--; + inputlines[inputline][input_cx] = 0; + } + return true; + } + + // move back in input history + if (key == KEY_UPARROW) + { + // copy one of the previous inputlines to the current + do + { + inputhist = (inputhist - 1) & 31; // cycle back + } while (inputhist != inputline && !inputlines[inputhist][1]); + + // stop at the last history input line, which is the + // current line + 1 because we cycle through the 32 input lines + if (inputhist == inputline) + inputhist = (inputline + 1) & 31; + + M_Memcpy(inputlines[inputline], inputlines[inputhist], CON_MAXPROMPTCHARS); + input_cx = strlen(inputlines[inputline]); + + return true; + } + + // move forward in input history + if (key == KEY_DOWNARROW) + { + if (inputhist == inputline) + return true; + do + { + inputhist = (inputhist + 1) & 31; + } while (inputhist != inputline && !inputlines[inputhist][1]); + + memset(inputlines[inputline], 0, CON_MAXPROMPTCHARS); + + // back to currentline + if (inputhist == inputline) + { + inputlines[inputline][0] = CON_PROMPTCHAR; + input_cx = 1; + } + else + { + strcpy(inputlines[inputline], inputlines[inputhist]); + input_cx = strlen(inputlines[inputline]); + } + return true; + } + + // allow people to use keypad in console (good for typing IP addresses) - Calum + if (key >= KEY_KEYPAD7 && key <= KEY_KPADDEL) + { + XBOXSTATIC char keypad_translation[] = {'7','8','9','-', + '4','5','6','+', + '1','2','3', + '0','.'}; + + key = keypad_translation[key - KEY_KEYPAD7]; + } + else if (key == KEY_KPADSLASH) + key = '/'; + + if (shiftdown) + key = shiftxform[key]; + + // enter a char into the command prompt + if (key < 32 || key > 127) + return false; + + // add key to cmd line here + if (input_cx < CON_MAXPROMPTCHARS) + { + if (key >= 'A' && key <= 'Z' && !shiftdown) //this is only really necessary for dedicated servers + key = key + 'a' - 'A'; + + inputlines[inputline][input_cx] = (char)key; + inputlines[inputline][input_cx + 1] = 0; + input_cx++; + } + + return true; +} + +// Insert a new line in the console text buffer +// +static void CON_Linefeed(void) +{ + // set time for heads up messages + con_hudtime[con_cy%con_hudlines] = cons_msgtimeout.value*TICRATE; + + con_cy++; + con_cx = 0; + + con_line = &con_buffer[(con_cy%con_totallines)*con_width]; + memset(con_line, ' ', con_width); + + // make sure the view borders are refreshed if hud messages scroll + con_hudupdate = true; // see HU_Erase() +} + +// Outputs text into the console text buffer +static void CON_Print(char *msg) +{ + size_t l; + INT32 controlchars = 0; // for color changing + + if (msg == NULL) + return; + + if (*msg == '\3') // chat text, makes ding sound + S_StartSound(NULL, sfx_radio); + else if (*msg == '\4') // chat action, dings and is in yellow + { + *msg = '\x82'; // yellow + S_StartSound(NULL, sfx_radio); + } + + if (!(*msg & 0x80)) + { + con_line[con_cx++] = '\x80'; + controlchars = 1; + } + + while (*msg) + { + // skip non-printable characters and white spaces + while (*msg && *msg <= ' ') + { + if (*msg & 0x80) + { + con_line[con_cx++] = *(msg++); + controlchars++; + continue; + } + else if (*msg == '\r') // carriage return + { + con_cy--; + CON_Linefeed(); + controlchars = 0; + } + else if (*msg == '\n') // linefeed + { + CON_Linefeed(); + controlchars = 0; + } + else if (*msg == ' ') // space + { + con_line[con_cx++] = ' '; + if (con_cx - controlchars >= con_width-11) + { + CON_Linefeed(); + controlchars = 0; + } + } + else if (*msg == '\t') + { + // adds tab spaces for nice layout in console + + do + { + con_line[con_cx++] = ' '; + } while ((con_cx - controlchars) % 4 != 0); + + if (con_cx - controlchars >= con_width-11) + { + CON_Linefeed(); + controlchars = 0; + } + } + msg++; + } + + if (*msg == '\0') + return; + + // printable character + for (l = 0; l < (con_width-11) && msg[l] > ' '; l++) + ; + + // word wrap + if ((con_cx - controlchars) + l > con_width-11) + { + CON_Linefeed(); + controlchars = 0; + } + + // a word at a time + for (; l > 0; l--) + con_line[con_cx++] = *(msg++); + } +} + +void CON_LogMessage(const char *msg) +{ + XBOXSTATIC char txt[8192], *t; + const char *p = msg, *e = txt+sizeof (txt)-2; + + for (t = txt; *p != '\0'; p++) + { + if (*p == '\n' || *p >= ' ') // don't log or console print CON_Print's control characters + *t++ = *p; + + if (t >= e) + { + *t = '\0'; //end of string + I_OutputMsg("%s", txt); //print string + t = txt; //reset t pointer + memset(txt,'\0', sizeof (txt)); //reset txt + } + } + *t = '\0'; //end of string + I_OutputMsg("%s", txt); +} + +// Console print! Wahooo! Lots o fun! +// + +void CONS_Printf(const char *fmt, ...) +{ + va_list argptr; + static char *txt = NULL; + + if (txt == NULL) + txt = malloc(8192); + + va_start(argptr, fmt); + vsprintf(txt, fmt, argptr); + va_end(argptr); + + // echo console prints to log file +#ifndef _arch_dreamcast + DEBFILE(txt); +#endif + + if (!con_started) + { +#if defined (_XBOX) && defined (__GNUC__) + if (!keyboard_started) debugPrint(txt); +#endif +#ifdef PC_DOS + CON_LogMessage(txt); + free(txt); + return; +#endif + } + else + // write message in con text buffer + CON_Print(txt); + +#ifndef PC_DOS + CON_LogMessage(txt); +#endif + + // make sure new text is visible + con_scrollup = 0; + + // if not in display loop, force screen update + if (con_startup) + { +#if (defined (_WINDOWS)) || (defined (__OS2__) && !defined (SDL)) + static lumpnum_t con_backpic_lumpnum = UINT32_MAX; + patch_t *con_backpic; + + if (con_backpic_lumpnum == UINT32_MAX) + con_backpic_lumpnum = W_GetNumForName("CONSBACK"); + + // We load the raw lump, even in hardware mode + con_backpic = (patch_t*)W_CacheLumpNum(con_backpic_lumpnum, PU_CACHE); + + // show startup screen and message using only 'software' graphics + // (rendermode may be hardware accelerated, but the video mode is not set yet) + CON_DrawBackpic(con_backpic, 0, vid.width); // put console background + I_LoadingScreen(txt); + + Z_Unlock(con_backpic); +#else + // here we display the console background and console text + // (no hardware accelerated support for these versions) + CON_Drawer(); + I_FinishUpdate(); // page flip or blit buffer +#endif + } +} + +void CONS_Alert(alerttype_t level, const char *fmt, ...) +{ + va_list argptr; + static char *txt = NULL; + + if (txt == NULL) + txt = malloc(8192); + + va_start(argptr, fmt); + vsprintf(txt, fmt, argptr); + va_end(argptr); + + switch (level) + { + case CONS_NOTICE: + CONS_Printf("\x83" "%s" "\x80 ", M_GetText("NOTICE:")); + break; + case CONS_WARNING: + CONS_Printf("\x82" "%s" "\x80 ", M_GetText("WARNING:")); + break; + case CONS_ERROR: + CONS_Printf("\x85" "%s" "\x80 ", M_GetText("ERROR:")); + break; + } + + // I am lazy and I feel like just letting CONS_Printf take care of things. + // Is that okay? + CONS_Printf("%s", txt); +} + +void CONS_Debug(INT32 debugflags, const char *fmt, ...) +{ + va_list argptr; + static char *txt = NULL; + + if ((cv_debug & debugflags) != debugflags) + return; + + if (txt == NULL) + txt = malloc(8192); + + va_start(argptr, fmt); + vsprintf(txt, fmt, argptr); + va_end(argptr); + + // Again I am lazy, oh well + CONS_Printf("%s", txt); +} + + +// Print an error message, and wait for ENTER key to continue. +// To make sure the user has seen the message +// +void CONS_Error(const char *msg) +{ +#ifdef RPC_NO_WINDOWS_H + if (!graphics_started) + { + MessageBoxA(vid.WndParent, msg, "SRB2 Warning", MB_OK); + return; + } +#endif + CONS_Printf("\x82%s", msg); // write error msg in different colour + CONS_Printf(M_GetText("Press ENTER to continue\n")); + + // dirty quick hack, but for the good cause + while (I_GetKey() != KEY_ENTER) + I_OsPolling(); +} + +//====================================================================== +// CONSOLE DRAW +//====================================================================== + +// draw console prompt line +// +static void CON_DrawInput(void) +{ + char *p; + size_t c; + INT32 x, y; + INT32 charwidth = (INT32)con_scalefactor << 3; + + // input line scrolls left if it gets too long + p = inputlines[inputline]; + if (input_cx >= con_width-11) + p += input_cx - (con_width-11) + 1; + + y = con_curlines - 12 * con_scalefactor; + + for (c = 0, x = charwidth; c < con_width-11; c++, x += charwidth) + V_DrawCharacter(x, y, p[c] | cv_constextsize.value | V_NOSCALESTART, !cv_allcaps.value); + + // draw the blinking cursor + // + x = ((input_cx >= con_width-11) ? (INT32)(con_width-11) : (INT32)((input_cx + 1)) * charwidth); + if (con_tick < 4) + V_DrawCharacter(x, y, '_' | cv_constextsize.value | V_NOSCALESTART, !cv_allcaps.value); +} + +// draw the last lines of console text to the top of the screen +static void CON_DrawHudlines(void) +{ + UINT8 *p; + size_t i; + INT32 y; + INT32 charflags = 0; + INT32 charwidth = 8 * con_scalefactor; + INT32 charheight = 8 * con_scalefactor; + + if (con_hudlines <= 0) + return; + + if (chat_on) + y = charheight; // leave place for chat input in the first row of text + else + y = 0; + + for (i = con_cy - con_hudlines+1; i <= con_cy; i++) + { + size_t c; + INT32 x; + + if ((signed)i < 0) + continue; + if (con_hudtime[i%con_hudlines] == 0) + continue; + + p = (UINT8 *)&con_buffer[(i%con_totallines)*con_width]; + + for (c = 0, x = 0; c < con_width; c++, x += charwidth, p++) + { + while (*p & 0x80) // Graue 06-19-2004 + { + charflags = (*p & 0x7f) << V_CHARCOLORSHIFT; + p++; + } + if (*p < HU_FONTSTART) + ;//charwidth = 4 * con_scalefactor; + else + { + //charwidth = SHORT(hu_font['A'-HU_FONTSTART]->width) * con_scalefactor; + V_DrawCharacter(x, y, (INT32)(*p) | charflags | cv_constextsize.value | V_NOSCALESTART, !cv_allcaps.value); + } + } + + //V_DrawCharacter(x, y, (p[c]&0xff) | cv_constextsize.value | V_NOSCALESTART, !cv_allcaps.value); + y += charheight; + } + + // top screen lines that might need clearing when view is reduced + con_clearlines = y; // this is handled by HU_Erase(); +} + +// Scale a pic_t at 'startx' pos, to 'destwidth' columns. +// startx, destwidth is resolution dependent +// Used to draw console borders, console background. +// The pic must be sized BASEVIDHEIGHT height. +static void CON_DrawBackpic(patch_t *pic, INT32 startx, INT32 destwidth) +{ + (void)startx; + (void)destwidth; + V_DrawScaledPatch(0, 0, 0, pic); +} + +#if 0 +static inline void CON_DrawBackpic2(pic_t *pic, INT32 startx, INT32 destwidth) +{ + INT32 x, y; + INT32 v; + UINT8 *src, *dest; + const UINT8 *deststop; + INT32 frac, fracstep; + + dest = screens[0]+startx; + deststop = screens[0] + vid.rowbytes * vid.height; + + for (y = 0; y < con_curlines; y++, dest += vid.width) + { + // scale the picture to the resolution + v = SHORT(pic->height) - ((con_curlines - y) * (BASEVIDHEIGHT-1) / vid.height) - 1; + + src = pic->data + v*SHORT(pic->width); + + // in case of the console backpic, simplify + if (SHORT(pic->width) == destwidth) + M_Memcpy(dest, src, destwidth); + else + { + // scale pic to screen width + frac = 0; + fracstep = (SHORT(pic->width)<<16)/destwidth; + for (x = 0; x < destwidth; x += 4) + { + if (dest+x > deststop) break; + dest[x] = src[frac>>FRACBITS]; + frac += fracstep; + if (dest+x+1 > deststop) break; + dest[x+1] = src[frac>>FRACBITS]; + frac += fracstep; + if (dest+x+2 > deststop) break; + dest[x+2] = src[frac>>FRACBITS]; + frac += fracstep; + if (dest+x+3 > deststop) break; + dest[x+3] = src[frac>>FRACBITS]; + frac += fracstep; + } + } + } +} +#endif + +// draw the console background, text, and prompt if enough place +// +static void CON_DrawConsole(void) +{ + UINT8 *p; + size_t i; + INT32 y; + INT32 w = 0, x2 = 0; + INT32 charflags = 0; + INT32 charwidth = (INT32)con_scalefactor << 3; + INT32 charheight = charwidth; + INT32 minheight = 20 * con_scalefactor; // 20 = 8+8+4 + + if (con_curlines <= 0) + return; + + //FIXME: refresh borders only when console bg is translucent + con_clearlines = con_curlines; // clear console draw from view borders + con_hudupdate = true; // always refresh while console is on + + // draw console background + if (cons_backpic.value || con_forcepic) + { + static lumpnum_t con_backpic_lumpnum = UINT32_MAX; + patch_t *con_backpic; + + if (con_backpic_lumpnum == UINT32_MAX) + con_backpic_lumpnum = W_GetNumForName("CONSBACK"); + + con_backpic = (patch_t*)W_CachePatchNum(con_backpic_lumpnum, PU_CACHE); + + if (rendermode != render_soft) + V_DrawScaledPatch(0, 0, 0, con_backpic); + else if (rendermode != render_none) + CON_DrawBackpic(con_backpic, 0, vid.width); // picture as background + + W_UnlockCachedPatch(con_backpic); + } + else + { + x2 = vid.width; + // Hurdler: what's the correct value of w and x2 in hardware mode??? + if (rendermode != render_none) V_DrawFadeConsBack(w, 0, x2, con_curlines, cons_backcolor.value); // translucent background + } + + // draw console text lines from top to bottom + if (con_curlines < minheight) + return; + + i = con_cy - con_scrollup; + + // skip the last empty line due to the cursor being at the start of a new line + if (!con_scrollup && !con_cx) + i--; + + i -= (con_curlines - minheight) / charheight; + + if (rendermode == render_none) return; + + for (y = (con_curlines-minheight) % charheight; y <= con_curlines-minheight; y += charheight, i++) + { + INT32 x; + size_t c; + + p = (UINT8 *)&con_buffer[((i > 0 ? i : 0)%con_totallines)*con_width]; + + for (c = 0, x = charwidth; c < con_width; c++, x += charwidth, p++) + { + while (*p & 0x80) + { + charflags = (*p & 0x7f) << V_CHARCOLORSHIFT; + p++; + } + V_DrawCharacter(x, y, (INT32)(*p) | charflags | cv_constextsize.value | V_NOSCALESTART, !cv_allcaps.value); + } + } + + // draw prompt if enough place (not while game startup) + if ((con_curlines == con_destlines) && (con_curlines >= minheight) && !con_startup) + CON_DrawInput(); +} + +// Console refresh drawer, call each frame +// +void CON_Drawer(void) +{ + if (!con_started || !graphics_started) + return; + + if (con_recalc) + CON_RecalcSize(); + + if (con_curlines > 0) + CON_DrawConsole(); + else if (gamestate == GS_LEVEL || gamestate == GS_INTERMISSION || gamestate == GS_CUTSCENE || gamestate == GS_CREDITS) + CON_DrawHudlines(); +} diff --git a/src/console.h b/src/console.h new file mode 100644 index 000000000..c95f2b036 --- /dev/null +++ b/src/console.h @@ -0,0 +1,60 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Copyright (C) 1999-2014 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file console.h +/// \brief Console drawing and input + +#include "d_event.h" +#include "command.h" + +#ifdef _WII +void CON_InitWii(void); +#else +void CON_Init(void); +#endif + +boolean CON_Responder(event_t *ev); + +// set true when screen size has changed, to adapt console +extern boolean con_recalc; + +extern boolean con_startup; + +// top clip value for view render: do not draw part of view hidden by console +extern INT32 con_clipviewtop; + +// 0 means console if off, or moving out +extern INT32 con_destlines; + +extern INT32 con_clearlines; // lines of top of screen to refresh +extern boolean con_hudupdate; // hud messages have changed, need refresh +extern UINT32 con_scalefactor; // console text scale factor + +extern consvar_t cons_backcolor; + +extern UINT8 *yellowmap, *purplemap, *lgreenmap, *bluemap, *graymap, *redmap, *orangemap; + +// Console bg colors: +extern UINT8 *cwhitemap, *corangemap, *cbluemap, *cgreenmap, *cgraymap, + *credmap; + +void CON_ReSetupBackColormap(UINT16 num); +void CON_ClearHUD(void); // clear heads up messages + +void CON_Ticker(void); +void CON_Drawer(void); +void CONS_Error(const char *msg); // print out error msg, and wait a key + +// force console to move out +void CON_ToggleOff(void); + +// Is console down? +boolean CON_Ready(void); + +void CON_LogMessage(const char *msg); diff --git a/src/d_clisrv.c b/src/d_clisrv.c new file mode 100644 index 000000000..e0c727f52 --- /dev/null +++ b/src/d_clisrv.c @@ -0,0 +1,4021 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Copyright (C) 1999-2014 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file d_clisrv.c +/// \brief SRB2 Network game communication and protocol, all OS independent parts. + +#if !defined (UNDER_CE) +#include +#endif +#ifdef __GNUC__ +#include //for unlink +#endif + +#include "i_net.h" +#include "i_system.h" +#include "i_video.h" +#include "d_net.h" +#include "d_main.h" +#include "g_game.h" +#include "hu_stuff.h" +#include "keys.h" +#include "m_menu.h" +#include "console.h" +#include "d_netfil.h" +#include "byteptr.h" +#include "p_saveg.h" +#include "z_zone.h" +#include "p_local.h" +#include "m_misc.h" +#include "am_map.h" +#include "m_random.h" +#include "mserv.h" +#include "y_inter.h" +#include "r_local.h" +#include "m_argv.h" +#include "p_setup.h" +#include "lzf.h" +#include "lua_script.h" +#include "lua_hook.h" + +#ifdef CLIENT_LOADINGSCREEN +// cl loading screen +#include "v_video.h" +#include "f_finale.h" +#endif + +#ifdef _XBOX +#include "sdl/SRB2XBOX/xboxhelp.h" +#endif + +// +// NETWORKING +// +// gametic is the tic about to (or currently being) run +// maketic is the tic that hasn't had control made for it yet +// server: +// nettics is the tic for each node +// firstticstosend is the lowest value of nettics +// client: +// neededtic is the tic needed by the client for run the game +// firstticstosend is used to optimize a condition +// normally maketic >= gametic > 0 + +#define PREDICTIONQUEUE BACKUPTICS +#define PREDICTIONMASK (PREDICTIONQUEUE-1) +#define MAX_REASONLENGTH 30 + +boolean server = true; // true or false but !server == client +boolean nodownload = false; +static boolean serverrunning = false; +INT32 serverplayer = 0; +char motd[254], server_context[8]; // Message of the Day, Unique Context (even without Mumble support) + +// server specific vars +UINT8 playernode[MAXPLAYERS]; +UINT8 consfailcount[MAXPLAYERS]; +UINT8 consfailstatus[MAXPLAYERS]; + +#ifdef NEWPING +UINT16 pingmeasurecount = 1; +UINT32 realpingtable[MAXPLAYERS]; //the base table of ping where an average will be sent to everyone. +UINT32 playerpingtable[MAXPLAYERS]; //table of player latency values. +#endif +SINT8 nodetoplayer[MAXNETNODES]; +SINT8 nodetoplayer2[MAXNETNODES]; // say the numplayer for this node if any (splitscreen) +UINT8 playerpernode[MAXNETNODES]; // used specialy for scplitscreen +boolean nodeingame[MAXNETNODES]; // set false as nodes leave game +static tic_t nettics[MAXNETNODES]; // what tic the client have received +static tic_t supposedtics[MAXNETNODES]; // nettics prevision for smaller packet +static UINT8 nodewaiting[MAXNETNODES]; +static tic_t firstticstosend; // min of the nettics +static INT16 consistancy[BACKUPTICS]; +static tic_t tictoclear = 0; // optimize d_clearticcmd +static tic_t maketic; + +// client specific +static ticcmd_t localcmds; +static ticcmd_t localcmds2; +static boolean cl_packetmissed; +// here it is for the secondary local player (splitscreen) +static UINT8 mynode; // my address pointofview server + +static UINT8 localtextcmd[MAXTEXTCMD]; +static UINT8 localtextcmd2[MAXTEXTCMD]; // splitscreen +static tic_t neededtic; +SINT8 servernode = 0; // the number of the server node +/// \brief do we accept new players? +/// \todo WORK! +boolean acceptnewnode = true; + +// engine + +// Must be a power of two +#define TEXTCMD_HASH_SIZE 4 + +typedef struct textcmdplayer_s +{ + INT32 playernum; + UINT8 cmd[MAXTEXTCMD]; + struct textcmdplayer_s *next; +} textcmdplayer_t; + +typedef struct textcmdtic_s +{ + tic_t tic; + textcmdplayer_t *playercmds[TEXTCMD_HASH_SIZE]; + struct textcmdtic_s *next; +} textcmdtic_t; + +ticcmd_t netcmds[BACKUPTICS][MAXPLAYERS]; +static textcmdtic_t *textcmds[TEXTCMD_HASH_SIZE] = {NULL}; + + +static consvar_t cv_showjoinaddress = {"showjoinaddress", "On", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + +static CV_PossibleValue_t playbackspeed_cons_t[] = {{1, "MIN"}, {10, "MAX"}, {0, NULL}}; +consvar_t cv_playbackspeed = {"playbackspeed", "1", 0, playbackspeed_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; + +void D_ResetTiccmds(void) +{ + memset(&localcmds, 0, sizeof(ticcmd_t)); + memset(&localcmds2, 0, sizeof(ticcmd_t)); +} + +static inline void *G_DcpyTiccmd(void* dest, const ticcmd_t* src, const size_t n) +{ + const size_t d = n / sizeof(ticcmd_t); + const size_t r = n % sizeof(ticcmd_t); + UINT8 *ret = dest; + + if (r) + M_Memcpy(dest, src, n); + else if (d) + G_MoveTiccmd(dest, src, d); + return ret+n; +} + +static inline void *G_ScpyTiccmd(ticcmd_t* dest, void* src, const size_t n) +{ + const size_t d = n / sizeof(ticcmd_t); + const size_t r = n % sizeof(ticcmd_t); + UINT8 *ret = src; + + if (r) + M_Memcpy(dest, src, n); + else if (d) + G_MoveTiccmd(dest, src, d); + return ret+n; +} + + + +// some software don't support largest packet +// (original sersetup, not exactely, but the probabylity of sending a packet +// of 512 octet is like 0.1) +UINT16 software_MAXPACKETLENGTH; + +tic_t ExpandTics(INT32 low) +{ + INT32 delta; + + delta = low - (maketic & UINT8_MAX); + + if (delta >= -64 && delta <= 64) + return (maketic & ~UINT8_MAX) + low; + else if (delta > 64) + return (maketic & ~UINT8_MAX) - 256 + low; + else //if (delta < -64) + return (maketic & ~UINT8_MAX) + 256 + low; +} + +// ----------------------------------------------------------------- +// Some extra data function for handle textcmd buffer +// ----------------------------------------------------------------- + +static void (*listnetxcmd[MAXNETXCMD])(UINT8 **p, INT32 playernum); + +void RegisterNetXCmd(netxcmd_t id, void (*cmd_f)(UINT8 **p, INT32 playernum)) +{ +#ifdef PARANOIA + if (id >= MAXNETXCMD) + I_Error("command id %d too big", id); + if (listnetxcmd[id] != 0) + I_Error("Command id %d already used", id); +#endif + listnetxcmd[id] = cmd_f; +} + +void SendNetXCmd(netxcmd_t id, const void *param, size_t nparam) +{ + if (localtextcmd[0]+2+nparam > MAXTEXTCMD) + { + // for future reference: if (cv_debug) != debug disabled. + CONS_Alert(CONS_ERROR, M_GetText("NetXCmd buffer full, cannot add netcmd %d! (size: %d, needed: %s)\n"), id, localtextcmd[0], sizeu1(nparam)); + return; + } + localtextcmd[0]++; + localtextcmd[localtextcmd[0]] = (UINT8)id; + if (param && nparam) + { + M_Memcpy(&localtextcmd[localtextcmd[0]+1], param, nparam); + localtextcmd[0] = (UINT8)(localtextcmd[0] + (UINT8)nparam); + } +} + +// splitscreen player +void SendNetXCmd2(netxcmd_t id, const void *param, size_t nparam) +{ + if (localtextcmd2[0]+2+nparam > MAXTEXTCMD) + { + I_Error("No more place in the buffer for netcmd %d\n",id); + return; + } + localtextcmd2[0]++; + localtextcmd2[localtextcmd2[0]] = (UINT8)id; + if (param && nparam) + { + M_Memcpy(&localtextcmd2[localtextcmd2[0]+1], param, nparam); + localtextcmd2[0] = (UINT8)(localtextcmd2[0] + (UINT8)nparam); + } +} + +UINT8 GetFreeXCmdSize(void) +{ + // -1 for the size and another -1 for the ID. + return (UINT8)(localtextcmd[0] - 2); +} + +// Frees all textcmd memory for the specified tic +static void D_FreeTextcmd(tic_t tic) +{ + textcmdtic_t **tctprev = &textcmds[tic & (TEXTCMD_HASH_SIZE - 1)]; + textcmdtic_t *textcmdtic = *tctprev; + + while (textcmdtic && textcmdtic->tic != tic) + { + tctprev = &textcmdtic->next; + textcmdtic = textcmdtic->next; + } + + if (textcmdtic) + { + INT32 i; + + // Remove this tic from the list. + *tctprev = textcmdtic->next; + + // Free all players. + for (i = 0; i < TEXTCMD_HASH_SIZE; i++) + { + textcmdplayer_t *textcmdplayer = textcmdtic->playercmds[i]; + + while (textcmdplayer) + { + textcmdplayer_t *tcpnext = textcmdplayer->next; + Z_Free(textcmdplayer); + textcmdplayer = tcpnext; + } + } + + // Free this tic's own memory. + Z_Free(textcmdtic); + } +} + +// Gets the buffer for the specified ticcmd, or NULL if there isn't one +static UINT8* D_GetExistingTextcmd(tic_t tic, INT32 playernum) +{ + textcmdtic_t *textcmdtic = textcmds[tic & (TEXTCMD_HASH_SIZE - 1)]; + while (textcmdtic && textcmdtic->tic != tic) textcmdtic = textcmdtic->next; + + // Do we have an entry for the tic? If so, look for player. + if (textcmdtic) + { + textcmdplayer_t *textcmdplayer = textcmdtic->playercmds[playernum & (TEXTCMD_HASH_SIZE - 1)]; + while (textcmdplayer && textcmdplayer->playernum != playernum) textcmdplayer = textcmdplayer->next; + + if (textcmdplayer) return textcmdplayer->cmd; + } + + return NULL; +} + +// Gets the buffer for the specified ticcmd, creating one if necessary +static UINT8* D_GetTextcmd(tic_t tic, INT32 playernum) +{ + textcmdtic_t *textcmdtic = textcmds[tic & (TEXTCMD_HASH_SIZE - 1)]; + textcmdtic_t **tctprev = &textcmds[tic & (TEXTCMD_HASH_SIZE - 1)]; + textcmdplayer_t *textcmdplayer, **tcpprev; + + // Look for the tic. + while (textcmdtic && textcmdtic->tic != tic) + { + tctprev = &textcmdtic->next; + textcmdtic = textcmdtic->next; + } + + // If we don't have an entry for the tic, make it. + if (!textcmdtic) + { + textcmdtic = *tctprev = Z_Calloc(sizeof (textcmdtic_t), PU_STATIC, NULL); + textcmdtic->tic = tic; + } + + tcpprev = &textcmdtic->playercmds[playernum & (TEXTCMD_HASH_SIZE - 1)]; + textcmdplayer = *tcpprev; + + // Look for the player. + while (textcmdplayer && textcmdplayer->playernum != playernum) + { + tcpprev = &textcmdplayer->next; + textcmdplayer = textcmdplayer->next; + } + + // If we don't have an entry for the player, make it. + if (!textcmdplayer) + { + textcmdplayer = *tcpprev = Z_Calloc(sizeof (textcmdplayer_t), PU_STATIC, NULL); + textcmdplayer->playernum = playernum; + } + + return textcmdplayer->cmd; +} + +static void ExtraDataTicker(void) +{ + INT32 i; + + for (i = 0; i < MAXPLAYERS; i++) + if (playeringame[i] || i == 0) + { + UINT8 *bufferstart = D_GetExistingTextcmd(gametic, i); + + if (bufferstart) + { + UINT8 *curpos = bufferstart; + UINT8 *bufferend = &curpos[curpos[0]+1]; + + curpos++; + while (curpos < bufferend) + { + if (*curpos < MAXNETXCMD && listnetxcmd[*curpos]) + { + const UINT8 id = *curpos; + curpos++; + DEBFILE(va("executing x_cmd %u ply %u ", id, i)); + (listnetxcmd[id])(&curpos, i); + DEBFILE("done\n"); + } + else + { + if (server) + { + XBOXSTATIC UINT8 buf[3]; + + buf[0] = (UINT8)i; + buf[1] = KICK_MSG_CON_FAIL; + SendNetXCmd(XD_KICK, &buf, 2); + DEBFILE(va("player %d kicked [gametic=%u] reason as follows:\n", i, gametic)); + } + CONS_Alert(CONS_WARNING, M_GetText("Got unknown net command [%s]=%d (max %d)\n"), sizeu1(curpos - bufferstart), *curpos, bufferstart[0]); + D_FreeTextcmd(gametic); + return; + } + } + } + } + + D_FreeTextcmd(gametic); +} + +static void D_Clearticcmd(tic_t tic) +{ + INT32 i; + + D_FreeTextcmd(tic); + + for (i = 0; i < MAXPLAYERS; i++) + netcmds[tic%BACKUPTICS][i].angleturn = 0; + + DEBFILE(va("clear tic %5u (%2u)\n", tic, tic%BACKUPTICS)); +} + +// ----------------------------------------------------------------- +// end of extra data function +// ----------------------------------------------------------------- + +// ----------------------------------------------------------------- +// extra data function for lmps +// ----------------------------------------------------------------- + +// if extradatabit is set, after the ziped tic you find this: +// +// type | description +// ---------+-------------- +// byte | size of the extradata +// byte | the extradata (xd) bits: see XD_... +// with this byte you know what parameter folow +// if (xd & XDNAMEANDCOLOR) +// byte | color +// char[MAXPLAYERNAME] | name of the player +// endif +// if (xd & XD_WEAPON_PREF) +// byte | original weapon switch: boolean, true if use the old +// | weapon switch methode +// char[NUMWEAPONS] | the weapon switch priority +// byte | autoaim: true if use the old autoaim system +// endif +/*boolean AddLmpExtradata(UINT8 **demo_point, INT32 playernum) +{ + UINT8 *textcmd = D_GetExistingTextcmd(gametic, playernum); + + if (!textcmd) + return false; + + M_Memcpy(*demo_point, textcmd, textcmd[0]+1); + *demo_point += textcmd[0]+1; + return true; +} + +void ReadLmpExtraData(UINT8 **demo_pointer, INT32 playernum) +{ + UINT8 nextra; + UINT8 *textcmd; + + if (!demo_pointer) + return; + + textcmd = D_GetTextcmd(gametic, playernum); + nextra = **demo_pointer; + M_Memcpy(textcmd, *demo_pointer, nextra + 1); + // increment demo pointer + *demo_pointer += nextra + 1; +}*/ + +// ----------------------------------------------------------------- +// end extra data function for lmps +// ----------------------------------------------------------------- + +static INT16 Consistancy(void); + +#ifndef NONET +#define JOININGAME +#endif + +typedef enum +{ + cl_searching, + cl_downloadfiles, + cl_askjoin, + cl_waitjoinresponse, +#ifdef JOININGAME + cl_downloadsavegame, +#endif + cl_connected, + cl_aborted +} cl_mode_t; + +static void GetPackets(void); + +static cl_mode_t cl_mode = cl_searching; + +#ifdef CLIENT_LOADINGSCREEN +// +// CL_DrawConnectionStatus +// +// Keep the local client informed of our status. +// +static inline void CL_DrawConnectionStatus(void) +{ + INT32 ccstime = I_GetTime(); + + // Draw background fade + V_DrawFadeScreen(); + + // Draw the bottom box. + M_DrawTextBox(BASEVIDWIDTH/2-128-8, BASEVIDHEIGHT-24-8, 32, 1); + V_DrawCenteredString(BASEVIDWIDTH/2, BASEVIDHEIGHT-24-24, V_YELLOWMAP, "Press ESC to abort"); + + if (cl_mode != cl_downloadfiles) + { + INT32 i, animtime = ((ccstime / 4) & 15) + 16; + UINT8 palstart = (cl_mode == cl_searching) ? 128 : 160; + // 15 pal entries total. + const char *cltext; + + for (i = 0; i < 16; ++i) + V_DrawFill((BASEVIDWIDTH/2-128) + (i * 16), BASEVIDHEIGHT-24, 16, 8, palstart + ((animtime - i) & 15)); + + switch (cl_mode) + { + case cl_downloadsavegame: + cltext = M_GetText("Downloading game state..."); + Net_GetNetStat(); + V_DrawString(BASEVIDWIDTH/2-128, BASEVIDHEIGHT-24, V_20TRANS|V_MONOSPACE, + va(" %4uK",fileneeded[lastfilenum].currentsize>>10)); + V_DrawRightAlignedString(BASEVIDWIDTH/2+128, BASEVIDHEIGHT-24, V_20TRANS|V_MONOSPACE, + va("%3.1fK/s ", ((double)getbps)/1024)); + break; + case cl_askjoin: + case cl_waitjoinresponse: + cltext = M_GetText("Requesting to join..."); + break; + default: + cltext = M_GetText("Connecting to server..."); + break; + } + V_DrawCenteredString(BASEVIDWIDTH/2, BASEVIDHEIGHT-24-32, V_YELLOWMAP, cltext); + } + else + { + INT32 dldlength; + static char tempname[32]; + + Net_GetNetStat(); + dldlength = (INT32)((fileneeded[lastfilenum].currentsize/(double)fileneeded[lastfilenum].totalsize) * 256); + if (dldlength > 256) + dldlength = 256; + V_DrawFill(BASEVIDWIDTH/2-128, BASEVIDHEIGHT-24, 256, 8, 175); + V_DrawFill(BASEVIDWIDTH/2-128, BASEVIDHEIGHT-24, dldlength, 8, 160); + + memset(tempname, 0, sizeof(tempname)); + nameonly(strncpy(tempname, fileneeded[lastfilenum].filename, 31)); + + V_DrawCenteredString(BASEVIDWIDTH/2, BASEVIDHEIGHT-24-32, V_YELLOWMAP, + va(M_GetText("Downloading \"%s\""), tempname)); + V_DrawString(BASEVIDWIDTH/2-128, BASEVIDHEIGHT-24, V_20TRANS|V_MONOSPACE, + va(" %4uK/%4uK",fileneeded[lastfilenum].currentsize>>10,fileneeded[lastfilenum].totalsize>>10)); + V_DrawRightAlignedString(BASEVIDWIDTH/2+128, BASEVIDHEIGHT-24, V_20TRANS|V_MONOSPACE, + va("%3.1fK/s ", ((double)getbps)/1024)); + } +} +#endif + +// +// CL_SendJoin +// +// send a special packet for declare how many player in local +// used only in arbitratrenetstart() +static boolean CL_SendJoin(void) +{ + UINT8 localplayers = 1; + if (netgame) + CONS_Printf(M_GetText("Sending join request...\n")); + netbuffer->packettype = PT_CLIENTJOIN; + + if (splitscreen || botingame) + localplayers++; + netbuffer->u.clientcfg.localplayers = localplayers; + netbuffer->u.clientcfg.version = VERSION; + netbuffer->u.clientcfg.subversion = SUBVERSION; + + return HSendPacket(servernode, true, 0, sizeof (clientconfig_pak)); +} + +static void SV_SendServerInfo(INT32 node, tic_t servertime) +{ + UINT8 *p; + + netbuffer->packettype = PT_SERVERINFO; + netbuffer->u.serverinfo.version = VERSION; + netbuffer->u.serverinfo.subversion = SUBVERSION; + // return back the time value so client can compute their ping + netbuffer->u.serverinfo.time = (tic_t)LONG(servertime); + netbuffer->u.serverinfo.leveltime = (tic_t)LONG(leveltime); + + netbuffer->u.serverinfo.numberofplayer = (UINT8)D_NumPlayers(); + netbuffer->u.serverinfo.maxplayer = (UINT8)cv_maxplayers.value; + netbuffer->u.serverinfo.gametype = (UINT8)gametype; + netbuffer->u.serverinfo.modifiedgame = (UINT8)modifiedgame; + netbuffer->u.serverinfo.cheatsenabled = CV_CheatsEnabled(); + netbuffer->u.serverinfo.isdedicated = (UINT8)dedicated; + strncpy(netbuffer->u.serverinfo.servername, cv_servername.string, + MAXSERVERNAME); + strncpy(netbuffer->u.serverinfo.mapname, G_BuildMapName(gamemap), 7); + + M_Memcpy(netbuffer->u.serverinfo.mapmd5, mapmd5, 16); + + if (strcmp(mapheaderinfo[gamemap-1]->lvlttl, "")) + strncpy(netbuffer->u.serverinfo.maptitle, (char *)mapheaderinfo[gamemap-1]->lvlttl, 33); + else + strncpy(netbuffer->u.serverinfo.maptitle, "UNKNOWN", 33); + + netbuffer->u.serverinfo.maptitle[32] = '\0'; + + if (!(mapheaderinfo[gamemap-1]->levelflags & LF_NOZONE)) + netbuffer->u.serverinfo.iszone = 1; + else + netbuffer->u.serverinfo.iszone = 0; + + netbuffer->u.serverinfo.actnum = mapheaderinfo[gamemap-1]->actnum; + + p = PutFileNeeded(); + + HSendPacket(node, false, 0, p - ((UINT8 *)&netbuffer->u)); +} + +static void SV_SendPlayerInfo(INT32 node) +{ + UINT8 i; + netbuffer->packettype = PT_PLAYERINFO; + + for (i = 0; i < MAXPLAYERS; i++) + { + if (!playeringame[i]) + { + netbuffer->u.playerinfo[i].node = 255; // This slot is empty. + continue; + } + + netbuffer->u.playerinfo[i].node = (UINT8)playernode[i]; + strncpy(netbuffer->u.playerinfo[i].name, (const char *)&player_names[i], MAXPLAYERNAME+1); + netbuffer->u.playerinfo[i].name[MAXPLAYERNAME] = '\0'; + + //fetch IP address + { + const char *claddress; + UINT32 numericaddress[4]; + + memset(netbuffer->u.playerinfo[i].address, 0, 4); + if (playernode[i] == 0) + { + //127.0.0.1 + netbuffer->u.playerinfo[i].address[0] = 127; + netbuffer->u.playerinfo[i].address[3] = 1; + } + else if (playernode[i] > 0 && I_GetNodeAddress && (claddress = I_GetNodeAddress(playernode[i])) != NULL) + { + if (sscanf(claddress, "%d.%d.%d.%d", &numericaddress[0], &numericaddress[1], &numericaddress[2], &numericaddress[3]) < 4) + goto badaddress; + netbuffer->u.playerinfo[i].address[0] = (UINT8)numericaddress[0]; + netbuffer->u.playerinfo[i].address[1] = (UINT8)numericaddress[1]; + netbuffer->u.playerinfo[i].address[2] = (UINT8)numericaddress[2]; + netbuffer->u.playerinfo[i].address[3] = (UINT8)numericaddress[3]; + } + } + badaddress: + + if (G_GametypeHasTeams()) + { + if (!players[i].ctfteam) + netbuffer->u.playerinfo[i].team = 255; + else + netbuffer->u.playerinfo[i].team = (UINT8)players[i].ctfteam; + } + else + { + if (players[i].spectator) + netbuffer->u.playerinfo[i].team = 255; + else + netbuffer->u.playerinfo[i].team = 0; + } + + netbuffer->u.playerinfo[i].score = LONG(players[i].score); + netbuffer->u.playerinfo[i].timeinserver = SHORT((UINT16)(players[i].jointime / TICRATE)); + netbuffer->u.playerinfo[i].skin = (UINT8)players[i].skin; + + // Extra data + netbuffer->u.playerinfo[i].data = players[i].skincolor; + + if (players[i].pflags & PF_TAGIT) + netbuffer->u.playerinfo[i].data |= 0x20; + + if (players[i].gotflag) + netbuffer->u.playerinfo[i].data |= 0x40; + + if (players[i].powers[pw_super]) + netbuffer->u.playerinfo[i].data |= 0x80; + } + + HSendPacket(node, false, 0, sizeof(plrinfo) * MAXPLAYERS); +} + +static boolean SV_SendServerConfig(INT32 node) +{ + INT32 i; + UINT8 *p, *op; + boolean waspacketsent; + UINT32 playermask = 0; + + netbuffer->packettype = PT_SERVERCFG; + for (i = 0; i < MAXPLAYERS; i++) + if (playeringame[i]) + playermask |= 1<u.servercfg.version = VERSION; + netbuffer->u.servercfg.subversion = SUBVERSION; + + netbuffer->u.servercfg.serverplayer = (UINT8)serverplayer; + netbuffer->u.servercfg.totalslotnum = (UINT8)(doomcom->numslots); + netbuffer->u.servercfg.playerdetected = LONG(playermask); + netbuffer->u.servercfg.gametic = (tic_t)LONG(gametic); + netbuffer->u.servercfg.clientnode = (UINT8)node; + netbuffer->u.servercfg.gamestate = (UINT8)gamestate; + netbuffer->u.servercfg.gametype = (UINT8)gametype; + netbuffer->u.servercfg.modifiedgame = (UINT8)modifiedgame; + netbuffer->u.servercfg.adminplayer = (SINT8)adminplayer; + memcpy(netbuffer->u.servercfg.server_context, server_context, 8); + op = p = netbuffer->u.servercfg.netcvarstates; + CV_SaveNetVars(&p); + { + const size_t len = sizeof (serverconfig_pak) + (size_t)(p - op); + +#ifdef DEBUGFILE + if (debugfile) + { + fprintf(debugfile, "ServerConfig Packet about to be sent, size of packet:%s to node:%d\n", + sizeu1(len), node); + } +#endif + + waspacketsent = HSendPacket(node, true, 0, len); + } + +#ifdef DEBUGFILE + if (debugfile) + { + if (waspacketsent) + { + fprintf(debugfile, "ServerConfig Packet was sent\n"); + } + else + { + fprintf(debugfile, "ServerConfig Packet could not be sent right now\n"); + } + } +#endif + + return waspacketsent; +} + +#ifdef JOININGAME +#define SAVEGAMESIZE (768*1024) + +static void SV_SendSaveGame(INT32 node) +{ + size_t length, compressedlen; + UINT8 *savebuffer; + UINT8 *compressedsave; + UINT8 *buffertosend; + + // first save it in a malloced buffer + savebuffer = (UINT8 *)malloc(SAVEGAMESIZE); + if (!savebuffer) + { + CONS_Alert(CONS_ERROR, M_GetText("No more free memory for savegame\n")); + return; + } + + // Leave room for the uncompressed length. + save_p = savebuffer + sizeof(size_t); + + P_SaveNetGame(); + + length = save_p - savebuffer; + if (length > SAVEGAMESIZE) + { + free(savebuffer); + save_p = NULL; + I_Error("Savegame buffer overrun"); + } + + // Allocate space for compressed save: one byte fewer than for the + // uncompressed data to ensure that the compression is worthwhile. + compressedsave = malloc(length - 1); + if (!compressedsave) + { + CONS_Alert(CONS_ERROR, M_GetText("No more free memory for savegame\n")); + return; + } + + // Attempt to compress it. + if((compressedlen = lzf_compress(savebuffer + sizeof(size_t), length - sizeof(size_t), compressedsave + sizeof(size_t), length - sizeof(size_t) - 1))) + { + // Compressing succeeded; send compressed data + + free(savebuffer); + + // State that we're compressed. + buffertosend = compressedsave; + WRITEUINT32(compressedsave, length - sizeof(size_t)); + length = compressedlen + sizeof(size_t); + } + else + { + // Compression failed to make it smaller; send original + + free(compressedsave); + + // State that we're not compressed + buffertosend = savebuffer; + WRITEUINT32(savebuffer, 0); + } + + SendRam(node, buffertosend, length, SF_RAM, 0); + save_p = NULL; +} + +#ifdef DUMPCONSISTENCY +#define TMPSAVENAME "badmath.sav" +static consvar_t cv_dumpconsistency = {"dumpconsistency", "Off", CV_NETVAR, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + +static void SV_SavedGame(void) +{ + size_t length; + UINT8 *savebuffer; + XBOXSTATIC char tmpsave[256]; + + if (!cv_dumpconsistency.value) + return; + + sprintf(tmpsave, "%s" PATHSEP TMPSAVENAME, srb2home); + + // first save it in a malloced buffer + save_p = savebuffer = (UINT8 *)malloc(SAVEGAMESIZE); + if (!save_p) + { + CONS_Alert(CONS_ERROR, M_GetText("No more free memory for savegame\n")); + return; + } + + P_SaveNetGame(); + + length = save_p - savebuffer; + if (length > SAVEGAMESIZE) + { + free(savebuffer); + save_p = NULL; + I_Error("Savegame buffer overrun"); + } + + // then save it! + if (!FIL_WriteFile(tmpsave, savebuffer, length)) + CONS_Printf(M_GetText("Didn't save %s for netgame"), tmpsave); + + free(savebuffer); + save_p = NULL; +} + +#undef TMPSAVENAME +#endif +#define TMPSAVENAME "$$$.sav" + + +static void CL_LoadReceivedSavegame(void) +{ + UINT8 *savebuffer = NULL; + size_t length, decompressedlen; + XBOXSTATIC char tmpsave[256]; + + sprintf(tmpsave, "%s" PATHSEP TMPSAVENAME, srb2home); + + length = FIL_ReadFile(tmpsave, &savebuffer); + + CONS_Printf(M_GetText("Loading savegame length %s\n"), sizeu1(length)); + if (!length) + { + I_Error("Can't read savegame sent"); + return; + } + + save_p = savebuffer; + + // Decompress saved game if necessary. + decompressedlen = READUINT32(save_p); + if(decompressedlen > 0) + { + UINT8 *decompressedbuffer = Z_Malloc(decompressedlen, PU_STATIC, NULL); + lzf_decompress(save_p, length - sizeof(size_t), decompressedbuffer, decompressedlen); + Z_Free(savebuffer); + save_p = savebuffer = decompressedbuffer; + } + + paused = false; + demoplayback = false; + titledemo = false; + automapactive = false; + + // load a base level + playerdeadview = false; + + if (P_LoadNetGame()) + { + const INT32 actnum = mapheaderinfo[gamemap-1]->actnum; + CONS_Printf(M_GetText("Map is now \"%s"), G_BuildMapName(gamemap)); + if (strcmp(mapheaderinfo[gamemap-1]->lvlttl, "")) + { + CONS_Printf(": %s", mapheaderinfo[gamemap-1]->lvlttl); + if (!(mapheaderinfo[gamemap-1]->levelflags & LF_NOZONE)) + CONS_Printf(M_GetText("ZONE")); + if (actnum > 0) + CONS_Printf(" %2d", actnum); + } + CONS_Printf("\"\n"); + } + else + { + CONS_Alert(CONS_ERROR, M_GetText("Can't load the level!\n")); + Z_Free(savebuffer); + save_p = NULL; + if (unlink(tmpsave) == -1) + CONS_Alert(CONS_ERROR, M_GetText("Can't delete %s"), tmpsave); + return; + } + + // done + Z_Free(savebuffer); + save_p = NULL; + if (unlink(tmpsave) == -1) + CONS_Alert(CONS_ERROR, M_GetText("Can't delete %s"), tmpsave); + consistancy[gametic%BACKUPTICS] = Consistancy(); + CON_ToggleOff(); +} +#endif + +#ifndef NONET +static void SendAskInfo(INT32 node, boolean viams) +{ + const tic_t asktime = I_GetTime(); + netbuffer->packettype = PT_ASKINFO; + netbuffer->u.askinfo.version = VERSION; + netbuffer->u.askinfo.time = (tic_t)LONG(asktime); + + // Even if this never arrives due to the host being firewalled, we've + // now allowed traffic from the host to us in, so once the MS relays + // our address to the host, it'll be able to speak to us. + HSendPacket(node, false, 0, sizeof (askinfo_pak)); + + // Also speak to the MS. + if (viams && node != 0 && node != BROADCASTADDR) + SendAskInfoViaMS(node, asktime); +} + +serverelem_t serverlist[MAXSERVERLIST]; +UINT32 serverlistcount = 0; + +static void SL_ClearServerList(INT32 connectedserver) +{ + UINT32 i; + + for (i = 0; i < serverlistcount; i++) + if (connectedserver != serverlist[i].node) + { + Net_CloseConnection(serverlist[i].node); + serverlist[i].node = 0; + } + serverlistcount = 0; +} + +static UINT32 SL_SearchServer(INT32 node) +{ + UINT32 i; + for (i = 0; i < serverlistcount; i++) + if (serverlist[i].node == node) + return i; + + return UINT32_MAX; +} + +static void SL_InsertServer(serverinfo_pak* info, SINT8 node) +{ + UINT32 i; + boolean moved; + + // search if not already on it + i = SL_SearchServer(node); + if (i == UINT32_MAX) + { + // not found add it + if (serverlistcount >= MAXSERVERLIST) + return; // list full + + if (info->version != VERSION) + return; // Not same version. + + if (info->subversion != SUBVERSION) + return; // Close, but no cigar. + + i = serverlistcount++; + } + + serverlist[i].info = *info; + serverlist[i].node = node; + + // list is sorted, so move the entry until it is sorted + do + { + INT32 keycurr = 0, keyprev = 0, keynext = 0; + switch(cv_serversort.value) + { + case 0: // Ping. + keycurr = (tic_t)LONG(serverlist[i].info.time); + if (i > 0) keyprev = (tic_t)LONG(serverlist[i-1].info.time); + if (i < serverlistcount - 1) keynext = (tic_t)LONG(serverlist[i+1].info.time); + break; + case 1: // Players. + keycurr = serverlist[i].info.numberofplayer; + if (i > 0) keyprev = serverlist[i-1].info.numberofplayer; + if (i < serverlistcount - 1) keynext = serverlist[i+1].info.numberofplayer; + break; + case 2: // Gametype. + keycurr = serverlist[i].info.gametype; + if (i > 0) keyprev = serverlist[i-1].info.gametype; + if (i < serverlistcount - 1) keynext = serverlist[i+1].info.gametype; + break; + } + + moved = false; + if (i > 0 && keycurr < keyprev) + { + serverelem_t s; + s = serverlist[i]; + serverlist[i] = serverlist[i-1]; + serverlist[i-1] = s; + i--; + moved = true; + } + else if (i < serverlistcount - 1 && keycurr > keynext) + { + serverelem_t s; + s = serverlist[i]; + serverlist[i] = serverlist[i+1]; + serverlist[i+1] = s; + i++; + moved = true; + } + } while (moved); +} + +void CL_UpdateServerList(boolean internetsearch, INT32 room) +{ + SL_ClearServerList(0); + + if (!netgame && I_NetOpenSocket) + { + MSCloseUDPSocket(); // Tidy up before wiping the slate. + if (I_NetOpenSocket()) + { + netgame = true; + multiplayer = true; + } + } + + // search for local servers + if (netgame) + SendAskInfo(BROADCASTADDR, false); + + if (internetsearch) + { + const msg_server_t *server_list; + INT32 i = -1; + server_list = GetShortServersList(room); + if (server_list) + { + char version[8] = ""; +#if VERSION > 0 || SUBVERSION > 0 + snprintf(version, sizeof (version), "%d.%d.%d", VERSION/100, VERSION%100, SUBVERSION); +#else + strcpy(version, GetRevisionString()); +#endif + version[sizeof (version) - 1] = '\0'; + + for (i = 0; server_list[i].header.buffer[0]; i++) + { + // Make sure MS version matches our own, to + // thwart nefarious servers who lie to the MS. + + if(strcmp(version, server_list[i].version) == 0) + { + INT32 node = I_NetMakeNodewPort(server_list[i].ip, server_list[i].port); + if (node == -1) + break; // no more node free + SendAskInfo(node, true); + } + } + } + + //no server list?(-1) or no servers?(0) + if (!i) + { + ; /// TODO: display error or warning? + } + } +} + +#endif // ifndef NONET + +// use adaptive send using net_bandwidth and stat.sendbytes +static void CL_ConnectToServer(boolean viams) +{ + INT32 pnumnodes, nodewaited = doomcom->numnodes, i; + boolean waitmore; + tic_t oldtic; +#ifndef NONET + tic_t asksent; +#endif +#ifdef JOININGAME + XBOXSTATIC char tmpsave[256]; + + sprintf(tmpsave, "%s" PATHSEP TMPSAVENAME, srb2home); +#endif + + cl_mode = cl_searching; + +#ifdef CLIENT_LOADINGSCREEN + lastfilenum = 0; +#endif + +#ifdef JOININGAME + // don't get a corrupt savegame error because tmpsave already exists + if (FIL_FileExists(tmpsave) && unlink(tmpsave) == -1) + I_Error("Can't delete %s\n", tmpsave); +#endif + + if (netgame) + { + if (servernode < 0 || servernode >= MAXNETNODES) + CONS_Printf(M_GetText("Searching for a server...\n")); + else + CONS_Printf(M_GetText("Contacting the server...\n")); + } + + if (gamestate == GS_INTERMISSION) + Y_EndIntermission(); // clean up intermission graphics etc + + DEBFILE(va("waiting %d nodes\n", doomcom->numnodes)); + G_SetGamestate(GS_WAITINGPLAYERS); + wipegamestate = GS_WAITINGPLAYERS; + + adminplayer = -1; + pnumnodes = 1; + oldtic = I_GetTime() - 1; +#ifndef NONET + asksent = (tic_t)-TICRATE; + + i = SL_SearchServer(servernode); + + if (i != -1) + { + INT32 j; + const char *gametypestr = NULL; + CONS_Printf(M_GetText("Connecting to: %s\n"), serverlist[i].info.servername); + for (j = 0; gametype_cons_t[j].strvalue; j++) + { + if (gametype_cons_t[j].value == serverlist[i].info.gametype) + { + gametypestr = gametype_cons_t[j].strvalue; + break; + } + } + if (gametypestr) + CONS_Printf(M_GetText("Gametype: %s\n"), gametypestr); + CONS_Printf(M_GetText("Version: %d.%.2d.%u\n"), serverlist[i].info.version/100, + serverlist[i].info.version%100, serverlist[i].info.subversion); + } + SL_ClearServerList(servernode); +#endif + + do + { + switch (cl_mode) + { + case cl_searching: +#ifndef NONET + // serverlist is updated by GetPacket function + if (serverlistcount > 0) + { + // this can be a responce to our broadcast request + if (servernode == -1 || servernode >= MAXNETNODES) + { + i = 0; + servernode = serverlist[i].node; + CONS_Printf(M_GetText("Found, ")); + } + else + { + i = SL_SearchServer(servernode); + if (i < 0) + break; // the case + } + + // Quit here rather than downloading files and being refused later. + if (serverlist[i].info.numberofplayer >= serverlist[i].info.maxplayer) + { + D_QuitNetGame(); + CL_Reset(); + D_StartTitle(); + M_StartMessage(va(M_GetText("Maximum players reached: %d\n\nPress ESC\n"), serverlist[i].info.maxplayer), NULL, MM_NOTHING); + return; + } + + if (!server) + { + D_ParseFileneeded(serverlist[i].info.fileneedednum, + serverlist[i].info.fileneeded); + CONS_Printf(M_GetText("Checking files...\n")); + i = CL_CheckFiles(); + if (i == 2) // cannot join for some reason + { + D_QuitNetGame(); + CL_Reset(); + D_StartTitle(); + M_StartMessage(M_GetText( + "You have WAD files loaded or have\n" + "modified the game in some way, and\n" + "your file list does not match\n" + "the server's file list.\n" + "Please restart SRB2 before connecting.\n\n" + "Press ESC\n" + ), NULL, MM_NOTHING); + return; + } + else if (i == 1) + cl_mode = cl_askjoin; + else + { + // must download something + // can we, though? + if (!CL_CheckDownloadable()) // nope! + { + D_QuitNetGame(); + CL_Reset(); + D_StartTitle(); + M_StartMessage(M_GetText( + "You cannot conect to this server\n" + "because you cannot download the files\n" + "that you are missing from the server.\n\n" + "See the console or log file for\n" + "more details.\n\n" + "Press ESC\n" + ), NULL, MM_NOTHING); + return; + } + // no problem if can't send packet, we will retry later + if (CL_SendRequestFile()) + cl_mode = cl_downloadfiles; + } + } + else + cl_mode = cl_askjoin; // files need not be checked for the server. + break; + } + // ask the info to the server (askinfo packet) + if (asksent + NEWTICRATE < I_GetTime()) + { + SendAskInfo(servernode, viams); + asksent = I_GetTime(); + } +#else + (void)viams; + // No netgames, so we skip this state. + cl_mode = cl_askjoin; +#endif // ifndef NONET/else + break; + case cl_downloadfiles: + waitmore = false; + for (i = 0; i < fileneedednum; i++) + if (fileneeded[i].status == FS_DOWNLOADING + || fileneeded[i].status == FS_REQUESTED) + { + waitmore = true; + break; + } + if (waitmore) + break; // exit the case + + cl_mode = cl_askjoin; // don't break case continue to cljoin request now + case cl_askjoin: + CL_LoadServerFiles(); +#ifdef JOININGAME + // prepare structures to save the file + // WARNING: this can be useless in case of server not in GS_LEVEL + // but since the network layer doesn't provide ordered packets... + CL_PrepareDownloadSaveGame(tmpsave); +#endif + if (CL_SendJoin()) + cl_mode = cl_waitjoinresponse; + break; +#ifdef JOININGAME + case cl_downloadsavegame: + if (fileneeded[0].status == FS_FOUND) + { + // Gamestate is now handled within CL_LoadReceivedSavegame() + CL_LoadReceivedSavegame(); + cl_mode = cl_connected; + } // don't break case continue to cl_connected + else + break; +#endif + case cl_waitjoinresponse: + case cl_connected: + default: + break; + + // Connection closed by cancel, timeout or refusal. + case cl_aborted: + cl_mode = cl_searching; + return; + } + + GetPackets(); + Net_AckTicker(); + + // call it only one by tic + if (oldtic != I_GetTime()) + { + INT32 key; + + I_OsPolling(); + key = I_GetKey(); + if (key == KEY_ESCAPE) + { + CONS_Printf(M_GetText("Network game synchronization aborted.\n")); +// M_StartMessage(M_GetText("Network game synchronization aborted.\n\nPress ESC\n"), NULL, MM_NOTHING); + D_QuitNetGame(); + CL_Reset(); + D_StartTitle(); + return; + } + + // why are these here? this is for servers, we're a client + //if (key == 's' && server) + // doomcom->numnodes = (INT16)pnumnodes; + //FiletxTicker(); + oldtic = I_GetTime(); + +#ifdef CLIENT_LOADINGSCREEN + if (!server && cl_mode != cl_connected && cl_mode != cl_aborted) + { + F_TitleScreenTicker(true); + F_TitleScreenDrawer(); + CL_DrawConnectionStatus(); + I_UpdateNoVsync(); // page flip or blit buffer + if (moviemode) + M_SaveFrame(); + } +#else + CON_Drawer(); + I_UpdateNoVsync(); +#endif + } + else I_Sleep(); + + if (server) + { + pnumnodes = 0; + for (i = 0; i < MAXNETNODES; i++) + if (nodeingame[i]) pnumnodes++; + } + } + while (!(cl_mode == cl_connected && (!server || (server && nodewaited <= pnumnodes)))); + + DEBFILE(va("Synchronisation Finished\n")); + + displayplayer = consoleplayer; +} + +#ifndef NONET +typedef struct banreason_s +{ + char *reason; + struct banreason_s *prev; //-1 + struct banreason_s *next; //+1 +} banreason_t; + +static banreason_t *reasontail = NULL; //last entry, use prev +static banreason_t *reasonhead = NULL; //1st entry, use next + +static void Command_ShowBan(void) //Print out ban list +{ + size_t i; + const char *address, *mask; + banreason_t *reasonlist = reasonhead; + + if (I_GetBanAddress) + CONS_Printf(M_GetText("Ban List:\n")); + else + return; + + for (i = 0;(address = I_GetBanAddress(i)) != NULL;i++) + { + if (!I_GetBanMask || (mask = I_GetBanMask(i)) == NULL) + CONS_Printf("%s: %s ", sizeu1(i+1), address); + else + CONS_Printf("%s: %s/%s ", sizeu1(i+1), address, mask); + + if (reasonlist && reasonlist->reason) + CONS_Printf("(%s)\n", reasonlist->reason); + else + CONS_Printf("\n"); + + if (reasonlist) reasonlist = reasonlist->next; + } + + if (i == 0 && !address) + CONS_Printf(M_GetText("(empty)\n")); +} + +void D_SaveBan(void) +{ + FILE *f; + size_t i; + banreason_t *reasonlist = reasonhead; + const char *address, *mask; + + if (!reasonhead) + return; + + f = fopen(va("%s"PATHSEP"%s", srb2home, "ban.txt"), "w"); + + if (!f) + { + CONS_Alert(CONS_WARNING, M_GetText("Could not save ban list into ban.txt\n")); + return; + } + + for (i = 0;(address = I_GetBanAddress(i)) != NULL;i++) + { + if (!I_GetBanMask || (mask = I_GetBanMask(i)) == NULL) + fprintf(f, "%s 0", address); + else + fprintf(f, "%s %s", address, mask); + + if (reasonlist && reasonlist->reason) + fprintf(f, " %s\n", reasonlist->reason); + else + fprintf(f, " %s\n", "NA"); + + if (reasonlist) reasonlist = reasonlist->next; + } + + fclose(f); +} + +static void Ban_Add(const char *reason) +{ + banreason_t *reasonlist = malloc(sizeof(*reasonlist)); + + if (!reasonlist) + return; + if (!reason) + reason = "NA"; + + reasonlist->next = NULL; + reasonlist->reason = Z_StrDup(reason); + if ((reasonlist->prev = reasontail) == NULL) + reasonhead = reasonlist; + else + reasontail->next = reasonlist; + reasontail = reasonlist; +} + +static void Command_ClearBans(void) +{ + banreason_t *temp; + + if (!I_ClearBans) + return; + + I_ClearBans(); + reasontail = NULL; + while (reasonhead) + { + temp = reasonhead->next; + Z_Free(reasonhead->reason); + free(reasonhead); + reasonhead = temp; + } +} + +static void Ban_Load_File(boolean warning) +{ + FILE *f; + size_t i; + const char *address, *mask; + char buffer[MAX_WADPATH]; + + f = fopen(va("%s"PATHSEP"%s", srb2home, "ban.txt"), "r"); + + if (!f) + { + if (warning) + CONS_Alert(CONS_WARNING, M_GetText("Could not open ban.txt for ban list\n")); + return; + } + + if (I_ClearBans) + Command_ClearBans(); + else + { + fclose(f); + return; + } + + for (i=0; fgets(buffer, (int)sizeof(buffer), f); i++) + { + address = strtok(buffer, " \t\r\n"); + mask = strtok(NULL, " \t\r\n"); + + I_SetBanAddress(address, mask); + + Ban_Add(strtok(NULL, "\r\n")); + } + + fclose(f); +} + +static void Command_ReloadBan(void) //recheck ban.txt +{ + Ban_Load_File(true); +} + +static void Command_connect(void) +{ + // Assume we connect directly. + boolean viams = false; + + if (COM_Argc() < 2) + { + CONS_Printf(M_GetText( + "Connect (port): connect to a server\n" + "Connect ANY: connect to the first lan server found\n" + "Connect SELF: connect to your own server.\n")); + return; + } + + if (Playing()) + { + CONS_Printf(M_GetText("You cannot connect while in a game. End this game first.\n")); + return; + } + + // modified game check: no longer handled + // we don't request a restart unless the filelist differs + + server = false; + + if (!stricmp(COM_Argv(1), "self")) + { + servernode = 0; + server = true; + /// \bug should be but... + //SV_SpawnServer(); + } + else + { + // used in menu to connect to a server in the list + if (netgame && !stricmp(COM_Argv(1), "node")) + { + servernode = (SINT8)atoi(COM_Argv(2)); + + // Use MS to traverse NAT firewalls. + viams = true; + } + else if (netgame) + { + CONS_Printf(M_GetText("You cannot connect while in a game. End this game first.\n")); + return; + } + else if (I_NetOpenSocket) + { + MSCloseUDPSocket(); // Tidy up before wiping the slate. + I_NetOpenSocket(); + netgame = true; + multiplayer = true; + + if (!stricmp(COM_Argv(1), "any")) + servernode = BROADCASTADDR; + else if (I_NetMakeNodewPort && COM_Argc() >= 3) + servernode = I_NetMakeNodewPort(COM_Argv(1), COM_Argv(2)); + else if (I_NetMakeNodewPort) + servernode = I_NetMakeNode(COM_Argv(1)); + else + { + CONS_Alert(CONS_ERROR, M_GetText("There is no server identification with this network driver\n")); + D_CloseConnection(); + return; + } + } + else + CONS_Alert(CONS_ERROR, M_GetText("There is no network driver\n")); + } + + splitscreen = false; + SplitScreen_OnChange(); + botingame = false; + botskin = 0; + CL_ConnectToServer(viams); +} +#endif + +static void ResetNode(INT32 node); + +// +// CL_ClearPlayer +// +// Clears the player data so that a future client can use this slot +// +void CL_ClearPlayer(INT32 playernum) +{ + if (players[playernum].mo) + { + // Don't leave a NiGHTS ghost! + if ((players[playernum].pflags & PF_NIGHTSMODE) && players[playernum].mo->tracer) + P_RemoveMobj(players[playernum].mo->tracer); + P_RemoveMobj(players[playernum].mo); + } + players[playernum].mo = NULL; + memset(&players[playernum], 0, sizeof (player_t)); +} + +// +// CL_RemovePlayer +// +// Removes a player from the current game +// +static void CL_RemovePlayer(INT32 playernum) +{ + // Sanity check: exceptional cases (i.e. c-fails) can cause multiple + // kick commands to be issued for the same player. + if (!playeringame[playernum]) + return; + + if (server && !demoplayback) + { + INT32 node = playernode[playernum]; + playerpernode[node]--; + if (playerpernode[node] <= 0) + { + nodeingame[playernode[playernum]] = false; + Net_CloseConnection(playernode[playernum]); + ResetNode(node); + } + } + + if (gametype == GT_CTF) + P_PlayerFlagBurst(&players[playernum], false); // Don't take the flag with you! + + // If in a special stage, redistribute the player's rings across + // the remaining players. + if (G_IsSpecialStage(gamemap)) + { + INT32 i, count, increment, rings; + + for (i = 0, count = 0; i < MAXPLAYERS; i++) + { + if (playeringame[i]) + count++; + } + + count--; + rings = players[playernum].health - 1; + increment = rings/count; + + for (i = 0; i < MAXPLAYERS; i++) + { + if (playeringame[i] && i != playernum) + { + if (rings < increment) + P_GivePlayerRings(&players[i], rings); + else + P_GivePlayerRings(&players[i], increment); + + rings -= increment; + } + } + } + + // Reset player data + CL_ClearPlayer(playernum); + + // remove avatar of player + playeringame[playernum] = false; + playernode[playernum] = UINT8_MAX; + while (!playeringame[doomcom->numslots-1] && doomcom->numslots > 1) + doomcom->numslots--; + + // Reset the name + sprintf(player_names[playernum], "Player %d", playernum+1); + + if (playernum == adminplayer) + adminplayer = -1; // don't stay admin after you're gone + + if (playernum == displayplayer) + displayplayer = consoleplayer; // don't look through someone's view who isn't there + + consfailcount[playernum] = 0; + consfailstatus[playernum] = 0; + +#ifdef HAVE_BLUA + LUA_InvalidatePlayer(&players[playernum]); +#endif + + if (G_TagGametype()) //Check if you still have a game. Location flexible. =P + P_CheckSurvivors(); + else if (gametype == GT_RACE || gametype == GT_COMPETITION) + P_CheckRacers(); +} + +void CL_Reset(void) +{ + if (demorecording || metalrecording) + G_CheckDemoStatus(); + + // reset client/server code + DEBFILE(va("\n-=-=-=-=-=-=-= Client reset =-=-=-=-=-=-=-\n\n")); + + if (servernode > 0 && servernode < MAXNETNODES) + { + nodeingame[(UINT8)servernode] = false; + Net_CloseConnection(servernode); + } + D_CloseConnection(); // netgame = false + multiplayer = false; + servernode = 0; + server = true; + doomcom->numnodes = 1; + doomcom->numslots = 1; + SV_StopServer(); + SV_ResetServer(); + + // D_StartTitle should get done now, but the calling function will handle it +} + +#ifndef NONET +static void Command_GetPlayerNum(void) +{ + INT32 i; + + for (i = 0; i < MAXPLAYERS; i++) + if (playeringame[i]) + { + if (serverplayer == i) + CONS_Printf(M_GetText("num:%2d node:%2d %s\n"), i, playernode[i], player_names[i]); + else + CONS_Printf(M_GetText("\x82num:%2d node:%2d %s\n"), i, playernode[i], player_names[i]); + } +} + +SINT8 nametonum(const char *name) +{ + INT32 playernum, i; + + if (!strcmp(name, "0")) + return 0; + + playernum = (SINT8)atoi(name); + + if (playernum < 0 || playernum >= MAXPLAYERS) + return -1; + + if (playernum) + { + if (playeringame[playernum]) + return (SINT8)playernum; + else + return -1; + } + + for (i = 0; i < MAXPLAYERS; i++) + if (playeringame[i] && !stricmp(player_names[i], name)) + return (SINT8)i; + + CONS_Printf(M_GetText("There is no player named \"%s\"\n"), name); + + return -1; +} + +/** Lists all players and their player numbers. + * + * \sa Command_GetPlayerNum + */ +static void Command_Nodes(void) +{ + INT32 i; + size_t maxlen = 0; + const char *address; + + for (i = 0; i < MAXPLAYERS; i++) + { + const size_t plen = strlen(player_names[i]); + if (playeringame[i] && plen > maxlen) + maxlen = plen; + } + + for (i = 0; i < MAXPLAYERS; i++) + { + if (playeringame[i]) + { + CONS_Printf("%.2u: %*s", i, (int)maxlen, player_names[i]); + CONS_Printf(" - %.2d", playernode[i]); + if (I_GetNodeAddress && (address = I_GetNodeAddress(playernode[i])) != NULL) + CONS_Printf(" - %s", address); + + if (i == adminplayer) + CONS_Printf(M_GetText(" (verified admin)")); + + if (players[i].spectator) + CONS_Printf(M_GetText(" (spectator)")); + + CONS_Printf("\n"); + } + } +} + +static void Command_Ban(void) +{ + if (COM_Argc() == 1) + { + CONS_Printf(M_GetText("Ban : ban and kick a player\n")); + return; + } + + if (server || adminplayer == consoleplayer) + { + XBOXSTATIC UINT8 buf[3 + MAX_REASONLENGTH]; + UINT8 *p = buf; + const SINT8 pn = nametonum(COM_Argv(1)); + const INT32 node = playernode[(INT32)pn]; + + if (pn == -1 || pn == 0) + return; + else + WRITEUINT8(p, pn); + if (I_Ban && !I_Ban(node)) + { + CONS_Alert(CONS_WARNING, M_GetText("Too many bans! Geez, that's a lot of people you're excluding...\n")); + WRITEUINT8(p, KICK_MSG_GO_AWAY); + SendNetXCmd(XD_KICK, &buf, 2); + } + else + { + Ban_Add(COM_Argv(2)); + + if (COM_Argc() == 2) + { + WRITEUINT8(p, KICK_MSG_BANNED); + SendNetXCmd(XD_KICK, &buf, 2); + } + else + { + size_t i, j = COM_Argc(); + char message[MAX_REASONLENGTH]; + + //Steal from the motd code so you don't have to put the reason in quotes. + strlcpy(message, COM_Argv(2), sizeof message); + for (i = 3; i < j; i++) + { + strlcat(message, " ", sizeof message); + strlcat(message, COM_Argv(i), sizeof message); + } + + WRITEUINT8(p, KICK_MSG_CUSTOM_BAN); + WRITESTRINGN(p, message, MAX_REASONLENGTH); + SendNetXCmd(XD_KICK, &buf, p - buf); + } + } + } + else + CONS_Printf(M_GetText("Only the server or a remote admin can use this.\n")); + +} + +static void Command_Kick(void) +{ + XBOXSTATIC UINT8 buf[3 + MAX_REASONLENGTH]; + UINT8 *p = buf; + + if (COM_Argc() == 1) + { + CONS_Printf(M_GetText("kick : kick a player\n")); + return; + } + + if (server || adminplayer == consoleplayer) + { + const SINT8 pn = nametonum(COM_Argv(1)); + WRITESINT8(p, pn); + if (pn == -1 || pn == 0) + return; + if (COM_Argc() == 2) + { + WRITEUINT8(p, KICK_MSG_GO_AWAY); + SendNetXCmd(XD_KICK, &buf, 2); + } + else + { + size_t i, j = COM_Argc(); + char message[MAX_REASONLENGTH]; + + //Steal from the motd code so you don't have to put the reason in quotes. + strlcpy(message, COM_Argv(2), sizeof message); + for (i = 3; i < j; i++) + { + strlcat(message, " ", sizeof message); + strlcat(message, COM_Argv(i), sizeof message); + } + + WRITEUINT8(p, KICK_MSG_CUSTOM_KICK); + WRITESTRINGN(p, message, MAX_REASONLENGTH); + SendNetXCmd(XD_KICK, &buf, p - buf); + } + } + else + CONS_Printf(M_GetText("Only the server or a remote admin can use this.\n")); +} +#endif + +static void Got_KickCmd(UINT8 **p, INT32 playernum) +{ + INT32 pnum, msg; + XBOXSTATIC char buf[3 + MAX_REASONLENGTH]; + char *reason = buf; + + pnum = READUINT8(*p); + msg = READUINT8(*p); + + if (pnum == serverplayer && playernum == adminplayer) + { + CONS_Printf(M_GetText("Server is being shut down remotely. Goodbye!\n")); + + if (server) + COM_BufAddText("quit\n"); + + return; + } + + // Is playernum authorized to make this kick? + if (playernum != serverplayer && playernum != adminplayer + && !(playerpernode[playernode[playernum]] == 2 + && nodetoplayer2[playernode[playernum]] == pnum)) + { + // We received a kick command from someone who isn't the + // server or admin, and who isn't in splitscreen removing + // player 2. Thus, it must be someone with a modified + // binary, trying to kick someone but without having + // authorization. + + // We deal with this by changing the kick reason to + // "consistency failure" and kicking the offending user + // instead. + + // Note: Splitscreen in netgames is broken because of + // this. Only the server has any idea of which players + // are using splitscreen on the same computer, so + // clients cannot always determine if a kick is + // legitimate. + + CONS_Alert(CONS_WARNING, M_GetText("Illegal kick command received from %s for player %d\n"), player_names[playernum], pnum); + + // In debug, print a longer message with more details. + // TODO Callum: Should we translate this? +/* + CONS_Debug(DBG_NETPLAY, + "So, you must be asking, why is this an illegal kick?\n" + "Well, let's take a look at the facts, shall we?\n" + "\n" + "playernum (this is the guy who did it), he's %d.\n" + "pnum (the guy he's trying to kick) is %d.\n" + "playernum's node is %d.\n" + "That node has %d players.\n" + "Player 2 on that node is %d.\n" + "pnum's node is %d.\n" + "That node has %d players.\n" + "Player 2 on that node is %d.\n" + "\n" + "If you think this is a bug, please report it, including all of the details above.\n", + playernum, pnum, + playernode[playernum], playerpernode[playernode[playernum]], + nodetoplayer2[playernode[playernum]], + playernode[pnum], playerpernode[playernode[pnum]], + nodetoplayer2[playernode[pnum]]); +*/ + pnum = playernum; + msg = KICK_MSG_CON_FAIL; + } + + CONS_Printf("\x82%s ", player_names[pnum]); + + // If a verified admin banned someone, the server needs to know about it. + // If the playernum isn't zero (the server) then the server needs to record the ban. + if (server && playernum && msg == KICK_MSG_BANNED) + { + if (I_Ban && !I_Ban(playernode[(INT32)pnum])) + { + CONS_Alert(CONS_WARNING, M_GetText("Too many bans! Geez, that's a lot of people you're excluding...\n")); + } + } + + switch (msg) + { + case KICK_MSG_GO_AWAY: + CONS_Printf(M_GetText("has been kicked (Go away)\n")); + break; +#ifdef NEWPING + case KICK_MSG_PING_HIGH: + CONS_Printf(M_GetText("left the game (Broke ping limit)\n")); + break; +#endif + case KICK_MSG_CON_FAIL: + CONS_Printf(M_GetText("left the game (Consistency failure)\n")); + + if (M_CheckParm("-consisdump")) // Helps debugging some problems + { + INT32 i; + + CONS_Printf(M_GetText("Player kicked is #%d, dumping consistency...\n"), pnum); + + for (i = 0; i < MAXPLAYERS; i++) + { + if (!playeringame[i]) + continue; + CONS_Printf("-------------------------------------\n"); + CONS_Printf("Player %d: %s\n", i, player_names[i]); + CONS_Printf("Skin: %d\n", players[i].skin); + CONS_Printf("Color: %d\n", players[i].skincolor); + CONS_Printf("Speed: %d\n",players[i].speed>>FRACBITS); + if (players[i].mo) + { + if (!players[i].mo->skin) + CONS_Printf("Mobj skin: NULL!\n"); + else + CONS_Printf("Mobj skin: %s\n", ((skin_t *)players[i].mo->skin)->name); + CONS_Printf("Position: %d, %d, %d\n", players[i].mo->x, players[i].mo->y, players[i].mo->z); + if (!players[i].mo->state) + CONS_Printf("State: S_NULL\n"); + else + CONS_Printf("State: %d\n", (statenum_t)(players[i].mo->state-states)); + } + else + CONS_Printf("Mobj: NULL\n"); + CONS_Printf("-------------------------------------\n"); + } + } + break; + case KICK_MSG_TIMEOUT: + CONS_Printf(M_GetText("left the game (Connection timeout)\n")); + break; + case KICK_MSG_PLAYER_QUIT: + if (netgame) // not splitscreen/bots + CONS_Printf(M_GetText("left the game\n")); + break; + case KICK_MSG_BANNED: + CONS_Printf(M_GetText("has been banned (Don't come back)\n")); + break; + case KICK_MSG_CUSTOM_KICK: + READSTRINGN(*p, reason, MAX_REASONLENGTH+1); + CONS_Printf(M_GetText("has been kicked (%s)\n"), reason); + break; + case KICK_MSG_CUSTOM_BAN: + READSTRINGN(*p, reason, MAX_REASONLENGTH+1); + CONS_Printf(M_GetText("has been banned (%s)\n"), reason); + break; + } + + if (pnum == consoleplayer) + { +#ifdef DUMPCONSISTENCY + if (msg == KICK_MSG_CON_FAIL) SV_SavedGame(); +#endif + D_QuitNetGame(); + CL_Reset(); + D_StartTitle(); + if (msg == KICK_MSG_CON_FAIL) + { + M_StartMessage(M_GetText("Server closed connection\n(consistency failure)\nPress ESC\n"), NULL, + MM_NOTHING); + } +#ifdef NEWPING + else if (msg == KICK_MSG_PING_HIGH) + M_StartMessage(M_GetText("Server closed connection\n(Broke ping limit)\nPress ESC\n"), NULL, MM_NOTHING); +#endif + else if (msg == KICK_MSG_BANNED) + M_StartMessage(M_GetText("You have been banned by the server\n\nPress ESC\n"), NULL, MM_NOTHING); + else if (msg == KICK_MSG_CUSTOM_KICK) + M_StartMessage(va(M_GetText("You have been kicked\n(%s)\nPress ESC\n"), reason), NULL, MM_NOTHING); + else if (msg == KICK_MSG_CUSTOM_BAN) + M_StartMessage(va(M_GetText("You have been banned\n(%s)\nPress ESC\n"), reason), NULL, MM_NOTHING); + else + M_StartMessage(M_GetText("You have been kicked by the server\n\nPress ESC\n"), NULL, MM_NOTHING); + } + else + CL_RemovePlayer(pnum); +} + +consvar_t cv_allownewplayer = {"allowjoin", "On", CV_NETVAR, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL }; +consvar_t cv_joinnextround = {"joinnextround", "Off", CV_NETVAR, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; /// \todo not done +static CV_PossibleValue_t maxplayers_cons_t[] = {{2, "MIN"}, {32, "MAX"}, {0, NULL}}; +consvar_t cv_maxplayers = {"maxplayers", "8", CV_SAVE, maxplayers_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +static CV_PossibleValue_t consfailprotect_cons_t[] = {{0, "MIN"}, {20, "MAX"}, {0, NULL}}; +consvar_t cv_consfailprotect = {"consfailprotect", "10", 0, consfailprotect_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL }; +consvar_t cv_blamecfail = {"blamecfail", "Off", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL }; + +// max file size to send to a player (in kilobytes) +static CV_PossibleValue_t maxsend_cons_t[] = {{0, "MIN"}, {51200, "MAX"}, {0, NULL}}; +consvar_t cv_maxsend = {"maxsend", "1024", CV_SAVE, maxsend_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; + +static void Got_AddPlayer(UINT8 **p, INT32 playernum); + +// called one time at init +void D_ClientServerInit(void) +{ + DEBFILE(va("- - -== SRB2 v%d.%.2d.%d "VERSIONSTRING" debugfile ==- - -\n", + VERSION/100, VERSION%100, SUBVERSION)); + +#ifndef NONET + COM_AddCommand("getplayernum", Command_GetPlayerNum); + COM_AddCommand("kick", Command_Kick); + COM_AddCommand("ban", Command_Ban); + COM_AddCommand("clearbans", Command_ClearBans); + COM_AddCommand("showbanlist", Command_ShowBan); + COM_AddCommand("reloadbans", Command_ReloadBan); + COM_AddCommand("connect", Command_connect); + COM_AddCommand("nodes", Command_Nodes); +#endif + + RegisterNetXCmd(XD_KICK, Got_KickCmd); + RegisterNetXCmd(XD_ADDPLAYER, Got_AddPlayer); +#ifndef NONET + CV_RegisterVar(&cv_allownewplayer); + CV_RegisterVar(&cv_joinnextround); + CV_RegisterVar(&cv_showjoinaddress); + CV_RegisterVar(&cv_consfailprotect); + CV_RegisterVar(&cv_blamecfail); +#ifdef DUMPCONSISTENCY + CV_RegisterVar(&cv_dumpconsistency); +#endif + Ban_Load_File(false); +#endif + + gametic = 0; + localgametic = 0; + + // do not send anything before the real begin + SV_StopServer(); + SV_ResetServer(); + if (dedicated) + SV_SpawnServer(); +} + +static void ResetNode(INT32 node) +{ + nodeingame[node] = false; + nodetoplayer[node] = -1; + nodetoplayer2[node] = -1; + nettics[node] = gametic; + supposedtics[node] = gametic; + nodewaiting[node] = 0; + playerpernode[node] = 0; +} + +void SV_ResetServer(void) +{ + INT32 i; + + // +1 because this command will be executed in com_executebuffer in + // tryruntic so gametic will be incremented, anyway maketic > gametic + // is not a issue + + maketic = gametic + 1; + neededtic = maketic; + tictoclear = maketic; + + for (i = 0; i < MAXNETNODES; i++) + ResetNode(i); + + for (i = 0; i < MAXPLAYERS; i++) + { +#ifdef HAVE_BLUA + LUA_InvalidatePlayer(&players[i]); +#endif + playeringame[i] = false; + playernode[i] = UINT8_MAX; + sprintf(player_names[i], "Player %d", i + 1); + } + + mynode = 0; + cl_packetmissed = false; + + if (dedicated) + { + nodeingame[0] = true; + serverplayer = 0; + } + else + serverplayer = consoleplayer; + + if (server) + servernode = 0; + + doomcom->numslots = 0; + + // clear server_context + memset(server_context, '-', 8); + + DEBFILE("\n-=-=-=-=-=-=-= Server Reset =-=-=-=-=-=-=-\n\n"); +} + +static inline void SV_GenContext(void) +{ + UINT8 i; + // generate server_context, as exactly 8 bytes of randomly mixed A-Z and a-z + // (hopefully M_Random is initialized!! if not this will be awfully silly!) + for (i = 0; i < 8; i++) + { + const char a = M_RandomKey(26*2); + if (a <= 26) // uppercase + server_context[i] = 'A'+a; + else // lowercase + server_context[i] = 'a'+(a-26); + } +} + +// +// D_QuitNetGame +// Called before quitting to leave a net game +// without hanging the other players +// +void D_QuitNetGame(void) +{ + if (!netgame || !netbuffer) + return; + + DEBFILE("===========================================================================\n" + " Quitting Game, closing connection\n" + "===========================================================================\n"); + + // abort send/receive of files + CloseNetFile(); + + if (server) + { + INT32 i; + + netbuffer->packettype = PT_SERVERSHUTDOWN; + for (i = 0; i < MAXNETNODES; i++) + if (nodeingame[i]) + HSendPacket(i, true, 0, 0); + if (serverrunning && ms_RoomId > 0) + UnregisterServer(); + } + else if (servernode > 0 && servernode < MAXNETNODES && nodeingame[(UINT8)servernode]!=0) + { + netbuffer->packettype = PT_CLIENTQUIT; + HSendPacket(servernode, true, 0, 0); + } + + D_CloseConnection(); + adminplayer = -1; + + DEBFILE("===========================================================================\n" + " Log finish\n" + "===========================================================================\n"); +#ifdef DEBUGFILE + if (debugfile) + { + fclose(debugfile); + debugfile = NULL; + } +#endif +} + +// add a node to the game (player will follow at map change or at savegame....) +static inline void SV_AddNode(INT32 node) +{ + nettics[node] = gametic; + supposedtics[node] = gametic; + // little hack because the server connect to itself and put + // nodeingame when connected not here + if (node) + nodeingame[node] = true; +} + +// Xcmd XD_ADDPLAYER +static void Got_AddPlayer(UINT8 **p, INT32 playernum) +{ + INT16 node, newplayernum; + boolean splitscreenplayer; + + if (playernum != serverplayer && playernum != adminplayer) + { + // protect against hacked/buggy client + CONS_Alert(CONS_WARNING, M_GetText("Illegal add player command received from %s\n"), player_names[playernum]); + if (server) + { + XBOXSTATIC UINT8 buf[2]; + + buf[0] = (UINT8)playernum; + buf[1] = KICK_MSG_CON_FAIL; + SendNetXCmd(XD_KICK, &buf, 2); + } + return; + } + + node = READUINT8(*p); + newplayernum = READUINT8(*p); + splitscreenplayer = newplayernum & 0x80; + newplayernum &= ~0x80; + + // Clear player before joining, lest some things get set incorrectly + // HACK: don't do this for splitscreen, it relies on preset values + if (!splitscreen && !botingame) + CL_ClearPlayer(newplayernum); + playeringame[newplayernum] = true; + G_AddPlayer(newplayernum); + if (newplayernum+1 > doomcom->numslots) + doomcom->numslots = (INT16)(newplayernum+1); + + if (netgame) + CONS_Printf(M_GetText("Player %d has joined the game (node %d)\n"), newplayernum+1, node); + + // the server is creating my player + if (node == mynode) + { + playernode[newplayernum] = 0; // for information only + if (!splitscreenplayer) + { + consoleplayer = newplayernum; + displayplayer = newplayernum; + secondarydisplayplayer = newplayernum; + DEBFILE("spawning me\n"); + } + else + { + secondarydisplayplayer = newplayernum; + DEBFILE("spawning my brother\n"); + if (botingame) + players[newplayernum].bot = 1; + } + D_SendPlayerConfig(); + addedtogame = true; + } + else if (server && netgame && cv_showjoinaddress.value) + { + const char *address; + if (I_GetNodeAddress && (address = I_GetNodeAddress(node)) != NULL) + CONS_Printf(M_GetText("Player Address is %s\n"), address); + } + + if (server && multiplayer && motd[0] != '\0') + COM_BufAddText(va("sayto %d %s\n", newplayernum, motd)); + +#ifdef HAVE_BLUA + LUAh_PlayerJoin(newplayernum); +#endif +} + +static boolean SV_AddWaitingPlayers(void) +{ + INT32 node, n, newplayer = false; + XBOXSTATIC UINT8 buf[2]; + UINT8 newplayernum = 0; + + // What is the reason for this? Why can't newplayernum always be 0? + if (dedicated) + newplayernum = 1; + + for (node = 0; node < MAXNETNODES; node++) + { + // splitscreen can allow 2 player in one node + for (; nodewaiting[node] > 0; nodewaiting[node]--) + { + newplayer = true; + + // search for a free playernum + // we can't use playeringame since it is not updated here + for (; newplayernum < MAXPLAYERS; newplayernum++) + { + for (n = 0; n < MAXNETNODES; n++) + if (nodetoplayer[n] == newplayernum || nodetoplayer2[n] == newplayernum) + break; + if (n == MAXNETNODES) + break; + } + + // should never happen since we check the playernum + // before accepting the join + I_Assert(newplayernum < MAXPLAYERS); + + playernode[newplayernum] = (UINT8)node; + + buf[0] = (UINT8)node; + buf[1] = newplayernum; + if (playerpernode[node] < 1) + nodetoplayer[node] = newplayernum; + else + { + nodetoplayer2[node] = newplayernum; + buf[1] |= 0x80; + } + playerpernode[node]++; + + SendNetXCmd(XD_ADDPLAYER, &buf, 2); + + DEBFILE(va("Server added player %d node %d\n", newplayernum, node)); + // use the next free slot (we can't put playeringame[newplayernum] = true here) + newplayernum++; + } + } + + return newplayer; +} + +void CL_AddSplitscreenPlayer(void) +{ + if (cl_mode == cl_connected) + CL_SendJoin(); +} + +void CL_RemoveSplitscreenPlayer(void) +{ + XBOXSTATIC UINT8 buf[2]; + + if (cl_mode != cl_connected) + return; + + buf[0] = (UINT8)secondarydisplayplayer; + buf[1] = KICK_MSG_PLAYER_QUIT; + SendNetXCmd(XD_KICK, &buf, 2); +} + +// is there a game running +boolean Playing(void) +{ + return (server && serverrunning) || (!server && cl_mode == cl_connected); +} + +boolean SV_SpawnServer(void) +{ + if (demoplayback || metalplayback) + G_StopDemo(); // reset engine parameter + + if (!serverrunning) + { + CONS_Printf(M_GetText("Starting Server....\n")); + serverrunning = true; + SV_ResetServer(); + SV_GenContext(); + if (netgame && I_NetOpenSocket) + { + MSCloseUDPSocket(); // Tidy up before wiping the slate. + I_NetOpenSocket(); + if (ms_RoomId > 0) + RegisterServer(); + } + + // non dedicated server just connect to itself + if (!dedicated) + CL_ConnectToServer(false); + else doomcom->numslots = 1; + } + + return SV_AddWaitingPlayers(); +} + +void SV_StopServer(void) +{ + tic_t i; + + if (gamestate == GS_INTERMISSION) + Y_EndIntermission(); + gamestate = wipegamestate = GS_NULL; + + localtextcmd[0] = 0; + localtextcmd2[0] = 0; + + for (i = 0; i < BACKUPTICS; i++) + D_Clearticcmd(i); + + consoleplayer = 0; + cl_mode = cl_searching; + maketic = gametic+1; + neededtic = maketic; + serverrunning = false; +} + +// called at singleplayer start and stopdemo +void SV_StartSinglePlayerServer(void) +{ + server = true; + netgame = false; + multiplayer = false; + gametype = GT_COOP; + + // no more tic the game with this settings! + SV_StopServer(); + + if (splitscreen) + multiplayer = true; +} + +static void SV_SendRefuse(INT32 node, const char *reason) +{ + strcpy(netbuffer->u.serverrefuse.reason, reason); + + netbuffer->packettype = PT_SERVERREFUSE; + HSendPacket(node, true, 0, strlen(netbuffer->u.serverrefuse.reason) + 1); + Net_CloseConnection(node); +} + +static inline void writeconplayer(cons_pak *con, const size_t i) +{ + size_t j; + + con->playernum = (UINT8)i; + + con->playerstate = (UINT8)players[i].playerstate; + G_MoveTiccmd(&con->cmd, &players[i].cmd, 1); + con->viewz = LONG(players[i].viewz); + con->viewheight = LONG(players[i].viewheight); + con->deltaviewheight = LONG(players[i].deltaviewheight); + con->bob = LONG(players[i].bob); + con->aiming = (angle_t)LONG(players[i].aiming); + con->awayviewaiming = (angle_t)LONG(players[i].awayviewaiming); + con->phealth = LONG(players[i].health); + con->pity = players[i].pity; + con->currentweapon = LONG(players[i].currentweapon); + con->ringweapons = LONG(players[i].ringweapons); + + for (j = 0; j < NUMPOWERS; j++) + con->powers[j] = (UINT16)SHORT(players[i].powers[j]); + + con->pflags = (UINT32)LONG(players[i].pflags); + con->panim = (UINT8)players[i].panim; + con->flashcount = LONG(players[i].flashcount); + con->skincolor = players[i].skincolor; + con->skin = LONG(players[i].skin); + con->score = (UINT32)LONG(players[i].score); + con->maxlink = LONG(players[i].maxlink); + con->dashspeed = LONG(players[i].dashspeed); + con->dashtime = LONG(players[i].dashtime); + con->normalspeed = LONG(players[i].normalspeed); + con->runspeed = LONG(players[i].runspeed); + con->thrustfactor = players[i].thrustfactor; + con->accelstart = players[i].accelstart; + con->acceleration = players[i].acceleration; + con->charability = players[i].charability; + con->charability2 = players[i].charability2; + con->charflags = (UINT32)LONG(players[i].charflags); + con->thokitem = (UINT32)LONG(players[i].thokitem); + con->spinitem = (UINT32)LONG(players[i].spinitem); + con->revitem = (UINT32)LONG(players[i].revitem); + con->actionspd = LONG(players[i].actionspd); + con->mindash = LONG(players[i].mindash); + con->maxdash = LONG(players[i].maxdash); + con->jumpfactor = LONG(players[i].jumpfactor); + con->lives = LONG(players[i].lives); + con->continues = LONG(players[i].continues); + con->xtralife = LONG(players[i].xtralife); + con->speed = LONG(players[i].speed); + con->jumping = LONG(players[i].jumping); + con->secondjump =players[i].secondjump; + con->fly1 = players[i].fly1; + con->scoreadd = (UINT32)LONG(players[i].scoreadd); + con->glidetime = (tic_t)LONG(players[i].glidetime); + con->climbing = players[i].climbing; + con->deadtimer = LONG(players[i].deadtimer); + con->exiting = (tic_t)LONG(players[i].exiting); + con->homing = players[i].homing; + con->skidtime = (tic_t)LONG(players[i].skidtime); + con->cmomx = LONG(players[i].cmomx); + con->cmomy = LONG(players[i].cmomy); + con->rmomx = LONG(players[i].rmomx); + con->rmomy = LONG(players[i].rmomy); + con->numboxes = LONG(players[i].numboxes); + con->totalring = LONG(players[i].totalring); + con->realtime = (tic_t)LONG(players[i].realtime); + con->laps = (UINT32)LONG(players[i].laps); + con->ctfteam = LONG(players[i].ctfteam); + con->gotflag = (UINT16)SHORT(players[i].gotflag); + con->weapondelay = LONG(players[i].weapondelay); + con->tossdelay = LONG(players[i].tossdelay); + con->starpostx = SHORT(players[i].starpostx); + con->starposty = SHORT(players[i].starposty); + con->starpostz = SHORT(players[i].starpostz); + con->starpostnum = LONG(players[i].starpostnum); + con->starposttime = (tic_t)LONG(players[i].starposttime); + con->starpostangle = (angle_t)LONG(players[i].starpostangle); + con->angle_pos = (angle_t)LONG(players[i].angle_pos); + con->old_angle_pos = (angle_t)LONG(players[i].old_angle_pos); + con->bumpertime = (tic_t)LONG(players[i].bumpertime); + con->flyangle = LONG(players[i].flyangle); + con->drilltimer = (tic_t)LONG(players[i].drilltimer); + con->linkcount = LONG(players[i].linkcount); + con->linktimer = (tic_t)LONG(players[i].linktimer); + con->anotherflyangle = LONG(players[i].anotherflyangle); + con->nightstime = (tic_t)LONG(players[i].nightstime); + con->drillmeter = LONG(players[i].drillmeter); + con->drilldelay = players[i].drilldelay; + con->bonustime = (UINT8)players[i].bonustime; + con->mare = players[i].mare; + con->lastsidehit = SHORT(players[i].lastsidehit); + con->lastlinehit = SHORT(players[i].lastlinehit); + con->losstime = (tic_t)LONG(players[i].losstime); + con->timeshit = (UINT8)players[i].timeshit; + con->onconveyor = LONG(players[i].onconveyor); + con->spectator = (UINT8)players[i].spectator; + con->jointime = (tic_t)LONG(players[i].jointime); + + con->hasmo = false; + //Transfer important mo information if the player has a body. + //This lets us resync players even if they are dead. + if (!players[i].mo) + return; + + con->hasmo = true; + con->angle = (angle_t)LONG(players[i].mo->angle); + con->eflags = (UINT32)LONG(players[i].mo->eflags); + con->flags = LONG(players[i].mo->flags); + con->flags2 = LONG(players[i].mo->flags2); + con->friction = LONG(players[i].mo->friction); + con->health = LONG(players[i].mo->health); + con->momx = LONG(players[i].mo->momx); + con->momy = LONG(players[i].mo->momy); + con->momz = LONG(players[i].mo->momz); + con->movefactor = LONG(players[i].mo->movefactor); + con->tics = LONG(players[i].mo->tics); + con->statenum = (statenum_t)LONG(players[i].mo->state-states); // :( + con->x = LONG(players[i].mo->x); + con->y = LONG(players[i].mo->y); + con->z = LONG(players[i].mo->z); + con->radius = LONG(players[i].mo->radius); + con->height = LONG(players[i].mo->height); + con->scale = LONG(players[i].mo->scale); + con->destscale = LONG(players[i].mo->destscale); + con->scalespeed = LONG(players[i].mo->scalespeed); +} + +static void readconplayer(cons_pak *con, const INT32 playernum) +{ + size_t i; + mobj_t *savedmo = players[playernum].mo; + + //We get a packet for each player in game. + + //Restore CTF information + if (gametype == GT_CTF) + { + // Remove old flags. + if (redflag) + { + P_RemoveMobj(redflag); + redflag = NULL; + } + if (blueflag) + { + P_RemoveMobj(blueflag); + blueflag = NULL; + } + + // Spawn the flags if players aren't carrying them. + if (con->rflagloose != 2) + { + mobj_t *newflag = P_SpawnMobj(con->rflagx << FRACBITS, con->rflagy << FRACBITS, con->rflagz << FRACBITS, MT_REDFLAG); + newflag->flags |= MF_SPECIAL; + newflag->flags2 = con->rflags2; + newflag->fuse = con->rfuse; + newflag->spawnpoint = rflagpoint; + redflag = newflag; + } + + if (con->bflagloose != 2) + { + mobj_t *newflag = P_SpawnMobj(con->bflagx << FRACBITS, con->bflagy << FRACBITS, con->bflagz << FRACBITS, MT_BLUEFLAG); + newflag->flags |= MF_SPECIAL; + newflag->flags2 = con->bflags2; + newflag->fuse = con->bfuse; + newflag->spawnpoint = bflagpoint; + blueflag = newflag; + } + } + + if (!playeringame[playernum]) + return; + + //Tranfer player information. + players[playernum].playerstate = (playerstate_t)con->playerstate; + G_MoveTiccmd(&players[playernum].cmd, &con->cmd, 1); + players[playernum].viewz = LONG(con->viewz); + players[playernum].viewheight = LONG(con->viewheight); + players[playernum].deltaviewheight = LONG(con->deltaviewheight); + players[playernum].bob = LONG(con->bob); + players[playernum].aiming = (angle_t)LONG(con->aiming); + players[playernum].awayviewaiming = (angle_t)LONG(con->awayviewaiming); + players[playernum].health = LONG(con->phealth); + players[playernum].pity = con->pity; + players[playernum].currentweapon = LONG(con->currentweapon); + players[playernum].ringweapons = LONG(con->ringweapons); + + for (i = 0; i < NUMPOWERS; i++) + players[playernum].powers[i] = (UINT16)SHORT(con->powers[i]); + + players[playernum].pflags = (pflags_t)LONG(con->pflags); + players[playernum].panim = (panim_t)con->panim; + players[playernum].flashcount = LONG(con->flashcount); + players[playernum].skincolor = con->skincolor; + players[playernum].skin = LONG(con->skin); + players[playernum].score = (UINT32)LONG(con->score); + players[playernum].maxlink = LONG(con->maxlink); + players[playernum].dashspeed = LONG(con->dashspeed); + players[playernum].dashtime = LONG(con->dashtime); + players[playernum].normalspeed = LONG(con->normalspeed); + players[playernum].runspeed = LONG(con->runspeed); + players[playernum].thrustfactor = con->thrustfactor; + players[playernum].accelstart = con->accelstart; + players[playernum].acceleration = con->acceleration; + players[playernum].charability = con->charability; + players[playernum].charability2 = con->charability2; + players[playernum].charflags = (UINT32)LONG(con->charflags); + players[playernum].thokitem = (mobjtype_t)LONG(con->thokitem); + players[playernum].spinitem = (mobjtype_t)LONG(con->spinitem); + players[playernum].revitem = (mobjtype_t)LONG(con->revitem); + players[playernum].actionspd = LONG(con->actionspd); + players[playernum].mindash = LONG(con->mindash); + players[playernum].maxdash = LONG(con->maxdash); + players[playernum].jumpfactor = LONG(con->jumpfactor); + players[playernum].lives = LONG(con->lives); + players[playernum].continues = LONG(con->continues); + players[playernum].xtralife = LONG(con->xtralife); + players[playernum].speed = LONG(con->speed); + players[playernum].jumping = LONG(con->jumping); + players[playernum].secondjump = con->secondjump; + players[playernum].fly1 = con->fly1; + players[playernum].scoreadd = (UINT32)LONG(con->scoreadd); + players[playernum].glidetime = (tic_t)LONG(con->glidetime); + players[playernum].climbing = con->climbing; + players[playernum].deadtimer = LONG(con->deadtimer); + players[playernum].exiting = (tic_t)LONG(con->exiting); + players[playernum].homing = con->homing; + players[playernum].skidtime = (tic_t)LONG(con->skidtime); + players[playernum].cmomx = LONG(con->cmomx); + players[playernum].cmomy = LONG(con->cmomy); + players[playernum].rmomx = LONG(con->rmomx); + players[playernum].rmomy = LONG(con->rmomy); + players[playernum].numboxes = LONG(con->numboxes); + players[playernum].totalring = LONG(con->totalring); + players[playernum].realtime = (tic_t)LONG(con->realtime); + players[playernum].laps = (UINT32)LONG(con->laps); + players[playernum].ctfteam = LONG(con->ctfteam); + players[playernum].gotflag = (UINT16)SHORT(con->gotflag); + players[playernum].weapondelay = LONG(con->weapondelay); + players[playernum].tossdelay = LONG(con->tossdelay); + players[playernum].starpostx = LONG(con->starpostx); + players[playernum].starposty = LONG(con->starposty); + players[playernum].starpostz = LONG(con->starpostz); + players[playernum].starpostnum = LONG(con->starpostnum); + players[playernum].starposttime = (tic_t)LONG(con->starposttime); + players[playernum].starpostangle = (angle_t)LONG(con->starpostangle); + players[playernum].angle_pos = (angle_t)LONG(con->angle_pos); + players[playernum].old_angle_pos = (angle_t)LONG(con->old_angle_pos); + players[playernum].bumpertime = (tic_t)LONG(con->bumpertime); + players[playernum].flyangle = LONG(con->flyangle); + players[playernum].drilltimer = (tic_t)LONG(con->drilltimer); + players[playernum].linkcount = LONG(con->linkcount); + players[playernum].linktimer = (tic_t)LONG(con->linktimer); + players[playernum].anotherflyangle = LONG(con->anotherflyangle); + players[playernum].nightstime = (tic_t)LONG(con->nightstime); + players[playernum].drillmeter = LONG(con->drillmeter); + players[playernum].drilldelay = con->drilldelay; + players[playernum].bonustime = (boolean)con->bonustime; + players[playernum].mare = con->mare; + players[playernum].lastsidehit = SHORT(con->lastsidehit); + players[playernum].lastlinehit = SHORT(con->lastlinehit); + players[playernum].losstime = (tic_t)LONG(con->losstime); + players[playernum].timeshit = (UINT8)con->timeshit; + players[playernum].onconveyor = LONG(con->onconveyor); + players[playernum].spectator = (boolean)con->spectator; + players[playernum].jointime = (tic_t)LONG(con->jointime); + + //...but keep old mo even if it is corrupt or null! + players[playernum].mo = savedmo; + + //Transfer important mo information if they have a valid mo. + if (!con->hasmo) + return; + //server thinks player has a body. + //Give them a new body that can be then manipulated by the server's info. + if (!players[playernum].mo) //client thinks it has no body. + P_SpawnPlayer(playernum); + + //At this point, the player should have a body, whether they were respawned or not. + P_UnsetThingPosition(players[playernum].mo); + players[playernum].mo->angle = (angle_t)LONG(con->angle); + players[playernum].mo->eflags = (UINT32)LONG(con->eflags); + players[playernum].mo->flags = LONG(con->flags); + players[playernum].mo->flags2 = LONG(con->flags2); + players[playernum].mo->friction = LONG(con->friction); + players[playernum].mo->health = LONG(con->health); + players[playernum].mo->momx = LONG(con->momx); + players[playernum].mo->momy = LONG(con->momy); + players[playernum].mo->momz = LONG(con->momz); + players[playernum].mo->movefactor = LONG(con->movefactor); + players[playernum].mo->tics = LONG(con->tics); + P_SetPlayerMobjState(players[playernum].mo, LONG(con->statenum)); + players[playernum].mo->x = LONG(con->x); + players[playernum].mo->y = LONG(con->y); + players[playernum].mo->z = LONG(con->z); + players[playernum].mo->radius = LONG(con->radius); + players[playernum].mo->height = LONG(con->height); + // P_SetScale is redundant for this, as all related variables are already restored properly. + players[playernum].mo->scale = LONG(con->scale); + players[playernum].mo->destscale = LONG(con->destscale); + players[playernum].mo->scalespeed = LONG(con->scalespeed); + + // And finally, SET THE MOBJ SKIN damn it. + players[playernum].mo->skin = &skins[players[playernum].skin]; + players[playernum].mo->color = players[playernum].skincolor; + + P_SetThingPosition(players[playernum].mo); +} + +static inline void handlectfconstuff(cons_pak *con) +{ + if (redflag) + { + // Flag is loose + if (redflag->fuse) + { + con->rflagloose = 1; + con->rflagx = SHORT(redflag->x >> FRACBITS); + con->rflagy = SHORT(redflag->y >> FRACBITS); + con->rflagz = SHORT(redflag->z >> FRACBITS); + con->rflags2 = LONG(redflag->flags2); + con->rfuse = LONG(redflag->fuse); + } + else // flag is at base + { + con->rflagloose = 0; + con->rflagx = SHORT(rflagpoint->x); + con->rflagy = SHORT(rflagpoint->y); + con->rflagz = SHORT(rflagpoint->z); + con->rflags2 = 0; + con->rfuse = 0; + } + } + else // player has flag + con->rflagloose = 2; + + if (blueflag) + { + // Flag is loose + if (blueflag->fuse) + { + con->bflagloose = 1; + con->bflagx = SHORT(blueflag->x >> FRACBITS); + con->bflagy = SHORT(blueflag->y >> FRACBITS); + con->bflagz = SHORT(blueflag->z >> FRACBITS); + con->bflags2 = LONG(blueflag->flags2); + con->bfuse = LONG(blueflag->fuse); + } + else // flag is at base + { + con->bflagloose = 0; + con->bflagx = SHORT(bflagpoint->x); + con->bflagy = SHORT(bflagpoint->y); + con->bflagz = SHORT(bflagpoint->z); + con->bflags2 = 0; + con->bfuse = 0; + } + } + else // player has flag + con->bflagloose = 2; +} + +/// \todo Remove this AWFUL consistency fixing packet and replace it with re-sending $$$.sav, or at least pause the game until it gets acked! +static void SV_SendConsistency(INT32 node) +{ + INT32 i; + + netbuffer->packettype = PT_CONSISTENCY; + + if (gametype == GT_CTF) + handlectfconstuff(&netbuffer->u.consistency); + + for (i = 0; i < MAXPLAYERS; i++) + if (playeringame[i]) + { + writeconplayer(&netbuffer->u.consistency, i); + HSendPacket(node, true, 0, (sizeof(cons_pak))); + } +} + +// used at txtcmds received to check packetsize bound +static size_t TotalTextCmdPerTic(tic_t tic) +{ + INT32 i; + size_t total = 1; // num of textcmds in the tic (ntextcmd byte) + + for (i = 0; i < MAXPLAYERS; i++) + { + UINT8 *textcmd = D_GetExistingTextcmd(tic, i); + if ((!i || playeringame[i]) && textcmd) + total += 2 + textcmd[0]; // "+2" for size and playernum + } + + return total; +} + +static void HandleConnect(SINT8 node) +{ + if (bannednode && bannednode[node]) + SV_SendRefuse(node, M_GetText("You have been banned\nfrom the server")); + else if (netbuffer->u.clientcfg.version != VERSION + || netbuffer->u.clientcfg.subversion != SUBVERSION) + SV_SendRefuse(node, va(M_GetText("Different SRB2 versions cannot\nplay a netgame!\n(server version %d.%d.%d)"), VERSION/100, VERSION%100, SUBVERSION)); + else if (!cv_allownewplayer.value && node) + SV_SendRefuse(node, M_GetText("The server is not accepting\njoins for the moment")); + else if (D_NumPlayers() >= cv_maxplayers.value) + SV_SendRefuse(node, va(M_GetText("Maximum players reached: %d"), cv_maxplayers.value)); + else if (netgame && netbuffer->u.clientcfg.localplayers > 1) // Hacked client? + SV_SendRefuse(node, M_GetText("Too many players from\nthis node.")); + else if (netgame && !netbuffer->u.clientcfg.localplayers) // Stealth join? + SV_SendRefuse(node, M_GetText("No players from\nthis node.")); + else + { +#ifndef NONET + boolean newnode = false; +#endif + + // client authorised to join + nodewaiting[node] = (UINT8)(netbuffer->u.clientcfg.localplayers - playerpernode[node]); + if (!nodeingame[node]) + { + gamestate_t backupstate = gamestate; +#ifndef NONET + newnode = true; +#endif + SV_AddNode(node); + if (cv_joinnextround.value && gameaction == ga_nothing) + G_SetGamestate(GS_WAITINGPLAYERS); + if (!SV_SendServerConfig(node)) + { + G_SetGamestate(backupstate); + ResetNode(node); + SV_SendRefuse(node, M_GetText("Server couldn't send info, please try again")); + /// \todo fix this !!! + return; // restart the while + } + //if (gamestate != GS_LEVEL) // GS_INTERMISSION, etc? + // SV_SendPlayerConfigs(node); // send bare minimum player info + G_SetGamestate(backupstate); + DEBFILE("new node joined\n"); + } +#ifdef JOININGAME + if (nodewaiting[node]) + { + if ((gamestate == GS_LEVEL || gamestate == GS_INTERMISSION) && newnode) + { + SV_SendSaveGame(node); // send a complete game state + DEBFILE("send savegame\n"); + } + SV_AddWaitingPlayers(); + } +#endif + } +} + +static void HandleShutdown(SINT8 node) +{ + (void)node; + D_QuitNetGame(); + CL_Reset(); + D_StartTitle(); + M_StartMessage(M_GetText("Server has shutdown\n\nPress Esc\n"), NULL, MM_NOTHING); +} + +static void HandleTimeout(SINT8 node) +{ + (void)node; + D_QuitNetGame(); + CL_Reset(); + D_StartTitle(); + M_StartMessage(M_GetText("Server Timeout\n\nPress Esc\n"), NULL, MM_NOTHING); +} + +#ifndef NONET +static void HandleServerInfo(SINT8 node) +{ + // compute ping in ms + const tic_t ticnow = I_GetTime(); + const tic_t ticthen = (tic_t)LONG(netbuffer->u.serverinfo.time); + const tic_t ticdiff = (ticnow - ticthen)*1000/NEWTICRATE; + netbuffer->u.serverinfo.time = (tic_t)LONG(ticdiff); + netbuffer->u.serverinfo.servername[MAXSERVERNAME-1] = 0; + + SL_InsertServer(&netbuffer->u.serverinfo, node); +} +#endif + +/** \brief GetPackets + + \todo break this 300 line function into multiple functions +*/ +static void GetPackets(void) +{FILESTAMP + XBOXSTATIC INT32 netconsole; + XBOXSTATIC SINT8 node; + XBOXSTATIC tic_t realend,realstart; + XBOXSTATIC UINT8 *pak, *txtpak, numtxtpak; +FILESTAMP + while (HGetPacket()) + { + node = (SINT8)doomcom->remotenode; + if (netbuffer->packettype == PT_CLIENTJOIN && server) + { + HandleConnect(node); + continue; + } + if (netbuffer->packettype == PT_SERVERSHUTDOWN && node == servernode + && !server && cl_mode != cl_searching) + { + HandleShutdown(node); + continue; + } + if (netbuffer->packettype == PT_NODETIMEOUT && node == servernode + && !server && cl_mode != cl_searching) + { + HandleTimeout(node); + continue; + } + +#ifndef NONET + if (netbuffer->packettype == PT_SERVERINFO) + { + HandleServerInfo(node); + continue; + } +#endif + + if (netbuffer->packettype == PT_PLAYERINFO) + continue; // We do nothing with PLAYERINFO, that's for the MS browser. + + if (!nodeingame[node]) + { + if (node != servernode) + DEBFILE(va("Received packet from unknown host %d\n", node)); + + // anyone trying to join + switch (netbuffer->packettype) + { + case PT_ASKINFOVIAMS: + if (server && serverrunning) + { + INT32 clientnode = I_NetMakeNode(netbuffer->u.msaskinfo.clientaddr); + SV_SendServerInfo(clientnode, (tic_t)LONG(netbuffer->u.msaskinfo.time)); + SV_SendPlayerInfo(clientnode); // send extra info + Net_CloseConnection(clientnode); + // Don't close connection to MS. + } + break; + + case PT_ASKINFO: + if (server && serverrunning) + { + SV_SendServerInfo(node, (tic_t)LONG(netbuffer->u.askinfo.time)); + SV_SendPlayerInfo(node); // send extra info + Net_CloseConnection(node); + } + break; + case PT_SERVERREFUSE: // negative response of client join request + if (server && serverrunning) + { // but wait I thought I'm the server? + if (I_Shun) + I_Shun(node); // No more garbage from you! + Net_CloseConnection(node); + break; + } + if (cl_mode == cl_waitjoinresponse) + { + D_QuitNetGame(); + CL_Reset(); + D_StartTitle(); + + M_StartMessage(va(M_GetText("Server refuses connection\n\nReason:\n%s"), + netbuffer->u.serverrefuse.reason), NULL, MM_NOTHING); + + // Will be reset by caller. Signals refusal. + cl_mode = cl_aborted; + } + break; + case PT_SERVERCFG: // positive response of client join request + { + INT32 j; + UINT8 *scp; + UINT32 playermask = 0; + + if (server && serverrunning && node != servernode) + { // but wait I thought I'm the server? + if (I_Shun) + I_Shun(node); // No more garbage from you! + Net_CloseConnection(node); + break; + } + /// \note how would this happen? and is it doing the right thing if it does? + if (cl_mode != cl_waitjoinresponse) + break; + + if (!server) + { + maketic = gametic = neededtic = (tic_t)LONG(netbuffer->u.servercfg.gametic); + gametype = netbuffer->u.servercfg.gametype; + modifiedgame = netbuffer->u.servercfg.modifiedgame; + adminplayer = netbuffer->u.servercfg.adminplayer; + memcpy(server_context, netbuffer->u.servercfg.server_context, 8); + } + + nodeingame[(UINT8)servernode] = true; + serverplayer = netbuffer->u.servercfg.serverplayer; + doomcom->numslots = SHORT(netbuffer->u.servercfg.totalslotnum); + mynode = netbuffer->u.servercfg.clientnode; + if (serverplayer >= 0) + playernode[(UINT8)serverplayer] = servernode; + + if (netgame) +#ifdef JOININGAME + CONS_Printf(M_GetText("Join accepted, waiting for complete game state...\n")); +#else + CONS_Printf(M_GetText("Join accepted, waiting for next level change...\n")); +#endif + DEBFILE(va("Server accept join gametic=%u mynode=%d\n", gametic, mynode)); + + playermask = LONG(netbuffer->u.servercfg.playerdetected); + for (j = 0; j < MAXPLAYERS; j++) + playeringame[j] = (playermask & (1<u.servercfg.netcvarstates; + CV_LoadNetVars(&scp); +#ifdef JOININGAME + if (netbuffer->u.servercfg.gamestate == GS_LEVEL/* || + netbuffer->u.servercfg.gamestate == GS_INTERMISSION*/) + cl_mode = cl_downloadsavegame; + else +#endif + cl_mode = cl_connected; + break; + } + // handled in d_netfil.c + case PT_FILEFRAGMENT: + if (server) + { // but wait I thought I'm the server? + if (I_Shun) + I_Shun(node); // No more garbage from you! + Net_CloseConnection(node); + break; + } + else + Got_Filetxpak(); + break; + case PT_REQUESTFILE: + if (server) + Got_RequestFilePak(node); + break; + case PT_NODETIMEOUT: + case PT_CLIENTQUIT: + if (server) + Net_CloseConnection(node); + break; + case PT_CLIENTCMD: + break; // this is not an "unknown packet" + case PT_SERVERTICS: + // do not remove my own server (we have just get a out of order packet) + if (node == servernode) + break; + default: + DEBFILE(va("unknown packet received (%d) from unknown host\n",netbuffer->packettype)); + if (I_Shun) + I_Shun(node); // No more garbage from you! + Net_CloseConnection(node); + break; // ignore it + } // switch + continue; //while + } + if (dedicated && node == 0) netconsole = 0; + else netconsole = nodetoplayer[node]; +#ifdef PARANOIA + if (netconsole >= MAXPLAYERS) + I_Error("bad table nodetoplayer: node %d player %d", doomcom->remotenode, netconsole); +#endif + + switch (netbuffer->packettype) + { +// -------------------------------------------- SERVER RECEIVE ---------- + case PT_CLIENTCMD: + case PT_CLIENT2CMD: + case PT_CLIENTMIS: + case PT_CLIENT2MIS: + case PT_NODEKEEPALIVE: + case PT_NODEKEEPALIVEMIS: + if (!server) + break; + + // to save bytes, only the low byte of tic numbers are sent + // Figure out what the rest of the bytes are + realstart = ExpandTics(netbuffer->u.clientpak.client_tic); + realend = ExpandTics(netbuffer->u.clientpak.resendfrom); + + if (netbuffer->packettype == PT_CLIENTMIS || netbuffer->packettype == PT_CLIENT2MIS + || netbuffer->packettype == PT_NODEKEEPALIVEMIS + || supposedtics[node] < realend) + { + supposedtics[node] = realend; + } + // discard out of order packet + if (nettics[node] > realend) + { + DEBFILE(va("out of order ticcmd discarded nettics = %u\n", nettics[node])); + break; + } + + // update the nettics + nettics[node] = realend; + + // don't do anything for packets of type NODEKEEPALIVE? + if (netconsole == -1 || netbuffer->packettype == PT_NODEKEEPALIVE + || netbuffer->packettype == PT_NODEKEEPALIVEMIS) + break; + + // copy ticcmd + G_MoveTiccmd(&netcmds[maketic%BACKUPTICS][netconsole], &netbuffer->u.clientpak.cmd, 1); + + // check ticcmd for "speed hacks" + if (netcmds[maketic%BACKUPTICS][netconsole].forwardmove > MAXPLMOVE || netcmds[maketic%BACKUPTICS][netconsole].forwardmove < -MAXPLMOVE + || netcmds[maketic%BACKUPTICS][netconsole].sidemove > MAXPLMOVE || netcmds[maketic%BACKUPTICS][netconsole].sidemove < -MAXPLMOVE) + { + XBOXSTATIC char buf[2]; + CONS_Alert(CONS_WARNING, M_GetText("Illegal movement value recieved from node %d\n"), netconsole); + //D_Clearticcmd(k); + + buf[0] = (char)netconsole; + buf[1] = KICK_MSG_CON_FAIL; + SendNetXCmd(XD_KICK, &buf, 2); + break; + } + + // splitscreen cmd + if (netbuffer->packettype == PT_CLIENT2CMD && nodetoplayer2[node] >= 0) + G_MoveTiccmd(&netcmds[maketic%BACKUPTICS][(UINT8)nodetoplayer2[node]], + &netbuffer->u.client2pak.cmd2, 1); + + // check player consistancy during the level + // Careful: When a consistency packet is sent, it overwrites the incoming packet containing the ticcmd. + // Keep this in mind when changing the code that responds to these packets. + if (realstart <= gametic && realstart > gametic - BACKUPTICS+1 + && players[netconsole].pflags & PF_CONSISTANCY + && consistancy[realstart%BACKUPTICS] != SHORT(netbuffer->u.clientpak.consistancy) + && gamestate == GS_LEVEL) + { + if (cv_consfailprotect.value && playeringame[netconsole] && consfailcount[netconsole] < cv_consfailprotect.value) + { + if (!consfailstatus[netconsole]) + { + if (cv_blamecfail.value) + CONS_Printf(M_GetText("Consistency failure for player %d (%s), restoring...\n"), netconsole+1, player_names[netconsole]); + + DEBFILE(va("Restoring player %d (consistency failure) [%update] %d!=%d\n", + netconsole, realstart, consistancy[realstart%BACKUPTICS], + SHORT(netbuffer->u.clientpak.consistancy))); + + SV_SendConsistency(netconsole); + consfailstatus[netconsole] = 1; + consfailcount[netconsole]++; + break; // ticcmd packet is gone. + } + else + { + //We don't want to send any more packets than we have to. + //If the client doesn't resync in a certain time, + //assume they didn't get the packet. Send another. + if (consfailstatus[netconsole] < 10) + consfailstatus[netconsole]++; + else + consfailstatus[netconsole] = 0; + } + } + else + { + XBOXSTATIC UINT8 buf[3]; + + buf[0] = (UINT8)netconsole; + buf[1] = KICK_MSG_CON_FAIL; + SendNetXCmd(XD_KICK, &buf, 2); + DEBFILE(va("player %d kicked (consistency failure) [%u] %d!=%d\n", + netconsole, realstart, consistancy[realstart%BACKUPTICS], + SHORT(netbuffer->u.clientpak.consistancy))); + players[netconsole].pflags &= ~PF_CONSISTANCY; + consfailstatus[netconsole] = 0; + consfailcount[netconsole] = 0; + break; + } + } + else + { + consfailstatus[netconsole] = 0; + consfailcount[netconsole] = 0; + } + break; + case PT_TEXTCMD2: // splitscreen special + netconsole = nodetoplayer2[node]; + case PT_TEXTCMD: + if (!server) + break; + + if (netconsole < 0 || netconsole >= MAXPLAYERS) + Net_UnAcknowledgPacket(node); + else + { + size_t j; + tic_t tic = maketic; + UINT8 *textcmd; + + // check if tic that we are making isn't too large else we cannot send it :( + // doomcom->numslots+1 "+1" since doomcom->numslots can change within this time and sent time + j = software_MAXPACKETLENGTH + - (netbuffer->u.textcmd[0]+2+BASESERVERTICSSIZE + + (doomcom->numslots+1)*sizeof(ticcmd_t)); + + // search a tic that have enougth space in the ticcmd + while ((textcmd = D_GetExistingTextcmd(tic, netconsole)), + (TotalTextCmdPerTic(tic) > j || netbuffer->u.textcmd[0] + (textcmd ? textcmd[0] : 0) > MAXTEXTCMD) + && tic < firstticstosend + BACKUPTICS) + tic++; + + if (tic >= firstticstosend + BACKUPTICS) + { + DEBFILE(va("GetPacket: Textcmd too long (max %s, used %s, mak %d, " + "tosend %u, node %u, player %d)\n", sizeu1(j), sizeu2(TotalTextCmdPerTic(maketic)), + maketic, firstticstosend, node, netconsole)); + Net_UnAcknowledgPacket(node); + break; + } + + // Make sure we have a buffer + if (!textcmd) textcmd = D_GetTextcmd(tic, netconsole); + + DEBFILE(va("textcmd put in tic %u at position %d (player %d) ftts %u mk %u\n", + tic, textcmd[0]+1, netconsole, firstticstosend, maketic)); + + M_Memcpy(&textcmd[textcmd[0]+1], netbuffer->u.textcmd+1, netbuffer->u.textcmd[0]); + textcmd[0] += (UINT8)netbuffer->u.textcmd[0]; + } + break; + case PT_NODETIMEOUT: + case PT_CLIENTQUIT: + if (!server) + break; + + // nodeingame will be put false in the execution of kick command + // this allow to send some packets to the quitting client to have their ack back + nodewaiting[node] = 0; + if (netconsole != -1 && playeringame[netconsole]) + { + XBOXSTATIC UINT8 buf[2]; + buf[0] = (UINT8)netconsole; + if (netbuffer->packettype == PT_NODETIMEOUT) + buf[1] = KICK_MSG_TIMEOUT; + else + buf[1] = KICK_MSG_PLAYER_QUIT; + SendNetXCmd(XD_KICK, &buf, 2); + nodetoplayer[node] = -1; + if (nodetoplayer2[node] != -1 && nodetoplayer2[node] >= 0 + && playeringame[(UINT8)nodetoplayer2[node]]) + { + buf[0] = nodetoplayer2[node]; + SendNetXCmd(XD_KICK, &buf, 2); + nodetoplayer2[node] = -1; + } + } + Net_CloseConnection(node); + nodeingame[node] = false; + break; +// -------------------------------------------- CLIENT RECEIVE ---------- + case PT_SERVERTICS: + // Only accept PT_SERVERTICS from the server. + if (node != servernode) + { + CONS_Alert(CONS_WARNING, M_GetText("%s recieved from non-host %d\n"), "PT_SERVERTICS", node); + + if (server) + { + XBOXSTATIC UINT8 buf[2]; + buf[0] = (UINT8)node; + buf[1] = KICK_MSG_CON_FAIL; + SendNetXCmd(XD_KICK, &buf, 2); + } + + break; + } + + realstart = ExpandTics(netbuffer->u.serverpak.starttic); + realend = realstart + netbuffer->u.serverpak.numtics; + + txtpak = (UINT8 *)&netbuffer->u.serverpak.cmds[netbuffer->u.serverpak.numslots + * netbuffer->u.serverpak.numtics]; + + if (realend > gametic + BACKUPTICS) + realend = gametic + BACKUPTICS; + cl_packetmissed = realstart > neededtic; + + if (realstart <= neededtic && realend > neededtic) + { + tic_t i, j; + pak = (UINT8 *)&netbuffer->u.serverpak.cmds; + + for (i = realstart; i < realend; i++) + { + // clear first + D_Clearticcmd(i); + + // copy the tics + pak = G_ScpyTiccmd(netcmds[i%BACKUPTICS], pak, + netbuffer->u.serverpak.numslots*sizeof (ticcmd_t)); + + // copy the textcmds + numtxtpak = *txtpak++; + for (j = 0; j < numtxtpak; j++) + { + INT32 k = *txtpak++; // playernum + const size_t txtsize = txtpak[0]+1; + + M_Memcpy(D_GetTextcmd(i, k), txtpak, txtsize); + txtpak += txtsize; + } + } + + neededtic = realend; + } + else + DEBFILE(va("frame not in bound: %u\n", neededtic)); + break; + case PT_CONSISTENCY: + // Only accept PT_CONSISTENCY from the server. + if (node != servernode) + { + CONS_Alert(CONS_WARNING, M_GetText("%s recieved from non-host %d\n"), "PT_CONSISTENCY", node); + + if (server) + { + XBOXSTATIC char buf[2]; + buf[0] = (char)node; + buf[1] = KICK_MSG_CON_FAIL; + SendNetXCmd(XD_KICK, &buf, 2); + } + + break; + } + + readconplayer(&netbuffer->u.consistency, netbuffer->u.consistency.playernum); + break; +#ifdef NEWPING + case PT_PING: + // Only accept PT_PING from the server. + if (node != servernode) + { + CONS_Alert(CONS_WARNING, M_GetText("%s recieved from non-host %d\n"), "PT_PING", node); + + if (server) + { + XBOXSTATIC char buf[2]; + buf[0] = (char)node; + buf[1] = KICK_MSG_CON_FAIL; + SendNetXCmd(XD_KICK, &buf, 2); + } + + break; + } + + //Update client ping table from the server. + if (!server) + { + INT32 i; + for (i = 0; i < MAXNETNODES; i++) + if (playeringame[i]) + playerpingtable[i] = (tic_t)netbuffer->u.pingtable[i]; + } + + break; +#endif + case PT_SERVERCFG: + break; + case PT_FILEFRAGMENT: + if (!server) + Got_Filetxpak(); + break; + default: + DEBFILE(va("UNKNOWN PACKET TYPE RECEIVED %d from host %d\n", + netbuffer->packettype, node)); + } // end switch + } // end while +} + +// +// NetUpdate +// Builds ticcmds for console player, +// sends out a packet +// +// no more use random generator, because at very first tic isn't yet synchronized +// Note: It is called consistAncy on purpose. +// +static INT16 Consistancy(void) +{ + INT16 ret = 0; + INT32 i; + + DEBFILE(va("TIC %u ", gametic)); + for (i = 0; i < MAXPLAYERS; i++) + if (playeringame[i] && players[i].mo && !players[i].spectator && players[i].pflags & PF_CONSISTANCY) + { + DEBFILE(va("p[%d].x = %f ", i, (double)FIXED_TO_FLOAT(players[i].mo->x))); + ret = (INT16)((ret + players[i].mo->x) & 0xFFFF); + ret = (INT16)((ret + players[i].powers[pw_shield]) & 0xFFFF); + } + //DEBFILE(va("pos = %d, rnd %d\n", ret, P_GetRandSeed())); + //ret = (INT16)(ret + P_GetRandSeed()); + + return ret; +} + +// send the client packet to the server +static void CL_SendClientCmd(void) +{ + size_t packetsize = 0; + + netbuffer->packettype = PT_CLIENTCMD; + + if (cl_packetmissed) + netbuffer->packettype++; + netbuffer->u.clientpak.resendfrom = (UINT8)(neededtic & UINT8_MAX); + netbuffer->u.clientpak.client_tic = (UINT8)(gametic & UINT8_MAX); + + if (gamestate == GS_WAITINGPLAYERS) + { + // send NODEKEEPALIVE packet + netbuffer->packettype += 4; + packetsize = sizeof (clientcmd_pak) - sizeof (ticcmd_t) - sizeof (INT16); + HSendPacket(servernode, false, 0, packetsize); + } + else if (gamestate != GS_NULL) + { + G_MoveTiccmd(&netbuffer->u.clientpak.cmd, &localcmds, 1); + netbuffer->u.clientpak.consistancy = SHORT(consistancy[gametic%BACKUPTICS]); + + // send a special packet with 2 cmd for splitscreen + if (splitscreen || botingame) + { + netbuffer->packettype += 2; + G_MoveTiccmd(&netbuffer->u.client2pak.cmd2, &localcmds2, 1); + packetsize = sizeof (client2cmd_pak); + } + else + packetsize = sizeof (clientcmd_pak); + + HSendPacket(servernode, false, 0, packetsize); + } + + if (cl_mode == cl_connected || dedicated) + { + // send extra data if needed + if (localtextcmd[0]) + { + netbuffer->packettype = PT_TEXTCMD; + M_Memcpy(netbuffer->u.textcmd,localtextcmd, localtextcmd[0]+1); + // all extra data have been sended + if (HSendPacket(servernode, true, 0, localtextcmd[0]+1)) // send can fail... + localtextcmd[0] = 0; + } + + // send extra data if needed for player 2 (splitscreen) + if (localtextcmd2[0]) + { + netbuffer->packettype = PT_TEXTCMD2; + M_Memcpy(netbuffer->u.textcmd, localtextcmd2, localtextcmd2[0]+1); + // all extra data have been sended + if (HSendPacket(servernode, true, 0, localtextcmd2[0]+1)) // send can fail... + localtextcmd2[0] = 0; + } + } +} + +// send the server packet +// send tic from firstticstosend to maketic-1 +static void SV_SendTics(void) +{ + tic_t realfirsttic, lasttictosend, i; + UINT32 n; + INT32 j; + size_t packsize; + UINT8 *bufpos; + UINT8 *ntextcmd; + + // send to all client but not to me + // for each node create a packet with x tics and send it + // x is computed using supposedtics[n], max packet size and maketic + for (n = 1; n < MAXNETNODES; n++) + if (nodeingame[n]) + { + lasttictosend = maketic; + + // assert supposedtics[n]>=nettics[n] + realfirsttic = supposedtics[n]; + if (realfirsttic >= maketic) + { + // well we have sent all tics we will so use extrabandwidth + // to resent packet that are supposed lost (this is necessary since lost + // packet detection work when we have received packet with firsttic > neededtic + // (getpacket servertics case) + DEBFILE(va("Nothing to send node %u mak=%u sup=%u net=%u \n", + n, maketic, supposedtics[n], nettics[n])); + realfirsttic = nettics[n]; + if (realfirsttic >= maketic || (I_GetTime() + n)&3) + // all tic are ok + continue; + DEBFILE(va("Sent %d anyway\n", realfirsttic)); + } + if (realfirsttic < firstticstosend) + realfirsttic = firstticstosend; + + // compute the length of the packet and cut it if too large + packsize = BASESERVERTICSSIZE; + for (i = realfirsttic; i < lasttictosend; i++) + { + packsize += sizeof (ticcmd_t) * doomcom->numslots; + packsize += TotalTextCmdPerTic(i); + + if (packsize > software_MAXPACKETLENGTH) + { + DEBFILE(va("packet too large (%s) at tic %d (should be from %d to %d)\n", + sizeu1(packsize), i, realfirsttic, lasttictosend)); + lasttictosend = i; + + // too bad: too much player have send extradata and there is too + // much data in one tic. + // To avoid it put the data on the next tic. (see getpacket + // textcmd case) but when numplayer changes the computation can be different + if (lasttictosend == realfirsttic) + { + if (packsize > MAXPACKETLENGTH) + I_Error("Too many players: can't send %s data for %d players to node %d\n" + "Well sorry nobody is perfect....\n", + sizeu1(packsize), doomcom->numslots, n); + else + { + lasttictosend++; // send it anyway! + DEBFILE("sending it anyway\n"); + } + } + break; + } + } + + // Send the tics + netbuffer->packettype = PT_SERVERTICS; + netbuffer->u.serverpak.starttic = (UINT8)realfirsttic; + netbuffer->u.serverpak.numtics = (UINT8)(lasttictosend - realfirsttic); + netbuffer->u.serverpak.numslots = (UINT8)SHORT(doomcom->numslots); + bufpos = (UINT8 *)&netbuffer->u.serverpak.cmds; + + for (i = realfirsttic; i < lasttictosend; i++) + { + bufpos = G_DcpyTiccmd(bufpos, netcmds[i%BACKUPTICS], doomcom->numslots * sizeof (ticcmd_t)); + } + + // add textcmds + for (i = realfirsttic; i < lasttictosend; i++) + { + ntextcmd = bufpos++; + *ntextcmd = 0; + for (j = 0; j < MAXPLAYERS; j++) + { + UINT8 *textcmd = D_GetExistingTextcmd(i, j); + INT32 size = textcmd ? textcmd[0] : 0; + + if ((!j || playeringame[j]) && size) + { + (*ntextcmd)++; + WRITEUINT8(bufpos, j); + M_Memcpy(bufpos, textcmd, size + 1); + bufpos += size + 1; + } + } + } + packsize = bufpos - (UINT8 *)&(netbuffer->u); + + HSendPacket(n, false, 0, packsize); + // when tic are too large, only one tic is sent so don't go backward! + if (lasttictosend-doomcom->extratics > realfirsttic) + supposedtics[n] = lasttictosend-doomcom->extratics; + else + supposedtics[n] = lasttictosend; + if (supposedtics[n] < nettics[n]) supposedtics[n] = nettics[n]; + } + // node 0 is me! + supposedtics[0] = maketic; +} + +// +// TryRunTics +// +static void Local_Maketic(INT32 realtics) +{ + I_OsPolling(); // I_Getevent + D_ProcessEvents(); // menu responder, cons responder, + // game responder calls HU_Responder, AM_Responder, F_Responder, + // and G_MapEventsToControls + if (!dedicated) rendergametic = gametic; + // translate inputs (keyboard/mouse/joystick) into game controls + G_BuildTiccmd(&localcmds, realtics); + if (splitscreen || botingame) + G_BuildTiccmd2(&localcmds2, realtics); + + localcmds.angleturn |= TICCMD_RECEIVED; +} + +void SV_SpawnPlayer(INT32 playernum, INT32 x, INT32 y, angle_t angle) +{ + tic_t tic; + + (void)x; + (void)y; + + // Revisionist history: adjust the angles in the ticcmds received + // for this player, because they actually preceded the player + // spawning, but will be applied afterwards. + + for (tic = server ? maketic : (neededtic - 1); tic >= gametic; tic--) + netcmds[tic%BACKUPTICS][playernum].angleturn = (INT16)((angle>>16) | TICCMD_RECEIVED); +} + +// create missed tic +static void SV_Maketic(void) +{ + INT32 j; + + for (j = 0; j < MAXNETNODES; j++) + if (playerpernode[j]) + { + INT32 player = nodetoplayer[j]; + if ((netcmds[maketic%BACKUPTICS][player].angleturn & TICCMD_RECEIVED) == 0) + { // we didn't receive this tic + INT32 i; + + DEBFILE(va("MISS tic%4d for node %d\n", maketic, j)); +#if defined(PARANOIA) && 0 + CONS_Debug(DBG_NETPLAY, "Client Misstic %d\n", maketic); +#endif + // copy the old tic + for (i = 0; i < playerpernode[j]; i++, player = nodetoplayer2[j]) + { + netcmds[maketic%BACKUPTICS][player] = netcmds[(maketic-1)%BACKUPTICS][player]; + netcmds[maketic%BACKUPTICS][player].angleturn &= ~TICCMD_RECEIVED; + } + } + } + + // all tic are now proceed make the next + maketic++; +} + +void TryRunTics(tic_t realtics) +{ + // the machine has lagged but it is not so bad + if (realtics > TICRATE/7) // FIXME: consistency failure!! + { + if (server) + realtics = 1; + else + realtics = TICRATE/7; + } + + if (singletics) + realtics = 1; + + if (realtics >= 1) + { + COM_BufExecute(); + if (mapchangepending) + D_MapChange(-1, 0, ultimatemode, false, 2, false, fromlevelselect); // finish the map change + } + + NetUpdate(); + + if (demoplayback) + { + neededtic = gametic + (realtics * cv_playbackspeed.value); + // start a game after a demo + maketic += realtics; + firstticstosend = maketic; + tictoclear = firstticstosend; + } + + GetPackets(); + +#ifdef DEBUGFILE + if (debugfile && (realtics || neededtic > gametic)) + { + //SoM: 3/30/2000: Need long INT32 in the format string for args 4 & 5. + //Shut up stupid warning! + fprintf(debugfile, "------------ Tryruntic: REAL:%d NEED:%d GAME:%d LOAD: %d\n", + realtics, neededtic, gametic, debugload); + debugload = 100000; + } +#endif + + if (neededtic > gametic) + { + if (advancedemo) + D_StartTitle(); + else + // run the count * tics + while (neededtic > gametic) + { + DEBFILE(va("============ Running tic %d (local %d)\n", gametic, localgametic)); + + G_Ticker((gametic % NEWTICRATERATIO) == 0); + ExtraDataTicker(); + gametic++; + consistancy[gametic%BACKUPTICS] = Consistancy(); + } + } +} + +#ifdef NEWPING +static inline void PingUpdate(void) +{ + INT32 i; + boolean laggers[MAXPLAYERS]; + UINT8 numlaggers = 0; + memset(laggers, 0, sizeof(boolean) * MAXPLAYERS); + + netbuffer->packettype = PT_PING; + + //check for ping limit breakage. + if (cv_maxping.value) + { + for (i = 1; i < MAXNETNODES; i++) + { + if (playeringame[i] && (realpingtable[i] / pingmeasurecount > (unsigned)cv_maxping.value)) + { + if (players[i].jointime > 30 * TICRATE) + laggers[i] = true; + numlaggers++; + } + } + + //kick lagging players... unless everyone but the server's ping sucks. + //in that case, it is probably the server's fault. + if (numlaggers < D_NumPlayers() - 1) + { + for (i = 1; i < MAXNETNODES; i++) + { + if (playeringame[i] && laggers[i]) + { + XBOXSTATIC char buf[2]; + + buf[0] = (char)i; + buf[1] = KICK_MSG_PING_HIGH; + SendNetXCmd(XD_KICK, &buf, 2); + } + } + } + } + + //make the ping packet and clear server data for next one + for (i = 0; i < MAXNETNODES; i++) + { + netbuffer->u.pingtable[i] = realpingtable[i] / pingmeasurecount; + //server takes a snapshot of the real ping for display. + //otherwise, pings fluctuate a lot and would be odd to look at. + playerpingtable[i] = realpingtable[i] / pingmeasurecount; + realpingtable[i] = 0; //Reset each as we go. + } + + //send out our ping packets + for (i = 0; i < MAXNETNODES; i++) + if (playeringame[i]) + HSendPacket(i, true, 0, sizeof(INT32) * MAXPLAYERS); + + pingmeasurecount = 1; //Reset count +} +#endif + +void NetUpdate(void) +{ + static tic_t gametime = 0; + static tic_t resptime = 0; + tic_t nowtime; + INT32 i; + INT32 realtics; + + nowtime = I_GetTime(); + realtics = nowtime - gametime; + + if (realtics <= 0) // nothing new to update + return; + if (realtics > 5) + { + if (server) + realtics = 1; + else + realtics = 5; + } + + gametime = nowtime; + + if (!(gametime % 255) && netgame && server) + { +#ifdef NEWPING + PingUpdate(); +#endif + } + +#ifdef NEWPING + if (server) + { + // update node latency values so we can take an average later. + for (i = 0; i < MAXNETNODES; i++) + if (playeringame[i]) + realpingtable[i] += G_TicsToMilliseconds(GetLag(i)); + pingmeasurecount++; + } +#endif + + if (!server) + maketic = neededtic; + + Local_Maketic(realtics); // make local tic, and call menu? + + if (server) + CL_SendClientCmd(); // send it +FILESTAMP + GetPackets(); // get packet from client or from server +FILESTAMP + // client send the command after a receive of the server + // the server send before because in single player is beter + + MasterClient_Ticker(); // acking the master server + + if (!server) + CL_SendClientCmd(); // send tic cmd + else + { + if (!demoplayback) + { + INT32 counts; + + firstticstosend = gametic; + for (i = 0; i < MAXNETNODES; i++) + if (nodeingame[i] && nettics[i] < firstticstosend) + firstticstosend = nettics[i]; + + // Don't erase tics not acknowledged + counts = realtics; + + if (maketic + counts >= firstticstosend + BACKUPTICS) + counts = firstticstosend+BACKUPTICS-maketic-1; + + for (i = 0; i < counts; i++) + SV_Maketic(); // create missed tics and increment maketic + + for (; tictoclear < firstticstosend; tictoclear++) // clear only when acknoledged + D_Clearticcmd(tictoclear); // clear the maketic the new tic + + SV_SendTics(); + + neededtic = maketic; // the server is a client too + } + } + Net_AckTicker(); + nowtime /= NEWTICRATERATIO; + if (nowtime > resptime) + { + resptime = nowtime; + M_Ticker(); + CON_Ticker(); + } + FiletxTicker(); +} + +/** Returns the number of players playing. + * \return Number of players. Can be zero if we're running a ::dedicated + * server. + * \author Graue + */ +INT32 D_NumPlayers(void) +{ + INT32 num = 0, ix; + for (ix = 0; ix < MAXPLAYERS; ix++) + if (playeringame[ix]) + num++; + return num; +} + +tic_t GetLag(INT32 node) +{ + return gametic - nettics[node]; +} diff --git a/src/d_clisrv.h b/src/d_clisrv.h new file mode 100644 index 000000000..d35c5cb3c --- /dev/null +++ b/src/d_clisrv.h @@ -0,0 +1,495 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Copyright (C) 1999-2014 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file d_clisrv.h +/// \brief high level networking stuff + +#ifndef __D_CLISRV__ +#define __D_CLISRV__ + +#include "d_ticcmd.h" +#include "d_netcmd.h" +#include "tables.h" +#include "d_player.h" + +// Network play related stuff. +// There is a data struct that stores network +// communication related stuff, and another +// one that defines the actual packets to +// be transmitted. + +// Networking and tick handling related. +#define BACKUPTICS 32 +#define MAXTEXTCMD 256 +// +// Packet structure +// +typedef enum +{ + PT_NOTHING, // To send a nop through the network. ^_~ + PT_SERVERCFG, // Server config used in start game + // (must stay 1 for backwards compatibility). + // This is a positive response to a CLIENTJOIN request. + PT_CLIENTCMD, // Ticcmd of the client. + PT_CLIENTMIS, // Same as above with but saying resend from. + PT_CLIENT2CMD, // 2 cmds in the packet for splitscreen. + PT_CLIENT2MIS, // Same as above with but saying resend from + PT_NODEKEEPALIVE, // Same but without ticcmd and consistancy + PT_NODEKEEPALIVEMIS, + PT_SERVERTICS, // All cmds for the tic. + PT_SERVERREFUSE, // Server refuses joiner (reason inside). + PT_SERVERSHUTDOWN, + PT_CLIENTQUIT, // Client closes the connection. + + PT_ASKINFO, // Anyone can ask info of the server. + PT_SERVERINFO, // Send game & server info (gamespy). + PT_PLAYERINFO, // Send information for players in game (gamespy). + PT_REQUESTFILE, // Client requests a file transfer + PT_ASKINFOVIAMS, // Packet from the MS requesting info be sent to new client. + // If this ID changes, update masterserver definition. + + // Add non-PT_CANFAIL packet types here to avoid breaking MS compatibility. + + PT_CANFAIL, // This is kind of a priority. Anything bigger than CANFAIL + // allows HSendPacket(,true,,) to return false. + // In addition, this packet can't occupy all the available slots. + + PT_FILEFRAGMENT = PT_CANFAIL, // A part of a file. + + PT_TEXTCMD, // Extra text commands from the client. + PT_TEXTCMD2, // Splitscreen text commands. + PT_CLIENTJOIN, // Client wants to join; used in start game. + PT_NODETIMEOUT, // Packet sent to self if the connection times out. + PT_CONSISTENCY, // Packet sent to resync players. +#ifdef NEWPING + PT_PING, // Packet sent to tell clients the other client's latency to server. +#endif + NUMPACKETTYPE +} packettype_t; + +#if defined(_MSC_VER) +#pragma pack(1) +#endif + +// client to server packet +typedef struct +{ + UINT8 client_tic; + UINT8 resendfrom; + INT16 consistancy; + ticcmd_t cmd; +} ATTRPACK clientcmd_pak; + +// splitscreen packet +// WARNING: must have the same format of clientcmd_pak, for more easy use +typedef struct +{ + UINT8 client_tic; + UINT8 resendfrom; + INT16 consistancy; + ticcmd_t cmd, cmd2; +} ATTRPACK client2cmd_pak; + +#ifdef _MSC_VER +#pragma warning(disable : 4200) +#endif + +// Server to client packet +// this packet is too large +typedef struct +{ + UINT8 starttic; + UINT8 numtics; + UINT8 numslots; // "Slots filled": Highest player number in use plus one. + ticcmd_t cmds[45]; // normally [BACKUPTIC][MAXPLAYERS] but too large +} ATTRPACK servertics_pak; + +typedef struct +{ + UINT8 version; // different versions don't work + UINT8 subversion; // contains build version + + // server launch stuffs + UINT8 serverplayer; + UINT8 totalslotnum; // "Slots": highest player number in use plus one. + + tic_t gametic; + UINT8 clientnode; + UINT8 gamestate; + + UINT32 playerdetected; // playeringame vector in bit field + UINT8 gametype; + UINT8 modifiedgame; + SINT8 adminplayer; // needs to be signed + + char server_context[8]; // unique context id, generated at server startup. + + UINT8 netcvarstates[0]; +} ATTRPACK serverconfig_pak; + +typedef struct { + UINT8 fileid; + UINT32 position; + UINT16 size; + UINT8 data[0]; // size is variable using hardware_MAXPACKETLENGTH +} ATTRPACK filetx_pak; + +#ifdef _MSC_VER +#pragma warning(default : 4200) +#endif + +typedef struct +{ + UINT8 version; // different versions don't work + UINT8 subversion; // contains build version + UINT8 localplayers; + UINT8 mode; +} ATTRPACK clientconfig_pak; + +#define MAXSERVERNAME 32 +// this packet is too large +typedef struct +{ + UINT8 version; + UINT8 subversion; + UINT8 numberofplayer; + UINT8 maxplayer; + UINT8 gametype; + UINT8 modifiedgame; + UINT8 cheatsenabled; + UINT8 isdedicated; + UINT8 fileneedednum; + SINT8 adminplayer; + tic_t time; + tic_t leveltime; + char servername[MAXSERVERNAME]; + char mapname[8]; + char maptitle[33]; + unsigned char mapmd5[16]; + UINT8 actnum; + UINT8 iszone; + UINT8 fileneeded[915]; // is filled with writexxx (byteptr.h) +} ATTRPACK serverinfo_pak; + +typedef struct +{ + char reason[255]; +} ATTRPACK serverrefuse_pak; + +typedef struct +{ + UINT8 version; + tic_t time; // used for ping evaluation +} ATTRPACK askinfo_pak; + +typedef struct +{ + char clientaddr[22]; + tic_t time; // used for ping evaluation +} ATTRPACK msaskinfo_pak; + +typedef struct +{ + UINT32 randomseed; + + //ctf flag stuff + UINT8 rflagloose; + UINT8 bflagloose; + INT32 rfuse; + INT32 bfuse; + INT32 rflags2; + INT32 bflags2; + INT16 rflagx; + INT16 rflagy; + INT16 rflagz; + INT16 bflagx; + INT16 bflagy; + INT16 bflagz; + + //player stuff + UINT8 playernum; + + UINT8 playerstate; //playerstate_t + ticcmd_t cmd; + fixed_t viewz; + fixed_t viewheight; + fixed_t deltaviewheight; + fixed_t bob; + angle_t aiming; + angle_t awayviewaiming; + INT32 phealth; + SINT8 pity; + INT32 currentweapon; + INT32 ringweapons; + UINT16 powers[NUMPOWERS]; + UINT32 pflags; //pflags_t + UINT8 panim; //panim_t + INT32 flashcount; + UINT8 skincolor; + INT32 skin; + UINT32 score; + INT32 maxlink; + fixed_t dashspeed; + INT32 dashtime; + fixed_t normalspeed; + fixed_t runspeed; + UINT8 thrustfactor; + UINT8 accelstart; + UINT8 acceleration; + UINT8 charability; + UINT8 charability2; + UINT32 charflags; + UINT32 thokitem; //mobjtype_t + UINT32 spinitem; //mobjtype_t + UINT32 revitem; //mobjtype_t + INT32 actionspd; + INT32 mindash; + INT32 maxdash; + fixed_t jumpfactor; + INT32 lives; + INT32 continues; + INT32 xtralife; + fixed_t speed; + INT32 jumping; + UINT8 secondjump; + UINT8 fly1; + UINT8 scoreadd; + tic_t glidetime; + UINT8 climbing; + INT32 deadtimer; + tic_t exiting; + UINT8 homing; + tic_t skidtime; + fixed_t cmomx; + fixed_t cmomy; + fixed_t rmomx; + fixed_t rmomy; + INT32 numboxes; + INT32 totalring; + tic_t realtime; + UINT32 laps; + INT32 ctfteam; + UINT16 gotflag; + INT32 weapondelay; + INT32 tossdelay; + INT16 starpostx; + INT16 starposty; + INT16 starpostz; + INT32 starpostnum; + tic_t starposttime; + angle_t starpostangle; + angle_t angle_pos; + angle_t old_angle_pos; + tic_t bumpertime; + INT32 flyangle; + tic_t drilltimer; + INT32 linkcount; + tic_t linktimer; + INT32 anotherflyangle; + tic_t nightstime; + INT32 drillmeter; + UINT8 drilldelay; + UINT8 bonustime; + UINT8 mare; + INT16 lastsidehit, lastlinehit; + tic_t losstime; + UINT8 timeshit; + INT32 onconveyor; + UINT8 spectator; //boolean + tic_t jointime; + + //player->mo stuff + UINT8 hasmo; //boolean + + angle_t angle; + fixed_t x; + fixed_t y; + fixed_t z; + fixed_t momx; + fixed_t momy; + fixed_t momz; + fixed_t friction; + fixed_t movefactor; + + INT32 tics; + statenum_t statenum; + UINT32 flags; + UINT32 flags2; + UINT8 eflags; + INT32 health; + + fixed_t radius; + fixed_t height; + fixed_t scale; + fixed_t destscale; + fixed_t scalespeed; +} ATTRPACK cons_pak; + +// Shorter player information for external use. +typedef struct +{ + UINT8 node; + char name[MAXPLAYERNAME+1]; + UINT8 address[4]; // sending another string would run us up against MAXPACKETLENGTH + UINT8 team; + UINT8 skin; + UINT8 data; // Color is first four bits, hasflag, isit and issuper have one bit each, the last is unused. + UINT32 score; + UINT16 timeinserver; // In seconds. +} ATTRPACK plrinfo; + +// Shortest player information for join during intermission. +typedef struct +{ + char name[MAXPLAYERNAME+1]; + UINT8 skin; + UINT8 color; + UINT32 pflags; + UINT32 score; + UINT8 ctfteam; +} ATTRPACK plrconfig; + +// +// Network packet data. +// +typedef struct +{ + UINT32 checksum; + UINT8 ack; // if not null the node asks for acknowledgement, the receiver must resend the ack + UINT8 ackreturn; // the return of the ack number + + UINT8 packettype; + UINT8 reserved; // padding + union + { + clientcmd_pak clientpak; // 144 bytes + client2cmd_pak client2pak; // 200 bytes + servertics_pak serverpak; // 132495 bytes + serverconfig_pak servercfg; // 773 bytes + UINT8 textcmd[MAXTEXTCMD+1]; // 66049 bytes + filetx_pak filetxpak; // 139 bytes + clientconfig_pak clientcfg; // 136 bytes + serverinfo_pak serverinfo; // 1024 bytes + serverrefuse_pak serverrefuse; // 65025 bytes + askinfo_pak askinfo; // 61 bytes + msaskinfo_pak msaskinfo; // 22 bytes + cons_pak consistency; // 544 bytes + plrinfo playerinfo[MAXPLAYERS]; // 1152 bytes + plrconfig playerconfig[MAXPLAYERS]; // (up to) 896 bytes +#ifdef NEWPING + UINT32 pingtable[MAXPLAYERS]; // 128 bytes +#endif + } u; // this is needed to pack diff packet types data together +} ATTRPACK doomdata_t; + +#if defined(_MSC_VER) +#pragma pack() +#endif + +#define MAXSERVERLIST 64 // depends only on the display +typedef struct +{ + SINT8 node; + serverinfo_pak info; +} serverelem_t; + +extern serverelem_t serverlist[MAXSERVERLIST]; +extern UINT32 serverlistcount; +extern INT32 mapchangepending; + +// points inside doomcom +extern doomdata_t *netbuffer; + +extern consvar_t cv_playbackspeed; + +#define BASEPACKETSIZE ((size_t)&(((doomdata_t *)0)->u)) +#define FILETXHEADER ((size_t)((filetx_pak *)0)->data) +#define BASESERVERTICSSIZE ((size_t)&(((doomdata_t *)0)->u.serverpak.cmds[0])) + +#define KICK_MSG_GO_AWAY 1 +#define KICK_MSG_CON_FAIL 2 +#define KICK_MSG_PLAYER_QUIT 3 +#define KICK_MSG_TIMEOUT 4 +#define KICK_MSG_BANNED 5 +#ifdef NEWPING +#define KICK_MSG_PING_HIGH 6 +#endif +#define KICK_MSG_CUSTOM_KICK 7 +#define KICK_MSG_CUSTOM_BAN 8 + +extern boolean server; +extern boolean dedicated; // for dedicated server +extern UINT16 software_MAXPACKETLENGTH; +extern boolean acceptnewnode; +extern SINT8 servernode; + +void Command_Ping_f(void); +extern tic_t connectiontimeout; +#ifdef NEWPING +extern UINT16 pingmeasurecount; +extern UINT32 realpingtable[MAXPLAYERS]; +extern UINT32 playerpingtable[MAXPLAYERS]; +#endif + +extern consvar_t cv_joinnextround, cv_allownewplayer, cv_maxplayers, cv_consfailprotect, cv_blamecfail, cv_maxsend; + +// used in d_net, the only dependence +tic_t ExpandTics(INT32 low); +void D_ClientServerInit(void); + +// initialise the other field +void RegisterNetXCmd(netxcmd_t id, void (*cmd_f)(UINT8 **p, INT32 playernum)); +void SendNetXCmd(netxcmd_t id, const void *param, size_t nparam); +void SendNetXCmd2(netxcmd_t id, const void *param, size_t nparam); // splitsreen player + +// Create any new ticcmds and broadcast to other players. +void NetUpdate(void); + +void SV_StartSinglePlayerServer(void); +boolean SV_SpawnServer(void); +void SV_SpawnPlayer(INT32 playernum, INT32 x, INT32 y, angle_t angle); +void SV_StopServer(void); +void SV_ResetServer(void); +void CL_AddSplitscreenPlayer(void); +void CL_RemoveSplitscreenPlayer(void); +void CL_Reset(void); +void CL_ClearPlayer(INT32 playernum); +void CL_UpdateServerList(boolean internetsearch, INT32 room); +// is there a game running +boolean Playing(void); + +// Broadcasts special packets to other players +// to notify of game exit +void D_QuitNetGame(void); + +//? how many ticks to run? +void TryRunTics(tic_t realtic); + +// extra data for lmps +// these functions scare me. they contain magic. +/*boolean AddLmpExtradata(UINT8 **demo_p, INT32 playernum); +void ReadLmpExtraData(UINT8 **demo_pointer, INT32 playernum);*/ + +#ifndef NONET +// translate a playername in a player number return -1 if not found and +// print a error message in the console +SINT8 nametonum(const char *name); +#endif + +extern char motd[254], server_context[8]; +extern UINT8 playernode[MAXPLAYERS]; +extern UINT8 consfailcount[MAXPLAYERS]; + +INT32 D_NumPlayers(void); +void D_ResetTiccmds(void); + +tic_t GetLag(INT32 node); +UINT8 GetFreeXCmdSize(void); + +#endif diff --git a/src/d_event.h b/src/d_event.h new file mode 100644 index 000000000..cf5cf02d7 --- /dev/null +++ b/src/d_event.h @@ -0,0 +1,49 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 1993-1996 by id Software, Inc. +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Copyright (C) 1999-2014 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file d_event.h +/// \brief Event handling + +#ifndef __D_EVENT__ +#define __D_EVENT__ + +#include "doomtype.h" +#include "g_state.h" + +// Input event types. +typedef enum +{ + ev_keydown, + ev_keyup, + ev_console, + ev_mouse, + ev_joystick, + ev_mouse2, + ev_joystick2, +} evtype_t; + +// Event structure. +typedef struct +{ + evtype_t type; + INT32 data1; // keys / mouse/joystick buttons + INT32 data2; // mouse/joystick x move + INT32 data3; // mouse/joystick y move +} event_t; + +// +// GLOBAL VARIABLES +// +#define MAXEVENTS 128 + +extern event_t events[MAXEVENTS]; +extern INT32 eventhead, eventtail; + +#endif diff --git a/src/d_main.c b/src/d_main.c new file mode 100644 index 000000000..6a0be9ceb --- /dev/null +++ b/src/d_main.c @@ -0,0 +1,1395 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 1993-1996 by id Software, Inc. +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Copyright (C) 1999-2014 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file d_main.c +/// \brief SRB2 main program +/// +/// SRB2 main program (D_SRB2Main) and game loop (D_SRB2Loop), +/// plus functions to parse command line parameters, configure game +/// parameters, and call the startup functions. + +#if (defined (__unix__) && !defined (MSDOS)) || defined(__APPLE__) || defined (UNIXCOMMON) +#include +#include +#endif + +#ifdef __GNUC__ +#include // for getcwd +#endif + +#ifdef PC_DOS +#include // for snprintf +int snprintf(char *str, size_t n, const char *fmt, ...); +//int vsnprintf(char *str, size_t n, const char *fmt, va_list ap); +#endif + +#if (defined (_WIN32) && !defined (_WIN32_WCE)) && !defined (_XBOX) +#include +#include +#endif + +#if !defined (UNDER_CE) +#include +#elif defined (_XBOX) +#define NO_TIME +#endif + +#include "doomdef.h" +#include "am_map.h" +#include "console.h" +#include "d_net.h" +#include "f_finale.h" +#include "g_game.h" +#include "hu_stuff.h" +#include "i_sound.h" +#include "i_system.h" +#include "i_video.h" +#include "m_argv.h" +#include "m_menu.h" +#include "m_misc.h" +#include "p_setup.h" +#include "p_saveg.h" +#include "r_main.h" +#include "r_local.h" +#include "s_sound.h" +#include "st_stuff.h" +#include "v_video.h" +#include "w_wad.h" +#include "z_zone.h" +#include "d_main.h" +#include "d_netfil.h" +#include "m_cheat.h" +#include "y_inter.h" +#include "p_local.h" // chasecam +#include "mserv.h" // ms_RoomId +#include "m_misc.h" // screenshot functionality +#include "dehacked.h" // Dehacked list test +#include "m_cond.h" // condition initialization +#include "fastcmp.h" + +#ifdef _XBOX +#include "sdl/SRB2XBOX/xboxhelp.h" +#endif + +#ifdef HWRENDER +#include "hardware/hw_main.h" // 3D View Rendering +#endif + +#ifdef _WINDOWS +#include "win32/win_main.h" // I_DoStartupMouse +#endif + +#ifdef HW3SOUND +#include "hardware/hw3sound.h" +#endif + +// +// DEMO LOOP +// +//static INT32 demosequence; +static const char *pagename = "MAP1PIC"; +static char *startupwadfiles[MAX_WADFILES]; + +boolean devparm = false; // started game with -devparm + +boolean singletics = false; // timedemo +boolean lastdraw = false; + +postimg_t postimgtype = postimg_none; +INT32 postimgparam; +postimg_t postimgtype2 = postimg_none; +INT32 postimgparam2; + +#ifdef _XBOX +boolean nomidimusic = true, nosound = true; +boolean nodigimusic = true; +#else +boolean nomidimusic = false, nosound = false; +boolean nodigimusic = false; // No fmod-based music +#endif + +// These variables are only true if +// the respective sound system is initialized +// and active, but no sounds/music should play. +boolean music_disabled = false; +boolean sound_disabled = false; +boolean digital_disabled = false; + +boolean advancedemo; +#ifdef DEBUGFILE +INT32 debugload = 0; +#endif + +#ifdef _arch_dreamcast +char srb2home[256] = "/cd"; +char srb2path[256] = "/cd"; +#else +char srb2home[256] = "."; +char srb2path[256] = "."; +#endif +boolean usehome = true; +const char *pandf = "%s" PATHSEP "%s"; + +// +// EVENT HANDLING +// +// Events are asynchronous inputs generally generated by the game user. +// Events can be discarded if no responder claims them +// referenced from i_system.c for I_GetKey() + +event_t events[MAXEVENTS]; +INT32 eventhead, eventtail; + +boolean dedicated = false; + +// +// D_PostEvent +// Called by the I/O functions when input is detected +// +void D_PostEvent(const event_t *ev) +{ + events[eventhead] = *ev; + eventhead = (eventhead+1) & (MAXEVENTS-1); +} +// just for lock this function +#ifndef DOXYGEN +void D_PostEvent_end(void) {}; +#endif + +// +// D_ProcessEvents +// Send all the events of the given timestamp down the responder chain +// +void D_ProcessEvents(void) +{ + event_t *ev; + + for (; eventtail != eventhead; eventtail = (eventtail+1) & (MAXEVENTS-1)) + { + ev = &events[eventtail]; + + // Screenshots over everything so that they can be taken anywhere. + if (M_ScreenshotResponder(ev)) + continue; // ate the event + + if (gameaction == ga_nothing && gamestate == GS_TITLESCREEN) + { + if (cht_Responder(ev)) + continue; + } + + // Menu input + if (M_Responder(ev)) + continue; // menu ate the event + + // console input + if (CON_Responder(ev)) + continue; // ate the event + + G_Responder(ev); + } +} + +// +// D_Display +// draw current display, possibly wiping it from the previous +// + +// wipegamestate can be set to -1 to force a wipe on the next draw +// added comment : there is a wipe eatch change of the gamestate +gamestate_t wipegamestate = GS_LEVEL; + +static void D_Display(void) +{ + static boolean menuactivestate = false; + static gamestate_t oldgamestate = -1; + boolean redrawsbar = false; + + static boolean wipe = false; + INT32 wipedefindex = 0; + + if (dedicated) + return; + + if (nodrawers) + return; // for comparative timing/profiling + + // check for change of screen size (video mode) + if (setmodeneeded && !wipe) + SCR_SetMode(); // change video mode + + if (vid.recalc) + SCR_Recalc(); // NOTE! setsizeneeded is set by SCR_Recalc() + + // change the view size if needed + if (setsizeneeded) + { + R_ExecuteSetViewSize(); + oldgamestate = -1; // force background redraw + redrawsbar = true; + } + + // save the current screen if about to wipe + if (gamestate != wipegamestate) + { + wipe = true; + F_WipeStartScreen(); + } + else + wipe = false; + + // draw buffered stuff to screen + // Used only by linux GGI version + I_UpdateNoBlit(); + + if (wipe) + { + // set for all later + wipedefindex = gamestate; // wipe_xxx_toblack + if (gamestate == GS_INTERMISSION) + { + if (intertype == int_spec) // Special Stage + wipedefindex = wipe_specinter_toblack; + else if (intertype != int_coop) // Multiplayer + wipedefindex = wipe_multinter_toblack; + } + + if (rendermode != render_none) + { + // Fade to black first + if (gamestate != GS_LEVEL // fades to black on its own timing, always + && wipedefs[wipedefindex] != UINT8_MAX) + { + V_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, 31); +#ifdef HWRENDER + if(rendermode != render_soft) + HWR_PrepFadeToBlack(); +#endif + F_WipeEndScreen(); + F_RunWipe(wipedefs[wipedefindex], gamestate != GS_TIMEATTACK); + } + + F_WipeStartScreen(); + } + } + + // do buffered drawing + switch (gamestate) + { + case GS_LEVEL: + if (!gametic) + break; + HU_Erase(); + if (automapactive) + AM_Drawer(); + if (wipe || menuactivestate || (rendermode != render_soft && rendermode != render_none) || vid.recalc) + redrawsbar = true; + break; + + case GS_INTERMISSION: + Y_IntermissionDrawer(); + HU_Erase(); + HU_Drawer(); + break; + + case GS_TIMEATTACK: + break; + + case GS_INTRO: + F_IntroDrawer(); + if (wipegamestate == (gamestate_t)-1) + wipe = true; + break; + + case GS_CUTSCENE: + F_CutsceneDrawer(); + HU_Erase(); + HU_Drawer(); + break; + + case GS_GAMEEND: + F_GameEndDrawer(); + break; + + case GS_EVALUATION: + F_GameEvaluationDrawer(); + HU_Drawer(); + break; + + case GS_CONTINUING: + F_ContinueDrawer(); + break; + + case GS_CREDITS: + F_CreditDrawer(); + HU_Erase(); + HU_Drawer(); + break; + + case GS_TITLESCREEN: + F_TitleScreenDrawer(); + break; + + case GS_WAITINGPLAYERS: + // The clientconnect drawer is independent... + case GS_DEDICATEDSERVER: + case GS_NULL: + break; + } + + // clean up border stuff + // see if the border needs to be initially drawn + if (gamestate == GS_LEVEL) + { +#if 0 + if (oldgamestate != GS_LEVEL) + R_FillBackScreen(); // draw the pattern into the back screen +#endif + + // draw the view directly + if (!automapactive && !dedicated && cv_renderview.value) + { + if (players[displayplayer].mo || players[displayplayer].playerstate == PST_DEAD) + { + topleft = screens[0] + viewwindowy*vid.width + viewwindowx; + objectsdrawn = 0; +#ifdef HWRENDER + if (rendermode != render_soft) + HWR_RenderPlayerView(0, &players[displayplayer]); + else +#endif + if (rendermode != render_none) + R_RenderPlayerView(&players[displayplayer]); + } + + // render the second screen + if (splitscreen && players[secondarydisplayplayer].mo) + { +#ifdef HWRENDER + if (rendermode != render_soft) + HWR_RenderPlayerView(1, &players[secondarydisplayplayer]); + else +#endif + if (rendermode != render_none) + { + viewwindowy = vid.height / 2; + M_Memcpy(ylookup, ylookup2, viewheight*sizeof (ylookup[0])); + + topleft = screens[0] + viewwindowy*vid.width + viewwindowx; + + R_RenderPlayerView(&players[secondarydisplayplayer]); + + viewwindowy = 0; + M_Memcpy(ylookup, ylookup1, viewheight*sizeof (ylookup[0])); + } + } + + // Image postprocessing effect + if (postimgtype) + V_DoPostProcessor(0, postimgtype, postimgparam); + if (postimgtype2) + V_DoPostProcessor(1, postimgtype2, postimgparam2); + } + + if (lastdraw) + { + if (rendermode == render_soft) + VID_BlitLinearScreen(screens[0], screens[1], vid.width*vid.bpp, vid.height, vid.width*vid.bpp, vid.rowbytes); + lastdraw = false; + } + + ST_Drawer(redrawsbar); + + HU_Drawer(); + } + + // change gamma if needed + if (gamestate != oldgamestate && gamestate != GS_LEVEL) + V_SetPalette(0); + + menuactivestate = menuactive; + oldgamestate = wipegamestate = gamestate; + + // draw pause pic + if (paused && cv_showhud.value && (!menuactive || netgame)) + { + INT32 py; + patch_t *patch; + if (automapactive) + py = 4; + else + py = viewwindowy + 4; + patch = W_CachePatchName("M_PAUSE", PU_CACHE); + V_DrawScaledPatch(viewwindowx + (BASEVIDWIDTH - SHORT(patch->width))/2, py, 0, patch); + } + + // vid size change is now finished if it was on... + vid.recalc = 0; + + // FIXME: draw either console or menu, not the two + if (gamestate != GS_TIMEATTACK) + CON_Drawer(); + + M_Drawer(); // menu is drawn even on top of everything + NetUpdate(); // send out any new accumulation + + // It's safe to end the game now. + if (G_GetExitGameFlag()) + { + Command_ExitGame_f(); + G_ClearExitGameFlag(); + } + + // + // normal update + // + if (!wipe) + { + if (cv_netstat.value) + { + char s[50]; + Net_GetNetStat(); + + s[sizeof s - 1] = '\0'; + + snprintf(s, sizeof s - 1, "get %d b/s", getbps); + V_DrawRightAlignedString(BASEVIDWIDTH, BASEVIDHEIGHT-ST_HEIGHT-40, V_YELLOWMAP, s); + snprintf(s, sizeof s - 1, "send %d b/s", sendbps); + V_DrawRightAlignedString(BASEVIDWIDTH, BASEVIDHEIGHT-ST_HEIGHT-30, V_YELLOWMAP, s); + snprintf(s, sizeof s - 1, "GameMiss %.2f%%", gamelostpercent); + V_DrawRightAlignedString(BASEVIDWIDTH, BASEVIDHEIGHT-ST_HEIGHT-20, V_YELLOWMAP, s); + snprintf(s, sizeof s - 1, "SysMiss %.2f%%", lostpercent); + V_DrawRightAlignedString(BASEVIDWIDTH, BASEVIDHEIGHT-ST_HEIGHT-10, V_YELLOWMAP, s); + } + + I_FinishUpdate(); // page flip or blit buffer + return; + } + + // + // wipe update + // + wipedefindex += WIPEFINALSHIFT; + + if (rendermode != render_none) + { + F_WipeEndScreen(); + F_RunWipe(wipedefs[wipedefindex], gamestate != GS_TIMEATTACK); + } +} + +// ========================================================================= +// D_SRB2Loop +// ========================================================================= + +tic_t rendergametic; +boolean supdate; + +void D_SRB2Loop(void) +{ + tic_t oldentertics = 0, entertic = 0, realtics = 0, rendertimeout = INFTICS; + + if (dedicated) + server = true; + + if (M_CheckParm("-voodoo")) // 256x256 Texture Limiter + COM_BufAddText("gr_voodoocompatibility on\n"); + + // Pushing of + parameters is now done back in D_SRB2Main, not here. + + CONS_Printf("I_StartupKeyboard()...\n"); + I_StartupKeyboard(); + +#ifdef _WINDOWS + CONS_Printf("I_StartupMouse()...\n"); + I_DoStartupMouse(); +#endif + + oldentertics = I_GetTime(); + + // end of loading screen: CONS_Printf() will no more call FinishUpdate() + con_startup = false; + + // make sure to do a d_display to init mode _before_ load a level + SCR_SetMode(); // change video mode + SCR_Recalc(); + + // Check and print which version is executed. + // Use this as the border between setup and the main game loop being entered. + CONS_Printf( + "===========================================================================\n" + " We hope you enjoy this game as\n" + " much as we did making it!\n" + " ...wait. =P\n" + "===========================================================================\n"); + + // hack to start on a nice clear console screen. + COM_ImmedExecute("cls;version"); + + if (rendermode == render_soft) + V_DrawScaledPatch(0, 0, 0, (patch_t *)W_CacheLumpNum(W_GetNumForName("CONSBACK"), PU_CACHE)); + I_FinishUpdate(); // page flip or blit buffer + + for (;;) + { + if (lastwipetic) + { + oldentertics = lastwipetic; + lastwipetic = 0; + } + + // get real tics + entertic = I_GetTime(); + realtics = entertic - oldentertics; + oldentertics = entertic; + +#ifdef DEBUGFILE + if (!realtics) + if (debugload) + debugload--; +#endif + + if (!realtics && !singletics) + { + I_Sleep(); + continue; + } + +#ifdef HW3SOUND + HW3S_BeginFrameUpdate(); +#endif + + // don't skip more than 10 frames at a time + // (fadein / fadeout cause massive frame skip!) + if (realtics > 8) + realtics = 1; + + // process tics (but maybe not if realtic == 0) + TryRunTics(realtics); + + if (lastdraw || singletics || gametic > rendergametic) + { + rendergametic = gametic; + rendertimeout = entertic+TICRATE/17; + + // Update display, next frame, with current state. + D_Display(); + supdate = false; + + if (moviemode) + M_SaveFrame(); + if (takescreenshot) // Only take screenshots after drawing. + M_DoScreenShot(); + } + else if (rendertimeout < entertic) // in case the server hang or netsplit + { + // Lagless camera! Yay! + if (gamestate == GS_LEVEL && netgame) + { + if (splitscreen && camera2.chase) + P_MoveChaseCamera(&players[secondarydisplayplayer], &camera2, false); + if (camera.chase) + P_MoveChaseCamera(&players[displayplayer], &camera, false); + } + D_Display(); + + if (moviemode) + M_SaveFrame(); + if (takescreenshot) // Only take screenshots after drawing. + M_DoScreenShot(); + } + + // consoleplayer -> displayplayer (hear sounds from viewpoint) + S_UpdateSounds(); // move positional sounds + + // check for media change, loop music.. + I_UpdateCD(); + +#ifdef HW3SOUND + HW3S_EndFrameUpdate(); +#endif + } +} + +// +// D_AdvanceDemo +// Called after each demo or intro demosequence finishes +// +void D_AdvanceDemo(void) +{ + advancedemo = true; +} + +// ========================================================================= +// D_SRB2Main +// ========================================================================= + +// +// D_StartTitle +// +void D_StartTitle(void) +{ + if (netgame) + { + if (gametype == GT_COOP) + { + G_SetGamestate(GS_WAITINGPLAYERS); // hack to prevent a command repeat + + if (server) + { + char mapname[6]; + + strlcpy(mapname, G_BuildMapName(spstage_start), sizeof (mapname)); + strlwr(mapname); + mapname[5] = '\0'; + + COM_BufAddText(va("map %s\n", mapname)); + } + } + + return; + } + + // okay, stop now + // (otherwise the game still thinks we're playing!) + SV_StopServer(); + + // In case someone exits out at the same time they start a time attack run, + // reset modeattacking + modeattacking = ATTACKING_NONE; + + // empty maptol so mario/etc sounds don't play in sound test when they shouldn't + maptol = 0; + + gameaction = ga_nothing; + playerdeadview = false; + displayplayer = consoleplayer = 0; + //demosequence = -1; + gametype = GT_COOP; + paused = false; + advancedemo = false; + F_StartTitleScreen(); + CON_ToggleOff(); + + // Reset the palette +#ifdef HWRENDER + if (rendermode == render_opengl) + HWR_SetPaletteColor(0); + else +#endif + if (rendermode != render_none) + V_SetPaletteLump("PLAYPAL"); +} + +// +// D_AddFile +// +static void D_AddFile(const char *file) +{ + size_t pnumwadfiles; + char *newfile; + + for (pnumwadfiles = 0; startupwadfiles[pnumwadfiles]; pnumwadfiles++) + ; + + newfile = malloc(strlen(file) + 1); + if (!newfile) + { + I_Error("No more free memory to AddFile %s",file); + } + strcpy(newfile, file); + + startupwadfiles[pnumwadfiles] = newfile; +} + +static inline void D_CleanFile(void) +{ + size_t pnumwadfiles; + for (pnumwadfiles = 0; startupwadfiles[pnumwadfiles]; pnumwadfiles++) + { + free(startupwadfiles[pnumwadfiles]); + startupwadfiles[pnumwadfiles] = NULL; + } +} + +#ifndef _MAX_PATH +#define _MAX_PATH MAX_WADPATH +#endif + +// ========================================================================== +// Identify the SRB2 version, and IWAD file to use. +// ========================================================================== + +static void IdentifyVersion(void) +{ + char *srb2wad1, *srb2wad2; + const char *srb2waddir = NULL; + +#if (defined (__unix__) && !defined (MSDOS)) || defined (UNIXCOMMON) || defined (SDL) + // change to the directory where 'srb2.srb' is found + srb2waddir = I_LocateWad(); +#endif + + // get the current directory (possible problem on NT with "." as current dir) + if (srb2waddir) + { + strlcpy(srb2path,srb2waddir,sizeof (srb2path)); + } + else + { +#if !defined(_WIN32_WCE) && !defined(_PS3) + if (getcwd(srb2path, 256) != NULL) + srb2waddir = srb2path; + else +#endif + { +#ifdef _arch_dreamcast + srb2waddir = "/cd"; +#else + srb2waddir = "."; +#endif + } + } + +#if defined (macintosh) && !defined (SDL) + // cwd is always "/" when app is dbl-clicked + if (!stricmp(srb2waddir, "/")) + srb2waddir = I_GetWadDir(); +#endif + // Commercial. + srb2wad1 = malloc(strlen(srb2waddir)+1+8+1); + srb2wad2 = malloc(strlen(srb2waddir)+1+8+1); + if (srb2wad1 == NULL && srb2wad2 == NULL) + I_Error("No more free memory to look in %s", srb2waddir); + if (srb2wad1 != NULL) + sprintf(srb2wad1, pandf, srb2waddir, "srb2.srb"); + if (srb2wad2 != NULL) + sprintf(srb2wad2, pandf, srb2waddir, "srb2.wad"); + + // will be overwritten in case of -cdrom or unix/win home + snprintf(configfile, sizeof configfile, "%s" PATHSEP CONFIGFILENAME, srb2waddir); + configfile[sizeof configfile - 1] = '\0'; + + // Load the IWAD + if (srb2wad2 != NULL && FIL_ReadFileOK(srb2wad2)) + D_AddFile(srb2wad2); + else if (srb2wad1 != NULL && FIL_ReadFileOK(srb2wad1)) + D_AddFile(srb2wad1); + else + I_Error("SRB2.SRB/SRB2.WAD not found! Expected in %s, ss files: %s and %s\n", srb2waddir, srb2wad1, srb2wad2); + + if (srb2wad1) + free(srb2wad1); + if (srb2wad2) + free(srb2wad2); + + // if you change the ordering of this or add/remove a file, be sure to update the md5 + // checking in D_SRB2Main + + // Add the maps + D_AddFile(va(pandf,srb2waddir,"zones.dta")); + + // Add the players + D_AddFile(va(pandf,srb2waddir, "player.dta")); + + // Add the weapons + D_AddFile(va(pandf,srb2waddir,"rings.dta")); + +#if !defined (SDL) || defined (HAVE_MIXER) + { +#if defined (DC) && 0 + const char *musicfile = "music_dc.dta"; +#else + const char *musicfile = "music.dta"; +#endif + const char *musicpath = va(pandf,srb2waddir,musicfile); + int ms = W_VerifyNMUSlumps(musicpath); // Don't forget the music! + if (ms == 1) + D_AddFile(musicpath); + else if (ms == 0) + I_Error("File %s has been modified with non-music lumps",musicfile); + } +#endif + + // D_AddFile(va(pandf,srb2waddir,"patch.dta")); //for dev +} + +/* ======================================================================== */ +// Just print the nice red titlebar like the original SRB2 for DOS. +/* ======================================================================== */ +#ifdef PC_DOS +static inline void D_Titlebar(char *title1, char *title2) +{ + // SRB2 banner + clrscr(); + textattr((BLUE<<4)+WHITE); + clreol(); + cputs(title1); + + // standard srb2 banner + textattr((RED<<4)+WHITE); + clreol(); + gotoxy((80-strlen(title2))/2, 2); + cputs(title2); + normvideo(); + gotoxy(1,3); +} +#endif + +// +// Center the title string, then add the date and time of compilation. +// +static inline void D_MakeTitleString(char *s) +{ + char temp[82]; + char *t; + const char *u; + INT32 i; + + for (i = 0, t = temp; i < 82; i++) + *t++=' '; + + for (t = temp + (80-strlen(s))/2, u = s; *u != '\0' ;) + *t++ = *u++; + + u = compdate; + for (t = temp + 1, i = 11; i-- ;) + *t++ = *u++; + u = comptime; + for (t = temp + 71, i = 8; i-- ;) + *t++ = *u++; + + temp[80] = '\0'; + strcpy(s, temp); +} + + +// +// D_SRB2Main +// +void D_SRB2Main(void) +{ + INT32 p; + char srb2[82]; // srb2 title banner + char title[82]; + + INT32 pstartmap = 1; + boolean autostart = false; + + // keep error messages until the final flush(stderr) +#if !defined (PC_DOS) && !defined (_WIN32_WCE) && !defined(NOTERMIOS) + if (setvbuf(stderr, NULL, _IOFBF, 1000)) + I_OutputMsg("setvbuf didnt work\n"); +#endif + +#ifdef GETTEXT + // initialise locale code + M_StartupLocale(); +#endif + + // get parameters from a response file (eg: srb2 @parms.txt) + M_FindResponseFile(); + + // MAINCFG is now taken care of where "OBJCTCFG" is handled + G_LoadGameSettings(); + + // Test Dehacked lists + DEH_Check(); + + // identify the main IWAD file to use + IdentifyVersion(); + +#if !defined (_WIN32_WCE) && !defined(NOTERMIOS) + setbuf(stdout, NULL); // non-buffered output +#endif + +#if defined (_WIN32_WCE) //|| defined (_DEBUG) || defined (GP2X) + devparm = !M_CheckParm("-nodebug"); +#else + devparm = M_CheckParm("-debug"); +#endif + + // for dedicated server +#if !defined (_WINDOWS) //already check in win_main.c + dedicated = M_CheckParm("-dedicated") != 0; +#endif + + strcpy(title, "Sonic Robo Blast 2"); + strcpy(srb2, "Sonic Robo Blast 2"); + D_MakeTitleString(srb2); + +#ifdef PC_DOS + D_Titlebar(srb2, title); +#endif + +#if defined (__OS2__) && !defined (SDL) + // set PM window title + snprintf(pmData->title, sizeof (pmData->title), + "Sonic Robo Blast 2" VERSIONSTRING ": %s", + title); + pmData->title[sizeof (pmData->title) - 1] = '\0'; +#endif + + if (devparm) + CONS_Printf(M_GetText("Development mode ON.\n")); + + // default savegame + strcpy(savegamename, SAVEGAMENAME"%u.ssg"); + + { + const char *userhome = D_Home(); //Alam: path to home + + if (!userhome) + { +#if ((defined (__unix__) && !defined (MSDOS)) || defined(__APPLE__) || defined (UNIXCOMMON)) && !defined (__CYGWIN__) && !defined (DC) && !defined (PSP) && !defined(GP2X) + I_Error("Please set $HOME to your home directory\n"); +#elif defined (_WIN32_WCE) && 0 + if (dedicated) + snprintf(configfile, sizeof configfile, "/Storage Card/SRB2DEMO/d"CONFIGFILENAME); + else + snprintf(configfile, sizeof configfile, "/Storage Card/SRB2DEMO/"CONFIGFILENAME); +#else + if (dedicated) + snprintf(configfile, sizeof configfile, "d"CONFIGFILENAME); + else + snprintf(configfile, sizeof configfile, CONFIGFILENAME); +#endif + } + else + { + // use user specific config file +#ifdef DEFAULTDIR + snprintf(srb2home, sizeof srb2home, "%s" PATHSEP DEFAULTDIR, userhome); + snprintf(downloaddir, sizeof downloaddir, "%s" PATHSEP "DOWNLOAD", srb2home); + if (dedicated) + snprintf(configfile, sizeof configfile, "%s" PATHSEP "d"CONFIGFILENAME, srb2home); + else + snprintf(configfile, sizeof configfile, "%s" PATHSEP CONFIGFILENAME, srb2home); + + // can't use sprintf since there is %u in savegamename + strcatbf(savegamename, srb2home, PATHSEP); + + I_mkdir(srb2home, 0700); +#else + snprintf(srb2home, sizeof srb2home, "%s", userhome); + snprintf(downloaddir, sizeof downloaddir, "%s", userhome); + if (dedicated) + snprintf(configfile, sizeof configfile, "%s" PATHSEP "d"CONFIGFILENAME, userhome); + else + snprintf(configfile, sizeof configfile, "%s" PATHSEP CONFIGFILENAME, userhome); + + // can't use sprintf since there is %u in savegamename + strcatbf(savegamename, userhome, PATHSEP); +#endif + } + + configfile[sizeof configfile - 1] = '\0'; + +#ifdef _arch_dreamcast + strcpy(downloaddir, "/ram"); // the dreamcast's TMP +#endif + } + + // rand() needs seeded regardless of password + srand((unsigned int)time(NULL)); + + if (M_CheckParm("-password") && M_IsNextParm()) + D_SetPassword(M_GetNextParm()); + else + { + size_t z; + char junkpw[25]; + for (z = 0; z < 24; z++) + junkpw[z] = (char)(rand() & 64)+32; + junkpw[24] = '\0'; + D_SetPassword(junkpw); + } + + // add any files specified on the command line with -file wadfile + // to the wad list + if (!(M_CheckParm("-connect"))) + { + if (M_CheckParm("-file")) + { + // the parms after p are wadfile/lump names, + // until end of parms or another - preceded parm + while (M_IsNextParm()) + { + const char *s = M_GetNextParm(); + + if (s) // Check for NULL? + { + if (!W_VerifyNMUSlumps(s)) + G_SetGameModified(true); + D_AddFile(s); + } + } + } + } + + // get map from parms + + if (M_CheckParm("-server") || dedicated) + netgame = server = true; + + if (M_CheckParm("-warp") && M_IsNextParm()) + { + const char *word = M_GetNextParm(); + if (fastncmp(word, "MAP", 3)) + pstartmap = M_MapNumber(word[3], word[4]); + else + pstartmap = atoi(word); + // Don't check if lump exists just yet because the wads haven't been loaded! + // Just do a basic range check here. + if (pstartmap < 1 || pstartmap > NUMMAPS) + I_Error("Cannot warp to map %d (out of range)\n", pstartmap); + else + { + if (!M_CheckParm("-server")) + G_SetGameModified(true); + autostart = true; + } + } + + CONS_Printf("Z_Init(): Init zone memory allocation daemon. \n"); + Z_Init(); + + // adapt tables to SRB2's needs, including extra slots for dehacked file support + P_PatchInfoTables(); + + //---------------------------------------------------- READY TIME + // we need to check for dedicated before initialization of some subsystems + + CONS_Printf("I_StartupTimer()...\n"); + I_StartupTimer(); + + // Make backups of some SOCcable tables. + P_BackupTables(); + + // Setup default unlockable conditions + M_SetupDefaultConditionSets(); + + // load wad, including the main wad file + CONS_Printf("W_InitMultipleFiles(): Adding IWAD and main PWADs.\n"); + if (!W_InitMultipleFiles(startupwadfiles)) +#ifdef _DEBUG + CONS_Error("A WAD file was not found or not valid.\nCheck the log to see which ones.\n"); +#else + I_Error("A WAD file was not found or not valid.\nCheck the log to see which ones.\n"); +#endif + D_CleanFile(); + +#if 1 // md5s last updated 3/15/14 + // Yes, you read that right, that's the day of release. + // Aren't we batshit insane? + + // Check MD5s of autoloaded files + W_VerifyFileMD5(0, "ac309fb3c7d4b5b685e2cd26beccf0e8"); // srb2.srb/srb2.wad + W_VerifyFileMD5(1, "a894044b555dfcc71865cee16a996e88"); // zones.dta + W_VerifyFileMD5(2, "4c410c1de6e0440cc5b2858dcca80c3e"); // player.dta + W_VerifyFileMD5(3, "85901ad4bf94637e5753d2ac2c03ea26"); // rings.dta + //W_VerifyFileMD5(5, ""); // patch.dta (dev changable) + + // don't check music.dta because people like to modify it, and it doesn't matter if they do + // ...except it does if they slip maps in there, and that's what W_VerifyNMUSlumps is for. +#endif + + mainwads = 5; // there are 5 wads not to unload + + cht_Init(); + + //---------------------------------------------------- READY SCREEN + // we need to check for dedicated before initialization of some subsystems + + CONS_Printf("I_StartupGraphics()...\n"); + I_StartupGraphics(); + + //--------------------------------------------------------- CONSOLE + // setup loading screen + SCR_Startup(); + + // we need the font of the console + CONS_Printf("HU_Init(): Setting up heads up display.\n"); + HU_Init(); + + COM_Init(); + // libogc has a CON_Init function, we must rename SRB2's CON_Init in WII/libogc +#ifndef _WII + CON_Init(); +#else + CON_InitWii(); +#endif + + D_RegisterServerCommands(); + D_RegisterClientCommands(); // be sure that this is called before D_CheckNetGame + R_RegisterEngineStuff(); + S_RegisterSoundStuff(); + + I_RegisterSysCommands(); + + //--------------------------------------------------------- CONFIG.CFG + M_FirstLoadConfig(); // WARNING : this do a "COM_BufExecute()" + + G_LoadGameData(); + +#if (defined (__unix__) && !defined (MSDOS)) || defined (UNIXCOMMON) || defined (SDL) + VID_PrepareModeList(); // Regenerate Modelist according to cv_fullscreen +#endif + + // set user default mode or mode set at cmdline + SCR_CheckDefaultMode(); + + wipegamestate = gamestate; + + P_InitMapHeaders(); + savedata.lives = 0; // flag this as not-used + + //------------------------------------------------ COMMAND LINE PARAMS + + // Initialize CD-Audio + if (M_CheckParm("-usecd") && !dedicated) + I_InitCD(); + + if (M_CheckParm("-noupload")) + COM_BufAddText("downloading 0\n"); + + CONS_Printf("M_Init(): Init miscellaneous info.\n"); + M_Init(); + + CONS_Printf("R_Init(): Init SRB2 refresh daemon.\n"); + R_Init(); + + // setting up sound + CONS_Printf("S_Init(): Setting up sound.\n"); + if (M_CheckParm("-nosound")) + nosound = true; + if (M_CheckParm("-nomusic")) // combines -nomidimusic and -nodigmusic + nomidimusic = nodigimusic = true; + else + { + if (M_CheckParm("-nomidimusic")) + nomidimusic = true; ; // WARNING: DOS version initmusic in I_StartupSound + if (M_CheckParm("-nodigmusic")) + nodigimusic = true; // WARNING: DOS version initmusic in I_StartupSound + } + I_StartupSound(); + I_InitMusic(); + S_Init(cv_soundvolume.value, cv_digmusicvolume.value, cv_midimusicvolume.value); + + CONS_Printf("ST_Init(): Init status bar.\n"); + ST_Init(); + + if (M_CheckParm("-room")) + { + if (!M_IsNextParm()) + I_Error("usage: -room \nCheck the Master Server's webpage for room ID numbers.\n"); + +#ifdef UPDATE_ALERT + GetMODVersion_Console(); +#endif + + ms_RoomId = atoi(M_GetNextParm()); + } + + // init all NETWORK + CONS_Printf("D_CheckNetGame(): Checking network game status.\n"); + if (D_CheckNetGame()) + autostart = true; + + // check for a driver that wants intermission stats + // start the apropriate game based on parms + if (M_CheckParm("-metal")) + { + G_RecordMetal(); + autostart = true; + } + else if (M_CheckParm("-record") && M_IsNextParm()) + { + G_RecordDemo(M_GetNextParm()); + autostart = true; + } + + // user settings come before "+" parameters. + if (dedicated) + COM_ImmedExecute(va("exec \"%s"PATHSEP"adedserv.cfg\"\n", srb2home)); + else + COM_ImmedExecute(va("exec \"%s"PATHSEP"autoexec.cfg\" -noerror\n", srb2home)); + + if (!autostart) + M_PushSpecialParameters(); // push all "+" parameters at the command buffer + + // demo doesn't need anymore to be added with D_AddFile() + p = M_CheckParm("-playdemo"); + if (!p) + p = M_CheckParm("-timedemo"); + if (p && M_IsNextParm()) + { + char tmp[MAX_WADPATH]; + // add .lmp to identify the EXTERNAL demo file + // it is NOT possible to play an internal demo using -playdemo, + // rather push a playdemo command.. to do. + + strcpy(tmp, M_GetNextParm()); + // get spaced filename or directory + while (M_IsNextParm()) + { + strcat(tmp, " "); + strcat(tmp, M_GetNextParm()); + } + + FIL_DefaultExtension(tmp, ".lmp"); + + CONS_Printf(M_GetText("Playing demo %s.\n"), tmp); + + if (M_CheckParm("-playdemo")) + { + singledemo = true; // quit after one demo + G_DeferedPlayDemo(tmp); + } + else + G_TimeDemo(tmp); + + G_SetGamestate(GS_NULL); + wipegamestate = GS_NULL; + return; + } + + if (M_CheckParm("-ultimatemode")) + { + autostart = true; + ultimatemode = true; + } + + if (autostart || netgame || M_CheckParm("+connect") || M_CheckParm("-connect")) + { + gameaction = ga_nothing; + + CV_ClearChangedFlags(); + + // Do this here so if you run SRB2 with eg +timelimit 5, the time limit counts + // as having been modified for the first game. + M_PushSpecialParameters(); // push all "+" parameter at the command buffer + + if (M_CheckParm("-gametype") && M_IsNextParm()) + { + // from Command_Map_f + INT32 j; + INT16 newgametype = -1; + const char *sgametype = M_GetNextParm(); + + for (j = 0; gametype_cons_t[j].strvalue; j++) + if (!strcasecmp(gametype_cons_t[j].strvalue, sgametype)) + { + newgametype = (INT16)gametype_cons_t[j].value; + break; + } + if (!gametype_cons_t[j].strvalue) // reached end of the list with no match + { + j = atoi(sgametype); // assume they gave us a gametype number, which is okay too + if (j >= 0 && j < NUMGAMETYPES) + newgametype = (INT16)j; + } + + if (newgametype != -1) + { + j = gametype; + gametype = newgametype; + D_GameTypeChanged(j); + } + } + + if (server && !M_CheckParm("+map") && !M_CheckParm("+connect") + && !M_CheckParm("-connect")) + { + // Prevent warping to nonexistent levels + if (W_CheckNumForName(G_BuildMapName(pstartmap)) == LUMPERROR) + I_Error("Could not warp to %s (map not found)\n", G_BuildMapName(pstartmap)); + // Prevent warping to locked levels + // ... unless you're in a dedicated server. Yes, technically this means you can view any level by + // running a dedicated server and joining it yourself, but that's better than making dedicated server's + // lives hell. + else if (!dedicated && M_MapLocked(pstartmap)) + I_Error("You need to unlock this level before you can warp to it!\n"); + else + D_MapChange(pstartmap, gametype, ultimatemode, true, 0, false, false); + } + } + else if (M_CheckParm("-skipintro")) + { + CON_ToggleOff(); + CON_ClearHUD(); + F_StartTitleScreen(); + } + else + F_StartIntro(); // Tails 03-03-2002 + + if (dedicated && server) + { + pagename = "TITLESKY"; + levelstarttic = gametic; + G_SetGamestate(GS_LEVEL); + if (!P_SetupLevel(false)) + I_Quit(); // fail so reset game stuff + } +} + +const char *D_Home(void) +{ + const char *userhome = NULL; + +#ifdef ANDROID + return "/data/data/org.srb2/"; +#endif +#ifdef _arch_dreamcast + char VMUHOME[] = "HOME=/vmu/a1"; + putenv(VMUHOME); //don't use I_PutEnv +#endif + + if (M_CheckParm("-home") && M_IsNextParm()) + userhome = M_GetNextParm(); + else + { +#if defined (GP2X) + usehome = false; //let use the CWD + return NULL; +#elif !((defined (__unix__) && !defined (MSDOS)) || defined(__APPLE__) || defined (UNIXCOMMON)) && !defined (__APPLE__) && !defined(_WIN32_WCE) + if (FIL_FileOK(CONFIGFILENAME)) + usehome = false; // Let's NOT use home + else +#endif + userhome = I_GetEnv("HOME"); //Alam: my new HOME for srb2 + } +#if defined (_WIN32) && !defined(_WIN32_WCE) //Alam: only Win32 have APPDATA and USERPROFILE + if (!userhome && usehome) //Alam: Still not? + { + char *testhome = NULL; + testhome = I_GetEnv("APPDATA"); + if (testhome != NULL + && (FIL_FileOK(va("%s" PATHSEP "%s" PATHSEP CONFIGFILENAME, testhome, DEFAULTDIR)))) + { + userhome = testhome; + } + } +#ifndef __CYGWIN__ + if (!userhome && usehome) //Alam: All else fails? + { + char *testhome = NULL; + testhome = I_GetEnv("USERPROFILE"); + if (testhome != NULL + && (FIL_FileOK(va("%s" PATHSEP "%s" PATHSEP CONFIGFILENAME, testhome, DEFAULTDIR)))) + { + userhome = testhome; + } + } +#endif// !__CYGWIN__ +#endif// _WIN32 + if (usehome) return userhome; + else return NULL; +} diff --git a/src/d_main.h b/src/d_main.h new file mode 100644 index 000000000..800b61f53 --- /dev/null +++ b/src/d_main.h @@ -0,0 +1,61 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 1993-1996 by id Software, Inc. +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Copyright (C) 1999-2014 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file d_main.h +/// \brief game startup, and main loop code, system specific interface stuff. + +#ifndef __D_MAIN__ +#define __D_MAIN__ + +#include "d_event.h" +#include "w_wad.h" // for MAX_WADFILES + +extern boolean supdate; +extern boolean advancedemo; + +// make sure not to write back the config until it's been correctly loaded +extern tic_t rendergametic; + +extern char srb2home[256]; //Alam: My Home +extern boolean usehome; //Alam: which path? +extern const char *pandf; //Alam: how to path? +extern char srb2path[256]; //Alam: SRB2's Home + +// the infinite loop of D_SRB2Loop() called from win_main for windows version +void D_SRB2Loop(void) FUNCNORETURN; + +// +// D_SRB2Main() +// Not a globally visible function, just included for source reference, +// calls all startup code, parses command line options. +// If not overrided by user input, calls N_AdvanceDemo. +// +void D_SRB2Main(void); + +// Called by IO functions when input is detected. +void D_PostEvent(const event_t *ev); +#ifndef DOXYGEN +void D_PostEvent_end(void); // delimiter for locking memory +#endif + +void D_ProcessEvents(void); + +const char *D_Home(void); + +// +// BASE LEVEL +// +void D_PageTicker(void); +// pagename is lumpname of a 320x200 patch to fill the screen +void D_PageDrawer(const char *pagename); +void D_AdvanceDemo(void); +void D_StartTitle(void); + +#endif //__D_MAIN__ diff --git a/src/d_net.c b/src/d_net.c new file mode 100644 index 000000000..f2f8f958d --- /dev/null +++ b/src/d_net.c @@ -0,0 +1,1249 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 1993-1996 by id Software, Inc. +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Copyright (C) 1999-2014 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file d_net.c +/// \brief SRB2 network game communication and protocol, all OS independent parts. +// +/// Implement a Sliding window protocol without receiver window +/// (out of order reception) +/// This protocol uses a mix of "goback n" and "selective repeat" implementation +/// The NOTHING packet is sent when connection is idle to acknowledge packets + +#include "doomdef.h" +#include "g_game.h" +#include "i_net.h" +#include "i_system.h" +#include "m_argv.h" +#include "d_net.h" +#include "w_wad.h" +#include "d_netfil.h" +#include "d_clisrv.h" +#include "z_zone.h" +#include "i_tcp.h" + +// +// NETWORKING +// +// gametic is the tic about to be (or currently being) run +// server: +// maketic is the tic that hasn't had control made for it yet +// nettics: is the tic for each node +// firsttictosend: is the lowest value of nettics +// client: +// neededtic: is the tic needed by the client to run the game +// firsttictosend: is used to optimize a condition +// normally maketic >= gametic > 0 + +#define FORCECLOSE 0x8000 +tic_t connectiontimeout = (15*TICRATE); + +/// \brief network packet +doomcom_t *doomcom = NULL; +/// \brief network packet data, points inside doomcom +doomdata_t *netbuffer = NULL; + +FILE *debugfile = NULL; // put some net info in a file during the game + +#define MAXREBOUND 8 +static doomdata_t reboundstore[MAXREBOUND]; +static INT16 reboundsize[MAXREBOUND]; +static INT32 rebound_head, rebound_tail; + +/// \brief bandwith of netgame +INT32 net_bandwidth; + +/// \brief max length per packet +INT16 hardware_MAXPACKETLENGTH; + +void (*I_NetGet)(void) = NULL; +void (*I_NetSend)(void) = NULL; +boolean (*I_NetCanSend)(void) = NULL; +boolean (*I_NetCanGet)(void) = NULL; +void (*I_NetCloseSocket)(void) = NULL; +void (*I_NetFreeNodenum)(INT32 nodenum) = NULL; +SINT8 (*I_NetMakeNodewPort)(const char *address, const char* port) = NULL; +boolean (*I_NetOpenSocket)(void) = NULL; +boolean (*I_Ban) (INT32 node) = NULL; +boolean (*I_Shun) (INT32 node) = NULL; +void (*I_ClearBans)(void) = NULL; +const char *(*I_GetNodeAddress) (INT32 node) = NULL; +const char *(*I_GetBanAddress) (size_t ban) = NULL; +const char *(*I_GetBanMask) (size_t ban) = NULL; +boolean (*I_SetBanAddress) (const char *address, const char *mask) = NULL; +boolean *bannednode = NULL; + + +// network stats +static tic_t statstarttic; +INT32 getbytes = 0; +INT64 sendbytes = 0; +static INT32 retransmit = 0, duppacket = 0; +static INT32 sendackpacket = 0, getackpacket = 0; +INT32 ticruned = 0, ticmiss = 0; + +// globals +INT32 getbps, sendbps; +float lostpercent, duppercent, gamelostpercent; +INT32 packetheaderlength; + +boolean Net_GetNetStat(void) +{ + const tic_t t = I_GetTime(); + static INT64 oldsendbyte = 0; + if (statstarttic+STATLENGTH <= t) + { + const tic_t df = t-statstarttic; + const INT64 newsendbyte = sendbytes - oldsendbyte; + sendbps = (INT32)(newsendbyte*TICRATE)/df; + getbps = (getbytes*TICRATE)/df; + if (sendackpacket) + lostpercent = 100.0f*(float)retransmit/(float)sendackpacket; + else + lostpercent = 0.0f; + if (getackpacket) + duppercent = 100.0f*(float)duppacket/(float)getackpacket; + else + duppercent = 0.0f; + if (ticruned) + gamelostpercent = 100.0f*(float)ticmiss/(float)ticruned; + else + gamelostpercent = 0.0f; + + ticmiss = ticruned = 0; + oldsendbyte = sendbytes; + getbytes = 0; + sendackpacket = getackpacket = duppacket = retransmit = 0; + statstarttic = t; + + return 1; + } + return 0; +} + +// ----------------------------------------------------------------- +// Some structs and functions for acknowledgement of packets +// ----------------------------------------------------------------- +#define MAXACKPACKETS 64 // minimum number of nodes +#define MAXACKTOSEND 64 +#define URGENTFREESLOTENUM 6 +#define ACKTOSENDTIMEOUT (TICRATE/17) + +#ifndef NONET +typedef struct +{ + UINT8 acknum; + UINT8 nextacknum; + UINT8 destinationnode; + tic_t senttime; + UINT16 length; + UINT16 resentnum; + union { + SINT8 raw[MAXPACKETLENGTH]; + doomdata_t data; + } pak; +} ackpak_t; +#endif + +typedef enum +{ + CLOSE = 1, // flag is set when connection is closing +} node_flags_t; + +#ifndef NONET +// table of packet that was not acknowleged can be resend (the sender window) +static ackpak_t ackpak[MAXACKPACKETS]; +#endif + +typedef struct +{ + // ack return to send (like sliding window protocol) + UINT8 firstacktosend; + + // when no consecutive packets are received we keep in mind what packets + // we already received in a queue + UINT8 acktosend_head; + UINT8 acktosend_tail; + UINT8 acktosend[MAXACKTOSEND]; + + // automatically send keep alive packet when not enough trafic + tic_t lasttimeacktosend_sent; + // detect connection lost + tic_t lasttimepacketreceived; + + // flow control: do not send too many packets with ack + UINT8 remotefirstack; + UINT8 nextacknum; + + UINT8 flags; +#ifndef NEWPING + // jacobson tcp timeout evaluation algorithm (Karn variation) + fixed_t ping; + fixed_t varping; + INT32 timeout; // computed with ping and varping +#endif +} node_t; + +static node_t nodes[MAXNETNODES]; +#ifndef NEWPING +#define PINGDEFAULT ((200*TICRATE*FRACUNIT)/1000) +#define VARPINGDEFAULT ((50*TICRATE*FRACUNIT)/1000) +#define TIMEOUT(p,v) (p+4*v+FRACUNIT/2)>>FRACBITS; +#else +#define NODETIMEOUT 14 //What the above boiled down to... +#endif + +#ifndef NONET +// return <0 if a < b (mod 256) +// 0 if a = n (mod 256) +// >0 if a > b (mod 256) +// mnemonic: to use it compare to 0: cmpack(a,b)<0 is "a < b" ... +FUNCMATH static INT32 cmpack(UINT8 a, UINT8 b) +{ + register INT32 d = a - b; + + if (d >= 127 || d < -128) + return -d; + return d; +} + +// return a free acknum and copy netbuffer in the ackpak table +static boolean GetFreeAcknum(UINT8 *freeack, boolean lowtimer) +{ + node_t *node = &nodes[doomcom->remotenode]; + INT32 i, numfreeslote = 0; + + if (cmpack((UINT8)((node->remotefirstack + MAXACKTOSEND) % 256), node->nextacknum) < 0) + { + DEBFILE(va("too fast %d %d\n",node->remotefirstack,node->nextacknum)); + return false; + } + + for (i = 0; i < MAXACKPACKETS; i++) + if (!ackpak[i].acknum) + { + // for low priority packet, make sure let freeslotes so urgents packets can be sent + numfreeslote++; + if (netbuffer->packettype >= PT_CANFAIL && numfreeslote < URGENTFREESLOTENUM) + continue; + + ackpak[i].acknum = node->nextacknum; + ackpak[i].nextacknum = node->nextacknum; + node->nextacknum++; + if (!node->nextacknum) + node->nextacknum++; + ackpak[i].destinationnode = (UINT8)(node - nodes); + ackpak[i].length = doomcom->datalength; + if (lowtimer) + { + // lowtime mean can't be sent now so try it soon as possible + ackpak[i].senttime = 0; + ackpak[i].resentnum = 1; + } + else + { + ackpak[i].senttime = I_GetTime(); + ackpak[i].resentnum = 0; + } + M_Memcpy(ackpak[i].pak.raw, netbuffer, ackpak[i].length); + + *freeack = ackpak[i].acknum; + + sendackpacket++; // for stat + + return true; + } +#ifdef PARANOIA + CONS_Debug(DBG_NETPLAY, "No more free ackpacket\n"); +#endif + if (netbuffer->packettype < PT_CANFAIL) + I_Error("Connection lost\n"); + return false; +} + +// Get a ack to send in the queu of this node +static UINT8 GetAcktosend(INT32 node) +{ + nodes[node].lasttimeacktosend_sent = I_GetTime(); + return nodes[node].firstacktosend; +} + +static void Removeack(INT32 i) +{ + INT32 node = ackpak[i].destinationnode; +#ifndef NEWPING + fixed_t trueping = (I_GetTime() - ackpak[i].senttime)<>FRACBITS,(double)FIXED_TO_FLOAT(nodes[node].ping),(double)FIXED_TO_FLOAT(nodes[node].varping),nodes[node].timeout)); +#else + DEBFILE(va("Remove ack %d\n",ackpak[i].acknum)); +#endif + ackpak[i].acknum = 0; + if (nodes[node].flags & CLOSE) + Net_CloseConnection(node); +} + +// we have got a packet proceed the ack request and ack return +static boolean Processackpak(void) +{ + INT32 i; + boolean goodpacket = true; + node_t *node = &nodes[doomcom->remotenode]; + + // received an ack return, so remove the ack in the list + if (netbuffer->ackreturn && cmpack(node->remotefirstack, netbuffer->ackreturn) < 0) + { + node->remotefirstack = netbuffer->ackreturn; + // search the ackbuffer and free it + for (i = 0; i < MAXACKPACKETS; i++) + if (ackpak[i].acknum && ackpak[i].destinationnode == node - nodes + && cmpack(ackpak[i].acknum, netbuffer->ackreturn) <= 0) + { + Removeack(i); + } + } + + // received a packet with ack, queue it to send the ack back + if (netbuffer->ack) + { + UINT8 ack = netbuffer->ack; + getackpacket++; + if (cmpack(ack, node->firstacktosend) <= 0) + { + DEBFILE(va("Discard(1) ack %d (duplicated)\n", ack)); + duppacket++; + goodpacket = false; // discard packet (duplicate) + } + else + { + // check if it is not already in the queue + for (i = node->acktosend_tail; i != node->acktosend_head; i = (i+1) % MAXACKTOSEND) + if (node->acktosend[i] == ack) + { + DEBFILE(va("Discard(2) ack %d (duplicated)\n", ack)); + duppacket++; + goodpacket = false; // discard packet (duplicate) + break; + } + if (goodpacket) + { + // is a good packet so increment the acknowledge number, + // then search for a "hole" in the queue + UINT8 nextfirstack = (UINT8)(node->firstacktosend + 1); + if (!nextfirstack) + nextfirstack = 1; + + if (ack == nextfirstack) + { + UINT8 hm1; // head - 1 + boolean change = true; + + node->firstacktosend = nextfirstack++; + if (!nextfirstack) + nextfirstack = 1; + hm1 = (UINT8)((node->acktosend_head-1+MAXACKTOSEND) % MAXACKTOSEND); + while (change) + { + change = false; + for (i = node->acktosend_tail; i != node->acktosend_head; + i = (i+1) % MAXACKTOSEND) + { + if (cmpack(node->acktosend[i], nextfirstack) <= 0) + { + if (node->acktosend[i] == nextfirstack) + { + node->firstacktosend = nextfirstack++; + if (!nextfirstack) + nextfirstack = 1; + change = true; + } + if (i == node->acktosend_tail) + { + node->acktosend[node->acktosend_tail] = 0; + node->acktosend_tail = (UINT8)((i+1) % MAXACKTOSEND); + } + else if (i == hm1) + { + node->acktosend[hm1] = 0; + node->acktosend_head = hm1; + hm1 = (UINT8)((hm1-1+MAXACKTOSEND) % MAXACKTOSEND); + } + } + } + } + } + else // out of order packet + { + // don't increment firsacktosend, put it in asktosend queue + // will be incremented when the nextfirstack comes (code above) + UINT8 newhead = (UINT8)((node->acktosend_head+1) % MAXACKTOSEND); + DEBFILE(va("out of order packet (%d expected)\n", nextfirstack)); + if (newhead != node->acktosend_tail) + { + node->acktosend[node->acktosend_head] = ack; + node->acktosend_head = newhead; + } + else // buffer full discard packet, sender will resend it + { // we can admit the packet but we will not detect the duplication after :( + DEBFILE("no more freeackret\n"); + goodpacket = false; + } + } + } + } + } + return goodpacket; +} +#endif + +// send special packet with only ack on it +void Net_SendAcks(INT32 node) +{ +#ifdef NONET + (void)node; +#else + netbuffer->packettype = PT_NOTHING; + M_Memcpy(netbuffer->u.textcmd, nodes[node].acktosend, MAXACKTOSEND); + HSendPacket(node, false, 0, MAXACKTOSEND); +#endif +} + +#ifndef NONET +static void GotAcks(void) +{ + INT32 i, j; + + for (j = 0; j < MAXACKTOSEND; j++) + if (netbuffer->u.textcmd[j]) + for (i = 0; i < MAXACKPACKETS; i++) + if (ackpak[i].acknum && ackpak[i].destinationnode == doomcom->remotenode) + { + if (ackpak[i].acknum == netbuffer->u.textcmd[j]) + Removeack(i); + else + // nextacknum is first equal to acknum, then when receiving bigger ack + // there is big chance the packet is lost + // when resent, nextacknum = nodes[node].nextacknum + // will redo the same but with different value + if (cmpack(ackpak[i].nextacknum, netbuffer->u.textcmd[j]) <= 0 + && ackpak[i].senttime > 0) + { + ackpak[i].senttime--; // hurry up + } + } +} +#endif + +static inline void Net_ConnectionTimeout(INT32 node) +{ + // send a very special packet to self (hack the reboundstore queue) + // main code will handle it + reboundstore[rebound_head].packettype = PT_NODETIMEOUT; + reboundstore[rebound_head].ack = 0; + reboundstore[rebound_head].ackreturn = 0; + reboundstore[rebound_head].u.textcmd[0] = (UINT8)node; + reboundsize[rebound_head] = (INT16)(BASEPACKETSIZE + 1); + rebound_head = (rebound_head+1) % MAXREBOUND; + + // do not redo it quickly (if we do not close connection it is + // for a good reason!) + nodes[node].lasttimepacketreceived = I_GetTime(); +} + +// resend the data if needed +void Net_AckTicker(void) +{ +#ifndef NONET + INT32 i; + + for (i = 0; i < MAXACKPACKETS; i++) + { + const INT32 nodei = ackpak[i].destinationnode; + node_t *node = &nodes[nodei]; +#ifdef NEWPING + if (ackpak[i].acknum && ackpak[i].senttime + NODETIMEOUT < I_GetTime()) +#else + if (ackpak[i].acknum && ackpak[i].senttime + node->timeout < I_GetTime()) +#endif + { + if (ackpak[i].resentnum > 10 && (node->flags & CLOSE)) + { + DEBFILE(va("ack %d sent 10 times so connection is supposed lost: node %d\n", + i, nodei)); + Net_CloseConnection(nodei | FORCECLOSE); + + ackpak[i].acknum = 0; + continue; + } +#ifdef NEWPING + DEBFILE(va("Resend ack %d, %u<%d at %u\n", ackpak[i].acknum, ackpak[i].senttime, + NODETIMEOUT, I_GetTime())); +#else + DEBFILE(va("Resend ack %d, %u<%d at %u\n", ackpak[i].acknum, ackpak[i].senttime, + node->timeout, I_GetTime())); +#endif + M_Memcpy(netbuffer, ackpak[i].pak.raw, ackpak[i].length); + ackpak[i].senttime = I_GetTime(); + ackpak[i].resentnum++; + ackpak[i].nextacknum = node->nextacknum; + retransmit++; // for stat + HSendPacket((INT32)(node - nodes), false, ackpak[i].acknum, + (size_t)(ackpak[i].length - BASEPACKETSIZE)); + } + } + + for (i = 1; i < MAXNETNODES; i++) + { + // this is something like node open flag + if (nodes[i].firstacktosend) + { + // we haven't sent a packet for a long time + // acknowledge packet if needed + if (nodes[i].lasttimeacktosend_sent + ACKTOSENDTIMEOUT < I_GetTime()) + Net_SendAcks(i); + + if (!(nodes[i].flags & CLOSE) + && nodes[i].lasttimepacketreceived + connectiontimeout < I_GetTime()) + { + Net_ConnectionTimeout(i); + } + } + } +#endif +} + +// remove last packet received ack before resending the ackret +// (the higher layer doesn't have room, or something else ....) +void Net_UnAcknowledgPacket(INT32 node) +{ +#ifdef NONET + (void)node; +#else + INT32 hm1 = (nodes[node].acktosend_head-1+MAXACKTOSEND) % MAXACKTOSEND; + DEBFILE(va("UnAcknowledge node %d\n", node)); + if (!node) + return; + if (nodes[node].acktosend[hm1] == netbuffer->ack) + { + nodes[node].acktosend[hm1] = 0; + nodes[node].acktosend_head = (UINT8)hm1; + } + else if (nodes[node].firstacktosend == netbuffer->ack) + { + nodes[node].firstacktosend--; + if (!nodes[node].firstacktosend) + nodes[node].firstacktosend = UINT8_MAX; + } + else + { + while (nodes[node].firstacktosend != netbuffer->ack) + { + nodes[node].acktosend_tail = (UINT8) + ((nodes[node].acktosend_tail-1+MAXACKTOSEND) % MAXACKTOSEND); + nodes[node].acktosend[nodes[node].acktosend_tail] = nodes[node].firstacktosend; + + nodes[node].firstacktosend--; + if (!nodes[node].firstacktosend) + nodes[node].firstacktosend = UINT8_MAX; + } + nodes[node].firstacktosend++; + if (!nodes[node].firstacktosend) + nodes[node].firstacktosend = 1; + } +#endif +} + +boolean Net_AllAckReceived(void) +{ +#ifndef NONET + INT32 i; + + for (i = 0; i < MAXACKPACKETS; i++) + if (ackpak[i].acknum) + return false; +#endif + + return true; +} + +// wait for all ackreturns with timeout in seconds +void Net_WaitAllAckReceived(UINT32 timeout) +{ +#ifdef NONET + (void)timeout; +#else + tic_t tictac = I_GetTime(); + timeout = tictac + timeout*NEWTICRATE; + + HGetPacket(); + while (timeout > I_GetTime() && !Net_AllAckReceived()) + { + while (tictac == I_GetTime()) + I_Sleep(); + tictac = I_GetTime(); + HGetPacket(); + Net_AckTicker(); + } +#endif +} + +static void InitNode(INT32 node) +{ + nodes[node].acktosend_head = nodes[node].acktosend_tail = 0; +#ifndef NEWPING + nodes[node].ping = PINGDEFAULT; + nodes[node].varping = VARPINGDEFAULT; + nodes[node].timeout = TIMEOUT(nodes[node].ping,nodes[node].varping); +#endif + nodes[node].firstacktosend = 0; + nodes[node].nextacknum = 1; + nodes[node].remotefirstack = 0; + nodes[node].flags = 0; +} + +static void InitAck(void) +{ + INT32 i; + +#ifndef NONET + for (i = 0; i < MAXACKPACKETS; i++) + ackpak[i].acknum = 0; +#endif + + for (i = 0; i < MAXNETNODES; i++) + InitNode(i); +} + +void Net_AbortPacketType(UINT8 packettype) +{ +#ifdef NONET + (void)packettype; +#else + INT32 i; + for (i = 0; i < MAXACKPACKETS; i++) + if (ackpak[i].acknum && (ackpak[i].pak.data.packettype == packettype + || packettype == UINT8_MAX)) + { + ackpak[i].acknum = 0; + } +#endif +} + +// ----------------------------------------------------------------- +// end of acknowledge function +// ----------------------------------------------------------------- + +// remove a node, clear all ack from this node and reset askret +void Net_CloseConnection(INT32 node) +{ +#ifdef NONET + (void)node; +#else + INT32 i; + boolean forceclose = (node & FORCECLOSE) != 0; + node &= ~FORCECLOSE; + + if (!node) + return; + + nodes[node].flags |= CLOSE; + + // try to Send ack back (two army problem) + if (GetAcktosend(node)) + { + Net_SendAcks(node); + Net_SendAcks(node); + } + + // check if we are waiting for an ack from this node + for (i = 0; i < MAXACKPACKETS; i++) + if (ackpak[i].acknum && ackpak[i].destinationnode == node) + { + if (!forceclose) + return; // connection will be closed when ack is returned + else + ackpak[i].acknum = 0; + } + + InitNode(node); + AbortSendFiles(node); + I_NetFreeNodenum(node); +#endif +} + +#ifndef NONET +// +// Checksum +// +static UINT32 NetbufferChecksum(void) +{ + UINT32 c = 0x1234567; + const INT32 l = doomcom->datalength - 4; + const UINT8 *buf = (UINT8 *)netbuffer + 4; + INT32 i; + + for (i = 0; i < l; i++, buf++) + c += (*buf) * (i+1); + + return LONG(c); +} +#endif + +#ifdef DEBUGFILE + +static void fprintfstring(char *s, size_t len) +{ + INT32 mode = 0; + size_t i; + + for (i = 0; i < len; i++) + if (s[i] < 32) + { + if (!mode) + { + fprintf(debugfile, "[%d", (UINT8)s[i]); + mode = 1; + } + else + fprintf(debugfile, ",%d", (UINT8)s[i]); + } + else + { + if (mode) + { + fprintf(debugfile, "]"); + mode = 0; + } + fprintf(debugfile, "%c", s[i]); + } + if (mode) + fprintf(debugfile, "]"); + fprintf(debugfile, "\n"); +} + +static const char *packettypename[NUMPACKETTYPE] = +{ + "NOTHING", + "SERVERCFG", + "CLIENTCMD", + "CLIENTMIS", + "CLIENT2CMD", + "CLIENT2MIS", + "NODEKEEPALIVE", + "NODEKEEPALIVEMIS", + "SERVERTICS", + "SERVERREFUSE", + "SERVERSHUTDOWN", + "CLIENTQUIT", + + "ASKINFO", + "SERVERINFO", + "REQUESTFILE", + "ASKINFOVIAMS", + + "PLAYERCONFIGS", + "FILEFRAGMENT", + "TEXTCMD", + "TEXTCMD2", + "CLIENTJOIN", + "NODETIMEOUT", +}; + +static void DebugPrintpacket(const char *header) +{ + fprintf(debugfile, "%-12s (node %d,ack %d,ackret %d,size %d) type(%d) : %s\n", + header, doomcom->remotenode, netbuffer->ack, netbuffer->ackreturn, doomcom->datalength, + netbuffer->packettype, packettypename[netbuffer->packettype]); + + switch (netbuffer->packettype) + { + case PT_ASKINFO: + case PT_ASKINFOVIAMS: + fprintf(debugfile, " time %u\n", (tic_t)LONG(netbuffer->u.askinfo.time) ); + break; + case PT_CLIENTJOIN: + fprintf(debugfile, " number %d mode %d\n", netbuffer->u.clientcfg.localplayers, + netbuffer->u.clientcfg.mode); + break; + case PT_SERVERTICS: + fprintf(debugfile, " firsttic %u ply %d tics %d ntxtcmd %s\n ", + (UINT32)ExpandTics(netbuffer->u.serverpak.starttic), netbuffer->u.serverpak.numslots, + netbuffer->u.serverpak.numtics, + sizeu1((size_t)(&((UINT8 *)netbuffer)[doomcom->datalength] - (UINT8 *)&netbuffer->u.serverpak.cmds[netbuffer->u.serverpak.numslots*netbuffer->u.serverpak.numtics]))); + fprintfstring((char *)&netbuffer->u.serverpak.cmds[netbuffer->u.serverpak.numslots*netbuffer->u.serverpak.numtics],(size_t)( + &((UINT8 *)netbuffer)[doomcom->datalength] - (UINT8 *)&netbuffer->u.serverpak.cmds[netbuffer->u.serverpak.numslots*netbuffer->u.serverpak.numtics])); + break; + case PT_CONSISTENCY: + fprintf(debugfile, " randomseed %d playernum %d hasmo %d\n", + netbuffer->u.consistency.randomseed, netbuffer->u.consistency.playernum, netbuffer->u.consistency.hasmo); + fprintf(debugfile, " x %d y %d z %d momx %d momy %d momz %d\n", + netbuffer->u.consistency.x, netbuffer->u.consistency.y, netbuffer->u.consistency.z, + netbuffer->u.consistency.momx, netbuffer->u.consistency.momy, netbuffer->u.consistency.momz); + fprintf(debugfile, " angle %d health %d eflags %d flags %d flags2 %d\n", + netbuffer->u.consistency.angle, netbuffer->u.consistency.health, netbuffer->u.consistency.eflags, + netbuffer->u.consistency.flags, netbuffer->u.consistency.flags2); + fprintf(debugfile, " friction %d movefactor %d tics %d statenum %d\n", + netbuffer->u.consistency.friction, netbuffer->u.consistency.movefactor, + netbuffer->u.consistency.tics, (INT32)netbuffer->u.consistency.statenum); + case PT_CLIENTCMD: + case PT_CLIENT2CMD: + case PT_CLIENTMIS: + case PT_CLIENT2MIS: + case PT_NODEKEEPALIVE: + case PT_NODEKEEPALIVEMIS: + fprintf(debugfile, " tic %4u resendfrom %u\n", + (UINT32)ExpandTics(netbuffer->u.clientpak.client_tic), + (UINT32)ExpandTics (netbuffer->u.clientpak.resendfrom)); + break; + case PT_TEXTCMD: + case PT_TEXTCMD2: + fprintf(debugfile, " length %d\n ", netbuffer->u.textcmd[0]); + fprintfstring((char *)netbuffer->u.textcmd+1, netbuffer->u.textcmd[0]); + break; + case PT_SERVERCFG: + fprintf(debugfile, " playermask %x playerslots %d clientnode %d serverplayer %d " + "gametic %u gamestate %d gametype %d modifiedgame %d\n", + (UINT32)LONG(netbuffer->u.servercfg.playerdetected), + netbuffer->u.servercfg.totalslotnum, netbuffer->u.servercfg.clientnode, + netbuffer->u.servercfg.serverplayer, (UINT32)LONG(netbuffer->u.servercfg.gametic), + netbuffer->u.servercfg.gamestate, netbuffer->u.servercfg.gametype, + netbuffer->u.servercfg.modifiedgame); + break; + case PT_SERVERINFO: + fprintf(debugfile, " '%s' player %d/%d, map %s, filenum %d, time %u \n", + netbuffer->u.serverinfo.servername, netbuffer->u.serverinfo.numberofplayer, + netbuffer->u.serverinfo.maxplayer, netbuffer->u.serverinfo.mapname, + netbuffer->u.serverinfo.fileneedednum, + (UINT32)LONG(netbuffer->u.serverinfo.time)); + fprintfstring((char *)netbuffer->u.serverinfo.fileneeded, + (UINT8)((UINT8 *)netbuffer + doomcom->datalength + - (UINT8 *)netbuffer->u.serverinfo.fileneeded)); + break; + case PT_SERVERREFUSE: + fprintf(debugfile, " reason %s\n", netbuffer->u.serverrefuse.reason); + break; + case PT_FILEFRAGMENT: + fprintf(debugfile, " fileid %d datasize %d position %u\n", + netbuffer->u.filetxpak.fileid, (UINT16)SHORT(netbuffer->u.filetxpak.size), + (UINT32)LONG(netbuffer->u.filetxpak.position)); + break; + case PT_REQUESTFILE: + default: // write as a raw packet + fprintfstring((char *)netbuffer->u.textcmd, + (UINT8)((UINT8 *)netbuffer + doomcom->datalength - (UINT8 *)netbuffer->u.textcmd)); + break; + } +} +#endif + +// +// HSendPacket +// +boolean HSendPacket(INT32 node, boolean reliable, UINT8 acknum, size_t packetlength) +{ + doomcom->datalength = (INT16)(packetlength + BASEPACKETSIZE); + if (node == 0) // packet is to go back to us + { + if ((rebound_head+1) % MAXREBOUND == rebound_tail) + { +#ifdef PARANOIA + CONS_Debug(DBG_NETPLAY, "No more rebound buf\n"); +#endif + return false; + } + M_Memcpy(&reboundstore[rebound_head], netbuffer, + doomcom->datalength); + reboundsize[rebound_head] = doomcom->datalength; + rebound_head = (rebound_head+1) % MAXREBOUND; +#ifdef DEBUGFILE + if (debugfile) + { + doomcom->remotenode = (INT16)node; + DebugPrintpacket("SENDLOCAL"); + } +#endif + return true; + } + + if (!netgame) + I_Error("Tried to transmit to another node"); + +#ifdef NONET + (void)node; + (void)reliable; + (void)acknum; +#else + // do this before GetFreeAcknum because this function backup + // the current packet + doomcom->remotenode = (INT16)node; + if (doomcom->datalength <= 0) + { + DEBFILE("HSendPacket: nothing to send\n"); +#ifdef DEBUGFILE + if (debugfile) + DebugPrintpacket("TRISEND"); +#endif + return false; + } + + if (node < MAXNETNODES) // can be a broadcast + netbuffer->ackreturn = GetAcktosend(node); + else + netbuffer->ackreturn = 0; + if (reliable) + { + if (I_NetCanSend && !I_NetCanSend()) + { + if (netbuffer->packettype < PT_CANFAIL) + GetFreeAcknum(&netbuffer->ack, true); + + DEBFILE("HSendPacket: Out of bandwidth\n"); + return false; + } + else if (!GetFreeAcknum(&netbuffer->ack, false)) + return false; + } + else + netbuffer->ack = acknum; + + netbuffer->checksum = NetbufferChecksum(); + sendbytes += packetheaderlength + doomcom->datalength; // for stat + + // simulate internet :) + if (true || rand()<(INT32)RAND_MAX/5) + { +#ifdef DEBUGFILE + if (debugfile) + DebugPrintpacket("SEND"); +#endif + I_NetSend(); + } +#ifdef DEBUGFILE + else if (debugfile) + DebugPrintpacket("NOTSEND"); +#endif + +#endif // ndef NONET + + return true; +} + +// +// HGetPacket +// Returns false if no packet is waiting +// Check Datalength and checksum +// +boolean HGetPacket(void) +{ + // get a packet from self + if (rebound_tail != rebound_head) + { + M_Memcpy(netbuffer, &reboundstore[rebound_tail], reboundsize[rebound_tail]); + doomcom->datalength = reboundsize[rebound_tail]; + if (netbuffer->packettype == PT_NODETIMEOUT) + doomcom->remotenode = netbuffer->u.textcmd[0]; + else + doomcom->remotenode = 0; + + rebound_tail = (rebound_tail+1) % MAXREBOUND; +#ifdef DEBUGFILE + if (debugfile) + DebugPrintpacket("GETLOCAL"); +#endif + return true; + } + + if (!netgame) + return false; + +#ifndef NONET + + while(true) + { + I_NetGet(); + + if (doomcom->remotenode == -1) + return false; + + getbytes += packetheaderlength + doomcom->datalength; // for stat + + if (doomcom->remotenode >= MAXNETNODES) + { + DEBFILE(va("receive packet from node %d !\n", doomcom->remotenode)); + continue; + } + + nodes[doomcom->remotenode].lasttimepacketreceived = I_GetTime(); + + if (netbuffer->checksum != NetbufferChecksum()) + { + DEBFILE("Bad packet checksum\n"); + if (I_Shun) + I_Shun(doomcom->remotenode); // No more garbage from you! + Net_CloseConnection(doomcom->remotenode); + continue; + } + +#ifdef DEBUGFILE + if (debugfile) + DebugPrintpacket("GET"); +#endif + + // proceed the ack and ackreturn field + if (!Processackpak()) + continue; // discarded (duplicated) + + // a packet with just ackreturn + if (netbuffer->packettype == PT_NOTHING) + { + GotAcks(); + continue; + } + break; + } +#endif // ndef NONET + + return true; +} + +static void Internal_Get(void) +{ + doomcom->remotenode = -1; +} + +FUNCNORETURN static ATTRNORETURN void Internal_Send(void) +{ + I_Error("Send without netgame\n"); +} + +static void Internal_FreeNodenum(INT32 nodenum) +{ + (void)nodenum; +} + +SINT8 I_NetMakeNode(const char *hostname) +{ + SINT8 newnode = -1; + if (I_NetMakeNodewPort) + { + char *localhostname = strdup(hostname); + char *t = localhostname; + const char *port; + if (!localhostname) + return newnode; + // retrieve portnum from address! + strtok(localhostname, ":"); + port = strtok(NULL, ":"); + + // remove the port in the hostname as we've it already + while ((*t != ':') && (*t != '\0')) + t++; + *t = '\0'; + + newnode = I_NetMakeNodewPort(localhostname, port); + free(localhostname); + } + return newnode; +} + +void D_SetDoomcom(void) +{ + if (doomcom) return; + doomcom = Z_Calloc(sizeof (doomcom_t), PU_STATIC, NULL); + doomcom->id = DOOMCOM_ID; + doomcom->numslots = doomcom->numnodes = 1; + doomcom->gametype = 0; + doomcom->consoleplayer = 0; + doomcom->extratics = 0; +} + +// +// D_CheckNetGame +// Works out player numbers among the net participants +// +boolean D_CheckNetGame(void) +{ + boolean ret = false; + + InitAck(); + rebound_tail = rebound_head = 0; + + statstarttic = I_GetTime(); + + I_NetGet = Internal_Get; + I_NetSend = Internal_Send; + I_NetCanSend = NULL; + I_NetCloseSocket = NULL; + I_NetFreeNodenum = Internal_FreeNodenum; + I_NetMakeNodewPort = NULL; + + hardware_MAXPACKETLENGTH = MAXPACKETLENGTH; + net_bandwidth = 30000; + // I_InitNetwork sets doomcom and netgame + // check and initialize the network driver + multiplayer = false; + + // only dos version with external driver will return true + netgame = I_InitNetwork(); + if (!netgame && !I_NetOpenSocket) + { + D_SetDoomcom(); + netgame = I_InitTcpNetwork(); + } + + if (netgame) + ret = true; + if (!server && netgame) + netgame = false; + server = true; // WTF? server always true??? + // no! The deault mode is server. Client is set elsewhere + // when the client executes connect command. + doomcom->ticdup = 1; + + if (M_CheckParm("-extratic")) + { + if (M_IsNextParm()) + doomcom->extratics = (INT16)atoi(M_GetNextParm()); + else + doomcom->extratics = 1; + CONS_Printf(M_GetText("Set extratics to %d\n"), doomcom->extratics); + } + + if (M_CheckParm("-bandwidth")) + { + if (M_IsNextParm()) + { + net_bandwidth = atoi(M_GetNextParm()); + if (net_bandwidth < 1000) + net_bandwidth = 1000; + if (net_bandwidth > 100000) + hardware_MAXPACKETLENGTH = MAXPACKETLENGTH; + CONS_Printf(M_GetText("Network bandwidth set to %d\n"), net_bandwidth); + } + else + I_Error("usage: -bandwidth "); + } + + software_MAXPACKETLENGTH = hardware_MAXPACKETLENGTH; + if (M_CheckParm("-packetsize")) + { + if (M_IsNextParm()) + { + INT32 p = atoi(M_GetNextParm()); + if (p < 75) + p = 75; + if (p > hardware_MAXPACKETLENGTH) + p = hardware_MAXPACKETLENGTH; + software_MAXPACKETLENGTH = (UINT16)p; + } + else + I_Error("usage: -packetsize "); + } + + if (netgame) + multiplayer = true; + + if (doomcom->id != DOOMCOM_ID) + I_Error("Doomcom buffer invalid!"); + if (doomcom->numnodes > MAXNETNODES) + I_Error("Too many nodes (%d), max:%d", doomcom->numnodes, MAXNETNODES); + + netbuffer = (doomdata_t *)(void *)&doomcom->data; + +#ifdef DEBUGFILE +#ifdef _arch_dreamcast + //debugfile = stderr; + if (debugfile) + CONS_Printf(M_GetText("debug output to: %s\n"), "STDERR"); +#else + if (M_CheckParm("-debugfile")) + { + char filename[20]; + INT32 k = doomcom->consoleplayer - 1; + if (M_IsNextParm()) + k = atoi(M_GetNextParm()) - 1; + while (!debugfile && k < MAXPLAYERS) + { + k++; + sprintf(filename, "debug%d.txt", k); + debugfile = fopen(filename, "w"); + } + if (debugfile) + CONS_Printf(M_GetText("debug output to: %s\n"), filename); + else + CONS_Alert(CONS_WARNING, M_GetText("cannot debug output to file %s!\n"), filename); + } +#endif +#endif + + D_ClientServerInit(); + + return ret; +} + +void Command_Ping_f(void) +{ +#ifndef NEWPING + if(server) + { +#endif + INT32 i; + for (i = 0; i < MAXPLAYERS;i++) + { +#ifndef NEWPING + const INT32 node = playernode[i]; + if (playeringame[i] && node != 0) + CONS_Printf(M_GetText("%.2d : %s\n %d tics, %d ms.\n"), i, player_names[i], + GetLag(node), G_TicsToMilliseconds(GetLag(node))); +#else + if (playeringame[i] && i != 0) + CONS_Printf(M_GetText("%.2d : %s\n %d ms\n"), i, player_names[i], playerpingtable[i]); +#endif + } +#ifndef NEWPING + } + else + CONS_Printf(M_GetText("Only the server can use this.\n")); +#endif +} + +void D_CloseConnection(void) +{ + INT32 i; + + if (netgame) + { + // wait the ackreturn with timout of 5 Sec + Net_WaitAllAckReceived(5); + + // close all connection + for (i = 0; i < MAXNETNODES; i++) + Net_CloseConnection(i|FORCECLOSE); + + InitAck(); + + if (I_NetCloseSocket) + I_NetCloseSocket(); + + I_NetGet = Internal_Get; + I_NetSend = Internal_Send; + I_NetCanSend = NULL; + I_NetCloseSocket = NULL; + I_NetFreeNodenum = Internal_FreeNodenum; + I_NetMakeNodewPort = NULL; + netgame = false; + addedtogame = false; + } +} diff --git a/src/d_net.h b/src/d_net.h new file mode 100644 index 000000000..72de080d4 --- /dev/null +++ b/src/d_net.h @@ -0,0 +1,60 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 1993-1996 by id Software, Inc. +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Copyright (C) 1999-2014 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file d_net.h +/// \brief part of layer 4 (transport) (tp4) of the osi model +/// assure the reception of packet and proceed a checksums +/// +/// There is a data struct that stores network communication related +/// stuff, and one that defines the actual packets to be transmitted + +#ifndef __D_NET__ +#define __D_NET__ + +// Max computers in a game. +#define MAXNETNODES 32 +#define BROADCASTADDR MAXNETNODES +#define MAXSPLITSCREENPLAYERS 2 // max number of players on a single computer + +#define STATLENGTH (TICRATE*2) + +// stat of net +extern INT32 ticruned, ticmiss; +extern INT32 getbps, sendbps; +extern float lostpercent, duppercent, gamelostpercent; +extern INT32 packetheaderlength; +boolean Net_GetNetStat(void); +extern INT32 getbytes; +extern INT64 sendbytes; // realtime updated + +extern SINT8 nodetoplayer[MAXNETNODES]; +extern SINT8 nodetoplayer2[MAXNETNODES]; // say the numplayer for this node if any (splitscreen) +extern UINT8 playerpernode[MAXNETNODES]; // used specialy for scplitscreen +extern boolean nodeingame[MAXNETNODES]; // set false as nodes leave game + +void Net_AckTicker(void); +boolean Net_AllAckReceived(void); + +// if reliable return true if packet sent, 0 else +boolean HSendPacket(INT32 node, boolean reliable, UINT8 acknum, + size_t packetlength); +boolean HGetPacket(void); +void D_SetDoomcom(void); +#ifndef NONET +void D_SaveBan(void); +#endif +boolean D_CheckNetGame(void); +void D_CloseConnection(void); +void Net_UnAcknowledgPacket(INT32 node); +void Net_CloseConnection(INT32 node); +void Net_AbortPacketType(UINT8 packettype); +void Net_SendAcks(INT32 node); +void Net_WaitAllAckReceived(UINT32 timeout); +#endif diff --git a/src/d_netcmd.c b/src/d_netcmd.c new file mode 100644 index 000000000..091c35ad0 --- /dev/null +++ b/src/d_netcmd.c @@ -0,0 +1,4361 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Copyright (C) 1999-2014 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file d_netcmd.c +/// \brief host/client network commands +/// commands are executed through the command buffer +/// like console commands, other miscellaneous commands (at the end) + +#include "doomdef.h" + +#include "console.h" +#include "command.h" +#include "i_system.h" +#include "g_game.h" +#include "hu_stuff.h" +#include "g_input.h" +#include "m_menu.h" +#include "r_local.h" +#include "r_things.h" +#include "p_local.h" +#include "p_setup.h" +#include "s_sound.h" +#include "m_misc.h" +#include "am_map.h" +#include "byteptr.h" +#include "d_netfil.h" +#include "p_spec.h" +#include "m_cheat.h" +#include "d_clisrv.h" +#include "v_video.h" +#include "d_main.h" +#include "m_random.h" +#include "f_finale.h" +#include "mserv.h" +#include "md5.h" +#include "z_zone.h" +#include "lua_script.h" +#include "lua_hook.h" +#include "m_cond.h" +#include "m_anigif.h" + +#ifdef NETGAME_DEVMODE +#define CV_RESTRICT CV_NETVAR +#else +#define CV_RESTRICT 0 +#endif + +// ------ +// protos +// ------ + +static void Got_NameAndColor(UINT8 **cp, INT32 playernum); +static void Got_WeaponPref(UINT8 **cp, INT32 playernum); +static void Got_Mapcmd(UINT8 **cp, INT32 playernum); +static void Got_ExitLevelcmd(UINT8 **cp, INT32 playernum); +static void Got_RequestAddfilecmd(UINT8 **cp, INT32 playernum); +#ifdef DELFILE +static void Got_Delfilecmd(UINT8 **cp, INT32 playernum); +#endif +static void Got_Addfilecmd(UINT8 **cp, INT32 playernum); +static void Got_Pause(UINT8 **cp, INT32 playernum); +static void Got_Suicide(UINT8 **cp, INT32 playernum); +static void Got_RandomSeed(UINT8 **cp, INT32 playernum); +static void Got_RunSOCcmd(UINT8 **cp, INT32 playernum); +static void Got_Teamchange(UINT8 **cp, INT32 playernum); +static void Got_Clearscores(UINT8 **cp, INT32 playernum); + +static void PointLimit_OnChange(void); +static void TimeLimit_OnChange(void); +static void NumLaps_OnChange(void); +static void Mute_OnChange(void); + +static void Hidetime_OnChange(void); + +static void AutoBalance_OnChange(void); +static void TeamScramble_OnChange(void); + +static void NetTimeout_OnChange(void); + +static void Ringslinger_OnChange(void); +static void Gravity_OnChange(void); +static void ForceSkin_OnChange(void); + +static void Name_OnChange(void); +static void Name2_OnChange(void); +static void Skin_OnChange(void); +static void Skin2_OnChange(void); +static void Color_OnChange(void); +static void Color2_OnChange(void); +static void DummyConsvar_OnChange(void); +static void SoundTest_OnChange(void); + +#ifdef NETGAME_DEVMODE +static void Fishcake_OnChange(void); +#endif + +static void Command_Playdemo_f(void); +static void Command_Timedemo_f(void); +static void Command_Stopdemo_f(void); +static void Command_StartMovie_f(void); +static void Command_StopMovie_f(void); +static void Command_Map_f(void); +static void Command_Teleport_f(void); +static void Command_RTeleport_f(void); +static void Command_ResetCamera_f(void); + +static void Command_Addfile(void); +static void Command_ListWADS_f(void); +#ifdef DELFILE +static void Command_Delfile(void); +#endif +static void Command_RunSOC(void); +static void Command_Pause(void); +static void Command_Suicide(void); + +static void Command_Version_f(void); +#ifdef UPDATE_ALERT +static void Command_ModDetails_f(void); +#endif +static void Command_ShowGametype_f(void); +static void Command_JumpToAxis_f(void); +FUNCNORETURN static ATTRNORETURN void Command_Quit_f(void); +static void Command_Playintro_f(void); + +static void Command_Displayplayer_f(void); +static void Command_Tunes_f(void); +static void Command_Skynum_f(void); + +static void Command_ExitLevel_f(void); +static void Command_Showmap_f(void); + +static void Command_Teamchange_f(void); +static void Command_Teamchange2_f(void); +static void Command_ServerTeamChange_f(void); + +static void Command_Clearscores_f(void); + +// Remote Administration +static void Command_Changepassword_f(void); +static void Command_Login_f(void); +static void Got_Login(UINT8 **cp, INT32 playernum); +static void Got_Verification(UINT8 **cp, INT32 playernum); +static void Command_Verify_f(void); +static void Command_MotD_f(void); +static void Got_MotD_f(UINT8 **cp, INT32 playernum); + +static void Command_ShowScores_f(void); +static void Command_ShowTime_f(void); + +static void Command_Isgamemodified_f(void); +static void Command_Cheats_f(void); +#ifdef _DEBUG +static void Command_Togglemodified_f(void); +#ifdef HAVE_BLUA +static void Command_Archivetest_f(void); +#endif +#endif + +// ========================================================================= +// CLIENT VARIABLES +// ========================================================================= + +void SendWeaponPref(void); + +static CV_PossibleValue_t usemouse_cons_t[] = {{0, "Off"}, {1, "On"}, {2, "Force"}, {0, NULL}}; +#if (defined (__unix__) && !defined (MSDOS)) || defined(__APPLE__) || defined (UNIXCOMMON) +static CV_PossibleValue_t mouse2port_cons_t[] = {{0, "/dev/gpmdata"}, {1, "/dev/ttyS0"}, + {2, "/dev/ttyS1"}, {3, "/dev/ttyS2"}, {4, "/dev/ttyS3"}, {0, NULL}}; +#else +static CV_PossibleValue_t mouse2port_cons_t[] = {{1, "COM1"}, {2, "COM2"}, {3, "COM3"}, {4, "COM4"}, + {0, NULL}}; +#endif + +#ifdef LJOYSTICK +static CV_PossibleValue_t joyport_cons_t[] = {{1, "/dev/js0"}, {2, "/dev/js1"}, {3, "/dev/js2"}, + {4, "/dev/js3"}, {0, NULL}}; +#else +// accept whatever value - it is in fact the joystick device number +#define usejoystick_cons_t NULL +#endif + +static CV_PossibleValue_t autobalance_cons_t[] = {{0, "MIN"}, {4, "MAX"}, {0, NULL}}; +static CV_PossibleValue_t teamscramble_cons_t[] = {{0, "Off"}, {1, "Random"}, {2, "Points"}, {0, NULL}}; + +static CV_PossibleValue_t startingliveslimit_cons_t[] = {{1, "MIN"}, {99, "MAX"}, {0, NULL}}; +static CV_PossibleValue_t sleeping_cons_t[] = {{-1, "MIN"}, {1000/TICRATE, "MAX"}, {0, NULL}}; +static CV_PossibleValue_t competitionboxes_cons_t[] = {{0, "Normal"}, {1, "Random"}, {2, "Teleports"}, + {3, "None"}, {0, NULL}}; + +static CV_PossibleValue_t matchboxes_cons_t[] = {{0, "Normal"}, {1, "Random"}, {2, "Non-Random"}, + {3, "None"}, {0, NULL}}; + +static CV_PossibleValue_t chances_cons_t[] = {{0, "MIN"}, {9, "MAX"}, {0, NULL}}; +static CV_PossibleValue_t match_scoring_cons_t[] = {{0, "Normal"}, {1, "Classic"}, {0, NULL}}; +static CV_PossibleValue_t pause_cons_t[] = {{0, "Server"}, {1, "All"}, {0, NULL}}; + +static CV_PossibleValue_t timetic_cons_t[] = {{0, "Normal"}, {1, "Tics"}, {2, "Centiseconds"}, {0, NULL}}; + +#ifdef NETGAME_DEVMODE +static consvar_t cv_fishcake = {"fishcake", "Off", CV_CALL|CV_NOSHOWHELP|CV_RESTRICT, CV_OnOff, Fishcake_OnChange, 0, NULL, NULL, 0, 0, NULL}; +#endif +static consvar_t cv_dummyconsvar = {"dummyconsvar", "Off", CV_CALL|CV_NOSHOWHELP, CV_OnOff, + DummyConsvar_OnChange, 0, NULL, NULL, 0, 0, NULL}; + +consvar_t cv_restrictskinchange = {"restrictskinchange", "Yes", CV_NETVAR|CV_CHEAT, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_allowteamchange = {"allowteamchange", "Yes", CV_NETVAR, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; + +consvar_t cv_startinglives = {"startinglives", "3", CV_NETVAR|CV_CHEAT, startingliveslimit_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; + +static CV_PossibleValue_t respawntime_cons_t[] = {{0, "MIN"}, {30, "MAX"}, {0, NULL}}; +consvar_t cv_respawntime = {"respawndelay", "3", CV_NETVAR|CV_CHEAT, respawntime_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; + +consvar_t cv_competitionboxes = {"competitionboxes", "Random", CV_NETVAR|CV_CHEAT, competitionboxes_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; + +#ifdef SEENAMES +static CV_PossibleValue_t seenames_cons_t[] = {{0, "Off"}, {1, "Colorless"}, {2, "Team"}, {3, "Ally/Foe"}, {0, NULL}}; +consvar_t cv_seenames = {"seenames", "Ally/Foe", CV_SAVE, seenames_cons_t, 0, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_allowseenames = {"allowseenames", "Yes", CV_NETVAR, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; +#endif + +// these are just meant to be saved to the config +consvar_t cv_playername = {"name", "Sonic", CV_SAVE|CV_CALL|CV_NOINIT, NULL, Name_OnChange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_playername2 = {"name2", "Tails", CV_SAVE|CV_CALL|CV_NOINIT, NULL, Name2_OnChange, 0, NULL, NULL, 0, 0, NULL}; +// player colors +consvar_t cv_playercolor = {"color", "Blue", CV_CALL|CV_NOINIT, Color_cons_t, Color_OnChange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_playercolor2 = {"color2", "Orange", CV_CALL|CV_NOINIT, Color_cons_t, Color2_OnChange, 0, NULL, NULL, 0, 0, NULL}; +// player's skin, saved for commodity, when using a favorite skins wad.. +consvar_t cv_skin = {"skin", DEFAULTSKIN, CV_CALL|CV_NOINIT, NULL, Skin_OnChange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_skin2 = {"skin2", DEFAULTSKIN2, CV_CALL|CV_NOINIT, NULL, Skin2_OnChange, 0, NULL, NULL, 0, 0, NULL}; + +consvar_t cv_skipmapcheck = {"skipmapcheck", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + +INT32 cv_debug; + +consvar_t cv_usemouse = {"use_mouse", "On", CV_SAVE|CV_CALL,usemouse_cons_t, I_StartupMouse, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_usemouse2 = {"use_mouse2", "Off", CV_SAVE|CV_CALL,usemouse_cons_t, I_StartupMouse2, 0, NULL, NULL, 0, 0, NULL}; + +#if defined (DC) || defined (_XBOX) || defined (WMINPUT) || defined (_WII) //joystick 1 and 2 +consvar_t cv_usejoystick = {"use_joystick", "1", CV_SAVE|CV_CALL, usejoystick_cons_t, + I_InitJoystick, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_usejoystick2 = {"use_joystick2", "2", CV_SAVE|CV_CALL, usejoystick_cons_t, + I_InitJoystick2, 0, NULL, NULL, 0, 0, NULL}; +#elif defined (PSP) || defined (GP2X) || defined (_NDS) //only one joystick +consvar_t cv_usejoystick = {"use_joystick", "1", CV_SAVE|CV_CALL, usejoystick_cons_t, + I_InitJoystick, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_usejoystick2 = {"use_joystick2", "0", CV_SAVE|CV_CALL, usejoystick_cons_t, + I_InitJoystick2, 0, NULL, NULL, 0, 0, NULL}; +#else //all esle, no joystick +consvar_t cv_usejoystick = {"use_joystick", "0", CV_SAVE|CV_CALL, usejoystick_cons_t, + I_InitJoystick, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_usejoystick2 = {"use_joystick2", "0", CV_SAVE|CV_CALL, usejoystick_cons_t, + I_InitJoystick2, 0, NULL, NULL, 0, 0, NULL}; +#endif +#if (defined (LJOYSTICK) || defined (SDL)) +#ifdef LJOYSTICK +consvar_t cv_joyport = {"joyport", "/dev/js0", CV_SAVE, joyport_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_joyport2 = {"joyport2", "/dev/js0", CV_SAVE, joyport_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; //Alam: for later +#endif +consvar_t cv_joyscale = {"joyscale", "1", CV_SAVE|CV_CALL, NULL, I_JoyScale, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_joyscale2 = {"joyscale2", "1", CV_SAVE|CV_CALL, NULL, I_JoyScale2, 0, NULL, NULL, 0, 0, NULL}; +#else +consvar_t cv_joyscale = {"joyscale", "1", CV_SAVE|CV_HIDEN, NULL, NULL, 0, NULL, NULL, 0, 0, NULL}; //Alam: Dummy for save +consvar_t cv_joyscale2 = {"joyscale2", "1", CV_SAVE|CV_HIDEN, NULL, NULL, 0, NULL, NULL, 0, 0, NULL}; //Alam: Dummy for save +#endif +#if (defined (__unix__) && !defined (MSDOS)) || defined(__APPLE__) || defined (UNIXCOMMON) +consvar_t cv_mouse2port = {"mouse2port", "/dev/gpmdata", CV_SAVE, mouse2port_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_mouse2opt = {"mouse2opt", "0", CV_SAVE, NULL, NULL, 0, NULL, NULL, 0, 0, NULL}; +#else +consvar_t cv_mouse2port = {"mouse2port", "COM2", CV_SAVE, mouse2port_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +#endif + +consvar_t cv_matchboxes = {"matchboxes", "Normal", CV_NETVAR|CV_CHEAT, matchboxes_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_specialrings = {"specialrings", "On", CV_NETVAR, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_powerstones = {"powerstones", "On", CV_NETVAR, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + +#ifdef CHAOSISNOTDEADYET +consvar_t cv_chaos_bluecrawla = {"chaos_bluecrawla", "8", CV_NETVAR, chances_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_chaos_redcrawla = {"chaos_redcrawla", "8", CV_NETVAR, chances_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_chaos_crawlacommander = {"chaos_crawlacommander", "2", CV_NETVAR, chances_cons_t, + NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_chaos_jettysynbomber = {"chaos_jettysynbomber", "5", CV_NETVAR, chances_cons_t, + NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_chaos_jettysyngunner = {"chaos_jettysyngunner", "2", CV_NETVAR, chances_cons_t, + NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_chaos_eggmobile1 = {"chaos_eggmobile1", "2", CV_NETVAR, chances_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_chaos_eggmobile2 = {"chaos_eggmobile2", "2", CV_NETVAR, chances_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_chaos_skim = {"chaos_skim", "5", CV_NETVAR, chances_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_chaos_spawnrate = {"chaos_spawnrate", "30",CV_NETVAR, CV_Unsigned, NULL, 0, NULL, NULL, 0, 0, NULL}; +#endif + +consvar_t cv_recycler = {"tv_recycler", "5", CV_NETVAR|CV_CHEAT, chances_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_teleporters = {"tv_teleporter", "5", CV_NETVAR|CV_CHEAT, chances_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_superring = {"tv_superring", "5", CV_NETVAR|CV_CHEAT, chances_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_supersneakers = {"tv_supersneaker", "5", CV_NETVAR|CV_CHEAT, chances_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_invincibility = {"tv_invincibility", "5", CV_NETVAR|CV_CHEAT, chances_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_jumpshield = {"tv_jumpshield", "5", CV_NETVAR|CV_CHEAT, chances_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_watershield = {"tv_watershield", "5", CV_NETVAR|CV_CHEAT, chances_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_ringshield = {"tv_ringshield", "5", CV_NETVAR|CV_CHEAT, chances_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_forceshield = {"tv_forceshield", "5", CV_NETVAR|CV_CHEAT, chances_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_bombshield = {"tv_bombshield", "5", CV_NETVAR|CV_CHEAT, chances_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_1up = {"tv_1up", "5", CV_NETVAR|CV_CHEAT, chances_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_eggmanbox = {"tv_eggman", "5", CV_NETVAR|CV_CHEAT, chances_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; + +consvar_t cv_ringslinger = {"ringslinger", "No", CV_NETVAR|CV_NOSHOWHELP|CV_CALL|CV_CHEAT, CV_YesNo, + Ringslinger_OnChange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_gravity = {"gravity", "0.5", CV_RESTRICT|CV_FLOAT|CV_CALL, NULL, Gravity_OnChange, 0, NULL, NULL, 0, 0, NULL}; + +consvar_t cv_soundtest = {"soundtest", "0", CV_CALL, NULL, SoundTest_OnChange, 0, NULL, NULL, 0, 0, NULL}; + +static CV_PossibleValue_t minitimelimit_cons_t[] = {{15, "MIN"}, {9999, "MAX"}, {0, NULL}}; +consvar_t cv_countdowntime = {"countdowntime", "60", CV_NETVAR|CV_CHEAT, minitimelimit_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; + +consvar_t cv_touchtag = {"touchtag", "Off", CV_NETVAR, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_hidetime = {"hidetime", "30", CV_NETVAR|CV_CALL, minitimelimit_cons_t, Hidetime_OnChange, 0, NULL, NULL, 0, 0, NULL}; + +consvar_t cv_autobalance = {"autobalance", "0", CV_NETVAR|CV_CALL, autobalance_cons_t, AutoBalance_OnChange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_teamscramble = {"teamscramble", "Off", CV_NETVAR|CV_CALL|CV_NOINIT, teamscramble_cons_t, TeamScramble_OnChange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_scrambleonchange = {"scrambleonchange", "Off", CV_NETVAR, teamscramble_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; + +consvar_t cv_friendlyfire = {"friendlyfire", "Off", CV_NETVAR, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_itemfinder = {"itemfinder", "Off", CV_CALL, CV_OnOff, ItemFinder_OnChange, 0, NULL, NULL, 0, 0, NULL}; + +// Scoring type options +consvar_t cv_match_scoring = {"matchscoring", "Normal", CV_NETVAR|CV_CHEAT, match_scoring_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_overtime = {"overtime", "Yes", CV_NETVAR, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; + +consvar_t cv_realnames = {"realnames", "Off", CV_NOSHOWHELP, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_rollingdemos = {"rollingdemos", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + +consvar_t cv_timetic = {"timerres", "Normal", 0, timetic_cons_t, NULL, CV_SAVE, NULL, NULL, 0, 0, NULL}; // use tics in display +consvar_t cv_resetmusic = {"resetmusic", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; + +static CV_PossibleValue_t pointlimit_cons_t[] = {{0, "MIN"}, {999999990, "MAX"}, {0, NULL}}; +consvar_t cv_pointlimit = {"pointlimit", "0", CV_NETVAR|CV_CALL|CV_NOINIT, pointlimit_cons_t, + PointLimit_OnChange, 0, NULL, NULL, 0, 0, NULL}; +static CV_PossibleValue_t timelimit_cons_t[] = {{0, "MIN"}, {30, "MAX"}, {0, NULL}}; +consvar_t cv_timelimit = {"timelimit", "0", CV_NETVAR|CV_CALL|CV_NOINIT, timelimit_cons_t, + TimeLimit_OnChange, 0, NULL, NULL, 0, 0, NULL}; +static CV_PossibleValue_t numlaps_cons_t[] = {{0, "MIN"}, {50, "MAX"}, {0, NULL}}; +consvar_t cv_numlaps = {"numlaps", "4", CV_NETVAR|CV_CALL|CV_NOINIT, numlaps_cons_t, + NumLaps_OnChange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_usemapnumlaps = {"usemaplaps", "Yes", CV_NETVAR, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; + +// log elemental hazards -- not a netvar, is local to current player +consvar_t cv_hazardlog = {"hazardlog", "Yes", 0, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; + +consvar_t cv_forceskin = {"forceskin", "-1", CV_NETVAR|CV_CALL, NULL, ForceSkin_OnChange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_downloading = {"downloading", "On", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_allowexitlevel = {"allowexitlevel", "No", CV_NETVAR, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; + +consvar_t cv_killingdead = {"killingdead", "Off", CV_NETVAR, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + +consvar_t cv_netstat = {"netstat", "Off", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; // show bandwidth statistics +static CV_PossibleValue_t nettimeout_cons_t[] = {{TICRATE/7, "MIN"}, {60*TICRATE, "MAX"}, {0, NULL}}; +consvar_t cv_nettimeout = {"nettimeout", "525", CV_CALL|CV_SAVE, nettimeout_cons_t, NetTimeout_OnChange, 0, NULL, NULL, 0, 0, NULL}; +#ifdef NEWPING +consvar_t cv_maxping = {"maxping", "0", CV_SAVE, CV_Unsigned, NULL, 0, NULL, NULL, 0, 0, NULL}; +#endif +// Intermission time Tails 04-19-2002 +static CV_PossibleValue_t inttime_cons_t[] = {{0, "MIN"}, {3600, "MAX"}, {0, NULL}}; +consvar_t cv_inttime = {"inttime", "20", CV_NETVAR, inttime_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; + +static CV_PossibleValue_t advancemap_cons_t[] = {{0, "Off"}, {1, "Next"}, {2, "Random"}, {0, NULL}}; +consvar_t cv_advancemap = {"advancemap", "Next", CV_NETVAR, advancemap_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +static CV_PossibleValue_t playersforexit_cons_t[] = {{0, "One"}, {1, "All"}, {0, NULL}}; +consvar_t cv_playersforexit = {"playersforexit", "One", CV_NETVAR, playersforexit_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; + +consvar_t cv_runscripts = {"runscripts", "Yes", 0, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; + +consvar_t cv_pause = {"pausepermission", "Server", CV_NETVAR, pause_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_mute = {"mute", "Off", CV_NETVAR|CV_CALL, CV_OnOff, Mute_OnChange, 0, NULL, NULL, 0, 0, NULL}; + +consvar_t cv_sleep = {"cpusleep", "-1", CV_SAVE, sleeping_cons_t, NULL, -1, NULL, NULL, 0, 0, NULL}; + +static boolean triggerforcedskin = false; +INT16 gametype = GT_COOP; +boolean splitscreen = false; +boolean circuitmap = false; +INT32 adminplayer = -1; + +// ========================================================================= +// SERVER STARTUP +// ========================================================================= + +/** Registers server commands and variables. + * Anything required by a dedicated server should probably go here. + * + * \sa D_RegisterClientCommands + */ +void D_RegisterServerCommands(void) +{ + RegisterNetXCmd(XD_NAMEANDCOLOR, Got_NameAndColor); + RegisterNetXCmd(XD_WEAPONPREF, Got_WeaponPref); + RegisterNetXCmd(XD_MAP, Got_Mapcmd); + RegisterNetXCmd(XD_EXITLEVEL, Got_ExitLevelcmd); + RegisterNetXCmd(XD_ADDFILE, Got_Addfilecmd); + RegisterNetXCmd(XD_REQADDFILE, Got_RequestAddfilecmd); +#ifdef DELFILE + RegisterNetXCmd(XD_DELFILE, Got_Delfilecmd); +#endif + RegisterNetXCmd(XD_PAUSE, Got_Pause); + RegisterNetXCmd(XD_SUICIDE, Got_Suicide); + RegisterNetXCmd(XD_RUNSOC, Got_RunSOCcmd); +#ifdef HAVE_BLUA + RegisterNetXCmd(XD_LUACMD, Got_Luacmd); +#endif + + // Remote Administration + COM_AddCommand("password", Command_Changepassword_f); + RegisterNetXCmd(XD_LOGIN, Got_Login); + COM_AddCommand("login", Command_Login_f); // useful in dedicated to kick off remote admin + COM_AddCommand("verify", Command_Verify_f); + RegisterNetXCmd(XD_VERIFIED, Got_Verification); + + COM_AddCommand("motd", Command_MotD_f); + RegisterNetXCmd(XD_SETMOTD, Got_MotD_f); // For remote admin + + RegisterNetXCmd(XD_TEAMCHANGE, Got_Teamchange); + COM_AddCommand("serverchangeteam", Command_ServerTeamChange_f); + + RegisterNetXCmd(XD_CLEARSCORES, Got_Clearscores); + COM_AddCommand("clearscores", Command_Clearscores_f); + COM_AddCommand("map", Command_Map_f); + + COM_AddCommand("exitgame", Command_ExitGame_f); + COM_AddCommand("retry", Command_Retry_f); + COM_AddCommand("exitlevel", Command_ExitLevel_f); + COM_AddCommand("showmap", Command_Showmap_f); + + COM_AddCommand("addfile", Command_Addfile); + COM_AddCommand("listwad", Command_ListWADS_f); + +#ifdef DELFILE + COM_AddCommand("delfile", Command_Delfile); +#endif + COM_AddCommand("runsoc", Command_RunSOC); + COM_AddCommand("pause", Command_Pause); + COM_AddCommand("suicide", Command_Suicide); + + COM_AddCommand("gametype", Command_ShowGametype_f); + COM_AddCommand("jumptoaxis", Command_JumpToAxis_f); + COM_AddCommand("version", Command_Version_f); +#ifdef UPDATE_ALERT + COM_AddCommand("mod_details", Command_ModDetails_f); +#endif + COM_AddCommand("quit", Command_Quit_f); + + COM_AddCommand("saveconfig", Command_SaveConfig_f); + COM_AddCommand("loadconfig", Command_LoadConfig_f); + COM_AddCommand("changeconfig", Command_ChangeConfig_f); + COM_AddCommand("isgamemodified", Command_Isgamemodified_f); // test + COM_AddCommand("showscores", Command_ShowScores_f); + COM_AddCommand("showtime", Command_ShowTime_f); + COM_AddCommand("cheats", Command_Cheats_f); // test +#ifdef _DEBUG + COM_AddCommand("togglemodified", Command_Togglemodified_f); +#ifdef HAVE_BLUA + COM_AddCommand("archivetest", Command_Archivetest_f); +#endif +#endif + + // for master server connection + AddMServCommands(); + + // p_mobj.c + CV_RegisterVar(&cv_itemrespawntime); + CV_RegisterVar(&cv_itemrespawn); + CV_RegisterVar(&cv_flagtime); + CV_RegisterVar(&cv_suddendeath); + + // misc + CV_RegisterVar(&cv_friendlyfire); + CV_RegisterVar(&cv_pointlimit); + CV_RegisterVar(&cv_numlaps); + CV_RegisterVar(&cv_usemapnumlaps); + + CV_RegisterVar(&cv_hazardlog); + + CV_RegisterVar(&cv_autobalance); + CV_RegisterVar(&cv_teamscramble); + CV_RegisterVar(&cv_scrambleonchange); + + CV_RegisterVar(&cv_touchtag); + CV_RegisterVar(&cv_hidetime); + + CV_RegisterVar(&cv_inttime); + CV_RegisterVar(&cv_advancemap); + CV_RegisterVar(&cv_playersforexit); + CV_RegisterVar(&cv_timelimit); + CV_RegisterVar(&cv_playbackspeed); + CV_RegisterVar(&cv_forceskin); + CV_RegisterVar(&cv_downloading); + + CV_RegisterVar(&cv_specialrings); + CV_RegisterVar(&cv_powerstones); + CV_RegisterVar(&cv_competitionboxes); + CV_RegisterVar(&cv_matchboxes); + +#ifdef CHAOSISNOTDEADYET + CV_RegisterVar(&cv_chaos_bluecrawla); + CV_RegisterVar(&cv_chaos_redcrawla); + CV_RegisterVar(&cv_chaos_crawlacommander); + CV_RegisterVar(&cv_chaos_jettysynbomber); + CV_RegisterVar(&cv_chaos_jettysyngunner); + CV_RegisterVar(&cv_chaos_eggmobile1); + CV_RegisterVar(&cv_chaos_eggmobile2); + CV_RegisterVar(&cv_chaos_skim); + CV_RegisterVar(&cv_chaos_spawnrate); +#endif + + CV_RegisterVar(&cv_recycler); + CV_RegisterVar(&cv_teleporters); + CV_RegisterVar(&cv_superring); + CV_RegisterVar(&cv_supersneakers); + CV_RegisterVar(&cv_invincibility); + CV_RegisterVar(&cv_jumpshield); + CV_RegisterVar(&cv_watershield); + CV_RegisterVar(&cv_ringshield); + CV_RegisterVar(&cv_forceshield); + CV_RegisterVar(&cv_bombshield); + CV_RegisterVar(&cv_1up); + CV_RegisterVar(&cv_eggmanbox); + + CV_RegisterVar(&cv_ringslinger); + + CV_RegisterVar(&cv_startinglives); + CV_RegisterVar(&cv_countdowntime); + CV_RegisterVar(&cv_runscripts); + CV_RegisterVar(&cv_match_scoring); + CV_RegisterVar(&cv_overtime); + CV_RegisterVar(&cv_pause); + CV_RegisterVar(&cv_mute); + + RegisterNetXCmd(XD_RANDOMSEED, Got_RandomSeed); + + CV_RegisterVar(&cv_allowexitlevel); + CV_RegisterVar(&cv_restrictskinchange); + CV_RegisterVar(&cv_allowteamchange); + CV_RegisterVar(&cv_respawntime); + CV_RegisterVar(&cv_killingdead); + + // d_clisrv + CV_RegisterVar(&cv_maxplayers); + CV_RegisterVar(&cv_maxsend); + + COM_AddCommand("ping", Command_Ping_f); + CV_RegisterVar(&cv_nettimeout); + + CV_RegisterVar(&cv_skipmapcheck); + CV_RegisterVar(&cv_sleep); +#ifdef NEWPING + CV_RegisterVar(&cv_maxping); +#endif + +#ifdef SEENAMES + CV_RegisterVar(&cv_allowseenames); +#endif + + CV_RegisterVar(&cv_dummyconsvar); +} + +// ========================================================================= +// CLIENT STARTUP +// ========================================================================= + +/** Registers client commands and variables. + * Nothing needed for a dedicated server should be registered here. + * + * \sa D_RegisterServerCommands + */ +void D_RegisterClientCommands(void) +{ + const char *username; + INT32 i; + + for (i = 0; i < MAXSKINCOLORS; i++) + { + Color_cons_t[i].value = i; + Color_cons_t[i].strvalue = Color_Names[i]; + } + Color_cons_t[MAXSKINCOLORS].value = 0; + Color_cons_t[MAXSKINCOLORS].strvalue = NULL; + + if (dedicated) + return; + + COM_AddCommand("numthinkers", Command_Numthinkers_f); + COM_AddCommand("countmobjs", Command_CountMobjs_f); + + COM_AddCommand("changeteam", Command_Teamchange_f); + COM_AddCommand("changeteam2", Command_Teamchange2_f); + + COM_AddCommand("playdemo", Command_Playdemo_f); + COM_AddCommand("timedemo", Command_Timedemo_f); + COM_AddCommand("stopdemo", Command_Stopdemo_f); + COM_AddCommand("playintro", Command_Playintro_f); + + COM_AddCommand("resetcamera", Command_ResetCamera_f); + + COM_AddCommand("setcontrol", Command_Setcontrol_f); + COM_AddCommand("setcontrol2", Command_Setcontrol2_f); + + COM_AddCommand("screenshot", M_ScreenShot); + COM_AddCommand("startmovie", Command_StartMovie_f); + COM_AddCommand("stopmovie", Command_StopMovie_f); + + CV_RegisterVar(&cv_screenshot_option); + CV_RegisterVar(&cv_screenshot_folder); + CV_RegisterVar(&cv_moviemode); + // PNG variables + CV_RegisterVar(&cv_zlib_level); + CV_RegisterVar(&cv_zlib_memory); + CV_RegisterVar(&cv_zlib_strategy); + CV_RegisterVar(&cv_zlib_window_bits); + // APNG variables + CV_RegisterVar(&cv_zlib_levela); + CV_RegisterVar(&cv_zlib_memorya); + CV_RegisterVar(&cv_zlib_strategya); + CV_RegisterVar(&cv_zlib_window_bitsa); + CV_RegisterVar(&cv_apng_delay); + // GIF variables + CV_RegisterVar(&cv_gif_optimize); + CV_RegisterVar(&cv_gif_downscale); + + CV_RegisterVar(&cv_splats); + + // register these so it is saved to config + if ((username = I_GetUserName())) + cv_playername.defaultvalue = username; + CV_RegisterVar(&cv_playername); + CV_RegisterVar(&cv_playercolor); + CV_RegisterVar(&cv_skin); // r_things.c (skin NAME) + // secondary player (splitscreen) + CV_RegisterVar(&cv_playername2); + CV_RegisterVar(&cv_playercolor2); + CV_RegisterVar(&cv_skin2); + +#ifdef SEENAMES + CV_RegisterVar(&cv_seenames); +#endif + CV_RegisterVar(&cv_realnames); + CV_RegisterVar(&cv_rollingdemos); + CV_RegisterVar(&cv_netstat); + +#ifdef NETGAME_DEVMODE + CV_RegisterVar(&cv_fishcake); +#endif + + // HUD + CV_RegisterVar(&cv_timetic); + CV_RegisterVar(&cv_itemfinder); + + // time attack ghost options are also saved to config + CV_RegisterVar(&cv_ghost_bestscore); + CV_RegisterVar(&cv_ghost_besttime); + CV_RegisterVar(&cv_ghost_bestrings); + CV_RegisterVar(&cv_ghost_last); + CV_RegisterVar(&cv_ghost_guest); + + COM_AddCommand("displayplayer", Command_Displayplayer_f); + COM_AddCommand("tunes", Command_Tunes_f); + CV_RegisterVar(&cv_resetmusic); + + // FIXME: not to be here.. but needs be done for config loading + CV_RegisterVar(&cv_usegamma); + + // m_menu.c + CV_RegisterVar(&cv_crosshair); + CV_RegisterVar(&cv_crosshair2); + CV_RegisterVar(&cv_alwaysfreelook); + CV_RegisterVar(&cv_alwaysfreelook2); + + // g_input.c + CV_RegisterVar(&cv_sideaxis); + CV_RegisterVar(&cv_sideaxis2); + CV_RegisterVar(&cv_turnaxis); + CV_RegisterVar(&cv_turnaxis2); + CV_RegisterVar(&cv_moveaxis); + CV_RegisterVar(&cv_moveaxis2); + CV_RegisterVar(&cv_lookaxis); + CV_RegisterVar(&cv_lookaxis2); + CV_RegisterVar(&cv_fireaxis); + CV_RegisterVar(&cv_fireaxis2); + CV_RegisterVar(&cv_firenaxis); + CV_RegisterVar(&cv_firenaxis2); + + // WARNING: the order is important when initialising mouse2 + // we need the mouse2port + CV_RegisterVar(&cv_mouse2port); +#if (defined (__unix__) && !defined (MSDOS)) || defined(__APPLE__) || defined (UNIXCOMMON) + CV_RegisterVar(&cv_mouse2opt); +#endif + CV_RegisterVar(&cv_controlperkey); + + CV_RegisterVar(&cv_usemouse); + CV_RegisterVar(&cv_usemouse2); + CV_RegisterVar(&cv_invertmouse); + CV_RegisterVar(&cv_invertmouse2); + CV_RegisterVar(&cv_mousesens); + CV_RegisterVar(&cv_mousesens2); + CV_RegisterVar(&cv_mousemove); + CV_RegisterVar(&cv_mousemove2); + + CV_RegisterVar(&cv_usejoystick); + CV_RegisterVar(&cv_usejoystick2); +#ifdef LJOYSTICK + CV_RegisterVar(&cv_joyport); + CV_RegisterVar(&cv_joyport2); +#endif + CV_RegisterVar(&cv_joyscale); + CV_RegisterVar(&cv_joyscale2); + + // Analog Control + CV_RegisterVar(&cv_analog); + CV_RegisterVar(&cv_analog2); + CV_RegisterVar(&cv_useranalog); + CV_RegisterVar(&cv_useranalog2); + + // s_sound.c + CV_RegisterVar(&cv_soundvolume); + CV_RegisterVar(&cv_digmusicvolume); + CV_RegisterVar(&cv_midimusicvolume); + CV_RegisterVar(&cv_numChannels); + + // i_cdmus.c + CV_RegisterVar(&cd_volume); + CV_RegisterVar(&cdUpdate); + + // screen.c + CV_RegisterVar(&cv_fullscreen); + CV_RegisterVar(&cv_renderview); + CV_RegisterVar(&cv_scr_depth); + CV_RegisterVar(&cv_scr_width); + CV_RegisterVar(&cv_scr_height); + + // p_fab.c + CV_RegisterVar(&cv_translucency); + + CV_RegisterVar(&cv_soundtest); + + // ingame object placing + COM_AddCommand("objectplace", Command_ObjectPlace_f); + COM_AddCommand("writethings", Command_Writethings_f); + CV_RegisterVar(&cv_speed); + CV_RegisterVar(&cv_opflags); + CV_RegisterVar(&cv_mapthingnum); +// CV_RegisterVar(&cv_grid); +// CV_RegisterVar(&cv_snapto); + + // add cheat commands + COM_AddCommand("noclip", Command_CheatNoClip_f); + COM_AddCommand("god", Command_CheatGod_f); + COM_AddCommand("notarget", Command_CheatNoTarget_f); + COM_AddCommand("getallemeralds", Command_Getallemeralds_f); + COM_AddCommand("resetemeralds", Command_Resetemeralds_f); + COM_AddCommand("setrings", Command_Setrings_f); + COM_AddCommand("setlives", Command_Setlives_f); + COM_AddCommand("setcontinues", Command_Setcontinues_f); + COM_AddCommand("devmode", Command_Devmode_f); + COM_AddCommand("savecheckpoint", Command_Savecheckpoint_f); + COM_AddCommand("scale", Command_Scale_f); + COM_AddCommand("gravflip", Command_Gravflip_f); + COM_AddCommand("hurtme", Command_Hurtme_f); + COM_AddCommand("charability", Command_Charability_f); + COM_AddCommand("charspeed", Command_Charspeed_f); + COM_AddCommand("teleport", Command_Teleport_f); + COM_AddCommand("rteleport", Command_RTeleport_f); + COM_AddCommand("skynum", Command_Skynum_f); +#ifdef _DEBUG + COM_AddCommand("causecfail", Command_CauseCfail_f); +#endif +#if defined(HAVE_BLUA) && defined(LUA_ALLOW_BYTECODE) + COM_AddCommand("dumplua", Command_Dumplua_f); +#endif +} + +/** Checks if a name (as received from another player) is okay. + * A name is okay if it is no fewer than 1 and no more than ::MAXPLAYERNAME + * chars long (not including NUL), it does not begin or end with a space, + * it does not contain non-printing characters (according to isprint(), which + * allows space), it does not start with a digit, and no other player is + * currently using it. + * \param name Name to check. + * \param playernum Player who wants the name, so we can check if they already + * have it, and let them keep it if so. + * \sa CleanupPlayerName, SetPlayerName, Got_NameAndColor + * \author Graue + */ +static boolean IsNameGood(char *name, INT32 playernum) +{ + INT32 ix; + + if (strlen(name) == 0 || strlen(name) > MAXPLAYERNAME) + return false; // Empty or too long. + if (name[0] == ' ' || name[strlen(name)-1] == ' ') + return false; // Starts or ends with a space. + if (isdigit(name[0])) + return false; // Starts with a digit. + if (name[0] == '@' || name[0] == '~') + return false; // Starts with an admin symbol. + + // Check if it contains a non-printing character. + // Note: ANSI C isprint() considers space a printing character. + // Also don't allow semicolons, since they are used as + // console command separators. + + // Also, anything over 0x80 is disallowed too, since compilers love to + // differ on whether they're printable characters or not. + for (ix = 0; name[ix] != '\0'; ix++) + if (!isprint(name[ix]) || name[ix] == ';' || (UINT8)(name[ix]) >= 0x80) + return false; + + // Check if a player is currently using the name, case-insensitively. + for (ix = 0; ix < MAXPLAYERS; ix++) + { + if (ix != playernum && playeringame[ix] + && strcasecmp(name, player_names[ix]) == 0) + { + // We shouldn't kick people out just because + // they joined the game with the same name + // as someone else -- modify the name instead. + size_t len = strlen(name); + + // Recursion! + // Slowly strip characters off the end of the + // name until we no longer have a duplicate. + if (len > 1) + { + name[len-1] = '\0'; + if (!IsNameGood (name, playernum)) + return false; + } + else if (len == 1) // Agh! + { + // Last ditch effort... + sprintf(name, "%d", M_Random() & 7); + if (!IsNameGood (name, playernum)) + return false; + } + else + return false; + } + } + + return true; +} + +/** Cleans up a local player's name before sending a name change. + * Spaces at the beginning or end of the name are removed. Then if the new + * name is identical to another player's name, ignoring case, the name change + * is canceled, and the name in cv_playername.value or cv_playername2.value + * is restored to what it was before. + * + * We assume that if playernum is ::consoleplayer or ::secondarydisplayplayer + * the console variable ::cv_playername or ::cv_playername2 respectively is + * already set to newname. However, the player name table is assumed to + * contain the old name. + * + * \param playernum Player number who has requested a name change. + * Should be ::consoleplayer or ::secondarydisplayplayer. + * \param newname New name for that player; should already be in + * ::cv_playername or ::cv_playername2 if player is the + * console or secondary display player, respectively. + * \sa cv_playername, cv_playername2, SendNameAndColor, SendNameAndColor2, + * SetPlayerName + * \author Graue + */ +static void CleanupPlayerName(INT32 playernum, const char *newname) +{ + char *buf; + char *p; + char *tmpname = NULL; + INT32 i; + boolean namefailed = true; + + buf = Z_StrDup(newname); + + do + { + p = buf; + + while (*p == ' ') + p++; // remove leading spaces + + if (strlen(p) == 0) + break; // empty names not allowed + + if (isdigit(*p)) + break; // names starting with digits not allowed + + if (*p == '@' || *p == '~') + break; // names that start with @ or ~ (admin symbols) not allowed + + tmpname = p; + + // Remove trailing spaces. + p = &tmpname[strlen(tmpname)-1]; // last character + while (*p == ' ' && p >= tmpname) + { + *p = '\0'; + p--; + } + + if (strlen(tmpname) == 0) + break; // another case of an empty name + + // Truncate name if it's too long (max MAXPLAYERNAME chars + // excluding NUL). + if (strlen(tmpname) > MAXPLAYERNAME) + tmpname[MAXPLAYERNAME] = '\0'; + + // Remove trailing spaces again. + p = &tmpname[strlen(tmpname)-1]; // last character + while (*p == ' ' && p >= tmpname) + { + *p = '\0'; + p--; + } + + // no stealing another player's name + for (i = 0; i < MAXPLAYERS; i++) + { + if (i != playernum && playeringame[i] + && strcasecmp(tmpname, player_names[i]) == 0) + { + break; + } + } + + if (i < MAXPLAYERS) + break; + + // name is okay then + namefailed = false; + } while (0); + + if (namefailed) + tmpname = player_names[playernum]; + + // set consvars whether namefailed or not, because even if it succeeded, + // spaces may have been removed + if (playernum == consoleplayer) + CV_StealthSet(&cv_playername, tmpname); + else if (playernum == secondarydisplayplayer + || (!netgame && playernum == 1)) + { + CV_StealthSet(&cv_playername2, tmpname); + } + else I_Assert(((void)"CleanupPlayerName used on non-local player", 0)); + + Z_Free(buf); +} + +/** Sets a player's name, if it is good. + * If the name is not good (indicating a modified or buggy client), it is not + * set, and if we are the server in a netgame, the player responsible is + * kicked with a consistency failure. + * + * This function prints a message indicating the name change, unless the game + * is currently showing the intro, e.g. when processing autoexec.cfg. + * + * \param playernum Player number who has requested a name change. + * \param newname New name for that player. Should be good, but won't + * necessarily be if the client is maliciously modified or + * buggy. + * \sa CleanupPlayerName, IsNameGood + * \author Graue + */ +static void SetPlayerName(INT32 playernum, char *newname) +{ + if (IsNameGood(newname, playernum)) + { + if (strcasecmp(newname, player_names[playernum]) != 0) + { + if (netgame) + CONS_Printf(M_GetText("%s renamed to %s\n"), + player_names[playernum], newname); + strcpy(player_names[playernum], newname); + } + } + else + { + CONS_Printf(M_GetText("Player %d sent a bad name change\n"), playernum+1); + if (server && netgame) + { + XBOXSTATIC UINT8 buf[2]; + + buf[0] = (UINT8)playernum; + buf[1] = KICK_MSG_CON_FAIL; + SendNetXCmd(XD_KICK, &buf, 2); + } + } +} + +UINT8 CanChangeSkin(INT32 playernum) +{ + // Of course we can change if we're not playing + if (!Playing() || !addedtogame) + return true; + + // Force skin in effect. + if (!server && (cv_forceskin.value != -1) && !(adminplayer == playernum && serverplayer == -1)) + return false; + + // Can change skin in intermission and whatnot. + if (gamestate != GS_LEVEL) + return true; + + // Server has skin change restrictions. + if (cv_restrictskinchange.value) + { + if (gametype == GT_COOP) + return true; + + // Can change skin during initial countdown. + if ((gametype == GT_RACE || gametype == GT_COMPETITION) && leveltime < 4*TICRATE) + return true; + + if (G_TagGametype()) + { + // Can change skin during hidetime. + if (leveltime < hidetime * TICRATE) + return true; + + // IT players can always change skins to persue players hiding in character only locations. + if (players[playernum].pflags & PF_TAGIT) + return true; + } + + if (players[playernum].spectator || players[playernum].playerstate == PST_DEAD || players[playernum].playerstate == PST_REBORN) + return true; + + return false; + } + + return true; +} + + +static INT32 snacpending = 0, snac2pending = 0, chmappending = 0; + +// name, color, or skin has changed +// +static void SendNameAndColor(void) +{ + XBOXSTATIC char buf[MAXPLAYERNAME+2]; + char *p; + + p = buf; + + // normal player colors + if (G_GametypeHasTeams()) + { + if (players[consoleplayer].ctfteam == 1 && cv_playercolor.value != skincolor_redteam) + CV_StealthSetValue(&cv_playercolor, skincolor_redteam); + else if (players[consoleplayer].ctfteam == 2 && cv_playercolor.value != skincolor_blueteam) + CV_StealthSetValue(&cv_playercolor, skincolor_blueteam); + } + + // never allow the color "none" + if (!cv_playercolor.value) + { + if (players[consoleplayer].skincolor) + CV_StealthSetValue(&cv_playercolor, players[consoleplayer].skincolor); + else if (skins[players[consoleplayer].skin].prefcolor) + CV_StealthSetValue(&cv_playercolor, skins[players[consoleplayer].skin].prefcolor); + else + CV_StealthSet(&cv_playercolor, cv_playercolor.defaultvalue); + } + + if (!strcmp(cv_playername.string, player_names[consoleplayer]) + && cv_playercolor.value == players[consoleplayer].skincolor + && !strcmp(cv_skin.string, skins[players[consoleplayer].skin].name)) + return; + + // If you're not in a netgame, merely update the skin, color, and name. + if (!netgame) + { + INT32 foundskin; + + CleanupPlayerName(consoleplayer, cv_playername.zstring); + strcpy(player_names[consoleplayer], cv_playername.zstring); + + players[consoleplayer].skincolor = cv_playercolor.value; + + if (players[consoleplayer].mo) + players[consoleplayer].mo->color = players[consoleplayer].skincolor; + + if (metalrecording) + { // Metal Sonic is Sonic, obviously. + SetPlayerSkinByNum(consoleplayer, 0); + CV_StealthSet(&cv_skin, skins[0].name); + } + else if (cv_forceskin.value >= 0 && (netgame || multiplayer)) // Server wants everyone to use the same player + { + const INT32 forcedskin = cv_forceskin.value; + + if (triggerforcedskin) + { + INT32 i; + + for (i = 0; i < MAXPLAYERS; i++) + { + if (playeringame[i]) + { + SetPlayerSkinByNum(i, forcedskin); + + // If it's me (or my brother), set appropriate skin value in cv_skin/cv_skin2 + if (i == consoleplayer) + CV_StealthSet(&cv_skin, skins[forcedskin].name); + else if (i == secondarydisplayplayer) + CV_StealthSet(&cv_skin2, skins[forcedskin].name); + } + } + triggerforcedskin = false; + } + else + { + SetPlayerSkinByNum(consoleplayer, forcedskin); + CV_StealthSet(&cv_skin, skins[forcedskin].name); + } + } + else if ((foundskin = R_SkinAvailable(cv_skin.string)) != -1) + { + boolean notsame; + + cv_skin.value = foundskin; + + notsame = (cv_skin.value != players[consoleplayer].skin); + + SetPlayerSkin(consoleplayer, cv_skin.string); + CV_StealthSet(&cv_skin, skins[cv_skin.value].name); + + if (notsame) + { + CV_StealthSetValue(&cv_playercolor, skins[cv_skin.value].prefcolor); + + players[consoleplayer].skincolor = (cv_playercolor.value&0x1F) % MAXSKINCOLORS; + + if (players[consoleplayer].mo) + players[consoleplayer].mo->color = (UINT8)players[consoleplayer].skincolor; + } + } + + return; + } + + snacpending++; + + // Don't change name if muted + if (cv_mute.value && !(server || adminplayer == consoleplayer)) + CV_StealthSet(&cv_playername, player_names[consoleplayer]); + else // Cleanup name if changing it + CleanupPlayerName(consoleplayer, cv_playername.zstring); + + // Don't change skin if the server doesn't want you to. + if (!CanChangeSkin(consoleplayer)) + CV_StealthSet(&cv_skin, skins[players[consoleplayer].skin].name); + + // check if player has the skin loaded (cv_skin may have + // the name of a skin that was available in the previous game) + cv_skin.value = R_SkinAvailable(cv_skin.string); + if (cv_skin.value < 0) + { + CV_StealthSet(&cv_skin, DEFAULTSKIN); + cv_skin.value = 0; + } + + // Finally write out the complete packet and send it off. + WRITESTRINGN(p, cv_playername.zstring, MAXPLAYERNAME); + WRITEUINT8(p, (UINT8)cv_playercolor.value); + WRITEUINT8(p, (UINT8)cv_skin.value); + SendNetXCmd(XD_NAMEANDCOLOR, buf, p - buf); +} + +// splitscreen +static void SendNameAndColor2(void) +{ + INT32 secondplaya; + + if (!splitscreen && !botingame) + return; // can happen if skin2/color2/name2 changed + + if (secondarydisplayplayer != consoleplayer) + secondplaya = secondarydisplayplayer; + else // HACK + secondplaya = 1; + + // normal player colors + if (G_GametypeHasTeams()) + { + if (players[secondplaya].ctfteam == 1 && cv_playercolor2.value != skincolor_redteam) + CV_StealthSetValue(&cv_playercolor2, skincolor_redteam); + else if (players[secondplaya].ctfteam == 2 && cv_playercolor2.value != skincolor_blueteam) + CV_StealthSetValue(&cv_playercolor2, skincolor_blueteam); + } + + // never allow the color "none" + if (!cv_playercolor2.value) + { + if (players[secondplaya].skincolor) + CV_StealthSetValue(&cv_playercolor2, players[secondplaya].skincolor); + else if (skins[players[secondplaya].skin].prefcolor) + CV_StealthSetValue(&cv_playercolor2, skins[players[secondplaya].skin].prefcolor); + else + CV_StealthSet(&cv_playercolor2, cv_playercolor2.defaultvalue); + } + + // If you're not in a netgame, merely update the skin, color, and name. + if (botingame) + { + players[secondplaya].skincolor = botcolor; + if (players[secondplaya].mo) + players[secondplaya].mo->color = players[secondplaya].skincolor; + SetPlayerSkinByNum(secondplaya, botskin-1); + return; + } + else if (!netgame) + { + INT32 foundskin; + + CleanupPlayerName(secondplaya, cv_playername2.zstring); + strcpy(player_names[secondplaya], cv_playername2.zstring); + + // don't use secondarydisplayplayer: the second player must be 1 + players[secondplaya].skincolor = cv_playercolor2.value; + if (players[secondplaya].mo) + players[secondplaya].mo->color = players[secondplaya].skincolor; + + if (cv_forceskin.value >= 0 && (netgame || multiplayer)) // Server wants everyone to use the same player + { + const INT32 forcedskin = cv_forceskin.value; + + SetPlayerSkinByNum(secondplaya, forcedskin); + CV_StealthSet(&cv_skin2, skins[forcedskin].name); + } + else if ((foundskin = R_SkinAvailable(cv_skin2.string)) != -1) + { + boolean notsame; + + cv_skin2.value = foundskin; + + notsame = (cv_skin2.value != players[secondplaya].skin); + + SetPlayerSkin(secondplaya, cv_skin2.string); + + if (notsame) + { + CV_StealthSetValue(&cv_playercolor2, skins[players[secondplaya].skin].prefcolor); + + players[secondplaya].skincolor = (cv_playercolor2.value&0x1F) % MAXSKINCOLORS; + + if (players[secondplaya].mo) + players[secondplaya].mo->color = players[secondplaya].skincolor; + } + } + return; + } + + // Don't actually send anything because splitscreen isn't actually allowed in netgames anyway! +} + +static void Got_NameAndColor(UINT8 **cp, INT32 playernum) +{ + player_t *p = &players[playernum]; + INT32 i; + char name[MAXPLAYERNAME+1]; + UINT8 color, skin; + +#ifdef PARANOIA + if (playernum < 0 || playernum > MAXPLAYERS) + I_Error("There is no player %d!", playernum); +#endif + + if (playernum == consoleplayer) + snacpending--; + else if (playernum == secondarydisplayplayer) + snac2pending--; + +#ifdef PARANOIA + if (snacpending < 0 || snac2pending < 0) + I_Error("snacpending negative!"); +#endif + + READSTRINGN(*cp, name, MAXPLAYERNAME); + color = READUINT8(*cp); + skin = READUINT8(*cp); + + // set name + if (strcasecmp(player_names[playernum], name) != 0) + SetPlayerName(playernum, name); + + // set color + p->skincolor = color % MAXSKINCOLORS; + if (p->mo) + p->mo->color = (UINT8)p->skincolor; + + // normal player colors + if (server && (p != &players[consoleplayer] && p != &players[secondarydisplayplayer])) + { + boolean kick = false; + + // team colors + if (G_GametypeHasTeams()) + { + if (p->ctfteam == 1 && p->skincolor != skincolor_redteam) + kick = true; + else if (p->ctfteam == 2 && p->skincolor != skincolor_blueteam) + kick = true; + } + + // don't allow color "none" + if (!p->skincolor) + kick = true; + + if (kick) + { + XBOXSTATIC UINT8 buf[2]; + CONS_Alert(CONS_WARNING, M_GetText("Illegal color change received from %s (team: %d), color: %d)\n"), player_names[playernum], p->ctfteam, p->skincolor); + + buf[0] = (UINT8)playernum; + buf[1] = KICK_MSG_CON_FAIL; + SendNetXCmd(XD_KICK, &buf, 2); + return; + } + } + + // set skin + if (cv_forceskin.value >= 0 && (netgame || multiplayer)) // Server wants everyone to use the same player + { + const INT32 forcedskin = cv_forceskin.value; + + if (triggerforcedskin) + { + for (i = 0; i < MAXPLAYERS; i++) + { + if (playeringame[i]) + { + SetPlayerSkinByNum(i, forcedskin); + + // If it's me (or my brother), set appropriate skin value in cv_skin/cv_skin2 + if (i == consoleplayer) + CV_StealthSet(&cv_skin, skins[forcedskin].name); + else if (i == secondarydisplayplayer) + CV_StealthSet(&cv_skin2, skins[forcedskin].name); + } + } + triggerforcedskin = false; + } + else + { + SetPlayerSkinByNum(playernum, forcedskin); + + if (playernum == consoleplayer) + CV_StealthSet(&cv_skin, skins[forcedskin].name); + else if (playernum == secondarydisplayplayer) + CV_StealthSet(&cv_skin2, skins[forcedskin].name); + } + } + else + SetPlayerSkinByNum(playernum, skin); + + players[playernum].pflags |= PF_CONSISTANCY; +} + +void SendWeaponPref(void) +{ + XBOXSTATIC UINT8 buf[1]; + + buf[0] = 0; + if (cv_flipcam.value) + buf[0] |= 1; + SendNetXCmd(XD_WEAPONPREF, buf, 1); + + if (splitscreen) + { + buf[0] = 0; + if (cv_flipcam2.value) + buf[0] |= 1; + SendNetXCmd2(XD_WEAPONPREF, buf, 1); + } +} + +static void Got_WeaponPref(UINT8 **cp,INT32 playernum) +{ + UINT8 prefs = READUINT8(*cp); + if (prefs & 1) + players[playernum].pflags |= PF_FLIPCAM; + else + players[playernum].pflags &= ~PF_FLIPCAM; +} + +void D_SendPlayerConfig(void) +{ + SendNameAndColor(); + if (splitscreen || botingame) + SendNameAndColor2(); + SendWeaponPref(); +} + +// Only works for displayplayer, sorry! +static void Command_ResetCamera_f(void) +{ + P_ResetCamera(&players[displayplayer], &camera); +} + +static void Command_RTeleport_f(void) +{ + fixed_t intx, inty, intz; + size_t i; + player_t *p = &players[consoleplayer]; + subsector_t *ss; + + if (!(cv_debug || devparm)) + { + CONS_Printf(M_GetText("DEVMODE must be enabled.")); + return; + } + if (netgame) + { + CONS_Printf(M_GetText("This only works in single player.\n")); + return; + } + + if (COM_Argc() < 3 || COM_Argc() > 7) + { + CONS_Printf(M_GetText("rteleport -x -y -z : relative teleport to a location\n")); + return; + } + + if (!p->mo) + return; + + i = COM_CheckParm("-x"); + if (i) + intx = atoi(COM_Argv(i + 1)); + else + intx = 0; + + i = COM_CheckParm("-y"); + if (i) + inty = atoi(COM_Argv(i + 1)); + else + inty = 0; + + ss = R_PointInSubsector(p->mo->x + intx*FRACUNIT, p->mo->y + inty*FRACUNIT); + if (!ss || ss->sector->ceilingheight - ss->sector->floorheight < p->mo->height) + { + CONS_Alert(CONS_NOTICE, M_GetText("Not a valid location.\n")); + return; + } + i = COM_CheckParm("-z"); + if (i) + { + intz = atoi(COM_Argv(i + 1)); + intz <<= FRACBITS; + intz += p->mo->z; + if (intz < ss->sector->floorheight) + intz = ss->sector->floorheight; + if (intz > ss->sector->ceilingheight - p->mo->height) + intz = ss->sector->ceilingheight - p->mo->height; + } + else + intz = 0; + + CONS_Printf(M_GetText("Teleporting by %d, %d, %d...\n"), intx, inty, FixedInt((intz-p->mo->z))); + + P_MapStart(); + if (!P_TeleportMove(p->mo, p->mo->x+intx*FRACUNIT, p->mo->y+inty*FRACUNIT, intz)) + CONS_Alert(CONS_WARNING, M_GetText("Unable to teleport to that spot!\n")); + else + S_StartSound(p->mo, sfx_mixup); + P_MapEnd(); +} + +static void Command_Teleport_f(void) +{ + fixed_t intx, inty, intz; + size_t i; + player_t *p = &players[consoleplayer]; + subsector_t *ss; + + if (!(cv_debug || devparm)) + { + CONS_Printf(M_GetText("DEVMODE must be enabled.")); + return; + } + if (netgame) + { + CONS_Printf(M_GetText("This only works in single player.\n")); + return; + } + + if (COM_Argc() < 3 || COM_Argc() > 7) + { + CONS_Printf(M_GetText("teleport -x -y -z : teleport to a location\n")); + return; + } + + if (!p->mo) + return; + + i = COM_CheckParm("-x"); + if (i) + intx = atoi(COM_Argv(i + 1)); + else + { + CONS_Alert(CONS_NOTICE, M_GetText("%s value not specified\n"), "X"); + return; + } + + i = COM_CheckParm("-y"); + if (i) + inty = atoi(COM_Argv(i + 1)); + else + { + CONS_Alert(CONS_NOTICE, M_GetText("%s value not specified\n"), "Y"); + return; + } + + ss = R_PointInSubsector(intx*FRACUNIT, inty*FRACUNIT); + if (!ss || ss->sector->ceilingheight - ss->sector->floorheight < p->mo->height) + { + CONS_Alert(CONS_NOTICE, M_GetText("Not a valid location.\n")); + return; + } + i = COM_CheckParm("-z"); + if (i) + { + intz = atoi(COM_Argv(i + 1)); + intz <<= FRACBITS; + if (intz < ss->sector->floorheight) + intz = ss->sector->floorheight; + if (intz > ss->sector->ceilingheight - p->mo->height) + intz = ss->sector->ceilingheight - p->mo->height; + } + else + intz = ss->sector->floorheight; + + CONS_Printf(M_GetText("Teleporting to %d, %d, %d...\n"), intx, inty, FixedInt(intz)); + + P_MapStart(); + if (!P_TeleportMove(p->mo, intx*FRACUNIT, inty*FRACUNIT, intz)) + CONS_Alert(CONS_WARNING, M_GetText("Unable to teleport to that spot!\n")); + else + S_StartSound(p->mo, sfx_mixup); + P_MapEnd(); +} + +// ======================================================================== + +// play a demo, add .lmp for external demos +// eg: playdemo demo1 plays the internal game demo +// +// UINT8 *demofile; // demo file buffer +static void Command_Playdemo_f(void) +{ + char name[256]; + + if (COM_Argc() != 2) + { + CONS_Printf(M_GetText("playdemo : playback a demo\n")); + return; + } + + // disconnect from server here? + if (demoplayback || metalplayback) + G_StopDemo(); + if (netgame) + { + CONS_Printf(M_GetText("You can't play a demo while in a netgame.\n")); + return; + } + + // open the demo file + strcpy(name, COM_Argv(1)); + // dont add .lmp so internal game demos can be played + + CONS_Printf(M_GetText("Playing back demo '%s'.\n"), name); + + G_DoPlayDemo(name); +} + +static void Command_Timedemo_f(void) +{ + char name[256]; + + if (COM_Argc() != 2) + { + CONS_Printf(M_GetText("timedemo : time a demo\n")); + return; + } + + // disconnect from server here? + if (demoplayback || metalplayback) + G_StopDemo(); + if (netgame) + { + CONS_Printf(M_GetText("You can't play a demo while in a netgame.\n")); + return; + } + + // open the demo file + strcpy (name, COM_Argv(1)); + // dont add .lmp so internal game demos can be played + + CONS_Printf(M_GetText("Timing demo '%s'.\n"), name); + + G_TimeDemo(name); +} + +// stop current demo +static void Command_Stopdemo_f(void) +{ + G_CheckDemoStatus(); + CONS_Printf(M_GetText("Stopped demo.\n")); +} + +static void Command_StartMovie_f(void) +{ + M_StartMovie(); +} + +static void Command_StopMovie_f(void) +{ + M_StopMovie(); +} + +INT32 mapchangepending = 0; + +/** Runs a map change. + * The supplied data are assumed to be good. If provided by a user, they will + * have already been checked in Command_Map_f(). + * + * Do \b NOT call this function directly from a menu! M_Responder() is called + * from within the event processing loop, and this function calls + * SV_SpawnServer(), which calls CL_ConnectToServer(), which gives you "Press + * ESC to abort", which calls I_GetKey(), which adds an event. In other words, + * 63 old events will get reexecuted, with ridiculous results. Just don't do + * it (without setting delay to 1, which is the current solution). + * + * \param mapnum Map number to change to. + * \param gametype Gametype to switch to. + * \param pultmode Is this 'Ultimate Mode'? + * \param resetplayers 1 to reset player scores and lives and such, 0 not to. + * \param delay Determines how the function will be executed: 0 to do + * it all right now (must not be done from a menu), 1 to + * do step one and prepare step two, 2 to do step two. + * \param skipprecutscene To skip the precutscence or not? + * \sa D_GameTypeChanged, Command_Map_f + * \author Graue + */ +void D_MapChange(INT32 mapnum, INT32 newgametype, boolean pultmode, boolean resetplayers, INT32 delay, boolean skipprecutscene, boolean FLS) +{ + static char buf[2+MAX_WADPATH+1+4]; + static char *buf_p = buf; + + // The supplied data are assumed to be good. + I_Assert(delay >= 0 && delay <= 2); + + CONS_Debug(DBG_GAMELOGIC, "Map change: mapnum=%d gametype=%d ultmode=%d resetplayers=%d delay=%d skipprecutscene=%d\n", + mapnum, newgametype, pultmode, resetplayers, delay, skipprecutscene); + + if (netgame || multiplayer) + FLS = false; + + if (delay != 2) + { + UINT8 flags = 0; + const char *mapname = G_BuildMapName(mapnum); + + I_Assert(W_CheckNumForName(mapname) != LUMPERROR); + + buf_p = buf; + if (pultmode) + flags |= 1; + if (!resetplayers) + flags |= 1<<1; + if (skipprecutscene) + flags |= 1<<2; + if (FLS) + flags |= 1<<3; + WRITEUINT8(buf_p, flags); + + // new gametype value + WRITEUINT8(buf_p, newgametype); + + WRITESTRINGN(buf_p, mapname, MAX_WADPATH); + } + + if (delay == 1) + mapchangepending = 1; + else + { + mapchangepending = 0; + // spawn the server if needed + // reset players if there is a new one + if (!(adminplayer == consoleplayer) && SV_SpawnServer()) + buf[0] &= ~(1<<1); + + // Kick bot from special stages + if (botskin) + { + if (G_IsSpecialStage(mapnum)) + { + if (botingame) + { + //CL_RemoveSplitscreenPlayer(); + botingame = false; + playeringame[1] = false; + } + } + else if (!botingame) + { + //CL_AddSplitscreenPlayer(); + botingame = true; + secondarydisplayplayer = 1; + playeringame[1] = true; + players[1].bot = 1; + SendNameAndColor2(); + } + } + + chmappending++; + if (netgame) + WRITEUINT32(buf_p, M_RandomizedSeed()); // random seed + SendNetXCmd(XD_MAP, buf, buf_p - buf); + } +} + +// Warp to map code. +// Called either from map console command, or idclev cheat. +// +static void Command_Map_f(void) +{ + const char *mapname; + size_t i; + INT32 j, newmapnum; + boolean newresetplayers; + INT32 newgametype = gametype; + + // max length of command: map map03 -gametype coop -noresetplayers -force + // 1 2 3 4 5 6 + // = 8 arg max + if (COM_Argc() < 2 || COM_Argc() > 8) + { + CONS_Printf(M_GetText("map [-gametype [-force]: warp to map\n")); + return; + } + + if (!server && !(adminplayer == consoleplayer)) + { + CONS_Printf(M_GetText("Only the server or a remote admin can use this.\n")); + return; + } + + // internal wad lump always: map command doesn't support external files as in doom legacy + if (W_CheckNumForName(COM_Argv(1)) == LUMPERROR) + { + CONS_Alert(CONS_ERROR, M_GetText("Internal game level '%s' not found\n"), COM_Argv(1)); + return; + } + + if (!(netgame || multiplayer) && (!modifiedgame || savemoddata)) + { + if (COM_CheckParm("-force")) + G_SetGameModified(false); + else + { + CONS_Printf(M_GetText("Sorry, level change disabled in single player.\n")); + return; + } + } + + newresetplayers = !COM_CheckParm("-noresetplayers"); + + if (!newresetplayers && !cv_debug) + { + CONS_Printf(M_GetText("DEVMODE must be enabled.\n")); + return; + } + + mapname = COM_Argv(1); + if (strlen(mapname) != 5 + || (newmapnum = M_MapNumber(mapname[3], mapname[4])) == 0) + { + CONS_Alert(CONS_ERROR, M_GetText("Invalid level name %s\n"), mapname); + return; + } + + // Ultimate Mode only in SP via menu + if (netgame || multiplayer) + ultimatemode = false; + + // new gametype value + // use current one by default + i = COM_CheckParm("-gametype"); + if (i) + { + if (!multiplayer) + { + CONS_Printf(M_GetText("You can't switch gametypes in single player!\n")); + return; + } + + for (j = 0; gametype_cons_t[j].strvalue; j++) + if (!strcasecmp(gametype_cons_t[j].strvalue, COM_Argv(i+1))) + { + // Don't do any variable setting here. Wait until you get your + // map packet first to avoid sending the same info twice! + newgametype = gametype_cons_t[j].value; + + break; + } + + if (!gametype_cons_t[j].strvalue) // reached end of the list with no match + { + // assume they gave us a gametype number, which is okay too + for (j = 0; gametype_cons_t[j].strvalue != NULL; j++) + { + if (atoi(COM_Argv(i+1)) == gametype_cons_t[j].value) + { + newgametype = gametype_cons_t[j].value; + break; + } + } + } + } + + // don't use a gametype the map doesn't support + if (cv_debug || COM_CheckParm("-force") || cv_skipmapcheck.value) + ; // The player wants us to trek on anyway. Do so. + // G_TOLFlag handles both multiplayer gametype and ignores it for !multiplayer + // Alternatively, bail if the map header is completely missing anyway. + else if (!mapheaderinfo[newmapnum-1] + || !(mapheaderinfo[newmapnum-1]->typeoflevel & G_TOLFlag(newgametype))) + { + char gametypestring[32] = "Single Player"; + + if (multiplayer) + for (i = 0; gametype_cons_t[i].strvalue != NULL; i++) + if (gametype_cons_t[i].value == newgametype) + { + strcpy(gametypestring, gametype_cons_t[i].strvalue); + break; + } + + CONS_Alert(CONS_WARNING, M_GetText("%s doesn't support %s mode!\n(Use -force to override)\n"), mapname, gametypestring); + return; + } + + // Prevent warping to locked levels + // ... unless you're in a dedicated server. Yes, technically this means you can view any level by + // running a dedicated server and joining it yourself, but that's better than making dedicated server's + // lives hell. + if (!dedicated && M_MapLocked(newmapnum)) + { + CONS_Alert(CONS_NOTICE, M_GetText("You need to unlock this level before you can warp to it!\n")); + return; + } + + fromlevelselect = false; + D_MapChange(newmapnum, newgametype, false, newresetplayers, 0, false, false); +} + +/** Receives a map command and changes the map. + * + * \param cp Data buffer. + * \param playernum Player number responsible for the message. Should be + * ::serverplayer or ::adminplayer. + * \sa D_MapChange + */ +static void Got_Mapcmd(UINT8 **cp, INT32 playernum) +{ + char mapname[MAX_WADPATH+1]; + UINT8 flags; + INT32 resetplayer = 1, lastgametype; + UINT8 skipprecutscene, FLS; + + if (playernum != serverplayer && playernum != adminplayer) + { + CONS_Alert(CONS_WARNING, M_GetText("Illegal map change received from %s\n"), player_names[playernum]); + if (server) + { + XBOXSTATIC UINT8 buf[2]; + + buf[0] = (UINT8)playernum; + buf[1] = KICK_MSG_CON_FAIL; + SendNetXCmd(XD_KICK, &buf, 2); + } + return; + } + + if (chmappending) + chmappending--; + + flags = READUINT8(*cp); + + ultimatemode = ((flags & 1) != 0); + if (netgame || multiplayer) + ultimatemode = false; + + resetplayer = ((flags & (1<<1)) == 0); + + lastgametype = gametype; + gametype = READUINT8(*cp); + + if (gametype != lastgametype) + D_GameTypeChanged(lastgametype); // emulate consvar_t behavior for gametype + + skipprecutscene = ((flags & (1<<2)) != 0); + + FLS = ((flags & (1<<3)) != 0); + + READSTRINGN(*cp, mapname, MAX_WADPATH); + + if (netgame) + P_SetRandSeed(READUINT32(*cp)); + + if (!skipprecutscene) + { + DEBFILE(va("Warping to %s [resetplayer=%d lastgametype=%d gametype=%d cpnd=%d]\n", + mapname, resetplayer, lastgametype, gametype, chmappending)); + CONS_Printf(M_GetText("Speeding off to level...\n")); + } + if (demoplayback && !timingdemo) + precache = false; + + if (resetplayer) + { + if (!FLS || (netgame || multiplayer)) + emeralds = 0; + } + +#ifdef HAVE_BLUA + LUAh_MapChange(); +#endif + + G_InitNew(ultimatemode, mapname, resetplayer, skipprecutscene); + if (demoplayback && !timingdemo) + precache = true; + CON_ToggleOff(); + if (timingdemo) + G_DoneLevelLoad(); + + if (modeattacking) + { + SetPlayerSkinByNum(0, cv_chooseskin.value-1); + players[0].skincolor = skins[players[0].skin].prefcolor; + CV_StealthSetValue(&cv_playercolor, players[0].skincolor); + + // a copy of color + if (players[0].mo) + players[0].mo->color = players[0].skincolor; + } + if (metalrecording) + G_BeginMetal(); + if (demorecording) // Okay, level loaded, character spawned and skinned, + G_BeginRecording(); // I AM NOW READY TO RECORD. + demo_start = true; +} + +static void Command_Pause(void) +{ + XBOXSTATIC UINT8 buf[2]; + UINT8 *cp = buf; + + if (COM_Argc() > 1) + WRITEUINT8(cp, (char)(atoi(COM_Argv(1)) != 0)); + else + WRITEUINT8(cp, (char)(!paused)); + + if (dedicated) + WRITEUINT8(cp, 1); + else + WRITEUINT8(cp, 0); + + if (cv_pause.value || server || (adminplayer == consoleplayer)) + { + if (!(gamestate == GS_LEVEL || gamestate == GS_INTERMISSION)) + { + CONS_Printf(M_GetText("You can't pause here.\n")); + return; + } + SendNetXCmd(XD_PAUSE, &buf, 2); + } + else + CONS_Printf(M_GetText("Only the server or a remote admin can use this.\n")); +} + +static void Got_Pause(UINT8 **cp, INT32 playernum) +{ + UINT8 dedicatedpause = false; + const char *playername; + + if (netgame && !cv_pause.value && playernum != serverplayer && playernum != adminplayer) + { + CONS_Alert(CONS_WARNING, M_GetText("Illegal pause command received from %s\n"), player_names[playernum]); + if (server) + { + XBOXSTATIC UINT8 buf[2]; + + buf[0] = (UINT8)playernum; + buf[1] = KICK_MSG_CON_FAIL; + SendNetXCmd(XD_KICK, &buf, 2); + } + return; + } + + paused = READUINT8(*cp); + dedicatedpause = READUINT8(*cp); + + if (!demoplayback) + { + if (netgame) + { + if (dedicatedpause) + playername = "SERVER"; + else + playername = player_names[playernum]; + + if (paused) + CONS_Printf(M_GetText("Game paused by %s\n"), playername); + else + CONS_Printf(M_GetText("Game unpaused by %s\n"), playername); + } + + if (paused) + { + if (!menuactive || netgame) + S_PauseSound(); + } + else + S_ResumeSound(); + } +} + +// Command for stuck characters in netgames, griefing, etc. +static void Command_Suicide(void) +{ + XBOXSTATIC UINT8 buf[4]; + UINT8 *cp = buf; + + WRITEINT32(cp, consoleplayer); + + if (!(gamestate == GS_LEVEL || gamestate == GS_INTERMISSION)) + { + CONS_Printf(M_GetText("You must be in a level to use this.\n")); + return; + } + + if (!G_PlatformGametype()) + { + CONS_Printf(M_GetText("You may only use this in co-op, race, and competition!\n")); + return; + } + + // Retry is quicker. Probably should force people to use it. + if (!(netgame || multiplayer)) + { + CONS_Printf(M_GetText("You can't use this in Single Player! Use \"retry\" instead.\n")); + return; + } + + SendNetXCmd(XD_SUICIDE, &buf, 4); +} + +static void Got_Suicide(UINT8 **cp, INT32 playernum) +{ + INT32 suicideplayer = READINT32(*cp); + + // You can't suicide someone else. Nice try, there. + if (suicideplayer != playernum || (!G_PlatformGametype())) + { + CONS_Alert(CONS_WARNING, M_GetText("Illegal suicide command recieved from %s\n"), player_names[playernum]); + if (server) + { + XBOXSTATIC UINT8 buf[2]; + + buf[0] = (UINT8)playernum; + buf[1] = KICK_MSG_CON_FAIL; + SendNetXCmd(XD_KICK, &buf, 2); + } + return; + } + + if (players[suicideplayer].mo) + P_DamageMobj(players[suicideplayer].mo, NULL, NULL, 10000); +} + +/** Deals with an ::XD_RANDOMSEED message in a netgame. + * These messages set the position of the random number LUT and are crucial to + * correct synchronization. + * + * Such a message should only ever come from the ::serverplayer. If it comes + * from any other player, it is ignored. + * + * \param cp Data buffer. + * \param playernum Player responsible for the message. Must be ::serverplayer. + * \author Graue + */ +static void Got_RandomSeed(UINT8 **cp, INT32 playernum) +{ + UINT32 seed; + + seed = READUINT32(*cp); + + if (playernum != serverplayer) // it's not from the server, wtf? + return; + + P_SetRandSeed(seed); +} + +/** Clears all players' scores in a netgame. + * Only the server or a remote admin can use this command, for obvious reasons. + * + * \sa XD_CLEARSCORES, Got_Clearscores + * \author SSNTails + */ +static void Command_Clearscores_f(void) +{ + if (!(server || (adminplayer == consoleplayer))) + return; + + SendNetXCmd(XD_CLEARSCORES, NULL, 1); +} + +/** Handles an ::XD_CLEARSCORES message, which resets all players' scores in a + * netgame to zero. + * + * \param cp Data buffer. + * \param playernum Player responsible for the message. Must be ::serverplayer + * or ::adminplayer. + * \sa XD_CLEARSCORES, Command_Clearscores_f + * \author SSNTails + */ +static void Got_Clearscores(UINT8 **cp, INT32 playernum) +{ + INT32 i; + + (void)cp; + if (playernum != serverplayer && playernum != adminplayer) + { + CONS_Alert(CONS_WARNING, M_GetText("Illegal clear scores command received from %s\n"), player_names[playernum]); + if (server) + { + XBOXSTATIC UINT8 buf[2]; + + buf[0] = (UINT8)playernum; + buf[1] = KICK_MSG_CON_FAIL; + SendNetXCmd(XD_KICK, &buf, 2); + } + return; + } + + for (i = 0; i < MAXPLAYERS; i++) + players[i].score = 0; + + CONS_Printf(M_GetText("Scores have been reset by the server.\n")); +} + +// Team changing functions +static void Command_Teamchange_f(void) +{ + changeteam_union NetPacket; + boolean error = false; + UINT16 usvalue; + NetPacket.value.l = NetPacket.value.b = 0; + + // 0 1 + // changeteam + + if (COM_Argc() <= 1) + { + if (G_GametypeHasTeams()) + CONS_Printf(M_GetText("changeteam : switch to a new team (%s)\n"), "red, blue or spectator"); + else if (G_GametypeHasSpectators()) + CONS_Printf(M_GetText("changeteam : switch to a new team (%s)\n"), "spectator or playing"); + else + CONS_Alert(CONS_NOTICE, M_GetText("This command cannot be used in this gametype.\n")); + return; + } + + if (G_GametypeHasTeams()) + { + if (!strcasecmp(COM_Argv(1), "red") || !strcasecmp(COM_Argv(1), "1")) + NetPacket.packet.newteam = 1; + else if (!strcasecmp(COM_Argv(1), "blue") || !strcasecmp(COM_Argv(1), "2")) + NetPacket.packet.newteam = 2; + else if (!strcasecmp(COM_Argv(1), "spectator") || !strcasecmp(COM_Argv(1), "0")) + NetPacket.packet.newteam = 0; + else + error = true; + } + else if (G_GametypeHasSpectators()) + { + if (!strcasecmp(COM_Argv(1), "spectator") || !strcasecmp(COM_Argv(1), "0")) + NetPacket.packet.newteam = 0; + else if (!strcasecmp(COM_Argv(1), "playing") || !strcasecmp(COM_Argv(1), "1")) + NetPacket.packet.newteam = 3; + else + error = true; + } + else + { + CONS_Alert(CONS_NOTICE, M_GetText("This command cannot be used in this gametype.\n")); + return; + } + + if (error) + { + if (G_GametypeHasTeams()) + CONS_Printf(M_GetText("changeteam : switch to a new team (%s)\n"), "red, blue or spectator"); + else if (G_GametypeHasSpectators()) + CONS_Printf(M_GetText("changeteam : switch to a new team (%s)\n"), "spectator or playing"); + return; + } + + if (G_GametypeHasTeams()) + { + if (NetPacket.packet.newteam == (unsigned)players[consoleplayer].ctfteam || + (players[consoleplayer].spectator && !NetPacket.packet.newteam)) + error = true; + } + else if (G_GametypeHasSpectators()) + { + if ((players[consoleplayer].spectator && !NetPacket.packet.newteam) || + (!players[consoleplayer].spectator && NetPacket.packet.newteam == 3)) + error = true; + } +#ifdef PARANOIA + else + I_Error("Invalid gametype after initial checks!"); +#endif + + if (error) + { + CONS_Alert(CONS_NOTICE, M_GetText("You're already on that team!\n")); + return; + } + + if (!cv_allowteamchange.value && !NetPacket.packet.newteam) // allow swapping to spectator even in locked teams. + { + CONS_Alert(CONS_NOTICE, M_GetText("The server is not allowing team changes at the moment.\n")); + return; + } + + //additional check for hide and seek. Don't allow change of status after hidetime ends. + if (gametype == GT_HIDEANDSEEK && leveltime >= (hidetime * TICRATE)) + { + CONS_Alert(CONS_NOTICE, M_GetText("Hiding time expired; no Hide and Seek status changes allowed!\n")); + return; + } + + usvalue = SHORT(NetPacket.value.l|NetPacket.value.b); + SendNetXCmd(XD_TEAMCHANGE, &usvalue, sizeof(usvalue)); +} + +static void Command_Teamchange2_f(void) +{ + changeteam_union NetPacket; + boolean error = false; + UINT16 usvalue; + NetPacket.value.l = NetPacket.value.b = 0; + + // 0 1 + // changeteam2 + + if (COM_Argc() <= 1) + { + if (G_GametypeHasTeams()) + CONS_Printf(M_GetText("changeteam : switch to a new team (%s)\n"), "red, blue or spectator"); + else if (G_GametypeHasSpectators()) + CONS_Printf(M_GetText("changeteam : switch to a new team (%s)\n"), "spectator or playing"); + else + CONS_Alert(CONS_NOTICE, M_GetText("This command cannot be used in this gametype.\n")); + return; + } + + if (G_GametypeHasTeams()) + { + if (!strcasecmp(COM_Argv(1), "red") || !strcasecmp(COM_Argv(1), "1")) + NetPacket.packet.newteam = 1; + else if (!strcasecmp(COM_Argv(1), "blue") || !strcasecmp(COM_Argv(1), "2")) + NetPacket.packet.newteam = 2; + else if (!strcasecmp(COM_Argv(1), "spectator") || !strcasecmp(COM_Argv(1), "0")) + NetPacket.packet.newteam = 0; + else + error = true; + } + else if (G_GametypeHasSpectators()) + { + if (!strcasecmp(COM_Argv(1), "spectator") || !strcasecmp(COM_Argv(1), "0")) + NetPacket.packet.newteam = 0; + else if (!strcasecmp(COM_Argv(1), "playing") || !strcasecmp(COM_Argv(1), "1")) + NetPacket.packet.newteam = 3; + else + error = true; + } + + else + { + CONS_Alert(CONS_NOTICE, M_GetText("This command cannot be used in this gametype.\n")); + return; + } + + if (error) + { + if (G_GametypeHasTeams()) + CONS_Printf(M_GetText("changeteam2 : switch to a new team (%s)\n"), "red, blue or spectator"); + else if (G_GametypeHasSpectators()) + CONS_Printf(M_GetText("changeteam2 : switch to a new team (%s)\n"), "spectator or playing"); + return; + } + + if (G_GametypeHasTeams()) + { + if (NetPacket.packet.newteam == (unsigned)players[secondarydisplayplayer].ctfteam || + (players[secondarydisplayplayer].spectator && !NetPacket.packet.newteam)) + error = true; + } + else if (G_GametypeHasSpectators()) + { + if ((players[secondarydisplayplayer].spectator && !NetPacket.packet.newteam) || + (!players[secondarydisplayplayer].spectator && NetPacket.packet.newteam == 3)) + error = true; + } +#ifdef PARANOIA + else + I_Error("Invalid gametype after initial checks!"); +#endif + + if (error) + { + CONS_Alert(CONS_NOTICE, M_GetText("You're already on that team!\n")); + return; + } + + if (!cv_allowteamchange.value && !NetPacket.packet.newteam) // allow swapping to spectator even in locked teams. + { + CONS_Alert(CONS_NOTICE, M_GetText("The server is not allowing team changes at the moment.\n")); + return; + } + + //additional check for hide and seek. Don't allow change of status after hidetime ends. + if (gametype == GT_HIDEANDSEEK && leveltime >= (hidetime * TICRATE)) + { + CONS_Alert(CONS_NOTICE, M_GetText("Hiding time expired; no Hide and Seek status changes allowed!\n")); + return; + } + + usvalue = SHORT(NetPacket.value.l|NetPacket.value.b); + SendNetXCmd2(XD_TEAMCHANGE, &usvalue, sizeof(usvalue)); +} + +static void Command_ServerTeamChange_f(void) +{ + changeteam_union NetPacket; + boolean error = false; + UINT16 usvalue; + NetPacket.value.l = NetPacket.value.b = 0; + + if (!(server || (adminplayer == consoleplayer))) + { + CONS_Printf(M_GetText("Only the server or a remote admin can use this.\n")); + return; + } + + // 0 1 2 + // serverchangeteam + + if (COM_Argc() < 3) + { + if (G_TagGametype()) + CONS_Printf(M_GetText("serverchangeteam : switch player to a new team (%s)\n"), "it, notit, playing, or spectator"); + else if (G_GametypeHasTeams()) + CONS_Printf(M_GetText("serverchangeteam : switch player to a new team (%s)\n"), "red, blue or spectator"); + else if (G_GametypeHasSpectators()) + CONS_Printf(M_GetText("serverchangeteam : switch player to a new team (%s)\n"), "spectator or playing"); + else + CONS_Alert(CONS_NOTICE, M_GetText("This command cannot be used in this gametype.\n")); + return; + } + + if (G_TagGametype()) + { + if (!strcasecmp(COM_Argv(2), "it") || !strcasecmp(COM_Argv(2), "1")) + NetPacket.packet.newteam = 1; + else if (!strcasecmp(COM_Argv(2), "notit") || !strcasecmp(COM_Argv(2), "2")) + NetPacket.packet.newteam = 2; + else if (!strcasecmp(COM_Argv(2), "playing") || !strcasecmp(COM_Argv(2), "3")) + NetPacket.packet.newteam = 3; + else if (!strcasecmp(COM_Argv(2), "spectator") || !strcasecmp(COM_Argv(2), "0")) + NetPacket.packet.newteam = 0; + else + error = true; + } + else if (G_GametypeHasTeams()) + { + if (!strcasecmp(COM_Argv(2), "red") || !strcasecmp(COM_Argv(2), "1")) + NetPacket.packet.newteam = 1; + else if (!strcasecmp(COM_Argv(2), "blue") || !strcasecmp(COM_Argv(2), "2")) + NetPacket.packet.newteam = 2; + else if (!strcasecmp(COM_Argv(2), "spectator") || !strcasecmp(COM_Argv(2), "0")) + NetPacket.packet.newteam = 0; + else + error = true; + } + else if (G_GametypeHasSpectators()) + { + if (!strcasecmp(COM_Argv(2), "spectator") || !strcasecmp(COM_Argv(2), "0")) + NetPacket.packet.newteam = 0; + else if (!strcasecmp(COM_Argv(2), "playing") || !strcasecmp(COM_Argv(2), "1")) + NetPacket.packet.newteam = 3; + else + error = true; + } + else + { + CONS_Alert(CONS_NOTICE, M_GetText("This command cannot be used in this gametype.\n")); + return; + } + + if (error) + { + if (G_TagGametype()) + CONS_Printf(M_GetText("serverchangeteam : switch player to a new team (%s)\n"), "it, notit, playing, or spectator"); + else if (G_GametypeHasTeams()) + CONS_Printf(M_GetText("serverchangeteam : switch player to a new team (%s)\n"), "red, blue or spectator"); + else if (G_GametypeHasSpectators()) + CONS_Printf(M_GetText("serverchangeteam : switch player to a new team (%s)\n"), "spectator or playing"); + return; + } + + NetPacket.packet.playernum = atoi(COM_Argv(1)); + + if (!playeringame[NetPacket.packet.playernum]) + { + CONS_Alert(CONS_NOTICE, M_GetText("There is no player %d!\n"), NetPacket.packet.playernum); + return; + } + + if (G_TagGametype()) + { + if (( (players[NetPacket.packet.playernum].pflags & PF_TAGIT) && NetPacket.packet.newteam == 1) || + (!(players[NetPacket.packet.playernum].pflags & PF_TAGIT) && NetPacket.packet.newteam == 2) || + ( players[NetPacket.packet.playernum].spectator && !NetPacket.packet.newteam) || + (!players[NetPacket.packet.playernum].spectator && NetPacket.packet.newteam == 3)) + error = true; + } + else if (G_GametypeHasTeams()) + { + if (NetPacket.packet.newteam == (unsigned)players[NetPacket.packet.playernum].ctfteam || + (players[NetPacket.packet.playernum].spectator && !NetPacket.packet.newteam)) + error = true; + } + else if (G_GametypeHasSpectators()) + { + if ((players[NetPacket.packet.playernum].spectator && !NetPacket.packet.newteam) || + (!players[NetPacket.packet.playernum].spectator && NetPacket.packet.newteam == 3)) + error = true; + } +#ifdef PARANOIA + else + I_Error("Invalid gametype after initial checks!"); +#endif + + if (error) + { + CONS_Alert(CONS_NOTICE, M_GetText("That player is already on that team!\n")); + return; + } + + //additional check for hide and seek. Don't allow change of status after hidetime ends. + if (gametype == GT_HIDEANDSEEK && leveltime >= (hidetime * TICRATE)) + { + CONS_Alert(CONS_NOTICE, M_GetText("Hiding time expired; no Hide and Seek status changes allowed!\n")); + return; + } + + NetPacket.packet.verification = true; // This signals that it's a server change + + usvalue = SHORT(NetPacket.value.l|NetPacket.value.b); + SendNetXCmd(XD_TEAMCHANGE, &usvalue, sizeof(usvalue)); +} + +//todo: This and the other teamchange functions are getting too long and messy. Needs cleaning. +static void Got_Teamchange(UINT8 **cp, INT32 playernum) +{ + changeteam_union NetPacket; + boolean error = false; + NetPacket.value.l = NetPacket.value.b = READINT16(*cp); + + if (!G_GametypeHasTeams() && !G_GametypeHasSpectators()) //Make sure you're in the right gametype. + { + // this should never happen unless the client is hacked/buggy + CONS_Alert(CONS_WARNING, M_GetText("Illegal team change received from player %s\n"), player_names[playernum]); + if (server) + { + XBOXSTATIC UINT8 buf[2]; + + buf[0] = (UINT8)playernum; + buf[1] = KICK_MSG_CON_FAIL; + SendNetXCmd(XD_KICK, &buf, 2); + } + } + + if (NetPacket.packet.verification) // Special marker that the server sent the request + { + if (playernum != serverplayer && (playernum != adminplayer)) + { + CONS_Alert(CONS_WARNING, M_GetText("Illegal team change received from player %s\n"), player_names[playernum]); + if (server) + { + XBOXSTATIC UINT8 buf[2]; + + buf[0] = (UINT8)playernum; + buf[1] = KICK_MSG_CON_FAIL; + SendNetXCmd(XD_KICK, &buf, 2); + } + return; + } + playernum = NetPacket.packet.playernum; + } + + // Prevent multiple changes in one go. + if (G_TagGametype()) + { + if (((players[playernum].pflags & PF_TAGIT) && NetPacket.packet.newteam == 1) || + (!(players[playernum].pflags & PF_TAGIT) && NetPacket.packet.newteam == 2) || + (players[playernum].spectator && NetPacket.packet.newteam == 0) || + (!players[playernum].spectator && NetPacket.packet.newteam == 3)) + return; + } + else if (G_GametypeHasTeams()) + { + if ((NetPacket.packet.newteam && (NetPacket.packet.newteam == (unsigned)players[playernum].ctfteam)) || + (players[playernum].spectator && !NetPacket.packet.newteam)) + return; + } + else if (G_GametypeHasSpectators()) + { + if ((players[playernum].spectator && !NetPacket.packet.newteam) || + (!players[playernum].spectator && NetPacket.packet.newteam == 3)) + return; + } + else + { + if (playernum != serverplayer && (playernum != adminplayer)) + { + CONS_Alert(CONS_WARNING, M_GetText("Illegal team change received from player %s\n"), player_names[playernum]); + if (server) + { + XBOXSTATIC UINT8 buf[2]; + + buf[0] = (UINT8)playernum; + buf[1] = KICK_MSG_CON_FAIL; + SendNetXCmd(XD_KICK, &buf, 2); + } + } + return; + } + + //Make sure that the right team number is sent. Keep in mind that normal clients cannot change to certain teams in certain gametypes. + switch (gametype) + { + case GT_HIDEANDSEEK: + //no status changes after hidetime + if (leveltime >= (hidetime * TICRATE)) + { + error = true; + break; + } + //fall down + case GT_TAG: + switch (NetPacket.packet.newteam) + { + case 0: + break; + case 1: case 2: + if (!NetPacket.packet.verification) + error = true; //Only admin can change player's IT status' in tag. + break; + case 3: //Join game via console. + if (!NetPacket.packet.verification && !cv_allowteamchange.value) + error = true; + break; + } + + break; + default: +#ifdef PARANOIA + if (!G_GametypeHasTeams() && !G_GametypeHasSpectators()) + I_Error("Invalid gametype after initial checks!"); +#endif + + if (!cv_allowteamchange.value) + { + if (!NetPacket.packet.verification && NetPacket.packet.newteam) + error = true; //Only admin can change status, unless changing to spectator. + } + break; //Otherwise, you don't need special permissions. + } + + if (server && ((NetPacket.packet.newteam < 0 || NetPacket.packet.newteam > 3) || error)) + { + XBOXSTATIC UINT8 buf[2]; + + buf[0] = (UINT8)playernum; + buf[1] = KICK_MSG_CON_FAIL; + CONS_Alert(CONS_WARNING, M_GetText("Illegal team change received from player %s\n"), player_names[playernum]); + SendNetXCmd(XD_KICK, &buf, 2); + } + + //Safety first! + if (players[playernum].mo) + { + if (!players[playernum].spectator) + P_DamageMobj(players[playernum].mo, NULL, NULL, 10000); + else + { + P_RemoveMobj(players[playernum].mo); + players[playernum].mo = NULL; + players[playernum].playerstate = PST_REBORN; + } + } + else + players[playernum].playerstate = PST_REBORN; + + //Now that we've done our error checking and killed the player + //if necessary, put the player on the correct team/status. + if (G_TagGametype()) + { + if (!NetPacket.packet.newteam) + { + players[playernum].spectator = true; + players[playernum].pflags &= ~PF_TAGIT; + players[playernum].pflags &= ~PF_TAGGED; + } + else if (NetPacket.packet.newteam != 3) // .newteam == 1 or 2. + { + players[playernum].spectator = false; + players[playernum].pflags &= ~PF_TAGGED;//Just in case. + + if (NetPacket.packet.newteam == 1) //Make the player IT. + players[playernum].pflags |= PF_TAGIT; + else + players[playernum].pflags &= ~PF_TAGIT; + } + else // Just join the game. + { + players[playernum].spectator = false; + + //If joining after hidetime in normal tag, default to being IT. + if (gametype == GT_TAG && (leveltime > (hidetime * TICRATE))) + { + NetPacket.packet.newteam = 1; //minor hack, causes the "is it" message to be printed later. + players[playernum].pflags |= PF_TAGIT; //make the player IT. + } + } + } + else if (G_GametypeHasTeams()) + { + if (!NetPacket.packet.newteam) + { + players[playernum].ctfteam = 0; + players[playernum].spectator = true; + } + else + { + players[playernum].ctfteam = NetPacket.packet.newteam; + players[playernum].spectator = false; + } + } + else if (G_GametypeHasSpectators()) + { + if (!NetPacket.packet.newteam) + players[playernum].spectator = true; + else + players[playernum].spectator = false; + } + + if (NetPacket.packet.autobalance) + { + if (NetPacket.packet.newteam == 1) + CONS_Printf(M_GetText("%s was autobalanced to the %c%s%c.\n"), player_names[playernum], '\x85', M_GetText("Red Team"), '\x80'); + else if (NetPacket.packet.newteam == 2) + CONS_Printf(M_GetText("%s was autobalanced to the %c%s%c.\n"), player_names[playernum], '\x84', M_GetText("Blue Team"), '\x80'); + } + else if (NetPacket.packet.scrambled) + { + if (NetPacket.packet.newteam == 1) + CONS_Printf(M_GetText("%s was scrambled to the %c%s%c.\n"), player_names[playernum], '\x85', M_GetText("Red Team"), '\x80'); + else if (NetPacket.packet.newteam == 2) + CONS_Printf(M_GetText("%s was scrambled to the %c%s%c.\n"), player_names[playernum], '\x84', M_GetText("Blue Team"), '\x80'); + } + else if (NetPacket.packet.newteam == 1) + { + if (G_TagGametype()) + CONS_Printf(M_GetText("%s is now IT!\n"), player_names[playernum]); + else + CONS_Printf(M_GetText("%s switched to the %c%s%c.\n"), player_names[playernum], '\x85', M_GetText("Red Team"), '\x80'); + } + else if (NetPacket.packet.newteam == 2) + { + if (G_TagGametype()) + CONS_Printf(M_GetText("%s is no longer IT!\n"), player_names[playernum]); + else + CONS_Printf(M_GetText("%s switched to the %c%s%c.\n"), player_names[playernum], '\x84', M_GetText("Blue Team"), '\x80'); + } + else if (NetPacket.packet.newteam == 3) + CONS_Printf(M_GetText("%s entered the game.\n"), player_names[playernum]); + else + CONS_Printf(M_GetText("%s became a spectator.\n"), player_names[playernum]); + + //reset view if you are changed, or viewing someone who was changed. + if (playernum == consoleplayer || displayplayer == playernum) + displayplayer = consoleplayer; + + if (G_GametypeHasTeams()) + { + if (NetPacket.packet.newteam) + { + if (playernum == consoleplayer) //CTF and Team Match colors. + CV_SetValue(&cv_playercolor, NetPacket.packet.newteam + 5); + else if (playernum == secondarydisplayplayer) + CV_SetValue(&cv_playercolor2, NetPacket.packet.newteam + 5); + } + } + + // Clear player score and rings if a spectator. + if (players[playernum].spectator) + { + players[playernum].score = 0; + players[playernum].health = 1; + if (players[playernum].mo) + players[playernum].mo->health = 1; + } + + // In tag, check to see if you still have a game. + if (G_TagGametype()) + P_CheckSurvivors(); +} + +// +// Attempts to make password system a little sane without +// rewriting the entire goddamn XD_file system +// +#include "md5.h" +static void D_MD5PasswordPass(const UINT8 *buffer, size_t len, const char *salt, void *dest) +{ +#ifdef NOMD5 + (void)buffer; + (void)len; + (void)salt; + memset(dest, 0, 16); +#else + XBOXSTATIC char tmpbuf[256]; + + if (len > 256-strlen(salt)) + len = 256-strlen(salt); + memcpy(tmpbuf, buffer, len); + strcpy(&tmpbuf[len], salt); + len += strlen(salt); + if (len < 256) + memset(&tmpbuf[len],0,256-len); + + // Yes, we intentionally md5 the ENTIRE buffer regardless of size... + md5_buffer(tmpbuf, 256, dest); +#endif +} + +#define BASESALT "basepasswordstorage" +static UINT8 adminpassmd5[16]; + +void D_SetPassword(const char *pw) +{ + D_MD5PasswordPass((const UINT8 *)pw, strlen(pw), BASESALT, &adminpassmd5); +} + +// Remote Administration +static void Command_Changepassword_f(void) +{ +#ifdef NOMD5 + // If we have no MD5 support then completely disable XD_LOGIN responses for security. + CONS_Alert(CONS_NOTICE, "Remote administration commands are not supported in this build.\n"); +#else + if (!server) // cannot change remotely + { + CONS_Printf(M_GetText("Only the server can use this.\n")); + return; + } + + if (COM_Argc() != 2) + { + CONS_Printf(M_GetText("password : change remote admin password\n")); + return; + } + + D_SetPassword(COM_Argv(1)); + CONS_Printf(M_GetText("Password set.\n")); +#endif +} + +static void Command_Login_f(void) +{ +#ifdef NOMD5 + // If we have no MD5 support then completely disable XD_LOGIN responses for security. + CONS_Alert(CONS_NOTICE, "Remote administration commands are not supported in this build.\n"); +#else + XBOXSTATIC UINT8 finalmd5[16]; + const char *pw; + + // If the server uses login, it will effectively just remove admin privileges + // from whoever has them. This is good. + if (COM_Argc() != 2) + { + CONS_Printf(M_GetText("login : Administrator login\n")); + return; + } + + pw = COM_Argv(1); + + // Do the base pass to get what the server has (or should?) + D_MD5PasswordPass((const UINT8 *)pw, strlen(pw), BASESALT, &finalmd5); + + // Do the final pass to get the comparison the server will come up with + D_MD5PasswordPass(finalmd5, 16, va("PNUM%02d", consoleplayer), &finalmd5); + + CONS_Printf(M_GetText("Sending login... (Notice only given if password is correct.)\n")); + + SendNetXCmd(XD_LOGIN, finalmd5, 16); +#endif +} + +static void Got_Login(UINT8 **cp, INT32 playernum) +{ +#ifdef NOMD5 + // If we have no MD5 support then completely disable XD_LOGIN responses for security. + (void)cp; + (void)playernum; +#else + UINT8 sentmd5[16], finalmd5[16]; + + READMEM(*cp, sentmd5, 16); + + if (!server) + return; + + // Do the final pass to compare with the sent md5 + D_MD5PasswordPass(adminpassmd5, 16, va("PNUM%02d", playernum), &finalmd5); + + if (!memcmp(sentmd5, finalmd5, 16)) + { + CONS_Printf(M_GetText("%s passed authentication.\n"), player_names[playernum]); + COM_BufInsertText(va("verify %d\n", playernum)); // do this immediately + } + else + CONS_Printf(M_GetText("Password from %s failed.\n"), player_names[playernum]); +#endif +} + +static void Command_Verify_f(void) +{ + XBOXSTATIC char buf[8]; // Should be plenty + char *temp; + INT32 playernum; + + if (!server) + { + CONS_Printf(M_GetText("Only the server can use this.\n")); + return; + } + + if (COM_Argc() != 2) + { + CONS_Printf(M_GetText("verify : give admin privileges to a node\n")); + return; + } + + strlcpy(buf, COM_Argv(1), sizeof (buf)); + + playernum = atoi(buf); + + temp = buf; + + WRITEUINT8(temp, playernum); + + if (playeringame[playernum]) + SendNetXCmd(XD_VERIFIED, buf, 1); +} + +static void Got_Verification(UINT8 **cp, INT32 playernum) +{ + INT16 num = READUINT8(*cp); + + if (playernum != serverplayer) // it's not from the server (hacker or bug) + { + CONS_Alert(CONS_WARNING, M_GetText("Illegal verification received from %s (serverplayer is %s)\n"), player_names[playernum], player_names[serverplayer]); + if (server) + { + XBOXSTATIC UINT8 buf[2]; + + buf[0] = (UINT8)playernum; + buf[1] = KICK_MSG_CON_FAIL; + SendNetXCmd(XD_KICK, &buf, 2); + } + return; + } + + adminplayer = num; + + if (num != consoleplayer) + return; + + CONS_Printf(M_GetText("You are now a server administrator.\n")); +} + +static void Command_MotD_f(void) +{ + size_t i, j; + char *mymotd; + + if ((j = COM_Argc()) < 2) + { + CONS_Printf(M_GetText("motd : Set a message that clients see upon join.\n")); + return; + } + + if (!(server || (adminplayer == consoleplayer))) + { + CONS_Printf(M_GetText("Only the server or a remote admin can use this.\n")); + return; + } + + mymotd = Z_Malloc(sizeof(motd), PU_STATIC, NULL); + + strlcpy(mymotd, COM_Argv(1), sizeof motd); + for (i = 2; i < j; i++) + { + strlcat(mymotd, " ", sizeof motd); + strlcat(mymotd, COM_Argv(i), sizeof motd); + } + + // Disallow non-printing characters and semicolons. + for (i = 0; mymotd[i] != '\0'; i++) + if (!isprint(mymotd[i]) || mymotd[i] == ';') + { + Z_Free(mymotd); + return; + } + + if ((netgame || multiplayer) && !server) + SendNetXCmd(XD_SETMOTD, mymotd, sizeof(motd)); + else + { + strcpy(motd, mymotd); + CONS_Printf(M_GetText("Message of the day set.\n")); + } + + Z_Free(mymotd); +} + +static void Got_MotD_f(UINT8 **cp, INT32 playernum) +{ + char *mymotd = Z_Malloc(sizeof(motd), PU_STATIC, NULL); + INT32 i; + boolean kick = false; + + READSTRINGN(*cp, mymotd, sizeof(motd)); + + // Disallow non-printing characters and semicolons. + for (i = 0; mymotd[i] != '\0'; i++) + if (!isprint(mymotd[i]) || mymotd[i] == ';') + kick = true; + + if ((playernum != serverplayer && playernum != adminplayer) || kick) + { + CONS_Alert(CONS_WARNING, M_GetText("Illegal motd change received from %s\n"), player_names[playernum]); + if (server) + { + XBOXSTATIC UINT8 buf[2]; + + buf[0] = (UINT8)playernum; + buf[1] = KICK_MSG_CON_FAIL; + SendNetXCmd(XD_KICK, &buf, 2); + } + + Z_Free(mymotd); + return; + } + + strcpy(motd, mymotd); + + CONS_Printf(M_GetText("Message of the day set.\n")); + + Z_Free(mymotd); +} + +static void Command_RunSOC(void) +{ + const char *fn; + XBOXSTATIC char buf[255]; + size_t length = 0; + + if (COM_Argc() != 2) + { + CONS_Printf(M_GetText("runsoc or : run a soc\n")); + return; + } + else + fn = COM_Argv(1); + + if (netgame && !(server || consoleplayer == adminplayer)) + { + CONS_Printf(M_GetText("Only the server or a remote admin can use this.\n")); + return; + } + + if (!(netgame || multiplayer)) + { + if (!P_RunSOC(fn)) + CONS_Printf(M_GetText("Could not find SOC.\n")); + else + G_SetGameModified(multiplayer); + return; + } + + nameonly(strcpy(buf, fn)); + length = strlen(buf)+1; + + SendNetXCmd(XD_RUNSOC, buf, length); +} + +static void Got_RunSOCcmd(UINT8 **cp, INT32 playernum) +{ + char filename[256]; + filestatus_t ncs = FS_NOTFOUND; + + if (playernum != serverplayer && playernum != adminplayer) + { + CONS_Alert(CONS_WARNING, M_GetText("Illegal runsoc command received from %s\n"), player_names[playernum]); + if (server) + { + XBOXSTATIC UINT8 buf[2]; + + buf[0] = (UINT8)playernum; + buf[1] = KICK_MSG_CON_FAIL; + SendNetXCmd(XD_KICK, &buf, 2); + } + return; + } + + READSTRINGN(*cp, filename, 255); + + // Maybe add md5 support? + if (strstr(filename, ".soc") != NULL) + { + ncs = findfile(filename,NULL,true); + + if (ncs != FS_FOUND) + { + Command_ExitGame_f(); + if (ncs == FS_NOTFOUND) + { + CONS_Printf(M_GetText("The server tried to add %s,\nbut you don't have this file.\nYou need to find it in order\nto play on this server.\n"), filename); + M_StartMessage(va("The server added a file\n(%s)\nthat you do not have.\n\nPress ESC\n",filename), NULL, MM_NOTHING); + } + else + { + CONS_Printf(M_GetText("Unknown error finding soc file (%s) the server added.\n"), filename); + M_StartMessage(va("Unknown error trying to load a file\nthat the server added\n(%s).\n\nPress ESC\n",filename), NULL, MM_NOTHING); + } + return; + } + } + + P_RunSOC(filename); + G_SetGameModified(true); +} + +/** Adds a pwad at runtime. + * Searches for sounds, maps, music, new images. + */ +static void Command_Addfile(void) +{ + const char *fn, *p; + XBOXSTATIC char buf[256]; + char *buf_p = buf; + INT32 i; + + if (COM_Argc() != 2) + { + CONS_Printf(M_GetText("addfile : load wad file\n")); + return; + } + else + fn = COM_Argv(1); + + // Disallow non-printing characters and semicolons. + for (i = 0; fn[i] != '\0'; i++) + if (!isprint(fn[i]) || fn[i] == ';') + return; + + if (!W_VerifyNMUSlumps(fn)) + { + // ... But only so long as they contain nothing more then music and sprites. + if (netgame && !(server || adminplayer == consoleplayer)) + { + CONS_Printf(M_GetText("Only the server or a remote admin can use this.\n")); + return; + } + G_SetGameModified(multiplayer); + } + + // Add file on your client directly if it is trivial, or you aren't in a netgame. + if (!(netgame || multiplayer) || W_VerifyNMUSlumps(fn)) + { + P_AddWadFile(fn, NULL); + return; + } + + p = fn+strlen(fn); + while(p > fn && *p != '\\' && *p != '/' && *p != ':') + --p; + WRITESTRINGN(buf_p,p,240); + + { + UINT8 md5sum[16]; +#ifdef NOMD5 + memset(md5sum,0,16); +#else + FILE *fhandle; + + fhandle = fopen(fn, "rb"); + + if (fhandle) + { + tic_t t = I_GetTime(); + CONS_Debug(DBG_SETUP, "Making MD5 for %s\n",fn); + md5_stream(fhandle, md5sum); + CONS_Debug(DBG_SETUP, "MD5 calc for %s took %f second\n", fn, (float)(I_GetTime() - t)/TICRATE); + fclose(fhandle); + } + else + { + CONS_Printf(M_GetText("File %s not found.\n"), fn); + return; + } +#endif + WRITEMEM(buf_p, md5sum, 16); + } + + if (adminplayer == consoleplayer) // Request to add file + SendNetXCmd(XD_REQADDFILE, buf, buf_p - buf); + else + SendNetXCmd(XD_ADDFILE, buf, buf_p - buf); +} + +#ifdef DELFILE +/** removes the last added pwad at runtime. + * Searches for sounds, maps, music and images to remove + */ +static void Command_Delfile(void) +{ + if (gamestate == GS_LEVEL) + { + CONS_Printf(M_GetText("You must NOT be in a level to use this.\n")); + return; + } + + if (netgame && !(server || adminplayer == consoleplayer)) + { + CONS_Printf(M_GetText("Only the server or a remote admin can use this.\n")); + return; + } + + if (numwadfiles <= mainwads) + { + CONS_Printf(M_GetText("No additional WADs are loaded.\n")); + return; + } + + if (!(netgame || multiplayer)) + { + P_DelWadFile(); + if (mainwads == numwadfiles && modifiedgame) + modifiedgame = false; + return; + } + + SendNetXCmd(XD_DELFILE, NULL, 0); +} +#endif + +static void Got_RequestAddfilecmd(UINT8 **cp, INT32 playernum) +{ + char filename[241]; + filestatus_t ncs = FS_NOTFOUND; + UINT8 md5sum[16]; + boolean kick = false; + INT32 i; + + READSTRINGN(*cp, filename, 240); + READMEM(*cp, md5sum, 16); + + // Only the server processes this message. + if (!server) + return; + + // Disallow non-printing characters and semicolons. + for (i = 0; filename[i] != '\0'; i++) + if (!isprint(filename[i]) || filename[i] == ';') + kick = true; + + if ((playernum != serverplayer && playernum != adminplayer) || kick) + { + XBOXSTATIC UINT8 buf[2]; + + CONS_Alert(CONS_WARNING, M_GetText("Illegal addfile command received from %s\n"), player_names[playernum]); + + buf[0] = (UINT8)playernum; + buf[1] = KICK_MSG_CON_FAIL; + SendNetXCmd(XD_KICK, &buf, 2); + return; + } + + ncs = findfile(filename,md5sum,true); + + if (ncs != FS_FOUND) + { + char message[256]; + + if (ncs == FS_NOTFOUND) + sprintf(message, M_GetText("The server doesn't have %s\n"), filename); + else if (ncs == FS_MD5SUMBAD) + sprintf(message, M_GetText("Checksum mismatch on %s\n"), filename); + else + sprintf(message, M_GetText("Unknown error finding wad file (%s)\n"), filename); + + CONS_Printf("%s",message); + + if (adminplayer) + COM_BufAddText(va("sayto %d %s", adminplayer, message)); + + return; + } + + COM_BufAddText(va("addfile %s\n", filename)); +} + +#ifdef DELFILE +static void Got_Delfilecmd(UINT8 **cp, INT32 playernum) +{ + if (playernum != serverplayer && playernum != adminplayer) + { + CONS_Alert(CONS_WARNING, M_GetText("Illegal delfile command received from %s\n"), player_names[playernum]); + if (server) + { + XBOXSTATIC UINT8 buf[2]; + + buf[0] = (UINT8)playernum; + buf[1] = KICK_MSG_CON_FAIL; + SendNetXCmd(XD_KICK, &buf, 2); + } + return; + } + (void)cp; + + if (numwadfiles <= mainwads) //sanity + return; + + P_DelWadFile(); + if (mainwads == numwadfiles && modifiedgame) + modifiedgame = false; +} +#endif + +static void Got_Addfilecmd(UINT8 **cp, INT32 playernum) +{ + char filename[241]; + filestatus_t ncs = FS_NOTFOUND; + UINT8 md5sum[16]; + + READSTRINGN(*cp, filename, 240); + READMEM(*cp, md5sum, 16); + + if (playernum != serverplayer) + { + CONS_Alert(CONS_WARNING, M_GetText("Illegal addfile command received from %s\n"), player_names[playernum]); + if (server) + { + XBOXSTATIC UINT8 buf[2]; + + buf[0] = (UINT8)playernum; + buf[1] = KICK_MSG_CON_FAIL; + SendNetXCmd(XD_KICK, &buf, 2); + } + return; + } + + ncs = findfile(filename,md5sum,true); + + if (ncs != FS_FOUND) + { + Command_ExitGame_f(); + if (ncs == FS_NOTFOUND) + { + CONS_Printf(M_GetText("The server tried to add %s,\nbut you don't have this file.\nYou need to find it in order\nto play on this server."), filename); + M_StartMessage(va("The server added a file \n(%s)\nthat you do not have.\n\nPress ESC\n",filename), NULL, MM_NOTHING); + } + else if (ncs == FS_MD5SUMBAD) + { + CONS_Printf(M_GetText("Checksum mismatch while loading %s.\nMake sure you have the copy of\nthis file that the server has.\n"), filename); + M_StartMessage(va("Checksum mismatch while loading \n%s.\nThe server seems to have a\ndifferent version of this file.\n\nPress ESC\n",filename), NULL, MM_NOTHING); + } + else + { + CONS_Printf(M_GetText("Unknown error finding wad file (%s) the server added.\n"), filename); + M_StartMessage(va("Unknown error trying to load a file\nthat the server added \n(%s).\n\nPress ESC\n",filename), NULL, MM_NOTHING); + } + return; + } + + P_AddWadFile(filename, NULL); + G_SetGameModified(true); +} + +static void Command_ListWADS_f(void) +{ + INT32 i = numwadfiles; + char *tempname; + CONS_Printf(M_GetText("There are %d wads loaded:\n"),numwadfiles); + for (i--; i; i--) + { + nameonly(tempname = va("%s", wadfiles[i]->filename)); + if (i >= mainwads) + CONS_Printf(" %.2d: %s\n", i, tempname); + else + CONS_Printf("* %.2d: %s\n", i, tempname); + } + CONS_Printf(" IWAD: %s\n", wadfiles[0]->filename); +} + +// ========================================================================= +// MISC. COMMANDS +// ========================================================================= + +/** Prints program version. + */ +static void Command_Version_f(void) +{ + CONS_Printf("Sonic Robo Blast 2 %s (%s %s %s)\n", VERSIONSTRING, compdate, comptime, comprevision); +} + +#ifdef UPDATE_ALERT +static void Command_ModDetails_f(void) +{ + CONS_Printf(M_GetText("Mod ID: %d\nMod Version: %d\nCode Base:%d\n"), MODID, MODVERSION, CODEBASE); +} +#endif + +// Returns current gametype being used. +// +static void Command_ShowGametype_f(void) +{ + CONS_Printf(M_GetText("Current gametype is %d\n"), gametype); +} + +// Moves the NiGHTS player to another axis within the current mare +// Only for development purposes. +// +static void Command_JumpToAxis_f(void) +{ + if (!cv_debug) + CONS_Printf(M_GetText("DEVMODE must be enabled.\n")); + + if (COM_Argc() != 2) + { + CONS_Printf(M_GetText("jumptoaxis : Jump to axis within current mare.\n")); + return; + } + + P_TransferToAxis(&players[consoleplayer], atoi(COM_Argv(1))); +} + +/** Plays the intro. + */ +static void Command_Playintro_f(void) +{ + if (netgame) + return; + + F_StartIntro(); +} + +/** Quits the game immediately. + */ +FUNCNORETURN static ATTRNORETURN void Command_Quit_f(void) +{ + I_Quit(); +} + +void ItemFinder_OnChange(void) +{ + if (!cv_itemfinder.value) + return; // it's fine. + + if (!M_SecretUnlocked(SECRET_ITEMFINDER)) + { + CONS_Printf(M_GetText("You haven't earned this yet.\n")); + CV_StealthSetValue(&cv_itemfinder, 0); + return; + } + else if (netgame || multiplayer) + { + CONS_Printf(M_GetText("This only works in single player.\n")); + CV_StealthSetValue(&cv_itemfinder, 0); + return; + } +} + +/** Deals with a pointlimit change by printing the change to the console. + * If the gametype is single player, cooperative, or race, the pointlimit is + * silently disabled again. + * + * Timelimit and pointlimit can be used at the same time. + * + * We don't check immediately for the pointlimit having been reached, + * because you would get "caught" when turning it up in the menu. + * \sa cv_pointlimit, TimeLimit_OnChange + * \author Graue + */ +static void PointLimit_OnChange(void) +{ + // Don't allow pointlimit in Single Player/Co-Op/Race! + if (server && Playing() && G_PlatformGametype()) + { + if (cv_pointlimit.value) + CV_StealthSetValue(&cv_pointlimit, 0); + return; + } + + if (cv_pointlimit.value) + { + CONS_Printf(M_GetText("Levels will end after %s scores %d point%s.\n"), + G_GametypeHasTeams() ? M_GetText("a team") : M_GetText("someone"), + cv_pointlimit.value, + cv_pointlimit.value > 1 ? "s" : ""); + } + else if (netgame || multiplayer) + CONS_Printf(M_GetText("Point limit disabled\n")); +} + +static void NumLaps_OnChange(void) +{ + // Just don't be verbose + if (gametype == GT_RACE) + CONS_Printf(M_GetText("Number of laps set to %d\n"), cv_numlaps.value); +} + +static void NetTimeout_OnChange(void) +{ + connectiontimeout = (tic_t)cv_nettimeout.value; +} + +UINT32 timelimitintics = 0; + +/** Deals with a timelimit change by printing the change to the console. + * If the gametype is single player, cooperative, or race, the timelimit is + * silently disabled again. + * + * Timelimit and pointlimit can be used at the same time. + * + * \sa cv_timelimit, PointLimit_OnChange + */ +static void TimeLimit_OnChange(void) +{ + // Don't allow timelimit in Single Player/Co-Op/Race! + if (server && Playing() && cv_timelimit.value != 0 && G_PlatformGametype()) + { + CV_SetValue(&cv_timelimit, 0); + return; + } + + if (cv_timelimit.value != 0) + { + CONS_Printf(M_GetText("Levels will end after %d minute%s.\n"),cv_timelimit.value,cv_timelimit.value == 1 ? "" : "s"); // Graue 11-17-2003 + timelimitintics = cv_timelimit.value * 60 * TICRATE; + + //add hidetime for tag too! + if (G_TagGametype()) + timelimitintics += hidetime * TICRATE; + + // Note the deliberate absence of any code preventing + // pointlimit and timelimit from being set simultaneously. + // Some people might like to use them together. It works. + } + else if (netgame || multiplayer) + CONS_Printf(M_GetText("Time limit disabled\n")); +} + +/** Adjusts certain settings to match a changed gametype. + * + * \param lastgametype The gametype we were playing before now. + * \sa D_MapChange + * \author Graue + * \todo Get rid of the hardcoded stuff, ugly stuff, etc. + */ +void D_GameTypeChanged(INT32 lastgametype) +{ + if (netgame) + { + INT32 j; + const char *oldgt = NULL, *newgt = NULL; + for (j = 0; gametype_cons_t[j].strvalue; j++) + { + if (gametype_cons_t[j].value == lastgametype) + oldgt = gametype_cons_t[j].strvalue; + if (gametype_cons_t[j].value == gametype) + newgt = gametype_cons_t[j].strvalue; + } + if (oldgt && newgt) + CONS_Printf(M_GetText("Gametype was changed from %s to %s\n"), oldgt, newgt); + } + // Only do the following as the server, not as remote admin. + // There will always be a server, and this only needs to be done once. + if (server && (multiplayer || netgame)) + { + if (gametype == GT_COMPETITION || gametype == GT_COOP) + CV_SetValue(&cv_itemrespawn, 0); + else if (!cv_itemrespawn.changed) + CV_SetValue(&cv_itemrespawn, 1); + + switch (gametype) + { +#ifdef CHAOSISNOTDEADYET + case GT_CHAOS: + if (!cv_timelimit.changed && !cv_pointlimit.changed) // user hasn't changed limits + { + // default settings for chaos: timelimit 2 mins, no pointlimit + CV_SetValue(&cv_pointlimit, 0); + CV_SetValue(&cv_timelimit, 2); + } + if (!cv_itemrespawntime.changed) + CV_SetValue(&cv_itemrespawntime, 90); // respawn sparingly in chaos + break; +#endif + case GT_MATCH: + case GT_TEAMMATCH: + if (!cv_timelimit.changed && !cv_pointlimit.changed) // user hasn't changed limits + { + // default settings for match: timelimit 10 mins, no pointlimit + CV_SetValue(&cv_pointlimit, 0); + CV_SetValue(&cv_timelimit, 10); + } + if (!cv_itemrespawntime.changed) + CV_Set(&cv_itemrespawntime, cv_itemrespawntime.defaultvalue); // respawn normally + break; + case GT_TAG: + case GT_HIDEANDSEEK: + if (!cv_timelimit.changed && !cv_pointlimit.changed) // user hasn't changed limits + { + // default settings for tag: 5 mins, no pointlimit + // Note that tag mode also uses an alternate timing mechanism in tandem with timelimit. + CV_SetValue(&cv_timelimit, 5); + CV_SetValue(&cv_pointlimit, 0); + } + if (!cv_itemrespawntime.changed) + CV_Set(&cv_itemrespawntime, cv_itemrespawntime.defaultvalue); // respawn normally + break; + case GT_CTF: + if (!cv_timelimit.changed && !cv_pointlimit.changed) // user hasn't changed limits + { + // default settings for CTF: no timelimit, pointlimit 5 + CV_SetValue(&cv_timelimit, 0); + CV_SetValue(&cv_pointlimit, 5); + } + if (!cv_itemrespawntime.changed) + CV_Set(&cv_itemrespawntime, cv_itemrespawntime.defaultvalue); // respawn normally + break; + } + } + else if (!multiplayer && !netgame) + { + gametype = GT_COOP; + // These shouldn't matter anymore + //CV_Set(&cv_itemrespawntime, cv_itemrespawntime.defaultvalue); + //CV_SetValue(&cv_itemrespawn, 0); + } + + // reset timelimit and pointlimit in race/coop, prevent stupid cheats + if (server) + { + if (G_PlatformGametype()) + { + if (cv_timelimit.value) + CV_SetValue(&cv_timelimit, 0); + if (cv_pointlimit.value) + CV_SetValue(&cv_pointlimit, 0); + } + else if ((cv_pointlimit.changed || cv_timelimit.changed) && cv_pointlimit.value) + { + if (lastgametype != GT_CTF && gametype == GT_CTF) + CV_SetValue(&cv_pointlimit, cv_pointlimit.value / 500); + else if (lastgametype == GT_CTF && gametype != GT_CTF) + CV_SetValue(&cv_pointlimit, cv_pointlimit.value * 500); + } + } + + // When swapping to a gametype that supports spectators, + // make everyone a spectator initially. + if (!splitscreen && (G_GametypeHasSpectators())) + { + INT32 i; + for (i = 0; i < MAXPLAYERS; i++) + if (playeringame[i]) + { + players[i].ctfteam = 0; + players[i].spectator = true; + } + } + + // don't retain teams in other modes or between changes from ctf to team match. + // also, stop any and all forms of team scrambling that might otherwise take place. + if (G_GametypeHasTeams()) + { + INT32 i; + for (i = 0; i < MAXPLAYERS; i++) + if (playeringame[i]) + players[i].ctfteam = 0; + + if (server || (adminplayer == consoleplayer)) + { + CV_StealthSetValue(&cv_teamscramble, 0); + teamscramble = 0; + } + } +} + +static void Ringslinger_OnChange(void) +{ + if (!M_SecretUnlocked(SECRET_PANDORA) && !netgame && cv_ringslinger.value && !cv_debug) + { + CONS_Printf(M_GetText("You haven't earned this yet.\n")); + CV_StealthSetValue(&cv_ringslinger, 0); + return; + } + + if (cv_ringslinger.value) // Only if it's been turned on + G_SetGameModified(multiplayer); +} + +static void Gravity_OnChange(void) +{ + if (!M_SecretUnlocked(SECRET_PANDORA) && !netgame && !cv_debug + && strcmp(cv_gravity.string, cv_gravity.defaultvalue)) + { + CONS_Printf(M_GetText("You haven't earned this yet.\n")); + CV_StealthSet(&cv_gravity, cv_gravity.defaultvalue); + return; + } +#ifndef NETGAME_GRAVITY + if(netgame) + { + CV_StealthSet(&cv_gravity, cv_gravity.defaultvalue); + return; + } +#endif + + if (!CV_IsSetToDefault(&cv_gravity)) + G_SetGameModified(multiplayer); + gravity = cv_gravity.value; +} + +static void SoundTest_OnChange(void) +{ + if (cv_soundtest.value < 0) + { + CV_SetValue(&cv_soundtest, NUMSFX-1); + return; + } + + if (cv_soundtest.value >= NUMSFX) + { + CV_SetValue(&cv_soundtest, 0); + return; + } + + S_StopSounds(); + S_StartSound(NULL, cv_soundtest.value); +} + +static void AutoBalance_OnChange(void) +{ + autobalance = (INT16)cv_autobalance.value; +} + +static void TeamScramble_OnChange(void) +{ + INT16 i = 0, j = 0, playercount = 0; + boolean repick = true; + INT32 blue = 0, red = 0; + INT32 maxcomposition = 0; + INT16 newteam = 0; + INT32 retries = 0; + boolean success = false; + + // Don't trigger outside level or intermission! + if (!(gamestate == GS_LEVEL || gamestate == GS_INTERMISSION)) + return; + + if (!cv_teamscramble.value) + teamscramble = 0; + + if (!G_GametypeHasTeams() && (server || consoleplayer == adminplayer)) + { + CONS_Alert(CONS_NOTICE, M_GetText("This command cannot be used in this gametype.\n")); + CV_StealthSetValue(&cv_teamscramble, 0); + return; + } + + // If a team scramble is already in progress, do not allow another one to be started! + if (teamscramble) + return; + +retryscramble: + + // Clear related global variables. These will get used again in p_tick.c/y_inter.c as the teams are scrambled. + memset(&scrambleplayers, 0, sizeof(scrambleplayers)); + memset(&scrambleteams, 0, sizeof(scrambleplayers)); + scrambletotal = scramblecount = 0; + blue = red = maxcomposition = newteam = playercount = 0; + repick = true; + + // Put each player's node in the array. + for (i = 0; i < MAXPLAYERS; i++) + { + if (playeringame[i] && !players[i].spectator) + { + scrambleplayers[playercount] = i; + playercount++; + } + } + + if (playercount < 2) + { + CV_StealthSetValue(&cv_teamscramble, 0); + return; // Don't scramble one or zero players. + } + + // Randomly place players on teams. + if (cv_teamscramble.value == 1) + { + maxcomposition = playercount / 2; + + // Now randomly assign players to teams. + // If the teams get out of hand, assign the rest to the other team. + for (i = 0; i < playercount; i++) + { + if (repick) + newteam = (INT16)((M_Random() % 2) + 1); + + // One team has the most players they can get, assign the rest to the other team. + if (red == maxcomposition || blue == maxcomposition) + { + if (red == maxcomposition) + newteam = 2; + else if (blue == maxcomposition) + newteam = 1; + + repick = false; + } + + scrambleteams[i] = newteam; + + if (newteam == 1) + red++; + else + blue++; + } + } + else if (cv_teamscramble.value == 2) // Same as before, except split teams based on current score. + { + // Now, sort the array based on points scored. + for (i = 1; i < playercount; i++) + { + for (j = i; j < playercount; j++) + { + INT16 tempplayer = 0; + + if ((players[scrambleplayers[i-1]].score > players[scrambleplayers[j]].score)) + { + tempplayer = scrambleplayers[i-1]; + scrambleplayers[i-1] = scrambleplayers[j]; + scrambleplayers[j] = tempplayer; + } + } + } + + // Now assign players to teams based on score. Scramble in pairs. + // If there is an odd number, one team will end up with the unlucky slob who has no points. =( + for (i = 0; i < playercount; i++) + { + if (repick) + { + newteam = (INT16)((M_Random() % 2) + 1); + repick = false; + } + else + { + // We will only randomly pick the team for the first guy. + // Otherwise, just alternate back and forth, distributing players. + if (newteam == 1) + newteam = 2; + else + newteam = 1; + } + + scrambleteams[i] = newteam; + } + } + + // Check to see if our random selection actually + // changed anybody. If not, we run through and try again. + for (i = 0; i < playercount; i++) + { + if (players[scrambleplayers[i]].ctfteam != scrambleteams[i]) + success = true; + } + + if (!success && retries < 5) + { + retries++; + goto retryscramble; //try again + } + + // Display a witty message, but only during scrambles specifically triggered by an admin. + if (cv_teamscramble.value) + { + scrambletotal = playercount; + teamscramble = (INT16)cv_teamscramble.value; + + if (!(gamestate == GS_INTERMISSION && cv_scrambleonchange.value)) + CONS_Printf(M_GetText("Teams will be scrambled next round.\n")); + } +} + +static void Hidetime_OnChange(void) +{ + if (Playing() && G_TagGametype() && leveltime >= (hidetime * TICRATE)) + { + // Don't allow hidetime changes after it expires. + CV_StealthSetValue(&cv_hidetime, hidetime); + return; + } + hidetime = cv_hidetime.value; + + //uh oh, gotta change timelimitintics now too + if (G_TagGametype()) + timelimitintics = (cv_timelimit.value * 60 * TICRATE) + (hidetime * TICRATE); +} + +static void Command_Showmap_f(void) +{ + if (gamestate == GS_LEVEL) + { + if (mapheaderinfo[gamemap-1]->actnum) + CONS_Printf("%s (%d): %s %d\n", G_BuildMapName(gamemap), gamemap, mapheaderinfo[gamemap-1]->lvlttl, mapheaderinfo[gamemap-1]->actnum); + else + CONS_Printf("%s (%d): %s\n", G_BuildMapName(gamemap), gamemap, mapheaderinfo[gamemap-1]->lvlttl); + } + else + CONS_Printf(M_GetText("You must be in a level to use this.\n")); +} + +static void Command_ExitLevel_f(void) +{ + if (!(netgame || (multiplayer && gametype != GT_COOP)) && !cv_debug) + CONS_Printf(M_GetText("This only works in a netgame.\n")); + else if (!(server || (adminplayer == consoleplayer))) + CONS_Printf(M_GetText("Only the server or a remote admin can use this.\n")); + else if (gamestate != GS_LEVEL || demoplayback) + CONS_Printf(M_GetText("You must be in a level to use this.\n")); + else + SendNetXCmd(XD_EXITLEVEL, NULL, 0); +} + +static void Got_ExitLevelcmd(UINT8 **cp, INT32 playernum) +{ + (void)cp; + + // Ignore duplicate XD_EXITLEVEL commands. + if (gameaction == ga_completed) + return; + + if (playernum != serverplayer && playernum != adminplayer) + { + CONS_Alert(CONS_WARNING, M_GetText("Illegal exitlevel command received from %s\n"), player_names[playernum]); + if (server) + { + XBOXSTATIC UINT8 buf[2]; + + buf[0] = (UINT8)playernum; + buf[1] = KICK_MSG_CON_FAIL; + SendNetXCmd(XD_KICK, &buf, 2); + } + return; + } + + G_ExitLevel(); +} + +/** Prints the number of the displayplayer. + * + * \todo Possibly remove this; it was useful for debugging at one point. + */ +static void Command_Displayplayer_f(void) +{ + CONS_Printf(M_GetText("Displayplayer is %d\n"), displayplayer); +} + +static void Command_Skynum_f(void) +{ + if (!cv_debug) + { + CONS_Printf(M_GetText("DEVMODE must be enabled.\n")); + CONS_Printf(M_GetText("If you want to change the sky interactively on a map, use the linedef executor feature instead.\n")); + return; + } + + if (netgame || multiplayer) + { + CONS_Printf(M_GetText("This only works in single player.\n")); + return; + } + + if (COM_Argc() != 2) + { + CONS_Printf(M_GetText("skynum : change the sky\n")); + return; + } + + CONS_Printf(M_GetText("Previewing sky %s...\n"), COM_Argv(1)); + + P_SetupLevelSky(atoi(COM_Argv(1)), false); +} + +static void Command_Tunes_f(void) +{ + const char *tunearg; + UINT16 tune, track = 0; + const size_t argc = COM_Argc(); + + if (argc < 2) //tunes slot ... + { + CONS_Printf("tunes :\n"); + CONS_Printf(M_GetText("Play a music slot at a set speed (\"1\" being normal speed).\n")); + CONS_Printf(M_GetText("If the format supports multiple songs, you can specify which one to play.\n")); + CONS_Printf(M_GetText("The current tune is: %d\nThe current track is: %d\n"), + (mapmusic & MUSIC_SONGMASK), ((mapmusic & MUSIC_TRACKMASK) >> MUSIC_TRACKSHIFT)); + return; + } + + tunearg = COM_Argv(1); + tune = (UINT16)atoi(tunearg); + track = 0; + + if (!strcasecmp(tunearg, "default")) + { + tune = mapheaderinfo[gamemap-1]->musicslot; + track = mapheaderinfo[gamemap-1]->musicslottrack; + } + else if (toupper(tunearg[0]) >= 'A' && toupper(tunearg[0]) <= 'Z') + tune = (UINT16)M_MapNumber(tunearg[0], tunearg[1]); + + if (tune >= NUMMUSIC) + { + CONS_Alert(CONS_NOTICE, M_GetText("Valid slots are 1 to %d, or 0 to stop music\n"), NUMMUSIC - 1); + return; + } + + if (argc > 3) + track = (UINT16)atoi(COM_Argv(3))-1; + + mapmusic = tune | (track << MUSIC_TRACKSHIFT); + + if (tune == mus_None) + S_StopMusic(); + else + S_ChangeMusic(mapmusic, true); + + if (argc > 2) + { + float speed = (float)atof(COM_Argv(2)); + if (speed > 0.0f) + S_SpeedMusic(speed); + } +} + +/** Quits a game and returns to the title screen. + * + */ +void Command_ExitGame_f(void) +{ + INT32 i; + + D_QuitNetGame(); + CL_Reset(); + CV_ClearChangedFlags(); + + for (i = 0; i < MAXPLAYERS; i++) + CL_ClearPlayer(i); + + splitscreen = false; + SplitScreen_OnChange(); + botingame = false; + botskin = 0; + cv_debug = 0; + emeralds = 0; + + if (!modeattacking) + D_StartTitle(); +} + +void Command_Retry_f(void) +{ + if (!(gamestate == GS_LEVEL || gamestate == GS_INTERMISSION)) + CONS_Printf(M_GetText("You must be in a level to use this.\n")); + else if (netgame || multiplayer) + CONS_Printf(M_GetText("This only works in single player.\n")); + else if (!&players[consoleplayer] || players[consoleplayer].lives <= 1) + CONS_Printf(M_GetText("You can't retry without any lives remaining!\n")); + else if (G_IsSpecialStage(gamemap)) + CONS_Printf(M_GetText("You can't retry special stages!\n")); + else + { + M_ClearMenus(true); + G_SetRetryFlag(); + } +} + +#ifdef NETGAME_DEVMODE +// Allow the use of devmode in netgames. +static void Fishcake_OnChange(void) +{ + cv_debug = cv_fishcake.value; + // consvar_t's get changed to default when registered + // so don't make modifiedgame always on! + if (cv_debug) + { + G_SetGameModified(multiplayer); + } + + else if (cv_debug != cv_fishcake.value) + CV_SetValue(&cv_fishcake, cv_debug); +} +#endif + +/** Reports to the console whether or not the game has been modified. + * + * \todo Make it obvious, so a console command won't be necessary. + * \sa modifiedgame + * \author Graue + */ +static void Command_Isgamemodified_f(void) +{ + if (savemoddata) + CONS_Printf(M_GetText("modifiedgame is true, but you can save emblem and time data in this mod.\n")); + else if (modifiedgame) + CONS_Printf(M_GetText("modifiedgame is true, secrets will not be unlocked\n")); + else + CONS_Printf(M_GetText("modifiedgame is false, you can unlock secrets\n")); +} + +static void Command_Cheats_f(void) +{ + if (CV_CheatsEnabled()) + CONS_Printf(M_GetText("At least one CHEAT-marked variable has been changed -- Cheats are enabled.\n")); + else + CONS_Printf(M_GetText("No CHEAT-marked variables are changed -- Cheats are disabled.\n")); +} + +#ifdef _DEBUG +static void Command_Togglemodified_f(void) +{ + modifiedgame = !modifiedgame; +} + +#ifdef HAVE_BLUA +extern UINT8 *save_p; +static void Command_Archivetest_f(void) +{ + UINT8 *buf; + UINT32 i, wrote; + thinker_t *th; + if (gamestate != GS_LEVEL) + { + CONS_Printf("This command only works in-game, you dummy.\n"); + return; + } + + // assign mobjnum + i = 0; + for (th = thinkercap.next; th != &thinkercap; th = th->next) + if (th->function.acp1 == (actionf_p1)P_MobjThinker) + ((mobj_t *)th)->mobjnum = i++; + + // allocate buffer + buf = save_p = ZZ_Alloc(1024); + + // test archive + CONS_Printf("LUA_Archive...\n"); + LUA_Archive(); + WRITEUINT8(save_p, 0x7F); + wrote = (UINT32)(save_p-buf); + + // clear Lua state, so we can really see what happens! + CONS_Printf("Clearing state!\n"); + LUA_ClearExtVars(); + + // test unarchive + save_p = buf; + CONS_Printf("LUA_UnArchive...\n"); + LUA_UnArchive(); + i = READUINT8(save_p); + if (i != 0x7F || wrote != (UINT32)(save_p-buf)) + CONS_Printf("Savegame corrupted. (write %u, read %u)\n", wrote, (UINT32)(save_p-buf)); + + // free buffer + Z_Free(buf); + CONS_Printf("Done. No crash.\n"); +} +#endif +#endif + +/** Makes a change to ::cv_forceskin take effect immediately. + * + * \todo Move the enforcement code out of SendNameAndColor() so this hack + * isn't needed. + * \sa Command_SetForcedSkin_f, cv_forceskin, forcedskin + * \author Graue + */ +static void ForceSkin_OnChange(void) +{ + if ((server || adminplayer == consoleplayer) && (cv_forceskin.value < -1 || cv_forceskin.value >= numskins)) + { + if (cv_forceskin.value == -2) + CV_StealthSetValue(&cv_forceskin, numskins-1); + else + { + // hack because I can't restrict this and still allow added skins to be used with forceskin. + if (!menuactive) + CONS_Printf(M_GetText("Valid skin numbers are 0 to %d (-1 disables)\n"), numskins - 1); + CV_SetValue(&cv_forceskin, -1); + return; + } + } + + if (cv_forceskin.value >= 0 && (netgame || multiplayer)) // NOT in SP, silly! + { + triggerforcedskin = true; + SendNameAndColor(); // have it take effect immediately + } +} + +//Allows the player's name to be changed if cv_mute is off. +static void Name_OnChange(void) +{ + if (cv_mute.value && !(server || adminplayer == consoleplayer)) + { + CONS_Alert(CONS_NOTICE, M_GetText("You may not change your name when chat is muted.\n")); + CV_StealthSet(&cv_playername, player_names[consoleplayer]); + } + else + SendNameAndColor(); + +} + +static void Name2_OnChange(void) +{ + if (cv_mute.value) //Secondary player can't be admin. + { + CONS_Alert(CONS_NOTICE, M_GetText("You may not change your name when chat is muted.\n")); + CV_StealthSet(&cv_playername2, player_names[secondarydisplayplayer]); + } + else + SendNameAndColor2(); +} + +/** Sends a skin change for the console player, unless that player is moving. + * \sa cv_skin, Skin2_OnChange, Color_OnChange + * \author Graue + */ +static void Skin_OnChange(void) +{ + if (CanChangeSkin(consoleplayer) && !P_PlayerMoving(consoleplayer)) + SendNameAndColor(); + else + { + CONS_Alert(CONS_NOTICE, M_GetText("You can't change your skin at the moment.\n")); + CV_StealthSet(&cv_skin, skins[players[consoleplayer].skin].name); + } +} + +/** Sends a skin change for the secondary splitscreen player, unless that + * player is moving. + * \sa cv_skin2, Skin_OnChange, Color2_OnChange + * \author Graue + */ +static void Skin2_OnChange(void) +{ + if (CanChangeSkin(secondarydisplayplayer) && !P_PlayerMoving(secondarydisplayplayer)) + SendNameAndColor2(); + else + { + CONS_Alert(CONS_NOTICE, M_GetText("You can't change your skin at the moment.\n")); + CV_StealthSet(&cv_skin2, skins[players[secondarydisplayplayer].skin].name); + } +} + +/** Sends a color change for the console player, unless that player is moving. + * \sa cv_playercolor, Color2_OnChange, Skin_OnChange + * \author Graue + */ +static void Color_OnChange(void) +{ + if (!P_PlayerMoving(consoleplayer)) + { + // Color change menu scrolling fix + // Determine what direction you are scrolling + // and skip the proper colors. + if (menuactive) + { + UINT8 prevcolor = players[consoleplayer].skincolor; + if (cv_playercolor.value == 0) // no color + { + if (prevcolor == 1) + CV_StealthSetValue(&cv_playercolor, MAXSKINCOLORS-1); + else + CV_StealthSetValue(&cv_playercolor, 1); + } + } + + SendNameAndColor(); + } + else { + CV_StealthSetValue(&cv_playercolor, + players[consoleplayer].skincolor); + } +} + +/** Sends a color change for the secondary splitscreen player, unless that + * player is moving. + * \sa cv_playercolor2, Color_OnChange, Skin2_OnChange + * \author Graue + */ +static void Color2_OnChange(void) +{ + if (!P_PlayerMoving(secondarydisplayplayer)) + { + // Color change menu scrolling fix + // Determine what direction you are scrolling + // and skip the proper colors. + if (menuactive) + { + UINT8 prevcolor = players[secondarydisplayplayer].skincolor; + if (cv_playercolor2.value == 0) // no color + { + if (prevcolor == 1) + CV_StealthSetValue(&cv_playercolor2, MAXSKINCOLORS-1); + else + CV_StealthSetValue(&cv_playercolor2, 1); + } + } + + SendNameAndColor2(); + } + else { + CV_StealthSetValue(&cv_playercolor2, + players[secondarydisplayplayer].skincolor); + } +} + +/** Displays the result of the chat being muted or unmuted. + * The server or remote admin should already know and be able to talk + * regardless, so this is only displayed to clients. + * + * \sa cv_mute + * \author Graue + */ +static void Mute_OnChange(void) +{ + if (server || (adminplayer == consoleplayer)) + return; + + if (cv_mute.value) + CONS_Printf(M_GetText("Chat has been muted.\n")); + else + CONS_Printf(M_GetText("Chat is no longer muted.\n")); +} + +/** Hack to clear all changed flags after game start. + * A lot of code (written by dummies, obviously) uses COM_BufAddText() to run + * commands and change consvars, especially on game start. This is problematic + * because CV_ClearChangedFlags() needs to get called on game start \b after + * all those commands are run. + * + * Here's how it's done: the last thing in COM_BufAddText() is "dummyconsvar + * 1", so we end up here, where dummyconsvar is reset to 0 and all the changed + * flags are set to 0. + * + * \todo Fix the aforementioned code and make this hack unnecessary. + * \sa cv_dummyconsvar + * \author Graue + */ +static void DummyConsvar_OnChange(void) +{ + if (cv_dummyconsvar.value == 1) + { + CV_SetValue(&cv_dummyconsvar, 0); + CV_ClearChangedFlags(); + } +} + +static void Command_ShowScores_f(void) +{ + UINT8 i; + + if (!(netgame || multiplayer)) + { + CONS_Printf(M_GetText("This only works in a netgame.\n")); + return; + } + + for (i = 0; i < MAXPLAYERS; i++) + { + if (playeringame[i]) + // FIXME: %lu? what's wrong with %u? ~Callum (produces warnings...) + CONS_Printf(M_GetText("%s's score is %u\n"), player_names[i], players[i].score); + } + CONS_Printf(M_GetText("The pointlimit is %d\n"), cv_pointlimit.value); + +} + +static void Command_ShowTime_f(void) +{ + if (!(netgame || multiplayer)) + { + CONS_Printf(M_GetText("This only works in a netgame.\n")); + return; + } + + CONS_Printf(M_GetText("The current time is %f.\nThe timelimit is %f\n"), (double)leveltime/TICRATE, (double)timelimitintics/TICRATE); +} diff --git a/src/d_netcmd.h b/src/d_netcmd.h new file mode 100644 index 000000000..932d77664 --- /dev/null +++ b/src/d_netcmd.h @@ -0,0 +1,226 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Copyright (C) 1999-2014 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file d_netcmd.h +/// \brief host/client network commands +/// commands are executed through the command buffer +/// like console commands + +#ifndef __D_NETCMD__ +#define __D_NETCMD__ + +#include "command.h" + +// console vars +extern consvar_t cv_playername; +extern consvar_t cv_playercolor; +#ifdef SEENAMES +extern consvar_t cv_seenames, cv_allowseenames; +#endif +extern consvar_t cv_usemouse; +extern consvar_t cv_usejoystick; +extern consvar_t cv_usejoystick2; +#ifdef LJOYSTICK +extern consvar_t cv_joyport; +extern consvar_t cv_joyport2; +#endif +extern consvar_t cv_joyscale; +extern consvar_t cv_joyscale2; +extern consvar_t cv_controlperkey; + +// splitscreen with second mouse +extern consvar_t cv_mouse2port; +extern consvar_t cv_usemouse2; +#if (defined (__unix__) && !defined (MSDOS)) || defined (UNIXCOMMON) +extern consvar_t cv_mouse2opt; +#endif +extern consvar_t cv_invertmouse2; +extern consvar_t cv_alwaysfreelook2; +extern consvar_t cv_mousemove2; +extern consvar_t cv_mousesens2; + +// normally in p_mobj but the .h is not read +extern consvar_t cv_itemrespawntime; +extern consvar_t cv_itemrespawn; + +extern consvar_t cv_flagtime; +extern consvar_t cv_suddendeath; + +extern consvar_t cv_skin; + +// secondary splitscreen player +extern consvar_t cv_playername2; +extern consvar_t cv_playercolor2; +extern consvar_t cv_skin2; + +extern consvar_t cv_touchtag; +extern consvar_t cv_hidetime; + +extern consvar_t cv_friendlyfire; +extern consvar_t cv_pointlimit; +extern consvar_t cv_timelimit; +extern consvar_t cv_numlaps; +extern consvar_t cv_usemapnumlaps; +extern UINT32 timelimitintics; +extern consvar_t cv_allowexitlevel; + +extern consvar_t cv_hazardlog; + +extern consvar_t cv_autobalance; +extern consvar_t cv_teamscramble; +extern consvar_t cv_scrambleonchange; + +extern consvar_t cv_useranalog, cv_useranalog2; +extern consvar_t cv_analog, cv_analog2; + +extern consvar_t cv_netstat; +extern consvar_t cv_translucency; +extern consvar_t cv_splats; + +extern consvar_t cv_countdowntime; +extern consvar_t cv_runscripts; +extern consvar_t cv_mute; +extern consvar_t cv_killingdead; +extern consvar_t cv_pause; + +extern consvar_t cv_restrictskinchange, cv_allowteamchange, cv_respawntime; + +extern consvar_t cv_teleporters, cv_superring, cv_supersneakers, cv_invincibility; +extern consvar_t cv_jumpshield, cv_watershield, cv_ringshield, cv_forceshield, cv_bombshield; +extern consvar_t cv_1up, cv_eggmanbox; +extern consvar_t cv_recycler; + +extern consvar_t cv_itemfinder; + +extern consvar_t cv_inttime, cv_advancemap, cv_playersforexit; +extern consvar_t cv_soniccd; +extern consvar_t cv_match_scoring; +extern consvar_t cv_overtime; +extern consvar_t cv_startinglives; + +// for F_finale.c +extern consvar_t cv_realnames, cv_rollingdemos; + +extern consvar_t cv_resetmusic; + +extern consvar_t cv_ringslinger, cv_soundtest; + +extern consvar_t cv_specialrings, cv_powerstones, cv_matchboxes, cv_competitionboxes; + +#ifdef CHAOSISNOTDEADYET +extern consvar_t cv_chaos_spawnrate, cv_chaos_bluecrawla, cv_chaos_redcrawla; +extern consvar_t cv_chaos_crawlacommander, cv_chaos_jettysynbomber, cv_chaos_jettysyngunner; +extern consvar_t cv_chaos_eggmobile1, cv_chaos_eggmobile2, cv_chaos_skim; +#endif + +#ifdef NEWPING +extern consvar_t cv_maxping; +#endif + +extern consvar_t cv_skipmapcheck; + +extern consvar_t cv_sleep, cv_screenshot_option, cv_screenshot_folder; + +extern consvar_t cv_moviemode; + +extern consvar_t cv_zlib_level, cv_zlib_memory, cv_zlib_strategy; + +extern consvar_t cv_zlib_window_bits, cv_zlib_levela, cv_zlib_memorya; + +extern consvar_t cv_zlib_strategya, cv_zlib_window_bitsa; + +extern consvar_t cv_apng_delay; + +typedef enum +{ + XD_NAMEANDCOLOR = 1, + XD_WEAPONPREF, // 2 + XD_KICK, // 3 + XD_NETVAR, // 4 + XD_SAY, // 5 + XD_MAP, // 6 + XD_EXITLEVEL, // 7 + XD_ADDFILE, // 8 + XD_PAUSE, // 9 + XD_ADDPLAYER, // 10 + XD_TEAMCHANGE, // 11 + XD_CLEARSCORES, // 12 + XD_LOGIN, // 13 + XD_VERIFIED, // 14 + XD_RANDOMSEED, // 15 + XD_RUNSOC, // 16 + XD_REQADDFILE, // 17 + XD_DELFILE, // 18 + XD_SETMOTD, // 19 + XD_SUICIDE, // 20 +#ifdef HAVE_BLUA + XD_LUACMD, // 21 + XD_LUAVAR, // 22 +#endif + MAXNETXCMD +} netxcmd_t; + +#if defined(_MSC_VER) +#pragma pack(1) +#endif + +#ifdef _MSC_VER +#pragma warning(disable : 4214) +#endif + +//Packet composition for Command_TeamChange_f() ServerTeamChange, etc. +//bitwise structs make packing bits a little easier, but byte alignment harder? +//todo: decide whether to make the other netcommands conform, or just get rid of this experiment. +typedef struct { + UINT32 playernum : 5; // value 0 to 31 + UINT32 newteam : 5; // value 0 to 31 + UINT32 verification : 1; // value 0 to 1 + UINT32 autobalance : 1; // value 0 to 1 + UINT32 scrambled : 1; // value 0 to 1 +} ATTRPACK changeteam_packet_t; + +#ifdef _MSC_VER +#pragma warning(default : 4214) +#endif + +typedef struct { + UINT16 l; // liitle endian + UINT16 b; // big enian +} ATTRPACK changeteam_value_t; + +//Since we do not want other files/modules to know about this data buffer we union it here with a Short Int. +//Other files/modules will hand the INT16 back to us and we will decode it here. +//We don't have to use a union, but we would then send four bytes instead of two. +typedef union { + changeteam_packet_t packet; + changeteam_value_t value; +} ATTRPACK changeteam_union; + +#if defined(_MSC_VER) +#pragma pack() +#endif + +// add game commands, needs cleanup +void D_RegisterServerCommands(void); +void D_RegisterClientCommands(void); +void D_SendPlayerConfig(void); +void Command_ExitGame_f(void); +void Command_Retry_f(void); +void D_GameTypeChanged(INT32 lastgametype); // not a real _OnChange function anymore +void D_MapChange(INT32 pmapnum, INT32 pgametype, boolean pultmode, boolean presetplayers, INT32 pdelay, boolean pskipprecutscene, boolean pfromlevelselect); +void ObjectPlace_OnChange(void); +void ItemFinder_OnChange(void); +void D_SetPassword(const char *pw); + +// used for the player setup menu +UINT8 CanChangeSkin(INT32 playernum); + +#endif + + diff --git a/src/d_netfil.c b/src/d_netfil.c new file mode 100644 index 000000000..bc2ff87c3 --- /dev/null +++ b/src/d_netfil.c @@ -0,0 +1,807 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Copyright (C) 1999-2014 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file d_netfil.c +/// \brief Transfer a file using HSendPacket. + +#include +#ifndef _WIN32_WCE +#ifdef __OS2__ +#include +#endif // __OS2__ +#include +#endif + +#if !defined (UNDER_CE) +#include +#endif + +#if ((defined (_WIN32) && !defined (_WIN32_WCE)) || defined (__DJGPP__)) && !defined (_XBOX) +#include +#include +#elif !defined (_WIN32_WCE) && !(defined (_XBOX) && !defined (__GNUC__)) +#include +#include +#include +#endif + +#ifdef __GNUC__ +#include +#include +#elif defined (_WIN32) && !defined (_WIN32_WCE) +#include +#endif +#ifdef __DJGPP__ +#include +#include +#endif + +#include "doomdef.h" +#include "doomstat.h" +#include "d_main.h" +#include "g_game.h" +#include "i_net.h" +#include "i_system.h" +#include "m_argv.h" +#include "d_net.h" +#include "w_wad.h" +#include "d_netfil.h" +#include "z_zone.h" +#include "byteptr.h" +#include "p_setup.h" +#include "m_misc.h" +#include "m_menu.h" +#include "md5.h" +#include "filesrch.h" + +static void SendFile(INT32 node, const char *filename, UINT8 fileid); + +// sender structure +typedef struct filetx_s +{ + INT32 ram; + char *filename; // name of the file or ptr of the data in ram + UINT32 size; + UINT8 fileid; + INT32 node; // destination + struct filetx_s *next; // a queue +} filetx_t; + +// current transfers (one for each node) +typedef struct filetran_s +{ + filetx_t *txlist; + UINT32 position; + FILE *currentfile; +} filetran_t; +static filetran_t transfer[MAXNETNODES]; + +// read time of file: stat _stmtime +// write time of file: utime + +// receiver structure +INT32 fileneedednum; +fileneeded_t fileneeded[MAX_WADFILES]; +char downloaddir[256] = "DOWNLOAD"; + +#ifdef CLIENT_LOADINGSCREEN +// for cl loading screen +INT32 lastfilenum = 0; +#endif + +/** Fills a serverinfo packet with information about wad files loaded. + * + * \todo Give this function a better name since it is in global scope. + */ +UINT8 *PutFileNeeded(void) +{ + size_t i, count = 0; + UINT8 *p = netbuffer->u.serverinfo.fileneeded; + char wadfilename[MAX_WADPATH] = ""; + UINT8 filestatus; + size_t bytesused = 0; + + for (i = 0; i < numwadfiles; i++) + { + // if it has only music/sound lumps, mark it as unimportant + if (W_VerifyNMUSlumps(wadfiles[i]->filename)) + filestatus = 0; + else + filestatus = 1; // important + + // Store in the upper four bits + if (!cv_downloading.value) + filestatus += (2 << 4); // won't send + else if ((wadfiles[i]->filesize > (UINT32)cv_maxsend.value * 1024)) + filestatus += (0 << 4); // won't send + else + filestatus += (1 << 4); // will send if requested + + bytesused += (nameonlylength(wadfilename) + 22); + + // Don't write too far... + if (bytesused > sizeof(netbuffer->u.serverinfo.fileneeded)) + I_Error("Too many wad files added to host a game. (%s, stopped on %s)\n", sizeu1(bytesused), wadfilename); + + WRITEUINT8(p, filestatus); + + count++; + WRITEUINT32(p, wadfiles[i]->filesize); + nameonly(strcpy(wadfilename, wadfiles[i]->filename)); + WRITESTRINGN(p, wadfilename, MAX_WADPATH); + WRITEMEM(p, wadfiles[i]->md5sum, 16); + } + netbuffer->u.serverinfo.fileneedednum = (UINT8)count; + + return p; +} + +// parse the serverinfo packet and fill fileneeded table on client +void D_ParseFileneeded(INT32 fileneedednum_parm, UINT8 *fileneededstr) +{ + INT32 i; + UINT8 *p; + UINT8 filestatus; + + fileneedednum = fileneedednum_parm; + p = (UINT8 *)fileneededstr; + for (i = 0; i < fileneedednum; i++) + { + fileneeded[i].status = FS_NOTFOUND; + filestatus = READUINT8(p); + fileneeded[i].important = (UINT8)(filestatus & 3); + fileneeded[i].willsend = (UINT8)(filestatus >> 4); + fileneeded[i].totalsize = READUINT32(p); + fileneeded[i].phandle = NULL; + READSTRINGN(p, fileneeded[i].filename, MAX_WADPATH); + READMEM(p, fileneeded[i].md5sum, 16); + } +} + +void CL_PrepareDownloadSaveGame(const char *tmpsave) +{ + fileneedednum = 1; + fileneeded[0].status = FS_REQUESTED; + fileneeded[0].totalsize = UINT32_MAX; + fileneeded[0].phandle = NULL; + memset(fileneeded[0].md5sum, 0, 16); + strcpy(fileneeded[0].filename, tmpsave); +} + +/** Checks the server to see if we CAN download all the files, + * before starting to create them and requesting. + */ +boolean CL_CheckDownloadable(void) +{ + UINT8 i,dlstatus = 0; + + for (i = 0; i < fileneedednum; i++) + if (fileneeded[i].status != FS_FOUND && fileneeded[i].status != FS_OPEN && fileneeded[i].important) + { + if (fileneeded[i].willsend == 1) + continue; + + if (fileneeded[i].willsend == 0) + dlstatus = 1; + else //if (fileneeded[i].willsend == 2) + dlstatus = 2; + } + + // Downloading locally disabled + if (!dlstatus && M_CheckParm("-nodownload")) + dlstatus = 3; + + if (!dlstatus) + return true; + + // not downloadable, put reason in console + CONS_Alert(CONS_NOTICE, M_GetText("You need additional files to connect to this server:\n")); + for (i = 0; i < fileneedednum; i++) + if (fileneeded[i].status != FS_FOUND && fileneeded[i].status != FS_OPEN && fileneeded[i].important) + { + CONS_Printf(" * \"%s\" (%dK)", fileneeded[i].filename, fileneeded[i].totalsize >> 10); + + if (fileneeded[i].status == FS_NOTFOUND) + CONS_Printf(M_GetText(" not found, md5: ")); + else if (fileneeded[i].status == FS_MD5SUMBAD) + CONS_Printf(M_GetText(" wrong version, md5: ")); + + { + INT32 j; + char md5tmp[33]; + for (j = 0; j < 16; j++) + sprintf(&md5tmp[j*2], "%02x", fileneeded[i].md5sum[j]); + CONS_Printf("%s", md5tmp); + } + CONS_Printf("\n"); + } + + switch (dlstatus) + { + case 1: + CONS_Printf(M_GetText("Some files are larger than the server is willing to send.\n")); + break; + case 2: + CONS_Printf(M_GetText("The server is not allowing download requests.\n")); + break; + case 3: + CONS_Printf(M_GetText("All files downloadable, but you have chosen to disable downloading locally.\n")); + break; + } + return false; +} + +/** Send requests for files in the ::fileneeded table with a status of + * ::FS_NOTFOUND. + */ +boolean CL_SendRequestFile(void) +{ + char *p; + INT32 i; + INT64 totalfreespaceneeded = 0, availablefreespace; + +#ifdef PARANOIA + if (M_CheckParm("-nodownload")) + I_Error("Attempted to download files in -nodownload mode"); + + for (i = 0; i < fileneedednum; i++) + if (fileneeded[i].status != FS_FOUND && fileneeded[i].status != FS_OPEN + && fileneeded[i].important && (fileneeded[i].willsend == 0 || fileneeded[i].willsend == 2)) + { + I_Error("Attempted to download files that were not sendable"); + } +#endif + + netbuffer->packettype = PT_REQUESTFILE; + p = (char *)netbuffer->u.textcmd; + for (i = 0; i < fileneedednum; i++) + if ((fileneeded[i].status == FS_NOTFOUND || fileneeded[i].status == FS_MD5SUMBAD) + && fileneeded[i].important) + { + totalfreespaceneeded += fileneeded[i].totalsize; + nameonly(fileneeded[i].filename); + WRITEUINT8(p, i); // fileid + WRITESTRINGN(p, fileneeded[i].filename, MAX_WADPATH); + // put it in download dir + strcatbf(fileneeded[i].filename, downloaddir, "/"); + fileneeded[i].status = FS_REQUESTED; + } + WRITEUINT8(p, 0xFF); + I_GetDiskFreeSpace(&availablefreespace); + if (totalfreespaceneeded > availablefreespace) + I_Error("To play on this server you must download %s KB,\n" + "but you have only %s KB free space on this drive\n", + sizeu1((size_t)(totalfreespaceneeded>>10)), sizeu2((size_t)(availablefreespace>>10))); + + // prepare to download + I_mkdir(downloaddir, 0755); + return HSendPacket(servernode, true, 0, p - (char *)netbuffer->u.textcmd); +} + +// get request filepak and put it on the send queue +void Got_RequestFilePak(INT32 node) +{ + char wad[MAX_WADPATH+1]; + UINT8 *p = netbuffer->u.textcmd; + UINT8 id; + while (p < netbuffer->u.textcmd + MAXTEXTCMD-1) // Don't allow hacked client to overflow + { + id = READUINT8(p); + if (id == 0xFF) + break; + READSTRINGN(p, wad, MAX_WADPATH); + SendFile(node, wad, id); + } +} + +// client check if the fileneeded aren't already loaded or on the disk +INT32 CL_CheckFiles(void) +{ + INT32 i, j; + char wadfilename[MAX_WADPATH]; + INT32 ret = 1; + +// if (M_CheckParm("-nofiles")) +// return 1; + + // the first is the iwad (the main wad file) + // we don't care if it's called srb2.srb or srb2.wad. + // Never download the IWAD, just assume it's there and identical + fileneeded[0].status = FS_OPEN; + + // Modified game handling -- check for an identical file list + // must be identical in files loaded AND in order + // Return 2 on failure -- disconnect from server + if (modifiedgame) + { + CONS_Debug(DBG_NETPLAY, "game is modified; only doing basic checks\n"); + for (i = 1, j = 1; i < fileneedednum || j < numwadfiles;) + { + if (i < fileneedednum && !fileneeded[i].important) + { + // Eh whatever, don't care + ++i; + continue; + } + if (j < numwadfiles && W_VerifyNMUSlumps(wadfiles[j]->filename)) + { + // unimportant on our side. still don't care. + ++j; + continue; + } + + // If this test is true, we've reached the end of one file list + // and the other still has a file that's important + if (i >= fileneedednum || j >= numwadfiles) + return 2; + + // for the sake of speed, only bother with a md5 check + if (memcmp(wadfiles[j]->md5sum, fileneeded[i].md5sum, 16)) + return 2; + + // it's accounted for! let's keep going. + CONS_Debug(DBG_NETPLAY, "'%s' accounted for\n", fileneeded[i].filename); + fileneeded[i].status = FS_OPEN; + ++i; + ++j; + } + return 1; + } + + for (i = 1; i < fileneedednum; i++) + { + CONS_Debug(DBG_NETPLAY, "searching for '%s' ", fileneeded[i].filename); + + // check in allready loaded files + for (j = 1; wadfiles[j]; j++) + { + nameonly(strcpy(wadfilename, wadfiles[j]->filename)); + if (!stricmp(wadfilename, fileneeded[i].filename) && + !memcmp(wadfiles[j]->md5sum, fileneeded[i].md5sum, 16)) + { + CONS_Debug(DBG_NETPLAY, "already loaded\n"); + fileneeded[i].status = FS_OPEN; + break; + } + } + if (fileneeded[i].status != FS_NOTFOUND || !fileneeded[i].important) + continue; + + fileneeded[i].status = findfile(fileneeded[i].filename, fileneeded[i].md5sum, true); + CONS_Debug(DBG_NETPLAY, "found %d\n", fileneeded[i].status); + if (fileneeded[i].status != FS_FOUND) + ret = 0; + } + return ret; +} + +// load it now +void CL_LoadServerFiles(void) +{ + INT32 i; + +// if (M_CheckParm("-nofiles")) +// return; + + for (i = 1; i < fileneedednum; i++) + { + if (fileneeded[i].status == FS_OPEN) + continue; // already loaded + else if (fileneeded[i].status == FS_FOUND) + { + P_AddWadFile(fileneeded[i].filename, NULL); + G_SetGameModified(true); + fileneeded[i].status = FS_OPEN; + } + else if (fileneeded[i].status == FS_MD5SUMBAD) + { + // If the file is marked important, don't even bother proceeding. + if (fileneeded[i].important) + I_Error("Wrong version of important file %s", fileneeded[i].filename); + + // If it isn't, no need to worry the user with a console message, + // although it can't hurt to put something in the debug file. + + // ...but wait a second. What if the local version is "important"? + if (!W_VerifyNMUSlumps(fileneeded[i].filename)) + I_Error("File %s should only contain music and sound effects!", + fileneeded[i].filename); + + // Okay, NOW we know it's safe. Whew. + P_AddWadFile(fileneeded[i].filename, NULL); + if (fileneeded[i].important) + G_SetGameModified(true); + fileneeded[i].status = FS_OPEN; + DEBFILE(va("File %s found but with different md5sum\n", fileneeded[i].filename)); + } + else if (fileneeded[i].important) + I_Error("Try to load file %s with status of %d\n", fileneeded[i].filename, + fileneeded[i].status); + } +} + +// little optimization to test if there is a file in the queue +static INT32 filetosend = 0; + +static void SendFile(INT32 node, const char *filename, UINT8 fileid) +{ + filetx_t **q; + filetx_t *p; + INT32 i; + char wadfilename[MAX_WADPATH]; + + q = &transfer[node].txlist; + while (*q) + q = &((*q)->next); + p = *q = (filetx_t *)malloc(sizeof (filetx_t)); + if (p) + memset(p, 0, sizeof (filetx_t)); + else + I_Error("SendFile: No more ram\n"); + p->filename = (char *)malloc(MAX_WADPATH); + if (!p->filename) + I_Error("SendFile: No more ram\n"); + + // a minimum of security, can get only file in srb2 direcory + strlcpy(p->filename, filename, MAX_WADPATH); + nameonly(p->filename); + + // check first in wads loaded the majority of case + for (i = 0; wadfiles[i]; i++) + { + strlcpy(wadfilename, wadfiles[i]->filename, MAX_WADPATH); + nameonly(wadfilename); + if (!stricmp(wadfilename, p->filename)) + { + // copy filename with full path + strlcpy(p->filename, wadfiles[i]->filename, MAX_WADPATH); + break; + } + } + + if (!wadfiles[i]) + { + DEBFILE(va("%s not found in wadfiles\n", filename)); + // this formerly checked if (!findfile(p->filename, NULL, true)) + + // not found + // don't inform client (probably hacker) + DEBFILE(va("Client %d request %s: not found\n", node, filename)); + free(p->filename); + free(p); + *q = NULL; + return; + } + + if (wadfiles[i]->filesize > (UINT32)cv_maxsend.value * 1024) + { + // too big + // don't inform client (client sucks, man) + DEBFILE(va("Client %d request %s: file too big, not sending\n", node, filename)); + free(p->filename); + free(p); + *q = NULL; + return; + } + + DEBFILE(va("Sending file %s (id=%d) to %d\n", filename, fileid, node)); + p->ram = SF_FILE; + p->fileid = fileid; + p->next = NULL; // end of list + filetosend++; +} + +void SendRam(INT32 node, void *data, size_t size, freemethod_t freemethod, UINT8 fileid) +{ + filetx_t **q; + filetx_t *p; + + q = &transfer[node].txlist; + while (*q) + q = &((*q)->next); + p = *q = (filetx_t *)malloc(sizeof (filetx_t)); + if (p) + memset(p, 0, sizeof (filetx_t)); + else + I_Error("SendRam: No more ram\n"); + p->ram = freemethod; + p->filename = data; + p->size = (UINT32)size; + p->fileid = fileid; + p->next = NULL; // end of list + + DEBFILE(va("Sending ram %p(size:%u) to %d (id=%u)\n",p->filename,p->size,node,fileid)); + + filetosend++; +} + +static void EndSend(INT32 node) +{ + filetx_t *p = transfer[node].txlist; + switch (p->ram) + { + case SF_FILE: + if (transfer[node].currentfile) + fclose(transfer[node].currentfile); + free(p->filename); + break; + case SF_Z_RAM: + Z_Free(p->filename); + break; + case SF_RAM: + free(p->filename); + case SF_NOFREERAM: + break; + } + transfer[node].txlist = p->next; + transfer[node].currentfile = NULL; + free(p); + filetosend--; +} + +#define PACKETPERTIC net_bandwidth/(TICRATE*software_MAXPACKETLENGTH) + +void FiletxTicker(void) +{ + static INT32 currentnode = 0; + filetx_pak *p; + size_t size; + filetx_t *f; + INT32 packetsent = PACKETPERTIC, ram, i; + + if (!filetosend) + return; + if (!packetsent) + packetsent++; + // (((sendbytes-nowsentbyte)*TICRATE)/(I_GetTime()-starttime)<(UINT32)net_bandwidth) + while (packetsent-- && filetosend != 0) + { + for (i = currentnode, ram = 0; ram < MAXNETNODES; + i = (i+1) % MAXNETNODES, ram++) + { + if (transfer[i].txlist) + goto found; + } + // no transfer to do + I_Error("filetosend=%d but no filetosend found\n", filetosend); + found: + currentnode = (i+1) % MAXNETNODES; + f = transfer[i].txlist; + ram = f->ram; + + if (!transfer[i].currentfile) // file not already open + { + if (!ram) + { + long filesize; + + transfer[i].currentfile = + fopen(f->filename, "rb"); + + if (!transfer[i].currentfile) + I_Error("File %s does not exist", + f->filename); + + fseek(transfer[i].currentfile, 0, SEEK_END); + filesize = ftell(transfer[i].currentfile); + + // Nobody wants to transfer a file bigger + // than 4GB! + if (filesize >= LONG_MAX) + I_Error("filesize of %s is too large", f->filename); + if (-1 == filesize) + I_Error("Error getting filesize of %s", f->filename); + + f->size = (UINT32)filesize; + fseek(transfer[i].currentfile, 0, SEEK_SET); + } + else + transfer[i].currentfile = (FILE *)1; + transfer[i].position = 0; + } + + p = &netbuffer->u.filetxpak; + size = software_MAXPACKETLENGTH - (FILETXHEADER + BASEPACKETSIZE); + if (f->size-transfer[i].position < size) + size = f->size-transfer[i].position; + if (ram) + M_Memcpy(p->data, &f->filename[transfer[i].position], size); + else if (fread(p->data, 1, size, transfer[i].currentfile) != size) + I_Error("FiletxTicker: can't read %s byte on %s at %d because %s", sizeu1(size), f->filename, transfer[i].position, strerror(ferror(transfer[i].currentfile))); + p->position = LONG(transfer[i].position); + // put flag so receiver know the totalsize + if (transfer[i].position + size == f->size) + p->position |= LONG(0x80000000); + p->fileid = f->fileid; + p->size = SHORT((UINT16)size); + netbuffer->packettype = PT_FILEFRAGMENT; + if (!HSendPacket(i, true, 0, FILETXHEADER + size)) // reliable SEND + { // not sent for some odd reason, retry at next call + if (!ram) + fseek(transfer[i].currentfile,transfer[i].position,SEEK_SET); + // exit the while (can't send this one so why should i send the next?) + break; + } + else // success + { + transfer[i].position = (UINT32)(size+transfer[i].position); + if (transfer[i].position == f->size) // finish ? + EndSend(i); + } + } +} + +void Got_Filetxpak(void) +{ + INT32 filenum = netbuffer->u.filetxpak.fileid; + static INT32 filetime = 0; + + if (filenum >= fileneedednum) + { + DEBFILE(va("fileframent not needed %d>%d\n",filenum, fileneedednum)); + return; + } + + if (fileneeded[filenum].status == FS_REQUESTED) + { + if (fileneeded[filenum].phandle) I_Error("Got_Filetxpak: allready open file\n"); + fileneeded[filenum].phandle = fopen(fileneeded[filenum].filename, "wb"); + if (!fileneeded[filenum].phandle) I_Error("Can't create file %s: disk full ?",fileneeded[filenum].filename); + CONS_Printf("\r%s...\n",fileneeded[filenum].filename); + fileneeded[filenum].currentsize = 0; + fileneeded[filenum].status = FS_DOWNLOADING; + } + + if (fileneeded[filenum].status == FS_DOWNLOADING) + { + UINT32 pos = LONG(netbuffer->u.filetxpak.position); + UINT16 size = SHORT(netbuffer->u.filetxpak.size); + // use a special tric to know when file is finished (not allways used) + // WARNING: filepak can arrive out of order so don't stop now ! + if (pos & 0x80000000) + { + pos &= ~0x80000000; + fileneeded[filenum].totalsize = pos + size; + } + // we can receive packet in the wrong order, anyway all os support gaped file + fseek(fileneeded[filenum].phandle,pos,SEEK_SET); + if (fwrite(netbuffer->u.filetxpak.data,size,1,fileneeded[filenum].phandle)!=1) + I_Error("Can't write %s: disk full ? or %s\n",fileneeded[filenum].filename, strerror(ferror(fileneeded[filenum].phandle))); + fileneeded[filenum].currentsize += size; + + // finished? + if (fileneeded[filenum].currentsize == fileneeded[filenum].totalsize) + { + fclose(fileneeded[filenum].phandle); + fileneeded[filenum].phandle = NULL; + fileneeded[filenum].status = FS_FOUND; + CONS_Printf(M_GetText("Downloading %s...(done)\n"), + fileneeded[filenum].filename); + } + } + else + I_Error("Received a file not requested\n"); + // send ack back quickly + + if (++filetime == 3) + { + Net_SendAcks(servernode); + filetime = 0; + } + +#ifdef CLIENT_LOADINGSCREEN + lastfilenum = filenum; +#endif +} + +void AbortSendFiles(INT32 node) +{ + while (transfer[node].txlist) + EndSend(node); +} + +void CloseNetFile(void) +{ + INT32 i; + // is sending? + for (i = 0; i < MAXNETNODES; i++) + AbortSendFiles(i); + + // receiving a file? + for (i = 0; i < MAX_WADFILES; i++) + if (fileneeded[i].status == FS_DOWNLOADING && fileneeded[i].phandle) + { + fclose(fileneeded[i].phandle); + // file is not complete delete it + remove(fileneeded[i].filename); + } + + // remove FILEFRAGMENT from acknledge list + Net_AbortPacketType(PT_FILEFRAGMENT); +} + +// functions cut and pasted from doomatic :) + +void nameonly(char *s) +{ + size_t j, len; + void *ns; + + for (j = strlen(s); j != (size_t)-1; j--) + if ((s[j] == '\\') || (s[j] == ':') || (s[j] == '/')) + { + ns = &(s[j+1]); + len = strlen(ns); + if (false) + M_Memcpy(s, ns, len+1); + else + memmove(s, ns, len+1); + return; + } +} + +// Returns the length in characters of the last element of a path. +size_t nameonlylength(const char *s) +{ + size_t j, len = strlen(s); + + for (j = len; j != (size_t)-1; j--) + if ((s[j] == '\\') || (s[j] == ':') || (s[j] == '/')) + return len - j - 1; + + return len; +} + +#ifndef O_BINARY +#define O_BINARY 0 +#endif + +filestatus_t checkfilemd5(char *filename, const UINT8 *wantedmd5sum) +{ +#if defined (NOMD5) || defined (_arch_dreamcast) + (void)wantedmd5sum; + (void)filename; +#else + FILE *fhandle; + UINT8 md5sum[16]; + + if (!wantedmd5sum) + return FS_FOUND; + + fhandle = fopen(filename, "rb"); + if (fhandle) + { + md5_stream(fhandle,md5sum); + fclose(fhandle); + if (!memcmp(wantedmd5sum, md5sum, 16)) + return FS_FOUND; + return FS_MD5SUMBAD; + } + + I_Error("Couldn't open %s for md5 check", filename); +#endif + return FS_FOUND; // will never happen, but makes the compiler shut up +} + +filestatus_t findfile(char *filename, const UINT8 *wantedmd5sum, boolean completepath) +{ + filestatus_t homecheck = filesearch(filename, srb2home, wantedmd5sum, false, 10); + if (homecheck == FS_FOUND) + return filesearch(filename, srb2home, wantedmd5sum, completepath, 10); + + homecheck = filesearch(filename, srb2path, wantedmd5sum, false, 10); + if (homecheck == FS_FOUND) + return filesearch(filename, srb2path, wantedmd5sum, completepath, 10); + +#ifdef _arch_dreamcast + return filesearch(filename, "/cd", wantedmd5sum, completepath, 10); +#else + return filesearch(filename, ".", wantedmd5sum, completepath, 10); +#endif +} diff --git a/src/d_netfil.h b/src/d_netfil.h new file mode 100644 index 000000000..224ec4dbb --- /dev/null +++ b/src/d_netfil.h @@ -0,0 +1,90 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Copyright (C) 1999-2014 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file d_netfil.h +/// \brief File transferring related structs and functions. + +#ifndef __D_NETFIL__ +#define __D_NETFIL__ + +#include "w_wad.h" + +typedef enum +{ + SF_FILE, + SF_Z_RAM, + SF_RAM, + SF_NOFREERAM +} freemethod_t; + +typedef enum +{ + FS_NOTFOUND, + FS_FOUND, + FS_REQUESTED, + FS_DOWNLOADING, + FS_OPEN, // is opened and used in w_wad + FS_MD5SUMBAD +} filestatus_t; + +typedef struct +{ + UINT8 important; + UINT8 willsend; // is the server willing to send it? + char filename[MAX_WADPATH]; + UINT8 md5sum[16]; + // used only for download + FILE *phandle; + UINT32 currentsize; + UINT32 totalsize; + filestatus_t status; // the value returned by recsearch +} fileneeded_t; + +extern INT32 fileneedednum; +extern fileneeded_t fileneeded[MAX_WADFILES]; +extern char downloaddir[256]; + +#ifdef CLIENT_LOADINGSCREEN +extern INT32 lastfilenum; +#endif + +UINT8 *PutFileNeeded(void); +void D_ParseFileneeded(INT32 fileneedednum_parm, UINT8 *fileneededstr); +void CL_PrepareDownloadSaveGame(const char *tmpsave); + +// check file list in wadfiles return 0 when a file is not found +// 1 if all file are found +// 2 if you cannot connect (different wad version or +// no enought space to download files) +INT32 CL_CheckFiles(void); +void CL_LoadServerFiles(void); +void SendRam(INT32 node, void *data, size_t size, freemethod_t freemethod, + UINT8 fileid); + +void FiletxTicker(void); +void Got_Filetxpak(void); + +boolean CL_CheckDownloadable(void); +boolean CL_SendRequestFile(void); +void Got_RequestFilePak(INT32 node); + +void AbortSendFiles(INT32 node); +void CloseNetFile(void); + +boolean fileexist(char *filename, time_t ptime); + +// search a file in the wadpath, return FS_FOUND when found +filestatus_t findfile(char *filename, const UINT8 *wantedmd5sum, + boolean completepath); +filestatus_t checkfilemd5(char *filename, const UINT8 *wantedmd5sum); + +void nameonly(char *s); +size_t nameonlylength(const char *s); + +#endif // __D_NETFIL__ diff --git a/src/d_player.h b/src/d_player.h new file mode 100644 index 000000000..e98f23ed0 --- /dev/null +++ b/src/d_player.h @@ -0,0 +1,436 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 1993-1996 by id Software, Inc. +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Copyright (C) 1999-2014 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file d_player.h +/// \brief player data structures + +#ifndef __D_PLAYER__ +#define __D_PLAYER__ + +// The player data structure depends on a number +// of other structs: items (internal inventory), +// animation states (closely tied to the sprites +// used to represent them, unfortunately). +#include "p_pspr.h" + +// In addition, the player is just a special +// case of the generic moving object/actor. +#include "p_mobj.h" + +// Finally, for odd reasons, the player input +// is buffered within the player data struct, +// as commands per game tick. +#include "d_ticcmd.h" + +// Extra abilities/settings for skins (combinable stuff) +typedef enum +{ + SF_SUPER = 1, // Can turn super in singleplayer/co-op mode. + SF_SUPERANIMS = 1<<1, // If super, use the super sonic animations + SF_SUPERSPIN = 1<<2, // Should spin frames be played while super? + SF_HIRES = 1<<3, // Draw the sprite 2x as small? + SF_NOSKID = 1<<4, // No skid particles etc + SF_NOSPEEDADJUST = 1<<5, // Skin-specific version of disablespeedadjust +} skinflags_t; + +//Primary and secondary skin abilities +typedef enum +{ + CA_NONE=0, + CA_THOK, + CA_FLY, + CA_GLIDEANDCLIMB, + CA_HOMINGTHOK, + CA_SWIM, + CA_DOUBLEJUMP, + CA_FLOAT, + CA_SLOWFALL, + CA_TELEKINESIS, + CA_FALLSWITCH, + CA_JUMPBOOST, + CA_AIRDRILL +} charability_t; + +//Secondary skin abilities +typedef enum +{ + CA2_NONE=0, + CA2_SPINDASH, + CA2_MULTIABILITY +} charability2_t; + +// +// Player states. +// +typedef enum +{ + // Playing or camping. + PST_LIVE, + // Dead on the ground, view follows killer. + PST_DEAD, + // Ready to restart/respawn??? + PST_REBORN +} playerstate_t; + +// +// Player internal flags +// +typedef enum +{ + // Flip camera angle with gravity flip prefrence. + PF_FLIPCAM = 1, + + // Cheats + PF_GODMODE = 1<<1, + PF_NOCLIP = 1<<2, + PF_INVIS = 1<<3, + + // True if button down last tic. + PF_ATTACKDOWN = 1<<4, + PF_USEDOWN = 1<<5, + PF_JUMPDOWN = 1<<6, + PF_WPNDOWN = 1<<7, + + // Unmoving states + PF_STASIS = 1<<8, // Player is not allowed to move + PF_JUMPSTASIS = 1<<9, // and that includes jumping. + PF_FULLSTASIS = PF_STASIS|PF_JUMPSTASIS, + + // Did you get a time-over? + PF_TIMEOVER = 1<<10, + + // Ready for Super? + PF_SUPERREADY = 1<<11, + + // Character action status + PF_JUMPED = 1<<12, + PF_SPINNING = 1<<13, + PF_STARTDASH = 1<<14, + PF_THOKKED = 1<<15, + + // Are you gliding? + PF_GLIDING = 1<<16, + + // Tails pickup! + PF_CARRIED = 1<<17, + + // Sliding (usually in water) like Labyrinth/Oil Ocean + PF_SLIDING = 1<<18, + + // Hanging on a rope + PF_ROPEHANG = 1<<19, + + // Hanging on an item of some kind - zipline, chain, etc. (->tracer) + PF_ITEMHANG = 1<<20, + + // On the mace chain spinning around (->tracer) + PF_MACESPIN = 1<<21, + + /*** NIGHTS STUFF ***/ + // Is the player in NiGHTS mode? + PF_NIGHTSMODE = 1<<22, + PF_TRANSFERTOCLOSEST = 1<<23, + + // Spill rings after falling + PF_NIGHTSFALL = 1<<24, + PF_DRILLING = 1<<25, + PF_SKIDDOWN = 1<<26, + + /*** TAG STUFF ***/ + PF_TAGGED = 1<<27, // Player has been tagged and awaits the next round in hide and seek. + PF_TAGIT = 1<<28, // The player is it! For Tag Mode + + // free: 1<<29, 1<<30 + + PF_CONSISTANCY = 1<<31 // DON'T mess with this flag or horrible things will happen. +} pflags_t; + +typedef enum +{ + // Are animation frames playing? + PA_ETC=0, + PA_IDLE, + PA_WALK, + PA_RUN, + PA_ROLL, + PA_FALL, + PA_ABILITY +} panim_t; + +typedef enum +{ + SH_NONE = 0, + // Standard shields + SH_JUMP, + SH_ATTRACT, + SH_ELEMENTAL, + SH_BOMB, + // Stupid useless unimplimented Sonic 3 shields + SH_BUBBLEWRAP, + SH_THUNDERCOIN, + SH_FLAMEAURA, + // Pity shield: the world's most basic shield ever, given to players who suck at Match + SH_PITY, + // The fireflower is special, it combines with other shields. + SH_FIREFLOWER = 0x100, + // The force shield uses the lower 8 bits to count how many hits are left. + SH_FORCE = 0x200, + + SH_STACK = SH_FIREFLOWER, + SH_NOSTACK = ~SH_STACK +} shieldtype_t; + +// Player powers. (don't edit this comment) +typedef enum +{ + pw_invulnerability, + pw_sneakers, + pw_flashing, + pw_shield, + pw_tailsfly, // tails flying + pw_underwater, // underwater timer + pw_spacetime, // In space, no one can hear you spin! + pw_extralife, // Extra Life timer + + pw_super, // Are you super? + pw_gravityboots, // gravity boots + + // Weapon ammunition + pw_infinityring, + pw_automaticring, + pw_bouncering, + pw_scatterring, + pw_grenadering, + pw_explosionring, + pw_railring, + + // Power Stones + pw_emeralds, // stored like global 'emeralds' variable + + // NiGHTS powerups + pw_nights_superloop, + pw_nights_helper, + pw_nights_linkfreeze, + + //for linedef exec 427 + pw_nocontrol, + pw_ingoop, // In goop + + NUMPOWERS +} powertype_t; + +#define WEP_AUTO 1 +#define WEP_BOUNCE 2 +#define WEP_SCATTER 3 +#define WEP_GRENADE 4 +#define WEP_EXPLODE 5 +#define WEP_RAIL 6 +#define NUM_WEAPONS 7 + +typedef enum +{ + RW_AUTO = 1, + RW_BOUNCE = 2, + RW_SCATTER = 4, + RW_GRENADE = 8, + RW_EXPLODE = 16, + RW_RAIL = 32 +} ringweapons_t; + +// ======================================================================== +// PLAYER STRUCTURE +// ======================================================================== +typedef struct player_s +{ + mobj_t *mo; + + // Caveat: ticcmd_t is ATTRPACK! Be careful what precedes it. + ticcmd_t cmd; + + playerstate_t playerstate; + + // Determine POV, including viewpoint bobbing during movement. + // Focal origin above r.z + fixed_t viewz; + // Base height above floor for viewz. + fixed_t viewheight; + // Bob/squat speed. + fixed_t deltaviewheight; + // bounded/scaled total momentum. + fixed_t bob; + + // Mouse aiming, where the guy is looking at! + // It is updated with cmd->aiming. + angle_t aiming; + + angle_t awayviewaiming; // Used for cut-away view + + // This is only used between levels, + // mo->health is used during levels. + INT32 health; + + SINT8 pity; // i pity the fool. + INT32 currentweapon; // current weapon selected. + INT32 ringweapons; // weapons currently obtained. + + // Power ups. invinc and invis are tic counters. + UINT16 powers[NUMPOWERS]; + + // Bit flags. + // See pflags_t, above. + pflags_t pflags; + + // playing animation. + panim_t panim; + + // For screen flashing (bright). + UINT16 flashcount; + UINT16 flashpal; + + // Player skin colorshift, 0-15 for which color to draw player. + UINT8 skincolor; + + INT32 skin; + + UINT32 score; // player score + fixed_t dashspeed; // dashing speed + INT32 dashtime; // tics dashing, used for rev sound + + fixed_t normalspeed; // Normal ground + fixed_t runspeed; // Speed you break into the run animation + UINT8 thrustfactor; // Thrust = thrustfactor * acceleration + UINT8 accelstart; // Starting acceleration if speed = 0. + UINT8 acceleration; // Acceleration + + // See charability_t and charability2_t for more information. + UINT8 charability; // Ability definition + UINT8 charability2; // Secondary ability definition + + UINT32 charflags; // Extra abilities/settings for skins (combinable stuff) + // See SF_ flags + + mobjtype_t thokitem; // Object # to spawn for the thok + mobjtype_t spinitem; // Object # to spawn for spindash/spinning + mobjtype_t revitem; // Object # to spawn for spindash/spinning + + fixed_t actionspd; // Speed of thok/glide/fly + fixed_t mindash; // Minimum spindash speed + fixed_t maxdash; // Maximum spindash speed + + fixed_t jumpfactor; // How high can the player jump? + + INT32 lives; + INT32 continues; // continues that player has acquired + + INT32 xtralife; // Ring Extra Life counter + UINT8 gotcontinue; // Got continue from this stage? + + fixed_t speed; // Player's speed (distance formula of MOMX and MOMY values) + INT32 jumping; // Jump counter + + UINT8 secondjump; + + UINT8 fly1; // Tails flying + UINT8 scoreadd; // Used for multiple enemy attack bonus + tic_t glidetime; // Glide counter for thrust + UINT8 climbing; // Climbing on the wall + INT32 deadtimer; // End game if game over lasts too long + tic_t exiting; // Exitlevel timer + + UINT8 homing; // Are you homing? + + tic_t skidtime; // Skid timer + + //////////////////////////// + // Conveyor Belt Movement // + //////////////////////////// + fixed_t cmomx; // Conveyor momx + fixed_t cmomy; // Conveyor momy + fixed_t rmomx; // "Real" momx (momx - cmomx) + fixed_t rmomy; // "Real" momy (momy - cmomy) + + ///////////////////// + // Race Mode Stuff // + ///////////////////// + INT32 numboxes; // Number of item boxes obtained for Race Mode + INT32 totalring; // Total number of rings obtained for Race Mode + tic_t realtime; // integer replacement for leveltime + UINT32 laps; // Number of laps (optional) + + //////////////////// + // CTF Mode Stuff // + //////////////////// + INT32 ctfteam; // 0 == Spectator, 1 == Red, 2 == Blue + UINT16 gotflag; // 1 == Red, 2 == Blue Do you have the flag? + + INT32 weapondelay; // Delay (if any) to fire the weapon again + INT32 tossdelay; // Delay (if any) to toss a flag/emeralds again + + // Starpost information + INT16 starpostx; + INT16 starposty; + INT16 starpostz; + INT32 starpostnum; // The number of the last starpost you hit + tic_t starposttime; // Your time when you hit the starpost + angle_t starpostangle; // Angle that the starpost is facing - you respawn facing this way + + ///////////////// + // NiGHTS Stuff// + ///////////////// + angle_t angle_pos; + angle_t old_angle_pos; + + mobj_t *axis1; + mobj_t *axis2; + tic_t bumpertime; // Currently being bounced by MT_NIGHTSBUMPER + INT32 flyangle; + tic_t drilltimer; + INT32 linkcount; + tic_t linktimer; + INT32 anotherflyangle; + tic_t nightstime; // How long you can fly as NiGHTS. + INT32 drillmeter; + UINT8 drilldelay; + boolean bonustime; // Capsule destroyed, now it's bonus time! + mobj_t *capsule; // Go inside the capsule + UINT8 mare; // Current mare + + // Statistical purposes. + tic_t marebegunat; // Leveltime when mare begun + tic_t startedtime; // Time which you started this mare with. + tic_t finishedtime; // Time it took you to finish the mare (used for display) + INT16 finishedrings; // The rings you had left upon finishing the mare + UINT32 marescore; // score for this nights stage + UINT32 lastmarescore; // score for the last mare + UINT8 lastmare; // previous mare + INT32 maxlink; // maximum link obtained + UINT8 texttimer; // nights_texttime should not be local + UINT8 textvar; // which line of NiGHTS text to show -- let's not use cheap hacks + + INT16 lastsidehit, lastlinehit; + + tic_t losstime; + UINT8 timeshit; // That's TIMES HIT, not TIME SHIT, you doofus! + + INT32 onconveyor; // You are on a conveyor belt if nonzero + + mobj_t *awayviewmobj; + INT32 awayviewtics; + + boolean spectator; + UINT8 bot; + + tic_t jointime; // Timer when player joins game to change skin/color +#ifdef HWRENDER + fixed_t fovadd; // adjust FOV for hw rendering +#endif +} player_t; + +#endif diff --git a/src/d_think.h b/src/d_think.h new file mode 100644 index 000000000..3bbcf5124 --- /dev/null +++ b/src/d_think.h @@ -0,0 +1,54 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 1993-1996 by id Software, Inc. +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Copyright (C) 1999-2014 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file d_think.h +/// \brief MapObj data. Map Objects or mobjs are actors, entities, +/// thinker, take-your-pick +/// +/// anything that moves, acts, or suffers state changes of more or less violent nature. + +#ifndef __D_THINK__ +#define __D_THINK__ + +#ifdef __GNUG__ +#pragma interface +#endif + +// +// Experimental stuff. +// To compile this as "ANSI C with classes" we will need to handle the various +// action functions cleanly. +// +typedef void (*actionf_v)(); +typedef void (*actionf_p1)(void *); + +typedef union +{ + actionf_v acv; + actionf_p1 acp1; +} actionf_t; + +// Historically, "think_t" is yet another function pointer to a routine +// to handle an actor. +typedef actionf_t think_t; + +// Doubly linked list of actors. +typedef struct thinker_s +{ + struct thinker_s *prev; + struct thinker_s *next; + think_t function; + + // killough 11/98: count of how many other objects reference + // this one using pointers. Used for garbage collection. + INT32 references; +} thinker_t; + +#endif diff --git a/src/d_ticcmd.h b/src/d_ticcmd.h new file mode 100644 index 000000000..41d25f2e9 --- /dev/null +++ b/src/d_ticcmd.h @@ -0,0 +1,69 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 1993-1996 by id Software, Inc. +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Copyright (C) 1999-2014 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file d_ticcmd.h +/// \brief Button/action code definitions, ticcmd_t + +#ifndef __D_TICCMD__ +#define __D_TICCMD__ + +#include "m_fixed.h" +#include "doomtype.h" + +#ifdef __GNUG__ +#pragma interface +#endif + +// Button/action code definitions. +typedef enum +{ + // First 4 bits are weapon change info, DO NOT USE! + BT_WEAPONMASK = 0x0F, //our first four bits. + + BT_WEAPONNEXT = 1<<4, + BT_WEAPONPREV = 1<<5, + + BT_ATTACK = 1<<6, // shoot rings + BT_USE = 1<<7, // spin + BT_CAMLEFT = 1<<8, // turn camera left + BT_CAMRIGHT = 1<<9, // turn camera right + BT_TOSSFLAG = 1<<10, + BT_JUMP = 1<<11, + BT_FIRENORMAL = 1<<12 // Fire a normal ring no matter what + // free: up to and including 1<<15 +} buttoncode_t; + +// The data sampled per tick (single player) +// and transmitted to other peers (multiplayer). +// Mainly movements/button commands per game tick, +// plus a checksum for internal state consistency. + +// bits in angleturn +#define TICCMD_RECEIVED 1 +#define TICCMD_XY 2 + +#if defined(_MSC_VER) +#pragma pack(1) +#endif + +typedef struct +{ + SINT8 forwardmove; // -MAXPLMOVE to MAXPLMOVE (50) + SINT8 sidemove; // -MAXPLMOVE to MAXPLMOVE (50) + INT16 angleturn; // <<16 for angle delta - saved as 1 byte into demos + INT16 aiming; // vertical aiming, see G_BuildTicCmd + UINT16 buttons; +} ATTRPACK ticcmd_t; + +#if defined(_MSC_VER) +#pragma pack() +#endif + +#endif diff --git a/src/dehacked.c b/src/dehacked.c new file mode 100644 index 000000000..a757f31e8 --- /dev/null +++ b/src/dehacked.c @@ -0,0 +1,8594 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Copyright (C) 1999-2014 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file dehacked.c +/// \brief Load dehacked file and change tables and text + +#include "doomdef.h" +#include "g_game.h" +#include "sounds.h" +#include "info.h" +#include "d_think.h" +#include "m_argv.h" +#include "z_zone.h" +#include "w_wad.h" +#include "m_menu.h" +#include "m_misc.h" +#include "f_finale.h" +#include "dehacked.h" +#include "st_stuff.h" +#include "i_system.h" +#include "p_local.h" // for var1 and var2, and some constants +#include "p_setup.h" +#include "r_data.h" +#include "fastcmp.h" +#include "lua_script.h" +#include "lua_hook.h" + +#include "m_cond.h" + +#ifdef HAVE_BLUA +#include "v_video.h" // video flags (for lua) +#endif + +#ifdef HWRENDER +#include "hardware/hw_light.h" +#endif + +#ifdef PC_DOS +#include // for snprintf +//int snprintf(char *str, size_t n, const char *fmt, ...); +int vsnprintf(char *str, size_t n, const char *fmt, va_list ap); +#endif + +// Free slot names +// The crazy word-reading stuff uses these. +static char *FREE_STATES[NUMSTATEFREESLOTS]; +static char *FREE_MOBJS[NUMMOBJFREESLOTS]; +static UINT8 used_spr[(NUMSPRITEFREESLOTS / 8) + 1]; // Bitwise flag for sprite freeslot in use! I would use ceil() here if I could, but it only saves 1 byte of memory anyway. +#define initfreeslots() {\ +memset(FREE_STATES,0,sizeof(char *) * NUMSTATEFREESLOTS);\ +memset(FREE_MOBJS,0,sizeof(char *) * NUMMOBJFREESLOTS);\ +memset(used_spr,0,sizeof(UINT8) * ((NUMSPRITEFREESLOTS / 8) + 1));\ +} + +// Crazy word-reading stuff +/// \todo Put these in a seperate file or something. +static mobjtype_t get_mobjtype(const char *word); +static statenum_t get_state(const char *word); +static spritenum_t get_sprite(const char *word); +static sfxenum_t get_sfx(const char *word); +static UINT16 get_mus(const char *word); +static hudnum_t get_huditem(const char *word); +#ifndef HAVE_BLUA +static powertype_t get_power(const char *word); +#endif + +boolean deh_loaded = false; +boolean modcredits = false; // Whether a mod creator's name will show in the credits. +char modcreditname[32]; +static int dbg_line; + +static boolean gamedataadded = false; + +#ifdef DELFILE +typedef struct undehacked_s +{ + char *undata; + struct undehacked_s *next; +} undehacked_t; + +static UINT16 unsocwad; +static undehacked_t *unsocdata[MAX_WADFILES]; +static boolean disableundo = false; + +void DEH_WriteUndoline(const char *value, const char *data, undotype_f flags) +{ + const char *eqstr = " = "; + const char *space = " "; + const char *pader = eqstr; + undehacked_t *newdata; + + if (disableundo || !unsocwad) + return; + + if ((newdata = malloc(sizeof(*newdata))) == NULL) + I_Error("Out of memory for unsoc line"); + + if (flags & UNDO_SPACE) + pader = space; + + if (flags & UNDO_ENDTEXT && !data) + data = space; + + if (value) + { + const size_t plen = strlen(pader); + const char *pound = "#"; + char *undata = NULL; + const size_t elen = strlen(pound); + size_t vlen = strlen(value), dlen = 0, len = 1; + + if (*(value+vlen-1) == '\n') + vlen--; // lnet not copy the ending \n + + if (flags & UNDO_ENDTEXT) + len += elen; // let malloc more space + + if (flags & UNDO_NEWLINE) + len++; // more space for the beginning \n + + if (data) + { + dlen = strlen(data); + if (flags & UNDO_CUTLINE && *(data+dlen-1) == '\n') + dlen--; // let not copy the ending \n + newdata->undata = malloc(vlen+plen+dlen+len); + newdata->undata[vlen+plen+dlen+len-1] = '\0'; + } + else + { + newdata->undata = malloc(vlen+len); + newdata->undata[vlen+len-1] = '\0'; + } + + if (newdata->undata) + { + undata = newdata->undata; + *undata = '\0'; + } + else + { + free(newdata); + I_Error("Out of memory for unsoc data"); + } + + if (flags & UNDO_NEWLINE) // let start with \n + strcat(undata, "\n"); + + strncat(undata, value, vlen); + + if (data) // value+pader+data + strncat(strncat(undata, pader, plen), data, dlen); + + if (flags & UNDO_ENDTEXT) // let end the text + strncat(undata, pound, elen); + } + else + newdata->undata = NULL; + + newdata->next = unsocdata[unsocwad]; + unsocdata[unsocwad] = newdata; +} +#endif + +ATTRINLINE static FUNCINLINE char myfget_color(MYFILE *f) +{ + char c = *f->curpos++; + if (c == '^') // oh, nevermind then. + return '^'; + + if (c >= '0' && c <= '9') + return 0x80+(c-'0'); + return 0x80; // Unhandled -- default to no color +} + +ATTRINLINE static FUNCINLINE char myfget_hex(MYFILE *f) +{ + char c = *f->curpos++, endchr = 0; + if (c == '\\') // oh, nevermind then. + return '\\'; + + if (c >= '0' && c <= '9') + endchr += (c-'0') << 4; + else if (c >= 'A' && c <= 'F') + endchr += ((c-'A') + 10) << 4; + else if (c >= 'a' && c <= 'f') + endchr += ((c-'a') + 10) << 4; + else // invalid. stop and return a question mark. + return '?'; + + c = *f->curpos++; + if (c >= '0' && c <= '9') + endchr += (c-'0'); + else if (c >= 'A' && c <= 'F') + endchr += ((c-'A') + 10); + else if (c >= 'a' && c <= 'f') + endchr += ((c-'a') + 10); + else // invalid. stop and return a question mark. + return '?'; + + return endchr; +} + +char *myfgets(char *buf, size_t bufsize, MYFILE *f) +{ + size_t i = 0; + if (myfeof(f)) + return NULL; + // we need one byte for a null terminated string + bufsize--; + while (i < bufsize && !myfeof(f)) + { + char c = *f->curpos++; + if (c == '^') + buf[i++] = myfget_color(f); + else if (c == '\\') + buf[i++] = myfget_hex(f); + else if (c != '\r') + buf[i++] = c; + if (c == '\n') + break; + } + buf[i] = '\0'; + + dbg_line++; + return buf; +} + +static char *myhashfgets(char *buf, size_t bufsize, MYFILE *f) +{ + size_t i = 0; + if (myfeof(f)) + return NULL; + // we need one byte for a null terminated string + bufsize--; + while (i < bufsize && !myfeof(f)) + { + char c = *f->curpos++; + if (c == '^') + buf[i++] = myfget_color(f); + else if (c == '\\') + buf[i++] = myfget_hex(f); + else if (c != '\r') + buf[i++] = c; + if (c == '\n') // Ensure debug line is right... + dbg_line++; + if (c == '#') + break; + } + i++; + buf[i] = '\0'; + + return buf; +} + +static INT32 deh_num_warning = 0; + +FUNCPRINTF static void deh_warning(const char *first, ...) +{ + va_list argptr; + char *buf = Z_Malloc(1000, PU_STATIC, NULL); + + va_start(argptr, first); + vsnprintf(buf, 1000, first, argptr); // sizeof only returned 4 here. it didn't like that pointer. + va_end(argptr); + + if(dbg_line == -1) // Not in a SOC, line number unknown. + CONS_Alert(CONS_WARNING, "%s\n", buf); + else + CONS_Alert(CONS_WARNING, "Line %u: %s\n", dbg_line, buf); + + deh_num_warning++; + + Z_Free(buf); +} + +static void deh_strlcpy(char *dst, const char *src, size_t size, const char *warntext) +{ + size_t len = strlen(src)+1; // Used to determine if truncation has been done + if (len > size) + deh_warning("%s exceeds max length of %s", warntext, sizeu1(size-1)); + strlcpy(dst, src, size); +} + +/* ======================================================================== */ +// Load a dehacked file format +/* ======================================================================== */ +/* a sample to see + Thing 1 (Player) { // MT_PLAYER +INT32 doomednum; ID # = 3232 -1, // doomednum +INT32 spawnstate; Initial frame = 32 "PLAY", // spawnstate +INT32 spawnhealth; Hit points = 3232 100, // spawnhealth +INT32 seestate; First moving frame = 32 "PLAY_RUN1", // seestate +INT32 seesound; Alert sound = 32 sfx_None, // seesound +INT32 reactiontime; Reaction time = 3232 0, // reactiontime +INT32 attacksound; Attack sound = 32 sfx_None, // attacksound +INT32 painstate; Injury frame = 32 "PLAY_PAIN", // painstate +INT32 painchance; Pain chance = 3232 255, // painchance +INT32 painsound; Pain sound = 32 sfx_plpain, // painsound +INT32 meleestate; Close attack frame = 32 "NULL", // meleestate +INT32 missilestate; Far attack frame = 32 "PLAY_ATK1", // missilestate +INT32 deathstate; Death frame = 32 "PLAY_DIE1", // deathstate +INT32 xdeathstate; Exploding frame = 32 "PLAY_XDIE1", // xdeathstate +INT32 deathsound; Death sound = 32 sfx_pldeth, // deathsound +INT32 speed; Speed = 3232 0, // speed +INT32 radius; Width = 211812352 16*FRACUNIT, // radius +INT32 height; Height = 211812352 56*FRACUNIT, // height +INT32 dispoffset; DispOffset = 0 0, // dispoffset +INT32 mass; Mass = 3232 100, // mass +INT32 damage; Missile damage = 3232 0, // damage +INT32 activesound; Action sound = 32 sfx_None, // activesound +INT32 flags; Bits = 3232 MF_SOLID|MF_SHOOTABLE|MF_DROPOFF|MF_PICKUP|MF_NOTDMATCH, +INT32 raisestate; Respawn frame = 32 S_NULL // raisestate + }, */ + +static INT32 searchvalue(const char *s) +{ + while (s[0] != '=' && s[0]) + s++; + if (s[0] == '=') + return atoi(&s[1]); + else + { + deh_warning("No value found"); + return 0; + } +} + +#ifdef HWRENDER +static float searchfvalue(const char *s) +{ + while (s[0] != '=' && s[0]) + s++; + if (s[0] == '=') + return (float)atof(&s[1]); + else + { + deh_warning("No value found"); + return 0; + } +} +#endif + +// These are for clearing all of various things +static void clear_conditionsets(void) +{ + UINT8 i; + for (i = 0; i < MAXCONDITIONSETS; ++i) + M_ClearConditionSet(i); +} + +static void clear_levels(void) +{ + INT16 i; + + // This is potentially dangerous but if we're resetting these headers, + // we may as well try to save some memory, right? + for (i = 0; i < NUMMAPS; ++i) + { + if (!mapheaderinfo[i]) + continue; + + P_DeleteGrades(i); + Z_Free(mapheaderinfo[i]); + mapheaderinfo[i] = NULL; + } + + // Realloc the one for the current gamemap as a safeguard + P_AllocMapHeader(gamemap-1); +} + +/* +// Edits an animated texture slot on the array +// Tails 12-27-2003 +static void readAnimTex(MYFILE *f, INT32 num) +{ + char s[MAXLINELEN]; + char *word; + char *word2; + INT32 i; + + do { + if (myfgets(s, sizeof s, f) != NULL) + { + if (s[0] == '\n') break; + + tmp = strchr(s, '#'); + if (tmp) + *tmp = '\0'; + // set the value in the appropriate field + + word = strtok(s, " "); + if (word) + strupr(word); + else + break; + + word2 = strtok(NULL, " = "); + if (word2) + strupr(word2); + else + break; + + if (word2[strlen(word2)-1] == '\n') + word2[strlen(word2)-1] = '\0'; + + i = atoi(word2); + + if (fastcmp(word, "START")) + strncpy(harddefs[num].startname, word2, 8); + if (fastcmp(word, "END")) + strncpy(harddefs[num].endname, word2, 8); + else if (fastcmp(word, "SPEED")) harddefs[num].speed = i; + else if (fastcmp(word, "ISTEXTURE")) harddefs[num].istexture = i; + + else deh_warning("readAnimTex %d: unknown word '%s'", num, word); + } + } while (s[0] != '\n' && !myfeof(f)); //finish when the line is empty +} +*/ + +static boolean findFreeSlot(INT32 *num) +{ + // Send the character select entry to a free slot. + while (*num < 32 && PlayerMenu[*num].status != IT_DISABLED) + *num = *num+1; + + // No more free slots. :( + if (*num >= 32) + return false; + + // Found one! ^_^ + return true; +} + +// Reads a player. +// For modifying the character select screen +static void readPlayer(MYFILE *f, INT32 num) +{ + char *s = Z_Malloc(MAXLINELEN, PU_STATIC, NULL); + char *word; + char *word2; + INT32 i; + boolean slotfound = false; + + DEH_WriteUndoline("PLAYERTEXT", description[num].notes, UNDO_ENDTEXT); + + do + { + if (myfgets(s, MAXLINELEN, f)) + { + if (s[0] == '\n') + break; + + word = strtok(s, " "); + if (word) + strupr(word); + else + break; + + if (fastcmp(word, "PLAYERTEXT")) + { + char *playertext = NULL; + + if (!slotfound && (slotfound = findFreeSlot(&num)) == false) + goto done; + + for (i = 0; i < MAXLINELEN-3; i++) + { + if (s[i] == '=') + { + playertext = &s[i+2]; + break; + } + } + if (playertext) + { + strcpy(description[num].notes, playertext); + strcat(description[num].notes, myhashfgets(playertext, sizeof (description[num].notes), f)); + } + else + strcpy(description[num].notes, ""); + + // For some reason, cutting the string did not work above. Most likely due to strcpy or strcat... + // It works down here, though. + { + INT32 numline = 0; + for (i = 0; i < MAXLINELEN-1; i++) + { + if (numline < 20 && description[num].notes[i] == '\n') + numline++; + + if (numline >= 20 || description[num].notes[i] == '\0' || description[num].notes[i] == '#') + break; + } + } + description[num].notes[strlen(description[num].notes)-1] = '\0'; + description[num].notes[i] = '\0'; + continue; + } + + word2 = strtok(NULL, " = "); + if (word2) + strupr(word2); + else + break; + + if (word2[strlen(word2)-1] == '\n') + word2[strlen(word2)-1] = '\0'; + i = atoi(word2); + + /*if (fastcmp(word, "PLAYERNAME")) + { + if (!slotfound && (slotfound = findFreeSlot(&num)) == false) + goto done; + DEH_WriteUndoline(word, description[num].text, UNDO_NONE); + strlcpy(description[num].text, word2, sizeof (description[num].text)); + for (word2 = description[num].text; *word2; word2++) + if (*word2 == '_') + *word2 = ' '; + PlayerMenu[num].text = description[num].text; + }*/ +/* else if (fastcmp(word, "MENUPOSITION")) + { // Make sure you make MENUPOSITION the first thing under CHARACTER if you're using it! + // This is to manually choose a slot and overwrite existing characters! It is NOT necessary for most individual character wads!! +#ifdef DELFILE + if (disableundo) +#endif + { + slotfound = true; + num = i; + } + } */ + /*else*/ if (fastcmp(word, "PICNAME")) + { + if (!slotfound && (slotfound = findFreeSlot(&num)) == false) + goto done; + DEH_WriteUndoline(word, &description[num].picname[0], UNDO_NONE); + strncpy(description[num].picname, word2, 8); + } + else if (fastcmp(word, "STATUS")) + { + // Limit the status to only IT_DISABLED and IT_CALL + if (i) + i = IT_CALL; + else + i = IT_DISABLED; + + /* + You MAY disable previous entries if you so desire... + But try to enable something that's already enabled and you will be sent to a free slot. + + Because of this, you are allowed to edit any previous entrys you like, but only if you + signal that you are purposely doing so by disabling and then reenabling the slot. + + ... Or use MENUPOSITION first, that works too. Hell, you could edit multiple character + slots in a single section that way, due to how SOC editing works. + */ + if (i != IT_DISABLED && !slotfound && (slotfound = findFreeSlot(&num)) == false) + goto done; + DEH_WriteUndoline(word, va("%d", PlayerMenu[num].status), UNDO_NONE); + PlayerMenu[num].status = (INT16)i; + } + else if (fastcmp(word, "SKINNAME")) + { + // Send to free slot. + if (!slotfound && (slotfound = findFreeSlot(&num)) == false) + goto done; + DEH_WriteUndoline(word, description[num].skinname, UNDO_NONE); + strlcpy(description[num].skinname, word2, sizeof description[num].skinname); + strlwr(description[num].skinname); + } + else + deh_warning("readPlayer %d: unknown word '%s'", num, word); + } + } while (!myfeof(f)); // finish when the line is empty + +#ifdef DELFILE + if (slotfound) + DEH_WriteUndoline("MENUPOSITION", va("%d", num), UNDO_NONE); +#endif + +done: + Z_Free(s); +} + +// TODO: Figure out how to do undolines for this.... +// TODO: Warnings for running out of freeslots +static void readfreeslots(MYFILE *f) +{ + char *s = Z_Malloc(MAXLINELEN, PU_STATIC, NULL); + char *word,*type; + char *tmp; + int i; + + do + { + if (myfgets(s, MAXLINELEN, f)) + { + if (s[0] == '\n') + break; + + tmp = strchr(s, '#'); + if (tmp) + *tmp = '\0'; + if (s == tmp) + continue; // Skip comment lines, but don't break. + + type = strtok(s, "_"); + if (type) + strupr(type); + else + break; + + word = strtok(NULL, "\n"); + if (word) + strupr(word); + else + break; + + // TODO: Check for existing freeslot mobjs/states/etc. and make errors. + // TODO: Out-of-slots warnings/errors. + // TODO: Name too long (truncated) warnings. + if (fastcmp(type, "SFX")) + S_AddSoundFx(word, false, -1, false); + else if (fastcmp(type, "SPR")) + { + for (i = SPR_FIRSTFREESLOT; i <= SPR_LASTFREESLOT; i++) + { + if (used_spr[(i-SPR_FIRSTFREESLOT)/8] & (1<<(i%8))) + { + if (!sprnames[i][4] && memcmp(sprnames[i],word,4)==0) + sprnames[i][4] = (char)f->wad; + continue; // Already allocated, next. + } + // Found a free slot! + strncpy(sprnames[i],word,4); + //sprnames[i][4] = 0; + used_spr[(i-SPR_FIRSTFREESLOT)/8] |= 1<<(i%8); // Okay, this sprite slot has been named now. + break; + } + } + else if (fastcmp(type, "S")) + { + for (i = 0; i < NUMSTATEFREESLOTS; i++) + if (!FREE_STATES[i]) { + FREE_STATES[i] = Z_Malloc(strlen(word)+1, PU_STATIC, NULL); + strcpy(FREE_STATES[i],word); + break; + } + } + else if (fastcmp(type, "MT")) + { + for (i = 0; i < NUMMOBJFREESLOTS; i++) + if (!FREE_MOBJS[i]) { + FREE_MOBJS[i] = Z_Malloc(strlen(word)+1, PU_STATIC, NULL); + strcpy(FREE_MOBJS[i],word); + break; + } + } + else + deh_warning("Freeslots: unknown enum class '%s' for '%s_%s'", type, type, word); + } + } while (!myfeof(f)); // finish when the line is empty + + Z_Free(s); +} + +static void readthing(MYFILE *f, INT32 num) +{ + char *s = Z_Malloc(MAXLINELEN, PU_STATIC, NULL); + char *word, *word2; + char *tmp; + + do + { + if (myfgets(s, MAXLINELEN, f)) + { + if (s[0] == '\n') + break; + + tmp = strchr(s, '#'); + if (tmp) + *tmp = '\0'; + if (s == tmp) + continue; // Skip comment lines, but don't break. + + word = strtok(s, " "); + if (word) + strupr(word); + else + break; + + word2 = strtok(NULL, " = "); + if (word2) + strupr(word2); + else + break; + if (word2[strlen(word2)-1] == '\n') + word2[strlen(word2)-1] = '\0'; + + if (fastcmp(word, "MAPTHINGNUM") || fastcmp(word, "DOOMEDNUM")) + { + DEH_WriteUndoline(word, va("%d", mobjinfo[num].doomednum), UNDO_NONE); + mobjinfo[num].doomednum = (INT32)atoi(word2); + } + else if (fastcmp(word, "SPAWNSTATE")) + { + DEH_WriteUndoline(word, va("%d", mobjinfo[num].spawnstate), UNDO_NONE); + mobjinfo[num].spawnstate = get_number(word2); + } + else if (fastcmp(word, "SPAWNHEALTH")) + { + DEH_WriteUndoline(word, va("%d", mobjinfo[num].spawnhealth), UNDO_NONE); + mobjinfo[num].spawnhealth = (INT32)get_number(word2); + } + else if (fastcmp(word, "SEESTATE")) + { + DEH_WriteUndoline(word, va("%d", mobjinfo[num].seestate), UNDO_NONE); + mobjinfo[num].seestate = get_number(word2); + } + else if (fastcmp(word, "SEESOUND")) + { + DEH_WriteUndoline(word, va("%d", mobjinfo[num].seesound), UNDO_NONE); + mobjinfo[num].seesound = get_number(word2); + } + else if (fastcmp(word, "REACTIONTIME")) + { + DEH_WriteUndoline(word, va("%d", mobjinfo[num].reactiontime), UNDO_NONE); + mobjinfo[num].reactiontime = (INT32)get_number(word2); + } + else if (fastcmp(word, "ATTACKSOUND")) + { + DEH_WriteUndoline(word, va("%d", mobjinfo[num].attacksound), UNDO_NONE); + mobjinfo[num].attacksound = get_number(word2); + } + else if (fastcmp(word, "PAINSTATE")) + { + DEH_WriteUndoline(word, va("%d", mobjinfo[num].painstate), UNDO_NONE); + mobjinfo[num].painstate = get_number(word2); + } + else if (fastcmp(word, "PAINCHANCE")) + { + DEH_WriteUndoline(word, va("%d", mobjinfo[num].painchance), UNDO_NONE); + mobjinfo[num].painchance = (INT32)get_number(word2); + } + else if (fastcmp(word, "PAINSOUND")) + { + DEH_WriteUndoline(word, va("%d", mobjinfo[num].painsound), UNDO_NONE); + mobjinfo[num].painsound = get_number(word2); + } + else if (fastcmp(word, "MELEESTATE")) + { + DEH_WriteUndoline(word, va("%d", mobjinfo[num].meleestate), UNDO_NONE); + mobjinfo[num].meleestate = get_number(word2); + } + else if (fastcmp(word, "MISSILESTATE")) + { + DEH_WriteUndoline(word, va("%d", mobjinfo[num].missilestate), UNDO_NONE); + mobjinfo[num].missilestate = get_number(word2); + } + else if (fastcmp(word, "DEATHSTATE")) + { + DEH_WriteUndoline(word, va("%d", mobjinfo[num].deathstate), UNDO_NONE); + mobjinfo[num].deathstate = get_number(word2); + } + else if (fastcmp(word, "DEATHSOUND")) + { + DEH_WriteUndoline(word, va("%d", mobjinfo[num].deathsound), UNDO_NONE); + mobjinfo[num].deathsound = get_number(word2); + } + else if (fastcmp(word, "XDEATHSTATE")) + { + DEH_WriteUndoline(word, va("%d", mobjinfo[num].xdeathstate), UNDO_NONE); + mobjinfo[num].xdeathstate = get_number(word2); + } + else if (fastcmp(word, "SPEED")) + { + DEH_WriteUndoline(word, va("%d", mobjinfo[num].speed), UNDO_NONE); + mobjinfo[num].speed = get_number(word2); + } + else if (fastcmp(word, "RADIUS")) + { + DEH_WriteUndoline(word, va("%d", mobjinfo[num].radius), UNDO_NONE); + mobjinfo[num].radius = get_number(word2); + } + else if (fastcmp(word, "HEIGHT")) + { + DEH_WriteUndoline(word, va("%d", mobjinfo[num].height), UNDO_NONE); + mobjinfo[num].height = get_number(word2); + } + else if (fastcmp(word, "DISPOFFSET")) + { + DEH_WriteUndoline(word, va("%d", mobjinfo[num].dispoffset), UNDO_NONE); + mobjinfo[num].dispoffset = get_number(word2); + } + else if (fastcmp(word, "MASS")) + { + DEH_WriteUndoline(word, va("%d", mobjinfo[num].mass), UNDO_NONE); + mobjinfo[num].mass = (INT32)get_number(word2); + } + else if (fastcmp(word, "DAMAGE")) + { + DEH_WriteUndoline(word, va("%d", mobjinfo[num].damage), UNDO_NONE); + mobjinfo[num].damage = (INT32)get_number(word2); + } + else if (fastcmp(word, "ACTIVESOUND")) + { + DEH_WriteUndoline(word, va("%d", mobjinfo[num].activesound), UNDO_NONE); + mobjinfo[num].activesound = get_number(word2); + } + else if (fastcmp(word, "FLAGS")) + { + DEH_WriteUndoline(word, va("%d", mobjinfo[num].flags), UNDO_NONE); + mobjinfo[num].flags = (INT32)get_number(word2); + } + else if (fastcmp(word, "RAISESTATE")) + { + DEH_WriteUndoline(word, va("%d", mobjinfo[num].raisestate), UNDO_NONE); + mobjinfo[num].raisestate = get_number(word2); + } + else + deh_warning("Thing %d: unknown word '%s'", num, word); + } + } while (!myfeof(f)); // finish when the line is empty + + Z_Free(s); +} + +#ifdef HWRENDER +static void readlight(MYFILE *f, INT32 num) +{ + char *s = Z_Malloc(MAXLINELEN, PU_STATIC, NULL); + char *word; + char *tmp; + INT32 value; + float fvalue; + + do + { + if (myfgets(s, MAXLINELEN, f)) + { + if (s[0] == '\n') + break; + + tmp = strchr(s, '#'); + if (tmp) + *tmp = '\0'; + if (s == tmp) + continue; // Skip comment lines, but don't break. + + fvalue = searchfvalue(s); + value = searchvalue(s); + + word = strtok(s, " "); + if (word) + strupr(word); + else + break; + + if (fastcmp(word, "TYPE")) + { + DEH_WriteUndoline(word, va("%d", lspr[num].type), UNDO_NONE); + lspr[num].type = (UINT16)value; + } + else if (fastcmp(word, "OFFSETX")) + { + DEH_WriteUndoline(word, va("%f", lspr[num].light_xoffset), UNDO_NONE); + lspr[num].light_xoffset = fvalue; + } + else if (fastcmp(word, "OFFSETY")) + { + DEH_WriteUndoline(word, va("%f", lspr[num].light_yoffset), UNDO_NONE); + lspr[num].light_yoffset = fvalue; + } + else if (fastcmp(word, "CORONACOLOR")) + { + DEH_WriteUndoline(word, va("%u", lspr[num].corona_color), UNDO_NONE); + lspr[num].corona_color = value; + } + else if (fastcmp(word, "CORONARADIUS")) + { + DEH_WriteUndoline(word, va("%f", lspr[num].corona_radius), UNDO_NONE); + lspr[num].corona_radius = fvalue; + } + else if (fastcmp(word, "DYNAMICCOLOR")) + { + DEH_WriteUndoline(word, va("%u", lspr[num].dynamic_color), UNDO_NONE); + lspr[num].dynamic_color = value; + } + else if (fastcmp(word, "DYNAMICRADIUS")) + { + DEH_WriteUndoline(word, va("%f", lspr[num].dynamic_radius), UNDO_NONE); + lspr[num].dynamic_radius = fvalue; + + /// \note Update the sqrradius! unnecessary? + lspr[num].dynamic_sqrradius = fvalue * fvalue; + } + else + deh_warning("Light %d: unknown word '%s'", num, word); + } + } while (!myfeof(f)); // finish when the line is empty + + Z_Free(s); +} + +static void readspritelight(MYFILE *f, INT32 num) +{ + char *s = Z_Malloc(MAXLINELEN, PU_STATIC, NULL); + char *word; + char *tmp; + INT32 value; + + do + { + if (myfgets(s, MAXLINELEN, f)) + { + if (s[0] == '\n') + break; + + tmp = strchr(s, '#'); + if (tmp) + *tmp = '\0'; + if (s == tmp) + continue; // Skip comment lines, but don't break. + + value = searchvalue(s); + + word = strtok(s, " "); + if (word) + strupr(word); + else + break; + + if (fastcmp(word, "LIGHTTYPE")) + { + INT32 oldvar; + for (oldvar = 0; t_lspr[num] != &lspr[oldvar]; oldvar++) + ; + DEH_WriteUndoline(word, va("%d", oldvar), UNDO_NONE); + t_lspr[num] = &lspr[value]; + } + else + deh_warning("Sprite %d: unknown word '%s'", num, word); + } + } while (!myfeof(f)); // finish when the line is empty + + Z_Free(s); +} +#endif // HWRENDER + +static const struct { + const char *name; + const UINT16 flag; +} TYPEOFLEVEL[] = { + {"SOLO",TOL_SP}, + {"SP",TOL_SP}, + {"SINGLEPLAYER",TOL_SP}, + {"SINGLE",TOL_SP}, + + {"COOP",TOL_COOP}, + {"CO-OP",TOL_COOP}, + + {"COMPETITION",TOL_COMPETITION}, + {"RACE",TOL_RACE}, + + {"MATCH",TOL_MATCH}, + {"TAG",TOL_TAG}, + {"CTF",TOL_CTF}, + + {"CUSTOM",TOL_CUSTOM}, + + {"2D",TOL_2D}, + {"MARIO",TOL_MARIO}, + {"NIGHTS",TOL_NIGHTS}, + {"OLDBRAK",TOL_ERZ3}, + + {"XMAS",TOL_XMAS}, + {"CHRISTMAS",TOL_XMAS}, + {"WINTER",TOL_XMAS}, + + {NULL, 0} +}; + +static void readlevelheader(MYFILE *f, INT32 num) +{ + char *s = Z_Malloc(MAXLINELEN, PU_STATIC, NULL); + char *word = s; + char *word2; + char *tmp; + INT32 i; + + // Reset all previous map header information + // This call automatically saves all previous information when DELFILE is defined. + // We don't need to do it ourselves. + P_AllocMapHeader((INT16)(num-1)); + + do + { + if (myfgets(s, MAXLINELEN, f)) + { + if (s[0] == '\n') + break; + + // First remove trailing newline, if there is one + tmp = strchr(s, '\n'); + if (tmp) + *tmp = '\0'; + + tmp = strchr(s, '#'); + if (tmp) + *tmp = '\0'; + if (s == tmp) + continue; // Skip comment lines, but don't break. + + // Get the part before the " = " + tmp = strchr(s, '='); + *(tmp-1) = '\0'; + strupr(word); + + // Now get the part after + word2 = tmp += 2; + i = atoi(word2); // used for numerical settings + + // CHEAP HACK: move this over here for lowercase subtitles + if (fastcmp(word, "SUBTITLE")) + { + deh_strlcpy(mapheaderinfo[num-1]->subttl, word2, + sizeof(mapheaderinfo[num-1]->subttl), va("Level header %d: subtitle", num)); + continue; + } + + // Now go to uppercase + strupr(word2); + + // NiGHTS grades + if (fastncmp(word, "GRADES", 6)) + { + UINT8 mare = (UINT8)atoi(word + 6); + + if (mare <= 0 || mare > 8) + { + deh_warning("Level header %d: unknown word '%s'", num, word); + continue; + } + P_AddGradesForMare((INT16)(num-1), mare-1, word2); + } + + // Strings that can be truncated + else if (fastcmp(word, "LEVELNAME")) + deh_strlcpy(mapheaderinfo[num-1]->lvlttl, word2, + sizeof(mapheaderinfo[num-1]->lvlttl), va("Level header %d: levelname", num)); + else if (fastcmp(word, "SCRIPTNAME")) + deh_strlcpy(mapheaderinfo[num-1]->scriptname, word2, + sizeof(mapheaderinfo[num-1]->scriptname), va("Level header %d: scriptname", num)); + else if (fastcmp(word, "RUNSOC")) + deh_strlcpy(mapheaderinfo[num-1]->runsoc, word2, + sizeof(mapheaderinfo[num-1]->runsoc), va("Level header %d: runsoc", num)); + else if (fastcmp(word, "ACT")) + { + if (i >= 0 && i < 20) // 0 for no act number, TTL1 through TTL19 + mapheaderinfo[num-1]->actnum = (UINT8)i; + else + deh_warning("Level header %d: invalid act number %d", num, i); + } + else if (fastcmp(word, "NEXTLEVEL")) + { + // Support using the actual map name, + // i.e., Nextlevel = AB, Nextlevel = FZ, etc. + + // Convert to map number + if (word2[0] >= 'A' && word2[0] <= 'Z' && word2[2] == '\0') + i = M_MapNumber(word2[0], word2[1]); + + mapheaderinfo[num-1]->nextlevel = (INT16)i; + } + else if (fastcmp(word, "TYPEOFLEVEL")) + { + if (i) // it's just a number + mapheaderinfo[num-1]->typeoflevel = (UINT16)i; + else + { + UINT16 tol = 0; + tmp = strtok(word2,","); + do { + for (i = 0; TYPEOFLEVEL[i].name; i++) + if (fastcmp(tmp, TYPEOFLEVEL[i].name)) + break; + if (!TYPEOFLEVEL[i].name) + deh_warning("Level header %d: unknown typeoflevel flag %s\n", num, tmp); + tol |= TYPEOFLEVEL[i].flag; + } while((tmp = strtok(NULL,",")) != NULL); + mapheaderinfo[num-1]->typeoflevel = tol; + } + } + else if (fastcmp(word, "MUSICSLOT")) + { + // Convert to map number + if (word2[0] >= 'A' && word2[0] <= 'Z' && word2[2] == '\0') + i = M_MapNumber(word2[0], word2[1]); + + if (i) // it's just a number + mapheaderinfo[num-1]->musicslot = (UINT16)i; + else // No? Okay, now we'll get technical. + mapheaderinfo[num-1]->musicslot = get_mus(word2); // accepts all of O_CHRSEL, mus_chrsel, or just plain ChrSel + } + else if (fastcmp(word, "MUSICSLOTTRACK")) + mapheaderinfo[num-1]->musicslottrack = ((UINT16)i - 1); + else if (fastcmp(word, "FORCECHARACTER")) + { + strlcpy(mapheaderinfo[num-1]->forcecharacter, word2, SKINNAMESIZE+1); + strlwr(mapheaderinfo[num-1]->forcecharacter); // skin names are lowercase + } + else if (fastcmp(word, "WEATHER")) + mapheaderinfo[num-1]->weather = (UINT8)get_number(word2); + else if (fastcmp(word, "SKYNUM")) + mapheaderinfo[num-1]->skynum = (INT16)i; + else if (fastcmp(word, "INTERSCREEN")) + strncpy(mapheaderinfo[num-1]->interscreen, word2, 8); + else if (fastcmp(word, "PRECUTSCENENUM")) + mapheaderinfo[num-1]->precutscenenum = (UINT8)i; + else if (fastcmp(word, "CUTSCENENUM")) + mapheaderinfo[num-1]->cutscenenum = (UINT8)i; + else if (fastcmp(word, "COUNTDOWN")) + mapheaderinfo[num-1]->countdown = (INT16)i; + else if (fastcmp(word, "PALETTE")) + mapheaderinfo[num-1]->palette = (UINT16)i; + else if (fastcmp(word, "NUMLAPS")) + mapheaderinfo[num-1]->numlaps = (UINT32)i; + else if (fastcmp(word, "UNLOCKABLE")) + { + if (i >= 0 && i <= MAXUNLOCKABLES) // 0 for no unlock required, anything else requires something + mapheaderinfo[num-1]->unlockrequired = (SINT8)i - 1; + else + deh_warning("Level header %d: invalid unlockable number %d", num, i); + } + else if (fastcmp(word, "LEVELSELECT")) + mapheaderinfo[num-1]->levelselect = (UINT8)i; + else if (fastcmp(word, "SKYBOXSCALE")) + mapheaderinfo[num-1]->skybox_scalex = mapheaderinfo[num-1]->skybox_scaley = mapheaderinfo[num-1]->skybox_scalez = (INT16)i; + else if (fastcmp(word, "SKYBOXSCALEX")) + mapheaderinfo[num-1]->skybox_scalex = (INT16)i; + else if (fastcmp(word, "SKYBOXSCALEY")) + mapheaderinfo[num-1]->skybox_scaley = (INT16)i; + else if (fastcmp(word, "SKYBOXSCALEZ")) + mapheaderinfo[num-1]->skybox_scalez = (INT16)i; + + else if (fastcmp(word, "BONUSTYPE")) + { + if (fastcmp(word2, "NONE")) i = -1; + else if (fastcmp(word2, "NORMAL")) i = 0; + else if (fastcmp(word2, "BOSS")) i = 1; + else if (fastcmp(word2, "ERZ3")) i = 2; + + if (i >= -1 && i <= 2) // -1 for no bonus. Max is 2. + mapheaderinfo[num-1]->bonustype = (SINT8)i; + else + deh_warning("Level header %d: invalid bonus type number %d", num, i); + } + + else if (fastcmp(word, "LEVELFLAGS")) + mapheaderinfo[num-1]->levelflags = (UINT8)i; + else if (fastcmp(word, "MENUFLAGS")) + mapheaderinfo[num-1]->menuflags = (UINT8)i; + + // Individual triggers for level flags, for ease of use (and 2.0 compatibility) + else if (fastcmp(word, "SCRIPTISFILE")) + { + if (i || word2[0] == 'T' || word2[0] == 'Y') + mapheaderinfo[num-1]->levelflags |= LF_SCRIPTISFILE; + else + mapheaderinfo[num-1]->levelflags &= ~LF_SCRIPTISFILE; + } + else if (fastcmp(word, "SPEEDMUSIC")) + { + if (i || word2[0] == 'T' || word2[0] == 'Y') + mapheaderinfo[num-1]->levelflags |= LF_SPEEDMUSIC; + else + mapheaderinfo[num-1]->levelflags &= ~LF_SPEEDMUSIC; + } + else if (fastcmp(word, "NOSSMUSIC")) + { + if (i || word2[0] == 'T' || word2[0] == 'Y') + mapheaderinfo[num-1]->levelflags |= LF_NOSSMUSIC; + else + mapheaderinfo[num-1]->levelflags &= ~LF_NOSSMUSIC; + } + else if (fastcmp(word, "NORELOAD")) + { + if (i || word2[0] == 'T' || word2[0] == 'Y') + mapheaderinfo[num-1]->levelflags |= LF_NORELOAD; + else + mapheaderinfo[num-1]->levelflags &= ~LF_NORELOAD; + } + else if (fastcmp(word, "NOZONE")) + { + if (i || word2[0] == 'T' || word2[0] == 'Y') + mapheaderinfo[num-1]->levelflags |= LF_NOZONE; + else + mapheaderinfo[num-1]->levelflags &= ~LF_NOZONE; + } + + // Individual triggers for menu flags + else if (fastcmp(word, "HIDDEN")) + { + if (i || word2[0] == 'T' || word2[0] == 'Y') + mapheaderinfo[num-1]->menuflags |= LF2_HIDEINMENU; + else + mapheaderinfo[num-1]->menuflags &= ~LF2_HIDEINMENU; + } + else if (fastcmp(word, "HIDEINSTATS")) + { + if (i || word2[0] == 'T' || word2[0] == 'Y') + mapheaderinfo[num-1]->menuflags |= LF2_HIDEINSTATS; + else + mapheaderinfo[num-1]->menuflags &= ~LF2_HIDEINSTATS; + } + else if (fastcmp(word, "RECORDATTACK") || fastcmp(word, "TIMEATTACK")) + { // TIMEATTACK is an accepted alias + if (i || word2[0] == 'T' || word2[0] == 'Y') + mapheaderinfo[num-1]->menuflags |= LF2_RECORDATTACK; + else + mapheaderinfo[num-1]->menuflags &= ~LF2_RECORDATTACK; + } + else if (fastcmp(word, "NIGHTSATTACK")) + { + if (i || word2[0] == 'T' || word2[0] == 'Y') + mapheaderinfo[num-1]->menuflags |= LF2_NIGHTSATTACK; + else + mapheaderinfo[num-1]->menuflags &= LF2_NIGHTSATTACK; + } + else if (fastcmp(word, "NOVISITNEEDED")) + { + if (i || word2[0] == 'T' || word2[0] == 'Y') + mapheaderinfo[num-1]->menuflags |= LF2_NOVISITNEEDED; + else + mapheaderinfo[num-1]->menuflags &= ~LF2_NOVISITNEEDED; + } + + else + deh_warning("Level header %d: unknown word '%s'", num, word); + } + } while (!myfeof(f)); // finish when the line is empty + + Z_Free(s); +} + +static void readcutscenescene(MYFILE *f, INT32 num, INT32 scenenum) +{ + char *s = Z_Calloc(MAXLINELEN, PU_STATIC, NULL); + char *word; + char *word2; + INT32 i; + UINT16 usi; + UINT8 picid; + + DEH_WriteUndoline("SCENETEXT", cutscenes[num]->scene[scenenum].text, UNDO_ENDTEXT); + + do + { + if (myfgets(s, MAXLINELEN, f)) + { + if (s[0] == '\n') + break; + + word = strtok(s, " "); + if (word) + strupr(word); + else + break; + + if (fastcmp(word, "SCENETEXT")) + { + char *scenetext = NULL; + char *buffer; + const int bufferlen = 4096; + + for (i = 0; i < MAXLINELEN; i++) + { + if (s[i] == '=') + { + scenetext = &s[i+2]; + break; + } + } + + if (!scenetext) + { + Z_Free(cutscenes[num]->scene[scenenum].text); + cutscenes[num]->scene[scenenum].text = NULL; + continue; + } + + for (i = 0; i < MAXLINELEN; i++) + { + if (s[i] == '\0') + { + s[i] = '\n'; + s[i+1] = '\0'; + break; + } + } + + buffer = Z_Malloc(4096, PU_STATIC, NULL); + strcpy(buffer, scenetext); + + strcat(buffer, + myhashfgets(scenetext, bufferlen + - strlen(buffer) - 1, f)); + + // A cutscene overwriting another one... + Z_Free(cutscenes[num]->scene[scenenum].text); + + cutscenes[num]->scene[scenenum].text = Z_StrDup(buffer); + + Z_Free(buffer); + + continue; + } + + word2 = strtok(NULL, " = "); + if (word2) + strupr(word2); + else + break; + + if (word2[strlen(word2)-1] == '\n') + word2[strlen(word2)-1] = '\0'; + i = atoi(word2); + usi = (UINT16)i; + + + if (fastcmp(word, "NUMBEROFPICS")) + { + DEH_WriteUndoline(word, va("%d", cutscenes[num]->scene[scenenum].numpics), UNDO_NONE); + cutscenes[num]->scene[scenenum].numpics = (UINT8)i; + } + else if (fastncmp(word, "PIC", 3)) + { + picid = (UINT8)atoi(word + 3); + if (picid > 8 || picid == 0) + { + deh_warning("CutSceneScene %d: unknown word '%s'", num, word); + continue; + } + --picid; + + if (fastcmp(word+4, "NAME")) + { + DEH_WriteUndoline(word, cutscenes[num]->scene[scenenum].picname[picid], UNDO_NONE); + strncpy(cutscenes[num]->scene[scenenum].picname[picid], word2, 8); + } + else if (fastcmp(word+4, "HIRES")) + { + DEH_WriteUndoline(word, va("%d", cutscenes[num]->scene[scenenum].pichires[picid]), UNDO_NONE); + cutscenes[num]->scene[scenenum].pichires[picid] = (UINT8)(i || word2[0] == 'T' || word2[0] == 'Y'); + } + else if (fastcmp(word+4, "DURATION")) + { + DEH_WriteUndoline(word, va("%u", cutscenes[num]->scene[scenenum].picduration[picid]), UNDO_NONE); + cutscenes[num]->scene[scenenum].picduration[picid] = usi; + } + else if (fastcmp(word+4, "XCOORD")) + { + DEH_WriteUndoline(word, va("%u", cutscenes[num]->scene[scenenum].xcoord[picid]), UNDO_NONE); + cutscenes[num]->scene[scenenum].xcoord[picid] = usi; + } + else if (fastcmp(word+4, "YCOORD")) + { + DEH_WriteUndoline(word, va("%u", cutscenes[num]->scene[scenenum].ycoord[picid]), UNDO_NONE); + cutscenes[num]->scene[scenenum].ycoord[picid] = usi; + } + else + deh_warning("CutSceneScene %d: unknown word '%s'", num, word); + } + else if (fastcmp(word, "MUSICSLOT")) + { + DEH_WriteUndoline(word, va("%u", cutscenes[num]->scene[scenenum].musicslot), UNDO_NONE); + cutscenes[num]->scene[scenenum].musicslot = get_mus(word2); // accepts all of O_MAP01M, mus_map01m, or just plain MAP01M + } + else if (fastcmp(word, "MUSICLOOP")) + { + DEH_WriteUndoline(word, va("%u", cutscenes[num]->scene[scenenum].musicloop), UNDO_NONE); + cutscenes[num]->scene[scenenum].musicloop = (UINT8)(i || word2[0] == 'T' || word2[0] == 'Y'); + } + else if (fastcmp(word, "TEXTXPOS")) + { + DEH_WriteUndoline(word, va("%u", cutscenes[num]->scene[scenenum].textxpos), UNDO_NONE); + cutscenes[num]->scene[scenenum].textxpos = usi; + } + else if (fastcmp(word, "TEXTYPOS")) + { + DEH_WriteUndoline(word, va("%u", cutscenes[num]->scene[scenenum].textypos), UNDO_NONE); + cutscenes[num]->scene[scenenum].textypos = usi; + } + else if (fastcmp(word, "FADEINID")) + { + DEH_WriteUndoline(word, va("%u", cutscenes[num]->scene[scenenum].fadenum), UNDO_NONE); + cutscenes[num]->scene[scenenum].fadeinid = (UINT8)i; + } + else if (fastcmp(word, "FADEOUTID")) + { + DEH_WriteUndoline(word, va("%u", cutscenes[num]->scene[scenenum].fadenum), UNDO_NONE); + cutscenes[num]->scene[scenenum].fadeoutid = (UINT8)i; + } + else if (fastcmp(word, "FADECOLOR")) + { + DEH_WriteUndoline(word, va("%u", cutscenes[num]->scene[scenenum].fadenum), UNDO_NONE); + cutscenes[num]->scene[scenenum].fadecolor = (UINT8)i; + } + else + deh_warning("CutSceneScene %d: unknown word '%s'", num, word); + } + } while (!myfeof(f)); // finish when the line is empty + + Z_Free(s); +} + +static void readcutscene(MYFILE *f, INT32 num) +{ + char *s = Z_Malloc(MAXLINELEN, PU_STATIC, NULL); + char *word; + char *word2; + char *tmp; + INT32 value; +#ifdef DELFILE + const INT32 oldnumscenes = cutscenes[num]->numscenes; +#endif + + // Allocate memory for this cutscene if we don't yet have any + if (!cutscenes[num]) + cutscenes[num] = Z_Calloc(sizeof (cutscene_t), PU_STATIC, NULL); + + do + { + if (myfgets(s, MAXLINELEN, f)) + { + if (s[0] == '\n') + break; + + tmp = strchr(s, '#'); + if (tmp) + *tmp = '\0'; + if (s == tmp) + continue; // Skip comment lines, but don't break. + + word = strtok(s, " "); + if (word) + strupr(word); + else + break; + + word2 = strtok(NULL, " "); + if (word2) + value = atoi(word2); + else + { + deh_warning("No value for token %s", word); + continue; + } + + if (fastcmp(word, "NUMSCENES")) + { + cutscenes[num]->numscenes = value; + } + else if (fastcmp(word, "SCENE")) + { + if (1 <= value && value <= 128) + { + readcutscenescene(f, num, value - 1); + DEH_WriteUndoline(word, word2, UNDO_SPACE|UNDO_CUTLINE); + DEH_WriteUndoline("NUMSCENES", va("%d", oldnumscenes), UNDO_SPACE); + } + else + deh_warning("Scene number %d out of range (1 - 128)", value); + + } + else + deh_warning("Cutscene %d: unknown word '%s', Scene expected.", num, word); + } + } while (!myfeof(f)); // finish when the line is empty + + Z_Free(s); +} + +static void readhuditem(MYFILE *f, INT32 num) +{ + char *s = Z_Malloc(MAXLINELEN, PU_STATIC, NULL); + char *word = s; + char *word2; + char *tmp; + INT32 i; + + do + { + if (myfgets(s, MAXLINELEN, f)) + { + if (s[0] == '\n') + break; + + // First remove trailing newline, if there is one + tmp = strchr(s, '\n'); + if (tmp) + *tmp = '\0'; + + tmp = strchr(s, '#'); + if (tmp) + *tmp = '\0'; + if (s == tmp) + continue; // Skip comment lines, but don't break. + + // Get the part before the " = " + tmp = strchr(s, '='); + *(tmp-1) = '\0'; + strupr(word); + + // Now get the part after + word2 = tmp += 2; + strupr(word2); + + i = atoi(word2); // used for numerical settings + + if (fastcmp(word, "X")) + { + DEH_WriteUndoline(word, va("%d", hudinfo[num].x), UNDO_NONE); + hudinfo[num].x = i; + } + else if (fastcmp(word, "Y")) + { + DEH_WriteUndoline(word, va("%d", hudinfo[num].y), UNDO_NONE); + hudinfo[num].y = i; + } + else + deh_warning("Level header %d: unknown word '%s'", num, word); + } + } while (!myfeof(f)); // finish when the line is empty + + Z_Free(s); +} + +/* +Sprite number = 10 +Sprite subnumber = 32968 +Duration = 200 +Next frame = 200 +*/ + +/** Action pointer for reading actions from Dehacked lumps. + */ +typedef struct +{ + actionf_t action; ///< Function pointer corresponding to the actual action. + const char *name; ///< Name of the action in ALL CAPS. +} actionpointer_t; + +/** Array mapping action names to action functions. + * Names must be in ALL CAPS for case insensitive comparisons. + */ +static actionpointer_t actionpointers[] = +{ + {{A_Explode}, "A_EXPLODE"}, + {{A_Pain}, "A_PAIN"}, + {{A_Fall}, "A_FALL"}, + {{A_MonitorPop}, "A_MONITORPOP"}, + {{A_Look}, "A_LOOK"}, + {{A_Chase}, "A_CHASE"}, + {{A_FaceStabChase}, "A_FACESTABCHASE"}, + {{A_FaceTarget}, "A_FACETARGET"}, + {{A_FaceTracer}, "A_FACETRACER"}, + {{A_Scream}, "A_SCREAM"}, + {{A_BossDeath}, "A_BOSSDEATH"}, + {{A_CustomPower}, "A_CUSTOMPOWER"}, + {{A_GiveWeapon}, "A_GIVEWEAPON"}, + {{A_RingShield}, "A_RINGSHIELD"}, + {{A_RingBox}, "A_RINGBOX"}, + {{A_Invincibility}, "A_INVINCIBILITY"}, + {{A_SuperSneakers}, "A_SUPERSNEAKERS"}, + {{A_BunnyHop}, "A_BUNNYHOP"}, + {{A_BubbleSpawn}, "A_BUBBLESPAWN"}, + {{A_FanBubbleSpawn}, "A_FANBUBBLESPAWN"}, + {{A_BubbleRise}, "A_BUBBLERISE"}, + {{A_BubbleCheck}, "A_BUBBLECHECK"}, + {{A_AwardScore}, "A_AWARDSCORE"}, + {{A_ExtraLife}, "A_EXTRALIFE"}, + {{A_BombShield}, "A_BOMBSHIELD"}, + {{A_JumpShield}, "A_JUMPSHIELD"}, + {{A_WaterShield}, "A_WATERSHIELD"}, + {{A_ForceShield}, "A_FORCESHIELD"}, + {{A_PityShield}, "A_PITYSHIELD"}, + {{A_GravityBox}, "A_GRAVITYBOX"}, + {{A_ScoreRise}, "A_SCORERISE"}, + {{A_ParticleSpawn}, "A_PARTICLESPAWN"}, + {{A_AttractChase}, "A_ATTRACTCHASE"}, + {{A_DropMine}, "A_DROPMINE"}, + {{A_FishJump}, "A_FISHJUMP"}, + {{A_ThrownRing}, "A_THROWNRING"}, + {{A_SetSolidSteam}, "A_SETSOLIDSTEAM"}, + {{A_UnsetSolidSteam}, "A_UNSETSOLIDSTEAM"}, + {{A_SignPlayer}, "A_SIGNPLAYER"}, + {{A_OverlayThink}, "A_OVERLAYTHINK"}, + {{A_JetChase}, "A_JETCHASE"}, + {{A_JetbThink}, "A_JETBTHINK"}, + {{A_JetgThink}, "A_JETGTHINK"}, + {{A_JetgShoot}, "A_JETGSHOOT"}, + {{A_ShootBullet}, "A_SHOOTBULLET"}, + {{A_MinusDigging}, "A_MINUSDIGGING"}, + {{A_MinusPopup}, "A_MINUSPOPUP"}, + {{A_MinusCheck}, "A_MINUSCHECK"}, + {{A_ChickenCheck}, "A_CHICKENCHECK"}, + {{A_MouseThink}, "A_MOUSETHINK"}, + {{A_DetonChase}, "A_DETONCHASE"}, + {{A_CapeChase}, "A_CAPECHASE"}, + {{A_RotateSpikeBall}, "A_ROTATESPIKEBALL"}, + {{A_SlingAppear}, "A_SLINGAPPEAR"}, + {{A_MaceRotate}, "A_MACEROTATE"}, + {{A_UnidusBall}, "A_UNIDUSBALL"}, + {{A_RockSpawn}, "A_ROCKSPAWN"}, + {{A_SetFuse}, "A_SETFUSE"}, + {{A_CrawlaCommanderThink}, "A_CRAWLACOMMANDERTHINK"}, + {{A_SmokeTrailer}, "A_SMOKETRAILER"}, + {{A_RingExplode}, "A_RINGEXPLODE"}, + {{A_OldRingExplode}, "A_OLDRINGEXPLODE"}, + {{A_MixUp}, "A_MIXUP"}, + {{A_RecyclePowers}, "A_RECYCLEPOWERS"}, + {{A_Boss1Chase}, "A_BOSS1CHASE"}, + {{A_FocusTarget}, "A_FOCUSTARGET"}, + {{A_Boss2Chase}, "A_BOSS2CHASE"}, + {{A_Boss2Pogo}, "A_BOSS2POGO"}, + {{A_BossZoom}, "A_BOSSZOOM"}, + {{A_BossScream}, "A_BOSSSCREAM"}, + {{A_Boss2TakeDamage}, "A_BOSS2TAKEDAMAGE"}, + {{A_Boss7Chase}, "A_BOSS7CHASE"}, + {{A_GoopSplat}, "A_GOOPSPLAT"}, + {{A_Boss2PogoSFX}, "A_BOSS2POGOSFX"}, + {{A_Boss2PogoTarget}, "A_BOSS2POGOTARGET"}, + {{A_BossJetFume}, "A_BOSSJETFUME"}, + {{A_EggmanBox}, "A_EGGMANBOX"}, + {{A_TurretFire}, "A_TURRETFIRE"}, + {{A_SuperTurretFire}, "A_SUPERTURRETFIRE"}, + {{A_TurretStop}, "A_TURRETSTOP"}, + {{A_JetJawRoam}, "A_JETJAWROAM"}, + {{A_JetJawChomp}, "A_JETJAWCHOMP"}, + {{A_PointyThink}, "A_POINTYTHINK"}, + {{A_CheckBuddy}, "A_CHECKBUDDY"}, + {{A_HoodThink}, "A_HOODTHINK"}, + {{A_ArrowCheck}, "A_ARROWCHECK"}, + {{A_SnailerThink}, "A_SNAILERTHINK"}, + {{A_SharpChase}, "A_SHARPCHASE"}, + {{A_SharpSpin}, "A_SHARPSPIN"}, + {{A_VultureVtol}, "A_VULTUREVTOL"}, + {{A_VultureCheck}, "A_VULTURECHECK"}, + {{A_SkimChase}, "A_SKIMCHASE"}, + {{A_1upThinker}, "A_1UPTHINKER"}, + {{A_SkullAttack}, "A_SKULLATTACK"}, + {{A_LobShot}, "A_LOBSHOT"}, + {{A_FireShot}, "A_FIRESHOT"}, + {{A_SuperFireShot}, "A_SUPERFIRESHOT"}, + {{A_BossFireShot}, "A_BOSSFIRESHOT"}, + {{A_Boss7FireMissiles}, "A_BOSS7FIREMISSILES"}, + {{A_Boss1Laser}, "A_BOSS1LASER"}, + {{A_Boss4Reverse}, "A_BOSS4REVERSE"}, + {{A_Boss4SpeedUp}, "A_BOSS4SPEEDUP"}, + {{A_Boss4Raise}, "A_BOSS4RAISE"}, + {{A_SparkFollow}, "A_SPARKFOLLOW"}, + {{A_BuzzFly}, "A_BUZZFLY"}, + {{A_GuardChase}, "A_GUARDCHASE"}, + {{A_EggShield}, "A_EGGSHIELD"}, + {{A_SetReactionTime}, "A_SETREACTIONTIME"}, + {{A_Boss1Spikeballs}, "A_BOSS1SPIKEBALLS"}, + {{A_Boss3TakeDamage}, "A_BOSS3TAKEDAMAGE"}, + {{A_Boss3Path}, "A_BOSS3PATH"}, + {{A_LinedefExecute}, "A_LINEDEFEXECUTE"}, + {{A_PlaySeeSound}, "A_PLAYSEESOUND"}, + {{A_PlayAttackSound}, "A_PLAYATTACKSOUND"}, + {{A_PlayActiveSound}, "A_PLAYACTIVESOUND"}, + {{A_SpawnObjectAbsolute}, "A_SPAWNOBJECTABSOLUTE"}, + {{A_SpawnObjectRelative}, "A_SPAWNOBJECTRELATIVE"}, + {{A_ChangeAngleRelative}, "A_CHANGEANGLERELATIVE"}, + {{A_ChangeAngleAbsolute}, "A_CHANGEANGLEABSOLUTE"}, + {{A_PlaySound}, "A_PLAYSOUND"}, + {{A_FindTarget}, "A_FINDTARGET"}, + {{A_FindTracer}, "A_FINDTRACER"}, + {{A_SetTics}, "A_SETTICS"}, + {{A_SetRandomTics}, "A_SETRANDOMTICS"}, + {{A_ChangeColorRelative}, "A_CHANGECOLORRELATIVE"}, + {{A_ChangeColorAbsolute}, "A_CHANGECOLORABSOLUTE"}, + {{A_MoveRelative}, "A_MOVERELATIVE"}, + {{A_MoveAbsolute}, "A_MOVEABSOLUTE"}, + {{A_Thrust}, "A_THRUST"}, + {{A_ZThrust}, "A_ZTHRUST"}, + {{A_SetTargetsTarget}, "A_SETTARGETSTARGET"}, + {{A_SetObjectFlags}, "A_SETOBJECTFLAGS"}, + {{A_SetObjectFlags2}, "A_SETOBJECTFLAGS2"}, + {{A_RandomState}, "A_RANDOMSTATE"}, + {{A_RandomStateRange}, "A_RANDOMSTATERANGE"}, + {{A_DualAction}, "A_DUALACTION"}, + {{A_RemoteAction}, "A_REMOTEACTION"}, + {{A_ToggleFlameJet}, "A_TOGGLEFLAMEJET"}, + {{A_OrbitNights}, "A_ORBITNIGHTS"}, + {{A_GhostMe}, "A_GHOSTME"}, + {{A_SetObjectState}, "A_SETOBJECTSTATE"}, + {{A_SetObjectTypeState}, "A_SETOBJECTTYPESTATE"}, + {{A_KnockBack}, "A_KNOCKBACK"}, + {{A_PushAway}, "A_PUSHAWAY"}, + {{A_RingDrain}, "A_RINGDRAIN"}, + {{A_SplitShot}, "A_SPLITSHOT"}, + {{A_MissileSplit}, "A_MISSILESPLIT"}, + {{A_MultiShot}, "A_MULTISHOT"}, + {{A_InstaLoop}, "A_INSTALOOP"}, + {{A_Custom3DRotate}, "A_CUSTOM3DROTATE"}, + {{A_SearchForPlayers}, "A_SEARCHFORPLAYERS"}, + {{A_CheckRandom}, "A_CHECKRANDOM"}, + {{A_CheckTargetRings}, "A_CHECKTARGETRINGS"}, + {{A_CheckRings}, "A_CHECKRINGS"}, + {{A_CheckTotalRings}, "A_CHECKTOTALRINGS"}, + {{A_CheckHealth}, "A_CHECKHEALTH"}, + {{A_CheckRange}, "A_CHECKRANGE"}, + {{A_CheckHeight}, "A_CHECKHEIGHT"}, + {{A_CheckTrueRange}, "A_CHECKTRUERANGE"}, + {{A_CheckThingCount}, "A_CHECKTHINGCOUNT"}, + {{A_CheckAmbush}, "A_CHECKAMBUSH"}, + {{A_CheckCustomValue}, "A_CHECKCUSTOMVALUE"}, + {{A_CheckCusValMemo}, "A_CHECKCUSVALMEMO"}, + {{A_SetCustomValue}, "A_SETCUSTOMVALUE"}, + {{A_UseCusValMemo}, "A_USECUSVALMEMO"}, + {{A_RelayCustomValue}, "A_RELAYCUSTOMVALUE"}, + {{A_CusValAction}, "A_CUSVALACTION"}, + {{A_ForceStop}, "A_FORCESTOP"}, + {{A_ForceWin}, "A_FORCEWIN"}, + {{A_SpikeRetract}, "A_SPIKERETRACT"}, + {{A_InfoState}, "A_INFOSTATE"}, + {{A_Repeat}, "A_REPEAT"}, + {{A_SetScale}, "A_SETSCALE"}, + {{A_RemoteDamage}, "A_REMOTEDAMAGE"}, + {{A_HomingChase}, "A_HOMINGCHASE"}, + {{A_TrapShot}, "A_TRAPSHOT"}, + {{A_VileTarget}, "A_VILETARGET"}, + {{A_VileAttack}, "A_VILEATTACK"}, + {{A_VileFire}, "A_VILEFIRE"}, + {{A_BrakChase}, "A_BRAKCHASE"}, + {{A_BrakFireShot}, "A_BRAKFIRESHOT"}, + {{A_BrakLobShot}, "A_BRAKLOBSHOT"}, + {{A_NapalmScatter}, "A_NAPALMSCATTER"}, + {{A_SpawnFreshCopy}, "A_SPAWNFRESHCOPY"}, + + {{NULL}, "NONE"}, + + // This NULL entry must be the last in the list + {{NULL}, NULL}, +}; + +static void readframe(MYFILE *f, INT32 num) +{ + char *s = Z_Malloc(MAXLINELEN, PU_STATIC, NULL); + char *word1; + char *word2 = NULL; + char *tmp; + INT32 j; + + do + { + if (myfgets(s, MAXLINELEN, f)) + { + if (s[0] == '\n') + break; + + tmp = strchr(s, '#'); + if (tmp) + *tmp = '\0'; + if (s == tmp) + continue; // Skip comment lines, but don't break. + + for (j = 0; s[j] != '\n'; j++) + { + if (s[j] == '=') + { + j += 2; + j = atoi(&s[j]); + break; + } + } + + word1 = strtok(s, " "); + if (word1) + strupr(word1); + else + break; + + word2 = strtok(NULL, " = "); + if (word2) + strupr(word2); + else + break; + if (word2[strlen(word2)-1] == '\n') + word2[strlen(word2)-1] = '\0'; + + if (fastcmp(word1, "SPRITENUMBER") || fastcmp(word1, "SPRITENAME")) + { + DEH_WriteUndoline(word1, va("%u", states[num].sprite), UNDO_NONE); + states[num].sprite = get_sprite(word2); + } + else if (fastcmp(word1, "SPRITESUBNUMBER") || fastcmp(word1, "SPRITEFRAME")) + { + DEH_WriteUndoline(word1, va("%d", states[num].frame), UNDO_NONE); + states[num].frame = (INT32)get_number(word2); // So the FF_ flags get calculated + } + else if (fastcmp(word1, "DURATION")) + { + DEH_WriteUndoline(word1, va("%u", states[num].tics), UNDO_NONE); + states[num].tics = (INT32)get_number(word2); // So TICRATE can be used + } + else if (fastcmp(word1, "NEXT")) + { + DEH_WriteUndoline(word1, va("%d", states[num].nextstate), UNDO_NONE); + states[num].nextstate = get_state(word2); + } + else if (fastcmp(word1, "VAR1")) + { + DEH_WriteUndoline(word1, va("%d", states[num].var1), UNDO_NONE); + states[num].var1 = (INT32)get_number(word2); + } + else if (fastcmp(word1, "VAR2")) + { + DEH_WriteUndoline(word1, va("%d", states[num].var2), UNDO_NONE); + states[num].var2 = (INT32)get_number(word2); + } + else if (fastcmp(word1, "ACTION")) + { + size_t z; + boolean found = false; + XBOXSTATIC char actiontocompare[32]; + + memset(actiontocompare, 0x00, sizeof(actiontocompare)); + strlcpy(actiontocompare, word2, sizeof (actiontocompare)); + strupr(actiontocompare); + + for (z = 0; z < 32; z++) + { + if (actiontocompare[z] == '\n' || actiontocompare[z] == '\r') + { + actiontocompare[z] = '\0'; + break; + } + } + + for (z = 0; actionpointers[z].name; z++) + { + if (actionpointers[z].action.acv == states[num].action.acv) + { + DEH_WriteUndoline(word1, actionpointers[z].name, UNDO_NONE); + break; + } + } + + z = 0; +#ifdef HAVE_BLUA + found = LUA_SetLuaAction(&states[num], actiontocompare); + if (!found) +#endif + while (actionpointers[z].name) + { + if (fastcmp(actiontocompare, actionpointers[z].name)) + { + states[num].action = actionpointers[z].action; + states[num].action.acv = actionpointers[z].action.acv; // assign + states[num].action.acp1 = actionpointers[z].action.acp1; + found = true; + break; + } + z++; + } + + if (!found) + deh_warning("Unknown action %s", actiontocompare); + } + else + deh_warning("Frame %d: unknown word '%s'", num, word1); + } + } while (!myfeof(f)); + + Z_Free(s); +} + +static void readsound(MYFILE *f, INT32 num, const char *savesfxnames[]) +{ + char *s = Z_Malloc(MAXLINELEN, PU_STATIC, NULL); + char *word; + char *tmp; + INT32 value; + + do + { + if (myfgets(s, MAXLINELEN, f)) + { + if (s[0] == '\n') + break; + + tmp = strchr(s, '#'); + if (tmp) + *tmp = '\0'; + + value = searchvalue(s); + + word = strtok(s, " "); + if (word) + strupr(word); + else + break; + +/* if (fastcmp(word, "OFFSET")) + { + value -= 150360; + if (value <= 64) + value /= 8; + else if (value <= 260) + value = (value+4)/8; + else + value = (value+8)/8; + if (value >= -1 && value < sfx_freeslot0 - 1) + S_sfx[num].name = savesfxnames[value+1]; + else + deh_warning("Sound %d: offset out of bounds", num); + } + else */if (fastcmp(word, "SINGULAR")) + { + DEH_WriteUndoline(word, va("%d", S_sfx[num].singularity), UNDO_NONE); + S_sfx[num].singularity = value; + } + else if (fastcmp(word, "PRIORITY")) + { + DEH_WriteUndoline(word, va("%d", S_sfx[num].priority), UNDO_NONE); + S_sfx[num].priority = value; + } + else if (fastcmp(word, "FLAGS")) + { + DEH_WriteUndoline(word, va("%d", S_sfx[num].pitch), UNDO_NONE); + S_sfx[num].pitch = value; + } + else + deh_warning("Sound %d : unknown word '%s'",num,word); + } + } while (!myfeof(f)); + + Z_Free(s); + + (void)savesfxnames; +} + +/** Checks if a game data file name for a mod is good. + * "Good" means that it contains only alphanumerics, _, and -; + * ends in ".dat"; has at least one character before the ".dat"; + * and is not "gamedata.dat" (tested case-insensitively). + * + * Assumption: that gamedata.dat is the only .dat file that will + * ever be treated specially by the game. + * + * Note: Check for the tail ".dat" case-insensitively since at + * present, we get passed the filename in all uppercase. + * + * \param s Filename string to check. + * \return True if the filename is good. + * \sa readmaincfg() + * \author Graue + */ +static boolean GoodDataFileName(const char *s) +{ + const char *p; + const char *tail = ".dat"; + + for (p = s; *p != '\0'; p++) + if (!isalnum(*p) && *p != '_' && *p != '-' && *p != '.') + return false; + + p = s + strlen(s) - strlen(tail); + if (p <= s) return false; // too short + if (!fasticmp(p, tail)) return false; // doesn't end in .dat +#ifdef DELFILE + if (fasticmp(s, "gamedata.dat") && !disableundo) return false; +#else + if (fasticmp(s, "gamedata.dat")) return false; +#endif + + return true; +} + +static void reademblemdata(MYFILE *f, INT32 num) +{ + char *s = Z_Malloc(MAXLINELEN, PU_STATIC, NULL); + char *word = s; + char *word2; + char *tmp; + INT32 value; + + // Reset all data initially + DEH_WriteUndoline("TYPE", va("%d", emblemlocations[num-1].type), UNDO_NONE); + DEH_WriteUndoline("X", va("%d", emblemlocations[num-1].x), UNDO_NONE); + DEH_WriteUndoline("Y", va("%d", emblemlocations[num-1].y), UNDO_NONE); + DEH_WriteUndoline("Z", va("%d", emblemlocations[num-1].z), UNDO_NONE); + DEH_WriteUndoline("MAPNUM", va("%d", emblemlocations[num-1].level), UNDO_NONE); + DEH_WriteUndoline("VAR", va("%d", emblemlocations[num-1].var), UNDO_NONE); + DEH_WriteUndoline("SPRITE", va("%d", emblemlocations[num-1].sprite), UNDO_NONE); + DEH_WriteUndoline("COLOR", va("%d", emblemlocations[num-1].color), UNDO_NONE); + DEH_WriteUndoline("HINT", extraemblems[num-1].hint, UNDO_NONE); + + memset(&emblemlocations[num-1], 0, sizeof(emblem_t)); + + do + { + if (myfgets(s, MAXLINELEN, f)) + { + if (s[0] == '\n') + break; + + // First remove trailing newline, if there is one + tmp = strchr(s, '\n'); + if (tmp) + *tmp = '\0'; + + tmp = strchr(s, '#'); + if (tmp) + *tmp = '\0'; + if (s == tmp) + continue; // Skip comment lines, but don't break. + + // Get the part before the " = " + tmp = strchr(s, '='); + *(tmp-1) = '\0'; + strupr(word); + + // Now get the part after + word2 = tmp += 2; + value = atoi(word2); // used for numerical settings + + // Up here to allow lowercase in hints + if (fastcmp(word, "HINT")) + { + while ((tmp = strchr(word2, '\\'))) + *tmp = '\n'; + deh_strlcpy(emblemlocations[num-1].hint, word2, sizeof (emblemlocations[num-1].hint), va("Emblem %d: hint", num)); + continue; + } + strupr(word2); + + if (fastcmp(word, "TYPE")) + { + if (fastcmp(word2, "GLOBAL")) + emblemlocations[num-1].type = ET_GLOBAL; + else if (fastcmp(word2, "SKIN")) + emblemlocations[num-1].type = ET_SKIN; + else if (fastcmp(word2, "SCORE")) + emblemlocations[num-1].type = ET_SCORE; + else if (fastcmp(word2, "TIME")) + emblemlocations[num-1].type = ET_TIME; + else if (fastcmp(word2, "RINGS")) + emblemlocations[num-1].type = ET_RINGS; + else if (fastcmp(word2, "NGRADE")) + emblemlocations[num-1].type = ET_NGRADE; + else if (fastcmp(word2, "NTIME")) + emblemlocations[num-1].type = ET_NTIME; + else + emblemlocations[num-1].type = (UINT8)value; + } + else if (fastcmp(word, "X")) + emblemlocations[num-1].x = (INT16)value; + else if (fastcmp(word, "Y")) + emblemlocations[num-1].y = (INT16)value; + else if (fastcmp(word, "Z")) + emblemlocations[num-1].z = (INT16)value; + else if (fastcmp(word, "MAPNUM")) + { + // Support using the actual map name, + // i.e., Level AB, Level FZ, etc. + + // Convert to map number + if (word2[0] >= 'A' && word2[0] <= 'Z') + value = M_MapNumber(word2[0], word2[1]); + + emblemlocations[num-1].level = (INT16)value; + } + else if (fastcmp(word, "SPRITE")) + { + if (word2[0] >= 'A' && word2[0] <= 'Z') + value = word2[0]; + else + value += 'A'-1; + + if (value < 'A' || value > 'Z') + deh_warning("Emblem %d: sprite must be from A - Z (1 - 26)", num); + else + emblemlocations[num-1].sprite = (UINT8)value; + } + else if (fastcmp(word, "COLOR")) + emblemlocations[num-1].color = get_number(word2); + else if (fastcmp(word, "VAR")) + emblemlocations[num-1].var = get_number(word2); + else + deh_warning("Emblem %d: unknown word '%s'", num, word); + } + } while (!myfeof(f)); + + // Default sprite and color definitions for lazy people like me + if (!emblemlocations[num-1].sprite) switch (emblemlocations[num-1].type) + { + case ET_RINGS: + emblemlocations[num-1].sprite = 'R'; break; + case ET_SCORE: case ET_NGRADE: + emblemlocations[num-1].sprite = 'S'; break; + case ET_TIME: case ET_NTIME: + emblemlocations[num-1].sprite = 'T'; break; + default: + emblemlocations[num-1].sprite = 'A'; break; + } + if (!emblemlocations[num-1].color) switch (emblemlocations[num-1].type) + { + case ET_RINGS: + emblemlocations[num-1].color = SKINCOLOR_GOLD; break; + case ET_SCORE: + emblemlocations[num-1].color = SKINCOLOR_BROWN; break; + case ET_NGRADE: + emblemlocations[num-1].color = SKINCOLOR_TEAL; break; + case ET_TIME: case ET_NTIME: + emblemlocations[num-1].color = SKINCOLOR_GREY; break; + default: + emblemlocations[num-1].color = SKINCOLOR_BLUE; break; + } + + Z_Free(s); +} + +static void readextraemblemdata(MYFILE *f, INT32 num) +{ + char *s = Z_Malloc(MAXLINELEN, PU_STATIC, NULL); + char *word = s; + char *word2; + char *tmp; + INT32 value; + + // Reset all data initially + DEH_WriteUndoline("NAME", extraemblems[num-1].name, UNDO_NONE); + DEH_WriteUndoline("OBJECTIVE", extraemblems[num-1].description, UNDO_NONE); + DEH_WriteUndoline("CONDITIONSET", va("%d", extraemblems[num-1].conditionset), UNDO_NONE); + DEH_WriteUndoline("SPRITE", va("%d", extraemblems[num-1].sprite), UNDO_NONE); + DEH_WriteUndoline("COLOR", va("%d", extraemblems[num-1].color), UNDO_NONE); + + memset(&extraemblems[num-1], 0, sizeof(extraemblem_t)); + + do + { + if (myfgets(s, MAXLINELEN, f)) + { + if (s[0] == '\n') + break; + + // First remove trailing newline, if there is one + tmp = strchr(s, '\n'); + if (tmp) + *tmp = '\0'; + + tmp = strchr(s, '#'); + if (tmp) + *tmp = '\0'; + if (s == tmp) + continue; // Skip comment lines, but don't break. + + // Get the part before the " = " + tmp = strchr(s, '='); + *(tmp-1) = '\0'; + strupr(word); + + // Now get the part after + word2 = tmp += 2; + strupr(word2); + + value = atoi(word2); // used for numerical settings + + if (fastcmp(word, "NAME")) + deh_strlcpy(extraemblems[num-1].name, word2, + sizeof (extraemblems[num-1].name), va("Extra emblem %d: name", num)); + else if (fastcmp(word, "OBJECTIVE")) + deh_strlcpy(extraemblems[num-1].description, word2, + sizeof (extraemblems[num-1].description), va("Extra emblem %d: objective", num)); + else if (fastcmp(word, "CONDITIONSET")) + extraemblems[num-1].conditionset = (UINT8)value; + else if (fastcmp(word, "SPRITE")) + { + if (word2[0] >= 'A' && word2[0] <= 'Z') + value = word2[0]; + else + value += 'A'-1; + + if (value < 'A' || value > 'Z') + deh_warning("Emblem %d: sprite must be from A - Z (1 - 26)", num); + else + extraemblems[num-1].sprite = (UINT8)value; + } + else if (fastcmp(word, "COLOR")) + extraemblems[num-1].color = get_number(word2); + else + deh_warning("Extra emblem %d: unknown word '%s'", num, word); + } + } while (!myfeof(f)); + + if (!extraemblems[num-1].sprite) + extraemblems[num-1].sprite = 'X'; + if (!extraemblems[num-1].color) + extraemblems[num-1].color = SKINCOLOR_BLUE; + + Z_Free(s); +} + +static void readunlockable(MYFILE *f, INT32 num) +{ + char *s = Z_Malloc(MAXLINELEN, PU_STATIC, NULL); + char *word = s; + char *word2; + char *tmp; + INT32 i; + + // Same deal with unlockables, clear all first + DEH_WriteUndoline("NAME", unlockables[num].name, UNDO_NONE); + DEH_WriteUndoline("OBJECTIVE", unlockables[num].objective, UNDO_NONE); + DEH_WriteUndoline("HEIGHT", va("%d", unlockables[num].height), UNDO_NONE); + DEH_WriteUndoline("CONDITIONSET", va("%d", unlockables[num].conditionset), UNDO_NONE); + DEH_WriteUndoline("TYPE", va("%d", unlockables[num].type), UNDO_NONE); + DEH_WriteUndoline("NOCECHO", va("%d", unlockables[num].nocecho), UNDO_NONE); + DEH_WriteUndoline("NOCHECKLIST", va("%d", unlockables[num].nochecklist), UNDO_NONE); + DEH_WriteUndoline("VAR", va("%d", unlockables[num].variable), UNDO_NONE); + + memset(&unlockables[num], 0, sizeof(unlockable_t)); + + do + { + if (myfgets(s, MAXLINELEN, f)) + { + if (s[0] == '\n') + break; + + // First remove trailing newline, if there is one + tmp = strchr(s, '\n'); + if (tmp) + *tmp = '\0'; + + tmp = strchr(s, '#'); + if (tmp) + *tmp = '\0'; + if (s == tmp) + continue; // Skip comment lines, but don't break. + + // Get the part before the " = " + tmp = strchr(s, '='); + *(tmp-1) = '\0'; + strupr(word); + + // Now get the part after + word2 = tmp += 2; + strupr(word2); + + i = atoi(word2); // used for numerical settings + + if (fastcmp(word, "NAME")) + deh_strlcpy(unlockables[num].name, word2, + sizeof (unlockables[num].name), va("Unlockable %d: name", num)); + else if (fastcmp(word, "OBJECTIVE")) + deh_strlcpy(unlockables[num].objective, word2, + sizeof (unlockables[num].objective), va("Unlockable %d: objective", num)); + else if (fastcmp(word, "HEIGHT")) + unlockables[num].height = (UINT16)i; + else if (fastcmp(word, "CONDITIONSET")) + unlockables[num].conditionset = (UINT8)i; + else if (fastcmp(word, "NOCECHO")) + unlockables[num].nocecho = (UINT8)(i || word2[0] == 'T' || word2[0] == 'Y'); + else if (fastcmp(word, "NOCHECKLIST")) + unlockables[num].nochecklist = (UINT8)(i || word2[0] == 'T' || word2[0] == 'Y'); + else if (fastcmp(word, "TYPE")) + { + if (fastcmp(word2, "NONE")) + unlockables[num].type = SECRET_NONE; + else if (fastcmp(word2, "ITEMFINDER")) + unlockables[num].type = SECRET_ITEMFINDER; + else if (fastcmp(word2, "EMBLEMHINTS")) + unlockables[num].type = SECRET_EMBLEMHINTS; + else if (fastcmp(word2, "PANDORA")) + unlockables[num].type = SECRET_PANDORA; + else if (fastcmp(word2, "CREDITS")) + unlockables[num].type = SECRET_CREDITS; + else if (fastcmp(word2, "RECORDATTACK")) + unlockables[num].type = SECRET_RECORDATTACK; + else if (fastcmp(word2, "NIGHTSMODE")) + unlockables[num].type = SECRET_NIGHTSMODE; + else if (fastcmp(word2, "HEADER")) + unlockables[num].type = SECRET_HEADER; + else if (fastcmp(word2, "LEVELSELECT")) + unlockables[num].type = SECRET_LEVELSELECT; + else if (fastcmp(word2, "WARP")) + unlockables[num].type = SECRET_WARP; + else if (fastcmp(word2, "SOUNDTEST")) + unlockables[num].type = SECRET_SOUNDTEST; + else + unlockables[num].type = (INT16)i; + } + else if (fastcmp(word, "VAR")) + { + // Support using the actual map name, + // i.e., Level AB, Level FZ, etc. + + // Convert to map number + if (word2[0] >= 'A' && word2[0] <= 'Z') + i = M_MapNumber(word2[0], word2[1]); + + unlockables[num].variable = (INT16)i; + } + else + deh_warning("Unlockable %d: unknown word '%s'", num+1, word); + } + } while (!myfeof(f)); // finish when the line is empty + + Z_Free(s); +} + +#define PARAMCHECK(n) do { if (!params[n]) { deh_warning("Too few parameters, need %d", n); return; }} while (0) +static void readcondition(UINT8 set, UINT32 id, char *word2) +{ + INT32 i; + char *params[4]; // condition, requirement, extra info, extra info + char *spos; + + conditiontype_t ty; + INT32 re; + INT16 x1 = 0, x2 = 0; + + INT32 offset = 0; + + spos = strtok(word2, " "); + + for (i = 0; i < 4; ++i) + { + if (spos != NULL) + { + params[i] = spos; + spos = strtok(NULL, " "); + } + else + params[i] = NULL; + } + + if (!params[0]) + { + deh_warning("condition line is empty"); + return; + } + + if (fastcmp(params[0], "PLAYTIME")) + { + PARAMCHECK(1); + ty = UC_PLAYTIME; + re = atoi(params[1]); + } + else if (fastcmp(params[0], "GAMECLEAR") + || (++offset && fastcmp(params[0], "ALLEMERALDS")) + || (++offset && fastcmp(params[0], "ULTIMATECLEAR"))) + { + ty = UC_GAMECLEAR + offset; + re = (params[1]) ? atoi(params[1]) : 1; + } + else if ((offset=0) || fastcmp(params[0], "OVERALLSCORE") + || (++offset && fastcmp(params[0], "OVERALLTIME")) + || (++offset && fastcmp(params[0], "OVERALLRINGS"))) + { + PARAMCHECK(1); + ty = UC_OVERALLSCORE + offset; + re = atoi(params[1]); + } + else if ((offset=0) || fastcmp(params[0], "MAPVISITED") + || (++offset && fastcmp(params[0], "MAPBEATEN")) + || (++offset && fastcmp(params[0], "MAPALLEMERALDS")) + || (++offset && fastcmp(params[0], "MAPULTIMATE")) + || (++offset && fastcmp(params[0], "MAPPERFECT"))) + { + PARAMCHECK(1); + ty = UC_MAPVISITED + offset; + + // Convert to map number if it appears to be one + if (params[1][0] >= 'A' && params[1][0] <= 'Z') + re = M_MapNumber(params[1][0], params[1][1]); + else + re = atoi(params[1]); + + if (re < 0 || re >= NUMMAPS) + { + deh_warning("Level number %d out of range (1 - %d)", re, NUMMAPS); + return; + } + } + else if ((offset=0) || fastcmp(params[0], "MAPSCORE") + || (++offset && fastcmp(params[0], "MAPTIME")) + || (++offset && fastcmp(params[0], "MAPRINGS"))) + { + PARAMCHECK(2); + ty = UC_MAPSCORE + offset; + re = atoi(params[2]); + + // Convert to map number if it appears to be one + if (params[1][0] >= 'A' && params[1][0] <= 'Z') + x1 = (INT16)M_MapNumber(params[1][0], params[1][1]); + else + x1 = (INT16)atoi(params[1]); + + if (x1 < 0 || x1 >= NUMMAPS) + { + deh_warning("Level number %d out of range (1 - %d)", re, NUMMAPS); + return; + } + } + else if ((offset=0) || fastcmp(params[0], "NIGHTSSCORE") + || (++offset && fastcmp(params[0], "NIGHTSTIME")) + || (++offset && fastcmp(params[0], "NIGHTSGRADE"))) + { + PARAMCHECK(2); // one optional one + + ty = UC_NIGHTSSCORE + offset; + re = atoi(params[2 + !!(params[3])]); + + // Convert to map number if it appears to be one + if (params[1][0] >= 'A' && params[1][0] <= 'Z') + x1 = (INT16)M_MapNumber(params[1][0], params[1][1]); + else + x1 = (INT16)atoi(params[1]); + + if (x1 < 0 || x1 >= NUMMAPS) + { + deh_warning("Level number %d out of range (1 - %d)", re, NUMMAPS); + return; + } + + // Mare number (0 for overall) + if (params[3]) // Only if we actually got 3 params (so the second one == mare and not requirement) + x2 = (INT16)atoi(params[2]); + else + x2 = 0; + + } + else if (fastcmp(params[0], "TRIGGER")) + { + PARAMCHECK(1); + ty = UC_TRIGGER; + re = atoi(params[1]); + + // constrained by 32 bits + if (re < 0 || re > 31) + { + deh_warning("Trigger ID %d out of range (0 - 31)", re); + return; + } + } + else if (fastcmp(params[0], "TOTALEMBLEMS")) + { + PARAMCHECK(1); + ty = UC_TOTALEMBLEMS; + re = atoi(params[1]); + } + else if (fastcmp(params[0], "EMBLEM")) + { + PARAMCHECK(1); + ty = UC_EMBLEM; + re = atoi(params[1]); + + if (re <= 0 || re > MAXEMBLEMS) + { + deh_warning("Emblem %d out of range (1 - %d)", re, MAXEMBLEMS); + return; + } + } + else if (fastcmp(params[0], "EXTRAEMBLEM")) + { + PARAMCHECK(1); + ty = UC_EXTRAEMBLEM; + re = atoi(params[1]); + + if (re <= 0 || re > MAXEXTRAEMBLEMS) + { + deh_warning("Extra emblem %d out of range (1 - %d)", re, MAXEXTRAEMBLEMS); + return; + } + } + else if (fastcmp(params[0], "CONDITIONSET")) + { + PARAMCHECK(1); + ty = UC_CONDITIONSET; + re = atoi(params[1]); + + if (re <= 0 || re > MAXCONDITIONSETS) + { + deh_warning("Condition set %d out of range (1 - %d)", re, MAXCONDITIONSETS); + return; + } + } + else + { + deh_warning("Invalid condition name %s", params[0]); + return; + } + + M_AddRawCondition(set, (UINT8)id, ty, re, x1, x2); +} +#undef PARAMCHECK + +static void readconditionset(MYFILE *f, UINT8 setnum) +{ + char *s = Z_Malloc(MAXLINELEN, PU_STATIC, NULL); + char *word = s; + char *word2; + char *tmp; + UINT8 id; + UINT8 previd = 0; + + M_ClearConditionSet(setnum); + + do + { + if (myfgets(s, MAXLINELEN, f)) + { + if (s[0] == '\n') + break; + + // First remove trailing newline, if there is one + tmp = strchr(s, '\n'); + if (tmp) + *tmp = '\0'; + + tmp = strchr(s, '#'); + if (tmp) + *tmp = '\0'; + if (s == tmp) + continue; // Skip comment lines, but don't break. + + // Get the part before the " = " + tmp = strchr(s, '='); + *(tmp-1) = '\0'; + strupr(word); + + // Now get the part after + word2 = tmp += 2; + strupr(word2); + + if (fastncmp(word, "CONDITION", 9)) + { + id = (UINT8)atoi(word + 9); + if (id == 0) + { + deh_warning("Condition set %d: unknown word '%s'", setnum, word); + continue; + } + else if (previd > id) + { + // out of order conditions can cause problems, so enforce proper order + deh_warning("Condition set %d: conditions are out of order, ignoring this line", setnum); + continue; + } + previd = id; + + readcondition(setnum, id, word2); + } + else + deh_warning("Condition set %d: unknown word '%s'", setnum, word); + } + } while (!myfeof(f)); // finish when the line is empty + + Z_Free(s); +} + +static void readtexture(MYFILE *f, const char *name) +{ + char *s = Z_Malloc(MAXLINELEN, PU_STATIC, NULL); + char *word; + char *word2; + char *tmp; + INT32 i, j, value; + UINT16 width = 0, height = 0; + INT16 patchcount = 0; + texture_t *texture; + + do + { + if (myfgets(s, MAXLINELEN, f)) + { + if (s[0] == '\n') + break; + + tmp = strchr(s, '#'); + if (tmp) + *tmp = '\0'; + + value = searchvalue(s); + word = strtok(s, " "); + if (word) + strupr(word); + else + break; + + word2 = strtok(NULL, " "); + if (word2) + strupr(word2); + else + break; + + // Width of the texture. + if (fastcmp(word, "WIDTH")) + { + DEH_WriteUndoline(word, va("%d", width), UNDO_NONE); + width = SHORT((UINT16)value); + } + // Height of the texture. + else if (fastcmp(word, "HEIGHT")) + { + DEH_WriteUndoline(word, va("%d", height), UNDO_NONE); + height = SHORT((UINT16)value); + } + // Number of patches the texture has. + else if (fastcmp(word, "NUMPATCHES")) + { + DEH_WriteUndoline(word, va("%d", patchcount), UNDO_NONE); + patchcount = SHORT((UINT16)value); + } + else + deh_warning("readtexture: unknown word '%s'", word); + } + } while (!myfeof(f)); + + // Error checking. + if (!width) + I_Error("Texture %s has no width!\n", name); + + if (!height) + I_Error("Texture %s has no height!\n", name); + + if (!patchcount) + I_Error("Texture %s has no patches!\n", name); + + // Allocate memory for the texture, and fill in information. + texture = Z_Calloc(sizeof(texture_t) + (sizeof(texpatch_t) * SHORT(patchcount)), PU_STATIC, NULL); + M_Memcpy(texture->name, name, sizeof(texture->name)); + texture->width = width; + texture->height = height; + texture->patchcount = patchcount; + texture->holes = false; + // Fill out the texture patches, to allow them to be detected + // accurately by readpatch. + for (i = 0; i < patchcount; i++) + { + texture->patches[i].originx = 0; + texture->patches[i].originy = 0; + texture->patches[i].wad = UINT16_MAX; + texture->patches[i].lump = UINT16_MAX; + } + + // Jump to the next empty texture entry. + i = 0; + while (textures[i]) + i++; + + // Fill the global texture buffer entries. + j = 1; + while (j << 1 <= texture->width) + j <<= 1; + + textures[i] = texture; + texturewidthmask[i] = j - 1; + textureheight[i] = texture->height << FRACBITS; + + // Clean up. + Z_Free(s); +} + +static void readpatch(MYFILE *f, const char *name, UINT16 wad) +{ + char *s = Z_Malloc(MAXLINELEN, PU_STATIC, NULL); + char *word; + char *word2; + char *tmp; + INT32 i = 0, j = 0, value; + texpatch_t patch = {0, 0, UINT16_MAX, UINT16_MAX}; + + // Jump to the texture this patch belongs to, which, + // coincidentally, is always the last one on the buffer cache. + while (textures[i+1]) + i++; + + // Jump to the next empty patch entry. + while (memcmp(&(textures[i]->patches[j]), &patch, sizeof(patch))) + j++; + + patch.wad = wad; + // Set the texture number, but only if the lump exists. + if ((patch.lump = W_CheckNumForNamePwad(name, wad, 0)) == INT16_MAX) + I_Error("readpatch: Missing patch in texture %s", textures[i]->name); + + // note: undoing this patch will be done by other means + do + { + if (myfgets(s, MAXLINELEN, f)) + { + if (s[0] == '\n') + break; + + tmp = strchr(s, '#'); + if (tmp) + *tmp = '\0'; + + value = searchvalue(s); + word = strtok(s, " "); + if (word) + strupr(word); + else + break; + + word2 = strtok(NULL, " "); + if (word2) + strupr(word2); + else + break; + + // X position of the patch in the texture. + if (fastcmp(word, "X")) + { + //DEH_WriteUndoline(word, va("%d", patch->originx), UNDO_NONE); + patch.originx = (INT16)value; + } + // Y position of the patch in the texture. + else if (fastcmp(word, "Y")) + { + //DEH_WriteUndoline(word, va("%d", patch->originy), UNDO_NONE); + patch.originy = (INT16)value; + } + else + deh_warning("readpatch: unknown word '%s'", word); + } + } while (!myfeof(f)); + + // Error checking. + /* // Irrelevant. Origins cannot be unsigned. + if (patch.originx == UINT16_MAX) + I_Error("Patch %s on texture %s has no X position!\n", name, textures[i]->name); + + if (patch.originy == UINT16_MAX) + I_Error("Patch %s on texture %s has no Y position!\n", name, textures[i]->name); +*/ + + // Set the patch as that patch number. + textures[i]->patches[j] = patch; + + // Clean up. + Z_Free(s); +} + +static void readmaincfg(MYFILE *f) +{ + char *s = Z_Malloc(MAXLINELEN, PU_STATIC, NULL); + char *word = s; + char *word2; + char *tmp; + INT32 value; + + do + { + if (myfgets(s, MAXLINELEN, f)) + { + if (s[0] == '\n') + break; + + // First remove trailing newline, if there is one + tmp = strchr(s, '\n'); + if (tmp) + *tmp = '\0'; + + tmp = strchr(s, '#'); + if (tmp) + *tmp = '\0'; + if (s == tmp) + continue; // Skip comment lines, but don't break. + + // Get the part before the " = " + tmp = strchr(s, '='); + *(tmp-1) = '\0'; + strupr(word); + + // Now get the part after + word2 = tmp += 2; + strupr(word2); + + value = atoi(word2); // used for numerical settings + + if (fastcmp(word, "EXECCFG")) + COM_BufAddText(va("exec %s\n", word2)); + + else if (fastcmp(word, "SPSTAGE_START")) + { + // Support using the actual map name, + // i.e., Level AB, Level FZ, etc. + + // Convert to map number + if (word2[0] >= 'A' && word2[0] <= 'Z') + value = M_MapNumber(word2[0], word2[1]); + else + value = get_number(word2); + + DEH_WriteUndoline(word, va("%d", spstage_start), UNDO_NONE); + spstage_start = (INT16)value; + } + else if (fastcmp(word, "SSTAGE_START")) + { + // Support using the actual map name, + // i.e., Level AB, Level FZ, etc. + + // Convert to map number + if (word2[0] >= 'A' && word2[0] <= 'Z') + value = M_MapNumber(word2[0], word2[1]); + else + value = get_number(word2); + + DEH_WriteUndoline(word, va("%d", sstage_start), UNDO_NONE); + sstage_start = (INT16)value; + sstage_end = (INT16)(sstage_start+6); // 7 special stages total + } + else if (fastcmp(word, "USENIGHTSSS")) + { + DEH_WriteUndoline(word, va("%d", useNightsSS), UNDO_NONE); + useNightsSS = (UINT8)(value || word2[0] == 'T' || word2[0] == 'Y'); + } + else if (fastcmp(word, "REDTEAM")) + { + DEH_WriteUndoline(word, va("%d", skincolor_redteam), UNDO_NONE); + skincolor_redteam = (UINT8)get_number(word2); + } + else if (fastcmp(word, "BLUETEAM")) + { + DEH_WriteUndoline(word, va("%d", skincolor_blueteam), UNDO_NONE); + skincolor_blueteam = (UINT8)get_number(word2); + } + else if (fastcmp(word, "REDRING")) + { + DEH_WriteUndoline(word, va("%d", skincolor_redring), UNDO_NONE); + skincolor_redring = (UINT8)get_number(word2); + } + else if (fastcmp(word, "BLUERING")) + { + DEH_WriteUndoline(word, va("%d", skincolor_bluering), UNDO_NONE); + skincolor_bluering = (UINT8)get_number(word2); + } + else if (fastcmp(word, "INVULNTICS")) + { + DEH_WriteUndoline(word, va("%u", invulntics), UNDO_NONE); + invulntics = (UINT16)get_number(word2); + } + else if (fastcmp(word, "SNEAKERTICS")) + { + DEH_WriteUndoline(word, va("%u", sneakertics), UNDO_NONE); + sneakertics = (UINT16)get_number(word2); + } + else if (fastcmp(word, "FLASHINGTICS")) + { + DEH_WriteUndoline(word, va("%u", flashingtics), UNDO_NONE); + flashingtics = (UINT16)get_number(word2); + } + else if (fastcmp(word, "TAILSFLYTICS")) + { + DEH_WriteUndoline(word, va("%u", tailsflytics), UNDO_NONE); + tailsflytics = (UINT16)get_number(word2); + } + else if (fastcmp(word, "UNDERWATERTICS")) + { + DEH_WriteUndoline(word, va("%u", underwatertics), UNDO_NONE); + underwatertics = (UINT16)get_number(word2); + } + else if (fastcmp(word, "SPACETIMETICS")) + { + DEH_WriteUndoline(word, va("%u", spacetimetics), UNDO_NONE); + spacetimetics = (UINT16)get_number(word2); + } + else if (fastcmp(word, "EXTRALIFETICS")) + { + DEH_WriteUndoline(word, va("%u", extralifetics), UNDO_NONE); + extralifetics = (UINT16)get_number(word2); + } + else if (fastcmp(word, "GAMEOVERTICS")) + { + DEH_WriteUndoline(word, va("%u", gameovertics), UNDO_NONE); + gameovertics = get_number(word2); + } + + else if (fastcmp(word, "INTROTOPLAY")) + { + DEH_WriteUndoline(word, va("%d", introtoplay), UNDO_NONE); + introtoplay = (UINT8)get_number(word2); + // range check, you morons. + if (introtoplay > 128) + introtoplay = 128; + } + else if (fastcmp(word, "LOOPTITLE")) + { + DEH_WriteUndoline(word, va("%d", looptitle), UNDO_NONE); + looptitle = (boolean)(value || word2[0] == 'T' || word2[0] == 'Y'); + } + else if (fastcmp(word, "TITLESCROLLSPEED")) + { + DEH_WriteUndoline(word, va("%d", titlescrollspeed), UNDO_NONE); + titlescrollspeed = get_number(word2); + } + else if (fastcmp(word, "CREDITSCUTSCENE")) + { + DEH_WriteUndoline(word, va("%d", creditscutscene), UNDO_NONE); + creditscutscene = (UINT8)get_number(word2); + // range check, you morons. + if (creditscutscene > 128) + creditscutscene = 128; + } + else if (fastcmp(word, "DISABLESPEEDADJUST")) + { + DEH_WriteUndoline(word, va("%d", disableSpeedAdjust), UNDO_NONE); + disableSpeedAdjust = (UINT8)get_number(word2); + } + else if (fastcmp(word, "NUMDEMOS")) + { + DEH_WriteUndoline(word, va("%d", numDemos), UNDO_NONE); + numDemos = (UINT8)get_number(word2); + } + else if (fastcmp(word, "DEMODELAYTIME")) + { + DEH_WriteUndoline(word, va("%d", demoDelayTime), UNDO_NONE); + demoDelayTime = get_number(word2); + } + else if (fastcmp(word, "DEMOIDLETIME")) + { + DEH_WriteUndoline(word, va("%d", demoIdleTime), UNDO_NONE); + demoIdleTime = get_number(word2); + } + else if (fastcmp(word, "USE1UPSOUND")) + { + DEH_WriteUndoline(word, va("%u", use1upSound), UNDO_NONE); + use1upSound = (UINT8)(value || word2[0] == 'T' || word2[0] == 'Y'); + } + else if (fastcmp(word, "MAXXTRALIFE")) + { + DEH_WriteUndoline(word, va("%u", maxXtraLife), UNDO_NONE); + maxXtraLife = (UINT8)get_number(word2); + } + + else if (fastcmp(word, "GAMEDATA")) + { + size_t filenamelen; + + // Check the data filename so that mods + // can't write arbitrary files. + if (!GoodDataFileName(word2)) + I_Error("Maincfg: bad data file name '%s'\n", word2); + + G_SaveGameData(); + DEH_WriteUndoline(word, gamedatafilename, UNDO_NONE); + strlcpy(gamedatafilename, word2, sizeof (gamedatafilename)); + strlwr(gamedatafilename); + savemoddata = true; + + // Also save a time attack folder + filenamelen = strlen(gamedatafilename)-4; // Strip off the extension + strncpy(timeattackfolder, gamedatafilename, min(filenamelen, sizeof (timeattackfolder))); + timeattackfolder[min(filenamelen, sizeof (timeattackfolder) - 1)] = '\0'; + + strncpy(savegamename, timeattackfolder, sizeof (timeattackfolder)); + strlcat(savegamename, "%u.ssg", sizeof(savegamename)); + + gamedataadded = true; + } + else if (fastcmp(word, "RESETDATA")) + { + DEH_WriteUndoline(word, "0", UNDO_TODO); /// \todo + P_ResetData(value); + } + else if (fastcmp(word, "CUSTOMVERSION")) + { + DEH_WriteUndoline(word, customversionstring, UNDO_NONE); + strlcpy(customversionstring, word2, sizeof (customversionstring)); + } + else + deh_warning("Maincfg: unknown word '%s'", word); + } + } while (!myfeof(f)); + + Z_Free(s); +} + +static void readwipes(MYFILE *f) +{ + char *s = Z_Malloc(MAXLINELEN, PU_STATIC, NULL); + char *word = s; + char *pword = word; + char *word2; + char *tmp; + INT32 value; + INT32 wipeoffset; + + do + { + if (myfgets(s, MAXLINELEN, f)) + { + if (s[0] == '\n') + break; + + // First remove trailing newline, if there is one + tmp = strchr(s, '\n'); + if (tmp) + *tmp = '\0'; + + tmp = strchr(s, '#'); + if (tmp) + *tmp = '\0'; + if (s == tmp) + continue; // Skip comment lines, but don't break. + + // Get the part before the " = " + tmp = strchr(s, '='); + *(tmp-1) = '\0'; + strupr(word); + + // Now get the part after + word2 = tmp += 2; + value = atoi(word2); // used for numerical settings + + if (value < -1 || value > 99) + { + deh_warning("Wipes: bad value '%s'", word2); + continue; + } + else if (value == -1) + value = UINT8_MAX; + + // error catching + wipeoffset = -1; + + if (fastncmp(word, "LEVEL_", 6)) + { + pword = word + 6; + if (fastcmp(pword, "TOBLACK")) + wipeoffset = wipe_level_toblack; + else if (fastcmp(pword, "FINAL")) + wipeoffset = wipe_level_final; + } + else if (fastncmp(word, "INTERMISSION_", 13)) + { + pword = word + 13; + if (fastcmp(pword, "TOBLACK")) + wipeoffset = wipe_intermission_toblack; + else if (fastcmp(pword, "FINAL")) + wipeoffset = wipe_intermission_final; + } + else if (fastncmp(word, "SPECINTER_", 10)) + { + pword = word + 10; + if (fastcmp(pword, "TOBLACK")) + wipeoffset = wipe_specinter_toblack; + else if (fastcmp(pword, "FINAL")) + wipeoffset = wipe_specinter_final; + } + else if (fastncmp(word, "MULTINTER_", 10)) + { + pword = word + 10; + if (fastcmp(pword, "TOBLACK")) + wipeoffset = wipe_multinter_toblack; + else if (fastcmp(pword, "FINAL")) + wipeoffset = wipe_multinter_final; + } + else if (fastncmp(word, "CONTINUING_", 11)) + { + pword = word + 11; + if (fastcmp(pword, "TOBLACK")) + wipeoffset = wipe_continuing_toblack; + else if (fastcmp(pword, "FINAL")) + wipeoffset = wipe_continuing_final; + } + else if (fastncmp(word, "TITLESCREEN_", 12)) + { + pword = word + 12; + if (fastcmp(pword, "TOBLACK")) + wipeoffset = wipe_titlescreen_toblack; + else if (fastcmp(pword, "FINAL")) + wipeoffset = wipe_titlescreen_final; + } + else if (fastncmp(word, "TIMEATTACK_", 11)) + { + pword = word + 11; + if (fastcmp(pword, "TOBLACK")) + wipeoffset = wipe_timeattack_toblack; + else if (fastcmp(pword, "FINAL")) + wipeoffset = wipe_timeattack_final; + } + else if (fastncmp(word, "CREDITS_", 8)) + { + pword = word + 8; + if (fastcmp(pword, "TOBLACK")) + wipeoffset = wipe_credits_toblack; + else if (fastcmp(pword, "FINAL")) + wipeoffset = wipe_credits_final; + else if (fastcmp(pword, "INTERMEDIATE")) + wipeoffset = wipe_credits_intermediate; + } + else if (fastncmp(word, "EVALUATION_", 11)) + { + pword = word + 11; + if (fastcmp(pword, "TOBLACK")) + wipeoffset = wipe_evaluation_toblack; + else if (fastcmp(pword, "FINAL")) + wipeoffset = wipe_evaluation_final; + } + else if (fastncmp(word, "GAMEEND_", 8)) + { + pword = word + 8; + if (fastcmp(pword, "TOBLACK")) + wipeoffset = wipe_gameend_toblack; + else if (fastcmp(pword, "FINAL")) + wipeoffset = wipe_gameend_final; + } + + if (wipeoffset < 0) + { + deh_warning("Wipes: unknown word '%s'", word); + continue; + } + + if (value == UINT8_MAX // Cannot disable non-toblack wipes (or the level toblack wipe) + && (wipeoffset <= wipe_level_toblack || wipeoffset >= wipe_level_final)) + { + deh_warning("Wipes: can't disable wipe of type '%s'", word); + continue; + } + + wipedefs[wipeoffset] = (UINT8)value; + } + } while (!myfeof(f)); + + Z_Free(s); +} + +// Used when you do something invalid like read a bad item number +// to prevent extra unnecessary errors +static void ignorelines(MYFILE *f) +{ + char *s = Z_Malloc(MAXLINELEN, PU_STATIC, NULL); + do + { + if (myfgets(s, MAXLINELEN, f)) + { + if (s[0] == '\n') + break; + } + } while (!myfeof(f)); + Z_Free(s); +} + +static void DEH_LoadDehackedFile(MYFILE *f, UINT16 wad) +{ + char *s = Z_Malloc(MAXLINELEN, PU_STATIC, NULL); + char *word; + char *word2; + INT32 i; + // do a copy of this for cross references probleme + //XBOXSTATIC actionf_t saveactions[NUMSTATES]; + //XBOXSTATIC const char *savesprnames[NUMSPRITES]; + XBOXSTATIC const char *savesfxnames[NUMSFX]; + + if (!deh_loaded) + initfreeslots(); + + deh_num_warning = 0; + // save values for cross reference + /* + for (i = 0; i < NUMSTATES; i++) + saveactions[i] = states[i].action; + for (i = 0; i < NUMSPRITES; i++) + savesprnames[i] = sprnames[i]; + */ + for (i = 0; i < NUMSFX; i++) + savesfxnames[i] = S_sfx[i].name; + + gamedataadded = false; + + // it doesn't test the version of SRB2 and version of dehacked file + dbg_line = -1; // start at -1 so the first line is 0. + while (!myfeof(f)) + { + XBOXSTATIC char origpos[128]; + INT32 size = 0; + char *traverse; + + myfgets(s, MAXLINELEN, f); + if (s[0] == '\n' || s[0] == '#') + continue; + + traverse = s; + + while (traverse[0] != '\n') + { + traverse++; + size++; + } + + strncpy(origpos, s, size); + origpos[size] = '\0'; + + if (NULL != (word = strtok(s, " "))) { + strupr(word); + if (word[strlen(word)-1] == '\n') + word[strlen(word)-1] = '\0'; + } + if (word) + { + if (fastcmp(word, "FREESLOT")) + { + readfreeslots(f); + continue; + } + else if (fastcmp(word, "MAINCFG")) + { + readmaincfg(f); + DEH_WriteUndoline(word, "", UNDO_HEADER); + continue; + } + else if (fastcmp(word, "WIPES")) + { + readwipes(f); + DEH_WriteUndoline(word, "", UNDO_HEADER); + continue; + } + word2 = strtok(NULL, " "); + if (fastcmp(word, "CHARACTER")) + { + if (word2) { + strupr(word2); + if (word2[strlen(word2)-1] == '\n') + word2[strlen(word2)-1] = '\0'; + i = atoi(word2); + } else + i = 0; + if (i >= 0 && i < 32) + readPlayer(f, i); + else + { + deh_warning("Character %d out of range (0 - 31)", i); + ignorelines(f); + } + DEH_WriteUndoline(word, word2, UNDO_HEADER); + continue; + } + if (word2) + { + strupr(word2); + if (word2[strlen(word2)-1] == '\n') + word2[strlen(word2)-1] = '\0'; + i = atoi(word2); + if (fastcmp(word, "TEXTURE")) + { + // Read texture from spec file. + readtexture(f, word2); + DEH_WriteUndoline(word, word2, UNDO_HEADER); + } + else if (fastcmp(word, "PATCH")) + { + // Read patch from spec file. + readpatch(f, word2, wad); + DEH_WriteUndoline(word, word2, UNDO_HEADER); + } + else if (fastcmp(word, "THING") || fastcmp(word, "MOBJ") || fastcmp(word, "OBJECT")) + { + if (i == 0 && word2[0] != '0') // If word2 isn't a number + i = get_mobjtype(word2); // find a thing by name + if (i < NUMMOBJTYPES && i >= 0) + readthing(f, i); + else + { + deh_warning("Thing %d out of range (0 - %d)", i, NUMMOBJTYPES-1); + ignorelines(f); + } + DEH_WriteUndoline(word, word2, UNDO_HEADER); + } + else if (fastcmp(word, "MODBY")) + { + memset(modcreditname, 0, sizeof(char) * 32); + strcpy(modcreditname, origpos+6); + modcredits = true; + } +/* else if (fastcmp(word, "ANIMTEX")) + { + readAnimTex(f, i); + }*/ + else if (fastcmp(word, "LIGHT")) + { +#ifdef HWRENDER + // TODO: Read lights by name + if (i > 0 && i < NUMLIGHTS) + readlight(f, i); + else + { + deh_warning("Light number %d out of range (1 - %d)", i, NUMLIGHTS-1); + ignorelines(f); + } + DEH_WriteUndoline(word, word2, UNDO_HEADER); +#endif + } + else if (fastcmp(word, "SPRITE")) + { +#ifdef HWRENDER + if (i == 0 && word2[0] != '0') // If word2 isn't a number + i = get_sprite(word2); // find a sprite by name + if (i < NUMSPRITES && i >= 0) + readspritelight(f, i); + else + { + deh_warning("Sprite number %d out of range (0 - %d)", i, NUMSPRITES-1); + ignorelines(f); + } + DEH_WriteUndoline(word, word2, UNDO_HEADER); +#endif + } + else if (fastcmp(word, "LEVEL")) + { + // Support using the actual map name, + // i.e., Level AB, Level FZ, etc. + + // Convert to map number + if (word2[0] >= 'A' && word2[0] <= 'Z') + i = M_MapNumber(word2[0], word2[1]); + + if (i > 0 && i <= NUMMAPS) + readlevelheader(f, i); + else + { + deh_warning("Level number %d out of range (1 - %d)", i, NUMMAPS); + ignorelines(f); + } + DEH_WriteUndoline(word, word2, UNDO_HEADER); + } + else if (fastcmp(word, "CUTSCENE")) + { + if (i > 0 && i < 129) + readcutscene(f, i - 1); + else + { + deh_warning("Cutscene number %d out of range (1 - 128)", i); + ignorelines(f); + } + DEH_WriteUndoline(word, word2, UNDO_HEADER); + } + else if (fastcmp(word, "FRAME") || fastcmp(word, "STATE")) + { + if (i == 0 && word2[0] != '0') // If word2 isn't a number + i = get_state(word2); // find a state by name + if (i < NUMSTATES && i >= 0) + readframe(f, i); + else + { + deh_warning("Frame %d out of range (0 - %d)", i, NUMSTATES-1); + ignorelines(f); + } + DEH_WriteUndoline(word, word2, UNDO_HEADER); + } + // Added translations to this just in case its re-enabled +/* else if (fastcmp(word, "POINTER")) + { + word = strtok(NULL, " "); // get frame + word = strtok(NULL, ")"); + if (word) + { + i = atoi(word); + if (i < NUMSTATES && i >= 0) + { + if (myfgets(s, MAXLINELEN, f)) + states[i].action = saveactions[searchvalue(s)]; + } + else + { + deh_warning("Pointer: Frame %d doesn't exist", i); + ignorelines(f); + } + } + else + deh_warning("pointer (Frame %d) : missing ')'", i); + }*/ + else if (fastcmp(word, "SOUND")) + { + if (i == 0 && word2[0] != '0') // If word2 isn't a number + i = get_sfx(word2); // find a sound by name + if (i < NUMSFX && i >= 0) + readsound(f, i, savesfxnames); + else + { + deh_warning("Sound %d out of range (0 - %d)", i, NUMSFX-1); + ignorelines(f); + } + DEH_WriteUndoline(word, word2, UNDO_HEADER); + } +/* else if (fastcmp(word, "SPRITE")) + { + if (i < NUMSPRITES && i >= 0) + { + if (myfgets(s, MAXLINELEN, f)) + { + INT32 k; + k = (searchvalue(s) - 151328)/8; + if (k >= 0 && k < NUMSPRITES) + sprnames[i] = savesprnames[k]; + else + { + deh_warning("Sprite %d: offset out of bounds", i); + ignorelines(f); + } + } + } + else + deh_warning("Sprite %d doesn't exist",i); + }*/ + else if (fastcmp(word, "HUDITEM")) + { + if (i == 0 && word2[0] != '0') // If word2 isn't a number + i = get_huditem(word2); // find a huditem by name + if (i >= 0 && i < NUMHUDITEMS) + readhuditem(f, i); + else + { + deh_warning("HUD item number %d out of range (0 - %d)", i, NUMHUDITEMS-1); + ignorelines(f); + } + DEH_WriteUndoline(word, word2, UNDO_HEADER); + } + else if (fastcmp(word, "EMBLEM")) + { + if (!gamedataadded) + { + deh_warning("You must define a custom gamedata to use \"%s\"", word); + ignorelines(f); + } + else if (i > 0 && i <= MAXEMBLEMS) + { + if (numemblems < i) + numemblems = i; + reademblemdata(f, i); + } + else + { + deh_warning("Emblem number %d out of range (1 - %d)", i, MAXEMBLEMS); + ignorelines(f); + } + DEH_WriteUndoline(word, word2, UNDO_HEADER); + } + else if (fastcmp(word, "EXTRAEMBLEM")) + { + if (!gamedataadded) + { + deh_warning("You must define a custom gamedata to use \"%s\"", word); + ignorelines(f); + } + else if (i > 0 && i <= MAXEXTRAEMBLEMS) + { + if (numextraemblems < i) + numextraemblems = i; + readextraemblemdata(f, i); + } + else + { + deh_warning("Extra emblem number %d out of range (1 - %d)", i, MAXEXTRAEMBLEMS); + ignorelines(f); + } + DEH_WriteUndoline(word, word2, UNDO_HEADER); + } + else if (fastcmp(word, "UNLOCKABLE")) + { + if (!gamedataadded) + { + deh_warning("You must define a custom gamedata to use \"%s\"", word); + ignorelines(f); + } + else if (i > 0 && i <= MAXUNLOCKABLES) + readunlockable(f, i - 1); + else + { + deh_warning("Unlockable number %d out of range (1 - %d)", i, MAXUNLOCKABLES); + ignorelines(f); + } + DEH_WriteUndoline(word, word2, UNDO_HEADER); + } + else if (fastcmp(word, "CONDITIONSET")) + { + if (!gamedataadded) + { + deh_warning("You must define a custom gamedata to use \"%s\"", word); + ignorelines(f); + } + else if (i > 0 && i <= MAXCONDITIONSETS) + readconditionset(f, (UINT8)i); + else + { + deh_warning("Condition set number %d out of range (1 - %d)", i, MAXCONDITIONSETS); + ignorelines(f); + } + // no undo support for this insanity yet + //DEH_WriteUndoline(word, word2, UNDO_HEADER); + } + else if (fastcmp(word, "SRB2")) + { + INT32 ver = searchvalue(strtok(NULL, "\n")); + if (ver != PATCHVERSION) + deh_warning("Patch is for SRB2 version %d,\nonly version %d is supported", ver, PATCHVERSION); + //DEH_WriteUndoline(word, va("%d", ver), UNDO_NONE); + } + // Clear all data in certain locations (mostly for unlocks) + // Unless you REALLY want to piss people off, + // define a custom gamedata /before/ doing this!! + // (then again, modifiedgame will prevent game data saving anyway) + else if (fastcmp(word, "CLEAR")) + { + boolean clearall = (fastcmp(word2, "ALL")); + + if (!gamedataadded) + { + deh_warning("You must define a custom gamedata to use \"%s\"", word); + continue; + } + + if (clearall || fastcmp(word2, "UNLOCKABLES")) + memset(&unlockables, 0, sizeof(unlockables)); + + if (clearall || fastcmp(word2, "EMBLEMS")) + { + memset(&emblemlocations, 0, sizeof(emblemlocations)); + numemblems = 0; + } + + if (clearall || fastcmp(word2, "EXTRAEMBLEMS")) + { + memset(&extraemblems, 0, sizeof(extraemblems)); + numextraemblems = 0; + } + + if (clearall || fastcmp(word2, "CONDITIONSETS")) + clear_conditionsets(); + + if (clearall || fastcmp(word2, "LEVELS")) + clear_levels(); + } + else + deh_warning("Unknown word: %s", word); + } + else + deh_warning("missing argument for '%s'", word); + } + else + deh_warning("No word in this line: %s", s); + } // end while + + if (gamedataadded) + G_LoadGameData(); + + dbg_line = -1; + if (deh_num_warning) + { + CONS_Printf(M_GetText("%d warning%s in the SOC lump\n"), deh_num_warning, deh_num_warning == 1 ? "" : "s"); + if (devparm) { + I_Error("%s%s",va(M_GetText("%d warning%s in the SOC lump\n"), deh_num_warning, deh_num_warning == 1 ? "" : "s"), M_GetText("See log.txt for details.\n")); + //while (!I_GetKey()) + //I_OsPolling(); + } + } + + deh_loaded = true; + Z_Free(s); +} + +// read dehacked lump in a wad (there is special trick for for deh +// file that are converted to wad in w_wad.c) +void DEH_LoadDehackedLumpPwad(UINT16 wad, UINT16 lump) +{ + MYFILE f; +#ifdef DELFILE + unsocwad = wad; +#endif + f.wad = wad; + f.size = W_LumpLengthPwad(wad, lump); + f.data = Z_Malloc(f.size + 1, PU_STATIC, NULL); + W_ReadLumpPwad(wad, lump, f.data); + f.curpos = f.data; + f.data[f.size] = 0; + DEH_LoadDehackedFile(&f, wad); + DEH_WriteUndoline(va("# uload for wad: %u, lump: %u", wad, lump), NULL, UNDO_DONE); + Z_Free(f.data); +} + +void DEH_LoadDehackedLump(lumpnum_t lumpnum) +{ + DEH_LoadDehackedLumpPwad(WADFILENUM(lumpnum),LUMPNUM(lumpnum)); +} + +#ifdef DELFILE +#define DUMPUNDONE + +// read (un)dehacked lump in wad's memory +void DEH_UnloadDehackedWad(UINT16 wad) +{ + undehacked_t *tmp, *curundo = unsocdata[wad]; + MYFILE f; + size_t len = 0; + char *data; +#ifdef DUMPUNDONE + FILE *UNDO = fopen("undo.soc", "wt"); +#endif + CONS_Printf(M_GetText("Unloading WAD SOC edits\n")); + while (curundo) + { + data = curundo->undata; + curundo = curundo->next; + if (data) + len += strlen(data); + len += 1; +#ifdef DUMPUNDONE + if (UNDO) + { + if (data) + fprintf(UNDO, "%s\n", data); + else + fprintf(UNDO, "\n"); + } +#endif + } +#ifndef DUMPUNDONE + if (UNDO) fclose(UNDO); +#endif + if (!len) return; + f.size = len; + data = f.data = Z_Malloc(f.size + 1, PU_STATIC, NULL); + curundo = unsocdata[wad]; + unsocdata[wad] = NULL; + while (curundo) + { + tmp = curundo; + curundo = curundo->next; + if (tmp->undata) + data += sprintf(data, "%s\n", tmp->undata); + else + data += sprintf(data, "\n"); + if (tmp->undata) free(tmp->undata); + free(tmp); + } + f.wad = wad; + f.curpos = f.data; + f.data[f.size] = 0; + disableundo = true; + DEH_LoadDehackedFile(&f); + disableundo = false; + Z_Free(f.data); +} +#endif //DELFILE + + +//////////////////////////////////////////////////////////////////////////////// +// CRAZY LIST OF STATE NAMES AND ALL FROM HERE DOWN +// TODO: Make this all a seperate file or something, like part of info.c?? +// TODO: Read the list from a text lump in a WAD as necessary instead +// or something, don't just keep it all in memory like this. +// TODO: Make the lists public so we can start using actual mobj +// and state names in warning and error messages! :D + +// RegEx to generate this from info.h: ^\tS_([^,]+), --> \t"S_\1", +// I am leaving the prefixes solely for clarity to programmers, +// because sadly no one remembers this place while searching for full state names. +static const char *const STATE_LIST[] = { // array length left dynamic for sanity testing later. + "S_NULL", + "S_UNKNOWN", + "S_INVISIBLE", // state for invisible sprite + + "S_SPAWNSTATE", + "S_SEESTATE", + "S_MELEESTATE", + "S_MISSILESTATE", + "S_DEATHSTATE", + "S_XDEATHSTATE", + "S_RAISESTATE", + + // Thok + "S_THOK", + + "S_PLAY_STND", + "S_PLAY_TAP1", + "S_PLAY_TAP2", + "S_PLAY_RUN1", + "S_PLAY_RUN2", + "S_PLAY_RUN3", + "S_PLAY_RUN4", + "S_PLAY_RUN5", + "S_PLAY_RUN6", + "S_PLAY_RUN7", + "S_PLAY_RUN8", + "S_PLAY_SPD1", + "S_PLAY_SPD2", + "S_PLAY_SPD3", + "S_PLAY_SPD4", + "S_PLAY_ATK1", + "S_PLAY_ATK2", + "S_PLAY_ATK3", + "S_PLAY_ATK4", + "S_PLAY_SPRING", + "S_PLAY_FALL1", + "S_PLAY_FALL2", + "S_PLAY_ABL1", + "S_PLAY_ABL2", + "S_PLAY_SPC1", + "S_PLAY_SPC2", + "S_PLAY_SPC3", + "S_PLAY_SPC4", + "S_PLAY_CLIMB1", + "S_PLAY_CLIMB2", + "S_PLAY_CLIMB3", + "S_PLAY_CLIMB4", + "S_PLAY_CLIMB5", + "S_PLAY_GASP", + "S_PLAY_PAIN", + "S_PLAY_DIE", + "S_PLAY_TEETER1", + "S_PLAY_TEETER2", + "S_PLAY_CARRY", + "S_PLAY_SUPERSTAND", + "S_PLAY_SUPERWALK1", + "S_PLAY_SUPERWALK2", + "S_PLAY_SUPERFLY1", + "S_PLAY_SUPERFLY2", + "S_PLAY_SUPERTEETER", + "S_PLAY_SUPERHIT", + "S_PLAY_SUPERTRANS1", + "S_PLAY_SUPERTRANS2", + "S_PLAY_SUPERTRANS3", + "S_PLAY_SUPERTRANS4", + "S_PLAY_SUPERTRANS5", + "S_PLAY_SUPERTRANS6", + "S_PLAY_SUPERTRANS7", + "S_PLAY_SUPERTRANS8", + "S_PLAY_SUPERTRANS9", // This has special significance in the code. If you add more frames, search for it and make the appropriate changes. + + // technically the player goes here but it's an infinite tic state + "S_OBJPLACE_DUMMY", + + // 1-Up Box Sprites (uses player sprite) + "S_PLAY_BOX1", + "S_PLAY_BOX2", + "S_PLAY_ICON1", + "S_PLAY_ICON2", + "S_PLAY_ICON3", + + // Level end sign (uses player sprite) + "S_PLAY_SIGN", + + // Blue Crawla + "S_POSS_STND", + "S_POSS_STND2", + "S_POSS_RUN1", + "S_POSS_RUN2", + "S_POSS_RUN3", + "S_POSS_RUN4", + "S_POSS_RUN5", + "S_POSS_RUN6", + + // Red Crawla + "S_SPOS_STND", + "S_SPOS_STND2", + "S_SPOS_RUN1", + "S_SPOS_RUN2", + "S_SPOS_RUN3", + "S_SPOS_RUN4", + "S_SPOS_RUN5", + "S_SPOS_RUN6", + + // Greenflower Fish + "S_FISH1", + "S_FISH2", + "S_FISH3", + "S_FISH4", + + // Buzz (Gold) + "S_BUZZLOOK1", + "S_BUZZLOOK2", + "S_BUZZFLY1", + "S_BUZZFLY2", + + // Buzz (Red) + "S_RBUZZLOOK1", + "S_RBUZZLOOK2", + "S_RBUZZFLY1", + "S_RBUZZFLY2", + + // AquaBuzz + "S_BBUZZFLY1", + "S_BBUZZFLY2", + + // Jetty-Syn Bomber + "S_JETBLOOK1", + "S_JETBLOOK2", + "S_JETBZOOM1", + "S_JETBZOOM2", + + // Jetty-Syn Gunner + "S_JETGLOOK1", + "S_JETGLOOK2", + "S_JETGZOOM1", + "S_JETGZOOM2", + "S_JETGSHOOT1", + "S_JETGSHOOT2", + + // Crawla Commander + "S_CCOMMAND1", + "S_CCOMMAND2", + "S_CCOMMAND3", + "S_CCOMMAND4", + + // Deton + "S_DETON1", + "S_DETON2", + "S_DETON3", + "S_DETON4", + "S_DETON5", + "S_DETON6", + "S_DETON7", + "S_DETON8", + "S_DETON9", + "S_DETON10", + "S_DETON11", + "S_DETON12", + "S_DETON13", + "S_DETON14", + "S_DETON15", + "S_DETON16", + + // Skim Mine Dropper + "S_SKIM1", + "S_SKIM2", + "S_SKIM3", + "S_SKIM4", + + // THZ Turret + "S_TURRET", + "S_TURRETFIRE", + "S_TURRETSHOCK1", + "S_TURRETSHOCK2", + "S_TURRETSHOCK3", + "S_TURRETSHOCK4", + "S_TURRETSHOCK5", + "S_TURRETSHOCK6", + "S_TURRETSHOCK7", + "S_TURRETSHOCK8", + "S_TURRETSHOCK9", + + // Popup Turret + "S_TURRETLOOK", + "S_TURRETSEE", + "S_TURRETPOPUP1", + "S_TURRETPOPUP2", + "S_TURRETPOPUP3", + "S_TURRETPOPUP4", + "S_TURRETPOPUP5", + "S_TURRETPOPUP6", + "S_TURRETPOPUP7", + "S_TURRETPOPUP8", + "S_TURRETSHOOT", + "S_TURRETPOPDOWN1", + "S_TURRETPOPDOWN2", + "S_TURRETPOPDOWN3", + "S_TURRETPOPDOWN4", + "S_TURRETPOPDOWN5", + "S_TURRETPOPDOWN6", + "S_TURRETPOPDOWN7", + "S_TURRETPOPDOWN8", + + // Sharp + "S_SHARP_ROAM1", + "S_SHARP_ROAM2", + "S_SHARP_AIM1", + "S_SHARP_AIM2", + "S_SHARP_AIM3", + "S_SHARP_AIM4", + "S_SHARP_SPIN", + + // Jet Jaw + "S_JETJAW_ROAM1", + "S_JETJAW_ROAM2", + "S_JETJAW_ROAM3", + "S_JETJAW_ROAM4", + "S_JETJAW_ROAM5", + "S_JETJAW_ROAM6", + "S_JETJAW_ROAM7", + "S_JETJAW_ROAM8", + "S_JETJAW_CHOMP1", + "S_JETJAW_CHOMP2", + "S_JETJAW_CHOMP3", + "S_JETJAW_CHOMP4", + "S_JETJAW_CHOMP5", + "S_JETJAW_CHOMP6", + "S_JETJAW_CHOMP7", + "S_JETJAW_CHOMP8", + "S_JETJAW_CHOMP9", + "S_JETJAW_CHOMP10", + "S_JETJAW_CHOMP11", + "S_JETJAW_CHOMP12", + "S_JETJAW_CHOMP13", + "S_JETJAW_CHOMP14", + "S_JETJAW_CHOMP15", + "S_JETJAW_CHOMP16", + + // Snailer + "S_SNAILER1", + + // Vulture + "S_VULTURE_STND", + "S_VULTURE_VTOL1", + "S_VULTURE_VTOL2", + "S_VULTURE_VTOL3", + "S_VULTURE_VTOL4", + "S_VULTURE_ZOOM1", + "S_VULTURE_ZOOM2", + "S_VULTURE_ZOOM3", + "S_VULTURE_ZOOM4", + "S_VULTURE_ZOOM5", + + // Pointy + "S_POINTY1", + "S_POINTYBALL1", + + // Robo-Hood + "S_ROBOHOOD_LOOK", + "S_ROBOHOOD_STND", + "S_ROBOHOOD_SHOOT", + "S_ROBOHOOD_JUMP", + "S_ROBOHOOD_JUMP2", + "S_ROBOHOOD_FALL", + + // CastleBot FaceStabber + "S_FACESTABBER_STND1", + "S_FACESTABBER_STND2", + "S_FACESTABBER_STND3", + "S_FACESTABBER_STND4", + "S_FACESTABBER_STND5", + "S_FACESTABBER_STND6", + "S_FACESTABBER_CHARGE1", + "S_FACESTABBER_CHARGE2", + "S_FACESTABBER_CHARGE3", + "S_FACESTABBER_CHARGE4", + + // Egg Guard + "S_EGGGUARD_STND", + "S_EGGGUARD_WALK1", + "S_EGGGUARD_WALK2", + "S_EGGGUARD_WALK3", + "S_EGGGUARD_WALK4", + "S_EGGGUARD_MAD1", + "S_EGGGUARD_MAD2", + "S_EGGGUARD_MAD3", + "S_EGGGUARD_RUN1", + "S_EGGGUARD_RUN2", + "S_EGGGUARD_RUN3", + "S_EGGGUARD_RUN4", + + // Egg Shield for Egg Guard + "S_EGGSHIELD", + + // Green Snapper + "S_GSNAPPER_STND", + "S_GSNAPPER1", + "S_GSNAPPER2", + "S_GSNAPPER3", + "S_GSNAPPER4", + + // Minus + "S_MINUS_STND", + "S_MINUS_DIGGING", + "S_MINUS_POPUP", + "S_MINUS_UPWARD1", + "S_MINUS_UPWARD2", + "S_MINUS_UPWARD3", + "S_MINUS_UPWARD4", + "S_MINUS_UPWARD5", + "S_MINUS_UPWARD6", + "S_MINUS_UPWARD7", + "S_MINUS_UPWARD8", + "S_MINUS_DOWNWARD1", + "S_MINUS_DOWNWARD2", + "S_MINUS_DOWNWARD3", + "S_MINUS_DOWNWARD4", + "S_MINUS_DOWNWARD5", + "S_MINUS_DOWNWARD6", + "S_MINUS_DOWNWARD7", + "S_MINUS_DOWNWARD8", + + // Spring Shell + "S_SSHELL_STND", + "S_SSHELL_RUN1", + "S_SSHELL_RUN2", + "S_SSHELL_RUN3", + "S_SSHELL_RUN4", + "S_SSHELL_SPRING1", + "S_SSHELL_SPRING2", + "S_SSHELL_SPRING3", + "S_SSHELL_SPRING4", + + // Spring Shell (yellow) + "S_YSHELL_STND", + "S_YSHELL_RUN1", + "S_YSHELL_RUN2", + "S_YSHELL_RUN3", + "S_YSHELL_RUN4", + "S_YSHELL_SPRING1", + "S_YSHELL_SPRING2", + "S_YSHELL_SPRING3", + "S_YSHELL_SPRING4", + + // Unidus + "S_UNIDUS_STND", + "S_UNIDUS_RUN", + "S_UNIDUS_BALL", + + // Boss Explosion + "S_BPLD1", + "S_BPLD2", + "S_BPLD3", + "S_BPLD4", + "S_BPLD5", + "S_BPLD6", + "S_BPLD7", + + // S3&K Boss Explosion + "S_SONIC3KBOSSEXPLOSION1", + "S_SONIC3KBOSSEXPLOSION2", + "S_SONIC3KBOSSEXPLOSION3", + "S_SONIC3KBOSSEXPLOSION4", + "S_SONIC3KBOSSEXPLOSION5", + "S_SONIC3KBOSSEXPLOSION6", + + "S_JETFUME1", + "S_JETFUME2", + + // Boss 1 + "S_EGGMOBILE_STND", + "S_EGGMOBILE_LATK1", + "S_EGGMOBILE_LATK2", + "S_EGGMOBILE_LATK3", + "S_EGGMOBILE_LATK4", + "S_EGGMOBILE_LATK5", + "S_EGGMOBILE_LATK6", + "S_EGGMOBILE_LATK7", + "S_EGGMOBILE_LATK8", + "S_EGGMOBILE_LATK9", + "S_EGGMOBILE_LATK10", + "S_EGGMOBILE_RATK1", + "S_EGGMOBILE_RATK2", + "S_EGGMOBILE_RATK3", + "S_EGGMOBILE_RATK4", + "S_EGGMOBILE_RATK5", + "S_EGGMOBILE_RATK6", + "S_EGGMOBILE_RATK7", + "S_EGGMOBILE_RATK8", + "S_EGGMOBILE_RATK9", + "S_EGGMOBILE_RATK10", + "S_EGGMOBILE_PANIC1", + "S_EGGMOBILE_PANIC2", + "S_EGGMOBILE_PANIC3", + "S_EGGMOBILE_PANIC4", + "S_EGGMOBILE_PANIC5", + "S_EGGMOBILE_PANIC6", + "S_EGGMOBILE_PANIC7", + "S_EGGMOBILE_PANIC8", + "S_EGGMOBILE_PANIC9", + "S_EGGMOBILE_PANIC10", + "S_EGGMOBILE_PAIN", + "S_EGGMOBILE_PAIN2", + "S_EGGMOBILE_DIE1", + "S_EGGMOBILE_DIE2", + "S_EGGMOBILE_DIE3", + "S_EGGMOBILE_DIE4", + "S_EGGMOBILE_DIE5", + "S_EGGMOBILE_DIE6", + "S_EGGMOBILE_DIE7", + "S_EGGMOBILE_DIE8", + "S_EGGMOBILE_DIE9", + "S_EGGMOBILE_DIE10", + "S_EGGMOBILE_DIE11", + "S_EGGMOBILE_DIE12", + "S_EGGMOBILE_DIE13", + "S_EGGMOBILE_DIE14", + "S_EGGMOBILE_FLEE1", + "S_EGGMOBILE_FLEE2", + "S_EGGMOBILE_BALL", + "S_EGGMOBILE_TARGET", + + // Boss 2 + "S_EGGMOBILE2_STND", + "S_EGGMOBILE2_POGO1", + "S_EGGMOBILE2_POGO2", + "S_EGGMOBILE2_POGO3", + "S_EGGMOBILE2_POGO4", + "S_EGGMOBILE2_POGO5", + "S_EGGMOBILE2_POGO6", + "S_EGGMOBILE2_POGO7", + "S_EGGMOBILE2_PAIN", + "S_EGGMOBILE2_PAIN2", + "S_EGGMOBILE2_DIE1", + "S_EGGMOBILE2_DIE2", + "S_EGGMOBILE2_DIE3", + "S_EGGMOBILE2_DIE4", + "S_EGGMOBILE2_DIE5", + "S_EGGMOBILE2_DIE6", + "S_EGGMOBILE2_DIE7", + "S_EGGMOBILE2_DIE8", + "S_EGGMOBILE2_DIE9", + "S_EGGMOBILE2_DIE10", + "S_EGGMOBILE2_DIE11", + "S_EGGMOBILE2_DIE12", + "S_EGGMOBILE2_DIE13", + "S_EGGMOBILE2_DIE14", + "S_EGGMOBILE2_FLEE1", + "S_EGGMOBILE2_FLEE2", + + "S_BOSSTANK1", + "S_BOSSTANK2", + "S_BOSSSPIGOT", + + // Boss 2 Goop + "S_GOOP1", + "S_GOOP2", + "S_GOOP3", + + // Boss 3 + "S_EGGMOBILE3_STND", + "S_EGGMOBILE3_ATK1", + "S_EGGMOBILE3_ATK2", + "S_EGGMOBILE3_ATK3A", + "S_EGGMOBILE3_ATK3B", + "S_EGGMOBILE3_ATK3C", + "S_EGGMOBILE3_ATK3D", + "S_EGGMOBILE3_ATK4", + "S_EGGMOBILE3_ATK5", + "S_EGGMOBILE3_LAUGH1", + "S_EGGMOBILE3_LAUGH2", + "S_EGGMOBILE3_LAUGH3", + "S_EGGMOBILE3_LAUGH4", + "S_EGGMOBILE3_LAUGH5", + "S_EGGMOBILE3_LAUGH6", + "S_EGGMOBILE3_LAUGH7", + "S_EGGMOBILE3_LAUGH8", + "S_EGGMOBILE3_LAUGH9", + "S_EGGMOBILE3_LAUGH10", + "S_EGGMOBILE3_LAUGH11", + "S_EGGMOBILE3_LAUGH12", + "S_EGGMOBILE3_LAUGH13", + "S_EGGMOBILE3_LAUGH14", + "S_EGGMOBILE3_LAUGH15", + "S_EGGMOBILE3_LAUGH16", + "S_EGGMOBILE3_LAUGH17", + "S_EGGMOBILE3_LAUGH18", + "S_EGGMOBILE3_LAUGH19", + "S_EGGMOBILE3_LAUGH20", + "S_EGGMOBILE3_PAIN", + "S_EGGMOBILE3_PAIN2", + "S_EGGMOBILE3_DIE1", + "S_EGGMOBILE3_DIE2", + "S_EGGMOBILE3_DIE3", + "S_EGGMOBILE3_DIE4", + "S_EGGMOBILE3_DIE5", + "S_EGGMOBILE3_DIE6", + "S_EGGMOBILE3_DIE7", + "S_EGGMOBILE3_DIE8", + "S_EGGMOBILE3_DIE9", + "S_EGGMOBILE3_DIE10", + "S_EGGMOBILE3_DIE11", + "S_EGGMOBILE3_DIE12", + "S_EGGMOBILE3_DIE13", + "S_EGGMOBILE3_DIE14", + "S_EGGMOBILE3_FLEE1", + "S_EGGMOBILE3_FLEE2", + + // Boss 3 Propeller + "S_PROPELLER1", + "S_PROPELLER2", + "S_PROPELLER3", + "S_PROPELLER4", + "S_PROPELLER5", + "S_PROPELLER6", + "S_PROPELLER7", + + // Boss 3 pinch + "S_FAKEMOBILE_INIT", + "S_FAKEMOBILE", + "S_FAKEMOBILE_ATK1", + "S_FAKEMOBILE_ATK2", + "S_FAKEMOBILE_ATK3A", + "S_FAKEMOBILE_ATK3B", + "S_FAKEMOBILE_ATK3C", + "S_FAKEMOBILE_ATK3D", + "S_FAKEMOBILE_ATK4", + "S_FAKEMOBILE_ATK5", + + // Boss 4 + "S_EGGMOBILE4_STND", + "S_EGGMOBILE4_LATK1", + "S_EGGMOBILE4_LATK2", + "S_EGGMOBILE4_LATK3", + "S_EGGMOBILE4_LATK4", + "S_EGGMOBILE4_LATK5", + "S_EGGMOBILE4_LATK6", + "S_EGGMOBILE4_RATK1", + "S_EGGMOBILE4_RATK2", + "S_EGGMOBILE4_RATK3", + "S_EGGMOBILE4_RATK4", + "S_EGGMOBILE4_RATK5", + "S_EGGMOBILE4_RATK6", + "S_EGGMOBILE4_RAISE1", + "S_EGGMOBILE4_RAISE2", + "S_EGGMOBILE4_RAISE3", + "S_EGGMOBILE4_RAISE4", + "S_EGGMOBILE4_RAISE5", + "S_EGGMOBILE4_RAISE6", + "S_EGGMOBILE4_RAISE7", + "S_EGGMOBILE4_RAISE8", + "S_EGGMOBILE4_RAISE9", + "S_EGGMOBILE4_RAISE10", + "S_EGGMOBILE4_PAIN", + "S_EGGMOBILE4_DIE1", + "S_EGGMOBILE4_DIE2", + "S_EGGMOBILE4_DIE3", + "S_EGGMOBILE4_DIE4", + "S_EGGMOBILE4_DIE5", + "S_EGGMOBILE4_DIE6", + "S_EGGMOBILE4_DIE7", + "S_EGGMOBILE4_DIE8", + "S_EGGMOBILE4_DIE9", + "S_EGGMOBILE4_DIE10", + "S_EGGMOBILE4_DIE11", + "S_EGGMOBILE4_DIE12", + "S_EGGMOBILE4_DIE13", + "S_EGGMOBILE4_DIE14", + "S_EGGMOBILE4_FLEE1", + "S_EGGMOBILE4_FLEE2", + "S_EGGMOBILE4_MACE", + + // Boss 4 jet flame + "S_JETFLAME1", + "S_JETFLAME2", + + // Black Eggman (Boss 7) + "S_BLACKEGG_STND", + "S_BLACKEGG_STND2", + "S_BLACKEGG_WALK1", + "S_BLACKEGG_WALK2", + "S_BLACKEGG_WALK3", + "S_BLACKEGG_WALK4", + "S_BLACKEGG_WALK5", + "S_BLACKEGG_WALK6", + "S_BLACKEGG_SHOOT1", + "S_BLACKEGG_SHOOT2", + "S_BLACKEGG_PAIN1", + "S_BLACKEGG_PAIN2", + "S_BLACKEGG_PAIN3", + "S_BLACKEGG_PAIN4", + "S_BLACKEGG_PAIN5", + "S_BLACKEGG_PAIN6", + "S_BLACKEGG_PAIN7", + "S_BLACKEGG_PAIN8", + "S_BLACKEGG_PAIN9", + "S_BLACKEGG_PAIN10", + "S_BLACKEGG_PAIN11", + "S_BLACKEGG_PAIN12", + "S_BLACKEGG_PAIN13", + "S_BLACKEGG_PAIN14", + "S_BLACKEGG_PAIN15", + "S_BLACKEGG_PAIN16", + "S_BLACKEGG_PAIN17", + "S_BLACKEGG_PAIN18", + "S_BLACKEGG_PAIN19", + "S_BLACKEGG_PAIN20", + "S_BLACKEGG_PAIN21", + "S_BLACKEGG_PAIN22", + "S_BLACKEGG_PAIN23", + "S_BLACKEGG_PAIN24", + "S_BLACKEGG_PAIN25", + "S_BLACKEGG_PAIN26", + "S_BLACKEGG_PAIN27", + "S_BLACKEGG_PAIN28", + "S_BLACKEGG_PAIN29", + "S_BLACKEGG_PAIN30", + "S_BLACKEGG_PAIN31", + "S_BLACKEGG_PAIN32", + "S_BLACKEGG_PAIN33", + "S_BLACKEGG_PAIN34", + "S_BLACKEGG_PAIN35", + "S_BLACKEGG_HITFACE1", + "S_BLACKEGG_HITFACE2", + "S_BLACKEGG_HITFACE3", + "S_BLACKEGG_HITFACE4", + "S_BLACKEGG_DIE1", + "S_BLACKEGG_DIE2", + "S_BLACKEGG_DIE3", + "S_BLACKEGG_DIE4", + "S_BLACKEGG_DIE5", + "S_BLACKEGG_MISSILE1", + "S_BLACKEGG_MISSILE2", + "S_BLACKEGG_MISSILE3", + "S_BLACKEGG_GOOP", + "S_BLACKEGG_JUMP1", + "S_BLACKEGG_JUMP2", + "S_BLACKEGG_DESTROYPLAT1", + "S_BLACKEGG_DESTROYPLAT2", + "S_BLACKEGG_DESTROYPLAT3", + + "S_BLACKEGG_HELPER", // Collision helper + + "S_BLACKEGG_GOOP1", + "S_BLACKEGG_GOOP2", + "S_BLACKEGG_GOOP3", + "S_BLACKEGG_GOOP4", + "S_BLACKEGG_GOOP5", + "S_BLACKEGG_GOOP6", + "S_BLACKEGG_GOOP7", + + "S_BLACKEGG_MISSILE", + + // New Very-Last-Minute 2.1 Brak Eggman (Cy-Brak-demon) + "S_CYBRAKDEMON_IDLE", + "S_CYBRAKDEMON_WALK1", + "S_CYBRAKDEMON_WALK2", + "S_CYBRAKDEMON_WALK3", + "S_CYBRAKDEMON_WALK4", + "S_CYBRAKDEMON_WALK5", + "S_CYBRAKDEMON_WALK6", + "S_CYBRAKDEMON_CHOOSE_ATTACK1", + "S_CYBRAKDEMON_MISSILE_ATTACK1", // Aim + "S_CYBRAKDEMON_MISSILE_ATTACK2", // Fire + "S_CYBRAKDEMON_MISSILE_ATTACK3", // Aim + "S_CYBRAKDEMON_MISSILE_ATTACK4", // Fire + "S_CYBRAKDEMON_MISSILE_ATTACK5", // Aim + "S_CYBRAKDEMON_MISSILE_ATTACK6", // Fire + "S_CYBRAKDEMON_FLAME_ATTACK1", // Reset + "S_CYBRAKDEMON_FLAME_ATTACK2", // Aim + "S_CYBRAKDEMON_FLAME_ATTACK3", // Fire + "S_CYBRAKDEMON_FLAME_ATTACK4", // Loop + "S_CYBRAKDEMON_CHOOSE_ATTACK2", + "S_CYBRAKDEMON_VILE_ATTACK1", + "S_CYBRAKDEMON_VILE_ATTACK2", + "S_CYBRAKDEMON_VILE_ATTACK3", + "S_CYBRAKDEMON_VILE_ATTACK4", + "S_CYBRAKDEMON_VILE_ATTACK5", + "S_CYBRAKDEMON_VILE_ATTACK6", + "S_CYBRAKDEMON_NAPALM_ATTACK1", + "S_CYBRAKDEMON_NAPALM_ATTACK2", + "S_CYBRAKDEMON_NAPALM_ATTACK3", + "S_CYBRAKDEMON_FINISH_ATTACK", // If just attacked, remove MF2_FRET w/out going back to spawnstate + "S_CYBRAKDEMON_FINISH_ATTACK2", // Force a delay between attacks so you don't get bombarded with them back-to-back + "S_CYBRAKDEMON_PAIN1", + "S_CYBRAKDEMON_PAIN2", + "S_CYBRAKDEMON_PAIN3", + "S_CYBRAKDEMON_DIE1", + "S_CYBRAKDEMON_DIE2", + "S_CYBRAKDEMON_DIE3", + "S_CYBRAKDEMON_DIE4", + "S_CYBRAKDEMON_DIE5", + "S_CYBRAKDEMON_DIE6", + "S_CYBRAKDEMON_DIE7", + "S_CYBRAKDEMON_DIE8", + "S_CYBRAKDEMON_DEINVINCIBLERIZE", + "S_CYBRAKDEMON_INVINCIBLERIZE", + + "S_CYBRAKDEMONMISSILE", + "S_CYBRAKDEMONMISSILE_EXPLODE1", + "S_CYBRAKDEMONMISSILE_EXPLODE2", + "S_CYBRAKDEMONMISSILE_EXPLODE3", + + "S_CYBRAKDEMONFLAMESHOT_FLY1", + "S_CYBRAKDEMONFLAMESHOT_FLY2", + "S_CYBRAKDEMONFLAMESHOT_FLY3", + "S_CYBRAKDEMONFLAMESHOT_DIE", + + "S_CYBRAKDEMONFLAMEREST", + + "S_CYBRAKDEMONELECTRICBARRIER_INIT1", + "S_CYBRAKDEMONELECTRICBARRIER_INIT2", + "S_CYBRAKDEMONELECTRICBARRIER_PLAYSOUND", + "S_CYBRAKDEMONELECTRICBARRIER1", + "S_CYBRAKDEMONELECTRICBARRIER2", + "S_CYBRAKDEMONELECTRICBARRIER3", + "S_CYBRAKDEMONELECTRICBARRIER4", + "S_CYBRAKDEMONELECTRICBARRIER5", + "S_CYBRAKDEMONELECTRICBARRIER6", + "S_CYBRAKDEMONELECTRICBARRIER7", + "S_CYBRAKDEMONELECTRICBARRIER8", + "S_CYBRAKDEMONELECTRICBARRIER9", + "S_CYBRAKDEMONELECTRICBARRIER10", + "S_CYBRAKDEMONELECTRICBARRIER11", + "S_CYBRAKDEMONELECTRICBARRIER12", + "S_CYBRAKDEMONELECTRICBARRIER13", + "S_CYBRAKDEMONELECTRICBARRIER14", + "S_CYBRAKDEMONELECTRICBARRIER15", + "S_CYBRAKDEMONELECTRICBARRIER16", + "S_CYBRAKDEMONELECTRICBARRIER17", + "S_CYBRAKDEMONELECTRICBARRIER18", + "S_CYBRAKDEMONELECTRICBARRIER19", + "S_CYBRAKDEMONELECTRICBARRIER20", + "S_CYBRAKDEMONELECTRICBARRIER21", + "S_CYBRAKDEMONELECTRICBARRIER22", + "S_CYBRAKDEMONELECTRICBARRIER23", + "S_CYBRAKDEMONELECTRICBARRIER24", + "S_CYBRAKDEMONELECTRICBARRIER_DIE1", + "S_CYBRAKDEMONELECTRICBARRIER_DIE2", + "S_CYBRAKDEMONELECTRICBARRIER_DIE3", + "S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOMCHECK", + "S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOMSUCCESS", + "S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOMCHOOSE", + "S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOM1", + "S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOM2", + "S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOM3", + "S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOM4", + "S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOM5", + "S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOM6", + "S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOM7", + "S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOM8", + "S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOM9", + "S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOM10", + "S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOM11", + "S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOM12", + "S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOMFAIL", + "S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOMLOOP", + "S_CYBRAKDEMONELECTRICBARRIER_REVIVE1", + "S_CYBRAKDEMONELECTRICBARRIER_REVIVE2", + "S_CYBRAKDEMONELECTRICBARRIER_REVIVE3", + + "S_CYBRAKDEMONTARGETRETICULE1", + "S_CYBRAKDEMONTARGETRETICULE2", + "S_CYBRAKDEMONTARGETRETICULE3", + "S_CYBRAKDEMONTARGETRETICULE4", + "S_CYBRAKDEMONTARGETRETICULE5", + "S_CYBRAKDEMONTARGETRETICULE6", + "S_CYBRAKDEMONTARGETRETICULE7", + "S_CYBRAKDEMONTARGETRETICULE8", + "S_CYBRAKDEMONTARGETRETICULE9", + "S_CYBRAKDEMONTARGETRETICULE10", + "S_CYBRAKDEMONTARGETRETICULE11", + "S_CYBRAKDEMONTARGETRETICULE12", + "S_CYBRAKDEMONTARGETRETICULE13", + "S_CYBRAKDEMONTARGETRETICULE14", + + "S_CYBRAKDEMONNAPALMBOMBLARGE_FLY1", + "S_CYBRAKDEMONNAPALMBOMBLARGE_FLY2", + "S_CYBRAKDEMONNAPALMBOMBLARGE_FLY3", + "S_CYBRAKDEMONNAPALMBOMBLARGE_FLY4", + "S_CYBRAKDEMONNAPALMBOMBLARGE_DIE1", // Explode + "S_CYBRAKDEMONNAPALMBOMBLARGE_DIE2", // Outer ring + "S_CYBRAKDEMONNAPALMBOMBLARGE_DIE3", // Center + "S_CYBRAKDEMONNAPALMBOMBLARGE_DIE4", // Sound + + "S_CYBRAKDEMONNAPALMBOMBSMALL", + "S_CYBRAKDEMONNAPALMBOMBSMALL_DIE1", // Explode + "S_CYBRAKDEMONNAPALMBOMBSMALL_DIE2", // Outer ring + "S_CYBRAKDEMONNAPALMBOMBSMALL_DIE3", // Inner ring + "S_CYBRAKDEMONNAPALMBOMBSMALL_DIE4", // Center + "S_CYBRAKDEMONNAPALMBOMBSMALL_DIE5", // Sound + + "S_CYBRAKDEMONNAPALMFLAME_FLY1", + "S_CYBRAKDEMONNAPALMFLAME_FLY2", + "S_CYBRAKDEMONNAPALMFLAME_FLY3", + "S_CYBRAKDEMONNAPALMFLAME_FLY4", + "S_CYBRAKDEMONNAPALMFLAME_FLY5", + "S_CYBRAKDEMONNAPALMFLAME_FLY6", + "S_CYBRAKDEMONNAPALMFLAME_DIE", + + "S_CYBRAKDEMONVILEEXPLOSION1", + "S_CYBRAKDEMONVILEEXPLOSION2", + "S_CYBRAKDEMONVILEEXPLOSION3", + + // Metal Sonic (Race) + // S_PLAY_STND + "S_METALSONIC_STAND", + // S_PLAY_TAP1 + "S_METALSONIC_WAIT1", + "S_METALSONIC_WAIT2", + // S_PLAY_RUN1 + "S_METALSONIC_WALK1", + "S_METALSONIC_WALK2", + "S_METALSONIC_WALK3", + "S_METALSONIC_WALK4", + "S_METALSONIC_WALK5", + "S_METALSONIC_WALK6", + "S_METALSONIC_WALK7", + "S_METALSONIC_WALK8", + // S_PLAY_SPD1 + "S_METALSONIC_RUN1", + "S_METALSONIC_RUN2", + "S_METALSONIC_RUN3", + "S_METALSONIC_RUN4", + // Metal Sonic (Battle) + "S_METALSONIC_FLOAT", + "S_METALSONIC_VECTOR", + "S_METALSONIC_STUN", + "S_METALSONIC_BLOCK", + "S_METALSONIC_RAISE", + "S_METALSONIC_GATHER", + "S_METALSONIC_DASH", + "S_METALSONIC_BOUNCE", + "S_METALSONIC_SHOOT", + "S_METALSONIC_PAIN", + "S_METALSONIC_DEATH", + "S_METALSONIC_FLEE1", + "S_METALSONIC_FLEE2", + "S_METALSONIC_FLEE3", + "S_METALSONIC_FLEE4", + + "S_MSSHIELD_F1", + "S_MSSHIELD_F2", + "S_MSSHIELD_F3", + "S_MSSHIELD_F4", + "S_MSSHIELD_F5", + "S_MSSHIELD_F6", + "S_MSSHIELD_F7", + "S_MSSHIELD_F8", + "S_MSSHIELD_F9", + "S_MSSHIELD_F10", + "S_MSSHIELD_F11", + "S_MSSHIELD_F12", + + // Ring + "S_RING1", + "S_RING2", + "S_RING3", + "S_RING4", + "S_RING5", + "S_RING6", + "S_RING7", + "S_RING8", + "S_RING9", + "S_RING10", + "S_RING11", + "S_RING12", + "S_RING13", + "S_RING14", + "S_RING15", + "S_RING16", + "S_RING17", + "S_RING18", + "S_RING19", + "S_RING20", + "S_RING21", + "S_RING22", + "S_RING23", + "S_RING24", + + // Blue Sphere for special stages + "S_BLUEBALL", + "S_BLUEBALLSPARK", + + // Gravity Wells for special stages + "S_GRAVWELLGREEN", + "S_GRAVWELLGREEN2", + "S_GRAVWELLGREEN3", + + "S_GRAVWELLRED", + "S_GRAVWELLRED2", + "S_GRAVWELLRED3", + + // Individual Team Rings + "S_TEAMRING1", + "S_TEAMRING2", + "S_TEAMRING3", + "S_TEAMRING4", + "S_TEAMRING5", + "S_TEAMRING6", + "S_TEAMRING7", + "S_TEAMRING8", + "S_TEAMRING9", + "S_TEAMRING10", + "S_TEAMRING11", + "S_TEAMRING12", + "S_TEAMRING13", + "S_TEAMRING14", + "S_TEAMRING15", + "S_TEAMRING16", + "S_TEAMRING17", + "S_TEAMRING18", + "S_TEAMRING19", + "S_TEAMRING20", + "S_TEAMRING21", + "S_TEAMRING22", + "S_TEAMRING23", + "S_TEAMRING24", + + // Special Stage Token + "S_EMMY1", + "S_EMMY2", + "S_EMMY3", + "S_EMMY4", + "S_EMMY5", + "S_EMMY6", + "S_EMMY7", + + // Special Stage Token + "S_TOKEN", + "S_MOVINGTOKEN", + + // CTF Flags + "S_REDFLAG", + "S_BLUEFLAG", + + // Emblem + "S_EMBLEM1", + "S_EMBLEM2", + "S_EMBLEM3", + "S_EMBLEM4", + "S_EMBLEM5", + "S_EMBLEM6", + "S_EMBLEM7", + "S_EMBLEM8", + "S_EMBLEM9", + "S_EMBLEM10", + "S_EMBLEM11", + "S_EMBLEM12", + "S_EMBLEM13", + "S_EMBLEM14", + "S_EMBLEM15", + "S_EMBLEM16", + "S_EMBLEM17", + "S_EMBLEM18", + "S_EMBLEM19", + "S_EMBLEM20", + "S_EMBLEM21", + "S_EMBLEM22", + "S_EMBLEM23", + "S_EMBLEM24", + "S_EMBLEM25", + "S_EMBLEM26", + + // Chaos Emeralds + "S_CEMG1", + "S_CEMG2", + "S_CEMG3", + "S_CEMG4", + "S_CEMG5", + "S_CEMG6", + "S_CEMG7", + + // Emeralds (for hunt) + "S_EMER1", + + "S_FAN", + "S_FAN2", + "S_FAN3", + "S_FAN4", + "S_FAN5", + + // Bubble Source + "S_BUBBLES1", + "S_BUBBLES2", + + // Level End Sign + "S_SIGN1", + "S_SIGN2", + "S_SIGN3", + "S_SIGN4", + "S_SIGN5", + "S_SIGN6", + "S_SIGN7", + "S_SIGN8", + "S_SIGN9", + "S_SIGN10", + "S_SIGN11", + "S_SIGN12", + "S_SIGN13", + "S_SIGN14", + "S_SIGN15", + "S_SIGN16", + "S_SIGN17", + "S_SIGN18", + "S_SIGN19", + "S_SIGN20", + "S_SIGN21", + "S_SIGN22", + "S_SIGN23", + "S_SIGN24", + "S_SIGN25", + "S_SIGN26", + "S_SIGN27", + "S_SIGN28", + "S_SIGN29", + "S_SIGN30", + "S_SIGN31", + "S_SIGN32", + "S_SIGN33", + "S_SIGN34", + "S_SIGN35", + "S_SIGN36", + "S_SIGN37", + "S_SIGN38", + "S_SIGN39", + "S_SIGN40", + "S_SIGN41", + "S_SIGN42", + "S_SIGN43", + "S_SIGN44", + "S_SIGN45", + "S_SIGN46", + "S_SIGN47", + "S_SIGN48", + "S_SIGN49", + "S_SIGN50", + "S_SIGN51", + "S_SIGN52", // Eggman + "S_SIGN53", + + // Steam Riser + "S_STEAM1", + "S_STEAM2", + "S_STEAM3", + "S_STEAM4", + "S_STEAM5", + "S_STEAM6", + "S_STEAM7", + "S_STEAM8", + + // Spike Ball + "S_SPIKEBALL1", + "S_SPIKEBALL2", + "S_SPIKEBALL3", + "S_SPIKEBALL4", + "S_SPIKEBALL5", + "S_SPIKEBALL6", + "S_SPIKEBALL7", + "S_SPIKEBALL8", + + // Fire Shield's Spawn + "S_SPINFIRE1", + "S_SPINFIRE2", + "S_SPINFIRE3", + "S_SPINFIRE4", + "S_SPINFIRE5", + "S_SPINFIRE6", + + // Spikes + "S_SPIKE1", + "S_SPIKE2", + "S_SPIKE3", + "S_SPIKE4", + "S_SPIKE5", + "S_SPIKE6", + "S_SPIKED1", + "S_SPIKED2", + + // Starpost + "S_STARPOST1", + "S_STARPOST2", + "S_STARPOST3", + "S_STARPOST4", + "S_STARPOST5", + "S_STARPOST6", + "S_STARPOST7", + "S_STARPOST8", + "S_STARPOST9", + "S_STARPOST10", + "S_STARPOST11", + "S_STARPOST12", + "S_STARPOST13", + "S_STARPOST14", + "S_STARPOST15", + "S_STARPOST16", + "S_STARPOST17", + "S_STARPOST18", + "S_STARPOST19", + "S_STARPOST20", + "S_STARPOST21", + "S_STARPOST22", + "S_STARPOST23", + "S_STARPOST24", + "S_STARPOST25", + "S_STARPOST26", + "S_STARPOST27", + "S_STARPOST28", + "S_STARPOST29", + "S_STARPOST30", + "S_STARPOST31", + "S_STARPOST32", + "S_STARPOST33", + "S_STARPOST34", + + // Big floating mine + "S_BIGMINE1", + "S_BIGMINE2", + "S_BIGMINE3", + "S_BIGMINE4", + "S_BIGMINE5", + "S_BIGMINE6", + "S_BIGMINE7", + "S_BIGMINE8", + + // Cannon Launcher + "S_CANNONLAUNCHER1", + "S_CANNONLAUNCHER2", + "S_CANNONLAUNCHER3", + + // Super Ring Box + "S_SUPERRINGBOX", + "S_SUPERRINGBOX1", + "S_SUPERRINGBOX2", + "S_SUPERRINGBOX3", + "S_SUPERRINGBOX4", + "S_SUPERRINGBOX5", + "S_SUPERRINGBOX6", + + // Red Team Ring Box + "S_REDRINGBOX", + "S_REDRINGBOX1", + + // Blue Team Ring Box + "S_BLUERINGBOX", + "S_BLUERINGBOX1", + + // Super Sneakers Box + "S_SHTV", + "S_SHTV1", + "S_SHTV2", + "S_SHTV3", + "S_SHTV4", + "S_SHTV5", + "S_SHTV6", + + // Invincibility Box + "S_PINV", + "S_PINV1", + "S_PINV2", + "S_PINV3", + "S_PINV4", + "S_PINV5", + "S_PINV6", + + // 1-Up Box + "S_PRUP", + "S_PRUP1", + "S_PRUP2", + "S_PRUP3", + "S_PRUP4", + "S_PRUP5", + "S_PRUP6", + + // Ring Shield Box + "S_YLTV", + "S_YLTV1", + "S_YLTV2", + "S_YLTV3", + "S_YLTV4", + "S_YLTV5", + "S_YLTV6", + + // Force Shield Box + "S_BLTV1", + "S_BLTV2", + "S_BLTV3", + "S_BLTV4", + "S_BLTV5", + "S_BLTV6", + "S_BLTV7", + + // Bomb Shield Box + "S_BKTV1", + "S_BKTV2", + "S_BKTV3", + "S_BKTV4", + "S_BKTV5", + "S_BKTV6", + "S_BKTV7", + + // Jump Shield Box + "S_WHTV1", + "S_WHTV2", + "S_WHTV3", + "S_WHTV4", + "S_WHTV5", + "S_WHTV6", + "S_WHTV7", + + // Water Shield Box + "S_GRTV", + "S_GRTV1", + "S_GRTV2", + "S_GRTV3", + "S_GRTV4", + "S_GRTV5", + "S_GRTV6", + + // Pity Shield Box + "S_PITV1", + "S_PITV2", + "S_PITV3", + "S_PITV4", + "S_PITV5", + "S_PITV6", + "S_PITV7", + + // Eggman Box + "S_EGGTV1", + "S_EGGTV2", + "S_EGGTV3", + "S_EGGTV4", + "S_EGGTV5", + "S_EGGTV6", + "S_EGGTV7", + + // Teleport Box + "S_MIXUPBOX1", + "S_MIXUPBOX2", + "S_MIXUPBOX3", + "S_MIXUPBOX4", + "S_MIXUPBOX5", + "S_MIXUPBOX6", + "S_MIXUPBOX7", + + // Recycler Box + "S_RECYCLETV1", + "S_RECYCLETV2", + "S_RECYCLETV3", + "S_RECYCLETV4", + "S_RECYCLETV5", + "S_RECYCLETV6", + "S_RECYCLETV7", + + // Question Box + "S_RANDOMBOX1", + "S_RANDOMBOX2", + "S_RANDOMBOX3", + + // Gravity Boots Box + "S_GBTV1", + "S_GBTV2", + "S_GBTV3", + "S_GBTV4", + "S_GBTV5", + "S_GBTV6", + "S_GBTV7", + + // Score boxes + "S_SCORETVA1", + "S_SCORETVA2", + "S_SCORETVA3", + "S_SCORETVA4", + "S_SCORETVA5", + "S_SCORETVA6", + "S_SCORETVA7", + "S_SCORETVB1", + "S_SCORETVB2", + "S_SCORETVB3", + "S_SCORETVB4", + "S_SCORETVB5", + "S_SCORETVB6", + "S_SCORETVB7", + + // Monitor Explosion + "S_MONITOREXPLOSION1", + "S_MONITOREXPLOSION2", + + "S_REDMONITOREXPLOSION1", + "S_REDMONITOREXPLOSION2", + + "S_BLUEMONITOREXPLOSION1", + "S_BLUEMONITOREXPLOSION2", + + "S_ROCKET", + + "S_LASER", + + "S_TORPEDO", + + "S_ENERGYBALL1", + "S_ENERGYBALL2", + + // Skim Mine, also used by Jetty-Syn bomber + "S_MINE1", + "S_MINE_BOOM1", + "S_MINE_BOOM2", + "S_MINE_BOOM3", + "S_MINE_BOOM4", + + // Jetty-Syn Bullet + "S_JETBULLET1", + "S_JETBULLET2", + + "S_TURRETLASER", + "S_TURRETLASEREXPLODE1", + "S_TURRETLASEREXPLODE2", + + // Cannonball + "S_CANNONBALL1", + + // Arrow + "S_ARROW", + "S_ARROWUP", + "S_ARROWDOWN", + + // Trapgoyle Demon fire + "S_DEMONFIRE", + + "S_GFZFLOWERA", + "S_GFZFLOWERA2", + + "S_GFZFLOWERB1", + "S_GFZFLOWERB2", + + "S_GFZFLOWERC1", + + "S_BERRYBUSH", + "S_BUSH", + + // THZ Plant + "S_THZPLANT1", + "S_THZPLANT2", + "S_THZPLANT3", + "S_THZPLANT4", + + // THZ Alarm + "S_ALARM1", + + // Deep Sea Gargoyle + "S_GARGOYLE", + + // DSZ Seaweed + "S_SEAWEED1", + "S_SEAWEED2", + "S_SEAWEED3", + "S_SEAWEED4", + "S_SEAWEED5", + "S_SEAWEED6", + + // Dripping Water + "S_DRIPA1", + "S_DRIPA2", + "S_DRIPA3", + "S_DRIPA4", + "S_DRIPB1", + "S_DRIPC1", + "S_DRIPC2", + + // Coral 1 + "S_CORAL1", + + // Coral 2 + "S_CORAL2", + + // Coral 3 + "S_CORAL3", + + // Blue Crystal + "S_BLUECRYSTAL1", + + // CEZ Chain + "S_CEZCHAIN", + + // Flame + "S_FLAME1", + "S_FLAME2", + "S_FLAME3", + "S_FLAME4", + + // Eggman Statue + "S_EGGSTATUE1", + + // CEZ hidden sling + "S_SLING1", + "S_SLING2", + + // CEZ Small Mace Chain + "S_SMALLMACECHAIN", + + // CEZ Big Mace Chain + "S_BIGMACECHAIN", + + // CEZ Small Mace + "S_SMALLMACE", + + // CEZ Big Mace + "S_BIGMACE", + + "S_CEZFLOWER1", + + // Big Tumbleweed + "S_BIGTUMBLEWEED", + "S_BIGTUMBLEWEED_ROLL1", + "S_BIGTUMBLEWEED_ROLL2", + "S_BIGTUMBLEWEED_ROLL3", + "S_BIGTUMBLEWEED_ROLL4", + "S_BIGTUMBLEWEED_ROLL5", + "S_BIGTUMBLEWEED_ROLL6", + "S_BIGTUMBLEWEED_ROLL7", + "S_BIGTUMBLEWEED_ROLL8", + + // Little Tumbleweed + "S_LITTLETUMBLEWEED", + "S_LITTLETUMBLEWEED_ROLL1", + "S_LITTLETUMBLEWEED_ROLL2", + "S_LITTLETUMBLEWEED_ROLL3", + "S_LITTLETUMBLEWEED_ROLL4", + "S_LITTLETUMBLEWEED_ROLL5", + "S_LITTLETUMBLEWEED_ROLL6", + "S_LITTLETUMBLEWEED_ROLL7", + "S_LITTLETUMBLEWEED_ROLL8", + + // Cacti Sprites + "S_CACTI1", + "S_CACTI2", + "S_CACTI3", + "S_CACTI4", + + // Flame jet + "S_FLAMEJETSTND", + "S_FLAMEJETSTART", + "S_FLAMEJETSTOP", + "S_FLAMEJETFLAME1", + "S_FLAMEJETFLAME2", + "S_FLAMEJETFLAME3", + + // Spinning flame jets + "S_FJSPINAXISA1", // Counter-clockwise + "S_FJSPINAXISA2", + "S_FJSPINAXISA3", + "S_FJSPINAXISA4", + "S_FJSPINAXISA5", + "S_FJSPINAXISA6", + "S_FJSPINAXISA7", + "S_FJSPINAXISA8", + "S_FJSPINAXISA9", + "S_FJSPINHELPERA1", + "S_FJSPINHELPERA2", + "S_FJSPINHELPERA3", + "S_FJSPINAXISB1", // Clockwise + "S_FJSPINAXISB2", + "S_FJSPINAXISB3", + "S_FJSPINAXISB4", + "S_FJSPINAXISB5", + "S_FJSPINAXISB6", + "S_FJSPINAXISB7", + "S_FJSPINAXISB8", + "S_FJSPINAXISB9", + "S_FJSPINHELPERB1", + "S_FJSPINHELPERB2", + "S_FJSPINHELPERB3", + + // Blade's flame + "S_FLAMEJETFLAMEB1", + "S_FLAMEJETFLAMEB2", + "S_FLAMEJETFLAMEB3", + "S_FLAMEJETFLAMEB4", + "S_FLAMEJETFLAMEB5", + "S_FLAMEJETFLAMEB6", + + // Trapgoyles + "S_TRAPGOYLE", + "S_TRAPGOYLE_CHECK", + "S_TRAPGOYLE_FIRE1", + "S_TRAPGOYLE_FIRE2", + "S_TRAPGOYLE_FIRE3", + "S_TRAPGOYLEUP", + "S_TRAPGOYLEUP_CHECK", + "S_TRAPGOYLEUP_FIRE1", + "S_TRAPGOYLEUP_FIRE2", + "S_TRAPGOYLEUP_FIRE3", + "S_TRAPGOYLEDOWN", + "S_TRAPGOYLEDOWN_CHECK", + "S_TRAPGOYLEDOWN_FIRE1", + "S_TRAPGOYLEDOWN_FIRE2", + "S_TRAPGOYLEDOWN_FIRE3", + "S_TRAPGOYLELONG", + "S_TRAPGOYLELONG_CHECK", + "S_TRAPGOYLELONG_FIRE1", + "S_TRAPGOYLELONG_FIRE2", + "S_TRAPGOYLELONG_FIRE3", + "S_TRAPGOYLELONG_FIRE4", + "S_TRAPGOYLELONG_FIRE5", + + // ATZ's Red Crystal/Target + "S_TARGET_IDLE", + "S_TARGET_HIT1", + "S_TARGET_HIT2", + "S_TARGET_RESPAWN", + "S_TARGET_ALLDONE", + + // Stalagmites + "S_STG0", + "S_STG1", + "S_STG2", + "S_STG3", + "S_STG4", + "S_STG5", + "S_STG6", + "S_STG7", + "S_STG8", + "S_STG9", + + // Xmas-specific stuff + "S_XMASPOLE", + "S_CANDYCANE", + "S_SNOWMAN", + + // Botanic Serenity's loads of scenery states + "S_BSZTALLFLOWER_RED", + "S_BSZTALLFLOWER_PURPLE", + "S_BSZTALLFLOWER_BLUE", + "S_BSZTALLFLOWER_CYAN", + "S_BSZTALLFLOWER_YELLOW", + "S_BSZTALLFLOWER_ORANGE", + "S_BSZFLOWER_RED", + "S_BSZFLOWER_PURPLE", + "S_BSZFLOWER_BLUE", + "S_BSZFLOWER_CYAN", + "S_BSZFLOWER_YELLOW", + "S_BSZFLOWER_ORANGE", + "S_BSZSHORTFLOWER_RED", + "S_BSZSHORTFLOWER_PURPLE", + "S_BSZSHORTFLOWER_BLUE", + "S_BSZSHORTFLOWER_CYAN", + "S_BSZSHORTFLOWER_YELLOW", + "S_BSZSHORTFLOWER_ORANGE", + "S_BSZTULIP_RED", + "S_BSZTULIP_PURPLE", + "S_BSZTULIP_BLUE", + "S_BSZTULIP_CYAN", + "S_BSZTULIP_YELLOW", + "S_BSZTULIP_ORANGE", + "S_BSZCLUSTER_RED", + "S_BSZCLUSTER_PURPLE", + "S_BSZCLUSTER_BLUE", + "S_BSZCLUSTER_CYAN", + "S_BSZCLUSTER_YELLOW", + "S_BSZCLUSTER_ORANGE", + "S_BSZBUSH_RED", + "S_BSZBUSH_PURPLE", + "S_BSZBUSH_BLUE", + "S_BSZBUSH_CYAN", + "S_BSZBUSH_YELLOW", + "S_BSZBUSH_ORANGE", + "S_BSZVINE_RED", + "S_BSZVINE_PURPLE", + "S_BSZVINE_BLUE", + "S_BSZVINE_CYAN", + "S_BSZVINE_YELLOW", + "S_BSZVINE_ORANGE", + "S_BSZSHRUB", + "S_BSZCLOVER", + "S_BSZFISH", + "S_BSZSUNFLOWER", + + "S_DBALL1", + "S_DBALL2", + "S_DBALL3", + "S_DBALL4", + "S_DBALL5", + "S_DBALL6", + "S_EGGSTATUE2", + + // Shield Orb + "S_ARMA1", + "S_ARMA2", + "S_ARMA3", + "S_ARMA4", + "S_ARMA5", + "S_ARMA6", + "S_ARMA7", + "S_ARMA8", + "S_ARMA9", + "S_ARMA10", + "S_ARMA11", + "S_ARMA12", + "S_ARMA13", + "S_ARMA14", + "S_ARMA15", + "S_ARMA16", + + "S_ARMF1", + "S_ARMF2", + "S_ARMF3", + "S_ARMF4", + "S_ARMF5", + "S_ARMF6", + "S_ARMF7", + "S_ARMF8", + "S_ARMF9", + "S_ARMF10", + "S_ARMF11", + "S_ARMF12", + "S_ARMF13", + "S_ARMF14", + "S_ARMF15", + "S_ARMF16", + + "S_ARMB1", + "S_ARMB2", + "S_ARMB3", + "S_ARMB4", + "S_ARMB5", + "S_ARMB6", + "S_ARMB7", + "S_ARMB8", + "S_ARMB9", + "S_ARMB10", + "S_ARMB11", + "S_ARMB12", + "S_ARMB13", + "S_ARMB14", + "S_ARMB15", + "S_ARMB16", + + "S_WIND1", + "S_WIND2", + "S_WIND3", + "S_WIND4", + "S_WIND5", + "S_WIND6", + "S_WIND7", + "S_WIND8", + + "S_MAGN1", + "S_MAGN2", + "S_MAGN3", + "S_MAGN4", + "S_MAGN5", + "S_MAGN6", + "S_MAGN7", + "S_MAGN8", + "S_MAGN9", + "S_MAGN10", + "S_MAGN11", + "S_MAGN12", + + "S_FORC1", + "S_FORC2", + "S_FORC3", + "S_FORC4", + "S_FORC5", + "S_FORC6", + "S_FORC7", + "S_FORC8", + "S_FORC9", + "S_FORC10", + + "S_FORC11", + "S_FORC12", + "S_FORC13", + "S_FORC14", + "S_FORC15", + "S_FORC16", + "S_FORC17", + "S_FORC18", + "S_FORC19", + "S_FORC20", + + "S_ELEM1", + "S_ELEM2", + "S_ELEM3", + "S_ELEM4", + "S_ELEM5", + "S_ELEM6", + "S_ELEM7", + "S_ELEM8", + "S_ELEM9", + "S_ELEM10", + "S_ELEM11", + "S_ELEM12", + + "S_ELEMF1", + "S_ELEMF2", + "S_ELEMF3", + "S_ELEMF4", + "S_ELEMF5", + "S_ELEMF6", + "S_ELEMF7", + "S_ELEMF8", + + "S_PITY1", + "S_PITY2", + "S_PITY3", + "S_PITY4", + "S_PITY5", + "S_PITY6", + "S_PITY7", + "S_PITY8", + "S_PITY9", + "S_PITY10", + + // Invincibility Sparkles + "S_IVSP1", + "S_IVSP2", + "S_IVSP3", + "S_IVSP4", + "S_IVSP5", + "S_IVSP6", + "S_IVSP7", + "S_IVSP8", + "S_IVSP9", + "S_IVSP10", + "S_IVSP11", + "S_IVSP12", + "S_IVSP13", + "S_IVSP14", + "S_IVSP15", + "S_IVSP16", + "S_IVSP17", + "S_IVSP18", + "S_IVSP19", + "S_IVSP20", + "S_IVSP21", + "S_IVSP22", + "S_IVSP23", + "S_IVSP24", + "S_IVSP25", + "S_IVSP26", + "S_IVSP27", + "S_IVSP28", + "S_IVSP29", + "S_IVSP30", + "S_IVSP31", + "S_IVSP32", + + // Super Sonic Spark + "S_SSPK1", + "S_SSPK2", + "S_SSPK3", + "S_SSPK4", + "S_SSPK5", + + // Freed Birdie + "S_BIRD1", + "S_BIRD2", + "S_BIRD3", + + // Freed Bunny + "S_BUNNY1", + "S_BUNNY2", + "S_BUNNY3", + "S_BUNNY4", + "S_BUNNY5", + "S_BUNNY6", + "S_BUNNY7", + "S_BUNNY8", + "S_BUNNY9", + "S_BUNNY10", + + // Freed Mouse + "S_MOUSE1", + "S_MOUSE2", + + // Freed Chicken + "S_CHICKEN1", + "S_CHICKENHOP", + "S_CHICKENFLY1", + "S_CHICKENFLY2", + + // Freed Cow + "S_COW1", + "S_COW2", + "S_COW3", + "S_COW4", + + // Red Birdie in Bubble + "S_RBIRD1", + "S_RBIRD2", + "S_RBIRD3", + + "S_YELLOWSPRING", + "S_YELLOWSPRING2", + "S_YELLOWSPRING3", + "S_YELLOWSPRING4", + "S_YELLOWSPRING5", + + "S_REDSPRING", + "S_REDSPRING2", + "S_REDSPRING3", + "S_REDSPRING4", + "S_REDSPRING5", + + // Blue Springs + "S_BLUESPRING", + "S_BLUESPRING2", + "S_BLUESPRING3", + "S_BLUESPRING4", + "S_BLUESPRING5", + + // Yellow Diagonal Spring + "S_YDIAG1", + "S_YDIAG2", + "S_YDIAG3", + "S_YDIAG4", + "S_YDIAG5", + "S_YDIAG6", + "S_YDIAG7", + "S_YDIAG8", + + // Red Diagonal Spring + "S_RDIAG1", + "S_RDIAG2", + "S_RDIAG3", + "S_RDIAG4", + "S_RDIAG5", + "S_RDIAG6", + "S_RDIAG7", + "S_RDIAG8", + + // Rain + "S_RAIN1", + "S_RAINRETURN", + + // Snowflake + "S_SNOW1", + "S_SNOW2", + "S_SNOW3", + + // Water Splish + "S_SPLISH1", + "S_SPLISH2", + "S_SPLISH3", + "S_SPLISH4", + "S_SPLISH5", + "S_SPLISH6", + "S_SPLISH7", + "S_SPLISH8", + "S_SPLISH9", + + // added water splash + "S_SPLASH1", + "S_SPLASH2", + "S_SPLASH3", + + // lava/slime damage burn smoke + "S_SMOKE1", + "S_SMOKE2", + "S_SMOKE3", + "S_SMOKE4", + "S_SMOKE5", + + // Bubbles + "S_SMALLBUBBLE", + "S_SMALLBUBBLE1", + "S_MEDIUMBUBBLE", + "S_MEDIUMBUBBLE1", + "S_LARGEBUBBLE", + "S_EXTRALARGEBUBBLE", // breathable + + "S_POP1", // Extra Large bubble goes POP! + + "S_FOG1", + "S_FOG2", + "S_FOG3", + "S_FOG4", + "S_FOG5", + "S_FOG6", + "S_FOG7", + "S_FOG8", + "S_FOG9", + "S_FOG10", + "S_FOG11", + "S_FOG12", + "S_FOG13", + "S_FOG14", + + "S_SEED", + + "S_PARTICLE", + "S_PARTICLEGEN", + + // Score Logos + "S_SCRA", // 100 + "S_SCRB", // 200 + "S_SCRC", // 500 + "S_SCRD", // 1000 + "S_SCRE", // 10000 + "S_SCRF", // 400 (mario) + "S_SCRG", // 800 (mario) + "S_SCRH", // 2000 (mario) + "S_SCRI", // 4000 (mario) + "S_SCRJ", // 8000 (mario) + "S_SCRK", // 1UP (mario) + + // Drowning Timer Numbers + "S_ZERO1", + "S_ONE1", + "S_TWO1", + "S_THREE1", + "S_FOUR1", + "S_FIVE1", + + // Tag Sign + "S_TTAG1", + + // Got Flag Sign + "S_GOTFLAG1", + "S_GOTFLAG2", + "S_GOTFLAG3", + "S_GOTFLAG4", + + // Red Ring + "S_RRNG1", + "S_RRNG2", + "S_RRNG3", + "S_RRNG4", + "S_RRNG5", + "S_RRNG6", + "S_RRNG7", + + // Bounce Ring + "S_BOUNCERING1", + "S_BOUNCERING2", + "S_BOUNCERING3", + "S_BOUNCERING4", + "S_BOUNCERING5", + "S_BOUNCERING6", + "S_BOUNCERING7", + "S_BOUNCERING8", + "S_BOUNCERING9", + "S_BOUNCERING10", + "S_BOUNCERING11", + "S_BOUNCERING12", + "S_BOUNCERING13", + "S_BOUNCERING14", + "S_BOUNCERING15", + "S_BOUNCERING16", + "S_BOUNCERING17", + "S_BOUNCERING18", + "S_BOUNCERING19", + "S_BOUNCERING20", + "S_BOUNCERING21", + "S_BOUNCERING22", + "S_BOUNCERING23", + "S_BOUNCERING24", + "S_BOUNCERING25", + "S_BOUNCERING26", + "S_BOUNCERING27", + "S_BOUNCERING28", + "S_BOUNCERING29", + "S_BOUNCERING30", + "S_BOUNCERING31", + "S_BOUNCERING32", + "S_BOUNCERING33", + "S_BOUNCERING34", + "S_BOUNCERING35", + + // Rail Ring + "S_RAILRING1", + "S_RAILRING2", + "S_RAILRING3", + "S_RAILRING4", + "S_RAILRING5", + "S_RAILRING6", + "S_RAILRING7", + "S_RAILRING8", + "S_RAILRING9", + "S_RAILRING10", + "S_RAILRING11", + "S_RAILRING12", + "S_RAILRING13", + "S_RAILRING14", + "S_RAILRING15", + "S_RAILRING16", + "S_RAILRING17", + "S_RAILRING18", + "S_RAILRING19", + "S_RAILRING20", + "S_RAILRING21", + "S_RAILRING22", + "S_RAILRING23", + "S_RAILRING24", + "S_RAILRING25", + "S_RAILRING26", + "S_RAILRING27", + "S_RAILRING28", + "S_RAILRING29", + "S_RAILRING30", + "S_RAILRING31", + "S_RAILRING32", + "S_RAILRING33", + "S_RAILRING34", + "S_RAILRING35", + + // Infinity ring + "S_INFINITYRING1", + "S_INFINITYRING2", + "S_INFINITYRING3", + "S_INFINITYRING4", + "S_INFINITYRING5", + "S_INFINITYRING6", + "S_INFINITYRING7", + "S_INFINITYRING8", + "S_INFINITYRING9", + "S_INFINITYRING10", + "S_INFINITYRING11", + "S_INFINITYRING12", + "S_INFINITYRING13", + "S_INFINITYRING14", + "S_INFINITYRING15", + "S_INFINITYRING16", + "S_INFINITYRING17", + "S_INFINITYRING18", + "S_INFINITYRING19", + "S_INFINITYRING20", + "S_INFINITYRING21", + "S_INFINITYRING22", + "S_INFINITYRING23", + "S_INFINITYRING24", + "S_INFINITYRING25", + "S_INFINITYRING26", + "S_INFINITYRING27", + "S_INFINITYRING28", + "S_INFINITYRING29", + "S_INFINITYRING30", + "S_INFINITYRING31", + "S_INFINITYRING32", + "S_INFINITYRING33", + "S_INFINITYRING34", + "S_INFINITYRING35", + + // Automatic Ring + "S_AUTOMATICRING1", + "S_AUTOMATICRING2", + "S_AUTOMATICRING3", + "S_AUTOMATICRING4", + "S_AUTOMATICRING5", + "S_AUTOMATICRING6", + "S_AUTOMATICRING7", + "S_AUTOMATICRING8", + "S_AUTOMATICRING9", + "S_AUTOMATICRING10", + "S_AUTOMATICRING11", + "S_AUTOMATICRING12", + "S_AUTOMATICRING13", + "S_AUTOMATICRING14", + "S_AUTOMATICRING15", + "S_AUTOMATICRING16", + "S_AUTOMATICRING17", + "S_AUTOMATICRING18", + "S_AUTOMATICRING19", + "S_AUTOMATICRING20", + "S_AUTOMATICRING21", + "S_AUTOMATICRING22", + "S_AUTOMATICRING23", + "S_AUTOMATICRING24", + "S_AUTOMATICRING25", + "S_AUTOMATICRING26", + "S_AUTOMATICRING27", + "S_AUTOMATICRING28", + "S_AUTOMATICRING29", + "S_AUTOMATICRING30", + "S_AUTOMATICRING31", + "S_AUTOMATICRING32", + "S_AUTOMATICRING33", + "S_AUTOMATICRING34", + "S_AUTOMATICRING35", + + // Explosion Ring + "S_EXPLOSIONRING1", + "S_EXPLOSIONRING2", + "S_EXPLOSIONRING3", + "S_EXPLOSIONRING4", + "S_EXPLOSIONRING5", + "S_EXPLOSIONRING6", + "S_EXPLOSIONRING7", + "S_EXPLOSIONRING8", + "S_EXPLOSIONRING9", + "S_EXPLOSIONRING10", + "S_EXPLOSIONRING11", + "S_EXPLOSIONRING12", + "S_EXPLOSIONRING13", + "S_EXPLOSIONRING14", + "S_EXPLOSIONRING15", + "S_EXPLOSIONRING16", + "S_EXPLOSIONRING17", + "S_EXPLOSIONRING18", + "S_EXPLOSIONRING19", + "S_EXPLOSIONRING20", + "S_EXPLOSIONRING21", + "S_EXPLOSIONRING22", + "S_EXPLOSIONRING23", + "S_EXPLOSIONRING24", + "S_EXPLOSIONRING25", + "S_EXPLOSIONRING26", + "S_EXPLOSIONRING27", + "S_EXPLOSIONRING28", + "S_EXPLOSIONRING29", + "S_EXPLOSIONRING30", + "S_EXPLOSIONRING31", + "S_EXPLOSIONRING32", + "S_EXPLOSIONRING33", + "S_EXPLOSIONRING34", + "S_EXPLOSIONRING35", + + // Scatter Ring + "S_SCATTERRING1", + "S_SCATTERRING2", + "S_SCATTERRING3", + "S_SCATTERRING4", + "S_SCATTERRING5", + "S_SCATTERRING6", + "S_SCATTERRING7", + "S_SCATTERRING8", + "S_SCATTERRING9", + "S_SCATTERRING10", + "S_SCATTERRING11", + "S_SCATTERRING12", + "S_SCATTERRING13", + "S_SCATTERRING14", + "S_SCATTERRING15", + "S_SCATTERRING16", + "S_SCATTERRING17", + "S_SCATTERRING18", + "S_SCATTERRING19", + "S_SCATTERRING20", + "S_SCATTERRING21", + "S_SCATTERRING22", + "S_SCATTERRING23", + "S_SCATTERRING24", + "S_SCATTERRING25", + "S_SCATTERRING26", + "S_SCATTERRING27", + "S_SCATTERRING28", + "S_SCATTERRING29", + "S_SCATTERRING30", + "S_SCATTERRING31", + "S_SCATTERRING32", + "S_SCATTERRING33", + "S_SCATTERRING34", + "S_SCATTERRING35", + + // Grenade Ring + "S_GRENADERING1", + "S_GRENADERING2", + "S_GRENADERING3", + "S_GRENADERING4", + "S_GRENADERING5", + "S_GRENADERING6", + "S_GRENADERING7", + "S_GRENADERING8", + "S_GRENADERING9", + "S_GRENADERING10", + "S_GRENADERING11", + "S_GRENADERING12", + "S_GRENADERING13", + "S_GRENADERING14", + "S_GRENADERING15", + "S_GRENADERING16", + "S_GRENADERING17", + "S_GRENADERING18", + "S_GRENADERING19", + "S_GRENADERING20", + "S_GRENADERING21", + "S_GRENADERING22", + "S_GRENADERING23", + "S_GRENADERING24", + "S_GRENADERING25", + "S_GRENADERING26", + "S_GRENADERING27", + "S_GRENADERING28", + "S_GRENADERING29", + "S_GRENADERING30", + "S_GRENADERING31", + "S_GRENADERING32", + "S_GRENADERING33", + "S_GRENADERING34", + "S_GRENADERING35", + + // Weapon pickup + "S_BOUNCEPICKUP1", + "S_BOUNCEPICKUP2", + "S_BOUNCEPICKUP3", + "S_BOUNCEPICKUP4", + "S_BOUNCEPICKUP5", + "S_BOUNCEPICKUP6", + "S_BOUNCEPICKUP7", + "S_BOUNCEPICKUP8", + "S_BOUNCEPICKUP9", + "S_BOUNCEPICKUP10", + "S_BOUNCEPICKUP11", + "S_BOUNCEPICKUP12", + "S_BOUNCEPICKUP13", + "S_BOUNCEPICKUP14", + "S_BOUNCEPICKUP15", + "S_BOUNCEPICKUP16", + + "S_BOUNCEPICKUPFADE1", + "S_BOUNCEPICKUPFADE2", + "S_BOUNCEPICKUPFADE3", + "S_BOUNCEPICKUPFADE4", + "S_BOUNCEPICKUPFADE5", + "S_BOUNCEPICKUPFADE6", + "S_BOUNCEPICKUPFADE7", + "S_BOUNCEPICKUPFADE8", + + "S_RAILPICKUP1", + "S_RAILPICKUP2", + "S_RAILPICKUP3", + "S_RAILPICKUP4", + "S_RAILPICKUP5", + "S_RAILPICKUP6", + "S_RAILPICKUP7", + "S_RAILPICKUP8", + "S_RAILPICKUP9", + "S_RAILPICKUP10", + "S_RAILPICKUP11", + "S_RAILPICKUP12", + "S_RAILPICKUP13", + "S_RAILPICKUP14", + "S_RAILPICKUP15", + "S_RAILPICKUP16", + + "S_RAILPICKUPFADE1", + "S_RAILPICKUPFADE2", + "S_RAILPICKUPFADE3", + "S_RAILPICKUPFADE4", + "S_RAILPICKUPFADE5", + "S_RAILPICKUPFADE6", + "S_RAILPICKUPFADE7", + "S_RAILPICKUPFADE8", + + "S_AUTOPICKUP1", + "S_AUTOPICKUP2", + "S_AUTOPICKUP3", + "S_AUTOPICKUP4", + "S_AUTOPICKUP5", + "S_AUTOPICKUP6", + "S_AUTOPICKUP7", + "S_AUTOPICKUP8", + "S_AUTOPICKUP9", + "S_AUTOPICKUP10", + "S_AUTOPICKUP11", + "S_AUTOPICKUP12", + "S_AUTOPICKUP13", + "S_AUTOPICKUP14", + "S_AUTOPICKUP15", + "S_AUTOPICKUP16", + + "S_AUTOPICKUPFADE1", + "S_AUTOPICKUPFADE2", + "S_AUTOPICKUPFADE3", + "S_AUTOPICKUPFADE4", + "S_AUTOPICKUPFADE5", + "S_AUTOPICKUPFADE6", + "S_AUTOPICKUPFADE7", + "S_AUTOPICKUPFADE8", + + "S_EXPLODEPICKUP1", + "S_EXPLODEPICKUP2", + "S_EXPLODEPICKUP3", + "S_EXPLODEPICKUP4", + "S_EXPLODEPICKUP5", + "S_EXPLODEPICKUP6", + "S_EXPLODEPICKUP7", + "S_EXPLODEPICKUP8", + "S_EXPLODEPICKUP9", + "S_EXPLODEPICKUP10", + "S_EXPLODEPICKUP11", + "S_EXPLODEPICKUP12", + "S_EXPLODEPICKUP13", + "S_EXPLODEPICKUP14", + "S_EXPLODEPICKUP15", + "S_EXPLODEPICKUP16", + + "S_EXPLODEPICKUPFADE1", + "S_EXPLODEPICKUPFADE2", + "S_EXPLODEPICKUPFADE3", + "S_EXPLODEPICKUPFADE4", + "S_EXPLODEPICKUPFADE5", + "S_EXPLODEPICKUPFADE6", + "S_EXPLODEPICKUPFADE7", + "S_EXPLODEPICKUPFADE8", + + "S_SCATTERPICKUP1", + "S_SCATTERPICKUP2", + "S_SCATTERPICKUP3", + "S_SCATTERPICKUP4", + "S_SCATTERPICKUP5", + "S_SCATTERPICKUP6", + "S_SCATTERPICKUP7", + "S_SCATTERPICKUP8", + "S_SCATTERPICKUP9", + "S_SCATTERPICKUP10", + "S_SCATTERPICKUP11", + "S_SCATTERPICKUP12", + "S_SCATTERPICKUP13", + "S_SCATTERPICKUP14", + "S_SCATTERPICKUP15", + "S_SCATTERPICKUP16", + + "S_SCATTERPICKUPFADE1", + "S_SCATTERPICKUPFADE2", + "S_SCATTERPICKUPFADE3", + "S_SCATTERPICKUPFADE4", + "S_SCATTERPICKUPFADE5", + "S_SCATTERPICKUPFADE6", + "S_SCATTERPICKUPFADE7", + "S_SCATTERPICKUPFADE8", + + "S_GRENADEPICKUP1", + "S_GRENADEPICKUP2", + "S_GRENADEPICKUP3", + "S_GRENADEPICKUP4", + "S_GRENADEPICKUP5", + "S_GRENADEPICKUP6", + "S_GRENADEPICKUP7", + "S_GRENADEPICKUP8", + "S_GRENADEPICKUP9", + "S_GRENADEPICKUP10", + "S_GRENADEPICKUP11", + "S_GRENADEPICKUP12", + "S_GRENADEPICKUP13", + "S_GRENADEPICKUP14", + "S_GRENADEPICKUP15", + "S_GRENADEPICKUP16", + + "S_GRENADEPICKUPFADE1", + "S_GRENADEPICKUPFADE2", + "S_GRENADEPICKUPFADE3", + "S_GRENADEPICKUPFADE4", + "S_GRENADEPICKUPFADE5", + "S_GRENADEPICKUPFADE6", + "S_GRENADEPICKUPFADE7", + "S_GRENADEPICKUPFADE8", + + // Thrown Weapon Rings + "S_THROWNBOUNCE1", + "S_THROWNBOUNCE2", + "S_THROWNBOUNCE3", + "S_THROWNBOUNCE4", + "S_THROWNBOUNCE5", + "S_THROWNBOUNCE6", + "S_THROWNBOUNCE7", + "S_THROWNINFINITY1", + "S_THROWNINFINITY2", + "S_THROWNINFINITY3", + "S_THROWNINFINITY4", + "S_THROWNINFINITY5", + "S_THROWNINFINITY6", + "S_THROWNINFINITY7", + "S_THROWNAUTOMATIC1", + "S_THROWNAUTOMATIC2", + "S_THROWNAUTOMATIC3", + "S_THROWNAUTOMATIC4", + "S_THROWNAUTOMATIC5", + "S_THROWNAUTOMATIC6", + "S_THROWNAUTOMATIC7", + "S_THROWNEXPLOSION1", + "S_THROWNEXPLOSION2", + "S_THROWNEXPLOSION3", + "S_THROWNEXPLOSION4", + "S_THROWNEXPLOSION5", + "S_THROWNEXPLOSION6", + "S_THROWNEXPLOSION7", + "S_THROWNGRENADE1", + "S_THROWNGRENADE2", + "S_THROWNGRENADE3", + "S_THROWNGRENADE4", + "S_THROWNGRENADE5", + "S_THROWNGRENADE6", + "S_THROWNGRENADE7", + "S_THROWNGRENADE8", + "S_THROWNGRENADE9", + "S_THROWNGRENADE10", + "S_THROWNGRENADE11", + "S_THROWNGRENADE12", + "S_THROWNGRENADE13", + "S_THROWNGRENADE14", + "S_THROWNGRENADE15", + "S_THROWNGRENADE16", + "S_THROWNGRENADE17", + "S_THROWNGRENADE18", + "S_THROWNSCATTER", + + "S_RINGEXPLODE", + + "S_COIN1", + "S_COIN2", + "S_COIN3", + "S_COINSPARKLE1", + "S_COINSPARKLE2", + "S_COINSPARKLE3", + "S_COINSPARKLE4", + "S_GOOMBA1", + "S_GOOMBA1B", + "S_GOOMBA2", + "S_GOOMBA3", + "S_GOOMBA4", + "S_GOOMBA5", + "S_GOOMBA6", + "S_GOOMBA7", + "S_GOOMBA8", + "S_GOOMBA9", + "S_GOOMBA_DEAD", + "S_BLUEGOOMBA1", + "S_BLUEGOOMBA1B", + "S_BLUEGOOMBA2", + "S_BLUEGOOMBA3", + "S_BLUEGOOMBA4", + "S_BLUEGOOMBA5", + "S_BLUEGOOMBA6", + "S_BLUEGOOMBA7", + "S_BLUEGOOMBA8", + "S_BLUEGOOMBA9", + "S_BLUEGOOMBA_DEAD", + + // Mario-specific stuff + "S_FIREFLOWER1", + "S_FIREFLOWER2", + "S_FIREFLOWER3", + "S_FIREFLOWER4", + "S_FIREBALL1", + "S_FIREBALL2", + "S_FIREBALL3", + "S_FIREBALL4", + "S_FIREBALLEXP1", + "S_FIREBALLEXP2", + "S_FIREBALLEXP3", + "S_SHELL", + "S_SHELL1", + "S_SHELL2", + "S_SHELL3", + "S_SHELL4", + "S_PUMA1", + "S_PUMA2", + "S_PUMA3", + "S_PUMA4", + "S_PUMA5", + "S_PUMA6", + "S_HAMMER1", + "S_HAMMER2", + "S_HAMMER3", + "S_HAMMER4", + "S_KOOPA1", + "S_KOOPA2", + "S_KOOPAFLAME1", + "S_KOOPAFLAME2", + "S_KOOPAFLAME3", + "S_AXE1", + "S_AXE2", + "S_AXE3", + "S_MARIOBUSH1", + "S_MARIOBUSH2", + "S_TOAD", + + // Nights-specific stuff + "S_NIGHTSDRONE1", + "S_NIGHTSDRONE2", + "S_NIGHTSDRONE_SPARKLING1", + "S_NIGHTSDRONE_SPARKLING2", + "S_NIGHTSDRONE_SPARKLING3", + "S_NIGHTSDRONE_SPARKLING4", + "S_NIGHTSDRONE_SPARKLING5", + "S_NIGHTSDRONE_SPARKLING6", + "S_NIGHTSDRONE_SPARKLING7", + "S_NIGHTSDRONE_SPARKLING8", + "S_NIGHTSDRONE_SPARKLING9", + "S_NIGHTSDRONE_SPARKLING10", + "S_NIGHTSDRONE_SPARKLING11", + "S_NIGHTSDRONE_SPARKLING12", + "S_NIGHTSDRONE_SPARKLING13", + "S_NIGHTSDRONE_SPARKLING14", + "S_NIGHTSDRONE_SPARKLING15", + "S_NIGHTSDRONE_SPARKLING16", + "S_NIGHTSGOAL1", + "S_NIGHTSGOAL2", + "S_NIGHTSGOAL3", + "S_NIGHTSGOAL4", + + "S_NIGHTSFLY1A", + "S_NIGHTSFLY1B", + "S_NIGHTSDRILL1A", + "S_NIGHTSDRILL1B", + "S_NIGHTSDRILL1C", + "S_NIGHTSDRILL1D", + "S_NIGHTSFLY2A", + "S_NIGHTSFLY2B", + "S_NIGHTSDRILL2A", + "S_NIGHTSDRILL2B", + "S_NIGHTSDRILL2C", + "S_NIGHTSDRILL2D", + "S_NIGHTSFLY3A", + "S_NIGHTSFLY3B", + "S_NIGHTSDRILL3A", + "S_NIGHTSDRILL3B", + "S_NIGHTSDRILL3C", + "S_NIGHTSDRILL3D", + "S_NIGHTSFLY4A", + "S_NIGHTSFLY4B", + "S_NIGHTSDRILL4A", + "S_NIGHTSDRILL4B", + "S_NIGHTSDRILL4C", + "S_NIGHTSDRILL4D", + "S_NIGHTSFLY5A", + "S_NIGHTSFLY5B", + "S_NIGHTSDRILL5A", + "S_NIGHTSDRILL5B", + "S_NIGHTSDRILL5C", + "S_NIGHTSDRILL5D", + "S_NIGHTSFLY6A", + "S_NIGHTSFLY6B", + "S_NIGHTSDRILL6A", + "S_NIGHTSDRILL6B", + "S_NIGHTSDRILL6C", + "S_NIGHTSDRILL6D", + "S_NIGHTSFLY7A", + "S_NIGHTSFLY7B", + "S_NIGHTSDRILL7A", + "S_NIGHTSDRILL7B", + "S_NIGHTSDRILL7C", + "S_NIGHTSDRILL7D", + "S_NIGHTSFLY8A", + "S_NIGHTSFLY8B", + "S_NIGHTSDRILL8A", + "S_NIGHTSDRILL8B", + "S_NIGHTSDRILL8C", + "S_NIGHTSDRILL8D", + "S_NIGHTSFLY9A", + "S_NIGHTSFLY9B", + "S_NIGHTSDRILL9A", + "S_NIGHTSDRILL9B", + "S_NIGHTSDRILL9C", + "S_NIGHTSDRILL9D", + "S_NIGHTSHURT1", + "S_NIGHTSHURT2", + "S_NIGHTSHURT3", + "S_NIGHTSHURT4", + "S_NIGHTSHURT5", + "S_NIGHTSHURT6", + "S_NIGHTSHURT7", + "S_NIGHTSHURT8", + "S_NIGHTSHURT9", + "S_NIGHTSHURT10", + "S_NIGHTSHURT11", + "S_NIGHTSHURT12", + "S_NIGHTSHURT13", + "S_NIGHTSHURT14", + "S_NIGHTSHURT15", + "S_NIGHTSHURT16", + "S_NIGHTSHURT17", + "S_NIGHTSHURT18", + "S_NIGHTSHURT19", + "S_NIGHTSHURT20", + "S_NIGHTSHURT21", + "S_NIGHTSHURT22", + "S_NIGHTSHURT23", + "S_NIGHTSHURT24", + "S_NIGHTSHURT25", + "S_NIGHTSHURT26", + "S_NIGHTSHURT27", + "S_NIGHTSHURT28", + "S_NIGHTSHURT29", + "S_NIGHTSHURT30", + "S_NIGHTSHURT31", + "S_NIGHTSHURT32", + + "S_NIGHTSPARKLE1", + "S_NIGHTSPARKLE2", + "S_NIGHTSPARKLE3", + "S_NIGHTSPARKLE4", + "S_NIGHTSPARKLESUPER1", + "S_NIGHTSPARKLESUPER2", + "S_NIGHTSPARKLESUPER3", + "S_NIGHTSPARKLESUPER4", + "S_NIGHTSLOOPHELPER", + + // NiGHTS bumper + "S_NIGHTSBUMPER1", + "S_NIGHTSBUMPER2", + "S_NIGHTSBUMPER3", + "S_NIGHTSBUMPER4", + "S_NIGHTSBUMPER5", + "S_NIGHTSBUMPER6", + "S_NIGHTSBUMPER7", + "S_NIGHTSBUMPER8", + "S_NIGHTSBUMPER9", + "S_NIGHTSBUMPER10", + "S_NIGHTSBUMPER11", + "S_NIGHTSBUMPER12", + + "S_HOOP", + "S_HOOP_XMASA", + "S_HOOP_XMASB", + + "S_NIGHTSCORE10", + "S_NIGHTSCORE20", + "S_NIGHTSCORE30", + "S_NIGHTSCORE40", + "S_NIGHTSCORE50", + "S_NIGHTSCORE60", + "S_NIGHTSCORE70", + "S_NIGHTSCORE80", + "S_NIGHTSCORE90", + "S_NIGHTSCORE100", + "S_NIGHTSCORE10_2", + "S_NIGHTSCORE20_2", + "S_NIGHTSCORE30_2", + "S_NIGHTSCORE40_2", + "S_NIGHTSCORE50_2", + "S_NIGHTSCORE60_2", + "S_NIGHTSCORE70_2", + "S_NIGHTSCORE80_2", + "S_NIGHTSCORE90_2", + "S_NIGHTSCORE100_2", + + "S_NIGHTSWING", + "S_NIGHTSWING_XMAS", + + // NiGHTS Paraloop Powerups + "S_NIGHTSPOWERUP1", + "S_NIGHTSPOWERUP2", + "S_NIGHTSPOWERUP3", + "S_NIGHTSPOWERUP4", + "S_NIGHTSPOWERUP5", + "S_NIGHTSPOWERUP6", + "S_NIGHTSPOWERUP7", + "S_NIGHTSPOWERUP8", + "S_NIGHTSPOWERUP9", + "S_NIGHTSPOWERUP10", + "S_EGGCAPSULE", + + // Orbiting Chaos Emeralds + "S_ORBITEM1", + "S_ORBITEM2", + "S_ORBITEM3", + "S_ORBITEM4", + "S_ORBITEM5", + "S_ORBITEM6", + "S_ORBITEM7", + + // "Flicky" helper + "S_NIGHTOPIANHELPER1", + "S_NIGHTOPIANHELPER2", + "S_NIGHTOPIANHELPER3", + "S_NIGHTOPIANHELPER4", + "S_NIGHTOPIANHELPER5", + "S_NIGHTOPIANHELPER6", + "S_NIGHTOPIANHELPER7", + "S_NIGHTOPIANHELPER8", + + "S_CRUMBLE1", + "S_CRUMBLE2", + + "S_SUPERTRANS1", + "S_SUPERTRANS2", + "S_SUPERTRANS3", + "S_SUPERTRANS4", + "S_SUPERTRANS5", + "S_SUPERTRANS6", + "S_SUPERTRANS7", + "S_SUPERTRANS8", + "S_SUPERTRANS9", + + // Spark + "S_SPRK1", + "S_SPRK2", + "S_SPRK3", + "S_SPRK4", + "S_SPRK5", + "S_SPRK6", + "S_SPRK7", + "S_SPRK8", + "S_SPRK9", + "S_SPRK10", + "S_SPRK11", + "S_SPRK12", + "S_SPRK13", + "S_SPRK14", + "S_SPRK15", + "S_SPRK16", + + // Robot Explosion + "S_XPLD1", + "S_XPLD2", + "S_XPLD3", + "S_XPLD4", + + // Underwater Explosion + "S_WPLD1", + "S_WPLD2", + "S_WPLD3", + "S_WPLD4", + "S_WPLD5", + "S_WPLD6", + + "S_ROCKSPAWN", + + "S_ROCKCRUMBLEA1", + "S_ROCKCRUMBLEA2", + "S_ROCKCRUMBLEA3", + "S_ROCKCRUMBLEA4", + "S_ROCKCRUMBLEA5", + + "S_ROCKCRUMBLEB1", + "S_ROCKCRUMBLEB2", + "S_ROCKCRUMBLEB3", + "S_ROCKCRUMBLEB4", + "S_ROCKCRUMBLEB5", + + "S_ROCKCRUMBLEC1", + "S_ROCKCRUMBLEC2", + "S_ROCKCRUMBLEC3", + "S_ROCKCRUMBLEC4", + "S_ROCKCRUMBLEC5", + + "S_ROCKCRUMBLED1", + "S_ROCKCRUMBLED2", + "S_ROCKCRUMBLED3", + "S_ROCKCRUMBLED4", + "S_ROCKCRUMBLED5", + + "S_ROCKCRUMBLEE1", + "S_ROCKCRUMBLEE2", + "S_ROCKCRUMBLEE3", + "S_ROCKCRUMBLEE4", + "S_ROCKCRUMBLEE5", + + "S_ROCKCRUMBLEF1", + "S_ROCKCRUMBLEF2", + "S_ROCKCRUMBLEF3", + "S_ROCKCRUMBLEF4", + "S_ROCKCRUMBLEF5", + + "S_ROCKCRUMBLEG1", + "S_ROCKCRUMBLEG2", + "S_ROCKCRUMBLEG3", + "S_ROCKCRUMBLEG4", + "S_ROCKCRUMBLEG5", + + "S_ROCKCRUMBLEH1", + "S_ROCKCRUMBLEH2", + "S_ROCKCRUMBLEH3", + "S_ROCKCRUMBLEH4", + "S_ROCKCRUMBLEH5", + + "S_ROCKCRUMBLEI1", + "S_ROCKCRUMBLEI2", + "S_ROCKCRUMBLEI3", + "S_ROCKCRUMBLEI4", + "S_ROCKCRUMBLEI5", + + "S_ROCKCRUMBLEJ1", + "S_ROCKCRUMBLEJ2", + "S_ROCKCRUMBLEJ3", + "S_ROCKCRUMBLEJ4", + "S_ROCKCRUMBLEJ5", + + "S_ROCKCRUMBLEK1", + "S_ROCKCRUMBLEK2", + "S_ROCKCRUMBLEK3", + "S_ROCKCRUMBLEK4", + "S_ROCKCRUMBLEK5", + + "S_ROCKCRUMBLEL1", + "S_ROCKCRUMBLEL2", + "S_ROCKCRUMBLEL3", + "S_ROCKCRUMBLEL4", + "S_ROCKCRUMBLEL5", + + "S_ROCKCRUMBLEM1", + "S_ROCKCRUMBLEM2", + "S_ROCKCRUMBLEM3", + "S_ROCKCRUMBLEM4", + "S_ROCKCRUMBLEM5", + + "S_ROCKCRUMBLEN1", + "S_ROCKCRUMBLEN2", + "S_ROCKCRUMBLEN3", + "S_ROCKCRUMBLEN4", + "S_ROCKCRUMBLEN5", + + "S_ROCKCRUMBLEO1", + "S_ROCKCRUMBLEO2", + "S_ROCKCRUMBLEO3", + "S_ROCKCRUMBLEO4", + "S_ROCKCRUMBLEO5", + + "S_ROCKCRUMBLEP1", + "S_ROCKCRUMBLEP2", + "S_ROCKCRUMBLEP3", + "S_ROCKCRUMBLEP4", + "S_ROCKCRUMBLEP5", + + "S_SRB1_CRAWLA1", + "S_SRB1_CRAWLA2", + "S_SRB1_CRAWLA3", + "S_SRB1_CRAWLA4", + + "S_SRB1_BAT1", + "S_SRB1_BAT2", + "S_SRB1_BAT3", + "S_SRB1_BAT4", + + "S_SRB1_ROBOFISH1", + "S_SRB1_ROBOFISH2", + "S_SRB1_ROBOFISH3", + + "S_SRB1_VOLCANOGUY1", + "S_SRB1_VOLCANOGUY2", + + "S_SRB1_HOPPY1", + "S_SRB1_HOPPY2", + + "S_SRB1_HOPPYWATER1", + "S_SRB1_HOPPYWATER2", + + "S_SRB1_HOPPYSKYLAB1", + + "S_SRB1_MMZFLYING1", + "S_SRB1_MMZFLYING2", + "S_SRB1_MMZFLYING3", + "S_SRB1_MMZFLYING4", + "S_SRB1_MMZFLYING5", + + "S_SRB1_UFO1", + "S_SRB1_UFO2", + + "S_SRB1_GRAYBOT1", + "S_SRB1_GRAYBOT2", + "S_SRB1_GRAYBOT3", + "S_SRB1_GRAYBOT4", + "S_SRB1_GRAYBOT5", + "S_SRB1_GRAYBOT6", + + "S_SRB1_ROBOTOPOLIS1", + "S_SRB1_ROBOTOPOLIS2", + + "S_SRB1_RBZBUZZ1", + "S_SRB1_RBZBUZZ2", + + "S_SRB1_RBZSPIKES1", + "S_SRB1_RBZSPIKES2", + + "S_SRB1_METALSONIC1", + "S_SRB1_METALSONIC2", + "S_SRB1_METALSONIC3", + + "S_SRB1_GOLDBOT1", + "S_SRB1_GOLDBOT2", + "S_SRB1_GOLDBOT3", + "S_SRB1_GOLDBOT4", + "S_SRB1_GOLDBOT5", + "S_SRB1_GOLDBOT6", + + "S_SRB1_GENREX1", + "S_SRB1_GENREX2", + +#ifdef SEENAMES + "S_NAMECHECK", +#endif +}; + +// RegEx to generate this from info.h: ^\tMT_([^,]+), --> \t"MT_\1", +// I am leaving the prefixes solely for clarity to programmers, +// because sadly no one remembers this place while searching for full state names. +static const char *const MOBJTYPE_LIST[] = { // array length left dynamic for sanity testing later. + "MT_NULL", + "MT_UNKNOWN", + + "MT_THOK", // Thok! mobj + "MT_PLAYER", + + // Enemies + "MT_BLUECRAWLA", + "MT_REDCRAWLA", + "MT_GFZFISH", // Greenflower Fish + "MT_GOLDBUZZ", + "MT_REDBUZZ", + "MT_AQUABUZZ", + "MT_JETTBOMBER", // Jetty-Syn Bomber + "MT_JETTGUNNER", // Jetty-Syn Gunner + "MT_CRAWLACOMMANDER", // Crawla Commander + "MT_DETON", // Deton + "MT_SKIM", // Skim mine dropper + "MT_TURRET", + "MT_POPUPTURRET", + "MT_SHARP", // Sharp + "MT_JETJAW", // Jet Jaw + "MT_SNAILER", // Snailer + "MT_VULTURE", // Vulture + "MT_POINTY", // Pointy + "MT_POINTYBALL", // Pointy Ball + "MT_ROBOHOOD", // Robo-Hood + "MT_FACESTABBER", // CastleBot FaceStabber + "MT_EGGGUARD", // Egg Guard + "MT_EGGSHIELD", // Egg Shield for Egg Guard + "MT_GSNAPPER", // Green Snapper + "MT_MINUS", // Minus + "MT_SPRINGSHELL", // Spring Shell (no drop) + "MT_YELLOWSHELL", // Spring Shell (yellow) + "MT_UNIDUS", // Unidus + "MT_UNIBALL", // Unidus Ball + + // Generic Boss Items + "MT_BOSSEXPLODE", + "MT_SONIC3KBOSSEXPLODE", + "MT_BOSSFLYPOINT", + "MT_EGGTRAP", + "MT_BOSS3WAYPOINT", + "MT_BOSS9GATHERPOINT", + + // Boss 1 + "MT_EGGMOBILE", + "MT_JETFUME1", + "MT_EGGMOBILE_BALL", + "MT_EGGMOBILE_TARGET", + "MT_EGGMOBILE_FIRE", + + // Boss 2 + "MT_EGGMOBILE2", + "MT_EGGMOBILE2_POGO", + "MT_BOSSTANK1", + "MT_BOSSTANK2", + "MT_BOSSSPIGOT", + "MT_GOOP", + + // Boss 3 + "MT_EGGMOBILE3", + "MT_PROPELLER", + "MT_FAKEMOBILE", + + // Boss 4 + "MT_EGGMOBILE4", + "MT_EGGMOBILE4_MACE", + "MT_JETFLAME", + + // Black Eggman (Boss 7) + "MT_BLACKEGGMAN", + "MT_BLACKEGGMAN_HELPER", + "MT_BLACKEGGMAN_GOOPFIRE", + "MT_BLACKEGGMAN_MISSILE", + + // New Very-Last-Minute 2.1 Brak Eggman (Cy-Brak-demon) + "MT_CYBRAKDEMON", + "MT_CYBRAKDEMON_ELECTRIC_BARRIER", + "MT_CYBRAKDEMON_MISSILE", + "MT_CYBRAKDEMON_FLAMESHOT", + "MT_CYBRAKDEMON_FLAMEREST", + "MT_CYBRAKDEMON_TARGET_RETICULE", + "MT_CYBRAKDEMON_NAPALM_BOMB_LARGE", + "MT_CYBRAKDEMON_NAPALM_BOMB_SMALL", + "MT_CYBRAKDEMON_NAPALM_FLAMES", + "MT_CYBRAKDEMON_VILE_EXPLOSION", + + // Metal Sonic + "MT_METALSONIC_RACE", + "MT_METALSONIC_BATTLE", + "MT_MSSHIELD_FRONT", + "MT_MSGATHER", + + // Collectible Items + "MT_RING", + "MT_FLINGRING", // Lost ring +#ifdef BLUE_SPHERES + "MT_BLUEBALL", // Blue sphere replacement for special stages +#endif + "MT_REDTEAMRING", //Rings collectable by red team. + "MT_BLUETEAMRING", //Rings collectable by blue team. + "MT_EMMY", // emerald token for special stage + "MT_TOKEN", // Special Stage Token (uncollectible part) + "MT_REDFLAG", // Red CTF Flag + "MT_BLUEFLAG", // Blue CTF Flag + "MT_EMBLEM", + "MT_EMERALD1", + "MT_EMERALD2", + "MT_EMERALD3", + "MT_EMERALD4", + "MT_EMERALD5", + "MT_EMERALD6", + "MT_EMERALD7", + "MT_EMERHUNT", // Emerald Hunt + "MT_EMERALDSPAWN", // Emerald spawner w/ delay + "MT_FLINGEMERALD", // Lost emerald + + // Springs and others + "MT_FAN", + "MT_STEAM", // Steam riser + "MT_BLUESPRING", + "MT_YELLOWSPRING", + "MT_REDSPRING", + "MT_YELLOWDIAG", // Yellow Diagonal Spring + "MT_REDDIAG", // Red Diagonal Spring + + // Interactive Objects + "MT_BUBBLES", // Bubble source + "MT_SIGN", // Level end sign + "MT_SPIKEBALL", // Spike Ball + "MT_SPECIALSPIKEBALL", + "MT_SPINFIRE", + "MT_SPIKE", + "MT_STARPOST", + "MT_BIGMINE", + "MT_BIGAIRMINE", + "MT_CANNONLAUNCHER", + + // Monitor Boxes + "MT_SUPERRINGBOX", + "MT_REDRINGBOX", + "MT_BLUERINGBOX", + "MT_SNEAKERTV", + "MT_INV", + "MT_PRUP", // 1up Box + "MT_YELLOWTV", // Attract shield TV + "MT_BLUETV", // Force shield TV + "MT_BLACKTV", // Bomb shield TV + "MT_WHITETV", // Jump shield TV + "MT_GREENTV", // Elemental shield TV + "MT_PITYTV", // Pity shield TV + "MT_EGGMANBOX", + "MT_MIXUPBOX", + "MT_RECYCLETV", + "MT_RECYCLEICO", + "MT_QUESTIONBOX", + "MT_GRAVITYBOX", + "MT_SCORETVSMALL", + "MT_SCORETVLARGE", + + // Monitor miscellany + "MT_MONITOREXPLOSION", + "MT_REDMONITOREXPLOSION", + "MT_BLUEMONITOREXPLOSION", + "MT_RINGICO", + "MT_SHOESICO", + "MT_INVCICO", + "MT_1UPICO", + "MT_YSHIELDICO", + "MT_BSHIELDICO", + "MT_KSHIELDICO", + "MT_WSHIELDICO", + "MT_GSHIELDICO", + "MT_PITYSHIELDICO", + "MT_EGGMANICO", + "MT_MIXUPICO", + "MT_GRAVITYICO", + "MT_SCOREICOSMALL", + "MT_SCOREICOLARGE", + + // Projectiles + "MT_ROCKET", + "MT_LASER", + "MT_TORPEDO", + "MT_TORPEDO2", // silent + "MT_ENERGYBALL", + "MT_MINE", // Skim/Jetty-Syn mine + "MT_JETTBULLET", // Jetty-Syn Bullet + "MT_TURRETLASER", + "MT_CANNONBALL", // Cannonball + "MT_CANNONBALLDECOR", // Decorative/still cannonball + "MT_ARROW", // Arrow + "MT_DEMONFIRE", // Trapgoyle fire + + // Greenflower Scenery + "MT_GFZFLOWER1", + "MT_GFZFLOWER2", + "MT_GFZFLOWER3", + "MT_BERRYBUSH", + "MT_BUSH", + + // Techno Hill Scenery + "MT_THZPLANT", // THZ Plant + "MT_ALARM", + + // Deep Sea Scenery + "MT_GARGOYLE", // Deep Sea Gargoyle + "MT_SEAWEED", // DSZ Seaweed + "MT_WATERDRIP", // Dripping Water source + "MT_WATERDROP", // Water drop from dripping water + "MT_CORAL1", // Coral 1 + "MT_CORAL2", // Coral 2 + "MT_CORAL3", // Coral 3 + "MT_BLUECRYSTAL", // Blue Crystal + + // Castle Eggman Scenery + "MT_CHAIN", // CEZ Chain + "MT_FLAME", // Flame (has corona) + "MT_EGGSTATUE", // Eggman Statue + "MT_MACEPOINT", // Mace rotation point + "MT_SWINGMACEPOINT", // Mace swinging point + "MT_HANGMACEPOINT", // Hangable mace chain + "MT_SPINMACEPOINT", // Spin/Controllable mace chain + "MT_HIDDEN_SLING", // Spin mace chain (activatable) + "MT_SMALLMACECHAIN", // Small Mace Chain + "MT_BIGMACECHAIN", // Big Mace Chain + "MT_SMALLMACE", // Small Mace + "MT_BIGMACE", // Big Mace + "MT_CEZFLOWER", + + // Arid Canyon Scenery + "MT_BIGTUMBLEWEED", + "MT_LITTLETUMBLEWEED", + "MT_CACTI1", + "MT_CACTI2", + "MT_CACTI3", + "MT_CACTI4", + + // Red Volcano Scenery + "MT_FLAMEJET", + "MT_VERTICALFLAMEJET", + "MT_FLAMEJETFLAME", + + "MT_FJSPINAXISA", // Counter-clockwise + "MT_FJSPINHELPERA", + "MT_FJSPINAXISB", // Clockwise + "MT_FJSPINHELPERB", + + "MT_FLAMEJETFLAMEB", // Blade's flame + + // Dark City Scenery + + // Egg Rock Scenery + + // Azure Temple Scenery + "MT_TRAPGOYLE", + "MT_TRAPGOYLEUP", + "MT_TRAPGOYLEDOWN", + "MT_TRAPGOYLELONG", + "MT_TARGET", + + // Stalagmites + "MT_STALAGMITE0", + "MT_STALAGMITE1", + "MT_STALAGMITE2", + "MT_STALAGMITE3", + "MT_STALAGMITE4", + "MT_STALAGMITE5", + "MT_STALAGMITE6", + "MT_STALAGMITE7", + "MT_STALAGMITE8", + "MT_STALAGMITE9", + + // Christmas Scenery + "MT_XMASPOLE", + "MT_CANDYCANE", + "MT_SNOWMAN", + + // Botanic Serenity + "MT_BSZTALLFLOWER_RED", + "MT_BSZTALLFLOWER_PURPLE", + "MT_BSZTALLFLOWER_BLUE", + "MT_BSZTALLFLOWER_CYAN", + "MT_BSZTALLFLOWER_YELLOW", + "MT_BSZTALLFLOWER_ORANGE", + "MT_BSZFLOWER_RED", + "MT_BSZFLOWER_PURPLE", + "MT_BSZFLOWER_BLUE", + "MT_BSZFLOWER_CYAN", + "MT_BSZFLOWER_YELLOW", + "MT_BSZFLOWER_ORANGE", + "MT_BSZSHORTFLOWER_RED", + "MT_BSZSHORTFLOWER_PURPLE", + "MT_BSZSHORTFLOWER_BLUE", + "MT_BSZSHORTFLOWER_CYAN", + "MT_BSZSHORTFLOWER_YELLOW", + "MT_BSZSHORTFLOWER_ORANGE", + "MT_BSZTULIP_RED", + "MT_BSZTULIP_PURPLE", + "MT_BSZTULIP_BLUE", + "MT_BSZTULIP_CYAN", + "MT_BSZTULIP_YELLOW", + "MT_BSZTULIP_ORANGE", + "MT_BSZCLUSTER_RED", + "MT_BSZCLUSTER_PURPLE", + "MT_BSZCLUSTER_BLUE", + "MT_BSZCLUSTER_CYAN", + "MT_BSZCLUSTER_YELLOW", + "MT_BSZCLUSTER_ORANGE", + "MT_BSZBUSH_RED", + "MT_BSZBUSH_PURPLE", + "MT_BSZBUSH_BLUE", + "MT_BSZBUSH_CYAN", + "MT_BSZBUSH_YELLOW", + "MT_BSZBUSH_ORANGE", + "MT_BSZVINE_RED", + "MT_BSZVINE_PURPLE", + "MT_BSZVINE_BLUE", + "MT_BSZVINE_CYAN", + "MT_BSZVINE_YELLOW", + "MT_BSZVINE_ORANGE", + "MT_BSZSHRUB", + "MT_BSZCLOVER", + "MT_BSZFISH", + "MT_BSZSUNFLOWER", + + // Misc scenery + "MT_DBALL", + "MT_EGGSTATUE2", + + // Powerup Indicators + "MT_GREENORB", // Elemental shield mobj + "MT_YELLOWORB", // Attract shield mobj + "MT_BLUEORB", // Force shield mobj + "MT_BLACKORB", // Armageddon shield mobj + "MT_WHITEORB", // Whirlwind shield mobj + "MT_PITYORB", // Pity shield mobj + "MT_IVSP", // invincibility sparkles + "MT_SUPERSPARK", // Super Sonic Spark + + // Freed Animals + "MT_BIRD", // Birdie freed! + "MT_BUNNY", // Bunny freed! + "MT_MOUSE", // Mouse + "MT_CHICKEN", // Chicken + "MT_COW", // Cow + "MT_REDBIRD", // Red Birdie in Bubble + + // Environmental Effects + "MT_RAIN", // Rain + "MT_SNOWFLAKE", // Snowflake + "MT_SPLISH", // Water splish! + "MT_SMOKE", + "MT_SMALLBUBBLE", // small bubble + "MT_MEDIUMBUBBLE", // medium bubble + "MT_EXTRALARGEBUBBLE", // extra large bubble + "MT_TFOG", + "MT_SEED", + "MT_PARTICLE", + "MT_PARTICLEGEN", // For fans, etc. + + // Game Indicators + "MT_SCORE", // score logo + "MT_DROWNNUMBERS", // Drowning Timer + "MT_GOTEMERALD", // Chaos Emerald (intangible) + "MT_TAG", // Tag Sign + "MT_GOTFLAG", // Got Flag sign + "MT_GOTFLAG2", // Got Flag sign + + // Ambient Sounds + "MT_AWATERA", // Ambient Water Sound 1 + "MT_AWATERB", // Ambient Water Sound 2 + "MT_AWATERC", // Ambient Water Sound 3 + "MT_AWATERD", // Ambient Water Sound 4 + "MT_AWATERE", // Ambient Water Sound 5 + "MT_AWATERF", // Ambient Water Sound 6 + "MT_AWATERG", // Ambient Water Sound 7 + "MT_AWATERH", // Ambient Water Sound 8 + "MT_RANDOMAMBIENT", + "MT_RANDOMAMBIENT2", + + // Ring Weapons + "MT_REDRING", + "MT_BOUNCERING", + "MT_RAILRING", + "MT_INFINITYRING", + "MT_AUTOMATICRING", + "MT_EXPLOSIONRING", + "MT_SCATTERRING", + "MT_GRENADERING", + + "MT_BOUNCEPICKUP", + "MT_RAILPICKUP", + "MT_AUTOPICKUP", + "MT_EXPLODEPICKUP", + "MT_SCATTERPICKUP", + "MT_GRENADEPICKUP", + + "MT_THROWNBOUNCE", + "MT_THROWNINFINITY", + "MT_THROWNAUTOMATIC", + "MT_THROWNSCATTER", + "MT_THROWNEXPLOSION", + "MT_THROWNGRENADE", + + // Mario-specific stuff + "MT_COIN", + "MT_FLINGCOIN", + "MT_GOOMBA", + "MT_BLUEGOOMBA", + "MT_FIREFLOWER", + "MT_FIREBALL", + "MT_SHELL", + "MT_PUMA", + "MT_HAMMER", + "MT_KOOPA", + "MT_KOOPAFLAME", + "MT_AXE", + "MT_MARIOBUSH1", + "MT_MARIOBUSH2", + "MT_TOAD", + + // NiGHTS Stuff + "MT_AXIS", + "MT_AXISTRANSFER", + "MT_AXISTRANSFERLINE", + "MT_NIGHTSDRONE", + "MT_NIGHTSGOAL", + "MT_NIGHTSCHAR", + "MT_NIGHTSPARKLE", + "MT_NIGHTSLOOPHELPER", + "MT_NIGHTSBUMPER", // NiGHTS Bumper + "MT_HOOP", + "MT_HOOPCOLLIDE", // Collision detection for NiGHTS hoops + "MT_HOOPCENTER", // Center of a hoop + "MT_NIGHTSCORE", + "MT_NIGHTSWING", + "MT_NIGHTSSUPERLOOP", + "MT_NIGHTSDRILLREFILL", + "MT_NIGHTSHELPER", + "MT_NIGHTSEXTRATIME", + "MT_NIGHTSLINKFREEZE", + "MT_EGGCAPSULE", + "MT_NIGHTOPIANHELPER", // the actual helper object that orbits you + + // Utility Objects + "MT_CHAOSSPAWNER", + "MT_TELEPORTMAN", + "MT_ALTVIEWMAN", + "MT_CRUMBLEOBJ", // Sound generator for crumbling platform + "MT_TUBEWAYPOINT", + "MT_PUSH", + "MT_PULL", + "MT_GHOST", + "MT_OVERLAY", + "MT_POLYANCHOR", + "MT_POLYSPAWN", + "MT_POLYSPAWNCRUSH", + + // Skybox objects + "MT_SKYBOX", + + // Debris + "MT_SPARK", //spark + "MT_EXPLODE", // Robot Explosion + "MT_UWEXPLODE", // Underwater Explosion + "MT_ROCKSPAWNER", + "MT_FALLINGROCK", + "MT_ROCKCRUMBLE1", + "MT_ROCKCRUMBLE2", + "MT_ROCKCRUMBLE3", + "MT_ROCKCRUMBLE4", + "MT_ROCKCRUMBLE5", + "MT_ROCKCRUMBLE6", + "MT_ROCKCRUMBLE7", + "MT_ROCKCRUMBLE8", + "MT_ROCKCRUMBLE9", + "MT_ROCKCRUMBLE10", + "MT_ROCKCRUMBLE11", + "MT_ROCKCRUMBLE12", + "MT_ROCKCRUMBLE13", + "MT_ROCKCRUMBLE14", + "MT_ROCKCRUMBLE15", + "MT_ROCKCRUMBLE16", + + "MT_SRB1_CRAWLA", + "MT_SRB1_BAT", + "MT_SRB1_ROBOFISH", + "MT_SRB1_VOLCANOGUY", + "MT_SRB1_HOPPY", + "MT_SRB1_HOPPYWATER", + "MT_SRB1_HOPPYSKYLAB", + "MT_SRB1_MMZFLYING", + "MT_SRB1_UFO", + "MT_SRB1_GRAYBOT", + "MT_SRB1_ROBOTOPOLIS", + "MT_SRB1_RBZBUZZ", + "MT_SRB1_RBZSPIKES", + "MT_SRB1_METALSONIC", + "MT_SRB1_GOLDBOT", + "MT_SRB1_GENREX", +#ifdef SEENAMES + "MT_NAMECHECK", +#endif +}; + +static const char *const MOBJFLAG_LIST[] = { + "SPECIAL", + "SOLID", + "SHOOTABLE", + "NOSECTOR", + "NOBLOCKMAP", + "AMBUSH", + "PUSHABLE", + "BOSS", + "SPAWNCEILING", + "NOGRAVITY", + "AMBIENT", + "SLIDEME", + "NOCLIP", + "FLOAT", + "BOXICON", + "MISSILE", + "SPRING", + "BOUNCE", + "MONITOR", + "NOTHINK", + "FIRE", + "NOCLIPHEIGHT", + "ENEMY", + "SCENERY", + "PAIN", + "STICKY", + "NIGHTSITEM", + "NOCLIPTHING", + "RUNSPAWNFUNC", + NULL +}; + +// \tMF2_(\S+).*// (.+) --> \t"\1", // \2 +static const char *const MOBJFLAG2_LIST[] = { + "AXIS", // It's a NiGHTS axis! (For faster checking) + "TWOD", // Moves like it's in a 2D level + "DONTRESPAWN", // Don't respawn this object! + "DONTDRAW", // Don't generate a vissprite + "AUTOMATIC", // Thrown ring has automatic properties + "RAILRING", // Thrown ring has rail properties + "BOUNCERING", // Thrown ring has bounce properties + "EXPLOSION", // Thrown ring has explosive properties + "SCATTER", // Thrown ring has scatter properties + "BEYONDTHEGRAVE",// Source of this missile has died and has since respawned. + "PUSHED", // Mobj was already pushed this tic + "SLIDEPUSH", // MF_PUSHABLE that pushes continuously. + "CLASSICPUSH", // Drops straight down when object has negative Z. + "STANDONME", // While not pushable, stand on me anyway. + "INFLOAT", // Floating to a height for a move, don't auto float to target's height. + "DEBRIS", // Splash ring from explosion ring + "NIGHTSPULL", // Attracted from a paraloop + "JUSTATTACKED", // can be pushed by other moving mobjs + "FIRING", // turret fire + "SUPERFIRE", // Firing something with Super Sonic-stopping properties. Or, if mobj has MF_MISSILE, this is the actual fire from it. + "SHADOW", // Fuzzy draw, makes targeting harder. + "STRONGBOX", // Flag used for "strong" random monitors. + "OBJECTFLIP", // Flag for objects that always have flipped gravity. + "SKULLFLY", // Special handling: skull in flight. + "FRET", // Flashing from a previous hit + "BOSSNOTRAP", // No Egg Trap after boss + "BOSSFLEE", // Boss is fleeing! + "BOSSDEAD", // Boss is dead! (Not necessarily fleeing, if a fleeing point doesn't exist.) + NULL +}; + +static const char *const MOBJEFLAG_LIST[] = { + "ONGROUND", // The mobj stands on solid floor (not on another mobj or in air) + "JUSTHITFLOOR", // The mobj just hit the floor while falling, this is cleared on next frame + "TOUCHWATER", // The mobj stands in a sector with water, and touches the surface + "UNDERWATER", // The mobj stands in a sector with water, and his waist is BELOW the water surface + "JUSTSTEPPEDDOWN", // used for ramp sectors + "VERTICALFLIP", // Vertically flip sprite/allow upside-down physics + "GOOWATER", // Goo water + NULL +}; + +static const char *const MAPTHINGFLAG_LIST[16] = { + NULL, + "OBJECTFLIP", // Reverse gravity flag for objects. + "OBJECTSPECIAL", // Special flag used with certain objects. + "AMBUSH", // Deaf monsters/do not react to sound. + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL +}; + +static const char *const PLAYERFLAG_LIST[] = { + // Flip camera angle with gravity flip prefrence. + "FLIPCAM", + + // Cheats + "GODMODE", + "NOCLIP", + "INVIS", + + // True if button down last tic. + "ATTACKDOWN", + "USEDOWN", + "JUMPDOWN", + "WPNDOWN", + + // Unmoving states + "STASIS", // Player is not allowed to move + "JUMPSTASIS", // and that includes jumping. + // (we don't include FULLSTASIS here I guess because it's just those two together...?) + + // Did you get a time-over? + "TIMEOVER", + + // Ready for Super? + "SUPERREADY", + + // Character action status + "JUMPED", + "SPINNING", + "STARTDASH", + "THOKKED", + + // Are you gliding? + "GLIDING", + + // Tails pickup! + "CARRIED", + + // Sliding (usually in water) like Labyrinth/Oil Ocean + "SLIDING", + + // Hanging on a rope + "ROPEHANG", + + // Hanging on an item of some kind - zipline, chain, etc. (->tracer) + "ITEMHANG", + + // On the mace chain spinning around (->tracer) + "MACESPIN", + + /*** NIGHTS STUFF ***/ + // Is the player in NiGHTS mode? + "NIGHTSMODE", + "TRANSFERTOCLOSEST", + + // Spill rings after falling + "NIGHTSFALL", + "DRILLING", + "SKIDDOWN", + + /*** TAG STUFF ***/ + "TAGGED", // Player has been tagged and awaits the next round in hide and seek. + "TAGIT", // The player is it! For Tag Mode + + NULL // stop loop here. +}; + +// Linedef flags +static const char *const ML_LIST[16] = { + "IMPASSIBLE", + "BLOCKMONSTERS", + "TWOSIDED", + "DONTPEGTOP", + "DONTPEGBOTTOM", + "EFFECT1", + "NOCLIMB", + "EFFECT2", + "EFFECT3", + "EFFECT4", + "EFFECT5", + "NOSONIC", + "NOTAILS", + "NOKNUX", + "BOUNCY", + "TFERLINE" +}; + +// This DOES differ from r_draw's Color_Names, unfortunately. +static const char *COLOR_ENUMS[] = { + "NONE", // SKINCOLOR_NONE + "WHITE", // SKINCOLOR_WHITE + "SILVER", // SKINCOLOR_SILVER + "GREY", // SKINCOLOR_GREY + "BLACK", // SKINCOLOR_BLACK + "CYAN", // SKINCOLOR_CYAN + "TEAL", // SKINCOLOR_TEAL + "STEELBLUE", // SKINCOLOR_STEELBLUE + "BLUE", // SKINCOLOR_BLUE + "PEACH", // SKINCOLOR_PEACH + "TAN", // SKINCOLOR_TAN + "PINK", // SKINCOLOR_PINK + "LAVENDER", // SKINCOLOR_LAVENDER + "PURPLE", // SKINCOLOR_PURPLE + "ORANGE", // SKINCOLOR_ORANGE + "ROSEWOOD", // SKINCOLOR_ROSEWOOD + "BEIGE", // SKINCOLOR_BEIGE + "BROWN", // SKINCOLOR_BROWN + "RED", // SKINCOLOR_RED + "DARKRED", // SKINCOLOR_DARKRED + "NEONGREEN", // SKINCOLOR_NEONGREEN + "GREEN", // SKINCOLOR_GREEN + "ZIM", // SKINCOLOR_ZIM + "OLIVE", // SKINCOLOR_OLIVE + "YELLOW", // SKINCOLOR_YELLOW + "GOLD" // SKINCOLOR_GOLD +}; + +static const char *const POWERS_LIST[] = { + "INVULNERABILITY", + "SNEAKERS", + "FLASHING", + "SHIELD", + "TAILSFLY", // tails flying + "UNDERWATER", // underwater timer + "SPACETIME", // In space, no one can hear you spin! + "EXTRALIFE", // Extra Life timer + + "SUPER", // Are you super? + "GRAVITYBOOTS", // gravity boots + + // Weapon ammunition + "INFINITYRING", + "BOUNCERING", + "RAILRING", + "AUTOMATICRING", + "EXPLOSIONRING", + "SCATTERRING", + "GRENADERING", + + // Power Stones + "EMERALDS", // stored like global 'emeralds' variable + + // NiGHTS powerups + "NIGHTS_SUPERLOOP", + "NIGHTS_HELPER", + "NIGHTS_LINKFREEZE", + + //for linedef exec 427 + "NOCONTROL", + "INGOOP" // In goop +}; + +static const char *const HUDITEMS_LIST[] = { + "LIVESNAME", + "LIVESPIC", + "LIVESNUM", + "LIVESX", + "RINGSSPLIT", + "RINGSNUMSPLIT", + "RINGS", + "RINGSNUM", + "SCORE", + "SCORENUM", + "TIMESPLIT", + "SECONDSSPLIT", + "MINUTESSPLIT", + "TIMECOLONSPLIT", + "TIME", + "TICS", + "SECONDS", + "MINUTES", + "TIMECOLON", + "TIMETICCOLON", + "SS_TOTALRINGS_SPLIT", + "SS_TOTALRINGS", + "GETRINGS", + "GETRINGSNUM", + "TIMELEFT", + "TIMELEFTNUM", + "TIMEUP", + "HUNTPICS", + "GRAVBOOTSICO", + "LAP" +}; + +struct { + const char *n; + // has to be able to hold both fixed_t and angle_t, so drastic measure!! +#ifdef HAVE_BLUA + lua_Integer v; +#else + INT64 v; +#endif +} const INT_CONST[] = { + // If a mod removes some variables here, + // please leave the names in-tact and just set + // the value to 0 or something. + + // integer type limits, from doomtype.h + // INT64 and UINT64 limits not included, they're too big for most purposes anyway + // signed + {"INT8_MIN",INT8_MIN}, + {"INT16_MIN",INT16_MIN}, + {"INT32_MIN",INT32_MIN}, + {"INT8_MAX",INT8_MAX}, + {"INT16_MAX",INT16_MAX}, + {"INT32_MAX",INT32_MAX}, + // unsigned + {"UINT8_MAX",UINT8_MAX}, + {"UINT16_MAX",UINT16_MAX}, + {"UINT32_MAX",UINT32_MAX}, + + // fixed_t constants, from m_fixed.h + {"FRACUNIT",FRACUNIT}, + {"FRACBITS",FRACBITS}, + + // doomdef.h constants + {"TICRATE",TICRATE}, + {"RING_DIST",RING_DIST}, + {"PUSHACCEL",PUSHACCEL}, + {"MODID",MODID}, // I don't know, I just thought it would be cool for a wad to potentially know what mod it was loaded into. + {"CODEBASE",CODEBASE}, // or what release of SRB2 this is. + + // Special linedef executor tag numbers! + {"LE_PINCHPHASE",LE_PINCHPHASE}, // A boss entered pinch phase (and, in most cases, is preparing their pinch phase attack!) + {"LE_ALLBOSSESDEAD",LE_ALLBOSSESDEAD}, // All bosses in the map are dead (Egg capsule raise) + {"LE_BOSSDEAD",LE_BOSSDEAD}, // A boss in the map died (Chaos mode boss tally) + {"LE_BOSS4DROP",LE_BOSS4DROP}, // CEZ boss dropped its cage + {"LE_BRAKVILEATACK",LE_BRAKVILEATACK}, // Brak's doing his LOS attack, oh noes + + /// \todo Get all this stuff into its own sections, maybe. Maybe. + + // Frame settings + {"FF_FRAMEMASK",FF_FRAMEMASK}, + {"FF_FULLBRIGHT",FF_FULLBRIGHT}, + {"FF_TRANSMASK",FF_TRANSMASK}, + {"FF_TRANSSHIFT",FF_TRANSSHIFT}, + // Transparency for SOCs is pre-shifted + {"TR_TRANS10",tr_trans10<gotflag! + // Used to be MF_ for some stupid reason, now they're GF_ to stop them looking like mobjflags + {"GF_REDFLAG",GF_REDFLAG}, + {"GF_BLUEFLAG",GF_BLUEFLAG}, + + // Angles + {"ANG1",ANG1}, + {"ANG2",ANG2}, + {"ANG10",ANG10}, + {"ANG15",ANG15}, + {"ANG20",ANG20}, + {"ANG30",ANG30}, + {"ANG60",ANG60}, + {"ANG64h",ANG64h}, + {"ANG105",ANG105}, + {"ANG210",ANG210}, + {"ANG255",ANG255}, + {"ANG340",ANG340}, + {"ANG350",ANG350}, + {"ANGLE_11hh",ANGLE_11hh}, + {"ANGLE_22h",ANGLE_22h}, + {"ANGLE_45",ANGLE_45}, + {"ANGLE_67h",ANGLE_67h}, + {"ANGLE_90",ANGLE_90}, + {"ANGLE_112h",ANGLE_112h}, + {"ANGLE_135",ANGLE_135}, + {"ANGLE_157h",ANGLE_157h}, + {"ANGLE_180",ANGLE_180}, + {"ANGLE_202h",ANGLE_202h}, + {"ANGLE_225",ANGLE_225}, + {"ANGLE_247h",ANGLE_247h}, + {"ANGLE_270",ANGLE_270}, + {"ANGLE_292h",ANGLE_292h}, + {"ANGLE_315",ANGLE_315}, + {"ANGLE_337h",ANGLE_337h}, + {"ANGLE_MAX",ANGLE_MAX}, + + // P_Chase directions (dirtype_t) + {"DI_NODIR",DI_NODIR}, + {"DI_EAST",DI_EAST}, + {"DI_NORTHEAST",DI_NORTHEAST}, + {"DI_NORTH",DI_NORTH}, + {"DI_NORTHWEST",DI_NORTHWEST}, + {"DI_WEST",DI_WEST}, + {"DI_SOUTHWEST",DI_SOUTHWEST}, + {"DI_SOUTH",DI_SOUTH}, + {"DI_SOUTHEAST",DI_SOUTHEAST}, + {"NUMDIRS",NUMDIRS}, + + // Buttons (ticcmd_t) + {"BT_WEAPONMASK",BT_WEAPONMASK}, //our first four bits. + {"BT_WEAPONNEXT",BT_WEAPONNEXT}, + {"BT_WEAPONPREV",BT_WEAPONPREV}, + {"BT_ATTACK",BT_ATTACK}, // shoot rings + {"BT_USE",BT_USE}, // spin + {"BT_CAMLEFT",BT_CAMLEFT}, // turn camera left + {"BT_CAMRIGHT",BT_CAMRIGHT}, // turn camera right + {"BT_TOSSFLAG",BT_TOSSFLAG}, + {"BT_JUMP",BT_JUMP}, + {"BT_FIRENORMAL",BT_FIRENORMAL}, // Fire a normal ring no matter what + + // cvflags_t + {"CV_SAVE",CV_SAVE}, + {"CV_CALL",CV_CALL}, + {"CV_NETVAR",CV_NETVAR}, + {"CV_NOINIT",CV_NOINIT}, + {"CV_FLOAT",CV_FLOAT}, + {"CV_NOTINNET",CV_NOTINNET}, + {"CV_MODIFIED",CV_MODIFIED}, + {"CV_SHOWMODIF",CV_SHOWMODIF}, + {"CV_SHOWMODIFONETIME",CV_SHOWMODIFONETIME}, + {"CV_NOSHOWHELP",CV_NOSHOWHELP}, + {"CV_HIDEN",CV_HIDEN}, + {"CV_HIDDEN",CV_HIDEN}, + {"CV_CHEAT",CV_CHEAT}, + + // v_video flags + {"V_NOSCALEPATCH",V_NOSCALEPATCH}, + {"V_SMALLSCALEPATCH",V_SMALLSCALEPATCH}, + {"V_MEDSCALEPATCH",V_MEDSCALEPATCH}, + {"V_6WIDTHSPACE",V_6WIDTHSPACE}, + {"V_OLDSPACING",V_OLDSPACING}, + {"V_MONOSPACE",V_MONOSPACE}, + {"V_PURPLEMAP",V_PURPLEMAP}, + {"V_YELLOWMAP",V_YELLOWMAP}, + {"V_GREENMAP",V_GREENMAP}, + {"V_BLUEMAP",V_BLUEMAP}, + {"V_REDMAP",V_REDMAP}, + {"V_GRAYMAP",V_GRAYMAP}, + {"V_ORANGEMAP",V_ORANGEMAP}, + {"V_TRANSLUCENT",V_TRANSLUCENT}, + {"V_10TRANS",V_10TRANS}, + {"V_20TRANS",V_20TRANS}, + {"V_30TRANS",V_30TRANS}, + {"V_40TRANS",V_40TRANS}, + {"V_50TRANS",V_TRANSLUCENT}, // alias + {"V_60TRANS",V_60TRANS}, + {"V_70TRANS",V_70TRANS}, + {"V_80TRANS",V_80TRANS}, + {"V_90TRANS",V_90TRANS}, + {"V_AUTOFADEOUT",V_AUTOFADEOUT}, + {"V_RETURN8",V_RETURN8}, + {"V_OFFSET",V_OFFSET}, + {"V_ALLOWLOWERCASE",V_ALLOWLOWERCASE}, + {"V_FLIP",V_FLIP}, + {"V_SNAPTOTOP",V_SNAPTOTOP}, + {"V_SNAPTOBOTTOM",V_SNAPTOBOTTOM}, + {"V_SNAPTOLEFT",V_SNAPTOLEFT}, + {"V_SNAPTORIGHT",V_SNAPTORIGHT}, + {"V_WRAPX",V_WRAPX}, + {"V_WRAPY",V_WRAPY}, + {"V_NOSCALESTART",V_NOSCALESTART}, + {"V_SPLITSCREEN",V_SPLITSCREEN}, + + {"V_PARAMMASK",V_PARAMMASK}, + {"V_SCALEPATCHMASK",V_SCALEPATCHMASK}, + {"V_SPACINGMASK",V_SPACINGMASK}, + {"V_CHARCOLORMASK",V_CHARCOLORMASK}, + {"V_ALPHAMASK",V_ALPHAMASK}, + + {"V_CHARCOLORSHIFT",V_CHARCOLORSHIFT}, + {"V_ALPHASHIFT",V_ALPHASHIFT}, +#endif + + {NULL,0} +}; + +static mobjtype_t get_mobjtype(const char *word) +{ // Returns the vlaue of MT_ enumerations + mobjtype_t i; + if (*word >= '0' && *word <= '9') + return atoi(word); + if (fastncmp("MT_",word,3)) + word += 3; // take off the MT_ + for (i = 0; i < NUMMOBJFREESLOTS; i++) { + if (!FREE_MOBJS[i]) + break; + if (fastcmp(word, FREE_MOBJS[i])) + return MT_FIRSTFREESLOT+i; + } + for (i = 0; i < MT_FIRSTFREESLOT; i++) + if (fastcmp(word, MOBJTYPE_LIST[i]+3)) + return i; + deh_warning("Couldn't find mobjtype named 'MT_%s'",word); + return MT_BLUECRAWLA; +} + +static statenum_t get_state(const char *word) +{ // Returns the value of S_ enumerations + statenum_t i; + if (*word >= '0' && *word <= '9') + return atoi(word); + if (fastncmp("S_",word,2)) + word += 2; // take off the S_ + for (i = 0; i < NUMSTATEFREESLOTS; i++) { + if (!FREE_STATES[i]) + break; + if (fastcmp(word, FREE_STATES[i])) + return S_FIRSTFREESLOT+i; + } + for (i = 0; i < S_FIRSTFREESLOT; i++) + if (fastcmp(word, STATE_LIST[i]+2)) + return i; + deh_warning("Couldn't find state named 'S_%s'",word); + return S_NULL; +} + +static spritenum_t get_sprite(const char *word) +{ // Returns the value of SPR_ enumerations + spritenum_t i; + if (*word >= '0' && *word <= '9') + return atoi(word); + if (fastncmp("SPR_",word,4)) + word += 4; // take off the SPR_ + for (i = 0; i < NUMSPRITES; i++) + if (!sprnames[i][4] && memcmp(word,sprnames[i],4)==0) + return i; + deh_warning("Couldn't find sprite named 'SPR_%s'",word); + return SPR_NULL; +} + +static sfxenum_t get_sfx(const char *word) +{ // Returns the value of SFX_ enumerations + sfxenum_t i; + if (*word >= '0' && *word <= '9') + return atoi(word); + if (fastncmp("SFX_",word,4)) + word += 4; // take off the SFX_ + else if (fastncmp("DS",word,2)) + word += 2; // take off the DS + for (i = 0; i < NUMSFX; i++) + if (S_sfx[i].name && fasticmp(word, S_sfx[i].name)) + return i; + deh_warning("Couldn't find sfx named 'SFX_%s'",word); + return sfx_None; +} + +static UINT16 get_mus(const char *word) +{ // Returns the value of SFX_ enumerations + UINT16 i; + if (*word >= '0' && *word <= '9') + return atoi(word); + if (fastncmp("MUS_",word,4)) + word += 4; // take off the MUS_ + else if (fastncmp("O_",word,2) || fastncmp("D_",word,2)) + word += 2; // take off the O_ or D_ + for (i = 0; i < NUMMUSIC; i++) + if (S_music[i].name && fasticmp(word, S_music[i].name)) + return i; + deh_warning("Couldn't find music named 'MUS_%s'",word); + return mus_None; +} + +static hudnum_t get_huditem(const char *word) +{ // Returns the value of HUD_ enumerations + hudnum_t i; + if (*word >= '0' && *word <= '9') + return atoi(word); + if (fastncmp("HUD_",word,4)) + word += 4; // take off the HUD_ + for (i = 0; i < NUMHUDITEMS; i++) + if (fastcmp(word, HUDITEMS_LIST[i])) + return i; + deh_warning("Couldn't find huditem named 'HUD_%s'",word); + return HUD_LIVESNAME; +} + +#ifndef HAVE_BLUA +static powertype_t get_power(const char *word) +{ // Returns the vlaue of pw_ enumerations + powertype_t i; + if (*word >= '0' && *word <= '9') + return atoi(word); + if (fastncmp("PW_",word,3)) + word += 3; // take off the pw_ + for (i = 0; i < NUMPOWERS; i++) + if (fastcmp(word, POWERS_LIST[i])) + return i; + deh_warning("Couldn't find power named 'pw_%s'",word); + return pw_invulnerability; +} + +/// \todo Make ANY of this completely over-the-top math craziness obey the order of operations. +static fixed_t op_mul(fixed_t a, fixed_t b) { return a*b; } +static fixed_t op_div(fixed_t a, fixed_t b) { return a/b; } +static fixed_t op_add(fixed_t a, fixed_t b) { return a+b; } +static fixed_t op_sub(fixed_t a, fixed_t b) { return a-b; } +static fixed_t op_or(fixed_t a, fixed_t b) { return a|b; } +static fixed_t op_and(fixed_t a, fixed_t b) { return a&b; } +static fixed_t op_lshift(fixed_t a, fixed_t b) { return a<>b; } + +struct { + const char c; + fixed_t (*v)(fixed_t,fixed_t); +} OPERATIONS[] = { + {'*',op_mul}, + {'/',op_div}, + {'+',op_add}, + {'-',op_sub}, + {'|',op_or}, + {'&',op_and}, + {'<',op_lshift}, + {'>',op_rshift}, + {0,NULL} +}; + +// Returns the full word, cut at the first symbol or whitespace +static char *read_word(const char *line) +{ + // Part 1: You got the start of the word, now find the end. + const char *p; + INT32 i; + for (p = line+1; *p; p++) { + if (*p == ' ' || *p == '\t') + break; + for (i = 0; OPERATIONS[i].c; i++) + if (*p == OPERATIONS[i].c) { + i = -1; + break; + } + if (i == -1) + break; + } + + // Part 2: Make a copy of the word and return it. + { + size_t len = (p-line); + char *word = malloc(len+1); + M_Memcpy(word,line,len); + word[len] = '\0'; + return word; + } +} + +static INT32 operation_pad(const char **word) +{ // Brings word the next operation and returns the operation number. + INT32 i; + for (; **word; (*word)++) { + if (**word == ' ' || **word == '\t') + continue; + for (i = 0; OPERATIONS[i].c; i++) + if (**word == OPERATIONS[i].c) + { + if ((**word == '<' && *(*word+1) == '<') || (**word == '>' && *(*word+1) == '>')) (*word)++; // These operations are two characters long. + else if (**word == '<' || **word == '>') continue; // ... do not accept one character long. + (*word)++; + return i; + } + deh_warning("Unknown operation '%c'",**word); + return -1; + } + return -1; +} + +static void const_warning(const char *type, const char *word) +{ + deh_warning("Couldn't find %s named '%s'",type,word); +} + +static fixed_t find_const(const char **rword) +{ // Finds the value of constants and returns it, bringing word to the next operation. + INT32 i; + fixed_t r; + char *word = read_word(*rword); + *rword += strlen(word); + if ((*word >= '0' && *word <= '9') || *word == '-') { // Parse a number + r = atoi(word); + free(word); + return r; + } + if (*word >= 'A' && !*(word+1)) { // Turn a single A-z symbol into numbers, like sprite frames. + r = *word-'A'; + free(word); + return r; + } + if (fastncmp("MF_", word, 3)) { + char *p = word+3; + for (i = 0; MOBJFLAG_LIST[i]; i++) + if (fastcmp(p, MOBJFLAG_LIST[i])) { + free(word); + return (1< 0) + { + s = Z_StrDup(luaL_checkstring(L,1)); + type = strtok(s, "_"); + if (type) + strupr(type); + else { + Z_Free(s); + return luaL_error(L, "Unknown enum type in '%s'\n", luaL_checkstring(L, 1)); + } + + word = strtok(NULL, "\n"); + if (word) + strupr(word); + else { + Z_Free(s); + return luaL_error(L, "Missing enum name in '%s'\n", luaL_checkstring(L, 1)); + } + if (fastcmp(type, "SFX")) { + sfxenum_t sfx; + strlwr(word); + CONS_Printf("Sound sfx_%s allocated.\n",word); + sfx = S_AddSoundFx(word, false, -1, false); + if (sfx != sfx_None) { + lua_pushinteger(L, sfx); + r++; + } else + return r; + } + else if (fastcmp(type, "SPR")) + { + char wad; + spritenum_t j; + lua_getfield(L, LUA_REGISTRYINDEX, "WAD"); + wad = (char)lua_tointeger(L, -1); + lua_pop(L, 1); + for (j = SPR_FIRSTFREESLOT; j <= SPR_LASTFREESLOT; j++) + { + if (used_spr[(j-SPR_FIRSTFREESLOT)/8] & (1<<(j%8))) + { + if (!sprnames[j][4] && memcmp(sprnames[j],word,4)==0) + sprnames[j][4] = wad; + continue; // Already allocated, next. + } + // Found a free slot! + CONS_Printf("Sprite SPR_%s allocated.\n",word); + strncpy(sprnames[j],word,4); + //sprnames[j][4] = 0; + used_spr[(j-SPR_FIRSTFREESLOT)/8] |= 1<<(j%8); // Okay, this sprite slot has been named now. + lua_pushinteger(L, j); + r++; + break; + } + if (j > SPR_LASTFREESLOT) + return r; + } + else if (fastcmp(type, "S")) + { + statenum_t i; + for (i = 0; i < NUMSTATEFREESLOTS; i++) + if (!FREE_STATES[i]) { + CONS_Printf("State S_%s allocated.\n",word); + FREE_STATES[i] = Z_Malloc(strlen(word)+1, PU_STATIC, NULL); + strcpy(FREE_STATES[i],word); + lua_pushinteger(L, i); + r++; + break; + } + if (i == NUMSTATEFREESLOTS) + return r; + } + else if (fastcmp(type, "MT")) + { + mobjtype_t i; + for (i = 0; i < NUMMOBJFREESLOTS; i++) + if (!FREE_MOBJS[i]) { + CONS_Printf("MobjType MT_%s allocated.\n",word); + FREE_MOBJS[i] = Z_Malloc(strlen(word)+1, PU_STATIC, NULL); + strcpy(FREE_MOBJS[i],word); + lua_pushinteger(L, i); + r++; + break; + } + if (i == NUMMOBJFREESLOTS) + return r; + } + Z_Free(s); + lua_remove(L, 1); + continue; + } + return r; +} + +// Wrapper for ALL A_Action functions. +// Upvalue: actionf_t to represent +// Arguments: mobj_t actor, int var1, int var2 +static inline int lib_action(lua_State *L) +{ + actionf_t *action = lua_touserdata(L,lua_upvalueindex(1)); + mobj_t **actor = luaL_checkudata(L,1,META_MOBJ); + var1 = (INT32)luaL_optinteger(L,2,0); + var2 = (INT32)luaL_optinteger(L,3,0); + if (!*actor) + return LUA_ErrInvalid(L, "mobj_t"); + action->acp1(*actor); + return 0; +} + +// Hardcoded A_Action name to call for super() or NULL if super() would be invalid. +// Set in lua_infolib. +const char *superactions[MAXRECURSION]; +UINT8 superstack = 0; + +static int lib_dummysuper(lua_State *L) +{ + return luaL_error(L, "Can't call super() outside of hardcode-replacing A_Action functions being called by state changes!"); // convoluted, I know. @_@;; +} + +static inline int lib_getenum(lua_State *L) +{ + const char *word, *p; + fixed_t i; + boolean mathlib = lua_toboolean(L, lua_upvalueindex(1)); + if (lua_type(L,2) != LUA_TSTRING) + return 0; + word = lua_tostring(L,2); + if (strlen(word) == 1) { // Assume sprite frame if length 1. + if (*word >= 'A' && *word <= '~') + { + lua_pushinteger(L, *word-'A'); + return 1; + } + if (mathlib) return luaL_error(L, "constant '%s' could not be parsed.\n", word); + return 0; + } + else if (fastncmp("MF_", word, 3)) { + p = word+3; + for (i = 0; MOBJFLAG_LIST[i]; i++) + if (fastcmp(p, MOBJFLAG_LIST[i])) { + lua_pushinteger(L, ((lua_Integer)1<acv) + return actionpointers[z].name; + } + return NULL; +} + +void LUA_SetActionByName(void *state, const char *actiontocompare) +{ + state_t *st = (state_t *)state; + size_t z; + for (z = 0; actionpointers[z].name; z++) + { + if (fasticmp(actiontocompare, actionpointers[z].name)) + { + st->action = actionpointers[z].action; + st->action.acv = actionpointers[z].action.acv; // assign + st->action.acp1 = actionpointers[z].action.acp1; + return; + } + } +} + +#endif // HAVE_BLUA diff --git a/src/dehacked.h b/src/dehacked.h new file mode 100644 index 000000000..7ef376f3c --- /dev/null +++ b/src/dehacked.h @@ -0,0 +1,73 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Copyright (C) 1999-2014 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file dehacked.h +/// \brief Dehacked files. + +#ifndef __DEHACKED_H__ +#define __DEHACKED_H__ + +#include "m_fixed.h" // for get_number + +typedef enum +{ + UNDO_NONE = 0x00, + UNDO_NEWLINE = 0x01, + UNDO_SPACE = 0x02, + UNDO_CUTLINE = 0x04, + UNDO_HEADER = 0x07, + UNDO_ENDTEXT = 0x08, + UNDO_TODO = 0, + UNDO_DONE = 0, +} undotype_f; + +#ifdef DELFILE +void DEH_WriteUndoline(const char *value, const char *data, undotype_f flags); +void DEH_UnloadDehackedWad(UINT16 wad); +#else // null the undo lines +#define DEH_WriteUndoline(a,b,c) +#endif + +void DEH_LoadDehackedLump(lumpnum_t lumpnum); +void DEH_LoadDehackedLumpPwad(UINT16 wad, UINT16 lump); + +void DEH_Check(void); + +fixed_t get_number(const char *word); + +#ifdef HAVE_BLUA +boolean LUA_SetLuaAction(void *state, const char *actiontocompare); +const char *LUA_GetActionName(void *action); +void LUA_SetActionByName(void *state, const char *actiontocompare); +#endif + +extern boolean deh_loaded, modcredits; +extern char modcreditname[32]; + +#define MAXRECURSION 30 +extern const char *superactions[MAXRECURSION]; +extern UINT8 superstack; + +// If the dehacked patch does not match this version, we throw a warning +#define PATCHVERSION 210 + +#define MAXLINELEN 1024 + +// the code was first write for a file +// converted to use memory with this functions +typedef struct +{ + char *data; + char *curpos; + size_t size; + UINT16 wad; +} MYFILE; +#define myfeof(a) (a->data + a->size <= a->curpos) +char *myfgets(char *buf, size_t bufsize, MYFILE *f); +#endif diff --git a/src/djgppdos/Makefile.cfg b/src/djgppdos/Makefile.cfg new file mode 100644 index 000000000..857a7267b --- /dev/null +++ b/src/djgppdos/Makefile.cfg @@ -0,0 +1,48 @@ +# +# djgppdos/makefile.cfg for SRB2/DOS +# + +# +#now for the DOS stuff, go DOS! +# + + # options + OPTS=-DPC_DOS + WFLAGS+=-Wno-cast-qual + NOHW=1 + NOHS=1 + PNG_CFLAGS= + PNG_LDFLAGS=-lpng -lz + +ifdef WATTCP + OPTS+=-DWATTCP + NOOBJDUMP=1 +endif + +#ifdef DEBUGMODE + LIBS=-lalld +#else +# LIBS=-lalleg +#endif + +ifndef NONET +ifdef WATTCP + LIBS+=-lwatt +else + LIBS+=-lsocket +endif +endif + +ifdef RDB + LIBS+=-lgdbst -ldzcom + OPTS+=-DREMOTE_DEBUGGING +endif + + OBJS=$(OBJDIR)/i_video.o $(OBJDIR)/vid_vesa.o + + # name of the exefile +ifdef WATTCP + EXENAME?=srb2dos.exe +else + EXENAME?=srb2w16.exe +endif diff --git a/src/djgppdos/bcd.c b/src/djgppdos/bcd.c new file mode 100644 index 000000000..6a91c707f --- /dev/null +++ b/src/djgppdos/bcd.c @@ -0,0 +1,755 @@ +/* bcd.c -- Brennan's CD-ROM Audio Playing Library + by Brennan Underwood, http://brennan.home.ml.org/ */ +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef STANDALONE +#include /* for getch() */ +#endif + +#include "bcd.h" + +typedef struct { + int is_audio; + int start, end, len; +} Track; + +static int mscdex_version; +static int first_drive; +static int num_tracks; +static int lowest_track, highest_track; +static int audio_length; + +#ifdef STATIC_TRACKS +static Track tracks[99]; +#else +static Track *tracks; +#endif + +static int dos_mem_segment, dos_mem_selector = -1; + +int _status, _error, _error_code; +const char *_bcd_error = NULL; + +#define RESET_ERROR (_error = _error_code = 0) +#define ERROR_BIT (1 << 15) +#define BUSY_BIT (1 << 9) +#ifndef TRUE +#define TRUE 1 +#define FALSE 0 +#endif + +#pragma pack(1) + +/* I know 'typedef struct {} bleh' is a bad habit, but... */ +typedef struct { + unsigned char len; + unsigned char unit; + unsigned char command; + unsigned short status; + unsigned char reserved[8]; +} ATTRPACK RequestHeader; + +typedef struct { + RequestHeader request_header; + unsigned char descriptor; + unsigned long address; + unsigned short len; + unsigned short secnum; + unsigned long ptr; +} ATTRPACK IOCTLI; + +typedef struct { + unsigned char control; + unsigned char lowest; + unsigned char highest; + char total[4]; +} ATTRPACK DiskInfo; + +typedef struct { + unsigned char control; + unsigned char track_number; + char start[4]; + unsigned char info; +} ATTRPACK TrackInfo; + +typedef struct { + RequestHeader request; + unsigned char mode; + unsigned long start; + unsigned long len; +} ATTRPACK PlayRequest; + +typedef struct { + RequestHeader request; +} ATTRPACK StopRequest; + +typedef struct { + RequestHeader request; +} ATTRPACK ResumeRequest; + +typedef struct { + unsigned char control; + unsigned char input0; + unsigned char volume0; + unsigned char input1; + unsigned char volume1; + unsigned char input2; + unsigned char volume2; + unsigned char input3; + unsigned char volume3; +} ATTRPACK VolumeRequest; + +typedef struct { + unsigned char control; + unsigned char fn; +} ATTRPACK LockRequest; + +typedef struct { + unsigned char control; + unsigned char mbyte; +} ATTRPACK MediaChangedRequest; + +typedef struct { + unsigned char control; + unsigned long status; +} ATTRPACK StatusRequest; + +typedef struct { + unsigned char control; + unsigned char mode; + unsigned long loc; +} ATTRPACK PositionRequest; + +#pragma pack() + +#ifdef __cplusplus +extern "C" { +#endif + +const char *bcd_error(void) { + static char retstr[132]; + const char *errorcodes[] = { + "Write-protect violation", + "Unknown unit", + "Drive not ready", + "Unknown command", + "CRC error", + "Bad drive request structure length", + "Seek error", + "Unknown media", + "Sector not found", + "Printer out of paper: world coming to an end",/* I mean really, on a CD? */ + "Write fault", + "Read fault", + "General failure", + "Reserved", + "Reserved", + "Invalid disk change" + }; + *retstr = 0; + if (_error != 0) { + strcat(retstr, "Device error: "); + if (_error_code < 0 || _error_code > 0xf) + strcat(retstr, "Invalid error"); + else + strcat(retstr, errorcodes[_error_code]); + strcat(retstr, " "); + } + if (_bcd_error != NULL) { + if (*retstr) strcat(retstr, ", "); + strcat(retstr, "BCD error: "); + strcat(retstr, _bcd_error); + } + return retstr; +} + +/* DOS IOCTL w/ command block */ +static void bcd_ioctl(IOCTLI *ioctli, void *command, int len) { + int ioctli_len = sizeof (IOCTLI); + unsigned long command_address = dos_mem_segment << 4; + __dpmi_regs regs; + + memset(®s, 0, sizeof regs); + regs.x.es = (__tb >> 4) & 0xffff; + regs.x.ax = 0x1510; + regs.x.bx = __tb & 0xf; + regs.x.cx = first_drive; + ioctli->address = dos_mem_segment << 16; + ioctli->len = len; + dosmemput(ioctli, ioctli_len, __tb); /* put ioctl into dos area */ + dosmemput(command, len, command_address); /* and command too */ + if (__dpmi_int(0x2f, ®s) == -1) { + _bcd_error = "__dpmi_int() failed"; + return; + } + dosmemget(__tb, ioctli_len, ioctli); /* retrieve results */ + dosmemget(command_address, len, command); + _status = ioctli->request_header.status; + if (_status & ERROR_BIT) { + _error = TRUE; + _error_code = _status & 0xff; + } else { + _error = FALSE; + _error_code = 0; + } +} + +/* no command block */ +FUNCINLINE static ATTRINLINE void bcd_ioctl2(void *cmd, int len) { + __dpmi_regs regs; + memset(®s, 0, sizeof regs); + regs.x.es = (__tb >> 4) & 0xffff; + regs.x.ax = 0x1510; + regs.x.bx = __tb & 0xf; + regs.x.cx = first_drive; + dosmemput(cmd, len, __tb); /* put ioctl block in dos arena */ + if (__dpmi_int(0x2f, ®s) == -1) { + _bcd_error = "__dpmi_int() failed"; + return; + } + /* I hate to have no error capability for ioctl2 but the command block + doesn't necessarily have a status field */ + RESET_ERROR; +} + +FUNCINLINE static ATTRINLINE int red2hsg(char *r) { + return r[0] + r[1]*75 + r[2]*4500 - 150; +} + +int bcd_now_playing(void) { + int i, loc = bcd_audio_position(); + _bcd_error = NULL; + if (!bcd_audio_busy()) { + _bcd_error = "Audio not playing"; + return 0; + } + if ( +#ifndef STATIC_TRACKS + tracks == NULL && +#endif + !bcd_get_audio_info()) + return 0; + for (i = lowest_track; i <= highest_track; i++) { + if (loc >= tracks[i].start && loc <= tracks[i].end) return i; + } + /* some bizarre location? */ + _bcd_error = "Head outside of bounds"; + return 0; +} + +/* handles the setup for CD-ROM audio interface */ +int bcd_open(void) { + __dpmi_regs regs; + _bcd_error = NULL; + + /* disk I/O wouldn't work anyway if you set sizeof tb this low, but... */ + if (_go32_info_block.size_of_transfer_buffer < 4096) { + _bcd_error = "Transfer buffer too small"; + return 0; + } + + memset(®s, 0, sizeof regs); + regs.x.ax = 0x1500; + regs.x.bx = 0x0; + __dpmi_int(0x2f, ®s); + if (regs.x.bx == 0) { /* abba no longer lives */ + _bcd_error = "MSCDEX not found"; + return 0; + } + + first_drive = regs.x.cx; /* use the first drive */ + + /* check for mscdex at least 2.0 */ + memset(®s, 0, sizeof regs); + regs.x.ax = 0x150C; + __dpmi_int(0x2f, ®s); + if (regs.x.bx == 0) { + _bcd_error = "MSCDEX version < 2.0"; + return 0; + } + mscdex_version = regs.x.bx; + + /* allocate 256 bytes of dos memory for the command blocks */ + if ((dos_mem_segment = __dpmi_allocate_dos_memory(16, &dos_mem_selector))<0) { + _bcd_error = "Could not allocate 256 bytes of DOS memory"; + return 0; + } + + return mscdex_version; +} + +/* Shuts down CD-ROM audio interface */ +int bcd_close(void) { + _bcd_error = NULL; + if (dos_mem_selector != -1) { + __dpmi_free_dos_memory(dos_mem_selector); + dos_mem_selector = -1; + } +#ifndef STATIC_TRACKS + if (tracks) free(tracks); + tracks = NULL; +#endif + RESET_ERROR; + return 1; +} + +int bcd_open_door(void) { + IOCTLI ioctli; + char eject = 0; + _bcd_error = NULL; + memset(&ioctli, 0, sizeof ioctli); + ioctli.request_header.len = sizeof ioctli; + ioctli.request_header.command = 12; + ioctli.len = 1; + bcd_ioctl(&ioctli, &eject, sizeof eject); + if (_error) return 0; + return 1; +} + +int bcd_close_door(void) { + IOCTLI ioctli; + char closeit = 5; + _bcd_error = NULL; + memset(&ioctli, 0, sizeof ioctli); + ioctli.request_header.len = sizeof ioctli; + ioctli.request_header.command = 12; + ioctli.len = 1; + bcd_ioctl(&ioctli, &closeit, sizeof closeit); + if (_error) return 0; + return 1; +} + +int bcd_lock(int fn) { + IOCTLI ioctli; + LockRequest req; + _bcd_error = NULL; + memset(&ioctli, 0, sizeof ioctli); + memset(&req, 0, sizeof req); + ioctli.request_header.len = sizeof ioctli; + ioctli.request_header.command = 12; + ioctli.len = sizeof req; + req.control = 1; + req.fn = fn ? 1 : 0; + bcd_ioctl(&ioctli, &req, sizeof req); + if (_error) return 0; + return 1; +} + + +int bcd_disc_changed(void) { + IOCTLI ioctli; + MediaChangedRequest req; + _bcd_error = NULL; + memset(&ioctli, 0, sizeof ioctli); + memset(&req, 0, sizeof req); + ioctli.request_header.len = sizeof ioctli; + ioctli.request_header.command = 3; + ioctli.len = sizeof req; + req.control = 9; + bcd_ioctl(&ioctli, &req, sizeof req); + return req.mbyte; +} + +int bcd_reset(void) { + IOCTLI ioctli; + char reset = 2; + _bcd_error = NULL; + + memset(&ioctli, 0, sizeof ioctli); + ioctli.request_header.len = sizeof ioctli; + ioctli.request_header.command = 12; + ioctli.len = 1; + bcd_ioctl(&ioctli, &reset, sizeof reset); + if (_error) return 0; + return 1; +} + +int bcd_device_status(void) { + IOCTLI ioctli; + StatusRequest req; + _bcd_error = NULL; + memset(&ioctli, 0, sizeof ioctli); + memset(&req, 0, sizeof req); + ioctli.request_header.len = sizeof ioctli; // ok + ioctli.request_header.command = 3; + ioctli.len = sizeof req; + req.control = 6; + bcd_ioctl(&ioctli, &req, sizeof req); + return req.status; +} + +static inline int bcd_get_status_word(void) { + IOCTLI ioctli; + DiskInfo disk_info; + + /* get cd info as an excuse to get a look at the status word */ + memset(&disk_info, 0, sizeof disk_info); + memset(&ioctli, 0, sizeof ioctli); + + ioctli.request_header.len = 26; + ioctli.request_header.command = 3; + ioctli.len = 7; + disk_info.control = 10; + bcd_ioctl(&ioctli, &disk_info, sizeof disk_info); + return _status; +} + +int bcd_audio_busy(void) { + _bcd_error = NULL; + /* If the door is open, then the head is busy, and so the busy bit is + on. It is not, however, playing audio. */ + if (bcd_device_status() & BCD_DOOR_OPEN) + return 0; + + bcd_get_status_word(); + if (_error) return -1; + return (_status & BUSY_BIT) ? 1 : 0; +} + +int bcd_audio_position(void) { + IOCTLI ioctli; + PositionRequest req; + _bcd_error = NULL; + memset(&ioctli, 0, sizeof ioctli); + memset(&req, 0, sizeof req); + ioctli.request_header.len = sizeof ioctli; + ioctli.request_header.command = 3; + ioctli.len = sizeof req; + req.control = 1; + bcd_ioctl(&ioctli, &req, sizeof req); + return req.loc; +} + +/* Internal function to get track info */ +static inline void bcd_get_track_info(int n, Track *t) { + IOCTLI ioctli; + TrackInfo info; + + memset(&ioctli, 0, sizeof ioctli); + memset(&info, 0, sizeof info); + ioctli.request_header.len = sizeof ioctli; + ioctli.request_header.command = 3; + info.control = 11; + info.track_number = n; + bcd_ioctl(&ioctli, &info, sizeof info); + t->start = red2hsg(info.start); + if (info.info & 64) + t->is_audio = 0; + else + t->is_audio = 1; +} + +int bcd_get_audio_info(void) { + IOCTLI ioctli; + DiskInfo disk_info; + int i; + + + _bcd_error = NULL; +#ifndef STATIC_TRACKS + if (tracks) free(tracks); + tracks = NULL; +#endif + + memset(&disk_info, 0, sizeof disk_info); + memset(&ioctli, 0, sizeof ioctli); + + ioctli.request_header.len = 26; + ioctli.request_header.command = 3; + ioctli.len = 7; + disk_info.control = 10; + bcd_ioctl(&ioctli, &disk_info, sizeof disk_info); + if (_error) return 0; + + lowest_track = disk_info.lowest; + highest_track = disk_info.highest; + num_tracks = disk_info.highest - disk_info.lowest + 1; + +#ifndef STATIC_TRACKS + //tracks = calloc(num_tracks, sizeof (Track)); + /* alloc max space in order to attempt to avoid possible overrun bug */ + tracks = calloc(highest_track+1, sizeof (Track)); + if (tracks == NULL) { + _bcd_error = "Out of memory allocating tracks\n"; + return 0; + } +#endif + + /* get track starts */ + for (i = lowest_track; i <= highest_track; i++) + bcd_get_track_info(i, tracks+i); + + /* figure out track ends */ + for (i = lowest_track; i < highest_track; i++) + tracks[i].end = tracks[i+1].start-1; + audio_length = red2hsg(disk_info.total); + tracks[i].end = audio_length; + for (i = lowest_track; i <= highest_track; i++) + tracks[i].len = tracks[i].end - tracks[i].start; + + return num_tracks; +} + +int bcd_get_track_address(int trackno, int *start, int *len) { + _bcd_error = NULL; + //if (trackno >= num_tracks+1 || trackno <= 0) { + if (trackno < lowest_track || trackno > highest_track) { + _bcd_error = "Track out of range"; + *start = *len = 0; + return 0; + } + *start = tracks[trackno].start; + *len = tracks[trackno].len; + return 1; +} + +int bcd_track_is_audio(int trackno) { + //if (trackno >= num_tracks+1 || trackno <= 0) { + if (trackno < lowest_track || trackno > highest_track) { + _bcd_error = "Track out of range"; + return 0; + } + return tracks[trackno].is_audio; +} + +int bcd_set_volume(int volume) { + IOCTLI ioctli; + VolumeRequest v; + + _bcd_error = NULL; + if (volume > 255) volume = 255; + else if (volume < 0) volume = 0; + memset(&ioctli, 0, sizeof ioctli); + ioctli.request_header.len = sizeof ioctli; + ioctli.request_header.command = 12; + ioctli.len = sizeof v; + v.control = 3; + v.volume0 = volume; + v.input0 = 0; + v.volume1 = volume; + v.input1 = 1; + v.volume2 = volume; + v.input2 = 2; + v.volume3 = volume; + v.input3 = 3; + + bcd_ioctl(&ioctli, &v, sizeof v); + if (_error) return 0; + return 1; +} + +int bcd_play(int location, int frames) { + PlayRequest cmd; + memset(&cmd, 0, sizeof cmd); + + _bcd_error = NULL; + /* the following should be in user code, but it'll fail otherwise */ + if (bcd_audio_busy()) + bcd_stop(); + + cmd.request.len = sizeof cmd; + cmd.request.command = 132; + cmd.start = location; + cmd.len = frames; + bcd_ioctl2(&cmd, sizeof cmd); + if (_error) return 0; + return 1; +} + +int bcd_play_track(int trackno) { + _bcd_error = NULL; + if (!bcd_get_audio_info()) return 0; + + if (trackno < lowest_track || trackno > highest_track) { + _bcd_error = "Track out of range"; + return 0; + } + + if (! tracks[trackno].is_audio) { + _bcd_error = "Not an audio track"; + return 0; + } + + return bcd_play(tracks[trackno].start, tracks[trackno].len); +} + +int bcd_stop(void) { + StopRequest cmd; + _bcd_error = NULL; + memset(&cmd, 0, sizeof cmd); + cmd.request.len = sizeof cmd; + cmd.request.command = 133; + bcd_ioctl2(&cmd, sizeof cmd); + if (_error) return 0; + return 1; +} + +int bcd_resume(void) { + ResumeRequest cmd; + _bcd_error = NULL; + memset(&cmd, 0, sizeof cmd); + cmd.request.len = sizeof cmd; + cmd.request.command = 136; + bcd_ioctl2(&cmd, sizeof cmd); + if (_error) return 0; + return 1; +} + +#ifdef __cplusplus +} +#endif + +#ifdef STANDALONE +static char *card(int c) { + return c == 1 ? "" : "s"; +} + +static void print_hsg(int hsg) { + int hours, minutes, seconds; + seconds = hsg / 75; + minutes = seconds / 60; + seconds %= 60; + hours = minutes / 60; + minutes %= 60; + printf("%2d:%02d:%02d", hours, minutes, seconds); +} + +static void print_binary(int v, int len) { + for (;len;len--) + printf("%d", (v & (1 << len)) ? 1 : 0); +} + +int main(int argc, char *argv[]) { + int i, n1, n2, t; + + if (!bcd_open()) { + fprintf(stderr, "Couldn't open CD-ROM drive. %s\n", bcd_error()); + exit(0); + } + + for (i = 1; i < argc; i++) { + if (*argv[i] == '-') strcpy(argv[i], argv[i]+1); + if (!strcmp(argv[i], "open") || !strcmp(argv[i], "eject")) { + bcd_open_door(); + } else if (!strcmp(argv[i], "close")) { + bcd_close_door(); + } else if (!strcmp(argv[i], "sleep")) { + if (++i >= argc) break; + sleep(atoi(argv[i])); + } else if (!strcmp(argv[i], "list")) { + int nd = 0, na = 0, audio_time = 0; + if (!bcd_get_audio_info()) { + printf("Error getting audio info\n"); + } else if (lowest_track == 0) { + printf("No audio tracks\n"); + } else { + for (t = lowest_track; t <= highest_track; t++) { + printf("Track %2d: ", t); + print_hsg(tracks[t].start); + printf(" -> "); + print_hsg(tracks[t].end); + printf(" ("); + print_hsg(tracks[t].len); + if (tracks[t].is_audio) { + na++; + printf(") audio"); + audio_time += tracks[t].len; + } else { + nd++; + printf(") data "); + } + printf(" (HSG: %06d->%06d)\n", tracks[t].start, tracks[t].end); + } + printf("%d audio track%s, %d data track%s\n", na, card(na), nd, card(nd)); + if (audio_time) { + printf("Audio time: "); + print_hsg(audio_time); + printf("\n"); + } + } + } else if (!strcmp(argv[i], "lock")) { + bcd_lock(1); + } else if (!strcmp(argv[i], "pladdr")) { + if (++i >= argc) break; + n1 = atoi(argv[i]); + if (++i >= argc) break; + n2 = atoi(argv[i]); + printf("Playing frame %d to frame %d\n", n1, n2); + bcd_play(n1, n2-n1); + } else if (!strcmp(argv[i], "play")) { + if (++i >= argc) break; + if (bcd_audio_busy()) { + bcd_stop(); + delay(1000); + } + n1 = atoi(argv[i]); + printf("Playing track %d\n", n1); + bcd_play_track(n1); + } else if (!strcmp(argv[i], "reset")) { + bcd_reset(); + } else if (!strcmp(argv[i], "resume")) { + bcd_resume(); + } else if (!strcmp(argv[i], "status")) { + int s; + s = bcd_device_status(); + printf("MSCDEX version %d.%d\n", mscdex_version >> 8, + mscdex_version & 0xff); + printf("Device status word '"); + print_binary(s, 16); + printf("'\nDoor is %sopen\n", s & BCD_DOOR_OPEN ? "" : "not "); + printf("Door is %slocked\n", s & BCD_DOOR_UNLOCKED ? "not " : ""); + printf("Audio is %sbusy\n", bcd_audio_busy() ? "" : "not "); + s = bcd_disc_changed(); + if (s == BCD_DISC_UNKNOWN) printf("Media change status unknown\n"); + else printf("Media has %schanged\n", + (s == BCD_DISC_CHANGED) ? "" : "not "); + } else if (!strcmp(argv[i], "stop")) { + bcd_stop(); + } else if (!strcmp(argv[i], "unlock")) { + bcd_lock(0); + } else if (!strcmp(argv[i], "volume")) { + bcd_set_volume(atoi(argv[++i])); + } else if (!strcmp(argv[i], "wait")) { + while (bcd_audio_busy()) { + int n = bcd_now_playing(); + if (n == 0) break; + printf("%2d: ", n); + print_hsg(bcd_audio_position() - tracks[n].start); + printf("\r"); + fflush(stdout); + delay(100); + if (kbhit() && getch() == 27) break; + } + printf("\n"); + } else if (!strcmp(argv[i], "help") || !strcmp(argv[i], "usage")) { + printf("BCD version %x.%x\n" \ + "Usage: BCD {commands}\n" \ + "Valid commands:\n" \ + "\tclose - close door/tray\n" \ + "\tdelay {n} - delay {n} seconds\n" \ + "\tlist - list track info\n" \ + "\tlock - lock door/tray\n" \ + "\topen - open door/tray\n" \ + "\tpladdr {n1} {n2}- play frame {n1} to {n2}\n" \ + "\tplay {n} - play track {n}\n" \ + "\treset - reset the drive\n" \ + "\tresume - resume from last stop\n" \ + "\tstatus - show drive status\n" \ + "\tstop - stop audio playback\n" \ + "\tunlock - unlock door/tray\n" \ + "\tvolume {n} - set volume to {n} where 0 <= {n} <= 255\n", + BCD_VERSION >> 8, BCD_VERSION & 0xff); + } else + printf("Unknown command '%s'\n", argv[i]); + if (_error || _bcd_error) printf("%s\n", bcd_error()); + } + bcd_close(); + exit(0); +} +#endif diff --git a/src/djgppdos/bcd.h b/src/djgppdos/bcd.h new file mode 100644 index 000000000..3997128a2 --- /dev/null +++ b/src/djgppdos/bcd.h @@ -0,0 +1,90 @@ +/* bcd.h -- header file for BCD, a CD-ROM audio playing library for DJGPP + by Brennan Underwood, http://brennan.home.ml.org/ */ +#ifndef _BCD_H +#define _BCD_H + +#define BCD_VERSION 0x0103 + +/* Installation and setup functions */ +/* Call this first! */ +int bcd_open(void); +/* Call before exit. */ +int bcd_close(void); + +/* open door, unlocking first if necessary */ +int bcd_open_door(void); +/* close door */ +int bcd_close_door(void); + +/* pass 1 to lock door, 0 to unlock */ +int bcd_lock(int); + +/* returns one of the following 3 #defined symbols */ +int bcd_disc_changed(void); +#define BCD_DISC_CHANGED 0xff +#define BCD_DISC_NOT_CHANGED 1 +#define BCD_DISC_UNKNOWN 0 + +/* perform a device reset */ +int bcd_reset(void); + +/* compare the returned status int to the following bits */ +int bcd_device_status(void); +#define BCD_DOOR_OPEN 1 +#define BCD_DOOR_UNLOCKED 2 +#define BCD_SUPPORT_COOKED 4 +#define BCD_READ_ONLY 8 +#define BCD_DATA_READ_ONLY 16 +#define BCD_SUPPORT_INTERLEAVE 32 + +/* returns 1 if audio is currently playing, 0 otherwise. -1 on error */ +int bcd_audio_busy(void); +/* current head position in frames */ +int bcd_audio_position(void); +/* convenience function, if audio busy, returns track# playing now */ +int bcd_now_playing(void); + +/* query MSCDEX for track list when disc changed or just starting up */ +int bcd_get_audio_info(void); +/* get a particular track's info */ +int bcd_get_track_address(int trackno, int *start, int *len); +/* check for track's audio/data status */ +int bcd_track_is_audio(int trackno); +/* play a particular track from beginning to end */ +int bcd_play_track(int tracknum); +/* play an arbitrary section of audio for an arbitrary length of time */ +int bcd_play(int start, int len); +/* set the output volume. pass a parameter from 0-255 */ +int bcd_set_volume(int); +/* stop and pause are equivalent */ +int bcd_stop(void); +#define bcd_pause bcd_stop +int bcd_resume(void); + +/* Troubleshooting */ +/* Returns a human readable description of the last error encountered */ +const char *bcd_error(void); +extern int _error_code; +/* If you are mad enough play the Rach 3, I mean parse _error_code yourself */ +#define BCD_DE_WRITE_PROTECT 0 +#define BCD_DE_UNKNOWN_UNIT 1 +#define BCD_DE_DRIVE_NOT_READY 2 +#define BCD_DE_UNKNOWN_COMMAND 3 +#define BCD_DE_CRC_ERROR 4 +#define BCD_DE_STRUCT_LEN 5 +#define BCD_DE_SEEK_ERROR 6 +#define BCD_DE_UNKNOWN_MEDIA 7 +#define BCD_DE_SECTOR_NOT_FOUND 8 +#define BCD_DE_OUT_OF_PAPER 9 +#define BCD_DE_WRITE_FAULT 10 +#define BCD_DE_READ_FAULT 11 +#define BCD_DE_GENERAL_FAILURE 12 +#define BCD_DE_INVALID_DISK_CHANGE 15 +/* set by BCD itself, for stuff like "Out of memory" */ +extern const char *_bcd_error; + +/* uncomment this line to force BCD to use a statically allocated + Track array instead of using malloc */ +#define STATIC_TRACKS + +#endif diff --git a/src/djgppdos/i_cdmus.c b/src/djgppdos/i_cdmus.c new file mode 100644 index 000000000..f707add5e --- /dev/null +++ b/src/djgppdos/i_cdmus.c @@ -0,0 +1,445 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright (C) 1998-2000 by DooM Legacy Team. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +//----------------------------------------------------------------------------- +/// \file +/// \brief cd music interface (uses bcd library) + +// Alam_GBC: I hate you, Brennan Underwood :) +#include "../doomtype.h" +#include "bcd.c" +//#include "bcd.h" // CD-Audio library by Brennan Underwood + +#include "../doomdef.h" +#include "../i_sound.h" +#include "../command.h" +#include "../i_system.h" +#include "../s_sound.h" + +// ------ +// protos +// ------ +static void Command_Cd_f (void); + + +//====================================================================== +// CD AUDIO MUSIC SUBSYSTEM +//====================================================================== + +UINT8 cdaudio_started=0; // for system startup/shutdown + +#define MAX_CD_TRACKS 256 +static boolean cdPlaying = false; +static int cdPlayTrack; // when cdPlaying is true +static boolean cdLooping = false; +static UINT8 cdRemap[MAX_CD_TRACKS]; +static boolean cdEnabled=true; // cd info available +static boolean cdValid; // true when last cd audio info was ok +static boolean wasPlaying; +static int cdVolume=0; // current cd volume (0-31) + +// 0-31 like Music & Sfx, though CD hardware volume is 0-255. +consvar_t cd_volume = {"cd_volume","31",CV_SAVE,soundvolume_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; + +// allow Update for next/loop track +// some crap cd drivers take up to +// a second for a simple 'busy' check.. +// (on those Update can be disabled) +consvar_t cdUpdate = {"cd_update","1",CV_SAVE, NULL, NULL, 0, NULL, NULL, 0, 0, NULL}; + + +// hour,minutes,seconds +FUNCINLINE static ATTRINLINE char *hms(int hsg) +{ + int hours, minutes, seconds; + static char s[9]; + + seconds = hsg / 75; + minutes = seconds / 60; + seconds %= 60; + hours = minutes / 60; + minutes %= 60; + if (hours>0) + sprintf (s, "%d:%02d:%02d", hours, minutes, seconds); + else + sprintf (s, "%2d:%02d", minutes, seconds); + return s; +} + +static void Command_Cd_f (void) +{ + const char * s; + int i,j; + + if (!cdaudio_started) + return; + + if (COM_Argc()<2) + { + CONS_Printf ("cd [on] [off] [remap] [reset] [open]\n" + " [info] [play ] [loop ]\n" + " [stop] [resume]\n"); + return; + } + + s = COM_Argv(1); + + // activate cd music + if (!strncmp(s,"on",2)) + { + cdEnabled = true; + return; + } + + // stop/deactivate cd music + if (!strncmp(s,"off",3)) + { + if (cdPlaying) + I_StopCD (); + cdEnabled = false; + return; + } + + // remap tracks + if (!strncmp(s,"remap",5)) + { + i = COM_Argc() - 2; + if (i <= 0) + { + CONS_Printf ("CD tracks remapped in that order :\n"); + for (j = 1; j < MAX_CD_TRACKS; j++) + if (cdRemap[j] != j) + CONS_Printf (" %2d -> %2d\n", j, cdRemap[j]); + return; + } + for (j = 1; j <= i; j++) + cdRemap[j] = atoi (COM_Argv (j+1)); + return; + } + + // reset the CD driver, useful on some odd cd's + if (!strncmp(s,"reset",5)) + { + cdEnabled = true; + if (cdPlaying) + I_StopCD (); + for (i = 0; i < MAX_CD_TRACKS; i++) + cdRemap[i] = i; + bcd_reset (); + cdValid = bcd_get_audio_info (); + return; + } + + // any other command is not allowed until we could retrieve cd information + if (!cdValid) + { + CONS_Printf ("CD is not ready.\n"); + return; + } + + if (!strncmp(s,"open",4)) + { + if (cdPlaying) + I_StopCD (); + bcd_open_door(); + cdValid = false; + return; + } + + if (!strncmp(s,"info",4)) + { + int totaltime = 0; + + if (!bcd_get_audio_info()) + { + CONS_Printf ("Error getting audio info: %s\n",bcd_error()); + cdValid = false; + return; + } + + cdValid = true; + + if (lowest_track == 0) + CONS_Printf ("No audio tracks\n"); + else + { + // display list of tracks + // highlight current playing track + for (i=lowest_track; i <= highest_track; i++) + { + CONS_Printf ("%s%2d. %s %s\n", + cdPlaying && (cdPlayTrack == i) ? "\2 " : " ", + i, tracks[i].is_audio ? "audio" : "data ", + hms(tracks[i].len)); + if (tracks[i].is_audio) + totaltime += tracks[i].len; + } + + if (totaltime) + CONS_Printf ("\2Total time : %s\n", hms(totaltime)); + } + if (cdPlaying) + { + CONS_Printf ("%s track : %d\n", cdLooping ? "looping" : "playing", + cdPlayTrack); + } + return; + } + + if (!strncmp(s,"play",4)) + { + I_PlayCD ((UINT8)atoi (COM_Argv (2)), false); + return; + } + + if (!strncmp(s,"stop",4)) + { + I_StopCD (); + return; + } + + if (!strncmp(s,"loop",4)) + { + I_PlayCD ((UINT8)atoi (COM_Argv (2)), true); + return; + } + + if (!strncmp(s,"resume",4)) + { + I_ResumeCD (); + return; + } + + CONS_Printf ("cd command '%s' unknown\n", s); +} + + +// pause cd music +void I_StopCD (void) +{ + if (!cdaudio_started || !cdEnabled) + return; + + bcd_stop(); + + wasPlaying = cdPlaying; + cdPlaying = false; +} + +// continue after a pause +void I_ResumeCD (void) +{ + if (!cdaudio_started || !cdEnabled) + return; + + if (!cdValid) + return; + + if (!wasPlaying) + return; + + bcd_resume (); + cdPlaying = true; +} + + +void I_ShutdownCD (void) +{ + int rc; + + if (!cdaudio_started) + return; + + I_StopCD (); + + rc = bcd_close (); + if (!rc) + CONS_Printf ("Error shuting down cd\n"); +} + +void I_InitCD (void) +{ + int rc; + int i; + + rc = bcd_open (); + + if (rc>=0x200) + { + CONS_Printf ("MSCDEX version %d.%d\n", rc>>8, rc&255); + + I_AddExitFunc (I_ShutdownCD); + cdaudio_started = true; + } + else + { + if (!rc) + CONS_Printf ("%s\n", bcd_error() ); + + cdaudio_started = false; + return; + } + + // last saved in config.cfg + i = cd_volume.value; + I_SetVolumeCD (0); // initialize to 0 for some odd cd drivers + I_SetVolumeCD (i); // now set the last saved volume + + for (i = 0; i < MAX_CD_TRACKS; i++) + cdRemap[i] = i; + + if (!bcd_get_audio_info()) + { + CONS_Printf("\2CD Init: No CD in player.\n"); + cdEnabled = false; + cdValid = false; + } + else + { + cdEnabled = true; + cdValid = true; + } + + COM_AddCommand ("cd", Command_Cd_f); +} + + + +// loop/go to next track when track is finished (if cd_update var is true) +// update the volume when it has changed (from console/menu) +/// \todo check for cd change and restart music ? + +void I_UpdateCD (void) +{ + int newVolume; + int now; + static int last; //game tics (35th of second) + + if (!cdaudio_started) + return; + + now = I_GetTime (); + if ((now - last) < 10) // about 1/4 second + return; + last = now; + + // update cd volume changed at console/menu + newVolume = cd_volume.value & 31; + + if (cdVolume != newVolume) + I_SetVolumeCD (newVolume); + + // slow drivers exit here + if (!cdUpdate.value) + return; + + if (cdPlaying) + { + if (!bcd_audio_busy()) + { + cdPlaying = false; + if (cdLooping) + I_PlayCD (cdPlayTrack, true); + else + { + // play the next cd track, or restart the first + cdPlayTrack++; + if (cdPlayTrack > highest_track) + cdPlayTrack = lowest_track; + while (!tracks[cdPlayTrack].is_audio && cdPlayTrack highest_track) + { + //CONS_Printf ("\2CD Audio: wrong track number %d\n", track); + // suppose there are not enough tracks for game levels.. + // then do a modulo so we always get something to hear + track = (track % (highest_track-lowest_track+1)) + 1; + //return; + } + + cdPlayTrack = track; + + if (!tracks[track].is_audio) + { + CONS_Printf ("\2CD Play: not an audio track\n"); + return; + } + + cdLooping = looping; + + if (!bcd_play_track (track)) + { + CONS_Printf ("CD Play: could not play track %d\n", track); + cdValid = false; + cdPlaying = false; + return; + } + + cdPlaying = true; + +} + + +// volume : logical cd audio volume 0-31 (hardware is 0-255) +boolean I_SetVolumeCD (INT32 volume) +{ + int hardvol; + + if (!cdaudio_started || !cdEnabled) + return false; + + // translate to hardware volume + volume &= 31; + + hardvol = ((volume+1)<<3)-1; //highest volume is 255 + if (hardvol<=8) + hardvol=0; //lowest volume is ZERO + + cdVolume = volume; + + if (bcd_set_volume (hardvol)) + { + CV_SetValue (&cd_volume, volume); + + return true; + } + else + return false; +} diff --git a/src/djgppdos/i_main.c b/src/djgppdos/i_main.c new file mode 100644 index 000000000..1b8894470 --- /dev/null +++ b/src/djgppdos/i_main.c @@ -0,0 +1,78 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright (C) 1993-1996 by id Software, Inc. +// Copyright (C) 1998-2000 by DooM Legacy Team. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +//----------------------------------------------------------------------------- +/// \file +/// \brief Main program, simply calls D_SRB2Main high level loop. + +#include "../doomdef.h" + +#include "../m_argv.h" +#include "../d_main.h" + +#include "../i_system.h" + +#ifdef REMOTE_DEBUGGING +#include +#include "rdb.h" +#endif + +//### let's try with Allegro ### +#define alleg_mouse_unused +#define alleg_timer_unused +#define ALLEGRO_NO_KEY_DEFINES +#define alleg_keyboard_unused +#define alleg_joystick_unused +#define alleg_gfx_driver_unused +#define alleg_palette_unused +#define alleg_graphics_unused +#define alleg_vidmem_unused +#define alleg_flic_unused +#define alleg_sound_unused +#define alleg_file_unused +#define alleg_datafile_unused +#define alleg_math_unused +#define alleg_gui_unused +#include +//### end of Allegro include ### + +int main (int argc, char **argv) +{ + myargc = argc; + myargv = argv; + + { + //added:03-01-98: + // Setup signal handlers and other stuff BEFORE ANYTHING ELSE! + I_StartupSystem(); +#ifdef REMOTE_DEBUGGING + /* Only setup if remote debugging is to be done, Muhahahaha!*/ + gdb_serial_init(DEBUG_COM_PORT,DEBUG_COM_PORT_SPEED); + gdb_target_init(); + breakpoint(); +#endif + + D_SRB2Main(); + D_SRB2Loop(); + + } + //added:03-01-98: + // hmmm... it will never go here. + + return 0; +} +#if ALLEGRO_VERSION == 4 +END_OF_MAIN() +#endif diff --git a/src/djgppdos/i_net.c b/src/djgppdos/i_net.c new file mode 100644 index 000000000..866aa8d8b --- /dev/null +++ b/src/djgppdos/i_net.c @@ -0,0 +1,113 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright (C) 1993-1996 by id Software, Inc. +// Portions Copyright (C) 1998-2000 by DooM Legacy Team. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +//----------------------------------------------------------------------------- +/// \file +/// \brief doomcom network interface + + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "../doomdef.h" + +#include "../i_system.h" +#include "../d_event.h" +#include "../d_net.h" +#include "../m_argv.h" + +#include "../doomstat.h" +#include "../z_zone.h" +#include "../i_net.h" +#include "../i_tcp.h" + +// +// NETWORKING +// + +typedef enum +{ + CMD_SEND = 1, + CMD_GET = 2, +} command_t; + +static void External_Driver_Get(void); +static void External_Driver_Send(void); +static void External_Driver_FreeNode(INT32 nodenum); + +static inline boolean External_Driver_OpenSocket(void) +{ + I_NetGet = External_Driver_Get; + I_NetSend = External_Driver_Send; + I_NetCloseSocket = NULL; + I_NetFreeNodenum = External_Driver_FreeNode; + + return true; +} + +// +// I_InitNetwork +// +boolean I_InitNetwork (void) +{ + int netgamepar; + + netgamepar = M_CheckParm ("-net"); + if (!netgamepar) + return false; + + // externals drivers specific + + __djgpp_nearptr_enable(); + + // set up for network + doomcom=(doomcom_t *)(__djgpp_conventional_base+atoi(myargv[netgamepar+1])); + CONS_Printf("I_DosNet : Using int 0x%x for communication\n",doomcom->intnum); + + server = (doomcom->consoleplayer == 0); + if (!server) + COM_BufAddText("connect any\n"); + + // ipx + time + 4 (padding) + packetheaderlength=30+4+4; + + hardware_MAXPACKETLENGTH = 512; + + I_NetOpenSocket = External_Driver_OpenSocket; + return true; +} + +FUNCNORETURN static ATTRNORETURN void External_Driver_Get(void) +{ + I_Error("External_Driver_Get not supported at this time"); +} + +FUNCNORETURN static ATTRNORETURN void External_Driver_Send(void) +{ + I_Error("External_Driver_Send not supported at this time"); +} + +FUNCNORETURN static ATTRNORETURN void External_Driver_FreeNode(INT32 nodenum) +{ + nodenum = 0; + I_Error("External_Driver_FreeNode not supported at this time"); +} diff --git a/src/djgppdos/i_sound.c b/src/djgppdos/i_sound.c new file mode 100644 index 000000000..88fc807f4 --- /dev/null +++ b/src/djgppdos/i_sound.c @@ -0,0 +1,551 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright (C) 1993-1996 by id Software, Inc. +// Portions Copyright (C) 1998-2000 by DooM Legacy Team. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +//----------------------------------------------------------------------------- +/// \file +/// \brief interface level code for sound + +#include +#include +#include + +#include + +#include "../doomdef.h" +#include "../doomstat.h" +#include "../i_system.h" +#include "../i_sound.h" +#include "../z_zone.h" +#include "../m_argv.h" +#include "../m_misc.h" +#include "../w_wad.h" +#include "../s_sound.h" +#include "../console.h" + +//### let's try with Allegro ### +#define alleg_mouse_unused +#define alleg_timer_unused +#define ALLEGRO_NO_KEY_DEFINES +#define alleg_keyboard_unused +#define alleg_joystick_unused +#define alleg_gfx_driver_unused +#define alleg_palette_unused +#define alleg_graphics_unused +#define alleg_vidmem_unused +#define alleg_flic_unused +//#define alleg_sound_unused we use it +#define alleg_file_unused +#define alleg_datafile_unused +#define alleg_math_unused +#define alleg_gui_unused +#include +//### end of Allegro include ### + +//allegro has 256 virtual voices +// warning should by a power of 2 +#define VIRTUAL_VOICES 256 +#define VOICESSHIFT 8 + +// Needed for calling the actual sound output. +#define SAMPLECOUNT 512 + + + +// +// this function converts raw 11khz, 8-bit data to a SAMPLE* that allegro uses +// it is need cuz allegro only loads samples from wavs and vocs +//added:11-01-98: now reads the frequency from the rawdata header. +// dsdata points a 4 UINT16 header: +// +0 : value 3 what does it mean? +// +2 : sample rate, either 11025 or 22050. +// +4 : number of samples, each sample is a single byte since it's 8bit +// +6 : value 0 +static inline SAMPLE *raw2SAMPLE(UINT8 *dsdata, size_t len) +{ + SAMPLE *spl; + + spl=Z_Malloc(sizeof (SAMPLE),PU_SOUND,NULL); + if (spl==NULL) + I_Error("Raw2Sample : no more free mem"); + spl->bits = 8; + spl->stereo = 0; + spl->freq = *((UINT16 *)dsdata+1); //mostly 11025, but some at 22050. + spl->len = len-8; + spl->priority = 255; //priority; + spl->loop_start = 0; + spl->loop_end = len-8; + spl->param = -1; + spl->data=(void *)(dsdata+8); //skip the 8bytes header + + return spl; +} + + +// This function loads the sound data from the WAD lump, +// for single sound. +// +void *I_GetSfx (sfxinfo_t * sfx) +{ + UINT8 *dssfx; + + if (sfx->lumpnum == LUMPERROR) + sfx->lumpnum = S_GetSfxLumpNum (sfx); + + sfx->length = W_LumpLength (sfx->lumpnum); + + dssfx = (UINT8 *) W_CacheLumpNum (sfx->lumpnum, PU_SOUND); + //_go32_dpmi_lock_data(dssfx,size); + + // convert raw data and header from Doom sfx to a SAMPLE for Allegro + return (void *)raw2SAMPLE (dssfx, sfx->length); +} + + +void I_FreeSfx (sfxinfo_t *sfx) +{ + if (sfx->lumpnum == LUMPERROR) + return; + + // free sample data + if ( sfx->data ) + Z_Free((UINT8 *) ((SAMPLE *)sfx->data)->data - 8); + Z_Free(sfx->data); // Allegro SAMPLE structure + sfx->data = NULL; + sfx->lumpnum = LUMPERROR; +} + +FUNCINLINE static ATTRINLINE int Volset(int vol) +{ + return (vol*255/31); +} + + +void I_SetSfxVolume(INT32 volume) +{ + if (nosound) + return; + + set_volume (Volset(volume),-1); +} + +void I_SetMIDIMusicVolume(INT32 volume) +{ + if (nomidimusic) + return; + + // Now set volume on output device. + set_volume (-1, Volset(volume)); +} + +// +// Starting a sound means adding it +// to the current list of active sounds +// in the internal channels. +// As the SFX info struct contains +// e.g. a pointer to the raw data, +// it is ignored. +// As our sound handling does not handle +// priority, it is ignored. +// Pitching (that is, increased speed of playback) +// is set, but currently not used by mixing. +// +INT32 I_StartSound ( sfxenum_t id, + INT32 vol, + INT32 sep, + INT32 pitch, + INT32 priority ) +{ + int voice; + + if (nosound) + return 0; + + // UNUSED + priority = 0; + + pitch = (pitch-128)/2+128; + voice = play_sample(S_sfx[id].data,vol,sep,(pitch*1000)/128,0); + + // Returns a handle + return (id<>VOICESSHIFT].data) + deallocate_voice(voice); +} + +INT32 I_SoundIsPlaying(INT32 handle) +{ + if (nosound) + return FALSE; + + if (voice_check(handle & (VIRTUAL_VOICES-1))==S_sfx[handle>>VOICESSHIFT].data) + return TRUE; + + return FALSE; +} + +// cut and past from ALLEGRO he don't share it :( +static inline int absolute_freq(int freq, SAMPLE *spl) +{ + if (freq == 1000) + return spl->freq; + else + return (spl->freq * freq) / 1000; +} + +void I_UpdateSoundParams( INT32 handle, + INT32 vol, + INT32 sep, + INT32 pitch) +{ + // I fail too see that this is used. + // Would be using the handle to identify + // on which channel the sound might be active, + // and resetting the channel parameters. + int voice=handle & (VIRTUAL_VOICES-1); + int numsfx=handle>>VOICESSHIFT; + + if (nosound) + return; + + if (voice_check(voice)==S_sfx[numsfx].data) + { + voice_set_volume(voice, vol); + voice_set_pan(voice, sep); + voice_set_frequency(voice, absolute_freq(pitch*1000/128, + S_sfx[numsfx].data)); + } +} + + +void I_ShutdownSound(void) +{ + // Wait till all pending sounds are finished. + + //added:03-01-98: + if ( !sound_started ) + return; + + //added:08-01-98: remove_sound() explicitly because we don't use + // Allegro's allegro_exit(); + remove_sound(); + sound_started = false; +} + +static char soundheader[] = "sound"; +#if ALLEGRO_VERSION == 3 +static char soundvar[] = "sb_freq"; +#else +static char soundvar[] = "sound_freq"; +#endif + +void I_StartupSound(void) +{ + int sfxcard,midicard; +#if ALLEGRO_VERSION == 3 + char err[255]; +#endif + + if (nosound) + sfxcard=DIGI_NONE; + else + sfxcard=DIGI_AUTODETECT; + + if (nomidimusic) + midicard=MIDI_NONE; + else + midicard=MIDI_AUTODETECT; //DetectMusicCard(); + + nodigimusic=true; //Alam: No OGG/MP3/IT/MOD support + + // Secure and configure sound device first. + CONS_Printf("I_StartupSound: "); + + //Fab:25-04-98:note:install_sound will check for sound settings + // in the sound.cfg or allegro.cfg, in the current directory, + // or the directory pointed by 'ALLEGRO' env var. +#if ALLEGRO_VERSION == 3 + if (install_sound(sfxcard,midicard,NULL)!=0) + { + sprintf (err,"Sound init error : %s\n",allegro_error); + CONS_Error (err); + nosound=true; + nomidimusic=true; + } + else + { + CONS_Printf(" configured audio device\n" ); + } + + //added:08-01-98:we use a similar startup/shutdown scheme as Allegro. + I_AddExitFunc(I_ShutdownSound); +#endif + sound_started = true; + CV_SetValue(&cv_samplerate,get_config_int(soundheader,soundvar,cv_samplerate.value)); +} + + + + +// +// MUSIC API. +// Still no music done. +// Remains. Dummies. +// + +static MIDI* currsong; //im assuming only 1 song will be played at once +static int islooping=0; +static int musicdies=-1; +UINT8 music_started=0; + + +/* load_midi_mem: + * Loads a standard MIDI file from memory, returning a pointer to + * a MIDI structure, * or NULL on error. + * It is the load_midi from Allegro modified to load it from memory + */ +static MIDI *load_midi_mem(char *mempointer,int *e) +{ + int c = *e; + long data=0; + unsigned char *fp; + MIDI *midi; + int num_tracks=0; + + fp = (void *)mempointer; + if (!fp) + return NULL; + + midi = malloc(sizeof (MIDI)); /* get some memory */ + if (!midi) + return NULL; + + for (c=0; ctrack[c].data = NULL; + midi->track[c].len = 0; + } + + fp+=4+4; // header size + 'chunk' size + + swab(fp,&data,2); // convert to intel-endian + fp+=2; /* MIDI file type */ + if ((data != 0) && (data != 1)) // only type 0 and 1 are suported + return NULL; + + swab(fp,&num_tracks,2); /* number of tracks */ + fp+=2; + if ((num_tracks < 1) || (num_tracks > MIDI_TRACKS)) + return NULL; + + swab(fp,&data,2); /* beat divisions */ + fp+=2; + midi->divisions = ABS(data); + + for (c=0; ctrack[c].len = data; + + midi->track[c].data = fp; + fp+=data; + } + + lock_midi(midi); + return midi; +} + +void I_InitMIDIMusic(void) +{ + if (nomidimusic) + return; + + I_AddExitFunc(I_ShutdownMusic); + music_started = true; +} + +void I_ShutdownMIDIMusic(void) +{ + if ( !music_started ) + return; + + I_StopSong(1); + + music_started=false; +} + +void I_InitDigMusic(void) +{ +// CONS_Printf("Digital music not yet supported under DOS.\n"); +} + +void I_ShutdownDigMusic(void) +{ +// CONS_Printf("Digital music not yet supported under DOS.\n"); +} + +void I_InitMusic(void) +{ + if (!nodigimusic) + I_InitDigMusic(); + if (!nomidimusic) + I_InitMIDIMusic(); +} + +void I_ShutdownMusic(void) +{ + I_ShutdownMIDIMusic(); + I_ShutdownDigMusic(); +} + +boolean I_PlaySong(INT32 handle, INT32 looping) +{ + handle = 0; + if (nomidimusic) + return false; + + islooping = looping; + musicdies = gametic + NEWTICRATE*30; + if (play_midi(currsong,looping)==0) + return true; + return false; +} + +void I_PauseSong (INT32 handle) +{ + handle = 0; + if (nomidimusic) + return; + + midi_pause(); +} + +void I_ResumeSong (INT32 handle) +{ + handle = 0; + if (nomidimusic) + return; + + midi_resume(); +} + +void I_StopSong(INT32 handle) +{ + handle = 0; + if (nomidimusic) + return; + + islooping = 0; + musicdies = 0; + stop_midi(); +} + +// Is the song playing? +#if 0 +int I_QrySongPlaying(int handle) +{ + if (nomidimusic) + return 0; + + //return islooping || musicdies > gametic; + return (midi_pos==-1); +} +#endif + +void I_UnRegisterSong(INT32 handle) +{ + handle = 0; + if (nomidimusic) + return; + + //destroy_midi(currsong); +} + +INT32 I_RegisterSong(void *data, size_t len) +{ + int e = len; //Alam: For error + if (nomidimusic) + return 0; + + if (memcmp(data,"MThd",4)==0) // support mid file in WAD !!! + { + currsong=load_midi_mem(data,&e); + } + else + { + CONS_Printf("Music Lump is not a MIDI lump\n"); + return 0; + } + + if (currsong==NULL) + { + CONS_Printf("Not a valid mid file : %d\n",e); + return 0; + } + + return 1; +} + +/// \todo Add OGG/MP3 support for dos +boolean I_StartDigSong(const char *musicname, INT32 looping) +{ + musicname = NULL; + looping = 0; + //CONS_Printf("I_StartDigSong: Not yet supported under DOS.\n"); + return false; +} + +void I_StopDigSong(void) +{ +// CONS_Printf("I_StopDigSong: Not yet supported under DOS.\n"); +} + +void I_SetDigMusicVolume(INT32 volume) +{ + volume = 0; + if (nodigimusic) + return; + + // Now set volume on output device. +// CONS_Printf("Digital music not yet supported under DOS.\n"); +} + +boolean I_SetSongSpeed(float speed) +{ + (void)speed; + return false; +} diff --git a/src/djgppdos/i_system.c b/src/djgppdos/i_system.c new file mode 100644 index 000000000..421652760 --- /dev/null +++ b/src/djgppdos/i_system.c @@ -0,0 +1,1753 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright (C) 1993-1996 by id Software, Inc. +// Portions Copyright (C) 1998-2000 by DooM Legacy Team. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +//----------------------------------------------------------------------------- +/// \file +/// \brief Misc. stuff +/// +/// Startup & Shutdown routines for music,sound,timer,keyboard, +/// Signal handler to trap errors and exit cleanly. + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef DJGPP + #include + #include + #include + #include + #include + #include + #include + + #include +#endif + + +#include "../doomdef.h" +#include "../m_misc.h" +#include "../i_video.h" +#include "../i_sound.h" +#include "../i_system.h" +#include "../d_net.h" +#include "../g_game.h" + +#include "../d_main.h" + +#include "../m_argv.h" + +#include "../w_wad.h" +#include "../z_zone.h" +#include "../g_input.h" + +#include "../console.h" + +#ifdef __GNUG__ + #pragma implementation "../i_system.h" +#endif + +#include "../i_joy.h" + +//### let's try with Allegro ### +#define alleg_mouse_unused +//#define alleg_timer_unused +#define alleg_keyboard_unused +#define ALLEGRO_NO_KEY_DEFINES +//#define alleg_joystick_unused +#define alleg_gfx_driver_unused +#define alleg_palette_unused +#define alleg_graphics_unused +#define alleg_vidmem_unused +#define alleg_flic_unused +#define alleg_sound_unused +#define alleg_file_unused +#define alleg_datafile_unused +#define alleg_math_unused +#define alleg_gui_unused +#include +//### end of Allegro include ### + +#ifndef DOXYGEN + +#ifndef MAX_JOYSTICKS +#define MAX_JOYSTICKS 4 +#endif + +#ifndef MAX_JOYSTICK_AXIS +#define MAX_JOYSTICK_AXIS 3 +#endif + +#ifndef MAX_JOYSTICK_STICKS +#define MAX_JOYSTICK_STICKS 4 +#endif + +#ifndef MAX_JOYSTICK_BUTTONS +#define MAX_JOYSTICK_BUTTONS 12 +#endif + +#endif + +#if ALLEGRO_VERSION == 4 +static char JOYFILE[] = "allegro4.cfg"; +#elif ALLEGRO_VERSION == 3 +static char JOYFILE[] = "allegro.cfg"; +#endif + +/// \brief max number of joystick buttons +#define JOYBUTTONS_MAX MAX_JOYSTICK_BUTTONS // +/// \brief max number of joystick button events +#define JOYBUTTONS_MIN min((JOYBUTTONS),(JOYBUTTONS_MAX)) + +/// \brief max number of joysick axies +#define JOYAXISSET_MAX MAX_JOYSTICK_STICKS +// \brief max number ofjoystick axis events +#define JOYAXISSET_MIN min((JOYAXISSET),(JOYAXISSET_MAX)) + +/// \brief max number of joystick hats +#define JOYHATS_MAX MAX_JOYSTICK_STICKS +/// \brief max number of joystick hat events +#define JOYHATS_MIN min((JOYHATS),(JOYHATS_MAX)) + +/// \brief max number of mouse buttons +#define MOUSEBUTTONS_MAX 16 // 16 bit of BL +/// \brief max number of muse button events +#define MOUSEBUTTONS_MIN min((MOUSEBUTTONS),(MOUSEBUTTONS_MAX)) + +// Do not execute cleanup code more than once. See Shutdown_xxx() routines. +UINT8 graphics_started = false; +UINT8 keyboard_started = false; +UINT8 sound_started = false; +static UINT8 timer_started = false; + +/* Mouse stuff */ +static UINT8 mouse_detected = false; +static UINT8 wheel_detected = false; + +static volatile tic_t ticcount; //returned by I_GetTime(), updated by timer interrupt + + +void I_Tactile(FFType Type, const JoyFF_t *Effect) +{ + // UNUSED. + Type = EvilForce; + Effect = NULL; +} + +void I_Tactile2(FFType Type, const JoyFF_t *Effect) +{ + // UNUSED. + Type = EvilForce; + Effect = NULL; +} + +static ticcmd_t emptycmd; +ticcmd_t * I_BaseTiccmd(void) +{ + return &emptycmd; +} + +static ticcmd_t emptycmd2; +ticcmd_t * I_BaseTiccmd2(void) +{ + return &emptycmd2; +} + +void I_SetupMumble(void) +{ +} + +void I_UpdateMumble(const MumblePos_t *MPos) +{ + (void)MPos; +} + +// +// Allocates the base zone memory, +// this function returns a valid pointer and size, +// else it should interrupt the program immediately. +// +//added:11-02-98: now checks if mem could be allocated, this is still +// prehistoric... there's a lot to do here: memory locking, detection +// of win95 etc... +// + +#if ALLEGRO_VERSION == 3 +extern int os_type; +extern int windows_version; +extern int windows_sub_version; +extern int i_love_bill; +#elif ALLEGRO_VERSION == 4 +#endif + +static void I_DetectOS (void) +{ +#if ALLEGRO_VERSION == 3 + char buf[16]; + __dpmi_regs r; + union REGS regs; + + /* check which OS we are running under */ + r.x.ax = 0x1600; + __dpmi_int(0x2F, &r); + if ((r.h.al != 0) && (r.h.al != 1) && (r.h.al != 0x80) && (r.h.al != 0xFF)) + { + /* win 3.1 or 95 */ + if (r.h.al == 4) + { + if (r.h.ah < 10) + { + os_type = OSTYPE_WIN95; + } + else + { + os_type = OSTYPE_WIN98; + } + } + else + { + os_type = OSTYPE_WIN3; + } + + windows_version = r.h.al; + windows_sub_version = r.h.ah; + i_love_bill = TRUE; + } + else + { + if (_get_dos_version(1) == 0x0532) + { + /* win NT */ + os_type = OSTYPE_WINNT; + windows_version = 0x100; + windows_sub_version = 0; + i_love_bill = TRUE; + } + else + { + /* see if OS/2 is present */ + r.x.ax = 0x4010; + __dpmi_int(0x2F, &r); + if (r.x.ax != 0x4010) + { + if (r.x.ax == 0x0000) + { + /* OS/2 Warp 3 */ + os_type = OSTYPE_WARP; + i_love_bill = TRUE; + } + else + { + /* no Warp, but previous OS/2 is available */ + os_type = OSTYPE_OS2; + i_love_bill = TRUE; + } + } + else + { + /* check if running under Linux DOSEMU */ + dosmemget(0xFFFF5, 10, buf); + buf[8] = 0; + if (!strcmp(buf, "02/25/93")) + { + regs.x.ax = 0; + int86(0xE6, ®s, ®s); + if (regs.x.ax == 0xAA55) + { + os_type = OSTYPE_DOSEMU; + windows_version = -1; + windows_sub_version = -1; + i_love_bill = TRUE; /* (evil chortle) */ + } + } + else + { + /* check if running under OpenDOS */ + r.x.ax = 0x4452; + __dpmi_int(0x21, &r); + if ((r.x.ax >= 0x1072) && !(r.x.flags & 1)) + { + os_type = OSTYPE_OPENDOS; + /* now check for OpenDOS EMM386.EXE */ + r.x.ax = 0x12FF; + r.x.bx = 0x0106; + __dpmi_int(0x2F, &r); + if ((r.x.ax == 0x0) && (r.x.bx == 0xEDC0)) + { + i_love_bill = TRUE; + } + } + } + } + } + } +#elif ALLEGRO_VERSION == 4 +/// \todo: add Allegro 4 version +#endif +} + +UINT32 I_GetFreeMem(UINT32 *total) +{ + __dpmi_free_mem_info info; + + __dpmi_get_free_memory_information(&info); + if ( total ) + *total = info.total_number_of_physical_pages<<12; // <<12 for convert page to byte + return info.total_number_of_free_pages<<12; +} + + +/*==========================================================================*/ +// I_GetTime () +/*==========================================================================*/ +tic_t I_GetTime (void) +{ + return ticcount; +} + + +void I_Sleep(void) +{ + if (cv_sleep.value > 0) + rest(cv_sleep.value); +} + + +static UINT8 joystick_detected = false; +static UINT8 joystick2_detected = false; + +// +// I_Init +// + + +FUNCINLINE static ATTRINLINE int I_WaitJoyButton (int js) +{ + CON_Drawer (); + I_FinishUpdate (); // page flip or blit buffer + + do + { + if (I_GetKey()) + return false; + poll_joystick(); + } while (!(joy[js].button[0].b || joy[js].button[1].b)); + + return true; +} + +/** \brief Joystick 1 buttons states +*/ +static INT64 lastjoybuttons = 0; +/** \brief Joystick 1 hats state +*/ +static INT64 lastjoyhats = 0; + +void I_InitJoystick (void) +{ + //init the joystick + if (joystick_detected && !joystick2_detected) + remove_joystick(); + joystick_detected=0; + if (M_CheckParm("-nojoy")) + return; + load_joystick_data(JOYFILE); + if (cv_usejoystick.value) + { + if (cv_usejoystick.value > MAX_JOYSTICKS) + cv_usejoystick.value = MAX_JOYSTICKS; + if (install_joystick(JOY_TYPE_AUTODETECT) == 0) + { + int js = cv_usejoystick.value -1; + // only gamepadstyle joysticks + if (joy[js].stick[0].flags & JOYFLAG_DIGITAL) Joystick.bGamepadStyle=true; + + while (joy[js].flags & JOYFLAG_CALIBRATE) + { + const char *msg = calibrate_joystick_name(js); + CONS_Printf("%s, and press a button\n", msg); + if (I_WaitJoyButton(js)) + calibrate_joystick(js); + else + { + if (joystick_detected && !joystick2_detected) + remove_joystick(); + joystick_detected=0; + CV_SetValue(&cv_usejoystick, 0); + return; + } + } + joystick_detected=1; + save_joystick_data(JOYFILE); + } + else + { + CONS_Printf("\2No Joystick detected.\n"); + } + } + else + { + int i; + event_t event; + event.type=ev_keyup; + event.data2 = 0; + event.data3 = 0; + + lastjoybuttons = lastjoyhats = 0; + + // emulate the up of all joystick buttons + for (i=0;i MAX_JOYSTICKS) + cv_usejoystick2.value = MAX_JOYSTICKS; + if (install_joystick(JOY_TYPE_AUTODETECT) == 0) + { + int js = cv_usejoystick2.value -1; + // only gamepadstyle joysticks + load_joystick_data(JOYFILE); + if (joy[js].stick[0].flags & JOYFLAG_DIGITAL) Joystick2.bGamepadStyle=true; + + while (joy[js].flags & JOYFLAG_CALIBRATE) + { + const char *msg = calibrate_joystick_name(js); + CONS_Printf("%s, and press a button\n", msg); + if (I_WaitJoyButton(js)) + calibrate_joystick(js); + else + { + if (joystick2_detected && !joystick_detected) + remove_joystick(); + joystick2_detected=0; + CV_SetValue(&cv_usejoystick2, 0); + return; + } + } + joystick2_detected=1; + save_joystick_data(JOYFILE); + } + else + { + CONS_Printf("\2No Joystick detected.\n"); + } + } + else + { + int i; + event_t event; + event.type=ev_keyup; + event.data2 = 0; + event.data3 = 0; + + lastjoy2buttons = lastjoy2hats = 0; + + // emulate the up of all joystick buttons + for (i=0;i7) + exit(-1); // recursive errors detected + } + shutdowning=true; + + //added:18-02-98: save one time is enough! + if (!errorcount) + { + M_SaveConfig (NULL); //save game config, cvars.. + G_SaveGameData(); // Tails 12-08-2002 + } + + //added:16-02-98: save demo, could be useful for debug + // NOTE: demos are normally not saved here. + I_ShutdownMusic(); + I_ShutdownSound(); + I_ShutdownCD(); + I_ShutdownGraphics(); + I_ShutdownSystem(); + + // put message to stderr + va_start (argptr,error); + fprintf (stderr, "Error: "); + vfprintf (stderr,error,argptr); +#ifdef DEBUGFILE + if (debugfile) + { + fprintf (debugfile,"I_Error :"); + vfprintf (debugfile,error,argptr); + } +#endif + + va_end (argptr); + + fprintf (stderr, "\nPress ENTER"); + fflush( stderr ); + getchar(); + W_Shutdown(); + exit(-1); +} + + +// +// I_Quit : shutdown everything cleanly, in reverse order of Startup. +// +void I_Quit (void) +{ + UINT8 *endoom = NULL; + + //added:16-02-98: when recording a demo, should exit using 'q' key, + // but sometimes we forget and use 'F10'.. so save here too. + M_SaveConfig (NULL); //save game config, cvars.. +#ifndef NONET + D_SaveBan(); // save the ban list +#endif + G_SaveGameData(); // Tails 12-08-2002 + if (demorecording) + G_CheckDemoStatus(); + D_QuitNetGame (); + I_ShutdownMusic(); + I_ShutdownSound(); + I_ShutdownCD(); + I_ShutdownGraphics(); + I_ShutdownSystem(); + + if (W_CheckNumForName("ENDOOM")!=LUMPERROR) endoom = W_CacheLumpName("ENDOOM",PU_CACHE); + + + //added:03-01-98: maybe it needs that the ticcount continues, + // or something else that will be finished by ShutdownSystem() + // so I do it before. + + if (endoom) + { + puttext(1,1,80,25,endoom); + gotoxy(1,24); + Z_Free(endoom); + } + + if (shutdowning || errorcount) + I_Error("Error detected (%d)",errorcount); + + fflush(stderr); + W_Shutdown(); + exit(0); +} + + +//added:12-02-98: does want to work!!!! rhaaahahha +void I_WaitVBL(INT32 count) +{ + while (count-->0); + { + do { } while (inportb(0x3DA) & 8); + do { } while (!(inportb(0x3DA) & 8)); + } +} + +// Fab: this is probably to activate the 'loading' disc icon +// it should set a flag, that I_FinishUpdate uses to know +// whether it draws a small 'loading' disc icon on the screen or not +// +// also it should explicitly draw the disc because the screen is +// possibly not refreshed while loading +// +void I_BeginRead (void) +{ +} + +// Fab: see above, end the 'loading' disc icon, set the flag false +// +void I_EndRead (void) +{ +} + +#define MOUSE2 +/* Secondary Mouse*/ +#ifdef MOUSE2 +static _go32_dpmi_seginfo oldmouseinfo,newmouseinfo; +static boolean mouse2_started=0; +static UINT16 mouse2port; +static UINT8 mouse2irq; +static volatile int handlermouse2buttons; +static volatile int handlermouse2x,handlermouse2y; +// internal use +static volatile int bytenum; +static volatile UINT8 combytes[8]; + +// +// support a secondary mouse without mouse driver ! +// +// take from the PC-GPE by Mark Feldman +static void I_MicrosoftMouseIntHandler(void) +{ + char dx,dy; + UINT8 inbyte; + + // Get the port byte + inbyte = inportb(mouse2port); + + // Make sure we are properly "synched" + if ((inbyte & 64)== 64 || bytenum>7) + bytenum = 0; + + // Store the byte and adjust bytenum + combytes[bytenum] = inbyte; + bytenum++; + + // Have we received all 3 bytes? + if (bytenum==3) + { + // Yes, so process them + dx = ((combytes[0] & 3) << 6) + combytes[1]; + dy = ((combytes[0] & 12) << 4) + combytes[2]; + handlermouse2x+= dx; + handlermouse2y+= dy; + handlermouse2buttons = (combytes[0] & (32+16)) >>4; + } + else if (bytenum==4) // for logitech 3 buttons + { + if (combytes[3] & 32) + handlermouse2buttons |= 4; + else + handlermouse2buttons &= ~4; + } + + // Acknowledge the interrupt + outportb(0x20,0x20); +} +#ifndef DOXYGEN +static END_OF_FUNCTION(I_MicrosoftMouseIntHandler); +#endif + +// wait ms milliseconde +FUNCINLINE static ATTRINLINE void I_Delay(int ms) +{ + tic_t starttime; + + if (timer_started) + { + starttime=I_GetTime()+(NEWTICRATE*ms)/1000; + while (starttime>=I_GetTime()) + I_Sleep(); + } + else + delay(ms); +} + +// +// Removes the mouse2 handler. +// +static void I_ShutdownMouse2(void) +{ + event_t event; + int i; + + if ( !mouse2_started ) + return; + + outportb(mouse2port+4,0x00); // shutdown mouse (DTR & RTS = 0) + I_Delay(1); + outportb(mouse2port+1,0x00); // disable COM interuption + + asm("cli"); + _go32_dpmi_set_protected_mode_interrupt_vector(mouse2irq, &oldmouseinfo); + _go32_dpmi_free_iret_wrapper(&newmouseinfo); + asm("sti"); + + handlermouse2x=handlermouse2y=handlermouse2buttons=0; + // emulate the up of all mouse buttons + for (i=0;i= 0; i--) + { + joybuttons <<= 1; + if (joy[js].button[i].b) + joybuttons |= 1; + } + + for (i = JOYHATS_MIN -1; i >=0;) + { + if (joy[js].stick[s].flags & JOYFLAG_DIGITAL) + { + if (joy[js].stick[s].axis[1].d1) joyhats |= 1<<(0 + 4*i); + if (joy[js].stick[s].axis[1].d2) joyhats |= 1<<(1 + 4*i); + if (joy[js].stick[s].axis[0].d1) joyhats |= 1<<(2 + 4*i); + if (joy[js].stick[s].axis[0].d2) joyhats |= 1<<(3 + 4*i); + i--; + } + if (s == JOYHATS_MAX) i = -1; + s++; + } + + // post key event for buttons + if (joybuttons!=lastjoybuttons) + { + INT64 j = 1; // only changed bit to 1 + INT64 k = (joybuttons ^ lastjoybuttons); + lastjoybuttons=joybuttons; + + for (i=0;i=0;) + { + event.data1 = i; + event.data2 = event.data3 = 0; + if (joy[js].stick[s].flags & JOYFLAG_DIGITAL) + { + if (joy[js].stick[s].axis[0].d1) + event.data2=-1; + if (joy[js].stick[s].axis[0].d2) + event.data2=1; + if (joy[js].stick[s].axis[1].d1) + event.data3=-1; + if (joy[js].stick[s].axis[1].d2) + event.data3=1; + D_PostEvent(&event); + i++; + } + else if (joy[js].stick[s].flags & JOYFLAG_ANALOGUE) + { + event.data2 = joy[js].stick[s].axis[0].pos*32; + event.data3 = joy[js].stick[s].axis[1].pos*32; + D_PostEvent(&event); + i++; + } + if (s == JOYAXISSET_MAX*2) i = -1; + s++; + } +} + +void I_GetJoystick2Events(void) +{ + event_t event; + INT64 joybuttons= 0; + INT64 joyhats = 0; + int s = 0, i; + int js = cv_usejoystick2.value - 1; + + if (!joystick2_detected) + return; + + // I assume that true is 1 + for (i = JOYBUTTONS_MIN - 1; i >= 0; i--) + { + joybuttons <<= 1; + if (joy[js].button[i].b) + joybuttons |= 1; + } + + for (i = JOYHATS_MIN -1; i >=0;) + { + if (joy[js].stick[s].flags & JOYFLAG_DIGITAL) + { + if (joy[js].stick[s].axis[1].d1) joyhats |= 1<<(0 + 4*i); + if (joy[js].stick[s].axis[1].d2) joyhats |= 1<<(1 + 4*i); + if (joy[js].stick[s].axis[0].d1) joyhats |= 1<<(2 + 4*i); + if (joy[js].stick[s].axis[0].d2) joyhats |= 1<<(3 + 4*i); + i--; + } + if (s == JOYHATS_MAX) i = -1; + s++; + } + + // post key event for buttons + if (joybuttons!=lastjoy2buttons) + { + INT64 j = 1; // only changed bit to 1 + INT64 k = (joybuttons ^ lastjoy2buttons); + lastjoy2buttons=joybuttons; + + for (i=0;i=0;) + { + event.data1 = i; + event.data2 = event.data3 = 0; + if (joy[js].stick[s].flags & JOYFLAG_DIGITAL) + { + if (joy[js].stick[s].axis[0].d1) + event.data2=-1; + if (joy[js].stick[s].axis[0].d2) + event.data2=1; + if (joy[js].stick[s].axis[1].d1) + event.data3=-1; + if (joy[js].stick[s].axis[1].d2) + event.data3=1; + D_PostEvent(&event); + i++; + } + else if (joy[js].stick[s].flags & JOYFLAG_ANALOGUE) + { + event.data2 = joy[js].stick[s].axis[0].pos*32; + event.data3 = joy[js].stick[s].axis[1].pos*32; + D_PostEvent(&event); + i++; + } + if (s == JOYAXISSET_MAX*2) i = -1; + s++; + } +} + +void I_GetMouseEvents(void) +{ + //mouse movement + event_t event; + int xmickeys,ymickeys,buttons,wheels = 0; + static int lastbuttons=0; + __dpmi_regs r; + + if (!mouse_detected) + return; + + r.x.ax=0x0b; // ask the mouvement not the position + __dpmi_int(0x33,&r); + xmickeys=(INT16)r.x.cx; + ymickeys=(INT16)r.x.dx; + r.x.ax=0x03; + __dpmi_int(0x33,&r); + buttons=r.h.bl; + if (wheel_detected) + wheels=(signed char)r.h.bh; + + // post key event for buttons + if (buttons!=lastbuttons) + { + int j=1,k,i; + k=(buttons ^ lastbuttons); // only changed bit to 1 + lastbuttons=buttons; + + for (i=0;i 0) + event.data1 = KEY_MOUSEWHEELUP; + else if (wheels < 0) + event.data1 = KEY_MOUSEWHEELDOWN; + if (event.data1) + D_PostEvent(&event); + + + if ((xmickeys!=0)||(ymickeys!=0)) + { + event.type=ev_mouse; + event.data1=0; + //event.data1=buttons; // not needed + event.data2=xmickeys; + event.data3=-ymickeys; + + D_PostEvent(&event); + } + + //reset wheel like in win32, I don't understand it but works + gamekeydown[KEY_MOUSEWHEELDOWN] = gamekeydown[KEY_MOUSEWHEELUP] = 0; + +} + +void I_GetEvent (void) +{ +#ifdef MOUSE2 + // mouse may be disabled during the game by setting usemouse false + if (mouse2_started) + { + event_t event; + //mouse movement + static UINT8 lastbuttons2=0; + + // post key event for buttons + if (handlermouse2buttons!=lastbuttons2) + { + int j=1,k,i; + k=(handlermouse2buttons ^ lastbuttons2); // only changed bit to 1 + lastbuttons2=handlermouse2buttons; + + for (i=0;i 8 +"More Joystick Names?" +#endif + + if (joyindex == 1) return "Joystick A"; + else if (joyindex == 2) return "Joystick B"; + else if (joyindex == 3) return "Joystick C"; + else if (joyindex == 4) return "Joystick D"; + else if (joyindex == 5) return "Joystick E"; + else if (joyindex == 6) return "Joystick F"; + else if (joyindex == 7) return "Joystick G"; + else if (joyindex == 8) return "Joystick H"; + else return NULL; + +} + +// +// Timer user routine called at ticrate. +// +static void I_TimerISR (void) +{ + // IO_PlayerInput(); // old doom did that + ticcount++; + +} +#ifndef DOXYGEN +static END_OF_FUNCTION(I_TimerISR); +#endif + + +//added:08-01-98: we don't use allegro_exit() so we have to do it ourselves. +static inline void I_ShutdownTimer (void) +{ + if ( !timer_started ) + return; + remove_timer(); +} + + +// +// Installs the timer interrupt handler with timer speed as NEWTICRATE. +// +void I_StartupTimer(void) +{ + ticcount = 0; + + //lock this from being swapped to disk! BEFORE INSTALLING + LOCK_VARIABLE(ticcount); + LOCK_FUNCTION(I_TimerISR); + + if ( install_timer() != 0 ) + I_Error("I_StartupTimer: could not install timer."); + + if ( install_int_ex( I_TimerISR, BPS_TO_TIMER(NEWTICRATE) ) != 0 ) + //should never happen since we use only one. + I_Error("I_StartupTimer: no room for callback routine."); + + //added:08-01-98: remove the timer explicitly because we don't use + // Allegro 's allegro_exit() shutdown code. + I_AddExitFunc(I_ShutdownTimer); + timer_started = true; +} + + +//added:07-02-98: +// +// +static UINT8 ASCIINames[128] = +{ +// 0 1 2 3 +// 4 5 6 7 +// 8 9 A B +// C D E F + 0, 27, '1', '2', + '3', '4', '5', '6', + '7', '8', '9', '0', + KEY_MINUS, KEY_EQUALS, KEY_BACKSPACE, KEY_TAB, + 'q', 'w', 'e', 'r', + 't', 'y', 'u', 'i', + 'o', 'p', '[', ']', + KEY_ENTER, KEY_LCTRL, 'a', 's', + 'd', 'f', 'g', 'h', + 'j', 'k', 'l', ';', + '\'', '`', KEY_LSHIFT, '\\', + 'z', 'x', 'c', 'v', + 'b', 'n', 'm', ',', + '.', '/', KEY_RSHIFT, '*', + KEY_LALT, KEY_SPACE, KEY_CAPSLOCK, KEY_F1, + KEY_F2, KEY_F3, KEY_F4, KEY_F5, + KEY_F6, KEY_F7, KEY_F8, KEY_F9, + KEY_F10,KEY_NUMLOCK,KEY_SCROLLLOCK,KEY_KEYPAD7, +KEY_KEYPAD8,KEY_KEYPAD9, KEY_MINUSPAD,KEY_KEYPAD4, +KEY_KEYPAD5,KEY_KEYPAD6, KEY_PLUSPAD,KEY_KEYPAD1, +KEY_KEYPAD2,KEY_KEYPAD3, KEY_KEYPAD0,KEY_KPADDEL, + 0, 0, 0, KEY_F11, + KEY_F12, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0 +}; + +static volatile int pausepressed=0; +static volatile char nextkeyextended; + +static void I_KeyboardHandler(void) +{ + UINT8 ch; + event_t event; + + ch=inportb(0x60); + + if (pausepressed>0) + pausepressed--; + else if (ch==0xE1) // pause key + { + event.type=ev_keydown; + event.data1=KEY_PAUSE; + D_PostEvent(&event); + pausepressed=5; + } + else if (ch==0xE0) // extended key handled at next call + { + nextkeyextended=1; + } + else + { + if ((ch&0x80)==0) + event.type=ev_keydown; + else + event.type=ev_keyup; + + ch&=0x7f; + + if (nextkeyextended) + { + nextkeyextended=0; + + if (ch==70) // crtl-break + { + asm ("movb $0x79, %%al\ncall ___djgpp_hw_exception" + : : :"%eax","%ebx","%ecx","%edx","%esi","%edi","memory"); + } + + // remap lonely keypad slash + if (ch==53) + event.data1 = KEY_KPADSLASH; + else if (ch>=91 && ch<=93) // remap the bill gates keys... + event.data1 = ch + 0x80; // leftwin, rightwin, menu + else if (ch>=71 && ch<=83) // remap non-keypad extended keys to a value<128, but + event.data1 = 0x80 + ch + 30; // make them different than the KEYPAD keys. + else if (ch==28) + event.data1 = KEY_ENTER; // keypad enter -> return key + else if (ch==29) + event.data1 = KEY_RCTRL; // rctrl -> lctrl + else if (ch==56) + event.data1 = KEY_RALT; // ralt -> lalt + else + ch = 0; + if (ch) + D_PostEvent(&event); + } + else + { + if (ASCIINames[ch]!=0) + event.data1=ASCIINames[ch]; + else + event.data1=ch+0x80; + D_PostEvent(&event); + } + } + + outportb(0x20,0x20); +} +#ifndef DOXYGEN +static END_OF_FUNCTION(I_KeyboardHandler); +#endif + +// Return a key that has been pushed, or 0 +// (replace getchar() at game startup) +// +INT32 I_GetKey (void) +{ + int rc=0; + if ( keyboard_started ) + { + event_t *ev; + + // return the first keypress from the event queue + for ( ; eventtail != eventhead ; eventtail = (eventtail+1)&(MAXEVENTS-1) ) + { + ev = &events[eventtail]; + if (ev->type == ev_keydown || ev->type == ev_console) + { + rc = ev->data1; + continue; + } + } + return rc; + } + + // keyboard not started use the bios call trouth djgpp + if (_conio_kbhit()) + { + rc=getch(); + if (rc==0) rc=getch()+256; + } + else + rc = 0; + + return rc; +} + +/* Keyboard handler stuff */ +static _go32_dpmi_seginfo oldkeyinfo,newkeyinfo; + +// +// Removes the keyboard handler. +// +static inline void I_ShutdownKeyboard(void) +{ + if ( !keyboard_started ) + return; + + asm("cli"); + _go32_dpmi_set_protected_mode_interrupt_vector(9, &oldkeyinfo); + _go32_dpmi_free_iret_wrapper(&newkeyinfo); + asm("sti"); + + keyboard_started=false; +} + +// +// Installs the keyboard handler. +// +void I_StartupKeyboard(void) +{ + if (keyboard_started) + return; + + nextkeyextended=0; + + asm("cli"); + _go32_dpmi_get_protected_mode_interrupt_vector(9, &oldkeyinfo); + newkeyinfo.pm_offset=(int)I_KeyboardHandler; + newkeyinfo.pm_selector=_go32_my_cs(); + _go32_dpmi_allocate_iret_wrapper(&newkeyinfo); + _go32_dpmi_set_protected_mode_interrupt_vector(9, &newkeyinfo); + + LOCK_VARIABLE(nextkeyextended); + LOCK_VARIABLE(pausepressed); + _go32_dpmi_lock_data(ASCIINames,sizeof (ASCIINames)); + LOCK_FUNCTION(I_KeyboardHandler); + + _go32_dpmi_lock_data(events,sizeof (events)); + LOCK_VARIABLE(eventhead); + LOCK_FUNCTION(D_PostEvent); + + asm("sti"); + + //added:08-01-98:register shutdown keyboard code. + I_AddExitFunc(I_ShutdownKeyboard); + keyboard_started = true; +} + + + + +//added:08-01-98: +// +// Clean Startup & Shutdown handling, as does Allegro. +// We need this services for ourselves too, and we don't want to mix +// with Allegro, because someone might not use Allegro. +// (all 'exit' was renamed to 'quit') +// +#define MAX_QUIT_FUNCS 16 +static quitfuncptr quit_funcs[MAX_QUIT_FUNCS] = + { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }; + + +//added:08-01-98: +// +// Adds a function to the list that need to be called by I_SystemShutdown(). +// +void I_AddExitFunc(void (*func)()) +{ + int c; + + for (c=0; c=0; c--) + if (quit_funcs[c]) + (*quit_funcs[c])(); +} + +void I_GetDiskFreeSpace(INT64 *freespace) +{ + struct diskfree_t df; + if (_dos_getdiskfree(0,&df)) + *freespace = (unsigned long)df.avail_clusters * + (unsigned long)df.bytes_per_sector * + (unsigned long)df.sectors_per_cluster; + else + *freespace = INT32_MAX; +} + +char *I_GetUserName(void) +{ + static char username[MAXPLAYERNAME]; + char *p; + if ((p=getenv("USER"))==NULL) + if ((p=getenv("user"))==NULL) + if ((p=getenv("USERNAME"))==NULL) + if ((p=getenv("username"))==NULL) + return NULL; + strncpy(username,p,MAXPLAYERNAME); + + if (strcmp(username,"")==0 ) + return NULL; + return username; +} + +INT32 I_mkdir(const char *pdirname, INT32 unixright) +{ + return mkdir(pdirname, unixright); +} + +char * I_GetEnv(const char *name) +{ + return getenv(name); +} + +INT32 I_PutEnv(char *variable) +{ + return putenv(variable); +} + +const CPUInfoFlags *I_CPUInfo(void) +{ + static CPUInfoFlags DOS_CPUInfo; + memset(&DOS_CPUInfo,0,sizeof (DOS_CPUInfo)); +#if ALLEGRO_VERSION == 3 + if (!cpu_cpuid) return NULL; + DOS_CPUInfo.CPUID = true; + DOS_CPUInfo.MMX = cpu_mmx; + DOS_CPUInfo.AMD3DNow = cpu_3dnow; +#else + DOS_CPUInfo.CPUID = ((cpu_capabilities&CPU_ID) == CPU_ID); + DOS_CPUInfo.FPU = ((cpu_capabilities&CPU_FPU) == CPU_FPU); +#ifdef CPU_IA64 + DOS_CPUInfo.IA64 = ((cpu_capabilities&CPU_IA64) == CPU_IA64); +#endif +#ifdef CPU_AMD64 + DOS_CPUInfo.AMD64 = ((cpu_capabilities&CPU_AMD64) == CPU_AMD64); +#endif + DOS_CPUInfo.MMX = ((cpu_capabilities&CPU_MMX) == CPU_MMX); + DOS_CPUInfo.MMXExt = ((cpu_capabilities&CPU_MMXPLUS) == CPU_MMXPLUS); + DOS_CPUInfo.SSE = ((cpu_capabilities&CPU_SSE) == CPU_SSE); + DOS_CPUInfo.SSE2 = ((cpu_capabilities&CPU_SSE2) == CPU_SSE2); +#ifdef CPU_SEE3 + DOS_CPUInfo.SSE3 = ((cpu_capabilities&CPU_SSE3) == CPU_SSE3); +#endif + DOS_CPUInfo.AMD3DNow = ((cpu_capabilities&CPU_3DNOW) == CPU_3DNOW); + DOS_CPUInfo.AMD3DNowExt = ((cpu_capabilities&CPU_ENH3DNOW) == CPU_ENH3DNOW); + DOS_CPUInfo.CMOV = ((cpu_capabilities&CPU_CMOV) == CPU_CMOV); +#endif + return &DOS_CPUInfo; +} + +void I_RegisterSysCommands(void) {} diff --git a/src/djgppdos/i_video.c b/src/djgppdos/i_video.c new file mode 100644 index 000000000..612c72215 --- /dev/null +++ b/src/djgppdos/i_video.c @@ -0,0 +1,333 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright (C) 1993-1996 by id Software, Inc. +// Portions Copyright (C) 1998-2000 by DooM Legacy Team. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +//----------------------------------------------------------------------------- +/// \file +/// \brief hardware and software level, screen and video i/o, refresh, +/// setup ... a big mess. Got to clean that up! + +#include +#include +#include +#include +#include +//#include + +#include +//#include +#include + +#include +#include +#include +#include +#include + +#include "../doomdef.h" +#include "../i_system.h" +#include "../v_video.h" +#include "../m_argv.h" +#include "vid_vesa.h" +#include "../i_video.h" + + +//dosstuff -newly added +static unsigned long dascreen; +static int gfx_use_vesa1; + +boolean highcolor; + +#define SCREENDEPTH 1 // bytes per pixel, do NOT change. + +rendermode_t rendermode=render_soft; + +// +// I_OsPolling +// +void I_OsPolling(void) +{ + I_GetEvent(); + //i dont think i have to do anything else here +} + + +// +// I_UpdateNoBlit +// +void I_UpdateNoBlit (void) +{ + // what is this? +} + + +//profile stuff --------------------------------------------------------- +//added:16-01-98:wanted to profile the VID_BlitLinearScreen() asm code. +//#define TIMING //uncomment this to enable profiling +#ifdef TIMING +#include "../p5prof.h" +static INT64 mycount; +static INT64 mytotal = 0; +static unsigned long nombre = NEWTICRATE*10; +//static char runtest[10][80]; +#endif +//profile stuff --------------------------------------------------------- + +// +// I_FinishUpdate +// +static void I_BlitScreenVesa1(void); //see later +void I_FinishUpdate (void) +{ + // draw FPS if enabled + if (cv_ticrate.value) + SCR_DisplayTicRate(); + + //blast it to the screen + // this code sucks + //memcpy(dascreen,screens[0],screenwidth*screenheight); + + //added:03-01-98: I tried to I_WaitVBL(1) here, but it slows down + // the game when the view becomes complicated, it looses ticks + if (cv_vidwait.value) + I_WaitVBL(1); + + +//added:16-01-98:profile screen blit. +#ifdef TIMING + ProfZeroTimer(); +#endif + //added:08-01-98: support vesa1 bank change, without Allegro's BITMAP screen. + if ( gfx_use_vesa1 ) + { + I_Error("Banked screen update not finished for dynamic res\n"); + I_BlitScreenVesa1(); //blast virtual to physical screen. + } + else + { + //added:16-01-98:use quickie asm routine, last 2 args are + // src and dest rowbytes + // (memcpy is as fast as this one...) + VID_BlitLinearScreen(screens[0], vid.direct, + vid.width*vid.bpp, vid.height, + vid.width*vid.bpp, vid.rowbytes ); + } +#ifdef TIMING + RDMSR(0x10,&mycount); + mytotal += mycount; //64bit add + + if (nombre--==0) + I_Error("ScreenBlit CPU Spy reports: 0x%d %d\n", *((int *)&mytotal+1), + (int)mytotal ); +#endif + +} + +// +// I_UpdateNoVsync +// +void I_UpdateNoVsync(void) +{ + int real_vidwait = cv_vidwait.value; + cv_vidwait.value = 0; + I_FinishUpdate(); + cv_vidwait.value = real_vidwait; +} + +// +// I_ReadScreen +// +void I_ReadScreen (UINT8 *scr) +{ + VID_BlitLinearScreen(screens[0], scr, + vid.width*vid.bpp, vid.height, + vid.width*vid.bpp, vid.rowbytes ); +} + + +void I_SetPalette (RGBA_t *palette) +{ + int i; + + outportb(0x3c8,0); + for (i=0;i<256;i++,palette++) + { + outportb(0x3c9,palette->s.red>>2); + outportb(0x3c9,palette->s.green>>2); + outportb(0x3c9,palette->s.blue>>2); + } +} + + +//added 29-12-1997 +/*==========================================================================*/ +// I_BlastScreen : copy the virtual screen buffer to the physical screen mem +// using bank switching if needed. +/*==========================================================================*/ +static void I_BlitScreenVesa1(void) +{ +#define VIDBANKSIZE (1<<16) +#define VIDBANKSIZEMASK (VIDBANKSIZE-1) // defines ahoy! + + __dpmi_regs r; + UINT8 *p_src; + long i; + long virtualsize; + + // virtual screen buffer size + virtualsize = vid.rowbytes * vid.height * SCREENDEPTH; + + p_src = screens[0]; + + for (i=0; virtualsize > 0; i++ ) + { + r.x.ax = 0x4f05; + r.x.bx = 0x0; + r.x.cx = 0x0; + r.x.dx = i; + __dpmi_int(0x10,&r); //set bank + + M_Memcpy((UINT8 *)dascreen,p_src,(virtualsize < VIDBANKSIZE) ? virtualsize : VIDBANKSIZE ); + + p_src += VIDBANKSIZE; + virtualsize -= VIDBANKSIZE; + } + +} + + +//added:08-01-98: now we use Allegro's set_gfx_mode, but we want to +// restore the exact text mode that was before. +static INT16 myOldVideoMode; +static inline void I_SaveOldVideoMode(void) +{ + __dpmi_regs r; + r.x.ax = 0x4f03; // Return current video mode + __dpmi_int(0x10,&r); + if ( r.x.ax != 0x4f ) + myOldVideoMode = -1; + else + myOldVideoMode = r.x.bx; +} + + +// +// Close the screen, restore previous video mode. +// +void I_ShutdownGraphics (void) +{ + __dpmi_regs r; + + rendermode = render_none; + if ( !graphics_started ) + return; + + // free the last video mode screen buffers + if (vid.buffer) + free (vid.buffer); + + /* Restore old video mode */ + if (myOldVideoMode!=-1) + { + /* Restore old video mode */ + r.x.ax = 0x4f02; // Set Super VGA video mode + r.x.bx = myOldVideoMode; + __dpmi_int(0x10,&r); + + // Boris: my s3 don't do a cls because "win95" :< + clrscr(); + } + else // no vesa put the normal video mode + { + r.x.ax = 0x03; + __dpmi_int(0x10,&r); + } + + graphics_started = false; +} + + +//added:08-01-98: +// Set VESA1 video mode, coz Allegro set_gfx_mode a larger screenwidth... +// +#if 0 +int set_vesa1_mode( int width, int height ) +{ + __dpmi_regs r; + + // setup video mode. + r.x.ax = 0x4f02; + if ( ( width==320 )&&( height==200 ) && ( SCREENDEPTH==1 ) ) + r.x.bx = 0x13; // 320x 200x1 (256 colors) + else + if ( ( width==320 )&&( height==240 ) && ( SCREENDEPTH==1 ) ) + r.x.bx = 0x154; // 320x 240x1 (256 colors) + else + if ( ( width==320 )&&( height==400 ) && ( SCREENDEPTH==1 ) ) + r.x.bx = 0x155; // 320x 400x1 (256 colors) + else + if ( ( width==640 )&&( height==400 ) && ( SCREENDEPTH==1 ) ) + r.x.bx = 0x100; // 640x 400x1 (256 colors) + else + if ( ( width==640 )&&( height==480 ) && ( SCREENDEPTH==1 ) ) + r.x.bx = 0x101; // 640x 480x1 (256 colors) + else + if ( ( width==800 )&&( height==600 ) && ( SCREENDEPTH==1 ) ) + r.x.bx = 0x103; // 800x 600x1 (256 colors) + else + if ( ( width==1024)&&( height==768 ) && ( SCREENDEPTH==1 ) ) + r.x.bx = 0x105; //1024x 768x1 (256 colors) + else + I_Error("I_SetVesa1Mode: video mode not supported."); + + // enter graphics mode. + __dpmi_int(0x10,&r); + + if ( r.x.ax != 0x4f ) + I_Error("I_SetVesa1Mode: init video mode failed !"); + + return 0; +} +#endif + + +//added:08-01-98: now uses Allegro to setup Linear Frame Buffer video modes. +// +// Initialize video mode, setup dynamic screen size variables, +// and allocate screens. +// +void I_StartupGraphics(void) +{ + //added:26-01-98: VID_Init() must be done only once, + // use VID_SetMode() to change vid mode while in the game. + if ( graphics_started ) + return; + + // remember the exact screen mode we were... + I_SaveOldVideoMode(); + + CONS_Printf("Vid_Init..."); + + // 0 for 256 color, else use highcolor modes + highcolor = M_CheckParm ("-highcolor"); + + VID_Init(); + + //gfx_use_vesa1 = false; + + //added:03-01-98: register exit code for graphics + I_AddExitFunc(I_ShutdownGraphics); + graphics_started = true; + +} diff --git a/src/djgppdos/internal.h b/src/djgppdos/internal.h new file mode 100644 index 000000000..94c1a052b --- /dev/null +++ b/src/djgppdos/internal.h @@ -0,0 +1,773 @@ +/* ______ ___ ___ + * /\ _ \ /\_ \ /\_ \ + * \ \ \L\ \\//\ \ \//\ \ __ __ _ __ ___ + * \ \ __ \ \ \ \ \ \ \ /'__`\ /'_ `\/\`'__\/ __`\ + * \ \ \/\ \ \_\ \_ \_\ \_/\ __//\ \L\ \ \ \//\ \L\ \ + * \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/ + * \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/ + * /\____/ + * \_/__/ + * + * Some definitions for internal use by the library code. + * This should not be included by user programs. + * + * By Shawn Hargreaves. + * + * See readme.txt for copyright information. + */ + + +#ifndef INTERNAL_H +#define INTERNAL_H + +#include "allegro.h" + +/* ______ ___ ___ + * /\ _ \ /\_ \ /\_ \ + * \ \ \L\ \\//\ \ \//\ \ __ __ _ __ ___ + * \ \ __ \ \ \ \ \ \ \ /'__`\ /'_ `\/\`'__\/ __`\ + * \ \ \/\ \ \_\ \_ \_\ \_/\ __//\ \L\ \ \ \//\ \L\ \ + * \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/ + * \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/ + * /\____/ + * \_/__/ + * + * Some definitions for internal use by the library code. + * This should not be included by user programs. + * + * By Shawn Hargreaves. + * + * See readme.txt for copyright information. + */ + + +#ifndef INTERNDJ_H +#define INTERNDJ_H + +#ifndef DJGPP +#error This file should only be used by the djgpp version of Allegro +#endif + + +#include + + +/* file access macros */ +#define FILE_OPEN(filename, handle) handle = open(filename, O_RDONLY | O_BINARY, S_IRUSR | S_IWUSR) +#define FILE_CREATE(filename, handle) handle = open(filename, O_WRONLY | O_BINARY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR) +#define FILE_CLOSE(handle) close(handle) +#define FILE_READ(handle, buf, size, sz) sz = read(handle, buf, size) +#define FILE_WRITE(handle, buf, size, sz) sz = write(handle, buf, size) +#define FILE_SEARCH_STRUCT struct ffblk +#define FILE_FINDFIRST(filename, attrib, dta) findfirst(filename, dta, attrib) +#define FILE_FINDNEXT(dta) findnext(dta) +#define FILE_ATTRIB ff_attrib +#define FILE_SIZE ff_fsize +#define FILE_NAME ff_name +#define FILE_TIME ff_ftime +#define FILE_DATE ff_fdate + + +/* macros to enable and disable interrupts */ +#define DISABLE() asm volatile ("cli") +#define ENABLE() asm volatile ("sti") + + +__INLINE__ void enter_critical(void) +{ + if (windows_version >= 3) { + __dpmi_regs r; + r.x.ax = 0x1681; + __dpmi_int(0x2F, &r); + } + + DISABLE(); +} + + +__INLINE__ void exit_critical(void) +{ + if (windows_version >= 3) { + __dpmi_regs r; + r.x.ax = 0x1682; + __dpmi_int(0x2F, &r); + } + + ENABLE(); +} + + +/* interrupt hander stuff */ +#define _map_irq(irq) (((irq)>7) ? ((irq)+104) : ((irq)+8)) + +int _install_irq(int num, int (*handler)(void)); +void _remove_irq(int num); +void _restore_irq(int irq); +void _enable_irq(int irq); +void _disable_irq(int irq); + +#define _eoi(irq) { outportb(0x20, 0x20); if ((irq)>7) outportb(0xA0, 0x20); } + +typedef struct _IRQ_HANDLER +{ + int (*handler)(void); /* our C handler */ + int number; /* irq number */ + __dpmi_paddr old_vector; /* original protected mode vector */ +} _IRQ_HANDLER; + + +/* DPMI memory mapping routines */ +int _create_physical_mapping(unsigned long *linear, int *segment, unsigned long physaddr, int size); +void _remove_physical_mapping(unsigned long *linear, int *segment); +int _create_linear_mapping(unsigned long *linear, unsigned long physaddr, int size); +void _remove_linear_mapping(unsigned long *linear); +int _create_selector(int *segment, unsigned long linear, int size); +void _remove_selector(int *segment); +void _unlock_dpmi_data(void *addr, int size); + + +/* bank switching routines */ +void _accel_bank_stub(void); +void _accel_bank_stub_end(void); + +void _accel_bank_switch (void); +void _accel_bank_switch_end(void); + +void _vesa_window_1(void); +void _vesa_window_1_end(void); +void _vesa_window_2(void); +void _vesa_window_2_end(void); + +void _vesa_pm_window_1(void); +void _vesa_pm_window_1_end(void); +void _vesa_pm_window_2(void); +void _vesa_pm_window_2_end(void); + +void _vesa_pm_es_window_1(void); +void _vesa_pm_es_window_1_end(void); +void _vesa_pm_es_window_2(void); +void _vesa_pm_es_window_2_end(void); + + +/* stuff for the VESA and VBE/AF drivers */ +extern __dpmi_regs _dpmi_reg; + +extern int _window_2_offset; + +extern void (*_pm_vesa_switcher)(void); +extern void (*_pm_vesa_scroller)(void); +extern void (*_pm_vesa_pallete)(void); + +extern int _mmio_segment; + +extern void *_accel_driver; + +extern int _accel_active; + +extern void *_accel_set_bank; +extern void *_accel_idle; + +void _fill_vbeaf_libc_exports(void *ptr); +void _fill_vbeaf_pmode_exports(void *ptr); + + +/* sound lib stuff */ +extern int _fm_port; +extern int _mpu_port; +extern int _mpu_irq; +extern int _sb_freq; +extern int _sb_port; +extern int _sb_dma; +extern int _sb_irq; + +int _sb_read_dsp_version(void); +int _sb_reset_dsp(int data); +void _sb_voice(int state); +int _sb_set_mixer(int digi_volume, int midi_volume); + +void _mpu_poll(void); + +int _dma_allocate_mem(int bytes, int *sel, unsigned long *phys); +void _dma_start(int channel, unsigned long addr, int size, int auto_init, int input); +void _dma_stop(int channel); +unsigned long _dma_todo(int channel); +void _dma_lock_mem(void); + + +#endif /* ifndef INTERNDJ_H */ + + +/* flag for how many times we have been initialised */ +extern int _allegro_count; + + +/* some Allegro functions need a block of scratch memory */ +extern void *_scratch_mem; +extern int _scratch_mem_size; + +__INLINE__ void _grow_scratch_mem(int size) +{ + if (size > _scratch_mem_size) { + size = (size+1023) & 0xFFFFFC00; + _scratch_mem = realloc(_scratch_mem, size); + _scratch_mem_size = size; + } +} + + +/* list of functions to call at program cleanup */ +void _add_exit_func(void (*func)(void)); +void _remove_exit_func(void (*func)(void)); + + +/* reads a translation file into memory */ +void _load_config_text(void); + + +/* various bits of mouse stuff */ +void _set_mouse_range(void); +extern BITMAP *_mouse_screen; +extern BITMAP *_mouse_sprite, *_mouse_pointer; +extern int _mouse_x_focus, _mouse_y_focus; +extern int _mouse_width, _mouse_height; + + +/* various bits of timer stuff */ +extern int _timer_use_retrace; +extern volatile int _retrace_hpp_value; + + +/* caches and tables for svga bank switching */ +extern int _last_bank_1, _last_bank_2; +extern int *_gfx_bank; + + +/* bank switching routines */ +void _stub_bank_switch (void); +void _stub_bank_switch_end(void); + + +/* stuff for setting up bitmaps */ +void _check_gfx_virginity(void); +BITMAP *_make_bitmap(int w, int h, unsigned long addr, GFX_DRIVER *driver, int color_depth, int bpl); +void _sort_out_virtual_width(int *width, GFX_DRIVER *driver); + +GFX_VTABLE *_get_vtable(int color_depth); + +extern GFX_VTABLE _screen_vtable; + +extern int _sub_bitmap_id_count; + +extern int _textmode; + +#define BYTES_PER_PIXEL(bpp) (((int)(bpp) + 7) / 8) + +int _color_load_depth(int depth); + +extern int _color_conv; + +BITMAP *_fixup_loaded_bitmap(BITMAP *bmp, PALETTE pal, int bpp); + + +/* VGA register access routines */ +void _vga_vsync(void); +void _vga_set_pallete_range(PALLETE p, int from, int to, int vsync); + +extern int _crtc; + + +/* _read_vga_register: + * Reads the contents of a VGA register. + */ +__INLINE__ int _read_vga_register(int port, int index) +{ + if (port==0x3C0) + inportb(_crtc+6); + + outportb(port, index); + return inportb(port+1); +} + + +/* _write_vga_register: + * Writes a byte to a VGA register. + */ +__INLINE__ void _write_vga_register(int port, int index, int v) +{ + if (port==0x3C0) { + inportb(_crtc+6); + outportb(port, index); + outportb(port, v); + } + else { + outportb(port, index); + outportb(port+1, v); + } +} + + +/* _alter_vga_register: + * Alters specific bits of a VGA register. + */ +__INLINE__ void _alter_vga_register(int port, int index, int mask, int v) +{ + int temp; + temp = _read_vga_register(port, index); + temp &= (~mask); + temp |= (v & mask); + _write_vga_register(port, index, temp); +} + + +/* _vsync_out_h: + * Waits until the VGA is not in either a vertical or horizontal retrace. + */ +__INLINE__ void _vsync_out_h(void) +{ + do { + } while (inportb(0x3DA) & 1); +} + + +/* _vsync_out_v: + * Waits until the VGA is not in a vertical retrace. + */ +__INLINE__ void _vsync_out_v(void) +{ + do { + } while (inportb(0x3DA) & 8); +} + + +/* _vsync_in: + * Waits until the VGA is in the vertical retrace period. + */ +__INLINE__ void _vsync_in(void) +{ + if (_timer_use_retrace) { + int t = retrace_count; + + do { + } while (t == retrace_count); + } + else { + do { + } while (!(inportb(0x3DA) & 8)); + } +} + + +/* _write_hpp: + * Writes to the VGA pelpan register. + */ +__INLINE__ void _write_hpp(int value) +{ + if (_timer_use_retrace) { + _retrace_hpp_value = value; + + do { + } while (_retrace_hpp_value == value); + } + else { + do { + } while (!(inportb(0x3DA) & 8)); + + _write_vga_register(0x3C0, 0x33, value); + } +} + + +void _set_vga_virtual_width(int old_width, int new_width); + + +/* current drawing mode */ +extern int _drawing_mode; +extern BITMAP *_drawing_pattern; +extern int _drawing_x_anchor; +extern int _drawing_y_anchor; +extern unsigned int _drawing_x_mask; +extern unsigned int _drawing_y_mask; + + +/* graphics drawing routines */ +void _normal_line(BITMAP *bmp, int x1, int y1, int x2, int y2, int color); +void _normal_rectfill(BITMAP *bmp, int x1, int y1, int x2, int y2, int color); + +int _linear_getpixel8(struct BITMAP *bmp, int x, int y); +void _linear_putpixel8(struct BITMAP *bmp, int x, int y, int color); +void _linear_vline8(struct BITMAP *bmp, int x, int y1, int y2, int color); +void _linear_hline8(struct BITMAP *bmp, int x1, int y, int x2, int color); +void _linear_draw_sprite8(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); +void _linear_draw_sprite_v_flip8(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); +void _linear_draw_sprite_h_flip8(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); +void _linear_draw_sprite_vh_flip8(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); +void _linear_draw_trans_sprite8(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); +void _linear_draw_lit_sprite8(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int color); +void _linear_draw_rle_sprite8(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y); +void _linear_draw_trans_rle_sprite8(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y); +void _linear_draw_lit_rle_sprite8(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y, int color); +void _linear_draw_character8(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int color); +void _linear_textout_fixed8(struct BITMAP *bmp, void *f, int h, unsigned char *str, int x, int y, int color); +void _linear_blit8(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); +void _linear_blit_backward8(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); +void _linear_masked_blit8(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); +void _linear_clear_to_color8(struct BITMAP *bitmap, int color); + +#ifdef ALLEGRO_COLOR16 + +void _linear_putpixel15(struct BITMAP *bmp, int x, int y, int color); +void _linear_vline15(struct BITMAP *bmp, int x, int y1, int y2, int color); +void _linear_hline15(struct BITMAP *bmp, int x1, int y, int x2, int color); +void _linear_draw_trans_sprite15(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); +void _linear_draw_lit_sprite15(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int color); +void _linear_draw_rle_sprite15(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y); +void _linear_draw_trans_rle_sprite15(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y); +void _linear_draw_lit_rle_sprite15(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y, int color); + +int _linear_getpixel16(struct BITMAP *bmp, int x, int y); +void _linear_putpixel16(struct BITMAP *bmp, int x, int y, int color); +void _linear_vline16(struct BITMAP *bmp, int x, int y1, int y2, int color); +void _linear_hline16(struct BITMAP *bmp, int x1, int y, int x2, int color); +void _linear_draw_sprite16(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); +void _linear_draw_256_sprite16(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); +void _linear_draw_sprite_v_flip16(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); +void _linear_draw_sprite_h_flip16(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); +void _linear_draw_sprite_vh_flip16(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); +void _linear_draw_trans_sprite16(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); +void _linear_draw_lit_sprite16(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int color); +void _linear_draw_rle_sprite16(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y); +void _linear_draw_trans_rle_sprite16(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y); +void _linear_draw_lit_rle_sprite16(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y, int color); +void _linear_draw_character16(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int color); +void _linear_textout_fixed16(struct BITMAP *bmp, void *f, int h, unsigned char *str, int x, int y, int color); +void _linear_blit16(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); +void _linear_blit_backward16(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); +void _linear_masked_blit16(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); +void _linear_clear_to_color16(struct BITMAP *bitmap, int color); + +#endif + +#ifdef ALLEGRO_COLOR24 + +int _linear_getpixel24(struct BITMAP *bmp, int x, int y); +void _linear_putpixel24(struct BITMAP *bmp, int x, int y, int color); +void _linear_vline24(struct BITMAP *bmp, int x, int y1, int y2, int color); +void _linear_hline24(struct BITMAP *bmp, int x1, int y, int x2, int color); +void _linear_draw_sprite24(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); +void _linear_draw_256_sprite24(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); +void _linear_draw_sprite_v_flip24(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); +void _linear_draw_sprite_h_flip24(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); +void _linear_draw_sprite_vh_flip24(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); +void _linear_draw_trans_sprite24(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); +void _linear_draw_lit_sprite24(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int color); +void _linear_draw_rle_sprite24(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y); +void _linear_draw_trans_rle_sprite24(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y); +void _linear_draw_lit_rle_sprite24(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y, int color); +void _linear_draw_character24(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int color); +void _linear_textout_fixed24(struct BITMAP *bmp, void *f, int h, unsigned char *str, int x, int y, int color); +void _linear_blit24(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); +void _linear_blit_backward24(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); +void _linear_masked_blit24(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); +void _linear_clear_to_color24(struct BITMAP *bitmap, int color); + +#endif + +#ifdef ALLEGRO_COLOR32 + +int _linear_getpixel32(struct BITMAP *bmp, int x, int y); +void _linear_putpixel32(struct BITMAP *bmp, int x, int y, int color); +void _linear_vline32(struct BITMAP *bmp, int x, int y1, int y2, int color); +void _linear_hline32(struct BITMAP *bmp, int x1, int y, int x2, int color); +void _linear_draw_sprite32(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); +void _linear_draw_256_sprite32(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); +void _linear_draw_sprite_v_flip32(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); +void _linear_draw_sprite_h_flip32(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); +void _linear_draw_sprite_vh_flip32(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); +void _linear_draw_trans_sprite32(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); +void _linear_draw_lit_sprite32(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int color); +void _linear_draw_rle_sprite32(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y); +void _linear_draw_trans_rle_sprite32(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y); +void _linear_draw_lit_rle_sprite32(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y, int color); +void _linear_draw_character32(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int color); +void _linear_textout_fixed32(struct BITMAP *bmp, void *f, int h, unsigned char *str, int x, int y, int color); +void _linear_blit32(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); +void _linear_blit_backward32(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); +void _linear_masked_blit32(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); +void _linear_clear_to_color32(struct BITMAP *bitmap, int color); + +#endif + +int _x_getpixel(struct BITMAP *bmp, int x, int y); +void _x_putpixel(struct BITMAP *bmp, int x, int y, int color); +void _x_vline(struct BITMAP *bmp, int x, int y1, int y2, int color); +void _x_hline(struct BITMAP *bmp, int x1, int y, int x2, int color); +void _x_draw_sprite(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); +void _x_draw_sprite_v_flip(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); +void _x_draw_sprite_h_flip(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); +void _x_draw_sprite_vh_flip(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); +void _x_draw_trans_sprite(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); +void _x_draw_lit_sprite(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int color); +void _x_draw_rle_sprite(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y); +void _x_draw_trans_rle_sprite(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y); +void _x_draw_lit_rle_sprite(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y, int color); +void _x_draw_character(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int color); +void _x_textout_fixed(struct BITMAP *bmp, void *f, int h, unsigned char *str, int x, int y, int color); +void _x_blit_from_memory(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); +void _x_blit_to_memory(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); +void _x_blit(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); +void _x_blit_forward(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); +void _x_blit_backward(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); +void _x_masked_blit(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); +void _x_clear_to_color(struct BITMAP *bitmap, int color); + + +/* asm helper for stretch_blit() */ +void _do_stretch(BITMAP *source, BITMAP *dest, void *drawer, int sx, fixed sy, fixed syd, int dx, int dy, int dh, int color_depth); + + +/* number of fractional bits used by the polygon rasteriser */ +#define POLYGON_FIX_SHIFT 18 + + +/* bitfield specifying which polygon attributes need interpolating */ +#define INTERP_FLAT 1 +#define INTERP_1COL 2 +#define INTERP_3COL 4 +#define INTERP_FIX_UV 8 +#define INTERP_Z 16 +#define INTERP_FLOAT_UV 32 +#define OPT_FLOAT_UV_TO_FIX 64 +#define COLOR_TO_RGB 128 + + +/* information for polygon scanline fillers */ +typedef struct POLYGON_SEGMENT +{ + fixed u, v, du, dv; /* fixed point u/v coordinates */ + fixed c, dc; /* single color gouraud shade values */ + fixed r, g, b, dr, dg, db; /* RGB gouraud shade values */ + float z, dz; /* polygon depth (1/z) */ + float fu, fv, dfu, dfv; /* floating point u/v coordinates */ + unsigned char *texture; /* the texture map */ + int umask, vmask, vshift; /* texture map size information */ + int seg; /* destination bitmap selector */ +} POLYGON_SEGMENT; + + +/* an active polygon edge */ +typedef struct POLYGON_EDGE +{ + int top; /* top y position */ + int bottom; /* bottom y position */ + fixed x, dx; /* fixed point x position and gradient */ + fixed w; /* width of line segment */ + POLYGON_SEGMENT dat; /* texture/gouraud information */ + struct POLYGON_EDGE *prev; /* doubly linked list */ + struct POLYGON_EDGE *next; +} POLYGON_EDGE; + + +/* prototype for the scanline filler functions */ +typedef void (*SCANLINE_FILLER)(unsigned long addr, int w, POLYGON_SEGMENT *info); + + +/* polygon helper functions */ +extern SCANLINE_FILLER _optim_alternative_drawer; +POLYGON_EDGE *_add_edge(POLYGON_EDGE *list, POLYGON_EDGE *edge, int sort_by_x); +POLYGON_EDGE *_remove_edge(POLYGON_EDGE *list, POLYGON_EDGE *edge); +void _fill_3d_edge_structure(POLYGON_EDGE *edge, V3D *v1, V3D *v2, int flags, BITMAP *bmp); +void _fill_3d_edge_structure_f(POLYGON_EDGE *edge, V3D_f *v1, V3D_f *v2, int flags, BITMAP *bmp); +SCANLINE_FILLER _get_scanline_filler(int type, int *flags, POLYGON_SEGMENT *info, BITMAP *texture, BITMAP *bmp); +void _clip_polygon_segment(POLYGON_SEGMENT *info, int gap, int flags); + + +/* polygon scanline filler functions */ +void _poly_scanline_gcol8(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_grgb8(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_atex8(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_ptex8(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_atex_mask8(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_ptex_mask8(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_atex_lit8(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_ptex_lit8(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_atex_mask_lit8(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_ptex_mask_lit8(unsigned long addr, int w, POLYGON_SEGMENT *info); + +void _poly_scanline_grgb8x(unsigned long addr, int w, POLYGON_SEGMENT *info); + +void _poly_scanline_grgb15(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_atex_mask15(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_ptex_mask15(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_atex_lit15(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_ptex_lit15(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_atex_mask_lit15(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_ptex_mask_lit15(unsigned long addr, int w, POLYGON_SEGMENT *info); + +void _poly_scanline_grgb15x(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_atex_lit15x(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_ptex_lit15x(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_atex_mask_lit15x(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_ptex_mask_lit15x(unsigned long addr, int w, POLYGON_SEGMENT *info); + +void _poly_scanline_ptex_lit15d(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_ptex_mask_lit15d(unsigned long addr, int w, POLYGON_SEGMENT *info); + +void _poly_scanline_grgb16(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_atex16(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_ptex16(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_atex_mask16(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_ptex_mask16(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_atex_lit16(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_ptex_lit16(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_atex_mask_lit16(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_ptex_mask_lit16(unsigned long addr, int w, POLYGON_SEGMENT *info); + +void _poly_scanline_grgb16x(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_atex_lit16x(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_ptex_lit16x(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_atex_mask_lit16x(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_ptex_mask_lit16x(unsigned long addr, int w, POLYGON_SEGMENT *info); + +void _poly_scanline_ptex_lit16d(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_ptex_mask_lit16d(unsigned long addr, int w, POLYGON_SEGMENT *info); + +void _poly_scanline_grgb24(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_atex24(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_ptex24(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_atex_mask24(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_ptex_mask24(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_atex_lit24(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_ptex_lit24(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_atex_mask_lit24(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_ptex_mask_lit24(unsigned long addr, int w, POLYGON_SEGMENT *info); + +void _poly_scanline_grgb24x(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_atex_lit24x(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_ptex_lit24x(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_atex_mask_lit24x(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_ptex_mask_lit24x(unsigned long addr, int w, POLYGON_SEGMENT *info); + +void _poly_scanline_ptex_lit24d(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_ptex_mask_lit24d(unsigned long addr, int w, POLYGON_SEGMENT *info); + +void _poly_scanline_grgb32(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_atex32(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_ptex32(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_atex_mask32(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_ptex_mask32(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_atex_lit32(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_ptex_lit32(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_atex_mask_lit32(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_ptex_mask_lit32(unsigned long addr, int w, POLYGON_SEGMENT *info); + +void _poly_scanline_grgb32x(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_atex_lit32x(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_ptex_lit32x(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_atex_mask_lit32x(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_ptex_mask_lit32x(unsigned long addr, int w, POLYGON_SEGMENT *info); + +void _poly_scanline_ptex_lit32d(unsigned long addr, int w, POLYGON_SEGMENT *info); +void _poly_scanline_ptex_mask_lit32d(unsigned long addr, int w, POLYGON_SEGMENT *info); + + +/* sound lib stuff */ +extern int _digi_volume; +extern int _midi_volume; +extern int _flip_pan; +extern int _sound_hq; + +extern int (*_midi_init)(void); +extern void (*_midi_exit)(void); + +int _midi_allocate_voice(int min, int max); + +extern volatile long _midi_tick; + +int _digmid_find_patches(char *dir, char *file); + +#define VIRTUAL_VOICES 256 + + +typedef struct /* a virtual (as seen by the user) soundcard voice */ +{ + SAMPLE *sample; /* which sample are we playing? (NULL = free) */ + int num; /* physical voice number (-1 = been killed off) */ + int autokill; /* set to free the voice when the sample finishes */ + long time; /* when we were started (for voice allocation) */ + int priority; /* how important are we? */ +} VOICE; + +extern VOICE _voice[VIRTUAL_VOICES]; + + +typedef struct /* a physical (as used by hardware) soundcard voice */ +{ + int num; /* the virtual voice currently using me (-1 = free) */ + int playmode; /* are we looping? */ + int vol; /* current volume (fixed point .12) */ + int dvol; /* volume delta, for ramping */ + int target_vol; /* target volume, for ramping */ + int pan; /* current pan (fixed point .12) */ + int dpan; /* pan delta, for sweeps */ + int target_pan; /* target pan, for sweeps */ + int freq; /* current frequency (fixed point .12) */ + int dfreq; /* frequency delta, for sweeps */ + int target_freq; /* target frequency, for sweeps */ +} PHYS_VOICE; + +extern PHYS_VOICE _phys_voice[DIGI_VOICES]; + + +#define MIXER_DEF_SFX 8 +#define MIXER_MAX_SFX 64 + +int _mixer_init(int bufsize, int freq, int stereo, int is16bit, int *voices); +void _mixer_exit(void); +void _mix_some_samples(unsigned long buf, unsigned short seg, int issigned); + +void _mixer_init_voice(int voice, SAMPLE *sample); +void _mixer_release_voice(int voice); +void _mixer_start_voice(int voice); +void _mixer_stop_voice(int voice); +void _mixer_loop_voice(int voice, int loopmode); +int _mixer_get_position(int voice); +void _mixer_set_position(int voice, int position); +int _mixer_get_volume(int voice); +void _mixer_set_volume(int voice, int volume); +void _mixer_ramp_volume(int voice, int time, int endvol); +void _mixer_stop_volume_ramp(int voice); +int _mixer_get_frequency(int voice); +void _mixer_set_frequency(int voice, int frequency); +void _mixer_sweep_frequency(int voice, int time, int endfreq); +void _mixer_stop_frequency_sweep(int voice); +int _mixer_get_pan(int voice); +void _mixer_set_pan(int voice, int pan); +void _mixer_sweep_pan(int voice, int time, int endpan); +void _mixer_stop_pan_sweep(int voice); +void _mixer_set_echo(int voice, int strength, int delay); +void _mixer_set_tremolo(int voice, int rate, int depth); +void _mixer_set_vibrato(int voice, int rate, int depth); + +/* dummy functions for the NoSound drivers */ +int _dummy_detect(int input); +int _dummy_init(int input, int voices); +void _dummy_exit(int input); +int _dummy_mixer_volume(int volume); +void _dummy_init_voice(int voice, SAMPLE *sample); +void _dummy_noop1(int p); +void _dummy_noop2(int p1, int p2); +void _dummy_noop3(int p1, int p2, int p3); +int _dummy_get_position(int voice); +int _dummy_get(int voice); +void _dummy_raw_midi(unsigned char data); +int _dummy_load_patches(char *patches, char *drums); +void _dummy_adjust_patches(char *patches, char *drums); +void _dummy_key_on(int inst, int note, int bend, int vol, int pan); + + +/* from djgpp's libc, needed to find which directory we were run from */ +extern int __crt0_argc; +extern char **__crt0_argv; + + +#endif /* ifndef INTERNAL_H */ diff --git a/src/djgppdos/rdb-s.h b/src/djgppdos/rdb-s.h new file mode 100644 index 000000000..6202dacfa --- /dev/null +++ b/src/djgppdos/rdb-s.h @@ -0,0 +1,22 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright (C) 2005 by Sonic Team Jr. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +//----------------------------------------------------------------------------- +/// \file +/// \brief Set Com port and speed for GDBStubs for DJGGP +/// +/// copy and rename as rdb.h and set the defines below as needed + +#define DEBUG_COM_PORT 2 +#define DEBUG_COM_PORT_SPEED 9600 diff --git a/src/djgppdos/vid_vesa.c b/src/djgppdos/vid_vesa.c new file mode 100644 index 000000000..ec7b8b886 --- /dev/null +++ b/src/djgppdos/vid_vesa.c @@ -0,0 +1,900 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright (C) 1998-2000 by DooM Legacy Team. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +//----------------------------------------------------------------------------- +/// \file +/// \brief extended vesa VESA2.0 video modes i/o + +#include + +#include "../i_system.h" //I_Error() +#include "vid_vesa.h" +#include "../doomdef.h" //MAXVIDWIDTH, MAXVIDHEIGHT +#include "../screen.h" + +#include +#include +#include +#include +#include +#include + +#include "../console.h" +#include "../command.h" //added:21-03-98: vid_xxx commands +#include "../i_video.h" + + +// PROTOS +static vmode_t *VID_GetModePtr (int modenum); +static int VID_VesaGetModeInfo (int modenum); +static void VID_VesaGetExtraModes (void); +static INT32 VID_VesaInitMode (viddef_t *lvid, vmode_t *pcurrentmode); + +static void VID_Command_NumModes_f (void); +static void VID_Command_ModeInfo_f (void); +static void VID_Command_ModeList_f (void); +static void VID_Command_Mode_f (void); + +consvar_t cv_vidwait = {"vid_wait", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +static consvar_t cv_stretch = {"stretch", "On", CV_SAVE|CV_NOSHOWHELP, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + +#define VBEVERSION 2 // we need vesa2 or higher + +// ----------------------------------------------------- +#define MASK_LINEAR(addr) (addr & 0x000FFFFF) +#define RM_TO_LINEAR(addr) (((addr & 0xFFFF0000) >> 12) + (addr & 0xFFFF)) +#define RM_OFFSET(addr) (addr & 0xF) +#define RM_SEGMENT(addr) ((addr >> 4) & 0xFFFF) +// ----------------------------------------------------- + +static int totalvidmem; + +static vmode_t vesa_modes[MAX_VESA_MODES] = {{NULL, NULL, 0, 0, 0, 0, 0, 0, NULL, NULL, 0}}; +static vesa_extra_t vesa_extra[MAX_VESA_MODES]; + +//this is the only supported non-vesa mode : standard 320x200x256c. +#define NUMVGAVIDMODES 1 +static INT32 VGA_InitMode (viddef_t *lvid, vmode_t *pcurrentmode); +static char vgamode1[] ="320x200"; +static vmode_t vgavidmodes[NUMVGAVIDMODES] = { + { + NULL, + vgamode1, + 320, 200, //(200.0/320.0)*(320.0/240.0), + 320, 1, // rowbytes, bytes per pixel + 0, 1, + NULL, + VGA_InitMode, 0 + } +}; + +static char names[MAX_VESA_MODES][10]; + +//----------------------------i_video.c------------------------------------ +// these ones should go to i_video.c, but I prefer keep them away from the +// doom sources until the vesa stuff is ok. +static int numvidmodes; //total number of video modes, vga, vesa1, vesa2. +static vmode_t *pvidmodes; //start of videomodes list. +static vmode_t *pcurrentmode; // the current active videomode. +//----------------------------i_video.c------------------------------------ + + + +// table des modes videos. +// seul le mode 320x200x256c standard VGA est support‚ sans le VESA. +// ce mode est le mode num‚ro 0 dans la liste. +typedef struct +{ + int modenum; // vesa vbe2.0 modenum + int mode_attributes; + int winasegment; + int winbsegment; + int bytes_per_scanline; // bytes per logical scanline (+16) + int win; // window number (A=0, B=1) + int win_size; // window size (+6) + int granularity; // how finely i can set the window in vid mem (+4) + int width, height; // displayed width and height (+18, +20) + int bits_per_pixel; // er, better be 8, 15, 16, 24, or 32 (+25) + int bytes_per_pixel; // er, better be 1, 2, or 4 + int memory_model; // and better be 4 or 6, packed or direct color (+27) + int num_pages; // number of complete frame buffer pages (+29) + int red_width; // the # of bits in the red component (+31) + int red_pos; // the bit position of the red component (+32) + int green_width; // etc.. (+33) + int green_pos; // (+34) + int blue_width; // (+35) + int blue_pos; // (+36) + int pptr; + int pagesize; + int numpages; +} modeinfo_t; + +static vbeinfoblock_t vesainfo; +static vesamodeinfo_t vesamodeinfo; + +// ------------------------------------------------------------------------ +// DOS stuff +// ------------------------------------------------------------------------ +static unsigned long conventional_memory = (unsigned long)-1; + +FUNCINLINE static ATTRINLINE void map_in_conventional_memory(void) +{ + if (conventional_memory == (unsigned long)-1) + { + if (__djgpp_nearptr_enable()) + { + conventional_memory = __djgpp_conventional_base; + } + } +} + +// Converts a flat 32 bit ptr to a realmode 0x12345 type ptr (seg<<4 + offs) +#if 0 +unsigned int ptr2real(void *ptr) +{ + map_in_conventional_memory(); + return (int)ptr - conventional_memory; +} +#endif + +// Converts 0x12345 (seg<<4+offs) realmode ptr to a flat 32bit ptr +FUNCINLINE static ATTRINLINE void *real2ptr(unsigned int real) +{ + map_in_conventional_memory(); + return (void *) (real + conventional_memory); +} + +// ------------------------------------------------------------------------ + + +/* ======================================================================== */ +// Add the standard VGA video modes (only one now) to the video modes list. +/* ======================================================================== */ +static inline void VGA_Init(void) +{ + vgavidmodes[NUMVGAVIDMODES-1].pnext = pvidmodes; + pvidmodes = &vgavidmodes[0]; + numvidmodes += NUMVGAVIDMODES; +} + + +//added:30-01-98: return number of video modes in pvidmodes list +INT32 VID_NumModes(void) +{ + return numvidmodes; +} + +//added:21-03-98: return info on video mode +FUNCINLINE static ATTRINLINE const char *VID_ModeInfo (int modenum, char **ppheader) +{ + static const char *badmodestr = "Bad video mode number\n"; + vmode_t *pv; + + pv = VID_GetModePtr (modenum); + + if (!pv) + { + if (ppheader) + *ppheader = NULL; + return badmodestr; + } + else + { + //if (ppheader) + // *ppheader = pv->header; + return pv->name; + } +} + + + +//added:03-02-98: return a video mode number from the dimensions +INT32 VID_GetModeForSize( INT32 w, INT32 h) +{ + vmode_t *pv; + int modenum; + + pv = pvidmodes; + for (modenum=0; pv!=NULL; pv=pv->pnext,modenum++ ) + { + if ( pv->width==(unsigned)w && pv->height==(unsigned)h ) + return modenum; + } + + return 0; +} + + +/* ======================================================================== */ +// +/* ======================================================================== */ +void VID_Init (void) +{ + COM_AddCommand ("vid_nummodes", VID_Command_NumModes_f); + COM_AddCommand ("vid_modeinfo", VID_Command_ModeInfo_f); + COM_AddCommand ("vid_modelist", VID_Command_ModeList_f); + COM_AddCommand ("vid_mode", VID_Command_Mode_f); + CV_RegisterVar (&cv_vidwait); + CV_RegisterVar (&cv_stretch); + + //setup the videmodes list, + // note that mode 0 must always be VGA mode 0x13 + pvidmodes = NULL; + pcurrentmode = NULL; + numvidmodes = 0; + // setup the vesa_modes list + VID_VesaGetExtraModes (); + + // the game boots in 320x200 standard VGA, but + // we need a highcolor mode to run the game in highcolor + if (highcolor && numvidmodes==0) + I_Error ("No 15bit highcolor VESA2 video mode found, cannot run in highcolor.\n"); + + // add the vga modes at the start of the modes list + VGA_Init(); + + +#ifdef DEBUG + CONS_Printf("VID_SetMode(%d)\n",vid.modenum); +#endif + VID_SetMode (0); //vid.modenum); + + +#ifdef DEBUG + CONS_Printf("after VID_SetMode\n"); + CONS_Printf("vid.width %d\n",vid.width); + CONS_Printf("vid.height %d\n",vid.height); + CONS_Printf("vid.buffer %x\n",vid.buffer); + CONS_Printf("vid.rowbytes %d\n",vid.rowbytes); + CONS_Printf("vid.numpages %d\n",vid.numpages); + CONS_Printf("vid.recalc %d\n",vid.recalc); + CONS_Printf("vid.direct %x\n",vid.direct); +#endif + +} + + +// ======================================================================== +// Returns a vmode_t from the video modes list, given a video mode number. +// ======================================================================== +vmode_t *VID_GetModePtr (int modenum) +{ + vmode_t *pv; + + pv = pvidmodes; + if (!pv) + I_Error ("VID_error 1\n"); + + while (modenum--) + { + pv = pv->pnext; + if (!pv) + I_Error ("VID_error 2\n"); + } + + return pv; +} + + +//added:30-01-98:return the name of a video mode +const char *VID_GetModeName (INT32 modenum) +{ + return (VID_GetModePtr(modenum))->name; +} + + +// ======================================================================== +// Sets a video mode +// ======================================================================== +INT32 VID_SetMode (INT32 modenum) //, UINT8 *palette) +{ + int vstat; + vmode_t *pnewmode, *poldmode; + + if ((modenum >= numvidmodes) || (modenum < 0)) + { + if (pcurrentmode == NULL) + { + modenum = 0; // mode hasn't been set yet, so initialize to base + // mode since they gave us an invalid initial mode + } + else + { + //nomodecheck = true; + I_Error ("Unknown video mode: %d\n", modenum); + //nomodecheck = false; + return 0; + } + } + + pnewmode = VID_GetModePtr (modenum); + + if (pnewmode == pcurrentmode) + return 1; // already in the desired mode + + // initialize the new mode + poldmode = pcurrentmode; + pcurrentmode = pnewmode; + + // initialize vidbuffer size for setmode + vid.width = pcurrentmode->width; + vid.height = pcurrentmode->height; + //vid.aspect = pcurrentmode->aspect; + vid.rowbytes = pcurrentmode->rowbytes; + vid.bpp = pcurrentmode->bytesperpixel; + + //debug + //if (vid.rowbytes != vid.width) + // I_Error("vidrowbytes (%d) <> vidwidth(%d)\n",vid.rowbytes,vid.width); + + vstat = (*pcurrentmode->setmode) (&vid, pcurrentmode); + + if (vstat < 1) + { + if (vstat == 0) + { + // harware could not setup mode + //if (!VID_SetMode (vid.modenum)) + // I_Error ("VID_SetMode: couldn't set video mode (hard failure)"); + I_Error("Couldn't set video mode %d\n", modenum); + } + else + if (vstat == -1) + { + CONS_Printf ("Not enough mem for VID_SetMode...\n"); + + // not enough memory; just put things back the way they were + pcurrentmode = poldmode; + vid.width = pcurrentmode->width; + vid.height = pcurrentmode->height; + vid.rowbytes = pcurrentmode->rowbytes; + vid.bpp = pcurrentmode->bytesperpixel; + return 0; + } + } + + vid.modenum = modenum; + + //printf ("%s\n", VID_ModeInfo (vid.modenum, NULL)); + + //added:20-01-98: recalc all tables and realloc buffers based on + // vid values. + vid.recalc = 1; + + if (!cv_stretch.value && (float)vid.width/vid.height != ((float)BASEVIDWIDTH/BASEVIDHEIGHT)) + vid.height = (int)(vid.width * ((float)BASEVIDHEIGHT/BASEVIDWIDTH));// Adjust the height to match + + return 1; +} + + + +// converts a segm:offs 32bit pair to a 32bit flat ptr +#if 0 +void *VID_ExtraFarToLinear (void *ptr) +{ + int temp; + + temp = (int)ptr; + return real2ptr (((temp & 0xFFFF0000) >> 12) + (temp & 0xFFFF)); +} +#endif + + + +// ======================================================================== +// Helper function for VID_VesaGetExtraModes +// In: vesa mode number, from the vesa videomodenumbers list +// Out: false, if no info for given modenum +// ======================================================================== +int VID_VesaGetModeInfo (int modenum) +{ + int bytes_per_pixel; + unsigned int i; + __dpmi_regs regs; + + for (i=0; i 2) || + (vesamodeinfo.XResolution > MAXVIDWIDTH) || + (vesamodeinfo.YResolution > MAXVIDHEIGHT)) + { + return false; + } + + // we only want color graphics modes that are supported by the hardware + if ((vesamodeinfo.ModeAttributes & + (MODE_SUPPORTED_IN_HW | COLOR_MODE | GRAPHICS_MODE) ) != + (MODE_SUPPORTED_IN_HW | COLOR_MODE | GRAPHICS_MODE)) + { + return false; + } + + // we only work with linear frame buffers, except for 320x200, + // which is linear when banked at 0xA000 + if (!(vesamodeinfo.ModeAttributes & LINEAR_FRAME_BUFFER)) + { + if ((vesamodeinfo.XResolution != 320) || + (vesamodeinfo.YResolution != 200)) + { + return false; + } + } + + // pagesize + if ((vesamodeinfo.BytesPerScanLine * vesamodeinfo.YResolution) + > totalvidmem) + { + return false; + } + + vesamodeinfo.NumberOfImagePages = 1; + + +#ifdef DEBUG + CONS_Printf("VID: (VESA) info for mode 0x%x\n", modeinfo.modenum); + CONS_Printf(" mode attrib = 0x%0x\n", modeinfo.mode_attributes); + CONS_Printf(" win a attrib = 0x%0x\n", *(UINT8 *)(infobuf+2)); + CONS_Printf(" win b attrib = 0x%0x\n", *(UINT8 *)(infobuf+3)); + CONS_Printf(" win a seg 0x%0x\n", (int) modeinfo.winasegment); + CONS_Printf(" win b seg 0x%0x\n", (int) modeinfo.winbsegment); + CONS_Printf(" bytes per scanline = %d\n", + modeinfo.bytes_per_scanline); + CONS_Printf(" width = %d, height = %d\n", modeinfo.width, + modeinfo.height); + CONS_Printf(" win = %c\n", 'A' + modeinfo.win); + CONS_Printf(" win granularity = %d\n", modeinfo.granularity); + CONS_Printf(" win size = %d\n", modeinfo.win_size); + CONS_Printf(" bits per pixel = %d\n", modeinfo.bits_per_pixel); + CONS_Printf(" bytes per pixel = %d\n", modeinfo.bytes_per_pixel); + CONS_Printf(" memory model = 0x%x\n", modeinfo.memory_model); + CONS_Printf(" num pages = %d\n", modeinfo.num_pages); + CONS_Printf(" red width = %d\n", modeinfo.red_width); + CONS_Printf(" red pos = %d\n", modeinfo.red_pos); + CONS_Printf(" green width = %d\n", modeinfo.green_width); + CONS_Printf(" green pos = %d\n", modeinfo.green_pos); + CONS_Printf(" blue width = %d\n", modeinfo.blue_width); + CONS_Printf(" blue pos = %d\n", modeinfo.blue_pos); + CONS_Printf(" phys mem = %x\n", modeinfo.pptr); +#endif + } + + return true; +} + + +// ======================================================================== +// Get extended VESA modes information, keep the ones that we support, +// so they'll be available in the game Video menu. +// ======================================================================== +#define MAXVESADESC 100 +static char vesadesc[MAXVESADESC] = ""; + +void VID_VesaGetExtraModes (void) +{ + unsigned int i; + unsigned long addr; + int nummodes; + __dpmi_meminfo phys_mem_info; + unsigned long mode_ptr; + __dpmi_regs regs; + + // make a copy of the video modes list! else trash in __tb + UINT16 vmode[MAX_VESA_MODES+1]; + int numvmodes; + UINT16 vesamode; + + // new ugly stuff... + for (i=0; i>8, + vesainfo.VESAVersion&0xFF); + + // + // vesa description string + // + i = 0; + addr = RM_TO_LINEAR(vesainfo.OemStringPtr); + _farsetsel(_dos_ds); + while (_farnspeekb(addr) != 0) + { + vesadesc[i++] = _farnspeekb(addr++); + if (i == MAXVESADESC-1) + break; + } + vesadesc[i]=0; + CONS_Printf ("%s)\n",vesadesc); + + totalvidmem = vesainfo.TotalMemory << 16; + + // + // find 8 bit modes + // + numvmodes = 0; + mode_ptr = RM_TO_LINEAR(vesainfo.VideoModePtr); + while ((vmode[numvmodes] = _farpeekw(_dos_ds, mode_ptr)) != 0xFFFF) + { + numvmodes++; + if ( numvmodes == MAX_VESA_MODES ) + break; + mode_ptr += 2; + } + vmode[numvmodes] = 0xffff; + + nummodes = 0; // number of video modes accepted for the game + + numvmodes=0; // go again through vmodes table + while ( ((vesamode=vmode[numvmodes++]) != 0xFFFF) && (nummodes < MAX_VESA_MODES) ) + { + //fill the modeinfo struct. + if (VID_VesaGetModeInfo (vesamode)) + { + vesa_modes[nummodes].pnext = &vesa_modes[nummodes+1]; + if (vesamodeinfo.XResolution > 999) + { + if (vesamodeinfo.YResolution > 999) + { + sprintf (&names[nummodes][0], "%4dx%4d", vesamodeinfo.XResolution, + vesamodeinfo.YResolution); + names[nummodes][9] = 0; + } + else + { + sprintf (&names[nummodes][0], "%4dx%3d", vesamodeinfo.XResolution, + vesamodeinfo.YResolution); + names[nummodes][8] = 0; + } + } + else + { + if (vesamodeinfo.YResolution > 999) + { + sprintf (&names[nummodes][0], "%3dx%4d", vesamodeinfo.XResolution, + vesamodeinfo.YResolution); + names[nummodes][8] = 0; + } + else + { + sprintf (&names[nummodes][0], "%3dx%3d", vesamodeinfo.XResolution, + vesamodeinfo.YResolution); + names[nummodes][7] = 0; + } + } + + vesa_modes[nummodes].name = &names[nummodes][0]; + vesa_modes[nummodes].width = vesamodeinfo.XResolution; + vesa_modes[nummodes].height = vesamodeinfo.YResolution; + + //added:20-01-98:aspect ratio to be implemented... + vesa_modes[nummodes].rowbytes = vesamodeinfo.BytesPerScanLine; + vesa_modes[nummodes].windowed = 0; + vesa_modes[nummodes].pextradata = &vesa_extra[nummodes]; + vesa_modes[nummodes].setmode = VID_VesaInitMode; + + if (vesamodeinfo.ModeAttributes & LINEAR_FRAME_BUFFER) + { + // add linear bit to mode for linear modes + vesa_extra[nummodes].vesamode = vesamode | LINEAR_MODE; + vesa_modes[nummodes].numpages = 1; //vesamodeinfo.NumberOfImagePages; + + phys_mem_info.address = (int)vesamodeinfo.PhysBasePtr; + phys_mem_info.size = 0x400000; + + // returns -1 on error + if (__dpmi_physical_address_mapping(&phys_mem_info)) + { + //skip this mode, it doesnt work + continue; + } + + // if physical mapping was ok... convert the selector:offset + vesa_extra[nummodes].plinearmem = + real2ptr (phys_mem_info.address); + + // lock the region + __dpmi_lock_linear_region (&phys_mem_info); + } + else + { + // banked at 0xA0000 + vesa_extra[nummodes].vesamode = vesamode; + //vesa_extra[nummodes].pages[0] = 0; + vesa_extra[nummodes].plinearmem = + real2ptr (vesamodeinfo.WinASegment<<4); + + vesa_modes[nummodes].numpages = 1; //modeinfo.numpages; + } + + vesa_modes[nummodes].bytesperpixel = (vesamodeinfo.BitsPerPixel+1)/8; + + nummodes++; + } + } + +// add the VESA modes at the start of the mode list (if there are any) + if (nummodes) + { + vesa_modes[nummodes-1].pnext = NULL; //pvidmodes; + pvidmodes = &vesa_modes[0]; + numvidmodes += nummodes; + } + +} + + +// ======================================================================== +// Free the video buffer of the last video mode, +// allocate a new buffer for the video mode to set. +// ======================================================================== +static boolean VID_FreeAndAllocVidbuffer (viddef_t *lvid) +{ + int vidbuffersize; + + vidbuffersize = (lvid->width * lvid->height * lvid->bpp * NUMSCREENS); //status bar + + // free allocated buffer for previous video mode + if (lvid->buffer!=NULL) + { + free(lvid->buffer); + } + + // allocate the new screen buffer + if ( (lvid->buffer = (UINT8 *) malloc(vidbuffersize))==NULL ) + return false; + + // initially clear the video buffer + memset (lvid->buffer, 0x00, vidbuffersize); + +#ifdef DEBUG + CONS_Printf("VID_FreeAndAllocVidbuffer done, vidbuffersize: %x\n",vidbuffersize); +#endif + return true; +} + + +// ======================================================================== +// Set video mode routine for STANDARD VGA MODES (NO HIGHCOLOR) +// Out: 1 ok, +// 0 hardware could not set mode, +// -1 no mem +// ======================================================================== +static INT32 VGA_InitMode (viddef_t *lvid, vmode_t *currentmodep) +{ + __dpmi_regs regs; + + if (!VID_FreeAndAllocVidbuffer (lvid)) + return -1; //no mem + + //added:26-01-98: should clear video mem here + + //set mode 0x13 + regs.h.ah = 0; + regs.h.al = 0x13; + __dpmi_int(0x10, ®s); + + // here it is the standard VGA 64k window, not an LFB + // (you could have 320x200x256c with LFB in the vesa modes) + lvid->direct = (UINT8 *) real2ptr (0xa0000); + lvid->u.numpages = 1; + lvid->bpp = currentmodep->bytesperpixel; + + return 1; +} + + +// ======================================================================== +// Set video mode routine for VESA video modes, see VID_SetMode() +// Out: 1 ok, +// 0 hardware could not set mode, +// -1 no mem +// ======================================================================== +INT32 VID_VesaInitMode (viddef_t *lvid, vmode_t *currentmodep) +{ + vesa_extra_t *pextra; + __dpmi_regs regs; + + pextra = currentmodep->pextradata; + +#ifdef DEBUG + CONS_Printf("VID_VesaInitMode...\n"); + CONS_Printf(" currentmodep->name %s\n",currentmodep->name); + CONS_Printf(" width %d\n",currentmodep->width); + CONS_Printf(" height %d\n",currentmodep->height); + CONS_Printf(" rowbytes %d\n",currentmodep->rowbytes); + CONS_Printf(" windowed %d\n",currentmodep->windowed); + CONS_Printf(" numpages %d\n",currentmodep->numpages); + CONS_Printf(" currentmodep->pextradata :\n"); + CONS_Printf(" ->vesamode %x\n",pextra->vesamode); + CONS_Printf(" ->plinearmem %x\n\n",pextra->plinearmem); +#endif + + //added:20-01-98:no page flipping now... TO DO!!! + lvid->u.numpages = 1; + + // clean up any old vid buffer lying around, alloc new if needed + if (!VID_FreeAndAllocVidbuffer (lvid)) + return -1; //no mem + + + //added:20-01-98: should clear video mem here + + + // set the mode + regs.x.ax = 0x4f02; + regs.x.bx = pextra->vesamode; + __dpmi_int (0x10, ®s); + + if (regs.x.ax != 0x4f) + return 0; // could not set mode + +//added:20-01-98: should setup wait_vsync flag, currentpage here... +// plus check for display_enable bit + +//added:20-01-98: here we should set the page if page flipping... + + // points to LFB, or the start of VGA mem. + lvid->direct = pextra->plinearmem; + lvid->bpp = currentmodep->bytesperpixel; + + return 1; +} + +// ======================================================================== +// VIDEO MODE CONSOLE COMMANDS +// ======================================================================== + + +// vid_nummodes +// +//added:21-03-98: +void VID_Command_NumModes_f (void) +{ + int nummodes; + + nummodes = VID_NumModes (); + CONS_Printf ("%d video mode(s) available(s)\n", nummodes); +} + + +// vid_modeinfo +// +void VID_Command_ModeInfo_f (void) +{ + vmode_t *pv; + int modenum; + + if (COM_Argc()!=2) + modenum = vid.modenum; // describe the current mode + else + modenum = atoi (COM_Argv(1)); // .. the given mode number + + if (modenum >= VID_NumModes()) + { + CONS_Printf ("No such video mode\n"); + return; + } + + pv = VID_GetModePtr (modenum); + + CONS_Printf ("%s\n", VID_ModeInfo (modenum, NULL)); + CONS_Printf ("width : %d\n" + "height: %d\n" + "bytes per scanline: %d\n" + "bytes per pixel: %d\n" + "numpages: %d\n", + pv->width, + pv->height, + pv->rowbytes, + pv->bytesperpixel, + pv->numpages ); +} + + +// vid_modelist +// +void VID_Command_ModeList_f (void) +{ + int i, nummodes; + const char *pinfo; + char *pheader; + vmode_t *pv; + boolean na; + + na = false; + + nummodes = VID_NumModes (); + for (i=0 ; ibytesperpixel==1) + CONS_Printf ("%d: %s\n", i, pinfo); + else + CONS_Printf ("%d: %s (hicolor)\n", i, pinfo); + } + +} + + +// vid_mode +// +void VID_Command_Mode_f (void) +{ + int modenum; + + if (COM_Argc()!=2) + { + CONS_Printf ("vid_mode : set video mode\n"); + return; + } + + modenum = atoi(COM_Argv(1)); + + if (modenum >= VID_NumModes()) + CONS_Printf ("No such video mode\n"); + else + // request vid mode change + setmodeneeded = modenum+1; +} diff --git a/src/djgppdos/vid_vesa.h b/src/djgppdos/vid_vesa.h new file mode 100644 index 000000000..b704336e8 --- /dev/null +++ b/src/djgppdos/vid_vesa.h @@ -0,0 +1,109 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright (C) 1998-2000 by DooM Legacy Team. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +//----------------------------------------------------------------------------- +/// \file +/// \brief VESA extra modes. + +#include "../doomdef.h" +#include "../screen.h" + + + +#define MODE_SUPPORTED_IN_HW 0x0001 +#define COLOR_MODE 0x0008 +#define GRAPHICS_MODE 0x0010 +#define VGA_INCOMPATIBLE 0x0020 +#define LINEAR_FRAME_BUFFER 0x0080 +#define LINEAR_MODE 0x4000 + +#define MAX_VESA_MODES 30 // we'll just take the first 30 if there + + +// VESA information block structure +typedef struct vbeinfoblock_s +{ + UINT8 VESASignature[4]; + UINT16 VESAVersion; + unsigned long OemStringPtr; + UINT8 Capabilities[4]; + unsigned long VideoModePtr; + UINT16 TotalMemory; + UINT8 OemSoftwareRev[2]; + UINT8 OemVendorNamePtr[4]; + UINT8 OemProductNamePtr[4]; + UINT8 OemProductRevPtr[4]; + UINT8 Reserved[222]; + UINT8 OemData[256]; +} ATTRPACK vbeinfoblock_t; + + +// VESA information for a specific mode +typedef struct vesamodeinfo_s +{ + UINT16 ModeAttributes; + UINT8 WinAAttributes; + UINT8 WinBAttributes; + UINT16 WinGranularity; + UINT16 WinSize; + UINT16 WinASegment; + UINT16 WinBSegment; + unsigned long WinFuncPtr; + UINT16 BytesPerScanLine; + UINT16 XResolution; + UINT16 YResolution; + UINT8 XCharSize; + UINT8 YCharSize; + UINT8 NumberOfPlanes; + UINT8 BitsPerPixel; + UINT8 NumberOfBanks; + UINT8 MemoryModel; + UINT8 BankSize; + UINT8 NumberOfImagePages; + UINT8 Reserved_page; + UINT8 RedMaskSize; + UINT8 RedMaskPos; + UINT8 GreenMaskSize; + UINT8 GreenMaskPos; + UINT8 BlueMaskSize; + UINT8 BlueMaskPos; + UINT8 ReservedMaskSize; + UINT8 ReservedMaskPos; + UINT8 DirectColorModeInfo; + + /* VBE 2.0 extensions */ + unsigned long PhysBasePtr; + unsigned long OffScreenMemOffset; + UINT16 OffScreenMemSize; + + /* VBE 3.0 extensions */ + UINT16 LinBytesPerScanLine; + UINT8 BnkNumberOfPages; + UINT8 LinNumberOfPages; + UINT8 LinRedMaskSize; + UINT8 LinRedFieldPos; + UINT8 LinGreenMaskSize; + UINT8 LinGreenFieldPos; + UINT8 LinBlueMaskSize; + UINT8 LinBlueFieldPos; + UINT8 LinRsvdMaskSize; + UINT8 LinRsvdFieldPos; + unsigned long MaxPixelClock; + + UINT8 Reserved[190]; +} ATTRPACK vesamodeinfo_t; + + +// setup standard VGA + VESA modes list, activate the default video mode. +void VID_Init (void); diff --git a/src/doomdata.h b/src/doomdata.h new file mode 100644 index 000000000..4023c4979 --- /dev/null +++ b/src/doomdata.h @@ -0,0 +1,214 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 1993-1996 by id Software, Inc. +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Copyright (C) 1999-2014 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file doomdata.h +/// \brief all external data is defined here +/// +/// most of the data is loaded into different structures at run time +/// some internal structures shared by many modules are here + +#ifndef __DOOMDATA__ +#define __DOOMDATA__ + +// The most basic types we use, portability. +#include "doomtype.h" + +// Some global defines, that configure the game. +#include "doomdef.h" + +// +// Map level types. +// The following data structures define the persistent format +// used in the lumps of the WAD files. +// + +// Lump order in a map WAD: each map needs a couple of lumps +// to provide a complete scene geometry description. +enum +{ + ML_LABEL, // A separator, name, MAPxx + ML_THINGS, // Enemies, rings, monitors, scenery, etc. + ML_LINEDEFS, // Linedefs, from editing + ML_SIDEDEFS, // Sidedefs, from editing + ML_VERTEXES, // Vertices, edited and BSP splits generated + ML_SEGS, // Linesegs, from linedefs split by BSP + ML_SSECTORS, // Subsectors, list of linesegs + ML_NODES, // BSP nodes + ML_SECTORS, // Sectors, from editing + ML_REJECT, // LUT, sector-sector visibility + ML_BLOCKMAP, // LUT, motion clipping, walls/grid element +}; + +// Reverse gravity flag for objects. +#define MTF_OBJECTFLIP 2 + +// Special flag used with certain objects. +#define MTF_OBJECTSPECIAL 4 + +// Deaf monsters/do not react to sound. +#define MTF_AMBUSH 8 + +// Do not use bit five or after, as they are used for object z-offsets. + +#if defined(_MSC_VER) +#pragma pack(1) +#endif + +// A single Vertex. +typedef struct +{ + INT16 x, y; +}ATTRPACK mapvertex_t; + +// A SideDef, defining the visual appearance of a wall, +// by setting textures and offsets. +typedef struct +{ + INT16 textureoffset, rowoffset; + char toptexture[8], bottomtexture[8], midtexture[8]; + // Front sector, towards viewer. + INT16 sector; +} ATTRPACK mapsidedef_t; + +// A LineDef, as used for editing, and as input +// to the BSP builder. +typedef struct +{ + INT16 v1, v2; + INT16 flags; + INT16 special; + INT16 tag; + // sidenum[1] will be 0xffff if one sided + UINT16 sidenum[2]; +} ATTRPACK maplinedef_t; + +// +// LineDef attributes. +// + +// Solid, is an obstacle. +#define ML_IMPASSIBLE 1 + +// Blocks monsters only. +#define ML_BLOCKMONSTERS 2 + +// Backside will not be present at all if not two sided. +#define ML_TWOSIDED 4 + +// If a texture is pegged, the texture will have +// the end exposed to air held constant at the +// top or bottom of the texture (stairs or pulled +// down things) and will move with a height change +// of one of the neighbor sectors. +// Unpegged textures allways have the first row of +// the texture at the top pixel of the line for both +// top and bottom textures (use next to windows). + +// upper texture unpegged +#define ML_DONTPEGTOP 8 + +// lower texture unpegged +#define ML_DONTPEGBOTTOM 16 + +#define ML_EFFECT1 32 + +// Don't let Knuckles climb on this line +#define ML_NOCLIMB 64 + +#define ML_EFFECT2 128 +#define ML_EFFECT3 256 +#define ML_EFFECT4 512 +#define ML_EFFECT5 1024 + +// New ones to disable lines for characters +#define ML_NOSONIC 2048 +#define ML_NOTAILS 4096 +#define ML_NOKNUX 8192 + +// Bounce off walls! +#define ML_BOUNCY 16384 + +#define ML_TFERLINE 32768 + +// Sector definition, from editing. +typedef struct +{ + INT16 floorheight; + INT16 ceilingheight; + char floorpic[8]; + char ceilingpic[8]; + INT16 lightlevel; + INT16 special; + INT16 tag; +} ATTRPACK mapsector_t; + +// SubSector, as generated by BSP. +typedef struct +{ + UINT16 numsegs; + // Index of first one, segs are stored sequentially. + UINT16 firstseg; +} ATTRPACK mapsubsector_t; + + +// LineSeg, generated by splitting LineDefs +// using partition lines selected by BSP builder. +typedef struct +{ + INT16 v1, v2; + INT16 angle; + INT16 linedef; + INT16 side; + INT16 offset; +} ATTRPACK mapseg_t; + +// BSP node structure. + +// Indicate a leaf. +#define NF_SUBSECTOR 0x8000 + +typedef struct +{ + // Partition line from (x,y) to x+dx,y+dy) + INT16 x, y; + INT16 dx, dy; + + // Bounding box for each child, clip against view frustum. + INT16 bbox[2][4]; + + // If NF_SUBSECTOR it's a subsector, else it's a node of another subtree. + UINT16 children[2]; +} ATTRPACK mapnode_t; + +#if defined(_MSC_VER) +#pragma pack() +#endif + +// Thing definition, position, orientation and type, +// plus visibility flags and attributes. +typedef struct +{ + INT16 x, y; + INT16 angle; + UINT16 type; + UINT16 options; + INT16 z; + UINT8 extrainfo; + struct mobj_s *mobj; +} mapthing_t; + +#define ZSHIFT 4 + +extern const char *Color_Names[MAXSKINCOLORS]; +extern const UINT8 Color_Opposite[MAXSKINCOLORS*2]; + +#define NUMMAPS 1035 + +#endif // __DOOMDATA__ diff --git a/src/doomdef.h b/src/doomdef.h new file mode 100644 index 000000000..535bcc144 --- /dev/null +++ b/src/doomdef.h @@ -0,0 +1,489 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 1993-1996 by id Software, Inc. +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Copyright (C) 1999-2014 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file doomdef.h +/// \brief Internally used data structures for virtually everything, +/// key definitions, lots of other stuff. + +#ifndef __DOOMDEF__ +#define __DOOMDEF__ + +// Sound system select +// This should actually be in the makefile, +// but I can't stand that gibberish. D: +#define SOUND_DUMMY 0 +#define SOUND_SDL 1 +#define SOUND_MIXER 2 +#define SOUND_FMOD 3 + +#ifndef SOUND +#ifdef SDL + +// Use Mixer interface? +#ifdef HAVE_MIXER + //#if !defined(DC) && !defined(_WIN32_WCE) && !defined(_XBOX) && !defined(GP2X) + #define SOUND SOUND_MIXER + #define NOHS // No HW3SOUND + #ifdef HW3SOUND + #undef HW3SOUND + #endif + //#endif +#endif + +// Use generic SDL interface. +#ifndef SOUND +#define SOUND SOUND_SDL +#endif + +#else // No SDL. + +// Use FMOD? +#ifdef HAVE_FMOD + #define SOUND SOUND_FMOD + #define NOHS // No HW3SOUND + #ifdef HW3SOUND + #undef HW3SOUND + #endif +#else + // No more interfaces. :( + #define SOUND SOUND_DUMMY +#endif + +#endif +#endif + +#ifdef _WINDOWS +#if !defined (HWRENDER) && !defined (NOHW) +#define HWRENDER +#endif +// judgecutor: 3D sound support +#if !defined(HW3SOUND) && !defined (NOHS) +#define HW3SOUND +#endif +#endif + +#if defined (_WIN32) || defined (_WIN32_WCE) +#define ASMCALL __cdecl +#else +#define ASMCALL +#endif + +#ifdef _MSC_VER +#pragma warning(disable : 4127 4152 4213 4514) +#ifdef _WIN64 +#pragma warning(disable : 4306) +#endif +#endif +// warning level 4 +// warning C4127: conditional expression is constant +// warning C4152: nonstandard extension, function/data pointer conversion in expression +// warning C4213: nonstandard extension used : cast on l-value + +#if defined (_WIN32_WCE) && defined (DEBUG) && defined (ARM) +#if defined (ARMV4) || defined (ARMV4I) +//#pragma warning(disable : 1166) +// warning LNK1166: cannot adjust code at offset= +#endif +#endif + + +#include "doomtype.h" + +#include +#include +#include +#include + +#include + +#ifdef GETTEXT +#include +#include +#endif + +#if !defined (_WIN32_WCE) +#include +#include +#endif +#include + +#if ((defined (_WIN32) && !defined (_WIN32_WCE)) || defined (__DJGPP__)) && !defined (_XBOX) +#include +#endif + +#ifdef PC_DOS +#include +#endif + +//#define NOMD5 + +// Uncheck this to compile debugging code +//#define RANGECHECK +//#ifndef PARANOIA +//#define PARANOIA // do some tests that never fail but maybe +// turn this on by make etc.. DEBUGMODE = 1 or use the Debug profile in the VC++ projects +//#endif +#if defined (_WIN32) || (defined (__unix__) && !defined (MSDOS)) || defined(__APPLE__) || defined (UNIXCOMMON) || defined (macintosh) +#define LOGMESSAGES // write message in log.txt +#endif + +#ifdef LOGMESSAGES +extern FILE *logstream; +#endif + +#if 0 +#define VERSION 0 // Game version +#define SUBVERSION 0 // more precise version number +#define VERSIONSTRING "Trunk" +#else +#define VERSION 201 // Game version +#define SUBVERSION 0 // more precise version number +#define VERSIONSTRING "v2.1.0" +#endif + +// Modification options +// If you want to take advantage of the Master Server's ability to force clients to update +// to the latest version, fill these out. Otherwise, just comment out UPDATE_ALERT and leave +// the other options the same. + +// Comment out this line to completely disable update alerts (recommended for testing, but not for release) +#define UPDATE_ALERT + +// The string used in the alert that pops up in the event of an update being available. +// Please change to apply to your modification (we don't want everyone asking where your mod is on SRB2.org!). +#define UPDATE_ALERT_STRING \ +"A new update is available for SRB2.\n"\ +"Please visit SRB2.org to download it.\n"\ +"\n"\ +"You are using version: %s\n"\ +"The newest version is: %s\n"\ +"\n"\ +"This update is required for online\n"\ +"play using the Master Server.\n"\ +"You will not be able to connect to\n"\ +"the Master Server until you update to\n"\ +"the newest version of the game.\n"\ +"\n"\ +"(Press a key)\n" + +// The string used in the I_Error alert upon trying to host through command line parameters. +// Generally less filled with newlines, since Windows gives you lots more room to work with. +#define UPDATE_ALERT_STRING_CONSOLE \ +"A new update is available for SRB2.\n"\ +"Please visit SRB2.org to download it.\n"\ +"\n"\ +"You are using version: %s\n"\ +"The newest version is: %s\n"\ +"\n"\ +"This update is required for online play using the Master Server.\n"\ +"You will not be able to connect to the Master Server\n"\ +"until you update to the newest version of the game.\n" + +// For future use, the codebase is the version of SRB2 that the modification is based on, +// and should not be changed unless you have merged changes between versions of SRB2 +// (such as 2.0.4 to 2.0.5, etc) into your working copy. +// Will always resemble the versionstring, 205 = 2.0.5, 210 = 2.1, etc. +#define CODEBASE 210 + +// The Modification ID; must be obtained from Inuyasha ( http://mb.srb2.org/private.php?do=newpm&u=2604 ). +// DO NOT try to set this otherwise, or your modification will be unplayable through the Master Server. +// "12" is the default mod ID for version 2.1 +#define MODID 12 + +// The Modification Version, starting from 1. Do not follow your version string for this, +// it's only for detection of the version the player is using so the MS can alert them of an update. +// Only set it higher, not lower, obviously. +// Note that we use this to help keep internal testing in check; this is why v2.1.0 is not version "1". +#define MODVERSION 4 + + + + + +// some tests, enable or disable it if it run or not +#define SPLITSCREEN + +// ========================================================================= + +// The maximum number of players, multiplayer/networking. +// NOTE: it needs more than this to increase the number of players... + +#define MAXPLAYERS 32 +#define MAXSKINS MAXPLAYERS +#define PLAYERSMASK (MAXPLAYERS-1) +#define MAXPLAYERNAME 21 + +typedef enum +{ + SKINCOLOR_NONE = 0, + SKINCOLOR_WHITE, + SKINCOLOR_SILVER, + SKINCOLOR_GREY, + SKINCOLOR_BLACK, + SKINCOLOR_CYAN, + SKINCOLOR_TEAL, + SKINCOLOR_STEELBLUE, + SKINCOLOR_BLUE, + SKINCOLOR_PEACH, + SKINCOLOR_TAN, + SKINCOLOR_PINK, + SKINCOLOR_LAVENDER, + SKINCOLOR_PURPLE, + SKINCOLOR_ORANGE, + SKINCOLOR_ROSEWOOD, + SKINCOLOR_BEIGE, + SKINCOLOR_BROWN, + SKINCOLOR_RED, + SKINCOLOR_DARKRED, + SKINCOLOR_NEONGREEN, + SKINCOLOR_GREEN, + SKINCOLOR_ZIM, + SKINCOLOR_OLIVE, + SKINCOLOR_YELLOW, + SKINCOLOR_GOLD, + + // Careful! MAXSKINCOLORS cannot be greater than 0x20! + MAXSKINCOLORS, + + // Super special awesome Super flashing colors! + SKINCOLOR_SUPER1 = MAXSKINCOLORS, + SKINCOLOR_SUPER2, + SKINCOLOR_SUPER3, + SKINCOLOR_SUPER4, + SKINCOLOR_SUPER5, + + // Super Knuckles + SKINCOLOR_KSUPER1, + SKINCOLOR_KSUPER2, + SKINCOLOR_KSUPER3, + SKINCOLOR_KSUPER4, + SKINCOLOR_KSUPER5, + + MAXTRANSLATIONS +} skincolors_t; + +// State updates, number of tics / second. +// NOTE: used to setup the timer rate, see I_StartupTimer(). +#define TICRATE 35 +#define NEWTICRATERATIO 1 // try 4 for 140 fps :) +#define NEWTICRATE (TICRATE*NEWTICRATERATIO) + +#define RING_DIST 512*FRACUNIT // how close you need to be to a ring to attract it + +#define PUSHACCEL (2*FRACUNIT) // Acceleration for MF2_SLIDEPUSH items. + +// Special linedef executor tag numbers! +enum { + LE_PINCHPHASE = -2, // A boss entered pinch phase (and, in most cases, is preparing their pinch phase attack!) + LE_ALLBOSSESDEAD = -3, // All bosses in the map are dead (Egg capsule raise) + LE_BOSSDEAD = -4, // A boss in the map died (Chaos mode boss tally) + LE_BOSS4DROP = -5, // CEZ boss dropped its cage + LE_BRAKVILEATACK = -6 // Brak's doing his LOS attack, oh noes +}; + +// Name of local directory for config files and savegames +#if !defined(_arch_dreamcast) && !defined(_WIN32_WCE) && !defined(GP2X) && !defined(_WII) && !defined(_PS3) +#if (((defined (__unix__) && !defined (MSDOS)) || defined (UNIXCOMMON)) && !defined (__CYGWIN__)) && !defined (__APPLE__) +#define DEFAULTDIR ".srb2" +#else +#define DEFAULTDIR "srb2" +#endif +#endif + +#include "g_state.h" + +// commonly used routines - moved here for include convenience + +/** \brief The I_Error function + + \param error the error message + + \return void + + +*/ +void I_Error(const char *error, ...) FUNCIERROR; + +/** \brief write a message to stderr (use before I_Quit) for when you need to quit with a msg, but need + the return code 0 of I_Quit(); + + \param error message string + + \return void +*/ +void I_OutputMsg(const char *error, ...) FUNCPRINTF; + +// console.h +typedef enum +{ + CONS_NOTICE, + CONS_WARNING, + CONS_ERROR +} alerttype_t; + +void CONS_Printf(const char *fmt, ...) FUNCPRINTF; +void CONS_Alert(alerttype_t level, const char *fmt, ...) FUNCDEBUG; +void CONS_Debug(INT32 debugflags, const char *fmt, ...) FUNCDEBUG; + +// For help debugging functions. +#define POTENTIALLYUNUSED CONS_Alert(CONS_WARNING, "(%s:%d) Unused code appears to be used.\n", __FILE__, __LINE__) + +#include "m_swap.h" + +// Things that used to be in dstrings.h +#define DEVMAPS "devmaps" +#define DEVDATA "devdata" + +#define SAVEGAMENAME "srb2sav" + +char savegamename[256]; + +// m_misc.h +#ifdef GETTEXT +#define M_GetText(String) gettext(String) +void M_StartupLocale(void); +#else +// If no translations are to be used, make a stub +// M_GetText function that just returns the string. +#define M_GetText(x) (x) +#endif +extern void *(*M_Memcpy)(void* dest, const void* src, size_t n) FUNCNONNULL; +char *va(const char *format, ...) FUNCPRINTF; +char *M_GetToken(const char *inputString); +char *sizeu1(size_t num); +char *sizeu2(size_t num); +char *sizeu3(size_t num); +char *sizeu4(size_t num); +char *sizeu5(size_t num); + +// d_main.c +extern boolean devparm; // development mode (-debug) +// d_netcmd.c +extern INT32 cv_debug; + +#define DBG_BASIC 0x0001 +#define DBG_DETAILED 0x0002 +#define DBG_RANDOMIZER 0x0004 +#define DBG_RENDER 0x0008 +#define DBG_NIGHTSBASIC 0x0010 +#define DBG_NIGHTS 0x0020 +#define DBG_POLYOBJ 0x0040 +#define DBG_GAMELOGIC 0x0080 +#define DBG_NETPLAY 0x0100 +#define DBG_MEMORY 0x0200 +#define DBG_SETUP 0x0400 +#define DBG_LUA 0x0800 + +// ======================= +// Misc stuff for later... +// ======================= + +// if we ever make our alloc stuff... +#define ZZ_Alloc(x) Z_Malloc(x, PU_STATIC, NULL) + +// i_system.c, replace getchar() once the keyboard has been appropriated +INT32 I_GetKey(void); + +#ifndef min // Double-Check with WATTCP-32's cdefs.h +#define min(x, y) (((x) < (y)) ? (x) : (y)) +#endif +#ifndef max // Double-Check with WATTCP-32's cdefs.h +#define max(x, y) (((x) > (y)) ? (x) : (y)) +#endif + +// An assert-type mechanism. +#ifdef PARANOIA +#define I_Assert(e) ((e) ? (void)0 : I_Error("assert failed: %s, file %s, line %d", #e, __FILE__, __LINE__)) +#else +#define I_Assert(e) ((void)0) +#endif + +// The character that separates pathnames. Forward slash on +// most systems, but reverse solidus (\) on Windows and DOS. +#if defined (PC_DOS) || defined (_WIN32) + #define PATHSEP "\\" +#else + #define PATHSEP "/" +#endif + +// Compile date and time and revision. +extern const char *compdate, *comptime, *comprevision; + +// Disabled code and code under testing +// None of these that are disabled in the normal build are guaranteed to work perfectly +// Compile them at your own risk! + +/// Max recursive portal renders +/// \note sadly some additional work will need to be done +/// before anything > 1 will function correctly +#define PORTAL_LIMIT 1 + +/// Fun experimental slope stuff! +//#define SLOPENESS + +/// Delete file while the game is running. +/// \note EXTREMELY buggy, tends to crash game. +//#define DELFILE + +/// Allows the use of devmode in multiplayer. AKA "fishcake" +//#define NETGAME_DEVMODE + +/// Allows gravity changes in netgames, no questions asked. +//#define NETGAME_GRAVITY + +/// Dumps the contents of a network save game upon consistency failure for debugging. +//#define DUMPCONSISTENCY + +/// Pre-1.08 Chaos gametype code +/// \note Code severely out of date, does not take new enemies/bosses into account. +//#define CHAOSISNOTDEADYET + +/// Polyobject fake flat code +//#define POLYOBJECTS_PLANES + +/// Blue spheres for future use. +/// \todo Remove this define. +#define BLUE_SPHERES // Blue spheres for future use. + +/// Improved way of dealing with ping values and a ping limit. +#define NEWPING + +/// See name of player in your crosshair +#define SEENAMES + +/// Who put weights on my recycler? ... Inuyasha did. +/// \note XMOD port. +//#define WEIGHTEDRECYCLER + +/// Allow loading of savegames between different versions of the game. +/// \note XMOD port. +/// Most modifications should probably enable this. +//#define SAVEGAME_OTHERVERSIONS + +#if !defined (_NDS) && !defined (_PSP) +/// Shuffle's incomplete OpenGL sorting code. +//#define SHUFFLE +#endif + +#if !defined (_NDS) && !defined (_PSP) +/// Allow the use of the SOC RESETINFO command. +/// \note Builds that are tight on memory should disable this. +/// This stops the game from storing backups of the states, sprites, and mobjinfo tables. +/// Though this info is compressed under normal circumstances, it's still a lot of extra +/// memory that never gets touched. +#define ALLOW_RESETDATA +#endif + +#ifndef NONET +/// Display a connection screen on join attempts. +#define CLIENT_LOADINGSCREEN +#endif + +#endif // __DOOMDEF__ diff --git a/src/doomstat.h b/src/doomstat.h new file mode 100644 index 000000000..576b70099 --- /dev/null +++ b/src/doomstat.h @@ -0,0 +1,477 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 1993-1996 by id Software, Inc. +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Copyright (C) 1999-2014 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file doomstat.h +/// \brief All the global variables that store the internal state. +/// +/// Theoretically speaking, the internal state of the engine +/// should be found by looking at the variables collected +/// here, and every relevant module will have to include +/// this header file. In practice... things are a bit messy. + +#ifndef __DOOMSTAT__ +#define __DOOMSTAT__ + +// We need globally shared data structures, for defining the global state variables. +#include "doomdata.h" + +// We need the player data structure as well. +#include "d_player.h" + +// ============================= +// Selected map etc. +// ============================= + +// Selected by user. +extern INT16 gamemap; + +// ----------------xxxxxxxxxxxxxxxx = music slot +// -xxxxxxxxxxxxxxx---------------- = track slot +// x------------------------------- = reset music bit +extern UINT32 mapmusic; +#define MUSIC_TRACKSHIFT 16 +#define MUSIC_SONGMASK 0x0000FFFF +#define MUSIC_TRACKMASK 0x7FFF0000 +#define MUSIC_RELOADRESET 0x80000000 + +extern INT16 maptol; +extern UINT8 globalweather; +extern INT32 curWeather; +extern INT32 cursaveslot; +extern INT16 lastmapsaved; +extern boolean gamecomplete; + +#define PRECIP_NONE 0 +#define PRECIP_STORM 1 +#define PRECIP_SNOW 2 +#define PRECIP_RAIN 3 +#define PRECIP_BLANK 4 +#define PRECIP_STORM_NORAIN 5 +#define PRECIP_STORM_NOSTRIKES 6 + +// Set if homebrew PWAD stuff has been added. +extern boolean modifiedgame; +extern UINT16 mainwads; +extern boolean savemoddata; // This mod saves time/emblem data. +extern boolean disableSpeedAdjust; // Don't alter the duration of player states if true +extern boolean imcontinuing; // Temporary flag while continuing +extern boolean metalrecording; + +#define ATTACKING_NONE 0 +#define ATTACKING_RECORD 1 +#define ATTACKING_NIGHTS 2 +extern UINT8 modeattacking; + +// menu demo things +extern UINT8 numDemos; +extern UINT32 demoDelayTime; +extern UINT32 demoIdleTime; + +// Netgame? only true in a netgame +extern boolean netgame; +extern boolean addedtogame; // true after the server has added you +// Only true if >1 player. netgame => multiplayer but not (multiplayer=>netgame) +extern boolean multiplayer; + +extern INT16 gametype; +extern boolean splitscreen; +extern boolean circuitmap; // Does this level have 'circuit mode'? +extern boolean fromlevelselect; + +// ======================================== +// Internal parameters for sound rendering. +// ======================================== + +extern boolean nomidimusic; // defined in d_main.c +extern boolean nosound; +extern boolean nodigimusic; +extern boolean music_disabled; +extern boolean sound_disabled; +extern boolean digital_disabled; + +// ========================= +// Status flags for refresh. +// ========================= +// + +extern boolean menuactive; // Menu overlaid? +extern UINT8 paused; // Game paused? + +extern boolean nodrawers; +extern boolean noblit; +extern boolean lastdraw; +extern postimg_t postimgtype; +extern INT32 postimgparam; +extern postimg_t postimgtype2; +extern INT32 postimgparam2; + +extern INT32 viewwindowx, viewwindowy; +extern INT32 viewwidth, scaledviewwidth; + +extern boolean gamedataloaded; + +// Player taking events, and displaying. +extern INT32 consoleplayer; +extern INT32 displayplayer; +extern INT32 secondarydisplayplayer; // for splitscreen + +// Maps of special importance +extern INT16 spstage_start; +extern INT16 sstage_start; +extern INT16 sstage_end; + +extern boolean looptitle; +extern boolean useNightsSS; + +// CTF colors. +extern UINT8 skincolor_redteam, skincolor_blueteam, skincolor_redring, skincolor_bluering; + +extern tic_t countdowntimer; +extern boolean countdowntimeup; + +typedef struct +{ + UINT8 numpics; + char picname[8][8]; + UINT8 pichires[8]; + char *text; + UINT16 xcoord[8]; + UINT16 ycoord[8]; + UINT16 picduration[8]; + UINT16 musicslot; + UINT8 musicloop; + UINT16 textxpos; + UINT16 textypos; + + UINT8 fadecolor; // Color number for fade, 0 means don't do the first fade + UINT8 fadeinid; // ID of the first fade, to a color -- ignored if fadecolor is 0 + UINT8 fadeoutid; // ID of the second fade, to the new screen +} scene_t; // TODO: It would probably behoove us to implement subsong/track selection here, too, but I'm lazy -SH + +typedef struct +{ + scene_t scene[128]; // 128 scenes per cutscene. + INT32 numscenes; // Number of scenes in this cutscene +} cutscene_t; + +extern cutscene_t *cutscenes[128]; + +// For the Custom Exit linedef. +extern INT16 nextmapoverride; +extern INT32 nextmapgametype; +extern boolean skipstats; + +extern UINT32 totalrings; // Total # of rings in a level + +// Fun extra stuff +extern INT16 lastmap; // Last level you were at (returning from special stages). +extern mobj_t *redflag, *blueflag; // Pointers to physical flags +extern mapthing_t *rflagpoint, *bflagpoint; // Pointers to the flag spawn locations +#define GF_REDFLAG 1 +#define GF_BLUEFLAG 2 + +// A single point in space. +typedef struct +{ + fixed_t x, y, z; +} mappoint_t; + +extern struct quake +{ + // camera offsets and duration + fixed_t x,y,z; + UINT16 time; + + // location, radius, and intensity... + mappoint_t *epicenter; + fixed_t radius, intensity; +} quake; + +// NiGHTS grades +typedef struct +{ + UINT32 grade[6]; // D, C, B, A, S, X (F: failed to reach any of these) +} nightsgrades_t; + +/** Map header information. + */ +typedef struct +{ + // The original eight, plus one. + char lvlttl[22]; ///< Level name without "Zone". (21 character limit instead of 32, 21 characters can display on screen max anyway) + char subttl[33]; ///< Subtitle for level + UINT8 actnum; ///< Act number or 0 for none. + UINT16 typeoflevel; ///< Combination of typeoflevel flags. + INT16 nextlevel; ///< Map number of next level, or 1100-1102 to end. + UINT16 musicslot; ///< Music slot number to play. 0 for no music. + UINT16 musicslottrack; ///< Subsong to play. Only really relevant for music modules and specific formats supported by GME. 0 to ignore. + char forcecharacter[17]; ///< (SKINNAMESIZE+1) Skin to switch to or "" to disable. + UINT8 weather; ///< 0 = sunny day, 1 = storm, 2 = snow, 3 = rain, 4 = blank, 5 = thunder w/o rain, 6 = rain w/o lightning, 7 = heat wave. + INT16 skynum; ///< Sky number to use. + INT16 skybox_scalex; ///< Skybox X axis scale. (0 = no movement, 1 = 1:1 movement, 16 = 16:1 slow movement, -4 = 1:4 fast movement, etc.) + INT16 skybox_scaley; ///< Skybox Y axis scale. + INT16 skybox_scalez; ///< Skybox Z axis scale. + + // Extra information. + char interscreen[8]; ///< 320x200 patch to display at intermission. + char runsoc[33]; ///< SOC to execute at start of level (32 character limit instead of 63) + char scriptname[33]; ///< Script to use when the map is switched to. (32 character limit instead of 191) + UINT8 precutscenenum; ///< Cutscene number to play BEFORE a level starts. + UINT8 cutscenenum; ///< Cutscene number to use, 0 for none. + INT16 countdown; ///< Countdown until level end? + UINT16 palette; ///< PAL lump to use on this map + UINT32 numlaps; ///< Number of laps in circuit mode, unless overridden. + SINT8 unlockrequired; ///< Is an unlockable required to play this level? -1 if no. + UINT8 levelselect; ///< Is this map available in the level select? If so, which map list is it available in? + SINT8 bonustype; ///< What type of bonus does this level have? (-1 for null.) + + UINT8 levelflags; ///< LF_flags: merged eight booleans into one UINT8 for space, see below + UINT8 menuflags; ///< LF2_flags: options that affect record attack / nights mode menus + + // NiGHTS stuff. + UINT8 numGradedMares; ///< Internal. For grade support. + nightsgrades_t *grades; ///< NiGHTS grades. Allocated dynamically for space reasons. Be careful. +} mapheader_t; + +// level flags +#define LF_SCRIPTISFILE 1 ///< True if the script is a file, not a lump. +#define LF_SPEEDMUSIC 2 ///< Speed up act music for super sneakers +#define LF_NOSSMUSIC 4 ///< Disable Super Sonic music +#define LF_NORELOAD 8 ///< Don't reload level on death +#define LF_NOZONE 16 ///< Don't include "ZONE" on level title + +#define LF2_HIDEINMENU 1 ///< Hide in the multiplayer menu +#define LF2_HIDEINSTATS 2 ///< Hide in the statistics screen +#define LF2_RECORDATTACK 4 ///< Show this map in Time Attack +#define LF2_NIGHTSATTACK 8 ///< Show this map in NiGHTS mode menu +#define LF2_NOVISITNEEDED 16 ///< Available in time attack/nights mode without visiting the level + +extern mapheader_t* mapheaderinfo[NUMMAPS]; + +enum TypeOfLevel +{ + TOL_SP = 0x01, ///< Single Player + TOL_COOP = 0x02, ///< Cooperative + TOL_COMPETITION = 0x04, ///< Competition + TOL_RACE = 0x08, ///< Race +// Single Player default = 15 + + TOL_MATCH = 0x10, ///< Match + TOL_TAG = 0x20, ///< Tag +// Match/Tag default = 48 + + TOL_CTF = 0x40, ///< Capture the Flag +// CTF default = 64 + + TOL_CUSTOM = 0x80, ///< Custom (Lua-scripted, etc.) + + TOL_2D = 0x0100, ///< 2D + TOL_MARIO = 0x0200, ///< Mario + TOL_NIGHTS = 0x0400, ///< NiGHTS + TOL_ERZ3 = 0x0800, ///< ERZ3 + TOL_XMAS = 0x1000 ///< Christmas NiGHTS +}; + +// Gametypes +enum GameType +{ + GT_COOP = 0, // also used in single player + GT_COMPETITION, // Classic "Race" + GT_RACE, + + GT_MATCH, + GT_TEAMMATCH, + + GT_TAG, + GT_HIDEANDSEEK, + + GT_CTF, // capture the flag + + NUMGAMETYPES +}; +// If you alter this list, update gametype_cons_t in m_menu.c + +extern tic_t totalplaytime; + +extern UINT8 stagefailed; + +// Emeralds stored as bits to throw savegame hackers off. +extern UINT16 emeralds; +#define EMERALD1 1 +#define EMERALD2 2 +#define EMERALD3 4 +#define EMERALD4 8 +#define EMERALD5 16 +#define EMERALD6 32 +#define EMERALD7 64 +#define ALL7EMERALDS(v) ((v & (EMERALD1|EMERALD2|EMERALD3|EMERALD4|EMERALD5|EMERALD6|EMERALD7)) == (EMERALD1|EMERALD2|EMERALD3|EMERALD4|EMERALD5|EMERALD6|EMERALD7)) + +extern INT32 nummaprings; //keep track of spawned rings/coins + +/** Time attack information, currently a very small structure. + */ +typedef struct +{ + tic_t time; ///< Time in which the level was finished. + UINT32 score; ///< Score when the level was finished. + UINT16 rings; ///< Rings when the level was finished. +} recorddata_t; + +/** Setup for one NiGHTS map. + * These are dynamically allocated because I am insane + */ +#define GRADE_F 0 +#define GRADE_E 1 +#define GRADE_D 2 +#define GRADE_C 3 +#define GRADE_B 4 +#define GRADE_A 5 +#define GRADE_S 6 + +typedef struct +{ + // 8 mares, 1 overall (0) + UINT8 nummares; + UINT32 score[9]; + UINT8 grade[9]; + tic_t time[9]; +} nightsdata_t; + +extern nightsdata_t *nightsrecords[NUMMAPS]; +extern recorddata_t *mainrecords[NUMMAPS]; + +// mapvisited is now a set of flags that says what we've done in the map. +#define MV_VISITED 1 +#define MV_BEATEN 2 +#define MV_ALLEMERALDS 4 +#define MV_ULTIMATE 8 +#define MV_PERFECT 16 +#define MV_MAX 31 // used in gamedata check +extern UINT8 mapvisited[NUMMAPS]; + +// Temporary holding place for nights data for the current map +nightsdata_t ntemprecords; + +extern UINT32 token; ///< Number of tokens collected in a level +extern UINT32 tokenlist; ///< List of tokens collected +extern INT32 tokenbits; ///< Used for setting token bits +extern INT32 sstimer; ///< Time allotted in the special stage +extern UINT32 bluescore; ///< Blue Team Scores +extern UINT32 redscore; ///< Red Team Scores + +// Eliminates unnecessary searching. +extern boolean CheckForBustableBlocks; +extern boolean CheckForBouncySector; +extern boolean CheckForQuicksand; +extern boolean CheckForMarioBlocks; +extern boolean CheckForFloatBob; +extern boolean CheckForReverseGravity; + +// Powerup durations +extern UINT16 invulntics; +extern UINT16 sneakertics; +extern UINT16 flashingtics; +extern UINT16 tailsflytics; +extern UINT16 underwatertics; +extern UINT16 spacetimetics; +extern UINT16 extralifetics; + +extern UINT8 introtoplay; +extern UINT8 creditscutscene; + +extern UINT8 use1upSound; +extern UINT8 maxXtraLife; // Max extra lives from rings + +extern mobj_t *hunt1, *hunt2, *hunt3; // Emerald hunt locations + +// For racing +extern UINT32 countdown; +extern UINT32 countdown2; + +extern fixed_t gravity; + +//for CTF balancing +extern INT16 autobalance; +extern INT16 teamscramble; +extern INT16 scrambleplayers[MAXPLAYERS]; //for CTF team scramble +extern INT16 scrambleteams[MAXPLAYERS]; //for CTF team scramble +extern INT16 scrambletotal; //for CTF team scramble +extern INT16 scramblecount; //for CTF team scramble + +extern INT32 cheats; + +extern tic_t hidetime; + +extern UINT32 timesBeaten; // # of times the game has been beaten. +extern UINT32 timesBeatenWithEmeralds; +extern UINT32 timesBeatenUltimate; + +// =========================== +// Internal parameters, fixed. +// =========================== +// These are set by the engine, and not changed +// according to user inputs. Partly load from +// WAD, partly set at startup time. + +extern tic_t gametic; +#define localgametic leveltime + +// Player spawn spots. +extern mapthing_t *playerstarts[MAXPLAYERS]; // Cooperative +extern mapthing_t *bluectfstarts[MAXPLAYERS]; // CTF +extern mapthing_t *redctfstarts[MAXPLAYERS]; // CTF + +// ===================================== +// Internal parameters, used for engine. +// ===================================== + +#if defined (macintosh) +#define DEBFILE(msg) I_OutputMsg(msg) +extern FILE *debugfile; +#else +#define DEBUGFILE +#ifdef DEBUGFILE +#define DEBFILE(msg) { if (debugfile) { fputs(msg, debugfile); fflush(debugfile); } } +extern FILE *debugfile; +#else +#define DEBFILE(msg) {} +extern FILE *debugfile; +#endif +#endif + +#ifdef DEBUGFILE +extern INT32 debugload; +#endif + +// if true, load all graphics at level load +extern boolean precache; + +// wipegamestate can be set to -1 +// to force a wipe on the next draw +extern gamestate_t wipegamestate; + +// debug flag to cancel adaptiveness +extern boolean singletics; + +// ============= +// Netgame stuff +// ============= + +#include "d_clisrv.h" + +extern consvar_t cv_timetic; // display high resolution timer +extern consvar_t cv_forceskin; // force clients to use the server's skin +extern consvar_t cv_downloading; // allow clients to downloading WADs. +extern ticcmd_t netcmds[BACKUPTICS][MAXPLAYERS]; +extern INT32 adminplayer, serverplayer; + +/// \note put these in d_clisrv outright? + +#endif //__DOOMSTAT__ diff --git a/src/doomtype.h b/src/doomtype.h new file mode 100644 index 000000000..a365e3c56 --- /dev/null +++ b/src/doomtype.h @@ -0,0 +1,375 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 1993-1996 by id Software, Inc. +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Copyright (C) 1999-2014 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file doomtype.h +/// \brief SRB2 standard types +/// +/// Simple basic typedefs, isolated here to make it easier +/// separating modules. + +#ifndef __DOOMTYPE__ +#define __DOOMTYPE__ + +#if (defined (_WIN32) && !defined (_XBOX)) || (defined (_WIN32_WCE) && !defined (__GNUC__)) +//#define WIN32_LEAN_AND_MEAN +#define RPC_NO_WINDOWS_H +#include +#endif + +#ifdef _NDS +#include +#endif + +/* 7.18.1.1 Exact-width integer types */ +#ifdef _MSC_VER +#define UINT8 unsigned __int8 +#define SINT8 signed __int8 + +#define UINT16 unsigned __int16 +#define INT16 __int16 + +#define INT32 __int32 +#define UINT32 unsigned __int32 + +#define INT64 __int64 +#define UINT64 unsigned __int64 + +typedef long ssize_t; + +/* Older Visual C++ headers don't have the Win64-compatible typedefs... */ +#if ((_MSC_VER <= 1200) && (!defined(DWORD_PTR))) +#define DWORD_PTR DWORD +#endif + +#if ((_MSC_VER <= 1200) && (!defined(PDWORD_PTR))) +#define PDWORD_PTR PDWORD +#endif +#elif defined (_arch_dreamcast) // KOS Dreamcast +#include + +#define UINT8 unsigned char +#define SINT8 signed char + +#define UINT16 uint16 +#define INT16 int16 + +#define INT32 int +#define UINT32 unsigned int +#define INT64 int64 +#define UINT64 uint64 +#elif defined (__DJGPP__) +#define UINT8 unsigned char +#define SINT8 signed char + +#define UINT16 unsigned short int +#define INT16 signed short int + +#define INT32 signed long +#define UINT32 unsigned long +#define INT64 signed long long +#define UINT64 unsigned long long +#else +#define __STDC_LIMIT_MACROS +#include + +#define UINT8 uint8_t +#define SINT8 int8_t + +#define UINT16 uint16_t +#define INT16 int16_t + +#define INT32 int32_t +#define UINT32 uint32_t +#define INT64 int64_t +#define UINT64 uint64_t +#endif + +#ifdef __APPLE_CC__ +#define DIRECTFULLSCREEN +#define DEBUG_LOG +#define HWRENDER +#define NOIPX +#endif + +#if defined (_MSC_VER) || defined (__OS2__) + // Microsoft VisualC++ +#ifdef _MSC_VER + #define snprintf _snprintf +#if (_MSC_VER <= 1200) + #define vsnprintf _vsnprintf +#endif +#endif + #define strncasecmp strnicmp + #define strcasecmp stricmp + #define inline __inline +#elif defined (__WATCOMC__) + #include + #include + #include + #include + #define strncasecmp strnicmp + #define strcasecmp strcmpi +#endif +#ifdef _PSP + #include +#elif (defined (__unix__) && !defined (MSDOS)) || defined(__APPLE__) || defined (UNIXCOMMON) + #undef stricmp + #define stricmp(x,y) strcasecmp(x,y) + #undef strnicmp + #define strnicmp(x,y,n) strncasecmp(x,y,n) +#endif +#ifdef _WIN32_WCE +#ifndef __GNUC__ + #define stricmp(x,y) _stricmp(x,y) + #define strnicmp _strnicmp +#endif + #define strdup _strdup + #define strupr _strupr + #define strlwr _strlwr +#endif + +#if defined (macintosh) //|| defined (__APPLE__) //skip all boolean/Boolean crap + #define true 1 + #define false 0 + #define min(x,y) (((x)<(y)) ? (x) : (y)) + #define max(x,y) (((x)>(y)) ? (x) : (y)) + +#ifdef macintosh + #define stricmp strcmp + #define strnicmp strncmp +#endif + + #define boolean INT32 + + #ifndef O_BINARY + #define O_BINARY 0 + #endif +#endif //macintosh + +#if defined (PC_DOS) || defined (_WIN32) || defined (_WII) || defined (_PSP) || defined (_arch_dreamcast) || defined (__HAIKU__) || defined(_NDS) || defined(_PS3) +#define HAVE_DOSSTR_FUNCS +#endif + +#ifndef HAVE_DOSSTR_FUNCS +int strupr(char *n); // from dosstr.c +int strlwr(char *n); // from dosstr.c +#endif + +#include // for size_t + +#ifndef __APPLE__ +size_t strlcat(char *dst, const char *src, size_t siz); +size_t strlcpy(char *dst, const char *src, size_t siz); +#endif + +// Macro for use with char foo[FOOSIZE+1] type buffers. +// Never use this with a buffer that is a "char *" or passed +// into the function as an argument. +// +// In those cases sizeof will return the size of the pointer, +// not the number of bytes in the buffer. +#define STRBUFCPY(dst,src) strlcpy(dst, src, sizeof dst) + +#ifndef __BYTEBOOL__ + #define __BYTEBOOL__ + + //faB: clean that up !! + #if (defined (_WIN32) || (defined (_WIN32_WCE) && !defined (__GNUC__))) && !defined (_XBOX) + #define false FALSE // use windows types + #define true TRUE + #define boolean BOOL + #elif defined(_NDS) + #define boolean bool + #elif defined(_PS3) // defined(__GNUC__)? + #include //_bool_true_false_are_defined? + #define boolean bool + #else + typedef enum {false, true} boolean; + #endif + //#endif // __cplusplus +#endif // __BYTEBOOL__ + +/* 7.18.2.1 Limits of exact-width integer types */ +#ifndef INT8_MIN +#define INT8_MIN (-128) +#endif +#ifndef INT16_MIN +#define INT16_MIN (-32768) +#endif +#ifndef INT32_MIN +#define INT32_MIN (-2147483647 - 1) +#endif +#ifndef INT64_MIN +#define INT64_MIN (-9223372036854775807LL - 1) +#endif + +#ifndef INT8_MAX +#define INT8_MAX 127 +#endif +#ifndef INT16_MAX +#define INT16_MAX 32767 +#endif +#ifndef INT32_MAX +#define INT32_MAX 2147483647 +#endif +#ifndef INT64_MAX +#define INT64_MAX 9223372036854775807LL +#endif + +#ifndef UINT8_MAX +#define UINT8_MAX 0xff /* 255U */ +#endif +#ifndef UINT16_MAX +#define UINT16_MAX 0xffff /* 65535U */ +#endif +#ifndef UINT32_MAX +#define UINT32_MAX 0xffffffff /* 4294967295U */ +#endif +#ifndef UINT64_MAX +#define UINT64_MAX 0xffffffffffffffffULL /* 18446744073709551615ULL */ +#endif + +union FColorRGBA +{ + UINT32 rgba; + struct + { + UINT8 red; + UINT8 green; + UINT8 blue; + UINT8 alpha; + } s; +} ATTRPACK; +typedef union FColorRGBA RGBA_t; + +typedef enum +{ + postimg_none, + postimg_water, + postimg_motion, + postimg_flip, + postimg_heat +} postimg_t; + +typedef UINT32 lumpnum_t; // 16 : 16 unsigned long (wad num: lump num) +#define LUMPERROR UINT32_MAX + +typedef UINT32 tic_t; +#define INFTICS UINT32_MAX + +#ifdef _BIG_ENDIAN +#define UINT2RGBA(a) a +#else +#define UINT2RGBA(a) (UINT32)((a&0xff)<<24)|((a&0xff00)<<8)|((a&0xff0000)>>8)|(((UINT32)a&0xff000000)>>24) +#endif + +#ifdef __GNUC__ // __attribute__ ((X)) +#define FUNCNORETURN __attribute__ ((noreturn)) +#if ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)) && defined (__MINGW32__) +#include "inttypes.h" +#if 0 //defined (__USE_MINGW_ANSI_STDIO) && __USE_MINGW_ANSI_STDIO > 0 +#define FUNCPRINTF __attribute__ ((format(gnu_printf, 1, 2))) +#define FUNCDEBUG __attribute__ ((format(gnu_printf, 2, 3))) +#define FUNCIERROR __attribute__ ((format(gnu_printf, 1, 2),noreturn)) +#elif (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) +#define FUNCPRINTF __attribute__ ((format(ms_printf, 1, 2))) +#define FUNCDEBUG __attribute__ ((format(ms_printf, 2, 3))) +#define FUNCIERROR __attribute__ ((format(ms_printf, 1, 2),noreturn)) +#else +#define FUNCPRINTF __attribute__ ((format(printf, 1, 2))) +#define FUNCDEBUG __attribute__ ((format(printf, 2, 3))) +#define FUNCIERROR __attribute__ ((format(printf, 1, 2),noreturn)) +#endif +#else +#define FUNCPRINTF __attribute__ ((format(printf, 1, 2))) +#define FUNCDEBUG __attribute__ ((format(printf, 2, 3))) +#define FUNCIERROR __attribute__ ((format(printf, 1, 2),noreturn)) +#endif +#ifndef FUNCIERROR +#define FUNCIERROR __attribute__ ((noreturn)) +#endif +#define FUNCMATH __attribute__((const)) +#if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1) +#define FUNCDEAD __attribute__ ((deprecated)) +#define FUNCINLINE __attribute__((always_inline)) +#define FUNCNONNULL __attribute__((nonnull)) +#endif +#define FUNCNOINLINE __attribute__((noinline)) +#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) +#ifdef __i386__ // i386 only +#define FUNCTARGET(X) __attribute__ ((__target__ (X))) +#endif +#endif +#define ATTRPACK __attribute__((packed)) +#define ATTRUNUSED __attribute__((unused)) +#ifdef _XBOX +#define FILESTAMP I_OutputMsg("%s:%d\n",__FILE__,__LINE__); +#define XBOXSTATIC static +#endif +#elif defined (_MSC_VER) +#define ATTRNORETURN __declspec(noreturn) +#define ATTRINLINE __forceinline +#if _MSC_VER > 1200 +#define ATTRNOINLINE __declspec(noinline) +#endif +#endif + +#ifndef FUNCPRINTF +#define FUNCPRINTF +#endif +#ifndef FUNCDEBUG +#define FUNCDEBUG +#endif +#ifndef FUNCNORETURN +#define FUNCNORETURN +#endif +#ifndef FUNCIERROR +#define FUNCIERROR +#endif +#ifndef FUNCMATH +#define FUNCMATH +#endif +#ifndef FUNCDEAD +#define FUNCDEAD +#endif +#ifndef FUNCINLINE +#define FUNCINLINE +#endif +#ifndef FUNCNONNULL +#define FUNCNONNULL +#endif +#ifndef FUNCNOINLINE +#define FUNCNOINLINE +#endif +#ifndef FUNCTARGET +#define FUNCTARGET(x) +#endif +#ifndef ATTRPACK +#define ATTRPACK +#endif +#ifndef ATTRUNUSED +#define ATTRUNUSED +#endif +#ifndef ATTRNORETURN +#define ATTRNORETURN +#endif +#ifndef ATTRINLINE +#define ATTRINLINE inline +#endif +#ifndef ATTRNOINLINE +#define ATTRNOINLINE +#endif +#ifndef XBOXSTATIC +#define XBOXSTATIC +#endif +#ifndef FILESTAMP +#define FILESTAMP +#endif +#endif //__DOOMTYPE__ diff --git a/src/dummy/i_cdmus.c b/src/dummy/i_cdmus.c new file mode 100644 index 000000000..fc35eb9cf --- /dev/null +++ b/src/dummy/i_cdmus.c @@ -0,0 +1,38 @@ +#include "../command.h" +#include "../s_sound.h" +#include "../i_sound.h" + +// +// CD MUSIC I/O +// + +UINT8 cdaudio_started = 0; + +consvar_t cd_volume = {"cd_volume","31",CV_SAVE,soundvolume_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cdUpdate = {"cd_update","1",CV_SAVE, NULL, NULL, 0, NULL, NULL, 0, 0, NULL}; + + +void I_InitCD(void){} + +void I_StopCD(void){} + +void I_PauseCD(void){} + +void I_ResumeCD(void){} + +void I_ShutdownCD(void){} + +void I_UpdateCD(void){} + +void I_PlayCD(UINT8 track, UINT8 looping) +{ + (void)track; + (void)looping; +} + +boolean I_SetVolumeCD(int volume) +{ + (void)volume; + return false; +} + diff --git a/src/dummy/i_main.c b/src/dummy/i_main.c new file mode 100644 index 000000000..0abf53b17 --- /dev/null +++ b/src/dummy/i_main.c @@ -0,0 +1,21 @@ +#include "../doomdef.h" +#include "../d_main.h" +#include "../m_argv.h" + +int main(int argc, char **argv) +{ + myargc = argc; + myargv = argv; /// \todo pull out path to exe from this string + + // startup SRB2 + CONS_Printf("Setting up SRB2...\n"); + D_SRB2Main(); + CONS_Printf("Entering main game loop...\n"); + // never return + D_SRB2Loop(); + + // return to OS +#ifndef __GNUC__ + return 0; +#endif +} diff --git a/src/dummy/i_net.c b/src/dummy/i_net.c new file mode 100644 index 000000000..f6e642022 --- /dev/null +++ b/src/dummy/i_net.c @@ -0,0 +1,6 @@ +#include "../i_net.h" + +boolean I_InitNetwork(void) +{ + return false; +} diff --git a/src/dummy/i_sound.c b/src/dummy/i_sound.c new file mode 100644 index 000000000..51dbb610d --- /dev/null +++ b/src/dummy/i_sound.c @@ -0,0 +1,147 @@ +#include "../i_sound.h" + +UINT8 sound_started = 0; + +void *I_GetSfx(sfxinfo_t *sfx) +{ + (void)sfx; + return NULL; +} + +void I_FreeSfx(sfxinfo_t *sfx) +{ + (void)sfx; +} + +void I_StartupSound(void){} + +void I_ShutdownSound(void){} + +void I_UpdateSound(void){}; + +// +// SFX I/O +// + +INT32 I_StartSound(sfxenum_t id, UINT8 vol, UINT8 sep, UINT8 pitch, UINT8 priority) +{ + (void)id; + (void)vol; + (void)sep; + (void)pitch; + (void)priority; + return -1; +} + +void I_StopSound(INT32 handle) +{ + (void)handle; +} + +boolean I_SoundIsPlaying(INT32 handle) +{ + (void)handle; + return false; +} + +void I_UpdateSoundParams(INT32 handle, UINT8 vol, UINT8 sep, UINT8 pitch) +{ + (void)handle; + (void)vol; + (void)sep; + (void)pitch; +} + +void I_SetSfxVolume(UINT8 volume) +{ + (void)volume; +} + +// +// MUSIC I/O +// + +void I_InitMusic(void){} + +void I_ShutdownMusic(void){} + +void I_PauseSong(INT32 handle) +{ + (void)handle; +} + +void I_ResumeSong(INT32 handle) +{ + (void)handle; +} + +// +// MIDI I/O +// + +void I_InitMIDIMusic(void){} + +void I_ShutdownMIDIMusic(void){} + +void I_SetMIDIMusicVolume(UINT8 volume) +{ + (void)volume; +} + +INT32 I_RegisterSong(void *data, size_t len) +{ + (void)data; + (void)len; + return -1; +} + +boolean I_PlaySong(INT32 handle, boolean looping) +{ + (void)handle; + (void)looping; + return false; +} + +void I_StopSong(INT32 handle) +{ + (void)handle; +} + +void I_UnRegisterSong(INT32 handle) +{ + (void)handle; +} + +// +// DIGMUSIC I/O +// + +void I_InitDigMusic(void){} + +void I_ShutdownDigMusic(void){} + +boolean I_StartDigSong(const char *musicname, boolean looping) +{ + (void)musicname; + (void)looping; + return false; +} + +void I_StopDigSong(void){} + +void I_SetDigMusicVolume(UINT8 volume) +{ + (void)volume; +} + +boolean I_SetSongSpeed(float speed) +{ + (void)speed; + return false; +} + +boolean I_SetSongTrack(int track) +{ + (void)track; + return false; +} diff --git a/src/dummy/i_system.c b/src/dummy/i_system.c new file mode 100644 index 000000000..c1e48b60b --- /dev/null +++ b/src/dummy/i_system.c @@ -0,0 +1,168 @@ +#include "../doomdef.h" +#include "../i_system.h" + +UINT8 graphics_started = 0; + +UINT8 keyboard_started = 0; + +UINT32 I_GetFreeMem(UINT32 *total) +{ + *total = 0; + return 0; +} + +tic_t I_GetTime(void) +{ + return 0; +} + +void I_Sleep(void){} + +void I_GetEvent(void){} + +void I_OsPolling(void){} + +ticcmd_t *I_BaseTiccmd(void) +{ + return NULL; +} + +ticcmd_t *I_BaseTiccmd2(void) +{ + return NULL; +} + +void I_Quit(void) +{ + exit(0); +} + +void I_Error(const char *error, ...) +{ + (void)error; + exit(-1); +} + +void I_Tactile(FFType Type, const JoyFF_t *Effect) +{ + (void)Type; + (void)Effect; +} + +void I_Tactile2(FFType Type, const JoyFF_t *Effect) +{ + (void)Type; + (void)Effect; +} + +void I_JoyScale(void){} + +void I_JoyScale2(void){} + +void I_InitJoystick(void){} + +void I_InitJoystick2(void){} + +INT32 I_NumJoys(void) +{ + return 0; +} + +const char *I_GetJoyName(INT32 joyindex) +{ + (void)joyindex; + return NULL; +} + +#ifndef NOMUMBLE +void I_UpdateMumble(const mobj_t *mobj, const listener_t listener) +{ + (void)mobj; + (void)listener; +} +#endif + +void I_OutputMsg(const char *error, ...) +{ + (void)error; +} + +void I_StartupMouse(void){} + +void I_StartupMouse2(void){} + +void I_StartupKeyboard(void){} + +INT32 I_GetKey(void) +{ + return 0; +} + +void I_StartupTimer(void){} + +void I_AddExitFunc(void (*func)()) +{ + (void)func; +} + +void I_RemoveExitFunc(void (*func)()) +{ + (void)func; +} + +INT32 I_StartupSystem(void) +{ + return -1; +} + +void I_ShutdownSystem(void){} + +void I_GetDiskFreeSpace(INT64* freespace) +{ + *freespace = 0; +} + +char *I_GetUserName(void) +{ + return NULL; +} + +INT32 I_mkdir(const char *dirname, INT32 unixright) +{ + (void)dirname; + (void)unixright; + return -1; +} + +const CPUInfoFlags *I_CPUInfo(void) +{ + return NULL; +} + +const char *I_LocateWad(void) +{ + return NULL; +} + +void I_GetJoystickEvents(void){} + +void I_GetJoystick2Events(void){} + +void I_GetMouseEvents(void){} + +char *I_GetEnv(const char *name) +{ + (void)name; + return NULL; +} + +INT32 I_PutEnv(char *variable) +{ + (void)variable; + return -1; +} + +void I_RegisterSysCommands(void) {} + +#include "../sdl/dosstr.c" + diff --git a/src/dummy/i_video.c b/src/dummy/i_video.c new file mode 100644 index 000000000..e167e833f --- /dev/null +++ b/src/dummy/i_video.c @@ -0,0 +1,67 @@ +#include "../doomdef.h" +#include "../command.h" +#include "../i_video.h" + +rendermode_t rendermode = render_none; + +boolean highcolor = false; + +boolean allow_fullscreen = false; + +consvar_t cv_vidwait = {"vid_wait", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + +void I_StartupGraphics(void){} + +void I_ShutdownGraphics(void){} + +void I_SetPalette(RGBA_t *palette) +{ + (void)palette; +} + +INT32 VID_NumModes(void) +{ + return 0; +} + +INT32 VID_GetModeForSize(INT32 w, INT32 h) +{ + (void)w; + (void)h; + return 0; +} + +void VID_PrepareModeList(void){} + +INT32 VID_SetMode(INT32 modenum) +{ + (void)modenum; + return 0; +} + +const char *VID_GetModeName(INT32 modenum) +{ + (void)modenum; + return NULL; +} + +void I_UpdateNoBlit(void){} + +void I_FinishUpdate(void){} + +void I_UpdateNoVsync(void) {} + +void I_WaitVBL(INT32 count) +{ + (void)count; +} + +void I_ReadScreen(UINT8 *scr) +{ + (void)scr; +} + +void I_BeginRead(void){} + +void I_EndRead(void){} + diff --git a/src/f_finale.c b/src/f_finale.c new file mode 100644 index 000000000..c6fde99b0 --- /dev/null +++ b/src/f_finale.c @@ -0,0 +1,1860 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 1993-1996 by id Software, Inc. +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Copyright (C) 1999-2014 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file f_finale.c +/// \brief Title screen, intro, game evaluation, and credits. + +#include "doomdef.h" +#include "doomstat.h" +#include "d_main.h" +#include "f_finale.h" +#include "g_game.h" +#include "hu_stuff.h" +#include "r_local.h" +#include "s_sound.h" +#include "i_video.h" +#include "v_video.h" +#include "w_wad.h" +#include "z_zone.h" +#include "i_system.h" +#include "m_menu.h" +#include "dehacked.h" +#include "g_input.h" +#include "console.h" +#include "m_random.h" +#include "y_inter.h" +#include "m_cond.h" + +// Stage of animation: +// 0 = text, 1 = art screen +static INT32 finalecount; +INT32 titlescrollspeed = 80; + +static INT32 timetonext; // Delay between screen changes +static INT32 continuetime; // Short delay when continuing + +static tic_t animtimer; // Used for some animation timings +static INT32 roidtics; // Asteroid spinning + +static INT32 deplete; +static tic_t stoptimer; + +static boolean keypressed = false; + +// (no longer) De-Demo'd Title Screen +static UINT8 curDemo = 0; +static UINT32 demoDelayLeft; +static UINT32 demoIdleLeft; + +static patch_t *ttbanner; // white banner with "robo blast" and "2" +static patch_t *ttwing; // wing background +static patch_t *ttsonic; // "SONIC" +static patch_t *ttswave1; // Title Sonics +static patch_t *ttswave2; +static patch_t *ttswip1; +static patch_t *ttsprep1; +static patch_t *ttsprep2; +static patch_t *ttspop1; +static patch_t *ttspop2; +static patch_t *ttspop3; +static patch_t *ttspop4; +static patch_t *ttspop5; +static patch_t *ttspop6; +static patch_t *ttspop7; + +static void F_SkyScroll(INT32 scrollspeed); + +// +// CUTSCENE TEXT WRITING +// +static const char *cutscene_basetext = NULL; +static char cutscene_disptext[1024]; +static INT32 cutscene_baseptr = 0; +static INT32 cutscene_writeptr = 0; +static INT32 cutscene_textcount = 0; +static INT32 cutscene_textspeed = 0; +static UINT8 cutscene_boostspeed = 0; +static tic_t cutscene_lasttextwrite = 0; + +// +// This alters the text string cutscene_disptext. +// Use the typical string drawing functions to display it. +// Returns 0 if \0 is reached (end of input) +// +static UINT8 F_WriteText(void) +{ + INT32 numtowrite = 1; + const char *c; + tic_t ltw = I_GetTime(); + + if (cutscene_lasttextwrite == ltw) + return 1; // singletics prevention + cutscene_lasttextwrite = ltw; + + if (cutscene_boostspeed) + { + // for custom cutscene speedup mode + numtowrite = 8; + } + else + { + // Don't draw any characters if the count was 1 or more when we started + if (--cutscene_textcount >= 0) + return 1; + + if (cutscene_textspeed < 7) + numtowrite = 8 - cutscene_textspeed; + } + + for (;numtowrite > 0;++cutscene_baseptr) + { + c = &cutscene_basetext[cutscene_baseptr]; + if (!c || !*c || *c=='#') + return 0; + + // \xA0 - \xAF = change text speed + if ((UINT8)*c >= 0xA0 && (UINT8)*c <= 0xAF) + { + cutscene_textspeed = (INT32)((UINT8)*c - 0xA0); + continue; + } + // \xB0 - \xD2 = delay character for up to one second (35 tics) + else if ((UINT8)*c >= 0xB0 && (UINT8)*c <= (0xB0+TICRATE-1)) + { + cutscene_textcount = (INT32)((UINT8)*c - 0xAF); + numtowrite = 0; + continue; + } + + cutscene_disptext[cutscene_writeptr++] = *c; + + // Ignore other control codes (color) + if ((UINT8)*c < 0x80) + --numtowrite; + } + // Reset textcount for next tic based on speed + // if it wasn't already set by a delay. + if (cutscene_textcount < 0) + { + cutscene_textcount = 0; + if (cutscene_textspeed > 7) + cutscene_textcount = cutscene_textspeed - 7; + } + return 1; +} + +static void F_NewCutscene(const char *basetext) +{ + cutscene_basetext = basetext; + memset(cutscene_disptext,0,sizeof(cutscene_disptext)); + cutscene_writeptr = cutscene_baseptr = 0; + cutscene_textspeed = 9; + cutscene_textcount = TICRATE/2; +} + +// +// F_DrawPatchCol +// +static void F_DrawPatchCol(INT32 x, patch_t *patch, INT32 col) +{ + const column_t *column; + const UINT8 *source; + UINT8 *desttop, *dest = NULL; + const UINT8 *deststop, *destbottom; + size_t count; + + desttop = screens[0] + x*vid.dupx; + deststop = screens[0] + vid.rowbytes * vid.height; + destbottom = desttop + vid.height*vid.width; + + do { + INT32 topdelta, prevdelta = -1; + column = (column_t *)((UINT8 *)patch + LONG(patch->columnofs[col])); + + // step through the posts in a column + while (column->topdelta != 0xff) + { + topdelta = column->topdelta; + if (topdelta <= prevdelta) + topdelta += prevdelta; + prevdelta = topdelta; + source = (const UINT8 *)column + 3; + dest = desttop + topdelta*vid.width; + count = column->length; + + while (count--) + { + INT32 dupycount = vid.dupy; + + while (dupycount-- && dest < destbottom) + { + INT32 dupxcount = vid.dupx; + while (dupxcount-- && dest <= deststop) + *dest++ = *source; + + dest += (vid.width - vid.dupx); + } + source++; + } + column = (const column_t *)((const UINT8 *)column + column->length + 4); + } + + desttop += SHORT(patch->height)*vid.dupy*vid.width; + } while(dest < destbottom); +} + +// +// F_SkyScroll +// +static void F_SkyScroll(INT32 scrollspeed) +{ + INT32 scrolled, x, mx, fakedwidth; + patch_t *pat; + + pat = W_CachePatchName("TITLESKY", PU_CACHE); + + animtimer = ((finalecount*scrollspeed)/16) % SHORT(pat->width); + + fakedwidth = vid.width / vid.dupx; + + if (rendermode == render_soft) + { // if only hardware rendering could be this elegant and complete + scrolled = (SHORT(pat->width) - animtimer) - 1; + for (x = 0, mx = scrolled; x < fakedwidth; x++, mx = (mx+1)%SHORT(pat->width)) + F_DrawPatchCol(x, pat, mx); + } +#ifdef HWRENDER + else if (rendermode != render_none) + { // if only software rendering could be this simple and retarded + scrolled = animtimer; + if (scrolled > 0) + V_DrawScaledPatch(scrolled - SHORT(pat->width), 0, 0, pat); + for (x = 0; x < fakedwidth; x += SHORT(pat->width)) + V_DrawScaledPatch(x + scrolled, 0, 0, pat); + } +#endif + + W_UnlockCachedPatch(pat); +} + +// ============= +// INTRO SCENE +// ============= +#define NUMINTROSCENES 16 +INT32 intro_scenenum = 0; +INT32 intro_curtime = 0; + +const char *introtext[NUMINTROSCENES]; + +static tic_t introscenetime[NUMINTROSCENES] = +{ + 7*TICRATE + (TICRATE/2), // STJr Presents + 11*TICRATE + (TICRATE/2), // Two months had passed since... + 15*TICRATE + (TICRATE/2), // As it was about to drain the rings... + 14*TICRATE, // What Sonic, Tails, and Knuckles... + 18*TICRATE, // About once every year, a strange... + 19*TICRATE + (TICRATE/2), // Curses! Eggman yelled. That ridiculous... + 19*TICRATE + (TICRATE/4), // It was only later that he had an idea... + 10*TICRATE + (TICRATE/2), // Before beginning his scheme, Eggman decided to give Sonic... + 16*TICRATE, // We're ready to fire in 15 seconds, the robot said... + 16*TICRATE, // Meanwhile, Sonic was tearing across the zones... + 16*TICRATE + (TICRATE/2), // Sonic knew he was getting closer to the city... + 17*TICRATE, // Greenflower City was gone... + 16*TICRATE + (TICRATE/2), // You're not quite as dead as we thought, huh?... + 18*TICRATE + (TICRATE/2), // Eggman took this as his cue and blasted off... + 16*TICRATE, // Easy! We go find Eggman and stop his... + 25*TICRATE, // I'm just finding what mission obje... +}; + +// custom intros +void F_StartCustomCutscene(INT32 cutscenenum, boolean precutscene, boolean resetplayer); + +void F_StartIntro(void) +{ + if (introtoplay) + { + if (!cutscenes[introtoplay - 1]) + D_StartTitle(); + else + F_StartCustomCutscene(introtoplay - 1, false, false); + return; + } + + introtext[0] = " #"; + + introtext[1] = M_GetText( + "Two months had passed since Dr. Eggman\n" + "tried to take over the world using his\n" + "Ring Satellite.\n#"); + + introtext[2] = M_GetText( + "As it was about to drain the rings\n" + "away from the planet, Sonic burst into\n" + "the Satellite and for what he thought\n" + "would be the last time,\xB4 defeated\n" + "Dr. Eggman.\n#"); + + introtext[3] = M_GetText( + "\nWhat Sonic, Tails, and Knuckles had\n" + "not anticipated was that Eggman would\n" + "return,\xB8 bringing an all new threat.\n#"); + + introtext[4] = M_GetText( + "\xA8""About once every year, a strange asteroid\n" + "hovers around the planet.\xBF It suddenly\n" + "appears from nowhere, circles around, and\n" + "\xB6- just as mysteriously as it arrives -\xB6\n" + "vanishes after about two months.\xBF\n" + "No one knows why it appears, or how.\n#"); + + introtext[5] = M_GetText( + "\xA7\"Curses!\"\xA9\xBA Eggman yelled. \xA7\"That hedgehog\n" + "and his ridiculous friends will pay\n" + "dearly for this!\"\xA9\xC8 Just then his scanner\n" + "blipped as the Black Rock made its\n" + "appearance from nowhere.\xBF Eggman looked at\n" + "the screen, and just shrugged it off.\n#"); + + introtext[6] = M_GetText( + "It was only later\n" + "that he had an\n" + "idea. \xBF\xA7\"The Black\n" + "Rock usually has a\n" + "lot of energy\n" + "within it\xAC...\xA7\xBF\n" + "If I can somehow\n" + "harness this,\xB8 I\n" + "can turn it into\n" + "the ultimate\n" + "battle station\xAC...\xA7\xBF\n" + "And every last\n" + "person will be\n" + "begging for mercy,\xB8\xA8\n" + "including Sonic!\"\n#"); + + introtext[7] = M_GetText( + "\xA8\nBefore beginning his scheme,\n" + "Eggman decided to give Sonic\n" + "a reunion party...\n#"); + + introtext[8] = M_GetText( + "\xA5\"We're\xB6 ready\xB6 to\xB4 fire\xB6 in\xB6 15\xB6 seconds!\"\xA8\xB8\n" + "The robot said, his voice crackling a\n" + "little down the com-link. \xBF\xA7\"Good!\"\xA8\xB8\n" + "Eggman sat back in his Egg-Mobile and\n" + "began to count down as he saw the\n" + "GreenFlower city on the main monitor.\n#"); + + introtext[9] = M_GetText( + "\xA5\"10...\xD2""9...\xD2""8...\"\xA8\xD2\n" + "Meanwhile, Sonic was tearing across the\n" + "zones. Everything became a blur as he\n" + "ran around loops, skimmed over water,\n" + "and catapulted himself off rocks with\n" + "his phenomenal speed.\n#"); + + introtext[10] = M_GetText( + "\xA5\"6...\xD2""5...\xD2""4...\"\xA8\xD2\n" + "Sonic knew he was getting closer to the\n" + "City, and pushed himself harder.\xB4 Finally,\n" + "the city appeared in the horizon.\xD2\xD2\n" + "\xA5\"3...\xD2""2...\xD2""1...\xD2""Zero.\"\n#"); + + introtext[11] = M_GetText( + "GreenFlower City was gone.\xC4\n" + "Sonic arrived just in time to see what\n" + "little of the 'ruins' were left.\n" + "Everyone and everything in the city\n" + "had been obliterated.\n#"); + + introtext[12] = M_GetText( + "\xA7\"You're not quite as dead as we thought,\n" + "huh?\xBF Are you going to tell us your plan as\n" + "usual or will I \xA8\xB4'have to work it out'\xA7 or\n" + "something?\"\xD2\xD2\n" + "\"We'll see\xAA...\xA7\xBF let's give you a quick warm\n" + "up, Sonic!\xA6\xC4 JETTYSYNS!\xA7\xBD Open fire!\"\n#"); + + introtext[13] = M_GetText( + "Eggman took this\n" + "as his cue and\n" + "blasted off,\n" + "leaving Sonic\n" + "and Tails behind.\xB6\n" + "Tails looked at\n" + "the ruins of the\n" + "Greenflower City\n" + "with a grim face\n" + "and sighed.\xC6\n" + "\xA7\"Now\xB6 what do we\n" + "do?\",\xA9 he asked.\n#"); + + introtext[14] = M_GetText( + "\xA7\"Easy!\xBF We go\n" + "find Eggman\n" + "and stop his\n" + "latest\n" + "insane plan.\xBF\n" + "Just like\n" + "we've always\n" + "done,\xBA right?\xD2\n\n" + "\xAE...\xA9\xD2\n\n" + "\"Tails, what\n" + "\xAA*ARE*\xA9 you\n" + "doing?\"\n#"); + + introtext[15] = M_GetText( + "\xA8\"I'm just finding what mission obje\xAC\xB1...\xBF\n" + "\xA6""a-\xB8""ha!\xBF Here it is!\xA8\xBF This will only give us\n" + "the robot's primary objective.\xBF It says\xAC\xB1...\"\n" + "\xD2\xA3\x83" + "* LOCATE AND RETRIEVE: CHAOS EMERALDS *" + "\xBF\n" + "* CLOSEST LOCATION: GREENFLOWER ZONE *" + "\x80\n\xA9\xD2\xD2" + "\"All right, then\xAF... \xD2\xD2\xA7let's go!\"\n#"); + +/* + "What are we waiting for? The first emerald is ours!" Sonic was about to + run, when he saw a shadow pass over him, he recognized the silhouette + instantly. + "Knuckles!" Sonic said. The echidna stopped his glide and landed + facing Sonic. "What are you doing here?" + He replied, "This crisis affects the Floating Island, + if that explosion I saw is anything to go by." + If you're willing to help then... let's go!" +*/ + + G_SetGamestate(GS_INTRO); + gameaction = ga_nothing; + playerdeadview = false; + paused = false; + CON_ToggleOff(); + CON_ClearHUD(); + F_NewCutscene(introtext[0]); + + intro_scenenum = 0; + finalecount = animtimer = stoptimer = 0; + roidtics = BASEVIDWIDTH - 64; + timetonext = introscenetime[intro_scenenum]; +} + +// +// F_IntroDrawScene +// +static void F_IntroDrawScene(void) +{ + boolean highres = false; + INT32 cx = 8, cy = 128; + patch_t *background = NULL; + INT32 bgxoffs = 0; + void *patch; + + // DRAW A FULL PIC INSTEAD OF FLAT! + if (intro_scenenum == 0); + else if (intro_scenenum == 1) + background = W_CachePatchName("INTRO1", PU_CACHE); + else if (intro_scenenum == 2) + { + background = W_CachePatchName("INTRO2", PU_CACHE); + highres = true; + } + else if (intro_scenenum == 3) + background = W_CachePatchName("INTRO3", PU_CACHE); + else if (intro_scenenum == 4) + background = W_CachePatchName("INTRO4", PU_CACHE); + else if (intro_scenenum == 5) + { + if (intro_curtime >= 5*TICRATE) + background = W_CachePatchName("RADAR", PU_CACHE); + else + { + background = W_CachePatchName("DRAT", PU_CACHE); + highres = true; + } + } + else if (intro_scenenum == 6) + { + background = W_CachePatchName("INTRO6", PU_CACHE); + cx = 180; + cy = 8; + } + else if (intro_scenenum == 7) + { + if (intro_curtime >= 6*TICRATE) + background = W_CachePatchName("SGRASS5", PU_CACHE); + else + background = W_CachePatchName("SGRASS1", PU_CACHE); + } + else if (intro_scenenum == 8) + { + background = W_CachePatchName("WATCHING", PU_CACHE); + highres = true; + } + else if (intro_scenenum == 9) + { + background = W_CachePatchName("ZOOMING", PU_CACHE); + highres = true; + } + else if (intro_scenenum == 10); + else if (intro_scenenum == 11) + background = W_CachePatchName("INTRO5", PU_CACHE); + else if (intro_scenenum == 12) + { + if (intro_curtime >= 7*TICRATE) + background = W_CachePatchName("CONFRONT", PU_CACHE); + else + background = W_CachePatchName("REVENGE", PU_CACHE); + highres = true; + } + else if (intro_scenenum == 13) + { + background = W_CachePatchName("TAILSSAD", PU_CACHE); + highres = true; + bgxoffs = 144; + cx = 8; + cy = 8; + } + else if (intro_scenenum == 14) + { + if (intro_curtime >= 7*TICRATE) + background = W_CachePatchName("SONICDO2", PU_CACHE); + else + background = W_CachePatchName("SONICDO1", PU_CACHE); + highres = true; + cx = 224; + cy = 8; + } + else if (intro_scenenum == 15) + { + background = W_CachePatchName("INTRO7", PU_CACHE); + highres = true; + } + + V_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, 31); + + if (background) + { + if (highres) + V_DrawSmallScaledPatch(bgxoffs, 0, 0, background); + else + V_DrawScaledPatch(bgxoffs, 0, 0, background); + } + else if (intro_scenenum == 0) // STJr presents + { + // "Waaaaaaah" intro + if (finalecount-TICRATE/2 < 4*TICRATE+23) { + // aspect is FRACUNIT/2 for 4:3 (source) resolutions, smaller for 16:10 (SRB2) resolutions + fixed_t aspect = (FRACUNIT + (FRACUNIT*4/3 - FRACUNIT*vid.width/vid.height)/2)>>1; + fixed_t x,y; + V_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, 2); + if (finalecount < 30) { // Cry! + if (finalecount < 4) + S_StopMusic(); + if (finalecount == 4) + S_ChangeMusic(mus_stjr, false); + x = (BASEVIDWIDTH< 6) { + V_DrawSciencePatch(x, y, 0, (patch = W_CachePatchName("WAHH2", PU_CACHE)), aspect); + W_UnlockCachedPatch(patch); + } + if (finalecount > 10) { + V_DrawSciencePatch(x, y, 0, (patch = W_CachePatchName("WAHH3", PU_CACHE)), aspect); + W_UnlockCachedPatch(patch); + } + if (finalecount > 14) { + V_DrawSciencePatch(x, y, 0, (patch = W_CachePatchName("WAHH4", PU_CACHE)), aspect); + W_UnlockCachedPatch(patch); + } + } + else if (finalecount-30 < 20) { // Big eggy + background = W_CachePatchName("FEEDIN", PU_CACHE); + x = (BASEVIDWIDTH< 4*TICRATE) { // Door is being raised! + int ftime = (finalecount-TICRATE/2-4*TICRATE); + y -= FixedDiv((ftime*ftime)< 5*TICRATE && timetonext < 6*TICRATE) + { + if (!(finalecount & 3)) + background = W_CachePatchName("BRITEGG1", PU_CACHE); + else + background = W_CachePatchName("DARKEGG1", PU_CACHE); + + V_DrawScaledPatch(0, 0, 0, background); + } + else if (timetonext > 3*TICRATE && timetonext < 4*TICRATE) + { + if (!(finalecount & 3)) + background = W_CachePatchName("BRITEGG2", PU_CACHE); + else + background = W_CachePatchName("DARKEGG2", PU_CACHE); + + V_DrawScaledPatch(0, 0, 0, background); + } + else if (timetonext > 1*TICRATE && timetonext < 2*TICRATE) + { + if (!(finalecount & 3)) + background = W_CachePatchName("BRITEGG3", PU_CACHE); + else + background = W_CachePatchName("DARKEGG3", PU_CACHE); + + V_DrawScaledPatch(0, 0, 0, background); + } + else + { + F_SkyScroll(80*4); + if (timetonext == 6) + { + stoptimer = finalecount; + animtimer = finalecount % 16; + } + else if (timetonext >= 0 && timetonext < 6) + { + animtimer = stoptimer; + deplete -= 32; + } + else + { + animtimer = finalecount % 16; + deplete = 160; + } + + if (finalecount & 1) + { + V_DrawScaledPatch(deplete, 8, 0, (patch = W_CachePatchName("RUN2", PU_CACHE))); + W_UnlockCachedPatch(patch); + V_DrawScaledPatch(deplete, 72, 0, (patch = W_CachePatchName("PEELOUT2", PU_CACHE))); + W_UnlockCachedPatch(patch); + } + else + { + V_DrawScaledPatch(deplete, 8, 0, (patch = W_CachePatchName("RUN1", PU_CACHE))); + W_UnlockCachedPatch(patch); + V_DrawScaledPatch(deplete, 72, 0, (patch = W_CachePatchName("PEELOUT1", PU_CACHE))); + W_UnlockCachedPatch(patch); + } + V_DrawFill(0, 112, BASEVIDWIDTH, BASEVIDHEIGHT - 112, 31); + } + } + + W_UnlockCachedPatch(background); + + if (intro_scenenum == 4) // The asteroid SPINS! + { + if (roidtics >= 0) + { + V_DrawScaledPatch(roidtics, 24, 0, + (patch = W_CachePatchName(va("ROID00%.2d", intro_curtime%35), PU_CACHE))); + W_UnlockCachedPatch(patch); + } + } + + if (animtimer) + animtimer--; + + if (intro_scenenum == 7 && intro_curtime > 7*TICRATE) + { + patch_t *sgrass; + + if (intro_curtime >= 7*TICRATE + ((TICRATE/7)*2)) + sgrass = W_CachePatchName("SGRASS4", PU_CACHE); + else if (intro_curtime >= 7*TICRATE + (TICRATE/7)) + sgrass = W_CachePatchName("SGRASS3", PU_CACHE); + else + sgrass = W_CachePatchName("SGRASS2", PU_CACHE); + V_DrawScaledPatch(123, 4, 0, sgrass); + + W_UnlockCachedPatch(sgrass); + } + + V_DrawString(cx, cy, 0, cutscene_disptext); +} + +// +// F_IntroDrawer +// +void F_IntroDrawer(void) +{ + if (timetonext <= 0) + { + if (intro_scenenum == 0) + { + if (rendermode != render_none) + { + F_WipeStartScreen(); + V_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, 31); + F_WipeEndScreen(); + F_RunWipe(99,true); + } + + S_ChangeMusic(mus_read_m, false); + } + else if (intro_scenenum == 3) + roidtics = BASEVIDWIDTH - 64; + else if (intro_scenenum == 10) + { + // The only fade to white in the entire damn game. + if (rendermode != render_none) + { + F_WipeStartScreen(); + V_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, 0); + F_WipeEndScreen(); + F_RunWipe(99,true); + } + } + else if (intro_scenenum == 15) + { + if (rendermode != render_none) + { + F_WipeStartScreen(); + V_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, 31); + F_WipeEndScreen(); + F_RunWipe(99,true); + } + + // Stay on black for a bit. =) + { + tic_t quittime; + quittime = I_GetTime() + NEWTICRATE*2; // Shortened the quit time, used to be 2 seconds + while (quittime > I_GetTime()) + { + I_OsPolling(); + I_UpdateNoBlit(); + M_Drawer(); // menu is drawn even on top of wipes + I_FinishUpdate(); // Update the screen with the image Tails 06-19-2001 + } + } + + D_StartTitle(); + return; + } + F_NewCutscene(introtext[++intro_scenenum]); + timetonext = introscenetime[intro_scenenum]; + + F_WipeStartScreen(); + wipegamestate = -1; + animtimer = stoptimer = 0; + } + + intro_curtime = introscenetime[intro_scenenum] - timetonext; + + if (rendermode != render_none) + { + if (intro_scenenum == 5 && intro_curtime == 5*TICRATE) + { + patch_t *radar = W_CachePatchName("RADAR", PU_CACHE); + + F_WipeStartScreen(); + V_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, 31); + V_DrawScaledPatch(0, 0, 0, radar); + W_UnlockCachedPatch(radar); + V_DrawString(8, 128, 0, cutscene_disptext); + + F_WipeEndScreen(); + F_RunWipe(99,true); + } + else if (intro_scenenum == 7 && intro_curtime == 6*TICRATE) // Force a wipe here + { + patch_t *grass = W_CachePatchName("SGRASS5", PU_CACHE); + + F_WipeStartScreen(); + V_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, 31); + V_DrawScaledPatch(0, 0, 0, grass); + W_UnlockCachedPatch(grass); + V_DrawString(8, 128, 0, cutscene_disptext); + + F_WipeEndScreen(); + F_RunWipe(99,true); + } + else if (intro_scenenum == 12 && intro_curtime == 7*TICRATE) + { + patch_t *confront = W_CachePatchName("CONFRONT", PU_CACHE); + + F_WipeStartScreen(); + V_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, 31); + V_DrawSmallScaledPatch(0, 0, 0, confront); + W_UnlockCachedPatch(confront); + V_DrawString(8, 128, 0, cutscene_disptext); + + F_WipeEndScreen(); + F_RunWipe(99,true); + } + if (intro_scenenum == 14 && intro_curtime == 7*TICRATE) + { + patch_t *sdo = W_CachePatchName("SONICDO2", PU_CACHE); + + F_WipeStartScreen(); + V_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, 31); + V_DrawSmallScaledPatch(0, 0, 0, sdo); + W_UnlockCachedPatch(sdo); + V_DrawString(224, 8, 0, cutscene_disptext); + + F_WipeEndScreen(); + F_RunWipe(99,true); + } + } + + F_IntroDrawScene(); +} + +// +// F_IntroTicker +// +void F_IntroTicker(void) +{ + // advance animation + finalecount++; + + if (finalecount % 3 == 0) + roidtics--; + + timetonext--; + + F_WriteText(); + + // check for skipping + if (keypressed) + keypressed = false; +} + +// +// F_IntroResponder +// +boolean F_IntroResponder(event_t *event) +{ + INT32 key = event->data1; + + // remap virtual keys (mouse & joystick buttons) + switch (key) + { + case KEY_MOUSE1: + key = KEY_ENTER; + break; + case KEY_MOUSE1 + 1: + key = KEY_BACKSPACE; + break; + case KEY_JOY1: + case KEY_JOY1 + 2: + key = KEY_ENTER; + break; + case KEY_JOY1 + 3: + key = 'n'; + break; + case KEY_JOY1 + 1: + key = KEY_BACKSPACE; + break; + case KEY_HAT1: + key = KEY_UPARROW; + break; + case KEY_HAT1 + 1: + key = KEY_DOWNARROW; + break; + case KEY_HAT1 + 2: + key = KEY_LEFTARROW; + break; + case KEY_HAT1 + 3: + key = KEY_RIGHTARROW; + break; + } + + if (event->type != ev_keydown && key != 301) + return false; + + if (key != 27 && key != KEY_ENTER && key != KEY_SPACE && key != KEY_BACKSPACE) + return false; + + if (keypressed) + return false; + + keypressed = true; + return true; +} + +// ========= +// CREDITS +// ========= +static const char *credits[] = { + "\1Sonic Team Junior", + "\1Staff", + "", + "\1Game Design", + "\"SSNTails\"", + "Ben \"Mystic\" Geyer", + "Johnny \"Sonikku\" Wallbank", + "", + "\1Programming", + "\"SSNTails\"", + "Alam \"GBC\" Arias", + "Logan \"GBA\" Arias", + "Callum Dickinson", + "Scott \"Graue\" Feeney", + "Nathan \"Jazz\" Giroux", + "Thomas \"Shadow Hog\" Igoe", + "\"Monster\" Iestyn Jealous", + "John \"JTE\" Muniz", + "Matthew \"Inuyasha\" Walsh", + "", + "\1Programming", + "\1Assistance", + "Andrew \"orospakr\" Clunis", + "Gregor \"Oogaland\" Dick", + "Julio \"Chaos Zero 64\" Guir", + "\"Kalaron\"", // Coded some of Sryder13's collection of OpenGL fixes, especially fog + "Matthew \"Shuffle\" Marsalko", + "Steven \"StroggOnMeth\" McGranahan", + "\"Morph\"", // For SRB2Morphed stuff + "Colin \"Sonict\" Pfaff", + "Sean \"Sryder13\" Ryder", + "Ben \"Cue\" Woodford", + "", + "\1Sprite Artists", + "\"SSNTails\"", + "Odi \"Iceman404\" Atunzu", + "Victor \"VAdaPEGA\" Ara\x1Fjo", // Araújo -- sorry for our limited font! D: + "Jim \"MotorRoach\" DeMello", + "Desmond \"Blade\" DesJardins", + "Sherman \"CoatRack\" DesJardins", + "Andrew \"Senku Niola\" Moran", + "David \"Instant Sonic\" Spencer Jr.", + "", + "\1Texture Artists", + "Ryan \"Blaze Hedgehog\" Bloom", + "Buddy \"KinkaJoy\" Fischer", + "Pedro \"Nev3r\" Iceta", + "Jarrett \"JEV3\" Voight", + "", + "\1Music and Sound", + "\1Production", + "\"SSNTails\"", + "Michael \"Spazzo\" Antonakes", + "Malcolm \"RedXVI\" Brown", + "David \"Bulmybag\" Bulmer", + "Paul \"Boinciel\" Clempson", + "Cyan Helkaraxe", + "Pedro \"Nev3r\" Iceta", + "\"Monster\" Iestyn Jealous", + "Jarel \"Arrow\" Jones", + "Stefan \"Stuf\" Rimalia", + "Shane Strife", + "David \"Big Wave Dave\" Spencer Sr.", + "David \"Instant Sonic\" Spencer Jr.", + "", + "\1Level Design", + "\"SSNTails\"", + "Michael \"Spazzo\" Antonakes", + "Matthew \"Fawfulfan\" Chapman", + "Paul \"Boinciel\" Clempson", + "Desmond \"Blade\" DesJardins", + "Sherman \"CoatRack\" DesJardins", + "Ben \"Mystic\" Geyer", + "Nathan \"Jazz\" Giroux", + "Dan \"Blitzzo\" Hagerstrand", + "Pedro \"Nev3r\" Iceta", + "Thomas \"Shadow Hog\" Igoe", + "Erik \"Torgo\" Nielsen", + "Wessel \"Spherallic\" Smit", + "Rob Tisdell", + "Jarrett \"JEV3\" Voight", + "Johnny \"Sonikku\" Wallbank", + "Matthew \"Inuyasha\" Walsh", + "Marco \"Digiku\" Zafra", + "", + "\1Testing", + "Hank \"FuriousFox\" Brannock", + "Cody \"SRB2 Playah\" Koester", + "Skye \"OmegaVelocity\" Meredith", + "Stephen \"HEDGESMFG\" Moellering", + "Nick \"ST218\" Molina", + "Samuel \"Prime 2.0\" Peters", + "Colin \"Sonict\" Pfaff", + "Bill \"Tets\" Reed", + "", + "\1Special Thanks", + "Doom Legacy Project", + "iD Software", + "Alex \"MistaED\" Fuller", + "FreeDoom Project", // Used some of the mancubus and rocket launcher sprites for Brak + "Randy Heit ()", // For his MSPaint sprite that we nicked + "Abigail \"Raspberry\" Fox", // (Inuyasha's girlfriend. >_> <_< >_>) + "", + "\1Thank you", + "\1for playing!", + NULL +}; + +static struct { + UINT32 x, y; + const char *patch; +} credits_pics[] = { + { 8, 80+200* 1, "CREDIT01"}, + { 4, 80+200* 2, "CREDIT13"}, + {250, 80+200* 3, "CREDIT12"}, + { 8, 80+200* 4, "CREDIT03"}, + {248, 80+200* 5, "CREDIT11"}, + { 8, 80+200* 6, "CREDIT04"}, + {112, 80+200* 7, "CREDIT10"}, + {240, 80+200* 8, "CREDIT05"}, + {120, 80+200* 9, "CREDIT06"}, + { 8, 80+200*10, "CREDIT07"}, + { 8, 80+200*11, "CREDIT08"}, + {112, 80+200*12, "CREDIT09"}, + {0, 0, NULL} +}; + +void F_StartCredits(void) +{ + G_SetGamestate(GS_CREDITS); + + // Just in case they're open ... somehow + M_ClearMenus(true); + + // Save the second we enter the credits + if ((!modifiedgame || savemoddata) && !(netgame || multiplayer) && cursaveslot >= 0) + G_SaveGame((UINT32)cursaveslot); + + if (creditscutscene) + { + F_StartCustomCutscene(creditscutscene - 1, false, false); + return; + } + + gameaction = ga_nothing; + playerdeadview = false; + paused = false; + CON_ToggleOff(); + CON_ClearHUD(); + S_StopMusic(); + + if (!modifiedgame && (M_SecretUnlocked(SECRET_PANDORA)) && ALL7EMERALDS(emeralds)) + S_ChangeMusic(mus_mapl4m, false); + else + S_ChangeMusic(mus_credit, false); + + finalecount = 0; + animtimer = 0; + timetonext = 2*TICRATE; +} + +void F_CreditDrawer(void) +{ + UINT16 i; + fixed_t y = (80<>1); + + // Draw credits text on top + for (i = 0; credits[i]; i++) + { + switch(credits[i][0]) + { + case 0: + y += 80<>FRACBITS > -20) + V_DrawCreditString((160 - (V_CreditStringWidth(&credits[i][1])>>1))<>FRACBITS > -10) + V_DrawStringAtFixed(32< vid.height) + break; + } + + if (!credits[i] && y <= 120<data1; + + // remap virtual keys (mouse & joystick buttons) + switch (key) + { + case KEY_MOUSE1: + key = KEY_ENTER; + break; + case KEY_MOUSE1 + 1: + key = KEY_BACKSPACE; + break; + case KEY_JOY1: + case KEY_JOY1 + 2: + key = KEY_ENTER; + break; + case KEY_JOY1 + 3: + key = 'n'; + break; + case KEY_JOY1 + 1: + key = KEY_BACKSPACE; + break; + case KEY_HAT1: + key = KEY_UPARROW; + break; + case KEY_HAT1 + 1: + key = KEY_DOWNARROW; + break; + case KEY_HAT1 + 2: + key = KEY_LEFTARROW; + break; + case KEY_HAT1 + 3: + key = KEY_RIGHTARROW; + break; + } + + if (!(timesBeaten) && !(netgame || multiplayer)) + return false; + + if (event->type != ev_keydown) + return false; + + if (key != KEY_ESCAPE && key != KEY_ENTER && key != KEY_SPACE && key != KEY_BACKSPACE) + return false; + + if (keypressed) + return true; + + keypressed = true; + return true; +} + +// ============ +// EVALUATION +// ============ +#define INTERVAL 50 +#define TRANSLEVEL V_80TRANS +static INT32 eemeralds_start; +static boolean drawemblem = false, drawchaosemblem = false; + +void F_StartGameEvaluation(void) +{ + // Credits option in secrets menu + if (cursaveslot == -2) + { + F_StartGameEnd(); + return; + } + + G_SetGamestate(GS_EVALUATION); + + // Just in case they're open ... somehow + M_ClearMenus(true); + + // Save the second we enter the evaluation + // We need to do this again! Remember, it's possible a mod designed skipped + // the credits sequence! + if ((!modifiedgame || savemoddata) && !(netgame || multiplayer) && cursaveslot >= 0) + G_SaveGame((UINT32)cursaveslot); + + gameaction = ga_nothing; + playerdeadview = false; + paused = false; + CON_ToggleOff(); + CON_ClearHUD(); + + finalecount = 0; +} + +void F_GameEvaluationDrawer(void) +{ + INT32 x, y, i; + const fixed_t radius = 48*FRACUNIT; + angle_t fa; + INT32 eemeralds_cur; + char patchname[7] = "CEMGx0"; + + V_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, 31); + + // Draw all the good crap here. + if (ALL7EMERALDS(emeralds)) + V_DrawString(114, 16, 0, "GOT THEM ALL!"); + else + V_DrawString(124, 16, 0, "TRY AGAIN!"); + + eemeralds_start++; + eemeralds_cur = eemeralds_start; + + for (i = 0; i < 7; ++i) + { + fa = (FixedAngle(eemeralds_cur*FRACUNIT)>>ANGLETOFINESHIFT) & FINEMASK; + x = 160 + FixedInt(FixedMul(FINECOSINE(fa),radius)); + y = 100 + FixedInt(FixedMul(FINESINE(fa),radius)); + + patchname[4] = 'A'+(char)i; + if (emeralds & (1<= 360) + eemeralds_start -= 360; + + if (finalecount == 5*TICRATE) + { + if ((!modifiedgame || savemoddata) && !(netgame || multiplayer)) + { + ++timesBeaten; + + if (ALL7EMERALDS(emeralds)) + ++timesBeatenWithEmeralds; + + if (ultimatemode) + ++timesBeatenUltimate; + + if (M_UpdateUnlockablesAndExtraEmblems()) + S_StartSound(NULL, sfx_ncitem); + + G_SaveGameData(); + } + } + + if (finalecount >= 5*TICRATE) + { + if (drawemblem) + V_DrawScaledPatch(120, 192, 0, W_CachePatchName("NWNGA0", PU_CACHE)); + + if (drawchaosemblem) + V_DrawScaledPatch(200, 192, 0, W_CachePatchName("NWNGA0", PU_CACHE)); + + V_DrawString(8, 16, V_YELLOWMAP, "Unlocked:"); + + if (!(netgame) && (!modifiedgame || savemoddata)) + { + INT32 startcoord = 32; + + for (i = 0; i < MAXUNLOCKABLES; i++) + { + if (unlockables[i].conditionset && unlockables[i].conditionset < MAXCONDITIONSETS + && unlockables[i].type && !unlockables[i].nocecho) + { + if (unlockables[i].unlocked) + V_DrawString(8, startcoord, 0, unlockables[i].name); + startcoord += 8; + } + } + } + else if (netgame) + V_DrawString(8, 96, V_YELLOWMAP, "Prizes only\nawarded in\nsingle player!"); + else + V_DrawString(8, 96, V_YELLOWMAP, "Prizes not\nawarded in\nmodified games!"); + } +} + +void F_GameEvaluationTicker(void) +{ + finalecount++; + + if (finalecount > 10*TICRATE) + F_StartGameEnd(); +} + +// ========== +// GAME END +// ========== +void F_StartGameEnd(void) +{ + G_SetGamestate(GS_GAMEEND); + + gameaction = ga_nothing; + playerdeadview = false; + paused = false; + CON_ToggleOff(); + CON_ClearHUD(); + S_StopMusic(); + + // In case menus are still up?!! + M_ClearMenus(true); + + timetonext = TICRATE; +} + +// +// F_GameEndDrawer +// +void F_GameEndDrawer(void) +{ +} + +// +// F_GameEndTicker +// +void F_GameEndTicker(void) +{ + if (timetonext > 0) + timetonext--; + else + D_StartTitle(); +} + + +// ============== +// TITLE SCREEN +// ============== +void F_StartTitleScreen(void) +{ + if (gamestate != GS_TITLESCREEN && gamestate != GS_WAITINGPLAYERS) + finalecount = 0; + else + wipegamestate = GS_TITLESCREEN; + G_SetGamestate(GS_TITLESCREEN); + CON_ClearHUD(); + + // IWAD dependent stuff. + + S_ChangeMusic(mus_titles, looptitle); + + animtimer = 0; + + demoDelayLeft = demoDelayTime; + demoIdleLeft = demoIdleTime; + + ttbanner = W_CachePatchName("TTBANNER", PU_LEVEL); + ttwing = W_CachePatchName("TTWING", PU_LEVEL); + ttsonic = W_CachePatchName("TTSONIC", PU_LEVEL); + ttswave1 = W_CachePatchName("TTSWAVE1", PU_LEVEL); + ttswave2 = W_CachePatchName("TTSWAVE2", PU_LEVEL); + ttswip1 = W_CachePatchName("TTSWIP1", PU_LEVEL); + ttsprep1 = W_CachePatchName("TTSPREP1", PU_LEVEL); + ttsprep2 = W_CachePatchName("TTSPREP2", PU_LEVEL); + ttspop1 = W_CachePatchName("TTSPOP1", PU_LEVEL); + ttspop2 = W_CachePatchName("TTSPOP2", PU_LEVEL); + ttspop3 = W_CachePatchName("TTSPOP3", PU_LEVEL); + ttspop4 = W_CachePatchName("TTSPOP4", PU_LEVEL); + ttspop5 = W_CachePatchName("TTSPOP5", PU_LEVEL); + ttspop6 = W_CachePatchName("TTSPOP6", PU_LEVEL); + ttspop7 = W_CachePatchName("TTSPOP7", PU_LEVEL); +} + +// (no longer) De-Demo'd Title Screen +void F_TitleScreenDrawer(void) +{ + if (modeattacking) + return; // We likely came here from retrying. Don't do a damn thing. + + // Draw that sky! + F_SkyScroll(titlescrollspeed); + + // Don't draw outside of the title screewn, or if the patch isn't there. + if (!ttwing || (gamestate != GS_TITLESCREEN && gamestate != GS_WAITINGPLAYERS)) + return; + + V_DrawScaledPatch(30, 14, 0, ttwing); + + if (finalecount < 57) + { + if (finalecount == 35) + V_DrawScaledPatch(115, 15, 0, ttspop1); + else if (finalecount == 36) + V_DrawScaledPatch(114, 15, 0,ttspop2); + else if (finalecount == 37) + V_DrawScaledPatch(113, 15, 0,ttspop3); + else if (finalecount == 38) + V_DrawScaledPatch(112, 15, 0,ttspop4); + else if (finalecount == 39) + V_DrawScaledPatch(111, 15, 0,ttspop5); + else if (finalecount == 40) + V_DrawScaledPatch(110, 15, 0, ttspop6); + else if (finalecount >= 41 && finalecount <= 44) + V_DrawScaledPatch(109, 15, 0, ttspop7); + else if (finalecount >= 45 && finalecount <= 48) + V_DrawScaledPatch(108, 12, 0, ttsprep1); + else if (finalecount >= 49 && finalecount <= 52) + V_DrawScaledPatch(107, 9, 0, ttsprep2); + else if (finalecount >= 53 && finalecount <= 56) + V_DrawScaledPatch(106, 6, 0, ttswip1); + V_DrawScaledPatch(93, 106, 0, ttsonic); + } + else + { + V_DrawScaledPatch(93, 106, 0,ttsonic); + if (finalecount/5 & 1) + V_DrawScaledPatch(100, 3, 0,ttswave1); + else + V_DrawScaledPatch(100,3, 0,ttswave2); + } + + V_DrawScaledPatch(48, 142, 0,ttbanner); +} + +// (no longer) De-Demo'd Title Screen +void F_TitleScreenTicker(boolean run) +{ + if (run) + finalecount++; + + // don't trigger if doing anything besides idling on title + if (gameaction != ga_nothing || gamestate != GS_TITLESCREEN) + return; + + // no demos to play? or, are they disabled? + if (!cv_rollingdemos.value || !numDemos) + return; + + // Wait for a while (for the music to finish, preferably) + // before starting demos + if (demoDelayLeft) + { + --demoDelayLeft; + return; + } + + // Hold up for a bit if menu or console active + if (menuactive || CON_Ready()) + { + demoIdleLeft = demoIdleTime; + return; + } + + // is it time? + if (!(--demoIdleLeft)) + { + char dname[9]; + lumpnum_t l; + + // prevent console spam if failed + demoIdleLeft = demoIdleTime; + + // Replay intro when done cycling through demos + if (curDemo == numDemos) + { + curDemo = 0; + F_StartIntro(); + return; + } + + // Setup demo name + snprintf(dname, 9, "DEMO_%03u", ++curDemo); + + if ((l = W_CheckNumForName(dname)) == LUMPERROR) + { + CONS_Alert(CONS_ERROR, M_GetText("Demo lump \"%s\" doesn't exist\n"), dname); + F_StartIntro(); + return; + } + + titledemo = true; + G_DoPlayDemo(dname); + } +} + +void F_TitleDemoTicker(void) +{ + keypressed = false; +} + +// ========== +// CONTINUE +// ========== +void F_StartContinue(void) +{ + I_Assert(!netgame && !multiplayer); + + if (players[consoleplayer].continues <= 0) + { + Command_ExitGame_f(); + return; + } + + G_SetGamestate(GS_CONTINUING); + gameaction = ga_nothing; + + keypressed = false; + playerdeadview = false; + paused = false; + CON_ToggleOff(); + CON_ClearHUD(); + + // In case menus are still up?!! + M_ClearMenus(true); + + S_ChangeMusic(mus_contsc, false); + S_StopSounds(); + + timetonext = TICRATE*11; +} + +// +// F_ContinueDrawer +// Moved continuing out of the HUD (hack removal!!) +// +void F_ContinueDrawer(void) +{ + patch_t *contsonic; + INT32 i, x = (BASEVIDWIDTH/2) + 4, ncontinues = players[consoleplayer].continues; + if (ncontinues > 20) + ncontinues = 20; + + if (imcontinuing) + contsonic = W_CachePatchName("CONT2", PU_CACHE); + else + contsonic = W_CachePatchName("CONT1", PU_CACHE); + + V_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, 31); + V_DrawCenteredString(BASEVIDWIDTH/2, 100, 0, "CONTINUE?"); + + // Draw a Sonic! + V_DrawScaledPatch((BASEVIDWIDTH - SHORT(contsonic->width))/2, 32, 0, contsonic); + + // Draw the continue markers! Show continues minus one. + x -= ncontinues * 6; + for (i = 0; i < ncontinues; ++i) + V_DrawContinueIcon(x + (i*12), 140, 0, players[consoleplayer].skin, players[consoleplayer].skincolor); + + V_DrawCenteredString(BASEVIDWIDTH/2, 168, 0, va("\x82*\x80" " %02d " "\x82*\x80", timetonext/TICRATE)); +} + +void F_ContinueTicker(void) +{ + if (!imcontinuing) + { + // note the setup to prevent 2x reloading + if (timetonext >= 0) + timetonext--; + if (timetonext == 0) + Command_ExitGame_f(); + } + else + { + // note the setup to prevent 2x reloading + if (continuetime >= 0) + continuetime--; + if (continuetime == 0) + G_Continue(); + } +} + +boolean F_ContinueResponder(event_t *event) +{ + INT32 key = event->data1; + + if (keypressed) + return true; + + if (timetonext >= 21*TICRATE/2) + return false; + if (event->type != ev_keydown) + return false; + + // remap virtual keys (mouse & joystick buttons) + switch (key) + { + case KEY_ENTER: + case KEY_SPACE: + case KEY_MOUSE1: + case KEY_JOY1: + case KEY_JOY1 + 2: + break; + default: + return false; + } + + keypressed = true; + imcontinuing = true; + continuetime = TICRATE; + S_StartSound(0, sfx_itemup); + return true; +} + +// ================== +// CUSTOM CUTSCENES +// ================== +static INT32 scenenum, cutnum; +static INT32 picxpos, picypos, picnum, pictime; +static INT32 textxpos, textypos; +static boolean dofadenow = false, cutsceneover = false; +static boolean runningprecutscene = false, precutresetplayer = false; + +static void F_AdvanceToNextScene(void) +{ + // Don't increment until after endcutscene check + // (possible overflow / bad patch names from the one tic drawn before the fade) + if (scenenum+1 >= cutscenes[cutnum]->numscenes) + { + F_EndCutScene(); + return; + } + ++scenenum; + + timetonext = 0; + stoptimer = 0; + picnum = 0; + picxpos = cutscenes[cutnum]->scene[scenenum].xcoord[picnum]; + picypos = cutscenes[cutnum]->scene[scenenum].ycoord[picnum]; + + if (cutscenes[cutnum]->scene[scenenum].musicslot != 0) + S_ChangeMusic(cutscenes[cutnum]->scene[scenenum].musicslot, cutscenes[cutnum]->scene[scenenum].musicloop); + + // Fade to the next + dofadenow = true; + F_NewCutscene(cutscenes[cutnum]->scene[scenenum].text); + + picnum = 0; + picxpos = cutscenes[cutnum]->scene[scenenum].xcoord[picnum]; + picypos = cutscenes[cutnum]->scene[scenenum].ycoord[picnum]; + textxpos = cutscenes[cutnum]->scene[scenenum].textxpos; + textypos = cutscenes[cutnum]->scene[scenenum].textypos; + + animtimer = pictime = cutscenes[cutnum]->scene[scenenum].picduration[picnum]; +} + +void F_EndCutScene(void) +{ + if (runningprecutscene) + { + if (server) + D_MapChange(gamemap, gametype, ultimatemode, precutresetplayer, 0, true, false); + } + else + { + if (cutnum == creditscutscene-1) + F_StartGameEvaluation(); + else if (cutnum == introtoplay-1) + D_StartTitle(); + else if (nextmap < 1100-1) + G_NextLevel(); + else + Y_EndGame(); + } + cutsceneover = true; +} + +void F_StartCustomCutscene(INT32 cutscenenum, boolean precutscene, boolean resetplayer) +{ + if (!cutscenes[cutscenenum]) + return; + + G_SetGamestate(GS_CUTSCENE); + + gameaction = ga_nothing; + playerdeadview = false; + paused = false; + CON_ToggleOff(); + + F_NewCutscene(cutscenes[cutscenenum]->scene[0].text); + + CON_ClearHUD(); + + cutsceneover = false; + runningprecutscene = precutscene; + precutresetplayer = resetplayer; + + scenenum = picnum = 0; + cutnum = cutscenenum; + picxpos = cutscenes[cutnum]->scene[0].xcoord[0]; + picypos = cutscenes[cutnum]->scene[0].ycoord[0]; + textxpos = cutscenes[cutnum]->scene[0].textxpos; + textypos = cutscenes[cutnum]->scene[0].textypos; + + pictime = cutscenes[cutnum]->scene[0].picduration[0]; + + keypressed = false; + finalecount = 0; + timetonext = 0; + animtimer = cutscenes[cutnum]->scene[0].picduration[0]; // Picture duration + stoptimer = 0; + + if (cutscenes[cutnum]->scene[scenenum].musicslot != 0) + S_ChangeMusic(cutscenes[cutnum]->scene[scenenum].musicslot, cutscenes[cutnum]->scene[scenenum].musicloop); + else + S_StopMusic(); +} + +// +// F_CutsceneDrawer +// +void F_CutsceneDrawer(void) +{ + if (dofadenow && rendermode != render_none) + { + F_WipeStartScreen(); + + // Fade to any palette color you want. + if (cutscenes[cutnum]->scene[scenenum].fadecolor) + { + V_DrawFill(0,0,BASEVIDWIDTH,BASEVIDHEIGHT,cutscenes[cutnum]->scene[scenenum].fadecolor); + + F_WipeEndScreen(); + F_RunWipe(cutscenes[cutnum]->scene[scenenum].fadeinid, true); + + F_WipeStartScreen(); + } + } + V_DrawFill(0,0, BASEVIDWIDTH, BASEVIDHEIGHT, 31); + + if (cutscenes[cutnum]->scene[scenenum].picname[picnum][0] != '\0') + { + if (cutscenes[cutnum]->scene[scenenum].pichires[picnum]) + V_DrawSmallScaledPatch(picxpos, picypos, 0, + W_CachePatchName(cutscenes[cutnum]->scene[scenenum].picname[picnum], PU_CACHE)); + else + V_DrawScaledPatch(picxpos,picypos, 0, + W_CachePatchName(cutscenes[cutnum]->scene[scenenum].picname[picnum], PU_CACHE)); + } + + if (dofadenow && rendermode != render_none) + { + F_WipeEndScreen(); + F_RunWipe(cutscenes[cutnum]->scene[scenenum].fadeoutid, true); + } + + V_DrawString(textxpos, textypos, 0, cutscene_disptext); +} + +void F_CutsceneTicker(void) +{ + INT32 i; + + // Online clients tend not to instantly get the map change, so just wait + // and don't send 30 of them. + if (cutsceneover) + return; + + // advance animation + finalecount++; + cutscene_boostspeed = 0; + + dofadenow = false; + + for (i = 0; i < MAXPLAYERS; i++) + { + if (netgame && i != serverplayer && i != adminplayer) + continue; + + if (players[i].cmd.buttons & BT_USE) + { + keypressed = false; + cutscene_boostspeed = 1; + if (timetonext) + timetonext = 2; + } + } + + if (animtimer) + { + animtimer--; + if (animtimer <= 0) + { + if (picnum < 7 && cutscenes[cutnum]->scene[scenenum].picname[picnum+1][0] != '\0') + { + picnum++; + picxpos = cutscenes[cutnum]->scene[scenenum].xcoord[picnum]; + picypos = cutscenes[cutnum]->scene[scenenum].ycoord[picnum]; + pictime = cutscenes[cutnum]->scene[scenenum].picduration[picnum]; + animtimer = pictime; + } + else + timetonext = 2; + } + } + + if (timetonext) + --timetonext; + + if (++stoptimer > 2 && timetonext == 1) + F_AdvanceToNextScene(); + else if (!timetonext && !F_WriteText()) + timetonext = 5*TICRATE + 1; +} + +boolean F_CutsceneResponder(event_t *event) +{ + if (cutnum == introtoplay-1) + return F_IntroResponder(event); + + return false; +} diff --git a/src/f_finale.h b/src/f_finale.h new file mode 100644 index 000000000..97a26f4c4 --- /dev/null +++ b/src/f_finale.h @@ -0,0 +1,114 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 1993-1996 by id Software, Inc. +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Copyright (C) 1999-2014 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file f_finale.h +/// \brief Title screen, intro, game evaluation, and credits. +/// Also includes protos for screen wipe functions. + +#ifndef __F_FINALE__ +#define __F_FINALE__ + +#include "doomtype.h" +#include "d_event.h" + +// +// FINALE +// + +// Called by main loop. +boolean F_IntroResponder(event_t *ev); +boolean F_CutsceneResponder(event_t *ev); +boolean F_CreditResponder(event_t *ev); + +// Called by main loop. +void F_GameEndTicker(void); +void F_IntroTicker(void); +void F_TitleScreenTicker(boolean run); +void F_CutsceneTicker(void); +void F_TitleDemoTicker(void); + +// Called by main loop. +void F_GameEndDrawer(void); +void F_IntroDrawer(void); +void F_TitleScreenDrawer(void); + +void F_GameEvaluationDrawer(void); +void F_StartGameEvaluation(void); +void F_GameEvaluationTicker(void); + +void F_CreditTicker(void); +void F_CreditDrawer(void); + +void F_StartCustomCutscene(INT32 cutscenenum, boolean precutscene, boolean resetplayer); +void F_CutsceneDrawer(void); +void F_EndCutScene(void); + +void F_StartGameEnd(void); +void F_StartIntro(void); +void F_StartTitleScreen(void); +void F_StartCredits(void); + +boolean F_ContinueResponder(event_t *event); +void F_StartContinue(void); +void F_ContinueTicker(void); +void F_ContinueDrawer(void); + +extern INT32 titlescrollspeed; + +// +// WIPE +// +extern boolean WipeInAction; +extern INT32 lastwipetic; + +void F_WipeStartScreen(void); +void F_WipeEndScreen(void); +void F_RunWipe(UINT8 wipetype, boolean drawMenu); + +enum +{ + wipe_credits_intermediate, // makes a good 0 I guess. + + wipe_level_toblack, + wipe_intermission_toblack, + wipe_continuing_toblack, + wipe_titlescreen_toblack, + wipe_timeattack_toblack, + wipe_credits_toblack, + wipe_evaluation_toblack, + wipe_gameend_toblack, + wipe_intro_toblack, + wipe_cutscene_toblack, + + // custom intermissions + wipe_specinter_toblack, + wipe_multinter_toblack, + + wipe_level_final, + wipe_intermission_final, + wipe_continuing_final, + wipe_titlescreen_final, + wipe_timeattack_final, + wipe_credits_final, + wipe_evaluation_final, + wipe_gameend_final, + wipe_intro_final, + wipe_cutscene_final, + + // custom intermissions + wipe_specinter_final, + wipe_multinter_final, + + NUMWIPEDEFS +}; +#define WIPEFINALSHIFT 12 +extern UINT8 wipedefs[NUMWIPEDEFS]; + +#endif diff --git a/src/f_wipe.c b/src/f_wipe.c new file mode 100644 index 000000000..fe740408f --- /dev/null +++ b/src/f_wipe.c @@ -0,0 +1,299 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 1993-1996 by id Software, Inc. +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Copyright (C) 2013-2014 by Matthew "Inuyasha" Walsh. +// Copyright (C) 1999-2014 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file f_wipe.c +/// \brief SRB2 2.1 custom fade mask "wipe" behavior. + +#include "f_finale.h" +#include "i_video.h" +#include "v_video.h" + +#include "r_draw.h" // transtable +#include "p_pspr.h" // tr_transxxx +#include "w_wad.h" +#include "z_zone.h" + +#include "i_system.h" +#include "m_menu.h" +#include "console.h" +#include "d_main.h" +#include "m_misc.h" // movie mode + +#ifdef HWRENDER +#include "hardware/hw_main.h" +#endif + +#if NUMSCREENS < 5 +#define NOWIPE // do not enable wipe image post processing for ARM, SH and MIPS CPUs +#endif + +typedef struct fademask_s { + UINT8* mask; + UINT16 width, height; + size_t size; + fixed_t xscale, yscale; +} fademask_t; + +UINT8 wipedefs[NUMWIPEDEFS] = { + 99, // wipe_credits_intermediate (0) + + 0, // wipe_level_toblack + UINT8_MAX, // wipe_intermission_toblack + UINT8_MAX, // wipe_continuing_toblack + 0, // wipe_titlescreen_toblack + 0, // wipe_timeattack_toblack + 99, // wipe_credits_toblack + 0, // wipe_evaluation_toblack + 0, // wipe_gameend_toblack + 99, // wipe_intro_toblack (hardcoded) + 99, // wipe_cutscene_toblack (hardcoded) + + 0, // wipe_specinter_toblack + 0, // wipe_multinter_toblack + + 0, // wipe_level_final + 0, // wipe_intermission_final + 0, // wipe_continuing_final + 0, // wipe_titlescreen_final + 0, // wipe_timeattack_final + 99, // wipe_credits_final + 0, // wipe_evaluation_final + 0, // wipe_gameend_final + 99, // wipe_intro_final (hardcoded) + 99, // wipe_cutscene_final (hardcoded) + + 0, // wipe_specinter_final + 0 // wipe_multinter_final +}; + +//-------------------------------------------------------------------------- +// SCREEN WIPE PACKAGE +//-------------------------------------------------------------------------- + +boolean WipeInAction = false; +INT32 lastwipetic = 0; + +#ifndef NOWIPE +static UINT8 *wipe_scr_start; //screen 3 +static UINT8 *wipe_scr_end; //screen 4 +static UINT8 *wipe_scr; //screen 0 (main drawing) +static fixed_t paldiv; + +/** Create fademask_t from lump + * + * \param lump Lump name to get data from + * \return fademask_t for lump + */ +static fademask_t *F_GetFadeMask(UINT8 masknum, UINT8 scrnnum) { + static char lumpname[9] = "FADEmmss"; + static fademask_t fm = {NULL,0,0,0,0,0}; + lumpnum_t lumpnum; + UINT8 *lump, *mask; + size_t lsize; + RGBA_t *pcolor; + + if (masknum > 99 || scrnnum > 99) + goto freemask; + + sprintf(&lumpname[4], "%.2hu%.2hu", (UINT16)masknum, (UINT16)scrnnum); + + lumpnum = W_CheckNumForName(lumpname); + if (lumpnum == LUMPERROR) + goto freemask; + + lump = W_CacheLumpNum(lumpnum, PU_CACHE); + lsize = W_LumpLength(lumpnum); + switch (lsize) + { + case 256000: // 640x400 + fm.width = 640; + fm.height = 400; + break; + case 64000: // 320x200 + fm.width = 320; + fm.height = 200; + break; + case 16000: // 160x100 + fm.width = 160; + fm.height = 100; + break; + case 4000: // 80x50 (minimum) + fm.width = 80; + fm.height = 50; + break; + + default: // bad lump + CONS_Alert(CONS_WARNING, "Fade mask lump %s of incorrect size, ignored\n", lumpname); + case 0: // end marker (not bad!, but still need clearing) + goto freemask; + } + if (lsize != fm.size) + fm.mask = Z_Realloc(fm.mask, lsize, PU_STATIC, NULL); + fm.size = lsize; + + mask = fm.mask; + + while (lsize--) + { + // Determine pixel to use from fademask + pcolor = &pLocalPalette[*lump++]; + *mask++ = FixedDiv((pcolor->s.red+1)<>FRACBITS; + } + + fm.xscale = FixedDiv(fm.width<mask[ // y*width + x + (FixedMul(y<yscale)>>FRACBITS)*fademask->width + + (FixedMul(x<xscale)>>FRACBITS) + ]; + + if (transval == 0) + *w = *s; + else if (transval == 10) + *w = *e; + else + *w = transtables[(*e<<8) + *s + ((9 - transval)<= vid.width) + { + x = 0; + ++y; + } + } while (++w && ++s && ++e && w < wipe_scr + vid.width*vid.height); +} +#endif + +/** Save the "before" screen of a wipe. + */ +void F_WipeStartScreen(void) +{ +#ifndef NOWIPE +#ifdef HWRENDER + if(rendermode != render_soft) + { + HWR_StartScreenWipe(); + return; + } +#endif + wipe_scr_start = screens[3]; + I_ReadScreen(wipe_scr_start); +#endif +} + +/** Save the "after" screen of a wipe. + */ +void F_WipeEndScreen(void) +{ +#ifndef NOWIPE +#ifdef HWRENDER + if(rendermode != render_soft) + { + HWR_EndScreenWipe(); + return; + } +#endif + wipe_scr_end = screens[4]; + I_ReadScreen(wipe_scr_end); + V_DrawBlock(0, 0, 0, vid.width, vid.height, wipe_scr_start); +#endif +} + +/** After setting up the screens you want to wipe, + * calling this will do a 'typical' wipe. + */ +void F_RunWipe(UINT8 wipetype, boolean drawMenu) +{ +#ifdef NOWIPE + (void)wipetype; + (void)drawMenu; +#else + tic_t nowtime; + UINT8 wipeframe = 0; + fademask_t *fmask; + + paldiv = FixedDiv(257< +#ifdef __GNUC__ +#include +#endif +#if defined (_WIN32) && !defined (_XBOX) +//#define WIN32_LEAN_AND_MEAN +#define RPC_NO_WINDOWS_H +#include +#endif +#ifdef _WIN32_WCE +#include "sdl/SRB2CE/cehelp.h" +#else +#include +#endif +#include + +#include "filesrch.h" +#include "d_netfil.h" +#include "m_misc.h" + +#if (defined (_WIN32) && !defined (_WIN32_WCE)) && defined (_MSC_VER) && !defined (_XBOX) + +#include +#include +#include + +#define SUFFIX "*" +#define SLASH "\\" +#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) + +#ifndef INVALID_FILE_ATTRIBUTES +#define INVALID_FILE_ATTRIBUTES ((DWORD)-1) +#endif + +struct dirent +{ + long d_ino; /* Always zero. */ + unsigned short d_reclen; /* Always zero. */ + unsigned short d_namlen; /* Length of name in d_name. */ + char d_name[FILENAME_MAX]; /* File name. */ +}; + +/* + * This is an internal data structure. Good programmers will not use it + * except as an argument to one of the functions below. + * dd_stat field is now int (was short in older versions). + */ +typedef struct +{ + /* disk transfer area for this dir */ + struct _finddata_t dd_dta; + + /* dirent struct to return from dir (NOTE: this makes this thread + * safe as long as only one thread uses a particular DIR struct at + * a time) */ + struct dirent dd_dir; + + /* _findnext handle */ +#if _MSC_VER > 1200 + intptr_t dd_handle; +#else + long dd_handle; +#endif + + /* + * Status of search: + * 0 = not started yet (next entry to read is first entry) + * -1 = off the end + * positive = 0 based index of next entry + */ + int dd_stat; + + /* given path for dir with search pattern (struct is extended) */ + CHAR dd_name[1]; +} DIR; + +/* + * opendir + * + * Returns a pointer to a DIR structure appropriately filled in to begin + * searching a directory. + */ + +DIR * +opendir (const CHAR *szPath) +{ + DIR *nd; + DWORD rc; + CHAR szFullPath[MAX_PATH]; + + errno = 0; + + if (!szPath) + { + errno = EFAULT; + return (DIR *) 0; + } + + if (szPath[0] == '\0') + { + errno = ENOTDIR; + return (DIR *) 0; + } + + /* Attempt to determine if the given path really is a directory. */ + rc = GetFileAttributesA(szPath); + if (rc == INVALID_FILE_ATTRIBUTES) + { + /* call GetLastError for more error info */ + errno = ENOENT; + return (DIR *) 0; + } + if (!(rc & FILE_ATTRIBUTE_DIRECTORY)) + { + /* Error, entry exists but not a directory. */ + errno = ENOTDIR; + return (DIR *) 0; + } + + /* Make an absolute pathname. */ + _fullpath (szFullPath, szPath, MAX_PATH); + + /* Allocate enough space to store DIR structure and the complete + * directory path given. */ + nd = (DIR *) malloc (sizeof (DIR) + (strlen(szFullPath) + strlen (SLASH) + + strlen(SUFFIX) + 1) * sizeof (CHAR)); + + if (!nd) + { + /* Error, out of memory. */ + errno = ENOMEM; + return (DIR *) 0; + } + + /* Create the search expression. */ + strcpy (nd->dd_name, szFullPath); + + /* Add on a slash if the path does not end with one. */ + if (nd->dd_name[0] != '\0' && + nd->dd_name[strlen (nd->dd_name) - 1] != '/' && + nd->dd_name[strlen (nd->dd_name) - 1] != '\\') + { + strcat (nd->dd_name, SLASH); + } + + /* Add on the search pattern */ + strcat (nd->dd_name, SUFFIX); + + /* Initialize handle to -1 so that a premature closedir doesn't try + * to call _findclose on it. */ + nd->dd_handle = -1; + + /* Initialize the status. */ + nd->dd_stat = 0; + + /* Initialize the dirent structure. ino and reclen are invalid under + * Win32, and name simply points at the appropriate part of the + * findfirst_t structure. */ + nd->dd_dir.d_ino = 0; + nd->dd_dir.d_reclen = 0; + nd->dd_dir.d_namlen = 0; + ZeroMemory(nd->dd_dir.d_name, FILENAME_MAX); + + return nd; +} + +/* + * readdir + * + * Return a pointer to a dirent structure filled with the information on the + * next entry in the directory. + */ +struct dirent * +readdir (DIR * dirp) +{ + errno = 0; + + /* Check for valid DIR struct. */ + if (!dirp) + { + errno = EFAULT; + return (struct dirent *) 0; + } + + if (dirp->dd_stat < 0) + { + /* We have already returned all files in the directory + * (or the structure has an invalid dd_stat). */ + return (struct dirent *) 0; + } + else if (dirp->dd_stat == 0) + { + /* We haven't started the search yet. */ + /* Start the search */ + dirp->dd_handle = _findfirst (dirp->dd_name, &(dirp->dd_dta)); + + if (dirp->dd_handle == -1) + { + /* Whoops! Seems there are no files in that + * directory. */ + dirp->dd_stat = -1; + } + else + { + dirp->dd_stat = 1; + } + } + else + { + /* Get the next search entry. */ + if (_findnext (dirp->dd_handle, &(dirp->dd_dta))) + { + /* We are off the end or otherwise error. + _findnext sets errno to ENOENT if no more file + Undo this. */ + DWORD winerr = GetLastError(); + if (winerr == ERROR_NO_MORE_FILES) + errno = 0; + _findclose (dirp->dd_handle); + dirp->dd_handle = -1; + dirp->dd_stat = -1; + } + else + { + /* Update the status to indicate the correct + * number. */ + dirp->dd_stat++; + } + } + + if (dirp->dd_stat > 0) + { + /* Successfully got an entry. Everything about the file is + * already appropriately filled in except the length of the + * file name. */ + dirp->dd_dir.d_namlen = (unsigned short)strlen (dirp->dd_dta.name); + strcpy (dirp->dd_dir.d_name, dirp->dd_dta.name); + return &dirp->dd_dir; + } + + return (struct dirent *) 0; +} + +/* + * closedir + * + * Frees up resources allocated by opendir. + */ +int +closedir (DIR * dirp) +{ + int rc; + + errno = 0; + rc = 0; + + if (!dirp) + { + errno = EFAULT; + return -1; + } + + if (dirp->dd_handle != -1) + { + rc = _findclose (dirp->dd_handle); + } + + /* Delete the dir structure. */ + free (dirp); + + return rc; +} +#endif +#if defined (_XBOX) && defined (_MSC_VER) +filestatus_t filesearch(char *filename, const char *startpath, const UINT8 *wantedmd5sum, + boolean completepath, int maxsearchdepth) +{ +//NONE? + startpath = filename = NULL; + wantedmd5sum = NULL; + maxsearchdepth = 0; + completepath = false; + return FS_NOTFOUND; +} +#elif defined (_WIN32_WCE) +filestatus_t filesearch(char *filename, const char *startpath, const UINT8 *wantedmd5sum, + boolean completepath, int maxsearchdepth) +{ +#ifdef __GNUC__ +//NONE? + startpath = filename = NULL; + wantedmd5sum = NULL; + maxsearchdepth = 0; + completepath = false; +#else + WIN32_FIND_DATA dta; + HANDLE searchhandle = INVALID_HANDLE_VALUE; + const wchar_t wm[4] = L"*.*"; + + //if (startpath) SetCurrentDirectory(startpath); + if (FIL_ReadFileOK(filename)) + { + // checkfilemd5 returns an FS_* value, either FS_FOUND or FS_MD5SUMBAD + return checkfilemd5(filename, wantedmd5sum); + } + ZeroMemory(&dta,sizeof (dta)); + if (maxsearchdepth) + searchhandle = FindFirstFile(wm,&dta); + if (searchhandle != INVALID_HANDLE_VALUE) + { + do + { + if ((dta.cFileName[0]!='.') && (dta.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) + { + //if (SetCurrentDirectory(dta.cFileName)) + { // can fail if we haven't the right + filestatus_t found; + found = filesearch(filename,NULL,wantedmd5sum,completepath,maxsearchdepth-1); + //SetCurrentDirectory(".."); + if (found == FS_FOUND || found == FS_MD5SUMBAD) + { + if (completepath) + strcatbf(filename,(char *)dta.cFileName,"\\"); + FindClose(searchhandle); + return found; + } + } + } + } while (FindNextFile(searchhandle,&dta)==0); + FindClose(searchhandle); + } +#endif + return FS_NOTFOUND; +} +#else +filestatus_t filesearch(char *filename, const char *startpath, const UINT8 *wantedmd5sum, boolean completepath, int maxsearchdepth) +{ + filestatus_t retval = FS_NOTFOUND; + DIR **dirhandle; + struct dirent *dent; + struct stat fsstat; + int found = 0; + char *searchname = strdup(filename); + int depthleft = maxsearchdepth; + char searchpath[1024]; + size_t *searchpathindex; + + dirhandle = (DIR**) malloc(maxsearchdepth * sizeof (DIR*)); + searchpathindex = (size_t *) malloc(maxsearchdepth * sizeof (size_t)); + + strcpy(searchpath,startpath); + searchpathindex[--depthleft] = strlen(searchpath) + 1; + + dirhandle[depthleft] = opendir(searchpath); + + if (dirhandle[depthleft] == NULL) + { + free(searchname); + free(dirhandle); + free(searchpathindex); + return FS_NOTFOUND; + } + + if (searchpath[searchpathindex[depthleft]-2] != '/') + { + searchpath[searchpathindex[depthleft]-1] = '/'; + searchpath[searchpathindex[depthleft]] = 0; + } + else + searchpathindex[depthleft]--; + + while ((!found) && (depthleft < maxsearchdepth)) + { + searchpath[searchpathindex[depthleft]]=0; + dent = readdir(dirhandle[depthleft]); + if (dent) + strcpy(&searchpath[searchpathindex[depthleft]],dent->d_name); + + if (!dent) + closedir(dirhandle[depthleft++]); + else if (dent->d_name[0]=='.' && + (dent->d_name[1]=='\0' || + (dent->d_name[1]=='.' && + dent->d_name[2]=='\0'))) + { + // we don't want to scan uptree + } + else if (stat(searchpath,&fsstat) < 0) // do we want to follow symlinks? if not: change it to lstat + { + // was the file (re)moved? can't stat it + } + else if (S_ISDIR(fsstat.st_mode) && depthleft) + { + strcpy(&searchpath[searchpathindex[depthleft]],dent->d_name); + searchpathindex[--depthleft] = strlen(searchpath) + 1; + dirhandle[depthleft] = opendir(searchpath); + if (!dirhandle[depthleft]) + { + // can't open it... maybe no read-permissions + // go back to previous dir + depthleft++; + } + + searchpath[searchpathindex[depthleft]-1]='/'; + searchpath[searchpathindex[depthleft]]=0; + } + else if (!strcasecmp(searchname, dent->d_name)) + { + switch (checkfilemd5(searchpath, wantedmd5sum)) + { + case FS_FOUND: + if (completepath) + strcpy(filename,searchpath); + else + strcpy(filename,dent->d_name); + retval = FS_FOUND; + found = 1; + break; + case FS_MD5SUMBAD: + retval = FS_MD5SUMBAD; + break; + default: // prevent some compiler warnings + break; + } + } + } + + for (; depthleft < maxsearchdepth; closedir(dirhandle[depthleft++])); + + free(searchname); + free(searchpathindex); + free(dirhandle); + return retval; +} +#endif diff --git a/src/filesrch.h b/src/filesrch.h new file mode 100644 index 000000000..33b148d4b --- /dev/null +++ b/src/filesrch.h @@ -0,0 +1,28 @@ +/// \file +/// \brief Support to find files + +#ifndef __FILESRCH_H__ +#define __FILESRCH_H__ + +#include "doomdef.h" +#include "d_netfil.h" + +/** \brief The filesearch function + + This function search files, manly WADs and return back the status of the file + + \param filename the file to look for + \param startpath where to start look from + \param wantedmd5sum want to check with MD5 + \param completepath want to return the complete path of the file? + \param maxsearchdepth the max depth to search for the file + + \return filestatus_t + + +*/ + +filestatus_t filesearch(char *filename, const char *startpath, const UINT8 *wantedmd5sum, + boolean completepath, int maxsearchdepth); + +#endif // __FILESRCH_H__ diff --git a/src/g_game.c b/src/g_game.c new file mode 100644 index 000000000..f6bc1c6c8 --- /dev/null +++ b/src/g_game.c @@ -0,0 +1,5435 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 1993-1996 by id Software, Inc. +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Copyright (C) 1999-2014 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file g_game.c +/// \brief game loop functions, events handling + +#include "doomdef.h" +#include "console.h" +#include "d_main.h" +#include "d_player.h" +#include "f_finale.h" +#include "p_setup.h" +#include "p_saveg.h" +#include "i_system.h" +#include "am_map.h" +#include "m_random.h" +#include "p_local.h" +#include "r_draw.h" +#include "r_main.h" +#include "s_sound.h" +#include "g_game.h" +#include "m_cheat.h" +#include "m_misc.h" +#include "m_menu.h" +#include "m_argv.h" +#include "hu_stuff.h" +#include "st_stuff.h" +#include "z_zone.h" +#include "i_video.h" +#include "byteptr.h" +#include "i_joy.h" +#include "r_local.h" +#include "r_things.h" +#include "y_inter.h" +#include "v_video.h" +#include "dehacked.h" // get_number (for ghost thok) +#include "lua_hook.h" +#include "b_bot.h" +#include "m_cond.h" // condition sets +#include "md5.h" // demo checksums + +gameaction_t gameaction; +gamestate_t gamestate = GS_NULL; +UINT8 ultimatemode = false; + +boolean botingame; +UINT8 botskin; +UINT8 botcolor; + +JoyType_t Joystick; +JoyType_t Joystick2; + +// 1024 bytes is plenty for a savegame +#define SAVEGAMESIZE (1024) + +char gamedatafilename[64] = "gamedata.dat"; +char timeattackfolder[64] = "main"; +char customversionstring[32] = "\0"; + +static void G_DoCompleted(void); +static void G_DoStartContinue(void); +static void G_DoContinued(void); +static void G_DoWorldDone(void); + +INT16 gamemap = 1; +UINT32 mapmusic; // music, track, and reset bit +INT16 maptol; +UINT8 globalweather = 0; +INT32 curWeather = PRECIP_NONE; +INT32 cursaveslot = -1; // Auto-save 1p savegame slot +INT16 lastmapsaved = 0; // Last map we auto-saved at +boolean gamecomplete = false; + +UINT16 mainwads = 0; +boolean modifiedgame; // Set if homebrew PWAD stuff has been added. +boolean savemoddata = false; +UINT8 paused; +UINT8 modeattacking = ATTACKING_NONE; +boolean disableSpeedAdjust = false; +boolean imcontinuing = false; +boolean runemeraldmanager = false; + +// menu demo things +UINT8 numDemos = 3; +UINT32 demoDelayTime = 15*TICRATE; +UINT32 demoIdleTime = 3*TICRATE; + +boolean timingdemo; // if true, exit with report on completion +boolean nodrawers; // for comparative timing purposes +boolean noblit; // for comparative timing purposes +static tic_t demostarttime; // for comparative timing purposes + +boolean netgame; // only true if packets are broadcast +boolean multiplayer; +boolean playeringame[MAXPLAYERS]; +boolean addedtogame; +player_t players[MAXPLAYERS]; + +INT32 consoleplayer; // player taking events and displaying +INT32 displayplayer; // view being displayed +INT32 secondarydisplayplayer; // for splitscreen + +tic_t gametic; +tic_t levelstarttic; // gametic at level start +UINT32 totalrings; // for intermission +INT16 lastmap; // last level you were at (returning from special stages) +tic_t timeinmap; // Ticker for time spent in level (used for levelcard display) + +INT16 spstage_start; +INT16 sstage_start; +INT16 sstage_end; + +boolean looptitle = false; +boolean useNightsSS = false; + +UINT8 skincolor_redteam = SKINCOLOR_RED; +UINT8 skincolor_blueteam = SKINCOLOR_BLUE; +UINT8 skincolor_redring = SKINCOLOR_RED; +UINT8 skincolor_bluering = SKINCOLOR_STEELBLUE; + +tic_t countdowntimer = 0; +boolean countdowntimeup = false; + +cutscene_t *cutscenes[128]; + +INT16 nextmapoverride; +INT32 nextmapgametype; +boolean skipstats; + +// Pointers to each CTF flag +mobj_t *redflag; +mobj_t *blueflag; +// Pointers to CTF spawn location +mapthing_t *rflagpoint; +mapthing_t *bflagpoint; + +struct quake quake; + +// Map Header Information +mapheader_t* mapheaderinfo[NUMMAPS] = {NULL}; + +static boolean exitgame = false; +static boolean retrying = false; + +UINT8 stagefailed; // Used for GEMS BONUS? Also to see if you beat the stage. + +UINT16 emeralds; +UINT32 token; // Number of tokens collected in a level +UINT32 tokenlist; // List of tokens collected +INT32 tokenbits; // Used for setting token bits + +// Old Special Stage +INT32 sstimer; // Time allotted in the special stage + +tic_t totalplaytime; +boolean gamedataloaded = false; + +// Time attack data for levels +// These are dynamically allocated for space reasons now +recorddata_t *mainrecords[NUMMAPS] = {NULL}; +nightsdata_t *nightsrecords[NUMMAPS] = {NULL}; +UINT8 mapvisited[NUMMAPS]; + +// Temporary holding place for nights data for the current map +nightsdata_t ntemprecords; + +UINT32 bluescore, redscore; // CTF and Team Match team scores + +// ring count... for PERFECT! +INT32 nummaprings = 0; + +// Elminates unnecessary searching. +boolean CheckForBustableBlocks; +boolean CheckForBouncySector; +boolean CheckForQuicksand; +boolean CheckForMarioBlocks; +boolean CheckForFloatBob; +boolean CheckForReverseGravity; + +// Powerup durations +UINT16 invulntics = 20*TICRATE; +UINT16 sneakertics = 20*TICRATE; +UINT16 flashingtics = 3*TICRATE; +UINT16 tailsflytics = 8*TICRATE; +UINT16 underwatertics = 30*TICRATE; +UINT16 spacetimetics = 11*TICRATE + (TICRATE/2); +UINT16 extralifetics = 4*TICRATE; + +INT32 gameovertics = 15*TICRATE; + +UINT8 use1upSound = 0; +UINT8 maxXtraLife = 2; // Max extra lives from rings + +UINT8 introtoplay; +UINT8 creditscutscene; + +// Emerald locations +mobj_t *hunt1; +mobj_t *hunt2; +mobj_t *hunt3; + +UINT32 countdown, countdown2; // for racing + +fixed_t gravity; + +INT16 autobalance; //for CTF team balance +INT16 teamscramble; //for CTF team scramble +INT16 scrambleplayers[MAXPLAYERS]; //for CTF team scramble +INT16 scrambleteams[MAXPLAYERS]; //for CTF team scramble +INT16 scrambletotal; //for CTF team scramble +INT16 scramblecount; //for CTF team scramble + +INT32 cheats; //for multiplayer cheat commands + +tic_t hidetime; + +// Grading +UINT32 timesBeaten; +UINT32 timesBeatenWithEmeralds; +UINT32 timesBeatenUltimate; + +static char demoname[64]; +boolean demorecording; +boolean demoplayback; +boolean titledemo; // Title Screen demo can be cancelled by any key +static UINT8 *demobuffer = NULL; +static UINT8 *metalbuffer = NULL; +static UINT8 *demo_p, *metal_p, *demotime_p; +static UINT8 *demoend; +static UINT8 demoflags; +boolean singledemo; // quit after playing a demo from cmdline +boolean metalrecording; // recording as metal sonic +mobj_t *metalplayback; +boolean demo_start; // don't start playing demo right away + +// extra data stuff (events registered this frame while recording) +static struct { + UINT8 flags; // EZT flags + + // EZT_COLOR + UINT8 color, lastcolor; + + // EZT_SCALE + fixed_t scale, lastscale; + + // EZT_HIT + UINT16 hits; + mobj_t **hitlist; +} ghostext; + +// Your naming conventions are stupid and useless. +// There is no conflict here. +typedef struct demoghost { + UINT8 checksum[16]; + UINT8 *buffer, *p; + mobj_t oldmo, *mo; + struct demoghost *next; +} demoghost; +demoghost *ghosts = NULL; + +boolean precache = true; // if true, load all graphics at start + +INT16 prevmap, nextmap; + +static UINT8 *savebuffer; + +// Analog Control +static void UserAnalog_OnChange(void); +static void UserAnalog2_OnChange(void); +static void Analog_OnChange(void); +static void Analog2_OnChange(void); + +static CV_PossibleValue_t crosshair_cons_t[] = {{0, "Off"}, {1, "Cross"}, {2, "Angle"}, {3, "Point"}, {0, NULL}}; +static CV_PossibleValue_t joyaxis_cons_t[] = {{0, "None"}, +#ifdef _WII +{1, "LStick.X"}, {2, "LStick.Y"}, {-1, "LStick.X-"}, {-2, "LStick.Y-"}, +#if JOYAXISSET > 1 +{3, "RStick.X"}, {4, "RStick.Y"}, {-3, "RStick.X-"}, {-4, "RStick.Y-"}, +#endif +#if JOYAXISSET > 2 +{5, "RTrigger"}, {6, "LTrigger"}, {-5, "RTrigger-"}, {-6, "LTrigger-"}, +#endif +#if JOYAXISSET > 3 +{7, "Pitch"}, {8, "Roll"}, {-7, "Pitch-"}, {-8, "Roll-"}, +#endif +#if JOYAXISSET > 3 +{7, "Pitch"}, {8, "Roll"}, {-7, "Pitch-"}, {-8, "Roll-"}, +#endif +#if JOYAXISSET > 4 +{7, "Yaw"}, {8, "Dummy"}, {-7, "Yaw-"}, {-8, "Dummy-"}, +#endif +#if JOYAXISSET > 4 +{9, "LAnalog"}, {10, "RAnalog"}, {-9, "LAnalog-"}, {-10, "RAnalog-"}, +#endif +#elif defined (WMINPUT) +{1, "LStick.X"}, {2, "LStick.Y"}, {-1, "LStick.X-"}, {-2, "LStick.Y-"}, +#if JOYAXISSET > 1 +{3, "RStick.X"}, {4, "RStick.Y"}, {-3, "RStick.X-"}, {-4, "RStick.Y-"}, +#endif +#if JOYAXISSET > 2 +{5, "NStick.X"}, {6, "NStick.Y"}, {-5, "NStick.X-"}, {-6, "NStick.Y-"}, +#endif +#if JOYAXISSET > 3 +{7, "LAnalog"}, {8, "RAnalog"}, {-7, "LAnalog-"}, {-8, "RAnalog-"}, +#endif +#else +{1, "X-Axis"}, {2, "Y-Axis"}, {-1, "X-Axis-"}, {-2, "Y-Axis-"}, +#ifdef _arch_dreamcast +{3, "R-Trig"}, {4, "L-Trig"}, {-3, "R-Trig-"}, {-4, "L-Trig-"}, +{5, "Alt X-Axis"}, {6, "Alt Y-Axis"}, {-5, "Alt X-Axis-"}, {-6, "Alt Y-Axis-"}, +{7, "Triggers"}, {-7,"Triggers-"}, +#elif defined (_XBOX) +{3, "Alt X-Axis"}, {4, "Alt Y-Axis"}, {-3, "Alt X-Axis-"}, {-4, "Alt Y-Axis-"}, +#else +#if JOYAXISSET > 1 +{3, "Z-Axis"}, {4, "X-Rudder"}, {-3, "Z-Axis-"}, {-4, "X-Rudder-"}, +#endif +#if JOYAXISSET > 2 +{5, "Y-Rudder"}, {6, "Z-Rudder"}, {-5, "Y-Rudder-"}, {-6, "Z-Rudder-"}, +#endif +#if JOYAXISSET > 3 +{7, "U-Axis"}, {8, "V-Axis"}, {-7, "U-Axis-"}, {-8, "V-Axis-"}, +#endif +#endif +#endif + {0, NULL}}; +#ifdef _WII +#if JOYAXISSET > 5 +"More Axis Sets" +#endif +#else +#if JOYAXISSET > 4 +"More Axis Sets" +#endif +#endif + +consvar_t cv_crosshair = {"crosshair", "Cross", CV_SAVE, crosshair_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_crosshair2 = {"crosshair2", "Cross", CV_SAVE, crosshair_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_invertmouse = {"invertmouse", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_alwaysfreelook = {"alwaysmlook", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_invertmouse2 = {"invertmouse2", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_alwaysfreelook2 = {"alwaysmlook2", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_mousemove = {"mousemove", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_mousemove2 = {"mousemove2", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_analog = {"analog", "Off", CV_CALL, CV_OnOff, Analog_OnChange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_analog2 = {"analog2", "Off", CV_CALL, CV_OnOff, Analog2_OnChange, 0, NULL, NULL, 0, 0, NULL}; +#ifdef DC +consvar_t cv_useranalog = {"useranalog", "On", CV_SAVE|CV_CALL, CV_OnOff, UserAnalog_OnChange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_useranalog2 = {"useranalog2", "On", CV_SAVE|CV_CALL, CV_OnOff, UserAnalog2_OnChange, 0, NULL, NULL, 0, 0, NULL}; +#else +consvar_t cv_useranalog = {"useranalog", "Off", CV_SAVE|CV_CALL, CV_OnOff, UserAnalog_OnChange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_useranalog2 = {"useranalog2", "Off", CV_SAVE|CV_CALL, CV_OnOff, UserAnalog2_OnChange, 0, NULL, NULL, 0, 0, NULL}; +#endif + +typedef enum +{ + AXISNONE = 0, + AXISTURN, + AXISMOVE, + AXISLOOK, + AXISSTRAFE, + AXISDEAD, //Axises that don't want deadzones + AXISFIRE, + AXISFIRENORMAL, +} axis_input_e; + +#if defined (_WII) || defined (WMINPUT) +consvar_t cv_turnaxis = {"joyaxis_turn", "LStick.X", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_moveaxis = {"joyaxis_move", "LStick.Y", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_sideaxis = {"joyaxis_side", "RStick.X", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_lookaxis = {"joyaxis_look", "RStick.Y", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_fireaxis = {"joyaxis_fire", "LAnalog", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_firenaxis = {"joyaxis_firenormal", "RAnalog", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +#else +consvar_t cv_turnaxis = {"joyaxis_turn", "X-Axis", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +#ifdef PSP +consvar_t cv_moveaxis = {"joyaxis_move", "None", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +#else +consvar_t cv_moveaxis = {"joyaxis_move", "Y-Axis", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +#endif +#ifdef _arch_dreamcast +consvar_t cv_sideaxis = {"joyaxis_side", "Triggers", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +#elif defined (_XBOX) +consvar_t cv_sideaxis = {"joyaxis_side", "Alt X-Axis", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_lookaxis = {"joyaxis_look", "Alt Y-Axis", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +#elif defined (PSP) +consvar_t cv_sideaxis = {"joyaxis_side", "None", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +#else +consvar_t cv_sideaxis = {"joyaxis_side", "Z-Axis", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +#endif +#ifndef _XBOX +#ifdef PSP +consvar_t cv_lookaxis = {"joyaxis_look", "Y-Axis", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +#else +consvar_t cv_lookaxis = {"joyaxis_look", "None", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +#endif +#endif +consvar_t cv_fireaxis = {"joyaxis_fire", "None", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_firenaxis = {"joyaxis_firenormal", "None", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +#endif + +#if defined (_WII) || defined (WMINPUT) +consvar_t cv_turnaxis2 = {"joyaxis2_turn", "LStick.X", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_moveaxis2 = {"joyaxis2_move", "LStick.Y", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_sideaxis2 = {"joyaxis2_side", "RStick.X", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_lookaxis2 = {"joyaxis2_look", "RStick.Y", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_fireaxis2 = {"joyaxis2_fire", "LAnalog", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_firenaxis2 = {"joyaxis2_firenormal", "RAnalog", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +#else +consvar_t cv_turnaxis2 = {"joyaxis2_turn", "X-Axis", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_moveaxis2 = {"joyaxis2_move", "Y-Axis", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +#ifdef _arch_dreamcast +consvar_t cv_sideaxis2 = {"joyaxis2_side", "Triggers", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +#elif defined (_XBOX) +consvar_t cv_sideaxis2 = {"joyaxis2_side", "Alt X-Axis", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_lookaxis2 = {"joyaxis2_look", "Alt Y-Axis", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +#elif defined (_PSP) +consvar_t cv_sideaxis2 = {"joyaxis2_side", "None", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +#else +consvar_t cv_sideaxis2 = {"joyaxis2_side", "Z-Axis", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +#endif +#ifndef _XBOX +consvar_t cv_lookaxis2 = {"joyaxis2_look", "None", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +#endif +consvar_t cv_fireaxis2 = {"joyaxis2_fire", "None", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_firenaxis2 = {"joyaxis2_firenormal", "None", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +#endif + + +#if MAXPLAYERS > 32 +#error "please update player_name table using the new value for MAXPLAYERS" +#endif + +#ifdef SEENAMES +player_t *seenplayer; // player we're aiming at right now +#endif + +char player_names[MAXPLAYERS][MAXPLAYERNAME+1] = +{ + "Player 1", + "Player 2", + "Player 3", + "Player 4", + "Player 5", + "Player 6", + "Player 7", + "Player 8", + "Player 9", + "Player 10", + "Player 11", + "Player 12", + "Player 13", + "Player 14", + "Player 15", + "Player 16", + "Player 17", + "Player 18", + "Player 19", + "Player 20", + "Player 21", + "Player 22", + "Player 23", + "Player 24", + "Player 25", + "Player 26", + "Player 27", + "Player 28", + "Player 29", + "Player 30", + "Player 31", + "Player 32" +}; + +INT16 rw_maximums[NUM_WEAPONS] = +{ + 800, // MAX_INFINITY + 400, // MAX_AUTOMATIC + 100, // MAX_BOUNCE + 50, // MAX_SCATTER + 100, // MAX_GRENADE + 50, // MAX_EXPLOSION + 50 // MAX_RAIL +}; + +// Allocation for time and nights data +void G_AllocMainRecordData(INT16 i) +{ + if (!mainrecords[i]) + mainrecords[i] = Z_Malloc(sizeof(recorddata_t), PU_STATIC, NULL); + memset(mainrecords[i], 0, sizeof(recorddata_t)); +} + +void G_AllocNightsRecordData(INT16 i) +{ + if (!nightsrecords[i]) + nightsrecords[i] = Z_Malloc(sizeof(nightsdata_t), PU_STATIC, NULL); + memset(nightsrecords[i], 0, sizeof(nightsdata_t)); +} + +// MAKE SURE YOU SAVE DATA BEFORE CALLING THIS +void G_ClearRecords(void) +{ + INT16 i; + for (i = 0; i < NUMMAPS; ++i) + { + if (mainrecords[i]) + { + Z_Free(mainrecords[i]); + mainrecords[i] = NULL; + } + if (nightsrecords[i]) + { + Z_Free(nightsrecords[i]); + nightsrecords[i] = NULL; + } + } +} + +// For easy retrieval of records +UINT32 G_GetBestScore(INT16 map) +{ + if (!mainrecords[map-1]) + return 0; + + return mainrecords[map-1]->score; +} + +tic_t G_GetBestTime(INT16 map) +{ + if (!mainrecords[map-1] || mainrecords[map-1]->time <= 0) + return (tic_t)UINT32_MAX; + + return mainrecords[map-1]->time; +} + +UINT16 G_GetBestRings(INT16 map) +{ + if (!mainrecords[map-1]) + return 0; + + return mainrecords[map-1]->rings; +} + +UINT32 G_GetBestNightsScore(INT16 map, UINT8 mare) +{ + if (!nightsrecords[map-1]) + return 0; + + return nightsrecords[map-1]->score[mare]; +} + +tic_t G_GetBestNightsTime(INT16 map, UINT8 mare) +{ + if (!nightsrecords[map-1] || nightsrecords[map-1]->time[mare] <= 0) + return (tic_t)UINT32_MAX; + + return nightsrecords[map-1]->time[mare]; +} + +UINT8 G_GetBestNightsGrade(INT16 map, UINT8 mare) +{ + if (!nightsrecords[map-1]) + return 0; + + return nightsrecords[map-1]->grade[mare]; +} + +// For easy adding of NiGHTS records +void G_AddTempNightsRecords(UINT32 pscore, tic_t ptime, UINT8 mare) +{ + ntemprecords.score[mare] = pscore; + ntemprecords.grade[mare] = P_GetGrade(pscore, gamemap, mare - 1); + ntemprecords.time[mare] = ptime; + + // Update nummares + // Note that mare "0" is overall, mare "1" is the first real mare + if (ntemprecords.nummares < mare) + ntemprecords.nummares = mare; +} + +void G_SetNightsRecords(void) +{ + INT32 i; + + if (!ntemprecords.nummares) + return; + + // Set overall + { + UINT32 totalscore = 0; + tic_t totaltime = 0; + UINT8 totalrank = 0, realrank = 0; + + for (i = 1; i <= ntemprecords.nummares; ++i) + { + totalscore += ntemprecords.score[i]; + totalrank += ntemprecords.grade[i]; + totaltime += ntemprecords.time[i]; + } + + // Determine overall grade + realrank = (UINT8)((FixedDiv((fixed_t)totalrank << FRACBITS, ntemprecords.nummares << FRACBITS) + (FRACUNIT/2)) >> FRACBITS); + + // You need ALL rainbow As to get a rainbow A overall + if (realrank == GRADE_S && (totalrank / ntemprecords.nummares) != GRADE_S) + realrank = GRADE_A; + + ntemprecords.score[0] = totalscore; + ntemprecords.grade[0] = realrank; + ntemprecords.time[0] = totaltime; + } + + // Now take all temp records and put them in the actual records + { + nightsdata_t *maprecords; + + if (!nightsrecords[gamemap-1]) + G_AllocNightsRecordData(gamemap-1); + maprecords = nightsrecords[gamemap-1]; + + if (maprecords->nummares != ntemprecords.nummares) + maprecords->nummares = ntemprecords.nummares; + + for (i = 0; i < ntemprecords.nummares + 1; ++i) + { + if (maprecords->score[i] < ntemprecords.score[i]) + maprecords->score[i] = ntemprecords.score[i]; + if (maprecords->grade[i] < ntemprecords.grade[i]) + maprecords->grade[i] = ntemprecords.grade[i]; + if (!maprecords->time[i] || maprecords->time[i] > ntemprecords.time[i]) + maprecords->time[i] = ntemprecords.time[i]; + } + } + + memset(&ntemprecords, 0, sizeof(nightsdata_t)); + + // If the mare count changed, this will update the score display + CV_AddValue(&cv_nextmap, 1); + CV_AddValue(&cv_nextmap, -1); +} + +// for consistency among messages: this modifies the game and removes savemoddata. +void G_SetGameModified(boolean silent) +{ + if (modifiedgame && !savemoddata) + return; + + modifiedgame = true; + savemoddata = false; + + if (!silent) + CONS_Alert(CONS_NOTICE, M_GetText("Game must be restarted to record statistics.\n")); +} + +/** Builds an original game map name from a map number. + * The complexity is due to MAPA0-MAPZZ. + * + * \param map Map number. + * \return Pointer to a static buffer containing the desired map name. + * \sa M_MapNumber + */ +const char *G_BuildMapName(INT32 map) +{ + static char mapname[9] = "MAPXX"; // internal map name (wad resource name) + + I_Assert(map > 0); + I_Assert(map <= NUMMAPS); + + if (map < 100) + sprintf(&mapname[3], "%.2d", map); + else + { + mapname[3] = (char)('A' + (char)((map - 100) / 36)); + if ((map - 100) % 36 < 10) + mapname[4] = (char)('0' + (char)((map - 100) % 36)); + else + mapname[4] = (char)('A' + (char)((map - 100) % 36) - 10); + mapname[5] = '\0'; + } + + return mapname; +} + +/** Clips the console player's mouse aiming to the current view. + * Used whenever the player view is changed manually. + * + * \param aiming Pointer to the vertical angle to clip. + * \return Short version of the clipped angle for building a ticcmd. + */ +INT16 G_ClipAimingPitch(INT32 *aiming) +{ + INT32 limitangle; + + limitangle = ANGLE_90 - 1; + + if (*aiming > limitangle) + *aiming = limitangle; + else if (*aiming < -limitangle) + *aiming = -limitangle; + + return (INT16)((*aiming)>>16); +} + +INT16 G_SoftwareClipAimingPitch(INT32 *aiming) +{ + INT32 limitangle; + + // note: the current software mode implementation doesn't have true perspective + limitangle = ANGLE_90 - ANG10; // Some viewing fun, but not too far down... + + if (*aiming > limitangle) + *aiming = limitangle; + else if (*aiming < -limitangle) + *aiming = -limitangle; + + return (INT16)((*aiming)>>16); +} + +static INT32 JoyAxis(axis_input_e axissel) +{ + INT32 retaxis; + INT32 axisval; + boolean flp = false; + + //find what axis to get + switch (axissel) + { + case AXISTURN: + axisval = cv_turnaxis.value; + break; + case AXISMOVE: + axisval = cv_moveaxis.value; + break; + case AXISLOOK: + axisval = cv_lookaxis.value; + break; + case AXISSTRAFE: + axisval = cv_sideaxis.value; + break; + case AXISFIRE: + axisval = cv_fireaxis.value; + break; + case AXISFIRENORMAL: + axisval = cv_firenaxis.value; + break; + default: + return 0; + } + + if (axisval < 0) //odd -axises + { + axisval = -axisval; + flp = true; + } +#ifdef _arch_dreamcast + if (axisval == 7) // special case + { + retaxis = joyxmove[1] - joyymove[1]; + goto skipDC; + } + else +#endif + if (axisval > JOYAXISSET*2 || axisval == 0) //not there in array or None + return 0; + + if (axisval%2) + { + axisval /= 2; + retaxis = joyxmove[axisval]; + } + else + { + axisval--; + axisval /= 2; + retaxis = joyymove[axisval]; + } + +#ifdef _arch_dreamcast + skipDC: +#endif + + if (retaxis < (-JOYAXISRANGE)) + retaxis = -JOYAXISRANGE; + if (retaxis > (+JOYAXISRANGE)) + retaxis = +JOYAXISRANGE; + if (!Joystick.bGamepadStyle && axissel < AXISDEAD) + { + const INT32 jdeadzone = JOYAXISRANGE/4; + if (-jdeadzone < retaxis && retaxis < jdeadzone) + return 0; + } + if (flp) retaxis = -retaxis; //flip it around + return retaxis; +} + +static INT32 Joy2Axis(axis_input_e axissel) +{ + INT32 retaxis; + INT32 axisval; + boolean flp = false; + + //find what axis to get + switch (axissel) + { + case AXISTURN: + axisval = cv_turnaxis2.value; + break; + case AXISMOVE: + axisval = cv_moveaxis2.value; + break; + case AXISLOOK: + axisval = cv_lookaxis2.value; + break; + case AXISSTRAFE: + axisval = cv_sideaxis2.value; + break; + case AXISFIRE: + axisval = cv_fireaxis2.value; + break; + case AXISFIRENORMAL: + axisval = cv_firenaxis2.value; + break; + default: + return 0; + } + + + if (axisval < 0) //odd -axises + { + axisval = -axisval; + flp = true; + } +#ifdef _arch_dreamcast + if (axisval == 7) // special case + { + retaxis = joy2xmove[1] - joy2ymove[1]; + goto skipDC; + } + else +#endif + if (axisval > JOYAXISSET*2 || axisval == 0) //not there in array or None + return 0; + + if (axisval%2) + { + axisval /= 2; + retaxis = joy2xmove[axisval]; + } + else + { + axisval--; + axisval /= 2; + retaxis = joy2ymove[axisval]; + } + +#ifdef _arch_dreamcast + skipDC: +#endif + + if (retaxis < (-JOYAXISRANGE)) + retaxis = -JOYAXISRANGE; + if (retaxis > (+JOYAXISRANGE)) + retaxis = +JOYAXISRANGE; + if (!Joystick2.bGamepadStyle && axissel < AXISDEAD) + { + const INT32 jdeadzone = JOYAXISRANGE/4; + if (-jdeadzone < retaxis && retaxis < jdeadzone) + return 0; + } + if (flp) retaxis = -retaxis; //flip it around + return retaxis; +} + + +// +// G_BuildTiccmd +// Builds a ticcmd from all of the available inputs +// or reads it from the demo buffer. +// If recording a demo, write it out +// +// set secondaryplayer true to build player 2's ticcmd in splitscreen mode +// +INT32 localaiming, localaiming2; +angle_t localangle, localangle2; + +static fixed_t forwardmove[2] = {25<>16, 50<>16}; +static fixed_t sidemove[2] = {25<>16, 50<>16}; // faster! +static fixed_t angleturn[3] = {640, 1280, 320}; // + slow turn + +void G_BuildTiccmd(ticcmd_t *cmd, INT32 realtics) +{ + boolean forcestrafe = false; + INT32 tspeed, forward, side, axis, i; + const INT32 speed = 1; + // these ones used for multiple conditions + boolean turnleft, turnright, mouseaiming, analogjoystickmove, gamepadjoystickmove; + player_t *player = &players[consoleplayer]; + + static INT32 turnheld; // for accelerative turning + static boolean keyboard_look; // true if lookup/down using keyboard + static boolean resetdown; // don't cam reset every frame + + G_CopyTiccmd(cmd, I_BaseTiccmd(), 1); // empty, or external driver + + // why build a ticcmd if we're paused? + // Or, for that matter, if we're being reborn. + if (paused || P_MenuActivePause() || (gamestate == GS_LEVEL && player->playerstate == PST_REBORN)) + { + cmd->angleturn = (INT16)(localangle >> 16); + cmd->aiming = G_ClipAimingPitch(&localaiming); + return; + } + + turnright = PLAYER1INPUTDOWN(gc_turnright); + turnleft = PLAYER1INPUTDOWN(gc_turnleft); + mouseaiming = (PLAYER1INPUTDOWN(gc_mouseaiming)) ^ cv_alwaysfreelook.value; + analogjoystickmove = cv_usejoystick.value && !Joystick.bGamepadStyle; + gamepadjoystickmove = cv_usejoystick.value && Joystick.bGamepadStyle; + + axis = JoyAxis(AXISTURN); + if (gamepadjoystickmove && axis != 0) + { + turnright = turnright || (axis > 0); + turnleft = turnleft || (axis < 0); + } + forward = side = 0; + + // use two stage accelerative turning + // on the keyboard and joystick + if (turnleft || turnright) + turnheld += realtics; + else + turnheld = 0; + + if (turnheld < SLOWTURNTICS) + tspeed = 2; // slow turn + else + tspeed = speed; + + // let movement keys cancel each other out + if (cv_analog.value) // Analog + { + if (turnright) + cmd->angleturn = (INT16)(cmd->angleturn - angleturn[tspeed]); + if (turnleft) + cmd->angleturn = (INT16)(cmd->angleturn + angleturn[tspeed]); + } + if (cv_analog.value || twodlevel + || (player->mo && (player->mo->flags2 & MF2_TWOD)) + || player->climbing + || (player->pflags & PF_NIGHTSMODE) + || (player->pflags & PF_SLIDING)) // Analog + forcestrafe = true; + if (forcestrafe) // Analog + { + if (turnright) + side += sidemove[speed]; + if (turnleft) + side -= sidemove[speed]; + + if (analogjoystickmove && axis != 0) + { + // JOYAXISRANGE is supposed to be 1023 (divide by 1024) + side += ((axis * sidemove[1]) >> 10); + } + } + else + { + if (turnright) + cmd->angleturn = (INT16)(cmd->angleturn - angleturn[tspeed]); + else if (turnleft) + cmd->angleturn = (INT16)(cmd->angleturn + angleturn[tspeed]); + + if (analogjoystickmove && axis != 0) + { + // JOYAXISRANGE should be 1023 (divide by 1024) + cmd->angleturn = (INT16)(cmd->angleturn - ((axis * angleturn[1]) >> 10)); // ANALOG! + } + } + + axis = JoyAxis(AXISSTRAFE); + if (gamepadjoystickmove && axis != 0) + { + if (axis < 0) + side += sidemove[speed]; + else if (axis > 0) + side -= sidemove[speed]; + } + else if (analogjoystickmove && axis != 0) + { + // JOYAXISRANGE is supposed to be 1023 (divide by 1024) + side += ((axis * sidemove[1]) >> 10); + } + + // forward with key or button + axis = JoyAxis(AXISMOVE); + if (PLAYER1INPUTDOWN(gc_forward) || (gamepadjoystickmove && axis < 0)) + forward = forwardmove[speed]; + if (PLAYER1INPUTDOWN(gc_backward) || (gamepadjoystickmove && axis > 0)) + forward -= forwardmove[speed]; + + if (analogjoystickmove && axis != 0) + forward -= ((axis * forwardmove[1]) >> 10); // ANALOG! + + // some people strafe left & right with mouse buttons + // those people are weird + if (PLAYER1INPUTDOWN(gc_straferight)) + side += sidemove[speed]; + if (PLAYER1INPUTDOWN(gc_strafeleft)) + side -= sidemove[speed]; + + if (PLAYER1INPUTDOWN(gc_weaponnext)) + cmd->buttons |= BT_WEAPONNEXT; // Next Weapon + if (PLAYER1INPUTDOWN(gc_weaponprev)) + cmd->buttons |= BT_WEAPONPREV; // Previous Weapon + +#if NUM_WEAPONS > 10 +"Add extra inputs to g_input.h/gamecontrols_e" +#endif + //use the four avaliable bits to determine the weapon. + cmd->buttons &= ~BT_WEAPONMASK; + for (i = 0; i < NUM_WEAPONS; ++i) + if (PLAYER1INPUTDOWN(gc_wepslot1 + i)) + { + cmd->buttons |= (UINT16)(i + 1); + break; + } + + // fire with any button/key + axis = JoyAxis(AXISFIRE); + if (PLAYER1INPUTDOWN(gc_fire) || (cv_usejoystick.value && axis > 0)) + cmd->buttons |= BT_ATTACK; + + // fire normal with any button/key + axis = JoyAxis(AXISFIRENORMAL); + if (PLAYER1INPUTDOWN(gc_firenormal) || (cv_usejoystick.value && axis > 0)) + cmd->buttons |= BT_FIRENORMAL; + + if (PLAYER1INPUTDOWN(gc_tossflag)) + cmd->buttons |= BT_TOSSFLAG; + + // use with any button/key + if (PLAYER1INPUTDOWN(gc_use) && !(player->pflags & PF_MACESPIN)) + cmd->buttons |= BT_USE; + + // Camera Controls + if (cv_debug || cv_analog.value || demoplayback || objectplacing || player->pflags & PF_NIGHTSMODE) + { + if (PLAYER1INPUTDOWN(gc_camleft)) + cmd->buttons |= BT_CAMLEFT; + if (PLAYER1INPUTDOWN(gc_camright)) + cmd->buttons |= BT_CAMRIGHT; + } + + if (PLAYER1INPUTDOWN(gc_camreset)) + { + if (camera.chase && !resetdown) + P_ResetCamera(&players[displayplayer], &camera); + resetdown = true; + } + else + resetdown = false; + + // jump button + if (PLAYER1INPUTDOWN(gc_jump)) + cmd->buttons |= BT_JUMP; + + // player aiming shit, ahhhh... + { + INT32 player_invert = cv_invertmouse.value ? -1 : 1; + INT32 screen_invert = + (player->mo && (player->mo->eflags & MFE_VERTICALFLIP) + && (!camera.chase || player->pflags & PF_FLIPCAM)) //because chasecam's not inverted + ? -1 : 1; // set to -1 or 1 to multiply + + // mouse look stuff (mouse look is not the same as mouse aim) + if (mouseaiming) + { + keyboard_look = false; + + // looking up/down + localaiming += (mlooky<<19)*player_invert*screen_invert; + } + + axis = JoyAxis(AXISLOOK); + if (analogjoystickmove && axis != 0 && cv_lookaxis.value != 0) + localaiming += (axis<<16) * screen_invert; + + // spring back if not using keyboard neither mouselookin' + if (!keyboard_look && cv_lookaxis.value == 0 && !mouseaiming) + localaiming = 0; + + if (PLAYER1INPUTDOWN(gc_lookup) || (gamepadjoystickmove && axis < 0)) + { + localaiming += KB_LOOKSPEED * screen_invert; + keyboard_look = true; + } + else if (PLAYER1INPUTDOWN(gc_lookdown) || (gamepadjoystickmove && axis > 0)) + { + localaiming -= KB_LOOKSPEED * screen_invert; + keyboard_look = true; + } + else if (PLAYER1INPUTDOWN(gc_centerview)) + localaiming = 0; + + // accept no mlook for network games + if (!cv_allowmlook.value) + localaiming = 0; + + cmd->aiming = G_ClipAimingPitch(&localaiming); + } + + if (!mouseaiming && cv_mousemove.value) + forward += mousey; + + if (cv_analog.value || player->climbing + || (player->pflags & PF_SLIDING)) // Analog for mouse + side += mousex*2; + else + cmd->angleturn = (INT16)(cmd->angleturn - (mousex*8)); + + mousex = mousey = mlooky = 0; + + if (forward > MAXPLMOVE) + forward = MAXPLMOVE; + else if (forward < -MAXPLMOVE) + forward = -MAXPLMOVE; + if (side > MAXPLMOVE) + side = MAXPLMOVE; + else if (side < -MAXPLMOVE) + side = -MAXPLMOVE; + + // No additional acceleration when moving forward/backward and strafing simultaneously. + // do this AFTER we cap to MAXPLMOVE so people can't find ways to cheese around this. + if (!forcestrafe && forward && side) + { + forward = FixedMul(forward, 3*FRACUNIT/4); + side = FixedMul(side, 3*FRACUNIT/4); + } + + //Silly hack to make 2d mode *somewhat* playable with no chasecam. + if ((twodlevel || (player->mo && player->mo->flags2 & MF2_TWOD)) && !camera.chase) + { + INT32 temp = forward; + forward = side; + side = temp; + } + + cmd->forwardmove = (SINT8)(cmd->forwardmove + forward); + cmd->sidemove = (SINT8)(cmd->sidemove + side); + + localangle += (cmd->angleturn<<16); + cmd->angleturn = (INT16)(localangle >> 16); + + //Reset away view if a command is given. + if ((cmd->forwardmove || cmd->sidemove || cmd->buttons) + && displayplayer != consoleplayer) + displayplayer = consoleplayer; +} + +// like the g_buildticcmd 1 but using mouse2, gamcontrolbis, ... +void G_BuildTiccmd2(ticcmd_t *cmd, INT32 realtics) +{ + boolean forcestrafe = false; + INT32 tspeed, forward, side, axis, i; + const INT32 speed = 1; + // these ones used for multiple conditions + boolean turnleft, turnright, mouseaiming, analogjoystickmove, gamepadjoystickmove; + player_t *player = &players[secondarydisplayplayer]; + + static INT32 turnheld; // for accelerative turning + static boolean keyboard_look; // true if lookup/down using keyboard + static boolean resetdown; // don't cam reset every frame + + G_CopyTiccmd(cmd, I_BaseTiccmd2(), 1); // empty, or external driver + + //why build a ticcmd if we're paused? + // Or, for that matter, if we're being reborn. + if (paused || P_MenuActivePause() || player->playerstate == PST_REBORN) + { + cmd->angleturn = (INT16)(localangle2 >> 16); + cmd->aiming = G_ClipAimingPitch(&localaiming2); + return; + } + + turnright = PLAYER2INPUTDOWN(gc_turnright); + turnleft = PLAYER2INPUTDOWN(gc_turnleft); + mouseaiming = (PLAYER2INPUTDOWN(gc_mouseaiming)) ^ cv_alwaysfreelook2.value; + analogjoystickmove = cv_usejoystick2.value && !Joystick2.bGamepadStyle; + gamepadjoystickmove = cv_usejoystick2.value && Joystick2.bGamepadStyle; + + axis = Joy2Axis(AXISTURN); + if (gamepadjoystickmove && axis != 0) + { + turnright = turnright || (axis > 0); + turnleft = turnleft || (axis < 0); + } + forward = side = 0; + + // use two stage accelerative turning + // on the keyboard and joystick + if (turnleft || turnright) + turnheld += realtics; + else + turnheld = 0; + + if (turnheld < SLOWTURNTICS) + tspeed = 2; // slow turn + else + tspeed = speed; + + // let movement keys cancel each other out + if (cv_analog2.value) // Analog + { + if (turnright) + cmd->angleturn = (INT16)(cmd->angleturn - angleturn[tspeed]); + if (turnleft) + cmd->angleturn = (INT16)(cmd->angleturn + angleturn[tspeed]); + } + if (cv_analog2.value || twodlevel + || (player->mo && (player->mo->flags2 & MF2_TWOD)) + || player->climbing + || (player->pflags & PF_NIGHTSMODE) + || (player->pflags & PF_SLIDING)) // Analog + forcestrafe = true; + if (forcestrafe) // Analog + { + if (turnright) + side += sidemove[speed]; + if (turnleft) + side -= sidemove[speed]; + + if (analogjoystickmove && axis != 0) + { + // JOYAXISRANGE is supposed to be 1023 (divide by 1024) + side += ((axis * sidemove[1]) >> 10); + } + } + else + { + if (turnright) + cmd->angleturn = (INT16)(cmd->angleturn - angleturn[tspeed]); + else if (turnleft) + cmd->angleturn = (INT16)(cmd->angleturn + angleturn[tspeed]); + + if (analogjoystickmove && axis != 0) + { + // JOYAXISRANGE should be 1023 (divide by 1024) + cmd->angleturn = (INT16)(cmd->angleturn - ((axis * angleturn[1]) >> 10)); // ANALOG! + } + } + + axis = Joy2Axis(AXISSTRAFE); + if (gamepadjoystickmove && axis != 0) + { + if (axis < 0) + side += sidemove[speed]; + else if (axis > 0) + side -= sidemove[speed]; + } + else if (analogjoystickmove && axis != 0) + { + // JOYAXISRANGE is supposed to be 1023 (divide by 1024) + side += ((axis * sidemove[1]) >> 10); + } + + // forward with key or button + axis = Joy2Axis(AXISMOVE); + if (PLAYER2INPUTDOWN(gc_forward) || (gamepadjoystickmove && axis < 0)) + forward = forwardmove[speed]; + if (PLAYER2INPUTDOWN(gc_backward) || (gamepadjoystickmove && axis > 0)) + forward -= forwardmove[speed]; + + if (analogjoystickmove && axis != 0) + forward -= ((axis * forwardmove[1]) >> 10); // ANALOG! + + // some people strafe left & right with mouse buttons + // those people are (still) weird + if (PLAYER2INPUTDOWN(gc_straferight)) + side += sidemove[speed]; + if (PLAYER2INPUTDOWN(gc_strafeleft)) + side -= sidemove[speed]; + + if (PLAYER2INPUTDOWN(gc_weaponnext)) + cmd->buttons |= BT_WEAPONNEXT; // Next Weapon + if (PLAYER2INPUTDOWN(gc_weaponprev)) + cmd->buttons |= BT_WEAPONPREV; // Previous Weapon + + //use the four avaliable bits to determine the weapon. + cmd->buttons &= ~BT_WEAPONMASK; + for (i = 0; i < NUM_WEAPONS; ++i) + if (PLAYER2INPUTDOWN(gc_wepslot1 + i)) + { + cmd->buttons |= (UINT16)(i + 1); + break; + } + + // fire with any button/key + axis = Joy2Axis(AXISFIRE); + if (PLAYER2INPUTDOWN(gc_fire) || (cv_usejoystick2.value && axis > 0)) + cmd->buttons |= BT_ATTACK; + + // fire normal with any button/key + axis = Joy2Axis(AXISFIRENORMAL); + if (PLAYER2INPUTDOWN(gc_firenormal) || (cv_usejoystick2.value && axis > 0)) + cmd->buttons |= BT_FIRENORMAL; + + if (PLAYER2INPUTDOWN(gc_tossflag)) + cmd->buttons |= BT_TOSSFLAG; + + // use with any button/key + if (PLAYER2INPUTDOWN(gc_use)) + cmd->buttons |= BT_USE; + + // Camera Controls + if (cv_debug || cv_analog2.value || player->pflags & PF_NIGHTSMODE) + { + if (PLAYER2INPUTDOWN(gc_camleft)) + cmd->buttons |= BT_CAMLEFT; + if (PLAYER2INPUTDOWN(gc_camright)) + cmd->buttons |= BT_CAMRIGHT; + } + + if (PLAYER2INPUTDOWN(gc_camreset)) + { + if (camera2.chase && !resetdown) + P_ResetCamera(&players[secondarydisplayplayer], &camera2); + resetdown = true; + } + else + resetdown = false; + + // jump button + if (PLAYER2INPUTDOWN(gc_jump)) + cmd->buttons |= BT_JUMP; + + // player aiming shit, ahhhh... + { + INT32 player_invert = cv_invertmouse2.value ? -1 : 1; + INT32 screen_invert = + (player->mo && (player->mo->eflags & MFE_VERTICALFLIP) + && (!camera2.chase || player->pflags & PF_FLIPCAM)) //because chasecam's not inverted + ? -1 : 1; // set to -1 or 1 to multiply + + // mouse look stuff (mouse look is not the same as mouse aim) + if (mouseaiming) + { + keyboard_look = false; + + // looking up/down + localaiming2 += (mlook2y<<19)*player_invert*screen_invert; + } + + axis = Joy2Axis(AXISLOOK); + if (analogjoystickmove && axis != 0 && cv_lookaxis2.value != 0) + localaiming2 += (axis<<16) * screen_invert; + + // spring back if not using keyboard neither mouselookin' + if (!keyboard_look && cv_lookaxis2.value == 0 && !mouseaiming) + localaiming2 = 0; + + if (PLAYER2INPUTDOWN(gc_lookup) || (gamepadjoystickmove && axis < 0)) + { + localaiming2 += KB_LOOKSPEED * screen_invert; + keyboard_look = true; + } + else if (PLAYER2INPUTDOWN(gc_lookdown) || (gamepadjoystickmove && axis > 0)) + { + localaiming2 -= KB_LOOKSPEED * screen_invert; + keyboard_look = true; + } + else if (PLAYER2INPUTDOWN(gc_centerview)) + localaiming2 = 0; + + // accept no mlook for network games + if (!cv_allowmlook.value) + localaiming2 = 0; + + cmd->aiming = G_ClipAimingPitch(&localaiming2); + } + + if (!mouseaiming && cv_mousemove2.value) + forward += mouse2y; + + if (cv_analog2.value || player->climbing + || (player->pflags & PF_SLIDING)) // Analog for mouse + side += mouse2x*2; + else + cmd->angleturn = (INT16)(cmd->angleturn - (mouse2x*8)); + + mouse2x = mouse2y = mlook2y = 0; + + if (forward > MAXPLMOVE) + forward = MAXPLMOVE; + else if (forward < -MAXPLMOVE) + forward = -MAXPLMOVE; + if (side > MAXPLMOVE) + side = MAXPLMOVE; + else if (side < -MAXPLMOVE) + side = -MAXPLMOVE; + + // No additional acceleration when moving forward/backward and strafing simultaneously. + // do this AFTER we cap to MAXPLMOVE so people can't find ways to cheese around this. + if (!forcestrafe && forward && side) + { + forward = FixedMul(forward, 3*FRACUNIT/4); + side = FixedMul(side, 3*FRACUNIT/4); + } + + //Silly hack to make 2d mode *somewhat* playable with no chasecam. + if ((twodlevel || (player->mo && player->mo->flags2 & MF2_TWOD)) && !camera2.chase) + { + INT32 temp = forward; + forward = side; + side = temp; + } + + cmd->forwardmove = (SINT8)(cmd->forwardmove + forward); + cmd->sidemove = (SINT8)(cmd->sidemove + side); + + if (player->bot == 1) { + if (!player->powers[pw_tailsfly] && (cmd->forwardmove || cmd->sidemove || cmd->buttons)) + { + player->bot = 2; // A player-controlled bot. Returns to AI when it respawns. + CV_SetValue(&cv_analog2, true); + } + else + { + G_CopyTiccmd(cmd, I_BaseTiccmd2(), 1); // empty, or external driver + B_BuildTiccmd(player, cmd); + } + } + + localangle2 += (cmd->angleturn<<16); + cmd->angleturn = (INT16)(localangle2 >> 16); +} + +// User has designated that they want +// analog ON, so tell the game to stop +// fudging with it. +static void UserAnalog_OnChange(void) +{ + if (cv_useranalog.value) + CV_SetValue(&cv_analog, 1); + else + CV_SetValue(&cv_analog, 0); +} + +static void UserAnalog2_OnChange(void) +{ + if (botingame) + return; + if (cv_useranalog2.value) + CV_SetValue(&cv_analog2, 1); + else + CV_SetValue(&cv_analog2, 0); +} + +static void Analog_OnChange(void) +{ + if (!cv_cam_dist.string) + return; + if (leveltime > 1) + CV_SetValue(&cv_cam_dist, 128); + + if (netgame || !camera.chase) + CV_StealthSetValue(&cv_analog, 0); + else if (cv_analog.value || demoplayback) + CV_SetValue(&cv_cam_dist, 192); +} + +static void Analog2_OnChange(void) +{ + if (!splitscreen || !cv_cam2_dist.string) + return; + if (leveltime > 1) + CV_SetValue(&cv_cam2_dist, 128); + if (netgame || !camera2.chase) + CV_StealthSetValue(&cv_analog2, 0); + else if (cv_analog2.value) + CV_SetValue(&cv_cam2_dist, 192); +} + +// +// G_DoLoadLevel +// +void G_DoLoadLevel(boolean resetplayer) +{ + INT32 i; + + // Make sure objectplace is OFF when you first start the level! + OP_ResetObjectplace(); + + levelstarttic = gametic; // for time calculation + + if (wipegamestate == GS_LEVEL) + wipegamestate = -1; // force a wipe + + if (gamestate == GS_INTERMISSION) + Y_EndIntermission(); + + G_SetGamestate(GS_LEVEL); + + for (i = 0; i < MAXPLAYERS; i++) + { + if (resetplayer || (playeringame[i] && players[i].playerstate == PST_DEAD)) + players[i].playerstate = PST_REBORN; + } + + // Setup the level. + if (!P_SetupLevel(false)) + { + // fail so reset game stuff + Command_ExitGame_f(); + return; + } + + if (!resetplayer) + P_FindEmerald(); + + displayplayer = consoleplayer; // view the guy you are playing + if (!splitscreen && !botingame) + secondarydisplayplayer = consoleplayer; + + gameaction = ga_nothing; +#ifdef PARANOIA + Z_CheckHeap(-2); +#endif + + if (camera.chase) + P_ResetCamera(&players[displayplayer], &camera); + if (camera2.chase && splitscreen) + P_ResetCamera(&players[secondarydisplayplayer], &camera2); + + // clear cmd building stuff + memset(gamekeydown, 0, sizeof (gamekeydown)); + for (i = 0;i < JOYAXISSET; i++) + { + joyxmove[i] = joyymove[i] = 0; + joy2xmove[i] = joy2ymove[i] = 0; + } + mousex = mousey = 0; + mouse2x = mouse2y = 0; + + // clear hud messages remains (usually from game startup) + CON_ClearHUD(); +} + +static INT32 pausedelay = 0; +static INT32 camtoggledelay, camtoggledelay2 = 0; + +// +// G_Responder +// Get info needed to make ticcmd_ts for the players. +// +boolean G_Responder(event_t *ev) +{ + // allow spy mode changes even during the demo + if (gamestate == GS_LEVEL && ev->type == ev_keydown && ev->data1 == KEY_F12) + { + if (splitscreen || !netgame) + displayplayer = consoleplayer; + else + { + // spy mode + do + { + displayplayer++; + if (displayplayer == MAXPLAYERS) + displayplayer = 0; + + if (!playeringame[displayplayer]) + continue; + + if (players[displayplayer].spectator) + continue; + + if (G_GametypeHasTeams()) + { + if (players[consoleplayer].ctfteam + && players[displayplayer].ctfteam != players[consoleplayer].ctfteam) + continue; + } + else if (gametype == GT_HIDEANDSEEK) + { + if (players[consoleplayer].pflags & PF_TAGIT) + continue; + } + // Other Tag-based gametypes? + else if (G_TagGametype()) + { + if (!players[consoleplayer].spectator + && (players[consoleplayer].pflags & PF_TAGIT) != (players[displayplayer].pflags & PF_TAGIT)) + continue; + } + else if (G_RingSlingerGametype()) + { + if (!players[consoleplayer].spectator) + continue; + } + + break; + } while (displayplayer != consoleplayer); + + // change statusbar also if playing back demo + if (singledemo) + ST_changeDemoView(); + + // tell who's the view + CONS_Printf(M_GetText("Viewpoint: %s\n"), player_names[displayplayer]); + + return true; + } + } + + // any other key pops up menu if in demos + if (gameaction == ga_nothing && !singledemo && + ((demoplayback && !modeattacking && !titledemo) || gamestate == GS_TITLESCREEN)) + { + if (ev->type == ev_keydown && ev->data1 != 301) + { + M_StartControlPanel(); + return true; + } + return false; + } + else if (demoplayback && titledemo) + { + // Title demo uses intro responder + if (F_IntroResponder(ev)) + { + // stop the title demo + G_CheckDemoStatus(); + return true; + } + return false; + } + + if (gamestate == GS_LEVEL) + { + if (HU_Responder(ev)) + return true; // chat ate the event + if (AM_Responder(ev)) + return true; // automap ate it + // map the event (key/mouse/joy) to a gamecontrol + } + // Intro + else if (gamestate == GS_INTRO) + { + if (F_IntroResponder(ev)) + { + D_StartTitle(); + return true; + } + } + else if (gamestate == GS_CUTSCENE) + { + if (HU_Responder(ev)) + return true; // chat ate the event + + if (F_CutsceneResponder(ev)) + { + D_StartTitle(); + return true; + } + } + + else if (gamestate == GS_CREDITS) + { + if (HU_Responder(ev)) + return true; // chat ate the event + + if (F_CreditResponder(ev)) + { + F_StartGameEvaluation(); + return true; + } + } + + else if (gamestate == GS_CONTINUING) + { + if (F_ContinueResponder(ev)) + return true; + } + // Demo End + else if (gamestate == GS_GAMEEND || gamestate == GS_EVALUATION || gamestate == GS_CREDITS) + return true; + + else if (gamestate == GS_INTERMISSION) + if (HU_Responder(ev)) + return true; // chat ate the event + + // update keys current state + G_MapEventsToControls(ev); + + switch (ev->type) + { + case ev_keydown: + if (ev->data1 == gamecontrol[gc_pause][0] + || ev->data1 == gamecontrol[gc_pause][1]) + { + if (!pausedelay) + { + // don't let busy scripts prevent pausing + pausedelay = NEWTICRATE/7; + + if (cv_pause.value == 1 || server || (adminplayer == consoleplayer)) + { + if (!(gamestate == GS_LEVEL || gamestate == GS_INTERMISSION)) + { + CONS_Printf(M_GetText("You can't pause here.\n")); + return true; + } + + COM_ImmedExecute("pause"); + } + else + CONS_Printf(M_GetText("Only the server or a remote admin can use this.\n")); + return true; + } + else + pausedelay = NEWTICRATE/7; + } + if (ev->data1 == gamecontrol[gc_camtoggle][0] + || ev->data1 == gamecontrol[gc_camtoggle][1]) + { + if (!camtoggledelay) + { + camtoggledelay = NEWTICRATE / 7; + CV_SetValue(&cv_chasecam, cv_chasecam.value ? 0 : 1); + } + } + if (ev->data1 == gamecontrolbis[gc_camtoggle][0] + || ev->data1 == gamecontrolbis[gc_camtoggle][1]) + { + if (!camtoggledelay2) + { + camtoggledelay2 = NEWTICRATE / 7; + CV_SetValue(&cv_chasecam2, cv_chasecam2.value ? 0 : 1); + } + } + return true; + + case ev_keyup: + return false; // always let key up events filter down + + case ev_mouse: + return true; // eat events + + case ev_joystick: + return true; // eat events + + case ev_joystick2: + return true; // eat events + + + default: + break; + } + + return false; +} + +// +// G_Ticker +// Make ticcmd_ts for the players. +// +void G_Ticker(boolean run) +{ + UINT32 i; + INT32 buf; + + P_MapStart(); + // do player reborns if needed + if (gamestate == GS_LEVEL) + { + // Or, alternatively, retry. + if (!(netgame || multiplayer) && G_GetRetryFlag()) + { + G_ClearRetryFlag(); + + // Costs a life to retry ... unless the player in question is dead already. + if (G_GametypeUsesLives() && players[consoleplayer].playerstate == PST_LIVE) + players[consoleplayer].lives -= 1; + + G_DoReborn(consoleplayer); + } + + for (i = 0; i < MAXPLAYERS; i++) + { + if (playeringame[i]) + { + if (players[i].playerstate == PST_REBORN) + { + G_DoReborn(i); + } + } + } + } + P_MapEnd(); + + // do things to change the game state + while (gameaction != ga_nothing) + switch (gameaction) + { + case ga_completed: G_DoCompleted(); break; + case ga_startcont: G_DoStartContinue(); break; + case ga_continued: G_DoContinued(); break; + case ga_worlddone: G_DoWorldDone(); break; + case ga_nothing: break; + default: I_Error("gameaction = %d\n", gameaction); + } + + buf = gametic % BACKUPTICS; + + // read/write demo and check turbo cheat + for (i = 0; i < MAXPLAYERS; i++) + { + if (playeringame[i]) + G_CopyTiccmd(&players[i].cmd, &netcmds[buf][i], 1); + } + + // do main actions + switch (gamestate) + { + case GS_LEVEL: + if (titledemo) + F_TitleDemoTicker(); + P_Ticker(run); // tic the game + ST_Ticker(); + AM_Ticker(); + HU_Ticker(); + break; + + case GS_INTERMISSION: + if (run) + Y_Ticker(); + HU_Ticker(); + break; + + case GS_TIMEATTACK: + break; + + case GS_INTRO: + if (run) + F_IntroTicker(); + break; + + case GS_CUTSCENE: + if (run) + F_CutsceneTicker(); + HU_Ticker(); + break; + + case GS_GAMEEND: + if (run) + F_GameEndTicker(); + break; + + case GS_EVALUATION: + if (run) + F_GameEvaluationTicker(); + break; + + case GS_CONTINUING: + if (run) + F_ContinueTicker(); + break; + + case GS_CREDITS: + if (run) + F_CreditTicker(); + HU_Ticker(); + break; + + case GS_TITLESCREEN: + case GS_WAITINGPLAYERS: + F_TitleScreenTicker(run); + break; + + case GS_DEDICATEDSERVER: + case GS_NULL: + break; // do nothing + } + + if (run) + { + if (pausedelay) + pausedelay--; + + if (camtoggledelay) + camtoggledelay--; + + if (camtoggledelay2) + camtoggledelay2--; + } +} + +// +// PLAYER STRUCTURE FUNCTIONS +// also see P_SpawnPlayer in P_Things +// + +// +// G_PlayerFinishLevel +// Called when a player completes a level. +// +static inline void G_PlayerFinishLevel(INT32 player) +{ + player_t *p; + + p = &players[player]; + + memset(p->powers, 0, sizeof (p->powers)); + p->ringweapons = 0; + + p->mo->flags2 &= ~MF2_SHADOW; // cancel invisibility + P_FlashPal(p, 0, 0); // Resets + p->starpostangle = 0; + p->starposttime = 0; + p->starpostx = 0; + p->starposty = 0; + p->starpostz = 0; + p->starpostnum = 0; + + if (rendermode == render_soft) + V_SetPaletteLump(GetPalette()); // Reset the palette +} + +// +// G_PlayerReborn +// Called after a player dies. Almost everything is cleared and initialized. +// +void G_PlayerReborn(INT32 player) +{ + player_t *p; + INT32 score; + INT32 lives; + INT32 continues; + INT32 xtralife; + UINT8 charability; + UINT8 charability2; + fixed_t normalspeed; + fixed_t runspeed; + UINT8 thrustfactor; + UINT8 accelstart; + UINT8 acceleration; + INT32 charflags; + INT32 pflags; + UINT32 thokitem; + UINT32 spinitem; + UINT32 revitem; + fixed_t actionspd; + fixed_t mindash; + fixed_t maxdash; + INT32 ctfteam; + INT32 starposttime; + INT16 starpostx; + INT16 starposty; + INT16 starpostz; + INT32 starpostnum; + INT32 starpostangle; + fixed_t jumpfactor; + INT32 exiting; + INT32 numboxes; + INT32 laps; + INT32 totalring; + UINT8 mare; + UINT8 skincolor; + INT32 skin; + tic_t jointime; + boolean spectator; + INT16 bot; + SINT8 pity; + + score = players[player].score; + lives = players[player].lives; + continues = players[player].continues; + xtralife = players[player].xtralife; + ctfteam = players[player].ctfteam; + exiting = players[player].exiting; + jointime = players[player].jointime; + spectator = players[player].spectator; + pflags = (players[player].pflags & (PF_TIMEOVER|PF_FLIPCAM|PF_TAGIT|PF_TAGGED|PF_CONSISTANCY)); + + // As long as we're not in multiplayer, carry over cheatcodes from map to map + if (!(netgame || multiplayer)) + pflags |= (players[player].pflags & (PF_GODMODE|PF_NOCLIP|PF_INVIS)); + + numboxes = players[player].numboxes; + laps = players[player].laps; + totalring = players[player].totalring; + + skincolor = players[player].skincolor; + skin = players[player].skin; + charability = players[player].charability; + charability2 = players[player].charability2; + normalspeed = players[player].normalspeed; + runspeed = players[player].runspeed; + thrustfactor = players[player].thrustfactor; + accelstart = players[player].accelstart; + acceleration = players[player].acceleration; + charflags = players[player].charflags; + + starposttime = players[player].starposttime; + starpostx = players[player].starpostx; + starposty = players[player].starposty; + starpostz = players[player].starpostz; + starpostnum = players[player].starpostnum; + starpostangle = players[player].starpostangle; + jumpfactor = players[player].jumpfactor; + thokitem = players[player].thokitem; + spinitem = players[player].spinitem; + revitem = players[player].revitem; + actionspd = players[player].actionspd; + mindash = players[player].mindash; + maxdash = players[player].maxdash; + + mare = players[player].mare; + bot = players[player].bot; + pity = players[player].pity; + + p = &players[player]; + memset(p, 0, sizeof (*p)); + + p->score = score; + p->lives = lives; + p->continues = continues; + p->pflags = pflags; + p->xtralife = xtralife; + p->ctfteam = ctfteam; + p->jointime = jointime; + p->spectator = spectator; + + // save player config truth reborn + p->skincolor = skincolor; + p->skin = skin; + p->charability = charability; + p->charability2 = charability2; + p->normalspeed = normalspeed; + p->runspeed = runspeed; + p->thrustfactor = thrustfactor; + p->accelstart = accelstart; + p->acceleration = acceleration; + p->charflags = charflags; + p->thokitem = thokitem; + p->spinitem = spinitem; + p->revitem = revitem; + p->actionspd = actionspd; + p->mindash = mindash; + p->maxdash = maxdash; + + p->starposttime = starposttime; + p->starpostx = starpostx; + p->starposty = starposty; + p->starpostz = starpostz; + p->starpostnum = starpostnum; + p->starpostangle = starpostangle; + p->jumpfactor = jumpfactor; + p->exiting = exiting; + + p->numboxes = numboxes; + p->laps = laps; + p->totalring = totalring; + + p->mare = mare; + if (bot) + p->bot = 1; // reset to AI-controlled + p->pity = pity; + + // Don't do anything immediately + p->pflags |= PF_USEDOWN; + p->pflags |= PF_ATTACKDOWN; + p->pflags |= PF_JUMPDOWN; + + p->playerstate = PST_LIVE; + p->health = 1; // 0 rings + p->panim = PA_IDLE; // standing animation + + if ((netgame || multiplayer) && !p->spectator + && gametype != GT_RACE) + p->powers[pw_flashing] = flashingtics-1; // Babysitting deterrent + + if (p-players == consoleplayer) + { + if (mapmusic & MUSIC_RELOADRESET) // TODO: Might not need this here + { + mapmusic = mapheaderinfo[gamemap-1]->musicslot + | (mapheaderinfo[gamemap-1]->musicslottrack << MUSIC_TRACKSHIFT); + } + S_ChangeMusic(mapmusic, true); + } + + if (gametype == GT_COOP) + P_FindEmerald(); // scan for emeralds to hunt for + + // Reset Nights score and max link to 0 on death + p->marescore = p->maxlink = 0; + + // If NiGHTS, find lowest mare to start with. + p->mare = P_FindLowestMare(); + + CONS_Debug(DBG_NIGHTS, M_GetText("Current mare is %d\n"), p->mare); + + if (p->mare == 255) + p->mare = 0; + + // Check to make sure their color didn't change somehow... + if (G_GametypeHasTeams()) + { + if (p->ctfteam == 1 && p->skincolor != skincolor_redteam) + { + if (p == &players[consoleplayer]) + CV_SetValue(&cv_playercolor, skincolor_redteam); + else if (p == &players[secondarydisplayplayer]) + CV_SetValue(&cv_playercolor2, skincolor_redteam); + } + else if (p->ctfteam == 2 && p->skincolor != skincolor_blueteam) + { + if (p == &players[consoleplayer]) + CV_SetValue(&cv_playercolor, skincolor_blueteam); + else if (p == &players[secondarydisplayplayer]) + CV_SetValue(&cv_playercolor2, skincolor_blueteam); + } + } +} + +// +// G_CheckSpot +// Returns false if the player cannot be respawned +// at the given mapthing_t spot +// because something is occupying it +// +static boolean G_CheckSpot(INT32 playernum, mapthing_t *mthing) +{ + fixed_t x; + fixed_t y; + INT32 i; + + // maybe there is no player start + if (!mthing) + return false; + + if (!players[playernum].mo) + { + // first spawn of level + for (i = 0; i < playernum; i++) + if (playeringame[i] && players[i].mo + && players[i].mo->x == mthing->x << FRACBITS + && players[i].mo->y == mthing->y << FRACBITS) + { + return false; + } + return true; + } + + x = mthing->x << FRACBITS; + y = mthing->y << FRACBITS; + + if (!P_CheckPosition(players[playernum].mo, x, y)) + return false; + + return true; +} + +// +// G_SpawnPlayer +// Spawn a player in a spot appropriate for the gametype -- +// or a not-so-appropriate spot, if it initially fails +// due to a lack of starts open or something. +// +void G_SpawnPlayer(INT32 playernum, boolean starpost) +{ + mapthing_t *spawnpoint; + + if (!playeringame[playernum]) + return; + + P_SpawnPlayer(playernum); + + if (starpost) //Don't even bother with looking for a place to spawn. + { + P_MovePlayerToStarpost(playernum); + return; + } + + // -- CTF -- + // Order: CTF->DM->Coop + if (gametype == GT_CTF && players[playernum].ctfteam) + { + if (!(spawnpoint = G_FindCTFStart(playernum)) // find a CTF start + && !(spawnpoint = G_FindMatchStart(playernum))) // find a DM start + spawnpoint = G_FindCoopStart(playernum); // fallback + } + + // -- DM/Tag/CTF-spectator/etc -- + // Order: DM->CTF->Coop + else if (gametype == GT_MATCH || gametype == GT_TEAMMATCH || gametype == GT_CTF + || ((gametype == GT_TAG || gametype == GT_HIDEANDSEEK) && !(players[playernum].pflags & PF_TAGIT)) +#ifdef CHAOSISNOTDEADYET + || gametype == GT_CHAOS +#endif + ) + { + if (!(spawnpoint = G_FindMatchStart(playernum)) // find a DM start + && !(spawnpoint = G_FindCTFStart(playernum))) // find a CTF start + spawnpoint = G_FindCoopStart(playernum); // fallback + } + + // -- Other game modes -- + // Order: Coop->DM->CTF + else + { + if (!(spawnpoint = G_FindCoopStart(playernum)) // find a Co-op start + && !(spawnpoint = G_FindMatchStart(playernum))) // find a DM start + spawnpoint = G_FindCTFStart(playernum); // fallback + } + + //No spawns found. ANYWHERE. + if (!spawnpoint) + { + if (nummapthings) + { + if (playernum == consoleplayer || (splitscreen && playernum == secondarydisplayplayer)) + CONS_Alert(CONS_ERROR, M_GetText("No player spawns found, spawning at the first mapthing!\n")); + spawnpoint = &mapthings[0]; + } + else + { + if (playernum == consoleplayer || (splitscreen && playernum == secondarydisplayplayer)) + CONS_Alert(CONS_ERROR, M_GetText("No player spawns found, spawning at the origin!\n")); + //P_MovePlayerToSpawn handles this fine if the spawnpoint is NULL. + } + } + P_MovePlayerToSpawn(playernum, spawnpoint); +} + +mapthing_t *G_FindCTFStart(INT32 playernum) +{ + INT32 i,j; + + if (!numredctfstarts && !numbluectfstarts) //why even bother, eh? + { + if (playernum == consoleplayer || (splitscreen && playernum == secondarydisplayplayer)) + CONS_Alert(CONS_WARNING, M_GetText("No CTF starts in this map!\n")); + return NULL; + } + + if ((!players[playernum].ctfteam && numredctfstarts && (!numbluectfstarts || P_Random() & 1)) || players[playernum].ctfteam == 1) //red + { + if (!numredctfstarts) + { + if (playernum == consoleplayer || (splitscreen && playernum == secondarydisplayplayer)) + CONS_Alert(CONS_WARNING, M_GetText("No Red Team starts in this map!\n")); + return NULL; + } + + for (j = 0; j < 32; j++) + { + i = P_RandomKey(numredctfstarts); + if (G_CheckSpot(playernum, redctfstarts[i])) + return redctfstarts[i]; + } + + if (playernum == consoleplayer || (splitscreen && playernum == secondarydisplayplayer)) + CONS_Alert(CONS_WARNING, M_GetText("Could not spawn at any Red Team starts!\n")); + return NULL; + } + else if (!players[playernum].ctfteam || players[playernum].ctfteam == 2) //blue + { + if (!numbluectfstarts) + { + if (playernum == consoleplayer || (splitscreen && playernum == secondarydisplayplayer)) + CONS_Alert(CONS_WARNING, M_GetText("No Blue Team starts in this map!\n")); + return NULL; + } + + for (j = 0; j < 32; j++) + { + i = P_RandomKey(numbluectfstarts); + if (G_CheckSpot(playernum, bluectfstarts[i])) + return bluectfstarts[i]; + } + if (playernum == consoleplayer || (splitscreen && playernum == secondarydisplayplayer)) + CONS_Alert(CONS_WARNING, M_GetText("Could not spawn at any Blue Team starts!\n")); + return NULL; + } + //should never be reached but it gets stuff to shut up + return NULL; +} + +mapthing_t *G_FindMatchStart(INT32 playernum) +{ + INT32 i, j; + + if (numdmstarts) + { + for (j = 0; j < 64; j++) + { + i = P_RandomKey(numdmstarts); + if (G_CheckSpot(playernum, deathmatchstarts[i])) + return deathmatchstarts[i]; + } + if (playernum == consoleplayer || (splitscreen && playernum == secondarydisplayplayer)) + CONS_Alert(CONS_WARNING, M_GetText("Could not spawn at any Deathmatch starts!\n")); + return NULL; + } + + if (playernum == consoleplayer || (splitscreen && playernum == secondarydisplayplayer)) + CONS_Alert(CONS_WARNING, M_GetText("No Deathmatch starts in this map!\n")); + return NULL; +} + +mapthing_t *G_FindCoopStart(INT32 playernum) +{ + if (numcoopstarts) + { + //if there's 6 players in a map with 3 player starts, this spawns them 1/2/3/1/2/3. + if (G_CheckSpot(playernum, playerstarts[playernum % numcoopstarts])) + return playerstarts[playernum % numcoopstarts]; + + //Don't bother checking to see if the player 1 start is open. + //Just spawn there. + return playerstarts[0]; + } + + if (playernum == consoleplayer || (splitscreen && playernum == secondarydisplayplayer)) + CONS_Alert(CONS_WARNING, M_GetText("No Co-op starts in this map!\n")); + return NULL; +} + +// Go back through all the projectiles and remove all references to the old +// player mobj, replacing them with the new one. +void G_ChangePlayerReferences(mobj_t *oldmo, mobj_t *newmo) +{ + thinker_t *th; + mobj_t *mo2; + + I_Assert((oldmo != NULL) && (newmo != NULL)); + + // scan all thinkers + for (th = thinkercap.next; th != &thinkercap; th = th->next) + { + if (th->function.acp1 != (actionf_p1)P_MobjThinker) + continue; + + mo2 = (mobj_t *)th; + + if (!(mo2->flags & MF_MISSILE)) + continue; + + if (mo2->target == oldmo) + { + P_SetTarget(&mo2->target, newmo); + mo2->flags2 |= MF2_BEYONDTHEGRAVE; // this mobj belongs to a player who has reborn + } + } +} + +// +// G_DoReborn +// +void G_DoReborn(INT32 playernum) +{ + player_t *player = &players[playernum]; + boolean starpost = false; + + if (modeattacking) + { + M_EndModeAttackRun(); + return; + } + + // Make sure objectplace is OFF when you first start the level! + OP_ResetObjectplace(); + + if (player->bot && playernum != consoleplayer) + { // Bots respawn next to their master. + mobj_t *oldmo = NULL; + + // first dissasociate the corpse + if (player->mo) + { + oldmo = player->mo; + // Don't leave your carcass stuck 10-billion feet in the ground! + P_RemoveMobj(player->mo); + } + + B_RespawnBot(playernum); + if (oldmo) + G_ChangePlayerReferences(oldmo, players[playernum].mo); + } + else if (countdowntimeup || (!multiplayer && gametype == GT_COOP)) + { + // reload the level from scratch + if (countdowntimeup) + { + player->starpostangle = 0; + player->starposttime = 0; + player->starpostx = 0; + player->starposty = 0; + player->starpostz = 0; + player->starpostnum = 0; + } + if (!countdowntimeup && (mapheaderinfo[gamemap-1]->levelflags & LF_NORELOAD)) + { + INT32 i; + + P_LoadThingsOnly(); + + P_ClearStarPost(player->starpostnum); + + // Do a wipe + wipegamestate = -1; + + if (player->starposttime) + starpost = true; + + if (camera.chase) + P_ResetCamera(&players[displayplayer], &camera); + if (camera2.chase && splitscreen) + P_ResetCamera(&players[secondarydisplayplayer], &camera2); + + // clear cmd building stuff + memset(gamekeydown, 0, sizeof (gamekeydown)); + for (i = 0;i < JOYAXISSET; i++) + { + joyxmove[i] = joyymove[i] = 0; + joy2xmove[i] = joy2ymove[i] = 0; + } + mousex = mousey = 0; + mouse2x = mouse2y = 0; + + // clear hud messages remains (usually from game startup) + CON_ClearHUD(); + + // Starpost support + G_SpawnPlayer(playernum, starpost); + } + else +#ifdef HAVE_BLUA + { + LUAh_MapChange(); +#endif + G_DoLoadLevel(true); +#ifdef HAVE_BLUA + } +#endif + } + else + { + // respawn at the start + mobj_t *oldmo = NULL; + + if (player->starposttime) + starpost = true; + + // first dissasociate the corpse + if (player->mo) + { + oldmo = player->mo; + // Don't leave your carcass stuck 10-billion feet in the ground! + P_RemoveMobj(player->mo); + } + + G_SpawnPlayer(playernum, starpost); + if (oldmo) + G_ChangePlayerReferences(oldmo, players[playernum].mo); + } +} + +void G_AddPlayer(INT32 playernum) +{ + player_t *p = &players[playernum]; + + p->jointime = 0; + p->playerstate = PST_REBORN; +} + +void G_ExitLevel(void) +{ + if (gamestate == GS_LEVEL) + { + gameaction = ga_completed; + lastdraw = true; + + // If you want your teams scrambled on map change, start the process now. + // The teams will scramble at the start of the next round. + if (cv_scrambleonchange.value && G_GametypeHasTeams()) + { + if (server) + CV_SetValue(&cv_teamscramble, cv_scrambleonchange.value); + } + + if (gametype != GT_COOP) + CONS_Printf(M_GetText("The round has ended.\n")); + } +} + +// +// G_IsSpecialStage +// +// Returns TRUE if +// the given map is a special stage. +// +boolean G_IsSpecialStage(INT32 mapnum) +{ + if (gametype == GT_COOP && modeattacking != ATTACKING_RECORD && mapnum >= sstage_start && mapnum <= sstage_end) + return true; + + return false; +} + +// +// G_GametypeUsesLives +// +// Returns true if the current gametype uses +// the lives system. False otherwise. +// +boolean G_GametypeUsesLives(void) +{ + // Coop, Competitive + if ((gametype == GT_COOP || gametype == GT_COMPETITION) + && !modeattacking // No lives in Time Attack + //&& !G_IsSpecialStage(gamemap) + && !(maptol & TOL_NIGHTS)) // No lives in NiGHTS + return true; + return false; +} + +// +// G_GametypeHasTeams +// +// Returns true if the current gametype uses +// Red/Blue teams. False otherwise. +// +boolean G_GametypeHasTeams(void) +{ + return (gametype == GT_TEAMMATCH || gametype == GT_CTF); +} + +// +// G_GametypeHasSpectators +// +// Returns true if the current gametype supports +// spectators. False otherwise. +// +boolean G_GametypeHasSpectators(void) +{ + return (gametype != GT_COOP && gametype != GT_COMPETITION && gametype != GT_RACE); +} + +// +// G_RingSlingerGametype +// +// Returns true if the current gametype supports firing rings. +// ANY gametype can be a ringslinger gametype, just flick a switch. +// +boolean G_RingSlingerGametype(void) +{ + return ((gametype != GT_COOP && gametype != GT_COMPETITION && gametype != GT_RACE) || (cv_ringslinger.value)); +} + +// +// G_PlatformGametype +// +// Returns true if a gametype is a more traditional platforming-type. +// +boolean G_PlatformGametype(void) +{ + return (gametype == GT_COOP || gametype == GT_RACE || gametype == GT_COMPETITION); +} + +// +// G_TagGametype +// +// For Jazz's Tag/HnS modes that have a lot of special cases.. +// +boolean G_TagGametype(void) +{ + return (gametype == GT_TAG || gametype == GT_HIDEANDSEEK); +} + +/** Get the typeoflevel flag needed to indicate support of a gametype. + * In single-player, this always returns TOL_SP. + * \param gametype The gametype for which support is desired. + * \return The typeoflevel flag to check for that gametype. + * \author Graue + */ +INT16 G_TOLFlag(INT32 pgametype) +{ + if (!multiplayer) return TOL_SP; + if (pgametype == GT_COOP) return TOL_COOP; + if (pgametype == GT_COMPETITION) return TOL_COMPETITION; + if (pgametype == GT_RACE) return TOL_RACE; + if (pgametype == GT_MATCH) return TOL_MATCH; + if (pgametype == GT_TEAMMATCH) return TOL_MATCH; +#ifdef CHAOSISNOTDEADYET + if (pgametype == GT_CHAOS) return TOL_CHAOS; +#endif + if (pgametype == GT_TAG) return TOL_TAG; + if (pgametype == GT_HIDEANDSEEK) return TOL_TAG; + if (pgametype == GT_CTF) return TOL_CTF; + + CONS_Alert(CONS_ERROR, M_GetText("Unknown gametype! %d\n"), pgametype); + return INT16_MAX; +} + +/** Select a random map with the given typeoflevel flags. + * If no map has those flags, this arbitrarily gives you map 1. + * \param tolflags The typeoflevel flags to insist on. Other bits may + * be on too, but all of these must be on. + * \return A random map with those flags, 1-based, or 1 if no map + * has those flags. + * \author Graue + */ +static INT16 RandMap(INT16 tolflags, INT16 pprevmap) +{ + INT16 *okmaps = Z_Malloc(NUMMAPS * sizeof(INT16), PU_STATIC, NULL); + INT32 numokmaps = 0; + INT16 ix; + + // Find all the maps that are ok and and put them in an array. + for (ix = 0; ix < NUMMAPS; ix++) + if (mapheaderinfo[ix] && (mapheaderinfo[ix]->typeoflevel & tolflags) == tolflags + && ix != pprevmap // Don't pick the same map. + && (dedicated || !M_MapLocked(ix+1)) // Don't pick locked maps. + ) + okmaps[numokmaps++] = ix; + + if (numokmaps == 0) + ix = 0; // Sorry, none match. You get MAP01. + else + ix = okmaps[M_RandomKey(numokmaps)]; + + Z_Free(okmaps); + + return ix; +} + +// +// G_DoCompleted +// +static void G_DoCompleted(void) +{ + INT32 i; + boolean gottoken = false; + + tokenlist = 0; // Reset the list + + gameaction = ga_nothing; + + if (metalrecording || metalplayback) + G_CheckDemoStatus(); + + for (i = 0; i < MAXPLAYERS; i++) + if (playeringame[i]) + G_PlayerFinishLevel(i); // take away cards and stuff + + if (automapactive) + AM_Stop(); + + S_StopSounds(); + + prevmap = (INT16)(gamemap-1); + + // go to next level + // nextmap is 0-based, unlike gamemap + if (nextmapoverride != 0) + nextmap = (INT16)(nextmapoverride-1); + else + nextmap = (INT16)(mapheaderinfo[gamemap-1]->nextlevel-1); + + // Remember last map for when you come out of the special stage. + if (!G_IsSpecialStage(gamemap)) + lastmap = nextmap; + + // If nextmap is actually going to get used, make sure it points to + // a map of the proper gametype -- skip levels that don't support + // the current gametype. (Helps avoid playing boss levels in Race, + // for instance). + if (!token && !G_IsSpecialStage(gamemap) + && (nextmap >= 0 && nextmap < NUMMAPS)) + { + register INT16 cm = nextmap; + INT16 tolflag = G_TOLFlag(gametype); + UINT8 visitedmap[(NUMMAPS+7)/8]; + + memset(visitedmap, 0, sizeof (visitedmap)); + + while (!mapheaderinfo[cm] || !(mapheaderinfo[cm]->typeoflevel & tolflag)) + { + visitedmap[cm/8] |= (1<<(cm&7)); + if (!mapheaderinfo[cm]) + cm = -1; // guarantee error execution + else + cm = (INT16)(mapheaderinfo[cm]->nextlevel-1); + + if (cm >= NUMMAPS || cm < 0) // out of range (either 1100-1102 or error) + { + cm = nextmap; //Start the loop again so that the error checking below is executed. + + //Make sure the map actually exists before you try to go to it! + if ((W_CheckNumForName(G_BuildMapName(cm + 1)) == LUMPERROR)) + { + CONS_Alert(CONS_ERROR, M_GetText("Next map given (MAP %d) doesn't exist! Reverting to MAP01.\n"), cm+1); + cm = 0; + break; + } + } + + if (visitedmap[cm/8] & (1<<(cm&7))) // smells familiar + { + // We got stuck in a loop, came back to the map we started on + // without finding one supporting the current gametype. + // Thus, print a warning, and just use this map anyways. + CONS_Alert(CONS_WARNING, M_GetText("Can't find a compatible map after map %d; using map %d anyway\n"), prevmap+1, cm+1); + break; + } + } + nextmap = cm; + } + + if (nextmap < 0 || (nextmap >= NUMMAPS && nextmap < 1100-1) || nextmap > 1102-1) + I_Error("Followed map %d to invalid map %d\n", prevmap + 1, nextmap + 1); + + // wrap around in race + if (nextmap >= 1100-1 && nextmap <= 1102-1 && (gametype == GT_RACE || gametype == GT_COMPETITION)) + nextmap = (INT16)(spstage_start-1); + + if (gametype == GT_COOP && token) + { + token--; + gottoken = true; + + if (!(emeralds & EMERALD1)) + nextmap = (INT16)(sstage_start - 1); // Special Stage 1 + else if (!(emeralds & EMERALD2)) + nextmap = (INT16)(sstage_start); // Special Stage 2 + else if (!(emeralds & EMERALD3)) + nextmap = (INT16)(sstage_start + 1); // Special Stage 3 + else if (!(emeralds & EMERALD4)) + nextmap = (INT16)(sstage_start + 2); // Special Stage 4 + else if (!(emeralds & EMERALD5)) + nextmap = (INT16)(sstage_start + 3); // Special Stage 5 + else if (!(emeralds & EMERALD6)) + nextmap = (INT16)(sstage_start + 4); // Special Stage 6 + else if (!(emeralds & EMERALD7)) + nextmap = (INT16)(sstage_start + 5); // Special Stage 7 + else + gottoken = false; + } + + if (G_IsSpecialStage(gamemap) && !gottoken) + nextmap = lastmap; // Exiting from a special stage? Go back to the game. Tails 08-11-2001 + + automapactive = false; + + if (gametype != GT_COOP) + { + if (cv_advancemap.value == 0) // Stay on same map. + nextmap = prevmap; + else if (cv_advancemap.value == 2) // Go to random map. + nextmap = RandMap(G_TOLFlag(gametype), prevmap); + } + + // We are committed to this map now. + // We may as well allocate its header if it doesn't exist + if(!mapheaderinfo[nextmap]) + P_AllocMapHeader(nextmap); + + if (skipstats) + G_AfterIntermission(); + else + { + G_SetGamestate(GS_INTERMISSION); + Y_StartIntermission(); + } +} + +void G_AfterIntermission(void) +{ + HU_ClearCEcho(); + + if (mapheaderinfo[gamemap-1]->cutscenenum && !modeattacking) // Start a custom cutscene. + F_StartCustomCutscene(mapheaderinfo[gamemap-1]->cutscenenum-1, false, false); + else + { + if (nextmap < 1100-1) + G_NextLevel(); + else + Y_EndGame(); + } +} + +// +// G_NextLevel (WorldDone) +// +// init next level or go to the final scene +// called by end of intermission screen (y_inter) +// +void G_NextLevel(void) +{ + gameaction = ga_worlddone; +} + +static void G_DoWorldDone(void) +{ + if (server) + { + INT32 nextgametype; + + // for custom exit (linetype 2) that changes gametype + if (nextmapgametype != -1) + nextgametype = nextmapgametype; + else + { + // use current gametype by default + nextgametype = gametype; + } + + if (gametype == GT_COOP && nextgametype == GT_COOP) + // don't reset player between maps + D_MapChange(nextmap+1, nextgametype, ultimatemode, false, 0, false, false); + else + // resetplayer in match/chaos/tag/CTF/race for more equality + D_MapChange(nextmap+1, nextgametype, ultimatemode, true, 0, false, false); + } + + gameaction = ga_nothing; +} + +// +// G_UseContinue +// +void G_UseContinue(void) +{ + if (gamestate == GS_LEVEL && !netgame && !multiplayer) + { + gameaction = ga_startcont; + lastdraw = true; + } +} + +static void G_DoStartContinue(void) +{ + I_Assert(!netgame && !multiplayer); + + G_PlayerFinishLevel(consoleplayer); // take away cards and stuff + + F_StartContinue(); + gameaction = ga_nothing; +} + +// +// G_Continue +// +// re-init level, used by continue and possibly countdowntimeup +// +void G_Continue(void) +{ + if (!netgame && !multiplayer) + gameaction = ga_continued; +} + +static void G_DoContinued(void) +{ + player_t *pl = &players[consoleplayer]; + I_Assert(!netgame && !multiplayer); + I_Assert(pl->continues > 0); + + pl->continues--; + + // Reset score + pl->score = 0; + + // Allow tokens to come back + tokenlist = 0; + token = 0; + + // Reset # of lives + pl->lives = (ultimatemode) ? 1 : 3; + + D_MapChange(gamemap, gametype, ultimatemode, false, 0, false, false); + + gameaction = ga_nothing; +} + +// +// G_LoadGameSettings +// +// Sets a tad of default info we need. +void G_LoadGameSettings(void) +{ + // defaults + spstage_start = 1; + sstage_start = 50; + sstage_end = 57; // 8 special stages in vanilla SRB2 + useNightsSS = false; //true; + + // initialize free sfx slots for skin sounds + S_InitRuntimeSounds(); +} + +// G_LoadGameData +// Loads the main data file, which stores information such as emblems found, etc. +void G_LoadGameData(void) +{ + size_t length; + INT32 i, j; + UINT8 modded = false; + UINT8 rtemp; + + //For records + UINT32 recscore; + tic_t rectime; + UINT16 recrings; + + UINT8 recmares; + INT32 curmare; + + // Clear things so previously read gamedata doesn't transfer + // to new gamedata + G_ClearRecords(); // main and nights records + M_ClearSecrets(); // emblems, unlocks, maps visited, etc + totalplaytime = 0; // total play time (separate from all) + + if (M_CheckParm("-nodata")) + return; // Don't load. + + // Allow saving of gamedata beyond this point + gamedataloaded = true; + + if (M_CheckParm("-resetdata")) + return; // Don't load (essentially, reset). + + length = FIL_ReadFile(va(pandf, srb2home, gamedatafilename), &savebuffer); + if (!length) // Aw, no game data. Their loss! + return; + + save_p = savebuffer; + + // Version check + if (READUINT32(save_p) != 0xFCAFE211) + { + const char *gdfolder = "the SRB2 folder"; + if (strcmp(srb2home,".")) + gdfolder = srb2home; + + Z_Free(savebuffer); + save_p = NULL; + I_Error("Game data is from another version of SRB2.\nDelete %s(maybe in %s) and try again.", gamedatafilename, gdfolder); + } + + totalplaytime = READUINT32(save_p); + + modded = READUINT8(save_p); + + // Aha! Someone's been screwing with the save file! + if ((modded && !savemoddata)) + goto datacorrupt; + else if (modded != true && modded != false) + goto datacorrupt; + + // TODO put another cipher on these things? meh, I don't care... + for (i = 0; i < NUMMAPS; i++) + if ((mapvisited[i] = READUINT8(save_p)) > MV_MAX) + goto datacorrupt; + + // To save space, use one bit per collected/achieved/unlocked flag + for (i = 0; i < MAXEMBLEMS;) + { + rtemp = READUINT8(save_p); + for (j = 0; j < 8 && j+i < MAXEMBLEMS; ++j) + emblemlocations[j+i].collected = ((rtemp >> j) & 1); + i += j; + } + for (i = 0; i < MAXEXTRAEMBLEMS;) + { + rtemp = READUINT8(save_p); + for (j = 0; j < 8 && j+i < MAXEXTRAEMBLEMS; ++j) + extraemblems[j+i].collected = ((rtemp >> j) & 1); + i += j; + } + for (i = 0; i < MAXUNLOCKABLES;) + { + rtemp = READUINT8(save_p); + for (j = 0; j < 8 && j+i < MAXUNLOCKABLES; ++j) + unlockables[j+i].unlocked = ((rtemp >> j) & 1); + i += j; + } + for (i = 0; i < MAXCONDITIONSETS;) + { + rtemp = READUINT8(save_p); + for (j = 0; j < 8 && j+i < MAXCONDITIONSETS; ++j) + conditionSets[j+i].achieved = ((rtemp >> j) & 1); + i += j; + } + + timesBeaten = READUINT32(save_p); + timesBeatenWithEmeralds = READUINT32(save_p); + timesBeatenUltimate = READUINT32(save_p); + + // Main records + for (i = 0; i < NUMMAPS; ++i) + { + recscore = READUINT32(save_p); + rectime = (tic_t)READUINT32(save_p); + recrings = READUINT16(save_p); + + if (recrings > 10000 || recscore > MAXSCORE) + goto datacorrupt; + + if (recscore || rectime || recrings) + { + G_AllocMainRecordData((INT16)i); + mainrecords[i]->score = recscore; + mainrecords[i]->time = rectime; + mainrecords[i]->rings = recrings; + } + } + + // Nights records + for (i = 0; i < NUMMAPS; ++i) + { + if ((recmares = READUINT8(save_p)) == 0) + continue; + + G_AllocNightsRecordData((INT16)i); + + for (curmare = 0; curmare < (recmares+1); ++curmare) + { + nightsrecords[i]->score[curmare] = READUINT32(save_p); + nightsrecords[i]->grade[curmare] = READUINT8(save_p); + nightsrecords[i]->time[curmare] = (tic_t)READUINT32(save_p); + + if (nightsrecords[i]->grade[curmare] > GRADE_S) + goto datacorrupt; + } + + nightsrecords[i]->nummares = recmares; + } + + // done + Z_Free(savebuffer); + save_p = NULL; + + // Silent update unlockables in case they're out of sync with conditions + M_SilentUpdateUnlockablesAndEmblems(); + + return; + + // Landing point for corrupt gamedata + datacorrupt: + { + const char *gdfolder = "the SRB2 folder"; + if (strcmp(srb2home,".")) + gdfolder = srb2home; + + Z_Free(savebuffer); + save_p = NULL; + + I_Error("Corrupt game data file.\nDelete %s(maybe in %s) and try again.", gamedatafilename, gdfolder); + } +} + +// G_SaveGameData +// Saves the main data file, which stores information such as emblems found, etc. +void G_SaveGameData(void) +{ + size_t length; + INT32 i, j; + UINT8 btemp; + + INT32 curmare; + + if (!gamedataloaded) + return; // If never loaded (-nodata), don't save + + save_p = savebuffer = (UINT8 *)malloc(GAMEDATASIZE); + if (!save_p) + { + CONS_Alert(CONS_ERROR, M_GetText("No more free memory for saving game data\n")); + return; + } + + if (modifiedgame && !savemoddata) + { + free(savebuffer); + save_p = savebuffer = NULL; + return; + } + + // Version test + WRITEUINT32(save_p, 0xFCAFE211); + + WRITEUINT32(save_p, totalplaytime); + + btemp = (UINT8)(savemoddata || modifiedgame); + WRITEUINT8(save_p, btemp); + + // TODO put another cipher on these things? meh, I don't care... + for (i = 0; i < NUMMAPS; i++) + WRITEUINT8(save_p, mapvisited[i]); + + // To save space, use one bit per collected/achieved/unlocked flag + for (i = 0; i < MAXEMBLEMS;) + { + btemp = 0; + for (j = 0; j < 8 && j+i < MAXEMBLEMS; ++j) + btemp |= (emblemlocations[j+i].collected << j); + WRITEUINT8(save_p, btemp); + i += j; + } + for (i = 0; i < MAXEXTRAEMBLEMS;) + { + btemp = 0; + for (j = 0; j < 8 && j+i < MAXEXTRAEMBLEMS; ++j) + btemp |= (extraemblems[j+i].collected << j); + WRITEUINT8(save_p, btemp); + i += j; + } + for (i = 0; i < MAXUNLOCKABLES;) + { + btemp = 0; + for (j = 0; j < 8 && j+i < MAXUNLOCKABLES; ++j) + btemp |= (unlockables[j+i].unlocked << j); + WRITEUINT8(save_p, btemp); + i += j; + } + for (i = 0; i < MAXCONDITIONSETS;) + { + btemp = 0; + for (j = 0; j < 8 && j+i < MAXCONDITIONSETS; ++j) + btemp |= (conditionSets[j+i].achieved << j); + WRITEUINT8(save_p, btemp); + i += j; + } + + WRITEUINT32(save_p, timesBeaten); + WRITEUINT32(save_p, timesBeatenWithEmeralds); + WRITEUINT32(save_p, timesBeatenUltimate); + + // Main records + for (i = 0; i < NUMMAPS; i++) + { + if (mainrecords[i]) + { + WRITEUINT32(save_p, mainrecords[i]->score); + WRITEUINT32(save_p, mainrecords[i]->time); + WRITEUINT16(save_p, mainrecords[i]->rings); + } + else + { + WRITEUINT32(save_p, 0); + WRITEUINT32(save_p, 0); + WRITEUINT16(save_p, 0); + } + } + + // NiGHTS records + for (i = 0; i < NUMMAPS; i++) + { + if (!nightsrecords[i] || !nightsrecords[i]->nummares) + { + WRITEUINT8(save_p, 0); + continue; + } + + WRITEUINT8(save_p, nightsrecords[i]->nummares); + + for (curmare = 0; curmare < (nightsrecords[i]->nummares + 1); ++curmare) + { + WRITEUINT32(save_p, nightsrecords[i]->score[curmare]); + WRITEUINT8(save_p, nightsrecords[i]->grade[curmare]); + WRITEUINT32(save_p, nightsrecords[i]->time[curmare]); + } + } + + length = save_p - savebuffer; + + FIL_WriteFile(va(pandf, srb2home, gamedatafilename), savebuffer, length); + free(savebuffer); + save_p = savebuffer = NULL; +} + +#define VERSIONSIZE 16 + +#ifdef SAVEGAMES_OTHERVERSIONS +static INT16 startonmapnum = 0; + +// +// User wants to load a savegame from a different version? +// +static void M_ForceLoadGameResponse(INT32 ch) +{ + if (ch != 'y' && ch != KEY_ENTER) + { + //refused + Z_Free(savebuffer); + save_p = savebuffer = NULL; + startonmapnum = 0; + M_SetupNextMenu(&SP_LoadDef); + return; + } + + // pick up where we left off. + save_p += VERSIONSIZE; + if (!P_LoadGame(startonmapnum)) + { + M_ClearMenus(true); // so ESC backs out to title + M_StartMessage(M_GetText("Savegame file corrupted\n\nPress ESC\n"), NULL, MM_NOTHING); + Command_ExitGame_f(); + Z_Free(savebuffer); + save_p = savebuffer = NULL; + startonmapnum = 0; + + // no cheating! + memset(&savedata, 0, sizeof(savedata)); + return; + } + + // done + Z_Free(savebuffer); + save_p = savebuffer = NULL; + startonmapnum = 0; + + //set cursaveslot to -1 so nothing gets saved. + cursaveslot = -1; + + displayplayer = consoleplayer; + multiplayer = splitscreen = false; + + if (setsizeneeded) + R_ExecuteSetViewSize(); + + M_ClearMenus(true); + CON_ToggleOff(); +} +#endif + +// +// G_InitFromSavegame +// Can be called by the startup code or the menu task. +// +void G_LoadGame(UINT32 slot, INT16 mapoverride) +{ + size_t length; + char vcheck[VERSIONSIZE]; + char savename[255]; + + // memset savedata to all 0, fixes calling perfectly valid saves corrupt because of bots + memset(&savedata, 0, sizeof(savedata)); + +#ifdef SAVEGAME_OTHERVERSIONS + //Oh christ. The force load response needs access to mapoverride too... + startonmapnum = mapoverride; +#endif + + sprintf(savename, savegamename, slot); + + length = FIL_ReadFile(savename, &savebuffer); + if (!length) + { + CONS_Printf(M_GetText("Couldn't read file %s\n"), savename); + return; + } + + save_p = savebuffer; + + memset(vcheck, 0, sizeof (vcheck)); + sprintf(vcheck, "version %d", VERSION); + if (strcmp((const char *)save_p, (const char *)vcheck)) + { +#ifdef SAVEGAME_OTHERVERSIONS + M_StartMessage(M_GetText("Save game from different version.\nYou can load this savegame, but\nsaving afterwards will be disabled.\n\nDo you want to continue anyway?\n\n(Press 'Y' to confirm)\n"), + M_ForceLoadGameResponse, MM_YESNO); + //Freeing done by the callback function of the above message +#else + M_ClearMenus(true); // so ESC backs out to title + M_StartMessage(M_GetText("Save game from different version\n\nPress ESC\n"), NULL, MM_NOTHING); + Command_ExitGame_f(); + Z_Free(savebuffer); + save_p = savebuffer = NULL; + + // no cheating! + memset(&savedata, 0, sizeof(savedata)); +#endif + return; // bad version + } + save_p += VERSIONSIZE; + +// if (demoplayback) // reset game engine +// G_StopDemo(); + +// paused = false; +// automapactive = false; + + // dearchive all the modifications + if (!P_LoadGame(mapoverride)) + { + M_ClearMenus(true); // so ESC backs out to title + M_StartMessage(M_GetText("Savegame file corrupted\n\nPress ESC\n"), NULL, MM_NOTHING); + Command_ExitGame_f(); + Z_Free(savebuffer); + save_p = savebuffer = NULL; + + // no cheating! + memset(&savedata, 0, sizeof(savedata)); + return; + } + + // done + Z_Free(savebuffer); + save_p = savebuffer = NULL; + +// gameaction = ga_nothing; +// G_SetGamestate(GS_LEVEL); + displayplayer = consoleplayer; + multiplayer = splitscreen = false; + +// G_DeferedInitNew(sk_medium, G_BuildMapName(1), 0, 0, 1); + if (setsizeneeded) + R_ExecuteSetViewSize(); + + M_ClearMenus(true); + CON_ToggleOff(); +} + +// +// G_SaveGame +// Saves your game. +// +void G_SaveGame(UINT32 savegameslot) +{ + boolean saved; + char savename[256] = ""; + const char *backup; + + sprintf(savename, savegamename, savegameslot); + backup = va("%s",savename); + + // save during evaluation or credits? game's over, folks! + if (gamestate == GS_CREDITS || gamestate == GS_EVALUATION) + gamecomplete = true; + + gameaction = ga_nothing; + { + char name[VERSIONSIZE]; + size_t length; + + save_p = savebuffer = (UINT8 *)malloc(SAVEGAMESIZE); + if (!save_p) + { + CONS_Alert(CONS_ERROR, M_GetText("No more free memory for saving game data\n")); + return; + } + + memset(name, 0, sizeof (name)); + sprintf(name, "version %d", VERSION); + WRITEMEM(save_p, name, VERSIONSIZE); + + P_SaveGame(); + + length = save_p - savebuffer; + saved = FIL_WriteFile(backup, savebuffer, length); + free(savebuffer); + save_p = savebuffer = NULL; + } + + gameaction = ga_nothing; + + if (cv_debug && saved) + CONS_Printf(M_GetText("Game saved.\n")); + else if (!saved) + CONS_Alert(CONS_ERROR, M_GetText("Error while writing to %s for save slot %u, base: %s\n"), backup, savegameslot, savegamename); +} + +// +// G_DeferedInitNew +// Can be called by the startup code or the menu task, +// consoleplayer, displayplayer, playeringame[] should be set. +// +void G_DeferedInitNew(boolean pultmode, const char *mapname, INT32 pickedchar, boolean SSSG, boolean FLS) +{ + UINT8 color = 0; + paused = false; + + if (demoplayback) + COM_BufAddText("stopdemo\n"); + ghosts = NULL; + + // this leave the actual game if needed + SV_StartSinglePlayerServer(); + + if (savedata.lives > 0) + { + color = savedata.skincolor; + botskin = savedata.botskin; + botcolor = savedata.botcolor; + botingame = (botskin != 0); + } + else if (splitscreen != SSSG) + { + splitscreen = SSSG; + SplitScreen_OnChange(); + } + + if (!color) + color = skins[pickedchar].prefcolor; + SetPlayerSkinByNum(consoleplayer, pickedchar); + CV_StealthSet(&cv_skin, skins[pickedchar].name); + CV_StealthSetValue(&cv_playercolor, color); + + if (mapname) + D_MapChange(M_MapNumber(mapname[3], mapname[4]), gametype, pultmode, true, 1, false, FLS); +} + +// +// This is the map command interpretation something like Command_Map_f +// +// called at: map cmd execution, doloadgame, doplaydemo +void G_InitNew(UINT8 pultmode, const char *mapname, boolean resetplayer, boolean skipprecutscene) +{ + INT32 i; + + if (paused) + { + paused = false; + S_ResumeSound(); + } + + if (netgame || multiplayer) // Nice try, haxor. + ultimatemode = false; + + if (!demoplayback && !netgame) // Netgame sets random seed elsewhere, demo playback sets seed just before us! + P_SetRandSeed(M_RandomizedSeed()); // Use a more "Random" random seed + + if (resetplayer) + { + // Clear a bunch of variables + tokenlist = token = sstimer = redscore = bluescore = lastmap = 0; + countdown = countdown2 = 0; + + for (i = 0; i < MAXPLAYERS; i++) + { + players[i].playerstate = PST_REBORN; + players[i].starpostangle = players[i].starpostnum = players[i].starposttime = 0; + players[i].starpostx = players[i].starposty = players[i].starpostz = 0; + + if (netgame || multiplayer) + { + players[i].lives = cv_startinglives.value; + players[i].continues = 0; + } + else if (pultmode) + { + players[i].lives = 1; + players[i].continues = 0; + } + else + { + players[i].lives = 3; + players[i].continues = 1; + } + + // The latter two should clear by themselves, but just in case + players[i].pflags &= ~(PF_TAGIT|PF_TAGGED|PF_FULLSTASIS); + + // Clear cheatcodes too, just in case. + players[i].pflags &= ~(PF_GODMODE|PF_NOCLIP|PF_INVIS); + + players[i].score = players[i].xtralife = 0; + } + + // Reset unlockable triggers + unlocktriggers = 0; + + // clear itemfinder, just in case + CV_StealthSetValue(&cv_itemfinder, 0); + } + + // internal game map + // well this check is useless because it is done before (d_netcmd.c::command_map_f) + // but in case of for demos.... + if (W_CheckNumForName(mapname) == LUMPERROR) + { + I_Error("Internal game map '%s' not found\n", mapname); + Command_ExitGame_f(); + return; + } + + gamemap = (INT16)M_MapNumber(mapname[3], mapname[4]); // get xx out of MAPxx + + // gamemap changed; we assume that its map header is always valid, + // so make it so + if(!mapheaderinfo[gamemap-1]) + P_AllocMapHeader(gamemap-1); + + maptol = mapheaderinfo[gamemap-1]->typeoflevel; + globalweather = mapheaderinfo[gamemap-1]->weather; + + // Don't carry over custom music change to another map. + mapmusic |= MUSIC_RELOADRESET; + + ultimatemode = pultmode; + playerdeadview = false; + automapactive = false; + imcontinuing = false; + + if (!skipprecutscene && mapheaderinfo[gamemap-1]->precutscenenum && !modeattacking) // Start a custom cutscene. + F_StartCustomCutscene(mapheaderinfo[gamemap-1]->precutscenenum-1, true, resetplayer); + else + G_DoLoadLevel(resetplayer); + + if (netgame) + { + char *title = G_BuildMapTitle(gamemap); + + CONS_Printf(M_GetText("Map is now \"%s"), G_BuildMapName(gamemap)); + if (title) + { + CONS_Printf(": %s", title); + Z_Free(title); + } + CONS_Printf("\"\n"); + } +} + + +char *G_BuildMapTitle(INT32 mapnum) +{ + char *title = NULL; + + if (strcmp(mapheaderinfo[mapnum-1]->lvlttl, "")) + { + size_t len = 1; + const char *zonetext = NULL; + const INT32 actnum = mapheaderinfo[mapnum-1]->actnum; + + len += strlen(mapheaderinfo[mapnum-1]->lvlttl); + if (!(mapheaderinfo[mapnum-1]->levelflags & LF_NOZONE)) + { + zonetext = M_GetText("ZONE"); + len += strlen(zonetext) + 1; // ' ' + zonetext + } + if (actnum > 0) + len += 1 + 11; // ' ' + INT32 + + title = Z_Malloc(len, PU_STATIC, NULL); + + sprintf(title, "%s", mapheaderinfo[mapnum-1]->lvlttl); + if (zonetext) sprintf(title + strlen(title), " %s", zonetext); + if (actnum > 0) sprintf(title + strlen(title), " %d", actnum); + } + + return title; +} + +// +// DEMO RECORDING +// + +#define DEMOVERSION 0x0008 +#define DEMOHEADER "\xF0" "SRB2Replay" "\x0F" + +#define DF_GHOST 0x01 // This demo contains ghost data too! +#define DF_RECORDATTACK 0x02 // This demo is from record attack and contains its final completion time, score, and rings! +#define DF_NIGHTSATTACK 0x04 // This demo is from NiGHTS attack and contains its time left, score, and mares! +#define DF_ATTACKMASK 0x06 // This demo is from ??? attack and contains ??? +#define DF_ATTACKSHIFT 1 + +// For demos +#define ZT_FWD 0x01 +#define ZT_SIDE 0x02 +#define ZT_ANGLE 0x04 +#define ZT_BUTTONS 0x08 +#define ZT_AIMING 0x10 +#define DEMOMARKER 0x80 // demoend + +static ticcmd_t oldcmd; + +// For Metal Sonic and time attack ghosts +#define GZT_XYZ 0x01 +#define GZT_MOMXY 0x02 +#define GZT_MOMZ 0x04 +#define GZT_ANGLE 0x08 +// Not used for Metal Sonic +#define GZT_SPRITE 0x10 // Animation frame +#define GZT_EXTRA 0x20 + +// GZT_EXTRA flags +#define EZT_THOK 0x01 // Spawned a thok object +#define EZT_SPIN 0x02 // Because one type of thok object apparently wasn't enough +#define EZT_COLOR 0x04 // Changed color (Super transformation, Mario fireflowers/invulnerability, etc.) +#define EZT_FLIP 0x08 // Reversed gravity +#define EZT_SCALE 0x10 // Changed size +#define EZT_HIT 0x20 // Damaged a mobj +#define EZT_SPRITE 0x40 // Changed sprite set completely out of PLAY (NiGHTS, SOCs, whatever) + +static mobj_t oldmetal, oldghost; + +ticcmd_t *G_CopyTiccmd(ticcmd_t* dest, const ticcmd_t* src, const size_t n) +{ + return M_Memcpy(dest, src, n*sizeof(*src)); +} + +ticcmd_t *G_MoveTiccmd(ticcmd_t* dest, const ticcmd_t* src, const size_t n) +{ + size_t i; + for (i = 0; i < n; i++) + { + dest[i].forwardmove = src[i].forwardmove; + dest[i].sidemove = src[i].sidemove; + dest[i].angleturn = SHORT(src[i].angleturn); + dest[i].aiming = (INT16)SHORT(src[i].aiming); + dest[i].buttons = (UINT16)SHORT(src[i].buttons); + } + return dest; +} + +void G_ReadDemoTiccmd(ticcmd_t *cmd, INT32 playernum) +{ + UINT8 ziptic; + (void)playernum; + + if (!demo_p || !demo_start) + return; + ziptic = READUINT8(demo_p); + + if (ziptic & ZT_FWD) + oldcmd.forwardmove = READSINT8(demo_p); + if (ziptic & ZT_SIDE) + oldcmd.sidemove = READSINT8(demo_p); + if (ziptic & ZT_ANGLE) + oldcmd.angleturn = READINT16(demo_p); + if (ziptic & ZT_BUTTONS) + oldcmd.buttons = (oldcmd.buttons & (BT_CAMLEFT|BT_CAMRIGHT)) | (READUINT16(demo_p) & ~(BT_CAMLEFT|BT_CAMRIGHT)); + if (ziptic & ZT_AIMING) + oldcmd.aiming = READINT16(demo_p); + + G_CopyTiccmd(cmd, &oldcmd, 1); + + if (!(demoflags & DF_GHOST) && *demo_p == DEMOMARKER) + { + // end of demo data stream + G_CheckDemoStatus(); + return; + } +} + +void G_WriteDemoTiccmd(ticcmd_t *cmd, INT32 playernum) +{ + char ziptic = 0; + UINT8 *ziptic_p; + (void)playernum; + + if (!demo_p) + return; + ziptic_p = demo_p++; // the ziptic, written at the end of this function + + if (cmd->forwardmove != oldcmd.forwardmove) + { + WRITEUINT8(demo_p,cmd->forwardmove); + oldcmd.forwardmove = cmd->forwardmove; + ziptic |= ZT_FWD; + } + + if (cmd->sidemove != oldcmd.sidemove) + { + WRITEUINT8(demo_p,cmd->sidemove); + oldcmd.sidemove = cmd->sidemove; + ziptic |= ZT_SIDE; + } + + if (cmd->angleturn != oldcmd.angleturn) + { + WRITEINT16(demo_p,cmd->angleturn); + oldcmd.angleturn = cmd->angleturn; + ziptic |= ZT_ANGLE; + } + + if (cmd->buttons != oldcmd.buttons) + { + WRITEUINT16(demo_p,cmd->buttons); + oldcmd.buttons = cmd->buttons; + ziptic |= ZT_BUTTONS; + } + + if (cmd->aiming != oldcmd.aiming) + { + WRITEINT16(demo_p,cmd->aiming); + oldcmd.aiming = cmd->aiming; + ziptic |= ZT_AIMING; + } + + *ziptic_p = ziptic; + + // attention here for the ticcmd size! + // latest demos with mouse aiming byte in ticcmd + if (!(demoflags & DF_GHOST) && ziptic_p > demoend - 9) + { + G_CheckDemoStatus(); // no more space + return; + } +} + +void G_GhostAddThok(void) +{ + if (!demorecording || !(demoflags & DF_GHOST)) + return; + ghostext.flags |= EZT_THOK; +} + +void G_GhostAddSpin(void) +{ + if (!demorecording || !(demoflags & DF_GHOST)) + return; + ghostext.flags |= EZT_SPIN; +} + +void G_GhostAddFlip(void) +{ + if (!demorecording || !(demoflags & DF_GHOST)) + return; + ghostext.flags |= EZT_FLIP; +} + +void G_GhostAddColor(ghostcolor_t color) +{ + if (!demorecording || !(demoflags & DF_GHOST)) + return; + if (ghostext.lastcolor == (UINT8)color) + { + ghostext.flags &= ~EZT_COLOR; + return; + } + ghostext.flags |= EZT_COLOR; + ghostext.color = (UINT8)color; +} + +void G_GhostAddScale(UINT16 scale) +{ + if (!demorecording || !(demoflags & DF_GHOST)) + return; + if (ghostext.lastscale == scale) + { + ghostext.flags &= ~EZT_SCALE; + return; + } + ghostext.flags |= EZT_SCALE; + ghostext.scale = scale; +} + +void G_GhostAddHit(mobj_t *victim) +{ + if (!demorecording || !(demoflags & DF_GHOST)) + return; + ghostext.flags |= EZT_HIT; + ghostext.hits++; + ghostext.hitlist = Z_Realloc(ghostext.hitlist, ghostext.hits * sizeof(mobj_t *), PU_LEVEL, NULL); + ghostext.hitlist[ghostext.hits-1] = victim; +} + +void G_WriteGhostTic(mobj_t *ghost) +{ + char ziptic = 0; + UINT8 *ziptic_p; + UINT32 i; + UINT8 sprite; + UINT8 frame; + + if (!demo_p) + return; + if (!(demoflags & DF_GHOST)) + return; // No ghost data to write. + + ziptic_p = demo_p++; // the ziptic, written at the end of this function + + #define MAXMOM (0xFFFF<<8) + + // GZT_XYZ is only useful if you've moved 256 FRACUNITS or more in a single tic. + if (abs(ghost->x-oldghost.x) > MAXMOM + || abs(ghost->y-oldghost.y) > MAXMOM + || abs(ghost->z-oldghost.z) > MAXMOM) + { + oldghost.x = ghost->x; + oldghost.y = ghost->y; + oldghost.z = ghost->z; + ziptic |= GZT_XYZ; + WRITEFIXED(demo_p,oldghost.x); + WRITEFIXED(demo_p,oldghost.y); + WRITEFIXED(demo_p,oldghost.z); + } + else + { + // For moving normally: + // Store one full byte of movement, plus one byte of fractional movement. + INT16 momx = (INT16)((ghost->x-oldghost.x)>>8); + INT16 momy = (INT16)((ghost->y-oldghost.y)>>8); + if (momx != oldghost.momx + || momy != oldghost.momy) + { + oldghost.momx = momx; + oldghost.momy = momy; + ziptic |= GZT_MOMXY; + WRITEINT16(demo_p,momx); + WRITEINT16(demo_p,momy); + } + momx = (INT16)((ghost->z-oldghost.z)>>8); + if (momx != oldghost.momz) + { + oldghost.momz = momx; + ziptic |= GZT_MOMZ; + WRITEINT16(demo_p,momx); + } + + // This SHOULD set oldghost.x/y/z to match ghost->x/y/z + // but it keeps the fractional loss of one byte, + // so it will hopefully be made up for in future tics. + oldghost.x += oldghost.momx<<8; + oldghost.y += oldghost.momy<<8; + oldghost.z += oldghost.momz<<8; + } + + #undef MAXMOM + + // Only store the 8 most relevant bits of angle + // because exact values aren't too easy to discern to begin with when only 8 angles have different sprites + // and it does not affect this mode of movement at all anyway. + if (ghost->angle>>24 != oldghost.angle) + { + oldghost.angle = ghost->angle>>24; + ziptic |= GZT_ANGLE; + WRITEUINT8(demo_p,oldghost.angle); + } + + // Store the sprite frame. + if (ghost->player && ghost->player->pflags & PF_NIGHTSMODE && ghost->tracer) + frame = ghost->tracer->frame & 0xFF; // get frame from NiGHTS tracer + else + frame = ghost->frame & 0xFF; // get frame from player + if (frame != oldghost.frame) + { + oldghost.frame = frame; + ziptic |= GZT_SPRITE; + WRITEUINT8(demo_p,oldghost.frame); + } + + // Check for sprite set changes + if (ghost->player && ghost->player->pflags & PF_NIGHTSMODE && ghost->tracer) + sprite = ghost->tracer->sprite; // get sprite from NiGHTS tracer + else + sprite = ghost->sprite; // get sprite from player + if (sprite != oldghost.sprite) + { + oldghost.sprite = sprite; + ghostext.flags |= EZT_SPRITE; + } + + if (ghostext.flags) + { + ziptic |= GZT_EXTRA; + + if (ghostext.color == ghostext.lastcolor) + ghostext.flags &= ~EZT_COLOR; + if (ghostext.scale == ghostext.lastscale) + ghostext.flags &= ~EZT_SCALE; + + WRITEUINT8(demo_p,ghostext.flags); + if (ghostext.flags & EZT_COLOR) + { + WRITEUINT8(demo_p,ghostext.color); + ghostext.lastcolor = ghostext.color; + } + if (ghostext.flags & EZT_SCALE) + { + WRITEFIXED(demo_p,ghostext.scale); + ghostext.lastscale = ghostext.scale; + } + if (ghostext.flags & EZT_HIT) + { + WRITEUINT16(demo_p,ghostext.hits); + for (i = 0; i < ghostext.hits; i++) + { + mobj_t *mo = ghostext.hitlist[i]; + WRITEUINT32(demo_p,UINT32_MAX); // reserved for some method of determining exactly which mobj this is. (mobjnum doesn't work here.) + WRITEUINT32(demo_p,mo->type); + WRITEUINT16(demo_p,(UINT16)mo->health); + WRITEFIXED(demo_p,mo->x); + WRITEFIXED(demo_p,mo->y); + WRITEFIXED(demo_p,mo->z); + WRITEANGLE(demo_p,mo->angle); + } + Z_Free(ghostext.hitlist); + ghostext.hits = 0; + ghostext.hitlist = NULL; + } + if (ghostext.flags & EZT_SPRITE) + WRITEUINT8(demo_p,sprite); + ghostext.flags = 0; + } + + *ziptic_p = ziptic; + + // attention here for the ticcmd size! + // latest demos with mouse aiming byte in ticcmd + if (demo_p >= demoend - (13 + 9)) + { + G_CheckDemoStatus(); // no more space + return; + } +} + +// console warning messages +UINT8 demosynced = true; + +// Uses ghost data to do consistency checks on your position. +// This fixes desynchronising demos when fighting eggman. +void G_ConsGhostTic(void) +{ + UINT8 ziptic; + UINT16 px,py,pz,gx,gy,gz; + + if (!demo_p || !demo_start) + return; + if (!(demoflags & DF_GHOST)) + return; // No ghost data to use. + + // Grab ghost data. + ziptic = READUINT8(demo_p); + if (ziptic & GZT_XYZ) + { + oldghost.x = READFIXED(demo_p); + oldghost.y = READFIXED(demo_p); + oldghost.z = READFIXED(demo_p); + } + else + { + if (ziptic & GZT_MOMXY) + { + oldghost.momx = READINT16(demo_p)<<8; + oldghost.momy = READINT16(demo_p)<<8; + } + if (ziptic & GZT_MOMZ) + oldghost.momz = READINT16(demo_p)<<8; + oldghost.x += oldghost.momx; + oldghost.y += oldghost.momy; + oldghost.z += oldghost.momz; + } + if (ziptic & GZT_ANGLE) + demo_p++; + if (ziptic & GZT_SPRITE) + demo_p++; + + if (ziptic & GZT_EXTRA) + { // But wait, there's more! + ziptic = READUINT8(demo_p); + if (ziptic & EZT_COLOR) + demo_p++; + if (ziptic & EZT_SCALE) + demo_p += sizeof(fixed_t); + if (ziptic & EZT_HIT) + { // Resync mob damage. + UINT16 i, count = READUINT16(demo_p); + thinker_t *th; + mobj_t *mobj; + + UINT32 type; + UINT16 health; + fixed_t x; + fixed_t y; + fixed_t z; + + for (i = 0; i < count; i++) + { + demo_p += 4; // reserved. + type = READUINT32(demo_p); + health = READUINT16(demo_p); + x = READFIXED(demo_p); + y = READFIXED(demo_p); + z = READFIXED(demo_p); + demo_p += sizeof(angle_t); // angle, unnecessary for cons. + + mobj = NULL; + for (th = thinkercap.next; th != &thinkercap; th = th->next) + { + if (th->function.acp1 != (actionf_p1)P_MobjThinker) + continue; + mobj = (mobj_t *)th; + if (mobj->type == (mobjtype_t)type && mobj->x == x && mobj->y == y && mobj->z == z) + break; + mobj = NULL; // wasn't this one, keep searching. + } + if (mobj && mobj->health != health) // Wasn't damaged?! This is desync! Fix it! + P_DamageMobj(mobj, players[0].mo, players[0].mo, 1); + } + } + if (ziptic & EZT_SPRITE) + demo_p++; + } + + // Re-synchronise + px = (players[0].mo->x>>8)&UINT16_MAX; + py = (players[0].mo->y>>8)&UINT16_MAX; + pz = (players[0].mo->z>>8)&UINT16_MAX; + gx = (oldghost.x>>8)&UINT16_MAX; + gy = (oldghost.y>>8)&UINT16_MAX; + gz = (oldghost.z>>8)&UINT16_MAX; + + if (px != gx || py != gy || pz != gz) + { + if (demosynced) + CONS_Alert(CONS_WARNING, M_GetText("Demo playback has desynced!\n")); + demosynced = false; + + P_UnsetThingPosition(players[0].mo); + players[0].mo->x = oldghost.x; + players[0].mo->y = oldghost.y; + P_SetThingPosition(players[0].mo); + players[0].mo->z = oldghost.z; + } + else + demosynced = true; + + if (*demo_p == DEMOMARKER) + { + // end of demo data stream + G_CheckDemoStatus(); + return; + } +} + +void G_GhostTicker(void) +{ + demoghost *g,*p; + for(g = ghosts, p = NULL; g; g = g->next) + { + // Skip normal demo data. + UINT8 ziptic = READUINT8(g->p); + if (ziptic & ZT_FWD) + g->p++; + if (ziptic & ZT_SIDE) + g->p++; + if (ziptic & ZT_ANGLE) + g->p += 2; + if (ziptic & ZT_BUTTONS) + g->p += 2; + if (ziptic & ZT_AIMING) + g->p += 2; + + // Grab ghost data. + ziptic = READUINT8(g->p); + if (ziptic & GZT_XYZ) + { + g->oldmo.x = READFIXED(g->p); + g->oldmo.y = READFIXED(g->p); + g->oldmo.z = READFIXED(g->p); + } + else + { + if (ziptic & GZT_MOMXY) + { + g->oldmo.momx = READINT16(g->p)<<8; + g->oldmo.momy = READINT16(g->p)<<8; + } + if (ziptic & GZT_MOMZ) + g->oldmo.momz = READINT16(g->p)<<8; + g->oldmo.x += g->oldmo.momx; + g->oldmo.y += g->oldmo.momy; + g->oldmo.z += g->oldmo.momz; + } + if (ziptic & GZT_ANGLE) + g->oldmo.angle = READUINT8(g->p)<<24; + if (ziptic & GZT_SPRITE) + g->oldmo.frame = READUINT8(g->p); + + // Update ghost + P_UnsetThingPosition(g->mo); + g->mo->x = g->oldmo.x; + g->mo->y = g->oldmo.y; + g->mo->z = g->oldmo.z; + P_SetThingPosition(g->mo); + g->mo->angle = g->oldmo.angle; + g->mo->frame = g->oldmo.frame | tr_trans30<p); + if (ziptic & EZT_COLOR) + { + switch(READUINT8(g->p)) + { + default: + case GHC_NORMAL: // Go back to skin color + g->mo->color = g->oldmo.color; + break; + case GHC_SUPER: // Super Sonic + g->mo->color = SKINCOLOR_SUPER4; + break; + case GHC_INVINCIBLE: /// \todo Mario invincibility + g->mo->color = SKINCOLOR_SUPER4; + break; + case GHC_FIREFLOWER: // Fireflower + g->mo->color = SKINCOLOR_WHITE; + break; + } + } + if (ziptic & EZT_FLIP) + g->mo->eflags ^= MFE_VERTICALFLIP; + if (ziptic & EZT_SCALE) + { + g->mo->destscale = READFIXED(g->p); + if (g->mo->destscale != g->mo->scale) + P_SetScale(g->mo, g->mo->destscale); + } + if (ziptic & (EZT_THOK|EZT_SPIN)) + { // Let's only spawn ONE of these per frame, thanks. + mobj_t *mobj; + INT32 type = -1; + if (g->mo->skin) + { + skin_t *skin = (skin_t *)g->mo->skin; + if (ziptic & EZT_THOK) + type = skin->thokitem < 0 ? (UINT32)mobjinfo[MT_PLAYER].painchance : (UINT32)skin->thokitem; + else + type = skin->spinitem < 0 ? (UINT32)mobjinfo[MT_PLAYER].damage : (UINT32)skin->spinitem; + } + if (type == MT_GHOST) + { + mobj = P_SpawnGhostMobj(g->mo); // does a large portion of the work for us + mobj->frame = (mobj->frame & ~FF_FRAMEMASK)|tr_trans60<mo->x, g->mo->y, g->mo->z - FixedDiv(FixedMul(g->mo->info->height, g->mo->scale) - g->mo->height,3*FRACUNIT), MT_THOK); + mobj->sprite = states[mobjinfo[type].spawnstate].sprite; + mobj->frame = (states[mobjinfo[type].spawnstate].frame & FF_FRAMEMASK) | tr_trans60<tics = -1; // nope. + mobj->color = g->mo->color; + if (g->mo->eflags & MFE_VERTICALFLIP) + { + mobj->flags2 |= MF2_OBJECTFLIP; + mobj->eflags |= MFE_VERTICALFLIP; + } + P_SetScale(mobj, g->mo->scale); + mobj->destscale = g->mo->scale; + } + mobj->floorz = mobj->z; + mobj->ceilingz = mobj->z+mobj->height; + P_UnsetThingPosition(mobj); + mobj->flags = MF_NOBLOCKMAP|MF_NOCLIP|MF_NOCLIPHEIGHT|MF_NOGRAVITY; // make an ATTEMPT to curb crazy SOCs fucking stuff up... + P_SetThingPosition(mobj); + mobj->fuse = 8; + P_SetTarget(&mobj->target, g->mo); + } + if (ziptic & EZT_HIT) + { // Spawn hit poofs for killing things! + UINT16 i, count = READUINT16(g->p), health; + UINT32 type; + fixed_t x,y,z; + angle_t angle; + mobj_t *poof; + for (i = 0; i < count; i++) + { + g->p += 4; // reserved + type = READUINT32(g->p); + health = READUINT16(g->p); + x = READFIXED(g->p); + y = READFIXED(g->p); + z = READFIXED(g->p); + angle = READANGLE(g->p); + if (!(mobjinfo[type].flags & MF_SHOOTABLE) + || !(mobjinfo[type].flags & (MF_ENEMY|MF_MONITOR)) + || health != 0 || i >= 4) // only spawn for the first 4 hits per frame, to prevent ghosts from splode-spamming too bad. + continue; + poof = P_SpawnMobj(x, y, z, MT_GHOST); + poof->angle = angle; + poof->flags = MF_NOBLOCKMAP|MF_NOCLIP|MF_NOCLIPHEIGHT|MF_NOGRAVITY; // make an ATTEMPT to curb crazy SOCs fucking stuff up... + poof->health = 0; + P_SetMobjStateNF(poof, S_XPLD1); + } + } + if (ziptic & EZT_SPRITE) + g->mo->sprite = READUINT8(g->p); + } + + // Demo ends after ghost data. + if (*g->p == DEMOMARKER) + { + g->mo->momx = g->mo->momy = g->mo->momz = 0; + if (p) + p->next = g->next; + else + ghosts = g->next; + continue; + } + p = g; + } +} + +void G_ReadMetalTic(mobj_t *metal) +{ + UINT8 ziptic; + UINT16 speed; + UINT8 statetype; + + if (!metal_p || !demo_start) + return; + ziptic = READUINT8(metal_p); + + // Read changes from the tic + if (ziptic & GZT_XYZ) + { + P_TeleportMove(metal, READFIXED(metal_p), READFIXED(metal_p), READFIXED(metal_p)); + oldmetal.x = metal->x; + oldmetal.y = metal->y; + oldmetal.z = metal->z; + } + else + { + if (ziptic & GZT_MOMXY) + { + oldmetal.momx = READINT16(metal_p)<<8; + oldmetal.momy = READINT16(metal_p)<<8; + } + if (ziptic & GZT_MOMZ) + oldmetal.momz = READINT16(metal_p)<<8; + oldmetal.x += oldmetal.momx; + oldmetal.y += oldmetal.momy; + oldmetal.z += oldmetal.momz; + } + if (ziptic & GZT_ANGLE) + oldmetal.angle = READUINT8(metal_p)<<24; + if (ziptic & GZT_SPRITE) + metal_p++; // Currently unused. (Metal Sonic figures out what he's doing his own damn self.) + + // Set movement, position, and angle + // oldmetal contains where you're supposed to be. + metal->momx = oldmetal.momx; + metal->momy = oldmetal.momy; + metal->momz = oldmetal.momz; + P_UnsetThingPosition(metal); + metal->x = oldmetal.x; + metal->y = oldmetal.y; + metal->z = oldmetal.z; + P_SetThingPosition(metal); + metal->angle = oldmetal.angle; + + if (ziptic & GZT_EXTRA) + { // But wait, there's more! + ziptic = READUINT8(metal_p); + if (ziptic & EZT_FLIP) + metal->eflags ^= MFE_VERTICALFLIP; + if (ziptic & EZT_SCALE) + { + metal->destscale = READFIXED(metal_p); + if (metal->destscale != metal->scale) + P_SetScale(metal, metal->destscale); + } + } + + // Calculates player's speed based on distance-of-a-line formula + speed = FixedDiv(P_AproxDistance(oldmetal.momx, oldmetal.momy), metal->scale)>>FRACBITS; + + // Use speed to decide an appropriate state + if (speed > 28) // default skin runspeed + statetype = 2; + else if (speed > 1) // stopspeed + statetype = 1; + else + statetype = 0; + + // Set state + if (statetype != metal->threshold) + { + switch (statetype) + { + case 2: // run + P_SetMobjState(metal,metal->info->meleestate); + break; + case 1: // walk + P_SetMobjState(metal,metal->info->seestate); + break; + default: // stand + P_SetMobjState(metal,metal->info->spawnstate); + break; + } + metal->threshold = statetype; + } + + // TODO: Modify state durations based on movement speed, similar to players? + + if (*metal_p == DEMOMARKER) + { + // end of demo data stream + G_CheckDemoStatus(); + return; + } +} + +void G_WriteMetalTic(mobj_t *metal) +{ + UINT8 ziptic = 0; + UINT8 *ziptic_p; + + if (!demo_p) // demo_p will be NULL until the race start linedef executor is triggered! + return; + + ziptic_p = demo_p++; // the ziptic, written at the end of this function + + #define MAXMOM (0xFFFF<<8) + + // GZT_XYZ is only useful if you've moved 256 FRACUNITS or more in a single tic. + if (abs(metal->x-oldmetal.x) > MAXMOM + || abs(metal->y-oldmetal.y) > MAXMOM + || abs(metal->z-oldmetal.z) > MAXMOM) + { + oldmetal.x = metal->x; + oldmetal.y = metal->y; + oldmetal.z = metal->z; + WRITEFIXED(demo_p,oldmetal.x); + WRITEFIXED(demo_p,oldmetal.y); + WRITEFIXED(demo_p,oldmetal.z); + ziptic |= GZT_XYZ; + } + else + { + // For moving normally: + // Store one full byte of movement, plus one byte of fractional movement. + INT16 momx = (INT16)((metal->x-oldmetal.x)>>8); + INT16 momy = (INT16)((metal->y-oldmetal.y)>>8); + if (momx != oldmetal.momx + || momy != oldmetal.momy) + { + oldmetal.momx = momx; + oldmetal.momy = momy; + WRITEINT16(demo_p,momx); + WRITEINT16(demo_p,momy); + ziptic |= GZT_MOMXY; + } + momx = (INT16)((metal->z-oldmetal.z)>>8); + if (momx != oldmetal.momz) + { + oldmetal.momz = momx; + WRITEINT16(demo_p,momx); + ziptic |= GZT_MOMZ; + } + + // This SHOULD set oldmetal.x/y/z to match metal->x/y/z + // but it keeps the fractional loss of one byte, + // so it will hopefully be made up for in future tics. + oldmetal.x += oldmetal.momx<<8; + oldmetal.y += oldmetal.momy<<8; + oldmetal.z += oldmetal.momz<<8; + } + + #undef MAXMOM + + // Only store the 8 most relevant bits of angle + // because exact values aren't too easy to discern to begin with when only 8 angles have different sprites + // and it does not affect movement at all anyway. + if (metal->angle>>24 != oldmetal.angle) + { + oldmetal.angle = metal->angle>>24; + WRITEUINT8(demo_p,oldmetal.angle); + ziptic |= GZT_ANGLE; + } + + // Metal Sonic does not need our state changes. + // ... currently. + + { + UINT8 *exttic_p = NULL; + UINT8 exttic = 0; + if ((metal->eflags & MFE_VERTICALFLIP) != (oldmetal.eflags & MFE_VERTICALFLIP)) + { + if (!exttic_p) + exttic_p = demo_p++; + exttic |= EZT_FLIP; + oldmetal.eflags ^= MFE_VERTICALFLIP; + } + if (metal->scale != oldmetal.scale) + { + if (!exttic_p) + exttic_p = demo_p++; + exttic |= EZT_SCALE; + WRITEFIXED(demo_p,metal->scale); + oldmetal.scale = metal->scale; + } + if (exttic_p) + { + *exttic_p = exttic; + ziptic |= GZT_EXTRA; + } + } + + *ziptic_p = ziptic; + + // attention here for the ticcmd size! + // latest demos with mouse aiming byte in ticcmd + if (demo_p >= demoend - 32) + { + G_CheckDemoStatus(); // no more space + return; + } +} + +// +// G_RecordDemo +// +void G_RecordDemo(const char *name) +{ + INT32 maxsize; + + strcpy(demoname, name); + strcat(demoname, ".lmp"); + maxsize = 1024*1024; + if (M_CheckParm("-maxdemo") && M_IsNextParm()) + maxsize = atoi(M_GetNextParm()) * 1024; +// if (demobuffer) +// free(demobuffer); + demo_p = NULL; + demobuffer = malloc(maxsize); + demoend = demobuffer + maxsize; + + demorecording = true; +} + +void G_RecordMetal(void) +{ + INT32 maxsize; + maxsize = 1024*1024; + if (M_CheckParm("-maxdemo") && M_IsNextParm()) + maxsize = atoi(M_GetNextParm()) * 1024; + demo_p = NULL; + demobuffer = malloc(maxsize); + demoend = demobuffer + maxsize; + metalrecording = true; +} + +void G_BeginRecording(void) +{ + UINT8 i; + char name[16]; + player_t *player = &players[consoleplayer]; + + if (demo_p) + return; + memset(name,0,sizeof(name)); + + demo_p = demobuffer; + demoflags = DF_GHOST; + if (modeattacking == ATTACKING_RECORD) + demoflags |= DF_RECORDATTACK; + else if (modeattacking == ATTACKING_NIGHTS) + demoflags |= DF_NIGHTSATTACK; + + // Setup header. + M_Memcpy(demo_p, DEMOHEADER, 12); demo_p += 12; + WRITEUINT8(demo_p,VERSION); + WRITEUINT8(demo_p,SUBVERSION); + WRITEUINT16(demo_p,DEMOVERSION); + + // demo checksum + demo_p += 16; + + // game data + M_Memcpy(demo_p, "PLAY", 4); demo_p += 4; + WRITEUINT8(demo_p,gamemap); + M_Memcpy(demo_p, mapmd5, 16); demo_p += 16; + + WRITEUINT8(demo_p,demoflags); + switch ((demoflags & DF_ATTACKMASK)>>DF_ATTACKSHIFT) + { + case ATTACKING_NONE: // 0 + break; + case ATTACKING_RECORD: // 1 + demotime_p = demo_p; + WRITEUINT32(demo_p,UINT32_MAX); // time + WRITEUINT32(demo_p,0); // score + WRITEUINT16(demo_p,0); // rings + break; + case ATTACKING_NIGHTS: // 2 + demotime_p = demo_p; + WRITEUINT32(demo_p,UINT32_MAX); // time + WRITEUINT32(demo_p,0); // score + break; + default: // 3 + break; + } + + WRITEUINT32(demo_p,P_GetInitSeed()); + + // Name + for (i = 0; i < 16 && cv_playername.string[i]; i++) + name[i] = cv_playername.string[i]; + for (; i < 16; i++) + name[i] = '\0'; + M_Memcpy(demo_p,name,16); + demo_p += 16; + + // Skin + for (i = 0; i < 16 && cv_skin.string[i]; i++) + name[i] = cv_skin.string[i]; + for (; i < 16; i++) + name[i] = '\0'; + M_Memcpy(demo_p,name,16); + demo_p += 16; + + // Color + for (i = 0; i < 16 && cv_playercolor.string[i]; i++) + name[i] = cv_playercolor.string[i]; + for (; i < 16; i++) + name[i] = '\0'; + M_Memcpy(demo_p,name,16); + demo_p += 16; + + // Stats + WRITEUINT8(demo_p,player->charability); + WRITEUINT8(demo_p,player->charability2); + WRITEUINT8(demo_p,player->actionspd>>FRACBITS); + WRITEUINT8(demo_p,player->mindash>>FRACBITS); + WRITEUINT8(demo_p,player->maxdash>>FRACBITS); + WRITEUINT8(demo_p,player->normalspeed>>FRACBITS); + WRITEUINT8(demo_p,player->runspeed>>FRACBITS); + WRITEUINT8(demo_p,player->thrustfactor); + WRITEUINT8(demo_p,player->accelstart); + WRITEUINT8(demo_p,player->acceleration); + + // Trying to convert it back to % causes demo desync due to precision loss. + // Don't do it. + WRITEFIXED(demo_p, player->jumpfactor); + + // Save netvar data (SONICCD, etc) + CV_SaveNetVars(&demo_p); + + memset(&oldcmd,0,sizeof(oldcmd)); + memset(&oldghost,0,sizeof(oldghost)); + memset(&ghostext,0,sizeof(ghostext)); + ghostext.lastcolor = ghostext.color = GHC_NORMAL; + ghostext.lastscale = ghostext.scale = FRACUNIT; + + if (player->mo) + { + oldghost.x = player->mo->x; + oldghost.y = player->mo->y; + oldghost.z = player->mo->z; + oldghost.angle = player->mo->angle; + } +} + +void G_BeginMetal(void) +{ + mobj_t *mo = players[consoleplayer].mo; + + if (demo_p) + return; + + demo_p = demobuffer; + + // Write header. + M_Memcpy(demo_p, DEMOHEADER, 12); demo_p += 12; + WRITEUINT8(demo_p,VERSION); + WRITEUINT8(demo_p,SUBVERSION); + WRITEUINT16(demo_p,DEMOVERSION); + + // demo checksum + demo_p += 16; + + M_Memcpy(demo_p, "METL", 4); demo_p += 4; + + // Set up our memory. + memset(&oldmetal,0,sizeof(oldmetal)); + oldmetal.x = mo->x; + oldmetal.y = mo->y; + oldmetal.z = mo->z; + oldmetal.angle = mo->angle; +} + +void G_SetDemoTime(UINT32 ptime, UINT32 pscore, UINT16 prings) +{ + if (!(demorecording && demoflags & DF_RECORDATTACK && demotime_p)) + return; // Can't record a time. :( + WRITEUINT32(demotime_p, ptime); + WRITEUINT32(demotime_p, pscore); + WRITEUINT16(demotime_p, prings); + demotime_p = NULL; +} + +// Returns bitfield: +// 1 == new demo has lower time +// 2 == new demo has higher score +// 4 == new demo has higher rings +UINT8 G_CmpDemoTime(char *oldname, char *newname) +{ + UINT8 *buffer,*p; + UINT8 flags; + UINT32 oldtime, newtime, oldscore, newscore; + UINT16 oldrings, newrings; + size_t bufsize ATTRUNUSED; + UINT8 c; + UINT16 s ATTRUNUSED; + + // load the new file + FIL_DefaultExtension(newname, ".lmp"); + bufsize = FIL_ReadFile(newname, &buffer); + I_Assert(bufsize != 0); + p = buffer; + + // read demo header + I_Assert(!memcmp(p, DEMOHEADER, 12)); + p += 12; // DEMOHEADER + c = READUINT8(p); // VERSION + I_Assert(c == VERSION); + c = READUINT8(p); // SUBVERSION + I_Assert(c == SUBVERSION); + s = READUINT16(p); + I_Assert(s == DEMOVERSION); + p += 16; // demo checksum + I_Assert(!memcmp(p, "PLAY", 4)); + p += 4; // PLAY + p++; // gamemap + p += 16; // map md5 + flags = READUINT8(p); // demoflags + I_Assert(flags & DF_RECORDATTACK); + newtime = READUINT32(p); + newscore = READUINT32(p); + newrings = READUINT16(p); + + Z_Free(buffer); + + // load old file + FIL_DefaultExtension(oldname, ".lmp"); + if (!FIL_ReadFile(oldname, &buffer)) + { + CONS_Alert(CONS_ERROR, M_GetText("Failed to read file '%s'.\n"), oldname); + return UINT8_MAX; + } + p = buffer; + + // read demo header + if (memcmp(p, DEMOHEADER, 12)) + { + CONS_Alert(CONS_NOTICE, M_GetText("File '%s' invalid format. It will be overwritten.\n"), oldname); + Z_Free(buffer); + return UINT8_MAX; + } p += 12; // DEMOHEADER + p++; // VERSION + p++; // SUBVERSION + if (READUINT16(p) != DEMOVERSION) + { + CONS_Alert(CONS_NOTICE, M_GetText("File '%s' invalid format. It will be overwritten.\n"), oldname); + Z_Free(buffer); + return UINT8_MAX; + } + p += 16; // demo checksum + if (memcmp(p, "PLAY", 4)) + { + CONS_Alert(CONS_NOTICE, M_GetText("File '%s' invalid format. It will be overwritten.\n"), oldname); + Z_Free(buffer); + return UINT8_MAX; + } p += 4; // "PLAY" + p++; // gamemap + p += 16; // mapmd5 + flags = READUINT8(p); + if (!(flags & DF_RECORDATTACK)) + { + CONS_Alert(CONS_NOTICE, M_GetText("File '%s' not from timeattack. It will be overwritten.\n"), oldname); + Z_Free(buffer); + return UINT8_MAX; + } + oldtime = READUINT32(p); + oldscore = READUINT32(p); + oldrings = READUINT16(p); + + Z_Free(buffer); + + c = 0; + if (newtime < oldtime + || (newtime == oldtime && (newscore > oldscore || newrings > oldrings))) + c |= 1; // Better time + if (newscore > oldscore + || (newscore == oldscore && newtime < oldtime)) + c |= 1<<1; // Better score + if (newrings > oldrings + || (newrings == oldrings && newtime < oldtime)) + c |= 1<<2; // Better rings + return c; +} + +// +// G_PlayDemo +// +void G_DeferedPlayDemo(const char *name) +{ + COM_BufAddText("playdemo \""); + COM_BufAddText(name); + COM_BufAddText("\"\n"); +} + +// +// Start a demo from a .LMP file or from a wad resource +// +void G_DoPlayDemo(char *defdemoname) +{ + UINT8 i; + lumpnum_t l; + char skin[17],color[17],*n,*pdemoname; + UINT8 version,subversion,charability,charability2,thrustfactor,accelstart,acceleration; + UINT32 randseed; + fixed_t actionspd,mindash,maxdash,normalspeed,runspeed,jumpfactor; + char msg[1024]; + + skin[16] = '\0'; + color[16] = '\0'; + + n = defdemoname+strlen(defdemoname); + while (*n != '/' && *n != '\\' && n != defdemoname) + n--; + if (n != defdemoname) + n++; + pdemoname = ZZ_Alloc(strlen(n)+1); + strcpy(pdemoname,n); + + // Internal if no extension, external if one exists + if (FIL_CheckExtension(defdemoname)) + { + //FIL_DefaultExtension(defdemoname, ".lmp"); + if (!FIL_ReadFile(defdemoname, &demobuffer)) + { + snprintf(msg, 1024, M_GetText("Failed to read file '%s'.\n"), defdemoname); + CONS_Alert(CONS_ERROR, "%s", msg); + gameaction = ga_nothing; + M_StartMessage(msg, NULL, MM_NOTHING); + return; + } + demo_p = demobuffer; + } + // load demo resource from WAD + else if ((l = W_CheckNumForName(defdemoname)) == LUMPERROR) + { + snprintf(msg, 1024, M_GetText("Failed to read lump '%s'.\n"), defdemoname); + CONS_Alert(CONS_ERROR, "%s", msg); + gameaction = ga_nothing; + M_StartMessage(msg, NULL, MM_NOTHING); + return; + } + else // it's an internal demo + demobuffer = demo_p = W_CacheLumpNum(l, PU_STATIC); + + // read demo header + gameaction = ga_nothing; + demoplayback = true; + if (memcmp(demo_p, DEMOHEADER, 12)) + { + snprintf(msg, 1024, M_GetText("%s is not a SRB2 replay file.\n"), pdemoname); + CONS_Alert(CONS_ERROR, "%s", msg); + M_StartMessage(msg, NULL, MM_NOTHING); + Z_Free(pdemoname); + Z_Free(demobuffer); + demoplayback = false; + titledemo = false; + return; + } + demo_p += 12; // DEMOHEADER + + version = READUINT8(demo_p); + subversion = READUINT8(demo_p); + if (DEMOVERSION != READUINT16(demo_p)) + { + snprintf(msg, 1024, M_GetText("%s is a different replay format and cannot be played.\n"), pdemoname); + CONS_Alert(CONS_ERROR, "%s", msg); + M_StartMessage(msg, NULL, MM_NOTHING); + Z_Free(pdemoname); + Z_Free(demobuffer); + demoplayback = false; + titledemo = false; + return; + } + demo_p += 16; // demo checksum + if (memcmp(demo_p, "PLAY", 4)) + { + snprintf(msg, 1024, M_GetText("%s is the wrong type of recording and cannot be played.\n"), pdemoname); + CONS_Alert(CONS_ERROR, "%s", msg); + M_StartMessage(msg, NULL, MM_NOTHING); + Z_Free(pdemoname); + Z_Free(demobuffer); + demoplayback = false; + titledemo = false; + return; + } + demo_p += 4; // "PLAY" + gamemap = READUINT8(demo_p); + demo_p += 16; // mapmd5 + + demoflags = READUINT8(demo_p); + modeattacking = (demoflags & DF_ATTACKMASK)>>DF_ATTACKSHIFT; + CON_ToggleOff(); + + hu_demoscore = 0; + hu_demotime = UINT32_MAX; + hu_demorings = 0; + + switch (modeattacking) + { + case ATTACKING_NONE: // 0 + break; + case ATTACKING_RECORD: // 1 + hu_demotime = READUINT32(demo_p); + hu_demoscore = READUINT32(demo_p); + hu_demorings = READUINT16(demo_p); + break; + case ATTACKING_NIGHTS: // 2 + hu_demotime = READUINT32(demo_p); + hu_demoscore = READUINT32(demo_p); + break; + default: // 3 + modeattacking = ATTACKING_NONE; + break; + } + + // Random seed + randseed = READUINT32(demo_p); + + // Player name + M_Memcpy(player_names[0],demo_p,16); + demo_p += 16; + + // Skin + M_Memcpy(skin,demo_p,16); + demo_p += 16; + + // Color + M_Memcpy(color,demo_p,16); + demo_p += 16; + + charability = READUINT8(demo_p); + charability2 = READUINT8(demo_p); + actionspd = (fixed_t)READUINT8(demo_p)<color = players[0].skincolor; + oldghost.x = players[0].mo->x; + oldghost.y = players[0].mo->y; + oldghost.z = players[0].mo->z; + } + + // Set saved attribute values + // No cheat checking here, because even if they ARE wrong... + // it would only break the replay if we clipped them. + players[0].charability = charability; + players[0].charability2 = charability2; + players[0].actionspd = actionspd; + players[0].mindash = mindash; + players[0].maxdash = maxdash; + players[0].normalspeed = normalspeed; + players[0].runspeed = runspeed; + players[0].thrustfactor = thrustfactor; + players[0].accelstart = accelstart; + players[0].acceleration = acceleration; + players[0].jumpfactor = jumpfactor; + + demo_start = true; +} + +void G_AddGhost(char *defdemoname) +{ + INT32 i; + lumpnum_t l; + char name[17],skin[17],color[17],*n,*pdemoname,md5[16]; + demoghost *gh; + UINT8 flags; + UINT8 *buffer,*p; + mapthing_t *mthing; + UINT16 count; + + name[16] = '\0'; + skin[16] = '\0'; + color[16] = '\0'; + + n = defdemoname+strlen(defdemoname); + while (*n != '/' && *n != '\\' && n != defdemoname) + n--; + if (n != defdemoname) + n++; + pdemoname = ZZ_Alloc(strlen(n)+1); + strcpy(pdemoname,n); + + // Internal if no extension, external if one exists + if (FIL_CheckExtension(defdemoname)) + { + //FIL_DefaultExtension(defdemoname, ".lmp"); + if (!FIL_ReadFileTag(defdemoname, &buffer, PU_LEVEL)) + { + CONS_Alert(CONS_ERROR, M_GetText("Failed to read file '%s'.\n"), defdemoname); + Z_Free(pdemoname); + return; + } + p = buffer; + } + // load demo resource from WAD + else if ((l = W_CheckNumForName(defdemoname)) == LUMPERROR) + { + CONS_Alert(CONS_ERROR, M_GetText("Failed to read lump '%s'.\n"), defdemoname); + Z_Free(pdemoname); + return; + } + else // it's an internal demo + buffer = p = W_CacheLumpNum(l, PU_LEVEL); + + // read demo header + if (memcmp(p, DEMOHEADER, 12)) + { + CONS_Alert(CONS_NOTICE, M_GetText("Ghost %s: Not a SRB2 replay.\n"), pdemoname); + Z_Free(pdemoname); + Z_Free(buffer); + return; + } p += 12; // DEMOHEADER + p++; // VERSION + p++; // SUBVERSION + if (DEMOVERSION != READUINT16(p)) + { + CONS_Alert(CONS_NOTICE, M_GetText("Ghost %s: Demo format unacceptable.\n"), pdemoname); + Z_Free(pdemoname); + Z_Free(buffer); + return; + } + M_Memcpy(md5, p, 16); p += 16; // demo checksum + for (gh = ghosts; gh; gh = gh->next) + if (!memcmp(md5, gh->checksum, 16)) // another ghost in the game already has this checksum? + { // Don't add another one, then! + CONS_Debug(DBG_SETUP, "Rejecting duplicate ghost %s (MD5 was matched)\n", pdemoname); + Z_Free(pdemoname); + Z_Free(buffer); + return; + } + if (memcmp(p, "PLAY", 4)) + { + CONS_Alert(CONS_NOTICE, M_GetText("Ghost %s: Demo format unacceptable.\n"), pdemoname); + Z_Free(pdemoname); + Z_Free(buffer); + return; + } p += 4; // "PLAY" + p++; // gamemap + p += 16; // mapmd5 (possibly check for consistency?) + flags = READUINT8(p); + if (!(flags & DF_GHOST)) + { + CONS_Alert(CONS_NOTICE, M_GetText("Ghost %s: No ghost data in this demo.\n"), pdemoname); + Z_Free(pdemoname); + Z_Free(buffer); + return; + } + switch ((flags & DF_ATTACKMASK)>>DF_ATTACKSHIFT) + { + case ATTACKING_NONE: // 0 + break; + case ATTACKING_RECORD: // 1 + p += 10; // demo time, score, and rings + break; + case ATTACKING_NIGHTS: // 2 + p += 8; // demo time left, score + break; + default: // 3 + break; + } + + p += 4; // random seed + + // Player name (TODO: Display this somehow if it doesn't match cv_playername!) + M_Memcpy(name, p,16); + p += 16; + + // Skin + M_Memcpy(skin, p,16); + p += 16; + + // Color + M_Memcpy(color, p,16); + p += 16; + + // Ghosts do not have a player structure to put this in. + p++; // charability + p++; // charability2 + p++; // actionspd + p++; // mindash + p++; // maxdash + p++; // normalspeed + p++; // runspeed + p++; // thrustfactor + p++; // accelstart + p++; // acceleration + p += 4; // jumpfactor + + // net var data + count = READUINT16(p); + while (count--) + { + p += 2; + SKIPSTRING(p); + p++; + } + + if (*p == DEMOMARKER) + { + CONS_Alert(CONS_NOTICE, M_GetText("Failed to add ghost %s: Replay is empty.\n"), pdemoname); + Z_Free(pdemoname); + Z_Free(buffer); + return; + } + + gh = Z_Calloc(sizeof(demoghost), PU_LEVEL, NULL); + gh->next = ghosts; + gh->buffer = buffer; + M_Memcpy(gh->checksum, md5, 16); + gh->p = p; + + ghosts = gh; + mthing = playerstarts[0]; + I_Assert(mthing); + { // A bit more complex than P_SpawnPlayer because ghosts aren't solid and won't just push themselves out of the ceiling. + fixed_t x,y,z; + x = mthing->x << FRACBITS; + y = mthing->y << FRACBITS; + if (mthing->options & MTF_AMBUSH) + z = R_PointInSubsector(x, y)->sector->ceilingheight - mobjinfo[MT_PLAYER].height; + else if (mthing->options >> ZSHIFT) + { + sector_t *sector = R_PointInSubsector(x, y)->sector; + z = sector->floorheight + ((mthing->options >> ZSHIFT) << FRACBITS); + if (z > sector->ceilingheight - mobjinfo[MT_PLAYER].height) + z = sector->ceilingheight - mobjinfo[MT_PLAYER].height; + } + else + z = mthing->z << FRACBITS; + gh->mo = P_SpawnMobj(x, y, z, MT_GHOST); + gh->mo->angle = FixedAngle(mthing->angle*FRACUNIT); + } + gh->mo->state = states+S_PLAY_STND; + gh->mo->sprite = gh->mo->state->sprite; + gh->mo->frame = (gh->mo->state->frame & FF_FRAMEMASK) | tr_trans20<mo->tics = -1; + + gh->oldmo.x = gh->mo->x; + gh->oldmo.y = gh->mo->y; + gh->oldmo.z = gh->mo->z; + + // Set skin + for (i = 0; i < numskins; i++) + if (!stricmp(skins[i].name,skin)) + { + gh->mo->skin = &skins[i]; + break; + } + + // Set color + for (i = 0; i < MAXSKINCOLORS; i++) + if (!stricmp(Color_Names[i],color)) + { + gh->mo->color = (UINT8)i; + break; + } + + CONS_Printf(M_GetText("Added ghost %s from %s\n"), name, pdemoname); + Z_Free(pdemoname); +} + +// +// G_TimeDemo +// NOTE: name is a full filename for external demos +// +static INT32 restorecv_vidwait; + +void G_TimeDemo(const char *name) +{ + nodrawers = M_CheckParm("-nodraw"); + noblit = M_CheckParm("-noblit"); + restorecv_vidwait = cv_vidwait.value; + if (cv_vidwait.value) + CV_Set(&cv_vidwait, "0"); + timingdemo = true; + singletics = true; + framecount = 0; + demostarttime = I_GetTime(); + G_DeferedPlayDemo(name); +} + +void G_DoPlayMetal(void) +{ + lumpnum_t l; + mobj_t *mo = NULL; + thinker_t *th; + + // it's an internal demo + if ((l = W_CheckNumForName(va("%sMS",G_BuildMapName(gamemap)))) == LUMPERROR) + { + CONS_Alert(CONS_WARNING, M_GetText("No bot recording for this map.\n")); + return; + } + else + metalbuffer = metal_p = W_CacheLumpNum(l, PU_STATIC); + + // find metal sonic + for (th = thinkercap.next; th != &thinkercap; th = th->next) + { + if (th->function.acp1 != (actionf_p1)P_MobjThinker) + continue; + + mo = (mobj_t *)th; + if (mo->type == MT_METALSONIC_RACE) + break; + } + if (!mo) + { + CONS_Alert(CONS_ERROR, M_GetText("Failed to find bot entity.\n")); + return; + } + + // read demo header + metal_p += 12; // DEMOHEADER + metal_p++; // VERSION + metal_p++; // SUBVERSION + if (DEMOVERSION != READUINT16(metal_p)) + { + CONS_Alert(CONS_WARNING, M_GetText("Failed to load bot recording for this map, format version mismatch.\n")); + Z_Free(metalbuffer); + return; + } + metal_p += 16; // demo checksum + if (memcmp(metal_p, "METL", 4)) + { + CONS_Alert(CONS_WARNING, M_GetText("Failed to load bot recording for this map, wasn't recorded in Metal format.\n")); + Z_Free(metalbuffer); + return; + } metal_p += 4; // "METL" + + // read initial tic + memset(&oldmetal,0,sizeof(oldmetal)); + oldmetal.x = mo->x; + oldmetal.y = mo->y; + oldmetal.z = mo->z; + oldmetal.angle = mo->angle; + metalplayback = mo; +} + +void G_DoneLevelLoad(void) +{ + CONS_Printf(M_GetText("Loaded level in %f sec\n"), (double)(I_GetTime() - demostarttime) / TICRATE); + framecount = 0; + demostarttime = I_GetTime(); +} + +/* +=================== += += G_CheckDemoStatus += += Called after a death or level completion to allow demos to be cleaned up += Returns true if a new demo loop action will take place +=================== +*/ + +// reset engine variable set for the demos +// called from stopdemo command, map command, and g_checkdemoStatus. +void G_StopDemo(void) +{ + if (metalplayback) + { // Metal Sonic finishing doesn't end the game, dammit. + Z_Free(metalbuffer); + metalbuffer = NULL; + metalplayback = NULL; + if (!demoplayback) + return; + } + Z_Free(demobuffer); + demobuffer = NULL; + demoplayback = false; + titledemo = false; + timingdemo = false; + singletics = false; + + if (gamestate == GS_INTERMISSION) + Y_EndIntermission(); // cleanup + + G_SetGamestate(GS_NULL); + wipegamestate = GS_NULL; + SV_StopServer(); + SV_ResetServer(); +} + +boolean G_CheckDemoStatus(void) +{ + boolean saved; + + if(ghosts) // ... ... ... + ghosts = NULL; // :) + + if (metalrecording) + { + saved = false; + if (demo_p) + { + UINT8 *p = demobuffer+16; // checksum position +#ifdef NOMD5 + UINT8 i; + WRITEUINT8(demo_p, DEMOMARKER); // add the demo end marker + for (i = 0; i < 16; i++, p++) + *p = P_Random(); // This MD5 was chosen by fair dice roll and most likely < 50% correct. +#else + WRITEUINT8(demo_p, DEMOMARKER); // add the demo end marker + md5_buffer((char *)p+16, demo_p - (p+16), (void *)p); // make a checksum of everything after the checksum in the file. +#endif + saved = FIL_WriteFile(va("%sMS.LMP", G_BuildMapName(gamemap)), demobuffer, demo_p - demobuffer); // finally output the file. + } + free(demobuffer); + metalrecording = false; + if (saved) + I_Error("Saved to %sMS.LMP", G_BuildMapName(gamemap)); + else + I_Error("Failed to save demo!"); + return true; + } + + if (timingdemo) + { + INT32 demotime; + double f1, f2; + demotime = I_GetTime() - demostarttime; + if (!demotime) + return true; + G_StopDemo(); + timingdemo = false; + f1 = (double)demotime; + f2 = (double)framecount*TICRATE; + CONS_Printf(M_GetText("timed %u gametics in %d realtics\n%f seconds, %f avg fps\n"), leveltime,demotime,f1/TICRATE,f2/f1); + if (restorecv_vidwait != cv_vidwait.value) + CV_SetValue(&cv_vidwait, restorecv_vidwait); + D_AdvanceDemo(); + return true; + } + + if (demoplayback) + { + if (singledemo) + I_Quit(); + G_StopDemo(); + + if (modeattacking == ATTACKING_RECORD) + M_EndModeAttackRun(); + else + D_AdvanceDemo(); + + return true; + } + + if (demorecording) + { + UINT8 *p = demobuffer+16; // checksum position +#ifdef NOMD5 + UINT8 i; + WRITEUINT8(demo_p, DEMOMARKER); // add the demo end marker + for (i = 0; i < 16; i++, p++) + *p = P_Random(); // This MD5 was chosen by fair dice roll and most likely < 50% correct. +#else + WRITEUINT8(demo_p, DEMOMARKER); // add the demo end marker + md5_buffer((char *)p+16, demo_p - (p+16), p); // make a checksum of everything after the checksum in the file. +#endif + saved = FIL_WriteFile(demoname, demobuffer, demo_p - demobuffer); // finally output the file. + free(demobuffer); + demorecording = false; + + if (!modeattacking == ATTACKING_RECORD) + { + if (saved) + CONS_Printf(M_GetText("Demo %s recorded\n"), demoname); + else + CONS_Alert(CONS_WARNING, M_GetText("Demo %s not saved\n"), demoname); + } + return true; + } + + if (metalplayback) + { + G_StopDemo(); + return false; + } + + return false; +} + +// +// G_SetGamestate +// +// Use this to set the gamestate, please. +// +void G_SetGamestate(gamestate_t newstate) +{ + gamestate = newstate; +} + +/* These functions handle the exitgame flag. Before, when the user + chose to end a game, it happened immediately, which could cause + crashes if the game was in the middle of something. Now, a flag + is set, and the game can then be stopped when it's safe to do + so. +*/ + +// Used as a callback function. +void G_SetExitGameFlag(void) +{ + exitgame = true; +} + +void G_ClearExitGameFlag(void) +{ + exitgame = false; +} + +boolean G_GetExitGameFlag(void) +{ + return exitgame; +} + +// Same deal with retrying. +void G_SetRetryFlag(void) +{ + retrying = true; +} + +void G_ClearRetryFlag(void) +{ + retrying = false; +} + +boolean G_GetRetryFlag(void) +{ + return retrying; +} + +// Time utility functions +INT32 G_TicsToHours(tic_t tics) +{ + return tics/(3600*TICRATE); +} + +INT32 G_TicsToMinutes(tic_t tics, boolean full) +{ + if (full) + return tics/(60*TICRATE); + else + return tics/(60*TICRATE)%60; +} + +INT32 G_TicsToSeconds(tic_t tics) +{ + return (tics/TICRATE)%60; +} + +INT32 G_TicsToCentiseconds(tic_t tics) +{ + return (INT32)((tics%TICRATE) * (100.00f/TICRATE)); +} + +INT32 G_TicsToMilliseconds(tic_t tics) +{ + return (INT32)((tics%TICRATE) * (1000.00f/TICRATE)); +} + diff --git a/src/g_game.h b/src/g_game.h new file mode 100644 index 000000000..d57b6ebdd --- /dev/null +++ b/src/g_game.h @@ -0,0 +1,213 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 1993-1996 by id Software, Inc. +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Copyright (C) 1999-2014 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file g_game.h +/// \brief Game loop, events handling. + +#ifndef __G_GAME__ +#define __G_GAME__ + +#include "doomdef.h" +#include "doomstat.h" +#include "d_event.h" + +extern char gamedatafilename[64]; +extern char timeattackfolder[64]; +extern char customversionstring[32]; +#define GAMEDATASIZE (4*8192) + +#ifdef SEENAMES +extern player_t *seenplayer; +#endif +extern char player_names[MAXPLAYERS][MAXPLAYERNAME+1]; + +extern player_t players[MAXPLAYERS]; +extern boolean playeringame[MAXPLAYERS]; + +// ====================================== +// DEMO playback/recording related stuff. +// ====================================== + +// demoplaying back and demo recording +extern boolean demoplayback, titledemo, demorecording, timingdemo; +extern mobj_t *metalplayback; + +// Quit after playing a demo from cmdline. +extern boolean singledemo; +extern boolean demo_start; + +// gametic at level start +extern tic_t levelstarttic; + +// for modding? +extern INT16 prevmap, nextmap; +extern INT32 gameovertics; +extern tic_t timeinmap; // Ticker for time spent in level (used for levelcard display) +extern INT16 rw_maximums[NUM_WEAPONS]; + +// used in game menu +extern consvar_t cv_crosshair, cv_crosshair2; +extern consvar_t cv_invertmouse, cv_alwaysfreelook, cv_mousemove; +extern consvar_t cv_sideaxis,cv_turnaxis,cv_moveaxis,cv_lookaxis,cv_fireaxis,cv_firenaxis; +extern consvar_t cv_sideaxis2,cv_turnaxis2,cv_moveaxis2,cv_lookaxis2,cv_fireaxis2,cv_firenaxis2; +extern consvar_t cv_ghost_bestscore, cv_ghost_besttime, cv_ghost_bestrings, cv_ghost_last, cv_ghost_guest; + +// mouseaiming (looking up/down with the mouse or keyboard) +#define KB_LOOKSPEED (1<<25) +#define MAXPLMOVE (50) +#define SLOWTURNTICS (6) + +// build an internal map name MAPxx from map number +const char *G_BuildMapName(INT32 map); +void G_BuildTiccmd(ticcmd_t *cmd, INT32 realtics); +void G_BuildTiccmd2(ticcmd_t *cmd, INT32 realtics); + +// copy ticcmd_t to and fro the normal way +ticcmd_t *G_CopyTiccmd(ticcmd_t* dest, const ticcmd_t* src, const size_t n); +// copy ticcmd_t to and fro network packets +ticcmd_t *G_MoveTiccmd(ticcmd_t* dest, const ticcmd_t* src, const size_t n); + +// clip the console player aiming to the view +INT16 G_ClipAimingPitch(INT32 *aiming); +INT16 G_SoftwareClipAimingPitch(INT32 *aiming); + +extern angle_t localangle, localangle2; +extern INT32 localaiming, localaiming2; // should be an angle_t but signed + +// +// GAME +// +void G_ChangePlayerReferences(mobj_t *oldmo, mobj_t *newmo); +void G_DoReborn(INT32 playernum); +void G_PlayerReborn(INT32 player); +void G_InitNew(UINT8 pultmode, const char *mapname, boolean resetplayer, + boolean skipprecutscene); +char *G_BuildMapTitle(INT32 mapnum); + +// XMOD spawning +mapthing_t *G_FindCTFStart(INT32 playernum); +mapthing_t *G_FindMatchStart(INT32 playernum); +mapthing_t *G_FindCoopStart(INT32 playernum); +void G_SpawnPlayer(INT32 playernum, boolean starpost); + +// Can be called by the startup code or M_Responder. +// A normal game starts at map 1, but a warp test can start elsewhere +void G_DeferedInitNew(boolean pultmode, const char *mapname, INT32 pickedchar, + boolean SSSG, boolean FLS); +void G_DoLoadLevel(boolean resetplayer); + +void G_DeferedPlayDemo(const char *demo); + +// Can be called by the startup code or M_Responder, calls P_SetupLevel. +void G_LoadGame(UINT32 slot, INT16 mapoverride); + +void G_SaveGameData(void); + +void G_SaveGame(UINT32 slot); + +// Only called by startup code. +void G_RecordDemo(const char *name); +void G_RecordMetal(void); +void G_BeginRecording(void); +void G_BeginMetal(void); + +// Only called by shutdown code. +void G_SetDemoTime(UINT32 ptime, UINT32 pscore, UINT16 prings); +UINT8 G_CmpDemoTime(char *oldname, char *newname); + +typedef enum +{ + GHC_NORMAL = 0, + GHC_SUPER, + GHC_FIREFLOWER, + GHC_INVINCIBLE +} ghostcolor_t; + +// Record/playback tics +void G_ReadDemoTiccmd(ticcmd_t *cmd, INT32 playernum); +void G_WriteDemoTiccmd(ticcmd_t *cmd, INT32 playernum); +void G_GhostAddThok(void); +void G_GhostAddSpin(void); +void G_GhostAddColor(ghostcolor_t color); +void G_GhostAddFlip(void); +void G_GhostAddScale(UINT16 scale); +void G_GhostAddHit(mobj_t *victim); +void G_WriteGhostTic(mobj_t *ghost); +void G_ConsGhostTic(void); +void G_GhostTicker(void); +void G_ReadMetalTic(mobj_t *metal); +void G_WriteMetalTic(mobj_t *metal); + +void G_DoPlayDemo(char *defdemoname); +void G_TimeDemo(const char *name); +void G_AddGhost(char *defdemoname); +void G_DoPlayMetal(void); +void G_DoneLevelLoad(void); +void G_StopDemo(void); +boolean G_CheckDemoStatus(void); + +boolean G_IsSpecialStage(INT32 mapnum); +boolean G_GametypeUsesLives(void); +boolean G_GametypeHasTeams(void); +boolean G_GametypeHasSpectators(void); +boolean G_RingSlingerGametype(void); +boolean G_PlatformGametype(void); +boolean G_TagGametype(void); +void G_ExitLevel(void); +void G_NextLevel(void); +void G_Continue(void); +void G_UseContinue(void); +void G_AfterIntermission(void); + +void G_Ticker(boolean run); +boolean G_Responder(event_t *ev); + +void G_AddPlayer(INT32 playernum); + +void G_SetExitGameFlag(void); +void G_ClearExitGameFlag(void); +boolean G_GetExitGameFlag(void); +void G_SetRetryFlag(void); +void G_ClearRetryFlag(void); +boolean G_GetRetryFlag(void); + + +void G_LoadGameData(void); +void G_LoadGameSettings(void); + +void G_SetGameModified(boolean silent); + +void G_SetGamestate(gamestate_t newstate); + +// Gamedata record shit +void G_AllocMainRecordData(INT16 i); +void G_AllocNightsRecordData(INT16 i); +void G_ClearRecords(void); + +UINT32 G_GetBestScore(INT16 map); +tic_t G_GetBestTime(INT16 map); +UINT16 G_GetBestRings(INT16 map); +UINT32 G_GetBestNightsScore(INT16 map, UINT8 mare); +tic_t G_GetBestNightsTime(INT16 map, UINT8 mare); +UINT8 G_GetBestNightsGrade(INT16 map, UINT8 mare); + +void G_AddTempNightsRecords(UINT32 pscore, tic_t ptime, UINT8 mare); +void G_SetNightsRecords(void); + +FUNCMATH INT32 G_TicsToHours(tic_t tics); +FUNCMATH INT32 G_TicsToMinutes(tic_t tics, boolean full); +FUNCMATH INT32 G_TicsToSeconds(tic_t tics); +FUNCMATH INT32 G_TicsToCentiseconds(tic_t tics); +FUNCMATH INT32 G_TicsToMilliseconds(tic_t tics); + +// Don't split up TOL handling +INT16 G_TOLFlag(INT32 pgametype); + +#endif diff --git a/src/g_input.c b/src/g_input.c new file mode 100644 index 000000000..29d13dce9 --- /dev/null +++ b/src/g_input.c @@ -0,0 +1,1366 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Copyright (C) 1999-2014 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file g_input.c +/// \brief handle mouse/keyboard/joystick inputs, +/// maps inputs to game controls (forward, spin, jump...) + +#include "doomdef.h" +#include "doomstat.h" +#include "g_input.h" +#include "keys.h" +#include "hu_stuff.h" // need HUFONT start & end +#include "keys.h" +#include "d_net.h" +#include "console.h" + +#define MAXMOUSESENSITIVITY 100 // sensitivity steps + +static CV_PossibleValue_t mousesens_cons_t[] = {{1, "MIN"}, {MAXMOUSESENSITIVITY, "MAX"}, {0, NULL}}; +static CV_PossibleValue_t onecontrolperkey_cons_t[] = {{1, "One"}, {2, "Several"}, {0, NULL}}; + +// mouse values are used once +consvar_t cv_mousesens = {"mousesens", "35", CV_SAVE, mousesens_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_mousesens2 = {"mousesens2", "35", CV_SAVE, mousesens_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_controlperkey = {"controlperkey", "One", CV_SAVE, onecontrolperkey_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; + +INT32 mousex, mousey; +INT32 mlooky; // like mousey but with a custom sensitivity for mlook + +INT32 mouse2x, mouse2y, mlook2y; + +// joystick values are repeated +INT32 joyxmove[JOYAXISSET], joyymove[JOYAXISSET], joy2xmove[JOYAXISSET], joy2ymove[JOYAXISSET]; + +// current state of the keys: true if pushed +UINT8 gamekeydown[NUMINPUTS]; + +// two key codes (or virtual key) per game control +INT32 gamecontrol[num_gamecontrols][2]; +INT32 gamecontrolbis[num_gamecontrols][2]; // secondary splitscreen player + +typedef struct +{ + UINT8 time; + UINT8 state; + UINT8 clicks; +} dclick_t; +static dclick_t mousedclicks[MOUSEBUTTONS]; +static dclick_t joydclicks[JOYBUTTONS + JOYHATS*4]; +static dclick_t mouse2dclicks[MOUSEBUTTONS]; +static dclick_t joy2dclicks[JOYBUTTONS + JOYHATS*4]; + +// protos +static UINT8 G_CheckDoubleClick(UINT8 state, dclick_t *dt); + +// +// Remaps the inputs to game controls. +// +// A game control can be triggered by one or more keys/buttons. +// +// Each key/mousebutton/joybutton triggers ONLY ONE game control. +// +void G_MapEventsToControls(event_t *ev) +{ + INT32 i; + UINT8 flag; + + switch (ev->type) + { + case ev_keydown: + if (ev->data1 < NUMINPUTS) + gamekeydown[ev->data1] = 1; +#ifdef PARANOIA + else + { + CONS_Debug(DBG_GAMELOGIC, "Bad downkey input %d\n",ev->data1); + } + +#endif + break; + + case ev_keyup: + if (ev->data1 < NUMINPUTS) + gamekeydown[ev->data1] = 0; +#ifdef PARANOIA + else + { + CONS_Debug(DBG_GAMELOGIC, "Bad upkey input %d\n",ev->data1); + } +#endif + break; + + case ev_mouse: // buttons are virtual keys + mousex = (INT32)(ev->data2*((cv_mousesens.value*cv_mousesens.value)/110.0f + 0.1f)); + mousey = (INT32)(ev->data3*((cv_mousesens.value*cv_mousesens.value)/110.0f + 0.1f)); + mlooky = mousey; + break; + + case ev_joystick: // buttons are virtual keys + i = ev->data1; + if (i >= JOYAXISSET) + break; + if (ev->data2 != INT32_MAX) joyxmove[i] = ev->data2; + if (ev->data3 != INT32_MAX) joyymove[i] = ev->data3; + break; + + case ev_joystick2: // buttons are virtual keys + i = ev->data1; + if (i >= JOYAXISSET) + break; + if (ev->data2 != INT32_MAX) joy2xmove[i] = ev->data2; + if (ev->data3 != INT32_MAX) joy2ymove[i] = ev->data3; + break; + + case ev_mouse2: // buttons are virtual keys + mouse2x = (INT32)(ev->data2*((cv_mousesens2.value*cv_mousesens2.value)/110.0f + 0.1f)); + mouse2y = (INT32)(ev->data3*((cv_mousesens2.value*cv_mousesens2.value)/110.0f + 0.1f)); + mlook2y = mouse2y; + break; + + default: + break; + } + + // ALWAYS check for mouse & joystick double-clicks even if no mouse event + for (i = 0; i < MOUSEBUTTONS; i++) + { + flag = G_CheckDoubleClick(gamekeydown[KEY_MOUSE1+i], &mousedclicks[i]); + gamekeydown[KEY_DBLMOUSE1+i] = flag; + } + + for (i = 0; i < JOYBUTTONS + JOYHATS*4; i++) + { + flag = G_CheckDoubleClick(gamekeydown[KEY_JOY1+i], &joydclicks[i]); + gamekeydown[KEY_DBLJOY1+i] = flag; + } + + for (i = 0; i < MOUSEBUTTONS; i++) + { + flag = G_CheckDoubleClick(gamekeydown[KEY_2MOUSE1+i], &mouse2dclicks[i]); + gamekeydown[KEY_DBL2MOUSE1+i] = flag; + } + + for (i = 0; i < JOYBUTTONS + JOYHATS*4; i++) + { + flag = G_CheckDoubleClick(gamekeydown[KEY_2JOY1+i], &joy2dclicks[i]); + gamekeydown[KEY_DBL2JOY1+i] = flag; + } +} + +// +// General double-click detection routine for any kind of input. +// +static UINT8 G_CheckDoubleClick(UINT8 state, dclick_t *dt) +{ + if (state != dt->state && dt->time > 1) + { + dt->state = state; + if (state) + dt->clicks++; + if (dt->clicks == 2) + { + dt->clicks = 0; + return true; + } + else + dt->time = 0; + } + else + { + dt->time++; + if (dt->time > 20) + { + dt->clicks = 0; + dt->state = 0; + } + } + return false; +} + +typedef struct +{ + INT32 keynum; + const char *name; +} keyname_t; + +static keyname_t keynames[] = +{ + {KEY_SPACE, "SPACE"}, + {KEY_CAPSLOCK, "CAPS LOCK"}, + {KEY_ENTER, "ENTER"}, + {KEY_TAB, "TAB"}, + {KEY_ESCAPE, "ESCAPE"}, + {KEY_BACKSPACE, "BACKSPACE"}, + + {KEY_NUMLOCK, "NUMLOCK"}, + {KEY_SCROLLLOCK, "SCROLLLOCK"}, + + // bill gates keys +#ifndef _arch_dreamcast + {KEY_LEFTWIN, "LEFTWIN"}, + {KEY_RIGHTWIN, "RIGHTWIN"}, + {KEY_MENU, "MENU"}, +#endif + + {KEY_LSHIFT, "LSHIFT"}, + {KEY_RSHIFT, "RSHIFT"}, + {KEY_LSHIFT, "SHIFT"}, + {KEY_LCTRL, "LCTRL"}, + {KEY_RCTRL, "RCTRL"}, + {KEY_LCTRL, "CTRL"}, + {KEY_LALT, "LALT"}, + {KEY_RALT, "RALT"}, + {KEY_LALT, "ALT"}, + + // keypad keys + {KEY_KPADSLASH, "KEYPAD /"}, + {KEY_KEYPAD7, "KEYPAD 7"}, + {KEY_KEYPAD8, "KEYPAD 8"}, + {KEY_KEYPAD9, "KEYPAD 9"}, + {KEY_MINUSPAD, "KEYPAD -"}, + {KEY_KEYPAD4, "KEYPAD 4"}, + {KEY_KEYPAD5, "KEYPAD 5"}, + {KEY_KEYPAD6, "KEYPAD 6"}, + {KEY_PLUSPAD, "KEYPAD +"}, + {KEY_KEYPAD1, "KEYPAD 1"}, + {KEY_KEYPAD2, "KEYPAD 2"}, + {KEY_KEYPAD3, "KEYPAD 3"}, + {KEY_KEYPAD0, "KEYPAD 0"}, + {KEY_KPADDEL, "KEYPAD ."}, + + // extended keys (not keypad) + {KEY_HOME, "HOME"}, + {KEY_UPARROW, "UP ARROW"}, + {KEY_PGUP, "PGUP"}, + {KEY_LEFTARROW, "LEFT ARROW"}, + {KEY_RIGHTARROW, "RIGHT ARROW"}, + {KEY_END, "END"}, + {KEY_DOWNARROW, "DOWN ARROW"}, + {KEY_PGDN, "PGDN"}, + {KEY_INS, "INS"}, + {KEY_DEL, "DEL"}, + + // other keys + {KEY_F1, "F1"}, + {KEY_F2, "F2"}, + {KEY_F3, "F3"}, + {KEY_F4, "F4"}, + {KEY_F5, "F5"}, + {KEY_F6, "F6"}, + {KEY_F7, "F7"}, + {KEY_F8, "F8"}, + {KEY_F9, "F9"}, + {KEY_F10, "F10"}, + {KEY_F11, "F11"}, + {KEY_F12, "F12"}, + + // KEY_CONSOLE has an exception in the keyname code + {'`', "TILDE"}, + {KEY_PAUSE, "PAUSE/BREAK"}, + + // virtual keys for mouse buttons and joystick buttons + {KEY_MOUSE1+0,"MOUSE1"}, + {KEY_MOUSE1+1,"MOUSE2"}, + {KEY_MOUSE1+2,"MOUSE3"}, +#if !defined (_arch_dreamcast) && !defined (_XBOX) && !defined (_PSP) && !defined (_WII) + {KEY_MOUSE1+3,"MOUSE4"}, + {KEY_MOUSE1+4,"MOUSE5"}, + {KEY_MOUSE1+5,"MOUSE6"}, + {KEY_MOUSE1+6,"MOUSE7"}, + {KEY_MOUSE1+7,"MOUSE8"}, +#endif + {KEY_2MOUSE1+0,"SEC_MOUSE2"}, // BP: sorry my mouse handler swap button 1 and 2 + {KEY_2MOUSE1+1,"SEC_MOUSE1"}, + {KEY_2MOUSE1+2,"SEC_MOUSE3"}, +#if !defined (_arch_dreamcast) && !defined (_XBOX) && !defined (_PSP) && !defined (_WII) + {KEY_2MOUSE1+3,"SEC_MOUSE4"}, + {KEY_2MOUSE1+4,"SEC_MOUSE5"}, + {KEY_2MOUSE1+5,"SEC_MOUSE6"}, + {KEY_2MOUSE1+6,"SEC_MOUSE7"}, + {KEY_2MOUSE1+7,"SEC_MOUSE8"}, +#endif + {KEY_MOUSEWHEELUP, "Wheel 1 UP"}, + {KEY_MOUSEWHEELDOWN, "Wheel 1 Down"}, + {KEY_2MOUSEWHEELUP, "Wheel 2 UP"}, + {KEY_2MOUSEWHEELDOWN, "Wheel 2 Down"}, + +#ifdef DC + {KEY_JOY1+0, "JOYC"}, + {KEY_JOY1+1, "JOYB"}, + {KEY_JOY1+2, "JOYA"}, + {KEY_JOY1+3, "JOYS"}, + {KEY_JOY1+4, "JOYZ"}, + {KEY_JOY1+5, "JOYY"}, + {KEY_JOY1+6, "JOYX"}, + {KEY_JOY1+7, "JOYD"}, +#elif defined (_XBOX) + {KEY_JOY1+0, "JOYA"}, + {KEY_JOY1+1, "JOYB"}, + {KEY_JOY1+2, "JOYX"}, + {KEY_JOY1+3, "JOYY"}, + {KEY_JOY1+4, "JOYG"}, + {KEY_JOY1+5, "JOYW"}, + {KEY_JOY1+6, "JOYL"}, + {KEY_JOY1+7, "JOYR"}, + {KEY_JOY1+8, "JOYS"}, + {KEY_JOY1+9, "JOYN"}, + {KEY_JOY1+10,"JOYW"}, + {KEY_JOY1+11,"JOYE"}, +#define NOMOREJOYBTN_1S +#elif defined (_PSP) + {KEY_JOY1+0, "TRIANGLE"}, + {KEY_JOY1+1, "CIRCLE" }, + {KEY_JOY1+2, "CROSS" }, + {KEY_JOY1+3, "SQUARE" }, + {KEY_JOY1+4, "LTRIGGER"}, + {KEY_JOY1+5, "RTRIGGER"}, + {KEY_JOY1+6, "SELECT" }, + {KEY_JOY1+7, "START" }, + {KEY_JOY1+8, "HOME" }, + {KEY_JOY1+9, "HOLD" }, +#define NOMOREJOYBTN_1S +#elif defined (GP2X) + {KEY_JOY1+0, "JOYA"}, + {KEY_JOY1+1, "JOYY"}, + {KEY_JOY1+2, "JOYB"}, + {KEY_JOY1+3, "JOYX"}, + {KEY_JOY1+4, "JOYL"}, + {KEY_JOY1+5, "JOYR"}, + {KEY_JOY1+6, "JOYVOLUP"}, + {KEY_JOY1+7, "JOYVOLDOWN"}, + {KEY_JOY1+8, "JOYSELECT"}, +#elif defined (_NDS) + {KEY_JOY1+0, "JOYA"}, + {KEY_JOY1+1, "JOYB"}, + {KEY_JOY1+2, "JOYX"}, + {KEY_JOY1+3, "JOYY"}, + {KEY_JOY1+4, "JOYL"}, + {KEY_JOY1+5, "JOYR"}, + {KEY_JOY1+6, "JOYSTART"}, + {KEY_JOY1+7, "JOYSELECT"}, +#define NOMOREJOYBTN_1S +#elif defined (WMINPUT) + {KEY_JOY1+0, "JOYB"}, + {KEY_JOY1+1, "JOYA"}, + {KEY_JOY1+2, "JOYUP"}, + {KEY_JOY1+3, "JOYDOWN"}, + {KEY_JOY1+4, "JOYLEFT"}, + {KEY_JOY1+5, "JOYRIGHT"}, + {KEY_JOY1+6, "JOYAA"}, + {KEY_JOY1+7, "JOYBB"}, + {KEY_JOY1+8, "JOYCC"}, + {KEY_JOY1+9, "JOYXX"}, + {KEY_JOY1+10, "JOYYY"}, + {KEY_JOY1+11, "JOYZZ"}, + {KEY_JOY1+12, "JOYL"}, + {KEY_JOY1+13, "JOYR"}, + {KEY_JOY1+14, "JOYZL"}, + {KEY_JOY1+15, "JOYZR"}, + {KEY_JOY1+16, "JOYSELECT"}, + {KEY_JOY1+17, "JOYSTART"}, + {KEY_JOY1+18, "JOYHOME"}, + {KEY_JOY1+19, "JOYMINUS"}, + {KEY_JOY1+20, "JOYPLUS"}, + {KEY_JOY1+21, "JOY_1"}, + {KEY_JOY1+22, "JOY_2"}, + {KEY_JOY1+23, "JOY24"}, + {KEY_JOY1+24, "JOY25"}, + {KEY_JOY1+25, "JOY26"}, + {KEY_JOY1+26, "JOY27"}, + {KEY_JOY1+27, "JOY28"}, + {KEY_JOY1+28, "JOY29"}, + {KEY_JOY1+29, "JOY30"}, + {KEY_JOY1+30, "JOY31"}, + {KEY_JOY1+31, "JOY32"}, +#define NOMOREJOYBTN_1S +#elif defined (_WII) + {KEY_JOY1+0, "JOYA"}, + {KEY_JOY1+1, "JOYB"}, + {KEY_JOY1+2, "JOY1"}, + {KEY_JOY1+3, "JOY2"}, + {KEY_JOY1+4, "JOYMINUS"}, + {KEY_JOY1+5, "JOYPLUS"}, + {KEY_JOY1+6, "JOYHOME"}, + {KEY_JOY1+7, "JOYZ"}, + {KEY_JOY1+8, "JOYC"}, + {KEY_JOY1+9, "JOYA_CC"}, + {KEY_JOY1+10, "JOYB_CC"}, + {KEY_JOY1+11, "JOYX"}, + {KEY_JOY1+12, "JOYY"}, + {KEY_JOY1+13, "JOYL"}, + {KEY_JOY1+14, "JOYR"}, + {KEY_JOY1+15, "JOYZL"}, + {KEY_JOY1+16, "JOYZR"}, + {KEY_JOY1+17, "JOYMINUS_CC"}, + {KEY_JOY1+18, "JOYHPLUS_CC"}, + {KEY_JOY1+19, "JOYMHOME_CC"}, +#define NOMOREJOYBTN_1S +#else + {KEY_JOY1+0, "JOY1"}, + {KEY_JOY1+1, "JOY2"}, + {KEY_JOY1+2, "JOY3"}, + {KEY_JOY1+3, "JOY4"}, + {KEY_JOY1+4, "JOY5"}, + {KEY_JOY1+5, "JOY6"}, + {KEY_JOY1+6, "JOY7"}, + {KEY_JOY1+7, "JOY8"}, + {KEY_JOY1+8, "JOY9"}, +#endif +#if !defined (_arch_dreamcast) && !defined (NOMOREJOYBTN_1S) + // we use up to 32 buttons in DirectInput + {KEY_JOY1+9, "JOY10"}, + {KEY_JOY1+10, "JOY11"}, + {KEY_JOY1+11, "JOY12"}, + {KEY_JOY1+12, "JOY13"}, + {KEY_JOY1+13, "JOY14"}, + {KEY_JOY1+14, "JOY15"}, + {KEY_JOY1+15, "JOY16"}, + {KEY_JOY1+16, "JOY17"}, + {KEY_JOY1+17, "JOY18"}, + {KEY_JOY1+18, "JOY19"}, + {KEY_JOY1+19, "JOY20"}, + {KEY_JOY1+20, "JOY21"}, + {KEY_JOY1+21, "JOY22"}, + {KEY_JOY1+22, "JOY23"}, + {KEY_JOY1+23, "JOY24"}, + {KEY_JOY1+24, "JOY25"}, + {KEY_JOY1+25, "JOY26"}, + {KEY_JOY1+26, "JOY27"}, + {KEY_JOY1+27, "JOY28"}, + {KEY_JOY1+28, "JOY29"}, + {KEY_JOY1+29, "JOY30"}, + {KEY_JOY1+30, "JOY31"}, + {KEY_JOY1+31, "JOY32"}, +#endif + // the DOS version uses Allegro's joystick support + {KEY_HAT1+0, "HATUP"}, + {KEY_HAT1+1, "HATDOWN"}, + {KEY_HAT1+2, "HATLEFT"}, + {KEY_HAT1+3, "HATRIGHT"}, +#if !defined (_XBOX) && !defined (_PSP) && !defined (_WII) + {KEY_HAT1+4, "HATUP2"}, + {KEY_HAT1+5, "HATDOWN2"}, + {KEY_HAT1+6, "HATLEFT2"}, + {KEY_HAT1+7, "HATRIGHT2"}, +#ifndef _arch_dreamcast + {KEY_HAT1+8, "HATUP3"}, + {KEY_HAT1+9, "HATDOWN3"}, + {KEY_HAT1+10, "HATLEFT3"}, + {KEY_HAT1+11, "HATRIGHT3"}, + {KEY_HAT1+12, "HATUP4"}, + {KEY_HAT1+13, "HATDOWN4"}, + {KEY_HAT1+14, "HATLEFT4"}, + {KEY_HAT1+15, "HATRIGHT4"}, +#endif +#endif + + {KEY_DBLMOUSE1+0, "DBLMOUSE1"}, + {KEY_DBLMOUSE1+1, "DBLMOUSE2"}, + {KEY_DBLMOUSE1+2, "DBLMOUSE3"}, +#if !defined (_arch_dreamcast) && !defined (_XBOX) && !defined (_PSP) && !defined (_WII) + {KEY_DBLMOUSE1+3, "DBLMOUSE4"}, + {KEY_DBLMOUSE1+4, "DBLMOUSE5"}, + {KEY_DBLMOUSE1+5, "DBLMOUSE6"}, + {KEY_DBLMOUSE1+6, "DBLMOUSE7"}, + {KEY_DBLMOUSE1+7, "DBLMOUSE8"}, +#endif + {KEY_DBL2MOUSE1+0, "DBLSEC_MOUSE2"}, // BP: sorry my mouse handler swap button 1 and 2 + {KEY_DBL2MOUSE1+1, "DBLSEC_MOUSE1"}, + {KEY_DBL2MOUSE1+2, "DBLSEC_MOUSE3"}, +#if !defined (_arch_dreamcast) && !defined (_XBOX) && !defined (_PSP) && !defined (_WII) + {KEY_DBL2MOUSE1+3, "DBLSEC_MOUSE4"}, + {KEY_DBL2MOUSE1+4, "DBLSEC_MOUSE5"}, + {KEY_DBL2MOUSE1+5, "DBLSEC_MOUSE6"}, + {KEY_DBL2MOUSE1+6, "DBLSEC_MOUSE7"}, + {KEY_DBL2MOUSE1+7, "DBLSEC_MOUSE8"}, +#endif + +#ifdef DC + {KEY_DBLJOY1+0, "DBLJOYC"}, + {KEY_DBLJOY1+1, "DBLJOYB"}, + {KEY_DBLJOY1+2, "DBLJOYA"}, + {KEY_DBLJOY1+3, "DBLJOYS"}, + {KEY_DBLJOY1+4, "DBLJOYZ"}, + {KEY_DBLJOY1+5, "DBLJOYY"}, + {KEY_DBLJOY1+6, "DBLJOYX"}, + {KEY_DBLJOY1+7, "DBLJOYD"}, +#elif defined (_XBOX) + {KEY_DBLJOY1+0, "DBLJOYA"}, + {KEY_DBLJOY1+1, "DBLJOYB"}, + {KEY_DBLJOY1+2, "DBLJOYX"}, + {KEY_DBLJOY1+3, "DBLJOYY"}, + {KEY_DBLJOY1+4, "DBLJOYG"}, + {KEY_DBLJOY1+5, "DBLJOYW"}, + {KEY_DBLJOY1+6, "DBLJOYL"}, + {KEY_DBLJOY1+7, "DBLJOYR"}, + {KEY_DBLJOY1+8, "DBLJOYS"}, + {KEY_DBLJOY1+9, "DBLJOYN"}, + {KEY_DBLJOY1+10,"DBLJOYW"}, + {KEY_DBLJOY1+11,"DBLJOYE"}, +#define NOMOREJOYBTN_1DBL +#elif defined (_PSP) + {KEY_DBLJOY1+0, "DBLTRIANGLE"}, + {KEY_DBLJOY1+1, "DBLCIRCLE" }, + {KEY_DBLJOY1+2, "DBLCROSS" }, + {KEY_DBLJOY1+3, "DBLSQUARE" }, + {KEY_DBLJOY1+4, "DBLLTRIGGER"}, + {KEY_DBLJOY1+5, "DBLRTRIGGER"}, + {KEY_DBLJOY1+6, "DBLSELECT" }, + {KEY_DBLJOY1+7, "DBLSTART" }, + {KEY_DBLJOY1+8, "DBLHOME" }, + {KEY_DBLJOY1+9, "DBLHOLD" }, +#elif defined (GP2X) + {KEY_DBLJOY1+0, "DBLJOYA"}, + {KEY_DBLJOY1+1, "DBLJOYY"}, + {KEY_DBLJOY1+2, "DBLJOYB"}, + {KEY_DBLJOY1+3, "DBLJOYX"}, + {KEY_DBLJOY1+4, "DBLJOYL"}, + {KEY_DBLJOY1+5, "DBLJOYR"}, + {KEY_DBLJOY1+6, "DBLJOYVOLUP"}, + {KEY_DBLJOY1+7, "DBLJOYVOLDOWN"}, + {KEY_DBLJOY1+8, "DBLJOYSELECT"}, +#define NOMOREJOYBTN_1DBL +#elif defined (_NDS) + {KEY_DBLJOY1+0, "DBLJOYA"}, + {KEY_DBLJOY1+1, "DBLJOYB"}, + {KEY_DBLJOY1+2, "DBLJOYX"}, + {KEY_DBLJOY1+3, "DBLJOYY"}, + {KEY_DBLJOY1+4, "DBLJOYL"}, + {KEY_DBLJOY1+5, "DBLJOYR"}, + {KEY_DBLJOY1+6, "DBLJOYSTART"}, + {KEY_DBLJOY1+7, "DBLJOYSELECT"}, +#define NOMOREJOYBTN_1DBL +#elif defined (WMINPUT) + {KEY_DBLJOY1+0, "DBLJOYB"}, + {KEY_DBLJOY1+1, "DBLJOYA"}, + {KEY_DBLJOY1+2, "DBLJOYUP"}, + {KEY_DBLJOY1+3, "DBLJOYDOWN"}, + {KEY_DBLJOY1+4, "DBLJOYLEFT"}, + {KEY_DBLJOY1+5, "DBLJOYRIGHT"}, + {KEY_DBLJOY1+6, "DBLJOYAA"}, + {KEY_DBLJOY1+7, "DBLJOYBB"}, + {KEY_DBLJOY1+8, "DBLJOYCC"}, + {KEY_DBLJOY1+9, "DBLJOYXX"}, + {KEY_DBLJOY1+10, "DBLJOYYY"}, + {KEY_DBLJOY1+11, "DBLJOYZZ"}, + {KEY_DBLJOY1+12, "DBLJOYL"}, + {KEY_DBLJOY1+13, "DBLJOYR"}, + {KEY_DBLJOY1+14, "DBLJOYZL"}, + {KEY_DBLJOY1+15, "DBLJOYZR"}, + {KEY_DBLJOY1+16, "DBLJOYSELECT"}, + {KEY_DBLJOY1+17, "DBLJOYSTART"}, + {KEY_DBLJOY1+18, "DBLJOYHOME"}, + {KEY_DBLJOY1+19, "DBLJOYMINUS"}, + {KEY_DBLJOY1+20, "DBLJOYPLUS"}, + {KEY_DBLJOY1+21, "DBLJOY_1"}, + {KEY_DBLJOY1+22, "DBLJOY_2"}, + {KEY_DBLJOY1+23, "DBLJOY24"}, + {KEY_DBLJOY1+24, "DBLJOY25"}, + {KEY_DBLJOY1+25, "DBLJOY26"}, + {KEY_DBLJOY1+26, "DBLJOY27"}, + {KEY_DBLJOY1+27, "DBLJOY28"}, + {KEY_DBLJOY1+28, "DBLJOY29"}, + {KEY_DBLJOY1+29, "DBLJOY30"}, + {KEY_DBLJOY1+30, "DBLJOY31"}, + {KEY_DBLJOY1+31, "DBLJOY32"}, +#define NOMOREJOYBTN_1DBL +#elif defined (_WII) + {KEY_DBLJOY1+0, "DBLJOYA"}, + {KEY_DBLJOY1+1, "DBLJOYB"}, + {KEY_DBLJOY1+2, "DBLJOY1"}, + {KEY_DBLJOY1+3, "DBLJOY2"}, + {KEY_DBLJOY1+4, "DBLJOYMINUS"}, + {KEY_DBLJOY1+5, "DBLJOYPLUS"}, + {KEY_DBLJOY1+6, "DBLJOYHOME"}, + {KEY_DBLJOY1+7, "DBLJOYZ"}, + {KEY_DBLJOY1+8, "DBLJOYC"}, + {KEY_DBLJOY1+9, "DBLJOYA_CC"}, + {KEY_DBLJOY1+10, "DBLJOYB_CC"}, + {KEY_DBLJOY1+11, "DBLJOYX"}, + {KEY_DBLJOY1+12, "DBLJOYY"}, + {KEY_DBLJOY1+13, "DBLJOYL"}, + {KEY_DBLJOY1+14, "DBLJOYR"}, + {KEY_DBLJOY1+15, "DBLJOYZL"}, + {KEY_DBLJOY1+16, "DBLJOYZR"}, + {KEY_DBLJOY1+17, "DBLJOYMINUS_CC"}, + {KEY_DBLJOY1+18, "DBLJOYHPLUS_CC"}, + {KEY_DBLJOY1+19, "DBLJOYMHOME_CC"}, +#define NOMOREJOYBTN_1DBL +#else + {KEY_DBLJOY1+0, "DBLJOY1"}, + {KEY_DBLJOY1+1, "DBLJOY2"}, + {KEY_DBLJOY1+2, "DBLJOY3"}, + {KEY_DBLJOY1+3, "DBLJOY4"}, + {KEY_DBLJOY1+4, "DBLJOY5"}, + {KEY_DBLJOY1+5, "DBLJOY6"}, + {KEY_DBLJOY1+6, "DBLJOY7"}, + {KEY_DBLJOY1+7, "DBLJOY8"}, +#endif +#if !defined (_arch_dreamcast) && !defined (NOMOREJOYBTN_1DBL) + {KEY_DBLJOY1+8, "DBLJOY9"}, + {KEY_DBLJOY1+9, "DBLJOY10"}, + {KEY_DBLJOY1+10, "DBLJOY11"}, + {KEY_DBLJOY1+11, "DBLJOY12"}, + {KEY_DBLJOY1+12, "DBLJOY13"}, + {KEY_DBLJOY1+13, "DBLJOY14"}, + {KEY_DBLJOY1+14, "DBLJOY15"}, + {KEY_DBLJOY1+15, "DBLJOY16"}, + {KEY_DBLJOY1+16, "DBLJOY17"}, + {KEY_DBLJOY1+17, "DBLJOY18"}, + {KEY_DBLJOY1+18, "DBLJOY19"}, + {KEY_DBLJOY1+19, "DBLJOY20"}, + {KEY_DBLJOY1+20, "DBLJOY21"}, + {KEY_DBLJOY1+21, "DBLJOY22"}, + {KEY_DBLJOY1+22, "DBLJOY23"}, + {KEY_DBLJOY1+23, "DBLJOY24"}, + {KEY_DBLJOY1+24, "DBLJOY25"}, + {KEY_DBLJOY1+25, "DBLJOY26"}, + {KEY_DBLJOY1+26, "DBLJOY27"}, + {KEY_DBLJOY1+27, "DBLJOY28"}, + {KEY_DBLJOY1+28, "DBLJOY29"}, + {KEY_DBLJOY1+29, "DBLJOY30"}, + {KEY_DBLJOY1+30, "DBLJOY31"}, + {KEY_DBLJOY1+31, "DBLJOY32"}, +#endif + {KEY_DBLHAT1+0, "DBLHATUP"}, + {KEY_DBLHAT1+1, "DBLHATDOWN"}, + {KEY_DBLHAT1+2, "DBLHATLEFT"}, + {KEY_DBLHAT1+3, "DBLHATRIGHT"}, +#if !defined (_XBOX) && !defined (_PSP) && !defined (_WII) + {KEY_DBLHAT1+4, "DBLHATUP2"}, + {KEY_DBLHAT1+5, "DBLHATDOWN2"}, + {KEY_DBLHAT1+6, "DBLHATLEFT2"}, + {KEY_DBLHAT1+7, "DBLHATRIGHT2"}, +#ifndef _arch_dreamcast + {KEY_DBLHAT1+8, "DBLHATUP3"}, + {KEY_DBLHAT1+9, "DBLHATDOWN3"}, + {KEY_DBLHAT1+10, "DBLHATLEFT3"}, + {KEY_DBLHAT1+11, "DBLHATRIGHT3"}, + {KEY_DBLHAT1+12, "DBLHATUP4"}, + {KEY_DBLHAT1+13, "DBLHATDOWN4"}, + {KEY_DBLHAT1+14, "DBLHATLEFT4"}, + {KEY_DBLHAT1+15, "DBLHATRIGHT4"}, +#endif +#endif + +#ifdef DC + {KEY_2JOY1+0, "SEC_JOYC"}, + {KEY_2JOY1+1, "SEC_JOYB"}, + {KEY_2JOY1+2, "SEC_JOYA"}, + {KEY_2JOY1+3, "SEC_JOYS"}, + {KEY_2JOY1+4, "SEC_JOYZ"}, + {KEY_2JOY1+5, "SEC_JOYY"}, + {KEY_2JOY1+6, "SEC_JOYX"}, + {KEY_2JOY1+7, "SEC_JOYD"}, +#elif defined (_XBOX) + {KEY_2JOY1+0, "SEC_JOYA"}, + {KEY_2JOY1+1, "SEC_JOYB"}, + {KEY_2JOY1+2, "SEC_JOYX"}, + {KEY_2JOY1+3, "SEC_JOYY"}, + {KEY_2JOY1+4, "SEC_JOYG"}, + {KEY_2JOY1+5, "SEC_JOYW"}, + {KEY_2JOY1+6, "SEC_JOYL"}, + {KEY_2JOY1+7, "SEC_JOYR"}, + {KEY_2JOY1+8, "SEC_JOYS"}, + {KEY_2JOY1+9, "SEC_JOYN"}, + {KEY_2JOY1+10,"SEC_JOYW"}, + {KEY_2JOY1+11,"SEC_JOYE"}, +#define NOMOREJOYBTN_2S +#elif defined (_PSP) + {KEY_2JOY1+0, "SEC_TRIANGLE"}, + {KEY_2JOY1+1, "SEC_CIRCLE" }, + {KEY_2JOY1+2, "SEC_CROSS" }, + {KEY_2JOY1+3, "SEC_SQUARE" }, + {KEY_2JOY1+4, "SEC_LTRIGGER"}, + {KEY_2JOY1+5, "SEC_RTRIGGER"}, + {KEY_2JOY1+6, "SEC_SELECT" }, + {KEY_2JOY1+7, "SEC_START" }, + {KEY_2JOY1+8, "SEC_HOME" }, + {KEY_2JOY1+9, "SEC_HOLD" }, +#define NOMOREJOYBTN_2S +#elif defined (WMINPUT) + {KEY_2JOY1+0, "SEC_JOYB"}, + {KEY_2JOY1+1, "SEC_JOYA"}, + {KEY_2JOY1+2, "SEC_JOYUP"}, + {KEY_2JOY1+3, "SEC_JOYDOWN"}, + {KEY_2JOY1+4, "SEC_JOYLEFT"}, + {KEY_2JOY1+5, "SEC_JOYRIGHT"}, + {KEY_2JOY1+6, "SEC_JOYAA"}, + {KEY_2JOY1+7, "SEC_JOYBB"}, + {KEY_2JOY1+8, "SEC_JOYCC"}, + {KEY_2JOY1+9, "SEC_JOYXX"}, + {KEY_2JOY1+10, "SEC_JOYYY"}, + {KEY_2JOY1+11, "SEC_JOYZZ"}, + {KEY_2JOY1+12, "SEC_JOYL"}, + {KEY_2JOY1+13, "SEC_JOYR"}, + {KEY_2JOY1+14, "SEC_JOYZL"}, + {KEY_2JOY1+15, "SEC_JOYZR"}, + {KEY_2JOY1+16, "SEC_JOYSELECT"}, + {KEY_2JOY1+17, "SEC_JOYSTART"}, + {KEY_2JOY1+18, "SEC_JOYHOME"}, + {KEY_2JOY1+19, "SEC_JOYMINUS"}, + {KEY_2JOY1+20, "SEC_JOYPLUS"}, + {KEY_2JOY1+21, "SEC_JOY_1"}, + {KEY_2JOY1+22, "SEC_JOY_2"}, + {KEY_2JOY1+23, "SEC_JOY24"}, + {KEY_2JOY1+24, "SEC_JOY25"}, + {KEY_2JOY1+25, "SEC_JOY26"}, + {KEY_2JOY1+26, "SEC_JOY27"}, + {KEY_2JOY1+27, "SEC_JOY28"}, + {KEY_2JOY1+28, "SEC_JOY29"}, + {KEY_2JOY1+29, "SEC_JOY30"}, + {KEY_2JOY1+30, "SEC_JOY31"}, + {KEY_2JOY1+31, "SEC_JOY32"}, +#define NOMOREJOYBTN_2S +#elif defined (_WII) + {KEY_2JOY1+0, "SEC_JOYA"}, + {KEY_2JOY1+1, "SEC_JOYB"}, + {KEY_2JOY1+2, "SEC_JOY1"}, + {KEY_2JOY1+3, "SEC_JOY2"}, + {KEY_2JOY1+4, "SEC_JOYMINUS"}, + {KEY_2JOY1+5, "SEC_JOYPLUS"}, + {KEY_2JOY1+6, "SEC_JOYHOME"}, + {KEY_2JOY1+7, "SEC_JOYZ"}, + {KEY_2JOY1+8, "SEC_JOYC"}, + {KEY_2JOY1+9, "SEC_JOYA_CC"}, + {KEY_2JOY1+10, "SEC_JOYB_CC"}, + {KEY_2JOY1+11, "SEC_JOYX"}, + {KEY_2JOY1+12, "SEC_JOYY"}, + {KEY_2JOY1+13, "SEC_JOYL"}, + {KEY_2JOY1+14, "SEC_JOYR"}, + {KEY_2JOY1+15, "SEC_JOYZL"}, + {KEY_2JOY1+16, "SEC_JOYZR"}, + {KEY_2JOY1+17, "SEC_JOYMINUS_CC"}, + {KEY_2JOY1+18, "SEC_JOYHPLUS_CC"}, + {KEY_2JOY1+19, "SEC_JOYMHOME_CC"}, +#define NOMOREJOYBTN_2S +#else + {KEY_2JOY1+0, "SEC_JOY1"}, + {KEY_2JOY1+1, "SEC_JOY2"}, + {KEY_2JOY1+2, "SEC_JOY3"}, + {KEY_2JOY1+3, "SEC_JOY4"}, + {KEY_2JOY1+4, "SEC_JOY5"}, + {KEY_2JOY1+5, "SEC_JOY6"}, + {KEY_2JOY1+6, "SEC_JOY7"}, + {KEY_2JOY1+7, "SEC_JOY8"}, +#endif +#if !defined (_arch_dreamcast) && !defined (NOMOREJOYBTN_2S) + // we use up to 32 buttons in DirectInput + {KEY_2JOY1+8, "SEC_JOY9"}, + {KEY_2JOY1+9, "SEC_JOY10"}, + {KEY_2JOY1+10, "SEC_JOY11"}, + {KEY_2JOY1+11, "SEC_JOY12"}, + {KEY_2JOY1+12, "SEC_JOY13"}, + {KEY_2JOY1+13, "SEC_JOY14"}, + {KEY_2JOY1+14, "SEC_JOY15"}, + {KEY_2JOY1+15, "SEC_JOY16"}, + {KEY_2JOY1+16, "SEC_JOY17"}, + {KEY_2JOY1+17, "SEC_JOY18"}, + {KEY_2JOY1+18, "SEC_JOY19"}, + {KEY_2JOY1+19, "SEC_JOY20"}, + {KEY_2JOY1+20, "SEC_JOY21"}, + {KEY_2JOY1+21, "SEC_JOY22"}, + {KEY_2JOY1+22, "SEC_JOY23"}, + {KEY_2JOY1+23, "SEC_JOY24"}, + {KEY_2JOY1+24, "SEC_JOY25"}, + {KEY_2JOY1+25, "SEC_JOY26"}, + {KEY_2JOY1+26, "SEC_JOY27"}, + {KEY_2JOY1+27, "SEC_JOY28"}, + {KEY_2JOY1+28, "SEC_JOY29"}, + {KEY_2JOY1+29, "SEC_JOY30"}, + {KEY_2JOY1+30, "SEC_JOY31"}, + {KEY_2JOY1+31, "SEC_JOY32"}, +#endif + // the DOS version uses Allegro's joystick support + {KEY_2HAT1+0, "SEC_HATUP"}, + {KEY_2HAT1+1, "SEC_HATDOWN"}, + {KEY_2HAT1+2, "SEC_HATLEFT"}, + {KEY_2HAT1+3, "SEC_HATRIGHT"}, +#if !defined (_XBOX) && !defined (_PSP) && !defined (_WII) + {KEY_2HAT1+4, "SEC_HATUP2"}, + {KEY_2HAT1+5, "SEC_HATDOWN2"}, + {KEY_2HAT1+6, "SEC_HATLEFT2"}, + {KEY_2HAT1+7, "SEC_HATRIGHT2"}, +#ifndef _arch_dreamcast + {KEY_2HAT1+8, "SEC_HATUP3"}, + {KEY_2HAT1+9, "SEC_HATDOWN3"}, + {KEY_2HAT1+10, "SEC_HATLEFT3"}, + {KEY_2HAT1+11, "SEC_HATRIGHT3"}, + {KEY_2HAT1+12, "SEC_HATUP4"}, + {KEY_2HAT1+13, "SEC_HATDOWN4"}, + {KEY_2HAT1+14, "SEC_HATLEFT4"}, + {KEY_2HAT1+15, "SEC_HATRIGHT4"}, +#endif +#endif + +#ifdef DC + {KEY_DBL2JOY1+0, "DBLSEC_JOYC"}, + {KEY_DBL2JOY1+1, "DBLSEC_JOYB"}, + {KEY_DBL2JOY1+2, "DBLSEC_JOYA"}, + {KEY_DBL2JOY1+3, "DBLSEC_JOYS"}, + {KEY_DBL2JOY1+4, "DBLSEC_JOYZ"}, + {KEY_DBL2JOY1+5, "DBLSEC_JOYY"}, + {KEY_DBL2JOY1+6, "DBLSEC_JOYX"}, + {KEY_DBL2JOY1+7, "DBLSEC_JOYD"}, +#elif defined (_XBOX) + {KEY_DBL2JOY1+0, "DBLSEC_JOYA"}, + {KEY_DBL2JOY1+1, "DBLSEC_JOYB"}, + {KEY_DBL2JOY1+2, "DBLSEC_JOYX"}, + {KEY_DBL2JOY1+3, "DBLSEC_JOYY"}, + {KEY_DBL2JOY1+4, "DBLSEC_JOYG"}, + {KEY_DBL2JOY1+5, "DBLSEC_JOYW"}, + {KEY_DBL2JOY1+6, "DBLSEC_JOYL"}, + {KEY_DBL2JOY1+7, "DBLSEC_JOYR"}, + {KEY_DBL2JOY1+8, "DBLSEC_JOYS"}, + {KEY_DBL2JOY1+9, "DBLSEC_JOYN"}, + {KEY_DBL2JOY1+10,"DBLSEC_JOYW"}, + {KEY_DBL2JOY1+11,"DBLSEC_JOYE"}, +#define NOMOREJOYBTN_2DBL +#elif defined (_PSP) + {KEY_DBL2JOY1+0, "DBLSEC_TRIANGLE"}, + {KEY_DBL2JOY1+1, "DBLSEC_CIRCLE" }, + {KEY_DBL2JOY1+2, "DBLSEC_CROSS" }, + {KEY_DBL2JOY1+3, "DBLSEC_SQUARE" }, + {KEY_DBL2JOY1+4, "DBLSEC_LTRIGGER"}, + {KEY_DBL2JOY1+5, "DBLSEC_RTRIGGER"}, + {KEY_DBL2JOY1+6, "DBLSEC_SELECT" }, + {KEY_DBL2JOY1+7, "DBLSEC_START" }, + {KEY_DBL2JOY1+8, "DBLSEC_HOME" }, + {KEY_DBL2JOY1+9, "DBLSEC_HOLD" }, +#define NOMOREJOYBTN_2DBL +#elif defined (WMINPUT) + {KEY_DBL2JOY1+0, "DBLSEC_JOYB"}, + {KEY_DBL2JOY1+1, "DBLSEC_JOYA"}, + {KEY_DBL2JOY1+2, "DBLSEC_JOYUP"}, + {KEY_DBL2JOY1+3, "DBLSEC_JOYDOWN"}, + {KEY_DBL2JOY1+4, "DBLSEC_JOYLEFT"}, + {KEY_DBL2JOY1+5, "DBLSEC_JOYRIGHT"}, + {KEY_DBL2JOY1+6, "DBLSEC_JOYAA"}, + {KEY_DBL2JOY1+7, "DBLSEC_JOYBB"}, + {KEY_DBL2JOY1+8, "DBLSEC_JOYCC"}, + {KEY_DBL2JOY1+9, "DBLSEC_JOYXX"}, + {KEY_DBL2JOY1+10, "DBLSEC_JOYYY"}, + {KEY_DBL2JOY1+11, "DBLSEC_JOYZZ"}, + {KEY_DBL2JOY1+12, "DBLSEC_JOYL"}, + {KEY_DBL2JOY1+13, "DBLSEC_JOYR"}, + {KEY_DBL2JOY1+14, "DBLSEC_JOYZL"}, + {KEY_DBL2JOY1+15, "DBLSEC_JOYZR"}, + {KEY_DBL2JOY1+16, "DBLSEC_JOYSELECT"}, + {KEY_DBL2JOY1+17, "DBLSEC_JOYSTART"}, + {KEY_DBL2JOY1+18, "DBLSEC_JOYHOME"}, + {KEY_DBL2JOY1+19, "DBLSEC_JOYMINUS"}, + {KEY_DBL2JOY1+20, "DBLSEC_JOYPLUS"}, + {KEY_DBL2JOY1+21, "DBLSEC_JOY_1"}, + {KEY_DBL2JOY1+22, "DBLSEC_JOY_2"}, + {KEY_DBL2JOY1+23, "DBLSEC_JOY24"}, + {KEY_DBL2JOY1+24, "DBLSEC_JOY25"}, + {KEY_DBL2JOY1+25, "DBLSEC_JOY26"}, + {KEY_DBL2JOY1+26, "DBLSEC_JOY27"}, + {KEY_DBL2JOY1+27, "DBLSEC_JOY28"}, + {KEY_DBL2JOY1+28, "DBLSEC_JOY29"}, + {KEY_DBL2JOY1+29, "DBLSEC_JOY30"}, + {KEY_DBL2JOY1+30, "DBLSEC_JOY31"}, + {KEY_DBL2JOY1+31, "DBLSEC_JOY32"}, +#define NOMOREJOYBTN_2SDBL +#elif defined (_WII) + {KEY_DBL2JOY1+0, "DBLSEC_JOYA"}, + {KEY_DBL2JOY1+1, "DBLSEC_JOYB"}, + {KEY_DBL2JOY1+2, "DBLSEC_JOY1"}, + {KEY_DBL2JOY1+3, "DBLSEC_JOY2"}, + {KEY_DBL2JOY1+4, "DBLSEC_JOYMINUS"}, + {KEY_DBL2JOY1+5, "DBLSEC_JOYPLUS"}, + {KEY_DBL2JOY1+6, "DBLSEC_JOYHOME"}, + {KEY_DBL2JOY1+7, "DBLSEC_JOYZ"}, + {KEY_DBL2JOY1+8, "DBLSEC_JOYC"}, + {KEY_DBL2JOY1+9, "DBLSEC_JOYA_CC"}, + {KEY_DBL2JOY1+10, "DBLSEC_JOYB_CC"}, + {KEY_DBL2JOY1+11, "DBLSEC_JOYX"}, + {KEY_DBL2JOY1+12, "DBLSEC_JOYY"}, + {KEY_DBL2JOY1+13, "DBLSEC_JOYL"}, + {KEY_DBL2JOY1+14, "DBLSEC_JOYR"}, + {KEY_DBL2JOY1+15, "DBLSEC_JOYZL"}, + {KEY_DBL2JOY1+16, "DBLSEC_JOYZR"}, + {KEY_DBL2JOY1+17, "DBLSEC_JOYMINUS_CC"}, + {KEY_DBL2JOY1+18, "DBLSEC_JOYHPLUS_CC"}, + {KEY_DBL2JOY1+19, "DBLSEC_JOYMHOME_CC"}, +#define NOMOREJOYBTN_2DBL +#else + {KEY_DBL2JOY1+0, "DBLSEC_JOY1"}, + {KEY_DBL2JOY1+1, "DBLSEC_JOY2"}, + {KEY_DBL2JOY1+2, "DBLSEC_JOY3"}, + {KEY_DBL2JOY1+3, "DBLSEC_JOY4"}, + {KEY_DBL2JOY1+4, "DBLSEC_JOY5"}, + {KEY_DBL2JOY1+5, "DBLSEC_JOY6"}, + {KEY_DBL2JOY1+6, "DBLSEC_JOY7"}, + {KEY_DBL2JOY1+7, "DBLSEC_JOY8"}, +#endif +#if !defined (_arch_dreamcast) && !defined (NOMOREJOYBTN_2DBL) + {KEY_DBL2JOY1+8, "DBLSEC_JOY9"}, + {KEY_DBL2JOY1+9, "DBLSEC_JOY10"}, + {KEY_DBL2JOY1+10, "DBLSEC_JOY11"}, + {KEY_DBL2JOY1+11, "DBLSEC_JOY12"}, + {KEY_DBL2JOY1+12, "DBLSEC_JOY13"}, + {KEY_DBL2JOY1+13, "DBLSEC_JOY14"}, + {KEY_DBL2JOY1+14, "DBLSEC_JOY15"}, + {KEY_DBL2JOY1+15, "DBLSEC_JOY16"}, + {KEY_DBL2JOY1+16, "DBLSEC_JOY17"}, + {KEY_DBL2JOY1+17, "DBLSEC_JOY18"}, + {KEY_DBL2JOY1+18, "DBLSEC_JOY19"}, + {KEY_DBL2JOY1+19, "DBLSEC_JOY20"}, + {KEY_DBL2JOY1+20, "DBLSEC_JOY21"}, + {KEY_DBL2JOY1+21, "DBLSEC_JOY22"}, + {KEY_DBL2JOY1+22, "DBLSEC_JOY23"}, + {KEY_DBL2JOY1+23, "DBLSEC_JOY24"}, + {KEY_DBL2JOY1+24, "DBLSEC_JOY25"}, + {KEY_DBL2JOY1+25, "DBLSEC_JOY26"}, + {KEY_DBL2JOY1+26, "DBLSEC_JOY27"}, + {KEY_DBL2JOY1+27, "DBLSEC_JOY28"}, + {KEY_DBL2JOY1+28, "DBLSEC_JOY29"}, + {KEY_DBL2JOY1+29, "DBLSEC_JOY30"}, + {KEY_DBL2JOY1+30, "DBLSEC_JOY31"}, + {KEY_DBL2JOY1+31, "DBLSEC_JOY32"}, +#endif + {KEY_DBL2HAT1+0, "DBLSEC_HATUP"}, + {KEY_DBL2HAT1+1, "DBLSEC_HATDOWN"}, + {KEY_DBL2HAT1+2, "DBLSEC_HATLEFT"}, + {KEY_DBL2HAT1+3, "DBLSEC_HATRIGHT"}, +#if !defined (_XBOX) && !defined (_PSP) && !defined (_WII) + {KEY_DBL2HAT1+4, "DBLSEC_HATUP2"}, + {KEY_DBL2HAT1+5, "DBLSEC_HATDOWN2"}, + {KEY_DBL2HAT1+6, "DBLSEC_HATLEFT2"}, + {KEY_DBL2HAT1+7, "DBLSEC_HATRIGHT2"}, +#ifndef _arch_dreamcast + {KEY_DBL2HAT1+8, "DBLSEC_HATUP3"}, + {KEY_DBL2HAT1+9, "DBLSEC_HATDOWN3"}, + {KEY_DBL2HAT1+10, "DBLSEC_HATLEFT3"}, + {KEY_DBL2HAT1+11, "DBLSEC_HATRIGHT3"}, + {KEY_DBL2HAT1+12, "DBLSEC_HATUP4"}, + {KEY_DBL2HAT1+13, "DBLSEC_HATDOWN4"}, + {KEY_DBL2HAT1+14, "DBLSEC_HATLEFT4"}, + {KEY_DBL2HAT1+15, "DBLSEC_HATRIGHT4"}, +#endif +#endif + +}; + +static const char *gamecontrolname[num_gamecontrols] = +{ + "nothing", // a key/button mapped to gc_null has no effect + "forward", + "backward", + "strafeleft", + "straferight", + "turnleft", + "turnright", + "weaponnext", + "weaponprev", + "weapon1", + "weapon2", + "weapon3", + "weapon4", + "weapon5", + "weapon6", + "weapon7", + "weapon8", + "weapon9", + "weapon10", + "fire", + "firenormal", + "tossflag", + "use", + "camtoggle", + "camleft", + "camright", + "camreset", + "lookup", + "lookdown", + "centerview", + "mouseaiming", + "talkkey", + "teamtalkkey", + "scores", + "jump", + "console", + "pause", +}; + +#define NUMKEYNAMES (sizeof (keynames)/sizeof (keyname_t)) + +// +// Detach any keys associated to the given game control +// - pass the pointer to the gamecontrol table for the player being edited +void G_ClearControlKeys(INT32 (*setupcontrols)[2], INT32 control) +{ + setupcontrols[control][0] = KEY_NULL; + setupcontrols[control][1] = KEY_NULL; +} + +// +// Returns the name of a key (or virtual key for mouse and joy) +// the input value being an keynum +// +const char *G_KeynumToString(INT32 keynum) +{ + static char keynamestr[8]; + + UINT32 j; + + // return a string with the ascii char if displayable + if (keynum > ' ' && keynum <= 'z' && keynum != KEY_CONSOLE) + { + keynamestr[0] = (char)keynum; + keynamestr[1] = '\0'; + return keynamestr; + } + + // find a description for special keys + for (j = 0; j < NUMKEYNAMES; j++) + if (keynames[j].keynum == keynum) + return keynames[j].name; + + // create a name for unknown keys + sprintf(keynamestr, "KEY%d", keynum); + return keynamestr; +} + +INT32 G_KeyStringtoNum(const char *keystr) +{ + UINT32 j; + + if (!keystr[1] && keystr[0] > ' ' && keystr[0] <= 'z') + return keystr[0]; + + for (j = 0; j < NUMKEYNAMES; j++) + if (!stricmp(keynames[j].name, keystr)) + return keynames[j].keynum; + + if (strlen(keystr) > 3) + return atoi(&keystr[3]); + + return 0; +} + +#ifdef DC +void G_Controldefault(void) +{ + gamecontrol[gc_forward ][0] = KEY_HAT1+0; //Up + gamecontrol[gc_forward ][1] = KEY_UPARROW; + gamecontrol[gc_backward ][0] = KEY_HAT1+1; //Down + gamecontrol[gc_backward ][1] = KEY_DOWNARROW; + //gamecontrol[gc_straferight][0] = '['; + //gamecontrol[gc_strafeleft ][0] = ']'; + gamecontrol[gc_turnleft ][0] = KEY_HAT1+2; //Left + gamecontrol[gc_turnleft ][1] = KEY_LEFTARROW; + gamecontrol[gc_turnright ][0] = KEY_HAT1+3; //Right + gamecontrol[gc_turnright ][1] = KEY_RIGHTARROW; + gamecontrol[gc_weaponnext ][0] = ']'; + gamecontrol[gc_weaponprev ][0] = '['; + gamecontrol[gc_fire ][0] = KEY_JOY1+6; //X + gamecontrol[gc_fire ][1] = KEY_RCTRL; + gamecontrol[gc_firenormal ][0] = KEY_JOY1+5; //Y + gamecontrol[gc_firenormal ][1] = ';'; + gamecontrol[gc_tossflag ][0] = '\''; + gamecontrol[gc_use ][0] = KEY_JOY1+1; //B + gamecontrol[gc_use ][1] = '.'; + gamecontrol[gc_camtoggle ][1] = ','; + gamecontrol[gc_camleft ][0] = 'o'; + gamecontrol[gc_camright ][0] = 'p'; + gamecontrol[gc_camreset ][0] = 'c'; + gamecontrol[gc_lookup ][0] = KEY_PGUP; + gamecontrol[gc_lookdown ][0] = KEY_PGDN; + gamecontrol[gc_centerview ][0] = KEY_END; + gamecontrol[gc_mouseaiming][0] = 's'; + gamecontrol[gc_talkkey ][0] = 't'; + gamecontrol[gc_teamkey ][0] = 'y'; + gamecontrol[gc_scores ][0] = KEY_TAB; + gamecontrol[gc_jump ][0] = KEY_JOY1+2; //A + gamecontrol[gc_jump ][1] = '/'; + gamecontrol[gc_console ][0] = KEY_CONSOLE; + gamecontrol[gc_console ][1] = KEY_F5; + //gamecontrolbis + gamecontrolbis[gc_forward ][0] = KEY_2HAT1+0; + gamecontrolbis[gc_forward ][1] = 'w'; + gamecontrolbis[gc_backward ][0] = KEY_2HAT1+1; + gamecontrolbis[gc_backward ][1] = 's'; + gamecontrolbis[gc_turnleft ][0] = KEY_2HAT1+2; + gamecontrolbis[gc_turnleft ][1] = 'a'; + gamecontrolbis[gc_turnright ][0] = KEY_2HAT1+3; + gamecontrolbis[gc_turnright ][1] = 'd'; + gamecontrolbis[gc_weaponnext][0] = 't'; + gamecontrolbis[gc_weaponprev][0] = 'r'; + gamecontrolbis[gc_fire ][0] = KEY_2JOY1+6; //X + gamecontrolbis[gc_firenormal][0] = KEY_2JOY1+5; //Y + gamecontrolbis[gc_use ][0] = KEY_2JOY1+1; //B + gamecontrolbis[gc_jump ][0] = KEY_2JOY1+2; //A + //gamecontrolbis[gc_straferight][0] = 'x'; + //gamecontrolbis[gc_strafeleft ][0] = 'z'; +} +#elif defined (_PSP) +void G_Controldefault(void) +{ + gamecontrol[gc_forward ][0] = KEY_HAT1+0; // Up + gamecontrol[gc_backward ][0] = KEY_HAT1+1; // Down + gamecontrol[gc_turnleft ][0] = KEY_HAT1+2; // Left + gamecontrol[gc_turnright ][0] = KEY_HAT1+3; // Right + gamecontrol[gc_strafeleft ][0] = KEY_JOY1+4; // L + gamecontrol[gc_straferight][0] = KEY_JOY1+5; // R + gamecontrol[gc_tossflag ][0] = KEY_JOY1+0; // Triangle + gamecontrol[gc_use ][0] = KEY_JOY1+1; // Circle + gamecontrol[gc_camtoggle ][0] = KEY_JOY1+6; // Select + gamecontrol[gc_camreset ][0] = KEY_JOY1+3; // Square + gamecontrol[gc_centerview ][0] = KEY_JOY1+9; // Hold + gamecontrol[gc_pause ][0] = KEY_JOY1+8; // Start + gamecontrol[gc_jump ][0] = KEY_JOY1+2; // Cross +} +#elif defined (GP2X) +void G_Controldefault(void) +{ + gamecontrol[gc_fire ][0] = KEY_JOY1+0; //A + gamecontrol[gc_forward ][0] = KEY_JOY1+1; //Y + gamecontrol[gc_jump ][0] = KEY_JOY1+2; //B + gamecontrol[gc_use ][0] = KEY_JOY1+3; //X + gamecontrol[gc_strafeleft ][0] = KEY_JOY1+4; //L + gamecontrol[gc_straferight][0] = KEY_JOY1+5; //R + gamecontrol[gc_lookup ][0] = KEY_JOY1+6; //U + gamecontrol[gc_lookdown ][0] = KEY_JOY1+7; //D + gamecontrol[gc_pause ][0] = KEY_JOY1+8; //S +} +#elif defined (_NDS) +void G_Controldefault(void) +{ + gamecontrol[gc_fire ][0] = KEY_JOY1+2; //X + gamecontrol[gc_forward ][0] = KEY_UPARROW; + gamecontrol[gc_backward ][0] = KEY_DOWNARROW; + gamecontrol[gc_jump ][0] = KEY_JOY1+0; //A + gamecontrol[gc_use ][0] = KEY_JOY1+3; //Y + gamecontrol[gc_strafeleft ][0] = KEY_JOY1+4; //L + gamecontrol[gc_straferight][0] = KEY_JOY1+5; //R + gamecontrol[gc_turnleft ][0] = KEY_LEFTARROW; + gamecontrol[gc_turnright ][0] = KEY_RIGHTARROW; + gamecontrol[gc_pause ][0] = KEY_JOY1+6; //Start + gamecontrol[gc_weaponnext ][0] = KEY_JOY1+7; //Select +} +#else +void G_Controldefault(void) +{ + gamecontrol[gc_forward ][0] = KEY_UPARROW; + gamecontrol[gc_forward ][1] = 'w'; + gamecontrol[gc_backward ][0] = KEY_DOWNARROW; + gamecontrol[gc_backward ][1] = 's'; + gamecontrol[gc_strafeleft ][0] = 'a'; + gamecontrol[gc_straferight][0] = 'd'; + gamecontrol[gc_turnleft ][0] = KEY_LEFTARROW; + gamecontrol[gc_turnright ][0] = KEY_RIGHTARROW; + gamecontrol[gc_weaponnext ][0] = 'e'; + gamecontrol[gc_weaponprev ][0] = 'q'; + gamecontrol[gc_wepslot1 ][0] = '1'; + gamecontrol[gc_wepslot2 ][0] = '2'; + gamecontrol[gc_wepslot3 ][0] = '3'; + gamecontrol[gc_wepslot4 ][0] = '4'; + gamecontrol[gc_wepslot5 ][0] = '5'; + gamecontrol[gc_wepslot6 ][0] = '6'; + gamecontrol[gc_wepslot7 ][0] = '7'; + gamecontrol[gc_wepslot8 ][0] = '8'; + gamecontrol[gc_wepslot9 ][0] = '9'; + gamecontrol[gc_wepslot10 ][0] = '0'; + gamecontrol[gc_fire ][0] = KEY_RCTRL; + gamecontrol[gc_fire ][1] = KEY_MOUSE1+0; + gamecontrol[gc_firenormal ][0] = 'c'; + gamecontrol[gc_tossflag ][0] = '\''; + gamecontrol[gc_use ][0] = 'x'; + gamecontrol[gc_camtoggle ][0] = 'v'; + gamecontrol[gc_camleft ][0] = '['; + gamecontrol[gc_camright ][0] = ']'; + gamecontrol[gc_camreset ][0] = 'r'; + gamecontrol[gc_lookup ][0] = KEY_PGUP; + gamecontrol[gc_lookdown ][0] = KEY_PGDN; + gamecontrol[gc_centerview ][0] = KEY_END; + gamecontrol[gc_talkkey ][0] = 't'; + gamecontrol[gc_teamkey ][0] = 'y'; + gamecontrol[gc_scores ][0] = KEY_TAB; + gamecontrol[gc_jump ][0] = 'z'; + gamecontrol[gc_jump ][1] = KEY_MOUSE1+1; + gamecontrol[gc_console ][0] = KEY_CONSOLE; + gamecontrol[gc_pause ][0] = KEY_PAUSE; +#ifdef WMINPUT + gamecontrol[gc_forward ][0] = KEY_JOY1+02; //UP + gamecontrol[gc_backward ][0] = KEY_JOY1+03; //DOWN + gamecontrol[gc_turnleft ][0] = KEY_JOY1+04; //LEFT + gamecontrol[gc_turnright ][0] = KEY_JOY1+05; //RIGHT + gamecontrol[gc_weaponnext ][0] = KEY_JOY1+10; //y + gamecontrol[gc_weaponprev ][0] = KEY_JOY1+9; //x + gamecontrol[gc_fire ][0] = KEY_JOY1+12; //L + gamecontrol[gc_firenormal ][0] = KEY_JOY1+13; //R + gamecontrol[gc_use ][0] = KEY_JOY1+00; //B + gamecontrol[gc_use ][1] = KEY_JOY1+07; //b + gamecontrol[gc_jump ][0] = KEY_JOY1+01; //A + gamecontrol[gc_jump ][1] = KEY_JOY1+06; //a + gamecontrol[gc_pause ][0] = KEY_JOY1+18; //Home + gamecontrolbis[gc_forward ][0] = KEY_2JOY1+02; //UP + gamecontrolbis[gc_backward ][0] = KEY_2JOY1+03; //DOWN + gamecontrolbis[gc_turnleft ][0] = KEY_2JOY1+04; //LEFT + gamecontrolbis[gc_turnright ][0] = KEY_2JOY1+05; //RIGHT + gamecontrolbis[gc_weaponnext ][0] = KEY_2JOY1+10; //y + gamecontrolbis[gc_weaponprev ][0] = KEY_2JOY1+9; //x + gamecontrolbis[gc_fire ][0] = KEY_2JOY1+12; //L + gamecontrolbis[gc_firenormal ][0] = KEY_2JOY1+13; //R + gamecontrolbis[gc_use ][0] = KEY_2JOY1+00; //B + gamecontrolbis[gc_use ][1] = KEY_2JOY1+07; //b + gamecontrolbis[gc_jump ][0] = KEY_2JOY1+01; //A + gamecontrolbis[gc_jump ][1] = KEY_2JOY1+06; //a + gamecontrolbis[gc_pause ][0] = KEY_2JOY1+18; //Home +#endif +#ifdef _WII + gamecontrol[gc_forward ][1] = KEY_HAT1+00; //UP + gamecontrol[gc_backward ][1] = KEY_HAT1+01; //DOWN + gamecontrol[gc_straferight][1] = KEY_JOY1+16; //ZR + gamecontrol[gc_strafeleft ][1] = KEY_JOY1+15; //ZL + gamecontrol[gc_turnleft ][1] = KEY_HAT1+02; //LEFT + gamecontrol[gc_turnright ][1] = KEY_HAT1+03; //RIGHT + gamecontrol[gc_weaponnext ][1] = KEY_JOY1+11; //x + gamecontrol[gc_fire ][0] = KEY_JOY1+12; //y + gamecontrol[gc_fire ][1] = KEY_JOY1+01; //B + gamecontrol[gc_firenormal ][0] = KEY_JOY1+13; //L + gamecontrol[gc_firenormal ][1] = KEY_JOY1+00; //A + gamecontrol[gc_tossflag ][1] = KEY_JOY1+17; //Plus CC + gamecontrol[gc_use ][0] = KEY_JOY1+9; //a + gamecontrol[gc_use ][1] = KEY_JOY1+02; //1 + gamecontrol[gc_centerview ][1] = KEY_JOY1+14; //R + gamecontrol[gc_scores ][0] = KEY_JOY1+04; //Minus + gamecontrol[gc_scores ][1] = KEY_JOY1+18; //Minus + gamecontrol[gc_jump ][0] = KEY_JOY1+10; //b + gamecontrol[gc_jump ][1] = KEY_JOY1+3; //2 + gamecontrol[gc_pause ][0] = KEY_JOY1+06; //Home + gamecontrol[gc_pause ][1] = KEY_JOY1+19; //Home + gamecontrolbis[gc_forward ][1] = KEY_2HAT1+00; //UP + gamecontrolbis[gc_backward ][1] = KEY_2HAT1+01; //DOWN + gamecontrolbis[gc_straferight][1] = KEY_2JOY1+16; //ZR + gamecontrolbis[gc_strafeleft ][1] = KEY_2JOY1+15; //ZL + gamecontrolbis[gc_turnleft ][1] = KEY_2HAT1+02; //LEFT + gamecontrolbis[gc_turnright ][1] = KEY_2HAT1+03; //RIGHT + gamecontrolbis[gc_weaponnext ][1] = KEY_2JOY1+11; //x + gamecontrolbis[gc_fire ][0] = KEY_2JOY1+12; //y + gamecontrolbis[gc_fire ][1] = KEY_2JOY1+01; //B + gamecontrolbis[gc_firenormal ][0] = KEY_2JOY1+13; //L + gamecontrolbis[gc_firenormal ][1] = KEY_2JOY1+00; //A + gamecontrolbis[gc_tossflag ][1] = KEY_2JOY1+17; //Plus CC + gamecontrolbis[gc_use ][0] = KEY_2JOY1+9; //a + gamecontrolbis[gc_use ][1] = KEY_2JOY1+02; //1 + gamecontrolbis[gc_centerview ][1] = KEY_2JOY1+14; //R + gamecontrolbis[gc_scores ][0] = KEY_2JOY1+04; //Minus + gamecontrolbis[gc_scores ][1] = KEY_2JOY1+18; //Minus + gamecontrolbis[gc_jump ][0] = KEY_2JOY1+10; //b + gamecontrolbis[gc_jump ][1] = KEY_2JOY1+3; //2 + gamecontrolbis[gc_pause ][0] = KEY_2JOY1+06; //Home + gamecontrolbis[gc_pause ][1] = KEY_2JOY1+19; //Home +#endif +} +#endif + +void G_SaveKeySetting(FILE *f) +{ + INT32 i; + + for (i = 1; i < num_gamecontrols; i++) + { + fprintf(f, "setcontrol \"%s\" \"%s\"", gamecontrolname[i], + G_KeynumToString(gamecontrol[i][0])); + + if (gamecontrol[i][1]) + fprintf(f, " \"%s\"\n", G_KeynumToString(gamecontrol[i][1])); + else + fprintf(f, "\n"); + } + + for (i = 1; i < num_gamecontrols; i++) + { + fprintf(f, "setcontrol2 \"%s\" \"%s\"", gamecontrolname[i], + G_KeynumToString(gamecontrolbis[i][0])); + + if (gamecontrolbis[i][1]) + fprintf(f, " \"%s\"\n", G_KeynumToString(gamecontrolbis[i][1])); + else + fprintf(f, "\n"); + } +} + +void G_CheckDoubleUsage(INT32 keynum) +{ + if (cv_controlperkey.value == 1) + { + INT32 i; + for (i = 0; i < num_gamecontrols; i++) + { + if (gamecontrol[i][0] == keynum) + gamecontrol[i][0] = KEY_NULL; + if (gamecontrol[i][1] == keynum) + gamecontrol[i][1] = KEY_NULL; + if (gamecontrolbis[i][0] == keynum) + gamecontrolbis[i][0] = KEY_NULL; + if (gamecontrolbis[i][1] == keynum) + gamecontrolbis[i][1] = KEY_NULL; + } + } +} + +static void setcontrol(INT32 (*gc)[2], INT32 na) +{ + INT32 numctrl; + const char *namectrl; + INT32 keynum; + + namectrl = COM_Argv(1); + for (numctrl = 0; numctrl < num_gamecontrols && stricmp(namectrl, gamecontrolname[numctrl]); + numctrl++) + ; + if (numctrl == num_gamecontrols) + { + CONS_Printf(M_GetText("Control '%s' unknown\n"), namectrl); + return; + } + keynum = G_KeyStringtoNum(COM_Argv(2)); + G_CheckDoubleUsage(keynum); + gc[numctrl][0] = keynum; + + if (na == 4) + gc[numctrl][1] = G_KeyStringtoNum(COM_Argv(3)); + else + gc[numctrl][1] = 0; +} + +void Command_Setcontrol_f(void) +{ + INT32 na; + + na = (INT32)COM_Argc(); + + if (na != 3 && na != 4) + { + CONS_Printf(M_GetText("setcontrol [<2nd keyname>]: set controls for player 1\n")); + return; + } + + setcontrol(gamecontrol, na); +} + +void Command_Setcontrol2_f(void) +{ + INT32 na; + + na = (INT32)COM_Argc(); + + if (na != 3 && na != 4) + { + CONS_Printf(M_GetText("setcontrol2 [<2nd keyname>]: set controls for player 2\n")); + return; + } + + setcontrol(gamecontrolbis, na); +} diff --git a/src/g_input.h b/src/g_input.h new file mode 100644 index 000000000..334b7ad9d --- /dev/null +++ b/src/g_input.h @@ -0,0 +1,160 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Copyright (C) 1999-2014 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file g_input.h +/// \brief handle mouse/keyboard/joystick inputs, +/// maps inputs to game controls (forward, spin, jump...) + +#ifndef __G_INPUT__ +#define __G_INPUT__ + +#include "d_event.h" +#include "keys.h" +#include "command.h" + +// number of total 'button' inputs, include keyboard keys, plus virtual +// keys (mousebuttons and joybuttons becomes keys) +#define NUMKEYS 256 + + +#ifdef _arch_dreamcast +#define MOUSEBUTTONS 5 +#define JOYBUTTONS 8 // 8 buttons +#define JOYHATS 2 // 2 hats +#define JOYAXISSET 3 // 3 Sets of 2 axises +#elif defined (_XBOX) +#define MOUSEBUTTONS 5 +#define JOYBUTTONS 12 // 12 buttons +#define JOYHATS 1 // 1 hat +#define JOYAXISSET 2 // 2 Sets of 2 axises +#elif defined (_PSP) +#define MOUSEBUTTONS 3 +#define JOYBUTTONS 14 // 10 buttons +#define JOYHATS 1 // 1 hat +#define JOYAXISSET 1 // 1 Set of 2 axises +#elif defined (_WII) +#define MOUSEBUTTONS 3 +#define JOYBUTTONS 20 // 20 buttons +#define JOYHATS 1 // 1 hat +#define JOYAXISSET 5 // 5 Sets of 2 axises +#else +#define MOUSEBUTTONS 8 +#define JOYBUTTONS 32 // 32 buttons +#define JOYHATS 4 // 4 hats +#define JOYAXISSET 4 // 4 Sets of 2 axises +#endif + +// +// mouse and joystick buttons are handled as 'virtual' keys +// +typedef enum +{ + KEY_MOUSE1 = NUMKEYS, + KEY_JOY1 = KEY_MOUSE1 + MOUSEBUTTONS, + KEY_HAT1 = KEY_JOY1 + JOYBUTTONS, + + KEY_DBLMOUSE1 =KEY_HAT1 + JOYHATS*4, // double clicks + KEY_DBLJOY1 = KEY_DBLMOUSE1 + MOUSEBUTTONS, + KEY_DBLHAT1 = KEY_DBLJOY1 + JOYBUTTONS, + + KEY_2MOUSE1 = KEY_DBLHAT1 + JOYHATS*4, + KEY_2JOY1 = KEY_2MOUSE1 + MOUSEBUTTONS, + KEY_2HAT1 = KEY_2JOY1 + JOYBUTTONS, + + KEY_DBL2MOUSE1 = KEY_2HAT1 + JOYHATS*4, + KEY_DBL2JOY1 = KEY_DBL2MOUSE1 + MOUSEBUTTONS, + KEY_DBL2HAT1 = KEY_DBL2JOY1 + JOYBUTTONS, + + KEY_MOUSEWHEELUP = KEY_DBL2HAT1 + JOYHATS*4, + KEY_MOUSEWHEELDOWN = KEY_MOUSEWHEELUP + 1, + KEY_2MOUSEWHEELUP = KEY_MOUSEWHEELDOWN + 1, + KEY_2MOUSEWHEELDOWN = KEY_2MOUSEWHEELUP + 1, + + NUMINPUTS = KEY_2MOUSEWHEELDOWN + 1, +} key_input_e; + +typedef enum +{ + gc_null = 0, // a key/button mapped to gc_null has no effect + gc_forward, + gc_backward, + gc_strafeleft, + gc_straferight, + gc_turnleft, + gc_turnright, + gc_weaponnext, + gc_weaponprev, + gc_wepslot1, + gc_wepslot2, + gc_wepslot3, + gc_wepslot4, + gc_wepslot5, + gc_wepslot6, + gc_wepslot7, + gc_wepslot8, + gc_wepslot9, + gc_wepslot10, + gc_fire, + gc_firenormal, + gc_tossflag, + gc_use, + gc_camtoggle, + gc_camleft, + gc_camright, + gc_camreset, + gc_lookup, + gc_lookdown, + gc_centerview, + gc_mouseaiming, // mouse aiming is momentary (toggleable in the menu) + gc_talkkey, + gc_teamkey, + gc_scores, + gc_jump, + gc_console, + gc_pause, + num_gamecontrols +} gamecontrols_e; + +// mouse values are used once +extern consvar_t cv_mousesens; + +extern INT32 mousex, mousey; +extern INT32 mlooky; //mousey with mlookSensitivity +extern INT32 mouse2x, mouse2y, mlook2y; + +extern INT32 joyxmove[JOYAXISSET], joyymove[JOYAXISSET], joy2xmove[JOYAXISSET], joy2ymove[JOYAXISSET]; + +// current state of the keys: true if pushed +extern UINT8 gamekeydown[NUMINPUTS]; + +// two key codes (or virtual key) per game control +extern INT32 gamecontrol[num_gamecontrols][2]; +extern INT32 gamecontrolbis[num_gamecontrols][2]; // secondary splitscreen player +#define PLAYER1INPUTDOWN(gc) (gamekeydown[gamecontrol[gc][0]] || gamekeydown[gamecontrol[gc][1]]) +#define PLAYER2INPUTDOWN(gc) (gamekeydown[gamecontrolbis[gc][0]] || gamekeydown[gamecontrolbis[gc][1]]) + +// peace to my little coder fingers! +// check a gamecontrol being active or not + +// remaps the input event to a game control. +void G_MapEventsToControls(event_t *ev); + +// returns the name of a key +const char *G_KeynumToString(INT32 keynum); +INT32 G_KeyStringtoNum(const char *keystr); + +// detach any keys associated to the given game control +void G_ClearControlKeys(INT32 (*setupcontrols)[2], INT32 control); +void Command_Setcontrol_f(void); +void Command_Setcontrol2_f(void); +void G_Controldefault(void); +void G_SaveKeySetting(FILE *f); +void G_CheckDoubleUsage(INT32 keynum); + +#endif diff --git a/src/g_state.h b/src/g_state.h new file mode 100644 index 000000000..27909dccd --- /dev/null +++ b/src/g_state.h @@ -0,0 +1,60 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Copyright (C) 1999-2014 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file g_state.h +/// \brief SRB2 game states + +#ifndef __G_STATE__ +#define __G_STATE__ + +#include "doomtype.h" + +// the current state of the game +typedef enum +{ + GS_NULL = 0, // At beginning. + + // Fadable gamestates + GS_LEVEL, // Playing, in a level. + GS_INTERMISSION, // Gazing at the intermission screen. + GS_CONTINUING, // continue screen + + GS_TITLESCREEN, // title screen + GS_TIMEATTACK, // time attack menu + GS_CREDITS, // credit sequence + GS_EVALUATION, // Evaluation at the end of a game. + GS_GAMEEND, // game end sequence + + // Hardcoded fades or other fading methods + GS_INTRO, // introduction + GS_CUTSCENE, // custom cutscene + + // Not fadable + GS_DEDICATEDSERVER, // new state for dedicated server + GS_WAITINGPLAYERS // waiting for players in a net game +} gamestate_t; + +typedef enum +{ + ga_nothing, + ga_completed, + ga_worlddone, + ga_startcont, + ga_continued, +} gameaction_t; + +extern gamestate_t gamestate; +extern UINT8 ultimatemode; // was sk_insane +extern boolean oncontinuescreen; +extern gameaction_t gameaction; + +extern boolean botingame; +extern UINT8 botskin, botcolor; + +#endif //__G_STATE__ diff --git a/src/hardware/hw3dsdrv.h b/src/hardware/hw3dsdrv.h new file mode 100644 index 000000000..4938f8763 --- /dev/null +++ b/src/hardware/hw3dsdrv.h @@ -0,0 +1,85 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright (C) 2001 by DooM Legacy Team. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +//----------------------------------------------------------------------------- +/// \file +/// \brief 3D sound import/export prototypes for low-level hardware interface + +#ifndef __HW_3DS_DRV_H__ +#define __HW_3DS_DRV_H__ + +// Use standart hardware API +#include "hw_dll.h" +#include "hws_data.h" + +#if defined (SDL) || !defined (HWD) +EXPORT void HWRAPI(Shutdown) (void); +#endif + +// Use standart Init and Shutdown functions + +EXPORT INT32 HWRAPI (Startup) (I_Error_t FatalErrorFunction, snddev_t *snd_dev); +EXPORT u_int HWRAPI (AddSfx) (sfx_data_t *sfx); +EXPORT INT32 HWRAPI (AddSource) (source3D_data_t *src, u_int sfxhandle); +EXPORT INT32 HWRAPI (StartSource) (INT32 handle); +EXPORT void HWRAPI (StopSource) (INT32 handle); +EXPORT INT32 HWRAPI (GetHW3DSVersion) (void); +EXPORT void HWRAPI (BeginFrameUpdate) (void); +EXPORT void HWRAPI (EndFrameUpdate) (void); +EXPORT INT32 HWRAPI (IsPlaying) (INT32 handle); +EXPORT void HWRAPI (UpdateListener) (listener_data_t *data, INT32 num); +EXPORT void HWRAPI (UpdateSourceParms) (INT32 handle, INT32 vol, INT32 sep); +EXPORT void HWRAPI (SetGlobalSfxVolume) (INT32 volume); +EXPORT INT32 HWRAPI (SetCone) (INT32 handle, cone_def_t *cone_def); +EXPORT void HWRAPI (Update3DSource) (INT32 handle, source3D_pos_t *data); +EXPORT INT32 HWRAPI (ReloadSource) (INT32 handle, u_int sfxhandle); +EXPORT void HWRAPI (KillSource) (INT32 handle); +EXPORT void HWRAPI (KillSfx) (u_int sfxhandle); +EXPORT void HWRAPI (GetHW3DSTitle) (char *buf, size_t size); + + +#if !defined (_CREATE_DLL_) + +struct hardware3ds_s +{ + Startup pfnStartup; + AddSfx pfnAddSfx; + AddSource pfnAddSource; + StartSource pfnStartSource; + StopSource pfnStopSource; + GetHW3DSVersion pfnGetHW3DSVersion; + BeginFrameUpdate pfnBeginFrameUpdate; + EndFrameUpdate pfnEndFrameUpdate; + IsPlaying pfnIsPlaying; + UpdateListener pfnUpdateListener; + UpdateSourceParms pfnUpdateSourceParms; + SetGlobalSfxVolume pfnSetGlobalSfxVolume; + SetCone pfnSetCone; + Update3DSource pfnUpdate3DSource; + ReloadSource pfnReloadSource; + KillSource pfnKillSource; + KillSfx pfnKillSfx; + Shutdown pfnShutdown; + GetHW3DSTitle pfnGetHW3DSTitle; +}; + +extern struct hardware3ds_s hw3ds_driver; + +#define HW3DS hw3ds_driver + + +#endif // _CREATE_DLL_ + +#endif // __HW_3DS_DRV_H__ diff --git a/src/hardware/hw3sound.c b/src/hardware/hw3sound.c new file mode 100644 index 000000000..efc1d247b --- /dev/null +++ b/src/hardware/hw3sound.c @@ -0,0 +1,996 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright (C) 2001 by DooM Legacy Team. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +//----------------------------------------------------------------------------- +/// \file +/// \brief Hardware 3D sound general code + +#include "../doomdef.h" + +#ifdef HW3SOUND + +#include "../i_sound.h" +#include "../s_sound.h" +#include "../w_wad.h" +#include "../z_zone.h" +#include "../g_game.h" +#include "../tables.h" +#include "../sounds.h" +#include "../r_main.h" +#include "../r_things.h" +#include "../m_random.h" +#include "../p_local.h" +#include "hw3dsdrv.h" +#include "hw3sound.h" + +#define ANGLE2DEG(x) (((double)(x)) / ((double)ANGLE_45/45)) +#define NORM_PITCH 128 +#define NORM_PRIORITY 64 +#define NORM_SEP 128 +#if 1 +#define TPS(x) (x) +#else //Alam_GBC: MPS, not MPF! +#define TPS(x) ((float)(x)/(float)TICRATE) +#endif + +struct hardware3ds_s hw3ds_driver; + + +typedef struct source_s +{ + sfxinfo_t *sfxinfo; + const void *origin; + INT32 handle; // Internal source handle + channel_type_t type; // Sound type (attack, scream, etc) +} source_t; + + +typedef struct ambient_sdata_s +{ + source3D_data_t left; + source3D_data_t right; +} ambient_sdata_t; + + +typedef struct ambient_source_s +{ + source_t left; + source_t right; +} ambient_source_t; + +// Static sources +// This sources always creates +static source_t p_attack_source; // Player attack source +static source_t p_attack_source2; // Player2 attack source +static source_t p_scream_source; // Player scream source +static source_t p_scream_source2; // Player2 scream source + + +static ambient_source_t ambient_source; // Ambinet sound sources + +// abuse??? +//static source3D_data_t p_attack_sdata; // ?? Now just holds precalculated player attack source data +//static source3D_data_t p_default_sdata;// ?? ---- // ---- // ---- // ---- player scream source data + +static ambient_sdata_t ambient_sdata; // Precalculated datas of an ambient sound sources + +// Stack of dynamic sources +static source_t *sources = NULL; // Much like original channels +static INT32 num_sources = 0; + +// Current mode of 3D sound system +// Default is original (stereo) mode +INT32 hws_mode = HWS_DEFAULT_MODE; + +//============================================================================= +void HW3S_SetSourcesNum(void) +{ + INT32 i; + + // Allocating the internal channels for mixing + // (the maximum number of sounds rendered + // simultaneously) within zone memory. + if (sources) + HW3S_StopSounds(); + Z_Free(sources); + + if (cv_numChannels.value <= STATIC_SOURCES_NUM) + I_Error("HW3S_SetSourcesNum: Number of sound sources cannot be less than %d\n", STATIC_SOURCES_NUM + 1); + + num_sources = cv_numChannels.value - STATIC_SOURCES_NUM; + + sources = (source_t *) Z_Malloc(num_sources * sizeof (*sources), PU_STATIC, 0); + + // Free all channels for use + for (i = 0; i < num_sources; i++) + { + sources[i].sfxinfo = NULL; + sources[i].type = CT_NORMAL; + sources[i].handle = -1; + } +} + + +//============================================================================= +static void HW3S_KillSource(INT32 snum) +{ + source_t * s = &sources[snum]; + + if (s->sfxinfo) + { + HW3DS.pfnStopSource(s->handle); + HW3DS.pfnKillSource(s->handle); + s->handle = -1; + s->sfxinfo->usefulness--; + s->origin = NULL; + s->sfxinfo = NULL; + } +} + + +//============================================================================= +/* +static void HW3S_StopSource(INT32 snum) +{ + source_t * s = &sources[snum]; + + if (s->sfxinfo) + { + // stop the sound playing + HW3DS.pfnStopSource(s->handle); + } +} +*/ + + +//============================================================================= +void HW3S_StopSound(void *origin) +{ + INT32 snum; + + for (snum = 0; snum < num_sources; snum++) + { + if (sources[snum].sfxinfo && sources[snum].origin == origin) + { + HW3S_KillSource(snum); + break; + } + } +} + +void HW3S_StopSoundByID(void *origin, sfxenum_t sfx_id) +{ + INT32 snum; + + for (snum = 0; snum < num_sources; snum++) + { + if (sources[snum].sfxinfo == &S_sfx[sfx_id] && sources[snum].origin == origin) + { + HW3S_KillSource(snum); + break; + } + } +} + +void HW3S_StopSoundByNum(sfxenum_t sfxnum) +{ + INT32 snum; + + for (snum = 0; snum < num_sources; snum++) + { + if (sources[snum].sfxinfo == &S_sfx[sfxnum]) + { + HW3S_KillSource(snum); + break; + } + } +} + +//============================================================================= +void HW3S_StopSounds(void) +{ + INT32 snum; + + // kill all playing sounds at start of level + // (trust me - a good idea) + for (snum = 0; snum < num_sources; snum++) + if (sources[snum].sfxinfo) + HW3S_KillSource(snum); + + // Also stop all static sources + HW3DS.pfnStopSource(p_attack_source.handle); + HW3DS.pfnStopSource(p_attack_source2.handle); + HW3DS.pfnStopSource(p_scream_source.handle); + HW3DS.pfnStopSource(p_scream_source2.handle); + HW3DS.pfnStopSource(ambient_source.left.handle); + HW3DS.pfnStopSource(ambient_source.right.handle); +} + + +//============================================================================= +static INT32 HW3S_GetSource(const void *origin, sfxinfo_t *sfxinfo, boolean splitsound) +{ + // + // If none available, return -1. Otherwise source #. + // source number to use + + INT32 snum; + source_t * src; + INT32 sep = NORM_SEP, pitch = NORM_PITCH, volume = 255; + + (void)splitsound; + + // Find an open source + for (snum = 0, src = sources; snum < num_sources; src++, snum++) + { + if (!src->sfxinfo) + break; + +#if 0 + if (origin && src->origin == origin) + { + HW3S_KillSource(snum); + break; + } +#endif + } + +#if 0 + // Check to see if it is audible + if (origin && origin != listenmobj) + { + INT32 rc; + rc = S_AdjustSoundParams(listenmobj, origin, &volume, &sep, &pitch, sfxinfo); + if (!rc) + return -1; + } +#else + (void)origin; + (void)pitch; + (void)volume; + (void)sep; +#endif + + // None available + if (snum == num_sources) + { + // Look for lower priority + for (snum = 0, src = sources; snum < num_sources; src++, snum++) + if (src->sfxinfo->priority <= sfxinfo->priority) + break; + + if (snum == num_sources) + { + // No lower priority. Sorry, Charlie. + return -1; + } + else + { + // Otherwise, kick out lower priority + HW3S_KillSource(snum); + } + } + return snum; +} + + +//============================================================================= +static void HW3S_FillSourceParameters + (const mobj_t *origin, + source3D_data_t *data, + channel_type_t c_type) +{ + fixed_t x = 0, y = 0, z = 0; + + data->max_distance = MAX_DISTANCE; + data->min_distance = MIN_DISTANCE; + + if (origin && origin != players[displayplayer].mo) + { + data->head_relative = false; + + data->pos.momx = TPS(FIXED_TO_FLOAT(origin->momx)); + data->pos.momy = TPS(FIXED_TO_FLOAT(origin->momy)); + data->pos.momz = TPS(FIXED_TO_FLOAT(origin->momz)); + + x = origin->x; + y = origin->y; + z = origin->z; + + if (c_type == CT_ATTACK) + { + const angle_t an = origin->angle >> ANGLETOFINESHIFT; + x += FixedMul(16*FRACUNIT, FINECOSINE(an)); + y += FixedMul(16*FRACUNIT, FINESINE(an)); + z += origin->height >> 1; + } + + else if (c_type == CT_SCREAM) + z += origin->height - (5 * FRACUNIT); + } + else + { + data->head_relative = true; + + data->pos.momx = 0.0f; + data->pos.momy = 0.0f; + data->pos.momz = 0.0f; + } + data->pos.x = FIXED_TO_FLOAT(x); + data->pos.y = FIXED_TO_FLOAT(y); + data->pos.z = FIXED_TO_FLOAT(z); +} + +#define HEADER_SIZE 8 +//============================================================== +/* +static void make_outphase_sfx(void *dest, void *src, INT32 size) +{ + SINT8 *s = (SINT8 *)src + HEADER_SIZE, *d = (SINT8 *)dest + HEADER_SIZE; + + M_Memcpy(dest, src, HEADER_SIZE); + size -= HEADER_SIZE; + + while (size--) + *d++ = -(*s++); +} +*/ + +//INT32 HW3S_Start3DSound(const void *origin, source3D_data_t *source_parm, cone_def_t *cone_parm, channel_type_t channel, INT32 sfx_id, INT32 vol, INT32 pitch); +//============================================================================= +INT32 HW3S_I_StartSound(const void *origin_p, source3D_data_t *source_parm, channel_type_t c_type, sfxenum_t sfx_id, INT32 volume, INT32 pitch, INT32 sep) +{ + sfxinfo_t *sfx; + const mobj_t *origin = (const mobj_t *)origin_p; + source3D_data_t source3d_data; + INT32 s_num = 0; + source_t *source = NULL; + mobj_t *listenmobj = players[displayplayer].mo; + mobj_t *listenmobj2 = NULL; + + if (splitscreen) listenmobj2 = players[secondarydisplayplayer].mo; + + if (nosound) + return -1; + + sfx = &S_sfx[sfx_id]; + + if (sfx->skinsound!=-1 && origin && origin->skin) + { + // it redirect player sound to the sound in the skin table + sfx_id = ((skin_t *)origin->skin)->soundsid[sfx->skinsound]; + sfx = &S_sfx[sfx_id]; + } + + if (!sfx->data) + sfx->data = HW3S_GetSfx(sfx); + + // judgecutor 08-16-2002 + // Sound pitching for both Doom and Heretic +#if 0 + if (cv_rndsoundpitch.value) + { + /*if (gamemode != heretic) + { + if (sfx_id >= sfx_sawup && sfx_id <= sfx_sawhit) + pitch += 8 - (M_Random()&15); + else if (sfx_id != sfx_itemup && sfx_id != sfx_tink) + pitch += 16 - (M_Random()&31); + } + else*/ + pitch = 128 + (M_Random() & 7) - (M_Random() & 7); + } +#endif + + if (pitch < 0) + pitch = NORMAL_PITCH; + + if (pitch > 255) + pitch = 255; + + if (sep < 0) + sep = 128; + + if (splitscreen && listenmobj2) // Copy the sound for the split player + { + if (c_type != CT_NORMAL && origin && (origin == listenmobj2)) + { + if (c_type == CT_ATTACK) + { + if (origin == listenmobj2) + source = &p_attack_source; + else + source = &p_attack_source2; + } + else + { + if (origin == listenmobj2) + source = &p_scream_source; + else + source = &p_scream_source2; + } + + if (source->sfxinfo != sfx) + { + HW3DS.pfnStopSource(source->handle); + source->handle = HW3DS.pfnReloadSource(source->handle, sfx->volume); + //I_OutputMsg("PlayerSound data reloaded\n"); + } + } + else if (c_type == CT_AMBIENT) + { + // sfx_data_t outphased_sfx; + + if (ambient_source.left.sfxinfo != sfx) + { + HW3DS.pfnStopSource(ambient_source.left.handle); + HW3DS.pfnStopSource(ambient_source.right.handle); + + // judgecutor: + // Outphased sfx's temporarily not used!!! + /* + outphased_sfx.data = Z_Malloc(sfx_data.length, PU_STATIC, 0); + make_outphase_sfx(outphased_sfx.data, sfx_data.data, sfx_data.length); + outphased_sfx.length = sfx_data.length; + outphased_sfx.id = sfx_data.id; + */ + ambient_source.left.handle = HW3DS.pfnReloadSource(ambient_source.left.handle, (u_int)sfx->length); + //ambient_source.right.handle = HW3DS.pfnReloadSource(ambient_source.right.handle, &outphased_sfx); + ambient_source.right.handle = HW3DS.pfnReloadSource(ambient_source.right.handle, (u_int)sfx->length); + ambient_source.left.sfxinfo = ambient_source.right.sfxinfo = sfx; + //Z_Free(outphased_sfx.data); + } + + HW3DS.pfnUpdateSourceParms(ambient_source.left.handle, volume, -1); + HW3DS.pfnUpdateSourceParms(ambient_source.right.handle, volume, -1); + + if (sfx->usefulness++ < 0) + sfx->usefulness = -1; + + // Ambient sound is special case + HW3DS.pfnStartSource(ambient_source.left.handle); + HW3DS.pfnStartSource(ambient_source.right.handle); + } + else + { + s_num = HW3S_GetSource(origin, sfx, true); + + if (s_num < 0) + { + //I_OutputMsg("No free source, aborting\n"); + return -1; + } + + source = &sources[s_num]; + + if (origin && c_type == CT_NORMAL) + { + if (!source_parm) + { + source_parm = &source3d_data; + source3d_data.permanent = 0; + HW3S_FillSourceParameters(origin, source_parm, c_type); + } + + source->handle = HW3DS.pfnAddSource(source_parm, (u_int)sfx->length); + } + else + source->handle = HW3DS.pfnAddSource(NULL, (u_int)sfx->length); + } + + // increase the usefulness + if (sfx->usefulness++ < 0) + sfx->usefulness = -1; + + source->sfxinfo = sfx; + source->origin = origin; + HW3DS.pfnStartSource(source->handle); + } + + if (c_type != CT_NORMAL && origin && (origin == listenmobj)) + { + if (c_type == CT_ATTACK) + { + if (origin == listenmobj) + source = &p_attack_source; + else + source = &p_attack_source2; + } + else + { + if (origin == listenmobj) + source = &p_scream_source; + else + source = &p_scream_source2; + } + + if (source->sfxinfo != sfx) + { + HW3DS.pfnStopSource(source->handle); + source->handle = HW3DS.pfnReloadSource(source->handle, sfx->volume); + //I_OutputMsg("PlayerSound data reloaded\n"); + } + } + else if (c_type == CT_AMBIENT) + { +// sfx_data_t outphased_sfx; + + if (ambient_source.left.sfxinfo != sfx) + { + HW3DS.pfnStopSource(ambient_source.left.handle); + HW3DS.pfnStopSource(ambient_source.right.handle); + + // judgecutor: + // Outphased sfx's temporarily not used!!! +/* + outphased_sfx.data = Z_Malloc(sfx_data.length, PU_STATIC, 0); + make_outphase_sfx(outphased_sfx.data, sfx_data.data, sfx_data.length); + outphased_sfx.length = sfx_data.length; + outphased_sfx.id = sfx_data.id; +*/ + ambient_source.left.handle = HW3DS.pfnReloadSource(ambient_source.left.handle, (u_int)sfx->length); + //ambient_source.right.handle = HW3DS.pfnReloadSource(ambient_source.right.handle, &outphased_sfx); + ambient_source.right.handle = HW3DS.pfnReloadSource(ambient_source.right.handle, (u_int)sfx->length); + ambient_source.left.sfxinfo = ambient_source.right.sfxinfo = sfx; + //Z_Free(outphased_sfx.data); + } + + HW3DS.pfnUpdateSourceParms(ambient_source.left.handle, volume, -1); + HW3DS.pfnUpdateSourceParms(ambient_source.right.handle, volume, -1); + + if (sfx->usefulness++ < 0) + sfx->usefulness = -1; + + // Ambient sound is special case + HW3DS.pfnStartSource(ambient_source.left.handle); + HW3DS.pfnStartSource(ambient_source.right.handle); + return -1; + } + else + { + s_num = HW3S_GetSource(origin, sfx, false); + + if (s_num < 0) + { + //I_OutputMsg("No free source, aborting\n"); + return -1; + } + + source = &sources[s_num]; + + if (origin && c_type == CT_NORMAL) + { + if (!source_parm) + { + source_parm = &source3d_data; + source3d_data.permanent = 0; + HW3S_FillSourceParameters(origin, source_parm, c_type); + } + + source->handle = HW3DS.pfnAddSource(source_parm, (u_int)sfx->length); + } + else + source->handle = HW3DS.pfnAddSource(NULL, (u_int)sfx->length); + + } + + // increase the usefulness + if (sfx->usefulness++ < 0) + sfx->usefulness = -1; + + source->sfxinfo = sfx; + source->origin = origin; + HW3DS.pfnStartSource(source->handle); + return s_num; + +} + + +// Start normal sound +//============================================================================= +void HW3S_StartSound(const void *origin, sfxenum_t sfx_id) +{ + HW3S_I_StartSound(origin, NULL, CT_NORMAL, sfx_id, 255, NORMAL_PITCH, NORMAL_SEP); +} + + +//============================================================================= +void S_StartAttackSound(const void *origin, sfxenum_t sfx_id) +{ + if (hws_mode != HWS_DEFAULT_MODE) + HW3S_I_StartSound(origin, NULL, CT_ATTACK, sfx_id, 255, NORMAL_PITCH, NORMAL_SEP); + else + S_StartSound(origin, sfx_id); +} + +void S_StartScreamSound(const void *origin, sfxenum_t sfx_id) +{ + if (hws_mode != HWS_DEFAULT_MODE) + HW3S_I_StartSound(origin, NULL, CT_SCREAM, sfx_id, 255, NORMAL_PITCH, NORMAL_SEP); + else + S_StartSound(origin, sfx_id); +} + +#if 0 /// NOTE: not used +void S_StartAmbientSound(sfxenum_t sfx_id, INT32 volume) +{ + if (hws_mode != HWS_DEFAULT_MODE) + { + volume += 30; + if (volume > 255) + volume = 255; + + HW3S_I_StartSound(NULL, NULL, CT_AMBIENT, sfx_id, volume, NORMAL_PITCH, NORMAL_SEP); + } + else + S_StartSoundAtVolume(NULL, sfx_id, volume); +} +#endif + +FUNCMATH static inline float AmbientPos(angle_t an) +{ + const fixed_t fm = FixedMul(FLOAT_TO_FIXED(MIN_DISTANCE), FINESINE(an>>ANGLETOFINESHIFT)); + return FIXED_TO_FLOAT(fm); +} + + +//============================================================================= +INT32 HW3S_Init(I_Error_t FatalErrorFunction, snddev_t *snd_dev) +{ + INT32 succ; + source3D_data_t source_data; + + if (HW3DS.pfnStartup(FatalErrorFunction, snd_dev)) + { + // Attack source + source_data.head_relative = 1; + source_data.pos.x = 0.0f; + source_data.pos.y = 16.0f; + source_data.pos.z = -FIXED_TO_FLOAT(mobjinfo[MT_PLAYER].height >> 1); + source_data.pos.momx = 0.0f; + source_data.pos.momy = 0.0f; + source_data.pos.momz = 0.0f; + source_data.min_distance = MIN_DISTANCE; + source_data.max_distance = MAX_DISTANCE; + source_data.permanent = 1; + + p_attack_source.sfxinfo = NULL; + + M_Memcpy(&p_attack_source2, &p_attack_source, sizeof (source_t)); + + p_attack_source.handle = HW3DS.pfnAddSource(&source_data, sfx_None); + p_attack_source2.handle = HW3DS.pfnAddSource(&source_data, sfx_None); + + // Scream source + source_data.pos.y = 0; + source_data.pos.z = 0; + + p_scream_source.sfxinfo = NULL; + + M_Memcpy(&p_scream_source2, &p_scream_source, sizeof (source_t)); + + p_scream_source.handle = HW3DS.pfnAddSource(&source_data, sfx_None); + p_scream_source2.handle = HW3DS.pfnAddSource(&source_data, sfx_None); + + //FIXED_TO_FLOAT(mobjinfo[MT_PLAYER].height - (5 * FRACUNIT)); + + // Ambient sources (left and right) at 210 and 330 degree + // relative to listener + memset(&ambient_sdata, 0, sizeof (ambient_sdata)); + + ambient_sdata.left.head_relative = 1; + ambient_sdata.left.pos.x = ambient_sdata.left.pos.y = AmbientPos(ANG210); + ambient_sdata.left.max_distance = MAX_DISTANCE; + ambient_sdata.left.min_distance = MIN_DISTANCE; + + ambient_sdata.left.permanent = 1; + + M_Memcpy(&ambient_sdata.right, &ambient_sdata.left, sizeof (source3D_data_t)); + + ambient_sdata.right.pos.x = -ambient_sdata.left.pos.x; + ambient_source.left.handle = HW3DS.pfnAddSource(&ambient_sdata.left, sfx_None); + ambient_source.right.handle = HW3DS.pfnAddSource(&ambient_sdata.right, sfx_None); + + succ = p_attack_source.handle > -1 && p_scream_source.handle > -1 && + p_attack_source2.handle > -1 && p_scream_source2.handle > -1 && + ambient_source.left.handle > -1 && ambient_source.right.handle > -1; + + //I_OutputMsg("Player handles: attack %d, default %d\n", p_attack_source.handle, p_scream_source.handle); + return succ; + } + return 0; +} + + + + +//============================================================================= +INT32 HW3S_GetVersion(void) +{ + return HW3DS.pfnGetHW3DSVersion(); +} + + +//============================================================================= +void HW3S_BeginFrameUpdate(void) +{ + if (hws_mode != HWS_DEFAULT_MODE) + HW3DS.pfnBeginFrameUpdate(); +} + + +//============================================================================= +void HW3S_EndFrameUpdate(void) +{ + if (hws_mode != HWS_DEFAULT_MODE) + HW3DS.pfnEndFrameUpdate(); +} + + + +//============================================================================= +INT32 HW3S_SoundIsPlaying(INT32 handle) +{ + return HW3DS.pfnIsPlaying(handle); +} + +INT32 HW3S_OriginPlaying(void *origin) +{ + INT32 snum; + + if (!origin) + return 0; + for (snum = 0; snum < num_sources; snum++) + if (sources[snum].origin == origin) + return 1; + return 0; +} + +INT32 HW3S_IdPlaying(sfxenum_t id) +{ + INT32 snum; + for (snum = 0; snum < num_sources; snum++) + if ((size_t)(sources[snum].sfxinfo - S_sfx) == (size_t)id) + return 1; + return 0; +} + +INT32 HW3S_SoundPlaying(void *origin, sfxenum_t id) +{ + INT32 snum; + + if (!origin) + return 0; + + for (snum = 0; snum < num_sources; snum++) + { + if (sources[snum].origin == origin + && (size_t)(sources[snum].sfxinfo - S_sfx) == (size_t)id) + return 1; + } + return 0; +} + +//============================================================================= +static void HW3S_UpdateListener(mobj_t *listener) +{ + listener_data_t data; + + if (!listener || !listener->player) + return; + + if (camera.chase) + { + data.x = FIXED_TO_FLOAT(camera.x); + data.y = FIXED_TO_FLOAT(camera.y); + data.z = FIXED_TO_FLOAT(camera.z + camera.height - (5 * FRACUNIT)); + + data.f_angle = ANGLE2DEG(camera.angle); + data.h_angle = ANGLE2DEG(camera.aiming); + + data.momx = TPS(FIXED_TO_FLOAT(camera.momx)); + data.momy = TPS(FIXED_TO_FLOAT(camera.momy)); + data.momz = TPS(FIXED_TO_FLOAT(camera.momz)); + } + else + { + data.x = FIXED_TO_FLOAT(listener->x); + data.y = FIXED_TO_FLOAT(listener->y); + data.z = FIXED_TO_FLOAT(listener->z + listener->height - (5 * FRACUNIT)); + + data.f_angle = ANGLE2DEG(listener->angle); + data.h_angle = ANGLE2DEG(listener->player->aiming); + + data.momx = TPS(FIXED_TO_FLOAT(listener->momx)); + data.momy = TPS(FIXED_TO_FLOAT(listener->momy)); + data.momz = TPS(FIXED_TO_FLOAT(listener->momz)); + } + HW3DS.pfnUpdateListener(&data, 1); +} + +static void HW3S_UpdateListener2(mobj_t *listener) +{ + listener_data_t data; + + if (!listener || !listener->player) + { + HW3DS.pfnUpdateListener(NULL, 2); + return; + } + + if (camera2.chase) + { + data.x = FIXED_TO_FLOAT(camera2.x); + data.y = FIXED_TO_FLOAT(camera2.y); + data.z = FIXED_TO_FLOAT(camera2.z + camera2.height - (5 * FRACUNIT)); + + data.f_angle = ANGLE2DEG(camera2.angle); + data.h_angle = ANGLE2DEG(camera2.aiming); + + data.momx = TPS(FIXED_TO_FLOAT(camera2.momx)); + data.momy = TPS(FIXED_TO_FLOAT(camera2.momy)); + data.momz = TPS(FIXED_TO_FLOAT(camera2.momz)); + } + else + { + data.x = FIXED_TO_FLOAT(listener->x); + data.y = FIXED_TO_FLOAT(listener->y); + data.z = FIXED_TO_FLOAT(listener->z + listener->height - (5 * FRACUNIT)); + + data.f_angle = ANGLE2DEG(listener->angle); + data.h_angle = ANGLE2DEG(listener->player->aiming); + + data.momx = TPS(FIXED_TO_FLOAT(listener->momx)); + data.momy = TPS(FIXED_TO_FLOAT(listener->momy)); + data.momz = TPS(FIXED_TO_FLOAT(listener->momz)); + } + + HW3DS.pfnUpdateListener(&data, 2); +} + +void HW3S_SetSfxVolume(INT32 volume) +{ + HW3DS.pfnSetGlobalSfxVolume(volume); +} + + +static void HW3S_Update3DSource(source_t *src) +{ + source3D_data_t data; + data.permanent = 0; + HW3S_FillSourceParameters(src->origin, &data, src->type); + HW3DS.pfnUpdate3DSource(src->handle, &data.pos); + +} + +void HW3S_UpdateSources(void) +{ + mobj_t *listener = players[displayplayer].mo; + mobj_t *listener2 = NULL; + source_t *src; + INT32 audible, snum, volume, sep, pitch; + + if (splitscreen) listener2 = players[secondarydisplayplayer].mo; + + HW3S_UpdateListener2(listener2); + HW3S_UpdateListener(listener); + + for (snum = 0, src = sources; snum < num_sources; src++, snum++) + { + if (src->sfxinfo) + { +#if 0 + if (HW3DS.pfnIsPlaying(src->handle)) + { + if (src->origin) + { + // initialize parameters + volume = 255; // 8 bits internal volume precision + pitch = NORM_PITCH; + sep = NORM_SEP; + + // check non-local sounds for distance clipping + // or modify their params + if (src->origin && listener != src->origin && !(listener2 && src->origin == listener2)) + { + INT32 audible2; + INT32 volume2 = volume, sep2 = sep, pitch2 = pitch; + audible = S_AdjustSoundParams(listener, src->origin, &volume, &sep, &pitch, + src->sfxinfo); + + if (listener2) + { + audible2 = S_AdjustSoundParams(listener2, + src->origin, &volume2, &sep2, &pitch2, src->sfxinfo); + if (audible2 && (!audible || (audible && volume2 > volume))) + { + audible = true; + volume = volume2; + sep = sep2; + pitch = pitch2; + } + } + + if (audible) + HW3S_Update3DSource(src); // Update positional sources + else + HW3S_KillSource(snum); //Kill it! + } + } + } + else + { + // Source allocated but stopped. Kill. + HW3S_KillSource(snum); + } +#else + if (src->origin && listener != src->origin && !(listener2 && src->origin == listener2)) + HW3S_Update3DSource(src); // Update positional sources + (void)pitch; + (void)sep; + (void)volume; + (void)audible; +#endif + } + } +} + +void HW3S_Shutdown(void) +{ + HW3DS.pfnShutdown(); +} + +void *HW3S_GetSfx(sfxinfo_t *sfx) +{ + sfx_data_t sfx_data; + + if (sfx->lumpnum == LUMPERROR) + sfx->lumpnum = S_GetSfxLumpNum (sfx); + + sfx_data.length = W_LumpLength(sfx->lumpnum); + sfx_data.data = Z_Malloc(sfx_data.length, PU_SOUND, &sfx->data); + W_ReadLump(sfx->lumpnum, sfx_data.data); + sfx_data.priority = sfx->priority; + + sfx->length = HW3DS.pfnAddSfx(&sfx_data); + + Z_ChangeTag(sfx->data, PU_CACHE); + + return sfx_data.data; +} + +void HW3S_FreeSfx(sfxinfo_t *sfx) +{ + INT32 snum; + + for (snum = 0; snum < num_sources; snum++) + { + if (sources[snum].sfxinfo == sfx) + { + HW3S_KillSource(snum); + break; + } + } + + if (sfx->length > 0) + HW3DS.pfnKillSfx((u_int)sfx->length); + sfx->length = 0; + + sfx->lumpnum = LUMPERROR; + + Z_Free(sfx->data); + sfx->data = NULL; +} + +#endif diff --git a/src/hardware/hw3sound.h b/src/hardware/hw3sound.h new file mode 100644 index 000000000..a8a475b69 --- /dev/null +++ b/src/hardware/hw3sound.h @@ -0,0 +1,106 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright (C) 2001 by DooM Legacy Team. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +//----------------------------------------------------------------------------- +/// \file +/// \brief High-level functions of hardware 3D sound + +#ifndef __HW3_SOUND_H__ +#define __HW3_SOUND_H__ + +#ifdef HW3SOUND +#include "hws_data.h" +//#include "../s_sound.h" +//#include "../p_mobj.h" + +// Default sound mode (original stereo mode) +enum +{ + HWS_DEFAULT_MODE = 0, + HWS_DS3D, + HWS_OTHER, + HWS_FMOD3D, + HWS_OPENAL, +}; + +typedef enum +{ + CT_NORMAL = 0, + CT_ATTACK, + CT_SCREAM, + CT_AMBIENT, +} channel_type_t; + +extern INT32 hws_mode; // Current sound mode + +#if defined (HW3DS) || defined (DOXYGEN) +INT32 HW3S_Init(I_Error_t FatalErrorFunction, snddev_t *snd_dev); +#endif +void HW3S_Shutdown(void); +INT32 HW3S_GetVersion(void); + +// Common case - start 3D or 2D source +void HW3S_StartSound(const void *origin, sfxenum_t sfx_id); + +// Special cases of 3D sources +void S_StartAmbientSound(sfxenum_t sfx_id, INT32 volume); +void S_StartAttackSound(const void *origin, sfxenum_t sfx_id); +void S_StartScreamSound(const void *origin, sfxenum_t sfx_id); + +// Starts 3D sound with specified parameters +// origin - for object movement tracking. NULL are possible value (no movement tracking) +// source_parm - 3D source parameters (position etc.) +// cone_parm - 3D source cone parameters. NULL are possible value (default cone will be used) +// channel - +// sfx_id - sfx id +// vol - sound volume +// pitch - sound pitching value +// Returns: - sound id +INT32 HW3S_I_StartSound(const void *origin, source3D_data_t *source_parm, channel_type_t channel, sfxenum_t sfx_id, INT32 vol, INT32 pitch, INT32 sep); +void HW3S_StopSoundByID(void *origin, sfxenum_t sfx_id); +void HW3S_StopSoundByNum(sfxenum_t sfxnum); +void HW3S_StopSound(void *origin); +void HW3S_StopSounds(void); + +void HW3S_BeginFrameUpdate(void); +void HW3S_EndFrameUpdate(void); + +void HW3S_UpdateSources(void); + +void HW3S_SetSfxVolume(INT32 volume); + +// Utility functions +INT32 HW3S_SoundIsPlaying(INT32 handle); +void HW3S_SetSourcesNum(void); + +INT32 HW3S_OriginPlaying(void *origin); +INT32 HW3S_IdPlaying(sfxenum_t id); +INT32 HW3S_SoundPlaying(void *origin, sfxenum_t id); + +void *HW3S_GetSfx(sfxinfo_t *sfx); +void HW3S_FreeSfx(sfxinfo_t *sfx); + +#else // HW3SOUND + +//#define S_StartAmbientSound(i,v) S_StartSoundAtVolume(NULL, i, v) +#define S_StartAttackSound S_StartSound +#define S_StartScreamSound S_StartSound + +#endif // HW3SOUND + +INT32 S_AdjustSoundParams(const mobj_t *listener, const mobj_t *source, + INT32 *vol, INT32 *sep, INT32 *pitch, sfxinfo_t *sfxinfo); + +#endif // __HW3_SOUND_H__ diff --git a/src/hardware/hw_bsp.c b/src/hardware/hw_bsp.c new file mode 100644 index 000000000..17eb8761c --- /dev/null +++ b/src/hardware/hw_bsp.c @@ -0,0 +1,1031 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright (C) 1998-2000 by DooM Legacy Team. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +//----------------------------------------------------------------------------- +/// \file +/// \brief convert SRB2 map + +#include "../doomdef.h" +#include "../doomstat.h" +#ifdef HWRENDER +#include "hw_glob.h" +#include "../r_local.h" +#include "../z_zone.h" +#include "../console.h" +#include "../v_video.h" +#include "../m_menu.h" +#include "../i_system.h" +#include "../m_argv.h" +#include "../i_video.h" +#include "../w_wad.h" + +// -------------------------------------------------------------------------- +// This is global data for planes rendering +// -------------------------------------------------------------------------- + +extrasubsector_t *extrasubsectors = NULL; + +// newsubsectors are subsectors without segs, added for the plane polygons +#define NEWSUBSECTORS 50 +static size_t totsubsectors; +size_t addsubsector; + +typedef struct +{ + float x, y; + float dx, dy; +} fdivline_t; + +// ========================================================================== +// FLOOR & CEILING CONVEX POLYS GENERATION +// ========================================================================== + +//debug counters +static INT32 nobackpoly = 0; +static INT32 skipcut = 0; +static INT32 totalsubsecpolys = 0; + +// -------------------------------------------------------------------------- +// Polygon fast alloc / free +// -------------------------------------------------------------------------- +//hurdler: quick fix for those who wants to play with larger wad + +#define ZPLANALLOC +#ifndef ZPLANALLOC +//#define POLYPOOLSIZE 1024000 // may be much over what is needed +/// \todo check out how much is used +static size_t POLYPOOLSIZE = 1024000; + +static UINT8 *gr_polypool = NULL; +static UINT8 *gr_ppcurrent; +static size_t gr_ppfree; +#endif + +// only between levels, clear poly pool +static void HWR_ClearPolys(void) +{ +#ifndef ZPLANALLOC + gr_ppcurrent = gr_polypool; + gr_ppfree = POLYPOOLSIZE; +#endif +} + +// allocate pool for fast alloc of polys +void HWR_InitPolyPool(void) +{ +#ifndef ZPLANALLOC + INT32 pnum; + + //hurdler: quick fix for those who wants to play with larger wad + if ((pnum = M_CheckParm("-polypoolsize"))) + POLYPOOLSIZE = atoi(myargv[pnum+1])*1024; // (in kb) + + CONS_Debug(DBG_RENDER, "HWR_InitPolyPool(): allocating %d bytes\n", POLYPOOLSIZE); + gr_polypool = malloc(POLYPOOLSIZE); + if (!gr_polypool) + I_Error("HWR_InitPolyPool(): couldn't malloc polypool\n"); + HWR_ClearPolys(); +#endif +} + +void HWR_FreePolyPool(void) +{ +#ifndef ZPLANALLOC + if (gr_polypool) + free(gr_polypool); + gr_polypool = NULL; +#endif +} + +static poly_t *HWR_AllocPoly(INT32 numpts) +{ + poly_t *p; + size_t size = sizeof (poly_t) + sizeof (polyvertex_t) * numpts; +#ifdef ZPLANALLOC + p = Z_Malloc(size, PU_HWRPLANE, NULL); +#else +#ifdef PARANOIA + if (!gr_polypool) + I_Error("Used gr_polypool without init!\n"); + if (!gr_ppcurrent) + I_Error("gr_ppcurrent == NULL!\n"); +#endif + + if (gr_ppfree < size) + I_Error("HWR_AllocPoly(): no more memory %u bytes left, %u bytes needed\n\n%s\n", + gr_ppfree, size, "You can try the param -polypoolsize 2048 (or higher if needed)"); + + p = (poly_t *)gr_ppcurrent; + gr_ppcurrent += size; + gr_ppfree -= size; +#endif + p->numpts = numpts; + return p; +} + +static polyvertex_t *HWR_AllocVertex(void) +{ + polyvertex_t *p; + size_t size = sizeof (polyvertex_t); +#ifdef ZPLANALLOC + p = Z_Malloc(size, PU_HWRPLANE, NULL); +#else + if (gr_ppfree < size) + I_Error("HWR_AllocVertex(): no more memory %u bytes left, %u bytes needed\n\n%s\n", + gr_ppfree, size, "You can try the param -polypoolsize 2048 (or higher if needed)"); + + p = (polyvertex_t *)gr_ppcurrent; + gr_ppcurrent += size; + gr_ppfree -= size; +#endif + return p; +} + +/// \todo polygons should be freed in reverse order for efficiency, +/// for now don't free because it doesn't free in reverse order +static void HWR_FreePoly(poly_t *poly) +{ +#ifdef ZPLANALLOC + Z_Free(poly); +#else + const size_t size = sizeof (poly_t) + sizeof (polyvertex_t) * poly->numpts; + memset(poly, 0x00, size); + //mempoly -= polysize; +#endif +} + + +// Return interception along bsp line, +// with the polygon segment +// +static float bspfrac; +static polyvertex_t *fracdivline(fdivline_t *bsp, polyvertex_t *v1, + polyvertex_t *v2) +{ + static polyvertex_t pt; + double frac; + double num; + double den; + double v1x,v1y,v1dx,v1dy; + double v2x,v2y,v2dx,v2dy; + + // a segment of a polygon + v1x = v1->x; + v1y = v1->y; + v1dx = v2->x - v1->x; + v1dy = v2->y - v1->y; + + // the bsp partition line + v2x = bsp->x; + v2y = bsp->y; + v2dx = bsp->dx; + v2dy = bsp->dy; + + den = v2dy*v1dx - v2dx*v1dy; + if (den == 0) + return NULL; // parallel + + // first check the frac along the polygon segment, + // (do not accept hit with the extensions) + num = (v2x - v1x)*v2dy + (v1y - v2y)*v2dx; + frac = num / den; + if (frac < 0 || frac > 1) + return NULL; + + // now get the frac along the BSP line + // which is useful to determine what is left, what is right + num = (v2x - v1x)*v1dy + (v1y - v2y)*v1dx; + frac = num / den; + bspfrac = (float)frac; + + + // find the interception point along the partition line + pt.x = (float)(v2x + v2dx*frac); + pt.y = (float)(v2y + v2dy*frac); + + return &pt; +} + +#if 0 +//Hurdler: it's not used anymore +static boolean NearVertice (polyvertex_t *p1, polyvertex_t *p2) +{ +#if 1 + float diff; + diff = p2->x - p1->x; + if (diff < -1.5f || diff > 1.5f) + return false; + diff = p2->y - p1->y; + if (diff < -1.5f || diff > 1.5f) + return false; +#else + if (p1->x != p2->x) + return false; + if (p1->y != p2->y) + return false; +#endif + // p1 and p2 are considered the same vertex + return true; +} +#endif + +// if two vertice coords have a x and/or y difference +// of less or equal than 1 FRACUNIT, they are considered the same +// point. Note: hardcoded value, 1.0f could be anything else. +static boolean SameVertice (polyvertex_t *p1, polyvertex_t *p2) +{ +#if 0 + float diff; + diff = p2->x - p1->x; + if (diff < -1.5f || diff > 1.5f) + return false; + diff = p2->y - p1->y; + if (diff < -1.5f || diff > 1.5f) + return false; +#else + if (p1->x != p2->x) + return false; + if (p1->y != p2->y) + return false; +#endif + // p1 and p2 are considered the same vertex + return true; +} + + +// split a _CONVEX_ polygon in two convex polygons +// outputs: +// frontpoly : polygon on right side of bsp line +// backpoly : polygon on left side +// +static void SplitPoly (fdivline_t *bsp, //splitting parametric line + poly_t *poly, //the convex poly we split + poly_t **frontpoly, //return one poly here + poly_t **backpoly) //return the other here +{ + INT32 i,j; + polyvertex_t *pv; + + INT32 ps = -1,pe = -1; + INT32 nptfront,nptback; + polyvertex_t vs = {0,0,0}; + polyvertex_t ve = {0,0,0}; + polyvertex_t lastpv = {0,0,0}; + float fracs = 0.0f,frace = 0.0f; //used to tell which poly is on + // the front side of the bsp partition line + INT32 psonline = 0, peonline = 0; + + for (i = 0; i < poly->numpts; i++) + { + j = i + 1; + if (j == poly->numpts) j = 0; + + // start & end points + pv = fracdivline(bsp, &poly->pts[i], &poly->pts[j]); + + if (pv) + { + if (ps < 0) + { + // first point + ps = i; + vs = *pv; + fracs = bspfrac; + } + else + { + //the partition line traverse a junction between two segments + // or the two points are so close, they can be considered as one + // thus, don't accept, since split 2 must be another vertex + if (SameVertice(pv, &lastpv)) + { + if (pe < 0) + { + ps = i; + psonline = 1; + } + else + { + pe = i; + peonline = 1; + } + } + else + { + if (pe < 0) + { + pe = i; + ve = *pv; + frace = bspfrac; + } + else + { + // a frac, not same vertice as last one + // we already got pt2 so pt 2 is not on the line, + // so we probably got back to the start point + // which is on the line + if (SameVertice(pv, &vs)) + psonline = 1; + break; + } + } + } + + // remember last point intercept to detect identical points + lastpv = *pv; + } + } + + // no split: the partition line is either parallel and + // aligned with one of the poly segments, or the line is totally + // out of the polygon and doesn't traverse it (happens if the bsp + // is fooled by some trick where the sidedefs don't point to + // the right sectors) + if (ps < 0) + { + //I_Error("SplitPoly: did not split polygon (%d %d)\n" + // "debugpos %d",ps,pe,debugpos); + + // this eventually happens with 'broken' BSP's that accept + // linedefs where each side point the same sector, that is: + // the deep water effect with the original Doom + + /// \todo make sure front poly is to front of partition line? + + *frontpoly = poly; + *backpoly = NULL; + return; + } + + if (ps >= 0 && pe < 0) + { + //I_Error("SplitPoly: only one point for split line (%d %d)", ps, pe); + *frontpoly = poly; + *backpoly = NULL; + return; + } + if (pe <= ps) + I_Error("SplitPoly: invalid splitting line (%d %d)", ps, pe); + + // number of points on each side, _not_ counting those + // that may lie just one the line + nptback = pe - ps - peonline; + nptfront = poly->numpts - peonline - psonline - nptback; + + if (nptback > 0) + *backpoly = HWR_AllocPoly(2 + nptback); + else + *backpoly = NULL; + if (nptfront) + *frontpoly = HWR_AllocPoly(2 + nptfront); + else + *frontpoly = NULL; + + // generate FRONT poly + if (*frontpoly) + { + pv = (*frontpoly)->pts; + *pv++ = vs; + *pv++ = ve; + i = pe; + do + { + if (++i == poly->numpts) + i = 0; + *pv++ = poly->pts[i]; + } while (i != ps && --nptfront); + } + + // generate BACK poly + if (*backpoly) + { + pv = (*backpoly)->pts; + *pv++ = ve; + *pv++ = vs; + i = ps; + do + { + if (++i == poly->numpts) + i = 0; + *pv++ = poly->pts[i]; + } while (i != pe && --nptback); + } + + // make sure frontpoly is the one on the 'right' side + // of the partition line + if (fracs > frace) + { + poly_t *swappoly; + swappoly = *backpoly; + *backpoly = *frontpoly; + *frontpoly = swappoly; + } + + HWR_FreePoly (poly); +} + + +// use each seg of the poly as a partition line, keep only the +// part of the convex poly to the front of the seg (that is, +// the part inside the sector), the part behind the seg, is +// the void space and is cut out +// +static poly_t *CutOutSubsecPoly(seg_t *lseg, INT32 count, poly_t *poly) +{ + INT32 i, j; + + polyvertex_t *pv; + + INT32 nump = 0, ps, pe; + polyvertex_t vs = {0, 0, 0}, ve = {0, 0, 0}, + p1 = {0, 0, 0}, p2 = {0, 0, 0}; + float fracs = 0.0f; + + fdivline_t cutseg; // x, y, dx, dy as start of node_t struct + + poly_t *temppoly; + + // for each seg of the subsector + for (; count--; lseg++) + { + //x,y,dx,dy (like a divline) + line_t *line = lseg->linedef; + p1.x = FIXED_TO_FLOAT(lseg->side ? line->v2->x : line->v1->x); + p1.y = FIXED_TO_FLOAT(lseg->side ? line->v2->y : line->v1->y); + p2.x = FIXED_TO_FLOAT(lseg->side ? line->v1->x : line->v2->x); + p2.y = FIXED_TO_FLOAT(lseg->side ? line->v1->y : line->v2->y); + + cutseg.x = p1.x; + cutseg.y = p1.y; + cutseg.dx = p2.x - p1.x; + cutseg.dy = p2.y - p1.y; + + // see if it cuts the convex poly + ps = -1; + pe = -1; + for (i = 0; i < poly->numpts; i++) + { + j = i + 1; + if (j == poly->numpts) + j = 0; + + pv = fracdivline(&cutseg, &poly->pts[i], &poly->pts[j]); + + if (pv) + { + if (ps < 0) + { + ps = i; + vs = *pv; + fracs = bspfrac; + } + else + { + //frac 1 on previous segment, + // 0 on the next, + //the split line goes through one of the convex poly + // vertices, happens quite often since the convex + // poly is already adjacent to the subsector segs + // on most borders + if (SameVertice(pv, &vs)) + continue; + + if (fracs <= bspfrac) + { + nump = 2 + poly->numpts - (i-ps); + pe = ps; + ps = i; + ve = *pv; + } + else + { + nump = 2 + (i-ps); + pe = i; + ve = vs; + vs = *pv; + } + //found 2nd point + break; + } + } + } + + // there was a split + if (ps >= 0) + { + //need 2 points + if (pe >= 0) + { + // generate FRONT poly + temppoly = HWR_AllocPoly(nump); + pv = temppoly->pts; + *pv++ = vs; + *pv++ = ve; + do + { + if (++ps == poly->numpts) + ps = 0; + *pv++ = poly->pts[ps]; + } while (ps != pe); + HWR_FreePoly(poly); + poly = temppoly; + } + //hmmm... maybe we should NOT accept this, but this happens + // only when the cut is not needed it seems (when the cut + // line is aligned to one of the borders of the poly, and + // only some times..) + else + skipcut++; + // I_Error("CutOutPoly: only one point for split line (%d %d) %d", ps, pe, debugpos); + } + } + return poly; +} + +// At this point, the poly should be convex and the exact +// layout of the subsector, it is not always the case, +// so continue to cut off the poly into smaller parts with +// each seg of the subsector. +// +static inline void HWR_SubsecPoly(INT32 num, poly_t *poly) +{ + INT16 count; + subsector_t *sub; + seg_t *lseg; + + sscount++; + + sub = &subsectors[num]; + count = sub->numlines; + lseg = &segs[sub->firstline]; + + if (poly) + { + poly = CutOutSubsecPoly (lseg,count,poly); + totalsubsecpolys++; + //extra data for this subsector + extrasubsectors[num].planepoly = poly; + } +} + +// the bsp divline have not enouth presition +// search for the segs source of this divline +static inline void SearchDivline(node_t *bsp, fdivline_t *divline) +{ +#if 0 // MAR - If you don't use the same partition line that the BSP uses, the front/back polys won't match the subsectors in the BSP! +#endif + divline->x = FIXED_TO_FLOAT(bsp->x); + divline->y = FIXED_TO_FLOAT(bsp->y); + divline->dx = FIXED_TO_FLOAT(bsp->dx); + divline->dy = FIXED_TO_FLOAT(bsp->dy); +} + +//Hurdler: implement a loading status +static size_t ls_count = 0; +static UINT8 ls_percent = 0; + +// poly : the convex polygon that encloses all child subsectors +static void WalkBSPNode(INT32 bspnum, poly_t *poly, UINT16 *leafnode, fixed_t *bbox) +{ + node_t *bsp; + poly_t *backpoly, *frontpoly; + fdivline_t fdivline; + polyvertex_t *pt; + INT32 i; + + // Found a subsector? + if (bspnum & NF_SUBSECTOR) + { + if (bspnum == -1) + { + // BP: i think this code is useless and wrong because + // - bspnum==-1 happens only when numsubsectors == 0 + // - it can't happens in bsp recursive call since bspnum is a INT32 and children is UINT16 + // - the BSP is complet !! (there just can have subsector without segs) (i am not sure of this point) + + // do we have a valid polygon ? + if (poly && poly->numpts > 2) + { + CONS_Debug(DBG_RENDER, "Adding a new subsector\n"); + if (addsubsector == numsubsectors + NEWSUBSECTORS) + I_Error("WalkBSPNode: not enough addsubsectors\n"); + else if (addsubsector > 0x7fff) + I_Error("WalkBSPNode: addsubsector > 0x7fff\n"); + *leafnode = (UINT16)((UINT16)addsubsector | NF_SUBSECTOR); + extrasubsectors[addsubsector].planepoly = poly; + addsubsector++; + } + + //add subsectors without segs here? + //HWR_SubsecPoly(0, NULL); + } + else + { + HWR_SubsecPoly(bspnum&(~NF_SUBSECTOR), poly); + //Hurdler: implement a loading status + + if (ls_count-- <= 0) + { + char s[16]; + int x, y; + + I_OsPolling(); + ls_count = numsubsectors/50; + CON_Drawer(); + sprintf(s, "%d%%", (++ls_percent)<<1); + x = BASEVIDWIDTH/2; + y = BASEVIDHEIGHT/2; + V_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, 31); // Black background to match fade in effect + //V_DrawPatchFill(W_CachePatchName("SRB2BACK",PU_CACHE)); // SRB2 background, ehhh too bright. + M_DrawTextBox(x-58, y-8, 13, 1); + V_DrawString(x-50, y, V_YELLOWMAP, "Loading..."); + V_DrawRightAlignedString(x+50, y, V_YELLOWMAP, s); + + // Is this really necessary at this point..? + V_DrawCenteredString(BASEVIDWIDTH/2, 40, V_YELLOWMAP, "OPENGL MODE IS INCOMPLETE AND MAY"); + V_DrawCenteredString(BASEVIDWIDTH/2, 50, V_YELLOWMAP, "NOT DISPLAY SOME SURFACES."); + V_DrawCenteredString(BASEVIDWIDTH/2, 70, V_YELLOWMAP, "USE AT SONIC'S RISK."); + + I_UpdateNoVsync(); + } + } + M_ClearBox(bbox); + poly = extrasubsectors[bspnum&~NF_SUBSECTOR].planepoly; + + for (i = 0, pt = poly->pts; i < poly->numpts; i++,pt++) + M_AddToBox(bbox, FLOAT_TO_FIXED(pt->x), FLOAT_TO_FIXED(pt->y)); + + return; + } + + bsp = &nodes[bspnum]; + SearchDivline(bsp, &fdivline); + SplitPoly(&fdivline, poly, &frontpoly, &backpoly); + poly = NULL; + + //debug + if (!backpoly) + nobackpoly++; + + // Recursively divide front space. + if (frontpoly) + { + WalkBSPNode(bsp->children[0], frontpoly, &bsp->children[0],bsp->bbox[0]); + + // copy child bbox + M_Memcpy(bbox, bsp->bbox[0], 4*sizeof (fixed_t)); + } + else + I_Error("WalkBSPNode: no front poly?"); + + // Recursively divide back space. + if (backpoly) + { + // Correct back bbox to include floor/ceiling convex polygon + WalkBSPNode(bsp->children[1], backpoly, &bsp->children[1], + bsp->bbox[1]); + + // enlarge bbox with seconde child + M_AddToBox(bbox, bsp->bbox[1][BOXLEFT ], + bsp->bbox[1][BOXTOP ]); + M_AddToBox(bbox, bsp->bbox[1][BOXRIGHT ], + bsp->bbox[1][BOXBOTTOM]); + } +} + +// FIXME: use Z_Malloc() STATIC ? +void HWR_FreeExtraSubsectors(void) +{ + if (extrasubsectors) + free(extrasubsectors); + extrasubsectors = NULL; +} + +#define MAXDIST 1.5f +// BP: can't move vertex: DON'T change polygon geometry! (convex) +//#define MOVEVERTEX +static boolean PointInSeg(polyvertex_t *a,polyvertex_t *v1,polyvertex_t *v2) +{ + register float ax,ay,bx,by,cx,cy,d,norm; + register polyvertex_t *p; + + // check bbox of the seg first + if (v1->x > v2->x) + { + p = v1; + v1 = v2; + v2 = p; + } + + if (a->x < v1->x-MAXDIST || a->x > v2->x+MAXDIST) + return false; + + if (v1->y > v2->y) + { + p = v1; + v1 = v2; + v2 = p; + } + if (a->y < v1->y-MAXDIST || a->y > v2->y+MAXDIST) + return false; + + // v1 = origine + ax= v2->x-v1->x; + ay= v2->y-v1->y; + norm = (float)hypot(ax, ay); + ax /= norm; + ay /= norm; + bx = a->x-v1->x; + by = a->y-v1->y; + //d = a.b + d =ax*bx+ay*by; + // bound of the seg + if (d < 0 || d > norm) + return false; + //c = d.1a-b + cx = ax*d-bx; + cy = ay*d-by; +#ifdef MOVEVERTEX + if (cx*cx+cy*cy <= MAXDIST*MAXDIST) + { + // ajust a little the point position + a->x = ax*d+v1->x; + a->y = ay*d+v1->y; + // anyway the correction is not enouth + return true; + } + return false; +#else + return cx*cx+cy*cy <= MAXDIST*MAXDIST; +#endif +} + +static INT32 numsplitpoly; + +static void SearchSegInBSP(INT32 bspnum,polyvertex_t *p,poly_t *poly) +{ + poly_t *q; + INT32 j,k; + + if (bspnum & NF_SUBSECTOR) + { + if (bspnum!=-1) + { + bspnum&=~NF_SUBSECTOR; + q = extrasubsectors[bspnum].planepoly; + if (poly == q || !q) + return; + for (j = 0; j < q->numpts; j++) + { + k = j+1; + if (k == q->numpts) k = 0; + if (!SameVertice(p, &q->pts[j]) + && !SameVertice(p, &q->pts[k]) + && PointInSeg(p, &q->pts[j], + &q->pts[k])) + { + poly_t *newpoly = HWR_AllocPoly(q->numpts+1); + INT32 n; + + for (n = 0; n <= j; n++) + newpoly->pts[n] = q->pts[n]; + newpoly->pts[k] = *p; + for (n = k+1; n < newpoly->numpts; n++) + newpoly->pts[n] = q->pts[n-1]; + numsplitpoly++; + extrasubsectors[bspnum].planepoly = + newpoly; + HWR_FreePoly(q); + return; + } + } + } + return; + } + + if ((FIXED_TO_FLOAT(nodes[bspnum].bbox[0][BOXBOTTOM])-MAXDIST <= p->y) && + (FIXED_TO_FLOAT(nodes[bspnum].bbox[0][BOXTOP ])+MAXDIST >= p->y) && + (FIXED_TO_FLOAT(nodes[bspnum].bbox[0][BOXLEFT ])-MAXDIST <= p->x) && + (FIXED_TO_FLOAT(nodes[bspnum].bbox[0][BOXRIGHT ])+MAXDIST >= p->x)) + SearchSegInBSP(nodes[bspnum].children[0],p,poly); + + if ((FIXED_TO_FLOAT(nodes[bspnum].bbox[1][BOXBOTTOM])-MAXDIST <= p->y) && + (FIXED_TO_FLOAT(nodes[bspnum].bbox[1][BOXTOP ])+MAXDIST >= p->y) && + (FIXED_TO_FLOAT(nodes[bspnum].bbox[1][BOXLEFT ])-MAXDIST <= p->x) && + (FIXED_TO_FLOAT(nodes[bspnum].bbox[1][BOXRIGHT ])+MAXDIST >= p->x)) + SearchSegInBSP(nodes[bspnum].children[1],p,poly); +} + +// search for T-intersection problem +// BP : It can be mush more faster doing this at the same time of the splitpoly +// but we must use a different structure : polygone pointing on segs +// segs pointing on polygone and on vertex (too mush complicated, well not +// realy but i am soo lasy), the methode discibed is also better for segs presition +static INT32 SolveTProblem(void) +{ + poly_t *p; + INT32 i; + size_t l; + + if (cv_grsolvetjoin.value == 0) + return 0; + + CONS_Debug(DBG_RENDER, "Solving T-joins. This may take a while. Please wait...\n"); + CON_Drawer(); //let the user know what we are doing + I_FinishUpdate(); // page flip or blit buffer + + numsplitpoly = 0; + + for (l = 0; l < addsubsector; l++) + { + p = extrasubsectors[l].planepoly; + if (p) + for (i = 0; i < p->numpts; i++) + SearchSegInBSP((INT32)numnodes-1, &p->pts[i], p); + } + //CONS_Debug(DBG_RENDER, "numsplitpoly %d\n", numsplitpoly); + return numsplitpoly; +} + +#define NEARDIST (0.75f) +#define MYMAX (10000000000000.0f) + +/* Adjust true segs (from the segs lump) to be exactely the same as + * plane polygone segs + * This also convert fixed_t point of segs in float (in moste case + * it share the same vertice + */ +static void AdjustSegs(void) +{ + size_t i, count; + INT32 j; + seg_t *lseg; + poly_t *p; + INT32 v1found = 0, v2found = 0; + float nearv1, nearv2; + + for (i = 0; i < numsubsectors; i++) + { + count = subsectors[i].numlines; + lseg = &segs[subsectors[i].firstline]; + p = extrasubsectors[i].planepoly; + if (!p) + continue; + for (; count--; lseg++) + { + float distv1,distv2,tmp; + nearv1 = nearv2 = MYMAX; + +#ifdef POLYOBJECTS + // Don't touch polyobject segs. We'll compensate + // for this when we go about drawing them. + if (lseg->polyseg) + continue; +#endif + + for (j = 0; j < p->numpts; j++) + { + distv1 = p->pts[j].x - FIXED_TO_FLOAT(lseg->v1->x); + tmp = p->pts[j].y - FIXED_TO_FLOAT(lseg->v1->y); + distv1 = distv1*distv1+tmp*tmp; + if (distv1 <= nearv1) + { + v1found = j; + nearv1 = distv1; + } + // the same with v2 + distv2 = p->pts[j].x - FIXED_TO_FLOAT(lseg->v2->x); + tmp = p->pts[j].y - FIXED_TO_FLOAT(lseg->v2->y); + distv2 = distv2*distv2+tmp*tmp; + if (distv2 <= nearv2) + { + v2found = j; + nearv2 = distv2; + } + } + if (nearv1 <= NEARDIST*NEARDIST) + // share vertice with segs + lseg->v1 = (vertex_t *)&(p->pts[v1found]); + else + { + // BP: here we can do better, using PointInSeg and compute + // the right point position also split a polygone side to + // solve a T-intersection, but too mush work + + // convert fixed vertex to float vertex + polyvertex_t *pv = HWR_AllocVertex(); + pv->x = FIXED_TO_FLOAT(lseg->v1->x); + pv->y = FIXED_TO_FLOAT(lseg->v1->y); + lseg->v1 = (vertex_t *)pv; + } + if (nearv2 <= NEARDIST*NEARDIST) + lseg->v2 = (vertex_t *)&(p->pts[v2found]); + else + { + polyvertex_t *pv = HWR_AllocVertex(); + pv->x = FIXED_TO_FLOAT(lseg->v2->x); + pv->y = FIXED_TO_FLOAT(lseg->v2->y); + lseg->v2 = (vertex_t *)pv; + } + + // recompute length + { + float x,y; + x = ((polyvertex_t *)lseg->v2)->x - ((polyvertex_t *)lseg->v1)->x + + FIXED_TO_FLOAT(FRACUNIT/2); + y = ((polyvertex_t *)lseg->v2)->y - ((polyvertex_t *)lseg->v1)->y + + FIXED_TO_FLOAT(FRACUNIT/2); + lseg->flength = (float)hypot(x, y); + // BP: debug see this kind of segs + //if (nearv2 > NEARDIST*NEARDIST || nearv1 > NEARDIST*NEARDIST) + // lseg->length = 1; + } + } + } +} + + +// call this routine after the BSP of a Doom wad file is loaded, +// and it will generate all the convex polys for the hardware renderer +void HWR_CreatePlanePolygons(INT32 bspnum) +{ + poly_t *rootp; + polyvertex_t *rootpv; + size_t i; + fixed_t rootbbox[4]; + + CONS_Debug(DBG_RENDER, "Creating polygons, please wait...\n"); + ls_count = ls_percent = 0; // reset the loading status + CON_Drawer(); //let the user know what we are doing + I_FinishUpdate(); // page flip or blit buffer + + HWR_ClearPolys(); + + // find min/max boundaries of map + //CONS_Debug(DBG_RENDER, "Looking for boundaries of map...\n"); + M_ClearBox(rootbbox); + for (i = 0;i < numvertexes; i++) + M_AddToBox(rootbbox, vertexes[i].x, vertexes[i].y); + + //CONS_Debug(DBG_RENDER, "Generating subsector polygons... %d subsectors\n", numsubsectors); + + HWR_FreeExtraSubsectors(); + // allocate extra data for each subsector present in map + totsubsectors = numsubsectors + NEWSUBSECTORS; + extrasubsectors = calloc(totsubsectors, sizeof (*extrasubsectors)); + if (extrasubsectors == NULL) + I_Error("couldn't malloc extrasubsectors totsubsectors %s\n", sizeu1(totsubsectors)); + + // allocate table for back to front drawing of subsectors + /*gr_drawsubsectors = (INT16 *)malloc(sizeof (*gr_drawsubsectors) * totsubsectors); + if (!gr_drawsubsectors) + I_Error("couldn't malloc gr_drawsubsectors\n");*/ + + // number of the first new subsector that might be added + addsubsector = numsubsectors; + + // construct the initial convex poly that encloses the full map + rootp = HWR_AllocPoly(4); + rootpv = rootp->pts; + + rootpv->x = FIXED_TO_FLOAT(rootbbox[BOXLEFT ]); + rootpv->y = FIXED_TO_FLOAT(rootbbox[BOXBOTTOM]); //lr + rootpv++; + rootpv->x = FIXED_TO_FLOAT(rootbbox[BOXLEFT ]); + rootpv->y = FIXED_TO_FLOAT(rootbbox[BOXTOP ]); //ur + rootpv++; + rootpv->x = FIXED_TO_FLOAT(rootbbox[BOXRIGHT ]); + rootpv->y = FIXED_TO_FLOAT(rootbbox[BOXTOP ]); //ul + rootpv++; + rootpv->x = FIXED_TO_FLOAT(rootbbox[BOXRIGHT ]); + rootpv->y = FIXED_TO_FLOAT(rootbbox[BOXBOTTOM]); //ll + rootpv++; + + WalkBSPNode(bspnum, rootp, NULL,rootbbox); + + i = SolveTProblem(); + //CONS_Debug(DBG_RENDER, "%d point divides a polygon line\n",i); + AdjustSegs(); + + //debug debug.. + //if (nobackpoly) + // CONS_Debug(DBG_RENDER, "no back polygon %u times\n",nobackpoly); + //"(should happen only with the deep water trick)" + //if (skipcut) + // CONS_Debug(DBG_RENDER, "%u cuts were skipped because of only one point\n",skipcut); + + //CONS_Debug(DBG_RENDER, "done: %u total subsector convex polygons\n", totalsubsecpolys); +} + +#endif //HWRENDER diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c new file mode 100644 index 000000000..c97e51616 --- /dev/null +++ b/src/hardware/hw_cache.c @@ -0,0 +1,1005 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright (C) 1998-2000 by DooM Legacy Team. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +//----------------------------------------------------------------------------- +/// \file +/// \brief load and convert graphics to the hardware format + +#include "../doomdef.h" + +#ifdef HWRENDER +#include "hw_glob.h" +#include "hw_drv.h" + +#include "../doomstat.h" //gamemode +#include "../i_video.h" //rendermode +#include "../r_data.h" +#include "../w_wad.h" +#include "../z_zone.h" +#include "../v_video.h" +#include "../r_draw.h" + +//Hurdler: 25/04/2000: used for new colormap code in hardware mode +//static UINT8 *gr_colormap = NULL; // by default it must be NULL ! (because colormap tables are not initialized) +boolean firetranslucent = false; + +// Values set after a call to HWR_ResizeBlock() +static INT32 blocksize, blockwidth, blockheight; + +INT32 patchformat = GR_TEXFMT_AP_88; // use alpha for holes +INT32 textureformat = GR_TEXFMT_P_8; // use chromakey for hole + +// sprite, use alpha and chroma key for hole +static void HWR_DrawPatchInCache(GLMipmap_t *mipmap, + INT32 pblockwidth, INT32 pblockheight, INT32 blockmodulo, + INT32 ptexturewidth, INT32 ptextureheight, + INT32 originx, INT32 originy, // where to draw patch in surface block + const patch_t *realpatch, INT32 bpp) +{ + INT32 x, x1, x2; + INT32 col, ncols; + fixed_t xfrac, xfracstep; + fixed_t yfrac, yfracstep, position, count; + fixed_t scale_y; + RGBA_t colortemp; + UINT8 *dest; + const UINT8 *source; + const column_t *patchcol; + UINT8 alpha; + UINT8 *block = mipmap->grInfo.data; + UINT8 texel; + UINT16 texelu16; + + x1 = originx; + x2 = x1 + SHORT(realpatch->width); + + if (x1 < 0) + x = 0; + else + x = x1; + + if (x2 > ptexturewidth) + x2 = ptexturewidth; + + if (!ptexturewidth) + return; + + col = x * pblockwidth / ptexturewidth; + ncols = ((x2 - x) * pblockwidth) / ptexturewidth; + +/* + CONS_Debug(DBG_RENDER, "patch %dx%d texture %dx%d block %dx%d\n", SHORT(realpatch->width), + SHORT(realpatch->height), + ptexturewidth, + textureheight, + pblockwidth,pblockheight); + CONS_Debug(DBG_RENDER, " col %d ncols %d x %d\n", col, ncols, x); +*/ + + // source advance + xfrac = 0; + if (x1 < 0) + xfrac = -x1< 4) + I_Error("HWR_DrawPatchInCache: no drawer defined for this bpp (%d)\n",bpp); + + for (block += col*bpp; ncols--; block += bpp, xfrac += xfracstep) + { + INT32 topdelta, prevdelta = -1; + patchcol = (const column_t *)((const UINT8 *)realpatch + + LONG(realpatch->columnofs[xfrac>>FRACBITS])); + + scale_y = (pblockheight << FRACBITS) / ptextureheight; + + while (patchcol->topdelta != 0xff) + { + topdelta = patchcol->topdelta; + if (topdelta <= prevdelta) + topdelta += prevdelta; + prevdelta = topdelta; + source = (const UINT8 *)patchcol + 3; + count = ((patchcol->length * scale_y) + (FRACUNIT/2)) >> FRACBITS; + position = originy + topdelta; + + yfrac = 0; + //yfracstep = (patchcol->length << FRACBITS) / count; + if (position < 0) + { + yfrac = -position<> FRACBITS); + position = 0; + } + + position = ((position * scale_y) + (FRACUNIT/2)) >> FRACBITS; + + if (position < 0) + position = 0; + + if (position + count >= pblockheight) + count = pblockheight - position; + + dest = block + (position*blockmodulo); + while (count > 0) + { + count--; + + texel = source[yfrac>>FRACBITS]; + + if (firetranslucent && (transtables[(texel<<8)+0x40000]!=texel)) + alpha = 0x80; + else + alpha = 0xff; + + //Hurdler: not perfect, but better than holes + if (texel == HWR_PATCHES_CHROMAKEY_COLORINDEX && (mipmap->flags & TF_CHROMAKEYED)) + texel = HWR_CHROMAKEY_EQUIVALENTCOLORINDEX; + //Hurdler: 25/04/2000: now support colormap in hardware mode + else if (mipmap->colormap) + texel = mipmap->colormap[texel]; + + // hope compiler will get this switch out of the loops (dreams...) + // gcc do it ! but vcc not ! (why don't use cygwin gcc for win32 ?) + // Alam: SRB2 uses Mingw, HUGS + switch (bpp) + { + case 2 : texelu16 = (UINT16)((alpha<<8) | texel); + memcpy(dest, &texelu16, sizeof(UINT16)); + break; + case 3 : colortemp = V_GetColor(texel); + memcpy(dest, &colortemp, sizeof(RGBA_t)-sizeof(UINT8)); + break; + case 4 : colortemp = V_GetColor(texel); + colortemp.s.alpha = alpha; + memcpy(dest, &colortemp, sizeof(RGBA_t)); + break; + // default is 1 + default: *dest = texel; + break; + } + + dest += blockmodulo; + yfrac += yfracstep; + } + patchcol = (const column_t *)((const UINT8 *)patchcol + patchcol->length + 4); + } + } +} + + +// resize the patch to be 3dfx compliant +// set : blocksize = blockwidth * blockheight (no bpp used) +// blockwidth +// blockheight +//note : 8bit (1 byte per pixel) palettized format +static void HWR_ResizeBlock(INT32 originalwidth, INT32 originalheight, + GrTexInfo *grInfo) +{ + // Build the full textures from patches. + static const GrLOD_t gr_lods[9] = + { + GR_LOD_LOG2_256, + GR_LOD_LOG2_128, + GR_LOD_LOG2_64, + GR_LOD_LOG2_32, + GR_LOD_LOG2_16, + GR_LOD_LOG2_8, + GR_LOD_LOG2_4, + GR_LOD_LOG2_2, + GR_LOD_LOG2_1 + }; + + typedef struct + { + GrAspectRatio_t aspect; + float max_s; + float max_t; + } booring_aspect_t; + + static const booring_aspect_t gr_aspects[8] = + { + {GR_ASPECT_LOG2_1x1, 255, 255}, + {GR_ASPECT_LOG2_2x1, 255, 127}, + {GR_ASPECT_LOG2_4x1, 255, 63}, + {GR_ASPECT_LOG2_8x1, 255, 31}, + + {GR_ASPECT_LOG2_1x1, 255, 255}, + {GR_ASPECT_LOG2_1x2, 127, 255}, + {GR_ASPECT_LOG2_1x4, 63, 255}, + {GR_ASPECT_LOG2_1x8, 31, 255} + }; + + INT32 j,k; + INT32 max,min; + + // find a power of 2 width/height + if (cv_grrounddown.value) + { + blockwidth = 256; + while (originalwidth < blockwidth) + blockwidth >>= 1; + if (blockwidth < 1) + I_Error("3D GenerateTexture : too small"); + + blockheight = 256; + while (originalheight < blockheight) + blockheight >>= 1; + if (blockheight < 1) + I_Error("3D GenerateTexture : too small"); + } + else if (cv_voodoocompatibility.value) + { + if (originalwidth > 256 || originalheight > 256) + { + blockwidth = 256; + while (originalwidth < blockwidth) + blockwidth >>= 1; + if (blockwidth < 1) + I_Error("3D GenerateTexture : too small"); + + blockheight = 256; + while (originalheight < blockheight) + blockheight >>= 1; + if (blockheight < 1) + I_Error("3D GenerateTexture : too small"); + } + else + { + //size up to nearest power of 2 + blockwidth = 1; + while (blockwidth < originalwidth) + blockwidth <<= 1; + // scale down the original graphics to fit in 256 + if (blockwidth > 256) + blockwidth = 256; + //I_Error("3D GenerateTexture : too big"); + + //size up to nearest power of 2 + blockheight = 1; + while (blockheight < originalheight) + blockheight <<= 1; + // scale down the original graphics to fit in 256 + if (blockheight > 256) + blockheight = 255; + //I_Error("3D GenerateTexture : too big"); + } + } + else + { + //size up to nearest power of 2 + blockwidth = 1; + while (blockwidth < originalwidth) + blockwidth <<= 1; + // scale down the original graphics to fit in 256 + if (blockwidth > 2048) + blockwidth = 2048; + //I_Error("3D GenerateTexture : too big"); + + //size up to nearest power of 2 + blockheight = 1; + while (blockheight < originalheight) + blockheight <<= 1; + // scale down the original graphics to fit in 256 + if (blockheight > 2048) + blockheight = 2048; + //I_Error("3D GenerateTexture : too big"); + } + + // do the boring LOD stuff.. blech! + if (blockwidth >= blockheight) + { + max = blockwidth; + min = blockheight; + } + else + { + max = blockheight; + min = blockwidth; + } + + for (k = 2048, j = 0; k > max; j++) + k>>=1; + grInfo->smallLodLog2 = gr_lods[j]; + grInfo->largeLodLog2 = gr_lods[j]; + + for (k = max, j = 0; k > min && j < 4; j++) + k>>=1; + // aspect ratio too small for 3Dfx (eg: 8x128 is 1x16 : use 1x8) + if (j == 4) + { + j = 3; + //CONS_Debug(DBG_RENDER, "HWR_ResizeBlock : bad aspect ratio %dx%d\n", blockwidth,blockheight); + if (blockwidth < blockheight) + blockwidth = max>>3; + else + blockheight = max>>3; + } + if (blockwidth < blockheight) + j += 4; + grInfo->aspectRatioLog2 = gr_aspects[j].aspect; + + blocksize = blockwidth * blockheight; + + //CONS_Debug(DBG_RENDER, "Width is %d, Height is %d\n", blockwidth, blockheight); +} + + +static const INT32 format2bpp[16] = +{ + 0, //0 + 0, //1 + 1, //2 GR_TEXFMT_ALPHA_8 + 1, //3 GR_TEXFMT_INTENSITY_8 + 1, //4 GR_TEXFMT_ALPHA_INTENSITY_44 + 1, //5 GR_TEXFMT_P_8 + 4, //6 GR_RGBA + 0, //7 + 0, //8 + 0, //9 + 2, //10 GR_TEXFMT_RGB_565 + 2, //11 GR_TEXFMT_ARGB_1555 + 2, //12 GR_TEXFMT_ARGB_4444 + 2, //13 GR_TEXFMT_ALPHA_INTENSITY_88 + 2, //14 GR_TEXFMT_AP_88 +}; + +static UINT8 *MakeBlock(GLMipmap_t *grMipmap) +{ + UINT8 *block; + INT32 bpp, i; + UINT16 bu16 = ((0x00 <<8) | HWR_CHROMAKEY_EQUIVALENTCOLORINDEX); + + bpp = format2bpp[grMipmap->grInfo.format]; + block = Z_Malloc(blocksize*bpp, PU_HWRCACHE, &(grMipmap->grInfo.data)); + + switch (bpp) + { + case 1: memset(block, HWR_PATCHES_CHROMAKEY_COLORINDEX, blocksize); break; + case 2: + // fill background with chromakey, alpha = 0 + for (i = 0; i < blocksize; i++) + //[segabor] + memcpy(block+i*sizeof(UINT16), &bu16, sizeof(UINT16)); + break; + case 4: memset(block, 0x00, blocksize*sizeof(UINT32)); break; + } + + return block; +} + +// +// Create a composite texture from patches, adapt the texture size to a power of 2 +// height and width for the hardware texture cache. +// +static void HWR_GenerateTexture(INT32 texnum, GLTexture_t *grtex) +{ + UINT8 *block; + texture_t *texture; + texpatch_t *patch; + patch_t *realpatch; + + INT32 i; + boolean skyspecial = false; //poor hack for Legacy large skies.. + + texture = textures[texnum]; + + // hack the Legacy skies.. + if (texture->name[0] == 'S' && + texture->name[1] == 'K' && + texture->name[2] == 'Y' && + (texture->name[4] == 0 || + texture->name[5] == 0) + ) + { + skyspecial = true; + grtex->mipmap.flags = TF_WRAPXY; // don't use the chromakey for sky + } + else + grtex->mipmap.flags = TF_CHROMAKEYED | TF_WRAPXY; + + HWR_ResizeBlock (texture->width, texture->height, &grtex->mipmap.grInfo); + grtex->mipmap.width = (UINT16)blockwidth; + grtex->mipmap.height = (UINT16)blockheight; + grtex->mipmap.grInfo.format = textureformat; + + block = MakeBlock(&grtex->mipmap); + + if (skyspecial) //Hurdler: not efficient, but better than holes in the sky (and it's done only at level loading) + { + INT32 j; + RGBA_t col; + + col = V_GetColor(HWR_CHROMAKEY_EQUIVALENTCOLORINDEX); + for (j = 0; j < blockheight; j++) + { + for (i = 0; i < blockwidth; i++) + { + block[4*(j*blockwidth+i)+0] = col.s.red; + block[4*(j*blockwidth+i)+1] = col.s.green; + block[4*(j*blockwidth+i)+2] = col.s.blue; + block[4*(j*blockwidth+i)+3] = 0xff; + } + } + } + + // Composite the columns together. + for (i = 0, patch = texture->patches; i < texture->patchcount; i++, patch++) + { + realpatch = W_CacheLumpNumPwad(patch->wad, patch->lump, PU_CACHE); + HWR_DrawPatchInCache(&grtex->mipmap, + blockwidth, blockheight, + blockwidth*format2bpp[grtex->mipmap.grInfo.format], + texture->width, texture->height, + patch->originx, patch->originy, + realpatch, + format2bpp[grtex->mipmap.grInfo.format]); + Z_Unlock(realpatch); + } + //Hurdler: not efficient at all but I don't remember exactly how HWR_DrawPatchInCache works :( + if (format2bpp[grtex->mipmap.grInfo.format]==4) + { + for (i = 3; i < blocksize; i += 4) + { + if (block[i] == 0) + { + grtex->mipmap.flags |= TF_TRANSPARENT; + break; + } + } + } + + grtex->scaleX = 1.0f/(texture->width*FRACUNIT); + grtex->scaleY = 1.0f/(texture->height*FRACUNIT); +} + +// patch may be NULL if grMipmap has been initialised already and makebitmap is false +void HWR_MakePatch (const patch_t *patch, GLPatch_t *grPatch, GLMipmap_t *grMipmap, boolean makebitmap) +{ + INT32 newwidth, newheight; + + // don't do it twice (like a cache) + if (grMipmap->width == 0) + { + // save the original patch header so that the GLPatch can be casted + // into a standard patch_t struct and the existing code can get the + // orginal patch dimensions and offsets. + grPatch->width = SHORT(patch->width); + grPatch->height = SHORT(patch->height); + grPatch->leftoffset = SHORT(patch->leftoffset); + grPatch->topoffset = SHORT(patch->topoffset); + + // find the good 3dfx size (boring spec) + HWR_ResizeBlock (SHORT(patch->width), SHORT(patch->height), &grMipmap->grInfo); + grMipmap->width = (UINT16)blockwidth; + grMipmap->height = (UINT16)blockheight; + + // no wrap around, no chroma key + grMipmap->flags = 0; + // setup the texture info + grMipmap->grInfo.format = patchformat; + } + else + { + blockwidth = grMipmap->width; + blockheight = grMipmap->height; + blocksize = blockwidth * blockheight; + } + + Z_Free(grMipmap->grInfo.data); + grMipmap->grInfo.data = NULL; + + // if rounddown, rounddown patches as well as textures + if (cv_grrounddown.value) + { + newwidth = blockwidth; + newheight = blockheight; + } + else if (cv_voodoocompatibility.value) // Only scales down textures that exceed 256x256. + { + // no rounddown, do not size up patches, so they don't look 'scaled' + newwidth = min(grPatch->width, blockwidth); + newheight = min(grPatch->height, blockheight); + + if (newwidth > 256 || newheight > 256) + { + newwidth = blockwidth; + newheight = blockheight; + } + } + else + { + // no rounddown, do not size up patches, so they don't look 'scaled' + newwidth = min(grPatch->width, blockwidth); + newheight = min(grPatch->height, blockheight); + } + + if (makebitmap) + { + MakeBlock(grMipmap); + + HWR_DrawPatchInCache(grMipmap, + newwidth, newheight, + blockwidth*format2bpp[grMipmap->grInfo.format], + grPatch->width, grPatch->height, + 0, 0, + patch, + format2bpp[grMipmap->grInfo.format]); + } + + grPatch->max_s = (float)newwidth / (float)blockwidth; + grPatch->max_t = (float)newheight / (float)blockheight; +} + + +// ================================================= +// CACHING HANDLING +// ================================================= + +static size_t gr_numtextures; +static GLTexture_t *gr_textures; // for ALL Doom textures + +void HWR_InitTextureCache(void) +{ + gr_numtextures = 0; + gr_textures = NULL; +} + + +// Callback function for HWR_FreeTextureCache. +static void FreeMipmapColormap(INT32 patchnum, void *patch) +{ + GLPatch_t* const grpatch = patch; + (void)patchnum; //unused + while (grpatch->mipmap.nextcolormap) + { + GLMipmap_t *grmip = grpatch->mipmap.nextcolormap; + grpatch->mipmap.nextcolormap = grmip->nextcolormap; + if (grmip->grInfo.data) Z_Free(grmip->grInfo.data); + free(grmip); + } +} + +void HWR_FreeTextureCache(void) +{ + INT32 i; + // free references to the textures + HWD.pfnClearMipMapCache(); + + // free all hardware-converted graphics cached in the heap + // our gool is only the textures since user of the texture is the texture cache + Z_FreeTags(PU_HWRCACHE, PU_HWRCACHE); + Z_FreeTags(PU_HWRCACHE_UNLOCKED, PU_HWRCACHE_UNLOCKED); + + // Alam: free the Z_Blocks before freeing it's users + + // free all skin after each level: must be done after pfnClearMipMapCache! + for (i = 0; i < numwadfiles; i++) + M_AATreeIterate(wadfiles[i]->hwrcache, FreeMipmapColormap); + + // now the heap don't have any 'user' pointing to our + // texturecache info, we can free it + if (gr_textures) + free(gr_textures); + gr_textures = NULL; + gr_numtextures = 0; +} + +void HWR_PrepLevelCache(size_t pnumtextures) +{ + // problem: the mipmap cache management hold a list of mipmaps.. but they are + // reallocated on each level.. + //sub-optimal, but 1) just need re-download stuff in hardware cache VERY fast + // 2) sprite/menu stuff mixed with level textures so can't do anything else + + // we must free it since numtextures changed + HWR_FreeTextureCache(); + + gr_numtextures = pnumtextures; + gr_textures = calloc(pnumtextures, sizeof (*gr_textures)); + if (gr_textures == NULL) + I_Error("3D can't alloc gr_textures"); +} + +void HWR_SetPalette(RGBA_t *palette) +{ + //Hudler: 16/10/99: added for OpenGL gamma correction + RGBA_t gamma_correction = {0x7F7F7F7F}; + + //Hurdler 16/10/99: added for OpenGL gamma correction + gamma_correction.s.red = (UINT8)cv_grgammared.value; + gamma_correction.s.green = (UINT8)cv_grgammagreen.value; + gamma_correction.s.blue = (UINT8)cv_grgammablue.value; + HWD.pfnSetPalette(palette, &gamma_correction); + + // hardware driver will flush there own cache if cache is non paletized + // now flush data texture cache so 32 bit texture are recomputed + if (patchformat == GR_RGBA || textureformat == GR_RGBA) + { + Z_FreeTags(PU_HWRCACHE, PU_HWRCACHE); + Z_FreeTags(PU_HWRCACHE_UNLOCKED, PU_HWRCACHE_UNLOCKED); + } +} + +// -------------------------------------------------------------------------- +// Make sure texture is downloaded and set it as the source +// -------------------------------------------------------------------------- +GLTexture_t *HWR_GetTexture(INT32 tex) +{ + GLTexture_t *grtex; +#ifdef PARANOIA + if ((unsigned)tex >= gr_numtextures) + I_Error(" HWR_GetTexture: tex >= numtextures\n"); +#endif + grtex = &gr_textures[tex]; + + if (!grtex->mipmap.grInfo.data && !grtex->mipmap.downloaded) + HWR_GenerateTexture(tex, grtex); + + HWD.pfnSetTexture(&grtex->mipmap); + + // The system-memory data can be purged now. + Z_ChangeTag(grtex->mipmap.grInfo.data, PU_HWRCACHE_UNLOCKED); + + return grtex; +} + + +static void HWR_CacheFlat(GLMipmap_t *grMipmap, lumpnum_t flatlumpnum) +{ + size_t size, pflatsize; + + // setup the texture info + grMipmap->grInfo.smallLodLog2 = GR_LOD_LOG2_64; + grMipmap->grInfo.largeLodLog2 = GR_LOD_LOG2_64; + grMipmap->grInfo.aspectRatioLog2 = GR_ASPECT_LOG2_1x1; + grMipmap->grInfo.format = GR_TEXFMT_P_8; + grMipmap->flags = TF_WRAPXY|TF_CHROMAKEYED; + + size = W_LumpLength(flatlumpnum); + + switch (size) + { + case 4194304: // 2048x2048 lump + pflatsize = 2048; + break; + case 1048576: // 1024x1024 lump + pflatsize = 1024; + break; + case 262144:// 512x512 lump + pflatsize = 512; + break; + case 65536: // 256x256 lump + pflatsize = 256; + break; + case 16384: // 128x128 lump + pflatsize = 128; + break; + case 1024: // 32x32 lump + pflatsize = 32; + break; + default: // 64x64 lump + pflatsize = 64; + break; + } + grMipmap->width = (UINT16)pflatsize; + grMipmap->height = (UINT16)pflatsize; + + // the flat raw data needn't be converted with palettized textures + W_ReadLump(flatlumpnum, Z_Malloc(W_LumpLength(flatlumpnum), + PU_HWRCACHE, &grMipmap->grInfo.data)); +} + + +// Download a Doom 'flat' to the hardware cache and make it ready for use +void HWR_GetFlat(lumpnum_t flatlumpnum) +{ + GLMipmap_t *grmip; + + grmip = &HWR_GetCachedGLPatch(flatlumpnum)->mipmap; + + if (!grmip->downloaded && !grmip->grInfo.data) + HWR_CacheFlat(grmip, flatlumpnum); + + HWD.pfnSetTexture(grmip); + + // The system-memory data can be purged now. + Z_ChangeTag(grmip->grInfo.data, PU_HWRCACHE_UNLOCKED); +} + +// +// HWR_LoadMappedPatch(): replace the skin color of the sprite in cache +// : load it first in doom cache if not already +// +static void HWR_LoadMappedPatch(GLMipmap_t *grmip, GLPatch_t *gpatch) +{ + if (!grmip->downloaded && !grmip->grInfo.data) + { + patch_t *patch = W_CacheLumpNumPwad(gpatch->wadnum, gpatch->lumpnum, PU_STATIC); + HWR_MakePatch(patch, gpatch, grmip, true); + + Z_Free(patch); + } + + HWD.pfnSetTexture(grmip); + + // The system-memory data can be purged now. + Z_ChangeTag(grmip->grInfo.data, PU_HWRCACHE_UNLOCKED); +} + +// -----------------+ +// HWR_GetPatch : Download a patch to the hardware cache and make it ready for use +// -----------------+ +void HWR_GetPatch(GLPatch_t *gpatch) +{ + // is it in hardware cache + if (!gpatch->mipmap.downloaded && !gpatch->mipmap.grInfo.data) + { + // load the software patch, PU_STATIC or the Z_Malloc for hardware patch will + // flush the software patch before the conversion! oh yeah I suffered + patch_t *ptr = W_CacheLumpNumPwad(gpatch->wadnum, gpatch->lumpnum, PU_STATIC); + HWR_MakePatch(ptr, gpatch, &gpatch->mipmap, true); + + // this is inefficient.. but the hardware patch in heap is purgeable so it should + // not fragment memory, and besides the REAL cache here is the hardware memory + Z_Free(ptr); + } + + HWD.pfnSetTexture(&gpatch->mipmap); + + // The system-memory patch data can be purged now. + Z_ChangeTag(gpatch->mipmap.grInfo.data, PU_HWRCACHE_UNLOCKED); +} + + +// -------------------+ +// HWR_GetMappedPatch : Same as HWR_GetPatch for sprite color +// -------------------+ +void HWR_GetMappedPatch(GLPatch_t *gpatch, const UINT8 *colormap) +{ + GLMipmap_t *grmip, *newmip; + + if (colormap == colormaps || colormap == NULL) + { + // Load the default (green) color in doom cache (temporary?) AND hardware cache + HWR_GetPatch(gpatch); + return; + } + + // search for the mimmap + // skip the first (no colormap translated) + for (grmip = &gpatch->mipmap; grmip->nextcolormap; ) + { + grmip = grmip->nextcolormap; + if (grmip->colormap == colormap) + { + HWR_LoadMappedPatch(grmip, gpatch); + return; + } + } + // not found, create it! + // If we are here, the sprite with the current colormap is not already in hardware memory + + //BP: WARNING: don't free it manually without clearing the cache of harware renderer + // (it have a liste of mipmap) + // this malloc is cleared in HWR_FreeTextureCache + // (...) unfortunately z_malloc fragment alot the memory :(so malloc is better + newmip = calloc(1, sizeof (*newmip)); + if (newmip == NULL) + I_Error("%s: Out of memory", "HWR_GetMappedPatch"); + grmip->nextcolormap = newmip; + + newmip->colormap = colormap; + HWR_LoadMappedPatch(newmip, gpatch); +} + +void HWR_UnlockCachedPatch(GLPatch_t *gpatch) +{ + if (!gpatch) + return; + + Z_ChangeTag(gpatch->mipmap.grInfo.data, PU_HWRCACHE_UNLOCKED); + Z_ChangeTag(gpatch, PU_HWRPATCHINFO_UNLOCKED); +} + +static const INT32 picmode2GR[] = +{ + GR_TEXFMT_P_8, // PALETTE + 0, // INTENSITY (unsupported yet) + GR_TEXFMT_ALPHA_INTENSITY_88, // INTENSITY_ALPHA (corona use this) + 0, // RGB24 (unsupported yet) + GR_RGBA, // RGBA32 (opengl only) +}; + +static void HWR_DrawPicInCache(UINT8 *block, INT32 pblockwidth, INT32 pblockheight, + INT32 blockmodulo, pic_t *pic, INT32 bpp) +{ + INT32 i,j; + fixed_t posx, posy, stepx, stepy; + UINT8 *dest, *src, texel; + UINT16 texelu16; + INT32 picbpp; + RGBA_t col; + + stepy = ((INT32)SHORT(pic->height)<width)<mode]]; + posy = 0; + for (j = 0; j < pblockheight; j++) + { + posx = 0; + dest = &block[j*blockmodulo]; + src = &pic->data[(posy>>FRACBITS)*SHORT(pic->width)*picbpp]; + for (i = 0; i < pblockwidth;i++) + { + switch (pic->mode) + { // source bpp + case PALETTE : + texel = src[(posx+FRACUNIT/2)>>FRACBITS]; + switch (bpp) + { // destination bpp + case 1 : + *dest++ = texel; break; + case 2 : + texelu16 = (UINT16)(texel | 0xff00); + memcpy(dest, &texelu16, sizeof(UINT16)); + dest += sizeof(UINT16); + break; + case 3 : + col = V_GetColor(texel); + memcpy(dest, &col, sizeof(RGBA_t)-sizeof(UINT8)); + dest += sizeof(RGBA_t)-sizeof(UINT8); + break; + case 4 : + memcpy(dest, &V_GetColor(texel), sizeof(RGBA_t)); + dest += sizeof(RGBA_t); + break; + } + break; + case INTENSITY : + *dest++ = src[(posx+FRACUNIT/2)>>FRACBITS]; + break; + case INTENSITY_ALPHA : // assume dest bpp = 2 + memcpy(dest, src + ((posx+FRACUNIT/2)>>FRACBITS)*sizeof(UINT16), sizeof(UINT16)); + dest += sizeof(UINT16); + break; + case RGB24 : + break; // not supported yet + case RGBA32 : // assume dest bpp = 4 + dest += sizeof(UINT32); + memcpy(dest, src + ((posx+FRACUNIT/2)>>FRACBITS)*sizeof(UINT32), sizeof(UINT32)); + break; + } + posx += stepx; + } + posy += stepy; + } +} + +// -----------------+ +// HWR_GetPic : Download a Doom pic (raw row encoded with no 'holes') +// Returns : +// -----------------+ +GLPatch_t *HWR_GetPic(lumpnum_t lumpnum) +{ + GLPatch_t *grpatch; + + grpatch = HWR_GetCachedGLPatch(lumpnum); + + if (!grpatch->mipmap.downloaded && !grpatch->mipmap.grInfo.data) + { + pic_t *pic; + UINT8 *block; + size_t len; + INT32 newwidth, newheight; + + pic = W_CacheLumpNum(lumpnum, PU_CACHE); + grpatch->width = SHORT(pic->width); + grpatch->height = SHORT(pic->height); + len = W_LumpLength(lumpnum) - sizeof (pic_t); + + grpatch->leftoffset = 0; + grpatch->topoffset = 0; + + // find the good 3dfx size (boring spec) + HWR_ResizeBlock (grpatch->width, grpatch->height, &grpatch->mipmap.grInfo); + grpatch->mipmap.width = (UINT16)blockwidth; + grpatch->mipmap.height = (UINT16)blockheight; + + if (pic->mode == PALETTE) + grpatch->mipmap.grInfo.format = textureformat; // can be set by driver + else + grpatch->mipmap.grInfo.format = picmode2GR[pic->mode]; + + Z_Free(grpatch->mipmap.grInfo.data); + + // allocate block + block = MakeBlock(&grpatch->mipmap); + + // if rounddown, rounddown patches as well as textures + if (cv_grrounddown.value) + { + newwidth = blockwidth; + newheight = blockheight; + } + else if (cv_voodoocompatibility.value) // Only scales down textures that exceed 256x256. + { + // no rounddown, do not size up patches, so they don't look 'scaled' + newwidth = min(SHORT(pic->width),blockwidth); + newheight = min(SHORT(pic->height),blockheight); + + if (newwidth > 256 || newheight > 256) + { + newwidth = blockwidth; + newheight = blockheight; + } + } + else + { + // no rounddown, do not size up patches, so they don't look 'scaled' + newwidth = min(SHORT(pic->width),blockwidth); + newheight = min(SHORT(pic->height),blockheight); + } + + + if (grpatch->width == blockwidth && + grpatch->height == blockheight && + format2bpp[grpatch->mipmap.grInfo.format] == format2bpp[picmode2GR[pic->mode]]) + { + // no conversion needed + M_Memcpy(grpatch->mipmap.grInfo.data, pic->data,len); + } + else + HWR_DrawPicInCache(block, newwidth, newheight, + blockwidth*format2bpp[grpatch->mipmap.grInfo.format], + pic, + format2bpp[grpatch->mipmap.grInfo.format]); + + Z_Unlock(pic); + Z_ChangeTag(block, PU_HWRCACHE_UNLOCKED); + + grpatch->mipmap.flags = 0; + grpatch->max_s = (float)newwidth / (float)blockwidth; + grpatch->max_t = (float)newheight / (float)blockheight; + } + HWD.pfnSetTexture(&grpatch->mipmap); + //CONS_Debug(DBG_RENDER, "picloaded at %x as texture %d\n",grpatch->mipmap.grInfo.data, grpatch->mipmap.downloaded); + + return grpatch; +} + +GLPatch_t *HWR_GetCachedGLPatchPwad(UINT16 wadnum, UINT16 lumpnum) +{ + aatree_t *hwrcache = wadfiles[wadnum]->hwrcache; + GLPatch_t *grpatch; + + if (!(grpatch = M_AATreeGet(hwrcache, lumpnum))) + { + grpatch = Z_Calloc(sizeof(GLPatch_t), PU_HWRPATCHINFO, NULL); + grpatch->wadnum = wadnum; + grpatch->lumpnum = lumpnum; + M_AATreeSet(hwrcache, lumpnum, grpatch); + } + + return grpatch; +} + +GLPatch_t *HWR_GetCachedGLPatch(lumpnum_t lumpnum) +{ + return HWR_GetCachedGLPatchPwad(WADFILENUM(lumpnum),LUMPNUM(lumpnum)); +} + +#endif //HWRENDER diff --git a/src/hardware/hw_data.h b/src/hardware/hw_data.h new file mode 100644 index 000000000..77db10805 --- /dev/null +++ b/src/hardware/hw_data.h @@ -0,0 +1,94 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright (C) 1998-2000 by DooM Legacy Team. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +//----------------------------------------------------------------------------- +/// \file +/// \brief defines structures and exports for the standard 3D driver DLL used by Doom Legacy + +#ifndef _HWR_DATA_ +#define _HWR_DATA_ + +#if defined (_WIN32) && !defined (__CYGWIN__) && !defined (_XBOX) +//#define WIN32_LEAN_AND_MEAN +#define RPC_NO_WINDOWS_H +#include +#endif + +#if defined (VID_X11) && !defined (SDL) +#include +#endif + +#include "../doomdef.h" +//THIS MUST DISAPPEAR!!! +#include "hw_glide.h" +#include "../screen.h" + + +// ========================================================================== +// TEXTURE INFO +// ========================================================================== + +// grInfo.data holds the address of the graphics data cached in heap memory +// NULL if the texture is not in Doom heap cache. +struct GLMipmap_s +{ + GrTexInfo grInfo; //for TexDownloadMipMap + FxU32 flags; + UINT16 height; + UINT16 width; + UINT32 downloaded; // the dll driver have it in there cache ? + + struct GLMipmap_s *nextcolormap; + const UINT8 *colormap; + + // opengl + struct GLMipmap_s *nextmipmap; // opengl : liste of all texture in opengl driver +}; +typedef struct GLMipmap_s GLMipmap_t; + + +// +// Doom texture info, as cached for hardware rendering +// +struct GLTexture_s +{ + GLMipmap_t mipmap; + float scaleX; //used for scaling textures on walls + float scaleY; +}; +typedef struct GLTexture_s GLTexture_t; + + +// a cached patch as converted to hardware format, holding the original patch_t +// header so that the existing code can retrieve ->width, ->height as usual +// This is returned by W_CachePatchNum()/W_CachePatchName(), when rendermode +// is 'render_opengl'. Else it returns the normal patch_t data. + +struct GLPatch_s +{ + // the 4 first fields come right away from the original patch_t + INT16 width; + INT16 height; + INT16 leftoffset; // pixels to the left of origin + INT16 topoffset; // pixels below the origin + // + float max_s,max_t; + UINT16 wadnum; // the software patch lump num for when the hardware patch + UINT16 lumpnum; // was flushed, and we need to re-create it + GLMipmap_t mipmap; +} ATTRPACK; +typedef struct GLPatch_s GLPatch_t; + +#endif //_HWR_DATA_ diff --git a/src/hardware/hw_defs.h b/src/hardware/hw_defs.h new file mode 100644 index 000000000..98305da6d --- /dev/null +++ b/src/hardware/hw_defs.h @@ -0,0 +1,230 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright (C) 1998-2000 by DooM Legacy Team. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +//----------------------------------------------------------------------------- +/// \file +/// \brief 3D hardware renderer definitions + +#ifndef _HWR_DEFS_ +#define _HWR_DEFS_ +#include "../doomtype.h" + +#define ZCLIP_PLANE 4.0f +#define NZCLIP_PLANE 0.9f + +// ========================================================================== +// SIMPLE TYPES +// ========================================================================== + +typedef long FINT; +typedef unsigned long FUINT; +typedef unsigned char FUBYTE; +typedef unsigned long FBITFIELD; +#ifndef __MINGW32__ +typedef float FLOAT; +#endif +typedef unsigned char FBOOLEAN; + +// ========================================================================== +// COLORS +// ========================================================================== + +// byte value for paletted graphics, which represent the transparent color +#ifdef _NDS +// NDS is hardwired to use zero as transparent color +#define HWR_PATCHES_CHROMAKEY_COLORINDEX 0 +#define HWR_CHROMAKEY_EQUIVALENTCOLORINDEX 1 +#else +#define HWR_PATCHES_CHROMAKEY_COLORINDEX 247 +#define HWR_CHROMAKEY_EQUIVALENTCOLORINDEX 220 +#endif + +// the chroma key color shows on border sprites, set it to black +#define HWR_PATCHES_CHROMAKEY_COLORVALUE (0x00000000) //RGBA format as in grSstWinOpen() + +// RGBA Color components with float type ranging [ 0 ... 1 ] +struct FRGBAFloat +{ + FLOAT red; + FLOAT green; + FLOAT blue; + FLOAT alpha; +}; +typedef struct FRGBAFloat FRGBAFloat; + +struct FColorARGB +{ + FUBYTE alpha; + FUBYTE red; + FUBYTE green; + FUBYTE blue; +}; +typedef struct FColorARGB ARGB_t; +typedef struct FColorARGB FColorARGB; + + + +// ========================================================================== +// VECTORS +// ========================================================================== + +// Simple 2D coordinate +typedef struct +{ + FLOAT x,y; +} F2DCoord, v2d_t; + +// Simple 3D vector +typedef struct FVector +{ + FLOAT x,y,z; +} FVector; + +// 3D model vector (coords + texture coords) +typedef struct +{ + //FVector Point; + FLOAT x,y,z; + FLOAT s,t,w; // texture coordinates +} v3d_t, wallVert3D; + +//Hurdler: Transform (coords + angles) +//BP: transform order : scale(rotation_x(rotation_y(translation(v)))) +typedef struct +{ + FLOAT x,y,z; // position + FLOAT anglex,angley; // aimingangle / viewangle + FLOAT scalex,scaley,scalez; + FLOAT fovxangle, fovyangle; + INT32 splitscreen; +} FTransform; + +// Transformed vector, as passed to HWR API +typedef struct +{ + FLOAT x,y,z; + FUINT argb; // flat-shaded color + FLOAT sow; // s texture ordinate (s over w) + FLOAT tow; // t texture ordinate (t over w) +} FOutVector; + + +// ========================================================================== +// RENDER MODES +// ========================================================================== + +// Flags describing how to render a polygon +// You pass a combination of these flags to DrawPolygon() +enum EPolyFlags +{ + // the first 5 are mutually exclusive + + PF_Masked = 0x00000001, // Poly is alpha scaled and 0 alpha pels are discarded (holes in texture) + PF_Translucent = 0x00000002, // Poly is transparent, alpha = level of transparency + PF_Additive = 0x00000024, // Poly is added to the frame buffer + PF_Environment = 0x00000008, // Poly should be drawn environment mapped. + // Hurdler: used for text drawing + PF_Substractive = 0x00000010, // for splat + PF_NoAlphaTest = 0x00000020, // hiden param + PF_Blending = (PF_Environment|PF_Additive|PF_Translucent|PF_Masked|PF_Substractive)&~PF_NoAlphaTest, + + // other flag bits + + PF_Occlude = 0x00000100, // Update the depth buffer + PF_NoDepthTest = 0x00000200, // Disable the depth test mode + PF_Invisible = 0x00000400, // Disable write to color buffer + PF_Decal = 0x00000800, // Enable polygon offset + PF_Modulated = 0x00001000, // Modulation (multiply output with constant ARGB) + // When set, pass the color constant into the FSurfaceInfo -> FlatColor + PF_NoTexture = 0x00002000, // Use the small white texture + PF_Corona = 0x00004000, // Tell the rendrer we are drawing a corona + PF_MD2 = 0x00008000, // Tell the rendrer we are drawing an MD2 + PF_RemoveYWrap = 0x00010000, // Force clamp texture on Y + PF_ForceWrapX = 0x00020000, // Force repeat texture on X + PF_ForceWrapY = 0x00040000, // Force repeat texture on Y + PF_Clip = 0x40000000, // clip to frustum and nearz plane (glide only, automatic in opengl) + PF_NoZClip = 0x20000000, // in conjonction with PF_Clip + PF_Debug = 0x80000000 // print debug message in driver :) +}; + + +enum ESurfFlags +{ + SF_DYNLIGHT = 0x00000001, + +}; + +enum ETextureFlags +{ + TF_WRAPX = 0x00000001, // wrap around X + TF_WRAPY = 0x00000002, // wrap around Y + TF_WRAPXY = TF_WRAPY|TF_WRAPX, // very common so use alias is more easy + TF_CHROMAKEYED = 0x00000010, + TF_TRANSPARENT = 0x00000040, // texture with some alpha == 0 +}; + +#ifdef TODO +struct FTextureInfo +{ + FUINT Width; // Pixels + FUINT Height; // Pixels + FUBYTE *TextureData; // Image data + FUINT Format; // FORMAT_RGB, ALPHA ... + FBITFIELD Flags; // Flags to tell driver about texture (see ETextureFlags) + void DriverExtra; // (OpenGL texture object nr, ...) + // chromakey enabled,... + + struct FTextureInfo *Next; // Manage list of downloaded textures. +}; +#else +typedef struct GLMipmap_s FTextureInfo; +#endif + +// Description of a renderable surface +struct FSurfaceInfo +{ + FUINT PolyFlags; // Surface flags -- UNUSED YET -- + RGBA_t FlatColor; // Flat-shaded color used with PF_Modulated mode +}; +typedef struct FSurfaceInfo FSurfaceInfo; + +//Hurdler: added for backward compatibility +enum hwdsetspecialstate +{ + HWD_SET_FOG_TABLE = 1, + HWD_SET_FOG_MODE, + HWD_SET_FOG_COLOR, + HWD_SET_FOG_DENSITY, + HWD_SET_FOV, + HWD_SET_POLYGON_SMOOTH, + HWD_SET_PALETTECOLOR, + HWD_SET_TEXTUREFILTERMODE, + HWD_SET_TEXTUREANISOTROPICMODE, + HWD_NUMSTATE +}; + +typedef enum hwdsetspecialstate hwdspecialstate_t; + +enum hwdfiltermode +{ + HWD_SET_TEXTUREFILTER_POINTSAMPLED, + HWD_SET_TEXTUREFILTER_BILINEAR, + HWD_SET_TEXTUREFILTER_TRILINEAR, + HWD_SET_TEXTUREFILTER_MIXED1, + HWD_SET_TEXTUREFILTER_MIXED2, + HWD_SET_TEXTUREFILTER_MIXED3, +}; + + +#endif //_HWR_DEFS_ diff --git a/src/hardware/hw_dll.h b/src/hardware/hw_dll.h new file mode 100644 index 000000000..d9620be02 --- /dev/null +++ b/src/hardware/hw_dll.h @@ -0,0 +1,81 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright (C) 2005 by SRB2 Jr. Team. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +//----------------------------------------------------------------------------- +/// \file +/// \brief Win32 DLL and Shared Objects API definitions + +#ifndef __HWR_DLL_H__ +#define __HWR_DLL_H__ + +// Function declaration for exports from the DLL : +// EXPORT HWRAPI() (); +// If _CREATE_DLL_ is defined the above declaration translates to : +// __declspec(dllexport) WINAPI (); +// If _CREATE_DLL_ is NOT DEFINED the above declaration translates to : +// __declspec(dllexport) type> (WINAPI *) (); + +#ifdef _CREATE_DLL_ + #ifdef _WINDOWS + #ifdef __cplusplus + #define EXPORT extern "C" __declspec(dllexport) + #else + #define EXPORT __declspec(dllexport) + #endif + #else + #ifdef __cplusplus + #define EXPORT extern "C" + #else + #define EXPORT + #endif + #endif + #if defined (_WIN32) && !defined (_XBOX) + #define HWRAPI(fn) WINAPI fn + #else + #define HWRAPI(fn) fn + #endif +#else // _CREATE_DLL_ + #define EXPORT typedef + #if defined (_WIN32) && !defined (_XBOX) + #define HWRAPI(fn) (WINAPI *fn) + #else + #define HWRAPI(fn) (*fn) + #endif +#endif + +typedef void (*I_Error_t) (const char *error, ...); + +// ========================================================================== +// MATHS +// ========================================================================== + +// Constants +#ifndef M_PIl +#define M_PIl 3.1415926535897932384626433832795029L +#endif +#define DEGREE (0.017453292519943295769236907684883l) // 2*PI/360 + +void DBG_Printf(const char *lpFmt, ...) /*FUNCPRINTF*/; + +#ifdef _WINDOWS +BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved); +#elif defined (__CYGWIN__) +void _init() __attribute__((constructor)); +void _fini() __attribute__((destructor)); +#else +void _init(); +void _fini(); +#endif + +#endif diff --git a/src/hardware/hw_draw.c b/src/hardware/hw_draw.c new file mode 100644 index 000000000..6dc0f0f79 --- /dev/null +++ b/src/hardware/hw_draw.c @@ -0,0 +1,890 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright (C) 1998-2000 by DooM Legacy Team. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +//----------------------------------------------------------------------------- +/// \file +/// \brief miscellaneous drawing (mainly 2d) + +#ifdef __GNUC__ +#include +#endif + +#include "../doomdef.h" + +#ifdef HWRENDER +#include "hw_glob.h" +#include "hw_drv.h" + +#include "../m_misc.h" //FIL_WriteFile() +#include "../r_draw.h" //viewborderlump +#include "../r_main.h" +#include "../w_wad.h" +#include "../z_zone.h" +#include "../v_video.h" +#include "../st_stuff.h" + +#include +#include "../i_video.h" // for rendermode != render_glide + +#ifndef O_BINARY +#define O_BINARY 0 +#endif + +float gr_patch_scalex; +float gr_patch_scaley; + +#if defined(_MSC_VER) +#pragma pack(1) +#endif +typedef struct +{ + UINT8 id_field_length ; // 1 + UINT8 color_map_type ; // 2 + UINT8 image_type ; // 3 + UINT8 dummy[5] ; // 4, 8 + INT16 x_origin ; // 9, 10 + INT16 y_origin ; //11, 12 + INT16 width ; //13, 14 + INT16 height ; //15, 16 + UINT8 image_pix_size ; //17 + UINT8 image_descriptor; //18 +} ATTRPACK TGAHeader; // sizeof is 18 +#if defined(_MSC_VER) +#pragma pack() +#endif +typedef UINT8 GLRGB[3]; + +#define BLENDMODE PF_Translucent + +// +// -----------------+ +// HWR_DrawPatch : Draw a 'tile' graphic +// Notes : x,y : positions relative to the original Doom resolution +// : textes(console+score) + menus + status bar +// -----------------+ +void HWR_DrawPatch(GLPatch_t *gpatch, INT32 x, INT32 y, INT32 option) +{ + FOutVector v[4]; + FBITFIELD flags; + +// 3--2 +// | /| +// |/ | +// 0--1 + float sdupx = FIXED_TO_FLOAT(vid.fdupx)*2.0f; + float sdupy = FIXED_TO_FLOAT(vid.fdupy)*2.0f; + float pdupx = FIXED_TO_FLOAT(vid.fdupx)*2.0f; + float pdupy = FIXED_TO_FLOAT(vid.fdupy)*2.0f; + + // make patch ready in hardware cache + HWR_GetPatch(gpatch); + + switch (option & V_SCALEPATCHMASK) + { + case V_NOSCALEPATCH: + pdupx = pdupy = 2.0f; + break; + case V_SMALLSCALEPATCH: + pdupx = 2.0f * FIXED_TO_FLOAT(vid.fsmalldupx); + pdupy = 2.0f * FIXED_TO_FLOAT(vid.fsmalldupy); + break; + case V_MEDSCALEPATCH: + pdupx = 2.0f * FIXED_TO_FLOAT(vid.fmeddupx); + pdupy = 2.0f * FIXED_TO_FLOAT(vid.fmeddupy); + break; + } + + if (option & V_NOSCALESTART) + sdupx = sdupy = 2.0f; + + v[0].x = v[3].x = (x*sdupx-gpatch->leftoffset*pdupx)/vid.width - 1; + v[2].x = v[1].x = (x*sdupx+(gpatch->width-gpatch->leftoffset)*pdupx)/vid.width - 1; + v[0].y = v[1].y = 1-(y*sdupy-gpatch->topoffset*pdupy)/vid.height; + v[2].y = v[3].y = 1-(y*sdupy+(gpatch->height-gpatch->topoffset)*pdupy)/vid.height; + + v[0].z = v[1].z = v[2].z = v[3].z = 1.0f; + + v[0].sow = v[3].sow = 0.0f; + v[2].sow = v[1].sow = gpatch->max_s; + v[0].tow = v[1].tow = 0.0f; + v[2].tow = v[3].tow = gpatch->max_t; + + flags = BLENDMODE|PF_Clip|PF_NoZClip|PF_NoDepthTest; + + if (option & V_WRAPX) + flags |= PF_ForceWrapX; + if (option & V_WRAPY) + flags |= PF_ForceWrapY; + + // clip it since it is used for bunny scroll in doom I + if (option & V_TRANSLUCENT) + { + FSurfaceInfo Surf; + Surf.FlatColor.s.red = Surf.FlatColor.s.green = Surf.FlatColor.s.blue = 0xff; + Surf.FlatColor.s.alpha = (UINT8)cv_grtranslucenthud.value; + flags |= PF_Modulated; + HWD.pfnDrawPolygon(&Surf, v, 4, flags); + } + else + HWD.pfnDrawPolygon(NULL, v, 4, flags); +} + +void HWR_DrawSciencePatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, INT32 option, fixed_t scale) +{ + FOutVector v[4]; + FBITFIELD flags; + float cx = FIXED_TO_FLOAT(x); + float cy = FIXED_TO_FLOAT(y); + +// 3--2 +// | /| +// |/ | +// 0--1 + float sdupx = FIXED_TO_FLOAT(vid.fdupx)*2.0f; + float sdupy = FIXED_TO_FLOAT(vid.fdupy)*2.0f; + float pdupx = FIXED_TO_FLOAT(vid.fdupx)*2.0f*FIXED_TO_FLOAT(scale); + float pdupy = FIXED_TO_FLOAT(vid.fdupy)*2.0f*FIXED_TO_FLOAT(scale); + + // make patch ready in hardware cache + HWR_GetPatch(gpatch); + + switch (option & V_SCALEPATCHMASK) + { + case V_NOSCALEPATCH: + pdupx = pdupy = 2.0f; + break; + case V_SMALLSCALEPATCH: + pdupx = 2.0f * FIXED_TO_FLOAT(vid.fsmalldupx); + pdupy = 2.0f * FIXED_TO_FLOAT(vid.fsmalldupy); + break; + case V_MEDSCALEPATCH: + pdupx = 2.0f * FIXED_TO_FLOAT(vid.fmeddupx); + pdupy = 2.0f * FIXED_TO_FLOAT(vid.fmeddupy); + break; + } + + if (option & V_NOSCALESTART) + sdupx = sdupy = 2.0f; + + v[0].x = v[3].x = (cx*sdupx-gpatch->leftoffset*pdupx)/vid.width - 1; + v[2].x = v[1].x = (cx*sdupx+(gpatch->width-gpatch->leftoffset)*pdupx)/vid.width - 1; + v[0].y = v[1].y = 1-(cy*sdupy-gpatch->topoffset*pdupy)/vid.height; + v[2].y = v[3].y = 1-(cy*sdupy+(gpatch->height-gpatch->topoffset)*pdupy)/vid.height; + + v[0].z = v[1].z = v[2].z = v[3].z = 1.0f; + + v[0].sow = v[3].sow = 0.0f; + v[2].sow = v[1].sow = gpatch->max_s; + v[0].tow = v[1].tow = 0.0f; + v[2].tow = v[3].tow = gpatch->max_t; + + flags = BLENDMODE|PF_Clip|PF_NoZClip|PF_NoDepthTest; + + if (option & V_WRAPX) + flags |= PF_ForceWrapX; + if (option & V_WRAPY) + flags |= PF_ForceWrapY; + + // clip it since it is used for bunny scroll in doom I + if (option & V_TRANSLUCENT) + { + FSurfaceInfo Surf; + Surf.FlatColor.s.red = Surf.FlatColor.s.green = Surf.FlatColor.s.blue = 0xff; + Surf.FlatColor.s.alpha = (UINT8)cv_grtranslucenthud.value; + flags |= PF_Modulated; + HWD.pfnDrawPolygon(&Surf, v, 4, flags); + } + else + HWD.pfnDrawPolygon(NULL, v, 4, flags); +} + +void HWR_DrawClippedPatch (GLPatch_t *gpatch, INT32 x, INT32 y, INT32 option) +{ + // hardware clips the patch quite nicely anyway :) + HWR_DrawPatch(gpatch, x, y, option); /// \todo do real cliping +} + +// Only supports one kind of translucent for now. Tails 06-12-2003 +// Boked +// Alam_GBC: Why? you could not get a FSurfaceInfo to set the alpha channel? +void HWR_DrawTranslucentPatch (GLPatch_t *gpatch, INT32 x, INT32 y, INT32 option) +{ + FOutVector v[4]; + FBITFIELD flags; + +// 3--2 +// | /| +// |/ | +// 0--1 + float sdupx = FIXED_TO_FLOAT(vid.fdupx)*2.0f; + float sdupy = FIXED_TO_FLOAT(vid.fdupy)*2.0f; + float pdupx = FIXED_TO_FLOAT(vid.fdupx)*2.0f; + float pdupy = FIXED_TO_FLOAT(vid.fdupy)*2.0f; + FSurfaceInfo Surf; + + // make patch ready in hardware cache + HWR_GetPatch (gpatch); + + switch (option & V_SCALEPATCHMASK) + { + case V_NOSCALEPATCH: + pdupx = pdupy = 2.0f; + break; + case V_SMALLSCALEPATCH: + pdupx = 2.0f * FIXED_TO_FLOAT(vid.fsmalldupx); + pdupy = 2.0f * FIXED_TO_FLOAT(vid.fsmalldupy); + break; + case V_MEDSCALEPATCH: + pdupx = 2.0f * FIXED_TO_FLOAT(vid.fmeddupx); + pdupy = 2.0f * FIXED_TO_FLOAT(vid.fmeddupy); + break; + } + + if (option & V_NOSCALESTART) + sdupx = sdupy = 2.0f; + + v[0].x = v[3].x = (x*sdupx-gpatch->leftoffset*pdupx)/vid.width - 1; + v[2].x = v[1].x = (x*sdupx+(gpatch->width-gpatch->leftoffset)*pdupx)/vid.width - 1; + v[0].y = v[1].y = 1-(y*sdupy-gpatch->topoffset*pdupy)/vid.height; + v[2].y = v[3].y = 1-(y*sdupy+(gpatch->height-gpatch->topoffset)*pdupy)/vid.height; + + v[0].z = v[1].z = v[2].z = v[3].z = 1.0f; + + v[0].sow = v[3].sow = 0.0f; + v[2].sow = v[1].sow = gpatch->max_s; + v[0].tow = v[1].tow = 0.0f; + v[2].tow = v[3].tow = gpatch->max_t; + + flags = PF_Modulated | BLENDMODE | PF_Clip | PF_NoZClip | PF_NoDepthTest; + + if (option & V_WRAPX) + flags |= PF_ForceWrapX; + if (option & V_WRAPY) + flags |= PF_ForceWrapY; + + Surf.FlatColor.s.red = Surf.FlatColor.s.green = Surf.FlatColor.s.blue = 0xff; + // Alam_GBC: There, you have translucent HW Draw, OK? + if ((option & V_TRANSLUCENT) && cv_grtranslucenthud.value != 255) + { + Surf.FlatColor.s.alpha = (UINT8)(cv_grtranslucenthud.value/2); + } + else + Surf.FlatColor.s.alpha = 127; + + HWD.pfnDrawPolygon(&Surf, v, 4, flags); +} + +// Draws a patch 2x as small SSNTails 06-10-2003 +void HWR_DrawSmallPatch (GLPatch_t *gpatch, INT32 x, INT32 y, INT32 option, const UINT8 *colormap) +{ + FOutVector v[4]; + FBITFIELD flags; + + float sdupx = FIXED_TO_FLOAT(vid.fdupx); + float sdupy = FIXED_TO_FLOAT(vid.fdupy); + float pdupx = FIXED_TO_FLOAT(vid.fdupx); + float pdupy = FIXED_TO_FLOAT(vid.fdupy); + + // make patch ready in hardware cache + HWR_GetMappedPatch (gpatch, colormap); + + switch (option & V_SCALEPATCHMASK) + { + case V_NOSCALEPATCH: + pdupx = pdupy = 2.0f; + break; + case V_SMALLSCALEPATCH: + pdupx = 2.0f * FIXED_TO_FLOAT(vid.fsmalldupx); + pdupy = 2.0f * FIXED_TO_FLOAT(vid.fsmalldupy); + break; + case V_MEDSCALEPATCH: + pdupx = 2.0f * FIXED_TO_FLOAT(vid.fmeddupx); + pdupy = 2.0f * FIXED_TO_FLOAT(vid.fmeddupy); + break; + } + + if (option & V_NOSCALESTART) + sdupx = sdupy = 2.0f; + + v[0].x = v[3].x = (x*sdupx-gpatch->leftoffset*pdupx)/vid.width - 1; + v[2].x = v[1].x = (x*sdupx+(gpatch->width-gpatch->leftoffset)*pdupx)/vid.width - 1; + v[0].y = v[1].y = 1-(y*sdupy-gpatch->topoffset*pdupy)/vid.height; + v[2].y = v[3].y = 1-(y*sdupy+(gpatch->height-gpatch->topoffset)*pdupy)/vid.height; + + v[0].z = v[1].z = v[2].z = v[3].z = 1.0f; + + v[0].sow = v[3].sow = 0.0f; + v[2].sow = v[1].sow = gpatch->max_s; + v[0].tow = v[1].tow = 0.0f; + v[2].tow = v[3].tow = gpatch->max_t; + + flags = BLENDMODE | PF_Clip | PF_NoZClip | PF_NoDepthTest; + + if (option & V_WRAPX) + flags |= PF_ForceWrapX; + if (option & V_WRAPY) + flags |= PF_ForceWrapY; + + // clip it since it is used for bunny scroll in doom I + if (option & V_TRANSLUCENT) + { + FSurfaceInfo Surf; + Surf.FlatColor.s.red = Surf.FlatColor.s.green = Surf.FlatColor.s.blue = 0xff; + Surf.FlatColor.s.alpha = (UINT8)cv_grtranslucenthud.value; + flags |= PF_Modulated; + HWD.pfnDrawPolygon(&Surf, v, 4, flags); + } + else + HWD.pfnDrawPolygon(NULL, v, 4, flags); +} + +// +// HWR_DrawMappedPatch(): Like HWR_DrawPatch but with translated color +// +void HWR_DrawMappedPatch (GLPatch_t *gpatch, INT32 x, INT32 y, INT32 option, const UINT8 *colormap) +{ + FOutVector v[4]; + FBITFIELD flags; + + float sdupx = FIXED_TO_FLOAT(vid.fdupx)*2.0f; + float sdupy = FIXED_TO_FLOAT(vid.fdupy)*2.0f; + float pdupx = FIXED_TO_FLOAT(vid.fdupx)*2.0f; + float pdupy = FIXED_TO_FLOAT(vid.fdupy)*2.0f; + + // make patch ready in hardware cache + HWR_GetMappedPatch (gpatch, colormap); + + switch (option & V_SCALEPATCHMASK) + { + case V_NOSCALEPATCH: + pdupx = pdupy = 2.0f; + break; + case V_SMALLSCALEPATCH: + pdupx = 2.0f * FIXED_TO_FLOAT(vid.fsmalldupx); + pdupy = 2.0f * FIXED_TO_FLOAT(vid.fsmalldupy); + break; + case V_MEDSCALEPATCH: + pdupx = 2.0f * FIXED_TO_FLOAT(vid.fmeddupx); + pdupy = 2.0f * FIXED_TO_FLOAT(vid.fmeddupy); + break; + } + + if (option & V_NOSCALESTART) + sdupx = sdupy = 2.0f; + + v[0].x = v[3].x = (x*sdupx-gpatch->leftoffset*pdupx)/vid.width - 1; + v[2].x = v[1].x = (x*sdupx+(gpatch->width-gpatch->leftoffset)*pdupx)/vid.width - 1; + v[0].y = v[1].y = 1-(y*sdupy-gpatch->topoffset*pdupy)/vid.height; + v[2].y = v[3].y = 1-(y*sdupy+(gpatch->height-gpatch->topoffset)*pdupy)/vid.height; + + v[0].z = v[1].z = v[2].z = v[3].z = 1.0f; + + v[0].sow = v[3].sow = 0.0f; + v[2].sow = v[1].sow = gpatch->max_s; + v[0].tow = v[1].tow = 0.0f; + v[2].tow = v[3].tow = gpatch->max_t; + + flags = BLENDMODE | PF_Clip | PF_NoZClip | PF_NoDepthTest; + + if (option & V_WRAPX) + flags |= PF_ForceWrapX; + if (option & V_WRAPY) + flags |= PF_ForceWrapY; + + // clip it since it is used for bunny scroll in doom I + if (option & V_TRANSLUCENT) + { + FSurfaceInfo Surf; + Surf.FlatColor.s.red = Surf.FlatColor.s.green = Surf.FlatColor.s.blue = 0xff; + Surf.FlatColor.s.alpha = (UINT8)cv_grtranslucenthud.value; + flags |= PF_Modulated; + HWD.pfnDrawPolygon(&Surf, v, 4, flags); + } + else + HWD.pfnDrawPolygon(NULL, v, 4, flags); +} + +void HWR_DrawPic(INT32 x, INT32 y, lumpnum_t lumpnum) +{ + FOutVector v[4]; + const GLPatch_t *patch; + + // make pic ready in hardware cache + patch = HWR_GetPic(lumpnum); + +// 3--2 +// | /| +// |/ | +// 0--1 + + v[0].x = v[3].x = 2.0f * (float)x/vid.width - 1; + v[2].x = v[1].x = 2.0f * (float)(x + patch->width*FIXED_TO_FLOAT(vid.fdupx))/vid.width - 1; + v[0].y = v[1].y = 1.0f - 2.0f * (float)y/vid.height; + v[2].y = v[3].y = 1.0f - 2.0f * (float)(y + patch->height*FIXED_TO_FLOAT(vid.fdupy))/vid.height; + + v[0].z = v[1].z = v[2].z = v[3].z = 1.0f; + + v[0].sow = v[3].sow = 0; + v[2].sow = v[1].sow = patch->max_s; + v[0].tow = v[1].tow = 0; + v[2].tow = v[3].tow = patch->max_t; + + + //Hurdler: Boris, the same comment as above... but maybe for pics + // it not a problem since they don't have any transparent pixel + // if I'm right !? + // But then, the question is: why not 0 instead of PF_Masked ? + // or maybe PF_Environment ??? (like what I said above) + // BP: PF_Environment don't change anything ! and 0 is undifined + if (cv_grtranslucenthud.value != 255) + { + FSurfaceInfo Surf; + Surf.FlatColor.s.red = Surf.FlatColor.s.green = Surf.FlatColor.s.blue = 0xff; + Surf.FlatColor.s.alpha = (UINT8)cv_grtranslucenthud.value; + HWD.pfnDrawPolygon(&Surf, v, 4, PF_Modulated | BLENDMODE | PF_NoDepthTest | PF_Clip | PF_NoZClip); + } + else + HWD.pfnDrawPolygon(NULL, v, 4, BLENDMODE | PF_NoDepthTest | PF_Clip | PF_NoZClip); +} + +// ========================================================================== +// V_VIDEO.C STUFF +// ========================================================================== + + +// -------------------------------------------------------------------------- +// Fills a box of pixels using a flat texture as a pattern +// -------------------------------------------------------------------------- +void HWR_DrawFlatFill (INT32 x, INT32 y, INT32 w, INT32 h, lumpnum_t flatlumpnum) +{ + FOutVector v[4]; + double dflatsize; + INT32 flatflag; + const size_t len = W_LumpLength(flatlumpnum); + + switch (len) + { + case 4194304: // 2048x2048 lump + dflatsize = 2048.0f; + flatflag = 2047; + break; + case 1048576: // 1024x1024 lump + dflatsize = 1024.0f; + flatflag = 1023; + break; + case 262144:// 512x512 lump + dflatsize = 512.0f; + flatflag = 511; + break; + case 65536: // 256x256 lump + dflatsize = 256.0f; + flatflag = 255; + break; + case 16384: // 128x128 lump + dflatsize = 128.0f; + flatflag = 127; + break; + case 1024: // 32x32 lump + dflatsize = 32.0f; + flatflag = 31; + break; + default: // 64x64 lump + dflatsize = 64.0f; + flatflag = 63; + break; + } + +// 3--2 +// | /| +// |/ | +// 0--1 + + v[0].x = v[3].x = (x - 160.0f)/160.0f; + v[2].x = v[1].x = ((x+w) - 160.0f)/160.0f; + v[0].y = v[1].y = -(y - 100.0f)/100.0f; + v[2].y = v[3].y = -((y+h) - 100.0f)/100.0f; + + v[0].z = v[1].z = v[2].z = v[3].z = 1.0f; + + // flat is 64x64 lod and texture offsets are [0.0, 1.0] + v[0].sow = v[3].sow = (float)((x & flatflag)/dflatsize); + v[2].sow = v[1].sow = (float)(v[0].sow + w/dflatsize); + v[0].tow = v[1].tow = (float)((y & flatflag)/dflatsize); + v[2].tow = v[3].tow = (float)(v[0].tow + h/dflatsize); + + HWR_GetFlat(flatlumpnum); + + //Hurdler: Boris, the same comment as above... but maybe for pics + // it not a problem since they don't have any transparent pixel + // if I'm right !? + // BTW, I see we put 0 for PFs, and If I'm right, that + // means we take the previous PFs as default + // how can we be sure they are ok? + HWD.pfnDrawPolygon(NULL, v, 4, PF_NoDepthTest); //PF_Translucent); +} + + +// -------------------------------------------------------------------------- +// Fade down the screen so that the menu drawn on top of it looks brighter +// -------------------------------------------------------------------------- +// 3--2 +// | /| +// |/ | +// 0--1 +void HWR_FadeScreenMenuBack(UINT32 color, INT32 height) +{ + FOutVector v[4]; + FSurfaceInfo Surf; + + // setup some neat-o translucency effect + if (!height) //cool hack 0 height is full height + height = vid.height; + + v[0].x = v[3].x = -1.0f; + v[2].x = v[1].x = 1.0f; + v[0].y = v[1].y = 1.0f-((height<<1)/(float)vid.height); + v[2].y = v[3].y = 1.0f; + v[0].z = v[1].z = v[2].z = v[3].z = 1.0f; + + v[0].sow = v[3].sow = 0.0f; + v[2].sow = v[1].sow = 1.0f; + v[0].tow = v[1].tow = 1.0f; + v[2].tow = v[3].tow = 0.0f; + + Surf.FlatColor.rgba = UINT2RGBA(color); + Surf.FlatColor.s.alpha = (UINT8)((0xff/2) * ((float)height / vid.height)); //calum: varies console alpha + HWD.pfnDrawPolygon(&Surf, v, 4, PF_NoTexture|PF_Modulated|PF_Translucent|PF_NoDepthTest); +} + +// Draw the console background with translucency support +void HWR_DrawConsoleBack(UINT32 color, INT32 height) +{ + FOutVector v[4]; + FSurfaceInfo Surf; + + // setup some neat-o translucency effect + if (!height) //cool hack 0 height is full height + height = vid.height; + + v[0].x = v[3].x = -1.0f; + v[2].x = v[1].x = 1.0f; + v[0].y = v[1].y = 1.0f-((height<<1)/(float)vid.height); + v[2].y = v[3].y = 1.0f; + v[0].z = v[1].z = v[2].z = v[3].z = 1.0f; + + v[0].sow = v[3].sow = 0.0f; + v[2].sow = v[1].sow = 1.0f; + v[0].tow = v[1].tow = 1.0f; + v[2].tow = v[3].tow = 0.0f; + + Surf.FlatColor.rgba = UINT2RGBA(color); + Surf.FlatColor.s.alpha = 0x80; + + HWD.pfnDrawPolygon(&Surf, v, 4, PF_NoTexture|PF_Modulated|PF_Translucent|PF_NoDepthTest); +} + + +// ========================================================================== +// R_DRAW.C STUFF +// ========================================================================== + +// ------------------ +// HWR_DrawViewBorder +// Fill the space around the view window with a Doom flat texture, draw the +// beveled edges. +// 'clearlines' is useful to clear the heads up messages, when the view +// window is reduced, it doesn't refresh all the view borders. +// ------------------ +void HWR_DrawViewBorder(INT32 clearlines) +{ + INT32 x, y; + INT32 top, side; + INT32 baseviewwidth, baseviewheight; + INT32 basewindowx, basewindowy; + GLPatch_t *patch; + +// if (gr_viewwidth == vid.width) +// return; + + if (!clearlines) + clearlines = BASEVIDHEIGHT; // refresh all + + // calc view size based on original game resolution + baseviewwidth = FixedInt(FixedDiv(FLOAT_TO_FIXED(gr_viewwidth), vid.fdupx)); //(cv_viewsize.value * BASEVIDWIDTH/10)&~7; + baseviewheight = FixedInt(FixedDiv(FLOAT_TO_FIXED(gr_viewheight), vid.fdupy)); + top = FixedInt(FixedDiv(FLOAT_TO_FIXED(gr_baseviewwindowy), vid.fdupy)); + side = FixedInt(FixedDiv(FLOAT_TO_FIXED(gr_viewwindowx), vid.fdupx)); + + // top + HWR_DrawFlatFill(0, 0, + BASEVIDWIDTH, (top < clearlines ? top : clearlines), + st_borderpatchnum); + + // left + if (top < clearlines) + HWR_DrawFlatFill(0, top, side, + (clearlines-top < baseviewheight ? clearlines-top : baseviewheight), + st_borderpatchnum); + + // right + if (top < clearlines) + HWR_DrawFlatFill(side + baseviewwidth, top, side, + (clearlines-top < baseviewheight ? clearlines-top : baseviewheight), + st_borderpatchnum); + + // bottom + if (top + baseviewheight < clearlines) + HWR_DrawFlatFill(0, top + baseviewheight, + BASEVIDWIDTH, BASEVIDHEIGHT, st_borderpatchnum); + + // + // draw the view borders + // + + basewindowx = (BASEVIDWIDTH - baseviewwidth)>>1; + if (baseviewwidth == BASEVIDWIDTH) + basewindowy = 0; + else + basewindowy = top; + + // top edge + if (clearlines > basewindowy - 8) + { + patch = W_CachePatchNum(viewborderlump[BRDR_T], PU_CACHE); + for (x = 0; x < baseviewwidth; x += 8) + HWR_DrawPatch(patch, basewindowx + x, basewindowy - 8, + 0); + } + + // bottom edge + if (clearlines > basewindowy + baseviewheight) + { + patch = W_CachePatchNum(viewborderlump[BRDR_B], PU_CACHE); + for (x = 0; x < baseviewwidth; x += 8) + HWR_DrawPatch(patch, basewindowx + x, + basewindowy + baseviewheight, 0); + } + + // left edge + if (clearlines > basewindowy) + { + patch = W_CachePatchNum(viewborderlump[BRDR_L], PU_CACHE); + for (y = 0; y < baseviewheight && basewindowy + y < clearlines; + y += 8) + { + HWR_DrawPatch(patch, basewindowx - 8, basewindowy + y, + 0); + } + } + + // right edge + if (clearlines > basewindowy) + { + patch = W_CachePatchNum(viewborderlump[BRDR_R], PU_CACHE); + for (y = 0; y < baseviewheight && basewindowy+y < clearlines; + y += 8) + { + HWR_DrawPatch(patch, basewindowx + baseviewwidth, + basewindowy + y, 0); + } + } + + // Draw beveled corners. + if (clearlines > basewindowy - 8) + HWR_DrawPatch(W_CachePatchNum(viewborderlump[BRDR_TL], + PU_CACHE), + basewindowx - 8, basewindowy - 8, 0); + + if (clearlines > basewindowy - 8) + HWR_DrawPatch(W_CachePatchNum(viewborderlump[BRDR_TR], + PU_CACHE), + basewindowx + baseviewwidth, basewindowy - 8, 0); + + if (clearlines > basewindowy+baseviewheight) + HWR_DrawPatch(W_CachePatchNum(viewborderlump[BRDR_BL], + PU_CACHE), + basewindowx - 8, basewindowy + baseviewheight, 0); + + if (clearlines > basewindowy + baseviewheight) + HWR_DrawPatch(W_CachePatchNum(viewborderlump[BRDR_BR], + PU_CACHE), + basewindowx + baseviewwidth, + basewindowy + baseviewheight, 0); +} + + +// ========================================================================== +// AM_MAP.C DRAWING STUFF +// ========================================================================== + +// Clear the automap part of the screen +void HWR_clearAutomap(void) +{ + FRGBAFloat fColor = {0, 0, 0, 1}; + + // minx,miny,maxx,maxy + HWD.pfnGClipRect(0, 0, vid.width, vid.height, NZCLIP_PLANE); + HWD.pfnClearBuffer(true, true, &fColor); + HWD.pfnGClipRect(0, 0, vid.width, vid.height, NZCLIP_PLANE); +} + + +// -----------------+ +// HWR_drawAMline : draw a line of the automap (the clipping is already done in automap code) +// Arg : color is a RGB 888 value +// -----------------+ +void HWR_drawAMline(const fline_t *fl, INT32 color) +{ + F2DCoord v1, v2; + RGBA_t color_rgba; + + color_rgba = V_GetColor(color); + + v1.x = ((float)fl->a.x-(vid.width/2.0f))*(2.0f/vid.width); + v1.y = ((float)fl->a.y-(vid.height/2.0f))*(2.0f/vid.height); + + v2.x = ((float)fl->b.x-(vid.width/2.0f))*(2.0f/vid.width); + v2.y = ((float)fl->b.y-(vid.height/2.0f))*(2.0f/vid.height); + + HWD.pfnDraw2DLine(&v1, &v2, color_rgba); +} + + +// -----------------+ +// HWR_DrawFill : draw flat coloured rectangle, with no texture +// -----------------+ +void HWR_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 color) +{ + FOutVector v[4]; + FSurfaceInfo Surf; + +// 3--2 +// | /| +// |/ | +// 0--1 + v[0].x = v[3].x = (x - 160.0f)/160.0f; + v[2].x = v[1].x = ((x+w) - 160.0f)/160.0f; + v[0].y = v[1].y = -(y - 100.0f)/100.0f; + v[2].y = v[3].y = -((y+h) - 100.0f)/100.0f; + + //Hurdler: do we still use this argb color? if not, we should remove it + v[0].argb = v[1].argb = v[2].argb = v[3].argb = 0xff00ff00; //; + v[0].z = v[1].z = v[2].z = v[3].z = 1.0f; + + v[0].sow = v[3].sow = 0.0f; + v[2].sow = v[1].sow = 1.0f; + v[0].tow = v[1].tow = 0.0f; + v[2].tow = v[3].tow = 1.0f; + + Surf.FlatColor = V_GetColor(color); + + HWD.pfnDrawPolygon(&Surf, v, 4, + PF_Modulated|PF_NoTexture|PF_NoDepthTest); +} + +#ifdef HAVE_PNG + +#ifndef _MSC_VER +#ifndef _LARGEFILE64_SOURCE +#define _LARGEFILE64_SOURCE +#endif +#endif + +#ifndef _LFS64_LARGEFILE +#define _LFS64_LARGEFILE +#endif + +#ifndef _FILE_OFFSET_BITS +#define _FILE_OFFSET_BITS 0 +#endif + + #include "png.h" + #ifdef PNG_WRITE_SUPPORTED + #define USE_PNG // PNG is only used if write is supported (see ../m_misc.c) + #endif +#endif + +#ifndef USE_PNG +// -------------------------------------------------------------------------- +// save screenshots with TGA format +// -------------------------------------------------------------------------- +static inline boolean saveTGA(const char *file_name, void *buffer, + INT32 width, INT32 height) +{ + INT32 fd; + TGAHeader tga_hdr; + INT32 i; + UINT8 *buf8 = buffer; + + fd = open(file_name, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666); + if (fd < 0) + return false; + + memset(&tga_hdr, 0, sizeof (tga_hdr)); + tga_hdr.width = SHORT(width); + tga_hdr.height = SHORT(height); + tga_hdr.image_pix_size = 24; + tga_hdr.image_type = 2; + tga_hdr.image_descriptor = 32; + + write(fd, &tga_hdr, sizeof (TGAHeader)); + // format to 888 BGR + for (i = 0; i < width * height * 3; i+=3) + { + const UINT8 temp = buf8[i]; + buf8[i] = buf8[i+2]; + buf8[i+2] = temp; + } + write(fd, buffer, width * height * 3); + close(fd); + return true; +} +#endif + +// -------------------------------------------------------------------------- +// screen shot +// -------------------------------------------------------------------------- + +UINT8 *HWR_GetScreenshot(void) +{ + UINT8 *buf = malloc(vid.width * vid.height * 3 * sizeof (*buf)); + + if (!buf) + return NULL; + // returns 24bit 888 RGB + HWD.pfnReadRect(0, 0, vid.width, vid.height, vid.width * 3, (void *)buf); + return buf; +} + +boolean HWR_Screenshot(const char *lbmname) +{ + boolean ret; + UINT8 *buf = malloc(vid.width * vid.height * 3 * sizeof (*buf)); + + if (!buf) + return false; + + // returns 24bit 888 RGB + HWD.pfnReadRect(0, 0, vid.width, vid.height, vid.width * 3, (void *)buf); + +#ifdef USE_PNG + ret = M_SavePNG(lbmname, buf, vid.width, vid.height, NULL); +#else + ret = saveTGA(lbmname, buf, vid.width, vid.height); +#endif + free(buf); + return ret; +} + +#endif //HWRENDER diff --git a/src/hardware/hw_drv.h b/src/hardware/hw_drv.h new file mode 100644 index 000000000..854e7aaaf --- /dev/null +++ b/src/hardware/hw_drv.h @@ -0,0 +1,142 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright (C) 1998-2000 by DooM Legacy Team. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +//----------------------------------------------------------------------------- +/// \file +/// \brief imports/exports for the 3D hardware low-level interface API + +#ifndef __HWR_DRV_H__ +#define __HWR_DRV_H__ + +// this must be here 19991024 by Kin +#include "../screen.h" +#include "hw_data.h" +#include "hw_defs.h" +#include "hw_md2.h" + +#include "hw_dll.h" + +// ========================================================================== +// STANDARD DLL EXPORTS +// ========================================================================== + +#ifdef SDL +#undef VID_X11 +#endif + +EXPORT boolean HWRAPI(Init) (I_Error_t ErrorFunction); +#ifndef SDL +EXPORT void HWRAPI(Shutdown) (void); +#endif +#ifdef _WINDOWS +EXPORT void HWRAPI(GetModeList) (vmode_t **pvidmodes, INT32 *numvidmodes); +#endif +#ifdef VID_X11 +EXPORT Window HWRAPI(HookXwin) (Display *, INT32, INT32, boolean); +#endif +#if defined (PURESDL) || defined (macintosh) +EXPORT void HWRAPI(SetPalette) (INT32 *, RGBA_t *gamma); +#else +EXPORT void HWRAPI(SetPalette) (RGBA_t *ppal, RGBA_t *pgamma); +#endif +EXPORT void HWRAPI(FinishUpdate) (INT32 waitvbl); +EXPORT void HWRAPI(Draw2DLine) (F2DCoord *v1, F2DCoord *v2, RGBA_t Color); +EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags); +EXPORT void HWRAPI(SetBlend) (FBITFIELD PolyFlags); +EXPORT void HWRAPI(ClearBuffer) (FBOOLEAN ColorMask, FBOOLEAN DepthMask, FRGBAFloat *ClearColor); +EXPORT void HWRAPI(SetTexture) (FTextureInfo *TexInfo); +EXPORT void HWRAPI(ReadRect) (INT32 x, INT32 y, INT32 width, INT32 height, INT32 dst_stride, UINT16 *dst_data); +EXPORT void HWRAPI(GClipRect) (INT32 minx, INT32 miny, INT32 maxx, INT32 maxy, float nearclip); +EXPORT void HWRAPI(ClearMipMapCache) (void); + +//Hurdler: added for backward compatibility +EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value); + +//Hurdler: added for new development +EXPORT void HWRAPI(DrawMD2) (INT32 *gl_cmd_buffer, md2_frame_t *frame, FTransform *pos, float scale); +EXPORT void HWRAPI(DrawMD2i) (INT32 *gl_cmd_buffer, md2_frame_t *frame, UINT32 duration, UINT32 tics, md2_frame_t *nextframe, FTransform *pos, float scale, UINT8 flipped, UINT8 *color); +EXPORT void HWRAPI(SetTransform) (FTransform *ptransform); +EXPORT INT32 HWRAPI(GetTextureUsed) (void); +EXPORT INT32 HWRAPI(GetRenderVersion) (void); + +#ifdef VID_X11 // ifdef to be removed as soon as windoze supports that as well +// metzgermeister: added for Voodoo detection +EXPORT char *HWRAPI(GetRenderer) (void); +#endif +#ifdef SHUFFLE +#define SCREENVERTS 10 +EXPORT void HWRAPI(PostImgRedraw) (float points[SCREENVERTS][SCREENVERTS][2]); +#endif +EXPORT void HWRAPI(StartScreenWipe) (void); +EXPORT void HWRAPI(EndScreenWipe) (void); +EXPORT void HWRAPI(DoScreenWipe) (float alpha); +EXPORT void HWRAPI(DrawIntermissionBG) (void); +EXPORT void HWRAPI(MakeScreenTexture) (void); +// ========================================================================== +// HWR DRIVER OBJECT, FOR CLIENT PROGRAM +// ========================================================================== + +#if !defined (_CREATE_DLL_) + +struct hwdriver_s +{ + Init pfnInit; + SetPalette pfnSetPalette; + FinishUpdate pfnFinishUpdate; + Draw2DLine pfnDraw2DLine; + DrawPolygon pfnDrawPolygon; + SetBlend pfnSetBlend; + ClearBuffer pfnClearBuffer; + SetTexture pfnSetTexture; + ReadRect pfnReadRect; + GClipRect pfnGClipRect; + ClearMipMapCache pfnClearMipMapCache; + SetSpecialState pfnSetSpecialState;//Hurdler: added for backward compatibility + DrawMD2 pfnDrawMD2; + DrawMD2i pfnDrawMD2i; + SetTransform pfnSetTransform; + GetTextureUsed pfnGetTextureUsed; + GetRenderVersion pfnGetRenderVersion; +#ifdef _WINDOWS + GetModeList pfnGetModeList; +#endif +#ifdef VID_X11 + HookXwin pfnHookXwin; + GetRenderer pfnGetRenderer; +#endif +#ifndef SDL + Shutdown pfnShutdown; +#endif +#ifdef SHUFFLE + PostImgRedraw pfnPostImgRedraw; +#endif + StartScreenWipe pfnStartScreenWipe; + EndScreenWipe pfnEndScreenWipe; + DoScreenWipe pfnDoScreenWipe; + DrawIntermissionBG pfnDrawIntermissionBG; + MakeScreenTexture pfnMakeScreenTexture; +}; + +extern struct hwdriver_s hwdriver; + +//Hurdler: 16/10/99: added for OpenGL gamma correction +//extern RGBA_t gamma_correction; + +#define HWD hwdriver + +#endif //not defined _CREATE_DLL_ + +#endif //__HWR_DRV_H__ + diff --git a/src/hardware/hw_glide.h b/src/hardware/hw_glide.h new file mode 100644 index 000000000..2625d5864 --- /dev/null +++ b/src/hardware/hw_glide.h @@ -0,0 +1,71 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright (C) 1998-2000 by DooM Legacy Team. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +//----------------------------------------------------------------------------- +/// \file +/// \brief Declaration needed by Glide renderer +/// !!! To be replaced by our own def in the future !!! + +#ifndef _GLIDE_H_ +#define _GLIDE_H_ + +#ifndef __GLIDE_H__ + +typedef unsigned long FxU32; +typedef long FxI32; + +typedef FxI32 GrAspectRatio_t; +#define GR_ASPECT_LOG2_8x1 3 /* 8W x 1H */ +#define GR_ASPECT_LOG2_4x1 2 /* 4W x 1H */ +#define GR_ASPECT_LOG2_2x1 1 /* 2W x 1H */ +#define GR_ASPECT_LOG2_1x1 0 /* 1W x 1H */ +#define GR_ASPECT_LOG2_1x2 -1 /* 1W x 2H */ +#define GR_ASPECT_LOG2_1x4 -2 /* 1W x 4H */ +#define GR_ASPECT_LOG2_1x8 -3 /* 1W x 8H */ + +typedef FxI32 GrLOD_t; +#define GR_LOD_LOG2_256 0x8 +#define GR_LOD_LOG2_128 0x7 +#define GR_LOD_LOG2_64 0x6 +#define GR_LOD_LOG2_32 0x5 +#define GR_LOD_LOG2_16 0x4 +#define GR_LOD_LOG2_8 0x3 +#define GR_LOD_LOG2_4 0x2 +#define GR_LOD_LOG2_2 0x1 +#define GR_LOD_LOG2_1 0x0 + +typedef FxI32 GrTextureFormat_t; +#define GR_TEXFMT_ALPHA_8 0x2 /* (0..0xFF) alpha */ +#define GR_TEXFMT_INTENSITY_8 0x3 /* (0..0xFF) intensity */ +#define GR_TEXFMT_ALPHA_INTENSITY_44 0x4 +#define GR_TEXFMT_P_8 0x5 /* 8-bit palette */ +#define GR_TEXFMT_RGB_565 0xa +#define GR_TEXFMT_ARGB_1555 0xb +#define GR_TEXFMT_ARGB_4444 0xc +#define GR_TEXFMT_ALPHA_INTENSITY_88 0xd +#define GR_TEXFMT_AP_88 0xe /* 8-bit alpha 8-bit palette */ +#define GR_RGBA 0x6 // 32 bit RGBA ! + +typedef struct +{ + GrLOD_t smallLodLog2; + GrLOD_t largeLodLog2; + GrAspectRatio_t aspectRatioLog2; + GrTextureFormat_t format; + void *data; +} GrTexInfo; + +#endif // __GLIDE_H__ (defined in ) + +#endif // _GLIDE_H_ diff --git a/src/hardware/hw_glob.h b/src/hardware/hw_glob.h new file mode 100644 index 000000000..ee84e8b10 --- /dev/null +++ b/src/hardware/hw_glob.h @@ -0,0 +1,122 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright (C) 1998-2000 by DooM Legacy Team. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +//----------------------------------------------------------------------------- +/// \file +/// \brief globals (shared data & code) for hw_ modules + +#ifndef _HWR_GLOB_H_ +#define _HWR_GLOB_H_ + +#include "hw_defs.h" +#include "hw_main.h" +#include "../m_misc.h" + +// the original aspect ratio of Doom graphics isn't square +#define ORIGINAL_ASPECT (320.0f/200.0f) + +// ----------- +// structures +// ----------- + +// a vertex of a Doom 'plane' polygon +typedef struct +{ + float x; + float y; +//#ifdef SLOPENESS + float z; +//#endif +} polyvertex_t; + +#ifdef _MSC_VER +#pragma warning(disable : 4200) +#endif + +// a convex 'plane' polygon, clockwise order +typedef struct +{ + INT32 numpts; + polyvertex_t pts[0]; +} poly_t; + +#ifdef _MSC_VER +#pragma warning(default : 4200) +#endif + +// holds extra info for 3D render, for each subsector in subsectors[] +typedef struct +{ + poly_t *planepoly; // the generated convex polygon +} extrasubsector_t; + +// needed for sprite rendering +// equivalent of the software renderer's vissprites +typedef struct gr_vissprite_s +{ + // Doubly linked list + struct gr_vissprite_s *prev; + struct gr_vissprite_s *next; + float x1, x2; + float tz, ty; + lumpnum_t patchlumpnum; + boolean flip; + UINT8 translucency; //alpha level 0-255 + mobj_t *mobj; + boolean precip; // Tails 08-25-2002 + boolean vflip; + //Hurdler: 25/04/2000: now support colormap in hardware mode + UINT8 *colormap; +} gr_vissprite_t; + +// -------- +// hw_bsp.c +// -------- +extern extrasubsector_t *extrasubsectors; +extern size_t addsubsector; + +void HWR_InitPolyPool(void); +void HWR_FreePolyPool(void); + +// -------- +// hw_cache.c +// -------- +void HWR_InitTextureCache(void); +void HWR_FreeTextureCache(void); +void HWR_FreeExtraSubsectors(void); + +void HWR_GetFlat(lumpnum_t flatlumpnum); +GLTexture_t *HWR_GetTexture(INT32 tex); +void HWR_GetPatch(GLPatch_t *gpatch); +void HWR_GetMappedPatch(GLPatch_t *gpatch, const UINT8 *colormap); +void HWR_UnlockCachedPatch(GLPatch_t *gpatch); +GLPatch_t *HWR_GetPic(lumpnum_t lumpnum); +void HWR_SetPalette(RGBA_t *palette); +GLPatch_t *HWR_GetCachedGLPatchPwad(UINT16 wad, UINT16 lump); +GLPatch_t *HWR_GetCachedGLPatch(lumpnum_t lumpnum); + +// -------- +// hw_draw.c +// -------- +extern float gr_patch_scalex; +extern float gr_patch_scaley; + +extern consvar_t cv_grrounddown; // on/off + +extern INT32 patchformat; +extern INT32 textureformat; +extern boolean firetranslucent; + +#endif //_HW_GLOB_ diff --git a/src/hardware/hw_light.c b/src/hardware/hw_light.c new file mode 100644 index 000000000..ee68edd41 --- /dev/null +++ b/src/hardware/hw_light.c @@ -0,0 +1,1332 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright (C) 1998-2000 by DooM Legacy Team. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +//----------------------------------------------------------------------------- +/// \file +/// \brief Corona/Dynamic/Static lighting add on by Hurdler +/// !!! Under construction !!! + +#include "../doomdef.h" + +#ifdef HWRENDER +#include "hw_light.h" +#include "hw_drv.h" +#include "../i_video.h" +#include "../z_zone.h" +#include "../m_random.h" +#include "../m_bbox.h" +#include "../w_wad.h" +#include "../r_state.h" +#include "../r_main.h" +#include "../p_local.h" + +//============================================================================= +// DEFINES +//============================================================================= + +#define DL_SQRRADIUS(x) dynlights->p_lspr[(x)]->dynamic_sqrradius +#define DL_RADIUS(x) dynlights->p_lspr[(x)]->dynamic_radius +#define LIGHT_POS(i) dynlights->position[(i)] + +#define DL_HIGH_QUALITY +//#define STATICLIGHT //Hurdler: TODO! +//#define LIGHTMAPFLAGS (PF_Masked|PF_Clip|PF_NoAlphaTest) // debug see overdraw +#define LIGHTMAPFLAGS (PF_Modulated|PF_Additive|PF_Clip) + +#ifdef ALAM_LIGHTING +static dynlights_t view_dynlights[2]; // 2 players in splitscreen mode +static dynlights_t *dynlights = &view_dynlights[0]; +#endif + +#define UNDEFINED_SPR 0x0 // actually just for testing +#define CORONA_SPR 0x1 // a light source which only emit a corona +#define DYNLIGHT_SPR 0x2 // a light source which is only used for dynamic lighting +#define LIGHT_SPR (DYNLIGHT_SPR|CORONA_SPR) +#define ROCKET_SPR (DYNLIGHT_SPR|CORONA_SPR|0x10) +//#define MONSTER_SPR 4 +//#define AMMO_SPR 8 +//#define BONUS_SPR 16 + +//Hurdler: now we can change those values via FS :) +light_t lspr[NUMLIGHTS] = +{ + // type offset x, y coronas color, c_size,light color,l_radius, sqr radius computed at init + // UNDEFINED: 0 + { UNDEFINED_SPR, 0.0f, 0.0f, 0x00000000, 24.0f, 0x00000000, 0.0f, 0.0f}, + // weapons + // RINGSPARK_L + { LIGHT_SPR, 0.0f, 0.0f, 0x0000e0ff, 16.0f, 0x0000e0ff, 32.0f, 0.0f}, // Tails 09-08-2002 + // SUPERSONIC_L + { DYNLIGHT_SPR, 0.0f, 0.0f, 0xff00e0ff, 32.0f, 0xff00e0ff, 128.0f, 0.0f}, // Tails 09-08-2002 + // SUPERSPARK_L + { LIGHT_SPR, 0.0f, 0.0f, 0xe0ffffff, 8.0f, 0xe0ffffff, 64.0f, 0.0f}, + // INVINCIBLE_L + { DYNLIGHT_SPR, 0.0f, 0.0f, 0x10ffaaaa, 16.0f, 0x10ffaaaa, 128.0f, 0.0f}, + // GREENSHIELD_L + { DYNLIGHT_SPR, 0.0f, 0.0f, 0x602b7337, 32.0f, 0x602b7337, 128.0f, 0.0f}, + // BLUESHIELD_L + { DYNLIGHT_SPR, 0.0f, 0.0f, 0x60cb0000, 32.0f, 0x60cb0000, 128.0f, 0.0f}, + + // tall lights + // YELLOWSHIELD_L + { DYNLIGHT_SPR, 0.0f, 0.0f, 0x601f7baf, 32.0f, 0x601f7baf, 128.0f, 0.0f}, + + // REDSHIELD_L + { DYNLIGHT_SPR, 0.0f, 0.0f, 0x600000cb, 32.0f, 0x600000cb, 128.0f, 0.0f}, + + // BLACKSHIELD_L // Black light? lol + { DYNLIGHT_SPR, 0.0f, 0.0f, 0x60010101, 32.0f, 0x60ff00ff, 128.0f, 0.0f}, + + // WHITESHIELD_L + { DYNLIGHT_SPR, 0.0f, 0.0f, 0x60ffffff, 32.0f, 0x60ffffff, 128.0f, 0.0f}, + + // SMALLREDBALL_L + { DYNLIGHT_SPR, 0.0f, 0.0f, 0x606060f0, 0.0f, 0x302070ff, 32.0f, 0.0f}, + + // small lights + // RINGLIGHT_L + { DYNLIGHT_SPR, 0.0f, 0.0f, 0x60b0f0f0, 0.0f, 0x30b0f0f0, 100.0f, 0.0f}, + // GREENSMALL_L + { LIGHT_SPR, 0.0f, 14.0f, 0x6070ff70, 60.0f, 0x4070ff70, 100.0f, 0.0f}, + // REDSMALL_L + { LIGHT_SPR, 0.0f, 14.0f, 0x705070ff, 60.0f, 0x405070ff, 100.0f, 0.0f}, + + // type offset x, y coronas color, c_size,light color,l_radius, sqr radius computed at init + // GREENSHINE_L + { LIGHT_SPR, 0.0f, 0.0f, 0xff00ff00, 64.0f, 0xff00ff00, 256.0f, 0.0f}, + // ORANGESHINE_L + { LIGHT_SPR, 0.0f, 0.0f, 0xff0080ff, 64.0f, 0xff0080ff, 256.0f, 0.0f}, + // PINKSHINE_L + { LIGHT_SPR, 0.0f, 0.0f, 0xffe080ff, 64.0f, 0xffe080ff, 256.0f, 0.0f}, + // BLUESHINE_L + { LIGHT_SPR, 0.0f, 0.0f, 0xffff0000, 64.0f, 0xffff0000, 256.0f, 0.0f}, + // REDSHINE_L + { LIGHT_SPR, 0.0f, 0.0f, 0xff0000ff, 64.0f, 0xff0000ff, 256.0f, 0.0f}, + // LBLUESHINE_L + { LIGHT_SPR, 0.0f, 0.0f, 0xffff8080, 64.0f, 0xffff8080, 256.0f, 0.0f}, + // GREYSHINE_L + { LIGHT_SPR, 0.0f, 0.0f, 0xffe0e0e0, 64.0f, 0xffe0e0e0, 256.0f, 0.0f}, + + // monsters + // REDBALL_L + { DYNLIGHT_SPR, 0.0f, 0.0f, 0x606060ff, 0.0f, 0x606060ff, 100.0f, 0.0f}, + // GREENBALL_L + { DYNLIGHT_SPR, 0.0f, 0.0f, 0x6060ff60, 120.0f, 0x6060ff60, 100.0f, 0.0f}, + // BLUEBALL_L + { DYNLIGHT_SPR, 0.0f, 0.0f, 0x60ff6060, 120.0f, 0x60ff6060, 100.0f, 0.0f}, + + // NIGHTSLIGHT_L + { LIGHT_SPR, 0.0f, 6.0f, 0x60ffffff, 16.0f, 0x30ffffff, 32.0f, 0.0f}, + + // JETLIGHT_L + { DYNLIGHT_SPR, 0.0f, 6.0f, 0x60ffaaaa, 16.0f, 0x30ffaaaa, 64.0f, 0.0f}, + + // GOOPLIGHT_L + { DYNLIGHT_SPR, 0.0f, 6.0f, 0x60ff00ff, 16.0f, 0x30ff00ff, 32.0f, 0.0f}, + + // STREETLIGHT_L + { LIGHT_SPR, 0.0f, 0.0f, 0xe0ffffff, 64.0f, 0xe0ffffff, 384.0f, 0.0f}, +}; + +light_t *t_lspr[NUMSPRITES] = +{ + &lspr[NOLIGHT], // SPR_NULL + &lspr[NOLIGHT], // SPR_UNKN + + &lspr[NOLIGHT], // SPR_THOK + &lspr[SUPERSONIC_L],// SPR_PLAY + + // Enemies + &lspr[NOLIGHT], // SPR_POSS + &lspr[NOLIGHT], // SPR_SPOS + &lspr[NOLIGHT], // SPR_FISH + &lspr[NOLIGHT], // SPR_BUZZ Graue 03-10-2004 + &lspr[NOLIGHT], // SPR_RBUZ Graue 03-10-2004 + &lspr[NOLIGHT], // SPR_JETB + &lspr[NOLIGHT], // SPR_JETW + &lspr[NOLIGHT], // SPR_JETG + &lspr[NOLIGHT], // SPR_CCOM + &lspr[NOLIGHT], // SPR_DETN + &lspr[NOLIGHT], // SPR_SKIM + &lspr[NOLIGHT], // SPR_TRET + &lspr[NOLIGHT], // SPR_TURR + &lspr[NOLIGHT], // SPR_SHRP + &lspr[NOLIGHT], // SPR_JJAW + &lspr[NOLIGHT], // SPR_SNLR + &lspr[NOLIGHT], // SPR_VLTR + &lspr[NOLIGHT], // SPR_PNTY + &lspr[NOLIGHT], // SPR_ARCH + &lspr[NOLIGHT], // SPR_CBFS + &lspr[NOLIGHT], // SPR_SPSH + &lspr[NOLIGHT], // SPR_ESHI + &lspr[NOLIGHT], // SPR_GSNP + &lspr[NOLIGHT], // SPR_MNUS + &lspr[NOLIGHT], // SPR_SSHL + &lspr[NOLIGHT], // SPR_UNID + &lspr[NOLIGHT], // SPR_BBUZ + + // Generic Boos Items + &lspr[JETLIGHT_L], // SPR_JETF // Boss jet fumes + + // Boss 1, (Greenflower) + &lspr[NOLIGHT], // SPR_EGGM + + // Boss 2, (Techno Hill) + &lspr[NOLIGHT], // SPR_EGGN + &lspr[NOLIGHT], // SPR_TNKA + &lspr[NOLIGHT], // SPR_TNKB + &lspr[NOLIGHT], // SPR_SPNK + &lspr[NOLIGHT], // SPR_GOOP + + // Boss 3 (Deep Sea) + &lspr[NOLIGHT], // SPR_EGGO + &lspr[NOLIGHT], // SPR_PRPL + &lspr[NOLIGHT], // SPR_FAKE + + // Boss 4 (Castle Eggman) + &lspr[NOLIGHT], // SPR_EGGP + &lspr[REDBALL_L], // SPR_EFIR + + // Boss 5 (Arid Canyon) + &lspr[NOLIGHT], // SPR_EGGQ + + // Boss 6 (Red Volcano) + &lspr[NOLIGHT], // SPR_EEGR + + // Boss 7 (Dark City) + &lspr[NOLIGHT], // SPR_BRAK + &lspr[NOLIGHT], // SPR_BGOO + &lspr[NOLIGHT], // SPR_BMSL + + // Boss 8 (Egg Rock) + &lspr[NOLIGHT], // SPR_EGGT + + &lspr[NOLIGHT], //SPR_RCKT + &lspr[NOLIGHT], //SPR_ELEC + &lspr[NOLIGHT], //SPR_TARG + &lspr[NOLIGHT], //SPR_NPLM + &lspr[NOLIGHT], //SPR_MNPL + + // Metal Sonic + &lspr[NOLIGHT], // SPR_METL + &lspr[NOLIGHT], // SPR_MSCF + &lspr[NOLIGHT], // SPR_MSCB + + // Collectible Items + &lspr[NOLIGHT], // SPR_RING + &lspr[NOLIGHT], // SPR_TRNG + &lspr[NOLIGHT], // SPR_EMMY + &lspr[BLUEBALL_L], // SPR_TOKE + &lspr[REDBALL_L], // SPR_RFLG + &lspr[BLUEBALL_L], // SPR_BFLG + &lspr[NOLIGHT], // SPR_NWNG + &lspr[NOLIGHT], // SPR_EMBM + &lspr[NOLIGHT], // SPR_CEMG + &lspr[NOLIGHT], // SPR_EMER + + // Interactive Objects + &lspr[NOLIGHT], // SPR_FANS + &lspr[NOLIGHT], // SPR_BUBL + &lspr[NOLIGHT], // SPR_SIGN + &lspr[NOLIGHT], // SPR_STEM + &lspr[NOLIGHT], // SPR_SPIK + &lspr[NOLIGHT], // SPR_SFLM + &lspr[NOLIGHT], // SPR_USPK + &lspr[NOLIGHT], // SPR_STPT + &lspr[NOLIGHT], // SPR_BMNE + + // Monitor Boxes + &lspr[NOLIGHT], // SPR_SRBX + &lspr[NOLIGHT], // SPR_RRBX + &lspr[NOLIGHT], // SPR_BRBX + &lspr[NOLIGHT], // SPR_SHTV + &lspr[NOLIGHT], // SPR_PINV + &lspr[NOLIGHT], // SPR_YLTV + &lspr[NOLIGHT], // SPR_BLTV + &lspr[NOLIGHT], // SPR_BKTV + &lspr[NOLIGHT], // SPR_WHTV + &lspr[NOLIGHT], // SPR_GRTV + &lspr[NOLIGHT], // SPR_ELTV + &lspr[NOLIGHT], // SPR_EGGB + &lspr[NOLIGHT], // SPR_MIXU + &lspr[NOLIGHT], // SPR_RECY + &lspr[NOLIGHT], // SPR_QUES + &lspr[NOLIGHT], // SPR_GBTV + &lspr[NOLIGHT], // SPR_PRUP + &lspr[NOLIGHT], // SPR_PTTV + + // Monitor Miscellany + &lspr[NOLIGHT], // SPR_MTEX + + // Projectiles + &lspr[NOLIGHT], // SPR_MISL + &lspr[NOLIGHT], // SPR_TORP + &lspr[NOLIGHT], // SPR_ENRG + &lspr[NOLIGHT], // SPR_MINE + &lspr[NOLIGHT], // SPR_JBUL + &lspr[SMALLREDBALL_L], // SPR_TRLS + &lspr[NOLIGHT], // SPR_CBLL + &lspr[NOLIGHT], // SPR_AROW + + // Greenflower Scenery + &lspr[NOLIGHT], // SPR_FWR1 + &lspr[NOLIGHT], // SPR_FWR2 + &lspr[NOLIGHT], // SPR_FWR3 + &lspr[NOLIGHT], // SPR_FWR4 + &lspr[NOLIGHT], // SPR_BUS1 + &lspr[NOLIGHT], // SPR_BUS2 + + // Techno Hill Scenery + &lspr[NOLIGHT], // SPR_THZP + &lspr[REDBALL_L], // SPR_ALRM + + // Deep Sea Scenery + &lspr[NOLIGHT], // SPR_GARG + &lspr[NOLIGHT], // SPR_SEWE + &lspr[NOLIGHT], // SPR_DRIP + &lspr[NOLIGHT], // SPR_CRL1 + &lspr[NOLIGHT], // SPR_CRL2 + &lspr[NOLIGHT], // SPR_CRL3 + &lspr[NOLIGHT], // SPR_BCRY + + // Castle Eggman Scenery + &lspr[NOLIGHT], // SPR_CHAN + &lspr[REDBALL_L], // SPR_FLAM + &lspr[NOLIGHT], // SPR_ESTA + &lspr[NOLIGHT], // SPR_SMCH + &lspr[NOLIGHT], // SPR_BMCH + &lspr[NOLIGHT], // SPR_SMCE + &lspr[NOLIGHT], // SPR_BMCE + + // Arid Canyon Scenery + &lspr[NOLIGHT], // SPR_BTBL + &lspr[NOLIGHT], // SPR_STBL + &lspr[NOLIGHT], // SPR_CACT + + // Red Volcano Scenery + &lspr[REDBALL_L], // SPR_FLME + &lspr[REDBALL_L], // SPR_DFLM + + // Dark City Scenery + + // Egg Rock Scenery + + // Christmas Scenery + &lspr[NOLIGHT], // SPR_XMS1 + &lspr[NOLIGHT], // SPR_XMS2 + &lspr[NOLIGHT], // SPR_XMS3 + + // Botanic Serenity Scenery + &lspr[NOLIGHT], // SPR_BSZ1 + &lspr[NOLIGHT], // SPR_BSZ2 + &lspr[NOLIGHT], // SPR_BSZ3 + &lspr[NOLIGHT], // SPR_BSZ4 + &lspr[NOLIGHT], // SPR_BSZ5 + &lspr[NOLIGHT], // SPR_BSZ6 + &lspr[NOLIGHT], // SPR_BSZ7 + &lspr[NOLIGHT], // SPR_BSZ8 + + // Stalagmites + &lspr[NOLIGHT], // SPR_STLG + + // Disco Ball + &lspr[NOLIGHT], // SPR_DBAL + + // ATZ Red Crystal + &lspr[NOLIGHT], // SPR_RCRY + + // Powerup Indicators + &lspr[NOLIGHT], // SPR_ARMA + &lspr[NOLIGHT], // SPR_ARMF + &lspr[NOLIGHT], // SPR_ARMB + &lspr[NOLIGHT], // SPR_WIND + &lspr[NOLIGHT], // SPR_MAGN + &lspr[NOLIGHT], // SPR_ELEM + &lspr[NOLIGHT], // SPR_FORC + &lspr[NOLIGHT], // SPR_PITY + &lspr[INVINCIBLE_L], // SPR_IVSP + &lspr[SUPERSPARK_L], // SPR_SSPK + + &lspr[NOLIGHT], // SPR_GOAL + + // Freed Animals + &lspr[NOLIGHT], // SPR_BIRD + &lspr[NOLIGHT], // SPR_BUNY + &lspr[NOLIGHT], // SPR_MOUS + &lspr[NOLIGHT], // SPR_CHIC + &lspr[NOLIGHT], // SPR_COWZ + &lspr[NOLIGHT], // SPR_RBRD + + // Springs + &lspr[NOLIGHT], // SPR_SPRY + &lspr[NOLIGHT], // SPR_SPRR + &lspr[NOLIGHT], // SPR_SPRB Graue + &lspr[NOLIGHT], // SPR_YSPR + &lspr[NOLIGHT], // SPR_RSPR + + // Environmentals Effects + &lspr[NOLIGHT], // SPR_RAIN + &lspr[NOLIGHT], // SPR_SNO1 + &lspr[NOLIGHT], // SPR_SPLH + &lspr[NOLIGHT], // SPR_SPLA + &lspr[NOLIGHT], // SPR_SMOK + &lspr[NOLIGHT], // SPR_BUBP + &lspr[NOLIGHT], // SPR_BUBO + &lspr[NOLIGHT], // SPR_BUBN + &lspr[NOLIGHT], // SPR_BUBM + &lspr[NOLIGHT], // SPR_POPP + &lspr[SUPERSPARK_L], // SPR_TFOG + &lspr[NIGHTSLIGHT_L], // SPR_SEED // Sonic CD flower seed + &lspr[NOLIGHT], // SPR_PRTL + + // Game Indicators + &lspr[NOLIGHT], // SPR_SCOR + &lspr[NOLIGHT], // SPR_DRWN + &lspr[NOLIGHT], // SPR_TTAG + &lspr[NOLIGHT], // SPR_GFLG + + // Ring Weapons + &lspr[RINGLIGHT_L], // SPR_RRNG + &lspr[RINGLIGHT_L], // SPR_RNGB + &lspr[RINGLIGHT_L], // SPR_RNGR + &lspr[RINGLIGHT_L], // SPR_RNGI + &lspr[RINGLIGHT_L], // SPR_RNGA + &lspr[RINGLIGHT_L], // SPR_RNGE + &lspr[RINGLIGHT_L], // SPR_RNGS + &lspr[RINGLIGHT_L], // SPR_RNGG + + &lspr[RINGLIGHT_L], // SPR_PIKB + &lspr[RINGLIGHT_L], // SPR_PIKR + &lspr[RINGLIGHT_L], // SPR_PIKA + &lspr[RINGLIGHT_L], // SPR_PIKE + &lspr[RINGLIGHT_L], // SPR_PIKS + &lspr[RINGLIGHT_L], // SPR_PIKG + + &lspr[RINGLIGHT_L], // SPR_TAUT + &lspr[RINGLIGHT_L], // SPR_TGRE + &lspr[RINGLIGHT_L], // SPR_TSCR + + // Mario-specific stuff + &lspr[NOLIGHT], // SPR_COIN + &lspr[NOLIGHT], // SPR_CPRK + &lspr[NOLIGHT], // SPR_GOOM + &lspr[NOLIGHT], // SPR_BGOM + &lspr[REDBALL_L], // SPR_FFWR + &lspr[SMALLREDBALL_L], // SPR_FBLL + &lspr[NOLIGHT], // SPR_SHLL + &lspr[REDBALL_L], // SPR_PUMA + &lspr[NOLIGHT], // SPR_HAMM + &lspr[NOLIGHT], // SPR_KOOP + &lspr[REDBALL_L], // SPR_BFLM + &lspr[NOLIGHT], // SPR_MAXE + &lspr[NOLIGHT], // SPR_MUS1 + &lspr[NOLIGHT], // SPR_MUS2 + &lspr[NOLIGHT], // SPR_TOAD + + // NiGHTS Stuff + &lspr[SUPERSONIC_L], // SPR_NDRN // NiGHTS drone + &lspr[SUPERSONIC_L], // SPR_SUPE // NiGHTS character flying + &lspr[SUPERSONIC_L], // SPR_SUPZ // NiGHTS hurt + &lspr[SUPERSONIC_L], // SPR_NDRL // NiGHTS character drilling + &lspr[NOLIGHT], // SPR_NSPK + &lspr[NOLIGHT], // SPR_NBMP + &lspr[NOLIGHT], // SPR_HOOP + &lspr[NOLIGHT], // SPR_HSCR + &lspr[NOLIGHT], // SPR_NPRU + &lspr[NOLIGHT], // SPR_CAPS + &lspr[SUPERSONIC_L], // SPR_SUPT + + // Debris + &lspr[RINGSPARK_L], // SPR_SPRK + &lspr[NOLIGHT], // SPR_BOM1 + &lspr[SUPERSPARK_L], // SPR_BOM2 + &lspr[SUPERSPARK_L], // SPR_BOM3 + &lspr[NOLIGHT], // SPR_BOM4 + + // Crumbly rocks + &lspr[NOLIGHT], // SPR_ROIA + &lspr[NOLIGHT], // SPR_ROIB + &lspr[NOLIGHT], // SPR_ROIC + &lspr[NOLIGHT], // SPR_ROID + &lspr[NOLIGHT], // SPR_ROIE + &lspr[NOLIGHT], // SPR_ROIF + &lspr[NOLIGHT], // SPR_ROIG + &lspr[NOLIGHT], // SPR_ROIH + &lspr[NOLIGHT], // SPR_ROII + &lspr[NOLIGHT], // SPR_ROIJ + &lspr[NOLIGHT], // SPR_ROIK + &lspr[NOLIGHT], // SPR_ROIL + &lspr[NOLIGHT], // SPR_ROIM + &lspr[NOLIGHT], // SPR_ROIN + &lspr[NOLIGHT], // SPR_ROIO + &lspr[NOLIGHT], // SPR_ROIP + + // Blue Spheres + &lspr[NOLIGHT], // SPR_BBAL + + // Gravity Well Objects + &lspr[NOLIGHT], // SPR_GWLG + &lspr[NOLIGHT], // SPR_GWLR + + // SRB1 Sprites + &lspr[NOLIGHT], // SPR_SRBA + &lspr[NOLIGHT], // SPR_SRBB + &lspr[NOLIGHT], // SPR_SRBC + &lspr[NOLIGHT], // SPR_SRBD + &lspr[NOLIGHT], // SPR_SRBE + &lspr[NOLIGHT], // SPR_SRBF + &lspr[NOLIGHT], // SPR_SRBG + &lspr[NOLIGHT], // SPR_SRBH + &lspr[NOLIGHT], // SPR_SRBI + &lspr[NOLIGHT], // SPR_SRBJ + &lspr[NOLIGHT], // SPR_SRBK + &lspr[NOLIGHT], // SPR_SRBL + &lspr[NOLIGHT], // SPR_SRBM + &lspr[NOLIGHT], // SPR_SRBN + &lspr[NOLIGHT], // SPR_SRBO + + // Free slots + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], + &lspr[NOLIGHT], +}; + +#ifdef ALAM_LIGHTING + +//============================================================================= +// PROTOS +//============================================================================= + +static void HWR_SetLight(void); + +// -------------------------------------------------------------------------- +// calcul la projection d'un point sur une droite (determin� par deux +// points) et ensuite calcul la distance (au carr� de ce point au point +// project�sur cette droite +// -------------------------------------------------------------------------- +static float HWR_DistP2D(FOutVector *p1, FOutVector *p2, FVector *p3, FVector *inter) +{ + if (p1->z == p2->z) + { + inter->x = p3->x; + inter->z = p1->z; + } + else if (p1->x == p2->x) + { + inter->x = p1->x; + inter->z = p3->z; + } + else + { + register float local, pente; + // Wat een mooie formula! Hurdler's math;-) + pente = (p1->z-p2->z) / (p1->x-p2->x); + local = p1->z - p1->x*pente; + inter->x = (p3->z - local + p3->x/pente) * (pente/(pente*pente+1)); + inter->z = inter->x*pente + local; + } + + return (p3->x-inter->x)*(p3->x-inter->x) + (p3->z-inter->z)*(p3->z-inter->z); +} + +// check if sphere (radius r) centred in p3 touch the bounding box defined by p1, p2 +static boolean SphereTouchBBox3D(FOutVector *p1, FOutVector *p2, FVector *p3, float r) +{ + float minx = p1->x,maxx = p2->x,miny = p2->y,maxy = p1->y,minz = p2->z,maxz = p1->z; + + if (minx > maxx) + { + minx = maxx; + maxx = p1->x; + } + if (miny > maxy) + { + miny = maxy; + maxy = p2->y; + } + if (minz > maxz) + { + minz = maxz; + maxz = p2->z; + } + + if (minx-r > p3->x) return false; + if (maxx+r < p3->x) return false; + if (miny-r > p3->y) return false; + if (maxy+r < p3->y) return false; + if (minz-r > p3->z) return false; + if (maxz+r < p3->z) return false; + return true; +} + +// Hurdler: The old code was removed by me because I don't think it will be used one day. +// (It's still available on the CVS for educational purpose: Revision 1.8) + +// -------------------------------------------------------------------------- +// calcul du dynamic lighting sur les murs +// lVerts contient les coords du mur sans le mlook (up/down) +// -------------------------------------------------------------------------- +void HWR_WallLighting(FOutVector *wlVerts) +{ + int i, j; + + // dynlights->nb == 0 if cv_grdynamiclighting.value is not set + for (j = 0; j < dynlights->nb; j++) + { + FVector inter; + FSurfaceInfo Surf; + float dist_p2d, d[4], s; + + // check bounding box first + if (SphereTouchBBox3D(&wlVerts[2], &wlVerts[0], &LIGHT_POS(j), DL_RADIUS(j))==false) + continue; + d[0] = wlVerts[2].x - wlVerts[0].x; + d[1] = wlVerts[2].z - wlVerts[0].z; + d[2] = LIGHT_POS(j).x - wlVerts[0].x; + d[3] = LIGHT_POS(j).z - wlVerts[0].z; + // backface cull + if (d[2]*d[1] - d[3]*d[0] < 0) + continue; + // check exact distance + dist_p2d = HWR_DistP2D(&wlVerts[2], &wlVerts[0], &LIGHT_POS(j), &inter); + if (dist_p2d >= DL_SQRRADIUS(j)) + continue; + + d[0] = (float)sqrt((wlVerts[0].x-inter.x)*(wlVerts[0].x-inter.x) + + (wlVerts[0].z-inter.z)*(wlVerts[0].z-inter.z)); + d[1] = (float)sqrt((wlVerts[2].x-inter.x)*(wlVerts[2].x-inter.x) + + (wlVerts[2].z-inter.z)*(wlVerts[2].z-inter.z)); + //dAB = sqrtf((wlVerts[0].x-wlVerts[2].x)*(wlVerts[0].x-wlVerts[2].x)+(wlVerts[0].z-wlVerts[2].z)*(wlVerts[0].z-wlVerts[2].z)); + //if ((d[0] < dAB) && (d[1] < dAB)) // test if the intersection is on the wall + //{ + // d[0] = -d[0]; // if yes, the left distcance must be negative for texcoord + //} + // test if the intersection is on the wall + if ((wlVerts[0].x < inter.x && wlVerts[2].x > inter.x) || + (wlVerts[0].x > inter.x && wlVerts[2].x < inter.x) || + (wlVerts[0].z < inter.z && wlVerts[2].z > inter.z) || + (wlVerts[0].z > inter.z && wlVerts[2].z < inter.z)) + { + d[0] = -d[0]; // if yes, the left distcance must be negative for texcoord + } + d[2] = d[1]; d[3] = d[0]; +#ifdef DL_HIGH_QUALITY + s = 0.5f / DL_RADIUS(j); +#else + s = 0.5f / sqrtf(DL_SQRRADIUS(j)-dist_p2d); +#endif + for (i = 0; i < 4; i++) + { + wlVerts[i].sow = (float)(0.5f + d[i]*s); + wlVerts[i].tow = (float)(0.5f + (wlVerts[i].y-LIGHT_POS(j).y)*s*1.2f); + } + + HWR_SetLight(); + + Surf.FlatColor.rgba = LONG(dynlights->p_lspr[j]->dynamic_color); +#ifdef DL_HIGH_QUALITY + Surf.FlatColor.s.alpha = (UINT8)((1-dist_p2d/DL_SQRRADIUS(j))*Surf.FlatColor.s.alpha); +#endif + if (!dynlights->mo[j]->state) + return; + // next state is null so fade out with alpha + if (dynlights->mo[j]->state->nextstate == S_NULL) + Surf.FlatColor.s.alpha = (UINT8)(((float)dynlights->mo[j]->tics/(float)dynlights->mo[j]->state->tics)*Surf.FlatColor.s.alpha); + + HWD.pfnDrawPolygon (&Surf, wlVerts, 4, LIGHTMAPFLAGS); + + } // end for (j = 0; j < dynlights->nb; j++) +} + +// -------------------------------------------------------------------------- +// calcul du dynamic lighting sur le sol +// clVerts contient les coords du sol avec le mlook (up/down) +// -------------------------------------------------------------------------- +void HWR_PlaneLighting(FOutVector *clVerts, int nrClipVerts) +{ + int i, j; + FOutVector p1,p2; + + p1.z = FIXED_TO_FLOAT(hwbbox[BOXTOP ]); + p1.x = FIXED_TO_FLOAT(hwbbox[BOXLEFT ]); + p2.z = FIXED_TO_FLOAT(hwbbox[BOXBOTTOM]); + p2.x = FIXED_TO_FLOAT(hwbbox[BOXRIGHT ]); + p2.y = clVerts[0].y; + p1.y = clVerts[0].y; + + for (j = 0; j < dynlights->nb; j++) + { + FSurfaceInfo Surf; + float dist_p2d, s; + + // BP: The kickass Optimization: check if light touch bounding box + if (SphereTouchBBox3D(&p1, &p2, &dynlights->position[j], DL_RADIUS(j))==false) + continue; + // backface cull + //Hurdler: doesn't work with new TANDL code + if ((clVerts[0].y > atransform.z) // true mean it is a ceiling false is a floor + ^ (LIGHT_POS(j).y < clVerts[0].y)) // true mean light is down plane false light is up plane + continue; + dist_p2d = (clVerts[0].y-LIGHT_POS(j).y); + dist_p2d *= dist_p2d; + // done in SphereTouchBBox3D + //if (dist_p2d >= DL_SQRRADIUS(j)) + // continue; + +#ifdef DL_HIGH_QUALITY + s = 0.5f / DL_RADIUS(j); +#else + s = 0.5f / sqrtf(DL_SQRRADIUS(j)-dist_p2d); +#endif + for (i = 0; i < nrClipVerts; i++) + { + clVerts[i].sow = 0.5f + (clVerts[i].x-LIGHT_POS(j).x)*s; + clVerts[i].tow = 0.5f + (clVerts[i].z-LIGHT_POS(j).z)*s*1.2f; + } + + HWR_SetLight(); + + Surf.FlatColor.rgba = LONG(dynlights->p_lspr[j]->dynamic_color); +#ifdef DL_HIGH_QUALITY + Surf.FlatColor.s.alpha = (unsigned char)((1 - dist_p2d/DL_SQRRADIUS(j))*Surf.FlatColor.s.alpha); +#endif + if (!dynlights->mo[j]->state) + return; + // next state is null so fade out with alpha + if ((dynlights->mo[j]->state->nextstate == S_NULL)) + Surf.FlatColor.s.alpha = (unsigned char)(((float)dynlights->mo[j]->tics/(float)dynlights->mo[j]->state->tics)*Surf.FlatColor.s.alpha); + + HWD.pfnDrawPolygon (&Surf, clVerts, nrClipVerts, LIGHTMAPFLAGS); + + } // end for (j = 0; j < dynlights->nb; j++) +} + + +static lumpnum_t coronalumpnum = LUMPERROR; +#ifndef NEWCORONAS +// -------------------------------------------------------------------------- +// coronas lighting +// -------------------------------------------------------------------------- +void HWR_DoCoronasLighting(FOutVector *outVerts, gr_vissprite_t *spr) +{ + light_t *p_lspr; + + if (coronalumpnum == LUMPERROR) + return; + + //CONS_Debug(DBG_RENDER, "sprite (type): %d (%s)\n", spr->type, sprnames[spr->type]); + p_lspr = t_lspr[spr->mobj->sprite]; + if ((spr->mobj->state>=&states[S_EXPLODE1] && spr->mobj->state<=&states[S_EXPLODE3]) + || (spr->mobj->state>=&states[S_FATSHOTX1] && spr->mobj->state<=&states[S_FATSHOTX3])) + { + p_lspr = &lspr[ROCKETEXP_L]; + } + + if (cv_grcoronas.value && (p_lspr->type & CORONA_SPR)) + { // it's an object which emits light + FOutVector light[4]; + FSurfaceInfo Surf; + float cx = 0.0f, cy = 0.0f, cz = 0.0f; // gravity center + float size; + UINT8 i; + + switch (p_lspr->type) + { + case LIGHT_SPR: + size = p_lspr->corona_radius * ((outVerts[0].z+120.0f)/950.0f); // d'ou vienne ces constante ? + break; + case ROCKET_SPR: + p_lspr->corona_color = (((M_Random()>>1)&0xff)<<24)|0x0040ff; + // don't need a break + case CORONA_SPR: + size = p_lspr->corona_radius * ((outVerts[0].z+60.0f)/100.0f); // d'ou vienne ces constante ? + break; + default: + I_Error("HWR_DoCoronasLighting: unknow light type %d",p_lspr->type); + return; + } + if (size > p_lspr->corona_radius) + size = p_lspr->corona_radius; + size *= FIXED_TO_FLOAT(cv_grcoronasize.value<<1); + + // compute position doing average + for (i = 0; i < 4; i++) + { + cx += outVerts[i].x; + cy += outVerts[i].y; + cz += outVerts[i].z; + } + cx /= 4.0f; cy /= 4.0f; cz /= 4.0f; + + // more realistique corona ! + if (cz >= 255*8+250) + return; + Surf.FlatColor.rgba = p_lspr->corona_color; + if (cz > 250.0f) + Surf.FlatColor.s.alpha = 0xff-((int)cz-250)/8; + else + Surf.FlatColor.s.alpha = 0xff; + + // do not be hide by sprite of the light itself ! + cz = cz - 2.0f; + + // Bp; je comprend pas, ou est la rotation haut/bas ? + // tu ajoute un offset a y mais si la tu la reguarde de haut + // sa devrais pas marcher ... comprend pas :( + // (...) bon je croit que j'ai comprit il est tout pourit le code ? + // car comme l'offset est minime sa ce voit pas ! + light[0].x = cx-size; light[0].z = cz; + light[0].y = cy-size*1.33f+p_lspr->light_yoffset; + light[0].sow = 0.0f; light[0].tow = 0.0f; + + light[1].x = cx+size; light[1].z = cz; + light[1].y = cy-size*1.33f+p_lspr->light_yoffset; + light[1].sow = 1.0f; light[1].tow = 0.0f; + + light[2].x = cx+size; light[2].z = cz; + light[2].y = cy+size*1.33f+p_lspr->light_yoffset; + light[2].sow = 1.0f; light[2].tow = 1.0f; + + light[3].x = cx-size; light[3].z = cz; + light[3].y = cy+size*1.33f+p_lspr->light_yoffset; + light[3].sow = 0.0f; light[3].tow = 1.0f; + + HWR_GetPic(coronalumpnum); /// \todo use different coronas + + HWD.pfnDrawPolygon (&Surf, light, 4, PF_Modulated | PF_Additive | PF_Clip | PF_Corona | PF_NoDepthTest); + } +} +#endif + +#ifdef NEWCORONAS +// use the lightlist of the frame to draw the coronas at the top of everythink +void HWR_DrawCoronas(void) +{ + int j; + + if (!cv_grcoronas.value || dynlights->nb <= 0 || coronalumpnum == LUMPERROR) + return; + + HWR_GetPic(coronalumpnum); /// \todo use different coronas + for (j = 0;j < dynlights->nb;j++) + { + FOutVector light[4]; + FSurfaceInfo Surf; + float cx = LIGHT_POS(j).x; + float cy = LIGHT_POS(j).y; + float cz = LIGHT_POS(j).z; // gravity center + float size; + light_t *p_lspr = dynlights->p_lspr[j]; + + // it's an object which emits light + if (!(p_lspr->type & CORONA_SPR)) + continue; + + transform(&cx,&cy,&cz); + + // more realistique corona ! + if (cz >= 255*8+250) + continue; + Surf.FlatColor.rgba = p_lspr->corona_color; + if (cz > 250.0f) + Surf.FlatColor.s.alpha = (UINT8)(0xff-(UINT8)(((int)cz-250)/8)); + else + Surf.FlatColor.s.alpha = 0xff; + + switch (p_lspr->type) + { + case LIGHT_SPR: + size = p_lspr->corona_radius * ((cz+120.0f)/950.0f); // d'ou vienne ces constante ? + break; + case ROCKET_SPR: + Surf.FlatColor.s.alpha = (UINT8)((M_Random()>>1)&0xff); + // don't need a break + case CORONA_SPR: + size = p_lspr->corona_radius * ((cz+60.0f)/100.0f); // d'ou vienne ces constante ? + break; + default: + I_Error("HWR_DoCoronasLighting: unknow light type %d",p_lspr->type); + continue; + } + if (size > p_lspr->corona_radius) + size = p_lspr->corona_radius; + size = (float)(FIXED_TO_FLOAT(cv_grcoronasize.value<<1)*size); + + // put light little forward the sprite so there is no + // z-buffer problem (coplanar polygons) + // BP: use PF_Decal do not help :( + cz = cz - 5.0f; + + light[0].x = cx-size; light[0].z = cz; + light[0].y = cy-size*1.33f; + light[0].sow = 0.0f; light[0].tow = 0.0f; + + light[1].x = cx+size; light[1].z = cz; + light[1].y = cy-size*1.33f; + light[1].sow = 1.0f; light[1].tow = 0.0f; + + light[2].x = cx+size; light[2].z = cz; + light[2].y = cy+size*1.33f; + light[2].sow = 1.0f; light[2].tow = 1.0f; + + light[3].x = cx-size; light[3].z = cz; + light[3].y = cy+size*1.33f; + light[3].sow = 0.0f; light[3].tow = 1.0f; + + HWD.pfnDrawPolygon (&Surf, light, 4, PF_Modulated | PF_Additive | PF_Clip | PF_NoDepthTest | PF_Corona); + } +} +#endif + +// -------------------------------------------------------------------------- +// Remove all the dynamic lights at eatch frame +// -------------------------------------------------------------------------- +void HWR_ResetLights(void) +{ + dynlights->nb = 0; +} + +// -------------------------------------------------------------------------- +// Change view, thus change lights (splitscreen) +// -------------------------------------------------------------------------- +void HWR_SetLights(int viewnumber) +{ + dynlights = &view_dynlights[viewnumber]; +} + +// -------------------------------------------------------------------------- +// Add a light for dynamic lighting +// The light position is already transformed execpt for mlook +// -------------------------------------------------------------------------- +void HWR_DL_AddLight(gr_vissprite_t *spr, GLPatch_t *patch) +{ + light_t *p_lspr; + + //Hurdler: moved here because it's better;-) + (void)patch; + if (!cv_grdynamiclighting.value) + return; + + if (!spr->mobj) +#ifdef PARANOIA + I_Error("vissprite without mobj !!!"); +#else + return; +#endif + + // check if sprite contain dynamic light + p_lspr = t_lspr[spr->mobj->sprite]; + if ((p_lspr->type&DYNLIGHT_SPR) + && ((p_lspr->type != LIGHT_SPR) || cv_grstaticlighting.value) + && (dynlights->nb < DL_MAX_LIGHT) + + && spr->mobj->state) + { + LIGHT_POS(dynlights->nb).x = FIXED_TO_FLOAT(spr->mobj->x); + LIGHT_POS(dynlights->nb).y = FIXED_TO_FLOAT(spr->mobj->z)+FIXED_TO_FLOAT(spr->mobj->height>>1)+p_lspr->light_yoffset; + LIGHT_POS(dynlights->nb).z = FIXED_TO_FLOAT(spr->mobj->y); + + P_SetTarget(&dynlights->mo[dynlights->nb], spr->mobj); + + dynlights->p_lspr[dynlights->nb] = p_lspr; + + dynlights->nb++; + } +} + +static GLPatch_t lightmappatch; + +void HWR_InitLight(void) +{ + size_t i; + + // precalculate sqr radius + for (i = 0;i < NUMLIGHTS;i++) + lspr[i].dynamic_sqrradius = lspr[i].dynamic_radius*lspr[i].dynamic_radius; + + lightmappatch.mipmap.downloaded = false; + coronalumpnum = W_CheckNumForName("CORONA"); +} + +// -----------------+ +// HWR_SetLight : Download a disc shaped alpha map for rendering fake lights +// -----------------+ +static void HWR_SetLight(void) +{ + int i, j; + + if (!lightmappatch.mipmap.downloaded && !lightmappatch.mipmap.grInfo.data) + { + + UINT16 *Data = Z_Malloc(129*128*sizeof (UINT16), PU_HWRCACHE, &lightmappatch.mipmap.grInfo.data); + + for (i = 0; i < 128; i++) + { + for (j = 0; j < 128; j++) + { + int pos = ((i-64)*(i-64))+((j-64)*(j-64)); + if (pos <= 63*63) + Data[i*128+j] = (UINT16)(((UINT8)(255-(4*(float)sqrt((float)pos)))) << 8 | 0xff); + else + Data[i*128+j] = 0; + } + } + lightmappatch.mipmap.grInfo.format = GR_TEXFMT_ALPHA_INTENSITY_88; + + lightmappatch.width = 128; + lightmappatch.height = 128; + lightmappatch.mipmap.width = 128; + lightmappatch.mipmap.height = 128; + lightmappatch.mipmap.grInfo.smallLodLog2 = GR_LOD_LOG2_128; + lightmappatch.mipmap.grInfo.largeLodLog2 = GR_LOD_LOG2_128; + lightmappatch.mipmap.grInfo.aspectRatioLog2 = GR_ASPECT_LOG2_1x1; + lightmappatch.mipmap.flags = 0; //TF_WRAPXY; // DEBUG: view the overdraw ! + } + HWD.pfnSetTexture(&lightmappatch.mipmap); + + // The system-memory data can be purged now. + Z_ChangeTag(lightmappatch.mipmap.grInfo.data, PU_HWRCACHE_UNLOCKED); +} + +//********************************************************** +// Hurdler: new code for faster static lighting and and T&L +//********************************************************** + +#ifdef STATICLIGHT +// is this really necessary? +static sector_t *lgr_backsector; +static seg_t *lgr_curline; +#endif + +// p1 et p2 c'est le deux bou du seg en float +static inline void HWR_BuildWallLightmaps(FVector *p1, FVector *p2, int lighnum, seg_t *line) +{ + lightmap_t *lp; + + // (...) calcul presit de la projection et de la distance + +// if (dist_p2d >= DL_SQRRADIUS(lightnum)) +// return; + + // (...) attention faire le backfase cull histoir de faire mieux que Q3 ! + + (void)lighnum; + (void)p1; + (void)p2; + lp = malloc(sizeof (*lp)); + lp->next = line->lightmaps; + line->lightmaps = lp; + + // (...) encore des b�calcul bien lourd et on stock tout sa dans la lightmap +} + +#ifdef STATICLIGHT +static void HWR_AddLightMapForLine(int lightnum, seg_t *line) +{ + /* + int x1; + int x2; + angle_t angle1; + angle_t angle2; + angle_t span; + angle_t tspan; + */ + FVector p1,p2; + + lgr_curline = line; + lgr_backsector = line->backsector; + + // Reject empty lines used for triggers and special events. + // Identical floor and ceiling on both sides, + // identical light levels on both sides, + // and no middle texture. +/* + if ( lgr_backsector->ceilingpic == gr_frontsector->ceilingpic + && lgr_backsector->floorpic == gr_frontsector->floorpic + && lgr_backsector->lightlevel == gr_frontsector->lightlevel + && lgr_curline->sidedef->midtexture == 0) + { + return; + } +*/ + + p1.y = FIXED_TO_FLOAT(lgr_curline->v1->y); + p1.x = FIXED_TO_FLOAT(lgr_curline->v1->x); + p2.y = FIXED_TO_FLOAT(lgr_curline->v2->y); + p2.x = FIXED_TO_FLOAT(lgr_curline->v2->x); + + // check bbox of the seg +// if (CircleTouchBBox(&p1, &p2, &LIGHT_POS(lightnum), DL_RADIUS(lightnum))==false) +// return; + + HWR_BuildWallLightmaps(&p1, &p2, lightnum, line); +} + +/// \todo see what HWR_AddLine does +static void HWR_CheckSubsector(size_t num, fixed_t *bbox) +{ + int count; + seg_t *line; + subsector_t *sub; + FVector p1,p2; + int lightnum; + + p1.y = FIXED_TO_FLOAT(bbox[BOXTOP ]); + p1.x = FIXED_TO_FLOAT(bbox[BOXLEFT ]); + p2.y = FIXED_TO_FLOAT(bbox[BOXBOTTOM]); + p2.x = FIXED_TO_FLOAT(bbox[BOXRIGHT ]); + + + if (num < numsubsectors) + { + sub = &subsectors[num]; // subsector + for (lightnum = 0; lightnum < dynlights->nb; lightnum++) + { +// if (CircleTouchBBox(&p1, &p2, &LIGHT_POS(lightnum), DL_RADIUS(lightnum))==false) +// continue; + + count = sub->numlines; // how many linedefs + line = &segs[sub->firstline]; // first line seg + while (count--) + { + HWR_AddLightMapForLine (lightnum, line); // compute lightmap + line++; + } + } + } +} + + +// -------------------------------------------------------------------------- +// Hurdler: this adds lights by mobj. +// -------------------------------------------------------------------------- +static void HWR_AddMobjLights(mobj_t *thing) +{ + if (t_lspr[thing->sprite]->type & CORONA_SPR) + { + LIGHT_POS(dynlights->nb).x = FIXED_TO_FLOAT(thing->x); + LIGHT_POS(dynlights->nb).y = FIXED_TO_FLOAT(thing->z) + t_lspr[thing->sprite]->light_yoffset; + LIGHT_POS(dynlights->nb).z = FIXED_TO_FLOAT(thing->y); + + dynlights->p_lspr[dynlights->nb] = t_lspr[thing->sprite]; + + dynlights->nb++; + if (dynlights->nb > DL_MAX_LIGHT) + dynlights->nb = DL_MAX_LIGHT; + } +} + +//Hurdler: The goal of this function is to walk through all the bsp starting +// on the top. +// We need to do that to know all the lights in the map and all the walls +static void HWR_ComputeLightMapsInBSPNode(int bspnum, fixed_t *bbox) +{ + if (bspnum & NF_SUBSECTOR) // Found a subsector? + { + if (bspnum == -1) + HWR_CheckSubsector(0, bbox); // probably unecessary: see boris' comment in hw_bsp + else + HWR_CheckSubsector(bspnum&(~NF_SUBSECTOR), bbox); + return; + } + HWR_ComputeLightMapsInBSPNode(nodes[bspnum].children[0], nodes[bspnum].bbox[0]); + HWR_ComputeLightMapsInBSPNode(nodes[bspnum].children[1], nodes[bspnum].bbox[1]); +} + +static void HWR_SearchLightsInMobjs(void) +{ + thinker_t * th; + //mobj_t * mobj; + + // search in the list of thinkers + for (th = thinkercap.next; th != &thinkercap; th = th->next) + { + // a mobj ? + if (th->function.acp1 == (actionf_p1)P_MobjThinker) + HWR_AddMobjLights((mobj_t *)th); + } +} +#endif + +// +// HWR_CreateStaticLightmaps() +// +void HWR_CreateStaticLightmaps(int bspnum) +{ +#ifdef STATICLIGHT + CONS_Debug(DBG_RENDER, "HWR_CreateStaticLightmaps\n"); + + dynlights->nb = 0; + + // First: Searching for lights + // BP: if i was you, I will make it in create mobj since mobj can be create + // at runtime now with fragle scipt + HWR_SearchLightsInMobjs(); + CONS_Debug(DBG_RENDER, "%d lights found\n", dynlights->nb); + + // Second: Build all lightmap for walls covered by lights + validcount++; // to be sure + HWR_ComputeLightMapsInBSPNode(bspnum, NULL); + + dynlights->nb = 0; +#else + (void)bspnum; +#endif +} + +/** + \todo + + - Les coronas ne sont pas g�er avec le nouveau systeme, seul le dynamic lighting l'est + - calculer l'offset des coronas au chargement du level et non faire la moyenne + au moment de l'afficher + BP: euh non en fait il faux encoder la position de la light dans le sprite + car c'est pas focement au mileux de plus il peut en y avoir plusieur (chandelier) + - changer la comparaison pour l'affichage des coronas (+ un epsilon) + BP: non non j'ai trouver mieux :) : lord du AddSprite tu rajoute aussi la coronas + dans la sprite list ! avec un z de epsilon (attention au ZCLIP_PLANE) et donc on + l'affiche en dernier histoir qu'il puisse etre cacher par d'autre sprite :) + Bon fait metre pas mal de code special dans hwr_project sprite mais sa vaux le + coup + - gerer dynamic et static : retenir le nombre de lightstatic et clearer toute les + light > lightstatic (les dynamique) et les lightmap correspondant dans les segs + puit refaire une passe avec le code si dessus mais rien que pour les dynamiques + (tres petite modification) + - finalement virer le hack splitscreen, il n'est plus necessaire ! +*/ +#endif +#endif // HWRENDER diff --git a/src/hardware/hw_light.h b/src/hardware/hw_light.h new file mode 100644 index 000000000..2733cc698 --- /dev/null +++ b/src/hardware/hw_light.h @@ -0,0 +1,100 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright (C) 1998-2000 by DooM Legacy Team. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +//----------------------------------------------------------------------------- +/// \file +/// \brief Dynamic lighting & coronas add on by Hurdler + +#ifndef _HW_LIGHTS_ +#define _HW_LIGHTS_ + +#include "hw_glob.h" +#include "hw_defs.h" + +#define NUMLIGHTFREESLOTS 32 // Free light slots (for SOCs) + +#ifdef ALAM_LIGHTING +#define NEWCORONAS + +#define DL_MAX_LIGHT 256 // maximum number of lights (extra lights are ignored) + +void HWR_InitLight(void); +void HWR_DL_AddLight(gr_vissprite_t *spr, GLPatch_t *patch); +void HWR_PlaneLighting(FOutVector *clVerts, int nrClipVerts); +void HWR_WallLighting(FOutVector *wlVerts); +void HWR_ResetLights(void); +void HWR_SetLights(int viewnumber); + +#ifdef NEWCORONAS +void HWR_DrawCoronas(void); +#else +void HWR_DoCoronasLighting(FOutVector *outVerts, gr_vissprite_t *spr); +#endif + +typedef struct +{ + int nb; + light_t *p_lspr[DL_MAX_LIGHT]; + FVector position[DL_MAX_LIGHT]; // actually maximum DL_MAX_LIGHT lights + mobj_t *mo[DL_MAX_LIGHT]; +} dynlights_t; + +#endif + +typedef enum +{ + NOLIGHT = 0, + RINGSPARK_L, + SUPERSONIC_L, // Cool. =) + SUPERSPARK_L, + INVINCIBLE_L, + GREENSHIELD_L, + BLUESHIELD_L, + YELLOWSHIELD_L, + REDSHIELD_L, + BLACKSHIELD_L, + WHITESHIELD_L, + SMALLREDBALL_L, + RINGLIGHT_L, + GREENSMALL_L, + REDSMALL_L, + GREENSHINE_L, + ORANGESHINE_L, + PINKSHINE_L, + BLUESHINE_L, + REDSHINE_L, + LBLUESHINE_L, + GREYSHINE_L, + REDBALL_L, + GREENBALL_L, + BLUEBALL_L, + NIGHTSLIGHT_L, + JETLIGHT_L, + GOOPLIGHT_L, + STREETLIGHT_L, + + // free slots for SOCs at run-time -------------------- + FREESLOT0_L, + // + // ... 32 free lights here ... + // + LASTFREESLOT_L = (FREESLOT0_L+NUMLIGHTFREESLOTS-1), + // end of freeslots --------------------------------------------- + + NUMLIGHTS +} lightspritenum_t; + +extern light_t lspr[NUMLIGHTS]; +extern light_t *t_lspr[NUMSPRITES]; +#endif diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c new file mode 100644 index 000000000..b2b517737 --- /dev/null +++ b/src/hardware/hw_main.c @@ -0,0 +1,5149 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright (C) 1998-2000 by DooM Legacy Team. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +//----------------------------------------------------------------------------- +/// \file +/// \brief hardware renderer, using the standard HardWareRender driver DLL for SRB2 + +#include + +#include "../doomstat.h" + +#ifdef HWRENDER +#include "hw_glob.h" +#include "hw_light.h" +#include "hw_drv.h" + +#include "../i_video.h" // for rendermode == render_glide +#include "../v_video.h" +#include "../p_local.h" +#include "../p_setup.h" +#include "../r_local.h" +#include "../r_bsp.h" +#include "../d_clisrv.h" +#include "../w_wad.h" +#include "../z_zone.h" +#include "../r_splats.h" +#include "../g_game.h" +#include "../st_stuff.h" +#include "../i_system.h" +#include "../m_cheat.h" + +#include "hw_md2.h" + +#define R_FAKEFLOORS +//#define HWPRECIP +#define SORTING +//#define POLYSKY + +// ========================================================================== +// the hardware driver object +// ========================================================================== +struct hwdriver_s hwdriver; + +// ========================================================================== +// PROTOS +// ========================================================================== + + +static void HWR_AddSprites(sector_t *sec); +static void HWR_ProjectSprite(mobj_t *thing); +#ifdef HWPRECIP +static void HWR_ProjectPrecipitationSprite(precipmobj_t *thing); +#endif + +#ifdef SORTING +void HWR_AddTransparentFloor(lumpnum_t lumpnum, extrasubsector_t *xsub, fixed_t fixedheight, + INT32 lightlevel, INT32 alpha, sector_t *FOFSector, FBITFIELD blend, boolean fogplane, extracolormap_t *planecolormap); +#else +static void HWR_Add3DWater(lumpnum_t lumpnum, extrasubsector_t *xsub, fixed_t fixedheight, + INT32 lightlevel, INT32 alpha, sector_t *FOFSector); +static void HWR_Render3DWater(void); +static void HWR_RenderTransparentWalls(void); +#endif +static void HWR_FoggingOn(void); +static UINT32 atohex(const char *s); + +static void CV_filtermode_ONChange(void); +static void CV_anisotropic_ONChange(void); +static void CV_FogDensity_ONChange(void); +static void CV_grFov_OnChange(void); +// ========================================================================== +// 3D ENGINE COMMANDS & CONSOLE VARS +// ========================================================================== + +static CV_PossibleValue_t grfov_cons_t[] = {{0, "MIN"}, {179*FRACUNIT, "MAX"}, {0, NULL}}; +static CV_PossibleValue_t grfiltermode_cons_t[]= {{HWD_SET_TEXTUREFILTER_POINTSAMPLED, "Nearest"}, + {HWD_SET_TEXTUREFILTER_BILINEAR, "Bilinear"}, {HWD_SET_TEXTUREFILTER_TRILINEAR, "Trilinear"}, + {HWD_SET_TEXTUREFILTER_MIXED1, "Linear_Nearest"}, + {HWD_SET_TEXTUREFILTER_MIXED2, "Nearest_Linear"}, + {HWD_SET_TEXTUREFILTER_MIXED3, "Nearest_Mipmap"}, + {0, NULL}}; +CV_PossibleValue_t granisotropicmode_cons_t[] = {{1, "MIN"}, {16, "MAX"}, {0, NULL}}; + +boolean drawsky = true; + +// needs fix: walls are incorrectly clipped one column less +static consvar_t cv_grclipwalls = {"gr_clipwalls", "Off", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + +//development variables for diverse uses +static consvar_t cv_gralpha = {"gr_alpha", "160", 0, CV_Unsigned, NULL, 0, NULL, NULL, 0, 0, NULL}; +static consvar_t cv_grbeta = {"gr_beta", "0", 0, CV_Unsigned, NULL, 0, NULL, NULL, 0, 0, NULL}; + +static float HWRWipeCounter = 1.0f; +consvar_t cv_grrounddown = {"gr_rounddown", "Off", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_grfov = {"gr_fov", "90", CV_FLOAT|CV_CALL, grfov_cons_t, CV_grFov_OnChange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_grfogdensity = {"gr_fogdensity", "150", CV_CALL|CV_NOINIT, CV_Unsigned, + CV_FogDensity_ONChange, 0, NULL, NULL, 0, 0, NULL}; + +// Unfortunately, this can no longer be saved.. +consvar_t cv_grfiltermode = {"gr_filtermode", "Nearest", CV_CALL, grfiltermode_cons_t, + CV_filtermode_ONChange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_granisotropicmode = {"gr_anisotropicmode", "1", CV_CALL, granisotropicmode_cons_t, + CV_anisotropic_ONChange, 0, NULL, NULL, 0, 0, NULL}; +//static consvar_t cv_grzbuffer = {"gr_zbuffer", "On", 0, CV_OnOff}; +consvar_t cv_grcorrecttricks = {"gr_correcttricks", "On", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_grsolvetjoin = {"gr_solvetjoin", "On", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + +static CV_PossibleValue_t CV_MD2[] = {{0, "Off"}, {1, "On"}, {2, "Old"}, {0, NULL}}; +// console variables in development +consvar_t cv_grmd2 = {"gr_md2", "Off", 0, CV_MD2, NULL, 0, NULL, NULL, 0, 0, NULL}; + +static void CV_FogDensity_ONChange(void) +{ + HWD.pfnSetSpecialState(HWD_SET_FOG_DENSITY, cv_grfogdensity.value); +} + +static void CV_filtermode_ONChange(void) +{ + HWD.pfnSetSpecialState(HWD_SET_TEXTUREFILTERMODE, cv_grfiltermode.value); +} + +static void CV_anisotropic_ONChange(void) +{ + HWD.pfnSetSpecialState(HWD_SET_TEXTUREANISOTROPICMODE, cv_granisotropicmode.value); +} + +/* + * lookuptable for lightvalues + * calculated as follow: + * floatlight = (1.0-exp((light^3)*gamma)) / (1.0-exp(1.0*gamma)); + * gamma=-0,2;-2,0;-4,0;-6,0;-8,0 + * light = 0,0 .. 1,0 + */ +static const float lighttable[5][256] = +{ + { + 0.00000f,0.00000f,0.00000f,0.00000f,0.00000f,0.00001f,0.00001f,0.00002f,0.00003f,0.00004f, + 0.00006f,0.00008f,0.00010f,0.00013f,0.00017f,0.00020f,0.00025f,0.00030f,0.00035f,0.00041f, + 0.00048f,0.00056f,0.00064f,0.00073f,0.00083f,0.00094f,0.00106f,0.00119f,0.00132f,0.00147f, + 0.00163f,0.00180f,0.00198f,0.00217f,0.00237f,0.00259f,0.00281f,0.00305f,0.00331f,0.00358f, + 0.00386f,0.00416f,0.00447f,0.00479f,0.00514f,0.00550f,0.00587f,0.00626f,0.00667f,0.00710f, + 0.00754f,0.00800f,0.00848f,0.00898f,0.00950f,0.01003f,0.01059f,0.01117f,0.01177f,0.01239f, + 0.01303f,0.01369f,0.01437f,0.01508f,0.01581f,0.01656f,0.01734f,0.01814f,0.01896f,0.01981f, + 0.02069f,0.02159f,0.02251f,0.02346f,0.02444f,0.02544f,0.02647f,0.02753f,0.02862f,0.02973f, + 0.03088f,0.03205f,0.03325f,0.03448f,0.03575f,0.03704f,0.03836f,0.03971f,0.04110f,0.04252f, + 0.04396f,0.04545f,0.04696f,0.04851f,0.05009f,0.05171f,0.05336f,0.05504f,0.05676f,0.05852f, + 0.06031f,0.06214f,0.06400f,0.06590f,0.06784f,0.06981f,0.07183f,0.07388f,0.07597f,0.07810f, + 0.08027f,0.08248f,0.08473f,0.08702f,0.08935f,0.09172f,0.09414f,0.09659f,0.09909f,0.10163f, + 0.10421f,0.10684f,0.10951f,0.11223f,0.11499f,0.11779f,0.12064f,0.12354f,0.12648f,0.12946f, + 0.13250f,0.13558f,0.13871f,0.14188f,0.14511f,0.14838f,0.15170f,0.15507f,0.15850f,0.16197f, + 0.16549f,0.16906f,0.17268f,0.17635f,0.18008f,0.18386f,0.18769f,0.19157f,0.19551f,0.19950f, + 0.20354f,0.20764f,0.21179f,0.21600f,0.22026f,0.22458f,0.22896f,0.23339f,0.23788f,0.24242f, + 0.24702f,0.25168f,0.25640f,0.26118f,0.26602f,0.27091f,0.27587f,0.28089f,0.28596f,0.29110f, + 0.29630f,0.30156f,0.30688f,0.31226f,0.31771f,0.32322f,0.32879f,0.33443f,0.34013f,0.34589f, + 0.35172f,0.35761f,0.36357f,0.36960f,0.37569f,0.38185f,0.38808f,0.39437f,0.40073f,0.40716f, + 0.41366f,0.42022f,0.42686f,0.43356f,0.44034f,0.44718f,0.45410f,0.46108f,0.46814f,0.47527f, + 0.48247f,0.48974f,0.49709f,0.50451f,0.51200f,0.51957f,0.52721f,0.53492f,0.54271f,0.55058f, + 0.55852f,0.56654f,0.57463f,0.58280f,0.59105f,0.59937f,0.60777f,0.61625f,0.62481f,0.63345f, + 0.64217f,0.65096f,0.65984f,0.66880f,0.67783f,0.68695f,0.69615f,0.70544f,0.71480f,0.72425f, + 0.73378f,0.74339f,0.75308f,0.76286f,0.77273f,0.78268f,0.79271f,0.80283f,0.81304f,0.82333f, + 0.83371f,0.84417f,0.85472f,0.86536f,0.87609f,0.88691f,0.89781f,0.90880f,0.91989f,0.93106f, + 0.94232f,0.95368f,0.96512f,0.97665f,0.98828f,1.00000f + }, + { + 0.00000f,0.00000f,0.00000f,0.00000f,0.00001f,0.00002f,0.00003f,0.00005f,0.00007f,0.00010f, + 0.00014f,0.00019f,0.00024f,0.00031f,0.00038f,0.00047f,0.00057f,0.00069f,0.00081f,0.00096f, + 0.00112f,0.00129f,0.00148f,0.00170f,0.00193f,0.00218f,0.00245f,0.00274f,0.00306f,0.00340f, + 0.00376f,0.00415f,0.00456f,0.00500f,0.00547f,0.00597f,0.00649f,0.00704f,0.00763f,0.00825f, + 0.00889f,0.00957f,0.01029f,0.01104f,0.01182f,0.01264f,0.01350f,0.01439f,0.01532f,0.01630f, + 0.01731f,0.01836f,0.01945f,0.02058f,0.02176f,0.02298f,0.02424f,0.02555f,0.02690f,0.02830f, + 0.02974f,0.03123f,0.03277f,0.03436f,0.03600f,0.03768f,0.03942f,0.04120f,0.04304f,0.04493f, + 0.04687f,0.04886f,0.05091f,0.05301f,0.05517f,0.05738f,0.05964f,0.06196f,0.06434f,0.06677f, + 0.06926f,0.07181f,0.07441f,0.07707f,0.07979f,0.08257f,0.08541f,0.08831f,0.09126f,0.09428f, + 0.09735f,0.10048f,0.10368f,0.10693f,0.11025f,0.11362f,0.11706f,0.12056f,0.12411f,0.12773f, + 0.13141f,0.13515f,0.13895f,0.14281f,0.14673f,0.15072f,0.15476f,0.15886f,0.16303f,0.16725f, + 0.17153f,0.17587f,0.18028f,0.18474f,0.18926f,0.19383f,0.19847f,0.20316f,0.20791f,0.21272f, + 0.21759f,0.22251f,0.22748f,0.23251f,0.23760f,0.24274f,0.24793f,0.25318f,0.25848f,0.26383f, + 0.26923f,0.27468f,0.28018f,0.28573f,0.29133f,0.29697f,0.30266f,0.30840f,0.31418f,0.32001f, + 0.32588f,0.33179f,0.33774f,0.34374f,0.34977f,0.35585f,0.36196f,0.36810f,0.37428f,0.38050f, + 0.38675f,0.39304f,0.39935f,0.40570f,0.41207f,0.41847f,0.42490f,0.43136f,0.43784f,0.44434f, + 0.45087f,0.45741f,0.46398f,0.47057f,0.47717f,0.48379f,0.49042f,0.49707f,0.50373f,0.51041f, + 0.51709f,0.52378f,0.53048f,0.53718f,0.54389f,0.55061f,0.55732f,0.56404f,0.57075f,0.57747f, + 0.58418f,0.59089f,0.59759f,0.60429f,0.61097f,0.61765f,0.62432f,0.63098f,0.63762f,0.64425f, + 0.65086f,0.65746f,0.66404f,0.67060f,0.67714f,0.68365f,0.69015f,0.69662f,0.70307f,0.70948f, + 0.71588f,0.72224f,0.72857f,0.73488f,0.74115f,0.74739f,0.75359f,0.75976f,0.76589f,0.77199f, + 0.77805f,0.78407f,0.79005f,0.79599f,0.80189f,0.80774f,0.81355f,0.81932f,0.82504f,0.83072f, + 0.83635f,0.84194f,0.84747f,0.85296f,0.85840f,0.86378f,0.86912f,0.87441f,0.87964f,0.88482f, + 0.88995f,0.89503f,0.90005f,0.90502f,0.90993f,0.91479f,0.91959f,0.92434f,0.92903f,0.93366f, + 0.93824f,0.94276f,0.94723f,0.95163f,0.95598f,0.96027f,0.96451f,0.96868f,0.97280f,0.97686f, + 0.98086f,0.98481f,0.98869f,0.99252f,0.99629f,1.00000f + }, + { + 0.00000f,0.00000f,0.00000f,0.00001f,0.00002f,0.00003f,0.00005f,0.00008f,0.00013f,0.00018f, + 0.00025f,0.00033f,0.00042f,0.00054f,0.00067f,0.00083f,0.00101f,0.00121f,0.00143f,0.00168f, + 0.00196f,0.00227f,0.00261f,0.00299f,0.00339f,0.00383f,0.00431f,0.00483f,0.00538f,0.00598f, + 0.00661f,0.00729f,0.00802f,0.00879f,0.00961f,0.01048f,0.01140f,0.01237f,0.01340f,0.01447f, + 0.01561f,0.01680f,0.01804f,0.01935f,0.02072f,0.02215f,0.02364f,0.02520f,0.02682f,0.02850f, + 0.03026f,0.03208f,0.03397f,0.03594f,0.03797f,0.04007f,0.04225f,0.04451f,0.04684f,0.04924f, + 0.05172f,0.05428f,0.05691f,0.05963f,0.06242f,0.06530f,0.06825f,0.07129f,0.07441f,0.07761f, + 0.08089f,0.08426f,0.08771f,0.09125f,0.09487f,0.09857f,0.10236f,0.10623f,0.11019f,0.11423f, + 0.11836f,0.12257f,0.12687f,0.13125f,0.13571f,0.14027f,0.14490f,0.14962f,0.15442f,0.15931f, + 0.16427f,0.16932f,0.17445f,0.17966f,0.18496f,0.19033f,0.19578f,0.20130f,0.20691f,0.21259f, + 0.21834f,0.22417f,0.23007f,0.23605f,0.24209f,0.24820f,0.25438f,0.26063f,0.26694f,0.27332f, + 0.27976f,0.28626f,0.29282f,0.29944f,0.30611f,0.31284f,0.31962f,0.32646f,0.33334f,0.34027f, + 0.34724f,0.35426f,0.36132f,0.36842f,0.37556f,0.38273f,0.38994f,0.39718f,0.40445f,0.41174f, + 0.41907f,0.42641f,0.43378f,0.44116f,0.44856f,0.45598f,0.46340f,0.47084f,0.47828f,0.48573f, + 0.49319f,0.50064f,0.50809f,0.51554f,0.52298f,0.53042f,0.53784f,0.54525f,0.55265f,0.56002f, + 0.56738f,0.57472f,0.58203f,0.58932f,0.59658f,0.60381f,0.61101f,0.61817f,0.62529f,0.63238f, + 0.63943f,0.64643f,0.65339f,0.66031f,0.66717f,0.67399f,0.68075f,0.68746f,0.69412f,0.70072f, + 0.70726f,0.71375f,0.72017f,0.72653f,0.73282f,0.73905f,0.74522f,0.75131f,0.75734f,0.76330f, + 0.76918f,0.77500f,0.78074f,0.78640f,0.79199f,0.79751f,0.80295f,0.80831f,0.81359f,0.81880f, + 0.82393f,0.82898f,0.83394f,0.83883f,0.84364f,0.84836f,0.85301f,0.85758f,0.86206f,0.86646f, + 0.87078f,0.87502f,0.87918f,0.88326f,0.88726f,0.89118f,0.89501f,0.89877f,0.90245f,0.90605f, + 0.90957f,0.91301f,0.91638f,0.91966f,0.92288f,0.92601f,0.92908f,0.93206f,0.93498f,0.93782f, + 0.94059f,0.94329f,0.94592f,0.94848f,0.95097f,0.95339f,0.95575f,0.95804f,0.96027f,0.96244f, + 0.96454f,0.96658f,0.96856f,0.97049f,0.97235f,0.97416f,0.97591f,0.97760f,0.97924f,0.98083f, + 0.98237f,0.98386f,0.98530f,0.98669f,0.98803f,0.98933f,0.99058f,0.99179f,0.99295f,0.99408f, + 0.99516f,0.99620f,0.99721f,0.99817f,0.99910f,1.00000f + }, + { + 0.00000f,0.00000f,0.00000f,0.00001f,0.00002f,0.00005f,0.00008f,0.00012f,0.00019f,0.00026f, + 0.00036f,0.00048f,0.00063f,0.00080f,0.00099f,0.00122f,0.00148f,0.00178f,0.00211f,0.00249f, + 0.00290f,0.00335f,0.00386f,0.00440f,0.00500f,0.00565f,0.00636f,0.00711f,0.00793f,0.00881f, + 0.00975f,0.01075f,0.01182f,0.01295f,0.01416f,0.01543f,0.01678f,0.01821f,0.01971f,0.02129f, + 0.02295f,0.02469f,0.02652f,0.02843f,0.03043f,0.03252f,0.03469f,0.03696f,0.03933f,0.04178f, + 0.04433f,0.04698f,0.04973f,0.05258f,0.05552f,0.05857f,0.06172f,0.06498f,0.06834f,0.07180f, + 0.07537f,0.07905f,0.08283f,0.08672f,0.09072f,0.09483f,0.09905f,0.10337f,0.10781f,0.11236f, + 0.11701f,0.12178f,0.12665f,0.13163f,0.13673f,0.14193f,0.14724f,0.15265f,0.15817f,0.16380f, + 0.16954f,0.17538f,0.18132f,0.18737f,0.19351f,0.19976f,0.20610f,0.21255f,0.21908f,0.22572f, + 0.23244f,0.23926f,0.24616f,0.25316f,0.26023f,0.26739f,0.27464f,0.28196f,0.28935f,0.29683f, + 0.30437f,0.31198f,0.31966f,0.32740f,0.33521f,0.34307f,0.35099f,0.35896f,0.36699f,0.37506f, + 0.38317f,0.39133f,0.39952f,0.40775f,0.41601f,0.42429f,0.43261f,0.44094f,0.44929f,0.45766f, + 0.46604f,0.47443f,0.48283f,0.49122f,0.49962f,0.50801f,0.51639f,0.52476f,0.53312f,0.54146f, + 0.54978f,0.55807f,0.56633f,0.57457f,0.58277f,0.59093f,0.59905f,0.60713f,0.61516f,0.62314f, + 0.63107f,0.63895f,0.64676f,0.65452f,0.66221f,0.66984f,0.67739f,0.68488f,0.69229f,0.69963f, + 0.70689f,0.71407f,0.72117f,0.72818f,0.73511f,0.74195f,0.74870f,0.75536f,0.76192f,0.76839f, + 0.77477f,0.78105f,0.78723f,0.79331f,0.79930f,0.80518f,0.81096f,0.81664f,0.82221f,0.82768f, + 0.83305f,0.83832f,0.84347f,0.84853f,0.85348f,0.85832f,0.86306f,0.86770f,0.87223f,0.87666f, + 0.88098f,0.88521f,0.88933f,0.89334f,0.89726f,0.90108f,0.90480f,0.90842f,0.91194f,0.91537f, + 0.91870f,0.92193f,0.92508f,0.92813f,0.93109f,0.93396f,0.93675f,0.93945f,0.94206f,0.94459f, + 0.94704f,0.94941f,0.95169f,0.95391f,0.95604f,0.95810f,0.96009f,0.96201f,0.96386f,0.96564f, + 0.96735f,0.96900f,0.97059f,0.97212f,0.97358f,0.97499f,0.97634f,0.97764f,0.97888f,0.98007f, + 0.98122f,0.98231f,0.98336f,0.98436f,0.98531f,0.98623f,0.98710f,0.98793f,0.98873f,0.98949f, + 0.99021f,0.99090f,0.99155f,0.99218f,0.99277f,0.99333f,0.99387f,0.99437f,0.99486f,0.99531f, + 0.99575f,0.99616f,0.99654f,0.99691f,0.99726f,0.99759f,0.99790f,0.99819f,0.99847f,0.99873f, + 0.99897f,0.99920f,0.99942f,0.99963f,0.99982f,1.00000f + }, + { + 0.00000f,0.00000f,0.00000f,0.00001f,0.00003f,0.00006f,0.00010f,0.00017f,0.00025f,0.00035f, + 0.00048f,0.00064f,0.00083f,0.00106f,0.00132f,0.00163f,0.00197f,0.00237f,0.00281f,0.00330f, + 0.00385f,0.00446f,0.00513f,0.00585f,0.00665f,0.00751f,0.00845f,0.00945f,0.01054f,0.01170f, + 0.01295f,0.01428f,0.01569f,0.01719f,0.01879f,0.02048f,0.02227f,0.02415f,0.02614f,0.02822f, + 0.03042f,0.03272f,0.03513f,0.03765f,0.04028f,0.04303f,0.04589f,0.04887f,0.05198f,0.05520f, + 0.05855f,0.06202f,0.06561f,0.06933f,0.07318f,0.07716f,0.08127f,0.08550f,0.08987f,0.09437f, + 0.09900f,0.10376f,0.10866f,0.11369f,0.11884f,0.12414f,0.12956f,0.13512f,0.14080f,0.14662f, + 0.15257f,0.15865f,0.16485f,0.17118f,0.17764f,0.18423f,0.19093f,0.19776f,0.20471f,0.21177f, + 0.21895f,0.22625f,0.23365f,0.24117f,0.24879f,0.25652f,0.26435f,0.27228f,0.28030f,0.28842f, + 0.29662f,0.30492f,0.31329f,0.32175f,0.33028f,0.33889f,0.34756f,0.35630f,0.36510f,0.37396f, + 0.38287f,0.39183f,0.40084f,0.40989f,0.41897f,0.42809f,0.43723f,0.44640f,0.45559f,0.46479f, + 0.47401f,0.48323f,0.49245f,0.50167f,0.51088f,0.52008f,0.52927f,0.53843f,0.54757f,0.55668f, + 0.56575f,0.57479f,0.58379f,0.59274f,0.60164f,0.61048f,0.61927f,0.62799f,0.63665f,0.64524f, + 0.65376f,0.66220f,0.67056f,0.67883f,0.68702f,0.69511f,0.70312f,0.71103f,0.71884f,0.72655f, + 0.73415f,0.74165f,0.74904f,0.75632f,0.76348f,0.77053f,0.77747f,0.78428f,0.79098f,0.79756f, + 0.80401f,0.81035f,0.81655f,0.82264f,0.82859f,0.83443f,0.84013f,0.84571f,0.85117f,0.85649f, + 0.86169f,0.86677f,0.87172f,0.87654f,0.88124f,0.88581f,0.89026f,0.89459f,0.89880f,0.90289f, + 0.90686f,0.91071f,0.91445f,0.91807f,0.92157f,0.92497f,0.92826f,0.93143f,0.93450f,0.93747f, + 0.94034f,0.94310f,0.94577f,0.94833f,0.95081f,0.95319f,0.95548f,0.95768f,0.95980f,0.96183f, + 0.96378f,0.96565f,0.96744f,0.96916f,0.97081f,0.97238f,0.97388f,0.97532f,0.97669f,0.97801f, + 0.97926f,0.98045f,0.98158f,0.98266f,0.98369f,0.98467f,0.98560f,0.98648f,0.98732f,0.98811f, + 0.98886f,0.98958f,0.99025f,0.99089f,0.99149f,0.99206f,0.99260f,0.99311f,0.99359f,0.99404f, + 0.99446f,0.99486f,0.99523f,0.99559f,0.99592f,0.99623f,0.99652f,0.99679f,0.99705f,0.99729f, + 0.99751f,0.99772f,0.99792f,0.99810f,0.99827f,0.99843f,0.99857f,0.99871f,0.99884f,0.99896f, + 0.99907f,0.99917f,0.99926f,0.99935f,0.99943f,0.99951f,0.99958f,0.99964f,0.99970f,0.99975f, + 0.99980f,0.99985f,0.99989f,0.99993f,0.99997f,1.00000f + } +}; + +#define gld_CalcLightLevel(lightlevel) (lighttable[1][max(min((lightlevel),255),0)]) + +// ========================================================================== +// VIEW GLOBALS +// ========================================================================== +// Fineangles in the SCREENWIDTH wide window. +#define FIELDOFVIEW ANGLE_90 +#define ABS(x) ((x) < 0 ? -(x) : (x)) + +static angle_t gr_clipangle; + +// The viewangletox[viewangle + FINEANGLES/4] lookup +// maps the visible view angles to screen X coordinates, +// flattening the arc to a flat projection plane. +// There will be many angles mapped to the same X. +static INT32 gr_viewangletox[FINEANGLES/2]; + +// The xtoviewangleangle[] table maps a screen pixel +// to the lowest viewangle that maps back to x ranges +// from clipangle to -clipangle. +static angle_t gr_xtoviewangle[MAXVIDWIDTH+1]; + +// ========================================================================== +// GLOBALS +// ========================================================================== + +// uncomment to remove the plane rendering +#define DOPLANES +//#define DOWALLS + +// test of drawing sky by polygons like in software with visplane, unfortunately +// this doesn't work since we must have z for pixel and z for texture (not like now with z = oow) +//#define POLYSKY + +// test change fov when looking up/down but bsp projection messup :( +//#define NOCRAPPYMLOOK + +/// \note crappy +#define drawtextured true + +// base values set at SetViewSize +static float gr_basecentery; + +float gr_baseviewwindowy, gr_basewindowcentery; +float gr_viewwidth, gr_viewheight; // viewport clipping boundaries (screen coords) +float gr_viewwindowx; + +static float gr_centerx, gr_centery; +static float gr_viewwindowy; // top left corner of view window +static float gr_windowcenterx; // center of view window, for projection +static float gr_windowcentery; + +static float gr_pspritexscale, gr_pspriteyscale; + +static seg_t *gr_curline; +static side_t *gr_sidedef; +static line_t *gr_linedef; +static sector_t *gr_frontsector; +static sector_t *gr_backsector; + +// -------------------------------------------------------------------------- +// STUFF FOR THE PROJECTION CODE +// -------------------------------------------------------------------------- + +FTransform atransform; +// duplicates of the main code, set after R_SetupFrame() passed them into sharedstruct, +// copied here for local use +static fixed_t dup_viewx, dup_viewy, dup_viewz; +static angle_t dup_viewangle; + +static float gr_viewx, gr_viewy, gr_viewz; +static float gr_viewsin, gr_viewcos; + +// Maybe not necessary with the new T&L code (needs to be checked!) +static float gr_viewludsin, gr_viewludcos; // look up down kik test +static float gr_fovlud; + +// ========================================================================== +// LIGHT stuffs +// ========================================================================== + +static UINT8 lightleveltonumlut[256]; + +// added to SRB2's sector lightlevel to make things a bit brighter (sprites/walls/planes) +FUNCMATH UINT8 LightLevelToLum(INT32 l) +{ + return (UINT8)(255*gld_CalcLightLevel(l)); +} + +static inline void InitLumLut(void) +{ + INT32 i, k = 0; + for (i = 0; i < 256; i++) + { + if (i > 128) + k += 2; + else + k = 1; + lightleveltonumlut[i] = (UINT8)(k); + } +} + +//#define FOGFACTOR 300 //was 600 >> Covered by cv_grfogdensity +#define NORMALFOG 0x00000000 +#define FADEFOG 0x19000000 +#define CALCFOGDENSITY(x) ((float)((5220.0f*(1.0f/((x)/41.0f+1.0f)))-(5220.0f*(1.0f/(255.0f/41.0f+1.0f))))) // Approximate fog calculation based off of software walls +#define CALCFOGDENSITYFLOOR(x) ((float)((40227.0f*(1.0f/((x)/11.0f+1.0f)))-(40227.0f*(1.0f/(255.0f/11.0f+1.0f))))) // Approximate fog calculation based off of software floors +#define CALCLIGHT(x,y) ((float)(x)*((y)/255.0f)) +UINT32 HWR_Lighting(INT32 light, UINT32 color, UINT32 fadecolor, boolean fogblockpoly, boolean plane) +{ + RGBA_t realcolor, fogcolor, surfcolor; + INT32 alpha, fogalpha; + + (void)fogblockpoly; + + realcolor.rgba = color; + fogcolor.rgba = fadecolor; + + alpha = (realcolor.s.alpha*255)/25; + fogalpha = (fogcolor.s.alpha*255)/25; + + if (cv_grfog.value && cv_grsoftwarefog.value) // Only do this when fog is on, software fog mode is on, and the poly is not from a fog block + { + // Modulate the colors by alpha. + realcolor.s.red = (UINT8)(CALCLIGHT(alpha,realcolor.s.red)); + realcolor.s.green = (UINT8)(CALCLIGHT(alpha,realcolor.s.green)); + realcolor.s.blue = (UINT8)(CALCLIGHT(alpha,realcolor.s.blue)); + + // Set the surface colors and further modulate the colors by light. + surfcolor.s.red = (UINT8)(CALCLIGHT((0xFF-alpha),255)+CALCLIGHT(realcolor.s.red,255)); + surfcolor.s.green = (UINT8)(CALCLIGHT((0xFF-alpha),255)+CALCLIGHT(realcolor.s.green,255)); + surfcolor.s.blue = (UINT8)(CALCLIGHT((0xFF-alpha),255)+CALCLIGHT(realcolor.s.blue,255)); + surfcolor.s.alpha = 0xFF; + + // Modulate the colors by alpha. + fogcolor.s.red = (UINT8)(CALCLIGHT(fogalpha,fogcolor.s.red)); + fogcolor.s.green = (UINT8)(CALCLIGHT(fogalpha,fogcolor.s.green)); + fogcolor.s.blue = (UINT8)(CALCLIGHT(fogalpha,fogcolor.s.blue)); + } + else + { + // Modulate the colors by alpha. + realcolor.s.red = (UINT8)(CALCLIGHT(alpha,realcolor.s.red)); + realcolor.s.green = (UINT8)(CALCLIGHT(alpha,realcolor.s.green)); + realcolor.s.blue = (UINT8)(CALCLIGHT(alpha,realcolor.s.blue)); + + // Set the surface colors and further modulate the colors by light. + surfcolor.s.red = (UINT8)(CALCLIGHT((0xFF-alpha),light)+CALCLIGHT(realcolor.s.red,light)); + surfcolor.s.green = (UINT8)(CALCLIGHT((0xFF-alpha),light)+CALCLIGHT(realcolor.s.green,light)); + surfcolor.s.blue = (UINT8)(CALCLIGHT((0xFF-alpha),light)+CALCLIGHT(realcolor.s.blue,light)); + + // Modulate the colors by alpha. + fogcolor.s.red = (UINT8)(CALCLIGHT(fogalpha,fogcolor.s.red)); + fogcolor.s.green = (UINT8)(CALCLIGHT(fogalpha,fogcolor.s.green)); + fogcolor.s.blue = (UINT8)(CALCLIGHT(fogalpha,fogcolor.s.blue)); + + // Set the surface colors and further modulate the colors by light. + surfcolor.s.red = surfcolor.s.red+((UINT8)(CALCLIGHT((0xFF-fogalpha),(255-light))+CALCLIGHT(fogcolor.s.red,(255-light)))); + surfcolor.s.green = surfcolor.s.green+((UINT8)(CALCLIGHT((0xFF-fogalpha),(255-light))+CALCLIGHT(fogcolor.s.green,(255-light)))); + surfcolor.s.blue = surfcolor.s.blue+((UINT8)(CALCLIGHT((0xFF-fogalpha),(255-light))+CALCLIGHT(fogcolor.s.blue,(255-light)))); + surfcolor.s.alpha = 0xFF; + } + + if(cv_grfog.value) + { + if (cv_grsoftwarefog.value) + { + fogcolor.s.red = (UINT8)((CALCLIGHT(fogcolor.s.red,(255-light)))+(CALCLIGHT(realcolor.s.red,light))); + fogcolor.s.green = (UINT8)((CALCLIGHT(fogcolor.s.green,(255-light)))+(CALCLIGHT(realcolor.s.green,light))); + fogcolor.s.blue = (UINT8)((CALCLIGHT(fogcolor.s.blue,(255-light)))+(CALCLIGHT(realcolor.s.blue,light))); + + // Set the fog options. + if (cv_grsoftwarefog.value == 1 && plane) // With floors, software draws them way darker for their distance + HWD.pfnSetSpecialState(HWD_SET_FOG_DENSITY, (INT32)(CALCFOGDENSITYFLOOR(light))); + else // everything else is drawn like walls + HWD.pfnSetSpecialState(HWD_SET_FOG_DENSITY, (INT32)(CALCFOGDENSITY(light))); + } + else + { + fogcolor.s.red = (UINT8)((CALCLIGHT(fogcolor.s.red,(255-light)))+(CALCLIGHT(realcolor.s.red,light))); + fogcolor.s.green = (UINT8)((CALCLIGHT(fogcolor.s.green,(255-light)))+(CALCLIGHT(realcolor.s.green,light))); + fogcolor.s.blue = (UINT8)((CALCLIGHT(fogcolor.s.blue,(255-light)))+(CALCLIGHT(realcolor.s.blue,light))); + + fogalpha = (UINT8)((CALCLIGHT(fogalpha,(255-light)))+(CALCLIGHT(alpha,light))); + + // Set the fog options. + light = (UINT8)(CALCLIGHT(light,(255-fogalpha))); + HWD.pfnSetSpecialState(HWD_SET_FOG_DENSITY, (INT32)(cv_grfogdensity.value-(cv_grfogdensity.value*(float)light/255.0f))); + } + + HWD.pfnSetSpecialState(HWD_SET_FOG_COLOR, (fogcolor.s.red*0x10000)+(fogcolor.s.green*0x100)+fogcolor.s.blue); + HWD.pfnSetSpecialState(HWD_SET_FOG_MODE, 1); + } + return surfcolor.rgba; +} + + +static UINT8 HWR_FogBlockAlpha(INT32 light, UINT32 color, UINT32 fadecolor) // Let's see if this can work +{ + RGBA_t realcolor, fogcolor, surfcolor; + INT32 alpha, fogalpha; + + realcolor.rgba = color; + fogcolor.rgba = fadecolor; + + alpha = (realcolor.s.alpha*255)/25; + fogalpha = (fogcolor.s.alpha*255)/25; + + // Fog blocks seem to get slightly more opaque with more opaque colourmap opacity, and much more opaque with darker brightness + surfcolor.s.alpha = (UINT8)(CALCLIGHT(light, ((0xFF-light)+alpha)/2)+CALCLIGHT(0xFF-light, ((light)+fogalpha)/2)); + + return surfcolor.s.alpha; +} + +// ========================================================================== +// FLOOR/CEILING GENERATION FROM SUBSECTORS +// ========================================================================== + +#ifdef DOPLANES + +// -----------------+ +// HWR_RenderPlane : Render a floor or ceiling convex polygon +// -----------------+ +static void HWR_RenderPlane(sector_t *sector, extrasubsector_t *xsub, fixed_t fixedheight, + FBITFIELD PolyFlags, INT32 lightlevel, lumpnum_t lumpnum, sector_t *FOFsector, UINT8 alpha, boolean fogplane, extracolormap_t *planecolormap) +{ + polyvertex_t * pv; + float height; //constant y for all points on the convex flat polygon + FOutVector *v3d; + INT32 nrPlaneVerts; //verts original define of convex flat polygon + INT32 i; + float flatxref,flatyref; + float fflatsize; + INT32 flatflag; + size_t len; + float scrollx = 0.0f, scrolly = 0.0f; + angle_t angle = 0; + FSurfaceInfo Surf; + fixed_t tempxsow, tempytow; + + static FOutVector *planeVerts = NULL; + static UINT16 numAllocedPlaneVerts = 0; + + // no convex poly were generated for this subsector + if (!xsub->planepoly) + return; + + height = FIXED_TO_FLOAT(fixedheight); + + pv = xsub->planepoly->pts; + nrPlaneVerts = xsub->planepoly->numpts; + + if (nrPlaneVerts < 3) //not even a triangle ? + return; + + if (nrPlaneVerts > UINT16_MAX) // FIXME: exceeds plVerts size + { + CONS_Debug(DBG_RENDER, "polygon size of %d exceeds max value of %d vertices\n", nrPlaneVerts, UINT16_MAX); + return; + } + + // Allocate plane-vertex buffer if we need to + if (!planeVerts || nrPlaneVerts > numAllocedPlaneVerts) + { + numAllocedPlaneVerts = (UINT16)nrPlaneVerts; + Z_Free(planeVerts); + Z_Malloc(numAllocedPlaneVerts * sizeof (FOutVector), PU_LEVEL, &planeVerts); + } + + len = W_LumpLength(lumpnum); + + switch (len) + { + case 4194304: // 2048x2048 lump + fflatsize = 2048.0f; + flatflag = 2047; + break; + case 1048576: // 1024x1024 lump + fflatsize = 1024.0f; + flatflag = 1023; + break; + case 262144:// 512x512 lump + fflatsize = 512.0f; + flatflag = 511; + break; + case 65536: // 256x256 lump + fflatsize = 256.0f; + flatflag = 255; + break; + case 16384: // 128x128 lump + fflatsize = 128.0f; + flatflag = 127; + break; + case 1024: // 32x32 lump + fflatsize = 32.0f; + flatflag = 31; + break; + default: // 64x64 lump + fflatsize = 64.0f; + flatflag = 63; + break; + } + + // reference point for flat texture coord for each vertex around the polygon + flatxref = (float)(((fixed_t)pv->x & (~flatflag)) / fflatsize); + flatyref = (float)(((fixed_t)pv->y & (~flatflag)) / fflatsize); + + // transform + v3d = planeVerts; + + if (FOFsector != NULL) + { + if (fixedheight == FOFsector->floorheight) // it's a floor + { + scrollx = FIXED_TO_FLOAT(FOFsector->floor_xoffs)/fflatsize; + scrolly = FIXED_TO_FLOAT(FOFsector->floor_yoffs)/fflatsize; + angle = FOFsector->floorpic_angle>>ANGLETOFINESHIFT; + } + else // it's a ceiling + { + scrollx = FIXED_TO_FLOAT(FOFsector->ceiling_xoffs)/fflatsize; + scrolly = FIXED_TO_FLOAT(FOFsector->ceiling_yoffs)/fflatsize; + angle = FOFsector->ceilingpic_angle>>ANGLETOFINESHIFT; + } + } + else if (gr_frontsector) + { + if (fixedheight < dup_viewz) // it's a floor + { + scrollx = FIXED_TO_FLOAT(gr_frontsector->floor_xoffs)/fflatsize; + scrolly = FIXED_TO_FLOAT(gr_frontsector->floor_yoffs)/fflatsize; + angle = gr_frontsector->floorpic_angle>>ANGLETOFINESHIFT; + } + else // it's a ceiling + { + scrollx = FIXED_TO_FLOAT(gr_frontsector->ceiling_xoffs)/fflatsize; + scrolly = FIXED_TO_FLOAT(gr_frontsector->ceiling_yoffs)/fflatsize; + angle = gr_frontsector->ceilingpic_angle>>ANGLETOFINESHIFT; + } + } + + if (angle) // Only needs to be done if there's an altered angle + { + + // This needs to be done so that it scrolls in a different direction after rotation like software + tempxsow = FLOAT_TO_FIXED(scrollx); + tempytow = FLOAT_TO_FIXED(scrolly); + scrollx = (FIXED_TO_FLOAT(FixedMul(tempxsow, FINECOSINE(angle)) - FixedMul(tempytow, FINESINE(angle)))); + scrolly = (FIXED_TO_FLOAT(FixedMul(tempxsow, FINESINE(angle)) + FixedMul(tempytow, FINECOSINE(angle)))); + + // This needs to be done so everything aligns after rotation + // It would be done so that rotation is done, THEN the translation, but I couldn't get it to rotate AND scroll like software does + tempxsow = FLOAT_TO_FIXED(flatxref); + tempytow = FLOAT_TO_FIXED(flatyref); + flatxref = (FIXED_TO_FLOAT(FixedMul(tempxsow, FINECOSINE(angle)) - FixedMul(tempytow, FINESINE(angle)))); + flatyref = (FIXED_TO_FLOAT(FixedMul(tempxsow, FINESINE(angle)) + FixedMul(tempytow, FINECOSINE(angle)))); + } + + for (i = 0; i < nrPlaneVerts; i++,v3d++,pv++) + { + // Hurdler: add scrolling texture on floor/ceiling + v3d->sow = (float)((pv->x / fflatsize) - flatxref + scrollx); + v3d->tow = (float)(flatyref - (pv->y / fflatsize) + scrolly); + + //v3d->sow = (float)(pv->x / fflatsize); + //v3d->tow = (float)(pv->y / fflatsize); + + // Need to rotate before translate + if (angle) // Only needs to be done if there's an altered angle + { + tempxsow = FLOAT_TO_FIXED(v3d->sow); + tempytow = FLOAT_TO_FIXED(v3d->tow); + v3d->sow = (FIXED_TO_FLOAT(FixedMul(tempxsow, FINECOSINE(angle)) - FixedMul(tempytow, FINESINE(angle)))); + v3d->tow = (FIXED_TO_FLOAT(-FixedMul(tempxsow, FINESINE(angle)) - FixedMul(tempytow, FINECOSINE(angle)))); + } + + //v3d->sow = (float)(v3d->sow - flatxref + scrollx); + //v3d->tow = (float)(flatyref - v3d->tow + scrolly); + + v3d->x = pv->x; + v3d->y = height; + v3d->z = pv->y; +#ifdef SLOPENESS + if (sector && sector->special == 65535) + { + size_t q; + for (q = 0; q < sector->linecount; q++) + { + if (v3d->x == sector->lines[q]->v1->x>>FRACBITS) + { + if (v3d->z == sector->lines[q]->v1->y>>FRACBITS) + { + v3d->y += sector->lines[q]->v1->z>>FRACBITS; + break; + } + } + } + } +#else + (void)sector; +#endif + } + + // only useful for flat coloured triangles + //Surf.FlatColor = 0xff804020; + + // use different light tables + // for horizontal / vertical / diagonal + // note: try to get the same visual feel as the original + Surf.FlatColor.s.red = Surf.FlatColor.s.green = + Surf.FlatColor.s.blue = LightLevelToLum(lightlevel); // Don't take from the frontsector, or the game will crash + +#if 0 // no colormap test + // colormap test + if (gr_frontsector) + { + sector_t *psector = gr_frontsector; + + if (psector->ffloors) + { + ffloor_t *caster = psector->lightlist[R_GetPlaneLight(psector, fixedheight, false)].caster; + psector = caster ? §ors[caster->secnum] : psector; + + if (caster) + { + lightlevel = psector->lightlevel; + Surf.FlatColor.s.red = Surf.FlatColor.s.green = Surf.FlatColor.s.blue = LightLevelToLum(lightlevel); + } + } + if (psector->extra_colormap) + Surf.FlatColor.rgba = HWR_Lighting(LightLevelToLum(lightlevel),psector->extra_colormap->rgba,psector->extra_colormap->fadergba, false, true); + else + Surf.FlatColor.rgba = HWR_Lighting(LightLevelToLum(lightlevel),NORMALFOG,FADEFOG, false, true); + } + else + Surf.FlatColor.rgba = HWR_Lighting(LightLevelToLum(lightlevel),NORMALFOG,FADEFOG, false, true); + +#endif // NOPE + + if (planecolormap) + { + if (fogplane) + Surf.FlatColor.rgba = HWR_Lighting(LightLevelToLum(lightlevel), planecolormap->rgba, planecolormap->fadergba, true, false); + else + Surf.FlatColor.rgba = HWR_Lighting(LightLevelToLum(lightlevel), planecolormap->rgba, planecolormap->fadergba, false, true); + } + else + { + if (fogplane) + Surf.FlatColor.rgba = HWR_Lighting(LightLevelToLum(lightlevel), NORMALFOG, FADEFOG, true, false); + else + Surf.FlatColor.rgba = HWR_Lighting(LightLevelToLum(lightlevel), NORMALFOG, FADEFOG, false, true); + } + + if (PolyFlags & PF_Translucent) + { + Surf.FlatColor.s.alpha = (UINT8)alpha; + PolyFlags |= PF_Modulated|PF_Occlude|PF_Clip; + } + else + PolyFlags |= PF_Masked|PF_Modulated|PF_Clip; + + HWD.pfnDrawPolygon(&Surf, planeVerts, nrPlaneVerts, PolyFlags); + +#ifdef ALAM_LIGHTING + // add here code for dynamic lighting on planes + HWR_PlaneLighting(planeVerts, nrPlaneVerts); +#endif +} + +#ifdef POLYSKY +// this don't draw anything it only update the z-buffer so there isn't problem with +// wall/things upper that sky (map12) +static void HWR_RenderSkyPlane(extrasubsector_t *xsub, fixed_t fixedheight) +{ + polyvertex_t *pv; + float height; //constant y for all points on the convex flat polygon + FOutVector *v3d; + INT32 nrPlaneVerts; //verts original define of convex flat polygon + INT32 i; + + // no convex poly were generated for this subsector + if (!xsub->planepoly) + return; + + height = FIXED_TO_FLOAT(fixedheight); + + pv = xsub->planepoly->pts; + nrPlaneVerts = xsub->planepoly->numpts; + + if (nrPlaneVerts < 3) // not even a triangle? + return; + + if (nrPlaneVerts > MAXPLANEVERTICES) // FIXME: exceeds plVerts size + { + CONS_Debug(DBG_RENDER, "polygon size of %d exceeds max value of %d vertices\n", nrPlaneVerts, MAXPLANEVERTICES); + return; + } + + // transform + v3d = planeVerts; + for (i = 0; i < nrPlaneVerts; i++,v3d++,pv++) + { + v3d->sow = 0.0f; + v3d->tow = 0.0f; + v3d->x = pv->x; + v3d->y = height; + v3d->z = pv->y; + } + + HWD.pfnDrawPolygon(NULL, planeVerts, nrPlaneVerts, + PF_Clip|PF_Invisible|PF_NoTexture|PF_Occlude); +} +#endif //polysky + +#endif //doplanes + +/* + wallVerts order is : + 3--2 + | /| + |/ | + 0--1 +*/ +#ifdef WALLSPLATS +static void HWR_DrawSegsSplats(FSurfaceInfo * pSurf) +{ + FOutVector trVerts[4], *wv; + wallVert3D wallVerts[4]; + wallVert3D *pwallVerts; + wallsplat_t *splat; + GLPatch_t *gpatch; + fixed_t i; + FSurfaceInfo pSurf2; + // seg bbox + fixed_t segbbox[4]; + + M_ClearBox(segbbox); + M_AddToBox(segbbox, + FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v1)->x), + FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v1)->y)); + M_AddToBox(segbbox, + FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v2)->x), + FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v2)->y)); + + splat = (wallsplat_t *)gr_curline->linedef->splats; + for (; splat; splat = splat->next) + { + //BP: don't draw splat extern to this seg + // this is quick fix best is explain in logboris.txt at 12-4-2000 + if (!M_PointInBox(segbbox,splat->v1.x,splat->v1.y) && !M_PointInBox(segbbox,splat->v2.x,splat->v2.y)) + continue; + + gpatch = W_CachePatchNum(splat->patch, PU_CACHE); + HWR_GetPatch(gpatch); + + wallVerts[0].x = wallVerts[3].x = FIXED_TO_FLOAT(splat->v1.x); + wallVerts[0].z = wallVerts[3].z = FIXED_TO_FLOAT(splat->v1.y); + wallVerts[2].x = wallVerts[1].x = FIXED_TO_FLOAT(splat->v2.x); + wallVerts[2].z = wallVerts[1].z = FIXED_TO_FLOAT(splat->v2.y); + + i = splat->top; + if (splat->yoffset) + i += *splat->yoffset; + + wallVerts[2].y = wallVerts[3].y = FIXED_TO_FLOAT(i)+(gpatch->height>>1); + wallVerts[0].y = wallVerts[1].y = FIXED_TO_FLOAT(i)-(gpatch->height>>1); + + wallVerts[3].s = wallVerts[3].t = wallVerts[2].s = wallVerts[0].t = 0.0f; + wallVerts[1].s = wallVerts[1].t = wallVerts[2].t = wallVerts[0].s = 1.0f; + + // transform + wv = trVerts; + pwallVerts = wallVerts; + for (i = 0; i < 4; i++,wv++,pwallVerts++) + { + wv->x = pwallVerts->x; + wv->z = pwallVerts->z; + wv->y = pwallVerts->y; + + // Kalaron: TOW and SOW needed to be switched + wv->sow = pwallVerts->t; + wv->tow = pwallVerts->s; + } + M_Memcpy(&pSurf2,pSurf,sizeof (FSurfaceInfo)); + switch (splat->flags & SPLATDRAWMODE_MASK) + { + case SPLATDRAWMODE_OPAQUE : + pSurf2.FlatColor.s.alpha = 0xff; + i = PF_Translucent; + break; + case SPLATDRAWMODE_TRANS : + pSurf2.FlatColor.s.alpha = 128; + i = PF_Translucent; + break; + case SPLATDRAWMODE_SHADE : + pSurf2.FlatColor.s.alpha = 0xff; + i = PF_Substractive; + break; + } + + HWD.pfnDrawPolygon(&pSurf2, trVerts, 4, i|PF_Modulated|PF_Clip|PF_Decal); + } +} +#endif + +// ========================================================================== +// WALL GENERATION FROM SUBSECTOR SEGS +// ========================================================================== + + +FBITFIELD HWR_TranstableToAlpha(INT32 transtablenum, FSurfaceInfo *pSurf) +{ + switch (transtablenum) + { + case tr_trans10 : pSurf->FlatColor.s.alpha = 0xe6;return PF_Translucent; + case tr_trans20 : pSurf->FlatColor.s.alpha = 0xcc;return PF_Translucent; + case tr_trans30 : pSurf->FlatColor.s.alpha = 0xb3;return PF_Translucent; + case tr_trans40 : pSurf->FlatColor.s.alpha = 0x99;return PF_Translucent; + case tr_trans50 : pSurf->FlatColor.s.alpha = 0x80;return PF_Translucent; + case tr_trans60 : pSurf->FlatColor.s.alpha = 0x66;return PF_Translucent; + case tr_trans70 : pSurf->FlatColor.s.alpha = 0x4c;return PF_Translucent; + case tr_trans80 : pSurf->FlatColor.s.alpha = 0x33;return PF_Translucent; + case tr_trans90 : pSurf->FlatColor.s.alpha = 0x19;return PF_Translucent; + } + return PF_Translucent; +} + +// v1,v2 : the start & end vertices along the original wall segment, that may have been +// clipped so that only a visible portion of the wall seg is drawn. +// floorheight, ceilingheight : depend on wall upper/lower/middle, comes from the sectors. + +static void HWR_AddTransparentWall(wallVert3D *wallVerts, FSurfaceInfo * pSurf, INT32 texnum, FBITFIELD blend, boolean fogwall, INT32 lightlevel, extracolormap_t *wallcolormap); + +// -----------------+ +// HWR_ProjectWall : +// -----------------+ +/* + wallVerts order is : + 3--2 + | /| + |/ | + 0--1 +*/ +static void HWR_ProjectWall(wallVert3D * wallVerts, + FSurfaceInfo * pSurf, + FBITFIELD blendmode, INT32 lightlevel, extracolormap_t *wallcolormap) +{ + FOutVector trVerts[4]; + FOutVector *wv; + + // transform + wv = trVerts; + // it sounds really stupid to do this conversion with the new T&L code + // we should directly put the right information in the right structure + // wallVerts3D seems ok, doesn't need FOutVector + // also remove the light copy + + // More messy to unwrap, but it's also quicker, uses less memory. + wv->sow = wallVerts->s; + wv->tow = wallVerts->t; + wv->x = wallVerts->x; + wv->y = wallVerts->y; + wv->z = wallVerts->z; + wv++; wallVerts++; + wv->sow = wallVerts->s; + wv->tow = wallVerts->t; + wv->x = wallVerts->x; + wv->y = wallVerts->y; + wv->z = wallVerts->z; + wv++; wallVerts++; + wv->sow = wallVerts->s; + wv->tow = wallVerts->t; + wv->x = wallVerts->x; + wv->y = wallVerts->y; + wv->z = wallVerts->z; + wv++; wallVerts++; + wv->sow = wallVerts->s; + wv->tow = wallVerts->t; + wv->x = wallVerts->x; + wv->y = wallVerts->y; + wv->z = wallVerts->z; + + if (wallcolormap) + { + pSurf->FlatColor.rgba = HWR_Lighting(LightLevelToLum(lightlevel), wallcolormap->rgba, wallcolormap->fadergba, false, false); + } + else + { + pSurf->FlatColor.rgba = HWR_Lighting(LightLevelToLum(lightlevel), NORMALFOG, FADEFOG, false, false); + } + + HWD.pfnDrawPolygon(pSurf, trVerts, 4, blendmode|PF_Modulated|PF_Occlude|PF_Clip); + +#ifdef WALLSPLATS + if (gr_curline->linedef->splats && cv_splats.value) + HWR_DrawSegsSplats(pSurf); +#endif +#ifdef ALAM_LIGHTING + //Hurdler: TDOD: do static lighting using gr_curline->lm + HWR_WallLighting(trVerts); + + //Hurdler: for better dynamic light in dark area, we should draw the light first + // and then the wall all that with the right blending func + //HWD.pfnDrawPolygon(pSurf, trVerts, 4, PF_Additive|PF_Modulated|PF_Occlude|PF_Clip); +#endif +} + +// ========================================================================== +// BSP, CULL, ETC.. +// ========================================================================== + +// return the frac from the interception of the clipping line +// (in fact a clipping plane that has a constant, so can clip with simple 2d) +// with the wall segment +// +static float HWR_ClipViewSegment(INT32 x, polyvertex_t *v1, polyvertex_t *v2) +{ + float num, den; + float v1x, v1y, v1dx, v1dy, v2dx, v2dy; + angle_t pclipangle = gr_xtoviewangle[x]; + + // a segment of a polygon + v1x = v1->x; + v1y = v1->y; + v1dx = (v2->x - v1->x); + v1dy = (v2->y - v1->y); + + // the clipping line + pclipangle = pclipangle + dup_viewangle; //back to normal angle (non-relative) + v2dx = FIXED_TO_FLOAT(FINECOSINE(pclipangle>>ANGLETOFINESHIFT)); + v2dy = FIXED_TO_FLOAT(FINESINE(pclipangle>>ANGLETOFINESHIFT)); + + den = v2dy*v1dx - v2dx*v1dy; + if (den == 0) + return -1; // parallel + + // calc the frac along the polygon segment, + //num = (v2x - v1x)*v2dy + (v1y - v2y)*v2dx; + //num = -v1x * v2dy + v1y * v2dx; + num = (gr_viewx - v1x)*v2dy + (v1y - gr_viewy)*v2dx; + + return num / den; +} + +// +// HWR_SplitWall +// +static void HWR_SplitWall(sector_t *sector, wallVert3D *wallVerts, INT32 texnum, FSurfaceInfo* Surf, UINT32 cutflag) +{ + /* SoM: split up and light walls according to the + lightlist. This may also include leaving out parts + of the wall that can't be seen */ + GLTexture_t * glTex; + float realtop, realbot, top, bot; + float pegt, pegb, pegmul; + float height = 0.0f, bheight = 0.0f; + INT32 solid, i; + lightlist_t * list = sector->lightlist; + const UINT8 alpha = Surf->FlatColor.s.alpha; + FUINT lightnum; + extracolormap_t *colormap; + + realtop = top = wallVerts[2].y; + realbot = bot = wallVerts[0].y; + pegt = wallVerts[2].t; + pegb = wallVerts[0].t; + pegmul = (pegb - pegt) / (top - bot); + + for (i = 1; i < sector->numlights; i++) + { + if (top < realbot) + return; + + //Hurdler: fix a crashing bug, but is it correct? +// if (!list[i].caster) +// continue; + + solid = false; + + if (list[i].caster) + { + if (sector->lightlist[i].caster->flags & FF_SOLID && !(cutflag & FF_EXTRA)) + solid = true; + else if (sector->lightlist[i].caster->flags & FF_CUTEXTRA && cutflag & FF_EXTRA) + { + if (sector->lightlist[i].caster->flags & FF_EXTRA) + { + if (sector->lightlist[i].caster->flags == cutflag) // Only merge with your own types + solid = true; + } + else + solid = true; + } + else + solid = false; + } + else + solid = false; + + if (cutflag == FF_CUTSOLIDS) // These are regular walls sent in from StoreWallRange, they shouldn't be cut from this + solid = false; + + if (cutflag & FF_SOLID) // these weren't being cut before anyway, although they probably should be in the right conditions + solid = false; + + height = FIXED_TO_FLOAT(list[i].height); + if (solid) + bheight = FIXED_TO_FLOAT(*list[i].caster->bottomheight); + + if (height >= top) + { + if (solid && top > bheight) + top = bheight; + continue; + } + + //Found a break; + bot = height; + + if (bot < realbot) + bot = realbot; + + // colormap test + if (list[i-1].caster) + { + lightnum = *list[i-1].lightlevel; + colormap = list[i-1].extra_colormap; + } + else + { + lightnum = sector->lightlevel; + colormap = sector->extra_colormap; + } + + Surf->FlatColor.s.alpha = alpha; + + + wallVerts[3].t = wallVerts[2].t = pegt + ((realtop - top) * pegmul); + wallVerts[0].t = wallVerts[1].t = pegt + ((realtop - bot) * pegmul); + + // set top/bottom coords + wallVerts[2].y = wallVerts[3].y = top; + wallVerts[0].y = wallVerts[1].y = bot; + + glTex = HWR_GetTexture(texnum); + if (cutflag & FF_TRANSLUCENT) + HWR_AddTransparentWall(wallVerts, Surf, texnum, PF_Translucent, false, lightnum, colormap); + else if (glTex->mipmap.flags & TF_TRANSPARENT) + HWR_AddTransparentWall(wallVerts, Surf, texnum, PF_Environment, false, lightnum, colormap); + else + HWR_ProjectWall(wallVerts, Surf, PF_Masked, lightnum, colormap); + + if (solid) + top = bheight; + else + top = height; + } + + bot = realbot; + if (top <= realbot) + return; + + if (list[i-1].caster) + { + lightnum = *list[i-1].lightlevel; + colormap = list[i-1].extra_colormap; + } + else + { + lightnum = sector->lightlevel; + colormap = sector->extra_colormap; + } + Surf->FlatColor.s.alpha = alpha; + + wallVerts[3].t = wallVerts[2].t = pegt + ((realtop - top) * pegmul); + wallVerts[0].t = wallVerts[1].t = pegt + ((realtop - bot) * pegmul); + + // set top/bottom coords + wallVerts[2].y = wallVerts[3].y = top; + wallVerts[0].y = wallVerts[1].y = bot; + + glTex = HWR_GetTexture(texnum); + if (cutflag & FF_TRANSLUCENT) + HWR_AddTransparentWall(wallVerts, Surf, texnum, PF_Translucent, false, lightnum, colormap); + else if (glTex->mipmap.flags & TF_TRANSPARENT) + HWR_AddTransparentWall(wallVerts, Surf, texnum, PF_Environment, false, lightnum, colormap); + else + HWR_ProjectWall(wallVerts, Surf, PF_Masked, lightnum, colormap); +} + +// +// HWR_SplitFog +// Exclusively for fog +// +static void HWR_SplitFog(sector_t *sector, wallVert3D *wallVerts, FSurfaceInfo* Surf, UINT32 cutflag, FUINT lightnum, extracolormap_t *colormap) +{ + /* SoM: split up and light walls according to the + lightlist. This may also include leaving out parts + of the wall that can't be seen */ + float realtop, realbot, top, bot; + float pegt, pegb, pegmul; + float height = 0.0f, bheight = 0.0f; + INT32 solid, i; + lightlist_t * list = sector->lightlist; + const UINT8 alpha = Surf->FlatColor.s.alpha; + + realtop = top = wallVerts[2].y; + realbot = bot = wallVerts[0].y; + pegt = wallVerts[2].t; + pegb = wallVerts[0].t; + pegmul = (pegb - pegt) / (top - bot); + + for (i = 1; i < sector->numlights; i++) + { + if (top < realbot) + return; + + //Hurdler: fix a crashing bug, but is it correct? +// if (!list[i].caster) +// continue; + + solid = false; + + if (list[i].caster) + { + if (sector->lightlist[i].caster->flags & FF_SOLID && !(cutflag & FF_EXTRA)) + solid = true; + else if (sector->lightlist[i].caster->flags & FF_CUTEXTRA && cutflag & FF_EXTRA) + { + if (sector->lightlist[i].caster->flags & FF_EXTRA) + { + if (sector->lightlist[i].caster->flags == cutflag) + solid = true; + } + else + solid = true; + } + else + solid = false; + } + else + solid = false; + + height = FIXED_TO_FLOAT(list[i].height); + + if (solid) + bheight = FIXED_TO_FLOAT(*list[i].caster->bottomheight); + + if (height >= top) + { + if (solid && top > bheight) + top = bheight; + continue; + } + + //Found a break; + bot = height; + + if (bot < realbot) + bot = realbot; + + { + + + + Surf->FlatColor.s.alpha = alpha; + } + + wallVerts[3].t = wallVerts[2].t = pegt + ((realtop - top) * pegmul); + wallVerts[0].t = wallVerts[1].t = pegt + ((realtop - bot) * pegmul); + + // set top/bottom coords + wallVerts[2].y = wallVerts[3].y = top; + wallVerts[0].y = wallVerts[1].y = bot; + + if (!solid) // Don't draw it if there's more fog behind it + HWR_AddTransparentWall(wallVerts, Surf, 0, PF_Translucent|PF_NoTexture, true, lightnum, colormap); + + top = height; + } + + bot = realbot; + if (top <= realbot) + return; + + { + + Surf->FlatColor.s.alpha = alpha; + } + + wallVerts[3].t = wallVerts[2].t = pegt + ((realtop - top) * pegmul); + wallVerts[0].t = wallVerts[1].t = pegt + ((realtop - bot) * pegmul); + + // set top/bottom coords + wallVerts[2].y = wallVerts[3].y = top; + wallVerts[0].y = wallVerts[1].y = bot; + + HWR_AddTransparentWall(wallVerts, Surf, 0, PF_Translucent|PF_NoTexture, true, lightnum, colormap); +} + +// +// HWR_StoreWallRange +// A portion or all of a wall segment will be drawn, from startfrac to endfrac, +// where 0 is the start of the segment, 1 the end of the segment +// Anything between means the wall segment has been clipped with solidsegs, +// reducing wall overdraw to a minimum +// +static void HWR_StoreWallRange(double startfrac, double endfrac) +{ + wallVert3D wallVerts[4]; + v2d_t vs, ve; // start, end vertices of 2d line (view from above) + + fixed_t worldtop, worldbottom; + fixed_t worldhigh = 0, worldlow = 0; + + GLTexture_t *grTex = NULL; + float cliplow = 0.0f, cliphigh = 0.0f; + INT32 gr_midtexture; + fixed_t h, l; // 3D sides and 2s middle textures + + FUINT lightnum = 0; // shut up compiler + extracolormap_t *colormap; + FSurfaceInfo Surf; + + if (startfrac > endfrac) + return; + + gr_sidedef = gr_curline->sidedef; + gr_linedef = gr_curline->linedef; + + if (gr_frontsector->heightsec != -1) + { + worldtop = sectors[gr_frontsector->heightsec].ceilingheight; + worldbottom = sectors[gr_frontsector->heightsec].floorheight; + } + else + { + worldtop = gr_frontsector->ceilingheight; + worldbottom = gr_frontsector->floorheight; + } + + vs.x = ((polyvertex_t *)gr_curline->v1)->x; + vs.y = ((polyvertex_t *)gr_curline->v1)->y; + ve.x = ((polyvertex_t *)gr_curline->v2)->x; + ve.y = ((polyvertex_t *)gr_curline->v2)->y; + + // remember vertices ordering + // 3--2 + // | /| + // |/ | + // 0--1 + // make a wall polygon (with 2 triangles), using the floor/ceiling heights, + // and the 2d map coords of start/end vertices + wallVerts[0].x = wallVerts[3].x = vs.x; + wallVerts[0].z = wallVerts[3].z = vs.y; + wallVerts[2].x = wallVerts[1].x = ve.x; + wallVerts[2].z = wallVerts[1].z = ve.y; + wallVerts[0].w = wallVerts[1].w = wallVerts[2].w = wallVerts[3].w = 1.0f; + + if (drawtextured) + { + // x offset the texture + fixed_t texturehpeg = gr_sidedef->textureoffset + gr_curline->offset; + + // clip texture s start/end coords with solidsegs + if (startfrac > 0.0f && startfrac < 1.0f) + cliplow = (float)(texturehpeg + (gr_curline->flength*FRACUNIT) * startfrac); + else + cliplow = (float)texturehpeg; + + if (endfrac > 0.0f && endfrac < 1.0f) + cliphigh = (float)(texturehpeg + (gr_curline->flength*FRACUNIT) * endfrac); + else + cliphigh = (float)(texturehpeg + (gr_curline->flength*FRACUNIT)); + } + + lightnum = gr_frontsector->lightlevel; + colormap = gr_frontsector->extra_colormap; + + if (gr_frontsector) + { + Surf.FlatColor.s.alpha = 255; + } + + if (gr_backsector) + { + // two sided line + if (gr_backsector->heightsec != -1) + { + worldhigh = sectors[gr_backsector->heightsec].ceilingheight; + worldlow = sectors[gr_backsector->heightsec].floorheight; + } + else + { + worldhigh = gr_backsector->ceilingheight; + worldlow = gr_backsector->floorheight; + } + + // hack to allow height changes in outdoor areas + // This is what gets rid of the upper textures if there should be sky + if (gr_frontsector->ceilingpic == skyflatnum && + gr_backsector->ceilingpic == skyflatnum) + { + worldtop = worldhigh; + } + + // check TOP TEXTURE + if (worldhigh < worldtop && texturetranslation[gr_sidedef->toptexture] +#ifdef POLYOBJECTS // polyobjects don't have top textures, silly. + && !gr_curline->polyseg +#endif + ) + { + if (drawtextured) + { + fixed_t texturevpegtop; // top + + grTex = HWR_GetTexture(texturetranslation[gr_sidedef->toptexture]); + + // PEGGING + if (gr_linedef->flags & ML_DONTPEGTOP) + texturevpegtop = 0; + else + texturevpegtop = worldhigh + textureheight[gr_sidedef->toptexture] - worldtop; + + texturevpegtop += gr_sidedef->rowoffset; + + wallVerts[3].t = wallVerts[2].t = texturevpegtop * grTex->scaleY; + wallVerts[0].t = wallVerts[1].t = (texturevpegtop + worldtop - worldhigh) * grTex->scaleY; + wallVerts[0].s = wallVerts[3].s = cliplow * grTex->scaleX; + wallVerts[2].s = wallVerts[1].s = cliphigh * grTex->scaleX; + } + + // set top/bottom coords + wallVerts[2].y = wallVerts[3].y = FIXED_TO_FLOAT(worldtop); + wallVerts[0].y = wallVerts[1].y = FIXED_TO_FLOAT(worldhigh); + + if (gr_frontsector->numlights) + HWR_SplitWall(gr_frontsector, wallVerts, texturetranslation[gr_sidedef->toptexture], &Surf, FF_CUTSOLIDS); + else if (grTex->mipmap.flags & TF_TRANSPARENT) + HWR_AddTransparentWall(wallVerts, &Surf, texturetranslation[gr_sidedef->toptexture], PF_Environment, false, lightnum, colormap); + else + HWR_ProjectWall(wallVerts, &Surf, PF_Masked, lightnum, colormap); + } + + // check BOTTOM TEXTURE + if (worldlow > worldbottom && texturetranslation[gr_sidedef->bottomtexture] +#ifdef POLYOBJECTS // polyobjects don't have bottom textures, silly. + && !gr_curline->polyseg +#endif + ) //only if VISIBLE!!! + { + if (drawtextured) + { + fixed_t texturevpegbottom = 0; // bottom + + grTex = HWR_GetTexture(texturetranslation[gr_sidedef->bottomtexture]); + + // PEGGING + if (gr_linedef->flags & ML_DONTPEGBOTTOM) + texturevpegbottom = worldtop - worldlow; + else + texturevpegbottom = 0; + + texturevpegbottom += gr_sidedef->rowoffset; + + wallVerts[3].t = wallVerts[2].t = texturevpegbottom * grTex->scaleY; + wallVerts[0].t = wallVerts[1].t = (texturevpegbottom + worldlow - worldbottom) * grTex->scaleY; + wallVerts[0].s = wallVerts[3].s = cliplow * grTex->scaleX; + wallVerts[2].s = wallVerts[1].s = cliphigh * grTex->scaleX; + } + + // set top/bottom coords + wallVerts[2].y = wallVerts[3].y = FIXED_TO_FLOAT(worldlow); + wallVerts[0].y = wallVerts[1].y = FIXED_TO_FLOAT(worldbottom); + + if (gr_frontsector->numlights) + HWR_SplitWall(gr_frontsector, wallVerts, texturetranslation[gr_sidedef->bottomtexture], &Surf, FF_CUTSOLIDS); + else if (grTex->mipmap.flags & TF_TRANSPARENT) + HWR_AddTransparentWall(wallVerts, &Surf, texturetranslation[gr_sidedef->bottomtexture], PF_Environment, false, lightnum, colormap); + else + HWR_ProjectWall(wallVerts, &Surf, PF_Masked, lightnum, colormap); + } + gr_midtexture = texturetranslation[gr_sidedef->midtexture]; + if (gr_midtexture) + { + FBITFIELD blendmode; + sector_t *front, *back; + fixed_t popentop, popenbottom, polytop, polybottom, lowcut, highcut; + fixed_t texturevpeg = 0; + INT32 repeats; + + if (gr_linedef->frontsector->heightsec != -1) + front = §ors[gr_linedef->frontsector->heightsec]; + else + front = gr_linedef->frontsector; + + if (gr_linedef->backsector->heightsec != -1) + back = §ors[gr_linedef->backsector->heightsec]; + else + back = gr_linedef->backsector; + + if (gr_sidedef->repeatcnt) + repeats = 1 + gr_sidedef->repeatcnt; + else if (gr_linedef->flags & ML_EFFECT5) + { + fixed_t high, low; + + if (front->ceilingheight > back->ceilingheight) + high = back->ceilingheight; + else + high = front->ceilingheight; + + if (front->floorheight > back->floorheight) + low = front->floorheight; + else + low = back->floorheight; + + repeats = (high - low)/textureheight[gr_sidedef->midtexture]; + if ((high-low)%textureheight[gr_sidedef->midtexture]) + repeats++; // tile an extra time to fill the gap -- Monster Iestyn + } + else + repeats = 1; + + // SoM: a little note: This code re-arranging will + // fix the bug in Nimrod map02. popentop and popenbottom + // record the limits the texture can be displayed in. + // polytop and polybottom, are the ideal (i.e. unclipped) + // heights of the polygon, and h & l, are the final (clipped) + // poly coords. + +#ifdef POLYOBJECTS + // NOTE: With polyobjects, whenever you need to check the properties of the polyobject sector it belongs to, + // you must use the linedef's backsector to be correct + // From CB + if (gr_curline->polyseg) + { + popentop = back->ceilingheight; + popenbottom = back->floorheight; + } +#endif + else + { + popentop = front->ceilingheight < back->ceilingheight ? front->ceilingheight : back->ceilingheight; + popenbottom = front->floorheight > back->floorheight ? front->floorheight : back->floorheight; + } + + if (gr_linedef->flags & ML_DONTPEGBOTTOM) + { + polybottom = popenbottom + gr_sidedef->rowoffset; + polytop = polybottom + textureheight[gr_midtexture]*repeats; + } + else + { + polytop = popentop + gr_sidedef->rowoffset; + polybottom = polytop - textureheight[gr_midtexture]*repeats; + } + // CB +#ifdef POLYOBJECTS + // NOTE: With polyobjects, whenever you need to check the properties of the polyobject sector it belongs to, + // you must use the linedef's backsector to be correct + if (gr_curline->polyseg) + { + lowcut = polybottom; + highcut = polytop; + } +#endif + else + { + // The cut-off values of a linedef can always be constant, since every line has an absoulute front and or back sector + lowcut = front->floorheight > back->floorheight ? front->floorheight : back->floorheight; + highcut = front->ceilingheight < back->ceilingheight ? front->ceilingheight : back->ceilingheight; + } + + h = polytop > highcut ? highcut : polytop; + l = polybottom < lowcut ? lowcut : polybottom; + + if (drawtextured) + { + // PEGGING + if (gr_linedef->flags & ML_DONTPEGBOTTOM) + texturevpeg = textureheight[gr_sidedef->midtexture]*repeats - h + polybottom; + else + texturevpeg = polytop - h; + + grTex = HWR_GetTexture(gr_midtexture); + + wallVerts[3].t = wallVerts[2].t = texturevpeg * grTex->scaleY; + wallVerts[0].t = wallVerts[1].t = (h - l + texturevpeg) * grTex->scaleY; + wallVerts[0].s = wallVerts[3].s = cliplow * grTex->scaleX; + wallVerts[2].s = wallVerts[1].s = cliphigh * grTex->scaleX; + } + + // set top/bottom coords + // Take the texture peg into account, rather than changing the offsets past + // where the polygon might not be. + wallVerts[2].y = wallVerts[3].y = FIXED_TO_FLOAT(h); + wallVerts[0].y = wallVerts[1].y = FIXED_TO_FLOAT(l); + + // set alpha for transparent walls (new boom and legacy linedef types) + // ooops ! this do not work at all because render order we should render it in backtofront order + switch (gr_linedef->special) + { + case 900: + blendmode = HWR_TranstableToAlpha(tr_trans10, &Surf); + break; + case 901: + blendmode = HWR_TranstableToAlpha(tr_trans20, &Surf); + break; + case 902: + blendmode = HWR_TranstableToAlpha(tr_trans30, &Surf); + break; + case 903: + blendmode = HWR_TranstableToAlpha(tr_trans40, &Surf); + break; + case 904: + blendmode = HWR_TranstableToAlpha(tr_trans50, &Surf); + break; + case 905: + blendmode = HWR_TranstableToAlpha(tr_trans60, &Surf); + break; + case 906: + blendmode = HWR_TranstableToAlpha(tr_trans70, &Surf); + break; + case 907: + blendmode = HWR_TranstableToAlpha(tr_trans80, &Surf); + break; + case 908: + blendmode = HWR_TranstableToAlpha(tr_trans90, &Surf); + break; + // Translucent + case 102: + case 121: + case 123: + case 124: + case 125: + case 141: + case 142: + case 144: + case 145: + case 174: + case 175: + case 192: + case 195: + case 221: + case 253: + case 256: + blendmode = PF_Translucent; + break; + default: + blendmode = PF_Masked; + break; + } + if (grTex->mipmap.flags & TF_TRANSPARENT) + blendmode = PF_Environment; + + if (gr_frontsector->numlights) + HWR_SplitWall(gr_frontsector, wallVerts, gr_midtexture, &Surf, FF_CUTSOLIDS); + else if (!(blendmode & PF_Masked)) + HWR_AddTransparentWall(wallVerts, &Surf, gr_midtexture, blendmode, false, lightnum, colormap); + else + HWR_ProjectWall(wallVerts, &Surf, blendmode, lightnum, colormap); + + // If there is a colormap change, remove it. +/* if (!(Surf.FlatColor.s.red + Surf.FlatColor.s.green + Surf.FlatColor.s.blue == Surf.FlatColor.s.red/3) + { + Surf.FlatColor.s.red = Surf.FlatColor.s.green = Surf.FlatColor.s.blue = 0xff; + Surf.FlatColor.rgba = 0xffffffff; + }*/ + } + } + else + { + // Single sided line... Deal only with the middletexture (if one exists) + gr_midtexture = texturetranslation[gr_sidedef->midtexture]; + if (gr_midtexture) + { + if (drawtextured) + { + fixed_t texturevpeg; + // PEGGING + if (gr_linedef->flags & ML_DONTPEGBOTTOM) + texturevpeg = worldbottom + textureheight[gr_sidedef->midtexture] - worldtop + gr_sidedef->rowoffset; + else + // top of texture at top + texturevpeg = gr_sidedef->rowoffset; + + grTex = HWR_GetTexture(gr_midtexture); + + wallVerts[3].t = wallVerts[2].t = texturevpeg * grTex->scaleY; + wallVerts[0].t = wallVerts[1].t = (texturevpeg + worldtop - worldbottom) * grTex->scaleY; + wallVerts[0].s = wallVerts[3].s = cliplow * grTex->scaleX; + wallVerts[2].s = wallVerts[1].s = cliphigh * grTex->scaleX; + } + // set top/bottom coords + wallVerts[2].y = wallVerts[3].y = FIXED_TO_FLOAT(worldtop); + wallVerts[0].y = wallVerts[1].y = FIXED_TO_FLOAT(worldbottom); + + // I don't think that solid walls can use translucent linedef types... + if (gr_frontsector->numlights) + HWR_SplitWall(gr_frontsector, wallVerts, gr_midtexture, &Surf, FF_CUTSOLIDS); + else + { + if (grTex->mipmap.flags & TF_TRANSPARENT) + HWR_AddTransparentWall(wallVerts, &Surf, gr_midtexture, PF_Environment, false, lightnum, colormap); + else + HWR_ProjectWall(wallVerts, &Surf, PF_Masked, lightnum, colormap); + } + } + } + + + //Hurdler: 3d-floors test +#ifdef R_FAKEFLOORS + if (gr_frontsector && gr_backsector && gr_frontsector->tag != gr_backsector->tag && (gr_backsector->ffloors || gr_frontsector->ffloors)) + { + ffloor_t * rover; + fixed_t highcut = 0, lowcut = 0; + + highcut = gr_frontsector->ceilingheight < gr_backsector->ceilingheight ? gr_frontsector->ceilingheight : gr_backsector->ceilingheight; + lowcut = gr_frontsector->floorheight > gr_backsector->floorheight ? gr_frontsector->floorheight : gr_backsector->floorheight; + + if (gr_backsector->ffloors) + { + for (rover = gr_backsector->ffloors; rover; rover = rover->next) + { + if (!(rover->flags & FF_EXISTS) || !(rover->flags & FF_RENDERSIDES) || (rover->flags & FF_INVERTSIDES)) + continue; + if (*rover->topheight < lowcut || *rover->bottomheight > highcut) + continue; + + + h = *rover->topheight; + l = *rover->bottomheight; + if (h > highcut) + h = highcut; + if (l < lowcut) + l = lowcut; + //Hurdler: HW code starts here + //FIXME: check if peging is correct + // set top/bottom coords + wallVerts[2].y = wallVerts[3].y = FIXED_TO_FLOAT(h); + wallVerts[0].y = wallVerts[1].y = FIXED_TO_FLOAT(l); + if (rover->flags & FF_FOG) + { + wallVerts[3].t = wallVerts[2].t = 0; + wallVerts[0].t = wallVerts[1].t = 0; + wallVerts[0].s = wallVerts[3].s = 0; + wallVerts[2].s = wallVerts[1].s = 0; + } + else if (drawtextured) + { + grTex = HWR_GetTexture(texturetranslation[sides[rover->master->sidenum[0]].midtexture]); + + wallVerts[3].t = wallVerts[2].t = (*rover->topheight - h + sides[rover->master->sidenum[0]].rowoffset) * grTex->scaleY; + wallVerts[0].t = wallVerts[1].t = (h - l + (*rover->topheight - h + sides[rover->master->sidenum[0]].rowoffset)) * grTex->scaleY; + wallVerts[0].s = wallVerts[3].s = cliplow * grTex->scaleX; + wallVerts[2].s = wallVerts[1].s = cliphigh * grTex->scaleX; + } + if (rover->flags & FF_FOG) + { + FBITFIELD blendmode; + + blendmode = PF_Translucent|PF_NoTexture; + + lightnum = rover->master->frontsector->lightlevel; + colormap = rover->master->frontsector->extra_colormap; + + if (rover->master->frontsector->extra_colormap) + { + + Surf.FlatColor.s.alpha = HWR_FogBlockAlpha(rover->master->frontsector->lightlevel,rover->master->frontsector->extra_colormap->rgba,rover->master->frontsector->extra_colormap->fadergba); + } + else + { + Surf.FlatColor.s.alpha = HWR_FogBlockAlpha(rover->master->frontsector->lightlevel,NORMALFOG,FADEFOG); + } + + if (gr_frontsector->numlights) + HWR_SplitFog(gr_frontsector, wallVerts, &Surf, rover->flags, lightnum, colormap); + else + HWR_AddTransparentWall(wallVerts, &Surf, 0, blendmode, true, lightnum, colormap); + } + else + { + FBITFIELD blendmode = PF_Masked; + + if (rover->flags & FF_TRANSLUCENT) + { + blendmode = PF_Translucent; + Surf.FlatColor.s.alpha = (UINT8)rover->alpha-1 > 255 ? 255 : rover->alpha-1; + } + else if (grTex->mipmap.flags & TF_TRANSPARENT) + { + blendmode = PF_Environment; + } + + if (gr_frontsector->numlights) + HWR_SplitWall(gr_frontsector, wallVerts, texturetranslation[sides[rover->master->sidenum[0]].midtexture], &Surf, rover->flags); + else + { + if (blendmode != PF_Masked) + HWR_AddTransparentWall(wallVerts, &Surf, texturetranslation[sides[rover->master->sidenum[0]].midtexture], blendmode, false, lightnum, colormap); + else + HWR_ProjectWall(wallVerts, &Surf, PF_Masked, lightnum, colormap); + } + } + } + } + + if (gr_frontsector->ffloors) // Putting this seperate should allow 2 FOF sectors to be connected without too many errors? I think? + { + for (rover = gr_frontsector->ffloors; rover; rover = rover->next) + { + if (!(rover->flags & FF_EXISTS) || !(rover->flags & FF_RENDERSIDES) || !(rover->flags & FF_ALLSIDES)) + continue; + if (*rover->topheight < lowcut || *rover->bottomheight > highcut) + continue; + + h = *rover->topheight; + l = *rover->bottomheight; + if (h > highcut) + h = highcut; + if (l < lowcut) + l = lowcut; + //Hurdler: HW code starts here + //FIXME: check if peging is correct + // set top/bottom coords + wallVerts[2].y = wallVerts[3].y = FIXED_TO_FLOAT(h); + wallVerts[0].y = wallVerts[1].y = FIXED_TO_FLOAT(l); + + if (rover->flags & FF_FOG) + { + wallVerts[3].t = wallVerts[2].t = 0; + wallVerts[0].t = wallVerts[1].t = 0; + wallVerts[0].s = wallVerts[3].s = 0; + wallVerts[2].s = wallVerts[1].s = 0; + } + else if (drawtextured) + { + grTex = HWR_GetTexture(texturetranslation[sides[rover->master->sidenum[0]].midtexture]); + + wallVerts[3].t = wallVerts[2].t = (*rover->topheight - h + sides[rover->master->sidenum[0]].rowoffset) * grTex->scaleY; + wallVerts[0].t = wallVerts[1].t = (h - l + (*rover->topheight - h + sides[rover->master->sidenum[0]].rowoffset)) * grTex->scaleY; + wallVerts[0].s = wallVerts[3].s = cliplow * grTex->scaleX; + wallVerts[2].s = wallVerts[1].s = cliphigh * grTex->scaleX; + } + + if (rover->flags & FF_FOG) + { + FBITFIELD blendmode; + + blendmode = PF_Translucent|PF_NoTexture; + + lightnum = rover->master->frontsector->lightlevel; + colormap = rover->master->frontsector->extra_colormap; + + if (rover->master->frontsector->extra_colormap) + { + Surf.FlatColor.s.alpha = HWR_FogBlockAlpha(rover->master->frontsector->lightlevel,rover->master->frontsector->extra_colormap->rgba,rover->master->frontsector->extra_colormap->fadergba); + } + else + { + Surf.FlatColor.s.alpha = HWR_FogBlockAlpha(rover->master->frontsector->lightlevel,NORMALFOG,FADEFOG); + } + + if (gr_backsector->numlights) + HWR_SplitFog(gr_backsector, wallVerts, &Surf, rover->flags, lightnum, colormap); + else + HWR_AddTransparentWall(wallVerts, &Surf, 0, blendmode, true, lightnum, colormap); + } + else + { + FBITFIELD blendmode = PF_Masked; + + if (rover->flags & FF_TRANSLUCENT) + { + blendmode = PF_Translucent; + Surf.FlatColor.s.alpha = (UINT8)rover->alpha-1 > 255 ? 255 : rover->alpha-1; + } + else if (grTex->mipmap.flags & TF_TRANSPARENT) + { + blendmode = PF_Environment; + } + + if (gr_backsector->numlights) + HWR_SplitWall(gr_backsector, wallVerts, texturetranslation[sides[rover->master->sidenum[0]].midtexture], &Surf, rover->flags); + else + { + if (blendmode != PF_Masked) + HWR_AddTransparentWall(wallVerts, &Surf, texturetranslation[sides[rover->master->sidenum[0]].midtexture], blendmode, false, lightnum, colormap); + else + HWR_ProjectWall(wallVerts, &Surf, PF_Masked, lightnum, colormap); + } + } + } + } + } +#endif +//Hurdler: end of 3d-floors test +} + +//Hurdler: just like in r_bsp.c +#if 1 +#define MAXSEGS MAXVIDWIDTH/2+1 +#else +//Alam_GBC: Or not (may cause overflow) +#define MAXSEGS 128 +#endif + +// hw_newend is one past the last valid seg +static cliprange_t * hw_newend; +static cliprange_t gr_solidsegs[MAXSEGS]; + + +static void printsolidsegs(void) +{ + cliprange_t * start; + if (!hw_newend || cv_grbeta.value != 2) + return; + for (start = gr_solidsegs;start != hw_newend;start++) + { + CONS_Debug(DBG_RENDER, "%d-%d|",start->first,start->last); + } + CONS_Debug(DBG_RENDER, "\n\n"); +} + +// +// +// +static void HWR_ClipSolidWallSegment(INT32 first, INT32 last) +{ + cliprange_t *next, *start; + float lowfrac, highfrac; + boolean poorhack = false; + + // Find the first range that touches the range + // (adjacent pixels are touching). + start = gr_solidsegs; + while (start->last < first-1) + start++; + + if (first < start->first) + { + if (last < start->first-1) + { + // Post is entirely visible (above start), + // so insert a new clippost. + HWR_StoreWallRange(first, last); + + next = hw_newend; + hw_newend++; + + while (next != start) + { + *next = *(next-1); + next--; + } + + next->first = first; + next->last = last; + printsolidsegs(); + return; + } + + // There is a fragment above *start. + if (!cv_grclipwalls.value) + { + if (!poorhack) HWR_StoreWallRange(first, last); + poorhack = true; + } + else + { + highfrac = HWR_ClipViewSegment(start->first+1, (polyvertex_t *)gr_curline->v1, (polyvertex_t *)gr_curline->v2); + HWR_StoreWallRange(0, highfrac); + } + // Now adjust the clip size. + start->first = first; + } + + // Bottom contained in start? + if (last <= start->last) + { + printsolidsegs(); + return; + } + next = start; + while (last >= (next+1)->first-1) + { + // There is a fragment between two posts. + if (!cv_grclipwalls.value) + { + if (!poorhack) HWR_StoreWallRange(first,last); + poorhack = true; + } + else + { + lowfrac = HWR_ClipViewSegment(next->last-1, (polyvertex_t *)gr_curline->v1, (polyvertex_t *)gr_curline->v2); + highfrac = HWR_ClipViewSegment((next+1)->first+1, (polyvertex_t *)gr_curline->v1, (polyvertex_t *)gr_curline->v2); + HWR_StoreWallRange(lowfrac, highfrac); + } + next++; + + if (last <= next->last) + { + // Bottom is contained in next. + // Adjust the clip size. + start->last = next->last; + goto crunch; + } + } + + if (first == next->first+1) // 1 line texture + { + if (!cv_grclipwalls.value) + { + if (!poorhack) HWR_StoreWallRange(first,last); + poorhack = true; + } + else + HWR_StoreWallRange(0, 1); + } + else + { + // There is a fragment after *next. + if (!cv_grclipwalls.value) + { + if (!poorhack) HWR_StoreWallRange(first,last); + poorhack = true; + } + else + { + lowfrac = HWR_ClipViewSegment(next->last-1, (polyvertex_t *)gr_curline->v1, (polyvertex_t *)gr_curline->v2); + HWR_StoreWallRange(lowfrac, 1); + } + } + + // Adjust the clip size. + start->last = last; + + // Remove start+1 to next from the clip list, + // because start now covers their area. +crunch: + if (next == start) + { + printsolidsegs(); + // Post just extended past the bottom of one post. + return; + } + + + while (next++ != hw_newend) + { + // Remove a post. + *++start = *next; + } + + hw_newend = start; + printsolidsegs(); +} + +// +// handle LineDefs with upper and lower texture (windows) +// +static void HWR_ClipPassWallSegment(INT32 first, INT32 last) +{ + cliprange_t *start; + float lowfrac, highfrac; + //to allow noclipwalls but still solidseg reject of non-visible walls + boolean poorhack = false; + + // Find the first range that touches the range + // (adjacent pixels are touching). + start = gr_solidsegs; + while (start->last < first - 1) + start++; + + if (first < start->first) + { + if (last < start->first-1) + { + // Post is entirely visible (above start). + HWR_StoreWallRange(0, 1); + return; + } + + // There is a fragment above *start. + if (!cv_grclipwalls.value) + { //20/08/99: Changed by Hurdler (taken from faB's code) + if (!poorhack) HWR_StoreWallRange(0, 1); + poorhack = true; + } + else + { + highfrac = HWR_ClipViewSegment(min(start->first + 1, + start->last), (polyvertex_t *)gr_curline->v1, + (polyvertex_t *)gr_curline->v2); + HWR_StoreWallRange(0, highfrac); + } + } + + // Bottom contained in start? + if (last <= start->last) + return; + + while (last >= (start+1)->first-1) + { + // There is a fragment between two posts. + if (!cv_grclipwalls.value) + { + if (!poorhack) HWR_StoreWallRange(0, 1); + poorhack = true; + } + else + { + lowfrac = HWR_ClipViewSegment(max(start->last-1,start->first), (polyvertex_t *)gr_curline->v1, (polyvertex_t *)gr_curline->v2); + highfrac = HWR_ClipViewSegment(min((start+1)->first+1,(start+1)->last), (polyvertex_t *)gr_curline->v1, (polyvertex_t *)gr_curline->v2); + HWR_StoreWallRange(lowfrac, highfrac); + } + start++; + + if (last <= start->last) + return; + } + + if (first == start->first+1) // 1 line texture + { + if (!cv_grclipwalls.value) + { + if (!poorhack) HWR_StoreWallRange(0, 1); + poorhack = true; + } + else + HWR_StoreWallRange(0, 1); + } + else + { + // There is a fragment after *next. + if (!cv_grclipwalls.value) + { + if (!poorhack) HWR_StoreWallRange(0,1); + poorhack = true; + } + else + { + lowfrac = HWR_ClipViewSegment(max(start->last - 1, + start->first), (polyvertex_t *)gr_curline->v1, + (polyvertex_t *)gr_curline->v2); + HWR_StoreWallRange(lowfrac, 1); + } + } +} + +// -------------------------------------------------------------------------- +// HWR_ClipToSolidSegs check if it is hide by wall (solidsegs) +// -------------------------------------------------------------------------- +static boolean HWR_ClipToSolidSegs(INT32 first, INT32 last) +{ + cliprange_t * start; + + // Find the first range that touches the range + // (adjacent pixels are touching). + start = gr_solidsegs; + while (start->last < first-1) + start++; + + if (first < start->first) + return true; + + // Bottom contained in start? + if (last <= start->last) + return false; + + return true; +} + +// +// HWR_ClearClipSegs +// +static void HWR_ClearClipSegs(void) +{ + gr_solidsegs[0].first = -0x7fffffff; + gr_solidsegs[0].last = -1; + gr_solidsegs[1].first = vid.width; //viewwidth; + gr_solidsegs[1].last = 0x7fffffff; + hw_newend = gr_solidsegs+2; +} + +// -----------------+ +// HWR_AddLine : Clips the given segment and adds any visible pieces to the line list. +// Notes : gr_cursectorlight is set to the current subsector -> sector -> light value +// : (it may be mixed with the wall's own flat colour in the future ...) +// -----------------+ +static void HWR_AddLine(seg_t * line) +{ + INT32 x1, x2; + angle_t angle1, angle2; + angle_t span, tspan; + + // SoM: Backsector needs to be run through R_FakeFlat + sector_t tempsec; + + if (line->polyseg && !(line->polyseg->flags & POF_RENDERSIDES)) + return; + + gr_curline = line; + + // OPTIMIZE: quickly reject orthogonal back sides. + angle1 = R_PointToAngle(FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v1)->x), + FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v1)->y)); + angle2 = R_PointToAngle(FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v2)->x), + FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v2)->y)); + + // Clip to view edges. + span = angle1 - angle2; + + // backface culling : span is < ANGLE_180 if ang1 > ang2 : the seg is facing + if (span >= ANGLE_180) + return; + + // Global angle needed by segcalc. + //rw_angle1 = angle1; + angle1 -= dup_viewangle; + angle2 -= dup_viewangle; + + tspan = angle1 + gr_clipangle; + if (tspan > 2*gr_clipangle) + { + tspan -= 2*gr_clipangle; + + // Totally off the left edge? + if (tspan >= span) + return; + + angle1 = gr_clipangle; + } + tspan = gr_clipangle - angle2; + if (tspan > 2*gr_clipangle) + { + tspan -= 2*gr_clipangle; + + // Totally off the left edge? + if (tspan >= span) + return; + + angle2 = (angle_t)-(signed)gr_clipangle; + } + +#if 0 + { + float fx1,fx2,fy1,fy2; + //BP: test with a better projection than viewangletox[R_PointToAngle(angle)] + // do not enable this at release 4 mul and 2 div + fx1 = ((polyvertex_t *)(line->v1))->x-gr_viewx; + fy1 = ((polyvertex_t *)(line->v1))->y-gr_viewy; + fy2 = (fx1 * gr_viewcos + fy1 * gr_viewsin); + if (fy2 < 0) + // the point is back + fx1 = 0; + else + fx1 = gr_windowcenterx + (fx1 * gr_viewsin - fy1 * gr_viewcos) * gr_centerx / fy2; + + fx2 = ((polyvertex_t *)(line->v2))->x-gr_viewx; + fy2 = ((polyvertex_t *)(line->v2))->y-gr_viewy; + fy1 = (fx2 * gr_viewcos + fy2 * gr_viewsin); + if (fy1 < 0) + // the point is back + fx2 = vid.width; + else + fx2 = gr_windowcenterx + (fx2 * gr_viewsin - fy2 * gr_viewcos) * gr_centerx / fy1; + + x1 = fx1+0.5f; + x2 = fx2+0.5f; + } +#else + // The seg is in the view range, + // but not necessarily visible. + angle1 = (angle1+ANGLE_90)>>ANGLETOFINESHIFT; + angle2 = (angle2+ANGLE_90)>>ANGLETOFINESHIFT; + + x1 = gr_viewangletox[angle1]; + x2 = gr_viewangletox[angle2]; +#endif + // Does not cross a pixel? +// if (x1 == x2) +/* { + // BP: HERE IS THE MAIN PROBLEM ! + //CONS_Debug(DBG_RENDER, "tineline\n"); + return; + } +*/ + gr_backsector = line->backsector; + + // Single sided line? + if (!gr_backsector) + goto clipsolid; + + gr_backsector = R_FakeFlat(gr_backsector, &tempsec, NULL, NULL, true); + + // Closed door. + if (gr_backsector->ceilingheight <= gr_frontsector->floorheight || + gr_backsector->floorheight >= gr_frontsector->ceilingheight) + goto clipsolid; + + // Window. + if (gr_backsector->ceilingheight != gr_frontsector->ceilingheight || + gr_backsector->floorheight != gr_frontsector->floorheight) + goto clippass; + + // Reject empty lines used for triggers and special events. + // Identical floor and ceiling on both sides, + // identical light levels on both sides, + // and no middle texture. + if ( +#ifdef POLYOBJECTS + !line->polyseg +#endif + && gr_backsector->ceilingpic == gr_frontsector->ceilingpic + && gr_backsector->floorpic == gr_frontsector->floorpic + && gr_backsector->lightlevel == gr_frontsector->lightlevel + && gr_curline->sidedef->midtexture == 0 + && !gr_backsector->ffloors && !gr_frontsector->ffloors) + // SoM: For 3D sides... Boris, would you like to take a + // crack at rendering 3D sides? You would need to add the + // above check and add code to HWR_StoreWallRange... + { + return; + } + +clippass: + if (x1 == x2) + { x2++;x1 -= 2; } + HWR_ClipPassWallSegment(x1, x2-1); + return; + +clipsolid: + if (x1 == x2) + goto clippass; + HWR_ClipSolidWallSegment(x1, x2-1); +} + +// HWR_CheckBBox +// Checks BSP node/subtree bounding box. +// Returns true +// if some part of the bbox might be visible. +// +// modified to use local variables + +static boolean HWR_CheckBBox(fixed_t *bspcoord) +{ + INT32 boxpos, sx1, sx2; + fixed_t px1, py1, px2, py2; + angle_t angle1, angle2, span, tspan; + + // Find the corners of the box + // that define the edges from current viewpoint. + if (dup_viewx <= bspcoord[BOXLEFT]) + boxpos = 0; + else if (dup_viewx < bspcoord[BOXRIGHT]) + boxpos = 1; + else + boxpos = 2; + + if (dup_viewy >= bspcoord[BOXTOP]) + boxpos |= 0; + else if (dup_viewy > bspcoord[BOXBOTTOM]) + boxpos |= 1<<2; + else + boxpos |= 2<<2; + + if (boxpos == 5) + return true; + + px1 = bspcoord[checkcoord[boxpos][0]]; + py1 = bspcoord[checkcoord[boxpos][1]]; + px2 = bspcoord[checkcoord[boxpos][2]]; + py2 = bspcoord[checkcoord[boxpos][3]]; + + // check clip list for an open space + angle1 = R_PointToAngle(px1, py1) - dup_viewangle; + angle2 = R_PointToAngle(px2, py2) - dup_viewangle; + + span = angle1 - angle2; + + // Sitting on a line? + if (span >= ANGLE_180) + return true; + + tspan = angle1 + gr_clipangle; + + if (tspan > 2*gr_clipangle) + { + tspan -= 2*gr_clipangle; + + // Totally off the left edge? + if (tspan >= span) + return false; + + angle1 = gr_clipangle; + } + tspan = gr_clipangle - angle2; + if (tspan > 2*gr_clipangle) + { + tspan -= 2*gr_clipangle; + + // Totally off the left edge? + if (tspan >= span) + return false; + + angle2 = (angle_t)-(signed)gr_clipangle; + } + + // Find the first clippost + // that touches the source post + // (adjacent pixels are touching). + angle1 = (angle1+ANGLE_90)>>ANGLETOFINESHIFT; + angle2 = (angle2+ANGLE_90)>>ANGLETOFINESHIFT; + sx1 = gr_viewangletox[angle1]; + sx2 = gr_viewangletox[angle2]; + + // Does not cross a pixel. + if (sx1 == sx2) + return false; + + return HWR_ClipToSolidSegs(sx1, sx2 - 1); +} + +#ifdef POLYOBJECTS + +// +// HWR_AddPolyObjectSegs +// +// haleyjd 02/19/06 +// Adds all segs in all polyobjects in the given subsector. +// Modified for hardware rendering. +// +static inline void HWR_AddPolyObjectSegs(void) +{ + size_t i, j; + seg_t *gr_fakeline = Z_Calloc(sizeof(seg_t), PU_STATIC, NULL); + polyvertex_t *pv1 = Z_Calloc(sizeof(polyvertex_t), PU_STATIC, NULL); + polyvertex_t *pv2 = Z_Calloc(sizeof(polyvertex_t), PU_STATIC, NULL); + + // Sort through all the polyobjects + for (i = 0; i < numpolys; ++i) + { + // Render the polyobject's lines + for (j = 0; j < po_ptrs[i]->segCount; ++j) + { + // Copy the info of a polyobject's seg, then convert it to OpenGL floating point + M_Memcpy(gr_fakeline, po_ptrs[i]->segs[j], sizeof(seg_t)); + + // Now convert the line to float and add it to be rendered + pv1->x = FIXED_TO_FLOAT(gr_fakeline->v1->x); + pv1->y = FIXED_TO_FLOAT(gr_fakeline->v1->y); + pv2->x = FIXED_TO_FLOAT(gr_fakeline->v2->x); + pv2->y = FIXED_TO_FLOAT(gr_fakeline->v2->y); + + gr_fakeline->v1 = (vertex_t *)pv1; + gr_fakeline->v2 = (vertex_t *)pv2; + + HWR_AddLine(gr_fakeline); + } + } + + // Free temporary data no longer needed + Z_Free(pv2); + Z_Free(pv1); + Z_Free(gr_fakeline); +} +#endif + +// -----------------+ +// HWR_Subsector : Determine floor/ceiling planes. +// : Add sprites of things in sector. +// : Draw one or more line segments. +// Notes : Sets gr_cursectorlight to the light of the parent sector, to modulate wall textures +// -----------------+ +static lumpnum_t doomwaterflat; //set by R_InitFlats hack +static void HWR_Subsector(size_t num) +{ + INT16 count; + seg_t *line; + subsector_t *sub; + sector_t tempsec; //SoM: 4/7/2000 + INT32 floorlightlevel; + INT32 ceilinglightlevel; + INT32 locFloorHeight, locCeilingHeight; + INT32 light = 0; + fixed_t wh; + extracolormap_t *floorcolormap; + extracolormap_t *ceilingcolormap; + +#ifdef PARANOIA //no risk while developing, enough debugging nights! + if (num >= addsubsector) + I_Error("HWR_Subsector: ss %s with numss = %s, addss = %s\n", + sizeu1(num), sizeu2(numsubsectors), sizeu3(addsubsector)); + + /*if (num >= numsubsectors) + I_Error("HWR_Subsector: ss %i with numss = %i", + num, + numsubsectors);*/ +#endif + + if (num < numsubsectors) + { + sscount++; + // subsector + sub = &subsectors[num]; + // sector + gr_frontsector = sub->sector; + // how many linedefs + count = sub->numlines; + // first line seg + line = &segs[sub->firstline]; + } + else + { + // there are no segs but only planes + sub = &subsectors[0]; + gr_frontsector = sub->sector; + count = 0; + line = NULL; + } + + //SoM: 4/7/2000: Test to make Boom water work in Hardware mode. + gr_frontsector = R_FakeFlat(gr_frontsector, &tempsec, &floorlightlevel, + &ceilinglightlevel, false); + //FIXME: Use floorlightlevel and ceilinglightlevel insted of lightlevel. + + floorcolormap = ceilingcolormap = gr_frontsector->extra_colormap; + + // ------------------------------------------------------------------------ + // sector lighting, DISABLED because it's done in HWR_StoreWallRange + // ------------------------------------------------------------------------ + /// \todo store a RGBA instead of just intensity, allow coloured sector lighting + //light = (FUBYTE)(sub->sector->lightlevel & 0xFF) / 255.0f; + //gr_cursectorlight.red = light; + //gr_cursectorlight.green = light; + //gr_cursectorlight.blue = light; + //gr_cursectorlight.alpha = light; + +// ----- for special tricks with HW renderer ----- + if (gr_frontsector->pseudoSector) + { + locFloorHeight = gr_frontsector->virtualFloorheight; + locCeilingHeight = gr_frontsector->virtualCeilingheight; + } + else if (gr_frontsector->virtualFloor) + { + locFloorHeight = gr_frontsector->virtualFloorheight; + if (gr_frontsector->virtualCeiling) + locCeilingHeight = gr_frontsector->virtualCeilingheight; + else + locCeilingHeight = gr_frontsector->ceilingheight; + } + else if (gr_frontsector->virtualCeiling) + { + locCeilingHeight = gr_frontsector->virtualCeilingheight; + locFloorHeight = gr_frontsector->floorheight; + } + else + { + locFloorHeight = gr_frontsector->floorheight; + locCeilingHeight = gr_frontsector->ceilingheight; + } +// ----- end special tricks ----- + + if (gr_frontsector->ffloors) + { + if (gr_frontsector->moved) + { + gr_frontsector->numlights = sub->sector->numlights = 0; + R_Prep3DFloors(gr_frontsector); + sub->sector->lightlist = gr_frontsector->lightlist; + sub->sector->numlights = gr_frontsector->numlights; + sub->sector->moved = gr_frontsector->moved = false; + } + + light = R_GetPlaneLight(gr_frontsector, locFloorHeight, false); + if (gr_frontsector->floorlightsec == -1) + floorlightlevel = *gr_frontsector->lightlist[light].lightlevel; + floorcolormap = gr_frontsector->lightlist[light].extra_colormap; + + light = R_GetPlaneLight(gr_frontsector, locCeilingHeight, false); + if (gr_frontsector->ceilinglightsec == -1) + ceilinglightlevel = *gr_frontsector->lightlist[light].lightlevel; + ceilingcolormap = gr_frontsector->lightlist[light].extra_colormap; + } + + sub->sector->extra_colormap = gr_frontsector->extra_colormap; + + // render floor ? +#ifdef DOPLANES + // yeah, easy backface cull! :) + if (locFloorHeight < dup_viewz) + { + if (gr_frontsector->floorpic != skyflatnum) + { + if (sub->validcount != validcount) + { + HWR_GetFlat(levelflats[gr_frontsector->floorpic].lumpnum); + HWR_RenderPlane(gr_frontsector, &extrasubsectors[num], locFloorHeight, PF_Occlude, floorlightlevel, levelflats[gr_frontsector->floorpic].lumpnum, NULL, 255, false, floorcolormap); + } + } + else + { +#ifdef POLYSKY + HWR_RenderSkyPlane(&extrasubsectors[num], locFloorHeight); +#endif + } + } + + if (locCeilingHeight > dup_viewz) + { + if (gr_frontsector->ceilingpic != skyflatnum) + { + if (sub->validcount != validcount) + { + HWR_GetFlat(levelflats[gr_frontsector->ceilingpic].lumpnum); + HWR_RenderPlane(NULL, &extrasubsectors[num], locCeilingHeight, PF_Occlude, ceilinglightlevel, levelflats[gr_frontsector->ceilingpic].lumpnum,NULL, 255, false, ceilingcolormap); + } + } + else + { +#ifdef POLYSKY + HWR_RenderSkyPlane(&extrasubsectors[num], locCeilingHeight); +#endif + } + } + +#ifndef POLYSKY + // Moved here because before, when above the ceiling and the floor does not have the sky flat, it doesn't draw the sky + if (gr_frontsector->ceilingpic == skyflatnum || gr_frontsector->floorpic == skyflatnum) + { + drawsky = true; + } +#endif + +#ifdef R_FAKEFLOORS + if (gr_frontsector->ffloors) + { + /// \todo fix light, xoffs, yoffs, extracolormap ? + ffloor_t * rover; + + R_Prep3DFloors(gr_frontsector); + for (rover = gr_frontsector->ffloors; + rover; rover = rover->next) + { + + if (!(rover->flags & FF_EXISTS) || !(rover->flags & FF_RENDERPLANES)) + continue; + if (sub->validcount == validcount) + continue; + + if (*rover->bottomheight <= gr_frontsector->ceilingheight && + *rover->bottomheight >= gr_frontsector->floorheight && + ((dup_viewz < *rover->bottomheight && !(rover->flags & FF_INVERTPLANES)) || + (dup_viewz > *rover->bottomheight && (rover->flags & FF_BOTHPLANES || rover->flags & FF_INVERTPLANES)))) + { + if (rover->flags & FF_FOG) + { + UINT8 alpha; + + light = R_GetPlaneLight(gr_frontsector, *rover->bottomheight, dup_viewz < *rover->bottomheight ? true : false); + + if (rover->master->frontsector->extra_colormap) + alpha = HWR_FogBlockAlpha(*gr_frontsector->lightlist[light].lightlevel, rover->master->frontsector->extra_colormap->rgba, rover->master->frontsector->extra_colormap->fadergba); + else + alpha = HWR_FogBlockAlpha(*gr_frontsector->lightlist[light].lightlevel, NORMALFOG, FADEFOG); + + HWR_AddTransparentFloor(0, + &extrasubsectors[num], + *rover->bottomheight, + *gr_frontsector->lightlist[light].lightlevel, + alpha, rover->master->frontsector, PF_Translucent|PF_NoTexture, + true, rover->master->frontsector->extra_colormap); + } + else if (rover->flags & FF_TRANSLUCENT) // SoM: Flags are more efficient + { + light = R_GetPlaneLight(gr_frontsector, *rover->bottomheight, dup_viewz < *rover->bottomheight ? true : false); +#ifndef SORTING + HWR_Add3DWater(levelflats[*rover->bottompic].lumpnum, + &extrasubsectors[num], + *rover->bottomheight, + *gr_frontsector->lightlist[light].lightlevel, + rover->alpha-1, rover->master->frontsector); +#else + HWR_AddTransparentFloor(levelflats[*rover->bottompic].lumpnum, + &extrasubsectors[num], + *rover->bottomheight, + *gr_frontsector->lightlist[light].lightlevel, + rover->alpha-1 > 255 ? 255 : rover->alpha-1, rover->master->frontsector, PF_Translucent, + false, gr_frontsector->lightlist[light].extra_colormap); +#endif + } + else + { + HWR_GetFlat(levelflats[*rover->bottompic].lumpnum); + light = R_GetPlaneLight(gr_frontsector, *rover->bottomheight, dup_viewz < *rover->bottomheight ? true : false); + HWR_RenderPlane(NULL, &extrasubsectors[num], *rover->bottomheight, PF_Occlude, *gr_frontsector->lightlist[light].lightlevel, levelflats[*rover->bottompic].lumpnum, + rover->master->frontsector, 255, false, gr_frontsector->lightlist[light].extra_colormap); + } + } + if (*rover->topheight >= gr_frontsector->floorheight && + *rover->topheight <= gr_frontsector->ceilingheight && + ((dup_viewz > *rover->topheight && !(rover->flags & FF_INVERTPLANES)) || + (dup_viewz < *rover->topheight && (rover->flags & FF_BOTHPLANES || rover->flags & FF_INVERTPLANES)))) + { + if (rover->flags & FF_FOG) + { + UINT8 alpha; + + light = R_GetPlaneLight(gr_frontsector, *rover->topheight, dup_viewz < *rover->topheight ? true : false); + + if (rover->master->frontsector->extra_colormap) + alpha = HWR_FogBlockAlpha(*gr_frontsector->lightlist[light].lightlevel, rover->master->frontsector->extra_colormap->rgba, rover->master->frontsector->extra_colormap->fadergba); + else + alpha = HWR_FogBlockAlpha(*gr_frontsector->lightlist[light].lightlevel, NORMALFOG, FADEFOG); + + HWR_AddTransparentFloor(0, + &extrasubsectors[num], + *rover->topheight, + *gr_frontsector->lightlist[light].lightlevel, + alpha, rover->master->frontsector, PF_Translucent|PF_NoTexture, + true, rover->master->frontsector->extra_colormap); + } + else if (rover->flags & FF_TRANSLUCENT) + { + light = R_GetPlaneLight(gr_frontsector, *rover->topheight, dup_viewz < *rover->topheight ? true : false); +#ifndef SORTING + HWR_Add3DWater(levelflats[*rover->toppic].lumpnum, + &extrasubsectors[num], + *rover->topheight, + *gr_frontsector->lightlist[light].lightlevel, + rover->alpha-1, rover->master->frontsector); +#else + HWR_AddTransparentFloor(levelflats[*rover->toppic].lumpnum, + &extrasubsectors[num], + *rover->topheight, + *gr_frontsector->lightlist[light].lightlevel, + rover->alpha-1 > 255 ? 255 : rover->alpha-1, rover->master->frontsector, PF_Translucent, + false, gr_frontsector->lightlist[light].extra_colormap); +#endif + + } + else + { + HWR_GetFlat(levelflats[*rover->toppic].lumpnum); + light = R_GetPlaneLight(gr_frontsector, *rover->topheight, dup_viewz < *rover->topheight ? true : false); + HWR_RenderPlane(NULL, &extrasubsectors[num], *rover->topheight, PF_Occlude, *gr_frontsector->lightlist[light].lightlevel, levelflats[*rover->toppic].lumpnum, + rover->master->frontsector, 255, false, gr_frontsector->lightlist[light].extra_colormap); + } + } + } + } +#endif +#endif //doplanes + +#ifdef POLYOBJECTS + // Draw all the polyobjects in this subsector + if (sub->polyList) + { + polyobj_t *po = sub->polyList; + + numpolys = 0; + + // Count all the polyobjects, reset the list, and recount them + while (po) + { + ++numpolys; + po = (polyobj_t *)(po->link.next); + } + + // Sort polyobjects + R_SortPolyObjects(sub); + + // Draw polyobject lines. + HWR_AddPolyObjectSegs(); + + // Draw polyobject planes + //HWR_AddPolyObjectPlanes(); + } +#endif + +// Hurder ici se passe les choses INT32�essantes! +// on vient de tracer le sol et le plafond +// on trace �pr�ent d'abord les sprites et ensuite les murs +// hurdler: faux: on ajoute seulement les sprites, le murs sont trac� d'abord + if (line) + { + // draw sprites first, coz they are clipped to the solidsegs of + // subsectors more 'in front' + HWR_AddSprites(gr_frontsector); + + //Hurdler: at this point validcount must be the same, but is not because + // gr_frontsector doesn't point anymore to sub->sector due to + // the call gr_frontsector = R_FakeFlat(...) + // if it's not done, the sprite is drawn more than once, + // what looks really bad with translucency or dynamic light, + // without talking about the overdraw of course. + sub->sector->validcount = validcount;/// \todo fix that in a better way + + while (count--) + { + HWR_AddLine(line); + line++; + } + } + +//20/08/99: Changed by Hurdler (taken from faB's code) +#ifdef DOPLANES + // -------------------- WATER IN DEV. TEST ------------------------ + //dck hack : use abs(tag) for waterheight + if (gr_frontsector->tag < 0) + { + wh = ((-gr_frontsector->tag) < gr_frontsector->floorheight && + wh < gr_frontsector->ceilingheight) + { + HWR_GetFlat(doomwaterflat); + HWR_RenderPlane(gr_frontsector, + &extrasubsectors[num], wh, PF_Translucent, + gr_frontsector->lightlevel, doomwaterflat, + NULL, 255, false, gr_frontsector->lightlist[light].extra_colormap); + } + } + // -------------------- WATER IN DEV. TEST ------------------------ +#endif + sub->validcount = validcount; +} + +// +// Renders all subsectors below a given node, +// traversing subtree recursively. +// Just call with BSP root. + +#ifdef coolhack +//t;b;l;r +static fixed_t hackbbox[4]; +//BOXTOP, +//BOXBOTTOM, +//BOXLEFT, +//BOXRIGHT +static boolean HWR_CheckHackBBox(fixed_t *bb) +{ + if (bb[BOXTOP] < hackbbox[BOXBOTTOM]) //y up + return false; + if (bb[BOXBOTTOM] > hackbbox[BOXTOP]) + return false; + if (bb[BOXLEFT] > hackbbox[BOXRIGHT]) + return false; + if (bb[BOXRIGHT] < hackbbox[BOXLEFT]) + return false; + return true; +} +#endif + +// BP: big hack for a test in lighning ref : 1249753487AB +fixed_t *hwbbox; + +static void HWR_RenderBSPNode(INT32 bspnum) +{ + /*//GZDoom code + if(bspnum == -1) + { + HWR_Subsector(subsectors); + return; + } + while(!((size_t)bspnum&(~NF_SUBSECTOR))) // Keep going until found a subsector + { + node_t *bsp = &nodes[bspnum]; + + // Decide which side the view point is on + INT32 side = R_PointOnSide(dup_viewx, dup_viewy, bsp); + + // Recursively divide front space (toward the viewer) + HWR_RenderBSPNode(bsp->children[side]); + + // Possibly divide back space (away from viewer) + side ^= 1; + + if (!HWR_CheckBBox(bsp->bbox[side])) + return; + + bspnum = bsp->children[side]; + } + + HWR_Subsector(bspnum-1); +*/ + node_t *bsp = &nodes[bspnum]; + + // Decide which side the view point is on + INT32 side; + + // Found a subsector? + if (bspnum & NF_SUBSECTOR) + { + if (bspnum == -1) + { + //*(gr_drawsubsector_p++) = 0; + HWR_Subsector(0); + } + else + { + //*(gr_drawsubsector_p++) = bspnum&(~NF_SUBSECTOR); + HWR_Subsector(bspnum&(~NF_SUBSECTOR)); + } + return; + } + + // Decide which side the view point is on. + side = R_PointOnSide(dup_viewx, dup_viewy, bsp); + + // BP: big hack for a test in lighning ref : 1249753487AB + hwbbox = bsp->bbox[side]; + + // Recursively divide front space. + HWR_RenderBSPNode(bsp->children[side]); + + // Possibly divide back space. + if (HWR_CheckBBox(bsp->bbox[side^1])) + { + // BP: big hack for a test in lighning ref : 1249753487AB + hwbbox = bsp->bbox[side^1]; + HWR_RenderBSPNode(bsp->children[side^1]); + } +} + +/* +// +// Clear 'stack' of subsectors to draw +// +static void HWR_ClearDrawSubsectors(void) +{ + gr_drawsubsector_p = gr_drawsubsectors; +} + +// +// Draw subsectors pushed on the drawsubsectors 'stack', back to front +// +static void HWR_RenderSubsectors(void) +{ + while (gr_drawsubsector_p > gr_drawsubsectors) + { + HWR_RenderBSPNode( + lastsubsec->nextsubsec = bspnum & (~NF_SUBSECTOR); + } +} +*/ + +// ========================================================================== +// FROM R_MAIN.C +// ========================================================================== + +//BP : exactely the same as R_InitTextureMapping +void HWR_InitTextureMapping(void) +{ + angle_t i; + INT32 x; + INT32 t; + fixed_t focallength; + fixed_t grcenterx; + fixed_t grcenterxfrac; + INT32 grviewwidth; + +#define clipanglefov (FIELDOFVIEW>>ANGLETOFINESHIFT) + + grviewwidth = vid.width; + grcenterx = grviewwidth/2; + grcenterxfrac = grcenterx< FRACUNIT*2) + t = -1; + else if (FINETANGENT(i) < -FRACUNIT*2) + t = grviewwidth+1; + else + { + t = FixedMul(FINETANGENT(i), focallength); + t = (grcenterxfrac - t+FRACUNIT-1)>>FRACBITS; + + if (t < -1) + t = -1; + else if (t > grviewwidth+1) + t = grviewwidth+1; + } + gr_viewangletox[i] = t; + } + + // Scan viewangletox[] to generate xtoviewangle[]: + // xtoviewangle will give the smallest view angle + // that maps to x. + for (x = 0; x <= grviewwidth; x++) + { + i = 0; + while (gr_viewangletox[i]>x) + i++; + gr_xtoviewangle[x] = (i<> VISSPRITECHUNKBITS] = {NULL}; + +// -------------------------------------------------------------------------- +// HWR_ClearSprites +// Called at frame start. +// -------------------------------------------------------------------------- +static void HWR_ClearSprites(void) +{ + gr_visspritecount = 0; +} + +static inline void HWR_ResetVisSpriteChunks(void) +{ + memset(gr_visspritechunks, 0, sizeof(gr_visspritechunks)); +} + + +// -------------------------------------------------------------------------- +// HWR_NewVisSprite +// -------------------------------------------------------------------------- +static gr_vissprite_t gr_overflowsprite; + +static gr_vissprite_t *HWR_GetVisSprite(UINT32 num) +{ + UINT32 chunk = num >> VISSPRITECHUNKBITS; + + // Allocate chunk if necessary + if (!gr_visspritechunks[chunk]) + Z_Malloc(sizeof(gr_vissprite_t) * VISSPRITESPERCHUNK, PU_LEVEL, &gr_visspritechunks[chunk]); + + return gr_visspritechunks[chunk] + (num & VISSPRITEINDEXMASK); +} + +static gr_vissprite_t *HWR_NewVisSprite(void) +{ + if (gr_visspritecount == MAXVISSPRITES) + return &gr_overflowsprite; + + return HWR_GetVisSprite(gr_visspritecount++); +} + +// Finds a floor through which light does not pass. +static fixed_t HWR_OpaqueFloorAtPos(fixed_t x, fixed_t y, fixed_t z, fixed_t height) +{ + const sector_t *sec = R_PointInSubsector(x, y)->sector; + fixed_t floorz = sec->floorheight; + + if (sec->ffloors) + { + ffloor_t *rover; + fixed_t delta1, delta2; + const fixed_t thingtop = z + height; + + for (rover = sec->ffloors; rover; rover = rover->next) + { + if (!(rover->flags & FF_EXISTS) + || !(rover->flags & FF_RENDERPLANES) + || rover->flags & FF_TRANSLUCENT + || rover->flags & FF_FOG + || rover->flags & FF_INVERTPLANES) + continue; + + delta1 = z - (*rover->bottomheight + ((*rover->topheight - *rover->bottomheight)/2)); + delta2 = thingtop - (*rover->bottomheight + ((*rover->topheight - *rover->bottomheight)/2)); + if (*rover->topheight > floorz && abs(delta1) < abs(delta2)) + floorz = *rover->topheight; + } + } + + return floorz; +} + +// -----------------+ +// HWR_DrawSprite : Draw flat sprites +// : (monsters, bonuses, weapons, lights, ...) +// Returns : +// -----------------+ +static void HWR_DrawSprite(gr_vissprite_t *spr) +{ + UINT8 i; + float tr_x, tr_y, this_scale = 1.0f; + FOutVector wallVerts[4]; + FOutVector *wv; + GLPatch_t *gpatch; // sprite patch converted to hardware + FSurfaceInfo Surf; + const boolean hires = (spr->mobj && spr->mobj->skin && ((skin_t *)spr->mobj->skin)->flags & SF_HIRES); + if (spr->mobj) + this_scale = FIXED_TO_FLOAT(spr->mobj->scale); + if (hires) + this_scale = this_scale * FIXED_TO_FLOAT(((skin_t *)spr->mobj->skin)->highresscale); + + if (!spr->mobj) + return; + + if (!spr->mobj->subsector) + return; + + // cache sprite graphics + //12/12/99: Hurdler: + // OK, I don't change anything for MD2 support because I want to be + // sure to do it the right way. So actually, we keep normal sprite + // in memory and we add the md2 model if it exists for that sprite + + gpatch = W_CachePatchNum(spr->patchlumpnum, PU_CACHE); + +#ifdef ALAM_LIGHTING + if (!(spr->mobj->flags2 & MF2_DEBRIS) && (spr->mobj->sprite != SPR_PLAY || + (spr->mobj->player && spr->mobj->player->powers[pw_super]))) + HWR_DL_AddLight(spr, gpatch); +#endif + + // create the sprite billboard + // + // 3--2 + // | /| + // |/ | + // 0--1 + + // these were already scaled in HWR_ProjectSprite + wallVerts[0].x = wallVerts[3].x = spr->x1; + wallVerts[2].x = wallVerts[1].x = spr->x2; + wallVerts[2].y = wallVerts[3].y = spr->ty; + if (spr->mobj && this_scale != 1.0f) + wallVerts[0].y = wallVerts[1].y = spr->ty - gpatch->height * this_scale; + else + wallVerts[0].y = wallVerts[1].y = spr->ty - gpatch->height; + + // make a wall polygon (with 2 triangles), using the floor/ceiling heights, + // and the 2d map coords of start/end vertices + wallVerts[0].z = wallVerts[1].z = wallVerts[2].z = wallVerts[3].z = spr->tz; + + // transform + wv = wallVerts; + + for (i = 0; i < 4; i++,wv++) + { + //look up/down ----TOTAL SUCKS!!!--- do the 2 in one!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + tr_x = wv->z; + tr_y = wv->y; + wv->y = (tr_x * gr_viewludcos) + (tr_y * gr_viewludsin); + wv->z = (tr_x * gr_viewludsin) - (tr_y * gr_viewludcos); + // ---------------------- mega lame test ---------------------------------- + + //scale y before frustum so that frustum can be scaled to screen height + wv->y *= ORIGINAL_ASPECT * gr_fovlud; + wv->x *= gr_fovlud; + } + + if (spr->flip) + { + wallVerts[0].sow = wallVerts[3].sow = gpatch->max_s; + wallVerts[2].sow = wallVerts[1].sow = 0; + }else{ + wallVerts[0].sow = wallVerts[3].sow = 0; + wallVerts[2].sow = wallVerts[1].sow = gpatch->max_s; + } + + // flip the texture coords (look familiar?) + if (spr->vflip) + { + wallVerts[3].tow = wallVerts[2].tow = gpatch->max_t; + wallVerts[0].tow = wallVerts[1].tow = 0; + }else{ + wallVerts[3].tow = wallVerts[2].tow = 0; + wallVerts[0].tow = wallVerts[1].tow = gpatch->max_t; + } + + // cache the patch in the graphics card memory + //12/12/99: Hurdler: same comment as above (for md2) + //Hurdler: 25/04/2000: now support colormap in hardware mode + HWR_GetMappedPatch(gpatch, spr->colormap); + + // Draw shadow BEFORE sprite + if (cv_shadow.value // Shadows enabled + && !(spr->mobj->flags & MF_SCENERY && spr->mobj->flags & MF_SPAWNCEILING && spr->mobj->flags & MF_NOGRAVITY) // Ceiling scenery have no shadow. + && !(spr->mobj->flags2 & MF2_DEBRIS) // Debris have no corona or shadow. +#ifdef ALAM_LIGHTING + && !(t_lspr[spr->mobj->sprite]->type // Things with dynamic lights have no shadow. + && (!spr->mobj->player || spr->mobj->player->powers[pw_super])) // Except for non-super players. +#endif + && (spr->mobj->z >= spr->mobj->floorz)) // Without this, your shadow shows on the floor, even after you die and fall through the ground. + { + //////////////////// + // SHADOW SPRITE! // + //////////////////// + FOutVector swallVerts[4]; + FSurfaceInfo sSurf; + fixed_t floorheight, mobjfloor; + + mobjfloor = HWR_OpaqueFloorAtPos( + spr->mobj->x, spr->mobj->y, + spr->mobj->z, spr->mobj->height); + if (cv_shadowoffs.value) + { + angle_t shadowdir; + + // Set direction + if (splitscreen && stplyr != &players[displayplayer]) + shadowdir = localangle2 + FixedAngle(cv_cam2_rotate.value); + else + shadowdir = localangle + FixedAngle(cv_cam_rotate.value); + + // Find floorheight + floorheight = HWR_OpaqueFloorAtPos( + spr->mobj->x + P_ReturnThrustX(spr->mobj, shadowdir, spr->mobj->z - mobjfloor), + spr->mobj->y + P_ReturnThrustY(spr->mobj, shadowdir, spr->mobj->z - mobjfloor), + spr->mobj->z, spr->mobj->height); + + // The shadow is falling ABOVE it's mobj? + // Don't draw it, then! + if (spr->mobj->z < floorheight) + goto noshadow; + else + { + fixed_t floorz; + floorz = HWR_OpaqueFloorAtPos( + spr->mobj->x + P_ReturnThrustX(spr->mobj, shadowdir, spr->mobj->z - floorheight), + spr->mobj->y + P_ReturnThrustY(spr->mobj, shadowdir, spr->mobj->z - floorheight), + spr->mobj->z, spr->mobj->height); + // The shadow would be falling on a wall? Don't draw it, then. + // Would draw midair otherwise. + if (floorz < floorheight) + goto noshadow; + } + + floorheight = FixedInt(spr->mobj->z - floorheight); + } + else + floorheight = FixedInt(spr->mobj->z - mobjfloor); + + // create the sprite billboard + // + // 3--2 + // | /| + // |/ | + // 0--1 + + // x1/x2 were already scaled in HWR_ProjectSprite + swallVerts[0].x = swallVerts[3].x = spr->x1; + swallVerts[2].x = swallVerts[1].x = spr->x2; + + if (spr->mobj && this_scale != 1.0f) + { + // Always a pixel above the floor, perfectly flat. + swallVerts[0].y = swallVerts[1].y = swallVerts[2].y = swallVerts[3].y = spr->ty - gpatch->topoffset * this_scale - (floorheight+3); + + swallVerts[0].z = swallVerts[1].z = spr->tz - (gpatch->height-gpatch->topoffset) * this_scale; + swallVerts[2].z = swallVerts[3].z = spr->tz + gpatch->topoffset * this_scale; + } + else + { + // Always a pixel above the floor, perfectly flat. + swallVerts[0].y = swallVerts[1].y = swallVerts[2].y = swallVerts[3].y = spr->ty - gpatch->topoffset - (floorheight+3); + + // Spread out top away from the camera. (Fixme: Make it always move out in the same direction!... somehow.) + swallVerts[0].z = swallVerts[1].z = spr->tz - (gpatch->height-gpatch->topoffset); + swallVerts[2].z = swallVerts[3].z = spr->tz + gpatch->topoffset; + } + + // transform + wv = swallVerts; + + for (i = 0; i < 4; i++,wv++) + { + // Offset away from the camera based on height from floor. + if (cv_shadowoffs.value) + wv->z += floorheight; + wv->z += 3; + + //look up/down ----TOTAL SUCKS!!!--- do the 2 in one!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + tr_x = wv->z; + tr_y = wv->y; + wv->y = (tr_x * gr_viewludcos) + (tr_y * gr_viewludsin); + wv->z = (tr_x * gr_viewludsin) - (tr_y * gr_viewludcos); + // ---------------------- mega lame test ---------------------------------- + + //scale y before frustum so that frustum can be scaled to screen height + wv->y *= ORIGINAL_ASPECT * gr_fovlud; + wv->x *= gr_fovlud; + } + + if (spr->flip) + { + swallVerts[0].sow = swallVerts[3].sow = gpatch->max_s; + swallVerts[2].sow = swallVerts[1].sow = 0; + } + else + { + swallVerts[0].sow = swallVerts[3].sow = 0; + swallVerts[2].sow = swallVerts[1].sow = gpatch->max_s; + } + + // flip the texture coords (look familiar?) + if (spr->vflip) + { + swallVerts[3].tow = swallVerts[2].tow = gpatch->max_t; + swallVerts[0].tow = swallVerts[1].tow = 0; + } + else + { + swallVerts[3].tow = swallVerts[2].tow = 0; + swallVerts[0].tow = swallVerts[1].tow = gpatch->max_t; + } + + sSurf.FlatColor.s.red = 0x00; + sSurf.FlatColor.s.blue = 0x00; + sSurf.FlatColor.s.green = 0x00; + + if (spr->mobj->frame & FF_TRANSMASK || spr->mobj->flags2 & MF2_SHADOW) + { + sector_t *sector = spr->mobj->subsector->sector; + UINT8 lightlevel = LightLevelToLum(sector->lightlevel); + extracolormap_t *colormap = sector->extra_colormap; + + if (sector->numlights) + { + INT32 light = R_GetPlaneLight(sector, spr->mobj->floorz, false); + + if (!(spr->mobj->frame & FF_FULLBRIGHT)) + lightlevel = LightLevelToLum(*sector->lightlist[light].lightlevel); + else + lightlevel = LightLevelToLum(255); + + if (sector->lightlist[light].extra_colormap) + colormap = sector->lightlist[light].extra_colormap; + } + else + { + lightlevel = LightLevelToLum(sector->lightlevel); + + if (sector->extra_colormap) + colormap = sector->extra_colormap; + } + + if (colormap) + sSurf.FlatColor.rgba = HWR_Lighting(lightlevel/2, colormap->rgba, colormap->fadergba, false, true); + else + sSurf.FlatColor.rgba = HWR_Lighting(lightlevel/2, NORMALFOG, FADEFOG, false, true); + } + Surf.FlatColor.rgba = NORMALFOG; + + /// \todo do the test earlier + if (!cv_grmd2.value || (md2_models[spr->mobj->sprite].scale < 0.0f) || (md2_models[spr->mobj->sprite].notfound = true) || (md2_playermodels[(skin_t*)spr->mobj->skin-skins].scale < 0.0f) || (md2_playermodels[(skin_t*)spr->mobj->skin-skins].notfound = true)) + { + if (0x80 > floorheight/4) + { + sSurf.FlatColor.s.alpha = (UINT8)(0x80 - floorheight/4); + HWD.pfnDrawPolygon(&sSurf, swallVerts, 4, PF_Translucent|PF_Modulated|PF_Clip); + } + } + } + +noshadow: + + // This needs to be AFTER the shadows so that the regular sprites aren't drawn completely black. + // sprite lighting by modulating the RGB components + /// \todo coloured + + // colormap test + { + sector_t *sector = spr->mobj->subsector->sector; + UINT8 lightlevel = LightLevelToLum(sector->lightlevel); + extracolormap_t *colormap = sector->extra_colormap; + + if (sector->numlights) + { + INT32 light = R_GetPlaneLight(sector, spr->mobj->z, false); + + if ((sector->lightlist[light].height > (spr->mobj->z + spr->mobj->height)) && !(sector->lightlist[light].flags & FF_NOSHADE)) + { + if (!(spr->mobj->frame & FF_FULLBRIGHT)) + lightlevel = LightLevelToLum(*sector->lightlist[light].lightlevel); + else + lightlevel = LightLevelToLum(255); + + if (sector->lightlist[light].extra_colormap) + colormap = sector->lightlist[light].extra_colormap; + } + else // If we can't use the light at its bottom, we'll use the light at its top + { + light = R_GetPlaneLight(sector, spr->mobj->z + spr->mobj->height, false); + + if (!(spr->mobj->frame & FF_FULLBRIGHT)) + lightlevel = LightLevelToLum(*sector->lightlist[light].lightlevel); + else + lightlevel = LightLevelToLum(255); + + if (sector->lightlist[light].extra_colormap) + colormap = sector->lightlist[light].extra_colormap; + } + } + else + { + if (!(spr->mobj->frame & FF_FULLBRIGHT)) + lightlevel = LightLevelToLum(sector->lightlevel); + else + lightlevel = LightLevelToLum(255); + + if (sector->extra_colormap) + colormap = sector->extra_colormap; + } + + if (spr->mobj->frame & FF_FULLBRIGHT) + lightlevel = LightLevelToLum(255); + + if (colormap) + Surf.FlatColor.rgba = HWR_Lighting(lightlevel, colormap->rgba, colormap->fadergba, false, false); + else + Surf.FlatColor.rgba = HWR_Lighting(lightlevel, NORMALFOG, FADEFOG, false, false); + } + + /// \todo do the test earlier + if (!cv_grmd2.value || (md2_models[spr->mobj->sprite].scale < 0.0f)) + { + FBITFIELD blend = 0; + if (spr->mobj->flags2 & MF2_SHADOW) + { + Surf.FlatColor.s.alpha = 0x40; + blend = PF_Translucent; + } + else if (spr->mobj->frame & FF_TRANSMASK) + blend = HWR_TranstableToAlpha((spr->mobj->frame & FF_TRANSMASK)>>FF_TRANSSHIFT, &Surf); + else + { + // BP: i agree that is little better in environement but it don't + // work properly under glide nor with fogcolor to ffffff :( + // Hurdler: PF_Environement would be cool, but we need to fix + // the issue with the fog before + Surf.FlatColor.s.alpha = 0xFF; + blend = PF_Translucent|PF_Occlude; + } + + HWD.pfnDrawPolygon(&Surf, wallVerts, 4, blend|PF_Modulated|PF_Clip); + } +} + +#ifdef HWPRECIP +// Sprite drawer for precipitation +static inline void HWR_DrawPrecipitationSprite(gr_vissprite_t *spr) +{ + UINT8 i; + FBITFIELD blend = 0; + float tr_x, tr_y; + FOutVector wallVerts[4]; + FOutVector *wv; + GLPatch_t *gpatch; // sprite patch converted to hardware + FSurfaceInfo Surf; + sector_t *sector; + + if (!spr->mobj) + return; + + if (!spr->mobj->subsector) + return; + + // cache sprite graphics + gpatch = W_CachePatchNum(spr->patchlumpnum, PU_CACHE); + + // create the sprite billboard + // + // 3--2 + // | /| + // |/ | + // 0--1 + wallVerts[0].x = wallVerts[3].x = spr->x1; + wallVerts[2].x = wallVerts[1].x = spr->x2; + wallVerts[2].y = wallVerts[3].y = spr->ty; + wallVerts[0].y = wallVerts[1].y = spr->ty - gpatch->height; + + // make a wall polygon (with 2 triangles), using the floor/ceiling heights, + // and the 2d map coords of start/end vertices + wallVerts[0].z = wallVerts[1].z = wallVerts[2].z = wallVerts[3].z = spr->tz; + + // transform + wv = wallVerts; + + for (i = 0; i < 4; i++, wv++) + { + //look up/down ----TOTAL SUCKS!!!--- do the 2 in one!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + tr_x = wv->z; + tr_y = wv->y; + wv->y = (tr_x * gr_viewludcos) + (tr_y * gr_viewludsin); + wv->z = (tr_x * gr_viewludsin) - (tr_y * gr_viewludcos); + // ---------------------- mega lame test ---------------------------------- + + //scale y before frustum so that frustum can be scaled to screen height + wv->y *= ORIGINAL_ASPECT * gr_fovlud; + wv->x *= gr_fovlud; + } + + wallVerts[0].sow = wallVerts[3].sow = 0; + wallVerts[2].sow = wallVerts[1].sow = gpatch->max_s; + + wallVerts[3].tow = wallVerts[2].tow = 0; + wallVerts[0].tow = wallVerts[1].tow = gpatch->max_t; + + // cache the patch in the graphics card memory + //12/12/99: Hurdler: same comment as above (for md2) + //Hurdler: 25/04/2000: now support colormap in hardware mode + HWR_GetMappedPatch(gpatch, spr->colormap); + + sector = spr->mobj->subsector->sector; + + if (sector->ffloors) + { + ffloor_t *caster = sector->lightlist[R_GetPlaneLight(sector, spr->mobj->z, false)].caster; + sector = caster ? §ors[caster->secnum] : sector; + } + + // sprite lighting by modulating the RGB components + if (sector->extra_colormap) + Surf.FlatColor.rgba = HWR_Lighting(spr->sectorlight,sector->extra_colormap->rgba,sector->extra_colormap->fadergba, false, false); + else + Surf.FlatColor.rgba = HWR_Lighting(spr->sectorlight,NORMALFOG,FADEFOG, false, false); + + if (spr->mobj->flags2 & MF2_SHADOW) + { + Surf.FlatColor.s.alpha = 0x40; + blend = PF_Translucent; + } + else if (spr->mobj->frame & FF_TRANSMASK) + blend = HWR_TranstableToAlpha((spr->mobj->frame & FF_TRANSMASK)>>FF_TRANSSHIFT, &Surf); + else + { + // BP: i agree that is little better in environement but it don't + // work properly under glide nor with fogcolor to ffffff :( + // Hurdler: PF_Environement would be cool, but we need to fix + // the issue with the fog before + Surf.FlatColor.s.alpha = 0xFF; + blend = PF_Translucent|PF_Occlude; + } + + HWD.pfnDrawPolygon(&Surf, wallVerts, 4, blend|PF_Modulated|PF_Clip); +} +#endif + +// -------------------------------------------------------------------------- +// Sort vissprites by distance +// -------------------------------------------------------------------------- +static gr_vissprite_t gr_vsprsortedhead; + +static void HWR_SortVisSprites(void) +{ + UINT32 i; + gr_vissprite_t *ds, *dsprev, *dsnext, *dsfirst; + gr_vissprite_t *best = NULL; + gr_vissprite_t unsorted; + float bestdist; + + if (!gr_visspritecount) + return; + + dsfirst = HWR_GetVisSprite(0); + + for (i = 0, dsnext = dsfirst, ds = NULL; i < gr_visspritecount; i++) + { + dsprev = ds; + ds = dsnext; + if (i < gr_visspritecount - 1) dsnext = HWR_GetVisSprite(i + 1); + + ds->next = dsnext; + ds->prev = dsprev; + } + + // Fix first and last. ds still points to the last one after the loop + dsfirst->prev = &unsorted; + unsorted.next = dsfirst; + ds->next = &unsorted; + unsorted.prev = ds; + + // pull the vissprites out by scale + gr_vsprsortedhead.next = gr_vsprsortedhead.prev = &gr_vsprsortedhead; + for (i = 0; i < gr_visspritecount; i++) + { + bestdist = ZCLIP_PLANE-1; + for (ds = unsorted.next; ds != &unsorted; ds = ds->next) + { + if (ds->tz > bestdist) + { + bestdist = ds->tz; + best = ds; + } + } + best->next->prev = best->prev; + best->prev->next = best->next; + best->next = &gr_vsprsortedhead; + best->prev = gr_vsprsortedhead.prev; + gr_vsprsortedhead.prev->next = best; + gr_vsprsortedhead.prev = best; + } +} + +// A drawnode is something that points to a 3D floor, 3D side, or masked +// middle texture. This is used for sorting with sprites. +typedef struct +{ + wallVert3D wallVerts[4]; + FSurfaceInfo Surf; + INT32 texnum; + FBITFIELD blend; + INT32 drawcount; +#ifndef SORTING + fixed_t fixedheight; +#endif + boolean fogwall; + INT32 lightlevel; + extracolormap_t *wallcolormap; // Doing the lighting in HWR_RenderWall now for correct fog after sorting +} wallinfo_t; + +static wallinfo_t *wallinfo = NULL; +static size_t numwalls = 0; // a list of transparent walls to be drawn + +static void HWR_RenderWall(wallVert3D *wallVerts, FSurfaceInfo *pSurf, FBITFIELD blend, boolean fogwall, INT32 lightlevel, extracolormap_t *wallcolormap); + +#define MAX_TRANSPARENTWALL 256 + +typedef struct +{ + extrasubsector_t *xsub; + fixed_t fixedheight; + INT32 lightlevel; + lumpnum_t lumpnum; + INT32 alpha; + sector_t *FOFSector; + FBITFIELD blend; + boolean fogplane; + extracolormap_t *planecolormap; + INT32 drawcount; +} planeinfo_t; + +static size_t numplanes = 0; // a list of transparent floors to be drawn +static planeinfo_t *planeinfo = NULL; + +#ifndef SORTING +size_t numfloors = 0; +#else +//static floorinfo_t *floorinfo = NULL; +//static size_t numfloors = 0; +//Hurdler: 3D water sutffs +typedef struct gr_drawnode_s +{ + planeinfo_t *plane; + wallinfo_t *wall; + gr_vissprite_t *sprite; + +// struct gr_drawnode_s *next; +// struct gr_drawnode_s *prev; +} gr_drawnode_t; + +static INT32 drawcount = 0; + +#define MAX_TRANSPARENTFLOOR 512 + +// This will likely turn into a copy of HWR_Add3DWater and replace it. +void HWR_AddTransparentFloor(lumpnum_t lumpnum, extrasubsector_t *xsub, + fixed_t fixedheight, INT32 lightlevel, INT32 alpha, sector_t *FOFSector, FBITFIELD blend, boolean fogplane, extracolormap_t *planecolormap) +{ + static size_t allocedplanes = 0; + + // Force realloc if buffer has been freed + if (!planeinfo) + allocedplanes = 0; + + if (allocedplanes < numplanes + 1) + { + allocedplanes += MAX_TRANSPARENTFLOOR; + Z_Realloc(planeinfo, allocedplanes * sizeof (*planeinfo), PU_LEVEL, &planeinfo); + } + + planeinfo[numplanes].fixedheight = fixedheight; + planeinfo[numplanes].lightlevel = lightlevel; + planeinfo[numplanes].lumpnum = lumpnum; + planeinfo[numplanes].xsub = xsub; + planeinfo[numplanes].alpha = alpha; + planeinfo[numplanes].FOFSector = FOFSector; + planeinfo[numplanes].blend = blend; + planeinfo[numplanes].fogplane = fogplane; + planeinfo[numplanes].planecolormap = planecolormap; + planeinfo[numplanes].drawcount = drawcount++; + numplanes++; +} + +// +// HWR_CreateDrawNodes +// Creates and sorts a list of drawnodes for the scene being rendered. +static void HWR_CreateDrawNodes(void) +{ + UINT32 i = 0, p = 0, prev = 0, loop; + const fixed_t pviewz = dup_viewz; + + // Dump EVERYTHING into a huge drawnode list. Then we'll sort it! + // Could this be optimized into _AddTransparentWall/_AddTransparentPlane? + // Hell yes! But sort algorithm must be modified to use a linked list. + gr_drawnode_t *sortnode = Z_Calloc((sizeof(planeinfo_t)*numplanes) + + (sizeof(wallinfo_t)*numwalls) + ,PU_STATIC, NULL); + // todo: + // However, in reality we shouldn't be re-copying and shifting all this information + // that is already lying around. This should all be in some sort of linked list or lists. + size_t *sortindex = Z_Calloc(sizeof(size_t) * (numplanes + numwalls), PU_STATIC, NULL); + + // If true, swap the draw order. + boolean shift = false; + + for (i = 0; i < numplanes; i++, p++) + { + sortnode[p].plane = &planeinfo[i]; + sortindex[p] = p; + } + + for (i = 0; i < numwalls; i++, p++) + { + sortnode[p].wall = &wallinfo[i]; + sortindex[p] = p; + } + + // p is the number of stuff to sort + + // Add the 3D floors, thicksides, and masked textures... + // Instead of going through drawsegs, we need to iterate + // through the lists of masked textures and + // translucent ffloors being drawn. + + // This is a bubble sort! Wahoo! + + // Stuff is sorted: + // sortnode[sortindex[0]] = farthest away + // sortnode[sortindex[p-1]] = closest + // "i" should be closer. "prev" should be further. + // The lower drawcount is, the further it is from the screen. + + for (loop = 0; loop < p; loop++) + { + for (i = 1; i < p; i++) + { + prev = i-1; + if (sortnode[sortindex[i]].plane) + { + // What are we comparing it with? + if (sortnode[sortindex[prev]].plane) + { + // Plane (i) is further away than plane (prev) + if (ABS(sortnode[sortindex[i]].plane->fixedheight - pviewz) > ABS(sortnode[sortindex[prev]].plane->fixedheight - pviewz)) + shift = true; + } + else if (sortnode[sortindex[prev]].wall) + { + // Plane (i) is further than wall (prev) + if (sortnode[sortindex[i]].plane->drawcount > sortnode[sortindex[prev]].wall->drawcount) + shift = true; + } + } + else if (sortnode[sortindex[i]].wall) + { + // What are we comparing it with? + if (sortnode[sortindex[prev]].plane) + { + // Wall (i) is further than plane(prev) + if (sortnode[sortindex[i]].wall->drawcount > sortnode[sortindex[prev]].plane->drawcount) + shift = true; + } + else if (sortnode[sortindex[prev]].wall) + { + // Wall (i) is further than wall (prev) + if (sortnode[sortindex[i]].wall->drawcount > sortnode[sortindex[prev]].wall->drawcount) + shift = true; + } + } + + if (shift) + { + size_t temp; + + temp = sortindex[prev]; + sortindex[prev] = sortindex[i]; + sortindex[i] = temp; + + shift = false; + } + + } //i++ + } // loop++ + + HWD.pfnSetTransform(&atransform); + // Okay! Let's draw it all! Woo! + for (i = 0; i < p; i++) + { + if (sortnode[sortindex[i]].plane) + { + // We aren't traversing the BSP tree, so make gr_frontsector null to avoid crashes. + gr_frontsector = NULL; + + if (!(sortnode[sortindex[i]].plane->blend & PF_NoTexture)) + HWR_GetFlat(sortnode[sortindex[i]].plane->lumpnum); + HWR_RenderPlane(NULL, sortnode[sortindex[i]].plane->xsub, sortnode[sortindex[i]].plane->fixedheight, sortnode[sortindex[i]].plane->blend, sortnode[sortindex[i]].plane->lightlevel, + sortnode[sortindex[i]].plane->lumpnum, sortnode[sortindex[i]].plane->FOFSector, sortnode[sortindex[i]].plane->alpha, sortnode[sortindex[i]].plane->fogplane, sortnode[sortindex[i]].plane->planecolormap); + } + else if (sortnode[sortindex[i]].wall) + { + if (!(sortnode[sortindex[i]].wall->blend & PF_NoTexture)) + HWR_GetTexture(sortnode[sortindex[i]].wall->texnum); + HWR_RenderWall(sortnode[sortindex[i]].wall->wallVerts, &sortnode[sortindex[i]].wall->Surf, sortnode[sortindex[i]].wall->blend, sortnode[sortindex[i]].wall->fogwall, + sortnode[sortindex[i]].wall->lightlevel, sortnode[sortindex[i]].wall->wallcolormap); + } + } + + numwalls = 0; + numplanes = 0; + + // No mem leaks, please. + Z_Free(sortnode); + Z_Free(sortindex); +} + +#endif + +// -------------------------------------------------------------------------- +// Draw all vissprites +// -------------------------------------------------------------------------- +#ifdef SORTING +static void HWR_DrawSprites(void) +{ + if (gr_visspritecount > 0) + { + gr_vissprite_t *spr; + + // draw all vissprites back to front + for (spr = gr_vsprsortedhead.next; + spr != &gr_vsprsortedhead; + spr = spr->next) + { +#ifdef HWPRECIP + if (spr->precip) + HWR_DrawPrecipitationSprite(spr); + else +#endif + if (spr->mobj->skin) + { + if (!cv_grmd2.value || (cv_grmd2.value && md2_playermodels[(skin_t*)spr->mobj->skin-skins].notfound == true)) + HWR_DrawSprite(spr); + } + else if (!cv_grmd2.value || (cv_grmd2.value && md2_models[spr->mobj->sprite].notfound == true)) + HWR_DrawSprite(spr); + } + } +} +#endif +// -------------------------------------------------------------------------- +// Draw all MD2 +// -------------------------------------------------------------------------- +static void HWR_DrawMD2S(void) +{ + if (gr_visspritecount > 0) + { + gr_vissprite_t *spr; + + // draw all MD2 back to front + for (spr = gr_vsprsortedhead.next; + spr != &gr_vsprsortedhead; + spr = spr->next) + { +#ifdef HWPRECIP + if (!spr->precip) + { +#endif + if (spr->mobj && spr->mobj->skin) + { + if ((md2_playermodels[(skin_t*)spr->mobj->skin-skins].notfound == false) && (md2_playermodels[(skin_t*)spr->mobj->skin-skins].scale > 0.0f)) + HWR_DrawMD2(spr); + } + else if (md2_models[spr->mobj->sprite].notfound == false && md2_models[spr->mobj->sprite].scale > 0.0f) + HWR_DrawMD2(spr); +#ifdef HWPRECIP + } +#endif + } + } +} + +// -------------------------------------------------------------------------- +// HWR_AddSprites +// During BSP traversal, this adds sprites by sector. +// -------------------------------------------------------------------------- +static UINT8 sectorlight; +static void HWR_AddSprites(sector_t *sec) +{ + mobj_t *thing; +#ifdef HWPRECIP + precipmobj_t *precipthing; +#endif + fixed_t approx_dist, limit_dist; + + // BSP is traversed by subsector. + // A sector might have been split into several + // subsectors during BSP building. + // Thus we check whether its already added. + if (sec->validcount == validcount) + return; + + // Well, now it will be done. + sec->validcount = validcount; + + // sprite lighting + sectorlight = LightLevelToLum(sec->lightlevel & 0xff); + + // Handle all things in sector. + // If a limit exists, handle things a tiny bit different. + if ((limit_dist = (fixed_t)((maptol & TOL_NIGHTS) ? cv_drawdist_nights.value : cv_drawdist.value) << FRACBITS)) + { + if (!players[displayplayer].mo) + return; // Draw nothing if no player. + // todo: is this really the best option for this situation? + + for (thing = sec->thinglist; thing; thing = thing->snext) + { + if (thing->sprite == SPR_NULL || thing->flags2 & MF2_DONTDRAW) + continue; + + approx_dist = P_AproxDistance( + players[displayplayer].mo->x - thing->x, + players[displayplayer].mo->y - thing->y); + + if (splitscreen && approx_dist > limit_dist && players[secondarydisplayplayer].mo) + approx_dist = P_AproxDistance( + players[secondarydisplayplayer].mo->x - thing->x, + players[secondarydisplayplayer].mo->y - thing->y); + + if (approx_dist <= limit_dist) + HWR_ProjectSprite(thing); + } + } + else + { + // Draw everything in sector, no checks + for (thing = sec->thinglist; thing; thing = thing->snext) + if (!(thing->sprite == SPR_NULL || thing->flags2 & MF2_DONTDRAW)) + HWR_ProjectSprite(thing); + } + +#ifdef HWPRECIP + // Someone seriously wants infinite draw distance for precipitation? + if ((limit_dist = (fixed_t)cv_drawdist_precip.value << FRACBITS)) + { + if (!players[displayplayer].mo) + return; // Draw nothing if no player. + // todo: is this really the best option for this situation? + + for (precipthing = sec->preciplist; precipthing; precipthing = precipthing->snext) + { + if (precipthing->invisible) + continue; + + approx_dist = P_AproxDistance( + players[displayplayer].mo->x - precipthing->x, + players[displayplayer].mo->y - precipthing->y); + + if (splitscreen && approx_dist > limit_dist && players[secondarydisplayplayer].mo) + approx_dist = P_AproxDistance( + players[secondarydisplayplayer].mo->x - precipthing->x, + players[secondarydisplayplayer].mo->y - precipthing->y); + + if (approx_dist <= limit_dist) + HWR_ProjectPrecipitationSprite(precipthing); + } + } + else + { + // Draw everything in sector, no checks + for (precipthing = sec->preciplist; precipthing; precipthing = precipthing->snext) + if (!precipthing->invisible) + HWR_ProjectPrecipitationSprite(precipthing); + } +#endif +} + +// -------------------------------------------------------------------------- +// HWR_ProjectSprite +// Generates a vissprite for a thing if it might be visible. +// -------------------------------------------------------------------------- +// BP why not use xtoviexangle/viewangletox like in bsp ?.... +static void HWR_ProjectSprite(mobj_t *thing) +{ + gr_vissprite_t *vis; + float tr_x, tr_y; + float tx, tz; + float x1, x2; + float this_scale; + float gz, gzt; + spritedef_t *sprdef; + spriteframe_t *sprframe; + size_t lumpoff; + unsigned rot; + UINT8 flip; + angle_t ang; + INT32 heightsec, phs; + + if (!thing) + return; + else + this_scale = FIXED_TO_FLOAT(thing->scale); + + // transform the origin point + tr_x = FIXED_TO_FLOAT(thing->x) - gr_viewx; + tr_y = FIXED_TO_FLOAT(thing->y) - gr_viewy; + + // rotation around vertical axis + tz = (tr_x * gr_viewcos) + (tr_y * gr_viewsin); + + // thing is behind view plane? + if (tz < ZCLIP_PLANE) + return; + + tx = (tr_x * gr_viewsin) - (tr_y * gr_viewcos); + + // decide which patch to use for sprite relative to player +#ifdef RANGECHECK + if ((unsigned)thing->sprite >= numsprites) + I_Error("HWR_ProjectSprite: invalid sprite number %i ", thing->sprite); +#endif + + rot = thing->frame&FF_FRAMEMASK; + + //Fab : 02-08-98: 'skin' override spritedef currently used for skin + if (thing->skin && thing->sprite == SPR_PLAY) + sprdef = &((skin_t *)thing->skin)->spritedef; + else + sprdef = &sprites[thing->sprite]; + + if (rot >= sprdef->numframes) + { + CONS_Alert(CONS_ERROR, M_GetText("R_ProjectSprite: invalid sprite frame %s/%s for %s\n"), + sizeu1(rot), sizeu2(sprdef->numframes), sprnames[thing->sprite]); + thing->sprite = states[S_UNKNOWN].sprite; + thing->frame = states[S_UNKNOWN].frame; + rot = thing->frame&FF_FRAMEMASK; + thing->state->sprite = thing->sprite; + thing->state->frame = thing->frame; + } + + sprframe = &sprdef->spriteframes[rot]; + +#ifdef PARANOIA + if (!sprframe) + I_Error("sprframes NULL for sprite %d\n", thing->sprite); +#endif + + if (sprframe->rotate) + { + // choose a different rotation based on player view + ang = R_PointToAngle(thing->x, thing->y); // uses viewx,viewy + rot = (ang-thing->angle+ANGLE_202h)>>29; + //Fab: lumpid is the index for spritewidth,spriteoffset... tables + lumpoff = sprframe->lumpid[rot]; + flip = sprframe->flip & (1<patch below + lumpoff = sprframe->lumpid[0]; //Fab: see note above + flip = sprframe->flip; // Will only be 0x00 or 0xFF + } + + if (thing->skin && ((skin_t *)thing->skin)->flags & SF_HIRES) + this_scale = this_scale * FIXED_TO_FLOAT(((skin_t *)thing->skin)->highresscale); + + // calculate edges of the shape + if (flip) + tx -= FIXED_TO_FLOAT(spritecachedinfo[lumpoff].width - spritecachedinfo[lumpoff].offset) * this_scale; + else + tx -= FIXED_TO_FLOAT(spritecachedinfo[lumpoff].offset) * this_scale; + + // project x + x1 = gr_windowcenterx + (tx * gr_centerx / tz); + + //faB : tr_x doesnt matter + // hurdler: it's used in cliptosolidsegs + tr_x = x1; + + x1 = tx; + + tx += FIXED_TO_FLOAT(spritecachedinfo[lumpoff].width) * this_scale; + x2 = gr_windowcenterx + (tx * gr_centerx / tz); + + if (thing->eflags & MFE_VERTICALFLIP) + { + gz = FIXED_TO_FLOAT(thing->z+thing->height) - FIXED_TO_FLOAT(spritecachedinfo[lumpoff].topoffset) * this_scale; + gzt = gz + FIXED_TO_FLOAT(spritecachedinfo[lumpoff].height) * this_scale; + } + else + { + gzt = FIXED_TO_FLOAT(thing->z) + FIXED_TO_FLOAT(spritecachedinfo[lumpoff].topoffset) * this_scale; + gz = gzt - FIXED_TO_FLOAT(spritecachedinfo[lumpoff].height) * this_scale; + } + + if (thing->subsector->sector->cullheight) + { + float cullplane = FIXED_TO_FLOAT(thing->subsector->sector->cullheight->frontsector->floorheight); + if (thing->subsector->sector->cullheight->flags & ML_NOCLIMB) // Group culling + { + // Make sure this is part of the same group + if (viewsector->cullheight && viewsector->cullheight->frontsector + == thing->subsector->sector->cullheight->frontsector) + { + // OK, we can cull + if (gr_viewz > cullplane && gzt < cullplane) // Cull if below plane + return; + + if (gz > cullplane && gr_viewz <= cullplane) // Cull if above plane + return; + } + } + else // Quick culling + { + if (gr_viewz > cullplane && gzt < cullplane) // Cull if below plane + return; + + if (gz > cullplane && gr_viewz <= cullplane) // Cull if above plane + return; + } + } + + heightsec = thing->subsector->sector->heightsec; + phs = players[displayplayer].mo->subsector->sector->heightsec; + + if (heightsec != -1 && phs != -1) // only clip things which are in special sectors + { + if (gr_viewz < FIXED_TO_FLOAT(sectors[phs].floorheight) ? + FIXED_TO_FLOAT(thing->z) >= FIXED_TO_FLOAT(sectors[heightsec].floorheight) : + gzt < FIXED_TO_FLOAT(sectors[heightsec].floorheight)) + return; + if (gr_viewz > FIXED_TO_FLOAT(sectors[phs].ceilingheight) ? + gzt < FIXED_TO_FLOAT(sectors[heightsec].ceilingheight) && gr_viewz >= FIXED_TO_FLOAT(sectors[heightsec].ceilingheight) : + FIXED_TO_FLOAT(thing->z) >= FIXED_TO_FLOAT(sectors[heightsec].ceilingheight)) + return; + } + + // store information in a vissprite + vis = HWR_NewVisSprite(); + vis->x1 = x1; +#if 0 + vis->x2 = x2; +#else + (void)x2; +#endif + vis->x2 = tx; + vis->tz = tz; + vis->patchlumpnum = sprframe->lumppat[rot]; + vis->flip = flip; + vis->mobj = thing; + + //Hurdler: 25/04/2000: now support colormap in hardware mode + if ((vis->mobj->flags & MF_BOSS) && (vis->mobj->flags2 & MF2_FRET) && (leveltime & 1)) // Bosses "flash" + { + if (vis->mobj->type == MT_CYBRAKDEMON) + vis->colormap = R_GetTranslationColormap(TC_ALLWHITE, 0, GTC_CACHE); + else if (vis->mobj->type == MT_METALSONIC_BATTLE) + vis->colormap = R_GetTranslationColormap(TC_METALSONIC, 0, GTC_CACHE); + else + vis->colormap = R_GetTranslationColormap(TC_BOSS, 0, GTC_CACHE); + } + else if (thing->color) + { + // New colormap stuff for skins Tails 06-07-2002 + if (thing->skin && thing->sprite == SPR_PLAY) // This thing is a player! + { + size_t skinnum = (skin_t*)thing->skin-skins; + vis->colormap = R_GetTranslationColormap((INT32)skinnum, thing->color, GTC_CACHE); + } + else + vis->colormap = R_GetTranslationColormap(TC_DEFAULT, vis->mobj->color ? vis->mobj->color : SKINCOLOR_CYAN, GTC_CACHE); + } + else + vis->colormap = colormaps; + + // set top/bottom coords + vis->ty = gzt - gr_viewz; + + //CONS_Debug(DBG_RENDER, "------------------\nH: sprite : %d\nH: frame : %x\nH: type : %d\nH: sname : %s\n\n", + // thing->sprite, thing->frame, thing->type, sprnames[thing->sprite]); + + if (thing->eflags & MFE_VERTICALFLIP) + vis->vflip = true; + else + vis->vflip = false; + + vis->precip = false; +} + +#ifdef HWPRECIP +// Precipitation projector for hardware mode +static void HWR_ProjectPrecipitationSprite(precipmobj_t *thing) +{ + gr_vissprite_t *vis; + float tr_x, tr_y; + float tx, tz; + float x1, x2; + spritedef_t *sprdef; + spriteframe_t *sprframe; + size_t lumpoff; + unsigned rot = 0; + UINT8 flip; + + // transform the origin point + tr_x = FIXED_TO_FLOAT(thing->x) - gr_viewx; + tr_y = FIXED_TO_FLOAT(thing->y) - gr_viewy; + + // rotation around vertical axis + tz = (tr_x * gr_viewcos) + (tr_y * gr_viewsin); + + // thing is behind view plane? + if (tz < ZCLIP_PLANE) + return; + + tx = (tr_x * gr_viewsin) - (tr_y * gr_viewcos); + + // decide which patch to use for sprite relative to player + if ((unsigned)thing->sprite >= numsprites) +#ifdef RANGECHECK + I_Error("HWR_ProjectPrecipitationSprite: invalid sprite number %i ", + thing->sprite); +#else + return; +#endif + + sprdef = &sprites[thing->sprite]; + + if ((size_t)(thing->frame&FF_FRAMEMASK) >= sprdef->numframes) +#ifdef RANGECHECK + I_Error("HWR_ProjectPrecipitationSprite: invalid sprite frame %i : %i for %s", + thing->sprite, thing->frame, sprnames[thing->sprite]); +#else + return; +#endif + + sprframe = &sprdef->spriteframes[ thing->frame & FF_FRAMEMASK]; + + // use single rotation for all views + lumpoff = sprframe->lumpid[0]; + flip = sprframe->flip; // Will only be 0x00 or 0xFF + + // calculate edges of the shape + tx -= FIXED_TO_FLOAT(spritecachedinfo[lumpoff].offset); + + // project x + x1 = gr_windowcenterx + (tx * gr_centerx / tz); + + //faB : tr_x doesnt matter + // hurdler: it's used in cliptosolidsegs + tr_x = x1; + + x1 = tx; + + tx += FIXED_TO_FLOAT(spritecachedinfo[lumpoff].width); + x2 = gr_windowcenterx + (tx * gr_centerx / tz); + + // + // store information in a vissprite + // + vis = HWR_NewVisSprite(); + vis->x1 = x1; + vis->x2 = tx; + vis->tz = tz; + vis->patchlumpnum = sprframe->lumppat[rot]; + vis->flip = flip; + vis->mobj = (mobj_t *)thing; + + vis->colormap = colormaps; + + // set top/bottom coords + vis->ty = FIXED_TO_FLOAT(thing->z + spritecachedinfo[lumpoff].topoffset) - gr_viewz; + + vis->sectorlight = 0xff; + vis->precip = true; +} +#endif + +// ========================================================================== +// +// ========================================================================== +static void HWR_DrawSkyBackground(player_t *player) +{ + FOutVector v[4]; + angle_t angle; + float f; + +// 3--2 +// | /| +// |/ | +// 0--1 + + (void)player; + HWR_GetTexture(skytexture); + + //Hurdler: the sky is the only texture who need 4.0f instead of 1.0 + // because it's called just after clearing the screen + // and thus, the near clipping plane is set to 3.99 + v[0].x = v[3].x = -4.0f; + v[1].x = v[2].x = 4.0f; + v[0].y = v[1].y = -4.0f; + v[2].y = v[3].y = 4.0f; + + v[0].z = v[1].z = v[2].z = v[3].z = 4.0f; + + if (textures[skytexture]->width > 256) + angle = (angle_t)((float)(dup_viewangle + gr_xtoviewangle[0]) + /((float)textures[skytexture]->width/256.0f)) + %(ANGLE_90-1); + else + angle = (dup_viewangle + gr_xtoviewangle[0])%(ANGLE_90-1); + + f = (float)((textures[skytexture]->width/2) + * FIXED_TO_FLOAT(FINETANGENT((2048 + - ((INT32)angle>>(ANGLETOFINESHIFT + 1))) & FINEMASK))); + + v[0].sow = v[3].sow = 0.22f+(f)/(textures[skytexture]->width/2); + v[2].sow = v[1].sow = 0.22f+(f+(127))/(textures[skytexture]->width/2); + + f = (float)((textures[skytexture]->height/2) + * FIXED_TO_FLOAT(FINETANGENT((2048 + - ((INT32)aimingangle>>(ANGLETOFINESHIFT + 1))) & FINEMASK))); + + v[3].tow = v[2].tow = 0.22f+(f)/(textures[skytexture]->height/2); + v[0].tow = v[1].tow = 0.22f+(f+(127))/(textures[skytexture]->height/2); + + HWD.pfnDrawPolygon(NULL, v, 4, 0); +} + + +// -----------------+ +// HWR_ClearView : clear the viewwindow, with maximum z value +// -----------------+ +static inline void HWR_ClearView(void) +{ + // 3--2 + // | /| + // |/ | + // 0--1 + + /// \bug faB - enable depth mask, disable color mask + + HWD.pfnGClipRect((INT32)gr_viewwindowx, + (INT32)gr_viewwindowy, + (INT32)(gr_viewwindowx + gr_viewwidth), + (INT32)(gr_viewwindowy + gr_viewheight), + 3.99f); + HWD.pfnClearBuffer(false, true, 0); + + //disable clip window - set to full size + // rem by Hurdler + // HWD.pfnGClipRect(0, 0, vid.width, vid.height); +} + + +// -----------------+ +// HWR_SetViewSize : set projection and scaling values +// -----------------+ +void HWR_SetViewSize(void) +{ + // setup view size + gr_viewwidth = (float)vid.width; + gr_viewheight = (float)vid.height; + + if (splitscreen) + gr_viewheight /= 2; + + gr_centerx = gr_viewwidth / 2; + gr_basecentery = gr_viewheight / 2; //note: this is (gr_centerx * gr_viewheight / gr_viewwidth) + + gr_viewwindowx = (vid.width - gr_viewwidth) / 2; + gr_windowcenterx = (float)(vid.width / 2); + if (gr_viewwidth == vid.width) + { + gr_baseviewwindowy = 0; + gr_basewindowcentery = gr_viewheight / 2; // window top left corner at 0,0 + } + else + { + gr_baseviewwindowy = (vid.height-gr_viewheight) / 2; + gr_basewindowcentery = (float)(vid.height / 2); + } + + gr_pspritexscale = gr_viewwidth / BASEVIDWIDTH; + gr_pspriteyscale = ((vid.height*gr_pspritexscale*BASEVIDWIDTH)/BASEVIDHEIGHT)/vid.width; +} + +// ========================================================================== +// +// ========================================================================== +void HWR_RenderPlayerView(INT32 viewnumber, player_t *player) +{ + const float fpov = FIXED_TO_FLOAT(cv_grfov.value+player->fovadd); + FTransform stransform; + + { + // do we really need to save player (is it not the same)? + player_t *saved_player = stplyr; + stplyr = player; + ST_doPaletteStuff(); + stplyr = saved_player; +#ifdef ALAM_LIGHTING + HWR_SetLights(viewnumber); +#endif + } + + // note: sets viewangle, viewx, viewy, viewz + R_SetupFrame(player, false); + + // copy view cam position for local use + dup_viewx = viewx; + dup_viewy = viewy; + dup_viewz = viewz; + dup_viewangle = viewangle; + + // set window position + gr_centery = gr_basecentery; + gr_viewwindowy = gr_baseviewwindowy; + gr_windowcentery = gr_basewindowcentery; + if (splitscreen && viewnumber == 1) + { + gr_viewwindowy += (vid.height/2); + gr_windowcentery += (vid.height/2); + } + + // check for new console commands. + NetUpdate(); + + gr_viewx = FIXED_TO_FLOAT(dup_viewx); + gr_viewy = FIXED_TO_FLOAT(dup_viewy); + gr_viewz = FIXED_TO_FLOAT(dup_viewz); + gr_viewsin = FIXED_TO_FLOAT(viewsin); + gr_viewcos = FIXED_TO_FLOAT(viewcos); + + gr_viewludsin = FIXED_TO_FLOAT(FINECOSINE(aimingangle>>ANGLETOFINESHIFT)); + gr_viewludcos = FIXED_TO_FLOAT(-FINESINE(aimingangle>>ANGLETOFINESHIFT)); + + //04/01/2000: Hurdler: added for T&L + // It should replace all other gr_viewxxx when finished + atransform.anglex = (float)(aimingangle>>ANGLETOFINESHIFT)*(360.0f/(float)FINEANGLES); + atransform.angley = (float)(viewangle>>ANGLETOFINESHIFT)*(360.0f/(float)FINEANGLES); + atransform.x = gr_viewx; // FIXED_TO_FLOAT(viewx) + atransform.y = gr_viewy; // FIXED_TO_FLOAT(viewy) + atransform.z = gr_viewz; // FIXED_TO_FLOAT(viewz) + atransform.scalex = 1; + atransform.scaley = ORIGINAL_ASPECT; + atransform.scalez = 1; + atransform.fovxangle = fpov; // Tails + atransform.fovyangle = fpov; // Tails + atransform.splitscreen = splitscreen; + + // Transform for sprites + stransform.anglex = 0.0f; + stransform.angley = -270.0f; + stransform.x = 0.0f; + stransform.y = 0.0f; + stransform.z = 0.0f; + stransform.scalex = 1; + stransform.scaley = 1; + stransform.scalez = 1; + stransform.fovxangle = 90.0f; + stransform.fovyangle = 90.0f; + stransform.splitscreen = splitscreen; + + gr_fovlud = (float)(1.0l/tan((double)(fpov*M_PIl/360l))); + + //------------------------------------------------------------------------ + HWR_ClearView(); + +if (0) +{ // I don't think this is ever used. + if (cv_grfog.value) + HWR_FoggingOn(); // First of all, turn it on, set the default user settings too + else + HWD.pfnSetSpecialState(HWD_SET_FOG_MODE, 0); // Turn it off +} + +#ifndef _NDS + if (drawsky) + HWR_DrawSkyBackground(player); +#else + (void)HWR_DrawSkyBackground; +#endif + + //Hurdler: it doesn't work in splitscreen mode + drawsky = splitscreen; + + HWR_ClearSprites(); + +#ifdef SORTING + drawcount = 0; +#endif + HWR_ClearClipSegs(); + + //04/01/2000: Hurdler: added for T&L + // Actually it only works on Walls and Planes + HWD.pfnSetTransform(&atransform); + + validcount++; + + HWR_RenderBSPNode((INT32)numnodes-1); + + // Make a viewangle int so we can render things based on mouselook + if (player == &players[consoleplayer]) + viewangle = localaiming; + else if (splitscreen && player == &players[secondarydisplayplayer]) + viewangle = localaiming2; + + // Handle stuff when you are looking farther up or down. + if ((aimingangle || cv_grfov.value+player->fovadd > 90*FRACUNIT)) + { + dup_viewangle += ANGLE_90; + HWR_ClearClipSegs(); + HWR_RenderBSPNode((INT32)numnodes-1); //left + + dup_viewangle += ANGLE_90; + if (((INT32)aimingangle > ANGLE_45 || (INT32)aimingangle<-ANGLE_45)) + { + HWR_ClearClipSegs(); + HWR_RenderBSPNode((INT32)numnodes-1); //back + } + + dup_viewangle += ANGLE_90; + HWR_ClearClipSegs(); + HWR_RenderBSPNode((INT32)numnodes-1); //right + + dup_viewangle += ANGLE_90; + } + + // Check for new console commands. + NetUpdate(); + +#ifdef ALAM_LIGHTING + //14/11/99: Hurdler: moved here because it doesn't work with + // subsector, see other comments; + HWR_ResetLights(); +#endif + + // Draw MD2 and sprites +#ifdef SORTING + HWR_SortVisSprites(); +#endif + HWR_DrawMD2S(); + + // Draw the sprites with trivial transform + HWD.pfnSetTransform(&stransform); +#ifdef SORTING + HWR_DrawSprites(); +#endif +#ifdef NEWCORONAS + //Hurdler: they must be drawn before translucent planes, what about gl fog? + HWR_DrawCoronas(); +#endif + +#ifdef SORTING + if (numplanes || numwalls) //Hurdler: render 3D water and transparent walls after everything + { + HWR_CreateDrawNodes(); + } +#else + if (numfloors || numwalls) + { + HWD.pfnSetTransform(&atransform); + if (numfloors) + HWR_Render3DWater(); + if (numwalls) + HWR_RenderTransparentWalls(); + } +#endif + + HWD.pfnSetTransform(NULL); + + // put it off for menus etc + if (cv_grfog.value) + HWD.pfnSetSpecialState(HWD_SET_FOG_MODE, 0); + + HWR_DoPostProcessor(player); + + // Check for new console commands. + NetUpdate(); + + // added by Hurdler for correct splitscreen + // moved here by hurdler so it works with the new near clipping plane + HWD.pfnGClipRect(0, 0, vid.width, vid.height, NZCLIP_PLANE); +} + +// ========================================================================== +// FOG +// ========================================================================== + +/// \author faB + +static UINT32 atohex(const char *s) +{ + INT32 iCol; + const char *sCol; + char cCol; + INT32 i; + + if (strlen(s)<6) + return 0; + + iCol = 0; + sCol = s; + for (i = 0; i < 6; i++, sCol++) + { + iCol <<= 4; + cCol = *sCol; + if (cCol >= '0' && cCol <= '9') + iCol |= cCol - '0'; + else + { + if (cCol >= 'F') + cCol -= 'a' - 'A'; + if (cCol >= 'A' && cCol <= 'F') + iCol = iCol | (cCol - 'A' + 10); + } + } + //CONS_Debug(DBG_RENDER, "col %x\n", iCol); + return iCol; +} + +static void HWR_FoggingOn(void) +{ + HWD.pfnSetSpecialState(HWD_SET_FOG_COLOR, atohex(cv_grfogcolor.string)); + HWD.pfnSetSpecialState(HWD_SET_FOG_DENSITY, cv_grfogdensity.value); + HWD.pfnSetSpecialState(HWD_SET_FOG_MODE, 1); +} + +// ========================================================================== +// 3D ENGINE COMMANDS +// ========================================================================== + + +static void CV_grFov_OnChange(void) +{ + if ((netgame || multiplayer) && !cv_debug && cv_grfov.value != 90*FRACUNIT) + CV_Set(&cv_grfov, cv_grfov.defaultvalue); +} + +static void Command_GrStats_f(void) +{ + Z_CheckHeap(9875); // debug + + CONS_Printf(M_GetText("Patch info headers: %7s kb\n"), sizeu1(Z_TagUsage(PU_HWRPATCHINFO)>>10)); + CONS_Printf(M_GetText("3D Texture cache : %7s kb\n"), sizeu1(Z_TagUsage(PU_HWRCACHE)>>10)); + CONS_Printf(M_GetText("Plane polygon : %7s kb\n"), sizeu1(Z_TagUsage(PU_HWRPLANE)>>10)); +} + + +// ************************************************************************** +// 3D ENGINE SETUP +// ************************************************************************** + +// -------------------------------------------------------------------------- +// Add hardware engine commands & consvars +// -------------------------------------------------------------------------- +//added by Hurdler: console varibale that are saved +void HWR_AddCommands(void) +{ + CV_RegisterVar(&cv_grmd2); + CV_RegisterVar(&cv_grrounddown); + CV_RegisterVar(&cv_grfov); + CV_RegisterVar(&cv_grfogdensity); + CV_RegisterVar(&cv_grfiltermode); + CV_RegisterVar(&cv_granisotropicmode); + CV_RegisterVar(&cv_grcorrecttricks); + CV_RegisterVar(&cv_grsolvetjoin); +} + +static inline void HWR_AddEngineCommands(void) +{ + // engine state variables + //CV_RegisterVar(&cv_grzbuffer); + CV_RegisterVar(&cv_grclipwalls); + + // engine development mode variables + // - usage may vary from version to version.. + CV_RegisterVar(&cv_gralpha); + CV_RegisterVar(&cv_grbeta); + + // engine commands + COM_AddCommand("gr_stats", Command_GrStats_f); +} + + +// -------------------------------------------------------------------------- +// Setup the hardware renderer +// -------------------------------------------------------------------------- +void HWR_Startup(void) +{ + static boolean startupdone = false; + + // setup GLPatch_t scaling + gr_patch_scalex = (float)(1.0f / vid.width); + gr_patch_scaley = (float)(1.0f / vid.height); + + // initalze light lut translation + InitLumLut(); + + // do this once + if (!startupdone) + { + CONS_Printf("HWR_Startup()\n"); + HWR_InitPolyPool(); + // add console cmds & vars + HWR_AddEngineCommands(); + HWR_InitTextureCache(); + + // for test water translucent surface + doomwaterflat = W_CheckNumForName("FWATER1"); + if (doomwaterflat == LUMPERROR) // if FWATER1 not found (in doom shareware) + doomwaterflat = W_GetNumForName("WATER0"); + + HWR_InitMD2(); + +#ifdef ALAM_LIGHTING + HWR_InitLight(); +#endif + } + + if (rendermode == render_opengl) + textureformat = patchformat = +#ifdef _NDS + GR_TEXFMT_P_8; +#else + GR_RGBA; +#endif + + startupdone = true; +} + + +// -------------------------------------------------------------------------- +// Free resources allocated by the hardware renderer +// -------------------------------------------------------------------------- +void HWR_Shutdown(void) +{ + CONS_Printf("HWR_Shutdown()\n"); + HWR_FreeExtraSubsectors(); + HWR_FreePolyPool(); + HWR_FreeTextureCache(); +} + +void transform(float *cx, float *cy, float *cz) +{ + float tr_x,tr_y; + // translation + tr_x = *cx - gr_viewx; + tr_y = *cz - gr_viewy; +// *cy = *cy; + + // rotation around vertical y axis + *cx = (tr_x * gr_viewsin) - (tr_y * gr_viewcos); + tr_x = (tr_x * gr_viewcos) + (tr_y * gr_viewsin); + + //look up/down ----TOTAL SUCKS!!!--- do the 2 in one!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + tr_y = *cy - gr_viewz; + + *cy = (tr_x * gr_viewludcos) + (tr_y * gr_viewludsin); + *cz = (tr_x * gr_viewludsin) - (tr_y * gr_viewludcos); + + //scale y before frustum so that frustum can be scaled to screen height + *cy *= ORIGINAL_ASPECT * gr_fovlud; + *cx *= gr_fovlud; +} + + +//Hurdler: 3D Water stuff +#define MAX_3DWATER 512 + +#ifndef SORTING +static void HWR_Add3DWater(lumpnum_t lumpnum, extrasubsector_t *xsub, + fixed_t fixedheight, INT32 lightlevel, INT32 alpha, sector_t *FOFSector) +{ + static size_t allocedplanes = 0; + + // Force realloc if buffer has been freed + if (!planeinfo) + allocedplanes = 0; + + if (allocedplanes < numfloors + 1) + { + allocedplanes += MAX_3DWATER; + Z_Realloc(planeinfo, allocedplanes * sizeof (*planeinfo), PU_LEVEL, &planeinfo); + } + planeinfo[numfloors].fixedheight = fixedheight; + planeinfo[numfloors].lightlevel = lightlevel; + planeinfo[numfloors].lumpnum = lumpnum; + planeinfo[numfloors].xsub = xsub; + planeinfo[numfloors].alpha = alpha; + planeinfo[numfloors].FOFSector = FOFSector; + numfloors++; +} +#endif + +#define DIST_PLANE(i) ABS(planeinfo[(i)].fixedheight-dup_viewz) + +#if 0 +static void HWR_QuickSortPlane(INT32 start, INT32 finish) +{ + INT32 left = start; + INT32 right = finish; + INT32 starterval = (INT32)((right+left)/2); //pick a starter + + planeinfo_t temp; + + //'sort of sort' the two halves of the data list about starterval + while (right > left); + { + while (DIST_PLANE(left) < DIST_PLANE(starterval)) left++; //attempt to find a bigger value on the left + while (DIST_PLANE(right) > DIST_PLANE(starterval)) right--; //attempt to find a smaller value on the right + + if (left < right) //if we haven't gone too far + { + //switch them + M_Memcpy(&temp, &planeinfo[left], sizeof (planeinfo_t)); + M_Memcpy(&planeinfo[left], &planeinfo[right], sizeof (planeinfo_t)); + M_Memcpy(&planeinfo[right], &temp, sizeof (planeinfo_t)); + //move the bounds + left++; + right--; + } + } + + if (start < right) HWR_QuickSortPlane(start, right); + if (left < finish) HWR_QuickSortPlane(left, finish); +} +#endif + +#ifndef SORTING +static void HWR_Render3DWater(void) +{ + size_t i; + + //bubble sort 3D Water for correct alpha blending + { + boolean permut = true; + while (permut) + { + size_t j; + for (j = 0, permut= false; j < numfloors-1; j++) + { + if (ABS(planeinfo[j].fixedheight-dup_viewz) < ABS(planeinfo[j+1].fixedheight-dup_viewz)) + { + planeinfo_t temp; + M_Memcpy(&temp, &planeinfo[j+1], sizeof (planeinfo_t)); + M_Memcpy(&planeinfo[j+1], &planeinfo[j], sizeof (planeinfo_t)); + M_Memcpy(&planeinfo[j], &temp, sizeof (planeinfo_t)); + permut = true; + } + } + } + } +#if 0 //thanks epat, but it's goes looping forever on CTF map Silver Cascade Zone + HWR_QuickSortPlane(0, numplanes-1); +#endif + + gr_frontsector = NULL; //Hurdler: gr_fronsector is no longer valid + for (i = 0; i < numfloors; i++) + { + HWR_GetFlat(planeinfo[i].lumpnum); + HWR_RenderPlane(NULL, planeinfo[i].xsub, planeinfo[i].fixedheight, PF_Translucent, planeinfo[i].lightlevel, planeinfo[i].lumpnum, + planeinfo[i].FOFSector, planeinfo[i].alpha, planeinfo[i].fogplane, planeinfo[i].planecolormap); + } + numfloors = 0; +} +#endif + +static void HWR_AddTransparentWall(wallVert3D *wallVerts, FSurfaceInfo *pSurf, INT32 texnum, FBITFIELD blend, boolean fogwall, INT32 lightlevel, extracolormap_t *wallcolormap) +{ + static size_t allocedwalls = 0; + + // Force realloc if buffer has been freed + if (!wallinfo) + allocedwalls = 0; + + if (allocedwalls < numwalls + 1) + { + allocedwalls += MAX_TRANSPARENTWALL; + Z_Realloc(wallinfo, allocedwalls * sizeof (*wallinfo), PU_LEVEL, &wallinfo); + } + + M_Memcpy(wallinfo[numwalls].wallVerts, wallVerts, sizeof (wallinfo[numwalls].wallVerts)); + M_Memcpy(&wallinfo[numwalls].Surf, pSurf, sizeof (FSurfaceInfo)); + wallinfo[numwalls].texnum = texnum; + wallinfo[numwalls].blend = blend; +#ifdef SORTING + wallinfo[numwalls].drawcount = drawcount++; +#endif + wallinfo[numwalls].fogwall = fogwall; + wallinfo[numwalls].lightlevel = lightlevel; + wallinfo[numwalls].wallcolormap = wallcolormap; + numwalls++; +} +#ifndef SORTING +static void HWR_RenderTransparentWalls(void) +{ + size_t i; + + /*{ // sorting is disbale for now, do it! + INT32 permut = 1; + while (permut) + { + INT32 j; + for (j = 0, permut = 0; j < numwalls-1; j++) + { + if (ABS(wallinfo[j].fixedheight-dup_viewz) < ABS(wallinfo[j+1].fixedheight-dup_viewz)) + { + wallinfo_t temp; + M_Memcpy(&temp, &wallinfo[j+1], sizeof (wallinfo_t)); + M_Memcpy(&wallinfo[j+1], &wallinfo[j], sizeof (wallinfo_t)); + M_Memcpy(&wallinfo[j], &temp, sizeof (wallinfo_t)); + permut = 1; + } + } + } + }*/ + + for (i = 0; i < numwalls; i++) + { + HWR_GetTexture(wallinfo[i].texnum); + HWR_RenderWall(wallinfo[i].wallVerts, &wallinfo[i].Surf, wallinfo[i].blend, wallinfo[i].wall->fogwall, wallinfo[i].wall->lightlevel, wallinfo[i].wall->wallcolormap); + } + numwalls = 0; +} +#endif +static void HWR_RenderWall(wallVert3D *wallVerts, FSurfaceInfo *pSurf, FBITFIELD blend, boolean fogwall, INT32 lightlevel, extracolormap_t *wallcolormap) +{ + FOutVector trVerts[4]; + UINT8 i; + FOutVector *wv; + UINT8 alpha; + + // transform + wv = trVerts; + // it sounds really stupid to do this conversion with the new T&L code + // we should directly put the right information in the right structure + // wallVerts3D seems ok, doesn't need FOutVector + // also remove the light copy + for (i = 0; i < 4; i++, wv++, wallVerts++) + { + wv->sow = wallVerts->s; + wv->tow = wallVerts->t; + wv->x = wallVerts->x; + wv->y = wallVerts->y; + wv->z = wallVerts->z; + } + + alpha = pSurf->FlatColor.s.alpha; // retain the alpha + + // Lighting is done here instead so that fog isn't drawn incorrectly on transparent walls after sorting + if (wallcolormap) + { + if (fogwall) + pSurf->FlatColor.rgba = HWR_Lighting(LightLevelToLum(lightlevel), wallcolormap->rgba, wallcolormap->fadergba, true, false); + else + pSurf->FlatColor.rgba = HWR_Lighting(LightLevelToLum(lightlevel), wallcolormap->rgba, wallcolormap->fadergba, false, false); + } + else + { + if (fogwall) + pSurf->FlatColor.rgba = HWR_Lighting(LightLevelToLum(lightlevel), NORMALFOG, FADEFOG, true, false); + else + pSurf->FlatColor.rgba = HWR_Lighting(LightLevelToLum(lightlevel), NORMALFOG, FADEFOG, false, false); + } + + pSurf->FlatColor.s.alpha = alpha; // put the alpha back after lighting + + if (blend & PF_Environment) + HWD.pfnDrawPolygon(pSurf, trVerts, 4, blend|PF_Modulated|PF_Clip|PF_Occlude); // PF_Occlude must be used for solid objects + else + HWD.pfnDrawPolygon(pSurf, trVerts, 4, blend|PF_Modulated|PF_Clip); // No PF_Occlude means overlapping (incorrect) transparency + +#ifdef WALLSPLATS + if (gr_curline->linedef->splats && cv_splats.value) + HWR_DrawSegsSplats(pSurf); + +#ifdef ALAM_LIGHTING + //Hurdler: TODO: do static lighting using gr_curline->lm + HWR_WallLighting(trVerts); +#endif +#endif +} + +void HWR_SetPaletteColor(INT32 palcolor) +{ + HWD.pfnSetSpecialState(HWD_SET_PALETTECOLOR, palcolor); +} + +INT32 HWR_GetTextureUsed(void) +{ + return HWD.pfnGetTextureUsed(); +} + +void HWR_DoPostProcessor(player_t *player) +{ + // Armageddon Blast Flash! + // Could this even be considered postprocessor? + if (player->flashcount) + { + FOutVector v[4]; + FSurfaceInfo Surf; + + v[0].x = v[2].y = v[3].x = v[3].y = -1.0f; + v[0].y = v[1].x = v[1].y = v[2].x = 1.0f; + v[0].z = v[1].z = v[2].z = v[3].z = 1.0f; + + Surf.FlatColor.s.red = Surf.FlatColor.s.green = Surf.FlatColor.s.blue = 0xff; + Surf.FlatColor.s.alpha = 0xc0; // match software mode + + HWD.pfnDrawPolygon(&Surf, v, 4, PF_Modulated|PF_Additive|PF_NoTexture|PF_NoDepthTest|PF_Clip|PF_NoZClip); + } + + // Capture the screen for intermission and screen waving + if(gamestate != GS_INTERMISSION) + HWD.pfnMakeScreenTexture(); + + if (splitscreen) // Not supported in splitscreen - someone want to add support? + return; + +#ifdef SHUFFLE + // Drunken vision! WooOOooo~ + if (postimgtype == postimg_water || postimgtype == postimg_heat) + { + // 10 by 10 grid. 2 coordinates (xy) + float v[SCREENVERTS][SCREENVERTS][2]; + static double disStart = 0; + UINT8 x, y; + INT32 WAVELENGTH; + INT32 AMPLITUDE; + INT32 FREQUENCY; + + // Modifies the wave. + if (postimgtype == postimg_water) + { + WAVELENGTH = 20; // Lower is longer + AMPLITUDE = 20; // Lower is bigger + FREQUENCY = 16; // Lower is faster + } + else + { + WAVELENGTH = 10; // Lower is longer + AMPLITUDE = 30; // Lower is bigger + FREQUENCY = 4; // Lower is faster + } + + for (x = 0; x < SCREENVERTS; x++) + { + for (y = 0; y < SCREENVERTS; y++) + { + // Change X position based on its Y position. + v[x][y][0] = (x/((float)(SCREENVERTS-1.0f)/9.0f))-4.5f + (float)sin((disStart+(y*WAVELENGTH))/FREQUENCY)/AMPLITUDE; + v[x][y][1] = (y/((float)(SCREENVERTS-1.0f)/9.0f))-4.5f; + } + } + HWD.pfnPostImgRedraw(v); + disStart += 1; + } + else if (postimgtype == postimg_flip) //We like our screens inverted. + { + // 10 by 10 grid. 2 coordinates (xy) + float v[SCREENVERTS][SCREENVERTS][2]; + UINT8 x, y; + UINT8 flipy; + + for (x = 0; x < SCREENVERTS; x++) + { + for (y = 0, flipy = SCREENVERTS; y < SCREENVERTS; y++, flipy--) + { + // Flip the screen. + v[x][y][0] = (x/((float)(SCREENVERTS-1.0f)/9.0f))-4.5f; + v[x][y][1] = (flipy/((float)(SCREENVERTS-1.0f)/9.0f))-5.5f; + } + } + HWD.pfnPostImgRedraw(v); + } +#endif // SHUFFLE +} + +void HWR_StartScreenWipe(void) +{ + //CONS_Debug(DBG_RENDER, "In HWR_StartScreenWipe()\n"); + HWD.pfnStartScreenWipe(); +} + +void HWR_EndScreenWipe(void) +{ + HWRWipeCounter = 1.0f; + //CONS_Debug(DBG_RENDER, "In HWR_EndScreenWipe()\n"); + HWD.pfnEndScreenWipe(); +} + +// Prepare the screen for fading to black. +void HWR_PrepFadeToBlack(void) +{ + FOutVector v[4]; + INT32 flags; + FSurfaceInfo Surf; + + v[0].x = v[2].y = v[3].x = v[3].y = -1.0f; + v[0].y = v[1].x = v[1].y = v[2].x = 1.0f; + v[0].z = v[1].z = v[2].z = v[3].z = 1.0f; + + flags = PF_Modulated | PF_Clip | PF_NoZClip | PF_NoDepthTest | PF_NoTexture; + Surf.FlatColor.s.red = Surf.FlatColor.s.green = Surf.FlatColor.s.blue = 0x00; + Surf.FlatColor.s.alpha = 0xff; + + HWD.pfnDrawPolygon(&Surf, v, 4, flags); +} + +void HWR_DrawIntermissionBG(void) +{ + HWD.pfnDrawIntermissionBG(); +} + +void HWR_DoScreenWipe(void) +{ + HWRWipeCounter -= 0.035f; + + //CONS_Debug(DBG_RENDER, "In HWR_DoScreenWipe(). Alpha =%f\n", HWRWipeCounter); + + HWD.pfnDoScreenWipe(HWRWipeCounter); + + I_OsPolling(); + I_FinishUpdate(); +} + +#endif // HWRENDER diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h new file mode 100644 index 000000000..d3b3df667 --- /dev/null +++ b/src/hardware/hw_main.h @@ -0,0 +1,114 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright (C) 1998-2000 by DooM Legacy Team. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +//----------------------------------------------------------------------------- +/// \file +/// \brief 3D render mode functions + +#ifndef __HWR_MAIN_H__ +#define __HWR_MAIN_H__ + +#include "hw_data.h" +#include "hw_defs.h" + +#include "../am_map.h" +#include "../d_player.h" +#include "../r_defs.h" + +// Startup & Shutdown the hardware mode renderer +void HWR_Startup(void); +void HWR_Shutdown(void); + +void HWR_clearAutomap(void); +void HWR_drawAMline(const fline_t *fl, INT32 color); +void HWR_FadeScreenMenuBack(UINT32 color, INT32 height); +void HWR_DrawConsoleBack(UINT32 color, INT32 height); +void HWR_RenderPlayerView(INT32 viewnumber, player_t *player); +void HWR_DrawViewBorder(INT32 clearlines); +void HWR_DrawFlatFill(INT32 x, INT32 y, INT32 w, INT32 h, lumpnum_t flatlumpnum); +UINT8 *HWR_GetScreenshot(void); +boolean HWR_Screenshot(const char *lbmname); +void HWR_InitTextureMapping(void); +void HWR_SetViewSize(void); +void HWR_DrawPatch(GLPatch_t *gpatch, INT32 x, INT32 y, INT32 option); +void HWR_DrawClippedPatch(GLPatch_t *gpatch, INT32 x, INT32 y, INT32 option); +void HWR_DrawSciencePatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, INT32 option, fixed_t scale); +void HWR_DrawTranslucentPatch(GLPatch_t *gpatch, INT32 x, INT32 y, INT32 option); +void HWR_DrawSmallPatch(GLPatch_t *gpatch, INT32 x, INT32 y, INT32 option, const UINT8 *colormap); +void HWR_DrawMappedPatch(GLPatch_t *gpatch, INT32 x, INT32 y, INT32 option, const UINT8 *colormap); +void HWR_MakePatch (const patch_t *patch, GLPatch_t *grPatch, GLMipmap_t *grMipmap, boolean makebitmap); +void HWR_CreatePlanePolygons(INT32 bspnum); +void HWR_CreateStaticLightmaps(INT32 bspnum); +void HWR_PrepLevelCache(size_t pnumtextures); +void HWR_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 color); +void HWR_DrawPic(INT32 x,INT32 y,lumpnum_t lumpnum); + +void HWR_AddCommands(void); +void HWR_CorrectSWTricks(void); +void transform(float *cx, float *cy, float *cz); +FBITFIELD HWR_TranstableToAlpha(INT32 transtablenum, FSurfaceInfo *pSurf); +void HWR_SetPaletteColor(INT32 palcolor); +INT32 HWR_GetTextureUsed(void); +void HWR_DoPostProcessor(player_t *player); +void HWR_StartScreenWipe(void); +void HWR_EndScreenWipe(void); +void HWR_DoScreenWipe(void); +void HWR_PrepFadeToBlack(void); +void HWR_DrawIntermissionBG(void); + +// This stuff is put here so MD2's can use them +UINT32 HWR_Lighting(INT32 light, UINT32 color, UINT32 fadecolor, boolean fogblockpoly, boolean plane); +FUNCMATH UINT8 LightLevelToLum(INT32 l); + +extern CV_PossibleValue_t granisotropicmode_cons_t[]; + +extern consvar_t cv_grdynamiclighting; +extern consvar_t cv_grstaticlighting; +extern consvar_t cv_grcoronas; +extern consvar_t cv_grcoronasize; +extern consvar_t cv_grfov; +extern consvar_t cv_grmd2; +extern consvar_t cv_grfog; +extern consvar_t cv_grfogcolor; +extern consvar_t cv_grfogdensity; +extern consvar_t cv_grsoftwarefog; +extern consvar_t cv_grgammared; +extern consvar_t cv_grgammagreen; +extern consvar_t cv_grgammablue; +extern consvar_t cv_grfiltermode; +extern consvar_t cv_granisotropicmode; +extern consvar_t cv_grcorrecttricks; +extern consvar_t cv_voodoocompatibility; +extern consvar_t cv_grfovchange; +extern consvar_t cv_grsolvetjoin; + +extern float gr_viewwidth, gr_viewheight, gr_baseviewwindowy; + +extern float gr_viewwindowx, gr_basewindowcentery; + +// BP: big hack for a test in lighting ref : 1249753487AB +extern fixed_t *hwbbox; +extern FTransform atransform; + +typedef struct +{ + wallVert3D floorVerts[4]; + FSurfaceInfo Surf; + INT32 texnum; + INT32 blend; + INT32 drawcount; +} floorinfo_t; + +#endif diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c new file mode 100644 index 000000000..fb012535c --- /dev/null +++ b/src/hardware/hw_md2.c @@ -0,0 +1,1263 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright (C) 1998-2000 by DooM Legacy Team. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +//----------------------------------------------------------------------------- +/// \file +/// \brief MD2 Handling +/// Inspired from md2.c by Mete Ciragan (mete@swissquake.ch) + + +#ifdef __GNUC__ +#include +#endif +#include +#include +#include +#include + +#include "../doomdef.h" +#include "../doomstat.h" + +#ifdef HWRENDER +#include "hw_drv.h" +#include "hw_light.h" +#include "hw_md2.h" +#include "../r_bsp.h" +#include "../r_main.h" +#include "../m_misc.h" +#include "../w_wad.h" +#include "../z_zone.h" +#include "../r_things.h" + +#include "hw_main.h" +#ifdef HAVE_PNG + +#ifndef _MSC_VER +#ifndef _LARGEFILE64_SOURCE +#define _LARGEFILE64_SOURCE +#endif +#endif + +#ifndef _LFS64_LARGEFILE +#define _LFS64_LARGEFILE +#endif + +#ifndef _FILE_OFFSET_BITS +#define _FILE_OFFSET_BITS 0 +#endif + + #include "png.h" + #ifndef PNG_READ_SUPPORTED + #undef HAVE_PNG + #endif + #if PNG_LIBPNG_VER < 100207 + //#undef HAVE_PNG + #endif +#endif + +#define NUMVERTEXNORMALS 162 +float avertexnormals[NUMVERTEXNORMALS][3] = { +{-0.525731f, 0.000000f, 0.850651f}, +{-0.442863f, 0.238856f, 0.864188f}, +{-0.295242f, 0.000000f, 0.955423f}, +{-0.309017f, 0.500000f, 0.809017f}, +{-0.162460f, 0.262866f, 0.951056f}, +{0.000000f, 0.000000f, 1.000000f}, +{0.000000f, 0.850651f, 0.525731f}, +{-0.147621f, 0.716567f, 0.681718f}, +{0.147621f, 0.716567f, 0.681718f}, +{0.000000f, 0.525731f, 0.850651f}, +{0.309017f, 0.500000f, 0.809017f}, +{0.525731f, 0.000000f, 0.850651f}, +{0.295242f, 0.000000f, 0.955423f}, +{0.442863f, 0.238856f, 0.864188f}, +{0.162460f, 0.262866f, 0.951056f}, +{-0.681718f, 0.147621f, 0.716567f}, +{-0.809017f, 0.309017f, 0.500000f}, +{-0.587785f, 0.425325f, 0.688191f}, +{-0.850651f, 0.525731f, 0.000000f}, +{-0.864188f, 0.442863f, 0.238856f}, +{-0.716567f, 0.681718f, 0.147621f}, +{-0.688191f, 0.587785f, 0.425325f}, +{-0.500000f, 0.809017f, 0.309017f}, +{-0.238856f, 0.864188f, 0.442863f}, +{-0.425325f, 0.688191f, 0.587785f}, +{-0.716567f, 0.681718f, -0.147621f}, +{-0.500000f, 0.809017f, -0.309017f}, +{-0.525731f, 0.850651f, 0.000000f}, +{0.000000f, 0.850651f, -0.525731f}, +{-0.238856f, 0.864188f, -0.442863f}, +{0.000000f, 0.955423f, -0.295242f}, +{-0.262866f, 0.951056f, -0.162460f}, +{0.000000f, 1.000000f, 0.000000f}, +{0.000000f, 0.955423f, 0.295242f}, +{-0.262866f, 0.951056f, 0.162460f}, +{0.238856f, 0.864188f, 0.442863f}, +{0.262866f, 0.951056f, 0.162460f}, +{0.500000f, 0.809017f, 0.309017f}, +{0.238856f, 0.864188f, -0.442863f}, +{0.262866f, 0.951056f, -0.162460f}, +{0.500000f, 0.809017f, -0.309017f}, +{0.850651f, 0.525731f, 0.000000f}, +{0.716567f, 0.681718f, 0.147621f}, +{0.716567f, 0.681718f, -0.147621f}, +{0.525731f, 0.850651f, 0.000000f}, +{0.425325f, 0.688191f, 0.587785f}, +{0.864188f, 0.442863f, 0.238856f}, +{0.688191f, 0.587785f, 0.425325f}, +{0.809017f, 0.309017f, 0.500000f}, +{0.681718f, 0.147621f, 0.716567f}, +{0.587785f, 0.425325f, 0.688191f}, +{0.955423f, 0.295242f, 0.000000f}, +{1.000000f, 0.000000f, 0.000000f}, +{0.951056f, 0.162460f, 0.262866f}, +{0.850651f, -0.525731f, 0.000000f}, +{0.955423f, -0.295242f, 0.000000f}, +{0.864188f, -0.442863f, 0.238856f}, +{0.951056f, -0.162460f, 0.262866f}, +{0.809017f, -0.309017f, 0.500000f}, +{0.681718f, -0.147621f, 0.716567f}, +{0.850651f, 0.000000f, 0.525731f}, +{0.864188f, 0.442863f, -0.238856f}, +{0.809017f, 0.309017f, -0.500000f}, +{0.951056f, 0.162460f, -0.262866f}, +{0.525731f, 0.000000f, -0.850651f}, +{0.681718f, 0.147621f, -0.716567f}, +{0.681718f, -0.147621f, -0.716567f}, +{0.850651f, 0.000000f, -0.525731f}, +{0.809017f, -0.309017f, -0.500000f}, +{0.864188f, -0.442863f, -0.238856f}, +{0.951056f, -0.162460f, -0.262866f}, +{0.147621f, 0.716567f, -0.681718f}, +{0.309017f, 0.500000f, -0.809017f}, +{0.425325f, 0.688191f, -0.587785f}, +{0.442863f, 0.238856f, -0.864188f}, +{0.587785f, 0.425325f, -0.688191f}, +{0.688191f, 0.587785f, -0.425325f}, +{-0.147621f, 0.716567f, -0.681718f}, +{-0.309017f, 0.500000f, -0.809017f}, +{0.000000f, 0.525731f, -0.850651f}, +{-0.525731f, 0.000000f, -0.850651f}, +{-0.442863f, 0.238856f, -0.864188f}, +{-0.295242f, 0.000000f, -0.955423f}, +{-0.162460f, 0.262866f, -0.951056f}, +{0.000000f, 0.000000f, -1.000000f}, +{0.295242f, 0.000000f, -0.955423f}, +{0.162460f, 0.262866f, -0.951056f}, +{-0.442863f, -0.238856f, -0.864188f}, +{-0.309017f, -0.500000f, -0.809017f}, +{-0.162460f, -0.262866f, -0.951056f}, +{0.000000f, -0.850651f, -0.525731f}, +{-0.147621f, -0.716567f, -0.681718f}, +{0.147621f, -0.716567f, -0.681718f}, +{0.000000f, -0.525731f, -0.850651f}, +{0.309017f, -0.500000f, -0.809017f}, +{0.442863f, -0.238856f, -0.864188f}, +{0.162460f, -0.262866f, -0.951056f}, +{0.238856f, -0.864188f, -0.442863f}, +{0.500000f, -0.809017f, -0.309017f}, +{0.425325f, -0.688191f, -0.587785f}, +{0.716567f, -0.681718f, -0.147621f}, +{0.688191f, -0.587785f, -0.425325f}, +{0.587785f, -0.425325f, -0.688191f}, +{0.000000f, -0.955423f, -0.295242f}, +{0.000000f, -1.000000f, 0.000000f}, +{0.262866f, -0.951056f, -0.162460f}, +{0.000000f, -0.850651f, 0.525731f}, +{0.000000f, -0.955423f, 0.295242f}, +{0.238856f, -0.864188f, 0.442863f}, +{0.262866f, -0.951056f, 0.162460f}, +{0.500000f, -0.809017f, 0.309017f}, +{0.716567f, -0.681718f, 0.147621f}, +{0.525731f, -0.850651f, 0.000000f}, +{-0.238856f, -0.864188f, -0.442863f}, +{-0.500000f, -0.809017f, -0.309017f}, +{-0.262866f, -0.951056f, -0.162460f}, +{-0.850651f, -0.525731f, 0.000000f}, +{-0.716567f, -0.681718f, -0.147621f}, +{-0.716567f, -0.681718f, 0.147621f}, +{-0.525731f, -0.850651f, 0.000000f}, +{-0.500000f, -0.809017f, 0.309017f}, +{-0.238856f, -0.864188f, 0.442863f}, +{-0.262866f, -0.951056f, 0.162460f}, +{-0.864188f, -0.442863f, 0.238856f}, +{-0.809017f, -0.309017f, 0.500000f}, +{-0.688191f, -0.587785f, 0.425325f}, +{-0.681718f, -0.147621f, 0.716567f}, +{-0.442863f, -0.238856f, 0.864188f}, +{-0.587785f, -0.425325f, 0.688191f}, +{-0.309017f, -0.500000f, 0.809017f}, +{-0.147621f, -0.716567f, 0.681718f}, +{-0.425325f, -0.688191f, 0.587785f}, +{-0.162460f, -0.262866f, 0.951056f}, +{0.442863f, -0.238856f, 0.864188f}, +{0.162460f, -0.262866f, 0.951056f}, +{0.309017f, -0.500000f, 0.809017f}, +{0.147621f, -0.716567f, 0.681718f}, +{0.000000f, -0.525731f, 0.850651f}, +{0.425325f, -0.688191f, 0.587785f}, +{0.587785f, -0.425325f, 0.688191f}, +{0.688191f, -0.587785f, 0.425325f}, +{-0.955423f, 0.295242f, 0.000000f}, +{-0.951056f, 0.162460f, 0.262866f}, +{-1.000000f, 0.000000f, 0.000000f}, +{-0.850651f, 0.000000f, 0.525731f}, +{-0.955423f, -0.295242f, 0.000000f}, +{-0.951056f, -0.162460f, 0.262866f}, +{-0.864188f, 0.442863f, -0.238856f}, +{-0.951056f, 0.162460f, -0.262866f}, +{-0.809017f, 0.309017f, -0.500000f}, +{-0.864188f, -0.442863f, -0.238856f}, +{-0.951056f, -0.162460f, -0.262866f}, +{-0.809017f, -0.309017f, -0.500000f}, +{-0.681718f, 0.147621f, -0.716567f}, +{-0.681718f, -0.147621f, -0.716567f}, +{-0.850651f, 0.000000f, -0.525731f}, +{-0.688191f, 0.587785f, -0.425325f}, +{-0.587785f, 0.425325f, -0.688191f}, +{-0.425325f, 0.688191f, -0.587785f}, +{-0.425325f, -0.688191f, -0.587785f}, +{-0.587785f, -0.425325f, -0.688191f}, +{-0.688191f, -0.587785f, -0.425325f}, +}; + +md2_t md2_models[NUMSPRITES]; +md2_t md2_playermodels[MAXSKINS]; + + +/* + * free model + */ +static void md2_freeModel (md2_model_t *model) +{ + if (model) + { + if (model->skins) + free(model->skins); + + if (model->texCoords) + free(model->texCoords); + + if (model->triangles) + free(model->triangles); + + if (model->frames) + { + size_t i; + + for (i = 0; i < model->header.numFrames; i++) + { + if (model->frames[i].vertices) + free(model->frames[i].vertices); + } + free(model->frames); + } + + if (model->glCommandBuffer) + free(model->glCommandBuffer); + + free(model); + } +} + + +// +// load model +// +// Hurdler: the current path is the Legacy.exe path +static md2_model_t *md2_readModel(const char *filename) +{ + FILE *file; + md2_model_t *model; + UINT8 buffer[MD2_MAX_FRAMESIZE]; + size_t i; + + model = calloc(1, sizeof (*model)); + if (model == NULL) + return 0; + + file = fopen(filename, "rb"); + if (!file) + { + free(model); + return 0; + } + + // initialize model and read header + + if (fread(&model->header, sizeof (model->header), 1, file) != 1 + || model->header.magic != + (INT32)(('2' << 24) + ('P' << 16) + ('D' << 8) + 'I')) + { + fclose(file); + free(model); + return 0; + } + + model->header.numSkins = 1; + + // read skins + fseek(file, model->header.offsetSkins, SEEK_SET); + if (model->header.numSkins > 0) + { + model->skins = calloc(sizeof (md2_skin_t), model->header.numSkins); + if (!model->skins || model->header.numSkins != + fread(model->skins, sizeof (md2_skin_t), model->header.numSkins, file)) + { + md2_freeModel (model); + return 0; + } + + ; + } + + // read texture coordinates + fseek(file, model->header.offsetTexCoords, SEEK_SET); + if (model->header.numTexCoords > 0) + { + model->texCoords = calloc(sizeof (md2_textureCoordinate_t), model->header.numTexCoords); + if (!model->texCoords || model->header.numTexCoords != + fread(model->texCoords, sizeof (md2_textureCoordinate_t), model->header.numTexCoords, file)) + { + md2_freeModel (model); + return 0; + } + + + } + + // read triangles + fseek(file, model->header.offsetTriangles, SEEK_SET); + if (model->header.numTriangles > 0) + { + model->triangles = calloc(sizeof (md2_triangle_t), model->header.numTriangles); + if (!model->triangles || model->header.numTriangles != + fread(model->triangles, sizeof (md2_triangle_t), model->header.numTriangles, file)) + { + md2_freeModel (model); + return 0; + } + } + + // read alias frames + fseek(file, model->header.offsetFrames, SEEK_SET); + if (model->header.numFrames > 0) + { + model->frames = calloc(sizeof (md2_frame_t), model->header.numFrames); + if (!model->frames) + { + md2_freeModel (model); + return 0; + } + + for (i = 0; i < model->header.numFrames; i++) + { + md2_alias_frame_t *frame = (md2_alias_frame_t *)(void *)buffer; + size_t j; + + model->frames[i].vertices = calloc(sizeof (md2_triangleVertex_t), model->header.numVertices); + if (!model->frames[i].vertices || model->header.frameSize != + fread(frame, 1, model->header.frameSize, file)) + { + md2_freeModel (model); + return 0; + } + + strcpy(model->frames[i].name, frame->name); + for (j = 0; j < model->header.numVertices; j++) + { + model->frames[i].vertices[j].vertex[0] = (float) ((INT32) frame->alias_vertices[j].vertex[0]) * frame->scale[0] + frame->translate[0]; + model->frames[i].vertices[j].vertex[2] = -1* ((float) ((INT32) frame->alias_vertices[j].vertex[1]) * frame->scale[1] + frame->translate[1]); + model->frames[i].vertices[j].vertex[1] = (float) ((INT32) frame->alias_vertices[j].vertex[2]) * frame->scale[2] + frame->translate[2]; + model->frames[i].vertices[j].normal[0] = avertexnormals[frame->alias_vertices[j].lightNormalIndex][0]; + model->frames[i].vertices[j].normal[1] = avertexnormals[frame->alias_vertices[j].lightNormalIndex][1]; + model->frames[i].vertices[j].normal[2] = avertexnormals[frame->alias_vertices[j].lightNormalIndex][2]; + } + } + } + + // read gl commands + fseek(file, model->header.offsetGlCommands, SEEK_SET); + if (model->header.numGlCommands) + { + model->glCommandBuffer = calloc(sizeof (INT32), model->header.numGlCommands); + if (!model->glCommandBuffer || model->header.numGlCommands != + fread(model->glCommandBuffer, sizeof (INT32), model->header.numGlCommands, file)) + { + md2_freeModel (model); + return 0; + } + } + + fclose(file); + + return model; +} + +/* + * center model + */ +static inline void md2_getBoundingBox (md2_model_t *model, float *minmax) +{ + size_t i; + float minx, maxx; + float miny, maxy; + float minz, maxz; + + minx = miny = minz = 999999.0f; + maxx = maxy = maxz = -999999.0f; + + /* get bounding box */ + for (i = 0; i < model->header.numVertices; i++) + { + md2_triangleVertex_t *v = &model->frames[0].vertices[i]; + + if (v->vertex[0] < minx) + minx = v->vertex[0]; + else if (v->vertex[0] > maxx) + maxx = v->vertex[0]; + + if (v->vertex[1] < miny) + miny = v->vertex[1]; + else if (v->vertex[1] > maxy) + maxy = v->vertex[1]; + + if (v->vertex[2] < minz) + minz = v->vertex[2]; + else if (v->vertex[2] > maxz) + maxz = v->vertex[2]; + } + + minmax[0] = minx; + minmax[1] = maxx; + minmax[2] = miny; + minmax[3] = maxy; + minmax[4] = minz; + minmax[5] = maxz; +} + +static inline INT32 md2_getAnimationCount(md2_model_t *model) +{ + size_t i, pos; + INT32 j = 0, count; + char name[16], last[16]; + + strcpy(last, model->frames[0].name); + pos = strlen(last) - 1; + while (last[pos] >= '0' && last[pos] <= '9' && j < 2) + { + pos--; + j++; + } + last[pos + 1] = '\0'; + + count = 0; + + for (i = 0; i <= model->header.numFrames; i++) + { + if (i == model->header.numFrames) + strcpy(name, ""); // some kind of a sentinel + else + strcpy(name, model->frames[i].name); + pos = strlen(name) - 1; + j = 0; + while (name[pos] >= '0' && name[pos] <= '9' && j < 2) + { + pos--; + j++; + } + name[pos + 1] = '\0'; + + if (strcmp(last, name)) + { + strcpy(last, name); + count++; + } + } + + return count; +} + +static inline const char * md2_getAnimationName (md2_model_t *model, INT32 animation) +{ + size_t i, pos; + INT32 j = 0, count; + static char last[32]; + char name[32]; + + strcpy(last, model->frames[0].name); + pos = strlen(last) - 1; + while (last[pos] >= '0' && last[pos] <= '9' && j < 2) + { + pos--; + j++; + } + last[pos + 1] = '\0'; + + count = 0; + + for (i = 0; i <= model->header.numFrames; i++) + { + if (i == model->header.numFrames) + strcpy(name, ""); // some kind of a sentinel + else + strcpy(name, model->frames[i].name); + pos = strlen(name) - 1; + j = 0; + while (name[pos] >= '0' && name[pos] <= '9' && j < 2) + { + pos--; + j++; + } + name[pos + 1] = '\0'; + + if (strcmp(last, name)) + { + if (count == animation) + return last; + + strcpy(last, name); + count++; + } + } + + return 0; +} + +static inline void md2_getAnimationFrames(md2_model_t *model, + INT32 animation, INT32 *startFrame, INT32 *endFrame) +{ + size_t i, pos; + INT32 j = 0, count, numFrames, frameCount; + char name[16], last[16]; + + strcpy(last, model->frames[0].name); + pos = strlen(last) - 1; + while (last[pos] >= '0' && last[pos] <= '9' && j < 2) + { + pos--; + j++; + } + last[pos + 1] = '\0'; + + count = 0; + numFrames = 0; + frameCount = 0; + + for (i = 0; i <= model->header.numFrames; i++) + { + if (i == model->header.numFrames) + strcpy(name, ""); // some kind of a sentinel + else + strcpy(name, model->frames[i].name); + pos = strlen(name) - 1; + j = 0; + while (name[pos] >= '0' && name[pos] <= '9' && j < 2) + { + pos--; + j++; + } + name[pos + 1] = '\0'; + + if (strcmp(last, name)) + { + strcpy(last, name); + + if (count == animation) + { + *startFrame = frameCount - numFrames; + *endFrame = frameCount - 1; + return; + } + + count++; + numFrames = 0; + } + frameCount++; + numFrames++; + } + *startFrame = *endFrame = 0; +} + +static inline void md2_printModelInfo (md2_model_t *model) +{ +#if 0 + INT32 i; + + CONS_Debug(DBG_RENDER, "magic:\t\t\t%c%c%c%c\n", model->header.magic>>24, + (model->header.magic>>16)&0xff, + (model->header.magic>>8)&0xff, + model->header.magic&0xff); + CONS_Debug(DBG_RENDER, "version:\t\t%d\n", model->header.version); + CONS_Debug(DBG_RENDER, "skinWidth:\t\t%d\n", model->header.skinWidth); + CONS_Debug(DBG_RENDER, "skinHeight:\t\t%d\n", model->header.skinHeight); + CONS_Debug(DBG_RENDER, "frameSize:\t\t%d\n", model->header.frameSize); + CONS_Debug(DBG_RENDER, "numSkins:\t\t%d\n", model->header.numSkins); + CONS_Debug(DBG_RENDER, "numVertices:\t\t%d\n", model->header.numVertices); + CONS_Debug(DBG_RENDER, "numTexCoords:\t\t%d\n", model->header.numTexCoords); + CONS_Debug(DBG_RENDER, "numTriangles:\t\t%d\n", model->header.numTriangles); + CONS_Debug(DBG_RENDER, "numGlCommands:\t\t%d\n", model->header.numGlCommands); + CONS_Debug(DBG_RENDER, "numFrames:\t\t%d\n", model->header.numFrames); + CONS_Debug(DBG_RENDER, "offsetSkins:\t\t%d\n", model->header.offsetSkins); + CONS_Debug(DBG_RENDER, "offsetTexCoords:\t%d\n", model->header.offsetTexCoords); + CONS_Debug(DBG_RENDER, "offsetTriangles:\t%d\n", model->header.offsetTriangles); + CONS_Debug(DBG_RENDER, "offsetFrames:\t\t%d\n", model->header.offsetFrames); + CONS_Debug(DBG_RENDER, "offsetGlCommands:\t%d\n", model->header.offsetGlCommands); + CONS_Debug(DBG_RENDER, "offsetEnd:\t\t%d\n", model->header.offsetEnd); + + for (i = 0; i < model->header.numFrames; i++) + CONS_Debug(DBG_RENDER, "%s ", model->frames[i].name); + CONS_Debug(DBG_RENDER, "\n"); +#else + (void)model; +#endif +} + +#ifdef HAVE_PNG +static void PNG_error(png_structp PNG, png_const_charp pngtext) +{ + CONS_Debug(DBG_RENDER, "libpng error at %p: %s", PNG, pngtext); + //I_Error("libpng error at %p: %s", PNG, pngtext); +} + +static void PNG_warn(png_structp PNG, png_const_charp pngtext) +{ + CONS_Debug(DBG_RENDER, "libpng warning at %p: %s", PNG, pngtext); +} + +static GrTextureFormat_t PNG_Load(const char *filename, int *w, int *h, GLPatch_t *grpatch) +{ + png_structp png_ptr; + png_infop png_info_ptr; + png_uint_32 width, height; + int bit_depth, color_type; +#ifdef PNG_SETJMP_SUPPORTED +#ifdef USE_FAR_KEYWORD + jmp_buf jmpbuf; +#endif +#endif + png_FILE_p png_FILE; + char *pngfilename = va("md2/%s", filename); + + FIL_ForceExtension(pngfilename, ".png"); + png_FILE = fopen(pngfilename, "rb"); + if (!png_FILE) + { + //CONS_Debug(DBG_RENDER, "M_SavePNG: Error on opening %s for loading\n", filename); + return 0; + } + + png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, + PNG_error, PNG_warn); + if (!png_ptr) + { + CONS_Debug(DBG_RENDER, "PNG_Load: Error on initialize libpng\n"); + fclose(png_FILE); + return 0; + } + + png_info_ptr = png_create_info_struct(png_ptr); + if (!png_info_ptr) + { + CONS_Debug(DBG_RENDER, "PNG_Load: Error on allocate for libpng\n"); + png_destroy_read_struct(&png_ptr, NULL, NULL); + fclose(png_FILE); + return 0; + } + +#ifdef USE_FAR_KEYWORD + if (setjmp(jmpbuf)) +#else + if (setjmp(png_jmpbuf(png_ptr))) +#endif + { + //CONS_Debug(DBG_RENDER, "libpng load error on %s\n", filename); + png_destroy_read_struct(&png_ptr, &png_info_ptr, NULL); + fclose(png_FILE); + Z_Free(grpatch->mipmap.grInfo.data); + return 0; + } +#ifdef USE_FAR_KEYWORD + png_memcpy(png_jmpbuf(png_ptr), jmpbuf, sizeof jmp_buf); +#endif + + png_init_io(png_ptr, png_FILE); + +#ifdef PNG_SET_USER_LIMITS_SUPPORTED + png_set_user_limits(png_ptr, 2048, 2048); +#endif + + png_read_info(png_ptr, png_info_ptr); + + png_get_IHDR(png_ptr, png_info_ptr, &width, &height, &bit_depth, &color_type, + NULL, NULL, NULL); + + if (bit_depth == 16) + png_set_strip_16(png_ptr); + + if (color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA) + png_set_gray_to_rgb(png_ptr); + else if (color_type == PNG_COLOR_TYPE_PALETTE) + png_set_palette_to_rgb(png_ptr); + + if (png_get_valid(png_ptr, png_info_ptr, PNG_INFO_tRNS)) + png_set_tRNS_to_alpha(png_ptr); + else if (color_type != PNG_COLOR_TYPE_RGB_ALPHA && color_type != PNG_COLOR_TYPE_GRAY_ALPHA) + { +#if PNG_LIBPNG_VER < 10207 + png_set_filler(png_ptr, 0xFF, PNG_FILLER_AFTER); +#else + png_set_add_alpha(png_ptr, 0xFF, PNG_FILLER_AFTER); +#endif + } + + png_read_update_info(png_ptr, png_info_ptr); + + { + png_uint_32 i, pitch = png_get_rowbytes(png_ptr, png_info_ptr); + png_bytep PNG_image = Z_Malloc(pitch*height, PU_HWRCACHE, &grpatch->mipmap.grInfo.data); + png_bytepp row_pointers = png_malloc(png_ptr, height * sizeof (png_bytep)); + for (i = 0; i < height; i++) + row_pointers[i] = PNG_image + i*pitch; + png_read_image(png_ptr, row_pointers); + png_free(png_ptr, (png_voidp)row_pointers); + } + + png_destroy_read_struct(&png_ptr, &png_info_ptr, NULL); + + fclose(png_FILE); + *w = (int)width; + *h = (int)height; + return GR_RGBA; +} +#endif + +typedef struct +{ + UINT8 manufacturer; + UINT8 version; + UINT8 encoding; + UINT8 bitsPerPixel; + INT16 xmin; + INT16 ymin; + INT16 xmax; + INT16 ymax; + INT16 hDpi; + INT16 vDpi; + UINT8 colorMap[48]; + UINT8 reserved; + UINT8 numPlanes; + INT16 bytesPerLine; + INT16 paletteInfo; + INT16 hScreenSize; + INT16 vScreenSize; + UINT8 filler[54]; +} PcxHeader; + +static GrTextureFormat_t PCX_Load(const char *filename, int *w, int *h, + GLPatch_t *grpatch) +{ + PcxHeader header; +#define PALSIZE 768 + UINT8 palette[PALSIZE]; + const UINT8 *pal; + RGBA_t *image; + size_t pw, ph, size, ptr = 0; + INT32 ch, rep; + FILE *file; + char *pcxfilename = va("md2/%s", filename); + + FIL_ForceExtension(pcxfilename, ".pcx"); + file = fopen(pcxfilename, "rb"); + if (!file) + return 0; + + if (fread(&header, sizeof (PcxHeader), 1, file) != 1) + { + fclose(file); + return 0; + } + + if (header.bitsPerPixel != 8) + { + fclose(file); + return 0; + } + + fseek(file, -PALSIZE, SEEK_END); + + pw = *w = header.xmax - header.xmin + 1; + ph = *h = header.ymax - header.ymin + 1; + image = Z_Malloc(pw*ph*4, PU_HWRCACHE, &grpatch->mipmap.grInfo.data); + + if (fread(palette, sizeof (UINT8), PALSIZE, file) != PALSIZE) + { + Z_Free(image); + fclose(file); + return 0; + } + fseek(file, sizeof (PcxHeader), SEEK_SET); + + size = pw * ph; + while (ptr < size) + { + ch = fgetc(file); //Hurdler: beurk + if (ch >= 192) + { + rep = ch - 192; + ch = fgetc(file); + } + else + { + rep = 1; + } + while (rep--) + { + pal = palette + ch*3; + image[ptr].s.red = *pal++; + image[ptr].s.green = *pal++; + image[ptr].s.blue = *pal++; + image[ptr].s.alpha = 0xFF; + ptr++; + } + } + fclose(file); + return GR_RGBA; +} + +// -----------------+ +// md2_loadTexture : Download a pcx or png texture for MD2 models +// -----------------+ +static void md2_loadTexture(md2_t *model) +{ + GLPatch_t *grpatch; + const char *filename = model->filename; + + if (model->grpatch) + { + grpatch = model->grpatch; + Z_Free(grpatch->mipmap.grInfo.data); + } + else + grpatch = Z_Calloc(sizeof *grpatch, PU_HWRPATCHINFO, + &(model->grpatch)); + + if (!grpatch->mipmap.downloaded && !grpatch->mipmap.grInfo.data) + { + int w = 0, h = 0; +#ifdef HAVE_PNG + grpatch->mipmap.grInfo.format = PNG_Load(filename, &w, &h, grpatch); + if (grpatch->mipmap.grInfo.format == 0) +#endif + grpatch->mipmap.grInfo.format = PCX_Load(filename, &w, &h, grpatch); + if (grpatch->mipmap.grInfo.format == 0) + return; + + grpatch->mipmap.downloaded = 0; + grpatch->mipmap.flags = 0; + + grpatch->width = (INT16)w; + grpatch->height = (INT16)h; + grpatch->mipmap.width = (UINT16)w; + grpatch->mipmap.height = (UINT16)h; + + // not correct! + grpatch->mipmap.grInfo.smallLodLog2 = GR_LOD_LOG2_256; + grpatch->mipmap.grInfo.largeLodLog2 = GR_LOD_LOG2_256; + grpatch->mipmap.grInfo.aspectRatioLog2 = GR_ASPECT_LOG2_1x1; + } + HWD.pfnSetTexture(&grpatch->mipmap); + HWR_UnlockCachedPatch(grpatch); +} + +void HWR_InitMD2(void) +{ + size_t i; + INT32 s; + FILE *f; + char name[18], filename[32]; + float scale, offset; + + CONS_Printf("InitMD2()...\n"); + for (s = 0; s < MAXSKINS; s++) + { + md2_playermodels[s].scale = -1.0f; + md2_playermodels[s].model = NULL; + md2_playermodels[s].grpatch = NULL; + md2_playermodels[s].skin = -1; + md2_playermodels[s].notfound = true; + } + for (i = 0; i < NUMSPRITES; i++) + { + md2_models[i].scale = -1.0f; + md2_models[i].model = NULL; + md2_models[i].grpatch = NULL; + md2_models[i].skin = -1; + md2_models[i].notfound = true; + } + // read the md2.dat file + + f = fopen("md2.dat", "rt"); + if (!f) + { + CONS_Printf("%s", M_GetText("Error while loading md2.dat\n")); + return; + } + while (fscanf(f, "%19s %31s %f %f", name, filename, &scale, &offset) == 4) + { + for (i = 0; i < NUMSPRITES; i++) + { + if (stricmp(name, sprnames[i]) == 0) + { + if (stricmp(name, "PLAY") == 0) + continue; + + //CONS_Debug(DBG_RENDER, " Found: %s %s %f %f\n", name, filename, scale, offset); + md2_models[i].scale = scale; + md2_models[i].offset = offset; + md2_models[i].notfound = false; + strcpy(md2_models[i].filename, filename); + break; + } + if (i == NUMSPRITES) + { + CONS_Printf("MD2 for sprite %s not found\n", name); + md2_models[i].notfound = true; + } + } + + for (s = 0; s < MAXSKINS; s++) + { + if (stricmp(name, skins[s].name) == 0) + { + //CONS_Printf(" Found: %s %s %f %f\n", name, filename, scale, offset); + md2_playermodels[s].skin = s; + md2_playermodels[s].scale = scale; + md2_playermodels[s].offset = offset; + md2_playermodels[s].notfound = false; + strcpy(md2_playermodels[s].filename, filename); + break; + } + if (s == MAXSKINS-1) + { + CONS_Printf("MD2 for player skin %s not found\n", name); + md2_playermodels[s].notfound = true; + } + } + + } + fclose(f); +} + +void HWR_AddPlayerMD2(int skin) // For MD2's that were added after startup +{ + FILE *f; + char name[18], filename[32]; + float scale, offset; + + CONS_Printf("AddPlayerMD2()...\n"); + + // read the md2.dat file + + f = fopen("md2.dat", "rt"); + if (!f) + { + CONS_Printf("Error while loading md2.dat\n"); + return; + } + + // Check for any MD2s that match the names of player skins! + while (fscanf(f, "%19s %31s %f %f", name, filename, &scale, &offset) == 4) + { + if (stricmp(name, skins[skin].name) == 0) + { + md2_playermodels[skin].skin = skin; + md2_playermodels[skin].scale = scale; + md2_playermodels[skin].offset = offset; + md2_playermodels[skin].notfound = false; + strcpy(md2_playermodels[skin].filename, filename); + break; + } + if (skin == MAXSKINS-1) + { + CONS_Printf("MD2 for player skin %s not found\n", name); + md2_playermodels[skin].notfound = true; + } + } + + fclose(f); + +} + + +void HWR_AddSpriteMD2(size_t spritenum) // For MD2s that were added after startup +{ + FILE *f; + // name[18] is used to check for names in the md2.dat file that match with sprites or player skins + // sprite names are always 4 characters long, and names is for player skins can be up to 19 characters long + char name[18], filename[32]; + float scale, offset; + + // Read the md2.dat file + + f = fopen("md2.dat", "rt"); + + if (!f) + { + CONS_Printf("Error while loading md2.dat\n"); + return; + } + + // Check for any MD2s that match the names of player skins! + while (fscanf(f, "%19s %31s %f %f", name, filename, &scale, &offset) == 4) + { + { + if (stricmp(name, sprnames[spritenum]) == 0) + { + if (stricmp(name, "PLAY") == 0) // Handled already NEWMD2: Per sprite, per-skin check + continue; + + md2_models[spritenum].scale = scale; + md2_models[spritenum].offset = offset; + md2_models[spritenum].notfound = false; + strcpy(md2_models[spritenum].filename, filename); + break; + } + + if (spritenum == NUMSPRITES-1) + { + CONS_Printf("MD2 for sprite %s not found\n", name); + md2_models[spritenum].notfound = true; + } + } + } + + fclose(f); +} + + +// -----------------+ +// HWR_DrawMD2 : Draw MD2 +// : (monsters, bonuses, weapons, lights, ...) +// Returns : +// -----------------+ + /* + wait/stand + death + pain + walk + shoot/fire + + die? + atka? + atkb? + attacka/b/c/d? + res? + run? + */ +#define NORMALFOG 0x00000000 +#define FADEFOG 0x19000000 +void HWR_DrawMD2(gr_vissprite_t *spr) +{ + FSurfaceInfo Surf; + + char filename[64]; + INT32 frame; + FTransform p; + md2_t *md2; + UINT8 color[4]; + + // MD2 colormap fix + // colormap test + { + sector_t *sector = spr->mobj->subsector->sector; + UINT8 lightlevel = LightLevelToLum(sector->lightlevel); + extracolormap_t *colormap = sector->extra_colormap; + + if (sector->numlights) + { + INT32 light = R_GetPlaneLight(sector, spr->mobj->z, false); + + if (sector->lightlist[light].height > (spr->mobj->z + spr->mobj->height)) + { + if (!(spr->mobj->frame & FF_FULLBRIGHT)) + lightlevel = LightLevelToLum(*sector->lightlist[light].lightlevel); + else + lightlevel = LightLevelToLum(255); + + if (sector->lightlist[light].extra_colormap) + colormap = sector->lightlist[light].extra_colormap; + } + else // If we can't use the light at its bottom, we'll use the light at its top + { + light = R_GetPlaneLight(sector, spr->mobj->z + spr->mobj->height, false); + + if (!(spr->mobj->frame & FF_FULLBRIGHT)) + lightlevel = LightLevelToLum(*sector->lightlist[light].lightlevel); + else + lightlevel = LightLevelToLum(255); + + if (sector->lightlist[light].extra_colormap) + colormap = sector->lightlist[light].extra_colormap; + } + } + else + { + if (!(spr->mobj->frame & FF_FULLBRIGHT)) + lightlevel = LightLevelToLum(sector->lightlevel); + else + lightlevel = LightLevelToLum(255); + + if (sector->extra_colormap) + colormap = sector->extra_colormap; + } + + if (spr->mobj->frame & FF_FULLBRIGHT) + lightlevel = LightLevelToLum(255); + + if (colormap) + Surf.FlatColor.rgba = HWR_Lighting(lightlevel, colormap->rgba, colormap->fadergba, false, false); + else + Surf.FlatColor.rgba = HWR_Lighting(lightlevel, NORMALFOG, FADEFOG, false, false); + } + + // Look at HWR_ProjetctSprite for more + if (cv_grmd2.value && ((md2_models[spr->mobj->sprite].scale > 0.0f) || (md2_playermodels[(skin_t*)spr->mobj->skin-skins].scale > 0.0f)) && !spr->precip) + { + GLPatch_t *gpatch; + FBITFIELD blend = 0; + INT32 *buff; + UINT32 durs = spr->mobj->state->tics; + UINT32 tics = spr->mobj->tics; + md2_frame_t *curr, *next = NULL; + const UINT8 flip = (UINT8)((spr->mobj->eflags & MFE_VERTICALFLIP) == MFE_VERTICALFLIP); + spritedef_t *sprdef; + spriteframe_t *sprframe; + float finalscale; + + if (spr->mobj->flags2 & MF2_SHADOW) + { + Surf.FlatColor.s.alpha = 0x40; + blend = PF_Translucent; + } + else if (spr->mobj->frame & FF_TRANSMASK) + blend = HWR_TranstableToAlpha((spr->mobj->frame & FF_TRANSMASK)>>FF_TRANSSHIFT, &Surf); + else + { + Surf.FlatColor.s.alpha = 0xFF; + blend = PF_Translucent; + } + + // dont forget to enabled the depth test because we can't do this like + // before: polygons models are not sorted + + // 1. load model+texture if not already loaded + // 2. draw model with correct position, rotation,... + if (spr->mobj->skin) + { + md2 = &md2_playermodels[(skin_t*)spr->mobj->skin-skins]; + md2->skin = (skin_t*)spr->mobj->skin-skins; + } + else + md2 = &md2_models[spr->mobj->sprite]; + + if (!md2->model) + { + //CONS_Debug(DBG_RENDER, "Loading MD2... (%s)", sprnames[spr->mobj->sprite]); + sprintf(filename, "md2/%s", md2->filename); + md2->model = md2_readModel(filename); + + if (md2->model) + { + md2_printModelInfo(md2->model); + } + else + { + //CONS_Debug(DBG_RENDER, " FAILED\n"); + return; + } + } + HWD.pfnSetBlend(blend); + finalscale = md2->scale; + //Hurdler: arf, I don't like that implementation at all... too much crappy + gpatch = md2->grpatch; + if (!gpatch || !gpatch->mipmap.grInfo.format || !gpatch->mipmap.downloaded) + md2_loadTexture(md2); + else if (gpatch->mipmap.grInfo.format) + { + // This is safe, since we know the texture has been downloaded + HWD.pfnSetTexture(&gpatch->mipmap); + } + else + { + // Sprite + gpatch = W_CachePatchNum(spr->patchlumpnum, PU_CACHE); + HWR_GetMappedPatch(gpatch, spr->colormap); + } + + //FIXME: this is not yet correct + frame = (spr->mobj->frame & FF_FRAMEMASK) % md2->model->header.numFrames; + buff = md2->model->glCommandBuffer; + curr = &md2->model->frames[frame]; + if (cv_grmd2.value == 1 + && spr->mobj->state->nextstate != S_NULL + && !(spr->mobj->player && (spr->mobj->state->nextstate == S_PLAY_TAP1 || spr->mobj->state->nextstate == S_PLAY_TAP2) && spr->mobj->state == &states[S_PLAY_STND])) + { + const INT32 nextframe = (states[spr->mobj->state->nextstate].frame & FF_FRAMEMASK) % md2->model->header.numFrames; + next = &md2->model->frames[nextframe]; + } + + //Hurdler: it seems there is still a small problem with mobj angle + p.x = FIXED_TO_FLOAT(spr->mobj->x); + p.y = FIXED_TO_FLOAT(spr->mobj->y)+md2->offset; + + if (spr->mobj->eflags & MFE_VERTICALFLIP) + p.z = FIXED_TO_FLOAT(spr->mobj->z + spr->mobj->height); + else + p.z = FIXED_TO_FLOAT(spr->mobj->z); + + if (spr->mobj->skin) + sprdef = &((skin_t *)spr->mobj->skin)->spritedef; + else + sprdef = &sprites[spr->mobj->sprite]; + + sprframe = &sprdef->spriteframes[spr->mobj->frame & FF_FRAMEMASK]; + + if (sprframe->rotate) + { + const fixed_t anglef = AngleFixed(spr->mobj->angle); + p.angley = FIXED_TO_FLOAT(anglef); + } + else + { + const fixed_t anglef = AngleFixed((R_PointToAngle(spr->mobj->x, spr->mobj->y))-ANGLE_180); + p.angley = FIXED_TO_FLOAT(anglef); + } + p.anglex = 0.0f; + + color[0] = Surf.FlatColor.s.red; + color[1] = Surf.FlatColor.s.green; + color[2] = Surf.FlatColor.s.blue; + color[3] = Surf.FlatColor.s.alpha; + + // SRB2CBTODO: MD2 scaling support + finalscale *= FIXED_TO_FLOAT(spr->mobj->scale); + + HWD.pfnDrawMD2i(buff, curr, durs, tics, next, &p, finalscale, flip, color); + + + } +} + +#endif //HWRENDER diff --git a/src/hardware/hw_md2.h b/src/hardware/hw_md2.h new file mode 100644 index 000000000..1166f10f2 --- /dev/null +++ b/src/hardware/hw_md2.h @@ -0,0 +1,135 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright (C) 1998-2000 by DooM Legacy Team. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +//----------------------------------------------------------------------------- +/// \file +/// \brief MD2 Handling +/// Inspired from md2.h by Mete Ciragan (mete@swissquake.ch) + +#ifndef _HW_MD2_H_ +#define _HW_MD2_H_ + +#include "hw_glob.h" + +#define MD2_MAX_TRIANGLES 4096 +#define MD2_MAX_VERTICES 2048 +#define MD2_MAX_TEXCOORDS 2048 +#define MD2_MAX_FRAMES 512 +#define MD2_MAX_SKINS 32 +#define MD2_MAX_FRAMESIZE (MD2_MAX_VERTICES * 4 + 128) + +#if defined(_MSC_VER) +#pragma pack(1) +#endif +typedef struct +{ + UINT32 magic; + UINT32 version; + UINT32 skinWidth; + UINT32 skinHeight; + UINT32 frameSize; + UINT32 numSkins; + UINT32 numVertices; + UINT32 numTexCoords; + UINT32 numTriangles; + UINT32 numGlCommands; + UINT32 numFrames; + UINT32 offsetSkins; + UINT32 offsetTexCoords; + UINT32 offsetTriangles; + UINT32 offsetFrames; + UINT32 offsetGlCommands; + UINT32 offsetEnd; +} ATTRPACK md2_header_t; //NOTE: each of md2_header's members are 4 unsigned bytes + +typedef struct +{ + UINT8 vertex[3]; + UINT8 lightNormalIndex; +} ATTRPACK md2_alias_triangleVertex_t; + +typedef struct +{ + float vertex[3]; + float normal[3]; +} ATTRPACK md2_triangleVertex_t; + +typedef struct +{ + INT16 vertexIndices[3]; + INT16 textureIndices[3]; +} ATTRPACK md2_triangle_t; + +typedef struct +{ + INT16 s, t; +} ATTRPACK md2_textureCoordinate_t; + +typedef struct +{ + float scale[3]; + float translate[3]; + char name[16]; + md2_alias_triangleVertex_t alias_vertices[1]; +} ATTRPACK md2_alias_frame_t; + +typedef struct +{ + char name[16]; + md2_triangleVertex_t *vertices; +} ATTRPACK md2_frame_t; + +typedef char md2_skin_t[64]; + +typedef struct +{ + float s, t; + INT32 vertexIndex; +} ATTRPACK md2_glCommandVertex_t; + +typedef struct +{ + md2_header_t header; + md2_skin_t *skins; + md2_textureCoordinate_t *texCoords; + md2_triangle_t *triangles; + md2_frame_t *frames; + INT32 *glCommandBuffer; +} ATTRPACK md2_model_t; + +#if defined(_MSC_VER) +#pragma pack() +#endif + +typedef struct +{ + char filename[32]; + float scale; + float offset; + md2_model_t *model; + void *grpatch; + boolean notfound; + INT32 skin; +} md2_t; + +extern md2_t md2_models[NUMSPRITES]; +extern md2_t md2_playermodels[MAXSKINS]; + +void HWR_InitMD2(void); +void HWR_DrawMD2(gr_vissprite_t *spr); +void HWR_AddPlayerMD2(INT32 skin); +void HWR_AddSpriteMD2(size_t spritenum); + +#endif // _HW_MD2_H_ diff --git a/src/hardware/hw_trick.c b/src/hardware/hw_trick.c new file mode 100644 index 000000000..84bac0e26 --- /dev/null +++ b/src/hardware/hw_trick.c @@ -0,0 +1,942 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright (C) 1998-2001 by DooM Legacy Team. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +//----------------------------------------------------------------------------- +/// \file +/// \brief special trick routines to make some SW tricks look OK with +/// HW rendering. This includes: +/// - deepwatereffect (e.g. tnt/map02) +/// - invisible staircase (e.g. eternal/map02) +/// - floating ceilings (e.g. eternal/map03) +/// +/// It is not guaranteed that it looks identical to the SW mode, +/// but it looks in most of the cases far better than having +/// holes in the architecture, HOM, etc. +/// +/// It fixes as well missing textures, which are replaced by either +/// a default texture or the midtexture. +/// +/// words of notice: +/// pseudosectors, as mentioned in this file, are sectors where both +/// sidedefs point to the same sector. This expression is also used +/// for sectors which are enclosed by another sector but have no +/// correct sidedefs at all +/// +/// if a vertex is inside a poly is determined by the angles between +/// this vertex and all angles on the linedefs (imagine walking along +/// a circle always facing a certain point inside/outside the circle; +/// if inside, angle have taken all values [0..pi), otherwise the +/// range was < pi/2 + +#include +#include "../doomdef.h" +#include "../doomstat.h" + +#ifdef HWRENDER +#include "hw_glob.h" +#include "hw_dll.h" +#include "../r_local.h" +#include "../i_system.h" + +// +// add a line to a sectors list of lines +// +static void addLineToChain(sector_t *sector, line_t *line) +{ + linechain_t *thisElem = NULL, *nextElem; + + if (!sector) + return; + + nextElem = sector->sectorLines; + + while (nextElem) // walk through chain + { + thisElem = nextElem; + nextElem = thisElem->next; + } + + // add a new element into the chain + if (thisElem) + { + thisElem->next = malloc(sizeof (linechain_t)); + if (thisElem->next) + { + thisElem->next->line = line; + thisElem->next->next = NULL; + } + else + { + I_Error("Out of memory in addLineToChain(.)\n"); + } + } + else // first element in chain + { + sector->sectorLines = malloc(sizeof (linechain_t)); + if (sector->sectorLines) + { + sector->sectorLines->line = line; + sector->sectorLines->next = NULL; + } + else + { + I_Error("Out of memory in addLineToChain(.)\n"); + } + } +} + +// +// We dont want a memory hole, do we?;-) +// +static void releaseLineChains(void) +{ + linechain_t *thisElem, *nextElem; + sector_t *sector; + size_t i; + + for (i = 0; i < numsectors; i++) + { + sector = §ors[i]; + nextElem = sector->sectorLines; + + while (nextElem) + { + thisElem = nextElem; + nextElem = thisElem->next; + free(thisElem); + } + + sector->sectorLines = NULL; + } +} + +// +// check if a pseudo sector is valid by checking all its linedefs +// +static boolean isPSectorValid(sector_t *sector) +{ + linechain_t *thisElem, *nextElem; + + if (!sector->pseudoSector) // check only pseudosectors, others dont care + { +#ifdef PARANOIA + CONS_Debug(DBG_RENDER, "Alert! non-pseudosector fed to isPSectorClosed()\n"); +#endif + return false; + } + + nextElem = sector->sectorLines; + + while (nextElem) + { + thisElem = nextElem; + nextElem = thisElem->next; + if (thisElem->line->frontsector != thisElem->line->backsector) + return false; + } + return true; +} + +// +// angles are always phiMax-phiMin [0...2\pi) +// +FUNCMATH static double phiDiff(double phiMin, double phiMax) +{ + double result; + + result = phiMax-phiMin; + + if (result < 0.0l) + result += 2.0l*M_PIl; + + return result; +} + +// +// sort phi's so that enclosed angle < \pi +// +static void sortPhi(double phi1, double phi2, double *phiMin, double *phiMax) +{ + if (phiDiff(phi1, phi2) < M_PIl) + { + *phiMin = phi1; + *phiMax = phi2; + } + else + { + *phiMin = phi2; + *phiMax = phi1; + } +} + +// +// return if angle(phi1, phi2) is bigger than \pi +// if so, the vertex lies inside the poly +// +FUNCMATH static boolean biggerThanPi(double phi1, double phi2) +{ + if (phiDiff(phi1, phi2) > M_PIl) + return true; + + return false; +} + +#define DELTAPHI (M_PIl/100.0l) // some small phi << \pi + +// +// calculate bounds for minimum angle +// +static void phiBounds(double phi1, double phi2, double *phiMin, double *phiMax) +{ + double phi1Tmp, phi2Tmp; + double psi1, psi2, psi3, psi4, psi5, psi6, psi7; // for optimization + + sortPhi(phi1, phi2, &phi1Tmp, &phi2Tmp); + phi1 = phi1Tmp; + phi2 = phi2Tmp; + + // check start condition + if (*phiMin > M_PIl || *phiMax > M_PIl) + { + *phiMin = phi1; + *phiMax = phi2; + return; + } + + // 6 cases: + // new angles inbetween phiMin, phiMax -> forget it + // new angles enclose phiMin -> set phiMin + // new angles enclose phiMax -> set phiMax + // new angles completely outside phiMin, phiMax -> leave largest area free + // new angles close the range completely! + // new angles enlarges range on both sides + + psi1 = phiDiff(*phiMin, phi1); + psi2 = phiDiff(*phiMin, phi2); + psi3 = phiDiff(*phiMax, phi1); + psi4 = phiDiff(*phiMax, phi2); + psi5 = phiDiff(*phiMin, *phiMax); + psi6 = (double)(2.0l*M_PIl - psi5); // phiDiff(*phiMax, *phiMin); + psi7 = (double)(2.0l*M_PIl - psi2); // phiDiff(phi2, *phiMin); + + // case 1 & 5! + if ((psi1 <= psi5) && (psi2 <= psi5)) + { + if (psi1 <= psi2) // case 1 + { + return; + } + else // case 5 + { + // create some artificial interval here not to get into numerical trouble + // in fact we know now the sector is completely enclosed -> base for computational optimization + *phiMax = 0.0l; + *phiMin = DELTAPHI; + return; + } + } + + // case 2 + if ((psi1 >= psi5) && (psi2 <= psi5)) + { + *phiMin = phi1; + return; + } + + // case 3 + if ((psi3 >= psi6) && (psi4 <= psi6)) + { + *phiMax = phi2; + return; + } + + // case 4 & 6 +#ifdef PARANOIA + if ((psi3 <= psi6) && (psi4 <= psi6)) // FIXME: isn't this case implicitly true anyway?? +#endif + { + if (psi3 <= psi4) //case 4 + { + if (psi3 >= psi7) + { + *phiMin = phi1; + return; + } + else + { + *phiMax = phi2; + return; + } + } + else // case 6 + { + *phiMin = phi1; + *phiMax = phi2; + return; + } + } + +#ifdef PARANOIA + CONS_Debug(DBG_RENDER, "phiMin = %f, phiMax = %f, phi1 = %f, phi2 = %f\n", *phiMin, *phiMax, phi1, phi2); + I_Error("phiBounds() out of range!\n"); +#endif +} + +// +// Check if a vertex lies inside a sector +// This works for "well-behaved" convex polygons +// If we need it mathematically correct, we need to sort the +// linedefs first so we have them in a row, then walk along the linedefs, +// but this is a bit overdone +// +static inline boolean isVertexInside(vertex_t *vertex, sector_t *sector) +{ + double xa, ya, xe, ye; + linechain_t *chain; + double phiMin, phiMax; + double phi1, phi2; + + chain = sector->sectorLines; + phiMin = phiMax = 10.0l*M_PIl; // some value > \pi + + while (chain) + { + // start and end vertex + xa = (double)chain->line->v1->x - (double)vertex->x; + ya = (double)chain->line->v1->y - (double)vertex->y; + xe = (double)chain->line->v2->x - (double)vertex->x; + ye = (double)chain->line->v2->y - (double)vertex->y; + + // angle phi of connection between the vertices and the x-axis + phi1 = atan2(ya, xa); + phi2 = atan2(ye, xe); + + // if we have just started, we can have to create start bounds for phi + + phiBounds(phi1, phi2, &phiMin, &phiMax); + chain = chain->next; + } + + return biggerThanPi(phiMin, phiMax); +} + + +#define MAXSTACK 256 // Not more than 256 polys in each other? +// +// generate a list of sectors which enclose the given sector +// +static void generateStacklist(sector_t *thisSector) +{ + size_t i, stackCnt = 0; + sector_t *locStacklist[MAXSTACK]; + sector_t *checkSector; + + for (i = 0; i < numsectors; i++) + { + checkSector = §ors[i]; + + if (checkSector == thisSector) // dont check self + continue; + + // buggy sector? + if (!thisSector->sectorLines) + continue; + + // check if an arbitrary vertex of thisSector lies inside the checkSector + if (isVertexInside(thisSector->sectorLines->line->v1, checkSector)) + { + // if so, the thisSector lies inside the checkSector + locStacklist[stackCnt] = checkSector; + stackCnt++; + + if (MAXSTACK-1 == stackCnt) // beware of the SIGSEGV! and consider terminating NULL! + break; + } + } + + thisSector->stackList = malloc(sizeof (sector_t *) * (stackCnt+1)); + if (NULL == thisSector->stackList) + { + I_Error("Out of memory error in generateStacklist()"); + } + + locStacklist[stackCnt] = NULL; // terminating NULL + + memcpy(thisSector->stackList, locStacklist, sizeof (sector_t *) * (stackCnt+1)); +} + +// +// Bubble sort the stacklist with rising lineoutlengths +// +static void sortStacklist(sector_t *sector) +{ + sector_t **list; + sector_t *sec1, *sec2; + boolean finished; + size_t i; + + list = sector->stackList; + finished = false; + + if (!*list) + return; // nothing to sort + + while (!finished) + { + i = 0; + finished = true; + + while (NULL != *(list+i+1)) + { + sec1 = *(list+i); + sec2 = *(list+i+1); + + if (sec1->lineoutLength > sec2->lineoutLength) + { + *(list+i) = sec2; + *(list+i+1) = sec1; + finished = false; + } + i++; + } + } +} + +// +// length of a line in euclidian sense +// +static double lineLength(line_t *line) +{ + double dx, dy, length; + + dx = (double) line->v1->x - (double) line->v2->x; + dy = (double) line->v1->y - (double) line->v2->y; + + length = hypot(dx, dy); + + return length; +} + + +// +// length of the sector lineout +// +static double calcLineoutLength(sector_t *sector) +{ + linechain_t *chain; + double length = 0.0L; + chain = sector->sectorLines; + + while (NULL != chain) // sum up lengths of all lines + { + length += lineLength(chain->line); + chain = chain->next; + } + return length; +} + +// +// Calculate length of the sectors lineout +// +static void calcLineouts(sector_t *sector) +{ + size_t secCount = 0; + sector_t *encSector = *(sector->stackList); + + while (NULL != encSector) + { + if (encSector->lineoutLength < 0.0L) // if length has not yet been calculated + { + encSector->lineoutLength = calcLineoutLength(encSector); + } + + secCount++; + encSector = *((sector->stackList) + secCount); + } +} + +// +// Free Stacklists of all sectors +// +static void freeStacklists(void) +{ + size_t i; + + for (i = 0; i < numsectors; i++) + { + if (sectors[i].stackList) + { + free(sectors[i].stackList); + sectors[i].stackList = NULL; + } + } +} + +// +// if more than half of the toptextures are missing +// +static boolean areToptexturesMissing(sector_t *thisSector) +{ + linechain_t *thisElem, *nextElem = thisSector->sectorLines; + sector_t *frontSector, *backSector; + size_t nomiss = 0; + side_t *sidel, *sider; + + while (nextElem) // walk through chain + { + thisElem = nextElem; + nextElem = thisElem->next; + + frontSector = thisElem->line->frontsector; + backSector = thisElem->line->backsector; + + if (frontSector == backSector) // skip damn renderer tricks here + continue; + + if (!frontSector || !backSector) + continue; + + sider = &sides[thisElem->line->sidenum[0]]; + sidel = &sides[thisElem->line->sidenum[1]]; + + if (backSector->ceilingheight < frontSector->ceilingheight) + { + if (sider->toptexture != 0) + { + nomiss++; + break; // we can stop here if decision criterium is ==0 + } + } + else if (backSector->ceilingheight > frontSector->ceilingheight) + { + if (sidel->toptexture != 0) + { + nomiss++; + break; // we can stop here if decision criterium is ==0 + } + } + } + + return nomiss == 0; +} + +// +// are more textures missing than present? +// +static boolean areBottomtexturesMissing(sector_t *thisSector) +{ + linechain_t *thisElem, *nextElem = thisSector->sectorLines; + sector_t *frontSector, *backSector; + size_t nomiss = 0; + side_t *sidel, *sider; + + while (nextElem) // walk through chain + { + thisElem = nextElem; + nextElem = thisElem->next; + + frontSector = thisElem->line->frontsector; + backSector = thisElem->line->backsector; + + if (frontSector == backSector) // skip damn renderer tricks here + continue; + + if (frontSector == NULL || backSector == NULL) + continue; + + sider = &sides[thisElem->line->sidenum[0]]; + sidel = &sides[thisElem->line->sidenum[1]]; + + if (backSector->floorheight > frontSector->floorheight) + { + if (sider->bottomtexture != 0) + { + nomiss++; + break; // we can stop here if decision criterium is ==0 + } + } + + else if (backSector->floorheight < frontSector->floorheight) + { + if (sidel->bottomtexture != 0) + { + nomiss++; + break; // we can stop here if decision criterium is ==0 + } + } + } + + // return missing >= nomiss; + return nomiss == 0; +} + +// +// check if no adjacent sector has same ceiling height +// +static boolean isCeilingFloating(sector_t *thisSector) +{ + sector_t *adjSector, *refSector = NULL, *frontSector, *backSector; + boolean floating = true; + linechain_t *thisElem, *nextElem; + + if (!thisSector) + return false; + + nextElem = thisSector->sectorLines; + + while (NULL != nextElem) // walk through chain + { + thisElem = nextElem; + nextElem = thisElem->next; + + frontSector = thisElem->line->frontsector; + backSector = thisElem->line->backsector; + + if (frontSector == thisSector) + adjSector = backSector; + else + adjSector = frontSector; + + if (!adjSector) // assume floating sectors have surrounding sectors + { + floating = false; + break; + } + + if (!refSector) + { + refSector = adjSector; + continue; + } + + // if adjacent sector has same height or more than one adjacent sector exists -> stop + if (thisSector->ceilingheight == adjSector->ceilingheight || + refSector != adjSector) + { + floating = false; + break; + } + } + + // now check for walltextures + if (floating) + { + if (!areToptexturesMissing(thisSector)) + { + floating = false; + } + } + return floating; +} + +// +// check if no adjacent sector has same ceiling height +// FIXME: throw that together with isCeilingFloating?? +// +static boolean isFloorFloating(sector_t *thisSector) +{ + sector_t *adjSector, *refSector = NULL, *frontSector, *backSector; + boolean floating = true; + linechain_t *thisElem, *nextElem; + + if (!thisSector) + return false; + + nextElem = thisSector->sectorLines; + + while (nextElem) // walk through chain + { + thisElem = nextElem; + nextElem = thisElem->next; + + frontSector = thisElem->line->frontsector; + backSector = thisElem->line->backsector; + + if (frontSector == thisSector) + adjSector = backSector; + else + adjSector = frontSector; + + if (NULL == adjSector) // assume floating sectors have surrounding sectors + { + floating = false; + break; + } + + if (NULL == refSector) + { + refSector = adjSector; + continue; + } + + // if adjacent sector has same height or more than one adjacent sector exists -> stop + if (thisSector->floorheight == adjSector->floorheight || + refSector != adjSector) + { + floating = false; + break; + } + } + + // now check for walltextures + if (floating) + { + if (!areBottomtexturesMissing(thisSector)) + { + floating = false; + } + } + return floating; +} + +// +// estimate ceilingheight according to height of adjacent sector +// +static fixed_t estimateCeilHeight(sector_t *thisSector) +{ + sector_t *adjSector; + + if (!thisSector || + !thisSector->sectorLines || + !thisSector->sectorLines->line) + return 0; + + adjSector = thisSector->sectorLines->line->frontsector; + if (adjSector == thisSector) + adjSector = thisSector->sectorLines->line->backsector; + + if (!adjSector) + return 0; + + return adjSector->ceilingheight; +} + +// +// estimate ceilingheight according to height of adjacent sector +// +static fixed_t estimateFloorHeight(sector_t *thisSector) +{ + sector_t *adjSector; + + if (!thisSector || + !thisSector->sectorLines || + !thisSector->sectorLines->line) + return 0; + + adjSector = thisSector->sectorLines->line->frontsector; + if (adjSector == thisSector) + adjSector = thisSector->sectorLines->line->backsector; + + if (NULL == adjSector) + return 0; + + return adjSector->floorheight; +} + +#define CORRECT_FLOAT_EXPERIMENTAL + +// -------------------------------------------------------------------------- +// Some levels have missing sidedefs, which produces HOM, so lets try to compensate for that +// and some levels have deep water trick, invisible staircases etc. +// -------------------------------------------------------------------------- +// FIXME: put some nice default texture in legacy.dat and use it +void HWR_CorrectSWTricks(void) +{ + size_t i; + size_t k; + line_t *ld; + side_t *sidel = NULL, *sider; + sector_t *secl, *secr; + sector_t **sectorList; + sector_t *outSector; + + if ((0 == cv_grcorrecttricks.value)) + return; + + // determine lines for sectors + for (i = 0; i < numlines; i++) + { + ld = &lines[i]; + secr = ld->frontsector; + secl = ld->backsector; + + if (secr == secl) + { + secr->pseudoSector = true; // special renderer trick? + addLineToChain(secr, ld); + } + else + { + addLineToChain(secr, ld); + addLineToChain(secl, ld); + } + } + + // preprocessing + for (i = 0; i < numsectors; i++) + { + sector_t *checkSector; + + checkSector = §ors[i]; + + // identify real pseudosectors first + if (checkSector->pseudoSector) + { + if (!isPSectorValid(checkSector)) // drop invalid pseudo sectors + { + checkSector->pseudoSector = false; + } + } + + // determine enclosing sectors for pseudosectors ... used later + if (checkSector->pseudoSector) + { + generateStacklist(checkSector); + calcLineouts(checkSector); + sortStacklist(checkSector); + } + } + + // set virtual floor heights for pseudo sectors + // required for deep water effect e.g. + for (i = 0; i < numsectors; i++) + { + if (sectors[i].pseudoSector) + { + sectorList = sectors[i].stackList; + k = 0; + while (*(sectorList+k)) + { + outSector = *(sectorList+k); + if (!outSector->pseudoSector) + { + sectors[i].virtualFloorheight = outSector->floorheight; + sectors[i].virtualCeilingheight = outSector->ceilingheight; + break; + } + k++; + } + if (*(sectorList+k) == NULL) // sorry, did not work :( + { + sectors[i].virtualFloorheight = sectors[i].floorheight; + sectors[i].virtualCeilingheight = sectors[i].ceilingheight; + } + } + } +#ifdef CORRECT_FLOAT_EXPERIMENTAL + // correct ceiling/floor heights of totally floating sectors + for (i = 0; i < numsectors; i++) + { + sector_t *floatSector; + + floatSector = §ors[i]; + + // correct height of floating sectors + if (isCeilingFloating(floatSector)) + { + fixed_t corrheight; + + corrheight = estimateCeilHeight(floatSector); + floatSector->virtualCeilingheight = corrheight; + floatSector->virtualCeiling = true; + } + if (isFloorFloating(floatSector)) + { + fixed_t corrheight; + + corrheight = estimateFloorHeight(floatSector); + floatSector->virtualFloorheight = corrheight; + floatSector->virtualFloor = true; + } + } +#endif + + // now for the missing textures + for (i = 0; i < numlines; i++) + { + ld = &lines[i]; + sider = &sides[ld->sidenum[0]]; + if (ld->sidenum[1] != 0xffff) + sidel = &sides[ld->sidenum[1]]; + + secr = ld->frontsector; + secl = ld->backsector; + + if (secr == secl) // special renderer trick + continue; // we cant correct missing textures here + + if (secl) // only if there is a backsector + { + if (secr->pseudoSector || secl->pseudoSector) + continue; + if (!secr->virtualFloor && !secl->virtualFloor) + { + if (secl->floorheight > secr->floorheight) + { + // now check if r-sidedef is correct + if (sider->bottomtexture == 0) + { + if (sider->midtexture == 0) + sider->bottomtexture = R_TextureNumForName("REDWALL"); // Tails + else + sider->bottomtexture = sider->midtexture; + } + } + else if (secl->floorheight < secr->floorheight) + { + // now check if l-sidedef is correct + if (sidel->bottomtexture == 0) + { + if (sidel->midtexture == 0) + sidel->bottomtexture = R_TextureNumForName("REDWALL"); // Tails + else + sidel->bottomtexture = sidel->midtexture; + } + } + } + + if (!secr->virtualCeiling && !secl->virtualCeiling) + { + if (secl->ceilingheight < secr->ceilingheight) + { + // now check if r-sidedef is correct + if (sider->toptexture == 0) + { + if (sider->midtexture == 0) + sider->toptexture = 0; // Tails // When this was REDWALL it was causing issues in the sky sometimes + else + sider->toptexture = sider->midtexture; + } + } + else if (secl->ceilingheight > secr->ceilingheight) + { + // now check if l-sidedef is correct + if (sidel->toptexture == 0) + { + if (sidel->midtexture == 0) + sidel->toptexture = 0; // Tails // When this was REDWALL it was causing issues in the sky sometimes + else + sidel->toptexture = sidel->midtexture; + } + } + } + } // if (NULL != secl) + } // for (i = 0; i < numlines; i++) + + // release all linechains + releaseLineChains(); + freeStacklists(); +} + +#endif // HWRENDER diff --git a/src/hardware/hws_data.h b/src/hardware/hws_data.h new file mode 100644 index 000000000..9e2d0547e --- /dev/null +++ b/src/hardware/hws_data.h @@ -0,0 +1,123 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright (C) 2005 by SRB2 Jr. Team. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +//----------------------------------------------------------------------------- +/// \file +/// \brief 3D sound definitions + +#ifndef __HWS_DATA_H__ +#define __HWS_DATA_H__ + +#define NORMAL_SEP 128 + +// abuse? +#define STATIC_SOURCES_NUM 6 // Total number of static sources + +#define MIN_DISTANCE 160.0f +#define MAX_DISTANCE 1200.0f + +typedef struct source_pos_s +{ + double x; + double y; + double z; +} source_pos_t; + +typedef struct source3D_pos_s +{ + float x; + float y; + float z; + //float angle; + float momx; + float momy; + float momz; + +} source3D_pos_t; + + +enum {NORMAL_PITCH = 128}; + +/*typedef struct source2D_data_s +{ + INT32 volume; + INT32 sep; + +} source2D_data_t;*/ + + +// General 3D sound source description +typedef struct source3D_data_s +{ + float min_distance; // + float max_distance; // + INT32 head_relative; // + INT32 permanent; // + source3D_pos_t pos; // source position in 3D + +} source3D_data_t; + + +// Sound data +typedef struct sfx_data_s +{ + size_t length; + void *data; + INT32 priority; + INT32 sep; // Only when source is 2D sound +} sfx_data_t; + + +// Sound cone (for 3D sources) +typedef struct cone_def_s +{ + float inner; + float outer; + INT32 outer_gain; + /*float f_angle; + float h_angle;*/ +} cone_def_t; + + +typedef struct listener_data_s +{ + // Listener position + double x; + double y; + double z; + + // Listener front and head orientation (degrees) + double f_angle; + double h_angle; + + // Listener momentums + double momx; + double momy; + double momz; +} listener_data_t; + +typedef struct snddev_s +{ + INT32 sample_rate; + INT32 bps; + size_t numsfxs; + +// Windows specific data +#if defined (_WIN32) && !defined (_XBOX) + UINT32 cooplevel; + HWND hWnd; +#endif +} snddev_t; + +#endif //__HWS_DATA_H__ diff --git a/src/hardware/r_minigl/r_minigl.c b/src/hardware/r_minigl/r_minigl.c new file mode 100644 index 000000000..b2482a552 --- /dev/null +++ b/src/hardware/r_minigl/r_minigl.c @@ -0,0 +1,33 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright (C) 1998-2000 by DooM Legacy Team. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +//----------------------------------------------------------------------------- +/// \file +/// \brief MiniGL API for Doom Legacy + + +// tell r_opengl.cpp to compile for MiniGL Drivers +#define MINI_GL_COMPATIBILITY + +// tell r_opengl.cpp to compile for ATI Rage Pro OpenGL driver +//#define ATI_RAGE_PRO_COMPATIBILITY + +#define DRIVER_STRING "HWRAPI Init(): SRB2 MiniGL renderer" + +// Include this at end +#include "../r_opengl/r_opengl.c" +#include "../r_opengl/ogl_win.c" + +// That's all ;-) +// Just, be sure to do the right changes in r_opengl.cpp diff --git a/src/hardware/r_minigl/r_minigl.dev b/src/hardware/r_minigl/r_minigl.dev new file mode 100644 index 000000000..edf725ac5 --- /dev/null +++ b/src/hardware/r_minigl/r_minigl.dev @@ -0,0 +1,89 @@ +[Project] +FileName=r_minigl.dev +Name=r_minigl +Ver=1 +IsCpp=1 +Type=3 +Compiler=-D_M_IX86=500_@@_-Wall_@@_-D_WINDOWS_@@_-DUSE_WGL_SWAP_@@_-Os_@@_-fomit-frame-pointer_@@_ +CppCompiler= +Includes= +Linker=--def ../r_mingw.def_@@_-lgdi32_@@_ +Libs= +UnitCount=4 +Folders= +ObjFiles= +PrivateResource= +ResourceIncludes= +MakeIncludes= +Icon= +ExeOutput=C:\srb2demo2 +ObjectOutput=..\..\..\objs\Mingw\r_minigl +OverrideOutput=1 +OverrideOutputName=r_minigl.dll +HostApplication= +CommandLine= +IncludeVersionInfo=0 +SupportXPThemes=0 +CompilerSet=0 +CompilerSettings=00000000000000000111d0 +UseCustomMakefile=0 +CustomMakefile= + +[Unit1] +FileName=..\r_opengl\ogl_win.c +Folder= +Compile=0 +CompileCpp=0 +Link=0 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd=$(CC) -c ogl_win.c -o ../../../objs/Mingw/r_minigl/ogl_win.o $(CFLAGS) + +[Unit2] +FileName=..\r_opengl\r_opengl.c +Folder= +Compile=0 +CompileCpp=0 +Link=0 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd=$(CC) -c r_opengl.c -o ../../../objs/Mingw/r_minigl/r_opengl.o $(CFLAGS) + +[Unit3] +FileName=..\r_opengl\r_opengl.h +Folder= +Compile=1 +CompileCpp=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[VersionInfo] +Major=0 +Minor=1 +Release=1 +Build=1 +LanguageID=1033 +CharsetID=1252 +CompanyName= +FileVersion=0.1 +FileDescription=Developed using the Dev-C++ IDE +InternalName= +LegalCopyright= +LegalTrademarks= +OriginalFilename=r_opengl.exe +ProductName=r_opengl +ProductVersion=0.1 +AutoIncBuildNr=0 + +[Unit4] +FileName=r_minigl.c +CompileCpp=0 +Folder=r_minigl +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd=$(CC) -c r_minigl.c -o ../../../objs/Mingw/r_minigl/r_minigl.o $(CFLAGS) + diff --git a/src/hardware/r_minigl/r_minigl.dsp b/src/hardware/r_minigl/r_minigl.dsp new file mode 100644 index 000000000..686ca35a3 --- /dev/null +++ b/src/hardware/r_minigl/r_minigl.dsp @@ -0,0 +1,103 @@ +# Microsoft Developer Studio Project File - Name="r_minigl" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=r_minigl - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "r_minigl.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "r_minigl.mak" CFG="r_minigl - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "r_minigl - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "r_minigl - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "r_minigl - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "..\..\..\objs\Release" +# PROP BASE Intermediate_Dir "..\..\..\objs\Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "..\..\..\bin\VC\Release\r_minigl" +# PROP Intermediate_Dir "..\..\..\objs\VC\Release\r_minigl" +# PROP Ignore_Export_Lib 1 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "R_MINIGL_EXPORTS" /YX /FD /c +# ADD CPP /nologo /G5 /MT /W3 /GX /Zi /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "__WIN32__" /D "__MSC__" /FR /FD /c +# SUBTRACT CPP /YX +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x80c /d "NDEBUG" +# ADD RSC /l 0x40c /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 +# ADD LINK32 user32.lib gdi32.lib /nologo /dll /pdb:"..\..\..\bin\VC\Release\r_minigl.pdb" /machine:I386 /out:"..\..\..\bin\VC\Release\r_minigl.dll" +# SUBTRACT LINK32 /pdb:none /debug + +!ELSEIF "$(CFG)" == "r_minigl - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "..\..\..\objs\Debug" +# PROP BASE Intermediate_Dir "..\..\..\objs\Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "..\..\..\bin\VC\Debug\r_minigl" +# PROP Intermediate_Dir "..\..\..\objs\VC\Debug\r_minigl" +# PROP Ignore_Export_Lib 1 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "R_MINIGL_EXPORTS" /YX /FD /GZ /c +# ADD CPP /nologo /MTd /W4 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "__WIN32__" /D "__MSC__" /D "_MBCS" /D "_USRDLL" /D "R_MINIGL_EXPORTS" /FR /FD /GZ /c +# SUBTRACT CPP /YX +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x80c /d "_DEBUG" +# ADD RSC /l 0x40c /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 ouser32.lib gdi32.lib /nologo /dll /pdb:"..\..\..\bin\VC\Debug\r_minigl.pdb" /debug /machine:I386 /out:"..\..\..\bin\VC\Debug\r_minigl.dll" /pdbtype:sept +# SUBTRACT LINK32 /pdb:none + +!ENDIF + +# Begin Target + +# Name "r_minigl - Win32 Release" +# Name "r_minigl - Win32 Debug" +# Begin Source File + +SOURCE=.\r_minigl.c +# End Source File +# Begin Source File + +SOURCE=..\r_opengl\r_opengl.h +# End Source File +# End Target +# End Project diff --git a/src/hardware/r_opengl/ogl_win.c b/src/hardware/r_opengl/ogl_win.c new file mode 100644 index 000000000..daf37fe29 --- /dev/null +++ b/src/hardware/r_opengl/ogl_win.c @@ -0,0 +1,600 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright (C) 1998-2000 by DooM Legacy Team. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +//----------------------------------------------------------------------------- +/// \file +/// \brief Windows specific part of the OpenGL API for Doom Legacy +/// +/// TODO: +/// - check if windowed mode works +/// - support different pixel formats + + +#if defined (_WIN32) + +//#define WIN32_LEAN_AND_MEAN +#define RPC_NO_WINDOWS_H +#include +#include +#undef GETTEXT +#include "r_opengl.h" + + +// ************************************************************************** +// GLOBALS +// ************************************************************************** + +#ifdef DEBUG_TO_FILE +static unsigned long nb_frames = 0; +static clock_t my_clock; +FILE *logstream; +#endif + +static HDC hDC = NULL; // the window's device context +static HGLRC hGLRC = NULL; // the OpenGL rendering context +static HWND hWnd = NULL; +static BOOL WasFullScreen = FALSE; +static void UnSetRes(void); + +#ifdef USE_WGL_SWAP +PFNWGLEXTSWAPCONTROLPROC wglSwapIntervalEXT = NULL; +#endif + +PFNglClear pglClear; +PFNglGetIntegerv pglGetIntegerv; +PFNglGetString pglGetString; + +#define MAX_VIDEO_MODES 32 +static vmode_t video_modes[MAX_VIDEO_MODES]; +INT32 oglflags = 0; + +// ************************************************************************** +// FUNCTIONS +// ************************************************************************** + +// -----------------+ +// APIENTRY DllMain : DLL Entry Point, +// : open/close debug log +// Returns : +// -----------------+ +BOOL WINAPI DllMain(HINSTANCE hinstDLL, // handle to DLL module + DWORD fdwReason, // reason for calling function + LPVOID lpvReserved) // reserved +{ + // Perform actions based on the reason for calling. + UNREFERENCED_PARAMETER(lpvReserved); + switch (fdwReason) + { + case DLL_PROCESS_ATTACH: + // Initialize once for each new process. + // Return FALSE to fail DLL load. +#ifdef DEBUG_TO_FILE + logstream = fopen("ogllog.txt", "wt"); + if (logstream == NULL) + return FALSE; +#endif + DisableThreadLibraryCalls(hinstDLL); + break; + + case DLL_THREAD_ATTACH: + // Do thread-specific initialization. + break; + + case DLL_THREAD_DETACH: + // Do thread-specific cleanup. + break; + + case DLL_PROCESS_DETACH: + // Perform any necessary cleanup. +#ifdef DEBUG_TO_FILE + if (logstream) + { + fclose(logstream); + logstream = NULL; + } +#endif + break; + } + + return TRUE; // Successful DLL_PROCESS_ATTACH. +} + +#ifdef STATIC_OPENGL +#define pwglGetProcAddress wglGetProcAddress; +#define pwglCreateContext wglCreateContext; +#define pwglDeleteContext wglDeleteContext; +#define pwglMakeCurrent wglMakeCurrent; +#else +static HMODULE OGL32, GLU32; +typedef void *(WINAPI *PFNwglGetProcAddress) (const char *); +static PFNwglGetProcAddress pwglGetProcAddress; +typedef HGLRC (WINAPI *PFNwglCreateContext) (HDC hdc); +static PFNwglCreateContext pwglCreateContext; +typedef BOOL (WINAPI *PFNwglDeleteContext) (HGLRC hglrc); +static PFNwglDeleteContext pwglDeleteContext; +typedef BOOL (WINAPI *PFNwglMakeCurrent) (HDC hdc, HGLRC hglrc); +static PFNwglMakeCurrent pwglMakeCurrent; +#endif + +#ifndef STATIC_OPENGL +void *GetGLFunc(const char *proc) +{ + void *func = NULL; + if (strncmp(proc, "glu", 3) == 0) + { + if (GLU32) + func = GetProcAddress(GLU32, proc); + else + return NULL; + } + if (pwglGetProcAddress) + func = pwglGetProcAddress(proc); + if (!func) + func = GetProcAddress(OGL32, proc); + return func; +} +#endif + +boolean LoadGL(void) +{ +#ifndef STATIC_OPENGL + OGL32 = LoadLibrary("OPENGL32.DLL"); + + if (!OGL32) + return 0; + + GLU32 = LoadLibrary("GLU32.DLL"); + + pwglGetProcAddress = GetGLFunc("wglGetProcAddress"); + pwglCreateContext = GetGLFunc("wglCreateContext"); + pwglDeleteContext = GetGLFunc("wglDeleteContext"); + pwglMakeCurrent = GetGLFunc("wglMakeCurrent"); +#endif + return SetupGLfunc(); +} + +// -----------------+ +// SetupPixelFormat : Set the device context's pixel format +// Note : Because we currently use only the desktop's BPP format, all the +// : video modes in Doom Legacy OpenGL are of the same BPP, thus the +// : PixelFormat is set only once. +// : Setting the pixel format more than once on the same window +// : doesn't work. (ultimately for different pixel formats, we +// : should close the window, and re-create it) +// -----------------+ +int SetupPixelFormat(INT32 WantColorBits, INT32 WantStencilBits, INT32 WantDepthBits) +{ + static DWORD iLastPFD = 0; + INT32 nPixelFormat; + PIXELFORMATDESCRIPTOR pfd = + { + sizeof (PIXELFORMATDESCRIPTOR), // size + 1, // version + PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, + PFD_TYPE_RGBA, // color type + 32 /*WantColorBits*/, // cColorBits : prefered color depth + 0, 0, // cRedBits, cRedShift + 0, 0, // cGreenBits, cGreenShift + 0, 0, // cBlueBits, cBlueShift + 0, 0, // cAlphaBits, cAlphaShift + 0, // cAccumBits + 0, 0, 0, 0, // cAccum Red/Green/Blue/Alpha Bits + 0, // cDepthBits (0,16,24,32) + 0, // cStencilBits + 0, // cAuxBuffers + PFD_MAIN_PLANE, // iLayerType + 0, // reserved, must be zero + 0, 0, 0, // dwLayerMask, dwVisibleMask, dwDamageMask + }; + + DWORD iPFD = (WantColorBits<<16) | (WantStencilBits<<8) | WantDepthBits; + + pfd.cDepthBits = (BYTE)WantDepthBits; + pfd.cStencilBits = (BYTE)WantStencilBits; + + if (iLastPFD) + { + DBG_Printf("WARNING : SetPixelFormat() called twise not supported by all drivers !\n"); + } + + // set the pixel format only if different than the current + if (iPFD == iLastPFD) + return 2; + else + iLastPFD = iPFD; + + DBG_Printf("SetupPixelFormat() - %d ColorBits - %d StencilBits - %d DepthBits\n", + WantColorBits, WantStencilBits, WantDepthBits); + + nPixelFormat = ChoosePixelFormat(hDC, &pfd); + + if (nPixelFormat == 0) + DBG_Printf("ChoosePixelFormat() FAILED\n"); + + if (SetPixelFormat(hDC, nPixelFormat, &pfd) == 0) + { + DBG_Printf("SetPixelFormat() FAILED\n"); + return 0; + } + + return 1; +} + + +// -----------------+ +// SetRes : Set a display mode +// Notes : pcurrentmode is actually not used +// -----------------+ +static INT32 WINAPI SetRes(viddef_t *lvid, vmode_t *pcurrentmode) +{ + LPCSTR renderer; + BOOL WantFullScreen = !(lvid->u.windowed); //(lvid->u.windowed ? 0 : CDS_FULLSCREEN); + + UNREFERENCED_PARAMETER(pcurrentmode); + DBG_Printf ("SetMode(): %dx%d %d bits (%s)\n", + lvid->width, lvid->height, lvid->bpp*8, + WantFullScreen ? "fullscreen" : "windowed"); + + hWnd = lvid->WndParent; + + // BP : why flush texture ? + // if important flush also the first one (white texture) and restore it ! + Flush(); // Flush textures. + +// TODO: if not fullscreen, skip display stuff and just resize viewport stuff ... + + // Exit previous mode + //if (hGLRC) //Hurdler: TODO: check if this is valid + // UnSetRes(); + if (WasFullScreen) + ChangeDisplaySettings(NULL, CDS_FULLSCREEN); //switch in and out of fullscreen + + // Change display settings. + if (WantFullScreen) + { + DEVMODE dm; + ZeroMemory(&dm, sizeof (dm)); + dm.dmSize = sizeof (dm); + dm.dmPelsWidth = lvid->width; + dm.dmPelsHeight = lvid->height; + dm.dmBitsPerPel = lvid->bpp*8; + dm.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL; + if (ChangeDisplaySettings(&dm, CDS_TEST) != DISP_CHANGE_SUCCESSFUL) + return -2; + if (ChangeDisplaySettings(&dm, CDS_FULLSCREEN) !=DISP_CHANGE_SUCCESSFUL) + return -3; + + SetWindowLong(hWnd, GWL_STYLE, WS_POPUP|WS_VISIBLE); + // faB : book says to put these, surely for windowed mode + //WS_CLIPCHILDREN|WS_CLIPSIBLINGS); + SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, lvid->width, lvid->height, SWP_NOACTIVATE|SWP_NOZORDER); + } + else + { + RECT bounds; + INT32 x, y; + INT32 w = lvid->width, h = lvid->height; + GetWindowRect(hWnd, &bounds); + bounds.right = bounds.left+w; + bounds.bottom = bounds.top+h; + AdjustWindowRectEx(&bounds, GetWindowLong(hWnd, GWL_STYLE), (GetMenu(hWnd) != NULL), 0); + w = bounds.right-bounds.left; + h = bounds.bottom-bounds.top; + x = (GetSystemMetrics(SM_CXSCREEN)-w)/2; + y = (GetSystemMetrics(SM_CYSCREEN)-h)/2; + SetWindowPos(hWnd, NULL, x, y, w, h, SWP_NOACTIVATE|SWP_NOZORDER); + } + + if (!hDC) + hDC = GetDC(hWnd); + if (!hDC) + { + DBG_Printf("GetDC() FAILED\n"); + return 0; + } + + { + INT32 res; + + // Set res. + res = SetupPixelFormat(lvid->bpp*8, 0, 16); + + if (res == 0) + return 0; + else if (res == 1) + { + // Exit previous mode + if (hGLRC) + UnSetRes(); + hGLRC = pwglCreateContext(hDC); + if (!hGLRC) + { + DBG_Printf("pwglCreateContext() FAILED\n"); + return 0; + } + if (!pwglMakeCurrent(hDC, hGLRC)) + { + DBG_Printf("wglMakeCurrent() FAILED\n"); + return 0; + } + } + } + + gl_extensions = pglGetString(GL_EXTENSIONS); + // Get info and extensions. + //BP: why don't we make it earlier ? + //Hurdler: we cannot do that before intialising gl context + renderer = (LPCSTR)pglGetString(GL_RENDERER); + DBG_Printf("Vendor : %s\n", pglGetString(GL_VENDOR)); + DBG_Printf("Renderer : %s\n", renderer); + DBG_Printf("Version : %s\n", pglGetString(GL_VERSION)); + DBG_Printf("Extensions : %s\n", gl_extensions); + + // BP: disable advenced feature that don't work on somes hardware + // Hurdler: Now works on G400 with bios 1.6 and certified drivers 6.04 + if (strstr(renderer, "810")) oglflags |= GLF_NOZBUFREAD; + DBG_Printf("oglflags : 0x%X\n", oglflags); + +#ifdef USE_PALETTED_TEXTURE + if (isExtAvailable("GL_EXT_paletted_texture",gl_extensions)) + glColorTableEXT = GetGLFunc("glColorTableEXT"); + else + glColorTableEXT = NULL; +#endif + +#ifdef USE_WGL_SWAP + if (isExtAvailable("WGL_EXT_swap_control",gl_extensions)) + wglSwapIntervalEXT = GetGLFunc("wglSwapIntervalEXT"); + else + wglSwapIntervalEXT = NULL; +#endif + + if (isExtAvailable("GL_EXT_texture_filter_anisotropic",gl_extensions)) + pglGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maximumAnisotropy); + else + maximumAnisotropy = 0; + + + screen_depth = (GLbyte)(lvid->bpp*8); + if (screen_depth > 16) + textureformatGL = GL_RGBA; + else + textureformatGL = GL_RGB5_A1; + + SetModelView(lvid->width, lvid->height); + SetStates(); + // we need to clear the depth buffer. Very important!!! + pglClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); + + lvid->buffer = NULL; // unless we use the software view + lvid->direct = NULL; // direct access to video memory, old DOS crap + + WasFullScreen = WantFullScreen; + + return 1; // on renvoie une valeur pour dire que cela s'est bien pass� +} + + +// -----------------+ +// UnSetRes : Restore the original display mode +// -----------------+ +static void UnSetRes(void) +{ + DBG_Printf("UnSetRes()\n"); + + pwglMakeCurrent(hDC, NULL); + pwglDeleteContext(hGLRC); + hGLRC = NULL; + if (WasFullScreen) + ChangeDisplaySettings(NULL, CDS_FULLSCREEN); +} + + +// -----------------+ +// GetModeList : Return the list of available display modes. +// Returns : pvidmodes - points to list of detected OpenGL video modes +// : numvidmodes - number of detected OpenGL video modes +// -----------------+ +EXPORT void HWRAPI(GetModeList) (vmode_t** pvidmodes, INT32 *numvidmodes) +{ + INT32 i; + +#if 1 + INT32 iMode; +/* + faB test code + + Commented out because there might be a problem with combo (Voodoo2 + other card), + we need to get the 3D card's display modes only. +*/ + (*pvidmodes) = &video_modes[0]; + + // Get list of device modes + for (i = 0,iMode = 0; iMode < MAX_VIDEO_MODES; i++) + { + DEVMODE Tmp; + ZeroMemory(&Tmp, sizeof (Tmp)); + Tmp.dmSize = sizeof (Tmp); + if (!EnumDisplaySettings(NULL, i, &Tmp)) + break; + + // add video mode + if (Tmp.dmBitsPerPel == 16 && + (iMode == 0 || ! + (Tmp.dmPelsWidth == video_modes[iMode-1].width && + Tmp.dmPelsHeight == video_modes[iMode-1].height) + ) + ) + { + video_modes[iMode].pnext = &video_modes[iMode+1]; + video_modes[iMode].windowed = 0; // fullscreen is the default + video_modes[iMode].misc = 0; + video_modes[iMode].name = malloc(12 * sizeof (CHAR)); + sprintf(video_modes[iMode].name, "%dx%d", (INT32)Tmp.dmPelsWidth, (INT32)Tmp.dmPelsHeight); + DBG_Printf ("Mode: %s\n", video_modes[iMode].name); + video_modes[iMode].width = Tmp.dmPelsWidth; + video_modes[iMode].height = Tmp.dmPelsHeight; + video_modes[iMode].bytesperpixel = Tmp.dmBitsPerPel/8; + video_modes[iMode].rowbytes = Tmp.dmPelsWidth * video_modes[iMode].bytesperpixel; + video_modes[iMode].pextradata = NULL; + video_modes[iMode].setmode = SetRes; + iMode++; + } + } + (*numvidmodes) = iMode; +#else + + // classic video modes (fullscreen/windowed) + // Added some. Tails + INT32 res[][2] = { + { 320, 200}, + { 320, 240}, + { 400, 300}, + { 512, 384}, + { 640, 400}, + { 640, 480}, + { 800, 600}, + { 960, 600}, + {1024, 768}, + {1152, 864}, + {1280, 800}, + {1280, 960}, + {1280,1024}, + {1600,1000}, + {1680,1050}, + {1920,1200}, +}; + + HDC bpphdc; + INT32 iBitsPerPel; + + DBG_Printf ("HWRAPI GetModeList()\n"); + + bpphdc = GetDC(NULL); // on obtient le bpp actuel + iBitsPerPel = GetDeviceCaps(bpphdc, BITSPIXEL); + + ReleaseDC(NULL, bpphdc); + + (*pvidmodes) = &video_modes[0]; + (*numvidmodes) = sizeof (res) / sizeof (res[0]); + for (i = 0; i < (*numvidmodes); i++) + { + video_modes[i].pnext = &video_modes[i+1]; + video_modes[i].windowed = 0; // fullscreen is the default + video_modes[i].misc = 0; + video_modes[i].name = malloc(12 * sizeof (CHAR)); + sprintf(video_modes[i].name, "%dx%d", res[i][0], res[i][1]); + DBG_Printf ("Mode: %s\n", video_modes[i].name); + video_modes[i].width = res[i][0]; + video_modes[i].height = res[i][1]; + video_modes[i].bytesperpixel = iBitsPerPel/8; + video_modes[i].rowbytes = res[i][0] * video_modes[i].bytesperpixel; + video_modes[i].pextradata = NULL; + video_modes[i].setmode = SetRes; + } +#endif + video_modes[(*numvidmodes)-1].pnext = NULL; +} + + +// -----------------+ +// Shutdown : Shutdown OpenGL, restore the display mode +// -----------------+ +EXPORT void HWRAPI(Shutdown) (void) +{ +#ifdef DEBUG_TO_FILE + long nb_centiemes; + + DBG_Printf ("HWRAPI Shutdown()\n"); + nb_centiemes = ((clock()-my_clock)*100)/CLOCKS_PER_SEC; + DBG_Printf("Nb frames: %li; Nb sec: %2.2f -> %2.1f fps\n", + nb_frames, nb_centiemes/100.0f, (100*nb_frames)/(double)nb_centiemes); +#endif + + Flush(); + + // Exit previous mode + if (hGLRC) + UnSetRes(); + + if (hDC) + { + ReleaseDC(hWnd, hDC); + hDC = NULL; + } + FreeLibrary(GLU32); + FreeLibrary(OGL32); + DBG_Printf ("HWRAPI Shutdown(DONE)\n"); +} + +// -----------------+ +// FinishUpdate : Swap front and back buffers +// -----------------+ +EXPORT void HWRAPI(FinishUpdate) (INT32 waitvbl) +{ +#ifdef USE_WGL_SWAP + static INT32 oldwaitvbl = 0; +#else + UNREFERENCED_PARAMETER(waitvbl); +#endif + // DBG_Printf ("FinishUpdate()\n"); +#ifdef DEBUG_TO_FILE + if ((++nb_frames)==2) // on ne commence pas � la premi�re frame + my_clock = clock(); +#endif + +#ifdef USE_WGL_SWAP + if (oldwaitvbl != waitvbl && wglSwapIntervalEXT) + wglSwapIntervalEXT(waitvbl); + oldwaitvbl = waitvbl; +#endif + + SwapBuffers(hDC); +} + + +// -----------------+ +// SetPalette : Set the color lookup table for paletted textures +// : in OpenGL, we store values for conversion of paletted graphics when +// : they are downloaded to the 3D card. +// -----------------+ +EXPORT void HWRAPI(SetPalette) (RGBA_t *pal, RGBA_t *gamma) +{ + INT32 i; + + for (i = 0; i < 256; i++) + { + myPaletteData[i].s.red = (UINT8)MIN((pal[i].s.red*gamma->s.red)/127, 255); + myPaletteData[i].s.green = (UINT8)MIN((pal[i].s.green*gamma->s.green)/127, 255); + myPaletteData[i].s.blue = (UINT8)MIN((pal[i].s.blue*gamma->s.blue)/127, 255); + myPaletteData[i].s.alpha = pal[i].s.alpha; + } +#ifdef USE_PALETTED_TEXTURE + if (glColorTableEXT) + { + for (i = 0; i < 256; i++) + { + palette_tex[3*i+0] = pal[i].s.red; + palette_tex[3*i+1] = pal[i].s.green; + palette_tex[3*i+2] = pal[i].s.blue; + } + glColorTableEXT(GL_TEXTURE_2D, GL_RGB8, 256, GL_RGB, GL_UNSIGNED_BYTE, palette_tex); + } +#endif + // on a chang� de palette, il faut recharger toutes les textures + Flush(); +} + +#endif diff --git a/src/hardware/r_opengl/r_opengl-vc10.vcxproj b/src/hardware/r_opengl/r_opengl-vc10.vcxproj new file mode 100644 index 000000000..b1bf2ee03 --- /dev/null +++ b/src/hardware/r_opengl/r_opengl-vc10.vcxproj @@ -0,0 +1,288 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + r_opengl + {51137D5C-4E81-4955-AACF-EA3092006051} + r_opengl + + + + DynamicLibrary + false + + + DynamicLibrary + false + + + DynamicLibrary + false + + + DynamicLibrary + false + + + + + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>10.0.30319.1 + .\..\..\..\bin\VC10\$(Platform)\$(Configuration)\ + .\..\..\..\objs\VC10\$(Platform)\$(Configuration)\r_opengl\ + true + true + .\..\..\..\bin\VC10\$(Platform)\$(Configuration)\ + .\..\..\..\objs\VC10\$(Platform)\$(Configuration)\r_opengl\ + true + true + .\..\..\..\bin\VC10\$(Platform)\$(Configuration)\ + .\..\..\..\objs\VC10\$(Platform)\$(Configuration)\r_opengl\ + true + false + .\..\..\..\bin\VC10\$(Platform)\$(Configuration)\ + .\..\..\..\objs\VC10\$(Platform)\$(Configuration)\r_opengl\ + true + false + + + + _DEBUG;%(PreprocessorDefinitions) + true + true + Win32 + .\..\..\..\bin\VC10\$(Platform)\$(Configuration)\r_opengl\r_opengl.tlb + + + + + Disabled + _DEBUG;WIN32;_WINDOWS;__WIN32__;__MSC__;USE_WGL_SWAP;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + EnableFastChecks + MultiThreadedDebug + $(IntDir) + $(IntDir)r_opengl.pdb + true + Level4 + true + EditAndContinue + CompileAsC + + + _DEBUG;%(PreprocessorDefinitions) + 0x0409 + + + $(OutDir)r_opengl.dll + true + true + $(OutDir)r_opengl.pdb + false + + + $(IntDir)r_opengl.lib + MachineX86 + + + true + $(OutDir)r_opengl.bsc + + + + + _DEBUG;%(PreprocessorDefinitions) + true + true + X64 + .\..\..\..\bin\VC10\$(Platform)\$(Configuration)\r_opengl\r_opengl.tlb + + + + + Disabled + _DEBUG;WIN32;_WINDOWS;__WIN32__;__MSC__;USE_WGL_SWAP;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + EnableFastChecks + MultiThreadedDebug + $(IntDir) + $(IntDir)r_opengl.pdb + true + Level4 + true + ProgramDatabase + CompileAsC + + + _DEBUG;%(PreprocessorDefinitions) + 0x0409 + + + $(OutDir)r_opengl.dll + true + true + $(OutDir)r_opengl.pdb + false + + + $(IntDir)r_opengl.lib + MachineX64 + + + true + $(OutDir)r_opengl.bsc + + + + + NDEBUG;%(PreprocessorDefinitions) + true + true + Win32 + .\..\..\..\bin\VC10\$(Platform)\$(Configuration)\r_opengl\r_opengl.tlb + + + + + /MP %(AdditionalOptions) + MaxSpeed + OnlyExplicitInline + NDEBUG;WIN32;_WINDOWS;__WIN32__;__MSC__;USE_WGL_SWAP;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + MultiThreaded + true + $(IntDir) + $(IntDir)r_opengl.pdb + true + Level3 + true + ProgramDatabase + CompileAsC + + + NDEBUG;%(PreprocessorDefinitions) + 0x0409 + + + $(OutDir)r_opengl.dll + true + true + $(OutDir)r_opengl.pdb + false + + + $(IntDir)r_opengl.lib + MachineX86 + + + true + $(OutDir)r_opengl.bsc + + + + + NDEBUG;%(PreprocessorDefinitions) + true + true + X64 + .\..\..\..\bin\VC10\$(Platform)\$(Configuration)\r_opengl\r_opengl.tlb + + + + + /MP %(AdditionalOptions) + MaxSpeed + OnlyExplicitInline + NDEBUG;WIN32;_WINDOWS;__WIN32__;__MSC__;USE_WGL_SWAP;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + MultiThreaded + true + $(IntDir) + $(IntDir)r_opengl.pdb + true + Level3 + true + ProgramDatabase + CompileAsC + + + NDEBUG;%(PreprocessorDefinitions) + 0x0409 + + + $(OutDir)r_opengl.dll + true + true + $(OutDir)r_opengl.pdb + false + + + $(IntDir)r_opengl.lib + MachineX64 + + + true + $(OutDir)r_opengl.bsc + + + + + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + + + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + + + + + + + + {0f554f1d-ed49-4d65-a9a7-f63c57f277be} + false + + + + + + \ No newline at end of file diff --git a/src/hardware/r_opengl/r_opengl-vc9.vcproj b/src/hardware/r_opengl/r_opengl-vc9.vcproj new file mode 100644 index 000000000..9f3e38e19 --- /dev/null +++ b/src/hardware/r_opengl/r_opengl-vc9.vcproj @@ -0,0 +1,480 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c new file mode 100644 index 000000000..c9a2f392d --- /dev/null +++ b/src/hardware/r_opengl/r_opengl.c @@ -0,0 +1,2179 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright (C) 1998-2006 by Sonic Team Junior. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +//----------------------------------------------------------------------------- +/// \file +/// \brief OpenGL API for Sonic Robo Blast 2 + +#if defined (_WIN32) +//#define WIN32_LEAN_AND_MEAN +#define RPC_NO_WINDOWS_H +#include +#endif +#undef GETTEXT +#ifdef __GNUC__ +#include +#endif + +#include +#include +#ifndef SHUFFLE +#ifndef KOS_GL_COMPATIBILITY +#define SHUFFLE +#endif +#endif +#include "r_opengl.h" + +#if defined (HWRENDER) && !defined (NOROPENGL) +// for KOS: GL_TEXTURE_ENV, glAlphaFunc, glColorMask, glPolygonOffset, glReadPixels, GL_ALPHA_TEST, GL_POLYGON_OFFSET_FILL + +struct GLRGBAFloat +{ + GLfloat red; + GLfloat green; + GLfloat blue; + GLfloat alpha; +}; +typedef struct GLRGBAFloat GLRGBAFloat; + +// ========================================================================== +// CONSTANTS +// ========================================================================== + +// With OpenGL 1.1+, the first texture should be 1 +#define NOTEXTURE_NUM 1 // small white texture +#define FIRST_TEX_AVAIL (NOTEXTURE_NUM + 1) + +#define N_PI_DEMI (M_PIl/2.0f) //(1.5707963268f) + +#define ASPECT_RATIO (1.0f) //(320.0f/200.0f) +#define FAR_CLIPPING_PLANE 150000.0f // Draw further! Tails 01-21-2001 +static float NEAR_CLIPPING_PLANE = NZCLIP_PLANE; + +// ************************************************************************** +// GLOBALS +// ************************************************************************** + + +static GLuint NextTexAvail = FIRST_TEX_AVAIL; +static GLuint tex_downloaded = 0; +static GLfloat fov = 90.0f; +static GLuint pal_col = 0; +static FRGBAFloat const_pal_col; +static FBITFIELD CurrentPolyFlags; + +static FTextureInfo* gr_cachetail = NULL; +static FTextureInfo* gr_cachehead = NULL; + +RGBA_t myPaletteData[256]; +GLint screen_width = 0; // used by Draw2DLine() +GLint screen_height = 0; +GLbyte screen_depth = 0; +GLint textureformatGL = 0; +GLint maximumAnisotropy = 0; +#ifndef KOS_GL_COMPATIBILITY +static GLboolean MipMap = GL_FALSE; +#endif +static GLint min_filter = GL_LINEAR; +static GLint mag_filter = GL_LINEAR; +static GLint anisotropic_filter = 0; +static FTransform md2_transform; + +const GLubyte *gl_extensions = NULL; + +//Hurdler: 04/10/2000: added for the kick ass coronas as Boris wanted;-) +#ifndef MINI_GL_COMPATIBILITY +static GLdouble modelMatrix[16]; +static GLdouble projMatrix[16]; +static GLint viewport[4]; +#endif + + +#ifdef USE_PALETTED_TEXTURE + PFNGLCOLORTABLEEXTPROC glColorTableEXT = NULL; + GLubyte palette_tex[256*3]; +#endif + +// Yay for arbitrary numbers! NextTexAvail is buggy for some reason. +static GLuint screentexture = 60000; +static GLuint startScreenWipe = 60001; +static GLuint endScreenWipe = 60002; +#if 0 +GLuint screentexture = FIRST_TEX_AVAIL; +#endif + +// shortcut for ((float)1/i) +static const GLfloat byte2float[256] = { + 0.000000f, 0.003922f, 0.007843f, 0.011765f, 0.015686f, 0.019608f, 0.023529f, 0.027451f, + 0.031373f, 0.035294f, 0.039216f, 0.043137f, 0.047059f, 0.050980f, 0.054902f, 0.058824f, + 0.062745f, 0.066667f, 0.070588f, 0.074510f, 0.078431f, 0.082353f, 0.086275f, 0.090196f, + 0.094118f, 0.098039f, 0.101961f, 0.105882f, 0.109804f, 0.113725f, 0.117647f, 0.121569f, + 0.125490f, 0.129412f, 0.133333f, 0.137255f, 0.141176f, 0.145098f, 0.149020f, 0.152941f, + 0.156863f, 0.160784f, 0.164706f, 0.168627f, 0.172549f, 0.176471f, 0.180392f, 0.184314f, + 0.188235f, 0.192157f, 0.196078f, 0.200000f, 0.203922f, 0.207843f, 0.211765f, 0.215686f, + 0.219608f, 0.223529f, 0.227451f, 0.231373f, 0.235294f, 0.239216f, 0.243137f, 0.247059f, + 0.250980f, 0.254902f, 0.258824f, 0.262745f, 0.266667f, 0.270588f, 0.274510f, 0.278431f, + 0.282353f, 0.286275f, 0.290196f, 0.294118f, 0.298039f, 0.301961f, 0.305882f, 0.309804f, + 0.313726f, 0.317647f, 0.321569f, 0.325490f, 0.329412f, 0.333333f, 0.337255f, 0.341176f, + 0.345098f, 0.349020f, 0.352941f, 0.356863f, 0.360784f, 0.364706f, 0.368627f, 0.372549f, + 0.376471f, 0.380392f, 0.384314f, 0.388235f, 0.392157f, 0.396078f, 0.400000f, 0.403922f, + 0.407843f, 0.411765f, 0.415686f, 0.419608f, 0.423529f, 0.427451f, 0.431373f, 0.435294f, + 0.439216f, 0.443137f, 0.447059f, 0.450980f, 0.454902f, 0.458824f, 0.462745f, 0.466667f, + 0.470588f, 0.474510f, 0.478431f, 0.482353f, 0.486275f, 0.490196f, 0.494118f, 0.498039f, + 0.501961f, 0.505882f, 0.509804f, 0.513726f, 0.517647f, 0.521569f, 0.525490f, 0.529412f, + 0.533333f, 0.537255f, 0.541177f, 0.545098f, 0.549020f, 0.552941f, 0.556863f, 0.560784f, + 0.564706f, 0.568627f, 0.572549f, 0.576471f, 0.580392f, 0.584314f, 0.588235f, 0.592157f, + 0.596078f, 0.600000f, 0.603922f, 0.607843f, 0.611765f, 0.615686f, 0.619608f, 0.623529f, + 0.627451f, 0.631373f, 0.635294f, 0.639216f, 0.643137f, 0.647059f, 0.650980f, 0.654902f, + 0.658824f, 0.662745f, 0.666667f, 0.670588f, 0.674510f, 0.678431f, 0.682353f, 0.686275f, + 0.690196f, 0.694118f, 0.698039f, 0.701961f, 0.705882f, 0.709804f, 0.713726f, 0.717647f, + 0.721569f, 0.725490f, 0.729412f, 0.733333f, 0.737255f, 0.741177f, 0.745098f, 0.749020f, + 0.752941f, 0.756863f, 0.760784f, 0.764706f, 0.768627f, 0.772549f, 0.776471f, 0.780392f, + 0.784314f, 0.788235f, 0.792157f, 0.796078f, 0.800000f, 0.803922f, 0.807843f, 0.811765f, + 0.815686f, 0.819608f, 0.823529f, 0.827451f, 0.831373f, 0.835294f, 0.839216f, 0.843137f, + 0.847059f, 0.850980f, 0.854902f, 0.858824f, 0.862745f, 0.866667f, 0.870588f, 0.874510f, + 0.878431f, 0.882353f, 0.886275f, 0.890196f, 0.894118f, 0.898039f, 0.901961f, 0.905882f, + 0.909804f, 0.913726f, 0.917647f, 0.921569f, 0.925490f, 0.929412f, 0.933333f, 0.937255f, + 0.941177f, 0.945098f, 0.949020f, 0.952941f, 0.956863f, 0.960784f, 0.964706f, 0.968628f, + 0.972549f, 0.976471f, 0.980392f, 0.984314f, 0.988235f, 0.992157f, 0.996078f, 1.000000f +}; + +float byteasfloat(UINT8 fbyte) +{ + return (float)(byte2float[fbyte]*2.0f); +} + +static I_Error_t I_Error_GL = NULL; + + +// -----------------+ +// DBG_Printf : Output error messages to debug log if DEBUG_TO_FILE is defined, +// : else do nothing +// Returns : +// -----------------+ +#if !(defined (SDL) && defined (STATIC3DS)) +FUNCPRINTF void DBG_Printf(const char *lpFmt, ...) +{ +#ifdef DEBUG_TO_FILE + char str[4096] = ""; + va_list arglist; + + va_start (arglist, lpFmt); + vsnprintf (str, 4096, lpFmt, arglist); + va_end (arglist); + if (logstream) + fwrite(str, strlen(str), 1, logstream); +#else + (void)lpFmt; +#endif +} +#endif + +#ifdef STATIC_OPENGL +/* 1.0 functions */ +/* Miscellaneous */ +#define pglClearColor glClearColor +//glClear +#define pglColorMask glColorMask +#define pglAlphaFunc glAlphaFunc +#define pglBlendFunc glBlendFunc +#define pglCullFace glCullFace +#define pglPolygonMode glPolygonMode +#define pglPolygonOffset glPolygonOffset +#define pglScissor glScissor +#define pglEnable glEnable +#define pglDisable glDisable +#ifndef MINI_GL_COMPATIBILITY +#define pglGetDoublev glGetDoublev +#endif +//glGetIntegerv +//glGetString +#ifdef KOS_GL_COMPATIBILITY +#define pglHint glHint +#endif + +/* Depth Buffer */ +#define pglClearDepth glClearDepth +#define pglDepthFunc glDepthFunc +#define pglDepthMask glDepthMask +#define pglDepthRange glDepthRange + +/* Transformation */ +#define pglMatrixMode glMatrixMode +#define pglViewport glViewport +#define pglPushMatrix glPushMatrix +#define pglPopMatrix glPopMatrix +#define pglLoadIdentity glLoadIdentity +#ifdef MINI_GL_COMPATIBILITY +#define pglMultMatrixf glMultMatrixf +#else +#define pglMultMatrixd glMultMatrixd +#endif +#define pglRotatef glRotatef +#define pglScalef glScalef +#define pglTranslatef glTranslatef + +/* Drawing Functions */ +#define pglBegin glBegin +#define pglEnd glEnd +#define pglVertex3f glVertex3f +#define pglNormal3f glNormal3f +#define pglColor4f glColor4f +#define pglColor4fv glColor4fv +#define pglTexCoord2f glTexCoord2f + +/* Lighting */ +#define pglShadeModel glShadeModel +#define pglLightfv glLightfv +#define pglLightModelfv glLightModelfv +#define pglMaterialfv glMaterialfv + +/* Raster functions */ +#define pglReadPixels glReadPixels + +/* Texture mapping */ +#define pglTexEnvi glTexEnvi +#define pglTexParameteri glTexParameteri +#define pglTexImage2D glTexImage2D + +/* Fog */ +#define pglFogf glFogf +#define pglFogfv glFogfv + +/* 1.1 functions */ +/* texture objects */ //GL_EXT_texture_object +#define pglDeleteTextures glDeleteTextures +#define pglBindTexture glBindTexture +/* texture mapping */ //GL_EXT_copy_texture +#ifndef KOS_GL_COMPATIBILITY +#define pglCopyTexImage2D glCopyTexImage2D + +/* GLU functions */ +#define pgluBuild2DMipmaps gluBuild2DMipmaps +#endif +#else //!STATIC_OPENGL + +/* 1.0 functions */ +/* Miscellaneous */ +typedef void (APIENTRY * PFNglClearColor) (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); +static PFNglClearColor pglClearColor; +//glClear +typedef void (APIENTRY * PFNglColorMask) (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); +static PFNglColorMask pglColorMask; +typedef void (APIENTRY * PFNglAlphaFunc) (GLenum func, GLclampf ref); +static PFNglAlphaFunc pglAlphaFunc; +typedef void (APIENTRY * PFNglBlendFunc) (GLenum sfactor, GLenum dfactor); +static PFNglBlendFunc pglBlendFunc; +typedef void (APIENTRY * PFNglCullFace) (GLenum mode); +static PFNglCullFace pglCullFace; +typedef void (APIENTRY * PFNglPolygonMode) (GLenum face, GLenum mode); +static PFNglPolygonMode pglPolygonMode; +typedef void (APIENTRY * PFNglPolygonOffset) (GLfloat factor, GLfloat units); +static PFNglPolygonOffset pglPolygonOffset; +typedef void (APIENTRY * PFNglScissor) (GLint x, GLint y, GLsizei width, GLsizei height); +static PFNglScissor pglScissor; +typedef void (APIENTRY * PFNglEnable) (GLenum cap); +static PFNglEnable pglEnable; +typedef void (APIENTRY * PFNglDisable) (GLenum cap); +static PFNglDisable pglDisable; +#ifndef MINI_GL_COMPATIBILITY +typedef void (APIENTRY * PFNglGetDoublev) (GLenum pname, GLdouble *params); +static PFNglGetDoublev pglGetDoublev; +#endif +//glGetIntegerv +//glGetString + +/* Depth Buffer */ +typedef void (APIENTRY * PFNglClearDepth) (GLclampd depth); +static PFNglClearDepth pglClearDepth; +typedef void (APIENTRY * PFNglDepthFunc) (GLenum func); +static PFNglDepthFunc pglDepthFunc; +typedef void (APIENTRY * PFNglDepthMask) (GLboolean flag); +static PFNglDepthMask pglDepthMask; +typedef void (APIENTRY * PFNglDepthRange) (GLclampd near_val, GLclampd far_val); +static PFNglDepthRange pglDepthRange; + +/* Transformation */ +typedef void (APIENTRY * PFNglMatrixMode) (GLenum mode); +static PFNglMatrixMode pglMatrixMode; +typedef void (APIENTRY * PFNglViewport) (GLint x, GLint y, GLsizei width, GLsizei height); +static PFNglViewport pglViewport; +typedef void (APIENTRY * PFNglPushMatrix) (void); +static PFNglPushMatrix pglPushMatrix; +typedef void (APIENTRY * PFNglPopMatrix) (void); +static PFNglPopMatrix pglPopMatrix; +typedef void (APIENTRY * PFNglLoadIdentity) (void); +static PFNglLoadIdentity pglLoadIdentity; +#ifdef MINI_GL_COMPATIBILITY +typedef void (APIENTRY * PFNglMultMatrixf) (const GLfloat *m); +static PFNglMultMatrixf pglMultMatrixf; +#else +typedef void (APIENTRY * PFNglMultMatrixd) (const GLdouble *m); +static PFNglMultMatrixd pglMultMatrixd; +#endif +typedef void (APIENTRY * PFNglRotatef) (GLfloat angle, GLfloat x, GLfloat y, GLfloat z); +static PFNglRotatef pglRotatef; +typedef void (APIENTRY * PFNglScalef) (GLfloat x, GLfloat y, GLfloat z); +static PFNglScalef pglScalef; +typedef void (APIENTRY * PFNglTranslatef) (GLfloat x, GLfloat y, GLfloat z); +static PFNglTranslatef pglTranslatef; + +/* Drawing Functions */ +typedef void (APIENTRY * PFNglBegin) (GLenum mode); +static PFNglBegin pglBegin; +typedef void (APIENTRY * PFNglEnd) (void); +static PFNglEnd pglEnd; +typedef void (APIENTRY * PFNglVertex3f) (GLfloat x, GLfloat y, GLfloat z); +static PFNglVertex3f pglVertex3f; +typedef void (APIENTRY * PFNglNormal3f) (GLfloat x, GLfloat y, GLfloat z); +static PFNglNormal3f pglNormal3f; +typedef void (APIENTRY * PFNglColor4f) (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); +static PFNglColor4f pglColor4f; +typedef void (APIENTRY * PFNglColor4fv) (const GLfloat *v); +static PFNglColor4fv pglColor4fv; +typedef void (APIENTRY * PFNglTexCoord2f) (GLfloat s, GLfloat t); +static PFNglTexCoord2f pglTexCoord2f; + +/* Lighting */ +typedef void (APIENTRY * PFNglShadeModel) (GLenum mode); +static PFNglShadeModel pglShadeModel; +typedef void (APIENTRY * PFNglLightfv) (GLenum light, GLenum pname, GLfloat *params); +static PFNglLightfv pglLightfv; +typedef void (APIENTRY * PFNglLightModelfv) (GLenum pname, GLfloat *params); +static PFNglLightModelfv pglLightModelfv; +typedef void (APIENTRY * PFNglMaterialfv) (GLint face, GLenum pname, GLfloat *params); +static PFNglMaterialfv pglMaterialfv; + +/* Raster functions */ +typedef void (APIENTRY * PFNglReadPixels) (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels); +static PFNglReadPixels pglReadPixels; + +/* Texture mapping */ +typedef void (APIENTRY * PFNglTexEnvi) (GLenum target, GLenum pname, GLint param); +static PFNglTexEnvi pglTexEnvi; +typedef void (APIENTRY * PFNglTexParameteri) (GLenum target, GLenum pname, GLint param); +static PFNglTexParameteri pglTexParameteri; +typedef void (APIENTRY * PFNglTexImage2D) (GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +static PFNglTexImage2D pglTexImage2D; + +/* Fog */ +typedef void (APIENTRY * PFNglFogf) (GLenum pname, GLfloat param); +static PFNglFogf pglFogf; +typedef void (APIENTRY * PFNglFogfv) (GLenum pname, const GLfloat *params); +static PFNglFogfv pglFogfv; + +/* 1.1 functions */ +/* texture objects */ //GL_EXT_texture_object +typedef void (APIENTRY * PFNglDeleteTextures) (GLsizei n, const GLuint *textures); +static PFNglDeleteTextures pglDeleteTextures; +typedef void (APIENTRY * PFNglBindTexture) (GLenum target, GLuint texture); +static PFNglBindTexture pglBindTexture; +/* texture mapping */ //GL_EXT_copy_texture +typedef void (APIENTRY * PFNglCopyTexImage2D) (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); +static PFNglCopyTexImage2D pglCopyTexImage2D; + +/* GLU functions */ +typedef GLint (APIENTRY * PFNgluBuild2DMipmaps) (GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *data); +static PFNgluBuild2DMipmaps pgluBuild2DMipmaps; +#endif + +#ifndef MINI_GL_COMPATIBILITY +/* 1.2 Parms */ +/* GL_CLAMP_TO_EDGE_EXT */ +#ifndef GL_CLAMP_TO_EDGE +#define GL_CLAMP_TO_EDGE 0x812F +#endif +#ifndef GL_TEXTURE_MIN_LOD +#define GL_TEXTURE_MIN_LOD 0x813A +#endif +#ifndef GL_TEXTURE_MAX_LOD +#define GL_TEXTURE_MAX_LOD 0x813B +#endif + +#endif + +#ifdef MINI_GL_COMPATIBILITY +#undef GL_CLAMP_TO_EDGE +#undef GL_TEXTURE_MIN_LOD +#undef GL_TEXTURE_MAX_LOD +#endif + +boolean SetupGLfunc(void) +{ +#ifndef STATIC_OPENGL +#define GETOPENGLFUNC(func, proc) \ + func = GetGLFunc(#proc); \ + if (!func) \ + { \ + DBG_Printf("failed to get OpenGL function: %s", #proc); \ + } \ + + GETOPENGLFUNC(pglClearColor, glClearColor) + + GETOPENGLFUNC(pglClear , glClear) + GETOPENGLFUNC(pglColorMask , glColorMask) + GETOPENGLFUNC(pglAlphaFunc , glAlphaFunc) + GETOPENGLFUNC(pglBlendFunc , glBlendFunc) + GETOPENGLFUNC(pglCullFace , glCullFace) + GETOPENGLFUNC(pglPolygonMode , glPolygonMode) + GETOPENGLFUNC(pglPolygonOffset , glPolygonOffset) + GETOPENGLFUNC(pglScissor , glScissor) + GETOPENGLFUNC(pglEnable , glEnable) + GETOPENGLFUNC(pglDisable , glDisable) +#ifndef MINI_GL_COMPATIBILITY + GETOPENGLFUNC(pglGetDoublev , glGetDoublev) +#endif + GETOPENGLFUNC(pglGetIntegerv , glGetIntegerv) + GETOPENGLFUNC(pglGetString , glGetString) + + GETOPENGLFUNC(pglClearDepth , glClearDepth) + GETOPENGLFUNC(pglDepthFunc , glDepthFunc) + GETOPENGLFUNC(pglDepthMask , glDepthMask) + GETOPENGLFUNC(pglDepthRange , glDepthRange) + + GETOPENGLFUNC(pglMatrixMode , glMatrixMode) + GETOPENGLFUNC(pglViewport , glViewport) + GETOPENGLFUNC(pglPushMatrix , glPushMatrix) + GETOPENGLFUNC(pglPopMatrix , glPopMatrix) + GETOPENGLFUNC(pglLoadIdentity , glLoadIdentity) +#ifdef MINI_GL_COMPATIBILITY + GETOPENGLFUNC(pglMultMatrixf , glMultMatrixf) +#else + GETOPENGLFUNC(pglMultMatrixd , glMultMatrixd) +#endif + GETOPENGLFUNC(pglRotatef , glRotatef) + GETOPENGLFUNC(pglScalef , glScalef) + GETOPENGLFUNC(pglTranslatef , glTranslatef) + + GETOPENGLFUNC(pglBegin , glBegin) + GETOPENGLFUNC(pglEnd , glEnd) + GETOPENGLFUNC(pglVertex3f , glVertex3f) + GETOPENGLFUNC(pglNormal3f , glNormal3f) + GETOPENGLFUNC(pglColor4f , glColor4f) + GETOPENGLFUNC(pglColor4fv , glColor4fv) + GETOPENGLFUNC(pglTexCoord2f , glTexCoord2f) + + GETOPENGLFUNC(pglShadeModel , glShadeModel) + GETOPENGLFUNC(pglLightfv, glLightfv) + GETOPENGLFUNC(pglLightModelfv , glLightModelfv) + GETOPENGLFUNC(pglMaterialfv , glMaterialfv) + + GETOPENGLFUNC(pglReadPixels , glReadPixels) + + GETOPENGLFUNC(pglTexEnvi , glTexEnvi) + GETOPENGLFUNC(pglTexParameteri , glTexParameteri) + GETOPENGLFUNC(pglTexImage2D , glTexImage2D) + + GETOPENGLFUNC(pglFogf , glFogf) + GETOPENGLFUNC(pglFogfv , glFogfv) + + GETOPENGLFUNC(pglDeleteTextures , glDeleteTextures) + GETOPENGLFUNC(pglBindTexture , glBindTexture) + + GETOPENGLFUNC(pglCopyTexImage2D , glCopyTexImage2D) + +#undef GETOPENGLFUNC + + pgluBuild2DMipmaps = GetGLFunc("gluBuild2DMipmaps"); + +#endif + return true; +} + +// -----------------+ +// SetNoTexture : Disable texture +// -----------------+ +static void SetNoTexture(void) +{ + // Set small white texture. + if (tex_downloaded != NOTEXTURE_NUM) + { + pglBindTexture(GL_TEXTURE_2D, NOTEXTURE_NUM); + tex_downloaded = NOTEXTURE_NUM; + } +} + +static void GLPerspective(GLdouble fovy, GLdouble aspect) +{ +#ifdef MINI_GL_COMPATIBILITY + GLfloat m[4][4] = +#else + GLdouble m[4][4] = +#endif + { + { 1.0f, 0.0f, 0.0f, 0.0f}, + { 0.0f, 1.0f, 0.0f, 0.0f}, + { 0.0f, 0.0f, 1.0f,-1.0f}, + { 0.0f, 0.0f, 0.0f, 0.0f}, + }; + const GLdouble zNear = NEAR_CLIPPING_PLANE; + const GLdouble zFar = FAR_CLIPPING_PLANE; + const GLdouble radians = (GLdouble)(fovy / 2.0f * M_PIl / 180.0f); + const GLdouble sine = sin(radians); + const GLdouble deltaZ = zFar - zNear; + GLdouble cotangent; + + if ((deltaZ == 0.0f) || (sine == 0.0f) || (aspect == 0.0f)) { + return; + } + cotangent = cos(radians) / sine; + + m[0][0] = cotangent / aspect; + m[1][1] = cotangent; + m[2][2] = -(zFar + zNear) / deltaZ; + m[3][2] = -2.0f * zNear * zFar / deltaZ; +#ifdef MINI_GL_COMPATIBILITY + pglMultMatrixf(&m[0][0]); +#else + pglMultMatrixd(&m[0][0]); +#endif +} + +#ifndef MINI_GL_COMPATIBILITY +static void GLProject(GLdouble objX, GLdouble objY, GLdouble objZ, + GLdouble* winX, GLdouble* winY, GLdouble* winZ) +{ + GLdouble in[4], out[4]; + int i; + + for (i=0; i<4; i++) + { + out[i] = + objX * modelMatrix[0*4+i] + + objY * modelMatrix[1*4+i] + + objZ * modelMatrix[2*4+i] + + modelMatrix[3*4+i]; + } + for (i=0; i<4; i++) + { + in[i] = + out[0] * projMatrix[0*4+i] + + out[1] * projMatrix[1*4+i] + + out[2] * projMatrix[2*4+i] + + out[3] * projMatrix[3*4+i]; + } + if (in[3] == 0.0f) return; + in[0] /= in[3]; + in[1] /= in[3]; + in[2] /= in[3]; + /* Map x, y and z to range 0-1 */ + in[0] = in[0] * 0.5f + 0.5f; + in[1] = in[1] * 0.5f + 0.5f; + in[2] = in[2] * 0.5f + 0.5f; + + /* Map x,y to viewport */ + in[0] = in[0] * viewport[2] + viewport[0]; + in[1] = in[1] * viewport[3] + viewport[1]; + + *winX=in[0]; + *winY=in[1]; + *winZ=in[2]; +} +#endif + +// -----------------+ +// SetModelView : +// -----------------+ +void SetModelView(GLint w, GLint h) +{ + DBG_Printf("SetModelView(): %dx%d\n", (int)w, (int)h); + + screen_width = w; + screen_height = h; + + pglViewport(0, 0, w, h); +#ifdef GL_ACCUM_BUFFER_BIT + pglClear(GL_ACCUM_BUFFER_BIT); +#endif + + pglMatrixMode(GL_PROJECTION); + pglLoadIdentity(); + + pglMatrixMode(GL_MODELVIEW); + pglLoadIdentity(); + + GLPerspective(fov, ASPECT_RATIO); + //pglScalef(1.0f, 320.0f/200.0f, 1.0f); // gr_scalefrustum (ORIGINAL_ASPECT) + + // added for new coronas' code (without depth buffer) +#ifndef MINI_GL_COMPATIBILITY + pglGetIntegerv(GL_VIEWPORT, viewport); + pglGetDoublev(GL_PROJECTION_MATRIX, projMatrix); +#endif +} + + +// -----------------+ +// SetStates : Set permanent states +// -----------------+ +void SetStates(void) +{ + // Bind little white RGBA texture to ID NOTEXTURE_NUM. + /* + FUINT Data[8*8]; + INT32 i; + */ +#ifdef GL_LIGHT_MODEL_AMBIENT + GLfloat LightDiffuse[] = {1.0f, 1.0f, 1.0f, 1.0f}; +#endif +#ifndef KOS_GL_COMPATIBILITY + GLfloat LightPos[] = {0.0f, 1.0f, 0.0f, 0.0f}; +#endif + + DBG_Printf("SetStates()\n"); + + // Hurdler: not necessary, is it? + pglShadeModel(GL_SMOOTH); // iterate vertice colors + //pglShadeModel(GL_FLAT); + + pglEnable(GL_TEXTURE_2D); // two-dimensional texturing +#ifndef KOS_GL_COMPATIBILITY + pglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + + pglAlphaFunc(GL_NOTEQUAL, 0.0f); +#endif + //pglBlendFunc(GL_ONE, GL_ZERO); // copy pixel to frame buffer (opaque) + pglEnable(GL_BLEND); // enable color blending + +#ifndef KOS_GL_COMPATIBILITY + pglColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); +#endif + + //pglDisable(GL_DITHER); // faB: ??? (undocumented in OpenGL 1.1) + // Hurdler: yes, it is! + pglEnable(GL_DEPTH_TEST); // check the depth buffer + pglDepthMask(GL_TRUE); // enable writing to depth buffer + pglClearDepth(1.0f); + pglDepthRange(0.0f, 1.0f); + pglDepthFunc(GL_LEQUAL); + + // this set CurrentPolyFlags to the acctual configuration + CurrentPolyFlags = 0xffffffff; + SetBlend(0); + + /* + for (i = 0; i < 64; i++) + Data[i] = 0xffFFffFF; // white pixel + */ + + tex_downloaded = (GLuint)-1; + SetNoTexture(); + //pglBindTexture(GL_TEXTURE_2D, NOTEXTURE_NUM); + //tex_downloaded = NOTEXTURE_NUM; + //pglTexImage2D(GL_TEXTURE_2D, 0, 4, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, Data); + +#ifndef KOS_GL_COMPATIBILITY + pglPolygonOffset(-1.0f, -1.0f); +#endif + + //pglEnable(GL_CULL_FACE); + //pglCullFace(GL_FRONT); + //pglPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + //pglPolygonMode(GL_FRONT, GL_LINE); + + //glFogi(GL_FOG_MODE, GL_EXP); + //pglHint(GL_FOG_HINT, GL_FASTEST); + //pglFogfv(GL_FOG_COLOR, fogcolor); + //pglFogf(GL_FOG_DENSITY, 0.0005f); + + // Lighting for models +#ifdef GL_LIGHT_MODEL_AMBIENT + pglLightModelfv(GL_LIGHT_MODEL_AMBIENT, LightDiffuse); + pglEnable(GL_LIGHT0); +#endif +#ifndef KOS_GL_COMPATIBILITY + pglLightfv(GL_LIGHT0, GL_POSITION, LightPos); +#endif + + // bp : when no t&l :) + pglLoadIdentity(); + pglScalef(1.0f, 1.0f, -1.0f); +#ifndef MINI_GL_COMPATIBILITY + pglGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix); // added for new coronas' code (without depth buffer) +#endif +} + + +// -----------------+ +// Flush : flush OpenGL textures +// : Clear list of downloaded mipmaps +// -----------------+ +void Flush(void) +{ + //DBG_Printf ("HWR_Flush()\n"); + + while (gr_cachehead) + { + // ceci n'est pas du tout necessaire vu que tu les a charger normalement et + // donc il sont dans ta liste ! +#if 0 + //Hurdler: 25/04/2000: now support colormap in hardware mode + FTextureInfo *tmp = gr_cachehead->nextskin; + + // The memory should be freed in the main code + while (tmp) + { + pglDeleteTextures(1, &tmp->downloaded); + tmp->downloaded = 0; + tmp = tmp->nextcolormap; + } +#endif + pglDeleteTextures(1, (GLuint *)&gr_cachehead->downloaded); + gr_cachehead->downloaded = 0; + gr_cachehead = gr_cachehead->nextmipmap; + } + gr_cachetail = gr_cachehead = NULL; //Hurdler: well, gr_cachehead is already NULL + NextTexAvail = FIRST_TEX_AVAIL; +#if 0 + if (screentexture != FIRST_TEX_AVAIL) + { + pglDeleteTextures(1, &screentexture); + screentexture = FIRST_TEX_AVAIL; + } +#endif + tex_downloaded = 0; +} + + +// -----------------+ +// isExtAvailable : Look if an OpenGL extension is available +// Returns : true if extension available +// -----------------+ +INT32 isExtAvailable(const char *extension, const GLubyte *start) +{ + GLubyte *where, *terminator; + + if (!extension || !start) return 0; + where = (GLubyte *) strchr(extension, ' '); + if (where || *extension == '\0') + return 0; + + for (;;) + { + where = (GLubyte *) strstr((const char *) start, extension); + if (!where) + break; + terminator = where + strlen(extension); + if (where == start || *(where - 1) == ' ') + if (*terminator == ' ' || *terminator == '\0') + return 1; + start = terminator; + } + return 0; +} + + +// -----------------+ +// Init : Initialise the OpenGL interface API +// Returns : +// -----------------+ +EXPORT boolean HWRAPI(Init) (I_Error_t FatalErrorFunction) +{ + I_Error_GL = FatalErrorFunction; + DBG_Printf ("%s %s\n", DRIVER_STRING, VERSIONSTRING); + return LoadGL(); +} + + +// -----------------+ +// ClearMipMapCache : Flush OpenGL textures from memory +// -----------------+ +EXPORT void HWRAPI(ClearMipMapCache) (void) +{ + // DBG_Printf ("HWR_Flush(exe)\n"); + Flush(); +} + + +// -----------------+ +// ReadRect : Read a rectangle region of the truecolor framebuffer +// : store pixels as 16bit 565 RGB +// Returns : 16bit 565 RGB pixel array stored in dst_data +// -----------------+ +EXPORT void HWRAPI(ReadRect) (INT32 x, INT32 y, INT32 width, INT32 height, + INT32 dst_stride, UINT16 * dst_data) +{ +#ifdef KOS_GL_COMPATIBILITY + (void)x; + (void)y; + (void)width; + (void)height; + (void)dst_stride; + (void)dst_data; +#else + INT32 i; + // DBG_Printf ("ReadRect()\n"); + if (dst_stride == width*3) + { + GLubyte*top = (GLvoid*)dst_data, *bottom = top + dst_stride * (height - 1); + GLubyte *row = malloc(dst_stride); + if (!row) return; + pglReadPixels(x, y, width, height, GL_RGB, GL_UNSIGNED_BYTE, dst_data); + for(i = 0; i < height/2; i++) + { + memcpy(row, top, dst_stride); + memcpy(top, bottom, dst_stride); + memcpy(bottom, row, dst_stride); + top += dst_stride; + bottom -= dst_stride; + } + free(row); + } + else + { + INT32 j; + GLubyte *image = malloc(width*height*3*sizeof (*image)); + if (!image) return; + pglReadPixels(x, y, width, height, GL_RGB, GL_UNSIGNED_BYTE, image); + for (i = height-1; i >= 0; i--) + { + for (j = 0; j < width; j++) + { + dst_data[(height-1-i)*width+j] = + (UINT16)( + ((image[(i*width+j)*3]>>3)<<11) | + ((image[(i*width+j)*3+1]>>2)<<5) | + ((image[(i*width+j)*3+2]>>3))); + } + } + free(image); + } +#endif +} + + +// -----------------+ +// GClipRect : Defines the 2D hardware clipping window +// -----------------+ +EXPORT void HWRAPI(GClipRect) (INT32 minx, INT32 miny, INT32 maxx, INT32 maxy, float nearclip) +{ + // DBG_Printf ("GClipRect(%d, %d, %d, %d)\n", minx, miny, maxx, maxy); + + pglViewport(minx, screen_height-maxy, maxx-minx, maxy-miny); + NEAR_CLIPPING_PLANE = nearclip; + + //pglScissor(minx, screen_height-maxy, maxx-minx, maxy-miny); + pglMatrixMode(GL_PROJECTION); + pglLoadIdentity(); + GLPerspective(fov, ASPECT_RATIO); + pglMatrixMode(GL_MODELVIEW); + + // added for new coronas' code (without depth buffer) +#ifndef MINI_GL_COMPATIBILITY + pglGetIntegerv(GL_VIEWPORT, viewport); + pglGetDoublev(GL_PROJECTION_MATRIX, projMatrix); +#endif +} + + +// -----------------+ +// ClearBuffer : Clear the color/alpha/depth buffer(s) +// -----------------+ +EXPORT void HWRAPI(ClearBuffer) (FBOOLEAN ColorMask, + FBOOLEAN DepthMask, + FRGBAFloat * ClearColor) +{ + // DBG_Printf ("ClearBuffer(%d)\n", alpha); + GLbitfield ClearMask = 0; + + if (ColorMask) + { + if (ClearColor) + pglClearColor(ClearColor->red, + ClearColor->green, + ClearColor->blue, + ClearColor->alpha); + ClearMask |= GL_COLOR_BUFFER_BIT; + } + if (DepthMask) + { + pglClearDepth(1.0f); //Hurdler: all that are permanen states + pglDepthRange(0.0f, 1.0f); + pglDepthFunc(GL_LEQUAL); + ClearMask |= GL_DEPTH_BUFFER_BIT; + } + + SetBlend(DepthMask ? PF_Occlude | CurrentPolyFlags : CurrentPolyFlags&~PF_Occlude); + + pglClear(ClearMask); +} + + +// -----------------+ +// HWRAPI Draw2DLine: Render a 2D line +// -----------------+ +EXPORT void HWRAPI(Draw2DLine) (F2DCoord * v1, + F2DCoord * v2, + RGBA_t Color) +{ + GLRGBAFloat c; + + // DBG_Printf ("DrawLine() (%f %f %f) %d\n", v1->x, -v1->y, -v1->z, v1->argb); +#ifdef MINI_GL_COMPATIBILITY + GLfloat px1, px2, px3, px4; + GLfloat py1, py2, py3, py4; + GLfloat dx, dy; + GLfloat angle; +#endif + + // BP: we should reflect the new state in our variable + //SetBlend(PF_Modulated|PF_NoTexture); + + pglDisable(GL_TEXTURE_2D); + + c.red = byte2float[Color.s.red]; + c.green = byte2float[Color.s.green]; + c.blue = byte2float[Color.s.blue]; + c.alpha = byte2float[Color.s.alpha]; + +#ifndef MINI_GL_COMPATIBILITY + pglColor4fv(&c.red); // is in RGBA float format + pglBegin(GL_LINES); + pglVertex3f(v1->x, -v1->y, 1.0f); + pglVertex3f(v2->x, -v2->y, 1.0f); + pglEnd(); +#else + if (v2->x != v1->x) + angle = (float)atan((v2->y-v1->y)/(v2->x-v1->x)); + else + angle = N_PI_DEMI; + dx = (float)sin(angle) / (float)screen_width; + dy = (float)cos(angle) / (float)screen_height; + + px1 = v1->x - dx; py1 = v1->y + dy; + px2 = v2->x - dx; py2 = v2->y + dy; + px3 = v2->x + dx; py3 = v2->y - dy; + px4 = v1->x + dx; py4 = v1->y - dy; + + pglColor4f(c.red, c.green, c.blue, c.alpha); + pglBegin(GL_TRIANGLE_FAN); + pglVertex3f(px1, -py1, 1); + pglVertex3f(px2, -py2, 1); + pglVertex3f(px3, -py3, 1); + pglVertex3f(px4, -py4, 1); + pglEnd(); +#endif + + pglEnable(GL_TEXTURE_2D); +} + +static void Clamp2D(GLenum pname) +{ + pglTexParameteri(GL_TEXTURE_2D, pname, GL_CLAMP); // fallback clamp +#ifdef GL_CLAMP_TO_EDGE + pglTexParameteri(GL_TEXTURE_2D, pname, GL_CLAMP_TO_EDGE); +#endif +} + + +// -----------------+ +// SetBlend : Set render mode +// -----------------+ +// PF_Masked - we could use an ALPHA_TEST of GL_EQUAL, and alpha ref of 0, +// is it faster when pixels are discarded ? +EXPORT void HWRAPI(SetBlend) (FBITFIELD PolyFlags) +{ + FBITFIELD Xor; + Xor = CurrentPolyFlags^PolyFlags; + if (Xor & (PF_Blending|PF_RemoveYWrap|PF_ForceWrapX|PF_ForceWrapY|PF_Occlude|PF_NoTexture|PF_Modulated|PF_NoDepthTest|PF_Decal|PF_Invisible|PF_NoAlphaTest)) + { + if (Xor&(PF_Blending)) // if blending mode must be changed + { + switch (PolyFlags & PF_Blending) { + case PF_Translucent & PF_Blending: + pglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // alpha = level of transparency + break; + case PF_Masked & PF_Blending: + // Hurdler: does that mean lighting is only made by alpha src? + // it sounds ok, but not for polygonsmooth + pglBlendFunc(GL_SRC_ALPHA, GL_ZERO); // 0 alpha = holes in texture + break; + case PF_Additive & PF_Blending: +#ifdef ATI_RAGE_PRO_COMPATIBILITY + pglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // alpha = level of transparency +#else + pglBlendFunc(GL_SRC_ALPHA, GL_ONE); // src * alpha + dest +#endif + break; + case PF_Environment & PF_Blending: + pglBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); + break; + case PF_Substractive & PF_Blending: + // good for shadow + // not realy but what else ? + pglBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_COLOR); + break; + default : // must be 0, otherwise it's an error + // No blending + pglBlendFunc(GL_ONE, GL_ZERO); // the same as no blending + break; + } + } +#ifndef KOS_GL_COMPATIBILITY + if (Xor & PF_NoAlphaTest) + { + if (PolyFlags & PF_NoAlphaTest) + pglDisable(GL_ALPHA_TEST); + else + pglEnable(GL_ALPHA_TEST); // discard 0 alpha pixels (holes in texture) + } + + if (Xor & PF_Decal) + { + if (PolyFlags & PF_Decal) + pglEnable(GL_POLYGON_OFFSET_FILL); + else + pglDisable(GL_POLYGON_OFFSET_FILL); + } +#endif + if (Xor&PF_NoDepthTest) + { + if (PolyFlags & PF_NoDepthTest) + pglDepthFunc(GL_ALWAYS); //pglDisable(GL_DEPTH_TEST); + else + pglDepthFunc(GL_LEQUAL); //pglEnable(GL_DEPTH_TEST); + } + + if (Xor&PF_RemoveYWrap) + { + if (PolyFlags & PF_RemoveYWrap) + Clamp2D(GL_TEXTURE_WRAP_T); + } + + if (Xor&PF_ForceWrapX) + { + if (PolyFlags & PF_ForceWrapX) + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + } + + if (Xor&PF_ForceWrapY) + { + if (PolyFlags & PF_ForceWrapY) + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + } + +#ifdef KOS_GL_COMPATIBILITY + if (Xor&PF_Modulated && !(PolyFlags & PF_Modulated)) + pglColor4f(1.0f, 1.0f, 1.0f, 1.0f); +#else + if (Xor&PF_Modulated) + { +#if defined (__unix__) || defined (UNIXCOMMON) + if (oglflags & GLF_NOTEXENV) + { + if (!(PolyFlags & PF_Modulated)) + pglColor4f(1.0f, 1.0f, 1.0f, 1.0f); + } + else +#endif + if (PolyFlags & PF_Modulated) + { // mix texture colour with Surface->FlatColor + pglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + } + else + { // colour from texture is unchanged before blending + pglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + } + } +#endif + + if (Xor & PF_Occlude) // depth test but (no) depth write + { + if (PolyFlags&PF_Occlude) + { + pglDepthMask(1); + } + else + pglDepthMask(0); + } + ////Hurdler: not used if we don't define POLYSKY + if (Xor & PF_Invisible) + { + if (PolyFlags&PF_Invisible) + pglBlendFunc(GL_ZERO, GL_ONE); // transparent blending + else + { // big hack: (TODO: manage that better) + // we test only for PF_Masked because PF_Invisible is only used + // (for now) with it (yeah, that's crappy, sorry) + if ((PolyFlags&PF_Blending)==PF_Masked) + pglBlendFunc(GL_SRC_ALPHA, GL_ZERO); + } + } + if (PolyFlags & PF_NoTexture) + { + SetNoTexture(); + } + } + CurrentPolyFlags = PolyFlags; +} + + +// -----------------+ +// SetTexture : The mipmap becomes the current texture source +// -----------------+ +EXPORT void HWRAPI(SetTexture) (FTextureInfo *pTexInfo) +{ + if (!pTexInfo) + { + SetNoTexture(); + return; + } + else if (pTexInfo->downloaded) + { + if (pTexInfo->downloaded != tex_downloaded) + { + pglBindTexture(GL_TEXTURE_2D, pTexInfo->downloaded); + tex_downloaded = pTexInfo->downloaded; + } + } + else + { + // Download a mipmap +#ifdef KOS_GL_COMPATIBILITY + static GLushort tex[2048*2048]; +#else + static RGBA_t tex[2048*2048]; +#endif + const GLvoid *ptex = tex; + INT32 w, h; + + //DBG_Printf ("DownloadMipmap %d %x\n",NextTexAvail,pTexInfo->grInfo.data); + + w = pTexInfo->width; + h = pTexInfo->height; + +#ifdef USE_PALETTED_TEXTURE + if (glColorTableEXT && + (pTexInfo->grInfo.format == GR_TEXFMT_P_8) && + !(pTexInfo->flags & TF_CHROMAKEYED)) + { + // do nothing here. + // Not a problem with MiniGL since we don't use paletted texture + } + else +#endif +#ifdef KOS_GL_COMPATIBILITY + if ((pTexInfo->grInfo.format == GR_TEXFMT_P_8) || + (pTexInfo->grInfo.format == GR_TEXFMT_AP_88)) + { + const GLubyte *pImgData = (const GLubyte *)pTexInfo->grInfo.data; + INT32 i, j; + + for (j = 0; j < h; j++) + { + for (i = 0; i < w; i++) + { + if ((*pImgData == HWR_PATCHES_CHROMAKEY_COLORINDEX) && + (pTexInfo->flags & TF_CHROMAKEYED)) + { + tex[w*j+i] = 0; + } + else + { + if (pTexInfo->grInfo.format == GR_TEXFMT_AP_88 && !(pTexInfo->flags & TF_CHROMAKEYED)) + tex[w*j+i] = 0; + else + tex[w*j+i] = (myPaletteData[*pImgData].s.alpha>>4)<<12; + + tex[w*j+i] |= (myPaletteData[*pImgData].s.red >>4)<<8; + tex[w*j+i] |= (myPaletteData[*pImgData].s.green>>4)<<4; + tex[w*j+i] |= (myPaletteData[*pImgData].s.blue >>4); + } + + pImgData++; + + if (pTexInfo->grInfo.format == GR_TEXFMT_AP_88) + { + if (!(pTexInfo->flags & TF_CHROMAKEYED)) + tex[w*j+i] |= ((*pImgData)>>4)<<12; + pImgData++; + } + + } + } + } + else if (pTexInfo->grInfo.format == GR_RGBA) + { + // corona test : passed as ARGB 8888, which is not in glide formats + // Hurdler: not used for coronas anymore, just for dynamic lighting + const RGBA_t *pImgData = (const RGBA_t *)pTexInfo->grInfo.data; + INT32 i, j; + + for (j = 0; j < h; j++) + { + for (i = 0; i < w; i++) + { + tex[w*j+i] = (pImgData->s.alpha>>4)<<12; + tex[w*j+i] |= (pImgData->s.red >>4)<<8; + tex[w*j+i] |= (pImgData->s.green>>4)<<4; + tex[w*j+i] |= (pImgData->s.blue >>4); + pImgData++; + } + } + } + else if (pTexInfo->grInfo.format == GR_TEXFMT_ALPHA_INTENSITY_88) + { + const GLubyte *pImgData = (const GLubyte *)pTexInfo->grInfo.data; + INT32 i, j; + + for (j = 0; j < h; j++) + { + for (i = 0; i < w; i++) + { + const GLubyte sID = (*pImgData)>>4; + tex[w*j+i] = sID<<8 | sID<<4 | sID; + pImgData++; + tex[w*j+i] |= ((*pImgData)>>4)<<12; + pImgData++; + } + } + } + else + DBG_Printf ("SetTexture(bad format) %ld\n", pTexInfo->grInfo.format); +#else + if ((pTexInfo->grInfo.format == GR_TEXFMT_P_8) || + (pTexInfo->grInfo.format == GR_TEXFMT_AP_88)) + { + const GLubyte *pImgData = (const GLubyte *)pTexInfo->grInfo.data; + INT32 i, j; + + for (j = 0; j < h; j++) + { + for (i = 0; i < w; i++) + { + if ((*pImgData == HWR_PATCHES_CHROMAKEY_COLORINDEX) && + (pTexInfo->flags & TF_CHROMAKEYED)) + { + tex[w*j+i].s.red = 0; + tex[w*j+i].s.green = 0; + tex[w*j+i].s.blue = 0; + tex[w*j+i].s.alpha = 0; + } + else + { + tex[w*j+i].s.red = myPaletteData[*pImgData].s.red; + tex[w*j+i].s.green = myPaletteData[*pImgData].s.green; + tex[w*j+i].s.blue = myPaletteData[*pImgData].s.blue; + tex[w*j+i].s.alpha = myPaletteData[*pImgData].s.alpha; + } + + pImgData++; + + if (pTexInfo->grInfo.format == GR_TEXFMT_AP_88) + { + if (!(pTexInfo->flags & TF_CHROMAKEYED)) + tex[w*j+i].s.alpha = *pImgData; + pImgData++; + } + + } + } + } + else if (pTexInfo->grInfo.format == GR_RGBA) + { + // corona test : passed as ARGB 8888, which is not in glide formats + // Hurdler: not used for coronas anymore, just for dynamic lighting + ptex = pTexInfo->grInfo.data; + } + else if (pTexInfo->grInfo.format == GR_TEXFMT_ALPHA_INTENSITY_88) + { + const GLubyte *pImgData = (const GLubyte *)pTexInfo->grInfo.data; + INT32 i, j; + + for (j = 0; j < h; j++) + { + for (i = 0; i < w; i++) + { + tex[w*j+i].s.red = *pImgData; + tex[w*j+i].s.green = *pImgData; + tex[w*j+i].s.blue = *pImgData; + pImgData++; + tex[w*j+i].s.alpha = *pImgData; + pImgData++; + } + } + } + else + DBG_Printf ("SetTexture(bad format) %ld\n", pTexInfo->grInfo.format); +#endif + + pTexInfo->downloaded = NextTexAvail++; + tex_downloaded = pTexInfo->downloaded; + pglBindTexture(GL_TEXTURE_2D, pTexInfo->downloaded); + + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter); + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter); + +#ifdef KOS_GL_COMPATIBILITY + pglTexImage2D(GL_TEXTURE_2D, 0, GL_ARGB4444, w, h, 0, GL_ARGB4444, GL_UNSIGNED_BYTE, ptex); +#else +#ifdef MINI_GL_COMPATIBILITY + //if (pTexInfo->grInfo.format == GR_TEXFMT_ALPHA_INTENSITY_88) + //pglTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); + //else + if (MipMap) + pgluBuild2DMipmaps(GL_TEXTURE_2D, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, ptex); + else + pglTexImage2D(GL_TEXTURE_2D, 0, 4, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); +#else +#ifdef USE_PALETTED_TEXTURE + //Hurdler: not really supported and not tested recently + if (glColorTableEXT && + (pTexInfo->grInfo.format == GR_TEXFMT_P_8) && + !(pTexInfo->flags & TF_CHROMAKEYED)) + { + glColorTableEXT(GL_TEXTURE_2D, GL_RGB8, 256, GL_RGB, GL_UNSIGNED_BYTE, palette_tex); + pglTexImage2D(GL_TEXTURE_2D, 0, GL_COLOR_INDEX8_EXT, w, h, 0, GL_COLOR_INDEX, GL_UNSIGNED_BYTE, pTexInfo->grInfo.data); + } + else +#endif + if (pTexInfo->grInfo.format == GR_TEXFMT_ALPHA_INTENSITY_88) + { + //pglTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); + if (MipMap) + { + pgluBuild2DMipmaps(GL_TEXTURE_2D, GL_LUMINANCE_ALPHA, w, h, GL_RGBA, GL_UNSIGNED_BYTE, ptex); +#ifdef GL_TEXTURE_MIN_LOD + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, 0); +#endif +#ifdef GL_TEXTURE_MAX_LOD + if (pTexInfo->flags & TF_TRANSPARENT) + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 0); // No mippmaps on transparent stuff + else + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 4); +#endif + //pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_LINEAR_MIPMAP_LINEAR); + } + else + pglTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); + } + else + { + if (MipMap) + { + pgluBuild2DMipmaps(GL_TEXTURE_2D, textureformatGL, w, h, GL_RGBA, GL_UNSIGNED_BYTE, ptex); + // Control the mipmap level of detail +#ifdef GL_TEXTURE_MIN_LOD + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, 0); // the lower the number, the higer the detail +#endif +#ifdef GL_TEXTURE_MAX_LOD + if (pTexInfo->flags & TF_TRANSPARENT) + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 0); // No mippmaps on transparent stuff + else + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 5); +#endif + } + else + pglTexImage2D(GL_TEXTURE_2D, 0, textureformatGL, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); + } +#endif +#endif + + if (pTexInfo->flags & TF_WRAPX) + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + else + Clamp2D(GL_TEXTURE_WRAP_S); + + if (pTexInfo->flags & TF_WRAPY) + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + else + Clamp2D(GL_TEXTURE_WRAP_T); + + if (maximumAnisotropy) + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, anisotropic_filter); + + pTexInfo->nextmipmap = NULL; + if (gr_cachetail) + { // insertion en fin de liste + gr_cachetail->nextmipmap = pTexInfo; + gr_cachetail = pTexInfo; + } + else // initialisation de la liste + gr_cachetail = gr_cachehead = pTexInfo; + } +#ifdef MINI_GL_COMPATIBILITY + switch (pTexInfo->flags) + { + case 0 : + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); + break; + default: + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + break; + } +#endif +} + + +// -----------------+ +// DrawPolygon : Render a polygon, set the texture, set render mode +// -----------------+ +EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, + //FTextureInfo *pTexInfo, + FOutVector *pOutVerts, + FUINT iNumPts, + FBITFIELD PolyFlags) +{ + FUINT i; +#ifndef MINI_GL_COMPATIBILITY + FUINT j; +#endif + GLRGBAFloat c = {0,0,0,0}; + +#ifdef MINI_GL_COMPATIBILITY + if (PolyFlags & PF_Corona) + PolyFlags &= ~PF_NoDepthTest; +#else + if ((PolyFlags & PF_Corona) && (oglflags & GLF_NOZBUFREAD)) + PolyFlags &= ~(PF_NoDepthTest|PF_Corona); +#endif + + SetBlend(PolyFlags); //TODO: inline (#pragma..) + + // If Modulated, mix the surface colour to the texture + if ((CurrentPolyFlags & PF_Modulated) && pSurf) + { + if (pal_col) + { // hack for non-palettized mode + c.red = (const_pal_col.red +byte2float[pSurf->FlatColor.s.red]) /2.0f; + c.green = (const_pal_col.green+byte2float[pSurf->FlatColor.s.green])/2.0f; + c.blue = (const_pal_col.blue +byte2float[pSurf->FlatColor.s.blue]) /2.0f; + c.alpha = byte2float[pSurf->FlatColor.s.alpha]; + } + else + { + c.red = byte2float[pSurf->FlatColor.s.red]; + c.green = byte2float[pSurf->FlatColor.s.green]; + c.blue = byte2float[pSurf->FlatColor.s.blue]; + c.alpha = byte2float[pSurf->FlatColor.s.alpha]; + } + +#ifdef MINI_GL_COMPATIBILITY + pglColor4f(c.red, c.green, c.blue, c.alpha); +#else + pglColor4fv(&c.red); // is in RGBA float format +#endif + } + + // this test is added for new coronas' code (without depth buffer) + // I think I should do a separate function for drawing coronas, so it will be a little faster +#ifndef MINI_GL_COMPATIBILITY + if (PolyFlags & PF_Corona) // check to see if we need to draw the corona + { + //rem: all 8 (or 8.0f) values are hard coded: it can be changed to a higher value + GLfloat buf[8][8]; + GLdouble cx, cy, cz; + GLdouble px = 0.0f, py = 0.0f, pz = -1.0f; + GLfloat scalef = 0.0f; + + cx = (pOutVerts[0].x + pOutVerts[2].x) / 2.0f; // we should change the coronas' ... + cy = (pOutVerts[0].y + pOutVerts[2].y) / 2.0f; // ... code so its only done once. + cz = pOutVerts[0].z; + + // I dont know if this is slow or not + GLProject(cx, cy, cz, &px, &py, &pz); + //DBG_Printf("Projection: (%f, %f, %f)\n", px, py, pz); + + if ((pz < 0.0l) || + (px < -8.0l) || + (py < viewport[1]-8.0l) || + (px > viewport[2]+8.0l) || + (py > viewport[1]+viewport[3]+8.0l)) + return; + + // the damned slow glReadPixels functions :( + pglReadPixels((INT32)px-4, (INT32)py, 8, 8, GL_DEPTH_COMPONENT, GL_FLOAT, buf); + //DBG_Printf("DepthBuffer: %f %f\n", buf[0][0], buf[3][3]); + + for (i = 0; i < 8; i++) + for (j = 0; j < 8; j++) + scalef += (pz > buf[i][j]+0.00005f) ? 0 : 1; + + // quick test for screen border (not 100% correct, but looks ok) + if (px < 4) scalef -= (GLfloat)(8*(4-px)); + if (py < viewport[1]+4) scalef -= (GLfloat)(8*(viewport[1]+4-py)); + if (px > viewport[2]-4) scalef -= (GLfloat)(8*(4-(viewport[2]-px))); + if (py > viewport[1]+viewport[3]-4) scalef -= (GLfloat)(8*(4-(viewport[1]+viewport[3]-py))); + + scalef /= 64; + //DBG_Printf("Scale factor: %f\n", scalef); + + if (scalef < 0.05f) + return; + + c.alpha *= scalef; // change the alpha value (it seems better than changing the size of the corona) + pglColor4fv(&c.red); + } +#endif + if (PolyFlags & PF_MD2) + return; + + pglBegin(GL_TRIANGLE_FAN); + for (i = 0; i < iNumPts; i++) + { + pglTexCoord2f(pOutVerts[i].sow, pOutVerts[i].tow); + //Hurdler: test code: -pOutVerts[i].z => pOutVerts[i].z + pglVertex3f(pOutVerts[i].x, pOutVerts[i].y, pOutVerts[i].z); + //pglVertex3f(pOutVerts[i].x, pOutVerts[i].y, -pOutVerts[i].z); + } + pglEnd(); + + if (PolyFlags & PF_RemoveYWrap) + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + + if (PolyFlags & PF_ForceWrapX) + Clamp2D(GL_TEXTURE_WRAP_S); + + if (PolyFlags & PF_ForceWrapY) + Clamp2D(GL_TEXTURE_WRAP_T); +} + + +// ========================================================================== +// +// ========================================================================== +EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value) +{ + switch (IdState) + { + +#if 0 + case 77: + { + //08/01/00: Hurdler this is a test for mirror + if (!Value) + ClearBuffer(false, true, 0); // clear depth buffer + break; + } +#endif + + case HWD_SET_PALETTECOLOR: + { + pal_col = Value; + const_pal_col.blue = byte2float[((Value>>16)&0xff)]; + const_pal_col.green = byte2float[((Value>>8)&0xff)]; + const_pal_col.red = byte2float[((Value)&0xff)]; + break; + } + + case HWD_SET_FOG_COLOR: + { + GLfloat fogcolor[4]; + + fogcolor[0] = byte2float[((Value>>16)&0xff)]; + fogcolor[1] = byte2float[((Value>>8)&0xff)]; + fogcolor[2] = byte2float[((Value)&0xff)]; + fogcolor[3] = 0x0; + pglFogfv(GL_FOG_COLOR, fogcolor); + break; + } + case HWD_SET_FOG_DENSITY: + pglFogf(GL_FOG_DENSITY, Value*1200/(500*1000000.0f)); + break; + + case HWD_SET_FOG_MODE: + if (Value) + { + pglEnable(GL_FOG); + // experimental code + /* + switch (Value) + { + case 1: + glFogi(GL_FOG_MODE, GL_LINEAR); + pglFogf(GL_FOG_START, -1000.0f); + pglFogf(GL_FOG_END, 2000.0f); + break; + case 2: + glFogi(GL_FOG_MODE, GL_EXP); + break; + case 3: + glFogi(GL_FOG_MODE, GL_EXP2); + break; + } + */ + } + else + pglDisable(GL_FOG); + break; + + case HWD_SET_POLYGON_SMOOTH: +#ifdef KOS_GL_COMPATIBILITY // GL_POLYGON_SMOOTH_HINT + if (Value) + pglHint(GL_POLYGON_SMOOTH_HINT,GL_NICEST); + else + pglHint(GL_POLYGON_SMOOTH_HINT,GL_FASTEST); +#else + if (Value) + pglEnable(GL_POLYGON_SMOOTH); + else + pglDisable(GL_POLYGON_SMOOTH); +#endif + break; + + case HWD_SET_TEXTUREFILTERMODE: + switch (Value) + { +#ifdef KOS_GL_COMPATIBILITY + case HWD_SET_TEXTUREFILTER_TRILINEAR: + case HWD_SET_TEXTUREFILTER_BILINEAR: + min_filter = mag_filter = GL_FILTER_BILINEAR; + break; + case HWD_SET_TEXTUREFILTER_POINTSAMPLED: + min_filter = mag_filter = GL_FILTER_NONE; + case HWD_SET_TEXTUREFILTER_MIXED1: + min_filter = GL_FILTER_NONE; + mag_filter = GL_LINEAR; + case HWD_SET_TEXTUREFILTER_MIXED2: + min_filter = GL_LINEAR; + mag_filter = GL_FILTER_NONE; + break; + case HWD_SET_TEXTUREFILTER_MIXED3: + min_filter = GL_FILTER_BILINEAR; + mag_filter = GL_FILTER_NONE; + break; +#elif !defined (MINI_GL_COMPATIBILITY) + case HWD_SET_TEXTUREFILTER_TRILINEAR: + min_filter = GL_LINEAR_MIPMAP_LINEAR; + mag_filter = GL_LINEAR; + MipMap = GL_TRUE; + break; + case HWD_SET_TEXTUREFILTER_BILINEAR: + min_filter = mag_filter = GL_LINEAR; + MipMap = GL_FALSE; + break; + case HWD_SET_TEXTUREFILTER_POINTSAMPLED: + min_filter = mag_filter = GL_NEAREST; + MipMap = GL_FALSE; + break; + case HWD_SET_TEXTUREFILTER_MIXED1: + min_filter = GL_NEAREST; + mag_filter = GL_LINEAR; + MipMap = GL_FALSE; + break; + case HWD_SET_TEXTUREFILTER_MIXED2: + min_filter = GL_LINEAR; + mag_filter = GL_NEAREST; + MipMap = GL_FALSE; + break; + case HWD_SET_TEXTUREFILTER_MIXED3: + min_filter = GL_LINEAR_MIPMAP_LINEAR; + mag_filter = GL_NEAREST; + MipMap = GL_TRUE; + break; +#endif + default: +#ifdef KOS_GL_COMPATIBILITY + min_filter = mag_filter = GL_FILTER_NONE; +#else + mag_filter = GL_LINEAR; + min_filter = GL_NEAREST; +#endif + } +#ifndef STATIC_OPENGL + if (!pgluBuild2DMipmaps) + { + MipMap = GL_FALSE; + min_filter = GL_LINEAR; + } +#endif + Flush(); //??? if we want to change filter mode by texture, remove this + break; + + case HWD_SET_TEXTUREANISOTROPICMODE: + anisotropic_filter = min(Value,maximumAnisotropy); + if (maximumAnisotropy) + Flush(); //??? if we want to change filter mode by texture, remove this + break; + + default: + break; + } +} + +// -----------------+ +// HWRAPI DrawMD2 : Draw an MD2 model with glcommands +// -----------------+ +EXPORT void HWRAPI(DrawMD2i) (INT32 *gl_cmd_buffer, md2_frame_t *frame, UINT32 duration, UINT32 tics, md2_frame_t *nextframe, FTransform *pos, float scale, UINT8 flipped, UINT8 *color) +{ + INT32 val, count, pindex; + GLfloat s, t; + GLfloat ambient[4]; + GLfloat diffuse[4]; + + float pol; + UINT32 newtime; + float scalex, scaley, scalez; + scalex = scaley = scalez = scale; + + if (duration == 0) + duration = 1; + + newtime = (duration - tics) + 1; + + pol = (newtime)/(float)duration; + + if (pol > 1.0f) + pol = 1.0f; + + if (pol < 0.0f) + pol = 0.0f; + + if (color) + { + ambient[0] = (color[0]/255.0f); + ambient[1] = (color[1]/255.0f); + ambient[2] = (color[2]/255.0f); + ambient[3] = (color[3]/255.0f); + diffuse[0] = (color[0]/255.0f); + diffuse[1] = (color[1]/255.0f); + diffuse[2] = (color[2]/255.0f); + diffuse[3] = (color[3]/255.0f); + + if (ambient[0] > 0.75f) + ambient[0] = 0.75f; + if (ambient[1] > 0.75f) + ambient[1] = 0.75f; + if (ambient[2] > 0.75f) + ambient[2] = 0.75f; + + if (color[3] < 255) + { + pglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + pglDepthMask(GL_FALSE); + } + } + + pglEnable(GL_CULL_FACE); + + if (flipped) + pglCullFace(GL_FRONT); + else + pglCullFace(GL_BACK); + + pglShadeModel(GL_SMOOTH); + if (color) + { +#ifdef GL_LIGHT_MODEL_AMBIENT + pglEnable(GL_LIGHTING); + pglMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambient); + pglMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse); +#endif + } + + DrawPolygon(NULL, NULL, 0, PF_Masked|PF_Modulated|PF_Occlude|PF_Clip); + + pglPushMatrix(); // should be the same as glLoadIdentity + //Hurdler: now it seems to work + pglTranslatef(pos->x, pos->z, pos->y); + if (flipped) + scaley = -scaley; + pglRotatef(pos->angley, 0.0f, -1.0f, 0.0f); + pglRotatef(pos->anglex, -1.0f, 0.0f, 0.0f); + //pglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // alpha = level of transparency + + val = *gl_cmd_buffer++; + + while (val != 0) + { + if (val < 0) + { + pglBegin(GL_TRIANGLE_FAN); + count = -val; + } + else + { + pglBegin(GL_TRIANGLE_STRIP); + count = val; + } + + while (count--) + { + s = *(float *) gl_cmd_buffer++; + t = *(float *) gl_cmd_buffer++; + pindex = *gl_cmd_buffer++; + + pglTexCoord2f(s, t); + + if (!nextframe) + { + pglNormal3f(frame->vertices[pindex].normal[0], + frame->vertices[pindex].normal[1], + frame->vertices[pindex].normal[2]); + + pglVertex3f(frame->vertices[pindex].vertex[0]*scalex/2.0f, + frame->vertices[pindex].vertex[1]*scaley/2.0f, + frame->vertices[pindex].vertex[2]*scalez/2.0f); + } + else + { + // Interpolate + float px1 = frame->vertices[pindex].vertex[0]*scalex/2.0f; + float px2 = nextframe->vertices[pindex].vertex[0]*scalex/2.0f; + float py1 = frame->vertices[pindex].vertex[1]*scaley/2.0f; + float py2 = nextframe->vertices[pindex].vertex[1]*scaley/2.0f; + float pz1 = frame->vertices[pindex].vertex[2]*scalez/2.0f; + float pz2 = nextframe->vertices[pindex].vertex[2]*scalez/2.0f; + float nx1 = frame->vertices[pindex].normal[0]; + float nx2 = nextframe->vertices[pindex].normal[0]; + float ny1 = frame->vertices[pindex].normal[1]; + float ny2 = nextframe->vertices[pindex].normal[1]; + float nz1 = frame->vertices[pindex].normal[2]; + float nz2 = nextframe->vertices[pindex].normal[2]; + + pglNormal3f((nx1 + pol * (nx2 - nx1)), + (ny1 + pol * (ny2 - ny1)), + (nz1 + pol * (nz2 - nz1))); + pglVertex3f((px1 + pol * (px2 - px1)), + (py1 + pol * (py2 - py1)), + (pz1 + pol * (pz2 - pz1))); + } + } + + pglEnd(); + + val = *gl_cmd_buffer++; + } + pglPopMatrix(); // should be the same as glLoadIdentity + if (color) + pglDisable(GL_LIGHTING); + pglShadeModel(GL_FLAT); + pglDepthMask(GL_TRUE); + pglDisable(GL_CULL_FACE); +} + +EXPORT void HWRAPI(DrawMD2) (INT32 *gl_cmd_buffer, md2_frame_t *frame, FTransform *pos, float scale) +{ + DrawMD2i(gl_cmd_buffer, frame, 0, 0, NULL, pos, scale, false, NULL); +} + +// -----------------+ +// SetTransform : +// -----------------+ +EXPORT void HWRAPI(SetTransform) (FTransform *stransform) +{ + static INT32 special_splitscreen; + pglLoadIdentity(); + if (stransform) + { + // keep a trace of the transformation for md2 + memcpy(&md2_transform, stransform, sizeof (md2_transform)); + pglScalef(stransform->scalex, stransform->scaley, -stransform->scalez); + pglRotatef(stransform->anglex , 1.0f, 0.0f, 0.0f); + pglRotatef(stransform->angley+270.0f, 0.0f, 1.0f, 0.0f); + pglTranslatef(-stransform->x, -stransform->z, -stransform->y); + + pglMatrixMode(GL_PROJECTION); + pglLoadIdentity(); + special_splitscreen = (stransform->splitscreen && stransform->fovxangle == 90.0f); + if (special_splitscreen) + GLPerspective(53.13l, 2*ASPECT_RATIO); // 53.13 = 2*atan(0.5) + else + GLPerspective(stransform->fovxangle, ASPECT_RATIO); +#ifndef MINI_GL_COMPATIBILITY + pglGetDoublev(GL_PROJECTION_MATRIX, projMatrix); // added for new coronas' code (without depth buffer) +#endif + pglMatrixMode(GL_MODELVIEW); + } + else + { + pglScalef(1.0f, 1.0f, -1.0f); + + pglMatrixMode(GL_PROJECTION); + pglLoadIdentity(); + if (special_splitscreen) + GLPerspective(53.13l, 2*ASPECT_RATIO); // 53.13 = 2*atan(0.5) + else + //Hurdler: is "fov" correct? + GLPerspective(fov, ASPECT_RATIO); +#ifndef MINI_GL_COMPATIBILITY + pglGetDoublev(GL_PROJECTION_MATRIX, projMatrix); // added for new coronas' code (without depth buffer) +#endif + pglMatrixMode(GL_MODELVIEW); + } + +#ifndef MINI_GL_COMPATIBILITY + pglGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix); // added for new coronas' code (without depth buffer) +#endif +} + +EXPORT INT32 HWRAPI(GetTextureUsed) (void) +{ + FTextureInfo* tmp = gr_cachehead; + INT32 res = 0; + + while (tmp) + { + res += tmp->height*tmp->width*(screen_depth/8); + tmp = tmp->nextmipmap; + } + return res; +} + +EXPORT INT32 HWRAPI(GetRenderVersion) (void) +{ + return VERSION; +} + +#ifdef SHUFFLE +EXPORT void HWRAPI(PostImgRedraw) (float points[SCREENVERTS][SCREENVERTS][2]) +{ + INT32 x, y; + float float_x, float_y, float_nextx, float_nexty; + float xfix, yfix; + INT32 texsize = 2048; + + // Use a power of two texture, dammit + if(screen_width <= 1024) + texsize = 1024; + if(screen_width <= 512) + texsize = 512; + + // X/Y stretch fix for all resolutions(!) + xfix = (float)(texsize)/((float)((screen_width)/(float)(SCREENVERTS-1))); + yfix = (float)(texsize)/((float)((screen_height)/(float)(SCREENVERTS-1))); + + pglDisable(GL_DEPTH_TEST); + pglDisable(GL_BLEND); + pglBegin(GL_QUADS); + + // Draw a black square behind the screen texture, + // so nothing shows through the edges + pglColor4f(1.0f, 1.0f, 1.0f, 1.0f); + pglVertex3f(-16.0f, -16.0f, 6.0f); + pglVertex3f(-16.0f, 16.0f, 6.0f); + pglVertex3f(16.0f, 16.0f, 6.0f); + pglVertex3f(16.0f, -16.0f, 6.0f); + + for(x=0;x +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=r_opengl - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "r_opengl.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "r_opengl.mak" CFG="r_opengl - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "r_opengl - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "r_opengl - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "r_opengl - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "r_opengl___Win32_Release" +# PROP BASE Intermediate_Dir "r_opengl___Win32_Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "..\..\..\bin\VC\Release\r_opengl" +# PROP Intermediate_Dir "..\..\..\objs\VC\Release\r_opengl" +# PROP Ignore_Export_Lib 1 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "R_OPENGL_EXPORTS" /YX /FD /c +# ADD CPP /nologo /G5 /W3 /GX /Zi /O2 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "__WIN32__" /D "__MSC__" /D "USE_WGL_SWAP" /FR /FD /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x80c /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 +# ADD LINK32 user32.lib gdi32.lib /nologo /dll /pdb:"..\..\..\bin\VC\Release\r_opengl.pdb" /machine:I386 /out:"C:\srb2demo2\r_opengl.dll" +# SUBTRACT LINK32 /pdb:none /debug + +!ELSEIF "$(CFG)" == "r_opengl - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "..\..\..\objs\Debug" +# PROP BASE Intermediate_Dir "..\..\..\objs\Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "..\..\..\bin\VC\Debug\r_opengl" +# PROP Intermediate_Dir "..\..\..\objs\VC\Debug\r_opengl" +# PROP Ignore_Export_Lib 1 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "R_OPENGL_EXPORTS" /YX /FD /GZ /c +# ADD CPP /nologo /G6 /W4 /Gm /GX /ZI /Od /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "__WIN32__" /D "__MSC__" /D "USE_WGL_SWAP" /FR /FD /GZ /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x80c /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 user32.lib gdi32.lib /nologo /dll /pdb:"..\..\..\bin\VC\Debug\r_opengl.pdb" /debug /machine:I386 /out:"C:\srb2demo2\r_opengld.dll" /pdbtype:sept +# SUBTRACT LINK32 /pdb:none + +!ENDIF + +# Begin Target + +# Name "r_opengl - Win32 Release" +# Name "r_opengl - Win32 Debug" +# Begin Source File + +SOURCE=.\ogl_win.c +# End Source File +# Begin Source File + +SOURCE=.\r_opengl.c +# End Source File +# Begin Source File + +SOURCE=.\r_opengl.h +# End Source File +# End Target +# End Project diff --git a/src/hardware/r_opengl/r_opengl.h b/src/hardware/r_opengl/r_opengl.h new file mode 100644 index 000000000..875ac6fba --- /dev/null +++ b/src/hardware/r_opengl/r_opengl.h @@ -0,0 +1,131 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright (C) 1998-2000 by DooM Legacy Team. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +//----------------------------------------------------------------------------- +/// \file +/// \brief OpenGL API for Doom Legacy + +#ifndef _R_OPENGL_H_ +#define _R_OPENGL_H_ + +#ifdef SDL + +#ifdef _MSC_VER +#pragma warning(disable : 4214 4244) +#endif + +#include "SDL_opengl.h" //Alam_GBC: Simple, yes? + +#ifdef _MSC_VER +#pragma warning(default : 4214 4244) +#endif + +#else +#include +#include +#endif + +#define _CREATE_DLL_ // necessary for Unix AND Windows +#include "../../doomdef.h" +#include "../hw_drv.h" + +// ========================================================================== +// DEFINITIONS +// ========================================================================== + +#define MIN(x,y) (((x)<(y)) ? (x) : (y)) +#define MAX(x,y) (((x)>(y)) ? (x) : (y)) + +#undef DEBUG_TO_FILE // maybe defined in previous *.h +#define DEBUG_TO_FILE // output debugging msgs to ogllog.txt +#if defined ( SDL ) && !defined ( LOGMESSAGES ) +#undef DEBUG_TO_FILE +#endif + +#ifndef DRIVER_STRING +// #define USE_PALETTED_TEXTURE +#define DRIVER_STRING "HWRAPI Init(): SRB2 OpenGL renderer" // Tails +#endif + +// ========================================================================== +// PROTOS +// ========================================================================== + +boolean LoadGL(void); +void *GetGLFunc(const char *proc); +boolean SetupGLfunc(void); +void Flush(void); +INT32 isExtAvailable(const char *extension, const GLubyte *start); +boolean SetupPixelFormat(INT32 WantColorBits, INT32 WantStencilBits, INT32 WantDepthBits); +void SetModelView(GLint w, GLint h); +void SetStates(void); +FUNCMATH float byteasfloat(UINT8 fbyte); +#ifdef USE_PALETTED_TEXTURE +extern PFNGLCOLORTABLEEXTPROC glColorTableEXT; +extern GLubyte palette_tex[256*3]; +#endif + +#ifndef GL_EXT_texture_filter_anisotropic +#define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE +#define GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF +#endif + +#ifdef USE_WGL_SWAP +typedef BOOL (APIENTRY *PFNWGLEXTSWAPCONTROLPROC) (int); +typedef int (APIENTRY *PFNWGLEXTGETSWAPINTERVALPROC) (void); +extern PFNWGLEXTSWAPCONTROLPROC wglSwapIntervalEXT; +extern PFNWGLEXTGETSWAPINTERVALPROC wglGetSwapIntervalEXT; +#endif + +#ifdef STATIC_OPENGL +#define pglClear glClear +#define pglGetIntegerv glGetIntegerv +#define pglGetString glGetString +#else +/* 1.0 Miscellaneous functions */ +typedef void (APIENTRY * PFNglClear) (GLbitfield mask); +extern PFNglClear pglClear; +typedef void (APIENTRY * PFNglGetIntegerv) (GLenum pname, GLint *params); +extern PFNglGetIntegerv pglGetIntegerv; +typedef const GLubyte* (APIENTRY * PFNglGetString) (GLenum name); +extern PFNglGetString pglGetString; +#endif + +// ========================================================================== +// GLOBAL +// ========================================================================== + +extern const GLubyte *gl_extensions; +extern RGBA_t myPaletteData[]; +#ifndef SDL +extern FILE *logstream; +#endif +extern GLint screen_width; +extern GLint screen_height; +extern GLbyte screen_depth; +extern GLint maximumAnisotropy; + +/** \brief OpenGL flags for video driver +*/ +extern INT32 oglflags; +extern GLint textureformatGL; + +typedef enum +{ + GLF_NOZBUFREAD = 0x01, + GLF_NOTEXENV = 0x02, +} oglflags_t; + +#endif diff --git a/src/hardware/s_ds3d/s_ds3d.c b/src/hardware/s_ds3d/s_ds3d.c new file mode 100644 index 000000000..2cbf95599 --- /dev/null +++ b/src/hardware/s_ds3d/s_ds3d.c @@ -0,0 +1,1237 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright (C) 2001 by DooM Legacy Team. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +//----------------------------------------------------------------------------- +/// \file +/// \brief General driver for 3D sound system +/// +/// Implementend via DirectSound3D API + +#define INITGUID +//#define WIN32_LEAN_AND_MEAN +#define RPC_NO_WINDOWS_H +#include +#include +#define DIRECTSOUND_VERSION 0x0700 /* version 7.0 */ + +#ifdef __MINGW32__ +#define NONAMELESSUNION +#endif +#include + +#if (defined (DIRECTSOUND_VERSION) && (DIRECTSOUND_VERSION >= 0x0700)) +#define DX7 //Enable DX7 or up only code +#undef DUMMYUNIONNAMEN +#endif + +#ifdef __MINGW32__ +//#undef DX7 +#endif + +#define _CREATE_DLL_ +#include "../hw3dsdrv.h" +#include "../../m_fixed.h" +#include "../../doomdef.h" +//#define VERSIONSTRING "v1.08" + +#undef DEBUG_TO_FILE +#define DEBUG_TO_FILE + +#if defined ( SDL ) && !defined ( LOGMESSAGES ) +#undef DEBUG_TO_FILE +#endif + + +// Internal sound stack +typedef struct stack_snd_s +{ + // Sound data + LPDIRECTSOUNDBUFFER dsbuffer; + + // 3D data of 3D source + LPDIRECTSOUND3DBUFFER dsbuffer3D; // 3D data + + // Current parameters of 3D source + // Valid only when source is 3D source + // (dsbuffer3D is not NULL) + DS3DBUFFER parameters; + + // Currently unused + INT32 sfx_id; + + // Currently unused + INT32 LRU; + + // Flag of static source + // Driver does not manage intrenally such sources + INT32 permanent; + +} stack_t; + +// Just for now... +#define SOUND_ALLOCATE_DELTA 16 // Amount of sources per stack incrementation +#define MAX_LRU 16 // Maximum iterations to keep source in stack + +static stack_t *_stack; // Sound stack +static INT32 allocated_sounds; // Size of stack + +static INT32 srate; // Default sample rate + + +// output all debugging messages to this file +#if defined (DEBUG_TO_FILE) +#include +FILE *logstream = NULL; +#endif + +static LPDIRECTSOUND DSnd = NULL; // Main DirectSound object +static LPDIRECTSOUNDBUFFER PrimaryBuffer = NULL; // +static LPDIRECTSOUND3DLISTENER Listener = NULL; // + +static DS3DLISTENER listener_parms; // Listener papameters + +#ifdef DX7 +static BOOL virtualization; // TRUE if HRTF virtualization enabled +#endif + +static DWORD update_mode; // Current update mode of listener +//static DWORD max_3d_buffers; + +static I_Error_t I_ErrorDS3D = NULL; + +//static stack_snd_t sound_stack[MAX_SOUNDS]; + +// Safe buffer release +#define RELEASE_BUFFER(buf) {if (buf) { IDirectSoundBuffer_Release(buf); (buf) = NULL; }} +#define RELEASE_3DBUFFER(buf) {if (buf) { IDirectSound3DBuffer_Release(buf); (buf) = NULL; }} + +// Default flags for buffers +#define _2DSOURCE_FLAGS (DSBCAPS_CTRLPAN | DSBCAPS_CTRLVOLUME | DSBCAPS_STICKYFOCUS | DSBCAPS_STATIC | DSBCAPS_CTRLFREQUENCY) +#define _3DSOURCE_FLAGS (DSBCAPS_CTRL3D | DSBCAPS_STATIC | DSBCAPS_MUTE3DATMAXDISTANCE | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLFREQUENCY) + + +enum {IS_2DSOURCE = 0, IS_3DSOURCE = 1}; + +#define NEW_HANDLE -1 + +#ifdef _WINDOWS +BOOL WINAPI DllMain(HINSTANCE hinstDLL, // handle to DLL module + DWORD fdwReason, // reason for calling function + LPVOID lpvReserved) // reserved +{ + // Perform actions based on the reason for calling + UNREFERENCED_PARAMETER(lpvReserved); + switch ( fdwReason ) + { + case DLL_PROCESS_ATTACH: + // Initialize once for each new process. + // Return FALSE to fail DLL load. +#ifdef DEBUG_TO_FILE + logstream = fopen("s_ds3d.log", "wt"); + if (logstream == NULL) + return FALSE; +#endif + DisableThreadLibraryCalls(hinstDLL); + break; + + case DLL_THREAD_ATTACH: + // Do thread-specific initialization. + break; + + case DLL_THREAD_DETACH: + // Do thread-specific cleanup. + break; + + case DLL_PROCESS_DETACH: + // Perform any necessary cleanup. +#ifdef DEBUG_TO_FILE + if (logstream) + { + fclose(logstream); + logstream = NULL; + } +#endif + break; + } + return TRUE; // Successful DLL_PROCESS_ATTACH. +} +#endif + +// ************************************************************************** +// FUNCTIONS +// ************************************************************************** + +/*************************************************************** + * + * DBG_Printf + * Output error messages to debug log if DEBUG_TO_FILE is defined, + * else do nothing + * + *************************************************************** + */ +// -----------------+ +// DBG_Printf : Output error messages to debug log if DEBUG_TO_FILE is defined, +// : else do nothing +// Returns : +// -----------------+ +void DBG_Printf(const char *lpFmt, ... ) +{ +#ifdef DEBUG_TO_FILE + char str[4096] = ""; + va_list arglist; + + va_start(arglist, lpFmt); + vsnprintf(str, 4096, lpFmt, arglist); + va_end(arglist); + + if (logstream) + fwrite(str, strlen(str), 1, logstream); +#endif +} + + +/*************************************************************** + * + * Grow intrenal sound stack by SOUND_ALLOCATE_DELTA amount + * + *************************************************************** + */ +static BOOL reallocate_stack(void) +{ + stack_t *new_stack; + + if (_stack) + new_stack = realloc(_stack, sizeof (stack_t) * (allocated_sounds + SOUND_ALLOCATE_DELTA)); + else + new_stack = malloc(sizeof (stack_t) * (allocated_sounds + SOUND_ALLOCATE_DELTA)); + if (new_stack) + { + _stack = new_stack; + ZeroMemory(&_stack[allocated_sounds], SOUND_ALLOCATE_DELTA * sizeof (stack_t)); + allocated_sounds += SOUND_ALLOCATE_DELTA; + } + return (new_stack != NULL); +} + + +/*************************************************************** + * + * Destroys source in stack + * + *************************************************************** + */ +static void kill_sound(stack_t *snd) +{ + //stack_t *snd = _stack + handle; + + if (snd->dsbuffer3D) + RELEASE_3DBUFFER(snd->dsbuffer3D); + + if (snd->dsbuffer) + RELEASE_BUFFER(snd->dsbuffer); + + ZeroMemory(snd, sizeof (stack_t)); +} + + +/*************************************************************** + * + * Returns TRUE if source currently playing + * + *************************************************************** + */ +static BOOL is_playing(stack_t *snd) +{ + DWORD status; + LPDIRECTSOUNDBUFFER dsbuffer = snd->dsbuffer; + + if (dsbuffer == NULL) + return 0; + + IDirectSoundBuffer_GetStatus(dsbuffer, &status); + + return (status & (DSBSTATUS_PLAYING | DSBSTATUS_LOOPING)); +} + + +/*************************************************************** + * + * Creates DirectSound buffer and fills with sound data + * NULL sound data pointer are valid (empty buffer + * will be created) + * + *************************************************************** + */ +static LPDIRECTSOUNDBUFFER create_buffer (void *data, INT32 length, BOOL as3d) +{ + LPDIRECTSOUNDBUFFER dsbuffer; + HRESULT hr; + WAVEFORMATEX wfm; + DSBUFFERDESC dsbdesc; + LPVOID lpvAudio1; // receives address of lock start + DWORD dwBytes1; // receives number of bytes locked + LPVOID lpvAudio2; // receives address of lock start + DWORD dwBytes2; // receives number of bytes locked + + ZeroMemory(&wfm, sizeof (WAVEFORMATEX)); + wfm.wFormatTag = WAVE_FORMAT_PCM; + wfm.nChannels = 1; + wfm.nSamplesPerSec = data?*((UINT16 *)data+1):srate; //mostly 11025, but some at 22050. + wfm.wBitsPerSample = 8; + wfm.nBlockAlign = (WORD)(wfm.wBitsPerSample / 8 * wfm.nChannels); + wfm.nAvgBytesPerSec = wfm.nSamplesPerSec * wfm.nBlockAlign; + + // Set up DSBUFFERDESC structure. + ZeroMemory (&dsbdesc, sizeof (DSBUFFERDESC) ); + dsbdesc.dwSize = sizeof (DSBUFFERDESC); + dsbdesc.dwFlags = as3d?_3DSOURCE_FLAGS:_2DSOURCE_FLAGS; + dsbdesc.dwBufferBytes = length; + dsbdesc.lpwfxFormat = &wfm; + + // DirectX 7.0 and above! + // Try to enable full HRTF virtualization algorithm for + // two-speakers or headphones +#ifdef DX7 + if (as3d) + dsbdesc.guid3DAlgorithm = (virtualization?DS3DALG_HRTF_FULL:DS3DALG_DEFAULT); +#endif + + hr = IDirectSound_CreateSoundBuffer (DSnd, &dsbdesc, &dsbuffer, NULL); + + // CreateSoundBuffer might return DS_NO_VIRTUALIZATION so uses FAILED + // macro rather than check explictly for DS_OK value + if (FAILED(hr)) + { + DBG_Printf("CreateSoundBuffer FAILED. Code %d\n", hr); + return NULL; + } + + if (data) + { + hr = IDirectSoundBuffer_Lock(dsbuffer, 0, length, &lpvAudio1, &dwBytes1, &lpvAudio2, &dwBytes2, 0); + + // If DSERR_BUFFERLOST is returned, restore and retry lock. + if (hr == DSERR_BUFFERLOST) + { + hr = IDirectSoundBuffer_Restore(dsbuffer); + if (FAILED(hr)) + I_ErrorDS3D("Restore fail on %x, code %d\n",dsbuffer, hr); + hr = IDirectSoundBuffer_Lock(dsbuffer, 0, length, &lpvAudio1, &dwBytes1, &lpvAudio2, &dwBytes2, 0); + if (FAILED(hr)) + I_ErrorDS3D("Lock fail(2) on %x, code %d\n",dsbuffer, hr); + } + else + if (FAILED(hr)) + I_ErrorDS3D("Lock fail(1) on %x, code %d\n",dsbuffer, hr); + + // copy wave data into the buffer (note: dwBytes1 should equal to dsbdesc->dwBufferBytes ...) + CopyMemory (lpvAudio1, (LPBYTE)data+8, dwBytes1); + + if ( dwBytes2 && lpvAudio2) + CopyMemory(lpvAudio2, ((LPBYTE)data + 8) + dwBytes1, dwBytes2); + + + // finally, unlock the buffer + hr = IDirectSoundBuffer_Unlock(dsbuffer, lpvAudio1, dwBytes1, lpvAudio2, dwBytes2); + + if (FAILED(hr)) + I_ErrorDS3D("Unlock fail on %x, code %d\n",dsbuffer, hr); + } + + return dsbuffer; +} + + +/*************************************************************** + * + * Creates 3D source data buffer + * + *************************************************************** + */ +static LPDIRECTSOUND3DBUFFER create_3dbuffer(LPDIRECTSOUNDBUFFER dsbuffer, LPDIRECTSOUND3DBUFFER source3d) +{ + HRESULT hr; + + hr = IDirectSoundBuffer_QueryInterface(dsbuffer, + &IID_IDirectSound3DBuffer, (void **)&source3d); + + if (FAILED(hr)) + { + DBG_Printf("Couldn't obtain 3D Buffer interface. Code %d\n", hr); + return NULL; + } +#ifdef DX7 + if (hr == DS_NO_VIRTUALIZATION) + { + DBG_Printf("The 3D virtualization is not supported under this OS.\n"); + virtualization = FALSE; + } +#endif + return source3d; +} + + +/*************************************************************** + * + * Returns free (unused) source stack slot + * If none available sound stack will be increased + * + *************************************************************** + */ +static INT32 find_handle(INT32 new_sfx_id, INT32 new_is3d) +{ + INT32 free_sfx; + stack_t *snd; + + // At first do look for sound with same sfx ID and reuse it + new_sfx_id = new_is3d = 0; + for (free_sfx = 0, snd = _stack; free_sfx < allocated_sounds; snd++, free_sfx++) + { + + if (snd->permanent) + continue; +/* + if (!is_playing(snd)) + { + if (same_sfx == 0 && snd->sfx_id == new_sfx_id && snd->dsbuffer) + { + same_sfx = i; + continue; + } + + if (snd->sfx_id && ++snd->LRU >= MAX_LRU) + kill_sound(snd); + } +*/ + if (snd->dsbuffer == 0) + break; + //free_sfx = i; + } + + // No suitable resource found so increase sound stack + if (free_sfx == allocated_sounds) + { + DBG_Printf("No free or same sfx found so increase stack (currently %d srcs)\n", allocated_sounds); + free_sfx = reallocate_stack() ? free_sfx : -1; + } + + return free_sfx; +} + + +/*************************************************************** + * + * Recalculates volume from Doom scale to DirectSound scale + * + *************************************************************** + */ +static INT32 recalc_volume(INT32 base_vol, INT32 steps) +{ + return (base_vol * ((DSBVOLUME_MAX-DSBVOLUME_MIN)/4)) / steps + + (DSBVOLUME_MAX - ((DSBVOLUME_MAX-DSBVOLUME_MIN)/4)); +} + + +/*************************************************************** + * + * Updates sound volume of the DirectSound buffer + * + *************************************************************** + */ +static void UpdateSoundVolume (LPDIRECTSOUNDBUFFER lpSnd, INT32 volume) +{ + /*volume = (volume * ((DSBVOLUME_MAX-DSBVOLUME_MIN)/4)) / 256 + + (DSBVOLUME_MAX - ((DSBVOLUME_MAX-DSBVOLUME_MIN)/4)); + + IDirectSoundBuffer_SetVolume (lpSnd, volume);*/ + IDirectSoundBuffer_SetVolume (lpSnd, recalc_volume(volume, 256)); +} + + +// -------------------------------------------------------------------------- +// Update the panning for a secondary buffer, make sure it was created with +// DSBCAPS_CTRLPAN +// -------------------------------------------------------------------------- +#define DSBPAN_RANGE (DSBPAN_RIGHT-(DSBPAN_LEFT)) + +//Doom sounds pan range 0-255 (128 is centre) +#define SEP_RANGE 256 +static void Update2DSoundPanning (LPDIRECTSOUNDBUFFER lpSnd, INT32 sep) +{ + HRESULT hr; + hr = IDirectSoundBuffer_SetPan (lpSnd, (sep * DSBPAN_RANGE)/SEP_RANGE - DSBPAN_RIGHT); + //if (FAILED(hr)) + // DEBFILE(va("SetPan FAILED for sep %d pan %d\n", sep, (sep * DSBPAN_RANGE)/SEP_RANGE - DSBPAN_RIGHT)); +} + + + +/****************************************************************************** + * + * Initialise driver and listener + * + *****************************************************************************/ +EXPORT BOOL HWRAPI( Startup ) (I_Error_t FatalErrorFunction, snddev_t *snd_dev) +{ + HRESULT hr; + DSBUFFERDESC desc; + WAVEFORMATEX wfm; + DSCAPS dscaps; + DWORD speakers; + DWORD speaker_config; + DWORD speaker_geometry; + + I_ErrorDS3D = FatalErrorFunction; + DBG_Printf ("S_DS3D Init(): DirectSound3D driver for SRB2 v1.09"); // Tails + + DBG_Printf("Initialising DirectSound3D...\n"); + hr = DirectSoundCreate( NULL, &DSnd, NULL); + if (FAILED(hr)) + { + DBG_Printf("Failed to obtain DirectSound\n"); + return FALSE; + } + + hr = IDirectSound_SetCooperativeLevel(DSnd, snd_dev->hWnd, snd_dev->cooplevel); + if (FAILED(hr)) + { + DBG_Printf("Couldn't set coopertive level\n"); + return FALSE; + } + + dscaps.dwSize = sizeof (DSCAPS); + + IDirectSound_GetCaps(DSnd, &dscaps); + IDirectSound_GetSpeakerConfig(DSnd, &speakers); + + DBG_Printf("Sound hardware capabilities:\n"); + DBG_Printf(" Driver is %scertified.\n", (dscaps.dwFlags & DSCAPS_CERTIFIED) == DSCAPS_CERTIFIED?"":"not "); + DBG_Printf(" Maximum hardware mixing buffers %d\n", dscaps.dwMaxHwMixingAllBuffers); + DBG_Printf(" Maximum hardware 3D buffers %d\n", dscaps.dwFreeHw3DAllBuffers); + + speaker_config = DSSPEAKER_CONFIG(speakers); + speaker_geometry = DSSPEAKER_GEOMETRY(speakers); + + DBG_Printf("Current speaker configuration: "); + + switch (speaker_config) + { +#ifdef DX7 + case DSSPEAKER_5POINT1: + DBG_Printf("5.1 (5 speakers with subwoofer).\n"); + break; +#endif + case DSSPEAKER_HEADPHONE: + DBG_Printf("headphone.\n"); + break; + + case DSSPEAKER_MONO: + DBG_Printf("single speaker (mono).\n"); + break; + + case DSSPEAKER_QUAD: + DBG_Printf("quadrophonic\n"); + break; + + case DSSPEAKER_SURROUND: + DBG_Printf("surround.\n"); + break; + + case DSSPEAKER_STEREO: + DBG_Printf("stereo with %s geometry ", + speaker_geometry == DSSPEAKER_GEOMETRY_WIDE + ? "wide (arc of 20 deg.)" + : speaker_geometry == DSSPEAKER_GEOMETRY_NARROW + ? "narrow (arc of 10 deg.)" + : speaker_geometry == DSSPEAKER_GEOMETRY_MIN + ? "min (arc of 5 deg.)" + : speaker_geometry == DSSPEAKER_GEOMETRY_MAX + ? "max (arc of 180 deg.)" + : "unknown"); + break; + default: + DBG_Printf("undetectable.\n"); + + } + + update_mode = DS3D_IMMEDIATE; + + // Create primary sound buffer + ZeroMemory(&desc, sizeof (DSBUFFERDESC)); + desc.dwSize = sizeof (DSBUFFERDESC); + desc.dwFlags = DSBCAPS_CTRL3D | DSBCAPS_PRIMARYBUFFER | DSBCAPS_CTRLVOLUME; + desc.dwBufferBytes = 0; + desc.lpwfxFormat = NULL; + + hr = IDirectSound_CreateSoundBuffer(DSnd, &desc, &PrimaryBuffer, NULL); + if (FAILED(hr)) + { + DBG_Printf("CreateSoundBuffer FAILED (ErrNo %d)\n", hr); + return FALSE; + } + + // Query for 3D Listener object + hr = IDirectSoundBuffer_QueryInterface(PrimaryBuffer, + &IID_IDirectSound3DListener, (void **)&Listener); + + if (FAILED(hr)) + { + DBG_Printf("Couldn't obtain 3D Listener interface (ErrNo %d)\n", hr); + return FALSE; + } + + // Set up initial listsner parameters + IDirectSound3DListener_SetDistanceFactor(Listener, 1.0f/72.0f, DS3D_IMMEDIATE); + IDirectSound3DListener_SetRolloffFactor(Listener, 1.6f, DS3D_IMMEDIATE); + //IDirectSound3DListener_SetRolloffFactor(Listener, DS3D_MAXROLLOFFFACTOR, DS3D_IMMEDIATE); + listener_parms.dwSize = sizeof (DS3DLISTENER); + IDirectSound3DListener_GetAllParameters(Listener, &listener_parms); + + ZeroMemory (&wfm, sizeof (WAVEFORMATEX)); + wfm.wFormatTag = WAVE_FORMAT_PCM; + wfm.nChannels = 2; + wfm.nSamplesPerSec = srate = snd_dev->sample_rate; + wfm.wBitsPerSample = (WORD)snd_dev->bps; + wfm.nBlockAlign = (WORD)(wfm.wBitsPerSample / 8 * wfm.nChannels); + wfm.nAvgBytesPerSec = wfm.nSamplesPerSec * wfm.nBlockAlign; + + if (snd_dev->cooplevel >= DSSCL_PRIORITY) + { + hr = IDirectSoundBuffer_SetFormat(PrimaryBuffer, &wfm); + if (FAILED(hr)) + DBG_Printf("Couldn't set primary buffer format.\n"); + + DBG_Printf(" Compacting onboard sound-memory..."); + hr = IDirectSound_Compact(DSnd); + DBG_Printf(" %s\n", SUCCEEDED(hr) ? M_GetText("Done\n") : M_GetText("Failed\n")); + } + +#ifdef DX7 + // Initially enables HRTF virtualization (may be changed later) + virtualization = TRUE; +#endif + + _stack = NULL; + allocated_sounds = 0; + IDirectSoundBuffer_Play(PrimaryBuffer, 0, 0, DSBPLAY_LOOPING); + return reallocate_stack(); +} + + + +/*************************************************************** + * + * Shutdown driver + * + *************************************************************** + */ +EXPORT void HWRAPI( Shutdown ) (void) +{ + INT32 i; + + DBG_Printf ("S_DS3D Shutdown()\n"); + + for (i = 0; i < allocated_sounds; i++) + { + StopSource(i); + kill_sound(_stack + i); + } + + if (_stack) + free(_stack); + + if (Listener) + { + IDirectSound3DListener_Release(Listener); + Listener = NULL; + } + + if (PrimaryBuffer) + RELEASE_BUFFER(PrimaryBuffer); + + if (DSnd) + { + IDirectSound_Release(DSnd); + DSnd = NULL; + } + +} + + + +EXPORT INT32 HWRAPI (IsPlaying) (INT32 handle) +{ + if (handle < 0 || handle >= allocated_sounds) + return FALSE; + + return is_playing(_stack + handle); +} + + +// Calculate sound pitching +static float recalc_pitch(INT32 doom_pitch) +{ + return doom_pitch < NORMAL_PITCH ? + (float)(doom_pitch + NORMAL_PITCH) / (NORMAL_PITCH * 2) + :(float)doom_pitch / (float)NORMAL_PITCH; +} + + +static stack_t *setup_source(INT32 handle, sfx_data_t *sfx, BOOL is_3dsource) +{ + stack_t *snd; + //INT32 handle; + INT32 data_length; + LPDIRECTSOUNDBUFFER dsbuffer = NULL; + LPDIRECTSOUND3DBUFFER ds3dbuffer = NULL; + + if (handle == NEW_HANDLE) + handle = find_handle(sfx?sfx->id:0, is_3dsource); + + snd = _stack + handle; + + // Check for reused source + if (snd->dsbuffer) + return snd; + + data_length = sfx?sfx->length - 8:DSBSIZE_MIN; + + dsbuffer = create_buffer(sfx ? sfx->data : NULL, data_length, is_3dsource); + if (dsbuffer) + { + + if (is_3dsource) + { + ds3dbuffer = create_3dbuffer(dsbuffer, ds3dbuffer); + if (!ds3dbuffer) + { + RELEASE_BUFFER(dsbuffer); + return NULL; + } + snd->parameters.dwSize = sizeof (DS3DBUFFER); + IDirectSound3DBuffer_GetAllParameters(ds3dbuffer, &snd->parameters); + } + + // judgecutor: sound pitching + if (sfx) + { + DWORD freq; + + freq = (DWORD)((float)(*((UINT16 *)sfx->data+1)) * recalc_pitch(sfx->pitch)); + IDirectSoundBuffer_SetFrequency(dsbuffer, freq); + } + + snd->dsbuffer = dsbuffer; + snd->dsbuffer3D = ds3dbuffer; + snd->LRU = 0; + snd->sfx_id = sfx ? sfx->id : 0; + if (!is_3dsource) + snd->permanent = 0; + return snd; + } + return NULL; + +} + +/****************************************************************************** + * + * Creates 2D (stereo) source + * + ******************************************************************************/ +EXPORT INT32 HWRAPI ( Add2DSource ) (sfx_data_t *sfx) +{ + stack_t *snd; + + if (!sfx) + return -1; + + snd = setup_source(NEW_HANDLE, sfx, IS_2DSOURCE); + if (snd) + { + UpdateSoundVolume(snd->dsbuffer, sfx->volume); + Update2DSoundPanning(snd->dsbuffer, sfx->sep); + } + return snd - _stack; +} + +/****************************************************************************** + * + * Creates 3D source + * + ******************************************************************************/ + +EXPORT INT32 HWRAPI ( Add3DSource ) (source3D_data_t *src, sfx_data_t *sfx) +{ + stack_t *snd; + + snd = setup_source(NEW_HANDLE, sfx, IS_3DSOURCE); + + if (snd) + { + + /*x = src->pos.x; + y = src->pos.z; + z = src->pos.y; + + IDirectSound3DBuffer_SetPosition(source, x, y, z, update_mode); + IDirectSound3DBuffer_SetVelocity(source, src->pos.momx, src->pos.momz, src->pos.momy, update_mode); + IDirectSound3DBuffer_SetMode(source, src->head_relative?DS3DMODE_HEADRELATIVE:DS3DMODE_NORMAL, update_mode);*/ + +#ifdef DUMMYUNIONNAMEN + snd->parameters.vPosition.DUMMYUNIONNAMEN(9).x = src->pos.x; + snd->parameters.vPosition.DUMMYUNIONNAMEN(10).y = src->pos.z; + snd->parameters.vPosition.DUMMYUNIONNAMEN(11).z = src->pos.y; + + snd->parameters.vVelocity.DUMMYUNIONNAMEN(9).x = src->pos.momx; + snd->parameters.vVelocity.DUMMYUNIONNAMEN(10).y = src->pos.momz; + snd->parameters.vVelocity.DUMMYUNIONNAMEN(11).z = src->pos.momy; +#else + snd->parameters.vPosition.x = src->pos.x; + snd->parameters.vPosition.y = src->pos.z; + snd->parameters.vPosition.z = src->pos.y; + + snd->parameters.vVelocity.x = src->pos.momx; + snd->parameters.vVelocity.y = src->pos.momz; + snd->parameters.vVelocity.z = src->pos.momy; +#endif + snd->parameters.dwMode = src->head_relative ? DS3DMODE_HEADRELATIVE : DS3DMODE_NORMAL; + + snd->parameters.flMinDistance = src->min_distance; + snd->parameters.flMaxDistance = src->max_distance; + //snd->parameters.flMaxDistance = DS3D_DEFAULTMAXDISTANCE; + + snd->permanent = src->permanent; + + UpdateSoundVolume(snd->dsbuffer, sfx?sfx->volume:255); + IDirectSound3DBuffer_SetAllParameters(snd->dsbuffer3D, &snd->parameters, DS3D_IMMEDIATE); + IDirectSoundBuffer_SetCurrentPosition(snd->dsbuffer, 0); + } + + return (snd - _stack); +} + +/****************************************************************************** + * + * Destroy source and remove it from stack if it is a 2D source. + * Otherwise put source into cache + * + *****************************************************************************/ +EXPORT void HWRAPI (KillSource) (INT32 handle) +{ + + if (handle < 0 || handle >= allocated_sounds) + return; +/* + if (_stack[handle].dsbuffer3D) + { + // It's a 3D source so let him chance to be reused :-) + _stack[handle].LRU = 1; + } + else + { */ + // No, it is a 2D source so kill him + kill_sound(_stack + handle); + //} +} + + +/****************************************************************************** + * + * Update volume and separation (panning) of 2D source + * + *****************************************************************************/ +EXPORT void HWRAPI (Update2DSoundParms) (INT32 handle, INT32 vol, INT32 sep) +{ + LPDIRECTSOUNDBUFFER dsbuffer; + + if (handle < 0 || handle >= allocated_sounds) + return; + + if ((_stack+handle)->dsbuffer3D) + return; + dsbuffer = (_stack + handle)->dsbuffer; + + UpdateSoundVolume(dsbuffer, vol); + Update2DSoundPanning(dsbuffer, sep); +} + + + +// -------------------------------------------------------------------------- +// Set the global volume for sound effects +// -------------------------------------------------------------------------- +EXPORT void HWRAPI (SetGlobalSfxVolume) (INT32 volume) +{ + INT32 vol; + HRESULT hr; + + // use the last quarter of volume range + if (volume) + vol = recalc_volume(volume, 31); + else + vol = DSBVOLUME_MIN; + + hr = IDirectSoundBuffer_SetVolume (PrimaryBuffer, vol); +} + +EXPORT void HWRAPI ( StopSource) (INT32 handle) +{ + LPDIRECTSOUNDBUFFER dsbuffer; + + if (handle < 0 || handle >= allocated_sounds) + return; + + dsbuffer = (_stack + handle)->dsbuffer; + + if (dsbuffer) + { + IDirectSoundBuffer_Stop(dsbuffer); + IDirectSoundBuffer_SetCurrentPosition(dsbuffer, 0); + } +} + + +EXPORT INT32 HWRAPI ( GetHW3DSVersion) (void) +{ + return VERSION; +} + + +EXPORT void HWRAPI (BeginFrameUpdate) (void) +{ + update_mode = DS3D_DEFERRED; +} + + +EXPORT void HWRAPI (EndFrameUpdate) (void) +{ + if (update_mode == DS3D_DEFERRED) + IDirectSound3DListener_CommitDeferredSettings(Listener); + + update_mode = DS3D_IMMEDIATE; +} + + +/****************************************************************************** + * UpdateListener + * + * Set up main listener properties: + * - position + * - orientation + * - velocity + *****************************************************************************/ +EXPORT void HWRAPI (UpdateListener) (listener_data_t *data) +{ + D3DVECTOR pos; + D3DVECTOR face; + D3DVECTOR head; + D3DVECTOR velocity; + double f_angle; + //double h_angle, t_angle; + //double f_cos, f_sin, t_sin; + +#ifdef DUMMYUNIONNAMEN + pos.DUMMYUNIONNAMEN(9).x = (D3DVALUE)data->x; + pos.DUMMYUNIONNAMEN(10).y = (D3DVALUE)data->z; + pos.DUMMYUNIONNAMEN(11).z = (D3DVALUE)data->y; + + velocity.DUMMYUNIONNAMEN(9).x = (D3DVALUE)data->momx; + velocity.DUMMYUNIONNAMEN(10).y = (D3DVALUE)data->momz; + velocity.DUMMYUNIONNAMEN(11).z = (D3DVALUE)data->momy; +#else + pos.x = (D3DVALUE)data->x; + pos.y = (D3DVALUE)data->z; + pos.z = (D3DVALUE)data->y; + + velocity.x = (D3DVALUE)data->momx; + velocity.y = (D3DVALUE)data->momz; + velocity.z = (D3DVALUE)data->momy; +#endif + f_angle = (data->f_angle) / 180 * M_PI; + //h_angle = data->h_angle / 180 * M_PI; + //h_angle = 90 / 180 * M_PI; + + // Treat listener orientation angles as spherical coordinates. + // x = sin h * cos f + // y = sin h * sin f + // z = cos h + + // Front vector + //t_angle = (M_PI/2 - h_angle); + //t_angle = M_PI/2; + + //face.x = (t_sin = sin(t_angle)) * (f_cos = cos(f_angle)); + //face.z = t_sin * (f_sin = sin(f_angle)); + //face.y = cos(t_angle); +#ifdef DUMMYUNIONNAMEN + face.DUMMYUNIONNAMEN(9).x = (D3DVALUE)cos(f_angle); + face.DUMMYUNIONNAMEN(11).z = (D3DVALUE)sin(f_angle); + face.DUMMYUNIONNAMEN(10).y = 0.0f; + + head.DUMMYUNIONNAMEN(9).x = 0.0f; + head.DUMMYUNIONNAMEN(10).y = 1.0f; + head.DUMMYUNIONNAMEN(11).z = 0.0f; +#else + face.x = (D3DVALUE)cos(f_angle); + face.z = (D3DVALUE)sin(f_angle); + face.y = 0.0f; + + head.x = 0.0f; + head.y = 1.0f; + head.z = 0.0f; +#endif + // Top vector + //h_angle = (-data->h_angle) / 180 * M_PI; + +/* + t_angle = -h_angle; + + head.z = (t_sin = sin(t_angle)) * f_cos; + head.x = t_sin * f_sin; + head.y = cos(t_angle); +*/ + + // Update at once + CopyMemory(&listener_parms.vPosition, &pos, sizeof (D3DVECTOR)); + CopyMemory(&listener_parms.vOrientFront, &face, sizeof (D3DVECTOR)); + CopyMemory(&listener_parms.vOrientTop, &head, sizeof (D3DVECTOR)); + CopyMemory(&listener_parms.vVelocity, &velocity, sizeof (D3DVECTOR)); + //IDirectSound3DListener_SetAllParameters(Listener, &listener_parms, DS3D_IMMEDIATE); + IDirectSound3DListener_SetAllParameters(Listener, &listener_parms, update_mode); +} + +EXPORT void HWRAPI (UpdateListener2) (listener_data_t *data) +{ + D3DVECTOR pos; + D3DVECTOR face; + D3DVECTOR head; + D3DVECTOR velocity; + double f_angle; + //double h_angle, t_angle; + //double f_cos, f_sin, t_sin; + + if (!data) return; + +#ifdef DUMMYUNIONNAMEN + pos.DUMMYUNIONNAMEN(9).x = (D3DVALUE)data->x; + pos.DUMMYUNIONNAMEN(10).y = (D3DVALUE)data->z; + pos.DUMMYUNIONNAMEN(11).z = (D3DVALUE)data->y; + + velocity.DUMMYUNIONNAMEN(9).x = (D3DVALUE)data->momx; + velocity.DUMMYUNIONNAMEN(10).y = (D3DVALUE)data->momz; + velocity.DUMMYUNIONNAMEN(11).z = (D3DVALUE)data->momy; +#else + pos.x = (D3DVALUE)data->x; + pos.y = (D3DVALUE)data->z; + pos.z = (D3DVALUE)data->y; + + velocity.x = (D3DVALUE)data->momx; + velocity.y = (D3DVALUE)data->momz; + velocity.z = (D3DVALUE)data->momy; +#endif + f_angle = (data->f_angle) / 180 * M_PI; + //h_angle = data->h_angle / 180 * M_PI; + //h_angle = 90 / 180 * M_PI; + + // Treat listener orientation angles as spherical coordinates. + // x = sin h * cos f + // y = sin h * sin f + // z = cos h + + // Front vector + //t_angle = (M_PI/2 - h_angle); + //t_angle = M_PI/2; + + //face.x = (t_sin = sin(t_angle)) * (f_cos = cos(f_angle)); + //face.z = t_sin * (f_sin = sin(f_angle)); + //face.y = cos(t_angle); +#ifdef DUMMYUNIONNAMEN + face.DUMMYUNIONNAMEN(9).x = cos(f_angle); + face.DUMMYUNIONNAMEN(11).z = sin(f_angle); + face.DUMMYUNIONNAMEN(10).y = 0.0f; + + head.DUMMYUNIONNAMEN(9).x = 0.0f; + head.DUMMYUNIONNAMEN(10).y = 1.0f; + head.DUMMYUNIONNAMEN(11).z = 0.0f; +#else + face.x = (D3DVALUE)cos(f_angle); + face.z = (D3DVALUE)sin(f_angle); + face.y = 0.0f; + + head.x = 0.0f; + head.y = 1.0f; + head.z = 0.0f; +#endif + + // Top vector + //h_angle = (-data->h_angle) / 180 * M_PI; + +/* + t_angle = -h_angle; + + head.z = (t_sin = sin(t_angle)) * f_cos; + head.x = t_sin * f_sin; + head.y = cos(t_angle); +*/ + + // Update at once + CopyMemory(&listener_parms.vPosition, &pos, sizeof (D3DVECTOR)); + CopyMemory(&listener_parms.vOrientFront, &face, sizeof (D3DVECTOR)); + CopyMemory(&listener_parms.vOrientTop, &head, sizeof (D3DVECTOR)); + CopyMemory(&listener_parms.vVelocity, &velocity, sizeof (D3DVECTOR)); + //IDirectSound3DListener_SetAllParameters(Listener, &listener_parms, DS3D_IMMEDIATE); + //Alam_GBC: 2 Listeners? + //IDirectSound3DListener_SetAllParameters(Listener, &listener_parms, update_mode); +} + +EXPORT INT32 HWRAPI (SetCone) (INT32 handle, cone_def_t *cone_def) +{ + stack_t *snd; + //DS3DBUFFER parms; + + if (handle < 0 || handle >= allocated_sounds) + return -1; + + snd = _stack + handle; + + if (snd->dsbuffer3D) + { + + /*f_angle = cone_def->f_angle / 180 * M_PI; + h_angle = (90 - cone_def->h_angle) / 180 * M_PI; + parms.vConeOrientation.x = sin(h_angle) * cos(f_angle); + parms.vConeOrientation.z = sin(h_angle) * sin(f_angle); + parms.vConeOrientation.y = cos(h_angle);*/ + + snd->parameters.dwInsideConeAngle = (DWORD)cone_def->inner; + snd->parameters.dwOutsideConeAngle = (DWORD)cone_def->outer; + snd->parameters.lConeOutsideVolume = recalc_volume(cone_def->outer_gain, 256); + + return IDirectSound3DBuffer_SetAllParameters(snd->dsbuffer3D, &snd->parameters, update_mode); + } + + return -1; +} + +EXPORT void HWRAPI (Update3DSource) (INT32 handle, source3D_pos_t *data) +{ + stack_t *snd; + + if (handle < 0 || handle >= allocated_sounds) + return; + + snd = _stack + handle; + if (snd->dsbuffer3D) + { + + /*parms.dwSize = sizeof (DS3DBUFFER); + IDirectSound3DBuffer_GetAllParameters(snd, &parms);*/ + + //angle = data->angle * 180 / M_PI; + +#ifdef DUMMYUNIONNAMEN + snd->parameters.vPosition.DUMMYUNIONNAMEN(9).x = data->x; + snd->parameters.vPosition.DUMMYUNIONNAMEN(10).y = data->z; + snd->parameters.vPosition.DUMMYUNIONNAMEN(11).z = data->y; +#else + snd->parameters.vPosition.x = data->x; + snd->parameters.vPosition.y = data->z; + snd->parameters.vPosition.z = data->y; +#endif + + /*parms.vConeOrientation.x = cos(angle); + parms.vConeOrientation.z = sin(angle); + parms.vConeOrientation.y = 0;*/ + +#ifdef DUMMYUNIONNAMEN + snd->parameters.vVelocity.x = data->momx; + snd->parameters.vVelocity.y = data->momz; + snd->parameters.vVelocity.z = data->momy; +#else + snd->parameters.vVelocity.x = data->momx; + snd->parameters.vVelocity.y = data->momz; + snd->parameters.vVelocity.z = data->momy; +#endif + + //snd->parameters.flMinDistance = data->min_distance; + //snd->parameters.flMaxDistance = data->max_distance; + //snd->parameters.dwMode = pos->head_realtive?DS3DMODE_HEADREALTIVE:DS3DMODE_NORMAL; + + IDirectSound3DBuffer_SetAllParameters(snd->dsbuffer3D, &snd->parameters, update_mode); + } +} + + +EXPORT INT32 HWRAPI (StartSource) (INT32 handle) +{ + LPDIRECTSOUNDBUFFER snd; + + if (handle < 0 || handle >= allocated_sounds) + return -1; + + snd = (_stack + handle)->dsbuffer; + IDirectSoundBuffer_SetCurrentPosition(snd, 0); + return IDirectSoundBuffer_Play(snd, 0, 0, 0); + +} + +//------------------------------------------------------------- +// Load new sound data into source +//------------------------------------------------------------- +EXPORT INT32 HWRAPI (Reload3DSource) (INT32 handle, sfx_data_t *data) +{ + DS3DBUFFER temp; + stack_t *snd; + INT32 perm; + + // DirectX could not load new sound data into source + // so recreate sound buffers + if (handle < 0 || handle >= allocated_sounds) + return -1; + + snd = _stack + handle; + CopyMemory(&temp, &snd->parameters, sizeof (DS3DBUFFER)); + perm = snd->permanent; + + kill_sound(snd); + + snd = setup_source(handle, data, IS_3DSOURCE); + /*snd->dsbuffer = create_buffer(data->data, data->length, true); + if (snd->dsbuffer == NULL) + return -1; + snd->dsbuffer3D = create_3dbuffer(snd->dsbuffer, snd->dsbuffer3D); + if (snd->dsbuffer3D == NULL) + { + RELEASE_BUFFER(snd->dsbuffer); + return -1; + } + + snd->sfx_id = data->id; + snd->LRU = 0;*/ + if (snd) + { + snd->permanent = perm; + IDirectSound3DBuffer_SetAllParameters(snd->dsbuffer3D, &temp, DS3D_IMMEDIATE); + CopyMemory(&snd->parameters, &temp, sizeof (DS3DBUFFER)); + } + + return(snd - _stack); +} + +EXPORT void HWRAPI (UpdateSourceVolume) (INT32 handle, INT32 volume) +{ + if (handle < 0 || handle >= allocated_sounds) + return; + UpdateSoundVolume((_stack + handle)->dsbuffer, volume); +} diff --git a/src/hardware/s_ds3d/s_ds3d.dev b/src/hardware/s_ds3d/s_ds3d.dev new file mode 100644 index 000000000..1b51b1b77 --- /dev/null +++ b/src/hardware/s_ds3d/s_ds3d.dev @@ -0,0 +1,59 @@ +[Project] +FileName=s_ds3d.dev +Name=s_ds3d +Ver=1 +IsCpp=1 +Type=3 +Compiler=-D_M_IX86=500_@@_-Wall_@@_-D_WINDOWS_@@_-Os_@@_-fno-strict-aliasing_@@_-fomit-frame-pointer_@@_ +CppCompiler= +Includes= +Linker=--def ../s_mingw.def_@@_-luuid_@@_-ldsound_@@_ +Libs= +UnitCount=1 +Folders= +ObjFiles= +PrivateResource= +ResourceIncludes= +MakeIncludes= +Icon= +ExeOutput=C:\srb2demo2 +ObjectOutput=..\..\..\objs\Mingw\s_ds3d +OverrideOutput=1 +OverrideOutputName=s_ds3d.dll +HostApplication= +CommandLine= +IncludeVersionInfo=0 +SupportXPThemes=0 +CompilerSet=0 +CompilerSettings=00000000000000000111d0 +UseCustomMakefile=0 +CustomMakefile= + +[Unit1] +FileName=s_ds3d.c +Folder= +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[VersionInfo] +Major=0 +Minor=1 +Release=1 +Build=1 +LanguageID=1033 +CharsetID=1252 +CompanyName= +FileVersion=0.1 +FileDescription=Developed using the Dev-C++ IDE +InternalName= +LegalCopyright= +LegalTrademarks= +OriginalFilename=s_ds3d.exe +ProductName=s_ds3d +ProductVersion=0.1 +AutoIncBuildNr=0 + diff --git a/src/hardware/s_ds3d/s_ds3d.dsp b/src/hardware/s_ds3d/s_ds3d.dsp new file mode 100644 index 000000000..a82207c97 --- /dev/null +++ b/src/hardware/s_ds3d/s_ds3d.dsp @@ -0,0 +1,99 @@ +# Microsoft Developer Studio Project File - Name="s_ds3d" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=s_ds3d - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "s_ds3d.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "s_ds3d.mak" CFG="s_ds3d - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "s_ds3d - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "s_ds3d - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "s_ds3d - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "..\..\..\bin\VC\Release\s_ds3d" +# PROP Intermediate_Dir "..\..\..\objs\VC\Release\s_ds3d" +# PROP Ignore_Export_Lib 1 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "S_DS3D_EXPORTS" /YX /FD /c +# ADD CPP /nologo /G5 /MT /W3 /GX /Zi /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "__WIN32__" /D "__MSC__" /FD /c +# SUBTRACT CPP /YX +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x419 /d "NDEBUG" +# ADD RSC /l 0x40c /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 +# ADD LINK32 dsound.lib /nologo /dll /pdb:"..\..\..\bin\VC\Release\s_ds3d.pdb" /machine:I386 /out:"..\..\..\bin\VC\Release\s_ds3d.dll" +# SUBTRACT LINK32 /pdb:none + +!ELSEIF "$(CFG)" == "s_ds3d - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "..\..\..\bin\VC\Debug\s_ds3d" +# PROP Intermediate_Dir "..\..\..\objs\VC\Debug\s_ds3d" +# PROP Ignore_Export_Lib 1 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "S_DS3D_EXPORTS" /YX /FD /GZ /c +# ADD CPP /nologo /MTd /W4 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "__WIN32__" /D "__MSC__" /FD /GZ /c +# SUBTRACT CPP /YX +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32 +# ADD BASE RSC /l 0x419 /d "_DEBUG" +# ADD RSC /l 0x40c /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 dsound.lib /nologo /dll /pdb:"..\..\..\bin\VC\Debug\s_ds3d.pdb" /debug /machine:I386 /out:"..\..\..\bin\VC\Debug\s_ds3d.dll" /pdbtype:sept +# SUBTRACT LINK32 /pdb:none /incremental:no /nodefaultlib + +!ENDIF + +# Begin Target + +# Name "s_ds3d - Win32 Release" +# Name "s_ds3d - Win32 Debug" +# Begin Source File + +SOURCE=.\s_ds3d.c +# End Source File +# End Target +# End Project diff --git a/src/hardware/s_fmod/s_fmod.c b/src/hardware/s_fmod/s_fmod.c new file mode 100644 index 000000000..849fd44fa --- /dev/null +++ b/src/hardware/s_fmod/s_fmod.c @@ -0,0 +1,1210 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright (C) 2001 by DooM Legacy Team. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +//----------------------------------------------------------------------------- +/// \file +/// \brief General driver for 3D sound system +/// +/// Implementend via FMOD_SOUND API + +#ifdef _WINDOWS +//#define WIN32_LEAN_AND_MEAN +#define RPC_NO_WINDOWS_H +#include +#else +#include +#include +#include +#include +#include +#endif + +#include +FILE *logstream = NULL; + +#ifdef __MINGW32__ +#include +#else +#include +#endif + +#ifdef FSOUND_INIT_DONTLATENCYADJUST //Alam: why didn't I think about this before? :) +#define FSOUND_Sample_Load(index,data,mode,length) FSOUND_Sample_Load(index,data,mode,0,length) +#else +#define OLDFMOD //Alam: Yea! +#endif + +#ifdef __MINGW32__ +#include +#else +#include /* optional */ +#endif + +#define MAXCHANNEL 1024 + +#undef DEBUG_TO_FILE +#if defined ( SDL ) && !defined ( LOGMESSAGES ) +#define DEBUG_TO_FILE +#endif + +#ifndef MORESTUFF +//#define MORESTUFF +#define REL2D +#endif + +#define _CREATE_DLL_ +#include "../../doomdef.h" +#include "../hw3dsdrv.h" +#define INT2CHAR(p) (char *)p + 8 + +//Doom sound sample format +#define FSOUND_UNORMAL (FSOUND_8BITS | FSOUND_MONO | FSOUND_UNSIGNED) +//Load Raw +#define FSOUND_RAWLOAD (FSOUND_LOADRAW | FSOUND_LOADMEMORY) +//Load Sample Raw from pointer +#define FSOUND_DOOMLOAD (FSOUND_UNORMAL | FSOUND_RAWLOAD) +//length of SFX +#define SFXLENGTH (sfx->length-8) + +//SRB2 treats +X as east, +Y as north, +Z as up. +//FSOUND treats +X as right, +Y as up, and +Z as forwards. +//So SRB2's XZY is FSOUND's XYZ +//And FSOUND's XZY is SRB2's XYZ + +static I_Error_t I_ErrorFMOD = NULL; + +static FSOUND_SAMPLE *blankfmsample = NULL; + +// Calculate sound pitching +static float recalc_pitch(INT32 doom_pitch) +{ +#ifdef MORESTUFF + return (float)1; +#else + return doom_pitch < NORMAL_PITCH ? + (float)(doom_pitch + NORMAL_PITCH) / (NORMAL_PITCH * 2) + :(float)doom_pitch / (float)NORMAL_PITCH; +#endif +} + +/*************************************************************** + * + * DBG_Printf + * Output error messages to debug log if DEBUG_TO_FILE is defined, + * else do nothing + * + ************************************************************** + */ +// -----------------+ +// DBG_Printf : Output error messages to debug log if DEBUG_TO_FILE is defined, +// : else do nothing +// Returns : +// -----------------+ +FUNCPRINTF void DBG_Printf(const char *lpFmt, ...) +{ +#ifdef DEBUG_TO_FILE + char str[4096] = ""; + va_list arglist; + + va_start(arglist, lpFmt); + vsnprintf(str, 4096, lpFmt, arglist); + va_end(arglist); + + if (logstream) + fwrite(str, strlen(str), 1, logstream); +#endif +} + +// Start of head_relative system for FMOD3D + +typedef struct rellistener_s +{ + float pos[3]; + INT32 active; + float vel[3]; + +} rellistener_s_t; //Easy + +static rellistener_s_t rellistener[2]; //The 2 listeners + +typedef struct relarray_s +{ + INT32 handle; // handle number + INT32 chan; // real channel + INT32 listener; // for which listener + rellistener_s_t pos; // source position in 3D +} relarray_s_t; + +static relarray_s_t relarray[STATIC_SOURCES_NUM+1]; // array of chans + + +//set listener +static void relset(INT32 which) +{ + INT32 i; + + if (which == -2 || which == -1) + { + which = -which; + + memset(&rellistener[which-1], 0, sizeof (rellistener_s_t)); //Delete me + for (i = 0; i <= STATIC_SOURCES_NUM; i++) + { + if (relarray[i].pos.active && relarray[i].listener == which) + { + FSOUND_SetPaused(relarray[i].chan,true); + relarray[i].pos.active = false; + } + } + return; + } + else if (which == 1 || which ==2) + { + float pos[3], vel[3]; // Temp bin + which -= 1; //Hello! + + //Get update + FSOUND_3D_Listener_GetAttributes(&pos[0],&vel[0],NULL,NULL,NULL,NULL,NULL,NULL); + memcpy(&rellistener[which].pos[0],&pos[0],sizeof (pos)); + memcpy(&rellistener[which].vel[0],&vel[0],sizeof (vel)); + + if (!rellistener[which].active) + for (i = 0; i <= STATIC_SOURCES_NUM; i++) + { + if (!relarray[i].pos.active && relarray[i].listener == which) + { + FSOUND_SetPaused(relarray[i].chan,false); + relarray[i].pos.active = true; + } + } + + rellistener[which].active = which; + } + else + { + memset(&rellistener[0], 0, sizeof (rellistener_s_t)); + memset(&rellistener[1], 0, sizeof (rellistener_s_t)); + } +} + +//setup system +static void relsetup() +{ + INT32 i; + + // Setup the rel array for use + for (i = 0; i <= STATIC_SOURCES_NUM; i++) + { + relarray[i].handle = FSOUND_FREE; + relarray[i].chan = FSOUND_FREE; + relarray[i].listener = (i == 1 || i == 3)?2:1; + memset(&relarray[i].pos, 0, sizeof (rellistener_s_t)); + } + + // Set up the Listener array + relset(0); +} + + +//checkup for stack +static INT32 relstack(INT32 chan) +{ + INT32 i; + + for (i = 0; i <= STATIC_SOURCES_NUM; i++) + { + if (relarray[i].pos.active && relarray[i].handle == chan) + return i; + } + return -1; +} + +//checkup for fake rel chan +static INT32 relcheckup(INT32 chan) +{ + INT32 i = relstack(chan); + + if (i == -1) + return chan; + else + return relarray[i].chan; +} + + //Update place rel chan's vol +static void relvol(INT32 chan) +{ + INT32 vol = FSOUND_GetVolume(chan); + INT32 error = FSOUND_GetError(); + + if (chan == relcheckup(chan)) + return; + + if (!vol && error) + DBG_Printf("FMOD(relvol, FSOUND_GetVolume, Channel # %i): %s\n",chan,FMOD_ErrorString(error)); + else if (!FSOUND_SetVolume(relcheckup(chan), vol)) + DBG_Printf("FMOD(relvol, FSOUND_SetVolume, Channel # %i): %s\n",chan,FMOD_ErrorString(FSOUND_GetError())); +} + +//Copy rel chan +static INT32 relcopy(INT32 handle) +{ + FSOUND_SAMPLE *fmsample = NULL; + INT32 chan = -1; + float pos[3]; + float vel[3]; + + if (!FSOUND_3D_GetAttributes(handle,&pos[0],&vel[0])) + if (FSOUND_GetError() != FMOD_ERR_NONE) DBG_Printf("FMOD(relcopy, FSOUND_3D_GetAttributes, Channel # %i): %s\n",handle,FMOD_ErrorString(FSOUND_GetError())); + + fmsample = FSOUND_GetCurrentSample(handle); + + if (fmsample) + { +#ifdef REL2D + if (!FSOUND_Sample_SetMode(fmsample, FSOUND_2D)) + DBG_Printf("FMOD(relcopy, FSOUND_Sample_SetMode, handle# %i): %s\n",handle,FMOD_ErrorString(FSOUND_GetError())); +#endif + chan = FSOUND_PlaySoundEx(FSOUND_FREE,fmsample,NULL,true); + + if (chan == -1) + { + if (FSOUND_GetError() != FMOD_ERR_NONE) DBG_Printf("FMOD(relcopy, FSOUND_PlaySoundEx, handle# %i): %s\n",handle,FMOD_ErrorString(FSOUND_GetError())); + return FSOUND_FREE; + } +#ifdef MORESTUFF + else + DBG_Printf("FMOD(relcopy, Main): Copy Handle#%i to channel#%i\n",handle,chan); +#endif + } + else + { + if (FSOUND_GetError() != FMOD_ERR_NONE) + DBG_Printf("FMOD(relcopy, FSOUND_GetCurrentSample, handle# %i): %s\n",handle,FMOD_ErrorString(FSOUND_GetError())); + chan = FSOUND_PlaySoundEx(FSOUND_FREE,blankfmsample,NULL,true); + //return FSOUND_FREE; + } + + if (FSOUND_GetCurrentSample(chan)) + { + + if (!FSOUND_SetCurrentPosition(chan, 0)) + DBG_Printf("FMOD(relcopy, FSOUND_SetCurrentPosition, handle#%i, channel# %i): %s\n",handle,chan,FMOD_ErrorString(FSOUND_GetError())); +#ifndef REL2D + if (!FSOUND_3D_SetAttributes(chan,pos,vel)) + DBG_Printf("FMOD(relcopy, FSOUND_3D_SetAttributes, handle#%i, channel#%i): %s\n",handle,chan,FMOD_ErrorString(FSOUND_GetError())); +#endif +/* + if (!FSOUND_SetReserved(chan, TURE)) + DBG_Printf("FMOD(relcopy, FSOUND_SetReserved, handle#%i, channel# %i): %s\n",handle,chan,FMOD_ErrorString(FSOUND_GetError())); +*/ + return chan; + } + + return FSOUND_FREE; +} + +//update the rel chans +static void relupdate(INT32 handle) +{ + if (handle == FSOUND_FREE) + { + INT32 stack; + + for (stack = 0; stack <= STATIC_SOURCES_NUM;stack++) + { + //if (FSOUND_GetCurrentSample(relarray[stack].handle)) + // relarray[stack].chan = relcopy(relarray[stack].handle); + + if (relarray[stack].chan != FSOUND_FREE) + { + relarray[stack].pos.active = false; + relupdate(relarray[stack].chan); + } + else + relarray[stack].pos.active = false; + } + } + else if (handle == relcheckup(handle)) + return; +#ifndef REL2D + else + { + float pos[3], vel[3]; + INT32 stack = relstack(handle); + INT32 chan = relcheckup(handle); + INT32 which = relarray[stack].listener; + + pos[0] = relarray[stack].pos.pos[0] + rellistener[which].pos[0]; + pos[1] = relarray[stack].pos.pos[1] + rellistener[which].pos[1]; + pos[2] = relarray[stack].pos.pos[2] + rellistener[which].pos[2]; + vel[0] = relarray[stack].pos.vel[0] + rellistener[which].vel[0]; + vel[1] = relarray[stack].pos.vel[1] + rellistener[which].vel[1]; + vel[2] = relarray[stack].pos.vel[2] + rellistener[which].vel[2]; + + if (!FSOUND_3D_SetAttributes(chan,pos,vel)) + DBG_Printf("FMOD(relupdate, FSOUND_3D_SetAttributes, Handle #%i,Channel #%i): %s\n",handle, chan,FMOD_ErrorString(FSOUND_GetError())); + } +#endif +} + + //Update place rel chan's pos +static void relplace(INT32 chan) +{ + float pos[3], vel[3]; // Temp bin + + if (chan == relcheckup(chan)) + return; + + if (!FSOUND_3D_GetAttributes(chan,&pos[0],&vel[0])) + { + if (FSOUND_GetError() != FMOD_ERR_NONE) DBG_Printf("FMOD(relplace, FSOUND_3D_GetAttributes, Channel # %i): %s\n",chan,FMOD_ErrorString(FSOUND_GetError())); + } + else + { + INT32 stack = relstack(chan); + + if (stack == -1) + return; + + memcpy(&relarray[stack].pos.pos,&pos,sizeof (pos)); + memcpy(&relarray[stack].pos.vel,&vel,sizeof (vel)); + relupdate(chan); + } +} + +//New rel chan +static void reladd(INT32 chan) +{ + if (chan != relcheckup(chan)) + return; + else + { + INT32 stack = STATIC_SOURCES_NUM; + { + if (relarray[0].handle == FSOUND_FREE) + stack = 0; + else if (relarray[1].handle == FSOUND_FREE) + stack = 1; + else if (relarray[2].handle == FSOUND_FREE) + stack = 2; + else if (relarray[3].handle == FSOUND_FREE) + stack = 3; + else if (relarray[4].handle == FSOUND_FREE) + stack = 4; + else if (relarray[5].handle == FSOUND_FREE) + stack = 5; + else + DBG_Printf("No more room in relarray\n"); + } + + relarray[stack].handle = chan; + relarray[stack].chan = relcopy(chan); + + if (relarray[stack].chan != FSOUND_FREE) + { + relarray[stack].pos.active = true; + relupdate(chan); + } + else + relarray[stack].pos.active = false; + } +} + +// End of head_relative system for FMOD3D + + +/****************************************************************************** + * + * Initialise driver and listener + * + *****************************************************************************/ +EXPORT INT32 HWRAPI(Startup) (I_Error_t FatalErrorFunction, snddev_t *snd_dev) +{ + boolean inited = false; + INT32 i = 0; + + I_ErrorFMOD = FatalErrorFunction; + + if (FSOUND_GetVersion() < FMOD_VERSION) + { + DBG_Printf("Error : You are using the wrong DLL version!\nYou should be using FMOD %.02f\n", FMOD_VERSION); + return inited; + } + else + DBG_Printf("S_FMOD Init(): FMOD_SOUND driver for SRB2 %s\n",VERSIONSTRING); + + if (!FSOUND_SetMinHardwareChannels(STATIC_SOURCES_NUM*4)) + DBG_Printf("FMOD(Startup,FSOUND_SetMinHardwareChannels,# of Channels Min: %i): %s\n",STATIC_SOURCES_NUM*4, FMOD_ErrorString(FSOUND_GetError())); + + if (!FSOUND_SetMaxHardwareChannels(0)) + DBG_Printf("FMOD(Startup,FSOUND_SetMaxHardwareChannels,# of Channels Min: %i): %s\n",0, FMOD_ErrorString(FSOUND_GetError())); + + for (i = 0; i < FSOUND_GetNumDrivers(); i++) + { + UINT32 caps = 0; + DBG_Printf("Driver Caps, if any\n"); + + if (FSOUND_GetDriverCaps(i, &caps)) + { + DBG_Printf("FMOD: Driver# %d - %s\n", i+1, FSOUND_GetDriverName(i)); // print driver names + if (caps & FSOUND_CAPS_HARDWARE) + DBG_Printf("This sound hardware supports hardware accelerated 3d sound.\n"); + + if (caps & FSOUND_CAPS_EAX2) + DBG_Printf("This sound hardware supports hardware accelerated 3d sound with EAX 2 reverb.\n"); + + if (caps & FSOUND_CAPS_EAX3) + DBG_Printf("This sound hardware supports hardware accelerated 3d sound with EAX 3 reverb.\n"); + } + else + DBG_Printf("FMOD(Startup,FSOUND_GetDriverCaps,%s): %s\n",FSOUND_GetDriverName(i), FMOD_ErrorString(FSOUND_GetError())); + } +#if defined (_WIN32) || defined (_WIN64) + if (!FSOUND_SetHWND(snd_dev->hWnd)) + { + DBG_Printf("FMOD(Startup,FSOUND_SetHWND): %s\n", FMOD_ErrorString(FSOUND_GetError())); + return inited; + } + else +#endif + { + DBG_Printf("Initialising FMOD %.02f\n",FMOD_VERSION); + inited = FSOUND_Init(snd_dev->sample_rate,MAXCHANNEL,0); + } + + if (!inited) + { + DBG_Printf("FMOD(Startup,Main): %s\n", FMOD_ErrorString(FSOUND_GetError())); + } + else + { +#ifdef OLDFMOD + DBG_Printf(" Maximum hardware mixing buffers %d\n", FSOUND_GetNumHardwareChannels()); +#else + INT32 num2DC, num3DC, numDC; + + if (FSOUND_GetNumHWChannels(&num2DC,&num3DC,&numDC)) + { + DBG_Printf(" Maximum hardware 2D buffers %d\n", num2DC); + DBG_Printf(" Maximum hardware 3D buffers %d\n", num3DC); + DBG_Printf(" Maximum hardware mixing buffers %d\n", numDC); + } + else + DBG_Printf("FMOD(Startup,FSOUND_GetNumHWChannels): %s\n", FMOD_ErrorString(FSOUND_GetError())); +#endif + + DBG_Printf("FMOD is up and running at %i KHZ\n",FSOUND_GetOutputRate()); + DBG_Printf("Sound hardware capabilities:\n"); + + if (FSOUND_GetDriverName(FSOUND_GetDriver())) + DBG_Printf(" Driver is %s\n",FSOUND_GetDriverName(FSOUND_GetDriver())); + else + DBG_Printf("FMOD(Startup,FSOUND_GetDriverName): %s\n", FMOD_ErrorString(FSOUND_GetError())); + + FSOUND_3D_SetDistanceFactor(1.0f/72.0f); + FSOUND_3D_SetRolloffFactor(0); + FSOUND_3D_SetRolloffFactor(1.6f); +#ifdef MORESTUFF + FSOUND_3D_SetDopplerFactor(0); +#endif + + switch (FSOUND_GetOutput()) + { + case FSOUND_OUTPUT_NOSOUND: + DBG_Printf("FMOD driver: NoSound driver, all calls to this succeed but do nothing.\n"); + break; + case FSOUND_OUTPUT_WINMM: + DBG_Printf("FMOD driver: Windows Multimedia driver.\n"); + break; + case FSOUND_OUTPUT_DSOUND: + DBG_Printf("FMOD driver: DirectSound driver. You need this to get EAX2 or EAX3 support, or FX api support.\n"); + break; + case FSOUND_OUTPUT_A3D: + DBG_Printf("FMOD driver: A3D driver.\n"); + break; + case FSOUND_OUTPUT_XBOX: + DBG_Printf("FMOD driver: Xbox driver\n"); + break; + case FSOUND_OUTPUT_OSS: + DBG_Printf("FMOD driver: Linux/Unix OSS (Open Sound System) driver, i.e. the kernel sound drivers.\n"); + break; + case FSOUND_OUTPUT_ESD: + DBG_Printf("FMOD driver: Linux/Unix ESD (Enlightment Sound Daemon) driver.\n"); + break; + case FSOUND_OUTPUT_ALSA: + DBG_Printf("FMOD driver: Linux Alsa driver.\n"); + break; + case FSOUND_OUTPUT_MAC: + DBG_Printf("FMOD driver: Mac SoundManager driver\n"); + break; + case FSOUND_OUTPUT_PS2: + DBG_Printf("FMOD driver: PlayStation 2 driver\n"); + break; + case FSOUND_OUTPUT_GC: + DBG_Printf("FMOD driver: Gamecube driver\n"); + break; + case FSOUND_OUTPUT_NOSOUND_NONREALTIME: + DBG_Printf("FMOD driver: This is the same as nosound, but the sound generation is driven by FSOUND_Update\n"); + break; + case FSOUND_OUTPUT_ASIO: + DBG_Printf("FMOD driver: Low latency ASIO driver\n"); + break; + default: + DBG_Printf("FMOD driver: Unknown Sound Driver\n"); + break; + } + + relsetup(); + + blankfmsample = FSOUND_Sample_Alloc(FSOUND_UNMANAGED,1,FSOUND_UNORMAL,11025,127,FSOUND_STEREOPAN,127); + + if (!blankfmsample) + DBG_Printf("FMOD(Startup,FSOUND_Sample_Alloc): %s\n", FMOD_ErrorString(FSOUND_GetError())); + else if (!FSOUND_Sample_SetMaxPlaybacks(blankfmsample,STATIC_SOURCES_NUM*2)) + DBG_Printf("FMOD(Startup,FSOUND_Sample_SetMaxPlaybacks): %s\n", FMOD_ErrorString(FSOUND_GetError())); + } + return inited; +} + +EXPORT void HWRAPI(Shutdown) (void) +{ + DBG_Printf("Shuting down FMOD\n"); + FSOUND_Sample_Free(blankfmsample); + DBG_Printf("Shutdown of FMOD done\n"); + FSOUND_Close(); +} + +/****************************************************************************** + * + * Creates 3D source + * + ******************************************************************************/ + +EXPORT INT32 HWRAPI (Add3DSource) (source3D_data_t *src, sfx_data_t *sfx) +{ + FSOUND_SAMPLE *fmsample = NULL; + INT32 chan = -1; + float pos[3]; + float vel[3]; +#ifdef MORESTUFF + src->min_distance = MIN_DISTANCE; + src->max_distance = MAX_DISTANCE; +#endif + + pos[0] = src->pos.x; + pos[1] = src->pos.z; + pos[2] = src->pos.y; + vel[0] = src->pos.momx; + vel[1] = src->pos.momz; + vel[2] = src->pos.momy; + if (sfx) + fmsample = FSOUND_Sample_Load(FSOUND_FREE, INT2CHAR(sfx->data), FSOUND_DOOMLOAD, SFXLENGTH); + else + fmsample = blankfmsample; + + if (fmsample) + { + if (sfx && !FSOUND_Sample_SetDefaults(fmsample, + (INT32)((*((UINT16 *)sfx->data+1))*recalc_pitch(sfx->pitch)), + (sfx->volume == -1 ? 255 : sfx->volume), + (sfx->sep == NORMAL_SEP ? FSOUND_STEREOPAN : sfx->sep), + (sfx->priority) + ) + ) + DBG_Printf("FMOD(Add3DSource, FSOUND_Sample_SetDefaults, SFX's ID# %i): %s\n", sfx?sfx->id:0,FMOD_ErrorString(FSOUND_GetError())); +#if 0 + if (!FSOUND_Sample_SetMinMaxDistance(fmsample, src->min_distance, src->max_distance)) + DBG_Printf("FMOD(Add3DSource, FSOUND_Sample_SetMinMaxDistance, SFX's ID# %i): %s\n", sfx?sfx->id:0,FMOD_ErrorString(FSOUND_GetError())); +#endif + chan = FSOUND_PlaySoundEx(FSOUND_FREE,fmsample,NULL,true); + + if (chan == -1) + { + DBG_Printf("FMOD(Add3DSource, FSOUND_PlaySoundEx, SFX's ID# %i): %s\n",sfx?sfx->id:0,FMOD_ErrorString(FSOUND_GetError())); + return chan; + } + else + { + if (!sfx) + DBG_Printf("FMOD(Add3DSource, Main): Added blank-sound added to channel %i\n",chan); +#ifdef MORESTUFF + else DBG_Printf("FMOD(Add3DSource, Main): Added sfxid# %i added to channel %i\n",sfx->id,chan); +#endif + } + } + else + { + if (sfx) + DBG_Printf("FMOD(Add3DSource, FSOUND_Sample_Load, sfxid# %i): %s\n",sfx->id,FMOD_ErrorString(FSOUND_GetError())); + else + DBG_Printf("FMOD(Add3DSource, FSOUND_Sample_Alloc): %s\n", FMOD_ErrorString(FSOUND_GetError())); + + return chan; + } + + if (FSOUND_GetCurrentSample(chan)) + { + if (!FSOUND_SetCurrentPosition(chan, 0)) + DBG_Printf("FMOD(Add3DSource, FSOUND_SetCurrentPosition, channel %i, sfxid# %i): %s\n", chan,sfx?sfx->id:0,FMOD_ErrorString(FSOUND_GetError())); + + if (!FSOUND_3D_SetAttributes(chan,pos,vel)) + DBG_Printf("FMOD(Add3DSource, FSOUND_3D_SetAttributes, channel %i, sfxid# %i): %s\n", chan,sfx?sfx->id:0,FMOD_ErrorString(FSOUND_GetError())); + + if (!FSOUND_SetReserved(chan, (signed char)src->permanent)) + DBG_Printf("FMOD(Add3DSource, FSOUND_SetReserved, channel %i, sfxid# %i): %s\n", chan,sfx?sfx->id:0,FMOD_ErrorString(FSOUND_GetError())); + + if (src->head_relative) reladd(chan); + } + + return chan; +} + +/****************************************************************************** + * + * Creates 2D (stereo) source + * + ******************************************************************************/ +EXPORT INT32 HWRAPI (Add2DSource) (sfx_data_t *sfx) +{ + FSOUND_SAMPLE *fmsample = NULL; + INT32 chan = -1; + + if (!sfx) + return chan; + + fmsample = FSOUND_Sample_Load(FSOUND_FREE, INT2CHAR(sfx->data), FSOUND_DOOMLOAD, SFXLENGTH); + + if (fmsample) + { + if (!FSOUND_Sample_SetDefaults(fmsample, + (INT32)((float)(*((UINT16 *)sfx->data+1)) * recalc_pitch(sfx->pitch)), + sfx->volume == -1 ? 255 : sfx->volume, + sfx->sep == NORMAL_SEP ? FSOUND_STEREOPAN : sfx->sep, + sfx->priority)) + DBG_Printf("FMOD(Add2DSource, FSOUND_Sample_SetDefaults, sfxid# %i): %s\n", sfx->id,FMOD_ErrorString(FSOUND_GetError())); + + if (!FSOUND_Sample_SetMode(fmsample,FSOUND_2D)) + DBG_Printf("FMOD(Add2DSource, FSOUND_Sample_SetMode, sfxid# %i): %s\n", sfx->id,FMOD_ErrorString(FSOUND_GetError())); + + chan = FSOUND_PlaySoundEx(FSOUND_FREE,fmsample,NULL,true); + + if (chan == -1) + { + DBG_Printf("FMOD(Add2DSource, FSOUND_PlaySoundEx, sfxid# %i): %s\n", sfx->id,FMOD_ErrorString(FSOUND_GetError())); + return chan; + } +#ifdef MORESTUFF + else DBG_Printf("FMOD(Add2DSource, FSOUND_PlaySoundEx): sfxid# %i is playing on channel %i\n", sfx->id,chan); +#endif + } + else + { + DBG_Printf("FMOD(Add2DSource,FSOUND_Sample_Load, sfxid# %i): %s\n", sfx->id,FMOD_ErrorString(FSOUND_GetError())); + return chan; + } + + if (FSOUND_GetCurrentSample(chan)) + { + if (!FSOUND_SetCurrentPosition(chan, 0)) + DBG_Printf("FMOD(Add2DSource, FSOUND_SetCurrentPosition, channel %i, sfxid# %i): %s\n", chan,sfx->id,FMOD_ErrorString(FSOUND_GetError())); + } + + return chan; +} + +EXPORT INT32 HWRAPI (StartSource) (INT32 chan) +{ + FSOUND_SAMPLE *fmsample; + if (chan < 0) + return -1; + + fmsample = FSOUND_GetCurrentSample(chan); + + if (!fmsample) + return -1; + +#ifdef MORESTUFF + if (FSOUND_Sample_GetMode(fmsample) & FSOUND_2D) + { + DBG_Printf("FMOD(StartSource,Main): Starting 2D channel %i?\n",chan); + //return -1; + } + else + { + DBG_Printf("FMOD(StartSource,Main): Starting 3D Channel %i?\n",chan); + //return -1; + } +#endif + + if (FSOUND_GetPaused(relcheckup(chan))) + { + if (!FSOUND_SetPaused(relcheckup(chan), false)) + DBG_Printf("FMOD(StartSource,FSOUND_SetPaused, channel %i): %s\n", chan,FMOD_ErrorString(FSOUND_GetError())); + else if (relstack(chan) != -1) + relarray[relstack(chan)].pos.active = false; + } + else + DBG_Printf("FMOD(StartSource,FSOUND_GetPaused): Channel %i is playing already",chan); + + return chan; +} + +EXPORT void HWRAPI (StopSource) (INT32 chan) +{ + FSOUND_SAMPLE *fmsample; + + if (chan < 0) + return; + + fmsample = FSOUND_GetCurrentSample(chan); + + if (!fmsample) + return; + + if (!FSOUND_GetPaused(relcheckup(chan))) + { + if (!FSOUND_SetPaused(relcheckup(chan),true)) + { + DBG_Printf("FMOD(StopSource,FSOUND_SetPaused, channel %i): %s\n", chan,FMOD_ErrorString(FSOUND_GetError())); + } + else if (relstack(chan) != -1) + { + relarray[relstack(chan)].pos.active = false; + } + } +#ifdef MORESTUFF + else + DBG_Printf("FMOD(StopSource,FSOUND_GetPaused): Channel %i is stopped already\n",chan); +#endif +} + +EXPORT INT32 HWRAPI (GetHW3DSVersion) (void) +{ + return VERSION; +} + +EXPORT void HWRAPI (BeginFrameUpdate) (void) +{ + FSOUND_Update(); +} + +EXPORT void HWRAPI (EndFrameUpdate) (void) +{ + relupdate(FSOUND_FREE); +} + +EXPORT INT32 HWRAPI (IsPlaying) (INT32 chan) +{ + if (chan < 0) + return false; + + if (!FSOUND_GetCurrentSample(chan)) + return false; + + return FSOUND_IsPlaying(relcheckup(chan)); +} + +/****************************************************************************** + * UpdateListener + * + * Set up main listener properties: + * - position + * - orientation + * - velocity + *****************************************************************************/ +EXPORT void HWRAPI (UpdateListener) (listener_data_t *data) +{ + if (data) + { + float pos[3]; + float vel[3]; + double f_angle = 0; + if (data->f_angle) f_angle = (data->f_angle) / 180 * M_PI; + pos[0] = (float)data->x; + pos[1] = (float)data->z; + pos[2] = (float)data->y; + vel[0] = (float)data->momx; + vel[1] = (float)data->momz; + vel[2] = (float)data->momy; + + FSOUND_3D_Listener_SetAttributes(pos,vel,(float)cos(f_angle),0.0f,(float)sin(f_angle), 0.0f , 1.0f, 0.0f); + relset(1); + } + else + { + relset(-1); + DBG_Printf("Error: 1st listener data is missing\n"); + } +} + +EXPORT void HWRAPI (UpdateListener2) (listener_data_t *data) +{ + if (data) + { + float pos[3]; + float vel[3]; + double f_angle = 0; + if (data->f_angle) f_angle = (data->f_angle) / 180 * M_PI; + pos[0] = (float)data->x; + pos[1] = (float)data->z; + pos[2] = (float)data->y; + vel[0] = (float)data->momx; + vel[1] = (float)data->momz; + vel[2] = (float)data->momy; + + FSOUND_3D_Listener_SetCurrent(1,2); + FSOUND_3D_Listener_SetAttributes(pos,vel,(float)cos(f_angle),0.0f,(float)sin(f_angle), 0.0f , 1.0f, 0.0f); + relset(2); + FSOUND_3D_Listener_SetCurrent(0,2); + } + else + { + relset(-2); + FSOUND_3D_Listener_SetCurrent(0,1); + } +} + +EXPORT void HWRAPI (UpdateSourceVolume) (INT32 chan, INT32 vol) +{ + if (chan < 0) + return; + + if (!FSOUND_GetCurrentSample(chan)) + return; + + if (!FSOUND_SetVolume(chan,vol)) + DBG_Printf("FMOD(UpdateSourceVolume, FSOUND_SetVolume, channel %i to volume %i): %s\n", chan,vol,FMOD_ErrorString(FSOUND_GetError())); + else + { +#ifdef MORESTUFF + DBG_Printf("FMOD(UpdateSourceVolume, Main): channel %i is set to the volume of %i", chan,vol); +#endif + relvol(chan); + } +} + +/****************************************************************************** + * + * Update volume and separation (panning) of 2D source + * + *****************************************************************************/ +EXPORT void HWRAPI (Update2DSoundParms) (INT32 chan, INT32 vol, INT32 sep) +{ + FSOUND_SAMPLE *fmsample; + + if (chan < 0) + return; + + fmsample = FSOUND_GetCurrentSample(chan); + + if (fmsample) + { + if (!FSOUND_Sample_GetMode(fmsample) & FSOUND_2D) + { + DBG_Printf("FMOD(Update2DSoundParms,Main): 2D Vol/Pan on 3D channel %i?\n",chan); + //return; + } + } + else + return; + + if (!FSOUND_SetPaused(chan, true)) + DBG_Printf("FMOD(Update2DSoundParms, FSOUND_SetPaused, Pause, channel %i): %s\n", chan,FMOD_ErrorString(FSOUND_GetError())); + + if (!FSOUND_SetVolume(chan,vol)) + DBG_Printf("FMOD(Update2DSoundParms, , channel %i to volume %i): %s\n", chan,vol,FMOD_ErrorString(FSOUND_GetError())); + + if (!FSOUND_SetPan(chan, sep == NORMAL_SEP ? FSOUND_STEREOPAN : sep)) + DBG_Printf("FMOD(Update2DSoundParms, FSOUND_SetPan, channel %i to sep %i): %s\n", chan,sep,FMOD_ErrorString(FSOUND_GetError())); + + if (!FSOUND_SetPaused(chan, false)) + DBG_Printf("FMOD(Update2DSoundParms, FSOUND_SetPaused, Resume, channel %i): %s\n", chan,FMOD_ErrorString(FSOUND_GetError())); +} + +// -------------------------------------------------------------------------- +// Set the global volume for sound effects +// -------------------------------------------------------------------------- +EXPORT void HWRAPI (SetGlobalSfxVolume) (INT32 vol) +{ + INT32 realvol = (vol<<3)+(vol>>2); + + FSOUND_SetSFXMasterVolume(realvol); +#ifdef MORESTUFF + DBG_Printf("FMOD(SetGlobalSfxVolume, Main, the volume is set to %i): %s\n", realvol,FMOD_ErrorString(FSOUND_GetError())); +#endif +} + +//Alam_GBC: Not Used? +EXPORT INT32 HWRAPI (SetCone) (INT32 chan, cone_def_t *cone_def) +{ + FSOUND_SAMPLE *fmsample; + + if (chan < 0) + return -1; + + fmsample = FSOUND_GetCurrentSample(chan); + + if (fmsample) + { + if (FSOUND_Sample_GetMode(fmsample) & FSOUND_2D) + { + DBG_Printf("FMOD(Update3DSource,Main): 3D Cone on 2D Channel %i?\n",chan); + return -1; + } + } + + if (cone_def) + { + return -1; + } + else + { + return 1; + } + +} + +EXPORT void HWRAPI (Update3DSource) (INT32 chan, source3D_pos_t *sfx) +{ + float pos[3]; + float vel[3]; + FSOUND_SAMPLE *fmsample; + + pos[0] = sfx->x; + pos[1] = sfx->z; + pos[2] = sfx->y; + vel[0] = sfx->momx; + vel[1] = sfx->momz; + vel[2] = sfx->momy; + if (chan < 0) + return; + + fmsample = FSOUND_GetCurrentSample(chan); + + if (!fmsample) + return; + + if (fmsample) + { + if (FSOUND_Sample_GetMode(fmsample) & FSOUND_2D) + { + //DBG_Printf("FMOD(Update3DSource,Main): 3D Pos/Vel on 2D Channel %i?\n",chan); + //return; + } + } + else + { + return; + } + + if (!FSOUND_3D_SetAttributes(chan,pos,vel)) + DBG_Printf("FMOD(Update3DSource,FSOUND_3D_SetAttributes, onto channel %i): %s\n", chan,FMOD_ErrorString(FSOUND_GetError())); + else + relplace(chan); +} + +//------------------------------------------------------------- +// Load new sound data into source +//------------------------------------------------------------- +EXPORT INT32 HWRAPI (Reload3DSource) (INT32 handle, sfx_data_t *sfx) +{ + source3D_data_t src; + float pos[3], vel[3]; + INT32 chan = relcheckup(handle); + FSOUND_SAMPLE *fmsample; + + if (handle < 0 || !sfx) + return -1; + + fmsample = FSOUND_GetCurrentSample(chan); + + if (!fmsample) + return -1; + + if (FSOUND_Sample_GetMode(fmsample) & FSOUND_2D) + { + DBG_Printf("FMOD(Reload3DSource,Main): New 3D Sound on 2D Channel %i?\n",handle); + return -1; + } +#ifdef MORESTUFF + else + DBG_Printf("FMOD(Reload3DSource, Main, sending new sfx# %i to chan %i)\n",sfx->id,handle); +#endif + +#ifdef OLDFMOD + src.min_distance = MIN_DISTANCE; + src.max_distance = MAX_DISTANCE; +#else + if (!FSOUND_3D_GetMinMaxDistance(handle,&src.min_distance,&src.min_distance)) + DBG_Printf("FMOD(Reload3DSource, FSOUND_3D_GetMinMaxDistance, channel %i, for sfxid# %i): %s\n",handle, sfx->id,FMOD_ErrorString(FSOUND_GetError())); +#endif + src.head_relative = (handle != chan); + src.permanent = FSOUND_GetReserved(handle); + if (!FSOUND_3D_GetAttributes(handle,&pos[0],&vel[0])) + DBG_Printf("FMOD(Reload3DSource, FSOUND_3D_GetAttributes, channel %i, for sfxid# %i): %s\n",handle,sfx->id,FMOD_ErrorString(FSOUND_GetError())); + + //if (handle == chan) + { + if (fmsample != blankfmsample) FSOUND_Sample_Free(fmsample); + } + //else + { + // fmsample = FSOUND_GetCurrentSample(handle); + } + + fmsample = FSOUND_Sample_Load(FSOUND_FREE, INT2CHAR(sfx->data), FSOUND_DOOMLOAD, SFXLENGTH); + + if (!FSOUND_StopSound(chan)) + DBG_Printf("FMOD(Reload3DSource,FSOUND_StopSound, of channel %i for sfxid# %i): %s\n", handle,sfx->id,FMOD_ErrorString(FSOUND_GetError())); + + if (fmsample) + { + if (!FSOUND_Sample_SetDefaults(fmsample, + (INT32)((float)(*((UINT16 *)sfx->data+1)) * recalc_pitch(sfx->pitch)), + sfx->volume == -1 ? 255 : sfx->volume, + sfx->sep == NORMAL_SEP ? FSOUND_STEREOPAN : sfx->sep, + sfx->priority)) + DBG_Printf("FMOD(Reload3DSource, FSOUND_Sample_SetDefaults, for sfxid# %i): %s\n", sfx->id,FMOD_ErrorString(FSOUND_GetError())); + + if (!FSOUND_Sample_SetMinMaxDistance(fmsample, src.min_distance, src.max_distance)) + DBG_Printf("FMOD(Reload3DSource, FSOUND_Sample_SetMinMaxDistance, SFX's ID# %i): %s\n", sfx->id,FMOD_ErrorString(FSOUND_GetError())); + + chan = FSOUND_PlaySoundEx(chan,fmsample,NULL,true); + + if (chan == -1) + { + DBG_Printf("FMOD(Reload3DSource, FSOUND_PlaySoundEx, for sfxid# %i): %s\n", sfx->id,FMOD_ErrorString(FSOUND_GetError())); + return chan; + } + + if (FSOUND_GetCurrentSample(chan)) + { + if (!FSOUND_SetCurrentPosition(chan, 0)) + DBG_Printf("FMOD(Reload3DSource, FSOUND_SetCurrentPosition, channel %i, sfxid# %i): %s\n", chan,sfx?sfx->id:0,FMOD_ErrorString(FSOUND_GetError())); + + if (!FSOUND_3D_SetAttributes(chan,pos,vel)) + DBG_Printf("FMOD(Reload3DSource, FSOUND_3D_SetAttributes, channel %i, sfxid# %i): %s\n", chan,sfx?sfx->id:0,FMOD_ErrorString(FSOUND_GetError())); + + if (!FSOUND_SetReserved(chan, (signed char)src.permanent)) + DBG_Printf("FMOD(Reload3DSource, FSOUND_SetReserved, channel %i, sfxid# %i): %s\n", chan,sfx?sfx->id:0,FMOD_ErrorString(FSOUND_GetError())); + + if (src.head_relative) relupdate(handle); + } + } + else + DBG_Printf("FMOD(Reload3DSource,FSOUND_Sample_Load, for sfxid# %i): %s\n", sfx->id,FMOD_ErrorString(FSOUND_GetError())); + + return chan; +} + +/****************************************************************************** + * + * Destroy source and remove it from stack if it is a 2D source. + * Otherwise put source into cache + * + *****************************************************************************/ +EXPORT void HWRAPI (KillSource) (INT32 chan) +{ + FSOUND_SAMPLE *fmsample; + INT32 relchan; + + if (chan < 0) + return; + + relchan = relcheckup(chan); + + fmsample = FSOUND_GetCurrentSample(chan); + + if (!fmsample) + return; + +#ifdef MORESTUFF + if (FSOUND_IsPlaying(relchan)) + if (!FSOUND_SetLoopMode(relchan, FSOUND_LOOP_OFF)) + DBG_Printf("FMOD(KillSource,FSOUND_SetLoopMode, for channel %i): %s\n", chan,FMOD_ErrorString(FSOUND_GetError())); //Alam_GBC: looping off + else +#endif + if (!FSOUND_StopSound(relchan)) + { + DBG_Printf("FMOD(KillSource,FSOUND_StopSound, for channel %i): %s\n", chan,FMOD_ErrorString(FSOUND_GetError())); + } +#ifdef MORESTUFF + else DBG_Printf("FMOD(KillSource, Main, for channel %i)\n", chan); +#endif + if (fmsample != blankfmsample) FSOUND_Sample_Free(fmsample); +} + +#ifdef _WINDOWS +BOOL WINAPI DllMain(HINSTANCE hinstDLL, // handle to DLL module + DWORD fdwReason, // reason for calling function + LPVOID lpvReserved) // reserved +{ + // Perform actions based on the reason for calling. + UNREFERENCED_PARAMETER(lpvReserved); + switch (fdwReason) + { + case DLL_PROCESS_ATTACH: + // Initialize once for each new process. + // Return FALSE to fail DLL load. +#ifdef DEBUG_TO_FILE + logstream = fopen("s_fmod.log", "wt"); + if (logstream == NULL) + return FALSE; +#endif + DisableThreadLibraryCalls(hinstDLL); + break; + + case DLL_THREAD_ATTACH: + // Do thread-specific initialization. + break; + + case DLL_THREAD_DETACH: + // Do thread-specific cleanup. + break; + + case DLL_PROCESS_DETACH: + // Perform any necessary cleanup. +#ifdef DEBUG_TO_FILE + if (logstream) + { + fclose(logstream); + logstream = NULL; + } +#endif + break; + } + return TRUE; // Successful DLL_PROCESS_ATTACH. +} +#elif !defined (SDL) + +// ************************************************************************** +// FUNCTIONS +// ************************************************************************** + +EXPORT void _init() +{ +#ifdef DEBUG_TO_FILE + logstream = fopen("s_fmod.log","wt"); +#endif +} + +EXPORT void _fini() +{ +#ifdef DEBUG_TO_FILE + if (logstream) + fclose(logstream); +#endif +} +#endif diff --git a/src/hardware/s_fmod/s_fmod.dev b/src/hardware/s_fmod/s_fmod.dev new file mode 100644 index 000000000..01e21e2b7 --- /dev/null +++ b/src/hardware/s_fmod/s_fmod.dev @@ -0,0 +1,59 @@ +[Project] +FileName=s_fmod.dev +Name=s_fmod +Ver=1 +IsCpp=1 +Type=3 +Compiler=-D_M_IX86=500_@@_-Wall_@@_-D_WINDOWS_@@_-Os_@@_-fomit-frame-pointer_@@_ +CppCompiler= +Includes=..\..\win32\FMOD +Linker=--def ../s_mingw.def_@@_-lfmod_@@_ +Libs=..\..\win32\FMOD +UnitCount=1 +Folders= +ObjFiles= +PrivateResource= +ResourceIncludes= +MakeIncludes= +Icon= +ExeOutput=C:\srb2demo2 +ObjectOutput=..\..\..\objs\Mingw\s_fmod +OverrideOutput=1 +OverrideOutputName=s_fmod.dll +HostApplication= +CommandLine= +IncludeVersionInfo=0 +SupportXPThemes=0 +CompilerSet=0 +CompilerSettings=00000000000000000111d0 +UseCustomMakefile=0 +CustomMakefile= + +[Unit1] +FileName=s_fmod.c +Folder= +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[VersionInfo] +Major=1 +Minor=0 +Release=8 +Build=42 +LanguageID=1033 +CharsetID=1252 +CompanyName=Alam Arias +FileVersion=1.42 +FileDescription=SRB2 Sound API DLL for FMOD +InternalName=Super FMOD! +LegalCopyright= +LegalTrademarks= +OriginalFilename=s_fmod.dll +ProductName=s_fmod +ProductVersion=0.1 +AutoIncBuildNr=0 + diff --git a/src/hardware/s_fmod/s_fmod.dsp b/src/hardware/s_fmod/s_fmod.dsp new file mode 100644 index 000000000..c9a1fb743 --- /dev/null +++ b/src/hardware/s_fmod/s_fmod.dsp @@ -0,0 +1,97 @@ +# Microsoft Developer Studio Project File - Name="s_fmod" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=s_fmod - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "s_fmod.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "s_fmod.mak" CFG="s_fmod - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "s_fmod - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "s_fmod - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "s_fmod - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "..\..\..\bin\VC\Release\s_fmod" +# PROP Intermediate_Dir "..\..\..\objs\VC\Release\s_fmod" +# PROP Ignore_Export_Lib 1 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "S_FMOD_EXPORTS" /YX /FD /c +# ADD CPP /nologo /MT /W3 /GX /Zi /O2 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "__WIN32__" /D "__MSC__" /FR /FD /c +# SUBTRACT CPP /YX +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 +# ADD LINK32 fmodvc.lib /nologo /dll /pdb:"..\..\..\bin\VC\Release\s_fmod.pdb" /machine:I386 /out:"..\..\..\bin\VC\Release\s_fmod.dll" + +!ELSEIF "$(CFG)" == "s_fmod - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "..\..\..\bin\VC\Debug\s_fmod" +# PROP Intermediate_Dir "..\..\..\objs\VC\Debug\s_fmod" +# PROP Ignore_Export_Lib 1 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "S_FMOD_EXPORTS" /YX /FD /GZ /c +# ADD CPP /nologo /MTd /W4 /Gm /GX /ZI /Od /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "__WIN32__" /D "__MSC__" /FR /FD /GZ /c +# SUBTRACT CPP /YX +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 fmodvc.lib /nologo /dll /pdb:"..\..\..\bin\VC\Debug\s_fmod.pdb" /debug /machine:I386 /out:"..\..\..\bin\VC\Debug\s_fmod.dll" /pdbtype:sept + +!ENDIF + +# Begin Target + +# Name "s_fmod - Win32 Release" +# Name "s_fmod - Win32 Debug" +# Begin Source File + +SOURCE=.\s_fmod.c +# End Source File +# End Target +# End Project diff --git a/src/hardware/s_openal/s_openal-vc10.vcxproj b/src/hardware/s_openal/s_openal-vc10.vcxproj new file mode 100644 index 000000000..f6d053b77 --- /dev/null +++ b/src/hardware/s_openal/s_openal-vc10.vcxproj @@ -0,0 +1,282 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + s_openal + {E662D0B3-412D-4D55-A5EC-8CBD680DDCBE} + s_openal + + + + DynamicLibrary + false + MultiByte + + + DynamicLibrary + false + + + DynamicLibrary + false + MultiByte + + + DynamicLibrary + false + + + + + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>10.0.30319.1 + .\..\..\..\bin\VC10\$(Platform)\$(Configuration)\ + .\..\..\..\objs\VC10\$(Platform)\$(Configuration)\s_openal\ + true + false + .\..\..\..\bin\VC10\$(Platform)\$(Configuration)\ + .\..\..\..\objs\VC10\$(Platform)\$(Configuration)\s_openal\ + true + false + .\..\..\..\bin\VC10\$(Platform)\$(Configuration)\ + .\..\..\..\objs\VC10\$(Platform)\$(Configuration)\s_openal\ + true + true + .\..\..\..\bin\VC10\$(Platform)\$(Configuration)\ + .\..\..\..\objs\VC10\$(Platform)\$(Configuration)\s_openal\ + true + true + + + + NDEBUG;%(PreprocessorDefinitions) + true + Win32 + .\..\..\..\bin\VC10\$(Platform)\$(Configuration)\s_openal\s_openal.tlb + + + + + /MP %(AdditionalOptions) + MaxSpeed + OnlyExplicitInline + WIN32;NDEBUG;_WINDOWS;__WIN32__;__MSC__;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + MultiThreaded + true + $(IntDir) + $(IntDir)s_openal.pdb + true + Level3 + true + CompileAsC + + + NDEBUG;%(PreprocessorDefinitions) + 0x0409 + + + OpenAL32.lib;%(AdditionalDependencies) + $(OutDir)s_openal.dll + true + true + $(OutDir)s_openal.pdb + false + + + $(IntDir)s_openal.lib + MachineX86 + + + true + $(OutDir)s_openal.bsc + + + + + NDEBUG;%(PreprocessorDefinitions) + true + X64 + .\..\..\..\bin\VC10\$(Platform)\$(Configuration)\s_openal\s_openal.tlb + + + + + /MP %(AdditionalOptions) + MaxSpeed + OnlyExplicitInline + WIN32;NDEBUG;_WINDOWS;__WIN32__;__MSC__;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + MultiThreaded + true + $(IntDir) + $(IntDir)s_openal.pdb + true + Level3 + true + CompileAsC + + + NDEBUG;%(PreprocessorDefinitions) + 0x0409 + + + OpenAL32.lib;%(AdditionalDependencies) + $(OutDir)s_openal.dll + true + true + $(OutDir)s_openal.pdb + false + + + $(IntDir)s_openal.lib + MachineX64 + + + true + $(OutDir)s_openal.bsc + + + + + _DEBUG;%(PreprocessorDefinitions) + true + true + Win32 + .\..\..\..\bin\VC10\$(Platform)\$(Configuration)\s_openal\s_openal.tlb + + + + + /MP %(AdditionalOptions) + Disabled + WIN32;_DEBUG;_WINDOWS;__WIN32__;__MSC__;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + EnableFastChecks + MultiThreadedDebug + $(IntDir) + $(IntDir)s_openal.pdb + true + Level4 + true + EditAndContinue + CompileAsC + + + _DEBUG;%(PreprocessorDefinitions) + 0x0409 + + + OpenAL32.lib;%(AdditionalDependencies) + $(OutDir)s_openal.dll + true + true + $(OutDir)s_openal.pdb + false + + + $(IntDir)s_openal.lib + MachineX86 + + + true + $(OutDir)s_openal.bsc + + + + + _DEBUG;%(PreprocessorDefinitions) + true + true + X64 + .\..\..\..\bin\VC10\$(Platform)\$(Configuration)\s_openal\s_openal.tlb + + + + + Disabled + WIN32;_DEBUG;_WINDOWS;__WIN32__;__MSC__;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + EnableFastChecks + MultiThreadedDebug + $(IntDir) + $(IntDir)s_openal.pdb + true + Level4 + true + ProgramDatabase + CompileAsC + + + _DEBUG;%(PreprocessorDefinitions) + 0x0409 + + + OpenAL32.lib;%(AdditionalDependencies) + $(OutDir)s_openal.dll + true + true + $(OutDir)s_openal.pdb + false + + + $(IntDir)s_openal.lib + MachineX64 + + + true + $(OutDir)s_openal.bsc + + + + + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + + + + + {0f554f1d-ed49-4d65-a9a7-f63c57f277be} + false + + + + + + \ No newline at end of file diff --git a/src/hardware/s_openal/s_openal-vc9.vcproj b/src/hardware/s_openal/s_openal-vc9.vcproj new file mode 100644 index 000000000..349755471 --- /dev/null +++ b/src/hardware/s_openal/s_openal-vc9.vcproj @@ -0,0 +1,443 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/hardware/s_openal/s_openal.c b/src/hardware/s_openal/s_openal.c new file mode 100644 index 000000000..ad842bde3 --- /dev/null +++ b/src/hardware/s_openal/s_openal.c @@ -0,0 +1,998 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright (C) 2001 by DooM Legacy Team. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +//----------------------------------------------------------------------------- +/// \file +/// \brief General driver for 3D sound system +/// +/// Implementend via OpenAL API + +#ifdef _WINDOWS +//#define WIN32_LEAN_AND_MEAN +#define RPC_NO_WINDOWS_H +#include +#include +FILE* logstream = NULL; +#else +#include +#include +#include +#include +#include +#include +#ifndef SDL // let not make a logstream here is we are inline the HW3D in the SDL binary +FILE* logstream = NULL; +#endif +#endif + +#ifdef __APPLE__ +#include //Main AL +#include //Helpers +#else +#include //Main AL +#include //Helpers +#endif + +#define _CREATE_DLL_ +#include "../../doomdef.h" +#include "../hw3dsdrv.h" + +//#undef DEBUG_TO_FILE +//#if defined ( SDL ) && !defined ( LOGMESSAGES ) +#define DEBUG_TO_FILE +//#endif + +// Internal sound stack +typedef struct stack_snd_s +{ + ALuint ALsource;// 3D data of 3D source + + ALint sfx_id;// Currently unused + + ALint LRU;// Currently unused + + ALboolean permanent;// Flag of static source +} stack_snd_t; + +#ifndef AL_INVALID +#define AL_INVALID (-1) +#endif + +static I_Error_t I_ErrorOpenAl = NULL; +static stack_snd_t *ALstack = NULL; // Sound stack +static ALsizei allocated_sounds = 0; // Size of stack +static ALsizei allocate_delta = 16; +static ALCdevice *ALCDevice = NULL; +static ALCcontext *ALContext = NULL; +static ALenum ALo_Lasterror = AL_NO_ERROR; +static ALenum ALCo_Lasterror = ALC_NO_ERROR; + +static ALenum ALo_GetError(ALvoid) +{ + ALo_Lasterror = alGetError(); + return ALo_Lasterror; +} + +static ALenum ALCo_GetError(ALvoid) +{ + ALCo_Lasterror = alcGetError(ALCDevice); + return ALCo_Lasterror; +} + +static ALfloat ALvol(ALint vol, ALsizei step) +{ + return ((ALfloat)vol)/(ALfloat)step; +} + +/* +static ALfloat Alpitch(ALint pitch) +{ +#if 1 + pitch = NORMAL_PITCH; +#endif + return pitch < NORMAL_PITCH ? + (float)(pitch + NORMAL_PITCH) / (NORMAL_PITCH * 2) + :(float)pitch / (float)NORMAL_PITCH; +} +*/ + +static const ALchar *GetALErrorString(ALenum err) +{ + switch (err) + { + case AL_NO_ERROR: + return "There no error"; + break; + + case AL_INVALID_NAME: + return "Invalid name"; + break; + + case AL_INVALID_ENUM: + return "Invalid enum"; + break; + + case AL_INVALID_VALUE: + return "Invalid value"; + break; + + case AL_INVALID_OPERATION: + return "Invalid operation"; + break; + + case AL_OUT_OF_MEMORY: + return "Out Of Memory"; + break; + + default: + return alGetString(err); + break; + } +} + +static const ALchar *GetALCErrorString(ALenum err) +{ + switch (err) + { + case ALC_NO_ERROR: + return "There no error"; + break; + + case ALC_INVALID_DEVICE: + return "Invalid Device"; + break; + + case ALC_INVALID_CONTEXT: + return "Invalid Context"; + break; + + case ALC_INVALID_ENUM: + return "Invalid enum"; + break; + + case ALC_INVALID_VALUE: + return "Invalid value"; + break; + + case ALC_OUT_OF_MEMORY: + return "Out Of Memory"; + break; + + default: + return alcGetString(ALCDevice, err); + break; + } +} + +/*************************************************************** + * + * DBG_Printf + * Output error messages to debug log if DEBUG_TO_FILE is defined, + * else do nothing + * + ************************************************************** + */ +// -----------------+ +// DBG_Printf : Output error messages to debug log if DEBUG_TO_FILE is defined, +// : else do nothing +// Returns : +// -----------------+ +FUNCPRINTF void DBG_Printf(const char *lpFmt, ... ) +{ +#ifdef DEBUG_TO_FILE + char str[4096] = ""; + va_list arglist; + + va_start(arglist, lpFmt); + vsnprintf(str, 4096, lpFmt, arglist); + va_end(arglist); + if (logstream) + fwrite(str, strlen(str), 1 , logstream); +#else + lpFmt = NULL; +#endif +} + +/*************************************************************** + * + * Grow internal sound stack by allocate_delta amount + * + *************************************************************** + */ +static ALboolean reallocate_stack(void) +{ + stack_snd_t *new_stack; + if (ALstack) + new_stack = realloc(ALstack, sizeof (stack_snd_t) * (allocated_sounds + allocate_delta)); + else + new_stack = malloc(sizeof (stack_snd_t) * (allocate_delta)); + if (new_stack) + { + ALsizei clean_stack; + ALstack = new_stack; + memset(&ALstack[allocated_sounds], 0, allocate_delta * sizeof (stack_snd_t)); + for (clean_stack = allocated_sounds; clean_stack < allocated_sounds; clean_stack++) + ALstack[clean_stack].ALsource = (ALuint)AL_INVALID; + allocated_sounds += allocate_delta; + return AL_TRUE; + } + return AL_FALSE; +} + + +/*************************************************************** + * + * Destroys source in stack + * + *************************************************************** + */ +static ALvoid kill_sound(stack_snd_t *snd) +{ + if (alIsSource(snd->ALsource)) + alDeleteSources(1,&snd->ALsource); + if (ALo_GetError() != AL_NO_ERROR) + { + DBG_Printf("%s: alDeleteSources, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); + } + memset(snd,0, sizeof (stack_snd_t)); + snd->ALsource = (ALuint)AL_INVALID; +} + +/*************************************************************** + * + * Returns free (unused) source stack slot + * If none available sound stack will be increased + * + *************************************************************** + */ +static ALsizei find_handle(void) +{ + ALsizei free_sfx = 0; + stack_snd_t *snd; + + for (snd = ALstack; free_sfx < allocated_sounds; snd++, free_sfx++) + { + if (snd->permanent) + continue; + if (snd->ALsource==(ALuint)AL_INVALID) + break; + if (!alIsSource(snd->ALsource)) + break; + ALo_GetError(); + if (snd->sfx_id == 0) + break; + } + + // No suitable resource found so increase sound stack + //DBG_Printf("sfx chan %d\n", free_sfx); + if (free_sfx == allocated_sounds) + { + DBG_Printf("No free or same sfx found so increase stack (currently %d srcs)\n", allocated_sounds); + free_sfx = reallocate_stack() ? free_sfx : (ALsizei)AL_INVALID; + } + return free_sfx; +} + +static ALvoid ALSetPan(ALuint sid, INT32 sep) +{ + ALfloat facing[3] ={0.0f, 0.0f, 0.0f}; //Alam: bad? + const ALfloat fsep = (ALfloat)sep; + const ALfloat nsep = (ALfloat)NORMAL_SEP; + if (sep) + { + facing[0] = (ALfloat)(fsep/nsep); + facing[2] = 1.0f; + } + alSourcefv(sid, AL_POSITION, facing); + if (ALo_GetError() != AL_NO_ERROR) + { + DBG_Printf("%s: alSourcefv, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); + } +} + + +/****************************************************************************** + * + * Initialise driver and listener + * + *****************************************************************************/ +EXPORT INT32 HWRAPI( Startup ) (I_Error_t FatalErrorFunction, snddev_t *snd_dev) +{ + ALenum model = AL_INVERSE_DISTANCE_CLAMPED; + ALCboolean inited = ALC_FALSE; + ALCint AlSetup[8] = {ALC_FREQUENCY,22050,ALC_REFRESH,35,ALC_SYNC,AL_FALSE,ALC_INVALID,ALC_INVALID}; +#if (defined (_WIN32) || defined (_WIN64)) && 0 + const ALCubyte *ALCdriver = alcGetString(NULL,ALC_DEFAULT_DEVICE_SPECIFIER); + const ALCubyte *DSdriver = "DirectSound"; + + if (!strcmp((const ALCbyte *)ALCdriver,"DirectSound3D")) //Alam: OpenAL's DS3D is buggy + ALCDevice = alcOpenDevice(DSdriver); //Open DirectSound + else //Alam: The OpenAl device + ALCDevice = alcOpenDevice(ALCdriver); //Open Default +#else + ALCDevice = alcOpenDevice(alcGetString(NULL,ALC_DEFAULT_DEVICE_SPECIFIER)); +#endif + if (ALCo_GetError() != ALC_NO_ERROR || !ALCDevice) + { + DBG_Printf("S_OpenAl: Error %s when opening device!\n", GetALCErrorString(ALCo_Lasterror)); + return inited; + } + else + { + DBG_Printf("Driver Name : %s\n", alcGetString(ALCDevice,ALC_DEVICE_SPECIFIER)); + DBG_Printf("Extensions : %s\n", alcGetString(ALCDevice,ALC_EXTENSIONS)); + DBG_Printf("S_OpenAl: OpenAl Device %s opened\n",alcGetString(ALCDevice, ALC_DEVICE_SPECIFIER)); + } + + I_ErrorOpenAl = FatalErrorFunction; + + AlSetup[1] = snd_dev->sample_rate; //ALC_FREQUENCY + AlSetup[1] = 44100; + AlSetup[3] = 35; //ALC_REFRESH + + //Alam: The Environment? + ALContext = alcCreateContext(ALCDevice,AlSetup); + if (ALCo_GetError() != ALC_NO_ERROR || !ALContext) + { + DBG_Printf("S_OpenAl: Error %s when making the environment!\n",GetALCErrorString(ALCo_Lasterror)); + return inited; + } + else + { + DBG_Printf("S_OpenAl: OpenAl environment made\n"); + } + + alcMakeContextCurrent(ALContext); + if (ALCo_GetError() != ALC_NO_ERROR) + { + DBG_Printf("S_OpenAl: Error %s when setting the environment!\n",GetALCErrorString(ALCo_Lasterror)); + return inited; + } + else + { + DBG_Printf("S_OpenAl: OpenAl environment setted up\n"); + } + + DBG_Printf("Vendor : %s\n", alGetString(AL_VENDOR)); + DBG_Printf("Renderer : %s\n", alGetString(AL_RENDERER)); + DBG_Printf("Version : %s\n", alGetString(AL_VERSION)); + DBG_Printf("Extensions : %s\n", alGetString(AL_EXTENSIONS)); + + alDopplerFactor(0.0f); + if (ALo_GetError() != AL_NO_ERROR) + { + DBG_Printf("S_OpenAl: Error %s when setting Doppler Factor!\n",GetALErrorString(ALo_Lasterror)); + return inited; + } + else + { + DBG_Printf("S_OpenAl: Doppler Factor of %f setted\n", alGetDouble(AL_DOPPLER_FACTOR)); + } + + alSpeedOfSound(600.0f); + if (ALo_GetError() != AL_NO_ERROR) + { + DBG_Printf("S_OpenAl: Error %s when setting Speed of Sound!\n",GetALErrorString(ALo_Lasterror)); + return inited; + } + else + { + DBG_Printf("S_OpenAl: Speed of Sound set to %f\n", alGetDouble(AL_SPEED_OF_SOUND)); + } + + alDistanceModel(model); + if (ALo_GetError() != AL_NO_ERROR) + { + DBG_Printf("S_OpenAl: Error %s when setting Distance Model!\n",GetALErrorString(ALo_Lasterror)); + return inited; + } + else + { + //DBG_Printf("S_OpenAl: %s mode setted\n",alGetString(model)); + } + + inited = reallocate_stack(); + + return inited; +} + +/****************************************************************************** + * + * Shutdown 3D Sound + * + ******************************************************************************/ +EXPORT void HWRAPI( Shutdown ) ( void ) +{ + ALsizei i; + + DBG_Printf ("S_OpenAL Shutdown()\n"); + + for (i = 0; i < allocated_sounds; i++) + { + StopSource(i); + kill_sound(ALstack + i); + } + +#if defined(linux) || defined(__linux) || defined(__linux__) + alcMakeContextCurrent(NULL); + //TODO:check? +#endif + + if (ALContext) + { + alcDestroyContext(ALContext); + ALContext = NULL; + } + + if (ALstack) + { + free(ALstack); + ALstack = NULL; + } + + //TODO:check? + if (ALCDevice) + { + alcCloseDevice(ALCDevice); + ALCDevice = NULL; + } + //TODO:check? +} + +#ifdef _MSC_VER +#pragma warning(disable : 4200) +#pragma pack(1) +#endif + +typedef struct +{ + ALushort header; // 3? + ALushort samplerate; // 11025+ + ALushort samples; // number of samples + ALushort dummy; // 0 + ALubyte data[0]; // data; +} ATTRPACK dssfx_t; + +#ifdef _MSC_VER +#pragma pack() +#pragma warning(default : 4200) +#endif + +static ALsizei getfreq(ALvoid *sfxdata, size_t len) +{ + dssfx_t *dsfx = sfxdata; + const ALsizei freq = SHORT(dsfx->samplerate); + + if (len <= 8) + return 0; + else + return freq; +} + +static ALsizei makechan(ALuint sfxhandle, ALboolean perm) +{ + ALsizei chan = find_handle(); + + if (chan == (ALsizei)AL_INVALID) return chan; + + alGenSources(1, &ALstack[chan].ALsource); + if (ALo_GetError() != AL_NO_ERROR || !alIsSource(ALstack[chan].ALsource)) + { + DBG_Printf("S_OpenAl: Error %s when make an ALSource!\n",GetALErrorString(ALo_Lasterror)); + ALstack[chan].ALsource = (ALuint)AL_INVALID; + return (ALsizei)AL_INVALID; + } + + ALstack[chan].permanent = perm; + + alSourceQueueBuffers(ALstack[chan].ALsource, 1, &sfxhandle); + if (ALo_GetError() != AL_NO_ERROR) + { + DBG_Printf("S_OpenAl: Error %s when queue up an alSource!\n",GetALErrorString(ALo_Lasterror)); + } + + return chan; +} + +/****************************************************************************** + * + * Creates ?D source + * + ******************************************************************************/ +EXPORT INT32 HWRAPI ( AddSource ) (source3D_data_t *src, u_int sfxhandle) +{ + ALsizei chan = makechan(sfxhandle, (ALboolean)(src?src->permanent:AL_FALSE)); + ALuint sid = (ALuint)AL_INVALID; + if (chan == (ALsizei)AL_INVALID) + return AL_INVALID; + else + sid = ALstack[chan].ALsource; + + if (src) //3D + { +#if 0 + alSourcef(sid, AL_REFERENCE_DISTANCE, src->min_distance); + if (ALo_GetError() != AL_NO_ERROR) + { + DBG_Printf("%s: AL_REFERENCE_DISTANCE, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); + } + + alSourcef(sid, AL_MAX_DISTANCE, src->max_distance); + if (ALo_GetError() != AL_NO_ERROR) + { + DBG_Printf("%s: AL_MAX_DISTANCE, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); + } +#endif + + if (src->head_relative) + alSourcei(sid, AL_SOURCE_RELATIVE, AL_TRUE); + else + alSourcei(sid, AL_SOURCE_RELATIVE, AL_FALSE); + if (ALo_GetError() != AL_NO_ERROR) + { + DBG_Printf("%s: AL_SOURCE_RELATIVE, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); + } + + alSource3f(sid, AL_POSITION, src->pos.x, src->pos.z, src->pos.y); + if (ALo_GetError() != AL_NO_ERROR) + { + DBG_Printf("%s: AL_POSITION, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); + } + alSource3f(sid, AL_VELOCITY, src->pos.momx, src->pos.momz, src->pos.momy); + if (ALo_GetError() != AL_NO_ERROR) + { + DBG_Printf("%s: AL_VELOCITY, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); + } + } + else //2D + { + alSourcei(sid, AL_SOURCE_RELATIVE, AL_TRUE); + if (ALo_GetError() != AL_NO_ERROR) + { + DBG_Printf("%s: AL_SOURCE_RELATIVE, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); + } + } + + alSourcef(sid, AL_ROLLOFF_FACTOR, 0.0f); + if (ALo_GetError() != AL_NO_ERROR) + { + DBG_Printf("%s: AL_ROLLOFF_FACTOR, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); + } + + alSourcef(sid, AL_REFERENCE_DISTANCE, 0.0f); + if (ALo_GetError() != AL_NO_ERROR) + { + DBG_Printf("%s: AL_REFERENCE_DISTANC, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); + } + return chan; +} + +EXPORT INT32 HWRAPI ( StartSource ) (INT32 chan) +{ + ALint state = AL_NONE; + ALuint sid = (ALuint)AL_INVALID; + + if (chan <= AL_INVALID || !alIsSource(ALstack[chan].ALsource)) + return AL_FALSE; + else + sid = ALstack[chan].ALsource; + + ALo_GetError(); + + alSourcePlay(sid); + if (ALo_GetError() != AL_NO_ERROR) + { + DBG_Printf("%s: alSourcePlay, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); + } + + alGetSourcei(sid, AL_SOURCE_STATE, &state); + if (ALo_GetError() != AL_NO_ERROR) + { + DBG_Printf("%s: alGetSourcei, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); + } + + return (state == AL_PLAYING); +} + +EXPORT void HWRAPI ( StopSource) (INT32 chan) +{ + ALuint sfxhandle = AL_NONE; + ALuint sid = (ALuint)AL_INVALID; + if (chan <= AL_INVALID || !alIsSource(ALstack[chan].ALsource)) + return; + else + sid = ALstack[chan].ALsource; + + ALo_GetError(); + +#if 1 + alSourceQueueBuffers(sid, 1, &sfxhandle); + if (ALo_GetError() != AL_NO_ERROR) + { + DBG_Printf("%s: alSourceQueueBuffers, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); + } +#else + alSourceStop(sid); + if (ALo_GetError() != AL_NO_ERROR) + { + DBG_Printf("%s: alSourceStop, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); + } +#endif +} + +EXPORT INT32 HWRAPI ( GetHW3DSVersion) (void) +{ + return VERSION; +} + +EXPORT void HWRAPI (BeginFrameUpdate) (void) +{ + alcSuspendContext(ALContext); + if (ALo_GetError() != AL_NO_ERROR) + { + DBG_Printf("%s: alcSuspendContext, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); + } +} + +EXPORT void HWRAPI (EndFrameUpdate) (void) +{ + alcProcessContext(ALContext); + if (ALo_GetError() != AL_NO_ERROR) + { + DBG_Printf("%s: alcProcessContext, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); + } +} + +EXPORT INT32 HWRAPI (IsPlaying) (INT32 chan) +{ + ALint state = AL_NONE; + ALuint sid = (ALuint)AL_INVALID; + + if (chan <= AL_INVALID || !alIsSource(ALstack[chan].ALsource)) + return AL_FALSE; + else + sid = ALstack[chan].ALsource; + + ALo_GetError(); + + alGetSourcei(sid, AL_SOURCE_STATE, &state); + if (ALo_GetError() != AL_NO_ERROR) + { + DBG_Printf("%s: alGetSourcei, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); + } + + return (state == AL_PLAYING); +} + +/****************************************************************************** + * UpdateListener + * + * Set up main listener properties: + * - position + * - orientation + * - velocity + *****************************************************************************/ +EXPORT void HWRAPI (UpdateListener) (listener_data_t *data, INT32 num) +{ + if (num != 1) return; + + if (data) + { + ALfloat facing[6]; + ALdouble f_angle = 0.0; + if (data->f_angle) f_angle = (ALdouble)((data->f_angle) / 180.0l * M_PIl); + facing[0] = (ALfloat)cos(f_angle); + facing[1] = 0.0f; + facing[2] = (ALfloat)sin(f_angle); + facing[3] = 0.0f; + facing[4] = 1.0f; + facing[5] = 0.0f; + + alListener3f(AL_POSITION,(ALfloat)-data->x,(ALfloat)data->z,(ALfloat)data->y); + if (ALo_GetError() != AL_NO_ERROR) + { + DBG_Printf("%s: AL_POSITIO, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); + } + + alListener3f(AL_VELOCITY,(ALfloat)data->momx,(ALfloat)data->momz,(ALfloat)data->momy); + if (ALo_GetError() != AL_NO_ERROR) + { + DBG_Printf("%s: AL_VELOCITY, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); + } + + alListenerfv(AL_ORIENTATION, facing); + if (ALo_GetError() != AL_NO_ERROR) + { + DBG_Printf("%s: AL_ORIENTATION, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); + } + } + else + { + DBG_Printf("Error: 1st listener data is missing\n"); + } +} + +/****************************************************************************** + * + * Update volume for 2D source and separation (panning) of 2D source + * + *****************************************************************************/ +EXPORT void HWRAPI (UpdateSourceParms) (INT32 chan, INT32 vol, INT32 sep) +{ + ALuint sid = AL_NONE; + ALint is2d = AL_FALSE; + if (chan > AL_INVALID && !alIsSource(ALstack[chan].ALsource)) + return; + else + sid = ALstack[chan].ALsource; + + alGetSourcei(sid, AL_SOURCE_RELATIVE, &is2d); + + if (!is2d) + return; + + if (vol != -1) + { + alSourcef(sid,AL_GAIN,ALvol(vol,256)); + if (ALo_GetError() != AL_NO_ERROR) + { + DBG_Printf("%s: alSourcef, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); + } + } + + if (sep != -1) + { + ALSetPan(sid,sep-NORMAL_SEP); + if (ALo_GetError() != AL_NO_ERROR) + { + DBG_Printf("%s: ALSetPan, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); + } + } +} + +// -------------------------------------------------------------------------- +// Set the global volume for sound effects +// -------------------------------------------------------------------------- +EXPORT void HWRAPI (SetGlobalSfxVolume) (INT32 vol) +{ + alListenerf(AL_GAIN, ALvol(vol,32)); + if (ALo_GetError() != AL_NO_ERROR) + { + DBG_Printf("%s: AL_GAIN, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); + } +} + +//Alam: Not Used? +EXPORT INT32 HWRAPI (SetCone) (INT32 chan, cone_def_t *cone_def) +{ + ALuint sid = AL_NONE; + ALint is2d = AL_FALSE; + if (chan > AL_INVALID && !alIsSource(ALstack[chan].ALsource)) + return AL_FALSE; + else + sid = ALstack[chan].ALsource; + + alGetSourcei(sid, AL_SOURCE_RELATIVE, &is2d); + + if(is2d || !cone_def) + return AL_FALSE; + + alSourcef(sid,AL_CONE_INNER_ANGLE,cone_def->inner); + if (ALo_GetError() != AL_NO_ERROR) + { + DBG_Printf("%s: AL_CONE_INNER_ANGLE, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); + } + + alSourcef(sid,AL_CONE_OUTER_ANGLE,cone_def->outer); + if (ALo_GetError() != AL_NO_ERROR) + { + DBG_Printf("%s: AL_CONE_OUTER_ANGL, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); + } + + alSourcei(sid,AL_CONE_OUTER_GAIN, cone_def->outer_gain); + if (ALo_GetError() != AL_NO_ERROR) + { + DBG_Printf("%s: AL_CONE_OUTER_GAIN, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); + } + + return AL_TRUE; +} + +EXPORT void HWRAPI (Update3DSource) (INT32 chan, source3D_pos_t *sfx) +{ + ALuint sid = AL_NONE; + ALint is2d = AL_FALSE; + if (chan > AL_INVALID && !alIsSource(ALstack[chan].ALsource)) + return; + else + sid = ALstack[chan].ALsource; + + alGetSourcei(sid, AL_SOURCE_RELATIVE, &is2d); + + if (is2d) + return; + + alSource3f(sid, AL_POSITION, sfx->x, sfx->z, sfx->y); + if (ALo_GetError() != AL_NO_ERROR) + { + DBG_Printf("%s: AL_POSITION, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); + } + + alSource3f(sid, AL_VELOCITY, sfx->momx, sfx->momz, sfx->momy); + if (ALo_GetError() != AL_NO_ERROR) + { + DBG_Printf("%s: AL_VELOCITY, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); + } +} + +//------------------------------------------------------------- +// Load new sound data into source +//------------------------------------------------------------- +EXPORT INT32 HWRAPI (ReloadSource) (INT32 chan, u_int sfxhandle) +{ + ALuint sid; + + if (chan <= AL_INVALID || !alIsSource(ALstack[chan].ALsource) || !alIsBuffer(sfxhandle)) + return AL_INVALID; + else + sid = ALstack[chan].ALsource; + + ALo_GetError(); + + alSourceQueueBuffers(sid, 1, &sfxhandle); + if (ALo_GetError() == AL_INVALID_OPERATION) //Alam: not needed? + { + alSourceStop(sid); + alSourcei(sid, AL_BUFFER, sfxhandle); + ALo_GetError(); + } + if (ALo_Lasterror != AL_NO_ERROR) + { + DBG_Printf("%s: alSourcei, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); + } + + return chan; +} + +/****************************************************************************** + * + * Destroy source and remove it from stack if it is a 2D source. + * Otherwise put source into cache + * + *****************************************************************************/ +EXPORT void HWRAPI (KillSource) (INT32 chan) +{ + if (chan > AL_INVALID && (ALsizei)chan <= allocated_sounds) + kill_sound(ALstack + chan); +} + +EXPORT u_int HWRAPI (AddSfx) (sfx_data_t *sfx) +{ + ALuint chan = (ALuint)AL_INVALID; + ALsizei freq = 11025; + ALubyte *data = NULL; + ALsizei size = 0; + + if (!sfx) + return 0; + else + { + data = ((ALubyte *)sfx->data)+8; + size = (ALsizei)(sfx->length-8); + } + + alGenBuffers(1, &chan); + if (ALo_GetError() != AL_NO_ERROR || !alIsBuffer(chan)) + { + DBG_Printf("S_OpenAl: Error %s when make an ALBuffer!\n",GetALErrorString(ALo_Lasterror)); + return (u_int)AL_INVALID; + } + + freq = getfreq(sfx->data, sfx->length); + + alBufferData(chan, AL_FORMAT_MONO8, data, size, freq); + if (ALo_GetError() != AL_NO_ERROR) + { + DBG_Printf("S_OpenAl: Error %s when setting up a alBuffer!\n",GetALErrorString(ALo_Lasterror)); + } + + return chan; +} + +EXPORT void HWRAPI (KillSfx) (u_int sfxhandle) +{ + ALuint ALsfx = sfxhandle; + if (!alIsBuffer(ALsfx)) + return; + alDeleteBuffers(1, &ALsfx); + if (ALo_GetError() == AL_INVALID_OPERATION) + { + // Buffer leak + } + else if (ALo_Lasterror != AL_NO_ERROR) + { + DBG_Printf("%s: alDeleteBuffers, %s", __FUNCTION__, GetALErrorString(ALo_Lasterror)); + } +} + +EXPORT void HWRAPI (GetHW3DSTitle) (char *buf, size_t size) +{ + strncpy(buf, "OpenAL", size); +} + + +#ifdef _WINDOWS +BOOL WINAPI DllMain(HINSTANCE hinstDLL, // handle to DLL module + DWORD fdwReason, // reason for calling function + LPVOID lpvReserved) // reserved +{ + // Perform actions based on the reason for calling. + UNREFERENCED_PARAMETER(lpvReserved); + switch ( fdwReason ) + { + case DLL_PROCESS_ATTACH: + // Initialize once for each new process. + // Return FALSE to fail DLL load. +#ifdef DEBUG_TO_FILE + logstream = fopen("s_openal.log", "wt"); + if (logstream == NULL) + return FALSE; +#endif + DisableThreadLibraryCalls(hinstDLL); + break; + + case DLL_THREAD_ATTACH: + // Do thread-specific initialization. + break; + + case DLL_THREAD_DETACH: + // Do thread-specific cleanup. + break; + + case DLL_PROCESS_DETACH: + // Perform any necessary cleanup. +#ifdef DEBUG_TO_FILE + if ( logstream) + { + fclose(logstream); + logstream = NULL; + } +#endif + break; + } + return TRUE; // Successful DLL_PROCESS_ATTACH. +} +#elif !defined (_WINDOWS) + +// ************************************************************************** +// FUNCTIONS +// ************************************************************************** + +EXPORT void _init() +{ +#ifdef DEBUG_TO_FILE + logstream = fopen("s_openal.log", "w+"); +#endif +} + +EXPORT void _fini() +{ +#ifdef DEBUG_TO_FILE + if (logstream) + fclose(logstream); + logstream = NULL; +#endif +} +#endif + diff --git a/src/hardware/s_openal/s_openal.dev b/src/hardware/s_openal/s_openal.dev new file mode 100644 index 000000000..c8fb9e62b --- /dev/null +++ b/src/hardware/s_openal/s_openal.dev @@ -0,0 +1,59 @@ +[Project] +FileName=s_openal.dev +Name=s_openal +Ver=1 +IsCpp=1 +Type=3 +Compiler=-D_M_IX86=500_@@_-Wall_@@_-fexceptions_@@_-D_WINDOWS_@@_ +CppCompiler= +Includes= +Linker=--def ../s_mingw.def_@@_-lopenal32_@@_ +Libs= +UnitCount=1 +Folders= +ObjFiles= +PrivateResource= +ResourceIncludes= +MakeIncludes= +Icon= +ExeOutput=..\..\..\bin +ObjectOutput=..\..\..\objs\Mingw\s_opengl +OverrideOutput=0 +OverrideOutputName=s_openal.dll +HostApplication= +CommandLine= +UseCustomMakefile=0 +CustomMakefile= +IncludeVersionInfo=0 +SupportXPThemes=0 +CompilerSet=0 +CompilerSettings=0000000010001001001001 + +[Unit1] +FileName=s_openal.c +Folder= +Compile=1 +CompileCpp=0 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[VersionInfo] +Major=0 +Minor=1 +Release=1 +Build=1 +LanguageID=1033 +CharsetID=1252 +CompanyName= +FileVersion=0.1 +FileDescription=Developed using the Dev-C++ IDE +InternalName= +LegalCopyright= +LegalTrademarks= +OriginalFilename=s_openal.dll +ProductName=s_openal +ProductVersion=0.1 +AutoIncBuildNr=0 + diff --git a/src/hardware/s_openal/s_openal.dsp b/src/hardware/s_openal/s_openal.dsp new file mode 100644 index 000000000..ac7fbaa84 --- /dev/null +++ b/src/hardware/s_openal/s_openal.dsp @@ -0,0 +1,98 @@ +# Microsoft Developer Studio Project File - Name="s_openal" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=s_openal - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "s_openal.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "s_openal.mak" CFG="s_openal - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "s_openal - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "s_openal - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "s_openal - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "..\..\..\bin\VC\Release\s_openal" +# PROP Intermediate_Dir "..\..\..\objs\VC\Release\s_openal" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "S_OPENAL_EXPORTS" /YX /FD /c +# ADD CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "__WIN32__" /D "__MSC__" /YX /FD /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "NDEBUG" /win32 +# SUBTRACT MTL /mktyplib203 +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 +# ADD LINK32 OpenAL32.lib /nologo /dll /pdb:"..\..\..\bin\VC\Release\s_openal.pdb" /machine:I386 /out:"C:\srb2demo2\s_openal.dll" +# SUBTRACT LINK32 /pdb:none + +!ELSEIF "$(CFG)" == "s_openal - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "..\..\..\bin\VC\Debug\s_openal" +# PROP Intermediate_Dir "..\..\..\objs\VC\Debug\s_openal" +# PROP Ignore_Export_Lib 1 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "S_OPENAL_EXPORTS" /YX /FD /GZ /c +# ADD CPP /nologo /MTd /W4 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "__WIN32__" /D "__MSC__" /D "_MBCS" /D "_USRDLL" /D "S_OPENAL_EXPORTS" /YX /FD /GZ /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 OpenAL32.lib /nologo /dll /pdb:"..\..\..\bin\VC\Debug\s_openal.pdb" /debug /machine:I386 /out:"C:\srb2demo2\s_openaldebug.dll" /pdbtype:sept +# SUBTRACT LINK32 /pdb:none + +!ENDIF + +# Begin Target + +# Name "s_openal - Win32 Release" +# Name "s_openal - Win32 Debug" +# Begin Source File + +SOURCE=.\s_openal.c +# End Source File +# End Target +# End Project diff --git a/src/hu_stuff.c b/src/hu_stuff.c new file mode 100644 index 000000000..7fdbd1c8e --- /dev/null +++ b/src/hu_stuff.c @@ -0,0 +1,1767 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 1993-1996 by id Software, Inc. +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Copyright (C) 1999-2014 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file hu_stuff.c +/// \brief Heads up display + +#include "doomdef.h" +#include "byteptr.h" +#include "hu_stuff.h" + +#include "m_menu.h" // gametype_cons_t +#include "m_cond.h" // emblems + +#include "d_clisrv.h" + +#include "g_game.h" +#include "g_input.h" + +#include "i_video.h" +#include "i_system.h" + +#include "st_stuff.h" // ST_HEIGHT +#include "r_local.h" + +#include "keys.h" +#include "v_video.h" + +#include "w_wad.h" +#include "z_zone.h" + +#include "console.h" +#include "am_map.h" +#include "d_main.h" + +#include "p_local.h" // camera, camera2 +#include "p_tick.h" + +#ifdef HWRENDER +#include "hardware/hw_main.h" +#endif + +#ifdef HAVE_BLUA +#include "lua_hud.h" +#endif + +// coords are scaled +#define HU_INPUTX 0 +#define HU_INPUTY 0 + +#define HU_SERVER_SAY 1 // Server message (dedicated). +#define HU_CSAY 2 // Server CECHOes to everyone. + +//------------------------------------------- +// heads up font +//------------------------------------------- +patch_t *hu_font[HU_FONTSIZE]; +patch_t *tny_font[HU_FONTSIZE]; +patch_t *tallnum[10]; // 0-9 +patch_t *nightsnum[10]; // 0-9 + +// Level title and credits fonts +patch_t *lt_font[LT_FONTSIZE]; +patch_t *cred_font[CRED_FONTSIZE]; + +static player_t *plr; +boolean chat_on; // entering a chat message? +static char w_chat[HU_MAXMSGLEN]; +static boolean headsupactive = false; +boolean hu_showscores; // draw rankings +static char hu_tick; + +patch_t *rflagico; +patch_t *bflagico; +patch_t *rmatcico; +patch_t *bmatcico; +patch_t *tagico; +patch_t *tallminus; + +//------------------------------------------- +// coop hud +//------------------------------------------- + +patch_t *emeraldpics[7]; +patch_t *tinyemeraldpics[7]; +static patch_t *emblemicon; +static patch_t *tokenicon; + +//------------------------------------------- +// misc vars +//------------------------------------------- + +// crosshair 0 = off, 1 = cross, 2 = angle, 3 = point, see m_menu.c +static patch_t *crosshair[HU_CROSSHAIRS]; // 3 precached crosshair graphics + +// ------- +// protos. +// ------- +static void HU_DrawRankings(void); +static void HU_DrawCoopOverlay(void); +static void HU_DrawNetplayCoopOverlay(void); + +//====================================================================== +// KEYBOARD LAYOUTS FOR ENTERING TEXT +//====================================================================== + +char *shiftxform; + +char english_shiftxform[] = +{ + 0, + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, + 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, + 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, + 31, + ' ', '!', '"', '#', '$', '%', '&', + '"', // shift-' + '(', ')', '*', '+', + '<', // shift-, + '_', // shift-- + '>', // shift-. + '?', // shift-/ + ')', // shift-0 + '!', // shift-1 + '@', // shift-2 + '#', // shift-3 + '$', // shift-4 + '%', // shift-5 + '^', // shift-6 + '&', // shift-7 + '*', // shift-8 + '(', // shift-9 + ':', + ':', // shift-; + '<', + '+', // shift-= + '>', '?', '@', + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', + 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', + '{', // shift-[ + '|', // shift-backslash - OH MY GOD DOES WATCOM SUCK + '}', // shift-] + '"', '_', + '~', // shift-` + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', + 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', + '{', '|', '}', '~', 127 +}; + +static char cechotext[1024]; +static tic_t cechotimer = 0; +static tic_t cechoduration = 5*TICRATE; +static INT32 cechoflags = 0; + +//====================================================================== +// HEADS UP INIT +//====================================================================== + +#ifndef NONET +// just after +static void Command_Say_f(void); +static void Command_Sayto_f(void); +static void Command_Sayteam_f(void); +static void Command_CSay_f(void); +static void Got_Saycmd(UINT8 **p, INT32 playernum); +#endif + +void HU_LoadGraphics(void) +{ + char buffer[9]; + INT32 i, j; + + if (dedicated) + return; + + j = HU_FONTSTART; + for (i = 0; i < HU_FONTSIZE; i++, j++) + { + // cache the heads-up font for entire game execution + sprintf(buffer, "STCFN%.3d", j); + if (W_CheckNumForName(buffer) == LUMPERROR) + hu_font[i] = NULL; + else + hu_font[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); + + // tiny version of the heads-up font + sprintf(buffer, "TNYFN%.3d", j); + if (W_CheckNumForName(buffer) == LUMPERROR) + tny_font[i] = NULL; + else + tny_font[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); + } + + // cache the level title font for entire game execution + lt_font[0] = (patch_t *)W_CachePatchName("LTFNT039", PU_HUDGFX); /// \note fake start hack + + // Number support + lt_font[9] = (patch_t *)W_CachePatchName("LTFNT048", PU_HUDGFX); + lt_font[10] = (patch_t *)W_CachePatchName("LTFNT049", PU_HUDGFX); + lt_font[11] = (patch_t *)W_CachePatchName("LTFNT050", PU_HUDGFX); + lt_font[12] = (patch_t *)W_CachePatchName("LTFNT051", PU_HUDGFX); + lt_font[13] = (patch_t *)W_CachePatchName("LTFNT052", PU_HUDGFX); + lt_font[14] = (patch_t *)W_CachePatchName("LTFNT053", PU_HUDGFX); + lt_font[15] = (patch_t *)W_CachePatchName("LTFNT054", PU_HUDGFX); + lt_font[16] = (patch_t *)W_CachePatchName("LTFNT055", PU_HUDGFX); + lt_font[17] = (patch_t *)W_CachePatchName("LTFNT056", PU_HUDGFX); + lt_font[18] = (patch_t *)W_CachePatchName("LTFNT057", PU_HUDGFX); + + j = LT_FONTSTART; + for (i = 0; i < LT_FONTSIZE; i++) + { + sprintf(buffer, "LTFNT%.3d", j); + j++; + + if (W_CheckNumForName(buffer) == LUMPERROR) + lt_font[i] = NULL; + else + lt_font[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); + } + + // cache the credits font for entire game execution (why not?) + j = CRED_FONTSTART; + for (i = 0; i < CRED_FONTSIZE; i++) + { + sprintf(buffer, "CRFNT%.3d", j); + j++; + + if (W_CheckNumForName(buffer) == LUMPERROR) + cred_font[i] = NULL; + else + cred_font[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); + } + + //cache numbers too! + for (i = 0; i < 10; i++) + { + sprintf(buffer, "STTNUM%d", i); + tallnum[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); + sprintf(buffer, "NGTNUM%d", i); + nightsnum[i] = (patch_t *) W_CachePatchName(buffer, PU_HUDGFX); + } + + // minus for negative tallnums + tallminus = (patch_t *)W_CachePatchName("STTMINUS", PU_HUDGFX); + + // cache the crosshairs, don't bother to know which one is being used, + // just cache all 3, they're so small anyway. + for (i = 0; i < HU_CROSSHAIRS; i++) + { + sprintf(buffer, "CROSHAI%c", '1'+i); + crosshair[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); + } + + emblemicon = W_CachePatchName("EMBLICON", PU_HUDGFX); + tokenicon = W_CachePatchName("TOKNICON", PU_HUDGFX); + + emeraldpics[0] = W_CachePatchName("CHAOS1", PU_HUDGFX); + emeraldpics[1] = W_CachePatchName("CHAOS2", PU_HUDGFX); + emeraldpics[2] = W_CachePatchName("CHAOS3", PU_HUDGFX); + emeraldpics[3] = W_CachePatchName("CHAOS4", PU_HUDGFX); + emeraldpics[4] = W_CachePatchName("CHAOS5", PU_HUDGFX); + emeraldpics[5] = W_CachePatchName("CHAOS6", PU_HUDGFX); + emeraldpics[6] = W_CachePatchName("CHAOS7", PU_HUDGFX); + tinyemeraldpics[0] = W_CachePatchName("TEMER1", PU_HUDGFX); + tinyemeraldpics[1] = W_CachePatchName("TEMER2", PU_HUDGFX); + tinyemeraldpics[2] = W_CachePatchName("TEMER3", PU_HUDGFX); + tinyemeraldpics[3] = W_CachePatchName("TEMER4", PU_HUDGFX); + tinyemeraldpics[4] = W_CachePatchName("TEMER5", PU_HUDGFX); + tinyemeraldpics[5] = W_CachePatchName("TEMER6", PU_HUDGFX); + tinyemeraldpics[6] = W_CachePatchName("TEMER7", PU_HUDGFX); +} + +// Initialise Heads up +// once at game startup. +// +void HU_Init(void) +{ +#ifndef NONET + COM_AddCommand("say", Command_Say_f); + COM_AddCommand("sayto", Command_Sayto_f); + COM_AddCommand("sayteam", Command_Sayteam_f); + COM_AddCommand("csay", Command_CSay_f); + RegisterNetXCmd(XD_SAY, Got_Saycmd); +#endif + + // set shift translation table + shiftxform = english_shiftxform; + + HU_LoadGraphics(); +} + +static inline void HU_Stop(void) +{ + headsupactive = false; +} + +// +// Reset Heads up when consoleplayer spawns +// +void HU_Start(void) +{ + if (headsupactive) + HU_Stop(); + + plr = &players[consoleplayer]; + + headsupactive = true; +} + +//====================================================================== +// EXECUTION +//====================================================================== + +#ifndef NONET +/** Runs a say command, sending an ::XD_SAY message. + * A say command consists of a signed 8-bit integer for the target, an + * unsigned 8-bit flag variable, and then the message itself. + * + * The target is 0 to say to everyone, 1 to 32 to say to that player, or -1 + * to -32 to say to everyone on that player's team. Note: This means you + * have to add 1 to the player number, since they are 0 to 31 internally. + * + * The flag HU_SERVER_SAY will be set if it is the dedicated server speaking. + * + * This function obtains the message using COM_Argc() and COM_Argv(). + * + * \param target Target to send message to. + * \param usedargs Number of arguments to ignore. + * \param flags Set HU_CSAY for server/admin to CECHO everyone. + * \sa Command_Say_f, Command_Sayteam_f, Command_Sayto_f, Got_Saycmd + * \author Graue + */ +static void DoSayCommand(SINT8 target, size_t usedargs, UINT8 flags) +{ + XBOXSTATIC char buf[254]; + size_t numwords, ix; + char *msg = &buf[2]; + const size_t msgspace = sizeof buf - 2; + + numwords = COM_Argc() - usedargs; + I_Assert(numwords > 0); + + if (cv_mute.value && !(server || adminplayer == consoleplayer)) + { + CONS_Alert(CONS_NOTICE, M_GetText("The chat is muted. You can't say anything at the moment.\n")); + return; + } + + // Only servers/admins can CSAY. + if(!server && adminplayer != consoleplayer) + flags &= ~HU_CSAY; + + // We handle HU_SERVER_SAY, not the caller. + flags &= ~HU_SERVER_SAY; + if(dedicated && !(flags & HU_CSAY)) + flags |= HU_SERVER_SAY; + + buf[0] = target; + buf[1] = flags; + msg[0] = '\0'; + + for (ix = 0; ix < numwords; ix++) + { + if (ix > 0) + strlcat(msg, " ", msgspace); + strlcat(msg, COM_Argv(ix + usedargs), msgspace); + } + + SendNetXCmd(XD_SAY, buf, strlen(msg) + 1 + msg-buf); +} + +/** Send a message to everyone. + * \sa DoSayCommand, Command_Sayteam_f, Command_Sayto_f + * \author Graue + */ +static void Command_Say_f(void) +{ + if (COM_Argc() < 2) + { + CONS_Printf(M_GetText("say : send a message\n")); + return; + } + + DoSayCommand(0, 1, 0); +} + +/** Send a message to a particular person. + * \sa DoSayCommand, Command_Sayteam_f, Command_Say_f + * \author Graue + */ +static void Command_Sayto_f(void) +{ + INT32 target; + + if (COM_Argc() < 3) + { + CONS_Printf(M_GetText("sayto : send a message to a player\n")); + return; + } + + target = nametonum(COM_Argv(1)); + if (target == -1) + { + CONS_Alert(CONS_NOTICE, M_GetText("No player with that name!\n")); + return; + } + target++; // Internally we use 0 to 31, but say command uses 1 to 32. + + DoSayCommand((SINT8)target, 2, 0); +} + +/** Send a message to members of the player's team. + * \sa DoSayCommand, Command_Say_f, Command_Sayto_f + * \author Graue + */ +static void Command_Sayteam_f(void) +{ + if (COM_Argc() < 2) + { + CONS_Printf(M_GetText("sayteam : send a message to your team\n")); + return; + } + + if (dedicated) + { + CONS_Alert(CONS_NOTICE, M_GetText("Dedicated servers can't send team messages. Use \"say\".\n")); + return; + } + + DoSayCommand(-1, 1, 0); +} + +/** Send a message to everyone, to be displayed by CECHO. Only + * permitted to servers and admins. + */ +static void Command_CSay_f(void) +{ + if (COM_Argc() < 2) + { + CONS_Printf(M_GetText("csay : send a message to be shown in the middle of the screen\n")); + return; + } + + if(!server && adminplayer != consoleplayer) + { + CONS_Alert(CONS_NOTICE, M_GetText("Only servers and admins can use csay.\n")); + return; + } + + DoSayCommand(0, 1, HU_CSAY); +} + +/** Receives a message, processing an ::XD_SAY command. + * \sa DoSayCommand + * \author Graue + */ +static void Got_Saycmd(UINT8 **p, INT32 playernum) +{ + SINT8 target; + UINT8 flags; + const char *dispname; + char *msg; + boolean action = false; + char *ptr; + + CONS_Debug(DBG_NETPLAY,"Recieved SAY cmd from Player %d (%s)\n", playernum+1, player_names[playernum]); + + target = READSINT8(*p); + flags = READUINT8(*p); + msg = (char *)*p; + SKIPSTRING(*p); + + if ((cv_mute.value || flags & (HU_CSAY|HU_SERVER_SAY)) && playernum != serverplayer && playernum != adminplayer) + { + CONS_Alert(CONS_WARNING, cv_mute.value ? + M_GetText("Illegal say command received from %s while muted\n") : M_GetText("Illegal csay command received from non-admin %s\n"), + player_names[playernum]); + if (server) + { + XBOXSTATIC UINT8 buf[2]; + + buf[0] = (UINT8)playernum; + buf[1] = KICK_MSG_CON_FAIL; + SendNetXCmd(XD_KICK, &buf, 2); + } + return; + } + + //check for invalid characters (0x80 or above) + { + size_t i; + const size_t j = strlen(msg); + for (i = 0; i < j; i++) + { + if (msg[i] & 0x80) + { + CONS_Alert(CONS_WARNING, M_GetText("Illegal say command received from %s containing invalid characters\n"), player_names[playernum]); + if (server) + { + XBOXSTATIC char buf[2]; + + buf[0] = (char)playernum; + buf[1] = KICK_MSG_CON_FAIL; + SendNetXCmd(XD_KICK, &buf, 2); + } + return; + } + } + } + + // If it's a CSAY, just CECHO and be done with it. + if (flags & HU_CSAY) + { + HU_SetCEchoDuration(5); + I_OutputMsg("Server message: "); + HU_DoCEcho(msg); + return; + } + + // Handle "/me" actions, but only in messages to everyone. + if (target == 0 && strlen(msg) > 4 && strnicmp(msg, "/me ", 4) == 0) + { + msg += 4; + action = true; + } + + if (flags & HU_SERVER_SAY) + dispname = "SERVER"; + else + dispname = player_names[playernum]; + + // Clean up message a bit + // If you use a \r character, you can remove your name + // from before the text and then pretend to be someone else! + ptr = msg; + while (*ptr != '\0') + { + if (*ptr == '\r') + *ptr = ' '; + + ptr++; + } + + // Show messages sent by you, to you, to your team, or to everyone: + if (playernum == consoleplayer // By you + || (target == -1 && ST_SameTeam(&players[consoleplayer], &players[playernum])) // To your team + || target == 0 // To everyone + || consoleplayer == target-1) // To you + { + const char *cstart = "", *cend = "", *adminchar = "~", *remotechar = "@", *fmt; + char *tempchar = NULL; + + // In CTF and team match, color the player's name. + if (G_GametypeHasTeams()) + { + cend = "\x80"; + if (players[playernum].ctfteam == 1) // red + cstart = "\x85"; + else if (players[playernum].ctfteam == 2) // blue + cstart = "\x84"; + } + + // Give admins and remote admins their symbols. + if (playernum == serverplayer) + tempchar = (char *)Z_Calloc(strlen(cstart) + strlen(adminchar) + 1, PU_STATIC, NULL); + else if (playernum == adminplayer) + tempchar = (char *)Z_Calloc(strlen(cstart) + strlen(remotechar) + 1, PU_STATIC, NULL); + if (tempchar) + { + strcat(tempchar, cstart); + if (playernum == serverplayer) + strcat(tempchar, adminchar); + else + strcat(tempchar, remotechar); + cstart = tempchar; + } + + // Choose the proper format string for display. + // Each format includes four strings: color start, display + // name, color end, and the message itself. + // '\4' makes the message yellow and beeps; '\3' just beeps. + if (action) + fmt = "\4* %s%s%s \x82%s\n"; + else if (target == 0) // To everyone + fmt = "\3<%s%s%s> %s\n"; + else if (target-1 == consoleplayer) // To you + fmt = "\3*%s%s%s* %s\n"; + else if (target > 0) // By you, to another player + { + // Use target's name. + dispname = player_names[target-1]; + fmt = "\3->*%s%s%s* %s\n"; + } + else // To your team + fmt = "\3>>%s%s%s<< (team) %s\n"; + + CONS_Printf(fmt, cstart, dispname, cend, msg); + if (tempchar) + Z_Free(tempchar); + } + else + CONS_Printf("Dropped chat: %d %d %s\n", playernum, target, msg); +} +#endif + +// Handles key input and string input +// +static inline boolean HU_keyInChatString(char *s, char ch) +{ + size_t l; + + if ((ch >= HU_FONTSTART && ch <= HU_FONTEND && hu_font[ch-HU_FONTSTART]) + || ch == ' ') // Allow spaces, of course + { + l = strlen(s); + if (l < HU_MAXMSGLEN - 1) + { + s[l++] = ch; + s[l]=0; + return true; + } + return false; + } + else if (ch == KEY_BACKSPACE) + { + l = strlen(s); + if (l) + s[--l] = 0; + else + return false; + } + else if (ch != KEY_ENTER) + return false; // did not eat key + + return true; // ate the key +} + +// +// +void HU_Ticker(void) +{ + if (dedicated) + return; + + hu_tick++; + hu_tick &= 7; // currently only to blink chat input cursor + + if (PLAYER1INPUTDOWN(gc_scores)) + hu_showscores = !chat_on; + else + hu_showscores = false; +} + +#define QUEUESIZE 256 + +static boolean teamtalk = false; +static char chatchars[QUEUESIZE]; +static INT32 head = 0, tail = 0; + +// +// HU_dequeueChatChar +// +char HU_dequeueChatChar(void) +{ + char c; + + if (head != tail) + { + c = chatchars[tail]; + tail = (tail + 1) & (QUEUESIZE-1); + } + else + c = 0; + + return c; +} + +// +// +static void HU_queueChatChar(char c) +{ + // send automaticly the message (no more chat char) + if (c == KEY_ENTER) + { + char buf[2+256]; + size_t ci = 2; + + do { + c = HU_dequeueChatChar(); + if (!c || (c >= ' ' && !(c & 0x80))) // copy printable characters and terminating '\0' only. + buf[ci++]=c; + } while (c); + + // last minute mute check + if (cv_mute.value && !(server || adminplayer == consoleplayer)) + { + CONS_Alert(CONS_NOTICE, M_GetText("The chat is muted. You can't say anything at the moment.\n")); + return; + } + + if (ci > 3) // don't send target+flags+empty message. + { + if (teamtalk) + buf[0] = -1; // target + else + buf[0] = 0; // target + buf[1] = 0; // flags + SendNetXCmd(XD_SAY, buf, 2 + strlen(&buf[2]) + 1); + } + return; + } + + if (((head + 1) & (QUEUESIZE-1)) == tail) + CONS_Printf(M_GetText("[Message unsent]\n")); // message not sent + else + { + if (c == KEY_BACKSPACE) + { + if (tail != head) + head = (head - 1) & (QUEUESIZE-1); + } + else + { + chatchars[head] = c; + head = (head + 1) & (QUEUESIZE-1); + } + } +} + +void HU_clearChatChars(void) +{ + while (tail != head) + HU_queueChatChar(KEY_BACKSPACE); + chat_on = false; +} + +// +// Returns true if key eaten +// +boolean HU_Responder(event_t *ev) +{ + static boolean shiftdown = false; + UINT8 c; + + if (ev->data1 == KEY_LSHIFT || ev->data1 == KEY_RSHIFT) + { + shiftdown = (ev->type == ev_keydown); + return chat_on; + } + + if (ev->type != ev_keydown) + return false; + + // only KeyDown events now... + + if (!chat_on) + { + // enter chat mode + if ((ev->data1 == gamecontrol[gc_talkkey][0] || ev->data1 == gamecontrol[gc_talkkey][1]) + && netgame && (!cv_mute.value || server || (adminplayer == consoleplayer))) + { + if (cv_mute.value && !(server || adminplayer == consoleplayer)) + return false; + chat_on = true; + w_chat[0] = 0; + teamtalk = false; + return true; + } + if ((ev->data1 == gamecontrol[gc_teamkey][0] || ev->data1 == gamecontrol[gc_teamkey][1]) + && netgame && (!cv_mute.value || server || (adminplayer == consoleplayer))) + { + if (cv_mute.value && !(server || adminplayer == consoleplayer)) + return false; + chat_on = true; + w_chat[0] = 0; + teamtalk = true; + return true; + } + } + else // if chat_on + { + c = (UINT8)ev->data1; + + // use console translations + if (shiftdown) + c = shiftxform[c]; + + if (HU_keyInChatString(w_chat,c)) + HU_queueChatChar(c); + if (c == KEY_ENTER) + chat_on = false; + else if (c == KEY_ESCAPE) + chat_on = false; + + return true; + } + return false; +} + +//====================================================================== +// HEADS UP DRAWING +//====================================================================== + +// +// HU_DrawChat +// +// Draw chat input +// +static void HU_DrawChat(void) +{ + INT32 t = 0, c = 0, y = HU_INPUTY; + size_t i = 0; + const char *ntalk = "Say: ", *ttalk = "Say-Team: "; + const char *talk = ntalk; + INT32 charwidth = 8 * con_scalefactor; //SHORT(hu_font['A'-HU_FONTSTART]->width) * con_scalefactor; + INT32 charheight = 8 * con_scalefactor; //SHORT(hu_font['A'-HU_FONTSTART]->height) * con_scalefactor; + + if (teamtalk) + { + talk = ttalk; +#if 0 + if (players[consoleplayer].ctfteam == 1) + t = 0x500; // Red + else if (players[consoleplayer].ctfteam == 2) + t = 0x400; // Blue +#endif + } + + while (talk[i]) + { + if (talk[i] < HU_FONTSTART) + { + ++i; + //charwidth = 4 * con_scalefactor; + } + else + { + //charwidth = SHORT(hu_font[talk[i]-HU_FONTSTART]->width) * con_scalefactor; + V_DrawCharacter(HU_INPUTX + c, y, talk[i++] | cv_constextsize.value | V_NOSCALESTART, !cv_allcaps.value); + } + c += charwidth; + } + + i = 0; + while (w_chat[i]) + { + //Hurdler: isn't it better like that? + if (w_chat[i] < HU_FONTSTART) + { + ++i; + //charwidth = 4 * con_scalefactor; + } + else + { + //charwidth = SHORT(hu_font[w_chat[i]-HU_FONTSTART]->width) * con_scalefactor; + V_DrawCharacter(HU_INPUTX + c, y, w_chat[i++] | cv_constextsize.value | V_NOSCALESTART | t, !cv_allcaps.value); + } + + c += charwidth; + if (c >= vid.width) + { + c = 0; + y += charheight; + } + } + + if (hu_tick < 4) + V_DrawCharacter(HU_INPUTX + c, y, '_' | cv_constextsize.value |V_NOSCALESTART|t, !cv_allcaps.value); +} + + +// draw the Crosshair, at the exact center of the view. +// +// Crosshairs are pre-cached at HU_Init + +static inline void HU_DrawCrosshair(void) +{ + INT32 i, y; + + i = cv_crosshair.value & 3; + if (!i) + return; + + if ((netgame || multiplayer) && players[displayplayer].spectator) + return; + +#ifdef HWRENDER + if (rendermode != render_soft) + y = (INT32)gr_basewindowcentery; + else +#endif + y = viewwindowy + (viewheight>>1); + + V_DrawTranslucentPatch(vid.width>>1, y, V_NOSCALESTART|V_OFFSET, crosshair[i - 1]); +} + +static inline void HU_DrawCrosshair2(void) +{ + INT32 i, y; + + i = cv_crosshair2.value & 3; + if (!i) + return; + + if ((netgame || multiplayer) && players[secondarydisplayplayer].spectator) + return; + +#ifdef HWRENDER + if (rendermode != render_soft) + y = (INT32)gr_basewindowcentery; + else +#endif + y = viewwindowy + (viewheight>>1); + + if (splitscreen) + { +#ifdef HWRENDER + if (rendermode != render_soft) + y += (INT32)gr_viewheight; + else +#endif + y += viewheight; + + V_DrawTranslucentPatch(vid.width>>1, y, V_NOSCALESTART|V_OFFSET, crosshair[i - 1]); + } +} + +static void HU_DrawCEcho(void) +{ + INT32 i = 0; + INT32 y = (BASEVIDHEIGHT/2)-4; + INT32 pnumlines = 0; + + UINT32 realflags = cechoflags; + INT32 realalpha = (INT32)((cechoflags & V_ALPHAMASK) >> V_ALPHASHIFT); + + char *line; + char *echoptr; + char temp[1024]; + + for (i = 0; cechotext[i] != '\0'; ++i) + if (cechotext[i] == '\\') + pnumlines++; + + y -= (pnumlines-1)*((realflags & V_RETURN8) ? 4 : 6); + + // Prevent crashing because I'm sick of this + if (y < 0) + { + CONS_Alert(CONS_WARNING, "CEcho contained too many lines, not displaying\n"); + cechotimer = 0; + return; + } + + // Automatic fadeout + if (realflags & V_AUTOFADEOUT) + { + UINT32 tempalpha = (UINT32)max((INT32)(10 - cechotimer), realalpha); + + realflags &= ~V_ALPHASHIFT; + realflags |= (tempalpha << V_ALPHASHIFT); + } + + strcpy(temp, cechotext); + echoptr = &temp[0]; + + while (*echoptr != '\0') + { + line = strchr(echoptr, '\\'); + + if (line == NULL) + break; + + *line = '\0'; + + V_DrawCenteredString(BASEVIDWIDTH/2, y, realflags, echoptr); + y += ((realflags & V_RETURN8) ? 8 : 12); + + echoptr = line; + echoptr++; + } + + --cechotimer; +} + +static void HU_drawGametype(void) +{ + INT32 i = 0; + + for (i = 0; gametype_cons_t[i].strvalue; i++) + { + if (gametype_cons_t[i].value == gametype) + { + if (splitscreen) + V_DrawString(4, 184, 0, gametype_cons_t[i].strvalue); + else + V_DrawString(4, 192, 0, gametype_cons_t[i].strvalue); + return; + } + } +} + +// +// demo info stuff +// +UINT32 hu_demoscore; +UINT32 hu_demotime; +UINT16 hu_demorings; + +static void HU_DrawDemoInfo(void) +{ + V_DrawString(4, 188-24, V_YELLOWMAP, va(M_GetText("%s's replay"), player_names[0])); + V_DrawString(4, 188-16, V_YELLOWMAP|V_MONOSPACE, "SCORE:"); + V_DrawRightAlignedString(120, 188-16, V_MONOSPACE, va("%d", hu_demoscore)); + + V_DrawString(4, 188- 8, V_YELLOWMAP|V_MONOSPACE, "TIME:"); + if (hu_demotime != UINT32_MAX) + V_DrawRightAlignedString(120, 188- 8, V_MONOSPACE, va("%i:%02i.%02i", + G_TicsToMinutes(hu_demotime,true), + G_TicsToSeconds(hu_demotime), + G_TicsToCentiseconds(hu_demotime))); + else + V_DrawRightAlignedString(120, 188- 8, V_MONOSPACE, "--:--.--"); + + V_DrawString(4, 188 , V_YELLOWMAP|V_MONOSPACE, "RINGS:"); + V_DrawRightAlignedString(120, 188 , V_MONOSPACE, va("%d", hu_demorings)); +} + +// Heads up displays drawer, call each frame +// +void HU_Drawer(void) +{ + // draw chat string plus cursor + if (chat_on) + HU_DrawChat(); + + if (cechotimer) + HU_DrawCEcho(); + + if (demoplayback && hu_showscores) + HU_DrawDemoInfo(); + + if (!Playing() + || gamestate == GS_INTERMISSION || gamestate == GS_CUTSCENE + || gamestate == GS_CREDITS || gamestate == GS_EVALUATION + || gamestate == GS_GAMEEND) + return; + + // draw multiplayer rankings + if (hu_showscores) + { + if (netgame || multiplayer) + { +#ifdef HAVE_BLUA + if (LUA_HudEnabled(hud_rankings)) +#endif + HU_DrawRankings(); + if (gametype == GT_COOP) + HU_DrawNetplayCoopOverlay(); + } + else + HU_DrawCoopOverlay(); +#ifdef HAVE_BLUA + LUAh_ScoresHUD(); +#endif + } + + if (gamestate != GS_LEVEL) + return; + + // draw the crosshair, not when viewing demos nor with chasecam + if (!automapactive && cv_crosshair.value && !demoplayback && !camera.chase && !players[displayplayer].spectator) + HU_DrawCrosshair(); + + if (!automapactive && cv_crosshair2.value && !demoplayback && !camera2.chase && !players[secondarydisplayplayer].spectator) + HU_DrawCrosshair2(); +} + +//====================================================================== +// HUD MESSAGES CLEARING FROM SCREEN +//====================================================================== + +// Clear old messages from the borders around the view window +// (only for reduced view, refresh the borders when needed) +// +// startline: y coord to start clear, +// clearlines: how many lines to clear. +// +static INT32 oldclearlines; + +void HU_Erase(void) +{ + INT32 topline, bottomline; + INT32 y, yoffset; + +#ifdef HWRENDER + // clear hud msgs on double buffer (OpenGL mode) + boolean secondframe; + static INT32 secondframelines; +#endif + + if (con_clearlines == oldclearlines && !con_hudupdate && !chat_on) + return; + +#ifdef HWRENDER + // clear the other frame in double-buffer modes + secondframe = (con_clearlines != oldclearlines); + if (secondframe) + secondframelines = oldclearlines; +#endif + + // clear the message lines that go away, so use _oldclearlines_ + bottomline = oldclearlines; + oldclearlines = con_clearlines; + if (chat_on) + if (bottomline < 8) + bottomline = 8; + + if (automapactive || viewwindowx == 0) // hud msgs don't need to be cleared + return; + + // software mode copies view border pattern & beveled edges from the backbuffer + if (rendermode == render_soft) + { + topline = 0; + for (y = topline, yoffset = y*vid.width; y < bottomline; y++, yoffset += vid.width) + { + if (y < viewwindowy || y >= viewwindowy + viewheight) + R_VideoErase(yoffset, vid.width); // erase entire line + else + { + R_VideoErase(yoffset, viewwindowx); // erase left border + // erase right border + R_VideoErase(yoffset + viewwindowx + viewwidth, viewwindowx); + } + } + con_hudupdate = false; // if it was set.. + } +#ifdef HWRENDER + else if (rendermode != render_none) + { + // refresh just what is needed from the view borders + HWR_DrawViewBorder(secondframelines); + con_hudupdate = secondframe; + } +#endif +} + +//====================================================================== +// IN-LEVEL MULTIPLAYER RANKINGS +//====================================================================== + +// +// HU_DrawTabRankings +// +void HU_DrawTabRankings(INT32 x, INT32 y, playersort_t *tab, INT32 scorelines, INT32 whiteplayer) +{ + INT32 i; + const UINT8 *colormap; + + //this function is designed for 9 or less score lines only + I_Assert(scorelines <= 9); + + V_DrawFill(1, 26, 318, 1, 0); //Draw a horizontal line because it looks nice! + + for (i = 0; i < scorelines; i++) + { + if (players[tab[i].num].spectator) + continue; //ignore them. + + V_DrawString(x + 24, y, + ((tab[i].num == whiteplayer) ? V_YELLOWMAP : 0) + | ((players[tab[i].num].health > 0) ? 0 : V_60TRANS) + | V_ALLOWLOWERCASE, tab[i].name); + + // Draw emeralds + if (!players[tab[i].num].powers[pw_super] + || ((leveltime/7) & 1)) + { + HU_DrawEmeralds(x-12,y+2,tab[i].emeralds); + } + + if (players[tab[i].num].health <= 0) + V_DrawSmallTranslucentPatch (x, y-4, V_80TRANS, livesback); + else + V_DrawSmallScaledPatch (x, y-4, 0, livesback); + + if (tab[i].color == 0) + { + colormap = colormaps; + if (players[tab[i].num].powers[pw_super]) + V_DrawSmallScaledPatch(x, y-4, 0, superprefix[players[tab[i].num].skin]); + else + { + if (players[tab[i].num].health <= 0) + V_DrawSmallTranslucentPatch(x, y-4, V_80TRANS, faceprefix[players[tab[i].num].skin]); + else + V_DrawSmallScaledPatch(x, y-4, 0, faceprefix[players[tab[i].num].skin]); + } + } + else + { + if (players[tab[i].num].powers[pw_super]) + { + colormap = R_GetTranslationColormap(players[tab[i].num].skin, players[tab[i].num].mo ? players[tab[i].num].mo->color : tab[i].color, GTC_CACHE); + V_DrawSmallMappedPatch (x, y-4, 0, superprefix[players[tab[i].num].skin], colormap); + } + else + { + colormap = R_GetTranslationColormap(players[tab[i].num].skin, players[tab[i].num].mo ? players[tab[i].num].mo->color : tab[i].color, GTC_CACHE); + if (players[tab[i].num].health <= 0) + V_DrawSmallTranslucentMappedPatch (x, y-4, V_80TRANS, faceprefix[players[tab[i].num].skin], colormap); + else + V_DrawSmallMappedPatch (x, y-4, 0, faceprefix[players[tab[i].num].skin], colormap); + } + } + + if (G_GametypeUsesLives()) //show lives + V_DrawRightAlignedString(x, y+4, V_ALLOWLOWERCASE|((players[tab[i].num].health > 0) ? 0 : V_60TRANS), va("%dx", players[tab[i].num].lives)); + else if (G_TagGametype() && players[tab[i].num].pflags & PF_TAGIT) + { + if (players[tab[i].num].health <= 0) + V_DrawSmallTranslucentPatch(x-32, y-4, V_60TRANS, tagico); + else + V_DrawSmallScaledPatch(x-32, y-4, 0, tagico); + } + + if (gametype == GT_RACE) + { + if (circuitmap) + { + if (players[tab[i].num].exiting) + V_DrawRightAlignedString(x+240, y, 0, va("%i:%02i.%02i", G_TicsToMinutes(players[tab[i].num].realtime,true), G_TicsToSeconds(players[tab[i].num].realtime), G_TicsToCentiseconds(players[tab[i].num].realtime))); + else + V_DrawRightAlignedString(x+240, y, ((players[tab[i].num].health > 0) ? 0 : V_60TRANS), va("%u", tab[i].count)); + } + else + V_DrawRightAlignedString(x+240, y, ((players[tab[i].num].health > 0) ? 0 : V_60TRANS), va("%i:%02i.%02i", G_TicsToMinutes(tab[i].count,true), G_TicsToSeconds(tab[i].count), G_TicsToCentiseconds(tab[i].count))); + } + else + V_DrawRightAlignedString(x+240, y, ((players[tab[i].num].health > 0) ? 0 : V_60TRANS), va("%u", tab[i].count)); + + y += 16; + } +} + +// +// HU_DrawTeamTabRankings +// +void HU_DrawTeamTabRankings(playersort_t *tab, INT32 whiteplayer) +{ + INT32 i,x,y; + INT32 redplayers = 0, blueplayers = 0; + const UINT8 *colormap; + char name[MAXPLAYERNAME+1]; + + V_DrawFill(160, 26, 1, 154, 0); //Draw a vertical line to separate the two teams. + V_DrawFill(1, 26, 318, 1, 0); //And a horizontal line to make a T. + V_DrawFill(1, 180, 318, 1, 0); //And a horizontal line near the bottom. + + for (i = 0; i < MAXPLAYERS; i++) + { + if (players[tab[i].num].spectator) + continue; //ignore them. + + if (tab[i].color == skincolor_redteam) //red + { + if (redplayers++ > 8) + continue; + x = 32 + (BASEVIDWIDTH/2); + y = (redplayers * 16) + 16; + } + else if (tab[i].color == skincolor_blueteam) //blue + { + if (blueplayers++ > 8) + continue; + x = 32; + y = (blueplayers * 16) + 16; + } + else //er? not on red or blue, so ignore them + continue; + + strlcpy(name, tab[i].name, 9); + V_DrawString(x + 24, y, + ((tab[i].num == whiteplayer) ? V_YELLOWMAP : 0) + | ((players[tab[i].num].health > 0) ? 0 : V_TRANSLUCENT) + | V_ALLOWLOWERCASE, name); + + if (gametype == GT_CTF) + { + if (players[tab[i].num].gotflag & GF_REDFLAG) // Red + V_DrawSmallScaledPatch(x-28, y-4, 0, rflagico); + else if (players[tab[i].num].gotflag & GF_BLUEFLAG) // Blue + V_DrawSmallScaledPatch(x-28, y-4, 0, bflagico); + } + + // Draw emeralds + if (!players[tab[i].num].powers[pw_super] + || ((leveltime/7) & 1)) + { + HU_DrawEmeralds(x-12,y+2,tab[i].emeralds); + } + + if (players[tab[i].num].powers[pw_super]) + { + colormap = R_GetTranslationColormap(players[tab[i].num].skin, players[tab[i].num].mo ? players[tab[i].num].mo->color : tab[i].color, GTC_CACHE); + V_DrawSmallMappedPatch (x, y-4, 0, superprefix[players[tab[i].num].skin], colormap); + } + else + { + colormap = R_GetTranslationColormap(players[tab[i].num].skin, players[tab[i].num].mo ? players[tab[i].num].mo->color : tab[i].color, GTC_CACHE); + if (players[tab[i].num].health <= 0) + V_DrawSmallTranslucentMappedPatch (x, y-4, 0, faceprefix[players[tab[i].num].skin], colormap); + else + V_DrawSmallMappedPatch (x, y-4, 0, faceprefix[players[tab[i].num].skin], colormap); + } + V_DrawRightAlignedString(x+120, y, ((players[tab[i].num].health > 0) ? 0 : V_TRANSLUCENT), va("%u", tab[i].count)); + } +} + +// +// HU_DrawDualTabRankings +// +void HU_DrawDualTabRankings(INT32 x, INT32 y, playersort_t *tab, INT32 scorelines, INT32 whiteplayer) +{ + INT32 i; + const UINT8 *colormap; + char name[MAXPLAYERNAME+1]; + + V_DrawFill(160, 26, 1, 154, 0); //Draw a vertical line to separate the two sides. + V_DrawFill(1, 26, 318, 1, 0); //And a horizontal line to make a T. + V_DrawFill(1, 180, 318, 1, 0); //And a horizontal line near the bottom. + + if (gametype == GT_RACE || gametype == GT_COOP) + x -= 32; //we need more room! + + for (i = 0; i < scorelines; i++) + { + if (players[tab[i].num].spectator) + continue; //ignore them. + + strlcpy(name, tab[i].name, 9); + V_DrawString(x + 24, y, + ((tab[i].num == whiteplayer) ? V_YELLOWMAP : 0) + | ((players[tab[i].num].health > 0) ? 0 : V_TRANSLUCENT) + | V_ALLOWLOWERCASE, name); + + if (G_GametypeUsesLives()) //show lives + V_DrawRightAlignedString(x, y+4, V_ALLOWLOWERCASE, va("%dx", players[tab[i].num].lives)); + else if (G_TagGametype() && players[tab[i].num].pflags & PF_TAGIT) + V_DrawSmallScaledPatch(x-28, y-4, 0, tagico); + + // Draw emeralds + if (!players[tab[i].num].powers[pw_super] + || ((leveltime/7) & 1)) + { + HU_DrawEmeralds(x-12,y+2,tab[i].emeralds); + } + + //V_DrawSmallScaledPatch (x, y-4, 0, livesback); + if (tab[i].color == 0) + { + colormap = colormaps; + if (players[tab[i].num].powers[pw_super]) + V_DrawSmallScaledPatch (x, y-4, 0, superprefix[players[tab[i].num].skin]); + else + { + if (players[tab[i].num].health <= 0) + V_DrawSmallTranslucentPatch (x, y-4, 0, faceprefix[players[tab[i].num].skin]); + else + V_DrawSmallScaledPatch (x, y-4, 0, faceprefix[players[tab[i].num].skin]); + } + } + else + { + if (players[tab[i].num].powers[pw_super]) + { + colormap = R_GetTranslationColormap(players[tab[i].num].skin, players[tab[i].num].mo ? players[tab[i].num].mo->color : tab[i].color, GTC_CACHE); + V_DrawSmallMappedPatch (x, y-4, 0, superprefix[players[tab[i].num].skin], colormap); + } + else + { + colormap = R_GetTranslationColormap(players[tab[i].num].skin, players[tab[i].num].mo ? players[tab[i].num].mo->color : tab[i].color, GTC_CACHE); + if (players[tab[i].num].health <= 0) + V_DrawSmallTranslucentMappedPatch (x, y-4, 0, faceprefix[players[tab[i].num].skin], colormap); + else + V_DrawSmallMappedPatch (x, y-4, 0, faceprefix[players[tab[i].num].skin], colormap); + } + } + + if (gametype == GT_RACE) + { + if (circuitmap) + { + if (players[tab[i].num].exiting) + V_DrawRightAlignedString(x+156, y, 0, va("%i:%02i.%02i", G_TicsToMinutes(players[tab[i].num].realtime,true), G_TicsToSeconds(players[tab[i].num].realtime), G_TicsToCentiseconds(players[tab[i].num].realtime))); + else + V_DrawRightAlignedString(x+156, y, ((players[tab[i].num].health > 0) ? 0 : V_TRANSLUCENT), va("%u", tab[i].count)); + } + else + V_DrawRightAlignedString(x+156, y, ((players[tab[i].num].health > 0) ? 0 : V_TRANSLUCENT), va("%i:%02i.%02i", G_TicsToMinutes(tab[i].count,true), G_TicsToSeconds(tab[i].count), G_TicsToCentiseconds(tab[i].count))); + } + else + V_DrawRightAlignedString(x+120, y, ((players[tab[i].num].health > 0) ? 0 : V_TRANSLUCENT), va("%u", tab[i].count)); + + y += 16; + if (y > 160) + { + y = 32; + x += BASEVIDWIDTH/2; + } + } +} + +// +// HU_DrawEmeralds +// +void HU_DrawEmeralds(INT32 x, INT32 y, INT32 pemeralds) +{ + //Draw the emeralds, in the CORRECT order, using tiny emerald sprites. + if (pemeralds & EMERALD1) + V_DrawSmallScaledPatch(x , y-6, 0, tinyemeraldpics[0]); + + if (pemeralds & EMERALD2) + V_DrawSmallScaledPatch(x+4, y-3, 0, tinyemeraldpics[1]); + + if (pemeralds & EMERALD3) + V_DrawSmallScaledPatch(x+4, y+3, 0, tinyemeraldpics[2]); + + if (pemeralds & EMERALD4) + V_DrawSmallScaledPatch(x , y+6, 0, tinyemeraldpics[3]); + + if (pemeralds & EMERALD5) + V_DrawSmallScaledPatch(x-4, y+3, 0, tinyemeraldpics[4]); + + if (pemeralds & EMERALD6) + V_DrawSmallScaledPatch(x-4, y-3, 0, tinyemeraldpics[5]); + + if (pemeralds & EMERALD7) + V_DrawSmallScaledPatch(x, y, 0, tinyemeraldpics[6]); +} + +// +// HU_DrawSpectatorTicker +// +static inline void HU_DrawSpectatorTicker(void) +{ + int i; + int length = 0, height = 174; + int totallength = 0, templength = 0; + + for (i = 0; i < MAXPLAYERS; i++) + if (playeringame[i] && players[i].spectator) + totallength += (signed)strlen(player_names[i]) * 8 + 16; + + length -= (leveltime % (totallength + BASEVIDWIDTH)); + length += BASEVIDWIDTH; + + for (i = 0; i < MAXPLAYERS; i++) + if (playeringame[i] && players[i].spectator) + { + char *pos; + char initial[MAXPLAYERNAME+1]; + char current[MAXPLAYERNAME+1]; + + strcpy(initial, player_names[i]); + pos = initial; + + if (length >= -((signed)strlen(player_names[i]) * 8 + 16) && length <= BASEVIDWIDTH) + { + if (length < 0) + { + UINT8 eatenchars = (UINT8)(abs(length) / 8 + 1); + + if (eatenchars <= strlen(initial)) + { + // Eat one letter off the left side, + // then compensate the drawing position. + pos += eatenchars; + strcpy(current, pos); + templength = length % 8 + 8; + } + else + { + strcpy(current, " "); + templength = length; + } + } + else + { + strcpy(current, initial); + templength = length; + } + + V_DrawString(templength, height + 8, V_TRANSLUCENT, current); + } + + length += (signed)strlen(player_names[i]) * 8 + 16; + } +} + +// +// HU_DrawRankings +// +static void HU_DrawRankings(void) +{ + patch_t *p; + playersort_t tab[MAXPLAYERS]; + INT32 i, j, scorelines; + boolean completed[MAXPLAYERS]; + UINT32 whiteplayer; + + // draw the current gametype in the lower right + HU_drawGametype(); + + if (G_GametypeHasTeams()) + { + if (gametype == GT_CTF) + p = bflagico; + else + p = bmatcico; + + V_DrawSmallScaledPatch(128 - SHORT(p->width)/4, 4, 0, p); + V_DrawCenteredString(128, 16, 0, va("%u", bluescore)); + + if (gametype == GT_CTF) + p = rflagico; + else + p = rmatcico; + + V_DrawSmallScaledPatch(192 - SHORT(p->width)/4, 4, 0, p); + V_DrawCenteredString(192, 16, 0, va("%u", redscore)); + } + + if (gametype != GT_RACE && gametype != GT_COMPETITION && gametype != GT_COOP) + { + if (cv_timelimit.value && timelimitintics > 0) + { + INT32 timeval = (timelimitintics+1-leveltime)/TICRATE; + + if (leveltime <= timelimitintics) + { + V_DrawCenteredString(64, 8, 0, "TIME LEFT"); + V_DrawCenteredString(64, 16, 0, va("%u", timeval)); + } + + // overtime + if ((leveltime > (timelimitintics + TICRATE/2)) && cv_overtime.value) + { + V_DrawCenteredString(64, 8, 0, "TIME LEFT"); + V_DrawCenteredString(64, 16, 0, "OVERTIME"); + } + } + + if (cv_pointlimit.value > 0) + { + V_DrawCenteredString(256, 8, 0, "POINT LIMIT"); + V_DrawCenteredString(256, 16, 0, va("%d", cv_pointlimit.value)); + } + } + else if (gametype == GT_COOP) + { + INT32 totalscore = 0; + for (i = 0; i < MAXPLAYERS; i++) + { + if (playeringame[i]) + totalscore += players[i].score; + } + + V_DrawCenteredString(256, 8, 0, "TOTAL SCORE"); + V_DrawCenteredString(256, 16, 0, va("%u", totalscore)); + } + else + { + if (circuitmap) + { + V_DrawCenteredString(64, 8, 0, "NUMBER OF LAPS"); + V_DrawCenteredString(64, 16, 0, va("%d", cv_numlaps.value)); + } + } + + // When you play, you quickly see your score because your name is displayed in white. + // When playing back a demo, you quickly see who's the view. + whiteplayer = demoplayback ? displayplayer : consoleplayer; + + scorelines = 0; + memset(completed, 0, sizeof (completed)); + memset(tab, 0, sizeof (playersort_t)*MAXPLAYERS); + + for (i = 0; i < MAXPLAYERS; i++) + { + tab[i].num = -1; + tab[i].name = 0; + + if (gametype == GT_RACE && !circuitmap) + tab[i].count = INT32_MAX; + } + + for (j = 0; j < MAXPLAYERS; j++) + { + if (!playeringame[j] || players[j].spectator) + continue; + + for (i = 0; i < MAXPLAYERS; i++) + { + if (playeringame[i] && !players[i].spectator) + { + if (gametype == GT_RACE) + { + if (circuitmap) + { + if (players[i].laps+1 >= tab[scorelines].count && completed[i] == false) + { + tab[scorelines].count = players[i].laps+1; + tab[scorelines].num = i; + tab[scorelines].color = players[i].skincolor; + tab[scorelines].name = player_names[i]; + } + } + else + { + if (players[i].realtime <= tab[scorelines].count && completed[i] == false) + { + tab[scorelines].count = players[i].realtime; + tab[scorelines].num = i; + tab[scorelines].color = players[i].skincolor; + tab[scorelines].name = player_names[i]; + } + } + } + else if (gametype == GT_COMPETITION) + { + // todo put something more fitting for the gametype here, such as current + // number of categories led + if (players[i].score >= tab[scorelines].count && completed[i] == false) + { + tab[scorelines].count = players[i].score; + tab[scorelines].num = i; + tab[scorelines].color = players[i].skincolor; + tab[scorelines].name = player_names[i]; + tab[scorelines].emeralds = players[i].powers[pw_emeralds]; + } + } + else + { + if (players[i].score >= tab[scorelines].count && completed[i] == false) + { + tab[scorelines].count = players[i].score; + tab[scorelines].num = i; + tab[scorelines].color = players[i].skincolor; + tab[scorelines].name = player_names[i]; + tab[scorelines].emeralds = players[i].powers[pw_emeralds]; + } + } + } + } + completed[tab[scorelines].num] = true; + scorelines++; + } + + if (scorelines > 20) + scorelines = 20; //dont draw past bottom of screen, show the best only + + if (G_GametypeHasTeams()) + HU_DrawTeamTabRankings(tab, whiteplayer); //separate function for Spazzo's silly request + else if (scorelines <= 9) + HU_DrawTabRankings(40, 32, tab, scorelines, whiteplayer); + else + HU_DrawDualTabRankings(32, 32, tab, scorelines, whiteplayer); + + // draw spectators in a ticker across the bottom + if (!splitscreen && G_GametypeHasSpectators()) + HU_DrawSpectatorTicker(); +} + +static void HU_DrawCoopOverlay(void) +{ + if (token +#ifdef HAVE_BLUA + && LUA_HudEnabled(hud_tokens) +#endif + ) + { + V_DrawString(168, 176, 0, va("- %d", token)); + V_DrawSmallScaledPatch(148, 172, 0, tokenicon); + } + +#ifdef HAVE_BLUA + if (LUA_HudEnabled(hud_tabemblems)) +#endif + if (!modifiedgame || savemoddata) + { + V_DrawString(160, 144, 0, va("- %d/%d", M_CountEmblems(), numemblems+numextraemblems)); + V_DrawScaledPatch(128, 144 - SHORT(emblemicon->height)/4, 0, emblemicon); + } + +#ifdef HAVE_BLUA + if (!LUA_HudEnabled(hud_coopemeralds)) + return; +#endif + + if (emeralds & EMERALD1) + V_DrawScaledPatch((BASEVIDWIDTH/2)-8 , (BASEVIDHEIGHT/3)-32, V_TRANSLUCENT, emeraldpics[0]); + if (emeralds & EMERALD2) + V_DrawScaledPatch((BASEVIDWIDTH/2)-8+24, (BASEVIDHEIGHT/3)-16, V_TRANSLUCENT, emeraldpics[1]); + if (emeralds & EMERALD3) + V_DrawScaledPatch((BASEVIDWIDTH/2)-8+24, (BASEVIDHEIGHT/3)+16, V_TRANSLUCENT, emeraldpics[2]); + if (emeralds & EMERALD4) + V_DrawScaledPatch((BASEVIDWIDTH/2)-8 , (BASEVIDHEIGHT/3)+32, V_TRANSLUCENT, emeraldpics[3]); + if (emeralds & EMERALD5) + V_DrawScaledPatch((BASEVIDWIDTH/2)-8-24, (BASEVIDHEIGHT/3)+16, V_TRANSLUCENT, emeraldpics[4]); + if (emeralds & EMERALD6) + V_DrawScaledPatch((BASEVIDWIDTH/2)-8-24, (BASEVIDHEIGHT/3)-16, V_TRANSLUCENT, emeraldpics[5]); + if (emeralds & EMERALD7) + V_DrawScaledPatch((BASEVIDWIDTH/2)-8 , (BASEVIDHEIGHT/3) , V_TRANSLUCENT, emeraldpics[6]); +} + +static void HU_DrawNetplayCoopOverlay(void) +{ + int i; + +#ifdef HAVE_BLUA + if (!LUA_HudEnabled(hud_coopemeralds)) + return; +#endif + + for (i = 0; i < 7; ++i) + { + if (emeralds & (1 << i)) + V_DrawScaledPatch(20 + (i * 20), 6, V_TRANSLUCENT, emeraldpics[i]); + } +} + + +// Interface to CECHO settings for the outside world, avoiding the +// expense (and security problems) of going via the console buffer. +void HU_ClearCEcho(void) +{ + cechotimer = 0; +} + +void HU_SetCEchoDuration(INT32 seconds) +{ + cechoduration = seconds * TICRATE; +} + +void HU_SetCEchoFlags(INT32 flags) +{ + // Don't allow cechoflags to contain any bits in V_PARAMMASK + cechoflags = (flags & ~V_PARAMMASK); +} + +void HU_DoCEcho(const char *msg) +{ + I_OutputMsg("%s\n", msg); // print to log + + strncpy(cechotext, msg, sizeof(cechotext)); + strncat(cechotext, "\\", sizeof(cechotext) - strlen(cechotext) - 1); + cechotext[sizeof(cechotext) - 1] = '\0'; + cechotimer = cechoduration; +} diff --git a/src/hu_stuff.h b/src/hu_stuff.h new file mode 100644 index 000000000..059448f10 --- /dev/null +++ b/src/hu_stuff.h @@ -0,0 +1,116 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 1993-1996 by id Software, Inc. +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Copyright (C) 1999-2014 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file hu_stuff.h +/// \brief Heads up display + +#ifndef __HU_STUFF_H__ +#define __HU_STUFF_H__ + +#include "d_event.h" +#include "w_wad.h" +#include "r_defs.h" + +//------------------------------------ +// heads up font +//------------------------------------ +#define HU_FONTSTART '\x1F' // the first font character +#define HU_FONTEND '~' + +#define HU_FONTSIZE (HU_FONTEND - HU_FONTSTART + 1) + +// Level title font +#define LT_FONTSTART '!' // the first font characters +#define LT_FONTEND 'Z' // the last font characters +#define LT_FONTSIZE (LT_FONTEND - LT_FONTSTART + 1) + +#define CRED_FONTSTART '!' // the first font character +#define CRED_FONTEND 'Z' // the last font character +#define CRED_FONTSIZE (CRED_FONTEND - CRED_FONTSTART + 1) + +#define HU_CROSSHAIRS 3 // maximum of 9 - see HU_Init(); + +extern char *shiftxform; // english translation shift table +extern char english_shiftxform[]; + +//------------------------------------ +// sorted player lines +//------------------------------------ + +typedef struct +{ + UINT32 count; + INT32 num; + INT32 color; + INT32 emeralds; + const char *name; +} playersort_t; + +//------------------------------------ +// chat stuff +//------------------------------------ +#define HU_MAXMSGLEN 224 + +extern patch_t *hu_font[HU_FONTSIZE], *tny_font[HU_FONTSIZE]; +extern patch_t *tallnum[10]; +extern patch_t *nightsnum[10]; +extern patch_t *lt_font[LT_FONTSIZE]; +extern patch_t *cred_font[CRED_FONTSIZE]; +extern patch_t *emeraldpics[7]; +extern patch_t *tinyemeraldpics[7]; +extern patch_t *rflagico; +extern patch_t *bflagico; +extern patch_t *rmatcico; +extern patch_t *bmatcico; +extern patch_t *tagico; +extern patch_t *tallminus; + +// set true when entering a chat message +extern boolean chat_on; + +// set true whenever the tab rankings are being shown for any reason +extern boolean hu_showscores; + +// P_DeathThink sets this true to show scores while dead, in multiplayer +extern boolean playerdeadview; + +// init heads up data at game startup. +void HU_Init(void); + +void HU_LoadGraphics(void); + +// reset heads up when consoleplayer respawns. +void HU_Start(void); + +boolean HU_Responder(event_t *ev); + +void HU_Ticker(void); +void HU_Drawer(void); +char HU_dequeueChatChar(void); +void HU_Erase(void); +void HU_clearChatChars(void); +void HU_DrawTabRankings(INT32 x, INT32 y, playersort_t *tab, INT32 scorelines, INT32 whiteplayer); +void HU_DrawTeamTabRankings(playersort_t *tab, INT32 whiteplayer); +void HU_DrawDualTabRankings(INT32 x, INT32 y, playersort_t *tab, INT32 scorelines, INT32 whiteplayer); +void HU_DrawEmeralds(INT32 x, INT32 y, INT32 pemeralds); + +INT32 HU_CreateTeamScoresTbl(playersort_t *tab, UINT32 dmtotals[]); + +// CECHO interface. +void HU_ClearCEcho(void); +void HU_SetCEchoDuration(INT32 seconds); +void HU_SetCEchoFlags(INT32 flags); +void HU_DoCEcho(const char *msg); + +// Demo playback info +extern UINT32 hu_demoscore; +extern UINT32 hu_demotime; +extern UINT16 hu_demorings; +#endif diff --git a/src/i_addrinfo.c b/src/i_addrinfo.c new file mode 100644 index 000000000..9055bb258 --- /dev/null +++ b/src/i_addrinfo.c @@ -0,0 +1,693 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 2011-2014 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file i_addrinfo.c +/// \brief getaddr stubs, for lesser OSes +/// +/// Some systems/SDKs, like PSL1GHT v2 does not have addrinfo functions +/// So a stub is needed +#include +#include +#include +#ifdef _WIN32 +#ifdef USE_WINSOCK2 +#include +#else +#include +#endif +#elif !defined (__DJGPP__) && !defined(_WII) +#include +#ifndef _NDS +#include +#endif +#ifdef _PS3 +#include +#elif ! defined (_arch_dreamcast) +#include +#endif +#endif + +#include "i_addrinfo.h" + +/* + * This addrinfo stub have a testcases: + * To test the stub, use this command to compile the stub testcase: + * gcc -g -DTESTCASE -Dtest_stub -Wall -W i_addrinfo.c -o stub + * To test the real getaddrinfo API, use this command to get real one: + * gcc -g -DTESTCASE -Utest_stub -Wall -W i_addrinfo.c -o real + * For Win32,you need the WinSock library, version 1.1 or 2.2 + * for 1.1, add -lwsock32 + * i686-w64-mingw32-gcc -g -DTESTCASE -Dtest_stub -UUSE_WINSOCK2 -Wall -W i_addrinfo.c -o stub.exe -lwsock32 + * for 2.2, add -DUSE_WINSOCK2 -lws2_32 + * i686-w64-mingw32-gcc -g -DTESTCASE -Utest_stub -DUSE_WINSOCK2 -Wall -W i_addrinfo.c -o real.exe -lws2_32 + */ + +#ifndef I_getaddrinfo + +#ifndef _MSC_VER +#include +#else +typedef char bool; +#endif + +#ifdef _WIN32 +// it seems windows doesn't define that... maybe some other OS? OS/2 +static int inet_aton(const char *cp, struct in_addr *addr) +{ + if( cp == NULL || addr == NULL ) + { + return(0); + } + if (strcmp(cp, "255.255.255.225") == 0) + { + addr->s_addr = htonl(INADDR_BROADCAST); + return 0; + } + return (addr->s_addr = inet_addr(cp)) != htonl(INADDR_NONE); +} +#endif + +#ifdef USE_WINSOCK2 +static HMODULE ipv6dll = NULL; +typedef int (WSAAPI *p_getaddrinfo) (const char *node, const char *service, + const struct my_addrinfo *hints, + struct my_addrinfo **res); +typedef void (WSAAPI *p_freeaddrinfo) (struct my_addrinfo *res); + +static p_getaddrinfo WS_getaddrinfo = NULL; +static p_freeaddrinfo WS_freeaddrinfo = NULL; + +static HMODULE WS_getfunctions(HMODULE tmp) +{ + if (tmp != NULL) + { + WS_getaddrinfo = (p_getaddrinfo)GetProcAddress(tmp, "getaddrinfo"); + if (WS_getaddrinfo == NULL) + return NULL; + WS_freeaddrinfo = (p_freeaddrinfo)GetProcAddress(tmp, "freeaddrinfo"); + if (WS_freeaddrinfo == NULL) + { + WS_getaddrinfo = NULL; + return NULL; + } + } + return tmp; +} + +static void WS_addrinfosetup(void) +{ + if (WS_getaddrinfo && WS_freeaddrinfo) + return; // already have the functions + // why not hold it into ipv6dll? becase we already link with ws2_32, silly! + if (WS_getfunctions(GetModuleHandleA("ws2_32.dll")) == NULL) + ipv6dll = WS_getfunctions(LoadLibrary("wship6.dll")); +} + +void WS_addrinfocleanup(void) +{ + if (ipv6dll) + FreeLibrary(ipv6dll); + ipv6dll = NULL; + WS_getaddrinfo = NULL; + WS_freeaddrinfo = NULL; +} +#else +void WS_addrinfocleanup(void) {} +#endif + +int I_getaddrinfo(const char *node, const char *service, + const struct my_addrinfo *hints, + struct my_addrinfo **res) +{ + struct hostent *nodename = NULL; + bool hostlookup = true, passivemode = false; + int flags = 0; + int socktype = 0; + int sockport = 0; + struct my_addrinfo *ai; + struct sockaddr_in *addr; + struct in_addr ipv4; + size_t addrlen = 1; + size_t ailen = 1, i = 0, j; + size_t famsize = sizeof(struct sockaddr_in); +#ifdef USE_WINSOCK2 + WS_addrinfosetup(); + if (WS_getaddrinfo) + return WS_getaddrinfo(node, service, hints, res); +#endif + + // param check + if (node == NULL && service == NULL) + return EAI_NONAME; + //note: testcase show NULL as res crashes libc + if (res == NULL) + return -1; + + // check hints + if (hints) + { + // no support for IPv6 + if (hints->ai_family != AF_INET && hints->ai_family != AF_UNSPEC) + return -1; //EAI_FAMILY +#ifdef AI_NUMERICHOST + // do not look up hostnames + if ((hints->ai_flags & AI_NUMERICHOST) == AI_NUMERICHOST) + { + hostlookup = false; + flags |= AI_NUMERICHOST; + } +#endif +#ifdef AI_PASSIVE + // return loopback or any address? + if ((hints->ai_flags & AI_PASSIVE) == AI_PASSIVE) + { + passivemode = true; + flags |= AI_PASSIVE; + } +#endif + // why no support for canon names? lazy + //AI_CANONNAME + // what kind of socket? + socktype = hints->ai_socktype; + } + else + { +#ifdef AI_V4MAPPED + flags |= AI_V4MAPPED; +#endif +#ifdef AI_ADDRCONFIG + flags |= AI_ADDRCONFIG; +#endif + } + + // we need gethostbyname to convert numeric strings + if (node && hostlookup) + { + if (node == NULL) + return -1; + nodename = gethostbyname(node); + if (nodename == NULL) + { + if (inet_aton(node, &ipv4) != 0) + addrlen = 1; + else + return -1; + } + else while (nodename->h_addr_list[addrlen] != NULL) + addrlen++; + } + else if (node) + { + if (inet_aton(node, &ipv4) != 0) + addrlen = 1; + else if (!hostlookup) + return EAI_NONAME; + } + else + addrlen = 1; + + if (service) //AI_NUMERICSERV + sockport = atoi(service); + + if (socktype == 0) + ailen = addrlen*3; + else + ailen = addrlen; + + ai = calloc(ailen, sizeof(struct my_addrinfo)); + if (ai == NULL) + return -1; + else + *res = ai; + + addr = calloc(ailen*2, famsize); + if (addr == NULL) + { + free(ai); + return -1; + } + else + ai->ai_addr = memset(addr, 0x00, ailen*ai->ai_addrlen); + + for (i = 0; i < ailen; i++) + { + ai = *res+i; + ai->ai_flags = flags; + ai->ai_family = AF_INET; + ai->ai_socktype = socktype; + switch (ai->ai_socktype) + { + case SOCK_STREAM: + ai->ai_protocol = IPPROTO_TCP; + break; + case SOCK_DGRAM: + ai->ai_protocol = IPPROTO_UDP; + break; + default: + ai->ai_protocol = 0; + } + ai->ai_addrlen = famsize; + ai->ai_addr = (struct sockaddr *)&addr[i]; + //ai_cannonname + ai->ai_next = ai+1; + } + ai->ai_next = NULL; + ai = *res; + + for (i = 0, j = 0; i < ailen; i++, j++) + { + ai = *res+i; +#ifdef _PS3 + addr[i].sin_len = famsize; +#endif + addr[i].sin_port = htons((UINT16)sockport); + if (nodename) + { + memcpy(&addr[i].sin_addr, nodename->h_addr_list[j], ai->ai_addrlen); + addr[i].sin_family = nodename->h_addrtype; + } + else if (node) + { + memcpy(&addr[i].sin_addr, &ipv4, ai->ai_addrlen); + addr[i].sin_family = AF_INET; + } + else + { + if (passivemode) + addr[i].sin_addr.s_addr = htonl(INADDR_ANY); + else + addr[i].sin_addr.s_addr = htonl(INADDR_LOOPBACK); + addr[i].sin_family = AF_INET; + } + if (socktype == 0) + { + ai->ai_socktype = SOCK_STREAM; + ai->ai_protocol = IPPROTO_TCP; + memcpy(&addr[i+1], &addr[i], ai->ai_addrlen); + i++; ai++; + ai->ai_socktype = SOCK_DGRAM; + ai->ai_protocol = IPPROTO_UDP; + memcpy(&addr[i+1], &addr[i], ai->ai_addrlen); + i++; ai++; + ai->ai_socktype = SOCK_RAW; + ai->ai_protocol = IPPROTO_IP; + } + } + return 0; +} +#endif + +#ifndef I_freeaddrinfo +void I_freeaddrinfo(struct my_addrinfo *res) +{ +#ifdef USE_WINSOCK2 + if (WS_freeaddrinfo) + { + WS_freeaddrinfo(res); + return; + } +#endif + if (!res) + return; + free(res->ai_addr); + free(res); +} +#endif + +#ifdef TESTCASE +#include + +#ifdef USE_WINSOCK2 +#define inet_ntop inet_ntopA +#define HAVE_NTOP +static const char* inet_ntopA(int af, const void *cp, char *buf, socklen_t len) +{ + DWORD Dlen = len, AFlen = 0; + SOCKADDR_STORAGE any; + LPSOCKADDR anyp = (LPSOCKADDR)&any; + LPSOCKADDR_IN any4 = (LPSOCKADDR_IN)&any; + LPSOCKADDR_IN6 any6 = (LPSOCKADDR_IN6)&any; + + if (!buf) + { + WSASetLastError(STATUS_INVALID_PARAMETER); + return NULL; + } + + if (af != AF_INET && af != AF_INET6) + { + WSASetLastError(WSAEAFNOSUPPORT); + return NULL; + } + + ZeroMemory(&any, sizeof(SOCKADDR_STORAGE)); + any.ss_family = af; + + switch (af) + { + case AF_INET: + { + CopyMemory(&any4->sin_addr, cp, sizeof(IN_ADDR)); + AFlen = sizeof(SOCKADDR_IN); + break; + } + case AF_INET6: + { + CopyMemory(&any6->sin6_addr, cp, sizeof(IN6_ADDR)); + AFlen = sizeof(SOCKADDR_IN6); + break; + } + } + + if (WSAAddressToStringA(anyp, AFlen, NULL, buf, &Dlen) == SOCKET_ERROR) + return NULL; + return buf; +} +#elif defined (_WIN32) +// w32api, ws2tcpip.h, r1.12 +static inline char* gai_strerror(int ecode) +{ + static char message[1024+1]; + DWORD dwFlags = FORMAT_MESSAGE_FROM_SYSTEM + | FORMAT_MESSAGE_IGNORE_INSERTS + | FORMAT_MESSAGE_MAX_WIDTH_MASK; + DWORD dwLanguageId = MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT); + FormatMessageA(dwFlags, NULL, ecode, dwLanguageId, message, 1024, NULL); + return message; +} +#else +#define HAVE_NTOP +#endif + +#ifndef INET_ADDRSTRLEN +#define INET_ADDRSTRLEN 16 +#endif + +static inline void printflags(int ai_flags) +{ + printf("flags: %x(", ai_flags); + if (ai_flags == 0) + printf("NONE|"); +#ifdef AI_PASSIVE + if ((ai_flags & AI_PASSIVE) == AI_PASSIVE) + printf("AI_PASSIVE|"); + ai_flags &= ~AI_PASSIVE; +#endif +#ifdef AI_CANONNAME + if ((ai_flags & AI_CANONNAME) == AI_CANONNAME) + printf("AI_CANONNAME|"); + ai_flags &= ~AI_CANONNAME; +#endif +#ifdef AI_NUMERICHOST + if ((ai_flags & AI_NUMERICHOST) == AI_NUMERICHOST) + printf("AI_NUMERICHOST|"); + ai_flags &= ~AI_NUMERICHOST; +#endif +#ifdef AI_V4MAPPED + if ((ai_flags & AI_V4MAPPED) == AI_V4MAPPED) + printf("AI_V4MAPPED|"); + ai_flags &= ~AI_V4MAPPED; +#endif +#ifdef AI_ALL + if ((ai_flags & AI_ALL) == AI_ALL) + printf("AI_ALL|"); + ai_flags &= ~AI_ALL; +#endif +#ifdef AI_ADDRCONFIG + if ((ai_flags & AI_ADDRCONFIG) == AI_ADDRCONFIG) + printf("AI_ADDRCONFIG|"); + ai_flags &= ~AI_ADDRCONFIG; +#endif +#ifdef AI_IDN + if ((ai_flags & AI_IDN) == AI_IDN) + printf("AI_IDN|"); + ai_flags &= ~AI_IDN; +#endif +#ifdef AI_CANONIDN + if ((ai_flags & AI_CANONIDN) == AI_CANONIDN) + printf("AI_CANONIDN|"); + ai_flags &= ~AI_CANONIDN; +#endif +#ifdef AI_IDN_ALLOW_UNASSIGNED + if ((ai_flags & AI_IDN_ALLOW_UNASSIGNED) == AI_IDN_ALLOW_UNASSIGNED) + printf("AI_IDN_ALLOW_UNASSIGNED|"); + ai_flags &= ~AI_IDN_ALLOW_UNASSIGNED; +#endif +#ifdef AI_IDN_USE_STD3_ASCII_RULES + if ((ai_flags & AI_IDN_USE_STD3_ASCII_RULES) == AI_IDN_USE_STD3_ASCII_RULES) + printf("AI_IDN_USE_STD3_ASCII_RULES|"); + ai_flags &= ~AI_PASSIVE; +#endif +#ifdef AI_NUMERICSERV + if ((ai_flags & AI_NUMERICSERV) == AI_NUMERICSERV) + printf("AI_NUMERICSERV|"); + ai_flags &= ~AI_NUMERICSERV; +#endif + printf("%x", ai_flags); + printf(")\n"); +} + +static inline void printsocktype(int ai_socktype) +{ + printf("socktype: %d(", ai_socktype); + switch (ai_socktype) + { + case 0: + printf("SOCK_ Woe32"); + break; + case SOCK_STREAM: + printf("SOCK_STREAM"); + break; + case SOCK_DGRAM: + printf("SOCK_DGRAM"); + break; + case SOCK_RAW: + printf("SOCK_RAW"); + break; + default: + printf("SOCK_ERROR\n"); + exit(-1); + } + printf(")\n"); +} + +static inline void printprotocol(int ai_protocol) +{ + printf("protocol: %d(", ai_protocol); + switch (ai_protocol) + { + case IPPROTO_IP: + printf("IPPROTO_IP"); + break; + case IPPROTO_TCP: + printf("IPPROTO_TCP"); + break; + case IPPROTO_UDP: + printf("IPPROTO_UDP"); + break; + default: + printf("IPPROTO_ERROR\n"); + exit(-1); + } + printf(")\n"); +} + +static inline void printaddr(int ai_family, const struct sockaddr *ai_addr) +{ + char str[INET_ADDRSTRLEN+1] = "FAKE"; + printf("family: %d(", ai_family); + switch (ai_family) + { + case AF_UNSPEC: + printf("AF_UNSPEC"); + break; + case AF_INET: + printf("AF_INET"); + break; +#ifdef AF_INET6 + case AF_INET6: + printf("AF_INET6"); + break; +#endif + default: + printf("AF_ERROR\n"); + exit(-1); + } + printf(")\n"); + if (ai_family == AF_INET && ai_addr) + { + const struct sockaddr_in *ip4 = (void *)ai_addr; +#ifdef HAVE_NTOP + inet_ntop(ai_family, &ip4->sin_addr, str, INET_ADDRSTRLEN); +#else + strncpy(str, inet_ntoa(ip4->sin_addr), INET_ADDRSTRLEN); +#endif + printf("port: %d\n", ntohs(ip4->sin_port)); + } + printf("addr: %s\n", str); +} + +void printaddrinfo(const struct my_addrinfo *data) +{ + if(data == NULL) + { + printf("no data\n"); + return; + } + else + printf("starting addrinfo dump\n"); + while (data != NULL) + { + printflags(data->ai_flags); + printsocktype(data->ai_socktype); + printaddr(data->ai_family, data->ai_addr); + printprotocol(data->ai_protocol); + //addrlen + data = data->ai_next; + } +} + +int main(int argc, char **argv) +{ + struct my_addrinfo *res = NULL, hints; + int gaie; + + (void)argc; + (void)argv; + memset(&hints, 0x00, sizeof(struct my_addrinfo)); + hints.ai_family = AF_INET; + +#ifdef _WIN32 + { +#ifdef USE_WINSOCK2 + const WORD VerNeed = MAKEWORD(2,2); +#else + const WORD VerNeed = MAKEWORD(1,1); +#endif + WSADATA WSAData; + WSAStartup(VerNeed, &WSAData); + } +#endif + printf("-----------------------------------------------------------\n"); +#ifndef _WIN32 //NULL as res crashes Win32 + gaie = I_getaddrinfo(NULL, NULL, &hints, NULL); + if (gaie != EAI_NONAME) + printf("NULLs test returned: %s(%d)\n", gai_strerror(gaie), gaie); + I_freeaddrinfo(res); +#endif +#if 0 //NULL as res crashes + gaie = I_getaddrinfo("localhost", "5029", NULL, NULL); + if (gaie == 0) + printf("NULL crashes: %s(%d)\n", gai_strerror(gaie), gaie); + I_freeaddrinfo(res); +#endif + gaie = I_getaddrinfo("localhost", NULL, &hints, &res); + //if (gaie != 0) + printf("NULL service test returned: %s(%d)\n", gai_strerror(gaie), gaie); + printaddrinfo(res); + I_freeaddrinfo(res); res = NULL; + gaie = I_getaddrinfo(NULL, "5029", &hints, &res); + //if (gaie != 0) + printf("NULLs test returned: %s(%d)\n", gai_strerror(gaie), gaie); + printaddrinfo(res); + I_freeaddrinfo(res); res = NULL; + gaie = I_getaddrinfo("localhost", "5029", &hints, &res); + //if (gaie != 0) + printf("no hints test returned: %s(%d)\n", gai_strerror(gaie), gaie); + printaddrinfo(res); + I_freeaddrinfo(res); res = NULL; + printf("-----------------------------------------------------------\n"); + hints.ai_socktype = SOCK_STREAM; + hints.ai_protocol = IPPROTO_TCP; + gaie = I_getaddrinfo("localhost", NULL, &hints, &res); + //if (gaie != 0) + printf("NULL service test returned: %s(%d)\n", gai_strerror(gaie), gaie); + printaddrinfo(res); + I_freeaddrinfo(res); res = NULL; + gaie = I_getaddrinfo(NULL, "5029", &hints, &res); + //if (gaie != 0) + printf("NULLs test returned: %s(%d)\n", gai_strerror(gaie), gaie); + printaddrinfo(res); + I_freeaddrinfo(res); res = NULL; + gaie = I_getaddrinfo("localhost", "5029", &hints, &res); + //if (gaie != 0) + printf("no hints test returned: %s(%d)\n", gai_strerror(gaie), gaie); + printaddrinfo(res); + I_freeaddrinfo(res); res = NULL; + printf("-----------------------------------------------------------\n"); + hints.ai_socktype = SOCK_DGRAM; + hints.ai_protocol = IPPROTO_UDP; + gaie = I_getaddrinfo("localhost", NULL, &hints, &res); + //if (gaie != 0) + printf("NULL service test returned: %s(%d)\n", gai_strerror(gaie), gaie); + printaddrinfo(res); + I_freeaddrinfo(res); res = NULL; + gaie = I_getaddrinfo(NULL, "5029", &hints, &res); + //if (gaie != 0) + printf("NULLs test returned: %s(%d)\n", gai_strerror(gaie), gaie); + printaddrinfo(res); + I_freeaddrinfo(res); res = NULL; + gaie = I_getaddrinfo("localhost", "5029", &hints, &res); + //if (gaie != 0) + printf("no hints test returned: %s(%d)\n", gai_strerror(gaie), gaie); + printaddrinfo(res); + I_freeaddrinfo(res); res = NULL; + printf("-----------------------------------------------------------\n"); + hints.ai_flags = AI_NUMERICHOST; + gaie = I_getaddrinfo("localhost", NULL, &hints, &res); + //if (gaie != 0) + printf("NULL service test returned: %s(%d)\n", gai_strerror(gaie), gaie); + printaddrinfo(res); + I_freeaddrinfo(res); res = NULL; + gaie = I_getaddrinfo(NULL, "5029", &hints, &res); + //if (gaie != 0) + printf("NULLs test returned: %s(%d)\n", gai_strerror(gaie), gaie); + printaddrinfo(res); + I_freeaddrinfo(res); res = NULL; + gaie = I_getaddrinfo("localhost", "5029", &hints, &res); + //if (gaie != 0) + printf("no hints test returned: %s(%d)\n", gai_strerror(gaie), gaie); + printaddrinfo(res); + I_freeaddrinfo(res); res = NULL; + printf("-----------------------------------------------------------\n"); + gaie = I_getaddrinfo("127.0.0.1", NULL, &hints, &res); + //if (gaie != 0) + printf("NULL service test returned: %s(%d)\n", gai_strerror(gaie), gaie); + printaddrinfo(res); + I_freeaddrinfo(res); res = NULL; + gaie = I_getaddrinfo("127.0.0.1", "5029", &hints, &res); + //if (gaie != 0) + printf("no hints test returned: %s(%d)\n", gai_strerror(gaie), gaie); + printaddrinfo(res); + I_freeaddrinfo(res); res = NULL; + printf("-----------------------------------------------------------\n"); + gaie = I_getaddrinfo("255.255.255.255", NULL, &hints, &res); + //if (gaie != 0) + printf("NULL service test returned: %s(%d)\n", gai_strerror(gaie), gaie); + printaddrinfo(res); + I_freeaddrinfo(res); res = NULL; + gaie = I_getaddrinfo("255.255.255.255", "5029", &hints, &res); + //if (gaie != 0) + printf("no hints test returned: %s(%d)\n", gai_strerror(gaie), gaie); + printaddrinfo(res); + I_freeaddrinfo(res); res = NULL; + printf("-----------------------------------------------------------\n"); + hints.ai_flags = AI_PASSIVE; + gaie = I_getaddrinfo("0.0.0.0", NULL, &hints, &res); + //if (gaie != 0) + printf("NULL service test returned: %s(%d)\n", gai_strerror(gaie), gaie); + printaddrinfo(res); + I_freeaddrinfo(res); res = NULL; + gaie = I_getaddrinfo("0.0.0.0", "5029", &hints, &res); + //if (gaie != 0) + printf("no hints test returned: %s(%d)\n", gai_strerror(gaie), gaie); + printaddrinfo(res); + I_freeaddrinfo(res); res = NULL; + return 0; +} +#endif diff --git a/src/i_addrinfo.h b/src/i_addrinfo.h new file mode 100644 index 000000000..bdd76867a --- /dev/null +++ b/src/i_addrinfo.h @@ -0,0 +1,81 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 2011-2014 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file i_addrinfo.h +/// \brief getaddrinfo stub + +#ifndef __I_ADDRINFO__ +#define __I_ADDRINFO__ + +#ifdef __GNUG__ +#pragma interface +#endif + +#ifndef AI_PASSIVE +#define AI_PASSIVE 0x01 +#endif +#ifndef AI_NUMERICHOST +#define AI_NUMERICHOST 0x04 +#endif +#ifndef AI_V4MAPPED +#define AI_V4MAPPED 0x08 +#endif +#ifndef AI_ADDRCONFIG +#define AI_ADDRCONFIG 0x20 +#endif + +#ifdef _WIN32 +#ifndef EAI_NONAME +#define EAI_NONAME WSAHOST_NOT_FOUND +#endif +#endif + +#ifndef EAI_NONAME +#define EAI_NONAME -2 +#endif + +#ifdef _PS3 // PSL1GHT v2 +struct my_addrinfo { + int ai_flags; + int ai_family; + int ai_socktype; + int ai_protocol; + size_t ai_addrlen; + struct sockaddr *ai_addr; + struct my_addrinfo *ai_next; +}; +#elif defined (_WIN32) // already use the stub for Win32 +// w32api, ws2tcpip.h, r1.12 +struct my_addrinfo { + int ai_flags; + int ai_family; + int ai_socktype; + int ai_protocol; + size_t ai_addrlen; + char *ai_canonname; + struct sockaddr *ai_addr; + struct my_addrinfo *ai_next; +}; +#else +#define my_addrinfo addrinfo +#endif + +void WS_addrinfocleanup(void); + +#ifndef my_addrinfo +void I_freeaddrinfo(struct my_addrinfo *res); +int I_getaddrinfo(const char *node, const char *service, + const struct my_addrinfo *hints, + struct my_addrinfo **res); +#elif !defined (test_stub) +#define I_getaddrinfo getaddrinfo +#define I_freeaddrinfo freeaddrinfo +#endif + + +#endif diff --git a/src/i_joy.h b/src/i_joy.h new file mode 100644 index 000000000..c539cb419 --- /dev/null +++ b/src/i_joy.h @@ -0,0 +1,58 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Copyright (C) 1999-2014 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file i_joy.h +/// \brief share joystick information with game control code + +#ifndef __I_JOY_H__ +#define __I_JOY_H__ + +#include "g_input.h" + +/*! + \brief -JOYAXISRANGE to +JOYAXISRANGE for each axis + + (1024-1) so we can do a right shift instead of division + (doesnt matter anyway, just give enough precision) + a gamepad will return -1, 0, or 1 in the event data + an analog type joystick will return a value + from -JOYAXISRANGE to +JOYAXISRANGE for each axis +*/ + +#define JOYAXISRANGE 1023 + +// detect a bug if we increase JOYBUTTONS above DIJOYSTATE's number of buttons +#if (JOYBUTTONS > 64) +"JOYBUTTONS is greater than INT64 bits can hold" +#endif + +/** \brief The struct JoyType_s + + share some joystick information (maybe 2 for splitscreen), to the game input code, + actually, we need to know if it is a gamepad or analog controls +*/ + +struct JoyType_s +{ + /*! if true, we MUST Poll() to get new joystick data, + that is: we NEED the DIRECTINPUTDEVICE2 ! (watchout NT compatibility) */ + INT32 bJoyNeedPoll; + /*! this joystick is a gamepad, read: digital axes + if FALSE, interpret the joystick event data as JOYAXISRANGE (see above) */ + INT32 bGamepadStyle; + +}; +typedef struct JoyType_s JoyType_t; +/** \brief Joystick info + for palyer 1 and 2's joystick/gamepad +*/ + +extern JoyType_t Joystick, Joystick2; + +#endif // __I_JOY_H__ diff --git a/src/i_net.h b/src/i_net.h new file mode 100644 index 000000000..ecf6202de --- /dev/null +++ b/src/i_net.h @@ -0,0 +1,155 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 1993-1996 by id Software, Inc. +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Copyright (C) 1999-2014 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file i_net.h +/// \brief System specific network interface stuff. + +#ifndef __I_NET__ +#define __I_NET__ + +#ifdef __GNUG__ +#pragma interface +#endif + +#include "doomdef.h" +#include "command.h" + +/// \brief program net id +#define DOOMCOM_ID (INT32)0x12345678l + +/// \def MAXPACKETLENGTH +/// For use in a LAN +#define MAXPACKETLENGTH 1450 +/// \def INETPACKETLENGTH +/// For use on the internet +#define INETPACKETLENGTH 1024 + +extern INT16 hardware_MAXPACKETLENGTH; +extern INT32 net_bandwidth; // in byte/s + +#if defined(_MSC_VER) +#pragma pack(1) +#endif + +typedef struct +{ + /// Supposed to be DOOMCOM_ID + INT32 id; + + /// SRB2 executes an INT32 to execute commands. + INT16 intnum; + /// Communication between SRB2 and the driver. + /// Is CMD_SEND or CMD_GET. + INT16 command; + /// Is dest for send, set by get (-1 = no packet). + INT16 remotenode; + + /// Number of bytes in doomdata to be sent + INT16 datalength; + + /// Info common to all nodes. + /// Console is always node 0. + INT16 numnodes; + /// Flag: 1 = no duplication, 2-5 = dup for slow nets. + INT16 ticdup; + /// Flag: 1 = send a backup tic in every packet. + INT16 extratics; + /// kind of game + INT16 gametype; + /// Flag: -1 = new game, 0-5 = load savegame + INT16 savegame; + /// currect map + INT16 map; + + /// Info specific to this node. + INT16 consoleplayer; + /// Number of "slots": the highest player number in use plus one. + INT16 numslots; + + /// The packet data to be sent. + char data[MAXPACKETLENGTH]; +} ATTRPACK doomcom_t; + +#if defined(_MSC_VER) +#pragma pack() +#endif + +extern doomcom_t *doomcom; + +/** \brief return packet in doomcom struct +*/ +extern void (*I_NetGet)(void); + +/** \brief ask to driver if there is data waiting +*/ +extern boolean (*I_NetCanGet)(void); + +/** \brief send packet within doomcom struct +*/ +extern void (*I_NetSend)(void); + +/** \brief ask to driver if all is ok to send data now +*/ +extern boolean (*I_NetCanSend)(void); + +/** \brief close a connection + + \param nodenum node to be closed + + \return void + + +*/ +extern void (*I_NetFreeNodenum)(INT32 nodenum); + +/** \brief open a connection with specified address + + \param address address to connect to + + \return number of node + + +*/ +extern SINT8 I_NetMakeNode(const char *address); + +/** \brief open a connection with specified address and port + + \param address address to connect to + + \param port port to connect to + + \return number of node + + +*/ +extern SINT8 (*I_NetMakeNodewPort)(const char *address, const char *port); + +/** \brief open connection +*/ +extern boolean (*I_NetOpenSocket)(void); + +/** \brief close all connections no more allow geting any packet +*/ +extern void (*I_NetCloseSocket)(void); + + +extern boolean (*I_Ban) (INT32 node); +extern boolean (*I_Shun) (INT32 node); +extern void (*I_ClearBans)(void); +extern const char *(*I_GetNodeAddress) (INT32 node); +extern const char *(*I_GetBanAddress) (size_t ban); +extern const char *(*I_GetBanMask) (size_t ban); +extern boolean (*I_SetBanAddress) (const char *address,const char *mask); +extern boolean *bannednode; + +/// \brief Called by D_SRB2Main to be defined by extern network driver +boolean I_InitNetwork(void); + +#endif diff --git a/src/i_sound.h b/src/i_sound.h new file mode 100644 index 000000000..b3811df8f --- /dev/null +++ b/src/i_sound.h @@ -0,0 +1,282 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 1993-1996 by id Software, Inc. +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Copyright (C) 1999-2014 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file i_sound.h +/// \brief System interface, sound, music and CD + +#ifndef __I_SOUND__ +#define __I_SOUND__ + +#include "doomdef.h" +#include "sounds.h" +#include "command.h" + +/** \brief Sound subsystem runing and waiting +*/ +extern UINT8 sound_started; + +/** \brief info of samplerate +*/ +extern consvar_t cv_samplerate; +//extern consvar_t cv_rndsoundpitch; + +/** \brief The I_GetSfx function + + \param sfx sfx to setup + + \return data for sfx +*/ +void *I_GetSfx(sfxinfo_t *sfx); + +/** \brief The I_FreeSfx function + + \param sfx sfx to be freed up + + \return void +*/ +void I_FreeSfx(sfxinfo_t *sfx); + +/** \brief Init at program start... +*/ +void I_StartupSound(void); + +/** \brief ... shut down and relase at program termination. +*/ +void I_ShutdownSound(void); + +// +// SFX I/O +// + +/** \brief Starts a sound in a particular sound channel. + \param id sfxid + \param vol volume for sound + \param sep left-right balancle + \param pitch not used + \param priority not used + + \return sfx handle +*/ +INT32 I_StartSound(sfxenum_t id, UINT8 vol, UINT8 sep, UINT8 pitch, UINT8 priority); + +/** \brief Stops a sound channel. + + \param handle stop sfx handle + + \return void +*/ +void I_StopSound(INT32 handle); + +/** \brief Some digital sound drivers need this. +*/ +void I_UpdateSound(void); + +/** \brief Called by S_*() functions to see if a channel is still playing. + + \param handle sfx handle + + \return 0 if no longer playing, 1 if playing. +*/ +boolean I_SoundIsPlaying(INT32 handle); + +/** \brief Updates the sfx handle + + \param handle sfx handle + \param vol volume + \param sep separation + \param pitch ptich + + \return void +*/ +void I_UpdateSoundParams(INT32 handle, UINT8 vol, UINT8 sep, UINT8 pitch); + +/** \brief The I_SetSfxVolume function + + \param volume volume to set at + + \return void +*/ +void I_SetSfxVolume(UINT8 volume); + +// +// MUSIC I/O +// +/** \brief Init the music systems +*/ +void I_InitMusic(void); + +/** \brief Shutdown the music systems +*/ +void I_ShutdownMusic(void); + +/** \brief PAUSE game handling. + + \param handle song handle + + \return void +*/ +void I_PauseSong(INT32 handle); + +/** \brief RESUME game handling + + \param handle song handle + + \return void +*/ +void I_ResumeSong(INT32 handle); + +// +// MIDI I/O +// + +/** \brief Startup the MIDI music system +*/ +void I_InitMIDIMusic(void); + +/** \brief Shutdown the MIDI music system +*/ +void I_ShutdownMIDIMusic(void); + +/** \brief The I_SetMIDIMusicVolume function + + \param volume volume to set at + + \return void +*/ +void I_SetMIDIMusicVolume(UINT8 volume); + +/** \brief Registers a song handle to song data. + + \param data pointer to song data + \param len len of data + + \return song handle + + \todo Remove this +*/ +INT32 I_RegisterSong(void *data, size_t len); + +/** \brief Called by anything that wishes to start music + + \param handle Song handle + \param looping looping it if true + + \return if true, it's playing the song + + \todo pass music name, not handle +*/ +boolean I_PlaySong(INT32 handle, boolean looping); + +/** \brief Stops a song over 3 seconds + + \param handle Song handle + \return void + + /todo drop handle +*/ +void I_StopSong(INT32 handle); + +/** \brief See ::I_RegisterSong, then think backwards + + \param handle song handle + + \sa I_RegisterSong + \todo remove midi handle +*/ +void I_UnRegisterSong(INT32 handle); + +// +// DIGMUSIC I/O +// + +/** \brief Startup the music system +*/ +void I_InitDigMusic(void); + +/** \brief Shutdown the music system +*/ +void I_ShutdownDigMusic(void); + +boolean I_SetSongSpeed(float speed); + +boolean I_SetSongTrack(INT32 track); + +/** \brief The I_StartDigSong function + + \param musicname music lump name + \param looping if true, loop the song + + \return if true, song playing +*/ +boolean I_StartDigSong(const char *musicname, boolean looping); + +/** \brief stop non-MIDI song +*/ +void I_StopDigSong(void); + +/** \brief The I_SetDigMusicVolume function + + \param volume volume to set at + + \return void +*/ +void I_SetDigMusicVolume(UINT8 volume); + +// +// CD MUSIC I/O +// + + +/** \brief cd music interface +*/ +extern UINT8 cdaudio_started; + +/** \brief Startup the CD system +*/ +void I_InitCD(void); + +/** \brief Stop the CD playback +*/ +void I_StopCD(void); + +/** \brief Pause the CD playback +*/ +void I_PauseCD(void); + +/** \brief Resume the CD playback +*/ +void I_ResumeCD(void); + +/** \brief Shutdown the CD system +*/ +void I_ShutdownCD(void); + +/** \brief Update the CD info +*/ +void I_UpdateCD(void); + +/** \brief The I_PlayCD function + + \param track CD track number + \param looping if true, loop the track + + \return void +*/ +void I_PlayCD(UINT8 track, UINT8 looping); + +/** \brief The I_SetVolumeCD function + + \param volume volume level to set at + + \return return 0 on failure +*/ +boolean I_SetVolumeCD(INT32 volume); + +#endif diff --git a/src/i_system.h b/src/i_system.h new file mode 100644 index 000000000..74c1b08bd --- /dev/null +++ b/src/i_system.h @@ -0,0 +1,301 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 1993-1996 by id Software, Inc. +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Copyright (C) 1999-2014 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file i_system.h +/// \brief System specific interface stuff. + +#ifndef __I_SYSTEM__ +#define __I_SYSTEM__ + +#include "d_ticcmd.h" +#include "d_event.h" + +#ifdef __GNUG__ +#pragma interface +#endif + +/** \brief max quit functions +*/ +#define MAX_QUIT_FUNCS 16 + + +/** \brief Graphic system had started up +*/ +extern UINT8 graphics_started; + +/** \brief Keyboard system is up and run +*/ +extern UINT8 keyboard_started; + +/** \brief The I_GetFreeMem function + + \param total total memory in the system + + \return free memory in the system +*/ +UINT32 I_GetFreeMem(UINT32 *total); + +/** \brief Called by D_SRB2Loop, returns current time in tics. +*/ +tic_t I_GetTime(void); + +/** \brief The I_Sleep function + + \return void +*/ +void I_Sleep(void); + +/** \brief Get events + + Called by D_SRB2Loop, + called before processing each tic in a frame. + Quick syncronous operations are performed here. + Can call D_PostEvent. +*/ +void I_GetEvent(void); + +/** \brief Asynchronous interrupt functions should maintain private queues + that are read by the synchronous functions + to be converted into events. +*/ +void I_OsPolling(void); + +// Either returns a null ticcmd, +// or calls a loadable driver to build it. +// This ticcmd will then be modified by the gameloop +// for normal input. + +/** \brief Input for the first player +*/ +ticcmd_t *I_BaseTiccmd(void); + +/** \brief Input for the sencond player +*/ +ticcmd_t *I_BaseTiccmd2(void); + +/** \brief Called by M_Responder when quit is selected, return exit code 0 +*/ +void I_Quit(void) FUNCNORETURN; + +typedef enum +{ + EvilForce = -1, + //Constant + ConstantForce = 0, + //Ramp + RampForce, + //Periodics + SquareForce, + SineForce, + TriangleForce, + SawtoothUpForce, + SawtoothDownForce, + //MAX + NumberofForces, +} FFType; + +typedef struct JoyFF_s +{ + INT32 ForceX; ///< The X of the Force's Vel + INT32 ForceY; ///< The Y of the Force's Vel + //All + UINT32 Duration; ///< The total duration of the effect, in microseconds + INT32 Gain; //< /The gain to be applied to the effect, in the range from 0 through 10,000. + //All, CONSTANTFORCE -10,000 to 10,000 + INT32 Magnitude; ///< Magnitude of the effect, in the range from 0 through 10,000. + //RAMPFORCE + INT32 Start; ///< Magnitude at the start of the effect, in the range from -10,000 through 10,000. + INT32 End; ///< Magnitude at the end of the effect, in the range from -10,000 through 10,000. + //PERIODIC + INT32 Offset; ///< Offset of the effect. + UINT32 Phase; ///< Position in the cycle of the periodic effect at which playback begins, in the range from 0 through 35,999 + UINT32 Period; ///< Period of the effect, in microseconds. +} JoyFF_t; + +/** \brief Forcefeedback for the first joystick + + \param Type what kind of Effect + \param Effect Effect Info + + \return void +*/ + +void I_Tactile(FFType Type, const JoyFF_t *Effect); + +/** \brief Forcefeedback for the second joystick + + \param Type what kind of Effect + \param Effect Effect Info + + \return void +*/ +void I_Tactile2(FFType Type, const JoyFF_t *Effect); + +/** \brief to set up the first joystick scale +*/ +void I_JoyScale(void); + +/** \brief to set up the second joystick scale +*/ +void I_JoyScale2(void); + +// Called by D_SRB2Main. + +/** \brief to startup the first joystick +*/ +void I_InitJoystick(void); + +/** \brief to startup the second joystick +*/ +void I_InitJoystick2(void); + +/** \brief return the number of joystick on the system +*/ +INT32 I_NumJoys(void); + +/** \brief The *I_GetJoyName function + + \param joyindex which joystick + + \return joystick name +*/ +const char *I_GetJoyName(INT32 joyindex); + +#ifndef NOMUMBLE +#include "p_mobj.h" // mobj_t +#include "s_sound.h" // listener_t +/** \brief to update Mumble of Player Postion +*/ +void I_UpdateMumble(const mobj_t *mobj, const listener_t listener); +#endif + +/** \brief Startup the first mouse +*/ +void I_StartupMouse(void); + +/** \brief Startup the second mouse +*/ +void I_StartupMouse2(void); + +/** \brief keyboard startup, shutdown, handler +*/ +void I_StartupKeyboard(void); + +/** \brief setup timer irq and user timer routine. +*/ +void I_StartupTimer(void); + +/** \brief sample quit function +*/ +typedef void (*quitfuncptr)(); + +/** \brief add a list of functions to call at program cleanup + + \param (*func)() funcction to call at program cleanup + + \return void +*/ +void I_AddExitFunc(void (*func)()); + +/** \brief The I_RemoveExitFunc function + + \param (*func)() function to remove from the list + + \return void +*/ +void I_RemoveExitFunc(void (*func)()); + +/** \brief Setup signal handler, plus stuff for trapping errors and cleanly exit. +*/ +INT32 I_StartupSystem(void); + +/** \brief Shutdown systems +*/ +void I_ShutdownSystem(void); + +/** \brief The I_GetDiskFreeSpace function + + \param freespace a INT64 pointer to hold the free space amount + + \return void +*/ +void I_GetDiskFreeSpace(INT64 *freespace); + +/** \brief find out the user's name +*/ +char *I_GetUserName(void); + +/** \brief The I_mkdir function + + \param dirname string of mkidr + \param unixright unix right + + \return status of new folder +*/ +INT32 I_mkdir(const char *dirname, INT32 unixright); + +typedef struct { + int FPU : 1; ///< FPU availabile + int CPUID : 1; ///< CPUID instruction + int RDTSC : 1; ///< RDTSC instruction + int MMX : 1; ///< MMX features + int MMXExt : 1; ///< MMX Ext. features + int CMOV : 1; ///< Pentium Pro's "cmov" + int AMD3DNow : 1; ///< 3DNow features + int AMD3DNowExt: 1; ///< 3DNow! Ext. features + int SSE : 1; ///< SSE features + int SSE2 : 1; ///< SSE2 features + int SSE3 : 1; ///< SSE3 features + int IA64 : 1; ///< Running on IA64 + int AMD64 : 1; ///< Running on AMD64 + int AltiVec : 1; ///< AltiVec features + int FPPE : 1; ///< floating-point precision error + int PFC : 1; ///< TBD? + int cmpxchg : 1; ///< ? + int cmpxchg16b : 1; ///< ? + int cmp8xchg16 : 1; ///< ? + int FPE : 1; ///< FPU Emu + int DEP : 1; ///< Data excution prevent + int PPCMM64 : 1; ///< PowerPC Movemem 64bit ok? + int ALPHAbyte : 1; ///< ? + int PAE : 1; ///< Physical Address Extension + int CPUs : 8; +} CPUInfoFlags; + + +/** \brief Info about CPU + \return CPUInfo in bits +*/ +const CPUInfoFlags *I_CPUInfo(void); + +/** \brief Find main WAD + \return path to main WAD +*/ +const char *I_LocateWad(void); + +/** \brief First Joystick's events +*/ +void I_GetJoystickEvents(void); + +/** \brief Second Joystick's events +*/ +void I_GetJoystick2Events(void); + +/** \brief Mouses events +*/ +void I_GetMouseEvents(void); + +char *I_GetEnv(const char *name); + +INT32 I_PutEnv(char *variable); + +void I_RegisterSysCommands(void); + +#endif diff --git a/src/i_tcp.c b/src/i_tcp.c new file mode 100644 index 000000000..2127f1fc0 --- /dev/null +++ b/src/i_tcp.c @@ -0,0 +1,1525 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Copyright (C) 1999-2014 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file i_tcp.c +/// \brief TCP driver, socket code. +/// This is not really OS-dependent because all OSes have the same socket API. +/// Just use ifdef for OS-dependent parts. + +#include +#include +#include +#ifdef __GNUC__ +#include +#endif +#ifdef __OS2__ +#include +#include +#endif // __OS2__ + +#ifdef _PS3 +#define NO_IPV6 // PSL1GHT v2 do not have IPv6 support +#endif + +#ifndef NO_IPV6 +#define HAVE_IPV6 +#endif + +#if defined (_WIN32) || defined (_WIN32_WCE) +#define USE_WINSOCK +#if defined (_WIN64) || defined (HAVE_IPV6) +#define USE_WINSOCK2 +#else //_WIN64/HAVE_IPV6 +#define USE_WINSOCK1 +#endif +#endif //WIN32 OS + +#ifdef _XBOX // XBox have on WinSock API? +#undef USE_WINSOCK +#undef USE_WINSOCK1 +#undef USE_WINSOCK2 +#endif + +#ifdef USE_WINSOCK2 +#include +#endif + +#include "doomdef.h" + +#if defined (NOMD5) && !defined (NONET) +//#define NONET +#endif + +#ifndef NONET +#ifdef USE_WINSOCK1 +#include +#elif !defined (SCOUW2) && !defined (SCOUW7) && !defined (__OS2__) +#ifdef HAVE_LWIP +#include +#elif !defined (USE_WINSOCK) +#include +#endif //normal BSD API + +#ifdef HAVE_LWIP +#include +#define ioctl lwip_ioctl +#elif !defined (USE_WINSOCK) //!HAVE_LWIP +#ifdef __APPLE_CC__ +#ifndef _BSD_SOCKLEN_T_ +#define _BSD_SOCKLEN_T_ +#endif //_BSD_SOCKLEN_T_ +#endif //__APPLE_CC__ +#include +#include +#endif //normal BSD API + +#if defined(_arch_dreamcast) && !defined(HAVE_LWIP) +#include +#elif defined(HAVE_LWIP) +#include +#elif defined (_PS3) +#include +#include +#elif !defined(USE_WINSOCK) //!HAVE_LWIP +#include +#include +#endif //normal BSD API + +#include +#include + +#ifdef _arch_dreamcast +#include "sdl/SRB2DC/dchelp.h" +#endif + +#if (defined (__unix__) && !defined (MSDOS)) || defined(__APPLE__) || defined (UNIXCOMMON) + #include +#endif // UNIXCOMMON +#endif // !NONET + +#ifdef USE_WINSOCK + // some undefined under win32 + #undef errno + //#define errno WSAGetLastError() //Alam_GBC: this is the correct way, right? + #define errno h_errno // some very strange things happen when not using h_error?!? + #ifdef EWOULDBLOCK + #undef EWOULDBLOCK + #endif + #define EWOULDBLOCK WSAEWOULDBLOCK + #ifdef EMSGSIZE + #undef EMSGSIZE + #endif + #define EMSGSIZE WSAEMSGSIZE + #ifdef ECONNREFUSED + #undef ECONNREFUSED + #endif + #define ECONNREFUSED WSAECONNREFUSED + #ifdef ETIMEDOUT + #undef ETIMEDOUT + #endif + #define ETIMEDOUT WSAETIMEDOUT + #ifndef IOC_VENDOR + #define IOC_VENDOR 0x18000000 + #endif + #ifndef _WSAIOW + #define _WSAIOW(x,y) (IOC_IN|(x)|(y)) + #endif + #ifndef SIO_UDP_CONNRESET + #define SIO_UDP_CONNRESET _WSAIOW(IOC_VENDOR,12) + #endif + #ifndef AI_ADDRCONFIG + #define AI_ADDRCONFIG 0x00000400 + #endif + #ifndef STATUS_INVALID_PARAMETER + #define STATUS_INVALID_PARAMETER 0xC000000D + #endif +#endif + +#ifdef __DJGPP__ +#ifdef WATTCP // Alam_GBC: Wattcp may need this +#include +#define strerror strerror_s +#else // wattcp +#include +#endif // libsocket +#endif // djgpp + +typedef union +{ + struct sockaddr any; + struct sockaddr_in ip4; +#ifdef HAVE_IPV6 + struct sockaddr_in6 ip6; +#endif +} mysockaddr_t; + +#ifdef HAVE_MINIUPNPC +#ifdef STATIC_MINIUPNPC +#define STATICLIB +#endif +#include "miniupnpc/miniwget.h" +#include "miniupnpc/miniupnpc.h" +#include "miniupnpc/upnpcommands.h" +#undef STATICLIB +static UINT8 UPNP_support = TRUE; +#endif + +#endif // !NONET + +#define MAXBANS 100 + +#include "i_system.h" +#include "i_net.h" +#include "d_net.h" +#include "i_tcp.h" +#include "m_argv.h" + +#include "doomstat.h" + +// win32 or djgpp +#if defined (USE_WINSOCK) || defined (__DJGPP__) + // winsock stuff (in winsock a socket is not a file) + #define ioctl ioctlsocket + #define close closesocket + + #ifdef _WIN32_WCE + #include "sdl/SRB2CE/cehelp.h" + #endif + +#endif + +#include "i_addrinfo.h" + +#ifdef __DJGPP__ + +#ifdef WATTCP +#define SELECTTEST +#endif + +#elif defined(HAVE_LWIP) +#define SELECTTEST +#elif !defined( _arch_dreamcast) +#define SELECTTEST +#endif + +#define DEFAULTPORT "5029" + +#if defined (USE_WINSOCK) && !defined (NONET) +typedef SOCKET SOCKET_TYPE; +#define BADSOCKET INVALID_SOCKET +#define ERRSOCKET (SOCKET_ERROR) +#else +#if (defined (__unix__) && !defined (MSDOS)) || defined (__APPLE__) || defined (__HAIKU__) || defined(_PS3) +typedef int SOCKET_TYPE; +#else +typedef unsigned long SOCKET_TYPE; +#endif +#define BADSOCKET (SOCKET_TYPE)(~0) +#define ERRSOCKET (-1) +#endif + +#if (defined (WATTCP) && !defined (__libsocket_socklen_t)) || defined (USE_WINSOCK1) +typedef int socklen_t; +#endif + +#ifndef NONET +static SOCKET_TYPE mysockets[MAXNETNODES+1] = {BADSOCKET}; +static size_t mysocketses = 0; +static int myfamily[MAXNETNODES+1] = {0}; +static SOCKET_TYPE nodesocket[MAXNETNODES+1] = {BADSOCKET}; +static mysockaddr_t clientaddress[MAXNETNODES+1]; +static mysockaddr_t broadcastaddress[MAXNETNODES+1]; +static size_t broadcastaddresses = 0; +static boolean nodeconnected[MAXNETNODES+1]; +static mysockaddr_t banned[MAXBANS]; +static UINT8 bannedmask[MAXBANS]; +static mysockaddr_t shunned[MAXBANS]; +static UINT8 shunnedmask[MAXBANS]; +static size_t numshun = 0; +#endif + +static size_t numbans = 0; +static boolean SOCK_bannednode[MAXNETNODES+1]; /// \note do we really need the +1? +static boolean init_tcp_driver = false; + +static char port_name[8] = DEFAULTPORT; + +#ifndef NONET + +#ifdef WATTCP +static void wattcp_outch(char s) +{ + static char old = '\0'; + char pr[2] = {s,0}; + if (s == old && old == ' ') return; + else old = s; + if (s == '\r') CONS_Printf("\n"); + else if (s != '\n') CONS_Printf(pr); +} +#endif + +#ifdef USE_WINSOCK2 +#define inet_ntop inet_ntopA +#define HAVE_NTOP +static const char* inet_ntopA(short af, const void *cp, char *buf, socklen_t len) +{ + DWORD Dlen = len, AFlen = 0; + SOCKADDR_STORAGE any; + LPSOCKADDR anyp = (LPSOCKADDR)&any; + LPSOCKADDR_IN any4 = (LPSOCKADDR_IN)&any; + LPSOCKADDR_IN6 any6 = (LPSOCKADDR_IN6)&any; + + if (!buf) + { + WSASetLastError(STATUS_INVALID_PARAMETER); + return NULL; + } + + if (af != AF_INET && af != AF_INET6) + { + WSASetLastError(WSAEAFNOSUPPORT); + return NULL; + } + + ZeroMemory(&any, sizeof(SOCKADDR_STORAGE)); + any.ss_family = af; + + switch (af) + { + case AF_INET: + { + CopyMemory(&any4->sin_addr, cp, sizeof(IN_ADDR)); + AFlen = sizeof(SOCKADDR_IN); + break; + } + case AF_INET6: + { + CopyMemory(&any6->sin6_addr, cp, sizeof(IN6_ADDR)); + AFlen = sizeof(SOCKADDR_IN6); + break; + } + } + + if (WSAAddressToStringA(anyp, AFlen, NULL, buf, &Dlen) == SOCKET_ERROR) + return NULL; + return buf; +} +#elif !defined (USE_WINSOCK1) +#define HAVE_NTOP +#endif + +#ifdef HAVE_MINIUPNPC // based on old XChat patch +static struct UPNPUrls urls; +static struct IGDdatas data; +static char lanaddr[64]; + +static void I_ShutdownUPnP(void) +{ + FreeUPNPUrls(&urls); +} + +static inline void I_InitUPnP(void) +{ + struct UPNPDev * devlist = NULL; + int upnp_error = -2; + CONS_Printf(M_GetText("Looking for UPnP Internet Gateway Device\n")); + devlist = upnpDiscover(2000, NULL, NULL, 0, false, &upnp_error); + if (devlist) + { + struct UPNPDev *dev = devlist; + char * descXML; + int descXMLsize = 0; + while (dev) + { + if (strstr (dev->st, "InternetGatewayDevice")) + break; + dev = dev->pNext; + } + if (!dev) + dev = devlist; /* defaulting to first device */ + + CONS_Printf(M_GetText("Found UPnP device:\n desc: %s\n st: %s\n"), + dev->descURL, dev->st); + + UPNP_GetValidIGD(devlist, &urls, &data, lanaddr, sizeof(lanaddr)); + CONS_Printf(M_GetText("Local LAN IP address: %s\n"), lanaddr); + descXML = miniwget(dev->descURL, &descXMLsize); + if (descXML) + { + parserootdesc(descXML, descXMLsize, &data); + free(descXML); + descXML = NULL; + memset(&urls, 0, sizeof(struct UPNPUrls)); + memset(&data, 0, sizeof(struct IGDdatas)); + GetUPNPUrls(&urls, &data, dev->descURL); + I_AddExitFunc(I_ShutdownUPnP); + } + freeUPNPDevlist(devlist); + } + else if (upnp_error == UPNPDISCOVER_SOCKET_ERROR) + { + CONS_Printf(M_GetText("No UPnP devices discovered\n")); + } +} + +static inline void I_UPnP_add(const char * addr, const char *port, const char * servicetype) +{ + if (addr == NULL) + addr = lanaddr; + if (!urls.controlURL || urls.controlURL[0] == '\0') + return; + UPNP_AddPortMapping(urls.controlURL, data.first.servicetype, + port, port, addr, "SRB2", servicetype, NULL, NULL); +} + +static inline void I_UPnP_rem(const char *port, const char * servicetype) +{ + if (!urls.controlURL || urls.controlURL[0] == '\0') + return; + UPNP_DeletePortMapping(urls.controlURL, data.first.servicetype, + port, servicetype, NULL); +} +#endif + +static const char *SOCK_AddrToStr(mysockaddr_t *sk) +{ + static char s[64]; // 255.255.255.255:65535 or IPv6:65535 +#ifdef HAVE_NTOP + void *addr; + + if(sk->any.sa_family == AF_INET) + addr = &sk->ip4.sin_addr; +#ifdef HAVE_IPV6 + else if(sk->any.sa_family == AF_INET6) + addr = &sk->ip6.sin6_addr; +#endif + else + addr = NULL; + + if(addr == NULL) + sprintf(s, "No address"); + else if(inet_ntop(sk->any.sa_family, addr, s, sizeof (s)) == NULL) + sprintf(s, "Unknown family type, error #%u", errno); +#ifdef HAVE_IPV6 + else if(sk->any.sa_family == AF_INET6 && sk->ip6.sin6_port != 0) + strcat(s, va(":%d", ntohs(sk->ip6.sin6_port))); +#endif + else if(sk->any.sa_family == AF_INET && sk->ip4.sin_port != 0) + strcat(s, va(":%d", ntohs(sk->ip4.sin_port))); +#else + if (sk->any.sa_family == AF_INET) + { + strcpy(s, inet_ntoa(sk->ip4.sin_addr)); + if (sk->ip4.sin_port != 0) strcat(s, va(":%d", ntohs(sk->ip4.sin_port))); + } + else + sprintf(s, "Unknown type"); +#endif + return s; +} +#endif + +static const char *SOCK_GetNodeAddress(INT32 node) +{ + if (node == 0) + return "self"; +#ifdef NONET + return NULL; +#else + if (!nodeconnected[node]) + return NULL; + return SOCK_AddrToStr(&clientaddress[node]); +#endif +} + +static const char *SOCK_GetBanAddress(size_t ban) +{ + if (ban >= numbans) + return NULL; +#ifdef NONET + return NULL; +#else + return SOCK_AddrToStr(&banned[ban]); +#endif +} + +static const char *SOCK_GetBanMask(size_t ban) +{ +#ifdef NONET + (void)ban; +#else + static char s[16]; //255.255.255.255 netmask? no, just CDIR for only + if (ban >= numbans) + return NULL; + if (sprintf(s,"%d",bannedmask[ban]) > 0) + return s; +#endif + return NULL; +} + +#ifndef NONET +static boolean SOCK_cmpaddr(mysockaddr_t *a, mysockaddr_t *b, UINT8 mask) +{ + UINT32 bitmask = INADDR_NONE; + + if (mask && mask < 32) + bitmask = htonl(-1 << (32 - mask)); + + if (b->any.sa_family == AF_INET) + return (a->ip4.sin_addr.s_addr & bitmask) == (b->ip4.sin_addr.s_addr & bitmask) + && (b->ip4.sin_port == 0 || (a->ip4.sin_port == b->ip4.sin_port)); +#ifdef HAVE_IPV6 + else if (b->any.sa_family == AF_INET6) + return memcmp(&a->ip6.sin6_addr, &b->ip6.sin6_addr, sizeof(b->ip6.sin6_addr)) + && (b->ip6.sin6_port == 0 || (a->ip6.sin6_port == b->ip6.sin6_port)); +#endif + else + return false; +} + +static SINT8 getfreenode(void) +{ + SINT8 j; + + for (j = 0; j < MAXNETNODES; j++) + if (!nodeconnected[j]) + { + nodeconnected[j] = true; + return j; + } + return -1; +} + +// This is a hack. For some reason, nodes aren't being freed properly. +// This goes through and cleans up what nodes were supposed to be freed. +static void cleanupnodes(void) +{ + SINT8 j; + + if (!Playing()) + return; + + // Why can't I start at zero? + for (j = 1; j < MAXNETNODES; j++) + if (!nodeingame[j]) + nodeconnected[j] = false; +} +#endif + +#ifndef NONET +static void SOCK_Get(void) +{ + size_t i, n; + int j; + ssize_t c; + mysockaddr_t fromaddress; + socklen_t fromlen; + + for (n = 0; n < mysocketses; n++) + { + fromlen = (socklen_t)sizeof(fromaddress); + c = recvfrom(mysockets[n], (char *)&doomcom->data, MAXPACKETLENGTH, 0, + (void *)&fromaddress, &fromlen); + if (c != ERRSOCKET) + { + // check if it's a DoS attacker and don't respond. + for (i = 0; i < numshun; i++) + if (SOCK_cmpaddr(&fromaddress, &shunned[i], shunnedmask[i])) + break; + if (i < numshun) + continue; + // find remote node number + for (j = 0; j <= MAXNETNODES; j++) //include LAN + { + if (SOCK_cmpaddr(&fromaddress, &clientaddress[j], 0)) + { + doomcom->remotenode = (INT16)j; // good packet from a game player + doomcom->datalength = (INT16)c; + nodesocket[j] = mysockets[n]; + return; + } + } + // not found + + // find a free slot + cleanupnodes(); + j = getfreenode(); + if (j > 0) + { + M_Memcpy(&clientaddress[j], &fromaddress, fromlen); + nodesocket[j] = mysockets[n]; + DEBFILE(va("New node detected: node:%d address:%s\n", j, + SOCK_GetNodeAddress(j))); + doomcom->remotenode = (INT16)j; // good packet from a game player + doomcom->datalength = (INT16)c; + + // check if it's a banned dude so we can send a refusal later + for (i = 0; i < numbans; i++) + { + if (SOCK_cmpaddr(&fromaddress, &banned[i], bannedmask[i])) + { + SOCK_bannednode[j] = true; + DEBFILE("This dude has been banned\n"); + break; + } + } + if (i == numbans) + SOCK_bannednode[j] = false; + return; + } + else + DEBFILE("New node detected: No more free slots\n"); + + } + } + doomcom->remotenode = -1; // no packet +} +#endif + +// check if we can send (do not go over the buffer) +#ifndef NONET + +static fd_set masterset; + +#ifdef SELECTTEST +static boolean FD_CPY(fd_set *src, fd_set *dst, SOCKET_TYPE *fd, size_t len) +{ + size_t i; + boolean testset = false; + FD_ZERO(dst); + for (i = 0; i < len;i++) + { + if(fd[i] != BADSOCKET && fd[i] != (SOCKET_TYPE)ERRSOCKET && + FD_ISSET(fd[i], src) && !FD_ISSET(fd[i], dst)) // no checking for dups + { + FD_SET(fd[i], dst); + testset = true; + } + } + return testset; +} + +static boolean SOCK_CanSend(void) +{ + struct timeval timeval_for_select = {0, 0}; + fd_set tset; + int wselect; + + if(!FD_CPY(&masterset, &tset, mysockets, mysocketses)) + return false; + wselect = select(255, NULL, &tset, NULL, &timeval_for_select); + if (wselect >= 1) + return true; + return false; +} + +static boolean SOCK_CanGet(void) +{ + struct timeval timeval_for_select = {0, 0}; + fd_set tset; + int rselect; + + if(!FD_CPY(&masterset, &tset, mysockets, mysocketses)) + return false; + rselect = select(255, &tset, NULL, NULL, &timeval_for_select); + if (rselect >= 1) + return true; + return false; +} +#endif +#endif + +#ifndef NONET +static void SOCK_Send(void) +{ + ssize_t c = ERRSOCKET; + socklen_t d4 = (socklen_t)sizeof(struct sockaddr_in); +#ifdef HAVE_IPV6 + socklen_t d6 = (socklen_t)sizeof(struct sockaddr_in6); +#endif + socklen_t d, da = (socklen_t)sizeof(mysockaddr_t); + size_t i, j; + + if (!nodeconnected[doomcom->remotenode]) + return; + + if (doomcom->remotenode == BROADCASTADDR) + { + for (i = 0; i < mysocketses; i++) + { + for (j = 0; j < broadcastaddresses; j++) + { + if (myfamily[i] == broadcastaddress[j].any.sa_family) + { + if (broadcastaddress[i].any.sa_family == AF_INET) + d = d4; +#ifdef HAVE_IPV6 + if (broadcastaddress[i].any.sa_family == AF_INET6) + d = d6; +#endif + else + d = da; + + c = sendto(mysockets[i], (char *)&doomcom->data, doomcom->datalength, 0, + &broadcastaddress[j].any, d); + } + } + } + return; + } + else if (nodesocket[doomcom->remotenode] == BADSOCKET) + { + for (i = 0; i < mysocketses; i++) + { + if (myfamily[i] == clientaddress[doomcom->remotenode].any.sa_family) + { + if (clientaddress[doomcom->remotenode].any.sa_family == AF_INET) + d = d4; +#ifdef HAVE_IPV6 + else if (clientaddress[doomcom->remotenode].any.sa_family == AF_INET6) + d = d6; +#endif + else + d = da; + + sendto(mysockets[i], (char *)&doomcom->data, doomcom->datalength, 0, + &clientaddress[doomcom->remotenode].any, d); + } + } + return; + } + else + { + if (clientaddress[doomcom->remotenode].any.sa_family == AF_INET) + d = d4; +#ifdef HAVE_IPV6 + if (clientaddress[doomcom->remotenode].any.sa_family == AF_INET6) + d = d6; +#endif + else + d = da; + + c = sendto(nodesocket[doomcom->remotenode], (char *)&doomcom->data, doomcom->datalength, 0, + &clientaddress[doomcom->remotenode].any, d); + } + + if (c == ERRSOCKET && errno != ECONNREFUSED && errno != EWOULDBLOCK) + I_Error("SOCK_Send, error sending to node %d (%s) #%u: %s", doomcom->remotenode, + SOCK_GetNodeAddress(doomcom->remotenode), errno, strerror(errno)); +} +#endif + +#ifndef NONET +static void SOCK_FreeNodenum(INT32 numnode) +{ + // can't disconnect from self :) + if (!numnode || numnode > MAXNETNODES) + return; + + DEBFILE(va("Free node %d (%s)\n", numnode, SOCK_GetNodeAddress(numnode))); + + nodeconnected[numnode] = false; + nodesocket[numnode] = BADSOCKET; + + // put invalid address + memset(&clientaddress[numnode], 0, sizeof (clientaddress[numnode])); +} +#endif + +// +// UDPsocket +// +#ifndef NONET + +// allocate a socket +static SOCKET_TYPE UDP_Bind(int family, struct sockaddr *addr, socklen_t addrlen) +{ + SOCKET_TYPE s = socket(family, SOCK_DGRAM, IPPROTO_UDP); + int opt; + socklen_t opts; +#ifdef FIONBIO +#ifdef WATTCP + char trueval = true; +#else + unsigned long trueval = true; +#endif +#endif + mysockaddr_t straddr; + + if (s == (SOCKET_TYPE)ERRSOCKET || s == BADSOCKET) + return (SOCKET_TYPE)ERRSOCKET; +#ifdef USE_WINSOCK + { // Alam_GBC: disable the new UDP connection reset behavior for Win2k and up +#ifdef USE_WINSOCK2 + DWORD dwBytesReturned = 0; + BOOL bfalse = FALSE; + WSAIoctl(s, SIO_UDP_CONNRESET, &bfalse, sizeof(bfalse), + NULL, 0, &dwBytesReturned, NULL, NULL); +#else + unsigned long falseval = false; + ioctl(s, SIO_UDP_CONNRESET, &falseval); +#endif + } +#endif + + straddr.any = *addr; + I_OutputMsg("Binding to %s\n", SOCK_AddrToStr(&straddr)); + + if (family == AF_INET) + { + mysockaddr_t tmpaddr; + tmpaddr.any = *addr ; + if (tmpaddr.ip4.sin_addr.s_addr == htonl(INADDR_ANY)) + { + opt = true; + opts = (socklen_t)sizeof(opt); + setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *)&opt, opts); + } + // make it broadcastable + opt = true; + opts = (socklen_t)sizeof(opt); + if (setsockopt(s, SOL_SOCKET, SO_BROADCAST, (char *)&opt, opts)) + { + CONS_Alert(CONS_WARNING, M_GetText("Could not get broadcast rights\n")); // I do not care anymore + } + } +#ifdef HAVE_IPV6 + else if (family == AF_INET6) + { + if (memcmp(addr, &in6addr_any, sizeof(in6addr_any)) == 0) //IN6_ARE_ADDR_EQUAL + { + opt = true; + opts = (socklen_t)sizeof(opt); + setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *)&opt, opts); + } +#ifdef IPV6_V6ONLY + // make it IPv6 ony + opt = true; + opts = (socklen_t)sizeof(opt); + if (setsockopt(s, SOL_SOCKET, IPV6_V6ONLY, (char *)&opt, opts)) + { + CONS_Alert(CONS_WARNING, M_GetText("Could not limit IPv6 bind\n")); // I do not care anymore + } +#endif + } +#endif + + if (bind(s, addr, addrlen) == ERRSOCKET) + { + close(s); + I_OutputMsg("Binding failed\n"); + return (SOCKET_TYPE)ERRSOCKET; + } + +#ifdef FIONBIO + // make it non blocking + opt = true; + if (ioctl(s, FIONBIO, &trueval) != 0) + { + close(s); + I_OutputMsg("Seting FIOBIO on failed\n"); + return (SOCKET_TYPE)ERRSOCKET; + } +#endif + + opts = (socklen_t)sizeof(opt); + getsockopt(s, SOL_SOCKET, SO_RCVBUF, (char *)&opt, &opts); + CONS_Printf(M_GetText("Network system buffer: %dKb\n"), opt>>10); + + if (opt < 64<<10) // 64k + { + opt = 64<<10; + opts = (socklen_t)sizeof(opt); + setsockopt(s, SOL_SOCKET, SO_RCVBUF, (char *)&opt, opts); + getsockopt(s, SOL_SOCKET, SO_RCVBUF, (char *)&opt, &opts); + if (opt < 64<<10) + CONS_Alert(CONS_WARNING, M_GetText("Can't set buffer length to 64k, file transfer will be bad\n")); + else + CONS_Printf(M_GetText("Network system buffer set to: %dKb\n"), opt>>10); + } + + return s; +} + +static boolean UDP_Socket(void) +{ + const char *sock_port = NULL; + size_t s; + struct my_addrinfo *ai, *runp, hints; + int gaie; +#ifdef HAVE_IPV6 + const INT32 b_ipv6 = M_CheckParm("-ipv6"); +#endif + + + for (s = 0; s < mysocketses; s++) + mysockets[s] = BADSOCKET; + for (s = 0; s < MAXNETNODES+1; s++) + nodesocket[s] = BADSOCKET; + FD_ZERO(&masterset); + s = 0; + + memset(&hints, 0x00, sizeof (hints)); + hints.ai_flags = AI_NUMERICHOST; + hints.ai_family = AF_INET; + hints.ai_socktype = SOCK_DGRAM; + hints.ai_protocol = IPPROTO_UDP; + + if (M_CheckParm("-clientport")) + { + if (!M_IsNextParm()) + I_Error("syntax: -clientport "); + sock_port = M_GetNextParm(); + } + else + sock_port = port_name; + + if (M_CheckParm("-bindaddr")) + { + while (M_IsNextParm()) + { + gaie = I_getaddrinfo(M_GetNextParm(), sock_port, &hints, &ai); + if (gaie == 0) + { + runp = ai; + while (runp != NULL && s < MAXNETNODES+1) + { + mysockets[s] = UDP_Bind(runp->ai_family, runp->ai_addr, (socklen_t)runp->ai_addrlen); + if (mysockets[s] != (SOCKET_TYPE)ERRSOCKET) + { + FD_SET(mysockets[s], &masterset); + myfamily[s] = hints.ai_family; + s++; + } + runp = runp->ai_next; + } + I_freeaddrinfo(ai); + } + } + } + else + { + gaie = I_getaddrinfo("0.0.0.0", sock_port, &hints, &ai); + if (gaie == 0) + { + runp = ai; + while (runp != NULL && s < MAXNETNODES+1) + { + mysockets[s] = UDP_Bind(runp->ai_family, runp->ai_addr, (socklen_t)runp->ai_addrlen); + if (mysockets[s] != (SOCKET_TYPE)ERRSOCKET) + { + FD_SET(mysockets[s], &masterset); + myfamily[s] = hints.ai_family; + s++; +#ifdef HAVE_MINIUPNPC + if (UPNP_support) + { + I_UPnP_rem(sock_port, "UDP"); + I_UPnP_add(NULL, sock_port, "UDP"); + } +#endif + } + runp = runp->ai_next; + } + I_freeaddrinfo(ai); + } + } +#ifdef HAVE_IPV6 + if (b_ipv6) + { + hints.ai_family = AF_INET6; + if (M_CheckParm("-bindaddr6")) + { + while (M_IsNextParm()) + { + gaie = I_getaddrinfo(M_GetNextParm(), sock_port, &hints, &ai); + if (gaie == 0) + { + runp = ai; + while (runp != NULL && s < MAXNETNODES+1) + { + mysockets[s] = UDP_Bind(runp->ai_family, runp->ai_addr, (socklen_t)runp->ai_addrlen); + if (mysockets[s] != (SOCKET_TYPE)ERRSOCKET) + { + FD_SET(mysockets[s], &masterset); + myfamily[s] = hints.ai_family; + s++; + } + runp = runp->ai_next; + } + I_freeaddrinfo(ai); + } + } + } + else + { + gaie = I_getaddrinfo("::", sock_port, &hints, &ai); + if (gaie == 0) + { + runp = ai; + while (runp != NULL && s < MAXNETNODES+1) + { + mysockets[s] = UDP_Bind(runp->ai_family, runp->ai_addr, (socklen_t)runp->ai_addrlen); + if (mysockets[s] != (SOCKET_TYPE)ERRSOCKET) + { + FD_SET(mysockets[s], &masterset); + myfamily[s] = hints.ai_family; + s++; + } + runp = runp->ai_next; + } + I_freeaddrinfo(ai); + } + } + } +#endif + + mysocketses = s; + if (s == 0) // no sockets? + return false; + + s = 0; + + // ip + udp + packetheaderlength = 20 + 8; // for stats + + hints.ai_family = AF_INET; + gaie = I_getaddrinfo("127.0.0.1", "0", &hints, &ai); + if (gaie == 0) + { + runp = ai; + while (runp != NULL) + { + memcpy(&clientaddress[s], runp->ai_addr, runp->ai_addrlen); + s++; + runp = runp->ai_next; + } + I_freeaddrinfo(ai); + } + else + { + clientaddress[s].any.sa_family = AF_INET; + clientaddress[s].ip4.sin_port = htons(0); + clientaddress[s].ip4.sin_addr.s_addr = htonl(INADDR_LOOPBACK); //GetLocalAddress(); // my own ip + s++; + } + // setup broadcast adress to BROADCASTADDR entry + gaie = I_getaddrinfo("255.255.255.255", "0", &hints, &ai); + if (gaie == 0) + { + runp = ai; + while (runp != NULL) + { + memcpy(&broadcastaddress[s], runp->ai_addr, runp->ai_addrlen); + s++; + runp = runp->ai_next; + } + I_freeaddrinfo(ai); + } + else + { + broadcastaddress[s].any.sa_family = AF_INET; + broadcastaddress[s].ip4.sin_port = htons(0); + broadcastaddress[s].ip4.sin_addr.s_addr = htonl(INADDR_BROADCAST); + s++; + } +#ifdef HAVE_IPV6 + if (b_ipv6) + { + hints.ai_family = AF_INET6; + gaie = I_getaddrinfo("ff02::1", "0", &hints, &ai); + if (gaie == 0) + { + runp = ai; + while (runp != NULL) + { + memcpy(&broadcastaddress[s], runp->ai_addr, runp->ai_addrlen); + s++; + runp = runp->ai_next; + } + I_freeaddrinfo(ai); + } + } +#endif + + broadcastaddresses = s; + + doomcom->extratics = 1; // internet is very high ping + + return true; +} +#endif + +boolean I_InitTcpDriver(void) +{ + boolean tcp_was_up = init_tcp_driver; +#ifndef NONET + if (!init_tcp_driver) + { +#ifdef USE_WINSOCK +#ifdef USE_WINSOCK2 + const WORD VerNeed = MAKEWORD(2,2); +#else + const WORD VerNeed = MAKEWORD(1,1); +#endif + WSADATA WSAData; + const int WSAresult = WSAStartup(VerNeed, &WSAData); + if (WSAresult != 0) + { + LPCSTR WSError = NULL; + switch (WSAresult) + { + case WSASYSNOTREADY: + WSError = "The underlying network subsystem is not ready for network communication"; + break; + case WSAEINPROGRESS: + WSError = "A blocking Windows Sockets 1.1 operation is in progress"; + break; + case WSAEPROCLIM: + WSError = "Limit on the number of tasks supported by the Windows Sockets implementation has been reached"; + break; + case WSAEFAULT: + WSError = "WSAData is not a valid pointer? What kind of setup do you have?"; + break; + default: + WSError = va("Error code %u",WSAresult); + break; + } + if (WSAresult != WSAVERNOTSUPPORTED) + CONS_Debug(DBG_NETPLAY, "WinSock(TCP/IP) error: %s\n",WSError); + } +#ifdef USE_WINSOCK2 + if(LOBYTE(WSAData.wVersion) != 2 || + HIBYTE(WSAData.wVersion) != 2) + { + WSACleanup(); + CONS_Debug(DBG_NETPLAY, "No WinSock(TCP/IP) 2.2 driver detected\n"); + } +#else + if (LOBYTE(WSAData.wVersion) != 1 || + HIBYTE(WSAData.wVersion) != 1) + { + WSACleanup(); + CONS_Debug(DBG_NETPLAY, "No WinSock(TCP/IP) 1.1 driver detected\n"); + } +#endif + CONS_Debug(DBG_NETPLAY, "WinSock description: %s\n",WSAData.szDescription); + CONS_Debug(DBG_NETPLAY, "WinSock System Status: %s\n",WSAData.szSystemStatus); +#endif +#ifdef HAVE_LWIP + lwip_kos_init(); +#elif defined(_arch_dreamcast) + //return; + net_init(); +#endif +#ifdef __DJGPP__ +#ifdef WATTCP // Alam_GBC: survive bootp, dhcp, rarp and wattcp/pktdrv from failing to load + survive_eth = 1; // would be needed to not exit if pkt_eth_init() fails + survive_bootp = 1; // ditto for BOOTP + survive_dhcp = 1; // ditto for DHCP/RARP + survive_rarp = 1; + //_watt_do_exit = false; + //_watt_handle_cbreak = false; + //_watt_no_config = true; + _outch = wattcp_outch; + init_misc(); +//#ifdef DEBUGFILE + dbug_init(); +//#endif + switch (sock_init()) + { + case 0: + init_tcp_driver = true; + break; + case 3: + CONS_Debug(DBG_NETPLAY, "No packet driver detected\n"); + break; + case 4: + CONS_Debug(DBG_NETPLAY, "Error while talking to packet driver\n"); + break; + case 5: + CONS_Debug(DBG_NETPLAY, "BOOTP failed\n"); + break; + case 6: + CONS_Debug(DBG_NETPLAY, "DHCP failed\n"); + break; + case 7: + CONS_Debug(DBG_NETPLAY, "RARP failed\n"); + break; + case 8: + CONS_Debug(DBG_NETPLAY, "TCP/IP failed\n"); + break; + case 9: + CONS_Debug(DBG_NETPLAY, "PPPoE login/discovery failed\n"); + break; + default: + CONS_Debug(DBG_NETPLAY, "Unknown error with TCP/IP stack\n"); + break; + } + hires_timer(0); +#else // wattcp + if (__lsck_init()) + init_tcp_driver = true; + else + CONS_Debug(DBG_NETPLAY, "No TCP/IP driver detected\n"); +#endif // libsocket +#endif // __DJGPP__ +#ifdef _PS3 + netInitialize(); +#endif +#ifndef __DJGPP__ + init_tcp_driver = true; +#endif + } +#endif + if (!tcp_was_up && init_tcp_driver) + { + I_AddExitFunc(I_ShutdownTcpDriver); +#ifdef HAVE_MINIUPNPC + if (M_CheckParm("-useUPnP")) + I_InitUPnP(); + else + UPNP_support = false; +#endif + } + return init_tcp_driver; +} + +#ifndef NONET +static void SOCK_CloseSocket(void) +{ + size_t i; + for (i=0; i < MAXNETNODES+1; i++) + { + if (mysockets[i] != (SOCKET_TYPE)ERRSOCKET + && mysockets[i] != BADSOCKET + && FD_ISSET(mysockets[i], &masterset)) + { +#if !defined (__DJGPP__) || defined (WATTCP) + FD_CLR(mysockets[i], &masterset); + close(mysockets[i]); +#endif + } + mysockets[i] = BADSOCKET; + } +} +#endif + +void I_ShutdownTcpDriver(void) +{ +#ifndef NONET + SOCK_CloseSocket(); + + CONS_Printf("I_ShutdownTcpDriver: "); +#ifdef USE_WINSOCK + WS_addrinfocleanup(); + WSACleanup(); +#endif +#ifdef HAVE_LWIP + lwip_kos_shutdown(); +#elif defined(_arch_dreamcast) + net_shutdown(); +#endif +#ifdef __DJGPP__ +#ifdef WATTCP // wattcp + //_outch = NULL; + sock_exit(); +#else + __lsck_uninit(); +#endif // libsocket +#endif // __DJGPP__ +#ifdef _PS3 + netDeinitialize(); +#endif + CONS_Printf("shut down\n"); + init_tcp_driver = false; +#endif +} + +#ifndef NONET +static SINT8 SOCK_NetMakeNodewPort(const char *address, const char *port) +{ + SINT8 newnode = -1; + struct my_addrinfo *ai, *runp, hints; + int gaie; + + if (!port || !port[0]) + port = port_name; + + DEBFILE(va("Creating new node: %s@%s\n", address, port)); + + memset (&hints, 0x00, sizeof (hints)); + hints.ai_flags = 0; + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_DGRAM; + hints.ai_protocol = IPPROTO_UDP; + + gaie = I_getaddrinfo(address, port, &hints, &ai); + if (gaie == 0) + { + cleanupnodes(); + newnode = getfreenode(); + } + if (newnode == -1) + { + I_freeaddrinfo(ai); + return -1; + } + else + runp = ai; + + while (runp != NULL) + { + // find ip of the server + memcpy(&clientaddress[newnode], runp->ai_addr, runp->ai_addrlen); + runp = NULL; + } + I_freeaddrinfo(ai); + return newnode; +} +#endif + +static boolean SOCK_OpenSocket(void) +{ +#ifndef NONET + size_t i; + + memset(clientaddress, 0, sizeof (clientaddress)); + + nodeconnected[0] = true; // always connected to self + for (i = 1; i < MAXNETNODES; i++) + nodeconnected[i] = false; + nodeconnected[BROADCASTADDR] = true; + I_NetSend = SOCK_Send; + I_NetGet = SOCK_Get; + I_NetCloseSocket = SOCK_CloseSocket; + I_NetFreeNodenum = SOCK_FreeNodenum; + I_NetMakeNodewPort = SOCK_NetMakeNodewPort; + +#ifdef SELECTTEST + // seem like not work with libsocket : ( + I_NetCanSend = SOCK_CanSend; + I_NetCanGet = SOCK_CanGet; +#endif + + // build the socket but close it first + SOCK_CloseSocket(); + return UDP_Socket(); +#else + return false; +#endif +} + +static boolean SOCK_Ban(INT32 node) +{ + if (node > MAXNETNODES) + return false; +#ifdef NONET + return false; +#else + if (numbans == MAXBANS) + return false; + + M_Memcpy(&banned[numbans], &clientaddress[node], sizeof (mysockaddr_t)); + if (banned[numbans].any.sa_family == AF_INET) + { + banned[numbans].ip4.sin_port = 0; + bannedmask[numbans] = 32; + } +#ifdef HAVE_IPV6 + else if (banned[numbans].any.sa_family == AF_INET6) + { + banned[numbans].ip6.sin6_port = 0; + bannedmask[numbans] = 128; + } +#endif + numbans++; + return true; +#endif +} + +static boolean SOCK_Shun(INT32 node) +{ + if (node > MAXNETNODES) + return false; +#ifdef NONET + return false; +#else + if (numshun == MAXBANS) + return false; + + M_Memcpy(&shunned[numshun], &clientaddress[node], sizeof (mysockaddr_t)); + if (shunned[numshun].any.sa_family == AF_INET) + { + shunned[numshun].ip4.sin_port = 0; + shunnedmask[numshun] = 32; + } +#ifdef HAVE_IPV6 + else if (banned[numshun].any.sa_family == AF_INET6) + { + shunned[numshun].ip6.sin6_port = 0; + shunnedmask[numshun] = 128; + } +#endif + numshun++; + return true; +#endif +} + +static boolean SOCK_SetBanAddress(const char *address, const char *mask) +{ +#ifdef NONET + (void)address; + (void)mask; + return false; +#else + struct my_addrinfo *ai, *runp, hints; + int gaie; + + if (numbans == MAXBANS || !address) + return false; + + memset(&hints, 0x00, sizeof(hints)); + hints.ai_flags = 0; + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_DGRAM; + hints.ai_protocol = IPPROTO_UDP; + + gaie = I_getaddrinfo(address, "0", &hints, &ai); + if (gaie != 0) + return false; + + runp = ai; + + while(runp != NULL && numbans != MAXBANS) + { + memcpy(&banned[numbans], runp->ai_addr, runp->ai_addrlen); + + if (mask) + bannedmask[numbans] = (UINT8)atoi(mask); +#ifdef HAVE_IPV6 + else if (runp->ai_family == AF_INET6) + bannedmask[numbans] = 128; +#endif + else + bannedmask[numbans] = 32; + + if (bannedmask[numbans] > 32 && runp->ai_family == AF_INET) + bannedmask[numbans] = 32; +#ifdef HAVE_IPV6 + else if (bannedmask[numbans] > 128 && runp->ai_family == AF_INET6) + bannedmask[numbans] = 128; +#endif + numbans++; + runp = runp->ai_next; + } + + I_freeaddrinfo(ai); + + return true; +#endif +} + +static void SOCK_ClearBans(void) +{ + numbans = 0; +} + +boolean I_InitTcpNetwork(void) +{ + char serverhostname[255]; + boolean ret = false; + // initilize the OS's TCP/IP stack + if (!I_InitTcpDriver()) + return false; + + if (M_CheckParm("-udpport")) + { + if (M_IsNextParm()) + strcpy(port_name, M_GetNextParm()); + else + strcpy(port_name, "0"); + } + current_port = (UINT16)atoi(port_name); + + // parse network game options, + if (M_CheckParm("-server") || dedicated) + { + server = true; + + // If a number of clients (i.e. nodes) is specified, the server will wait for the clients + // to connect before starting. + // If no number is specified here, the server starts with 1 client, and others can join + // in-game. + // Since Boris has implemented join in-game, there is no actual need for specifying a + // particular number here. + // FIXME: for dedicated server, numnodes needs to be set to 0 upon start + if (dedicated) + doomcom->numnodes = 0; +/* else if (M_IsNextParm()) + doomcom->numnodes = (INT16)atoi(M_GetNextParm());*/ + else + doomcom->numnodes = 1; + + if (doomcom->numnodes < 0) + doomcom->numnodes = 0; + if (doomcom->numnodes > MAXNETNODES) + doomcom->numnodes = MAXNETNODES; + + // server + servernode = 0; + // FIXME: + // ??? and now ? + // server on a big modem ??? 4*isdn + net_bandwidth = 16000; + hardware_MAXPACKETLENGTH = INETPACKETLENGTH; + + ret = true; + } + else if (M_CheckParm("-connect")) + { + if (M_IsNextParm()) + strcpy(serverhostname, M_GetNextParm()); + else + serverhostname[0] = 0; // assuming server in the LAN, use broadcast to detect it + + // server address only in ip + if (serverhostname[0]) + { + COM_BufAddText("connect \""); + COM_BufAddText(serverhostname); + COM_BufAddText("\"\n"); + + // probably modem + hardware_MAXPACKETLENGTH = INETPACKETLENGTH; + } + else + { + // so we're on a LAN + COM_BufAddText("connect any\n"); + + net_bandwidth = 800000; + hardware_MAXPACKETLENGTH = MAXPACKETLENGTH; + } + } + + I_NetOpenSocket = SOCK_OpenSocket; + I_Ban = SOCK_Ban; + I_Shun = SOCK_Shun; + I_ClearBans = SOCK_ClearBans; + I_GetNodeAddress = SOCK_GetNodeAddress; + I_GetBanAddress = SOCK_GetBanAddress; + I_GetBanMask = SOCK_GetBanMask; + I_SetBanAddress = SOCK_SetBanAddress; + bannednode = SOCK_bannednode; + + return ret; +} + +#include "i_addrinfo.c" diff --git a/src/i_tcp.h b/src/i_tcp.h new file mode 100644 index 000000000..ef0baace9 --- /dev/null +++ b/src/i_tcp.h @@ -0,0 +1,31 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Copyright (C) 1999-2014 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file i_tcp.h +/// \brief TCP driver, sockets. + +#ifndef __I_TCP__ +#define __I_TCP__ + +extern UINT16 current_port; + +/** \brief The I_InitTcpNetwork function + + \return true if going or in a netgame, else it's false +*/ +boolean I_InitTcpNetwork(void); + +/** \brief The I_InitTcpNetwork function + + \return true if TCP/IP stack was initilized, else it's false +*/ +boolean I_InitTcpDriver(void); +void I_ShutdownTcpDriver(void); + +#endif diff --git a/src/i_video.h b/src/i_video.h new file mode 100644 index 000000000..76d2d6ef0 --- /dev/null +++ b/src/i_video.h @@ -0,0 +1,138 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 1993-1996 by id Software, Inc. +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Copyright (C) 1999-2014 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file i_video.h +/// \brief System specific interface stuff. + +#ifndef __I_VIDEO__ +#define __I_VIDEO__ + +#include "doomtype.h" + +#ifdef __GNUG__ +#pragma interface +#endif + +typedef enum +{ + /// Software + render_soft = 1, + + /// OpenGL + render_opengl = 2, + + /// Dedicated + render_none = 3 // for dedicated server +} rendermode_t; + +/** \brief currect render mode +*/ +extern rendermode_t rendermode; + + +/** \brief use highcolor modes if true +*/ +extern boolean highcolor; + +/** \brief setup video mode +*/ +void I_StartupGraphics(void); + +/** \brief restore old video mode +*/ +void I_ShutdownGraphics(void); + +/** \brief The I_SetPalette function + + \param palette Takes full 8 bit values + + \return void +*/ +void I_SetPalette(RGBA_t *palette); + +/** \brief return the number of video modes +*/ +INT32 VID_NumModes(void); + +/** \brief The VID_GetModeForSize function + + \param w width + \param h height + + \return vidmode closest to w : h +*/ +INT32 VID_GetModeForSize(INT32 w, INT32 h); + + +/** \brief The VID_SetMode function + + Set the video mode right now, + the video mode change is delayed until the start of the next refresh + by setting the setmodeneeded to a value >0 + setup a video mode, this is to be called from the menu + + + \param modenum video mode to set to + + \return currect video mode +*/ +INT32 VID_SetMode(INT32 modenum); + +/** \brief The VID_GetModeName function + + \param modenum video mode number + + \return name of video mode +*/ +const char *VID_GetModeName(INT32 modenum); +void VID_PrepareModeList(void); /// note hack for SDL + + +/** \brief can video system do fullscreen +*/ +extern boolean allow_fullscreen; + +/** \brief Update video system without updating frame +*/ +void I_UpdateNoBlit(void); + +/** \brief Update video system with updating frame +*/ +void I_FinishUpdate(void); + +/** \brief I_FinishUpdate(), but vsync disabled +*/ +void I_UpdateNoVsync(void); + +/** \brief Wait for vertical retrace or pause a bit. + + \param count max wait + + \return void +*/ +void I_WaitVBL(INT32 count); + +/** \brief The I_ReadScreen function + + \param scr buffer to copy screen to + + \return void +*/ +void I_ReadScreen(UINT8 *scr); + +/** \brief Start disk icon +*/ +void I_BeginRead(void); + +/** \brief Stop disk icon +*/ +void I_EndRead(void); + +#endif diff --git a/src/info.c b/src/info.c new file mode 100644 index 000000000..6f65095ed --- /dev/null +++ b/src/info.c @@ -0,0 +1,14389 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 1993-1996 by id Software, Inc. +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Copyright (C) 1999-2014 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file info.c +/// \brief Thing frame/state LUT + +// Data. +#include "doomdef.h" +#include "doomstat.h" +#include "sounds.h" +#include "p_mobj.h" +#include "m_misc.h" +#include "z_zone.h" +#include "d_player.h" +#include "lzf.h" +#ifdef HWRENDER +#include "hardware/hw_light.h" +#endif + +// Hey, moron! If you change this table, don't forget about the sprite enum in info.h and the sprite lights in hw_light.c! +char sprnames[NUMSPRITES + 1][5] = +{ + "NULL","UNKN","THOK","PLAY","POSS","SPOS","FISH","BUZZ","RBUZ","JETB", + "JETW","JETG","CCOM","DETN","SKIM","TRET","TURR","SHRP","JJAW","SNLR", + "VLTR","PNTY","ARCH","CBFS","SPSH","ESHI","GSNP","MNUS","SSHL","UNID", + "BBUZ","JETF","EGGM","EGGN","TNKA","TNKB","SPNK","GOOP","EGGO","PRPL", + "FAKE","EGGP","EFIR","EGGQ","EGGR","BRAK","BGOO","BMSL","EGGT","RCKT", + "ELEC","TARG","NPLM","MNPL","METL","MSCF","MSCB","RING","TRNG","EMMY", + "TOKE","RFLG","BFLG","NWNG","EMBM","CEMG","EMER","FANS","BUBL","SIGN", + "STEM","SPIK","SFLM","USPK","STPT","BMNE","SRBX","RRBX","BRBX","SHTV", + "PINV","YLTV","BLTV","BKTV","WHTV","GRTV","ELTV","EGGB","MIXU","RECY", + "QUES","GBTV","PRUP","PTTV","MTEX","MISL","TORP","ENRG","MINE","JBUL", + "TRLS","CBLL","AROW","FWR1","FWR2","FWR3","FWR4","BUS1","BUS2","THZP", + "ALRM","GARG","SEWE","DRIP","CRL1","CRL2","CRL3","BCRY","CHAN","FLAM", + "ESTA","SMCH","BMCH","SMCE","BMCE","BTBL","STBL","CACT","FLME","DFLM", + "XMS1","XMS2","XMS3","BSZ1","BSZ2","BSZ3","BSZ4","BSZ5","BSZ6","BSZ7", + "BSZ8","STLG","DBAL","RCRY","ARMA","ARMF","ARMB","WIND","MAGN","ELEM", + "FORC","PITY","IVSP","SSPK","GOAL","BIRD","BUNY","MOUS","CHIC","COWZ", + "RBRD","SPRY","SPRR","SPRB","YSPR","RSPR","RAIN","SNO1","SPLH","SPLA", + "SMOK","BUBP","BUBO","BUBN","BUBM","POPP","TFOG","SEED","PRTL","SCOR", + "DRWN","TTAG","GFLG","RRNG","RNGB","RNGR","RNGI","RNGA","RNGE","RNGS", + "RNGG","PIKB","PIKR","PIKA","PIKE","PIKS","PIKG","TAUT","TGRE","TSCR", + "COIN","CPRK","GOOM","BGOM","FFWR","FBLL","SHLL","PUMA","HAMM","KOOP", + "BFLM","MAXE","MUS1","MUS2","TOAD","NDRN","SUPE","SUPZ","NDRL","NSPK", + "NBMP","HOOP","NSCR","NPRU","CAPS","SUPT","SPRK","BOM1","BOM2","BOM3", + "BOM4","ROIA","ROIB","ROIC","ROID","ROIE","ROIF","ROIG","ROIH","ROII", + "ROIJ","ROIK","ROIL","ROIM","ROIN","ROIO","ROIP","BBAL","GWLG","GWLR", + "SRBA","SRBB","SRBC","SRBD","SRBE","SRBF","SRBG","SRBH","SRBI","SRBJ", + "SRBK","SRBL","SRBM","SRBN","SRBO", +}; + +// Doesn't work with g++, needs actionf_p1 (don't modify this comment) +state_t states[NUMSTATES] = +{ + // frame is masked through FF_FRAMEMASK + // FF_FULLBRIGHT (0x8000) activates the fullbright colormap + // Keep this comment directly above S_NULL. + {SPR_NULL, 0, 1, {NULL}, 0, 0, S_NULL}, // S_NULL + {SPR_UNKN, FF_FULLBRIGHT, -1, {NULL}, 0, 0, S_NULL}, // S_UNKNOWN + {SPR_NULL, 0, -1, {NULL}, 0, 0, S_NULL}, // S_INVISIBLE + + {SPR_UNKN, FF_FULLBRIGHT, -1, {A_InfoState}, 0, 0, S_NULL}, // S_SPAWNSTATE + {SPR_UNKN, FF_FULLBRIGHT, -1, {A_InfoState}, 1, 0, S_NULL}, // S_SEESTATE + {SPR_UNKN, FF_FULLBRIGHT, -1, {A_InfoState}, 2, 0, S_NULL}, // S_MELEESTATE + {SPR_UNKN, FF_FULLBRIGHT, -1, {A_InfoState}, 3, 0, S_NULL}, // S_MISSILESTATE + {SPR_UNKN, FF_FULLBRIGHT, -1, {A_InfoState}, 4, 0, S_NULL}, // S_DEATHSTATE + {SPR_UNKN, FF_FULLBRIGHT, -1, {A_InfoState}, 5, 0, S_NULL}, // S_XDEATHSTATE + {SPR_UNKN, FF_FULLBRIGHT, -1, {A_InfoState}, 6, 0, S_NULL}, // S_RAISESTATE + + // Thok + {SPR_THOK, 0, 8, {NULL}, 0, 0, S_NULL}, // S_THOK + + // Player + {SPR_PLAY, 0, 105, {NULL}, 0, 0, S_PLAY_TAP1}, // S_PLAY_STND + {SPR_PLAY, 1, 16, {NULL}, 0, 0, S_PLAY_TAP2}, // S_PLAY_TAP1 + {SPR_PLAY, 2, 16, {NULL}, 0, 0, S_PLAY_TAP1}, // S_PLAY_TAP2 + {SPR_PLAY, 3, 4, {NULL}, 0, 0, S_PLAY_RUN2}, // S_PLAY_RUN1 + {SPR_PLAY, 4, 4, {NULL}, 0, 0, S_PLAY_RUN3}, // S_PLAY_RUN2 + {SPR_PLAY, 5, 4, {NULL}, 0, 0, S_PLAY_RUN4}, // S_PLAY_RUN3 + {SPR_PLAY, 6, 4, {NULL}, 0, 0, S_PLAY_RUN5}, // S_PLAY_RUN4 + {SPR_PLAY, 7, 4, {NULL}, 0, 0, S_PLAY_RUN6}, // S_PLAY_RUN5 + {SPR_PLAY, 8, 4, {NULL}, 0, 0, S_PLAY_RUN7}, // S_PLAY_RUN6 + {SPR_PLAY, 9, 4, {NULL}, 0, 0, S_PLAY_RUN8}, // S_PLAY_RUN7 + {SPR_PLAY, 10, 4, {NULL}, 0, 0, S_PLAY_RUN1}, // S_PLAY_RUN8 + {SPR_PLAY, 16, 2, {NULL}, 0, 0, S_PLAY_SPD2}, // S_PLAY_SPD1 + {SPR_PLAY, 17, 2, {NULL}, 0, 0, S_PLAY_SPD3}, // S_PLAY_SPD2 + {SPR_PLAY, 18, 2, {NULL}, 0, 0, S_PLAY_SPD4}, // S_PLAY_SPD3 + {SPR_PLAY, 19, 2, {NULL}, 0, 0, S_PLAY_SPD1}, // S_PLAY_SPD4 + {SPR_PLAY, 11, 1, {NULL}, 0, 0, S_PLAY_ATK2}, // S_PLAY_ATK1 + {SPR_PLAY, 12, 1, {NULL}, 0, 0, S_PLAY_ATK3}, // S_PLAY_ATK2 + {SPR_PLAY, 13, 1, {NULL}, 0, 0, S_PLAY_ATK4}, // S_PLAY_ATK3 + {SPR_PLAY, 14, 1, {NULL}, 0, 0, S_PLAY_ATK1}, // S_PLAY_ATK4 + {SPR_PLAY, 15, -1, {NULL}, 0, 0, S_PLAY_FALL1}, // S_PLAY_SPRING + {SPR_PLAY, 31, 2, {NULL}, 0, 0, S_PLAY_FALL2}, // S_PLAY_FALL1 + {SPR_PLAY, 32, 2, {NULL}, 0, 0, S_PLAY_FALL1}, // S_PLAY_FALL2 + {SPR_PLAY, 20, 2, {NULL}, 0, 0, S_PLAY_ABL2}, // S_PLAY_ABL1 + {SPR_PLAY, 21, 2, {NULL}, 0, 0, S_PLAY_ABL1}, // S_PLAY_ABL2 + {SPR_PLAY, 22, 6, {NULL}, 0, 0, S_PLAY_SPC2}, // S_PLAY_SPC1 + {SPR_PLAY, 23, 6, {NULL}, 0, 0, S_PLAY_SPC3}, // S_PLAY_SPC2 + {SPR_PLAY, 24, 6, {NULL}, 0, 0, S_PLAY_SPC4}, // S_PLAY_SPC3 + {SPR_PLAY, 25, 6, {NULL}, 0, 0, S_PLAY_SPC1}, // S_PLAY_SPC4 + {SPR_PLAY, 22, -1, {NULL}, 0, 0, S_NULL}, // S_PLAY_CLIMB1 + {SPR_PLAY, 23, 5, {NULL}, 0, 0, S_PLAY_CLIMB3}, // S_PLAY_CLIMB2 + {SPR_PLAY, 24, 5, {NULL}, 0, 0, S_PLAY_CLIMB4}, // S_PLAY_CLIMB3 + {SPR_PLAY, 25, 5, {NULL}, 0, 0, S_PLAY_CLIMB5}, // S_PLAY_CLIMB4 + {SPR_PLAY, 24, 5, {NULL}, 0, 0, S_PLAY_CLIMB2}, // S_PLAY_CLIMB5 + {SPR_PLAY, 26, 14, {NULL}, 0, 0, S_PLAY_RUN1}, // S_PLAY_GASP + {SPR_PLAY, 27, 350, {NULL}, 0, 0, S_PLAY_FALL1}, // S_PLAY_PAIN + {SPR_PLAY, 28, -1, {A_Fall}, 0, 0, S_NULL}, // S_PLAY_DIE + {SPR_PLAY, 29, 12, {NULL}, 0, 0, S_PLAY_TEETER2}, // S_PLAY_TEETER1 + {SPR_PLAY, 30, 12, {NULL}, 0, 0, S_PLAY_TEETER1}, // S_PLAY_TEETER2 + {SPR_PLAY, 33, -1, {NULL}, 0, 0, S_NULL}, // S_PLAY_CARRY + {SPR_PLAY, 20, -1, {NULL}, 0, 0, S_PLAY_SUPERSTAND}, // S_PLAY_SUPERSTAND + {SPR_PLAY, 20, 7, {NULL}, 0, 0, S_PLAY_SUPERWALK2}, // S_PLAY_SUPERWALK1 + {SPR_PLAY, 21, 7, {NULL}, 0, 0, S_PLAY_SUPERWALK1}, // S_PLAY_SUPERWALK2 + {SPR_PLAY, 22, 7, {NULL}, 0, 0, S_PLAY_SUPERFLY2}, // S_PLAY_SUPERFLY1 + {SPR_PLAY, 23, 7, {NULL}, 0, 0, S_PLAY_SUPERFLY1}, // S_PLAY_SUPERFLY2 + {SPR_PLAY, 24, 12, {NULL}, 0, 0, S_PLAY_SUPERTEETER}, // S_PLAY_SUPERTEETER + {SPR_PLAY, 25, -1, {NULL}, 0, 0, S_PLAY_SUPERSTAND}, // S_PLAY_SUPERHIT + {SPR_PLAY, 36, 4, {NULL}, 0, 0, S_PLAY_SUPERTRANS2}, // S_PLAY_SUPERTRANS1 + {SPR_PLAY, 37, 4, {NULL}, 0, 0, S_PLAY_SUPERTRANS3}, // S_PLAY_SUPERTRANS2 + {SPR_PLAY, 32806, 4, {NULL}, 0, 0, S_PLAY_SUPERTRANS4}, // S_PLAY_SUPERTRANS3 + {SPR_PLAY, 39, 3, {NULL}, 0, 0, S_PLAY_SUPERTRANS5}, // S_PLAY_SUPERTRANS4 + {SPR_PLAY, 40, 3, {NULL}, 0, 0, S_PLAY_SUPERTRANS6}, // S_PLAY_SUPERTRANS5 + {SPR_PLAY, 41, 3, {NULL}, 0, 0, S_PLAY_SUPERTRANS7}, // S_PLAY_SUPERTRANS6 + {SPR_PLAY, 42, 3, {NULL}, 0, 0, S_PLAY_SUPERTRANS8}, // S_PLAY_SUPERTRANS7 + {SPR_PLAY, 43, 3, {NULL}, 0, 0, S_PLAY_SUPERTRANS9}, // S_PLAY_SUPERTRANS8 + {SPR_PLAY, 44, 16, {NULL}, 0, 0, S_PLAY_RUN1}, // S_PLAY_SUPERTRANS9 + + {SPR_NULL, 0, -1, {NULL}, 0, 0, S_OBJPLACE_DUMMY}, //S_OBJPLACE_DUMMY + + // 1-Up Box Sprites (uses player sprite) + {SPR_PLAY, 35, 2, {NULL}, 0, 16, S_PLAY_BOX2}, // S_PLAY_BOX1 + {SPR_NULL, 0, 1, {NULL}, 0, 0, S_PLAY_BOX1}, // S_PLAY_BOX2 + {SPR_PLAY, 35, 4, {NULL}, 0, 4, S_PLAY_ICON2}, // S_PLAY_ICON1 + {SPR_NULL, 0, 12, {NULL}, 0, 0, S_PLAY_ICON3}, // S_PLAY_ICON2 + {SPR_PLAY, 35, 18, {NULL}, 0, 4, S_NULL}, // S_PLAY_ICON3 + + // Level end sign (uses player sprite) + {SPR_PLAY, 34, 1, {NULL}, 0, 24, S_PLAY_SIGN}, // S_PLAY_SIGN + + // Blue Crawla + {SPR_POSS, 0, 5, {A_Look}, 0, 0, S_POSS_STND2}, // S_POSS_STND + {SPR_POSS, 0, 5, {A_Look}, 0, 0, S_POSS_STND}, // S_POSS_STND2 + {SPR_POSS, 0, 3, {A_Chase}, 0, 0, S_POSS_RUN2}, // S_POSS_RUN1 + {SPR_POSS, 1, 3, {A_Chase}, 0, 0, S_POSS_RUN3}, // S_POSS_RUN2 + {SPR_POSS, 2, 3, {A_Chase}, 0, 0, S_POSS_RUN4}, // S_POSS_RUN3 + {SPR_POSS, 3, 3, {A_Chase}, 0, 0, S_POSS_RUN5}, // S_POSS_RUN4 + {SPR_POSS, 4, 3, {A_Chase}, 0, 0, S_POSS_RUN6}, // S_POSS_RUN5 + {SPR_POSS, 5, 3, {A_Chase}, 0, 0, S_POSS_RUN1}, // S_POSS_RUN6 + + // Red Crawla + {SPR_SPOS, 0, 5, {A_Look}, 0, 0, S_SPOS_STND2}, // S_SPOS_STND + {SPR_SPOS, 0, 5, {A_Look}, 0, 0, S_SPOS_STND}, // S_SPOS_STND2 + {SPR_SPOS, 0, 1, {A_Chase}, 0, 0, S_SPOS_RUN2}, // S_SPOS_RUN1 + {SPR_SPOS, 1, 1, {A_Chase}, 0, 0, S_SPOS_RUN3}, // S_SPOS_RUN2 + {SPR_SPOS, 2, 1, {A_Chase}, 0, 0, S_SPOS_RUN4}, // S_SPOS_RUN3 + {SPR_SPOS, 3, 1, {A_Chase}, 0, 0, S_SPOS_RUN5}, // S_SPOS_RUN4 + {SPR_SPOS, 4, 1, {A_Chase}, 0, 0, S_SPOS_RUN6}, // S_SPOS_RUN5 + {SPR_SPOS, 5, 1, {A_Chase}, 0, 0, S_SPOS_RUN1}, // S_SPOS_RUN6 + + // Greenflower Fish + {SPR_FISH, 1, 1, {NULL}, 0, 0, S_FISH2}, // S_FISH1 + {SPR_FISH, 1, 1, {A_FishJump}, 0, 0, S_FISH1}, // S_FISH2 + {SPR_FISH, 0, 1, {NULL}, 0, 0, S_FISH4}, // S_FISH3 + {SPR_FISH, 0, 1, {A_FishJump}, 0, 0, S_FISH3}, // S_FISH4 + + // Gold Buzz + {SPR_BUZZ, 0, 2, {A_Look}, 0, 0, S_BUZZLOOK2}, // S_BUZZLOOK1 + {SPR_BUZZ, 1, 2, {A_Look}, 0, 0, S_BUZZLOOK1}, // S_BUZZLOOK2 + {SPR_BUZZ, 0, 2, {A_BuzzFly}, sfx_buzz4, 0, S_BUZZFLY2}, // S_BUZZFLY1 + {SPR_BUZZ, 1, 2, {A_BuzzFly}, 0, 0, S_BUZZFLY1}, // S_BUZZFLY2 + + // Red Buzz + {SPR_RBUZ, 0, 2, {A_Look}, 0, 0, S_RBUZZLOOK2}, // S_RBUZZLOOK1 + {SPR_RBUZ, 1, 2, {A_Look}, 0, 0, S_RBUZZLOOK1}, // S_RBUZZLOOK2 + {SPR_RBUZ, 0, 2, {A_BuzzFly}, sfx_buzz4, 0, S_RBUZZFLY2}, // S_RBUZZFLY1 + {SPR_RBUZ, 1, 2, {A_BuzzFly}, 0, 0, S_RBUZZFLY1}, // S_RBUZZFLY2 + + // AquaBuzz + {SPR_BBUZ, 0, 2, {NULL}, 0, 0, S_BBUZZFLY2}, // S_BBUZZFLY1 + {SPR_BBUZ, 1, 2, {NULL}, 0, 0, S_BBUZZFLY1}, // S_BBUZZFLY2 + + // Jetty-Syn Bomber + {SPR_JETB, 0, 4, {A_Look}, 0, 0, S_JETBLOOK2}, // S_JETBLOOK1 + {SPR_JETB, 1, 4, {A_Look}, 0, 0, S_JETBLOOK1}, // S_JETBLOOK2 + {SPR_JETB, 0, 1, {A_JetbThink}, 0, 0, S_JETBZOOM2}, // S_JETBZOOM1 + {SPR_JETB, 1, 1, {A_JetbThink}, 0, 0, S_JETBZOOM1}, // S_JETBZOOM2 + + // Jetty-Syn Gunner + {SPR_JETG, 0, 4, {A_Look}, 0, 0, S_JETGLOOK2}, // S_JETGLOOK1 + {SPR_JETG, 1, 4, {A_Look}, 0, 0, S_JETGLOOK1}, // S_JETGLOOK2 + {SPR_JETG, 0, 1, {A_JetgThink}, 0, 0, S_JETGZOOM2}, // S_JETGZOOM1 + {SPR_JETG, 1, 1, {A_JetgThink}, 0, 0, S_JETGZOOM1}, // S_JETGZOOM2 + {SPR_JETG, 2, 1, {A_JetgShoot}, 0, 0, S_JETGSHOOT2}, // S_JETGSHOOT1 + {SPR_JETG, 3, 1, {NULL}, 0, 0, S_JETGZOOM1}, // S_JETGSHOOT2 + + // Crawla Commander + {SPR_CCOM, 0, 1, {A_CrawlaCommanderThink}, 0, 15*FRACUNIT, S_CCOMMAND2}, // S_CCOMMAND1 + {SPR_CCOM, 1, 1, {A_CrawlaCommanderThink}, 0, 15*FRACUNIT, S_CCOMMAND1}, // S_CCOMMAND2 + {SPR_CCOM, 2, 1, {A_CrawlaCommanderThink}, 0, 15*FRACUNIT, S_CCOMMAND4}, // S_CCOMMAND3 + {SPR_CCOM, 3, 1, {A_CrawlaCommanderThink}, 0, 15*FRACUNIT, S_CCOMMAND3}, // S_CCOMMAND4 + + // Deton + {SPR_DETN, 0, 35, {A_Look}, 0, 0, S_DETON1}, // S_DETON1 + {SPR_DETN, 0, 1, {A_DetonChase}, 0, 0, S_DETON3}, // S_DETON2 + {SPR_DETN, 1, 1, {A_DetonChase}, 0, 0, S_DETON4}, // S_DETON3 + {SPR_DETN, 2, 1, {A_DetonChase}, 0, 0, S_DETON5}, // S_DETON4 + {SPR_DETN, 3, 1, {A_DetonChase}, 0, 0, S_DETON6}, // S_DETON5 + {SPR_DETN, 4, 1, {A_DetonChase}, 0, 0, S_DETON7}, // S_DETON6 + {SPR_DETN, 5, 1, {A_DetonChase}, 0, 0, S_DETON8}, // S_DETON7 + {SPR_DETN, 6, 1, {A_DetonChase}, 0, 0, S_DETON9}, // S_DETON8 + {SPR_DETN, 7, 1, {A_DetonChase}, 0, 0, S_DETON10}, // S_DETON9 + {SPR_DETN, 6, 1, {A_DetonChase}, 0, 0, S_DETON11}, // S_DETON10 + {SPR_DETN, 5, 1, {A_DetonChase}, 0, 0, S_DETON12}, // S_DETON11 + {SPR_DETN, 4, 1, {A_DetonChase}, 0, 0, S_DETON13}, // S_DETON12 + {SPR_DETN, 3, 1, {A_DetonChase}, 0, 0, S_DETON14}, // S_DETON13 + {SPR_DETN, 2, 1, {A_DetonChase}, 0, 0, S_DETON15}, // S_DETON14 + {SPR_DETN, 1, 1, {A_DetonChase}, 0, 0, S_DETON2}, // S_DETON15 + {SPR_DETN, 0, -1, {NULL}, 0, 0, S_DETON16}, // S_DETON16 + + // Skim Mine Dropper + {SPR_SKIM, 0, 1, {A_SkimChase}, 0, 0, S_SKIM2}, // S_SKIM1 + {SPR_SKIM, 0, 1, {A_SkimChase}, 0, 0, S_SKIM1}, // S_SKIM2 + {SPR_SKIM, 0, 14, {NULL}, 0, 0, S_SKIM4}, // S_SKIM3 + {SPR_SKIM, 0, 14, {A_DropMine}, 0, 0, S_SKIM1}, // S_SKIM4 + + // THZ Turret + {SPR_TRET, FF_FULLBRIGHT, 105, {A_TurretStop}, 0, 0, S_TURRETFIRE}, // S_TURRET + {SPR_TRET, FF_FULLBRIGHT, 105, {A_TurretFire}, 0, 0, S_TURRET}, // S_TURRETFIRE + {SPR_TRET, FF_FULLBRIGHT+1, 7, {A_Pain}, 0, 0, S_TURRETSHOCK2}, // S_TURRETSHOCK1 + {SPR_TRET, FF_FULLBRIGHT+2, 7, {NULL}, 0, 0, S_TURRETSHOCK3}, // S_TURRETSHOCK2 + {SPR_TRET, FF_FULLBRIGHT+3, 7, {NULL}, 0, 0, S_TURRETSHOCK4}, // S_TURRETSHOCK3 + {SPR_TRET, FF_FULLBRIGHT+4, 7, {NULL}, 0, 0, S_TURRETSHOCK5}, // S_TURRETSHOCK4 + {SPR_TRET, FF_FULLBRIGHT+1, 7, {NULL}, 0, 0, S_TURRETSHOCK6}, // S_TURRETSHOCK5 + {SPR_TRET, FF_FULLBRIGHT+2, 7, {A_Pain}, 0, 0, S_TURRETSHOCK7}, // S_TURRETSHOCK6 + {SPR_TRET, FF_FULLBRIGHT+3, 7, {NULL}, 0, 0, S_TURRETSHOCK8}, // S_TURRETSHOCK7 + {SPR_TRET, FF_FULLBRIGHT+4, 7, {NULL}, 0, 0, S_TURRETSHOCK9}, // S_TURRETSHOCK8 + {SPR_TRET, FF_FULLBRIGHT+4, 7, {A_LinedefExecute}, 32000, 0, S_XPLD1}, // S_TURRETSHOCK9 + + {SPR_TURR, 0, 1, {A_Look}, 1, 0, S_TURRETPOPDOWN8}, // S_TURRETLOOK + {SPR_TURR, 0, 0, {A_FaceTarget}, 0, 0, S_TURRETPOPUP1}, // S_TURRETSEE + {SPR_TURR, 1, 2, {A_Pain}, 0, 0, S_TURRETPOPUP2}, // S_TURRETPOPUP1 + {SPR_TURR, 2, 2, {NULL}, 0, 0, S_TURRETPOPUP3}, // S_TURRETPOPUP2 + {SPR_TURR, 3, 2, {NULL}, 0, 0, S_TURRETPOPUP4}, // S_TURRETPOPUP3 + {SPR_TURR, 4, 2, {NULL}, 0, 0, S_TURRETPOPUP5}, // S_TURRETPOPUP4 + {SPR_TURR, 5, 2, {NULL}, 0, 0, S_TURRETPOPUP6}, // S_TURRETPOPUP5 + {SPR_TURR, 6, 2, {NULL}, 0, 0, S_TURRETPOPUP7}, // S_TURRETPOPUP6 + {SPR_TURR, 7, 2, {NULL}, 0, 0, S_TURRETPOPUP8}, // S_TURRETPOPUP7 + {SPR_TURR, 8, 14,{NULL}, 0, 0, S_TURRETSHOOT}, // S_TURRETPOPUP8 + {SPR_TURR, 8, 14,{A_JetgShoot}, 0, 0, S_TURRETPOPDOWN1}, // S_TURRETSHOOT + {SPR_TURR, 7, 2, {A_Pain}, 0, 0, S_TURRETPOPDOWN2}, // S_TURRETPOPDOWN1 + {SPR_TURR, 6, 2, {NULL}, 0, 0, S_TURRETPOPDOWN3}, // S_TURRETPOPDOWN2 + {SPR_TURR, 5, 2, {NULL}, 0, 0, S_TURRETPOPDOWN4}, // S_TURRETPOPDOWN3 + {SPR_TURR, 4, 2, {NULL}, 0, 0, S_TURRETPOPDOWN5}, // S_TURRETPOPDOWN4 + {SPR_TURR, 3, 2, {NULL}, 0, 0, S_TURRETPOPDOWN6}, // S_TURRETPOPDOWN5 + {SPR_TURR, 2, 2, {NULL}, 0, 0, S_TURRETPOPDOWN7}, // S_TURRETPOPDOWN6 + {SPR_TURR, 1, 2, {NULL}, 0, 0, S_TURRETPOPDOWN8}, // S_TURRETPOPDOWN7 + {SPR_TURR, 0, 69,{A_SetTics}, 0, 1, S_TURRETLOOK}, // S_TURRETPOPDOWN8 + + // Sharp + {SPR_SHRP, 0, 1, {A_Look}, 0, 0, S_SHARP_ROAM1}, // S_SHARP_ROAM1, + {SPR_SHRP, 0, 1, {A_SharpChase}, 0, 0, S_SHARP_ROAM2}, // S_SHARP_ROAM2, + {SPR_SHRP, 1, 2, {A_FaceTarget}, 0, 0, S_SHARP_AIM2}, // S_SHARP_AIM1, + {SPR_SHRP, 2, 2, {A_FaceTarget}, 0, 0, S_SHARP_AIM3}, // S_SHARP_AIM2, + {SPR_SHRP, 3, 2, {A_FaceTarget}, 0, 0, S_SHARP_AIM4}, // S_SHARP_AIM3, + {SPR_SHRP, 4, 7, {A_FaceTarget}, 0, 0, S_SHARP_SPIN}, // S_SHARP_AIM4, + {SPR_SHRP, 4, 1, {A_SharpSpin}, 0, 0, S_SHARP_SPIN}, // S_SHARP_SPIN, + + // Jet Jaw + {SPR_JJAW, 0, 1, {A_JetJawRoam}, 0, 0, S_JETJAW_ROAM2}, // S_JETJAW_ROAM1 + {SPR_JJAW, 0, 1, {A_JetJawRoam}, 0, 0, S_JETJAW_ROAM3}, // S_JETJAW_ROAM2 + {SPR_JJAW, 0, 1, {A_JetJawRoam}, 0, 0, S_JETJAW_ROAM4}, // S_JETJAW_ROAM3 + {SPR_JJAW, 0, 1, {A_JetJawRoam}, 0, 0, S_JETJAW_ROAM5}, // S_JETJAW_ROAM4 + {SPR_JJAW, 1, 1, {A_JetJawRoam}, 0, 0, S_JETJAW_ROAM6}, // S_JETJAW_ROAM5 + {SPR_JJAW, 1, 1, {A_JetJawRoam}, 0, 0, S_JETJAW_ROAM7}, // S_JETJAW_ROAM6 + {SPR_JJAW, 1, 1, {A_JetJawRoam}, 0, 0, S_JETJAW_ROAM8}, // S_JETJAW_ROAM7 + {SPR_JJAW, 1, 1, {A_JetJawRoam}, 0, 0, S_JETJAW_ROAM1}, // S_JETJAW_ROAM8 + {SPR_JJAW, 0, 1, {A_JetJawChomp}, 0, 0, S_JETJAW_CHOMP2}, // S_JETJAW_CHOMP1 + {SPR_JJAW, 0, 1, {A_JetJawChomp}, 0, 0, S_JETJAW_CHOMP3}, // S_JETJAW_CHOMP2 + {SPR_JJAW, 0, 1, {A_JetJawChomp}, 0, 0, S_JETJAW_CHOMP4}, // S_JETJAW_CHOMP3 + {SPR_JJAW, 0, 1, {A_JetJawChomp}, 0, 0, S_JETJAW_CHOMP5}, // S_JETJAW_CHOMP4 + {SPR_JJAW, 1, 1, {A_JetJawChomp}, 0, 0, S_JETJAW_CHOMP6}, // S_JETJAW_CHOMP5 + {SPR_JJAW, 1, 1, {A_JetJawChomp}, 0, 0, S_JETJAW_CHOMP7}, // S_JETJAW_CHOMP6 + {SPR_JJAW, 1, 1, {A_JetJawChomp}, 0, 0, S_JETJAW_CHOMP8}, // S_JETJAW_CHOMP7 + {SPR_JJAW, 1, 1, {A_JetJawChomp}, 0, 0, S_JETJAW_CHOMP9}, // S_JETJAW_CHOMP8 + {SPR_JJAW, 2, 1, {A_JetJawChomp}, 0, 0, S_JETJAW_CHOMP10}, // S_JETJAW_CHOMP9 + {SPR_JJAW, 2, 1, {A_JetJawChomp}, 0, 0, S_JETJAW_CHOMP11}, // S_JETJAW_CHOMP10 + {SPR_JJAW, 2, 1, {A_JetJawChomp}, 0, 0, S_JETJAW_CHOMP12}, // S_JETJAW_CHOMP11 + {SPR_JJAW, 2, 1, {A_JetJawChomp}, 0, 0, S_JETJAW_CHOMP13}, // S_JETJAW_CHOMP12 + {SPR_JJAW, 3, 1, {A_JetJawChomp}, 0, 0, S_JETJAW_CHOMP14}, // S_JETJAW_CHOMP13 + {SPR_JJAW, 3, 1, {A_JetJawChomp}, 0, 0, S_JETJAW_CHOMP15}, // S_JETJAW_CHOMP14 + {SPR_JJAW, 3, 1, {A_JetJawChomp}, 0, 0, S_JETJAW_CHOMP16}, // S_JETJAW_CHOMP15 + {SPR_JJAW, 3, 1, {A_JetJawChomp}, 0, 0, S_JETJAW_CHOMP1}, // S_JETJAW_CHOMP16 + + // Snailer + {SPR_SNLR, 0, 1, {A_SnailerThink}, 0, 0, S_SNAILER1}, // S_SNAILER1 + + // Vulture + {SPR_VLTR, 4, 35, {A_Look}, 1, 0, S_VULTURE_STND}, // S_VULTURE_STND + {SPR_VLTR, 4, 1, {A_VultureVtol}, 0, 0, S_VULTURE_VTOL2}, // S_VULTURE_VTOL1 + {SPR_VLTR, 5, 1, {A_VultureVtol}, 0, 0, S_VULTURE_VTOL3}, // S_VULTURE_VTOL2 + {SPR_VLTR, 6, 1, {A_VultureVtol}, 0, 0, S_VULTURE_VTOL4}, // S_VULTURE_VTOL3 + {SPR_VLTR, 7, 1, {A_VultureVtol}, 0, 0, S_VULTURE_VTOL1}, // S_VULTURE_VTOL4 + {SPR_VLTR, 0, 1, {A_Thrust}, 30, 1, S_VULTURE_ZOOM2}, // S_VULTURE_ZOOM1 + {SPR_VLTR, 0, 1, {A_VultureCheck}, 0, 0, S_VULTURE_ZOOM3}, // S_VULTURE_ZOOM2 + {SPR_VLTR, 1, 1, {A_VultureCheck}, 0, 0, S_VULTURE_ZOOM4}, // S_VULTURE_ZOOM3 + {SPR_VLTR, 2, 1, {A_VultureCheck}, 0, 0, S_VULTURE_ZOOM5}, // S_VULTURE_ZOOM4 + {SPR_VLTR, 3, 1, {A_VultureCheck}, 0, 0, S_VULTURE_ZOOM2}, // S_VULTURE_ZOOM5 + + // Pointy + {SPR_PNTY, 0, 1, {A_PointyThink}, 0, 0, S_POINTY1}, // S_POINTY1 + + // Pointy Ball + {SPR_PNTY, 1, 1, {A_CheckBuddy}, 0, 0, S_POINTYBALL1}, // S_POINTYBALL1 + + // Robo-Hood + {SPR_ARCH, 0, 14, {A_Look}, (512<<16), 0, S_ROBOHOOD_LOOK}, // S_ROBOHOOD_LOOK + {SPR_ARCH, 2, 1, {A_HoodThink}, 0, 0, S_ROBOHOOD_STND}, // S_ROBOHOOD_STND + {SPR_ARCH, 0, 35, {A_FireShot}, MT_ARROW, -24, S_ROBOHOOD_STND}, // S_ROBOHOOD_SHOOT + {SPR_ARCH, 1, 1, {A_BunnyHop}, 8, 5, S_ROBOHOOD_JUMP2}, // S_ROBOHOOD_JUMP + {SPR_ARCH, 1, 1, {A_HoodThink}, 0, 0, S_ROBOHOOD_JUMP2}, // S_ROBOHOOD_JUMP2 + {SPR_ARCH, 0, 1, {A_HoodThink}, 0, 0, S_ROBOHOOD_FALL}, // S_ROBOHOOD_FALL + + // CastleBot FaceStabber + {SPR_CBFS, 0, 1, {A_FaceStabChase}, 0, 0, S_FACESTABBER_STND2}, // S_FACESTABBER_STND1 + {SPR_CBFS, 1, 1, {A_FaceStabChase}, 0, 0, S_FACESTABBER_STND3}, // S_FACESTABBER_STND2 + {SPR_CBFS, 2, 1, {A_FaceStabChase}, 0, 0, S_FACESTABBER_STND4}, // S_FACESTABBER_STND3 + {SPR_CBFS, 3, 1, {A_FaceStabChase}, 0, 0, S_FACESTABBER_STND5}, // S_FACESTABBER_STND4 + {SPR_CBFS, 4, 1, {A_FaceStabChase}, 0, 0, S_FACESTABBER_STND6}, // S_FACESTABBER_STND5 + {SPR_CBFS, 5, 1, {A_FaceStabChase}, 0, 0, S_FACESTABBER_STND1}, // S_FACESTABBER_STND6 + {SPR_CBFS, 6, 14, {A_PlayActiveSound}, 0, 0, S_FACESTABBER_CHARGE2}, // S_FACESTABBER_CHARGE1 + {SPR_CBFS, 6, 0, {A_PlayAttackSound}, 0, 0, S_FACESTABBER_CHARGE3}, // S_FACESTABBER_CHARGE2 + {SPR_CBFS, 6, 0, {A_FaceTarget}, 0, 0, S_FACESTABBER_CHARGE4}, // S_FACESTABBER_CHARGE3 + {SPR_CBFS, 7, 35, {A_Thrust}, 20, 1, S_FACESTABBER_STND1}, // S_FACESTABBER_CHARGE4 + + // Egg Guard + {SPR_SPSH, 0, 1, {A_Look}, 0, 0, S_EGGGUARD_STND}, // S_EGGGUARD_STND + {SPR_SPSH, 1, 3, {A_GuardChase}, 0, 0, S_EGGGUARD_WALK2}, // S_EGGGUARD_WALK1 + {SPR_SPSH, 2, 3, {A_GuardChase}, 0, 0, S_EGGGUARD_WALK3}, // S_EGGGUARD_WALK2 + {SPR_SPSH, 3, 3, {A_GuardChase}, 0, 0, S_EGGGUARD_WALK4}, // S_EGGGUARD_WALK3 + {SPR_SPSH, 4, 3, {A_GuardChase}, 0, 0, S_EGGGUARD_WALK1}, // S_EGGGUARD_WALK4 + {SPR_SPSH, 5, 5, {NULL}, 0, 0, S_EGGGUARD_MAD2}, // S_EGGGUARD_MAD1 + {SPR_SPSH, 6, 5, {NULL}, 0, 0, S_EGGGUARD_MAD3}, // S_EGGGUARD_MAD2 + {SPR_SPSH, 7, 15, {NULL}, 0, 0, S_EGGGUARD_RUN1}, // S_EGGGUARD_MAD3 + {SPR_SPSH, 8, 1, {A_GuardChase}, 0, 0, S_EGGGUARD_RUN2}, // S_EGGGUARD_RUN1 + {SPR_SPSH, 9, 1, {A_GuardChase}, 0, 0, S_EGGGUARD_RUN3}, // S_EGGGUARD_RUN2 + {SPR_SPSH, 10, 1, {A_GuardChase}, 0, 0, S_EGGGUARD_RUN4}, // S_EGGGUARD_RUN3 + {SPR_SPSH, 11, 1, {A_GuardChase}, 0, 0, S_EGGGUARD_RUN1}, // S_EGGGUARD_RUN4 + + // Egg Shield for Egg Guard + {SPR_ESHI, 0, 8, {A_EggShield}, 0, 0, S_EGGSHIELD}, // S_EGGSHIELD + + // Green Snapper + {SPR_GSNP, 0, 1, {A_Look}, 0, 0, S_GSNAPPER_STND}, // S_GSNAPPER_STND + {SPR_GSNP, 0, 2, {A_Chase}, 0, 0, S_GSNAPPER2}, // S_GSNAPPER1 + {SPR_GSNP, 1, 2, {A_Chase}, 0, 0, S_GSNAPPER3}, // S_GSNAPPER2 + {SPR_GSNP, 2, 2, {A_Chase}, 0, 0, S_GSNAPPER4}, // S_GSNAPPER3 + {SPR_GSNP, 3, 2, {A_Chase}, 0, 0, S_GSNAPPER1}, // S_GSNAPPER4 + + // Minus + {SPR_NULL, 0, 1, {A_Look}, 0, 0, S_MINUS_STND}, // S_MINUS_STND + {SPR_MNUS, 16, 1, {A_MinusDigging}, 0, 0, S_MINUS_DIGGING}, // S_MINUS_DIGGING + {SPR_MNUS, 0, 1, {A_MinusPopup}, 0, 0, S_MINUS_UPWARD1}, // S_MINUS_POPUP + {SPR_MNUS, 0, 1, {A_MinusCheck}, 0, 0, S_MINUS_UPWARD2}, // S_MINUS_UPWARD1 + {SPR_MNUS, 1, 1, {A_MinusCheck}, 0, 0, S_MINUS_UPWARD3}, // S_MINUS_UPWARD2 + {SPR_MNUS, 2, 1, {A_MinusCheck}, 0, 0, S_MINUS_UPWARD4}, // S_MINUS_UPWARD3 + {SPR_MNUS, 3, 1, {A_MinusCheck}, 0, 0, S_MINUS_UPWARD5}, // S_MINUS_UPWARD4 + {SPR_MNUS, 4, 1, {A_MinusCheck}, 0, 0, S_MINUS_UPWARD6}, // S_MINUS_UPWARD5 + {SPR_MNUS, 5, 1, {A_MinusCheck}, 0, 0, S_MINUS_UPWARD7}, // S_MINUS_UPWARD6 + {SPR_MNUS, 6, 1, {A_MinusCheck}, 0, 0, S_MINUS_UPWARD8}, // S_MINUS_UPWARD7 + {SPR_MNUS, 7, 1, {A_MinusCheck}, 0, 0, S_MINUS_UPWARD1}, // S_MINUS_UPWARD8 + {SPR_MNUS, 8, 1, {A_MinusCheck}, 0, 0, S_MINUS_DOWNWARD2}, // S_MINUS_DOWNWARD1 + {SPR_MNUS, 9, 1, {A_MinusCheck}, 0, 0, S_MINUS_DOWNWARD3}, // S_MINUS_DOWNWARD2 + {SPR_MNUS, 10, 1, {A_MinusCheck}, 0, 0, S_MINUS_DOWNWARD4}, // S_MINUS_DOWNWARD3 + {SPR_MNUS, 11, 1, {A_MinusCheck}, 0, 0, S_MINUS_DOWNWARD5}, // S_MINUS_DOWNWARD4 + {SPR_MNUS, 12, 1, {A_MinusCheck}, 0, 0, S_MINUS_DOWNWARD6}, // S_MINUS_DOWNWARD5 + {SPR_MNUS, 13, 1, {A_MinusCheck}, 0, 0, S_MINUS_DOWNWARD7}, // S_MINUS_DOWNWARD6 + {SPR_MNUS, 14, 1, {A_MinusCheck}, 0, 0, S_MINUS_DOWNWARD8}, // S_MINUS_DOWNWARD7 + {SPR_MNUS, 15, 1, {A_MinusCheck}, 0, 0, S_MINUS_DOWNWARD1}, // S_MINUS_DOWNWARD8 + + // Spring Shell + {SPR_SSHL, 0, 4, {A_Look}, 0, 0, S_SSHELL_STND}, // S_SSHELL_STND + {SPR_SSHL, 0, 4, {A_Chase}, 0, 0, S_SSHELL_RUN2}, // S_SSHELL_RUN1 + {SPR_SSHL, 1, 4, {A_Chase}, 0, 0, S_SSHELL_RUN3}, // S_SSHELL_RUN2 + {SPR_SSHL, 2, 4, {A_Chase}, 0, 0, S_SSHELL_RUN4}, // S_SSHELL_RUN3 + {SPR_SSHL, 3, 4, {A_Chase}, 0, 0, S_SSHELL_RUN1}, // S_SSHELL_RUN4 + {SPR_SSHL, 7, 4, {A_Pain}, 0, 0, S_SSHELL_SPRING2}, // S_SSHELL_SPRING1 + {SPR_SSHL, 6, 1, {NULL}, 0, 0, S_SSHELL_SPRING3}, // S_SSHELL_SPRING2 + {SPR_SSHL, 5, 1, {NULL}, 0, 0, S_SSHELL_SPRING4}, // S_SSHELL_SPRING3 + {SPR_SSHL, 4, 1, {NULL}, 0, 0, S_SSHELL_RUN1}, // S_SSHELL_SPRING4 + + // Spring Shell (yellow) + {SPR_SSHL, 8, 4, {A_Look}, 0, 0, S_YSHELL_STND}, // S_YSHELL_STND + {SPR_SSHL, 8, 4, {A_Chase}, 0, 0, S_YSHELL_RUN2}, // S_YSHELL_RUN1 + {SPR_SSHL, 9, 4, {A_Chase}, 0, 0, S_YSHELL_RUN3}, // S_YSHELL_RUN2 + {SPR_SSHL, 10, 4, {A_Chase}, 0, 0, S_YSHELL_RUN4}, // S_YSHELL_RUN3 + {SPR_SSHL, 11, 4, {A_Chase}, 0, 0, S_YSHELL_RUN1}, // S_YSHELL_RUN4 + {SPR_SSHL, 15, 4, {A_Pain}, 0, 0, S_YSHELL_SPRING2}, // S_YSHELL_SPRING1 + {SPR_SSHL, 14, 1, {NULL}, 0, 0, S_YSHELL_SPRING3}, // S_YSHELL_SPRING2 + {SPR_SSHL, 13, 1, {NULL}, 0, 0, S_YSHELL_SPRING4}, // S_YSHELL_SPRING3 + {SPR_SSHL, 12, 1, {NULL}, 0, 0, S_YSHELL_RUN1}, // S_YSHELL_SPRING4 + + // Unidus + {SPR_UNID, 0, 4, {A_Look}, 0, 0, S_UNIDUS_STND}, // S_UNIDUS_STND + {SPR_UNID, 0, 1, {A_Chase}, 0, 0, S_UNIDUS_RUN }, // S_UNIDUS_RUN + {SPR_UNID, 1, 1, {A_UnidusBall}, 1, 0, S_UNIDUS_BALL}, // S_UNIDUS_BALL + + // Boss Explosion + {SPR_BOM2, FF_FULLBRIGHT, 5, {NULL}, 0, 0, S_BPLD2}, // S_BPLD1 + {SPR_BOM2, FF_FULLBRIGHT+1, 5, {NULL}, 0, 0, S_BPLD3}, // S_BPLD2 + {SPR_BOM2, FF_FULLBRIGHT+2, 5, {NULL}, 0, 0, S_BPLD4}, // S_BPLD3 + {SPR_BOM2, FF_FULLBRIGHT+3, 5, {NULL}, 0, 0, S_BPLD5}, // S_BPLD4 + {SPR_BOM2, FF_FULLBRIGHT+4, 5, {NULL}, 0, 0, S_BPLD6}, // S_BPLD5 + {SPR_BOM2, FF_FULLBRIGHT+5, 5, {NULL}, 0, 0, S_BPLD7}, // S_BPLD6 + {SPR_BOM2, FF_FULLBRIGHT+6, 5, {NULL}, 0, 0, S_NULL}, // S_BPLD7 + + // S3&K Boss Explosion + {SPR_BOM3, FF_FULLBRIGHT, 1, {NULL}, 0, 0, S_SONIC3KBOSSEXPLOSION2}, // S_SONIC3KBOSSEXPLOSION1 + {SPR_BOM3, FF_FULLBRIGHT+1, 1, {NULL}, 0, 0, S_SONIC3KBOSSEXPLOSION3}, // S_SONIC3KBOSSEXPLOSION2 + {SPR_BOM3, FF_FULLBRIGHT+2, 2, {NULL}, 0, 0, S_SONIC3KBOSSEXPLOSION4}, // S_SONIC3KBOSSEXPLOSION3 + {SPR_BOM3, FF_FULLBRIGHT+3, 2, {NULL}, 0, 0, S_SONIC3KBOSSEXPLOSION5}, // S_SONIC3KBOSSEXPLOSION4 + {SPR_BOM3, FF_FULLBRIGHT+4, 3, {NULL}, 0, 0, S_SONIC3KBOSSEXPLOSION6}, // S_SONIC3KBOSSEXPLOSION5 + {SPR_BOM3, FF_FULLBRIGHT+5, 4, {NULL}, 0, 0, S_NULL}, // S_SONIC3KBOSSEXPLOSION6 + + {SPR_JETF, FF_FULLBRIGHT, 1, {NULL}, 0, 0, S_JETFUME2}, // S_JETFUME1 + {SPR_NULL, 0, 1, {NULL}, 0, 0, S_JETFUME1}, // S_JETFUME2 + + // Boss 1 + {SPR_EGGM, 0, 1, {A_Boss1Chase}, 0, 0, S_EGGMOBILE_STND}, // S_EGGMOBILE_STND + {SPR_EGGM, 1, 3, {A_FaceTarget}, 0, 0, S_EGGMOBILE_LATK2}, // S_EGGMOBILE_LATK1 + {SPR_EGGM, 2, 15, {NULL}, 0, 0, S_EGGMOBILE_LATK3}, // S_EGGMOBILE_LATK2 + {SPR_EGGM, 3, 2, {A_FaceTarget}, 0, 0, S_EGGMOBILE_LATK4}, // S_EGGMOBILE_LATK3 + {SPR_EGGM, 4, 1, {NULL}, 0, 0, S_EGGMOBILE_LATK5}, // S_EGGMOBILE_LATK4 + {SPR_EGGM, 5, 1, {NULL}, 0, 0, S_EGGMOBILE_LATK6}, // S_EGGMOBILE_LATK5 + {SPR_EGGM, 6, 1, {NULL}, 0, 0, S_EGGMOBILE_LATK7}, // S_EGGMOBILE_LATK6 + {SPR_EGGM, 7, 1, {NULL}, 0, 0, S_EGGMOBILE_LATK8}, // S_EGGMOBILE_LATK7 + {SPR_EGGM, 8, 45, {A_Boss1Laser}, MT_LASER, 0, S_EGGMOBILE_LATK9}, // S_EGGMOBILE_LATK8 + {SPR_EGGM, 9, 10, {NULL}, 0, 0, S_EGGMOBILE_LATK10}, // S_EGGMOBILE_LATK9 + {SPR_EGGM, 10, 2, {NULL}, 0, 0, S_EGGMOBILE_STND}, // S_EGGMOBILE_LATK10 + {SPR_EGGM, 11, 3, {A_FaceTarget}, 0, 0, S_EGGMOBILE_RATK2}, // S_EGGMOBILE_RATK1 + {SPR_EGGM, 12, 15, {NULL}, 0, 0, S_EGGMOBILE_RATK3}, // S_EGGMOBILE_RATK2 + {SPR_EGGM, 13, 2, {A_FaceTarget}, 0, 0, S_EGGMOBILE_RATK4}, // S_EGGMOBILE_RATK3 + {SPR_EGGM, 14, 1, {NULL}, 0, 0, S_EGGMOBILE_RATK5}, // S_EGGMOBILE_RATK4 + {SPR_EGGM, 15, 1, {NULL}, 0, 0, S_EGGMOBILE_RATK6}, // S_EGGMOBILE_RATK5 + {SPR_EGGM, 16, 1, {NULL}, 0, 0, S_EGGMOBILE_RATK7}, // S_EGGMOBILE_RATK6 + {SPR_EGGM, 17, 1, {NULL}, 0, 0, S_EGGMOBILE_RATK8}, // S_EGGMOBILE_RATK7 + {SPR_EGGM, 18, 45, {A_Boss1Laser}, MT_LASER, 1, S_EGGMOBILE_RATK9}, // S_EGGMOBILE_RATK8 + {SPR_EGGM, 19, 10, {NULL}, 0, 0, S_EGGMOBILE_RATK10}, // S_EGGMOBILE_RATK9 + {SPR_EGGM, 20, 2, {NULL}, 0, 0, S_EGGMOBILE_STND}, // S_EGGMOBILE_RATK10 + {SPR_EGGM, 3, 12, {NULL}, 0, 0, S_EGGMOBILE_PANIC2}, // S_EGGMOBILE_PANIC1 + {SPR_EGGM, 4, 4, {A_Boss1Spikeballs}, 0, 4, S_EGGMOBILE_PANIC3}, // S_EGGMOBILE_PANIC2 + {SPR_EGGM, 3, 5, {NULL}, 0, 0, S_EGGMOBILE_PANIC4}, // S_EGGMOBILE_PANIC3 + {SPR_EGGM, 4, 4, {A_Boss1Spikeballs}, 1, 4, S_EGGMOBILE_PANIC5}, // S_EGGMOBILE_PANIC4 + {SPR_EGGM, 3, 5, {NULL}, 0, 0, S_EGGMOBILE_PANIC6}, // S_EGGMOBILE_PANIC5 + {SPR_EGGM, 4, 4, {A_Boss1Spikeballs}, 2, 4, S_EGGMOBILE_PANIC7}, // S_EGGMOBILE_PANIC6 + {SPR_EGGM, 3, 5, {NULL}, 0, 0, S_EGGMOBILE_PANIC8}, // S_EGGMOBILE_PANIC7 + {SPR_EGGM, 4, 4, {A_Boss1Spikeballs}, 3, 4, S_EGGMOBILE_PANIC9}, // S_EGGMOBILE_PANIC8 + {SPR_EGGM, 3, 5, {NULL}, 0, 0, S_EGGMOBILE_PANIC10},// S_EGGMOBILE_PANIC9 + {SPR_EGGM, 0, 35, {A_SkullAttack}, 0, 0, S_EGGMOBILE_STND}, // S_EGGMOBILE_PANIC10 + {SPR_EGGM, 21, 24, {A_Pain}, 0, 0, S_EGGMOBILE_PAIN2}, // S_EGGMOBILE_PAIN + {SPR_EGGM, 21, 16, {A_SkullAttack}, 1, 1, S_EGGMOBILE_STND}, // S_EGGMOBILE_PAIN2 + {SPR_EGGM, 22, 8, {A_Fall}, 0, 0, S_EGGMOBILE_DIE2}, // S_EGGMOBILE_DIE1 + {SPR_EGGM, 22, 8, {A_BossScream}, 0, 0, S_EGGMOBILE_DIE3}, // S_EGGMOBILE_DIE2 + {SPR_EGGM, 22, 8, {A_BossScream}, 0, 0, S_EGGMOBILE_DIE4}, // S_EGGMOBILE_DIE3 + {SPR_EGGM, 22, 8, {A_BossScream}, 0, 0, S_EGGMOBILE_DIE5}, // S_EGGMOBILE_DIE4 + {SPR_EGGM, 22, 8, {A_BossScream}, 0, 0, S_EGGMOBILE_DIE6}, // S_EGGMOBILE_DIE5 + {SPR_EGGM, 22, 8, {A_BossScream}, 0, 0, S_EGGMOBILE_DIE7}, // S_EGGMOBILE_DIE6 + {SPR_EGGM, 22, 8, {A_BossScream}, 0, 0, S_EGGMOBILE_DIE8}, // S_EGGMOBILE_DIE7 + {SPR_EGGM, 22, 8, {A_BossScream}, 0, 0, S_EGGMOBILE_DIE9}, // S_EGGMOBILE_DIE8 + {SPR_EGGM, 22, 8, {A_BossScream}, 0, 0, S_EGGMOBILE_DIE10}, // S_EGGMOBILE_DIE9 + {SPR_EGGM, 22, 8, {A_BossScream}, 0, 0, S_EGGMOBILE_DIE11}, // S_EGGMOBILE_DIE10 + {SPR_EGGM, 22, 8, {A_BossScream}, 0, 0, S_EGGMOBILE_DIE12}, // S_EGGMOBILE_DIE11 + {SPR_EGGM, 22, 8, {A_BossScream}, 0, 0, S_EGGMOBILE_DIE13}, // S_EGGMOBILE_DIE12 + {SPR_EGGM, 22, 8, {A_BossScream}, 0, 0, S_EGGMOBILE_DIE14}, // S_EGGMOBILE_DIE13 + {SPR_EGGM, 22, -1, {A_BossDeath}, 0, 0, S_NULL}, // S_EGGMOBILE_DIE14 + {SPR_EGGM, 23, 5, {NULL}, 0, 0, S_EGGMOBILE_FLEE2}, // S_EGGMOBILE_FLEE1 + {SPR_EGGM, 24, 5, {NULL}, 0, 0, S_EGGMOBILE_FLEE1}, // S_EGGMOBILE_FLEE2 + {SPR_UNID, 1, 1, {A_UnidusBall}, 2, 0, S_EGGMOBILE_BALL}, // S_EGGMOBILE_BALL + {SPR_NULL, 0, 1, {A_FocusTarget}, 0, 0, S_EGGMOBILE_TARGET}, // S_EGGMOBILE_TARGET + + // Boss 2 + {SPR_EGGN, 0, -1, {NULL}, 0, 0, S_NULL}, // S_EGGMOBILE2_STND + {SPR_EGGN, 1, 4, {NULL}, 0, 0, S_EGGMOBILE2_POGO2}, // S_EGGMOBILE2_POGO1 + {SPR_EGGN, 0, 2, {A_Boss2PogoTarget}, 9*FRACUNIT, 8*FRACUNIT, S_EGGMOBILE2_POGO3}, // S_EGGMOBILE2_POGO2 + {SPR_EGGN, 1, 2, {NULL}, 0, 0, S_EGGMOBILE2_POGO4}, // S_EGGMOBILE2_POGO3 + {SPR_EGGN, 2, -1, {NULL}, 0, 0, S_NULL}, // S_EGGMOBILE2_POGO4 + {SPR_EGGN, 1, 4, {NULL}, 0, 0, S_EGGMOBILE2_POGO6}, // S_EGGMOBILE2_POGO5 + {SPR_EGGN, 0, 2, {A_Boss2PogoTarget}, 7*FRACUNIT, 8*FRACUNIT, S_EGGMOBILE2_POGO7}, // S_EGGMOBILE2_POGO6 + {SPR_EGGN, 1, 2, {NULL}, 0, 0, S_EGGMOBILE2_POGO4}, // S_EGGMOBILE2_POGO7 + {SPR_EGGN, 3, 24, {A_Boss2TakeDamage}, 24+TICRATE, 0, S_EGGMOBILE2_STND}, // S_EGGMOBILE2_PAIN + {SPR_EGGN, 4, 24, {A_Boss2TakeDamage}, 24+TICRATE, 0, S_EGGMOBILE2_POGO4}, // S_EGGMOBILE2_PAIN2 + {SPR_EGGN, 5, 8, {A_Fall}, 0, 0, S_EGGMOBILE2_DIE2}, // S_EGGMOBILE2_DIE1 + {SPR_EGGN, 5, 8, {A_BossScream}, 0, 0, S_EGGMOBILE2_DIE3}, // S_EGGMOBILE2_DIE2 + {SPR_EGGN, 5, 8, {A_BossScream}, 0, 0, S_EGGMOBILE2_DIE4}, // S_EGGMOBILE2_DIE3 + {SPR_EGGN, 5, 8, {A_BossScream}, 0, 0, S_EGGMOBILE2_DIE5}, // S_EGGMOBILE2_DIE4 + {SPR_EGGN, 5, 8, {A_BossScream}, 0, 0, S_EGGMOBILE2_DIE6}, // S_EGGMOBILE2_DIE5 + {SPR_EGGN, 5, 8, {A_BossScream}, 0, 0, S_EGGMOBILE2_DIE7}, // S_EGGMOBILE2_DIE6 + {SPR_EGGN, 5, 8, {A_BossScream}, 0, 0, S_EGGMOBILE2_DIE8}, // S_EGGMOBILE2_DIE7 + {SPR_EGGN, 5, 8, {A_BossScream}, 0, 0, S_EGGMOBILE2_DIE9}, // S_EGGMOBILE2_DIE8 + {SPR_EGGN, 5, 8, {A_BossScream}, 0, 0, S_EGGMOBILE2_DIE10}, // S_EGGMOBILE2_DIE9 + {SPR_EGGN, 5, 8, {A_BossScream}, 0, 0, S_EGGMOBILE2_DIE11}, // S_EGGMOBILE2_DIE10 + {SPR_EGGN, 5, 8, {A_BossScream}, 0, 0, S_EGGMOBILE2_DIE12}, // S_EGGMOBILE2_DIE11 + {SPR_EGGN, 5, 8, {A_BossScream}, 0, 0, S_EGGMOBILE2_DIE13}, // S_EGGMOBILE2_DIE12 + {SPR_EGGN, 5, 8, {A_BossScream}, 0, 0, S_EGGMOBILE2_DIE14}, // S_EGGMOBILE2_DIE13 + {SPR_EGGN, 5, -1, {A_BossDeath}, 0, 0, S_NULL}, // S_EGGMOBILE2_DIE14 + {SPR_EGGN, 6, 5, {NULL}, 0, 0, S_EGGMOBILE2_FLEE2}, // S_EGGMOBILE2_FLEE1 + {SPR_EGGN, 7, 5, {NULL}, 0, 0, S_EGGMOBILE2_FLEE1}, // S_EGGMOBILE2_FLEE2 + + {SPR_TNKA, 0, 35, {NULL}, 0, 0, S_NULL}, // S_BOSSTANK1 + {SPR_TNKB, 0, 35, {NULL}, 0, 0, S_NULL}, // S_BOSSTANK2 + {SPR_SPNK, 0, 35, {NULL}, 0, 0, S_NULL}, // S_BOSSSPIGOT + + // Boss 2 Goop + {SPR_GOOP, 0, 2, {NULL}, 0, 0, S_GOOP2}, // S_GOOP1 + {SPR_GOOP, 1, 2, {NULL}, 0, 0, S_GOOP1}, // S_GOOP2 + {SPR_GOOP, 2,-1, {NULL}, 0, 0, S_NULL}, // S_GOOP3 + + // Boss 3 + {SPR_EGGO, 0, 1, {NULL}, 0, 0, S_EGGMOBILE3_STND}, // S_EGGMOBILE3_STND + {SPR_EGGO, 1, 2, {NULL}, 0, 0, S_EGGMOBILE3_ATK2}, // S_EGGMOBILE3_ATK1 + {SPR_EGGO, 2, 2, {NULL}, 0, 0, S_EGGMOBILE3_ATK3A}, // S_EGGMOBILE3_ATK2 + {SPR_EGGO, 3, 2, {A_BossFireShot}, MT_TORPEDO, 2, S_EGGMOBILE3_ATK3B}, // S_EGGMOBILE3_ATK3A + {SPR_EGGO, 3, 2, {A_BossFireShot}, MT_TORPEDO, 4, S_EGGMOBILE3_ATK3C}, // S_EGGMOBILE3_ATK3B + {SPR_EGGO, 3, 2, {A_BossFireShot}, MT_TORPEDO, 3, S_EGGMOBILE3_ATK3D}, // S_EGGMOBILE3_ATK3C + {SPR_EGGO, 3, 2, {A_BossFireShot}, MT_TORPEDO, 5, S_EGGMOBILE3_ATK4}, // S_EGGMOBILE3_ATK3D + {SPR_EGGO, 4, 2, {NULL}, 0, 0, S_EGGMOBILE3_ATK5}, // S_EGGMOBILE3_ATK4 + {SPR_EGGO, 5, 2, {NULL}, 0, 0, S_EGGMOBILE3_LAUGH1}, // S_EGGMOBILE3_ATK5 + {SPR_EGGO, 6, 4, {NULL}, 0, 0, S_EGGMOBILE3_LAUGH2}, // S_EGGMOBILE3_LAUGH1 + {SPR_EGGO, 7, 4, {NULL}, 0, 0, S_EGGMOBILE3_LAUGH3}, // S_EGGMOBILE3_LAUGH2 + {SPR_EGGO, 6, 4, {NULL}, 0, 0, S_EGGMOBILE3_LAUGH4}, // S_EGGMOBILE3_LAUGH3 + {SPR_EGGO, 7, 4, {NULL}, 0, 0, S_EGGMOBILE3_LAUGH5}, // S_EGGMOBILE3_LAUGH4 + {SPR_EGGO, 6, 4, {NULL}, 0, 0, S_EGGMOBILE3_LAUGH6}, // S_EGGMOBILE3_LAUGH5 + {SPR_EGGO, 7, 4, {NULL}, 0, 0, S_EGGMOBILE3_LAUGH7}, // S_EGGMOBILE3_LAUGH6 + {SPR_EGGO, 6, 4, {NULL}, 0, 0, S_EGGMOBILE3_LAUGH8}, // S_EGGMOBILE3_LAUGH7 + {SPR_EGGO, 7, 4, {NULL}, 0, 0, S_EGGMOBILE3_LAUGH9}, // S_EGGMOBILE3_LAUGH8 + {SPR_EGGO, 6, 4, {NULL}, 0, 0, S_EGGMOBILE3_LAUGH10}, // S_EGGMOBILE3_LAUGH9 + {SPR_EGGO, 7, 4, {NULL}, 0, 0, S_EGGMOBILE3_LAUGH11}, // S_EGGMOBILE3_LAUGH10 + {SPR_EGGO, 6, 4, {NULL}, 0, 0, S_EGGMOBILE3_LAUGH12}, // S_EGGMOBILE3_LAUGH11 + {SPR_EGGO, 7, 4, {NULL}, 0, 0, S_EGGMOBILE3_LAUGH13}, // S_EGGMOBILE3_LAUGH12 + {SPR_EGGO, 6, 4, {NULL}, 0, 0, S_EGGMOBILE3_LAUGH14}, // S_EGGMOBILE3_LAUGH13 + {SPR_EGGO, 7, 4, {NULL}, 0, 0, S_EGGMOBILE3_LAUGH15}, // S_EGGMOBILE3_LAUGH14 + {SPR_EGGO, 6, 4, {NULL}, 0, 0, S_EGGMOBILE3_LAUGH16}, // S_EGGMOBILE3_LAUGH15 + {SPR_EGGO, 7, 4, {NULL}, 0, 0, S_EGGMOBILE3_LAUGH17}, // S_EGGMOBILE3_LAUGH16 + {SPR_EGGO, 6, 4, {NULL}, 0, 0, S_EGGMOBILE3_LAUGH18}, // S_EGGMOBILE3_LAUGH17 + {SPR_EGGO, 7, 4, {NULL}, 0, 0, S_EGGMOBILE3_LAUGH19}, // S_EGGMOBILE3_LAUGH18 + {SPR_EGGO, 6, 4, {NULL}, 0, 0, S_EGGMOBILE3_LAUGH20}, // S_EGGMOBILE3_LAUGH19 + {SPR_EGGO, 7, 4, {NULL}, 0, 0, S_EGGMOBILE3_STND}, // S_EGGMOBILE3_LAUGH20 + {SPR_EGGO, 8, 1, {A_Boss3TakeDamage}, 0, 0, S_EGGMOBILE3_PAIN2}, // S_EGGMOBILE3_PAIN + {SPR_EGGO, 8, 23, {A_Pain}, 0, 0, S_EGGMOBILE3_STND}, // S_EGGMOBILE3_PAIN2 + {SPR_EGGO, 9, 8, {A_Fall}, 0, 0, S_EGGMOBILE3_DIE2}, // S_EGGMOBILE3_DIE1 + {SPR_EGGO, 9, 8, {A_BossScream}, 0, 0, S_EGGMOBILE3_DIE3}, // S_EGGMOBILE3_DIE2 + {SPR_EGGO, 9, 8, {A_BossScream}, 0, 0, S_EGGMOBILE3_DIE4}, // S_EGGMOBILE3_DIE3 + {SPR_EGGO, 9, 8, {A_BossScream}, 0, 0, S_EGGMOBILE3_DIE5}, // S_EGGMOBILE3_DIE4 + {SPR_EGGO, 9, 8, {A_BossScream}, 0, 0, S_EGGMOBILE3_DIE6}, // S_EGGMOBILE3_DIE5 + {SPR_EGGO, 9, 8, {A_BossScream}, 0, 0, S_EGGMOBILE3_DIE7}, // S_EGGMOBILE3_DIE6 + {SPR_EGGO, 9, 8, {A_BossScream}, 0, 0, S_EGGMOBILE3_DIE8}, // S_EGGMOBILE3_DIE7 + {SPR_EGGO, 9, 8, {A_BossScream}, 0, 0, S_EGGMOBILE3_DIE9}, // S_EGGMOBILE3_DIE8 + {SPR_EGGO, 9, 8, {A_BossScream}, 0, 0, S_EGGMOBILE3_DIE10}, // S_EGGMOBILE3_DIE9 + {SPR_EGGO, 9, 8, {A_BossScream}, 0, 0, S_EGGMOBILE3_DIE11}, // S_EGGMOBILE3_DIE10 + {SPR_EGGO, 9, 8, {A_BossScream}, 0, 0, S_EGGMOBILE3_DIE12}, // S_EGGMOBILE3_DIE11 + {SPR_EGGO, 9, 8, {A_BossScream}, 0, 0, S_EGGMOBILE3_DIE13}, // S_EGGMOBILE3_DIE12 + {SPR_EGGO, 9, 8, {A_BossScream}, 0, 0, S_EGGMOBILE3_DIE14}, // S_EGGMOBILE3_DIE13 + {SPR_EGGO, 9, -1, {A_BossDeath}, 0, 0, S_NULL}, // S_EGGMOBILE3_DIE14 + {SPR_EGGO, 10, 5, {NULL}, 0, 0, S_EGGMOBILE3_FLEE2}, // S_EGGMOBILE3_FLEE1 + {SPR_EGGO, 11, 5, {A_BossScream}, 0, 0, S_EGGMOBILE3_FLEE1}, // S_EGGMOBILE3_FLEE2 + + // Boss 3 Propeller + {SPR_PRPL, 0, 1, {NULL}, 0, 0, S_PROPELLER2}, // S_PROPELLER1 + {SPR_PRPL, 1, 1, {NULL}, 0, 0, S_PROPELLER3}, // S_PROPELLER2 + {SPR_PRPL, 2, 1, {NULL}, 0, 0, S_PROPELLER4}, // S_PROPELLER3 + {SPR_PRPL, 3, 1, {NULL}, 0, 0, S_PROPELLER5}, // S_PROPELLER4 + {SPR_PRPL, 4, 1, {NULL}, 0, 0, S_PROPELLER6}, // S_PROPELLER5 + {SPR_PRPL, 5, 1, {NULL}, 0, 0, S_PROPELLER7}, // S_PROPELLER6 + {SPR_PRPL, 6, 1, {NULL}, 0, 0, S_PROPELLER1}, // S_PROPELLER7 + + // Boss 3 Pinch + {SPR_FAKE, 0, 1, {A_BossJetFume}, 1, 0, S_FAKEMOBILE}, // S_FAKEMOBILE_INIT + {SPR_FAKE, 0, 1, {A_Boss3Path}, 0, 0, S_FAKEMOBILE}, // S_FAKEMOBILE + {SPR_FAKE, 0, 2, {NULL}, 0, 0, S_FAKEMOBILE_ATK2}, // S_FAKEMOBILE_ATK1 + {SPR_FAKE, 0, 2, {NULL}, 0, 0, S_FAKEMOBILE_ATK3A}, // S_FAKEMOBILE_ATK2 + {SPR_FAKE, 0, 2, {A_BossFireShot}, MT_TORPEDO2, 2, S_FAKEMOBILE_ATK3B}, // S_FAKEMOBILE_ATK3A + {SPR_FAKE, 0, 2, {A_BossFireShot}, MT_TORPEDO2, 4, S_FAKEMOBILE_ATK3C}, // S_FAKEMOBILE_ATK3B + {SPR_FAKE, 0, 2, {A_BossFireShot}, MT_TORPEDO2, 3, S_FAKEMOBILE_ATK3D}, // S_FAKEMOBILE_ATK3C + {SPR_FAKE, 0, 2, {A_BossFireShot}, MT_TORPEDO2, 5, S_FAKEMOBILE_ATK4}, // S_FAKEMOBILE_ATK3D + {SPR_FAKE, 0, 2, {NULL}, 0, 0, S_FAKEMOBILE_ATK5}, // S_FAKEMOBILE_ATK4 + {SPR_FAKE, 0, 2, {NULL}, 0, 0, S_FAKEMOBILE}, // S_FAKEMOBILE_ATK5 + + // Boss 4 + {SPR_EGGP, 0, -1, {NULL}, 0, 0, S_NULL}, // S_EGGMOBILE4_STND + {SPR_EGGP, 1, 3, {NULL}, 0, 0, S_EGGMOBILE4_LATK2}, // S_EGGMOBILE4_LATK1 + {SPR_EGGP, 2, 15, {NULL}, 0, 0, S_EGGMOBILE4_LATK3}, // S_EGGMOBILE4_LATK2 + {SPR_EGGP, 3, 2, {NULL}, 0, 0, S_EGGMOBILE4_LATK4}, // S_EGGMOBILE4_LATK3 + {SPR_EGGP, 4, 4, {NULL}, 0, 0, S_EGGMOBILE4_LATK5}, // S_EGGMOBILE4_LATK4 + {SPR_EGGP, 4, 50, {A_Boss4Reverse}, sfx_mswing, 0, S_EGGMOBILE4_LATK6}, // S_EGGMOBILE4_LATK5 + {SPR_EGGP, 5, 2, {NULL}, 0, 0, S_EGGMOBILE4_STND}, // S_EGGMOBILE4_LATK6 + {SPR_EGGP, 6, 3, {NULL}, 0, 0, S_EGGMOBILE4_RATK2}, // S_EGGMOBILE4_RATK1 + {SPR_EGGP, 7, 15, {NULL}, 0, 0, S_EGGMOBILE4_RATK3}, // S_EGGMOBILE4_RATK2 + {SPR_EGGP, 8, 2, {NULL}, 0, 0, S_EGGMOBILE4_RATK4}, // S_EGGMOBILE4_RATK3 + {SPR_EGGP, 9, 4, {NULL}, 0, 0, S_EGGMOBILE4_RATK5}, // S_EGGMOBILE4_RATK4 + {SPR_EGGP, 9,150, {A_Boss4SpeedUp}, sfx_mswing, 0, S_EGGMOBILE4_RATK6}, // S_EGGMOBILE4_RATK5 + {SPR_EGGP,10, 2, {NULL}, 0, 0, S_EGGMOBILE4_STND}, // S_EGGMOBILE4_RATK6 + {SPR_EGGP, 0, 20, {A_Boss4Raise}, sfx_doord1, 0, S_EGGMOBILE4_RAISE2}, // S_EGGMOBILE4_RAISE1 + {SPR_EGGP,13, 10, {NULL}, 0, 0, S_EGGMOBILE4_RAISE3}, // S_EGGMOBILE4_RAISE2 + {SPR_EGGP,14, 10, {NULL}, 0, 0, S_EGGMOBILE4_RAISE4}, // S_EGGMOBILE4_RAISE3 + {SPR_EGGP,13, 10, {NULL}, 0, 0, S_EGGMOBILE4_RAISE5}, // S_EGGMOBILE4_RAISE4 + {SPR_EGGP,14, 10, {NULL}, 0, 0, S_EGGMOBILE4_RAISE6}, // S_EGGMOBILE4_RAISE5 + {SPR_EGGP,13, 10, {NULL}, 0, 0, S_EGGMOBILE4_RAISE7}, // S_EGGMOBILE4_RAISE6 + {SPR_EGGP,14, 10, {NULL}, 0, 0, S_EGGMOBILE4_RAISE8}, // S_EGGMOBILE4_RAISE7 + {SPR_EGGP,13, 10, {NULL}, 0, 0, S_EGGMOBILE4_RAISE9}, // S_EGGMOBILE4_RAISE8 + {SPR_EGGP,14, 10, {NULL}, 0, 0, S_EGGMOBILE4_RAISE10},// S_EGGMOBILE4_RAISE9 + {SPR_EGGP,13, 10, {NULL}, 0, 0, S_EGGMOBILE4_STND}, // S_EGGMOBILE4_RAISE10 + {SPR_EGGP,11, 24, {A_Pain}, 0, 0, S_EGGMOBILE4_STND}, // S_EGGMOBILE4_PAIN + {SPR_EGGP,12, 8, {A_Fall}, 0, 0, S_EGGMOBILE4_DIE2}, // S_EGGMOBILE4_DIE1 + {SPR_EGGP,12, 8, {A_BossScream}, 0, 0, S_EGGMOBILE4_DIE3}, // S_EGGMOBILE4_DIE2 + {SPR_EGGP,12, 8, {A_BossScream}, 0, 0, S_EGGMOBILE4_DIE4}, // S_EGGMOBILE4_DIE3 + {SPR_EGGP,12, 8, {A_BossScream}, 0, 0, S_EGGMOBILE4_DIE5}, // S_EGGMOBILE4_DIE4 + {SPR_EGGP,12, 8, {A_BossScream}, 0, 0, S_EGGMOBILE4_DIE6}, // S_EGGMOBILE4_DIE5 + {SPR_EGGP,12, 8, {A_BossScream}, 0, 0, S_EGGMOBILE4_DIE7}, // S_EGGMOBILE4_DIE6 + {SPR_EGGP,12, 8, {A_BossScream}, 0, 0, S_EGGMOBILE4_DIE8}, // S_EGGMOBILE4_DIE7 + {SPR_EGGP,12, 8, {A_BossScream}, 0, 0, S_EGGMOBILE4_DIE9}, // S_EGGMOBILE4_DIE8 + {SPR_EGGP,12, 8, {A_BossScream}, 0, 0, S_EGGMOBILE4_DIE10}, // S_EGGMOBILE4_DIE9 + {SPR_EGGP,12, 8, {A_BossScream}, 0, 0, S_EGGMOBILE4_DIE11}, // S_EGGMOBILE4_DIE10 + {SPR_EGGP,12, 8, {A_BossScream}, 0, 0, S_EGGMOBILE4_DIE12}, // S_EGGMOBILE4_DIE11 + {SPR_EGGP,12, 8, {A_BossScream}, 0, 0, S_EGGMOBILE4_DIE13}, // S_EGGMOBILE4_DIE12 + {SPR_EGGP,12, 8, {A_BossScream}, 0, 0, S_EGGMOBILE4_DIE14}, // S_EGGMOBILE4_DIE13 + {SPR_EGGP,12, -1, {A_BossDeath}, 0, 0, S_NULL}, // S_EGGMOBILE4_DIE14 + {SPR_EGGP,13, 5, {NULL}, 0, 0, S_EGGMOBILE4_FLEE2}, // S_EGGMOBILE4_FLEE1 + {SPR_EGGP,14, 5, {NULL}, 0, 0, S_EGGMOBILE4_FLEE1}, // S_EGGMOBILE4_FLEE2 + {SPR_BMCE, 0, -1, {NULL}, 0, 0, S_NULL}, // S_EGGMOBILE4_MACE + + // Boss 4 Jet flame + {SPR_EFIR, FF_FULLBRIGHT, 1, {NULL}, 0, 0, S_JETFLAME2}, // S_JETFLAME1 + {SPR_EFIR, FF_FULLBRIGHT+1, 1, {NULL}, 0, 0, S_JETFLAME1}, // S_JETFLAME2 + + {SPR_BRAK, 0, 1, {A_SetReactionTime}, 0, 0, S_BLACKEGG_STND2}, // S_BLACKEGG_STND + {SPR_BRAK, 0, 7, {A_Look}, 1, 0, S_BLACKEGG_STND2}, // S_BLACKEGG_STND2 + {SPR_BRAK, 1, 7, {NULL}, 0, 0, S_BLACKEGG_WALK2}, // S_BLACKEGG_WALK1 + {SPR_BRAK, 2, 7, {NULL}, 0, 0, S_BLACKEGG_WALK3}, // S_BLACKEGG_WALK2 + {SPR_BRAK, 3, 7, {A_PlaySound}, sfx_bestep, 0, S_BLACKEGG_WALK4}, // S_BLACKEGG_WALK3 + {SPR_BRAK, 4, 7, {NULL}, 0, 0, S_BLACKEGG_WALK5}, // S_BLACKEGG_WALK4 + {SPR_BRAK, 5, 7, {NULL}, 0, 0, S_BLACKEGG_WALK6}, // S_BLACKEGG_WALK5 + {SPR_BRAK, 6, 7, {A_PlaySound}, sfx_bestp2, 0, S_BLACKEGG_WALK1}, // S_BLACKEGG_WALK6 + {SPR_BRAK, 7, 3, {NULL}, 0, 0, S_BLACKEGG_SHOOT2}, // S_BLACKEGG_SHOOT1 + {SPR_BRAK, 24, 1, {A_PlaySound}, sfx_befire, 0, S_BLACKEGG_SHOOT1}, // S_BLACKEGG_SHOOT2 + + {SPR_BRAK, 8, 1, {NULL}, 0, 0, S_BLACKEGG_PAIN2}, // S_BLACKEGG_PAIN1 + {SPR_BRAK, 25, 1, {NULL}, 0, 0, S_BLACKEGG_PAIN3}, // S_BLACKEGG_PAIN2 + {SPR_BRAK, 8, 1, {NULL}, 0, 0, S_BLACKEGG_PAIN4}, // S_BLACKEGG_PAIN3 + {SPR_BRAK, 25, 1, {NULL}, 0, 0, S_BLACKEGG_PAIN5}, // S_BLACKEGG_PAIN4 + {SPR_BRAK, 8, 1, {NULL}, 0, 0, S_BLACKEGG_PAIN6}, // S_BLACKEGG_PAIN5 + {SPR_BRAK, 25, 1, {NULL}, 0, 0, S_BLACKEGG_PAIN7}, // S_BLACKEGG_PAIN6 + {SPR_BRAK, 8, 1, {NULL}, 0, 0, S_BLACKEGG_PAIN8}, // S_BLACKEGG_PAIN7 + {SPR_BRAK, 25, 1, {NULL}, 0, 0, S_BLACKEGG_PAIN9}, // S_BLACKEGG_PAIN8 + {SPR_BRAK, 8, 1, {NULL}, 0, 0, S_BLACKEGG_PAIN10}, // S_BLACKEGG_PAIN9 + {SPR_BRAK, 25, 1, {NULL}, 0, 0, S_BLACKEGG_PAIN11}, // S_BLACKEGG_PAIN10 + {SPR_BRAK, 8, 1, {NULL}, 0, 0, S_BLACKEGG_PAIN12}, // S_BLACKEGG_PAIN11 + {SPR_BRAK, 25, 1, {NULL}, 0, 0, S_BLACKEGG_PAIN13}, // S_BLACKEGG_PAIN12 + {SPR_BRAK, 8, 1, {NULL}, 0, 0, S_BLACKEGG_PAIN14}, // S_BLACKEGG_PAIN13 + {SPR_BRAK, 25, 1, {NULL}, 0, 0, S_BLACKEGG_PAIN15}, // S_BLACKEGG_PAIN14 + {SPR_BRAK, 8, 1, {NULL}, 0, 0, S_BLACKEGG_PAIN16}, // S_BLACKEGG_PAIN15 + {SPR_BRAK, 25, 1, {NULL}, 0, 0, S_BLACKEGG_PAIN17}, // S_BLACKEGG_PAIN16 + {SPR_BRAK, 8, 1, {NULL}, 0, 0, S_BLACKEGG_PAIN18}, // S_BLACKEGG_PAIN17 + {SPR_BRAK, 25, 1, {NULL}, 0, 0, S_BLACKEGG_PAIN19}, // S_BLACKEGG_PAIN18 + {SPR_BRAK, 8, 1, {NULL}, 0, 0, S_BLACKEGG_PAIN20}, // S_BLACKEGG_PAIN19 + {SPR_BRAK, 25, 1, {NULL}, 0, 0, S_BLACKEGG_PAIN21}, // S_BLACKEGG_PAIN20 + {SPR_BRAK, 8, 1, {NULL}, 0, 0, S_BLACKEGG_PAIN22}, // S_BLACKEGG_PAIN21 + {SPR_BRAK, 25, 1, {NULL}, 0, 0, S_BLACKEGG_PAIN23}, // S_BLACKEGG_PAIN22 + {SPR_BRAK, 8, 1, {NULL}, 0, 0, S_BLACKEGG_PAIN24}, // S_BLACKEGG_PAIN23 + {SPR_BRAK, 25, 1, {NULL}, 0, 0, S_BLACKEGG_PAIN25}, // S_BLACKEGG_PAIN24 + {SPR_BRAK, 8, 1, {NULL}, 0, 0, S_BLACKEGG_PAIN26}, // S_BLACKEGG_PAIN25 + {SPR_BRAK, 25, 1, {NULL}, 0, 0, S_BLACKEGG_PAIN27}, // S_BLACKEGG_PAIN26 + {SPR_BRAK, 8, 1, {NULL}, 0, 0, S_BLACKEGG_PAIN28}, // S_BLACKEGG_PAIN27 + {SPR_BRAK, 25, 1, {NULL}, 0, 0, S_BLACKEGG_PAIN29}, // S_BLACKEGG_PAIN28 + {SPR_BRAK, 8, 1, {NULL}, 0, 0, S_BLACKEGG_PAIN30}, // S_BLACKEGG_PAIN29 + {SPR_BRAK, 25, 1, {NULL}, 0, 0, S_BLACKEGG_PAIN31}, // S_BLACKEGG_PAIN30 + {SPR_BRAK, 8, 1, {NULL}, 0, 0, S_BLACKEGG_PAIN32}, // S_BLACKEGG_PAIN31 + {SPR_BRAK, 25, 1, {NULL}, 0, 0, S_BLACKEGG_PAIN33}, // S_BLACKEGG_PAIN32 + {SPR_BRAK, 8, 1, {NULL}, 0, 0, S_BLACKEGG_PAIN34}, // S_BLACKEGG_PAIN33 + {SPR_BRAK, 25, 1, {NULL}, 0, 0, S_BLACKEGG_PAIN35}, // S_BLACKEGG_PAIN34 + {SPR_BRAK, 8, 1, {NULL}, 0, 0, S_BLACKEGG_WALK1}, // S_BLACKEGG_PAIN35 + + {SPR_BRAK, 9, 20, {NULL}, 0, 0, S_BLACKEGG_HITFACE2}, // S_BLACKEGG_HITFACE1 + {SPR_BRAK, 10, 2, {NULL}, 0, 0, S_BLACKEGG_HITFACE3}, // S_BLACKEGG_HITFACE2 + {SPR_BRAK, 11, 2, {NULL}, 0, 0, S_BLACKEGG_HITFACE4}, // S_BLACKEGG_HITFACE3 + {SPR_BRAK, 12,14, {NULL}, 0, 0, S_BLACKEGG_PAIN1}, // S_BLACKEGG_HITFACE4 + + {SPR_BRAK, 13, 14, {NULL}, 0, 0, S_BLACKEGG_DIE2}, // S_BLACKEGG_DIE1 + {SPR_BRAK, 14, 7, {NULL}, 0, 0, S_BLACKEGG_DIE3}, // S_BLACKEGG_DIE2 + {SPR_BRAK, 15, 5, {NULL}, 0, 0, S_BLACKEGG_DIE4}, // S_BLACKEGG_DIE3 + {SPR_BRAK, 16, 3, {A_PlaySound}, sfx_bgxpld, 0, S_BLACKEGG_DIE5}, // S_BLACKEGG_DIE4 + {SPR_BRAK, 17, -1, {NULL}, 0, 0, S_BLACKEGG_DIE5}, // S_BLACKEGG_DIE5 + + {SPR_BRAK, 18, 14, {NULL}, 0, 0, S_BLACKEGG_MISSILE2}, // S_BLACKEGG_MISSILE1 + {SPR_BRAK, 19, 5, {NULL}, 0, 0, S_BLACKEGG_MISSILE3}, // S_BLACKEGG_MISSILE2 + {SPR_BRAK, 20, 35, {A_Boss7FireMissiles}, MT_BLACKEGGMAN_MISSILE, sfx_beshot, S_BLACKEGG_JUMP1}, // S_BLACKEGG_MISSILE3 + + {SPR_BRAK, 21, -1, {NULL}, 0, 0, S_BLACKEGG_STND}, // S_BLACKEGG_GOOP + + {SPR_BRAK, 22, 14, {A_PlaySound}, sfx_belnch, 0, S_BLACKEGG_JUMP2}, // S_BLACKEGG_JUMP1 + {SPR_BRAK, 23, -1, {NULL}, 0, 0, S_BLACKEGG_WALK1}, // S_BLACKEGG_JUMP2 + + {SPR_BRAK, 21, 3*TICRATE, {NULL}, 0, 0, S_BLACKEGG_DESTROYPLAT2}, // S_BLACKEGG_DESTROYPLAT1 + {SPR_BRAK, 21, 1, {A_PlaySound}, sfx_s3k54, 0, S_BLACKEGG_DESTROYPLAT3}, // S_BLACKEGG_DESTROYPLAT2 + {SPR_BRAK, 21, 14, {A_LinedefExecute}, 4200, 0, S_BLACKEGG_STND}, // S_BLACKEGG_DESTROYPLAT3 + + {SPR_NULL, 0, 1, {A_CapeChase}, (160 - 20) << 16, 0, S_BLACKEGG_HELPER}, // S_BLACKEGG_HELPER + + {SPR_BGOO, 0, 2, {NULL}, 0, 0, S_BLACKEGG_GOOP2}, // S_BLACKEGG_GOOP1 + {SPR_BGOO, 1, 2, {NULL}, 0, 0, S_BLACKEGG_GOOP1}, // S_BLACKEGG_GOOP2 + {SPR_BGOO, 2, 6*TICRATE, {A_GoopSplat}, 0, 0, S_BLACKEGG_GOOP4}, // S_BLACKEGG_GOOP3 + {SPR_BGOO, 2, 4, {NULL}, 0, 0, S_BLACKEGG_GOOP5}, // S_BLACKEGG_GOOP4 + {SPR_BGOO, 2, 4, {NULL}, 0, 0, S_BLACKEGG_GOOP6}, // S_BLACKEGG_GOOP5 + {SPR_BGOO, 2, 4, {NULL}, 0, 0, S_BLACKEGG_GOOP7}, // S_BLACKEGG_GOOP6 + {SPR_BGOO, 2, 4, {NULL}, 0, 0, S_NULL}, // S_BLACKEGG_GOOP7 + + {SPR_BMSL, 0, 1, {NULL}, 0, 0, S_BLACKEGG_MISSILE}, // S_BLACKEGG_MISSILE + + // New Very-Last-Minute 2.1 Brak Eggman (Cy-Brak-demon) + {SPR_BRAK, 0, 10, {A_Look}, 0, 0, S_CYBRAKDEMON_IDLE}, // S_CYBRAKDEMON_IDLE + {SPR_BRAK, 1, 8, {A_BrakChase}, 3, 0, S_CYBRAKDEMON_WALK2}, // S_CYBRAKDEMON_WALK1 + {SPR_BRAK, 2, 8, {A_BrakChase}, 3, 0, S_CYBRAKDEMON_WALK3}, // S_CYBRAKDEMON_WALK2 + {SPR_BRAK, 3, 8, {A_BrakChase}, 3, sfx_bestep, S_CYBRAKDEMON_WALK4}, // S_CYBRAKDEMON_WALK3 + {SPR_BRAK, 4, 8, {A_BrakChase}, 3, 0, S_CYBRAKDEMON_WALK5}, // S_CYBRAKDEMON_WALK4 + {SPR_BRAK, 5, 8, {A_BrakChase}, 3, 0, S_CYBRAKDEMON_WALK6}, // S_CYBRAKDEMON_WALK5 + {SPR_BRAK, 6, 8, {A_BrakChase}, 3, sfx_bestp2, S_CYBRAKDEMON_WALK1}, // S_CYBRAKDEMON_WALK6 + {SPR_BRAK, 7, 6, {A_RandomState}, S_CYBRAKDEMON_MISSILE_ATTACK1, S_CYBRAKDEMON_FLAME_ATTACK1, S_CYBRAKDEMON_MISSILE_ATTACK1}, // S_CYBRAKDEMON_CHOOSE_ATTACK1 + {SPR_BRAK, 7, 6, {A_FaceTarget}, 0, 0, S_CYBRAKDEMON_MISSILE_ATTACK2}, // S_CYBRAKDEMON_MISSILE_ATTACK1 // Aim + {SPR_BRAK, 26 + FF_FULLBRIGHT, 12, {A_BrakFireShot}, MT_CYBRAKDEMON_MISSILE, 128, S_CYBRAKDEMON_MISSILE_ATTACK3}, // S_CYBRAKDEMON_MISSILE_ATTACK2 // Fire + {SPR_BRAK, 7, 12, {A_FaceTarget}, 0, 0, S_CYBRAKDEMON_MISSILE_ATTACK4}, // S_CYBRAKDEMON_MISSILE_ATTACK3 // Aim + {SPR_BRAK, 26 + FF_FULLBRIGHT, 12, {A_BrakFireShot}, MT_CYBRAKDEMON_MISSILE, 128, S_CYBRAKDEMON_MISSILE_ATTACK5}, // S_CYBRAKDEMON_MISSILE_ATTACK4 // Fire + {SPR_BRAK, 7, 12, {A_FaceTarget}, 0, 0, S_CYBRAKDEMON_MISSILE_ATTACK6}, // S_CYBRAKDEMON_MISSILE_ATTACK5 // Aim + {SPR_BRAK, 26 + FF_FULLBRIGHT, 12, {A_BrakFireShot}, MT_CYBRAKDEMON_MISSILE, 128, S_CYBRAKDEMON_FINISH_ATTACK1}, // S_CYBRAKDEMON_MISSILE_ATTACK6 // Fire + {SPR_BRAK, 7, 1, {A_Repeat}, 1, S_CYBRAKDEMON_FLAME_ATTACK1, S_CYBRAKDEMON_FLAME_ATTACK2}, // S_CYBRAKDEMON_FLAME_ATTACK1 // Reset + {SPR_BRAK, 7, 6, {A_FaceTarget}, 0, 0, S_CYBRAKDEMON_FLAME_ATTACK3}, // S_CYBRAKDEMON_FLAME_ATTACK2 // Aim + {SPR_BRAK, 26 + FF_FULLBRIGHT, 2, {A_BrakFireShot}, MT_CYBRAKDEMON_FLAMESHOT, 128, S_CYBRAKDEMON_FLAME_ATTACK4}, // S_CYBRAKDEMON_FLAME_ATTACK3 // Fire + {SPR_BRAK, 7, 1, {A_Repeat}, 30, S_CYBRAKDEMON_FLAME_ATTACK3, S_CYBRAKDEMON_FINISH_ATTACK1}, // S_CYBRAKDEMON_FLAME_ATTACK4 // Loop + {SPR_BRAK, 0, 6, {A_RandomState}, S_CYBRAKDEMON_VILE_ATTACK1, S_CYBRAKDEMON_NAPALM_ATTACK1, S_CYBRAKDEMON_MISSILE_ATTACK1}, // S_CYBRAKDEMON_CHOOSE_ATTACK2 + {SPR_BRAK, 20, 0, {A_LinedefExecute}, LE_BRAKVILEATACK, 0, S_CYBRAKDEMON_VILE_ATTACK2}, // S_CYBRAKDEMON_VILE_ATTACK1 + {SPR_BRAK, 20, 24, {A_VileTarget}, MT_CYBRAKDEMON_TARGET_RETICULE, 1, S_CYBRAKDEMON_VILE_ATTACK3}, // S_CYBRAKDEMON_VILE_ATTACK2 + {SPR_BRAK, 19, 8, {A_FaceTarget}, 0, 0, S_CYBRAKDEMON_VILE_ATTACK4}, // S_CYBRAKDEMON_VILE_ATTACK3 + {SPR_BRAK, 18, 8, {A_FaceTarget}, 0, 0, S_CYBRAKDEMON_VILE_ATTACK5}, // S_CYBRAKDEMON_VILE_ATTACK4 + {SPR_BRAK, 8, 32, {A_FaceTarget}, 0, 0, S_CYBRAKDEMON_VILE_ATTACK6}, // S_CYBRAKDEMON_VILE_ATTACK5 + {SPR_BRAK, 20 + FF_FULLBRIGHT, 28, {A_VileAttack}, sfx_brakrx, MT_CYBRAKDEMON_VILE_EXPLOSION + (1<<16), S_CYBRAKDEMON_FINISH_ATTACK1}, // S_CYBRAKDEMON_VILE_ATTACK6 + {SPR_BRAK, 0, 6, {A_FaceTarget}, 0, 0, S_CYBRAKDEMON_NAPALM_ATTACK2}, // S_CYBRAKDEMON_NAPALM_ATTACK1 + {SPR_BRAK, 21 + FF_FULLBRIGHT, 8, {A_BrakLobShot}, MT_CYBRAKDEMON_NAPALM_BOMB_LARGE, 96, S_CYBRAKDEMON_NAPALM_ATTACK3}, // S_CYBRAKDEMON_NAPALM_ATTACK2 + {SPR_BRAK, 0, 8, {A_FaceTarget}, 0, 0, S_CYBRAKDEMON_FINISH_ATTACK1}, // S_CYBRAKDEMON_NAPALM_ATTACK3 + {SPR_BRAK, 0, 0, {A_SetObjectFlags2}, MF2_FRET, 1, S_CYBRAKDEMON_FINISH_ATTACK2}, // S_CYBRAKDEMON_FINISH_ATTACK1 // If just attacked, remove MF2_FRET w/out going back to spawnstate + {SPR_BRAK, 0, 0, {A_SetReactionTime}, 0, 0, S_CYBRAKDEMON_WALK1}, // S_CYBRAKDEMON_FINISH_ATTACK2 // If just attacked, remove MF2_FRET w/out going back to spawnstate + {SPR_BRAK, 18, 24, {A_Pain}, 0, 0, S_CYBRAKDEMON_PAIN2}, // S_CYBRAKDEMON_PAIN1 + {SPR_BRAK, 18, 0, {A_CheckHealth}, 3, S_CYBRAKDEMON_PAIN3, S_CYBRAKDEMON_CHOOSE_ATTACK1}, // S_CYBRAKDEMON_PAIN2 + {SPR_BRAK, 18, 0, {A_LinedefExecute}, LE_PINCHPHASE, 0, S_CYBRAKDEMON_CHOOSE_ATTACK1}, // S_CYBRAKDEMON_PAIN3 + {SPR_BRAK, 18, 1, {A_Repeat}, 1, S_CYBRAKDEMON_DIE1, S_CYBRAKDEMON_DIE2}, // S_CYBRAKDEMON_DIE1 + {SPR_BRAK, 18, 2, {A_BossScream}, 0, MT_SONIC3KBOSSEXPLODE, S_CYBRAKDEMON_DIE3}, // S_CYBRAKDEMON_DIE2 + {SPR_BRAK, 18, 0, {A_Repeat}, 52, S_CYBRAKDEMON_DIE2, S_CYBRAKDEMON_DIE4}, // S_CYBRAKDEMON_DIE3 + {SPR_BRAK, 13, 14, {A_PlaySound}, sfx_bedie2, 0, S_CYBRAKDEMON_DIE5}, // S_CYBRAKDEMON_DIE4 + {SPR_BRAK, 14, 7, {NULL}, 0, 0, S_CYBRAKDEMON_DIE6}, // S_CYBRAKDEMON_DIE5 + {SPR_BRAK, 15, 5, {NULL}, 0, 0, S_CYBRAKDEMON_DIE7}, // S_CYBRAKDEMON_DIE6 + {SPR_BRAK, 16, 3, {A_PlaySound}, sfx_bgxpld, 0, S_CYBRAKDEMON_DIE8}, // S_CYBRAKDEMON_DIE7 + {SPR_BRAK, 17, -1, {A_BossDeath}, 0, 0, S_NULL}, // S_CYBRAKDEMON_DIE8 + {SPR_BRAK, 0, 0, {A_SetObjectFlags}, MF_SPECIAL|MF_SHOOTABLE, 2, S_CYBRAKDEMON_IDLE}, // S_CYBRAKDEMON_DEINVINCIBLERIZE + {SPR_BRAK, 0, 0, {A_SetObjectFlags}, MF_SPECIAL|MF_SHOOTABLE, 1, S_CYBRAKDEMON_IDLE}, // S_CYBRAKDEMON_INVINCIBLERIZE + + {SPR_RCKT, 0 + FF_FULLBRIGHT, 1, {A_SetObjectFlags2}, MF2_RAILRING, 2, S_CYBRAKDEMONMISSILE}, // S_CYBRAKDEMONMISSILE + {SPR_RCKT, 1 + FF_FULLBRIGHT, 8, {A_Explode}, 0, 0, S_CYBRAKDEMONMISSILE_EXPLODE2}, // S_CYBRAKDEMONMISSILE_EXPLODE1 //TODO: set missile mobj's "damage" to an appropriate radius + {SPR_RCKT, 2 + FF_FULLBRIGHT, 6, {A_NapalmScatter}, MT_CYBRAKDEMON_NAPALM_FLAMES + (6<<16), 32 + (16<<16), S_CYBRAKDEMONMISSILE_EXPLODE3}, // S_CYBRAKDEMONMISSILE_EXPLODE2 + {SPR_RCKT, 3 + FF_FULLBRIGHT, 4, {NULL}, 0, 0, S_NULL}, // S_CYBRAKDEMONMISSILE_EXPLODE3 + + {SPR_FLME, 0 + FF_FULLBRIGHT, 15, {NULL}, 0, 0, S_CYBRAKDEMONFLAMESHOT_FLY2}, // S_CYBRAKDEMONFLAMESHOT_FLY1 + {SPR_FLME, 1 + FF_FULLBRIGHT, 15, {NULL}, 0, 0, S_CYBRAKDEMONFLAMESHOT_FLY3}, // S_CYBRAKDEMONFLAMESHOT_FLY2 + {SPR_FLME, 2 + FF_FULLBRIGHT, -1, {NULL}, 0, 0, S_CYBRAKDEMONFLAMESHOT_FLY3}, // S_CYBRAKDEMONFLAMESHOT_FLY3 + {SPR_FLME, 2 + FF_FULLBRIGHT, 0, {A_SpawnObjectRelative}, 0, MT_CYBRAKDEMON_FLAMEREST, S_NULL}, // S_CYBRAKDEMONFLAMESHOT_DIE + + {SPR_FLAM, 3 + FF_FULLBRIGHT, 3, {A_SetFuse}, 10*TICRATE, 0, S_FLAME1}, // S_CYBRAKDEMONFLAMEREST + + {SPR_ELEC, 0 + FF_FULLBRIGHT, 1, {NULL}, 0, 0, S_CYBRAKDEMONELECTRICBARRIER_INIT2}, // S_CYBRAKDEMONELECTRICBARRIER_INIT1 + {SPR_ELEC, 0 + FF_FULLBRIGHT, 0, {A_RemoteAction}, -1, S_CYBRAKDEMON_INVINCIBLERIZE, S_CYBRAKDEMONELECTRICBARRIER_PLAYSOUND}, // S_CYBRAKDEMONELECTRICBARRIER_INIT2 + {SPR_ELEC, 0 + FF_FULLBRIGHT, 0, {A_PlayActiveSound}, 0, 0, S_CYBRAKDEMONELECTRICBARRIER1}, // S_CYBRAKDEMONELECTRICBARRIER_PLAYSOUND + {SPR_ELEC, 0 + FF_FULLBRIGHT, 1, {A_CapeChase}, 0, 0, S_CYBRAKDEMONELECTRICBARRIER2}, // S_CYBRAKDEMONELECTRICBARRIER1 + {SPR_ELEC, 0 + FF_FULLBRIGHT, 1, {A_CapeChase}, 0, 0, S_CYBRAKDEMONELECTRICBARRIER3}, // S_CYBRAKDEMONELECTRICBARRIER2 + {SPR_ELEC, 1 + FF_FULLBRIGHT, 1, {A_CapeChase}, 0, 0, S_CYBRAKDEMONELECTRICBARRIER4}, // S_CYBRAKDEMONELECTRICBARRIER3 + {SPR_ELEC, 1 + FF_FULLBRIGHT, 1, {A_CapeChase}, 0, 0, S_CYBRAKDEMONELECTRICBARRIER5}, // S_CYBRAKDEMONELECTRICBARRIER4 + {SPR_ELEC, 2 + FF_FULLBRIGHT, 1, {A_CapeChase}, 0, 0, S_CYBRAKDEMONELECTRICBARRIER6}, // S_CYBRAKDEMONELECTRICBARRIER5 + {SPR_ELEC, 2 + FF_FULLBRIGHT, 1, {A_CapeChase}, 0, 0, S_CYBRAKDEMONELECTRICBARRIER7}, // S_CYBRAKDEMONELECTRICBARRIER6 + {SPR_ELEC, 3 + FF_FULLBRIGHT, 1, {A_CapeChase}, 0, 0, S_CYBRAKDEMONELECTRICBARRIER8}, // S_CYBRAKDEMONELECTRICBARRIER7 + {SPR_ELEC, 3 + FF_FULLBRIGHT, 1, {A_CapeChase}, 0, 0, S_CYBRAKDEMONELECTRICBARRIER9}, // S_CYBRAKDEMONELECTRICBARRIER8 + {SPR_ELEC, 4 + FF_FULLBRIGHT, 1, {A_CapeChase}, 0, 0, S_CYBRAKDEMONELECTRICBARRIER10}, // S_CYBRAKDEMONELECTRICBARRIER9 + {SPR_ELEC, 4 + FF_FULLBRIGHT, 1, {A_CapeChase}, 0, 0, S_CYBRAKDEMONELECTRICBARRIER11}, // S_CYBRAKDEMONELECTRICBARRIER10 + {SPR_ELEC, 5 + FF_FULLBRIGHT, 1, {A_CapeChase}, 0, 0, S_CYBRAKDEMONELECTRICBARRIER12}, // S_CYBRAKDEMONELECTRICBARRIER11 + {SPR_ELEC, 5 + FF_FULLBRIGHT, 1, {A_CapeChase}, 0, 0, S_CYBRAKDEMONELECTRICBARRIER13}, // S_CYBRAKDEMONELECTRICBARRIER12 + {SPR_ELEC, 6 + FF_FULLBRIGHT, 1, {A_CapeChase}, 0, 0, S_CYBRAKDEMONELECTRICBARRIER14}, // S_CYBRAKDEMONELECTRICBARRIER13 + {SPR_ELEC, 6 + FF_FULLBRIGHT, 1, {A_CapeChase}, 0, 0, S_CYBRAKDEMONELECTRICBARRIER15}, // S_CYBRAKDEMONELECTRICBARRIER14 + {SPR_ELEC, 7 + FF_FULLBRIGHT, 1, {A_CapeChase}, 0, 0, S_CYBRAKDEMONELECTRICBARRIER16}, // S_CYBRAKDEMONELECTRICBARRIER15 + {SPR_ELEC, 7 + FF_FULLBRIGHT, 1, {A_CapeChase}, 0, 0, S_CYBRAKDEMONELECTRICBARRIER17}, // S_CYBRAKDEMONELECTRICBARRIER16 + {SPR_ELEC, 8 + FF_FULLBRIGHT, 1, {A_CapeChase}, 0, 0, S_CYBRAKDEMONELECTRICBARRIER18}, // S_CYBRAKDEMONELECTRICBARRIER17 + {SPR_ELEC, 8 + FF_FULLBRIGHT, 1, {A_CapeChase}, 0, 0, S_CYBRAKDEMONELECTRICBARRIER19}, // S_CYBRAKDEMONELECTRICBARRIER18 + {SPR_ELEC, 9 + FF_FULLBRIGHT, 1, {A_CapeChase}, 0, 0, S_CYBRAKDEMONELECTRICBARRIER20}, // S_CYBRAKDEMONELECTRICBARRIER19 + {SPR_ELEC, 9 + FF_FULLBRIGHT, 1, {A_CapeChase}, 0, 0, S_CYBRAKDEMONELECTRICBARRIER21}, // S_CYBRAKDEMONELECTRICBARRIER20 + {SPR_ELEC, 10 + FF_FULLBRIGHT, 1, {A_CapeChase}, 0, 0, S_CYBRAKDEMONELECTRICBARRIER22}, // S_CYBRAKDEMONELECTRICBARRIER21 + {SPR_ELEC, 10 + FF_FULLBRIGHT, 1, {A_CapeChase}, 0, 0, S_CYBRAKDEMONELECTRICBARRIER23}, // S_CYBRAKDEMONELECTRICBARRIER22 + {SPR_ELEC, 11 + FF_FULLBRIGHT, 1, {A_CapeChase}, 0, 0, S_CYBRAKDEMONELECTRICBARRIER24}, // S_CYBRAKDEMONELECTRICBARRIER23 + {SPR_ELEC, 11 + FF_FULLBRIGHT, 1, {A_CapeChase}, 0, 0, S_CYBRAKDEMONELECTRICBARRIER_PLAYSOUND}, // S_CYBRAKDEMONELECTRICBARRIER24 + {SPR_NULL, 0, 0, {A_RemoteAction}, -1, S_CYBRAKDEMON_DEINVINCIBLERIZE, S_CYBRAKDEMONELECTRICBARRIER_DIE2}, // S_CYBRAKDEMONELECTRICBARRIER_DIE1 + {SPR_NULL, 0, 0, {A_SetObjectFlags}, MF_PUSHABLE|MF_FIRE|MF_PAIN, 1, S_CYBRAKDEMONELECTRICBARRIER_DIE3}, // S_CYBRAKDEMONELECTRICBARRIER_DIE2 + {SPR_NULL, 0, 20*TICRATE, {A_Scream}, 0, 0, S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOMSUCCESS}, // S_CYBRAKDEMONELECTRICBARRIER_DIE3 + {SPR_NULL, 0, 0, {A_CheckRandom}, 10, S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOMSUCCESS, S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOMFAIL}, // S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOMCHECK, + {SPR_NULL, 0, 0, {A_CapeChase}, 0, 0, S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOMCHOOSE}, // S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOMSUCCESS, + {SPR_NULL, 0, 0, {A_RandomStateRange}, S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOM1, S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOM12, S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOM1}, // S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOMCHOOSE, + {SPR_ELEC, 0 + FF_FULLBRIGHT, 1, {A_PlaySound}, sfx_s3k5c, 1, S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOMLOOP}, // S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOM1, + {SPR_ELEC, 1 + FF_FULLBRIGHT, 1, {A_PlaySound}, sfx_s3k5c, 1, S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOMLOOP}, // S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOM2, + {SPR_ELEC, 2 + FF_FULLBRIGHT, 1, {A_PlaySound}, sfx_s3k5c, 1, S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOMLOOP}, // S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOM3, + {SPR_ELEC, 3 + FF_FULLBRIGHT, 1, {A_PlaySound}, sfx_s3k5c, 1, S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOMLOOP}, // S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOM4, + {SPR_ELEC, 4 + FF_FULLBRIGHT, 1, {A_PlaySound}, sfx_s3k5c, 1, S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOMLOOP}, // S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOM5, + {SPR_ELEC, 5 + FF_FULLBRIGHT, 1, {A_PlaySound}, sfx_s3k5c, 1, S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOMLOOP}, // S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOM6, + {SPR_ELEC, 6 + FF_FULLBRIGHT, 1, {A_PlaySound}, sfx_s3k5c, 1, S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOMLOOP}, // S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOM7, + {SPR_ELEC, 7 + FF_FULLBRIGHT, 1, {A_PlaySound}, sfx_s3k5c, 1, S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOMLOOP}, // S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOM8, + {SPR_ELEC, 8 + FF_FULLBRIGHT, 1, {A_PlaySound}, sfx_s3k5c, 1, S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOMLOOP}, // S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOM9, + {SPR_ELEC, 9 + FF_FULLBRIGHT, 1, {A_PlaySound}, sfx_s3k5c, 1, S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOMLOOP}, // S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOM10, + {SPR_ELEC, 10 + FF_FULLBRIGHT, 1, {A_PlaySound}, sfx_s3k5c, 1, S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOMLOOP}, // S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOM11, + {SPR_ELEC, 11 + FF_FULLBRIGHT, 1, {A_PlaySound}, sfx_s3k5c, 1, S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOMLOOP}, // S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOM12, + {SPR_NULL, 0, 1, {NULL}, 0, 0, S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOMLOOP}, // S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOMFAIL, + {SPR_NULL, 0, 0, {A_Repeat}, 5*TICRATE, S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOMCHECK, S_CYBRAKDEMONELECTRICBARRIER_REVIVE1}, // S_CYBRAKDEMONELECTRICBARRIER_SPARK_RANDOMLOOP, + {SPR_NULL, 0, 0, {A_CapeChase}, 0, 0, S_CYBRAKDEMONELECTRICBARRIER_REVIVE2}, // S_CYBRAKDEMONELECTRICBARRIER_REVIVE1 + {SPR_NULL, 0, 0, {A_SpawnFreshCopy}, 0, 0, S_CYBRAKDEMONELECTRICBARRIER_REVIVE3}, // S_CYBRAKDEMONELECTRICBARRIER_REVIVE2 + {SPR_NULL, 0, TICRATE, {A_PlaySound}, sfx_s3k79, 0, S_NULL}, // S_CYBRAKDEMONELECTRICBARRIER_INIT1 + + {SPR_TARG, 0 + FF_FULLBRIGHT, 1, {A_VileFire}, sfx_s3k9d, 0, S_CYBRAKDEMONTARGETRETICULE2}, // S_CYBRAKDEMONTARGETRETICULE1 + {SPR_TARG, 6 + FF_FULLBRIGHT, 1, {A_VileFire}, 0, 0, S_CYBRAKDEMONTARGETRETICULE3}, // S_CYBRAKDEMONTARGETRETICULE2 + {SPR_TARG, 1 + FF_FULLBRIGHT, 1, {A_VileFire}, 0, 0, S_CYBRAKDEMONTARGETRETICULE4}, // S_CYBRAKDEMONTARGETRETICULE3 + {SPR_TARG, 6 + FF_FULLBRIGHT, 1, {A_VileFire}, 0, 0, S_CYBRAKDEMONTARGETRETICULE5}, // S_CYBRAKDEMONTARGETRETICULE4 + {SPR_TARG, 2 + FF_FULLBRIGHT, 1, {A_VileFire}, 0, 0, S_CYBRAKDEMONTARGETRETICULE6}, // S_CYBRAKDEMONTARGETRETICULE5 + {SPR_TARG, 6 + FF_FULLBRIGHT, 1, {A_VileFire}, 0, 0, S_CYBRAKDEMONTARGETRETICULE7}, // S_CYBRAKDEMONTARGETRETICULE6 + {SPR_TARG, 3 + FF_FULLBRIGHT, 1, {A_VileFire}, 0, 0, S_CYBRAKDEMONTARGETRETICULE8}, // S_CYBRAKDEMONTARGETRETICULE7 + {SPR_TARG, 6 + FF_FULLBRIGHT, 1, {A_VileFire}, 0, 0, S_CYBRAKDEMONTARGETRETICULE9}, // S_CYBRAKDEMONTARGETRETICULE8 + {SPR_TARG, 4 + FF_FULLBRIGHT, 1, {A_VileFire}, 0, 0, S_CYBRAKDEMONTARGETRETICULE10}, // S_CYBRAKDEMONTARGETRETICULE9 + {SPR_TARG, 6 + FF_FULLBRIGHT, 1, {A_VileFire}, 0, 0, S_CYBRAKDEMONTARGETRETICULE11}, // S_CYBRAKDEMONTARGETRETICULE10 + {SPR_TARG, 5 + FF_FULLBRIGHT, 1, {A_VileFire}, 0, 0, S_CYBRAKDEMONTARGETRETICULE12}, // S_CYBRAKDEMONTARGETRETICULE11 + {SPR_TARG, 6 + FF_FULLBRIGHT, 1, {A_VileFire}, 0, 0, S_CYBRAKDEMONTARGETRETICULE13}, // S_CYBRAKDEMONTARGETRETICULE12 + {SPR_TARG, 0 + FF_FULLBRIGHT, 1, {A_VileFire}, 0, 0, S_CYBRAKDEMONTARGETRETICULE14}, // S_CYBRAKDEMONTARGETRETICULE13 + {SPR_TARG, 6 + FF_FULLBRIGHT, 1, {A_Repeat}, 6, S_CYBRAKDEMONTARGETRETICULE2, S_NULL}, // S_CYBRAKDEMONTARGETRETICULE14 + + {SPR_NPLM, 0, 2, {NULL}, 0, 0, S_CYBRAKDEMONNAPALMBOMBLARGE_FLY2}, //S_CYBRAKDEMONNAPALMBOMBLARGE_FLY1, + {SPR_NPLM, 1, 2, {NULL}, 0, 0, S_CYBRAKDEMONNAPALMBOMBLARGE_FLY3}, //S_CYBRAKDEMONNAPALMBOMBLARGE_FLY2, + {SPR_NPLM, 2, 2, {NULL}, 0, 0, S_CYBRAKDEMONNAPALMBOMBLARGE_FLY4}, //S_CYBRAKDEMONNAPALMBOMBLARGE_FLY3, + {SPR_NPLM, 3, 2, {NULL}, 0, 0, S_CYBRAKDEMONNAPALMBOMBLARGE_FLY1}, //S_CYBRAKDEMONNAPALMBOMBLARGE_FLY4, + {SPR_NPLM, 0, 1, {A_Explode}, 0, 0, S_CYBRAKDEMONNAPALMBOMBLARGE_DIE2}, //S_CYBRAKDEMONNAPALMBOMBLARGE_DIE1, // Explode + {SPR_NPLM, 0, 1, {A_NapalmScatter}, MT_CYBRAKDEMON_NAPALM_BOMB_SMALL + (6<<16), 256 + (48<<16), S_CYBRAKDEMONNAPALMBOMBLARGE_DIE3}, //S_CYBRAKDEMONNAPALMBOMBLARGE_DIE2, // Outer ring + {SPR_NPLM, 0, 1, {A_NapalmScatter}, MT_CYBRAKDEMON_NAPALM_BOMB_SMALL + (1<<16), 32<<16, S_CYBRAKDEMONNAPALMBOMBLARGE_DIE4}, //S_CYBRAKDEMONNAPALMBOMBLARGE_DIE3, // Center + {SPR_NULL, 0, 81, {A_Scream}, 0, 0, S_NULL}, //S_CYBRAKDEMONNAPALMBOMBLARGE_DIE4, // Sound + + {SPR_MNPL, 0, 1, {NULL}, 0, 0, S_CYBRAKDEMONNAPALMBOMBSMALL}, //S_CYBRAKDEMONNAPALMBOMBSMALL, + {SPR_MNPL, 0, 1, {A_Explode}, 0, 0, S_CYBRAKDEMONNAPALMBOMBSMALL_DIE2}, //S_CYBRAKDEMONNAPALMBOMBSMALL_DIE1, // Explode + {SPR_MNPL, 0, 1, {A_NapalmScatter}, MT_CYBRAKDEMON_NAPALM_FLAMES + (12<<16), 128 + (40<<16), S_CYBRAKDEMONNAPALMBOMBSMALL_DIE3}, //S_CYBRAKDEMONNAPALMBOMBSMALL_DIE2, // Outer ring + {SPR_MNPL, 0, 1, {A_NapalmScatter}, MT_CYBRAKDEMON_NAPALM_FLAMES + (8<<16), 64 + (32<<16), S_CYBRAKDEMONNAPALMBOMBSMALL_DIE4}, //S_CYBRAKDEMONNAPALMBOMBSMALL_DIE3, // Inner ring + {SPR_MNPL, 0, 1, {A_NapalmScatter}, MT_CYBRAKDEMON_NAPALM_FLAMES + (1<<16), 24<<16, S_CYBRAKDEMONNAPALMBOMBSMALL_DIE5}, //S_CYBRAKDEMONNAPALMBOMBSMALL_DIE4, // Center + {SPR_NULL, 0, 24, {A_Scream}, 0, 0, S_NULL}, //S_CYBRAKDEMONNAPALMBOMBSMALL_DIE5, // Sound + + {SPR_SFLM, FF_FULLBRIGHT, 2, {NULL}, 0, 0, S_CYBRAKDEMONNAPALMFLAME_FLY2}, //S_CYBRAKDEMONNAPALMFLAME_FLY1, + {SPR_SFLM, FF_FULLBRIGHT+1, 2, {NULL}, 0, 0, S_CYBRAKDEMONNAPALMFLAME_FLY3}, //S_CYBRAKDEMONNAPALMFLAME_FLY2, + {SPR_SFLM, FF_FULLBRIGHT+2, 2, {NULL}, 0, 0, S_CYBRAKDEMONNAPALMFLAME_FLY4}, //S_CYBRAKDEMONNAPALMFLAME_FLY3, + {SPR_SFLM, FF_FULLBRIGHT+3, 2, {NULL}, 0, 0, S_CYBRAKDEMONNAPALMFLAME_FLY5}, //S_CYBRAKDEMONNAPALMFLAME_FLY4, + {SPR_SFLM, FF_FULLBRIGHT+4, 2, {NULL}, 0, 0, S_CYBRAKDEMONNAPALMFLAME_FLY6}, //S_CYBRAKDEMONNAPALMFLAME_FLY5, + {SPR_SFLM, FF_FULLBRIGHT+5, 2, {NULL}, 0, 0, S_CYBRAKDEMONNAPALMFLAME_FLY1}, //S_CYBRAKDEMONNAPALMFLAME_FLY6, + {SPR_SFLM, FF_FULLBRIGHT, 0, {A_SpawnObjectRelative}, 0, MT_CYBRAKDEMON_FLAMEREST, S_NULL}, //S_CYBRAKDEMONNAPALMFLAME_DIE, + + {SPR_NULL, 0, 1, {A_SetFuse}, TICRATE, 0, S_CYBRAKDEMONVILEEXPLOSION2}, //S_CYBRAKDEMONVILEEXPLOSION1, + {SPR_NULL, 0, 0, {A_ScoreRise}, 0, 0, S_CYBRAKDEMONVILEEXPLOSION3}, //S_CYBRAKDEMONVILEEXPLOSION2, + {SPR_NULL, 0, 1, {A_BossScream}, 0, MT_SONIC3KBOSSEXPLODE, S_CYBRAKDEMONVILEEXPLOSION1}, //S_CYBRAKDEMONVILEEXPLOSION3, + + // Metal Sonic + {SPR_METL, 0, 35, {NULL}, 0, 0, S_METALSONIC_WAIT1}, // S_METALSONIC_STAND + {SPR_METL, 1, 8, {NULL}, 0, 0, S_METALSONIC_WAIT2}, // S_METALSONIC_WAIT1 + {SPR_METL, 2, 8, {NULL}, 0, 0, S_METALSONIC_WAIT1}, // S_METALSONIC_WAIT2 + {SPR_METL, 3, 4, {NULL}, 0, 0, S_METALSONIC_WALK2}, // S_METALSONIC_WALK1 + {SPR_METL, 4, 4, {NULL}, 0, 0, S_METALSONIC_WALK3}, // S_METALSONIC_WALK2 + {SPR_METL, 5, 4, {NULL}, 0, 0, S_METALSONIC_WALK4}, // S_METALSONIC_WALK3 + {SPR_METL, 6, 4, {NULL}, 0, 0, S_METALSONIC_WALK5}, // S_METALSONIC_WALK4 + {SPR_METL, 7, 4, {NULL}, 0, 0, S_METALSONIC_WALK6}, // S_METALSONIC_WALK5 + {SPR_METL, 6, 4, {NULL}, 0, 0, S_METALSONIC_WALK7}, // S_METALSONIC_WALK6 + {SPR_METL, 5, 4, {NULL}, 0, 0, S_METALSONIC_WALK8}, // S_METALSONIC_WALK7 + {SPR_METL, 4, 4, {NULL}, 0, 0, S_METALSONIC_WALK1}, // S_METALSONIC_WALK8 + {SPR_METL, 8, 2, {NULL}, 0, 0, S_METALSONIC_RUN2}, // S_METALSONIC_RUN1 + {SPR_METL, 9, 2, {NULL}, 0, 0, S_METALSONIC_RUN3}, // S_METALSONIC_RUN2 + {SPR_METL, 10, 2, {NULL}, 0, 0, S_METALSONIC_RUN4}, // S_METALSONIC_RUN3 + {SPR_METL, 9, 2, {NULL}, 0, 0, S_METALSONIC_RUN1}, // S_METALSONIC_RUN4 + + {SPR_METL, 4, -1, {NULL}, 0, 0, S_NULL}, // S_METALSONIC_FLOAT + {SPR_METL, 12, -1, {NULL}, 0, 0, S_METALSONIC_STUN}, // S_METALSONIC_VECTOR + {SPR_METL, 0, -1, {NULL}, 0, 0, S_METALSONIC_FLOAT}, // S_METALSONIC_STUN + {SPR_METL, 13, -1, {NULL}, 0, 0, S_NULL}, // S_METALSONIC_BLOCK + {SPR_METL, 13, 40, {NULL}, 0, 0, S_METALSONIC_GATHER},// S_METALSONIC_RAISE + {SPR_METL, 14, -1, {NULL}, 0, 0, S_NULL}, // S_METALSONIC_GATHER + {SPR_METL, 9, -1, {NULL}, 0, 0, S_METALSONIC_BOUNCE},// S_METALSONIC_DASH + {SPR_METL, 14, -1, {NULL}, 0, 0, S_NULL}, // S_METALSONIC_BOUNCE + {SPR_METL, 13, -1, {NULL}, 0, 0, S_METALSONIC_GATHER},// S_METALSONIC_SHOOT + {SPR_METL, 11, 40, {A_Pain}, 0, 0, S_METALSONIC_FLOAT}, // S_METALSONIC_PAIN + {SPR_METL, 0, -1, {A_BossDeath}, 0, 0, S_NULL}, // S_METALSONIC_DEATH + {SPR_METL, 3, 4, {NULL}, 0, 0, S_METALSONIC_FLEE2}, // S_METALSONIC_FLEE1 + {SPR_METL, 4, 4, {A_BossScream}, 0, 0, S_METALSONIC_FLEE3}, // S_METALSONIC_FLEE2 + {SPR_METL, 5, 4, {NULL}, 0, 0, S_METALSONIC_FLEE4}, // S_METALSONIC_FLEE3 + {SPR_METL, 4, 4, {NULL}, 0, 0, S_METALSONIC_FLEE1}, // S_METALSONIC_FLEE4 + + {SPR_MSCF, FF_FULLBRIGHT|(tr_trans30<

'.htmlentities($formatedentry).'
'; + break; + case SMARTIRC_FILE: + if (!is_resource($this->_logfilefp)) { + if ($this->_logfilefp === null) { + // we reconncted and don't want to destroy the old log entries + $this->_logfilefp = @fopen($this->_logfile,'a'); + } else { + $this->_logfilefp = @fopen($this->_logfile,'w'); + } + } + @fwrite($this->_logfilefp, $formatedentry); + fflush($this->_logfilefp); + break; + case SMARTIRC_SYSLOG: + define_syslog_variables(); + if (!is_int($this->_logfilefp)) { + $this->_logfilefp = openlog('Net_SmartIRC', LOG_NDELAY, LOG_DAEMON); + } + syslog(LOG_INFO, $entry); + break; + } + } + + /** + * Returns the full motd. + * + * @return array + * @access public + */ + function getMotd() + { + return $this->_motd; + } + + /** + * Returns the usermode. + * + * @return string + * @access public + */ + function getUsermode() + { + return $this->_usermode; + } + + /** + * Creates the sockets and connects to the IRC server on the given port. + * + * @param string $address + * @param integer $port + * @return void + * @access public + */ + function connect($address, $port) + { + $this->log(SMARTIRC_DEBUG_CONNECTION, 'DEBUG_CONNECTION: connecting', __FILE__, __LINE__); + $this->_address = $address; + $this->_port = $port; + + if ($this->_usesockets == true) { + $this->log(SMARTIRC_DEBUG_SOCKET, 'DEBUG_SOCKET: using real sockets', __FILE__, __LINE__); + $this->_socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); + $result = @socket_connect($this->_socket, $this->_address, $this->_port); + } else { + $this->log(SMARTIRC_DEBUG_SOCKET, 'DEBUG_SOCKET: using fsockets', __FILE__, __LINE__); + $result = @fsockopen($this->_address, $this->_port, $errno, $errstr); + } + + if ($result === false) { + if ($this->_usesockets == true) { + $error = socket_strerror(socket_last_error($this->_socket)); + } else { + $error = $errstr.' ('.$errno.')'; + } + + $error_msg = 'couldn\'t connect to "'.$address.'" reason: "'.$error.'"'; + $this->log(SMARTIRC_DEBUG_NOTICE, 'DEBUG_NOTICE: '.$error_msg, __FILE__, __LINE__); + // TODO! muss return wert sein + $this->throwError($error_msg); + + // doesn't work somehow.... I only want to retry 4 times! no endless loop (causes segfault) + static $tries = 0; + if ($this->_autoretry == true && $tries < 5) { + $this->reconnect(); + $tries++; + } else { + die(); + } + } else { + $this->log(SMARTIRC_DEBUG_CONNECTION, 'DEBUG_CONNECTION: connected', __FILE__, __LINE__); + + if ($this->_usesockets != true) { + $this->_socket = $result; + $this->log(SMARTIRC_DEBUG_SOCKET, 'DEBUG_SOCKET: activating nonblocking fsocket mode', __FILE__, __LINE__); + socket_set_blocking($this->_socket, false); + } + } + + $this->_lastrx = time(); + $this->_lasttx = $this->_lastrx; + $this->_updatestate(); + + if ($result !== false) { + return true; + } else { + return false; + } + } + + /** + * Disconnects from the IRC server nicely with a QUIT or just destroys the socket. + * + * Disconnects from the IRC server in the given quickness mode. + * $quickdisconnect: + * true, just close the socket + * false, send QUIT and wait {@link $_disconnectime $_disconnectime} before closing the socket + * + * @param boolean $quickdisconnect default: false + * @return boolean + * @access public + */ + function disconnect($quickdisconnect = false) + { + if ($this->_state() == SMARTIRC_STATE_CONNECTED) { + if ($quickdisconnect == false) { + $this->_send('QUIT', SMARTIRC_CRITICAL); + usleep($this->_disconnecttime*1000); + } + + if ($this->_usesockets == true) { + @socket_shutdown($this->_socket); + @socket_close($this->_socket); + } else { + fclose($this->_socket); + } + + $this->_updatestate(); + $this->log(SMARTIRC_DEBUG_CONNECTION, 'DEBUG_CONNECTION: disconnected', __FILE__, __LINE__); + } else { + return false; + } + + if ($this->_channelsyncing == true) { + // let's clean our channel array + $this->_channels = array(); + $this->log(SMARTIRC_DEBUG_CHANNELSYNCING, 'DEBUG_CHANNELSYNCING: cleaned channel array', __FILE__, __LINE__); + } + + if ($this->_logdestination == SMARTIRC_FILE) { + fclose($this->_logfilefp); + $this->_logfilefp = null; + } else if ($this->_logdestination == SMARTIRC_SYSLOG) { + closelog(); + } + + return true; + } + + /** + * Reconnects to the IRC server with the same login info, + * it also rejoins the channels + * + * @return void + * @access public + */ + function reconnect() + { + $this->log(SMARTIRC_DEBUG_CONNECTION, 'DEBUG_CONNECTION: reconnecting...', __FILE__, __LINE__); + + // remember in which channels we are joined + $channels = array(); + foreach ($this->_channels as $value) { + if (empty($value->key)) { + $channels[] = array('name' => $value->name); + } else { + $channels[] = array('name' => $value->name, 'key' => $value->key); + } + } + + $this->disconnect(true); + $this->connect($this->_address, $this->_port); + $this->login($this->_nick, $this->_realname, $this->_usermode, $this->_username, $this->_password); + + // rejoin the channels + foreach ($channels as $value) { + if (isset($value['key'])) { + $this->join($value['name'], $value['key']); + } else { + $this->join($value['name']); + } + } + } + + /** + * login and register nickname on the IRC network + * + * Registers the nickname and user information on the IRC network. + * + * @param string $nick + * @param string $realname + * @param integer $usermode + * @param string $username + * @param string $password + * @return void + * @access public + */ + function login($nick, $realname, $usermode = 0, $username = null, $password = null) + { + $this->log(SMARTIRC_DEBUG_CONNECTION, 'DEBUG_CONNECTION: logging in', __FILE__, __LINE__); + + $this->_nick = str_replace(' ', '', $nick); + $this->_realname = $realname; + + if ($username !== null) { + $this->_username = str_replace(' ', '', $username); + } else { + $this->_username = str_replace(' ', '', exec('whoami')); + } + + if ($password !== null) { + $this->_password = $password; + $this->_send('PASS '.$this->_password, SMARTIRC_CRITICAL); + } + + if (!is_numeric($usermode)) { + $this->log(SMARTIRC_DEBUG_NOTICE, 'DEBUG_NOTICE: login() usermode ('.$usermode.') is not valid, will use 0 instead', __FILE__, __LINE__); + $usermode = 0; + } + + $this->_send('NICK '.$this->_nick, SMARTIRC_CRITICAL); + $this->_send('USER '.$this->_username.' '.$usermode.' '.SMARTIRC_UNUSED.' :'.$this->_realname, SMARTIRC_CRITICAL); + } + + // + + /** + * checks if we or the given user is joined to the specified channel and returns the result + * ChannelSyncing is required for this. + * + * @see setChannelSyncing + * @param string $channel + * @param string $nickname + * @return boolean + * @access public + */ + function isJoined($channel, $nickname = null) + { + if ($this->_channelsyncing != true) { + $this->log(SMARTIRC_DEBUG_NOTICE, 'WARNING: isJoined() is called and the required Channel Syncing is not activated!', __FILE__, __LINE__); + return false; + } + + if ($nickname === null) { + $nickname = $this->_nick; + } + + if (isset($this->_channels[strtolower($channel)]->users[strtolower($nickname)])) { + return true; + } + + return false; + } + + /** + * Checks if we or the given user is opped on the specified channel and returns the result. + * ChannelSyncing is required for this. + * + * @see setChannelSyncing + * @param string $channel + * @param string $nickname + * @return boolean + * @access public + */ + function isOpped($channel, $nickname = null) + { + if ($this->_channelsyncing != true) { + $this->log(SMARTIRC_DEBUG_NOTICE, 'WARNING: isOpped() is called and the required Channel Syncing is not activated!', __FILE__, __LINE__); + return false; + } + + if ($nickname === null) { + $nickname = $this->_nick; + } + + if ($this->isJoined($channel, $nickname)) { + if ($this->_channels[strtolower($channel)]->users[strtolower($nickname)]->op) { + return true; + } + } + + return false; + } + + /** + * Checks if we or the given user is voiced on the specified channel and returns the result. + * ChannelSyncing is required for this. + * + * @see setChannelSyncing + * @param string $channel + * @param string $nickname + * @return boolean + * @access public + */ + function isVoiced($channel, $nickname = null) + { + if ($this->_channelsyncing != true) { + $this->log(SMARTIRC_DEBUG_NOTICE, 'WARNING: isVoiced() is called and the required Channel Syncing is not activated!', __FILE__, __LINE__); + return false; + } + + if ($nickname === null) { + $nickname = $this->_nick; + } + + if ($this->isJoined($channel, $nickname)) { + if ($this->_channels[strtolower($channel)]->users[strtolower($nickname)]->voice) { + return true; + } + } + + return false; + } + + /** + * Checks if the hostmask is on the specified channel banned and returns the result. + * ChannelSyncing is required for this. + * + * @see setChannelSyncing + * @param string $channel + * @param string $hostmask + * @return boolean + * @access public + */ + function isBanned($channel, $hostmask) + { + if ($this->_channelsyncing != true) { + $this->log(SMARTIRC_DEBUG_NOTICE, 'WARNING: isBanned() is called and the required Channel Syncing is not activated!', __FILE__, __LINE__); + return false; + } + + if ($this->isJoined($channel)) { + $result = array_search($hostmask, $this->_channels[strtolower($channel)]->bans); + + if ($result !== false) { + return true; + } + } + + return false; + } + + /** + * goes into receive mode + * + * Goes into receive and idle mode. Only call this if you want to "spawn" the bot. + * No further lines of PHP code will be processed after this call, only the bot methods! + * + * @return boolean + * @access public + */ + function listen() + { + if ($this->_state() == SMARTIRC_STATE_CONNECTED) { + $this->_rawreceive(); + return true; + } else { + return false; + } + } + + /** + * waits for a special message type and puts the answer in $result + * + * Creates a special actionhandler for that given TYPE and returns the answer. + * This will only receive the requested type, immediately quit and disconnect from the IRC server. + * Made for showing IRC statistics on your homepage, or other IRC related information. + * + * @param integer $messagetype see in the documentation 'Message Types' + * @return array answer from the IRC server for this $messagetype + * @access public + */ + function listenFor($messagetype) + { + $listenfor = &new Net_SmartIRC_listenfor(); + $this->registerActionhandler($messagetype, '.*', $listenfor, 'handler'); + $this->listen(); + $result = $listenfor->result; + + if (isset($listenfor)) { + unset($listenfor); + } + + return $result; + } + + /** + * waits for a special message type and puts the answer in $result + * + * Creates a special actionhandler for that given TYPE and returns the answer. + * This will only receive the requested type, immediately quit and disconnect from the IRC server. + * Made for showing IRC statistics on your homepage, or other IRC related information. + * This special version of listenFor() stores the whole ircdata object, not just the message! + * + * @param integer $messagetype see in the documentation 'Message Types' + * @return array answer from the IRC server for this $messagetype + * @access public + */ + function objListenFor($messagetype) + { + $objlistenfor = &new Net_SmartIRC_objListenFor(); + $this->registerActionhandler($messagetype, '.*', $objlistenfor, 'handler'); + $this->listen(); + $result = $objlistenfor->result; + + if (isset($objlistenfor)) { + unset($objlistenfor); + } + + return $result; + } + + /** + * registers a new actionhandler and returns the assigned id + * + * Registers an actionhandler in Net_SmartIRC for calling it later. + * The actionhandler id is needed for unregistering the actionhandler. + * + * @see example.php + * @param integer $handlertype bits constants, see in this documentation Message Types + * @param string $regexhandler the message that has to be in the IRC message in regex syntax + * @param object $object a reference to the objects of the method + * @param string $methodname the methodname that will be called when the handler happens + * @return integer assigned actionhandler id + * @access public + */ + function registerActionhandler($handlertype, $regexhandler, &$object, $methodname) + { + // precheck + if (!$this->_isValidType($handlertype)) { + $this->log(SMARTIRC_DEBUG_NOTICE, 'WARNING: passed invalid handlertype to registerActionhandler()', __FILE__, __LINE__); + return false; + } + + $id = $this->_actionhandlerid++; + $newactionhandler = &new Net_SmartIRC_actionhandler(); + + $newactionhandler->id = $id; + $newactionhandler->type = $handlertype; + $newactionhandler->message = $regexhandler; + $newactionhandler->object = &$object; + $newactionhandler->method = $methodname; + + $this->_actionhandler[] = &$newactionhandler; + $this->log(SMARTIRC_DEBUG_ACTIONHANDLER, 'DEBUG_ACTIONHANDLER: actionhandler('.$id.') registered', __FILE__, __LINE__); + return $id; + } + + /** + * unregisters an existing actionhandler + * + * @param integer $handlertype + * @param string $regexhandler + * @param object $object + * @param string $methodname + * @return boolean + * @access public + */ + function unregisterActionhandler($handlertype, $regexhandler, &$object, $methodname) + { + // precheck + if (!$this->_isValidType($handlertype)) { + $this->log(SMARTIRC_DEBUG_NOTICE, 'WARNING: passed invalid handlertype to unregisterActionhandler()', __FILE__, __LINE__); + return false; + } + + $handler = &$this->_actionhandler; + $handlercount = count($handler); + + for ($i = 0; $i < $handlercount; $i++) { + $handlerobject = &$handler[$i]; + + if ($handlerobject->type == $handlertype && + $handlerobject->message == $regexhandler && + $handlerobject->method == $methodname) { + + $id = $handlerobject->id; + + if (isset($this->_actionhandler[$i])) { + unset($this->_actionhandler[$i]); + } + + $this->log(SMARTIRC_DEBUG_ACTIONHANDLER, 'DEBUG_ACTIONHANDLER: actionhandler('.$id.') unregistered', __FILE__, __LINE__); + $this->_reorderactionhandler(); + return true; + } + } + + $this->log(SMARTIRC_DEBUG_ACTIONHANDLER, 'DEBUG_ACTIONHANDLER: could not find actionhandler type: "'.$handlertype.'" message: "'.$regexhandler.'" method: "'.$methodname.'" from object "'.get_class($object).'" _not_ unregistered', __FILE__, __LINE__); + return false; + } + + /** + * unregisters an existing actionhandler via the id + * + * @param integer $id + * @return boolean + * @access public + */ + function unregisterActionid($id) + { + $handler = &$this->_actionhandler; + $handlercount = count($handler); + for ($i = 0; $i < $handlercount; $i++) { + $handlerobject = &$handler[$i]; + + if ($handlerobject->id == $id) { + if (isset($this->_actionhandler[$i])) { + unset($this->_actionhandler[$i]); + } + + $this->log(SMARTIRC_DEBUG_ACTIONHANDLER, 'DEBUG_ACTIONHANDLER: actionhandler('.$id.') unregistered', __FILE__, __LINE__); + $this->_reorderactionhandler(); + return true; + } + } + + $this->log(SMARTIRC_DEBUG_ACTIONHANDLER, 'DEBUG_ACTIONHANDLER: could not find actionhandler id: '.$id.' _not_ unregistered', __FILE__, __LINE__); + return false; + } + + /** + * registers a timehandler and returns the assigned id + * + * Registers a timehandler in Net_SmartIRC, which will be called in the specified interval. + * The timehandler id is needed for unregistering the timehandler. + * + * @see example7.php + * @param integer $interval interval time in milliseconds + * @param object $object a reference to the objects of the method + * @param string $methodname the methodname that will be called when the handler happens + * @return integer assigned timehandler id + * @access public + */ + function registerTimehandler($interval, &$object, $methodname) + { + $id = $this->_timehandlerid++; + $newtimehandler = &new Net_SmartIRC_timehandler(); + + $newtimehandler->id = $id; + $newtimehandler->interval = $interval; + $newtimehandler->object = &$object; + $newtimehandler->method = $methodname; + $newtimehandler->lastmicrotimestamp = $this->_microint(); + + $this->_timehandler[] = &$newtimehandler; + $this->log(SMARTIRC_DEBUG_TIMEHANDLER, 'DEBUG_TIMEHANDLER: timehandler('.$id.') registered', __FILE__, __LINE__); + + if (($interval < $this->_mintimer) || ($this->_mintimer == false)) { + $this->_mintimer = $interval; + } + + return $id; + } + + /** + * unregisters an existing timehandler via the id + * + * @see example7.php + * @param integer $id + * @return boolean + * @access public + */ + function unregisterTimeid($id) + { + $handler = &$this->_timehandler; + $handlercount = count($handler); + for ($i = 0; $i < $handlercount; $i++) { + $handlerobject = &$handler[$i]; + + if ($handlerobject->id == $id) { + if (isset($this->_timehandler[$i])) { + unset($this->_timehandler[$i]); + } + + $this->log(SMARTIRC_DEBUG_TIMEHANDLER, 'DEBUG_TIMEHANDLER: timehandler('.$id.') unregistered', __FILE__, __LINE__); + $this->_reordertimehandler(); + $this->_updatemintimer(); + return true; + } + } + + $this->log(SMARTIRC_DEBUG_TIMEHANDLER, 'DEBUG_TIMEHANDLER: could not find timehandler id: '.$id.' _not_ unregistered', __FILE__, __LINE__); + return false; + } + + // + /** + * changes a already used nickname to a new nickname plus 3 random digits + * + * @return void + * @access private + */ + function _nicknameinuse() + { + $newnickname = substr($this->_nick, 0, 5).rand(0, 999); + $this->changeNick($newnickname, SMARTIRC_CRITICAL); + } + + /** + * sends an IRC message + * + * Adds a message to the messagequeue, with the optional priority. + * $priority: + * SMARTIRC_CRITICAL + * SMARTIRC_HIGH + * SMARTIRC_MEDIUM + * SMARTIRC_LOW + * + * @param string $data + * @param integer $priority must be one of the priority constants + * @return boolean + * @access private + */ + function _send($data, $priority = SMARTIRC_MEDIUM) + { + switch ($priority) { + case SMARTIRC_CRITICAL: + $this->_rawsend($data); + return true; + break; + case (SMARTIRC_HIGH|| + SMARTIRC_MEDIUM|| + SMARTIRC_LOW): + $this->_messagebuffer[$priority][] = $data; + return true; + break; + default: + $this->log(SMARTIRC_DEBUG_NOTICE, 'WARNING: message ('.$data.') with an invalid priority passed ('.$priority.'), message is ignored!', __FILE__, __LINE__); + return false; + } + } + + /** + * checks the buffer if there are messages to send + * + * @return void + * @access private + */ + function _checkbuffer() + { + if (!$this->_loggedin) { + return; + } + + static $highsent = 0; + static $lastmicrotimestamp = 0; + + if ($lastmicrotimestamp == 0) { + $lastmicrotimestamp = $this->_microint(); + } + + $highcount = count($this->_messagebuffer[SMARTIRC_HIGH]); + $mediumcount = count($this->_messagebuffer[SMARTIRC_MEDIUM]); + $lowcount = count($this->_messagebuffer[SMARTIRC_LOW]); + $this->_messagebuffersize = $highcount+$mediumcount+$lowcount; + + // don't send them too fast + if ($this->_microint() >= ($lastmicrotimestamp+($this->_senddelay/1000))) { + if ($highcount > 0 && $highsent <= 2) { + $this->_rawsend(array_shift($this->_messagebuffer[SMARTIRC_HIGH])); + $lastmicrotimestamp = $this->_microint(); + $highsent++; + } else if ($mediumcount > 0) { + $this->_rawsend(array_shift($this->_messagebuffer[SMARTIRC_MEDIUM])); + $lastmicrotimestamp = $this->_microint(); + $highsent = 0; + } else if ($lowcount > 0) { + $this->_rawsend(array_shift($this->_messagebuffer[SMARTIRC_LOW])); + $lastmicrotimestamp = $this->_microint(); + } + } + } + + /** + * Checks the running timers and calls the registered timehandler, + * when the interval is reached. + * + * @return void + * @access private + */ + function _checktimer() + { + if (!$this->_loggedin) { + return; + } + + // has to be count() because the array may change during the loop! + for ($i = 0; $i < count($this->_timehandler); $i++) { + $handlerobject = &$this->_timehandler[$i]; + $microtimestamp = $this->_microint(); + if ($microtimestamp >= ($handlerobject->lastmicrotimestamp+($handlerobject->interval/1000))) { + $methodobject = &$handlerobject->object; + $method = $handlerobject->method; + $handlerobject->lastmicrotimestamp = $microtimestamp; + + if (@method_exists($methodobject, $method)) { + $this->log(SMARTIRC_DEBUG_TIMEHANDLER, 'DEBUG_TIMEHANDLER: calling method "'.get_class($methodobject).'->'.$method.'"', __FILE__, __LINE__); + $methodobject->$method($this); + } + } + } + } + + /** + * Checks if a receive or transmit timeout occured and reconnects if configured + * + * @return void + * @access private + */ + function _checktimeout() + { + if ($this->_autoreconnect == true) { + $timestamp = time(); + if ($this->_lastrx < ($timestamp - $this->_rxtimeout)) { + $this->log(SMARTIRC_DEBUG_CONNECTION, 'DEBUG_CONNECTION: receive timeout detected, doing reconnect...', __FILE__, __LINE__); + $this->reconnect(); + } else if ($this->_lasttx < ($timestamp - $this->_txtimeout)) { + $this->log(SMARTIRC_DEBUG_CONNECTION, 'DEBUG_CONNECTION: transmit timeout detected, doing reconnect...', __FILE__, __LINE__); + $this->reconnect(); + } + } + } + + /** + * sends a raw message to the IRC server (don't use this!!) + * + * Use message() or _send() instead. + * + * @param string $data + * @return boolean + * @access private + */ + function _rawsend($data) + { + if ($this->_state() == SMARTIRC_STATE_CONNECTED) { + $this->log(SMARTIRC_DEBUG_IRCMESSAGES, 'DEBUG_IRCMESSAGES: sent: "'.$data.'"', __FILE__, __LINE__); + + if ($this->_usesockets == true) { + $result = @socket_write($this->_socket, $data.SMARTIRC_CRLF); + } else { + $result = @fwrite($this->_socket, $data.SMARTIRC_CRLF); + } + + + if ($result === false) { + return false; + } else { + $this->_lasttx = time(); + return true; + } + } else { + return false; + } + } + + /** + * goes into main idle loop for waiting messages from the IRC server + * + * @return void + * @access private + */ + function _rawreceive() + { + $lastpart = ''; + $rawdataar = array(); + + while ($this->_state() == SMARTIRC_STATE_CONNECTED) { + $this->_checkbuffer(); + + $timeout = $this->_selecttimeout(); + if ($this->_usesockets == true) { + $sread = array($this->_socket); + $result = @socket_select($sread, $w = null, $e = null, 0, $timeout*1000); + + if ($result == 1) { + // the socket got data to read + $rawdata = @socket_read($this->_socket, 10240); + } else if ($result === false) { + // panic! panic! something went wrong! + $this->log(SMARTIRC_DEBUG_NOTICE, 'WARNING: socket_select() returned false, something went wrong! Reason: '.socket_strerror(socket_last_error()), __FILE__, __LINE__); + exit; + } else { + // no data + $rawdata = null; + } + } else { + usleep($this->_receivedelay*1000); + $rawdata = @fread($this->_socket, 10240); + } + + $this->_checktimer(); + $this->_checktimeout(); + + if ($rawdata !== null && !empty($rawdata)) { + $this->_lastrx = time(); + $rawdata = str_replace("\r", '', $rawdata); + $rawdata = $lastpart.$rawdata; + + $lastpart = substr($rawdata, strrpos($rawdata ,"\n")+1); + $rawdata = substr($rawdata, 0, strrpos($rawdata ,"\n")); + $rawdataar = explode("\n", $rawdata); + } + + // loop through our received messages + while (count($rawdataar) > 0) { + $rawline = array_shift($rawdataar); + $validmessage = false; + + $this->log(SMARTIRC_DEBUG_IRCMESSAGES, 'DEBUG_IRCMESSAGES: received: "'.$rawline.'"', __FILE__, __LINE__); + + // building our data packet + $ircdata = &new Net_SmartIRC_data(); + $ircdata->rawmessage = $rawline; + $lineex = explode(' ', $rawline); + $ircdata->rawmessageex = $lineex; + $messagecode = $lineex[0]; + + if (substr($rawline, 0, 1) == ':') { + $validmessage = true; + $line = substr($rawline, 1); + $lineex = explode(' ', $line); + + // conform to RFC 2812 + $from = $lineex[0]; + $messagecode = $lineex[1]; + $exclamationpos = strpos($from, '!'); + $atpos = strpos($from, '@'); + $colonpos = strpos($line, ' :'); + if ($colonpos !== false) { + // we want the exact position of ":" not beginning from the space + $colonpos += 1; + } + $ircdata->nick = substr($from, 0, $exclamationpos); + $ircdata->ident = substr($from, $exclamationpos+1, ($atpos-$exclamationpos)-1); + $ircdata->host = substr($from, $atpos+1); + $ircdata->type = $this->_gettype($rawline); + $ircdata->from = $from; + if ($colonpos !== false) { + $ircdata->message = substr($line, $colonpos+1); + $ircdata->messageex = explode(' ', $ircdata->message); + } + + if ($ircdata->type & (SMARTIRC_TYPE_CHANNEL| + SMARTIRC_TYPE_ACTION| + SMARTIRC_TYPE_MODECHANGE| + SMARTIRC_TYPE_KICK| + SMARTIRC_TYPE_PART| + SMARTIRC_TYPE_JOIN)) { + $ircdata->channel = $lineex[2]; + } else if ($ircdata->type & (SMARTIRC_TYPE_WHO| + SMARTIRC_TYPE_BANLIST| + SMARTIRC_TYPE_TOPIC| + SMARTIRC_TYPE_CHANNELMODE)) { + $ircdata->channel = $lineex[3]; + } else if ($ircdata->type & SMARTIRC_TYPE_NAME) { + $ircdata->channel = $lineex[4]; + } + + if ($ircdata->channel !== null) { + if (substr($ircdata->channel, 0, 1) == ':') { + $ircdata->channel = substr($ircdata->channel, 1); + } + } + + $this->log(SMARTIRC_DEBUG_MESSAGEPARSER, 'DEBUG_MESSAGEPARSER: ircdata nick: "'.$ircdata->nick. + '" ident: "'.$ircdata->ident. + '" host: "'.$ircdata->host. + '" type: "'.$ircdata->type. + '" from: "'.$ircdata->from. + '" channel: "'.$ircdata->channel. + '" message: "'.$ircdata->message. + '"', __FILE__, __LINE__); + } + + // lets see if we have a messagehandler for it + $this->_handlemessage($messagecode, $ircdata); + + if ($validmessage == true) { + // now the actionhandlers are comming + $this->_handleactionhandler($ircdata); + } + + if (isset($ircdata)) { + unset($ircdata); + } + } + } + } + + /** + * sends the pong for keeping alive + * + * Sends the PONG signal as reply of the PING from the IRC server. + * + * @param string $data + * @return void + * @access private + */ + function _pong($data) + { + $this->log(SMARTIRC_DEBUG_CONNECTION, 'DEBUG_CONNECTION: Ping? Pong!', __FILE__, __LINE__); + $this->_send('PONG '.$data, SMARTIRC_CRITICAL); + } + + /** + * returns the calculated selecttimeout value + * + * @return integer selecttimeout in microseconds + * @access private + */ + function _selecttimeout() { + if ($this->_messagebuffersize == 0) { + $this->_selecttimeout = null; + + if ($this->_mintimer != false) { + $this->_calculateselecttimeout($this->_mintimer); + } + + if ($this->_autoreconnect == true) { + $this->_calculateselecttimeout($this->_rxtimeout*1000); + } + + $this->_calculateselecttimeout($this->_maxtimer); + return $this->_selecttimeout; + } else { + return $this->_senddelay; + } + } + + /** + * calculates the selecttimeout value + * + * @return void + * @access private + */ + function _calculateselecttimeout($microseconds) + { + if (($this->_selecttimeout > $microseconds) || $this->_selecttimeout === null) { + $this->_selecttimeout = $microseconds; + } + } + + /** + * updates _mintimer to the smallest timer interval + * + * @return void + * @access private + */ + function _updatemintimer() + { + $timerarray = array(); + foreach ($this->_timehandler as $values) { + $timerarray[] = $values->interval; + } + + $result = array_multisort($timerarray, SORT_NUMERIC, SORT_ASC); + if ($result == true && isset($timerarray[0])) { + $this->_mintimer = $timerarray[0]; + } else { + $this->_mintimer = false; + } + } + + /** + * reorders the actionhandler array, needed after removing one + * + * @return void + * @access private + */ + function _reorderactionhandler() + { + $orderedactionhandler = array(); + foreach ($this->_actionhandler as $value) { + $orderedactionhandler[] = $value; + } + $this->_actionhandler = &$orderedactionhandler; + } + + /** + * reorders the timehandler array, needed after removing one + * + * @return void + * @access private + */ + function _reordertimehandler() + { + $orderedtimehandler = array(); + foreach ($this->_timehandler as $value) { + $orderedtimehandler[] = $value; + } + $this->_timehandler = &$orderedtimehandler; + } + + /** + * reorders the modules array, needed after removing one + * + * @return void + * @access private + */ + function _reordermodules() + { + $orderedmodules = array(); + foreach ($this->_modules as $value) { + $orderedmodules[] = $value; + } + $this->_modules = &$orderedmodules; + } + + /** + * determines the messagetype of $line + * + * Analyses the type of an IRC message and returns the type. + * + * @param string $line + * @return integer SMARTIRC_TYPE_* constant + * @access private + */ + function _gettype($line) + { + if (preg_match('/^:[^ ]+? [0-9]{3} .+$/', $line) == 1) { + $lineex = explode(' ', $line); + $code = $lineex[1]; + + switch ($code) { + case SMARTIRC_RPL_WELCOME: + case SMARTIRC_RPL_YOURHOST: + case SMARTIRC_RPL_CREATED: + case SMARTIRC_RPL_MYINFO: + case SMARTIRC_RPL_BOUNCE: + return SMARTIRC_TYPE_LOGIN; + case SMARTIRC_RPL_LUSERCLIENT: + case SMARTIRC_RPL_LUSEROP: + case SMARTIRC_RPL_LUSERUNKNOWN: + case SMARTIRC_RPL_LUSERME: + case SMARTIRC_RPL_LUSERCHANNELS: + return SMARTIRC_TYPE_INFO; + case SMARTIRC_RPL_MOTDSTART: + case SMARTIRC_RPL_MOTD: + case SMARTIRC_RPL_ENDOFMOTD: + return SMARTIRC_TYPE_MOTD; + case SMARTIRC_RPL_NAMREPLY: + case SMARTIRC_RPL_ENDOFNAMES: + return SMARTIRC_TYPE_NAME; + case SMARTIRC_RPL_WHOREPLY: + case SMARTIRC_RPL_ENDOFWHO: + return SMARTIRC_TYPE_WHO; + case SMARTIRC_RPL_LISTSTART: + return SMARTIRC_TYPE_NONRELEVANT; + case SMARTIRC_RPL_LIST: + case SMARTIRC_RPL_LISTEND: + return SMARTIRC_TYPE_LIST; + case SMARTIRC_RPL_BANLIST: + case SMARTIRC_RPL_ENDOFBANLIST: + return SMARTIRC_TYPE_BANLIST; + case SMARTIRC_RPL_TOPIC: + return SMARTIRC_TYPE_TOPIC; + case SMARTIRC_RPL_WHOISUSER: + case SMARTIRC_RPL_WHOISSERVER: + case SMARTIRC_RPL_WHOISOPERATOR: + case SMARTIRC_RPL_WHOISIDLE: + case SMARTIRC_RPL_ENDOFWHOIS: + case SMARTIRC_RPL_WHOISCHANNELS: + return SMARTIRC_TYPE_WHOIS; + case SMARTIRC_RPL_WHOWASUSER: + case SMARTIRC_RPL_ENDOFWHOWAS: + return SMARTIRC_TYPE_WHOWAS; + case SMARTIRC_RPL_UMODEIS: + return SMARTIRC_TYPE_USERMODE; + case SMARTIRC_RPL_CHANNELMODEIS: + return SMARTIRC_TYPE_CHANNELMODE; + case SMARTIRC_ERR_NICKNAMEINUSE: + case SMARTIRC_ERR_NOTREGISTERED: + return SMARTIRC_TYPE_ERROR; + default: + $this->log(SMARTIRC_DEBUG_IRCMESSAGES, 'DEBUG_IRCMESSAGES: replycode UNKNOWN ('.$code.'): "'.$line.'"', __FILE__, __LINE__); + } + } + + if (preg_match('/^:.*? PRIVMSG .* :'.chr(1).'ACTION .*'.chr(1).'$/', $line) == 1) { + return SMARTIRC_TYPE_ACTION; + } else if (preg_match('/^:.*? PRIVMSG .* :'.chr(1).'.*'.chr(1).'$/', $line) == 1) { + return SMARTIRC_TYPE_CTCP; + } else if (preg_match('/^:.*? PRIVMSG (\&|\#|\+|\!).* :.*$/', $line) == 1) { + return SMARTIRC_TYPE_CHANNEL; + } else if (preg_match('/^:.*? PRIVMSG .*:.*$/', $line) == 1) { + return SMARTIRC_TYPE_QUERY; + } else if (preg_match('/^:.*? NOTICE .* :.*$/', $line) == 1) { + return SMARTIRC_TYPE_NOTICE; + } else if (preg_match('/^:.*? INVITE .* .*$/', $line) == 1) { + return SMARTIRC_TYPE_INVITE; + } else if (preg_match('/^:.*? JOIN .*$/', $line) == 1) { + return SMARTIRC_TYPE_JOIN; + } else if (preg_match('/^:.*? TOPIC .* :.*$/', $line) == 1) { + return SMARTIRC_TYPE_TOPICCHANGE; + } else if (preg_match('/^:.*? NICK .*$/', $line) == 1) { + return SMARTIRC_TYPE_NICKCHANGE; + } else if (preg_match('/^:.*? KICK .* .*$/', $line) == 1) { + return SMARTIRC_TYPE_KICK; + } else if (preg_match('/^:.*? PART .*$/', $line) == 1) { + return SMARTIRC_TYPE_PART; + } else if (preg_match('/^:.*? MODE .* .*$/', $line) == 1) { + return SMARTIRC_TYPE_MODECHANGE; + } else if (preg_match('/^:.*? QUIT :.*$/', $line) == 1) { + return SMARTIRC_TYPE_QUIT; + } else { + $this->log(SMARTIRC_DEBUG_MESSAGETYPES, 'DEBUG_MESSAGETYPES: SMARTIRC_TYPE_UNKNOWN!: "'.$line.'"', __FILE__, __LINE__); + return SMARTIRC_TYPE_UNKNOWN; + } + } + + /** + * updates the current connection state + * + * @return boolean + * @access private + */ + function _updatestate() + { + $rtype = get_resource_type($this->_socket); + if ((is_resource($this->_socket)) && + ($this->_socket !== false) && + ($rtype == 'socket' || $rtype == 'Socket' || $rtype == 'stream')) { + + $this->_state = true; + return true; + } else { + $this->_state = false; + $this->_loggedin = false; + return false; + } + } + + /** + * returns the current connection state + * + * @return integer SMARTIRC_STATE_CONNECTED or SMARTIRC_STATE_DISCONNECTED + * @access private + */ + function _state() + { + $result = $this->_updatestate(); + + if ($result == true) { + return SMARTIRC_STATE_CONNECTED; + } else { + return SMARTIRC_STATE_DISCONNECTED; + } + } + + /** + * tries to find a messagehandler for the received message ($ircdata) and calls it + * + * @param string $messagecode + * @param object $ircdata + * @return void + * @access private + */ + function _handlemessage($messagecode, &$ircdata) + { + $found = false; + + if (is_numeric($messagecode)) { + if (!array_key_exists($messagecode, $this->nreplycodes)) { + $this->log(SMARTIRC_DEBUG_MESSAGEHANDLER, 'DEBUG_MESSAGEHANDLER: ignoring unreconzied messagecode! "'.$messagecode.'"', __FILE__, __LINE__); + $this->log(SMARTIRC_DEBUG_MESSAGEHANDLER, 'DEBUG_MESSAGEHANDLER: this IRC server ('.$this->_address.') doesn\'t conform to the RFC 2812!', __FILE__, __LINE__); + return; + } + + $methodname = 'event_'.strtolower($this->nreplycodes[$messagecode]); + $_methodname = '_'.$methodname; + $_codetype = 'by numeric'; + } else if (is_string($messagecode)) { // its not numericcode so already a name/string + $methodname = 'event_'.strtolower($messagecode); + $_methodname = '_'.$methodname; + $_codetype = 'by string'; + } + + // if exists call internal method for the handling + if (@method_exists($this, $_methodname)) { + $this->log(SMARTIRC_DEBUG_MESSAGEHANDLER, 'DEBUG_MESSAGEHANDLER: calling internal method "'.get_class($this).'->'.$_methodname.'" ('.$_codetype.')', __FILE__, __LINE__); + $this->$_methodname($ircdata); + $found = true; + } + + // if exist, call user defined method for the handling + if (@method_exists($this, $methodname)) { + $this->log(SMARTIRC_DEBUG_MESSAGEHANDLER, 'DEBUG_MESSAGEHANDLER: calling user defined method "'.get_class($this).'->'.$methodname.'" ('.$_codetype.')', __FILE__, __LINE__); + $this->$methodname($ircdata); + $found = true; + } + + if ($found == false) { + $this->log(SMARTIRC_DEBUG_MESSAGEHANDLER, 'DEBUG_MESSAGEHANDLER: no method found for "'.$messagecode.'" ('.$methodname.')', __FILE__, __LINE__); + } + } + + /** + * tries to find a actionhandler for the received message ($ircdata) and calls it + * + * @param object $ircdata + * @return void + * @access private + */ + function _handleactionhandler(&$ircdata) + { + $handler = &$this->_actionhandler; + $handlercount = count($handler); + for ($i = 0; $i < $handlercount; $i++) { + $handlerobject = &$handler[$i]; + + if (substr($handlerobject->message, 0, 1) == '/') { + $regex = $handlerobject->message; + } else { + $regex = '/'.$handlerobject->message.'/'; + } + + if (($handlerobject->type & $ircdata->type) && + (preg_match($regex, $ircdata->message) == 1)) { + + $this->log(SMARTIRC_DEBUG_ACTIONHANDLER, 'DEBUG_ACTIONHANDLER: actionhandler match found for id: '.$i.' type: '.$ircdata->type.' message: "'.$ircdata->message.'" regex: "'.$regex.'"', __FILE__, __LINE__); + + $methodobject = &$handlerobject->object; + $method = $handlerobject->method; + + if (@method_exists($methodobject, $method)) { + $this->log(SMARTIRC_DEBUG_ACTIONHANDLER, 'DEBUG_ACTIONHANDLER: calling method "'.get_class($methodobject).'->'.$method.'"', __FILE__, __LINE__); + $methodobject->$method($this, $ircdata); + } else { + $this->log(SMARTIRC_DEBUG_ACTIONHANDLER, 'DEBUG_ACTIONHANDLER: method doesn\'t exist! "'.get_class($methodobject).'->'.$method.'"', __FILE__, __LINE__); + } + + break; + } + } + } + + /** + * getting current microtime, needed for benchmarks + * + * @return float + * @access private + */ + function _microint() + { + $tmp = microtime(); + $parts = explode(' ', $tmp); + $floattime = (float)$parts[0] + (float)$parts[1]; + return $floattime; + } + + /** + * adds an user to the channelobject or updates his info + * + * @param object $channel + * @param object $newuser + * @return void + * @access private + */ + function _adduser(&$channel, &$newuser) + { + $lowerednick = strtolower($newuser->nick); + if (isset($channel->users[$lowerednick])) { + $this->log(SMARTIRC_DEBUG_CHANNELSYNCING, 'DEBUG_CHANNELSYNCING: updating user: '.$newuser->nick.' on channel: '.$channel->name, __FILE__, __LINE__); + + // lets update the existing user + $currentuser = &$channel->users[$lowerednick]; + + if ($newuser->ident !== null) { + $currentuser->ident = $newuser->ident; + } + if ($newuser->host !== null) { + $currentuser->host = $newuser->host; + } + if ($newuser->realname !== null) { + $currentuser->realname = $newuser->realname; + } + if ($newuser->op !== null) { + $currentuser->op = $newuser->op; + } + if ($newuser->voice !== null) { + $currentuser->voice = $newuser->voice; + } + if ($newuser->ircop !== null) { + $currentuser->ircop = $newuser->ircop; + } + if ($newuser->away !== null) { + $currentuser->away = $newuser->away; + } + if ($newuser->server !== null) { + $currentuser->server = $newuser->server; + } + if ($newuser->hopcount !== null) { + $currentuser->hopcount = $newuser->hopcount; + } + } else { + $this->log(SMARTIRC_DEBUG_CHANNELSYNCING, 'DEBUG_CHANNELSYNCING: adding user: '.$newuser->nick.' to channel: '.$channel->name, __FILE__, __LINE__); + + // he is new just add the reference to him + $channel->users[$lowerednick] = &$newuser; + } + + $user = &$channel->users[$lowerednick]; + if ($user->op) { + $this->log(SMARTIRC_DEBUG_CHANNELSYNCING, 'DEBUG_CHANNELSYNCING: adding op: '.$user->nick.' to channel: '.$channel->name, __FILE__, __LINE__); + $channel->ops[$user->nick] = true; + } + if ($user->voice) { + $this->log(SMARTIRC_DEBUG_CHANNELSYNCING, 'DEBUG_CHANNELSYNCING: adding voice: '.$user->nick.' to channel: '.$channel->name, __FILE__, __LINE__); + $channel->voices[$user->nick] = true; + } + } + + /** + * removes an user from one channel or all if he quits + * + * @param object $ircdata + * @return void + * @access private + */ + function _removeuser(&$ircdata) + { + if ($ircdata->type & (SMARTIRC_TYPE_PART|SMARTIRC_TYPE_QUIT)) { + $nick = $ircdata->nick; + } else if ($ircdata->type & SMARTIRC_TYPE_KICK) { + $nick = $ircdata->rawmessageex[3]; + } else { + $this->log(SMARTIRC_DEBUG_CHANNELSYNCING, 'DEBUG_CHANNELSYNCING: unknown TYPE ('.$ircdata->type.') in _removeuser(), trying default', __FILE__, __LINE__); + $nick = $ircdata->nick; + } + + $lowerednick = strtolower($nick); + + if ($this->_nick == $nick) { + $this->log(SMARTIRC_DEBUG_CHANNELSYNCING, 'DEBUG_CHANNELSYNCING: we left channel: '.$ircdata->channel.' destroying...', __FILE__, __LINE__); + unset($this->_channels[strtolower($ircdata->channel)]); + } else { + if ($ircdata->type & SMARTIRC_TYPE_QUIT) { + $this->log(SMARTIRC_DEBUG_CHANNELSYNCING, 'DEBUG_CHANNELSYNCING: user '.$nick.' quit, removing him from all channels', __FILE__, __LINE__); + // remove the user from all channels + foreach ($this->_channels as $channelkey => $channelvalue) { + // loop through all channels + $channel = &$this->_channels[$channelkey]; + foreach ($channel->users as $userkey => $uservalue) { + // loop through all user in this channel + + if ($nick == $uservalue->nick) { + // found him + // kill him + $this->log(SMARTIRC_DEBUG_CHANNELSYNCING, 'DEBUG_CHANNELSYNCING: found him on channel: '.$channel->name.' destroying...', __FILE__, __LINE__); + unset($channel->users[$lowerednick]); + + if (isset($channel->ops[$nick])) { + // die! + $this->log(SMARTIRC_DEBUG_CHANNELSYNCING, 'DEBUG_CHANNELSYNCING: removing him from op list', __FILE__, __LINE__); + unset($channel->ops[$nick]); + } + + if (isset($channel->voices[$nick])) { + // die!! + $this->log(SMARTIRC_DEBUG_CHANNELSYNCING, 'DEBUG_CHANNELSYNCING: removing him from voice list', __FILE__, __LINE__); + unset($channel->voices[$nick]); + } + + // ups this was not DukeNukem 3D + } + } + } + } else { + $this->log(SMARTIRC_DEBUG_CHANNELSYNCING, 'DEBUG_CHANNELSYNCING: removing user: '.$nick.' from channel: '.$ircdata->channel, __FILE__, __LINE__); + $channel = &$this->_channels[strtolower($ircdata->channel)]; + unset($channel->users[$lowerednick]); + + if (isset($channel->ops[$nick])) { + $this->log(SMARTIRC_DEBUG_CHANNELSYNCING, 'DEBUG_CHANNELSYNCING: removing him from op list', __FILE__, __LINE__); + unset($channel->ops[$nick]); + } + + if (isset($channel->voices[$nick])) { + $this->log(SMARTIRC_DEBUG_CHANNELSYNCING, 'DEBUG_CHANNELSYNCING: removing him from voice list', __FILE__, __LINE__); + unset($channel->voices[$nick]); + } + } + } + } + + /** + * @return void + * @access private + */ + function _checkPHPVersion() + { + // doing nothing at the moment + } + + /** + * checks if the passed handlertype is valid + * + * @param integer $handlertype + * @return boolean + * @access private + */ + function _isValidType($handlertype) { + if ($handlertype & SMARTIRC_TYPE_ALL ) { + return true; + } else { + return false; + } + } + + // + + function isError($object) { + return (bool)(is_object($object) && (strtolower(get_class($object)) == 'net_smartirc_error')); + } + + function &throwError($message) { + return new Net_SmartIRC_Error($message); + } +} + +class Net_SmartIRC extends Net_SmartIRC_messagehandler +{ + // empty +} + +/** + * @access public + */ +class Net_SmartIRC_data +{ + /** + * @var string + * @access public + */ + var $from; + + /** + * @var string + * @access public + */ + var $nick; + + /** + * @var string + * @access public + */ + var $ident; + + /** + * @var string + * @access public + */ + var $host; + + /** + * @var string + * @access public + */ + var $channel; + + /** + * @var string + * @access public + */ + var $message; + + /** + * @var array + * @access public + */ + var $messageex = array(); + + /** + * @var integer + * @access public + */ + var $type; + + /** + * @var string + * @access public + */ + var $rawmessage; + + /** + * @var array + * @access public + */ + var $rawmessageex = array(); +} + +/** + * @access public + */ +class Net_SmartIRC_actionhandler +{ + /** + * @var integer + * @access public + */ + var $id; + + /** + * @var integer + * @access public + */ + var $type; + + /** + * @var string + * @access public + */ + var $message; + + /** + * @var object + * @access public + */ + var $object; + + /** + * @var string + * @access public + */ + var $method; +} + +/** + * @access public + */ +class Net_SmartIRC_timehandler +{ + /** + * @var integer + * @access public + */ + var $id; + + /** + * @var integer + * @access public + */ + var $interval; + + /** + * @var integer + * @access public + */ + var $lastmicrotimestamp; + + /** + * @var object + * @access public + */ + var $object; + + /** + * @var string + * @access public + */ + var $method; +} + +/** + * @access public + */ +class Net_SmartIRC_channel +{ + /** + * @var string + * @access public + */ + var $name; + + /** + * @var string + * @access public + */ + var $key; + + /** + * @var array + * @access public + */ + var $users = array(); + + /** + * @var array + * @access public + */ + var $ops = array(); + + /** + * @var array + * @access public + */ + var $voices = array(); + + /** + * @var array + * @access public + */ + var $bans = array(); + + /** + * @var string + * @access public + */ + var $topic; + + /** + * @var string + * @access public + */ + var $mode; +} + +/** + * @access public + */ +class Net_SmartIRC_user +{ + /** + * @var string + * @access public + */ + var $nick; + + /** + * @var string + * @access public + */ + var $ident; + + /** + * @var string + * @access public + */ + var $host; + + /** + * @var string + * @access public + */ + var $realname; + + /** + * @var boolean + * @access public + */ + var $ircop; + + /** + * @var boolean + * @access public + */ + var $away; + + /** + * @var string + * @access public + */ + var $server; + + /** + * @var integer + * @access public + */ + var $hopcount; +} + +/** + * @access public + */ +class Net_SmartIRC_channeluser extends Net_SmartIRC_user +{ + /** + * @var boolean + * @access public + */ + var $op; + + /** + * @var boolean + * @access public + */ + var $voice; +} + +/** + * @access public + */ +class Net_SmartIRC_ircuser extends Net_SmartIRC_user +{ + /** + * @var array + * @access public + */ + var $joinedchannels = array(); +} + +/** + * @access public + */ +class Net_SmartIRC_listenfor +{ + /** + * @var array + * @access public + */ + var $result = array(); + + /** + * stores the received answer into the result array + * + * @param object $irc + * @param object $ircdata + * @return void + */ + function handler(&$irc, &$ircdata) + { + $irc->log(SMARTIRC_DEBUG_ACTIONHANDLER, 'DEBUG_ACTIONHANDLER: listenfor handler called', __FILE__, __LINE__); + $this->result[] = $ircdata->message; + $irc->disconnect(true); + } +} + +// so we don't break BC! +/** + * @access public + */ +class Net_SmartIRC_objListenFor +{ + /** + * @var array + * @access public + */ + var $result = array(); + + /** + * stores the received answer into the result array + * + * @param object $irc + * @param object $ircdata + * @return void + */ + function handler(&$irc, &$ircdata) + { + $irc->log(SMARTIRC_DEBUG_ACTIONHANDLER, 'DEBUG_ACTIONHANDLER: objListenFor handler called', __FILE__, __LINE__); + $this->result[] = $ircdata; + $irc->disconnect(true); + } +} + +class Net_SmartIRC_Error +{ + var $error_msg; + + function Net_SmartIRC_Error($message) + { + $this->error_msg = $message; + } + + function getMessage() + { + return $this->error_msg; + } +} +?> \ No newline at end of file diff --git a/tools/IRC_Bot/SmartIRC/defines.php b/tools/IRC_Bot/SmartIRC/defines.php new file mode 100644 index 000000000..c095b13fc --- /dev/null +++ b/tools/IRC_Bot/SmartIRC/defines.php @@ -0,0 +1,234 @@ + + * + * Full LGPL License: + * + * 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 + */ + +// don't change this! unless you know what you do +define('SMARTIRC_CRLF', "\r\n"); +define('SMARTIRC_UNUSED', '*'); +define('SMARTIRC_STDOUT', 0); +define('SMARTIRC_FILE', 1); +define('SMARTIRC_SYSLOG', 2); +define('SMARTIRC_BROWSEROUT', 3); +define('SMARTIRC_NONE', 4); +define('SMARTIRC_LOW', 0); +define('SMARTIRC_MEDIUM', 1); +define('SMARTIRC_HIGH', 2); +define('SMARTIRC_CRITICAL', 3); +define('SMARTIRC_STATE_DISCONNECTED', 0); +define('SMARTIRC_STATE_CONNECTING', 1); +define('SMARTIRC_STATE_CONNECTED', 2); +define('SMARTIRC_DEBUG_NONE', 0); +define('SMARTIRC_DEBUG_NOTICE', 1); +define('SMARTIRC_DEBUG_CONNECTION', 2); +define('SMARTIRC_DEBUG_SOCKET', 4); +define('SMARTIRC_DEBUG_IRCMESSAGES', 8); +define('SMARTIRC_DEBUG_MESSAGETYPES', 16); +define('SMARTIRC_DEBUG_ACTIONHANDLER', 32); +define('SMARTIRC_DEBUG_TIMEHANDLER', 64); +define('SMARTIRC_DEBUG_MESSAGEHANDLER', 128); +define('SMARTIRC_DEBUG_CHANNELSYNCING', 256); +define('SMARTIRC_DEBUG_MODULES', 512); +define('SMARTIRC_DEBUG_USERSYNCING', 1024); +define('SMARTIRC_DEBUG_MESSAGEPARSER', 2048); +define('SMARTIRC_DEBUG_ALL', 4095); +define('SMARTIRC_TYPE_UNKNOWN', 1); +define('SMARTIRC_TYPE_CHANNEL', 2); +define('SMARTIRC_TYPE_QUERY', 4); +define('SMARTIRC_TYPE_CTCP', 8); +define('SMARTIRC_TYPE_NOTICE', 16); +define('SMARTIRC_TYPE_WHO', 32); +define('SMARTIRC_TYPE_JOIN', 64); +define('SMARTIRC_TYPE_INVITE', 128); +define('SMARTIRC_TYPE_ACTION', 256); +define('SMARTIRC_TYPE_TOPICCHANGE', 512); +define('SMARTIRC_TYPE_NICKCHANGE', 1024); +define('SMARTIRC_TYPE_KICK', 2048); +define('SMARTIRC_TYPE_QUIT', 4096); +define('SMARTIRC_TYPE_LOGIN', 8192); +define('SMARTIRC_TYPE_INFO', 16384); +define('SMARTIRC_TYPE_LIST', 32768); +define('SMARTIRC_TYPE_NAME', 65536); +define('SMARTIRC_TYPE_MOTD', 131072); +define('SMARTIRC_TYPE_MODECHANGE', 262144); +define('SMARTIRC_TYPE_PART', 524288); +define('SMARTIRC_TYPE_ERROR', 1048576); +define('SMARTIRC_TYPE_BANLIST', 2097152); +define('SMARTIRC_TYPE_TOPIC', 4194304); +define('SMARTIRC_TYPE_NONRELEVANT', 8388608); +define('SMARTIRC_TYPE_WHOIS', 16777216); +define('SMARTIRC_TYPE_WHOWAS', 33554432); +define('SMARTIRC_TYPE_USERMODE', 67108864); +define('SMARTIRC_TYPE_CHANNELMODE', 134217728); +define('SMARTIRC_TYPE_CTCP_REQUEST', 268435456); +define('SMARTIRC_TYPE_CTCP_REPLY', 536870912); +define('SMARTIRC_TYPE_ALL', 1073741823); + +$SMARTIRC_replycodes = array( +'RPL_WELCOME' => '001', +'RPL_YOURHOST' => '002', +'RPL_CREATED' => '003', +'RPL_MYINFO' => '004', +'RPL_BOUNCE' => '005', +'RPL_TRACELINK' => '200', +'RPL_TRACECONNECTING' => '201', +'RPL_TRACEHANDSHAKE' => '202', +'RPL_TRACEUNKNOWN' => '203', +'RPL_TRACEOPERATOR' => '204', +'RPL_TRACEUSER' => '205', +'RPL_TRACESERVER' => '206', +'RPL_TRACESERVICE' => '207', +'RPL_TRACENEWTYPE' => '208', +'RPL_TRACECLASS' => '209', +'RPL_TRACERECONNECT' => '210', +'RPL_STATSLINKINFO' => '211', +'RPL_STATSCOMMANDS' => '212', +'RPL_ENDOFSTATS' => '219', +'RPL_UMODEIS' => '221', +'RPL_SERVLIST' => '234', +'RPL_SERVLISTEND' => '235', +'RPL_STATSUPTIME' => '242', +'RPL_STATSOLINE' => '243', +'RPL_LUSERCLIENT' => '251', +'RPL_LUSEROP' => '252', +'RPL_LUSERUNKNOWN' => '253', +'RPL_LUSERCHANNELS' => '254', +'RPL_LUSERME' => '255', +'RPL_ADMINME' => '256', +'RPL_ADMINLOC1' => '257', +'RPL_ADMINLOC2' => '258', +'RPL_ADMINEMAIL' => '259', +'RPL_TRACELOG' => '261', +'RPL_TRACEEND' => '262', +'RPL_TRYAGAIN' => '263', +'RPL_AWAY' => '301', +'RPL_USERHOST' => '302', +'RPL_ISON' => '303', +'RPL_UNAWAY' => '305', +'RPL_NOWAWAY' => '306', +'RPL_WHOISUSER' => '311', +'RPL_WHOISSERVER' => '312', +'RPL_WHOISOPERATOR' => '313', +'RPL_WHOWASUSER' => '314', +'RPL_ENDOFWHO' => '315', +'RPL_WHOISIDLE' => '317', +'RPL_ENDOFWHOIS' => '318', +'RPL_WHOISCHANNELS' => '319', +'RPL_LISTSTART' => '321', +'RPL_LIST' => '322', +'RPL_LISTEND' => '323', +'RPL_CHANNELMODEIS' => '324', +'RPL_UNIQOPIS' => '325', +'RPL_NOTOPIC' => '331', +'RPL_TOPIC' => '332', +'RPL_INVITING' => '341', +'RPL_SUMMONING' => '342', +'RPL_INVITELIST' => '346', +'RPL_ENDOFINVITELIST' => '347', +'RPL_EXCEPTLIST' => '348', +'RPL_ENDOFEXCEPTLIST' => '349', +'RPL_VERSION' => '351', +'RPL_WHOREPLY' => '352', +'RPL_NAMREPLY' => '353', +'RPL_LINKS' => '364', +'RPL_ENDOFLINKS' => '365', +'RPL_ENDOFNAMES' => '366', +'RPL_BANLIST' => '367', +'RPL_ENDOFBANLIST' => '368', +'RPL_ENDOFWHOWAS' => '369', +'RPL_INFO' => '371', +'RPL_MOTD' => '372', +'RPL_ENDOFINFO' => '374', +'RPL_MOTDSTART' => '375', +'RPL_ENDOFMOTD' => '376', +'RPL_YOUREOPER' => '381', +'RPL_REHASHING' => '382', +'RPL_YOURESERVICE' => '383', +'RPL_TIME' => '391', +'RPL_USERSSTART' => '392', +'RPL_USERS' => '393', +'RPL_ENDOFUSERS' => '394', +'RPL_NOUSERS' => '395', +'ERR_NOSUCHNICK' => '401', +'ERR_NOSUCHSERVER' => '402', +'ERR_NOSUCHCHANNEL' => '403', +'ERR_CANNOTSENDTOCHAN' => '404', +'ERR_TOOMANYCHANNELS' => '405', +'ERR_WASNOSUCHNICK' => '406', +'ERR_TOOMANYTARGETS' => '407', +'ERR_NOSUCHSERVICE' => '408', +'ERR_NOORIGIN' => '409', +'ERR_NORECIPIENT' => '411', +'ERR_NOTEXTTOSEND' => '412', +'ERR_NOTOPLEVEL' => '413', +'ERR_WILDTOPLEVEL' => '414', +'ERR_BADMASK' => '415', +'ERR_UNKNOWNCOMMAND' => '421', +'ERR_NOMOTD' => '422', +'ERR_NOADMININFO' => '423', +'ERR_FILEERROR' => '424', +'ERR_NONICKNAMEGIVEN' => '431', +'ERR_ERRONEUSNICKNAME' => '432', +'ERR_NICKNAMEINUSE' => '433', +'ERR_NICKCOLLISION' => '436', +'ERR_UNAVAILRESOURCE' => '437', +'ERR_USERNOTINCHANNEL' => '441', +'ERR_NOTONCHANNEL' => '442', +'ERR_USERONCHANNEL' => '443', +'ERR_NOLOGIN' => '444', +'ERR_SUMMONDISABLED' => '445', +'ERR_USERSDISABLED' => '446', +'ERR_NOTREGISTERED' => '451', +'ERR_NEEDMOREPARAMS' => '461', +'ERR_ALREADYREGISTRED' => '462', +'ERR_NOPERMFORHOST' => '463', +'ERR_PASSWDMISMATCH' => '464', +'ERR_YOUREBANNEDCREEP' => '465', +'ERR_YOUWILLBEBANNED' => '466', +'ERR_KEYSET' => '467', +'ERR_CHANNELISFULL' => '471', +'ERR_UNKNOWNMODE' => '472', +'ERR_INVITEONLYCHAN' => '473', +'ERR_BANNEDFROMCHAN' => '474', +'ERR_BADCHANNELKEY' => '475', +'ERR_BADCHANMASK' => '476', +'ERR_NOCHANMODES' => '477', +'ERR_BANLISTFULL' => '478', +'ERR_NOPRIVILEGES' => '481', +'ERR_CHANOPRIVSNEEDED' => '482', +'ERR_CANTKILLSERVER' => '483', +'ERR_RESTRICTED' => '484', +'ERR_UNIQOPPRIVSNEEDED' => '485', +'ERR_NOOPERHOST' => '491', +'ERR_UMODEUNKNOWNFLAG' => '501', +'ERR_USERSDONTMATCH' => '502', +); + +$SMARTIRC_nreplycodes = array(); + +foreach ($SMARTIRC_replycodes as $key => $value) { + define('SMARTIRC_'.$key, $value); + $SMARTIRC_nreplycodes[$value] = $key; +} +?> \ No newline at end of file diff --git a/tools/IRC_Bot/SmartIRC/irccommands.php b/tools/IRC_Bot/SmartIRC/irccommands.php new file mode 100644 index 000000000..3c7b76c13 --- /dev/null +++ b/tools/IRC_Bot/SmartIRC/irccommands.php @@ -0,0 +1,433 @@ + + * + * Full LGPL License: + * + * 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 + */ + +class Net_SmartIRC_irccommands extends Net_SmartIRC_base +{ + /** + * sends a new message + * + * Sends a message to a channel or user. + * + * @see DOCUMENTATION + * @param integer $type specifies the type, like QUERY/ACTION or CTCP see 'Message Types' + * @param string $destination can be a user or channel + * @param string $message the message + * @return boolean + * @access public + */ + function message($type, $destination, $message, $priority = SMARTIRC_MEDIUM) + { + switch ($type) { + case SMARTIRC_TYPE_CHANNEL: + case SMARTIRC_TYPE_QUERY: + $this->_send('PRIVMSG '.$destination.' :'.$message, $priority); + break; + case SMARTIRC_TYPE_ACTION: + $this->_send('PRIVMSG '.$destination.' :'.chr(1).'ACTION '.$message.chr(1), $priority); + break; + case SMARTIRC_TYPE_NOTICE: + $this->_send('NOTICE '.$destination.' :'.$message, $priority); + break; + case SMARTIRC_TYPE_CTCP: // backwards compatibilty + case SMARTIRC_TYPE_CTCP_REPLY: + $this->_send('NOTICE '.$destination.' :'.chr(1).$message.chr(1), $priority); + break; + case SMARTIRC_TYPE_CTCP_REQUEST: + $this->_send('PRIVMSG '.$destination.' :'.chr(1).$message.chr(1), $priority); + break; + default: + return false; + } + + return true; + } + + /** + * returns an object reference to the specified channel + * + * If the channel does not exist (because not joint) false will be returned. + * + * @param string $channelname + * @return object reference to the channel object + * @access public + */ + function &channel($channelname) + { + if (isset($this->_channels[strtolower($channelname)])) { + return $this->_channels[strtolower($channelname)]; + } else { + return false; + } + } + + // + /** + * Joins one or more IRC channels with an optional key. + * + * @param mixed $channelarray + * @param string $key + * @param integer $priority message priority, default is SMARTIRC_MEDIUM + * @return void + * @access public + */ + function join($channelarray, $key = null, $priority = SMARTIRC_MEDIUM) + { + if (!is_array($channelarray)) { + $channelarray = array($channelarray); + } + + $channellist = implode(',', $channelarray); + + if ($key !== null) { + $this->_send('JOIN '.$channellist.' '.$key, $priority); + } else { + $this->_send('JOIN '.$channellist, $priority); + } + } + + /** + * parts from one or more IRC channels with an optional reason + * + * @param mixed $channelarray + * @param string $reason + * @param integer $priority message priority, default is SMARTIRC_MEDIUM + * @return void + * @access public + */ + function part($channelarray, $reason = null, $priority = SMARTIRC_MEDIUM) + { + if (!is_array($channelarray)) { + $channelarray = array($channelarray); + } + + $channellist = implode(',', $channelarray); + + if ($reason !== null) { + $this->_send('PART '.$channellist.' :'.$reason, $priority); + } else { + $this->_send('PART '.$channellist, $priority); + } + } + + /** + * Kicks one or more user from an IRC channel with an optional reason. + * + * @param string $channel + * @param mixed $nicknamearray + * @param string $reason + * @param integer $priority message priority, default is SMARTIRC_MEDIUM + * @return void + * @access public + */ + function kick($channel, $nicknamearray, $reason = null, $priority = SMARTIRC_MEDIUM) + { + if (!is_array($nicknamearray)) { + $nicknamearray = array($nicknamearray); + } + + $nicknamelist = implode(',', $nicknamearray); + + if ($reason !== null) { + $this->_send('KICK '.$channel.' '.$nicknamelist.' :'.$reason, $priority); + } else { + $this->_send('KICK '.$channel.' '.$nicknamelist, $priority); + } + } + + /** + * gets a list of one ore more channels + * + * Requests a full channellist if $channelarray is not given. + * (use it with care, usualy its a looooong list) + * + * @param mixed $channelarray + * @param integer $priority message priority, default is SMARTIRC_MEDIUM + * @return void + * @access public + */ + function getList($channelarray = null, $priority = SMARTIRC_MEDIUM) + { + if ($channelarray !== null) { + if (!is_array($channelarray)) { + $channelarray = array($channelarray); + } + + $channellist = implode(',', $channelarray); + $this->_send('LIST '.$channellist, $priority); + } else { + $this->_send('LIST', $priority); + } + } + + /** + * requests all nicknames of one or more channels + * + * The requested nickname list also includes op and voice state + * + * @param mixed $channelarray + * @param integer $priority message priority, default is SMARTIRC_MEDIUM + * @return void + * @access public + */ + function names($channelarray = null, $priority = SMARTIRC_MEDIUM) + { + if ($channelarray !== null) { + if (!is_array($channelarray)) { + $channelarray = array($channelarray); + } + + $channellist = implode(',', $channelarray); + $this->_send('NAMES '.$channellist, $priority); + } else { + $this->_send('NAMES', $priority); + } + } + + /** + * sets a new topic of a channel + * + * @param string $channel + * @param string $newtopic + * @param integer $priority message priority, default is SMARTIRC_MEDIUM + * @return void + * @access public + */ + function setTopic($channel, $newtopic, $priority = SMARTIRC_MEDIUM) + { + $this->_send('TOPIC '.$channel.' :'.$newtopic, $priority); + } + + /** + * gets the topic of a channel + * + * @param string $channel + * @param integer $priority message priority, default is SMARTIRC_MEDIUM + * @return void + * @access public + */ + function getTopic($channel, $priority = SMARTIRC_MEDIUM) + { + $this->_send('TOPIC '.$channel, $priority); + } + + /** + * sets or gets the mode of an user or channel + * + * Changes/requests the mode of the given target. + * + * @param string $target the target, can be an user (only yourself) or a channel + * @param string $newmode the new mode like +mt + * @param integer $priority message priority, default is SMARTIRC_MEDIUM + * @return void + * @access public + */ + function mode($target, $newmode = null, $priority = SMARTIRC_MEDIUM) + { + if ($newmode !== null) { + $this->_send('MODE '.$target.' '.$newmode, $priority); + } else { + $this->_send('MODE '.$target, $priority); + } + } + + /** + * ops an user in the given channel + * + * @param string $channel + * @param string $nickname + * @param integer $priority message priority, default is SMARTIRC_MEDIUM + * @return void + * @access public + */ + function op($channel, $nickname, $priority = SMARTIRC_MEDIUM) + { + $this->mode($channel, '+o '.$nickname, $priority); + } + + /** + * deops an user in the given channel + * + * @param string $channel + * @param string $nickname + * @param integer $priority message priority, default is SMARTIRC_MEDIUM + * @return void + * @access public + */ + function deop($channel, $nickname, $priority = SMARTIRC_MEDIUM) + { + $this->mode($channel, '-o '.$nickname, $priority); + } + + /** + * voice a user in the given channel + * + * @param string $channel + * @param string $nickname + * @param integer $priority message priority, default is SMARTIRC_MEDIUM + * @return void + * @access public + */ + function voice($channel, $nickname, $priority = SMARTIRC_MEDIUM) + { + $this->mode($channel, '+v '.$nickname, $priority); + } + + /** + * devoice a user in the given channel + * + * @param string $channel + * @param string $nickname + * @param integer $priority message priority, default is SMARTIRC_MEDIUM + * @return void + * @access public + */ + function devoice($channel, $nickname, $priority = SMARTIRC_MEDIUM) + { + $this->mode($channel, '-v '.$nickname, $priority); + } + + /** + * bans a hostmask for the given channel or requests the current banlist + * + * The banlist will be requested if no hostmask is specified + * + * @param string $channel + * @param string $hostmask + * @param integer $priority message priority, default is SMARTIRC_MEDIUM + * @return void + * @access public + */ + function ban($channel, $hostmask = null, $priority = SMARTIRC_MEDIUM) + { + if ($hostmask !== null) { + $this->mode($channel, '+b '.$hostmask, $priority); + } else { + $this->mode($channel, 'b', $priority); + } + } + + /** + * unbans a hostmask on the given channel + * + * @param string $channel + * @param string $hostmask + * @param integer $priority message priority, default is SMARTIRC_MEDIUM + * @return void + * @access public + */ + function unban($channel, $hostmask, $priority = SMARTIRC_MEDIUM) + { + $this->mode($channel, '-b '.$hostmask, $priority); + } + + /** + * invites a user to the specified channel + * + * @param string $nickname + * @param string $channel + * @param integer $priority message priority, default is SMARTIRC_MEDIUM + * @return void + * @access public + */ + function invite($nickname, $channel, $priority = SMARTIRC_MEDIUM) + { + $this->_send('INVITE '.$nickname.' '.$channel, $priority); + } + + /** + * changes the own nickname + * + * Trys to set a new nickname, nickcollisions are handled. + * + * @param string $newnick + * @param integer $priority message priority, default is SMARTIRC_MEDIUM + * @return void + * @access public + */ + function changeNick($newnick, $priority = SMARTIRC_MEDIUM) + { + $this->_send('NICK '.$newnick, $priority); + $this->_nick = $newnick; + } + + /** + * requests a 'WHO' from the specified target + * + * @param string $target + * @param integer $priority message priority, default is SMARTIRC_MEDIUM + * @return void + * @access public + */ + function who($target, $priority = SMARTIRC_MEDIUM) + { + $this->_send('WHO '.$target, $priority); + } + + /** + * requests a 'WHOIS' from the specified target + * + * @param string $target + * @param integer $priority message priority, default is SMARTIRC_MEDIUM + * @return void + * @access public + */ + function whois($target, $priority = SMARTIRC_MEDIUM) + { + $this->_send('WHOIS '.$target, $priority); + } + + /** + * requests a 'WHOWAS' from the specified target + * (if he left the IRC network) + * + * @param string $target + * @param integer $priority message priority, default is SMARTIRC_MEDIUM + * @return void + * @access public + */ + function whowas($target, $priority = SMARTIRC_MEDIUM) + { + $this->_send('WHOWAS '.$target, $priority); + } + + /** + * sends QUIT to IRC server and disconnects + * + * @param string $quitmessage optional quitmessage + * @param integer $priority message priority, default is SMARTIRC_MEDIUM + * @return void + * @access public + */ + function quit($quitmessage = null, $priority = SMARTIRC_MEDIUM) + { + if ($quitmessage !== null) { + $this->_send('QUIT :'.$quitmessage, $priority); + } else { + $this->_send('QUIT', $priority); + } + } +} +?> \ No newline at end of file diff --git a/tools/IRC_Bot/SmartIRC/messagehandler.php b/tools/IRC_Bot/SmartIRC/messagehandler.php new file mode 100644 index 000000000..54c46169e --- /dev/null +++ b/tools/IRC_Bot/SmartIRC/messagehandler.php @@ -0,0 +1,411 @@ + + * + * Full LGPL License: + * + * 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 + */ + +class Net_SmartIRC_messagehandler extends Net_SmartIRC_irccommands +{ + /* misc */ + function _event_ping(&$ircdata) + { + $this->_pong(substr($ircdata->rawmessage, 5)); + } + + function _event_error(&$ircdata) + { + if ($this->_autoretry == true) { + $this->reconnect(); + } else { + $this->disconnect(true); + } + } + + function _event_join(&$ircdata) + { + if ($this->_channelsyncing == true) { + if ($this->_nick == $ircdata->nick) { + $this->log(SMARTIRC_DEBUG_CHANNELSYNCING, 'DEBUG_CHANNELSYNCING: joining channel: '.$ircdata->channel, __FILE__, __LINE__); + $channel = &new Net_SmartIRC_channel(); + $channel->name = $ircdata->channel; + $this->_channels[strtolower($channel->name)] = &$channel; + + $this->who($channel->name); + $this->mode($channel->name); + $this->ban($channel->name); + } + + $this->log(SMARTIRC_DEBUG_CHANNELSYNCING, 'DEBUG_CHANNELSYNCING: '.$ircdata->nick.' joins channel: '.$ircdata->channel, __FILE__, __LINE__); + $channel = &$this->_channels[strtolower($ircdata->channel)]; + $user = &new Net_SmartIRC_channeluser(); + $user->nick = $ircdata->nick; + $user->ident = $ircdata->ident; + $user->host = $ircdata->host; + + $this->_adduser($channel, $user); + $this->who($user->nick); + } + } + + function _event_part(&$ircdata) + { + if ($this->_channelsyncing == true) { + $this->_removeuser($ircdata); + } + } + + function _event_kick(&$ircdata) + { + if ($this->_channelsyncing == true) { + $this->_removeuser($ircdata); + } + } + + function _event_quit(&$ircdata) + { + if ($this->_channelsyncing == true) { + $this->_removeuser($ircdata); + } + } + + function _event_nick(&$ircdata) + { + if ($this->_channelsyncing == true) { + $newnick = substr($ircdata->rawmessageex[2], 1); + $lowerednewnick = strtolower($newnick); + $lowerednick = strtolower($ircdata->nick); + + foreach ($this->_channels as $channelkey => $channelvalue) { + // loop through all channels + $channel = &$this->_channels[$channelkey]; + foreach ($channel->users as $userkey => $uservalue) { + // loop through all user in this channel + + if ($ircdata->nick == $uservalue->nick) { + // found him + // time for updating the object and his nickname + $channel->users[$lowerednewnick] = $channel->users[$lowerednick]; + $channel->users[$lowerednewnick]->nick = $newnick; + + if ($lowerednewnick != $lowerednick) { + unset($channel->users[$lowerednick]); + } + + // he was maybe op or voice, update comming + if (isset($channel->ops[$ircdata->nick])) { + $channel->ops[$newnick] = $channel->ops[$ircdata->nick]; + unset($channel->ops[$ircdata->nick]); + } + if (isset($channel->voices[$ircdata->nick])) { + $channel->voices[$newnick] = $channel->voices[$ircdata->nick]; + unset($channel->voices[$ircdata->nick]); + } + + break; + } + } + } + } + } + + function _event_mode(&$ircdata) + { + // check if its own usermode + if ($ircdata->rawmessageex[2] == $this->_nick) { + $this->_usermode = substr($ircdata->rawmessageex[3], 1); + } else if ($this->_channelsyncing == true) { + // it's not, and we do channel syching + $channel = &$this->_channels[strtolower($ircdata->channel)]; + $this->log(SMARTIRC_DEBUG_CHANNELSYNCING, 'DEBUG_CHANNELSYNCING: updating channel mode for: '.$channel->name, __FILE__, __LINE__); + $mode = $ircdata->rawmessageex[3]; + $parameters = array_slice($ircdata->rawmessageex, 4); + + $add = false; + $remove = false; + $channelmode = ''; + $modelength = strlen($mode); + for ($i = 0; $i < $modelength; $i++) { + switch($mode[$i]) { + case '-': + $remove = true; + $add = false; + break; + case '+': + $add = true; + $remove = false; + break; + // user modes + case 'o': + $nick = array_shift($parameters); + $lowerednick = strtolower($nick); + if ($add) { + $this->log(SMARTIRC_DEBUG_CHANNELSYNCING, 'DEBUG_CHANNELSYNCING: adding op: '.$nick.' to channel: '.$channel->name, __FILE__, __LINE__); + $channel->ops[$nick] = true; + $channel->users[$lowerednick]->op = true; + } + if ($remove) { + $this->log(SMARTIRC_DEBUG_CHANNELSYNCING, 'DEBUG_CHANNELSYNCING: removing op: '.$nick.' to channel: '.$channel->name, __FILE__, __LINE__); + unset($channel->ops[$nick]); + $channel->users[$lowerednick]->op = false; + } + break; + case 'v': + $nick = array_shift($parameters); + $lowerednick = strtolower($nick); + if ($add) { + $this->log(SMARTIRC_DEBUG_CHANNELSYNCING, 'DEBUG_CHANNELSYNCING: adding voice: '.$nick.' to channel: '.$channel->name, __FILE__, __LINE__); + $channel->voices[$nick] = true; + $channel->users[$lowerednick]->voice = true; + } + if ($remove) { + $this->log(SMARTIRC_DEBUG_CHANNELSYNCING, 'DEBUG_CHANNELSYNCING: removing voice: '.$nick.' to channel: '.$channel->name, __FILE__, __LINE__); + unset($channel->voices[$nick]); + $channel->users[$lowerednick]->voice = false; + } + break; + case 'k': + $key = array_shift($parameters); + if ($add) { + $this->log(SMARTIRC_DEBUG_CHANNELSYNCING, 'DEBUG_CHANNELSYNCING: stored channel key for: '.$channel->name, __FILE__, __LINE__); + $channel->key = $key; + } + if ($remove) { + $this->log(SMARTIRC_DEBUG_CHANNELSYNCING, 'DEBUG_CHANNELSYNCING: removed channel key for: '.$channel->name, __FILE__, __LINE__); + $channel->key = ''; + } + break; + default: + // channel modes + if ($mode[$i] == 'b') { + $hostmask = array_shift($parameters); + if ($add) { + $this->log(SMARTIRC_DEBUG_CHANNELSYNCING, 'DEBUG_CHANNELSYNCING: adding ban: '.$hostmask.' for: '.$channel->name, __FILE__, __LINE__); + $channel->bans[$hostmask] = true; + } + if ($remove) { + $this->log(SMARTIRC_DEBUG_CHANNELSYNCING, 'DEBUG_CHANNELSYNCING: removing ban: '.$hostmask.' for: '.$channel->name, __FILE__, __LINE__); + unset($channel->bans[$hostmask]); + } + } else { + $this->log(SMARTIRC_DEBUG_CHANNELSYNCING, 'DEBUG_CHANNELSYNCING: storing unknown channelmode ('.$mode.') in channel->mode for: '.$channel->name, __FILE__, __LINE__); + if ($add) { + $channel->mode .= $mode[$i]; + } + if ($remove) { + $channel->mode = str_replace($mode[$i], '', $channel->mode); + } + } + } + } + } + } + + function _event_topic(&$ircdata) + { + if ($this->_channelsyncing == true) { + $channel = &$this->_channels[strtolower($ircdata->rawmessageex[2])]; + $channel->topic = $ircdata->message; + } + } + + function _event_privmsg(&$ircdata) + { + if ($ircdata->type == SMARTIRC_TYPE_CTCP) { + // substr must be 1,4 because of \001 in CTCP messages + if (substr($ircdata->message, 1, 4) == 'PING') { + $this->message(SMARTIRC_TYPE_CTCP, $ircdata->nick, 'PING '.substr($ircdata->message, 5, -1)); + } elseif (substr($ircdata->message, 1, 7) == 'VERSION') { + if (!empty($this->_ctcpversion)) { + $versionstring = $this->_ctcpversion.' | using '.SMARTIRC_VERSIONSTRING; + } else { + $versionstring = SMARTIRC_VERSIONSTRING; + } + + $this->message(SMARTIRC_TYPE_CTCP, $ircdata->nick, 'VERSION '.$versionstring); + } + } + } + + /* rpl_ */ + function _event_rpl_welcome(&$ircdata) + { + $this->_loggedin = true; + $this->log(SMARTIRC_DEBUG_CONNECTION, 'DEBUG_CONNECTION: logged in', __FILE__, __LINE__); + + // updating our nickname, that we got (maybe cutted...) + $this->_nick = $ircdata->rawmessageex[2]; + } + + function _event_rpl_motdstart(&$ircdata) + { + $this->_motd[] = $ircdata->message; + } + + function _event_rpl_motd(&$ircdata) + { + $this->_motd[] = $ircdata->message; + } + + function _event_rpl_endofmotd(&$ircdata) + { + $this->_motd[] = $ircdata->message; + } + + function _event_rpl_umodeis(&$ircdata) + { + $this->_usermode = $ircdata->message; + } + + function _event_rpl_channelmodeis(&$ircdata) { + if ($this->_channelsyncing == true && $this->isJoined($ircdata->channel)) { + $mode = $ircdata->rawmessageex[4]; + $parameters = array_slice($ircdata->rawmessageex, 5); + + $ircdata->rawmessageex = array( 0 => '', + 1 => '', + 2 => '', + 3 => $mode); + + foreach ($parameters as $value) { + $ircdata->rawmessageex[] = $value; + } + + // let _mode() handle the received mode + $this->_event_mode($ircdata); + } + } + + function _event_rpl_whoreply(&$ircdata) + { + if ($this->_channelsyncing == true) { + $nick = $ircdata->rawmessageex[7]; + if ($ircdata->channel == '*') { + // we got who info without channel info, so we need to search the user + // on all channels and update him + foreach ($this->_channels as $channel) { + if ($this->isJoined($channel->name, $nick)) { + $ircdata->channel = $channel->name; + $this->_event_rpl_whoreply($ircdata); + } + } + } else { + if (!$this->isJoined($ircdata->channel, $nick)) { + return; + } + + $channel = &$this->_channels[strtolower($ircdata->channel)]; + + $user = &new Net_SmartIRC_channeluser(); + $user->ident = $ircdata->rawmessageex[4]; + $user->host = $ircdata->rawmessageex[5]; + $user->server = $ircdata->rawmessageex[6]; + $user->nick = $ircdata->rawmessageex[7]; + + $user->op = false; + $user->voice = false; + $user->ircop = false; + + $usermode = $ircdata->rawmessageex[8]; + $usermodelength = strlen($usermode); + for ($i = 0; $i < $usermodelength; $i++) { + switch ($usermode[$i]) { + case 'H': + $user->away = false; + break; + case 'G': + $user->away = true; + break; + case '@': + $user->op = true; + break; + case '+': + $user->voice = true; + break; + case '*': + $user->ircop = true; + break; + } + } + + $user->hopcount = substr($ircdata->rawmessageex[9], 1); + $user->realname = implode(array_slice($ircdata->rawmessageex, 10), ' '); + + $this->_adduser($channel, $user); + } + } + } + + function _event_rpl_namreply(&$ircdata) + { + if ($this->_channelsyncing == true) { + $channel = &$this->_channels[strtolower($ircdata->channel)]; + + $userarray = explode(' ', rtrim($ircdata->message)); + $userarraycount = count($userarray); + for ($i = 0; $i < $userarraycount; $i++) { + $user = &new Net_SmartIRC_channeluser(); + + $usermode = substr($userarray[$i], 0, 1); + switch ($usermode) { + case '@': + $user->op = true; + $user->nick = substr($userarray[$i], 1); + break; + case '+': + $user->voice = true; + $user->nick = substr($userarray[$i], 1); + break; + default: + $user->nick = $userarray[$i]; + } + + $this->_adduser($channel, $user); + } + } + } + + function _event_rpl_banlist(&$ircdata) + { + if ($this->_channelsyncing == true && $this->isJoined($ircdata->channel)) { + $channel = &$this->_channels[strtolower($ircdata->channel)]; + $hostmask = $ircdata->rawmessageex[4]; + $channel->bans[$hostmask] = true; + } + } + + function _event_rpl_topic(&$ircdata) + { + if ($this->_channelsyncing == true) { + $channel = &$this->_channels[strtolower($ircdata->channel)]; + $topic = substr(implode(array_slice($ircdata->rawmessageex, 4), ' '), 1); + $channel->topic = $topic; + } + } + + /* err_ */ + function _event_err_nicknameinuse(&$ircdata) + { + $this->_nicknameinuse(); + } +} +?> \ No newline at end of file diff --git a/tools/IRC_Bot/magpierss/AUTHORS b/tools/IRC_Bot/magpierss/AUTHORS new file mode 100644 index 000000000..7d7f3f53e --- /dev/null +++ b/tools/IRC_Bot/magpierss/AUTHORS @@ -0,0 +1 @@ +kellan diff --git a/tools/IRC_Bot/magpierss/CHANGES b/tools/IRC_Bot/magpierss/CHANGES new file mode 100644 index 000000000..b186af5c9 --- /dev/null +++ b/tools/IRC_Bot/magpierss/CHANGES @@ -0,0 +1,37 @@ +Version 0.7 +----------- + - support for input and output charset encoding + based on the work in FoF, uses iconv or mbstring if available + - + +Version 0.6 +----------- + - basic support for Atom syndication format + including support for Atom content constructs + - fixed support for private feeds (HTTP Auth and SSL) + (thanks to silverorange.com for providing test feeds) + - support for some broken webservers + +Version 0.52 +----------- + - support GZIP content negoiation + - PHP 4.3.2 support + +Version 0.4 +----------- + - improved error handling, better access for script authors + - included example scripts of working with MagpieRSS + - new Smarty plugin for RSS date parsing + +Version 0.3 +----------- + - added support for conditional gets (Last-Modified, ETag) + - now use Snoopy to handle fetching RSS files + +Version 0.2 +----------- + - MAJOR CLEAN UP + - removed kludgy $options array in favour of constants + - phased out returning arrays + - added better error handling + - re-worked comments diff --git a/tools/IRC_Bot/magpierss/ChangeLog b/tools/IRC_Bot/magpierss/ChangeLog new file mode 100644 index 000000000..d52a58782 --- /dev/null +++ b/tools/IRC_Bot/magpierss/ChangeLog @@ -0,0 +1,346 @@ +2004-11-21 22:45 kellan + + * rss_fetch.inc: detab, bump version + +2004-11-21 20:52 kellan + + * rss_fetch.inc, rss_parse.inc: cache on $url . $output_encoding + otherwise we can get munged output + * rss_parse.inc: don't set ERROR on notice or warning (rss_fetch + dies on parse errors) + * rss_fetch.inc: add encoding defines (fix timeout error reporting) + +2004-11-21 17:21 kellan + + * rss_parse.inc: incorporate steve's patch + +2004-11-21 16:26 kellan + + * rss_parse.inc: remove old debugging functions, totally + arbitrarily. might break stuff. can't really explain why i'm + doing this. + +2004-10-28 12:52 kellan + + * rss_parse.inc: fixed '=' instead of '==' + +2004-10-25 21:48 kellan + + * rss_parse.inc: chance epoch to timestamp to conform w/ php naming + conventions + +2004-06-15 09:00 kellan + + * rss_parse.inc: [no log message] + +2004-04-26 11:16 kellan + + * rss_fetch.inc: bump version + +2004-04-26 09:36 kellan + + * rss_parse.inc: fix field doubling + +2004-04-24 14:47 kellan + + * CHANGES, ChangeLog: updated + +2004-04-24 14:35 kellan + + * rss_fetch.inc: bumped version + +2004-04-24 13:52 kellan + + * rss_parse.inc: support arbitrary atom content constructs + + some refactoring + +2004-04-24 13:15 kellan + + * rss_parse.inc: support summary content contstruct. add normalize + function + +2004-03-27 13:29 kellan + + * extlib/Snoopy.class.inc: accept self-signed certs + +2004-03-27 09:53 kellan + + * extlib/Snoopy.class.inc: fixed SSL support * set status * set + error on bad curl + + (also ripped out big chunks of dead weight (submit_form) which + were getting in my way + +2004-01-24 23:25 kellan + + * rss_parse.inc: make RSS 1.0's rdf:about available + +2004-01-24 23:07 kellan + + * rss_parse.inc: clean up text, and line formats. add support item + rdf:about + +2004-01-24 20:40 kellan + + * CHANGES, ChangeLog: update changes + +2004-01-24 20:37 kellan + + * rss_fetch.inc: updated version + +2004-01-24 20:35 kellan + + * rss_parse.inc: whitespace + +2004-01-24 20:23 kellan + + * extlib/Snoopy.class.inc: support badly formatted http headers + +2004-01-24 20:20 kellan + + * rss_parse.inc: added alpha atom parsing support + +2003-06-25 19:34 kellan + + * extlib/Snoopy.class.inc: fixed fread 4.3.2 compatibility problems + +2003-06-13 08:31 kellan + + * rss_fetch.inc: reset cache on 304 + +2003-06-12 18:37 kellan + + * rss_cache.inc, rss_fetch.inc, rss_parse.inc, rss_utils.inc: + bumped up version numbers + +2003-06-12 18:32 kellan + + * htdocs/index.html: updated news + +2003-06-12 18:27 kellan + + * NEWS: a manual blog :) + +2003-06-12 18:22 kellan + + * htdocs/index.html: fully qualified img + +2003-06-12 18:20 kellan + + * htdocs/index.html: clean up. added badge. + +2003-06-12 18:04 kellan + + * rss_utils.inc: clean up regex + +2003-06-12 18:02 kellan + + * rss_cache.inc: suppress some warnings + +2003-05-30 17:44 kellan + + * extlib/Snoopy.class.inc: more comments, cleaned up notice + +2003-05-30 12:14 kellan + + * extlib/Snoopy.class.inc: don't advertise gzip support if the user + hasn't built php with gzinflate support + +2003-05-12 19:32 kellan + + * ChangeLog: changes + +2003-05-12 19:11 kellan + + * htdocs/index.html: announce 0.5 + +2003-05-12 18:42 kellan + + * htdocs/index.html: change + +2003-05-12 18:39 kellan + + * rss_fetch.inc: use gzip + +2003-05-12 18:37 kellan + + * extlib/Snoopy.class.inc: added support gzip encoded content + negoiation + +2003-05-12 18:32 kellan + + * rss_cache.inc, rss_fetch.inc, rss_parse.inc, rss_utils.inc: fixed + typoes + +2003-04-26 18:44 kellan + + * rss_parse.inc: fix minor typo + +2003-04-18 05:19 kellan + + * htdocs/cookbook.html: updated cookbook to show more code for + limiting items + +2003-03-03 13:02 kellan + + * rss_parse.inc, scripts/magpie_slashbox.php: committed (or + adpated) patch from Nicola (www.technick.com) to quell 'Undefined + Indexes' notices + +2003-03-03 12:59 kellan + + * rss_fetch.inc: commited patch from nicola (www.technick.com) to + quell 'undefined indexes' notices. + + * Magpie now automatically includes its version in the + user-agent, & whether cacheing is turned on. + +2003-02-11 22:22 kellan + + * CHANGES, ChangeLog: ChangeLog now auto-generated by cvs2cl + +2003-02-11 21:21 kellan + + * rss_fetch.inc: better errors, hopefully stomped on pesky notices + +2003-02-11 21:19 kellan + + * rss_parse.inc: check to see is xml is supported, if not die + + also throw better xml errors + +2003-02-11 21:18 kellan + + * rss_cache.inc: hopefully cleared up some notices that were being + thrown into the log + + fixed a debug statement that was being called as an error + +2003-02-11 21:15 kellan + + * scripts/: magpie_simple.php, magpie_slashbox.php: moved + magpie_simple to magpie_slashbox, and replaced it with a simpler + demo. + +2003-02-11 21:02 kellan + + * INSTALL, README, TROUBLESHOOTING: Improved documentation. Better + install instructions. + + TROUBLESHOOTING cover common installation and usage problems + +2003-01-22 11:40 kellan + + * htdocs/cookbook.html: added cookbook.html + +2003-01-21 20:47 kellan + + * cookbook: a magpie cookbook + +2003-01-20 07:09 kellan + + * ChangeLog: updated + +2003-01-20 06:23 kellan + + * scripts/simple_smarty.php: minor clean up + +2003-01-20 06:15 kellan + + * scripts/README: added smarty url + +2003-01-20 06:14 kellan + + * magpie_simple.php, htdocs/index.html, scripts/README, + scripts/magpie_debug.php, scripts/magpie_simple.php, + scripts/simple_smarty.php, + scripts/smarty_plugin/modifier.rss_date_parse.php, + scripts/templates/simple.smarty: Added scripts directory for + examples on how to use MagpieRSS + + magpie_simple - is a simple example magpie_debug - spew all the + information from a parsed RSS feed simple_smary - example of + using magpie with Smarty template system + smarty_plugin/modifier.rss_date_parse.php - support file for the + smarty demo templates/simple.smary - template for the smarty demo + +2003-01-20 06:11 kellan + + * rss_fetch.inc, rss_parse.inc: changes to error handling to give + script authors more access to magpie's errors. + + added method magpie_error() to retrieve global MAGPIE_ERROR + variable for when fetch_rss() returns false + +2002-10-26 16:02 kellan + + * htdocs/index.html: putting the website under source control + +2002-10-26 15:43 kellan + + * AUTHORS, ChangeLog, INSTALL, README: some documentation to make + it all look official :) + +2002-10-25 20:04 kellan + + * magpie_simple.php: quxx + +2002-10-25 20:04 kellan + + * rss_parse.inc: added support for textinput and image + +2002-10-25 16:23 kellan + + * magpie_simple.php, rss_cache.inc, rss_fetch.inc, rss_parse.inc, + rss_utils.inc: switched to using Snoopy for fetching remote RSS + files. + + added support for conditional gets + +2002-10-25 16:22 kellan + + * rss_cache.inc, rss_fetch.inc, rss_parse.inc, rss_utils.inc: + Change comment style to slavishly imitate the phpinsider style + found in Smarty and Snoopy :) + +2002-10-25 16:18 kellan + + * extlib/Snoopy.class.inc: added Snoopy in order to support + conditional gets + +2002-10-23 20:19 kellan + + * magpie_simple.php, rss_cache.inc, rss_fetch.inc, rss_parse.inc: + MAJOR CLEANUP! + + * rss_fetch got rid of the options array, replaced it with a more + PHP-like solution of using defines. constants are setup, with + defaults, in the function init() + + got rid of the idiom of passing back an array, its was awkward to + deal with in PHP, and unusual (and consquently confusing to + people). now i return true/false values, and try to setup error + string where appropiate (rss_cache has the most complete example + of this) + + change the logic for interacting with the cache + + * rss_cache major re-working of how error are handled. tried to + make the code more resillient. the cache is now much more aware + of MAX_AGE, where before this was being driven out of rss_fetch + (which was silly) + + * rss_parse properly handles xml parse errors. used to sail + along blithely unaware. + +2002-09-11 08:11 kellan + + * rss_cache.inc, rss_parse.inc, magpie_simple.php, rss_fetch.inc, + rss_utils.inc: Initial revision + +2002-09-11 08:11 kellan + + * rss_cache.inc, rss_parse.inc, magpie_simple.php, rss_fetch.inc, + rss_utils.inc: initial import + diff --git a/tools/IRC_Bot/magpierss/INSTALL b/tools/IRC_Bot/magpierss/INSTALL new file mode 100644 index 000000000..640833d50 --- /dev/null +++ b/tools/IRC_Bot/magpierss/INSTALL @@ -0,0 +1,143 @@ +REQUIREMENTS + + MapieRSS requires a recent PHP 4+ (developed with 4.2.0) + with xml (expat) support. + + Optionally: + * PHP5 with libxml2 support. + * cURL for SSL support + * iconv (preferred) or mb_string for expanded character set support + +QUICK START + + Magpie consists of 4 files (rss_fetch.inc, rss_parser.inc, rss_cache.inc, + and rss_utils.inc), and the directory extlib (which contains a modified + version of the Snoopy HTTP client) + + Copy these 5 resources to a directory named 'magpierss' in the same + directory as your PHP script. + + At the top of your script add the following line: + + require_once('magpierss/rss_fetch.inc'); + + Now you can use the fetch_rss() method: + + $rss = fetch_rss($url); + + Done. That's it. See README for more details on using MagpieRSS. + +NEXT STEPS + + Important: you'll probably want to get the cache directory working in + order to speed up your application, and not abuse the webserver you're + downloading the RSS from. + + Optionally you can install MagpieRSS in your PHP include path in order to + make it available server wide. + + Lastly you might want to look through the constants in rss_fetch.inc see if + there is anything you want to override (the defaults are pretty good) + + For more info, or if you have trouble, see TROUBLESHOOTING + +SETTING UP CACHING + + Magpie has built-in transparent caching. With caching Magpie will only + fetch and parse RSS feeds when there is new content. Without this feature + your pages will be slow, and the sites serving the RSS feed will be annoyed + with you. + +** Simple and Automatic ** + + By default Magpie will try to create a cache directory named 'cache' in the + same directory as your PHP script. + +** Creating a Local Cache Directory ** + + Often this will fail, because your webserver doesn't have sufficient + permissions to create the directory. + + Exact instructions for how to do this will vary from install to install and + platform to platform. The steps are: + + 1. Make a directory named 'cache' + 2. Give the web server write access to that directory. + + An example of how to do this on Debian would be: + + 1. mkdir /path/to/script/cache + 2. chgrp www-data /path/to/script/cache + 3. chmod 775 /path/to/script/cache + + On other Unixes you'll need to change 'www-data' to what ever user Apache + runs as. (on MacOS X the user would be 'www') + +** Cache in /tmp ** + + Sometimes you won't be able to create a local cache directory. Some reasons + might be: + + 1. No shell account + 2. Insufficient permissions to change ownership of a directory + 3. Webserver runs as 'nobody' + + In these situations using a cache directory in /tmp can often be a good + option. + + The drawback is /tmp is public, so anyone on the box can read the cache + files. Usually RSS feeds are public information, so you'll have to decide + how much of an issue that is. + + To use /tmp as your cache directory you need to add the following line to + your script: + + define('MAGPIE_CACHE_DIR', '/tmp/magpie_cache'); + +** Global Cache ** + + If you have several applications using Magpie, you can create a single + shared cache directory, either using the /tmp cache, or somewhere else on + the system. + + The upside is that you'll distribute fetching and parsing feeds across + several applications. + +INSTALLING MAGPIE SERVER WIDE + + Rather then following the Quickstart instructions which requires you to have + a copy of Magpie per application, alternately you can place it in some + shared location. + +** Adding Magpie to Your Include Path ** + + Copy the 5 resources (rss_fetch.inc, rss_parser.inc, rss_cache.inc, + rss_utils.inc, and extlib) to a directory named 'magpierss' in your include + path. Now any PHP file on your system can use Magpie with: + + require_once('magpierss/rss_fetch.inc'); + + Different installs have different include paths, and you'll have to figure + out what your include_path is. + + From shell you can try: + + php -i | grep 'include_path' + + Alternatley you can create a phpinfo.php file with contains: + + + + Debian's default is: + + /usr/share/php + + (though more idealogically pure location would be /usr/local/share/php) + + Apple's default include path is: + + /usr/lib/php + + While the Entropy PHP build seems to use: + + /usr/local/php/lib/php \ No newline at end of file diff --git a/tools/IRC_Bot/magpierss/NEWS b/tools/IRC_Bot/magpierss/NEWS new file mode 100644 index 000000000..5ac6b9788 --- /dev/null +++ b/tools/IRC_Bot/magpierss/NEWS @@ -0,0 +1,53 @@ +MagpieRSS News + +MAGPIERSS 0.51 RELEASED + * important bugfix! + * fix "silent failure" when PHP doesn't have zlib + +FEED ON FEEDS USES MAGPIE + * web-based RSS aggregator built with Magpie + * easy to install, easy to use. + http://minutillo.com/steve/feedonfeeds/ + +MAGPIERSS 0.5 RELEASED + * supports transparent HTTP gzip content negotiation for reduced bandwidth usage + * quashed some undefined index notices + +MAGPIERSS 0.46 RELEASED + * minor release, more error handling clean up + * documentation fixes, simpler example + * new trouble shooting guide for installation and usage problems + http://magpierss.sourceforge.net/TROUBLESHOOTING + +MAGPIE NEWS AS RSS + * releases, bug fixes, releated stories in RSS + +MAGPIERSS COOKBOOK: SIMPLE PHP RSS HOW TOS + * answers some of the most frequently asked Magpie questions + * feedback, suggestions, requests, recipes welcome + http://magpierss.sourceforge.net/cookbook.html + +MAGPIERSS 0.4 RELEASED! + * improved error handling, more flexibility for script authors, backwards compatible + * new and better examples! including using MagpieRSS and Smarty + * new Smarty plugin for RSS date parsing + http://smarty.php.net + +INFINITE PENGUIN NOW SUPPORTS MAGPIE 0.3 + * simple, sophisticated RSS viewer + * includes auto-generated javascript ticker from RSS feed + http://www.infinitepenguins.net/rss/ + +TRAUMWIND RELEASES REX BACKEND FOR MAGPIERSS + * drop in support using regex based XML parser + * parses improperly formed XML that chokes expat + http://traumwind.de/blog/magpie/magpie_alike.php + +MAGPIERSS 0.3 RELEASED! + * Support added for HTTP Conditional GETs. + http://fishbowl.pastiche.org/archives/001132.html + +MAGPIERSS 0.2! + * Major clean up of the code. Easier to use. + * Simpler install on shared hosts. + * Better documentation and comments. diff --git a/tools/IRC_Bot/magpierss/README b/tools/IRC_Bot/magpierss/README new file mode 100644 index 000000000..6af7edb07 --- /dev/null +++ b/tools/IRC_Bot/magpierss/README @@ -0,0 +1,48 @@ +NAME + + MagpieRSS - a simple RSS integration tool + +SYNOPSIS + + require_once(rss_fetch.inc); + $url = $_GET['url']; + $rss = fetch_rss( $url ); + + echo "Channel Title: " . $rss->channel['title'] . "

"; + echo "

    "; + foreach ($rss->items as $item) { + $href = $item['link']; + $title = $item['title']; + echo "
  • $title
  • "; + } + echo "
"; + +DESCRIPTION + + MapieRSS is an XML-based RSS parser in PHP. It attempts to be "PHP-like", + and simple to use. + + Some features include: + + * supports RSS 0.9 - 1.0, with limited RSS 2.0 support + * supports namespaces, and modules, including mod_content and mod_event + * open minded [1] + * simple, functional interface, to object oriented backend parser + * automatic caching of parsed RSS objects makes its easy to integrate + * supports conditional GET with Last-Modified, and ETag + * uses constants for easy override of default behaviour + * heavily commented + + +1. By open minded I mean Magpie will accept any tag it finds in good faith that + it was supposed to be here. For strict validation, look elsewhere. + + +GETTING STARTED + + + +COPYRIGHT: + Copyright(c) 2002 kellan@protest.net. All rights reserved. + This software is released under the GNU General Public License. + Please read the disclaimer at the top of the Snoopy.class.inc file. diff --git a/tools/IRC_Bot/magpierss/TROUBLESHOOTING b/tools/IRC_Bot/magpierss/TROUBLESHOOTING new file mode 100644 index 000000000..89068d382 --- /dev/null +++ b/tools/IRC_Bot/magpierss/TROUBLESHOOTING @@ -0,0 +1,152 @@ +TROUBLESHOOTING + + +Trouble Installing MagpieRSS: + +1. Fatal error: Failed opening required '/path/to/script/rss_fetch.inc' + (include_path='.:/usr/local/lib/php:/usr/local/lib/php/pear') + +2. Cache couldn't make dir './cache'. + +3. Fatal error: Failed to load PHP's XML Extension. + http://www.php.net/manual/en/ref.xml.php + +Trouble Using MagpieRSS + +4. Warning: MagpieRSS: Failed to fetch example.com/index.rdf. + (HTTP Error: Invalid protocol "") + +5. Warning: MagpieRSS: Failed to parse RSS file. + (not well-formed (invalid token) at line 19, column 98) + +6. Warning: MagpieRSS: Failed to fetch http://localhost/rss/features.1-0.rss. + (HTTP Response: HTTP/1.1 404 Not Found) + +If you would rather provide a custom error, see the COOKBOOK +(http://magpierss.sf.net/cookbook.html) recipe 2. + +************************************************************************* +1. Fatal error: Failed opening required '/path/to/script/rss_fetch.inc' + (include_path='.:/usr/local/lib/php:/usr/local/lib/php/pear') + + This could mean that: + + a) PHP can't find the MagpieRSS files. + b) PHP found them the MagpieRSS files, but can't read them. + + a. Telling PHP where to look for MagpieRSS file. + + This might mean your PHP program can't find the MagpieRSS libraries. + Magpie relies on 4 include files, rss_fetch.inc, rss_parse.inc, + rss_cache.inc, rss_util.inc, and for normal use you'll need all 4 (see the + cookbook for exceptions). + + This can be fixed by making sure the MagpieRSS files are in your include + path. + + If you can edit your include path (for example your on a shared host) then + you need to replace: + + require_once('rss_fetch.inc'); + + -with- + + define('MAGPIE_DIR', '/path/to/magpierss/'); + require_once(MAGPIE_DIR.'rss_fetch.inc'); + + b. PHP can't read the MagpieRSS files + + All PHP libraries need to be readable by your webserver. + + On Unix you can accomplish this with: + + chmod 755 rss_fetch.inc rss_parse.inc rss_cache.inc rss_util.inc + +************************************************************************* +2. Cache couldn't make dir './cache'. + + MagpieRSS caches the results of fetched and parsed RSS to reduce the load on + both your server, and the remote server providing the RSS. It does this by + writing files to a cache directory. + + This error means the webserver doesn't have write access to the current + directory. + + a. Make a webserver writeable cache directory + + Find the webserver's group. (on my system it is 'www') + + mkdir ./cache + chgrp www directory_name + chmod g+w directory_name + + (this is the best, and desired solution) + + b. Tell MagpieRSS to create the cache directory somewhere the webserver can + write to. + + define('MAGPIE_CACHE_DIR', '/tmp/magpierss'); + + (this is not a great solution, and might have security considerations) + + c. Turn off cacheing. + + Magpie can work fine with cacheing, but it will be slower, and you might + become a nuiance to the RSS provider, but it is an option. + + define('MAGPIE_CACHE_ON', 0); + + d. And lastly, do NOT + + chmod 777 ./cache + + Any of the above solutions are better then this. + + NOTE: If none of this works for you, let me know. I've got root, and a + custom compiled Apache on almost any box I ever touch, so I can be a little + out of touch with reality. But I won't know that if I don't feedback. + +************************************************************************* 3. +3. Fatal error: Failed to load PHP's XML Extension. + http://www.php.net/manual/en/ref.xml.php + + -or- + + Fatal error: Failed to create an instance of PHP's XML parser. + http://www.php.net/manual/en/ref.xml.php + + Make sure your PHP was built with --with-xml + + This has been turned on by default for several versions of PHP, but it might + be turned off in your build. + + See php.net for details on building and configuring PHP. + + +************************************************************************* +4. Warning: MagpieRSS: Failed to fetch index.rdf. + (HTTP Error: Invalid protocol "") + + You need to put http:// in front of your the URL to your RSS feed + +************************************************************************* +5. Warning: MagpieRSS: Failed to parse RSS file. + (not well-formed (invalid token) at line 19, column 98) + + There is a problem with the RSS feed you are trying to read. + MagpieRSS is an XML parser, and therefore can't parse RSS feed with invalid + characters. Some RSS parser are based on regular expressions, and can + parse invalid RSS but they have their own problems. + + You could try contacting the author of the RSS feed, and pointing them to + the online RSS validator at: + + http://feeds.archive.org/validator/ + +************************************************************************* +6. Warning: MagpieRSS: Failed to fetch http://example.com/index.rdf + (HTTP Response: HTTP/1.1 404 Not Found) + + Its a 404! The RSS file ain't there. + + diff --git a/tools/IRC_Bot/magpierss/extlib/Snoopy.class.inc b/tools/IRC_Bot/magpierss/extlib/Snoopy.class.inc new file mode 100644 index 000000000..532ecba10 --- /dev/null +++ b/tools/IRC_Bot/magpierss/extlib/Snoopy.class.inc @@ -0,0 +1,899 @@ + +Copyright (c): 1999-2000 ispi, all rights reserved +Version: 1.0 + + * 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 + +You may contact the author of Snoopy by e-mail at: +monte@ispi.net + +Or, write to: +Monte Ohrt +CTO, ispi +237 S. 70th suite 220 +Lincoln, NE 68510 + +The latest version of Snoopy can be obtained from: +http://snoopy.sourceforge.com + +*************************************************/ + +class Snoopy +{ + /**** Public variables ****/ + + /* user definable vars */ + + var $host = "www.php.net"; // host name we are connecting to + var $port = 80; // port we are connecting to + var $proxy_host = ""; // proxy host to use + var $proxy_port = ""; // proxy port to use + var $agent = "Snoopy v1.0"; // agent we masquerade as + var $referer = ""; // referer info to pass + var $cookies = array(); // array of cookies to pass + // $cookies["username"]="joe"; + var $rawheaders = array(); // array of raw headers to send + // $rawheaders["Content-type"]="text/html"; + + var $maxredirs = 5; // http redirection depth maximum. 0 = disallow + var $lastredirectaddr = ""; // contains address of last redirected address + var $offsiteok = true; // allows redirection off-site + var $maxframes = 0; // frame content depth maximum. 0 = disallow + var $expandlinks = true; // expand links to fully qualified URLs. + // this only applies to fetchlinks() + // or submitlinks() + var $passcookies = true; // pass set cookies back through redirects + // NOTE: this currently does not respect + // dates, domains or paths. + + var $user = ""; // user for http authentication + var $pass = ""; // password for http authentication + + // http accept types + var $accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*"; + + var $results = ""; // where the content is put + + var $error = ""; // error messages sent here + var $response_code = ""; // response code returned from server + var $headers = array(); // headers returned from server sent here + var $maxlength = 500000; // max return data length (body) + var $read_timeout = 0; // timeout on read operations, in seconds + // supported only since PHP 4 Beta 4 + // set to 0 to disallow timeouts + var $timed_out = false; // if a read operation timed out + var $status = 0; // http request status + + var $curl_path = "/usr/bin/curl"; + // Snoopy will use cURL for fetching + // SSL content if a full system path to + // the cURL binary is supplied here. + // set to false if you do not have + // cURL installed. See http://curl.haxx.se + // for details on installing cURL. + // Snoopy does *not* use the cURL + // library functions built into php, + // as these functions are not stable + // as of this Snoopy release. + + // send Accept-encoding: gzip? + var $use_gzip = true; + + /**** Private variables ****/ + + var $_maxlinelen = 4096; // max line length (headers) + + var $_httpmethod = "GET"; // default http request method + var $_httpversion = "HTTP/1.0"; // default http request version + var $_submit_method = "POST"; // default submit method + var $_submit_type = "application/x-www-form-urlencoded"; // default submit type + var $_mime_boundary = ""; // MIME boundary for multipart/form-data submit type + var $_redirectaddr = false; // will be set if page fetched is a redirect + var $_redirectdepth = 0; // increments on an http redirect + var $_frameurls = array(); // frame src urls + var $_framedepth = 0; // increments on frame depth + + var $_isproxy = false; // set if using a proxy server + var $_fp_timeout = 30; // timeout for socket connection + +/*======================================================================*\ + Function: fetch + Purpose: fetch the contents of a web page + (and possibly other protocols in the + future like ftp, nntp, gopher, etc.) + Input: $URI the location of the page to fetch + Output: $this->results the output text from the fetch +\*======================================================================*/ + + function fetch($URI) + { + + //preg_match("|^([^:]+)://([^:/]+)(:[\d]+)*(.*)|",$URI,$URI_PARTS); + $URI_PARTS = parse_url($URI); + if (!empty($URI_PARTS["user"])) + $this->user = $URI_PARTS["user"]; + if (!empty($URI_PARTS["pass"])) + $this->pass = $URI_PARTS["pass"]; + + switch($URI_PARTS["scheme"]) + { + case "http": + $this->host = $URI_PARTS["host"]; + if(!empty($URI_PARTS["port"])) + $this->port = $URI_PARTS["port"]; + if($this->_connect($fp)) + { + if($this->_isproxy) + { + // using proxy, send entire URI + $this->_httprequest($URI,$fp,$URI,$this->_httpmethod); + } + else + { + $path = $URI_PARTS["path"].(isset($URI_PARTS["query"]) ? "?".$URI_PARTS["query"] : ""); + // no proxy, send only the path + $this->_httprequest($path, $fp, $URI, $this->_httpmethod); + } + + $this->_disconnect($fp); + + if($this->_redirectaddr) + { + /* url was redirected, check if we've hit the max depth */ + if($this->maxredirs > $this->_redirectdepth) + { + // only follow redirect if it's on this site, or offsiteok is true + if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok) + { + /* follow the redirect */ + $this->_redirectdepth++; + $this->lastredirectaddr=$this->_redirectaddr; + $this->fetch($this->_redirectaddr); + } + } + } + + if($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0) + { + $frameurls = $this->_frameurls; + $this->_frameurls = array(); + + while(list(,$frameurl) = each($frameurls)) + { + if($this->_framedepth < $this->maxframes) + { + $this->fetch($frameurl); + $this->_framedepth++; + } + else + break; + } + } + } + else + { + return false; + } + return true; + break; + case "https": + if(!$this->curl_path || (!is_executable($this->curl_path))) { + $this->error = "Bad curl ($this->curl_path), can't fetch HTTPS \n"; + return false; + } + $this->host = $URI_PARTS["host"]; + if(!empty($URI_PARTS["port"])) + $this->port = $URI_PARTS["port"]; + if($this->_isproxy) + { + // using proxy, send entire URI + $this->_httpsrequest($URI,$URI,$this->_httpmethod); + } + else + { + $path = $URI_PARTS["path"].($URI_PARTS["query"] ? "?".$URI_PARTS["query"] : ""); + // no proxy, send only the path + $this->_httpsrequest($path, $URI, $this->_httpmethod); + } + + if($this->_redirectaddr) + { + /* url was redirected, check if we've hit the max depth */ + if($this->maxredirs > $this->_redirectdepth) + { + // only follow redirect if it's on this site, or offsiteok is true + if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok) + { + /* follow the redirect */ + $this->_redirectdepth++; + $this->lastredirectaddr=$this->_redirectaddr; + $this->fetch($this->_redirectaddr); + } + } + } + + if($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0) + { + $frameurls = $this->_frameurls; + $this->_frameurls = array(); + + while(list(,$frameurl) = each($frameurls)) + { + if($this->_framedepth < $this->maxframes) + { + $this->fetch($frameurl); + $this->_framedepth++; + } + else + break; + } + } + return true; + break; + default: + // not a valid protocol + $this->error = 'Invalid protocol "'.$URI_PARTS["scheme"].'"\n'; + return false; + break; + } + return true; + } + + + +/*======================================================================*\ + Private functions +\*======================================================================*/ + + +/*======================================================================*\ + Function: _striplinks + Purpose: strip the hyperlinks from an html document + Input: $document document to strip. + Output: $match an array of the links +\*======================================================================*/ + + function _striplinks($document) + { + preg_match_all("'<\s*a\s+.*href\s*=\s* # find ]+)) # if quote found, match up to next matching + # quote, otherwise match up to next space + 'isx",$document,$links); + + + // catenate the non-empty matches from the conditional subpattern + + while(list($key,$val) = each($links[2])) + { + if(!empty($val)) + $match[] = $val; + } + + while(list($key,$val) = each($links[3])) + { + if(!empty($val)) + $match[] = $val; + } + + // return the links + return $match; + } + +/*======================================================================*\ + Function: _stripform + Purpose: strip the form elements from an html document + Input: $document document to strip. + Output: $match an array of the links +\*======================================================================*/ + + function _stripform($document) + { + preg_match_all("'<\/?(FORM|INPUT|SELECT|TEXTAREA|(OPTION))[^<>]*>(?(2)(.*(?=<\/?(option|select)[^<>]*>[\r\n]*)|(?=[\r\n]*))|(?=[\r\n]*))'Usi",$document,$elements); + + // catenate the matches + $match = implode("\r\n",$elements[0]); + + // return the links + return $match; + } + + + +/*======================================================================*\ + Function: _striptext + Purpose: strip the text from an html document + Input: $document document to strip. + Output: $text the resulting text +\*======================================================================*/ + + function _striptext($document) + { + + // I didn't use preg eval (//e) since that is only available in PHP 4.0. + // so, list your entities one by one here. I included some of the + // more common ones. + + $search = array("']*?>.*?'si", // strip out javascript + "'<[\/\!]*?[^<>]*?>'si", // strip out html tags + "'([\r\n])[\s]+'", // strip out white space + "'&(quote|#34);'i", // replace html entities + "'&(amp|#38);'i", + "'&(lt|#60);'i", + "'&(gt|#62);'i", + "'&(nbsp|#160);'i", + "'&(iexcl|#161);'i", + "'&(cent|#162);'i", + "'&(pound|#163);'i", + "'&(copy|#169);'i" + ); + $replace = array( "", + "", + "\\1", + "\"", + "&", + "<", + ">", + " ", + chr(161), + chr(162), + chr(163), + chr(169)); + + $text = preg_replace($search,$replace,$document); + + return $text; + } + +/*======================================================================*\ + Function: _expandlinks + Purpose: expand each link into a fully qualified URL + Input: $links the links to qualify + $URI the full URI to get the base from + Output: $expandedLinks the expanded links +\*======================================================================*/ + + function _expandlinks($links,$URI) + { + + preg_match("/^[^\?]+/",$URI,$match); + + $match = preg_replace("|/[^\/\.]+\.[^\/\.]+$|","",$match[0]); + + $search = array( "|^http://".preg_quote($this->host)."|i", + "|^(?!http://)(\/)?(?!mailto:)|i", + "|/\./|", + "|/[^\/]+/\.\./|" + ); + + $replace = array( "", + $match."/", + "/", + "/" + ); + + $expandedLinks = preg_replace($search,$replace,$links); + + return $expandedLinks; + } + +/*======================================================================*\ + Function: _httprequest + Purpose: go get the http data from the server + Input: $url the url to fetch + $fp the current open file pointer + $URI the full URI + $body body contents to send if any (POST) + Output: +\*======================================================================*/ + + function _httprequest($url,$fp,$URI,$http_method,$content_type="",$body="") + { + if($this->passcookies && $this->_redirectaddr) + $this->setcookies(); + + $URI_PARTS = parse_url($URI); + if(empty($url)) + $url = "/"; + $headers = $http_method." ".$url." ".$this->_httpversion."\r\n"; + if(!empty($this->agent)) + $headers .= "User-Agent: ".$this->agent."\r\n"; + if(!empty($this->host) && !isset($this->rawheaders['Host'])) + $headers .= "Host: ".$this->host."\r\n"; + if(!empty($this->accept)) + $headers .= "Accept: ".$this->accept."\r\n"; + + if($this->use_gzip) { + // make sure PHP was built with --with-zlib + // and we can handle gzipp'ed data + if ( function_exists(gzinflate) ) { + $headers .= "Accept-encoding: gzip\r\n"; + } + else { + trigger_error( + "use_gzip is on, but PHP was built without zlib support.". + " Requesting file(s) without gzip encoding.", + E_USER_NOTICE); + } + } + + if(!empty($this->referer)) + $headers .= "Referer: ".$this->referer."\r\n"; + if(!empty($this->cookies)) + { + if(!is_array($this->cookies)) + $this->cookies = (array)$this->cookies; + + reset($this->cookies); + if ( count($this->cookies) > 0 ) { + $cookie_headers .= 'Cookie: '; + foreach ( $this->cookies as $cookieKey => $cookieVal ) { + $cookie_headers .= $cookieKey."=".urlencode($cookieVal)."; "; + } + $headers .= substr($cookie_headers,0,-2) . "\r\n"; + } + } + if(!empty($this->rawheaders)) + { + if(!is_array($this->rawheaders)) + $this->rawheaders = (array)$this->rawheaders; + while(list($headerKey,$headerVal) = each($this->rawheaders)) + $headers .= $headerKey.": ".$headerVal."\r\n"; + } + if(!empty($content_type)) { + $headers .= "Content-type: $content_type"; + if ($content_type == "multipart/form-data") + $headers .= "; boundary=".$this->_mime_boundary; + $headers .= "\r\n"; + } + if(!empty($body)) + $headers .= "Content-length: ".strlen($body)."\r\n"; + if(!empty($this->user) || !empty($this->pass)) + $headers .= "Authorization: BASIC ".base64_encode($this->user.":".$this->pass)."\r\n"; + + $headers .= "\r\n"; + + // set the read timeout if needed + if ($this->read_timeout > 0) + socket_set_timeout($fp, $this->read_timeout); + $this->timed_out = false; + + fwrite($fp,$headers.$body,strlen($headers.$body)); + + $this->_redirectaddr = false; + unset($this->headers); + + // content was returned gzip encoded? + $is_gzipped = false; + + while($currentHeader = fgets($fp,$this->_maxlinelen)) + { + if ($this->read_timeout > 0 && $this->_check_timeout($fp)) + { + $this->status=-100; + return false; + } + + // if($currentHeader == "\r\n") + if(preg_match("/^\r?\n$/", $currentHeader) ) + break; + + // if a header begins with Location: or URI:, set the redirect + if(preg_match("/^(Location:|URI:)/i",$currentHeader)) + { + // get URL portion of the redirect + preg_match("/^(Location:|URI:)\s+(.*)/",chop($currentHeader),$matches); + // look for :// in the Location header to see if hostname is included + if(!preg_match("|\:\/\/|",$matches[2])) + { + // no host in the path, so prepend + $this->_redirectaddr = $URI_PARTS["scheme"]."://".$this->host.":".$this->port; + // eliminate double slash + if(!preg_match("|^/|",$matches[2])) + $this->_redirectaddr .= "/".$matches[2]; + else + $this->_redirectaddr .= $matches[2]; + } + else + $this->_redirectaddr = $matches[2]; + } + + if(preg_match("|^HTTP/|",$currentHeader)) + { + if(preg_match("|^HTTP/[^\s]*\s(.*?)\s|",$currentHeader, $status)) + { + $this->status= $status[1]; + } + $this->response_code = $currentHeader; + } + + if (preg_match("/Content-Encoding: gzip/", $currentHeader) ) { + $is_gzipped = true; + } + + $this->headers[] = $currentHeader; + } + + # $results = fread($fp, $this->maxlength); + $results = ""; + while ( $data = fread($fp, $this->maxlength) ) { + $results .= $data; + if ( + strlen($results) > $this->maxlength ) { + break; + } + } + + // gunzip + if ( $is_gzipped ) { + // per http://www.php.net/manual/en/function.gzencode.php + $results = substr($results, 10); + $results = gzinflate($results); + } + + if ($this->read_timeout > 0 && $this->_check_timeout($fp)) + { + $this->status=-100; + return false; + } + + // check if there is a a redirect meta tag + + if(preg_match("']*?content[\s]*=[\s]*[\"\']?\d+;[\s]+URL[\s]*=[\s]*([^\"\']*?)[\"\']?>'i",$results,$match)) + { + $this->_redirectaddr = $this->_expandlinks($match[1],$URI); + } + + // have we hit our frame depth and is there frame src to fetch? + if(($this->_framedepth < $this->maxframes) && preg_match_all("']+)'i",$results,$match)) + { + $this->results[] = $results; + for($x=0; $x_frameurls[] = $this->_expandlinks($match[1][$x],$URI_PARTS["scheme"]."://".$this->host); + } + // have we already fetched framed content? + elseif(is_array($this->results)) + $this->results[] = $results; + // no framed content + else + $this->results = $results; + + return true; + } + +/*======================================================================*\ + Function: _httpsrequest + Purpose: go get the https data from the server using curl + Input: $url the url to fetch + $URI the full URI + $body body contents to send if any (POST) + Output: +\*======================================================================*/ + + function _httpsrequest($url,$URI,$http_method,$content_type="",$body="") + { + if($this->passcookies && $this->_redirectaddr) + $this->setcookies(); + + $headers = array(); + + $URI_PARTS = parse_url($URI); + if(empty($url)) + $url = "/"; + // GET ... header not needed for curl + //$headers[] = $http_method." ".$url." ".$this->_httpversion; + if(!empty($this->agent)) + $headers[] = "User-Agent: ".$this->agent; + if(!empty($this->host)) + $headers[] = "Host: ".$this->host; + if(!empty($this->accept)) + $headers[] = "Accept: ".$this->accept; + if(!empty($this->referer)) + $headers[] = "Referer: ".$this->referer; + if(!empty($this->cookies)) + { + if(!is_array($this->cookies)) + $this->cookies = (array)$this->cookies; + + reset($this->cookies); + if ( count($this->cookies) > 0 ) { + $cookie_str = 'Cookie: '; + foreach ( $this->cookies as $cookieKey => $cookieVal ) { + $cookie_str .= $cookieKey."=".urlencode($cookieVal)."; "; + } + $headers[] = substr($cookie_str,0,-2); + } + } + if(!empty($this->rawheaders)) + { + if(!is_array($this->rawheaders)) + $this->rawheaders = (array)$this->rawheaders; + while(list($headerKey,$headerVal) = each($this->rawheaders)) + $headers[] = $headerKey.": ".$headerVal; + } + if(!empty($content_type)) { + if ($content_type == "multipart/form-data") + $headers[] = "Content-type: $content_type; boundary=".$this->_mime_boundary; + else + $headers[] = "Content-type: $content_type"; + } + if(!empty($body)) + $headers[] = "Content-length: ".strlen($body); + if(!empty($this->user) || !empty($this->pass)) + $headers[] = "Authorization: BASIC ".base64_encode($this->user.":".$this->pass); + + for($curr_header = 0; $curr_header < count($headers); $curr_header++) + $cmdline_params .= " -H \"".$headers[$curr_header]."\""; + + if(!empty($body)) + $cmdline_params .= " -d \"$body\""; + + if($this->read_timeout > 0) + $cmdline_params .= " -m ".$this->read_timeout; + + $headerfile = uniqid(time()); + + # accept self-signed certs + $cmdline_params .= " -k"; + exec($this->curl_path." -D \"/tmp/$headerfile\"".$cmdline_params." ".$URI,$results,$return); + + if($return) + { + $this->error = "Error: cURL could not retrieve the document, error $return."; + return false; + } + + + $results = implode("\r\n",$results); + + $result_headers = file("/tmp/$headerfile"); + + $this->_redirectaddr = false; + unset($this->headers); + + for($currentHeader = 0; $currentHeader < count($result_headers); $currentHeader++) + { + + // if a header begins with Location: or URI:, set the redirect + if(preg_match("/^(Location: |URI: )/i",$result_headers[$currentHeader])) + { + // get URL portion of the redirect + preg_match("/^(Location: |URI:)(.*)/",chop($result_headers[$currentHeader]),$matches); + // look for :// in the Location header to see if hostname is included + if(!preg_match("|\:\/\/|",$matches[2])) + { + // no host in the path, so prepend + $this->_redirectaddr = $URI_PARTS["scheme"]."://".$this->host.":".$this->port; + // eliminate double slash + if(!preg_match("|^/|",$matches[2])) + $this->_redirectaddr .= "/".$matches[2]; + else + $this->_redirectaddr .= $matches[2]; + } + else + $this->_redirectaddr = $matches[2]; + } + + if(preg_match("|^HTTP/|",$result_headers[$currentHeader])) + { + $this->response_code = $result_headers[$currentHeader]; + if(preg_match("|^HTTP/[^\s]*\s(.*?)\s|",$this->response_code, $match)) + { + $this->status= $match[1]; + } + } + $this->headers[] = $result_headers[$currentHeader]; + } + + // check if there is a a redirect meta tag + + if(preg_match("']*?content[\s]*=[\s]*[\"\']?\d+;[\s]+URL[\s]*=[\s]*([^\"\']*?)[\"\']?>'i",$results,$match)) + { + $this->_redirectaddr = $this->_expandlinks($match[1],$URI); + } + + // have we hit our frame depth and is there frame src to fetch? + if(($this->_framedepth < $this->maxframes) && preg_match_all("']+)'i",$results,$match)) + { + $this->results[] = $results; + for($x=0; $x_frameurls[] = $this->_expandlinks($match[1][$x],$URI_PARTS["scheme"]."://".$this->host); + } + // have we already fetched framed content? + elseif(is_array($this->results)) + $this->results[] = $results; + // no framed content + else + $this->results = $results; + + unlink("/tmp/$headerfile"); + + return true; + } + +/*======================================================================*\ + Function: setcookies() + Purpose: set cookies for a redirection +\*======================================================================*/ + + function setcookies() + { + for($x=0; $xheaders); $x++) + { + if(preg_match("/^set-cookie:[\s]+([^=]+)=([^;]+)/i", $this->headers[$x],$match)) + $this->cookies[$match[1]] = $match[2]; + } + } + + +/*======================================================================*\ + Function: _check_timeout + Purpose: checks whether timeout has occurred + Input: $fp file pointer +\*======================================================================*/ + + function _check_timeout($fp) + { + if ($this->read_timeout > 0) { + $fp_status = socket_get_status($fp); + if ($fp_status["timed_out"]) { + $this->timed_out = true; + return true; + } + } + return false; + } + +/*======================================================================*\ + Function: _connect + Purpose: make a socket connection + Input: $fp file pointer +\*======================================================================*/ + + function _connect(&$fp) + { + if(!empty($this->proxy_host) && !empty($this->proxy_port)) + { + $this->_isproxy = true; + $host = $this->proxy_host; + $port = $this->proxy_port; + } + else + { + $host = $this->host; + $port = $this->port; + } + + $this->status = 0; + + if($fp = fsockopen( + $host, + $port, + $errno, + $errstr, + $this->_fp_timeout + )) + { + // socket connection succeeded + + return true; + } + else + { + // socket connection failed + $this->status = $errno; + switch($errno) + { + case -3: + $this->error="socket creation failed (-3)"; + case -4: + $this->error="dns lookup failure (-4)"; + case -5: + $this->error="connection refused or timed out (-5)"; + default: + $this->error="connection failed (".$errno.")"; + } + return false; + } + } +/*======================================================================*\ + Function: _disconnect + Purpose: disconnect a socket connection + Input: $fp file pointer +\*======================================================================*/ + + function _disconnect($fp) + { + return(fclose($fp)); + } + + +/*======================================================================*\ + Function: _prepare_post_body + Purpose: Prepare post body according to encoding type + Input: $formvars - form variables + $formfiles - form upload files + Output: post body +\*======================================================================*/ + + function _prepare_post_body($formvars, $formfiles) + { + settype($formvars, "array"); + settype($formfiles, "array"); + + if (count($formvars) == 0 && count($formfiles) == 0) + return; + + switch ($this->_submit_type) { + case "application/x-www-form-urlencoded": + reset($formvars); + while(list($key,$val) = each($formvars)) { + if (is_array($val) || is_object($val)) { + while (list($cur_key, $cur_val) = each($val)) { + $postdata .= urlencode($key)."[]=".urlencode($cur_val)."&"; + } + } else + $postdata .= urlencode($key)."=".urlencode($val)."&"; + } + break; + + case "multipart/form-data": + $this->_mime_boundary = "Snoopy".md5(uniqid(microtime())); + + reset($formvars); + while(list($key,$val) = each($formvars)) { + if (is_array($val) || is_object($val)) { + while (list($cur_key, $cur_val) = each($val)) { + $postdata .= "--".$this->_mime_boundary."\r\n"; + $postdata .= "Content-Disposition: form-data; name=\"$key\[\]\"\r\n\r\n"; + $postdata .= "$cur_val\r\n"; + } + } else { + $postdata .= "--".$this->_mime_boundary."\r\n"; + $postdata .= "Content-Disposition: form-data; name=\"$key\"\r\n\r\n"; + $postdata .= "$val\r\n"; + } + } + + reset($formfiles); + while (list($field_name, $file_names) = each($formfiles)) { + settype($file_names, "array"); + while (list(, $file_name) = each($file_names)) { + if (!is_readable($file_name)) continue; + + $fp = fopen($file_name, "r"); + $file_content = fread($fp, filesize($file_name)); + fclose($fp); + $base_name = basename($file_name); + + $postdata .= "--".$this->_mime_boundary."\r\n"; + $postdata .= "Content-Disposition: form-data; name=\"$field_name\"; filename=\"$base_name\"\r\n\r\n"; + $postdata .= "$file_content\r\n"; + } + } + $postdata .= "--".$this->_mime_boundary."--\r\n"; + break; + } + + return $postdata; + } +} + +?> diff --git a/tools/IRC_Bot/magpierss/rss_cache.inc b/tools/IRC_Bot/magpierss/rss_cache.inc new file mode 100644 index 000000000..fdfa5dd25 --- /dev/null +++ b/tools/IRC_Bot/magpierss/rss_cache.inc @@ -0,0 +1,184 @@ + + * Version: 0.51 + * License: GPL + * + * The lastest version of MagpieRSS can be obtained from: + * http://magpierss.sourceforge.net + * + * For questions, help, comments, discussion, etc., please join the + * Magpie mailing list: + * http://lists.sourceforge.net/lists/listinfo/magpierss-general + * + */ + +class RSSCache { + var $BASE_CACHE = './cache'; // where the cache files are stored + var $MAX_AGE = 3600; // when are files stale, default one hour + var $ERROR = ""; // accumulate error messages + + function RSSCache ($base='', $age='') { + if ( $base ) { + $this->BASE_CACHE = $base; + } + if ( $age ) { + $this->MAX_AGE = $age; + } + + // attempt to make the cache directory + if ( ! file_exists( $this->BASE_CACHE ) ) { + $status = @mkdir( $this->BASE_CACHE, 0755 ); + + // if make failed + if ( ! $status ) { + $this->error( + "Cache couldn't make dir '" . $this->BASE_CACHE . "'." + ); + } + } + } + +/*=======================================================================*\ + Function: set + Purpose: add an item to the cache, keyed on url + Input: url from wich the rss file was fetched + Output: true on sucess +\*=======================================================================*/ + function set ($url, $rss) { + $this->ERROR = ""; + $cache_file = $this->file_name( $url ); + $fp = @fopen( $cache_file, 'w' ); + + if ( ! $fp ) { + $this->error( + "Cache unable to open file for writing: $cache_file" + ); + return 0; + } + + + $data = $this->serialize( $rss ); + fwrite( $fp, $data ); + fclose( $fp ); + + return $cache_file; + } + +/*=======================================================================*\ + Function: get + Purpose: fetch an item from the cache + Input: url from wich the rss file was fetched + Output: cached object on HIT, false on MISS +\*=======================================================================*/ + function get ($url) { + $this->ERROR = ""; + $cache_file = $this->file_name( $url ); + + if ( ! file_exists( $cache_file ) ) { + $this->debug( + "Cache doesn't contain: $url (cache file: $cache_file)" + ); + return 0; + } + + $fp = @fopen($cache_file, 'r'); + if ( ! $fp ) { + $this->error( + "Failed to open cache file for reading: $cache_file" + ); + return 0; + } + + $data = fread( $fp, filesize($cache_file) ); + $rss = $this->unserialize( $data ); + + return $rss; + } + +/*=======================================================================*\ + Function: check_cache + Purpose: check a url for membership in the cache + and whether the object is older then MAX_AGE (ie. STALE) + Input: url from wich the rss file was fetched + Output: cached object on HIT, false on MISS +\*=======================================================================*/ + function check_cache ( $url ) { + $this->ERROR = ""; + $filename = $this->file_name( $url ); + + if ( file_exists( $filename ) ) { + // find how long ago the file was added to the cache + // and whether that is longer then MAX_AGE + $mtime = filemtime( $filename ); + $age = time() - $mtime; + if ( $this->MAX_AGE > $age ) { + // object exists and is current + return 'HIT'; + } + else { + // object exists but is old + return 'STALE'; + } + } + else { + // object does not exist + return 'MISS'; + } + } + +/*=======================================================================*\ + Function: serialize +\*=======================================================================*/ + function serialize ( $rss ) { + return serialize( $rss ); + } + +/*=======================================================================*\ + Function: unserialize +\*=======================================================================*/ + function unserialize ( $data ) { + return unserialize( $data ); + } + +/*=======================================================================*\ + Function: file_name + Purpose: map url to location in cache + Input: url from wich the rss file was fetched + Output: a file name +\*=======================================================================*/ + function file_name ($url) { + $filename = md5( $url ); + return join( DIRECTORY_SEPARATOR, array( $this->BASE_CACHE, $filename ) ); + } + +/*=======================================================================*\ + Function: error + Purpose: register error +\*=======================================================================*/ + function error ($errormsg, $lvl=E_USER_WARNING) { + // append PHP's error message if track_errors enabled + if ( isset($php_errormsg) ) { + $errormsg .= " ($php_errormsg)"; + } + $this->ERROR = $errormsg; + if ( MAGPIE_DEBUG ) { + trigger_error( $errormsg, $lvl); + } + else { + error_log( $errormsg, 0); + } + } + + function debug ($debugmsg, $lvl=E_USER_NOTICE) { + if ( MAGPIE_DEBUG ) { + $this->error("MagpieRSS [debug] $debugmsg", $lvl); + } + } + +} + +?> diff --git a/tools/IRC_Bot/magpierss/rss_fetch.inc b/tools/IRC_Bot/magpierss/rss_fetch.inc new file mode 100644 index 000000000..c1098d681 --- /dev/null +++ b/tools/IRC_Bot/magpierss/rss_fetch.inc @@ -0,0 +1,458 @@ + + * License: GPL + * + * The lastest version of MagpieRSS can be obtained from: + * http://magpierss.sourceforge.net + * + * For questions, help, comments, discussion, etc., please join the + * Magpie mailing list: + * magpierss-general@lists.sourceforge.net + * + */ + +// Setup MAGPIE_DIR for use on hosts that don't include +// the current path in include_path. +// with thanks to rajiv and smarty +if (!defined('DIR_SEP')) { + define('DIR_SEP', DIRECTORY_SEPARATOR); +} + +if (!defined('MAGPIE_DIR')) { + define('MAGPIE_DIR', dirname(__FILE__) . DIR_SEP); +} + +require_once( MAGPIE_DIR . 'rss_parse.inc' ); +require_once( MAGPIE_DIR . 'rss_cache.inc' ); + +// for including 3rd party libraries +define('MAGPIE_EXTLIB', MAGPIE_DIR . 'extlib' . DIR_SEP); +require_once( MAGPIE_EXTLIB . 'Snoopy.class.inc'); + + +/* + * CONSTANTS - redefine these in your script to change the + * behaviour of fetch_rss() currently, most options effect the cache + * + * MAGPIE_CACHE_ON - Should Magpie cache parsed RSS objects? + * For me a built in cache was essential to creating a "PHP-like" + * feel to Magpie, see rss_cache.inc for rationale + * + * + * MAGPIE_CACHE_DIR - Where should Magpie cache parsed RSS objects? + * This should be a location that the webserver can write to. If this + * directory does not already exist Mapie will try to be smart and create + * it. This will often fail for permissions reasons. + * + * + * MAGPIE_CACHE_AGE - How long to store cached RSS objects? In seconds. + * + * + * MAGPIE_CACHE_FRESH_ONLY - If remote fetch fails, throw error + * instead of returning stale object? + * + * MAGPIE_DEBUG - Display debugging notices? + * +*/ + + +/*=======================================================================*\ + Function: fetch_rss: + Purpose: return RSS object for the give url + maintain the cache + Input: url of RSS file + Output: parsed RSS object (see rss_parse.inc) + + NOTES ON CACHEING: + If caching is on (MAGPIE_CACHE_ON) fetch_rss will first check the cache. + + NOTES ON RETRIEVING REMOTE FILES: + If conditional gets are on (MAGPIE_CONDITIONAL_GET_ON) fetch_rss will + return a cached object, and touch the cache object upon recieving a + 304. + + NOTES ON FAILED REQUESTS: + If there is an HTTP error while fetching an RSS object, the cached + version will be return, if it exists (and if MAGPIE_CACHE_FRESH_ONLY is off) +\*=======================================================================*/ + +define('MAGPIE_VERSION', '0.7'); + +$MAGPIE_ERROR = ""; + +function fetch_rss ($url) { + // initialize constants + init(); + + if ( !isset($url) ) { + error("fetch_rss called without a url"); + return false; + } + + // if cache is disabled + if ( !MAGPIE_CACHE_ON ) { + // fetch file, and parse it + $resp = _fetch_remote_file( $url ); + if ( is_success( $resp->status ) ) { + return _response_to_rss( $resp ); + } + else { + error("Failed to fetch $url and cache is off"); + return false; + } + } + // else cache is ON + else { + // Flow + // 1. check cache + // 2. if there is a hit, make sure its fresh + // 3. if cached obj fails freshness check, fetch remote + // 4. if remote fails, return stale object, or error + + $cache = new RSSCache( MAGPIE_CACHE_DIR, MAGPIE_CACHE_AGE ); + + if (MAGPIE_DEBUG and $cache->ERROR) { + debug($cache->ERROR, E_USER_WARNING); + } + + + $cache_status = 0; // response of check_cache + $request_headers = array(); // HTTP headers to send with fetch + $rss = 0; // parsed RSS object + $errormsg = 0; // errors, if any + + // store parsed XML by desired output encoding + // as character munging happens at parse time + $cache_key = $url . MAGPIE_OUTPUT_ENCODING; + + if (!$cache->ERROR) { + // return cache HIT, MISS, or STALE + $cache_status = $cache->check_cache( $cache_key); + } + + // if object cached, and cache is fresh, return cached obj + if ( $cache_status == 'HIT' ) { + $rss = $cache->get( $cache_key ); + if ( isset($rss) and $rss ) { + // should be cache age + $rss->from_cache = 1; + if ( MAGPIE_DEBUG > 1) { + debug("MagpieRSS: Cache HIT", E_USER_NOTICE); + } + return $rss; + } + } + + // else attempt a conditional get + + // setup headers + if ( $cache_status == 'STALE' ) { + $rss = $cache->get( $cache_key ); + if ( $rss and $rss->etag and $rss->last_modified ) { + $request_headers['If-None-Match'] = $rss->etag; + $request_headers['If-Last-Modified'] = $rss->last_modified; + } + } + + $resp = _fetch_remote_file( $url, $request_headers ); + + if (isset($resp) and $resp) { + if ($resp->status == '304' ) { + // we have the most current copy + if ( MAGPIE_DEBUG > 1) { + debug("Got 304 for $url"); + } + // reset cache on 304 (at minutillo insistent prodding) + $cache->set($cache_key, $rss); + return $rss; + } + elseif ( is_success( $resp->status ) ) { + $rss = _response_to_rss( $resp ); + if ( $rss ) { + if (MAGPIE_DEBUG > 1) { + debug("Fetch successful"); + } + // add object to cache + $cache->set( $cache_key, $rss ); + return $rss; + } + } + else { + $errormsg = "Failed to fetch $url "; + if ( $resp->status == '-100' ) { + $errormsg .= "(Request timed out after " . MAGPIE_FETCH_TIME_OUT . " seconds)"; + } + elseif ( $resp->error ) { + # compensate for Snoopy's annoying habbit to tacking + # on '\n' + $http_error = substr($resp->error, 0, -2); + $errormsg .= "(HTTP Error: $http_error)"; + } + else { + $errormsg .= "(HTTP Response: " . $resp->response_code .')'; + } + } + } + else { + $errormsg = "Unable to retrieve RSS file for unknown reasons."; + } + + // else fetch failed + + // attempt to return cached object + if ($rss) { + if ( MAGPIE_DEBUG ) { + debug("Returning STALE object for $url"); + } + return $rss; + } + + // else we totally failed + error( $errormsg ); + + return false; + + } // end if ( !MAGPIE_CACHE_ON ) { +} // end fetch_rss() + +/*=======================================================================*\ + Function: error + Purpose: set MAGPIE_ERROR, and trigger error +\*=======================================================================*/ + +function error ($errormsg, $lvl=E_USER_WARNING) { + global $MAGPIE_ERROR; + + // append PHP's error message if track_errors enabled + if ( isset($php_errormsg) ) { + $errormsg .= " ($php_errormsg)"; + } + if ( $errormsg ) { + $errormsg = "MagpieRSS: $errormsg"; + $MAGPIE_ERROR = $errormsg; + trigger_error( $errormsg, $lvl); + } +} + +function debug ($debugmsg, $lvl=E_USER_NOTICE) { + trigger_error("MagpieRSS [debug] $debugmsg", $lvl); +} + +/*=======================================================================*\ + Function: magpie_error + Purpose: accessor for the magpie error variable +\*=======================================================================*/ +function magpie_error ($errormsg="") { + global $MAGPIE_ERROR; + + if ( isset($errormsg) and $errormsg ) { + $MAGPIE_ERROR = $errormsg; + } + + return $MAGPIE_ERROR; +} + +/*=======================================================================*\ + Function: _fetch_remote_file + Purpose: retrieve an arbitrary remote file + Input: url of the remote file + headers to send along with the request (optional) + Output: an HTTP response object (see Snoopy.class.inc) +\*=======================================================================*/ +function _fetch_remote_file ($url, $headers = "" ) { + // Snoopy is an HTTP client in PHP + $client = new Snoopy(); + $client->agent = MAGPIE_USER_AGENT; + $client->read_timeout = MAGPIE_FETCH_TIME_OUT; + $client->use_gzip = MAGPIE_USE_GZIP; + if (is_array($headers) ) { + $client->rawheaders = $headers; + } + + @$client->fetch($url); + return $client; + +} + +/*=======================================================================*\ + Function: _response_to_rss + Purpose: parse an HTTP response object into an RSS object + Input: an HTTP response object (see Snoopy) + Output: parsed RSS object (see rss_parse) +\*=======================================================================*/ +function _response_to_rss ($resp) { + $rss = new MagpieRSS( $resp->results, MAGPIE_OUTPUT_ENCODING, MAGPIE_INPUT_ENCODING, MAGPIE_DETECT_ENCODING ); + + // if RSS parsed successfully + if ( $rss and !$rss->ERROR) { + + // find Etag, and Last-Modified + foreach($resp->headers as $h) { + // 2003-03-02 - Nicola Asuni (www.tecnick.com) - fixed bug "Undefined offset: 1" + if (strpos($h, ": ")) { + list($field, $val) = explode(": ", $h, 2); + } + else { + $field = $h; + $val = ""; + } + + if ( $field == 'ETag' ) { + $rss->etag = $val; + } + + if ( $field == 'Last-Modified' ) { + $rss->last_modified = $val; + } + } + + return $rss; + } // else construct error message + else { + $errormsg = "Failed to parse RSS file."; + + if ($rss) { + $errormsg .= " (" . $rss->ERROR . ")"; + } + error($errormsg); + + return false; + } // end if ($rss and !$rss->error) +} + +/*=======================================================================*\ + Function: init + Purpose: setup constants with default values + check for user overrides +\*=======================================================================*/ +function init () { + if ( defined('MAGPIE_INITALIZED') ) { + return; + } + else { + define('MAGPIE_INITALIZED', true); + } + + if ( !defined('MAGPIE_CACHE_ON') ) { + define('MAGPIE_CACHE_ON', true); + } + + if ( !defined('MAGPIE_CACHE_DIR') ) { + define('MAGPIE_CACHE_DIR', './cache'); + } + + if ( !defined('MAGPIE_CACHE_AGE') ) { + define('MAGPIE_CACHE_AGE', 60*60); // one hour + } + + if ( !defined('MAGPIE_CACHE_FRESH_ONLY') ) { + define('MAGPIE_CACHE_FRESH_ONLY', false); + } + + if ( !defined('MAGPIE_OUTPUT_ENCODING') ) { + define('MAGPIE_OUTPUT_ENCODING', 'ISO-8859-1'); + } + + if ( !defined('MAGPIE_INPUT_ENCODING') ) { + define('MAGPIE_INPUT_ENCODING', null); + } + + if ( !defined('MAGPIE_DETECT_ENCODING') ) { + define('MAGPIE_DETECT_ENCODING', true); + } + + if ( !defined('MAGPIE_DEBUG') ) { + define('MAGPIE_DEBUG', 0); + } + + if ( !defined('MAGPIE_USER_AGENT') ) { + $ua = 'MagpieRSS/'. MAGPIE_VERSION . ' (+http://magpierss.sf.net'; + + if ( MAGPIE_CACHE_ON ) { + $ua = $ua . ')'; + } + else { + $ua = $ua . '; No cache)'; + } + + define('MAGPIE_USER_AGENT', $ua); + } + + if ( !defined('MAGPIE_FETCH_TIME_OUT') ) { + define('MAGPIE_FETCH_TIME_OUT', 5); // 5 second timeout + } + + // use gzip encoding to fetch rss files if supported? + if ( !defined('MAGPIE_USE_GZIP') ) { + define('MAGPIE_USE_GZIP', true); + } +} + +// NOTE: the following code should really be in Snoopy, or at least +// somewhere other then rss_fetch! + +/*=======================================================================*\ + HTTP STATUS CODE PREDICATES + These functions attempt to classify an HTTP status code + based on RFC 2616 and RFC 2518. + + All of them take an HTTP status code as input, and return true or false + + All this code is adapted from LWP's HTTP::Status. +\*=======================================================================*/ + + +/*=======================================================================*\ + Function: is_info + Purpose: return true if Informational status code +\*=======================================================================*/ +function is_info ($sc) { + return $sc >= 100 && $sc < 200; +} + +/*=======================================================================*\ + Function: is_success + Purpose: return true if Successful status code +\*=======================================================================*/ +function is_success ($sc) { + return $sc >= 200 && $sc < 300; +} + +/*=======================================================================*\ + Function: is_redirect + Purpose: return true if Redirection status code +\*=======================================================================*/ +function is_redirect ($sc) { + return $sc >= 300 && $sc < 400; +} + +/*=======================================================================*\ + Function: is_error + Purpose: return true if Error status code +\*=======================================================================*/ +function is_error ($sc) { + return $sc >= 400 && $sc < 600; +} + +/*=======================================================================*\ + Function: is_client_error + Purpose: return true if Error status code, and its a client error +\*=======================================================================*/ +function is_client_error ($sc) { + return $sc >= 400 && $sc < 500; +} + +/*=======================================================================*\ + Function: is_client_error + Purpose: return true if Error status code, and its a server error +\*=======================================================================*/ +function is_server_error ($sc) { + return $sc >= 500 && $sc < 600; +} + +?> diff --git a/tools/IRC_Bot/magpierss/rss_parse.inc b/tools/IRC_Bot/magpierss/rss_parse.inc new file mode 100644 index 000000000..af4020ebf --- /dev/null +++ b/tools/IRC_Bot/magpierss/rss_parse.inc @@ -0,0 +1,589 @@ + +* @version 0.7a +* @license GPL +* +*/ + +define('RSS', 'RSS'); +define('ATOM', 'Atom'); + +require_once (MAGPIE_DIR . 'rss_utils.inc'); + +/** +* Hybrid parser, and object, takes RSS as a string and returns a simple object. +* +* see: rss_fetch.inc for a simpler interface with integrated caching support +* +*/ +class MagpieRSS { + var $parser; + + var $current_item = array(); // item currently being parsed + var $items = array(); // collection of parsed items + var $channel = array(); // hash of channel fields + var $textinput = array(); + var $image = array(); + var $feed_type; + var $feed_version; + var $encoding = ''; // output encoding of parsed rss + + var $_source_encoding = ''; // only set if we have to parse xml prolog + + var $ERROR = ""; + var $WARNING = ""; + + // define some constants + + var $_CONTENT_CONSTRUCTS = array('content', 'summary', 'info', 'title', 'tagline', 'copyright'); + var $_KNOWN_ENCODINGS = array('UTF-8', 'US-ASCII', 'ISO-8859-1'); + + // parser variables, useless if you're not a parser, treat as private + var $stack = array(); // parser stack + var $inchannel = false; + var $initem = false; + var $incontent = false; // if in Atom field + var $intextinput = false; + var $inimage = false; + var $current_field = ''; + var $current_namespace = false; + + + /** + * Set up XML parser, parse source, and return populated RSS object.. + * + * @param string $source string containing the RSS to be parsed + * + * NOTE: Probably a good idea to leave the encoding options alone unless + * you know what you're doing as PHP's character set support is + * a little weird. + * + * NOTE: A lot of this is unnecessary but harmless with PHP5 + * + * + * @param string $output_encoding output the parsed RSS in this character + * set defaults to ISO-8859-1 as this is PHP's + * default. + * + * NOTE: might be changed to UTF-8 in future + * versions. + * + * @param string $input_encoding the character set of the incoming RSS source. + * Leave blank and Magpie will try to figure it + * out. + * + * + * @param bool $detect_encoding if false Magpie won't attempt to detect + * source encoding. (caveat emptor) + * + */ + function MagpieRSS ($source, $output_encoding='ISO-8859-1', + $input_encoding=null, $detect_encoding=true) + { + # if PHP xml isn't compiled in, die + # + if (!function_exists('xml_parser_create')) { + $this->error( "Failed to load PHP's XML Extension. " . + "http://www.php.net/manual/en/ref.xml.php", + E_USER_ERROR ); + } + + list($parser, $source) = $this->create_parser($source, + $output_encoding, $input_encoding, $detect_encoding); + + + if (!is_resource($parser)) { + $this->error( "Failed to create an instance of PHP's XML parser. " . + "http://www.php.net/manual/en/ref.xml.php", + E_USER_ERROR ); + } + + + $this->parser = $parser; + + # pass in parser, and a reference to this object + # setup handlers + # + xml_set_object( $this->parser, $this ); + xml_set_element_handler($this->parser, + 'feed_start_element', 'feed_end_element' ); + + xml_set_character_data_handler( $this->parser, 'feed_cdata' ); + + $status = xml_parse( $this->parser, $source ); + + if (! $status ) { + $errorcode = xml_get_error_code( $this->parser ); + if ( $errorcode != XML_ERROR_NONE ) { + $xml_error = xml_error_string( $errorcode ); + $error_line = xml_get_current_line_number($this->parser); + $error_col = xml_get_current_column_number($this->parser); + $errormsg = "$xml_error at line $error_line, column $error_col"; + + $this->error( $errormsg ); + } + } + + xml_parser_free( $this->parser ); + + $this->normalize(); + } + + function feed_start_element($p, $element, &$attrs) { + $el = $element = strtolower($element); + $attrs = array_change_key_case($attrs, CASE_LOWER); + + // check for a namespace, and split if found + $ns = false; + if ( strpos( $element, ':' ) ) { + list($ns, $el) = split( ':', $element, 2); + } + if ( $ns and $ns != 'rdf' ) { + $this->current_namespace = $ns; + } + + # if feed type isn't set, then this is first element of feed + # identify feed from root element + # + if (!isset($this->feed_type) ) { + if ( $el == 'rdf' ) { + $this->feed_type = RSS; + $this->feed_version = '1.0'; + } + elseif ( $el == 'rss' ) { + $this->feed_type = RSS; + $this->feed_version = $attrs['version']; + } + elseif ( $el == 'feed' ) { + $this->feed_type = ATOM; + $this->feed_version = $attrs['version']; + $this->inchannel = true; + } + return; + } + + if ( $el == 'channel' ) + { + $this->inchannel = true; + } + elseif ($el == 'item' or $el == 'entry' ) + { + $this->initem = true; + if ( isset($attrs['rdf:about']) ) { + $this->current_item['about'] = $attrs['rdf:about']; + } + } + + // if we're in the default namespace of an RSS feed, + // record textinput or image fields + elseif ( + $this->feed_type == RSS and + $this->current_namespace == '' and + $el == 'textinput' ) + { + $this->intextinput = true; + } + + elseif ( + $this->feed_type == RSS and + $this->current_namespace == '' and + $el == 'image' ) + { + $this->inimage = true; + } + + # handle atom content constructs + elseif ( $this->feed_type == ATOM and in_array($el, $this->_CONTENT_CONSTRUCTS) ) + { + // avoid clashing w/ RSS mod_content + if ($el == 'content' ) { + $el = 'atom_content'; + } + + $this->incontent = $el; + + + } + + // if inside an Atom content construct (e.g. content or summary) field treat tags as text + elseif ($this->feed_type == ATOM and $this->incontent ) + { + // if tags are inlined, then flatten + $attrs_str = join(' ', + array_map('map_attrs', + array_keys($attrs), + array_values($attrs) ) ); + + $this->append_content( "<$element $attrs_str>" ); + + array_unshift( $this->stack, $el ); + } + + // Atom support many links per containging element. + // Magpie treats link elements of type rel='alternate' + // as being equivalent to RSS's simple link element. + // + elseif ($this->feed_type == ATOM and $el == 'link' ) + { + if ( isset($attrs['rel']) and $attrs['rel'] == 'alternate' ) + { + $link_el = 'link'; + } + else { + $link_el = 'link_' . $attrs['rel']; + } + + $this->append($link_el, $attrs['href']); + } + // set stack[0] to current element + else { + array_unshift($this->stack, $el); + } + } + + + + function feed_cdata ($p, $text) { + + if ($this->feed_type == ATOM and $this->incontent) + { + $this->append_content( $text ); + } + else { + $current_el = join('_', array_reverse($this->stack)); + $this->append($current_el, $text); + } + } + + function feed_end_element ($p, $el) { + $el = strtolower($el); + + if ( $el == 'item' or $el == 'entry' ) + { + $this->items[] = $this->current_item; + $this->current_item = array(); + $this->initem = false; + } + elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'textinput' ) + { + $this->intextinput = false; + } + elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'image' ) + { + $this->inimage = false; + } + elseif ($this->feed_type == ATOM and in_array($el, $this->_CONTENT_CONSTRUCTS) ) + { + $this->incontent = false; + } + elseif ($el == 'channel' or $el == 'feed' ) + { + $this->inchannel = false; + } + elseif ($this->feed_type == ATOM and $this->incontent ) { + // balance tags properly + // note: i don't think this is actually neccessary + if ( $this->stack[0] == $el ) + { + $this->append_content(""); + } + else { + $this->append_content("<$el />"); + } + + array_shift( $this->stack ); + } + else { + array_shift( $this->stack ); + } + + $this->current_namespace = false; + } + + function concat (&$str1, $str2="") { + if (!isset($str1) ) { + $str1=""; + } + $str1 .= $str2; + } + + + + function append_content($text) { + if ( $this->initem ) { + $this->concat( $this->current_item[ $this->incontent ], $text ); + } + elseif ( $this->inchannel ) { + $this->concat( $this->channel[ $this->incontent ], $text ); + } + } + + // smart append - field and namespace aware + function append($el, $text) { + if (!$el) { + return; + } + if ( $this->current_namespace ) + { + if ( $this->initem ) { + $this->concat( + $this->current_item[ $this->current_namespace ][ $el ], $text); + } + elseif ($this->inchannel) { + $this->concat( + $this->channel[ $this->current_namespace][ $el ], $text ); + } + elseif ($this->intextinput) { + $this->concat( + $this->textinput[ $this->current_namespace][ $el ], $text ); + } + elseif ($this->inimage) { + $this->concat( + $this->image[ $this->current_namespace ][ $el ], $text ); + } + } + else { + if ( $this->initem ) { + $this->concat( + $this->current_item[ $el ], $text); + } + elseif ($this->intextinput) { + $this->concat( + $this->textinput[ $el ], $text ); + } + elseif ($this->inimage) { + $this->concat( + $this->image[ $el ], $text ); + } + elseif ($this->inchannel) { + $this->concat( + $this->channel[ $el ], $text ); + } + + } + } + + function normalize () { + // if atom populate rss fields + if ( $this->is_atom() ) { + $this->channel['description'] = $this->channel['tagline']; + for ( $i = 0; $i < count($this->items); $i++) { + $item = $this->items[$i]; + if ( isset($item['summary']) ) + $item['description'] = $item['summary']; + if ( isset($item['atom_content'])) + $item['content']['encoded'] = $item['atom_content']; + + $atom_date = (isset($item['issued']) ) ? $item['issued'] : $item['modified']; + if ( $atom_date ) { + $epoch = @parse_w3cdtf($item['modified']); + if ($epoch and $epoch > 0) { + $item['date_timestamp'] = $epoch; + } + } + + $this->items[$i] = $item; + } + } + elseif ( $this->is_rss() ) { + $this->channel['tagline'] = $this->channel['description']; + for ( $i = 0; $i < count($this->items); $i++) { + $item = $this->items[$i]; + if ( isset($item['description'])) + $item['summary'] = $item['description']; + if ( isset($item['content']['encoded'] ) ) + $item['atom_content'] = $item['content']['encoded']; + + if ( $this->is_rss() == '1.0' and isset($item['dc']['date']) ) { + $epoch = @parse_w3cdtf($item['dc']['date']); + if ($epoch and $epoch > 0) { + $item['date_timestamp'] = $epoch; + } + } + elseif ( isset($item['pubdate']) ) { + $epoch = @strtotime($item['pubdate']); + if ($epoch > 0) { + $item['date_timestamp'] = $epoch; + } + } + + $this->items[$i] = $item; + } + } + } + + + function is_rss () { + if ( $this->feed_type == RSS ) { + return $this->feed_version; + } + else { + return false; + } + } + + function is_atom() { + if ( $this->feed_type == ATOM ) { + return $this->feed_version; + } + else { + return false; + } + } + + /** + * return XML parser, and possibly re-encoded source + * + */ + function create_parser($source, $out_enc, $in_enc, $detect) { + if ( substr(phpversion(),0,1) == 5) { + $parser = $this->php5_create_parser($in_enc, $detect); + } + else { + list($parser, $source) = $this->php4_create_parser($source, $in_enc, $detect); + } + if ($out_enc) { + $this->encoding = $out_enc; + xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, $out_enc); + } + + return array($parser, $source); + } + + /** + * Instantiate an XML parser under PHP5 + * + * PHP5 will do a fine job of detecting input encoding + * if passed an empty string as the encoding. + * + * All hail libxml2! + * + */ + function php5_create_parser($in_enc, $detect) { + // by default php5 does a fine job of detecting input encodings + if(!$detect && $in_enc) { + return xml_parser_create($in_enc); + } + else { + return xml_parser_create(''); + } + } + + /** + * Instaniate an XML parser under PHP4 + * + * Unfortunately PHP4's support for character encodings + * and especially XML and character encodings sucks. As + * long as the documents you parse only contain characters + * from the ISO-8859-1 character set (a superset of ASCII, + * and a subset of UTF-8) you're fine. However once you + * step out of that comfy little world things get mad, bad, + * and dangerous to know. + * + * The following code is based on SJM's work with FoF + * @see http://minutillo.com/steve/weblog/2004/6/17/php-xml-and-character-encodings-a-tale-of-sadness-rage-and-data-loss + * + */ + function php4_create_parser($source, $in_enc, $detect) { + if ( !$detect ) { + return array(xml_parser_create($in_enc), $source); + } + + if (!$in_enc) { + if (preg_match('//m', $source, $m)) { + $in_enc = strtoupper($m[1]); + $this->source_encoding = $in_enc; + } + else { + $in_enc = 'UTF-8'; + } + } + + if ($this->known_encoding($in_enc)) { + return array(xml_parser_create($in_enc), $source); + } + + // the dectected encoding is not one of the simple encodings PHP knows + + // attempt to use the iconv extension to + // cast the XML to a known encoding + // @see http://php.net/iconv + + if (function_exists('iconv')) { + $encoded_source = iconv($in_enc,'UTF-8', $source); + if ($encoded_source) { + return array(xml_parser_create('UTF-8'), $encoded_source); + } + } + + // iconv didn't work, try mb_convert_encoding + // @see http://php.net/mbstring + if(function_exists('mb_convert_encoding')) { + $encoded_source = mb_convert_encoding($source, 'UTF-8', $in_enc ); + if ($encoded_source) { + return array(xml_parser_create('UTF-8'), $encoded_source); + } + } + + // else + $this->error("Feed is in an unsupported character encoding. ($in_enc) " . + "You may see strange artifacts, and mangled characters.", + E_USER_NOTICE); + + return array(xml_parser_create(), $source); + } + + function known_encoding($enc) { + $enc = strtoupper($enc); + if ( in_array($enc, $this->_KNOWN_ENCODINGS) ) { + return $enc; + } + else { + return false; + } + } + + function error ($errormsg, $lvl=E_USER_WARNING) { + // append PHP's error message if track_errors enabled + if ( $php_errormsg ) { + $errormsg .= " ($php_errormsg)"; + } + if ( MAGPIE_DEBUG ) { + trigger_error( $errormsg, $lvl); + } + else { + error_log( $errormsg, 0); + } + + $notices = E_USER_NOTICE|E_NOTICE; + if ( $lvl&$notices ) { + $this->WARNING = $errormsg; + } else { + $this->ERROR = $errormsg; + } + } + + +} // end class RSS + +function map_attrs($k, $v) { + return "$k=\"$v\""; +} + + +?> diff --git a/tools/IRC_Bot/magpierss/rss_utils.inc b/tools/IRC_Bot/magpierss/rss_utils.inc new file mode 100644 index 000000000..2a29e72a9 --- /dev/null +++ b/tools/IRC_Bot/magpierss/rss_utils.inc @@ -0,0 +1,67 @@ + + * Version: 0.51 + * License: GPL + * + * The lastest version of MagpieRSS can be obtained from: + * http://magpierss.sourceforge.net + * + * For questions, help, comments, discussion, etc., please join the + * Magpie mailing list: + * magpierss-general@lists.sourceforge.net + */ + + +/*======================================================================*\ + Function: parse_w3cdtf + Purpose: parse a W3CDTF date into unix epoch + + NOTE: http://www.w3.org/TR/NOTE-datetime +\*======================================================================*/ + +function parse_w3cdtf ( $date_str ) { + + # regex to match wc3dtf + $pat = "/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(:(\d{2}))?(?:([-+])(\d{2}):?(\d{2})|(Z))?/"; + + if ( preg_match( $pat, $date_str, $match ) ) { + list( $year, $month, $day, $hours, $minutes, $seconds) = + array( $match[1], $match[2], $match[3], $match[4], $match[5], $match[6]); + + # calc epoch for current date assuming GMT + $epoch = gmmktime( $hours, $minutes, $seconds, $month, $day, $year); + + $offset = 0; + if ( $match[10] == 'Z' ) { + # zulu time, aka GMT + } + else { + list( $tz_mod, $tz_hour, $tz_min ) = + array( $match[8], $match[9], $match[10]); + + # zero out the variables + if ( ! $tz_hour ) { $tz_hour = 0; } + if ( ! $tz_min ) { $tz_min = 0; } + + $offset_secs = (($tz_hour*60)+$tz_min)*60; + + # is timezone ahead of GMT? then subtract offset + # + if ( $tz_mod == '+' ) { + $offset_secs = $offset_secs * -1; + } + + $offset = $offset_secs; + } + $epoch = $epoch + $offset; + return $epoch; + } + else { + return -1; + } +} + +?> diff --git a/tools/LevelConverter/Makefile b/tools/LevelConverter/Makefile new file mode 100644 index 000000000..23b8a1106 --- /dev/null +++ b/tools/LevelConverter/Makefile @@ -0,0 +1,16 @@ +# Makfile for SRB2 Level Converter +# by Alam Arias et al. + +SRC=levelconverter.c +OBJ=$(SRC:.c=.o)# replaces the .c from SRC with .o +EXE=LevelConverter + +.PHONY : all # .PHONY ignores files named all +all: $(EXE) # all is dependent on $(BIN) to be complete + +$(EXE): $(OBJ) # $(EXE) is dependent on all of the files in $(OBJ) to exist + $(CC) $(OBJ) $(LDFLAGS) -o $@ + +.PHONY : clean # .PHONY ignores files named clean +clean: + -$(RM) $(OBJ) $(EXE) diff --git a/tools/LevelConverter/levelconverter.c b/tools/LevelConverter/levelconverter.c new file mode 100644 index 000000000..7c84ac510 --- /dev/null +++ b/tools/LevelConverter/levelconverter.c @@ -0,0 +1,1061 @@ +// +// Level Converter +// +// Converts thing types from 1.09.4 to 1.1 +// +// By A.J. Freda +// +// Modified from Graue's "Heightedit" +// and uses Graue's "LumpMod" utility. +// + +#include +#include +#include + +//#define STARPOSTS_ONLY + +#define TABLE_SIZE 16384 +int conversion[TABLE_SIZE]; // Conversion table. +FILE *lvlconvfile; + +static inline void InitializeThingConversionTable(void) +{ + memset(conversion, 0, sizeof(conversion)); + + // Player starts + conversion[1] = 1; + conversion[2] = 2; + conversion[3] = 3; + conversion[4] = 4; + conversion[4001] = 5; + conversion[4002] = 6; + conversion[4003] = 7; + conversion[4004] = 8; + conversion[4005] = 9; + conversion[4006] = 10; + conversion[4007] = 11; + conversion[4008] = 12; + conversion[4009] = 13; + conversion[4010] = 14; + conversion[4011] = 15; + conversion[4012] = 16; + conversion[4013] = 17; + conversion[4014] = 18; + conversion[4015] = 19; + conversion[4016] = 20; + conversion[4017] = 21; + conversion[4018] = 22; + conversion[4019] = 23; + conversion[4020] = 24; + conversion[4021] = 25; + conversion[4022] = 26; + conversion[4023] = 27; + conversion[4024] = 28; + conversion[4025] = 29; + conversion[4026] = 30; + conversion[4027] = 31; + conversion[4028] = 32; + conversion[11] = 33; + conversion[87] = 34; + conversion[89] = 35; + + // Enemies + conversion[3004] = 100; + conversion[9] = 101; + conversion[58] = 102; + conversion[5005] = 103; + conversion[5006] = 104; + conversion[3005] = 105; + conversion[22] = 106; + conversion[21] = 107; + conversion[71] = 108; + conversion[56] = 109; + conversion[2004] = 110; + conversion[42] = 111; + + // Bosses + conversion[16] = 200; + conversion[2008] = 201; + conversion[17] = 290; + conversion[2049] = 291; + + // Collectibles + conversion[2014] = 300; + conversion[69] = 301; + conversion[3003] = 302; + conversion[80] = 303; + conversion[26] = 304; + conversion[54] = 305; + conversion[31] = 310; + conversion[34] = 311; + conversion[2013] = 312; + conversion[420] = 313; + conversion[421] = 314; + conversion[422] = 315; + conversion[423] = 316; + conversion[424] = 317; + conversion[425] = 318; + conversion[426] = 319; + conversion[64] = 320; + conversion[3002] = 320; + conversion[3001] = 320; + + // Boxes + conversion[2011] = 400; + conversion[2012] = 400; + conversion[48] = 402; + conversion[2002] = 403; + conversion[2018] = 404; + conversion[35] = 405; + conversion[2028] = 406; + conversion[25] = 407; + conversion[2022] = 408; + conversion[41] = 409; + conversion[2005] = 410; + conversion[78] = 411; + conversion[3000] = 412; + + // Interactive Objects + conversion[33] = 500; + conversion[86] = 501; + conversion[3006] = 502; +// conversion[?] = 520; + conversion[23] = 521; + conversion[67] = 522; + conversion[68] = 523; + conversion[32] = 540; + conversion[30] = 541; + conversion[28] = 550; + conversion[79] = 551; + conversion[5004] = 552; + conversion[65] = 553; + conversion[66] = 554; + conversion[2015] = 555; + conversion[38] = 556; + conversion[20] = 557; + conversion[39] = 558; + + // Special Placement Patterns + conversion[84] = 600; + conversion[44] = 601; + conversion[76] = 602; + conversion[77] = 603; + conversion[47] = 604; + conversion[2007] = 605; + conversion[2048] = 606; + conversion[2010] = 607; + conversion[2046] = 608; + conversion[2047] = 609; + + // Powerup Indicators/Environmental Effects/Miscellany + conversion[2026] = 700; + conversion[2024] = 701; + conversion[2023] = 702; + conversion[2045] = 703; + conversion[83] = 704; + conversion[2019] = 705; + conversion[2025] = 706; + conversion[27] = 707; + conversion[14] = 708; + conversion[43] = 709; + conversion[8] = 750; + conversion[5003] = 751; + conversion[5007] = 752; + conversion[18] = 753; + conversion[5001] = 754; + conversion[5002] = 755; + conversion[2003] = 756; + + // Greenflower Scenery + conversion[36] = 800; + conversion[70] = 801; + conversion[73] = 802; + conversion[74] = 804; + conversion[75] = 805; + + // Techno Hill Scenery + conversion[2035] = 900; + conversion[2006] = 901; + + // Deep Sea Scenery + conversion[81] = 1000; + + // Castle Eggman Scenery + conversion[49] = 1100; + conversion[24] = 1101; + conversion[52] = 1102; + conversion[2001] = 1103; + + // NiGHTS Items + conversion[72] = 1700; + conversion[61] = 1701; + conversion[46] = 1702; + conversion[60] = 1703; + conversion[82] = 1704; + conversion[57] = 1705; + conversion[37] = 1706; + conversion[3007] = 1707; + conversion[3008] = 1708; + conversion[3009] = 1709; + conversion[40] = 1710; + + // Mario Items + conversion[10005] = 1800; + conversion[10000] = 1801; + conversion[10001] = 1802; + conversion[50] = 1803; + conversion[10] = 1804; + conversion[29] = 1805; + conversion[19] = 1806; + conversion[12] = 1807; + conversion[10002] = 1808; + conversion[10003] = 1809; + conversion[10004] = 1810; + + // Christmas Items + conversion[5] = 1850; + conversion[13] = 1851; + conversion[6] = 1852; +} + +static inline void InitializeSectorConversionTable(void) +{ + memset(conversion, 0, sizeof(conversion)); + + // Player starts + conversion[690] = -1; + conversion[691] = -1; + conversion[692] = -1; + conversion[693] = -1; + conversion[694] = -1; + conversion[695] = -1; + conversion[696] = -1; + conversion[697] = -1; + conversion[698] = -1; + conversion[699] = -1; + conversion[700] = -1; + conversion[701] = -1; + conversion[702] = -1; + conversion[703] = -1; + conversion[704] = -1; + conversion[705] = -1; + conversion[706] = -1; + conversion[707] = -1; + conversion[708] = -1; + conversion[709] = -1; + conversion[710] = -1; + conversion[711] = -1; + conversion[981] = -1; + conversion[986] = -1; + conversion[8] = -1; + conversion[17] = -1; + conversion[519] = 3 + (512 << 8); + conversion[984] = 2 + (512 << 8); + + // Section 1 + conversion[11] = 1; + conversion[983] = 2; + conversion[7] = 3; + conversion[18] = 4; + conversion[4] = 5; + conversion[16] = 6; + conversion[5] = 7; + conversion[10] = 8; + conversion[978] = 9; + conversion[980] = 10; + conversion[9] = 11; + conversion[6] = 12; + conversion[992] = 13; + conversion[996] = 14; + conversion[14] = 15; + + // Section 2 + conversion[971] = 1 << 4; + conversion[972] = 2 << 4; + conversion[973] = 3 << 4; + conversion[974] = 4 << 4; + conversion[975] = 5 << 4; + conversion[967] = 6 << 4; + conversion[968] = 7 << 4; + conversion[970] = 8 << 4; + conversion[666] = 9 << 4; + conversion[990] = 10 << 4; + conversion[991] = 11 << 4; + + // Section 3 + conversion[256] = 1 << 8; + conversion[512] = 2 << 8; + conversion[768] = 3 << 8; + conversion[985] = 4 << 8; + conversion[976] = 5 << 8; + conversion[977] = 6 << 8; + conversion[1500] = 7 << 8; + conversion[1501] = 8 << 8; + conversion[1502] = 9 << 8; + conversion[1503] = 10 << 8; + conversion[1504] = 11 << 8; + conversion[1505] = 12 << 8; + conversion[1506] = 13 << 8; + conversion[1507] = 14 << 8; + conversion[1508] = 15 << 8; + + // Section 4 + conversion[993] = 1 << 12; + conversion[33] = 2 << 12; + conversion[982] = 2 << 12; + conversion[987] = 2 << 12; + conversion[995] = 2 << 12; + conversion[988] = 3 << 12; + conversion[989] = 4 << 12; + conversion[997] = 5 << 12; + conversion[969] = 6 << 12; + conversion[979] = 7 << 12; + conversion[998] = 8 << 12; + conversion[999] = 9 << 12; + conversion[994] = 10 << 12; +} + +static inline void InitializeLinedefConversionTable(void) +{ + memset(conversion, 0, sizeof(conversion)); + + // Old Water Removed + conversion[14] = -1; + + // Level Parameters/Misc: + conversion[64] = 1; + conversion[71] = 2; + conversion[18] = 3; + conversion[65] = 4; + conversion[63] = 5; + conversion[73] = 6; + conversion[66] = 7; + + // Level-Load Effects: + conversion[26] = 50; + conversion[24] = 51; + conversion[88] = 52; + conversion[2] = 53; + conversion[3] = 54; + conversion[4] = 55; + conversion[6] = 56; + conversion[7] = 57; + conversion[8] = 58; + conversion[232] = 59; + conversion[233] = 60; + conversion[43] = 61; + conversion[50] = 62; + conversion[242] = 63; + + // Floor-Over-Floors: + conversion[25] = 100; + conversion[33] = 101; + conversion[44] = 102; + conversion[69] = 103; + conversion[51] = 104; + conversion[57] = 105; + conversion[48] = 120; + conversion[45] = 121; + conversion[75] = 122; + conversion[74] = 123; + conversion[59] = 140; + conversion[81] = 141; + conversion[77] = 142; + conversion[38] = 150; + conversion[68] = 151; + conversion[72] = 152; + conversion[34] = 160; + conversion[36] = 170; + conversion[35] = 171; + conversion[79] = 172; + conversion[80] = 173; + conversion[82] = 174; + conversion[83] = 175; + conversion[39] = 176; + conversion[1] = 177; + conversion[37] = 178; + conversion[42] = 179; + conversion[40] = 180; + conversion[89] = 190; + conversion[90] = 191; + conversion[91] = 192; + conversion[94] = 193; + conversion[92] = 194; + conversion[93] = 195; + conversion[49] = 200; + conversion[47] = 201; + conversion[46] = 202; + conversion[62] = 220; + conversion[52] = 221; + conversion[67] = 222; + conversion[58] = 223; + conversion[41] = 250; + conversion[54] = 251; + conversion[76] = 252; + conversion[86] = 253; + conversion[55] = 254; + conversion[78] = 255; + conversion[84] = 256; + conversion[56] = 257; + conversion[53] = 258; + conversion[87] = 259; + + // Linedef Executor Triggers: + conversion[96] = 300; + conversion[97] = 301; + conversion[98] = 302; + conversion[95] = 303; + conversion[99] = 304; + conversion[19] = 305; + conversion[20] = 306; + conversion[21] = 307; + conversion[9] = 308; + conversion[10] = 309; + conversion[11] = 310; + conversion[12] = 311; + conversion[13] = 312; + conversion[15] = 313; + + // Linedef Executor Options: + conversion[101] = 400; + conversion[102] = 401; + conversion[103] = 402; + conversion[106] = 403; + conversion[107] = 404; + conversion[108] = 405; + conversion[109] = 406; + conversion[110] = 407; + conversion[111] = 408; + conversion[112] = 409; + conversion[114] = 410; + conversion[116] = 411; + conversion[104] = 412; + conversion[105] = 413; + conversion[115] = 414; + conversion[113] = 415; + conversion[119] = 416; + conversion[120] = 417; + conversion[117] = 420; + conversion[118] = 421; + conversion[121] = 422; + conversion[123] = 423; + conversion[124] = 424; + conversion[125] = 425; + conversion[122] = 426; + conversion[126] = 427; + conversion[127] = 428; + + // Scrollers/Pushers + conversion[100] = 500; + conversion[85] = 501; + conversion[254] = 502; + conversion[218] = 503; + conversion[249] = 504; + conversion[255] = 505; + conversion[251] = 510; + conversion[215] = 511; + conversion[246] = 512; + conversion[250] = 513; + conversion[214] = 514; + conversion[245] = 515; + conversion[252] = 520; + conversion[216] = 521; + conversion[247] = 522; + conversion[203] = 523; + conversion[205] = 524; + conversion[201] = 525; + conversion[253] = 530; + conversion[217] = 531; + conversion[248] = 532; + conversion[202] = 533; + conversion[204] = 534; + conversion[200] = 535; + conversion[223] = 540; + conversion[224] = 541; + conversion[229] = 542; + conversion[230] = 543; + conversion[225] = 544; + conversion[227] = 545; + conversion[228] = 546; + conversion[226] = 547; + + // Lighting + conversion[213] = 600; + + conversion[5] = 601; + conversion[60] = 602; + conversion[61] = 603; + conversion[16] = 606; + + // Translucency + conversion[284] = 900; + conversion[285] = 901; + conversion[286] = 902; + conversion[287] = 903; + conversion[288] = 904; + conversion[283] = 905; + + // Extended numbers + conversion[281] = conversion[25]; + conversion[289] = conversion[33]; + conversion[282] = conversion[26]; +} + +#ifndef _WIN32 +#include +static inline const char* _strupr(char *n) +{ + const char *m = n; + while (*n != '\0') + { + *n = toupper(*n); + n++; + } + return m; +} +#define strupr _strupr +#endif + +static inline int ConvertStarposts(char *argv[]) +{ + char syscmd[100]; + InitializeThingConversionTable(); + + sprintf(syscmd, "lumpmod %s extract -s MAP%s THINGS lvlconv.tmp", + argv[1], strupr(argv[2])); + system(syscmd); + + lvlconvfile = fopen("lvlconv.tmp", "r+b"); + if(lvlconvfile == NULL) { + puts("Failed to open lvlconv.tmp."); + return EXIT_FAILURE; + } + for(;;) { + int c; + short x, y, angle, type, options; + + fseek(lvlconvfile, 1, SEEK_CUR); + fseek(lvlconvfile, -1, SEEK_CUR); + + c = fgetc(lvlconvfile); + if(c == EOF) break; + + fseek(lvlconvfile, -1, SEEK_CUR); + if(fread(&x, sizeof(short), 1, lvlconvfile) < 1) { + puts("I CANNOT READ THE X"); + return EXIT_FAILURE; + } + if(fread(&y, sizeof(short), 1, lvlconvfile) < 1) { + puts("I CAN'T READ THE Y"); + return EXIT_FAILURE; + } + if(fread(&angle, sizeof(short), 1, lvlconvfile) < 1) { + puts("I CAN'T READ THE ANGLE"); + return EXIT_FAILURE; + } + if(fread(&type, sizeof(short), 1, lvlconvfile) < 1) { + puts("I CAN'T READ THE TYPE"); + return EXIT_FAILURE; + } + if(fread(&options, sizeof(short), 1, lvlconvfile) < 1) { + puts("I CAN'T READ THE FLAGS"); + return EXIT_FAILURE; + } + + fseek(lvlconvfile, -6, SEEK_CUR); + + /* CHECK FOR MATCH */ + if(type == 502) + { + int numpost = options & 31; + angle %= 360; + angle += numpost * 360; + options = 0; + } + + if(fwrite(&angle, sizeof(short), 1, lvlconvfile) < 1) { + puts("I CANNOT WRITE THE ANGLE"); + return EXIT_FAILURE; + } + + if(fwrite(&type, sizeof(short), 1, lvlconvfile) < 1) { + puts("I CANNOT WRITE THE TYPE"); + return EXIT_FAILURE; + } + + if (fwrite(&options, sizeof(short), 1, lvlconvfile) < 1) { + puts("I CANNOT WRITE THE FLAGS"); + return EXIT_FAILURE; + } + } + fclose(lvlconvfile); + puts("DONE, Man!.. Inserting into WAD.\n"); + sprintf(syscmd, "lumpmod %s update -s MAP%s THINGS lvlconv.tmp", + argv[1], strupr(argv[2])); + system(syscmd); + remove("lvlconv.tmp"); + return 1; +} + +static inline int ConvertThings(char *argv[]) +{ + char syscmd[100]; + InitializeThingConversionTable(); + + printf("NOTE: Skill settings not supported in 1.1. All of your objects\nhave been converted to appear regardless of skill level.\n"); + + sprintf(syscmd, "lumpmod %s extract -s MAP%s THINGS lvlconv.tmp", + argv[1], strupr(argv[2])); + system(syscmd); + + lvlconvfile = fopen("lvlconv.tmp", "r+b"); + if(lvlconvfile == NULL) { + puts("Failed to open lvlconv.tmp."); + return EXIT_FAILURE; + } + for(;;) { + int c; + short x, y, angle, type, options; + + fseek(lvlconvfile, 1, SEEK_CUR); + fseek(lvlconvfile, -1, SEEK_CUR); + + c = fgetc(lvlconvfile); + if(c == EOF) break; + + fseek(lvlconvfile, -1, SEEK_CUR); + if(fread(&x, sizeof(short), 1, lvlconvfile) < 1) { + puts("I CANNOT READ THE X"); + return EXIT_FAILURE; + } + if(fread(&y, sizeof(short), 1, lvlconvfile) < 1) { + puts("I CAN'T READ THE Y"); + return EXIT_FAILURE; + } + if(fread(&angle, sizeof(short), 1, lvlconvfile) < 1) { + puts("I CAN'T READ THE ANGLE"); + return EXIT_FAILURE; + } + if(fread(&type, sizeof(short), 1, lvlconvfile) < 1) { + puts("I CAN'T READ THE TYPE"); + return EXIT_FAILURE; + } + if(fread(&options, sizeof(short), 1, lvlconvfile) < 1) { + puts("I CAN'T READ THE FLAGS"); + return EXIT_FAILURE; + } + + fseek(lvlconvfile, -6, SEEK_CUR); + + /* CHECK FOR MATCH */ + if(type != 32000 && type != 32001) // !@#$%^ Doom Builder... + { + if(type < TABLE_SIZE && conversion[type] < 0) + printf("\nThing type %d no longer supported. You will have to manually change this.", type); + else if(type < TABLE_SIZE && conversion[type] != 0) + type = conversion[type]; + else + printf("\nUnknown thing type %d!", type); + + if (type != 502 && type != 1700 && type != 1701 && type != 1702 && type != 1703 && type != 1704 && type != 1705) + { + if (options == 1 || options == 4) + { + printf("\nThing type %d on Easy or Hard only, renamed to thing type 4242.", type); + type = 4242; + } + + options &= ~7; // Strip skill settings + } + } + + if (type == 502) + { + int numpost = options & 31; + angle %= 360; + angle += numpost * 360; + options = 0; + } + + if(fwrite(&angle, sizeof(short), 1, lvlconvfile) < 1) { + puts("I CANNOT WRITE THE ANGLE"); + return EXIT_FAILURE; + } + + if(fwrite(&type, sizeof(short), 1, lvlconvfile) < 1) { + puts("I CANNOT WRITE THE TYPE"); + return EXIT_FAILURE; + } + + if (fwrite(&options, sizeof(short), 1, lvlconvfile) < 1) { + puts("I CANNOT WRITE THE FLAGS"); + return EXIT_FAILURE; + } + } + fclose(lvlconvfile); + puts("DONE, Man!.. Inserting into WAD.\n"); + sprintf(syscmd, "lumpmod %s update -s MAP%s THINGS lvlconv.tmp", + argv[1], strupr(argv[2])); + system(syscmd); + remove("lvlconv.tmp"); + return 1; +} + +static void ConvertFlat(char *garbage) +{ + /* CHECK FOR MATCH */ + if(!memcmp(garbage, "FLOOR0_3\0\0\0\0", 8)) + strncpy(garbage, "GFZFLR01\0\0\0\0", 8); + else if(!memcmp(garbage, "FLOOR0_6\0\0\0", 8)) + strncpy(garbage, "GFZFLR02\0\0\0", 8); + else if(!memcmp(garbage, "CEIL3_3\0\0\0\0\0", 8) || !memcmp(garbage, "GATE1\0\0\0\0\0\0", 8)) + strncpy(garbage, "GFZFLR03\0\0\0\0\0\0\0", 8); + else if(!memcmp(garbage, "CEIL3_4\0\0\0\0\0", 8)) + strncpy(garbage, "GFZFLR04\0\0\0\0\0\0\0", 8); + else if(!memcmp(garbage, "FLOOR1_1\0\0\0\0\0", 8)) + strncpy(garbage, "GFZFLR05\0\0\0\0\0\0\0", 8); + else if(!memcmp(garbage, "FLOOR1_7\0\0\0\0\0", 8)) + strncpy(garbage, "GFZFLR06\0\0\0\0\0\0\0", 8); + else if(!memcmp(garbage, "FLOOR5_3\0\0\0\0\0", 8)) + strncpy(garbage, "GFZFLR07\0\0\0\0\0\0\0", 8); + else if(!memcmp(garbage, "OLDROCK\0\0\0\0\0\0", 8)) + strncpy(garbage, "GFZFLR08\0\0\0\0\0\0\0", 8); + else if(!memcmp(garbage, "SFLR5_0\0\0\0\0\0", 8)) + strncpy(garbage, "GFZFLR09\0\0\0\0\0\0", 8); + else if(!memcmp(garbage, "SFLR6_1\0\0\0\0\0", 8) + || !memcmp(garbage, "SFLR6_4\0\0\0\0\0", 8) + || !memcmp(garbage, "SFLR7_1\0\0\0\0\0", 8) + || !memcmp(garbage, "SFLR7_4\0\0\0\0\0", 8)) + { + printf("Flat pic %s no longer supported. Use GFZFLR09 with\r\nlinedef special #7 to achieve same effect.\r\nFlat converted to GFZFLR09 for your convenience.\r\n", garbage); + strncpy(garbage, "GFZFLR09\0\0\0\0\0\0", 8); + } + else if(!memcmp(garbage, "DEM1_4\0\0\0\0\0\0", 8)) + strncpy(garbage, "GFZFLR10\0\0\0\0", 8); + + else if(!memcmp(garbage, "FLOOR3_3\0\0\0\0\0", 8)) + strncpy(garbage, "THZFLR30\0\0\0\0\0\0\0", 8); + else if(!memcmp(garbage, "FLOOR4_5\0\0\0\0\0", 8)) + strncpy(garbage, "THZFLR31\0\0\0\0\0\0\0", 8); + else if(!memcmp(garbage, "OTHZW1\0\0\0\0\0", 8)) + strncpy(garbage, "THZFLR32\0\0\0\0\0\0\0", 8); + else if(!memcmp(garbage, "OTHZW2\0\0\0\0\0", 8)) + strncpy(garbage, "THZFLR33\0\0\0\0\0\0\0", 8); + + else if(!memcmp(garbage, "BLOOD1\0\0", 8)) + strncpy(garbage, "LITER1\0\0", 8); + else if(!memcmp(garbage, "BLOOD2\0\0", 8)) + strncpy(garbage, "LITER2\0\0", 8); + else if(!memcmp(garbage, "BLOOD3\0\0", 8)) + strncpy(garbage, "LITER3\0\0", 8); + + else if(!memcmp(garbage, "BLUE1\0\0\0", 8)) + strncpy(garbage, "LITEB1\0\0", 8); + else if(!memcmp(garbage, "BLUE2\0\0\0", 8)) + strncpy(garbage, "LITEB2\0\0", 8); + else if(!memcmp(garbage, "BLUE3\0\0\0", 8)) + strncpy(garbage, "LITEB3\0\0", 8); + + else if(!memcmp(garbage, "GREY1\0\0\0", 8)) + strncpy(garbage, "LITEN1\0\0", 8); + else if(!memcmp(garbage, "GREY2\0\0\0", 8)) + strncpy(garbage, "LITEN2\0\0", 8); + else if(!memcmp(garbage, "GREY3\0\0\0", 8)) + strncpy(garbage, "LITEN3\0\0", 8); + + else if(!memcmp(garbage, "NUKAGE1\0\0\0", 8)) + strncpy(garbage, "LITEY1\0\0", 8); + else if(!memcmp(garbage, "NUKAGE2\0\0\0", 8)) + strncpy(garbage, "LITEY2\0\0", 8); + else if(!memcmp(garbage, "NUKAGE3\0\0\0", 8)) + strncpy(garbage, "LITEY3\0\0", 8); + + else if(!memcmp(garbage, "CEIL1_3\0\0\0\0\0", 8)) + strncpy(garbage, "CEZFLR09\0\0\0\0\0\0\0", 8); + else if(!memcmp(garbage, "CEIL1_1\0\0\0\0\0", 8)) + strncpy(garbage, "CEZFLR10\0\0\0\0\0\0\0", 8); + else if(!memcmp(garbage, "CEIL1_2\0\0\0\0\0", 8)) + strncpy(garbage, "CEZFLR11\0\0\0\0\0\0\0", 8); + + else if(!memcmp(garbage, "CONS1_1\0\0\0\0\0", 8)) + strncpy(garbage, "SFLR07\0\0\0\0\0\0\0", 8); + else if(!memcmp(garbage, "CONS1_5\0\0\0\0\0", 8)) + strncpy(garbage, "SFLR08\0\0\0\0\0\0\0", 8); + else if(!memcmp(garbage, "CONS1_7\0\0\0\0\0", 8)) + strncpy(garbage, "SFLR09\0\0\0\0\0\0\0", 8); + else if(!memcmp(garbage, "FLOOR0_5\0\0\0\0\0", 8)) + strncpy(garbage, "SFLR10\0\0\0\0\0\0\0", 8); + else if(!memcmp(garbage, "FLOOR0_7\0\0\0\0\0", 8)) + strncpy(garbage, "SFLR11\0\0\0\0\0\0\0", 8); + else if(!memcmp(garbage, "FLOOR1_6\0\0\0\0\0", 8)) + strncpy(garbage, "SFLR12\0\0\0\0\0\0\0", 8); + else if(!memcmp(garbage, "SLIME01\0\0\0\0\0", 8)) + strncpy(garbage, "SFLR13\0\0\0\0\0\0\0", 8); + else if(!memcmp(garbage, "SLIME02\0\0\0\0\0", 8)) + strncpy(garbage, "SFLR14\0\0\0\0\0\0\0", 8); + else if(!memcmp(garbage, "SLIME03\0\0\0\0\0", 8)) + strncpy(garbage, "SFLR15\0\0\0\0\0\0\0", 8); + else if(!memcmp(garbage, "SLIME04\0\0\0\0\0", 8)) + strncpy(garbage, "SFLR12\0\0\0\0\0\0\0", 8); + + else if(!memcmp(garbage, "DCFLR1\0\0\0\0\0", 8)) + strncpy(garbage, "DCZFLR01\0\0\0\0\0\0\0", 8); + else if(!memcmp(garbage, "DCCEIL1\0\0\0\0\0", 8)) + strncpy(garbage, "DCZFLR02\0\0\0\0\0\0\0", 8); + else if(!memcmp(garbage, "DCPAVE\0\0\0\0\0", 8)) + strncpy(garbage, "DCZFLR03\0\0\0\0\0\0\0", 8); + else if(!memcmp(garbage, "DCMANHO\0\0\0\0\0", 8)) + strncpy(garbage, "DCZFLR04\0\0\0\0\0\0\0", 8); + else if(!memcmp(garbage, "DCTEX1\0\0\0\0\0", 8)) + strncpy(garbage, "DCZFLR05\0\0\0\0\0\0\0", 8); + else if(!memcmp(garbage, "DCTEX2\0\0\0\0\0", 8)) + strncpy(garbage, "DCZFLR06\0\0\0\0\0\0\0", 8); + else if(!memcmp(garbage, "DCTEX3\0\0\0\0\0", 8)) + strncpy(garbage, "DCZFLR07\0\0\0\0\0\0\0", 8); + else if(!memcmp(garbage, "DCTEX4\0\0\0\0\0", 8)) + strncpy(garbage, "DCZFLR08\0\0\0\0\0\0\0", 8); + else if(!memcmp(garbage, "DCWHITE\0\0\0\0\0", 8)) + strncpy(garbage, "DCZFLR09\0\0\0\0\0\0\0", 8); + else if(!memcmp(garbage, "DCYELLOW\0\0\0\0\0", 8)) + strncpy(garbage, "DCZFLR10\0\0\0\0\0\0\0", 8); + else if(!memcmp(garbage, "DENTFLR\0\0\0\0\0", 8)) + strncpy(garbage, "DCZFLR11\0\0\0\0\0\0\0", 8); + else if(!memcmp(garbage, "DENTMETL\0\0\0\0\0", 8)) + strncpy(garbage, "DCZFLR12\0\0\0\0\0\0\0", 8); // Intentionally + else if(!memcmp(garbage, "FLAT14\0\0\0\0\0\0", 8)) + strncpy(garbage, "DCZFLR12\0\0\0\0\0", 8); // The same! + else if(!memcmp(garbage, "MFLR8_1\0\0\0\0\0", 8)) + strncpy(garbage, "DCZFLR13\0\0\0\0\0\0", 8); + else if(!memcmp(garbage, "STEP2\0\0\0\0\0", 8)) + strncpy(garbage, "DCZFLR14\0\0\0\0\0", 8); + + + else if(!memcmp(garbage, "DEEPSEA2\0\0\0\0\0", 8)) + strncpy(garbage, "DSZFLR04\0\0\0\0\0\0\0", 8); + else if(!memcmp(garbage, "DEEPSEA3\0\0\0\0\0", 8)) + strncpy(garbage, "DSZFLR05\0\0\0\0\0\0\0", 8); + else if(!memcmp(garbage, "DEEPSEA4\0\0\0\0\0", 8)) + strncpy(garbage, "DSZFLR06\0\0\0\0\0\0\0", 8); + else if(!memcmp(garbage, "FLOOR4_6\0\0\0\0\0", 8)) + strncpy(garbage, "DSZFLR07\0\0\0\0\0\0\0", 8); + else if(!memcmp(garbage, "SLIME14\0\0\0\0\0", 8)) + strncpy(garbage, "DSZFLR08\0\0\0\0\0\0\0", 8); + else if(!memcmp(garbage, "SLIME15\0\0\0\0\0", 8)) + strncpy(garbage, "DSZFLR09\0\0\0\0\0\0\0", 8); + else if(!memcmp(garbage, "SLIME16\0\0\0\0\0", 8)) + strncpy(garbage, "DSZFLR10\0\0\0\0\0\0\0", 8); + + else if(!memcmp(garbage, "ERROCK\0\0\0\0\0\0", 8)) + strncpy(garbage, "ERZFLR01\0\0\0\0\0", 8); + else if(!memcmp(garbage, "FLAT18\0\0\0\0\0\0", 8)) + strncpy(garbage, "ERZFLR02\0\0\0\0\0", 8); + else if(!memcmp(garbage, "FLAT20\0\0\0\0\0\0", 8)) + strncpy(garbage, "ERZFLR03\0\0\0\0\0", 8); + else if(!memcmp(garbage, "FLAT22\0\0\0\0\0\0", 8)) + strncpy(garbage, "ERZFLR04\0\0\0\0\0", 8); + else if(!memcmp(garbage, "FLAT23\0\0\0\0\0\0", 8)) + strncpy(garbage, "ERZFLR05\0\0\0\0\0", 8); + else if(!memcmp(garbage, "FLAT5_4\0\0\0\0", 8)) + strncpy(garbage, "ERZFLR06\0\0\0\0\0", 8); + + else if(!memcmp(garbage, "FLAT10\0\0\0\0\0\0", 8)) + strncpy(garbage, "REDFLR\0\0\0\0\0", 8); + else if(!memcmp(garbage, "FLAT5\0\0\0\0\0\0", 8)) + strncpy(garbage, "ORGFLR\0\0\0\0\0", 8); + + else if(!memcmp(garbage, "MFLR8_2\0\0\0\0\0\0", 8)) + strncpy(garbage, "GREYFLR\0\0\0\0\0", 8); + else if(!memcmp(garbage, "MFLR8_4\0\0\0\0\0\0", 8)) + strncpy(garbage, "GREYFLR\0\0\0\0\0", 8); +} + +static inline int ConvertSectors(char *argv[]) +{ + char syscmd[100]; + InitializeSectorConversionTable(); + + sprintf(syscmd, "lumpmod %s extract -s MAP%s SECTORS lvlconv.tmp", + argv[1], strupr(argv[2])); + system(syscmd); + + lvlconvfile = fopen("lvlconv.tmp", "r+b"); + if(lvlconvfile == NULL) { + puts("Failed to open lvlconv.tmp."); + return EXIT_FAILURE; + } + for(;;) { + int c; + char garbage[11]; + short type; + + c = fgetc(lvlconvfile); + if(c == EOF) break; + + fseek(lvlconvfile, -1, SEEK_CUR); + if(fread(&garbage, sizeof(short)*2, 1, lvlconvfile) < 1) { + puts("I CANNOT READ THE DATA BEFORE SECTOR FLATS"); + return EXIT_FAILURE; + } + + // Read floor flat first. + if(fread(&garbage, 8, 1, lvlconvfile) < 1) { + puts("I CAN'T READ THE SECTOR FLOOR FLAT"); + return EXIT_FAILURE; + } + + fseek(lvlconvfile, -8, SEEK_CUR); + + garbage[8] = 0; + + ConvertFlat(garbage); + + if(fwrite(&garbage, 8, 1, lvlconvfile) < 1) { + puts("I CANNOT WRITE THE FLOOR FLAT"); + return EXIT_FAILURE; + } + + fseek(lvlconvfile, 0, SEEK_CUR); + + memset(garbage, 0, sizeof(garbage)); + + // Now do ceiling flat. + if(fread(&garbage, 8, 1, lvlconvfile) < 1) { + puts("I CAN'T READ THE SECTOR CEILING FLAT"); + return EXIT_FAILURE; + } + + fseek(lvlconvfile, -8, SEEK_CUR); + + garbage[8] = 0; + ConvertFlat(garbage); + + if(fwrite(&garbage, 8, 1, lvlconvfile) < 1) { + puts("I CANNOT WRITE THE CEILING FLAT"); + return EXIT_FAILURE; + } + + // Skip lightlevel + fseek(lvlconvfile, 1 * sizeof(short), SEEK_CUR); + + // Now do sector special. + if(fread(&type, sizeof(short), 1, lvlconvfile) < 1) { + puts("I CAN'T READ THE SECTOR SPECIAL"); + return EXIT_FAILURE; + } + + fseek(lvlconvfile, -1 * (int)sizeof(short), SEEK_CUR); + + /* CHECK FOR MATCH */ + if(conversion[type] < 0) + printf("\nSector type %d no longer supported. You will have to manually change this.", type); + else if(conversion[type] != 0) + type = conversion[type]; + else if (type != 0) + printf("\nUnknown sector type %d!", type); + + if(fwrite(&type, sizeof(short), 1, lvlconvfile) < 1) { + puts("I CANNOT WRITE THE TYPE"); + return EXIT_FAILURE; + } + + /* skip 1 short of TOTAL CRAP */ + fseek(lvlconvfile, 1 * sizeof(short), SEEK_CUR); + } + fclose(lvlconvfile); + puts("DONE, Man!.. Inserting back into WAD.\n"); + sprintf(syscmd, "lumpmod %s update -s MAP%s SECTORS lvlconv.tmp", + argv[1], strupr(argv[2])); + system(syscmd); + remove("lvlconv.tmp"); + return 1; +} + +static inline int ConvertLinedefs(char *argv[]) +{ + char syscmd[100]; + InitializeLinedefConversionTable(); + + sprintf(syscmd, "lumpmod %s extract -s MAP%s LINEDEFS lvlconv.tmp", + argv[1], strupr(argv[2])); + system(syscmd); + + lvlconvfile = fopen("lvlconv.tmp", "r+b"); + if(lvlconvfile == NULL) { + puts("Failed to open lvlconv.tmp."); + return EXIT_FAILURE; + } + for(;;) { + int c; + short garbage[3], type; + + c = fgetc(lvlconvfile); + if(c == EOF) break; + + fseek(lvlconvfile, -1, SEEK_CUR); + if(fread(&garbage, sizeof(short)*3, 1, lvlconvfile) < 1) { + puts("I CANNOT READ THE DATA BEFORE THE LINEDEF SPECIAL"); + return EXIT_FAILURE; + } + if(fread(&type, sizeof(short), 1, lvlconvfile) < 1) { + puts("I CAN'T READ THE LINEDEF TYPE"); + return EXIT_FAILURE; + } + + fseek(lvlconvfile, -1 * (int)sizeof(short), SEEK_CUR); + + /* CHECK FOR MATCH */ + if(conversion[type] < 0) + printf("\nLinedef type %d no longer supported. You will have to manually change this.", type); + else if(conversion[type] != 0) + { + if(type == 65) + printf("\nThis level contains a speed pad linedef. You will have to flip the direction of the line for it to work properly."); + + type = conversion[type]; + } + else if (type != 0) + printf("\nUnknown linedef type %d!", type); + + if(fwrite(&type, sizeof(short), 1, lvlconvfile) < 1) { + puts("I CANNOT WRITE THE TYPE"); + return EXIT_FAILURE; + } + + /* skip 3 shorts of TOTAL CRAP */ + fseek(lvlconvfile, 3 * sizeof(short), SEEK_CUR); + } + fclose(lvlconvfile); + puts("DONE, Man!.. Inserting back into WAD.\n"); + sprintf(syscmd, "lumpmod %s update -s MAP%s LINEDEFS lvlconv.tmp", + argv[1], strupr(argv[2])); + system(syscmd); + remove("lvlconv.tmp"); + return 1; +} + +int main(int argc, char *argv[]) { + if(argc != 3) { + puts("Usage: lvlconv [filename] [mapnumber]"); + puts("Example: lvlconv wadfile.wad 01"); + return EXIT_FAILURE; /* YOU FAIL IT! */ + } + + if(strlen(argv[2]) != 2 || strlen(argv[1]) > 32) { + puts("nonono you screwed it up"); + return EXIT_FAILURE; /* YOU LIKEWISE FAIL IT! */ + } +#ifdef STARPOSTS_ONLY + ConvertStarposts(argv); +#else + puts("\nConverting Things..."); + ConvertThings(argv); + puts("\nConverting Sectors..."); + ConvertSectors(argv); + puts("\nConverting Linedefs..."); + ConvertLinedefs(argv); +#endif + + puts("\nOkay, DONE!! Enjoy the NEWLY MODIFIED WAD FILE!!! HAVE A GOOD DAY!"); + return EXIT_SUCCESS; /* YOU SUCCEED AT IT! :) */ +} diff --git a/tools/LevelConverter/levelconverter.dsp b/tools/LevelConverter/levelconverter.dsp new file mode 100644 index 000000000..655cc3799 --- /dev/null +++ b/tools/LevelConverter/levelconverter.dsp @@ -0,0 +1,88 @@ +# Microsoft Developer Studio Project File - Name="levelconverter" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=levelconverter - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "levelconverter.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "levelconverter.mak" CFG="levelconverter - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "levelconverter - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "levelconverter - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "levelconverter - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 + +!ELSEIF "$(CFG)" == "levelconverter - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c +# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept + +!ENDIF + +# Begin Target + +# Name "levelconverter - Win32 Release" +# Name "levelconverter - Win32 Debug" +# Begin Source File + +SOURCE=.\levelconverter.c +# End Source File +# End Target +# End Project diff --git a/tools/LevelConverter/levelconverter.dsw b/tools/LevelConverter/levelconverter.dsw new file mode 100644 index 000000000..51a840c28 --- /dev/null +++ b/tools/LevelConverter/levelconverter.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00 +# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! + +############################################################################### + +Project: "levelconverter"=.\levelconverter.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/tools/MSDfile b/tools/MSDfile new file mode 100644 index 000000000..287c31354 --- /dev/null +++ b/tools/MSDfile @@ -0,0 +1,235 @@ +# Doxyfile 1.4.3 + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- +PROJECT_NAME = "SRB2 MasterServer" +PROJECT_NUMBER = +OUTPUT_DIRECTORY = ../doc/MasterServer +CREATE_SUBDIRS = YES +OUTPUT_LANGUAGE = English +USE_WINDOWS_ENCODING = YES +BRIEF_MEMBER_DESC = YES +REPEAT_BRIEF = YES +ABBREVIATE_BRIEF = "The $name class" \ + "The $name widget" \ + "The $name file" \ + is \ + provides \ + specifies \ + contains \ + represents \ + a \ + an \ + the +ALWAYS_DETAILED_SEC = NO +INLINE_INHERITED_MEMB = NO +FULL_PATH_NAMES = YES +STRIP_FROM_PATH = +STRIP_FROM_INC_PATH = +SHORT_NAMES = NO +JAVADOC_AUTOBRIEF = NO +MULTILINE_CPP_IS_BRIEF = NO +DETAILS_AT_TOP = NO +INHERIT_DOCS = YES +DISTRIBUTE_GROUP_DOC = NO +SEPARATE_MEMBER_PAGES = NO +TAB_SIZE = 8 +ALIASES = +OPTIMIZE_OUTPUT_FOR_C = NO +OPTIMIZE_OUTPUT_JAVA = NO +SUBGROUPING = YES +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- +EXTRACT_ALL = YES +EXTRACT_PRIVATE = YES +EXTRACT_STATIC = YES +EXTRACT_LOCAL_CLASSES = YES +EXTRACT_LOCAL_METHODS = NO +HIDE_UNDOC_MEMBERS = NO +HIDE_UNDOC_CLASSES = NO +HIDE_FRIEND_COMPOUNDS = NO +HIDE_IN_BODY_DOCS = NO +INTERNAL_DOCS = NO +CASE_SENSE_NAMES = NO +HIDE_SCOPE_NAMES = NO +SHOW_INCLUDE_FILES = YES +INLINE_INFO = YES +SORT_MEMBER_DOCS = YES +SORT_BRIEF_DOCS = NO +SORT_BY_SCOPE_NAME = NO +GENERATE_TODOLIST = YES +GENERATE_TESTLIST = YES +GENERATE_BUGLIST = YES +GENERATE_DEPRECATEDLIST= YES +ENABLED_SECTIONS = +MAX_INITIALIZER_LINES = 30 +SHOW_USED_FILES = YES +SHOW_DIRECTORIES = YES +FILE_VERSION_FILTER = +#--------------------------------------------------------------------------- +# configuration options related to warning and progress messages +#--------------------------------------------------------------------------- +QUIET = NO +WARNINGS = YES +WARN_IF_UNDOCUMENTED = YES +WARN_IF_DOC_ERROR = YES +WARN_NO_PARAMDOC = NO +WARN_FORMAT = "$file:$line: $text" +WARN_LOGFILE = +#--------------------------------------------------------------------------- +# configuration options related to the input files +#--------------------------------------------------------------------------- +INPUT = ./masterserver +FILE_PATTERNS = *.cpp \ + *.h +RECURSIVE = NO +EXCLUDE = +EXCLUDE_SYMLINKS = NO +EXCLUDE_PATTERNS = +EXAMPLE_PATH = +EXAMPLE_PATTERNS = * +EXAMPLE_RECURSIVE = NO +IMAGE_PATH = +INPUT_FILTER = +FILTER_PATTERNS = +FILTER_SOURCE_FILES = YES +#--------------------------------------------------------------------------- +# configuration options related to source browsing +#--------------------------------------------------------------------------- +SOURCE_BROWSER = YES +INLINE_SOURCES = YES +STRIP_CODE_COMMENTS = YES +REFERENCED_BY_RELATION = NO +REFERENCES_RELATION = NO +USE_HTAGS = NO +VERBATIM_HEADERS = YES +#--------------------------------------------------------------------------- +# configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- +ALPHABETICAL_INDEX = NO +COLS_IN_ALPHA_INDEX = 5 +IGNORE_PREFIX = +#--------------------------------------------------------------------------- +# configuration options related to the HTML output +#--------------------------------------------------------------------------- +GENERATE_HTML = YES +HTML_OUTPUT = html +HTML_FILE_EXTENSION = .html +HTML_HEADER = +HTML_FOOTER = +HTML_STYLESHEET = +HTML_ALIGN_MEMBERS = YES +GENERATE_HTMLHELP = NO +CHM_FILE = +HHC_LOCATION = +GENERATE_CHI = NO +BINARY_TOC = NO +TOC_EXPAND = NO +DISABLE_INDEX = NO +ENUM_VALUES_PER_LINE = 4 +GENERATE_TREEVIEW = YES +TREEVIEW_WIDTH = 250 +#--------------------------------------------------------------------------- +# configuration options related to the LaTeX output +#--------------------------------------------------------------------------- +GENERATE_LATEX = NO +LATEX_OUTPUT = latex +LATEX_CMD_NAME = latex +MAKEINDEX_CMD_NAME = makeindex +COMPACT_LATEX = NO +PAPER_TYPE = a4wide +EXTRA_PACKAGES = +LATEX_HEADER = +PDF_HYPERLINKS = NO +USE_PDFLATEX = NO +LATEX_BATCHMODE = NO +LATEX_HIDE_INDICES = NO +#--------------------------------------------------------------------------- +# configuration options related to the RTF output +#--------------------------------------------------------------------------- +GENERATE_RTF = NO +RTF_OUTPUT = rtf +COMPACT_RTF = NO +RTF_HYPERLINKS = NO +RTF_STYLESHEET_FILE = +RTF_EXTENSIONS_FILE = +#--------------------------------------------------------------------------- +# configuration options related to the man page output +#--------------------------------------------------------------------------- +GENERATE_MAN = NO +MAN_OUTPUT = man +MAN_EXTENSION = .3 +MAN_LINKS = YES +#--------------------------------------------------------------------------- +# configuration options related to the XML output +#--------------------------------------------------------------------------- +GENERATE_XML = NO +XML_OUTPUT = xml +XML_SCHEMA = +XML_DTD = +XML_PROGRAMLISTING = YES +#--------------------------------------------------------------------------- +# configuration options for the AutoGen Definitions output +#--------------------------------------------------------------------------- +GENERATE_AUTOGEN_DEF = NO +#--------------------------------------------------------------------------- +# configuration options related to the Perl module output +#--------------------------------------------------------------------------- +GENERATE_PERLMOD = NO +PERLMOD_LATEX = NO +PERLMOD_PRETTY = YES +PERLMOD_MAKEVAR_PREFIX = +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- +ENABLE_PREPROCESSING = YES +MACRO_EXPANSION = NO +EXPAND_ONLY_PREDEF = NO +SEARCH_INCLUDES = YES +INCLUDE_PATH = C:/Dev/include +INCLUDE_FILE_PATTERNS = +PREDEFINED = HWRENDER \ + DIRECTFULLSCREEN \ + HW3SOUND +EXPAND_AS_DEFINED = +SKIP_FUNCTION_MACROS = YES +#--------------------------------------------------------------------------- +# Configuration::additions related to external references +#--------------------------------------------------------------------------- +TAGFILES = +GENERATE_TAGFILE = +ALLEXTERNALS = NO +EXTERNAL_GROUPS = YES +PERL_PATH = /usr/bin/perl +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- +CLASS_DIAGRAMS = YES +HIDE_UNDOC_RELATIONS = YES +HAVE_DOT = NO +CLASS_GRAPH = YES +COLLABORATION_GRAPH = YES +GROUP_GRAPHS = YES +UML_LOOK = NO +TEMPLATE_RELATIONS = NO +INCLUDE_GRAPH = YES +INCLUDED_BY_GRAPH = YES +CALL_GRAPH = NO +GRAPHICAL_HIERARCHY = YES +DIRECTORY_GRAPH = YES +DOT_IMAGE_FORMAT = png +DOT_PATH = +DOTFILE_DIRS = +MAX_DOT_GRAPH_WIDTH = 1024 +MAX_DOT_GRAPH_HEIGHT = 1024 +MAX_DOT_GRAPH_DEPTH = 1000 +DOT_TRANSPARENT = NO +DOT_MULTI_TARGETS = NO +GENERATE_LEGEND = YES +DOT_CLEANUP = YES +#--------------------------------------------------------------------------- +# Configuration::additions related to the search engine +#--------------------------------------------------------------------------- +SEARCHENGINE = NO diff --git a/tools/PHP/RSS1.0.php b/tools/PHP/RSS1.0.php new file mode 100644 index 000000000..30eb32585 --- /dev/null +++ b/tools/PHP/RSS1.0.php @@ -0,0 +1,55 @@ +'; +echo "\n"; +echo ''; +echo "\n"; +echo "\n"; +echo ' '; +echo "\n"; +echo ' SRB2 Master Server RSS Feed'; +echo "\n"; +echo ' http://srb2.servegame.org/'; +echo "\n"; +echo ' Playing around with RSS'; +echo "\n"; +//echo ' en-us'; +//echo "\n"; + $fd = fsockopen("srb2.servegame.org", 28900, $errno, $errstr, 5); +// $fd = 0; + if ($fd) + { + $buff = "000012400000"; + fwrite($fd, $buff); + while (1) + { + $content=fgets($fd, 13); // skip 13 first bytes + $content=fgets($fd, 1024); + echo "$content"; + if (feof($fd)) break; + } + fclose($fd); + } + else + { + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo "\n"; + echo ' '; + echo 'No master serverThe master server is not running'; + } +?> + \ No newline at end of file diff --git a/tools/PHP/RSS92.php b/tools/PHP/RSS92.php new file mode 100644 index 000000000..4dd194089 --- /dev/null +++ b/tools/PHP/RSS92.php @@ -0,0 +1,37 @@ +'; +echo "\n"; +echo ''; +echo "\n"; +echo ' '; +echo "\n"; +echo ' SRB2 Master Server RSS Feed'; +echo "\n"; +echo ' Playing around with RSS'; +echo "\n"; +echo ' http://srb2.servegame.org/'; +echo "\n"; +echo ' en-us'; +echo "\n"; + $fd = fsockopen("srb2.servegame.org", 28900, $errno, $errstr, 5); + if ($fd) + { + $buff = "000012380000"; + fwrite($fd, $buff); + while (1) + { + $content=fgets($fd, 13); // skip the next 13 bytes + $content=fgets($fd, 1024); + echo "$content"; + if (feof($fd)) break; + } + fclose($fd); + } + else + { + echo "No master serverThe master server is not running"; + } +?> + + \ No newline at end of file diff --git a/tools/PHP/index.php b/tools/PHP/index.php new file mode 100644 index 000000000..93bb7c92b --- /dev/null +++ b/tools/PHP/index.php @@ -0,0 +1,90 @@ + + + + +SRB2 Master Server Status + + +
+ + + + + + + + + +
+
+ SRB2 logo. +
+ SRB2's HomePage
+
+
+
+ Chompy World logo. +
+ Chompy World
+
+
+
+ SRB2 World logo. +
+ SRB2 World
+
+
+ +
+
+
+ +SRB2 Master Server Status\nCurrent host: $host_addr
"; + $buff = "000043210000"; + fwrite($fd, $buff); + while (1) + { + $content=fgets($fd, 13); // skip 13 first bytes + $content=fgets($fd, 1024); + echo "$content"; + if (feof($fd)) break; + } + fclose($fd); + + } + else + { + echo 'The master server is not running
'; + echo "ERROR: $errno - $errstr
\n"; + } +?> +
+

Info:

+
Win32 SRB2MSLauncher Great job, "Gregor Dick"/Oogaland of Gregorsoft Software +
+

+

Version Info:

+srb2dos.exe (DOS/Allegro/WATTCP32 version)
+srb2.exe (Windows/DirectX/FMOD version)
+srb2sdl.exe (Windows/SDL/SDL_mixer version)
+lsdlsrb2 (GNU/Linux/SDL/SDL_mixer version)
+
+Srb2win.exe v1.09.4 (use Internet search menu)
+ + + diff --git a/tools/PHP/text.php b/tools/PHP/text.php new file mode 100644 index 000000000..282b812b7 --- /dev/null +++ b/tools/PHP/text.php @@ -0,0 +1,24 @@ + diff --git a/tools/PHPD b/tools/PHPD new file mode 100644 index 000000000..d2877f4e3 --- /dev/null +++ b/tools/PHPD @@ -0,0 +1,239 @@ +# Doxyfile 1.4.3 + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- +PROJECT_NAME = "SRB2 MasterServer IRC Bot and PHP stuff" +PROJECT_NUMBER = +OUTPUT_DIRECTORY = ../doc/IRC_Bot +CREATE_SUBDIRS = YES +OUTPUT_LANGUAGE = English +USE_WINDOWS_ENCODING = YES +BRIEF_MEMBER_DESC = YES +REPEAT_BRIEF = YES +ABBREVIATE_BRIEF = "The $name class" \ + "The $name widget" \ + "The $name file" \ + is \ + provides \ + specifies \ + contains \ + represents \ + a \ + an \ + the +ALWAYS_DETAILED_SEC = NO +INLINE_INHERITED_MEMB = NO +FULL_PATH_NAMES = YES +STRIP_FROM_PATH = +STRIP_FROM_INC_PATH = +SHORT_NAMES = NO +JAVADOC_AUTOBRIEF = NO +MULTILINE_CPP_IS_BRIEF = NO +DETAILS_AT_TOP = NO +INHERIT_DOCS = YES +DISTRIBUTE_GROUP_DOC = NO +SEPARATE_MEMBER_PAGES = NO +TAB_SIZE = 8 +ALIASES = +OPTIMIZE_OUTPUT_FOR_C = NO +OPTIMIZE_OUTPUT_JAVA = NO +SUBGROUPING = YES +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- +EXTRACT_ALL = YES +EXTRACT_PRIVATE = YES +EXTRACT_STATIC = YES +EXTRACT_LOCAL_CLASSES = YES +EXTRACT_LOCAL_METHODS = NO +HIDE_UNDOC_MEMBERS = NO +HIDE_UNDOC_CLASSES = NO +HIDE_FRIEND_COMPOUNDS = NO +HIDE_IN_BODY_DOCS = NO +INTERNAL_DOCS = NO +CASE_SENSE_NAMES = NO +HIDE_SCOPE_NAMES = NO +SHOW_INCLUDE_FILES = YES +INLINE_INFO = YES +SORT_MEMBER_DOCS = YES +SORT_BRIEF_DOCS = NO +SORT_BY_SCOPE_NAME = NO +GENERATE_TODOLIST = YES +GENERATE_TESTLIST = YES +GENERATE_BUGLIST = YES +GENERATE_DEPRECATEDLIST= YES +ENABLED_SECTIONS = +MAX_INITIALIZER_LINES = 30 +SHOW_USED_FILES = YES +SHOW_DIRECTORIES = YES +FILE_VERSION_FILTER = +#--------------------------------------------------------------------------- +# configuration options related to warning and progress messages +#--------------------------------------------------------------------------- +QUIET = NO +WARNINGS = YES +WARN_IF_UNDOCUMENTED = YES +WARN_IF_DOC_ERROR = YES +WARN_NO_PARAMDOC = NO +WARN_FORMAT = "$file:$line: $text" +WARN_LOGFILE = +#--------------------------------------------------------------------------- +# configuration options related to the input files +#--------------------------------------------------------------------------- +INPUT = ./ +FILE_PATTERNS = *.php \ + *.php3 \ + *.inc \ + *.dox +RECURSIVE = YES +EXCLUDE = ./IRC_Bot/SmartIRC.php +EXCLUDE_SYMLINKS = NO +EXCLUDE_PATTERNS = */IRC_Bot/magpierss/* \ + */IRC_Bot/SmartIRC/* \ + */IRC_Bot/*SRB2MS_Pass.php +EXAMPLE_PATH = +EXAMPLE_PATTERNS = * +EXAMPLE_RECURSIVE = NO +IMAGE_PATH = +INPUT_FILTER = +FILTER_PATTERNS = +FILTER_SOURCE_FILES = YES +#--------------------------------------------------------------------------- +# configuration options related to source browsing +#--------------------------------------------------------------------------- +SOURCE_BROWSER = YES +INLINE_SOURCES = YES +STRIP_CODE_COMMENTS = YES +REFERENCED_BY_RELATION = NO +REFERENCES_RELATION = NO +USE_HTAGS = NO +VERBATIM_HEADERS = YES +#--------------------------------------------------------------------------- +# configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- +ALPHABETICAL_INDEX = NO +COLS_IN_ALPHA_INDEX = 5 +IGNORE_PREFIX = +#--------------------------------------------------------------------------- +# configuration options related to the HTML output +#--------------------------------------------------------------------------- +GENERATE_HTML = YES +HTML_OUTPUT = html +HTML_FILE_EXTENSION = .html +HTML_HEADER = +HTML_FOOTER = +HTML_STYLESHEET = +HTML_ALIGN_MEMBERS = YES +GENERATE_HTMLHELP = NO +CHM_FILE = +HHC_LOCATION = +GENERATE_CHI = NO +BINARY_TOC = NO +TOC_EXPAND = NO +DISABLE_INDEX = NO +ENUM_VALUES_PER_LINE = 4 +GENERATE_TREEVIEW = YES +TREEVIEW_WIDTH = 250 +#--------------------------------------------------------------------------- +# configuration options related to the LaTeX output +#--------------------------------------------------------------------------- +GENERATE_LATEX = NO +LATEX_OUTPUT = latex +LATEX_CMD_NAME = latex +MAKEINDEX_CMD_NAME = makeindex +COMPACT_LATEX = NO +PAPER_TYPE = a4wide +EXTRA_PACKAGES = +LATEX_HEADER = +PDF_HYPERLINKS = NO +USE_PDFLATEX = NO +LATEX_BATCHMODE = NO +LATEX_HIDE_INDICES = NO +#--------------------------------------------------------------------------- +# configuration options related to the RTF output +#--------------------------------------------------------------------------- +GENERATE_RTF = NO +RTF_OUTPUT = rtf +COMPACT_RTF = NO +RTF_HYPERLINKS = NO +RTF_STYLESHEET_FILE = +RTF_EXTENSIONS_FILE = +#--------------------------------------------------------------------------- +# configuration options related to the man page output +#--------------------------------------------------------------------------- +GENERATE_MAN = NO +MAN_OUTPUT = man +MAN_EXTENSION = .3 +MAN_LINKS = YES +#--------------------------------------------------------------------------- +# configuration options related to the XML output +#--------------------------------------------------------------------------- +GENERATE_XML = NO +XML_OUTPUT = xml +XML_SCHEMA = +XML_DTD = +XML_PROGRAMLISTING = YES +#--------------------------------------------------------------------------- +# configuration options for the AutoGen Definitions output +#--------------------------------------------------------------------------- +GENERATE_AUTOGEN_DEF = NO +#--------------------------------------------------------------------------- +# configuration options related to the Perl module output +#--------------------------------------------------------------------------- +GENERATE_PERLMOD = NO +PERLMOD_LATEX = NO +PERLMOD_PRETTY = YES +PERLMOD_MAKEVAR_PREFIX = +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- +ENABLE_PREPROCESSING = YES +MACRO_EXPANSION = NO +EXPAND_ONLY_PREDEF = NO +SEARCH_INCLUDES = YES +INCLUDE_PATH = C:/Dev/include +INCLUDE_FILE_PATTERNS = +PREDEFINED = HWRENDER \ + DIRECTFULLSCREEN \ + HW3SOUND +EXPAND_AS_DEFINED = +SKIP_FUNCTION_MACROS = YES +#--------------------------------------------------------------------------- +# Configuration::additions related to external references +#--------------------------------------------------------------------------- +TAGFILES = +GENERATE_TAGFILE = +ALLEXTERNALS = NO +EXTERNAL_GROUPS = YES +PERL_PATH = /usr/bin/perl +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- +CLASS_DIAGRAMS = YES +HIDE_UNDOC_RELATIONS = YES +HAVE_DOT = NO +CLASS_GRAPH = YES +COLLABORATION_GRAPH = YES +GROUP_GRAPHS = YES +UML_LOOK = NO +TEMPLATE_RELATIONS = NO +INCLUDE_GRAPH = YES +INCLUDED_BY_GRAPH = YES +CALL_GRAPH = NO +GRAPHICAL_HIERARCHY = YES +DIRECTORY_GRAPH = YES +DOT_IMAGE_FORMAT = png +DOT_PATH = +DOTFILE_DIRS = +MAX_DOT_GRAPH_WIDTH = 1024 +MAX_DOT_GRAPH_HEIGHT = 1024 +MAX_DOT_GRAPH_DEPTH = 1000 +DOT_TRANSPARENT = NO +DOT_MULTI_TARGETS = NO +GENERATE_LEGEND = YES +DOT_CLEANUP = YES +#--------------------------------------------------------------------------- +# Configuration::additions related to the search engine +#--------------------------------------------------------------------------- +SEARCHENGINE = NO diff --git a/tools/SDL-1.2.14-gc/README b/tools/SDL-1.2.14-gc/README new file mode 100644 index 000000000..8ce488fa9 --- /dev/null +++ b/tools/SDL-1.2.14-gc/README @@ -0,0 +1 @@ +Once patched, run autogen.sh, configure with "./configure --without-x --disable-video-x11 --disable-video-fbcon --disable-video-aalib --disable-video-directfb --disable-video-opengl --enable-video-gc" and then compile. diff --git a/tools/SDL-1.2.14-gc/SDL-1.2.14-gc.patch b/tools/SDL-1.2.14-gc/SDL-1.2.14-gc.patch new file mode 100644 index 000000000..5b2b2cfa0 --- /dev/null +++ b/tools/SDL-1.2.14-gc/SDL-1.2.14-gc.patch @@ -0,0 +1,641 @@ +From 8e6ada7bc33e3cc4e1c17821ea171bf0815a505d Mon Sep 17 00:00:00 2001 +From: Alam Arias +Date: Tue, 1 Dec 2009 19:31:57 -0500 +Subject: [PATCH] SDL GC hack + +--- + configure.in | 17 ++ + include/SDL_config.h.in | 1 + + src/video/fbcon/SDL_fbgc.c | 471 +++++++++++++++++++++++++++++++++++++++++ + src/video/fbcon/SDL_fbgc.h | 35 +++ + src/video/fbcon/SDL_fbvideo.c | 10 + + src/video/fbcon/SDL_fbvideo.h | 11 + + 6 files changed, 545 insertions(+), 0 deletions(-) + create mode 100644 src/video/fbcon/SDL_fbgc.c + create mode 100644 src/video/fbcon/SDL_fbgc.h + +diff --git a/configure.in b/configure.in +index a7e9b18..a8961ba 100644 +--- a/configure.in ++++ b/configure.in +@@ -1227,6 +1227,22 @@ AC_HELP_STRING([--enable-video-fbcon], [use framebuffer console video driver [[d + fi + } + ++dnl See if we're running on Linux for the Nintendo GameCube/Wii ++dnl FIXME, perform a real test here... ++CheckGC() ++{ ++ AC_ARG_ENABLE(video-gc, ++AC_HELP_STRING([--enable-video-gc], [enable GameCube video support in FB [[default=no]]]), ++ , enable_video_gc=no) ++ if test x$enable_video = xyes -a x$enable_video_gc = xyes -a x$video_fbcon = xyes; then ++ video_gc=yes ++ AC_MSG_RESULT($video_gc) ++ if test x$video_gc = xyes; then ++ AC_DEFINE(SDL_VIDEO_DRIVER_GC) ++ fi ++ fi ++} ++ + dnl Find DirectFB + CheckDirectFB() + { +@@ -2322,6 +2338,7 @@ case "$host" in + CheckX11 + CheckNANOX + CheckFBCON ++ CheckGC + CheckDirectFB + CheckPS2GS + CheckPS3 +diff --git a/include/SDL_config.h.in b/include/SDL_config.h.in +index 58593ca..e523e9b 100644 +--- a/include/SDL_config.h.in ++++ b/include/SDL_config.h.in +@@ -262,6 +262,7 @@ + #undef SDL_VIDEO_DRIVER_DUMMY + #undef SDL_VIDEO_DRIVER_FBCON + #undef SDL_VIDEO_DRIVER_GAPI ++#undef SDL_VIDEO_DRIVER_GC + #undef SDL_VIDEO_DRIVER_GEM + #undef SDL_VIDEO_DRIVER_GGI + #undef SDL_VIDEO_DRIVER_IPOD +diff --git a/src/video/fbcon/SDL_fbgc.c b/src/video/fbcon/SDL_fbgc.c +new file mode 100644 +index 0000000..b3b72bb +--- /dev/null ++++ b/src/video/fbcon/SDL_fbgc.c +@@ -0,0 +1,471 @@ ++/* ++ SDL - Simple DirectMedia Layer ++ Copyright (C) 1997-2009 Sam Lantinga ++ ++ 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 St, Fifth Floor, Boston, MA 02110-1301 USA ++ ++ Sam Lantinga ++ slouken@libsdl.org ++*/ ++#include "SDL_config.h" ++ ++#ifdef SDL_VIDEO_DRIVER_GC ++#include ++#include "SDL_video.h" ++#include "../SDL_blit.h" ++#include "SDL_fbgc.h" ++ ++static Uint32 r_Yr[256]; ++static Uint32 g_Yg_[256]; ++static Uint32 b_Yb[256]; ++static Uint32 r_Ur[256]; ++static Uint32 g_Ug_[256]; ++static Uint32 b_Ub[256]; ++/* static Uint32 r_Vr[256]; // space and cache optimisation */ ++#define r_Vr b_Ub ++static Uint32 g_Vg_[256]; ++static Uint32 b_Vb[256]; ++ ++static Uint8 RGB16toY[1 << 16]; ++static Uint8 RGB16toU[1 << 16]; ++static Uint8 RGB16toV[1 << 16]; ++ ++#ifndef FBIOFLIPHACK ++#define FBIOFLIPHACK 0x4623 /* gc-linux */ ++#endif ++ ++#ifndef GC_BLACK ++#define GC_BLACK 0x00800080 ++#endif ++ ++#ifdef GC_DEBUG ++# define GC_DPRINTF(fmt, args...) \ ++ fprintf(stderr,"DDD|%s: " fmt, __FUNCTION__ , ## args) ++#else ++# define GC_DPRINTF(fmt, args...) ++#endif ++ ++SDL_bool GC_Test(_THIS) ++{ ++ int fliptest; ++ if (ioctl(console_fd, FBIOFLIPHACK, &fliptest)) ++ return SDL_TRUE; ++ return SDL_FALSE; ++} ++ ++SDL_bool GC_Available(void) ++{ ++ if (access("/sys/bus/of_platform/drivers/gcn-vifb", 0) == 0) ++ return SDL_TRUE; ++ ++ return SDL_FALSE; ++} ++ ++/* ++ * ++ * Color space handling. ++ */ ++ ++#define RGB2YUV_SHIFT 16 ++#define RGB2YUV_LUMA 16 ++#define RGB2YUV_CHROMA 128 ++ ++#define Yr ((int)( 0.299*(1< y) ? y : z)) ++ ++static void GC_InitRGB2YUVTables(void) ++{ ++ unsigned int i; ++ unsigned int r, g, b; ++ ++ for (i = 0; i < 256; i++) { ++ r_Yr[i] = Yr * i; ++ g_Yg_[i] = Yg * i + (RGB2YUV_LUMA << RGB2YUV_SHIFT); ++ b_Yb[i] = Yb * i; ++ r_Ur[i] = Ur * i; ++ g_Ug_[i] = Ug * i + (RGB2YUV_CHROMA << RGB2YUV_SHIFT); ++ b_Ub[i] = Ub * i; ++ r_Vr[i] = Vr * i; ++ g_Vg_[i] = Vg * i + (RGB2YUV_CHROMA << RGB2YUV_SHIFT); ++ b_Vb[i] = Vb * i; ++ } ++ ++ for (i = 0; i < 1 << 16; i++) { ++ /* RGB565 */ ++ r = ((i >> 8) & 0xf8); ++ g = ((i >> 3) & 0xfc); ++ b = ((i << 3) & 0xf8); ++ /* extend to 8bit */ ++ r |= (r >> 5); ++ g |= (g >> 6); ++ b |= (b >> 5); ++ ++ RGB16toY[i] = ++ clamp(16, 235, ++ (r_Yr[r] + g_Yg_[g] + b_Yb[b]) >> RGB2YUV_SHIFT); ++ RGB16toU[i] = ++ clamp(16, 240, ++ (r_Ur[r] + g_Ug_[g] + b_Ub[b]) >> RGB2YUV_SHIFT); ++ RGB16toV[i] = ++ clamp(16, 240, ++ (r_Vr[r] + g_Vg_[g] + b_Vb[b]) >> RGB2YUV_SHIFT); ++ } ++} ++ ++static inline Uint32 rgbrgb16toyuy2(Uint16 rgb1, Uint16 rgb2) ++{ ++ register int Y1, Cb, Y2, Cr; ++ Uint16 rgb; ++ ++ /* fast path, thanks to bohdy */ ++ if (!(rgb1 | rgb2)) { ++ return GC_BLACK; /* black, black */ ++ } ++ ++ if (rgb1 == rgb2) { ++ /* fast path, thanks to isobel */ ++ Y1 = Y2 = RGB16toY[rgb1]; ++ Cb = RGB16toU[rgb1]; ++ Cr = RGB16toV[rgb1]; ++ } else { ++ Y1 = RGB16toY[rgb1]; ++ Y2 = RGB16toY[rgb2]; ++ ++ /* RGB565 average */ ++ rgb = ((rgb1 >> 1) & 0xFBEF) + ((rgb2 >> 1) & 0xFBEF) + ++ ((rgb1 & rgb2) & 0x0821); ++ ++ Cb = RGB16toU[rgb]; ++ Cr = RGB16toV[rgb]; ++ } ++ ++ return (((char)Y1) << 24) | (((char)Cb) << 16) | (((char)Y2) << 8) ++ | (((char)Cr) << 0); ++} ++ ++/* ++ * ++ * Blitters. ++ */ ++static void GC_UpdateRectRGB16(_THIS, SDL_Rect * rect, int pitch) ++{ ++ int width, height, left, i, mod, mod32; ++ Uint8 *src, *dst; ++ Uint32 *src32, *dst32; ++ Uint16 *rgb; ++ ++ /* XXX case width < 2 needs special treatment */ ++ ++ /* in pixel units */ ++ left = rect->x & ~1; /* 2 pixel align */ ++ width = (rect->w + 1) & ~1; /* 2 pixel align in excess */ ++ height = rect->h; ++ ++ /* in bytes, src and dest are 16bpp */ ++ src = shadow_mem + (rect->y * pitch) + left * 2; ++ dst = flip_address[back_page] + page_offset + ++ (rect->y * pitch) + left * 2; ++ mod = pitch - width * 2; ++ ++ src32 = (Uint32 *) src; ++ dst32 = (Uint32 *) dst; ++ mod32 = mod / 4; ++ ++ while (height--) { ++ i = width / 2; ++ ++ while (i--) { ++ rgb = (Uint16 *) src32; ++ *dst32++ = rgbrgb16toyuy2(rgb[0], rgb[1]); ++ src32++; ++ } ++ src32 += mod32; ++ dst32 += mod32; ++ } ++} ++ ++void GC_Init(_THIS, SDL_PixelFormat *vformat) ++{ ++ GC_InitRGB2YUVTables(); ++ ++ /* 16 bits per pixel */ ++ vformat->BitsPerPixel = 16; ++ vformat->BytesPerPixel = 2; ++ /* RGB565 */ ++ vformat->Rmask = 0x0000f800; ++ vformat->Gmask = 0x000007e0; ++ vformat->Bmask = 0x0000001f; ++ ++ shadow_fb = 1; ++} ++ ++/* ++ * ++ * Video mode handling. ++ */ ++ ++/* only 640x480 16bpp is currently supported */ ++const static SDL_Rect RECT_640x480 = { 0, 0, 640, 480 }; ++const static SDL_Rect *vid_modes[] = { ++ &RECT_640x480, ++ NULL ++}; ++ ++static SDL_Rect **GC_ListModes(_THIS, SDL_PixelFormat * format, Uint32 flags) ++{ ++ switch (format->BitsPerPixel) { ++ case 16: ++ return (SDL_Rect **) vid_modes; ++ default: ++ return NULL; ++ } ++} ++ ++SDL_Surface *GC_SetVideoMode(_THIS, SDL_Surface * current, ++ int width, int height, int bpp, Uint32 flags) ++{ ++ struct fb_fix_screeninfo finfo; ++ struct fb_var_screeninfo vinfo; ++ int i; ++ Uint32 Rmask; ++ Uint32 Gmask; ++ Uint32 Bmask; ++ Uint32 *p, *q; ++ Uint32 yres; ++ ++ GC_DPRINTF("Setting %dx%d %dbpp %smode\n", width, height, bpp, ++ (flags & SDL_DOUBLEBUF)?"(doublebuf) ":""); ++ ++ /* Set the terminal into graphics mode */ ++ if (FB_EnterGraphicsMode(this) < 0) { ++ return (NULL); ++ } ++ ++ /* Restore the original palette */ ++ //FB_RestorePalette(this); ++ ++ /* Set the video mode and get the final screen format */ ++ if (ioctl(console_fd, FBIOGET_VSCREENINFO, &vinfo) < 0) { ++ SDL_SetError("Couldn't get console screen info"); ++ return (NULL); ++ } ++ ++ yres = vinfo.yres; ++ ++ /* hack to center 640x480 resolution on PAL cubes */ ++ if (vinfo.xres == 640 && vinfo.yres == 576) { ++ page_offset = ((576 - 480) / 2) * 640 * ((bpp + 7) / 8); ++ } else { ++ page_offset = 0; ++ } ++ ++ /* clear all video memory */ ++ p = (Uint32 *)mapped_mem; ++ q = (Uint32 *)(mapped_mem + mapped_memlen); ++ while (p < q) ++ *p++ = GC_BLACK; ++ ++ if ((vinfo.xres != width) || (vinfo.yres != height) || ++ (vinfo.bits_per_pixel != bpp)) { ++ vinfo.activate = FB_ACTIVATE_NOW; ++ vinfo.accel_flags = 0; ++ vinfo.bits_per_pixel = bpp; ++ vinfo.xres = width; ++ vinfo.xres_virtual = width; ++ /* do not modify yres*, we use a fake 640x480 mode in PAL */ ++ //vinfo.yres = height; ++ //vinfo.yres_virtual = 2*height; ++ vinfo.xoffset = 0; ++ vinfo.yoffset = 0; ++ vinfo.red.length = vinfo.red.offset = 0; ++ vinfo.green.length = vinfo.green.offset = 0; ++ vinfo.blue.length = vinfo.blue.offset = 0; ++ vinfo.transp.length = vinfo.transp.offset = 0; ++ ++ if (ioctl(console_fd, FBIOPUT_VSCREENINFO, &vinfo) < 0) { ++ SDL_SetError("Couldn't set console screen info"); ++ return (NULL); ++ } ++ } else { ++ int maxheight; ++ ++ /* Figure out how much video memory is available */ ++ maxheight = 2*yres; ++ if (vinfo.yres_virtual > maxheight) { ++ vinfo.yres_virtual = maxheight; ++ } ++ } ++ cache_vinfo = vinfo; ++ ++ Rmask = 0; ++ for (i = 0; i < vinfo.red.length; ++i) { ++ Rmask <<= 1; ++ Rmask |= (0x00000001 << vinfo.red.offset); ++ } ++ Gmask = 0; ++ for (i = 0; i < vinfo.green.length; ++i) { ++ Gmask <<= 1; ++ Gmask |= (0x00000001 << vinfo.green.offset); ++ } ++ Bmask = 0; ++ for (i = 0; i < vinfo.blue.length; ++i) { ++ Bmask <<= 1; ++ Bmask |= (0x00000001 << vinfo.blue.offset); ++ } ++ if (!SDL_ReallocFormat(current, bpp, Rmask, Gmask, Bmask, 0)) { ++ return (NULL); ++ } ++ ++ /* Get the fixed information about the console hardware. ++ This is necessary since finfo.line_length changes. ++ */ ++ if (ioctl(console_fd, FBIOGET_FSCREENINFO, &finfo) < 0) { ++ SDL_SetError("Couldn't get console hardware info"); ++ return (NULL); ++ } ++ ++ /* Save hardware palette, if needed */ ++ //FB_SavePalette(this, &finfo, &vinfo); ++ ++ /* Set up the new mode framebuffer */ ++ current->flags = SDL_FULLSCREEN; ++ current->w = width; ++ current->h = height; ++ current->pitch = width * ((bpp + 7) / 8); ++ current->pixels = shadow_mem; ++ ++ flip_address[0] = mapped_mem; ++ flip_address[1] = mapped_mem + current->pitch * yres; ++ ++ back_page = 1; ++ if (flags & SDL_DOUBLEBUF) { ++ current->flags |= SDL_DOUBLEBUF; ++ flip_pending = 1; ++ } else { ++ flip_pending = 0; ++ /* make page 0 both the visible and back page */ ++ back_page = ioctl(console_fd, FBIOFLIPHACK, &back_page); ++ if (back_page < 0) ++ back_page = 0; ++ } ++ ++ /* Set the update rectangle function */ ++ switch (bpp) { ++ case 16: ++ GC_DPRINTF("Using 16bpp blitter\n"); ++ this->hidden->UpdateRect = GC_UpdateRectRGB16; ++ break; ++ default: ++ GC_DPRINTF("Using NO blitter\n"); ++ this->hidden->UpdateRect = NULL; ++ break; ++ } ++ ++ /* Handle OpenGL support */ ++#ifdef HAVE_OPENGL ++ if (flags & SDL_OPENGL) { ++ if (GC_GL_CreateWindow(this, width, height) == 0) { ++ current->flags |= (SDL_OPENGL | SDL_FULLSCREEN); ++ } else { ++ current = NULL; ++ } ++ } ++#endif /* HAVE_OPENGL */ ++ ++ /* We're done */ ++ return (current); ++} ++ ++static int GC_FlipHWSurface(_THIS, SDL_Surface * surface) ++{ ++ if (flip_pending) { ++ /* SDL_UpdateRect was not called */ ++ SDL_UpdateRect(this->screen, 0, 0, 0, 0); ++ } ++ ++ /* flip video page as soon as possible */ ++ ioctl(console_fd, FBIOFLIPHACK, NULL); ++ flip_pending = 1; ++ ++ return (0); ++} ++ ++static void GC_WaitForFlipCompletion(_THIS) ++{ ++ int visible_page; ++ int result; ++ ++ if (flip_pending) { ++ flip_pending = 0; ++ back_page ^= 1; ++ visible_page = back_page; ++ while (visible_page == back_page) { ++ /* wait until back_page is not visible */ ++ result = ioctl(console_fd, FBIOFLIPHACK, &back_page); ++ if (result < 0) { ++ if ((errno == EINTR) || (errno == EAGAIN)) ++ continue; ++ return; /* ioctl unsupported ... */ ++ } ++ visible_page = result; ++ } ++ /* ++ * At this point the back_page is not visible. We can safely ++ * write to it without tearing. ++ */ ++ } ++} ++ ++static void GC_UpdateRects(_THIS, int numrects, SDL_Rect * rects) ++{ ++ SDL_Surface *screen; ++ int pitch; ++ ++ /* external yuy2 fb is 16bpp */ ++ ++ screen = this->screen; ++ pitch = screen->pitch; /* this is the pitch of the shadow buffer */ ++ ++ if (this->hidden->UpdateRect) { ++ GC_WaitForFlipCompletion(this); ++ while (numrects--) { ++ if (rects->w <= 0 || rects->h <= 0) ++ continue; ++ this->hidden->UpdateRect(this, rects, pitch); ++ rects++; ++ } ++ } ++} ++ ++void GC_CreateDevice(SDL_VideoDevice *this) ++{ ++ this->ListModes = GC_ListModes; ++ this->SetVideoMode = GC_SetVideoMode; ++ this->FlipHWSurface = GC_FlipHWSurface; ++ this->UpdateRects = GC_UpdateRects; ++} ++ ++#endif +diff --git a/src/video/fbcon/SDL_fbgc.h b/src/video/fbcon/SDL_fbgc.h +new file mode 100644 +index 0000000..534a73e +--- /dev/null ++++ b/src/video/fbcon/SDL_fbgc.h +@@ -0,0 +1,35 @@ ++/* ++ SDL - Simple DirectMedia Layer ++ Copyright (C) 1997-2009 Sam Lantinga ++ ++ 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 St, Fifth Floor, Boston, MA 02110-1301 USA ++ ++ Sam Lantinga ++ slouken@libsdl.org ++*/ ++#include "SDL_config.h" ++ ++ ++#ifdef SDL_VIDEO_DRIVER_GC ++/* Gamecube/Wii hardware setup for the SDL framebuffer console driver */ ++ ++#include "SDL_fbvideo.h" ++ ++extern SDL_bool GC_Available(void); ++extern void GC_CreateDevice(SDL_VideoDevice *this); ++ ++extern SDL_bool GC_Test(_THIS); ++extern void GC_Init(_THIS, SDL_PixelFormat *vformat); ++#endif +diff --git a/src/video/fbcon/SDL_fbvideo.c b/src/video/fbcon/SDL_fbvideo.c +index 81a89da..328790e 100644 +--- a/src/video/fbcon/SDL_fbvideo.c ++++ b/src/video/fbcon/SDL_fbvideo.c +@@ -272,6 +272,11 @@ static SDL_VideoDevice *FB_CreateDevice(int devindex) + + this->free = FB_DeleteDevice; + ++#ifdef SDL_VIDEO_DRIVER_GC ++ if (GC_Available(this)) ++ GC_CreateDevice(this); ++#endif ++ + return this; + } + +@@ -784,6 +789,11 @@ static int FB_VideoInit(_THIS, SDL_PixelFormat *vformat) + } + } + ++#ifdef SDL_VIDEO_DRIVER_GC ++ if (GC_Test(this)) ++ GC_Init(this, vformat); ++#endif ++ + if (shadow_fb) { + shadow_mem = (char *)SDL_malloc(mapped_memlen); + if (shadow_mem == NULL) { +diff --git a/src/video/fbcon/SDL_fbvideo.h b/src/video/fbcon/SDL_fbvideo.h +index 03b9e94..74d1460 100644 +--- a/src/video/fbcon/SDL_fbvideo.h ++++ b/src/video/fbcon/SDL_fbvideo.h +@@ -106,6 +106,12 @@ struct SDL_PrivateVideoData { + + void (*wait_vbl)(_THIS); + void (*wait_idle)(_THIS); ++#ifdef SDL_VIDEO_DRIVER_GC ++ void (*UpdateRect) (_THIS, SDL_Rect * rect, int pitch); ++ int back_page; ++ int page_offset; ++ int flip_pending; ++#endif + }; + /* Old variable names */ + #define console_fd (this->hidden->console_fd) +@@ -147,6 +153,11 @@ struct SDL_PrivateVideoData { + #define screen_palette (this->hidden->screen_palette) + #define wait_vbl (this->hidden->wait_vbl) + #define wait_idle (this->hidden->wait_idle) ++#ifdef SDL_VIDEO_DRIVER_GC ++#define back_page (this->hidden->back_page) ++#define page_offset (this->hidden->page_offset) ++#define flip_pending (this->hidden->flip_pending) ++#endif + + /* Accelerator types that are supported by the driver, but are not + necessarily in the kernel headers on the system we compile on. +-- +1.6.5 + diff --git a/tools/SDL1.2.7_CE/SDL-1.27_CE.diff b/tools/SDL1.2.7_CE/SDL-1.27_CE.diff new file mode 100644 index 000000000..196329b84 --- /dev/null +++ b/tools/SDL1.2.7_CE/SDL-1.27_CE.diff @@ -0,0 +1,2260 @@ +diff -ruN SDL-1.2.7-orig/src/audio/windib/SDL_dibaudio.c SDL-1.2.7/src/audio/windib/SDL_dibaudio.c +--- SDL-1.2.7-orig/src/audio/windib/SDL_dibaudio.c Wed Feb 18 09:22:00 2004 ++++ SDL-1.2.7/src/audio/windib/SDL_dibaudio.c Thu Nov 18 12:07:29 2004 +@@ -146,8 +146,16 @@ + + /* Set high priority for the audio thread */ + static void DIB_ThreadInit(_THIS) +-{ +- SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST); ++{ ++#ifdef _WIN32_WCE ++#ifdef SH3 ++ SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL); ++#else ++ SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL); ++#endif ++#else ++ SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST); ++#endif + } + + void DIB_WaitAudio(_THIS) +diff -ruN SDL-1.2.7-orig/src/cpuinfo/SDL_cpuinfo.c SDL-1.2.7/src/cpuinfo/SDL_cpuinfo.c +--- SDL-1.2.7-orig/src/cpuinfo/SDL_cpuinfo.c Tue Feb 10 07:31:36 2004 ++++ SDL-1.2.7/src/cpuinfo/SDL_cpuinfo.c Fri Nov 19 20:53:01 2004 +@@ -38,6 +38,10 @@ + + #ifdef MACOSX + #include /* For AltiVec check */ ++#endif ++ ++#if defined(_MSC_VER) && (defined(ARM) || defined(MIPS) || defined(SHx)) ++#undef _MSC_VER + #endif + + #define CPU_HAS_RDTSC 0x00000001 +diff -ruN SDL-1.2.7-orig/src/joystick/win32/SDL_mmjoystick.c SDL-1.2.7/src/joystick/win32/SDL_mmjoystick.c +--- SDL-1.2.7-orig/src/joystick/win32/SDL_mmjoystick.c Wed Feb 18 09:22:02 2004 ++++ SDL-1.2.7/src/joystick/win32/SDL_mmjoystick.c Fri Nov 19 20:47:22 2004 +@@ -37,6 +37,7 @@ + + #include + #include ++#include + + #define MAX_JOYSTICKS 16 + #define MAX_AXES 6 /* each joystick can have up to 6 axes */ +@@ -51,6 +52,7 @@ + /* array to hold joystick ID values */ + static UINT SYS_JoystickID[MAX_JOYSTICKS]; + static JOYCAPS SYS_Joystick[MAX_JOYSTICKS]; ++static char *SYS_JoystickName[MAX_JOYSTICKS]; + + /* The private structure used to keep track of a joystick */ + struct joystick_hwdata +@@ -69,6 +71,78 @@ + /* Convert a win32 Multimedia API return code to a text message */ + static void SetMMerror(char *function, int code); + ++static char *GetJoystickName(int index, const char *szRegKey) ++{ ++ /* added 7/24/2004 by Eckhard Stolberg */ ++ /* ++ see if there is a joystick for the current ++ index (1-16) listed in the registry ++ */ ++ char *name = NULL; ++ HKEY hKey; ++ DWORD regsize; ++ LONG regresult; ++ unsigned char regkey[256]; ++ unsigned char regvalue[256]; ++ unsigned char regname[256]; ++ ++ sprintf(regkey, "%s\\%s\\%s", ++ REGSTR_PATH_JOYCONFIG, ++ szRegKey, ++ REGSTR_KEY_JOYCURR); ++ regresult = RegOpenKeyExA(HKEY_LOCAL_MACHINE, ++ (LPTSTR) ®key, 0, KEY_READ, &hKey); ++ if (regresult == ERROR_SUCCESS) ++ { ++ /* ++ find the registry key name for the ++ joystick's properties ++ */ ++ regsize = sizeof(regname); ++ sprintf(regvalue, ++ "Joystick%d%s", index+1, ++ REGSTR_VAL_JOYOEMNAME); ++ regresult = RegQueryValueExA(hKey, ++ regvalue, 0, 0, (LPBYTE) ®name, ++ (LPDWORD) ®size); ++ RegCloseKey(hKey); ++ if (regresult == ERROR_SUCCESS) ++ { ++ /* open that registry key */ ++ sprintf(regkey, "%s\\%s", ++ REGSTR_PATH_JOYOEM, regname); ++ regresult = RegOpenKeyExA(HKEY_LOCAL_MACHINE, ++ regkey, 0, KEY_READ, &hKey); ++ if (regresult == ERROR_SUCCESS) ++ { ++ /* find the size for the OEM name text */ ++ regsize = sizeof(regvalue); ++ regresult = ++ RegQueryValueExA(hKey, ++ REGSTR_VAL_JOYOEMNAME, ++ 0, 0, NULL, ++ (LPDWORD) ®size); ++ if (regresult == ERROR_SUCCESS) ++ { ++ /* ++ allocate enough memory ++ for the OEM name text ... ++ */ ++ name = (char *) malloc(regsize); ++ /* ... and read it from the registry */ ++ regresult = ++ RegQueryValueExA(hKey, ++ REGSTR_VAL_JOYOEMNAME, 0, 0, ++ (LPBYTE) name, ++ (LPDWORD) ®size); ++ RegCloseKey(hKey); ++ } ++ } ++ } ++ } ++ return(name); ++} ++ + + /* Function to scan the system for joysticks. + * This function should set SDL_numjoysticks to the number of available +@@ -94,6 +168,7 @@ + + for ( i = 0; i < MAX_JOYSTICKS; i++ ) { + SYS_JoystickID[i] = JOYSTICKID1 + i; ++ SYS_JoystickName[i] = NULL; + } + + +@@ -110,6 +185,7 @@ + if ( result == JOYERR_NOERROR ) { + SYS_JoystickID[numdevs] = SYS_JoystickID[i]; + SYS_Joystick[numdevs] = joycaps; ++ SYS_JoystickName[numdevs] = GetJoystickName(numdevs, joycaps.szRegKey); + numdevs++; + } + } +@@ -120,8 +196,11 @@ + /* Function to get the device-dependent name of a joystick */ + const char *SDL_SYS_JoystickName(int index) + { +- /***-> test for invalid index ? */ ++ if ( SYS_JoystickName[index] != NULL ) { ++ return(SYS_JoystickName[index]); ++ } else { + return(SYS_Joystick[index].szPname); ++ } + } + + /* Function to open a joystick for use. +@@ -292,7 +371,12 @@ + /* Function to perform any system-specific joystick related cleanup */ + void SDL_SYS_JoystickQuit(void) + { +- return; ++ int i; ++ for (i = 0; i < MAX_JOYSTICKS; i++) { ++ if ( SYS_JoystickName[i] != NULL ) { ++ free(SYS_JoystickName[i]); ++ } ++ } + } + + +diff -ruN SDL-1.2.7-orig/src/video/SDL_sysvideo.h SDL-1.2.7/src/video/SDL_sysvideo.h +--- SDL-1.2.7-orig/src/video/SDL_sysvideo.h Wed Feb 18 09:22:04 2004 ++++ SDL-1.2.7/src/video/SDL_sysvideo.h Thu Nov 18 12:08:48 2004 +@@ -361,6 +361,9 @@ + #endif + #ifdef ENABLE_WINDIB + extern VideoBootStrap WINDIB_bootstrap; ++#endif ++#ifdef ENABLE_WINGAPI ++extern VideoBootStrap WINGAPI_bootstrap; + #endif + #ifdef ENABLE_DIRECTX + extern VideoBootStrap DIRECTX_bootstrap; +diff -ruN SDL-1.2.7-orig/src/video/SDL_video.c SDL-1.2.7/src/video/SDL_video.c +--- SDL-1.2.7-orig/src/video/SDL_video.c Wed Feb 18 09:22:04 2004 ++++ SDL-1.2.7/src/video/SDL_video.c Thu Nov 18 12:11:01 2004 +@@ -80,6 +80,9 @@ + #endif + #ifdef ENABLE_DIRECTX + &DIRECTX_bootstrap, ++#endif ++#ifdef ENABLE_WINGAPI ++ &WINGAPI_bootstrap, + #endif + #ifdef ENABLE_WINDIB + &WINDIB_bootstrap, +diff -ruN SDL-1.2.7-orig/src/video/wincommon/SDL_sysevents.c SDL-1.2.7/src/video/wincommon/SDL_sysevents.c +--- SDL-1.2.7-orig/src/video/wincommon/SDL_sysevents.c Wed Feb 18 09:22:10 2004 ++++ SDL-1.2.7/src/video/wincommon/SDL_sysevents.c Thu Nov 18 12:28:03 2004 +@@ -40,6 +40,9 @@ + #include "SDL_lowvideo.h" + #include "SDL_syswm_c.h" + #include "SDL_main.h" ++#ifdef _WIN32_CE ++#include "SDL_dibvideo.h" ++#endif + + #ifdef WMMSG_DEBUG + #include "wmmsg.h" +@@ -173,6 +176,39 @@ + SDL_SetModState(state); + #endif /* !NO_GETKEYBOARDSTATE */ + } ++ ++#ifdef _WIN32_CE ++void transform(SDL_RotateAttr rotate, char ozone, Sint16 *x, Sint16 *y) { ++ Sint16 rotatedX; ++ Sint16 rotatedY; ++ ++ if (ozone) { ++ *x = *x * 2; ++ *y = *y * 2; ++ } ++ ++ switch(rotate) { ++ case SDL_ROTATE_NONE: ++ break; ++ case SDL_ROTATE_LEFT: ++ if (!SDL_VideoSurface) ++ break; ++ rotatedX = SDL_VideoSurface->w - *y; ++ rotatedY = *x; ++ *x = rotatedX; ++ *y = rotatedY; ++ break; ++ case SDL_ROTATE_RIGHT: ++ if (!SDL_VideoSurface) ++ break; ++ rotatedX = *y; ++ rotatedY = SDL_VideoSurface->h - *x; ++ *x = rotatedX; ++ *y = rotatedY; ++ break; ++ } ++} ++#endif + + /* The main Win32 event handler + DJM: This is no longer static as (DX5/DIB)_CreateWindow needs it +@@ -273,7 +309,11 @@ + SetCursorPos(center.x, center.y); + posted = SDL_PrivateMouseMotion(0, 1, x, y); + } +- } else { ++ } else { ++#ifdef _WIN32_CE ++ if (SDL_VideoSurface) ++ transform(rotation, ozoneHack, &x, &y); ++#endif + posted = SDL_PrivateMouseMotion(0, 0, x, y); + } + } +@@ -361,8 +401,16 @@ + x = 0; y = 0; + } else { + x = (Sint16)LOWORD(lParam); +- y = (Sint16)HIWORD(lParam); +- } ++ y = (Sint16)HIWORD(lParam); ++#ifdef _WIN32_CE ++ if (SDL_VideoSurface) ++ transform(rotation, ozoneHack, &x, &y); ++#endif ++ } ++#ifdef _WIN32_WCE ++ /* Since stylus movements are not continuous */ ++ posted = SDL_PrivateMouseMotion(0, 0, x, y); ++#endif + posted = SDL_PrivateMouseButton( + state, button, x, y); + } +diff -ruN SDL-1.2.7-orig/src/video/wincommon/SDL_sysmouse.c SDL-1.2.7/src/video/wincommon/SDL_sysmouse.c +--- SDL-1.2.7-orig/src/video/wincommon/SDL_sysmouse.c Sat Aug 30 13:13:12 2003 ++++ SDL-1.2.7/src/video/wincommon/SDL_sysmouse.c Thu Nov 18 12:29:20 2004 +@@ -250,12 +250,16 @@ + + /* Check to see if we need to enter or leave mouse relative mode */ + void WIN_CheckMouseMode(_THIS) +-{ ++{ ++#ifdef _WIN32_WCE ++ mouse_relative = 0; ++#else + /* If the mouse is hidden and input is grabbed, we use relative mode */ + if ( !(SDL_cursorstate & CURSOR_VISIBLE) && + (this->input_grab != SDL_GRAB_OFF) ) { + mouse_relative = 1; + } else { + mouse_relative = 0; +- } ++ } ++#endif + } +diff -ruN SDL-1.2.7-orig/src/video/windib/SDL_dibevents.c SDL-1.2.7/src/video/windib/SDL_dibevents.c +--- SDL-1.2.7-orig/src/video/windib/SDL_dibevents.c Wed Feb 18 09:22:10 2004 ++++ SDL-1.2.7/src/video/windib/SDL_dibevents.c Thu Nov 18 13:12:28 2004 +@@ -58,6 +58,29 @@ + /* DJM: If the user setup the window for us, we want to save his window proc, + and give him a chance to handle some messages. */ + static WNDPROC userWindowProc = NULL; ++ ++#ifdef _WIN32_WCE ++ ++WPARAM rotateKey(WPARAM key, SDL_RotateAttr direction) { ++ if (direction != SDL_ROTATE_LEFT) ++ return key; ++ ++ switch (key) { ++ case 0x26: /* up */ ++ return 0x27; ++ case 0x27: /* right */ ++ return 0x28; ++ case 0x28: /* down */ ++ return 0x25; ++ case 0x25: /* left */ ++ return 0x26; ++ } ++ ++ return key; ++} ++ ++#endif ++ + + /* The main Win32 event handler */ + LONG +@@ -69,6 +92,16 @@ + case WM_SYSKEYDOWN: + case WM_KEYDOWN: { + SDL_keysym keysym; ++ ++#ifdef _WIN32_WCE ++ // Drop GAPI artefacts ++ if (wParam == 0x84 || wParam == 0x5B) ++ return 0; ++ ++ // Rotate key if necessary ++ if (rotation != SDL_ROTATE_NONE) ++ wParam = rotateKey(wParam, rotation); ++#endif + + /* Ignore repeated keys */ + if ( lParam&REPEATED_KEYMASK ) { +@@ -129,6 +162,16 @@ + case WM_KEYUP: { + SDL_keysym keysym; + ++#ifdef _WIN32_WCE ++ // Drop GAPI artefacts ++ if (wParam == 0x84 || wParam == 0x5B) ++ return 0; ++ ++ // Rotate key if necessary ++ if (rotation != SDL_ROTATE_NONE) ++ wParam = rotateKey(wParam, rotation); ++#endif ++ + switch (wParam) { + case VK_CONTROL: + if ( lParam&EXTENDED_KEYMASK ) +@@ -333,7 +376,16 @@ + VK_keymap[VK_APPS] = SDLK_MENU; + + prev_shiftstates[0] = FALSE; +- prev_shiftstates[1] = FALSE; ++ prev_shiftstates[1] = FALSE; ++ ++#ifdef _WIN32_WCE ++ /* Hardcode the 4 magic keys to F1 F2 F3 F4 - the actual location of the keys varies ... */ ++ VK_keymap[0xC1] = SDLK_F1; ++ VK_keymap[0xC2] = SDLK_F2; ++ VK_keymap[0xC3] = SDLK_F3; ++ VK_keymap[0xC4] = SDLK_F4; ++#endif ++ + } + + static SDL_keysym *TranslateKey(UINT vkey, UINT scancode, SDL_keysym *keysym, int pressed) +@@ -364,9 +416,15 @@ + { + #ifndef CS_BYTEALIGNCLIENT + #define CS_BYTEALIGNCLIENT 0 ++#endif ++#ifdef _WIN32_CE ++ SDL_RegisterApp("SDL_app", CS_BYTEALIGNCLIENT | CS_HREDRAW | CS_VREDRAW, 0); ++#else ++ SDL_RegisterApp("SDL_app", CS_BYTEALIGNCLIENT, 0); + #endif +- SDL_RegisterApp("SDL_app", CS_BYTEALIGNCLIENT, 0); +- if ( SDL_windowid ) { ++ if ( SDL_windowid ) { ++// FIXME ++#ifndef _WIN32_WCE + SDL_Window = (HWND)strtol(SDL_windowid, NULL, 0); + + /* DJM: we want all event's for the user specified +@@ -375,11 +433,19 @@ + if (SDL_Window) { + userWindowProc = (WNDPROC)GetWindowLong(SDL_Window, GWL_WNDPROC); + SetWindowLong(SDL_Window, GWL_WNDPROC, (LONG)WinMessage); +- } +- } else { ++ } ++ #endif ++ } else { ++#ifdef _WIN32_WCE ++ ++ SDL_Window = CreateWindow(SDL_Appname, SDL_Appname, (WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX), ++ 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), ++ NULL, NULL, SDL_Instance, NULL); ++#else + SDL_Window = CreateWindow(SDL_Appname, SDL_Appname, + (WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX), +- CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL, SDL_Instance, NULL); ++ CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL, SDL_Instance, NULL); ++#endif + if ( SDL_Window == NULL ) { + SDL_SetError("Couldn't create window"); + return(-1); +diff -ruN SDL-1.2.7-orig/src/video/windib/SDL_dibvideo.c SDL-1.2.7/src/video/windib/SDL_dibvideo.c +--- SDL-1.2.7-orig/src/video/windib/SDL_dibvideo.c Wed Feb 18 09:22:10 2004 ++++ SDL-1.2.7/src/video/windib/SDL_dibvideo.c Mon Aug 8 18:27:52 2005 +@@ -29,15 +29,26 @@ + #include + #include + #include +-#if defined(WIN32_PLATFORM_PSPC) ++#if (defined (UNDER_CE) && (UNDER_CE >= 420)) + #include // Add Pocket PC includes + #pragma comment( lib, "aygshell" ) // Link Pocket PC library + #endif ++ ++#ifdef _MSC_VER ++#pragma warning(disable: 4244) ++#define inline __inline ++#endif ++ + + /* Not yet in the mingw32 cross-compile headers */ + #ifndef CDS_FULLSCREEN + #define CDS_FULLSCREEN 4 + #endif ++ ++#ifndef WS_THICKFRAME ++#define WS_THICKFRAME 0 ++#endif ++ + + #include "SDL.h" + #include "SDL_mutex.h" +@@ -55,7 +66,18 @@ + #ifdef _WIN32_WCE + #define NO_GETDIBITS + #define NO_CHANGEDISPLAYSETTINGS +-#define NO_GAMMA_SUPPORT ++#define NO_GAMMA_SUPPORT ++ ++/* uncomment this line if you target WinCE 3.x platform: */ ++//#define NO_SETDIBCOLORTABLE ++ ++/* these 2 variables are used to suport paletted DIBs on WinCE 3.x that ++ does not implement SetDIBColorTable, and when SetDIBColorTable is not working. ++ Slow. DIB is recreated every time. ++*/ ++static BITMAPINFO *last_bitmapinfo; ++static void** last_bits; ++ + #endif + #ifndef WS_MAXIMIZE + #define WS_MAXIMIZE 0 +@@ -96,6 +118,13 @@ + + /* helper fn */ + static int DIB_SussScreenDepth(); ++ ++#ifdef _WIN32_WCE ++void DIB_ShowTaskBar(BOOL taskBarShown); ++#ifdef ENABLE_WINGAPI ++extern void GAPI_GrabHardwareKeys(BOOL grab); ++#endif ++#endif + + /* DIB driver bootstrap functions */ + +@@ -352,6 +381,9 @@ + + /* Fill in some window manager capabilities */ + this->info.wm_available = 1; ++ ++ /* Rotation information */ ++ rotation = SDL_ROTATE_NONE; + + /* We're done! */ + return(0); +@@ -370,7 +402,43 @@ + } + #endif + } +- ++ ++#ifdef _WIN32_WCE ++ ++void DIB_ShowTaskBar(BOOL taskBarShown) { ++#if (UNDER_CE < 420) ++ // Hide taskbar, WinCE 2.x style - from EasyCE ++ HKEY hKey=0; ++ DWORD dwValue = 0; ++ unsigned long lSize = sizeof( DWORD ); ++ DWORD dwType = REG_DWORD; ++ HWND hWnd; ++ ++ RegOpenKeyEx( HKEY_LOCAL_MACHINE, TEXT("\\software\\microsoft\\shell"), 0, KEY_ALL_ACCESS, &hKey ); ++ RegQueryValueEx( hKey, TEXT("TBOpt"), 0, &dwType, (BYTE*)&dwValue, &lSize ); ++ if (taskBarShown) ++ dwValue &= 0xFFFFFFFF - 8; // reset bit to show taskbar ++ else ++ dwValue |= 8; // set bit to hide taskbar ++ RegSetValueEx( hKey, TEXT("TBOpt"), 0, REG_DWORD, (BYTE*)&dwValue, lSize ); ++ hWnd = FindWindow( TEXT("HHTaskBar"), NULL ); ++ SendMessage(hWnd, WM_COMMAND, 0x03EA, 0 ); ++ SetForegroundWindow(SDL_Window); ++#else ++ if (taskBarShown) ++ SHFullScreen(SDL_Window, SHFS_SHOWTASKBAR | SHFS_SHOWSIPBUTTON | SHFS_SHOWSTARTICON); ++ else ++ SHFullScreen(SDL_Window, SHFS_HIDETASKBAR | SHFS_HIDESIPBUTTON | SHFS_HIDESTARTICON); ++#endif ++ if (FindWindow(TEXT("HHTaskBar"), NULL)) { // is it valid for HPC ? ++ if (taskBarShown) ++ ShowWindow(FindWindow(TEXT("HHTaskBar"),NULL),SW_SHOWNORMAL); ++ else ++ ShowWindow(FindWindow(TEXT("HHTaskBar"),NULL),SW_HIDE); ++ } ++} ++ ++#endif + + /* + Helper fn to work out which screen depth windows is currently using. +@@ -444,7 +512,8 @@ + + + /* Various screen update functions available */ +-static void DIB_NormalUpdate(_THIS, int numrects, SDL_Rect *rects); ++static void DIB_NormalUpdate(_THIS, int numrects, SDL_Rect *rects); ++static void DIB_RotatedUpdate(_THIS, int numrects, SDL_Rect *rects); + + SDL_Surface *DIB_SetVideoMode(_THIS, SDL_Surface *current, + int width, int height, int bpp, Uint32 flags) +@@ -463,12 +532,20 @@ + HDC hdc; + RECT bounds; + int x, y; +- Uint32 Rmask, Gmask, Bmask; +- ++ Uint32 Rmask, Gmask, Bmask; ++#ifdef _WIN32_CE ++ int screenWidth, screenHeight; ++#endif ++#ifdef UNDER_CE ++ int i; ++#endif ++ ++#ifdef HAVE_OPENGL + /* Clean up any GL context that may be hanging around */ + if ( current->flags & SDL_OPENGL ) { + WIN_GL_ShutDown(this); +- } ++ } ++#endif + + /* Recalculate the bitmasks if necessary */ + if ( bpp == current->format->BitsPerPixel ) { +@@ -517,20 +594,16 @@ + video->h = height; + video->pitch = SDL_CalculatePitch(video); + +-#ifdef WIN32_PLATFORM_PSPC ++#ifdef _WIN32_CE + /* Stuff to hide that $#!^%#$ WinCE taskbar in fullscreen... */ + if ( flags & SDL_FULLSCREEN ) { + if ( !(prev_flags & SDL_FULLSCREEN) ) { +- SHFullScreen(SDL_Window, SHFS_HIDETASKBAR); +- SHFullScreen(SDL_Window, SHFS_HIDESIPBUTTON); +- ShowWindow(FindWindow(TEXT("HHTaskBar"),NULL),SW_HIDE); ++ DIB_ShowTaskBar(FALSE); + } + video->flags |= SDL_FULLSCREEN; + } else { + if ( prev_flags & SDL_FULLSCREEN ) { +- SHFullScreen(SDL_Window, SHFS_SHOWTASKBAR); +- SHFullScreen(SDL_Window, SHFS_SHOWSIPBUTTON); +- ShowWindow(FindWindow(TEXT("HHTaskBar"),NULL),SW_SHOWNORMAL); ++ DIB_ShowTaskBar(TRUE); + } + } + #endif +@@ -640,28 +713,82 @@ + ((Uint32*)binfo->bmiColors)[0] = video->format->Rmask; + ((Uint32*)binfo->bmiColors)[1] = video->format->Gmask; + ((Uint32*)binfo->bmiColors)[2] = video->format->Bmask; +- } else { ++ } else { ++#ifdef UNDER_CE ++ binfo->bmiHeader.biCompression = BI_RGB; /* 332 */ ++ if ( video->format->palette ) { ++ binfo->bmiHeader.biClrUsed = video->format->palette->ncolors; ++ for(i=0; iformat->palette->ncolors; i++) ++ { ++ binfo->bmiColors[i].rgbRed=i&(7<<5); ++ binfo->bmiColors[i].rgbGreen=(i&(7<<2))<<3; ++ binfo->bmiColors[i].rgbBlue=(i&3)<<5; ++ binfo->bmiColors[i].rgbReserved=0; ++ } ++ } ++#else + binfo->bmiHeader.biCompression = BI_RGB; /* BI_BITFIELDS for 565 vs 555 */ + if ( video->format->palette ) { + memset(binfo->bmiColors, 0, + video->format->palette->ncolors*sizeof(RGBQUAD)); +- } ++ } ++#endif + } + + /* Create the offscreen bitmap buffer */ +- hdc = GetDC(SDL_Window); ++ hdc = GetDC(SDL_Window); ++#ifdef _WIN32_CE ++ /* See if we need to rotate the buffer (WinCE specific) */ ++ screenWidth = GetDeviceCaps(hdc, HORZRES); ++ screenHeight = GetDeviceCaps(hdc, VERTRES); ++ rotation = SDL_ROTATE_NONE; ++ work_pixels = NULL; ++ if (rotation_pixels) { ++ free(rotation_pixels); ++ rotation_pixels = NULL; ++ } ++ ++ if ((flags & SDL_FULLSCREEN) && (width>height) && (width > screenWidth) ) { ++ /* OK, we rotate the screen */ ++ video->pixels = malloc(video->h * video->pitch); ++ rotation_pixels = video->pixels; ++ if (video->pixels) ++ rotation = SDL_ROTATE_LEFT; ++ OutputDebugString(TEXT("will rotate\r\n")); ++ } ++ screen_bmp = CreateDIBSection(hdc, binfo, DIB_RGB_COLORS, ++ (rotation == SDL_ROTATE_NONE ? (void **)(&video->pixels) : (void**)&work_pixels), NULL, 0); ++#else + screen_bmp = CreateDIBSection(hdc, binfo, DIB_RGB_COLORS, +- (void **)(&video->pixels), NULL, 0); +- ReleaseDC(SDL_Window, hdc); +- free(binfo); ++ (void **)(&video->pixels), NULL, 0); ++#endif ++ ReleaseDC(SDL_Window, hdc); ++#ifdef UNDER_CE ++/* keep bitmapinfo for palette in 8-bit modes for devices that don't have SetDIBColorTable */ ++ last_bits = (rotation == SDL_ROTATE_NONE ? (void **)(&video->pixels) : (void**)&work_pixels); ++ if(last_bitmapinfo) ++ free(last_bitmapinfo); ++ if(is16bitmode) ++ { ++ last_bitmapinfo = 0; ++ free(binfo); ++ } else ++ last_bitmapinfo = binfo; ++#else ++ free(binfo); ++#endif + if ( screen_bmp == NULL ) { + if ( video != current ) { + SDL_FreeSurface(video); + } + SDL_SetError("Couldn't create DIB section"); + return(NULL); +- } +- this->UpdateRects = DIB_NormalUpdate; ++ } ++#ifdef _WIN32_CE ++ this->UpdateRects = (work_pixels ? DIB_RotatedUpdate : DIB_NormalUpdate); ++#else ++ this->UpdateRects = DIB_NormalUpdate; ++#endif + + /* Set video surface flags */ + if ( bpp <= 8 ) { +@@ -695,7 +822,15 @@ + bounds.left = SDL_windowX; + bounds.top = SDL_windowY; + bounds.right = SDL_windowX+video->w; +- bounds.bottom = SDL_windowY+video->h; ++ bounds.bottom = SDL_windowY+video->h; ++#ifdef UNDER_CE ++ if(rotation != SDL_ROTATE_NONE) ++ { ++ int t=bounds.right; ++ bounds.right = bounds.bottom; ++ bounds.bottom=t; ++ } ++#endif + AdjustWindowRectEx(&bounds, GetWindowLong(SDL_Window, GWL_STYLE), FALSE, 0); + width = bounds.right-bounds.left; + height = bounds.bottom-bounds.top; +@@ -709,8 +844,10 @@ + x = (GetSystemMetrics(SM_CXSCREEN)-width)/2; + y = (GetSystemMetrics(SM_CYSCREEN)-height)/2; + } else { +- x = y = -1; +- swp_flags |= SWP_NOMOVE; ++ x = y = -1; ++#ifndef UNDER_CE ++ swp_flags |= SWP_NOMOVE; ++#endif + } + if ( y < 0 ) { /* Cover up title bar for more client area */ + y -= GetSystemMetrics(SM_CYCAPTION)/2; +@@ -719,19 +856,44 @@ + top = HWND_TOPMOST; + } else { + top = HWND_NOTOPMOST; +- } +- SetWindowPos(SDL_Window, top, x, y, width, height, swp_flags); ++ } ++#ifdef _WIN32_CE ++ if (flags & SDL_FULLSCREEN) { ++/* When WinCE program switches resolution from larger to smaller we should move its window so it would be visible in fullscreen */ ++// SetWindowPos(SDL_Window, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); ++ DIB_ShowTaskBar(FALSE); ++ if(x>0) x=0; // remove space from the left side of a screen in 320x200 mode ++ if(y>0) y=0; ++ SetWindowPos(SDL_Window, HWND_TOPMOST, x, y, width, height, SWP_NOCOPYBITS); ++ ShowWindow(SDL_Window, SW_SHOW); ++ } ++ else ++ SetWindowPos(SDL_Window, top, x, y, width, height, swp_flags); ++#else ++ SetWindowPos(SDL_Window, top, x, y, width, height, swp_flags); ++#endif + SDL_resizing = 0; + SetForegroundWindow(SDL_Window); + } + + /* Set up for OpenGL */ +- if ( flags & SDL_OPENGL ) { ++ if ( flags & SDL_OPENGL ) { ++#ifdef HAVE_OPENGL + if ( WIN_GL_SetupWindow(this) < 0 ) { + return(NULL); + } +- video->flags |= SDL_OPENGL; +- } ++ video->flags |= SDL_OPENGL; ++#else ++ return NULL; ++#endif ++ } ++ ++#ifdef ENABLE_WINGAPI ++ /* Grab hardware keys if necessary */ ++ if ( flags & SDL_FULLSCREEN ) { ++ GAPI_GrabHardwareKeys(TRUE); ++ } ++#endif + + /* We're live! */ + return(video); +@@ -754,22 +916,169 @@ + { + return; + } ++ ++#ifdef _WIN32_CE ++ ++static inline void rotateBlit(unsigned short *src, unsigned short *dest, SDL_Rect *rect, int pitch) { ++ int i=rect->w, j=rect->h; ++ src+=i; ++ ++ for (;i--;) { ++ register unsigned short *S=src--; ++// I use loop unrolling to spedup things a little ++ int cnt = j; ++ if(cnt&1) ++ { ++ *(dest++) = *S; ++ S+=pitch; ++ } ++ cnt>>=1; ++ if(cnt&1) ++ { ++ *(dest++) = *S; ++ S+=pitch; ++ *(dest++) = *S; ++ S+=pitch; ++ } ++ cnt>>=1; ++ for (; cnt--; ) { ++ *(dest++) = *S; ++ S+=pitch; ++ *(dest++) = *S; ++ S+=pitch; ++ *(dest++) = *S; ++ S+=pitch; ++ *(dest++) = *S; ++ S+=pitch; ++ } ++ } ++/* tiny optimization ++ int i, j; ++ src+=rect->w; ++ ++ for (i=0; iw; i++) { ++ register unsigned short *S=src--; ++ for (j=0; jh; j++) { ++ *(dest++) = *S; ++ S+=pitch; ++ } ++ } ++*/ ++/* original unoptimized version ++ int i, j; ++ ++ for (i=0; iw; i++) { ++ for (j=0; jh; j++) { ++ dest[i * rect->h + j] = src[pitch * j + (rect->w - i)]; ++ } ++ } ++*/ ++} ++ ++static inline void rotateBlit8(unsigned char *src, unsigned char *dest, SDL_Rect *rect, int pitch) { ++ int i=rect->w, j=rect->h; ++ src+=i; ++ ++ for (;i--;) { ++ register unsigned char *S=src--; ++// I use loop unrolling to spedup things a little ++ int cnt = j; ++ if(cnt&1) ++ { ++ *(dest++) = *S; ++ S+=pitch; ++ } ++ cnt>>=1; ++ if(cnt&1) ++ { ++ *(dest++) = *S; ++ S+=pitch; ++ *(dest++) = *S; ++ S+=pitch; ++ } ++ cnt>>=1; ++ for (; cnt--; ) { ++ *(dest++) = *S; ++ S+=pitch; ++ *(dest++) = *S; ++ S+=pitch; ++ *(dest++) = *S; ++ S+=pitch; ++ *(dest++) = *S; ++ S+=pitch; ++ } ++ } ++} ++ ++static void DIB_RotatedUpdate(_THIS, int numrects, SDL_Rect *rects) ++{ ++ HDC hdc, mdc; ++ HBITMAP hb, old; ++ int i; ++ ++ hdc = GetDC(SDL_Window); ++ if ( screen_pal ) { ++ SelectPalette(hdc, screen_pal, FALSE); ++ } ++ mdc = CreateCompatibleDC(hdc); ++ /*SelectObject(mdc, screen_bmp);*/ ++ if(this->screen->format->BytesPerPixel == 2) { ++ for ( i=0; iscreen->pixels; ++ rotateBlit(src + (this->screen->w * rects[i].y) + rects[i].x, work_pixels, &rects[i], this->screen->w); ++ hb = CreateBitmap(rects[i].h, rects[i].w, 1, 16, work_pixels); ++ old = (HBITMAP)SelectObject(mdc, hb); ++ BitBlt(hdc, rects[i].y, this->screen->w - (rects[i].x + rects[i].w), rects[i].h, rects[i].w, ++ mdc, 0, 0, SRCCOPY); ++ SelectObject(mdc, old); ++ DeleteObject(hb); ++ } ++ } else { ++ if ( screen_pal ) { ++ SelectPalette(mdc, screen_pal, FALSE); ++ } ++ for ( i=0; iscreen->pixels; ++ rotateBlit8(src + (this->screen->w * rects[i].y) + rects[i].x, work_pixels, &rects[i], this->screen->w); ++ hb = CreateBitmap(rects[i].h, rects[i].w, 1, 8, work_pixels); ++ old = (HBITMAP)SelectObject(mdc, hb); ++ BitBlt(hdc, rects[i].y, this->screen->w - (rects[i].x + rects[i].w), rects[i].h, rects[i].w, ++ mdc, 0, 0, SRCCOPY); ++ SelectObject(mdc, old); ++ DeleteObject(hb); ++ } ++ } ++ DeleteDC(mdc); ++ ReleaseDC(SDL_Window, hdc); ++} ++#endif ++ + + static void DIB_NormalUpdate(_THIS, int numrects, SDL_Rect *rects) + { + HDC hdc, mdc; +- int i; ++ int i; ++#ifdef _WIN32_CE ++ HBITMAP old; ++#endif + + hdc = GetDC(SDL_Window); + if ( screen_pal ) { + SelectPalette(hdc, screen_pal, FALSE); + } +- mdc = CreateCompatibleDC(hdc); +- SelectObject(mdc, screen_bmp); ++ mdc = CreateCompatibleDC(hdc); ++#ifdef _WIN32_CE ++ old = (HBITMAP)SelectObject(mdc, screen_bmp); ++#else ++ SelectObject(mdc, screen_bmp); ++#endif + for ( i=0; ibmiHeader.biClrUsed=256; ++ for ( i=firstcolor; ibmiColors[i]=pal[i]; ++ screen_bmp = CreateDIBSection(hdc, last_bitmapinfo, DIB_RGB_COLORS, ++ last_bits, NULL, 0); ++ } ++#else + SelectObject(mdc, screen_bmp); +- SetDIBColorTable(mdc, firstcolor, ncolors, pal); ++ SetDIBColorTable(mdc, firstcolor, ncolors, pal); ++#endif ++#ifndef UNDER_CE + BitBlt(hdc, 0, 0, this->screen->w, this->screen->h, +- mdc, 0, 0, SRCCOPY); ++ mdc, 0, 0, SRCCOPY); ++#else ++ { ++ SDL_Rect rect; ++ rect.x=0; rect.y=0; ++ rect.w=this->screen->w; rect.h=this->screen->h; ++// Fixme: screen flickers: (this->UpdateRects)(this, 1, &rect) ; ++ } ++#endif + DeleteDC(mdc); +-#endif + ReleaseDC(SDL_Window, hdc); + return(1); + } +@@ -937,27 +1270,27 @@ + + void DIB_VideoQuit(_THIS) + { +- /* Destroy the window and everything associated with it */ ++ /* Destroy the window and everything associated with it */ ++#ifdef _WIN32_CE ++ DIB_ShowTaskBar(TRUE); ++#ifdef ENABLE_WINGAPI ++ GAPI_GrabHardwareKeys(FALSE); ++#endif ++#endif + if ( SDL_Window ) { + /* Delete the screen bitmap (also frees screen->pixels) */ + if ( this->screen ) { +-#ifdef WIN32_PLATFORM_PSPC +- if ( this->screen->flags & SDL_FULLSCREEN ) { +- /* Unhide taskbar, etc. */ +- SHFullScreen(SDL_Window, SHFS_SHOWTASKBAR); +- SHFullScreen(SDL_Window, SHFS_SHOWSIPBUTTON); +- ShowWindow(FindWindow(TEXT("HHTaskBar"),NULL),SW_SHOWNORMAL); +- } +-#endif + #ifndef NO_CHANGEDISPLAYSETTINGS + if ( this->screen->flags & SDL_FULLSCREEN ) { + ChangeDisplaySettings(NULL, 0); + ShowWindow(SDL_Window, SW_HIDE); + } +-#endif ++#endif ++#ifdef HAVE_OPENGL + if ( this->screen->flags & SDL_OPENGL ) { + WIN_GL_ShutDown(this); +- } ++ } ++#endif + this->screen->pixels = NULL; + } + if ( screen_bmp ) { +diff -ruN SDL-1.2.7-orig/src/video/windib/SDL_dibvideo.h SDL-1.2.7/src/video/windib/SDL_dibvideo.h +--- SDL-1.2.7-orig/src/video/windib/SDL_dibvideo.h Wed Feb 18 09:22:10 2004 ++++ SDL-1.2.7/src/video/windib/SDL_dibvideo.h Thu Nov 18 13:13:42 2004 +@@ -29,11 +29,26 @@ + #define _SDL_dibvideo_h + + #include ++ ++//#ifdef _WIN32_CE ++/* Rotation direction */ ++typedef enum { ++ SDL_ROTATE_NONE, ++ SDL_ROTATE_LEFT, ++ SDL_ROTATE_RIGHT ++} SDL_RotateAttr; ++//#endif + + /* Private display data */ + struct SDL_PrivateVideoData { + HBITMAP screen_bmp; +- HPALETTE screen_pal; ++ HPALETTE screen_pal; ++//#ifdef _WIN32_CE ++ void *work_pixels; /* if the display needs to be rotated, memory allocated by the API */ ++ void *rotation_pixels; /* if the display needs to be rotated, memory allocated by the code */ ++ SDL_RotateAttr rotation; ++ char ozoneHack; /* force stylus translation if running without Hi Res flag */ ++//#endif + + #define NUM_MODELISTS 4 /* 8, 16, 24, and 32 bits-per-pixel */ + int SDL_nummodes[NUM_MODELISTS]; +@@ -43,6 +58,12 @@ + #define screen_bmp (this->hidden->screen_bmp) + #define screen_pal (this->hidden->screen_pal) + #define SDL_nummodes (this->hidden->SDL_nummodes) +-#define SDL_modelist (this->hidden->SDL_modelist) ++#define SDL_modelist (this->hidden->SDL_modelist) ++//#ifdef _WIN32_CE ++#define work_pixels (this->hidden->work_pixels) ++#define rotation (this->hidden->rotation) ++#define rotation_pixels (this->hidden->rotation_pixels) ++#define ozoneHack (this->hidden->ozoneHack) ++//#endif + + #endif /* _SDL_dibvideo_h */ +diff -ruN SDL-1.2.7-orig/src/video/wingapi/SDL_gapivideo.c SDL-1.2.7/src/video/wingapi/SDL_gapivideo.c +--- SDL-1.2.7-orig/src/video/wingapi/SDL_gapivideo.c Wed Dec 31 19:00:00 1969 ++++ SDL-1.2.7/src/video/wingapi/SDL_gapivideo.c Thu Nov 18 13:43:27 2004 +@@ -0,0 +1,956 @@ ++/* ++ SDL - Simple DirectMedia Layer ++ Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Sam Lantinga ++ ++ This library is free software; you can redistribute it and/or ++ modify it under the terms of the GNU Library General Public ++ License as published by the Free Software Foundation; either ++ version 2 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 ++ Library General Public License for more details. ++ ++ You should have received a copy of the GNU Library General Public ++ License along with this library; if not, write to the Free ++ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ++ ++ Sam Lantinga ++ slouken@libsdl.org ++*/ ++ ++#ifdef SAVE_RCSID ++static char rcsid = ++ "@(#) $Id: SDL_gapivideo.c,v 1.5 2004/02/29 21:54:11 lemure Exp $"; ++#endif ++ ++/* Dummy SDL video driver implementation; this is just enough to make an ++ * SDL-based application THINK it's got a working video driver, for ++ * applications that call SDL_Init(SDL_INIT_VIDEO) when they don't need it, ++ * and also for use as a collection of stubs when porting SDL to a new ++ * platform for which you haven't yet written a valid video driver. ++ * ++ * This is also a great way to determine bottlenecks: if you think that SDL ++ * is a performance problem for a given platform, enable this driver, and ++ * then see if your application runs faster without video overhead. ++ * ++ * Initial work by Ryan C. Gordon (icculus@linuxgames.com). A good portion ++ * of this was cut-and-pasted from Stephane Peter's work in the AAlib ++ * SDL video driver. Renamed to "DUMMY" by Sam Lantinga. ++ */ ++ ++#include ++#include ++#include ++#include ++ ++/* Not yet in the mingw32 cross-compile headers */ ++#ifndef CDS_FULLSCREEN ++#define CDS_FULLSCREEN 4 ++#endif ++ ++#ifndef WS_THICKFRAME ++#define WS_THICKFRAME 0 ++#endif ++ ++#include "SDL.h" ++#include "SDL_mutex.h" ++#include "SDL_syswm.h" ++#include "SDL_sysvideo.h" ++#include "SDL_sysevents.h" ++#include "SDL_events_c.h" ++#include "SDL_pixels_c.h" ++#include "SDL_syswm_c.h" ++#include "SDL_sysmouse_c.h" ++#include "SDL_dibevents_c.h" ++#include "SDL_gapivideo.h" ++ ++#if defined(WIN32_PLATFORM_PSPC) ++#include // Add Pocket PC includes ++#pragma comment( lib, "aygshell" ) // Link Pocket PC library ++#endif ++ ++#ifdef _WIN32_WCE ++extern void DIB_ShowTaskBar(BOOL taskBarShown); ++#endif ++ ++ ++/* Initialization/Query functions */ ++static int GAPI_VideoInit(_THIS, SDL_PixelFormat *vformat); ++static SDL_Rect **GAPI_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags); ++static SDL_Surface *GAPI_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags); ++static int GAPI_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors); ++static void GAPI_VideoQuit(_THIS); ++ ++ ++/* Hardware surface functions */ ++static int GAPI_AllocHWSurface(_THIS, SDL_Surface *surface); ++static int GAPI_LockHWSurface(_THIS, SDL_Surface *surface); ++static void GAPI_UnlockHWSurface(_THIS, SDL_Surface *surface); ++static void GAPI_FreeHWSurface(_THIS, SDL_Surface *surface); ++ ++/* Windows message handling functions, will not be processed */ ++static void GAPI_RealizePalette(_THIS); ++static void GAPI_PaletteChanged(_THIS, HWND window); ++static void GAPI_WinPAINT(_THIS, HDC hdc); ++ ++static void GAPI_UpdateRects(_THIS, int numrects, SDL_Rect *rects); ++/*static void GAPI_UpdateRectsMono(_THIS, int numrects, SDL_Rect *rects);*/ ++ ++static int GAPI_Available(void); ++static SDL_VideoDevice *GAPI_CreateDevice(int devindex); ++ ++void GAPI_GrabHardwareKeys(BOOL grab); ++ ++VideoBootStrap WINGAPI_bootstrap = { ++ "wingapi", "WinCE GAPI", ++ GAPI_Available, GAPI_CreateDevice ++}; ++ ++/* 2003 SE GAPI emulation */ ++ ++#define GETRAWFRAMEBUFFER 0x00020001 ++ ++#define FORMAT_565 1 ++#define FORMAT_555 2 ++#define FORMAT_OTHER 3 ++ ++static void* _OzoneFrameBuffer = NULL; ++static struct GXDisplayProperties _OzoneDisplayProperties; ++static char _OzoneAvailable = 0; ++ ++typedef struct _RawFrameBufferInfo ++{ ++ WORD wFormat; ++ WORD wBPP; ++ VOID *pFramePointer; ++ int cxStride; ++ int cyStride; ++ int cxPixels; ++ int cyPixels; ++} RawFrameBufferInfo; ++ ++ ++struct GXDisplayProperties Ozone_GetDisplayProperties(void) { ++ return _OzoneDisplayProperties; ++} ++ ++int Ozone_OpenDisplay(HWND window, unsigned long flag) { ++ return 1; ++} ++ ++int Ozone_CloseDisplay(void) { ++ return 1; ++} ++ ++void* Ozone_BeginDraw(void) { ++ return _OzoneFrameBuffer; ++} ++ ++int Ozone_EndDraw(void) { ++ return 1; ++} ++ ++int Ozone_Suspend(void) { ++ return 1; ++} ++ ++int Ozone_Resume(void) { ++ return 1; ++} ++ ++static HINSTANCE checkOzone(tGXDisplayProperties *gxGetDisplayProperties, tGXOpenDisplay *gxOpenDisplay, ++ tGXVoidFunction *gxCloseDisplay, tGXBeginDraw *gxBeginDraw, ++ tGXVoidFunction *gxEndDraw, tGXVoidFunction *gxSuspend, tGXVoidFunction *gxResume) { ++#ifdef ARM ++ ++ int result; ++ RawFrameBufferInfo frameBufferInfo; ++ HDC hdc = GetDC(NULL); ++ result = ExtEscape(hdc, GETRAWFRAMEBUFFER, 0, NULL, sizeof(RawFrameBufferInfo), (char *)&frameBufferInfo); ++ ReleaseDC(NULL, hdc); ++ if (result < 0) ++ return NULL; ++ OutputDebugString(TEXT("Running on Ozone\r\n")); ++ _OzoneAvailable = 1; ++ ++ // Initializing global parameters ++ _OzoneFrameBuffer = frameBufferInfo.pFramePointer; ++ _OzoneDisplayProperties.cBPP = frameBufferInfo.wBPP; ++ _OzoneDisplayProperties.cbxPitch = frameBufferInfo.cxStride; ++ _OzoneDisplayProperties.cbyPitch = frameBufferInfo.cyStride; ++ _OzoneDisplayProperties.cxWidth = frameBufferInfo.cxPixels; ++ _OzoneDisplayProperties.cyHeight = frameBufferInfo.cyPixels; ++ if (frameBufferInfo.wFormat == FORMAT_565) ++ _OzoneDisplayProperties.ffFormat = kfDirect565; ++ else ++ if (frameBufferInfo.wFormat == FORMAT_555) ++ _OzoneDisplayProperties.ffFormat = kfDirect555; ++ else { ++ OutputDebugString(TEXT("Ozone unknown screen format")); ++ return NULL; ++ } ++ ++ if (gxGetDisplayProperties) ++ *gxGetDisplayProperties = Ozone_GetDisplayProperties; ++ if (gxOpenDisplay) ++ *gxOpenDisplay = Ozone_OpenDisplay; ++ if (gxCloseDisplay) ++ *gxCloseDisplay = Ozone_CloseDisplay; ++ if (gxBeginDraw) ++ *gxBeginDraw = Ozone_BeginDraw; ++ if (gxEndDraw) ++ *gxEndDraw = Ozone_EndDraw; ++ if (gxSuspend) ++ *gxSuspend = Ozone_Suspend; ++ if (gxResume) ++ *gxResume = Ozone_Resume; ++ ++ return (HINSTANCE)1; ++ ++#else ++ ++ return NULL; ++ ++#endif ++} ++ ++int getScreenWidth() { ++ return (_OzoneFrameBuffer ? _OzoneDisplayProperties.cxWidth : GetSystemMetrics(SM_CXSCREEN)); ++} ++ ++int getScreenHeight() { ++ return (_OzoneFrameBuffer ? _OzoneDisplayProperties.cyHeight : GetSystemMetrics(SM_CYSCREEN)); ++} ++ ++ ++/* Check GAPI library */ ++ ++#define IMPORT(Handle,Variable,Type,Function, Store) \ ++ Variable = GetProcAddress(Handle, TEXT(Function)); \ ++ if (!Variable) { \ ++ FreeLibrary(Handle); \ ++ return NULL; \ ++ } \ ++ if (Store) \ ++ *Store = (Type)Variable; ++ ++static HINSTANCE checkGAPI(tGXDisplayProperties *gxGetDisplayProperties, tGXOpenDisplay *gxOpenDisplay, ++ tGXVoidFunction *gxCloseDisplay, tGXBeginDraw *gxBeginDraw, ++ tGXVoidFunction *gxEndDraw, tGXVoidFunction *gxSuspend, tGXVoidFunction *gxResume, ++ BOOL bypassOzone) { ++ HMODULE gapiLibrary; ++ FARPROC proc; ++ HINSTANCE result; ++ // FIXME paletted ! ++ tGXDisplayProperties temp_gxGetDisplayProperties; ++ ++ // Workaround for Windows Mobile 2003 SE ++ _OzoneFrameBuffer = NULL; ++ if (!bypassOzone) { ++ result = checkOzone(gxGetDisplayProperties, gxOpenDisplay, gxCloseDisplay, gxBeginDraw, gxEndDraw, gxSuspend, gxResume); ++ if (result) ++ return result; ++ } ++ ++ gapiLibrary = LoadLibrary(TEXT("gx.dll")); ++ if (!gapiLibrary) ++ return NULL; ++ ++ IMPORT(gapiLibrary, proc, tGXDisplayProperties, "?GXGetDisplayProperties@@YA?AUGXDisplayProperties@@XZ", gxGetDisplayProperties) ++ IMPORT(gapiLibrary, proc, tGXOpenDisplay, "?GXOpenDisplay@@YAHPAUHWND__@@K@Z", gxOpenDisplay) ++ IMPORT(gapiLibrary, proc, tGXVoidFunction, "?GXCloseDisplay@@YAHXZ", gxCloseDisplay) ++ IMPORT(gapiLibrary, proc, tGXBeginDraw, "?GXBeginDraw@@YAPAXXZ", gxBeginDraw) ++ IMPORT(gapiLibrary, proc, tGXVoidFunction, "?GXEndDraw@@YAHXZ", gxEndDraw) ++ IMPORT(gapiLibrary, proc, tGXVoidFunction, "?GXSuspend@@YAHXZ", gxSuspend) ++ IMPORT(gapiLibrary, proc, tGXVoidFunction, "?GXResume@@YAHXZ", gxResume) ++ ++ // FIXME paletted ! for the moment we just bail out ++ if (!gxGetDisplayProperties) { ++ IMPORT(gapiLibrary, proc, tGXDisplayProperties, "?GXGetDisplayProperties@@YA?AUGXDisplayProperties@@XZ", &temp_gxGetDisplayProperties) ++ if (temp_gxGetDisplayProperties().ffFormat & kfPalette) { ++ FreeLibrary(gapiLibrary); ++ return NULL; ++ } ++ FreeLibrary(gapiLibrary); ++ gapiLibrary = (HINSTANCE)1; ++ } ++ ++ return gapiLibrary; ++} ++ ++ ++/* GAPI driver bootstrap functions */ ++ ++static int GAPI_Available(void) ++{ ++ /* Check if the GAPI library is available */ ++ ++ if (!checkGAPI(NULL, NULL, NULL, NULL, NULL, NULL, NULL, FALSE)) { ++ OutputDebugString(TEXT("GAPI driver not available\r\n")); ++ return 0; ++ } ++ else { ++ OutputDebugString(TEXT("GAPI driver available\r\n")); ++ return 1; ++ } ++} ++ ++static void GAPI_DeleteDevice(SDL_VideoDevice *device) ++{ ++ if (device && device->hidden && device->hidden->gapiFuncs.dynamicGXCloseDisplay) ++ device->hidden->gapiFuncs.dynamicGXCloseDisplay(); ++ ++ if (device && device->hidden) ++ free(device->hidden); ++ if (device) ++ free(device); ++ ++} ++ ++static SDL_VideoDevice *GAPI_CreateDevice(int devindex) ++{ ++ SDL_VideoDevice *device; ++ ++ /* Initialize all variables that we clean on shutdown */ ++ device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice)); ++ if ( device ) { ++ memset(device, 0, (sizeof *device)); ++ device->hidden = (struct SDL_PrivateVideoData *) ++ malloc((sizeof *device->hidden)); ++ } ++ if ( (device == NULL) || (device->hidden == NULL) ) { ++ SDL_OutOfMemory(); ++ if ( device ) { ++ free(device); ++ } ++ return(0); ++ } ++ memset(device->hidden, 0, (sizeof *device->hidden)); ++ ++ /* Set GAPI pointers */ ++ ++ checkGAPI(&device->hidden->gapiFuncs.dynamicGXGetDisplayProperties, ++ &device->hidden->gapiFuncs.dynamicGXOpenDisplay, ++ &device->hidden->gapiFuncs.dynamicGXCloseDisplay, ++ &device->hidden->gapiFuncs.dynamicGXBeginDraw, ++ &device->hidden->gapiFuncs.dynamicGXEndDraw, ++ &device->hidden->gapiFuncs.dynamicGXSuspend, ++ &device->hidden->gapiFuncs.dynamicGXResume, ++ FALSE); ++ device->hidden->displayProps = device->hidden->gapiFuncs.dynamicGXGetDisplayProperties(); ++ ++ /* Set the function pointers */ ++ ++ device->VideoInit = GAPI_VideoInit; ++ device->ListModes = GAPI_ListModes; ++ device->SetVideoMode = GAPI_SetVideoMode; ++ device->UpdateMouse = WIN_UpdateMouse; ++ device->SetColors = GAPI_SetColors; ++ device->UpdateRects = NULL; ++ device->VideoQuit = GAPI_VideoQuit; ++ device->AllocHWSurface = GAPI_AllocHWSurface; ++ device->CheckHWBlit = NULL; ++ device->FillHWRect = NULL; ++ device->SetHWColorKey = NULL; ++ device->SetHWAlpha = NULL; ++ device->LockHWSurface = GAPI_LockHWSurface; ++ device->UnlockHWSurface = GAPI_UnlockHWSurface; ++ device->FlipHWSurface = NULL; ++ device->FreeHWSurface = GAPI_FreeHWSurface; ++ device->SetCaption = WIN_SetWMCaption; ++ device->SetIcon = WIN_SetWMIcon; ++ device->IconifyWindow = WIN_IconifyWindow; ++ device->GrabInput = WIN_GrabInput; ++ device->GetWMInfo = WIN_GetWMInfo; ++ device->FreeWMCursor = WIN_FreeWMCursor; ++ device->CreateWMCursor = WIN_CreateWMCursor; ++ device->ShowWMCursor = WIN_ShowWMCursor; ++ device->WarpWMCursor = WIN_WarpWMCursor; ++ device->CheckMouseMode = WIN_CheckMouseMode; ++ device->InitOSKeymap = DIB_InitOSKeymap; ++ device->PumpEvents = DIB_PumpEvents; ++ ++ device->SetColors = GAPI_SetColors; ++ ++ /* Set up the windows message handling functions */ ++ WIN_RealizePalette = GAPI_RealizePalette; ++ WIN_PaletteChanged = GAPI_PaletteChanged; ++ WIN_WinPAINT = GAPI_WinPAINT; ++ HandleMessage = DIB_HandleMessage; ++ ++ device->free = GAPI_DeleteDevice; ++ ++ ++ /* ++ device->VideoInit = GAPI_VideoInit; ++ device->ListModes = GAPI_ListModes; ++ device->SetVideoMode = GAPI_SetVideoMode; ++ device->CreateYUVOverlay = NULL; ++ device->SetColors = DUMMY_SetColors; ++ device->UpdateRects = DUMMY_UpdateRects; ++ device->VideoQuit = DUMMY_VideoQuit; ++ device->AllocHWSurface = DUMMY_AllocHWSurface; ++ device->CheckHWBlit = NULL; ++ device->FillHWRect = NULL; ++ device->SetHWColorKey = NULL; ++ device->SetHWAlpha = NULL; ++ device->LockHWSurface = DUMMY_LockHWSurface; ++ device->UnlockHWSurface = DUMMY_UnlockHWSurface; ++ device->FlipHWSurface = NULL; ++ device->FreeHWSurface = DUMMY_FreeHWSurface; ++ device->SetCaption = NULL; ++ device->SetIcon = NULL; ++ device->IconifyWindow = NULL; ++ device->GrabInput = NULL; ++ device->GetWMInfo = NULL; ++ device->InitOSKeymap = DUMMY_InitOSKeymap; ++ device->PumpEvents = DUMMY_PumpEvents; ++ ++ device->free = DUMMY_DeleteDevice; ++ */ ++ ++ return device; ++} ++ ++ ++int GAPI_VideoInit(_THIS, SDL_PixelFormat *vformat) ++{ ++ ++ /* Create the window */ ++ if ( DIB_CreateWindow(this) < 0 ) { ++ return(-1); ++ } ++ ++ vformat->BitsPerPixel = (unsigned char)displayProperties.cBPP; ++ ++ // Get color mask ++ if (displayProperties.ffFormat & kfDirect565) { ++ vformat->BitsPerPixel = 16; ++ vformat->Rmask = 0x0000f800; ++ vformat->Gmask = 0x000007e0; ++ vformat->Bmask = 0x0000001f; ++ videoMode = GAPI_DIRECT_565; ++ } ++ else ++ if (displayProperties.ffFormat & kfDirect555) { ++ vformat->BitsPerPixel = 16; ++ vformat->Rmask = 0x00007c00; ++ vformat->Gmask = 0x000003e0; ++ vformat->Bmask = 0x0000001f; ++ videoMode = GAPI_DIRECT_555; ++ } ++ else ++ if ((displayProperties.ffFormat & kfDirect) && (displayProperties.cBPP <= 8)) { ++ // We'll perform the conversion ++ vformat->BitsPerPixel = 24; ++ vformat->Rmask = 0x00ff0000; ++ vformat->Gmask = 0x0000ff00; ++ vformat->Bmask = 0x000000ff; ++ if (displayProperties.ffFormat & kfDirectInverted) ++ invert = (1 << displayProperties.cBPP) - 1; ++ colorscale = displayProperties.cBPP < 8 ? 8 - displayProperties.cBPP : 0; ++ videoMode = GAPI_MONO; ++ } ++ else ++ if (displayProperties.ffFormat & kfPalette) { ++ videoMode = GAPI_PALETTE; ++ } ++ ++ /* Set UpdateRect callback */ ++ // FIXME ++ /* ++ if (videoMode != GAPI_MONO) ++ this->UpdateRects = GAPI_UpdateRects; ++ else ++ this->UpdateRects = GAPI_UpdateRectsMono; ++ */ ++ ++ this->UpdateRects = GAPI_UpdateRects; ++ ++ /* We're done! */ ++ return(0); ++} ++ ++SDL_Rect **GAPI_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) ++{ ++ return (SDL_Rect **) -1; ++} ++ ++SDL_Surface *GAPI_SetVideoMode(_THIS, SDL_Surface *current, ++ int width, int height, int bpp, Uint32 flags) ++{ ++ SDL_Surface *video; ++ Uint32 Rmask, Gmask, Bmask; ++ Uint32 prev_flags; ++ DWORD style; ++ const DWORD directstyle = ++ (WS_POPUP); ++ const DWORD windowstyle = ++ (WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX); ++ const DWORD resizestyle = ++ (WS_THICKFRAME|WS_MAXIMIZEBOX); ++ int screenWidth, screenHeight; ++ BOOL was_visible; ++ ++ /* We negociate legacy GAPI if we want a screen that fits in QVGA */ ++ if (_OzoneAvailable && _OzoneFrameBuffer && (width <= GetSystemMetrics(SM_CXSCREEN) || width <= GetSystemMetrics(SM_CYSCREEN)) && ++ (height <= GetSystemMetrics(SM_CXSCREEN) || height <= GetSystemMetrics(SM_CYSCREEN))) { ++ OutputDebugString(TEXT("Ozone workaround, switching back to GAPI\r\n")); ++ ozoneHack = 0; ++ checkGAPI(&this->hidden->gapiFuncs.dynamicGXGetDisplayProperties, ++ &this->hidden->gapiFuncs.dynamicGXOpenDisplay, ++ &this->hidden->gapiFuncs.dynamicGXCloseDisplay, ++ &this->hidden->gapiFuncs.dynamicGXBeginDraw, ++ &this->hidden->gapiFuncs.dynamicGXEndDraw, ++ &this->hidden->gapiFuncs.dynamicGXSuspend, ++ &this->hidden->gapiFuncs.dynamicGXResume, ++ TRUE); ++ this->hidden->displayProps = this->hidden->gapiFuncs.dynamicGXGetDisplayProperties(); ++ } ++ /* Otherwise we'll use the new system call */ ++ if (_OzoneAvailable && !_OzoneFrameBuffer && (width > GetSystemMetrics(SM_CXSCREEN) && width > GetSystemMetrics(SM_CYSCREEN)) && ++ (height > GetSystemMetrics(SM_CXSCREEN) && height > GetSystemMetrics(SM_CYSCREEN))) { ++ OutputDebugString(TEXT("Ozone workaround, switching back to true Ozone\r\n")); ++ checkGAPI(&this->hidden->gapiFuncs.dynamicGXGetDisplayProperties, ++ &this->hidden->gapiFuncs.dynamicGXOpenDisplay, ++ &this->hidden->gapiFuncs.dynamicGXCloseDisplay, ++ &this->hidden->gapiFuncs.dynamicGXBeginDraw, ++ &this->hidden->gapiFuncs.dynamicGXEndDraw, ++ &this->hidden->gapiFuncs.dynamicGXSuspend, ++ &this->hidden->gapiFuncs.dynamicGXResume, ++ FALSE); ++ this->hidden->displayProps = this->hidden->gapiFuncs.dynamicGXGetDisplayProperties(); ++ } ++ /* Which will need a tiny input hack if the original code does not have the "Hi Res" aware ressource property set */ ++ ozoneHack = 0; ++ if (_OzoneFrameBuffer && (GetSystemMetrics(SM_CXSCREEN) != (signed) _OzoneDisplayProperties.cxWidth || ++ GetSystemMetrics(SM_CYSCREEN) != (signed) _OzoneDisplayProperties.cyHeight)) { ++ OutputDebugString(TEXT("Running true Ozone with stylus hack\r\n")); ++ ozoneHack = 1; ++ } ++ ++ /* See whether or not we should center the window */ ++ was_visible = IsWindowVisible(SDL_Window); ++ ++ /* Recalculate bitmasks if necessary */ ++ if (bpp == current->format->BitsPerPixel) { ++ video = current; ++ } ++ else { ++ switch(bpp) { ++ case 8: ++ Rmask = 0; ++ Gmask = 0; ++ Bmask = 0; ++ break; ++ case 15: ++ case 16: ++ /* Default is 565 unless the display is specifically 555 */ ++ if (displayProperties.ffFormat & kfDirect555) { ++ Rmask = 0x00007c00; ++ Gmask = 0x000003e0; ++ Bmask = 0x0000001f; ++ } ++ else { ++ Rmask = 0x0000f800; ++ Gmask = 0x000007e0; ++ Bmask = 0x0000001f; ++ } ++ break; ++ case 24: ++ case 32: ++ Rmask = 0x00ff0000; ++ Gmask = 0x0000ff00; ++ Bmask = 0x000000ff; ++ break; ++ default: ++ SDL_SetError("Unsupported Bits Per Pixel format requested"); ++ return NULL; ++ } ++ video = SDL_CreateRGBSurface(SDL_SWSURFACE, ++ 0, 0, bpp, Rmask, Gmask, Bmask, 0); ++ if ( video == NULL ) { ++ SDL_OutOfMemory(); ++ return(NULL); ++ } ++ } ++ ++ /* Fill in part of the video surface */ ++ prev_flags = video->flags; ++ video->flags = 0; /* Clear flags */ ++ video->w = width; ++ video->h = height; ++ video->pitch = SDL_CalculatePitch(video); ++ mainSurfaceWidth = width; ++ mainSurfaceHeight = height; ++ ++//#ifdef WIN32_PLATFORM_PSPC ++ /* Hide taskbar */ ++ if ( flags & SDL_FULLSCREEN ) { ++ if ( !(prev_flags & SDL_FULLSCREEN) ) { ++ //SHFullScreen(SDL_Window, SHFS_HIDETASKBAR | SHFS_HIDESIPBUTTON | SHFS_HIDESTARTICON); ++ //ShowWindow(FindWindow(TEXT("HHTaskBar"),NULL),SW_HIDE); ++ DIB_ShowTaskBar(FALSE); ++ } ++ video->flags |= SDL_FULLSCREEN; ++ } else { ++ if ( prev_flags & SDL_FULLSCREEN ) { ++ //SHFullScreen(SDL_Window, SHFS_SHOWTASKBAR | SHFS_SHOWSIPBUTTON | SHFS_SHOWSTARTICON); ++ //ShowWindow(FindWindow(TEXT("HHTaskBar"),NULL),SW_SHOWNORMAL); ++ DIB_ShowTaskBar(TRUE); ++ } ++ } ++//#endif ++ ++ /* Reset the palette and create a new one if necessary */ ++ if (screenPal != NULL) { ++ DeleteObject(screenPal); ++ screenPal = NULL; ++ } ++ ++ /* See if we need to create a translation palette */ ++ if (convertPalette != NULL) { ++ free(convertPalette); ++ } ++ if (bpp == 8) { ++ OutputDebugString(TEXT("creating palette\r\n")); ++ convertPalette = (unsigned short*)malloc(256 * sizeof(unsigned short)); ++ } ++ ++ if (displayProperties.ffFormat & kfPalette) { ++ /* Will only be able to support 256 colors in this mode */ ++ // FIXME ++ //screenPal = GAPI_CreatePalette(); ++ } ++ ++ /* Set Window style */ ++ style = GetWindowLong(SDL_Window, GWL_STYLE); ++ if ( (video->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { ++ style &= ~windowstyle; ++ style |= directstyle; ++ } else { ++ if ( flags & SDL_NOFRAME ) { ++ style &= ~windowstyle; ++ style |= directstyle; ++ video->flags |= SDL_NOFRAME; ++ } else { ++ style &= ~directstyle; ++ style |= windowstyle; ++ if ( flags & SDL_RESIZABLE ) { ++ style |= resizestyle; ++ video->flags |= SDL_RESIZABLE; ++ } ++ } ++#if WS_MAXIMIZE ++ if (IsZoomed(SDL_Window)) style |= WS_MAXIMIZE; ++#endif ++ } ++ ++ if (!SDL_windowid) ++ SetWindowLong(SDL_Window, GWL_STYLE, style); ++ ++ /* Allocate bitmap */ ++ if (gapiBuffer) { ++ free(gapiBuffer); ++ gapiBuffer = NULL; ++ } ++ gapiBuffer = malloc(video->h * video->pitch); ++ video->pixels = gapiBuffer; ++ ++ /* See if we will rotate */ ++ rotation = SDL_ROTATE_NONE; ++ screenWidth = getScreenWidth(); ++ screenHeight = getScreenHeight(); ++ if ((flags & SDL_FULLSCREEN) && ++ (width > screenWidth && width <= screenHeight) ++ ) ++ { ++ rotation = SDL_ROTATE_LEFT; ++ } ++ /* Compute the different drawing properties */ ++ switch(rotation) { ++ case SDL_ROTATE_NONE: ++ dstPixelstep = displayProperties.cbxPitch; ++ dstLinestep = displayProperties.cbyPitch; ++ startOffset = 0; ++ break; ++ case SDL_ROTATE_LEFT: ++ dstPixelstep = -displayProperties.cbyPitch; ++ dstLinestep = displayProperties.cbxPitch; ++ startOffset = displayProperties.cbyPitch * (displayProperties.cyHeight - 1); ++ break; ++ case SDL_ROTATE_RIGHT: ++ dstPixelstep = displayProperties.cbyPitch; ++ dstLinestep = -displayProperties.cbxPitch; ++ startOffset = displayProperties.cbxPitch * (displayProperties.cxWidth - 1); ++ break; ++ } ++ /* Compute padding */ ++ padWidth = 0; ++ padHeight = 0; ++ if (rotation == SDL_ROTATE_NONE) { ++ if (getScreenWidth() > width) ++ padWidth = (getScreenWidth() - width) / 2; ++ if (getScreenHeight() > height) ++ padHeight = (getScreenHeight() - height) / 2; ++ } ++ else { ++ if (getScreenWidth() > height) ++ padWidth = (getScreenWidth() - height) / 2; ++ if (getScreenHeight() > width) ++ padHeight = (getScreenHeight() - width) / 2; ++ } ++ srcLinestep = video->pitch; ++ srcPixelstep = (bpp == 15 ? 2 : bpp / 8); ++ ++ MoveWindow(SDL_Window, 0, 0, getScreenWidth(), getScreenHeight(), FALSE); ++ ShowWindow(SDL_Window, SW_SHOW); ++ ++ /* Resize the window */ ++ //if ( SDL_windowid == NULL ) { ++ if (0) { ++ HWND top; ++ UINT swp_flags; ++ RECT bounds; ++ int x,y; ++ ++ SDL_resizing = 1; ++ bounds.left = 0; ++ bounds.top = 0; ++ bounds.right = video->w; ++ bounds.bottom = video->h; ++ AdjustWindowRectEx(&bounds, GetWindowLong(SDL_Window, GWL_STYLE), FALSE, 0); ++ width = bounds.right-bounds.left; ++ height = bounds.bottom-bounds.top; ++ x = (getScreenWidth()-width)/2; ++ y = (getScreenHeight()-height)/2; ++ if ( y < 0 ) { /* Cover up title bar for more client area */ ++ y -= GetSystemMetrics(SM_CYCAPTION)/2; ++ } ++ swp_flags = (SWP_FRAMECHANGED | SWP_SHOWWINDOW); ++ if ( was_visible && !(flags & SDL_FULLSCREEN) ) { ++ swp_flags |= SWP_NOMOVE; ++ } ++ if ( flags & SDL_FULLSCREEN ) { ++ top = HWND_TOPMOST; ++ } else { ++ top = HWND_NOTOPMOST; ++ } ++ ++ if (flags & SDL_FULLSCREEN) { ++ SetWindowPos(SDL_Window, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); ++ ShowWindow(SDL_Window, SW_SHOW); ++ } ++ else ++ SetWindowPos(SDL_Window, top, x, y, width, height, swp_flags); ++ ++ SDL_resizing = 0; ++ SetForegroundWindow(SDL_Window); ++ } ++ ++ /* Open GAPI display */ ++ GXOpenDisplay(SDL_Window, (flags & SDL_FULLSCREEN ? GX_FULLSCREEN : 0)); ++ ++ /* Grab hardware keys if necessary */ ++ if (flags & SDL_FULLSCREEN) ++ GAPI_GrabHardwareKeys(TRUE); ++ ++ /* Blank screen */ ++ memset(GXBeginDraw(), 0, getScreenWidth() * getScreenHeight() * 2); ++ GXEndDraw(); ++ ++ /* We're done */ ++ return(video); ++} ++ ++/* We don't actually allow hardware surfaces other than the main one */ ++static int GAPI_AllocHWSurface(_THIS, SDL_Surface *surface) ++{ ++ return(-1); ++} ++static void GAPI_FreeHWSurface(_THIS, SDL_Surface *surface) ++{ ++ return; ++} ++ ++/* We need to wait for vertical retrace on page flipped displays */ ++static int GAPI_LockHWSurface(_THIS, SDL_Surface *surface) ++{ ++ return(0); ++} ++ ++static void GAPI_UnlockHWSurface(_THIS, SDL_Surface *surface) ++{ ++ return; ++} ++ ++static void updateLine(_THIS, unsigned char *srcPointer, unsigned char *destPointer, int width) { ++ // FIXME, we assume everything is in the correct format, either 16 bits 565 or 555, or 8 bits ++ int i; ++ for (i=0; i= 8) \ ++ { \ ++ bitshift = 0; \ ++ bitmask = (1<>= displayProperties.cBPP; ++ ++ ++static void GAPI_UpdateRectsMono(_THIS, int numrects, SDL_Rect *rects) ++{ ++ int i; ++ unsigned char *screenBuffer; ++ ++ screenBuffer = GXBeginDraw(); ++ ++ for (i=0; i>3)) ++ ++#define COLORCONV555(r,g,b) (((r&0xf8)<<(10-3))|((g&0xf8)<<(5-2))|((b&0xf8)>>3)) ++ ++int GAPI_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) ++{ ++ int i; ++ /* Convert colors to appropriate 565 or 555 mapping */ ++ for (i=0; ipixels) */ ++ if ( this->screen ) { ++//#ifdef WIN32_PLATFORM_PSPC ++ if ( this->screen->flags & SDL_FULLSCREEN ) { ++ /* Unhide taskbar, etc. */ ++ //SHFullScreen(SDL_Window, SHFS_SHOWTASKBAR | SHFS_SHOWSIPBUTTON | SHFS_SHOWSTARTICON); ++ //ShowWindow(FindWindow(TEXT("HHTaskBar"),NULL),SW_SHOWNORMAL); ++ DIB_ShowTaskBar(TRUE); ++ GAPI_GrabHardwareKeys(FALSE); ++ } ++//#endif ++ ++ if (this->screen->pixels != NULL) ++ { ++ free(this->screen->pixels); ++ this->screen->pixels = NULL; ++ } ++ ++ if (GXCloseDisplay) ++ GXCloseDisplay(); ++ } ++ } ++} ++ ++void GAPI_GrabHardwareKeys(BOOL grab) { ++ HINSTANCE GAPI_handle; ++ tGXVoidFunction GAPIActionInput; ++ ++ GAPI_handle = LoadLibrary(TEXT("gx.dll")); ++ if (!GAPI_handle) ++ return; ++ GAPIActionInput = (tGXVoidFunction)GetProcAddress(GAPI_handle, (grab ? TEXT("?GXOpenInput@@YAHXZ") : TEXT("?GXCloseInput@@YAHXZ"))); ++ if (GAPIActionInput) { ++ GAPIActionInput(); ++ } ++ FreeLibrary(GAPI_handle); ++} +diff -ruN SDL-1.2.7-orig/src/video/wingapi/SDL_gapivideo.h SDL-1.2.7/src/video/wingapi/SDL_gapivideo.h +--- SDL-1.2.7-orig/src/video/wingapi/SDL_gapivideo.h Wed Dec 31 19:00:00 1969 ++++ SDL-1.2.7/src/video/wingapi/SDL_gapivideo.h Sun May 30 17:57:48 2004 +@@ -0,0 +1,192 @@ ++/* ++ SDL - Simple DirectMedia Layer ++ Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Sam Lantinga ++ ++ This library is free software; you can redistribute it and/or ++ modify it under the terms of the GNU Library General Public ++ License as published by the Free Software Foundation; either ++ version 2 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 ++ Library General Public License for more details. ++ ++ You should have received a copy of the GNU Library General Public ++ License along with this library; if not, write to the Free ++ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ++ ++ Sam Lantinga ++ slouken@libsdl.org ++*/ ++ ++#ifdef SAVE_RCSID ++static char rcsid = ++ "@(#) $Id: SDL_gapivideo.h,v 1.1 2004/02/02 23:25:35 lemure Exp $"; ++#endif ++ ++#ifndef _SDL_gapivideo_h ++#define _SDL_gapivideo_h ++ ++#include ++ ++/* -------------------------------------------------------------------------------------------- */ ++ ++/* From gx.h, since it's not really C compliant */ ++ ++struct GXDisplayProperties { ++ DWORD cxWidth; ++ DWORD cyHeight; // notice lack of 'th' in the word height. ++ long cbxPitch; // number of bytes to move right one x pixel - can be negative. ++ long cbyPitch; // number of bytes to move down one y pixel - can be negative. ++ long cBPP; // # of bits in each pixel ++ DWORD ffFormat; // format flags. ++}; ++ ++struct GXKeyList { ++ short vkUp; // key for up ++ POINT ptUp; // x,y position of key/button. Not on screen but in screen coordinates. ++ short vkDown; ++ POINT ptDown; ++ short vkLeft; ++ POINT ptLeft; ++ short vkRight; ++ POINT ptRight; ++ short vkA; ++ POINT ptA; ++ short vkB; ++ POINT ptB; ++ short vkC; ++ POINT ptC; ++ short vkStart; ++ POINT ptStart; ++}; ++ ++#define kfLandscape 0x8 // Screen is rotated 270 degrees ++#define kfPalette 0x10 // Pixel values are indexes into a palette ++#define kfDirect 0x20 // Pixel values contain actual level information ++#define kfDirect555 0x40 // 5 bits each for red, green and blue values in a pixel. ++#define kfDirect565 0x80 // 5 red bits, 6 green bits and 5 blue bits per pixel ++#define kfDirect888 0x100 // 8 bits each for red, green and blue values in a pixel. ++#define kfDirect444 0x200 // 4 red, 4 green, 4 blue ++#define kfDirectInverted 0x400 ++ ++#define GX_FULLSCREEN 0x01 // for OpenDisplay() ++ ++/* -------------------------------------------------------------------------------------------- */ ++ ++/* Rotation direction */ ++typedef enum { ++ SDL_ROTATE_NONE, ++ SDL_ROTATE_LEFT, ++ SDL_ROTATE_RIGHT ++} SDL_RotateAttr; ++ ++/* GAPI video mode */ ++typedef enum { ++ GAPI_NONE = 0, ++ GAPI_DIRECT_565, ++ GAPI_DIRECT_555, ++ GAPI_MONO, ++ GAPI_PALETTE ++} SDL_GAPIVideoMode; ++ ++ ++/* Hidden "this" pointer for the video functions */ ++#define _THIS SDL_VideoDevice *this ++ ++/* GAPI functions definitions */ ++ ++typedef struct GXDisplayProperties (*tGXDisplayProperties)(void); ++typedef int (*tGXOpenDisplay)(HWND, unsigned long); ++typedef void* (*tGXBeginDraw)(void); ++typedef int (*tGXVoidFunction)(void); ++ ++/* Private display data */ ++ ++struct GAPI_funcs { ++ tGXDisplayProperties dynamicGXGetDisplayProperties; ++ tGXOpenDisplay dynamicGXOpenDisplay; ++ tGXVoidFunction dynamicGXCloseDisplay; ++ tGXBeginDraw dynamicGXBeginDraw; ++ tGXVoidFunction dynamicGXEndDraw; ++ tGXVoidFunction dynamicGXSuspend; ++ tGXVoidFunction dynamicGXResume; ++}; ++ ++struct GAPI_properties { ++ unsigned char invert; ++ int colorscale; ++ int dstPixelstep; ++ int dstLinestep; ++ int startOffset; ++ SDL_GAPIVideoMode videoMode; ++}; ++ ++#define MAX_CLR 0x100 ++ ++struct palette_properties { ++ unsigned char *palRed; ++ unsigned char *palGreen; ++ unsigned char *palBlue; ++ unsigned short *pal; ++}; ++ ++ ++struct SDL_PrivateVideoData { ++ /* --- --- begin with DIB private structure to allow DIB events code sharing */ ++ HBITMAP screen_bmp; ++ HPALETTE screen_pal; ++ void *work_pixels; /* if the display needs to be rotated, memory allocated by the API */ ++ void *rotation_pixels; /* if the display needs to be rotated, memory allocated by the code */ ++ SDL_RotateAttr rotation; ++ char ozoneHack; /* force stylus translation if running without Hi Res flag */ ++ ++#define NUM_MODELISTS 4 /* 8, 16, 24, and 32 bits-per-pixel */ ++ int SDL_nummodes[NUM_MODELISTS]; ++ SDL_Rect **SDL_modelist[NUM_MODELISTS]; ++ ++ /* --- --- */ ++ ++ int w, h; ++ void *gapiBuffer; ++ HPALETTE screenPal; ++ struct GAPI_funcs gapiFuncs; ++ struct GAPI_properties gapiProperties; ++ struct GXDisplayProperties displayProps; ++ int srcLinestep; ++ int srcPixelstep; ++ ++ int padWidth; ++ int padHeight; ++ ++ unsigned short *convertPalette; ++}; ++ ++#define gapiBuffer (this->hidden->gapiBuffer) ++#define mainSurfaceWidth (this->hidden->w) ++#define mainSurfaceHeight (this->hidden->h) ++#define rotation (this->hidden->rotation) ++#define ozoneHack (this->hidden->ozoneHack) ++#define displayProperties (this->hidden->displayProps) ++#define screenPal (this->hidden->screenPal) ++#define GXGetDisplayProperties (this->hidden->gapiFuncs.dynamicGXGetDisplayProperties) ++#define GXOpenDisplay (this->hidden->gapiFuncs.dynamicGXOpenDisplay) ++#define GXCloseDisplay (this->hidden->gapiFuncs.dynamicGXCloseDisplay) ++#define GXBeginDraw (this->hidden->gapiFuncs.dynamicGXBeginDraw) ++#define GXEndDraw (this->hidden->gapiFuncs.dynamicGXEndDraw) ++#define GXSuspend (this->hidden->gapiFuncs.dynamicGXSuspend) ++#define GXResume (this->hidden->gapiFuncs.dynamicGXResume) ++#define invert (this->hidden->gapiProperties.invert) ++#define colorscale (this->hidden->gapiProperties.colorscale) ++#define videoMode (this->hidden->gapiProperties.videoMode) ++#define srcPixelstep (this->hidden->srcPixelstep) ++#define srcLinestep (this->hidden->srcLinestep) ++#define dstPixelstep (this->hidden->gapiProperties.dstPixelstep) ++#define dstLinestep (this->hidden->gapiProperties.dstLinestep) ++#define startOffset (this->hidden->gapiProperties.startOffset) ++#define padWidth (this->hidden->padWidth) ++#define padHeight (this->hidden->padHeight) ++#define convertPalette (this->hidden->convertPalette) ++ ++#endif /* _SDL_gapivideo_h */ diff --git a/tools/SDL1.2.7_CE/VisualCEv2.zip b/tools/SDL1.2.7_CE/VisualCEv2.zip new file mode 100644 index 000000000..816382e3b Binary files /dev/null and b/tools/SDL1.2.7_CE/VisualCEv2.zip differ diff --git a/tools/SOCEdit/Global.bas b/tools/SOCEdit/Global.bas new file mode 100644 index 000000000..77bf3df2b --- /dev/null +++ b/tools/SOCEdit/Global.bas @@ -0,0 +1,96 @@ +Attribute VB_Name = "Module1" +Option Explicit +Public SOCFile As String +Public SOCTemp As String +Public SourcePath As String + +Public Function FirstToken(ByVal line As String) + Dim index As Integer + + index = InStr(line, " ") - 1 + + If index < 1 Then + index = Len(line) + End If + + FirstToken = TrimComplete(Left(line, index)) +End Function + +Public Function SecondToken(ByVal line As String) + Dim startclip As Integer + Dim endclip As Integer + + startclip = InStr(line, " ") + + startclip = startclip + 1 + + SecondToken = TrimComplete(Mid(line, startclip, Len(line))) +End Function + +Public Function SecondTokenEqual(ByVal line As String) + Dim startclip As Integer + Dim endclip As Integer + + startclip = InStr(line, "=") + + startclip = startclip + 2 + + line = Mid(line, startclip, Len(line)) + + SecondTokenEqual = TrimComplete(line) +End Function + +Public Function TrimComplete(ByVal sValue As String) As String + Dim sAns As String + Dim sWkg As String + Dim sChar As String + Dim lLen As Long + Dim lCtr As Long + + sAns = sValue + lLen = Len(sValue) + + If lLen > 0 Then + 'Ltrim + For lCtr = 1 To lLen + sChar = Mid(sAns, lCtr, 1) + If Asc(sChar) > 32 Then Exit For + Next + + sAns = Mid(sAns, lCtr) + lLen = Len(sAns) + + 'Rtrim + If lLen > 0 Then + For lCtr = lLen To 1 Step -1 + sChar = Mid(sAns, lCtr, 1) + If Asc(sChar) > 32 Then Exit For + Next + End If + sAns = Left$(sAns, lCtr) + End If + + TrimComplete = sAns +End Function + +Public Function RTrimComplete(ByVal sValue As String) As String + Dim sAns As String + Dim sWkg As String + Dim sChar As String + Dim lLen As Long + Dim lCtr As Long + + sAns = sValue + lLen = Len(sValue) + + 'Rtrim + If lLen > 0 Then + For lCtr = lLen To 1 Step -1 + sChar = Mid(sAns, lCtr, 1) + If Asc(sChar) > 32 Then Exit For + Next + End If + sAns = Left$(sAns, lCtr) + + RTrimComplete = sAns +End Function diff --git a/tools/SOCEdit/SOCEdit.vbp b/tools/SOCEdit/SOCEdit.vbp new file mode 100644 index 000000000..90af0095a --- /dev/null +++ b/tools/SOCEdit/SOCEdit.vbp @@ -0,0 +1,53 @@ +Type=Exe +Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#..\..\..\WINNT\system32\stdole2.tlb#OLE Automation +Reference=*\G{420B2830-E718-11CF-893D-00A0C9054228}#1.0#0#..\..\..\WINNT\system32\scrrun.dll#Microsoft Scripting Runtime +Form=Things.frm +Module=Module1; Global.bas +Form=frmStateEdit.frm +Form=frmLevelHeader.frm +Form=frmHub.frm +Form=frmMaincfg.frm +Form=frmUnlockablesEdit.frm +Form=frmEmblemEdit.frm +Form=frmSoundEdit.frm +Form=frmCharacterEdit.frm +Form=frmCutsceneEdit.frm +Form=frmHelp.frm +Form=frmHUDEdit.frm +IconForm="frmThingEdit" +Startup="frmHub" +HelpFile="" +Title="SOC Editor" +ExeName32="SOCEdit.exe" +Path32="..\..\..\srb2demo2\SOCEdit" +Command32="" +Name="SOCEditor" +HelpContextID="0" +CompatibleMode="0" +MajorVer=0 +MinorVer=7 +RevisionVer=7 +AutoIncrementVer=0 +ServerSupportFiles=0 +VersionComments="http://www.srb2.org/" +VersionCompanyName="Sonic Team Junior" +VersionFileDescription="For SRB2 v1.09.4" +CompilationType=0 +OptimizationType=0 +FavorPentiumPro(tm)=0 +CodeViewDebugInfo=0 +NoAliasing=0 +BoundsCheck=0 +OverflowCheck=0 +FlPointCheck=0 +FDIVCheck=0 +UnroundedFP=0 +StartMode=0 +Unattended=0 +Retained=0 +ThreadPerObject=0 +MaxNumberOfThreads=1 +DebugStartupOption=0 + +[MS Transaction Server] +AutoRefresh=1 diff --git a/tools/SOCEdit/Things.frm b/tools/SOCEdit/Things.frm new file mode 100644 index 000000000..f95b6afb7 --- /dev/null +++ b/tools/SOCEdit/Things.frm @@ -0,0 +1,1895 @@ +VERSION 5.00 +Begin VB.Form frmThingEdit + Caption = "Thing Edit" + ClientHeight = 5745 + ClientLeft = 60 + ClientTop = 345 + ClientWidth = 11880 + Icon = "Things.frx":0000 + LinkTopic = "Form1" + MaxButton = 0 'False + ScaleHeight = 5745 + ScaleWidth = 11880 + StartUpPosition = 3 'Windows Default + Begin VB.CommandButton cmdCopy + Caption = "&Copy Thing" + Height = 615 + Left = 6600 + TabIndex = 77 + Top = 4920 + Width = 975 + End + Begin VB.CommandButton cmdLoadDefault + Caption = "&Load Code Default" + Height = 615 + Left = 4440 + Style = 1 'Graphical + TabIndex = 76 + Top = 4920 + Width = 975 + End + Begin VB.CommandButton cmdDelete + Caption = "&Delete Thing from SOC" + Height = 615 + Left = 3240 + Style = 1 'Graphical + TabIndex = 74 + Top = 4920 + Width = 1095 + End + Begin VB.CommandButton cmdSave + Caption = "&Save" + Height = 615 + Left = 5520 + TabIndex = 73 + Top = 4920 + Width = 975 + End + Begin VB.Frame frmFlags + Caption = "Flags" + Height = 3735 + Left = 7680 + TabIndex = 45 + Top = 1920 + Width = 4095 + Begin VB.CheckBox chkFlags + Caption = "MF_FIRE" + Height = 255 + Index = 26 + Left = 2040 + TabIndex = 72 + Tag = "4194304" + ToolTipText = "Fire object. Doesn't harm if you have red shield." + Top = 2160 + Width = 1695 + End + Begin VB.CheckBox chkFlags + Caption = "MF_NOCLIPTHING" + Height = 255 + Index = 25 + Left = 2040 + TabIndex = 71 + Tag = "1073741824" + ToolTipText = "Don't be blocked by things (partial clipping)" + Top = 3120 + Width = 1815 + End + Begin VB.CheckBox chkFlags + Caption = "MF_SCENERY" + Height = 255 + Index = 24 + Left = 2040 + TabIndex = 70 + Tag = "33554432" + ToolTipText = "Scenery (uses scenery thinker). Uses less CPU than a standard object, but generally can't move, etc." + Top = 2880 + Width = 1455 + End + Begin VB.CheckBox chkFlags + Caption = "MF_ENEMY" + Height = 255 + Index = 23 + Left = 2040 + TabIndex = 69 + Tag = "16777216" + ToolTipText = "This mobj is an enemy!" + Top = 2640 + Width = 1335 + End + Begin VB.CheckBox chkFlags + Caption = "MF_COUNTITEM" + Height = 255 + Index = 22 + Left = 2040 + TabIndex = 68 + Tag = "8388608" + ToolTipText = "On picking up, count this item object towards intermission item total." + Top = 2400 + Width = 1695 + End + Begin VB.CheckBox chkFlags + Caption = "MF_NOTHINK" + Height = 255 + Index = 21 + Left = 2040 + TabIndex = 67 + Tag = "2097152" + ToolTipText = "Don't run this thing's thinker." + Top = 1920 + Width = 1695 + End + Begin VB.CheckBox chkFlags + Caption = "MF_MONITOR" + Height = 255 + Index = 20 + Left = 2040 + TabIndex = 66 + Tag = "1048576" + ToolTipText = "Item box" + Top = 1680 + Width = 1575 + End + Begin VB.CheckBox chkFlags + Caption = "MF_HIRES" + Height = 255 + Index = 19 + Left = 2040 + TabIndex = 65 + Tag = "524288" + ToolTipText = "Object uses a high-resolution sprite" + Top = 1440 + Width = 1215 + End + Begin VB.CheckBox chkFlags + Caption = "MF_BOUNCE" + Height = 255 + Index = 18 + Left = 2040 + TabIndex = 64 + Tag = "262144" + ToolTipText = "Bounce off walls and things." + Top = 1200 + Width = 1335 + End + Begin VB.CheckBox chkFlags + Caption = "MF_SPRING" + Height = 255 + Index = 17 + Left = 2040 + TabIndex = 63 + Tag = "131072" + ToolTipText = "Item is a spring." + Top = 960 + Width = 1575 + End + Begin VB.CheckBox chkFlags + Caption = "MF_MISSILE" + Height = 255 + Index = 16 + Left = 2040 + TabIndex = 62 + Tag = "65536" + ToolTipText = "Any kind of projectile currently flying through the air, waiting to hit something" + Top = 720 + Width = 1335 + End + Begin VB.CheckBox chkFlags + Caption = "MF_BOXICON" + Height = 255 + Index = 15 + Left = 2040 + TabIndex = 61 + Tag = "32768" + ToolTipText = "Monitor powerup icon. These rise a bit." + Top = 480 + Width = 1815 + End + Begin VB.CheckBox chkFlags + Caption = "MF_FLOAT" + Height = 255 + Index = 14 + Left = 2040 + TabIndex = 60 + Tag = "16384" + ToolTipText = "Allow moves to any height, no gravity. For active floaters." + Top = 240 + Width = 1215 + End + Begin VB.CheckBox chkFlags + Caption = "MF_SPECIALFLAGS" + Height = 255 + Index = 13 + Left = 120 + TabIndex = 59 + Tag = "8192" + ToolTipText = "This object does not adhere to regular flag/z properties for object placing." + Top = 3360 + Width = 1815 + End + Begin VB.CheckBox chkFlags + Caption = "MF_NOCLIP" + Height = 255 + Index = 12 + Left = 120 + TabIndex = 58 + Tag = "4096" + ToolTipText = "Don't clip against objects, walls, etc." + Top = 3120 + Width = 1335 + End + Begin VB.CheckBox chkFlags + Caption = "MF_SLIDEME" + Height = 255 + Index = 11 + Left = 120 + TabIndex = 57 + Tag = "2048" + ToolTipText = "Slide this object when it hits a wall." + Top = 2880 + Width = 1335 + End + Begin VB.CheckBox chkFlags + Caption = "MF_AMBIENT" + Height = 255 + Index = 10 + Left = 120 + TabIndex = 56 + Tag = "1024" + ToolTipText = "This object is an ambient sound." + Top = 2640 + Width = 1695 + End + Begin VB.CheckBox chkFlags + Caption = "MF_NOGRAVITY" + Height = 255 + Index = 9 + Left = 120 + TabIndex = 55 + Tag = "512" + ToolTipText = "Don't apply gravity" + Top = 2400 + Width = 1695 + End + Begin VB.CheckBox chkFlags + Caption = "MF_SPAWNCEILING" + Height = 255 + Index = 8 + Left = 120 + TabIndex = 54 + Tag = "256" + ToolTipText = "On level spawning (initial position), hang from ceiling instead of stand on floor." + Top = 2160 + Width = 1935 + End + Begin VB.CheckBox chkFlags + Caption = "MF_BOSS" + Height = 255 + Index = 7 + Left = 120 + TabIndex = 53 + Tag = "128" + ToolTipText = "Object is a boss." + Top = 1920 + Width = 1575 + End + Begin VB.CheckBox chkFlags + Caption = "MF_PUSHABLE" + Height = 255 + Index = 6 + Left = 120 + TabIndex = 52 + Tag = "64" + ToolTipText = "You can push this object. It can activate switches and things by pushing it on top." + Top = 1680 + Width = 1575 + End + Begin VB.CheckBox chkFlags + Caption = "MF_AMBUSH" + Height = 255 + Index = 5 + Left = 120 + TabIndex = 51 + Tag = "32" + ToolTipText = "Special attributes" + Top = 1440 + Width = 1455 + End + Begin VB.CheckBox chkFlags + Caption = "MF_NOBLOCKMAP" + Height = 255 + Index = 4 + Left = 120 + TabIndex = 50 + Tag = "16" + ToolTipText = "Don't use the blocklinks (inert but displayable)" + Top = 1200 + Width = 1815 + End + Begin VB.CheckBox chkFlags + Caption = "MF_NOSECTOR" + Height = 255 + Index = 3 + Left = 120 + TabIndex = 49 + Tag = "8" + ToolTipText = "Don't use the sector links (invisible but touchable)." + Top = 960 + Width = 1575 + End + Begin VB.CheckBox chkFlags + Caption = "MF_SHOOTABLE" + Height = 255 + Index = 2 + Left = 120 + TabIndex = 48 + Tag = "4" + ToolTipText = "Can be hit." + Top = 720 + Width = 1695 + End + Begin VB.CheckBox chkFlags + Caption = "MF_SOLID" + Height = 255 + Index = 1 + Left = 120 + TabIndex = 47 + Tag = "2" + ToolTipText = "Blocks." + Top = 480 + Width = 1335 + End + Begin VB.CheckBox chkFlags + Caption = "MF_SPECIAL" + Height = 255 + Index = 0 + Left = 120 + TabIndex = 46 + Tag = "1" + ToolTipText = "Call P_TouchSpecialThing when touched." + Top = 240 + Width = 1455 + End + End + Begin VB.ComboBox cmbRaisestate + Height = 315 + Left = 4320 + TabIndex = 43 + Text = "cmbRaisestate" + Top = 4440 + Width = 3300 + End + Begin VB.ComboBox cmbActivesound + Height = 315 + Left = 4320 + TabIndex = 41 + Text = "cmbActivesound" + Top = 4080 + Width = 3300 + End + Begin VB.TextBox txtDamage + Height = 285 + Left = 10680 + TabIndex = 39 + Text = "0" + Top = 1200 + Width = 1095 + End + Begin VB.TextBox txtMass + Height = 285 + Left = 10680 + TabIndex = 37 + Text = "0" + Top = 840 + Width = 1095 + End + Begin VB.TextBox txtHeight + Height = 285 + Left = 10680 + TabIndex = 35 + Text = "0" + Top = 480 + Width = 1095 + End + Begin VB.TextBox txtRadius + Height = 285 + Left = 10680 + TabIndex = 33 + Text = "0" + Top = 120 + Width = 1095 + End + Begin VB.TextBox txtSpeed + Height = 285 + Left = 8760 + TabIndex = 31 + Text = "0" + Top = 1560 + Width = 1095 + End + Begin VB.ComboBox cmbDeathsound + Height = 315 + Left = 4320 + TabIndex = 29 + Text = "cmbDeathsound" + Top = 3720 + Width = 3300 + End + Begin VB.ComboBox cmbXdeathstate + Height = 315 + Left = 4320 + TabIndex = 27 + Text = "cmbXdeathstate" + Top = 3360 + Width = 3300 + End + Begin VB.ComboBox cmbDeathstate + Height = 315 + Left = 4320 + TabIndex = 25 + Text = "cmbDeathstate" + Top = 3000 + Width = 3300 + End + Begin VB.ComboBox cmbMissilestate + Height = 315 + Left = 4320 + TabIndex = 23 + Text = "cmbMissilestate" + Top = 2640 + Width = 3300 + End + Begin VB.ComboBox cmbMeleestate + Height = 315 + Left = 4320 + TabIndex = 21 + Text = "cmbMeleestate" + Top = 2280 + Width = 3300 + End + Begin VB.ComboBox cmbPainsound + Height = 315 + Left = 4320 + TabIndex = 19 + Text = "cmbPainsound" + Top = 1920 + Width = 3300 + End + Begin VB.TextBox txtPainchance + Height = 285 + Left = 8760 + TabIndex = 17 + Text = "0" + Top = 1200 + Width = 1095 + End + Begin VB.ComboBox cmbPainstate + Height = 315 + Left = 4320 + TabIndex = 15 + Text = "cmbPainstate" + Top = 1560 + Width = 3300 + End + Begin VB.ComboBox cmbAttacksound + Height = 315 + Left = 4320 + TabIndex = 13 + Text = "cmbAttacksound" + Top = 1200 + Width = 3300 + End + Begin VB.TextBox txtReactiontime + Height = 285 + Left = 8760 + TabIndex = 11 + Text = "0" + Top = 840 + Width = 1095 + End + Begin VB.ComboBox cmbSeesound + Height = 315 + Left = 4320 + TabIndex = 9 + Text = "cmbSeesound" + Top = 840 + Width = 3300 + End + Begin VB.ComboBox cmbSeestate + Height = 315 + Left = 4320 + TabIndex = 7 + Text = "cmbSeestate" + Top = 480 + Width = 3300 + End + Begin VB.TextBox txtSpawnhealth + Height = 285 + Left = 8760 + TabIndex = 6 + Text = "0" + Top = 480 + Width = 1095 + End + Begin VB.ComboBox cmbSpawnstate + Height = 315 + Left = 4320 + TabIndex = 3 + Text = "cmbSpawnstate" + Top = 120 + Width = 3300 + End + Begin VB.TextBox txtDoomednum + Height = 285 + Left = 8760 + TabIndex = 1 + Text = "0" + Top = 120 + Width = 1095 + End + Begin VB.ListBox lstThings + Height = 5520 + ItemData = "Things.frx":0442 + Left = 120 + List = "Things.frx":0444 + TabIndex = 0 + Top = 120 + Width = 3015 + End + Begin VB.Label lblStatusInfo + Alignment = 2 'Center + Caption = "Idle" + BeginProperty Font + Name = "MS Sans Serif" + Size = 8.25 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 375 + Left = 9960 + TabIndex = 75 + Top = 1560 + Width = 1815 + End + Begin VB.Label lblRaisestate + Alignment = 1 'Right Justify + Caption = "Raisestate:" + Height = 255 + Left = 3360 + TabIndex = 44 + Top = 4440 + Width = 855 + End + Begin VB.Label lblActivesound + Alignment = 1 'Right Justify + Caption = "Activesound:" + Height = 255 + Left = 3240 + TabIndex = 42 + Top = 4080 + Width = 975 + End + Begin VB.Label lblDamage + Alignment = 1 'Right Justify + Caption = "Damage:" + Height = 255 + Left = 9840 + TabIndex = 40 + Top = 1200 + Width = 735 + End + Begin VB.Label lblMass + Alignment = 1 'Right Justify + Caption = "Mass:" + Height = 255 + Left = 9960 + TabIndex = 38 + Top = 840 + Width = 615 + End + Begin VB.Label lblHeight + Alignment = 1 'Right Justify + Caption = "Height:" + Height = 255 + Left = 9960 + TabIndex = 36 + Top = 480 + Width = 615 + End + Begin VB.Label lblRadius + Alignment = 1 'Right Justify + Caption = "Radius:" + Height = 255 + Left = 9960 + TabIndex = 34 + Top = 120 + Width = 615 + End + Begin VB.Label lblSpeed + Alignment = 1 'Right Justify + Caption = "Speed:" + Height = 255 + Left = 7680 + TabIndex = 32 + Top = 1560 + Width = 975 + End + Begin VB.Label lblDeathsound + Alignment = 1 'Right Justify + Caption = "Deathsound:" + Height = 255 + Left = 3240 + TabIndex = 30 + Top = 3720 + Width = 975 + End + Begin VB.Label lblXdeathstate + Alignment = 1 'Right Justify + Caption = "Xdeathstate:" + Height = 255 + Left = 3240 + TabIndex = 28 + Top = 3360 + Width = 975 + End + Begin VB.Label lblDeathstate + Alignment = 1 'Right Justify + Caption = "Deathstate:" + Height = 255 + Left = 3240 + TabIndex = 26 + Top = 3000 + Width = 975 + End + Begin VB.Label lblMissilestate + Alignment = 1 'Right Justify + Caption = "Missilestate:" + Height = 255 + Left = 3240 + TabIndex = 24 + Top = 2640 + Width = 975 + End + Begin VB.Label lblMeleestate + Alignment = 1 'Right Justify + Caption = "Meleestate:" + Height = 255 + Left = 3240 + TabIndex = 22 + Top = 2280 + Width = 975 + End + Begin VB.Label lblPainsound + Alignment = 1 'Right Justify + Caption = "Painsound:" + Height = 255 + Left = 3240 + TabIndex = 20 + Top = 1920 + Width = 975 + End + Begin VB.Label lblPainchance + Alignment = 1 'Right Justify + Caption = "Painchance:" + Height = 255 + Left = 7680 + TabIndex = 18 + Top = 1200 + Width = 975 + End + Begin VB.Label lblPainstate + Alignment = 1 'Right Justify + Caption = "Painstate:" + Height = 255 + Left = 3240 + TabIndex = 16 + Top = 1560 + Width = 975 + End + Begin VB.Label lblAttacksound + Alignment = 1 'Right Justify + Caption = "Attacksound:" + Height = 255 + Left = 3240 + TabIndex = 14 + Top = 1200 + Width = 975 + End + Begin VB.Label lblReactiontime + Alignment = 1 'Right Justify + Caption = "Reactiontime:" + Height = 255 + Left = 7680 + TabIndex = 12 + Top = 840 + Width = 975 + End + Begin VB.Label lblSeesound + Alignment = 1 'Right Justify + Caption = "Seesound:" + Height = 255 + Left = 3240 + TabIndex = 10 + Top = 840 + Width = 975 + End + Begin VB.Label lblSeestate + Alignment = 1 'Right Justify + Caption = "Seestate:" + Height = 255 + Left = 3240 + TabIndex = 8 + Top = 480 + Width = 975 + End + Begin VB.Label lblSpawnhealth + Alignment = 1 'Right Justify + Caption = "Spawnhealth:" + Height = 255 + Left = 7680 + TabIndex = 5 + Top = 480 + Width = 975 + End + Begin VB.Label lblSpawnstate + Alignment = 1 'Right Justify + Caption = "Spawnstate:" + Height = 255 + Left = 3240 + TabIndex = 4 + Top = 120 + Width = 975 + End + Begin VB.Label lblDoomednum + Alignment = 1 'Right Justify + Caption = "Thing Map #:" + Height = 255 + Left = 7680 + TabIndex = 2 + Top = 120 + Width = 975 + End +End +Attribute VB_Name = "frmThingEdit" +Attribute VB_GlobalNameSpace = False +Attribute VB_Creatable = False +Attribute VB_PredeclaredId = True +Attribute VB_Exposed = False +Option Explicit + +Private Sub cmdCopy_Click() + Dim Response As String + + Response$ = InputBox("Copy state to #:", "Copy State") + + If Response = "" Then Exit Sub + + Response = TrimComplete(Response) + + Call WriteThing(False, Val(Response)) + + MsgBox "Thing copied to #" & Val(Response) +End Sub + +Private Sub cmdDelete_Click() + Call WriteThing(True, lstThings.ListIndex) +End Sub + +Private Sub cmdLoadDefault_Click() + Call ClearForm + If InStr(lstThings.List(lstThings.ListIndex), "MT_FREESLOT") = 0 Then + LoadObjectInfo (lstThings.ListIndex) + Else + MsgBox "Free slots do not have a code default." + End If +End Sub + +Private Sub cmdSave_Click() + Call WriteThing(False, lstThings.ListIndex) +End Sub + +Private Sub Form_Load() + Call Reload +End Sub + +Private Sub ClearForm() + Dim i As Integer + cmbSpawnstate.Text = "" + cmbSeestate.Text = "" + cmbSeesound.Text = "" + cmbAttacksound.Text = "" + cmbPainstate.Text = "" + cmbPainsound.Text = "" + cmbMeleestate.Text = "" + cmbMissilestate.Text = "" + cmbDeathstate.Text = "" + cmbXdeathstate.Text = "" + cmbDeathsound.Text = "" + cmbActivesound.Text = "" + cmbRaisestate.Text = "" + txtDoomednum.Text = "" + txtSpawnhealth.Text = "" + txtReactiontime.Text = "" + txtPainchance.Text = "" + txtSpeed.Text = "" + txtRadius.Text = "" + txtHeight.Text = "" + txtMass.Text = "" + txtDamage.Text = "" + + For i = 0 To 26 + chkFlags(i).Value = 0 + Next +End Sub + +Private Sub Reload() + lblStatusInfo.Caption = "Loading Sounds Info..." + DoEvents + LoadSounds + lblStatusInfo.Caption = "Loading Things Info..." + DoEvents + LoadThings + lblStatusInfo.Caption = "Loading States Info..." + DoEvents + LoadStates + lblStatusInfo.Caption = "Idle" + lstThings.ListIndex = 0 +End Sub + +Private Sub LoadSounds() + Dim myFSO As New Scripting.FileSystemObject + Dim ts As TextStream + Dim line As String + Dim number As Integer + Dim startclip As Integer, endclip As Integer + Dim addstring As String + Dim i As Integer, numfreeslots As Integer + + ChDir SourcePath + Set ts = myFSO.OpenTextFile("sounds.h", ForReading, False) + + Do While InStr(ts.ReadLine, "List of sounds (don't modify this comment!)") = 0 + Loop + + ts.SkipLine ' typedef enum + ts.SkipLine ' { + + line = ts.ReadLine + number = 0 + + cmbSeesound.Clear + cmbAttacksound.Clear + cmbPainsound.Clear + cmbDeathsound.Clear + cmbActivesound.Clear + + Do While InStr(line, "sfx_freeslot0") = 0 + startclip = InStr(line, "sfx_") + If InStr(line, "sfx_") <> 0 Then + endclip = InStr(line, ",") + line = Mid(line, startclip, endclip - startclip) + addstring = number & " - " & line + cmbSeesound.AddItem addstring + cmbAttacksound.AddItem addstring + cmbPainsound.AddItem addstring + cmbDeathsound.AddItem addstring + cmbActivesound.AddItem addstring + number = number + 1 + End If + line = ts.ReadLine + Loop + + ts.Close + Set myFSO = Nothing + + 'Populate the free slots! + numfreeslots = 800 + + For i = 1 To numfreeslots + If i < 10 Then + addstring = number & " - " & "sfx_fre00" & i & " (free slot)" + ElseIf i < 100 Then + addstring = number & " - " & "sfx_fre0" & i & " (free slot)" + Else + addstring = number & " - " & "sfx_fre" & i & " (free slot)" + End If + cmbSeesound.AddItem addstring + cmbAttacksound.AddItem addstring + cmbPainsound.AddItem addstring + cmbDeathsound.AddItem addstring + cmbActivesound.AddItem addstring + number = number + 1 + Next +End Sub +Private Sub LoadStates() + Dim myFSO As New Scripting.FileSystemObject + Dim ts As TextStream + Dim line As String + Dim number As Integer + Dim startclip As Integer, endclip As Integer + Dim addstring As String + Dim i As Integer + Dim numfreeslots As Integer + + ChDir SourcePath + Set ts = myFSO.OpenTextFile("info.h", ForReading, False) + + Do While InStr(ts.ReadLine, "Object states (don't modify this comment!)") = 0 + Loop + + ts.SkipLine ' typedef enum + ts.SkipLine ' { + + line = ts.ReadLine + number = 0 + + cmbSpawnstate.Clear + cmbSeestate.Clear + cmbPainstate.Clear + cmbMeleestate.Clear + cmbMissilestate.Clear + cmbDeathstate.Clear + cmbXdeathstate.Clear + cmbRaisestate.Clear + + Do While InStr(line, "S_FIRSTFREESLOT") = 0 + startclip = InStr(line, "S_") + If InStr(line, "S_") <> 0 Then + endclip = InStr(line, ",") + line = Mid(line, startclip, endclip - startclip) + addstring = number & " - " & line + cmbSpawnstate.AddItem addstring + cmbSeestate.AddItem addstring + cmbPainstate.AddItem addstring + cmbMeleestate.AddItem addstring + cmbMissilestate.AddItem addstring + cmbDeathstate.AddItem addstring + cmbXdeathstate.AddItem addstring + cmbRaisestate.AddItem addstring + number = number + 1 + End If + line = ts.ReadLine + Loop + + ts.Close + + 'Populate the free slots! + Set ts = myFSO.OpenTextFile("info.h", ForReading, False) + + line = ts.ReadLine + Do While InStr(line, "#define NUMMOBJFREESLOTS") = 0 + line = ts.ReadLine + Loop + + startclip = InStr(line, "SLOTS ") + 6 + numfreeslots = Val(Mid(line, startclip, Len(line) - startclip + 1)) * 6 + + For i = 1 To numfreeslots + addstring = number & " - " & "S_FREESLOT" & i + cmbSpawnstate.AddItem addstring + cmbSeestate.AddItem addstring + cmbPainstate.AddItem addstring + cmbMeleestate.AddItem addstring + cmbMissilestate.AddItem addstring + cmbDeathstate.AddItem addstring + cmbXdeathstate.AddItem addstring + cmbRaisestate.AddItem addstring + number = number + 1 + Next + + ts.Close + Set myFSO = Nothing +End Sub + +Private Sub LoadThings() + Dim myFSO As New Scripting.FileSystemObject + Dim ts As TextStream + Dim line As String + Dim number As Integer + Dim startclip As Integer, endclip As Integer + Dim numfreeslots As Integer, i As Integer + + ChDir SourcePath + Set ts = myFSO.OpenTextFile("info.h", ForReading, False) + + Do While InStr(ts.ReadLine, "Little flag for SOC editor (don't change this comment!)") = 0 + Loop + + ts.SkipLine ' typedef enum + ts.SkipLine ' { + + line = ts.ReadLine + number = 0 + + lstThings.Clear + + Do While InStr(line, "MT_FIRSTFREESLOT") = 0 + startclip = InStr(line, "MT_") + If InStr(line, "MT_") <> 0 Then + endclip = InStr(line, ",") + line = Mid(line, startclip, endclip - startclip) + lstThings.AddItem number & " - " & line + number = number + 1 + End If + line = ts.ReadLine + Loop + + ts.Close + + 'Populate the free slots! + Set ts = myFSO.OpenTextFile("info.h", ForReading, False) + + line = ts.ReadLine + Do While InStr(line, "#define NUMMOBJFREESLOTS") = 0 + line = ts.ReadLine + Loop + + startclip = InStr(line, "SLOTS ") + 6 + numfreeslots = Val(Mid(line, startclip, Len(line) - startclip + 1)) + + For i = 1 To numfreeslots + lstThings.AddItem number & " - " & "MT_FREESLOT" & i + number = number + 1 + Next + + ts.Close + Set myFSO = Nothing +End Sub + +Private Sub LoadObjectInfo(ThingNum As Integer) + Dim myFSO As New Scripting.FileSystemObject + Dim ts As TextStream + Dim line As String + Dim number As Integer + Dim startclip As Integer, endclip As Integer + + ChDir SourcePath + Set ts = myFSO.OpenTextFile("info.c", ForReading, False) + + Do While InStr(ts.ReadLine, "mobjinfo[NUMMOBJTYPES] =") = 0 + Loop + + number = 0 + + Do While number <> ThingNum + Do While InStr(ts.ReadLine, "}") = 0 + Loop + number = number + 1 + Loop + + Do While InStr(line, "doomednum") = 0 + line = ts.ReadLine + Loop + + endclip = InStr(line, ",") + line = Left(line, endclip - 1) + line = TrimComplete(line) + 'Check for *FRACUNIT values + endclip = InStr(line, "*FRACUNIT") + If endclip <> 0 Then + line = Left(line, endclip - 1) + line = Val(line) * 65536 + End If + 'Check for crazy-odd MT_ usage + endclip = InStr(line, "MT_") + If endclip <> 0 Then + line = FindThingNum(line) & " - " & line + End If + 'Check for crazy-odd pw_ usage + endclip = InStr(line, "pw_") + If endclip <> 0 Then + line = FindPowerNum(line) & " - " & line + End If + txtDoomednum.Text = line + + line = ts.ReadLine + Do While InStr(line, "spawnstate") = 0 + Loop + endclip = InStr(line, ",") + line = Left(line, endclip - 1) + line = TrimComplete(line) + Call FindComboIndex(cmbSpawnstate, line) + 'Check for crazy-odd MT_ usage + endclip = InStr(line, "MT_") + If endclip <> 0 Then + number = FindThingNum(line) + cmbSpawnstate.Text = number & " - " & line + End If + 'Check for crazy-odd pw_ usage + endclip = InStr(line, "pw_") + If endclip <> 0 Then + number = FindPowerNum(line) + cmbSpawnstate.Text = number & " - " & line + End If + + line = ts.ReadLine + Do While InStr(line, "spawnhealth") = 0 + Loop + endclip = InStr(line, ",") + line = Left(line, endclip - 1) + line = TrimComplete(line) + 'Check for *FRACUNIT values + endclip = InStr(line, "*FRACUNIT") + If endclip <> 0 Then + line = Left(line, endclip - 1) + line = Val(line) * 65536 + End If + 'Check for crazy-odd MT_ usage + endclip = InStr(line, "MT_") + If endclip <> 0 Then + line = FindThingNum(line) & " - " & line + End If + 'Check for crazy-odd pw_ usage + endclip = InStr(line, "pw_") + If endclip <> 0 Then + line = FindPowerNum(line) & " - " & line + End If + txtSpawnhealth.Text = line + + line = ts.ReadLine + Do While InStr(line, "seestate") = 0 + Loop + endclip = InStr(line, ",") + line = Left(line, endclip - 1) + line = TrimComplete(line) + Call FindComboIndex(cmbSeestate, line) + 'Check for crazy-odd MT_ usage + endclip = InStr(line, "MT_") + If endclip <> 0 Then + number = FindThingNum(line) + cmbSeestate.Text = number & " - " & line + End If + 'Check for crazy-odd pw_ usage + endclip = InStr(line, "pw_") + If endclip <> 0 Then + number = FindPowerNum(line) + cmbSeestate.Text = number & " - " & line + End If + + line = ts.ReadLine + Do While InStr(line, "seesound") = 0 + Loop + endclip = InStr(line, ",") + line = Left(line, endclip - 1) + line = TrimComplete(line) + Call FindComboIndex(cmbSeesound, line) + 'Check for crazy-odd MT_ usage + endclip = InStr(line, "MT_") + If endclip <> 0 Then + number = FindThingNum(line) + cmbSeesound.Text = number & " - " & line + End If + 'Check for crazy-odd pw_ usage + endclip = InStr(line, "pw_") + If endclip <> 0 Then + number = FindPowerNum(line) + cmbSeesound.Text = number & " - " & line + End If + + line = ts.ReadLine + Do While InStr(line, "reactiontime") = 0 + Loop + endclip = InStr(line, ",") + line = Left(line, endclip - 1) + line = TrimComplete(line) + 'Check for *FRACUNIT values + endclip = InStr(line, "*FRACUNIT") + If endclip <> 0 Then + line = Left(line, endclip - 1) + line = Val(line) * 65536 + End If + 'Check for crazy-odd MT_ usage + endclip = InStr(line, "MT_") + If endclip <> 0 Then + line = FindThingNum(line) & " - " & line + End If + 'Check for crazy-odd pw_ usage + endclip = InStr(line, "pw_") + If endclip <> 0 Then + line = FindPowerNum(line) & " - " & line + End If + txtReactiontime.Text = line + + line = ts.ReadLine + Do While InStr(line, "attacksound") = 0 + Loop + endclip = InStr(line, ",") + line = Left(line, endclip - 1) + line = TrimComplete(line) + Call FindComboIndex(cmbAttacksound, line) + 'Check for crazy-odd MT_ usage + endclip = InStr(line, "MT_") + If endclip <> 0 Then + number = FindThingNum(line) + cmbAttacksound.Text = number & " - " & line + End If + 'Check for crazy-odd pw_ usage + endclip = InStr(line, "pw_") + If endclip <> 0 Then + number = FindPowerNum(line) + cmbAttacksound.Text = number & " - " & line + End If + + line = ts.ReadLine + Do While InStr(line, "painstate") = 0 + Loop + endclip = InStr(line, ",") + line = Left(line, endclip - 1) + line = TrimComplete(line) + Call FindComboIndex(cmbPainstate, line) + 'Check for crazy-odd MT_ usage + endclip = InStr(line, "MT_") + If endclip <> 0 Then + number = FindThingNum(line) + cmbPainstate.Text = number & " - " & line + End If + 'Check for crazy-odd pw_ usage + endclip = InStr(line, "pw_") + If endclip <> 0 Then + number = FindPowerNum(line) + cmbPainstate.Text = number & " - " & line + End If + + line = ts.ReadLine + Do While InStr(line, "painchance") = 0 + Loop + endclip = InStr(line, ",") + line = Left(line, endclip - 1) + line = TrimComplete(line) + 'Check for *FRACUNIT values + endclip = InStr(line, "*FRACUNIT") + If endclip <> 0 Then + line = Left(line, endclip - 1) + line = Val(line) * 65536 + End If + 'Check for crazy-odd MT_ usage + endclip = InStr(line, "MT_") + If endclip <> 0 Then + line = FindThingNum(line) & " - " & line + End If + 'Check for crazy-odd pw_ usage + endclip = InStr(line, "pw_") + If endclip <> 0 Then + line = FindPowerNum(line) & " - " & line + End If + txtPainchance.Text = line + + line = ts.ReadLine + Do While InStr(line, "painsound") = 0 + Loop + endclip = InStr(line, ",") + line = Left(line, endclip - 1) + line = TrimComplete(line) + Call FindComboIndex(cmbPainsound, line) + 'Check for crazy-odd MT_ usage + endclip = InStr(line, "MT_") + If endclip <> 0 Then + number = FindThingNum(line) + cmbPainsound.Text = number & " - " & line + End If + 'Check for crazy-odd pw_ usage + endclip = InStr(line, "pw_") + If endclip <> 0 Then + number = FindPowerNum(line) + cmbPainsound.Text = number & " - " & line + End If + + line = ts.ReadLine + Do While InStr(line, "meleestate") = 0 + Loop + endclip = InStr(line, ",") + line = Left(line, endclip - 1) + line = TrimComplete(line) + Call FindComboIndex(cmbMeleestate, line) + 'Check for crazy-odd MT_ usage + endclip = InStr(line, "MT_") + If endclip <> 0 Then + number = FindThingNum(line) + cmbMeleestate.Text = number & " - " & line + End If + 'Check for crazy-odd pw_ usage + endclip = InStr(line, "pw_") + If endclip <> 0 Then + number = FindPowerNum(line) + cmbMeleestate.Text = number & " - " & line + End If + + line = ts.ReadLine + Do While InStr(line, "missilestate") = 0 + Loop + endclip = InStr(line, ",") + line = Left(line, endclip - 1) + line = TrimComplete(line) + Call FindComboIndex(cmbMissilestate, line) + 'Check for crazy-odd MT_ usage + endclip = InStr(line, "MT_") + If endclip <> 0 Then + number = FindThingNum(line) + cmbMissilestate.Text = number & " - " & line + End If + 'Check for crazy-odd pw_ usage + endclip = InStr(line, "pw_") + If endclip <> 0 Then + number = FindPowerNum(line) + cmbMissilestate.Text = number & " - " & line + End If + + line = ts.ReadLine + Do While InStr(line, "deathstate") = 0 + Loop + endclip = InStr(line, ",") + line = Left(line, endclip - 1) + line = TrimComplete(line) + Call FindComboIndex(cmbDeathstate, line) + 'Check for crazy-odd MT_ usage + endclip = InStr(line, "MT_") + If endclip <> 0 Then + number = FindThingNum(line) + cmbDeathstate.Text = number & " - " & line + End If + 'Check for crazy-odd pw_ usage + endclip = InStr(line, "pw_") + If endclip <> 0 Then + number = FindPowerNum(line) + cmbDeathstate.Text = number & " - " & line + End If + + line = ts.ReadLine + Do While InStr(line, "xdeathstate") = 0 + Loop + endclip = InStr(line, ",") + line = Left(line, endclip - 1) + line = TrimComplete(line) + Call FindComboIndex(cmbXdeathstate, line) + 'Check for crazy-odd MT_ usage + endclip = InStr(line, "MT_") + If endclip <> 0 Then + number = FindThingNum(line) + cmbXdeathstate.Text = number & " - " & line + End If + 'Check for crazy-odd pw_ usage + endclip = InStr(line, "pw_") + If endclip <> 0 Then + number = FindPowerNum(line) + cmbXdeathstate.Text = number & " - " & line + End If + + line = ts.ReadLine + Do While InStr(line, "deathsound") = 0 + Loop + endclip = InStr(line, ",") + line = Left(line, endclip - 1) + line = TrimComplete(line) + Call FindComboIndex(cmbDeathsound, line) + 'Check for crazy-odd MT_ usage + endclip = InStr(line, "MT_") + If endclip <> 0 Then + number = FindThingNum(line) + cmbDeathsound.Text = number & " - " & line + End If + 'Check for crazy-odd pw_ usage + endclip = InStr(line, "pw_") + If endclip <> 0 Then + number = FindPowerNum(line) + cmbDeathsound.Text = number & " - " & line + End If + + + line = ts.ReadLine + Do While InStr(line, "speed") = 0 + Loop + endclip = InStr(line, ",") + line = Left(line, endclip - 1) + line = TrimComplete(line) + 'Check for *FRACUNIT values + endclip = InStr(line, "*FRACUNIT") + If endclip <> 0 Then + line = Left(line, endclip - 1) + line = Val(line) * 65536 + End If + 'Check for crazy-odd MT_ usage + endclip = InStr(line, "MT_") + If endclip <> 0 Then + line = FindThingNum(line) & " - " & line + End If + 'Check for crazy-odd pw_ usage + endclip = InStr(line, "pw_") + If endclip <> 0 Then + line = FindPowerNum(line) & " - " & line + End If + txtSpeed.Text = line + + line = ts.ReadLine + Do While InStr(line, "radius") = 0 + Loop + endclip = InStr(line, ",") + line = Left(line, endclip - 1) + line = TrimComplete(line) + 'Check for *FRACUNIT values + endclip = InStr(line, "*FRACUNIT") + If endclip <> 0 Then + line = Left(line, endclip - 1) + line = Val(line) * 65536 + End If + 'Check for crazy-odd MT_ usage + endclip = InStr(line, "MT_") + If endclip <> 0 Then + line = FindThingNum(line) & " - " & line + End If + 'Check for crazy-odd pw_ usage + endclip = InStr(line, "pw_") + If endclip <> 0 Then + line = FindPowerNum(line) & " - " & line + End If + txtRadius.Text = line + + line = ts.ReadLine + Do While InStr(line, "height") = 0 + Loop + endclip = InStr(line, ",") + line = Left(line, endclip - 1) + line = TrimComplete(line) + 'Check for *FRACUNIT values + endclip = InStr(line, "*FRACUNIT") + If endclip <> 0 Then + line = Left(line, endclip - 1) + line = Val(line) * 65536 + End If + 'Check for crazy-odd MT_ usage + endclip = InStr(line, "MT_") + If endclip <> 0 Then + line = FindThingNum(line) & " - " & line + End If + 'Check for crazy-odd pw_ usage + endclip = InStr(line, "pw_") + If endclip <> 0 Then + line = FindPowerNum(line) & " - " & line + End If + txtHeight.Text = line + + line = ts.ReadLine 'Display order offset (add support, please!) + + line = ts.ReadLine + Do While InStr(line, "mass") = 0 + Loop + endclip = InStr(line, ",") + line = Left(line, endclip - 1) + line = TrimComplete(line) + 'Check for *FRACUNIT values + endclip = InStr(line, "*FRACUNIT") + If endclip <> 0 Then + line = Left(line, endclip - 1) + line = Val(line) * 65536 + End If + 'Check for crazy-odd MT_ usage + endclip = InStr(line, "MT_") + If endclip <> 0 Then + line = FindThingNum(line) & " - " & line + End If + 'Check for crazy-odd pw_ usage + endclip = InStr(line, "pw_") + If endclip <> 0 Then + line = FindPowerNum(line) & " - " & line + End If + txtMass.Text = line + + line = ts.ReadLine + Do While InStr(line, "damage") = 0 + Loop + endclip = InStr(line, ",") + line = Left(line, endclip - 1) + line = TrimComplete(line) + 'Check for *FRACUNIT values + endclip = InStr(line, "*FRACUNIT") + If endclip <> 0 Then + line = Left(line, endclip - 1) + line = Val(line) * 65536 + End If + 'Check for crazy-odd MT_ usage + endclip = InStr(line, "MT_") + If endclip <> 0 Then + line = FindThingNum(line) & " - " & line + End If + 'Check for crazy-odd pw_ usage + endclip = InStr(line, "pw_") + If endclip <> 0 Then + line = FindPowerNum(line) & " - " & line + End If + txtDamage.Text = line + + line = ts.ReadLine + Do While InStr(line, "activesound") = 0 + Loop + endclip = InStr(line, ",") + line = Left(line, endclip - 1) + line = TrimComplete(line) + Call FindComboIndex(cmbActivesound, line) + 'Check for crazy-odd MT_ usage + endclip = InStr(line, "MT_") + If endclip <> 0 Then + number = FindThingNum(line) + cmbActivesound.Text = number & " - " & line + End If + 'Check for crazy-odd pw_ usage + endclip = InStr(line, "pw_") + If endclip <> 0 Then + number = FindPowerNum(line) + cmbActivesound.Text = number & " - " & line + End If + + line = ts.ReadLine + Do While InStr(line, "flags") = 0 + Loop + endclip = InStr(line, ",") + line = Left(line, endclip - 1) + line = TrimComplete(line) + ProcessFlags (line) + + line = ts.ReadLine + Do While InStr(line, "raisestate") = 0 + Loop + endclip = InStr(line, "//") + line = Left(line, endclip - 1) + line = TrimComplete(line) + Call FindComboIndex(cmbRaisestate, line) + 'Check for crazy-odd MT_ usage + endclip = InStr(line, "MT_") + If endclip <> 0 Then + number = FindThingNum(line) + cmbRaisestate.Text = number & " - " & line + End If + 'Check for crazy-odd pw_ usage + endclip = InStr(line, "pw_") + If endclip <> 0 Then + number = FindPowerNum(line) + cmbRaisestate.Text = number & " - " & line + End If + + ts.Close + Set myFSO = Nothing +End Sub + +Private Sub ProcessFlags(flags As String) + Dim FlagList(32) As String + Dim endpoint As Integer + Dim ListCount As Integer + Dim FlagString As String + Dim myFSO As New Scripting.FileSystemObject + Dim ts As TextStream + Dim line As String + Dim j As Integer, i As Integer + Dim number As Long + Dim startclip As Integer, endclip As Integer + + For j = 0 To 26 + chkFlags(j).Value = 0 + Next j + + FlagString = flags + + flags = flags & "||" + + ListCount = 0 + + Do While Len(flags) > 3 + endpoint = InStr(flags, "|") + FlagString = Left(flags, endpoint - 1) + flags = Right(flags, Len(flags) - endpoint) + FlagList(ListCount) = FlagString + ListCount = ListCount + 1 + Loop + + ChDir SourcePath + + For i = 0 To ListCount - 1 + Set ts = myFSO.OpenTextFile("p_mobj.h", ForReading, False) + + line = ts.ReadLine + + Do While Not ts.AtEndOfStream + line = ts.ReadLine + If InStr(line, FlagList(i)) Then + If InStr(line, "//") = 0 Or (InStr(line, "//") > InStr(line, FlagList(i))) Then + Exit Do + End If + End If + Loop + + If InStr(line, FlagList(i)) Then + startclip = InStr(line, "0x") + endclip = InStr(line, ",") + line = Mid(line, startclip + 2, endclip - 1) + line = "&H" & line + TrimComplete (line) + line = Left(line, Len(line) - 1) + number = CLng(line) + + For j = 0 To 26 + If chkFlags(j).Tag = number Then + chkFlags(j).Value = 1 + End If + Next j + End If + ts.Close + Next i + + Set myFSO = Nothing +End Sub + +Private Sub FindComboIndex(ByRef Box As ComboBox, line As String) + Dim i As Integer + + For i = 0 To Box.ListCount + If InStr(Box.List(i), line) Then + Box.ListIndex = i + Exit For + End If + Next +End Sub + +Private Sub lstThings_Click() + lblStatusInfo.Caption = "Loading thing info..." + DoEvents + Call ClearForm + If InStr(lstThings.List(lstThings.ListIndex), "MT_FREESLOT") = 0 Then + LoadObjectInfo (lstThings.ListIndex) + End If + LoadSOCObjectInfo (lstThings.ListIndex) + lblStatusInfo.Caption = "Idle" +End Sub + +Private Sub LoadSOCObjectInfo(ThingNum As Integer) + Dim myFSO As New Scripting.FileSystemObject + Dim ts As TextStream + Dim line As String + Dim word As String + Dim word2 As String + Dim j As Integer + Dim temp As Long + + Set ts = myFSO.OpenTextFile(SOCFile, ForReading, False) + +SOCLoad: + Do While Not ts.AtEndOfStream + line = ts.ReadLine + + If Left(line, 1) = "#" Then GoTo SOCLoad + + If Left(line, 1) = vbCrLf Then GoTo SOCLoad + + If Len(line) < 1 Then GoTo SOCLoad + + word = FirstToken(line) + word2 = SecondToken(line) + + If UCase(word) = "THING" And Val(word2) = ThingNum Then + Do While Len(line) > 0 And Not ts.AtEndOfStream + line = ts.ReadLine + word = UCase(FirstToken(line)) + word2 = UCase(SecondTokenEqual(line)) + + If word = "MAPTHINGNUM" Then + txtDoomednum.Text = Val(word2) + ElseIf word = "SPAWNSTATE" Then + cmbSpawnstate.ListIndex = Val(word2) + ElseIf word = "SPAWNHEALTH" Then + txtSpawnhealth.Text = Val(word2) + ElseIf word = "SEESTATE" Then + cmbSeestate.ListIndex = Val(word2) + ElseIf word = "SEESOUND" Then + cmbSeesound.ListIndex = Val(word2) + ElseIf word = "REACTIONTIME" Then + txtReactiontime.Text = Val(word2) + ElseIf word = "ATTACKSOUND" Then + cmbAttacksound.ListIndex = Val(word2) + ElseIf word = "PAINSTATE" Then + cmbPainstate.ListIndex = Val(word2) + ElseIf word = "PAINCHANCE" Then + txtPainchance.Text = Val(word2) + ElseIf word = "PAINSOUND" Then + cmbPainsound.ListIndex = Val(word2) + ElseIf word = "MELEESTATE" Then + cmbMeleestate.ListIndex = Val(word2) + ElseIf word = "MISSILESTATE" Then + cmbMissilestate.ListIndex = Val(word2) + ElseIf word = "DEATHSTATE" Then + cmbDeathstate.ListIndex = Val(word2) + ElseIf word = "DEATHSOUND" Then + cmbDeathsound.ListIndex = Val(word2) + ElseIf word = "XDEATHSTATE" Then + cmbXdeathstate.ListIndex = Val(word2) + ElseIf word = "SPEED" Then + txtSpeed.Text = Val(word2) + ElseIf word = "RADIUS" Then + txtRadius.Text = Val(word2) + ElseIf word = "HEIGHT" Then + txtHeight.Text = Val(word2) + ElseIf word = "MASS" Then + txtMass.Text = Val(word2) + ElseIf word = "DAMAGE" Then + txtDamage.Text = Val(word2) + ElseIf word = "ACTIVESOUND" Then + cmbActivesound.ListIndex = Val(word2) + ElseIf word = "FLAGS" Then + For j = 0 To 26 + temp = Val(word2) + If temp And chkFlags(j).Tag Then + chkFlags(j).Value = 1 + Else + chkFlags(j).Value = 0 + End If + Next j + ElseIf word = "RAISESTATE" Then + cmbRaisestate.ListIndex = Val(word2) + ElseIf Len(line) > 0 And Left(line, 1) <> "#" Then + MsgBox "Error in SOC!" & vbCrLf & "Unknown line: " & line + End If + Loop + Exit Do + End If + Loop + + ts.Close + Set myFSO = Nothing +End Sub + +Private Function FindThingNum(ThingName As String) As Integer + Dim i As Integer + Dim temp As String + Dim startpoint As Integer + Dim endpoint As Integer + + For i = 0 To lstThings.ListCount - 1 + temp = lstThings.List(i) + startpoint = InStr(temp, "-") + 2 + endpoint = Len(temp) - startpoint + 1 + temp = Mid(temp, startpoint, endpoint) + If temp = ThingName Then + FindThingNum = Val(lstThings.List(i)) + Exit For + End If + Next +End Function + +Private Function FindPowerNum(PowerName As String) As Integer + Dim myFSO As New Scripting.FileSystemObject + Dim ts As TextStream + Dim line As String + Dim number As Integer + Dim startclip As Integer + + ChDir SourcePath + Set ts = myFSO.OpenTextFile("d_player.h", ForReading, False) + + Do While InStr(ts.ReadLine, "Player powers. (don't edit this comment)") = 0 + Loop + + ts.SkipLine ' typedef enum + ts.SkipLine ' { + + line = ts.ReadLine + number = 0 + + Do While InStr(line, "NUMPOWERS") = 0 + startclip = InStr(line, PowerName) + If startclip <> 0 Then + FindPowerNum = number + Exit Do + End If + number = number + 1 + line = ts.ReadLine + Loop + + ts.Close + Set myFSO = Nothing +End Function + +Private Sub WriteThing(Remove As Boolean, num As Integer) + Dim myFSOSource As New Scripting.FileSystemObject + Dim tsSource As TextStream + Dim myFSOTarget As New Scripting.FileSystemObject + Dim tsTarget As TextStream + Dim line As String + Dim word As String + Dim word2 As String + Dim flags As Long + Dim thingfound As Boolean + Dim i As Integer + + thingfound = False + + Set tsSource = myFSOSource.OpenTextFile(SOCFile, ForReading, False) + Set tsTarget = myFSOTarget.OpenTextFile(SOCTemp, ForWriting, True) + + Do While Not tsSource.AtEndOfStream + line = tsSource.ReadLine + word = UCase(FirstToken(line)) + word2 = UCase(SecondToken(line)) + + 'If the current thing exists in the SOC, delete it. + If word = "THING" And Val(word2) = num Then + thingfound = True + Do While Len(TrimComplete(tsSource.ReadLine)) > 0 And Not (tsSource.AtEndOfStream) + Loop + Else + tsTarget.WriteLine line + End If + Loop + + tsSource.Close + Set myFSOSource = Nothing + + If Remove = False Then + If line <> "" Then tsTarget.WriteLine "" + tsTarget.WriteLine "Thing " & num + txtDoomednum.Text = TrimComplete(txtDoomednum.Text) + cmbSpawnstate.Text = TrimComplete(cmbSpawnstate.Text) + txtSpawnhealth.Text = TrimComplete(txtSpawnhealth.Text) + cmbSeestate.Text = TrimComplete(cmbSeestate.Text) + cmbSeesound.Text = TrimComplete(cmbSeesound.Text) + txtReactiontime.Text = TrimComplete(txtReactiontime.Text) + cmbAttacksound.Text = TrimComplete(cmbAttacksound.Text) + cmbPainstate.Text = TrimComplete(cmbPainstate.Text) + txtPainchance.Text = TrimComplete(txtPainchance.Text) + cmbPainsound.Text = TrimComplete(cmbPainsound.Text) + cmbMeleestate.Text = TrimComplete(cmbMeleestate.Text) + cmbMissilestate.Text = TrimComplete(cmbMissilestate.Text) + cmbDeathstate.Text = TrimComplete(cmbDeathstate.Text) + cmbDeathsound.Text = TrimComplete(cmbDeathsound.Text) + cmbXdeathstate.Text = TrimComplete(cmbXdeathstate.Text) + txtSpeed.Text = TrimComplete(txtSpeed.Text) + txtRadius.Text = TrimComplete(txtRadius.Text) + txtHeight.Text = TrimComplete(txtHeight.Text) + txtMass.Text = TrimComplete(txtMass.Text) + txtDamage.Text = TrimComplete(txtDamage.Text) + cmbActivesound.Text = TrimComplete(cmbActivesound.Text) + cmbRaisestate.Text = TrimComplete(cmbRaisestate.Text) + flags = 0 + ' Only 31 bits can be used, because VB is stupid. + For i = 0 To 26 + If chkFlags(i).Value = 1 Then flags = flags + Val(chkFlags(i).Tag) + Next + If txtDoomednum.Text <> "" Then tsTarget.WriteLine "MAPTHINGNUM = " & Val(txtDoomednum.Text) + If cmbSpawnstate.Text <> "" Then tsTarget.WriteLine "SPAWNSTATE = " & Val(cmbSpawnstate.Text) + If txtSpawnhealth.Text <> "" Then tsTarget.WriteLine "SPAWNHEALTH = " & Val(txtSpawnhealth.Text) + If cmbSeestate.Text <> "" Then tsTarget.WriteLine "SEESTATE = " & Val(cmbSeestate.Text) + If cmbSeesound.Text <> "" Then tsTarget.WriteLine "SEESOUND = " & Val(cmbSeesound.Text) + If txtReactiontime.Text <> "" Then tsTarget.WriteLine "REACTIONTIME = " & Val(txtReactiontime.Text) + If cmbAttacksound.Text <> "" Then tsTarget.WriteLine "ATTACKSOUND = " & Val(cmbAttacksound.Text) + If cmbPainstate.Text <> "" Then tsTarget.WriteLine "PAINSTATE = " & Val(cmbPainstate.Text) + If txtPainchance.Text <> "" Then tsTarget.WriteLine "PAINCHANCE = " & Val(txtPainchance.Text) + If cmbPainsound.Text <> "" Then tsTarget.WriteLine "PAINSOUND = " & Val(cmbPainsound.Text) + If cmbMeleestate.Text <> "" Then tsTarget.WriteLine "MELEESTATE = " & Val(cmbMeleestate.Text) + If cmbMissilestate.Text <> "" Then tsTarget.WriteLine "MISSILESTATE = " & Val(cmbMissilestate.Text) + If cmbDeathstate.Text <> "" Then tsTarget.WriteLine "DEATHSTATE = " & Val(cmbDeathstate.Text) + If cmbDeathsound.Text <> "" Then tsTarget.WriteLine "DEATHSOUND = " & Val(cmbDeathsound.Text) + If cmbXdeathstate.Text <> "" Then tsTarget.WriteLine "XDEATHSTATE = " & Val(cmbXdeathstate.Text) + If txtSpeed.Text <> "" Then tsTarget.WriteLine "SPEED = " & Val(txtSpeed.Text) + If txtRadius.Text <> "" Then tsTarget.WriteLine "RADIUS = " & Val(txtRadius.Text) + If txtHeight.Text <> "" Then tsTarget.WriteLine "HEIGHT = " & Val(txtHeight.Text) + If txtMass.Text <> "" Then tsTarget.WriteLine "MASS = " & Val(txtMass.Text) + If txtDamage.Text <> "" Then tsTarget.WriteLine "DAMAGE = " & Val(txtDamage.Text) + If cmbActivesound.Text <> "" Then tsTarget.WriteLine "ACTIVESOUND = " & Val(cmbActivesound.Text) + If cmbRaisestate.Text <> "" Then tsTarget.WriteLine "RAISESTATE = " & Val(cmbRaisestate.Text) + tsTarget.WriteLine "FLAGS = " & flags + End If + + tsTarget.Close + Set myFSOTarget = Nothing + + FileCopy SOCTemp, SOCFile + + Kill SOCTemp + + If Remove = True Then + If thingfound = True Then + MsgBox "Thing removed from SOC." + Else + MsgBox "Thing not found in SOC." + End If + Else + MsgBox "Thing Saved." + End If +End Sub diff --git a/tools/SOCEdit/Things.frx b/tools/SOCEdit/Things.frx new file mode 100644 index 000000000..980538679 Binary files /dev/null and b/tools/SOCEdit/Things.frx differ diff --git a/tools/SOCEdit/frmCharacterEdit.frm b/tools/SOCEdit/frmCharacterEdit.frm new file mode 100644 index 000000000..415fcbb0f --- /dev/null +++ b/tools/SOCEdit/frmCharacterEdit.frm @@ -0,0 +1,320 @@ +VERSION 5.00 +Begin VB.Form frmCharacterEdit + Caption = "Character Edit" + ClientHeight = 3345 + ClientLeft = 60 + ClientTop = 345 + ClientWidth = 4680 + Icon = "frmCharacterEdit.frx":0000 + LinkTopic = "Form1" + MaxButton = 0 'False + ScaleHeight = 3345 + ScaleWidth = 4680 + Begin VB.CommandButton cmdExample + Caption = "Show Me An &Example" + Height = 495 + Left = 1320 + Style = 1 'Graphical + TabIndex = 14 + Top = 2400 + Width = 975 + End + Begin VB.CheckBox chkEnabled + Caption = "Enable this player selection." + Height = 495 + Left = 1080 + TabIndex = 13 + Top = 1560 + Width = 1455 + End + Begin VB.CommandButton cmdDelete + Caption = "&Delete from SOC" + Height = 495 + Left = 120 + Style = 1 'Graphical + TabIndex = 12 + Top = 2760 + Width = 855 + End + Begin VB.CommandButton cmdSave + Caption = "&Save" + Height = 495 + Left = 120 + TabIndex = 11 + Top = 2160 + Width = 855 + End + Begin VB.TextBox txtSkinname + Height = 285 + Left = 3240 + TabIndex = 9 + Top = 1200 + Width = 1335 + End + Begin VB.TextBox txtPicname + Height = 285 + Left = 3240 + MaxLength = 8 + TabIndex = 7 + Top = 840 + Width = 1095 + End + Begin VB.TextBox txtMenuposition + Height = 285 + Left = 3240 + MaxLength = 3 + TabIndex = 5 + Top = 480 + Width = 495 + End + Begin VB.TextBox txtPlayername + Height = 285 + Left = 3240 + MaxLength = 64 + TabIndex = 3 + Top = 120 + Width = 1335 + End + Begin VB.TextBox txtPlayertext + Height = 1455 + Left = 2640 + MultiLine = -1 'True + TabIndex = 1 + Top = 1800 + Width = 1935 + End + Begin VB.ListBox lstPlayers + Height = 1815 + ItemData = "frmCharacterEdit.frx":0442 + Left = 120 + List = "frmCharacterEdit.frx":0461 + TabIndex = 0 + Top = 240 + Width = 855 + End + Begin VB.Label lblSkinname + Caption = "Name of player (skin) to use:" + Height = 255 + Left = 1080 + TabIndex = 10 + Top = 1200 + Width = 2055 + End + Begin VB.Label lblPicname + Alignment = 1 'Right Justify + Caption = "Picture to display:" + Height = 255 + Left = 1560 + TabIndex = 8 + Top = 840 + Width = 1575 + End + Begin VB.Label lblMenuposition + Alignment = 1 'Right Justify + Caption = "Vertical menu position:" + Height = 255 + Left = 1320 + TabIndex = 6 + Top = 480 + Width = 1815 + End + Begin VB.Label lblPlayername + Alignment = 1 'Right Justify + Caption = "Displayed name of player:" + Height = 255 + Left = 1320 + TabIndex = 4 + Top = 120 + Width = 1815 + End + Begin VB.Label lblPlayertext + Caption = "Short Description:" + Height = 255 + Left = 2640 + TabIndex = 2 + Top = 1560 + Width = 1455 + End +End +Attribute VB_Name = "frmCharacterEdit" +Attribute VB_GlobalNameSpace = False +Attribute VB_Creatable = False +Attribute VB_PredeclaredId = True +Attribute VB_Exposed = False +Option Explicit + +Private Sub cmdDelete_Click() + Call WriteCharacter(True) +End Sub + +Private Sub cmdExample_Click() + txtPlayername.Text = "SONIC" + txtMenuposition.Text = "20" + txtPicname.Text = "SONCCHAR" + txtSkinname.Text = "SONIC" + chkEnabled.Value = 1 + txtPlayertext.Text = " Fastest" & vbCrLf & " Speed Thok" & vbCrLf & " Not a good pick" & vbCrLf & "for starters, but when" & vbCrLf & "controlled properly," & vbCrLf & "Sonic is the most" & vbCrLf & "powerful of the three." +End Sub + +Private Sub cmdSave_Click() + Call WriteCharacter(False) +End Sub + +Private Sub ClearForm() + txtPlayername.Text = "" + txtMenuposition.Text = "" + txtPicname.Text = "" + txtSkinname.Text = "" + chkEnabled.Value = 0 + txtPlayertext.Text = "" +End Sub + +Private Sub ReadSOCPlayer(num As Integer) + Dim myFSO As New Scripting.FileSystemObject + Dim ts As TextStream + Dim line As String + Dim word As String + Dim word2 As String + + Set ts = myFSO.OpenTextFile(SOCFile, ForReading, False) + +SOCLoad: + Do While Not ts.AtEndOfStream + line = ts.ReadLine + + If Left(line, 1) = "#" Then GoTo SOCLoad + + If Left(line, 1) = vbCrLf Then GoTo SOCLoad + + If Len(line) < 1 Then GoTo SOCLoad + + word = FirstToken(line) + word2 = SecondToken(line) + + If UCase(word) = "CHARACTER" And Val(word2) = num Then + Do While Len(line) > 0 And Not ts.AtEndOfStream + line = ts.ReadLine + word = UCase(FirstToken(line)) + word2 = UCase(SecondTokenEqual(line)) + + If word = "PLAYERTEXT" Then + Dim startclip As Integer, endclip As Integer + startclip = InStr(line, "=") + + startclip = startclip + 2 + + line = Mid(line, startclip, Len(line)) + + txtPlayertext.Text = line & vbCrLf + + Do While InStr(line, "#") = 0 And Not ts.AtEndOfStream + line = ts.ReadLine & vbCrLf + txtPlayertext.Text = txtPlayertext.Text & line + Loop + + txtPlayertext.Text = RTrimComplete(txtPlayertext.Text) + If Right(txtPlayertext.Text, 1) = "#" Then + txtPlayertext.Text = Left(txtPlayertext.Text, Len(txtPlayertext.Text) - 1) + End If + ElseIf word = "PLAYERNAME" Then + txtPlayername.Text = word2 + ElseIf word = "MENUPOSITION" Then + txtMenuposition.Text = Val(word2) + ElseIf word = "PICNAME" Then + txtPicname.Text = word2 + ElseIf word = "STATUS" Then + If Val(word2) = 32 Then + chkEnabled.Value = 1 + Else + chkEnabled.Value = 0 + End If + ElseIf word = "SKINNAME" Then + txtSkinname.Text = word2 + ElseIf Len(line) > 0 And Left(line, 1) <> "#" Then + MsgBox "Error in SOC!" & vbCrLf & "Unknown line: " & line + End If + Loop + Exit Do + End If + Loop + + ts.Close + Set myFSO = Nothing +End Sub + +Private Sub lstPlayers_Click() + Call ClearForm + Call ReadSOCPlayer(lstPlayers.ListIndex) +End Sub + +Private Sub WriteCharacter(Remove As Boolean) + Dim myFSOSource As New Scripting.FileSystemObject + Dim tsSource As TextStream + Dim myFSOTarget As New Scripting.FileSystemObject + Dim tsTarget As TextStream + Dim line As String + Dim word As String + Dim word2 As String + Dim charfound As Boolean + + charfound = False + + Set tsSource = myFSOSource.OpenTextFile(SOCFile, ForReading, False) + Set tsTarget = myFSOTarget.OpenTextFile(SOCTemp, ForWriting, True) + + Do While Not tsSource.AtEndOfStream + line = tsSource.ReadLine + word = UCase(FirstToken(line)) + word2 = UCase(SecondToken(line)) + + 'If the current character exists in the SOC, delete it. + If word = "CHARACTER" And Val(word2) = lstPlayers.ListIndex Then + charfound = True + Do While Len(TrimComplete(tsSource.ReadLine)) > 0 And Not (tsSource.AtEndOfStream) + Loop + Else + tsTarget.WriteLine line + End If + Loop + + tsSource.Close + Set myFSOSource = Nothing + + If Remove = False Then + If line <> "" Then tsTarget.WriteLine "" + + tsTarget.WriteLine "CHARACTER " & lstPlayers.ListIndex + txtPlayername.Text = TrimComplete(txtPlayername.Text) + txtMenuposition.Text = TrimComplete(txtMenuposition.Text) + txtPicname.Text = TrimComplete(txtPicname.Text) + txtSkinname.Text = TrimComplete(txtSkinname.Text) + If txtPlayername.Text <> "" Then tsTarget.WriteLine "PLAYERNAME = " & txtPlayername.Text + If txtMenuposition.Text <> "" Then tsTarget.WriteLine "MENUPOSITION = " & Val(txtMenuposition.Text) + If txtPicname.Text <> "" Then tsTarget.WriteLine "PICNAME = " & txtPicname.Text + If txtSkinname.Text <> "" Then tsTarget.WriteLine "SKINNAME = " & txtSkinname.Text + If chkEnabled.Value = 1 Then + tsTarget.WriteLine "STATUS = 32" + Else + tsTarget.WriteLine "STATUS = 0" + End If + If txtPlayertext.Text <> "" Then tsTarget.WriteLine "PLAYERTEXT = " & txtPlayertext.Text & "#" + End If + + tsTarget.Close + Set myFSOTarget = Nothing + + FileCopy SOCTemp, SOCFile + + Kill SOCTemp + + If Remove = True Then + If charfound = True Then + MsgBox "Player choice removed from SOC." + Else + MsgBox "Player choice not found in SOC." + End If + Else + MsgBox "Character Saved." + End If +End Sub + diff --git a/tools/SOCEdit/frmCharacterEdit.frx b/tools/SOCEdit/frmCharacterEdit.frx new file mode 100644 index 000000000..5e767f4ab Binary files /dev/null and b/tools/SOCEdit/frmCharacterEdit.frx differ diff --git a/tools/SOCEdit/frmCutsceneEdit.frm b/tools/SOCEdit/frmCutsceneEdit.frm new file mode 100644 index 000000000..7fb18feed --- /dev/null +++ b/tools/SOCEdit/frmCutsceneEdit.frm @@ -0,0 +1,1365 @@ +VERSION 5.00 +Begin VB.Form frmCutsceneEdit + Caption = "Cutscene Edit" + ClientHeight = 6495 + ClientLeft = 60 + ClientTop = 345 + ClientWidth = 10410 + Icon = "frmCutsceneEdit.frx":0000 + LinkTopic = "Form1" + MaxButton = 0 'False + ScaleHeight = 6495 + ScaleWidth = 10410 + StartUpPosition = 3 'Windows Default + Begin VB.TextBox txtNumScenes + Height = 285 + Left = 3480 + MaxLength = 3 + TabIndex = 97 + Top = 240 + Width = 615 + End + Begin VB.ListBox lstScene + Height = 450 + ItemData = "frmCutsceneEdit.frx":0442 + Left = 3360 + List = "frmCutsceneEdit.frx":0444 + TabIndex = 94 + Top = 600 + Width = 735 + End + Begin VB.ComboBox cmbMusicslot + Height = 315 + Left = 8760 + TabIndex = 93 + Top = 1680 + Width = 1575 + End + Begin VB.Frame frmPic1 + Caption = "Picture 8:" + Height = 1335 + Index = 7 + Left = 7440 + TabIndex = 80 + Top = 5040 + Width = 2895 + Begin VB.TextBox txtPicycoord + Height = 285 + Index = 7 + Left = 600 + MaxLength = 3 + TabIndex = 85 + Top = 960 + Width = 495 + End + Begin VB.TextBox txtPicXcoord + Height = 285 + Index = 7 + Left = 600 + MaxLength = 3 + TabIndex = 84 + Top = 600 + Width = 495 + End + Begin VB.TextBox txtPicduration + Height = 285 + Index = 7 + Left = 2040 + MaxLength = 5 + TabIndex = 83 + Top = 600 + Width = 735 + End + Begin VB.TextBox txtPicname + Height = 285 + Index = 7 + Left = 1320 + TabIndex = 82 + Top = 240 + Width = 1455 + End + Begin VB.CheckBox chkPichires + Caption = "High-Resolution" + Height = 255 + Index = 7 + Left = 1320 + TabIndex = 81 + Top = 960 + Width = 1455 + End + Begin VB.Label lblPicycoord + Alignment = 1 'Right Justify + Caption = "Y:" + Height = 255 + Index = 7 + Left = 240 + TabIndex = 89 + Top = 960 + Width = 255 + End + Begin VB.Label lblPicxcoord + Alignment = 1 'Right Justify + Caption = "X:" + Height = 255 + Index = 7 + Left = 240 + TabIndex = 88 + Top = 600 + Width = 255 + End + Begin VB.Label lblPicduration + Alignment = 1 'Right Justify + Caption = "Duration:" + Height = 255 + Index = 7 + Left = 1200 + TabIndex = 87 + Top = 600 + Width = 735 + End + Begin VB.Label lblPicname + Alignment = 1 'Right Justify + Caption = "Picture Name:" + Height = 255 + Index = 7 + Left = 120 + TabIndex = 86 + Top = 240 + Width = 1095 + End + End + Begin VB.Frame frmPic1 + Caption = "Picture 7:" + Height = 1335 + Index = 6 + Left = 4440 + TabIndex = 70 + Top = 5040 + Width = 2895 + Begin VB.TextBox txtPicycoord + Height = 285 + Index = 6 + Left = 600 + MaxLength = 3 + TabIndex = 75 + Top = 960 + Width = 495 + End + Begin VB.TextBox txtPicXcoord + Height = 285 + Index = 6 + Left = 600 + MaxLength = 3 + TabIndex = 74 + Top = 600 + Width = 495 + End + Begin VB.TextBox txtPicduration + Height = 285 + Index = 6 + Left = 2040 + MaxLength = 5 + TabIndex = 73 + Top = 600 + Width = 735 + End + Begin VB.TextBox txtPicname + Height = 285 + Index = 6 + Left = 1320 + TabIndex = 72 + Top = 240 + Width = 1455 + End + Begin VB.CheckBox chkPichires + Caption = "High-Resolution" + Height = 255 + Index = 6 + Left = 1320 + TabIndex = 71 + Top = 960 + Width = 1455 + End + Begin VB.Label lblPicycoord + Alignment = 1 'Right Justify + Caption = "Y:" + Height = 255 + Index = 6 + Left = 240 + TabIndex = 79 + Top = 960 + Width = 255 + End + Begin VB.Label lblPicxcoord + Alignment = 1 'Right Justify + Caption = "X:" + Height = 255 + Index = 6 + Left = 240 + TabIndex = 78 + Top = 600 + Width = 255 + End + Begin VB.Label lblPicduration + Alignment = 1 'Right Justify + Caption = "Duration:" + Height = 255 + Index = 6 + Left = 1200 + TabIndex = 77 + Top = 600 + Width = 735 + End + Begin VB.Label lblPicname + Alignment = 1 'Right Justify + Caption = "Picture Name:" + Height = 255 + Index = 6 + Left = 120 + TabIndex = 76 + Top = 240 + Width = 1095 + End + End + Begin VB.Frame frmPic1 + Caption = "Picture 6:" + Height = 1335 + Index = 5 + Left = 7440 + TabIndex = 60 + Top = 3600 + Width = 2895 + Begin VB.TextBox txtPicycoord + Height = 285 + Index = 5 + Left = 600 + MaxLength = 3 + TabIndex = 65 + Top = 960 + Width = 495 + End + Begin VB.TextBox txtPicXcoord + Height = 285 + Index = 5 + Left = 600 + MaxLength = 3 + TabIndex = 64 + Top = 600 + Width = 495 + End + Begin VB.TextBox txtPicduration + Height = 285 + Index = 5 + Left = 2040 + MaxLength = 5 + TabIndex = 63 + Top = 600 + Width = 735 + End + Begin VB.TextBox txtPicname + Height = 285 + Index = 5 + Left = 1320 + TabIndex = 62 + Top = 240 + Width = 1455 + End + Begin VB.CheckBox chkPichires + Caption = "High-Resolution" + Height = 255 + Index = 5 + Left = 1320 + TabIndex = 61 + Top = 960 + Width = 1455 + End + Begin VB.Label lblPicycoord + Alignment = 1 'Right Justify + Caption = "Y:" + Height = 255 + Index = 5 + Left = 240 + TabIndex = 69 + Top = 960 + Width = 255 + End + Begin VB.Label lblPicxcoord + Alignment = 1 'Right Justify + Caption = "X:" + Height = 255 + Index = 5 + Left = 240 + TabIndex = 68 + Top = 600 + Width = 255 + End + Begin VB.Label lblPicduration + Alignment = 1 'Right Justify + Caption = "Duration:" + Height = 255 + Index = 5 + Left = 1200 + TabIndex = 67 + Top = 600 + Width = 735 + End + Begin VB.Label lblPicname + Alignment = 1 'Right Justify + Caption = "Picture Name:" + Height = 255 + Index = 5 + Left = 120 + TabIndex = 66 + Top = 240 + Width = 1095 + End + End + Begin VB.Frame frmPic1 + Caption = "Picture 5:" + Height = 1335 + Index = 4 + Left = 4440 + TabIndex = 50 + Top = 3600 + Width = 2895 + Begin VB.TextBox txtPicycoord + Height = 285 + Index = 4 + Left = 600 + MaxLength = 3 + TabIndex = 55 + Top = 960 + Width = 495 + End + Begin VB.TextBox txtPicXcoord + Height = 285 + Index = 4 + Left = 600 + MaxLength = 3 + TabIndex = 54 + Top = 600 + Width = 495 + End + Begin VB.TextBox txtPicduration + Height = 285 + Index = 4 + Left = 2040 + MaxLength = 5 + TabIndex = 53 + Top = 600 + Width = 735 + End + Begin VB.TextBox txtPicname + Height = 285 + Index = 4 + Left = 1320 + TabIndex = 52 + Top = 240 + Width = 1455 + End + Begin VB.CheckBox chkPichires + Caption = "High-Resolution" + Height = 255 + Index = 4 + Left = 1320 + TabIndex = 51 + Top = 960 + Width = 1455 + End + Begin VB.Label lblPicycoord + Alignment = 1 'Right Justify + Caption = "Y:" + Height = 255 + Index = 4 + Left = 240 + TabIndex = 59 + Top = 960 + Width = 255 + End + Begin VB.Label lblPicxcoord + Alignment = 1 'Right Justify + Caption = "X:" + Height = 255 + Index = 4 + Left = 240 + TabIndex = 58 + Top = 600 + Width = 255 + End + Begin VB.Label lblPicduration + Alignment = 1 'Right Justify + Caption = "Duration:" + Height = 255 + Index = 4 + Left = 1200 + TabIndex = 57 + Top = 600 + Width = 735 + End + Begin VB.Label lblPicname + Alignment = 1 'Right Justify + Caption = "Picture Name:" + Height = 255 + Index = 4 + Left = 120 + TabIndex = 56 + Top = 240 + Width = 1095 + End + End + Begin VB.Frame frmPic1 + Caption = "Picture 4:" + Height = 1335 + Index = 3 + Left = 1440 + TabIndex = 40 + Top = 3600 + Width = 2895 + Begin VB.CheckBox chkPichires + Caption = "High-Resolution" + Height = 255 + Index = 3 + Left = 1320 + TabIndex = 45 + Top = 960 + Width = 1455 + End + Begin VB.TextBox txtPicname + Height = 285 + Index = 3 + Left = 1320 + TabIndex = 44 + Top = 240 + Width = 1455 + End + Begin VB.TextBox txtPicduration + Height = 285 + Index = 3 + Left = 2040 + MaxLength = 5 + TabIndex = 43 + Top = 600 + Width = 735 + End + Begin VB.TextBox txtPicXcoord + Height = 285 + Index = 3 + Left = 600 + MaxLength = 3 + TabIndex = 42 + Top = 600 + Width = 495 + End + Begin VB.TextBox txtPicycoord + Height = 285 + Index = 3 + Left = 600 + MaxLength = 3 + TabIndex = 41 + Top = 960 + Width = 495 + End + Begin VB.Label lblPicname + Alignment = 1 'Right Justify + Caption = "Picture Name:" + Height = 255 + Index = 3 + Left = 120 + TabIndex = 49 + Top = 240 + Width = 1095 + End + Begin VB.Label lblPicduration + Alignment = 1 'Right Justify + Caption = "Duration:" + Height = 255 + Index = 3 + Left = 1200 + TabIndex = 48 + Top = 600 + Width = 735 + End + Begin VB.Label lblPicxcoord + Alignment = 1 'Right Justify + Caption = "X:" + Height = 255 + Index = 3 + Left = 240 + TabIndex = 47 + Top = 600 + Width = 255 + End + Begin VB.Label lblPicycoord + Alignment = 1 'Right Justify + Caption = "Y:" + Height = 255 + Index = 3 + Left = 240 + TabIndex = 46 + Top = 960 + Width = 255 + End + End + Begin VB.Frame frmPic1 + Caption = "Picture 3:" + Height = 1335 + Index = 2 + Left = 7440 + TabIndex = 30 + Top = 2160 + Width = 2895 + Begin VB.CheckBox chkPichires + Caption = "High-Resolution" + Height = 255 + Index = 2 + Left = 1320 + TabIndex = 35 + Top = 960 + Width = 1455 + End + Begin VB.TextBox txtPicname + Height = 285 + Index = 2 + Left = 1320 + TabIndex = 34 + Top = 240 + Width = 1455 + End + Begin VB.TextBox txtPicduration + Height = 285 + Index = 2 + Left = 2040 + MaxLength = 5 + TabIndex = 33 + Top = 600 + Width = 735 + End + Begin VB.TextBox txtPicXcoord + Height = 285 + Index = 2 + Left = 600 + MaxLength = 3 + TabIndex = 32 + Top = 600 + Width = 495 + End + Begin VB.TextBox txtPicycoord + Height = 285 + Index = 2 + Left = 600 + MaxLength = 3 + TabIndex = 31 + Top = 960 + Width = 495 + End + Begin VB.Label lblPicname + Alignment = 1 'Right Justify + Caption = "Picture Name:" + Height = 255 + Index = 2 + Left = 120 + TabIndex = 39 + Top = 240 + Width = 1095 + End + Begin VB.Label lblPicduration + Alignment = 1 'Right Justify + Caption = "Duration:" + Height = 255 + Index = 2 + Left = 1200 + TabIndex = 38 + Top = 600 + Width = 735 + End + Begin VB.Label lblPicxcoord + Alignment = 1 'Right Justify + Caption = "X:" + Height = 255 + Index = 2 + Left = 240 + TabIndex = 37 + Top = 600 + Width = 255 + End + Begin VB.Label lblPicycoord + Alignment = 1 'Right Justify + Caption = "Y:" + Height = 255 + Index = 2 + Left = 240 + TabIndex = 36 + Top = 960 + Width = 255 + End + End + Begin VB.Frame frmPic1 + Caption = "Picture 2:" + Height = 1335 + Index = 1 + Left = 4440 + TabIndex = 20 + Top = 2160 + Width = 2895 + Begin VB.CheckBox chkPichires + Caption = "High-Resolution" + Height = 255 + Index = 1 + Left = 1320 + TabIndex = 25 + Top = 960 + Width = 1455 + End + Begin VB.TextBox txtPicname + Height = 285 + Index = 1 + Left = 1320 + TabIndex = 24 + Top = 240 + Width = 1455 + End + Begin VB.TextBox txtPicduration + Height = 285 + Index = 1 + Left = 2040 + MaxLength = 5 + TabIndex = 23 + Top = 600 + Width = 735 + End + Begin VB.TextBox txtPicXcoord + Height = 285 + Index = 1 + Left = 600 + MaxLength = 3 + TabIndex = 22 + Top = 600 + Width = 495 + End + Begin VB.TextBox txtPicycoord + Height = 285 + Index = 1 + Left = 600 + MaxLength = 3 + TabIndex = 21 + Top = 960 + Width = 495 + End + Begin VB.Label lblPicname + Alignment = 1 'Right Justify + Caption = "Picture Name:" + Height = 255 + Index = 1 + Left = 120 + TabIndex = 29 + Top = 240 + Width = 1095 + End + Begin VB.Label lblPicduration + Alignment = 1 'Right Justify + Caption = "Duration:" + Height = 255 + Index = 1 + Left = 1200 + TabIndex = 28 + Top = 600 + Width = 735 + End + Begin VB.Label lblPicxcoord + Alignment = 1 'Right Justify + Caption = "X:" + Height = 255 + Index = 1 + Left = 240 + TabIndex = 27 + Top = 600 + Width = 255 + End + Begin VB.Label lblPicycoord + Alignment = 1 'Right Justify + Caption = "Y:" + Height = 255 + Index = 1 + Left = 240 + TabIndex = 26 + Top = 960 + Width = 255 + End + End + Begin VB.TextBox txtTextypos + Height = 285 + Left = 3120 + MaxLength = 3 + TabIndex = 19 + Top = 5880 + Width = 615 + End + Begin VB.TextBox txtTextxpos + Height = 285 + Left = 3120 + MaxLength = 3 + TabIndex = 18 + Top = 5520 + Width = 615 + End + Begin VB.Frame frmPic1 + Caption = "Picture 1:" + Height = 1335 + Index = 0 + Left = 1440 + TabIndex = 6 + Top = 2160 + Width = 2895 + Begin VB.TextBox txtPicycoord + Height = 285 + Index = 0 + Left = 600 + MaxLength = 3 + TabIndex = 14 + Top = 960 + Width = 495 + End + Begin VB.TextBox txtPicXcoord + Height = 285 + Index = 0 + Left = 600 + MaxLength = 3 + TabIndex = 12 + Top = 600 + Width = 495 + End + Begin VB.TextBox txtPicduration + Height = 285 + Index = 0 + Left = 2040 + MaxLength = 5 + TabIndex = 11 + Top = 600 + Width = 735 + End + Begin VB.TextBox txtPicname + Height = 285 + Index = 0 + Left = 1320 + TabIndex = 8 + Top = 240 + Width = 1455 + End + Begin VB.CheckBox chkPichires + Caption = "High-Resolution" + Height = 255 + Index = 0 + Left = 1320 + TabIndex = 7 + Top = 960 + Width = 1455 + End + Begin VB.Label lblPicycoord + Alignment = 1 'Right Justify + Caption = "Y:" + Height = 255 + Index = 0 + Left = 240 + TabIndex = 15 + Top = 960 + Width = 255 + End + Begin VB.Label lblPicxcoord + Alignment = 1 'Right Justify + Caption = "X:" + Height = 255 + Index = 0 + Left = 240 + TabIndex = 13 + Top = 600 + Width = 255 + End + Begin VB.Label lblPicduration + Alignment = 1 'Right Justify + Caption = "Duration:" + Height = 255 + Index = 0 + Left = 1200 + TabIndex = 10 + Top = 600 + Width = 735 + End + Begin VB.Label lblPicname + Alignment = 1 'Right Justify + Caption = "Picture Name:" + Height = 255 + Index = 0 + Left = 120 + TabIndex = 9 + Top = 240 + Width = 1095 + End + End + Begin VB.TextBox txtNumberofpics + Height = 285 + Left = 3840 + MaxLength = 1 + TabIndex = 5 + Top = 1800 + Width = 375 + End + Begin VB.TextBox txtScenetext + Height = 1815 + Left = 4440 + MultiLine = -1 'True + TabIndex = 3 + Top = 240 + Width = 3135 + End + Begin VB.CommandButton cmdSave + Caption = "&Save Scene" + Height = 495 + Left = 3360 + Style = 1 'Graphical + TabIndex = 1 + Top = 1200 + Width = 855 + End + Begin VB.ListBox lstCutscenes + Height = 6300 + ItemData = "frmCutsceneEdit.frx":0446 + Left = 120 + List = "frmCutsceneEdit.frx":0448 + TabIndex = 0 + Top = 120 + Width = 1215 + End + Begin VB.Label Label3 + Caption = "Note: The cutscene editor is not fully functional. Only use it to get an idea of the proper syntax to use." + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 1335 + Left = 7680 + TabIndex = 98 + Top = 240 + Width = 2655 + End + Begin VB.Label Label2 + Caption = "For Scene Text:" + BeginProperty Font + Name = "MS Sans Serif" + Size = 8.25 + Charset = 0 + Weight = 400 + Underline = -1 'True + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 255 + Left = 1560 + TabIndex = 96 + Top = 5160 + Width = 1695 + End + Begin VB.Label Label1 + Caption = "Enter all time durations in game tics (35 = 1 second)" + BeginProperty Font + Name = "MS Sans Serif" + Size = 8.25 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 855 + Left = 1560 + TabIndex = 95 + Top = 960 + Width = 1335 + End + Begin VB.Label lblMusicslot + Alignment = 1 'Right Justify + Caption = "Music to play:" + Height = 255 + Left = 7680 + TabIndex = 92 + Top = 1680 + Width = 975 + End + Begin VB.Label lblCurrentScene + Alignment = 1 'Right Justify + Caption = "Current Scene:" + Height = 255 + Left = 1920 + TabIndex = 91 + Top = 720 + Width = 1215 + End + Begin VB.Label lblNumScenes + Alignment = 1 'Right Justify + Caption = "Number of Scenes in this Cutscene:" + Height = 375 + Left = 1440 + TabIndex = 90 + Top = 120 + Width = 1935 + End + Begin VB.Label lblTextypos + Alignment = 1 'Right Justify + Caption = "Text Y Position:" + Height = 255 + Left = 1800 + TabIndex = 17 + Top = 5880 + Width = 1215 + End + Begin VB.Label lblTextxpos + Alignment = 1 'Right Justify + Caption = "Text X Position:" + Height = 255 + Left = 1800 + TabIndex = 16 + Top = 5520 + Width = 1215 + End + Begin VB.Label lblNumberofpics + Alignment = 1 'Right Justify + Caption = "Number of Pictures (max 8):" + Height = 255 + Left = 1560 + TabIndex = 4 + Top = 1800 + Width = 2175 + End + Begin VB.Label lblScenetext + Caption = "Scene Text:" + Height = 255 + Left = 4440 + TabIndex = 2 + Top = 0 + Width = 1215 + End +End +Attribute VB_Name = "frmCutsceneEdit" +Attribute VB_GlobalNameSpace = False +Attribute VB_Creatable = False +Attribute VB_PredeclaredId = True +Attribute VB_Exposed = False +Option Explicit + +Private Sub cmdSave_Click() + Call WriteScene(False) +End Sub + +Private Sub lstScene_Click() + Call ClearForm + Call LoadSOCCutscene(Val(lstCutscenes.List(lstCutscenes.ListIndex)), Val(lstScene.List(lstScene.ListIndex))) +End Sub + +Private Sub LoadMusic() + Dim myFSO As New Scripting.FileSystemObject + Dim ts As TextStream + Dim line As String + Dim number As Integer + Dim startclip As Integer, endclip As Integer + Dim addstring As String + + ChDir SourcePath + Set ts = myFSO.OpenTextFile("sounds.h", ForReading, False) + + Do While InStr(ts.ReadLine, "Music list (don't edit this comment!)") = 0 + Loop + + ts.SkipLine ' typedef enum + ts.SkipLine ' { + + line = ts.ReadLine + number = 0 + + cmbMusicslot.Clear + + Do While InStr(line, "NUMMUSIC") = 0 + startclip = InStr(line, "mus_") + If InStr(line, "mus_") <> 0 Then + endclip = InStr(line, ",") + line = Mid(line, startclip, endclip - startclip) + addstring = number & " - " & line + cmbMusicslot.AddItem addstring + number = number + 1 + End If + line = ts.ReadLine + Loop + + ts.Close + Set myFSO = Nothing +End Sub + +Private Sub cmdReload_Click() + Call Reload +End Sub + +Private Sub Form_Load() + Call Reload +End Sub + +Private Sub Reload() + ClearForm + Call ReadCutsceneSOCNumbers + Call LoadMusic + If lstCutscenes.ListCount > 0 Then + lstCutscenes.ListIndex = 0 + End If +End Sub + +Private Sub LoadSOCCutscene(CutNum As Integer, SceneNum As Integer) + Dim myFSO As New Scripting.FileSystemObject + Dim ts As TextStream + Dim line As String + Dim word As String + Dim word2 As String + Dim ind As Integer + + Set ts = myFSO.OpenTextFile(SOCFile, ForReading, False) + +SOCLoad: + Do While Not ts.AtEndOfStream + line = ts.ReadLine + + If Left(line, 1) = "#" Then GoTo SOCLoad + + If Left(line, 1) = vbCrLf Then GoTo SOCLoad + + If Len(line) < 1 Then GoTo SOCLoad + + word = FirstToken(line) + word2 = SecondToken(line) + + ' WOW! This looks fun, don't it?! + If UCase(word) = "CUTSCENE" And Val(word2) = CutNum Then + Do While Len(line) > 0 And Not ts.AtEndOfStream + line = ts.ReadLine + word = UCase(FirstToken(line)) + word2 = UCase(SecondToken(line)) + + If word = "NUMSCENES" Then + txtNumScenes.Text = Val(word2) + ElseIf UCase(word) = "SCENE" And Val(word2) = SceneNum Then + Do While Len(line) > 0 And Not ts.AtEndOfStream + line = ts.ReadLine + word = UCase(FirstToken(line)) + word2 = UCase(SecondTokenEqual(line)) + + If word = "SCENETEXT" Then + Dim startclip As Integer, endclip As Integer + startclip = InStr(line, "=") + + startclip = startclip + 2 + + line = Mid(line, startclip, Len(line)) + + txtScenetext.Text = line & vbCrLf + + Do While InStr(line, "#") = 0 And Not ts.AtEndOfStream + line = ts.ReadLine & vbCrLf + txtScenetext.Text = txtScenetext.Text & line + Loop + + txtScenetext.Text = RTrimComplete(txtScenetext.Text) + If Right(txtScenetext.Text, 1) = "#" Then + txtScenetext.Text = Left(txtScenetext.Text, Len(txtScenetext.Text) - 1) + End If + ElseIf word = "PIC1NAME" Or word = "PIC2NAME" Or word = "PIC3NAME" Or word = "PIC4NAME" Or word = "PIC5NAME" Or word = "PIC6NAME" Or word = "PIC7NAME" Or word = "PIC8NAME" Then + ind = Val(Mid(word, 4, 1)) - 1 + txtPicname(ind).Text = word2 + ElseIf word = "PIC1HIRES" Or word = "PIC2HIRES" Or word = "PIC3HIRES" Or word = "PIC4HIRES" Or word = "PIC5HIRES" Or word = "PIC6HIRES" Or word = "PIC7HIRES" Or word = "PIC8HIRES" Then + ind = Val(Mid(word, 4, 1)) - 1 + chkPichires(ind).Value = Val(word2) + ElseIf word = "PIC1DURATION" Or word = "PIC2DURATION" Or word = "PIC3DURATION" Or word = "PIC4DURATION" Or word = "PIC5DURATION" Or word = "PIC6DURATION" Or word = "PIC7DURATION" Or word = "PIC8DURATION" Then + ind = Val(Mid(word, 4, 1)) - 1 + txtPicduration(ind).Text = Val(word2) + ElseIf word = "PIC1XCOORD" Or word = "PIC2XCOORD" Or word = "PIC3XCOORD" Or word = "PIC4XCOORD" Or word = "PIC5XCOORD" Or word = "PIC6XCOORD" Or word = "PIC7XCOORD" Or word = "PIC8XCOORD" Then + ind = Val(Mid(word, 4, 1)) - 1 + txtPicXcoord(ind).Text = Val(word2) + ElseIf word = "PIC1YCOORD" Or word = "PIC2YCOORD" Or word = "PIC3YCOORD" Or word = "PIC4YCOORD" Or word = "PIC5YCOORD" Or word = "PIC6YCOORD" Or word = "PIC7YCOORD" Or word = "PIC8YCOORD" Then + ind = Val(Mid(word, 4, 1)) - 1 + txtPicycoord(ind).Text = Val(word2) + ElseIf word = "TEXTXPOS" Then + txtTextxpos.Text = Val(word2) + ElseIf word = "TEXTYPOS" Then + txtTextypos.Text = Val(word2) + ElseIf word = "MUSICSLOT" Then + cmbMusicslot.ListIndex = Val(word2) + ElseIf word = "NUMBEROFPICS" Then + txtNumberofpics.Text = Val(word2) + ElseIf word = "SCENE" Then 'End of scene data + line = "" + ElseIf Len(line) > 0 And Left(line, 1) <> "#" Then + MsgBox "Error in SOC!" & vbCrLf & "Unknown line: " & line + End If + Loop + End If + Loop + Exit Do + End If + Loop + + ts.Close + Set myFSO = Nothing +End Sub + +Private Sub ReadCutsceneSOCNumbers() + Dim myFSO As New Scripting.FileSystemObject + Dim ts As TextStream + Dim line As String + Dim word As String + Dim word2 As String + + Set ts = myFSO.OpenTextFile(SOCFile, ForReading, False) + + lstCutscenes.Clear + +CutsceneLoad: + Do While Not ts.AtEndOfStream + line = ts.ReadLine + + If Left(line, 1) = "#" Then GoTo CutsceneLoad + + If Left(line, 1) = vbCrLf Then GoTo CutsceneLoad + + If Len(line) < 1 Then GoTo CutsceneLoad + + word = FirstToken(line) + word2 = SecondToken(line) + + If UCase(word) = "CUTSCENE" Then + lstCutscenes.AddItem (Val(word2)) + End If + Loop + + ts.Close + Set myFSO = Nothing +End Sub + +Private Sub ClearForm() + Dim i As Integer + + For i = 0 To 7 + chkPichires(i).Value = 0 + txtPicXcoord(i).Text = "" + txtPicycoord(i).Text = "" + txtPicname(i).Text = "" + txtPicduration(i).Text = "" + Next + + txtScenetext.Text = "" + txtNumberofpics.Text = "" + txtTextxpos.Text = "" + txtTextypos.Text = "" + cmbMusicslot.Text = "" +End Sub + +Private Sub lstCutscenes_Click() + Dim i As Integer + + LoadNumScenes (Val(lstCutscenes.List(lstCutscenes.ListIndex))) + + lstScene.Clear + For i = 1 To Val(txtNumScenes.Text) + lstScene.AddItem i + Next + + If Val(txtNumScenes) > 0 Then + lstScene.ListIndex = lstScene.ListCount - 1 + lstScene.ListIndex = 0 + End If +End Sub + +Private Sub LoadNumScenes(CutNum As Integer) + Dim myFSO As New Scripting.FileSystemObject + Dim ts As TextStream + Dim line As String + Dim word As String + Dim word2 As String + Dim ind As Integer + + Set ts = myFSO.OpenTextFile(SOCFile, ForReading, False) + +SOCLoad: + Do While Not ts.AtEndOfStream + line = ts.ReadLine + + If Left(line, 1) = "#" Then GoTo SOCLoad + + If Left(line, 1) = vbCrLf Then GoTo SOCLoad + + If Len(line) < 1 Then GoTo SOCLoad + + word = FirstToken(line) + word2 = SecondToken(line) + + ' WOW! This looks fun, don't it?! + If UCase(word) = "CUTSCENE" And Val(word2) = CutNum Then + Do While Len(line) > 0 And Not ts.AtEndOfStream + line = ts.ReadLine + word = UCase(FirstToken(line)) + word2 = UCase(SecondToken(line)) + + If word = "NUMSCENES" Then + txtNumScenes.Text = Val(word2) + End If + Loop + Exit Do + End If + Loop + + ts.Close + Set myFSO = Nothing +End Sub + +Private Sub WriteScene(Remove As Boolean) + Dim myFSOSource As New Scripting.FileSystemObject + Dim tsSource As TextStream + Dim myFSOTarget As New Scripting.FileSystemObject + Dim tsTarget As TextStream + Dim line As String + Dim word As String + Dim word2 As String + Dim flags As Long + Dim i As Integer + Dim CutsceneNum As Integer + Dim InCutScene As Boolean + Dim scenefound As Boolean + Dim nevercheckagain As Boolean + + ' This whole sub is a mess, but it works, + ' so I'd better not touch it... + scenefound = False + nevercheckagain = False + + InCutScene = False + CutsceneNum = Val(lstCutscenes.List(lstCutscenes.ListIndex)) + + Set tsSource = myFSOSource.OpenTextFile(SOCFile, ForReading, False) + Set tsTarget = myFSOTarget.OpenTextFile(SOCTemp, ForWriting, True) + + Do While Not tsSource.AtEndOfStream + line = tsSource.ReadLine + word = UCase(FirstToken(line)) + word2 = UCase(SecondToken(line)) + + If nevercheckagain = False And word = "CUTSCENE" And Val(word2) = CutsceneNum Then + InCutScene = True + tsTarget.WriteLine "CUTSCENE " & Val(lstCutscenes.List(lstCutscenes.ListIndex)) + tsTarget.WriteLine "NUMSCENES " & Val(txtNumScenes.Text) + line = tsSource.ReadLine + word = UCase(FirstToken(line)) + word2 = UCase(SecondToken(line)) + If word = "NUMSCENES" Then + line = tsSource.ReadLine + word = UCase(FirstToken(line)) + word2 = UCase(SecondToken(line)) + End If + End If + + 'If the current scene exists in the SOC, delete it. + If nevercheckagain = False And InCutScene = True And word = "SCENE" And Val(word2) = Val(lstScene.List(lstScene.ListIndex)) Then + scenefound = True + line = tsSource.ReadLine + Do While (Left(UCase(line), 6) <> "SCENE " And Len(TrimComplete(line)) > 0) And Not (tsSource.AtEndOfStream) + line = tsSource.ReadLine + Loop + If Remove = False Then + tsTarget.WriteLine "SCENE " & Val(lstScene.List(lstScene.ListIndex)) + txtNumberofpics.Text = TrimComplete(txtNumberofpics.Text) + txtTextxpos.Text = TrimComplete(txtTextxpos.Text) + txtTextypos.Text = TrimComplete(txtTextypos.Text) + cmbMusicslot.Text = TrimComplete(cmbMusicslot.Text) + + For i = 0 To 7 + txtPicname(i).Text = TrimComplete(txtPicname(i).Text) + txtPicXcoord(i).Text = TrimComplete(txtPicXcoord(i).Text) + txtPicycoord(i).Text = TrimComplete(txtPicycoord(i).Text) + txtPicduration(i).Text = TrimComplete(txtPicduration(i).Text) + Next + + If txtNumberofpics.Text <> "" Then tsTarget.WriteLine "NUMBEROFPICS = " & Val(txtNumberofpics.Text) + If txtTextxpos.Text <> "" Then tsTarget.WriteLine "TEXTXPOS = " & Val(txtTextxpos.Text) + If txtTextypos.Text <> "" Then tsTarget.WriteLine "TEXTYPOS = " & Val(txtTextypos.Text) + If cmbMusicslot.Text <> "" Then tsTarget.WriteLine "MUSICSLOT = " & Val(cmbMusicslot.Text) + + For i = 0 To 7 + If txtPicname(i).Text <> "" Then tsTarget.WriteLine "PIC" & (i + 1) & "NAME = " & txtPicname(i).Text + + If chkPichires(i).Value = 1 Then tsTarget.WriteLine "PIC" & (i + 1) & "HIRES = 1" + + If txtPicXcoord(i).Text <> "" Then tsTarget.WriteLine "PIC" & (i + 1) & "XCOORD = " & Val(txtPicXcoord(i).Text) + If txtPicycoord(i).Text <> "" Then tsTarget.WriteLine "PIC" & (i + 1) & "YCOORD = " & Val(txtPicycoord(i).Text) + If txtPicduration(i).Text <> "" Then tsTarget.WriteLine "PIC" & (i + 1) & "DURATION = " & Val(txtPicduration(i).Text) + Next + If txtScenetext.Text <> "" Then tsTarget.WriteLine "SCENETEXT = " & txtScenetext.Text & "#" + End If + InCutScene = False + nevercheckagain = True + End If + tsTarget.WriteLine line + Loop + + tsSource.Close + Set myFSOSource = Nothing + + If Remove = False And scenefound = False Then + If line <> "" Then tsTarget.WriteLine "" + + tsTarget.WriteLine "CUTSCENE " & Val(lstCutscenes.List(lstCutscenes.ListIndex)) + tsTarget.WriteLine "NUMSCENES " & Val(txtNumScenes.Text) + tsTarget.WriteLine "SCENE " & Val(lstScene.List(lstScene.ListIndex)) + txtNumberofpics.Text = TrimComplete(txtNumberofpics.Text) + txtScenetext.Text = TrimComplete(txtScenetext.Text) + txtTextxpos.Text = TrimComplete(txtTextxpos.Text) + txtTextypos.Text = TrimComplete(txtTextypos.Text) + cmbMusicslot.Text = TrimComplete(cmbMusicslot.Text) + + For i = 0 To 7 + txtPicname(i).Text = TrimComplete(txtPicname(i).Text) + txtPicXcoord(i).Text = TrimComplete(txtPicXcoord(i).Text) + txtPicycoord(i).Text = TrimComplete(txtPicycoord(i).Text) + txtPicduration(i).Text = TrimComplete(txtPicduration(i).Text) + Next + + If txtNumberofpics.Text <> "" Then tsTarget.WriteLine "NUMBEROFPICS = " & Val(txtNumberofpics.Text) + If txtScenetext.Text <> "" Then tsTarget.WriteLine "SCENETEXT = " & txtScenetext.Text & "#" + If txtTextxpos.Text <> "" Then tsTarget.WriteLine "TEXTXPOS = " & Val(txtTextxpos.Text) + If txtTextypos.Text <> "" Then tsTarget.WriteLine "TEXTYPOS = " & Val(txtTextypos.Text) + If cmbMusicslot.Text <> "" Then tsTarget.WriteLine "MUSICSLOT = " & Val(cmbMusicslot.Text) + + For i = 0 To 7 + If txtPicname(i).Text <> "" Then tsTarget.WriteLine "PIC" & (i + 1) & "NAME = " & txtPicname(i).Text + + If chkPichires(i).Value = 1 Then tsTarget.WriteLine "PIC" & (i + 1) & "HIRES = 1" + + If txtPicXcoord(i).Text <> "" Then tsTarget.WriteLine "PIC" & (i + 1) & "XCOORD = " & Val(txtPicXcoord(i).Text) + If txtPicycoord(i).Text <> "" Then tsTarget.WriteLine "PIC" & (i + 1) & "YCOORD = " & Val(txtPicycoord(i).Text) + If txtPicduration(i).Text <> "" Then tsTarget.WriteLine "PIC" & (i + 1) & "DURATION = " & Val(txtPicduration(i).Text) + Next + End If + + tsTarget.Close + Set myFSOTarget = Nothing + + FileCopy SOCTemp, SOCFile + + Kill SOCTemp + + If Remove = True Then + If scenefound = True Then + MsgBox "Scene removed from SOC." + Else + MsgBox "Scene not found in SOC." + End If + Else + MsgBox "Scene Saved." + End If +End Sub diff --git a/tools/SOCEdit/frmCutsceneEdit.frx b/tools/SOCEdit/frmCutsceneEdit.frx new file mode 100644 index 000000000..6f844e643 Binary files /dev/null and b/tools/SOCEdit/frmCutsceneEdit.frx differ diff --git a/tools/SOCEdit/frmEmblemEdit.frm b/tools/SOCEdit/frmEmblemEdit.frm new file mode 100644 index 000000000..f94255b9c --- /dev/null +++ b/tools/SOCEdit/frmEmblemEdit.frm @@ -0,0 +1,384 @@ +VERSION 5.00 +Begin VB.Form frmEmblemEdit + Caption = "Emblem Edit" + ClientHeight = 2865 + ClientLeft = 60 + ClientTop = 345 + ClientWidth = 5160 + Icon = "frmEmblemEdit.frx":0000 + LinkTopic = "Form1" + MaxButton = 0 'False + ScaleHeight = 2865 + ScaleWidth = 5160 + StartUpPosition = 3 'Windows Default + Begin VB.CommandButton cmdDelete + Caption = "&Delete Last Emblem" + Height = 735 + Left = 1560 + Style = 1 'Graphical + TabIndex = 17 + Top = 600 + Width = 855 + End + Begin VB.CommandButton cmdAdd + Caption = "&Add" + Height = 375 + Left = 1560 + TabIndex = 16 + Top = 120 + Width = 855 + End + Begin VB.CommandButton cmdSave + Caption = "&Save Emblem" + Height = 495 + Left = 4200 + Style = 1 'Graphical + TabIndex = 13 + Top = 2280 + Width = 855 + End + Begin VB.CommandButton cmdReload + Caption = "&Reload" + Height = 495 + Left = 3120 + TabIndex = 12 + Top = 2280 + Width = 975 + End + Begin VB.TextBox txtPlayernum + Height = 285 + Left = 4320 + MaxLength = 3 + TabIndex = 9 + Top = 1800 + Width = 735 + End + Begin VB.TextBox txtMapnum + Height = 285 + Left = 4320 + MaxLength = 4 + TabIndex = 7 + Top = 1320 + Width = 735 + End + Begin VB.TextBox txtZ + Height = 285 + Left = 4320 + MaxLength = 5 + TabIndex = 3 + Top = 960 + Width = 735 + End + Begin VB.TextBox txtY + Height = 285 + Left = 4320 + MaxLength = 5 + TabIndex = 2 + Top = 600 + Width = 735 + End + Begin VB.TextBox txtX + Height = 285 + Left = 4320 + MaxLength = 5 + TabIndex = 1 + Top = 240 + Width = 735 + End + Begin VB.ListBox lstEmblems + Height = 2400 + Left = 120 + TabIndex = 0 + Top = 120 + Width = 1335 + End + Begin VB.Label Label1 + Caption = "Emblem #s must be linear, sorry!" + Height = 495 + Left = 1560 + TabIndex = 18 + Top = 2400 + Width = 1455 + End + Begin VB.Label lblNumEmblems + Caption = "# of Emblems:" + Height = 255 + Left = 120 + TabIndex = 15 + Top = 2520 + Width = 1335 + End + Begin VB.Label lblNote2 + Caption = "Don't forget to set Game Data file and # of Emblems in Global Game Settings!" + Height = 855 + Left = 1560 + TabIndex = 14 + Top = 1440 + Width = 1575 + End + Begin VB.Label lblNote + Appearance = 0 'Flat + BorderStyle = 1 'Fixed Single + Caption = "Note: Enter map coordinates, not game coordinates. (I.e., 128, not 8388608)" + ForeColor = &H80000008& + Height = 1095 + Left = 2640 + TabIndex = 11 + Top = 120 + Width = 1335 + End + Begin VB.Label lblPlayernum + Caption = "Player # (255 for all players):" + Height = 495 + Left = 3240 + TabIndex = 10 + Top = 1680 + Width = 1095 + End + Begin VB.Label lblMapnum + Alignment = 1 'Right Justify + Caption = "Map #:" + Height = 255 + Left = 3600 + TabIndex = 8 + Top = 1320 + Width = 615 + End + Begin VB.Label lblZ + Alignment = 1 'Right Justify + Caption = "Z:" + Height = 255 + Left = 3960 + TabIndex = 6 + Top = 960 + Width = 255 + End + Begin VB.Label lblY + Alignment = 1 'Right Justify + Caption = "Y:" + Height = 255 + Left = 3960 + TabIndex = 5 + Top = 600 + Width = 255 + End + Begin VB.Label lblX + Alignment = 1 'Right Justify + Caption = "X:" + Height = 255 + Left = 3960 + TabIndex = 4 + Top = 240 + Width = 255 + End +End +Attribute VB_Name = "frmEmblemEdit" +Attribute VB_GlobalNameSpace = False +Attribute VB_Creatable = False +Attribute VB_PredeclaredId = True +Attribute VB_Exposed = False +Option Explicit + +Private Sub cmdAdd_Click() + lstEmblems.AddItem "Emblem " & lstEmblems.ListCount + 1 + lstEmblems.ListIndex = lstEmblems.ListCount - 1 + lblNumEmblems.Caption = "# of Emblems: " & lstEmblems.ListCount + txtX.Text = 0 + txtY.Text = 0 + txtZ.Text = 0 + txtPlayernum.Text = 255 + txtMapnum.Text = 1 +End Sub + +Private Sub cmdDelete_Click() + Call WriteEmblem(True) + lstEmblems.RemoveItem lstEmblems.ListCount - 1 + lstEmblems.ListIndex = lstEmblems.ListCount - 1 + lblNumEmblems.Caption = "# of Emblems: " & lstEmblems.ListCount +End Sub + +Private Sub cmdReload_Click() + Call Reload +End Sub + +Private Sub Reload() + lstEmblems.Clear + txtX.Text = "" + txtY.Text = "" + txtZ.Text = "" + txtMapnum.Text = "" + txtPlayernum.Text = "" + lblNumEmblems.Caption = "# of Emblems: " & lstEmblems.ListCount + Call ReadSOCEmblems +End Sub + +Private Sub cmdSave_Click() + If lstEmblems.ListCount <= 0 Then + MsgBox "You have no emblems to save!" + Else + Call WriteEmblem(False) + End If +End Sub + +Private Sub Form_Load() + Call Reload +End Sub + +Private Sub ReadSOCEmblems() + Dim myFSO As New Scripting.FileSystemObject + Dim ts As TextStream + Dim line As String + Dim word As String + Dim word2 As String + + Set ts = myFSO.OpenTextFile(SOCFile, ForReading, False) + + lstEmblems.Clear + +EmblemLoad: + Do While Not ts.AtEndOfStream + line = ts.ReadLine + + If Left(line, 1) = "#" Then GoTo EmblemLoad + + If Left(line, 1) = vbCrLf Then GoTo EmblemLoad + + If Len(line) < 1 Then GoTo EmblemLoad + + word = FirstToken(line) + word2 = SecondToken(line) + + If UCase(word) = "EMBLEM" Then + lstEmblems.AddItem ("Emblem " & Val(word2)) + End If + Loop + + ts.Close + Set myFSO = Nothing +End Sub + +Private Sub ReadSOCEmblemNum(num As Integer) + Dim myFSO As New Scripting.FileSystemObject + Dim ts As TextStream + Dim line As String + Dim word As String + Dim word2 As String + + Set ts = myFSO.OpenTextFile(SOCFile, ForReading, False) + +EmblemLoad: + Do While Not ts.AtEndOfStream + line = ts.ReadLine + + If Left(line, 1) = "#" Then GoTo EmblemLoad + + If Left(line, 1) = vbCrLf Then GoTo EmblemLoad + + If Len(line) < 1 Then GoTo EmblemLoad + + word = UCase(FirstToken(line)) + word2 = UCase(SecondToken(line)) + + If word = "EMBLEM" Then + If Val(word2) = num Then + Do While Len(line) > 0 And Not ts.AtEndOfStream + line = ts.ReadLine + word = UCase(FirstToken(line)) + word2 = UCase(SecondTokenEqual(line)) + + If word = "X" Then + txtX.Text = Val(word2) + ElseIf word = "Y" Then + txtY.Text = Val(word2) + ElseIf word = "Z" Then + txtZ.Text = Val(word2) + ElseIf word = "PLAYERNUM" Then + txtPlayernum.Text = Val(word2) + ElseIf word = "MAPNUM" Then + txtMapnum.Text = Val(word2) + ElseIf Len(line) > 0 And Left(line, 1) <> "#" Then + MsgBox "Error in SOC with Emblem " & num & vbCrLf & "Unknown line: " & line + End If + Loop + Exit Do + End If + End If + Loop + + ts.Close + Set myFSO = Nothing +End Sub + +Private Sub lstEmblems_Click() + Dim i As Integer + + i = InStr(lstEmblems.List(lstEmblems.ListIndex), " ") + 1 + + i = Mid(lstEmblems.List(lstEmblems.ListIndex), i, Len(lstEmblems.List(lstEmblems.ListIndex)) - i + 1) + i = Val(i) + Call ReadSOCEmblemNum(i) +End Sub + +Private Sub WriteEmblem(Remove As Boolean) + Dim myFSOSource As New Scripting.FileSystemObject + Dim tsSource As TextStream + Dim myFSOTarget As New Scripting.FileSystemObject + Dim tsTarget As TextStream + Dim line As String + Dim word As String + Dim word2 As String + Dim i As Integer + + Set tsSource = myFSOSource.OpenTextFile(SOCFile, ForReading, False) + Set tsTarget = myFSOTarget.OpenTextFile(SOCTemp, ForWriting, True) + + Do While Not tsSource.AtEndOfStream + line = tsSource.ReadLine + word = UCase(FirstToken(line)) + word2 = UCase(SecondToken(line)) + i = InStr(lstEmblems.List(lstEmblems.ListIndex), " ") + 1 + + i = Mid(lstEmblems.List(lstEmblems.ListIndex), i, Len(lstEmblems.List(lstEmblems.ListIndex)) - i + 1) + i = Val(i) + + 'If the current emblem exists in the SOC, delete it. + If word = "EMBLEM" And Val(word2) = i Then + Do While Len(TrimComplete(tsSource.ReadLine)) > 0 And Not (tsSource.AtEndOfStream) + Loop + Else + tsTarget.WriteLine line + End If + Loop + + tsSource.Close + Set myFSOSource = Nothing + + If Remove = False Then + If line <> "" Then tsTarget.WriteLine "" + + tsTarget.WriteLine UCase(lstEmblems.List(lstEmblems.ListIndex)) + txtX.Text = TrimComplete(txtX.Text) + txtY.Text = TrimComplete(txtY.Text) + txtZ.Text = TrimComplete(txtZ.Text) + txtMapnum.Text = TrimComplete(txtMapnum.Text) + txtPlayernum.Text = TrimComplete(txtPlayernum.Text) + If txtX.Text <> "" Then tsTarget.WriteLine "X = " & Val(txtX.Text) + If txtY.Text <> "" Then tsTarget.WriteLine "Y = " & Val(txtY.Text) + If txtZ.Text <> "" Then tsTarget.WriteLine "Z = " & Val(txtZ.Text) + If txtMapnum.Text <> "" Then tsTarget.WriteLine "MAPNUM = " & Val(txtMapnum.Text) + If txtPlayernum.Text <> "" Then tsTarget.WriteLine "PLAYERNUM = " & Val(txtPlayernum.Text) + End If + + tsTarget.Close + Set myFSOTarget = Nothing + + FileCopy SOCTemp, SOCFile + + Kill SOCTemp + + If Remove = True Then + MsgBox "Emblem deleted." + Else + MsgBox "Emblem Saved." + End If +End Sub diff --git a/tools/SOCEdit/frmEmblemEdit.frx b/tools/SOCEdit/frmEmblemEdit.frx new file mode 100644 index 000000000..2ae367330 Binary files /dev/null and b/tools/SOCEdit/frmEmblemEdit.frx differ diff --git a/tools/SOCEdit/frmHUDEdit.frm b/tools/SOCEdit/frmHUDEdit.frm new file mode 100644 index 000000000..2b267b79b --- /dev/null +++ b/tools/SOCEdit/frmHUDEdit.frm @@ -0,0 +1,315 @@ +VERSION 5.00 +Begin VB.Form frmHUDEdit + Caption = "HUD Edit" + ClientHeight = 2505 + ClientLeft = 60 + ClientTop = 345 + ClientWidth = 5160 + Icon = "frmHUDEdit.frx":0000 + LinkTopic = "Form1" + MaxButton = 0 'False + ScaleHeight = 2505 + ScaleWidth = 5160 + StartUpPosition = 3 'Windows Default + Begin VB.CommandButton cmdCodeDefault + Caption = "&Load Code Default" + Height = 375 + Left = 3480 + TabIndex = 9 + Top = 1080 + Width = 1575 + End + Begin VB.CommandButton cmdDelete + Caption = "&Delete from SOC" + Height = 375 + Left = 3480 + TabIndex = 7 + Top = 2040 + Width = 1575 + End + Begin VB.CommandButton cmdSave + Caption = "&Save Changes" + Height = 375 + Left = 3480 + TabIndex = 6 + Top = 1560 + Width = 1575 + End + Begin VB.TextBox txtY + Height = 285 + Left = 4080 + MaxLength = 3 + TabIndex = 3 + Top = 720 + Width = 615 + End + Begin VB.TextBox txtX + Height = 285 + Left = 4080 + MaxLength = 3 + TabIndex = 2 + Top = 360 + Width = 615 + End + Begin VB.ListBox lstHUD + Height = 2010 + Left = 120 + TabIndex = 0 + Top = 360 + Width = 3255 + End + Begin VB.Label lblNote + Caption = "HUD items are placed on a 320x200 grid." + Height = 255 + Left = 1680 + TabIndex = 8 + Top = 120 + Width = 3015 + End + Begin VB.Label lblY + Alignment = 1 'Right Justify + Caption = "Y:" + Height = 255 + Left = 3600 + TabIndex = 5 + Top = 720 + Width = 375 + End + Begin VB.Label lblX + Alignment = 1 'Right Justify + Caption = "X:" + Height = 255 + Left = 3720 + TabIndex = 4 + Top = 360 + Width = 255 + End + Begin VB.Label lblHUDItems + Caption = "HUD Items:" + Height = 255 + Left = 120 + TabIndex = 1 + Top = 120 + Width = 975 + End +End +Attribute VB_Name = "frmHUDEdit" +Attribute VB_GlobalNameSpace = False +Attribute VB_Creatable = False +Attribute VB_PredeclaredId = True +Attribute VB_Exposed = False +Option Explicit + +Private Sub cmdCodeDefault_Click() + LoadHUDInfo (lstHUD.ListIndex) +End Sub + +Private Sub cmdDelete_Click() + Call WriteHUDItem(True) +End Sub + +Private Sub cmdSave_Click() + Call WriteHUDItem(False) +End Sub + +Private Sub Form_Load() + Call Reload +End Sub + +Private Sub Reload() + txtX.Text = "" + txtY.Text = "" + Call LoadCode + lstHUD.ListIndex = 0 +End Sub + +Private Sub LoadCode() + Dim myFSO As New Scripting.FileSystemObject + Dim ts As TextStream + Dim line As String + Dim number As Integer + Dim startclip As Integer, endclip As Integer + Dim addstring As String + + ChDir SourcePath + Set ts = myFSO.OpenTextFile("st_stuff.h", ForReading, False) + + Do While ts.ReadLine <> "/** HUD location information (don't move this comment)" + Loop + + ts.ReadLine ' */ + ts.ReadLine ' typedef struct + ts.ReadLine ' { + ts.ReadLine ' int x, y; + ts.ReadLine ' } hudinfo_t; + ts.ReadLine ' + ts.ReadLine ' typedef enum + ts.ReadLine ' { + + line = ts.ReadLine + number = 0 + + lstHUD.Clear + + Do While InStr(line, "NUMHUDITEMS") = 0 + startclip = InStr(line, "HUD_") + If InStr(line, "HUD_") <> 0 Then + endclip = InStr(line, ",") + line = Mid(line, startclip, endclip - startclip) + addstring = number & " - " & line + lstHUD.AddItem addstring + number = number + 1 + End If + line = ts.ReadLine + Loop + + ts.Close + Set myFSO = Nothing +End Sub + +Private Sub lstHUD_Click() + LoadHUDInfo (lstHUD.ListIndex) + Call ReadSOC(lstHUD.ListIndex) +End Sub + +Private Sub LoadHUDInfo(HUDNum As Integer) + Dim myFSO As New Scripting.FileSystemObject + Dim ts As TextStream + Dim line As String + Dim number As Integer + Dim startclip As Integer, endclip As Integer + + ChDir SourcePath + Set ts = myFSO.OpenTextFile("st_stuff.c", ForReading, False) + + Do While InStr(ts.ReadLine, "hudinfo[NUMHUDITEMS] =") = 0 + Loop + + ts.SkipLine ' { + line = ts.ReadLine ' First HUD item + + number = 0 + + Do While number <> HUDNum + line = ts.ReadLine + number = number + 1 + Loop + + startclip = InStr(line, "{") + 1 + endclip = InStr(line, ",") + + txtX.Text = TrimComplete(Mid(line, startclip, endclip - startclip)) + + startclip = endclip + 2 + endclip = InStr(startclip, line, "}") - 1 + + txtY.Text = TrimComplete(Mid(line, startclip, endclip - startclip)) + + ts.Close + Set myFSO = Nothing +End Sub + +Private Sub ReadSOC(HUDNum As Integer) + Dim myFSO As New Scripting.FileSystemObject + Dim ts As TextStream + Dim line As String + Dim word As String + Dim word2 As String + + Set ts = myFSO.OpenTextFile(SOCFile, ForReading, False) + +SOCLoad: + Do While Not ts.AtEndOfStream + line = ts.ReadLine + + If Left(line, 1) = "#" Then GoTo SOCLoad + + If Left(line, 1) = vbCrLf Then GoTo SOCLoad + + If Len(line) < 1 Then GoTo SOCLoad + + word = FirstToken(line) + word2 = SecondToken(line) + + If UCase(word) = "HUDITEM" And Val(word2) = HUDNum Then + Do While Len(line) > 0 And Not ts.AtEndOfStream + line = ts.ReadLine + word = UCase(FirstToken(line)) + word2 = UCase(SecondTokenEqual(line)) + + If word = "X" Then + txtX.Text = Val(word2) + ElseIf word = "Y" Then + txtY.Text = Val(word2) + ElseIf Len(line) > 0 And Left(line, 1) <> "#" Then + MsgBox "Error in SOC!" & vbCrLf & "Unknown line: " & line + End If + Loop + Exit Do + End If + Loop + + ts.Close + Set myFSO = Nothing +End Sub + +Private Sub WriteHUDItem(Remove As Boolean) + Dim myFSOSource As New Scripting.FileSystemObject + Dim tsSource As TextStream + Dim myFSOTarget As New Scripting.FileSystemObject + Dim tsTarget As TextStream + Dim line As String + Dim word As String + Dim word2 As String + Dim hudremoved As Boolean + + hudremoved = False + + Set tsSource = myFSOSource.OpenTextFile(SOCFile, ForReading, False) + Set tsTarget = myFSOTarget.OpenTextFile(SOCTemp, ForWriting, True) + + Do While Not tsSource.AtEndOfStream + line = tsSource.ReadLine + word = UCase(FirstToken(line)) + word2 = UCase(SecondToken(line)) + + 'If the current item exists in the SOC, delete it. + If word = "HUDITEM" And Val(word2) = lstHUD.ListIndex Then + hudremoved = True + Do While Len(TrimComplete(tsSource.ReadLine)) > 0 And Not tsSource.AtEndOfStream + Loop + Else + tsTarget.WriteLine line + End If + Loop + + tsSource.Close + Set myFSOSource = Nothing + + If Remove = False Then + If line <> "" Then tsTarget.WriteLine "" + + tsTarget.WriteLine "HUDITEM " & lstHUD.ListIndex + txtX.Text = TrimComplete(txtX.Text) + txtY.Text = TrimComplete(txtY.Text) + If txtX.Text <> "" Then tsTarget.WriteLine "X = " & Val(txtX.Text) + If txtY.Text <> "" Then tsTarget.WriteLine "Y = " & Val(txtY.Text) + End If + + tsTarget.Close + Set myFSOTarget = Nothing + + FileCopy SOCTemp, SOCFile + + Kill SOCTemp + + If Remove = True Then + If hudremoved = True Then + MsgBox "HUD Item deleted from SOC." + Else + MsgBox "Couldn't find HUD Item in SOC." + End If + Else + MsgBox "HUD Item Saved." + End If +End Sub diff --git a/tools/SOCEdit/frmHUDEdit.frx b/tools/SOCEdit/frmHUDEdit.frx new file mode 100644 index 000000000..2ae367330 Binary files /dev/null and b/tools/SOCEdit/frmHUDEdit.frx differ diff --git a/tools/SOCEdit/frmHelp.frm b/tools/SOCEdit/frmHelp.frm new file mode 100644 index 000000000..acf991057 --- /dev/null +++ b/tools/SOCEdit/frmHelp.frm @@ -0,0 +1,213 @@ +VERSION 5.00 +Begin VB.Form frmHelp + BorderStyle = 3 'Fixed Dialog + Caption = "Getting Started" + ClientHeight = 7395 + ClientLeft = 45 + ClientTop = 330 + ClientWidth = 6360 + Icon = "frmHelp.frx":0000 + LinkTopic = "Form1" + MaxButton = 0 'False + MinButton = 0 'False + ScaleHeight = 7395 + ScaleWidth = 6360 + ShowInTaskbar = 0 'False + StartUpPosition = 1 'CenterOwner + Begin VB.CommandButton cmdOK + Caption = "&OK, I know what I'm doing now." + Height = 495 + Left = 1920 + Style = 1 'Graphical + TabIndex = 8 + Top = 6840 + Width = 2535 + End + Begin VB.Line Line9 + X1 = 120 + X2 = 6120 + Y1 = 4800 + Y2 = 4800 + End + Begin VB.Line Line7 + X1 = 120 + X2 = 6120 + Y1 = 5400 + Y2 = 5400 + End + Begin VB.Label Label12 + Caption = $"frmHelp.frx":0442 + Height = 615 + Left = 120 + TabIndex = 12 + Top = 4800 + Width = 6015 + End + Begin VB.Line Line6 + X1 = 120 + X2 = 6120 + Y1 = 4200 + Y2 = 4200 + End + Begin VB.Label Label11 + Caption = $"frmHelp.frx":04F8 + Height = 615 + Left = 120 + TabIndex = 11 + Top = 4200 + Width = 6015 + End + Begin VB.Line Line8 + X1 = 120 + X2 = 6120 + Y1 = 6360 + Y2 = 6360 + End + Begin VB.Line Line5 + X1 = 120 + X2 = 6120 + Y1 = 3720 + Y2 = 3720 + End + Begin VB.Line Line4 + X1 = 120 + X2 = 6120 + Y1 = 2880 + Y2 = 2880 + End + Begin VB.Line Line3 + X1 = 120 + X2 = 6120 + Y1 = 2400 + Y2 = 2400 + End + Begin VB.Line Line2 + X1 = 120 + X2 = 6120 + Y1 = 1800 + Y2 = 1800 + End + Begin VB.Line Line1 + X1 = 120 + X2 = 6120 + Y1 = 1200 + Y2 = 1200 + End + Begin VB.Label Label10 + Caption = $"frmHelp.frx":05EC + Height = 495 + Left = 120 + TabIndex = 10 + Top = 3720 + Width = 6135 + End + Begin VB.Label Label9 + Caption = $"frmHelp.frx":068F + Height = 615 + Left = 120 + TabIndex = 9 + Top = 1200 + Width = 6135 + End + Begin VB.Label Label8 + Caption = $"frmHelp.frx":0772 + Height = 495 + Left = 120 + TabIndex = 7 + Top = 6360 + Width = 6135 + End + Begin VB.Label Label7 + Caption = "However, if you have these settings in the SOC you are using, don't worry - the editor will not erase them from your file." + Height = 495 + Left = 120 + TabIndex = 6 + Top = 5880 + Width = 6135 + End + Begin VB.Label Label6 + Caption = $"frmHelp.frx":0816 + Height = 495 + Left = 120 + TabIndex = 5 + Top = 5400 + Width = 6135 + End + Begin VB.Label Label5 + Caption = $"frmHelp.frx":08A9 + BeginProperty Font + Name = "MS Sans Serif" + Size = 8.25 + Charset = 0 + Weight = 700 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 855 + Left = 120 + TabIndex = 4 + Top = 2880 + Width = 6135 + End + Begin VB.Label Label4 + Caption = $"frmHelp.frx":09B1 + Height = 495 + Left = 120 + TabIndex = 3 + Top = 2400 + Width = 6135 + End + Begin VB.Label Label3 + Caption = $"frmHelp.frx":0A5A + Height = 495 + Left = 120 + TabIndex = 2 + Top = 1920 + Width = 6135 + End + Begin VB.Label Label2 + Caption = "Finally! A way to easily edit SOC files! I know you're anxious to get started, but here are some things you should know first:" + BeginProperty Font + Name = "MS Sans Serif" + Size = 9.75 + Charset = 0 + Weight = 400 + Underline = 0 'False + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 495 + Left = 120 + TabIndex = 1 + Top = 600 + Width = 6135 + End + Begin VB.Label Label1 + Caption = "How To Use This Program" + BeginProperty Font + Name = "MS Sans Serif" + Size = 13.5 + Charset = 0 + Weight = 700 + Underline = -1 'True + Italic = 0 'False + Strikethrough = 0 'False + EndProperty + Height = 495 + Left = 120 + TabIndex = 0 + Top = 120 + Width = 3855 + End +End +Attribute VB_Name = "frmHelp" +Attribute VB_GlobalNameSpace = False +Attribute VB_Creatable = False +Attribute VB_PredeclaredId = True +Attribute VB_Exposed = False +Option Explicit + +Private Sub cmdOK_Click() + frmHelp.Hide +End Sub diff --git a/tools/SOCEdit/frmHelp.frx b/tools/SOCEdit/frmHelp.frx new file mode 100644 index 000000000..25004fe29 Binary files /dev/null and b/tools/SOCEdit/frmHelp.frx differ diff --git a/tools/SOCEdit/frmHub.frm b/tools/SOCEdit/frmHub.frm new file mode 100644 index 000000000..3672c62b0 --- /dev/null +++ b/tools/SOCEdit/frmHub.frm @@ -0,0 +1,429 @@ +VERSION 5.00 +Begin VB.Form frmHub + Caption = "SOC Editor" + ClientHeight = 6960 + ClientLeft = 60 + ClientTop = 345 + ClientWidth = 4920 + Icon = "frmHub.frx":0000 + LinkTopic = "Form1" + MaxButton = 0 'False + ScaleHeight = 6960 + ScaleWidth = 4920 + StartUpPosition = 3 'Windows Default + Begin VB.CommandButton cmdCreateBlank + Caption = "Make a &Blank SOC" + Height = 255 + Left = 240 + TabIndex = 22 + Top = 2520 + Width = 2055 + End + Begin VB.CommandButton cmdUnlockables + Caption = "Edit &Unlockables" + Enabled = 0 'False + Height = 495 + Left = 2760 + Style = 1 'Graphical + TabIndex = 21 + Top = 6360 + Width = 1095 + End + Begin VB.CommandButton cmdAuthor + Caption = "Enter &Author Info" + Enabled = 0 'False + Height = 495 + Left = 120 + Style = 1 'Graphical + TabIndex = 19 + Top = 3960 + Width = 1215 + End + Begin VB.CommandButton cmdHelp + Caption = "Getting Starte&d / READ ME FIRST!" + Height = 495 + Left = 480 + TabIndex = 18 + Top = 2880 + Width = 1575 + End + Begin VB.CommandButton cmdEditCutscenes + Caption = "Edit C&utscenes" + Enabled = 0 'False + Height = 495 + Left = 120 + TabIndex = 17 + Top = 6360 + Width = 1215 + End + Begin VB.CommandButton cmdCharacterEdit + Caption = "Edit &Character Select Screen" + Enabled = 0 'False + Height = 495 + Left = 120 + Style = 1 'Graphical + TabIndex = 16 + Top = 5760 + Width = 1215 + End + Begin VB.PictureBox Picture1 + Height = 1965 + Left = 2760 + Picture = "frmHub.frx":0442 + ScaleHeight = 1905 + ScaleWidth = 1905 + TabIndex = 15 + Top = 3960 + Width = 1965 + End + Begin VB.CommandButton cmdSoundEdit + Caption = "Edit &Sounds" + Enabled = 0 'False + Height = 495 + Left = 120 + TabIndex = 14 + Top = 5160 + Width = 1215 + End + Begin VB.CommandButton cmdEmblemEdit + Caption = "Edit &Emblem Locations" + Enabled = 0 'False + Height = 495 + Left = 120 + Style = 1 'Graphical + TabIndex = 13 + Top = 4560 + Width = 1215 + End + Begin VB.CommandButton cmdHUDEdit + Caption = "Edit &HUD Coordinates" + Enabled = 0 'False + Height = 495 + Left = 1440 + Style = 1 'Graphical + TabIndex = 12 + Top = 3960 + Width = 1215 + End + Begin VB.CommandButton cmdMaincfg + Caption = "Edit &Global Game Settings" + Enabled = 0 'False + Height = 495 + Left = 1440 + Style = 1 'Graphical + TabIndex = 11 + Top = 4560 + Width = 1215 + End + Begin VB.DriveListBox Drive2 + Height = 315 + Left = 2640 + TabIndex = 9 + Top = 360 + Width = 2175 + End + Begin VB.DirListBox Dir2 + Height = 1665 + Left = 2520 + TabIndex = 8 + Top = 720 + Width = 2295 + End + Begin VB.FileListBox File1 + Height = 1455 + Left = 2520 + Pattern = "*.soc" + TabIndex = 7 + Top = 2400 + Width = 2295 + End + Begin VB.DriveListBox Drive1 + Height = 315 + Left = 120 + TabIndex = 6 + Top = 360 + Width = 2295 + End + Begin VB.DirListBox Dir1 + Height = 1665 + Left = 120 + TabIndex = 4 + Top = 720 + Width = 2295 + End + Begin VB.CommandButton cmdAbout + Caption = "&About" + Height = 375 + Left = 3960 + TabIndex = 3 + Top = 6000 + Width = 735 + End + Begin VB.CommandButton cmdStateEdit + Caption = "Edit St&ates" + Enabled = 0 'False + Height = 495 + Left = 1440 + TabIndex = 2 + Top = 6360 + Width = 1215 + End + Begin VB.CommandButton cmdLevelHeader + Caption = "Edit &Level Headers" + Enabled = 0 'False + Height = 495 + Left = 1440 + Style = 1 'Graphical + TabIndex = 1 + Top = 5160 + Width = 1215 + End + Begin VB.CommandButton cmdThingEdit + Caption = "Edit &Things" + Enabled = 0 'False + Height = 495 + Left = 1440 + TabIndex = 0 + Top = 5760 + Width = 1215 + End + Begin VB.Label lblAuthor + Caption = "Modification By:" + Height = 495 + Left = 120 + TabIndex = 20 + Top = 3480 + Width = 2295 + End + Begin VB.Label lblSOCFile + Caption = "SOC File to use (double click):" + Height = 255 + Left = 2640 + TabIndex = 10 + Top = 120 + Width = 2175 + End + Begin VB.Label lblSourcePath + Caption = "Path to SRB2 Source Code:" + Height = 255 + Left = 120 + TabIndex = 5 + Top = 120 + Width = 2175 + End +End +Attribute VB_Name = "frmHub" +Attribute VB_GlobalNameSpace = False +Attribute VB_Creatable = False +Attribute VB_PredeclaredId = True +Attribute VB_Exposed = False +Option Explicit + +Private Sub cmdAbout_Click() + MsgBox App.Title & " v" & App.Major & "." & App.Minor & "." & App.Revision & vbCrLf & "By " & App.CompanyName & vbCrLf & "(SSNTails)" & vbCrLf & App.Comments & vbCrLf & App.FileDescription +End Sub + +Private Sub cmdAuthor_Click() + Dim Response As String + + Response$ = InputBox("Enter name to appear on credits (type in NOBODY to delete):", "Modification By", GetAuthor) + + If Response = "" Then Exit Sub + + Response = TrimComplete(Response) + + If UCase(Response) = "NOBODY" Then + Call WriteAuthor(True, Response) + lblAuthor.Caption = "Modification By: " + Else + Call WriteAuthor(False, Response) + lblAuthor.Caption = "Modification By: " & Response + End If +End Sub + +Private Sub cmdCharacterEdit_Click() + frmCharacterEdit.Show vbModal, Me +End Sub + +Private Sub cmdCreateBlank_Click() + Dim socname As String + + socname = InputBox("This file will be created in the directory you have selected on the main window." & vbCrLf & vbCrLf & "Enter the filename you want (do not include .SOC at the end):", "Make A Blank SOC") + Trim (socname) + + If InStr(LCase(socname), ".soc") > 0 Then + MsgBox "The thing says not to include the .SOC at the end, stupid.", vbOKOnly, "You goofed!" + Exit Sub + End If + + If Len(socname) > 0 Then + socname = socname & ".soc" + + Dim myFSOSOC As New Scripting.FileSystemObject + Dim tsSOC As TextStream + + Set tsSOC = myFSOSOC.OpenTextFile(File1.Path & "\" & socname, ForWriting, True) + tsSOC.Close + Set myFSOSOC = Nothing + + MsgBox "Blank SOC named " & socname & " created in " & File1.Path, vbOKOnly, "Success!" + End If +End Sub + +Private Sub cmdEditCutscenes_Click() + frmCutsceneEdit.Show vbModal, Me +End Sub + +Private Sub cmdEmblemEdit_Click() + frmEmblemEdit.Show vbModal, Me +End Sub + +Private Sub cmdHelp_Click() + frmHelp.Show vbModal, Me +End Sub + +Private Sub cmdHUDEdit_Click() + frmHUDEdit.Show vbModal, Me +End Sub + +Private Sub cmdLevelHeader_Click() + frmLevelHeader.Show vbModal, Me +End Sub + +Private Sub cmdMaincfg_Click() + frmMaincfg.Show vbModal, Me +End Sub + +Private Sub cmdSoundEdit_Click() + frmSoundEdit.Show vbModal, Me +End Sub + +Private Sub cmdStateEdit_Click() + frmStateEdit.Show vbModal, Me +End Sub + +Private Sub cmdThingEdit_Click() + frmThingEdit.Show vbModal, Me +End Sub + +Private Sub cmdUnlockables_Click() + frmUnlockablesEdit.Show vbModal, Me +End Sub + +Private Sub Dir1_Change() + SourcePath = Dir1.Path +End Sub + +Private Sub Dir2_Change() + File1.Path = Dir2.Path +End Sub + +Private Sub Drive1_Change() + Dir1.Path = Drive1.Drive +End Sub + +Private Sub Drive2_Change() + Dir2.Path = Drive2.Drive +End Sub + +Private Sub File1_DblClick() + SOCTemp = File1.Path & "\" & "socedit.tmp" + SOCFile = File1.Path & "\" & File1.List(File1.ListIndex) + MsgBox "You are now using the file: " & vbCrLf & SOCFile + cmdLevelHeader.Enabled = True + cmdThingEdit.Enabled = True + cmdStateEdit.Enabled = True + cmdHUDEdit.Enabled = True + cmdMaincfg.Enabled = True + cmdEmblemEdit.Enabled = True + cmdSoundEdit.Enabled = True + cmdCharacterEdit.Enabled = True + cmdEditCutscenes.Enabled = True + cmdAuthor.Enabled = True + cmdUnlockables.Enabled = True + lblAuthor.Caption = "Modification By: " & GetAuthor +End Sub + +Private Sub Form_Load() + SourcePath = App.Path + Dir1.Path = SourcePath +End Sub + +Private Function GetAuthor() As String + Dim myFSO As New Scripting.FileSystemObject + Dim ts As TextStream + Dim line As String + Dim word As String + Dim word2 As String + + Set ts = myFSO.OpenTextFile(SOCFile, ForReading, False) + +SOCLoad: + Do While Not ts.AtEndOfStream + line = ts.ReadLine + + If Left(line, 1) = "#" Then GoTo SOCLoad + + If Left(line, 1) = vbCrLf Then GoTo SOCLoad + + If Len(line) < 1 Then GoTo SOCLoad + + word = FirstToken(line) + word2 = SecondToken(line) + + If UCase(word) = "MODBY" Then + GetAuthor = word2 + Exit Do + End If + Loop + + ts.Close + Set myFSO = Nothing +End Function + +Private Sub WriteAuthor(Remove As Boolean, ModderName As String) + Dim myFSOSource As New Scripting.FileSystemObject + Dim tsSource As TextStream + Dim myFSOTarget As New Scripting.FileSystemObject + Dim tsTarget As TextStream + Dim line As String + Dim word As String + Dim word2 As String + + Set tsSource = myFSOSource.OpenTextFile(SOCFile, ForReading, False) + Set tsTarget = myFSOTarget.OpenTextFile(SOCTemp, ForWriting, True) + + Do While Not tsSource.AtEndOfStream + line = tsSource.ReadLine + word = UCase(FirstToken(line)) + word2 = UCase(SecondToken(line)) + + 'If the entry exists in the SOC, delete it. + If word <> "MODBY" Then + tsTarget.WriteLine line + End If + Loop + + tsSource.Close + Set myFSOSource = Nothing + + If Remove = False Then + If line <> "" Then tsTarget.WriteLine "" + + tsTarget.WriteLine "ModBy " & ModderName + End If + + tsTarget.Close + Set myFSOTarget = Nothing + + FileCopy SOCTemp, SOCFile + + Kill SOCTemp + + If Remove = True Then + MsgBox "Name removed." + Else + MsgBox "Name Saved." + End If +End Sub + diff --git a/tools/SOCEdit/frmHub.frx b/tools/SOCEdit/frmHub.frx new file mode 100644 index 000000000..176491ab6 Binary files /dev/null and b/tools/SOCEdit/frmHub.frx differ diff --git a/tools/SOCEdit/frmLevelHeader.frm b/tools/SOCEdit/frmLevelHeader.frm new file mode 100644 index 000000000..e30acd581 --- /dev/null +++ b/tools/SOCEdit/frmLevelHeader.frm @@ -0,0 +1,839 @@ +VERSION 5.00 +Begin VB.Form frmLevelHeader + Caption = "Level Header Info" + ClientHeight = 5250 + ClientLeft = 60 + ClientTop = 345 + ClientWidth = 7650 + Icon = "frmLevelHeader.frx":0000 + LinkTopic = "Form1" + MaxButton = 0 'False + ScaleHeight = 5250 + ScaleWidth = 7650 + StartUpPosition = 3 'Windows Default + Begin VB.TextBox txtRunSOC + Height = 285 + Left = 6240 + MaxLength = 8 + TabIndex = 49 + Top = 4680 + Width = 1215 + End + Begin VB.CheckBox chkLevelSelect + Caption = "Show on Host Game selection menu" + Height = 375 + Left = 1680 + TabIndex = 48 + Top = 4800 + Width = 1935 + End + Begin VB.CheckBox chkTimeAttack + Caption = "Include in Time Attack calculations" + Height = 255 + Left = 1680 + TabIndex = 47 + Top = 4440 + Width = 2775 + End + Begin VB.CheckBox chkNoReload + Caption = "Retain level state when player dies." + Height = 255 + Left = 1680 + TabIndex = 46 + Top = 4080 + Width = 2895 + End + Begin VB.CommandButton cmdSave + Caption = "&Save Map" + Height = 735 + Left = 120 + Style = 1 'Graphical + TabIndex = 45 + Top = 4440 + Width = 1215 + End + Begin VB.CommandButton cmdRename + Caption = "&Rename Map" + Height = 375 + Left = 120 + TabIndex = 44 + Top = 3960 + Width = 1215 + End + Begin VB.CommandButton cmdDelete + Caption = "&Delete Map" + Height = 375 + Left = 120 + TabIndex = 43 + Top = 3480 + Width = 1215 + End + Begin VB.CommandButton cmdAddMap + Caption = "&Add Map" + Height = 375 + Left = 120 + TabIndex = 42 + Top = 3000 + Width = 1215 + End + Begin VB.CheckBox chkNossmusic + Caption = "Disable Super Sonic music changes" + Height = 255 + Left = 4560 + TabIndex = 29 + Top = 1200 + Width = 2895 + End + Begin VB.CheckBox chkHidden + Caption = "Don't show on level selection menu" + Height = 255 + Left = 4560 + TabIndex = 28 + Top = 480 + Width = 2895 + End + Begin VB.TextBox txtCountdown + Height = 285 + Left = 6360 + MaxLength = 3 + TabIndex = 26 + Top = 840 + Width = 735 + End + Begin VB.TextBox txtCutscenenum + Height = 285 + Left = 4440 + MaxLength = 3 + TabIndex = 25 + Top = 3720 + Width = 495 + End + Begin VB.TextBox txtPrecutscenenum + Height = 285 + Left = 2640 + MaxLength = 3 + TabIndex = 22 + Top = 3720 + Width = 495 + End + Begin VB.CheckBox chkScriptislump + Caption = "Script is a lump in WAD, not a file" + Height = 255 + Left = 1680 + TabIndex = 21 + Top = 3360 + Width = 2775 + End + Begin VB.TextBox txtScriptname + Height = 285 + Left = 2640 + MaxLength = 191 + TabIndex = 19 + Top = 3000 + Width = 1455 + End + Begin VB.TextBox txtSkynum + Height = 285 + Left = 2640 + MaxLength = 4 + TabIndex = 17 + Top = 2640 + Width = 495 + End + Begin VB.ComboBox cmbWeather + Height = 315 + ItemData = "frmLevelHeader.frx":0442 + Left = 2640 + List = "frmLevelHeader.frx":0458 + TabIndex = 15 + Top = 2280 + Width = 2295 + End + Begin VB.TextBox txtForcecharacter + Height = 285 + Left = 2640 + MaxLength = 2 + TabIndex = 13 + Top = 1920 + Width = 495 + End + Begin VB.ComboBox cmbMusicslot + Height = 315 + Left = 2640 + TabIndex = 11 + Top = 1560 + Width = 1815 + End + Begin VB.TextBox txtNextlevel + Height = 285 + Left = 2640 + MaxLength = 4 + TabIndex = 9 + Top = 1200 + Width = 615 + End + Begin VB.Frame frmTypeOfLevel + Caption = "Type of Level" + Height = 2775 + Left = 5040 + TabIndex = 8 + Top = 1680 + Width = 2535 + Begin VB.CheckBox chkTypeoflevel + Caption = "Christmas" + Height = 255 + Index = 11 + Left = 1440 + TabIndex = 41 + Tag = "1024" + Top = 960 + Width = 975 + End + Begin VB.CheckBox chkTypeoflevel + Caption = "2D" + Height = 255 + Index = 10 + Left = 1440 + TabIndex = 40 + Tag = "512" + Top = 720 + Width = 735 + End + Begin VB.CheckBox chkTypeoflevel + Caption = "Mario" + Height = 255 + Index = 9 + Left = 120 + TabIndex = 39 + Tag = "256" + Top = 2400 + Width = 1455 + End + Begin VB.CheckBox chkTypeoflevel + Caption = "Sonic Adventure" + Height = 255 + Index = 8 + Left = 120 + TabIndex = 38 + Tag = "128" + Top = 2160 + Width = 1575 + End + Begin VB.CheckBox chkTypeoflevel + Caption = "NiGHTS" + Height = 255 + Index = 7 + Left = 120 + TabIndex = 37 + Tag = "64" + Top = 1920 + Width = 1335 + End + Begin VB.CheckBox chkTypeoflevel + Caption = "Chaos" + Height = 255 + Index = 6 + Left = 120 + TabIndex = 36 + Tag = "32" + Top = 1680 + Width = 1455 + End + Begin VB.CheckBox chkTypeoflevel + Caption = "Capture the Flag" + Height = 255 + Index = 5 + Left = 120 + TabIndex = 35 + Tag = "16" + Top = 1440 + Width = 1695 + End + Begin VB.CheckBox chkTypeoflevel + Caption = "Tag" + Height = 255 + Index = 4 + Left = 120 + TabIndex = 34 + Tag = "8" + Top = 1200 + Width = 1215 + End + Begin VB.CheckBox chkTypeoflevel + Caption = "Match" + Height = 255 + Index = 3 + Left = 120 + TabIndex = 33 + Tag = "4" + Top = 960 + Width = 855 + End + Begin VB.CheckBox chkTypeoflevel + Caption = "Race" + Height = 255 + Index = 2 + Left = 120 + TabIndex = 32 + Tag = "2" + Top = 720 + Width = 855 + End + Begin VB.CheckBox chkTypeoflevel + Caption = "Cooperative" + Height = 255 + Index = 1 + Left = 120 + TabIndex = 31 + Tag = "1" + Top = 480 + Width = 1215 + End + Begin VB.CheckBox chkTypeoflevel + Caption = "Single Player" + Height = 255 + Index = 0 + Left = 120 + TabIndex = 30 + Tag = "4096" + Top = 240 + Width = 1215 + End + End + Begin VB.CheckBox chkNozone + Caption = "Don't show ""ZONE"" after Level Name" + Height = 255 + Left = 4560 + TabIndex = 7 + Top = 120 + Width = 3015 + End + Begin VB.TextBox txtAct + Height = 285 + Left = 2640 + MaxLength = 2 + TabIndex = 5 + Top = 840 + Width = 495 + End + Begin VB.TextBox txtInterscreen + Height = 285 + Left = 2640 + MaxLength = 8 + TabIndex = 3 + Top = 480 + Width = 1335 + End + Begin VB.ListBox lstMaps + Height = 2790 + Left = 120 + Sorted = -1 'True + TabIndex = 2 + Top = 120 + Width = 1215 + End + Begin VB.TextBox txtLevelName + Height = 285 + Left = 2640 + MaxLength = 32 + TabIndex = 0 + Top = 120 + Width = 1815 + End + Begin VB.Label lblRunSOC + Alignment = 1 'Right Justify + Caption = "Run SOC at level load (lump name):" + Height = 495 + Left = 4440 + TabIndex = 50 + Top = 4560 + Width = 1695 + End + Begin VB.Label lblCountdown + Alignment = 1 'Right Justify + Caption = "Level Timer (seconds):" + Height = 255 + Left = 4560 + TabIndex = 27 + Top = 840 + Width = 1695 + End + Begin VB.Label lblCutscenenum + Alignment = 1 'Right Justify + Caption = "Cutscene to play after level:" + Height = 495 + Left = 3240 + TabIndex = 24 + Top = 3600 + Width = 1095 + End + Begin VB.Label lblPrecutscenenum + Alignment = 1 'Right Justify + Caption = "Cutscene to play before level:" + Height = 375 + Left = 1320 + TabIndex = 23 + Top = 3600 + Width = 1215 + End + Begin VB.Label lblScriptName + Alignment = 1 'Right Justify + Caption = "Script Name:" + Height = 255 + Left = 1440 + TabIndex = 20 + Top = 3000 + Width = 1095 + End + Begin VB.Label lblSkynum + Alignment = 1 'Right Justify + Caption = "Sky #:" + Height = 255 + Left = 1800 + TabIndex = 18 + Top = 2640 + Width = 735 + End + Begin VB.Label Label1 + Alignment = 1 'Right Justify + Caption = "Weather:" + Height = 255 + Left = 1680 + TabIndex = 16 + Top = 2280 + Width = 855 + End + Begin VB.Label lblForcecharacter + Caption = "Force Character #:" + Height = 375 + Left = 1440 + TabIndex = 14 + Top = 1800 + Width = 1095 + End + Begin VB.Label lblMusicslot + Alignment = 1 'Right Justify + Caption = "Music:" + Height = 255 + Left = 1800 + TabIndex = 12 + Top = 1560 + Width = 735 + End + Begin VB.Label lblNextlevel + Alignment = 1 'Right Justify + Caption = "Next Level:" + Height = 255 + Left = 1440 + TabIndex = 10 + Top = 1200 + Width = 1095 + End + Begin VB.Label lblAct + Alignment = 1 'Right Justify + Caption = "Act:" + Height = 255 + Left = 2040 + TabIndex = 6 + Top = 840 + Width = 495 + End + Begin VB.Label lblInterscreen + Alignment = 1 'Right Justify + Caption = "Intermission BG:" + Height = 255 + Left = 1320 + TabIndex = 4 + Top = 480 + Width = 1215 + End + Begin VB.Label lblLevelName + Alignment = 1 'Right Justify + Caption = "Level Name:" + Height = 255 + Left = 1560 + TabIndex = 1 + Top = 120 + Width = 975 + End +End +Attribute VB_Name = "frmLevelHeader" +Attribute VB_GlobalNameSpace = False +Attribute VB_Creatable = False +Attribute VB_PredeclaredId = True +Attribute VB_Exposed = False +Option Explicit + +Private Sub cmdAddMap_Click() + Dim Response As String + Dim NewNum As Integer + + Response$ = InputBox("Enter the new level (NUMBER ONLY):") + + If Response = "" Then + Exit Sub + End If + + NewNum = Val(TrimComplete(Response)) + + lstMaps.AddItem "Level " & NewNum + lstMaps.ListIndex = lstMaps.ListCount - 1 +End Sub + +Private Sub cmdDelete_Click() + Dim i As Integer + + If MsgBox("Delete this level header?", vbYesNo) = vbNo Then + Exit Sub + End If + + i = InStr(lstMaps.List(lstMaps.ListIndex), " ") + 1 + + i = Mid(lstMaps.List(lstMaps.ListIndex), i, Len(lstMaps.List(lstMaps.ListIndex)) - i + 1) + i = Val(i) + Call WriteLevel(True, i) + lstMaps.RemoveItem lstMaps.ListIndex + + If lstMaps.ListCount > 0 Then + lstMaps.ListIndex = 0 + End If +End Sub + +Private Sub cmdRename_Click() + Dim Response As String + Dim NewNum As Integer + Dim i As Integer + + Response$ = InputBox("Rename level to (NUMBER ONLY):") + + If Response = "" Then + Exit Sub + End If + + NewNum = Val(TrimComplete(Response)) + + i = InStr(lstMaps.List(lstMaps.ListIndex), " ") + 1 + + i = Mid(lstMaps.List(lstMaps.ListIndex), i, Len(lstMaps.List(lstMaps.ListIndex)) - i + 1) + i = Val(i) + Call WriteLevel(True, i) + lstMaps.List(lstMaps.ListIndex) = "Level " & NewNum + Call cmdSave_Click +End Sub + +Private Sub cmdSave_Click() + Dim i As Integer + + i = InStr(lstMaps.List(lstMaps.ListIndex), " ") + 1 + + i = Val(Mid(lstMaps.List(lstMaps.ListIndex), i, Len(lstMaps.List(lstMaps.ListIndex)) - i + 1)) + Call WriteLevel(False, i) +End Sub + +Private Sub Form_Load() + Call LoadMusic + Call LoadSOCMaps + If lstMaps.ListCount > 0 Then lstMaps.ListIndex = 0 +End Sub + +Private Sub LoadSOCMaps() + Dim myFSO As New Scripting.FileSystemObject + Dim ts As TextStream + Dim line As String + Dim word As String + Dim word2 As String + + Set ts = myFSO.OpenTextFile(SOCFile, ForReading, False) + + lstMaps.Clear + +SOCLoad: + Do While Not ts.AtEndOfStream + line = ts.ReadLine + + If Left(line, 1) = "#" Then GoTo SOCLoad + + If Left(line, 1) = vbCrLf Then GoTo SOCLoad + + If Len(line) < 1 Then GoTo SOCLoad + + word = FirstToken(line) + word2 = SecondToken(line) + + If UCase(word) = "LEVEL" Then + lstMaps.AddItem ("Level " & Val(word2)) + End If + Loop + + ts.Close + Set myFSO = Nothing +End Sub + +Private Sub LoadMusic() + Dim myFSO As New Scripting.FileSystemObject + Dim ts As TextStream + Dim line As String + Dim number As Integer + Dim startclip As Integer, endclip As Integer + Dim addstring As String + + ChDir SourcePath + Set ts = myFSO.OpenTextFile("sounds.h", ForReading, False) + + Do While InStr(ts.ReadLine, "Music list (don't edit this comment!)") = 0 + Loop + + ts.SkipLine ' typedef enum + ts.SkipLine ' { + + line = ts.ReadLine + number = 0 + + cmbMusicslot.Clear + + Do While InStr(line, "NUMMUSIC") = 0 + startclip = InStr(line, "mus_") + If InStr(line, "mus_") <> 0 Then + endclip = InStr(line, ",") + line = Mid(line, startclip, endclip - startclip) + addstring = number & " - " & line + cmbMusicslot.AddItem addstring + number = number + 1 + End If + line = ts.ReadLine + Loop + + ts.Close + Set myFSO = Nothing +End Sub + +Private Sub ClearForm() + Dim j As Integer + + txtLevelName.Text = "" + txtInterscreen.Text = "" + txtAct.Text = "" + txtNextlevel.Text = "" + cmbMusicslot.Text = "" + txtForcecharacter.Text = "" + cmbWeather.Text = "" + txtSkynum.Text = "" + txtScriptname.Text = "" + chkScriptislump.Value = 0 + txtPrecutscenenum.Text = "" + txtCutscenenum.Text = "" + txtRunSOC.Text = "" + chkNozone.Value = 0 + chkHidden.Value = 0 + txtCountdown.Text = "" + chkNossmusic.Value = 0 + chkNoReload.Value = 0 + chkTimeAttack.Value = 0 + chkLevelSelect = 0 + + For j = 0 To 11 + chkTypeoflevel(j).Value = 0 + Next j +End Sub + +Private Sub lstMaps_Click() + Dim startclip As Integer + Call ClearForm + startclip = InStr(lstMaps.List(lstMaps.ListIndex), " ") + Call LoadSOCMapInfo(Val(Mid(lstMaps.List(lstMaps.ListIndex), startclip + 1, Len(lstMaps.List(lstMaps.ListIndex))))) +End Sub + +Private Sub LoadSOCMapInfo(num As Integer) + Dim myFSO As New Scripting.FileSystemObject + Dim ts As TextStream + Dim line As String + Dim word As String + Dim word2 As String + + Set ts = myFSO.OpenTextFile(SOCFile, ForReading, False) + +SOCLoad: + Do While Not ts.AtEndOfStream + line = ts.ReadLine + + If Left(line, 1) = "#" Then GoTo SOCLoad + + If Left(line, 1) = vbCrLf Then GoTo SOCLoad + + If Len(line) < 1 Then GoTo SOCLoad + + word = UCase(FirstToken(line)) + word2 = UCase(SecondToken(line)) + + If word = "LEVEL" Then + If Val(word2) = num Then + Do While Len(line) > 0 And Not ts.AtEndOfStream + line = ts.ReadLine + word = UCase(FirstToken(line)) + word2 = UCase(SecondTokenEqual(line)) + + If word = "LEVELNAME" Then + txtLevelName.Text = word2 + ElseIf word = "INTERSCREEN" Then + txtInterscreen.Text = word2 + ElseIf word = "ACT" Then + txtAct.Text = Val(word2) + ElseIf word = "NOZONE" Then + chkNozone.Value = Val(word2) + ElseIf word = "TYPEOFLEVEL" Then + ProcessMapFlags (Val(word2)) + ElseIf word = "NEXTLEVEL" Then + txtNextlevel.Text = Val(word2) + ElseIf word = "MUSICSLOT" Then + cmbMusicslot.ListIndex = Val(word2) + ElseIf word = "FORCECHARACTER" Then + txtForcecharacter.Text = Val(word2) + ElseIf word = "WEATHER" Then + cmbWeather.ListIndex = Val(word2) + ElseIf word = "SKYNUM" Then + txtSkynum.Text = Val(word2) + ElseIf word = "SCRIPTNAME" Then + txtScriptname.Text = word2 + ElseIf word = "SCRIPTISLUMP" Then + chkScriptislump.Value = Val(word2) + ElseIf word = "PRECUTSCENENUM" Then + txtPrecutscenenum.Text = Val(word2) + ElseIf word = "CUTSCENENUM" Then + txtCutscenenum.Text = Val(word2) + ElseIf word = "COUNTDOWN" Then + txtCountdown.Text = Val(word2) + ElseIf word = "HIDDEN" Then + chkHidden.Value = Val(word2) + ElseIf word = "NOSSMUSIC" Then + chkNossmusic.Value = Val(word2) + ElseIf word = "NORELOAD" Then + chkNoReload.Value = Val(word2) + ElseIf word = "TIMEATTACK" Then + chkTimeAttack.Value = Val(word2) + ElseIf word = "LEVELSELECT" Then + chkLevelSelect.Value = Val(word2) + ElseIf word = "RUNSOC" Then + txtRunSOC.Text = word2 + ElseIf Len(line) > 0 And Left(line, 1) <> "#" Then + MsgBox "Error in SOC!" & vbCrLf & "Unknown line: " & line + End If + Loop + Exit Do + End If + End If + Loop + + ts.Close + Set myFSO = Nothing +End Sub + +Private Sub ProcessMapFlags(flags As Long) + Dim j As Integer + + For j = 0 To 11 + If flags And chkTypeoflevel(j).Tag Then + chkTypeoflevel(j).Value = 1 + Else + chkTypeoflevel(j).Value = 0 + End If + Next j +End Sub + +Private Sub WriteLevel(Remove As Boolean, Mapnum As Integer) + Dim myFSOSource As New Scripting.FileSystemObject + Dim tsSource As TextStream + Dim myFSOTarget As New Scripting.FileSystemObject + Dim tsTarget As TextStream + Dim line As String + Dim word As String + Dim word2 As String + Dim flags As Long + Dim i As Integer + + Set tsSource = myFSOSource.OpenTextFile(SOCFile, ForReading, False) + Set tsTarget = myFSOTarget.OpenTextFile(SOCTemp, ForWriting, True) + + Do While Not tsSource.AtEndOfStream + line = tsSource.ReadLine + word = UCase(FirstToken(line)) + word2 = UCase(SecondToken(line)) + + i = InStr(lstMaps.List(lstMaps.ListIndex), " ") + 1 + + i = Mid(lstMaps.List(lstMaps.ListIndex), i, Len(lstMaps.List(lstMaps.ListIndex)) - i + 1) + i = Val(i) + 'If the current level exists in the SOC, delete it. + If word = "LEVEL" And Val(word2) = i Then + Do While Len(TrimComplete(tsSource.ReadLine)) > 0 And Not (tsSource.AtEndOfStream) + Loop + Else + tsTarget.WriteLine line + End If + Loop + + tsSource.Close + Set myFSOSource = Nothing + + If Remove = False Then + If line <> "" Then tsTarget.WriteLine "" + + tsTarget.WriteLine UCase(lstMaps.List(lstMaps.ListIndex)) + txtLevelName.Text = TrimComplete(txtLevelName.Text) + txtInterscreen.Text = TrimComplete(txtInterscreen.Text) + txtAct.Text = TrimComplete(txtAct.Text) + txtNextlevel.Text = TrimComplete(txtNextlevel.Text) + cmbMusicslot.Text = TrimComplete(cmbMusicslot.Text) + txtForcecharacter.Text = TrimComplete(txtForcecharacter.Text) + cmbWeather.Text = TrimComplete(cmbWeather.Text) + txtSkynum.Text = TrimComplete(txtSkynum.Text) + txtScriptname.Text = TrimComplete(txtScriptname.Text) + txtPrecutscenenum.Text = TrimComplete(txtPrecutscenenum.Text) + txtCutscenenum.Text = TrimComplete(txtCutscenenum.Text) + txtCountdown.Text = TrimComplete(txtCountdown.Text) + txtRunSOC.Text = TrimComplete(txtRunSOC.Text) + + If txtLevelName.Text <> "" Then tsTarget.WriteLine "LEVELNAME = " & txtLevelName.Text + If txtInterscreen.Text <> "" Then tsTarget.WriteLine "INTERSCREEN = " & txtInterscreen.Text + If txtAct.Text <> "" Then tsTarget.WriteLine "ACT = " & Val(txtAct.Text) + If txtNextlevel.Text <> "" Then tsTarget.WriteLine "NEXTLEVEL = " & Val(txtNextlevel.Text) + If cmbMusicslot.Text <> "" Then tsTarget.WriteLine "MUSICSLOT = " & cmbMusicslot.ListIndex + If txtForcecharacter.Text <> "" Then tsTarget.WriteLine "FORCECHARACTER = " & Val(txtForcecharacter.Text) + If cmbWeather.Text <> "" Then tsTarget.WriteLine "WEATHER = " & cmbWeather.ListIndex + If txtSkynum.Text <> "" Then tsTarget.WriteLine "SKYNUM = " & Val(txtSkynum.Text) + If txtScriptname.Text <> "" Then tsTarget.WriteLine "SCRIPTNAME = " & txtScriptname.Text + If txtPrecutscenenum.Text <> "" Then tsTarget.WriteLine "PRECUTSCENENUM = " & Val(txtPrecutscenenum.Text) + If txtCutscenenum.Text <> "" Then tsTarget.WriteLine "CUTSCENENUM = " & Val(txtCutscenenum.Text) + If txtCountdown.Text <> "" Then tsTarget.WriteLine "COUNTDOWN = " & Val(txtCountdown.Text) + If chkScriptislump.Value = 1 Then tsTarget.WriteLine "SCRIPTISLUMP = 1" + If chkNozone.Value = 1 Then tsTarget.WriteLine "NOZONE = 1" + If chkHidden.Value = 1 Then tsTarget.WriteLine "HIDDEN = 1" + If chkNossmusic.Value = 1 Then tsTarget.WriteLine "NOSSMUSIC = 1" + If chkNoReload.Value = 1 Then tsTarget.WriteLine "NORELOAD = 1" + If chkTimeAttack.Value = 1 Then tsTarget.WriteLine "TIMEATTACK = 1" + If chkLevelSelect.Value = 1 Then tsTarget.WriteLine "LEVELSELECT = 1" + If txtRunSOC.Text <> "" Then tsTarget.WriteLine "RUNSOC = " & txtRunSOC.Text + + flags = 0 + For i = 0 To 11 + If chkTypeoflevel(i).Value = 1 Then + flags = flags + Val(chkTypeoflevel(i).Tag) + End If + Next + + If flags > 0 Then tsTarget.WriteLine "TYPEOFLEVEL = " & flags + End If + + tsTarget.Close + Set myFSOTarget = Nothing + + FileCopy SOCTemp, SOCFile + + Kill SOCTemp + + If Remove = True Then + MsgBox "Level Deleted." + Else + MsgBox "Level Saved." + End If +End Sub + diff --git a/tools/SOCEdit/frmLevelHeader.frx b/tools/SOCEdit/frmLevelHeader.frx new file mode 100644 index 000000000..fe81f4413 Binary files /dev/null and b/tools/SOCEdit/frmLevelHeader.frx differ diff --git a/tools/SOCEdit/frmMaincfg.frm b/tools/SOCEdit/frmMaincfg.frm new file mode 100644 index 000000000..3efca74a8 --- /dev/null +++ b/tools/SOCEdit/frmMaincfg.frm @@ -0,0 +1,644 @@ +VERSION 5.00 +Begin VB.Form frmMaincfg + Caption = "Global Game Settings" + ClientHeight = 5295 + ClientLeft = 60 + ClientTop = 345 + ClientWidth = 9360 + Icon = "frmMaincfg.frx":0000 + LinkTopic = "Form1" + MaxButton = 0 'False + ScaleHeight = 5295 + ScaleWidth = 9360 + StartUpPosition = 3 'Windows Default + Begin VB.Frame frmReset + Caption = "Reset Data (Be sure this is at the TOP of your SOC)" + Height = 975 + Left = 4800 + TabIndex = 43 + Top = 4200 + Width = 4455 + Begin VB.CheckBox chkReset + Caption = "Thing Properties" + Height = 255 + Index = 2 + Left = 1680 + TabIndex = 46 + Tag = "4" + Top = 240 + Width = 1575 + End + Begin VB.CheckBox chkReset + Caption = "States" + Height = 255 + Index = 1 + Left = 240 + TabIndex = 45 + Tag = "2" + Top = 600 + Width = 1335 + End + Begin VB.CheckBox chkReset + Caption = "Sprite Names" + Height = 255 + Index = 0 + Left = 240 + TabIndex = 44 + Tag = "1" + Top = 240 + Width = 1575 + End + End + Begin VB.CheckBox chkDisableSpeedAdjust + Caption = "Disable speed adjustment of player animations depending on how fast they are moving." + Height = 375 + Left = 1080 + TabIndex = 42 + Top = 4200 + Width = 3615 + End + Begin VB.TextBox txtTitleScrollSpeed + Height = 285 + Left = 4080 + TabIndex = 41 + Top = 1920 + Width = 495 + End + Begin VB.CheckBox chkLoopTitle + Caption = "Loop the title screen music?" + Height = 195 + Left = 1080 + TabIndex = 39 + Top = 3840 + Width = 2415 + End + Begin VB.TextBox txtCreditsCutscene + Height = 285 + Left = 4080 + TabIndex = 37 + Top = 1560 + Width = 495 + End + Begin VB.CommandButton cmdSave + Caption = "&Save" + Height = 495 + Left = 120 + TabIndex = 36 + Top = 3120 + Width = 735 + End + Begin VB.CommandButton cmdReload + Caption = "&Reload" + Height = 495 + Left = 120 + TabIndex = 35 + Top = 2520 + Width = 735 + End + Begin VB.TextBox txtNumemblems + Height = 285 + Left = 4080 + MaxLength = 2 + TabIndex = 33 + Top = 3360 + Width = 495 + End + Begin VB.TextBox txtGamedata + Height = 285 + Left = 3240 + MaxLength = 64 + TabIndex = 31 + Top = 2880 + Width = 1335 + End + Begin VB.TextBox txtExeccfg + Height = 285 + Left = 3240 + TabIndex = 9 + Top = 2400 + Width = 1335 + End + Begin VB.Frame frmTimers + Caption = "Timers (35 = 1 second)" + Height = 3975 + Left = 4800 + TabIndex = 8 + Top = 120 + Width = 4455 + Begin VB.TextBox txtGameovertics + Height = 285 + Left = 3000 + TabIndex = 29 + Top = 3480 + Width = 1335 + End + Begin VB.TextBox txtHelpertics + Height = 285 + Left = 3000 + TabIndex = 27 + Top = 3120 + Width = 1335 + End + Begin VB.TextBox txtParalooptics + Height = 285 + Left = 3000 + TabIndex = 25 + Top = 2760 + Width = 1335 + End + Begin VB.TextBox txtExtralifetics + Height = 285 + Left = 3000 + TabIndex = 23 + Top = 2400 + Width = 1335 + End + Begin VB.TextBox txtSpacetimetics + Height = 285 + Left = 3000 + TabIndex = 21 + Top = 2040 + Width = 1335 + End + Begin VB.TextBox txtUnderwatertics + Height = 285 + Left = 3000 + TabIndex = 19 + Top = 1680 + Width = 1335 + End + Begin VB.TextBox txtTailsflytics + Height = 285 + Left = 3000 + TabIndex = 17 + Top = 1320 + Width = 1335 + End + Begin VB.TextBox txtFlashingtics + Height = 285 + Left = 3000 + TabIndex = 15 + Top = 960 + Width = 1335 + End + Begin VB.TextBox txtSneakertics + Height = 285 + Left = 3000 + TabIndex = 13 + Top = 600 + Width = 1335 + End + Begin VB.TextBox txtInvulntics + Height = 285 + Left = 3000 + TabIndex = 11 + Top = 240 + Width = 1335 + End + Begin VB.Label lblGameovertics + Alignment = 1 'Right Justify + Caption = "Game Over Screen Time:" + Height = 255 + Left = 960 + TabIndex = 30 + Top = 3480 + Width = 1935 + End + Begin VB.Label lblHelpertics + Alignment = 1 'Right Justify + Caption = "NiGHTS Nightopian Helper Time:" + Height = 255 + Left = 240 + TabIndex = 28 + Top = 3120 + Width = 2655 + End + Begin VB.Label lblParalooptics + Alignment = 1 'Right Justify + Caption = "NiGHTS Paraloop Powerup Time:" + Height = 255 + Left = 360 + TabIndex = 26 + Top = 2760 + Width = 2535 + End + Begin VB.Label lblExtralifetics + Alignment = 1 'Right Justify + Caption = "Extra Life Music Duration:" + Height = 255 + Left = 960 + TabIndex = 24 + Top = 2400 + Width = 1935 + End + Begin VB.Label lblSpacetimetics + Alignment = 1 'Right Justify + Caption = "Space Breath Timeout:" + Height = 255 + Left = 1200 + TabIndex = 22 + Top = 2040 + Width = 1695 + End + Begin VB.Label lblUnderwatertics + Alignment = 1 'Right Justify + Caption = "Underwater Breath Timeout:" + Height = 255 + Left = 840 + TabIndex = 20 + Top = 1680 + Width = 2055 + End + Begin VB.Label lblTailsflytics + Alignment = 1 'Right Justify + Caption = "Tails Flying Time:" + Height = 255 + Left = 1440 + TabIndex = 18 + Top = 1320 + Width = 1455 + End + Begin VB.Label lblFlashingtics + Alignment = 1 'Right Justify + Caption = "Flashing Time After Being Hit:" + Height = 255 + Left = 360 + TabIndex = 16 + Top = 960 + Width = 2535 + End + Begin VB.Label lblSneakertics + Alignment = 1 'Right Justify + Caption = "Super Sneakers Time:" + Height = 255 + Left = 240 + TabIndex = 14 + Top = 600 + Width = 2655 + End + Begin VB.Label lblInvulntics + Alignment = 1 'Right Justify + Caption = "Invincibility Time:" + Height = 255 + Left = 360 + TabIndex = 12 + Top = 240 + Width = 2535 + End + End + Begin VB.TextBox txtIntrotoplay + Height = 285 + Left = 4080 + TabIndex = 6 + Top = 1200 + Width = 495 + End + Begin VB.TextBox txtRacestage_start + Height = 285 + Left = 4080 + MaxLength = 4 + TabIndex = 4 + Top = 840 + Width = 495 + End + Begin VB.TextBox txtSpstage_start + Height = 285 + Left = 4080 + MaxLength = 4 + TabIndex = 2 + Top = 480 + Width = 495 + End + Begin VB.TextBox txtSstage_start + Height = 285 + Left = 4080 + MaxLength = 4 + TabIndex = 0 + Top = 120 + Width = 495 + End + Begin VB.Label lblTitleScrollSpeed + Alignment = 1 'Right Justify + Caption = "Scroll speed of title background:" + Height = 255 + Left = 1560 + TabIndex = 40 + Top = 1920 + Width = 2415 + End + Begin VB.Label lblCreditsCutscene + Alignment = 1 'Right Justify + Caption = "Cutscene # to replace credits with:" + Height = 255 + Left = 1080 + TabIndex = 38 + Top = 1560 + Width = 2895 + End + Begin VB.Label lblNumemblems + Alignment = 1 'Right Justify + Caption = "# of LEVEL Emblems (Gamedata field must also be filled out):" + Height = 375 + Left = 1440 + TabIndex = 34 + Top = 3240 + Width = 2535 + End + Begin VB.Label lblGamedata + Alignment = 1 'Right Justify + Caption = "Gamedata file (to save mod emblems and time data):" + Height = 375 + Left = 960 + TabIndex = 32 + Top = 2760 + Width = 2175 + End + Begin VB.Label lblExeccfg + Alignment = 1 'Right Justify + Caption = "CFG file to instantly execute upon loading this SOC:" + Height = 495 + Left = 960 + TabIndex = 10 + Top = 2280 + Width = 2175 + End + Begin VB.Label lblIntrotoplay + Alignment = 1 'Right Justify + Caption = "Cutscene # to use for introduction:" + Height = 255 + Left = 1440 + TabIndex = 7 + Top = 1200 + Width = 2535 + End + Begin VB.Label lblRacestage_start + Alignment = 1 'Right Justify + Caption = "Racing mode starts/loops back to this map #:" + Height = 255 + Left = 720 + TabIndex = 5 + Top = 840 + Width = 3255 + End + Begin VB.Label lblSpstage_start + Alignment = 1 'Right Justify + Caption = "Single Player Game Starts on this map #:" + Height = 255 + Left = 1080 + TabIndex = 3 + Top = 480 + Width = 2895 + End + Begin VB.Label lblSstage_start + Alignment = 1 'Right Justify + Caption = "First Special Stage Map #:" + Height = 255 + Left = 2040 + TabIndex = 1 + Top = 120 + Width = 1935 + End +End +Attribute VB_Name = "frmMaincfg" +Attribute VB_GlobalNameSpace = False +Attribute VB_Creatable = False +Attribute VB_PredeclaredId = True +Attribute VB_Exposed = False +Private Sub cmdReload_Click() + Call Reload +End Sub + +Private Sub cmdSave_Click() + Call WriteSettings +End Sub + +Private Sub Form_Load() + Call Reload +End Sub + +Private Sub ClearForm() + Dim i As Integer + + txtSstage_start.Text = "" + txtSpstage_start.Text = "" + txtRacestage_start.Text = "" + txtIntrotoplay.Text = "" + txtExeccfg.Text = "" + txtGamedata.Text = "" + txtNumemblems.Text = "" + txtInvulntics.Text = "" + txtSneakertics.Text = "" + txtFlashingtics.Text = "" + txtTailsflytics.Text = "" + txtUnderwatertics.Text = "" + txtSpacetimetics.Text = "" + txtExtralifetics.Text = "" + txtParalooptics.Text = "" + txtHelpertics.Text = "" + txtGameovertics.Text = "" + txtCreditsCutscene.Text = "" + txtTitleScrollSpeed.Text = "" + chkLoopTitle.Value = 0 + chkDisableSpeedAdjust.Value = 0 + + For i = 0 To 2 + chkReset(i).Value = 0 + Next i +End Sub + +Private Sub Reload() + Call ClearForm + Call ReadSOCMaincfg +End Sub + +Private Sub ReadSOCMaincfg() + Dim myFSO As New Scripting.FileSystemObject + Dim ts As TextStream + Dim line As String + Dim word As String + Dim word2 As String + + Set ts = myFSO.OpenTextFile(SOCFile, ForReading, False) + +SOCLoad: + Do While Not ts.AtEndOfStream + line = ts.ReadLine + + If Left(line, 1) = "#" Then GoTo SOCLoad + + If Left(line, 1) = vbCrLf Then GoTo SOCLoad + + If Len(line) < 1 Then GoTo SOCLoad + + word = FirstToken(line) + word2 = SecondToken(line) + + If UCase(word) = "MAINCFG" Then + Do While Len(line) > 0 And Not ts.AtEndOfStream + line = ts.ReadLine + word = UCase(FirstToken(line)) + word2 = UCase(SecondTokenEqual(line)) + + If word = "SSTAGE_START" Then + txtSstage_start.Text = Val(word2) + ElseIf word = "SPSTAGE_START" Then + txtSpstage_start.Text = Val(word2) + ElseIf word = "RACESTAGE_START" Then + txtRacestage_start.Text = Val(word2) + ElseIf word = "INVULNTICS" Then + txtInvulntics.Text = Val(word2) + ElseIf word = "SNEAKERTICS" Then + txtSneakertics.Text = Val(word2) + ElseIf word = "FLASHINGTICS" Then + txtFlashingtics.Text = Val(word2) + ElseIf word = "TAILSFLYTICS" Then + txtTailsflytics.Text = Val(word2) + ElseIf word = "UNDERWATERTICS" Then + txtUnderwatertics.Text = Val(word2) + ElseIf word = "SPACETIMETICS" Then + txtSpacetimetics.Text = Val(word2) + ElseIf word = "EXTRALIFETICS" Then + txtExtralifetics.Text = Val(word2) + ElseIf word = "PARALOOPTICS" Then + txtParalooptics.Text = Val(word2) + ElseIf word = "HELPERTICS" Then + txtHelpertics.Text = Val(word2) + ElseIf word = "GAMEOVERTICS" Then + txtGameovertics.Text = Val(word2) + ElseIf word = "INTROTOPLAY" Then + txtIntrotoplay.Text = Val(word2) + ElseIf word = "CREDITSCUTSCENE" Then + txtCreditsCutscene.Text = Val(word2) + ElseIf word = "TITLESCROLLSPEED" Then + txtTitleScrollSpeed.Text = Val(word2) + ElseIf word = "LOOPTITLE" Then + chkLoopTitle.Value = Val(word2) + ElseIf word = "DISABLESPEEDADJUST" Then + chkDisableSpeedAdjust.Value = Val(word2) + ElseIf word = "GAMEDATA" Then + txtGamedata.Text = word2 + ElseIf word = "NUMEMBLEMS" Then + txtNumemblems.Text = Val(word2) + ElseIf word = "RESETDATA" Then + Dim resetflags As Integer + Dim z As Integer + + resetflags = Val(word2) + + For z = 0 To 2 + If resetflags And chkReset(z).Tag Then + chkReset(z).Value = 1 + Else + chkReset(z).Value = 0 + End If + Next z + ElseIf Len(line) > 0 And Left(line, 1) <> "#" Then + MsgBox "Error in SOC!" & vbCrLf & "Unknown line: " & line + End If + Loop + Exit Do + End If + Loop + + ts.Close + Set myFSO = Nothing +End Sub + +Private Sub WriteSettings() + Dim myFSOSource As New Scripting.FileSystemObject + Dim tsSource As TextStream + Dim myFSOTarget As New Scripting.FileSystemObject + Dim tsTarget As TextStream + Dim line As String + Dim word As String + Dim word2 As String + Dim flags As Long + Dim i As Integer + + Set tsSource = myFSOSource.OpenTextFile(SOCFile, ForReading, False) + Set tsTarget = myFSOTarget.OpenTextFile(SOCTemp, ForWriting, True) + + Do While Not tsSource.AtEndOfStream + line = tsSource.ReadLine + word = UCase(FirstToken(line)) + word2 = UCase(SecondToken(line)) + + 'If the category exists in the SOC, delete it. + If word = "MAINCFG" Then + Do While Len(TrimComplete(tsSource.ReadLine)) > 0 And Not (tsSource.AtEndOfStream) + Loop + Else + tsTarget.WriteLine line + End If + Loop + + tsSource.Close + Set myFSOSource = Nothing + + If line <> "" Then tsTarget.WriteLine "" + + tsTarget.WriteLine "MAINCFG CATEGORY" + txtSstage_start.Text = TrimComplete(txtSstage_start.Text) + txtSpstage_start.Text = TrimComplete(txtSpstage_start.Text) + txtRacestage_start.Text = TrimComplete(txtRacestage_start.Text) + txtIntrotoplay.Text = TrimComplete(txtIntrotoplay.Text) + txtCreditsCutscene.Text = TrimComplete(txtCreditsCutscene.Text) + txtExeccfg.Text = TrimComplete(txtExeccfg.Text) + txtGamedata.Text = TrimComplete(txtGamedata.Text) + txtNumemblems.Text = TrimComplete(txtNumemblems.Text) + txtInvulntics.Text = TrimComplete(txtInvulntics.Text) + txtSneakertics.Text = TrimComplete(txtSneakertics.Text) + txtFlashingtics.Text = TrimComplete(txtFlashingtics.Text) + txtTailsflytics.Text = TrimComplete(txtTailsflytics.Text) + txtUnderwatertics.Text = TrimComplete(txtUnderwatertics.Text) + txtSpacetimetics.Text = TrimComplete(txtSpacetimetics.Text) + txtExtralifetics.Text = TrimComplete(txtExtralifetics.Text) + txtParalooptics.Text = TrimComplete(txtParalooptics.Text) + txtHelpertics.Text = TrimComplete(txtHelpertics.Text) + txtGameovertics.Text = TrimComplete(txtGameovertics.Text) + txtTitleScrollSpeed.Text = TrimComplete(txtTitleScrollSpeed.Text) + + If txtSstage_start.Text <> "" Then tsTarget.WriteLine "SSTAGE_START = " & Val(txtSstage_start.Text) + If txtSpstage_start.Text <> "" Then tsTarget.WriteLine "SPSTAGE_START = " & Val(txtSpstage_start.Text) + If txtRacestage_start.Text <> "" Then tsTarget.WriteLine "RACESTAGE_START = " & Val(txtRacestage_start.Text) + If txtIntrotoplay.Text <> "" Then tsTarget.WriteLine "INTROTOPLAY = " & Val(txtIntrotoplay.Text) + If txtCreditsCutscene.Text <> "" Then tsTarget.WriteLine "CREDITSCUTSCENE = " & Val(txtCreditsCutscene.Text) + If txtExeccfg.Text <> "" Then tsTarget.WriteLine "EXECCFG = " & txtExeccfg.Text + If txtGamedata.Text <> "" Then tsTarget.WriteLine "GAMEDATA = " & txtGamedata.Text + If txtNumemblems.Text <> "" Then + tsTarget.WriteLine "NUMEMBLEMS = " & Val(txtNumemblems.Text) + EditedNumemblems = True + End If + If txtInvulntics.Text <> "" Then tsTarget.WriteLine "INVULNTICS = " & Val(txtInvulntics.Text) + If txtSneakertics.Text <> "" Then tsTarget.WriteLine "SNEAKERTICS = " & Val(txtSneakertics.Text) + If txtFlashingtics.Text <> "" Then tsTarget.WriteLine "FLASHINGTICS = " & Val(txtFlashingtics.Text) + If txtTailsflytics.Text <> "" Then tsTarget.WriteLine "TAILSFLYTICS = " & Val(txtTailsflytics.Text) + If txtUnderwatertics.Text <> "" Then tsTarget.WriteLine "UNDERWATERTICS = " & Val(txtUnderwatertics.Text) + If txtSpacetimetics.Text <> "" Then tsTarget.WriteLine "SPACETIMETICS = " & Val(txtSpacetimetics.Text) + If txtExtralifetics.Text <> "" Then tsTarget.WriteLine "EXTRALIFETICS = " & Val(txtExtralifetics.Text) + If txtParalooptics.Text <> "" Then tsTarget.WriteLine "PARALOOPTICS = " & Val(txtParalooptics.Text) + If txtHelpertics.Text <> "" Then tsTarget.WriteLine "HELPERTICS = " & Val(txtHelpertics.Text) + If txtGameovertics.Text <> "" Then tsTarget.WriteLine "GAMEOVERTICS = " & Val(txtGameovertics.Text) + If txtTitleScrollSpeed.Text <> "" Then tsTarget.WriteLine "TITLESCROLLSPEED = " & Val(txtTitleScrollSpeed.Text) + If chkLoopTitle.Value = 1 Then tsTarget.WriteLine "LOOPTITLE = " & chkLoopTitle.Value + If chkDisableSpeedAdjust.Value = 1 Then tsTarget.WriteLine "DISABLESPEEDADJUST = " & chkDisableSpeedAdjust.Value + + flags = 0 + For i = 0 To 2 + If chkReset(i).Value = 1 Then + flags = flags + Val(chkReset(i).Tag) + End If + Next + + If flags > 0 Then tsTarget.WriteLine "RESETDATA = " & flags + + tsTarget.Close + Set myFSOTarget = Nothing + + FileCopy SOCTemp, SOCFile + + Kill SOCTemp + + MsgBox "Settings Saved." +End Sub + diff --git a/tools/SOCEdit/frmMaincfg.frx b/tools/SOCEdit/frmMaincfg.frx new file mode 100644 index 000000000..2ae367330 Binary files /dev/null and b/tools/SOCEdit/frmMaincfg.frx differ diff --git a/tools/SOCEdit/frmSoundEdit.frm b/tools/SOCEdit/frmSoundEdit.frm new file mode 100644 index 000000000..c91d84ed8 --- /dev/null +++ b/tools/SOCEdit/frmSoundEdit.frm @@ -0,0 +1,485 @@ +VERSION 5.00 +Begin VB.Form frmSoundEdit + Caption = "Sound Edit" + ClientHeight = 4995 + ClientLeft = 60 + ClientTop = 345 + ClientWidth = 6180 + Icon = "frmSoundEdit.frx":0000 + LinkTopic = "Form1" + MaxButton = 0 'False + ScaleHeight = 4995 + ScaleWidth = 6180 + StartUpPosition = 3 'Windows Default + Begin VB.CommandButton cmdDelete + Caption = "&Delete sound from SOC" + Height = 495 + Left = 5040 + Style = 1 'Graphical + TabIndex = 13 + Top = 4320 + Width = 1095 + End + Begin VB.CommandButton cmdSave + Caption = "&Save" + Height = 495 + Left = 3840 + TabIndex = 6 + Top = 4320 + Width = 1095 + End + Begin VB.CommandButton cmdReload + Caption = "&Load Code Default" + Height = 495 + Left = 2640 + Style = 1 'Graphical + TabIndex = 5 + Top = 4320 + Width = 1095 + End + Begin VB.Frame frmSpecial + Caption = "Special Properties" + Height = 3375 + Left = 2640 + TabIndex = 4 + Top = 840 + Width = 3495 + Begin VB.CheckBox chkTotallySingle + Caption = "Make sure only one sound of this is playing at a time on any sound channel." + Height = 615 + Left = 120 + TabIndex = 12 + Tag = "1" + Top = 2640 + Width = 3255 + End + Begin VB.CheckBox chkEightEx + Caption = "Sound can be heard across 8x the distance" + Height = 375 + Left = 120 + TabIndex = 10 + Tag = "16" + Top = 2160 + Width = 2295 + End + Begin VB.CheckBox chkOutside + Caption = "Volume dependent on how close you are to outside" + Height = 375 + Left = 120 + TabIndex = 9 + Tag = "4" + Top = 360 + Width = 2295 + End + Begin VB.CheckBox chkFourEx + Caption = "Sound can be heard across 4x the distance" + Height = 375 + Left = 120 + TabIndex = 8 + Tag = "8" + Top = 1560 + Width = 2055 + End + Begin VB.CheckBox chkMultiple + Caption = "More than one of this sound can be played per object at a time (i.e., thunder)" + Height = 615 + Left = 120 + TabIndex = 7 + Tag = "2" + Top = 840 + Width = 2535 + End + Begin VB.Label Label1 + Caption = "Combine for 32x" + Height = 495 + Left = 2760 + TabIndex = 11 + Top = 1800 + Width = 615 + End + Begin VB.Line Line4 + X1 = 2400 + X2 = 2640 + Y1 = 2400 + Y2 = 2400 + End + Begin VB.Line Line2 + X1 = 2400 + X2 = 2640 + Y1 = 1800 + Y2 = 1800 + End + Begin VB.Line Line1 + X1 = 2640 + X2 = 2640 + Y1 = 2400 + Y2 = 1800 + End + End + Begin VB.ComboBox cmbPriority + Height = 315 + ItemData = "frmSoundEdit.frx":0442 + Left = 3360 + List = "frmSoundEdit.frx":0444 + TabIndex = 2 + Top = 120 + Width = 855 + End + Begin VB.CheckBox chkSingularity + Caption = "Only one can be played at a time per object." + Height = 255 + Left = 2640 + TabIndex = 1 + Top = 480 + Width = 3495 + End + Begin VB.ListBox lstSounds + Height = 4740 + Left = 120 + TabIndex = 0 + Top = 120 + Width = 2415 + End + Begin VB.Line Line3 + X1 = 0 + X2 = 720 + Y1 = 0 + Y2 = 0 + End + Begin VB.Label lblPriority + Alignment = 1 'Right Justify + Caption = "Priority:" + Height = 255 + Left = 2640 + TabIndex = 3 + Top = 120 + Width = 615 + End +End +Attribute VB_Name = "frmSoundEdit" +Attribute VB_GlobalNameSpace = False +Attribute VB_Creatable = False +Attribute VB_PredeclaredId = True +Attribute VB_Exposed = False +Option Explicit + +Private Sub cmdDelete_Click() + Call WriteSound(True) +End Sub + +Private Sub cmdReload_Click() + Call ClearForm + If InStr(lstSounds.List(lstSounds.ListIndex), "(free slot)") = 0 Then + Call LoadSoundInfo(lstSounds.ListIndex) + Else + MsgBox "Free slots do not have a code default." + End If +End Sub + +Private Sub cmdSave_Click() + Call WriteSound(False) +End Sub + +Private Sub Form_Load() + Call Reload +End Sub + +Private Sub ClearForm() + cmbPriority.Text = "" + chkSingularity.Value = 0 + chkOutside.Value = 0 + chkMultiple.Value = 0 + chkFourEx.Value = 0 + chkEightEx.Value = 0 + chkTotallySingle.Value = 0 +End Sub + +Private Sub Reload() + Call ClearForm + Call LoadCode + lstSounds.ListIndex = 0 +End Sub + +Private Sub LoadCode() + Dim myFSO As New Scripting.FileSystemObject + Dim ts As TextStream + Dim line As String + Dim number As Integer + Dim startclip As Integer, endclip As Integer + Dim addstring As String + Dim i As Integer, numfreeslots As Integer + + ChDir SourcePath + Set ts = myFSO.OpenTextFile("sounds.h", ForReading, False) + + Do While InStr(ts.ReadLine, "List of sounds (don't modify this comment!)") = 0 + Loop + + ts.SkipLine ' typedef enum + ts.SkipLine ' { + + line = ts.ReadLine + number = 0 + + lstSounds.Clear + + Do While InStr(line, "sfx_freeslot0") = 0 + startclip = InStr(line, "sfx_") + If InStr(line, "sfx_") <> 0 Then + endclip = InStr(line, ",") + line = Mid(line, startclip, endclip - startclip) + addstring = number & " - " & line + lstSounds.AddItem addstring + number = number + 1 + End If + line = ts.ReadLine + Loop + + ts.Close + Set myFSO = Nothing + +'Populate the free slots! + numfreeslots = 800 + + For i = 1 To numfreeslots + If i < 10 Then + addstring = number & " - " & "sfx_fre00" & i & " (free slot)" + ElseIf i < 100 Then + addstring = number & " - " & "sfx_fre0" & i & " (free slot)" + Else + addstring = number & " - " & "sfx_fre" & i & " (free slot)" + End If + lstSounds.AddItem addstring + number = number + 1 + Next + + For i = 0 To 127 + cmbPriority.AddItem i + Next +End Sub + +Private Sub lstSounds_Click() + Call ClearForm + If InStr(lstSounds.List(lstSounds.ListIndex), "(free slot)") = 0 Then + Call LoadSoundInfo(lstSounds.ListIndex) + End If + Call LoadSOCSoundInfo(lstSounds.ListIndex) +End Sub + +Private Sub LoadSOCSoundInfo(SoundNum As Integer) + Dim myFSO As New Scripting.FileSystemObject + Dim ts As TextStream + Dim line As String + Dim word As String + Dim word2 As String + + Set ts = myFSO.OpenTextFile(SOCFile, ForReading, False) + +SOCLoad: + Do While Not ts.AtEndOfStream + line = ts.ReadLine + + If Left(line, 1) = "#" Then GoTo SOCLoad + + If Left(line, 1) = vbCrLf Then GoTo SOCLoad + + If Len(line) < 1 Then GoTo SOCLoad + + word = FirstToken(line) + word2 = SecondToken(line) + + If UCase(word) = "SOUND" And Val(word2) = SoundNum Then + Do While Len(line) > 0 And Not ts.AtEndOfStream + line = ts.ReadLine + word = UCase(FirstToken(line)) + word2 = UCase(SecondTokenEqual(line)) + + If word = "SINGULAR" Then + If Val(word2) = 1 Then + chkSingularity.Value = 1 + Else + chkSingularity.Value = 0 + End If + ElseIf word = "PRIORITY" Then + cmbPriority.Text = Val(word2) + ElseIf word = "FLAGS" Then + ProcessSoundFlags (Val(word2)) + ElseIf Len(line) > 0 And Left(line, 1) <> "#" Then + MsgBox "Error in SOC!" & vbCrLf & "Unknown line: " & line + End If + Loop + Exit Do + End If + Loop + + ts.Close + Set myFSO = Nothing +End Sub + +Private Sub LoadSoundInfo(StateNum As Integer) + Dim myFSO As New Scripting.FileSystemObject + Dim ts As TextStream + Dim line As String + Dim number As Integer + Dim startclip As Integer, endclip As Integer + Dim token As String + Dim frame As Long + + ChDir SourcePath + Set ts = myFSO.OpenTextFile("sounds.c", ForReading, False) + + Do While InStr(ts.ReadLine, "S_sfx[0] needs to be a dummy for odd reasons.") = 0 + Loop + + number = 0 + + Do While number <> StateNum + Do While InStr(ts.ReadLine, """") = 0 + Loop + number = number + 1 + Loop + + Do While InStr(line, """") = 0 + line = ts.ReadLine + Loop + + startclip = InStr(line, """") + 1 + line = Mid(line, startclip, Len(line) - startclip) + endclip = InStr(line, """") - 1 + token = TrimComplete(Left(line, endclip)) + + 'txtName.Text = line + + startclip = InStr(line, ",") + 1 + line = Mid(line, startclip, Len(line) - startclip) + endclip = InStr(line, ",") - 1 + token = TrimComplete(Left(line, endclip)) + + If token = "true" Then + chkSingularity.Value = 1 + Else + chkSingularity.Value = 0 + End If + + startclip = InStr(line, ",") + 1 + line = Mid(line, startclip, Len(line) - startclip) + endclip = InStr(line, ",") - 1 + token = TrimComplete(Left(line, endclip)) + cmbPriority.Text = token + + startclip = InStr(line, ",") + 1 + line = Mid(line, startclip, Len(line) - startclip) + endclip = InStr(line, ",") - 1 + token = TrimComplete(Left(line, endclip)) + + ProcessSoundFlags (Val(token)) + + ts.Close + Set myFSO = Nothing +End Sub + +Private Sub ProcessSoundFlags(flags As Long) + + chkTotallySingle.Value = 0 + chkMultiple.Value = 0 + chkOutside.Value = 0 + chkFourEx.Value = 0 + chkEightEx.Value = 0 + + If flags = -1 Then + Exit Sub + End If + + If flags And 1 Then + chkTotallySingle.Value = 1 + End If + + If flags And 2 Then + chkMultiple.Value = 1 + End If + + If flags And 4 Then + chkOutside.Value = 1 + End If + + If flags And 8 Then + chkFourEx.Value = 1 + End If + + If flags And 16 Then + chkEightEx.Value = 1 + End If + +End Sub + +Private Sub WriteSound(Remove As Boolean) + Dim myFSOSource As New Scripting.FileSystemObject + Dim tsSource As TextStream + Dim myFSOTarget As New Scripting.FileSystemObject + Dim tsTarget As TextStream + Dim line As String + Dim word As String + Dim word2 As String + Dim flags As Long + Dim soundfound As Boolean + + soundfound = False + + Set tsSource = myFSOSource.OpenTextFile(SOCFile, ForReading, False) + Set tsTarget = myFSOTarget.OpenTextFile(SOCTemp, ForWriting, True) + + Do While Not tsSource.AtEndOfStream + line = tsSource.ReadLine + word = UCase(FirstToken(line)) + word2 = UCase(SecondToken(line)) + + 'If the current sound exists in the SOC, delete it. + If word = "SOUND" And Val(word2) = lstSounds.ListIndex Then + soundfound = True + Do While Len(TrimComplete(tsSource.ReadLine)) > 0 And Not (tsSource.AtEndOfStream) + Loop + Else + tsTarget.WriteLine line + End If + Loop + + tsSource.Close + Set myFSOSource = Nothing + + If Remove = False Then + If line <> "" Then tsTarget.WriteLine "" + + tsTarget.WriteLine "SOUND " & lstSounds.ListIndex + cmbPriority.Text = TrimComplete(cmbPriority.Text) + If cmbPriority.Text <> "" Then tsTarget.WriteLine "PRIORITY = " & Val(cmbPriority.Text) + If chkSingularity.Value = 1 Then tsTarget.WriteLine "SINGULAR = 1" + + flags = 0 + + If chkOutside.Value = 1 Then flags = flags + Val(chkOutside.Tag) + If chkMultiple.Value = 1 Then flags = flags + Val(chkMultiple.Tag) + If chkFourEx.Value = 1 Then flags = flags + Val(chkFourEx.Tag) + If chkEightEx.Value = 1 Then flags = flags + Val(chkEightEx.Tag) + If chkTotallySingle.Value = 1 Then flags = flags + Val(chkTotallySingle.Tag) + + If flags > 0 Then tsTarget.WriteLine "FLAGS = " & flags + End If + + tsTarget.Close + Set myFSOTarget = Nothing + + FileCopy SOCTemp, SOCFile + + Kill SOCTemp + + If Remove = True Then + If soundfound = True Then + MsgBox "Sound removed from SOC." + Else + MsgBox "Sound not found in SOC." + End If + Else + MsgBox "Sound Saved." + End If +End Sub + diff --git a/tools/SOCEdit/frmSoundEdit.frx b/tools/SOCEdit/frmSoundEdit.frx new file mode 100644 index 000000000..980538679 Binary files /dev/null and b/tools/SOCEdit/frmSoundEdit.frx differ diff --git a/tools/SOCEdit/frmStateEdit.frm b/tools/SOCEdit/frmStateEdit.frm new file mode 100644 index 000000000..4eca5a1bc --- /dev/null +++ b/tools/SOCEdit/frmStateEdit.frm @@ -0,0 +1,940 @@ +VERSION 5.00 +Begin VB.Form frmStateEdit + Caption = "State Edit" + ClientHeight = 6750 + ClientLeft = 60 + ClientTop = 345 + ClientWidth = 8970 + Icon = "frmStateEdit.frx":0000 + LinkTopic = "Form1" + MaxButton = 0 'False + ScaleHeight = 6750 + ScaleWidth = 8970 + StartUpPosition = 3 'Windows Default + Begin VB.TextBox lblVar2Desc + Height = 495 + Left = 4440 + Locked = -1 'True + MultiLine = -1 'True + ScrollBars = 2 'Vertical + TabIndex = 25 + Top = 3000 + Width = 4455 + End + Begin VB.TextBox lblVar1Desc + Height = 495 + Left = 4440 + Locked = -1 'True + MultiLine = -1 'True + ScrollBars = 2 'Vertical + TabIndex = 24 + Top = 2400 + Width = 4455 + End + Begin VB.TextBox lblActionDesc + Height = 735 + Left = 4440 + Locked = -1 'True + MultiLine = -1 'True + ScrollBars = 2 'Vertical + TabIndex = 23 + Top = 1560 + Width = 4455 + End + Begin VB.ListBox lstThings + Height = 450 + ItemData = "frmStateEdit.frx":0442 + Left = 7440 + List = "frmStateEdit.frx":0444 + TabIndex = 22 + Top = 6120 + Visible = 0 'False + Width = 975 + End + Begin VB.TextBox txtFuncVar2 + Height = 285 + Left = 7200 + TabIndex = 19 + Top = 3600 + Width = 1215 + End + Begin VB.TextBox txtFuncVar1 + Height = 285 + Left = 5520 + TabIndex = 18 + Top = 3600 + Width = 1095 + End + Begin VB.CommandButton cmdCopy + Caption = "&Copy state to..." + Height = 495 + Left = 6120 + Style = 1 'Graphical + TabIndex = 17 + Top = 6120 + Width = 1095 + End + Begin VB.CommandButton cmdDelete + Caption = "&Delete State from SOC" + Height = 495 + Left = 6120 + Style = 1 'Graphical + TabIndex = 16 + Top = 5520 + Width = 1095 + End + Begin VB.CommandButton cmdReload + Caption = "&Load Code Default" + Height = 495 + Left = 4920 + Style = 1 'Graphical + TabIndex = 15 + Top = 5520 + Width = 1095 + End + Begin VB.CommandButton cmdSave + Caption = "&Save" + Height = 495 + Left = 7320 + TabIndex = 14 + Top = 5520 + Width = 1095 + End + Begin VB.ComboBox cmbTranslucency + Height = 315 + ItemData = "frmStateEdit.frx":0446 + Left = 6720 + List = "frmStateEdit.frx":045C + TabIndex = 12 + Top = 5040 + Width = 1695 + End + Begin VB.CheckBox chkFullbright + Caption = "Make sprite full-brightness (unaffected by lighting)" + Height = 495 + Left = 6240 + TabIndex = 11 + Top = 4440 + Width = 2175 + End + Begin VB.ComboBox cmbNextstate + Height = 315 + Left = 6120 + TabIndex = 9 + Top = 3960 + Width = 2295 + End + Begin VB.ComboBox cmbAction + Height = 315 + Left = 6000 + TabIndex = 7 + Top = 1200 + Width = 2295 + End + Begin VB.TextBox txtTics + Height = 285 + Left = 7800 + TabIndex = 5 + Top = 720 + Width = 495 + End + Begin VB.TextBox txtFrame + Height = 285 + Left = 5880 + MaxLength = 2 + TabIndex = 3 + Top = 720 + Width = 495 + End + Begin VB.ComboBox cmbSprite + Height = 315 + Left = 5880 + TabIndex = 1 + Top = 120 + Width = 2415 + End + Begin VB.ListBox lstStates + Height = 6495 + Left = 120 + TabIndex = 0 + Top = 120 + Width = 4215 + End + Begin VB.Label lblFuncVar2 + Alignment = 1 'Right Justify + Caption = "Var2:" + Height = 255 + Left = 6600 + TabIndex = 21 + Top = 3600 + Width = 495 + End + Begin VB.Label lblFuncVar1 + Alignment = 1 'Right Justify + Caption = "Var1:" + Height = 255 + Left = 4920 + TabIndex = 20 + Top = 3600 + Width = 495 + End + Begin VB.Label lblTranslucency + Alignment = 1 'Right Justify + Caption = "Translucency:" + Height = 255 + Left = 5520 + TabIndex = 13 + Top = 5040 + Width = 1095 + End + Begin VB.Label lblNextstate + Alignment = 1 'Right Justify + Caption = "Next State:" + Height = 255 + Left = 5160 + TabIndex = 10 + Top = 3960 + Width = 855 + End + Begin VB.Label lblAction + Alignment = 1 'Right Justify + Caption = "Function to Call:" + Height = 375 + Left = 5040 + TabIndex = 8 + Top = 1080 + Width = 855 + End + Begin VB.Label lblTics + Alignment = 1 'Right Justify + Caption = "Tics (-1 for infinite duration):" + Height = 495 + Left = 6480 + TabIndex = 6 + Top = 600 + Width = 1215 + End + Begin VB.Label lblFrame + Alignment = 1 'Right Justify + Caption = "Frame:" + Height = 255 + Left = 5160 + TabIndex = 4 + Top = 720 + Width = 615 + End + Begin VB.Label lblSprite + Alignment = 1 'Right Justify + Caption = "Sprite:" + Height = 255 + Left = 5160 + TabIndex = 2 + Top = 120 + Width = 615 + End +End +Attribute VB_Name = "frmStateEdit" +Attribute VB_GlobalNameSpace = False +Attribute VB_Creatable = False +Attribute VB_PredeclaredId = True +Attribute VB_Exposed = False +Option Explicit + +Private Sub cmbAction_Click() + Dim myFSO As New Scripting.FileSystemObject + Dim ts As TextStream + Dim line As String + Dim index As Integer + Dim ActionName As String + + ActionName = cmbAction.List(cmbAction.ListIndex) + + If cmbAction.ListIndex = 0 Then + lblActionDesc.Text = "" + lblVar1Desc.Text = "" + lblVar2Desc.Text = "" + Exit Sub + End If + + ChDir SourcePath + Set ts = myFSO.OpenTextFile("p_enemy.c", ForReading, False) + + Do While Not ts.AtEndOfStream + line = ts.ReadLine + + If Mid(line, 4, 9) = "Function:" And InStr(line, ActionName) > 0 Then + ts.ReadLine ' // + line = ts.ReadLine ' // Description: + index = InStr(line, ":") + lblActionDesc.Text = Mid(line, index + 2, Len(line) - (index + 1)) + + ts.ReadLine ' // + line = ts.ReadLine ' // var1 = + If InStr(line, "var1:") Then + lblVar1Desc.Text = Mid(line, 4, Len(line) - 3) + line = ts.ReadLine + Do While Left(line, 7) <> "// var2" + lblVar1Desc.Text = lblVar1Desc.Text & vbCrLf & TrimComplete(Mid(line, 4, Len(line) - 3)) + line = ts.ReadLine + Loop + Else + lblVar1Desc.Text = Mid(line, 4, Len(line) - 3) + End If + + If Left(line, 7) <> "// var2" Then + line = ts.ReadLine ' // var2 = + End If + + If InStr(line, "var2:") Then + lblVar2Desc.Text = Mid(line, 4, Len(line) - 3) + line = ts.ReadLine + Do While Len(line) > 4 + lblVar2Desc.Text = lblVar2Desc.Text & vbCrLf & TrimComplete(Mid(line, 4, Len(line) - 3)) + line = ts.ReadLine + Loop + Else + lblVar2Desc.Text = Mid(line, 4, Len(line) - 3) + End If + End If + Loop + + ts.Close + Set myFSO = Nothing +End Sub + +Private Sub cmdCopy_Click() + Dim Response As String + + Response$ = InputBox("Copy state to #:", "Copy State") + + If Response = "" Then Exit Sub + + Response = TrimComplete(Response) + + Call WriteState(False, Val(Response)) + + MsgBox "State copied to #" & Val(Response) +End Sub + +Private Sub cmdDelete_Click() + Call WriteState(True, lstStates.ListIndex) +End Sub + +Private Sub cmdReload_Click() + Call ClearForm + + If InStr(lstStates.List(lstStates.ListIndex), "S_FREESLOT") = 0 Then + LoadStateInfo (lstStates.ListIndex) + Else + MsgBox "Free slots do not have a code default." + End If +End Sub + +Private Sub cmdSave_Click() + If TrimComplete(txtFrame.Text) = "" And (chkFullbright.Value = 1 Or cmbTranslucency.ListIndex > 0) Then + MsgBox "ERROR: Frame field required for fullbright/translucency." + Exit Sub + End If + Call WriteState(False, lstStates.ListIndex) +End Sub + +Private Sub Form_Load() + Call Reload + lstStates.ListIndex = 0 +End Sub + +Private Sub ClearForm() + cmbNextstate.Text = "" + cmbSprite.Text = "" + txtFrame.Text = "" + cmbAction.Text = "" + txtFuncVar1.Text = "" + txtFuncVar2.Text = "" + lblActionDesc.Text = "" + lblVar1Desc.Text = "" + lblVar2Desc.Text = "" + chkFullbright.Value = False + cmbTranslucency.ListIndex = 0 +End Sub + +Private Sub Reload() + LoadStates + LoadSprites + LoadActions +End Sub + +Private Sub LoadStates() + Dim myFSO As New Scripting.FileSystemObject + Dim ts As TextStream + Dim line As String + Dim number As Integer + Dim startclip As Integer, endclip As Integer + Dim addstring As String + Dim numfreeslots As Integer, i As Integer + + ChDir SourcePath + Set ts = myFSO.OpenTextFile("info.h", ForReading, False) + + Do While InStr(ts.ReadLine, "Object states (don't modify this comment!)") = 0 + Loop + + ts.SkipLine ' typedef enum + ts.SkipLine ' { + + line = ts.ReadLine + number = 0 + + lstStates.Clear + + Do While InStr(line, "S_FIRSTFREESLOT") = 0 + startclip = InStr(line, "S_") + If InStr(line, "S_") <> 0 Then + endclip = InStr(line, ",") + line = Mid(line, startclip, endclip - startclip) + addstring = number & " - " & line + lstStates.AddItem addstring + cmbNextstate.AddItem addstring + number = number + 1 + End If + line = ts.ReadLine + Loop + + ts.Close + + 'Populate the free slots! + Set ts = myFSO.OpenTextFile("info.h", ForReading, False) + + line = ts.ReadLine + Do While InStr(line, "#define NUMMOBJFREESLOTS") = 0 + line = ts.ReadLine + Loop + + startclip = InStr(line, "SLOTS ") + 6 + numfreeslots = Val(Mid(line, startclip, Len(line) - startclip + 1)) * 6 + + For i = 1 To numfreeslots + addstring = number & " - " & "S_FREESLOT" & i + lstStates.AddItem addstring + cmbNextstate.AddItem addstring + number = number + 1 + Next + + ts.Close + Set myFSO = Nothing +End Sub + +Private Sub LoadSprites() + Dim myFSO As New Scripting.FileSystemObject + Dim ts As TextStream + Dim line As String + Dim number As Integer + Dim startclip As Integer, endclip As Integer + Dim addstring As String + Dim numfreeslots As Integer, i As Integer + + ChDir SourcePath + Set ts = myFSO.OpenTextFile("info.h", ForReading, False) + + Do While InStr(ts.ReadLine, "Hey, moron! If you change this table, don't forget about") = 0 + Loop + + ts.SkipLine ' typedef enum + ts.SkipLine ' { + + line = ts.ReadLine + number = 0 + + cmbSprite.Clear + + Do While InStr(line, "SPR_FIRSTFREESLOT") = 0 + startclip = InStr(line, "SPR_") + If InStr(line, "SPR_") <> 0 Then + endclip = InStr(line, ",") + line = Mid(line, startclip, endclip - startclip) + addstring = number & " - " & line + cmbSprite.AddItem addstring + number = number + 1 + End If + line = ts.ReadLine + Loop + + ts.Close + + 'Populate the free slots! + Set ts = myFSO.OpenTextFile("info.h", ForReading, False) + + line = ts.ReadLine + Do While InStr(line, "#define NUMMOBJFREESLOTS") = 0 + line = ts.ReadLine + Loop + + startclip = InStr(line, "SLOTS ") + 6 + numfreeslots = Val(Mid(line, startclip, Len(line) - startclip + 1)) + + For i = 1 To numfreeslots + If i < 10 Then + addstring = number & " - " & "SPR_F00" & i & " (Free slot)" + ElseIf i < 100 Then + addstring = number & " - " & "SPR_F0" & i & " (Free slot)" + Else + addstring = number & " - " & "SPR_F" & i & " (Free slot)" + End If + + cmbSprite.AddItem addstring + number = number + 1 + Next + + ts.Close + + Set myFSO = Nothing +End Sub + +Private Sub LoadActions() + Dim myFSO As New Scripting.FileSystemObject + Dim ts As TextStream + Dim line As String + Dim number As Integer + Dim startclip As Integer, endclip As Integer + Dim addstring As String + + ChDir SourcePath + Set ts = myFSO.OpenTextFile("dehacked.c", ForReading, False) + + Do While InStr(ts.ReadLine, "actionpointer_t actionpointers[]") = 0 + Loop + + ts.SkipLine ' { + + line = ts.ReadLine + number = 0 + + cmbAction.Clear + + cmbAction.AddItem "None" + + Do While InStr(line, "NULL") = 0 + startclip = InStr(line, "A_") + If InStr(line, "A_") <> 0 Then + endclip = InStr(line, "}") + line = Mid(line, startclip, endclip - startclip) + cmbAction.AddItem line + number = number + 1 + End If + line = ts.ReadLine + Loop + + ts.Close + Set myFSO = Nothing +End Sub + +Private Sub lstStates_Click() + Call ClearForm + + If InStr(lstStates.List(lstStates.ListIndex), "S_FREESLOT") = 0 Then + LoadStateInfo (lstStates.ListIndex) + End If + + LoadSOCStateInfo (lstStates.ListIndex) +End Sub + +Private Sub LoadSOCStateInfo(StateNum As Integer) + Dim myFSO As New Scripting.FileSystemObject + Dim ts As TextStream + Dim line As String + Dim word As String + Dim word2 As String + Dim frameNum As Long + + Set ts = myFSO.OpenTextFile(SOCFile, ForReading, False) + +SOCLoad: + Do While Not ts.AtEndOfStream + line = ts.ReadLine + + If Left(line, 1) = "#" Then GoTo SOCLoad + + If Left(line, 1) = vbCrLf Then GoTo SOCLoad + + If Len(line) < 1 Then GoTo SOCLoad + + word = FirstToken(line) + word2 = SecondToken(line) + + If UCase(word) = "FRAME" And Val(word2) = StateNum Then + Do While Len(line) > 0 And Not ts.AtEndOfStream + line = ts.ReadLine + word = UCase(FirstToken(line)) + word2 = UCase(SecondTokenEqual(line)) + + If word = "SPRITENUMBER" Then + cmbSprite.ListIndex = Val(word2) + ElseIf word = "SPRITESUBNUMBER" Then + frameNum = Val(word2) + + If frameNum >= 327680 Then ' 5 << 16 + cmbTranslucency.ListIndex = 5 + frameNum = frameNum And Not 327680 + ElseIf frameNum >= 262144 Then ' 4 << 16 + cmbTranslucency.ListIndex = 4 + frameNum = frameNum And Not 262144 + ElseIf frameNum >= 196608 Then ' 3 << 16 + cmbTranslucency.ListIndex = 3 + frameNum = frameNum And Not 196608 + ElseIf frameNum >= 131072 Then ' 2 << 16 + cmbTranslucency.ListIndex = 2 + frameNum = frameNum And Not 131072 + ElseIf frameNum >= 65536 Then ' 1 << 16 + cmbTranslucency.ListIndex = 1 + frameNum = frameNum And Not 65536 + End If + + If frameNum >= 32768 Then + chkFullbright.Value = 1 + frameNum = frameNum And Not 32768 + Else + chkFullbright.Value = 0 + End If + + txtFrame.Text = frameNum + ElseIf word = "DURATION" Then + txtTics.Text = Val(word2) + ElseIf word = "NEXT" Then + cmbNextstate.ListIndex = Val(word2) + ElseIf word = "ACTION" Then + Call FindComboIndex(cmbAction, UCase(SecondToken(line))) + ElseIf word = "VAR1" Then + txtFuncVar1.Text = Val(word2) + ElseIf word = "VAR2" Then + txtFuncVar2.Text = Val(word2) + ElseIf Len(line) > 0 And Left(line, 1) <> "#" Then + MsgBox "Error in SOC!" & vbCrLf & "Unknown line: " & line + End If + Loop + Exit Do + End If + Loop + + ts.Close + Set myFSO = Nothing +End Sub + +Private Sub LoadStateInfo(StateNum As Integer) + Dim myFSO As New Scripting.FileSystemObject + Dim ts As TextStream + Dim line As String + Dim number As Integer + Dim startclip As Integer, endclip As Integer + Dim token As String + Dim frame As Long + Dim templine As String + + ChDir SourcePath + Set ts = myFSO.OpenTextFile("info.c", ForReading, False) + + Do While InStr(ts.ReadLine, "Keep this comment directly above S_NULL") = 0 + Loop + + number = 0 + + Do While number <> StateNum + Do While InStr(ts.ReadLine, "SPR_") = 0 + Loop + number = number + 1 + Loop + + Do While InStr(line, "SPR_") = 0 + line = ts.ReadLine + Loop + + startclip = InStr(line, "SPR_") + line = Mid(line, startclip, Len(line) - startclip) + endclip = InStr(line, ",") - 1 + token = Left(line, endclip) + Call FindComboIndex(cmbSprite, token) + + startclip = InStr(line, ",") + 1 + line = TrimComplete(Mid(line, startclip, Len(line) - startclip)) + endclip = InStr(line, ",") - 1 + frame = Val(Left(line, endclip)) + + If frame >= 32768 Then + chkFullbright.Value = 1 + frame = frame - 32768 + Else + chkFullbright.Value = 0 + End If + + txtFrame.Text = frame + + cmbTranslucency.ListIndex = 0 + + startclip = InStr(line, ",") + 1 + line = TrimComplete(Mid(line, startclip, Len(line) - startclip)) + endclip = InStr(line, ",") - 1 + txtTics.Text = Val(Left(line, endclip)) + + startclip = InStr(line, "{") + 1 + line = TrimComplete(Mid(line, startclip, Len(line) - startclip)) + endclip = InStr(line, "}") - 1 + cmbAction.Text = TrimComplete(Left(line, endclip)) + If cmbAction.Text = "NULL" Then cmbAction.Text = "None" + + startclip = InStr(line, ",") + 1 + line = TrimComplete(Mid(line, startclip, Len(line) - startclip)) + endclip = InStr(line, ",") - 1 + templine = Left(line, endclip) + + templine = TrimComplete(templine) + 'Check for *FRACUNIT values + endclip = InStr(templine, "*FRACUNIT") + If endclip <> 0 Then + templine = Left(templine, endclip - 1) + templine = Val(templine) * 65536 + End If + 'Check for crazy-odd MT_ usage + endclip = InStr(templine, "MT_") + If endclip <> 0 Then + templine = FindThingNum(templine) & " - " & templine + End If + 'Check for crazy-odd pw_ usage + endclip = InStr(templine, "pw_") + If endclip <> 0 Then + templine = FindPowerNum(templine) & " - " & templine + End If + txtFuncVar1.Text = templine + + startclip = InStr(line, ",") + 1 + line = TrimComplete(Mid(line, startclip, Len(line) - startclip)) + endclip = InStr(line, ",") - 1 + templine = Left(line, endclip) + + templine = TrimComplete(templine) + 'Check for *FRACUNIT values + endclip = InStr(templine, "*FRACUNIT") + If endclip <> 0 Then + templine = Left(templine, endclip - 1) + templine = Val(templine) * 65536 + End If + 'Check for crazy-odd MT_ usage + endclip = InStr(templine, "MT_") + If endclip <> 0 Then + templine = FindThingNum(templine) & " - " & templine + End If + 'Check for crazy-odd pw_ usage + endclip = InStr(templine, "pw_") + If endclip <> 0 Then + templine = FindPowerNum(templine) & " - " & templine + End If + txtFuncVar2.Text = templine + + startclip = InStr(line, ",") + 1 + line = TrimComplete(Mid(line, startclip, Len(line) - startclip)) + endclip = InStr(line, "}") - 1 + Call FindComboIndex(cmbNextstate, TrimComplete(Left(line, endclip))) + + ts.Close + Set myFSO = Nothing +End Sub + +Private Sub FindComboIndex(ByRef Box As ComboBox, line As String) + Dim i As Integer + + For i = 0 To Box.ListCount + If InStr(UCase(Box.List(i)), UCase(line)) Then + Box.ListIndex = i + Exit For + End If + Next +End Sub + +Private Sub WriteState(Remove As Boolean, num As Integer) + Dim myFSOSource As New Scripting.FileSystemObject + Dim tsSource As TextStream + Dim myFSOTarget As New Scripting.FileSystemObject + Dim tsTarget As TextStream + Dim line As String + Dim word As String + Dim word2 As String + Dim flags As Long + Dim statefound As Boolean + + statefound = False + + Set tsSource = myFSOSource.OpenTextFile(SOCFile, ForReading, False) + Set tsTarget = myFSOTarget.OpenTextFile(SOCTemp, ForWriting, True) + + Do While Not tsSource.AtEndOfStream + line = tsSource.ReadLine + word = UCase(FirstToken(line)) + word2 = UCase(SecondToken(line)) + + 'If the current sound exists in the SOC, delete it. + If word = "FRAME" And Val(word2) = num Then + statefound = True + Do While Len(TrimComplete(tsSource.ReadLine)) > 0 And Not (tsSource.AtEndOfStream) + Loop + Else + tsTarget.WriteLine line + End If + Loop + + tsSource.Close + Set myFSOSource = Nothing + + If Remove = False Then + If line <> "" Then tsTarget.WriteLine "" + + tsTarget.WriteLine "FRAME " & num + cmbSprite.Text = TrimComplete(cmbSprite.Text) + txtFrame.Text = TrimComplete(txtFrame.Text) + txtTics.Text = TrimComplete(txtTics.Text) + cmbAction.Text = TrimComplete(cmbAction.Text) + txtFuncVar1.Text = TrimComplete(txtFuncVar1.Text) + txtFuncVar2.Text = TrimComplete(txtFuncVar2.Text) + cmbNextstate.Text = TrimComplete(cmbNextstate.Text) + cmbTranslucency.Text = TrimComplete(cmbTranslucency.Text) + + If cmbSprite.Text <> "" Then tsTarget.WriteLine "SPRITENUMBER = " & cmbSprite.ListIndex + + flags = Val(txtFrame.Text) + If chkFullbright.Value = 1 Then flags = flags + 32768 + + ' Grrr VB doesn't have bitshifts!! + If cmbTranslucency.Text <> "" Then + flags = flags + cmbTranslucency.ListIndex * 65536 + End If + + If txtFrame.Text <> "" Then tsTarget.WriteLine "SPRITESUBNUMBER = " & flags + If txtTics.Text <> "" Then tsTarget.WriteLine "DURATION = " & Val(txtTics.Text) + If cmbNextstate.Text <> "" Then tsTarget.WriteLine "NEXT = " & cmbNextstate.ListIndex + If cmbAction.Text <> "" Then tsTarget.WriteLine "ACTION " & cmbAction.Text + If txtFuncVar1.Text <> "" Then tsTarget.WriteLine "VAR1 = " & Val(txtFuncVar1.Text) + If txtFuncVar2.Text <> "" Then tsTarget.WriteLine "VAR2 = " & Val(txtFuncVar2.Text) + End If + + tsTarget.Close + Set myFSOTarget = Nothing + + FileCopy SOCTemp, SOCFile + + Kill SOCTemp + + If Remove = True Then + If statefound = True Then + MsgBox "State removed from SOC." + Else + MsgBox "State not found in SOC." + End If + Else + MsgBox "State Saved." + End If +End Sub + +Private Sub LoadThings() + Dim myFSO As New Scripting.FileSystemObject + Dim ts As TextStream + Dim line As String + Dim number As Integer + Dim startclip As Integer, endclip As Integer + Dim numfreeslots As Integer, i As Integer + + ChDir SourcePath + Set ts = myFSO.OpenTextFile("info.h", ForReading, False) + + Do While InStr(ts.ReadLine, "Little flag for SOC editor (don't change this comment!)") = 0 + Loop + + ts.SkipLine ' typedef enum + ts.SkipLine ' { + + line = ts.ReadLine + number = 0 + + lstThings.Clear + + Do While InStr(line, "MT_FIRSTFREESLOT") = 0 + startclip = InStr(line, "MT_") + If InStr(line, "MT_") <> 0 Then + endclip = InStr(line, ",") + line = Mid(line, startclip, endclip - startclip) + lstThings.AddItem number & " - " & line + number = number + 1 + End If + line = ts.ReadLine + Loop + + ts.Close + + 'Populate the free slots! + Set ts = myFSO.OpenTextFile("info.h", ForReading, False) + + line = ts.ReadLine + Do While InStr(line, "#define NUMMOBJFREESLOTS") = 0 + line = ts.ReadLine + Loop + + startclip = InStr(line, "SLOTS ") + 6 + numfreeslots = Val(Mid(line, startclip, Len(line) - startclip + 1)) + + For i = 1 To numfreeslots + lstThings.AddItem number & " - " & "MT_FREESLOT" & i + number = number + 1 + Next + + ts.Close + Set myFSO = Nothing +End Sub + +Private Function FindThingNum(ThingName As String) As Integer + Dim i As Integer + Dim temp As String + Dim startpoint As Integer + Dim endpoint As Integer + + lstThings.Clear + LoadThings + + For i = 0 To lstThings.ListCount - 1 + temp = lstThings.List(i) + startpoint = InStr(temp, "-") + 2 + endpoint = Len(temp) - startpoint + 1 + temp = Mid(temp, startpoint, endpoint) + If temp = ThingName Then + FindThingNum = Val(lstThings.List(i)) + Exit For + End If + Next +End Function + +Private Function FindPowerNum(PowerName As String) As Integer + Dim myFSO As New Scripting.FileSystemObject + Dim ts As TextStream + Dim line As String + Dim number As Integer + Dim startclip As Integer + + ChDir SourcePath + Set ts = myFSO.OpenTextFile("d_player.h", ForReading, False) + + Do While InStr(ts.ReadLine, "Player powers. (don't edit this comment)") = 0 + Loop + + ts.SkipLine ' typedef enum + ts.SkipLine ' { + + line = ts.ReadLine + number = 0 + + Do While InStr(line, "NUMPOWERS") = 0 + startclip = InStr(line, PowerName) + If startclip <> 0 Then + FindPowerNum = number + Exit Do + End If + number = number + 1 + line = ts.ReadLine + Loop + + ts.Close + Set myFSO = Nothing +End Function diff --git a/tools/SOCEdit/frmStateEdit.frx b/tools/SOCEdit/frmStateEdit.frx new file mode 100644 index 000000000..8069c37e0 Binary files /dev/null and b/tools/SOCEdit/frmStateEdit.frx differ diff --git a/tools/SOCEdit/frmUnlockablesEdit.frm b/tools/SOCEdit/frmUnlockablesEdit.frm new file mode 100644 index 000000000..f43209a78 --- /dev/null +++ b/tools/SOCEdit/frmUnlockablesEdit.frm @@ -0,0 +1,391 @@ +VERSION 5.00 +Begin VB.Form frmUnlockablesEdit + Caption = "Unlockables Edit" + ClientHeight = 3675 + ClientLeft = 60 + ClientTop = 345 + ClientWidth = 8130 + Icon = "frmUnlockablesEdit.frx":0000 + LinkTopic = "Form1" + MaxButton = 0 'False + ScaleHeight = 3675 + ScaleWidth = 8130 + StartUpPosition = 3 'Windows Default + Begin VB.CheckBox chkGrade + Caption = "Must have beaten Ultimate" + Height = 255 + Index = 4 + Left = 5400 + TabIndex = 20 + Tag = "1024" + Top = 2160 + Width = 2655 + End + Begin VB.CheckBox chkGrade + Caption = "Must have beaten Very Hard" + Height = 255 + Index = 3 + Left = 5400 + TabIndex = 19 + Tag = "128" + Top = 1800 + Width = 2655 + End + Begin VB.CheckBox chkGrade + Caption = "Must have all emblems" + Height = 255 + Index = 2 + Left = 5400 + TabIndex = 18 + Tag = "16" + Top = 1440 + Width = 2055 + End + Begin VB.CheckBox chkGrade + Caption = "Must have gotten all 7 emeralds" + Height = 255 + Index = 1 + Left = 5400 + TabIndex = 17 + Tag = "8" + Top = 1080 + Width = 2655 + End + Begin VB.CheckBox chkGrade + Caption = "Game must be completed" + Height = 255 + Index = 0 + Left = 5400 + TabIndex = 16 + Tag = "1" + Top = 720 + Width = 2175 + End + Begin VB.TextBox txtVar + Height = 285 + Left = 4320 + TabIndex = 14 + Top = 2640 + Width = 615 + End + Begin VB.ComboBox cmbType + Height = 315 + ItemData = "frmUnlockablesEdit.frx":0442 + Left = 3360 + List = "frmUnlockablesEdit.frx":044C + TabIndex = 12 + Top = 2160 + Width = 1575 + End + Begin VB.TextBox txtNeededTime + Height = 285 + Left = 4080 + TabIndex = 10 + Top = 1680 + Width = 855 + End + Begin VB.TextBox txtNeededEmblems + Height = 285 + Left = 4440 + TabIndex = 9 + Top = 1200 + Width = 495 + End + Begin VB.TextBox txtObjective + Height = 285 + Left = 3240 + TabIndex = 7 + Top = 720 + Width = 1695 + End + Begin VB.TextBox txtName + Height = 285 + Left = 3240 + TabIndex = 5 + Top = 240 + Width = 1695 + End + Begin VB.CommandButton cmdDelete + Caption = "&Delete from SOC" + Height = 375 + Left = 3480 + TabIndex = 3 + Top = 3120 + Width = 1575 + End + Begin VB.CommandButton cmdSave + Caption = "&Save Changes" + Height = 375 + Left = 1800 + TabIndex = 2 + Top = 3120 + Width = 1575 + End + Begin VB.ListBox lstUnlockables + Height = 2985 + ItemData = "frmUnlockablesEdit.frx":046A + Left = 120 + List = "frmUnlockablesEdit.frx":049B + TabIndex = 0 + Top = 480 + Width = 1215 + End + Begin VB.Label lblNote + Caption = "Note: All requirements are combinable." + Height = 495 + Left = 6000 + TabIndex = 22 + Top = 2760 + Width = 1695 + End + Begin VB.Label lblOtherReqs + Caption = "Other Requirements:" + Height = 255 + Left = 5400 + TabIndex = 21 + Top = 360 + Width = 1935 + End + Begin VB.Label lblVar + Alignment = 1 'Right Justify + Caption = "Map # to warp to:" + Height = 255 + Left = 2880 + TabIndex = 15 + Top = 2640 + Width = 1335 + End + Begin VB.Label lblType + Alignment = 1 'Right Justify + Caption = "Type of Unlockable:" + Height = 255 + Left = 1800 + TabIndex = 13 + Top = 2160 + Width = 1455 + End + Begin VB.Label lblNeededTime + Alignment = 1 'Right Justify + Caption = "Needed time on Time Attack rank (in seconds):" + Height = 375 + Left = 1440 + TabIndex = 11 + Top = 1560 + Width = 2535 + End + Begin VB.Label lblNeededEmblems + Alignment = 1 'Right Justify + Caption = "# of Emblems Needed:" + Height = 255 + Left = 2640 + TabIndex = 8 + Top = 1200 + Width = 1695 + End + Begin VB.Label lblObjective + Alignment = 1 'Right Justify + Caption = "Objective:" + Height = 255 + Left = 2400 + TabIndex = 6 + Top = 720 + Width = 735 + End + Begin VB.Label lblName + Alignment = 1 'Right Justify + Caption = "Name:" + Height = 255 + Left = 2640 + TabIndex = 4 + Top = 240 + Width = 495 + End + Begin VB.Label lblHUDItems + Caption = "Unlockables:" + Height = 255 + Left = 120 + TabIndex = 1 + Top = 240 + Width = 975 + End +End +Attribute VB_Name = "frmUnlockablesEdit" +Attribute VB_GlobalNameSpace = False +Attribute VB_Creatable = False +Attribute VB_PredeclaredId = True +Attribute VB_Exposed = False +Option Explicit + +Private Sub cmdDelete_Click() + Call WriteUnlockableItem(True) +End Sub + +Private Sub cmdSave_Click() + Call WriteUnlockableItem(False) +End Sub + +Private Sub Form_Load() + Call Reload +End Sub + +Private Sub Reload() + txtName.Text = "" + txtObjective.Text = "" + txtNeededEmblems.Text = "" + txtNeededTime.Text = "" + cmbType.Text = "" + txtVar.Text = "" + + Dim i As Integer + + For i = 0 To chkGrade.Count - 1 + chkGrade(i).Value = 0 + Next i + + lstUnlockables.ListIndex = 0 +End Sub + +Private Sub lstUnlockables_Click() + Call ReadSOC(lstUnlockables.ListIndex + 1) +End Sub + +Private Sub ReadSOC(UnlockableNum As Integer) + Dim myFSO As New Scripting.FileSystemObject + Dim ts As TextStream + Dim line As String + Dim word As String + Dim word2 As String + + Set ts = myFSO.OpenTextFile(SOCFile, ForReading, False) + +SOCLoad: + Do While Not ts.AtEndOfStream + line = ts.ReadLine + + If Left(line, 1) = "#" Then GoTo SOCLoad + + If Left(line, 1) = vbCrLf Then GoTo SOCLoad + + If Len(line) < 1 Then GoTo SOCLoad + + word = FirstToken(line) + word2 = SecondToken(line) + + If UCase(word) = "UNLOCKABLE" And Val(word2) = UnlockableNum Then + Do While Len(line) > 0 And Not ts.AtEndOfStream + line = ts.ReadLine + word = UCase(FirstToken(line)) + word2 = UCase(SecondTokenEqual(line)) + + If word = "NAME" Then + txtName.Text = word2 + ElseIf word = "OBJECTIVE" Then + txtObjective.Text = word2 + ElseIf word = "NEEDEDEMBLEMS" Then + txtNeededEmblems.Text = Val(word2) + ElseIf word = "NEEDEDTIME" Then + txtNeededTime.Text = Val(word2) + ElseIf word = "TYPE" Then + cmbType.ListIndex = Val(word2) + ElseIf word = "VAR" Then + txtVar.Text = Val(word2) + ElseIf word = "NEEDEDGRADE" Then + Dim i As Integer + + For i = 0 To chkGrade.Count - 1 + If Val(word2) And chkGrade(i).Tag Then + chkGrade(i).Tag = True + End If + Next i + ElseIf Len(line) > 0 And Left(line, 1) <> "#" Then + MsgBox "Error in SOC!" & vbCrLf & "Unknown line: " & line + End If + Loop + Exit Do + End If + Loop + + ts.Close + Set myFSO = Nothing +End Sub + +Private Sub WriteUnlockableItem(Remove As Boolean) + Dim myFSOSource As New Scripting.FileSystemObject + Dim tsSource As TextStream + Dim myFSOTarget As New Scripting.FileSystemObject + Dim tsTarget As TextStream + Dim line As String + Dim word As String + Dim word2 As String + Dim unlockableremoved As Boolean + + unlockableremoved = False + + Set tsSource = myFSOSource.OpenTextFile(SOCFile, ForReading, False) + Set tsTarget = myFSOTarget.OpenTextFile(SOCTemp, ForWriting, True) + + Do While Not tsSource.AtEndOfStream + line = tsSource.ReadLine + word = UCase(FirstToken(line)) + word2 = UCase(SecondToken(line)) + + 'If the current item exists in the SOC, delete it. + If word = "UNLOCKABLE" And Val(word2) = lstUnlockables.ListIndex + 1 Then + unlockableremoved = True + Do While Len(TrimComplete(tsSource.ReadLine)) > 0 And Not tsSource.AtEndOfStream + Loop + Else + tsTarget.WriteLine line + End If + Loop + + tsSource.Close + Set myFSOSource = Nothing + + If Remove = False Then + If line <> "" Then tsTarget.WriteLine "" + + tsTarget.WriteLine "UNLOCKABLE " & lstUnlockables.ListIndex + 1 + txtName.Text = TrimComplete(txtName.Text) + txtObjective.Text = TrimComplete(txtObjective.Text) + txtNeededEmblems.Text = TrimComplete(txtNeededEmblems.Text) + txtNeededTime.Text = TrimComplete(txtNeededTime.Text) + txtVar.Text = TrimComplete(txtVar.Text) + + If txtName.Text <> "" Then tsTarget.WriteLine "NAME = " & txtName.Text + If txtObjective.Text <> "" Then tsTarget.WriteLine "OBJECTIVE = " & txtObjective.Text + If txtNeededEmblems.Text <> "" Then tsTarget.WriteLine "NEEDEDEMBLEMS = " & txtNeededEmblems.Text + If txtNeededTime.Text <> "" Then tsTarget.WriteLine "NEEDEDTIME = " & txtNeededTime.Text + If cmbType.ListIndex <> -1 Then tsTarget.WriteLine "TYPE = " & cmbType.ListIndex + If txtVar.Text <> "" Then tsTarget.WriteLine "VAR = " & txtVar.Text + + Dim writegrade As Long + Dim i As Integer + writegrade = 0 + + For i = 0 To chkGrade.Count - 1 + If chkGrade(i).Value = 1 Then + writegrade = writegrade + chkGrade(i).Tag + End If + Next i + + If writegrade > 0 Then tsTarget.WriteLine "NEEDEDGRADE = " & writegrade + End If + + tsTarget.Close + Set myFSOTarget = Nothing + + FileCopy SOCTemp, SOCFile + + Kill SOCTemp + + If Remove = True Then + If unlockableremoved = True Then + MsgBox "Unlockable deleted from SOC." + Else + MsgBox "Couldn't find Unlockable in SOC." + End If + Else + MsgBox "Unlockable Saved." + End If +End Sub diff --git a/tools/SOCEdit/frmUnlockablesEdit.frx b/tools/SOCEdit/frmUnlockablesEdit.frx new file mode 100644 index 000000000..d9d464d4e Binary files /dev/null and b/tools/SOCEdit/frmUnlockablesEdit.frx differ diff --git a/tools/SOCEdit/icon1.ico b/tools/SOCEdit/icon1.ico new file mode 100644 index 000000000..1ea9d1005 Binary files /dev/null and b/tools/SOCEdit/icon1.ico differ diff --git a/tools/SRB2Launcher/ReadMe.txt b/tools/SRB2Launcher/ReadMe.txt new file mode 100644 index 000000000..9aafe08b8 --- /dev/null +++ b/tools/SRB2Launcher/ReadMe.txt @@ -0,0 +1,35 @@ +======================================================================== + WIN32 APPLICATION : SRB2Launcher +======================================================================== + + +AppWizard has created this SRB2Launcher application for you. + +This file contains a summary of what you will find in each of the files that +make up your SRB2Launcher application. + +SRB2Launcher.cpp + This is the main application source file. + +SRB2Launcher.dsp + This file (the project file) contains information at the project level and + is used to build a single project or subproject. Other users can share the + project (.dsp) file, but they should export the makefiles locally. + + +///////////////////////////////////////////////////////////////////////////// +Other standard files: + +StdAfx.h, StdAfx.cpp + These files are used to build a precompiled header (PCH) file + named SRB2Launcher.pch and a precompiled types file named StdAfx.obj. + + +///////////////////////////////////////////////////////////////////////////// +Other notes: + +AppWizard uses "TODO:" to indicate parts of the source code you +should add to or customize. + + +///////////////////////////////////////////////////////////////////////////// diff --git a/tools/SRB2Launcher/SRB2Launcher.cpp b/tools/SRB2Launcher/SRB2Launcher.cpp new file mode 100644 index 000000000..4138676d3 --- /dev/null +++ b/tools/SRB2Launcher/SRB2Launcher.cpp @@ -0,0 +1,1155 @@ +///////////////////////////// +// // +// Sonic Robo Blast 2 // +// Official Win32 Launcher // +// // +// By // +// SSNTails // +// ah518@tcnet.org // +// (Sonic Team Junior) // +// http://www.srb2.org // +// // +///////////////////////////// +// +// This source code is released under +// Public Domain. I hope it helps you +// learn how to write exciting Win32 +// applications in C! +// +// However, you may not alter this +// program and continue to call it +// the "Official Sonic Robo Blast 2 +// Launcher". +// +// NOTE: Not all files in this project +// are released under this license. +// Any license mentioned in accompanying +// source files overrides the license +// mentioned here, sorry! +// +// SRB2Launcher.cpp : Defines the entry point for the application. +// + +#include "stdafx.h" +#include +#include +#include "SRB2Launcher.h" + +char TempString[256]; + +char Arguments[16384]; + +HWND mainHWND; +HWND hostHWND; +HWND joinHWND; +HINSTANCE g_hInst; + +HANDLE ServerlistThread = 0; + +typedef struct +{ + char nospecialrings; + char suddendeath; + char scoringtype[16]; + char matchboxes[16]; + int respawnitemtime; + int timelimit; + int pointlimit; +} matchsettings_t; + +typedef struct +{ + char raceitemboxes[16]; + int numlaps; +} racesettings_t; + +typedef struct +{ + char nospecialrings; + char matchboxes[16]; + int respawnitemtime; + int timelimit; + int pointlimit; +} tagsettings_t; + +typedef struct +{ + char nospecialrings; + char matchboxes[16]; + int respawnitemtime; + int timelimit; + int flagtime; + int pointlimit; +} ctfsettings_t; + +typedef struct +{ + char nofile; + char nodownload; +} joinsettings_t; + +typedef struct +{ + matchsettings_t match; + racesettings_t race; + tagsettings_t tag; + ctfsettings_t ctf; + char gametype[16]; + char startmap[9]; + int maxplayers; + char advancestage[16]; + int inttime; + char forceskin; + char noautoaim; + char nosend; + char noadvertise; + + // Monitor Toggles... + char teleporters[8]; + char superring[8]; + char silverring[8]; + char supersneakers[8]; + char invincibility[8]; + char jumpshield[8]; + char watershield[8]; + char ringshield[8]; + char fireshield[8]; + char bombshield[8]; + char oneup[8]; + char eggmanbox[8]; +} hostsettings_t; + +typedef struct +{ + hostsettings_t host; + joinsettings_t join; + char EXEName[1024]; + char ConfigFile[1024]; + char ManualParameters[8192]; + char PlayerName[24]; + char PlayerColor[16]; + char PlayerSkin[24]; +} settings_t; + +// Whole structure is just dumped to a binary file when settings are saved. +settings_t launchersettings; + +#define APPTITLE "Official Sonic Robo Blast 2 Launcher" +#define APPVERSION "v0.1" +#define APPAUTHOR "SSNTails" +#define APPCOMPANY "Sonic Team Junior" + +LRESULT CALLBACK MainProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); + +// +// RunSRB2 +// +// Runs SRB2 +// returns true if successful +// +BOOL RunSRB2(void) +{ + SHELLEXECUTEINFO lpExecInfo; + BOOL result; + char EXEName[1024]; + + memset(&lpExecInfo, 0, sizeof(SHELLEXECUTEINFO)); + + lpExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); + + SendMessage(GetDlgItem(mainHWND, IDC_EXENAME), WM_GETTEXT, sizeof(EXEName), (LPARAM)(LPCSTR)EXEName); + lpExecInfo.lpFile = EXEName; + lpExecInfo.lpParameters = Arguments; + lpExecInfo.nShow = SW_SHOWNORMAL; + lpExecInfo.hwnd = mainHWND; + lpExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS; + lpExecInfo.lpVerb = "open"; + + result = ShellExecuteEx(&lpExecInfo); + + if(!result) + { + MessageBox(mainHWND, "Error starting the game!", "Error", MB_OK|MB_APPLMODAL|MB_ICONERROR); + return false; + } + + return true; +} + +// +// ChooseEXEName +// +// Provides a common dialog box +// for selecting the desired executable. +// +void ChooseEXEName(void) +{ + OPENFILENAME ofn; + char FileBuffer[256]; + + ZeroMemory(&ofn, sizeof(ofn)); + ofn.hwndOwner = NULL; + FileBuffer[0] = '\0'; + ofn.lpstrFilter = "Executable Files\0*.exe\0All Files\0*.*\0\0"; + ofn.lpstrInitialDir = NULL; + ofn.lpstrFile = FileBuffer; + ofn.lStructSize = sizeof(ofn); + ofn.nMaxFile = sizeof(FileBuffer); + ofn.nFilterIndex = 1; + ofn.lpstrFileTitle = NULL; + ofn.nMaxFileTitle = 0; + ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; + + if(GetOpenFileName(&ofn)) + { + SendMessage(GetDlgItem(mainHWND, IDC_EXENAME), WM_SETTEXT, 0, (LPARAM)(LPCSTR)FileBuffer); + strcpy(launchersettings.EXEName, FileBuffer); + } +} + +// +// ChooseConfigName +// +// Provides a common dialog box +// for selecting the desired cfg file. +// +void ChooseConfigName(void) +{ + OPENFILENAME ofn; + char FileBuffer[256]; + + ZeroMemory(&ofn, sizeof(ofn)); + ofn.hwndOwner = NULL; + FileBuffer[0] = '\0'; + ofn.lpstrFilter = "Config Files\0*.cfg\0All Files\0*.*\0\0"; + ofn.lpstrInitialDir = NULL; + ofn.lpstrFile = FileBuffer; + ofn.lStructSize = sizeof(ofn); + ofn.nMaxFile = sizeof(FileBuffer); + ofn.nFilterIndex = 1; + ofn.lpstrFileTitle = NULL; + ofn.nMaxFileTitle = 0; + ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; + + if(GetOpenFileName(&ofn)) + { + SendMessage(GetDlgItem(mainHWND, IDC_CONFIGFILE), WM_SETTEXT, 0, (LPARAM)(LPCSTR)FileBuffer); + strcpy(launchersettings.ConfigFile, FileBuffer); + } +} + +// +// Add External File +// +// Provides a common dialog box +// for adding an external file. +// +void AddExternalFile(void) +{ + OPENFILENAME ofn; + char FileBuffer[256]; + + ZeroMemory(&ofn, sizeof(ofn)); + ofn.hwndOwner = NULL; + FileBuffer[0] = '\0'; + ofn.lpstrFilter = "WAD/SOC Files\0*.soc;*.wad\0All Files\0*.*\0\0"; + ofn.lpstrInitialDir = NULL; + ofn.lpstrFile = FileBuffer; + ofn.lStructSize = sizeof(ofn); + ofn.nMaxFile = sizeof(FileBuffer); + ofn.nFilterIndex = 1; + ofn.lpstrFileTitle = NULL; + ofn.nMaxFileTitle = 0; + ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; + + if(GetOpenFileName(&ofn) && SendMessage(GetDlgItem(mainHWND, IDC_EXTFILECOMBO), CB_FINDSTRING, -1, (LPARAM)(LPCSTR)FileBuffer) == CB_ERR) + SendMessage(GetDlgItem(mainHWND, IDC_EXTFILECOMBO), CB_ADDSTRING, 0, (LPARAM)(LPCSTR)FileBuffer); +} + +// +// CompileArguments +// +// Go through ALL of the settings +// and put them into a parameter +// string. Yikes! +// +void CompileArguments(void) +{ + HWND temp; + int numitems; + int i; + + // Clear out the arguments, if any existed. + memset(Arguments, 0, sizeof(Arguments)); + + + // WAD/SOC Files Added + temp = GetDlgItem(mainHWND, IDC_EXTFILECOMBO); + + if ((numitems = SendMessage(temp, CB_GETCOUNT, 0, 0)) > 0) + { + char tempbuffer[1024]; + + strcpy(Arguments, "-file "); + + for (i = 0; i < numitems; i++) + { + SendMessage(temp, CB_GETLBTEXT, i, (LPARAM)(LPCSTR)tempbuffer); + strcat(Arguments, tempbuffer); + strcat(Arguments, " "); + } + } + + // Manual Parameters + temp = GetDlgItem(mainHWND, IDC_PARAMETERS); + + if (SendMessage(temp, WM_GETTEXTLENGTH, 0, 0) > 0) + { + char tempbuffer[8192]; + + SendMessage(temp, WM_GETTEXT, 8192, (LPARAM)(LPCSTR)tempbuffer); + + strcat(Arguments, tempbuffer); + } +} + +// +// GetConfigVariable +// +// Pulls a value out of the chosen +// config.cfg and places it into the +// string supplied in 'dest' +// +BOOL GetConfigVariable(char* varname, char* dest) +{ + FILE* f; + int size = 0; + char* buffer; + char* posWeWant; + char* stringstart; + char varnamecpy[256]; + + varnamecpy[0] = '\n'; + + strncpy(varnamecpy+1, varname, 255); + + if(!(f = fopen(launchersettings.ConfigFile, "rb"))) + return false; // Oops! + + // Get file size + while(!feof(f)) + { + size++; + fgetc(f); + } + + fseek(f, 0, SEEK_SET); + + buffer = (char*)malloc(size); + + fread(buffer, size, 1, f); + fclose(f); + + posWeWant = strstr(buffer, varname); + + if(posWeWant == NULL) + { + free(buffer); + return false; + } + + posWeWant++; + + // We are now at the line we want. + // Get the variable from it + + while(*posWeWant != '\"') posWeWant++; + + posWeWant++; + + stringstart = posWeWant; + + while(*posWeWant != '\"') posWeWant++; + + *posWeWant = '\0'; + + strcpy(dest, stringstart); + + free(buffer); + + // Phew! + return true; +} + +SOCKET ConnectSocket(char* IPAddress, int portnumber) +{ + DWORD dwDestAddr; + SOCKADDR_IN sockAddrDest; + SOCKET sockDest; + + // Create socket + sockDest = socket(AF_INET, SOCK_STREAM, 0); + + if(sockDest == SOCKET_ERROR) + { +// printf("Could not create socket: %d\n", WSAGetLastError()); + return INVALID_SOCKET; + } + + // Convert address to in_addr (binary) format + dwDestAddr = inet_addr(IPAddress); + + if(dwDestAddr == INADDR_NONE) + { + // It's not a xxx.xxx.xxx.xxx IP, so resolve through DNS + struct hostent* pHE = gethostbyname(IPAddress); + if(pHE == 0) + { +// printf("Unable to resolve address.\n"); + return INVALID_SOCKET; + } + + dwDestAddr = *((u_long*)pHE->h_addr_list[0]); + } + + // Initialize SOCKADDR_IN with IP address, port number and address family + memcpy(&sockAddrDest.sin_addr, &dwDestAddr, sizeof(DWORD)); + + sockAddrDest.sin_port = htons(portnumber); + sockAddrDest.sin_family = AF_INET; + + // Attempt to connect to server + if(connect(sockDest, (LPSOCKADDR)&sockAddrDest, sizeof(sockAddrDest)) == SOCKET_ERROR) + { +// printf("Could not connect to server socket: %d\n", WSAGetLastError()); + closesocket(sockDest); + return INVALID_SOCKET; + } + + return sockDest; +} + +// +// MS_Write(): +// +static int MS_Write(msg_t *msg, SOCKET socket) +{ +#ifdef NONET + msg = NULL; + return MS_WRITE_ERROR; +#else + int len; + + if (msg->length < 0) + msg->length = (long)strlen(msg->buffer); + len = msg->length + HEADER_SIZE; + + msg->type = htonl(msg->type); + msg->length = htonl(msg->length); + + if (send(socket, (char *)msg, len, 0) != len) + return MS_WRITE_ERROR; + return 0; +#endif +} + +// +// MS_Read(): +// +static int MS_Read(msg_t *msg, SOCKET socket) +{ +#ifdef NONET + msg = NULL; + return MS_READ_ERROR; +#else + if (recv(socket, (char *)msg, HEADER_SIZE, 0) != HEADER_SIZE) + return MS_READ_ERROR; + + msg->type = ntohl(msg->type); + msg->length = ntohl(msg->length); + + if (!msg->length) // fix a bug in Windows 2000 + return 0; + + if (recv(socket, (char *)msg->buffer, msg->length, 0) != msg->length) + return MS_READ_ERROR; + return 0; +#endif +} + +/** Gets a list of game servers from the master server. + */ +static inline int GetServersList(SOCKET socket) +{ + msg_t msg; + int count = 0; + + msg.type = GET_SERVER_MSG; + msg.length = 0; + if (MS_Write(&msg, socket) < 0) + return MS_WRITE_ERROR; + + while (MS_Read(&msg, socket) >= 0) + { + if (!msg.length) + { +// if (!count) +// printf("No server currently running.\n"); + return MS_NO_ERROR; + } + count++; + printf(msg.buffer); + } + + return MS_READ_ERROR; +} + +// +// RunSocketStuff +// +// Thread that checks the masterserver for new games. +void RunSocketStuff(HWND hListView) +{ + WSADATA wsaData; + SOCKET sock; + int i = 0; + char ServerAddressAndPort[256]; + char Address[256]; + char Port[8]; + + if(!GetConfigVariable("masterserver", ServerAddressAndPort)) // srb2.servegame.org:28900 + { + ServerlistThread = NULL; + return; + } + + strcpy(Address, ServerAddressAndPort); + + for(i = 0; i < (signed)strlen(Address); i++) + { + if(Address[i] == ':') + { + Address[i] = '\0'; + break; + } + } + + for(i = 0; i < (signed)strlen(ServerAddressAndPort); i++) + { + if(ServerAddressAndPort[i] == ':') + { + strcpy(Port, &ServerAddressAndPort[i+1]); + break; + } + } + + // Address now contains the hostname or IP + // Port now contains the port number + + + // Initialize WinSock + if(WSAStartup(MAKEWORD(1, 1), &wsaData) != 0) + { +// printf("Could not initialize sockets.\n"); + ServerlistThread = NULL; + return; + } + + // Create socket and connect to server + sock = ConnectSocket(/*IPAddress*/0, /*PortNumber*/0); + if(sock == INVALID_SOCKET) + { +// printf("Socket Error: %d\n", WSAGetLastError()); + ServerlistThread = NULL; + return; + } + + // We're connected! + // Now get information from server + + + // Add games to listview box. + ListView_DeleteAllItems(hListView); + +/* + while (MoreServersStillExist) + { + GetTheNextServerInformation(); + AddItemToList(hListView, servername, ping, players, gametype, level); + } +*/ + + // close socket + closesocket(sock); + + // Clean up WinSock + if(WSACleanup() == SOCKET_ERROR) + { +// printf("Could not cleanup sockets: %d\n", WSAGetLastError()); + ServerlistThread = NULL; + return; + } + + printf("Winsock thread terminated successfully.\n"); + ServerlistThread = NULL; + + return; +} + +BOOL GetGameList(HWND hListView) +{ + DWORD dwThreadID; + ServerlistThread = CreateThread( NULL, // default security + 0, // default stack + (LPTHREAD_START_ROUTINE)(void*)RunSocketStuff, // thread function + hListView, // arguments + 0, // default flags + &dwThreadID); // don't need this, but it makes it happy (and compatible with old Win32 OSes) + + if(ServerlistThread == NULL) + return false; + + return true; +} + +void RegisterDialogClass(char* name, WNDPROC callback) +{ + WNDCLASS wnd; + + wnd.style = CS_HREDRAW | CS_VREDRAW; + wnd.cbWndExtra = DLGWINDOWEXTRA; + wnd.cbClsExtra = 0; + wnd.hCursor = LoadCursor(NULL,MAKEINTRESOURCE(IDC_ARROW)); + wnd.hIcon = LoadIcon(NULL,MAKEINTRESOURCE(IDI_ICON1)); + wnd.hInstance = g_hInst; + wnd.lpfnWndProc = callback; + wnd.lpszClassName = name; + wnd.lpszMenuName = NULL; + wnd.hbrBackground = (HBRUSH)(COLOR_WINDOW); + + if(!RegisterClass(&wnd)) + { + return; + } +} + +int APIENTRY WinMain(HINSTANCE hInstance, + HINSTANCE hPrevInstance, + LPSTR lpCmdLine, + int nCmdShow) +{ + // Prevent multiples instances of this app. + CreateMutex(NULL, true, APPTITLE); + + if(GetLastError() == ERROR_ALREADY_EXISTS) + return 0; + + g_hInst = hInstance; + + RegisterDialogClass("SRB2Launcher", MainProc); + + DialogBox(g_hInst, (LPCSTR)IDD_MAIN, NULL, (DLGPROC)MainProc); + + return 0; +} + +// +// InitHostOptionsComboBoxes +// +// Does what it says. +// +void InitHostOptionsComboBoxes(HWND hwnd) +{ + HWND ctrl; + + ctrl = GetDlgItem(hwnd, IDC_MATCHBOXES); + + if(ctrl) + { + SendMessage(ctrl, CB_ADDSTRING, 0, (LPARAM)(LPCSTR)"Normal (Default)"); + SendMessage(ctrl, CB_ADDSTRING, 0, (LPARAM)(LPCSTR)"Random"); + SendMessage(ctrl, CB_ADDSTRING, 0, (LPARAM)(LPCSTR)"Non-Random"); + SendMessage(ctrl, CB_ADDSTRING, 0, (LPARAM)(LPCSTR)"None"); + } + + ctrl = GetDlgItem(hwnd, IDC_RACEITEMBOXES); + + if(ctrl) + { + SendMessage(ctrl, CB_ADDSTRING, 0, (LPARAM)(LPCSTR)"Normal (Default)"); + SendMessage(ctrl, CB_ADDSTRING, 0, (LPARAM)(LPCSTR)"Random"); + SendMessage(ctrl, CB_ADDSTRING, 0, (LPARAM)(LPCSTR)"Teleports"); + SendMessage(ctrl, CB_ADDSTRING, 0, (LPARAM)(LPCSTR)"None"); + } + + ctrl = GetDlgItem(hwnd, IDC_MATCH_SCORING); + + if(ctrl) + { + SendMessage(ctrl, CB_ADDSTRING, 0, (LPARAM)(LPCSTR)"Normal (Default)"); + SendMessage(ctrl, CB_ADDSTRING, 0, (LPARAM)(LPCSTR)"Classic"); + } +} + +LRESULT CALLBACK MatchOptionsDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + switch(message) + { + case WM_INITDIALOG: + InitHostOptionsComboBoxes(hwnd); + break; + + case WM_DESTROY: + EndDialog(hwnd, LOWORD(wParam)); + break; + + case WM_COMMAND: + { + switch(LOWORD(wParam)) + { + case 2: + PostMessage(hwnd, WM_DESTROY, 0, 0); + break; + default: + break; + } + + break; + } + } + + return 0; +} + +LRESULT CALLBACK RaceOptionsDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + switch(message) + { + case WM_INITDIALOG: + InitHostOptionsComboBoxes(hwnd); + break; + + case WM_DESTROY: + EndDialog(hwnd, LOWORD(wParam)); + break; + + case WM_COMMAND: + { + switch(LOWORD(wParam)) + { + case 2: + PostMessage(hwnd, WM_DESTROY, 0, 0); + break; + default: + break; + } + + break; + } + } + + return 0; +} + +LRESULT CALLBACK TagOptionsDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + switch(message) + { + case WM_INITDIALOG: + InitHostOptionsComboBoxes(hwnd); + break; + + case WM_DESTROY: + EndDialog(hwnd, LOWORD(wParam)); + break; + + case WM_COMMAND: + { + switch(LOWORD(wParam)) + { + case 2: + PostMessage(hwnd, WM_DESTROY, 0, 0); + break; + default: + break; + } + + break; + } + } + + return 0; +} + +LRESULT CALLBACK CTFOptionsDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + switch(message) + { + case WM_INITDIALOG: + InitHostOptionsComboBoxes(hwnd); + break; + + case WM_DESTROY: + EndDialog(hwnd, LOWORD(wParam)); + break; + + case WM_COMMAND: + { + switch(LOWORD(wParam)) + { + case 2: + PostMessage(hwnd, WM_DESTROY, 0, 0); + break; + default: + break; + } + + break; + } + } + + return 0; +} + +LRESULT CALLBACK HostProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + HWND temp; + + switch(message) + { + case WM_INITDIALOG: + hostHWND = hwnd; + + temp = GetDlgItem(hwnd, IDC_ADVANCEMAP); + SendMessage(temp, CB_ADDSTRING, 0, (LPARAM)(LPCSTR)"Off"); + SendMessage(temp, CB_ADDSTRING, 0, (LPARAM)(LPCSTR)"Next (Default)"); + SendMessage(temp, CB_ADDSTRING, 0, (LPARAM)(LPCSTR)"Random"); + + temp = GetDlgItem(hwnd, IDC_GAMETYPE); + SendMessage(temp, CB_ADDSTRING, 0, (LPARAM)(LPCSTR)"Coop"); + SendMessage(temp, CB_ADDSTRING, 0, (LPARAM)(LPCSTR)"Match"); + SendMessage(temp, CB_ADDSTRING, 0, (LPARAM)(LPCSTR)"Team Match"); + SendMessage(temp, CB_ADDSTRING, 0, (LPARAM)(LPCSTR)"Race"); + SendMessage(temp, CB_ADDSTRING, 0, (LPARAM)(LPCSTR)"Time-Only Race"); + SendMessage(temp, CB_ADDSTRING, 0, (LPARAM)(LPCSTR)"Tag"); + SendMessage(temp, CB_ADDSTRING, 0, (LPARAM)(LPCSTR)"CTF"); + + break; + + case WM_CREATE: + { + + break; + } + + case WM_DESTROY: + { + hostHWND = NULL; + EndDialog(hwnd, LOWORD(wParam)); + break; + } + + case WM_COMMAND: + { + switch(LOWORD(wParam)) + { + case 2: + PostMessage(hwnd, WM_DESTROY, 0, 0); + break; + case IDC_OPTIONS: + { + int gametype; + int dialognum; + DLGPROC callbackfunc; + + // Grab the current gametype from the IDC_GAMETYPE + // combo box and then display the appropriate + // options dialog. + temp = GetDlgItem(hostHWND, IDC_GAMETYPE); + switch(SendMessage(temp, CB_GETCURSEL, 0, 0)) + { + case 0: + gametype = 0; + break; + case 1: + gametype = 1; + break; + case 2: + gametype = 1; + break; + case 3: + gametype = 2; + break; + case 4: + gametype = 2; + break; + case 5: + gametype = 3; + break; + case 6: + gametype = 4; + break; + } + + switch(gametype) + { + case 1: + dialognum = IDD_MATCHOPTIONS; + callbackfunc = (DLGPROC)MatchOptionsDlgProc; + break; + case 2: + dialognum = IDD_RACEOPTIONS; + callbackfunc = (DLGPROC)RaceOptionsDlgProc; + break; + case 3: + dialognum = IDD_TAGOPTIONS; + callbackfunc = (DLGPROC)TagOptionsDlgProc; + break; + case 4: + dialognum = IDD_CTFOPTIONS; + callbackfunc = (DLGPROC)CTFOptionsDlgProc; + break; + case 0: + default: // ??? + dialognum = 0; + callbackfunc = NULL; + MessageBox(hostHWND, "This gametype does not have any additional options.", "Not Available", MB_OK|MB_APPLMODAL); + break; + } + + if(dialognum) + DialogBox(g_hInst, (LPCSTR)dialognum, hostHWND, callbackfunc); + } + break; + default: + break; + } + + break; + } + + case WM_PAINT: + { + break; + } + } + + return 0; +} + +// +// AddItemToList +// +// Adds a game to the list view. +// +void AddItemToList(HWND hListView, char* servername, + char* ping, char* players, + char* gametype, char* level) +{ + LVITEM lvTest; + + lvTest.mask = LVIF_TEXT | LVIF_STATE; + + lvTest.pszText = servername; + lvTest.iIndent = 0; + lvTest.stateMask = 0; + lvTest.state = 0; + + lvTest.iSubItem = 0; + lvTest.iItem = ListView_InsertItem(hListView, &lvTest); + + ListView_SetItemText(hListView,lvTest.iItem,1,ping); + + ListView_SetItemText(hListView,lvTest.iItem,2,players); + + ListView_SetItemText(hListView,lvTest.iItem,3,gametype); + + ListView_SetItemText(hListView,lvTest.iItem,4,level); +} + +// +// InitJoinGameColumns +// +// Initializes the column headers on the listview control +// on the Join Game page. +// +void InitJoinGameColumns(HWND hDlg) +{ + HWND hItemList; + LVCOLUMN columns[10]; + int i = 0; + + //Create the columns in the list control + hItemList = GetDlgItem(hDlg, IDC_GAMELIST); + + columns[i].mask = LVCF_TEXT | LVCF_WIDTH; + columns[i].pszText = "Server Name"; + columns[i].cchTextMax = 256; + columns[i].cx = 120; + columns[i].fmt = LVCFMT_LEFT; + ListView_InsertColumn(hItemList, i, &columns[i]); + + i++; + + columns[i].mask = LVCF_TEXT | LVCF_WIDTH; + columns[i].pszText = "Ping"; + columns[i].cchTextMax = 256; + columns[i].cx = 80; + columns[i].fmt = LVCFMT_LEFT; + ListView_InsertColumn(hItemList, i, &columns[i]); + + i++; + + columns[i].mask = LVCF_TEXT | LVCF_WIDTH; + columns[i].pszText = "Players"; + columns[i].cchTextMax = 256; + columns[i].cx = 80; + columns[i].fmt = LVCFMT_LEFT; + ListView_InsertColumn(hItemList, i, &columns[i]); + + i++; + + columns[i].mask = LVCF_TEXT | LVCF_WIDTH; + columns[i].pszText = "Game Type"; + columns[i].cchTextMax = 256; + columns[i].cx = 80; + columns[i].fmt = LVCFMT_LEFT; + ListView_InsertColumn(hItemList, i, &columns[i]); + + i++; + + columns[i].mask = LVCF_TEXT | LVCF_WIDTH; + columns[i].pszText = "Level"; + columns[i].cchTextMax = 256; + columns[i].cx = 120; + columns[i].fmt = LVCFMT_LEFT; + ListView_InsertColumn(hItemList, i, &columns[i]); +} + +LRESULT CALLBACK JoinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + switch(message) + { + case WM_INITDIALOG: + joinHWND = hwnd; + InitJoinGameColumns(hwnd); + // Start server listing thread + // and grab game list. + GetGameList(GetDlgItem(hwnd, IDC_GAMELIST)); + break; + + case WM_DESTROY: + joinHWND = NULL; + // Terminate server listing thread. + EndDialog(hwnd, LOWORD(wParam)); + break; + + case WM_COMMAND: + { + switch(LOWORD(wParam)) + { + case 2: + PostMessage(hwnd, WM_DESTROY, 0, 0); + break; + case IDC_SEARCHGAMES: + if(ServerlistThread == NULL) + GetGameList(GetDlgItem(hwnd, IDC_GAMELIST)); + break; + default: + break; + } + + break; + } + + case WM_PAINT: + { + break; + } + } + + return 0; +} + +void InitializeDefaults(void) +{ + memset(&launchersettings, 0, sizeof(launchersettings)); + strcpy(launchersettings.EXEName, "srb2win.exe"); + strcpy(launchersettings.ConfigFile, "config.cfg"); +} + +LRESULT CALLBACK MainProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + HWND temp; + + switch(message) + { + case WM_INITDIALOG: + mainHWND = hwnd; + InitializeDefaults(); + SendMessage(GetDlgItem(hwnd, IDC_EXENAME), WM_SETTEXT, 0, (LPARAM)(LPCSTR)launchersettings.EXEName); + SendMessage(GetDlgItem(hwnd, IDC_CONFIGFILE), WM_SETTEXT, 0, (LPARAM)(LPCSTR)launchersettings.ConfigFile); + break; + + case WM_CREATE: + { + + break; + } + + case WM_DESTROY: + { + PostQuitMessage(0); + break; + } + + case WM_COMMAND: + { + switch(LOWORD(wParam)) + { + case 2: + PostMessage(hwnd, WM_DESTROY, 0, 0); + break; + case IDC_ABOUT: // The About button. + sprintf(TempString, "%s %s by %s - %s", APPTITLE, APPVERSION, APPAUTHOR, APPCOMPANY); + MessageBox(mainHWND, TempString, "About", MB_OK|MB_APPLMODAL); + break; + case IDC_FINDEXENAME: + ChooseEXEName(); + break; + case IDC_FINDCONFIGNAME: + ChooseConfigName(); + break; + case IDC_ADDFILE: + AddExternalFile(); + break; + case IDC_REMOVEFILE: + temp = GetDlgItem(mainHWND, IDC_EXTFILECOMBO); + SendMessage(temp, CB_DELETESTRING, SendMessage(temp, CB_GETCURSEL, 0, 0), 0); + break; + case IDC_HOSTGAME: + DialogBox(g_hInst, (LPCSTR)IDD_HOSTGAME, mainHWND, (DLGPROC)HostProc); + break; + case IDC_JOINGAME: + DialogBox(g_hInst, (LPCSTR)IDD_JOINGAME, mainHWND, (DLGPROC)JoinProc); + break; + case IDC_GO: + CompileArguments(); + RunSRB2(); + break; + default: + break; + } + + break; + } + + case WM_PAINT: + { + break; + } + } + + return 0; +} + diff --git a/tools/SRB2Launcher/SRB2Launcher.dsp b/tools/SRB2Launcher/SRB2Launcher.dsp new file mode 100644 index 000000000..386dc301c --- /dev/null +++ b/tools/SRB2Launcher/SRB2Launcher.dsp @@ -0,0 +1,144 @@ +# Microsoft Developer Studio Project File - Name="SRB2Launcher" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Application" 0x0101 + +CFG=SRB2Launcher - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "SRB2Launcher.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "SRB2Launcher.mak" CFG="SRB2Launcher - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "SRB2Launcher - Win32 Release" (based on "Win32 (x86) Application") +!MESSAGE "SRB2Launcher - Win32 Debug" (based on "Win32 (x86) Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "SRB2Launcher - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /Yu"stdafx.h" /FD /c +# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /Yu"stdafx.h" /FD /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib /nologo /subsystem:windows /machine:I386 + +!ELSEIF "$(CFG)" == "SRB2Launcher - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /Yu"stdafx.h" /FD /GZ /c +# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /Yu"stdafx.h" /FD /GZ /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept + +!ENDIF + +# Begin Target + +# Name "SRB2Launcher - Win32 Release" +# Name "SRB2Launcher - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\SRB2Launcher.cpp +# End Source File +# Begin Source File + +SOURCE=.\StdAfx.cpp +# ADD CPP /Yc"stdafx.h" +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# Begin Source File + +SOURCE=.\lilsocklib.h +# End Source File +# Begin Source File + +SOURCE=.\resource.h +# End Source File +# Begin Source File + +SOURCE=.\SRB2Launcher.h +# End Source File +# Begin Source File + +SOURCE=.\StdAfx.h +# End Source File +# End Group +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# Begin Source File + +SOURCE=.\bitmap1.bmp +# End Source File +# Begin Source File + +SOURCE=.\icon1.ico +# End Source File +# Begin Source File + +SOURCE=.\Script1.rc +# End Source File +# End Group +# Begin Source File + +SOURCE=.\ReadMe.txt +# End Source File +# End Target +# End Project diff --git a/tools/SRB2Launcher/SRB2Launcher.dsw b/tools/SRB2Launcher/SRB2Launcher.dsw new file mode 100644 index 000000000..b716faced --- /dev/null +++ b/tools/SRB2Launcher/SRB2Launcher.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00 +# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! + +############################################################################### + +Project: "SRB2Launcher"=.\SRB2Launcher.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/tools/SRB2Launcher/SRB2Launcher.h b/tools/SRB2Launcher/SRB2Launcher.h new file mode 100644 index 000000000..3b9049f82 --- /dev/null +++ b/tools/SRB2Launcher/SRB2Launcher.h @@ -0,0 +1,8 @@ +extern char TempString[256]; +extern char EXEName[1024]; +extern char Arguments[16384]; + +#define APPTITLE "Official Sonic Robo Blast 2 Launcher" +#define APPVERSION "v0.1" +#define APPAUTHOR "SSNTails" +#define APPCOMPANY "Sonic Team Junior" diff --git a/tools/SRB2Launcher/Script1.rc b/tools/SRB2Launcher/Script1.rc new file mode 100644 index 000000000..1a27c0414 --- /dev/null +++ b/tools/SRB2Launcher/Script1.rc @@ -0,0 +1,355 @@ +//Microsoft Developer Studio generated resource script. +// +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "afxres.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (U.S.) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +#ifdef _WIN32 +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US +#pragma code_page(1252) +#endif //_WIN32 + +///////////////////////////////////////////////////////////////////////////// +// +// Dialog +// + +IDD_MAIN DIALOG DISCARDABLE 0, 0, 272, 226 +STYLE DS_3DLOOK | WS_MINIMIZEBOX | WS_POPUP | WS_VISIBLE | WS_CAPTION | + WS_SYSMENU +CAPTION "Official Sonic Robo Blast 2 Launcher v0.1" +FONT 8, "MS Sans Serif" +BEGIN + COMBOBOX IDC_LAUNCHCONFIG,125,15,135,155,CBS_DROPDOWNLIST | + CBS_SORT | WS_VSCROLL | WS_TABSTOP + GROUPBOX "Saved Launch Configuration",IDC_STATIC,120,5,145,45 + GROUPBOX "WAD/SOC Files",IDC_STATIC,120,55,145,45 + COMBOBOX IDC_EXTFILECOMBO,125,65,135,95,CBS_DROPDOWNLIST | + WS_VSCROLL | WS_TABSTOP + CONTROL 102,IDC_STATIC,"Static",SS_BITMAP,5,90,107,79 + PUSHBUTTON "&About",IDC_ABOUT,125,210,25,10 + DEFPUSHBUTTON "&Go!",IDC_GO,60,150,50,14 + PUSHBUTTON "Add",IDC_ADDFILE,225,80,35,15 + PUSHBUTTON "Remove",IDC_REMOVEFILE,185,80,35,15 + PUSHBUTTON "Save",IDC_SAVELAUNCHCFG,220,30,40,15 + GROUPBOX "Multiplayer",IDC_STATIC,5,5,105,50 + PUSHBUTTON "&Join A Game",IDC_JOINGAME,10,15,50,15 + PUSHBUTTON "&Host A Game",IDC_HOSTGAME,55,35,50,15 + EDITTEXT IDC_PARAMETERS,160,190,105,30,ES_MULTILINE | + ES_AUTOVSCROLL | WS_VSCROLL + RTEXT "Manual Parameters:",IDC_STATIC,115,190,40,15 + GROUPBOX "Executable Name",IDC_STATIC,120,105,145,50 + EDITTEXT IDC_EXENAME,125,115,95,12,ES_AUTOHSCROLL + PUSHBUTTON "Choose...",IDC_FINDEXENAME,225,115,35,10 + PUSHBUTTON "General &Options",IDC_OPTIONS,55,60,50,20,BS_MULTILINE + EDITTEXT IDC_CONFIGFILE,125,140,95,12,ES_AUTOHSCROLL + LTEXT "Configuration File:",IDC_STATIC,125,130,60,10 + PUSHBUTTON "Choose...",IDC_FINDCONFIGNAME,225,140,35,10 + CONTROL "List1",IDC_LIST1,"SysListView32",WS_BORDER | WS_TABSTOP, + 20,180,85,40 +END + +IDD_JOINGAME DIALOG DISCARDABLE 0, 0, 367, 166 +STYLE DS_MODALFRAME | DS_3DLOOK | WS_POPUP | WS_VISIBLE | WS_CAPTION | + WS_SYSMENU +CAPTION "Join Game" +FONT 8, "MS Sans Serif" +BEGIN + PUSHBUTTON "&Refresh List",IDC_SEARCHGAMES,5,140,55,20,BS_MULTILINE + CONTROL "List1",IDC_GAMELIST,"SysListView32",LVS_REPORT | + LVS_SINGLESEL | WS_BORDER | WS_TABSTOP,5,15,240,120 + EDITTEXT IDC_NAME,295,10,65,12,ES_AUTOHSCROLL + COMBOBOX IDC_COLOR,295,30,65,130,CBS_DROPDOWNLIST | CBS_SORT | + WS_VSCROLL | WS_TABSTOP + RTEXT "Name:",IDC_STATIC,265,10,25,10 + RTEXT "Color:",IDC_STATIC,265,30,25,10 + COMBOBOX IDC_SKIN,295,50,65,110,CBS_DROPDOWNLIST | CBS_SORT | + WS_VSCROLL | WS_TABSTOP + RTEXT "Character:",IDC_STATIC,255,50,35,10 + EDITTEXT IDC_ADDRESS,255,115,70,12,ES_AUTOHSCROLL + LTEXT "Manual Address:",IDC_STATIC,255,105,60,10 + CONTROL "Don't check server for files.",IDC_NOFILE,"Button", + BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP,255,70,105, + 10 + DEFPUSHBUTTON "&Go!",IDC_JOINSTART,330,115,30,15 + LTEXT "Double-Click on a game to join:",IDC_STATIC,5,5,215,10 + CONTROL "Don't download files",IDC_NODOWNLOAD,"Button", + BS_AUTOCHECKBOX | WS_TABSTOP,255,90,105,10 +END + +IDD_HOSTGAME DIALOG DISCARDABLE 0, 0, 287, 156 +STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU +CAPTION "Host Game" +FONT 8, "MS Sans Serif" +BEGIN + GROUPBOX "Game Type",IDC_STATIC,5,5,110,65 + PUSHBUTTON "&Options...",IDC_OPTIONS,55,30,40,15 + COMBOBOX IDC_GAMETYPE,10,15,85,100,CBS_DROPDOWNLIST | WS_VSCROLL | + WS_TABSTOP + RTEXT "Max # of players:",IDC_STATIC,35,86,70,10 + EDITTEXT IDC_MAXPLAYERS,110,86,20,12,ES_AUTOHSCROLL + GROUPBOX "General Options",IDC_STATIC,5,75,275,75 + COMBOBOX IDC_STARTMAP,40,50,70,95,CBS_DROPDOWN | CBS_SORT | + WS_VSCROLL | WS_TABSTOP + RTEXT "Start on map #:",IDC_STATIC,10,45,25,20 + CONTROL "Force players to use host's character",IDC_FORCESKIN, + "Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP,140, + 85,135,10 + COMBOBOX IDC_ADVANCEMAP,45,105,85,50,CBS_DROPDOWNLIST | + WS_VSCROLL | WS_TABSTOP + RTEXT "Advance Stage:",IDC_STATIC,10,100,30,20 + CONTROL "Don't advertise server on Internet",IDC_INTERNETSERVER, + "Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP,140, + 130,120,10 + RTEXT "Intermission Delay Between Levels (in seconds):", + IDC_STATIC,10,125,90,15 + EDITTEXT IDC_INTTIME,105,130,20,12,ES_AUTOHSCROLL | ES_NUMBER + CONTROL "Don't allow autoaim",IDC_DISABLEAUTOAIM,"Button", + BS_AUTOCHECKBOX | WS_TABSTOP,140,100,75,10 + CONTROL "Disable WAD/SOC Downloading",IDC_NODOWNLOAD,"Button", + BS_AUTOCHECKBOX | WS_TABSTOP,140,115,120,10 + PUSHBUTTON "Monitor &Toggles...",IDC_MONITORTOGGLES,125,45,40,20, + BS_MULTILINE +END + +IDD_MATCHOPTIONS DIALOG DISCARDABLE 0, 0, 142, 141 +STYLE DS_MODALFRAME | DS_3DLOOK | WS_POPUP | WS_VISIBLE | WS_CAPTION | + WS_SYSMENU +CAPTION "Match Options" +FONT 8, "MS Sans Serif" +BEGIN + CONTROL "Don't use special ring weapons.",IDC_SPECIALRINGS, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,5,115,10 + RTEXT "Item Box Behavior:",IDC_STATIC,5,50,60,10 + EDITTEXT IDC_RESPAWNITEMTIME,115,70,20,12,ES_AUTOHSCROLL | + ES_NUMBER + COMBOBOX IDC_MATCHBOXES,70,50,65,65,CBS_DROPDOWN | CBS_SORT | + WS_VSCROLL | WS_TABSTOP + RTEXT "Item Respawn Time (in seconds):",IDC_STATIC,5,70,105,10 + EDITTEXT IDC_TIMELIMIT,115,84,20,12,ES_AUTOHSCROLL | ES_NUMBER + RTEXT "Time Limit (in minutes):",IDC_STATIC,35,84,75,10 + RTEXT "Point Limit:",IDC_STATIC,70,100,40,10 + EDITTEXT IDC_POINTLIMIT,115,100,20,12,ES_AUTOHSCROLL | ES_NUMBER + CONTROL "Sudden Death Mode",IDC_SUDDENDEATH,"Button", + BS_AUTOCHECKBOX | WS_TABSTOP,15,20,80,10 + COMBOBOX IDC_MATCH_SCORING,70,35,65,65,CBS_DROPDOWNLIST | + CBS_SORT | WS_VSCROLL | WS_TABSTOP + RTEXT "Scoring Type:",IDC_STATIC,15,35,50,10 + PUSHBUTTON "Cance&l",IDC_CANCEL,100,120,35,15 + DEFPUSHBUTTON "O&K",IDC_OK,60,120,35,15 +END + +IDD_RACEOPTIONS DIALOG DISCARDABLE 0, 0, 142, 71 +STYLE DS_MODALFRAME | DS_3DLOOK | WS_POPUP | WS_VISIBLE | WS_CAPTION | + WS_SYSMENU +CAPTION "Race Options" +FONT 8, "MS Sans Serif" +BEGIN + RTEXT "Item Box Behavior:",IDC_STATIC,5,10,60,10 + COMBOBOX IDC_RACEITEMBOXES,70,10,65,55,CBS_DROPDOWNLIST | + CBS_SORT | WS_VSCROLL | WS_TABSTOP + EDITTEXT IDC_NUMLAPS,115,30,20,12,ES_AUTOHSCROLL | ES_NUMBER + RTEXT "Number of Laps:",IDC_STATIC,55,30,55,10 + PUSHBUTTON "Cance&l",IDC_CANCEL,100,50,35,15 + DEFPUSHBUTTON "O&K",IDC_OK,60,50,35,15 +END + +IDD_CTFOPTIONS DIALOG DISCARDABLE 0, 0, 142, 126 +STYLE DS_MODALFRAME | DS_3DLOOK | WS_POPUP | WS_VISIBLE | WS_CAPTION | + WS_SYSMENU +CAPTION "CTF Options" +FONT 8, "MS Sans Serif" +BEGIN + CONTROL "Don't use special ring weapons.",IDC_SPECIALRINGS, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,5,115,10 + RTEXT "Item Box Behavior:",IDC_STATIC,5,20,60,10 + COMBOBOX IDC_MATCHBOXES,70,20,65,60,CBS_DROPDOWNLIST | WS_VSCROLL | + WS_TABSTOP + RTEXT "Item Respawn Time (in seconds):",IDC_STATIC,5,40,105,10 + EDITTEXT IDC_RESPAWNITEMTIME,115,40,20,12,ES_AUTOHSCROLL | + ES_NUMBER + RTEXT "Time Limit (in minutes):",IDC_STATIC,35,70,75,10 + EDITTEXT IDC_TIMELIMIT,115,70,20,12,ES_AUTOHSCROLL | ES_NUMBER + RTEXT "Point Limit:",IDC_STATIC,70,86,40,10 + EDITTEXT IDC_POINTLIMIT,115,86,20,12,ES_AUTOHSCROLL | ES_NUMBER + RTEXT "Flag Respawn Time (in seconds):",IDC_STATIC,5,55,105,10 + EDITTEXT IDC_FLAGTIME,115,55,20,12,ES_AUTOHSCROLL | ES_NUMBER + PUSHBUTTON "Cance&l",IDC_CANCEL,100,105,35,15 + DEFPUSHBUTTON "O&K",IDC_OK,60,105,35,15 +END + +IDD_TAGOPTIONS DIALOG DISCARDABLE 0, 0, 142, 111 +STYLE DS_MODALFRAME | DS_3DLOOK | WS_POPUP | WS_VISIBLE | WS_CAPTION | + WS_SYSMENU +CAPTION "Tag Options" +FONT 8, "MS Sans Serif" +BEGIN + CONTROL "Don't use special ring weapons.",IDC_SPECIALRINGS, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,5,115,10 + COMBOBOX IDC_MATCHBOXES,70,20,65,60,CBS_DROPDOWNLIST | WS_VSCROLL | + WS_TABSTOP + RTEXT "Item Box Behavior:",IDC_STATIC,5,20,60,10 + DEFPUSHBUTTON "O&K",IDC_OK,60,90,35,15 + PUSHBUTTON "Cance&l",IDC_CANCEL,100,90,35,15 + RTEXT "Item Respawn Time (in seconds):",IDC_STATIC,5,40,105,10 + EDITTEXT IDC_RESPAWNITEMTIME,115,40,20,12,ES_AUTOHSCROLL | + ES_NUMBER + RTEXT "Time Limit (in minutes):",IDC_STATIC,35,55,75,10 + EDITTEXT IDC_TIMELIMIT,115,55,20,12,ES_AUTOHSCROLL | ES_NUMBER + RTEXT "Point Limit:",IDC_STATIC,70,70,40,10 + EDITTEXT IDC_POINTLIMIT,115,70,20,12,ES_AUTOHSCROLL | ES_NUMBER +END + + +///////////////////////////////////////////////////////////////////////////// +// +// DESIGNINFO +// + +#ifdef APSTUDIO_INVOKED +GUIDELINES DESIGNINFO DISCARDABLE +BEGIN + IDD_MAIN, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 265 + TOPMARGIN, 7 + BOTTOMMARGIN, 219 + END + + IDD_JOINGAME, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 360 + TOPMARGIN, 7 + BOTTOMMARGIN, 159 + END + + IDD_HOSTGAME, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 280 + TOPMARGIN, 7 + BOTTOMMARGIN, 149 + END + + IDD_MATCHOPTIONS, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 135 + TOPMARGIN, 7 + BOTTOMMARGIN, 134 + END + + IDD_RACEOPTIONS, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 135 + TOPMARGIN, 7 + BOTTOMMARGIN, 64 + END + + IDD_CTFOPTIONS, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 135 + TOPMARGIN, 7 + BOTTOMMARGIN, 119 + END + + IDD_TAGOPTIONS, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 135 + TOPMARGIN, 7 + BOTTOMMARGIN, 104 + END +END +#endif // APSTUDIO_INVOKED + + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE DISCARDABLE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE DISCARDABLE +BEGIN + "#include ""afxres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE DISCARDABLE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// Bitmap +// + +IDB_BITMAP1 BITMAP DISCARDABLE "bitmap1.bmp" + +///////////////////////////////////////////////////////////////////////////// +// +// Icon +// + +// Icon with lowest ID value placed first to ensure application icon +// remains consistent on all systems. +IDI_ICON1 ICON DISCARDABLE "icon1.ico" + +///////////////////////////////////////////////////////////////////////////// +// +// Dialog Info +// + +IDD_JOINGAME DLGINIT +BEGIN + IDC_SKIN, 0x403, 6, 0 +0x6f53, 0x696e, 0x0063, + IDC_SKIN, 0x403, 6, 0 +0x6154, 0x6c69, 0x0073, + IDC_SKIN, 0x403, 9, 0 +0x6e4b, 0x6375, 0x6c6b, 0x7365, "\000" + 0 +END + +#endif // English (U.S.) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/tools/SRB2Launcher/StdAfx.cpp b/tools/SRB2Launcher/StdAfx.cpp new file mode 100644 index 000000000..444cafebf --- /dev/null +++ b/tools/SRB2Launcher/StdAfx.cpp @@ -0,0 +1,8 @@ +// stdafx.cpp : source file that includes just the standard includes +// SRB2Launcher.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + +// TODO: reference any additional headers you need in STDAFX.H +// and not in this file diff --git a/tools/SRB2Launcher/StdAfx.h b/tools/SRB2Launcher/StdAfx.h new file mode 100644 index 000000000..549cbf9ee --- /dev/null +++ b/tools/SRB2Launcher/StdAfx.h @@ -0,0 +1,29 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// + +#if !defined(AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_) +#define AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_ + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 + +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers + +#include +#include +#include +#include +#include +#include "lilsocklib.h" +#include "resource.h" + + +// TODO: reference additional headers your program requires here + +//{{AFX_INSERT_LOCATION}} +// Microsoft Visual C++ will insert additional declarations immediately before the previous line. + +#endif // !defined(AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_) diff --git a/tools/SRB2Launcher/bitmap1.bmp b/tools/SRB2Launcher/bitmap1.bmp new file mode 100644 index 000000000..01b7cecd9 Binary files /dev/null and b/tools/SRB2Launcher/bitmap1.bmp differ diff --git a/tools/SRB2Launcher/i_tcp.c b/tools/SRB2Launcher/i_tcp.c new file mode 100644 index 000000000..259b416d3 --- /dev/null +++ b/tools/SRB2Launcher/i_tcp.c @@ -0,0 +1,57 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// MSERV SDK +// +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Adapted by Oogaland. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// +// +// DESCRIPTION: +// TCP/IP stuff. +// +//----------------------------------------------------------------------------- + + + + +#include +#include + + +#include "launcher.h" +#include "mserv.h" //Hurdler: support master server + + + + +static int init_tcp_driver = 0; + + +void I_InitTcpDriver(void) +{ + if (!init_tcp_driver) + { +#ifdef __WIN32__ + WSADATA winsockdata; + if( WSAStartup(MAKEWORD(1,1),&winsockdata) ) + I_Error("No Tcp/Ip driver detected"); +#endif +#ifdef __DJGPP_ + if( !__lsck_init() ) + I_Error("No Tcp/Ip driver detected"); +#endif + init_tcp_driver = 1; + } +} diff --git a/tools/SRB2Launcher/i_tcp.h b/tools/SRB2Launcher/i_tcp.h new file mode 100644 index 000000000..9cd34f930 --- /dev/null +++ b/tools/SRB2Launcher/i_tcp.h @@ -0,0 +1,34 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// MSERV SDK +// +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Adapted by Oogaland. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// +// +// DESCRIPTION: +// Header file for the TCP/IP routines +// +//----------------------------------------------------------------------------- + + +#ifndef _I_TCP_H_ +#define _I_TCP_H_ + +extern int sock_port; + +void I_InitTcpDriver(void); + +#endif // !defined(_I_TCP_H_) diff --git a/tools/SRB2Launcher/icon1.ico b/tools/SRB2Launcher/icon1.ico new file mode 100644 index 000000000..f54ce0d6a Binary files /dev/null and b/tools/SRB2Launcher/icon1.ico differ diff --git a/tools/SRB2Launcher/launcher.c b/tools/SRB2Launcher/launcher.c new file mode 100644 index 000000000..4967a95cc --- /dev/null +++ b/tools/SRB2Launcher/launcher.c @@ -0,0 +1,19 @@ +#include + +#include "launcher.h" + +int WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpvReserved) +{ + return TRUE; +} + + +void CONS_Printf(char *fmt, ...) +{ + MessageBox(NULL, fmt, "Master Server", 0); +} + +void I_Error (char *error, ...) +{ + MessageBox(NULL, error, "Master Server", MB_ICONERROR); +} diff --git a/tools/SRB2Launcher/launcher.h b/tools/SRB2Launcher/launcher.h new file mode 100644 index 000000000..12b10aad5 --- /dev/null +++ b/tools/SRB2Launcher/launcher.h @@ -0,0 +1,34 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// MSERV SDK +// +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Adapted by Oogaland. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// +// +// DESCRIPTION: +// Header file for the launcher routines +// +//----------------------------------------------------------------------------- + + +#ifndef _LAUNCHER_H_ +#define _LAUNCHER_H_ + + +void CONS_Printf(char *fmt, ...); +void I_Error (char *error, ...); + +#endif // !defined(_LAUNCHER_H_) diff --git a/tools/SRB2Launcher/lilsocklib.h b/tools/SRB2Launcher/lilsocklib.h new file mode 100644 index 000000000..232f3753a --- /dev/null +++ b/tools/SRB2Launcher/lilsocklib.h @@ -0,0 +1,52 @@ +// Unlike lilsocklib.c, since this takes code from SRB2, +// it is under the GPL, rather than public domain. =( +// +#ifndef __LILSOCKLIB_H__ +#define __LILSOCKLIB_H__ + +#define SD_BOTH 0x02 + +#define PACKET_SIZE 1024 + +#define MS_NO_ERROR 0 +#define MS_SOCKET_ERROR -201 +#define MS_CONNECT_ERROR -203 +#define MS_WRITE_ERROR -210 +#define MS_READ_ERROR -211 +#define MS_CLOSE_ERROR -212 +#define MS_GETHOSTBYNAME_ERROR -220 +#define MS_GETHOSTNAME_ERROR -221 +#define MS_TIMEOUT_ERROR -231 + +// see master server code for the values +#define ADD_SERVER_MSG 101 +#define REMOVE_SERVER_MSG 103 +#ifdef MASTERSERVERS12 +#define ADD_SERVERv2_MSG 104 +#endif +#define GET_SERVER_MSG 200 +#define GET_SHORT_SERVER_MSG 205 +#ifdef MASTERSERVERS12 +#define ASK_SERVER_MSG 206 +#define ANSWER_ASK_SERVER_MSG 207 +#endif + +#define HEADER_SIZE ((long)sizeof (long)*3) + +#define HEADER_MSG_POS 0 +#define IP_MSG_POS 16 +#define PORT_MSG_POS 32 +#define HOSTNAME_MSG_POS 40 + +/** A message to be exchanged with the master server. + */ +typedef struct +{ + long id; ///< Unused? + long type; ///< Type of message. + long length; ///< Length of the message. + char buffer[PACKET_SIZE]; ///< Actual contents of the message. +} msg_t; + +SOCKET ConnectSocket(char* IPAddress); +#endif diff --git a/tools/SRB2Launcher/mserv.c b/tools/SRB2Launcher/mserv.c new file mode 100644 index 000000000..0dd00e2bb --- /dev/null +++ b/tools/SRB2Launcher/mserv.c @@ -0,0 +1,400 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// MSERV SDK +// +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Adapted by Oogaland. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// +// +// DESCRIPTION: +// Commands used to communicate with the master server +// +//----------------------------------------------------------------------------- + + +#ifdef WIN32 +#include // socket(),... +#else +#include +#endif + + + + +#include "launcher.h" + +#include "mserv.h" +#include "i_tcp.h" + + + + + +// ================================ DEFINITIONS =============================== + +#define PACKET_SIZE 1024 + +#define MS_NO_ERROR 0 +#define MS_SOCKET_ERROR -201 +#define MS_CONNECT_ERROR -203 +#define MS_WRITE_ERROR -210 +#define MS_READ_ERROR -211 +#define MS_CLOSE_ERROR -212 +#define MS_GETHOSTBYNAME_ERROR -220 +#define MS_GETHOSTNAME_ERROR -221 +#define MS_TIMEOUT_ERROR -231 + +// see master server code for the values +#define GET_SERVER_MSG 200 + + +#define HEADER_SIZE ((long)sizeof(long)*3) + +#define HEADER_MSG_POS 0 +#define IP_MSG_POS 16 +#define PORT_MSG_POS 32 +#define HOSTNAME_MSG_POS 40 + +#ifndef SOCKET +#define SOCKET int +#endif + +typedef struct { + long id; + long type; + long length; + char buffer[PACKET_SIZE]; +} msg_t; + + +// win32 or djgpp +#if defined( WIN32) || defined( __DJGPP__ ) +#define ioctl ioctlsocket +#define close closesocket +#endif + +#if defined( WIN32) || defined( __OS2__) +// it seems windows doesn't define that... maybe some other OS? OS/2 +int inet_aton(char *hostname, struct in_addr *addr) +{ + return ( (addr->s_addr=inet_addr(hostname)) != INADDR_NONE ); +} +#endif + + + +enum { MSCS_NONE, MSCS_WAITING, MSCS_REGISTERED, MSCS_FAILED } con_state = MSCS_NONE; + + +static SOCKET socket_fd = -1; // TCP/IP socket +static struct sockaddr_in addr; +static struct timeval select_timeout; +static fd_set wset; + +int MS_Connect(char *ip_addr, char *str_port, int async); +static int MS_Read(msg_t *msg); +static int MS_Write(msg_t *msg); +static int MS_GetIP(char *); + +void ExtractServerInfo(char *serverout, struct SERVERLIST *serverlist); + + + + + + + + + + +void CloseConnection(void) +{ + if(socket_fd > 0) close(socket_fd); + socket_fd = -1; +} + + + + +/* +** MS_GetIP() +*/ +static int MS_GetIP(char *hostname) +{ + struct hostent *host_ent; + + if (!inet_aton(hostname, &addr.sin_addr)) { + //TODO: only when we are connected to Internet, or use a non bloking call + host_ent = gethostbyname(hostname); + if (host_ent==NULL) + return MS_GETHOSTBYNAME_ERROR; + memcpy(&addr.sin_addr, host_ent->h_addr_list[0], sizeof(struct in_addr)); + } + return 0; +} + + + + + + +/* +** MS_Connect() +*/ +int MS_Connect(char *ip_addr, char *str_port, int async) +{ + memset(&addr, 0, sizeof(addr)); + addr.sin_family = AF_INET; + I_InitTcpDriver(); // this is done only if not already done + + if ((socket_fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) + return MS_SOCKET_ERROR; + + if (MS_GetIP(ip_addr)==MS_GETHOSTBYNAME_ERROR) + return MS_GETHOSTBYNAME_ERROR; + addr.sin_port = htons((u_short)atoi(str_port)); + + if (async) // do asynchronous connection + { + int res = 1; + + ioctl(socket_fd, FIONBIO, &res); + res = connect(socket_fd, (struct sockaddr *) &addr, sizeof(addr)); + if (res < 0) + { + // humm, on win32 it doesn't work with EINPROGRESS (stupid windows) + if (WSAGetLastError() != WSAEWOULDBLOCK) + { + con_state = MSCS_FAILED; + CloseConnection(); + return MS_CONNECT_ERROR; + } + } + con_state = MSCS_WAITING; + FD_ZERO(&wset); + FD_SET(socket_fd, &wset); + select_timeout.tv_sec = 0, select_timeout.tv_usec = 0; + } + else + { + if (connect(socket_fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) + return MS_CONNECT_ERROR; + } + + return 0; +} + + + + + + +/* + * MS_Write(): + */ +static int MS_Write(msg_t *msg) +{ + int len; + + if (msg->length < 0) + msg->length = strlen(msg->buffer); + len = msg->length+HEADER_SIZE; + + //msg->id = htonl(msg->id); + msg->type = htonl(msg->type); + msg->length = htonl(msg->length); + + if (send(socket_fd, (char*)msg, len, 0) != len) + return MS_WRITE_ERROR; + + return 0; +} + + + + + + +/* + * MS_Read(): + */ +static int MS_Read(msg_t *msg) +{ + if (recv(socket_fd, (char*)msg, HEADER_SIZE, 0) != HEADER_SIZE) + return MS_READ_ERROR; + + msg->type = ntohl(msg->type); + msg->length = ntohl(msg->length); + + if (!msg->length) //Hurdler: fix a bug in Windows 2000 + return 0; + + if (recv(socket_fd, (char*)msg->buffer, msg->length, 0) != msg->length) + return MS_READ_ERROR; + + return 0; +} + + + + + + + + +/***************************************************************************/ + + + + + + + + + +/* GetServerListEx */ +EXPORT int __stdcall GetServerListEx(char *host, char *str_port, struct SERVERLIST serverlist[], short max_servers) +{ + msg_t msg; + int count = 0; + + + /* Attempt to connect to list server. */ + MS_Connect(host, str_port, 0); + + /* Poll the list server. If it fails, depart with an error code of -1. */ + msg.type = GET_SERVER_MSG; + msg.length = 0; + if (MS_Write(&msg) < 0) + return -1; + + + + /* Get a description of each server in turn. */ + /* What we get is exactly the same as the output to the console when using LISTSERV. */ + while (MS_Read(&msg) >= 0) + { + if(msg.length == 0 || count >= max_servers) + { + CloseConnection(); + return count; + } + + ExtractServerInfo(msg.buffer, &serverlist[count]); + + count++; + } + + + CloseConnection(); + return -2; +} + + + + + + + + + + + +/* GetServerList */ +/* Warning: Large kludge follows! This function is only included for backwards-compatibility. */ +/* Use GetServerListVB or GetServerListEx instead. */ +EXPORT int __stdcall GetServerList(char *host, char *str_port, + + struct SERVERLIST *serverlist1,struct SERVERLIST *serverlist2,struct SERVERLIST *serverlist3, + struct SERVERLIST *serverlist4,struct SERVERLIST *serverlist5,struct SERVERLIST *serverlist6, + struct SERVERLIST *serverlist7,struct SERVERLIST *serverlist8,struct SERVERLIST *serverlist9, + struct SERVERLIST *serverlist10,struct SERVERLIST *serverlist11,struct SERVERLIST *serverlist12, + struct SERVERLIST *serverlist13,struct SERVERLIST *serverlist14,struct SERVERLIST *serverlist15, + struct SERVERLIST *serverlist16) +{ + msg_t msg; + int count = 0; + struct SERVERLIST *serverlist[16]; + + + /* Attempt to connect to list server. */ + MS_Connect(host, str_port, 0); + + /* Poll the list server. If it fails, bomb with an error code of -1. */ + msg.type = GET_SERVER_MSG; + msg.length = 0; + if (MS_Write(&msg) < 0) + return -1; + + serverlist[0] = serverlist1; + serverlist[1] = serverlist2; + serverlist[2] = serverlist3; + serverlist[3] = serverlist4; + serverlist[4] = serverlist5; + serverlist[5] = serverlist6; + serverlist[6] = serverlist7; + serverlist[7] = serverlist8; + serverlist[8] = serverlist9; + serverlist[9] = serverlist10; + serverlist[10] = serverlist11; + serverlist[11] = serverlist12; + serverlist[12] = serverlist13; + serverlist[13] = serverlist14; + serverlist[14] = serverlist15; + serverlist[15] = serverlist16; + + + + + while (MS_Read(&msg) >= 0 && count < 16) + { + if(msg.length == 0 || count >= 16) + { + CloseConnection(); + return count; + } + + ExtractServerInfo(msg.buffer, serverlist[count]); + + count++; + } + + + CloseConnection(); + + + return -2; +} + + + +void ExtractServerInfo(char *serverout, struct SERVERLIST *serverlist) +{ + char *lines[5]; + int i; + + i=0; + lines[0] = strtok(serverout, "\r\n"); + for(i=1; i<5; i++) + { + lines[i] = strtok(NULL, "\r\n"); + } + + strcpy(serverlist->ip, strstr(lines[0], ": ")+2); + strcpy(serverlist->port, strstr(lines[1], ": ")+2); + strcpy(serverlist->name, strstr(lines[2], ": ")+2); + strcpy(serverlist->version, strstr(lines[3], ": ")+2); + strcpy(serverlist->perm, strstr(lines[4], ": ")+2); +} diff --git a/tools/SRB2Launcher/mserv.h b/tools/SRB2Launcher/mserv.h new file mode 100644 index 000000000..8f32ae632 --- /dev/null +++ b/tools/SRB2Launcher/mserv.h @@ -0,0 +1,64 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// MSERV SDK +// +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Adapted by Oogaland. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// +// +// DESCRIPTION: +// Header file for the master server routines +// +//----------------------------------------------------------------------------- + +#ifndef _MSERV_H_ +#define _MSERV_H_ + + + +#ifndef EXPORT +#ifdef __cplusplus +#define EXPORT extern "C" __declspec (dllexport) +#else +#define EXPORT __declspec (dllexport) +#endif +#endif + + + +struct SERVERLIST +{ + char ip[16]; + char port[6]; + char name[32]; + char version[16]; + char perm[4]; +}; + + + +EXPORT int __stdcall GetServerListEx(char *ip_addr, char *str_port, struct SERVERLIST serverlist[], short max_servers); +EXPORT int __stdcall GetServerList(char *ip_addr, char *str_port, + struct SERVERLIST *serverlist1,struct SERVERLIST *serverlist2,struct SERVERLIST *serverlist3, + struct SERVERLIST *serverlist4,struct SERVERLIST *serverlist5,struct SERVERLIST *serverlist6, + struct SERVERLIST *serverlist7,struct SERVERLIST *serverlist8,struct SERVERLIST *serverlist9, + struct SERVERLIST *serverlist10,struct SERVERLIST *serverlist11,struct SERVERLIST *serverlist12, + struct SERVERLIST *serverlist13,struct SERVERLIST *serverlist14,struct SERVERLIST *serverlist15, + struct SERVERLIST *serverlist16); + + + + +#endif // !defined(_MSERV_H_) diff --git a/tools/SRB2Launcher/mservsdk.h b/tools/SRB2Launcher/mservsdk.h new file mode 100644 index 000000000..722288e0b --- /dev/null +++ b/tools/SRB2Launcher/mservsdk.h @@ -0,0 +1,65 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// MSERV SDK +// +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Adapted by Oogaland. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// +// +// DESCRIPTION: +// Header file for the master server SDK. +// +//----------------------------------------------------------------------------- + +#ifndef _MSERVSDK_H_ +#define _MSERVSDK_H_ + + + +#ifndef IMPORT +#ifdef __cplusplus +#define IMPORT extern "C" __declspec (dllimport) +#else +#define IMPORT __declspec (dllimport) +#endif +#endif + + + + +struct SERVERLIST +{ + char ip[16]; + char port[6]; + char name[32]; + char version[16]; + char perm[4]; +}; + + + +IMPORT int __stdcall GetServerListEx(char *host, char *str_port, struct SERVERLIST serverlist[], short max_servers); +IMPORT int __stdcall GetServerList(char *host, char *str_port, + struct SERVERLIST *serverlist1,struct SERVERLIST *serverlist2,struct SERVERLIST *serverlist3, + struct SERVERLIST *serverlist4,struct SERVERLIST *serverlist5,struct SERVERLIST *serverlist6, + struct SERVERLIST *serverlist7,struct SERVERLIST *serverlist8,struct SERVERLIST *serverlist9, + struct SERVERLIST *serverlist10,struct SERVERLIST *serverlist11,struct SERVERLIST *serverlist12, + struct SERVERLIST *serverlist13,struct SERVERLIST *serverlist14,struct SERVERLIST *serverlist15, + struct SERVERLIST *serverlist16); + + + + +#endif // !defined(_MSERVSDK_H_) diff --git a/tools/SRB2Launcher/resource.h b/tools/SRB2Launcher/resource.h new file mode 100644 index 000000000..d787fef41 --- /dev/null +++ b/tools/SRB2Launcher/resource.h @@ -0,0 +1,71 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Developer Studio generated include file. +// Used by Script1.rc +// +#define IDD_MAIN 101 +#define IDB_BITMAP1 102 +#define IDI_ICON1 103 +#define IDD_JOINGAME 104 +#define IDD_HOSTGAME 106 +#define IDD_MATCHOPTIONS 108 +#define IDD_RACEOPTIONS 109 +#define IDD_CTFOPTIONS 110 +#define IDD_TAGOPTIONS 111 +#define IDC_GO 1001 +#define IDC_LAUNCHCONFIG 1002 +#define IDC_EXTFILECOMBO 1003 +#define IDC_ABOUT 1005 +#define IDC_ADDFILE 1006 +#define IDC_REMOVEFILE 1007 +#define IDC_SAVELAUNCHCFG 1008 +#define IDC_JOINGAME 1010 +#define IDC_HOSTGAME 1011 +#define IDC_SOUNDOPTS 1012 +#define IDC_PARAMETERS 1013 +#define IDC_EXENAME 1014 +#define IDC_FINDEXENAME 1015 +#define IDC_SEARCHGAMES 1016 +#define IDC_GAMELIST 1018 +#define IDC_NAME 1020 +#define IDC_COLOR 1021 +#define IDC_SKIN 1022 +#define IDC_ADDRESS 1023 +#define IDC_NOFILE 1024 +#define IDC_JOINSTART 1026 +#define IDC_NODOWNLOAD 1027 +#define IDC_OPTIONS 1028 +#define IDC_GAMETYPE 1029 +#define IDC_MAXPLAYERS 1030 +#define IDC_STARTMAP 1031 +#define IDC_FORCESKIN 1032 +#define IDC_ADVANCEMAP 1033 +#define IDC_INTERNETSERVER 1034 +#define IDC_SPECIALRINGS 1036 +#define IDC_MATCHBOXES 1037 +#define IDC_OK 1038 +#define IDC_CANCEL 1039 +#define IDC_RESPAWNITEMTIME 1040 +#define IDC_TIMELIMIT 1041 +#define IDC_POINTLIMIT 1042 +#define IDC_FLAGTIME 1048 +#define IDC_RACEITEMBOXES 1051 +#define IDC_NUMLAPS 1052 +#define IDC_SUDDENDEATH 1060 +#define IDC_MATCH_SCORING 1061 +#define IDC_INTTIME 1064 +#define IDC_DISABLEAUTOAIM 1065 +#define IDC_MONITORTOGGLES 1067 +#define IDC_CONFIGFILE 1069 +#define IDC_FINDCONFIGNAME 1070 +#define IDC_LIST1 1071 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 117 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1072 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/tools/SRB2MP/Makefile b/tools/SRB2MP/Makefile new file mode 100644 index 000000000..92e112d7a --- /dev/null +++ b/tools/SRB2MP/Makefile @@ -0,0 +1,44 @@ +# Makfile of SRB2MP + +CFLAGS +=-Wall -mms-bitfields -fno-exceptions +LDFLAGS +=-mwindows -lfmod +WINDRESFLAGS= + +SRC=lump.c SRB2MP.c + +ifdef DEBUGMODE +CFLAGS +=-g -D_DEBUG +LDFLAGS +=-g +else +CFLAGS :=-Os -s $(CFLAGS) +LDFLAGS :=-s $(LDFLAGS) +endif + +OBJ=$(SRC:.c=.o) # replaces the .c from SRC with .o +EXTRAOBJ=Script1.res +EXE=SRB2MP.exe + +ifdef PREFIX +CC=$(PREFIX)-gcc +WINDRES ?=$(PREFIX)-windres +endif + +WINDRES ?=windres + +RM=rm + +%.o: %.c StdAfx.h lump.h resource.h + $(CC) $(CFLAGS) -o $@ -c $< + +%.res: %.rc resource.h + $(WINDRES) -i $< -O rc $(WINDRESFLAGS) -o $@ -O coff + +.PHONY : all # .PHONY ignores files named all +all: $(EXE) # all is dependent on $(EXE) to be complete + +$(EXE): $(OBJ) $(EXTRAOBJ) # $(EXE) is dependent on all of the files in $(OBJ) to exist + $(CC) $(OBJ) $(EXTRAOBJ) $(LDFLAGS) -o $@ + +.PHONY : clean # .PHONY ignores files named clean +clean: + -$(RM) $(OBJ) $(EXTRAOBJ) diff --git a/tools/SRB2MP/SRB2MP.c b/tools/SRB2MP/SRB2MP.c new file mode 100644 index 000000000..69cc21040 --- /dev/null +++ b/tools/SRB2MP/SRB2MP.c @@ -0,0 +1,464 @@ +// SRB2MP.cpp : Defines the entry point for the application. +// + +#include "StdAfx.h" +#include "lump.h" + +#define APPTITLE "SRB2 Music Player" +#define APPVERSION "v0.1" +#define APPAUTHOR "SSNTails" +#define APPCOMPANY "Sonic Team Junior" + +static FSOUND_STREAM *fmus = NULL; +static int fsoundchannel = -1; +static FMUSIC_MODULE *mod = NULL; +static struct wadfile* wfptr = NULL; + +static inline VOID M_SetVolume(int volume) +{ + if (mod && FMUSIC_GetType(mod) != FMUSIC_TYPE_NONE) + FMUSIC_SetMasterVolume(mod, volume); + if (fsoundchannel != -1) + FSOUND_SetVolume(fsoundchannel, volume); +} + +static inline BOOL M_InitMusic(VOID) +{ + if (FSOUND_GetVersion() < FMOD_VERSION) + { + printf("Error : You are using the wrong DLL version!\nYou should be using FMOD %.02f\n", FMOD_VERSION); + return FALSE; + } + +#ifdef _DEBUG + FSOUND_SetOutput(FSOUND_OUTPUT_WINMM); +#endif + + if (!FSOUND_Init(44100, 1, FSOUND_INIT_GLOBALFOCUS)) + { + printf("%s\n", FMOD_ErrorString(FSOUND_GetError())); + return FALSE; + } + return TRUE; +} + +static inline VOID M_FreeMusic(VOID) +{ + if (mod) + { + FMUSIC_StopSong(mod); + FMUSIC_FreeSong(mod); + mod = NULL; + } + if (fmus) + { + FSOUND_Stream_Stop(fmus); + FSOUND_Stream_Close(fmus); + fmus = NULL; + fsoundchannel = -1; + } +} + +static inline VOID M_ShutdownMusic(VOID) +{ + M_FreeMusic(); + FSOUND_Close(); + //remove(musicfile); // Delete the temp file +} + +static inline VOID M_PauseMusic(VOID) +{ + if (mod && !FMUSIC_GetPaused(mod)) + FMUSIC_SetPaused(mod, TRUE); + if (fsoundchannel != -1 && FSOUND_IsPlaying(fsoundchannel)) + FSOUND_SetPaused(fsoundchannel, TRUE); +} + +static inline VOID M_ResumeMusic(VOID) +{ + if (mod && FMUSIC_GetPaused(mod)) + FMUSIC_SetPaused(mod, FALSE); + if (fsoundchannel != -1 && FSOUND_GetPaused(fsoundchannel)) + FSOUND_SetPaused(fsoundchannel, FALSE); +} + +static inline VOID M_StopMusic(VOID) +{ + if (mod) + FMUSIC_StopSong(mod); + if (fsoundchannel != -1 && fmus && FSOUND_IsPlaying(fsoundchannel)) + FSOUND_Stream_Stop(fmus); +} + +static inline VOID M_StartFMODSong(LPVOID data, int len, int looping, HWND hDlg) +{ + const int loops = FSOUND_LOOP_NORMAL|FSOUND_LOADMEMORY; + const int nloop = FSOUND_LOADMEMORY; + M_FreeMusic(); + + if (looping) + mod = FMUSIC_LoadSongEx(data, 0, len, loops, NULL, 0); + else + mod = FMUSIC_LoadSongEx(data, 0, len, nloop, NULL, 0); + + if (mod) + { + FMUSIC_SetLooping(mod, (signed char)looping); + FMUSIC_SetPanSeperation(mod, 0.0f); + } + else + { + if (looping) + fmus = FSOUND_Stream_Open(data, loops, 0, len); + else + fmus = FSOUND_Stream_Open(data, nloop, 0, len); + } + + if (!fmus && !mod) + { + MessageBoxA(hDlg, FMOD_ErrorString(FSOUND_GetError()), "Error", MB_OK|MB_APPLMODAL); + return; + } + + // Scan the OGG for the COMMENT= field for a custom loop point + if (looping && fmus) + { + const BYTE *origpos, *dataum = data; + size_t scan, size = len; + + CHAR buffer[512]; + BOOL titlefound = FALSE, artistfound = FALSE; + + unsigned int loopstart = 0; + + origpos = dataum; + + for(scan = 0; scan < size; scan++) + { + if (!titlefound) + { + if (*dataum++ == 'T') + if (*dataum++ == 'I') + if (*dataum++ == 'T') + if (*dataum++ == 'L') + if (*dataum++ == 'E') + if (*dataum++ == '=') + { + size_t titlecount = 0; + CHAR title[256]; + BYTE length = *(dataum-10) - 6; + + while(titlecount < length) + title[titlecount++] = *dataum++; + + title[titlecount] = '\0'; + + sprintf(buffer, "Title: %s", title); + + SendMessage(GetDlgItem(hDlg, IDC_TITLE), WM_SETTEXT, 0, (LPARAM)(LPCSTR)buffer); + + titlefound = TRUE; + } + } + } + + dataum = origpos; + + for(scan = 0; scan < size; scan++) + { + if (!artistfound) + { + if (*dataum++ == 'A') + if (*dataum++ == 'R') + if (*dataum++ == 'T') + if (*dataum++ == 'I') + if (*dataum++ == 'S') + if (*dataum++ == 'T') + if (*dataum++ == '=') + { + size_t artistcount = 0; + CHAR artist[256]; + BYTE length = *(dataum-11) - 7; + + while(artistcount < length) + artist[artistcount++] = *dataum++; + + artist[artistcount] = '\0'; + + sprintf(buffer, "By: %s", artist); + + SendMessage(GetDlgItem(hDlg, IDC_ARTIST), WM_SETTEXT, 0, (LPARAM)(LPCSTR)buffer); + + artistfound = TRUE; + } + } + } + + dataum = origpos; + + for(scan = 0; scan < size; scan++) + { + if (*dataum++ == 'C'){ + if (*dataum++ == 'O'){ + if (*dataum++ == 'M'){ + if (*dataum++ == 'M'){ + if (*dataum++ == 'E'){ + if (*dataum++ == 'N'){ + if (*dataum++ == 'T'){ + if (*dataum++ == '='){ + if (*dataum++ == 'L'){ + if (*dataum++ == 'O'){ + if (*dataum++ == 'O'){ + if (*dataum++ == 'P'){ + if (*dataum++ == 'P'){ + if (*dataum++ == 'O'){ + if (*dataum++ == 'I'){ + if (*dataum++ == 'N'){ + if (*dataum++ == 'T'){ + if (*dataum++ == '=') + { + size_t newcount = 0; + CHAR looplength[64]; + while (*dataum != 1 && newcount < 63) + { + looplength[newcount++] = *dataum++; + } + + looplength[newcount] = '\n'; + + loopstart = atoi(looplength); + } + else + dataum--;} + else + dataum--;} + else + dataum--;} + else + dataum--;} + else + dataum--;} + else + dataum--;} + else + dataum--;} + else + dataum--;} + else + dataum--;} + else + dataum--;} + else + dataum--;} + else + dataum--;} + else + dataum--;} + else + dataum--;} + else + dataum--;} + else + dataum--;} + else + dataum--;} + } + + if (loopstart > 0) + { + const int length = FSOUND_Stream_GetLengthMs(fmus); + const int freq = 44100; + const unsigned int loopend = (unsigned int)((freq/1000.0f)*length-(freq/1000.0f)); + if (!FSOUND_Stream_SetLoopPoints(fmus, loopstart, loopend)) + { + printf("FMOD(Start,FSOUND_Stream_SetLoopPoints): %s\n", + FMOD_ErrorString(FSOUND_GetError())); + } + } + } + + if (mod) + FMUSIC_PlaySong(mod); + if (fmus) + fsoundchannel = FSOUND_Stream_PlayEx(FSOUND_FREE, fmus, NULL, FALSE); + + M_SetVolume(128); +} + +static inline VOID FreeWADLumps(VOID) +{ + M_FreeMusic(); + if (wfptr) free_wadfile(wfptr); + wfptr = NULL; +} + +static inline VOID ReadWADLumps(LPCSTR WADfilename, HWND hDlg) +{ + HWND listbox = GetDlgItem(hDlg, IDC_PLAYLIST); + FILE* f; + struct lumplist *curlump; + + SendMessage(listbox, LB_RESETCONTENT, 0, 0); + FreeWADLumps(); + f = fopen(WADfilename, "rb"); + wfptr = read_wadfile(f); + fclose(f); + + /* start of C_LIST */ + /* Loop through the lump list, printing lump info */ + for(curlump = wfptr->head->next; curlump; curlump = curlump->next) + { + LPCSTR lumpname = get_lump_name(curlump->cl); + if (!strncmp(lumpname, "O_", 2) || !strncmp(lumpname, "D_", 2)) + SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)(LPCSTR)get_lump_name(curlump->cl)); + } + /* end of C_LIST */ +} + +// +// OpenWadfile +// +// Provides a common dialog box +// for selecting the desired wad file. +// +static inline VOID OpenWadfile(HWND hDlg) +{ + OPENFILENAMEA ofn; + CHAR FileBuffer[256] = ""; + + ZeroMemory(&ofn, sizeof(ofn)); + ofn.hwndOwner = hDlg; + ofn.lpstrFilter = "WAD Files\0*.wad\0All Files\0*.*\0\0"; + ofn.lpstrInitialDir = NULL; + ofn.lpstrFile = FileBuffer; + ofn.lStructSize = sizeof(ofn); + ofn.nMaxFile = sizeof(FileBuffer); + ofn.nFilterIndex = 1; + ofn.lpstrFileTitle = NULL; + ofn.nMaxFileTitle = 0; + ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; + + if (GetOpenFileNameA(&ofn)) + ReadWADLumps(FileBuffer, hDlg); +} + +static inline VOID PlayLump(HWND hDlg) +{ + HWND listbox = GetDlgItem(hDlg, IDC_PLAYLIST); + LRESULT cursel = SendMessage(listbox, LB_GETCURSEL, 0, 0); + + /* Start of C_EXTRACT */ + CHAR argv[9]; + + SendMessage(listbox, LB_GETTEXT, cursel, (LPARAM)(LPCSTR)argv); + + /* Extract LUMPNAME FILENAME pairs */ + if (wfptr) + { + struct lumplist *extracted; + + printf("Extracting lump %s...\n", argv); + /* Find the lump to extract */ + extracted = find_previous_lump(wfptr->head, NULL, argv); + if (extracted == NULL || (extracted = extracted->next) == NULL) + return; + + /* Extract lump */ + M_StartFMODSong(extracted->cl->data, extracted->cl->len, FALSE, hDlg); + + /* end of extracting LUMPNAME FILENAME pairs */ + + } /* end of C_EXTRACT */ + return; +} + +static LRESULT CALLBACK MainWndproc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + return DefWindowProc(hWnd, message, wParam, lParam); +} + +static INT_PTR CALLBACK DialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +{ + switch(message) + { + case WM_INITDIALOG: + M_InitMusic(); + break; + + case WM_CLOSE: + EndDialog(hDlg, message); + break; + + case WM_DESTROY: + FreeWADLumps(); + M_ShutdownMusic(); + break; + + case WM_COMMAND: + { + switch(LOWORD(wParam)) + { + case 2: + EndDialog(hDlg, message); + return TRUE; + case IDC_ABOUT: // The About button. + { + char TempString[256]; + sprintf(TempString, "%s %s by %s - %s", APPTITLE, APPVERSION, APPAUTHOR, APPCOMPANY); + MessageBoxA(hDlg, TempString, "About", MB_OK|MB_APPLMODAL); + } + return TRUE; + case IDC_OPEN: + OpenWadfile(hDlg); + return TRUE; + case IDC_PLAY: + PlayLump(hDlg); + return TRUE; + default: + break; + } + break; + } + } + + return FALSE; +} + +static inline VOID RegisterDialogClass(LPCSTR name, WNDPROC callback, HINSTANCE hInst) +{ + WNDCLASSA wnd; + + wnd.style = CS_HREDRAW | CS_VREDRAW; + wnd.cbWndExtra = DLGWINDOWEXTRA; + wnd.cbClsExtra = 0; + wnd.hCursor = LoadCursorA(NULL,(LPCSTR)MAKEINTRESOURCE(IDC_ARROW)); + wnd.hIcon = LoadIcon(NULL,MAKEINTRESOURCE(IDI_ICON1)); + wnd.hInstance = hInst; + wnd.lpfnWndProc = callback; + wnd.lpszClassName = name; + wnd.lpszMenuName = NULL; + wnd.hbrBackground = (HBRUSH)(COLOR_WINDOW); + + if (!RegisterClassA(&wnd)) + { + return; + } +} + +int APIENTRY WinMain(HINSTANCE hInstance, + HINSTANCE hPrevInstance, + LPSTR lpCmdLine, + int nCmdShow) +{ + // Prevent multiples instances of this app. + CreateMutexA(NULL, TRUE, APPTITLE); + + if (GetLastError() == ERROR_ALREADY_EXISTS) + return 0; + + RegisterDialogClass("SRB2MP", MainWndproc, hInstance); + + DialogBoxA(hInstance, (LPCSTR)IDD_MAIN, NULL, DialogProc); + + return 0; +} diff --git a/tools/SRB2MP/SRB2MP.dsp b/tools/SRB2MP/SRB2MP.dsp new file mode 100644 index 000000000..f2e700fb5 --- /dev/null +++ b/tools/SRB2MP/SRB2MP.dsp @@ -0,0 +1,148 @@ +# Microsoft Developer Studio Project File - Name="SRB2MP" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Application" 0x0101 + +CFG=SRB2MP - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "SRB2MP.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "SRB2MP.mak" CFG="SRB2MP - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "SRB2MP - Win32 Release" (based on "Win32 (x86) Application") +!MESSAGE "SRB2MP - Win32 Debug" (based on "Win32 (x86) Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "SRB2MP - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /Yu"stdafx.h" /FD /c +# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /Yu"stdafx.h" /FD /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib fmodvc.lib /nologo /subsystem:windows /machine:I386 + +!ELSEIF "$(CFG)" == "SRB2MP - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /Yu"stdafx.h" /FD /GZ /c +# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /Yu"stdafx.h" /FD /GZ /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib fmodvc.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept + +!ENDIF + +# Begin Target + +# Name "SRB2MP - Win32 Release" +# Name "SRB2MP - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\lump.c +# End Source File +# Begin Source File + +SOURCE=.\SRB2MP.c +# End Source File +# Begin Source File + +SOURCE=.\StdAfx.c +# ADD CPP /Yc"stdafx.h" +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# Begin Source File + +SOURCE=.\lump.h +# End Source File +# Begin Source File + +SOURCE=.\resource.h +# End Source File +# Begin Source File + +SOURCE=.\StdAfx.h +# End Source File +# End Group +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# Begin Source File + +SOURCE=.\icon1.ico +# End Source File +# Begin Source File + +SOURCE=.\icon2.ico +# End Source File +# Begin Source File + +SOURCE=.\icon3.ico +# End Source File +# Begin Source File + +SOURCE=.\Script1.rc +# End Source File +# End Group +# Begin Source File + +SOURCE=.\ReadMe.txt +# End Source File +# End Target +# End Project diff --git a/tools/SRB2MP/SRB2MP.dsw b/tools/SRB2MP/SRB2MP.dsw new file mode 100644 index 000000000..b73bd1ac7 --- /dev/null +++ b/tools/SRB2MP/SRB2MP.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00 +# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! + +############################################################################### + +Project: "SRB2MP"=.\SRB2MP.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/tools/SRB2MP/Script1.aps b/tools/SRB2MP/Script1.aps new file mode 100644 index 000000000..994653cb1 Binary files /dev/null and b/tools/SRB2MP/Script1.aps differ diff --git a/tools/SRB2MP/Script1.rc b/tools/SRB2MP/Script1.rc new file mode 100644 index 000000000..3fa7bd572 --- /dev/null +++ b/tools/SRB2MP/Script1.rc @@ -0,0 +1,118 @@ +//Microsoft Developer Studio generated resource script. +// +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "afxres.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (U.S.) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +#ifdef _WIN32 +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US +#pragma code_page(1252) +#endif //_WIN32 + +///////////////////////////////////////////////////////////////////////////// +// +// Dialog +// + +IDD_MAIN DIALOG DISCARDABLE 0, 0, 262, 170 +STYLE DS_3DLOOK | WS_MINIMIZEBOX | WS_POPUP | WS_VISIBLE | WS_CAPTION | + WS_SYSMENU +CAPTION "SRB2 Music Player" +FONT 8, "MS Sans Serif" +BEGIN + PUSHBUTTON "E&xit",IDCANCEL,205,145,50,19 + PUSHBUTTON "&About",IDC_ABOUT,230,15,23,10 + LISTBOX IDC_WADLIST,5,30,112,110,LBS_SORT | LBS_NOINTEGRALHEIGHT | + WS_VSCROLL | WS_TABSTOP + LISTBOX IDC_PLAYLIST,140,30,114,110,LBS_SORT | + LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP + PUSHBUTTON "&Play",IDC_PLAY,140,145,60,20 + PUSHBUTTON "->",IDC_ADD,120,35,15,15 + PUSHBUTTON "<-",IDC_REMOVE,120,55,15,15 + PUSHBUTTON "&Open WAD...",IDC_OPEN,5,10,50,15 + ICON IDI_ICON1,IDC_STATIC,205,5,20,20 + LTEXT "Title:",IDC_TITLE,5,140,125,10 + LTEXT "By:",IDC_ARTIST,5,150,125,15 +END + + +///////////////////////////////////////////////////////////////////////////// +// +// DESIGNINFO +// + +#ifdef APSTUDIO_INVOKED +GUIDELINES DESIGNINFO DISCARDABLE +BEGIN + IDD_MAIN, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 255 + TOPMARGIN, 7 + BOTTOMMARGIN, 163 + END +END +#endif // APSTUDIO_INVOKED + + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE DISCARDABLE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE DISCARDABLE +BEGIN + "#include ""afxres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE DISCARDABLE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// Icon +// + +// Icon with lowest ID value placed first to ensure application icon +// remains consistent on all systems. +IDI_ICON1 ICON DISCARDABLE "icon1.ico" +#endif // English (U.S.) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/tools/SRB2MP/StdAfx.c b/tools/SRB2MP/StdAfx.c new file mode 100644 index 000000000..4f305cd1a --- /dev/null +++ b/tools/SRB2MP/StdAfx.c @@ -0,0 +1,8 @@ +// stdafx.cpp : source file that includes just the standard includes +// SRB2MP.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "StdAfx.h" + +// TODO: reference any additional headers you need in STDAFX.H +// and not in this file diff --git a/tools/SRB2MP/StdAfx.h b/tools/SRB2MP/StdAfx.h new file mode 100644 index 000000000..84ac428b8 --- /dev/null +++ b/tools/SRB2MP/StdAfx.h @@ -0,0 +1,35 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// + +#if !defined(AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_) +#define AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_ + +//#define UNICODE + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 + +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers + +#include +#include +#include +#include + +// TODO: reference additional headers your program requires here +#ifdef __MINGW32__ +#include +#include +#else +#include +#include +#endif +#include "resource.h" + +//{{AFX_INSERT_LOCATION}} +// Microsoft Visual C++ will insert additional declarations immediately before the previous line. + +#endif // !defined(AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_) diff --git a/tools/SRB2MP/icon1.ico b/tools/SRB2MP/icon1.ico new file mode 100644 index 000000000..7548e7caf Binary files /dev/null and b/tools/SRB2MP/icon1.ico differ diff --git a/tools/SRB2MP/lump.c b/tools/SRB2MP/lump.c new file mode 100644 index 000000000..4cf355401 --- /dev/null +++ b/tools/SRB2MP/lump.c @@ -0,0 +1,471 @@ +/* + LumpMod v0.21, a command-line utility for working with lumps in wad files. + Copyright (C) 2003 Thunder Palace Entertainment. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + lump.c: Provides functions for dealing with lumps +*/ + +#include "StdAfx.h" +#include +#include +#include "lump.h" + +/* Read contents of a wad file and store them in memory. + * fpoint is the file to read, opened with "rb" mode. + * A pointer to a new wadfile struct will be returned, or NULL on error. + */ +struct wadfile *read_wadfile(FILE *fpoint) { + struct wadfile *wfptr; + struct lumplist *curlump; + unsigned long diroffset, filelen; + unsigned long count; + + /* Allocate memory for wadfile struct */ + wfptr = (struct wadfile*)malloc(sizeof(struct wadfile)); + if(wfptr == NULL) return NULL; + + /* Read first four characters (PWAD or IWAD) */ + if(fread(wfptr->id, 4, 1, fpoint) < 1) { + free(wfptr); + return NULL; + } + + /* Read number of lumps */ + if(fread(&(wfptr->numlumps), 4, 1, fpoint) < 1) { + free(wfptr); + return NULL; + } + + /* If number of lumps is zero, nothing more needs to be done */ + if(wfptr->numlumps == 0) { + wfptr->head = NULL; + return wfptr; + } + + /* Read offset of directory */ + if(fread(&diroffset, 4, 1, fpoint) < 1) { + free(wfptr); + return NULL; + } + + /* Verify that the directory as long as it needs to be */ + fseek(fpoint, 0, SEEK_END); + filelen = ftell(fpoint); + if((filelen - diroffset) / DIRENTRYLEN < wfptr->numlumps) { + free(wfptr); + return NULL; + } + + /* Allocate memory for head lumplist item and set head pointer */ + curlump = (struct lumplist*)malloc(sizeof(struct lumplist)); + if(curlump == NULL) { + free(wfptr); + return NULL; + } + wfptr->head = curlump; + curlump->cl = NULL; + + /* Read directory entries and lumps */ + for(count = 0; count < wfptr->numlumps; count++) { + long lumpdataoffset; + + /* Advance to a new list item */ + curlump->next = (struct lumplist*)malloc(sizeof(struct lumplist)); + if(curlump->next == NULL) { + free_wadfile(wfptr); + return NULL; + } + curlump = curlump->next; + curlump->next = NULL; + + /* Allocate memory for the lump info */ + curlump->cl = (struct lump*)malloc(sizeof(struct lump)); + if(curlump->cl == NULL) { + free_wadfile(wfptr); + return NULL; + } + + /* Seek to the proper position in the file */ + if(fseek(fpoint, diroffset + (count * DIRENTRYLEN), SEEK_SET) != 0) { + free_wadfile(wfptr); + return NULL; + } + + /* Read offset of lump data */ + if(fread(&lumpdataoffset, 4, 1, fpoint) < 1) { + free_wadfile(wfptr); + return NULL; + } + + /* Read size of lump in bytes */ + if(fread(&(curlump->cl->len), 4, 1, fpoint) < 1) { + free_wadfile(wfptr); + return NULL; + } + + /* Read lump name */ + if(fread(curlump->cl->name, 8, 1, fpoint) < 1) { + free_wadfile(wfptr); + return NULL; + } + + /* Read actual lump data, unless lump size is 0 */ + if(curlump->cl->len > 0) { + if(fseek(fpoint, lumpdataoffset, SEEK_SET) != 0) { + free_wadfile(wfptr); + return NULL; + } + + /* Allocate memory for data */ + curlump->cl->data = (unsigned char*)malloc(curlump->cl->len); + if(curlump->cl->data == NULL) { + free_wadfile(wfptr); + return NULL; + } + + /* Fill the data buffer */ + if(fread(curlump->cl->data, curlump->cl->len, 1, fpoint) < 1) { + free_wadfile(wfptr); + return NULL; + } + } else curlump->cl->data = NULL; + } /* End of directory reading loop */ + + return wfptr; +} + +/* Free a wadfile from memory as well as all related structures. + */ +void free_wadfile(struct wadfile *wfptr) { + struct lumplist *curlump, *nextlump; + + if(wfptr == NULL) return; + curlump = wfptr->head; + + /* Free items in the lump list */ + while(curlump != NULL) { + + /* Free the actual lump and its data, if necessary */ + if(curlump->cl != NULL) { + if(curlump->cl->data != NULL) free(curlump->cl->data); + free(curlump->cl); + } + + /* Advance to next lump and free this one */ + nextlump = curlump->next; + free(curlump); + curlump = nextlump; + } + + free(wfptr); +} + +/* Write complete wadfile to a file stream, opened with "wb" mode. + * fpoint is the stream to write to. + * wfptr is a pointer to the wadfile structure to use. + * Return zero on success, nonzero on failure. + */ +int write_wadfile(FILE *fpoint, struct wadfile *wfptr) { + struct lumplist *curlump; + long lumpdataoffset, diroffset; + + if(wfptr == NULL) return 1; + + /* Write four-character ID ("PWAD" or "IWAD") */ + if(fwrite(wfptr->id, 4, 1, fpoint) < 1) return 2; + + /* Write number of lumps */ + if(fwrite(&(wfptr->numlumps), 4, 1, fpoint) < 1) return 3; + + /* Offset of directory is not known yet. For now, write number of lumps + * again, just to fill the space. + */ + if(fwrite(&(wfptr->numlumps), 4, 1, fpoint) < 1) return 4; + + /* Loop through lump list, writing lump data */ + for(curlump = wfptr->head; curlump != NULL; curlump = curlump->next) { + + /* Don't write anything for the head of the lump list or for lumps of + zero length */ + if(curlump->cl == NULL || curlump->cl->data == NULL) continue; + + /* Write the data */ + if(fwrite(curlump->cl->data, curlump->cl->len, 1, fpoint) < 1) + return 5; + } + + /* Current position is where directory will start */ + diroffset = ftell(fpoint); + + /* Offset for the first lump's data is always 12 */ + lumpdataoffset = 12; + + /* Loop through lump list again, this time writing directory entries */ + for(curlump = wfptr->head; curlump != NULL; curlump = curlump->next) { + + /* Don't write anything for the head of the lump list */ + if(curlump->cl == NULL) continue; + + /* Write offset for lump data */ + if(fwrite(&lumpdataoffset, 4, 1, fpoint) < 1) return 6; + + /* Write size of lump data */ + if(fwrite(&(curlump->cl->len), 4, 1, fpoint) < 1) return 7; + + /* Write lump name */ + if(fwrite(curlump->cl->name, 8, 1, fpoint) < 1) return 8; + + /* Increment lumpdataoffset variable as appropriate */ + lumpdataoffset += curlump->cl->len; + } + + /* Go back to header and write the proper directory offset */ + fseek(fpoint, 8, SEEK_SET); + if(fwrite(&diroffset, 4, 1, fpoint) < 1) return 9; + + return 0; +} + +/* Get the name of a lump, as a null-terminated string. + * item is a pointer to the lump (not lumplist) whose name will be obtained. + * Return NULL on error. + */ +char *get_lump_name(struct lump *item) { + char convname[9], *retname; + + if(item == NULL) return NULL; + memcpy(convname, item->name, 8); + convname[8] = '\0'; + + retname = (char*)malloc(strlen(convname) + 1); + if(retname != NULL) strcpy(retname, convname); + return retname; +} + +/* Find the lump after start and before end having a certain name. + * Return a pointer to the list item for that lump, or return NULL if no lump + * by that name is found or lumpname is too long. + * lumpname is a null-terminated string. + * If end parameter is NULL, search to the end of the entire list. + */ +struct lumplist *find_previous_lump(struct lumplist *start, struct lumplist + *end, char *lumpname) { + struct lumplist *curlump, *lastlump; + char *curname; + int found = 0; + + /* Verify that parameters are valid */ + if(start==NULL || start==end || lumpname==NULL || strlen(lumpname) > 8) + return NULL; + + /* Loop through the list from start parameter */ + lastlump = start; + for(curlump = start->next; curlump != end && curlump != NULL; + curlump = curlump->next) { + + /* Skip header lump */ + if(curlump->cl == NULL) continue; + + /* Find name of this lump */ + curname = get_lump_name(curlump->cl); + if(curname == NULL) continue; + + /* Compare names to see if this is the lump we want */ + if(strcmp(curname, lumpname) == 0) { + found = 1; + break; + } + + /* Free memory allocated to curname */ + free(curname); + + lastlump = curlump; + } + + if(found) return lastlump; + return NULL; +} + +/* Remove a lump from the list, free it, and free its data. + * before is the lump immediately preceding the lump to be removed. + * wfptr is a pointer to the wadfile structure to which the removed lump + * belongs, so that numlumps can be decreased. + */ +void remove_next_lump(struct wadfile *wfptr, struct lumplist *before) { + struct lumplist *removed; + + /* Verify that parameters are valid */ + if(before == NULL || before->next == NULL || wfptr == NULL) return; + + /* Update linked list to omit removed lump */ + removed = before->next; + before->next = removed->next; + + /* Free lump info and data if necessary */ + if(removed->cl != NULL) { + if(removed->cl->data != NULL) free(removed->cl->data); + free(removed->cl); + } + + free(removed); + + /* Decrement numlumps */ + wfptr->numlumps--; +} + +/* Add a lump. + * The lump will follow prev in the list and be named name, with a data size + * of len. + * A copy will be made of the data. + * Return zero on success or nonzero on failure. + */ +int add_lump(struct wadfile *wfptr, struct lumplist *prev, char *name, long + len, unsigned char *data) { + struct lump *newlump; + struct lumplist *newlumplist; + unsigned char *copydata; + + /* Verify that parameters are valid */ + if(wfptr == NULL || prev == NULL || name == NULL || strlen(name) > 8) + return 1; + + /* Allocate space for newlump and newlumplist */ + newlump = (struct lump*)malloc(sizeof(struct lump)); + newlumplist = (struct lumplist*)malloc(sizeof(struct lumplist)); + if(newlump == NULL || newlumplist == NULL) return 2; + + /* Copy lump data and set up newlump */ + if(len == 0 || data == NULL) { + newlump->len = 0; + newlump->data = NULL; + } else { + newlump->len = len; + copydata = (unsigned char*)malloc(len); + if(copydata == NULL) return 3; + memcpy(copydata, data, len); + newlump->data = copydata; + } + + /* Set name of newlump */ + memset(newlump->name, '\0', 8); + if(strlen(name) == 8) memcpy(newlump->name, name, 8); + else strcpy(newlump->name, name); + + /* Set up newlumplist and alter prev appropriately */ + newlumplist->cl = newlump; + newlumplist->next = prev->next; + prev->next = newlumplist; + + /* Increment numlumps */ + wfptr->numlumps++; + + return 0; +} + +/* Rename a lump. + * renamed is a pointer to the lump (not lumplist) that needs renaming. + * newname is a null-terminated string with the new name. + * Return zero on success or nonzero on failure. + */ +int rename_lump(struct lump *renamed, char *newname) { + + /* Verify that parameters are valid. */ + if(newname == NULL || renamed == NULL || strlen(newname) > 8) return 1; + + /* Do the renaming. */ + memset(renamed->name, '\0', 8); + if(strlen(newname) == 8) memcpy(renamed->name, newname, 8); + else strcpy(renamed->name, newname); + + return 0; +} + +/* Find the last lump in a wadfile structure. + * Return this lump or NULL on failure. + */ +struct lumplist *find_last_lump(struct wadfile *wfptr) { + struct lumplist *curlump; + + if(wfptr == NULL || wfptr->head == NULL) return NULL; + curlump = wfptr->head; + + while(curlump->next != NULL) curlump = curlump->next; + return curlump; +} + +/* Find the last lump between start and end. + * Return this lump or NULL on failure. + */ +struct lumplist *find_last_lump_between(struct lumplist *start, struct + lumplist *end) { + struct lumplist *curlump; + + if(start == NULL) return NULL; + curlump = start; + + while(curlump->next != end) { + curlump = curlump->next; + if(curlump == NULL) break; + } + + return curlump; +} + +/* Find the next section lump. A section lump is MAPxx (0 <= x <= 9), ExMy + * (0 <= x <= 9, 0 <= y <= 9), or any lump whose name ends in _START or _END. + * Return NULL if there are no section lumps after start. + */ +struct lumplist *find_next_section_lump(struct lumplist *start) { + struct lumplist *curlump, *found = NULL; + char *curname; + + /* Verify that parameter is valid */ + if(start == NULL || start->next == NULL) return NULL; + + /* Loop through the list from start parameter */ + for(curlump = start->next; curlump != NULL && found == NULL; + curlump = curlump->next) { + + /* Skip header lump */ + if(curlump->cl == NULL) continue; + + /* Find name of this lump */ + curname = get_lump_name(curlump->cl); + if(curname == NULL) continue; + + /* Check to see if this is a section lump */ + if(strlen(curname) == 5 && strncmp("MAP", curname, 3) == 0 && + isdigit(curname[3]) && isdigit(curname[4])) + found = curlump; + else if(strlen(curname) == 4 && curname[0] == 'E' && curname[2] == + 'M' && isdigit(curname[1]) && isdigit(curname[3])) + found = curlump; + else if(strlen(curname) == 7 && strcmp("_START", &curname[1]) == 0) + found = curlump; + else if(strlen(curname) == 8 && strcmp("_START", &curname[2]) == 0) + found = curlump; + else if(strlen(curname) == 5 && strcmp("_END", &curname[1]) == 0) + found = curlump; + else if(strlen(curname) == 6 && strcmp("_END", &curname[2]) == 0) + found = curlump; + + /* Free memory allocated to curname */ + free(curname); + } + + return found; +} diff --git a/tools/SRB2MP/lump.h b/tools/SRB2MP/lump.h new file mode 100644 index 000000000..b36b84441 --- /dev/null +++ b/tools/SRB2MP/lump.h @@ -0,0 +1,61 @@ +/* + LumpMod v0.21, a command-line utility for working with lumps in wad files. + Copyright (C) 2003 Thunder Palace Entertainment. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + lump.h: Defines constants, structures, and functions used in lump.c +*/ + +#ifndef __LUMP_H +#define __LUMP_H + +/* Entries in the wadfile directory are 16 bytes */ +#define DIRENTRYLEN 16 + +/* Lumps and associated info */ +struct lump { + long len; + unsigned char *data; + char name[8]; +}; + +/* Linked list of lumps */ +struct lumplist { + struct lump *cl; /* actual content of the lump */ + struct lumplist *next; +}; + +/* Structure to contain all wadfile data */ +struct wadfile { + char id[4]; /* IWAD or PWAD */ + unsigned long numlumps; /* 32-bit integer */ + struct lumplist *head; /* points to first entry */ +}; + +/* Function declarations */ +struct wadfile *read_wadfile(FILE *); +void free_wadfile(struct wadfile *); +int write_wadfile(FILE *, struct wadfile *); +char *get_lump_name(struct lump *); +struct lumplist *find_previous_lump(struct lumplist *, struct lumplist *, char *); +void remove_next_lump(struct wadfile *, struct lumplist *); +int add_lump(struct wadfile *, struct lumplist *, char *, long, unsigned char *); +int rename_lump(struct lump *, char *); +struct lumplist *find_last_lump(struct wadfile *); +struct lumplist *find_last_lump_between(struct lumplist *, struct lumplist *); +struct lumplist *find_next_section_lump(struct lumplist *); + +#endif diff --git a/tools/SRB2MP/resource.h b/tools/SRB2MP/resource.h new file mode 100644 index 000000000..56924e34a --- /dev/null +++ b/tools/SRB2MP/resource.h @@ -0,0 +1,26 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Developer Studio generated include file. +// Used by Script1.rc +// +#define IDD_MAIN 101 +#define IDI_ICON1 102 +#define IDC_ABOUT 1000 +#define IDC_WADLIST 1001 +#define IDC_PLAYLIST 1002 +#define IDC_PLAY 1003 +#define IDC_ADD 1004 +#define IDC_REMOVE 1005 +#define IDC_OPEN 1006 +#define IDC_TITLE 1007 +#define IDC_ARTIST 1008 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 105 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1009 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/tools/SRB2Updater/Bunny.cs b/tools/SRB2Updater/Bunny.cs new file mode 100644 index 000000000..71934ee31 --- /dev/null +++ b/tools/SRB2Updater/Bunny.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Windows.Forms; + +namespace SRB2Updater +{ + public class Bunny + { + List Keys = new List{System.Windows.Forms.Keys.Up, System.Windows.Forms.Keys.Up, + System.Windows.Forms.Keys.Down, System.Windows.Forms.Keys.Down, + System.Windows.Forms.Keys.Left, System.Windows.Forms.Keys.Right, + System.Windows.Forms.Keys.Left, System.Windows.Forms.Keys.Right, + System.Windows.Forms.Keys.B, System.Windows.Forms.Keys.A}; + private int mPosition = -1; + + public int Position + { + get { return mPosition; } + private set { mPosition = value; } + } + + public bool IsCompletedBy(Keys key) + { + + if (Keys[Position + 1] == key) + { + // move to next + Position++; + } + else if (Position == 1 && key == System.Windows.Forms.Keys.Up) + { + // stay where we are + } + else if (Keys[0] == key) + { + // restart at 1st + Position = 0; + } + else + { + // no match in sequence + Position = -1; + } + + if (Position == Keys.Count - 1) + { + Position = -1; + return true; + } + return false; + } + } +} diff --git a/tools/SRB2Updater/Debug.Designer.cs b/tools/SRB2Updater/Debug.Designer.cs new file mode 100644 index 000000000..6ec72f904 --- /dev/null +++ b/tools/SRB2Updater/Debug.Designer.cs @@ -0,0 +1,266 @@ +namespace SRB2Updater +{ + partial class Debug + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.lblOverallPercentage = new System.Windows.Forms.Label(); + this.lblPercent = new System.Windows.Forms.Label(); + this.lblOverall = new System.Windows.Forms.Label(); + this.lblCurrent = new System.Windows.Forms.Label(); + this.lblTotal = new System.Windows.Forms.Label(); + this.lblRead = new System.Windows.Forms.Label(); + this.label1 = new System.Windows.Forms.Label(); + this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); + this.label6 = new System.Windows.Forms.Label(); + this.label5 = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label7 = new System.Windows.Forms.Label(); + this.lblKonami = new System.Windows.Forms.Label(); + this.lblRandom = new System.Windows.Forms.Label(); + this.label9 = new System.Windows.Forms.Label(); + this.tableLayoutPanel1.SuspendLayout(); + this.SuspendLayout(); + // + // lblOverallPercentage + // + this.lblOverallPercentage.AutoSize = true; + this.lblOverallPercentage.Location = new System.Drawing.Point(176, 150); + this.lblOverallPercentage.Name = "lblOverallPercentage"; + this.lblOverallPercentage.Size = new System.Drawing.Size(21, 13); + this.lblOverallPercentage.TabIndex = 26; + this.lblOverallPercentage.Text = "0%"; + // + // lblPercent + // + this.lblPercent.AutoSize = true; + this.lblPercent.Location = new System.Drawing.Point(176, 90); + this.lblPercent.Name = "lblPercent"; + this.lblPercent.Size = new System.Drawing.Size(21, 13); + this.lblPercent.TabIndex = 25; + this.lblPercent.Text = "0%"; + // + // lblOverall + // + this.lblOverall.AutoSize = true; + this.lblOverall.Location = new System.Drawing.Point(176, 120); + this.lblOverall.Name = "lblOverall"; + this.lblOverall.Size = new System.Drawing.Size(41, 13); + this.lblOverall.TabIndex = 24; + this.lblOverall.Text = "0 bytes"; + // + // lblCurrent + // + this.lblCurrent.AutoSize = true; + this.lblCurrent.Location = new System.Drawing.Point(176, 60); + this.lblCurrent.Name = "lblCurrent"; + this.lblCurrent.Size = new System.Drawing.Size(41, 13); + this.lblCurrent.TabIndex = 23; + this.lblCurrent.Text = "0 bytes"; + // + // lblTotal + // + this.lblTotal.AutoSize = true; + this.lblTotal.Location = new System.Drawing.Point(176, 0); + this.lblTotal.Name = "lblTotal"; + this.lblTotal.Size = new System.Drawing.Size(41, 13); + this.lblTotal.TabIndex = 21; + this.lblTotal.Text = "0 bytes"; + // + // lblRead + // + this.lblRead.AutoSize = true; + this.lblRead.Location = new System.Drawing.Point(176, 30); + this.lblRead.Name = "lblRead"; + this.lblRead.Size = new System.Drawing.Size(41, 13); + this.lblRead.TabIndex = 22; + this.lblRead.Text = "0 bytes"; + this.lblRead.TextAlign = System.Drawing.ContentAlignment.TopRight; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(3, 0); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(105, 13); + this.label1.TabIndex = 27; + this.label1.Text = "Total Download Size"; + // + // tableLayoutPanel1 + // + this.tableLayoutPanel1.ColumnCount = 2; + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 66.66666F)); + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tableLayoutPanel1.Controls.Add(this.label6, 0, 5); + this.tableLayoutPanel1.Controls.Add(this.label5, 0, 4); + this.tableLayoutPanel1.Controls.Add(this.label4, 0, 3); + this.tableLayoutPanel1.Controls.Add(this.label3, 0, 2); + this.tableLayoutPanel1.Controls.Add(this.label2, 0, 1); + this.tableLayoutPanel1.Controls.Add(this.label1, 0, 0); + this.tableLayoutPanel1.Controls.Add(this.lblOverallPercentage, 1, 5); + this.tableLayoutPanel1.Controls.Add(this.lblTotal, 1, 0); + this.tableLayoutPanel1.Controls.Add(this.lblOverall, 1, 4); + this.tableLayoutPanel1.Controls.Add(this.lblPercent, 1, 3); + this.tableLayoutPanel1.Controls.Add(this.lblRead, 1, 1); + this.tableLayoutPanel1.Controls.Add(this.lblCurrent, 1, 2); + this.tableLayoutPanel1.Controls.Add(this.label7, 0, 6); + this.tableLayoutPanel1.Controls.Add(this.lblKonami, 1, 6); + this.tableLayoutPanel1.Controls.Add(this.lblRandom, 1, 7); + this.tableLayoutPanel1.Controls.Add(this.label9, 0, 7); + this.tableLayoutPanel1.Location = new System.Drawing.Point(12, 12); + this.tableLayoutPanel1.Name = "tableLayoutPanel1"; + this.tableLayoutPanel1.RowCount = 9; + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel1.Size = new System.Drawing.Size(260, 355); + this.tableLayoutPanel1.TabIndex = 28; + // + // label6 + // + this.label6.AutoSize = true; + this.label6.Location = new System.Drawing.Point(3, 150); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(98, 13); + this.label6.TabIndex = 32; + this.label6.Text = "Overall Percentage"; + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Location = new System.Drawing.Point(3, 120); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(132, 13); + this.label5.TabIndex = 31; + this.label5.Text = "Bytes Downloaded Overall"; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(3, 90); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(118, 13); + this.label4.TabIndex = 30; + this.label4.Text = "Current File Percentage"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(3, 60); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(146, 13); + this.label3.TabIndex = 29; + this.label3.Text = "Downloaded from Current File"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(3, 30); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(62, 13); + this.label2.TabIndex = 28; + this.label2.Text = "Bytes Read"; + // + // label7 + // + this.label7.AutoSize = true; + this.label7.Location = new System.Drawing.Point(3, 180); + this.label7.Name = "label7"; + this.label7.Size = new System.Drawing.Size(42, 13); + this.label7.TabIndex = 33; + this.label7.Text = "Konami"; + // + // lblKonami + // + this.lblKonami.AutoSize = true; + this.lblKonami.Location = new System.Drawing.Point(176, 180); + this.lblKonami.Name = "lblKonami"; + this.lblKonami.Size = new System.Drawing.Size(16, 13); + this.lblKonami.TabIndex = 34; + this.lblKonami.Text = "-1"; + // + // lblRandom + // + this.lblRandom.AutoSize = true; + this.lblRandom.Location = new System.Drawing.Point(176, 210); + this.lblRandom.Name = "lblRandom"; + this.lblRandom.Size = new System.Drawing.Size(13, 13); + this.lblRandom.TabIndex = 37; + this.lblRandom.Text = "0"; + // + // label9 + // + this.label9.AutoSize = true; + this.label9.Location = new System.Drawing.Point(3, 210); + this.label9.Name = "label9"; + this.label9.Size = new System.Drawing.Size(47, 13); + this.label9.TabIndex = 38; + this.label9.Text = "Random"; + // + // Debug + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(284, 379); + this.Controls.Add(this.tableLayoutPanel1); + this.Name = "Debug"; + this.Text = "Debug"; + this.tableLayoutPanel1.ResumeLayout(false); + this.tableLayoutPanel1.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Label lblOverallPercentage; + private System.Windows.Forms.Label lblPercent; + private System.Windows.Forms.Label lblOverall; + private System.Windows.Forms.Label lblCurrent; + private System.Windows.Forms.Label lblTotal; + private System.Windows.Forms.Label lblRead; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; + private System.Windows.Forms.Label label6; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label7; + private System.Windows.Forms.Label lblKonami; + private System.Windows.Forms.Label lblRandom; + private System.Windows.Forms.Label label9; + } +} \ No newline at end of file diff --git a/tools/SRB2Updater/Debug.cs b/tools/SRB2Updater/Debug.cs new file mode 100644 index 000000000..5cb54dd37 --- /dev/null +++ b/tools/SRB2Updater/Debug.cs @@ -0,0 +1,66 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Text; +using System.Windows.Forms; + +namespace SRB2Updater +{ + public partial class Debug : Form + { + public Debug() + { + InitializeComponent(); + } + + public String strOverall + { + get { return this.lblOverall.Text; } + set { this.lblOverall.Text = value; } + } + + public String strKonami + { + get { return this.lblKonami.Text; } + set { this.lblKonami.Text = value; } + } + + public String strRandom + { + get { return this.lblRandom.Text; } + set { this.lblRandom.Text = value; } + } + + public String strOverallPercentage + { + get { return this.lblOverallPercentage.Text; } + set { this.lblOverallPercentage.Text = value; } + } + + public String strCurrent + { + get { return this.lblCurrent.Text; } + set { this.lblCurrent.Text = value; } + } + + public String strPercent + { + get { return this.lblPercent.Text; } + set { this.lblPercent.Text = value; } + } + + public String strRead + { + get { return this.lblRead.Text; } + set { this.lblRead.Text = value; } + } + + public String strTotal + { + get { return this.lblTotal.Text; } + set { this.lblTotal.Text = value; } + } + } +} diff --git a/tools/SRB2Updater/Debug.resx b/tools/SRB2Updater/Debug.resx new file mode 100644 index 000000000..ff31a6db5 --- /dev/null +++ b/tools/SRB2Updater/Debug.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/tools/SRB2Updater/Launcher.Designer.cs b/tools/SRB2Updater/Launcher.Designer.cs new file mode 100644 index 000000000..9126eba54 --- /dev/null +++ b/tools/SRB2Updater/Launcher.Designer.cs @@ -0,0 +1,766 @@ +namespace SRB2Updater +{ + partial class Launcher + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle5 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle6 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle(); + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Launcher)); + this.panel1 = new System.Windows.Forms.Panel(); + this.panel3 = new System.Windows.Forms.Panel(); + this.btnOptions = new System.Windows.Forms.Button(); + this.btnCheckFiles = new System.Windows.Forms.Button(); + this.btnStartSRB2 = new System.Windows.Forms.Button(); + this.panel2 = new System.Windows.Forms.Panel(); + this.lblProgress = new System.Windows.Forms.Label(); + this.update_optional = new System.Windows.Forms.CheckBox(); + this.progress_overall = new System.Windows.Forms.ProgressBar(); + this.progress_currentFile = new System.Windows.Forms.ProgressBar(); + this.tab_web = new System.Windows.Forms.TabControl(); + this.tabPage1 = new System.Windows.Forms.TabPage(); + this.panel10 = new System.Windows.Forms.Panel(); + this.webBrowser3 = new System.Windows.Forms.WebBrowser(); + this.tabPage2 = new System.Windows.Forms.TabPage(); + this.panel9 = new System.Windows.Forms.Panel(); + this.webBrowser1 = new System.Windows.Forms.WebBrowser(); + this.tabPage3 = new System.Windows.Forms.TabPage(); + this.panel8 = new System.Windows.Forms.Panel(); + this.fileList = new System.Windows.Forms.DataGridView(); + this.name = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.filename = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.status = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.localmd5 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.md5 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.optional = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.calculated = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.serverTab = new System.Windows.Forms.TabPage(); + this.panel6 = new System.Windows.Forms.Panel(); + this.listViewServers = new System.Windows.Forms.ListView(); + this.colhdrName = new System.Windows.Forms.ColumnHeader("(none)"); + this.colhdrGametype = new System.Windows.Forms.ColumnHeader(); + this.colhdrPing = new System.Windows.Forms.ColumnHeader(); + this.colhdrPlayers = new System.Windows.Forms.ColumnHeader(); + this.colhdrVersion = new System.Windows.Forms.ColumnHeader(); + this.panel4 = new System.Windows.Forms.Panel(); + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.label4 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label1 = new System.Windows.Forms.Label(); + this.button1 = new System.Windows.Forms.Button(); + this.button3 = new System.Windows.Forms.Button(); + this.btnConnect = new System.Windows.Forms.Button(); + this.panel5 = new System.Windows.Forms.Panel(); + this.bannerRandom = new System.Windows.Forms.Panel(); + this.backgroundWorkerQueryServers = new System.ComponentModel.BackgroundWorker(); + this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog(); + this.webBrowser2 = new System.Windows.Forms.WebBrowser(); + this.panel1.SuspendLayout(); + this.panel3.SuspendLayout(); + this.panel2.SuspendLayout(); + this.tab_web.SuspendLayout(); + this.tabPage1.SuspendLayout(); + this.panel10.SuspendLayout(); + this.tabPage2.SuspendLayout(); + this.panel9.SuspendLayout(); + this.tabPage3.SuspendLayout(); + this.panel8.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.fileList)).BeginInit(); + this.serverTab.SuspendLayout(); + this.panel6.SuspendLayout(); + this.panel4.SuspendLayout(); + this.groupBox1.SuspendLayout(); + this.panel5.SuspendLayout(); + this.SuspendLayout(); + // + // panel1 + // + this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.panel1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(212)))), ((int)(((byte)(204)))), ((int)(((byte)(187))))); + this.panel1.Controls.Add(this.panel3); + this.panel1.Controls.Add(this.panel2); + this.panel1.Location = new System.Drawing.Point(12, 415); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(772, 125); + this.panel1.TabIndex = 0; + // + // panel3 + // + this.panel3.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Right))); + this.panel3.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(235)))), ((int)(((byte)(230)))), ((int)(((byte)(217))))); + this.panel3.Controls.Add(this.btnOptions); + this.panel3.Controls.Add(this.btnCheckFiles); + this.panel3.Controls.Add(this.btnStartSRB2); + this.panel3.Location = new System.Drawing.Point(557, 10); + this.panel3.Name = "panel3"; + this.panel3.Size = new System.Drawing.Size(204, 104); + this.panel3.TabIndex = 1; + // + // btnOptions + // + this.btnOptions.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.btnOptions.Font = new System.Drawing.Font("Arial Rounded MT Bold", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.btnOptions.Location = new System.Drawing.Point(105, 72); + this.btnOptions.Name = "btnOptions"; + this.btnOptions.Size = new System.Drawing.Size(96, 29); + this.btnOptions.TabIndex = 2; + this.btnOptions.Text = "Options"; + this.btnOptions.UseVisualStyleBackColor = true; + this.btnOptions.Click += new System.EventHandler(this.btnOptions_Click); + // + // btnCheckFiles + // + this.btnCheckFiles.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.btnCheckFiles.Font = new System.Drawing.Font("Arial Rounded MT Bold", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.btnCheckFiles.Location = new System.Drawing.Point(4, 72); + this.btnCheckFiles.Name = "btnCheckFiles"; + this.btnCheckFiles.Size = new System.Drawing.Size(96, 29); + this.btnCheckFiles.TabIndex = 1; + this.btnCheckFiles.Text = "Check Files"; + this.btnCheckFiles.UseVisualStyleBackColor = true; + this.btnCheckFiles.Click += new System.EventHandler(this.update_Load); + // + // btnStartSRB2 + // + this.btnStartSRB2.BackColor = System.Drawing.Color.Transparent; + this.btnStartSRB2.Font = new System.Drawing.Font("Arial Rounded MT Bold", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.btnStartSRB2.Location = new System.Drawing.Point(4, 4); + this.btnStartSRB2.Name = "btnStartSRB2"; + this.btnStartSRB2.Size = new System.Drawing.Size(197, 62); + this.btnStartSRB2.TabIndex = 0; + this.btnStartSRB2.Text = "Start"; + this.btnStartSRB2.UseVisualStyleBackColor = false; + this.btnStartSRB2.Click += new System.EventHandler(this.btnStartSRB2_Click); + // + // panel2 + // + this.panel2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left))); + this.panel2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(235)))), ((int)(((byte)(230)))), ((int)(((byte)(217))))); + this.panel2.Controls.Add(this.lblProgress); + this.panel2.Controls.Add(this.update_optional); + this.panel2.Controls.Add(this.progress_overall); + this.panel2.Controls.Add(this.progress_currentFile); + this.panel2.Location = new System.Drawing.Point(10, 10); + this.panel2.Name = "panel2"; + this.panel2.Size = new System.Drawing.Size(541, 105); + this.panel2.TabIndex = 0; + // + // lblProgress + // + this.lblProgress.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.lblProgress.AutoSize = true; + this.lblProgress.Font = new System.Drawing.Font("Arial Rounded MT Bold", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.lblProgress.ForeColor = System.Drawing.Color.Black; + this.lblProgress.Location = new System.Drawing.Point(6, 68); + this.lblProgress.Name = "lblProgress"; + this.lblProgress.Size = new System.Drawing.Size(299, 14); + this.lblProgress.TabIndex = 14; + this.lblProgress.Text = "Click \'Check Files\' to check for and apply updates."; + // + // update_optional + // + this.update_optional.AutoSize = true; + this.update_optional.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.update_optional.Location = new System.Drawing.Point(372, 68); + this.update_optional.Name = "update_optional"; + this.update_optional.Size = new System.Drawing.Size(160, 18); + this.update_optional.TabIndex = 13; + this.update_optional.Text = "Download Optional Updates"; + this.update_optional.UseVisualStyleBackColor = true; + // + // progress_overall + // + this.progress_overall.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.progress_overall.Location = new System.Drawing.Point(9, 36); + this.progress_overall.Name = "progress_overall"; + this.progress_overall.Size = new System.Drawing.Size(522, 26); + this.progress_overall.TabIndex = 1; + // + // progress_currentFile + // + this.progress_currentFile.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.progress_currentFile.Location = new System.Drawing.Point(9, 4); + this.progress_currentFile.Name = "progress_currentFile"; + this.progress_currentFile.Size = new System.Drawing.Size(522, 26); + this.progress_currentFile.TabIndex = 0; + // + // tab_web + // + this.tab_web.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.tab_web.Controls.Add(this.tabPage1); + this.tab_web.Controls.Add(this.tabPage2); + this.tab_web.Controls.Add(this.tabPage3); + this.tab_web.Controls.Add(this.serverTab); + this.tab_web.Font = new System.Drawing.Font("Arial Rounded MT Bold", 9F); + this.tab_web.Location = new System.Drawing.Point(0, 138); + this.tab_web.Name = "tab_web"; + this.tab_web.SelectedIndex = 0; + this.tab_web.Size = new System.Drawing.Size(770, 256); + this.tab_web.TabIndex = 1; + // + // tabPage1 + // + this.tabPage1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(212)))), ((int)(((byte)(204)))), ((int)(((byte)(187))))); + this.tabPage1.Controls.Add(this.panel10); + this.tabPage1.Font = new System.Drawing.Font("Arial Rounded MT Bold", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.tabPage1.Location = new System.Drawing.Point(4, 23); + this.tabPage1.Name = "tabPage1"; + this.tabPage1.Padding = new System.Windows.Forms.Padding(3); + this.tabPage1.Size = new System.Drawing.Size(762, 229); + this.tabPage1.TabIndex = 0; + this.tabPage1.Text = "News & Updates"; + // + // panel10 + // + this.panel10.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(235)))), ((int)(((byte)(230)))), ((int)(((byte)(217))))); + this.panel10.Controls.Add(this.webBrowser3); + this.panel10.Location = new System.Drawing.Point(4, 6); + this.panel10.Name = "panel10"; + this.panel10.Padding = new System.Windows.Forms.Padding(5); + this.panel10.Size = new System.Drawing.Size(748, 217); + this.panel10.TabIndex = 14; + // + // webBrowser3 + // + this.webBrowser3.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.webBrowser3.Location = new System.Drawing.Point(8, 8); + this.webBrowser3.MinimumSize = new System.Drawing.Size(20, 20); + this.webBrowser3.Name = "webBrowser3"; + this.webBrowser3.Size = new System.Drawing.Size(732, 201); + this.webBrowser3.TabIndex = 0; + this.webBrowser3.Url = new System.Uri("http://update.srb2.org/files_beta/files_beta.xml", System.UriKind.Absolute); + // + // tabPage2 + // + this.tabPage2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(212)))), ((int)(((byte)(204)))), ((int)(((byte)(187))))); + this.tabPage2.Controls.Add(this.panel9); + this.tabPage2.Font = new System.Drawing.Font("Arial Rounded MT Bold", 9F); + this.tabPage2.Location = new System.Drawing.Point(4, 23); + this.tabPage2.Name = "tabPage2"; + this.tabPage2.Padding = new System.Windows.Forms.Padding(3); + this.tabPage2.Size = new System.Drawing.Size(762, 229); + this.tabPage2.TabIndex = 1; + this.tabPage2.Text = "Change Log"; + // + // panel9 + // + this.panel9.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(235)))), ((int)(((byte)(230)))), ((int)(((byte)(217))))); + this.panel9.Controls.Add(this.webBrowser1); + this.panel9.Location = new System.Drawing.Point(4, 6); + this.panel9.Name = "panel9"; + this.panel9.Padding = new System.Windows.Forms.Padding(5); + this.panel9.Size = new System.Drawing.Size(748, 217); + this.panel9.TabIndex = 13; + // + // webBrowser1 + // + this.webBrowser1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.webBrowser1.Location = new System.Drawing.Point(8, 8); + this.webBrowser1.MinimumSize = new System.Drawing.Size(20, 20); + this.webBrowser1.Name = "webBrowser1"; + this.webBrowser1.Size = new System.Drawing.Size(732, 201); + this.webBrowser1.TabIndex = 0; + this.webBrowser1.Url = new System.Uri("http://update.srb2.org/files_beta/changelog.html", System.UriKind.Absolute); + // + // tabPage3 + // + this.tabPage3.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(212)))), ((int)(((byte)(204)))), ((int)(((byte)(187))))); + this.tabPage3.Controls.Add(this.panel8); + this.tabPage3.Location = new System.Drawing.Point(4, 23); + this.tabPage3.Name = "tabPage3"; + this.tabPage3.Padding = new System.Windows.Forms.Padding(3); + this.tabPage3.Size = new System.Drawing.Size(762, 229); + this.tabPage3.TabIndex = 2; + this.tabPage3.Text = "Download List"; + // + // panel8 + // + this.panel8.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(235)))), ((int)(((byte)(230)))), ((int)(((byte)(217))))); + this.panel8.Controls.Add(this.fileList); + this.panel8.Location = new System.Drawing.Point(4, 6); + this.panel8.Name = "panel8"; + this.panel8.Padding = new System.Windows.Forms.Padding(5); + this.panel8.Size = new System.Drawing.Size(748, 217); + this.panel8.TabIndex = 12; + // + // fileList + // + this.fileList.AllowUserToAddRows = false; + this.fileList.AllowUserToDeleteRows = false; + this.fileList.AllowUserToResizeRows = false; + dataGridViewCellStyle1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(212)))), ((int)(((byte)(204)))), ((int)(((byte)(187))))); + dataGridViewCellStyle1.Font = new System.Drawing.Font("Arial Rounded MT Bold", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + dataGridViewCellStyle1.ForeColor = System.Drawing.Color.Black; + dataGridViewCellStyle1.SelectionBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(212)))), ((int)(((byte)(204)))), ((int)(((byte)(187))))); + dataGridViewCellStyle1.SelectionForeColor = System.Drawing.Color.Black; + this.fileList.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle1; + this.fileList.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.fileList.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; + this.fileList.BackgroundColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(224)))), ((int)(((byte)(206))))); + this.fileList.ColumnHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.None; + dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; + dataGridViewCellStyle2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(212)))), ((int)(((byte)(204)))), ((int)(((byte)(187))))); + dataGridViewCellStyle2.Font = new System.Drawing.Font("Arial Rounded MT Bold", 9F); + dataGridViewCellStyle2.ForeColor = System.Drawing.Color.Black; + dataGridViewCellStyle2.Padding = new System.Windows.Forms.Padding(2); + dataGridViewCellStyle2.SelectionBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(212)))), ((int)(((byte)(204)))), ((int)(((byte)(187))))); + dataGridViewCellStyle2.SelectionForeColor = System.Drawing.Color.Black; + dataGridViewCellStyle2.WrapMode = System.Windows.Forms.DataGridViewTriState.True; + this.fileList.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle2; + this.fileList.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.fileList.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.name, + this.filename, + this.status, + this.localmd5, + this.md5, + this.optional, + this.calculated}); + dataGridViewCellStyle4.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; + dataGridViewCellStyle4.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(224)))), ((int)(((byte)(206))))); + dataGridViewCellStyle4.Font = new System.Drawing.Font("Arial Rounded MT Bold", 9F); + dataGridViewCellStyle4.ForeColor = System.Drawing.SystemColors.ControlText; + dataGridViewCellStyle4.SelectionBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(224)))), ((int)(((byte)(206))))); + dataGridViewCellStyle4.SelectionForeColor = System.Drawing.Color.Black; + dataGridViewCellStyle4.WrapMode = System.Windows.Forms.DataGridViewTriState.False; + this.fileList.DefaultCellStyle = dataGridViewCellStyle4; + this.fileList.GridColor = System.Drawing.Color.FromArgb(((int)(((byte)(212)))), ((int)(((byte)(204)))), ((int)(((byte)(187))))); + this.fileList.Location = new System.Drawing.Point(8, 8); + this.fileList.MultiSelect = false; + this.fileList.Name = "fileList"; + this.fileList.ReadOnly = true; + dataGridViewCellStyle5.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; + dataGridViewCellStyle5.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(224)))), ((int)(((byte)(206))))); + dataGridViewCellStyle5.Font = new System.Drawing.Font("Arial Rounded MT Bold", 9F); + dataGridViewCellStyle5.ForeColor = System.Drawing.SystemColors.WindowText; + dataGridViewCellStyle5.SelectionBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(224)))), ((int)(((byte)(206))))); + dataGridViewCellStyle5.SelectionForeColor = System.Drawing.Color.Black; + dataGridViewCellStyle5.WrapMode = System.Windows.Forms.DataGridViewTriState.True; + this.fileList.RowHeadersDefaultCellStyle = dataGridViewCellStyle5; + this.fileList.RowHeadersVisible = false; + dataGridViewCellStyle6.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(224)))), ((int)(((byte)(206))))); + dataGridViewCellStyle6.ForeColor = System.Drawing.Color.Black; + dataGridViewCellStyle6.SelectionBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(224)))), ((int)(((byte)(206))))); + dataGridViewCellStyle6.SelectionForeColor = System.Drawing.Color.Black; + this.fileList.RowsDefaultCellStyle = dataGridViewCellStyle6; + this.fileList.RowTemplate.DefaultCellStyle.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(224)))), ((int)(((byte)(206))))); + this.fileList.RowTemplate.DefaultCellStyle.Font = new System.Drawing.Font("Arial", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.fileList.RowTemplate.DefaultCellStyle.SelectionBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(224)))), ((int)(((byte)(206))))); + this.fileList.RowTemplate.DefaultCellStyle.SelectionForeColor = System.Drawing.Color.Black; + this.fileList.RowTemplate.ReadOnly = true; + this.fileList.Size = new System.Drawing.Size(732, 201); + this.fileList.TabIndex = 11; + // + // name + // + this.name.DataPropertyName = "name"; + dataGridViewCellStyle3.BackColor = System.Drawing.Color.White; + this.name.DefaultCellStyle = dataGridViewCellStyle3; + this.name.FillWeight = 128.7982F; + this.name.HeaderText = "Name"; + this.name.Name = "name"; + this.name.ReadOnly = true; + // + // filename + // + this.filename.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.None; + this.filename.DataPropertyName = "filename"; + this.filename.HeaderText = "File"; + this.filename.Name = "filename"; + this.filename.ReadOnly = true; + this.filename.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable; + this.filename.Width = 150; + // + // status + // + this.status.DataPropertyName = "status"; + this.status.FillWeight = 128.7982F; + this.status.HeaderText = "Status"; + this.status.Name = "status"; + this.status.ReadOnly = true; + // + // localmd5 + // + this.localmd5.DataPropertyName = "localmd5"; + this.localmd5.FillWeight = 13.60544F; + this.localmd5.HeaderText = "localmd5"; + this.localmd5.Name = "localmd5"; + this.localmd5.ReadOnly = true; + this.localmd5.Visible = false; + // + // md5 + // + this.md5.DataPropertyName = "md5"; + this.md5.FillWeight = 128.7982F; + this.md5.HeaderText = "md5"; + this.md5.Name = "md5"; + this.md5.ReadOnly = true; + this.md5.Visible = false; + // + // optional + // + this.optional.DataPropertyName = "optional"; + this.optional.HeaderText = "optional"; + this.optional.Name = "optional"; + this.optional.ReadOnly = true; + this.optional.Visible = false; + // + // calculated + // + this.calculated.DataPropertyName = "calculated"; + this.calculated.HeaderText = "calculated"; + this.calculated.Name = "calculated"; + this.calculated.ReadOnly = true; + this.calculated.Visible = false; + // + // serverTab + // + this.serverTab.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(212)))), ((int)(((byte)(204)))), ((int)(((byte)(187))))); + this.serverTab.Controls.Add(this.panel6); + this.serverTab.Controls.Add(this.panel4); + this.serverTab.Location = new System.Drawing.Point(4, 23); + this.serverTab.Name = "serverTab"; + this.serverTab.Padding = new System.Windows.Forms.Padding(3); + this.serverTab.Size = new System.Drawing.Size(762, 229); + this.serverTab.TabIndex = 3; + this.serverTab.Text = "Master Server"; + // + // panel6 + // + this.panel6.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(235)))), ((int)(((byte)(230)))), ((int)(((byte)(217))))); + this.panel6.Controls.Add(this.listViewServers); + this.panel6.Location = new System.Drawing.Point(4, 6); + this.panel6.Name = "panel6"; + this.panel6.Padding = new System.Windows.Forms.Padding(5); + this.panel6.Size = new System.Drawing.Size(603, 217); + this.panel6.TabIndex = 6; + // + // listViewServers + // + this.listViewServers.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.listViewServers.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(224)))), ((int)(((byte)(206))))); + this.listViewServers.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.listViewServers.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { + this.colhdrName, + this.colhdrGametype, + this.colhdrPing, + this.colhdrPlayers, + this.colhdrVersion}); + this.listViewServers.Font = new System.Drawing.Font("Arial Rounded MT Bold", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.listViewServers.FullRowSelect = true; + this.listViewServers.HideSelection = false; + this.listViewServers.Location = new System.Drawing.Point(9, 8); + this.listViewServers.Name = "listViewServers"; + this.listViewServers.ShowItemToolTips = true; + this.listViewServers.Size = new System.Drawing.Size(586, 201); + this.listViewServers.TabIndex = 1; + this.listViewServers.UseCompatibleStateImageBehavior = false; + this.listViewServers.View = System.Windows.Forms.View.Details; + this.listViewServers.ItemActivate += new System.EventHandler(this.listViewServers_ItemActivate); + this.listViewServers.SelectedIndexChanged += new System.EventHandler(this.listViewServers_SelectedIndexChanged); + this.listViewServers.ColumnClick += new System.Windows.Forms.ColumnClickEventHandler(this.listViewServers_ColumnClick); + // + // colhdrName + // + this.colhdrName.Tag = ""; + this.colhdrName.Text = "Server Name"; + this.colhdrName.Width = 231; + // + // colhdrGametype + // + this.colhdrGametype.Text = "Gametype"; + this.colhdrGametype.Width = 92; + // + // colhdrPing + // + this.colhdrPing.Text = "Ping (ms)"; + this.colhdrPing.Width = 87; + // + // colhdrPlayers + // + this.colhdrPlayers.Text = "Players"; + this.colhdrPlayers.Width = 88; + // + // colhdrVersion + // + this.colhdrVersion.Text = "Version"; + this.colhdrVersion.Width = 87; + // + // panel4 + // + this.panel4.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(235)))), ((int)(((byte)(230)))), ((int)(((byte)(217))))); + this.panel4.Controls.Add(this.groupBox1); + this.panel4.Controls.Add(this.button1); + this.panel4.Controls.Add(this.button3); + this.panel4.Controls.Add(this.btnConnect); + this.panel4.Location = new System.Drawing.Point(613, 6); + this.panel4.Name = "panel4"; + this.panel4.Padding = new System.Windows.Forms.Padding(5); + this.panel4.Size = new System.Drawing.Size(139, 217); + this.panel4.TabIndex = 5; + // + // groupBox1 + // + this.groupBox1.Controls.Add(this.label4); + this.groupBox1.Controls.Add(this.label3); + this.groupBox1.Controls.Add(this.label2); + this.groupBox1.Controls.Add(this.label1); + this.groupBox1.Location = new System.Drawing.Point(9, 114); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(122, 95); + this.groupBox1.TabIndex = 5; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "Key"; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Font = new System.Drawing.Font("Arial Rounded MT Bold", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label4.ForeColor = System.Drawing.Color.Black; + this.label4.Location = new System.Drawing.Point(6, 77); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(87, 14); + this.label4.TabIndex = 3; + this.label4.Text = "Normal Game"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Font = new System.Drawing.Font("Arial Rounded MT Bold", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label3.ForeColor = System.Drawing.Color.DimGray; + this.label3.Location = new System.Drawing.Point(6, 57); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(78, 14); + this.label3.TabIndex = 2; + this.label3.Text = "Game is Full"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Font = new System.Drawing.Font("Arial Rounded MT Bold", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label2.ForeColor = System.Drawing.Color.Green; + this.label2.Location = new System.Drawing.Point(6, 37); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(99, 14); + this.label2.TabIndex = 1; + this.label2.Text = "Cheats Enabled"; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Font = new System.Drawing.Font("Arial Rounded MT Bold", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label1.ForeColor = System.Drawing.Color.Red; + this.label1.Location = new System.Drawing.Point(6, 17); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(57, 14); + this.label1.TabIndex = 0; + this.label1.Text = "Modified"; + // + // button1 + // + this.button1.Font = new System.Drawing.Font("Arial Rounded MT Bold", 9.75F); + this.button1.Location = new System.Drawing.Point(8, 8); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(123, 29); + this.button1.TabIndex = 2; + this.button1.Text = "Refresh List"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.btnRefresh_Click); + // + // button3 + // + this.button3.Font = new System.Drawing.Font("Arial Rounded MT Bold", 9.75F); + this.button3.Location = new System.Drawing.Point(8, 78); + this.button3.Name = "button3"; + this.button3.Size = new System.Drawing.Size(123, 29); + this.button3.TabIndex = 4; + this.button3.Text = "Join Game (IP)"; + this.button3.UseVisualStyleBackColor = true; + // + // btnConnect + // + this.btnConnect.Enabled = false; + this.btnConnect.Font = new System.Drawing.Font("Arial Rounded MT Bold", 9.75F); + this.btnConnect.Location = new System.Drawing.Point(8, 43); + this.btnConnect.Name = "btnConnect"; + this.btnConnect.Size = new System.Drawing.Size(123, 29); + this.btnConnect.TabIndex = 3; + this.btnConnect.Text = "Join Game (List)"; + this.btnConnect.UseVisualStyleBackColor = true; + this.btnConnect.Click += new System.EventHandler(this.btnConnect_Click); + // + // panel5 + // + this.panel5.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.panel5.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; + this.panel5.Controls.Add(this.tab_web); + this.panel5.Controls.Add(this.bannerRandom); + this.panel5.Location = new System.Drawing.Point(12, 13); + this.panel5.Name = "panel5"; + this.panel5.Size = new System.Drawing.Size(772, 396); + this.panel5.TabIndex = 1; + // + // bannerRandom + // + this.bannerRandom.BackgroundImage = global::SRB2Updater.Properties.Resources.Banner4; + this.bannerRandom.Location = new System.Drawing.Point(0, -2); + this.bannerRandom.Name = "bannerRandom"; + this.bannerRandom.Size = new System.Drawing.Size(768, 123); + this.bannerRandom.TabIndex = 3; + // + // backgroundWorkerQueryServers + // + this.backgroundWorkerQueryServers.DoWork += new System.ComponentModel.DoWorkEventHandler(this.backgroundWorkerQueryServers_DoWork); + // + // openFileDialog1 + // + this.openFileDialog1.DefaultExt = "exe"; + this.openFileDialog1.Filter = "Executables files|*.exe|All files|*.*"; + // + // webBrowser2 + // + this.webBrowser2.Location = new System.Drawing.Point(8, 8); + this.webBrowser2.MinimumSize = new System.Drawing.Size(20, 20); + this.webBrowser2.Name = "webBrowser2"; + this.webBrowser2.Size = new System.Drawing.Size(567, 201); + this.webBrowser2.TabIndex = 0; + this.webBrowser2.Url = new System.Uri("http://update.srb2.org/files_beta/changelog.html", System.UriKind.Absolute); + // + // Launcher + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(235)))), ((int)(((byte)(230)))), ((int)(((byte)(217))))); + this.ClientSize = new System.Drawing.Size(796, 552); + this.Controls.Add(this.panel5); + this.Controls.Add(this.panel1); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); + this.KeyPreview = true; + this.Name = "Launcher"; + this.Text = "Launcher"; + this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.Launcher_FormClosed); + this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.Launcher_KeyUp); + this.panel1.ResumeLayout(false); + this.panel3.ResumeLayout(false); + this.panel2.ResumeLayout(false); + this.panel2.PerformLayout(); + this.tab_web.ResumeLayout(false); + this.tabPage1.ResumeLayout(false); + this.panel10.ResumeLayout(false); + this.tabPage2.ResumeLayout(false); + this.panel9.ResumeLayout(false); + this.tabPage3.ResumeLayout(false); + this.panel8.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.fileList)).EndInit(); + this.serverTab.ResumeLayout(false); + this.panel6.ResumeLayout(false); + this.panel4.ResumeLayout(false); + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); + this.panel5.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Panel panel1; + private System.Windows.Forms.Panel panel2; + private System.Windows.Forms.Panel panel3; + private System.Windows.Forms.Button btnOptions; + private System.Windows.Forms.Button btnCheckFiles; + private System.Windows.Forms.Button btnStartSRB2; + private System.Windows.Forms.TabControl tab_web; + private System.Windows.Forms.TabPage tabPage1; + private System.Windows.Forms.TabPage tabPage2; + private System.Windows.Forms.Panel panel5; + private System.Windows.Forms.WebBrowser webBrowser1; + private System.Windows.Forms.Panel bannerRandom; + private System.Windows.Forms.ProgressBar progress_overall; + private System.Windows.Forms.ProgressBar progress_currentFile; + private System.Windows.Forms.TabPage tabPage3; + private System.Windows.Forms.DataGridView fileList; + private System.Windows.Forms.CheckBox update_optional; + private System.Windows.Forms.Label lblProgress; + private System.Windows.Forms.DataGridViewTextBoxColumn name; + private System.Windows.Forms.DataGridViewTextBoxColumn filename; + private System.Windows.Forms.DataGridViewTextBoxColumn status; + private System.Windows.Forms.DataGridViewTextBoxColumn localmd5; + private System.Windows.Forms.DataGridViewTextBoxColumn md5; + private System.Windows.Forms.DataGridViewTextBoxColumn optional; + private System.Windows.Forms.DataGridViewTextBoxColumn calculated; + private System.Windows.Forms.TabPage serverTab; + private System.Windows.Forms.ListView listViewServers; + private System.Windows.Forms.ColumnHeader colhdrName; + private System.Windows.Forms.ColumnHeader colhdrGametype; + private System.Windows.Forms.ColumnHeader colhdrPing; + private System.Windows.Forms.ColumnHeader colhdrPlayers; + private System.Windows.Forms.ColumnHeader colhdrVersion; + private System.ComponentModel.BackgroundWorker backgroundWorkerQueryServers; + private System.Windows.Forms.Panel panel4; + private System.Windows.Forms.Button button1; + private System.Windows.Forms.Button button3; + private System.Windows.Forms.Button btnConnect; + private System.Windows.Forms.OpenFileDialog openFileDialog1; + private System.Windows.Forms.Panel panel6; + private System.Windows.Forms.Panel panel8; + private System.Windows.Forms.Panel panel9; + private System.Windows.Forms.Panel panel10; + private System.Windows.Forms.WebBrowser webBrowser3; + private System.Windows.Forms.WebBrowser webBrowser2; + private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label4; + } +} \ No newline at end of file diff --git a/tools/SRB2Updater/Launcher.cs b/tools/SRB2Updater/Launcher.cs new file mode 100644 index 000000000..df2fdf712 --- /dev/null +++ b/tools/SRB2Updater/Launcher.cs @@ -0,0 +1,658 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +//using System.Data.OleDb; +using System.Xml; +//using System.Drawing; +using System.Text; +using System.Windows.Forms; +using System.Net; +using System.IO; +using System.Threading; +using System.Security.Cryptography; +//using System.Runtime.InteropServices; +using System.Diagnostics; +using System.Drawing; +using System.Media; + +namespace SRB2Updater +{ + public partial class Launcher : Form + { + private Settings settings = new Settings(); + private Debug debug = new Debug(); + // The thread inside which the download happens + private Thread thrDownload; + private Thread thrTotal; + // The stream of data retrieved from the web server + private Stream strResponse; + // The stream of data that we write to the harddrive + private Stream strLocal; + // The request to the web server for file information + private HttpWebRequest webRequest; + // The response from the web server containing information about the file + private HttpWebResponse webResponse; + // The progress of the download in percentage + private static int PercentProgress; + private static int OverallPercentProgress; + // Overall progress as a percentage + private static Int64 OverallProgress; + // Progress stored, for calculating overall + private static Int64 CurrentProgress; + // Total File Size of entire update + private static Int64 TotalSize; + // The delegate which we will call from the thread to update the form + private delegate void UpdateProgessCallback(Int64 BytesRead, Int64 TotalBytes); + private delegate void OverallProgessCallback(Int64 BytesRead); + // When to pause + bool goPause = false; + // Download Details + string downFile; + // Updating + bool filesGot = false; + bool downloadStatus = false; + bool doneCalculate = false; + string formTitle = "Sonic Robo Blast 2 Launcher"; + bool loadedBat = false; + ProcessStartInfo startinfo = new ProcessStartInfo(); + private ServerQuerier sq; + private string MSFail; + + public Launcher(string[] args) + { + InitializeComponent(); + settings.GetSettings(); + sq = new ServerQuerier(); + ServerInfoListViewAdder silva = new ServerInfoListViewAdder(sq, this); + try + { + sq.SetMasterServer(settings.msAddress, Convert.ToUInt16(settings.msPort)); + } + catch (Exception exception) + { + MSFail = exception.Message; + } + sq.StartListening(silva); + backgroundWorkerQueryServers.RunWorkerAsync(); + foreach (string arg in args) + { + if (arg == "-debug") + { + debug.Show(); + break; + } + } + RandomBanner(); + } + + public string getMD5(string filename) + { + StringBuilder sb = new StringBuilder(); + FileInfo f = new FileInfo(filename); + FileStream fs = f.OpenRead(); + MD5 md5 = new MD5CryptoServiceProvider(); + byte[] hash = md5.ComputeHash(fs); + fs.Close(); + foreach (byte hex in hash) + sb.Append(hex.ToString("x2")); + string md5sum = sb.ToString(); + return md5sum; + } + + public void PlayIt() + { + SoundPlayer player = new SoundPlayer(Properties.Resources.Kotaku); + player.Play(); + } + + public void RandomBanner() + { + Random random = new Random(); + int rand = random.Next(0, 4); + //this.bannerRandom.BackgroundImage = global::SRB2Updater.Properties.Resources.Banner; + switch (rand) + { + case 0: + bannerRandom.BackgroundImage = global::SRB2Updater.Properties.Resources.Banner; + break; + case 1: + bannerRandom.BackgroundImage = global::SRB2Updater.Properties.Resources.Banner2; + break; + case 2: + bannerRandom.BackgroundImage = global::SRB2Updater.Properties.Resources.Banner3; + break; + case 3: + bannerRandom.BackgroundImage = global::SRB2Updater.Properties.Resources.Banner4; + break; + default: + bannerRandom.BackgroundImage = global::SRB2Updater.Properties.Resources.Banner; + break; + } + + debug.strRandom = Convert.ToString(rand); + } + + private void updateList(bool doCalculate) + { + if (filesGot == false) + { + + XmlDataDocument xmlDatadoc = new XmlDataDocument(); + xmlDatadoc.DataSet.ReadXml("http://update.srb2.org/files_beta/files_beta.xml"); + DataSet ds = new DataSet("Files DataSet"); + ds = xmlDatadoc.DataSet; + fileList.DataSource = ds.DefaultViewManager; + fileList.DataMember = "File"; + filesGot = true; + } + if (downloadStatus == false) + { + foreach (DataGridViewRow fileRow in fileList.Rows) + { + if (!File.Exists(fileRow.Cells["filename"].Value.ToString()) && fileRow.Cells["filename"].Value.ToString() != "srb2update.update") + { +// fileRow.DefaultCellStyle.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(192))))); + fileRow.Cells["localmd5"].Value = "not_found"; + } else { + if (fileRow.Cells["filename"].Value.ToString() == "srb2update.update") + fileRow.Cells["localmd5"].Value = getMD5("srb2update.exe"); + else + fileRow.Cells["localmd5"].Value = getMD5(fileRow.Cells["filename"].Value.ToString()); + } + if (fileRow.Cells["localmd5"].Value.ToString() != fileRow.Cells["md5"].Value.ToString()) + { +// if (fileRow.Cells["localmd5"].Value.ToString() != "not_found") +// fileRow.DefaultCellStyle.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(224)))), ((int)(((byte)(206))))); + fileRow.Cells["status"].Value = "Queued"; + + } + else + { + fileRow.Cells["status"].Value = "Up to date"; + } + } + if (doCalculate) + { + thrTotal = new Thread(new ParameterizedThreadStart(CalculateTotalSize)); + thrTotal.Start(0); + } + if (doneCalculate) + { + foreach (DataGridViewRow fileRow in fileList.Rows) + { + if (fileRow.Cells["localmd5"].Value.ToString() != fileRow.Cells["md5"].Value.ToString()) + { + if (fileRow.Cells["optional"].Value.ToString() == "1" && !update_optional.Checked) + fileRow.Cells["Status"].Value = "Skipped (Optional)"; + else + { + downFile = fileRow.Cells["filename"].Value.ToString(); + thrDownload = new Thread(new ParameterizedThreadStart(Download)); + thrDownload.Start(0); + fileRow.Cells["Status"].Value = "Downloading..."; + downloadStatus = true; + break; + } + } + else + { + fileRow.Cells["Status"].Value = "Up to date"; + } + CurrentProgress = 0; + } + } + } + } + + private void UpdateProgress(Int64 BytesRead, Int64 TotalBytes) + { + // Calculate the download progress in percentages + PercentProgress = Convert.ToInt32((BytesRead * 100) / TotalBytes); + // Make progress on the progress bar + progress_currentFile.Value = PercentProgress; + // Display the current progress on the form + lblProgress.Text = downFile + " - " + (BytesRead / 1024) + "KB of " + (TotalBytes / 1024) + "KB (" + PercentProgress + "%)"; + this.Text = formTitle + " :: Downloading " + downFile + " (" + PercentProgress + "%)"; + debug.strPercent = PercentProgress.ToString() + "%"; + if (BytesRead >= TotalBytes - 1) + updateList(false); + } + + private void UpdateOverallProgress(Int64 BytesRead) + { + // Calculate progress change and add to OverallProgress... + OverallProgress += BytesRead - CurrentProgress; + // Calculate the download progress in percentages + if (TotalSize < 1) + TotalSize = 1; + OverallPercentProgress = Convert.ToInt32((OverallProgress * 100) / TotalSize); + // Make progress on the progress bar + if (OverallPercentProgress > 100) + OverallPercentProgress = 100; + progress_overall.Value = OverallPercentProgress; + if (OverallProgress >= TotalSize) + { + lblProgress.Text = "Done"; + btnCheckFiles.Enabled = true; + } + CurrentProgress = BytesRead; + debug.strCurrent = Convert.ToString(CurrentProgress) + " bytes"; + debug.strOverall = Convert.ToString(OverallProgress) + " bytes"; + debug.strOverallPercentage = Convert.ToString(OverallPercentProgress) + "%"; + debug.strRead = Convert.ToString(BytesRead) + " bytes"; + debug.strTotal = Convert.ToString(TotalSize) + " bytes"; + } + + private void CalculateTotalSize(object startpoint) + { + foreach (DataGridViewRow fileRow in fileList.Rows) + { + if ((fileRow.Cells["optional"].Value.ToString() == "0" || update_optional.Checked) && fileRow.Cells["localmd5"].Value.ToString() != fileRow.Cells["md5"].Value.ToString()) + { + try + { + // Create a request to the file we are downloading + webRequest = (HttpWebRequest)WebRequest.Create("http://update.srb2.org/files_beta/" + fileRow.Cells["filename"].Value.ToString()); + // Set the starting point of the request + webRequest.AddRange(0); + + // Set default authentication for retrieving the file + webRequest.Credentials = CredentialCache.DefaultCredentials; + // Retrieve the response from the server + webResponse = (HttpWebResponse)webRequest.GetResponse(); + // Ask the server for the file size and store it + Int64 fileSize = webResponse.ContentLength; + TotalSize = TotalSize + fileSize; + } + finally + { + // When the above code has ended, close the streams + webResponse.Close(); + } + } + } + doneCalculate = true; + updateList(false); + } + + private void Download(object startpoint) + { + try + { + string filename = Convert.ToString(startpoint); + // Create a request to the file we are downloading + webRequest = (HttpWebRequest)WebRequest.Create("http://update.srb2.org/files_beta/" + downFile); + // Set the starting point of the request + webRequest.AddRange(0); + + // Set default authentication for retrieving the file + webRequest.Credentials = CredentialCache.DefaultCredentials; + // Retrieve the response from the server + webResponse = (HttpWebResponse)webRequest.GetResponse(); + // Ask the server for the file size and store it + Int64 fileSize = webResponse.ContentLength; + + // Open the URL for download + strResponse = webResponse.GetResponseStream(); + + // Create a new file stream where we will be saving the data (local drive) + strLocal = new FileStream(downFile, FileMode.Create, FileAccess.Write, FileShare.None); + // It will store the current number of bytes we retrieved from the server + int bytesSize = 0; + // A buffer for storing and writing the data retrieved from the server + byte[] downBuffer = new byte[2048]; + + // Loop through the buffer until the buffer is empty + while ((bytesSize = strResponse.Read(downBuffer, 0, downBuffer.Length)) > 0) + { + // Write the data from the buffer to the local hard drive + strLocal.Write(downBuffer, 0, bytesSize); + // Invoke the method that updates the form's label and progress bar + this.Invoke(new UpdateProgessCallback(this.UpdateProgress), new object[] { strLocal.Length, fileSize }); + this.Invoke(new OverallProgessCallback(this.UpdateOverallProgress), new object[] { strLocal.Length }); + + if (goPause == true) + { + break; + } + } + } + finally + { + // When the above code has ended, close the streams + strResponse.Close(); + strLocal.Close(); + // And update the row! + downloadStatus = false; + if (downFile == "srb2update.update" && loadedBat != true) + { + MessageBox.Show("The updater will now restart to apply a patch.", "Self Update", MessageBoxButtons.OK); + CreateUpdaterBat(); + startinfo.WindowStyle = ProcessWindowStyle.Hidden; + startinfo.FileName = "srb2update.bat"; + System.Diagnostics.Process.Start(startinfo); + downloadStatus = false; + Environment.Exit(0); + } else + updateList(false); + } + } + + private void CreateUpdaterBat() + { + File.WriteAllText("srb2update.bat", "ping 127.0.0.1\ncopy srb2update.update srb2update.exe\ndel srb2update.update\nsrb2update.exe\nexit"); + } + + + private void update_Load(object sender, EventArgs e) + { + lblProgress.Text = "Getting File List..."; + if (File.Exists("srb2update.bat")) + File.Delete("srb2update.bat"); + TotalSize = 0; + CurrentProgress = 0; + OverallPercentProgress = 0; + OverallProgress = 0; + btnCheckFiles.Enabled = false; + updateList(true); + } + + private void btnOptions_Click(object sender, EventArgs e) + { + new Options(settings).ShowDialog(); + } + + private class ServerInfoListViewAdder : ServerQuerier.ServerInfoReceiveHandler + { + private delegate ListViewItem AddToListCallback(ListViewItem lvi); + private Launcher form1; + private Dictionary dicGametypes = new Dictionary(); + private static Dictionary> dicDefaultFiles = + new Dictionary>(); + + static ServerInfoListViewAdder() + { + dicDefaultFiles.Add( + ServerQuerier.ServerInfoVer.SIV_PREME, + new List( + new string[] { + "srb2.srb", "sonic.plr", "tails.plr", "knux.plr", + "auto.wpn", "bomb.wpn", "home.wpn", "rail.wpn", "infn.wpn", + "drill.dta", "soar.dta", "music.dta" + }) + ); + + dicDefaultFiles.Add( + ServerQuerier.ServerInfoVer.SIV_ME, + new List( + new string[] { + "srb2.wad", "sonic.plr", "tails.plr", "knux.plr", + "rings.wpn", "drill.dta", "soar.dta", "music.dta" + }) + ); + } + + + public ServerInfoListViewAdder(ServerQuerier sq, Launcher form1) + : base(sq) + { + this.form1 = form1; + + // Gametypes. + dicGametypes.Add(0, "Co-op"); + dicGametypes.Add(1, "Match"); + dicGametypes.Add(2, "Race"); + dicGametypes.Add(3, "Tag"); + dicGametypes.Add(4, "CTF"); + dicGametypes.Add(5, "Chaos"); + + // Don't think these are actually used. + dicGametypes.Add(42, "Team Match"); + dicGametypes.Add(43, "Time-Only Race"); + } + + public override void ProcessServerInfo(ServerQuerier.SRB2ServerInfo srb2si) + { + ListView lv = form1.listViewServers; + + // Build a list item. + ListViewItem lvi = new ListViewItem(srb2si.strName); + + // So we can get address and whatever else we might need. + lvi.Tag = srb2si; + + // Gametype string, or number if not recognised. + if (dicGametypes.ContainsKey(srb2si.byGametype)) + lvi.SubItems.Add(dicGametypes[srb2si.byGametype]); + else + lvi.SubItems.Add(Convert.ToString(srb2si.byGametype)); + + lvi.SubItems.Add(Convert.ToString(srb2si.uiTime)); + lvi.SubItems.Add(srb2si.byPlayers + "/" + srb2si.byMaxplayers); + lvi.SubItems.Add(srb2si.strVersion); + + // Make the tooltip. + BuildTooltip(lvi, form1.settings.ShowDefaultWads); + + // Is the game full? + if (srb2si.byPlayers >= srb2si.byMaxplayers) + lvi.ForeColor = Color.DimGray; + // Modified? + else if (srb2si.bModified) + lvi.ForeColor = Color.Red; + + // Thread-safe goodness. + if (lv.InvokeRequired) + { + // Call ourselves in the context of the form's thread. + AddToListCallback addtolistcallback = new AddToListCallback(lv.Items.Add); + lv.Invoke(addtolistcallback, new object[] { lvi }); + } + else + { + // Add it! + lv.Items.Add(lvi); + } + + } + + public override void HandleException(Exception e) + { + + } + + public static void BuildTooltip(ListViewItem lvi, bool bShowDefaultWads) + { + string strWads = String.Empty; + ServerQuerier.SRB2ServerInfo srb2si = (ServerQuerier.SRB2ServerInfo)lvi.Tag; + + foreach (ServerQuerier.AddedWad aw in srb2si.listFiles) + { + List listDefaultFiles = dicDefaultFiles[srb2si.siv]; + + if (bShowDefaultWads || !listDefaultFiles.Contains(aw.strFilename)) + { + strWads += String.Format("\n{0} ({1:f1} KB)", aw.strFilename, Convert.ToSingle(aw.uiSize) / 1024); + if (aw.bImportant) + { + if (aw.downloadtype == ServerQuerier.DownloadTypes.DT_TOOBIG) + strWads += " (too big to download)"; + else if (aw.downloadtype == ServerQuerier.DownloadTypes.DT_DISABLED) + strWads += " (downloading disabled)"; + } + else strWads += " (unimportant)"; + } + } + + lvi.ToolTipText = "Current map: " + srb2si.strMapName + "\n"; + if (strWads != String.Empty) + lvi.ToolTipText += "Wads added:" + strWads; + else lvi.ToolTipText += "No wads added"; + } + } + + private void backgroundWorkerQueryServers_DoWork(object sender, DoWorkEventArgs e) + { + MSClient msclient = new MSClient(); + + try + { + List listServers = msclient.GetServerList(settings.msAddress, Convert.ToUInt16(settings.msPort)); + + + // Query each of the individual servers asynchronously. + foreach (MSServerEntry msse in listServers) + { + sq.Query(msse.strAddress, msse.unPort); + } + } + catch (System.Net.Sockets.SocketException sockexception) + { + MSFail = sockexception.Message; + } + catch (Exception exception) + { + MSFail = exception.Message; + } + } + + private void btnRefresh_Click(object sender, EventArgs e) + { + if (!backgroundWorkerQueryServers.IsBusy) + { + // Clear the server list. + listViewServers.Items.Clear(); + + // Disable the Connect button. + btnConnect.Enabled = false; + + // Query the MS and the individual servers in another thread. + backgroundWorkerQueryServers.RunWorkerAsync(); + } + } + + private void btnConnect_Click(object sender, EventArgs e) + { + if (listViewServers.SelectedItems.Count > 0) + { + ConnectToServerFromListItem(listViewServers.SelectedItems[0]); + } + } + + private void ConnectToServerFromListItem(ListViewItem lvi) + { + ServerQuerier.SRB2ServerInfo srb2si = (ServerQuerier.SRB2ServerInfo)lvi.Tag; + + // Prompt to get a binary if we need one. + if (!settings.HasBinaryForVersion(srb2si.strVersion) && + MessageBox.Show("To join this game, you must register an executable file for version " + srb2si.strVersion + ". Would you like to do so?", Text, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes && + openFileDialog1.ShowDialog() == DialogResult.OK) + { + settings.SetBinary(srb2si.strVersion, openFileDialog1.FileName); + settings.SaveSettings(); + } + + // Go! + ConnectToServer(srb2si.strAddress, srb2si.unPort, srb2si.strVersion); + } + + private void ConnectToServer(string strAddress, ushort unPort, string strVersion) + { + // Make sure we now have a binary. + if (settings.HasBinaryForVersion(strVersion)) + { + try + { + string strBinary = settings.GetBinary(strVersion); + string strDirectory = System.IO.Path.GetDirectoryName(strBinary); + if (strDirectory != String.Empty) + System.IO.Directory.SetCurrentDirectory(strDirectory); + System.Diagnostics.Process.Start(strBinary, System.String.Format("-connect {0}:{1} {2}", strAddress, unPort, settings.Params)).Close(); + if (settings.CloseOnStart) + Environment.Exit(0); + } + catch (Exception exception) + { + MessageBox.Show("Unable to start SRB2: " + exception.Message + ".", "SRB2 MS Launcher", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private class ListViewSorter : System.Collections.IComparer + { + private int iColumn; + public int Column { get { return iColumn; } } + public SortOrder so; + + public ListViewSorter(int iColumn) + { + this.iColumn = iColumn; + so = SortOrder.Ascending; + } + + public int Compare(object x, object y) + { + ListViewItem lviX = (ListViewItem)x; + ListViewItem lviY = (ListViewItem)y; + + return ((so == SortOrder.Ascending) ? 1 : -1) * String.Compare(lviX.SubItems[iColumn].Text, lviY.SubItems[iColumn].Text); + } + + public void ToggleSortOrder() + { + if (so != SortOrder.Ascending) + so = SortOrder.Ascending; + else + so = SortOrder.Descending; + } + } + + private void listViewServers_ColumnClick(object sender, ColumnClickEventArgs e) + { + if (listViewServers.ListViewItemSorter != null && + ((ListViewSorter)listViewServers.ListViewItemSorter).Column == e.Column) + { + ((ListViewSorter)listViewServers.ListViewItemSorter).ToggleSortOrder(); + listViewServers.Sort(); + } + else + { + listViewServers.ListViewItemSorter = new ListViewSorter(e.Column); + } + } + + private void listViewServers_SelectedIndexChanged(object sender, EventArgs e) + { + btnConnect.Enabled = (listViewServers.SelectedItems.Count > 0); + } + + private void listViewServers_ItemActivate(object sender, EventArgs e) + { + ConnectToServerFromListItem(listViewServers.SelectedItems[0]); + } + + private void Launcher_FormClosed(object sender, FormClosedEventArgs e) + { + Environment.Exit(0); + } + + private Bunny sequence = new Bunny(); + + private void Launcher_KeyUp(object sender, KeyEventArgs e) + { + if (sequence.IsCompletedBy(e.KeyCode)) + { + PlayIt(); + } + debug.strKonami = Convert.ToString(sequence.Position); + } + + private void btnStartSRB2_Click(object sender, EventArgs e) + { + System.Diagnostics.Process.Start("srb2win.exe", System.String.Format("{0}", settings.Params)).Close(); + if(settings.CloseOnStart) + Environment.Exit(0); + } + } +} diff --git a/tools/SRB2Updater/Launcher.resx b/tools/SRB2Updater/Launcher.resx new file mode 100644 index 000000000..464d72c21 --- /dev/null +++ b/tools/SRB2Updater/Launcher.resx @@ -0,0 +1,190 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + 17, 17 + + + 585, 17 + + + + + AAABAAEAICAAAAEACACoCAAAFgAAACgAAAAgAAAAQAAAAAEACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAADg4OAIAAAABQABkAlgAAALkAAABQGQAAcwAlAJYAMQBzJQAAuQA9AJYxAACWAGIAMjIyALk9 + AAD/JSUAPj4+AFZWVgD/SEgAYmJiAABilgBubm4Aenp6AP9rawCAgIAAhoaGAJKSkgD/jo4Anp6eAKSg + oAD/jqsAqqqqAGuP/wC2trYAwMDAAI6r/wDCwsIAa8b/AM7OzgCO1P8A2traAObm5gDy8vIA////AAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAGgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFQ8PHQAAAAAAAAAAAAAAACMgJSUlJSUZ + AAAAABMNBgoPDw8AAAAAAAAAAAAAACInJycnJycnJyclFgYGBggPDw8PDwAAAAAAAAAAAAAjJycnJycn + JycnGScnFQkGCA8PDw8AAAAAAAAAAAAAISMnJycjIyMjJycnJycVDwYGDw8PDwAAAAAAAAAAAAAQAAEj + HygqKSkkHyMnJwoPDwYJDw8PAAAAAAAAAAAAACkTHxwrKysrKysrGhkMDw8PCwYJDw8AAAAAAAAAACkp + JA0pACkrKysrKyspDw8PDw8PAwYIAAAAAAAAAAAAACsiARwAISsrKysrKysSDw8PDw8PAwYAAAAAAAAA + AAAAKyIAEAAfKysrKysrKxcPDw8PDw8PDwgIABYAABcSCAArKAMPACIrKysrKysrGw8PDw8PDw8PDw8P + Dw8PDw8RACsoBA8EISsrKysrKyseDw8PDw8PDw8PDw8PDw8PDwAAKx8PDw8VKSsrKysrKxcPDw8PDw8P + Dw8PDw8PDw8AACooFQ8PDw8aKCsrKysmDw8PDw8PDw8PDw8PDw8PFQAAAAAKDw8PDw8VIigoIgoPDw8P + Dw8PDw8PDw8PDxEAAAAAAAoPDw8PDw8XFxcXEhIPDwUPDw8PDw8PDw8YAAAAAAAACA8PDw8SFxcXFxcX + FxcPFQ8PDw8PDw8KAAAAAAAAAAAACg8PEhcXFxcXFxcXFxkjBRISEhISGAAAAAAAAAAAIRcXCA8XFxcX + FxcXFxcaJyMFDwoLEQAAAAAAAAAAAAAAFxcSDxIXFxcXFxcSEyAlIwILCwsIAAAAAAAAAAAAABcXEg8A + EhIXFxcXEgoPDBUUBwsLCwsLAAAAAAAAAAAAFxcAAAAAFxIXFxcXFxIKDw8ICwsLDg4LAAAAAAAAAAAA + AAAAAAAAABISFxcXFw8PDw8PDw8PDwAAAAAAAAAAAAAAAAAAAAAAAAASEhcSDw8PDw8PDxIAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAFwoSDw8SFwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAP///////////////////3////w//APAf/AAAH/gAAD/wAAA/8AAAP/AAAD/AAAB/4AA + Af+AAABYgAAAAIAAAAGAAAADAAAAA8AAAAfAAAAPwAAAP+AAAH+AAAH/wAAB/4QAAP+eAAB//4AA///g + Af//+A////////////////// + + + \ No newline at end of file diff --git a/tools/SRB2Updater/MSClient.cs b/tools/SRB2Updater/MSClient.cs new file mode 100644 index 000000000..40cb0d984 --- /dev/null +++ b/tools/SRB2Updater/MSClient.cs @@ -0,0 +1,121 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Net.Sockets; +using System.Net; +using System.IO; + +namespace SRB2Updater +{ + class MSClient + { + private Socket socket; + + /// + /// Constructs an MS client object. + /// + public MSClient() + { + socket = new Socket( + AddressFamily.InterNetwork, + SocketType.Stream, + ProtocolType.IP); + } + + /// + /// Gets list of servers reported by the MS. + /// + /// Hostname or IP address of MS. + /// Port of MS. + /// List of running servers. + public List GetServerList(string strAddress, ushort unPort) + { + // Resolve the address if necessary. + IPHostEntry iphe = Dns.GetHostEntry(strAddress); + + int iIPIndex = 0; + while (iIPIndex < iphe.AddressList.Length && + iphe.AddressList[iIPIndex].AddressFamily != socket.AddressFamily) + { + iIPIndex++; + } + + // No addresses from our family? + if (iIPIndex >= iphe.AddressList.Length) + throw new SocketException((int)SocketError.HostNotFound); + + socket.Connect(iphe.AddressList[iIPIndex], unPort); + + // Send a request for the short server list. + byte[] byPacket = new byte[12]; + BinaryWriter bw = new BinaryWriter(new MemoryStream(byPacket)); + bw.Write((uint)0); // Unused + bw.Write((uint)IPAddress.HostToNetworkOrder(205)); // GET_SHORT_SERVER_MSG + bw.Write((uint)0); // Length of tail. + socket.Send(byPacket); + + List listServers = new List(); + + // Don't sit and wait for ever. + socket.ReceiveTimeout = 10000; + + // Keep reading packets. We break if we receive the sentinel end-packet. + byte[] byServer = new byte[12 + 80]; + while (true) + { + int iLen = socket.Receive(byServer); + BinaryReader br = new BinaryReader(new MemoryStream(byServer)); + + // Ignore the first eight bytes. + br.ReadInt64(); + + // Is that the list finished? + int iTailLen = IPAddress.NetworkToHostOrder(br.ReadInt32()); + if (iTailLen == 0) + break; + else if (iTailLen != iLen - 12) + { + // MS is in a bad mood. + //throw new Exception("Bad packet."); + break; + } + + // Otherwise, add the server to the list. + MSServerEntry msse = new MSServerEntry(); + + br.ReadBytes(16); // Skip. + msse.strAddress = Encoding.ASCII.GetString(br.ReadBytes(16)); + + string str = Encoding.ASCII.GetString(br.ReadBytes(8)); + int iPos = str.IndexOf("\0"); + if (iPos >= 0) + str = str.Remove(iPos); + msse.unPort = Convert.ToUInt16(str); + + msse.strName = Encoding.ASCII.GetString(br.ReadBytes(32)); + iPos = msse.strName.IndexOf("\0"); + if (iPos >= 0) + msse.strName = msse.strName.Remove(iPos); + + msse.strVersion = Encoding.ASCII.GetString(br.ReadBytes(8)); + iPos = msse.strVersion.IndexOf("\0"); + if (iPos >= 0) + msse.strVersion = msse.strVersion.Remove(iPos); + + listServers.Add(msse); + } + + return listServers; + } + } + + public struct MSServerEntry + { + public string strAddress; + public ushort unPort; + public string strName; + public string strVersion; + public bool bPermanent; + } + +} diff --git a/tools/SRB2Updater/Options.Designer.cs b/tools/SRB2Updater/Options.Designer.cs new file mode 100644 index 000000000..01234549d --- /dev/null +++ b/tools/SRB2Updater/Options.Designer.cs @@ -0,0 +1,628 @@ +namespace SRB2Updater +{ + partial class Options + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Options)); + this.groupDisplay = new System.Windows.Forms.GroupBox(); + this.label2 = new System.Windows.Forms.Label(); + this.txtHeight = new System.Windows.Forms.TextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.txtWidth = new System.Windows.Forms.TextBox(); + this.chkCustomResolution = new System.Windows.Forms.CheckBox(); + this.chkDisplayWindowed = new System.Windows.Forms.CheckBox(); + this.panel1 = new System.Windows.Forms.Panel(); + this.btnCancel = new System.Windows.Forms.Button(); + this.btnSave = new System.Windows.Forms.Button(); + this.panel2 = new System.Windows.Forms.Panel(); + this.groupMS = new System.Windows.Forms.GroupBox(); + this.label4 = new System.Windows.Forms.Label(); + this.txtMSPort = new System.Windows.Forms.TextBox(); + this.label3 = new System.Windows.Forms.Label(); + this.txtMSAddress = new System.Windows.Forms.TextBox(); + this.panel3 = new System.Windows.Forms.Panel(); + this.panel7 = new System.Windows.Forms.Panel(); + this.groupBox3 = new System.Windows.Forms.GroupBox(); + this.txtParams = new System.Windows.Forms.TextBox(); + this.label9 = new System.Windows.Forms.Label(); + this.panel4 = new System.Windows.Forms.Panel(); + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.listviewBinaries = new System.Windows.Forms.ListView(); + this.colhdrVersion = new System.Windows.Forms.ColumnHeader(); + this.colhdrBinary = new System.Windows.Forms.ColumnHeader(); + this.textboxBinary = new System.Windows.Forms.TextBox(); + this.btnAdd = new System.Windows.Forms.Button(); + this.btnDel = new System.Windows.Forms.Button(); + this.label5 = new System.Windows.Forms.Label(); + this.label7 = new System.Windows.Forms.Label(); + this.btnBrowse = new System.Windows.Forms.Button(); + this.textboxVersion = new System.Windows.Forms.TextBox(); + this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog(); + this.tabControl1 = new System.Windows.Forms.TabControl(); + this.tabPage1 = new System.Windows.Forms.TabPage(); + this.tabPage2 = new System.Windows.Forms.TabPage(); + this.panel5 = new System.Windows.Forms.Panel(); + this.panel6 = new System.Windows.Forms.Panel(); + this.groupBox2 = new System.Windows.Forms.GroupBox(); + this.chkShowDefaultWads = new System.Windows.Forms.CheckBox(); + this.chkCloseOnStart = new System.Windows.Forms.CheckBox(); + this.groupDisplay.SuspendLayout(); + this.panel1.SuspendLayout(); + this.panel2.SuspendLayout(); + this.groupMS.SuspendLayout(); + this.panel3.SuspendLayout(); + this.panel7.SuspendLayout(); + this.groupBox3.SuspendLayout(); + this.panel4.SuspendLayout(); + this.groupBox1.SuspendLayout(); + this.tabControl1.SuspendLayout(); + this.tabPage1.SuspendLayout(); + this.tabPage2.SuspendLayout(); + this.panel5.SuspendLayout(); + this.panel6.SuspendLayout(); + this.groupBox2.SuspendLayout(); + this.SuspendLayout(); + // + // groupDisplay + // + this.groupDisplay.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.groupDisplay.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(235)))), ((int)(((byte)(230)))), ((int)(((byte)(217))))); + this.groupDisplay.Controls.Add(this.label2); + this.groupDisplay.Controls.Add(this.txtHeight); + this.groupDisplay.Controls.Add(this.label1); + this.groupDisplay.Controls.Add(this.txtWidth); + this.groupDisplay.Controls.Add(this.chkCustomResolution); + this.groupDisplay.Controls.Add(this.chkDisplayWindowed); + this.groupDisplay.Location = new System.Drawing.Point(8, 8); + this.groupDisplay.Name = "groupDisplay"; + this.groupDisplay.Size = new System.Drawing.Size(268, 102); + this.groupDisplay.TabIndex = 1; + this.groupDisplay.TabStop = false; + this.groupDisplay.Text = "Display Settings"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(128, 74); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(46, 15); + this.label2.TabIndex = 5; + this.label2.Text = "Height:"; + // + // txtHeight + // + this.txtHeight.Location = new System.Drawing.Point(175, 71); + this.txtHeight.MaxLength = 4; + this.txtHeight.Name = "txtHeight"; + this.txtHeight.Size = new System.Drawing.Size(46, 21); + this.txtHeight.TabIndex = 4; + this.txtHeight.Text = "768"; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(19, 74); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(41, 15); + this.label1.TabIndex = 3; + this.label1.Text = "Width:"; + // + // txtWidth + // + this.txtWidth.Location = new System.Drawing.Point(66, 71); + this.txtWidth.MaxLength = 4; + this.txtWidth.Name = "txtWidth"; + this.txtWidth.Size = new System.Drawing.Size(46, 21); + this.txtWidth.TabIndex = 2; + this.txtWidth.Text = "1024"; + // + // chkCustomResolution + // + this.chkCustomResolution.AutoSize = true; + this.chkCustomResolution.Location = new System.Drawing.Point(6, 46); + this.chkCustomResolution.Name = "chkCustomResolution"; + this.chkCustomResolution.Size = new System.Drawing.Size(159, 19); + this.chkCustomResolution.TabIndex = 1; + this.chkCustomResolution.Text = "Use Custom Resolution"; + this.chkCustomResolution.UseVisualStyleBackColor = true; + this.chkCustomResolution.CheckedChanged += new System.EventHandler(this.chkCustomResolution_CheckedChanged); + // + // chkDisplayWindowed + // + this.chkDisplayWindowed.AutoSize = true; + this.chkDisplayWindowed.Location = new System.Drawing.Point(6, 20); + this.chkDisplayWindowed.Name = "chkDisplayWindowed"; + this.chkDisplayWindowed.Size = new System.Drawing.Size(117, 19); + this.chkDisplayWindowed.TabIndex = 0; + this.chkDisplayWindowed.Text = "Windowed Mode"; + this.chkDisplayWindowed.UseVisualStyleBackColor = true; + // + // panel1 + // + this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.panel1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(235)))), ((int)(((byte)(230)))), ((int)(((byte)(217))))); + this.panel1.Controls.Add(this.groupDisplay); + this.panel1.Location = new System.Drawing.Point(14, 13); + this.panel1.Name = "panel1"; + this.panel1.Padding = new System.Windows.Forms.Padding(5); + this.panel1.Size = new System.Drawing.Size(284, 118); + this.panel1.TabIndex = 2; + // + // btnCancel + // + this.btnCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.btnCancel.Font = new System.Drawing.Font("Arial Rounded MT Bold", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.btnCancel.Location = new System.Drawing.Point(260, 525); + this.btnCancel.Name = "btnCancel"; + this.btnCancel.Size = new System.Drawing.Size(75, 23); + this.btnCancel.TabIndex = 3; + this.btnCancel.Text = "Cancel"; + this.btnCancel.UseVisualStyleBackColor = true; + this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click); + // + // btnSave + // + this.btnSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.btnSave.Font = new System.Drawing.Font("Arial Rounded MT Bold", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.btnSave.Location = new System.Drawing.Point(174, 525); + this.btnSave.Name = "btnSave"; + this.btnSave.Size = new System.Drawing.Size(75, 23); + this.btnSave.TabIndex = 4; + this.btnSave.Text = "Ok"; + this.btnSave.UseVisualStyleBackColor = true; + this.btnSave.Click += new System.EventHandler(this.btnSave_Click); + // + // panel2 + // + this.panel2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(235)))), ((int)(((byte)(230)))), ((int)(((byte)(217))))); + this.panel2.Controls.Add(this.groupMS); + this.panel2.Location = new System.Drawing.Point(13, 13); + this.panel2.Name = "panel2"; + this.panel2.Padding = new System.Windows.Forms.Padding(5); + this.panel2.Size = new System.Drawing.Size(286, 95); + this.panel2.TabIndex = 5; + // + // groupMS + // + this.groupMS.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.groupMS.Controls.Add(this.label4); + this.groupMS.Controls.Add(this.txtMSPort); + this.groupMS.Controls.Add(this.label3); + this.groupMS.Controls.Add(this.txtMSAddress); + this.groupMS.Location = new System.Drawing.Point(9, 8); + this.groupMS.Name = "groupMS"; + this.groupMS.Size = new System.Drawing.Size(269, 79); + this.groupMS.TabIndex = 0; + this.groupMS.TabStop = false; + this.groupMS.Text = "Connection"; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(41, 51); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(32, 15); + this.label4.TabIndex = 3; + this.label4.Text = "Port:"; + // + // txtMSPort + // + this.txtMSPort.Location = new System.Drawing.Point(79, 48); + this.txtMSPort.Name = "txtMSPort"; + this.txtMSPort.Size = new System.Drawing.Size(86, 21); + this.txtMSPort.TabIndex = 2; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(17, 23); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(56, 15); + this.label3.TabIndex = 1; + this.label3.Text = "Address:"; + // + // txtMSAddress + // + this.txtMSAddress.Location = new System.Drawing.Point(79, 20); + this.txtMSAddress.Name = "txtMSAddress"; + this.txtMSAddress.Size = new System.Drawing.Size(184, 21); + this.txtMSAddress.TabIndex = 0; + // + // panel3 + // + this.panel3.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(212)))), ((int)(((byte)(204)))), ((int)(((byte)(187))))); + this.panel3.Controls.Add(this.panel7); + this.panel3.Controls.Add(this.panel4); + this.panel3.Controls.Add(this.panel1); + this.panel3.Location = new System.Drawing.Point(6, 6); + this.panel3.Name = "panel3"; + this.panel3.Padding = new System.Windows.Forms.Padding(10); + this.panel3.Size = new System.Drawing.Size(312, 467); + this.panel3.TabIndex = 6; + // + // panel7 + // + this.panel7.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(235)))), ((int)(((byte)(230)))), ((int)(((byte)(217))))); + this.panel7.Controls.Add(this.groupBox3); + this.panel7.Location = new System.Drawing.Point(15, 350); + this.panel7.Name = "panel7"; + this.panel7.Padding = new System.Windows.Forms.Padding(5); + this.panel7.Size = new System.Drawing.Size(283, 106); + this.panel7.TabIndex = 7; + // + // groupBox3 + // + this.groupBox3.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.groupBox3.Controls.Add(this.chkCloseOnStart); + this.groupBox3.Controls.Add(this.txtParams); + this.groupBox3.Controls.Add(this.label9); + this.groupBox3.Location = new System.Drawing.Point(13, 8); + this.groupBox3.Name = "groupBox3"; + this.groupBox3.Size = new System.Drawing.Size(258, 83); + this.groupBox3.TabIndex = 12; + this.groupBox3.TabStop = false; + this.groupBox3.Text = "Command Line"; + // + // txtParams + // + this.txtParams.Location = new System.Drawing.Point(83, 20); + this.txtParams.Name = "txtParams"; + this.txtParams.Size = new System.Drawing.Size(167, 21); + this.txtParams.TabIndex = 6; + // + // label9 + // + this.label9.AutoSize = true; + this.label9.Location = new System.Drawing.Point(5, 23); + this.label9.Name = "label9"; + this.label9.Size = new System.Drawing.Size(75, 15); + this.label9.TabIndex = 7; + this.label9.Text = "Parameters:"; + // + // panel4 + // + this.panel4.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(235)))), ((int)(((byte)(230)))), ((int)(((byte)(217))))); + this.panel4.Controls.Add(this.groupBox1); + this.panel4.Location = new System.Drawing.Point(15, 137); + this.panel4.Name = "panel4"; + this.panel4.Padding = new System.Windows.Forms.Padding(5); + this.panel4.Size = new System.Drawing.Size(284, 207); + this.panel4.TabIndex = 6; + // + // groupBox1 + // + this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.groupBox1.Controls.Add(this.listviewBinaries); + this.groupBox1.Controls.Add(this.textboxBinary); + this.groupBox1.Controls.Add(this.btnAdd); + this.groupBox1.Controls.Add(this.btnDel); + this.groupBox1.Controls.Add(this.label5); + this.groupBox1.Controls.Add(this.label7); + this.groupBox1.Controls.Add(this.btnBrowse); + this.groupBox1.Controls.Add(this.textboxVersion); + this.groupBox1.Location = new System.Drawing.Point(13, 8); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(259, 191); + this.groupBox1.TabIndex = 12; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "Executables"; + // + // listviewBinaries + // + this.listviewBinaries.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.listviewBinaries.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { + this.colhdrVersion, + this.colhdrBinary}); + this.listviewBinaries.FullRowSelect = true; + this.listviewBinaries.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable; + this.listviewBinaries.HideSelection = false; + this.listviewBinaries.Location = new System.Drawing.Point(6, 19); + this.listviewBinaries.Name = "listviewBinaries"; + this.listviewBinaries.Size = new System.Drawing.Size(245, 83); + this.listviewBinaries.TabIndex = 0; + this.listviewBinaries.UseCompatibleStateImageBehavior = false; + this.listviewBinaries.View = System.Windows.Forms.View.Details; + this.listviewBinaries.SelectedIndexChanged += new System.EventHandler(this.listviewBinaries_SelectedIndexChanged); + // + // colhdrVersion + // + this.colhdrVersion.Text = "Version"; + // + // colhdrBinary + // + this.colhdrBinary.Text = "Binary"; + this.colhdrBinary.Width = 198; + // + // textboxBinary + // + this.textboxBinary.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.textboxBinary.Enabled = false; + this.textboxBinary.Location = new System.Drawing.Point(84, 161); + this.textboxBinary.Name = "textboxBinary"; + this.textboxBinary.Size = new System.Drawing.Size(93, 21); + this.textboxBinary.TabIndex = 4; + this.textboxBinary.TextChanged += new System.EventHandler(this.textboxBinary_TextChanged); + // + // btnAdd + // + this.btnAdd.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.btnAdd.Location = new System.Drawing.Point(51, 104); + this.btnAdd.Name = "btnAdd"; + this.btnAdd.Size = new System.Drawing.Size(98, 25); + this.btnAdd.TabIndex = 1; + this.btnAdd.Text = "&Add"; + this.btnAdd.UseVisualStyleBackColor = true; + this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click); + // + // btnDel + // + this.btnDel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.btnDel.Enabled = false; + this.btnDel.Location = new System.Drawing.Point(155, 104); + this.btnDel.Name = "btnDel"; + this.btnDel.Size = new System.Drawing.Size(98, 25); + this.btnDel.TabIndex = 2; + this.btnDel.Text = "&Delete"; + this.btnDel.UseVisualStyleBackColor = true; + this.btnDel.Click += new System.EventHandler(this.btnDel_Click); + // + // label5 + // + this.label5.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.label5.AutoSize = true; + this.label5.Location = new System.Drawing.Point(6, 138); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(51, 15); + this.label5.TabIndex = 2; + this.label5.Text = "Version:"; + // + // label7 + // + this.label7.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.label7.AutoSize = true; + this.label7.Location = new System.Drawing.Point(6, 164); + this.label7.Name = "label7"; + this.label7.Size = new System.Drawing.Size(44, 15); + this.label7.TabIndex = 3; + this.label7.Text = "Binary:"; + // + // btnBrowse + // + this.btnBrowse.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.btnBrowse.Enabled = false; + this.btnBrowse.Location = new System.Drawing.Point(183, 161); + this.btnBrowse.Name = "btnBrowse"; + this.btnBrowse.Size = new System.Drawing.Size(68, 21); + this.btnBrowse.TabIndex = 5; + this.btnBrowse.Text = "&Browse..."; + this.btnBrowse.UseVisualStyleBackColor = true; + this.btnBrowse.Click += new System.EventHandler(this.btnBrowse_Click); + // + // textboxVersion + // + this.textboxVersion.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.textboxVersion.Enabled = false; + this.textboxVersion.Location = new System.Drawing.Point(84, 135); + this.textboxVersion.Name = "textboxVersion"; + this.textboxVersion.Size = new System.Drawing.Size(167, 21); + this.textboxVersion.TabIndex = 3; + this.textboxVersion.TextChanged += new System.EventHandler(this.textboxVersion_TextChanged); + // + // openFileDialog1 + // + this.openFileDialog1.DefaultExt = "exe"; + this.openFileDialog1.Filter = "Executable files|*.exe|All files|*.*"; + // + // tabControl1 + // + this.tabControl1.Controls.Add(this.tabPage1); + this.tabControl1.Controls.Add(this.tabPage2); + this.tabControl1.Location = new System.Drawing.Point(12, 12); + this.tabControl1.Name = "tabControl1"; + this.tabControl1.SelectedIndex = 0; + this.tabControl1.Size = new System.Drawing.Size(332, 507); + this.tabControl1.TabIndex = 7; + // + // tabPage1 + // + this.tabPage1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(212)))), ((int)(((byte)(204)))), ((int)(((byte)(187))))); + this.tabPage1.Controls.Add(this.panel3); + this.tabPage1.Location = new System.Drawing.Point(4, 24); + this.tabPage1.Name = "tabPage1"; + this.tabPage1.Padding = new System.Windows.Forms.Padding(3); + this.tabPage1.Size = new System.Drawing.Size(324, 479); + this.tabPage1.TabIndex = 0; + this.tabPage1.Text = "SRB2"; + // + // tabPage2 + // + this.tabPage2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(212)))), ((int)(((byte)(204)))), ((int)(((byte)(187))))); + this.tabPage2.Controls.Add(this.panel5); + this.tabPage2.Location = new System.Drawing.Point(4, 24); + this.tabPage2.Name = "tabPage2"; + this.tabPage2.Padding = new System.Windows.Forms.Padding(3); + this.tabPage2.Size = new System.Drawing.Size(324, 479); + this.tabPage2.TabIndex = 1; + this.tabPage2.Text = "Master Server"; + // + // panel5 + // + this.panel5.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(212)))), ((int)(((byte)(204)))), ((int)(((byte)(187))))); + this.panel5.Controls.Add(this.panel6); + this.panel5.Controls.Add(this.panel2); + this.panel5.Location = new System.Drawing.Point(6, 6); + this.panel5.Name = "panel5"; + this.panel5.Padding = new System.Windows.Forms.Padding(10); + this.panel5.Size = new System.Drawing.Size(312, 507); + this.panel5.TabIndex = 7; + // + // panel6 + // + this.panel6.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(235)))), ((int)(((byte)(230)))), ((int)(((byte)(217))))); + this.panel6.Controls.Add(this.groupBox2); + this.panel6.Location = new System.Drawing.Point(13, 114); + this.panel6.Name = "panel6"; + this.panel6.Padding = new System.Windows.Forms.Padding(5); + this.panel6.Size = new System.Drawing.Size(286, 61); + this.panel6.TabIndex = 6; + // + // groupBox2 + // + this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.groupBox2.Controls.Add(this.chkShowDefaultWads); + this.groupBox2.Location = new System.Drawing.Point(9, 8); + this.groupBox2.Name = "groupBox2"; + this.groupBox2.Size = new System.Drawing.Size(269, 45); + this.groupBox2.TabIndex = 0; + this.groupBox2.TabStop = false; + this.groupBox2.Text = "List Settings"; + // + // chkShowDefaultWads + // + this.chkShowDefaultWads.AutoSize = true; + this.chkShowDefaultWads.Location = new System.Drawing.Point(6, 20); + this.chkShowDefaultWads.Name = "chkShowDefaultWads"; + this.chkShowDefaultWads.Size = new System.Drawing.Size(201, 19); + this.chkShowDefaultWads.TabIndex = 8; + this.chkShowDefaultWads.Text = "Show default files in list of wads"; + this.chkShowDefaultWads.UseVisualStyleBackColor = true; + // + // chkCloseOnStart + // + this.chkCloseOnStart.AutoSize = true; + this.chkCloseOnStart.Location = new System.Drawing.Point(9, 47); + this.chkCloseOnStart.Name = "chkCloseOnStart"; + this.chkCloseOnStart.Size = new System.Drawing.Size(216, 19); + this.chkCloseOnStart.TabIndex = 9; + this.chkCloseOnStart.Text = "Close Launcher when SRB2 starts"; + this.chkCloseOnStart.UseVisualStyleBackColor = true; + // + // Options + // + this.AcceptButton = this.btnSave; + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(235)))), ((int)(((byte)(230)))), ((int)(((byte)(217))))); + this.ClientSize = new System.Drawing.Size(356, 560); + this.Controls.Add(this.tabControl1); + this.Controls.Add(this.btnSave); + this.Controls.Add(this.btnCancel); + this.Font = new System.Drawing.Font("Arial", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow; + this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); + this.Name = "Options"; + this.Text = "Options"; + this.groupDisplay.ResumeLayout(false); + this.groupDisplay.PerformLayout(); + this.panel1.ResumeLayout(false); + this.panel2.ResumeLayout(false); + this.groupMS.ResumeLayout(false); + this.groupMS.PerformLayout(); + this.panel3.ResumeLayout(false); + this.panel7.ResumeLayout(false); + this.groupBox3.ResumeLayout(false); + this.groupBox3.PerformLayout(); + this.panel4.ResumeLayout(false); + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); + this.tabControl1.ResumeLayout(false); + this.tabPage1.ResumeLayout(false); + this.tabPage2.ResumeLayout(false); + this.panel5.ResumeLayout(false); + this.panel6.ResumeLayout(false); + this.groupBox2.ResumeLayout(false); + this.groupBox2.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.GroupBox groupDisplay; + private System.Windows.Forms.Panel panel1; + private System.Windows.Forms.CheckBox chkDisplayWindowed; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.TextBox txtWidth; + private System.Windows.Forms.CheckBox chkCustomResolution; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.TextBox txtHeight; + private System.Windows.Forms.Button btnCancel; + private System.Windows.Forms.Button btnSave; + private System.Windows.Forms.Panel panel2; + private System.Windows.Forms.GroupBox groupMS; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.TextBox txtMSAddress; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.TextBox txtMSPort; + private System.Windows.Forms.Panel panel3; + private System.Windows.Forms.OpenFileDialog openFileDialog1; + private System.Windows.Forms.Panel panel4; + private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.ListView listviewBinaries; + private System.Windows.Forms.ColumnHeader colhdrVersion; + private System.Windows.Forms.ColumnHeader colhdrBinary; + private System.Windows.Forms.TextBox textboxBinary; + private System.Windows.Forms.Button btnAdd; + private System.Windows.Forms.Button btnDel; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.Label label7; + private System.Windows.Forms.Button btnBrowse; + private System.Windows.Forms.TextBox textboxVersion; + private System.Windows.Forms.TabControl tabControl1; + private System.Windows.Forms.TabPage tabPage1; + private System.Windows.Forms.TabPage tabPage2; + private System.Windows.Forms.Panel panel5; + private System.Windows.Forms.Panel panel6; + private System.Windows.Forms.GroupBox groupBox2; + private System.Windows.Forms.CheckBox chkShowDefaultWads; + private System.Windows.Forms.Panel panel7; + private System.Windows.Forms.GroupBox groupBox3; + private System.Windows.Forms.TextBox txtParams; + private System.Windows.Forms.Label label9; + private System.Windows.Forms.CheckBox chkCloseOnStart; + } +} \ No newline at end of file diff --git a/tools/SRB2Updater/Options.cs b/tools/SRB2Updater/Options.cs new file mode 100644 index 000000000..a45cb13af --- /dev/null +++ b/tools/SRB2Updater/Options.cs @@ -0,0 +1,134 @@ +using System; +using System.Collections.Generic; +using System.Collections; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Text; +using System.Windows.Forms; +using System.IO; + +namespace SRB2Updater +{ + public partial class Options : Form + { + private Settings settings; + public Options(Settings settings) + { + InitializeComponent(); + this.settings = settings; + SetOptions(); + } + + private void SetOptions() + { + chkDisplayWindowed.Checked = settings.displayWindowed; + chkCustomResolution.Checked = settings.displayCustom; + txtHeight.Text = settings.displayHeight.ToString(); + txtWidth.Text = settings.displayWidth.ToString(); + txtMSPort.Text = settings.msPort.ToString(); + settings.AddBinariesToListView(listviewBinaries); + txtMSAddress.Text = settings.msAddress.ToString(); + txtParams.Text = settings.Params.ToString(); + chkCloseOnStart.Checked = settings.CloseOnStart; + chkShowDefaultWads.Checked = settings.ShowDefaultWads; + if (settings.displayCustom) + { + txtHeight.Enabled = true; + txtWidth.Enabled = true; + } + else + { + txtHeight.Enabled = false; + txtWidth.Enabled = false; + } + } + + private void chkCustomResolution_CheckedChanged(object sender, EventArgs e) + { + if (chkCustomResolution.Checked) + { + txtHeight.Enabled = true; + txtWidth.Enabled = true; + } + else + { + txtHeight.Enabled = false; + txtWidth.Enabled = false; + } + } + + private void btnSave_Click(object sender, EventArgs e) + { + settings.displayCustom = chkCustomResolution.Checked; + settings.displayHeight = Convert.ToInt32(txtHeight.Text); + settings.displayWidth = Convert.ToInt32(txtWidth.Text); + settings.displayWindowed = chkDisplayWindowed.Checked; + settings.msAddress = txtMSAddress.Text; + settings.ShowDefaultWads = chkShowDefaultWads.Checked; + settings.Params = txtParams.Text; + settings.msPort = Convert.ToInt32(txtMSPort.Text); + settings.CloseOnStart = chkCloseOnStart.Checked; + settings.SaveSettings(); + settings.SetBinariesFromListView(listviewBinaries); + Close(); + } + + private void btnCancel_Click(object sender, EventArgs e) + { + Close(); + } + + private void btnAdd_Click(object sender, EventArgs e) + { + listviewBinaries.Items.Add(new ListViewItem(new string[] { "[New Version]", "" })); + } + + private void btnDel_Click(object sender, EventArgs e) + { + if (listviewBinaries.SelectedItems.Count > 0) + listviewBinaries.Items.Remove(listviewBinaries.SelectedItems[0]); + } + + private void btnBrowse_Click(object sender, EventArgs e) + { + if (listviewBinaries.SelectedItems.Count > 0 && + openFileDialog1.ShowDialog() == DialogResult.OK) + textboxBinary.Text = openFileDialog1.FileName; + } + + private void textboxVersion_TextChanged(object sender, EventArgs e) + { + if (listviewBinaries.SelectedItems.Count > 0) + listviewBinaries.SelectedItems[0].Text = textboxVersion.Text; + } + + private void textboxBinary_TextChanged(object sender, EventArgs e) + { + if (listviewBinaries.SelectedItems.Count > 0) + listviewBinaries.SelectedItems[0].SubItems[1].Text = textboxBinary.Text; + } + + private void listviewBinaries_SelectedIndexChanged(object sender, EventArgs e) + { + if (listviewBinaries.SelectedItems.Count > 0) + { + btnDel.Enabled = true; + btnBrowse.Enabled = true; + textboxVersion.Text = listviewBinaries.SelectedItems[0].Text; + textboxBinary.Text = listviewBinaries.SelectedItems[0].SubItems[1].Text; + textboxVersion.Enabled = true; + textboxBinary.Enabled = true; + } + else + { + btnDel.Enabled = false; + btnBrowse.Enabled = false; + textboxVersion.Text = ""; + textboxBinary.Text = ""; + textboxVersion.Enabled = false; + textboxBinary.Enabled = false; + } + } + } +} diff --git a/tools/SRB2Updater/Options.resx b/tools/SRB2Updater/Options.resx new file mode 100644 index 000000000..ee0d50c3f --- /dev/null +++ b/tools/SRB2Updater/Options.resx @@ -0,0 +1,166 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + + + + AAABAAEAICAAAAEACACoCAAAFgAAACgAAAAgAAAAQAAAAAEACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAADg4OAIAAAABQABkAlgAAALkAAABQGQAAcwAlAJYAMQBzJQAAuQA9AJYxAACWAGIAMjIyALk9 + AAD/JSUAPj4+AFZWVgD/SEgAYmJiAABilgBubm4Aenp6AP9rawCAgIAAhoaGAJKSkgD/jo4Anp6eAKSg + oAD/jqsAqqqqAGuP/wC2trYAwMDAAI6r/wDCwsIAa8b/AM7OzgCO1P8A2traAObm5gDy8vIA////AAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAGgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFQ8PHQAAAAAAAAAAAAAAACMgJSUlJSUZ + AAAAABMNBgoPDw8AAAAAAAAAAAAAACInJycnJycnJyclFgYGBggPDw8PDwAAAAAAAAAAAAAjJycnJycn + JycnGScnFQkGCA8PDw8AAAAAAAAAAAAAISMnJycjIyMjJycnJycVDwYGDw8PDwAAAAAAAAAAAAAQAAEj + HygqKSkkHyMnJwoPDwYJDw8PAAAAAAAAAAAAACkTHxwrKysrKysrGhkMDw8PCwYJDw8AAAAAAAAAACkp + JA0pACkrKysrKyspDw8PDw8PAwYIAAAAAAAAAAAAACsiARwAISsrKysrKysSDw8PDw8PAwYAAAAAAAAA + AAAAKyIAEAAfKysrKysrKxcPDw8PDw8PDwgIABYAABcSCAArKAMPACIrKysrKysrGw8PDw8PDw8PDw8P + Dw8PDw8RACsoBA8EISsrKysrKyseDw8PDw8PDw8PDw8PDw8PDwAAKx8PDw8VKSsrKysrKxcPDw8PDw8P + Dw8PDw8PDw8AACooFQ8PDw8aKCsrKysmDw8PDw8PDw8PDw8PDw8PFQAAAAAKDw8PDw8VIigoIgoPDw8P + Dw8PDw8PDw8PDxEAAAAAAAoPDw8PDw8XFxcXEhIPDwUPDw8PDw8PDw8YAAAAAAAACA8PDw8SFxcXFxcX + FxcPFQ8PDw8PDw8KAAAAAAAAAAAACg8PEhcXFxcXFxcXFxkjBRISEhISGAAAAAAAAAAAIRcXCA8XFxcX + FxcXFxcaJyMFDwoLEQAAAAAAAAAAAAAAFxcSDxIXFxcXFxcSEyAlIwILCwsIAAAAAAAAAAAAABcXEg8A + EhIXFxcXEgoPDBUUBwsLCwsLAAAAAAAAAAAAFxcAAAAAFxIXFxcXFxIKDw8ICwsLDg4LAAAAAAAAAAAA + AAAAAAAAABISFxcXFw8PDw8PDw8PDwAAAAAAAAAAAAAAAAAAAAAAAAASEhcSDw8PDw8PDxIAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAFwoSDw8SFwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAP///////////////////3////w//APAf/AAAH/gAAD/wAAA/8AAAP/AAAD/AAAB/4AA + Af+AAABYgAAAAIAAAAGAAAADAAAAA8AAAAfAAAAPwAAAP+AAAH+AAAH/wAAB/4QAAP+eAAB//4AA///g + Af//+A////////////////// + + + \ No newline at end of file diff --git a/tools/SRB2Updater/Program.cs b/tools/SRB2Updater/Program.cs new file mode 100644 index 000000000..51c0be56e --- /dev/null +++ b/tools/SRB2Updater/Program.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Windows.Forms; + +namespace SRB2Updater +{ + static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main(string[] args) + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Launcher(args)); + } + } +} diff --git a/tools/SRB2Updater/Properties/AssemblyInfo.cs b/tools/SRB2Updater/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..abc46e8cd --- /dev/null +++ b/tools/SRB2Updater/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Resources; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("SRB2 Automatic Updater")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Sonic Team Junior")] +[assembly: AssemblyProduct("Sonic Robo Blast 2")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("94c164ce-02a9-4966-948f-004d35760ba1")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: NeutralResourcesLanguageAttribute("en-US")] diff --git a/tools/SRB2Updater/Properties/Resources.Designer.cs b/tools/SRB2Updater/Properties/Resources.Designer.cs new file mode 100644 index 000000000..246c91e52 --- /dev/null +++ b/tools/SRB2Updater/Properties/Resources.Designer.cs @@ -0,0 +1,132 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:2.0.50727.4927 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace SRB2Updater.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "2.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SRB2Updater.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + internal static System.Drawing.Bitmap Banner { + get { + object obj = ResourceManager.GetObject("Banner", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + internal static System.Drawing.Bitmap Banner2 { + get { + object obj = ResourceManager.GetObject("Banner2", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + internal static System.Drawing.Bitmap Banner3 { + get { + object obj = ResourceManager.GetObject("Banner3", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + internal static System.Drawing.Bitmap Banner4 { + get { + object obj = ResourceManager.GetObject("Banner4", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + internal static System.Drawing.Bitmap CONSBACK { + get { + object obj = ResourceManager.GetObject("CONSBACK", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + internal static System.IO.UnmanagedMemoryStream Kotaku { + get { + return ResourceManager.GetStream("Kotaku", resourceCulture); + } + } + + internal static System.Drawing.Bitmap Sonic { + get { + object obj = ResourceManager.GetObject("Sonic", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + internal static System.Drawing.Bitmap sonic_bottom { + get { + object obj = ResourceManager.GetObject("sonic_bottom", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + internal static System.Drawing.Bitmap sonic_top { + get { + object obj = ResourceManager.GetObject("sonic_top", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + internal static System.Drawing.Bitmap updaterbanner { + get { + object obj = ResourceManager.GetObject("updaterbanner", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + } +} diff --git a/tools/SRB2Updater/Properties/Resources.resx b/tools/SRB2Updater/Properties/Resources.resx new file mode 100644 index 000000000..b5c93d021 --- /dev/null +++ b/tools/SRB2Updater/Properties/Resources.resx @@ -0,0 +1,151 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + ..\Resources\CONSBACK.bmp;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\Sonic.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\Banner.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\sonic_bottom.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\sonic_top.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\updaterbanner.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\Banner2.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\Banner3.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\Banner4.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\Kotaku.wav;System.IO.MemoryStream, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/tools/SRB2Updater/Properties/Settings.Designer.cs b/tools/SRB2Updater/Properties/Settings.Designer.cs new file mode 100644 index 000000000..4e8aea28c --- /dev/null +++ b/tools/SRB2Updater/Properties/Settings.Designer.cs @@ -0,0 +1,26 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:2.0.50727.3506 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace SRB2Updater.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "9.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + } +} diff --git a/tools/SRB2Updater/Properties/Settings.settings b/tools/SRB2Updater/Properties/Settings.settings new file mode 100644 index 000000000..abf36c5d3 --- /dev/null +++ b/tools/SRB2Updater/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/tools/SRB2Updater/Resources/Banner.png b/tools/SRB2Updater/Resources/Banner.png new file mode 100644 index 000000000..7d8d55602 Binary files /dev/null and b/tools/SRB2Updater/Resources/Banner.png differ diff --git a/tools/SRB2Updater/Resources/Banner.psd b/tools/SRB2Updater/Resources/Banner.psd new file mode 100644 index 000000000..eb29b8b6f Binary files /dev/null and b/tools/SRB2Updater/Resources/Banner.psd differ diff --git a/tools/SRB2Updater/Resources/Banner2.png b/tools/SRB2Updater/Resources/Banner2.png new file mode 100644 index 000000000..f3d3d3e6d Binary files /dev/null and b/tools/SRB2Updater/Resources/Banner2.png differ diff --git a/tools/SRB2Updater/Resources/Banner3.png b/tools/SRB2Updater/Resources/Banner3.png new file mode 100644 index 000000000..04713070a Binary files /dev/null and b/tools/SRB2Updater/Resources/Banner3.png differ diff --git a/tools/SRB2Updater/Resources/Banner4.png b/tools/SRB2Updater/Resources/Banner4.png new file mode 100644 index 000000000..8b2627b8d Binary files /dev/null and b/tools/SRB2Updater/Resources/Banner4.png differ diff --git a/tools/SRB2Updater/Resources/CONSBACK.bmp b/tools/SRB2Updater/Resources/CONSBACK.bmp new file mode 100644 index 000000000..3c1298f08 Binary files /dev/null and b/tools/SRB2Updater/Resources/CONSBACK.bmp differ diff --git a/tools/SRB2Updater/Resources/Kotaku.wav b/tools/SRB2Updater/Resources/Kotaku.wav new file mode 100644 index 000000000..49e7f613a Binary files /dev/null and b/tools/SRB2Updater/Resources/Kotaku.wav differ diff --git a/tools/SRB2Updater/Resources/Sonic.png b/tools/SRB2Updater/Resources/Sonic.png new file mode 100644 index 000000000..a19cf225d Binary files /dev/null and b/tools/SRB2Updater/Resources/Sonic.png differ diff --git a/tools/SRB2Updater/Resources/Srb2win.ico b/tools/SRB2Updater/Resources/Srb2win.ico new file mode 100644 index 000000000..0036a827a Binary files /dev/null and b/tools/SRB2Updater/Resources/Srb2win.ico differ diff --git a/tools/SRB2Updater/Resources/sonic_bottom.png b/tools/SRB2Updater/Resources/sonic_bottom.png new file mode 100644 index 000000000..42c17c785 Binary files /dev/null and b/tools/SRB2Updater/Resources/sonic_bottom.png differ diff --git a/tools/SRB2Updater/Resources/sonic_top.png b/tools/SRB2Updater/Resources/sonic_top.png new file mode 100644 index 000000000..66d6fccaa Binary files /dev/null and b/tools/SRB2Updater/Resources/sonic_top.png differ diff --git a/tools/SRB2Updater/Resources/updaterbanner.png b/tools/SRB2Updater/Resources/updaterbanner.png new file mode 100644 index 000000000..9a2f6fa38 Binary files /dev/null and b/tools/SRB2Updater/Resources/updaterbanner.png differ diff --git a/tools/SRB2Updater/SRB2Updater.csproj b/tools/SRB2Updater/SRB2Updater.csproj new file mode 100644 index 000000000..6e8647312 --- /dev/null +++ b/tools/SRB2Updater/SRB2Updater.csproj @@ -0,0 +1,173 @@ + + + Debug + AnyCPU + 9.0.21022 + 2.0 + {2E2F67C6-8492-4034-A142-50872504D86D} + WinExe + Properties + SRB2Updater + srb2update + + + + + 2.0 + v2.0 + + + false + Srb2win.ico + SRB2Updater.Program + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + Form + + + Debug.cs + + + Form + + + Launcher.cs + + + + Form + + + Options.cs + + + + + Debug.cs + Designer + + + Launcher.cs + Designer + + + Options.cs + Designer + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + True + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + False + .NET Framework Client Profile + false + + + False + .NET Framework 2.0 %28x86%29 + true + + + False + .NET Framework 3.0 %28x86%29 + false + + + False + .NET Framework 3.5 + false + + + False + .NET Framework 3.5 SP1 + false + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tools/SRB2Updater/SRB2Updater.sln b/tools/SRB2Updater/SRB2Updater.sln new file mode 100644 index 000000000..f4e88dc64 --- /dev/null +++ b/tools/SRB2Updater/SRB2Updater.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual Studio 2008 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SRB2Updater", "SRB2Updater.csproj", "{2E2F67C6-8492-4034-A142-50872504D86D}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {2E2F67C6-8492-4034-A142-50872504D86D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2E2F67C6-8492-4034-A142-50872504D86D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2E2F67C6-8492-4034-A142-50872504D86D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2E2F67C6-8492-4034-A142-50872504D86D}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/tools/SRB2Updater/ServerQuerier.cs b/tools/SRB2Updater/ServerQuerier.cs new file mode 100644 index 000000000..51b6940f6 --- /dev/null +++ b/tools/SRB2Updater/ServerQuerier.cs @@ -0,0 +1,362 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Net; +using System.Net.Sockets; +using System.IO; + +namespace SRB2Updater +{ + class ServerQuerier + { + private UdpClient udpclient; + private IPEndPoint ipepMS; + + private const int MS_HOLEPUNCH_SIZE = 0; + private const int PT_ASKINFO_SIZE = 16; + private const byte PT_ASKINFO = 12; + private const byte PT_SERVERINFO = 13; + private const int MAXSERVERNAME = 32; + private const int MAX_WADPATH = 128; + + /// + /// Constructs a ServerQuerier object. + /// + public ServerQuerier() + { + udpclient = new UdpClient(0, AddressFamily.InterNetwork); + + // Fix for WSAECONNRESET. Only affects Win2k and up. If I send a + // packet to a host which replies with an ICMP Port Unreachable, + // subsequent socket operations go doo-lally. So, we enable the + // older behaviour of ignoring these ICMP messages, since we don't + // care about them anyway. + if (Environment.OSVersion.Platform == PlatformID.Win32NT && + Environment.OSVersion.Version.Major >= 5) + { + const uint IOC_IN = 0x80000000; + const uint IOC_VENDOR = 0x18000000; + const uint SIO_UDP_CONNRESET = IOC_IN | IOC_VENDOR | 12; + + udpclient.Client.IOControl(unchecked((int)SIO_UDP_CONNRESET), new byte[] { Convert.ToByte(false) }, null); + } + } + + public void StartListening(ServerInfoReceiveHandler sirh) + { + // Start listening. + udpclient.BeginReceive(new AsyncCallback(ServerInfoReceiveHandler.Receive), sirh); + } + + + /// + /// Sets the master server address. Necessary before querying via the MS. + /// + /// IP address of hostname of MS. + /// Port of MS. + public void SetMasterServer(string strAddress, ushort unPort) + { + IPAddress address = Dns.GetHostEntry(strAddress).AddressList[0]; + ipepMS = new IPEndPoint(address, unPort); + } + + public void Query(string strAddress, ushort unPort) + { + // Build the packet. + byte[] byPacket = new byte[PT_ASKINFO_SIZE]; + BinaryWriter bw = new BinaryWriter(new MemoryStream(byPacket)); + + bw.Seek(4, SeekOrigin.Begin); // Skip the checksum. + bw.Write((byte)0); // ack + bw.Write((byte)0); // ackreturn + bw.Write((byte)PT_ASKINFO); // Packet type. + bw.Write((byte)0); // Reserved. + bw.Write((byte)0); // Version. This is actually unnecessary -- the client will reply anyway. -MattW_CFI + bw.Write((byte)0); // Reserved. + bw.Write((byte)0); // Reserved. + bw.Write((byte)0); // Reserved. + // Time for ping calculation. + bw.Write(unchecked((uint)(DateTime.Now.Ticks / 10000))); + + // Calculate the checksum. + bw.Seek(0, SeekOrigin.Begin); + bw.Write(SRB2Checksum(byPacket)); + + // Send the packet. + udpclient.Send(byPacket, byPacket.Length, strAddress, unPort); + } + + /// + /// Calculates the checksum of an SRB2 packet. + /// + /// Packet. + /// Checksum. + private static uint SRB2Checksum(byte[] byPacket) + { + uint c = 0x1234567; + int i; + + for (i = 4; i < byPacket.Length; i++) + unchecked + { + c += (uint)byPacket[i] * (uint)(i - 3); + } + + return c; + } + + private static string ReadFixedLengthStr(BinaryReader br, int iLen) + { + String str = Encoding.ASCII.GetString(br.ReadBytes(iLen)); + int iPos = str.IndexOf("\0"); + if (iPos >= 0) + str = str.Remove(iPos); + + return str; + } + + public abstract class ServerInfoReceiveHandler + { + UdpClient udpclient; + IPEndPoint ipepRemote; + + /// + /// Called after a server info packet is received. + /// + /// Server info. + public abstract void ProcessServerInfo(SRB2ServerInfo srb2si); + public abstract void HandleException(Exception e); + + public ServerInfoReceiveHandler(ServerQuerier sq) + { + ipepRemote = new IPEndPoint(IPAddress.Any, 0); + + udpclient = sq.udpclient; + } + + public static void Receive(IAsyncResult ar) + { + ServerInfoReceiveHandler sirh = (ServerInfoReceiveHandler)ar.AsyncState; + + byte[] byPacket = sirh.udpclient.EndReceive(ar, ref sirh.ipepRemote); + + // Analyse the packet. + BinaryReader br = new BinaryReader(new MemoryStream(byPacket)); + + // Get the checksum. + uint uiChecksum = br.ReadUInt32(); + + // Skip ack and ackreturn and get packet type. + br.ReadBytes(2); + byte byPacketType = br.ReadByte(); + + // Only interested in valid PT_SERVERINFO packets. + if (byPacketType == PT_SERVERINFO && uiChecksum == SRB2Checksum(byPacket)) + { + bool bMalformed = true; + + // Skip padding. + br.ReadByte(); + + // Remember where we are. + long iPacketStart = br.BaseStream.Position; + + // Try to interpret the packet in each recognised format. + foreach (ServerInfoVer siv in Enum.GetValues(typeof(ServerInfoVer))) + { + SRB2ServerInfo srb2si; + byte byNumWads = 0; + + srb2si.siv = siv; + + br.BaseStream.Position = iPacketStart; + + // Get address from socket. + srb2si.strAddress = sirh.ipepRemote.Address.ToString(); + srb2si.unPort = unchecked((ushort)sirh.ipepRemote.Port); + + // Get version. + byte byVersion = br.ReadByte(); + + if (siv == ServerInfoVer.SIV_PREME) + { + br.ReadBytes(3); + + uint uiSubVersion = br.ReadUInt32(); + + // Format version. + // MattW_CFI: I hope you don't mind this exception, Oogaland, but 0.01.6 looks odd >_> + if (byVersion == 1 && uiSubVersion == 6) + srb2si.strVersion = "X.01.6"; + else + srb2si.strVersion = byVersion.ToString(); + //srb2si.strVersion = String.Format("{0}.{1:00}.{2}", byVersion / 100, byVersion % 100, uiSubVersion); + } + else + { + byte bySubVersion = br.ReadByte(); + + // Format version. + //srb2si.strVersion = String.Format("{0}.{1:00}.{2}", byVersion / 100, byVersion % 100, bySubVersion); + srb2si.strVersion = byVersion.ToString(); + } + + srb2si.byPlayers = br.ReadByte(); + srb2si.byMaxplayers = br.ReadByte(); + srb2si.byGametype = br.ReadByte(); + srb2si.bModified = (br.ReadByte() != 0); + + if (siv == ServerInfoVer.SIV_ME) + byNumWads = br.ReadByte(); + + srb2si.sbyAdminplayer = br.ReadSByte(); + + if (siv == ServerInfoVer.SIV_PREME) + br.ReadBytes(3); + + // Calculate ping. + srb2si.uiTime = unchecked((uint)((long)(DateTime.Now.Ticks / 10000 - br.ReadUInt32()) % ((long)UInt32.MaxValue + 1))); + + if (siv == ServerInfoVer.SIV_PREME) + br.ReadUInt32(); + + // Get and tidy map name. + if (siv == ServerInfoVer.SIV_PREME) + { + srb2si.strMapName = ReadFixedLengthStr(br, 8); + srb2si.strName = ReadFixedLengthStr(br, MAXSERVERNAME); + } + else + { + srb2si.strName = ReadFixedLengthStr(br, MAXSERVERNAME); + srb2si.strMapName = ReadFixedLengthStr(br, 8); + } + + if (siv == ServerInfoVer.SIV_PREME) + byNumWads = br.ReadByte(); + + // Create new list of strings of initial size equal to number of wads. + srb2si.listFiles = new List(byNumWads); + + // Get the files info. + byte[] byFiles = br.ReadBytes(siv == ServerInfoVer.SIV_PREME ? 4096 : 936); + BinaryReader brFiles = new BinaryReader(new MemoryStream(byFiles)); + + // Extract the filenames. + try + { + for (int i = 0; i < byNumWads; i++) + { + bool bFullString = false; + AddedWad aw = new AddedWad(); + + if (siv == ServerInfoVer.SIV_PREME) + { + aw.bImportant = brFiles.ReadByte() != 0; + aw.downloadtype = (DownloadTypes)brFiles.ReadByte(); + } + else + { + byte byFileStatus = brFiles.ReadByte(); + aw.bImportant = (byFileStatus & 0xF) != 0; + aw.downloadtype = (DownloadTypes)(byFileStatus >> 4); + } + + aw.uiSize = brFiles.ReadUInt32(); + + // Work out how long the string is. + int iStringPos = (int)brFiles.BaseStream.Position; + while (iStringPos < byFiles.Length && byFiles[iStringPos] != 0) iStringPos++; + + // Make sure it's not longer than the max name length. + if (iStringPos - (int)brFiles.BaseStream.Position > MAX_WADPATH) + { + bFullString = true; + iStringPos = MAX_WADPATH + (int)brFiles.BaseStream.Position; + } + + // Get the info and add it, if possible. + if (iStringPos > (int)brFiles.BaseStream.Position) + { + aw.strFilename = Encoding.ASCII.GetString(brFiles.ReadBytes(iStringPos - (int)brFiles.BaseStream.Position)); + srb2si.listFiles.Add(aw); + } + + // Skip nul. + if (!bFullString) brFiles.ReadByte(); + + // Skip the md5sum. + brFiles.ReadBytes(16); + } + + // Okay, done! Do something useful with the server info. + sirh.ProcessServerInfo(srb2si); + + // If we got this far without an exception, leave the foreach loop. + bMalformed = false; + break; + } + catch (EndOfStreamException) + { + // Packet doesn't match supposed type, so we swallow the exception + // and try remaining types. + } + catch (Exception e) + { + sirh.HandleException(e); + break; + } + } + + if (bMalformed) + sirh.HandleException(new Exception("Received invalid PT_SERVERINFO packet from " + sirh.ipepRemote.Address + ":" + sirh.ipepRemote.Port + ".")); + } + + // Resume listening. + sirh.ipepRemote = new IPEndPoint(IPAddress.Any, 0); + sirh.udpclient.BeginReceive(new AsyncCallback(Receive), sirh); + } + } + + public enum DownloadTypes + { + DT_TOOBIG = 0, + DT_OK = 1, + DT_DISABLED = 2 + } + + public struct AddedWad + { + public string strFilename; + public bool bImportant; + public uint uiSize; + public DownloadTypes downloadtype; + } + + public enum ServerInfoVer + { + SIV_PREME, + SIV_ME + }; + + public struct SRB2ServerInfo + { + public string strAddress; + public ushort unPort; + + public ServerInfoVer siv; + + public string strVersion; + public byte byPlayers; + public byte byMaxplayers; + public byte byGametype; + public bool bModified; + public sbyte sbyAdminplayer; + public uint uiTime; + public string strMapName; + public string strName; + + public List listFiles; + } + } +} diff --git a/tools/SRB2Updater/Settings.cs b/tools/SRB2Updater/Settings.cs new file mode 100644 index 000000000..d72aeee51 --- /dev/null +++ b/tools/SRB2Updater/Settings.cs @@ -0,0 +1,219 @@ +using System; +using System.Collections.Generic; +using System.Collections; +using System.Text; +using System.Data; +using Microsoft.Win32; +using System.Windows.Forms; +using System.IO; + +namespace SRB2Updater +{ + public class Settings + { + // Global Settings + public bool boolDisplayWindowed; + public bool boolDisplayCustomResolution; + public bool boolCloseOnStart; + public int intDisplayWidth; + public int intDisplayHeight; + public string strMSAddress; + public int intMSPort; + public Array arrWadList; + public string strParams; + + public string Params + { + get { return strParams; } + set { strParams = value; } + } + + public Array wadList + { + get { return arrWadList; } + set { arrWadList = value; } + } + + public bool CloseOnStart + { + get { return boolCloseOnStart; } + set { boolCloseOnStart = value; } + } + + public string msAddress + { + get { return strMSAddress; } + set { strMSAddress = value; } + } + + public int msPort + { + get { return intMSPort; } + set { intMSPort = value; } + } + + public bool displayWindowed + { + get { return boolDisplayWindowed; } + set { boolDisplayWindowed = value; } + } + + public bool displayCustom + { + get { return boolDisplayCustomResolution; } + set { boolDisplayCustomResolution = value; } + } + + public int displayWidth + { + get { return intDisplayWidth; } + set { intDisplayWidth = value; } + } + + public int displayHeight + { + get { return intDisplayHeight; } + set { intDisplayHeight = value; } + } + + bool boolShowDefaultWads; + public bool ShowDefaultWads + { + get { return boolShowDefaultWads; } + set { boolShowDefaultWads = value; } + } + + public void GetSettings() + { + RegistryKey rk = Registry.CurrentUser.CreateSubKey(@"Software\SonicTeamJunior\Launcher"); + RegistryKey rkDisplay = Registry.CurrentUser.CreateSubKey(@"Software\SonicTeamJunior\Launcher\Display"); + RegistryKey rkMS = Registry.CurrentUser.CreateSubKey(@"Software\SonicTeamJunior\Launcher\MasterServer"); + RegistryKey rkBinaries = rk.CreateSubKey("Binaries"); + rkBinaries.SetValue("2.0.4", Directory.GetCurrentDirectory() + "\\srb2win.exe"); + + try { boolDisplayCustomResolution = Convert.ToInt32(rkDisplay.GetValue("CustomResolution", 0)) != 0; } + catch { boolDisplayCustomResolution = false; } + try { boolDisplayWindowed = Convert.ToInt32(rkDisplay.GetValue("Windowed", 0)) != 0; } + catch { boolDisplayWindowed = false; } + try { boolShowDefaultWads = Convert.ToInt32(rkDisplay.GetValue("ShowDefaultWads", 0)) != 0; } + catch { boolShowDefaultWads = false; } + try { boolCloseOnStart = Convert.ToInt32(rkDisplay.GetValue("CloseOnStart", 0)) != 0; } + catch { boolCloseOnStart = false; } + intDisplayHeight = Convert.ToInt32(rkDisplay.GetValue("Height", "480")); + intDisplayWidth = Convert.ToInt32(rkDisplay.GetValue("Width", "640")); + intMSPort = Convert.ToInt32(rkMS.GetValue("Port", "28900")); + strMSAddress = Convert.ToString(rkMS.GetValue("Address", "ms.srb2.org")); + strParams = Convert.ToString(rk.GetValue("Params")); + + dicBinaries.Clear(); + foreach (string strName in rkBinaries.GetValueNames()) + dicBinaries[strName] = (string)rkBinaries.GetValue(strName); + + + rk.Close(); + rkDisplay.Close(); + rkMS.Close(); + rkBinaries.Close(); + } + + public void SaveSettings() + { + RegistryKey rk = Registry.CurrentUser.CreateSubKey(@"Software\SonicTeamJunior\Launcher"); + RegistryKey rkDisplay = rk.CreateSubKey("Display"); + RegistryKey rkMS = rk.CreateSubKey("MasterServer"); + rkDisplay.SetValue("CustomResolution", boolDisplayCustomResolution); + rkDisplay.SetValue("Windowed", boolDisplayWindowed); + rkDisplay.SetValue("Height", intDisplayHeight); + rkDisplay.SetValue("Width", intDisplayWidth); + rkMS.SetValue("Port", intMSPort); + rkMS.SetValue("Address", strMSAddress); + rkMS.SetValue("ShowDefaultWads", boolShowDefaultWads); + rk.SetValue("Params", strParams); + rk.SetValue("CloseOnStart", boolCloseOnStart); + + rk.DeleteSubKey("Binaries", false); + RegistryKey rkBinaries = rk.CreateSubKey("Binaries"); + rkBinaries.SetValue("2.0.4", Directory.GetCurrentDirectory() + "\\srb2win.exe"); + foreach (string strName in dicBinaries.Keys) + rkBinaries.SetValue(strName, dicBinaries[strName]); + + rk.Close(); + } + +/* public void WriteToRegistry() + { + RegistryKey rk = Registry.CurrentUser.CreateSubKey(@"Software\SRB2MSLauncher"); + + rk.SetValue("Params", strParams); + rk.SetValue("Masterserver", strMSAddress); + rk.SetValue("MSPort", unMSPort, RegistryValueKind.DWord); + rk.SetValue("ShowDefaultWads", Convert.ToInt32(bShowDefaultWads), RegistryValueKind.DWord); + + rk.DeleteSubKey("Binaries", false); + RegistryKey rkBinaries = rk.CreateSubKey("Binaries"); + foreach (string strName in dicBinaries.Keys) + rkBinaries.SetValue(strName, dicBinaries[strName]); + + rkBinaries.Close(); + rk.Close(); + } + + public void LoadFromRegistry() + { + RegistryKey rk = Registry.CurrentUser.CreateSubKey(@"Software\SRB2MSLauncher"); + RegistryKey rkBinaries = rk.CreateSubKey("Binaries"); + + strParams = (string)rk.GetValue("Params", ""); + strMSAddress = (string)rk.GetValue("Masterserver", "ms.srb2.org"); + + try { unMSPort = Convert.ToUInt16(rk.GetValue("MSPort", MS_DEFAULT_PORT)); } + catch { unMSPort = MS_DEFAULT_PORT; } + + try { bShowDefaultWads = Convert.ToInt32(rk.GetValue("ShowDefaultWads", 0)) != 0; } + catch { bShowDefaultWads = true; } + + dicBinaries.Clear(); + foreach (string strName in rkBinaries.GetValueNames()) + dicBinaries[strName] = (string)rkBinaries.GetValue(strName); + + rkBinaries.Close(); + rk.Close(); + }*/ + + + public List VersionStrings + { + get { return new List(dicBinaries.Keys); } + } + + public bool HasBinaryForVersion(string strVersion) + { + return dicBinaries.ContainsKey(strVersion) && dicBinaries[strVersion] != ""; + } + + public void AddBinariesToListView(ListView lv) + { + foreach (string strName in dicBinaries.Keys) + lv.Items.Add(new ListViewItem(new string[] { strName, dicBinaries[strName] })); + } + + public void SetBinariesFromListView(ListView lv) + { + dicBinaries.Clear(); + foreach (ListViewItem lvi in lv.Items) + dicBinaries[lvi.Text] = lvi.SubItems[1].Text; + } + + Dictionary dicBinaries = new Dictionary(); + + public void SetBinary(string strVersion, string strBinary) + { + dicBinaries[strVersion] = strBinary; + } + + public string GetBinary(string strVersion) + { + return dicBinaries[strVersion]; + } + } +} \ No newline at end of file diff --git a/tools/SRB2Updater/app.config b/tools/SRB2Updater/app.config new file mode 100644 index 000000000..b7db28170 --- /dev/null +++ b/tools/SRB2Updater/app.config @@ -0,0 +1,3 @@ + + + diff --git a/tools/anglechk.c b/tools/anglechk.c new file mode 100644 index 000000000..bb9c4d9ea --- /dev/null +++ b/tools/anglechk.c @@ -0,0 +1,358 @@ +/* + * anglechk.c + * + * Copyright 2007 Alam Arias + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include +#ifdef _MSC_VER +#include +#endif +#define NOASM +#include "../src/tables.h" +#define NO_M +#include "../src/m_fixed.c" +#define FIXEDPOINTCONV + +// With angle_t, +// 360 deg = 2^32 +// 45 deg = 2^29 +// 1 deg = 2^29 / 45 +// To convert an angle to a fixed-point number of degrees, then, use +// fixed = angle * FRACUNIT / ((1<<29) / 45) +// But, done literally like that, this will overflow. +// It's mathematically equivalent to +// fixed = angle * (1<>(29-FRACBITS)) +// fixed = (angle>>(29-FRACBITS)) * 45 + +#define ANGLE_TO_FIXED(a) (fixed_t)(((a)>>(29-FRACBITS))*45) +#define FIXED_TO_ANGLE(x) (angle_t)(((x)/45)<<(29-FRACBITS)) + +/* +Old code that failed if FRACBITS was not 16. +In particular, the use of FRACUNIT in the definition of ANGLE_F is completely +wrong. The value wanted actually happens to be 65536 due to the definition +of angle_t (it's specified so that 360 degrees = 2^32, to take advantage of +modular arithmetic). That 65536 has nothing whatsoever to do with the setting +of FRACUNIT. + +#define ANGF_D 8192 +#define ANGF_N 45 +#define ANGLE_F (ANGF_N*FRACUNIT/ANGF_D) +#define FIXED_TO_ANGLE(x) (angle_t)FixedDiv(x, ANGLE_F) // angle_t = FixedDiv(fixed_t, ANGLE_F) +#define ANGLE_TO_FIXED(x) FixedMul((fixed_t)(x), ANGLE_F) // fixed_t = FixedMul(angle_t, ANGLE_F) +*/ + +static fixed_t AngleFixed204(angle_t af) +{ + const fixed_t cfn = 180*FRACUNIT; + if (af == 0) + return 0; + else if (af > ANGLE_180) + return cfn + ANGLE_TO_FIXED(af - ANGLE_180); + else if (af < ANGLE_180) + return ANGLE_TO_FIXED(af); + else return cfn; +} + +static inline angle_t FixedAngleC204(fixed_t fa, fixed_t factor) +{ +#if 0 //FixedMod off? + const boolean neqda = da < 0, neqfa = fa < 0; + const fixed_t afactor = abs(factor); + angle_t ra = ANGLE_180; + + if (factor == 0) + return FixedAngle204(fa); + else if (fa == 0) + return 0; + + if (neqfactor) + { + const fixed_t maf = FixedDiv(afactor, ANGLE_F); + const fixed_t cfn = FixedMul(360*FRACUNIT, afactor), hcfn = (cfn/2); + const fixed_t fam = FixedMod(fa, cfn); + + if (fam > hcfn) + ra = ANGLE_180 + (angle_t)FixedMul(fam - hcfn, maf); + else if (fam < hcfn) + ra = (angle_t)FixedMul(fam, maf); + } + else + { + const fixed_t maf = FixedMul(afactor, ANGLE_F); + const fixed_t cfn = FixedDiv(360*FRACUNIT, afactor), hcfn = (cfn/2); + const fixed_t fam = FixedMod(fa, cfn); + + if (fam > hcfn) + ra = ANGLE_180 + (angle_t)FixedDiv(fam - hcfn, maf); + else if (fam < hcfn) + ra = (angle_t)FixedDiv(fam, maf); + } + + if (neqfa) + ra = ANGLE_MAX-ra; + + return ra; +#else + if (factor == 0) + return FixedAngle(fa); + else if (factor > 0) + return (angle_t)((FIXED_TO_FLOAT(fa)/FIXED_TO_FLOAT(factor))*(ANGLE_45/45)); + else + return (angle_t)((FIXED_TO_FLOAT(fa)*FIXED_TO_FLOAT(-factor))*(ANGLE_45/45)); +#endif +} + +angle_t FixedAngle(fixed_t fa) +{ +#if 0 //FixedMod off? + const boolean neqfa = fa < 0; + const fixed_t cfn = 180*FRACUNIT; + const fixed_t fam = FixedMod(fa, 360*FRACUNIT); + angle_t ra = ANGLE_180; + + if (fa == 0) + return 0; + + if (fam > cfn) + ra = ANGLE_180+FIXED_TO_ANGLE(fam-cfn); + else if (fam < cfn) + ra = FIXED_TO_ANGLE(fam); + + if (neqfa) + ra = ANGLE_MAX-ra; + + return ra; +#else + return (angle_t)(FIXED_TO_FLOAT(fa)*(ANGLE_45/45)); +#endif +} + +fixed_t AngleFixed205(angle_t af) +{ +#ifdef FIXEDPOINTCONV + angle_t wa = ANGLE_180; + fixed_t wf = 180*FRACUNIT; + fixed_t rf = 0*FRACUNIT; + //const angle_t adj = 0x2000; + + //if (af < adj) // too small to notice + //return rf; + + while (af) + { + while (af < wa) + { + wa /= 2; + wf /= 2; + } + rf += wf; + af -= wa; + } + + return rf; +#else + const fixed_t cfn = 180*FRACUNIT; + if (af == 0) + return 0; + else if (af > ANGLE_180) + return cfn + ANGLE_TO_FIXED(af - ANGLE_180); + else if (af < ANGLE_180) + return ANGLE_TO_FIXED(af); + else return cfn; +#endif +} + +#ifdef FIXEDPOINTCONV +static FUNCMATH angle_t AngleAdj(const fixed_t fa, const fixed_t wf, + angle_t ra) +{ + const angle_t adj = 0x77; + const boolean fan = fa < 0; + const fixed_t sl = FixedDiv(fa, wf*2); + const fixed_t lb = FixedRem(fa, wf*2); + const fixed_t lo = (wf*2)-lb; + + if (ra == 0) + { + if (lb == 0) + { + ra = FixedMul(FRACUNIT/512, sl); + if (ra > FRACUNIT/64) + return ANGLE_MAX-ra+1; + return ra; + } + else if (lb > 0) + return ANGLE_MAX-FixedMul(lo*FRACUNIT, adj)+1; + else + return ANGLE_MAX-FixedMul(lo*FRACUNIT, adj)+1; + } + + if (fan) + return ANGLE_MAX-ra+1; + else + return ra; +} +#endif + +angle_t FixedAngleC205(fixed_t fa, fixed_t factor) +{ +#ifdef FIXEDPOINTCONV + angle_t wa = ANGLE_180; + fixed_t wf = 180*FRACUNIT; + angle_t ra = 0; + const fixed_t cfa = fa; + fixed_t cwf = wf; + + if (fa == 0) + return 0; + + if (factor == 0) + return FixedAngle(fa); + else if (factor > 0) + cwf = wf = FixedMul(wf, factor); + else if (factor < 0) + cwf = wf = FixedDiv(wf, -factor); + + fa = abs(fa); + + while (fa) + { + while (fa < wf) + { + wa /= 2; + wf /= 2; + } + ra = ra + wa; + fa = fa - wf; + } + + return AngleAdj(cfa, cwf, ra); +#else + if (factor == 0) + return FixedAngle(fa); + + //fa = FixedMod(fa, 360*FRACUNIT); + + if (factor > 0) + return (angle_t)((FIXED_TO_FLOAT(fa)/FIXED_TO_FLOAT(factor))*(ANGLE_45/45)); + else + return (angle_t)((FIXED_TO_FLOAT(fa)*FIXED_TO_FLOAT(-factor))*(ANGLE_45/45)); +#endif +} + +angle_t FixedAngle205(fixed_t fa) +{ +#ifdef FIXEDPOINTCONV + angle_t wa = ANGLE_180; + fixed_t wf = 180*FRACUNIT; + angle_t ra = 0; + const fixed_t cfa = fa; + const fixed_t cwf = wf; + + if (fa == 0) + return 0; + + fa = abs(fa); + + while (fa) + { + while (fa < wf) + { + wa /= 2; + wf /= 2; + } + ra = ra + wa; + fa = fa - wf; + } + + return AngleAdj(cfa, cwf, ra); +#else + //fa = FixedMod(fa, 360*FRACUNIT); + + if (fa == 0) + return 0; + + return (angle_t)(FIXED_TO_FLOAT(fa)*(ANGLE_45/45)); +#endif +} + +int main(int argc, char** argv) +{ + fixed_t f, f204, f205; + INT64 a; + angle_t a204, a205; + fixed_t CF = 40*FRACUNIT; + int err = 0; + (void)argc; + (void)argv; + + err = 0x29; //41 + + if (1) + for (a = 0; a < ANGLE_MAX; a += 0x1) + { + f204 = AngleFixed204((angle_t)a); + f205 = AngleFixed205((angle_t)a); + if (f204 != f205 && (abs(f204-f205) > err || f204 == 0 || f205 == 0)) + { + printf("Angle: %u, %d, %d, %d\n", (angle_t)a, f204, f205, f204-f205); + //err = abs(f204-f205); + } + } + + //err = FixedDiv(FRACUNIT, 120*FRACUNIT); // 547 + err = FixedDiv(FRACUNIT, 62*FRACUNIT); //1059 + + if (1) + for (f = FRACUNIT*-720; f < FRACUNIT*720; f += 1) + { + a204 = FixedAngle(f); + a205 = FixedAngle205(f); + if (a204 != a205 && (abs(a204-a205) > err || a204 == 0 || a205 == 0)) + { + printf("Fixed: %f, %u, %u, %d\n", FIXED_TO_FLOAT(f), a204, a205, a204-a205); + err = abs(a204-a205); + } + } + + //err = FixedDiv(FRACUNIT, 316*FRACUNIT); //207 + err = FixedDiv(FRACUNIT, 125*FRACUNIT); //526 + + if (1) + for (f = FixedMul(FRACUNIT*-720, CF); f < FixedMul(FRACUNIT*720, CF); f += FRACUNIT/16) + { + a204 = FixedAngleC204(f, CF); + a205 = FixedAngleC205(f, CF); + if (a204 != a205 && (abs(a204-a205) > err || a204 == 0 || a205 == 0)) + { + printf("FixedC: %f, %u, %u, %d\n", FIXED_TO_FLOAT(f), a204, a205, a204-a205); + //err = abs(a204-a205); + } + } + + return 0; +} + +void I_Error(const char *error, ...) +{ + (void)error; + exit(-1); +} diff --git a/tools/convert.c b/tools/convert.c new file mode 100644 index 000000000..0ab0cb132 --- /dev/null +++ b/tools/convert.c @@ -0,0 +1,35 @@ +// convert corona.raw in a pic_t as corona2.raw + +#include + +typedef struct +{ + short width; + char reserved0; // set to 0 + char mode; // see pic_mode_t above + short height; + short reserved1; // set to 0 +} pic_t; + +void main(int argc, char *argv[]) +{ + int i, j, k; + char buf1[256][256], buf2[256][256][2]; + pic_t pic = {256, 0, 2, 256, 0}; + FILE *g; + + FILE *f = fopen("corona.raw", "rb"); + fread(buf1, 256*256, 1, f); + fclose(f); + + g = fopen("corona2.raw", "wb"); + for (i = 0; i < 256; i++) + for (j = 0; j < 256; j++) + { + buf2[i][j][0] = buf1[i][j]; + buf2[i][j][1] = buf1[i][j]; + } + fwrite(&pic, sizeof (pic_t), 1, g); + fwrite(buf2, sizeof (buf2), 1, g); + fclose(g); +} diff --git a/tools/dircomp2.c b/tools/dircomp2.c new file mode 100644 index 000000000..96a55f36f --- /dev/null +++ b/tools/dircomp2.c @@ -0,0 +1,1028 @@ +//----------------------------------------------------------------------------- +// +// Copyright (C) 1998-2000 by Boris Pereira. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +//----------------------------------------------------------------------------- + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include"keys.h" + + +#define true 1 +#define false 0 + +#define MAXLINE 32768 +#define MAXLENLINE 4096 +#define SCREENWIDTH 80 + +typedef struct { + int lines; + char *line[MAXLINE]; +} textfile_t; + +char tempfilename[255],editor[128]="c:\\program files\\ultraedit\\uedit32.exe"; +int sameline=3,tab1=8,tab2=8; +int screenline=25; +textfile_t f1,f2; +int nonewfile = false; +int compspace = false; + +unsigned short colornormal = ( BLACK<<4) + LIGHTGRAY; +unsigned short colortitle = ( BLACK<<4) + WHITE; +unsigned short colortext = ( BLACK<<4) + DARKGRAY; +unsigned short colordiff = ( BLACK<<4) + LIGHTRED; +unsigned short colorkeys = ( BLACK<<4) + LIGHTCYAN; + + +// compare directorys +void CompareDir(char *dir1,char *dir2); + +// compare directorys this one check only for missing file +void CompareDir2(char *dir1,char *dir2); + +// compare files +void CompareFile(char *filename1,char *filename2); + +// copy a file +void fcopy(char *filename1,char *filename2); + +// recursive delete a dir +void dirunlink(char *dirname); + +// recursive copy a dir +void copydir(char *dirname1,char *dirname2); + +void Quit(char *f,...) +{ + va_list argptr; + + // put message to stderr + va_start (argptr,f); + fprintf (stderr, "Error: "); + vfprintf (stderr,f,argptr); + va_end (argptr); + + fflush( stderr ); + exit(-1); +} + +int CheckParm(int argc, char *argv[], char *param ) +{ + int i; + for(i=1;i []\n\n" + " Options\n" + " -------\n" + " -t1 n : change tab size for directory 1 (default 8)\n" + " -t2 n : change tab size for directory 2 (default 8)\n" + " -l n : use n same line to resynchronize (default 3)\n" + " -e : use spesified editor\n" + " -nonew: don't prompt to copy/delete file\n" + " -w compress space and tab"); + + if(findfirst(argv[1],&dir,FA_DIREC)) + Quit("Error can't find %s\n",argv[1]); + + if(findfirst(argv[2],&dir,FA_DIREC)) + Quit("Error can't find %s\n",argv[2]); + + if(argc>2) + { + i=CheckParm(argc,argv,"-t1"); + if(i) tab1=atoi(argv[i+1]); + i=CheckParm(argc,argv,"-t2"); + if(i) tab2=atoi(argv[i+1]); + i=CheckParm(argc,argv,"-l"); + if(i) sameline=atoi(argv[i+1]); + i=CheckParm(argc,argv,"-e"); + if(i) strcpy(editor,argv[i+1]); + nonewfile=CheckParm(argc,argv,"-nonew"); + compspace=CheckParm(argc,argv,"-w"); + } + + _set_screen_lines(50); + screenline=50; + // desable blink color so we can use darkcolor for background + //outportb(0x3b8,5); + intensevideo(); + + tmp=getenv("temp"); + if(!tmp) + tmp=getenv("TEMP"); + if(!tmp) + tmp=getenv("tmp"); + if(!tmp) + tmp=getenv("TMP"); + if(tmp) + { + strcpy(tempfilename,tmp); + if(tempfilename[strlen(tempfilename)]!='\\') + strcat(tempfilename,"\\"); + } + else + tempfilename[0]='\0'; + strcat(tempfilename,"dircmp$$.tmp"); + + CompareDir(argv[1],argv[2]); + + if(!nonewfile) + // just for file in the directory 2 and not in the 1 + CompareDir2(argv[1],argv[2]); + + return 0; +} + +char *fileextension(char *filename) +{ + static char nullextension=0; + int i; + i = strlen(filename)-1; + while(i>0 && filename[i]!='.') i--; + if( filename[i]=='.' ) + return filename+i+1; + // else + return &nullextension; +} + +void CompareDir(char *dirname1,char *dirname2) +{ + struct ffblk dir; + char filter[20]="\\*.*"; + char tempstr[255]; + int finish; + + strcpy(tempstr,dirname1); + strcat(tempstr,filter); + + printf("Comparing %s and %s\n",dirname2,dirname1); + + // enter in directorys first + finish=findfirst(tempstr,&dir,FA_DIREC); + while(!finish) + { + char tempstr2[255],tempstr3[255]; + + strcpy(tempstr2,dirname1); + strcat(tempstr2,"\\"); + strcat(tempstr2,dir.ff_name); + + strcpy(tempstr3,dirname2); + strcat(tempstr3,"\\"); + strcat(tempstr3,dir.ff_name); + + + if(dir.ff_attrib & FA_DIREC) + { + if(dir.ff_name[0]!='.' && strcmp(dir.ff_name,"CVS")!=0) + { + int check,choice; + check=access(tempstr3,F_OK); + if( check ) + { + printf("\nDirectory missing : %s\n" + "Delete %s ? (Y/N)\n",tempstr3,tempstr2); + do { + choice=getch(); + } while(choice!='y' && choice!='n' + && choice!='Y' && choice!='N'); + + if( choice=='y' || choice=='Y' ) + dirunlink(tempstr2); + } + else + CompareDir(tempstr2,tempstr3); + } + } + finish=findnext(&dir); + } + + finish=findfirst(tempstr,&dir,0); + while(!finish) + { + char tempstr2[255],tempstr3[255]; + + strcpy(tempstr2,dirname1); + strcat(tempstr2,"\\"); + strcat(tempstr2,dir.ff_name); + + strcpy(tempstr3,dirname2); + strcat(tempstr3,"\\"); + strcat(tempstr3,dir.ff_name); + + if((dir.ff_attrib & FA_DIREC)==0) + { + int check; + char *ext; + + ext = fileextension(dir.ff_name); + if( !(stricmp(ext,"dsp")==0 || + stricmp(ext,"dep")==0 || + stricmp(ext,"dsw")==0 || + stricmp(ext,"ncb")==0 || + stricmp(ext,"bmp")==0 || + stricmp(ext,"opt")==0 || + stricmp(ext,"plg")==0 || + stricmp(ext,"ico")==0 || + stricmp(ext,"rc" )==0 || + stricmp(ext,"o" )==0 || + stricmp(ext,"bat")==0 || + stricmp(ext,"obj")==0 )) + { + printf("Comparing %s and %s\n",tempstr2,tempstr3); + check=access(tempstr3,F_OK); + + if(check) + { + // seconde file not found + int choice; + if(!nonewfile) + { + printf("\nFile missing : %s\n" + "Delete %s ? (Y/N)\n",tempstr3,tempstr2); + do { + choice=getch(); + } while(choice!='y' && choice!='n' + && choice!='Y' && choice!='N'); + + if(choice=='y' || choice=='Y') + unlink(tempstr2); + } + } + else + { + struct stat fs1,fs2; + stat(tempstr2,&fs1); + stat(tempstr3,&fs2); + + if(fs1.st_atime!=fs2.st_atime || fs1.st_size!=fs2.st_size) + CompareFile(tempstr2,tempstr3); + } + printf("\n"); + } + } + finish=findnext(&dir); + } +} + +// find file in dir2 but not in dir1 +void CompareDir2(char *dirname1,char *dirname2) +{ + struct ffblk dir; + char filter[20]="\\*.*"; + char tempstr[255]; + int finish; + + strcpy(tempstr,dirname2); + strcat(tempstr,filter); + + printf("Comparing %s and %s\n",dirname1,dirname2); + + finish=findfirst(tempstr,&dir,FA_DIREC); + while(!finish) + { + char tempstr2[255],tempstr3[255]; + + strcpy(tempstr2,dirname1); + strcat(tempstr2,"\\"); + strcat(tempstr2,dir.ff_name); + + strcpy(tempstr3,dirname2); + strcat(tempstr3,"\\"); + strcat(tempstr3,dir.ff_name); + + + if(dir.ff_attrib & FA_DIREC) + { + if(dir.ff_name[0]!='.' && strcmp(dir.ff_name,"CVS")!=0) + { + int check,choice; + check=access(tempstr3,F_OK); + if( check ) + { + printf("\nDirectory missing : %s\n" + "Copy %s ? (Y/N)\n",tempstr3,tempstr2); + do { + choice=getch(); + } while(choice!='y' && choice!='n' + && choice!='Y' && choice!='N'); + + if( choice=='y' || choice=='Y' ) + copydir(tempstr2,tempstr3); + } + else + CompareDir2(tempstr2,tempstr3); + } + } + finish=findnext(&dir); + } + + finish=findfirst(tempstr,&dir,FA_DIREC); + while(!finish) + { + char tempstr2[255],tempstr3[255]; + + strcpy(tempstr2,dirname1); + strcat(tempstr2,"\\"); + strcat(tempstr2,dir.ff_name); + + strcpy(tempstr3,dirname2); + strcat(tempstr3,"\\"); + strcat(tempstr3,dir.ff_name); + + if((dir.ff_attrib & FA_DIREC)==0) + { + char *ext = fileextension(dir.ff_name); + if( !(stricmp(ext,"dsp")==0 || + stricmp(ext,"dep")==0 || + stricmp(ext,"dsw")==0 || + stricmp(ext,"ncb")==0 || + stricmp(ext,"bmp")==0 || + stricmp(ext,"opt")==0 || + stricmp(ext,"plg")==0 || + stricmp(ext,"ico")==0 || + stricmp(ext,"rc" )==0 || + stricmp(ext,"o" )==0 || + stricmp(ext,"bat")==0 || + stricmp(ext,"obj")==0 ) && + // check if file exist in dir1 + access(tempstr2,F_OK)) + { + int choice; + + printf("File %s found in %s but not in %s\n" + "Copy it ? (y/n)\n",tempstr3,dirname2,dirname1); + do { + choice=getch(); + } while(choice!='y' && choice!='n'); + + if(choice=='y') + fcopy(tempstr2,tempstr3); + + return; + + + } + } + finish=findnext(&dir); + } +} + +// convert tab to space +char *tabconv(char *c,int tabsize) +{ + static char buf[MAXLENLINE]; + int i=0,j=0; + + while(c[i]) + { + if(c[i]=='\t') + { + do { + buf[j++]=' '; + } while(j % tabsize); + } + else + buf[j++]=c[i]; + i++; + } + +/* + if(j>maxline) + { + buf[maxline-1]='\n'; // trunc + j=maxline; + } +*/ + buf[j]=0; + + return buf; +} + +void tabconv2(textfile_t *f,int start,int stop) +{ + static char buf[MAXLENLINE]; + char *c; + int i,j,k; + + for(k=start;k<=stop;k++) + { + c=f->line[k]; + i=j=0; + while(c[i]) + { + if(c[i]=='\t' && c[i+1]=='\t') + { + buf[j++]='\t'; + } + else + if(c[i]=='\t') + do { buf[j++]=' '; } while(j & 3); + else + buf[j++]=c[i]; + i++; + } + buf[j]=0; + free(f->line[k]); + f->line[k]=(char *)malloc(j); + strcpy(f->line[k],buf); + } +} + +int c; + +void initmyfgets( FILE *stream ) +{ + c = fgetc(stream); +} + +// convert any f*** format to the good one +char *myfgets( char *string, int n, FILE *stream ) +{ + int i=0; + char *s=string; + if( c==EOF ) + return NULL; + while( i=MAXLINE) + Quit("File %s too big, more than %d lines\n",filename,MAXLINE); + if(!myfgets(buf,MAXLENLINE,f)) + break; + if( convtab ) + strcpy(buf,tabconv(buf,tabsize)); + file->line[i]=(char *)malloc(strlen(buf)+1); + strcpy(file->line[i],buf); + i++; + } + fclose(f); + + file->lines=i; + + for(;iline[i]=eofline; +} + +void FreeTextFile(textfile_t *file) +{ + int i; + + for(i=0;ilines;i++) + free(file->line[i]); + + file->lines = 0; +} + +// afficher une partie de fichier en partant de startline jusqu'a stop line +// affiche les ligne redbeg jusqua redstop en rouge +// decale le text vers la droite de offset caractere +void PrintfBlock(textfile_t *f,int start,int redbeg,int redstop,int stop, int offset) +{ + int i,l; + char save80,save81,*p; + + if(start<0) + start=0; + + for(i=start;i<=stop;i++) + { + if(i>=redbeg && i<=redstop) + textattr(colordiff); + else + textattr(colortext); + if( f->line[i] ) + l=strlen(f->line[i]); + else + l=0; + if(l<=offset) + { + cprintf("\n\r"); + continue; + } + p=&(f->line[i][offset]); + l-=offset; + if( l>SCREENWIDTH-1) + { + save80=p[SCREENWIDTH-2]; + save81=p[SCREENWIDTH-1]; + if( p[SCREENWIDTH-2]!='\0') + p[SCREENWIDTH-2]='\n'; + p[SCREENWIDTH-1]='\0'; + cprintf("%s\r",p); + p[SCREENWIDTH-2]=save80; + p[SCREENWIDTH-1]=save81; + } + else + cprintf("%s\r",p); + } +} + +// copy only the syntax, compress all spacing in 1 space +char *delspace(char *s) +{ +static char buf[MAXLENLINE]; + int i=0,j=0; + + if( !compspace ) + { + // remove just trailing space + strcpy(buf, s); + for(i = strlen(buf)-1;(buf[i]==' ' || buf[i]=='\n' || buf[i]=='\r') && i>=0;i--) + buf[i]='\0'; + buf[i+1]='\n'; + buf[i+2]='\0'; + return buf; + } + + while(s[i]!='\n' && s[i]) + { + if(s[i]==' ') + { + while(s[i]==' ' && s[i]!='\n' && s[i]) { i++; } + if(s[i]!='\n' && s[i]) + buf[j++]=' '; + } + else + buf[j++]=s[i++]; + } + buf[j++]='\n'; + buf[j]='\0'; + + return buf; +} + +int LineCmp(char **a1,char **a2,int linetocmp) +{ + char buf[MAXLENLINE]; + char buf2[MAXLENLINE]; + int i; + + for(i=0;iline[line1+i-j] + ,&f2->line[line2+j],sameline)) + { + *ri=i-j; + *rj=j; + + return; + } + animcount++; + animcount&=0xF; + // not to mush printf this slowdown a lot + if( (animcount&3)==0 ) + cprintf("\b%c",anim[animcount>>2]); + } + Quit("Too mush difference between the files\n"); +} + +void cnprintf(char *s,int n) +{ + int i; + for(i=0;i%c%c] [-]%d lines[+] [u]ndo [e]dit [c]ompress space",27,26,sameline); + fflush(stdout); + textattr(colornormal); +} + +// copy file date of source to dest +void CopyFileDate(char *dest,char *source) +{ + struct stat fs1; + struct utimbuf fs2; + + stat(source,&fs1); + fs2.actime = fs1.st_mtime; + fs2.modtime = fs1.st_mtime; + + utime(dest,&fs2); +} + +void CompareFile(char *filename1,char *filename2) +{ + int i,j,choice,k,l; + int line1,line2; + FILE *outfile; + int maxlines,always,enterline=0,column=0; + int oneselected=false,twoselected=false; + + LoadTextFile(filename1,&f1,tab1); + LoadTextFile(filename2,&f2,tab2); + outfile=fopen(tempfilename,"wt"); + if( !outfile ) + Quit("Error: No way to open %s\n",tempfilename); + line1=0; + line2=0; + always=0; + maxlines=f1.lines+f2.lines+1; + +// if(maxlines1 ) { + sameline--; + Resynchronize(&f1,line1,&f2,line2,&i,&j,maxlines,sameline); + } + break; + case 'c' : + compspace = !compspace; + Resynchronize(&f1,line1,&f2,line2,&i,&j,maxlines,sameline); + break; +/* + case 't' : + tabconv2(&f1,line1,line1+i-1); + Resynchronize(&f1,line1,&f2,line2,&i,&j,maxlines,sameline); + break; +*/ + case 'p' : always=1;break; + case 'd' : always=2;break; + case 'u' : + fclose(outfile); + FreeTextFile(&f1); + FreeTextFile(&f2); + + // remove the temp file + unlink(tempfilename); + + CompareFile(filename1,filename2); + + return; + case 'e' : + { + char params[256]; + fclose(outfile); + FreeTextFile(&f1); + FreeTextFile(&f2); + + // remove the temp file + unlink(tempfilename); + + sprintf(params,"\"%s/%d\" \"%s/%d\"",filename1,line1,filename2,line2); + + spawnlp(P_WAIT,editor,params,params,NULL); + printf("\n\nHit Enter to continue\n"); + getchar(); + + CompareFile(filename1,filename2); + return; + } + } + + } while(choice!='3' && choice!='9' && always==0); + } + printf("\n"); + + if(choice=='9'|| always==1) + { + int blankline; + for(blankline=0;blankline $(DOBJ)\mmx.h +- @echo .text > $(DOBJ)\mmxtest.s +- @echo emms >> $(DOBJ)\mmxtest.s +- @gcc -c $(OBJ)/mmxtest.s -o $(OBJ)/mmxtest.o +- @echo #define ALLEGRO_MMX > $(DOBJ)\mmx.h ++ @echo // no MMX > $(subst /,\,$(OBJ))\mmx.h ++ @echo .text > $(subst /,\,$(OBJ))\mmxtest.s ++ @echo emms >> $(subst /,\,$(OBJ))\mmxtest.s ++ @$(GCC) -c $(OBJ)/mmxtest.s -o $(OBJ)/mmxtest.o ++ @echo #define ALLEGRO_MMX > $(subst /,\,$(OBJ))\mmx.h + @echo Your assembler supports MMX instructions! + + $(OBJ)/mmx.h: + @echo Testing for MMX assembler support... + -$(MAKE) mmxtest + +-$(OBJ)/setupdat.s $(OBJ)/setupdat.h: setup/setup.dat tools/dat2s.exe +- tools/dat2s.exe setup/setup.dat -o $(OBJ)/setupdat.s -h $(OBJ)/setupdat.h ++$(OBJ)/setupdat.s $(OBJ)/setupdat.h: setup/setup.dat tools/$(VERSION)/dat2s.exe ++ tools/$(VERSION)/dat2s.exe setup/setup.dat -o $(OBJ)/setupdat.s -h $(OBJ)/setupdat.h + + $(OBJ)/setupdat.o: $(OBJ)/setupdat.s +- gcc $(SFLAGS) -o $(OBJ)/setupdat.o -c $(OBJ)/setupdat.s ++ $(GCC) $(SFLAGS) -o $(OBJ)/setupdat.o -c $(OBJ)/setupdat.s + +-setup/setup.exe: $(OBJ)/setup.o $(OBJ)/setupdat.o $(LIB) +- gcc $(LFLAGS) -o setup/setup.exe $(OBJ)/setup.o $(OBJ)/setupdat.o $(LIB) ++setup/$(VERSION)/setup.exe: $(OBJ)/setup.o $(OBJ)/setupdat.o lib/djgpp/$(LIB) ++ $(GCC) $(LFLAGS) -o setup/$(VERSION)/setup.exe $(OBJ)/setup.o $(OBJ)/setupdat.o lib/djgpp/$(LIB) + ifndef DEBUGMODE + ifndef SYMBOLMODE + ifneq ($(DJP),) +- $(DJP) setup/setup.exe ++ $(DJP) setup/$(VERSION)/setup.exe + endif + endif + endif +@@ -301,79 +338,79 @@ + endif + + $(OBJ)/plugins.h: $(wildcard tools/plugins/*.inc) +- copy tools\plugins\*.inc $(DOBJ)\plugins.h ++ cat tools/plugins/*.inc > $(OBJ)/plugins.h + +-tools/dat.exe: $(OBJ)/dat.o $(DATEDIT_DEPS) $(LIB) +- gcc $(LFLAGS) -o tools/dat.exe $(OBJ)/dat.o $(DATEDIT_LINK) $(LIB) ++tools/$(VERSION)/dat.exe: $(OBJ)/dat.o $(DATEDIT_DEPS) lib/djgpp/$(LIB) ++ $(GCC) $(LFLAGS) -o tools/$(VERSION)/dat.exe $(OBJ)/dat.o $(DATEDIT_LINK) lib/djgpp/$(LIB) + +-tools/dat2s.exe: $(OBJ)/dat2s.o $(DATEDIT_DEPS) $(LIB) +- gcc $(LFLAGS) -o tools/dat2s.exe $(OBJ)/dat2s.o $(DATEDIT_LINK) $(LIB) ++tools/$(VERSION)/dat2s.exe: $(OBJ)/dat2s.o $(DATEDIT_DEPS) lib/djgpp/$(LIB) ++ $(GCC) $(LFLAGS) -o tools/$(VERSION)/dat2s.exe $(OBJ)/dat2s.o $(DATEDIT_LINK) lib/djgpp/$(LIB) + +-tools/grabber.exe: $(OBJ)/grabber.o $(DATEDIT_DEPS) $(LIB) +- gcc $(LFLAGS) -o tools/grabber.exe $(OBJ)/grabber.o $(DATEDIT_LINK) $(LIB) ++tools/$(VERSION)/grabber.exe: $(OBJ)/grabber.o $(DATEDIT_DEPS) lib/djgpp/$(LIB) ++ $(GCC) $(LFLAGS) -o tools/$(VERSION)/grabber.exe $(OBJ)/grabber.o $(DATEDIT_LINK) lib/djgpp/$(LIB) + +-tools/pat2dat.exe: $(OBJ)/pat2dat.o $(DATEDIT_DEPS) $(LIB) +- gcc $(LFLAGS) -o tools/pat2dat.exe $(OBJ)/pat2dat.o $(DATEDIT_LINK) $(LIB) ++tools/$(VERSION)/pat2dat.exe: $(OBJ)/pat2dat.o $(DATEDIT_DEPS) lib/djgpp/$(LIB) ++ $(GCC) $(LFLAGS) -o tools/$(VERSION)/pat2dat.exe $(OBJ)/pat2dat.o $(DATEDIT_LINK) lib/djgpp/$(LIB) + +-$(LIB): $(LIB_OBJS) +- ar rs $(LIB) $(LIB_OBJS) ++lib/djgpp/$(LIB): $(LIB_OBJS) ++ ar rs lib/djgpp/$(LIB) $(LIB_OBJS) + + compress: $(PROGRAMS) + ifneq ($(DJP),) +- $(DJP) demo/*.exe examples/*.exe tests/*.exe tools/*.exe setup/keyconf.exe obj/djgpp/*.exe ++ $(DJP) demo/$(VERSION)/*.exe examples/$(VERSION)/*.exe tests/$(VERSION)/*.exe tools/$(VERSION)/*.exe setup/$(VERSION)/keyconf.exe $(OBJ)*.exe + else + @echo No executable compressor found! This target requires either the + @echo DJP or UPX utilities to be installed in your djgpp bin directory. + endif + + clean: +- -rm -v obj/djgpp/*.* lib/djgpp/*.* docs/*.$(HTML) docs/*.txi docs/*.inf docs/*.rtf ++ -rm -f -v $(OBJ)/*.* lib/djgpp/*.* docs/*.$(HTML) docs/*.txi docs/*.inf docs/*.rtf + + veryclean: clean +- -rm -v allegro.txt AUTHORS CHANGES faq.txt help.txt NEWS THANKS \ +- demo/*.exe examples/*.exe setup/*.exe tests/*.exe tools/*.exe ++ -rm -f -v allegro.txt AUTHORS CHANGES faq.txt help.txt NEWS THANKS \ ++ demo/$(VERSION)/*.exe examples/$(VERSION)/*.exe setup/$(VERSION)/*.exe tests/$(VERSION)/*.exe tools/$(VERSION)/*.exe + + uninstall: +- -rm $(LIBDEST) +- -rm $(INCDEST) +- -rm $(DOCDEST) ++ -rm -f $(LIBDEST) ++ -rm -f $(INCDEST) ++ -rm -f $(DOCDEST) + @echo All gone! (sulk) + +-demo: demo/demo.exe +-keyconf: setup/keyconf.exe +-setup: setup/setup.exe +-afinfo: tests/afinfo.exe +-akaitest: tests/akaitest.exe +-digitest: tests/digitest.exe +-mathtest: tests/mathtest.exe +-miditest: tests/miditest.exe +-play: tests/play.exe +-playfli: tests/playfli.exe +-test: tests/test.exe +-vesainfo: tests/vesainfo.exe +-colormap: tools/colormap.exe +-dat: tools/dat.exe +-dat2s: tools/dat2s.exe +-exedat: tools/exedat.exe +-grabber: tools/grabber.exe +-pack: tools/pack.exe +-pat2dat: tools/pat2dat.exe +-rgbmap: tools/rgbmap.exe +- +-examples: examples/ex1.exe examples/ex2.exe examples/ex3.exe \ +- examples/ex4.exe examples/ex5.exe examples/ex6.exe \ +- examples/ex7.exe examples/ex8.exe examples/ex9.exe \ +- examples/ex10.exe examples/ex11.exe examples/ex12.exe \ +- examples/ex13.exe examples/ex14.exe examples/ex15.exe \ +- examples/ex16.exe examples/ex17.exe examples/ex18.exe \ +- examples/ex19.exe examples/ex20.exe examples/ex21.exe \ +- examples/ex22.exe examples/ex23.exe examples/ex24.exe \ +- examples/ex25.exe examples/ex26.exe examples/ex27.exe \ +- examples/ex28.exe examples/ex29.exe examples/ex30.exe \ +- examples/ex31.exe examples/ex32.exe examples/ex33.exe \ +- examples/ex34.exe examples/ex35.exe examples/ex36.exe \ +- examples/ex37.exe examples/ex38.exe examples/ex39.exe \ +- examples/ex40.exe ++demo: demo/$(VERSION)/demo.exe ++keyconf: setup/$(VERSION)/keyconf.exe ++setup: setup/$(VERSION)/setup.exe ++afinfo: tests/$(VERSION)/afinfo.exe ++akaitest: tests/$(VERSION)/akaitest.exe ++digitest: tests/$(VERSION)/digitest.exe ++mathtest: tests/$(VERSION)/mathtest.exe ++miditest: tests/$(VERSION)/miditest.exe ++play: tests/$(VERSION)/play.exe ++playfli: tests/$(VERSION)/playfli.exe ++test: tests/$(VERSION)/test.exe ++vesainfo: tests/$(VERSION)/vesainfo.exe ++colormap: tools/$(VERSION)/colormap.exe ++dat: tools/$(VERSION)/dat.exe ++dat2s: tools/$(VERSION)/dat2s.exe ++exedat: tools/$(VERSION)/exedat.exe ++grabber: tools/$(VERSION)/grabber.exe ++pack: tools/$(VERSION)/pack.exe ++pat2dat: tools/$(VERSION)/pat2dat.exe ++rgbmap: tools/$(VERSION)/rgbmap.exe ++ ++examples: examples/$(VERSION)/ex1.exe examples/$(VERSION)/ex2.exe examples/$(VERSION)/ex3.exe \ ++ examples/$(VERSION)/ex4.exe examples/$(VERSION)/ex5.exe examples/$(VERSION)/ex6.exe \ ++ examples/$(VERSION)/ex7.exe examples/$(VERSION)/ex8.exe examples/$(VERSION)/ex9.exe \ ++ examples/$(VERSION)/ex10.exe examples/$(VERSION)/ex11.exe examples/$(VERSION)/ex12.exe \ ++ examples/$(VERSION)/ex13.exe examples/$(VERSION)/ex14.exe examples/$(VERSION)/ex15.exe \ ++ examples/$(VERSION)/ex16.exe examples/$(VERSION)/ex17.exe examples/$(VERSION)/ex18.exe \ ++ examples/$(VERSION)/ex19.exe examples/$(VERSION)/ex20.exe examples/$(VERSION)/ex21.exe \ ++ examples/$(VERSION)/ex22.exe examples/$(VERSION)/ex23.exe examples/$(VERSION)/ex24.exe \ ++ examples/$(VERSION)/ex25.exe examples/$(VERSION)/ex26.exe examples/$(VERSION)/ex27.exe \ ++ examples/$(VERSION)/ex28.exe examples/$(VERSION)/ex29.exe examples/$(VERSION)/ex30.exe \ ++ examples/$(VERSION)/ex31.exe examples/$(VERSION)/ex32.exe examples/$(VERSION)/ex33.exe \ ++ examples/$(VERSION)/ex34.exe examples/$(VERSION)/ex35.exe examples/$(VERSION)/ex36.exe \ ++ examples/$(VERSION)/ex37.exe examples/$(VERSION)/ex38.exe examples/$(VERSION)/ex39.exe \ ++ examples/$(VERSION)/ex40.exe + + $(OBJ)/demo.o: demo.h + $(OBJ)/adlib.o: fm_instr.h +diff -ruN allegro.312/obj/djgpp/alld/tmp.txt allegro.313/obj/djgpp/alld/tmp.txt +--- allegro.312/obj/djgpp/alld/tmp.txt Thu Jan 1 00:00:00 1970 ++++ allegro.313/obj/djgpp/alld/tmp.txt Sat Feb 27 21:25:34 1999 +@@ -0,0 +1 @@ ++This file is needed because some unzip programs skip empty directories. +diff -ruN allegro.312/obj/djgpp/alleg/tmp.txt allegro.313/obj/djgpp/alleg/tmp.txt +--- allegro.312/obj/djgpp/alleg/tmp.txt Thu Jan 1 00:00:00 1970 ++++ allegro.313/obj/djgpp/alleg/tmp.txt Sat Feb 27 21:25:34 1999 +@@ -0,0 +1 @@ ++This file is needed because some unzip programs skip empty directories. +diff -ruN allegro.312/obj/djgpp/allp/tmp.txt allegro.313/obj/djgpp/allp/tmp.txt +--- allegro.312/obj/djgpp/allp/tmp.txt Thu Jan 1 00:00:00 1970 ++++ allegro.313/obj/djgpp/allp/tmp.txt Sat Feb 27 21:25:34 1999 +@@ -0,0 +1 @@ ++This file is needed because some unzip programs skip empty directories. +diff -ruN allegro.312/obj/djgpp/tmp.txt allegro.313/obj/djgpp/tmp.txt +--- allegro.312/obj/djgpp/tmp.txt Sat Feb 27 21:25:34 1999 ++++ allegro.313/obj/djgpp/tmp.txt Thu Jan 1 00:00:00 1970 +@@ -1 +0,0 @@ +-This file is needed because some unzip programs skip empty directories. +diff -ruN allegro.312/setup/alld/tmp.txt allegro.313/setup/alld/tmp.txt +--- allegro.312/setup/alld/tmp.txt Thu Jan 1 00:00:00 1970 ++++ allegro.313/setup/alld/tmp.txt Sat Feb 27 21:25:34 1999 +@@ -0,0 +1 @@ ++This file is needed because some unzip programs skip empty directories. +diff -ruN allegro.312/setup/alleg/tmp.txt allegro.313/setup/alleg/tmp.txt +--- allegro.312/setup/alleg/tmp.txt Thu Jan 1 00:00:00 1970 ++++ allegro.313/setup/alleg/tmp.txt Sat Feb 27 21:25:34 1999 +@@ -0,0 +1 @@ ++This file is needed because some unzip programs skip empty directories. +diff -ruN allegro.312/setup/allp/tmp.txt allegro.313/setup/allp/tmp.txt +--- allegro.312/setup/allp/tmp.txt Thu Jan 1 00:00:00 1970 ++++ allegro.313/setup/allp/tmp.txt Sat Feb 27 21:25:34 1999 +@@ -0,0 +1 @@ ++This file is needed because some unzip programs skip empty directories. +diff -ruN allegro.312/src/asmdefs.inc allegro.313/src/asmdefs.inc +--- allegro.312/src/asmdefs.inc Sat Feb 20 20:51:22 1999 ++++ allegro.313/src/asmdefs.inc Sun Jun 19 04:18:44 2005 +@@ -41,8 +41,8 @@ + * %eax. Registers will be unchanged, except %eax will return a pointer + * to the start of the selected scanline. + */ +-#define WRITE_BANK() call BMP_WBANK(%edx) +-#define READ_BANK() call BMP_RBANK(%edx) ++#define WRITE_BANK() call *BMP_WBANK(%edx) ++#define READ_BANK() call *BMP_RBANK(%edx) + + + /* Helper macro for looking up a position in the pattern bitmap. Passed +diff -ruN allegro.312/src/djgpp/gpro.c allegro.313/src/djgpp/gpro.c +--- allegro.312/src/djgpp/gpro.c Sat Feb 20 22:01:28 1999 ++++ allegro.313/src/djgpp/gpro.c Mon Jun 20 21:23:42 2005 +@@ -53,135 +53,79 @@ + */ + static int read_gpp(int pad_num) + { +- char samples[60]; +- char clock_mask, data_mask; +- int ret; +- +- asm ( +- " cmpb $0, %0 ; " +- " jne 14f ; " +- " movb $0x10, %b2 ; " +- " movb $0x20, %b3 ; " +- " jmp 15f ; " +- " 14: " +- " movb $0x40, %b2 ; " +- " movb $0x80, %b3 ; " +- +- " 15: " +- " xorl %%ebx, %%ebx ; " +- " xorl %%edi, %%edi ; " +- " movw $0x201, %%dx ; " +- +- " cli ; " +- " inb %%dx, %%al ; " +- " movb %%al, %%ah ; " +- +- " 4: " +- " xorl %%ecx, %%ecx ; " +- " 0: " +- " inb %%dx, %%al ; " +- " cmpb %%ah, %%al ; " +- " jne 1f ; " +- " incl %%ecx ; " +- " cmpl $255, %%ecx ; " +- " jl 0b ; " +- +- " 1: " +- " cmpl $255, %%ecx ; " +- " je 16f ; " +- +- " testb %%ah, %b2 ; " +- " jz 2f ; " +- " testb %%al, %b2 ; " +- " jnz 2f ; " +- +- " addl %4, %%edi ; " +- " testb %%al, %b3 ; " +- " jz 3f ; " +- " movb $1, (%%edi) ; " +- " jmp 12f ; " +- " 3: " +- " movb $0, (%%edi) ; " +- " 12: " +- " subl %4, %%edi ; " +- " incl %%edi ; " +- +- " 2: " +- " movb %%al, %%ah ; " +- " cmpl $200, %%ebx ; " +- " je 13f ; " +- " incl %%ebx ; " +- " cmpl $50, %%edi ; " +- " jl 4b ; " +- +- " 13: " +- " sti ; " +- " xorl %%ecx, %%ecx ; " +- " movl $1, %%esi ; " +- " 7: " +- " addl %4, %%esi ; " +- " movb (%%esi), %%dl ; " +- " subl %4, %%esi ; " +- " cmpb $1, %%dl ; " +- " jg 16f ; " +- " jne 6f ; " +- " incl %%ecx ; " +- " jmp 5f ; " +- " 6: " +- " xorl %%ecx, %%ecx ; " +- +- " 5: " +- " cmpl $5, %%ecx ; " +- " je 8f ; " +- " cmpl %%edi, %%esi ; " +- " je 8f ; " +- " incl %%esi ; " +- " jmp 7b ; " +- +- " 8: " +- " cmpl $5, %%ecx ; " +- " jne 16f ; " +- " addl $2, %%esi ; " +- " xorl %%eax, %%eax ; " +- " xorl %%ebx, %%ebx ; " +- " xorl %%ecx, %%ecx ; " +- " xorl %%edx, %%edx ; " +- +- " 10: " +- " incl %%ecx ; " +- " cmpl $5, %%ecx ; " +- " jne 11f ; " +- " movl $1, %%ecx ; " +- " incl %%esi ; " +- " 11: " +- " addl %4, %%esi ; " +- " movb (%%esi), %%dl ; " +- " subl %4, %%esi ; " +- " orl %%edx, %%eax ; " +- " shll $1, %%eax ; " +- " cmpl $13, %%ebx ; " +- " je 9f ; " +- " incl %%ebx ; " +- " incl %%esi ; " +- " jmp 10b ; " +- +- " 16: " +- " movl $1, %%eax ; " +- +- " 9: " +- " sti ; " +- +- : "=a" (ret) +- +- : "0" (pad_num), +- "m" (clock_mask), +- "m" (data_mask), +- "m" (samples) ++ int samples[50]; ++ int clock_mask, data_mask, data, old_data; ++ int num_samples, timeout1, timeout2, sample_pos, c; ++ ++ if (pad_num == 0) { ++ clock_mask = 0x10; ++ data_mask = 0x20; ++ } ++ else { ++ clock_mask = 0x40; ++ data_mask = 0x80; ++ } ++ ++ num_samples = 0; ++ timeout1 = 0; ++ ++ asm volatile ("cli"); ++ ++ old_data = inportb(0x201); ++ data = 0; ++ ++ while (num_samples<50) { ++ for (timeout2=0; timeout2<255; timeout2++) { ++ data = inportb(0x201); ++ if (data != old_data) ++ break; ++ } ++ ++ if (timeout2 == 255) { ++ asm volatile ("sti"); ++ return 1; ++ } ++ ++ if ((old_data & clock_mask) && (!(data & clock_mask))) { ++ samples[num_samples] = (data & data_mask) ? 1 : 0; ++ num_samples++; ++ } ++ ++ old_data = data; ++ ++ if (timeout1++ == 200) ++ break; ++ } ++ ++ asm volatile ("sti"); ++ ++ c = 0; ++ ++ for (sample_pos=1; sample_posgs), + "=m" (sregs->ss) + +- : /* no inputs */ +- +- : "%eax" /* clobbers %eax */ + ); + } + +diff -ruN allegro.312/src/gfx15.s allegro.313/src/gfx15.s +--- allegro.312/src/gfx15.s Sat Feb 20 20:50:30 1999 ++++ allegro.313/src/gfx15.s Mon Jun 20 22:46:02 2005 +@@ -367,9 +367,9 @@ + movl BMP_CT(%edx), %esi /* clip y1 */ + + vline_y1_ok: +- cmpw BMP_CB(%edx), %ecx /* test y2, bmp->cb */ ++ cmpw BMP_CB(%edx), %cx /* test y2, bmp->cb */ + jl vline_noclip +- cmpw BMP_CB(%edx), %esi /* test y1, bmp->cb */ ++ cmpw BMP_CB(%edx), %si /* test y1, bmp->cb */ + jge vline_done + movl BMP_CB(%edx), %ecx /* clip y2 */ + decl %ecx +diff -ruN allegro.312/src/gfx16.s allegro.313/src/gfx16.s +--- allegro.312/src/gfx16.s Sat Feb 20 20:50:42 1999 ++++ allegro.313/src/gfx16.s Mon Jun 20 22:47:28 2005 +@@ -417,9 +417,9 @@ + movl BMP_CT(%edx), %esi /* clip y1 */ + + vline_y1_ok: +- cmpw BMP_CB(%edx), %ecx /* test y2, bmp->cb */ ++ cmpw BMP_CB(%edx), %cx /* test y2, bmp->cb */ + jl vline_noclip +- cmpw BMP_CB(%edx), %esi /* test y1, bmp->cb */ ++ cmpw BMP_CB(%edx), %si /* test y1, bmp->cb */ + jge vline_done + movl BMP_CB(%edx), %ecx /* clip y2 */ + decl %ecx +diff -ruN allegro.312/src/gfx24.s allegro.313/src/gfx24.s +--- allegro.312/src/gfx24.s Sat Feb 20 20:46:30 1999 ++++ allegro.313/src/gfx24.s Mon Jun 20 22:48:22 2005 +@@ -265,7 +265,7 @@ + movl %eax, ARG2 /* ARG2 == 12(%ebp) */ + movl %eax, 15(%ebp) /* overwrite ARG2, ARG3, ARG4 */ + movl %eax, 18(%ebp) +- movw %eax, 21(%ebp) ++ movw %ax, 21(%ebp) + shrl $16, %eax + movb %al, 23(%ebp) + cmpl $4, %ecx +@@ -503,9 +503,9 @@ + movl BMP_CT(%edx), %esi /* clip y1 */ + + vline_y1_ok: +- cmpw BMP_CB(%edx), %ecx /* test y2, bmp->cb */ ++ cmpw BMP_CB(%edx), %cx /* test y2, bmp->cb */ + jl vline_noclip +- cmpw BMP_CB(%edx), %esi /* test y1, bmp->cb */ ++ cmpw BMP_CB(%edx), %si /* test y1, bmp->cb */ + jge vline_done + movl BMP_CB(%edx), %ecx /* clip y2 */ + decl %ecx +diff -ruN allegro.312/src/gfx32.s allegro.313/src/gfx32.s +--- allegro.312/src/gfx32.s Sat Feb 20 20:50:40 1999 ++++ allegro.313/src/gfx32.s Mon Jun 20 22:48:44 2005 +@@ -398,9 +398,9 @@ + movl BMP_CT(%edx), %esi /* clip y1 */ + + vline_y1_ok: +- cmpw BMP_CB(%edx), %ecx /* test y2, bmp->cb */ ++ cmpw BMP_CB(%edx), %cx /* test y2, bmp->cb */ + jl vline_noclip +- cmpw BMP_CB(%edx), %esi /* test y1, bmp->cb */ ++ cmpw BMP_CB(%edx), %si /* test y1, bmp->cb */ + jge vline_done + movl BMP_CB(%edx), %ecx /* clip y2 */ + decl %ecx +diff -ruN allegro.312/src/gfx8.s allegro.313/src/gfx8.s +--- allegro.312/src/gfx8.s Sat Feb 20 20:50:54 1999 ++++ allegro.313/src/gfx8.s Mon Jun 20 22:49:02 2005 +@@ -455,9 +455,9 @@ + movl BMP_CT(%edx), %esi /* clip y1 */ + + vline_y1_ok: +- cmpw BMP_CB(%edx), %ecx /* test y2, bmp->cb */ ++ cmpw BMP_CB(%edx), %cx /* test y2, bmp->cb */ + jl vline_noclip +- cmpw BMP_CB(%edx), %esi /* test y1, bmp->cb */ ++ cmpw BMP_CB(%edx), %si /* test y1, bmp->cb */ + jge vline_done + movl BMP_CB(%edx), %ecx /* clip y2 */ + decl %ecx +diff -ruN allegro.312/tests/alld/tmp.txt allegro.313/tests/alld/tmp.txt +--- allegro.312/tests/alld/tmp.txt Thu Jan 1 00:00:00 1970 ++++ allegro.313/tests/alld/tmp.txt Sat Feb 27 21:25:34 1999 +@@ -0,0 +1 @@ ++This file is needed because some unzip programs skip empty directories. +diff -ruN allegro.312/tests/alleg/tmp.txt allegro.313/tests/alleg/tmp.txt +--- allegro.312/tests/alleg/tmp.txt Thu Jan 1 00:00:00 1970 ++++ allegro.313/tests/alleg/tmp.txt Sat Feb 27 21:25:34 1999 +@@ -0,0 +1 @@ ++This file is needed because some unzip programs skip empty directories. +diff -ruN allegro.312/tests/allp/tmp.txt allegro.313/tests/allp/tmp.txt +--- allegro.312/tests/allp/tmp.txt Thu Jan 1 00:00:00 1970 ++++ allegro.313/tests/allp/tmp.txt Sat Feb 27 21:25:34 1999 +@@ -0,0 +1 @@ ++This file is needed because some unzip programs skip empty directories. +diff -ruN allegro.312/tools/alld/tmp.txt allegro.313/tools/alld/tmp.txt +--- allegro.312/tools/alld/tmp.txt Thu Jan 1 00:00:00 1970 ++++ allegro.313/tools/alld/tmp.txt Sat Feb 27 21:25:34 1999 +@@ -0,0 +1 @@ ++This file is needed because some unzip programs skip empty directories. +diff -ruN allegro.312/tools/alleg/tmp.txt allegro.313/tools/alleg/tmp.txt +--- allegro.312/tools/alleg/tmp.txt Thu Jan 1 00:00:00 1970 ++++ allegro.313/tools/alleg/tmp.txt Sat Feb 27 21:25:34 1999 +@@ -0,0 +1 @@ ++This file is needed because some unzip programs skip empty directories. +diff -ruN allegro.312/tools/allp/tmp.txt allegro.313/tools/allp/tmp.txt +--- allegro.312/tools/allp/tmp.txt Thu Jan 1 00:00:00 1970 ++++ allegro.313/tools/allp/tmp.txt Sat Feb 27 21:25:34 1999 +@@ -0,0 +1 @@ ++This file is needed because some unzip programs skip empty directories. diff --git a/tools/fmoddyn.h b/tools/fmoddyn.h new file mode 100644 index 000000000..d1e7c43f8 --- /dev/null +++ b/tools/fmoddyn.h @@ -0,0 +1,582 @@ +/* =========================================================================================== */ +/* FMOD Dynamic DLL loading header. Copyright (c), Firelight Technologies Pty, Ltd. 1999-2004. */ +/* =========================================================================================== */ + +#ifndef _FMODDYN_H_ +#define _FMODDYN_H_ + +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(_WIN64) + #include +#else + #include + #include +#endif +#include + +typedef struct +{ + void *module; + + signed char (F_API *FSOUND_SetOutput)(int outputtype); + signed char (F_API *FSOUND_SetDriver)(int driver); + signed char (F_API *FSOUND_SetMixer)(int mixer); + signed char (F_API *FSOUND_SetBufferSize)(int len_ms); + signed char (F_API *FSOUND_SetHWND)(void *hwnd); + signed char (F_API *FSOUND_SetMinHardwareChannels)(int min); + signed char (F_API *FSOUND_SetMaxHardwareChannels)(int max); + signed char (F_API *FSOUND_SetMemorySystem)(void *pool, int poollen, FSOUND_ALLOCCALLBACK useralloc, FSOUND_REALLOCCALLBACK userrealloc, FSOUND_FREECALLBACK userfree); + signed char (F_API *FSOUND_Init)(int mixrate, int maxsoftwarechannels, unsigned int flags); + void (F_API *FSOUND_Close)(); + void (F_API *FSOUND_Update)(); /* you must call this once a frame */ + void (F_API *FSOUND_SetSpeakerMode)(unsigned int speakermode); + void (F_API *FSOUND_SetSFXMasterVolume)(int volume); + void (F_API *FSOUND_SetPanSeperation)(float pansep); + void (F_API *FSOUND_File_SetCallbacks)(FSOUND_OPENCALLBACK useropen, FSOUND_CLOSECALLBACK userclose, FSOUND_READCALLBACK userread, FSOUND_SEEKCALLBACK userseek, FSOUND_TELLCALLBACK usertell); + int (F_API *FSOUND_GetError)(); + float (F_API *FSOUND_GetVersion)(); + int (F_API *FSOUND_GetOutput)(); + void * (F_API *FSOUND_GetOutputHandle)(); + int (F_API *FSOUND_GetDriver)(); + int (F_API *FSOUND_GetMixer)(); + int (F_API *FSOUND_GetNumDrivers)(); + const char * (F_API *FSOUND_GetDriverName)(int id); + signed char (F_API *FSOUND_GetDriverCaps)(int id, unsigned int *caps); + int (F_API *FSOUND_GetOutputRate)(); + int (F_API *FSOUND_GetMaxChannels)(); + int (F_API *FSOUND_GetMaxSamples)(); + unsigned int (F_API *FSOUND_GetSpeakerMode)(); + int (F_API *FSOUND_GetSFXMasterVolume)(); + signed char (F_API *FSOUND_GetNumHWChannels)(int *num2d, int *num3d, int *total); + int (F_API *FSOUND_GetChannelsPlaying)(); + float (F_API *FSOUND_GetCPUUsage)(); + void (F_API *FSOUND_GetMemoryStats)(unsigned int *currentalloced, unsigned int *maxalloced); + FSOUND_SAMPLE * (F_API *FSOUND_Sample_Load)(int index, const char *name_or_data, unsigned int mode, int offset, int length); + FSOUND_SAMPLE * (F_API *FSOUND_Sample_Alloc)(int index, int length, unsigned int mode, int deffreq, int defvol, int defpan, int defpri); + void (F_API *FSOUND_Sample_Free)(FSOUND_SAMPLE *sptr); + signed char (F_API *FSOUND_Sample_Upload)(FSOUND_SAMPLE *sptr, void *srcdata, unsigned int mode); + signed char (F_API *FSOUND_Sample_Lock)(FSOUND_SAMPLE *sptr, int offset, int length, void **ptr1, void **ptr2, unsigned int *len1, unsigned int *len2); + signed char (F_API *FSOUND_Sample_Unlock)(FSOUND_SAMPLE *sptr, void *ptr1, void *ptr2, unsigned int len1, unsigned int len2); + signed char (F_API *FSOUND_Sample_SetMode)(FSOUND_SAMPLE *sptr, unsigned int mode); + signed char (F_API *FSOUND_Sample_SetLoopPoints)(FSOUND_SAMPLE *sptr, int loopstart, int loopend); + signed char (F_API *FSOUND_Sample_SetDefaults)(FSOUND_SAMPLE *sptr, int deffreq, int defvol, int defpan, int defpri); + signed char (F_API *FSOUND_Sample_SetDefaultsEx)(FSOUND_SAMPLE *sptr, int deffreq, int defvol, int defpan, int defpri, int varfreq, int varvol, int varpan); + signed char (F_API *FSOUND_Sample_SetMinMaxDistance)(FSOUND_SAMPLE *sptr, float min, float max); + signed char (F_API *FSOUND_Sample_SetMaxPlaybacks)(FSOUND_SAMPLE *sptr, int max); + FSOUND_SAMPLE * (F_API *FSOUND_Sample_Get)(int sampno); + const char * (F_API *FSOUND_Sample_GetName)(FSOUND_SAMPLE *sptr); + unsigned int (F_API *FSOUND_Sample_GetLength)(FSOUND_SAMPLE *sptr); + signed char (F_API *FSOUND_Sample_GetLoopPoints)(FSOUND_SAMPLE *sptr, int *loopstart, int *loopend); + signed char (F_API *FSOUND_Sample_GetDefaults)(FSOUND_SAMPLE *sptr, int *deffreq, int *defvol, int *defpan, int *defpri); + signed char (F_API *FSOUND_Sample_GetDefaultsEx)(FSOUND_SAMPLE *sptr, int *deffreq, int *defvol, int *defpan, int *defpri, int *varfreq, int *varvol, int *varpan); + unsigned int (F_API *FSOUND_Sample_GetMode)(FSOUND_SAMPLE *sptr); + signed char (F_API *FSOUND_Sample_GetMinMaxDistance)(FSOUND_SAMPLE *sptr, float *min, float *max); + int (F_API *FSOUND_PlaySound)(int channel, FSOUND_SAMPLE *sptr); + int (F_API *FSOUND_PlaySoundEx)(int channel, FSOUND_SAMPLE *sptr, FSOUND_DSPUNIT *dsp, signed char startpaused); + signed char (F_API *FSOUND_StopSound)(int channel); + signed char (F_API *FSOUND_SetFrequency)(int channel, int freq); + signed char (F_API *FSOUND_SetVolume)(int channel, int vol); + signed char (F_API *FSOUND_SetVolumeAbsolute)(int channel, int vol); + signed char (F_API *FSOUND_SetPan)(int channel, int pan); + signed char (F_API *FSOUND_SetSurround)(int channel, signed char surround); + signed char (F_API *FSOUND_SetMute)(int channel, signed char mute); + signed char (F_API *FSOUND_SetPriority)(int channel, int priority); + signed char (F_API *FSOUND_SetReserved)(int channel, signed char reserved); + signed char (F_API *FSOUND_SetPaused)(int channel, signed char paused); + signed char (F_API *FSOUND_SetLoopMode)(int channel, unsigned int loopmode); + signed char (F_API *FSOUND_SetCurrentPosition)(int channel, unsigned int offset); + signed char (F_API *FSOUND_3D_SetAttributes)(int channel, const float *pos, const float *vel); + signed char (F_API *FSOUND_3D_SetMinMaxDistance)(int channel, float min, float max); + signed char (F_API *FSOUND_IsPlaying)(int channel); + int (F_API *FSOUND_GetFrequency)(int channel); + int (F_API *FSOUND_GetVolume)(int channel); + int (F_API *FSOUND_GetAmplitude)(int channel); + int (F_API *FSOUND_GetPan)(int channel); + signed char (F_API *FSOUND_GetSurround)(int channel); + signed char (F_API *FSOUND_GetMute)(int channel); + int (F_API *FSOUND_GetPriority)(int channel); + signed char (F_API *FSOUND_GetReserved)(int channel); + signed char (F_API *FSOUND_GetPaused)(int channel); + unsigned int (F_API *FSOUND_GetLoopMode)(int channel); + unsigned int (F_API *FSOUND_GetCurrentPosition)(int channel); + FSOUND_SAMPLE * (F_API *FSOUND_GetCurrentSample)(int channel); + signed char (F_API *FSOUND_GetCurrentLevels)(int channel, float *l, float *r); + int (F_API *FSOUND_GetNumSubChannels)(int channel); + int (F_API *FSOUND_GetSubChannel)(int channel, int subchannel); + signed char (F_API *FSOUND_3D_GetAttributes)(int channel, float *pos, float *vel); + signed char (F_API *FSOUND_3D_GetMinMaxDistance)(int channel, float *min, float *max); + void (F_API *FSOUND_3D_SetDopplerFactor)(float scale); + void (F_API *FSOUND_3D_SetDistanceFactor)(float scale); + void (F_API *FSOUND_3D_SetRolloffFactor)(float scale); + void (F_API *FSOUND_3D_Listener_SetCurrent)(int current, int numlisteners); /* use this if you use multiple listeners / splitscreen */ + void (F_API *FSOUND_3D_Listener_SetAttributes)(const float *pos, const float *vel, float fx, float fy, float fz, float tx, float ty, float tz); + void (F_API *FSOUND_3D_Listener_GetAttributes)(float *pos, float *vel, float *fx, float *fy, float *fz, float *tx, float *ty, float *tz); + int (F_API *FSOUND_FX_Enable)(int channel, unsigned int fx); /* See FSOUND_FX_MODES */ + signed char (F_API *FSOUND_FX_Disable)(int channel); + signed char (F_API *FSOUND_FX_SetChorus)(int fxid, float WetDryMix, float Depth, float Feedback, float Frequency, int Waveform, float Delay, int Phase); + signed char (F_API *FSOUND_FX_SetCompressor)(int fxid, float Gain, float Attack, float Release, float Threshold, float Ratio, float Predelay); + signed char (F_API *FSOUND_FX_SetDistortion)(int fxid, float Gain, float Edge, float PostEQCenterFrequency, float PostEQBandwidth, float PreLowpassCutoff); + signed char (F_API *FSOUND_FX_SetEcho)(int fxid, float WetDryMix, float Feedback, float LeftDelay, float RightDelay, int PanDelay); + signed char (F_API *FSOUND_FX_SetFlanger)(int fxid, float WetDryMix, float Depth, float Feedback, float Frequency, int Waveform, float Delay, int Phase); + signed char (F_API *FSOUND_FX_SetGargle)(int fxid, int RateHz, int WaveShape); + signed char (F_API *FSOUND_FX_SetI3DL2Reverb)(int fxid, int Room, int RoomHF, float RoomRolloffFactor, float DecayTime, float DecayHFRatio, int Reflections, float ReflectionsDelay, int Reverb, float ReverbDelay, float Diffusion, float Density, float HFReference); + signed char (F_API *FSOUND_FX_SetParamEQ)(int fxid, float Center, float Bandwidth, float Gain); + signed char (F_API *FSOUND_FX_SetWavesReverb)(int fxid, float InGain, float ReverbMix, float ReverbTime, float HighFreqRTRatio); + signed char (F_API *FSOUND_Stream_SetBufferSize)(int ms); /* call this before opening streams, not after */ + FSOUND_STREAM * (F_API *FSOUND_Stream_Open)(const char *name_or_data, unsigned int mode, int offset, int length); + FSOUND_STREAM * (F_API *FSOUND_Stream_Create)(FSOUND_STREAMCALLBACK callback, int length, unsigned int mode, int samplerate, void *userdata); + signed char (F_API *FSOUND_Stream_Close)(FSOUND_STREAM *stream); + int (F_API *FSOUND_Stream_Play)(int channel, FSOUND_STREAM *stream); + int (F_API *FSOUND_Stream_PlayEx)(int channel, FSOUND_STREAM *stream, FSOUND_DSPUNIT *dsp, signed char startpaused); + signed char (F_API *FSOUND_Stream_Stop)(FSOUND_STREAM *stream); + signed char (F_API *FSOUND_Stream_SetPosition)(FSOUND_STREAM *stream, unsigned int position); + unsigned int (F_API *FSOUND_Stream_GetPosition)(FSOUND_STREAM *stream); + signed char (F_API *FSOUND_Stream_SetTime)(FSOUND_STREAM *stream, int ms); + int (F_API *FSOUND_Stream_GetTime)(FSOUND_STREAM *stream); + int (F_API *FSOUND_Stream_GetLength)(FSOUND_STREAM *stream); + int (F_API *FSOUND_Stream_GetLengthMs)(FSOUND_STREAM *stream); + signed char (F_API *FSOUND_Stream_SetMode)(FSOUND_STREAM *stream, unsigned int mode); + unsigned int (F_API *FSOUND_Stream_GetMode)(FSOUND_STREAM *stream); + signed char (F_API *FSOUND_Stream_SetLoopPoints)(FSOUND_STREAM *stream, unsigned int loopstartpcm, unsigned int loopendpcm); + signed char (F_API *FSOUND_Stream_SetLoopCount)(FSOUND_STREAM *stream, int count); + int (F_API *FSOUND_Stream_GetOpenState)(FSOUND_STREAM *stream); + FSOUND_SAMPLE * (F_API *FSOUND_Stream_GetSample)(FSOUND_STREAM *stream); /* every stream contains a sample to playback on */ + FSOUND_DSPUNIT * (F_API *FSOUND_Stream_CreateDSP)(FSOUND_STREAM *stream, FSOUND_DSPCALLBACK callback, int priority, void *userdata); + signed char (F_API *FSOUND_Stream_SetEndCallback)(FSOUND_STREAM *stream, FSOUND_STREAMCALLBACK callback, void *userdata); + signed char (F_API *FSOUND_Stream_SetSyncCallback)(FSOUND_STREAM *stream, FSOUND_STREAMCALLBACK callback, void *userdata); + FSOUND_SYNCPOINT *(F_API *FSOUND_Stream_AddSyncPoint)(FSOUND_STREAM *stream, unsigned int pcmoffset, const char *name); + signed char (F_API *FSOUND_Stream_DeleteSyncPoint)(FSOUND_SYNCPOINT *point); + int (F_API *FSOUND_Stream_GetNumSyncPoints)(FSOUND_STREAM *stream); + FSOUND_SYNCPOINT *(F_API *FSOUND_Stream_GetSyncPoint)(FSOUND_STREAM *stream, int index); + char * (F_API *FSOUND_Stream_GetSyncPointInfo)(FSOUND_SYNCPOINT *point, unsigned int *pcmoffset); + signed char (F_API *FSOUND_Stream_SetSubStream)(FSOUND_STREAM *stream, int index); + int (F_API *FSOUND_Stream_GetNumSubStreams)(FSOUND_STREAM *stream); + signed char (F_API *FSOUND_Stream_SetSubStreamSentence)(FSOUND_STREAM *stream, const int *sentencelist, int numitems); + signed char (F_API *FSOUND_Stream_GetNumTagFields)(FSOUND_STREAM *stream, int *num); + signed char (F_API *FSOUND_Stream_GetTagField)(FSOUND_STREAM *stream, int num, int *type, char **name, void **value, int *length); + signed char (F_API *FSOUND_Stream_FindTagField)(FSOUND_STREAM *stream, int type, const char *name, void **value, int *length); + signed char (F_API *FSOUND_Stream_Net_SetProxy)(const char *proxy); + signed char (F_API *FSOUND_Stream_Net_SetTimeout)(int timeout); + char * (F_API *FSOUND_Stream_Net_GetLastServerStatus)(); + signed char (F_API *FSOUND_Stream_Net_SetBufferProperties)(int buffersize, int prebuffer_percent, int rebuffer_percent); + signed char (F_API *FSOUND_Stream_Net_GetBufferProperties)(int *buffersize, int *prebuffer_percent, int *rebuffer_percent); + signed char (F_API *FSOUND_Stream_Net_SetMetadataCallback)(FSOUND_STREAM *stream, FSOUND_METADATACALLBACK callback, void *userdata); + signed char (F_API *FSOUND_Stream_Net_GetStatus)(FSOUND_STREAM *stream, int *status, int *bufferpercentused, int *bitrate, unsigned int *flags); + signed char (F_API *FSOUND_CD_Play)(char drive, int track); + void (F_API *FSOUND_CD_SetPlayMode)(char drive, signed char mode); + signed char (F_API *FSOUND_CD_Stop)(char drive); + signed char (F_API *FSOUND_CD_SetPaused)(char drive, signed char paused); + signed char (F_API *FSOUND_CD_SetVolume)(char drive, int volume); + signed char (F_API *FSOUND_CD_SetTrackTime)(char drive, unsigned int ms); + signed char (F_API *FSOUND_CD_OpenTray)(char drive, signed char open); + signed char (F_API *FSOUND_CD_GetPaused)(char drive); + int (F_API *FSOUND_CD_GetTrack)(char drive); + int (F_API *FSOUND_CD_GetNumTracks)(char drive); + int (F_API *FSOUND_CD_GetVolume)(char drive); + int (F_API *FSOUND_CD_GetTrackLength)(char drive, int track); + int (F_API *FSOUND_CD_GetTrackTime)(char drive); + FSOUND_DSPUNIT * (F_API *FSOUND_DSP_Create)(FSOUND_DSPCALLBACK callback, int priority, void *userdata); + void (F_API *FSOUND_DSP_Free)(FSOUND_DSPUNIT *unit); + void (F_API *FSOUND_DSP_SetPriority)(FSOUND_DSPUNIT *unit, int priority); + int (F_API *FSOUND_DSP_GetPriority)(FSOUND_DSPUNIT *unit); + void (F_API *FSOUND_DSP_SetActive)(FSOUND_DSPUNIT *unit, signed char active); + signed char (F_API *FSOUND_DSP_GetActive)(FSOUND_DSPUNIT *unit); + FSOUND_DSPUNIT * (F_API *FSOUND_DSP_GetClearUnit)(); + FSOUND_DSPUNIT * (F_API *FSOUND_DSP_GetSFXUnit)(); + FSOUND_DSPUNIT * (F_API *FSOUND_DSP_GetMusicUnit)(); + FSOUND_DSPUNIT * (F_API *FSOUND_DSP_GetFFTUnit)(); + FSOUND_DSPUNIT * (F_API *FSOUND_DSP_GetClipAndCopyUnit)(); + signed char (F_API *FSOUND_DSP_MixBuffers)(void *destbuffer, void *srcbuffer, int len, int freq, int vol, int pan, unsigned int mode); + void (F_API *FSOUND_DSP_ClearMixBuffer)(); + int (F_API *FSOUND_DSP_GetBufferLength)(); /* Length of each DSP update */ + int (F_API *FSOUND_DSP_GetBufferLengthTotal)(); /* Total buffer length due to FSOUND_SetBufferSize */ + float * (F_API *FSOUND_DSP_GetSpectrum)(); /* Array of 512 floats - call FSOUND_DSP_SetActive(FSOUND_DSP_GetFFTUnit(), TRUE)) for this to work. */ + signed char (F_API *FSOUND_Reverb_SetProperties)(const FSOUND_REVERB_PROPERTIES *prop); + signed char (F_API *FSOUND_Reverb_GetProperties)(FSOUND_REVERB_PROPERTIES *prop); + signed char (F_API *FSOUND_Reverb_SetChannelProperties)(int channel, const FSOUND_REVERB_CHANNELPROPERTIES *prop); + signed char (F_API *FSOUND_Reverb_GetChannelProperties)(int channel, FSOUND_REVERB_CHANNELPROPERTIES *prop); + signed char (F_API *FSOUND_Record_SetDriver)(int outputtype); + int (F_API *FSOUND_Record_GetNumDrivers)(); + const char * (F_API *FSOUND_Record_GetDriverName)(int id); + int (F_API *FSOUND_Record_GetDriver)(); + signed char (F_API *FSOUND_Record_StartSample)(FSOUND_SAMPLE *sptr, signed char loop); + signed char (F_API *FSOUND_Record_Stop)(); + int (F_API *FSOUND_Record_GetPosition)(); + FMUSIC_MODULE * (F_API *FMUSIC_LoadSong)(const char *name); + FMUSIC_MODULE * (F_API *FMUSIC_LoadSongEx)(const char *name_or_data, int offset, int length, unsigned int mode, const int *samplelist, int samplelistnum); + int (F_API *FMUSIC_GetOpenState)(FMUSIC_MODULE *mod); + signed char (F_API *FMUSIC_FreeSong)(FMUSIC_MODULE *mod); + signed char (F_API *FMUSIC_PlaySong)(FMUSIC_MODULE *mod); + signed char (F_API *FMUSIC_StopSong)(FMUSIC_MODULE *mod); + void (F_API *FMUSIC_StopAllSongs)(); + signed char (F_API *FMUSIC_SetZxxCallback)(FMUSIC_MODULE *mod, FMUSIC_CALLBACK callback); + signed char (F_API *FMUSIC_SetRowCallback)(FMUSIC_MODULE *mod, FMUSIC_CALLBACK callback, int rowstep); + signed char (F_API *FMUSIC_SetOrderCallback)(FMUSIC_MODULE *mod, FMUSIC_CALLBACK callback, int orderstep); + signed char (F_API *FMUSIC_SetInstCallback)(FMUSIC_MODULE *mod, FMUSIC_CALLBACK callback, int instrument); + signed char (F_API *FMUSIC_SetSample)(FMUSIC_MODULE *mod, int sampno, FSOUND_SAMPLE *sptr); + signed char (F_API *FMUSIC_SetUserData)(FMUSIC_MODULE *mod, void *userdata); + signed char (F_API *FMUSIC_OptimizeChannels)(FMUSIC_MODULE *mod, int maxchannels, int minvolume); + signed char (F_API *FMUSIC_SetReverb)(signed char reverb); /* MIDI only */ + signed char (F_API *FMUSIC_SetLooping)(FMUSIC_MODULE *mod, signed char looping); + signed char (F_API *FMUSIC_SetOrder)(FMUSIC_MODULE *mod, int order); + signed char (F_API *FMUSIC_SetPaused)(FMUSIC_MODULE *mod, signed char pause); + signed char (F_API *FMUSIC_SetMasterVolume)(FMUSIC_MODULE *mod, int volume); + signed char (F_API *FMUSIC_SetMasterSpeed)(FMUSIC_MODULE *mode, float speed); + signed char (F_API *FMUSIC_SetPanSeperation)(FMUSIC_MODULE *mod, float pansep); + const char * (F_API *FMUSIC_GetName)(FMUSIC_MODULE *mod); + int (F_API *FMUSIC_GetType)(FMUSIC_MODULE *mod); + int (F_API *FMUSIC_GetNumOrders)(FMUSIC_MODULE *mod); + int (F_API *FMUSIC_GetNumPatterns)(FMUSIC_MODULE *mod); + int (F_API *FMUSIC_GetNumInstruments)(FMUSIC_MODULE *mod); + int (F_API *FMUSIC_GetNumSamples)(FMUSIC_MODULE *mod); + int (F_API *FMUSIC_GetNumChannels)(FMUSIC_MODULE *mod); + FSOUND_SAMPLE * (F_API *FMUSIC_GetSample)(FMUSIC_MODULE *mod, int sampno); + int (F_API *FMUSIC_GetPatternLength)(FMUSIC_MODULE *mod, int orderno); + signed char (F_API *FMUSIC_IsFinished)(FMUSIC_MODULE *mod); + signed char (F_API *FMUSIC_IsPlaying)(FMUSIC_MODULE *mod); + int (F_API *FMUSIC_GetMasterVolume)(FMUSIC_MODULE *mod); + int (F_API *FMUSIC_GetGlobalVolume)(FMUSIC_MODULE *mod); + int (F_API *FMUSIC_GetOrder)(FMUSIC_MODULE *mod); + int (F_API *FMUSIC_GetPattern)(FMUSIC_MODULE *mod); + int (F_API *FMUSIC_GetSpeed)(FMUSIC_MODULE *mod); + int (F_API *FMUSIC_GetBPM)(FMUSIC_MODULE *mod); + int (F_API *FMUSIC_GetRow)(FMUSIC_MODULE *mod); + signed char (F_API *FMUSIC_GetPaused)(FMUSIC_MODULE *mod); + int (F_API *FMUSIC_GetTime)(FMUSIC_MODULE *mod); + int (F_API *FMUSIC_GetRealChannel)(FMUSIC_MODULE *mod, int modchannel); + unsigned int (F_API *FMUSIC_GetUserData)(FMUSIC_MODULE *mod); +} FMOD_INSTANCE; + + +static FMOD_INSTANCE *FMOD_CreateInstance(char *dllName) +{ + FMOD_INSTANCE *instance; + + instance = (FMOD_INSTANCE *)calloc(sizeof(FMOD_INSTANCE), 1); + if (!instance) + { + return NULL; + } + +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(_WIN64) + instance->module = LoadLibrary(dllName); +#else + instance->module = dlopen(dllName, RTLD_LAZY); +#endif + if (!instance->module) + { + free(instance); + return NULL; + } + +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(_WIN64) +#ifdef __MINGW64__ + #define F_GETPROC(_x, _y) \ + { \ + char tmp[] = _y; \ + *(strchr(tmp, '@')) = 0; \ + instance->_x = (LPVOID)GetProcAddress((HMODULE)instance->module, &tmp[1]); \ + if (!instance->_x) \ + { \ + FreeLibrary((HMODULE)instance->module); \ + free(instance); \ + return NULL; \ + } \ + } +#elif defined(__MINGW32__) + #define F_GETPROC(_x, _y) \ + { \ + instance->_x = (LPVOID)GetProcAddress((HMODULE)instance->module, _y); \ + if (!instance->_x) \ + { \ + FreeLibrary((HMODULE)instance->module); \ + free(instance); \ + return NULL; \ + } \ + } +#elif defined (_X86_) + #define F_GETPROC(_x, _y) \ + { \ + instance->_x = (LPVOID)(size_t)GetProcAddress((HMODULE)instance->module, _y); \ + if (!instance->_x) \ + { \ + FreeLibrary((HMODULE)instance->module); \ + free(instance); \ + return NULL; \ + } \ + } +#else + #define F_GETPROC(_x, _y) \ + { \ + char tmp[] = _y; \ + *(strchr(tmp, '@')) = 0; \ + instance->_x = (LPVOID)(size_t)GetProcAddress((HMODULE)instance->module, &tmp[1]); \ + if (!instance->_x) \ + { \ + FreeLibrary((HMODULE)instance->module); \ + free(instance); \ + return NULL; \ + } \ + } +#endif +#else + #define F_GETPROC(_x, _y) \ + { \ + char tmp[] = _y; \ + *(strchr(tmp, '@')) = 0; \ + instance->_x = (void *)dlsym(instance->module, &tmp[1]); \ + if (!instance->_x) \ + { \ + dlclose(instance->module); \ + free(instance); \ + return NULL; \ + } \ + } +#endif + + F_GETPROC(FSOUND_SetOutput, "_FSOUND_SetOutput@4"); + F_GETPROC(FSOUND_SetDriver, "_FSOUND_SetDriver@4"); + F_GETPROC(FSOUND_SetMixer, "_FSOUND_SetMixer@4"); + F_GETPROC(FSOUND_SetBufferSize, "_FSOUND_SetBufferSize@4"); + F_GETPROC(FSOUND_SetHWND, "_FSOUND_SetHWND@4"); + F_GETPROC(FSOUND_SetMinHardwareChannels, "_FSOUND_SetMinHardwareChannels@4"); + F_GETPROC(FSOUND_SetMaxHardwareChannels, "_FSOUND_SetMaxHardwareChannels@4"); + F_GETPROC(FSOUND_SetMemorySystem, "_FSOUND_SetMemorySystem@20"); + F_GETPROC(FSOUND_Init, "_FSOUND_Init@12"); + F_GETPROC(FSOUND_Close, "_FSOUND_Close@0"); + F_GETPROC(FSOUND_Update, "_FSOUND_Update@0"); + F_GETPROC(FSOUND_SetSFXMasterVolume, "_FSOUND_SetSFXMasterVolume@4"); + F_GETPROC(FSOUND_SetPanSeperation, "_FSOUND_SetPanSeperation@4"); + F_GETPROC(FSOUND_SetSpeakerMode, "_FSOUND_SetSpeakerMode@4"); + F_GETPROC(FSOUND_GetError, "_FSOUND_GetError@0"); + F_GETPROC(FSOUND_GetVersion, "_FSOUND_GetVersion@0"); + F_GETPROC(FSOUND_GetOutput, "_FSOUND_GetOutput@0"); + F_GETPROC(FSOUND_GetOutputHandle, "_FSOUND_GetOutputHandle@0"); + F_GETPROC(FSOUND_GetDriver, "_FSOUND_GetDriver@0"); + F_GETPROC(FSOUND_GetMixer, "_FSOUND_GetMixer@0"); + F_GETPROC(FSOUND_GetNumDrivers, "_FSOUND_GetNumDrivers@0"); + F_GETPROC(FSOUND_GetDriverName, "_FSOUND_GetDriverName@4"); + F_GETPROC(FSOUND_GetDriverCaps, "_FSOUND_GetDriverCaps@8"); + F_GETPROC(FSOUND_GetOutputRate, "_FSOUND_GetOutputRate@0"); + F_GETPROC(FSOUND_GetMaxChannels, "_FSOUND_GetMaxChannels@0"); + F_GETPROC(FSOUND_GetMaxSamples, "_FSOUND_GetMaxSamples@0"); + F_GETPROC(FSOUND_GetSpeakerMode, "_FSOUND_GetSpeakerMode@0"); + F_GETPROC(FSOUND_GetSFXMasterVolume, "_FSOUND_GetSFXMasterVolume@0"); + F_GETPROC(FSOUND_GetNumHWChannels, "_FSOUND_GetNumHWChannels@12"); + F_GETPROC(FSOUND_GetChannelsPlaying, "_FSOUND_GetChannelsPlaying@0"); + F_GETPROC(FSOUND_GetCPUUsage, "_FSOUND_GetCPUUsage@0"); + F_GETPROC(FSOUND_GetMemoryStats, "_FSOUND_GetMemoryStats@8"); + F_GETPROC(FSOUND_Sample_Load, "_FSOUND_Sample_Load@20"); + F_GETPROC(FSOUND_Sample_Alloc, "_FSOUND_Sample_Alloc@28"); + F_GETPROC(FSOUND_Sample_Free, "_FSOUND_Sample_Free@4"); + F_GETPROC(FSOUND_Sample_Upload, "_FSOUND_Sample_Upload@12"); + F_GETPROC(FSOUND_Sample_Lock, "_FSOUND_Sample_Lock@28"); + F_GETPROC(FSOUND_Sample_Unlock, "_FSOUND_Sample_Unlock@20"); + F_GETPROC(FSOUND_Sample_SetMode, "_FSOUND_Sample_SetMode@8"); + F_GETPROC(FSOUND_Sample_SetLoopPoints, "_FSOUND_Sample_SetLoopPoints@12"); + F_GETPROC(FSOUND_Sample_SetDefaults, "_FSOUND_Sample_SetDefaults@20"); + F_GETPROC(FSOUND_Sample_SetDefaultsEx, "_FSOUND_Sample_SetDefaultsEx@32"); + F_GETPROC(FSOUND_Sample_SetMinMaxDistance, "_FSOUND_Sample_SetMinMaxDistance@12"); + F_GETPROC(FSOUND_Sample_SetMaxPlaybacks, "_FSOUND_Sample_SetMaxPlaybacks@8"); + F_GETPROC(FSOUND_Sample_Get, "_FSOUND_Sample_Get@4"); + F_GETPROC(FSOUND_Sample_GetName, "_FSOUND_Sample_GetName@4"); + F_GETPROC(FSOUND_Sample_GetLength, "_FSOUND_Sample_GetLength@4"); + F_GETPROC(FSOUND_Sample_GetLoopPoints, "_FSOUND_Sample_GetLoopPoints@12"); + F_GETPROC(FSOUND_Sample_GetDefaults, "_FSOUND_Sample_GetDefaults@20"); + F_GETPROC(FSOUND_Sample_GetDefaultsEx, "_FSOUND_Sample_GetDefaultsEx@32"); + F_GETPROC(FSOUND_Sample_GetMode, "_FSOUND_Sample_GetMode@4"); + F_GETPROC(FSOUND_Sample_GetMinMaxDistance, "_FSOUND_Sample_GetMinMaxDistance@12"); + F_GETPROC(FSOUND_PlaySound, "_FSOUND_PlaySound@8"); + F_GETPROC(FSOUND_PlaySoundEx, "_FSOUND_PlaySoundEx@16"); + F_GETPROC(FSOUND_StopSound, "_FSOUND_StopSound@4"); + F_GETPROC(FSOUND_SetFrequency, "_FSOUND_SetFrequency@8"); + F_GETPROC(FSOUND_SetVolume, "_FSOUND_SetVolume@8"); + F_GETPROC(FSOUND_SetVolumeAbsolute, "_FSOUND_SetVolumeAbsolute@8"); + F_GETPROC(FSOUND_SetPan, "_FSOUND_SetPan@8"); + F_GETPROC(FSOUND_SetSurround, "_FSOUND_SetSurround@8"); + F_GETPROC(FSOUND_SetMute, "_FSOUND_SetMute@8"); + F_GETPROC(FSOUND_SetPriority, "_FSOUND_SetPriority@8"); + F_GETPROC(FSOUND_SetReserved, "_FSOUND_SetReserved@8"); + F_GETPROC(FSOUND_SetPaused, "_FSOUND_SetPaused@8"); + F_GETPROC(FSOUND_SetLoopMode, "_FSOUND_SetLoopMode@8"); + F_GETPROC(FSOUND_SetCurrentPosition, "_FSOUND_SetCurrentPosition@8"); + F_GETPROC(FSOUND_3D_SetAttributes, "_FSOUND_3D_SetAttributes@12"); + F_GETPROC(FSOUND_3D_SetMinMaxDistance, "_FSOUND_3D_SetMinMaxDistance@12"); + F_GETPROC(FSOUND_IsPlaying, "_FSOUND_IsPlaying@4"); + F_GETPROC(FSOUND_GetFrequency, "_FSOUND_GetFrequency@4"); + F_GETPROC(FSOUND_GetVolume, "_FSOUND_GetVolume@4"); + F_GETPROC(FSOUND_GetAmplitude, "_FSOUND_GetAmplitude@4"); + F_GETPROC(FSOUND_GetPan, "_FSOUND_GetPan@4"); + F_GETPROC(FSOUND_GetSurround, "_FSOUND_GetSurround@4"); + F_GETPROC(FSOUND_GetMute, "_FSOUND_GetMute@4"); + F_GETPROC(FSOUND_GetPriority, "_FSOUND_GetPriority@4"); + F_GETPROC(FSOUND_GetReserved, "_FSOUND_GetReserved@4"); + F_GETPROC(FSOUND_GetPaused, "_FSOUND_GetPaused@4"); + F_GETPROC(FSOUND_GetLoopMode, "_FSOUND_GetLoopMode@4"); + F_GETPROC(FSOUND_GetCurrentPosition, "_FSOUND_GetCurrentPosition@4"); + F_GETPROC(FSOUND_GetCurrentSample, "_FSOUND_GetCurrentSample@4"); + F_GETPROC(FSOUND_GetCurrentLevels, "_FSOUND_GetCurrentLevels@12"); + F_GETPROC(FSOUND_GetNumSubChannels, "_FSOUND_GetNumSubChannels@4"); + F_GETPROC(FSOUND_GetSubChannel, "_FSOUND_GetSubChannel@8"); + F_GETPROC(FSOUND_3D_GetAttributes, "_FSOUND_3D_GetAttributes@12"); + F_GETPROC(FSOUND_3D_GetMinMaxDistance, "_FSOUND_3D_GetMinMaxDistance@12"); + F_GETPROC(FSOUND_3D_Listener_SetCurrent, "_FSOUND_3D_Listener_SetCurrent@8"); + F_GETPROC(FSOUND_3D_Listener_SetAttributes, "_FSOUND_3D_Listener_SetAttributes@32"); + F_GETPROC(FSOUND_3D_Listener_GetAttributes, "_FSOUND_3D_Listener_GetAttributes@32"); + F_GETPROC(FSOUND_3D_SetDopplerFactor, "_FSOUND_3D_SetDopplerFactor@4"); + F_GETPROC(FSOUND_3D_SetDistanceFactor, "_FSOUND_3D_SetDistanceFactor@4"); + F_GETPROC(FSOUND_3D_SetRolloffFactor, "_FSOUND_3D_SetRolloffFactor@4"); + F_GETPROC(FSOUND_FX_Enable, "_FSOUND_FX_Enable@8"); + F_GETPROC(FSOUND_FX_Disable, "_FSOUND_FX_Disable@4"); + F_GETPROC(FSOUND_FX_SetChorus, "_FSOUND_FX_SetChorus@32"); + F_GETPROC(FSOUND_FX_SetCompressor, "_FSOUND_FX_SetCompressor@28"); + F_GETPROC(FSOUND_FX_SetDistortion, "_FSOUND_FX_SetDistortion@24"); + F_GETPROC(FSOUND_FX_SetEcho, "_FSOUND_FX_SetEcho@24"); + F_GETPROC(FSOUND_FX_SetFlanger, "_FSOUND_FX_SetFlanger@32"); + F_GETPROC(FSOUND_FX_SetGargle, "_FSOUND_FX_SetGargle@12"); + F_GETPROC(FSOUND_FX_SetI3DL2Reverb, "_FSOUND_FX_SetI3DL2Reverb@52"); + F_GETPROC(FSOUND_FX_SetParamEQ, "_FSOUND_FX_SetParamEQ@16"); + F_GETPROC(FSOUND_FX_SetWavesReverb, "_FSOUND_FX_SetWavesReverb@20"); + F_GETPROC(FSOUND_Stream_Open, "_FSOUND_Stream_Open@16"); + F_GETPROC(FSOUND_Stream_Create, "_FSOUND_Stream_Create@20"); + F_GETPROC(FSOUND_Stream_Play, "_FSOUND_Stream_Play@8"); + F_GETPROC(FSOUND_Stream_PlayEx, "_FSOUND_Stream_PlayEx@16"); + F_GETPROC(FSOUND_Stream_Stop, "_FSOUND_Stream_Stop@4"); + F_GETPROC(FSOUND_Stream_Close, "_FSOUND_Stream_Close@4"); + F_GETPROC(FSOUND_Stream_SetEndCallback, "_FSOUND_Stream_SetEndCallback@12"); + F_GETPROC(FSOUND_Stream_SetSyncCallback, "_FSOUND_Stream_SetSyncCallback@12"); + F_GETPROC(FSOUND_Stream_GetSample, "_FSOUND_Stream_GetSample@4"); + F_GETPROC(FSOUND_Stream_CreateDSP, "_FSOUND_Stream_CreateDSP@16"); + F_GETPROC(FSOUND_Stream_SetBufferSize, "_FSOUND_Stream_SetBufferSize@4"); + F_GETPROC(FSOUND_Stream_SetPosition, "_FSOUND_Stream_SetPosition@8"); + F_GETPROC(FSOUND_Stream_GetPosition, "_FSOUND_Stream_GetPosition@4"); + F_GETPROC(FSOUND_Stream_SetTime, "_FSOUND_Stream_SetTime@8"); + F_GETPROC(FSOUND_Stream_GetTime, "_FSOUND_Stream_GetTime@4"); + F_GETPROC(FSOUND_Stream_GetLength, "_FSOUND_Stream_GetLength@4"); + F_GETPROC(FSOUND_Stream_GetLengthMs, "_FSOUND_Stream_GetLengthMs@4"); + F_GETPROC(FSOUND_Stream_SetMode, "_FSOUND_Stream_SetMode@8"); + F_GETPROC(FSOUND_Stream_GetMode, "_FSOUND_Stream_GetMode@4"); + F_GETPROC(FSOUND_Stream_SetSubStream, "_FSOUND_Stream_SetSubStream@8"); + F_GETPROC(FSOUND_Stream_GetNumSubStreams, "_FSOUND_Stream_GetNumSubStreams@4"); + F_GETPROC(FSOUND_Stream_SetSubStreamSentence, "_FSOUND_Stream_SetSubStreamSentence@12"); + F_GETPROC(FSOUND_Stream_SetLoopPoints, "_FSOUND_Stream_SetLoopPoints@12"); + F_GETPROC(FSOUND_Stream_SetLoopCount, "_FSOUND_Stream_SetLoopCount@8"); + F_GETPROC(FSOUND_Stream_AddSyncPoint, "_FSOUND_Stream_AddSyncPoint@12"); + F_GETPROC(FSOUND_Stream_DeleteSyncPoint, "_FSOUND_Stream_DeleteSyncPoint@4"); + F_GETPROC(FSOUND_Stream_GetNumSyncPoints, "_FSOUND_Stream_GetNumSyncPoints@4"); + F_GETPROC(FSOUND_Stream_GetSyncPoint, "_FSOUND_Stream_GetSyncPoint@8"); + F_GETPROC(FSOUND_Stream_GetSyncPointInfo, "_FSOUND_Stream_GetSyncPointInfo@8"); + F_GETPROC(FSOUND_Stream_GetOpenState, "_FSOUND_Stream_GetOpenState@4"); + F_GETPROC(FSOUND_Stream_GetNumTagFields, "_FSOUND_Stream_GetNumTagFields@8"); + F_GETPROC(FSOUND_Stream_GetTagField, "_FSOUND_Stream_GetTagField@24"); + F_GETPROC(FSOUND_Stream_FindTagField, "_FSOUND_Stream_FindTagField@20"); + F_GETPROC(FSOUND_Stream_Net_SetProxy, "_FSOUND_Stream_Net_SetProxy@4"); + F_GETPROC(FSOUND_Stream_Net_GetLastServerStatus, "_FSOUND_Stream_Net_GetLastServerStatus@0"); + F_GETPROC(FSOUND_Stream_Net_SetBufferProperties, "_FSOUND_Stream_Net_SetBufferProperties@12"); + F_GETPROC(FSOUND_Stream_Net_GetBufferProperties, "_FSOUND_Stream_Net_GetBufferProperties@12"); + F_GETPROC(FSOUND_Stream_Net_SetMetadataCallback, "_FSOUND_Stream_Net_SetMetadataCallback@12"); + F_GETPROC(FSOUND_Stream_Net_GetStatus, "_FSOUND_Stream_Net_GetStatus@20"); + F_GETPROC(FSOUND_CD_Play, "_FSOUND_CD_Play@8"); + F_GETPROC(FSOUND_CD_SetPlayMode, "_FSOUND_CD_SetPlayMode@8"); + F_GETPROC(FSOUND_CD_Stop, "_FSOUND_CD_Stop@4"); + F_GETPROC(FSOUND_CD_SetPaused, "_FSOUND_CD_SetPaused@8"); + F_GETPROC(FSOUND_CD_SetVolume, "_FSOUND_CD_SetVolume@8"); + F_GETPROC(FSOUND_CD_SetTrackTime, "_FSOUND_CD_SetTrackTime@8"); + F_GETPROC(FSOUND_CD_OpenTray, "_FSOUND_CD_OpenTray@8"); + F_GETPROC(FSOUND_CD_GetPaused, "_FSOUND_CD_GetPaused@4"); + F_GETPROC(FSOUND_CD_GetTrack, "_FSOUND_CD_GetTrack@4"); + F_GETPROC(FSOUND_CD_GetNumTracks, "_FSOUND_CD_GetNumTracks@4"); + F_GETPROC(FSOUND_CD_GetVolume, "_FSOUND_CD_GetVolume@4"); + F_GETPROC(FSOUND_CD_GetTrackLength, "_FSOUND_CD_GetTrackLength@8"); + F_GETPROC(FSOUND_CD_GetTrackTime, "_FSOUND_CD_GetTrackTime@4"); + F_GETPROC(FSOUND_DSP_Create, "_FSOUND_DSP_Create@12"); + F_GETPROC(FSOUND_DSP_Free, "_FSOUND_DSP_Free@4"); + F_GETPROC(FSOUND_DSP_SetPriority, "_FSOUND_DSP_SetPriority@8"); + F_GETPROC(FSOUND_DSP_GetPriority, "_FSOUND_DSP_GetPriority@4"); + F_GETPROC(FSOUND_DSP_SetActive, "_FSOUND_DSP_SetActive@8"); + F_GETPROC(FSOUND_DSP_GetActive, "_FSOUND_DSP_GetActive@4"); + F_GETPROC(FSOUND_DSP_GetClearUnit, "_FSOUND_DSP_GetClearUnit@0"); + F_GETPROC(FSOUND_DSP_GetSFXUnit, "_FSOUND_DSP_GetSFXUnit@0"); + F_GETPROC(FSOUND_DSP_GetMusicUnit, "_FSOUND_DSP_GetMusicUnit@0"); + F_GETPROC(FSOUND_DSP_GetClipAndCopyUnit, "_FSOUND_DSP_GetClipAndCopyUnit@0"); + F_GETPROC(FSOUND_DSP_GetFFTUnit, "_FSOUND_DSP_GetFFTUnit@0"); + F_GETPROC(FSOUND_DSP_MixBuffers, "_FSOUND_DSP_MixBuffers@28"); + F_GETPROC(FSOUND_DSP_ClearMixBuffer, "_FSOUND_DSP_ClearMixBuffer@0"); + F_GETPROC(FSOUND_DSP_GetBufferLength, "_FSOUND_DSP_GetBufferLength@0"); + F_GETPROC(FSOUND_DSP_GetBufferLengthTotal, "_FSOUND_DSP_GetBufferLengthTotal@0"); + F_GETPROC(FSOUND_DSP_GetSpectrum, "_FSOUND_DSP_GetSpectrum@0"); + F_GETPROC(FSOUND_Reverb_SetProperties, "_FSOUND_Reverb_SetProperties@4"); + F_GETPROC(FSOUND_Reverb_GetProperties, "_FSOUND_Reverb_GetProperties@4"); + F_GETPROC(FSOUND_Reverb_SetChannelProperties, "_FSOUND_Reverb_SetChannelProperties@8"); + F_GETPROC(FSOUND_Reverb_GetChannelProperties, "_FSOUND_Reverb_GetChannelProperties@8"); + F_GETPROC(FSOUND_Record_SetDriver, "_FSOUND_Record_SetDriver@4"); + F_GETPROC(FSOUND_Record_GetNumDrivers, "_FSOUND_Record_GetNumDrivers@0"); + F_GETPROC(FSOUND_Record_GetDriverName, "_FSOUND_Record_GetDriverName@4"); + F_GETPROC(FSOUND_Record_GetDriver, "_FSOUND_Record_GetDriver@0"); + F_GETPROC(FSOUND_Record_StartSample, "_FSOUND_Record_StartSample@8"); + F_GETPROC(FSOUND_Record_Stop, "_FSOUND_Record_Stop@0"); + F_GETPROC(FSOUND_Record_GetPosition, "_FSOUND_Record_GetPosition@0"); + F_GETPROC(FSOUND_File_SetCallbacks, "_FSOUND_File_SetCallbacks@20"); + F_GETPROC(FMUSIC_LoadSong, "_FMUSIC_LoadSong@4"); + F_GETPROC(FMUSIC_LoadSongEx, "_FMUSIC_LoadSongEx@24"); + F_GETPROC(FMUSIC_GetOpenState, "_FMUSIC_GetOpenState@4"); + F_GETPROC(FMUSIC_FreeSong, "_FMUSIC_FreeSong@4"); + F_GETPROC(FMUSIC_PlaySong, "_FMUSIC_PlaySong@4"); + F_GETPROC(FMUSIC_StopSong, "_FMUSIC_StopSong@4"); + F_GETPROC(FMUSIC_StopAllSongs, "_FMUSIC_StopAllSongs@0"); + F_GETPROC(FMUSIC_SetZxxCallback, "_FMUSIC_SetZxxCallback@8"); + F_GETPROC(FMUSIC_SetRowCallback, "_FMUSIC_SetRowCallback@12"); + F_GETPROC(FMUSIC_SetOrderCallback, "_FMUSIC_SetOrderCallback@12"); + F_GETPROC(FMUSIC_SetInstCallback, "_FMUSIC_SetInstCallback@12"); + F_GETPROC(FMUSIC_SetSample, "_FMUSIC_SetSample@12"); + F_GETPROC(FMUSIC_SetUserData, "_FMUSIC_SetUserData@8"); + F_GETPROC(FMUSIC_OptimizeChannels, "_FMUSIC_OptimizeChannels@12"); + F_GETPROC(FMUSIC_SetReverb, "_FMUSIC_SetReverb@4"); + F_GETPROC(FMUSIC_SetLooping, "_FMUSIC_SetLooping@8"); + F_GETPROC(FMUSIC_SetOrder, "_FMUSIC_SetOrder@8"); + F_GETPROC(FMUSIC_SetPaused, "_FMUSIC_SetPaused@8"); + F_GETPROC(FMUSIC_SetMasterVolume, "_FMUSIC_SetMasterVolume@8"); + F_GETPROC(FMUSIC_SetMasterSpeed, "_FMUSIC_SetMasterSpeed@8"); + F_GETPROC(FMUSIC_SetPanSeperation, "_FMUSIC_SetPanSeperation@8"); + F_GETPROC(FMUSIC_GetName, "_FMUSIC_GetName@4"); + F_GETPROC(FMUSIC_GetType, "_FMUSIC_GetType@4"); + F_GETPROC(FMUSIC_GetNumOrders, "_FMUSIC_GetNumOrders@4"); + F_GETPROC(FMUSIC_GetNumPatterns, "_FMUSIC_GetNumPatterns@4"); + F_GETPROC(FMUSIC_GetNumInstruments, "_FMUSIC_GetNumInstruments@4"); + F_GETPROC(FMUSIC_GetNumSamples, "_FMUSIC_GetNumSamples@4"); + F_GETPROC(FMUSIC_GetNumChannels, "_FMUSIC_GetNumChannels@4"); + F_GETPROC(FMUSIC_GetSample, "_FMUSIC_GetSample@8"); + F_GETPROC(FMUSIC_GetPatternLength, "_FMUSIC_GetPatternLength@8"); + F_GETPROC(FMUSIC_IsFinished, "_FMUSIC_IsFinished@4"); + F_GETPROC(FMUSIC_IsPlaying, "_FMUSIC_IsPlaying@4"); + F_GETPROC(FMUSIC_GetMasterVolume, "_FMUSIC_GetMasterVolume@4"); + F_GETPROC(FMUSIC_GetGlobalVolume, "_FMUSIC_GetGlobalVolume@4"); + F_GETPROC(FMUSIC_GetOrder, "_FMUSIC_GetOrder@4"); + F_GETPROC(FMUSIC_GetPattern, "_FMUSIC_GetPattern@4"); + F_GETPROC(FMUSIC_GetSpeed, "_FMUSIC_GetSpeed@4"); + F_GETPROC(FMUSIC_GetBPM, "_FMUSIC_GetBPM@4"); + F_GETPROC(FMUSIC_GetRow, "_FMUSIC_GetRow@4"); + F_GETPROC(FMUSIC_GetPaused, "_FMUSIC_GetPaused@4"); + F_GETPROC(FMUSIC_GetTime, "_FMUSIC_GetTime@4"); + F_GETPROC(FMUSIC_GetRealChannel, "_FMUSIC_GetRealChannel@8"); + F_GETPROC(FMUSIC_GetUserData, "_FMUSIC_GetUserData@4"); + + return instance; +} + +static void FMOD_FreeInstance(FMOD_INSTANCE *instance) +{ + if (instance) + { + if (instance->module) + { +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(_WIN64) + FreeLibrary((HMODULE)instance->module); +#else + dlclose(instance->module); +#endif + } + free(instance); + } +} + +#endif diff --git a/tools/gdbst03/Makefile b/tools/gdbst03/Makefile new file mode 100644 index 000000000..5279e5b55 --- /dev/null +++ b/tools/gdbst03/Makefile @@ -0,0 +1,83 @@ +# +# Makefile for GDB Stub for DJGPP/Mingw 0.3 source distribution +# +# Copyright 2000 by Jonathan Brogdon +# + +include Makefile.cfg + +default: + @$(ECHO) Welcome to GDB Stub for DJGPP & Mingw 0.3 source distribution! + @$(ECHO) To make the GDB stub type: + @$(ECHO) make all - Make library and demo programs + @$(ECHO) make library - Make only library + @$(ECHO) make demo - Make demo program + @$(ECHO) make install - Install library and header files + @$(ECHO) make uninstall - Uninstall library and header files + @$(ECHO) make clean - Remove .o files + @$(ECHO) make distclean - Remove ready binaries and .o files + @$(ECHO) make dep - Make dependences + +# Inform make of phony targets +.PHONY: library demo clean blankdep dep distclean install + +all: dep library demo + @$(ECHO) Library and demo program created + +./lib/libgdbst.a: + @mkdir -p lib + @make -s -C ./src/library all + +library: ./lib/libgdbst.a + @$(ECHO) Library created + +demo: ./lib/libgdbst.a + @mkdir -p demo + @make -s -C ./src/demo all + @$(ECHO) Demo program created + +clean: + @make -s -C ./src/library clean + @make -s -C ./src/demo clean + @$(ECHO) Clean complete + +blankdep: +# Create blank depend.dep files to avoid errors + @$(ECHOBLANK) > ./src/library/depend.dep + @$(ECHOBLANK) > ./src/demo/depend.dep + +# Now carry on as usual +dep: blankdep + @make -s -C ./src/library dep + @make -s -C ./src/demo dep + @$(ECHO) Created dependency files + +# Blank all the dependencies too +distclean: blankdep + @make -s -C ./src/library distclean + @make -s -C ./src/demo distclean + @$(RM) -r ./demo/ + @$(RM) -r ./lib/ + @$(ECHO) Cleaned up files + +install: library +ifdef DJGPP + @cp lib/*.a $(DJDIR)/lib + @ginstall -d $(DJDIR)/include + @cp include/*.h $(DJDIR)/include + @$(ECHO) GDB Stub Library for DJGPP installed +endif + +uninstall: +ifdef DJGPP + @$(RM) $(DJDIR)/lib/libgdb.a + @$(RM) $(DJDIR)/include/i386-stub.h + @$(ECHO) GDB Stub Library for DJGPP uninstalled +ifdef DJGPP + + + + + + + diff --git a/tools/gdbst03/announce b/tools/gdbst03/announce new file mode 100644 index 000000000..ac976b644 --- /dev/null +++ b/tools/gdbst03/announce @@ -0,0 +1,27 @@ +GDB Stub for DJGPP 0.1 Announcement +=================================== + +GDB Stub for DJGPP Copyright 2000 by Jonathan Brogdon + +Hello. + + I'd like to announce the GDB Stub for DJGPP for DJGPP, the latest version of +a GDB stub for DJGPP targets. The GDB Stub for DJGPP conforms to the GNU GDB stub +interface as specified in the GDB User's Manual. It allows for debugging of a +DJGPP target remotely over a serial link with GDB. + + It comes with an example program for demonstrating remote debugging of +DJGPP targets, and documentation (man and HTML pages). + + The GDB Stub for DJGPP is distributed under the GNU Library General Public License +(LGPL). + + If you have any questions relating to libsocket, please mail me and I'll +be happy to help. + + Thanks, + + Jonathan Brogdon + + + June 29th 2000 diff --git a/tools/gdbst03/include/i386-stub.h b/tools/gdbst03/include/i386-stub.h new file mode 100644 index 000000000..092a3dfc6 --- /dev/null +++ b/tools/gdbst03/include/i386-stub.h @@ -0,0 +1,43 @@ +/**************************************************************************** + * + * i386-stub.h + * + * Description: Data definitions and constants for low level + * GDB server support. + * + * Terms of use: This software is provided for use under the terms + * and conditions of the GNU General Public License. + * You should have received a copy of the GNU General + * Public License along with this program; if not, write + * to the Free Software Foundation, Inc., 59 Temple Place + * Suite 330, Boston, MA 02111-1307, USA. + * + * Credits: Created by Jonathan Brogdon + * + * History + * Engineer: Date: Notes: + * --------- ----- ------ + * Jonathan Brogdon 20000617 Genesis + * Gordon Schumacher 20020212 Updated for modularity + * + ****************************************************************************/ +#ifndef _GDBSTUB_H_ +#define _GDBSTUB_H_ + + +#ifdef __cplusplus +extern "C" { +#endif +extern int gdb_serial_init(unsigned int port, unsigned int speed); +extern void gdb_target_init(void); +extern void gdb_target_close(void); + +extern void set_debug_traps(void); +extern void restore_traps(void); +extern void breakpoint(void); +#ifdef __cplusplus +} +#endif + + +#endif /* _GDBSTUB_H_ */ diff --git a/tools/gdbst03/install b/tools/gdbst03/install new file mode 100644 index 000000000..b92c39c04 --- /dev/null +++ b/tools/gdbst03/install @@ -0,0 +1,20 @@ +The makefile contains the information about the target products +available. + +Note: Makefile.cfg contains macros for various tools used during +the build process. Of particular note: some folks use the echo.exe +that is available from the DJGPP (or other) site(s). Others may not +have installed this, and therefore calls to echo during the build +will use the built-in DOS echo command. When attempting to echo a +blank line, the arguments to these two echo commands are different. +Therefore, makefile.cfg contains the macro ECHOBLANK. Please set +this macro according to the needs of your environment. If you change +this in makefile.cfg, it will be picked up by all other project +makefiles. + +Type 'make' to see a list of targets. When the 'install' +target is made, the libgdb.a will be copied into your $(DJDIR)/lib +directory. In addition, the i386-stub.h file will be copied into +your $(DJDIR)/include directory. The uninstall target will remove +these files. + diff --git a/tools/gdbst03/license b/tools/gdbst03/license new file mode 100644 index 000000000..4356f26ed --- /dev/null +++ b/tools/gdbst03/license @@ -0,0 +1,454 @@ + +GNU LIBRARY GENERAL PUBLIC LICENSE +********************************** + + Version 2, June 1991 + + Copyright (C) 1991 Free Software Foundation, Inc. + 675 Mass Ave, Cambridge, MA 02139, 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 library GPL. It is + numbered 2 because it goes with version 2 of the ordinary GPL.] + +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 Library General Public License, applies to some +specially designated Free Software Foundation software, and to any +other libraries whose authors decide to use it. You can use it for +your libraries, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it in +new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the 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 a program 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. + + Our method of protecting your rights has two steps: (1) copyright +the library, and (2) offer you this license which gives you legal +permission to copy, distribute and/or modify the library. + + Also, for each distributor's protection, we want to make certain +that everyone understands that there is no warranty for this free +library. If the library is modified by someone else and passed on, we +want its recipients to know that what they have is not the original +version, so that any problems introduced by others will not reflect on +the original authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that companies distributing free +software will individually obtain patent licenses, thus in effect +transforming the program into proprietary software. To prevent this, +we have made it clear that any patent must be licensed for everyone's +free use or not licensed at all. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License, which was designed for utility +programs. This license, the GNU Library General Public License, +applies to certain designated libraries. This license is quite +different from the ordinary one; be sure to read it in full, and don't +assume that anything in it is the same as in the ordinary license. + + The reason we have a separate public license for some libraries is +that they blur the distinction we usually make between modifying or +adding to a program and simply using it. Linking a program with a +library, without changing the library, is in some sense simply using +the library, and is analogous to running a utility program or +application program. However, in a textual and legal sense, the linked +executable is a combined work, a derivative of the original library, +and the ordinary General Public License treats it as such. + + Because of this blurred distinction, using the ordinary General +Public License for libraries did not effectively promote software +sharing, because most developers did not use the libraries. We +concluded that weaker conditions might promote sharing better. + + However, unrestricted linking of non-free programs would deprive the +users of those programs of all benefit from the free status of the +libraries themselves. This Library General Public License is intended +to permit developers of non-free programs to use free libraries, while +preserving your freedom as a user of such programs to change the free +libraries that are incorporated in them. (We have not seen how to +achieve this as regards changes in header files, but we have achieved +it as regards changes in the actual functions of the Library.) The +hope is that this will lead to faster development of free libraries. + + 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, while the latter only +works together with the library. + + Note that it is possible for a library to be covered by the ordinary +General Public License rather than by this special one. + + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library which + contains a notice placed by the copyright holder or other + authorized party saying it may be distributed under the terms of + this Library 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. + + 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. + + 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. + + 6. As an exception to the Sections above, you may also compile 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. 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. + + c. 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. + + d. 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 source code distributed need not include anything + that is normally distributed (in either source or binary form) + with the major components (compiler, kernel, and so on) of the + operating system on which the executable runs, unless that + component itself accompanies the executable. + + 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. + + 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 to this License. + + 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 Library 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. + + 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 + diff --git a/tools/gdbst03/makefile.cfg b/tools/gdbst03/makefile.cfg new file mode 100644 index 000000000..4265258a7 --- /dev/null +++ b/tools/gdbst03/makefile.cfg @@ -0,0 +1,67 @@ +# +# Makefile.cfg for GDB stub for DJGPP and Mingw +# +# libgdbst Copyright 2000 by Jonathan Brogodn +# + +# +# GNU compiler & tools' flags +# +CC = gcc +CFLAGS = -Wall -Werror -march=i486 -O2 -g + +# Archiver +AR = ar +ARFLAGS = -r + +# Stripper +STRIP = strip + +# Assembler +AS = as +ASFLAGS = + +# Linker +LD = ld +LDFLAGS = + +# Remove +RM = rm -f + +# Echo +ECHO = echo + +# Echo Blank +#ECHOBLANK = echo "" +ECHOBLANK = echo. + +# +# check for OS... badly +# + +ifndef DJDIR +ifndef DJGPP + WINDOWS=1 +endif +endif + +ifndef windir +ifndef WINDOWS + DJGPP=1 +endif +endif + +# +# Rules +# +.SUFFIXES: .c .asm .o + +.asm.o: + @$(CC) $(CFLAGS) -I$(INC_PATH) -c -o ./$@ ./$< + +.s.o: + @$(AS) $(ASFLAGS) ./$< + +.c.o : + @$(CC) $(CFLAGS) -c -I$(INC_PATH) -c -o ./$@ ./$< + diff --git a/tools/gdbst03/readme b/tools/gdbst03/readme new file mode 100644 index 000000000..316e61cae --- /dev/null +++ b/tools/gdbst03/readme @@ -0,0 +1,171 @@ +GDB Stub for DJGPP 0.2 Readme File +================================== + +Copyright +--------- +GDB Stub for DJGPP is distributed under the terms of the GNU Library +General Public License (GNU LGPL) - please see the document LICENSE, +which should be found in the same directory as this file. + +Copyright (c) 2000 by Jonathan Brogdon, 2002 by Gordon Schumacher + +What It Does +------------ +The GDB stub is used to debug a DJGPP target remotely over a one of +the PC COM ports. GDB, running on a host machine, communicates with +the target using the GDB serial protocol over the serial link. For +more information on the GDB stub, see "Debugging with GDB, The GNU +Source-Level Debugger", by Richard M. Stallman and Roland H. Pesch +(http://sources.redhat.com/gdb/download/onlinedocs/gdb.html) + +How It Works +------------ + +Exceptions: + +The GDB stub needs to handle all processor exceptions. Since these +exceptions already handled by DJGPP, we cannot handle them directly. +DJGPP maps all processor exceptions to signals. Therefore, we can +install the GDB stub handler as the signal handler for those signals +that represent processor exceptions. The following table shows the +processor exception to signal mapping: + + Exception/Interrupt: Exception #: Signal: + ------------------- ----------- ------ + Divide Error 0 SIGFPE + Debug Exception 1 SIGTRAP + NMI Interrupt 2 No signal defined + Breakpoint 3 SIGTRAP + INTO-detected overflow 4 SIGFPE + BOUND Range Exceeded 5 SIGSEGV + Invalid Opcode 6 No signal defined + Coprocessor not available 7 SIGNOFP + Double Fault 8 SIGSEGV + Coprocessor Seg overrun 9 SIGSEGV + Invalid Task State Seg 10 No signal defined + Segment not present 11 SIGSEGV + Stack Fault 12 SIGSEGV + General Protection Fault 13 SIGSEGV + Page Fault 14 SIGSEGV + Intel Reserved 15 No signal defined + Coprocessor Error 16 SIGFPE + +The GDB stub handler services requests from the GDB host. These +requests are seen by the GDB stub handler as command messages from +the GDB host. These commands and command formats are defined in +"Debugging with GDB, The GNU Source-Level Debugger", by Richard M. +Stallman and Roland H. Pesch (http://sources.redhat.com/gdb/ +download/onlinedocs/gdb.html -- one of many sources). + +Serial Interface: + +Interface functions for sending and receiving characters from the +serial interface must be provided by the engineer porting the GDB +stub. The following funtions must be provided to support the +implementation. + + int getDebugChar(void); + void putDebugChar(int c); + +There are a variety of serial libraries for DJGPP. The user may +already be using one of these libraries in their application, and +installing more than one serial library often causes conflicts. +To this end, a modular function layer was written that allows any +serial library to be used with the GDB stub. Layers have been +written to support SVAsync, DZComm, and the _bios_serialcom() +function. At the time of this writing, DZComm appears to work the +best for serial debugging. + +Hard Coded Breakpoint: + +A breakpoint() function is provided to manually invoke the stub. +This function, inserts a breakpoint instruction directly in the code +to invoke the GDB stub handler. + +How You Use It +-------------- +First, you need to select a serial library. In the i386-supp.c file, +there are lines of the form + + // #include "some_layer.h" + +Uncomment the line for the serial library you intend to use - or add +a new include line for a file written for some other library. +In the main() function of your target program, you should initilize +the GDB serial handlers and the GDB stub. The following functions +are provided in the GDB stub library for this purpose. + + gdb_serial_init(unsigned int port, unsigned int speed); + gdb_target_init(void); + +Where, port is the COM port number, and speed is the baud rate for +the serial link. + +After initialing the GDB serial interface and target, you should +invoke the breakpoint() function somewhere. You may choose to do +this immediately after initialization, or at a specific location in +your code where you wish to set a breakpoint. By putting the +breakpoint() function in the beginning of main(), you can use the +GDB host to set a breakpoint at any place in your code. + +Make sure that you use the '-g' option when compiling your files with +gcc. + +After the target executable is running, start up gdb on the host, +passing the target executable as an argument. + + Example: gdb demo.exe + +Now, tell gdb which serial interface to use for communicating to +the target. + + Example: (gdb) target remote COM1 + +This example uses COM1 on the host to communicate with the target. +GDB is now 'listening' on COM for a valid GDB serial packet. + +Once your GDB host finds your target, you may need to tell GDB where +to find any source files which were used to generate your program. +Use the directory command to do this. + + Example: (gdb) directory ../src/demo + +That's it. You should now be able to single step through code, set +breakpoints, set variables, examine variables, any anthing else that +you would normally use GDB to accomplish. + +What You Build +-------------- +Read the INSTALL file for more information on installing the GDB stub +library. After installing the library, your code should include +i386-stub.h for function prototypes. In addition, your code should +link against the libgdb.a library. The source for a demonstration +program has been included with this distributias an example. +As an alternative, you can simply include the i386-stub and i386-supp +files and the layer header for the serial library you plan to use into +your project and link them in directly. + +For More Info +------------- +See "Debugging with GDB, The GNU Source-Level Debugger", by Richard +M. Stallman and Roland H. Pesch (http://sources.redhat.com/gdb/ +download/onlinedocs/gdb.html -- one of many sources). + +TODO +---- +Port for network operation. + +Contact Info +------------ +My contact info is below. If you have any comments, suggestions, bug +reports or problems, please mail me, and I'll see what I can do. + + Regards, + Jonathan Brogdon + + 6th June 2000 + + Modular update: + Gordon Schumacher + + 12th February 2002 \ No newline at end of file diff --git a/tools/gdbst03/src/demo/crc_16.c b/tools/gdbst03/src/demo/crc_16.c new file mode 100644 index 000000000..ad1f53cd1 --- /dev/null +++ b/tools/gdbst03/src/demo/crc_16.c @@ -0,0 +1,46 @@ +#define POLY 0x8408 +/* +// 16 12 5 +// this is the CCITT CRC 16 polynomial X + X + X + 1. +// This works out to be 0x1021, but the way the algorithm works +// lets us use 0x8408 (the reverse of the bit pattern). The high +// bit is always assumed to be set, thus we only use 16 bits to +// represent the 17 bit value. +*/ + +#include "crc.h" + +WORD crc16(char *data_p, WORD length) +{ + unsigned char i; + unsigned int data; + unsigned int crc = 0xffff; + + if (length == 0) + return (~crc); + + do + { + for (i=0, data=(unsigned int)0xff & *data_p++; + i < 8; + i++, data >>= 1) + { + if ((crc & 0x0001) ^ (data & 0x0001)) + crc = (crc >> 1) ^ POLY; + else crc >>= 1; + } + } while (--length); + + crc = ~crc; + data = crc; + crc = (crc << 8) | ((data >> 8) & 0xff); + + return (crc); +} + + + + + + + diff --git a/tools/gdbst03/src/demo/makefile b/tools/gdbst03/src/demo/makefile new file mode 100644 index 000000000..ab48954b2 --- /dev/null +++ b/tools/gdbst03/src/demo/makefile @@ -0,0 +1,42 @@ +# +# Makefile for GDB Stub demo +# Written by Jonathan Brogodn +# +# GDB Stub for DJGPP Copyright 2000 by Jonathan Brogdon +# + +include ../../Makefile.cfg + +CFLAGS += -g +CFLAGS += -I../../include -I../include -I. +CFLAGS += -DDEBUG_COM_PORT=1 +CFLAGS += -DDEBUG_COM_PORT_SPEED=9600 +CFLAGS += -DREMOTE_DEBUGGING + +# Objects to build +OBJS = serdbg.o crc_16.o + +all: demo + +demo: $(OBJS) +ifdef DJGPP + @$(LD) $(LDFLAGS) -Map ./$@.map -o../../demo/$@.exe $(DJDIR)/lib/crt0.o $(OBJS) -L$(DJDIR)/lib -L../../lib -lgdbst -ldzcom -lc -lgcc +endif +ifdef WINDOWS + @$(LD) $(LDFLAGS) -Map ./$@.map -o../../demo/$@.exe $(DJDIR)/lib/crt0.o $(OBJS) -L../../lib -lgdbst -lwsock32 -lc -lgcc +endif + +clean: + @$(RM) $(OBJS) + @$(RM) *.map + +distclean: clean + @$(RM) $(OBJS) + @$(RM) depend.dep + @$(RM) ../../demo/*.exe + +dep: + @$(CC) $(CFLAGS) -M *.c > depend.dep + +$(OBJS): +include depend.dep diff --git a/tools/gdbst03/src/demo/serdbg.c b/tools/gdbst03/src/demo/serdbg.c new file mode 100644 index 000000000..01778789c --- /dev/null +++ b/tools/gdbst03/src/demo/serdbg.c @@ -0,0 +1,102 @@ +/*********************************************************************** + * serdbg.c + * + * Description: Pretty simple demonstration program. It accomplishes + * the following. + * + * 1. Allocate a block of memory Feel free to change + * size (memBlockSize) with debugger. + * + * 2. Writes a word pattern to the entire block. Feel + * free to change the pattern (memPatternWord) with + * debugger. + * + * 3. Computes the CRC-16 on the block. Feel free to + * check the size with the debuger. + * + * 4. Free the memory block allocated in step 1. Repeat + * step 1. If you wish to exit, set doneFlag to 0 with + * the debugger. + * + * Credits: Created by Jonathan Brogdon + * + * Terms of use: Use as you will. + * + * Global Data: None. + * Global Functions: main + * + * History + * Engineer: Date: Notes: + * --------- ----- ------ + * Jonathan Brogdon 070500 Genesis + * + ***********************************************************************/ +#include +#include +#include +#include + +#define MEM_BLOCK_SIZE 100 /* Words */ +#define MEM_PATTERN_WORD 0x55AA + +void write_mem_pattern(unsigned short*, unsigned short, unsigned short); + +/************************************************************************ + * + * main() + * + ************************************************************************/ +int main(int argc, char *argv[]) +{ + volatile int doneFlag = 0; + unsigned short crcValue = 0; + unsigned short * memBlockPtr = NULL; + short memBlockSize = MEM_BLOCK_SIZE; + short memPatternWord = MEM_PATTERN_WORD; + +#ifdef REMOTE_DEBUGGING + /* Only setup if demonstrating remote debugging */ + gdb_serial_init(DEBUG_COM_PORT,DEBUG_COM_PORT_SPEED); + gdb_target_init(); + breakpoint(); +#endif + + while(doneFlag != 1) + { + memBlockSize = MEM_BLOCK_SIZE; + memPatternWord = MEM_PATTERN_WORD; + memBlockPtr = (unsigned short *) malloc((int)memBlockSize); + + write_mem_pattern(memBlockPtr, memBlockSize, memPatternWord); + + crcValue = crc16((char *)memBlockPtr,memBlockSize); + + free(memBlockPtr); + } + + exit(0); +} + +/************************************************************************ + * + * write_mem_pattern() + * + * Description: Writes a word pattern to a block of RAM. + * + ************************************************************************/ +void write_mem_pattern(unsigned short *block, unsigned short blockSize, unsigned short patternWord) +{ + int index = 0; + + for(index = 0; index < blockSize; index++) + { + block[index] = patternWord; + } +} + + + + + + + diff --git a/tools/gdbst03/src/include/crc.h b/tools/gdbst03/src/include/crc.h new file mode 100644 index 000000000..937d0b794 --- /dev/null +++ b/tools/gdbst03/src/include/crc.h @@ -0,0 +1,20 @@ +/* + * CRC.H - header file for CRC functions + */ + +#ifndef _CRC_H_ +#define _CRC_H_ + +#include /* For size_t */ + +typedef unsigned char BYTE; +typedef unsigned short WORD; +typedef unsigned long DWORD; + +/* +** File: CRC-16.C +*/ + +WORD crc16(char *data_p, WORD length); + +#endif /* _CRC_H_ */ diff --git a/tools/gdbst03/src/include/i386-supp.h b/tools/gdbst03/src/include/i386-supp.h new file mode 100644 index 000000000..e1923377c --- /dev/null +++ b/tools/gdbst03/src/include/i386-supp.h @@ -0,0 +1,30 @@ +/**************************************************************************** + * + * i386-supp.h + * + * Description: Data definitions and constants for low level + * GDB stub support. + * + * Terms of use: This software is provided for use under the terms + * and conditions of the GNU General Public License. + * You should have received a copy of the GNU General + * Public License along with this program; if not, write + * to the Free Software Foundation, Inc., 59 Temple Place + * Suite 330, Boston, MA 02111-1307, USA. + * + * Credits: Created by Jonathan Brogdon + * + * History + * Engineer: Date: Notes: + * --------- ----- ------ + * Jonathan Brogdon 20000629 Genesis + * Gordon Schumacher 20020212 Updated for modularity + * + ****************************************************************************/ +#ifndef _GDBSUPP_H_ +#define _GDBSUPP_H_ + +extern int putDebugChar(char c); +extern int getDebugChar(void); + +#endif /* _GDBSUPP_H_ */ diff --git a/tools/gdbst03/src/library/bios_layer.h b/tools/gdbst03/src/library/bios_layer.h new file mode 100644 index 000000000..946f40997 --- /dev/null +++ b/tools/gdbst03/src/library/bios_layer.h @@ -0,0 +1,137 @@ +//======================================================================================================= +// bios_layer.h - Serial command layer for standard BIOS calls +// It's here if you want it, but I wouldn't suggest it... +//======================================================================================================= + +//======================================================================================================= +//======================================================================================================= + +#ifndef _BIOS_LAYER_H +#define _BIOS_LAYER_H + + +//=============================================================================== +// Include files +//=============================================================================== + +#include + +//=============================================================================== +// Static variable definitions +//=============================================================================== + +unsigned comport; + +//=============================================================================== +// Inline function definitions +//=============================================================================== + +#define BIOS_SER_TIMEOUT 1000000 + +// Initialize the serial library +// Should return 0 if no error occurred +__inline int GDBStub_SerInit(int port) +{ + comport = (unsigned) port; + return 0; +} + + +// Set the serial port speed (and other configurables) +// Should return 0 if the speed is set properly +__inline int GDBStub_SerSpeed(int speed) +{ + unsigned bps; + + switch (speed) + { + case 110: + bps = _COM_110; + break; + + case 150: + bps = _COM_150; + break; + + case 300: + bps = _COM_300; + break; + + case 600: + bps = _COM_600; + break; + + case 1200: + bps = _COM_1200; + break; + + case 2400: + bps = _COM_2400; + break; + + case 4800: + bps = _COM_4800; + break; + + case 9600: + default: + bps = _COM_9600; + break; + } + + _bios_serialcom(_COM_INIT, comport, + bps | _COM_NOPARITY | _COM_CHR8 | _COM_STOP1); + return 0; +} + + +// Check to see if there's room in the buffer to send data +// Should return 0 if it is okay to send +__inline int GDBStub_SerSendOk(void) +{ + return 0; +} + + +// Send a character to the serial port +// Should return 0 if the send succeeds +__inline int GDBStub_SerSend(int c) +{ + register int ret; + register int timeout = 0; + + do + { + ret = _bios_serialcom(_COM_SEND, comport, (unsigned) c); + } while((ret != 0) && (timeout++ < BIOS_SER_TIMEOUT)); + return (timeout >= BIOS_SER_TIMEOUT); +} + + +// Check to see if there are characters waiting in the buffer +// Should return 0 if there's data waiting +__inline int GDBStub_SerRecvOk(void) +{ + return 0; +} + + +// Read a character from the serial port +// Should return the character read +__inline int GDBStub_SerRecv(void) +{ + register int data; + register int timeout = 0; + + do + { + data = _bios_serialcom(_COM_RECEIVE, comport, 0) & 0xff; + } while((data > 0xff) && (timeout++ < BIOS_SER_TIMEOUT)); + + return data; +} + + + + +#endif diff --git a/tools/gdbst03/src/library/dzc_layer.h b/tools/gdbst03/src/library/dzc_layer.h new file mode 100644 index 000000000..cc083077f --- /dev/null +++ b/tools/gdbst03/src/library/dzc_layer.h @@ -0,0 +1,169 @@ +//======================================================================================================= +// dzc_layer.h - Serial command layer for DZcomm +// +//======================================================================================================= + +//======================================================================================================= +//======================================================================================================= + +#ifndef _DZC_LAYER_H +#define _DZC_LAYER_H + + +//=============================================================================== +// Include files +//=============================================================================== + +#include + +//=============================================================================== +// Static variable definitions +//=============================================================================== + +comm_port *comport; + +//=============================================================================== +// Inline function definitions +//=============================================================================== + +// Initialize the serial library +// Should return 0 if no error occurred +__inline int GDBStub_SerInit(int port) +{ + int ret; + comm com; + + ret = dzcomm_init(); + if (ret != 0) + { + switch (port) + { + case 4: + com = _com4; + break; + + case 3: + com = _com3; + break; + + case 2: + com = _com2; + break; + + case 1: + default: + com = _com1; + break; + } + comport = comm_port_init(com); + } + return (ret == 0); +} + +// Set the serial port speed (and other configurables) +// Should return 0 if the speed is set properly +__inline int GDBStub_SerSpeed(int speed) +{ + baud_bits bps; + + switch (speed) + { + case 110: + bps = _110; + break; + + case 150: + bps = _150; + break; + + case 300: + bps = _300; + break; + + case 600: + bps = _600; + break; + + case 1200: + bps = _1200; + break; + + case 2400: + bps = _2400; + break; + + case 4800: + bps = _4800; + break; + + case 9600: + bps = _9600; + break; + + case 19200: + bps = _19200; + break; + + case 38400: + bps = _38400; + break; + + case 57600: + bps = _57600; + break; + + case 115200: + default: + bps = _115200; + break; + } + + comm_port_set_baud_rate(comport, bps); + comm_port_set_parity(comport, NO_PARITY); + comm_port_set_data_bits(comport, BITS_8); + comm_port_set_stop_bits(comport, STOP_1); + comm_port_set_flow_control(comport, RTS_CTS); + comm_port_install_handler(comport); + + return 0; +} + +// Check to see if there's room in the buffer to send data +// Should return 0 if it is okay to send +__inline int GDBStub_SerSendOk(void) +{ + return (comm_port_out_full(comport) == 0); +} + +// Send a character to the serial port +// Should return 0 if the send succeeds +__inline int GDBStub_SerSend(int c) +{ + return comm_port_out(comport, (unsigned char) c); +} + +// Check to see if there are characters waiting in the buffer +// Should return 0 if there's data waiting +__inline int GDBStub_SerRecvOk(void) +{ + return (comm_port_in_empty(comport) == 0); +} + +// Read a character from the serial port +// Should return the character read +__inline int GDBStub_SerRecv(void) +{ + return comm_port_test(comport); +} + + + + +#endif + +/*================================================================== + + $Log: $ + + +===============================================================*/ diff --git a/tools/gdbst03/src/library/i386-stub.c b/tools/gdbst03/src/library/i386-stub.c new file mode 100644 index 000000000..1ab2ceeeb --- /dev/null +++ b/tools/gdbst03/src/library/i386-stub.c @@ -0,0 +1,1555 @@ +/**************************************************************************** + + THIS SOFTWARE IS NOT COPYRIGHTED + + HP offers the following for use in the public domain. HP makes no + warranty with regard to the software or it's performance and the + user accepts the software "AS IS" with all faults. + + HP DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED, WITH REGARD + TO THIS SOFTWARE INCLUDING BUT NOT LIMITED TO THE WARRANTIES + OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + +****************************************************************************/ + +/**************************************************************************** + * Header: remcom.c,v 1.34 91/03/09 12:29:49 glenne Exp $ + * + * Module name: remcom.c $ + * Revision: 1.34 $ + * Date: 91/03/09 12:29:49 $ + * Contributor: Lake Stevens Instrument Division$ + * + * Description: low level support for gdb debugger. $ + * + * Considerations: only works on target hardware $ + * + * Written by: Glenn Engel $ + * ModuleState: Experimental $ + * + * NOTES: See Below $ + * + * Modified for 386 by Jim Kingdon, Cygnus Support. + * + * To enable debugger support, two things need to happen. One, a + * call to set_debug_traps() is necessary in order to allow any breakpoints + * or error conditions to be properly intercepted and reported to gdb. + * Two, a breakpoint needs to be generated to begin communication. This + * is most easily accomplished by a call to breakpoint(). Breakpoint() + * simulates a breakpoint by executing a trap #1. + * + * The external function exceptionHandler() is + * used to attach a specific handler to a specific 386 vector number. + * It should use the same privilege level it runs at. It should + * install it as an interrupt gate so that interrupts are masked + * while the handler runs. + * + * Because gdb will sometimes write to the stack area to execute function + * calls, this program cannot rely on using the supervisor stack so it + * uses it's own stack area reserved in the int array remcomStack. + * + ************* + * + * The following gdb commands are supported: + * + * command function Return value + * + * g return the value of the CPU registers hex data or ENN + * G set the value of the CPU registers OK or ENN + * + * mAA..AA,LLLL Read LLLL bytes at address AA..AA hex data or ENN + * MAA..AA,LLLL: Write LLLL bytes at address AA.AA OK or ENN + * + * c Resume at current address SNN ( signal NN) + * cAA..AA Continue at address AA..AA SNN + * + * s Step one instruction SNN + * sAA..AA Step one instruction from AA..AA SNN + * + * k kill + * + * ? What was the last sigval ? SNN (signal NN) + * + * All commands and responses are sent with a packet which includes a + * checksum. A packet consists of + * + * $#. + * + * where + * :: + * :: < two hex digits computed as modulo 256 sum of > + * + * When a packet is received, it is first acknowledged with either '+' or '-'. + * '+' indicates a successful transfer. '-' indicates a failed transfer. + * + * Example: + * + * Host: Reply: + * $m0,10#2a +$00010203040506070809101112131415#42 + * + ****************************************************************************/ + +#include +#include +#ifdef DJGPP +#include +#include +#include +#include +#endif //#ifdef DJGPP + + +/* + * + * external low-level support routines + */ + +extern void putDebugChar(); /* write a single character */ +extern int getDebugChar(); /* read and return a single char */ +#ifndef DJGPP +extern void exceptionHandler(); /* assign an exception handler */ +#endif + +/* + * BUFMAX defines the maximum number of characters in inbound/outbound buffers + * at least NUMREGBYTES*2 are needed for register packets + */ +#define BUFMAX 400 + +/* + * boolean flag. != 0 means we've been initialized + */ +static char gdb_initialized; + +/* + * debug > 0 prints ill-formed commands in valid packets & checksum errors + */ +int remote_debug; + +/* + * Hexadecimal character string. + */ +#ifndef DJGPP +static const char hexchars[]="0123456789abcdef"; +#else +static char hexchars[]="0123456789abcdef"; +#endif + +/* + * Number of registers. +*/ +#define NUMREGS 16 + +/* + * Number of bytes of registers. +*/ +#define NUMREGBYTES (NUMREGS * 4) + +/* + * i386 Registers + */ +enum regnames {EAX, ECX, EDX, EBX, ESP, EBP, ESI, EDI, + PC /* also known as eip */, + PS /* also known as eflags */, + CS, SS, DS, ES, FS, GS +}; + +/* + * Register storage buffer. + */ +static int registers[NUMREGS]; + +/* + * Address of a routine to RTE to if we get a memory fault. +*/ +#ifndef DJGPP +static void (*volatile mem_fault_routine) () = NULL; +#else +static void (*mem_fault_routine)() = NULL; +#endif + +/* I/O buffers */ +static char remcomInBuffer[BUFMAX]; +static char remcomOutBuffer[BUFMAX]; + +#if !(defined(DJGPP) || defined(_WIN32)) //MF +#define STACKSIZE 10000 +int remcomStack[STACKSIZE/sizeof(int)]; +static int* stackPtr = &remcomStack[STACKSIZE/sizeof(int) - 1]; +#endif + +#ifdef DJGPP +static void lock_handler_data(void); +#endif //#ifdef DJGPP + +void _returnFromException (); + +/*************************** ASSEMBLY CODE MACROS *************************/ +/* */ + +extern void +return_to_prog (); + +/* Restore the program's registers (including the stack pointer, which + means we get the right stack and don't have to worry about popping our + return address and any stack frames and so on) and return. */ +asm(".text"); +asm(".globl _return_to_prog"); +asm("_return_to_prog:"); +asm(" movw _registers+44, %ss"); +asm(" movl _registers+16, %esp"); +asm(" movl _registers+4, %ecx"); +asm(" movl _registers+8, %edx"); +asm(" movl _registers+12, %ebx"); +asm(" movl _registers+20, %ebp"); +asm(" movl _registers+24, %esi"); +asm(" movl _registers+28, %edi"); +asm(" movw _registers+48, %ds"); +asm(" movw _registers+52, %es"); +asm(" movw _registers+56, %fs"); +asm(" movw _registers+60, %gs"); +asm(" movl _registers+36, %eax"); +asm(" pushl %eax"); /* saved eflags */ +asm(" movl _registers+40, %eax"); +asm(" pushl %eax"); /* saved cs */ +asm(" movl _registers+32, %eax"); +asm(" pushl %eax"); /* saved eip */ +asm(" movl _registers, %eax"); +/* use iret to restore pc and flags together so + that trace flag works right. */ +asm(" iret"); + +/* + * BREAKPOINT macro + */ +#ifdef _MSC_VER //MF +#define BREAKPOINT() __asm int 3; +#else +#define BREAKPOINT() asm(" int $3"); +#endif + +/* + * Store the error code here just in case the user cares. +*/ +int gdb_i386errcode; + +/* + * Store the vector number here (since GDB only gets the signal + * number through the usual means, and that's not very specific). + */ +#ifndef _WIN32 //MF +int gdb_i386vector = -1; +#endif // !_WIN32 + +#if defined(DJGPP) || defined(_WIN32) +static void handle_exception(int); +#endif + +#ifdef DJGPP + +/*********************************************************************** + * save_regs + * + * Description: Retreives the i386 registers as they were when the + * exception occurred. Registers are stored in the + * local static buffer. + * + * Inputs: None. + * Outputs: None. + * Returns: None. + * + ***********************************************************************/ +static void save_regs(void) +{ + registers[EAX] = (int) __djgpp_exception_state->__eax; + registers[ECX] = (int) __djgpp_exception_state->__ecx; + registers[EDX] = (int) __djgpp_exception_state->__edx; + registers[EBX] = (int) __djgpp_exception_state->__ebx; + registers[ESP] = (int) __djgpp_exception_state->__esp; + registers[EBP] = (int) __djgpp_exception_state->__ebp; + registers[ESI] = (int) __djgpp_exception_state->__esi; + registers[EDI] = (int) __djgpp_exception_state->__edi; + registers[PC] = (int) __djgpp_exception_state->__eip; + registers[PS] = (int) __djgpp_exception_state->__eflags; + registers[CS] = (int) __djgpp_exception_state->__cs; + registers[SS] = (int) __djgpp_exception_state->__ss; + registers[DS] = (int) __djgpp_exception_state->__ds; + registers[ES] = (int) __djgpp_exception_state->__es; + registers[FS] = (int) __djgpp_exception_state->__fs; + registers[GS] = (int) __djgpp_exception_state->__gs; +} +static void end_save_regs(void){} + +/*********************************************************************** + * set_regs + * + * Description: Restores i386 registers to the DJGPP register buffer. + * DJGPP exception handler will restore registers from + * it's buffer on exit from the handler. + * + * Inputs: None. + * Outputs: None. + * Returns: None. + * + ***********************************************************************/ +static void set_regs(void) +{ + __djgpp_exception_state->__eax = (unsigned long) registers[EAX]; + __djgpp_exception_state->__ecx = (unsigned long) registers[ECX]; + __djgpp_exception_state->__edx = (unsigned long) registers[EDX]; + __djgpp_exception_state->__ebx = (unsigned long) registers[EBX]; + __djgpp_exception_state->__esp = (unsigned long) registers[ESP]; + __djgpp_exception_state->__ebp = (unsigned long) registers[EBP]; + __djgpp_exception_state->__esi = (unsigned long) registers[ESI]; + __djgpp_exception_state->__edi = (unsigned long) registers[EDI]; + __djgpp_exception_state->__eip = (unsigned long) registers[PC]; + __djgpp_exception_state->__eflags = (unsigned long) registers[PS]; + __djgpp_exception_state->__cs = (unsigned long) registers[CS]; + __djgpp_exception_state->__ss = (unsigned long) registers[SS]; + __djgpp_exception_state->__ds = (unsigned long) registers[DS]; + __djgpp_exception_state->__es = (unsigned long) registers[ES]; + __djgpp_exception_state->__fs = (unsigned long) registers[FS]; + __djgpp_exception_state->__gs = (unsigned long) registers[GS]; +} +static void end_set_regs(void){} + +/*********************************************************************** + * sigsegv_handler + * + * Description: Handles SIGSEGV signal + * + * Inputs: None. + * Outputs: None. + * Returns: None. + * + ***********************************************************************/ +static void sigsegv_handler(int except_num){ + + /* Save general purpose registers */ + save_regs(); + + /* Dispatch memory fault handling routine if one is registered. */ + if(mem_fault_routine != 0) + { + (*mem_fault_routine)(); + mem_fault_routine = NULL; + } + else + { + /* Save error code */ + gdb_i386errcode = __djgpp_exception_state->__sigmask & 0xffff; + + /* Call the general exception handler */ + handle_exception(except_num); + } + /* Write back registers */ + set_regs(); + + /* Return from handler */ + longjmp(__djgpp_exception_state,__djgpp_exception_state->__eax); +} +static void end_sigsegv_handler(void){} + +/*********************************************************************** + * sigfpe_handler + * + * Description: Handles SIGFPE signal + * + * Inputs: None. + * Outputs: None. + * Returns: None. + * + ***********************************************************************/ +static void sigfpe_handler(int except_num){ + + /* Save general purpose registers */ + save_regs(); + + /* Call the general purpose exception handler */ + handle_exception(except_num); + + /* Write back registers */ + set_regs(); + + /* Return from handler */ + longjmp(__djgpp_exception_state,__djgpp_exception_state->__eax); +} +static void end_sigfpe_handler(void){} + +/*********************************************************************** + * sigtrap_handler + * + * Description: Handles SIGTRAP signal + * + * Inputs: None. + * Outputs: None. + * Returns: None. + * + ***********************************************************************/ +static void sigtrap_handler(int except_num) { + + /* Save general purpose registers */ + save_regs(); + + /* Call the general purpose exception handler */ + handle_exception(except_num); + + /* Write back registers */ + set_regs(); + + /* Return from handler */ + longjmp(__djgpp_exception_state,__djgpp_exception_state->__eax); +} +static void end_sigtrap_handler(int except_num){} + +/*********************************************************************** + * sigill_handler + * + * Description: Handles SIGILL signal + * + * Inputs: None. + * Outputs: None. + * Returns: None. + * + ***********************************************************************/ +static void sigill_handler(int except_num) { + + /* Save general purpose registers */ + save_regs(); + + /* Call the general purpose exception handler */ + handle_exception(except_num); + + /* Write back registers */ + set_regs(); + + /* Return from handler */ + longjmp(__djgpp_exception_state,__djgpp_exception_state->__eax); +} +static void end_sigill_handler(int except_num){} +#endif + +#ifdef _WIN32 //MF + +void win32_exception_handler(EXCEPTION_POINTERS* exc_info) +{ + PCONTEXT ctx = exc_info->ContextRecord; + + registers[EAX] = ctx->Eax; + registers[ECX] = ctx->Ecx; + registers[EDX] = ctx->Edx; + registers[EBX] = ctx->Ebx; + registers[ESP] = ctx->Esp; + registers[EBP] = ctx->Ebp; + registers[ESI] = ctx->Esi; + registers[EDI] = ctx->Edi; + registers[PC] = ctx->Eip; + registers[PS] = ctx->EFlags; + registers[CS] = ctx->SegCs; + registers[SS] = ctx->SegSs; + registers[DS] = ctx->SegDs; + registers[ES] = ctx->SegEs; + registers[FS] = ctx->SegFs; + registers[GS] = ctx->SegGs; + + handle_exception((int)(exc_info->ExceptionRecord->ExceptionCode & 0xFFFF)); + + ctx->Eax = registers[EAX]; + ctx->Ecx = registers[ECX]; + ctx->Edx = registers[EDX]; + ctx->Ebx = registers[EBX]; + ctx->Esp = registers[ESP]; + ctx->Ebp = registers[EBP]; + ctx->Esi = registers[ESI]; + ctx->Edi = registers[EDI]; + ctx->Eip = registers[PC]; + ctx->EFlags = registers[PS]; + ctx->SegCs = registers[CS]; + ctx->SegSs = registers[SS]; + ctx->SegDs = registers[DS]; + ctx->SegEs = registers[ES]; + ctx->SegFs = registers[FS]; + ctx->SegGs = registers[GS]; +} + +#endif // _WIN32 + +/*********************************************************************** + * hex + * + * Description: Convert ASCII character values, representing hex + * digits, to the integer value. + * + * Inputs: + * ch - data character + * Outputs: None. + * Returns: integer value represented by the input character. + * + ***********************************************************************/ +static int hex (char ch) +{ + if ((ch >= 'a') && (ch <= 'f')) + return (ch - 'a' + 10); + if ((ch >= '0') && (ch <= '9')) + return (ch - '0'); + if ((ch >= 'A') && (ch <= 'F')) + return (ch - 'A' + 10); + return (-1); +} +#ifdef DJGPP +static void end_hex(void) {} +#endif + +/*********************************************************************** + * getpacket + * + * Description: Retrieve GDB data packet. + * Scan for the sequence $# + * Inputs: None. + * Outputs: None. + * Returns: Beginning of packet buffer. + * + ***********************************************************************/ +static unsigned char *getpacket (void) +{ + unsigned char *buffer = &remcomInBuffer[0]; + unsigned char checksum; + unsigned char xmitcsum; + int count; + char ch; + + while (1) + { + /* wait around for the start character, ignore all other characters */ + while ((ch = getDebugChar ()) != '$') + ; + + retry: + checksum = 0; + xmitcsum = -1; + count = 0; + + /* now, read until a # or end of buffer is found */ + while (count < BUFMAX) + { + ch = getDebugChar (); + if (ch == '$') + goto retry; + if (ch == '#') + break; + checksum = checksum + ch; + buffer[count] = ch; + count = count + 1; + } + buffer[count] = 0; + + if (ch == '#') + { + ch = getDebugChar (); + xmitcsum = hex (ch) << 4; + ch = getDebugChar (); + xmitcsum += hex (ch); + + if (checksum != xmitcsum) + { + if (remote_debug) + { + fprintf (stderr, + "bad checksum. My count = 0x%x, sent=0x%x. buf=%s\n", + checksum, xmitcsum, buffer); + } + putDebugChar ('-'); /* failed checksum */ + } + else + { + putDebugChar ('+'); /* successful transfer */ + + /* if a sequence char is present, reply the sequence ID */ + if (buffer[2] == ':') + { + putDebugChar (buffer[0]); + putDebugChar (buffer[1]); + + return &buffer[3]; + } + + return &buffer[0]; + } + } + } +} +#ifdef DJGPP +static void end_getpacket(void) {} +#endif + +/*********************************************************************** + * putpacket + * + * Description: Send GDB data packet. + * + * Inputs: Buffer of data to send. + * Outputs: None. + * Returns: None. + * + ***********************************************************************/ +static void putpacket (unsigned char *buffer) +{ + unsigned char checksum; + int count; + char ch; + + /* $#. */ + do + { + putDebugChar ('$'); + checksum = 0; + count = 0; + + while ((ch = buffer[count])) + { + putDebugChar (ch); + checksum += ch; + count += 1; + } + + putDebugChar ('#'); + putDebugChar (hexchars[checksum >> 4]); + putDebugChar (hexchars[checksum % 16]); + + } + while (getDebugChar () != '+'); +} +#ifdef DJGPP +static void end_putpacket(void) {} +#endif + + +/*********************************************************************** + * debug_error + * + * Description: Log errors + * + * Inputs: + * format - Format string. + * parm - parameter string + * Outputs: None. + * Returns: None. + * + ***********************************************************************/ +static void debug_error (const char *format, char *parm) +{ + if (remote_debug) + fprintf (stderr, format, parm); +} +#ifdef DJGPP +static void end_debug_error(void) {} +#endif + +/* + * Indicate to caller of mem2hex or hex2mem that there has been an error. + */ +#ifndef DJGPP +static volatile int mem_err = 0; +#else +static int mem_err = 0; +#endif + +/*********************************************************************** + * set_mem_err + * + * Description: set memory error flag + * + * Inputs: None. + * Outputs: None. + * Returns: None. + * + ***********************************************************************/ +static void set_mem_err (void) +{ + mem_err = 1; +} +#ifdef DJGPP +static void end_set_mem_err(void) {} +#endif + +/*********************************************************************** + * get_char + * + * Description: Retreive a character from the specified address. + * These are separate functions so that they are so + * short and sweet that the compiler won't save any + * registers (if there is a fault to mem_fault, they + * won't get restored, so there better not be any saved). + * + * Inputs: addr - The address to read from. + * Outputs: None. + * Returns: data read from address. + * + ***********************************************************************/ +static int get_char (char *addr) +{ + return *addr; +} +#ifdef DJGPP +static void end_get_char(void) {} +#endif + +/*********************************************************************** + * set_char + * + * Description: Write a value to the specified address. + * These are separate functions so that they are so + * short and sweet that the compiler won't save any + * registers (if there is a fault to mem_fault, they + * won't get restored, so there better not be any saved). + * + * Inputs: + * addr - The address to read from. + * val - value to write. + * Outputs: None. + * Returns: None. + * + ***********************************************************************/ +static void set_char (char *addr, int val) +{ + *addr = val; +} +#ifdef DJGPP +static void end_set_char(void) {} +#endif + + +/*********************************************************************** + * mem2hex + * + * Description: Convert the memory pointed to by mem into hex, placing + * result in buf. Return a pointer to the last char put + * in buf (null). If MAY_FAULT is non-zero, then we should + * set mem_err in response to a fault; if zero treat a + * fault like any other fault in the stub. + * + * Inputs: + * mem - Memory address + * buf - data buffer + * count - number of bytes + * may_fault - flag indicating that the operation may cause a mem fault. + * Outputs: None. + * Returns: Pointer to last character. + * + ***********************************************************************/ +static char *mem2hex (char *mem,char *buf,int count,int may_fault) +{ + int i; + unsigned char ch; + +#ifdef _WIN32 //MF + if (IsBadReadPtr(mem, (DWORD)count)) + return mem; +#else + if (may_fault) + mem_fault_routine = set_mem_err; +#endif + for (i = 0; i < count; i++) + { + ch = get_char (mem++); + if (may_fault && mem_err) + return (buf); + *buf++ = hexchars[ch >> 4]; + *buf++ = hexchars[ch % 16]; + } + *buf = 0; +#ifndef _WIN32 //MF + if (may_fault) + mem_fault_routine = NULL; +#endif + return (buf); +} +#ifdef DJGPP +static void end_mem2hex(void) {} +#endif + +/*********************************************************************** + * hex2mem + * + * Description: Convert the hex array pointed to by buf into binary to + * be placed in mem. Return a pointer to the character + * AFTER the last byte written + * Inputs: + * buf + * mem + * count + * may_fault + * Outputs: None. + * Returns: Pointer to buffer after last byte. + * + ***********************************************************************/ +static char *hex2mem (char *buf,char *mem,int count,int may_fault) +{ + int i; + unsigned char ch; + +#ifdef _WIN32 //MF + // MinGW does not support structured exception handling, so let's + // go safe and make memory writable by default + DWORD old_protect; + + VirtualProtect(mem, (DWORD)count, PAGE_EXECUTE_READWRITE, &old_protect); +#else + if (may_fault) + mem_fault_routine = set_mem_err; +#endif + for (i = 0; i < count; i++) + { + ch = hex (*buf++) << 4; + ch = ch + hex (*buf++); + set_char (mem++, ch); + if (may_fault && mem_err) + return (mem); + } +#ifndef _WIN32 //MF + if (may_fault) + mem_fault_routine = NULL; +#endif + return (mem); +} +#ifdef DJGPP +static void end_hex2mem(void) {} +#endif + +/*********************************************************************** + * computeSignal + * + * Description: This function takes the 386 exception vector and + * attempts to translate this number into a unix + * compatible signal value. + * Inputs: + * exceptionVector + * Outputs: None. + * Returns: + * + ***********************************************************************/ +static int computeSignal (int exceptionVector) +{ + int sigval; + switch (exceptionVector) + { + case 0: + sigval = 8; + break; /* divide by zero */ + case 1: + sigval = 5; + break; /* debug exception */ + case 3: + sigval = 5; + break; /* breakpoint */ + case 4: + sigval = 16; + break; /* into instruction (overflow) */ + case 5: + sigval = 16; + break; /* bound instruction */ + case 6: + sigval = 4; + break; /* Invalid opcode */ + case 7: + sigval = 8; + break; /* coprocessor not available */ + case 8: + sigval = 7; + break; /* double fault */ + case 9: + sigval = 11; + break; /* coprocessor segment overrun */ + case 10: + sigval = 11; + break; /* Invalid TSS */ + case 11: + sigval = 11; + break; /* Segment not present */ + case 12: + sigval = 11; + break; /* stack exception */ + case 13: + sigval = 11; + break; /* general protection */ + case 14: + sigval = 11; + break; /* page fault */ + case 16: + sigval = 7; + break; /* coprocessor error */ + default: + sigval = 7; /* "software generated" */ + } + return (sigval); +} +#ifdef DJGPP +static void end_computeSignal(void) {} +#endif + +/*********************************************************************** + * hexToInt + * + * Description: Convert an ASCII string to an integer. + * + * Inputs: + * Outputs: None. + * Returns: Number of chars processed + * + ***********************************************************************/ +int hexToInt (char **ptr, int *intValue) +{ + int numChars = 0; + int hexValue; + + *intValue = 0; + + while (**ptr) + { + hexValue = hex (**ptr); + if (hexValue >= 0) + { + *intValue = (*intValue << 4) | hexValue; + numChars++; + } + else + break; + + (*ptr)++; + } + + return (numChars); +} +#ifdef DJGPP +static void end_hexToInt(void) {} +#endif + + +/*********************************************************************** + * handle_exception + * + * Description: This function does all command procesing for interfacing + * to GDB. + * Inputs: + * exceptionVector - number of the vector. + * Outputs: None. + * Returns: None. + * + ***********************************************************************/ +static void handle_exception (int exceptionVector) +{ + int sigval, stepping; + int addr, length; + char *ptr; + int newPC; + +#ifndef _WIN32 //MF + gdb_i386vector = exceptionVector; +#endif + + if (remote_debug) + { + printf ("vector=%d, sr=0x%x, pc=0x%x\n", + exceptionVector, registers[PS], registers[PC]); + } + + /* reply to host that an exception has occurred */ + sigval = computeSignal (exceptionVector); + + ptr = remcomOutBuffer; + + *ptr++ = 'T'; /* notify gdb with signo, PC, FP and SP */ + *ptr++ = hexchars[sigval >> 4]; + *ptr++ = hexchars[sigval & 0xf]; + + *ptr++ = hexchars[ESP]; + *ptr++ = ':'; + ptr = mem2hex((char *)®isters[ESP], ptr, 4, 0); /* SP */ + *ptr++ = ';'; + + *ptr++ = hexchars[EBP]; + *ptr++ = ':'; + ptr = mem2hex((char *)®isters[EBP], ptr, 4, 0); /* FP */ + *ptr++ = ';'; + + *ptr++ = hexchars[PC]; + *ptr++ = ':'; + ptr = mem2hex((char *)®isters[PC], ptr, 4, 0); /* PC */ + *ptr++ = ';'; + + *ptr = '\0'; + + putpacket (remcomOutBuffer); + + stepping = 0; + + while (1 == 1) + { + remcomOutBuffer[0] = 0; + ptr = getpacket (); + + switch (*ptr++) + { + case '?': + remcomOutBuffer[0] = 'S'; + remcomOutBuffer[1] = hexchars[sigval >> 4]; + remcomOutBuffer[2] = hexchars[sigval % 16]; + remcomOutBuffer[3] = 0; + break; + case 'd': + remote_debug = !(remote_debug); /* toggle debug flag */ + break; + case 'g': /* return the value of the CPU registers */ + mem2hex ((char *) registers, remcomOutBuffer, NUMREGBYTES, 0); + break; + case 'G': /* set the value of the CPU registers - return OK */ + hex2mem (ptr, (char *) registers, NUMREGBYTES, 0); + strcpy (remcomOutBuffer, "OK"); + break; + case 'P': /* set the value of a single CPU register - return OK */ + { + int regno; + + if (hexToInt (&ptr, ®no) && *ptr++ == '=') + if (regno >= 0 && regno < NUMREGS) + { + hex2mem (ptr, (char *) ®isters[regno], 4, 0); + strcpy (remcomOutBuffer, "OK"); + break; + } + + strcpy (remcomOutBuffer, "E01"); + break; + } + + /* mAA..AA,LLLL Read LLLL bytes at address AA..AA */ + case 'm': + /* TRY TO READ %x,%x. IF SUCCEED, SET PTR = 0 */ + if (hexToInt (&ptr, &addr)) + if (*(ptr++) == ',') + if (hexToInt (&ptr, &length)) + { + ptr = 0; + mem_err = 0; + mem2hex ((char *) addr, remcomOutBuffer, length, 1); + if (mem_err) + { + strcpy (remcomOutBuffer, "E03"); + debug_error ("%s","memory fault"); + } + } + + if (ptr) + { + strcpy (remcomOutBuffer, "E01"); + } + break; + + /* MAA..AA,LLLL: Write LLLL bytes at address AA.AA return OK */ + case 'M': + /* TRY TO READ '%x,%x:'. IF SUCCEED, SET PTR = 0 */ + if (hexToInt (&ptr, &addr)) + if (*(ptr++) == ',') + if (hexToInt (&ptr, &length)) + if (*(ptr++) == ':') + { + mem_err = 0; + hex2mem (ptr, (char *) addr, length, 1); + + if (mem_err) + { + strcpy (remcomOutBuffer, "E03"); + debug_error ("%s","memory fault"); + } + else + { + strcpy (remcomOutBuffer, "OK"); + } + + ptr = 0; + } + if (ptr) + { + strcpy (remcomOutBuffer, "E02"); + } + break; + + /* cAA..AA Continue at address AA..AA(optional) */ + /* sAA..AA Step one instruction from AA..AA(optional) */ + case 's': + stepping = 1; + case 'c': + /* try to read optional parameter, pc unchanged if no parm */ + if (hexToInt (&ptr, &addr)) + registers[PC] = addr; + + newPC = registers[PC]; + + /* clear the trace bit */ + registers[PS] &= 0xfffffeff; + + /* set the trace bit if we're stepping */ + if (stepping) + registers[PS] |= 0x100; + +#ifdef _WIN32 //MF + return; +#else + _returnFromException (); /* this is a jump */ + + break; + + /* kill the program */ + case 'k': /* do nothing */ +#if 0 + /* Huh? This doesn't look like "nothing". + m68k-stub.c and sparc-stub.c don't have it. */ + BREAKPOINT (); +#endif + break; +#endif + } /* switch */ + + /* reply to the request */ + putpacket (remcomOutBuffer); + } +} +#ifdef DJGPP +static void end_handle_exception(void) {} +#endif + +#ifndef DJGPP +/* GDB stores segment registers in 32-bit words (that's just the way + m-i386v.h is written). So zero the appropriate areas in registers. */ +#define SAVE_REGISTERS1() \ + asm ("movl %eax, _registers"); \ + asm ("movl %ecx, _registers+4"); \ + asm ("movl %edx, _registers+8"); \ + asm ("movl %ebx, _registers+12"); \ + asm ("movl %ebp, _registers+20"); \ + asm ("movl %esi, _registers+24"); \ + asm ("movl %edi, _registers+28"); \ + asm ("movw $0, %ax"); \ + asm ("movw %ds, _registers+48"); \ + asm ("movw %ax, _registers+50"); \ + asm ("movw %es, _registers+52"); \ + asm ("movw %ax, _registers+54"); \ + asm ("movw %fs, _registers+56"); \ + asm ("movw %ax, _registers+58"); \ + asm ("movw %gs, _registers+60"); \ + asm ("movw %ax, _registers+62"); +#define SAVE_ERRCODE() \ + asm ("popl %ebx"); \ + asm ("movl %ebx, _gdb_i386errcode"); +#define SAVE_REGISTERS2() \ + asm ("popl %ebx"); /* old eip */ \ + asm ("movl %ebx, _registers+32"); \ + asm ("popl %ebx"); /* old cs */ \ + asm ("movl %ebx, _registers+40"); \ + asm ("movw %ax, _registers+42"); \ + asm ("popl %ebx"); /* old eflags */ \ + asm ("movl %ebx, _registers+36"); \ + /* Now that we've done the pops, we can save the stack pointer."); */ \ + asm ("movw %ss, _registers+44"); \ + asm ("movw %ax, _registers+46"); \ + asm ("movl %esp, _registers+16"); + +/* See if mem_fault_routine is set, if so just IRET to that address. */ +#define CHECK_FAULT() \ + asm ("cmpl $0, _mem_fault_routine"); \ + asm ("jne mem_fault"); + +asm (".text"); +asm ("mem_fault:"); +/* OK to clobber temp registers; we're just going to end up in set_mem_err. */ +/* Pop error code from the stack and save it. */ +asm (" popl %eax"); +asm (" movl %eax, _gdb_i386errcode"); + +asm (" popl %eax"); /* eip */ +/* We don't want to return there, we want to return to the function + pointed to by mem_fault_routine instead. */ +asm (" movl _mem_fault_routine, %eax"); +asm (" popl %ecx"); /* cs (low 16 bits; junk in hi 16 bits). */ +asm (" popl %edx"); /* eflags */ + +/* Remove this stack frame; when we do the iret, we will be going to + the start of a function, so we want the stack to look just like it + would after a "call" instruction. */ +asm (" leave"); + +/* Push the stuff that iret wants. */ +asm (" pushl %edx"); /* eflags */ +asm (" pushl %ecx"); /* cs */ +asm (" pushl %eax"); /* eip */ + +/* Zero mem_fault_routine. */ +asm (" movl $0, %eax"); +asm (" movl %eax, _mem_fault_routine"); + +asm ("iret"); + + +#define CALL_HOOK() asm("call _remcomHandler"); + +/* This function is called when a i386 exception occurs. It saves + * all the cpu regs in the _registers array, munges the stack a bit, + * and invokes an exception handler (remcom_handler). + * + * stack on entry: stack on exit: + * old eflags vector number + * old cs (zero-filled to 32 bits) + * old eip + * + */ +extern void _catchException3(); +asm(".text"); +asm(".globl __catchException3"); +asm("__catchException3:"); +SAVE_REGISTERS1(); +SAVE_REGISTERS2(); +asm ("pushl $3"); +CALL_HOOK(); + +/* Same thing for exception 1. */ +extern void _catchException1(); +asm(".text"); +asm(".globl __catchException1"); +asm("__catchException1:"); +SAVE_REGISTERS1(); +SAVE_REGISTERS2(); +asm ("pushl $1"); +CALL_HOOK(); + +/* Same thing for exception 0. */ +extern void _catchException0(); +asm(".text"); +asm(".globl __catchException0"); +asm("__catchException0:"); +SAVE_REGISTERS1(); +SAVE_REGISTERS2(); +asm ("pushl $0"); +CALL_HOOK(); + +/* Same thing for exception 4. */ +extern void _catchException4(); +asm(".text"); +asm(".globl __catchException4"); +asm("__catchException4:"); +SAVE_REGISTERS1(); +SAVE_REGISTERS2(); +asm ("pushl $4"); +CALL_HOOK(); + +/* Same thing for exception 5. */ +extern void _catchException5(); +asm(".text"); +asm(".globl __catchException5"); +asm("__catchException5:"); +SAVE_REGISTERS1(); +SAVE_REGISTERS2(); +asm ("pushl $5"); +CALL_HOOK(); + +/* Same thing for exception 6. */ +extern void _catchException6(); +asm(".text"); +asm(".globl __catchException6"); +asm("__catchException6:"); +SAVE_REGISTERS1(); +SAVE_REGISTERS2(); +asm ("pushl $6"); +CALL_HOOK(); + +/* Same thing for exception 7. */ +extern void _catchException7(); +asm(".text"); +asm(".globl __catchException7"); +asm("__catchException7:"); +SAVE_REGISTERS1(); +SAVE_REGISTERS2(); +asm ("pushl $7"); +CALL_HOOK(); + +/* Same thing for exception 8. */ +extern void _catchException8(); +asm(".text"); +asm(".globl __catchException8"); +asm("__catchException8:"); +SAVE_REGISTERS1(); +SAVE_ERRCODE(); +SAVE_REGISTERS2(); +asm ("pushl $8"); +CALL_HOOK(); + +/* Same thing for exception 9. */ +extern void _catchException9(); +asm(".text"); +asm(".globl __catchException9"); +asm("__catchException9:"); +SAVE_REGISTERS1(); +SAVE_REGISTERS2(); +asm ("pushl $9"); +CALL_HOOK(); + +/* Same thing for exception 10. */ +extern void _catchException10(); +asm(".text"); +asm(".globl __catchException10"); +asm("__catchException10:"); +SAVE_REGISTERS1(); +SAVE_ERRCODE(); +SAVE_REGISTERS2(); +asm ("pushl $10"); +CALL_HOOK(); + +/* Same thing for exception 12. */ +extern void _catchException12(); +asm(".text"); +asm(".globl __catchException12"); +asm("__catchException12:"); +SAVE_REGISTERS1(); +SAVE_ERRCODE(); +SAVE_REGISTERS2(); +asm ("pushl $12"); +CALL_HOOK(); + +/* Same thing for exception 16. */ +extern void _catchException16(); +asm(".text"); +asm(".globl __catchException16"); +asm("__catchException16:"); +SAVE_REGISTERS1(); +SAVE_REGISTERS2(); +asm ("pushl $16"); +CALL_HOOK(); + +/* For 13, 11, and 14 we have to deal with the CHECK_FAULT stuff. */ + +/* Same thing for exception 13. */ +extern void _catchException13 (); +asm (".text"); +asm (".globl __catchException13"); +asm ("__catchException13:"); +CHECK_FAULT(); +SAVE_REGISTERS1(); +SAVE_ERRCODE(); +SAVE_REGISTERS2(); +asm ("pushl $13"); +CALL_HOOK(); + +/* Same thing for exception 11. */ +extern void _catchException11 (); +asm (".text"); +asm (".globl __catchException11"); +asm ("__catchException11:"); +CHECK_FAULT(); +SAVE_REGISTERS1(); +SAVE_ERRCODE(); +SAVE_REGISTERS2(); +asm ("pushl $11"); +CALL_HOOK(); + +/* Same thing for exception 14. */ +extern void _catchException14 (); +asm (".text"); +asm (".globl __catchException14"); +asm ("__catchException14:"); +CHECK_FAULT(); +SAVE_REGISTERS1(); +SAVE_ERRCODE(); +SAVE_REGISTERS2(); +asm ("pushl $14"); +CALL_HOOK(); + +/* + * remcomHandler is a front end for handle_exception. It moves the + * stack pointer into an area reserved for debugger use. + */ +asm("_remcomHandler:"); +asm(" popl %eax"); /* pop off return address */ +asm(" popl %eax"); /* get the exception number */ +asm(" movl _stackPtr, %esp"); /* move to remcom stack area */ +asm(" pushl %eax"); /* push exception onto stack */ +asm(" call _handle_exception"); /* this never returns */ +#endif + +void _returnFromException () +{ +#ifndef DJGPP + return_to_prog (); +#else +/* Return from handler */ + longjmp(__djgpp_exception_state,__djgpp_exception_state->__eax); +#endif +} + +/* this function is used to set up exception handlers for tracing and + breakpoints */ +#ifndef DJGPP +void +set_debug_traps (void) +{ +#ifndef _WIN32 //MF + stackPtr = &remcomStack[STACKSIZE / sizeof (int) - 1]; + + exceptionHandler (0, _catchException0); + exceptionHandler (1, _catchException1); + exceptionHandler (3, _catchException3); + exceptionHandler (4, _catchException4); + exceptionHandler (5, _catchException5); + exceptionHandler (6, _catchException6); + exceptionHandler (7, _catchException7); + exceptionHandler (8, _catchException8); + exceptionHandler (9, _catchException9); + exceptionHandler (10, _catchException10); + exceptionHandler (11, _catchException11); + exceptionHandler (12, _catchException12); + exceptionHandler (13, _catchException13); + exceptionHandler (14, _catchException14); + exceptionHandler (16, _catchException16); +#endif // _WIN32 + + gdb_initialized = 1; +} +#endif //#ifndef DJGPP + + +// DJGPP stuff +#ifdef DJGPP +/*********************************************************************** + * restore_traps + * + * Description: This function restores all used signal handlers to + * defaults. + * + * Inputs: None. + * Outputs: None. + * Returns: None. + * + ***********************************************************************/ +void restore_traps(void) +{ + /* Restore default signal handlers */ + signal(SIGSEGV,SIG_DFL); + signal(SIGTRAP,SIG_DFL); + signal(SIGFPE,SIG_DFL); + signal(SIGTRAP,SIG_DFL); + signal(SIGILL,SIG_DFL); + + /* Clear init flag */ + gdb_initialized = 0; +} + +/*********************************************************************** + * lock_handler_data + * + * Description: This function locks all data that is used by the signal + * handlers. + * + * Inputs: None. + * Outputs: None. + * Returns: None. + * + ***********************************************************************/ +static void lock_handler_data(void) +{ + _go32_dpmi_lock_data(&gdb_initialized,sizeof(gdb_initialized)); + _go32_dpmi_lock_data(&remote_debug,sizeof(remote_debug)); + _go32_dpmi_lock_data(hexchars,sizeof(hexchars)); + _go32_dpmi_lock_data(registers,sizeof(registers)); + _go32_dpmi_lock_data(&gdb_i386errcode,sizeof(gdb_i386errcode)); + _go32_dpmi_lock_data(&gdb_i386vector,sizeof(gdb_i386vector)); + + _go32_dpmi_lock_data(remcomInBuffer,sizeof(remcomInBuffer)); + _go32_dpmi_lock_data(remcomOutBuffer,sizeof(remcomOutBuffer)); + + _go32_dpmi_lock_code(getpacket,(unsigned long)end_getpacket- + (unsigned long)getpacket); + _go32_dpmi_lock_code(putpacket,(unsigned long)end_putpacket- + (unsigned long)putpacket); + _go32_dpmi_lock_code(debug_error,(unsigned long)end_debug_error- + (unsigned long)debug_error); + + _go32_dpmi_lock_data(&mem_fault_routine,sizeof(mem_fault_routine)); + _go32_dpmi_lock_data(&mem_err,sizeof(mem_err)); + + _go32_dpmi_lock_code(set_mem_err,(unsigned long)end_set_mem_err-(unsigned long)set_mem_err); + _go32_dpmi_lock_code(get_char,(unsigned long)end_get_char-(unsigned long)get_char); + _go32_dpmi_lock_code(set_char,(unsigned long)end_set_char-(unsigned long)set_char); + _go32_dpmi_lock_code(mem2hex,(unsigned long)end_hex-(unsigned long)hex); + _go32_dpmi_lock_code(mem2hex,(unsigned long)end_mem2hex-(unsigned long)mem2hex); + _go32_dpmi_lock_code(hex2mem,(unsigned long)end_hex2mem-(unsigned long)hex2mem); + _go32_dpmi_lock_code(computeSignal,(unsigned long)end_computeSignal- + (unsigned long)computeSignal); + _go32_dpmi_lock_code(hexToInt,(unsigned long)end_hexToInt-(unsigned long)hexToInt); + _go32_dpmi_lock_code(handle_exception,(unsigned long)end_handle_exception- + (unsigned long)handle_exception); + + _go32_dpmi_lock_code(sigsegv_handler, + (unsigned long)end_sigsegv_handler-(unsigned long)sigsegv_handler); + + _go32_dpmi_lock_code(sigfpe_handler, + (unsigned long)end_sigfpe_handler-(unsigned long)sigfpe_handler); + + _go32_dpmi_lock_code(sigtrap_handler, + (unsigned long)end_sigtrap_handler-(unsigned long)sigtrap_handler); + + _go32_dpmi_lock_code(sigill_handler, + (unsigned long)end_sigill_handler-(unsigned long)sigill_handler); + + _go32_dpmi_lock_code(save_regs, + (unsigned long)end_save_regs-(unsigned long)save_regs); + + _go32_dpmi_lock_code(set_regs, + (unsigned long)end_set_regs-(unsigned long)set_regs); + +} + +/*********************************************************************** + * set_debug_traps + * + * Description: This function installs signal handlers. + * + * Inputs: None. + * Outputs: None. + * Returns: None. + * + ***********************************************************************/ +void set_debug_traps(void) +{ + /* Lock any data that may be used by the trap handlers */ + lock_handler_data(); + + /* Install signal handlers here */ + signal(SIGSEGV,sigsegv_handler); + signal(SIGFPE,sigfpe_handler); + signal(SIGTRAP,sigtrap_handler); + signal(SIGILL,sigill_handler); + + /* Set init flag */ + gdb_initialized = 1; + +} +#endif //#ifdef DJGPP + +/*********************************************************************** + * breakpoint + * + * Description: This function will generate a breakpoint exception. + * It is used at the beginning of a program to sync up + * with a debugger and can be used otherwise as a quick + * means to stop program execution and "break" into the + * debugger. + * + * Inputs: None. + * Outputs: None. + * Returns: None. + * + ***********************************************************************/ +void breakpoint () +{ + if (gdb_initialized) + BREAKPOINT (); +} + diff --git a/tools/gdbst03/src/library/i386-supp.c b/tools/gdbst03/src/library/i386-supp.c new file mode 100644 index 000000000..baf465b4e --- /dev/null +++ b/tools/gdbst03/src/library/i386-supp.c @@ -0,0 +1,424 @@ +/*********************************************************************** + * i386-supp.c + * + * Description: Support functions for the i386 GDB target stub. + * + * Credits: Created by Jonathan Brogdon + * + * Terms of use: This software is provided for use under the terms + * and conditions of the GNU General Public License. + * You should have received a copy of the GNU General + * Public License along with this program; if not, write + * to the Free Software Foundation, Inc., 59 Temple Place + * Suite 330, Boston, MA 02111-1307, USA. + * + * Global Data: None. + * Global Functions: + * gdb_serial_init + * gdb_target_init + * gdb_target_close + * putDebugChar + * getDebugChar + * + * History + * Engineer: Date: Notes: + * --------- ----- ------ + * Jonathan Brogdon 20000617 Genesis + * Gordon Schumacher 20020212 Updated for modularity + * + ***********************************************************************/ + + +#ifdef DJGPP +#include +#endif + +#ifdef _WIN32 +#define WIN32_LEAN_AND_MEAN +#include +#include +#include +#define DEBUGBUFFERSIZE 1024 +HANDLE ser_port = (HANDLE)(-1); + +//#include "utility/utility.h" +#ifdef _MSC_VER +#ifndef DEBUG_SERIAL +#pragma comment(lib, "wsock32") +#endif +#endif +#endif + +#include +#include + +#ifdef DJGPP +//#include "bios_layer.h" // Include this for BIOS calls - NOT RECOMMENDED! +//#include "sva_layer.h" // Include this for SVAsync usage +#include "dzc_layer.h" // Include this for DZComm usage + + +#endif +#define SER_TIMEOUT 1000000 + +#ifdef _WIN32 +static LPTOP_LEVEL_EXCEPTION_FILTER s_prev_exc_handler = 0; + + +#define I386_EXCEPTION_CNT 17 + +LONG WINAPI exc_protection_handler(EXCEPTION_POINTERS* exc_info) +{ + int exc_nr = exc_info->ExceptionRecord->ExceptionCode & 0xFFFF; + + if (exc_nr < I386_EXCEPTION_CNT) { + //LOG(FmtString(TEXT("exc_protection_handler: Exception %x"), exc_nr)); + +#if 0 + if (exc_nr==11 || exc_nr==13 || exc_nr==14) { + if (mem_fault_routine) + mem_fault_routine(); + } +#endif + + ++exc_info->ContextRecord->Eip; + } + + return EXCEPTION_CONTINUE_EXECUTION; +} + +LONG WINAPI exc_handler(EXCEPTION_POINTERS* exc_info) +{ + int exc_nr = exc_info->ExceptionRecord->ExceptionCode & 0xFFFF; + + if (exc_nr < I386_EXCEPTION_CNT) { + //LOG(FmtString("Exception %x", exc_nr)); + //LOG(FmtString("EIP=%08X EFLAGS=%08X", exc_info->ContextRecord->Eip, exc_info->ContextRecord->EFlags)); + + // step over initial breakpoint + if (s_initial_breakpoint) { + s_initial_breakpoint = 0; + ++exc_info->ContextRecord->Eip; + } + + SetUnhandledExceptionFilter(exc_protection_handler); + + win32_exception_handler(exc_info); + //LOG(FmtString("EIP=%08X EFLAGS=%08X", exc_info->ContextRecord->Eip, exc_info->ContextRecord->EFlags)); + + SetUnhandledExceptionFilter(exc_handler); + + return EXCEPTION_CONTINUE_EXECUTION; + } + + return EXCEPTION_CONTINUE_SEARCH; +} + +void disable_debugging() +{ + if (s_prev_exc_handler) { + SetUnhandledExceptionFilter(s_prev_exc_handler); + s_prev_exc_handler = 0; + } +} +#endif + +#if !(defined(DJGPP) || defined(_WIN32)) +void exceptionHandler(int exc_nr, void* exc_addr) +{ + if (exc_nr>=0 && exc_nr SER_TIMEOUT) + { + if(WriteFile( ser_port, buffer, 1, &dwLength, NULL )) + return 1; + else if(timeout > SER_TIMEOUT) + return 0; + } + else timeout++; + goto retrywrite; +#endif +} + +/*********************************************************************** + * getDebugChar + * + * Description: gets a character from the debug COM port. + * + * Inputs: None. + * Outputs: None. + * Returns: character data from the serial support. + * + ***********************************************************************/ +int getDebugChar(void) +{ + register int timeout = 0; +#ifdef DJGPP + register int ret = -1; + + while ((GDBStub_SerRecvOk() == 0) && (timeout < SER_TIMEOUT)) + timeout++; + if (timeout < SER_TIMEOUT) + ret = GDBStub_SerRecv(); + + return ret; +#elif defined(_WIN32) + DWORD buffer[DEBUGBUFFERSIZE]; + COMSTAT ComStat ; + DWORD dwErrorFlags; + DWORD dwLength; + + if(ser_port == (HANDLE)-1) + return -1; + + retryread: + ClearCommError( ser_port, &dwErrorFlags, &ComStat ) ; + dwLength = min( DEBUGBUFFERSIZE, ComStat.cbInQue ) ; + + if (dwLength > 0 || timeout > SER_TIMEOUT) + { + if(ReadFile( ser_port, buffer, 1, &dwLength, NULL )) + return buffer[0]; + else if(timeout > SER_TIMEOUT) + return -1; + } + else timeout++; + goto retryread; +#endif +} + +#if 0 +static SOCKET s_rem_fd = INVALID_SOCKET; + +int init_gdb_connect() +{ +#ifdef _WIN32 + WORD wVersionRequested; + WSADATA wsa_data; +#endif + SOCKADDR_IN srv_addr; + SOCKADDR_IN rem_addr; + SOCKET srv_socket; + int rem_len; + + memset(&srv_addr,0,sizeof(srv_addr)); + s_prev_exc_handler = SetUnhandledExceptionFilter(exc_handler); + +#ifdef _WIN32 + wVersionRequested= MAKEWORD( 2, 2 ); + if (WSAStartup(wVersionRequested, &wsa_data)) { + fprintf(stderr, "WSAStartup() failed"); + return 0; + } +#endif + + srv_addr.sin_family = AF_INET; + srv_addr.sin_addr.s_addr = htonl(INADDR_ANY); + srv_addr.sin_port = htons(9999); + + srv_socket = socket(PF_INET, SOCK_STREAM, 0); + if (srv_socket == INVALID_SOCKET) { + perror("socket()"); + return 0; + } + + if (bind(srv_socket, (struct sockaddr*) &srv_addr, sizeof(srv_addr)) == -1) { + perror("bind()"); + return 0; + } + + if (listen(srv_socket, 4) == -1) { + perror("listen()"); + return 0; + } + + rem_len = sizeof(rem_addr); + + for(;;) { + s_rem_fd = accept(srv_socket, (struct sockaddr*)&rem_addr, &rem_len); + + if (s_rem_fd == INVALID_SOCKET) { + if (errno == EINTR) + continue; + + perror("accept()"); + return 0; + } + + break; + } + + return 1; +} + + +int getDebugChar() +{ + char buffer[DEBUGBUFFERSIZE]; + int r; + + if (s_rem_fd == INVALID_SOCKET) + return EOF; + + r = recv(s_rem_fd, buffer, 1, 0); + if (r == -1) { + perror("recv()"); + //LOG(TEXT("debugger connection broken")); + s_rem_fd = INVALID_SOCKET; + return EOF; + } + + if (!r) + return EOF; + + return buffer[0]; +} + +void putDebugChar(int c) +{ + if (s_rem_fd == INVALID_SOCKET) { + const char buffer[] = {c}; + + if (!send(s_rem_fd, buffer, 1, 0)) { + perror("send()"); + //LOG(TEXT("debugger connection broken")); + exit(-1); + } + } +} +#endif diff --git a/tools/gdbst03/src/library/makefile b/tools/gdbst03/src/library/makefile new file mode 100644 index 000000000..05e1e9030 --- /dev/null +++ b/tools/gdbst03/src/library/makefile @@ -0,0 +1,30 @@ +# +# Makefile for GDB Stub for DJGPP +# +# GDB Stub for DJGPP Copyright 2000 by Jonathan Brogdon +# + +include ../../Makefile.cfg + +CFLAGS += -I../../include -I../include + +LOBJS = i386-stub.o i386-supp.o + +all: library + +library: $(LOBJS) + @$(RM) ../../lib/libgdbst.a + @$(AR) rcs ../../lib/libgdbst.a $(LOBJS) + +dep: + @$(CC) $(CFLAGS) -M *.c > depend.dep + +clean: + @$(RM) $(LOBJS) + +distclean: clean + @$(RM) ../../lib/libgdbst.a + @$(RM) depend.dep + +$(OBJS) $(LOBJS): +include depend.dep diff --git a/tools/gdbst03/src/library/sva_layer.h b/tools/gdbst03/src/library/sva_layer.h new file mode 100644 index 000000000..4cdd1628b --- /dev/null +++ b/tools/gdbst03/src/library/sva_layer.h @@ -0,0 +1,83 @@ +//======================================================================================================= +// sva_layer.h - Serial command layer for SVAsync +// +//======================================================================================================= + +//======================================================================================================= +//======================================================================================================= + +#ifndef _SVA_LAYER_H +#define _SVA_LAYER_H + + +//=============================================================================== +// Include files +//=============================================================================== + +#include "svasync.h" + +//=============================================================================== +// Inline function definitions +//=============================================================================== + +// Initialize the serial library +// Should return 0 if no error occurred +__inline int GDBStub_SerInit(int port) +{ + int ret, init; + + ret = init = SVAsyncInit(port - 1); + if (ret == 0) + ret = SVAsyncFifoInit(); + if (init == 0) + atexit(SVAsyncStop); + return ret; +} + + +// Set the serial port speed (and other configurables) +// Should return 0 if the speed is set properly +__inline int GDBStub_SerSpeed(int speed) +{ + SVAsyncSet(speed, BITS_8 | NO_PARITY | STOP_1); + SVAsyncHand(DTR | RTS); + return 0; +} + + +// Check to see if there's room in the buffer to send data +// Should return 0 if it is okay to send +__inline int GDBStub_SerSendOk(void) +{ + return !SVAsyncOutStat(); +} + + +// Send a character to the serial port +// Should return 0 if the send succeeds +__inline int GDBStub_SerSend(int c) +{ + SVAsyncOut((char) c); + return 0; +} + + +// Check to see if there are characters waiting in the buffer +// Should return 0 if there's data waiting +__inline int GDBStub_SerRecvOk(void) +{ + return SVAsyncInStat(); +} + + +// Read a character from the serial port +// Should return the character read +__inline int GDBStub_SerRecv(void) +{ + return SVAsyncIn(); +} + + + + +#endif diff --git a/tools/keys.h b/tools/keys.h new file mode 100644 index 000000000..a03ae5acc --- /dev/null +++ b/tools/keys.h @@ -0,0 +1,32 @@ + +// KEYS.H - header file. +// +// Codes des touches tel que renvoy‚s par getch(), +256 si ‚tendus. +// +// Author: Denis F. +// Date: June 16 1997. +// + +// codes des touches (getch()) ajout‚ de 256 s'il s'agit d'un code ‚tendu. + +#define KEY_BACKSPACE 8 +#define KEY_TAB 9 +#define KEY_ENTER 13 +#define KEY_ESCAPE 27 +#define KEY_SPACE 32 +#define KEY_F1 315 +#define KEY_F2 316 +#define KEY_F3 317 +#define KEY_F4 318 +#define KEY_F5 319 +#define KEY_F10 324 +#define KEY_HOME 327 +#define KEY_END 335 +#define KEY_CUP 328 +#define KEY_PGUP 329 +#define KEY_CLEFT 331 +#define KEY_CRIGHT 333 +#define KEY_CDOWN 336 +#define KEY_PGDN 337 +#define KEY_INSERT 338 +#define KEY_DELETE 339 diff --git a/tools/libwad/Makefile b/tools/libwad/Makefile new file mode 100644 index 000000000..3c93a2547 --- /dev/null +++ b/tools/libwad/Makefile @@ -0,0 +1,199 @@ +#!/usr/bin/env make -f + +## libwad: Doom WAD format interface library. +## Copyright (C) 2011 by Callum Dickinson. +# +## This program is free software; you can redistribute it and/or +## modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either version 2 +## of the License, or (at your option) any later version. +# +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. + +# Library name. +LIBNAME = wad +# Library version. +LIBVERM = 1 +LIBVER = $(LIBVERM).0.0 + +# Library default options. +CPPFLAGS += -DLIBNAME="$(LIBNAME)" -DLIBVER="$(LIBVER)" + +# Source files and directory. +SRCDIR = src +SRC = $(SRCDIR)/wad.c $(SRCDIR)/lump.c $(SRCDIR)/wad_static.c + +# Compiled files directory. +BINDIR = bin +INCDIR = include + +# +## Variables that shouldn't be edited unless +## you know what you are doing start here. +# + +# Makefile pretty text output variables. +PRAR = AR +PRCC = CC +PRINSTALL = INSTALL +PRCLEAN = CLEAN + +# Library name prefix. +LIBPFX = lib + +# Library installation directory. +PREFIX ?= /usr/local +LIBDIR := $(PREFIX)/lib +INCLUDE := $(PREFIX)/include + +# Variables created during compilation. +OBJ = $(SRC:.c=.o) +DEP = $(BINDIR)/$(LIBPFX)$(LIBNAME).d +ifdef MINGW +DEFN = $(LIBNAME).def +LIBN = $(LIBPFX)$(LIBNAME).lib +BIN = $(BINDIR)/$(LIBPFX)$(LIBNAME)-$(LIBVERM).dll +else +SONAME = $(LIBPFX)$(LIBNAME).so.$(LIBVERM) +BIN = $(BINDIR)/$(LIBPFX)$(LIBNAME).so.$(LIBVER) +endif +STABIN = $(BINDIR)/$(LIBPFX)$(LIBNAME).a + +# Compilation programs. +ECHO := echo +RM := $(RM) -r +FIND := find +GREP := grep +INSTALL := install -m 644 +MKDIR := mkdir -p +FOR := for +SED := sed +AR := $(CROSS_COMPILE)$(AR) +CC := $(CROSS_COMPILE)$(CC) + +# Shell programs. +SHECHO := $(ECHO) +SHFIND := $(FIND) +SHGREP := $(GREP) +SHINSTALL := $(INSTALL) +SHSED := $(SED) +SHCC := $(CC) + +# Quiet compiling programs during pretty text output. +ECHO := @$(ECHO) +ifndef V +RM := @$(RM) +LDCONFIG := @$(LDCONFIG) +FIND := @$(FIND) +GREP := @$(GREP) +INSTALL := @$(INSTALL) +MKDIR := @$(MKDIR) +FOR := @$(FOR) +SED := @$(SED) +AR := @$(AR) +CC := @$(CC) +endif + +LIBS = $(BIN) $(STABIN) +HEADERS = $(shell $(SHFIND) $(CURDIR) | $(SHGREP) -e "$(INCDIR)/.*.h" | $(SHGREP) -v ".svn" | $(SHSED) "s:$(CURDIR)/::") + +# Compiler default flags. +ifndef MINGW +CFLAGS += -fPIC +LDFLAGS += -fPIC +endif +ifdef DEBUG +CFLAGS += -g $(M5) -O0 -Wall +endif + +# Linker flags. +LDFLAGS += -shared +ifdef MINGW +LDFLAGS += -Wl,--output-def,$(DEFN),--out-implib,$(LIBN) +else +LDFLAGS += -Wl,-soname,$(SONAME) +endif + +# +## Makefile targets. +# + +# all is dependent on $(BIN) to be complete +all: $(DEP) $(BIN) $(STABIN) + +# $(EXE) is dependent on all of the files in $(OBJ) to exist +$(DEP): $(SRC) +ifndef V + $(ECHO) " $(PRCC)$@" +endif + -$(MKDIR) $(BINDIR) > /dev/null 2>&1 + -$(RM) $@ + $(FOR) f in $(SRC); do \ + $(SHCC) $(CPPFLAGS) $(CFLAGS) -MM $$f >> $@; \ + done +-include $@ + +%.o: %.c +ifndef V + $(ECHO) " $(PRCC)$@" +endif + $(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@ + +$(BIN): $(OBJ) +ifndef V + $(ECHO) " $(PRCC)$@" +endif + $(CC) $(LDFLAGS) -o $@ $(OBJ) $(LIB) + +$(STABIN): $(OBJ) +ifndef V + $(ECHO) " $(PRAR)$@" +endif + $(AR) rcs $@ $(OBJ) + +install: all install-libs install-headers + +install-libs: + $(MKDIR) $(LIBDIR) +ifndef V + $(FOR) f in $(LIBS); do \ + $(SHECHO) " $(PRINSTALL)$$f"; \ + $(SHINSTALL) $$f $(LIBDIR); \ + done +else + $(FOR) f in $(LIBS); do \ + $(SHINSTALL) $$f $(LIBDIR); \ + done +endif + $(LDCONFIG) + +install-headers: + $(MKDIR) $(INCLUDE) +ifndef V + $(FOR) f in $(HEADERS); do \ + $(SHECHO) " $(PRINSTALL)$$f"; \ + $(SHINSTALL) $$f $(INCLUDE); \ + done +else + $(FOR) f in $(HEADERS); do \ + $(SHINSTALL) $$f $(INCLUDE); \ + done +endif + +clean: +ifndef V + $(ECHO) " $(PRCLEAN)$(OBJ) $(LIBS)" +endif + -$(RM) $(OBJ) $(LIBS) + +distclean: +ifndef V + $(ECHO) " $(PRCLEAN)$(BINDIR)" +endif + -$(RM) $(BINDIR) + + +.PHONY : all install install-libs install-headers clean diff --git a/tools/libwad/examples/wadexample/Makefile b/tools/libwad/examples/wadexample/Makefile new file mode 100644 index 000000000..773733b06 --- /dev/null +++ b/tools/libwad/examples/wadexample/Makefile @@ -0,0 +1,139 @@ +#!/usr/bin/env make -f + +## wadexample: libwad example program. +## Copyright (C) 2011 by Callum Dickinson. +# +## This program is free software; you can redistribute it and/or +## modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either version 2 +## of the License, or (at your option) any later version. +# +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. + +# Program name. +PRONAME = wadexample +# Program version. +PROVER = 1.0.0 + +# Program default options. +CPPFLAGS += -DPRONAME="$(PRONAME)" -DPROVER="$(PROVER)" + +# Source files and directory. +SRC = wadexample.c + +# Required libraries. +LIB = -lwad + +# +## Variables that shouldn't be edited unless +## you know what you are doing start here. +# + +# Makefile pretty text output variables. +PRCC = CC +PRINSTALL=INSTALL +PRCLEAN = CLEAN + +# Library name prefix. +LIBPFX = lib + +# Library installation directory. +PREFIX ?= /usr/local +LIBDIR := $(PREFIX)/lib +INCLUDE := $(PREFIX)/include + +# Variables created during compilation. +OBJ = $(SRC:.c=.o) +DEP = $(PRONAME).d +ifdef MINGW +BIN = $(PRONAME).exe +else +BIN = $(PRONAME) +endif + +# Compilation programs. +ECHO := echo +RM := $(RM) -r +FIND := find +GREP := grep +INSTALLX:= install -m 755 +MKDIR := mkdir -p +FOR := for +SED := sed +CC := $(CROSS_COMPILE)$(CC) + +# Shell programs. +SHECHO := $(ECHO) +SHFIND := $(FIND) +SHGREP := $(GREP) +SHINSTALL:= $(INSTALL) +SHSED := $(SED) +SHCC := $(CC) + +# Quiet compiling programs during pretty text output. +NULL := /dev/null 2>&1 +ECHO := @$(ECHO) +ifndef V +RM := @$(RM) +LDCONFIG:= @$(LDCONFIG) +FIND := @$(FIND) +GREP := @$(GREP) +INSTALL := @$(INSTALL) +MKDIR := @$(MKDIR) +FOR := @$(FOR) +SED := @$(SED) +CC := @$(CC) +endif + +# Compiler default flags. +ifdef DEBUG +CFLAGS += -g -O0 -Wall -W +endif + +# Linker flags. +#LDFLAGS += + +# +## Makefile targets. +# + +all: $(DEP) $(BIN) + +$(DEP): $(SRC) +ifndef V + $(ECHO) " $(PRCC)$@" +endif + -$(RM) $@ + $(FOR) f in $(SRC); do \ + $(SHCC) $(CPPFLAGS) $(CFLAGS) -MM $$f >> $@; \ + done +-include $@ + +%.o: %.c +ifndef V + $(ECHO) " $(PRCC)$@" +endif + $(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@ + +$(BIN): $(OBJ) +ifndef V + $(ECHO) " $(PRCC)$@" +endif + $(CC) $(LDFLAGS) -o $@ $(OBJ) $(LIB) + +install: all +ifndef V + $(SHECHO) " $(PRINSTALL)$(BIN)" +endif + $(INSTALLX) $(BIN) $(INSTALLDIR) + +clean: +ifndef V + $(ECHO) " $(PRCLEAN)$(OBJ) $(DEP)" +endif + -$(RM) $(OBJ) $(DEP) + +.PHONY : all install clean diff --git a/tools/libwad/examples/wadexample/wadexample.c b/tools/libwad/examples/wadexample/wadexample.c new file mode 100644 index 000000000..5e35a1e4d --- /dev/null +++ b/tools/libwad/examples/wadexample/wadexample.c @@ -0,0 +1,64 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// wadexample: libwad example program. +// Copyright (C) 2011 by Callum Dickinson. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +//----------------------------------------------------------------------------- +/// \file wadconv.c +/// \brief Converts wads made for version 2.0 to 2.1. + +#include +#include +#include +#include +#include "wad.h" + +int main(int argc, char **argv) +{ + wad_uint32_t i; + + wad_t *w; + lump_t *l; + + if (argc < 2) + { + puts("Usage: wadexample [filename] [..]"); + puts("Example: example wadfile.wad wadfile2.wad"); + return EXIT_FAILURE; + } + + // Open the WAD files. + puts("Opening WADs..."); + for (i = 1; i < (unsigned)argc; i++) + { + if (!WAD_OpenWAD(argv[i])) + { + printf("Error opening WAD %s: %s\n", argv[i], WAD_Error()); + return 1; + } + } + + for (i = 0; i < wad_numwads; i = WAD_WADLoopAdvance(i)) + { + w = WAD_WADByNum(i); + printf("List of lumps inside wad %s:\n", WAD_BaseName(w->filename)); + for (l = w->lumps; l; l = l->next) + printf("Lump #%i: %s\n", l->num, l->name); + } + + puts("Closing WADs..."); + for (i = 0; i < wad_numwads; i++) + WAD_CloseWADByNum(i); + + return EXIT_SUCCESS; +} diff --git a/tools/libwad/include/wad.h b/tools/libwad/include/wad.h new file mode 100644 index 000000000..298a478b7 --- /dev/null +++ b/tools/libwad/include/wad.h @@ -0,0 +1,227 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// libwad: Doom WAD format interface library. +// Copyright (C) 2011 by Callum Dickinson. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +//----------------------------------------------------------------------------- +/// \file wad.h +/// \brief WAD file manipulation library. + +#ifndef __WAD_H__ +#define __WAD_H__ + +#ifdef __cplusplus +extern "C" +{ +#endif + +// +// Exact-width integer types. +// +#ifdef _MSC_VER +typedef signed __int8 wad_int8_t; +typedef unsigned __int8 wad_uint8_t; + +typedef __int16 wad_int16_t; +typedef unsigned __int16 wad_uint16_t; + +typedef __int32 wad_int32_t; +typedef unsigned __int32 wad_uint32_t; + +typedef __int64 wad_int64_t; +typedef unsigned __int64 wad_uint64_t; + +// Older Visual C++ headers don't have the Win64-compatible typedefs... +#if ((_MSC_VER <= 1200) && (!defined(DWORD_PTR))) +#define DWORD_PTR DWORD +#endif + +#if ((_MSC_VER <= 1200) && (!defined(PDWORD_PTR))) +#define PDWORD_PTR PDWORD +#endif + +#elif defined (_arch_dreamcast) +#include + +typedef signed char wad_int8_t; +typedef unsigned char wad_uint8_t; + +typedef int16 wad_int16_t; +typedef uint16 wad_uint16_t; + +typedef int wad_int32_t; +typedef unsigned int wad_uint32_t; + +typedef int64 wad_int64_t; +typedef uint64 wad_uint64_t; +#elif defined (__DJGPP__) +typedef signed char wad_int8_t; +typedef unsigned char wad_uint8_t; + +typedef signed short int wad_int16_t; +typedef unsigned short int wad_uint16_t; + +typedef signed long wad_int32_t; +typedef unsigned long wad_uint32_t; + +typedef signed long long wad_int64_t; +typedef unsigned long long wad_uint64_t; +#else +#define __STDC_LIMIT_MACROS +#include + +typedef int8_t wad_int8_t; +typedef uint8_t wad_uint8_t; + +typedef int16_t wad_int16_t; +typedef uint16_t wad_uint16_t; + +typedef int32_t wad_int32_t; +typedef uint32_t wad_uint32_t; + +typedef int64_t wad_int64_t; +typedef uint64_t wad_uint64_t; +#endif + +typedef enum +{ + false, + true +} wad_boolean_t; + +typedef struct +{ + char id[4]; // The WAD header's 4-character ID. + wad_uint32_t numlumps; // The number of lumps the WAD has. + wad_uint32_t lumpdir; // The pointer to the lump directory. +} wadheader_t; + +typedef struct wad_s +{ + char *filename; // The filename of the open WAD. + + wadheader_t *header; // The WAD's header. + wad_boolean_t compressed; + + struct lump_s *lumps; // The WAD's lumps buffer. +} wad_t; + +typedef struct lump_s +{ + wad_t *wad; // The WAD the lump belongs to. + + char name[9]; // The name of the lump. + + wad_uint64_t disksize; // The size of the lump on disk. + size_t size; // The real (uncompressed) size of the lump. + + wad_boolean_t compressed; + + void *data; // The actual lump data. + + wad_uint32_t num; // The lump number in the WAD. + struct lump_s *prev; // The previous node in the tree. + struct lump_s *next; // The next node in the tree. +} lump_t; + +// a raw entry of the wad directory +typedef struct +{ + wad_uint32_t position; // The position of the lump in the WAD file. + wad_uint32_t size; // Size of the lump. + char name[8]; // The lump's name. +} lumpdir_t; + +// +// wad_static.c +// Static file for internal libwad operations. +// +extern char *WAD_Error(void); +extern char *WAD_BaseName(char *path); +extern char *WAD_VA(const char *format, ...); + +extern inline wad_int16_t WAD_INT16_Endianness(wad_int16_t x); +extern inline wad_int32_t WAD_INT32_Endianness(wad_int32_t x); + +// +// wad.c +// WAD interface functionality. +// +extern wad_uint32_t wad_numwads; + +extern wad_uint32_t WAD_WADLoopAdvance(wad_uint32_t i); + +extern wad_t *WAD_WADByNum(wad_uint16_t num); +extern wad_t *WAD_WADByFileName(const char *filename); + +extern wad_t *WAD_OpenWAD(const char *filename); + +extern wad_int32_t WAD_SaveWAD(wad_t *wad); +extern inline wad_int32_t WAD_SaveWADByNum(wad_uint16_t num); +extern inline wad_int32_t WAD_SaveWADByFileName(const char *filename); + +extern inline wad_int32_t WAD_SaveCloseWAD(wad_t *wad); +extern inline wad_int32_t WAD_SaveCloseWADByNum(wad_uint16_t num); +extern inline wad_int32_t WAD_SaveCloseWADByFileName(const char *filename); + +extern void WAD_CloseWAD(wad_t *wad); +extern inline void WAD_CloseWADByNum(wad_uint16_t num); +extern inline void WAD_CloseWADByFileName(const char *filename); + +// +// lump.c +// Lump interface functionality. +// +extern char *WAD_LumpNameFromFileName(char *path); +extern lump_t *WAD_LumpInWADByNum(wad_t *wad, wad_uint32_t num); +extern lump_t *WAD_LumpInWADByName(wad_t *wad, const char *name); +extern lump_t *WAD_LumpByName(const char *name); + +extern inline wad_uint32_t WAD_LumpNum(lump_t *lump); +extern inline wad_uint32_t WAD_LumpNumInWADByName(wad_t *wad, const char *name); +extern inline wad_uint32_t WAD_LumpNumByName(const char *name); + +extern inline size_t WAD_LumpSize(lump_t *lump); +extern inline size_t WAD_LumpSizeInWADByName(wad_t *wad, const char *name); +extern inline size_t WAD_LumpSizeByName(const char *name); + +extern lump_t *WAD_AddLump(wad_t *wad, lump_t *destlump, const char *name, const char *filename); +extern inline lump_t *WAD_AddLumpInWADByNum(wad_t *wad, wad_uint32_t num, const char *name, const char *filename); +extern inline lump_t *WAD_AddLumpInWADByName(wad_t *wad, const char *destname, const char *name, const char *filename); +extern inline lump_t *WAD_AddLumpByName(const char *destname, const char *name, const char *filename); + +extern lump_t *WAD_CacheLump(lump_t *lump); +extern inline lump_t *WAD_CacheLumpInWADByNum(wad_t *wad, wad_uint32_t num); +extern inline lump_t *WAD_CacheLumpInWADByName(wad_t *wad, const char *name); +extern inline lump_t *WAD_CacheLumpByName(const char *name); + +extern lump_t *WAD_MoveLump(lump_t *lump, lump_t *destlump); +extern inline lump_t *WAD_MoveLumpInWADByNum(wad_t *wad, wad_uint32_t num, wad_t *destwad, wad_uint32_t destnum); +extern inline lump_t *WAD_MoveLumpInWADByName(wad_t *wad, const char *name, wad_t *destwad, const char *destname); +extern inline lump_t *WAD_MoveLumpByName(const char *name, const char *destname); + +extern void WAD_UncacheLump(lump_t *lump); +extern inline void WAD_UncacheLumpInWADByNum(wad_t *wad, wad_uint32_t num); +extern inline void WAD_UncacheLumpInWADByName(wad_t *wad, const char *name); +extern inline void WAD_UncacheLumpByName(const char *name); + +extern void WAD_RemoveLump(lump_t *lump); +extern inline void WAD_RemoveLumpInWADByNum(wad_t *wad, wad_uint32_t num); +extern inline void WAD_RemoveLumpInWADByName(wad_t *wad, const char *name); +extern inline void WAD_RemoveLumpByName(const char *name); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // __WAD_H__ diff --git a/tools/libwad/src/lump.c b/tools/libwad/src/lump.c new file mode 100644 index 000000000..a1f4c97fc --- /dev/null +++ b/tools/libwad/src/lump.c @@ -0,0 +1,392 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// libwad: Doom WAD format interface library. +// Copyright (C) 2011 by Callum Dickinson. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +//----------------------------------------------------------------------------- +/// \file lump.c +/// \brief Lump interface functionality. + +#include "wad_static.h" + +// +// Create a lump name from the file name +// of a lump. Used for when no name for +// a lump was given. +// +char *WAD_LumpNameFromFileName(char *path) +{ + wad_int32_t i; + char *name, *tempname, *file = WAD_BaseName(path); + + if (!file) + return NULL; + + // + // Process the filename for a suitable lump name. + // + // Get rid of any hidden file period. + if (file[0] == '.') + { + if (!(tempname = malloc(sizeof(*file) * strlen(&file[1])))) + { + free(file); + return NULL; + } + strcpy(tempname, &file[1]); + free(file); + } + else + tempname = file; + + // Get rid of any extensions. + for (i = 0; tempname[i] != '.' && tempname[i] != '\0'; i++); + + // Then, take the first eight characters of + // the resulting filename to get the lump name. + if (i > 8) + i = 8; + + if (!(name = malloc(sizeof(*name) * (i+1)))) + { + free(tempname); + return NULL; + } + + strncpy(name, tempname, i); + name[i+1] = '\0'; + + // + // Done processing lump name. + // + free(tempname); + return name; +} + +lump_t *WAD_LumpInWADByNum(wad_t *wad, wad_uint32_t num) +{ + lump_t *lump; + + if (!wad || !num) + return NULL; + + for (lump = wad->lumps; lump; lump = lump->next) + if (num == lump->num) + return lump; + + return NULL; +} + +lump_t *WAD_LumpInWADByName(wad_t *wad, const char *name) +{ + lump_t *lump; + + if (!wad || !name) + return NULL; + + for (lump = wad->lumps; lump; lump = lump->next) + if (!strcmp(name, lump->name)) + return lump; + + return NULL; +} + +lump_t *WAD_LumpByName(const char *name) +{ + wad_uint32_t i; + lump_t *lump; + + for (i = 0; i < wad_numwads; i = WAD_WADLoopAdvance(i)) + if ((lump = WAD_LumpInWADByName(WAD_WADByNum(i), name))) + return lump; + + return NULL; +} + +inline wad_uint32_t WAD_LumpNum(lump_t *lump) +{ + return lump->num; +} + +inline wad_uint32_t WAD_LumpNumInWADByName(wad_t *wad, const char *name) +{ + return WAD_LumpNum(WAD_LumpInWADByName(wad, name)); +} + +inline wad_uint32_t WAD_LumpNumByName(const char *name) +{ + return WAD_LumpNum(WAD_LumpByName(name)); +} + +inline size_t WAD_LumpSize(lump_t *lump) +{ + return lump->size; +} + +inline size_t WAD_LumpSizeInWADByName(wad_t *wad, const char *name) +{ + return WAD_LumpSize(WAD_LumpInWADByName(wad, name)); +} + +inline size_t WAD_LumpSizeByName(const char *name) +{ + return WAD_LumpSize(WAD_LumpByName(name)); +} + +static void WAD_AddLumpToTree(lump_t *lump, lump_t *destlump) +{ + lump_t *l; + + if (destlump) + { + lump->wad = destlump->wad; + lump->num = destlump->num; + for (l = destlump; l; l = l->next) + l->num++; + if (destlump->prev) + destlump->prev->next = lump; + lump->prev = destlump->prev; + destlump->prev = lump; + lump->next = destlump; + } + else + { + for (l = lump->wad->lumps; l; l = l->next) + if (!l->next) + break; + lump->num = lump->wad->header->numlumps; + l->next = lump; + lump->prev = l; + lump->next = NULL; + } + lump->wad->header->numlumps++; +} + +lump_t *WAD_AddLump(wad_t *wad, lump_t *destlump, const char *name, const char *filename) +{ + // The open lump file. + FILE *file = NULL; + // Pointer to the lump. + lump_t *lump; + // Lump structure. + wad_uint64_t disksize; // lump->disksize + size_t size; // lump->size + wad_boolean_t compressed;// lump->compressed + void *data; // lump->data + + if (!wad) + return NULL; + + if (!name && !filename) + return NULL; + + if (filename) + { + if (!(file = fopen(filename, "rb"))) + return NULL; + + fseek(file, 0, SEEK_END); + disksize = size = (unsigned)ftell(file); + compressed = false; + + + if (!(data = malloc(size))) + { + fclose(file); + return NULL; + } + + fseek(file, 0, SEEK_SET); + if (fread(data, disksize, 1, file) < 1) + return NULL; + fclose(file); + } + else + { + disksize = size = 0; + compressed = false; + data = NULL; + } + + + if (!(lump = malloc(sizeof(*lump)))) + { + WAD_FreeMemory(NULL, NULL, NULL, lump, NULL); + return NULL; + } + + lump->wad = wad; + if (!strcpy(lump->name, (name) ? name : WAD_LumpNameFromFileName((char *)filename))) + { + WAD_FreeMemory(NULL, NULL, NULL, lump, NULL); + return NULL; + } + lump->disksize = disksize; + lump->size = size; + lump->compressed = compressed; + + lump->data = data; + + WAD_AddLumpToTree(lump, destlump); + + return lump; +} + +inline lump_t *WAD_AddLumpInWADByNum(wad_t *wad, wad_uint32_t num, const char *name, const char *filename) +{ + return WAD_AddLump(wad, WAD_LumpInWADByNum(wad, num), name, filename); +} + +inline lump_t *WAD_AddLumpInWADByName(wad_t *wad, const char *destname, const char *name, const char *filename) +{ + return WAD_AddLump(wad, WAD_LumpInWADByName(wad, destname), name, filename); +} + +inline lump_t *WAD_AddLumpByName(const char *destname, const char *name, const char *filename) +{ + lump_t *l = WAD_LumpByName(destname); + return WAD_AddLump(l->wad, l, name, filename); +} + +lump_t *WAD_CacheLump(lump_t *lump) +{ + return lump; // TODO: WAD_CacheLump, dynamic lump loading. +} + +inline lump_t *WAD_CacheLumpInWADByNum(wad_t *wad, wad_uint32_t num) +{ + return WAD_CacheLump(WAD_LumpInWADByNum(wad, num)); +} + +inline lump_t *WAD_CacheLumpInWADByName(wad_t *wad, const char *name) +{ + return WAD_CacheLump(WAD_LumpInWADByName(wad, name)); +} + +inline lump_t *WAD_CacheLumpByName(const char *name) +{ + return WAD_CacheLump(WAD_LumpByName(name)); +} + +lump_t *WAD_MoveLump(lump_t *lump, lump_t *destlump) +{ + lump_t *l; + + if (!destlump) + return NULL; + + // + // Link the previous and next nodes in the WAD tree with each other. + // + if (lump->next) + { + lump->next->prev = lump->prev; + for (l = lump->next; l; l = l->next) + l->num--; + } + if (lump->prev) + lump->prev->next = lump->next; + lump->wad->header->numlumps--; + + // + WAD_AddLumpToTree(lump, destlump); + + return lump; +} + +inline lump_t *WAD_MoveLumpInWADByNum(wad_t *wad, wad_uint32_t num, wad_t *destwad, wad_uint32_t destnum) +{ + return WAD_MoveLump(WAD_LumpInWADByNum(wad, num), WAD_LumpInWADByNum(destwad, destnum)); +} + +inline lump_t *WAD_MoveLumpInWADByName(wad_t *wad, const char *name, wad_t *destwad, const char *destname) +{ + return WAD_MoveLump(WAD_LumpInWADByName(wad, name), WAD_LumpInWADByName(destwad, destname)); +} + +inline lump_t *WAD_MoveLumpByName(const char *name, const char *destname) +{ + return WAD_MoveLump(WAD_LumpByName(name), WAD_LumpByName(destname)); +} + +void WAD_UncacheLump(lump_t *lump) +{ + (void)lump; // TODO: WAD_UncacheLump, dynamic lump loading. +} + +inline void WAD_UncacheLumpInWADByNum(wad_t *wad, wad_uint32_t num) +{ + WAD_UncacheLump(WAD_LumpInWADByNum(wad, num)); +} + +inline void WAD_UncacheLumpInWADByName(wad_t *wad, const char *name) +{ + WAD_UncacheLump(WAD_LumpInWADByName(wad, name)); +} + +inline void WAD_UncacheLumpByName(const char *name) +{ + WAD_UncacheLump(WAD_LumpByName(name)); +} + +void WAD_RemoveLump(lump_t *lump) +{ + lump_t *l; + + if (!lump) + return; + + // + // Link the previous and next nodes in the WAD tree with each other. + // + lump->next->prev = lump->prev; + lump->prev->next = lump->next; + + // + // Modify the lump numbers for all the subsequent lumps, + // and the total lumps in the WAD. + // + lump->wad->header->numlumps--; + + if (lump->num == 0) + lump->wad->lumps = lump->next; + + for (l = lump->next; l; l = l->next) + l->num--; + + // + // While, at the same time, blanking the references + // to these nodes so they don't get removed. + // + lump->next = NULL; + + // + // Free this lump's memory. + // + WAD_FreeMemory(NULL, NULL, NULL, lump, NULL); +} + +inline void WAD_RemoveLumpInWADByNum(wad_t *wad, wad_uint32_t num) +{ + WAD_RemoveLump(WAD_LumpInWADByNum(wad, num)); +} + +inline void WAD_RemoveLumpInWADByName(wad_t *wad, const char *name) +{ + WAD_RemoveLump(WAD_LumpInWADByName(wad, name)); +} + +inline void WAD_RemoveLumpByName(const char *name) +{ + WAD_RemoveLump(WAD_LumpByName(name)); +} diff --git a/tools/libwad/src/wad.c b/tools/libwad/src/wad.c new file mode 100644 index 000000000..ab8099b47 --- /dev/null +++ b/tools/libwad/src/wad.c @@ -0,0 +1,412 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// libwad: Doom WAD format interface library. +// Copyright (C) 2011 by Callum Dickinson. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +//----------------------------------------------------------------------------- +/// \file wad.c +/// \brief WAD interface functionality. + +#include "wad_static.h" + +// +// Offset for the first lump's data is always 12 bytes. +// +#define LUMPOFFSET 12 + +// +// Maximum of wad files used at the same time. +// (There is a max of simultaneous open files anyway, and this should be plenty.) +// +#define MAX_WADFILES 48 + +wad_t *wads[MAX_WADFILES]; +wad_uint32_t wad_numwads; + +wad_uint32_t wad_oldnumwads; +wad_uint32_t wad_removednum; + +static inline void WAD_ChangeWADNum(wad_int32_t i, wad_t *wad) +{ + wads[i] = wad; +} + +static inline void WAD_CacheWAD(wad_t *wad) +{ + WAD_ChangeWADNum(wad_numwads, wad); + wad_oldnumwads = wad_numwads; + wad_numwads++; +} + +static void WAD_UncacheWAD(wad_t *wad) +{ + wad_uint32_t i; + + for (i = 0; i < wad_numwads; i++) + if (WAD_WADByNum(i) == wad) + break; + + WAD_ChangeWADNum(i, NULL); + wad_removednum = i; + + for (; i < wad_numwads; i++) + { + if (WAD_WADByNum(i+1)) + { + WAD_ChangeWADNum(i, WAD_WADByNum(i+1)); + WAD_ChangeWADNum(i+1, NULL); + } + } + + wad_oldnumwads = wad_numwads; + wad_numwads--; +} + +wad_uint32_t WAD_WADLoopAdvance(wad_uint32_t i) +{ + wad_uint32_t o; + + o = wad_oldnumwads; + wad_oldnumwads = wad_numwads; + + return (o > wad_numwads && i <= wad_removednum) ? i : i + 1; +} + +wad_t *WAD_WADByNum(wad_uint16_t num) +{ + return (wads[num]) ? (wad_t *)wads[num] : NULL; +} + +wad_t *WAD_WADByFileName(const char *filename) +{ + wad_uint32_t i; + wad_t *w; + + for (i = 0; i < wad_numwads; i = WAD_WADLoopAdvance(i)) + { + w = WAD_WADByNum(i); + if (!strcmp(filename, w->filename)) + return w; + } + + return NULL; +} + +// +// Allocate a wadfile, setup the lumpinfo (directory) and +// lumpcache, add the wadfile to the current active wadfiles +// +// 1: Reached the maximum WAD number. +// 2: Cannot open the file. +// 3: Cannot read the WAD file's header. +// 4: Invalid WAD ID. +// 5: WAD's lump directory is corrupt. +// 6: Corrupt compressed WAD. +// +wad_t *WAD_OpenWAD(const char *filename) +{ + size_t i; + // Pointer to the WAD. + wad_t *wad = NULL; + // WAD file structure information. + // wad->filename is the function's argument. + FILE *file; // wad->file + wadheader_t *header; // wad->header + lump_t *l, *lumps = NULL; // wad->lumps + // Temporary lump information. + wad_uint64_t position; + lumpdir_t *lumpdir; + lump_t *ln = NULL; + + // + // Check if the limit of maximum WAD files has been + // reached or not. + // + if (wad_numwads >= MAX_WADFILES) + return NULL; + + // + // Open the WAD file. + // + if (!(file = fopen(filename, "rb"))) + return NULL; + + // + // Read the WAD file's header. + // + header = malloc(sizeof(*header)); + if (fread(header, 1, sizeof(*header), file) < sizeof(*header)) + return NULL; + + // Check if the ID is valid. + if (memcmp(header->id, "IWAD", 4) && memcmp(header->id, "PWAD", 4) && memcmp(header->id, "SDLL", 4)) + { + WAD_FreeMemory(file, header, NULL, NULL, NULL); + return NULL; + } + + // Check the rest of the header for type. + header->numlumps = WAD_INT32_Endianness(header->numlumps); + header->lumpdir = WAD_INT32_Endianness(header->lumpdir); + + // + // Read the WAD file's lump directory. + // + i = header->numlumps * sizeof(*lumpdir); + lumpdir = malloc(i); + + if (fseek(file, header->lumpdir, SEEK_SET) < 0 || fread(lumpdir, i, 1, file) < 1) + { + WAD_FreeMemory(file, header, lumpdir, NULL, NULL); + return NULL; + } + + // + // Fill lump information structure. + // + for (i = 0; i < header->numlumps; i++, lumpdir++) + { + if (!(l = malloc(sizeof(*l)))) + { + WAD_FreeMemory(file, header, lumpdir, lumps, NULL); + return NULL; + } + + position = WAD_INT32_Endianness(lumpdir->position); + + strncpy(l->name, lumpdir->name, 8); + l->size = l->disksize = WAD_INT32_Endianness(lumpdir->size); + l->compressed = false; // TODO: Compressed WAD support. + + if (l->disksize) + { + fseek(file, position, SEEK_SET); + if (!(l->data = malloc(l->disksize)) || fread(l->data, l->disksize, 1, file) < 1) + { + WAD_FreeMemory(file, header, lumpdir, lumps, NULL); + + if (!l->data) + return NULL; + else + return NULL; + } + } + + l->num = i; + l->next = NULL; + if (!lumps) + { + l->prev = NULL; + ln = lumps = l; + } + else + { + l->prev = ln; + ln = ln->next = l; + } + } + //free(lumpdir); + + // + // Allocate and fill WAD entry. + // + if (!(wad = malloc(sizeof(*wad)))) + { + WAD_FreeMemory(file, header, NULL, lumps, NULL); + return NULL; + } + wad->filename = (char *)filename; + + wad->header = header; + wad->compressed = false; + + wad->lumps = lumps; + + for (l = wad->lumps; l; l = l->next) + l->wad = wad; + + fclose(file); + + // + // Add the WAD to the wadfiles buffer and wad_numwads number. + // + WAD_CacheWAD(wad); + + // + // Done, loaded the WAD file. + // + return wad; +} + +// 1: Invalid wad number. +// 2: Unable to open file for writing. +// 3: Unable to write wad ID to the header. +// 4: Unable to write number of lumps to the header. +// 5: Unable to write temporary data to the header. +// 6: Unable to write lump data. +// 7: Unable to write position of lump data. +// 8: Unable to Write size of lump data. +// 9: Unable to write lump name. +// 9: Unable to write directory position. +wad_int32_t WAD_SaveWAD(wad_t *wad) +{ + lump_t *l; + FILE *file; + char *newfilename; + wad_int64_t diroffset, lumpoffset; + + if (!wad) + return 1; + + newfilename = WAD_VA("%s%s", wad->filename, ".bak"); + + remove(newfilename); + rename(wad->filename, newfilename); + + if (!(file = fopen(wad->filename, "wb"))) + return 2; + + // + // Write four-character WAD ID. + // + if(fwrite(wad->header->id, 4, 1, file) < 1) + return 3; + + // + // Write number of lumps. + // + if (fwrite(&wad->header->numlumps, 4, 1, file) < 1) + return 4; + + // + // Offset of directory is not known yet. For now, write number of lumps + // again, just to fill the space. + // + if (fwrite(&wad->header->numlumps, 4, 1, file) < 1) + return 5; + + // + // Loop through lump list, writing lump data. + // + for (l = wad->lumps; l; l = l->next) + { + // Don't write anything for the head of the lump list or for lumps of + // zero length. + if (!l->data) + continue; + + // Write the data. + if (fwrite(l->data, l->disksize, 1, file) < 1) + return 6; + } + + // + // Current position is where directory will start. + // + diroffset = ftell(file); + + // + // Pointer to the offset for the first lump's data. + // + lumpoffset = LUMPOFFSET; + + // + // Loop through lump list again, this time writing directory entries. + // + for (l = wad->lumps; l; l = l->next) + { + // Write position of lump data. + if (fwrite(&lumpoffset, 4, 1, file) < 1) + return 7; + + // Write size of lump data. + if (fwrite(&(l->disksize), 4, 1, file) < 1) + return 8; + + // Write lump name. + if (fwrite(&(l->name), 8, 1, file) < 1) + return 9; + + // Increment lumpoffset variable as appropriate. + lumpoffset += l->disksize; + } + + // + // Go back to header and write the proper directory position. + // + fseek(file, 8, SEEK_SET); + if (fwrite(&diroffset, 4, 1, file) < 1) + return 10; + + // + // Done, saved the WAD file. + // + return 0; +} + +inline wad_int32_t WAD_SaveWADByNum(wad_uint16_t num) +{ + return WAD_SaveWAD(WAD_WADByNum(num)); +} + +inline wad_int32_t WAD_SaveWADByFileName(const char *filename) +{ + return WAD_SaveWAD(WAD_WADByFileName(filename)); +} + +inline wad_int32_t WAD_SaveCloseWAD(wad_t *wad) +{ + wad_int32_t ret; + + if (!(ret = WAD_SaveWAD(wad))) + return ret; + + WAD_CloseWAD(wad); + return ret; +} + +inline wad_int32_t WAD_SaveCloseWADByNum(wad_uint16_t num) +{ + return WAD_SaveCloseWAD(WAD_WADByNum(num)); +} + +inline wad_int32_t WAD_SaveCloseWADByFileName(const char *filename) +{ + return WAD_SaveCloseWAD(WAD_WADByFileName(filename)); +} + +void WAD_CloseWAD(wad_t *wad) +{ + if (!wad) + return; + + // + // Free memory used by the WAD. + // + WAD_FreeMemory(NULL, wad->header, NULL, wad->lumps, wad); + + // + // Remove references to the WAD. + // + WAD_UncacheWAD(wad); +} + +inline void WAD_CloseWADByNum(wad_uint16_t num) +{ + WAD_CloseWAD(WAD_WADByNum(num)); +} + +inline void WAD_CloseWADByFileName(const char *name) +{ + WAD_CloseWAD(WAD_WADByFileName(name)); +} diff --git a/tools/libwad/src/wad_static.c b/tools/libwad/src/wad_static.c new file mode 100644 index 000000000..dd631a5ba --- /dev/null +++ b/tools/libwad/src/wad_static.c @@ -0,0 +1,116 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// libwad: Doom WAD format interface library. +// Copyright (C) 2011 by Callum Dickinson. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +//----------------------------------------------------------------------------- +/// \file wad_static.c +/// \brief Static functions for internal libwad operations. + +#include "wad_static.h" + +#define WAD_MAXERROR 1024 +static char wad_error[WAD_MAXERROR]; + +void WAD_ErrorSet(const char *text) +{ + strncpy(wad_error, text, WAD_MAXERROR); + wad_error[WAD_MAXERROR] = '\0'; +} + +inline void WAD_FreeMemory(FILE *file, wadheader_t *header, void *lumpdir, lump_t *lumps, wad_t *wad) +{ + lump_t *l, *ln = NULL; + + if (file) + fclose(file); + if (header) + free(header); + if (lumpdir) + free(lumpdir); + + if (lumps) + { + for (l = lumps; l; l = ln) + { + ln = l->next; + free(l->data); + free(l); + } + } + + if (wad) + { + if (wad->filename) + free(wad->filename); + + free(wad); + } +} + +char *WAD_Error(void) +{ + return wad_error; +} + +char *WAD_BaseName(char *path) +{ + wad_int32_t i; + + // + // Check if there is no text to check. + // + if (!path || path[0] == '\0') + return NULL; + + // + // Find the buffer entry where the actual filename begins. + // + for (i = strlen(path) - 1; i >= 0 && path[i] != '/'; i--); + + return (i >= 0) ? &path[i+1] : path; +} + +char *WAD_VA(const char *format, ...) +{ + va_list argptr; + static char string[1024]; + + va_start(argptr, format); + vsprintf(string, format, argptr); + va_end(argptr); + + return string; +} + +inline wad_int16_t WAD_INT16_Endianness(wad_int16_t x) +{ +#ifdef _BIG_ENDIAN + return ((wad_int16_t)((((wad_uint16_t)(x) & (wad_uint16_t)0x00ffU) << 8) | (((wad_uint16_t)(x) & (wad_uint16_t)0xff00U) >> 8))); +#else + return (wad_int16_t)x; +#endif +} + +inline wad_int32_t WAD_INT32_Endianness(wad_int32_t x) +{ +#ifdef _BIG_ENDIAN + return ((wad_int32_t)(\ + (((wad_uint32_t)(x) & (wad_uint32_t)0x000000ffUL) << 24) |\ + (((wad_uint32_t)(x) & (wad_uint32_t)0x0000ff00UL) << 8) |\ + (((wad_uint32_t)(x) & (wad_uint32_t)0x00ff0000UL) >> 8) |\ + (((wad_uint32_t)(x) & (wad_uint32_t)0xff000000UL) >> 24))); +#else + return (wad_int32_t)x; +#endif +} diff --git a/tools/libwad/src/wad_static.h b/tools/libwad/src/wad_static.h new file mode 100644 index 000000000..04d367bbd --- /dev/null +++ b/tools/libwad/src/wad_static.h @@ -0,0 +1,34 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// libwad: Doom WAD format interface library. +// Copyright (C) 2011 by Callum Dickinson. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +//----------------------------------------------------------------------------- +/// \file wad_static.h +/// \brief Static header for internal libwad operations. + +#ifndef __WAD_STATIC_H__ +#define __WAD_STATIC_H__ + +#include +#include +#include +#include +#include +#include "../include/wad.h" + +void WAD_ErrorSet(const char *text); + +inline void WAD_FreeMemory(FILE *file, wadheader_t *header, void *lumpdir, lump_t *lumps, wad_t *wad); + +#endif // __WAD_STATIC_H__ diff --git a/tools/lumpmod/Makefile b/tools/lumpmod/Makefile new file mode 100644 index 000000000..a01f80278 --- /dev/null +++ b/tools/lumpmod/Makefile @@ -0,0 +1,16 @@ +# Makfile for SRB2 Lumpmod +# by Alam Arias et al. + +SRC=lumpmod.c lump.c +OBJ=$(SRC:.c=.o)# replaces the .c from SRC with .o +EXE=lumpmod + +.PHONY : all # .PHONY ignores files named all +all: $(EXE) # all is dependent on $(BIN) to be complete + +$(EXE): $(OBJ) # $(EXE) is dependent on all of the files in $(OBJ) to exist + $(CC) $(OBJ) $(LDFLAGS) -o $@ + +.PHONY : clean # .PHONY ignores files named clean +clean: + -$(RM) $(OBJ) $(EXE) diff --git a/tools/lumpmod/lump.c b/tools/lumpmod/lump.c new file mode 100644 index 000000000..ed2ff2f9d --- /dev/null +++ b/tools/lumpmod/lump.c @@ -0,0 +1,473 @@ +/* + LumpMod v0.2.1, a command-line utility for working with lumps in wad + files. + Copyright (C) 2003 Thunder Palace Entertainment. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + lump.c: Provides functions for dealing with lumps +*/ + +#include +#include +#include +#include +#include "lump.h" + +/* Read contents of a wad file and store them in memory. + * fpoint is the file to read, opened with "rb" mode. + * A pointer to a new wadfile struct will be returned, or NULL on error. + */ +struct wadfile *read_wadfile(FILE *fpoint) { + struct wadfile *wfptr; + struct lumplist *curlump; + long diroffset, filelen; + unsigned long count; + + /* Allocate memory for wadfile struct */ + wfptr = malloc(sizeof(struct wadfile)); + if(wfptr == NULL) return NULL; + + /* Read first four characters (PWAD or IWAD) */ + if(fread(wfptr->id, 4, 1, fpoint) < 1) { + free(wfptr); + return NULL; + } + + /* Read number of lumps */ + if(fread(&(wfptr->numlumps), 4, 1, fpoint) < 1) { + free(wfptr); + return NULL; + } + + /* If number of lumps is zero, nothing more needs to be done */ + if(wfptr->numlumps == 0) { + wfptr->head = NULL; + return wfptr; + } + + /* Read offset of directory */ + if(fread(&diroffset, 4, 1, fpoint) < 1) { + free(wfptr); + return NULL; + } + + /* Verify that the directory as long as it needs to be */ + fseek(fpoint, 0, SEEK_END); + filelen = ftell(fpoint); + if((filelen - diroffset) / DIRENTRYLEN < wfptr->numlumps) { + free(wfptr); + return NULL; + } + + /* Allocate memory for head lumplist item and set head pointer */ + curlump = malloc(sizeof(struct lumplist)); + if(curlump == NULL) { + free(wfptr); + return NULL; + } + wfptr->head = curlump; + curlump->cl = NULL; + + /* Read directory entries and lumps */ + for(count = 0; count < wfptr->numlumps; count++) { + long lumpdataoffset; + + /* Advance to a new list item */ + curlump->next = malloc(sizeof(struct lumplist)); + if(curlump->next == NULL) { + free_wadfile(wfptr); + return NULL; + } + curlump = curlump->next; + curlump->next = NULL; + + /* Allocate memory for the lump info */ + curlump->cl = malloc(sizeof(struct lump)); + if(curlump->cl == NULL) { + free_wadfile(wfptr); + return NULL; + } + + /* Seek to the proper position in the file */ + if(fseek(fpoint, diroffset + (count * DIRENTRYLEN), SEEK_SET) != 0) { + free_wadfile(wfptr); + return NULL; + } + + /* Read offset of lump data */ + if(fread(&lumpdataoffset, 4, 1, fpoint) < 1) { + free_wadfile(wfptr); + return NULL; + } + + /* Read size of lump in bytes */ + if(fread(&(curlump->cl->len), 4, 1, fpoint) < 1) { + free_wadfile(wfptr); + return NULL; + } + + /* Read lump name */ + if(fread(curlump->cl->name, 8, 1, fpoint) < 1) { + free_wadfile(wfptr); + return NULL; + } + + /* Read actual lump data, unless lump size is 0 */ + if(curlump->cl->len > 0) { + if(fseek(fpoint, lumpdataoffset, SEEK_SET) != 0) { + free_wadfile(wfptr); + return NULL; + } + + /* Allocate memory for data */ + curlump->cl->data = malloc(curlump->cl->len); + if(curlump->cl->data == NULL) { + free_wadfile(wfptr); + return NULL; + } + + /* Fill the data buffer */ + if(fread(curlump->cl->data, curlump->cl->len, 1, fpoint) < 1) { + free_wadfile(wfptr); + return NULL; + } + } else curlump->cl->data = NULL; + } /* End of directory reading loop */ + + return wfptr; +} + +/* Free a wadfile from memory as well as all related structures. + */ +void free_wadfile(struct wadfile *wfptr) { + struct lumplist *curlump, *nextlump; + + if(wfptr == NULL) return; + curlump = wfptr->head; + + /* Free items in the lump list */ + while(curlump != NULL) { + + /* Free the actual lump and its data, if necessary */ + if(curlump->cl != NULL) { + if(curlump->cl->data != NULL) free(curlump->cl->data); + free(curlump->cl); + } + + /* Advance to next lump and free this one */ + nextlump = curlump->next; + free(curlump); + curlump = nextlump; + } + + free(wfptr); +} + +/* Write complete wadfile to a file stream, opened with "wb" mode. + * fpoint is the stream to write to. + * wfptr is a pointer to the wadfile structure to use. + * Return zero on success, nonzero on failure. + */ +int write_wadfile(FILE *fpoint, struct wadfile *wfptr) { + struct lumplist *curlump; + long lumpdataoffset, diroffset; + + if(wfptr == NULL) return 1; + + /* Write four-character ID ("PWAD" or "IWAD") */ + if(fwrite(wfptr->id, 4, 1, fpoint) < 1) return 2; + + /* Write number of lumps */ + if(fwrite(&(wfptr->numlumps), 4, 1, fpoint) < 1) return 3; + + /* Offset of directory is not known yet. For now, write number of lumps + * again, just to fill the space. + */ + if(fwrite(&(wfptr->numlumps), 4, 1, fpoint) < 1) return 4; + + /* Loop through lump list, writing lump data */ + for(curlump = wfptr->head; curlump != NULL; curlump = curlump->next) { + + /* Don't write anything for the head of the lump list or for lumps of + zero length */ + if(curlump->cl == NULL || curlump->cl->data == NULL) continue; + + /* Write the data */ + if(fwrite(curlump->cl->data, curlump->cl->len, 1, fpoint) < 1) + return 5; + } + + /* Current position is where directory will start */ + diroffset = ftell(fpoint); + + /* Offset for the first lump's data is always 12 */ + lumpdataoffset = 12; + + /* Loop through lump list again, this time writing directory entries */ + for(curlump = wfptr->head; curlump != NULL; curlump = curlump->next) { + + /* Don't write anything for the head of the lump list */ + if(curlump->cl == NULL) continue; + + /* Write offset for lump data */ + if(fwrite(&lumpdataoffset, 4, 1, fpoint) < 1) return 6; + + /* Write size of lump data */ + if(fwrite(&(curlump->cl->len), 4, 1, fpoint) < 1) return 7; + + /* Write lump name */ + if(fwrite(curlump->cl->name, 8, 1, fpoint) < 1) return 8; + + /* Increment lumpdataoffset variable as appropriate */ + lumpdataoffset += curlump->cl->len; + } + + /* Go back to header and write the proper directory offset */ + fseek(fpoint, 8, SEEK_SET); + if(fwrite(&diroffset, 4, 1, fpoint) < 1) return 9; + + return 0; +} + +/* Get the name of a lump, as a null-terminated string. + * item is a pointer to the lump (not lumplist) whose name will be obtained. + * Return NULL on error. + */ +char *get_lump_name(struct lump *item) { + char convname[9], *retname; + + if(item == NULL) return NULL; + memcpy(convname, item->name, 8); + convname[8] = '\0'; + + retname = malloc(strlen(convname) + 1); + if(retname != NULL) strcpy(retname, convname); + return retname; +} + +/* Find the lump after start and before end having a certain name. + * Return a pointer to the list item for that lump, or return NULL if no lump + * by that name is found or lumpname is too long. + * lumpname is a null-terminated string. + * If end parameter is NULL, search to the end of the entire list. + */ +struct lumplist *find_previous_lump(struct lumplist *start, struct lumplist + *end, char *lumpname) { + struct lumplist *curlump, *lastlump; + char *curname; + int found = 0; + + /* Verify that parameters are valid */ + if(start==NULL || start==end || lumpname==NULL || strlen(lumpname) > 8) + return NULL; + + /* Loop through the list from start parameter */ + lastlump = start; + for(curlump = start->next; curlump != end && curlump != NULL; + curlump = curlump->next) { + + /* Skip header lump */ + if(curlump->cl == NULL) continue; + + /* Find name of this lump */ + curname = get_lump_name(curlump->cl); + if(curname == NULL) continue; + + /* Compare names to see if this is the lump we want */ + if(strcmp(curname, lumpname) == 0) { + found = 1; + break; + } + + /* Free memory allocated to curname */ + free(curname); + + lastlump = curlump; + } + + if(found) return lastlump; + return NULL; +} + +/* Remove a lump from the list, free it, and free its data. + * before is the lump immediately preceding the lump to be removed. + * wfptr is a pointer to the wadfile structure to which the removed lump + * belongs, so that numlumps can be decreased. + */ +void remove_next_lump(struct wadfile *wfptr, struct lumplist *before) { + struct lumplist *removed; + + /* Verify that parameters are valid */ + if(before == NULL || before->next == NULL || wfptr == NULL) return; + + /* Update linked list to omit removed lump */ + removed = before->next; + before->next = removed->next; + + /* Free lump info and data if necessary */ + if(removed->cl != NULL) { + if(removed->cl->data != NULL) free(removed->cl->data); + free(removed->cl); + } + + free(removed); + + /* Decrement numlumps */ + wfptr->numlumps--; +} + +/* Add a lump. + * The lump will follow prev in the list and be named name, with a data size + * of len. + * A copy will be made of the data. + * Return zero on success or nonzero on failure. + */ +int add_lump(struct wadfile *wfptr, struct lumplist *prev, char *name, long + len, unsigned char *data) { + struct lump *newlump; + struct lumplist *newlumplist; + unsigned char *copydata; + + /* Verify that parameters are valid */ + if(wfptr == NULL || prev == NULL || name == NULL || strlen(name) > 8) + return 1; + + /* Allocate space for newlump and newlumplist */ + newlump = malloc(sizeof(struct lump)); + newlumplist = malloc(sizeof(struct lumplist)); + if(newlump == NULL || newlumplist == NULL) return 2; + + /* Copy lump data and set up newlump */ + if(len == 0 || data == NULL) { + newlump->len = 0; + newlump->data = NULL; + } else { + newlump->len = len; + copydata = malloc(len); + if(copydata == NULL) return 3; + memcpy(copydata, data, len); + newlump->data = copydata; + } + + /* Set name of newlump */ + memset(newlump->name, '\0', 8); + if(strlen(name) == 8) memcpy(newlump->name, name, 8); + else strcpy(newlump->name, name); + + /* Set up newlumplist and alter prev appropriately */ + newlumplist->cl = newlump; + newlumplist->next = prev->next; + prev->next = newlumplist; + + /* Increment numlumps */ + wfptr->numlumps++; + + return 0; +} + +/* Rename a lump. + * renamed is a pointer to the lump (not lumplist) that needs renaming. + * newname is a null-terminated string with the new name. + * Return zero on success or nonzero on failure. + */ +int rename_lump(struct lump *renamed, char *newname) { + + /* Verify that parameters are valid. */ + if(newname == NULL || renamed == NULL || strlen(newname) > 8) return 1; + + /* Do the renaming. */ + memset(renamed->name, '\0', 8); + if(strlen(newname) == 8) memcpy(renamed->name, newname, 8); + else strcpy(renamed->name, newname); + + return 0; +} + +/* Find the last lump in a wadfile structure. + * Return this lump or NULL on failure. + */ +struct lumplist *find_last_lump(struct wadfile *wfptr) { + struct lumplist *curlump; + + if(wfptr == NULL || wfptr->head == NULL) return NULL; + curlump = wfptr->head; + + while(curlump->next != NULL) curlump = curlump->next; + return curlump; +} + +/* Find the last lump between start and end. + * Return this lump or NULL on failure. + */ +struct lumplist *find_last_lump_between(struct lumplist *start, struct + lumplist *end) { + struct lumplist *curlump; + + if(start == NULL) return NULL; + curlump = start; + + while(curlump->next != end) { + curlump = curlump->next; + if(curlump == NULL) break; + } + + return curlump; +} + +/* Find the next section lump. A section lump is MAPxx (0 <= x <= 9), ExMy + * (0 <= x <= 9, 0 <= y <= 9), or any lump whose name ends in _START or _END. + * Return NULL if there are no section lumps after start. + */ +struct lumplist *find_next_section_lump(struct lumplist *start) { + struct lumplist *curlump, *found = NULL; + char *curname; + + /* Verify that parameter is valid */ + if(start == NULL || start->next == NULL) return NULL; + + /* Loop through the list from start parameter */ + for(curlump = start->next; curlump != NULL && found == NULL; + curlump = curlump->next) { + + /* Skip header lump */ + if(curlump->cl == NULL) continue; + + /* Find name of this lump */ + curname = get_lump_name(curlump->cl); + if(curname == NULL) continue; + + /* Check to see if this is a section lump */ + if(strlen(curname) == 5 && strncmp("MAP", curname, 3) == 0 && + isdigit(curname[3]) && isdigit(curname[4])) + found = curlump; + else if(strlen(curname) == 4 && curname[0] == 'E' && curname[2] == + 'M' && isdigit(curname[1]) && isdigit(curname[3])) + found = curlump; + else if(strlen(curname) == 7 && strcmp("_START", &curname[1]) == 0) + found = curlump; + else if(strlen(curname) == 8 && strcmp("_START", &curname[2]) == 0) + found = curlump; + else if(strlen(curname) == 5 && strcmp("_END", &curname[1]) == 0) + found = curlump; + else if(strlen(curname) == 6 && strcmp("_END", &curname[2]) == 0) + found = curlump; + + /* Free memory allocated to curname */ + free(curname); + } + + return found; +} diff --git a/tools/lumpmod/lump.h b/tools/lumpmod/lump.h new file mode 100644 index 000000000..88e478716 --- /dev/null +++ b/tools/lumpmod/lump.h @@ -0,0 +1,62 @@ +/* + LumpMod v0.2.1, a command-line utility for working with lumps in wad + files. + Copyright (C) 2003 Thunder Palace Entertainment. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + lump.h: Defines constants, structures, and functions used in lump.c +*/ + +#ifndef __LUMP_H +#define __LUMP_H + +/* Entries in the wadfile directory are 16 bytes */ +#define DIRENTRYLEN 16 + +/* Lumps and associated info */ +struct lump { + long len; + unsigned char *data; + char name[8]; +}; + +/* Linked list of lumps */ +struct lumplist { + struct lump *cl; /* actual content of the lump */ + struct lumplist *next; +}; + +/* Structure to contain all wadfile data */ +struct wadfile { + char id[4]; /* IWAD or PWAD */ + long numlumps; /* 32-bit integer */ + struct lumplist *head; /* points to first entry */ +}; + +/* Function declarations */ +struct wadfile *read_wadfile(FILE *); +void free_wadfile(struct wadfile *); +int write_wadfile(FILE *, struct wadfile *); +char *get_lump_name(struct lump *); +struct lumplist *find_previous_lump(struct lumplist *, struct lumplist *, char *); +void remove_next_lump(struct wadfile *, struct lumplist *); +int add_lump(struct wadfile *, struct lumplist *, char *, long, unsigned char *); +int rename_lump(struct lump *, char *); +struct lumplist *find_last_lump(struct wadfile *); +struct lumplist *find_last_lump_between(struct lumplist *, struct lumplist *); +struct lumplist *find_next_section_lump(struct lumplist *); + +#endif diff --git a/tools/lumpmod/lumpmod.c b/tools/lumpmod/lumpmod.c new file mode 100644 index 000000000..e9042615e --- /dev/null +++ b/tools/lumpmod/lumpmod.c @@ -0,0 +1,785 @@ +/* + LumpMod v0.2.1, a command-line utility for working with lumps in wad + files. + Copyright (C) 2003 Thunder Palace Entertainment. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + lumpmod.c: Provides program functionality; depends on lump.c and lump.h +*/ + +#include +#include +#include +#include "lump.h" + +int main(int argc, char *argv[]) { + enum commands { C_ADD, C_ADDSECT, C_DELETE, C_DELSECT, C_EXTRACT, C_LIST, + C_RENAME, C_UPDATE } cmd; + struct wadfile *wfptr; + struct lumplist *startitem, *enditem = NULL; + FILE *fpoint; + char *progname, **params; + char *startname = NULL, *endname = NULL; + int numargs, numparams, insection = 0; + + progname = argv[0]; + numargs = argc - 1; + + /* Verify that there are enough arguments */ + if(numargs < 2) { + fprintf(stderr, "%s: not enough arguments\n", progname); + return EXIT_FAILURE; + } + + /* Identify the command used */ + if(strcmp(argv[2], "add" ) == 0) cmd = C_ADD; + else if(strcmp(argv[2], "addsect") == 0) cmd = C_ADDSECT; + else if(strcmp(argv[2], "delete" ) == 0) cmd = C_DELETE; + else if(strcmp(argv[2], "delsect") == 0) cmd = C_DELSECT; + else if(strcmp(argv[2], "extract") == 0) cmd = C_EXTRACT; + else if(strcmp(argv[2], "list" ) == 0) cmd = C_LIST; + else if(strcmp(argv[2], "rename" ) == 0) cmd = C_RENAME; + else if(strcmp(argv[2], "update" ) == 0) cmd = C_UPDATE; + else { + fprintf(stderr, "%s: invalid command %s\n", progname, argv[2]); + return EXIT_FAILURE; + } + + /* Check for -s option */ + if(numargs >= 4 && strcmp(argv[3], "-s") == 0) { + if(cmd == C_ADDSECT || cmd == C_DELSECT) { + fprintf(stderr, "%s: no option -s for command %s\n", progname, argv[2]); + return EXIT_FAILURE; + } + insection = 1; + params = &argv[5]; + numparams = numargs - 4; + + /* Assume a map name if length > 2 */ + if(strlen(argv[4]) > 2) startname = argv[4]; + else { + startname = malloc(strlen(argv[4]) + 7); + endname = malloc(strlen(argv[4]) + 5); + if(startname == NULL || endname == NULL) { + fprintf(stderr, "%s: out of memory\n", progname); + return EXIT_FAILURE; + } + sprintf(startname, "%s_START", argv[4]); + sprintf(endname, "%s_END", argv[4]); + } + } else { + params = &argv[3]; + numparams = numargs - 2; + } /* end of check for -s option */ + + /* Load the wadfile into memory, since all commands require this */ + fpoint = fopen(argv[1], "rb"); + if(fpoint == NULL) { + fprintf(stderr, "%s: unable to open file %s\n", progname, argv[1]); + return EXIT_FAILURE; + } + wfptr = read_wadfile(fpoint); + fclose(fpoint); + if(wfptr == NULL) { + fprintf(stderr, "%s: %s is not a valid wadfile\n", progname, argv[1]); + return EXIT_FAILURE; + } + + /* Find startitem and enditem, using startname and endname */ + if(startname == NULL) startitem = wfptr->head; + else { + startitem = find_previous_lump(wfptr->head, NULL, startname); + if(startitem == NULL) { + fprintf(stderr, "%s: can't find lump %s in %s", progname, + startname, argv[1]); + return EXIT_FAILURE; + } + startitem = startitem->next; + if(endname == NULL) { + if(startitem->next != NULL) { + char *itemname; + + enditem = startitem->next; + itemname = get_lump_name(enditem->cl); + while( strcmp(itemname, "THINGS" ) == 0 || + strcmp(itemname, "LINEDEFS") == 0 || + strcmp(itemname, "SIDEDEFS") == 0 || + strcmp(itemname, "VERTEXES") == 0 || + strcmp(itemname, "SEGS" ) == 0 || + strcmp(itemname, "SSECTORS") == 0 || + strcmp(itemname, "NODES" ) == 0 || + strcmp(itemname, "SECTORS" ) == 0 || + strcmp(itemname, "REJECT" ) == 0 || + strcmp(itemname, "BLOCKMAP") == 0) { + enditem = enditem->next; + if(enditem == NULL) break; + free(itemname); + itemname = get_lump_name(enditem->cl); + } + free(itemname); + if(enditem != NULL) enditem = enditem->next; + } else enditem = NULL; + } else { + enditem = find_previous_lump(startitem, NULL, endname); + if(enditem == NULL) { + fprintf(stderr, "%s: can't find lump %s in %s", progname, + endname, argv[1]); + return EXIT_FAILURE; + } + enditem = enditem->next; + } + } /* end of finding startitem and enditem */ + + /* Do stuff specific to each command */ + switch(cmd) { + case C_ADD: { + struct lumplist *startitem2, *before, *existing; + int overwrite = 1, firstentry = 0, canduplicate = 0; + char *startname2 = NULL; + + /* Parse options: -a, -b, -d, -n */ + while(numparams > 2) { + if(params[0][0] != '-') break; + if(strcmp(params[0], "-n") == 0) overwrite = 0; + else if(strcmp(params[0], "-d") == 0) canduplicate = 1; + else if(strcmp(params[0], "-b") == 0) firstentry = 1; + else if(strcmp(params[0], "-a") == 0) { + params = ¶ms[1]; + numparams--; + startname2 = params[0]; + } else { + fprintf(stderr, "%s: no option %s for command %s", + progname, params[0], argv[2]); + return EXIT_FAILURE; + } + params = ¶ms[1]; + numparams--; + } + + if(numparams < 2) { + fprintf(stderr, "%s: not enough parameters for %s", progname, + argv[2]); + return EXIT_FAILURE; + } + + /* Find the lump after which to add */ + if(firstentry) before = startitem; + else if(startname2 != NULL) { + before = find_previous_lump(startitem, enditem, startname2); + if(before == NULL) { + fprintf(stderr, "%s: can't find lump %s in %s", progname, + startname2, argv[1]); + return EXIT_FAILURE; + } + before = before->next; + } else { + if(insection) { + before = find_last_lump_between(startitem, enditem); + if(before == NULL) before = startitem; + } else before = find_last_lump(wfptr); + } + startitem2 = before; + + /* Add LUMPNAME FILENAME pairs */ + printf("Adding lumps in %s...\n", argv[1]); + for(;;) { + long newlumpsize; + unsigned char *newlumpdata; + + /* Check whether the lump already exists, unless -d is used */ + if(canduplicate) existing = NULL; + else existing = find_previous_lump(startitem, enditem, params[0]); + if(existing != NULL) existing = existing->next; + if(existing != NULL && overwrite == 0) { + printf("Lump %s already exists. Taking no action.\n", params[0]); + numparams -= 2; + if(numparams < 2) break; + params = ¶ms[2]; + continue; + } + + /* Read the file with new lump data */ + fpoint = fopen(params[1], "rb"); + if(fpoint == NULL) { + fprintf(stderr, "%s: can't open file %s\n", progname, + params[1]); + return EXIT_FAILURE; + } + + /* Find size of lump data */ + fseek(fpoint, 0, SEEK_END); + newlumpsize = ftell(fpoint); + fseek(fpoint, 0, SEEK_SET); + + /* Copy lump data to memory */ + if(newlumpsize == 0) newlumpdata = NULL; + else { + newlumpdata = malloc(newlumpsize); + if(newlumpdata == NULL) { + fprintf(stderr, "%s: out of memory\n", progname); + return EXIT_FAILURE; + } + if(fread(newlumpdata, newlumpsize, 1, fpoint) < 1) { + fprintf(stderr, "%s: unable to read file %s\n", + progname, params[1]); + return EXIT_FAILURE; + } + } + + /* Close the file */ + fclose(fpoint); + + /* Add or update lump */ + if(existing == NULL) { + if(add_lump(wfptr, before, params[0], newlumpsize, + newlumpdata) != 0) { + fprintf(stderr, "%s: unable to add lump %s\n", + progname, params[0]); + return EXIT_FAILURE; + } + printf("Lump %s added.\n", params[0]); + + /* Other lumps will be added after the new one */ + before = before->next; + } else { + existing->cl->len = newlumpsize; + free(existing->cl->data); + existing->cl->data = malloc(newlumpsize); + if(existing->cl->data == NULL) { + fprintf(stderr, "%s: out of memory\n", progname); + return EXIT_FAILURE; + } + memcpy(existing->cl->data, newlumpdata, newlumpsize); + printf("Lump %s updated.\n", params[0]); + } + + /* Advance to the next pair, if there is a next pair */ + numparams -= 2; + if(numparams < 2) break; + params = ¶ms[2]; + } /* end of adding LUMPNAME FILENAME pairs */ + + /* Save the modified wadfile */ + fpoint = fopen(argv[1], "wb"); + if(fpoint == NULL) { + fprintf(stderr, "%s: unable to open file %s for writing\n", + progname, argv[1]); + return EXIT_FAILURE; + } + if(write_wadfile(fpoint, wfptr) != 0) { + fprintf(stderr, "%s: unable to write wadfile to disk\n", + progname); + return EXIT_FAILURE; + } + fclose(fpoint); + printf("File %s successfully updated.\n", argv[1]); + } /* end of C_ADD */ + break; + + case C_UPDATE: { + struct lumplist *existing; + + /* Parse options (none) */ + if(numparams > 2 && params[0][0] == '-') { + fprintf(stderr, "%s: no option %s for command %s", + progname, params[0], argv[2]); + return EXIT_FAILURE; + } + + if(numparams < 2) { + fprintf(stderr, "%s: not enough parameters for %s", progname, + argv[2]); + return EXIT_FAILURE; + } + + /* Update LUMPNAME FILENAME pairs */ + printf("Updating lumps in %s...\n", argv[1]); + for(;;) { + long newlumpsize; + unsigned char *newlumpdata; + + /* Check whether the lump already exists */ + existing = find_previous_lump(startitem, enditem, params[0]); + if(existing == NULL) { + printf("Lump %s does not exist. Taking no action.\n", + params[0]); + numparams -= 2; + if(numparams < 2) break; + params = ¶ms[2]; + continue; + } + existing = existing->next; + + /* Read the file with new lump data */ + fpoint = fopen(params[1], "rb"); + if(fpoint == NULL) { + fprintf(stderr, "%s: can't open file %s\n", progname, + params[1]); + return EXIT_FAILURE; + } + + /* Find size of lump data */ + fseek(fpoint, 0, SEEK_END); + newlumpsize = ftell(fpoint); + fseek(fpoint, 0, SEEK_SET); + + /* Copy lump data to memory */ + if(newlumpsize == 0) newlumpdata = NULL; + else { + newlumpdata = malloc(newlumpsize); + if(newlumpdata == NULL) { + fprintf(stderr, "%s: out of memory\n", progname); + return EXIT_FAILURE; + } + if(fread(newlumpdata, newlumpsize, 1, fpoint) < 1) { + fprintf(stderr, "%s: unable to read file %s\n", + progname, params[1]); + return EXIT_FAILURE; + } + } + + /* Close the file */ + fclose(fpoint); + + /* Update lump */ + existing->cl->len = newlumpsize; + free(existing->cl->data); + existing->cl->data = malloc(newlumpsize); + if(existing->cl->data == NULL) { + fprintf(stderr, "%s: out of memory\n", progname); + return EXIT_FAILURE; + } + memcpy(existing->cl->data, newlumpdata, newlumpsize); + printf("Lump %s updated.\n", params[0]); + + /* Advance to the next pair, if there is a next pair */ + numparams -= 2; + if(numparams < 2) break; + params = ¶ms[2]; + } /* end of updating LUMPNAME FILENAME pairs */ + + /* Save the modified wadfile */ + fpoint = fopen(argv[1], "wb"); + if(fpoint == NULL) { + fprintf(stderr, "%s: unable to open file %s for writing\n", + progname, argv[1]); + return EXIT_FAILURE; + } + if(write_wadfile(fpoint, wfptr) != 0) { + fprintf(stderr, "%s: unable to write wadfile to disk\n", + progname); + return EXIT_FAILURE; + } + fclose(fpoint); + printf("File %s successfully updated.\n", argv[1]); + } /* end of C_UPDATE */ + break; + + case C_DELETE: { + struct lumplist *before; + + /* Parse options (none) */ + if(numparams > 1 && params[0][0] == '-') { + fprintf(stderr, "%s: no option %s for command %s", + progname, params[0], argv[2]); + return EXIT_FAILURE; + } + + if(numparams < 1) { + fprintf(stderr, "%s: not enough parameters for %s", progname, + argv[2]); + return EXIT_FAILURE; + } + + /* Delete LUMPNAME lumps */ + printf("Deleting lumps in %s...\n", argv[1]); + for(;;) { + + /* Find the lump to delete */ + before = find_previous_lump(startitem, enditem, params[0]); + if(before == NULL) { + printf("Lump %s does not exist. Taking no action.\n", + params[0]); + numparams--; + if(numparams < 1) break; + params = ¶ms[1]; + continue; + } + + /* Delete it */ + remove_next_lump(wfptr, before); + printf("Lump %s deleted.\n", params[0]); + + /* Advance to the next item to delete, if there is one */ + numparams--; + if(numparams < 1) break; + params = ¶ms[1]; + } /* end of deleting LUMPNAME lumps */ + + /* Save the modified wadfile */ + fpoint = fopen(argv[1], "wb"); + if(fpoint == NULL) { + fprintf(stderr, "%s: unable to open file %s for writing\n", + progname, argv[1]); + return EXIT_FAILURE; + } + if(write_wadfile(fpoint, wfptr) != 0) { + fprintf(stderr, "%s: unable to write wadfile to disk\n", + progname); + return EXIT_FAILURE; + } + fclose(fpoint); + printf("File %s successfully updated.\n", argv[1]); + } /* end of C_DELETE */ + break; + + case C_RENAME: { + struct lumplist *renamed; + + /* Parse options (none) */ + if(numparams > 2 && params[0][0] == '-') { + fprintf(stderr, "%s: no option %s for command %s", + progname, params[0], argv[2]); + return EXIT_FAILURE; + } + + if(numparams < 2) { + fprintf(stderr, "%s: not enough parameters for %s", progname, + argv[2]); + return EXIT_FAILURE; + } + + /* Rename OLDNAME NEWNAME pairs */ + printf("Renaming lumps in %s...\n", argv[1]); + for(;;) { + + /* Find the lump to rename */ + renamed = find_previous_lump(startitem, enditem, params[0]); + if(renamed == NULL) { + printf("Lump %s does not exist. Taking no action.\n", + params[0]); + numparams -= 2; + if(numparams < 2) break; + params = ¶ms[2]; + continue; + } + renamed = renamed->next; + + /* Rename lump */ + memset(renamed->cl->name, '\0', 8); + if(strlen(params[1]) >= 8) memcpy(renamed->cl->name, + params[1], 8); + else strcpy(renamed->cl->name, params[1]); + + printf("Lump %s renamed to %s.\n", params[0], params[1]); + + /* Advance to the next pair, if there is a next pair */ + numparams -= 2; + if(numparams < 2) break; + params = ¶ms[2]; + } /* end of renaming OLDNAME NEWNAME pairs */ + + /* Save the modified wadfile */ + fpoint = fopen(argv[1], "wb"); + if(fpoint == NULL) { + fprintf(stderr, "%s: unable to open file %s for writing\n", + progname, argv[1]); + return EXIT_FAILURE; + } + if(write_wadfile(fpoint, wfptr) != 0) { + fprintf(stderr, "%s: unable to write wadfile to disk\n", + progname); + return EXIT_FAILURE; + } + fclose(fpoint); + printf("File %s successfully updated.\n", argv[1]); + } /* end of C_RENAME */ + break; + + case C_EXTRACT: { + struct lumplist *extracted; + + /* Parse options (none) */ + if(numparams > 2 && params[0][0] == '-') { + fprintf(stderr, "%s: no option %s for command %s", + progname, params[0], argv[2]); + return EXIT_FAILURE; + } + + if(numparams < 2) { + fprintf(stderr, "%s: not enough parameters for %s", progname, + argv[2]); + return EXIT_FAILURE; + } + + /* Extract LUMPNAME FILENAME pairs */ + printf("Extracting lumps from %s...\n", argv[1]); + for(;;) { + + /* Find the lump to extract */ + extracted = find_previous_lump(startitem, enditem, params[0]); + if(extracted == NULL) { + printf("Lump %s does not exist. Taking no action.\n", + params[0]); + numparams -= 2; + if(numparams < 2) break; + params = ¶ms[2]; + continue; + } + extracted = extracted->next; + + /* Open the file to extract to */ + fpoint = fopen(params[1], "wb"); + if(fpoint == NULL) { + fprintf(stderr, "%s: can't open file %s for writing\n", + progname, params[1]); + return EXIT_FAILURE; + } + + /* Extract lump */ + if(fwrite(extracted->cl->data, extracted->cl->len, 1, fpoint) + < 1) { + fprintf(stderr, "%s: unable to write lump %s to disk\n", + progname, params[0]); + return EXIT_FAILURE; + } + + /* Close the file */ + fclose(fpoint); + printf("Lump %s saved as %s.\n", params[0], params[1]); + + /* Advance to the next pair, if there is a next pair */ + numparams -= 2; + if(numparams < 2) break; + params = ¶ms[2]; + } /* end of extracting LUMPNAME FILENAME pairs */ + + printf("Finished extracting lumps from file %s.\n", argv[1]); + } /* end of C_EXTRACT */ + break; + + case C_LIST: { + struct lumplist *curlump; + int verbose = 0, i = 0; + + /* Parse options: -v */ + while(numparams > 0) { + if(params[0][0] != '-') break; + if(strcmp(params[0], "-v") == 0) verbose = 1; + else { + fprintf(stderr, "%s: no option %s for command %s", + progname, params[0], argv[2]); + return EXIT_FAILURE; + } + params = ¶ms[1]; + numparams--; + } + + /* Loop through the lump list, printing lump info */ + for(curlump = startitem->next; curlump != enditem; curlump = + curlump->next) { + i++; + if(verbose) printf("%5i %-8s %7li\n", i, + get_lump_name(curlump->cl), curlump->cl->len); + else printf("%s\n", get_lump_name(curlump->cl)); + } + } /* end of C_LIST */ + break; + + case C_DELSECT: { + + /* Parse options (none) */ + if(numparams > 1 && params[0][0] == '-') { + fprintf(stderr, "%s: no option %s for command %s", + progname, params[0], argv[2]); + return EXIT_FAILURE; + } + + if(numparams < 1) { + fprintf(stderr, "%s: not enough parameters for %s", progname, + argv[2]); + return EXIT_FAILURE; + } + + /* Delete sections */ + printf("Deleting sections in %s...\n", argv[1]); + for(;;) { + struct lumplist *curlump; + + /* Assume a map name if length > 2 */ + if(strlen(params[0]) > 2) startname = params[0]; + else { + startname = malloc(strlen(params[0]) + 7); + endname = malloc(strlen(params[0]) + 5); + if(startname == NULL || endname == NULL) { + fprintf(stderr, "%s: out of memory\n", progname); + return EXIT_FAILURE; + } + sprintf(startname, "%s_START", params[0]); + sprintf(endname, "%s_END", params[0]); + } + + /* Find startitem and enditem, using startname and endname */ + startitem = find_previous_lump(wfptr->head, NULL, startname); + if(startitem == NULL) { + fprintf(stderr, "%s: can't find lump %s in %s", progname, + startname, argv[1]); + return EXIT_FAILURE; + } + if(endname == NULL && startitem->next != NULL) { + char *itemname; + + enditem = startitem->next; + itemname = get_lump_name(enditem->cl); + do { + enditem = enditem->next; + if(enditem == NULL) break; + free(itemname); + itemname = get_lump_name(enditem->cl); + } while(strcmp(itemname, "THINGS" ) == 0 || + strcmp(itemname, "LINEDEFS") == 0 || + strcmp(itemname, "SIDEDEFS") == 0 || + strcmp(itemname, "VERTEXES") == 0 || + strcmp(itemname, "SEGS" ) == 0 || + strcmp(itemname, "SSECTORS") == 0 || + strcmp(itemname, "NODES" ) == 0 || + strcmp(itemname, "SECTORS" ) == 0 || + strcmp(itemname, "REJECT" ) == 0 || + strcmp(itemname, "BLOCKMAP") == 0); + free(itemname); + } + else { + enditem = find_previous_lump(startitem, NULL, endname); + if(enditem == NULL) { + fprintf(stderr, "%s: can't find lump %s in %s", + progname, endname, argv[1]); + return EXIT_FAILURE; + } + enditem = enditem->next->next; + } /* end of finding startitem and enditem */ + + /* Loop through the section lumps, deleting them */ + curlump = startitem; + while(curlump->next != enditem) + remove_next_lump(wfptr, curlump); + printf("Deleted section %s.\n", params[0]); + + /* Move to next parameter, if it exists */ + numparams--; + if(numparams < 1) break; + params = ¶ms[1]; + } /* end of deleting sections */ + + /* Save the modified wadfile */ + fpoint = fopen(argv[1], "wb"); + if(fpoint == NULL) { + fprintf(stderr, "%s: unable to open file %s for writing\n", + progname, argv[1]); + return EXIT_FAILURE; + } + if(write_wadfile(fpoint, wfptr) != 0) { + fprintf(stderr, "%s: unable to write wadfile to disk\n", + progname); + return EXIT_FAILURE; + } + fclose(fpoint); + printf("File %s successfully updated.\n", argv[1]); + } /* end of C_DELSECT */ + break; + + case C_ADDSECT: { + + /* Parse options (none) */ + if(numparams > 1 && params[0][0] == '-') { + fprintf(stderr, "%s: no option %s for command %s", + progname, params[0], argv[2]); + return EXIT_FAILURE; + } + + if(numparams < 1) { + fprintf(stderr, "%s: not enough parameters for %s", progname, + argv[2]); + return EXIT_FAILURE; + } + + /* Add sections */ + printf("Adding sections in %s...\n", argv[1]); + for(;;) { + struct lumplist *curlump; + + /* Assume a map name if length > 2 */ + if(strlen(params[0]) > 2) startname = params[0]; + else { + startname = malloc(strlen(params[0]) + 7); + endname = malloc(strlen(params[0]) + 5); + if(startname == NULL || endname == NULL) { + fprintf(stderr, "%s: out of memory\n", progname); + return EXIT_FAILURE; + } + sprintf(startname, "%s_START", params[0]); + sprintf(endname, "%s_END", params[0]); + } + + /* Add section, unless it already exists */ + if(find_previous_lump(wfptr->head, NULL, startname) == NULL) { + struct lumplist *last; + + last = find_last_lump(wfptr); + if(add_lump(wfptr, last, startname, 0, NULL) != 0) { + fprintf(stderr, "%s: unable to add lump %s\n", + progname, startname); + return EXIT_FAILURE; + } + + if(endname != NULL) { + last = last->next; + if(add_lump(wfptr, last, endname, 0, NULL) != 0) { + fprintf(stderr, "%s: unable to add lump %s\n", + progname, endname); + return EXIT_FAILURE; + } + } + + printf("Added section %s.\n", params[0]); + } else + printf("Section %s already exists. Taking no action.\n", + params[0]); + + /* Move to next parameter, if it exists */ + numparams--; + if(numparams < 1) break; + params = ¶ms[1]; + } /* end of adding sections */ + + /* Save the modified wadfile */ + fpoint = fopen(argv[1], "wb"); + if(fpoint == NULL) { + fprintf(stderr, "%s: unable to open file %s for writing\n", + progname, argv[1]); + return EXIT_FAILURE; + } + if(write_wadfile(fpoint, wfptr) != 0) { + fprintf(stderr, "%s: unable to write wadfile to disk\n", + progname); + return EXIT_FAILURE; + } + fclose(fpoint); + printf("File %s successfully updated.\n", argv[1]); + } /* end of C_ADDSECT */ + } /* end of command-specific stuff */ + + return EXIT_SUCCESS; +} diff --git a/tools/lumpmod/lumpmod.html b/tools/lumpmod/lumpmod.html new file mode 100644 index 000000000..082784178 --- /dev/null +++ b/tools/lumpmod/lumpmod.html @@ -0,0 +1,82 @@ + + + + +LumpMod v0.2.1 Documentation +

LumpMod v0.2.1

+

LumpMod is a small command-line utility for working with lumps in wad +files in the format used by DOOM and DOOM 2. It can add, delete, extract, +rename, list, and update individual lumps. It can also add sections +(XX_START and XX_END, for instance) and delete entire sections.

+

Usage

+

lumpmod [wadfile] [command] [-s section] [parameters]

+

Sections are MAPxx (xx = 01-99, where that map exists in the file), ExMy +(x, y = 1-9, where that map exists in the file), and anything else will be +the section between WHATEVER_START and WHATEVER_END. Sections that do not +exist in the wad file cannot be used. The section part can be left out to +work with the whole file. Any section specified here while using the addsect +or delsect commands will cause an error.

+

Note that the []... parameters in the command listings can be repeated. +For example, you can use lumpmod clowns.wad add CLOWNS clowns.lmp to +add a CLOWNS lump, or lumpmod clowns.wad add CLOWN1 clown1.lmp CLOWN2 +clown2.lmp to add two clown-related lumps.

+

Note also that lump names and commands are case sensitive. There is an +update command, but no UPDATE command.

+

Commands

+

add [-a lumpname] [-b] [-d] [-n] [LUMPNAME FILENAME]...

+

Add a lump to the end of the wad, or after the lump specified with the -a +option. If the lump already exists, it will be overwritten (with its position +unchanged) unless the -n option is specified, in which case no action will be +taken, or the -d option is specified, in which case an additional lump with +the same name will be added. If the lump specified in the -a option does not +exist, an error will occur. The -b option will add the lump at the beginning, +overriding the -a option.

+

addsect [SECTNAME]...

+

Add a section. The name must be one or two characters long. If section +name is HX, zero-length entries HX_START and HX_END will be added to the end +of the wad file. If this section already exists, no action will be taken.

+

delete [LUMPNAME]...

+

Remove LUMPNAME from the wad.

+

delsect [SECTNAME]...

+

Delete a section and anything inside it. If the section doesn't exist, no +action will be taken.

+

extract [LUMPNAME FILENAME]...

+

Save the contents of LUMPNAME to the file named FILENAME. (Wad file will +not be changed in any way.)

+

list [-v]

+

List all lumps in the wad, in the order they appear in the directory. +With the -v option, include numbers and lump lengths.

+

rename [OLDNAME NEWNAME]...

+

Rename a lump in the wad.

+

update [LUMPNAME FILENAME]...

+

Update LUMPNAME with the contents of FILENAME. If no lump named LUMPNAME +exists in the wad, no action will be taken.

+

Changes

+

Version 0.2.1 adds the -d option to the add command.

+

Version 0.2 contains a fix to a bug involving empty sections. The initial +public release was version 0.1.

+

Bugs

+

LumpMod currently chokes on completely empty wad files (i.e., those that +contain absolutely no lumps). Let me know if you find any other bugs.

+

Author

+

Catatonic Porpoise, <graue@oceanbase.org>. +Updates can be found at http://www.thunderpalace.com/software/.

+

Thanks

+

Thanks to Matthew S. Fell for writing "The Unofficial DOOM +Specs," which were very helpful in making this program.

+

License

+

Copyright © 2003 Thunder Palace Entertainment.

+

This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version.

+

This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details.

+

You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

+ diff --git a/tools/makefile b/tools/makefile new file mode 100644 index 000000000..f4b377a26 --- /dev/null +++ b/tools/makefile @@ -0,0 +1,24 @@ + +default: dircomp2.c + gcc -O6 -mpentium -Wall -s dircomp2.c -o dircomp2.exe + +asm: + gcc -O6 -mpentium -Wall -g dircomp2.c -o tmp.exe + objdump -dS tmp.exe --debugging --no-show-raw-insn > dircomp2.s + del tmp.exe + +h2d: h2d.c + gcc -O6 -mpentium -Wall -s h2d.c -o h2d.exe + +dckconv: dckconv.c + gcc -O6 -mpentium -Wall -s dckconv.c -o dckconv.exe + +dckconv2: dckconv2.c + gcc -O6 -mpentium -Wall -s dckconv2.c -o dckconv2.exe + +dckcomp: dckcomp.c + gcc -O6 -mpentium -Wall -s dckcomp.c -o dckcomp.exe + +convert: convert.c + gcc -O6 -mpentium -Wall -s convert.c -o convert.exe + diff --git a/tools/masterserver/.gitignore b/tools/masterserver/.gitignore new file mode 100644 index 000000000..9f45745a3 --- /dev/null +++ b/tools/masterserver/.gitignore @@ -0,0 +1,4 @@ +/client +/server +/server.log +/*.o diff --git a/tools/masterserver/Makefile b/tools/masterserver/Makefile new file mode 100644 index 000000000..7e66ab210 --- /dev/null +++ b/tools/masterserver/Makefile @@ -0,0 +1,140 @@ +# Copyright (C) 2000 by DooM Legacy Team. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# DESCRIPTION: +# Makefile for DooM Legacy Master Server +# Created on 06/23/2000 by Thierry Van Elsuwe +# e-mail: hurdler@newdoom.com +# +#----------------------------------------------------------------------------- + +PORT=28900 +#PORT=7896 + +#*******************************************************************# + +CCFILES=common.cpp ipcs.cpp crypt.cpp md5.cpp +Main_CCFILES=server.cpp #client.cpp + +#******************************************************************# + +MYSQL_CONFIG?= mysql_config +MYSQL_CFLAGS?=$(shell $(MYSQL_CONFIG) --cflags) +MYSQL_LIBS?=$(shell $(MYSQL_CONFIG) --libs) + +CXXFLAGS+=-Wall -O3 -Wextra +ifdef MINGW +LIBS+=-lws2_32 +else +LIBS+=-lm +endif + +CXXFLAGS+=$(MYSQL_CFLAGS) +LIBS+=$(MYSQL_LIBS) + +ifdef DEBUG +CXXFLAGS+=-g -D__DEBUG__ +endif + +SRCS=$(CCFILES) $(Main_CCFILES) +OFILES=$(CCFILES:.cpp=.o) +Main_OFILES=$(Main_CCFILES:.cpp=.o) +EXEFILE=$(Main_CCFILES:.cpp=) + +##################################################################### + +.SUFFIXES: .cpp .h + +default: init $(EXEFILE) end + +init: + @echo + @echo "Compiling options:" + @echo " CXX : $(CXX)" + @echo " LDFLAGS : $(LDFLAGS)" + @echo " LIBS : $(LIBS)" + @echo " CXXFLAGS: $(CXXFLAGS)" + @echo + @echo "Files:" + @echo " SRCS : $(SRCS)" + @echo " OFILES : $(OFILES) $(Main_OFILES)" + @echo " EXEFILE : $(EXEFILE)" + @echo + +end: + @echo + @echo "*** Makefile ended successfully ***" + @echo + +##################################################################### + +$(EXEFILE): $(OFILES) $(Main_OFILES) + @echo Linking ... + @$(CXX) $(LDFLAGS) $(OFILES) $@.o -o $@ $(LIBS) +ifndef CYGWIN +ifndef MINGW + @chmod 755 $@ +endif +endif + @echo File $@ has been created + +##################################################################### + +.cpp.o: + @echo Compiling $< -\> $@ + @$(CXX) $(CXXFLAGS) $(INCS) -c $< -o $@ + +##################################################################### + +debug: debug_ +debug_: + @make "CXXFLAGS = $(CXXFLAGS) -D__DEBUG__" + @echo + +clean: clean_ +clean_: + @echo + @echo Removing obejcts files, executable files and eventually core file... + @rm -f $(OFILES) $(Main_OFILES) $(EXEFILE) core + @echo + +realclean: clean + @echo Removing backup files... + @rm -f *~ *.bak + @echo + +depend: dep +dep: + @echo + @echo Make dependencies... + @makedepend -- $(CXXFLAGS) -- $(Main_CCFILES) $(CCFILES) 2> /dev/null + @rm -f Makefile.bak + @echo + +BAKFILE = ../SRB2MasterServer +backup: bak +bak: clean + @echo Copy files to $(BAKFILE).tgz... + @tar cvf $(BAKFILE).tar * > /dev/null + @gzip $(BAKFILE).tar + @mv $(BAKFILE).tar.gz $(BAKFILE).tgz + @echo Removing backup files... + @rm -f *~ *.bak + @echo + +#mrproper: dep clean default +mrproper: clean default + +install: mrproper + @echo "Launching the server, port $(PORT)..." + @./server $(PORT) + @echo diff --git a/tools/masterserver/Master.dsp b/tools/masterserver/Master.dsp new file mode 100644 index 000000000..6bb0c13ed --- /dev/null +++ b/tools/masterserver/Master.dsp @@ -0,0 +1,230 @@ +# Microsoft Developer Studio Project File - Name="MasterServer" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=MasterServer - Win32 Client Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "Master.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "Master.mak" CFG="MasterServer - Win32 Client Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "MasterServer - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "MasterServer - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE "MasterServer - Win32 Client Debug" (based on "Win32 (x86) Console Application") +!MESSAGE "MasterServer - Win32 Client Release" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "MasterServer - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "../../bin/VC/Release/MasterServer" +# PROP Intermediate_Dir "../../objs/VC/Release/MasterServer" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /W4 /GX /O2 /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__STDC__" /D "_POSIX_" /FR /YX /FD /c +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 kernel32.lib wsock32.lib /nologo /subsystem:console /machine:I386 /out:"../../bin/VC/Release/MasterServer.exe" + +!ELSEIF "$(CFG)" == "MasterServer - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "../../bin/VC/Debug/MasterServer" +# PROP Intermediate_Dir "../../objs/VC/Debug/MasterServer" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c +# ADD CPP /nologo /W4 /Gm /GX /ZI /Od /D "_DEBUG" /D "_WIN32" /D "__DEBUG__" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__STDC__" /D "_POSIX_" /FR /YX /FD /GZ /c +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib wsock32.lib /nologo /subsystem:console /debug /machine:I386 /out:"../../bin/VC/Debug/MasterServer.exe" /pdbtype:sept + +!ELSEIF "$(CFG)" == "MasterServer - Win32 Client Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "MasterServer___Win32_Client_Debug" +# PROP BASE Intermediate_Dir "MasterServer___Win32_Client_Debug" +# PROP BASE Ignore_Export_Lib 0 +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "../../bin/VC/Debug/MasterClient" +# PROP Intermediate_Dir "../../objs/VC/Debug/MasterClient" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W4 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "_WIN32" /D "__STDC__" /YX /FD /GZ /c +# ADD CPP /nologo /W4 /Gm /GX /ZI /Od /D "_DEBUG" /D "_WIN32" /D "__DEBUG__" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__STDC__" /D "_POSIX_" /FR /YX /FD /GZ /c +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib wsock32.lib /nologo /subsystem:console /debug /machine:I386 /out:"../../bin/VC/Debug/MasterServer.exe" /pdbtype:sept +# ADD LINK32 kernel32.lib wsock32.lib /nologo /subsystem:console /debug /machine:I386 /out:"../../bin/VC/Debug/MasterClient.exe" /pdbtype:sept + +!ELSEIF "$(CFG)" == "MasterServer - Win32 Client Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "MasterServer___Win32_Client_Release" +# PROP BASE Intermediate_Dir "MasterServer___Win32_Client_Release" +# PROP BASE Ignore_Export_Lib 0 +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "../../bin/VC/Release/MasterClient" +# PROP Intermediate_Dir "../../objs/VC/Release/MasterClient" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W4 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /W4 /GX /O2 /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__STDC__" /D "_POSIX_" /FR /YX /FD /c +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib wsock32.lib /nologo /subsystem:console /machine:I386 /out:"../../bin/VC/Release/MasterServer.exe" +# ADD LINK32 kernel32.lib wsock32.lib /nologo /subsystem:console /machine:I386 /out:"../../bin/VC/Release/MasterClient.exe" + +!ENDIF + +# Begin Target + +# Name "MasterServer - Win32 Release" +# Name "MasterServer - Win32 Debug" +# Name "MasterServer - Win32 Client Debug" +# Name "MasterServer - Win32 Client Release" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\client.cpp + +!IF "$(CFG)" == "MasterServer - Win32 Release" + +# PROP Exclude_From_Build 1 + +!ELSEIF "$(CFG)" == "MasterServer - Win32 Debug" + +# PROP Exclude_From_Build 1 + +!ELSEIF "$(CFG)" == "MasterServer - Win32 Client Debug" + +# PROP BASE Exclude_From_Build 1 + +!ELSEIF "$(CFG)" == "MasterServer - Win32 Client Release" + +# PROP BASE Exclude_From_Build 1 + +!ENDIF + +# End Source File +# Begin Source File + +SOURCE=.\common.cpp +# End Source File +# Begin Source File + +SOURCE=.\crypt.cpp +# End Source File +# Begin Source File + +SOURCE=.\ipcs.cpp +# End Source File +# Begin Source File + +SOURCE=.\server.cpp + +!IF "$(CFG)" == "MasterServer - Win32 Release" + +!ELSEIF "$(CFG)" == "MasterServer - Win32 Debug" + +!ELSEIF "$(CFG)" == "MasterServer - Win32 Client Debug" + +# PROP Exclude_From_Build 1 + +!ELSEIF "$(CFG)" == "MasterServer - Win32 Client Release" + +# PROP Exclude_From_Build 1 + +!ENDIF + +# End Source File +# Begin Source File + +SOURCE=.\srvlist.cpp +# End Source File +# Begin Source File + +SOURCE=.\stats.cpp +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# Begin Source File + +SOURCE=.\common.h +# End Source File +# Begin Source File + +SOURCE=.\ipcs.h +# End Source File +# Begin Source File + +SOURCE=.\srvlist.h +# End Source File +# Begin Source File + +SOURCE=.\stats.h +# End Source File +# End Group +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# End Group +# End Target +# End Project diff --git a/tools/masterserver/Master.sln b/tools/masterserver/Master.sln new file mode 100644 index 000000000..129814c76 --- /dev/null +++ b/tools/masterserver/Master.sln @@ -0,0 +1,38 @@ + +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual C++ Express 2008 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MasterServer", "Master.vcproj", "{6AEBAD84-BCB1-4302-A453-7AAD1DF006DA}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Client Debug|Win32 = Client Debug|Win32 + Client Debug|x64 = Client Debug|x64 + Client Release|Win32 = Client Release|Win32 + Client Release|x64 = Client Release|x64 + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {6AEBAD84-BCB1-4302-A453-7AAD1DF006DA}.Client Debug|Win32.ActiveCfg = Client Debug|Win32 + {6AEBAD84-BCB1-4302-A453-7AAD1DF006DA}.Client Debug|Win32.Build.0 = Client Debug|Win32 + {6AEBAD84-BCB1-4302-A453-7AAD1DF006DA}.Client Debug|x64.ActiveCfg = Client Debug|x64 + {6AEBAD84-BCB1-4302-A453-7AAD1DF006DA}.Client Debug|x64.Build.0 = Client Debug|x64 + {6AEBAD84-BCB1-4302-A453-7AAD1DF006DA}.Client Release|Win32.ActiveCfg = Client Release|Win32 + {6AEBAD84-BCB1-4302-A453-7AAD1DF006DA}.Client Release|Win32.Build.0 = Client Release|Win32 + {6AEBAD84-BCB1-4302-A453-7AAD1DF006DA}.Client Release|x64.ActiveCfg = Client Release|x64 + {6AEBAD84-BCB1-4302-A453-7AAD1DF006DA}.Client Release|x64.Build.0 = Client Release|x64 + {6AEBAD84-BCB1-4302-A453-7AAD1DF006DA}.Debug|Win32.ActiveCfg = Debug|Win32 + {6AEBAD84-BCB1-4302-A453-7AAD1DF006DA}.Debug|Win32.Build.0 = Debug|Win32 + {6AEBAD84-BCB1-4302-A453-7AAD1DF006DA}.Debug|x64.ActiveCfg = Debug|x64 + {6AEBAD84-BCB1-4302-A453-7AAD1DF006DA}.Debug|x64.Build.0 = Debug|x64 + {6AEBAD84-BCB1-4302-A453-7AAD1DF006DA}.Release|Win32.ActiveCfg = Release|Win32 + {6AEBAD84-BCB1-4302-A453-7AAD1DF006DA}.Release|Win32.Build.0 = Release|Win32 + {6AEBAD84-BCB1-4302-A453-7AAD1DF006DA}.Release|x64.ActiveCfg = Release|x64 + {6AEBAD84-BCB1-4302-A453-7AAD1DF006DA}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/tools/masterserver/Master.vcproj b/tools/masterserver/Master.vcproj new file mode 100644 index 000000000..364094dd4 --- /dev/null +++ b/tools/masterserver/Master.vcproj @@ -0,0 +1,1063 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tools/masterserver/MasterClient.dev b/tools/masterserver/MasterClient.dev new file mode 100644 index 000000000..035bb0bff --- /dev/null +++ b/tools/masterserver/MasterClient.dev @@ -0,0 +1,159 @@ +[Project] +FileName=MasterClient.dev +Name=MasterClient +UnitCount=7 +Type=1 +Ver=1 +ObjFiles= +Includes= +Libs= +PrivateResource= +ResourceIncludes= +MakeIncludes= +Compiler=-Wall_@@_ +CppCompiler=-Wall_@@_ +Linker=-lwsock32_@@_ +IsCpp=1 +Icon= +ExeOutput=..\..\bin +ObjectOutput=..\..\objs\MasterClient +OverrideOutput=0 +OverrideOutputName=MasterServer.exe +HostApplication= +Folders=Client,Common +CommandLine= +UseCustomMakefile=0 +CustomMakefile= +IncludeVersionInfo=0 +SupportXPThemes=0 +CompilerSet=0 +CompilerSettings=0000000010001001001010 + +[Unit1] +FileName=common.cpp +CompileCpp=1 +Folder=Common +Compile=1 +Link=1 +Priority=1 +OverrideBuildCmd=0 +BuildCmd= + +[Unit2] +FileName=ipcs.cpp +CompileCpp=1 +Folder=Common +Compile=1 +Link=1 +Priority=2 +OverrideBuildCmd=0 +BuildCmd= + +[Unit7] +FileName=Makefile +CompileCpp=1 +Folder= +Compile=0 +Link=0 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit8] +FileName=stats.h +Folder=Server +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= +CompileCpp=1 + +[Unit9] +FileName=common.h +CompileCpp=1 +Folder=Common +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit11] +FileName=Makefile +CompileCpp=1 +Folder= +Compile=0 +Link=0 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit12] +FileName=srvlist.h +CompileCpp=1 +Folder=Server +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[VersionInfo] +Major=0 +Minor=1 +Release=1 +Build=1 +LanguageID=1033 +CharsetID=1252 +CompanyName= +FileVersion= +FileDescription=Developed using the Dev-C++ IDE +InternalName= +LegalCopyright= +LegalTrademarks= +OriginalFilename= +ProductName= +ProductVersion= +AutoIncBuildNr=0 + +[Unit3] +FileName=crypt.cpp +CompileCpp=1 +Folder=Common +Compile=1 +Link=1 +Priority=4 +OverrideBuildCmd=0 +BuildCmd= + +[Unit4] +FileName=client.cpp +CompileCpp=1 +Folder=Client +Compile=1 +Link=1 +Priority=7 +OverrideBuildCmd=0 +BuildCmd=$(CPP) -c client.cpp -o ../../../objs/MasterServer/client.o $(CXXFLAGS) + +[Unit5] +FileName=common.h +CompileCpp=1 +Folder=Common +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit6] +FileName=ipcs.h +CompileCpp=1 +Folder=Common +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + diff --git a/tools/masterserver/MasterServer.dev b/tools/masterserver/MasterServer.dev new file mode 100644 index 000000000..bc089ccd5 --- /dev/null +++ b/tools/masterserver/MasterServer.dev @@ -0,0 +1,169 @@ +[Project] +FileName=MasterServer.dev +Name=MasterServer +UnitCount=11 +Type=1 +Ver=1 +ObjFiles= +Includes= +Libs= +PrivateResource= +ResourceIncludes= +MakeIncludes= +Compiler=-Wall_@@_-DDEBUG_@@_ +CppCompiler=-Wall_@@_-DDEBUG_@@_ +Linker=-lwsock32_@@_-lmysql_@@_ +IsCpp=1 +Icon= +ExeOutput=..\..\bin +ObjectOutput=..\..\objs\MasterServer +OverrideOutput=0 +OverrideOutputName=MasterServer.exe +HostApplication= +Folders=Common,Server +CommandLine=28900 +UseCustomMakefile=0 +CustomMakefile= +IncludeVersionInfo=0 +SupportXPThemes=0 +CompilerSet=0 +CompilerSettings=0000000011001001001010 + +[Unit1] +FileName=common.cpp +CompileCpp=1 +Folder=Common +Compile=1 +Link=1 +Priority=1 +OverrideBuildCmd=0 +BuildCmd= + +[Unit2] +FileName=ipcs.cpp +CompileCpp=1 +Folder=Common +Compile=1 +Link=1 +Priority=2 +OverrideBuildCmd=0 +BuildCmd= + +[Unit3] +FileName=srvlist.cpp +CompileCpp=1 +Folder=Server +Compile=1 +Link=1 +Priority=3 +OverrideBuildCmd=0 +BuildCmd= + +[Unit4] +FileName=crypt.cpp +CompileCpp=1 +Folder=Common +Compile=1 +Link=1 +Priority=4 +OverrideBuildCmd=0 +BuildCmd= + +[Unit5] +FileName=stats.cpp +CompileCpp=1 +Folder=Server +Compile=1 +Link=1 +Priority=5 +OverrideBuildCmd=0 +BuildCmd= + +[Unit6] +FileName=server.cpp +CompileCpp=1 +Folder=Server +Compile=1 +Link=1 +Priority=6 +OverrideBuildCmd=0 +BuildCmd= + +[Unit8] +FileName=common.h +Folder=Common +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= +CompileCpp=1 + +[Unit9] +FileName=ipcs.h +CompileCpp=1 +Folder=Common +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit10] +FileName=Makefile +CompileCpp=1 +Folder= +Compile=0 +Link=0 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit11] +FileName=srvlist.h +CompileCpp=1 +Folder=Server +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[VersionInfo] +Major=0 +Minor=1 +Release=1 +Build=1 +LanguageID=1033 +CharsetID=1252 +CompanyName= +FileVersion= +FileDescription=Developed using the Dev-C++ IDE +InternalName= +LegalCopyright= +LegalTrademarks= +OriginalFilename= +ProductName= +ProductVersion= +AutoIncBuildNr=0 + +[Unit7] +FileName=stats.h +CompileCpp=1 +Folder=Server +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit13] +FileName=LIVE_MySQL.h +CompileCpp=1 +Folder=Server +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + diff --git a/tools/masterserver/client.cpp b/tools/masterserver/client.cpp new file mode 100644 index 000000000..8eba3f1a2 --- /dev/null +++ b/tools/masterserver/client.cpp @@ -0,0 +1,133 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright (C) 2000 by DooM Legacy Team. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +//----------------------------------------------------------------------------- + +#include +#include +#include "ipcs.h" +#include "common.h" + +//============================================================================= + +static CClientSocket client_socket; +//static msg_t msg; +FILE *logfile; + +//============================================================================= + +static msg_t *getData(int argc, char *argv[]) +{ + static msg_t msg; + msg_server_t *info = (msg_server_t *)msg.buffer; + +#if defined (_WIN32) + strcpy(info->header.buffer, ""); +#else + strcpy(info->header.buffer, getpass("Enter password: ")); +#endif + + // default values if one of the param is not entered + strcpy(info->ip, "88.86.106.169"); + strcpy(info->port, "5029"); + strcpy(info->name, "Cueball's Dedicated Server"); + strcpy(info->version, "1.09.4"); + msg.type = ADD_PSERVER_MSG; + msg.length = sizeof (msg_server_t); + + for (int i = 0; i < argc; i++) + { + // first: extra parameters (must be after all -param) + if (!strcasecmp(argv[i], "get")) + { + msg.type = GET_SERVER_MSG; + msg.length = 0; + } + else if (!strcasecmp(argv[i], "log")) + { + msg.type = GET_LOGFILE_MSG; + msg.length = sizeof (msg_server_t); + } + else if (!strcasecmp(argv[i], "erase")) + { + msg.type = ERASE_LOGFILE_MSG; + msg.length = sizeof (msg_server_t); + } + else if (!strcasecmp(argv[i], "remove")) + { + msg.type = REMOVE_PSERVER_MSG; + msg.length = sizeof (msg_server_t); + } + + if (i >= argc-1) + continue; + + // second: parameter requiring extra parameters + if (strcasecmp(argv[i], "-ip") == 0) + strcpy(info->ip, argv[i+1]); + else if (strcasecmp(argv[i], "-port") == 0) + strcpy(info->port, argv[i+1]); + else if (strcasecmp(argv[i], "-hostname") == 0) + strcpy(info->name, argv[i+1]); + else if (strcasecmp(argv[i], "-version") == 0) + strcpy(info->version, argv[i+1]); + else if (strcasecmp(argv[i], "-pass") == 0) + strcpy(info->header.buffer, argv[i+1]); + } + return &msg; +} + +int main(int argc, char *argv[]) +{ + if (argc == 2) + { + printf("encrypt: %s\n", pCrypt(argv[1], "04")); + return 0; + } + else if (argc > 2) + { + if (client_socket.connect(argv[1], argv[2]) < 0) + { + conPrintf(RED, "Connect failed.\n"); + return -1; + } + + msg_t *msg = getData(argc, argv); + + if (client_socket.write(msg) < 0) + { + dbgPrintf(RED, "Write failed.\n"); + return -1; + } + + switch (ntohl(msg->type)) + { + case GET_SERVER_MSG: + case GET_LOGFILE_MSG: + while (client_socket.read(msg) >= 0) + { + if (ntohl(msg->length) == 0) + break; + printf("%s", msg->buffer); + } + break; + + case REMOVE_PSERVER_MSG: + default: + break; + } + } + return 0; +} diff --git a/tools/masterserver/common.cpp b/tools/masterserver/common.cpp new file mode 100644 index 000000000..b9795bd0f --- /dev/null +++ b/tools/masterserver/common.cpp @@ -0,0 +1,207 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright (C) 2000 by DooM Legacy Team. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +//----------------------------------------------------------------------------- + +#include +#include +#include +#include "common.h" + +// ================================== GLOBALS ================================= + +static const char *fatal_error_msg[NUM_FATAL_ERROR] = +{ + "Error: signal()", + "Error: select()", + "Error: read()", + "Error: write()", +}; + +// used by xxxPrintf() functions as temporary variable +static char str[1024] =""; +static va_list arglist; +#ifdef _WIN32 +static size_t len = 0; +static HANDLE co = INVALID_HANDLE_VALUE; +static DWORD bytesWritten = 0; +static CONSOLE_SCREEN_BUFFER_INFO ConsoleScreenBufferInfo; +#endif + +// ================================= FUNCTIONS ================================ + +/* + * clearScreen(): + */ +void clearScreen() +{ +#ifdef _WIN32 +#else + printf("\033[0m \033[2J \033[0;0H"); +#endif +} + +/* + * fatalError(): + */ +void fatalError(fatal_error_t num) +{ + clearScreen(); + printf("\n"); + perror(fatal_error_msg[num]); + printf("\n"); + exit(-1); +} + + +/* + * dbgPrintf(): + */ +#ifdef _WIN32 +void dbgPrintf(DWORDLONG col, const char *lpFmt, ...) +#else +void dbgPrintf(const char *col, const char *lpFmt, ...) +#endif +{ +#if defined (__DEBUG__) + va_start(arglist, lpFmt); + vsnprintf(str, sizeof str, lpFmt, arglist); + va_end(arglist); + +#ifdef _WIN32 + len = strlen(str); + co = GetStdHandle(STD_OUTPUT_HANDLE); + + if (co == INVALID_HANDLE_VALUE) + return; + + if (col == DEFCOL) + { + if (!GetConsoleScreenBufferInfo(co, &ConsoleScreenBufferInfo)) + ConsoleScreenBufferInfo.wAttributes = + FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE; + + SetConsoleTextAttribute(co, (WORD)col); + } + + if (GetFileType(co) == FILE_TYPE_CHAR) + WriteConsoleA(co, str, (DWORD)len, &bytesWritten, NULL); + else + WriteFile(co, str, (DWORD)len, &bytesWritten, NULL); + + if (col != DEFCOL) + SetConsoleTextAttribute(co, + ConsoleScreenBufferInfo.wAttributes); +#else + printf("%s%s", col, str); + fflush(stdout); +#endif +#else + (void)col; + (void)lpFmt; +#endif +} + +/* + * conPrintf() + */ +#ifdef _WIN32 +void conPrintf(DWORDLONG col, const char *lpFmt, ...) +#else +void conPrintf(const char *col, const char *lpFmt, ...) +#endif +{ + va_start(arglist, lpFmt); + vsnprintf(str, sizeof str, lpFmt, arglist); + va_end(arglist); + +#ifdef _WIN32 + len = strlen(str); + co = GetStdHandle(STD_OUTPUT_HANDLE); + + if (col == DEFCOL) + { + if (!GetConsoleScreenBufferInfo(co, &ConsoleScreenBufferInfo)) + ConsoleScreenBufferInfo.wAttributes = + FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE; + + SetConsoleTextAttribute(co, (WORD)col); + } + + if (co == INVALID_HANDLE_VALUE) + return; + + if (GetFileType(co) == FILE_TYPE_CHAR) + WriteConsoleA(co, str, (DWORD)len, &bytesWritten, NULL); + else + WriteFile(co, str, (DWORD)len, &bytesWritten, NULL); + + if (col != DEFCOL) + SetConsoleTextAttribute(co, + ConsoleScreenBufferInfo.wAttributes); +#else + printf("%s%s", col, str); + fflush(stdout); +#endif +} + +/* + * logPrintf(): + */ +void logPrintf(FILE *f, const char *lpFmt, ...) +{ + char *ct; + time_t t; + + va_start(arglist, lpFmt); + vsnprintf(str, sizeof str, lpFmt, arglist); + va_end(arglist); + + t = time(NULL); + ct = ctime(&t); + ct[strlen(ct)-1] = '\0'; + fprintf(f, "%s: %s", ct, str); + fflush(f); +#if defined (__DEBUG__) +#ifdef _WIN32 + len = strlen(str); + printf("%s", str); +#else + printf("%s%s", DEFCOL, str); +#endif + fflush(stdout); +#endif +} + +/* + * openFile(): + */ +FILE *openFile(const char *filename) +{ + return fopen(filename, "a+t"); +} + +void strrand(char *s, const int len) { + static const char alphanum[] = + "0123456789" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz"; + + for (int i = 0; i < len; ++i) { + s[i] = alphanum[rand() % (sizeof(alphanum) - 1)]; + } + + s[len] = 0; +} diff --git a/tools/masterserver/common.h b/tools/masterserver/common.h new file mode 100644 index 000000000..cb935572d --- /dev/null +++ b/tools/masterserver/common.h @@ -0,0 +1,151 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright (C) 2000 by DooM Legacy Team. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +//----------------------------------------------------------------------------- + +#ifndef _COMMON_H_ +#define _COMMON_H_ + +#ifdef __GNUC__ +#include +#include + +#define UINT8 uint8_t +#define SINT8 int8_t + +#define UINT16 uint16_t +#define INT16 int16_t + +#define INT32 int32_t +#define UINT32 uint32_t +#define INT64 int64_t +#define UINT64 uint64_t +#define ATTRPACK __attribute__ ((packed)) +#elif defined ( _MSC_VER) +#include +#define UINT8 unsigned __int8 +#define SINT8 signed __int8 + +#define UINT16 unsigned __int16 +#define INT16 __int16 + +#define INT32 __int32 +#define UINT32 unsigned __int32 + +#define INT64 __int64 +#define UINT64 unsigned __int64 + +typedef long ssize_t; +#endif + +#ifndef ATTRPACK +#define ATTRPACK +#endif + +#include +#include +#include +#include + +#if defined (_WIN32) || defined (__OS2__) +#ifdef __GNUC__ +#define strcasecmp stricmp +#elif defined (_MSC_VER) +#define snprintf _snprintf +#define vsnprintf _vsnprintf +#define strcasecmp _stricmp +#pragma warning(disable : 4244) +#endif +#endif + +// ================================ DEFINITIONS =============================== + + +#ifdef _WIN32 +#ifdef __GNUC__ +#include +#include +#include +#include +#endif +#define DEFCOL 0xD0E0F0C0 // codes couleurs ANSI +#define BLACK 0 +#define RED FOREGROUND_RED +#define GREEN FOREGROUND_GREEN +#define BROWN FOREGROUND_GREEN|FOREGROUND_RED +#define BLUE FOREGROUND_BLUE +#define PURPLE FOREGROUND_RED|FOREGROUND_BLUE +#define CYAN FOREGROUND_BLUE|FOREGROUND_GREEN +#define LIGHTGRAY FOREGROUND_BLUE|FOREGROUND_GREEN|FOREGROUND_RED +#define DARKGRAY FOREGROUND_INTENSITY +#define LIGHTRED FOREGROUND_RED|FOREGROUND_INTENSITY +#define LIGHTGREEN FOREGROUND_GREEN|FOREGROUND_INTENSITY +#define YELLOW FOREGROUND_GREEN|FOREGROUND_RED|FOREGROUND_INTENSITY +#define LIGHTBLUE FOREGROUND_BLUE|FOREGROUND_INTENSITY +#define MAGENTA FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_INTENSITY +#define LIGHTCYAN FOREGROUND_BLUE|FOREGROUND_GREEN|FOREGROUND_INTENSITY +#define WHITE FOREGROUND_BLUE|FOREGROUND_GREEN|FOREGROUND_RED|FOREGROUND_INTENSITY + +#else + +#define DEFCOL "\033[0m" // codes couleurs ANSI +#define BLACK "\033[0;30m" +#define RED "\033[0;31m" +#define GREEN "\033[0;32m" +#define BROWN "\033[0;33m" +#define BLUE "\033[0;34m" +#define PURPLE "\033[0;35m" +#define CYAN "\033[0;36m" +#define LIGHTGRAY "\033[0;37m" +#define DARKGRAY "\033[1;30m" +#define LIGHTRED "\033[1;31m" +#define LIGHTGREEN "\033[1;32m" +#define YELLOW "\033[1;33m" +#define LIGHTBLUE "\033[1;34m" +#define MAGENTA "\033[1;35m" +#define LIGHTCYAN "\033[1;36m" +#define WHITE "\033[1;37m" + +#endif + +typedef enum +{ + FE_SIGNAL_ERR, + FE_SELECT_ERR, + FE_READ_ERR, + FE_WRITE_ERR, + NUM_FATAL_ERROR +} fatal_error_t; + +// ================================== PROTOS ================================== + +void clearScreen(); +void fatalError(fatal_error_t); +void logPrintf(FILE *, const char *, ...); +#ifdef _WIN32 +void dbgPrintf(DWORDLONG col, const char *lpFmt, ...); +void conPrintf(DWORDLONG col, const char *lpFmt, ...); +#else +void dbgPrintf(const char *col, const char *lpFmt, ...); +void conPrintf(const char *col, const char *lpFmt, ...); +#endif +FILE *openFile(const char *filename); +const char *pCrypt(const char *pw, const char *salt); + +// ================================== STRINGS ================================= +void strrand(char *s, const int len); + +// ================================== EXTERNS ================================= +#endif diff --git a/tools/masterserver/crypt.cpp b/tools/masterserver/crypt.cpp new file mode 100644 index 000000000..4f15d3c89 --- /dev/null +++ b/tools/masterserver/crypt.cpp @@ -0,0 +1,278 @@ +#include "common.h" + +static SINT8 IP[] = +{ + 58,50,42,34,26,18,10, 2, + 60,52,44,36,28,20,12, 4, + 62,54,46,38,30,22,14, 6, + 64,56,48,40,32,24,16, 8, + 57,49,41,33,25,17, 9, 1, + 59,51,43,35,27,19,11, 3, + 61,53,45,37,29,21,13, 5, + 63,55,47,39,31,23,15, 7, +}; +static SINT8 FP[] = +{ + 40, 8,48,16,56,24,64,32, + 39, 7,47,15,55,23,63,31, + 38, 6,46,14,54,22,62,30, + 37, 5,45,13,53,21,61,29, + 36, 4,44,12,52,20,60,28, + 35, 3,43,11,51,19,59,27, + 34, 2,42,10,50,18,58,26, + 33, 1,41, 9,49,17,57,25, +}; +static SINT8 PC1_C[] = +{ + 57,49,41,33,25,17, 9, + 1,58,50,42,34,26,18, + 10, 2,59,51,43,35,27, + 19,11, 3,60,52,44,36, +}; +static SINT8 PC1_D[] = +{ + 63,55,47,39,31,23,15, + 7,62,54,46,38,30,22, + 14, 6,61,53,45,37,29, + 21,13, 5,28,20,12, 4, +}; +static SINT8 shifts[] = {1,1,2,2,2,2,2,2,1,2,2,2,2,2,2,1}; +static SINT8 PC2_C[] = +{ + 14,17,11,24, 1, 5, + 3,28,15, 6,21,10, + 23,19,12, 4,26, 8, + 16, 7,27,20,13, 2, +}; +static SINT8 PC2_D[] = +{ + 41,52,31,37,47,55, + 30,40,51,45,33,48, + 44,49,39,56,34,53, + 46,42,50,36,29,32, +}; +static SINT8 C[28]; +static SINT8 D[28]; +static SINT8 KS[16][48]; +static SINT8 E[48]; +static SINT8 e2[] = +{ + 32, 1, 2, 3, 4, 5, + 4, 5, 6, 7, 8, 9, + 8, 9,10,11,12,13, + 12,13,14,15,16,17, + 16,17,18,19,20,21, + 20,21,22,23,24,25, + 24,25,26,27,28,29, + 28,29,30,31,32, 1, +}; +static SINT8 S[8][64] = +{ + { + 14, 4,13, 1, 2,15,11, 8, 3,10, 6,12, 5, 9, 0, 7, + 0,15, 7, 4,14, 2,13, 1,10, 6,12,11, 9, 5, 3, 8, + 4, 1,14, 8,13, 6, 2,11,15,12, 9, 7, 3,10, 5, 0, + 15,12, 8, 2, 4, 9, 1, 7, 5,11, 3,14,10, 0, 6,13, + }, + { + 15, 1, 8,14, 6,11, 3, 4, 9, 7, 2,13,12, 0, 5,10, + 3,13, 4, 7,15, 2, 8,14,12, 0, 1,10, 6, 9,11, 5, + 0,14, 7,11,10, 4,13, 1, 5, 8,12, 6, 9, 3, 2,15, + 13, 8,10, 1, 3,15, 4, 2,11, 6, 7,12, 0, 5,14, 9, + }, + { + 10, 0, 9,14, 6, 3,15, 5, 1,13,12, 7,11, 4, 2, 8, + 13, 7, 0, 9, 3, 4, 6,10, 2, 8, 5,14,12,11,15, 1, + 13, 6, 4, 9, 8,15, 3, 0,11, 1, 2,12, 5,10,14, 7, + 1,10,13, 0, 6, 9, 8, 7, 4,15,14, 3,11, 5, 2,12, + }, + { + 7,13,14, 3, 0, 6, 9,10, 1, 2, 8, 5,11,12, 4,15, + 13, 8,11, 5, 6,15, 0, 3, 4, 7, 2,12, 1,10,14, 9, + 10, 6, 9, 0,12,11, 7,13,15, 1, 3,14, 5, 2, 8, 4, + 3,15, 0, 6,10, 1,13, 8, 9, 4, 5,11,12, 7, 2,14, + }, + { + 2,12, 4, 1, 7,10,11, 6, 8, 5, 3,15,13, 0,14, 9, + 14,11, 2,12, 4, 7,13, 1, 5, 0,15,10, 3, 9, 8, 6, + 4, 2, 1,11,10,13, 7, 8,15, 9,12, 5, 6, 3, 0,14, + 11, 8,12, 7, 1,14, 2,13, 6,15, 0, 9,10, 4, 5, 3, + }, + { + 12, 1,10,15, 9, 2, 6, 8, 0,13, 3, 4,14, 7, 5,11, + 10,15, 4, 2, 7,12, 9, 5, 6, 1,13,14, 0,11, 3, 8, + 9,14,15, 5, 2, 8,12, 3, 7, 0, 4,10, 1,13,11, 6, + 4, 3, 2,12, 9, 5,15,10,11,14, 1, 7, 6, 0, 8,13, + }, + { + 4,11, 2,14,15, 0, 8,13, 3,12, 9, 7, 5,10, 6, 1, + 13, 0,11, 7, 4, 9, 1,10,14, 3, 5,12, 2,15, 8, 6, + 1, 4,11,13,12, 3, 7,14,10,15, 6, 8, 0, 5, 9, 2, + 6,11,13, 8, 1, 4,10, 7, 9, 5, 0,15,14, 2, 3,12, + }, + { + 13, 2, 8, 4, 6,15,11, 1,10, 9, 3,14, 5, 0,12, 7, + 1,15,13, 8,10, 3, 7, 4,12, 5, 6,11, 0,14, 9, 2, + 7,11, 4, 1, 9,12,14, 2, 0, 6,10,13,15, 3, 5, 8, + 2, 1,14, 7, 4,10, 8,13,15,12, 9, 0, 3, 5, 6,11, + } +}; +static SINT8 P[] = +{ + 16, 7,20,21, + 29,12,28,17, + 1,15,23,26, + 5,18,31,10, + 2, 8,24,14, + 32,27, 3, 9, + 19,13,30, 6, + 22,11, 4,25, +}; +static SINT8 L[64], *R = L + 32; +static SINT8 tempL[32]; +static SINT8 f[32]; +static SINT8 preS[48]; + +//======================================================================= + +static void setKey(const SINT8 *key) +{ + register INT32 i, j, k; + INT32 t; + + for (i = 0; i < 28; i++) + { + C[i] = key[PC1_C[i]-1]; + D[i] = key[PC1_D[i]-1]; + } + for (i = 0; i < 16; i++) + { + for (k = 0; k < shifts[i]; k++) + { + t = C[0]; + for (j = 0; j < 28-1; j++) + C[j] = C[j+1]; + C[27] = t; + t = D[0]; + for (j = 0; j < 28-1; j++) + D[j] = D[j+1]; + D[27] = t; + } + for (j = 0; j < 24; j++) + { + KS[i][j] = C[PC2_C[j]-1]; + KS[i][j+24] = D[PC2_D[j]-28-1]; + } + } + for (i = 0; i < 48; i++) + E[i] = e2[i]; +} + +void enCrypt(SINT8 *block) +{ + INT32 i, ii; + register INT32 t, j, k; + + for (j = 0; j < 64; j++) + L[j] = block[IP[j]-1]; + for (ii = 0; ii < 16; ii++) + { + i = ii; + for (j = 0; j < 32; j++) + tempL[j] = R[j]; + for (j = 0; j < 48; j++) + preS[j] = R[E[j]-1] ^ KS[i][j]; + for (j = 0; j < 8; j++) + { + t = 6*j; + k = S[j][(preS[t+0]<<5)+ + (preS[t+1]<<3)+ + (preS[t+2]<<2)+ + (preS[t+3]<<1)+ + (preS[t+4]<<0)+ + (preS[t+5]<<4)]; + t = 4*j; + f[t+0] = (k>>3)&01; + f[t+1] = (k>>2)&01; + f[t+2] = (k>>1)&01; + f[t+3] = (k>>0)&01; + } + for (j = 0; j < 32; j++) + R[j] = L[j] ^ f[P[j]-1]; + for (j = 0; j < 32; j++) + L[j] = tempL[j]; + } + for (j = 0; j < 32; j++) + { + t = L[j]; + L[j] = R[j]; + R[j] = t; + } + for (j = 0; j < 64; j++) + block[j] = L[FP[j]-1]; +} + +const char *pCrypt(const char *pw, const char *salt) +{ + register INT32 i, j, c; + INT32 temp; + static SINT8 block[66]; + static char iobuf[16]; + + for (i = 0; i < 66; i++) + block[i] = 0; + for (i = 0; (c = *pw) != '\0' && i < 64; pw++) + { + for (j = 0; j < 7; j++, i++) + block[i] = (c>>(6-j)) & 01; + i++; + } + + setKey(block); + + for (i = 0; i < 66; i++) + block[i] = 0; + + for (i = 0; i < 2; i++) + { + c = *salt++; + iobuf[i] = c; + if (c > 'Z') + c -= 6; + if (c > '9') + c -= 7; + c -= '.'; + for (j = 0; j < 6; j++) + { + if ((c>>j) & 01) + { + temp = E[6*i+j]; + E[6*i+j] = E[6*i+j+24]; + E[6*i+j+24] = temp; + } + } + } + + for (i = 0; i < 25; i++) + enCrypt(block); + + for (i = 0; i < 11; i++) + { + c = 0; + for (j = 0; j < 6; j++) + { + c <<= 1; + c |= block[6*i+j]; + } + c += '.'; + if (c > '9') + c += 7; + if (c > 'Z') + c += 6; + iobuf[i+2] = c; + } + iobuf[i+2] = 0; + if (iobuf[1] == 0) + iobuf[1] = iobuf[0]; + return(iobuf); +} diff --git a/tools/masterserver/ipcs.cpp b/tools/masterserver/ipcs.cpp new file mode 100644 index 000000000..4c3c6de74 --- /dev/null +++ b/tools/masterserver/ipcs.cpp @@ -0,0 +1,595 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright (C) 2000 by DooM Legacy Team. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +//----------------------------------------------------------------------------- + +#ifdef __GNUC__ +#include +#endif + +#ifdef _WIN32 +//#include +#else +#include // socket(),... +#include // socket(),... +#endif +#include // atoi(),... +#include // signal(),... +#ifndef _WIN32 +#include // gethostbyname(),... +#endif +#ifdef _WIN32 +#include +#else +#include // timeval,... (TIMEOUT) +#endif +#include // memset(),... +#include "ipcs.h" +#include "common.h" + +typedef void Sigfunc(int); + +#ifndef _WIN32 +static void sigHandler(int signr); +static Sigfunc *mySignal(int signo, Sigfunc *func); +#endif + +#ifdef _MSC_VER +#pragma warning(disable : 4127) +#endif +//============================================================================= + +#if defined (_WIN32) || defined (__OS2__) +// it seems windows doesn't define that... maybe some other OS? OS/2 +static int inet_aton(const char *hostname, struct in_addr *addr) +{ + return ((addr->s_addr=inet_addr(hostname)) != INADDR_NONE); +} +#endif + +/* +** CSocket() +*/ +CSocket::CSocket() +{ + dbgPrintf(DEFCOL, "Initializing socket... "); +#ifdef _WIN32 +//#warning SIGPIPE needed + WSADATA winsockdata; + if (WSAStartup(MAKEWORD(1, 1), &winsockdata)) + conPrintf(RED,"No TCP/IP driver detected"); +#else + signal(SIGPIPE, sigHandler); +#endif + FD_ZERO(&rset); + memset(&addr, 0, sizeof (addr)); + addr.sin_family = AF_INET; + dbgPrintf(DEFCOL, "DONE1.\n"); +} + +/* +** ~CSocket() +*/ +CSocket::~CSocket() +{ + dbgPrintf(DEFCOL, "Freeing socket... "); +#ifdef _WIN32 + WSACleanup(); +#endif + dbgPrintf(DEFCOL, "DONE2.\n"); +} + +/* +** getIP() +*/ +int CSocket::getIP(const char *ip_addr) +{ + struct hostent *host_ent; + + dbgPrintf(DEFCOL, "get IP for %s... ", ip_addr); + if (!inet_aton(ip_addr, &addr.sin_addr)) + { + host_ent = gethostbyname(ip_addr); + if (host_ent == NULL) + return GETHOSTBYNAME_ERROR; + memcpy(&addr.sin_addr, host_ent->h_addr_list[0], + sizeof (struct in_addr)); + } + dbgPrintf(DEFCOL, "got %s. ", inet_ntoa(addr.sin_addr)); + dbgPrintf(DEFCOL, "DONE3.\n"); + return 0; +} + +/* +** CClientSocket() +*/ +CClientSocket::CClientSocket() +{ + dbgPrintf(DEFCOL, "Initializing client socket... "); + socket_fd = (SOCKET)-1; + dbgPrintf(DEFCOL, "DONE4.\n"); +} + +/* +** ~CClientSocket() +*/ +CClientSocket::~CClientSocket() +{ + dbgPrintf(DEFCOL, "Freeing client socket... "); + if (socket_fd != (SOCKET)-1) + close(socket_fd); + dbgPrintf(DEFCOL, "DONE5.\n"); +} + +/* +** connect() +*/ +int CClientSocket::connect(const char *ip_addr, const char *str_port) +{ + dbgPrintf(DEFCOL, "Connect to %s %s...\n", ip_addr, str_port); + + // put that in the constructor? + if ((socket_fd = socket(AF_INET, SOCK_STREAM, 0)) == (SOCKET)-1) + return SOCKET_ERROR; + + if (getIP(ip_addr) == GETHOSTBYNAME_ERROR) + return GETHOSTBYNAME_ERROR; + addr.sin_port = htons(atoi(str_port)); + + if (::connect(socket_fd, (struct sockaddr *) &addr, sizeof (addr)) < 0) + return CONNECT_ERROR; + + FD_SET(socket_fd, &rset); + + dbgPrintf(DEFCOL, "DONE6.\n"); + + return 0; +} + +/* + * write() + */ +int CClientSocket::write(msg_t *msg) +{ + int len; + + if (msg->length < 0) + msg->length = (INT32)strlen(msg->buffer); + if (msg->length > PACKET_SIZE) + return WRITE_ERROR; // too big + len = msg->length + HEADER_SIZE; + + msg->id = htonl(msg->id); + msg->type = htonl(msg->type); + msg->length = htonl(msg->length); + msg->room = htonl(msg->room); + + dbgPrintf(DEFCOL, "Write a message %d (%s)... ", len, msg->buffer); + + if (send(socket_fd, (const char *)msg, len, 0) != len) + return WRITE_ERROR; + + dbgPrintf(DEFCOL, "DONE7.\n"); + + return 0; +} + +/* + * read() + */ +int CClientSocket::read(msg_t *msg) +{ + struct timeval timeout; + fd_set tset; + + dbgPrintf(DEFCOL, "Waiting a message... "); + + timeout.tv_sec = 60, timeout.tv_usec = 0; + memcpy(&tset, &rset, sizeof (tset)); + if ((select(255, &tset, NULL, NULL, &timeout)) <= 0) + return TIMEOUT_ERROR; + + if (!FD_ISSET(socket_fd, &tset)) + return READ_ERROR; + + dbgPrintf(DEFCOL, "Reading a message.\n"); + + if (recv(socket_fd, (char *)msg, HEADER_SIZE, 0) != HEADER_SIZE) + return READ_ERROR; + + msg->id = ntohl(msg->id); + msg->type = ntohl(msg->type); + msg->length = ntohl(msg->length); + msg->room = ntohl(msg->room); + + if (!msg->length) // work around a bug in Windows 2000 + return 0; + + if (msg->length > PACKET_SIZE) + return READ_ERROR; // packet too big + + if (recv(socket_fd, msg->buffer, msg->length, 0) != msg->length) + return READ_ERROR; + + dbgPrintf(DEFCOL, "DONE8.\n"); + + return 0; +} + +/* +** CServerSocket() +*/ +CServerSocket::CServerSocket() +{ + size_t id; + dbgPrintf(DEFCOL, "Initializing server socket... "); + num_clients = 0; + accept_fd = udp_fd = (SOCKET)-1; + for (id = 0; id < MAX_CLIENT; id++) + client_fd[id] = (SOCKET)-1; + udp_addr.sin_family = AF_INET; + dbgPrintf(DEFCOL, "DONE9.\n"); +} + +/* +** ~CServerSocket() +*/ +CServerSocket::~CServerSocket() +{ + size_t id; + dbgPrintf(DEFCOL, "Freeing server socket... "); + if (udp_fd != (SOCKET)-1) + close(udp_fd); + if (accept_fd != (SOCKET)-1) + close(accept_fd); + for (id = 0; id < num_clients || id < MAX_CLIENT; id++) + if (client_fd[id] != (SOCKET)-1) + close(client_fd[id]); + dbgPrintf(DEFCOL, "DONE10.\n"); +} + +/* +** listen() +*/ +int CServerSocket::listen(const char *str_port) +{ + dbgPrintf(DEFCOL, "Listen on %s... ", str_port); + // Init TCP socket + if ((accept_fd = socket(AF_INET, SOCK_STREAM, 0)) == (SOCKET)-1) + return SOCKET_ERROR; + int one = 1; setsockopt(accept_fd, SOL_SOCKET, SO_REUSEADDR, (char*)&one, sizeof(int)); + + addr.sin_addr.s_addr = htonl(INADDR_ANY); + addr.sin_port = htons(atoi(str_port)); + + if (bind(accept_fd, (struct sockaddr *) &addr, sizeof (addr)) < 0) + return BIND_ERROR; + + if (::listen(accept_fd, 5) < 0) + return LISTEN_ERROR; + + FD_SET(accept_fd, &rset); + + // Init UDP socket + if ((udp_fd = socket(AF_INET, SOCK_DGRAM, 0)) == (SOCKET)-1) + return SOCKET_ERROR; + + udp_addr.sin_addr.s_addr = htonl(INADDR_ANY); + udp_addr.sin_port = htons(atoi(str_port)+1); + + if (bind(udp_fd, (struct sockaddr *) &udp_addr, sizeof (udp_addr)) < 0) + return BIND_ERROR; + + FD_SET(udp_fd, &rset); + + dbgPrintf(DEFCOL, "DONE11.\n"); + + return 0; +} + +/* + * deleteClient(): + */ +int CServerSocket::deleteClient(size_t id) +{ + dbgPrintf(DEFCOL, "Deleting (client %u) of %u... ", id+1, num_clients); + FD_CLR(client_fd[id], &rset); + close(client_fd[id]); + if (num_clients != 0) + num_clients--; + client_fd[id] = client_fd[num_clients]; // move the top socket into this now empty space + memmove(&client_addr[id], &client_addr[num_clients], sizeof (client_addr[num_clients])); + client_fd[num_clients] = (SOCKET)-1; // now empty the top socket + memset(&client_addr[num_clients], 0 , sizeof (client_addr[num_clients])); + + dbgPrintf(DEFCOL, "DONE12.\n"); + + return 0; +} + +/* + * getUdpIP() + */ +const char *CServerSocket::getUdpIP(void) +{ + return inet_ntoa(udp_in_addr.sin_addr); +} + +/* + * getUdpPort() + */ +const char *CServerSocket::getUdpPort(bool offset) +{ + static char buffer[8]; + UINT16 port = htons(udp_in_addr.sin_port); + if (offset) + port--; + snprintf(buffer, sizeof buffer, "%d", port); + return buffer; +} + +/* + * read(): wait message on a socket, if it's an accept, call the accept method, + * otherwise read the message and update msg->id to the right value + * (client cannot put valid entry in msg->id) + */ +int CServerSocket::read(msg_t *msg) +{ + struct timeval timeout; + fd_set tset; + UINT32 id; + socklen_t lg = sizeof (addr); + + timeout.tv_sec = 20, timeout.tv_usec = 0; + memcpy(&tset, &rset, sizeof (tset)); + if ((select(255, &tset, NULL, NULL, &timeout)) <= 0) + { + msg->type = TIMEOUT_MSG; + return TIMEOUT_ERROR; + } + + if (FD_ISSET(udp_fd, &tset)) + { + msg->type = UDP_RECV_MSG; // This is a UDP packet + msg->length = recvfrom(udp_fd, msg->buffer, PACKET_SIZE, 0, (struct sockaddr *)&udp_in_addr, &lg); + return 0; + } + + if (FD_ISSET(accept_fd, &tset)) + { + msg->type = ACCEPT_MSG; + return this->accept(); + } + + id = 0; + while (!FD_ISSET(client_fd[id], &tset) && id < MAX_CLIENT) + id++; + + // paranoia + if ( (id >= num_clients) || (id >= MAX_CLIENT) ) + { + dbgPrintf(DEFCOL, "This should never happen\n"); + return READ_ERROR; + } + + dbgPrintf(DEFCOL, "Reading a message from (socket %u) for (client %u)... ", client_fd[id], id+1); + + if (recv(client_fd[id], (char *)msg, HEADER_SIZE, 0) != HEADER_SIZE) + { + deleteClient(id); // the connection is not good with the client, kick him + return READ_ERROR; + } + + //msg->id = ntohl(msg->id); // see comment above + msg->type = ntohl(msg->type); + msg->length = ntohl(msg->length); + msg->room = ntohl(msg->room); + + if ((0 < msg->length) && (msg->length < PACKET_SIZE)) + { + timeout.tv_sec = 0, timeout.tv_usec = 0; // the info should be already in the socket, so don't wait + memcpy(&tset, &rset, sizeof (tset)); + if ((select(255, &tset, NULL, NULL, &timeout)) <= 0) + { + deleteClient(id); + return READ_ERROR; + } + + if (!FD_ISSET(client_fd[id], &tset)) + { + deleteClient(id); + return READ_ERROR; + } + if (recv(client_fd[id], msg->buffer, msg->length, 0) != msg->length) + { + deleteClient(id); + return READ_ERROR; + } + } + + msg->id = id; + + dbgPrintf(DEFCOL, "DONE13.\n"); + + return 0; +} + +/* + * write(): + */ +int CServerSocket::write(msg_t *msg) +{ + struct timeval timeout; + fd_set tset; + int len; + + dbgPrintf(DEFCOL, "Write a message... "); + FD_ZERO(&tset); + /* + * Be sure the msg->id is still valid; we cannot do + * a delete between a read and a write. Should we + * use a readpending set in read method, so we know + * that we are still waiting for writing? For now, + * it's the responsibility of server code. + */ + FD_SET(client_fd[msg->id], &tset); + timeout.tv_sec = 0, timeout.tv_usec = 0; + if ((select(255, NULL, &tset, NULL, &timeout)) <= 0) + { + deleteClient(msg->id); // this shouldn't happen if the net connection is good + return TIMEOUT_ERROR; + } + if (msg->length < 0) + msg->length = (INT32)strlen(msg->buffer); + if (msg->length > PACKET_SIZE) + return WRITE_ERROR; // too big + len = msg->length+HEADER_SIZE; + //msg->id = htonl(msg->id); // same comment as for read + msg->type = htonl(msg->type); + msg->length = htonl(msg->length); + if (send(client_fd[msg->id], (const char *)msg, len, 0) != len) + { + deleteClient(msg->id); + return WRITE_ERROR; + } + + dbgPrintf(DEFCOL, "DONE14.\n"); + + return 0; +} + +/* + * writeUDP() + */ +int CServerSocket::writeUDP(const char *data, size_t length, const char *ip, UINT16 port) +{ + sockaddr_in sin; + struct timeval timeout; + fd_set tset; + + FD_ZERO(&tset); + FD_SET(udp_fd, &tset); + + if ((select(255, NULL, &tset, NULL, &timeout)) <= 0) + { + return TIMEOUT_ERROR; + } + + sin.sin_family = AF_INET; + inet_aton(ip, &sin.sin_addr); + sin.sin_port = htons(port); + + sendto(udp_fd, data, (int)length, 0, (sockaddr*)&sin, sizeof(sin)); + + return 0; +} + + +/* + * accept() + */ +int CServerSocket::accept() +{ + socklen_t lg = sizeof (addr); + + dbgPrintf(DEFCOL, "Accepting on (socket %u)... ", accept_fd); + + if ((client_fd[num_clients] = ::accept(accept_fd, (struct sockaddr *) &addr, &lg)) == (SOCKET)-1) + { + //client_fd[num_clients] = (SOCKET)-1; // we haven't accepted the client, so set it at default value + return ACCEPT_ERROR; + } + + if (num_clients < MAX_CLIENT-1) + { + extern FILE *sockfile; + + logPrintf(sockfile, "Accepting on socket %u for client %u (%s:%i)\n", + client_fd[num_clients], num_clients+1, inet_ntoa(addr.sin_addr), htons(addr.sin_port)); + memcpy(&client_addr[num_clients], &addr, sizeof (addr)); + FD_SET(client_fd[num_clients], &rset); + num_clients++; + } + else // we have reached the maximum number of clients + { + // close the connection (meaning "try again" for the client) + close(client_fd[num_clients]); + client_fd[num_clients] = (SOCKET)-1; + return ACCEPT_ERROR; + } + + //dbgPrintf(DEFCOL, "DONE15.\n"); + + return 0; +} + +/* + * getClientIP() + */ +const char *CServerSocket::getClientIP(size_t id) +{ + dbgPrintf(DEFCOL, "getClientIP: %u\n", id); + return inet_ntoa(client_addr[id].sin_addr); +} + +/* + * getClientPort() + */ +const char *CServerSocket::getClientPort(size_t id) +{ + static char buffer[8]; + + dbgPrintf(DEFCOL, "getClientPort: %u\n", id); + UINT16 port = htons(client_addr[id].sin_port); + snprintf(buffer, sizeof buffer, "%d", port); + return buffer; +} + +/* + * mySignal() + */ +#ifndef _WIN32 +static Sigfunc *mySignal(int signo, Sigfunc *func) +{ + struct sigaction act, oact; + + act.sa_handler = func; + sigemptyset(&act.sa_mask); +#if defined (SA_RESTART) + act.sa_flags = SA_RESTART; +#else + act.sa_flags = 0; +#endif + if (sigaction(signo, &act, &oact) < 0) + return SIG_ERR; + return oact.sa_handler; +} + +/* + * sigHandler() + */ +static void sigHandler(int signr) +{ + mySignal(signr, sigHandler); + switch (signr) + { + case SIGPIPE: + dbgPrintf(DEFCOL, "Catch SIG_PIPE\n"); + /// TODO be sure the socket is closed if the client + /// didn't quit properly + break; + } +} +#endif diff --git a/tools/masterserver/ipcs.h b/tools/masterserver/ipcs.h new file mode 100644 index 000000000..b9dc52fdf --- /dev/null +++ b/tools/masterserver/ipcs.h @@ -0,0 +1,281 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright (C) 2000 by DooM Legacy Team. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +//----------------------------------------------------------------------------- + +#ifndef _IPCS_H_ +#define _IPCS_H_ + +#include "common.h" + +#if defined (_WIN32) || defined ( __OS2__) +#include +#include +typedef int socklen_t; +#if defined (__OS2__) +#include +#endif +#endif +#ifdef _WIN32 +#include +#define close closesocket +#else +#include // inet_addr(),... +#endif + +#ifndef SOCKET +#define SOCKET u_int +#endif + +// ================================ DEFINITIONS =============================== + +#define PACKET_SIZE 1024 +#define MAX_CLIENT 512 + +#ifndef _WIN32 +#define NO_ERROR 0 +#define SOCKET_ERROR -201 +#endif +#define BIND_ERROR -202 +#define CONNECT_ERROR -203 +#define LISTEN_ERROR -204 +#define ACCEPT_ERROR -205 +#define WRITE_ERROR -210 +#define READ_ERROR -211 +#define CLOSE_ERROR -212 +#define GETHOSTBYNAME_ERROR -220 +#define SELECT_ERROR -230 +#define TIMEOUT_ERROR -231 +#define MALLOC_ERROR -301 + +#define INVALID_MSG -1 +#define ACCEPT_MSG 100 +#define ADD_SERVER_MSG 101 +#define ADD_CLIENT_MSG 102 +#define REMOVE_SERVER_MSG 103 +#define ADD_SERVERv2_MSG 104 +#define GET_SERVER_MSG 200 +#define SEND_SERVER_MSG 201 +#define GET_LOGFILE_MSG 202 +#define SEND_FILE_MSG 203 +#define ERASE_LOGFILE_MSG 204 +#define GET_SHORT_SERVER_MSG 205 +#define SEND_SHORT_SERVER_MSG 206 +#define ASK_SERVER_MSG 206 +#define ANSWER_ASK_SERVER_MSG 207 +#define GET_MOTD_MSG 208 +#define SEND_MOTD_MSG 209 +#define GET_ROOMS_MSG 210 +#define SEND_ROOMS_MSG 211 +#define GET_ROOMS_HOST_MSG 212 +#define GET_VERSION_MSG 213 +#define SEND_VERSION_MSG 214 +#define GET_BANNED_MSG 215 +#define PING_SERVER_MSG 216 + +#define UDP_RECV_MSG 300 +#define TIMEOUT_MSG 301 +#define HTTP_REQUEST_MSG 875770417 // "4321" +#define SEND_HTTP_REQUEST_MSG 875770418 // "4322" +#define TEXT_REQUEST_MSG 825373494 // "1236" +#define SEND_TEXT_REQUEST_MSG 825373495 // "1237" +#define RSS92_REQUEST_MSG 825373496 // "1238" +#define SEND_RSS92_REQUEST_MSG 825373497 // "1239" +#define RSS10_REQUEST_MSG 825373744 // "1240" +#define SEND_RSS10_REQUEST_MSG 825373745 // "1241" +#define ADD_PSERVER_MSG 0xabacab81 // this number just need to be different than the others +#define REMOVE_PSERVER_MSG 0xabacab82 + +// Sent FROM Client +#define LIVE_AUTH_USER 600 +#define LIVE_AUTH_KEY 601 +#define LIVE_GET_USER 602 +#define LIVE_UPDATE_LOCATION 603 +#define LIVE_UPDATE_PUBLIC_KEY 604 +#define LIVE_AUTH_PUBLIC_KEY 605 + +// Sent TO Client +#define LIVE_INVALID_KEY 800 +#define LIVE_INVALID_USER 801 +#define LIVE_AUTHORISED_KEY 802 +#define LIVE_SEND_USER 803 +#define LIVE_VALIDATED_USER 804 + +// Location Types +#define LIVE_LOCATION_SP 100 +#define LIVE_LOCATION_MENU 101 +#define LIVE_LOCATION_MP_JOIN 102 +#define LIVE_LOCATION_MP_HOST 103 +#define LIVE_LOCATION_MP_LOCAL 104 +#define LIVE_LOCATION_MP_PRIVATE 105 + +#define HEADER_SIZE ((UINT32)sizeof (UINT32)*4) + +#define HEADER_MSG_POS 0 +#define IP_MSG_POS 16 +#define PORT_MSG_POS 32 +#define HOSTNAME_MSG_POS 40 + +#if defined(_MSC_VER) +#pragma pack(1) +#endif + +// Keep this structure 8 bytes aligned (current size is 80) +typedef struct +{ + char header[16]; // information such as password + char ip[16]; + char port[8]; + char name[32]; + INT32 room; + char key[32]; // Secret key for linking dedicated servers to accounts + char version[8]; // format is: x.yy.z (like 1.30.2 or 1.31) +} ATTRPACK msg_server_t; + +typedef struct +{ + char header[16]; + UINT32 id; + char name[32]; + char motd[256]; +} ATTRPACK msg_rooms_t; + +typedef struct +{ + char header[16]; + char ipstart[16]; + char ipend[16]; + char endstamp[32]; + char reason[256]; + UINT8 hostonly; +} ATTRPACK msg_ban_t; + +typedef struct +{ + char header[16]; + INT32 id; + char username[100]; + char password[32]; +} ATTRPACK msg_live_auth_t; + +typedef struct +{ + char header[16]; + INT32 uid; + char username[100]; + INT32 location_type; + char location_ip[32]; + INT32 location_port; + INT32 lastseen_type; + char lastseen_data1[256]; + char lastseen_data2[256]; + char lastseen_data3[256]; +} ATTRPACK msg_live_user_t; + +typedef struct +{ + char header[16]; + UINT8 location_type; + char location_ip[32]; + INT32 location_port; + char location_data1[256]; + char location_data2[256]; + char location_data3[256]; +} ATTRPACK msg_live_updatelocation_t; + +typedef struct +{ + char header[16]; + char publickey[256]; + char username[256]; +} ATTRPACK msg_live_validateuser_t; + +typedef struct +{ + char header[16]; + char username[256]; + UINT8 keytype; + char keydata[256]; +} ATTRPACK msg_live_update_key_t; + + +typedef struct +{ + UINT32 id; + INT32 type; + INT32 room; + INT32 length; + char buffer[PACKET_SIZE]; +} ATTRPACK msg_t; + +#if defined(_MSC_VER) +#pragma pack() +#endif + +class CSocket +{ +protected: + sockaddr_in addr; + msg_t msg; + fd_set rset; +public: + int getIP(const char *); + CSocket(); + ~CSocket(); +}; + +class CServerSocket : public CSocket +{ +private: + sockaddr_in udp_addr; + sockaddr_in udp_in_addr; + SOCKET udp_fd; + SOCKET accept_fd; + size_t num_clients; + SOCKET client_fd[MAX_CLIENT]; + sockaddr_in client_addr[MAX_CLIENT]; + +public: + int deleteClient(size_t id); + int listen(const char *str_port); + int accept(void); + int read(msg_t *msg); + const char *getUdpIP(void); + const char *getUdpPort(bool); + int write(msg_t *msg); + int writeUDP(const char *data, size_t length, const char *ip, UINT16 port); + const char *getClientIP(size_t id); + const char *getClientPort(size_t id); + CServerSocket(void); + ~CServerSocket(void); +}; + +class CClientSocket : public CSocket +{ +private: + SOCKET socket_fd; +public: + int connect(const char *ip_addr, const char *str_port); + int read(msg_t *msg); + int write(msg_t *msg); + CClientSocket(void); + ~CClientSocket(void); +}; + +// ================================== PROTOS ================================== + +// ================================== EXTERNS ================================= + +#endif diff --git a/tools/masterserver/masterserver.sh b/tools/masterserver/masterserver.sh new file mode 100755 index 000000000..9b1adb128 --- /dev/null +++ b/tools/masterserver/masterserver.sh @@ -0,0 +1,48 @@ +#!/bin/sh -e +# +# SRB2 MasterServer - start up the masterserver +# + +# Get LSB functions +. /lib/lsb/init-functions +. /etc/default/rcS + +SRB2MS=/usr/local/bin/masterserver +SRB2MS_PORT=28900 + +# Check that the package is still installed +[ -x $SRB2MS ] || exit 0; + +case "$1" in + start) + log_begin_msg "Starting SRB2MS..." + umask 002 + if start-stop-daemon --start \ + --exec $SRB2MS \ + -- $SRB2MS_PORT; then + log_end_msg 0 + else + log_end_msg $? + fi + ;; + + stop) + log_begin_msg "Stopping SRB2MS..." + if start-stop-daemon --stop --exec $SRB2MS; then + log_end_msg 0 + else + log_end_msg $? + fi + ;; + + restart|force-reload) + "$0" stop && "$0" start + ;; + + *) + e cho "Usage: /etc/init.d/masterserver {start|stop|restart|force-reload}" + exit 1 + ;; +esac + +exit 0 diff --git a/tools/masterserver/md5.cpp b/tools/masterserver/md5.cpp new file mode 100644 index 000000000..4f4ff2292 --- /dev/null +++ b/tools/masterserver/md5.cpp @@ -0,0 +1,363 @@ +/* MD5 + converted to C++ class by Frank Thilo (thilo@unix-ag.org) + for bzflag (http://www.bzflag.org) + + based on: + + md5.h and md5.c + reference implemantion of RFC 1321 + + Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All +rights reserved. + +License to copy and use this software is granted provided that it +is identified as the "RSA Data Security, Inc. MD5 Message-Digest +Algorithm" in all material mentioning or referencing this software +or this function. + +License is also granted to make and use derivative works provided +that such works are identified as "derived from the RSA Data +Security, Inc. MD5 Message-Digest Algorithm" in all material +mentioning or referencing the derived work. + +RSA Data Security, Inc. makes no representations concerning either +the merchantability of this software or the suitability of this +software for any particular purpose. It is provided "as is" +without express or implied warranty of any kind. + +These notices must be retained in any copies of any part of this +documentation and/or software. + +*/ + +/* interface header */ +#include "md5.h" + +/* system implementation headers */ +#include +#include + + +// Constants for MD5Transform routine. +#define S11 7 +#define S12 12 +#define S13 17 +#define S14 22 +#define S21 5 +#define S22 9 +#define S23 14 +#define S24 20 +#define S31 4 +#define S32 11 +#define S33 16 +#define S34 23 +#define S41 6 +#define S42 10 +#define S43 15 +#define S44 21 + +/////////////////////////////////////////////// + +// F, G, H and I are basic MD5 functions. +inline MD5::uint4 MD5::F(uint4 x, uint4 y, uint4 z) { + return (x&y) | (~x&z); +} + +inline MD5::uint4 MD5::G(uint4 x, uint4 y, uint4 z) { + return (x&z) | (y&~z); +} + +inline MD5::uint4 MD5::H(uint4 x, uint4 y, uint4 z) { + return x^y^z; +} + +inline MD5::uint4 MD5::I(uint4 x, uint4 y, uint4 z) { + return y ^ (x | ~z); +} + +// rotate_left rotates x left n bits. +inline MD5::uint4 MD5::rotate_left(uint4 x, int n) { + return (x << n) | (x >> (32-n)); +} + +// FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. +// Rotation is separate from addition to prevent recomputation. +inline void MD5::FF(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac) { + a = rotate_left(a+ F(b,c,d) + x + ac, s) + b; +} + +inline void MD5::GG(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac) { + a = rotate_left(a + G(b,c,d) + x + ac, s) + b; +} + +inline void MD5::HH(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac) { + a = rotate_left(a + H(b,c,d) + x + ac, s) + b; +} + +inline void MD5::II(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac) { + a = rotate_left(a + I(b,c,d) + x + ac, s) + b; +} + +////////////////////////////////////////////// + +// default ctor, just initailize +MD5::MD5() +{ + init(); +} + +////////////////////////////////////////////// + +// nifty shortcut ctor, compute MD5 for string and finalize it right away +MD5::MD5(const std::string &text) +{ + init(); + update(text.c_str(), text.length()); + finalize(); +} + +////////////////////////////// + +void MD5::init() +{ + finalized=false; + + count[0] = 0; + count[1] = 0; + + // load magic initialization constants. + state[0] = 0x67452301; + state[1] = 0xefcdab89; + state[2] = 0x98badcfe; + state[3] = 0x10325476; +} + +////////////////////////////// + +// decodes input (unsigned char) into output (uint4). Assumes len is a multiple of 4. +void MD5::decode(uint4 output[], const uint1 input[], size_type len) +{ + for (unsigned int i = 0, j = 0; j < len; i++, j += 4) + output[i] = ((uint4)input[j]) | (((uint4)input[j+1]) << 8) | + (((uint4)input[j+2]) << 16) | (((uint4)input[j+3]) << 24); +} + +////////////////////////////// + +// encodes input (uint4) into output (unsigned char). Assumes len is +// a multiple of 4. +void MD5::encode(uint1 output[], const uint4 input[], size_type len) +{ + for (size_type i = 0, j = 0; j < len; i++, j += 4) { + output[j] = input[i] & 0xff; + output[j+1] = (input[i] >> 8) & 0xff; + output[j+2] = (input[i] >> 16) & 0xff; + output[j+3] = (input[i] >> 24) & 0xff; + } +} + +////////////////////////////// + +// apply MD5 algo on a block +void MD5::transform(const uint1 block[blocksize]) +{ + uint4 a = state[0], b = state[1], c = state[2], d = state[3], x[16]; + decode (x, block, blocksize); + + /* Round 1 */ + FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */ + FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */ + FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */ + FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */ + FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */ + FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */ + FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */ + FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */ + FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */ + FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */ + FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */ + FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */ + FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */ + FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */ + FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */ + FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */ + + /* Round 2 */ + GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */ + GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */ + GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */ + GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */ + GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */ + GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */ + GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */ + GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */ + GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */ + GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */ + GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */ + GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */ + GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */ + GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */ + GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */ + GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */ + + /* Round 3 */ + HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */ + HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */ + HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */ + HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */ + HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */ + HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */ + HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */ + HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */ + HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */ + HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */ + HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */ + HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */ + HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */ + HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */ + HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */ + HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */ + + /* Round 4 */ + II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */ + II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */ + II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */ + II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */ + II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */ + II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */ + II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */ + II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */ + II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */ + II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */ + II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */ + II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */ + II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */ + II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */ + II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */ + II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */ + + state[0] += a; + state[1] += b; + state[2] += c; + state[3] += d; + + // Zeroize sensitive information. + memset(x, 0, sizeof x); +} + +////////////////////////////// + +// MD5 block update operation. Continues an MD5 message-digest +// operation, processing another message block +void MD5::update(const unsigned char input[], size_type length) +{ + // compute number of bytes mod 64 + size_type index = count[0] / 8 % blocksize; + + // Update number of bits + if ((count[0] += (length << 3)) < (length << 3)) + count[1]++; + count[1] += (length >> 29); + + // number of bytes we need to fill in buffer + size_type firstpart = 64 - index; + + size_type i; + + // transform as many times as possible. + if (length >= firstpart) + { + // fill buffer first, transform + memcpy(&buffer[index], input, firstpart); + transform(buffer); + + // transform chunks of blocksize (64 bytes) + for (i = firstpart; i + blocksize <= length; i += blocksize) + transform(&input[i]); + + index = 0; + } + else + i = 0; + + // buffer remaining input + memcpy(&buffer[index], &input[i], length-i); +} + +////////////////////////////// + +// for convenience provide a verson with signed char +void MD5::update(const char input[], size_type length) +{ + update((const unsigned char*)input, length); +} + +////////////////////////////// + +// MD5 finalization. Ends an MD5 message-digest operation, writing the +// the message digest and zeroizing the context. +MD5& MD5::finalize() +{ + static unsigned char padding[64] = { + 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + }; + + if (!finalized) { + // Save number of bits + unsigned char bits[8]; + encode(bits, count, 8); + + // pad out to 56 mod 64. + size_type index = count[0] / 8 % 64; + size_type padLen = (index < 56) ? (56 - index) : (120 - index); + update(padding, padLen); + + // Append length (before padding) + update(bits, 8); + + // Store state in digest + encode(digest, state, 16); + + // Zeroize sensitive information. + memset(buffer, 0, sizeof buffer); + memset(count, 0, sizeof count); + + finalized=true; + } + + return *this; +} + +////////////////////////////// + +// return hex representation of digest as string +std::string MD5::hexdigest() const +{ + if (!finalized) + return ""; + + char buf[33]; + for (int i=0; i<16; i++) + sprintf(buf+i*2, "%02x", digest[i]); + buf[32]=0; + + return std::string(buf); +} + +////////////////////////////// + +std::ostream& operator<<(std::ostream& out, MD5 md5) +{ + return out << md5.hexdigest(); +} + +////////////////////////////// + +std::string md5(const std::string str) +{ + MD5 md5 = MD5(str); + + return md5.hexdigest(); +} diff --git a/tools/masterserver/md5.h b/tools/masterserver/md5.h new file mode 100644 index 000000000..55a90c4cb --- /dev/null +++ b/tools/masterserver/md5.h @@ -0,0 +1,93 @@ +/* MD5 + converted to C++ class by Frank Thilo (thilo@unix-ag.org) + for bzflag (http://www.bzflag.org) + + based on: + + md5.h and md5.c + reference implementation of RFC 1321 + + Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All +rights reserved. + +License to copy and use this software is granted provided that it +is identified as the "RSA Data Security, Inc. MD5 Message-Digest +Algorithm" in all material mentioning or referencing this software +or this function. + +License is also granted to make and use derivative works provided +that such works are identified as "derived from the RSA Data +Security, Inc. MD5 Message-Digest Algorithm" in all material +mentioning or referencing the derived work. + +RSA Data Security, Inc. makes no representations concerning either +the merchantability of this software or the suitability of this +software for any particular purpose. It is provided "as is" +without express or implied warranty of any kind. + +These notices must be retained in any copies of any part of this +documentation and/or software. + +*/ + +#ifndef BZF_MD5_H +#define BZF_MD5_H + +#include +#include + + +// a small class for calculating MD5 hashes of strings or byte arrays +// it is not meant to be fast or secure +// +// usage: 1) feed it blocks of uchars with update() +// 2) finalize() +// 3) get hexdigest() string +// or +// MD5(std::string).hexdigest() +// +// assumes that char is 8 bit and int is 32 bit +class MD5 +{ +public: + typedef unsigned int size_type; // must be 32bit + + MD5(); + MD5(const std::string& text); + void update(const unsigned char *buf, size_type length); + void update(const char *buf, size_type length); + MD5& finalize(); + std::string hexdigest() const; + friend std::ostream& operator<<(std::ostream&, MD5 md5); + +private: + void init(); + typedef unsigned char uint1; // 8bit + typedef unsigned int uint4; // 32bit + enum {blocksize = 64}; // VC6 won't eat a const static int here + + void transform(const uint1 block[blocksize]); + static void decode(uint4 output[], const uint1 input[], size_type len); + static void encode(uint1 output[], const uint4 input[], size_type len); + + bool finalized; + uint1 buffer[blocksize]; // bytes that didn't fit in last 64 byte chunk + uint4 count[2]; // 64bit counter for number of bits (lo, hi) + uint4 state[4]; // digest so far + uint1 digest[16]; // the result + + // low level logic operations + static inline uint4 F(uint4 x, uint4 y, uint4 z); + static inline uint4 G(uint4 x, uint4 y, uint4 z); + static inline uint4 H(uint4 x, uint4 y, uint4 z); + static inline uint4 I(uint4 x, uint4 y, uint4 z); + static inline uint4 rotate_left(uint4 x, int n); + static inline void FF(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac); + static inline void GG(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac); + static inline void HH(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac); + static inline void II(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac); +}; + +std::string md5(const std::string str); + +#endif diff --git a/tools/masterserver/server.cpp b/tools/masterserver/server.cpp new file mode 100644 index 000000000..b7ed0d6b4 --- /dev/null +++ b/tools/masterserver/server.cpp @@ -0,0 +1,1037 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright (C) 2000 by DooM Legacy Team. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +//----------------------------------------------------------------------------- +#ifdef __GNUC__ +#include +#include +#endif +#include +#include +#include +#include "ipcs.h" +#include "common.h" +#include "mysql.h" +#include "md5.h" +#include +//#include + +//============================================================================= + +#ifdef __GNUC__ +#define ATTRPACK __attribute__ ((packed)) +#else +#define ATTRPACK +#endif + +#define PT_ASKINFOVIAMS 15 + +static CServerSocket server_socket; + +FILE *logfile; +FILE *errorfile; +FILE *mysqlfile; +FILE *sockfile; +FILE *pidfile; + +#if defined(_MSC_VER) +#pragma pack(1) +#endif + +typedef struct +{ + char ip[16]; // Big enough to hold a full address. + UINT16 port; + UINT8 padding1[2]; + UINT32 time; +} ATTRPACK ms_holepunch_packet_t; + +typedef struct +{ + char clientaddr[22]; + UINT8 padding1[2]; + UINT32 time; +} ATTRPACK msaskinfo_pak; + +// +// SRB2 network packet data. +// +typedef struct +{ + UINT32 checksum; + UINT8 ack; // if not null the node asks for acknowledgement, the receiver must resend the ack + UINT8 ackreturn; // the return of the ack number + + UINT8 packettype; + UINT8 reserved; // padding + + msaskinfo_pak msaskinfo; +} ATTRPACK doomdata_t; + +#if defined(_MSC_VER) +#pragma pack() +#endif + +//============================================================================= + +#define HOSTNAME "loopback" +#define USER "srb2_ms" +#define PASSWORD "gLRDRb7WgLRDRb7W" +#define DATABASE "srb2_ms" + +// MySQL Stuff :D + + const char *server = HOSTNAME; + const char *user = USER; + const char *password = PASSWORD; + const char *database = DATABASE; + time_t lastupdate; + + MYSQL *conn; + MYSQL_RES *res; + MYSQL_ROW row; + int mysqlconnected = 0; +/* +char *str_replace(char * t1, char * t2, char * t6) +{ + char*t4; + char*t5=new(0); + + while(strstr(t6,t1)){ + t4=strstr(t6,t1); + strncpy(t5+strlen(t5),t6,t4-t6); + strcat(t5,t2); + t4+=strlen(t1); + t6=t4; + } + return strcat(t5,t4); +} +*/ +/* +// Cue was here +char *str_quakeformat(char *msg) +{ + char *quakemsg , *quakemsg1, *quakemsg2; + char *quakemsg3, *quakemsg4, *quakemsg5; + char *quakemsg6, *quakemsg7, *quakemsg8; + + quakemsg1 = new(sizeof(char) * (strlen(msg) + 1)); + strcpy(quakemsg1, msg); + quakemsg2 = str_replace("^1", "\x81",quakemsg1); + quakemsg3 = str_replace("^2", "\x82",quakemsg2); + quakemsg4 = str_replace("^3", "\x83",quakemsg3); + quakemsg5 = str_replace("^4", "\x84",quakemsg4); + quakemsg6 = str_replace("^5", "\x85",quakemsg5); + quakemsg7 = str_replace("^6", "\x86",quakemsg6); + quakemsg8 = str_replace("^7", "\x87",quakemsg7); + quakemsg = str_replace("^0", "\x80",quakemsg8); + delete(quakemsg1); + delete(quakemsg2); + delete(quakemsg3); + delete(quakemsg4); + delete(quakemsg5); + delete(quakemsg6); + delete(quakemsg7); + delete(quakemsg8); + + return quakemsg; +} + */ +void MySQL_Conn(bool force) { + //if(mysql_ping(conn)) + //mysqlconnected = 0; + logPrintf(mysqlfile, "Trying to connect to MySQL...\n"); + if(mysqlconnected != 1 || force) { + if(force) + mysql_close(conn); + const char *server = HOSTNAME; + const char *user = USER; + const char *password = PASSWORD; + const char *database = DATABASE; + + conn = mysql_init(NULL); + + /* Connect to database */ + if (!mysql_real_connect(conn, server, + user, password, database, 8219, NULL, 0)) { + logPrintf(errorfile, "%s\n", mysql_error(conn)); + } + conn = mysql_init(NULL); + + /* Connect to database */ + if (!mysql_real_connect(conn, server, user, password, database, 0, NULL, 0)) { + logPrintf(errorfile, "%s\n", mysql_error(conn)); + mysqlconnected = 0; + } else { + logPrintf(mysqlfile, "Connection to MySQL Database successful!\n"); + mysqlconnected = 1; + } + } +} + +static int MySQL_CheckBan(const char *ip, UINT32 id, bool sendinfo, bool type) { + msg_t msg; + int writecode; + MySQL_Conn(false); + msg.id = id; + char banqueryp1[500] = "SELECT bid,INET_NTOA(ipstart),INET_NTOA(ipend),DATE_FORMAT(FROM_UNIXTIME(full_endtime),'%%a %%b %%e %%Y at %%k:%%i (CDT)'),reason,hostonly,permanent FROM ms_bans WHERE INET_ATON('%s') BETWEEN `ipstart` AND `ipend` AND (`full_endtime` > %ld OR `permanent` = '1') LIMIT 1"; +// char exqueryp1[500] = "SELECT * FROM ms_exceptions WHERE `ip` = '%s' AND `bid` = '%s' LIMIT 1"; +// char exquery[500]; + char banquery[500]; +// char bid[5]; + + time_t current_time = time (NULL); + sprintf(banquery, banqueryp1, ip, current_time); + logPrintf(mysqlfile, "Executing MySQL Query: %s\n", banquery); + if(mysql_query(conn, banquery)) { + logPrintf(errorfile, "MYSQL ERROR: %s\n", mysql_error(conn)); + MySQL_Conn(true); + return false; + } else { + res = mysql_store_result(conn); + if(mysql_num_rows(res) >= 1) { + logPrintf(logfile, "We got a ban coming on!\n"); + row = mysql_fetch_row(res); + if(!type && strcmp(row[5],"1") == 0) + return false; + if(sendinfo) + { + logPrintf(logfile, "And we're meant to tell them some more!\n"); + msg_ban_t *info = (msg_ban_t *) msg.buffer; + info->header[0] = '\0'; + + logPrintf(logfile, "Got Ban: %s - %s, ends %s, for %s\n", row[1], row[2], row[3], row[4]); + logPrintf(logfile, "COPY: ipstart\n"); + strcpy(info->ipstart, row[1]); + logPrintf(logfile, "COPY: ipend\n"); + strcpy(info->ipend, row[2]); + logPrintf(logfile, "COPY: endtime\n"); + if(strcmp(row[6], "0") == 0) + { + logPrintf(logfile, "COPY: It's not permanent.\n"); + strcpy(info->endstamp, row[3]); + } + else + { + logPrintf(logfile, "COPY: It's permanent.\n"); + strcpy(info->endstamp, "Never"); + } + logPrintf(logfile, "COPY: reason\n"); + strcpy(info->reason, row[4]); + logPrintf(logfile, "COPY: hostonly\n"); + if(strcmp(row[5],"0") == 0) + info->hostonly = false; + else + info->hostonly = true; + + if(info->hostonly) + logPrintf(logfile, "BAN HAMMER: %s - %s || Reason: %s || Endstamp: %s || HOSTONLY\n", info->ipstart, info->ipend, info->reason, info->endstamp); + else + logPrintf(logfile, "BAN HAMMER: %s - %s || Reason: %s || Endstamp: %s || NOTHOSTONLY\n", info->ipstart, info->ipend, info->reason, info->endstamp); + mysql_free_result(res); + msg.type = GET_BANNED_MSG; + msg.length = sizeof (msg_ban_t); + msg.room = 0; + logPrintf(logfile, "Sending message?\n"); + writecode = server_socket.write(&msg); + logPrintf(logfile, "Message sent! :D\n"); + if (writecode < 0) + { + dbgPrintf(LIGHTRED, "Write error... %d client %d " + "deleted\n", writecode, id); + return true; + } + } + return true; + } else { + mysql_free_result(res); + return false; + } + } +} + +int MySQL_CheckRoom(UINT32 room) +{ + MySQL_Conn(false); + char checkqueryp1[500] = "SELECT private FROM `ms_rooms` WHERE `room_id` = '%d' AND `private` = '1' LIMIT 1"; + char checkquery[500]; + sprintf(checkquery, checkqueryp1, room); + logPrintf(mysqlfile, "Executing MySQL Query: %s\n", checkquery); + if(mysql_query(conn, checkquery)) { + logPrintf(errorfile, "MYSQL ERROR: %s\n", mysql_error(conn)); + MySQL_Conn(true); + return false; + } else { + res = mysql_store_result(conn); + if(mysql_num_rows(res) < 1) + return true; + else + return false; + } +} + +void MySQL_AddServer(const char *ip, const char *port, const char *name, const char *version, UINT32 room, bool firstadd, const char *key) { + char escapedName[255]; + char escapedPort[10]; + char escapedVersion[10]; + char escapedKey[32]; + char insertquery[5000]; + char checkquery[500]; + char updatequery[5000]; + char queryp1[5000] = "INSERT INTO `ms_servers` (`name`,`ip`,`port`,`version`,`timestamp`,`room`,`key`) VALUES ('%s','%s','%s','%s','%ld','%d','%s')"; + char checkqueryp1[500] = "SELECT room_override FROM `ms_servers` WHERE `ip` = '%s'"; + char updatequeryp1[5000]; + if(firstadd) + { + logPrintf(logfile, "First add.\n"); + strcpy(updatequeryp1, "UPDATE `ms_servers` SET `name` = '%s', `port` = '%s', `version` = '%s', timestamp = '%ld', upnow = '1', `room` = '%d', `delisted` = '0', `key` = '%s' WHERE `ip` = '%s'"); + } + else + { + logPrintf(logfile, "Update ping.\n"); + strcpy(updatequeryp1, "UPDATE `ms_servers` SET `name` = '%s', `port` = '%s', `version` = '%s', timestamp = '%ld', upnow = '1', `room` = '%d', `key` = '%s' WHERE `ip` = '%s' AND `delisted` = '0'"); + } + MySQL_Conn(false); + mysql_real_escape_string(conn, escapedName, name, (unsigned long)strlen(name)); + mysql_real_escape_string(conn, escapedPort, port, (unsigned long)strlen(port)); + mysql_real_escape_string(conn, escapedVersion, version, (unsigned long)strlen(version)); + mysql_real_escape_string(conn, escapedKey, key, (unsigned long)strlen(key)); + if(!MySQL_CheckBan(ip,0,false,1)) { + if(!MySQL_CheckRoom(room)) + { + logPrintf(errorfile, "IP %s tried to use the private room %d! THIS SHOULD NOT HAPPEN\n", ip, room); + return; + } + sprintf(checkquery, checkqueryp1, ip); + time_t timestamp; + timestamp = time (NULL); + logPrintf(logfile, "Checking for existing servers in table with the same IP...\n"); + logPrintf(mysqlfile, "Executing MySQL Query: %s\n", checkquery); + if(mysql_query(conn, checkquery)) { + logPrintf(errorfile, "MYSQL ERROR: %s\n", mysql_error(conn)); + MySQL_Conn(true); + } else { + res = mysql_store_result(conn); + logPrintf(logfile, "Found %d rows...\n", mysql_num_rows(res)); + if(mysql_num_rows(res) < 1) { + mysql_free_result(res); + logPrintf(logfile, "Adding the temporary server: %s:%s || Name: %s || Version: %s || Time: %ld || Room: %d || Key: %s\n", ip, port, name, version, timestamp, room, key); + sprintf(insertquery, queryp1, escapedName, ip, escapedPort, escapedVersion, timestamp, room, escapedKey); + logPrintf(mysqlfile, "Executing MySQL Query: %s\n", insertquery); + if(mysql_query(conn, insertquery)) { + logPrintf(errorfile, "MYSQL ERROR: %s\n", mysql_error(conn)); + MySQL_Conn(true); + } else { + logPrintf(logfile, "Server added successfully!\n"); + } + } else { + row = mysql_fetch_row(res); + if(atoi(row[0]) != 0) + room = atoi(row[0]); + mysql_free_result(res); + logPrintf(logfile, "Server's IP already exists, so let's just update it instead...\n"); + logPrintf(logfile, "Updating Server Data for %s\n", ip); + sprintf(updatequery, updatequeryp1, escapedName, escapedPort, escapedVersion, timestamp, room, escapedKey, ip); + logPrintf(mysqlfile, "Executing MySQL Query: %s\n", updatequery); + if(mysql_query(conn, updatequery)) { + logPrintf(errorfile, "MYSQL ERROR: %s\n", mysql_error(conn)); + MySQL_Conn(true); + } else { + logPrintf(logfile, "Server status for Server: %s:%s || Name: %s || Version: %s || Time: %ld || Room: %d || Key: %s set successfully.\n", ip, port, name, version, timestamp, room, key); + } + } + } + } else { + logPrintf(logfile, "IP %s is banned so do nothing.\n", ip); + } +} + +void MySQL_ListServers(UINT32 id, UINT32 type, const char *ip, UINT32 room) { + msg_t msg; + int writecode; + MySQL_Conn(false); + msg.id = id; + msg.type = type; + char servquery[1000]; + if(room == 0) + sprintf(servquery, "SELECT ip, port, name, version FROM ( SELECT * FROM `ms_servers` WHERE `upnow` = '1' ORDER BY `sid` ASC) as t2 ORDER BY `sticky` DESC"); + else + { + char servqueryp1[1000] = "SELECT ip, port, name, version FROM ( SELECT * FROM `ms_servers` WHERE `upnow` = '1' AND `room` = '%d' ORDER BY `sid` ASC) as t2 ORDER BY `sticky` DESC"; + sprintf(servquery, servqueryp1, room); + } + if(!MySQL_CheckBan(ip,0,false,0)) { + logPrintf(mysqlfile, "Executing MySQL Query: %s\n", servquery); + if(mysql_query(conn, servquery)) { + logPrintf(errorfile, "MYSQL ERROR: %s\n", mysql_error(conn)); + MySQL_Conn(true); + } else { + res = mysql_store_result(conn); + logPrintf(logfile, "Found %d servers...\n", mysql_num_rows(res)); + while ((row = mysql_fetch_row(res)) != NULL) + { + msg_server_t *info = (msg_server_t *) msg.buffer; + + info->header[0] = '\0'; // nothing interresting in it (for now) + strcpy(info->ip, row[0]); + strcpy(info->port, row[1]); + strcpy(info->name, row[2]); + strcpy(info->version, row[3]); + + msg.length = sizeof (msg_server_t); + msg.room = 0; + logPrintf(logfile, "Sending message?\n"); + writecode = server_socket.write(&msg); + logPrintf(logfile, "Message sent! :D\n"); + if (writecode < 0) + { + dbgPrintf(LIGHTRED, "Write error... %d client %d " + "deleted\n", writecode, id); + return; + } + } + mysql_free_result(res); + } + } else { + logPrintf(logfile, "IP %s is banned so do nothing.\n", ip); + } +} + +void MySQL_ListRooms(UINT32 id, UINT32 type, const char *ip, bool sendtype) { + msg_t msg; + int writecode; + //(void)ip; + MySQL_Conn(false); + msg.id = id; + msg.type = type; + char roomquery[1000]; + logPrintf(logfile, "Check their ban status first... (ID %d)\n",id); + if(MySQL_CheckBan(ip,id,true,sendtype)) + return; + + //Hmph! I suppose it'll be up to me to handle this. ~Inuyasha + if (sendtype) + { + char overridequery[500]; + + sprintf(overridequery, "SELECT room_override FROM `ms_servers` WHERE `ip` = '%s' AND `room_override` > 0", ip); + logPrintf(mysqlfile, "Checking for room overrides! Executing MySQL Query: %s\n", overridequery); + if (mysql_query(conn, overridequery)) + { + logPrintf(errorfile, "MYSQL ERROR: %s\n", mysql_error(conn)); + MySQL_Conn(true); + return; + } + + res = mysql_store_result(conn); + if (mysql_num_rows(res) >= 1) + { + int overriddenRoom; + + row = mysql_fetch_row(res); + overriddenRoom = atoi(row[0]); + mysql_free_result(res); + + sprintf(roomquery, "SELECT room_id, title, motd FROM `ms_rooms` WHERE `room_id` = '%d' LIMIT 1", overriddenRoom); + if (mysql_query(conn, roomquery)) + { + logPrintf(errorfile, "MYSQL ERROR: %s\n", mysql_error(conn)); + MySQL_Conn(true); + return; + } + res = mysql_store_result(conn); + if (mysql_num_rows(res) >= 1) + { + msg_rooms_t *info = (msg_rooms_t *) msg.buffer; + char roommotd[300]; + + row = mysql_fetch_row(res); + + info->header[0] = '\0'; // nothing interesting in it (for now) + strcpy(info->name, row[1]); + + // Just in case, let's make sure we don't overflow. + sprintf(roommotd, "\x85Your server has had a room override applied to it, so this is the only room you may host in.\x80\n\n%s", row[2]); + strncpy(info->motd, roommotd, 255); + info->motd[255] = '\0'; + + info->id = atoi(row[0]); + + logPrintf(logfile, "Sending Room %s with ID %d and MOTD %s\n", info->name, info->id, info->motd); + + msg.length = sizeof (msg_rooms_t); + msg.room = 0; + logPrintf(logfile, "Sending message?\n"); + writecode = server_socket.write(&msg); + logPrintf(logfile, "Message sent! :D\n"); + if (writecode < 0) + { + dbgPrintf(LIGHTRED, "Write error... %d client %d " + "deleted\n", writecode, id); + } + mysql_free_result(res); + return; + } + else + { + logPrintf(errorfile, "Someone's room override isn't set correctly! Room %d doesn't exist!", overriddenRoom); + mysql_free_result(res); + } + } + } + + if(sendtype) + sprintf(roomquery, "SELECT room_id, title, motd FROM `ms_rooms` WHERE `private` = '0' AND `visible` = '1' ORDER BY `order` ASC"); + else + sprintf(roomquery, "SELECT room_id, title, motd FROM `ms_rooms` WHERE `visible` = '1' ORDER BY `order` ASC"); + if(mysql_query(conn, roomquery)) { + logPrintf(errorfile, "MYSQL ERROR: %s\n", mysql_error(conn)); + MySQL_Conn(true); + } else + { + res = mysql_store_result(conn); + logPrintf(logfile, "Found %d rooms...\n", mysql_num_rows(res)); + while ((row = mysql_fetch_row(res)) != NULL) + { + msg_rooms_t *info = (msg_rooms_t *) msg.buffer; + + info->header[0] = '\0'; // nothing interresting in it (for now) + strcpy(info->name, row[1]); + strcpy(info->motd, row[2]); + info->id = atoi(row[0]); + + logPrintf(logfile, "Sending Room %s with ID %d and MOTD %s\n", info->name, info->id, info->motd); + + msg.length = sizeof (msg_rooms_t); + msg.room = 0; + logPrintf(logfile, "Sending message?\n"); + writecode = server_socket.write(&msg); + logPrintf(logfile, "Message sent! :D\n"); + if (writecode < 0) + { + dbgPrintf(LIGHTRED, "Write error... %d client %d " + "deleted\n", writecode, id); + return; + } + } + mysql_free_result(res); + } +} + +void MySQL_CheckVersion(UINT32 id, UINT32 type, const char *ip, UINT32 modid, const char *modversion) { + msg_t msg; + int writecode; + (void)ip; + MySQL_Conn(false); + msg.id = id; + msg.type = type; + char versionquery[1000]; + sprintf(versionquery, "SELECT * FROM `ms_versions` WHERE `mod_id` = '%d' AND `mod_version` > %s LIMIT 1",modid, modversion); + logPrintf(mysqlfile, "Executing MySQL Query: %s\n", versionquery); + if(mysql_query(conn, versionquery)) { + logPrintf(errorfile, "MYSQL ERROR: %s\n", mysql_error(conn)); + MySQL_Conn(true); + } else + { + res = mysql_store_result(conn); + if(mysql_num_rows(res) < 1) + { + logPrintf(logfile, "Buffer to NULL\n"); + strcpy(msg.buffer,"NULL"); + } + else + { + row = mysql_fetch_row(res); + logPrintf(logfile, "Version found: %s || Codebase: %s || Version: %s || Version String: %s || Mod ID: %s\n", row[4], row[3], row[1], row[2], row[0]); + strcpy(msg.buffer,row[2]); + } + msg.length = sizeof msg.buffer; + msg.room = 0; + logPrintf(logfile, "Sending message?\n"); + writecode = server_socket.write(&msg); + logPrintf(logfile, "Message sent! :D\n"); + if (writecode < 0) + { + dbgPrintf(LIGHTRED, "Write error... %d client %d " + "deleted\n", writecode, id); + return; + } + mysql_free_result(res); + } +} + +void MySQL_ListServServers(UINT32 id, UINT32 type, const char *ip) { + msg_t msg; + int writecode; + static char str[1024]; + //char banqueryp1[500] = "SELECT reason,name,FROM_UNIXTIME(endtime) FROM ms_bans WHERE INET_ATON('%s') BETWEEN `ipstart` AND `ipend` AND `endtime` < %ld LIMIT 1"; + //char banquery[500]; + //time_t current_time = time (NULL); + char servquery[1000] = "SELECT ip, port, name, version, permanent FROM ( SELECT * FROM `ms_servers` WHERE `upnow` = '1' OR `permanent` = '1' ORDER BY `sid` ASC) as ms_servers ORDER BY `sticky` DESC"; + MySQL_Conn(false); + if(!MySQL_CheckBan(ip,0,false,0)) { + msg.id = id; + msg.type = type; + msg.room = 0; + logPrintf(mysqlfile, "Executing MySQL Query: %s\n", servquery); + if(mysql_query(conn, servquery)) { + logPrintf(errorfile, "MYSQL ERROR: %s\n", mysql_error(conn)); + MySQL_Conn(true); + } else { + res = mysql_store_result(conn); + logPrintf(logfile, "Found %d servers...\n", mysql_num_rows(res)); + while ((row = mysql_fetch_row(res)) != NULL) + { + if(strcmp(row[4], "0") == 1) + snprintf(str, sizeof str, "IP\t\t: %s\nPort\t\t: %s\nHostname\t: %s\nVersion\t\t: %s\nPermanent\t: %s\n", row[0], row[1], row[2], row[3], "Yes"); + else + snprintf(str, sizeof str, "IP\t\t: %s\nPort\t\t: %s\nHostname\t: %s\nVersion\t\t: %s\nPermanent\t: %s\n", row[0], row[1], row[2], row[3], "No"); + + msg.length = (INT32)(strlen(str)+1); // send also the '\0' + strcpy(msg.buffer, str); + dbgPrintf(CYAN, "Writing: (%d)\n%s\n", msg.length, msg.buffer); + writecode = server_socket.write(&msg); + if (writecode < 0) + { + dbgPrintf(LIGHTRED, "Write error... %d client %d deleted\n", writecode, id); + return; + } + } + mysql_free_result(res); + } + } else { + logPrintf(logfile, "IP %s is banned so do nothing! Let them find out for themselves.\n", ip); + } +} + +void MySQL_RemoveServer(char *ip, char *port, char *name, char *version) { + char escapedName[255]; + char updatequery[5000]; + char updatequeryp1[5000] = "UPDATE `ms_servers` SET upnow = '0' WHERE `ip` = '%s' AND `permanent` = '0'"; + MySQL_Conn(false); + mysql_real_escape_string(conn, escapedName, name, (unsigned long)strlen(name)); + sprintf(updatequery, updatequeryp1, ip); + logPrintf(mysqlfile, "Executing MySQL Query: %s\n", updatequery); + if(mysql_query(conn, updatequery)) { + logPrintf(errorfile, "MYSQL ERROR: %s\n", mysql_error(conn)); + MySQL_Conn(true); + } else { + logPrintf(logfile, "Server: %s:%s || Name: %s || Version: %s removed successfully.\n", ip, port, name, version); + } +} + +/* LIVE FUNCTIONS */ +void LIVE_AuthUser(UINT32 id, char *buffer) +{ + msg_live_auth_t *auth; + char escapedName[255]; + char saltedPassword[62]; + char hashedPassword[34]; + char namequery[1000]; + char namequeryp1[1000] = "SELECT username,userid,salt,password FROM `user` WHERE `username` = '%s' LIMIT 1"; + char userquery[1000]; + char userqueryp1[1000] = "SELECT userid,username,live_authkey,live_publickey FROM `user` WHERE `userid` = '%s' LIMIT 1"; + msg_t msg2; + char ip[32]; + int writecode; + msg2.type = LIVE_INVALID_USER; + + auth = (msg_live_auth_t *)buffer; + + logPrintf(logfile, "Got User %s Pass %s\n", auth->username, auth->password); + // retrieve the true ip of the server + strcpy(ip, server_socket.getClientIP(id)); + MySQL_Conn(false); + msg2.id = id; + logPrintf(logfile, "Check their ban status first... (ID %d)\n",id); + if(MySQL_CheckBan(ip,0,false,0)) + return; + mysql_real_escape_string(conn, escapedName, auth->username, (unsigned long)strlen(auth->username)); + sprintf(namequery, namequeryp1, escapedName); + logPrintf(mysqlfile, "Executing MySQL Query: %s\n", namequery); + if(mysql_query(conn, namequery)) { + logPrintf(errorfile, "MYSQL ERROR: %s\n", mysql_error(conn)); + MySQL_Conn(true); + } else { + res = mysql_store_result(conn); + if(mysql_num_rows(res) < 1) + { + logPrintf(logfile, "Invalid user: %s\n", auth->username); + msg2.type = LIVE_INVALID_USER; + } + else + { + row = mysql_fetch_row(res); + sprintf(saltedPassword, "%s%s", auth->password, row[2]); + logPrintf(logfile, "Pre-hash: %s (Salt is %s)\n", saltedPassword, row[2]); + sprintf(hashedPassword, md5(saltedPassword).c_str()); + logPrintf(logfile, "Got Hashed Password: %s\n", hashedPassword); + if(strcmp(hashedPassword, row[3]) != 0) + { + msg2.type = LIVE_INVALID_USER; + logPrintf(logfile, "INVALID USER!\n"); + } else { + msg2.type = LIVE_SEND_USER; + sprintf(userquery, userqueryp1, row[1]); + mysql_free_result(res); + logPrintf(mysqlfile, "Executing MySQL Query: %s\n", userquery); + if(mysql_query(conn, userquery)) { + logPrintf(errorfile, "MYSQL ERROR: %s\n", mysql_error(conn)); + MySQL_Conn(true); + } else { + res = mysql_store_result(conn); + if(mysql_num_rows(res) < 1) + { + logPrintf(errorfile, "User Information Error, invalid USER ID!\n"); + msg2.type = LIVE_INVALID_USER; + } else { + row = mysql_fetch_row(res); + msg_live_user_t *user = (msg_live_user_t *) msg2.buffer; + + user->header[0] = '\0'; // nothing interresting in it (for now) + user->uid = atoi(row[0]); + strcpy(user->username, row[1]); + logPrintf(logfile, "Found user: %s, id %s\n", row[1], row[0]); + logPrintf(logfile, "Sending User %s with ID %d\n", user->username, user->uid); + + msg2.length = sizeof (msg_live_user_t); + } + } + } + } + } + msg2.length = sizeof msg2.buffer; + msg2.room = 0; + logPrintf(logfile, "Sending message?\n"); + writecode = server_socket.write(&msg2); + logPrintf(logfile, "Message sent! :D\n"); + if (writecode < 0) + { + dbgPrintf(LIGHTRED, "Write error... %d client %d " + "deleted\n", writecode, id); + return; + } + mysql_free_result(res); +} + +/* +** sendServersInformations() +*/ +static void sendServersInformations(UINT32 id, UINT32 room) +{ + msg_t msg; + int writecode; + char ip[16]; + strcpy(ip, server_socket.getClientIP(id)); + (void)room; + logPrintf(logfile, "Sending servers informations\n"); + msg.id = id; + msg.type = SEND_SERVER_MSG; + msg.room = 0; + MySQL_ListServServers(id, SEND_SERVER_MSG, ip); // Awesome new MySQL Code! + msg.length = 0; + //dbgPrintf(CYAN, "Writing: (%d) %s\n", msg.length, ""); + writecode = server_socket.write(&msg); + if (writecode < 0) + { + dbgPrintf(LIGHTRED, "Write error... %d client %d deleted\n", + writecode, id); + } +} + +/* +** sendShortServersInformations() +*/ +static void sendShortServersInformations(UINT32 id, UINT32 room) +{ + msg_t msg; + int writecode; + char ip[16]; + strcpy(ip, server_socket.getClientIP(id)); + + logPrintf(logfile, "Sending short servers informations\n"); + msg.id = id; + msg.type = SEND_SHORT_SERVER_MSG; + MySQL_ListServers(id, SEND_SHORT_SERVER_MSG, ip, room); // New code that's full of win! + logPrintf(logfile, "Packet Room: %d\n", room); + msg.length = 0; + writecode = server_socket.write(&msg); + if (writecode < 0) + { + dbgPrintf(LIGHTRED, "Write error... %d client %d deleted\n", + writecode, id); + } +} + +/* +** sendRoomInformations() +*/ +static void sendRoomInformations(UINT32 id, UINT32 room, bool type) +{ + msg_t msg; + int writecode; + char ip[16]; + strcpy(ip, server_socket.getClientIP(id)); + (void)room; + logPrintf(logfile, "Sending room information\n"); + msg.id = id; + msg.type = SEND_ROOMS_MSG; + msg.room = 0; + MySQL_ListRooms(id, SEND_ROOMS_MSG, ip, type); // New code that's full of win! + msg.length = 0; + writecode = server_socket.write(&msg); + if (writecode < 0) + { + dbgPrintf(LIGHTRED, "Write error... %d client %d deleted\n", + writecode, id); + } +} + +/* +** sendVersionInformations() +*/ +static void sendVersionInformations(UINT32 id, UINT32 modid, char *modversion) +{ + msg_t msg; + int writecode; + char ip[16]; + strcpy(ip, server_socket.getClientIP(id)); + + logPrintf(logfile, "Sending version information\n"); + msg.id = id; + msg.type = SEND_VERSION_MSG; + msg.room = 0; + MySQL_CheckVersion(id, SEND_VERSION_MSG, ip, modid, modversion); // New code that's full of win! + msg.length = sizeof msg.buffer; + writecode = server_socket.write(&msg); + if (writecode < 0) + { + dbgPrintf(LIGHTRED, "Write error... %d client %d deleted\n", + writecode, id); + } +} + +/* +** addServer() +*/ +static void addServer(int id, char *buffer, bool firstadd) +{ + msg_server_t *info; + char oldversion = 0; + + //TODO: Be sure there is no flood from a given IP: + // If a host need more than 2 servers, then it should be registrated + // manually + + info = (msg_server_t *)buffer; + + // I want to be sure the informations are correct, of course! + info->port[sizeof (info->port)-1] = '\0'; + info->name[sizeof (info->name)-1] = '\0'; + info->version[sizeof (info->version)-1] = '\0'; + // retrieve the true ip of the server + strcpy(info->ip, server_socket.getClientIP(id)); + //strcpy(info->port, server_socket.getClientPort(id)); + + if (info->version[0] == '1' && + info->version[1] == '.' && + info->version[2] == '0' && + info->version[3] == '9' && + info->version[4] == '.') + { + if ((info->version[5] == '2') || (info->version[5] == '3')) + { + oldversion = 1; + } + } + + if (info->version[0] == '1' && + info->version[1] == '.' && + info->version[2] == '6' && + info->version[3] == '9' && + info->version[4] == '.' && + info->version[5] == '6') + { + oldversion = 1; + } + + if (!oldversion) + { + MySQL_AddServer(info->ip, info->port, info->name, info->version, info->room, firstadd, info->key); + } + else + { + logPrintf(logfile, "Not adding the temporary server: %s %s %s %s\n", info->ip, info->port, info->name, info->version); + } +} + +/* +** removeServer() +*/ +static void removeServer(int id, char *buffer) +{ + msg_server_t *info; + + info = (msg_server_t *)buffer; + + // I want to be sure the informations are correct, of course! + info->port[sizeof (info->port)-1] = '\0'; + info->name[sizeof (info->name)-1] = '\0'; + info->version[sizeof (info->version)-1] = '\0'; + + // retrieve the true ip of the server + strcpy(info->ip, server_socket.getClientIP(id)); + + logPrintf(logfile, "Removing the temporary server: %s %s %s %s\n", info->ip, info->port, info->name, info->version); + MySQL_RemoveServer(info->ip, info->port, info->name, info->version); // New and win. +} + +/* +** analyseUDP() +*/ +static int analyseUDP(size_t size, const char *buffer) +{ + // this would be the part of reading the PT_SERVERINFO packet, + // but i'm not about to backport that sloppy code + (void)size; + (void)buffer; + return INVALID_MSG; +} + +/* +** UDPMessage() +*/ +static int UDPMessage(size_t size, const char *buffer) +{ + if (size == 4) + { + return 0; + } + else if (size == sizeof(ms_holepunch_packet_t)) + { + return 0; + } + else if (size > 58) + { + dbgPrintf(LIGHTGREEN, "Got a UDP %d byte long message\n", size); + return analyseUDP(size, buffer); + } + else + return INVALID_MSG; +} + +/* +** analyseMessage() +*/ +static int analyseMessage(msg_t *msg) +{ + switch (msg->type) + { + case UDP_RECV_MSG: + return UDPMessage(msg->length, msg->buffer); + case ACCEPT_MSG: + break; + case ADD_SERVER_MSG: + addServer(msg->id, msg->buffer, true); + break; + case PING_SERVER_MSG: + addServer(msg->id, msg->buffer, false); + break; + case REMOVE_SERVER_MSG: + removeServer(msg->id, msg->buffer); + break; + case GET_SERVER_MSG: + sendServersInformations(msg->id, msg->room); + break; + case GET_SHORT_SERVER_MSG: + sendShortServersInformations(msg->id, msg->room); + break; + case GET_ROOMS_MSG: + sendRoomInformations(msg->id, msg->room, 0); + break; + case GET_ROOMS_HOST_MSG: + sendRoomInformations(msg->id, msg->room, 1); + break; + case GET_VERSION_MSG: + sendVersionInformations(msg->id, msg->room, msg->buffer); + break; + case LIVE_AUTH_USER: + LIVE_AuthUser(msg->id, msg->buffer); + break; + default: + return INVALID_MSG; + } + return 0; +} + +/* +** main() +*/ +int main(int argc, char *argv[]) +{ + msg_t msg; +#ifdef __unix__ + pid_t pid; + char pidstr[12]; +#endif + + if (argc <= 1) + { + fprintf(stderr, "usage: %s port\n", argv[0]); + exit(1); + } + + if (server_socket.listen(argv[1]) < 0) + { + fprintf(stderr, "Error while initializing the server\n"); + exit(2); + } + + logfile = openFile("server.log"); + errorfile = openFile("error.log"); + mysqlfile = openFile("mysql.log"); + sockfile = openFile("sockets.log"); + MySQL_Conn(false); +#if !defined (DEBUG) && defined (__unix__) + pid = fork(); + switch (pid) + { + case 0: break; // child + case -1: printf("Error while launching the server in background\n"); return -1; + default: + pidfile = fopen("msd.pid", "w+"); + sprintf(pidstr, "%d", pid); + fputs(pidstr, pidfile); + fclose(pidfile); + return 0; // parent: keep child in background + } +#endif + srand((unsigned)time(NULL)); // Alam: GUIDs + for (;;) + { + memset(&msg, 0, sizeof (msg)); // remove previous message + if (!server_socket.read(&msg)) + { + // valid message: header message seems ok + analyseMessage(&msg); + //servers_list.show(); // for debug purpose + } + } + +#ifndef _MSC_VER + /* NOTREACHED */ + return 0; +#endif +} diff --git a/tools/masterserver/srvlist.cpp b/tools/masterserver/srvlist.cpp new file mode 100644 index 000000000..c9a6feea9 --- /dev/null +++ b/tools/masterserver/srvlist.cpp @@ -0,0 +1,405 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright (C) 2000 by DooM Legacy Team. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +//----------------------------------------------------------------------------- + +#ifdef __GNUC__ +#include +#endif +#include +#include "common.h" +#include "srvlist.h" + +//============================================================================= + +/* +** +*/ +CList::CList() +{ + list = NULL; + current = NULL; +} + +/* +** +*/ +CList::~CList() +{ + CItem *p; + + while (list) + { + p = list; + list = list->next; + delete(p); + } +} + +/* +** +*/ +int CList::insert(CItem *item) +{ + item->next = list; + list = item; + return 0; +} + +/* +** +*/ +int CList::remove(CItem *item) +{ + CItem *position, *q; + + q = NULL; + position = list; + + while (position && (position != item)) + { + q = position; + position = position->next; + } + if (position) + { + if (q) + q->next = position->next; + else + list = position->next; + delete position; + + return 1; + } + + return 0; +} + +/* +** +*/ +CItem *CList::getFirst() +{ + current = list; + return current; +} + +/* +** +*/ +CItem *CList::getNext() +{ + if (current) + current = current->next; + return current; +} + +/* +** +*/ +void CList::show() +{ + CItem *p; + + p = list; + while (p) + { + p->print(); + p = p->next; + } +} + +//============================================================================= + +/* +** +*/ +CItem::CItem() +{ + next = NULL; +} + +//============================================================================= + +/* +** +*/ +CInetAddr::CInetAddr(const char *ip, const char *port) +{ + strcpy(this->ip, ip); + strcpy(this->port, port); + PortNotChanged = true; +} + +/* +** +*/ +const char *CInetAddr::getIP() +{ + return ip; +} + +/* +** +*/ +const char *CInetAddr::getPort() +{ + return port; +} + +/* +** +*/ +bool CInetAddr::setPort(const char *port) +{ + if (PortNotChanged) + { + strcpy(this->port, port); + PortNotChanged = false; + } + return !PortNotChanged; +} + +//============================================================================= + +/* +** +*/ +CPlayerItem::CPlayerItem(const char *ip, const char *port, + const char *nickname) : CInetAddr(ip, port) +{ + strcpy(this->nickname, nickname); +} + +/* +** +*/ +void CPlayerItem::print() +{ + dbgPrintf(GREEN, "\tIP\t\t: %s\n\tPort\t\t: %s\n\tNickname\t: %s\n", + ip, port, nickname); +} + +/* +** +*/ +char *CPlayerItem::getString() +{ + static char tmpbuf[1024]; + + snprintf(tmpbuf, sizeof tmpbuf, + "\tIP\t\t: %s\n\tPort\t\t: %s\n\tNickname\t: %s\n", + ip, port, nickname); + return tmpbuf; +} + +//============================================================================= + +/* +** +*/ +CServerItem::CServerItem(const char *ip, const char *port, const char *hostname, const char *version, ServerType type) : CInetAddr(ip, port) +{ + time_t timenow = time(NULL); + const tm *timeGMT = gmtime(&timenow); + // check name of server here + strcpy(this->hostname, hostname); + strcpy(this->version, version); + this->type = type; + strftime(reg_time, REG_TIME_SIZE+1, "%Y-%m-%dT%H:%MZ",timeGMT); + { + int i; + memset(guid,'\0',GUID_SIZE); + strcpy(&guid[0], ip); + strcpy(&guid[15], port); // GenUID + for (i = 0; i <= GUID_SIZE-1; i++) + { + if (guid[i] == '\0' || guid[i] == '.') + guid[i] = '0' + (rand()/(RAND_MAX/15)); + if (guid[i] > '9') + guid[i] += 'A'-'9'; + } + guid[GUID_SIZE] = '\0'; + } + + HeartBeat = time(NULL); +} + +/* +** +*/ +void CServerItem::print() +{ + dbgPrintf(GREEN, "IP\t\t: %s\nPort\t\t: %s\nHostname\t: %s\nVersion\t: %s\nPermanent\t: %s\n", + ip, port, hostname, version, (type == ST_PERMANENT) ? "Yes" : "No"); +} + +/* +** +*/ +const char *CServerItem::getString() +{ + static char tmpbuf[1024]; + + snprintf(tmpbuf, sizeof tmpbuf, + "IP\t\t: %s\nPort\t\t: %s\nHostname\t: %s\nVersion\t\t: %s\nPermanent\t: %s\n", + ip, port, hostname, version, (type==ST_PERMANENT) ? "Yes" : "No"); + return tmpbuf; +} + +/* +** +*/ +const char *CServerItem::getName() +{ + return hostname; +} + +/* +** +*/ +const char *CServerItem::getVersion() +{ + return version; +} + +/* +** +*/ +const char *CServerItem::getGuid() +{ + return guid; +} + +/* +** +*/ +const char *CServerItem::getRegtime() +{ + return reg_time; +} + +/* +** +*/ +//============================================================================= + +/* +** +*/ +void CServerList::insertPlayer(CServerItem *server, CPlayerItem *player) +{ + server->players_list.insert(player); +} + +/* +** +*/ +void CServerList::removePlayer(CServerItem *server, CPlayerItem *player) +{ + server->players_list.remove(player); +} + +/* +** +*/ +int CServerList::insert(CServerItem *server) +{ + CList::insert((CItem *)server); + return 0; +} + +/* +** +*/ +int CServerList::insert(const char *ip, const char *port, + const char *hostname, const char *version, ServerType type) +{ + CServerItem *server; + + server = new CServerItem(ip, port, hostname, version, type); + CList::insert(server); + return 0; +} + +/* +** +*/ +int CServerList::remove(CServerItem *server) +{ + return CList::remove((CItem *)server); +} + +/* +** +*/ +int CServerList::remove(const char *ip, const char *port, + const char *hostname, const char *version, ServerType type) +{ + // TODO + CServerItem *position, *q; + bool match; + + (void)hostname; + (void)port; + + match = false; + position = (CServerItem *)list; + q = NULL; + + while (position && !match) + { + if (strcmp(position->ip, ip) == 0 + && strcmp(position->version, version) == 0 + && strcmp(position->port, port) == 0 + && position->type == type) + { + match = true; + } + else + { + q = position; + position = (CServerItem *)position->next; + } + } + if (position && match) + { + if (q) + q->next = position->next; + else + list = position->next; + delete position; + + return 1; + } + + return 0; +} + +/* +** +*/ +void CServerList::show() +{ + CServerItem *p; + + p = (CServerItem *)list; + while (p) + { + p->print(); + p->players_list.show(); + p = (CServerItem *)p->next; + } +} diff --git a/tools/masterserver/srvlist.h b/tools/masterserver/srvlist.h new file mode 100644 index 000000000..aa582ff8b --- /dev/null +++ b/tools/masterserver/srvlist.h @@ -0,0 +1,136 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright (C) 2000 by DooM Legacy Team. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +//----------------------------------------------------------------------------- + +#ifndef SRVLIST_H +#define SRVLIST_H + +#include + +enum ServerType +{ + ST_PERMANENT = 0, + ST_TEMPORARY, +}; + +//============================================================================= + +class CItem +{ + friend class CList; +protected: + CItem *next; +public: + CItem(); + virtual ~CItem() {}; // destructor must exist and be virtual + virtual void print() = 0; +}; + +//============================================================================= + +class CList +{ +protected: + CItem *list; + CItem *current; // the current item we are pointing on (for getfirst/getnext) +public: + CList(); + virtual ~CList(); + int insert(CItem *); + int remove(CItem *); + CItem *getFirst(); + CItem *getNext(); + void show(); +}; + +//============================================================================= + +class CInetAddr +{ +protected: + char ip[16]; + char port[8]; + bool PortNotChanged; +public: + CInetAddr(const char *ip, const char *port); + const char *getIP(); + bool setPort(const char *port); + const char *getPort(); +}; + +//============================================================================= + +class CPlayerItem : public CItem, public CInetAddr +{ +friend class CPlayerList; +private: + char nickname[32]; +public: + CPlayerItem(const char *ip, const char *port, const char *nickname); + void print(); + char *getString(); +}; + +//============================================================================= + +class CPlayerList : public CList +{ +}; + +//============================================================================= + +#define REG_TIME_SIZE 24 //1970-00-00T00:00:00.0+00:00 +#define GUID_SIZE 24-1 // format is 12700000000105000 + +class CServerItem : public CItem, public CInetAddr +{ + friend class CServerList; + +private: + char hostname[32]; + char version[8]; // format is: x.yy.z (like 1.30.2 or 1.31) + CPlayerList players_list; + char reg_time[REG_TIME_SIZE]; + char guid[GUID_SIZE+1]; + +public: + ServerType type; + time_t HeartBeat; + + CServerItem(const char *ip, const char *port, const char *hostname, const char *version, ServerType type); + void print(); + const char *getString(); + const char *getName(); + const char *getVersion(); + const char *getRegtime(); + const char *getGuid(); +}; + +//============================================================================= + +class CServerList : public CList +{ +public: + void insertPlayer(CServerItem *server, CPlayerItem *player); + void removePlayer(CServerItem *server, CPlayerItem *player); + int insert(const char *ip, const char *port, const char *hostname, const char *version, ServerType type); + int insert(CServerItem *server); + int remove(const char *ip, const char *port, const char *hostname, const char *version, ServerType type); + int remove(CServerItem *server); + void show(); +}; + +#endif diff --git a/tools/masterserver/stats.cpp b/tools/masterserver/stats.cpp new file mode 100644 index 000000000..741d82699 --- /dev/null +++ b/tools/masterserver/stats.cpp @@ -0,0 +1,147 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright (C) 2000 by DooM Legacy Team. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +//----------------------------------------------------------------------------- + +#ifdef __GNUC__ +#include +#endif +#include // strcat(),... +#include "common.h" +#include "ipcs.h" +#include "stats.h" + +//============================================================================= + +/* +** CServerStats() +*/ +CServerStats::CServerStats() +{ + uptime = time(NULL); + num_connections = 0; + num_http_con = 0; + num_servers = 0; + snprintf(motd, sizeof motd, "%s%s", "Welcome to the SRB2 Master Server!
", SERVERMOTDTEXT); + num_add = 0; + num_removal = 0; + num_retrieval = 0; + num_autoremoval = 0; + num_badconnection = 0; + for (int i = 0; i < NUMLASTSERVERS; i++) + { + strcpy(last_server[i].ip, "0.0.0.0"); + strcpy(last_server[i].name, "Non-Existing SRB2 server"); + strcpy(last_server[i].version, "0.0.0"); + } + snprintf(version, sizeof version, "%s %s", __DATE__, __TIME__); +} + +/* +** ~CServerStats() +*/ +CServerStats::~CServerStats() +{ +} + +/* +** getUptime() +*/ +const char *CServerStats::getUptime() +{ + char *res = ctime(&uptime); + res[strlen(res)-1] = '\0'; // remove the '\n' at the end + return res; +} + +/* +** getHours() +*/ +int CServerStats::getHours() +{ + return (int)(((time(NULL) - uptime)/(60*60))%24); +} + +/* +** getDays() +*/ +int CServerStats::getDays() +{ + return (int)((time(NULL) - uptime)/(60*60*24)); +} + +/* +** getMotd() +*/ +const char *CServerStats::getMotd() +{ + return motd; +} + +/* +** getLastServers() +*/ +const char *CServerStats::getLastServers() +{ + static char res[170*NUMLASTSERVERS]; + + tzset(); + res[0] = '\0'; + for (int i = 0; i < NUMLASTSERVERS; i++) + { + char str[170]; + char *ct; + + ct = ctime(&last_time[i]); + ct[strlen(ct)-1] = '\0'; // replace \n with a \0 + snprintf(str, sizeof str, + "Address: %15s Name: %-31s v%-7s (%s %s)\n000043210000", + last_server[i].ip, last_server[i].name, last_server[i].version, ct, tzname[0]); + strcat(res, str); + } + + return res; +} + +/* +** getVersion() +*/ +const char *CServerStats::getVersion() +{ + return version; +} + +/* +** putMotd() +*/ +void CServerStats::putMotd(char *motd) +{ + strcpy(this->motd, motd); +} + +/* +** putLastServer(): +*/ +void CServerStats::putLastServer(msg_server_t *server) +{ + for (int i = NUMLASTSERVERS-1; i > 0; i--) + { + memcpy(&last_server[i], &last_server[i-1], + sizeof (msg_server_t)); + last_time[i] = last_time[i-1]; + } + memcpy(&last_server[0], server, sizeof (msg_server_t)); + last_time[0] = time(NULL); +} diff --git a/tools/masterserver/stats.h b/tools/masterserver/stats.h new file mode 100644 index 000000000..4494a76f9 --- /dev/null +++ b/tools/masterserver/stats.h @@ -0,0 +1,68 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright (C) 2000 by DooM Legacy Team. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +//----------------------------------------------------------------------------- + +#ifndef _STATS_H_ +#define _STATS_H_ +#ifndef _IPCS_H_ +#error "You forget to include ipcs.h" +#endif +#include + +#define NUMLASTSERVERS 6 +#define SERVERMOTDTEXT "No Clans, advertising websites, Chat, Hangout, Hacked, or Role Playing Servers Allowed" + + +// ================================ DEFINITIONS =============================== + +class CServerStats +{ + time_t uptime; // master server uptime + char motd[2048]; // increase that if not enough + msg_server_t last_server[NUMLASTSERVERS]; // keep last 6 named registered servers + time_t last_time[NUMLASTSERVERS]; // keep date/time of registration of those servers + char version[32]; // master server version + +public: + int num_connections; + int num_http_con; + int num_text_con; + int num_RSS92_con; + int num_RSS10_con; + int num_servers; + int num_add; + int num_removal; + int num_retrieval; + int num_autoremoval; + int num_badconnection; + + CServerStats(); + ~CServerStats(); + const char *getUptime(); + int getHours(); + int getDays(); + const char *getMotd(); + const char *getLastServers(); + const char *getVersion(); + void putMotd(char *); + void putLastServer(msg_server_t *); +}; + +// ================================== PROTOS ================================== + +// ================================== EXTERNS ================================= + +#endif diff --git a/tools/srb2msns/elements/srb2ms.RDF b/tools/srb2msns/elements/srb2ms.RDF new file mode 100644 index 000000000..46b3c81f0 --- /dev/null +++ b/tools/srb2msns/elements/srb2ms.RDF @@ -0,0 +1,36 @@ + + + + + +]> + + +The SRB2MS Element Set namespace providing access +to its content by means of an RDF Schema +Logan Arias +The SRB2MS Element Set namespace provides +URIs for the SRB2MS Elements. Entries are declared using RDF Schema language +to support RDF applications. +English + + +Address +The IPv4 address of the server item. + + + + +Port +The Port number of the server item. + + + + +Version +Version number of the server item. + + + + diff --git a/tools/wadconv/Makefile b/tools/wadconv/Makefile new file mode 100644 index 000000000..d11fbf6ce --- /dev/null +++ b/tools/wadconv/Makefile @@ -0,0 +1,140 @@ +#!/usr/bin/env make -f + +## wadconv: SRB2 WAD Converter. +## Copyright (C) 2011 by Callum Dickinson. +# +## This program is free software; you can redistribute it and/or +## modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either version 2 +## of the License, or (at your option) any later version. +# +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. + +# Program name. +PRONAME = wadconv +# Program version. +PROVER = 1.0.0 + +# Program default options. +CPPFLAGS += -DPRONAME="$(PRONAME)" -DPROVER="$(PROVER)" + +# Source files and directory. +SRC = wadconv.c + +# Required libraries. +LIB = -lwad + +# +## Variables that shouldn't be edited unless +## you know what you are doing start here. +# + +# Makefile pretty text output variables. +PRCC = CC +PRINSTALL=INSTALL +PRCLEAN = CLEAN + +# Library name prefix. +LIBPFX = lib + +# Library installation directory. +PREFIX ?= /usr/local +LIBDIR := $(PREFIX)/lib +INCLUDE := $(PREFIX)/include + +# Variables created during compilation. +OBJ = $(SRC:.c=.o) +DEP = $(PRONAME).d +ifdef MINGW +BIN = $(PRONAME).exe +else +BIN = $(PRONAME) +endif + +# Compilation programs. +ECHO := echo +RM := rm -rf +FIND := find +GREP := grep +INSTALLX:= install -m 755 +FOR := for +SED := sed +CC := $(CROSS_COMPILE)$(CC) + +# Shell programs. +SHECHO := $(ECHO) +SHFIND := $(FIND) +SHGREP := $(GREP) +SHINSTALL:= $(INSTALL) +SHSED := $(SED) +SHCC := $(CC) + +# Quiet compiling programs during pretty text output. +NULL := /dev/null 2>&1 +ECHO := @$(ECHO) +ifndef V +RM := @$(RM) +LDCONFIG:= @$(LDCONFIG) +FIND := @$(FIND) +GREP := @$(GREP) +INSTALL := @$(INSTALL) +MKDIR := @$(MKDIR) +FOR := @$(FOR) +SED := @$(SED) +CC := @$(CC) +endif + +# Compiler default flags. +ifdef DEBUG +CFLAGS += -g -O0 -Wall +else +CFLAGS += -O3 +endif + +# Linker flags. +#LDFLAGS += + +# +## Makefile targets. +# + +all: $(DEP) $(BIN) + +$(DEP): $(SRC) +ifndef V + $(ECHO) " $(PRCC)$@" +endif + -$(RM) $@ + $(FOR) f in $(SRC); do \ + $(SHCC) $(CPPFLAGS) $(CFLAGS) -MM $$f >> $@; \ + done +-include $@ + +%.o: %.c +ifndef V + $(ECHO) " $(PRCC)$@" +endif + $(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@ + +$(BIN): $(OBJ) +ifndef V + $(ECHO) " $(PRCC)$@" +endif + $(CC) $(LDFLAGS) -o $@ $(OBJ) $(LIB) + +install: all +ifndef V + $(SHECHO) " $(PRINSTALL)$(BIN)" +endif + $(INSTALLX) $(BIN) $(INSTALLDIR) + +clean: +ifndef V + $(ECHO) " $(PRCLEAN)$(BIN) $(OBJ) $(DEP)" +endif + -$(RM) $(BIN) $(OBJ) $(DEP) + +.PHONY : all install clean diff --git a/tools/wadconv/wadconv.c b/tools/wadconv/wadconv.c new file mode 100644 index 000000000..4e9565118 --- /dev/null +++ b/tools/wadconv/wadconv.c @@ -0,0 +1,282 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// SRB2 WAD Converter +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +//----------------------------------------------------------------------------- +/// \file wadconv.c +/// \brief Converts wads made for version 2.0 to 2.1. + +#include +#include +#include +#include +#include "wad.h" + +// +// Texture definition. +// Each texture is composed of one or more patches, +// with patches being lumps stored in the WAD. +// The lumps are referenced by number, and patched +// into the rectangular texture space using origin +// and possibly other attributes. +// +typedef struct +{ + wad_int16_t originx, originy; + wad_int16_t patch, stepdir, colormap; +} mappatch_t; + +// +// Texture definition. +// An SRB2 wall texture is a list of patches +// which are to be combined in a predefined order. +// +typedef struct +{ + char name[8]; + wad_int32_t masked; + wad_int16_t width; + wad_int16_t height; + wad_int32_t columndirectory; // FIXTHIS: OBSOLETE + wad_int16_t patchcount; + mappatch_t patches[1]; +} maptexture_t; + +// A single patch from a texture definition, +// basically a rectangular area within +// the texture rectangle. +typedef struct +{ + // Block origin (always UL), which has already accounted for the internal origin of the patch. + wad_uint16_t originx, originy; + lump_t *patch; +} texpatch_t; + +// A maptexturedef_t describes a rectangular texture, +// which is composed of one or more mappatch_t structures +// that arrange graphic patches. +typedef struct +{ + // Keep name for switch changing, etc. + char name[8]; + wad_int16_t width, height; + + // All the patches[patchcount] are drawn back to front into the cached texture. + wad_uint16_t patchcount; + texpatch_t patches[1]; +} texture_t; + +static void ConvertTextures(wad_t *wad) +{ + wad_uint32_t i, j; + lump_t *l; + // PNAMES lump. + char pname[9]; + char *pnamesdata; + lump_t *pnames, **patchlookup; + wad_uint32_t numpatches; + // TEXTURE lump. + lump_t *texturex = NULL; + texture_t **textures; + texpatch_t *patch; + maptexture_t *mtexture; + mappatch_t *mpatch; + wad_uint32_t *directory, *maptex, numtextures, offset; + size_t maxoffset; + // TX_START. + lump_t *tx_start; + + // PNAMES. + if (!(pnames = WAD_CacheLumpInWADByName(wad, "PNAMES"))) + { + printf("error caching lump: %s\n", WAD_Error()); + exit(EXIT_FAILURE); + } + + pnamesdata = pnames->data + 4; + + memcpy(&numpatches, pnames->data, sizeof(wad_uint32_t)); + numpatches = WAD_INT32_Endianness(numpatches); + + if (!(patchlookup = malloc(sizeof(*patchlookup) * numpatches))) + { + printf("unable to allocate patchlookup array for wad %s\n", WAD_BaseName(wad->filename)); + exit(EXIT_FAILURE); + } + + pname[8] = '\0'; + for (i = 0; i < numpatches; i++) + { + strncpy(pname, pnamesdata+i*8, 8); + patchlookup[i] = WAD_LumpInWADByName(wad, pname); + } + + WAD_UncacheLump(pnames); + + // TEXTURE. + + for (i = 1; (texturex = WAD_LumpInWADByName(wad, WAD_VA("TEXTURE%i", i))); i++) + if (texturex) + break; + + texturex = WAD_CacheLump(texturex); + maptex = (wad_uint32_t *)texturex->data; + numtextures = WAD_INT32_Endianness(*maptex); + maxoffset = WAD_LumpSize(texturex); + directory = maptex + 1; + textures = malloc(sizeof(*textures) * numtextures); + + for (i = 0; i < numtextures; i++, directory++) + { + memcpy(&offset, directory, sizeof(wad_uint32_t)); + offset = WAD_INT32_Endianness(offset); + + if (offset > maxoffset) + { + printf("bad texture directory for wad %s\n", WAD_BaseName(wad->filename)); + exit(EXIT_FAILURE); + } + + mtexture = (maptexture_t *)((wad_uint8_t *)maptex + offset); + textures[i] = malloc(sizeof(texture_t) + (sizeof(texpatch_t) * (WAD_INT16_Endianness(mtexture->patchcount) - 1))); + + memcpy(textures[i]->name, mtexture->name, sizeof(textures[i]->name)); + textures[i]->width = WAD_INT16_Endianness(mtexture->width); + textures[i]->height = WAD_INT16_Endianness(mtexture->height); + textures[i]->patchcount = WAD_INT16_Endianness(mtexture->patchcount); + + mpatch = &mtexture->patches[0]; + patch = &textures[i]->patches[0]; + + for (j = 0; j < textures[i]->patchcount; j++, mpatch++, patch++) + { + patch->originx = WAD_INT16_Endianness(mpatch->originx); + patch->originy = WAD_INT16_Endianness(mpatch->originy); + patch->patch = patchlookup[WAD_INT16_Endianness(mpatch->patch)]; + if (!patch->patch) + printf("missing patch in texture %s in wad %s\n", textures[i]->name, wad->filename); + } + } + + WAD_UncacheLump(texturex); + + if (!(tx_start = WAD_LumpInWADByName(wad, "TX_START"))) + { + if (WAD_LumpInWADByName(wad, "P_END")) + tx_start = WAD_AddLumpInWADByNum(wad, WAD_LumpNumByName("P_END") + 1, "TX_START", NULL); + else + tx_start = WAD_AddLump(wad, NULL, "TX_START", NULL); + + if (!tx_start) + { + printf("unable to find TX_START in %s\n", wad->filename); + exit(EXIT_FAILURE); + } + } + WAD_RemoveLumpInWADByName(wad, "TX_END"); + + for (i = 0, l = WAD_LumpInWADByNum(wad, WAD_LumpNum(tx_start) + 1); i < numtextures; i++, directory++) + { + if (textures[i]->patchcount == 1 && !strncmp(textures[i]->name, textures[i]->patches[0].patch->name, 8)) + WAD_MoveLump(textures[i]->patches[0].patch, l); + else + { + FILE *socfile; + char *soc, *socname = textures[i]->name; + + for (j = 0; j < textures[i]->patchcount; j++) + { + if (!strncmp(textures[i]->name, textures[i]->patches[j].patch->name, 8)) + { + wad_int32_t k; + char socname1[5]; + + socname = malloc(sizeof(*socname) * 9); + + socname1[4] = '\0'; + strncpy(socname1, textures[i]->name, 4); + + for (k = 0 ;; k++) + if (!WAD_LumpInWADByName(wad, WAD_VA((k > 9) ? "%sSC%i" : "%sSC0%i", socname1, k))) + break; + + sprintf(socname, (k > 9) ? "%sSC%i" : "%sSC0%i", socname1, k); + break; + } + } + + soc = WAD_VA("%s%s", socname, ".lmp"); + + remove(soc); + socfile = fopen(soc, "wb"); + + fprintf(socfile, "TEXTURE %s\n", textures[i]->name); + fprintf(socfile, "WIDTH = %i\n", textures[i]->width); + fprintf(socfile, "HEIGHT = %i\n", textures[i]->height); + fprintf(socfile, "NUMPATCHES = %i\n\n", textures[i]->patchcount); + + for (j = 0; j < textures[i]->patchcount; j++) + { + fprintf(socfile, "PATCH %s\n", textures[i]->patches[j].patch->name); + fprintf(socfile, "X = %i\n", textures[i]->patches[j].originx); + fprintf(socfile, "Y = %i\n\n", textures[i]->patches[j].originy); + } + + fclose(socfile); + + WAD_AddLump(wad, l, socname, soc); + remove(soc); + } + } + WAD_AddLump(wad, l, "TX_END", NULL); + + WAD_RemoveLump(pnames); + WAD_RemoveLump(texturex); +} + +int main(int argc, char **argv) +{ + wad_t *w; + wad_uint32_t i; + + if (argc < 2) + { + puts("Usage: wadconv [filename]"); + puts("Example: wadconv wadfile.wad"); + return EXIT_FAILURE; + } + + // Open the WAD files. + for (i = 1; i < (unsigned)argc; i++) + { + if (!WAD_OpenWAD(argv[i])) + { + printf("Loading WAD failed: %s\n", WAD_Error()); + return EXIT_FAILURE; + } + } + + for (i = 0; i < wad_numwads; i = WAD_WADLoopAdvance(i)) + { + w = WAD_WADByNum(i); + // Convert textures. + printf("Converting textures for wad %s...\n", WAD_BaseName(w->filename)); + ConvertTextures(w); + } + + for (i = 0; i < wad_numwads; i = WAD_WADLoopAdvance(i)) + WAD_SaveCloseWADByNum(i); + + puts("Finished."); + return EXIT_SUCCESS; +} diff --git a/tools/wadzip/err.c b/tools/wadzip/err.c new file mode 100644 index 000000000..37393bfcb --- /dev/null +++ b/tools/wadzip/err.c @@ -0,0 +1,121 @@ +#if defined (__WIN32) || defined (WIN32) +#define NEED_ERR +#define LACK_PROGNAME +#define NEED_ENDIAN_STUBS +#define LACK_SYSTYPES +#endif + +#ifdef NEED_ERR + +/* + * Implementation of the err/errx/verr/verrx/warn/warnx/vwarn/vwarnx + * functions from BSD. + * + * This file is public-domain; anyone may deal in it without restriction. + * + * Written by Graue on January 16, 2006. + */ + +/* +err/warn family of functions cheat sheet: + +Print: + last component of program name + [ if fmt is non-NULL + ": " + the formatted error message + ] + [ if function name does not end in x + ": " + strerror(errno) + ] + newline + +Then if function name has "err" in it, quit with exit code `eval'. + +BSD's -x versions actually print ": " at the end if passed NULL, so I +duplicate that behavior. Passing these functions NULL is kind of useless +though. +*/ + +#include +#include +#include +#include +#include + +#ifdef LACK_PROGNAME +char *__progname = "wadzip"; +#else +extern char *__progname; +#endif + +#define progname __progname + +void vwarn(const char *fmt, va_list args) +{ + fputs(progname, stderr); + if (fmt != NULL) + { + fputs(": ", stderr); + vfprintf(stderr, fmt, args); + } + fputs(": ", stderr); + fputs(strerror(errno), stderr); + putc('\n', stderr); +} + +void vwarnx(const char *fmt, va_list args) +{ + fputs(progname, stderr); + fputs(": ", stderr); + if (fmt != NULL) + vfprintf(stderr, fmt, args); + putc('\n', stderr); +} + +void verr(int eval, const char *fmt, va_list args) +{ + vwarn(fmt, args); + exit(eval); +} + +void verrx(int eval, const char *fmt, va_list args) +{ + vwarnx(fmt, args); + exit(eval); +} + +void warn(const char *fmt, ...) +{ + va_list argptr; + va_start(argptr, fmt); + vwarn(fmt, argptr); + va_end(argptr); +} + +void warnx(const char *fmt, ...) +{ + va_list argptr; + va_start(argptr, fmt); + vwarnx(fmt, argptr); + va_end(argptr); +} + +void err(int eval, const char *fmt, ...) +{ + va_list argptr; + va_start(argptr, fmt); + verr(eval, fmt, argptr); + /* NOTREACHED, so don't worry about va_end() */ +} + +void errx(int eval, const char *fmt, ...) +{ + va_list argptr; + va_start(argptr, fmt); + verrx(eval, fmt, argptr); + /* NOTREACHED, so don't worry about va_end() */ +} + +#endif diff --git a/tools/wadzip/err.h b/tools/wadzip/err.h new file mode 100644 index 000000000..5b9380379 --- /dev/null +++ b/tools/wadzip/err.h @@ -0,0 +1,26 @@ +#if defined (__WIN32) || defined (WIN32) +#define NEED_ERR +#endif + +#ifndef NEED_ERR +#include /* system version of this file */ +#else + +#ifndef _ERR_H +#define _ERR_H + +#include + +void err (int eval, const char *fmt, ...); +void errx (int eval, const char *fmt, ...); +void verr (int eval, const char *fmt, va_list args); +void verrx (int eval, const char *fmt, va_list args); + +void warn ( const char *fmt, ...); +void warnx( const char *fmt, ...); +void vwarn ( const char *fmt, va_list args); +void vwarnx( const char *fmt, va_list args); + +#endif + +#endif diff --git a/tools/wadzip/lzf.h b/tools/wadzip/lzf.h new file mode 100644 index 000000000..8538609ab --- /dev/null +++ b/tools/wadzip/lzf.h @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2000-2005 Marc Alexander Lehmann + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, 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. The name of the author may not 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 MER- + * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- + * CIAL, 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 OTH- + * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Alternatively, the contents of this file may be used under the terms of + * the GNU General Public License version 2 (the "GPL"), in which case the + * provisions of the GPL are applicable instead of the above. If you wish to + * allow the use of your version of this file only under the terms of the + * GPL and not to allow others to use your version of this file under the + * BSD license, indicate your decision by deleting the provisions above and + * replace them with the notice and other provisions required by the GPL. If + * you do not delete the provisions above, a recipient may use your version + * of this file under either the BSD or the GPL. + */ + +#ifndef LZF_H +#define LZF_H + +/*********************************************************************** +** +** lzf -- an extremely fast/free compression/decompression-method +** http://liblzf.plan9.de/ +** +** This algorithm is believed to be patent-free. +** +***********************************************************************/ + +#define LZF_VERSION 0x0105 /* 1.5 */ + +/* + * Compress in_len bytes stored at the memory block starting at + * in_data and write the result to out_data, up to a maximum length + * of out_len bytes. + * + * If the output buffer is not large enough or any error occurs + * return 0, otherwise return the number of bytes used (which might + * be considerably larger than in_len, so it makes sense to always + * use out_len == in_len - 1), to ensure _some_ compression, and store + * the data uncompressed otherwise. + * + * lzf_compress might use different algorithms on different systems and + * even diferent runs, thus might result in different compressed strings + * depending on the phase of the moon or similar factors. However, all + * these strings are architecture-independent and will result in the + * original data when decompressed using lzf_decompress. + * + * The buffers must not be overlapping. + * + * If the option LZF_STATE_ARG is enabled, an extra argument must be + * supplied which is not reflected in this header file. Refer to lzfP.h + * and lzf_c.c. + * + */ +unsigned int +lzf_compress (const void *const in_data, unsigned int in_len, + void *out_data, unsigned int out_len); + +/* + * Decompress data compressed with some version of the lzf_compress + * function and stored at location in_data and length in_len. The result + * will be stored at out_data up to a maximum of out_len characters. + * + * If the output buffer is not large enough to hold the decompressed + * data, a 0 is returned and errno is set to E2BIG. Otherwise the number + * of decompressed bytes (i.e. the original length of the data) is + * returned. + * + * If an error in the compressed data is detected, a zero is returned and + * errno is set to EINVAL. + * + * This function is very fast, about as fast as a copying loop. + */ +unsigned int +lzf_decompress (const void *const in_data, unsigned int in_len, + void *out_data, unsigned int out_len); + +#endif + diff --git a/tools/wadzip/lzfP.h b/tools/wadzip/lzfP.h new file mode 100644 index 000000000..4d5a21e3c --- /dev/null +++ b/tools/wadzip/lzfP.h @@ -0,0 +1,169 @@ +/* + * Copyright (c) 2000-2005 Marc Alexander Lehmann + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, 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. The name of the author may not 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 MER- + * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- + * CIAL, 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 OTH- + * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Alternatively, the contents of this file may be used under the terms of + * the GNU General Public License version 2 (the "GPL"), in which case the + * provisions of the GPL are applicable instead of the above. If you wish to + * allow the use of your version of this file only under the terms of the + * GPL and not to allow others to use your version of this file under the + * BSD license, indicate your decision by deleting the provisions above and + * replace them with the notice and other provisions required by the GPL. If + * you do not delete the provisions above, a recipient may use your version + * of this file under either the BSD or the GPL. + */ + +#ifndef LZFP_h +#define LZFP_h + +#define STANDALONE 1 /* at the moment, this is ok. */ + +#ifndef STANDALONE +# include "lzf.h" +#endif + +/* + * Size of hashtable is (1 << HLOG) * sizeof (char *) + * decompression is independent of the hash table size + * the difference between 15 and 14 is very small + * for small blocks (and 14 is usually a bit faster). + * For a low-memory/faster configuration, use HLOG == 13; + * For best compression, use 15 or 16 (or more). + */ +#ifndef HLOG +# define HLOG 15 +#endif + +/* + * Sacrifice very little compression quality in favour of compression speed. + * This gives almost the same compression as the default code, and is + * (very roughly) 15% faster. This is the preferable mode of operation. + */ + +#ifndef VERY_FAST +# define VERY_FAST 1 +#endif + +/* + * Sacrifice some more compression quality in favour of compression speed. + * (roughly 1-2% worse compression for large blocks and + * 9-10% for small, redundant, blocks and >>20% better speed in both cases) + * In short: when in need for speed, enable this for binary data, + * possibly disable this for text data. + */ +#ifndef ULTRA_FAST +# define ULTRA_FAST 0 +#endif + +/* + * Unconditionally aligning does not cost very much, so do it if unsure + */ +#ifndef STRICT_ALIGN +# define STRICT_ALIGN !(defined(__i386) || defined (__amd64)) +#endif + +/* + * Use string functions to copy memory. + * this is usually a loss, even with glibc's optimized memcpy + */ +#ifndef USE_MEMCPY +# define USE_MEMCPY 0 +#endif + +/* + * You may choose to pre-set the hash table (might be faster on some + * modern cpus and large (>>64k) blocks) + */ +#ifndef INIT_HTAB +# define INIT_HTAB 0 +#endif + +/* + * Avoid assigning values to errno variable? for some embedding purposes + * (linux kernel for example), this is neccessary. NOTE: this breaks + * the documentation in lzf.h. + */ +#ifndef AVOID_ERRNO +# define AVOID_ERRNO 0 +#endif + +/* + * Wether to pass the LZF_STATE variable as argument, or allocate it + * on the stack. For small-stack environments, define this to 1. + * NOTE: this breaks the prototype in lzf.h. + */ +#ifndef LZF_STATE_ARG +# define LZF_STATE_ARG 0 +#endif + +/* + * Wether to add extra checks for input validity in lzf_decompress + * and return EINVAL if the input stream has been corrupted. This + * only shields against overflowing the input buffer and will not + * detect most corrupted streams. + * This check is not normally noticable on modern hardware + * (<1% slowdown), but might slow down older cpus considerably. + */ +#ifndef CHECK_INPUT +# define CHECK_INPUT 1 +#endif + +/*****************************************************************************/ +/* nothing should be changed below */ + +typedef unsigned char u8; + +typedef const u8 *LZF_STATE[1 << (HLOG)]; + +#if !STRICT_ALIGN +/* for unaligned accesses we need a 16 bit datatype. */ +# include +# if USHRT_MAX == 65535 + typedef unsigned short u16; +# elif UINT_MAX == 65535 + typedef unsigned int u16; +# else +# undef STRICT_ALIGN +# define STRICT_ALIGN 1 +# endif +#endif + +#if ULTRA_FAST +# if defined(VERY_FAST) +# undef VERY_FAST +# endif +#endif + +#if USE_MEMCPY || INIT_HTAB +# ifdef __cplusplus +# include +# else +# include +# endif +#endif + +#endif + diff --git a/tools/wadzip/lzf_c.c b/tools/wadzip/lzf_c.c new file mode 100644 index 000000000..b9b9ef991 --- /dev/null +++ b/tools/wadzip/lzf_c.c @@ -0,0 +1,242 @@ +/* + * Copyright (c) 2000-2005 Marc Alexander Lehmann + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, 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. The name of the author may not 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 MER- + * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- + * CIAL, 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 OTH- + * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Alternatively, the contents of this file may be used under the terms of + * the GNU General Public License version 2 (the "GPL"), in which case the + * provisions of the GPL are applicable instead of the above. If you wish to + * allow the use of your version of this file only under the terms of the + * GPL and not to allow others to use your version of this file under the + * BSD license, indicate your decision by deleting the provisions above and + * replace them with the notice and other provisions required by the GPL. If + * you do not delete the provisions above, a recipient may use your version + * of this file under either the BSD or the GPL. + */ + +#include "lzfP.h" + +#define HSIZE (1 << (HLOG)) + +/* + * don't play with this unless you benchmark! + * decompression is not dependent on the hash function + * the hashing function might seem strange, just believe me + * it works ;) + */ +#ifndef FRST +# define FRST(p) (((p[0]) << 8) | p[1]) +# define NEXT(v,p) (((v) << 8) | p[2]) +# define IDX(h) ((((h ^ (h << 5)) >> (3*8 - HLOG)) - h*5) & (HSIZE - 1)) +#endif +/* + * IDX works because it is very similar to a multiplicative hash, e.g. + * ((h * 57321 >> (3*8 - HLOG)) & (HSIZE - 1)) + * the latter is also quite fast on newer CPUs, and sligthly better + * + * the next one is also quite good, albeit slow ;) + * (int)(cos(h & 0xffffff) * 1e6) + */ + +#if 0 +/* original lzv-like hash function, much worse and thus slower */ +# define FRST(p) (p[0] << 5) ^ p[1] +# define NEXT(v,p) ((v) << 5) ^ p[2] +# define IDX(h) ((h) & (HSIZE - 1)) +#endif + +#define MAX_LIT (1 << 5) +#define MAX_OFF (1 << 13) +#define MAX_REF ((1 << 8) + (1 << 3)) + +/* + * compressed format + * + * 000LLLLL ; literal + * LLLooooo oooooooo ; backref L + * 111ooooo LLLLLLLL oooooooo ; backref L+7 + * + */ + +unsigned int +lzf_compress (const void *const in_data, unsigned int in_len, + void *out_data, unsigned int out_len +#if LZF_STATE_ARG + , LZF_STATE *htab +#endif + ) +{ +#if !LZF_STATE_ARG + LZF_STATE htab; +#endif + const u8 **hslot; + const u8 *ip = (const u8 *)in_data; + u8 *op = (u8 *)out_data; + const u8 *in_end = ip + in_len; + u8 *out_end = op + out_len; + const u8 *ref; + + unsigned int hval = FRST (ip); + unsigned long off; + int lit = 0; + +#if INIT_HTAB +# if USE_MEMCPY + memset (htab, 0, sizeof (htab)); +# else + for (hslot = htab; hslot < htab + HSIZE; hslot++) + *hslot++ = ip; +# endif +#endif + + for (;;) + { + if (ip < in_end - 2) + { + hval = NEXT (hval, ip); + hslot = htab + IDX (hval); + ref = *hslot; *hslot = ip; + + if (1 +#if INIT_HTAB && !USE_MEMCPY + && ref < ip /* the next test will actually take care of this, but this is faster */ +#endif + && (off = ip - ref - 1) < MAX_OFF + && ip + 4 < in_end + && ref > (u8 *)in_data +#if STRICT_ALIGN + && ref[0] == ip[0] + && ref[1] == ip[1] + && ref[2] == ip[2] +#else + && *(u16 *)ref == *(u16 *)ip + && ref[2] == ip[2] +#endif + ) + { + /* match found at *ref++ */ + unsigned int len = 2; + unsigned int maxlen = in_end - ip - len; + maxlen = maxlen > MAX_REF ? MAX_REF : maxlen; + + if (op + lit + 1 + 3 >= out_end) + return 0; + + do + len++; + while (len < maxlen && ref[len] == ip[len]); + + if (lit) + { + *op++ = lit - 1; + lit = -lit; + do + *op++ = ip[lit]; + while (++lit); + } + + len -= 2; + ip++; + + if (len < 7) + { + *op++ = (off >> 8) + (len << 5); + } + else + { + *op++ = (off >> 8) + ( 7 << 5); + *op++ = len - 7; + } + + *op++ = off; + +#if ULTRA_FAST || VERY_FAST + ip += len; +#if VERY_FAST && !ULTRA_FAST + --ip; +#endif + hval = FRST (ip); + + hval = NEXT (hval, ip); + htab[IDX (hval)] = ip; + ip++; + +#if VERY_FAST && !ULTRA_FAST + hval = NEXT (hval, ip); + htab[IDX (hval)] = ip; + ip++; +#endif +#else + do + { + hval = NEXT (hval, ip); + htab[IDX (hval)] = ip; + ip++; + } + while (len--); +#endif + continue; + } + } + else if (ip == in_end) + break; + + /* one more literal byte we must copy */ + lit++; + ip++; + + if (lit == MAX_LIT) + { + if (op + 1 + MAX_LIT >= out_end) + return 0; + + *op++ = MAX_LIT - 1; +#if USE_MEMCPY + memcpy (op, ip - MAX_LIT, MAX_LIT); + op += MAX_LIT; + lit = 0; +#else + lit = -lit; + do + *op++ = ip[lit]; + while (++lit); +#endif + } + } + + if (lit) + { + if (op + lit + 1 >= out_end) + return 0; + + *op++ = lit - 1; + lit = -lit; + do + *op++ = ip[lit]; + while (++lit); + } + + return op - (u8 *) out_data; +} diff --git a/tools/wadzip/lzf_d.c b/tools/wadzip/lzf_d.c new file mode 100644 index 000000000..73a1a80b6 --- /dev/null +++ b/tools/wadzip/lzf_d.c @@ -0,0 +1,140 @@ +/* + * Copyright (c) 2000-2005 Marc Alexander Lehmann + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, 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. The name of the author may not 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 MER- + * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- + * CIAL, 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 OTH- + * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Alternatively, the contents of this file may be used under the terms of + * the GNU General Public License version 2 (the "GPL"), in which case the + * provisions of the GPL are applicable instead of the above. If you wish to + * allow the use of your version of this file only under the terms of the + * GPL and not to allow others to use your version of this file under the + * BSD license, indicate your decision by deleting the provisions above and + * replace them with the notice and other provisions required by the GPL. If + * you do not delete the provisions above, a recipient may use your version + * of this file under either the BSD or the GPL. + */ + +#include "lzfP.h" + +#if AVOID_ERRNO +# define SET_ERRNO(n) +#else +# include +# define SET_ERRNO(n) errno = (n) +#endif + +unsigned int +lzf_decompress (const void *const in_data, unsigned int in_len, + void *out_data, unsigned int out_len) +{ + u8 const *ip = (const u8 *)in_data; + u8 *op = (u8 *)out_data; + u8 const *const in_end = ip + in_len; + u8 *const out_end = op + out_len; + + do + { + unsigned int ctrl = *ip++; + + if (ctrl < (1 << 5)) /* literal run */ + { + ctrl++; + + if (op + ctrl > out_end) + { + SET_ERRNO (E2BIG); + return 0; + } + +#if CHECK_INPUT + if (ip + ctrl > in_end) + { + SET_ERRNO (EINVAL); + return 0; + } +#endif + +#if USE_MEMCPY + memcpy (op, ip, ctrl); + op += ctrl; + ip += ctrl; +#else + do + *op++ = *ip++; + while (--ctrl); +#endif + } + else /* back reference */ + { + unsigned int len = ctrl >> 5; + + u8 *ref = op - ((ctrl & 0x1f) << 8) - 1; + +#if CHECK_INPUT + if (ip >= in_end) + { + SET_ERRNO (EINVAL); + return 0; + } +#endif + if (len == 7) + { + len += *ip++; +#if CHECK_INPUT + if (ip >= in_end) + { + SET_ERRNO (EINVAL); + return 0; + } +#endif + } + + ref -= *ip++; + + if (op + len + 2 > out_end) + { + SET_ERRNO (E2BIG); + return 0; + } + + if (ref < (u8 *)out_data) + { + SET_ERRNO (EINVAL); + return 0; + } + + *op++ = *ref++; + *op++ = *ref++; + + do + *op++ = *ref++; + while (--len); + } + } + while (ip < in_end); + + return op - (u8 *)out_data; +} + diff --git a/tools/wadzip/wadzip.c b/tools/wadzip/wadzip.c new file mode 100644 index 000000000..9b60f1a9b --- /dev/null +++ b/tools/wadzip/wadzip.c @@ -0,0 +1,309 @@ +/* + * Wad compressor/decompressor by Graue + * Written January 23, 2007 + * + * This file is in the public domain; use it without any restrictions. + */ + +#include +#include +#ifndef _MSC_VER +#include +#else +typedef unsigned int uint32_t; +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +#endif +#include +#include +#include "err.h" +#include "lzf.h" +#include "xm.h" + +/* Note: Define WORDS_BIGENDIAN if that is the case on the target CPU. */ + +#define MINCOMPRESS 1024 // Don't bother compressing lumps smaller than this. + +#define SWAP16(n) ((((n)&0xff)<<8) | ((n)>>8)) +#define SWAP32(n) \ +( \ + ((((n)&0xff) <<24) \ + | ((((n)>>8)&0xff)<<16) \ + | ((((n)>>16)&0xff)<<8) \ + | ((n)>>24) \ +) +#ifdef WORDS_BIGENDIAN +#define conv16le SWAP16 +#define conv32le SWAP32 +#else +#define conv16le(n) (n) +#define conv32le(n) (n) +#endif +#define READFUNC(name, type, conv) \ +static type name(FILE *fp) \ +{ \ + type val; \ + if (fread(&val, sizeof val, 1, fp) < 1) \ + { \ + if (ferror(fp)) \ + err(1, "error reading input file"); \ + errx(1, "premature end of input file"); \ + } \ + val = conv(val); \ + return val; \ +} +READFUNC(read32le, uint32_t, conv32le) + +#define WRITEFUNC(name, type, conv) \ +static void name(FILE *fp, type val) \ +{ \ + val = conv(val); \ + if (fwrite(&val, sizeof (type), 1, fp) < 1) \ + err(1, "error writing output file"); \ +} +WRITEFUNC(write32le, uint32_t, conv32le) + +#define ID_IWAD 0x44415749 +#define ID_PWAD 0x44415750 +#define ID_ZWAD 0x4441575a // 'ZWAD' for lzf-compressed wad + +typedef struct +{ + char name[8]; + uint32_t len; + void *data; +} lump_t; + +typedef struct +{ + uint32_t id; + uint32_t numlumps; + lump_t *lumps; +} wad_t; + +extern char *__progname; + +static void usage(void) +{ + fprintf(stderr, "usage: %s [cd] infile outfile\n", __progname); + exit(EXIT_FAILURE); +} + +#define fileoffset_t long +#define myseek fseek +#define mytell ftell + +static void readlumpdata(lump_t *lump, uint32_t csize, int compressed, FILE *fp) +{ + uint8_t *cbuf; + uint8_t *ubuf; + uint32_t usize; + unsigned int retval; + + cbuf = xm(1, csize); + if (fread(cbuf, csize, 1, fp) < 1) + err(1, "cannot read lump from input file"); + + if (!compressed) + { + lump->len = csize; + lump->data = cbuf; + return; + } + + usize = conv32le(*(uint32_t *)cbuf); + if (usize == 0) + { + lump->len = csize - 4; + lump->data = cbuf + 4; // XXX cannot be freed later + return; + } + + ubuf = xm(1, usize); + retval = lzf_decompress(cbuf + 4, csize - 4, ubuf, usize); + if (retval == 0) + { + if (errno == E2BIG) + errx(1, "decompressed data bigger than advertised"); + if (errno == EINVAL) + errx(1, "invalid compressed (lzf) data"); + else + err(1, "unknown error from lzf"); + } + else if (retval < usize) + errx(1, "decompressed data smaller than advertised"); + lump->len = usize; + lump->data = ubuf; + free(cbuf); + return; +} + +static wad_t *readwad(const char *fname) +{ + wad_t *wad; + FILE *fp; + int inputcompressed; + fileoffset_t dirstart; + uint32_t ix; + + fp = fopen(fname, "rb"); + if (fp == NULL) err(1, "%s", fname); + + wad = xm(sizeof *wad, 1); + + // Read wad id. If it is ZWAD, prepare to read compressed lumps. + wad->id = read32le(fp); + inputcompressed = wad->id == ID_ZWAD; + + // Read number of lumps, and prepare space for that many. + wad->numlumps = read32le(fp); + wad->lumps = xm(sizeof wad->lumps[0], wad->numlumps); + + // Read offset to directory. + dirstart = (fileoffset_t)read32le(fp); + + for (ix = 0; ix < wad->numlumps; ix++) + { + fileoffset_t lumpofs; + uint32_t lumpsize; // The compressed size, if it is compressed. + + if (myseek(fp, dirstart + (16*ix), SEEK_SET) == -1) + { + err(1, "cannot seek input file to dir entry %lu", + (unsigned long)ix); + } + lumpofs = (fileoffset_t)read32le(fp); + lumpsize = read32le(fp); + if (fread(wad->lumps[ix].name, 1, 8, fp) < 8) + err(1, "cannot read lump %lu name", (unsigned long)ix); + + // Don't try to seek to zero-length lumps. + // Their offset is meaningless. + if (lumpsize == 0) + { + wad->lumps[ix].len = 0; + continue; + } + + if (myseek(fp, lumpofs, SEEK_SET) == -1) + err(1, "cannot seek to lump %lu", (unsigned long)ix); + readlumpdata(&wad->lumps[ix], lumpsize, inputcompressed, fp); + } + + if (fclose(fp) == EOF) + warn("error closing input file %s", fname); + return wad; +} + +void writewad(const wad_t *wad, const char *fname, int compress) +{ + uint32_t *lumpofs; // Each lump's offset in the file. + uint32_t *disksize; // Each lump's disk size (compressed if applicable). + uint32_t dirstart; + uint32_t ix; + FILE *fp; + + lumpofs = xm(sizeof lumpofs[0], wad->numlumps); + disksize = xm(sizeof disksize[0], wad->numlumps); + + fp = fopen(fname, "wb"); + if (fp == NULL) err(1, "%s", fname); + + // Write header. + write32le(fp, compress ? ID_ZWAD : ID_PWAD); + write32le(fp, wad->numlumps); + write32le(fp, 0); // Directory table comes later. + + for (ix = 0; ix < wad->numlumps; ix++) + { + uint8_t *cbuf; + uint32_t csize; + + lumpofs[ix] = (uint32_t)mytell(fp); + if (!compress) + { + cbuf = wad->lumps[ix].data; + csize = wad->lumps[ix].len; + } + else + { + unsigned int retval; + + csize = wad->lumps[ix].len + 4; + cbuf = xm(1, csize); + if (wad->lumps[ix].len < MINCOMPRESS + || (retval = lzf_compress(wad->lumps[ix].data, + wad->lumps[ix].len, cbuf + 4, + csize - 5)) == 0) + { + // Store uncompressed. + memcpy(cbuf + 4, wad->lumps[ix].data, + wad->lumps[ix].len); + *(uint32_t *)cbuf = 0; + } + else + { + // Compression succeeded. + // Store uncompressed size, and set compressed + // size properly. + *(uint32_t *)cbuf = + conv32le(wad->lumps[ix].len); + csize = retval + 4; + } + } + + if (fwrite(cbuf, csize, 1, fp) < 1) + { + err(1, "cannot write lump %lu to %s", (unsigned long)ix, + fname); + } + + if (compress) + free(cbuf); + disksize[ix] = csize; + } + + dirstart = (uint32_t)mytell(fp); + if (myseek(fp, 8L, SEEK_SET) == -1) + err(1, "cannot reseek %s to write directory start", fname); + write32le(fp, dirstart); + if (myseek(fp, dirstart, SEEK_SET) == -1) + err(1, "cannot reseek %s to write actual directory", fname); + + for (ix = 0; ix < wad->numlumps; ix++) + { + // Write the lump's directory entry. + write32le(fp, lumpofs[ix]); + write32le(fp, disksize[ix]); + if (fwrite(wad->lumps[ix].name, 1, 8, fp) < 8) + { + err(1, "cannot write lump %lu's name", + (unsigned long)ix); + } + } + + if (fclose(fp) == EOF) + warn("error closing output file %s", fname); +} + +int main(int argc, char *argv[]) +{ + const char *infile, *outfile; + wad_t *wad; + int compress; + + if (argc != 4 || strlen(argv[1]) != 1) + usage(); + + /* c to compress, d to decompress */ + if (argv[1][0] == 'c') compress = 1; + else if (argv[1][0] == 'd') compress = 0; + else usage(); + + infile = argv[2]; + outfile = argv[3]; + + wad = readwad(infile); + writewad(wad, outfile, compress); + return 0; +} diff --git a/tools/wadzip/wadzip.dsp b/tools/wadzip/wadzip.dsp new file mode 100644 index 000000000..85f1f99ad --- /dev/null +++ b/tools/wadzip/wadzip.dsp @@ -0,0 +1,104 @@ +# Microsoft Developer Studio Project File - Name="wadzip" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=wadzip - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "wadzip.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "wadzip.mak" CFG="wadzip - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "wadzip - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "wadzip - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "wadzip - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 + +!ELSEIF "$(CFG)" == "wadzip - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c +# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept + +!ENDIF + +# Begin Target + +# Name "wadzip - Win32 Release" +# Name "wadzip - Win32 Debug" +# Begin Source File + +SOURCE=.\err.c +# End Source File +# Begin Source File + +SOURCE=.\lzf_c.c +# End Source File +# Begin Source File + +SOURCE=.\lzf_d.c +# End Source File +# Begin Source File + +SOURCE=.\wadzip.c +# End Source File +# Begin Source File + +SOURCE=.\xm.c +# End Source File +# End Target +# End Project diff --git a/tools/wadzip/wadzip.dsw b/tools/wadzip/wadzip.dsw new file mode 100644 index 000000000..c4bd785a2 --- /dev/null +++ b/tools/wadzip/wadzip.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00 +# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! + +############################################################################### + +Project: "wadzip"=.\wadzip.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/tools/wadzip/wadzip.txt b/tools/wadzip/wadzip.txt new file mode 100644 index 000000000..24d05d0f0 --- /dev/null +++ b/tools/wadzip/wadzip.txt @@ -0,0 +1,30 @@ +Compressed wad format: + +Just like a normal wad, except: + +1. The header id at the very beginning says "ZWAD" +instead of PWAD or IWAD. + +2. The first four bytes of each lump are (little +endian) the uncompressed size. If this is zero, +the lump is not compressed, and you can subtract +four from the size given in the wadfile directory. + +3. Unless those first four bytes give a value of +0, the lump is compressed with liblzf after that. + + + +To compile this program, just compiling all its +source files should work, that is: + gcc *.c -o wadzip + +[On a big-endian CPU, add "-DWORDS_BIGENDIAN" to +that command line.] + +Visual C++ should also work, as well as gcc. + +Compress a wad: + wadzip c original.wad compressed.wad +Decompress a wad (restoring the original): + wadzip d compressed.wad original.wad diff --git a/tools/wadzip/xm.c b/tools/wadzip/xm.c new file mode 100644 index 000000000..f388bab9e --- /dev/null +++ b/tools/wadzip/xm.c @@ -0,0 +1,76 @@ +/* Fail-proof memory allocation by Graue ; public domain */ + +#include +#include +#include "err.h" + +/* MinGW (for example) appears to lack SIZE_T_MAX. */ +#ifndef SIZE_T_MAX +#define SIZE_T_MAX ULONG_MAX +#endif + +/* + * The usual xmalloc and xrealloc type routines, for allocating memory + * and bombing out if it fails. + * + * xm and xr here take two values: size and nmemb, like fread/fwrite. + * The idea is to be able to check for overflow, to prevent some weird + * crashes and security problems that can arise if you multiply size + * and nmemb and they overflow. + */ + +/* FIXME: use %zu (size_t) in these format arguments if library is C99 */ + +/* + * Multiply size and number of elements, bombing out if overflow would + * occur. + + * Note: In the case where size*nmemb is exactly equal to SIZE_T_MAX, + * this function considers that an overflow, even though it isn't + * really. But it's not likely the program will get that much memory, + * anyway. + */ +static size_t sizmul(size_t size, size_t nmemb) +{ + if (SIZE_T_MAX / size <= nmemb) + { + errx(1, "allocating %lu objects of size %lu " + "would overflow", (unsigned long)nmemb, + (unsigned long)size); + } + return size * nmemb; /* won't overflow */ +} + +static void nomem(size_t size, size_t nmemb) +{ + err(1, "cannot allocate %lu objects of size %lu " + "(total %lu bytes)", (unsigned long)nmemb, + (unsigned long)size, (unsigned long)(nmemb*size)); +} + +void *xm(size_t size, size_t nmemb) +{ + const size_t bytes = sizmul(size, nmemb); + void *p; + + p = malloc(bytes); + if (p == NULL) nomem(size, nmemb); + return p; +} + +void *xr(void *p, size_t size, size_t nmemb) +{ + const size_t bytes = sizmul(size, nmemb); + + p = realloc(p, bytes); + if (p == NULL) nomem(size, nmemb); + return p; +} + +/* expand array */ +void *xpnd(void *p, int nit, int *sit, size_t sz) +{ + if (nit < *sit) return p; + else if (*sit > 0) return xr(p, sz, (*sit *= 2)); + else return xm(sz, (*sit = 10)); +} diff --git a/tools/wadzip/xm.h b/tools/wadzip/xm.h new file mode 100644 index 000000000..d57f8479b --- /dev/null +++ b/tools/wadzip/xm.h @@ -0,0 +1,4 @@ +void *xm(size_t size, size_t nmemb); +void *xr(void *p, size_t size, size_t nmemb); +void *xpnd(void *p, int nit, int *sit, size_t sz); +#define XPND(p, num, spc) (p = xpnd(p, num, &spc, sizeof *p))